Changeset 4939


Ignore:
Timestamp:
Feb 23, 2016, 9:07:05 AM (4 years ago)
Author:
lindanl
Message:

new version using the kernels.

Location:
icGREP/icgrep-devel/icgrep
Files:
2 added
15 edited

Legend:

Unmodified
Added
Removed
  • icGREP/icgrep-devel/icgrep/CMakeLists.txt

    r4937 r4939  
    6363
    6464SET(PABLO_SRC pablo/pabloAST.cpp pablo/ps_if.cpp pablo/ps_while.cpp pablo/function.cpp pablo/codegenstate.cpp pablo/builder.cpp pablo/symbol_generator.cpp pablo/printer_pablos.cpp)
    65 SET(PABLO_SRC ${PABLO_SRC} pablo/pablo_compiler.cpp pablo/carry_manager.cpp pablo/carry_data.cpp IDISA/idisa_builder.cpp IDISA/idisa_avx_builder.cpp IDISA/idisa_sse_builder.cpp kernels/s2p_gen.cpp kernels/scanmatchgen.cpp)
     65SET(PABLO_SRC ${PABLO_SRC} pablo/pablo_compiler.cpp pablo/carry_manager.cpp pablo/carry_data.cpp IDISA/idisa_builder.cpp IDISA/idisa_avx_builder.cpp IDISA/idisa_sse_builder.cpp kernels/s2p_kernel.cpp kernels/scanmatchgen.cpp kernels/kernel.cpp kernels/pipeline.cpp)
    6666SET(PABLO_SRC ${PABLO_SRC} pablo/analysis/pabloverifier.cpp)
    6767SET(PABLO_SRC ${PABLO_SRC} pablo/optimizers/pablo_simplifier.cpp pablo/optimizers/codemotionpass.cpp)
  • icGREP/icgrep-devel/icgrep/do_grep.cpp

    r4937 r4939  
    55 */
    66
    7 #include "basis_bits.h"
     7#include "toolchain.h"
    88#include "do_grep.h"
    99
     
    2323#include <cctype>
    2424
    25 #include "include/simd-lib/carryQ.hpp"
    26 #include "include/simd-lib/pabloSupport.hpp"
    27 #include "include/simd-lib/s2p.hpp"
    28 #include "include/simd-lib/buffer.hpp"
    2925
    3026#include <llvm/Support/raw_os_ostream.h>
     
    5753
    5854
    59 void GrepExecutor::write_matched_line(llvm::raw_ostream & out, const char * buffer, ssize_t line_start, ssize_t line_end) {
    60     if (mShowFileNameOption) {
    61         out << mFileName << ':';
    62     }
    63     if (mShowLineNumberingOption) {
    64         out << mLineNum << ":";
    65     }
    66     if ((buffer[line_start] == 0xA) && (line_start != line_end)) {
    67         // The line "starts" on the LF of a CRLF.  Really the end of the last line.
    68         line_start++;
    69     }
    70     if (buffer + line_end == mFileBuffer + mFileSize) {
    71         // The match position is at end-of-file.   We have a final unterminated line.
    72         out.write(&buffer[line_start], line_end - line_start);
    73         if (mNormalizeLineBreaksOption) {
    74             out << '\n';  // terminate it
    75         }
    76         return;
    77     }
    78     unsigned char end_byte = (unsigned char)buffer[line_end];
    79     if (mNormalizeLineBreaksOption) {
    80         if (end_byte == 0x85) {
    81             // Line terminated with NEL, on the second byte.  Back up 1.
    82             line_end--;
    83         } else if (end_byte > 0xD) {
    84             // Line terminated with PS or LS, on the third byte.  Back up 2.
    85             line_end -= 2;
    86         }
    87         out.write(&buffer[line_start], line_end - line_start);
    88         out << '\n';
    89     }
    90     else {
    91         if (end_byte == 0x0D) {
    92             // Check for line_end on first byte of CRLF;  note that we don't
    93             // want to access past the end of buffer.
    94             if ((buffer + line_end + 1 < mFileBuffer + mFileSize) && (buffer[line_end + 1] == 0x0A)) {
    95                 // Found CRLF; preserve both bytes.
    96                 line_end++;
    97             }
    98         }
    99         out.write(&buffer[line_start], line_end - line_start + 1);
    100     }
    101    
    102 }
    103 
    104 ssize_t GrepExecutor::write_matches(llvm::raw_ostream & out, const char * buffer, ssize_t line_start) {
    105 
    106     ssize_t match_pos;
    107     ssize_t line_end;
    108     while (mMatch_scanner.has_next()) {
    109         match_pos = mMatch_scanner.scan_to_next();
    110         // If we found a match, it must be at a line end.
    111         while (true) {
    112             line_end = mLineBreak_scanner.scan_to_next();
    113             if (line_end >= match_pos) {
    114                 break;
    115             }
    116             line_start = line_end + 1;
    117             mLineNum++;
    118         }
    119         write_matched_line(out,buffer, line_start, line_end);
    120         line_start = line_end + 1;
    121         mLineNum++;
    122     }
    123     while(mLineBreak_scanner.has_next()) {
    124         line_end = mLineBreak_scanner.scan_to_next();
    125         line_start = line_end+1;
    126         mLineNum++;
    127     }
    128     return line_start;
    129 }
    130 
    13155bool GrepExecutor::finalLineIsUnterminated() const {
    13256    if (mFileSize == 0) return false;
     
    14569}
    14670
    147 // Extracting codepoint data from UCD name data file.
    148 ssize_t GrepExecutor::extract_codepoints(char * buffer, ssize_t first_line_start) {
    149    
    150     ssize_t line_start = first_line_start;
    151     size_t match_pos;
    152     size_t line_end;
    153    
    154     while (mMatch_scanner.has_next()) {
    155         match_pos = mMatch_scanner.scan_to_next();
    156         // If we found a match, it must be at a line end.
    157         line_end = mLineBreak_scanner.scan_to_next();
    158         while (line_end < match_pos) {
    159             line_start = line_end + 1;
    160             mLineNum++;
    161             line_end = mLineBreak_scanner.scan_to_next();
    162         }
    163        
    164         re::codepoint_t c = 0;
    165         ssize_t line_pos = line_start;
    166         while (isxdigit(buffer[line_pos])) {
    167             if (isdigit(buffer[line_pos])) {
    168                 c = (c << 4) | (buffer[line_pos] - '0');
    169             }
    170             else {
    171                 c = (c << 4) | (tolower(buffer[line_pos]) - 'a' + 10);
    172             }
    173             line_pos++;
    174         }
    175         assert(((line_pos - line_start) >= 4) && ((line_pos - line_start) <= 6)); // UCD format 4 to 6 hex digits.
    176 #ifndef NDEBUG
    177         std::cerr << "\\N expression found codepoint " << std::hex << c << std::dec << std::endl;
    178 #endif
    179        
    180         mParsedCodePointSet->insert(c);
    181        
    182         line_start = line_end + 1;
    183         mLineNum++;
    184     }
    185     while(mLineBreak_scanner.has_next()) {
    186         line_end = mLineBreak_scanner.scan_to_next();
    187         line_start = line_end+1;
    188         mLineNum++;
    189     }
    190     return line_start;
    191    
    192 }
    193 
    194 
    19571void GrepExecutor::doGrep(const std::string & fileName) {
    19672
    197     Basis_bits basis_bits;
    198     BitBlock match_vector = simd<1>::constant<0>();
    199     size_t match_count = 0;
    200     size_t chars_avail = 0;
    201     ssize_t line_start = 0;
    202 
    20373    mFileName = fileName;
    204     mLineNum = 1;
    20574
    20675#ifdef USE_BOOST_MMAP
     
    250119    }
    251120    else {
    252         mFileBuffer = (char *) mmap(nullptr, mFileSize, PROT_READ, MAP_PRIVATE, fdSrc, 0);
     121        mFileBuffer = (char *) mmap(NULL, mFileSize, PROT_READ, MAP_PRIVATE, fdSrc, 0);
    253122        if (mFileBuffer == MAP_FAILED) {
    254123            if (errno ==  ENOMEM) {
     
    264133    }
    265134#endif
    266     size_t segment = 0;
    267     chars_avail = mFileSize;
    268135
    269136    llvm::raw_os_ostream out(std::cout);
    270     mInitializeCarriesFcn();
    271     //////////////////////////////////////////////////////////////////////////////////////////
    272     // Full Segments
    273     //////////////////////////////////////////////////////////////////////////////////////////
    274137
    275     while (chars_avail >= SEGMENT_SIZE) {
     138    uint64_t finalLineUnterminated = 0;
     139    if(finalLineIsUnterminated())
     140        finalLineUnterminated = 1;
    276141
    277         mLineBreak_scanner.init();
    278         mMatch_scanner.init();
     142    mMainFcn(mFileBuffer, mFileSize, fileName.c_str(), finalLineUnterminated);
    279143
    280         for (size_t blk = 0; blk != SEGMENT_BLOCKS; ++blk) {
    281             mTransposeFcn(reinterpret_cast<BytePack *>(mFileBuffer + (blk * BLOCK_SIZE) + (segment * SEGMENT_SIZE)), basis_bits);
    282             Output output;
    283             mProcessBlockFcn(basis_bits, output);
    284             mMatch_scanner.load_block(output.matches, blk);
    285             mLineBreak_scanner.load_block(output.LF, blk);
    286 
    287             if (mCountOnlyOption) {
    288                 if (bitblock::any(output.matches)) {
    289                     if (bitblock::any(simd_and(match_vector, output.matches))) {
    290                         match_count += bitblock::popcount(match_vector);
    291                         match_vector = output.matches;
    292                     } else {
    293                         match_vector = simd_or(match_vector, output.matches);
    294                     }
    295                 }
    296             }
    297         }
    298         if (!mCountOnlyOption) {
    299             if (mGetCodePointsOption) {
    300                 line_start = extract_codepoints(mFileBuffer + (segment * SEGMENT_SIZE), line_start);
    301             }
    302             else {
    303                 line_start = write_matches(out, mFileBuffer + (segment * SEGMENT_SIZE), line_start);
    304             }
    305         }
    306         segment++;
    307         line_start -= SEGMENT_SIZE;  /* Will be negative offset for use within next segment. */
    308         chars_avail -= SEGMENT_SIZE;
    309     }
    310 
    311     //////////////////////////////////////////////////////////////////////////////////////////
    312     // For the Final Partial Segment.
    313     //////////////////////////////////////////////////////////////////////////////////////////
    314 
    315     size_t remaining = chars_avail;
    316     size_t blk = 0;
    317 
    318     mLineBreak_scanner.init();
    319     mMatch_scanner.init();
    320 
    321     /* Full Blocks */
    322     for (; remaining >= BLOCK_SIZE; remaining -= BLOCK_SIZE, ++blk) {
    323         mTransposeFcn(reinterpret_cast<BytePack *>(mFileBuffer + (blk * BLOCK_SIZE) + (segment * SEGMENT_SIZE)), basis_bits);
    324         Output output;
    325         mProcessBlockFcn(basis_bits, output);
    326         mLineBreak_scanner.load_block(output.LF, blk);
    327         mMatch_scanner.load_block(output.matches, blk);
    328         if (mCountOnlyOption) {
    329             if (bitblock::any(output.matches)) {
    330                 if (bitblock::any(simd_and(match_vector, output.matches))) {
    331                     match_count += bitblock::popcount(match_vector);
    332                     match_vector = output.matches;
    333                 } else {
    334                     match_vector = simd_or(match_vector, output.matches);
    335                 }
    336             }
    337         }
    338     }
    339 
    340     //Final Partial Block (may be empty, but there could be carries pending).
     144    PrintTotalCount();
    341145   
    342    
    343     const auto EOF_mask = bitblock::srl(simd<1>::constant<1>(), convert(BLOCK_SIZE - remaining));
    344    
    345     if (remaining == 0) {  // No data, we may be at a page boundary.   Do not access memory.
    346         basis_bits.bit_0 = simd<1>::constant<0>();
    347         basis_bits.bit_1 = simd<1>::constant<0>();
    348         basis_bits.bit_2 = simd<1>::constant<0>();
    349         basis_bits.bit_3 = simd<1>::constant<0>();
    350         basis_bits.bit_4 = simd<1>::constant<0>();
    351         basis_bits.bit_5 = simd<1>::constant<0>();
    352         basis_bits.bit_6 = simd<1>::constant<0>();
    353         basis_bits.bit_7 = simd<1>::constant<0>();
    354     }
    355     else { // At least 1 byte, so we are not at a page boundary yet, safe to access a full block.
    356         mTransposeFcn(reinterpret_cast<BytePack *>(mFileBuffer + (blk * BLOCK_SIZE) + (segment * SEGMENT_SIZE)), basis_bits);
    357     }
    358 
    359     if (finalLineIsUnterminated()) {
    360         // Add a LF at the EOF position
    361         BitBlock EOF_pos = simd_not(simd_or(bitblock::slli<1>(simd_not(EOF_mask)), EOF_mask));
    362         //  LF = 00001010  (bits 4 and 6 set).
    363         basis_bits.bit_4 = simd_or(basis_bits.bit_4, EOF_pos);
    364         basis_bits.bit_6 = simd_or(basis_bits.bit_6, EOF_pos);
    365     }
    366    
    367     Output output;
    368     mProcessBlockFcn(basis_bits, output);
    369     if (mCountOnlyOption) {
    370         match_count += bitblock::popcount(match_vector);
    371         if (bitblock::any(output.matches)) {
    372             match_count += bitblock::popcount(output.matches);
    373         }
    374         if (mShowFileNameOption) {
    375             out << mFileName << ':';
    376         }
    377         out << match_count << '\n';
    378     } else {
    379         mLineBreak_scanner.load_block(output.LF, blk);
    380         mMatch_scanner.load_block(output.matches, blk);
    381         while (++blk < SEGMENT_BLOCKS) {
    382             mLineBreak_scanner.load_block(simd<1>::constant<0>(), blk);
    383             mMatch_scanner.load_block(simd<1>::constant<0>(), blk);
    384         }
    385         if (mGetCodePointsOption) {
    386             line_start = extract_codepoints(mFileBuffer + (segment * SEGMENT_SIZE), line_start);
    387         }
    388         else {
    389             line_start = write_matches(out, mFileBuffer + (segment * SEGMENT_SIZE), line_start);
    390         }
    391     }
    392146#ifdef USE_BOOST_MMAP
    393147    mFile.close();
  • icGREP/icgrep-devel/icgrep/do_grep.h

    r4904 r4939  
    99#include <string>
    1010#include <stdint.h>
    11 #include "basis_bits.h"
    12 #include "include/simd-lib/bitblock.hpp"
    13 #include "include/simd-lib/transpose.hpp"
    14 #include "include/simd-lib/bitblock_iterator.hpp"
    1511#include <re/re_cc.h>
    1612
    17 struct Output {
    18     BitBlock matches;
    19     BitBlock LF;
    20 };
    2113
    22 #if (BLOCK_SIZE == 128)
    23 #define SEGMENT_BLOCKS 7
    24 #endif
    25 
    26 #if (BLOCK_SIZE == 256)
    27 #define SEGMENT_BLOCKS 15
    28 #endif
    29 
    30 #define SEGMENT_SIZE (BLOCK_SIZE * SEGMENT_BLOCKS)
    31 
    32 
    33 #if (BLOCK_SIZE == 256)
    34 typedef BitStreamScanner<BitBlock, uint64_t, uint64_t, SEGMENT_BLOCKS> ScannerT;
    35 #endif
    36 
    37 #if (BLOCK_SIZE == 128)
    38 typedef BitStreamScanner<BitBlock, uint32_t, uint32_t, SEGMENT_BLOCKS> ScannerT;
    39 #endif
    40 
    41 typedef void (*transpose_fcn_T)(BytePack * byte_data, Basis_bits & basis_bits);
    42 typedef void (*process_block_initialize_carries_fcn)();
    43 typedef void (*process_block_fcn)(const Basis_bits & basis_bits, Output & output);
     14typedef void (*main_fcn_T)(char * byte_data, int filesize, const char* filename, uint64_t finalLineUnterminated);
    4415
    4516namespace llvm { class raw_ostream; }
     
    4819public:
    4920
    50     GrepExecutor(void * process_block_initialize_carries, void * process_block)
    51     : mCountOnlyOption(false)
    52     , mGetCodePointsOption(false)
    53     , mShowFileNameOption(false)
    54     , mShowLineNumberingOption(false)
    55     , mParsedCodePointSet(nullptr)
    56     , mTransposeFcn(reinterpret_cast<transpose_fcn_T>(&s2p_do_block))
    57     , mInitializeCarriesFcn(reinterpret_cast<process_block_initialize_carries_fcn>(process_block_initialize_carries))
    58     , mProcessBlockFcn(reinterpret_cast<process_block_fcn>(process_block)) {
     21    GrepExecutor(void * main_fnptr)
     22    : mMainFcn(reinterpret_cast<main_fcn_T>(main_fnptr)) {
    5923       
    6024    }
    61     GrepExecutor(void * s2p_fnptr, void * process_block_initialize_carries, void * process_block)
    62     : mCountOnlyOption(false)
    63     , mGetCodePointsOption(false)
    64     , mShowFileNameOption(false)
    65     , mShowLineNumberingOption(false)
    66     , mParsedCodePointSet(nullptr)
    67     , mTransposeFcn(reinterpret_cast<transpose_fcn_T>(s2p_fnptr))
    68     , mInitializeCarriesFcn(reinterpret_cast<process_block_initialize_carries_fcn>(process_block_initialize_carries))
    69     , mProcessBlockFcn(reinterpret_cast<process_block_fcn>(process_block)) {
    70        
    71     }
    72    
    73     void setCountOnlyOption(bool doCount = true) {mCountOnlyOption = doCount;}
    74     void setParseCodepointsOption() {
    75         mGetCodePointsOption = true;
    76         mParsedCodePointSet = re::makeCC();
    77     }
    78     void setShowFileNameOption(bool showF = true) {mShowFileNameOption = showF;}
    79     void setShowLineNumberOption(bool showN = true) {mShowLineNumberingOption = showN;}
    80     void setNormalizeLineBreaksOption(bool normLB = true) {mNormalizeLineBreaksOption = normLB;}
    81    
     25 
    8226    void doGrep(const std::string & fileName);
    83     re::CC * getParsedCodepoints() { return mParsedCodePointSet;}
    8427private:
    85     void write_matched_line(llvm::raw_ostream & out, const char * buffer, ssize_t line_start, ssize_t line_end);
     28   
     29    bool finalLineIsUnterminated() const;
    8630
    87     ssize_t write_matches(llvm::raw_ostream & out, const char *buffer, ssize_t first_line_start);
    88    
    89     bool finalLineIsUnterminated() const;
    90     ssize_t extract_codepoints(char * buffer, ssize_t first_line_start);
    91 
    92     bool mCountOnlyOption;
    93     bool mGetCodePointsOption;
    94     bool mShowFileNameOption;
    95     bool mShowLineNumberingOption;
    96     bool mNormalizeLineBreaksOption;
    97    
    98     re::CC * mParsedCodePointSet;
    99 
    100     transpose_fcn_T mTransposeFcn;
    101     process_block_initialize_carries_fcn mInitializeCarriesFcn;
    102     process_block_fcn mProcessBlockFcn;
     31    main_fcn_T mMainFcn;
    10332   
    10433    std::string mFileName;
    10534    size_t mFileSize;
    10635    char * mFileBuffer;
    107     ScannerT mLineBreak_scanner;
    108     ScannerT mMatch_scanner;
    109     size_t mLineNum;
    11036};
    11137
  • icGREP/icgrep-devel/icgrep/icgrep.cpp

    r4919 r4939  
    99#include <fstream>
    1010
    11 #include "basis_bits.h"
    1211#include "toolchain.h"
    1312#include "utf_encoding.h"
     
    2524#include <llvm/Support/Host.h>
    2625#include <llvm/IR/Verifier.h>
    27 #include <kernels/s2p_gen.h>
    28 #include <kernels/scanmatchgen.h>
    2926
    3027#include <re/re_re.h>
     
    3532#include <pablo/function.h>
    3633
    37 #include <iostream>
    38 
    39 #include <do_grep.h>
    40 #include <hrtime.h>
    41 
    42 #ifdef PRINT_TIMING_INFORMATION
    43 #include "papi_helper.hpp"
    44 #endif
     34#include "do_grep.h"
     35#include <kernels/pipeline.h>
    4536
    4637static cl::OptionCategory aRegexSourceOptions("Regular Expression Options",
    4738                                       "These options control the regular expression source.");
    4839
    49 static cl::OptionCategory bGrepOutputOptions("Output Options",
    50                                       "These options control the output.");
     40// static cl::OptionCategory bGrepOutputOptions("Output Options",
     41//                                       "These options control the output.");
    5142
    5243static cl::list<std::string> inputFiles(cl::Positional, cl::desc("<regex> <input file ...>"), cl::OneOrMore);
    5344
    54 static cl::opt<bool> CountOnly("c", cl::desc("Count and display the matching lines per file only."), cl::cat(bGrepOutputOptions));
    55 static cl::alias CountOnlyLong("count", cl::desc("Alias for -c"), cl::aliasopt(CountOnly));
    56 static cl::opt<bool> NormalizeLineBreaks("normalize-line-breaks", cl::desc("Normalize line breaks to std::endl."), cl::init(false),  cl::cat(bGrepOutputOptions));
     45// static cl::opt<bool> CountOnly("c", cl::desc("Count and display the matching lines per file only."), cl::cat(bGrepOutputOptions));
     46// static cl::alias CountOnlyLong("count", cl::desc("Alias for -c"), cl::aliasopt(CountOnly));
     47// static cl::opt<bool> NormalizeLineBreaks("normalize-line-breaks", cl::desc("Normalize line breaks to std::endl."), cl::init(false),  cl::cat(bGrepOutputOptions));
    5748
    58 static cl::opt<bool> ShowFileNames("H", cl::desc("Show the file name with each matching line."), cl::cat(bGrepOutputOptions));
    59 static cl::alias ShowFileNamesLong("with-filename", cl::desc("Alias for -H"), cl::aliasopt(ShowFileNames));
     49// static cl::opt<bool> ShowFileNames("H", cl::desc("Show the file name with each matching line."), cl::cat(bGrepOutputOptions));
     50// static cl::alias ShowFileNamesLong("with-filename", cl::desc("Alias for -H"), cl::aliasopt(ShowFileNames));
    6051
    6152static cl::opt<bool> CaseInsensitive("i", cl::desc("Ignore case distinctions in the pattern and the file."), cl::cat(aRegexSourceOptions));
    62 static cl::opt<bool> ShowLineNumbers("n", cl::desc("Show the line number with each matching line."), cl::cat(bGrepOutputOptions));
    63 static cl::alias ShowLineNumbersLong("line-number", cl::desc("Alias for -n"), cl::aliasopt(ShowLineNumbers));
     53// static cl::opt<bool> ShowLineNumbers("n", cl::desc("Show the line number with each matching line."), cl::cat(bGrepOutputOptions));
     54// static cl::alias ShowLineNumbersLong("line-number", cl::desc("Alias for -n"), cl::aliasopt(ShowLineNumbers));
    6455
    6556static cl::list<std::string> regexVector("e", cl::desc("Regular expression"), cl::ZeroOrMore, cl::cat(aRegexSourceOptions));
     
    6758static cl::opt<std::string> IRFileName("precompiled", cl::desc("Use precompiled regular expression"), cl::value_desc("LLVM IR file"), cl::init(""), cl::cat(aRegexSourceOptions));
    6859
    69 using namespace llvm;
     60
    7061
    7162static unsigned firstInputFile = 1;  // Normal case when first positional arg is a regex.
     
    143134    cl::ParseCommandLineOptions(argc, argv);
    144135   
    145     Encoding encoding(Encoding::Type::UTF_8, 8);
    146 
    147     llvm::Function * icgrep_IR = nullptr;
    148    
    149136    Module * M = new Module("grepcode", getGlobalContext());
    150137   
    151138    IDISA::IDISA_Builder * idb = GetNativeIDISA_Builder(M, VectorType::get(IntegerType::get(getGlobalContext(), 64), BLOCK_SIZE/64));
    152    
    153     gen_s2p_function(M, idb);
    154    
    155    
    156     generateScanBitBlockRoutine(M, idb, 64);
    157    
    158     if (IRFileName == "") {       
    159         re::RE * re_ast = get_icgrep_RE();
    160         re_ast = regular_expression_passes(encoding, re_ast);
    161        
    162         #ifdef PRINT_TIMING_INFORMATION
    163         const timestamp_t regex_compilation_start = read_cycle_counter();
    164         #endif
    165         pablo::PabloFunction * function = re2pablo_compiler(encoding, re_ast);
    166         #ifdef PRINT_TIMING_INFORMATION
    167         const timestamp_t regex_compilation_end = read_cycle_counter();
    168         std::cerr << "REGEX COMPILATION TIME: " << (regex_compilation_end - regex_compilation_start) << std::endl;
    169         #endif
    170139
    171         pablo_function_passes(function);
    172        
    173         pablo::PabloCompiler pablo_compiler(M, idb);
    174         try {
    175             icgrep_IR = pablo_compiler.compile(function);
    176             delete function;
    177             releaseSlabAllocatorMemory();
    178         } catch (std::runtime_error e) {
    179             delete function;
    180             releaseSlabAllocatorMemory();
    181             std::cerr << "Runtime error: " << e.what() << std::endl;
    182             exit(1);
    183         }
    184     } else {
    185         firstInputFile = 0;  // No regexp arguments; first positional argument is a file to process.
    186         SMDiagnostic ParseErr;
    187         M = parseIRFile(IRFileName, ParseErr, getGlobalContext()).release();
    188         if (!M) {
    189             throw std::runtime_error("Error in Parsing IR File " + IRFileName);
    190         }
    191         icgrep_IR = M->getFunction("process_block");
    192     }
    193     llvm::Function * s2p_IR = M->getFunction("s2p_block");
    194    
    195    // llvm::Function * scanRoutine = M->getFunction("scan_matches_in_bitblock");
    196    
    197     if (s2p_IR == nullptr) {
    198         std::cerr << "No s2p_IR!\n";
    199         exit(1);
    200     }
    201    
     140    PipelineBuilder pipelineBuilder(M, idb);
     141
     142    re::RE * re_ast = get_icgrep_RE();
     143    Encoding encoding(Encoding::Type::UTF_8, 8);
     144    re_ast = regular_expression_passes(encoding, re_ast);   
     145    pablo::PabloFunction * function = re2pablo_compiler(encoding, re_ast);
     146
     147    pipelineBuilder.CreateKernels(function, false);
     148
     149    pipelineBuilder.ExecuteKernels();
     150
     151    llvm::Function * main_IR = M->getFunction("Main");
    202152    llvm::ExecutionEngine * engine = JIT_to_ExecutionEngine(M);
    203153   
    204154    icgrep_Linking(M, engine);
    205155    verifyModule(*M, &dbgs());
    206    
    207     // Ensure everything is ready to go.
    208156    engine->finalizeObject();
    209    
    210     // TODO getPointerToFunction() is deprecated. Investigate getFunctionAddress(string name) instead.
    211     void * icgrep_init_carry_ptr = engine->getPointerToFunction(M->getFunction("process_block_initialize_carries"));
    212     void * icgrep_MCptr = engine->getPointerToFunction(icgrep_IR);
    213     void * s2p_MCptr = engine->getPointerToFunction(s2p_IR);
    214     // void * scan_MCptr = engine->getPointerToFunction(scanRoutine);
    215     if (s2p_MCptr == nullptr) {
    216         std::cerr << "No s2p_MCptr!\n";
    217         exit(1);
    218     }
    219157
    220     if (icgrep_MCptr) {
    221         GrepExecutor grepEngine(s2p_MCptr, icgrep_init_carry_ptr, icgrep_MCptr);
    222         //GrepExecutor grepEngine(s2p_MCptr, icgrep_init_carry_ptr, icgrep_MCptr, scan_MCptr);
    223         grepEngine.setCountOnlyOption(CountOnly);
    224         grepEngine.setNormalizeLineBreaksOption(NormalizeLineBreaks);
    225         grepEngine.setShowLineNumberOption(ShowLineNumbers);
    226         if (inputFiles.size() > (firstInputFile + 1) || ShowFileNames) {
    227             grepEngine.setShowFileNameOption();
    228         }
    229         #ifdef PRINT_TIMING_INFORMATION
    230         papi::PapiCounter<4> papiCounters({PAPI_RES_STL, PAPI_STL_CCY, PAPI_FUL_CCY, PAPI_MEM_WCY});
    231         #endif
     158    void * main_MCptr = engine->getPointerToFunction(main_IR);
     159
     160    if(main_MCptr){
     161        GrepExecutor grepEngine(main_MCptr);
    232162        for (unsigned i = firstInputFile; i != inputFiles.size(); ++i) {
    233             #ifdef PRINT_TIMING_INFORMATION
    234             papiCounters.start();
    235             const timestamp_t execution_start = read_cycle_counter();
    236             #endif
    237163            grepEngine.doGrep(inputFiles[i]);
    238             #ifdef PRINT_TIMING_INFORMATION
    239             const timestamp_t execution_end = read_cycle_counter();
    240             papiCounters.stop();
    241             std::cerr << "EXECUTION TIME: " << inputFiles[i] << ":" << "CYCLES|" << (execution_end - execution_start) << papiCounters << std::endl;
    242             #endif
    243164        }
    244165    }
     
    246167    //engine->freeMachineCodeForFunction(icgrep_IR); // Removed in LLVM 3.6. MC will be automatically freed in destructors.
    247168    delete engine;
    248     delete idb;
    249169
    250170    return 0;
  • icGREP/icgrep-devel/icgrep/kernels/pipeline.cpp

    r4935 r4939  
    2828}
    2929
    30 void PipelineBuilder::CreateKernels(pablo::PabloFunction * function){
     30void PipelineBuilder::CreateKernels(pablo::PabloFunction * function, bool isNameExpression){
    3131    mS2PKernel = new KernelBuilder("s2p", mMod, iBuilder);
    3232    mICgrepKernel = new KernelBuilder("icgrep", mMod, iBuilder);
     
    3535
    3636    generateS2PKernel(mMod, iBuilder, mS2PKernel);
    37     generateScanMatch(mMod, iBuilder, 64, mScanMatchKernel);
     37    generateScanMatch(mMod, iBuilder, 64, mScanMatchKernel, isNameExpression);
    3838
    3939    pablo_function_passes(function);
  • icGREP/icgrep-devel/icgrep/kernels/pipeline.h

    r4933 r4939  
    3434        ~PipelineBuilder();
    3535
    36         void CreateKernels(pablo::PabloFunction * function);
     36        void CreateKernels(pablo::PabloFunction * function, bool isNameExpression);
    3737    void ExecuteKernels();
    3838
  • icGREP/icgrep-devel/icgrep/kernels/scanmatchgen.cpp

    r4937 r4939  
    44 */
    55
    6 
     6#include "kernel.h"
    77#include "scanmatchgen.h"
    88#include <llvm/IR/Intrinsics.h>
     
    3232    return iBuilder->CreateAnd(bits_minus1, bits);
    3333}
    34 
    35 /*
    36        
    37 void write_matches_ending_in_segment(scanword_t matches, scanword_t lbreaks, ssize_t segmentPos, ssize_t & pendingLineStart, int & lineNum) {
    38     scanword_t remaining_matches = matches;
    39     scanword_t remaining_LBs = lbreaks;
    40     while (remaining_matches != 0) {
    41         // Find all the line marks prior to the match position
    42         scanword_t priorLineMarks = ForwardZeroesMask(remaining_matches) & remaining_LBs;
    43         if (priorLineMarks != 0) {
    44             int matchLineNum = lineNum + popcount(priorLineMarks);
    45             // The last of these line marks prior to the match position is the
    46             // starting positions of the matched line.
    47             matchLineStart = segmentPos + segmentBitWidth - CountReverseZeroes(priorLineMarks);
    48         }
    49         else {
    50             matchLineNum = lineNum;
    51             matchLineStart = pendingLineStart;
    52         }
    53         // The line end is marked by the match posiiton.
    54         matchLineEnd = segmentPos + CountForwardZeroes(remaining_matches);
    55         call write_match(matchLineNum, matchLineStart, matchLineEnd);
    56        
    57         remaining_matches = ResetLowestBit(remaining_matches);
    58         remaining_LBs = remaining_LBs ^ priorLineMarks;
    59         lineNum = matchLineNum;
    60     }
    61     if (remaining_LBs != 0) {
    62         lineNum += popcount(remaining_LBs);
    63         pendingLineStart = segmentPos + segmentBitWidth - CountReverseZeroes(remaining_LBs);
    64     }
    65 }   
    66         */
    67 
    68        
    69        
    70 void generateScanSegmentRoutine(Module * m, IDISA::IDISA_Builder * iBuilder, int segBitWidth) {
     34       
     35       
     36void generateScanWordRoutine(Module * m, IDISA::IDISA_Builder * iBuilder, int scanwordBitWidth, Type * kernelStuctType, bool isNameExpression) {
    7137    LLVMContext & ctxt = m->getContext();
    72     Type * T = iBuilder->getIntNTy(segBitWidth);
     38    Type * T = iBuilder->getIntNTy(scanwordBitWidth);   
     39    Type * S = PointerType::get(iBuilder->getIntNTy(8), 0);
    7340    Type * returnType = StructType::get(ctxt, std::vector<Type *>({T, T}));
    74     FunctionType * functionType = FunctionType::get(returnType, std::vector<Type *>({T, T, T, T, T}), false);
     41    FunctionType * functionType = FunctionType::get(returnType, std::vector<Type *>({kernelStuctType, T, T, T, T, T}), false);
    7542    Function * sFunction;
    7643       
     
    8451    AttributeSet AttrSet = AttributeSet::get(ctxt, Attrs);
    8552   
    86     sFunction = Function::Create(functionType, GlobalValue::ExternalLinkage, "scan_matches_in_segment", m);
     53    sFunction = Function::Create(functionType, GlobalValue::ExternalLinkage, "scan_matches_in_scanword", m);
    8754    sFunction->setCallingConv(CallingConv::C);
    8855    sFunction->setAttributes(AttrSet);
    8956       
    9057    Function::arg_iterator args = sFunction->arg_begin();
     58    Value * this_input_parm = args++;
     59    this_input_parm->setName("this");
    9160    Value * matches_input_parm = args++;
    9261    matches_input_parm->setName("matches");
    9362    Value * record_breaks_input_parm = args++;
    9463    record_breaks_input_parm->setName("breaks");
    95     Value * segmentPos = args++;
    96     segmentPos->setName("segmentPos");
     64    Value * scanwordPos = args++;
     65    scanwordPos->setName("scanwordPos");
    9766    Value * recordStart_input_parm = args++;
    9867    recordStart_input_parm->setName("pendingLineStart");
    9968    Value * recordNum_input_parm = args++;
    10069    recordNum_input_parm->setName("lineNum");
    101    
    102     Constant * matchProcessor = m->getOrInsertFunction("wrapped_report_match", Type::getVoidTy(ctxt), T, T, T, nullptr);
    103 
     70    Constant * matchProcessor;
     71    if(isNameExpression)
     72        matchProcessor = m->getOrInsertFunction("insert_codepoints", Type::getVoidTy(ctxt), T, T, T, S, nullptr);
     73    else
     74        matchProcessor = m->getOrInsertFunction("wrapped_report_match", Type::getVoidTy(ctxt), T, T, T, S, T, S, nullptr);
    10475   
    10576    iBuilder->SetInsertPoint(BasicBlock::Create(ctxt, "entry", sFunction,0));
     
    11687       
    11788    // The match scanner works with a loop involving four variables:
    118     // (a) the bit stream segment of matches marking the ends of selected records,
    119     // (b) the bit stream segment of record_breaks marking the ends of all records,
     89    // (a) the bit stream scanword of matches marking the ends of selected records,
     90    // (b) the bit stream scanword of record_breaks marking the ends of all records,
    12091    // (c) the integer lastRecordNum indicating the number of records processed so far,
    12192    // (d) the index lastRecordStart indicating the file position of the last record.
     
    154125    Value * matchRecordNum = iBuilder->CreateAdd(generatePopcount(iBuilder, prior_breaks), recordNum_phi);
    155126    Value * reverseDistance = generateCountReverseZeroes(iBuilder, prior_breaks);
    156     Value * width = ConstantInt::get(T, segBitWidth);
    157     Value * matchRecordStart = iBuilder->CreateAdd(segmentPos, iBuilder->CreateSub(width, reverseDistance));
     127    Value * width = ConstantInt::get(T, scanwordBitWidth);
     128    Value * matchRecordStart = iBuilder->CreateAdd(scanwordPos, iBuilder->CreateSub(width, reverseDistance));
    158129    iBuilder->CreateBr(loop_final_block);
    159130   
     
    168139    matchRecordStart_phi->addIncoming(recordStart_phi, process_matches_loop_entry);
    169140    matchRecordStart_phi->addIncoming(matchRecordStart, prior_breaks_block);
    170     Value * matchRecordEnd = iBuilder->CreateAdd(segmentPos, generateCountForwardZeroes(iBuilder, matches_phi));
    171     iBuilder->CreateCall(matchProcessor, std::vector<Value *>({matchRecordNum_phi, matchRecordStart_phi, matchRecordEnd}));
     141    Value * matchRecordEnd = iBuilder->CreateAdd(scanwordPos, generateCountForwardZeroes(iBuilder, matches_phi));
     142
     143    Value* filebuf_gep = iBuilder->CreateGEP(this_input_parm, {iBuilder->getInt64(0), iBuilder->getInt32(0), iBuilder->getInt32(7)});
     144    Value* filebufptr = iBuilder->CreateLoad(filebuf_gep, "filebuf");
     145
     146    Value* filesize_gep = iBuilder->CreateGEP(this_input_parm, {iBuilder->getInt64(0), iBuilder->getInt32(0), iBuilder->getInt32(8)});
     147    Value* filesize = iBuilder->CreateLoad(filesize_gep, "filensize");
     148
     149    Value* filename_gep = iBuilder->CreateGEP(this_input_parm, {iBuilder->getInt64(0), iBuilder->getInt32(0), iBuilder->getInt32(9)});
     150    Value* filenameptr = iBuilder->CreateLoad(filename_gep, "filename");
     151
     152    if(isNameExpression)
     153        iBuilder->CreateCall(matchProcessor, std::vector<Value *>({matchRecordNum_phi, matchRecordStart_phi, matchRecordEnd, filebufptr}));
     154    else
     155        iBuilder->CreateCall(matchProcessor, std::vector<Value *>({matchRecordNum_phi, matchRecordStart_phi, matchRecordEnd, filebufptr, filesize, filenameptr}));
    172156    Value * remaining_matches = generateResetLowestBit(iBuilder, matches_phi);
    173157    Value * remaining_breaks = iBuilder->CreateXor(record_breaks_phi, prior_breaks);
     
    190174    Value * final_record_num = iBuilder->CreateAdd(recordNum_phi, break_count);
    191175    Value * reverseZeroes = generateCountReverseZeroes(iBuilder, record_breaks_phi);
    192     Value * pendingLineStart = iBuilder->CreateAdd(segmentPos, iBuilder->CreateSub(width, reverseZeroes));
     176    Value * pendingLineStart = iBuilder->CreateAdd(scanwordPos, iBuilder->CreateSub(width, reverseZeroes));
    193177    iBuilder->CreateBr(return_block);
    194178   
     
    202186    finalRecordStart_phi->addIncoming(pendingLineStart, remaining_breaks_block);
    203187    Value * retVal = UndefValue::get(returnType);
    204     retVal = iBuilder->CreateInsertValue(retVal, finalRecordCount_phi, 0);
    205     retVal = iBuilder->CreateInsertValue(retVal, finalRecordStart_phi, 1);
     188    retVal = iBuilder->CreateInsertValue(retVal, finalRecordStart_phi, 0);
     189    retVal = iBuilder->CreateInsertValue(retVal, finalRecordCount_phi, 1);
    206190    iBuilder->CreateRet(retVal);
    207191   
     
    209193
    210194
    211 void generateScanBitBlockRoutine(Module * m, IDISA::IDISA_Builder * iBuilder, int segBitWidth) {
    212     LLVMContext & ctxt = m->getContext();
    213     Type * B = iBuilder->getBitBlockType();
    214     Type * T = iBuilder->getIntNTy(segBitWidth);
    215     generateScanSegmentRoutine(m, iBuilder, segBitWidth);
    216     int fieldCount = iBuilder->getBitBlockWidth()/segBitWidth;
    217     Type * segmentVectorType =  VectorType::get(T, fieldCount);
    218    
    219    
    220     Type * returnType = StructType::get(ctxt, std::vector<Type *>({T, T}));
    221     FunctionType * functionType = FunctionType::get(returnType, std::vector<Type *>({B, B, T, T, T}), false);
    222     Function * sFunction;
    223    
    224     SmallVector<AttributeSet, 6> Attrs;
    225     Attrs.push_back(AttributeSet::get(ctxt, ~0U, std::vector<Attribute::AttrKind>({ Attribute::NoUnwind, Attribute::UWTable })));
    226     Attrs.push_back(AttributeSet::get(ctxt, 1, std::vector<Attribute::AttrKind>({})));
    227     Attrs.push_back(AttributeSet::get(ctxt, 2, std::vector<Attribute::AttrKind>({})));
    228     Attrs.push_back(AttributeSet::get(ctxt, 3, std::vector<Attribute::AttrKind>({})));
    229     Attrs.push_back(AttributeSet::get(ctxt, 4, std::vector<Attribute::AttrKind>({})));
    230     Attrs.push_back(AttributeSet::get(ctxt, 5, std::vector<Attribute::AttrKind>({})));
    231     AttributeSet AttrSet = AttributeSet::get(ctxt, Attrs);
    232     sFunction = Function::Create(functionType, GlobalValue::ExternalLinkage, "scan_matches_in_bitblock", m);
    233     sFunction->setCallingConv(CallingConv::C);
    234     sFunction->setAttributes(AttrSet);
    235    
    236    
    237    
    238     Function::arg_iterator args = sFunction->arg_begin();
    239     Value * matches_input_parm = args++;
    240     matches_input_parm->setName("matches");
    241     Value * record_breaks_input_parm = args++;
    242     record_breaks_input_parm->setName("breaks");
    243     Value * blockPos = args++;
    244     blockPos->setName("blockPos");
    245     Value * recordStart_input_parm = args++;
    246     recordStart_input_parm->setName("pendingLineStart");
    247     Value * recordNum_input_parm = args++;
    248     recordNum_input_parm->setName("lineNum");
    249    
    250     iBuilder->SetInsertPoint(BasicBlock::Create(ctxt, "entry", sFunction,0));
    251    
    252     Value * matchSegVector = iBuilder->CreateBitCast(matches_input_parm, segmentVectorType);
    253     Value * breakSegVector = iBuilder->CreateBitCast(record_breaks_input_parm, segmentVectorType);
    254     Value * segmentPos = blockPos;
    255     Value * recordStart = recordStart_input_parm;
    256     Value * recordNum = recordNum_input_parm;
    257     Value * segResult = nullptr;
    258     Function * segScanFcn = m->getFunction("scan_matches_in_segment");
    259     for (uint64_t i = 0; i < iBuilder->getBitBlockWidth()/segBitWidth; i++) {
    260         Value * matchSeg = iBuilder->CreateExtractElement(matchSegVector, ConstantInt::get(T, i));
    261         Value * recordBreaksSeg = iBuilder->CreateExtractElement(breakSegVector, ConstantInt::get(T, i));
    262         segResult = iBuilder->CreateCall(segScanFcn, std::vector<Value *>({matchSeg, recordBreaksSeg, segmentPos, recordStart, recordNum}));
    263         segmentPos = iBuilder->CreateAdd(segmentPos, ConstantInt::get(T, segBitWidth));
    264         recordStart = iBuilder->CreateExtractValue(segResult, std::vector<unsigned>({0}));
    265         recordNum = iBuilder->CreateExtractValue(segResult, std::vector<unsigned>({1}));
     195void generateScanMatch(Module * m, IDISA::IDISA_Builder * iBuilder, int scanwordBitWidth, KernelBuilder * kBuilder, bool isNameExpression){
     196   
     197   
     198    Type * T = iBuilder->getIntNTy(scanwordBitWidth);
     199    Type * S = PointerType::get(iBuilder->getIntNTy(8), 0);
     200    int fieldCount = iBuilder->getBitBlockWidth()/scanwordBitWidth;
     201    Type * scanwordVectorType =  VectorType::get(T, fieldCount);
     202
     203    kBuilder->addKernelInputStream(1, "matches");
     204    kBuilder->addKernelInputStream(1, "breaks");
     205    //use index
     206    int blockPosIdx = kBuilder->extendKernelInternalStateType(T);
     207    int lineStartIdx = kBuilder->extendKernelInternalStateType(T);
     208    int lineNumIdx = kBuilder->extendKernelInternalStateType(T);
     209    kBuilder->extendKernelInternalStateType(S);
     210    kBuilder->extendKernelInternalStateType(T);
     211    kBuilder->extendKernelInternalStateType(S);
     212
     213    int segBlocks = kBuilder->getSegmentBlocks();
     214
     215    kBuilder->PrepareDoBlockFunction();
     216
     217    Type * kernelStuctType = PointerType::get(kBuilder->getKernelStructType(), 0);
     218    generateScanWordRoutine(m, iBuilder, scanwordBitWidth, kernelStuctType, isNameExpression);
     219
     220    struct Inputs inputs = kBuilder->openDoBlock();
     221    struct Outputs outputs;   
     222    Value * kernelStuctParam = kBuilder->getKernelStructParam();
     223   
     224    Value * scanwordPos = kBuilder->getKernelInternalState(blockPosIdx);
     225    Value * recordStart = kBuilder->getKernelInternalState(lineStartIdx);
     226    Value * recordNum = kBuilder->getKernelInternalState(lineNumIdx);
     227    Value * wordResult = nullptr;
     228
     229    Function * wordScanFcn = m->getFunction("scan_matches_in_scanword");
     230    for(int j=0; j<segBlocks; j++){
     231        Value * matchWordVector = iBuilder->CreateBitCast(inputs.streams[j][0], scanwordVectorType);
     232        Value * breakWordVector = iBuilder->CreateBitCast(inputs.streams[j][1], scanwordVectorType);
     233        for(int i=0; i<segBlocks*iBuilder->getBitBlockWidth()/scanwordBitWidth; i++){
     234
     235            Value * matchWord = iBuilder->CreateExtractElement(matchWordVector, ConstantInt::get(T, i));
     236            Value * recordBreaksWord = iBuilder->CreateExtractElement(breakWordVector, ConstantInt::get(T, i));
     237            wordResult = iBuilder->CreateCall(wordScanFcn, std::vector<Value *>({kernelStuctParam, matchWord, recordBreaksWord, scanwordPos, recordStart, recordNum}));
     238            scanwordPos = iBuilder->CreateAdd(scanwordPos, ConstantInt::get(T, scanwordBitWidth));
     239            recordStart = iBuilder->CreateExtractValue(wordResult, std::vector<unsigned>({0}));
     240            recordNum = iBuilder->CreateExtractValue(wordResult, std::vector<unsigned>({1}));
     241        }
    266242    }
    267     iBuilder->CreateRet(segResult);
    268 }
    269 
    270 
    271 
    272 
     243
     244    kBuilder->changeKernelInternalState(blockPosIdx, scanwordPos);
     245    kBuilder->changeKernelInternalState(lineStartIdx, recordStart);
     246    kBuilder->changeKernelInternalState(lineNumIdx, recordNum);
     247
     248    kBuilder->closeDoBlock(outputs);
     249
     250    kBuilder->finalizeMethods();
     251}
     252
     253
     254
  • icGREP/icgrep-devel/icgrep/kernels/scanmatchgen.h

    r4936 r4939  
    1111#include <llvm/IR/Module.h>
    1212       
    13 void generateScanBitBlockRoutine(Module * m, IDISA::IDISA_Builder * iBuilder, int segBitWidth);
     13void generateScanBitBlockRoutine(Module * m, IDISA::IDISA_Builder * iBuilder, int segBitWidth, Type * kernelStuctType, bool isNameExpression);
     14
     15void generateScanMatch(Module * m, IDISA::IDISA_Builder * iBuilder, int segBitWidth, KernelBuilder * kBuilder, bool isNameExpression);
    1416
    1517#endif // SCANMATCHGEN_H
  • icGREP/icgrep-devel/icgrep/pablo/carry_manager.cpp

    r4927 r4939  
    55 */
    66
    7 #include <include/simd-lib/bitblock.hpp>
    87#include <stdexcept>
    98#include <pablo/carry_data.h>
     
    6160 * @brief initialize
    6261 ** ------------------------------------------------------------------------------------------------------------- */
    63 void CarryManager::initialize(Module * m, PabloBlock * pb) {
     62void CarryManager::initialize(PabloBlock * pb, KernelBuilder * kBuilder) {
    6463    mRootScope = pb;
    6564    mCarryInfoVector.resize(doScopeCount(pb));
     
    7574   
    7675    ArrayType* cdArrayTy = ArrayType::get(mBitBlockType, mTotalCarryDataBitBlocks);
    77     GlobalVariable* cdArray = new GlobalVariable(*m, cdArrayTy, /*isConstant=*/false, GlobalValue::CommonLinkage, /*Initializer=*/0, "process_block_carry_data");
    78     cdArray->setAlignment(mBitBlockWidth / 8);
    79     ConstantAggregateZero* cdInitData = ConstantAggregateZero::get(cdArrayTy);
    80     cdArray->setInitializer(cdInitData);
     76    mCdArrayIdx = kBuilder->extendKernelInternalStateType(cdArrayTy);
    8177   
    82     mCarryPackBasePtr = iBuilder->CreateBitCast(cdArray, PointerType::get(mCarryPackType, 0));
    83     mCarryBitBlockPtr = iBuilder->CreateBitCast(cdArray, PointerType::get(mBitBlockType, 0));
    84    
    85     generateCarryDataInitializer(m);
    86    
    87     // Popcount data is stored after all the carry data.
    8878    if (mPabloCountCount > 0) {
    8979        ArrayType* pcArrayTy = ArrayType::get(iBuilder->getIntNTy(64), mPabloCountCount);
    90         GlobalVariable* pcArray = new GlobalVariable(*m, pcArrayTy, /*isConstant=*/false, GlobalValue::CommonLinkage, 0, "popcount_data");
    91         cdArray->setAlignment(mBitBlockWidth/8);
    92         ConstantAggregateZero* pcInitData = ConstantAggregateZero::get(pcArrayTy);
    93         pcArray->setInitializer(pcInitData);
    94         mPopcountBasePtr = iBuilder->CreateBitCast(pcArray, Type::getInt64PtrTy(iBuilder->getContext()));
    95     }
    96     // Carry Data area will have one extra bit block to store the block number.
    97     GlobalVariable* blkNo = new GlobalVariable(*m, iBuilder->getIntNTy(64), /*isConstant=*/false, GlobalValue::CommonLinkage, 0, "blockNo");
    98     blkNo->setAlignment(16);
    99     blkNo->setInitializer(iBuilder->getInt64(0));
    100     mBlockNoPtr = blkNo;
    101     mBlockNo = iBuilder->CreateLoad(mBlockNoPtr);
    102     /*  Set the current scope to PabloRoot */
     80        mPcArrayIdx = kBuilder->extendKernelInternalStateType(pcArrayTy);
     81    }
     82 
    10383    mCurrentScope = mRootScope;
    10484    mCurrentFrameIndex = 0;
    10585    mCarryInfo = mCarryInfoVector[0];
    10686    mCarryOutPack[summaryPack()] = Constant::getNullValue(mCarryPackType);
     87}
     88
     89void CarryManager::initialize_setPtrs(KernelBuilder * kBuilder) {
     90   
     91    Value * cdArrayPtr = kBuilder->getKernelInternalStatePtr(mCdArrayIdx);
     92 
     93    mCarryPackBasePtr = iBuilder->CreateBitCast(cdArrayPtr, PointerType::get(mCarryPackType, 0));
     94    mCarryBitBlockPtr = iBuilder->CreateBitCast(cdArrayPtr, PointerType::get(mBitBlockType, 0));
     95   
     96   
     97    if (mPabloCountCount > 0) {
     98        Value * pcArrayPtr = kBuilder->getKernelInternalStatePtr(mPcArrayIdx);
     99        mPopcountBasePtr = iBuilder->CreateBitCast(pcArrayPtr, Type::getInt64PtrTy(iBuilder->getContext()));
     100    }
     101 
     102    mBlockNo = iBuilder->CreateUDiv(kBuilder->getKernelInternalState(mFilePosIdx), iBuilder->getInt64(mBitBlockWidth));
     103    mCurrentScope = mRootScope;
     104    mCurrentFrameIndex = 0;
     105    mCarryInfo = mCarryInfoVector[0];
     106    mCarryOutPack[summaryPack()] = Constant::getNullValue(mCarryPackType);
     107}
     108
     109void CarryManager::set_BlockNo(KernelBuilder * kBuilder){
     110    mBlockNo = iBuilder->CreateUDiv(kBuilder->getKernelInternalState(mFilePosIdx), iBuilder->getInt64(mBitBlockWidth));
    107111}
    108112
     
    301305
    302306/** ------------------------------------------------------------------------------------------------------------- *
    303  * @brief blendCarrySummaryWithOuterSummary
     307 * @brief addOuterSummaryToNestedSummary
    304308 ** ------------------------------------------------------------------------------------------------------------- */
    305309void CarryManager::addOuterSummaryToNestedSummary() {
     
    550554 * @brief generateBlockNoIncrement
    551555 ** ------------------------------------------------------------------------------------------------------------- */
    552 void CarryManager::generateBlockNoIncrement() {
    553     iBuilder->CreateStore(iBuilder->CreateAdd(mBlockNo, iBuilder->getInt64(1)), mBlockNoPtr);
    554 }
     556// void CarryManager::generateBlockNoIncrement() {
     557//     iBuilder->CreateStore(iBuilder->CreateAdd(mBlockNo, iBuilder->getInt64(1)), mBlockNoPtr);
     558// }
    555559
    556560/* Helper routines */
  • icGREP/icgrep-devel/icgrep/pablo/carry_manager.h

    r4927 r4939  
    1313#include <pablo/carry_data.h>
    1414#include <llvm/IR/Constants.h>
    15 
     15#include "../kernels/kernel.h"
    1616
    1717/*
     
    5353    , mTotalCarryDataBitBlocks(0)
    5454    , mCarryDataAllocationSize(0)
     55    , mFilePosIdx(2)
    5556    {
    5657
     
    5960    ~CarryManager();
    6061   
    61     void initialize(Module * m, PabloBlock * blk);
     62    void initialize(PabloBlock * blk, KernelBuilder * kBuilder);
     63
     64    void initialize_setPtrs(KernelBuilder * kBuilder);
     65
     66    void set_BlockNo(KernelBuilder * kBuilder);
    6267   
    6368    void generateCarryDataInitializer(Module * m);
     
    155160    std::vector<Value *> mCarryOutPack;
    156161    std::vector<Value *> mCarrySummary;
     162    int mCdArrayIdx;
     163    int mPcArrayIdx;
     164    int mFilePosIdx;
    157165};
    158166
  • icGREP/icgrep-devel/icgrep/pablo/pablo_compiler.cpp

    r4927 r4939  
    7373, mCarryManager(nullptr)
    7474, mInputType(nullptr)
     75, mKBuilder(nullptr)
    7576, mWhileDepth(0)
    7677, mIfDepth(0)
     
    7879, mInputAddressPtr(nullptr)
    7980, mOutputAddressPtr(nullptr)
    80 , mMaxWhileDepth(0) {
     81, mMaxWhileDepth(0)
     82, mFilePosIdx(2) {
    8183   
    8284}
     
    8486PabloCompiler::~PabloCompiler() {
    8587}
    86        
     88 
     89void PabloCompiler::setKernel(KernelBuilder * kBuilder){
     90    mKBuilder = kBuilder;   
     91}
     92
    8793llvm::Function * PabloCompiler::compile(PabloFunction * function) {
    8894
     
    98104
    99105    mCarryManager = new CarryManager(iBuilder);
    100    
    101     GenerateFunction(*function);
    102    
    103     iBuilder->SetInsertPoint(BasicBlock::Create(mMod->getContext(), "entry", mFunction,0));
    104 
    105     //The basis bits structure
    106     for (unsigned i = 0; i != function->getNumOfParameters(); ++i) {
    107         Value* indices[] = {iBuilder->getInt64(0), iBuilder->getInt32(i)};
    108         Value * gep = iBuilder->CreateGEP(mInputAddressPtr, indices);
    109         LoadInst * basisBit = iBuilder->CreateAlignedLoad(gep, iBuilder->getBitBlockWidth()/8, false, function->getParameter(i)->getName()->to_string());
    110         mMarkerMap[function->getParameter(i)] = basisBit;
    111         if (DumpTrace) {
    112             iBuilder->genPrintRegister(function->getParameter(i)->getName()->to_string(), basisBit);
    113         }
    114     }
    115      
    116     //Generate the IR instructions for the function.
    117    
    118     mCarryManager->initialize(mMod, mainScope);
    119 
    120     compileBlock(mainScope);
    121    
    122     mCarryManager->generateBlockNoIncrement();
    123 
    124     if (DumpTrace) {
    125         iBuilder->genPrintRegister("mBlockNo", iBuilder->CreateAlignedLoad(iBuilder->CreateBitCast(mCarryManager->getBlockNoPtr(), PointerType::get(mBitBlockType, 0)), iBuilder->getBitBlockWidth()/8, false));
    126     }
    127    
    128     // Write the output values out
    129     for (unsigned i = 0; i != function->getNumOfResults(); ++i) {
    130         assert (function->getResult(i));
    131         SetOutputValue(mMarkerMap[function->getResult(i)], i);
    132     }
    133 
    134     //Terminate the block
    135     ReturnInst::Create(mMod->getContext(), iBuilder->GetInsertBlock());
    136    
    137     // Clean up
     106
     107    GenerateKernel(mainScope, function);
     108       
    138109    delete mCarryManager;
    139110    mCarryManager = nullptr;
     
    144115    #endif
    145116
    146 //    llvm::PassManager pm;
    147 //    llvm::PassManagerBuilder pmb;
    148 //    pmb.OptLevel = 3;
    149 //    pmb.populateModulePassManager(pm);
    150 //    pm.run(*mMod);
    151117
    152118    if (LLVM_UNLIKELY(DumpGeneratedIR)) {
     
    167133
    168134    return mFunction;
     135}
     136
     137inline void PabloCompiler::GenerateKernel(PabloBlock * mainScope, PabloFunction * function) {
     138 
     139    for(int i=0; i<8; i++){
     140        mKBuilder->addKernelInputStream(1, "basis_bits");
     141    }
     142    mKBuilder->addKernelOutputStream(1);
     143    mKBuilder->addKernelOutputStream(1);
     144
     145    mCarryManager->initialize(mainScope, mKBuilder);
     146 
     147    int segBlocks = mKBuilder->getSegmentBlocks();
     148    mKBuilder->PrepareDoBlockFunction();
     149    struct Inputs inputs = mKBuilder->openDoBlock();
     150    struct Outputs outputs;
     151    mFunction = mKBuilder->getDoBlockFunction();
     152
     153    mCarryManager->initialize_setPtrs(mKBuilder);
     154
     155    valptr results[segBlocks][2];
     156    for(int j=0; j<segBlocks; j++){     
     157        for(int i=0; i<inputs.streams[j].size(); i++){
     158            mMarkerMap[function->getParameter(i)] = inputs.streams[j][i];
     159        }
     160
     161        compileBlock(mainScope);
     162
     163        Value * filePos = iBuilder->CreateAdd(mKBuilder->getKernelInternalState(mFilePosIdx), iBuilder->getInt64(iBuilder->getBitBlockWidth()));
     164        mKBuilder->changeKernelInternalState(mFilePosIdx, filePos);
     165
     166        mCarryManager->set_BlockNo(mKBuilder);
     167
     168        results[j][0] = mMarkerMap[function->getResult(0)];
     169        results[j][1] = mMarkerMap[function->getResult(1)];
     170        outputs.streams.push_back(results[j]);
     171    }   
     172
     173    mKBuilder->closeDoBlock(outputs);
     174    mKBuilder->finalizeMethods();
    169175}
    170176
  • icGREP/icgrep-devel/icgrep/pablo/pablo_compiler.h

    r4900 r4939  
    2929#include <llvm/IR/IRBuilder.h>
    3030#include <IDISA/idisa_builder.h>
     31#include <kernels/kernel.h>
    3132
    3233namespace llvm {
     
    7576    PabloCompiler(Module * m, IDISA::IDISA_Builder * b);
    7677    ~PabloCompiler();
    77     Function * compile(pablo::PabloFunction * function);
     78    Function * compile(pablo::PabloFunction * function);   
     79    void setKernel(KernelBuilder * kBuilder);
     80   
    7881private:
    7982    void GenerateFunction(PabloFunction & function);
     
    8891    void compileWhile(const While * whileStmt);
    8992    Value* compileExpression(const PabloAST * expr);
     93    void GenerateKernel(PabloBlock * block, PabloFunction * function);
    9094
    9195    ASTToValueMap                       mMarkerMap;
     
    100104
    101105    PabloBlock *                        mPabloBlock;
     106
     107    KernelBuilder *                     mKBuilder;
    102108   
    103109    unsigned                            mWhileDepth;
     
    109115
    110116    unsigned                            mMaxWhileDepth;
     117    int                                 mFilePosIdx;
    111118
    112119};
  • icGREP/icgrep-devel/icgrep/re/re_parser.cpp

    r4907 r4939  
    2222#include "utf_encoding.h"
    2323#include <llvm/IR/Type.h>
    24 #include <kernels/s2p_gen.h>
    2524#include <pablo/pablo_compiler.h>
    2625#include <do_grep.h>
    2726#include <sstream>
    2827#include <algorithm>
     28#include "../kernels/pipeline.h"
     29#include "../toolchain.h"
    2930
    3031
     
    512513    return createName(std::move(canonicalize(start, mCursor.pos())));
    513514}
    514 
     515/*
    515516Name * RE_Parser::parseNamePatternExpression(){
    516517
     
    570571    return nullptr;
    571572}
    572 
     573*/
     574Name * RE_Parser::parseNamePatternExpression(){
     575
     576    ModeFlagSet outerFlags = fModeFlagSet;
     577    fModeFlagSet = 1;
     578
     579    bool outerNested = fNested;
     580    fNested = true;
     581
     582    RE * nameRE = parse_RE();
     583
     584    // Reset outer parsing state.
     585    fModeFlagSet = outerFlags;
     586    fNested = outerNested;
     587
     588    // Embed the nameRE in ";.*$nameRE" to skip the codepoint field of Uname.txt
     589    RE * embedded = makeSeq({mMemoizer.memoize(makeCC(0x3B)), makeRep(makeAny(), 0, Rep::UNBOUNDED_REP), nameRE});
     590    Encoding encoding(Encoding::Type::UTF_8, 8);
     591    embedded = regular_expression_passes(encoding, embedded);
     592
     593    pablo::PabloFunction * const nameSearchFunction = re2pablo_compiler(encoding, embedded);
     594    pablo_function_passes(nameSearchFunction);
     595   
     596    Module * M = new Module("NamePattern", getGlobalContext());
     597    IDISA::IDISA_Builder * idb = GetNativeIDISA_Builder(M, VectorType::get(IntegerType::get(getGlobalContext(), 64), BLOCK_SIZE/64));
     598   
     599    PipelineBuilder pipelineBuilder(M, idb);
     600    pipelineBuilder.CreateKernels(nameSearchFunction, true);
     601    pipelineBuilder.ExecuteKernels();
     602
     603    llvm::Function * main_IR = M->getFunction("Main");
     604    llvm::ExecutionEngine * engine = JIT_to_ExecutionEngine(M);
     605   
     606    icgrep_Linking(M, engine);
     607
     608    engine->finalizeObject();
     609
     610    void * main_MCptr = engine->getPointerToFunction(main_IR);
     611
     612    CC * codepoints = nullptr;
     613    if(main_MCptr){
     614        GrepExecutor grepEngine(main_MCptr);
     615        setParsedCodePointSet();
     616        grepEngine.doGrep("../Uname.txt");
     617        codepoints = getParsedCodePointSet();
     618        assert (codepoints);
     619    }
     620       
     621    delete engine;
     622    if (codepoints) {
     623        Name * const result = mMemoizer.memoize(codepoints);
     624        assert (*cast<CC>(result->getDefinition()) == *codepoints);
     625        return result;
     626    }
     627    return nullptr;
     628}
    573629
    574630CharsetOperatorKind RE_Parser::getCharsetOperator() {
  • icGREP/icgrep-devel/icgrep/toolchain.cpp

    r4937 r4939  
    99#include <fstream>
    1010
    11 #include "basis_bits.h"
    1211#include "utf_encoding.h"
    1312#include "pablo/pablo_compiler.h"
     
    2221#include <llvm/Support/TargetSelect.h>
    2322#include <llvm/Support/Host.h>
    24 #include <llvm/Support/FileSystem.h>
    25 
    2623
    2724#include <IDISA/idisa_avx_builder.h>
     
    4239#include <pablo/optimizers/pablo_simplifier.hpp>
    4340#include <pablo/optimizers/codemotionpass.h>
    44 #ifdef ENABLE_MULTIPLEXING
    4541#include <pablo/passes/flattenassociativedfg.h>
    4642#include <pablo/passes/factorizedfg.h>
     43#ifdef ENABLE_MULTIPLEXING
    4744#include <pablo/optimizers/pablo_automultiplexing.hpp>
    4845#include <pablo/optimizers/pablo_bddminimization.h>
     
    5552#include <pablo/printer_pablos.h>
    5653
    57 #include <hrtime.h>
    58 #include <do_grep.h>
     54#include "do_grep.h"
    5955
    6056using namespace pablo;
     57
     58static cl::OptionCategory bGrepOutputOptions("Output Options",
     59                                      "These options control the output.");
     60
     61static cl::opt<bool> CountOnly("c", cl::desc("Count and display the matching lines per file only."), cl::cat(bGrepOutputOptions));
     62static cl::alias CountOnlyLong("count", cl::desc("Alias for -c"), cl::aliasopt(CountOnly));
     63static cl::opt<bool> NormalizeLineBreaks("normalize-line-breaks", cl::desc("Normalize line breaks to std::endl."), cl::init(false),  cl::cat(bGrepOutputOptions));
     64
     65static cl::opt<bool> ShowFileNames("H", cl::desc("Show the file name with each matching line."), cl::cat(bGrepOutputOptions));
     66static cl::alias ShowFileNamesLong("with-filename", cl::desc("Alias for -H"), cl::aliasopt(ShowFileNames));
     67
     68static cl::opt<bool> ShowLineNumbers("n", cl::desc("Show the line number with each matching line."), cl::cat(bGrepOutputOptions));
     69static cl::alias ShowLineNumbersLong("line-number", cl::desc("Alias for -n"), cl::aliasopt(ShowLineNumbers));
     70
    6171
    6272static cl::OptionCategory cRegexOutputOptions("Regex Dump Options",
     
    6878static cl::opt<bool> PrintUTF8REs("print-utf8-REs", cl::init(false), cl::desc("print out UTF-8 REs"), cl::cat(cRegexOutputOptions));
    6979static cl::opt<bool> PrintSimplifiedREs("print-simplified-REs", cl::init(false), cl::desc("print out final simplified REs"), cl::cat(cRegexOutputOptions));
    70 static cl::OptionCategory dPabloDumpOptions("Pablo Dump Options", "These options control printing of intermediate Pablo code.");
     80static cl::OptionCategory dPabloDumpOptions("Pablo Dump Options",
     81                                            "These options control printing of intermediate Pablo code.");
    7182
    7283static cl::opt<bool> PrintOptimizedREcode("print-pablo", cl::init(false), cl::desc("print final optimized Pablo code"), cl::cat(dPabloDumpOptions));
    7384static cl::opt<bool> PrintCompiledCCcode("print-CC-pablo", cl::init(false), cl::desc("print Pablo output from character class compiler"), cl::cat(dPabloDumpOptions));
    7485static cl::opt<bool> PrintCompiledREcode("print-RE-pablo", cl::init(false), cl::desc("print Pablo output from the regular expression compiler"), cl::cat(dPabloDumpOptions));
    75 static cl::opt<std::string> PabloOutputFilename("print-pablo-output", cl::init(""), cl::desc("output Pablo filename"), cl::cat(dPabloDumpOptions));
    7686
    7787static cl::OptionCategory cPabloOptimizationsOptions("Pablo Optimizations", "These options control Pablo optimization passes.");
    7888
    79 static cl::opt<bool> DisableSimplification("disable-simplification", cl::init(false),
    80                                      cl::desc("Disable Pablo Simplification pass (not recommended)"),
     89static cl::opt<bool> DisablePabloCSE("disable-CSE", cl::init(false),
     90                                     cl::desc("Disable Pablo common subexpression elimination/dead code elimination"),
    8191                                     cl::cat(cPabloOptimizationsOptions));
    82 
    8392static cl::opt<bool> PabloSinkingPass("sinking", cl::init(false),
    8493                                      cl::desc("Moves all instructions into the innermost legal If-scope so that they are only executed when needed."),
    8594                                      cl::cat(cPabloOptimizationsOptions));
    8695
    87 static cl::OptionCategory cMachineCodeOptimization("Machine Code Optimizations", "These options control back-end compilier optimization levels.");
    88 
    89 
    90 static cl::opt<char> OptLevel("O", cl::desc("Optimization level. [-O0, -O1, -O2, or -O3] (default = '-O0')"),
    91                               cl::cat(cMachineCodeOptimization), cl::Prefix, cl::ZeroOrMore, cl::init('0'));
    92 
    9396#ifdef ENABLE_MULTIPLEXING
    9497static cl::opt<bool> PrintUnloweredCode("print-unlowered-pablo", cl::init(false), cl::desc("print Pablo output prior to lowering. "), cl::cat(dPabloDumpOptions));
     
    101104                                         cl::desc("coalesce associative functions prior to optimization passes."),
    102105                                         cl::cat(cPabloOptimizationsOptions));
    103 
    104106static cl::opt<bool> EnablePreDistribution("pre-dist", cl::init(false),
    105                                          cl::desc("apply distribution law optimization prior to multiplexing."),
     107                                         cl::desc("apply distribution law optimization."),
    106108                                         cl::cat(cPabloOptimizationsOptions));
    107 
    108109static cl::opt<bool> EnablePostDistribution("post-dist", cl::init(false),
    109                                          cl::desc("apply distribution law optimization after multiplexing."),
    110                                          cl::cat(cPabloOptimizationsOptions));
    111 
    112 static cl::opt<bool> EnablePrePassScheduling("pre-pass-scheduling", cl::init(false),
    113                                          cl::desc("apply pre-pass scheduling prior to LLVM IR generation."),
     110                                         cl::desc("apply distribution law optimization."),
    114111                                         cl::cat(cPabloOptimizationsOptions));
    115112#endif
     
    160157}
    161158
    162 #ifdef PRINT_TIMING_INFORMATION
    163 #define READ_CYCLE_COUNTER(name) name = read_cycle_counter();
    164 #else
    165 #define READ_CYCLE_COUNTER(name)
    166 #endif
    167 
    168 #ifdef PRINT_TIMING_INFORMATION
    169 unsigned COUNT_STATEMENTS(const PabloFunction * const entry) {
    170     std::stack<const Statement *> scope;
    171     unsigned statements = 0;
    172     // Scan through and collect all the advances, calls, scanthrus and matchstars ...
    173     for (const Statement * stmt = entry->getEntryBlock()->front(); ; ) {
    174         while ( stmt ) {
    175             ++statements;
    176             if (LLVM_UNLIKELY(isa<If>(stmt) || isa<While>(stmt))) {
    177                 // Set the next statement to be the first statement of the inner scope and push the
    178                 // next statement of the current statement into the scope stack.
    179                 const PabloBlock * const nested = isa<If>(stmt) ? cast<If>(stmt)->getBody() : cast<While>(stmt)->getBody();
    180                 scope.push(stmt->getNextNode());
    181                 stmt = nested->front();
    182                 assert (stmt);
    183                 continue;
    184             }
    185             stmt = stmt->getNextNode();
    186         }
    187         if (scope.empty()) {
    188             break;
    189         }
    190         stmt = scope.top();
    191         scope.pop();
    192     }
    193     return statements;
    194 }
    195 
    196 unsigned COUNT_ADVANCES(const PabloFunction * const entry) {
    197 
    198     std::stack<const Statement *> scope;
    199     unsigned advances = 0;
    200 
    201     // Scan through and collect all the advances, calls, scanthrus and matchstars ...
    202     for (const Statement * stmt = entry->getEntryBlock()->front(); ; ) {
    203         while ( stmt ) {
    204             if (isa<Advance>(stmt)) {
    205                 ++advances;
    206             }
    207             else if (LLVM_UNLIKELY(isa<If>(stmt) || isa<While>(stmt))) {
    208                 // Set the next statement to be the first statement of the inner scope and push the
    209                 // next statement of the current statement into the scope stack.
    210                 const PabloBlock * const nested = isa<If>(stmt) ? cast<If>(stmt)->getBody() : cast<While>(stmt)->getBody();
    211                 scope.push(stmt->getNextNode());
    212                 stmt = nested->front();
    213                 assert (stmt);
    214                 continue;
    215             }
    216             stmt = stmt->getNextNode();
    217         }
    218         if (scope.empty()) {
    219             break;
    220         }
    221         stmt = scope.top();
    222         scope.pop();
    223     }
    224     return advances;
    225 }
    226 
    227 using DistributionMap = boost::container::flat_map<unsigned, unsigned>;
    228 
    229 DistributionMap SUMMARIZE_VARIADIC_DISTRIBUTION(const PabloFunction * const entry) {
    230     std::stack<const Statement *> scope;
    231     DistributionMap distribution;
    232     // Scan through and collect all the advances, calls, scanthrus and matchstars ...
    233     for (const Statement * stmt = entry->getEntryBlock()->front(); ; ) {
    234         while ( stmt ) {
    235             if (isa<Variadic>(stmt)) {
    236                 auto f = distribution.find(stmt->getNumOperands());
    237                 if (f == distribution.end()) {
    238                     distribution.emplace(stmt->getNumOperands(), 1);
    239                 } else {
    240                     f->second += 1;
    241                 }
    242             }
    243             else if (LLVM_UNLIKELY(isa<If>(stmt) || isa<While>(stmt))) {
    244                 // Set the next statement to be the first statement of the inner scope and push the
    245                 // next statement of the current statement into the scope stack.
    246                 const PabloBlock * const nested = isa<If>(stmt) ? cast<If>(stmt)->getBody() : cast<While>(stmt)->getBody();
    247                 scope.push(stmt->getNextNode());
    248                 stmt = nested->front();
    249                 assert (stmt);
    250                 continue;
    251             }
    252             stmt = stmt->getNextNode();
    253         }
    254         if (scope.empty()) {
    255             break;
    256         }
    257         stmt = scope.top();
    258         scope.pop();
    259     }
    260     return distribution;
    261 }
    262 #endif
    263 
    264 void pablo_function_passes(PabloFunction * function) {   
     159void pablo_function_passes(PabloFunction * function) {
    265160    // Scan through the pablo code and perform DCE and CSE
    266 
    267 #ifdef PRINT_TIMING_INFORMATION
    268     timestamp_t simplification_start = 0, simplification_end = 0;
    269     timestamp_t coalescing_start = 0, coalescing_end = 0;
    270     timestamp_t sinking_start = 0, sinking_end = 0;
    271     timestamp_t pre_distribution_start = 0, pre_distribution_end = 0;
    272     timestamp_t multiplexing_start = 0, multiplexing_end = 0;
    273     timestamp_t post_distribution_start = 0, post_distribution_end = 0;
    274     timestamp_t lowering_start = 0, lowering_end = 0;
    275     timestamp_t scheduling_start = 0, scheduling_end = 0;
    276     DistributionMap distribution;
    277     const timestamp_t optimization_start = read_cycle_counter();
    278 #endif
    279     if (!DisableSimplification) {
    280         READ_CYCLE_COUNTER(simplification_start);
     161    if (!DisablePabloCSE) {
    281162        Simplifier::optimize(*function);
    282         READ_CYCLE_COUNTER(simplification_end);
    283163    }
    284164#ifdef ENABLE_MULTIPLEXING
    285     if (EnableLowering || EnablePreDistribution || EnablePostDistribution) {
    286         READ_CYCLE_COUNTER(coalescing_start);
    287         CanonicalizeDFG::transform(*function);
    288         READ_CYCLE_COUNTER(coalescing_end);
    289     }
     165    if (EnableLowering || EnablePreDistribution || EnablePostDistribution || EnableMultiplexing) {
     166        FlattenAssociativeDFG::transform(*function);
     167    }
     168#endif
     169    if (PabloSinkingPass) {
     170        CodeMotionPass::optimize(*function);
     171    }
     172#ifdef ENABLE_MULTIPLEXING   
    290173    if (EnablePreDistribution) {
    291         READ_CYCLE_COUNTER(pre_distribution_start);
    292174        DistributivePass::optimize(*function);
    293         READ_CYCLE_COUNTER(pre_distribution_end);
    294175    }
    295176    if (EnableMultiplexing) {
    296         READ_CYCLE_COUNTER(multiplexing_start);
    297177        MultiplexingPass::optimize(*function);
    298         READ_CYCLE_COUNTER(multiplexing_end);
    299         if (EnableLowering || EnablePreDistribution || EnablePostDistribution) {
    300             CanonicalizeDFG::transform(*function);
    301         }
    302178    }
    303179    if (EnablePostDistribution) {
    304         READ_CYCLE_COUNTER(post_distribution_start);
    305180        DistributivePass::optimize(*function);
    306         READ_CYCLE_COUNTER(post_distribution_end);
    307     }
    308 #endif
    309     if (PabloSinkingPass) {
    310         READ_CYCLE_COUNTER(sinking_start);
    311         CodeMotionPass::optimize(*function);
    312         READ_CYCLE_COUNTER(sinking_end);
    313     }
    314 #ifdef ENABLE_MULTIPLEXING
     181    }
     182    SchedulingPrePass::optimize(*function);
    315183    if (PrintUnloweredCode) {
    316184        //Print to the terminal the AST that was generated by the pararallel bit-stream compiler.
     
    318186        cerr << "Unlowered Pablo AST:\n";
    319187        PabloPrinter::print(*function, cerr);
    320     }   
    321     #ifdef PRINT_TIMING_INFORMATION
    322     distribution = SUMMARIZE_VARIADIC_DISTRIBUTION(function);
    323     #endif
    324     if (EnableLowering || EnablePreDistribution || EnablePostDistribution) {
    325         READ_CYCLE_COUNTER(lowering_start);
     188    }
     189    if (EnableLowering || EnablePreDistribution || EnablePostDistribution || EnableMultiplexing) {
    326190        FactorizeDFG::transform(*function);
    327         READ_CYCLE_COUNTER(lowering_end);
    328     }
    329     if (EnablePrePassScheduling) {
    330         READ_CYCLE_COUNTER(scheduling_start);
    331         SchedulingPrePass::optimize(*function);
    332         READ_CYCLE_COUNTER(scheduling_end);
    333     }
    334 #endif
    335 #ifdef PRINT_TIMING_INFORMATION
    336     const timestamp_t optimization_end = read_cycle_counter();
     191    }
    337192#endif
    338193    if (PrintOptimizedREcode) {
    339         if (PabloOutputFilename.empty()) {
    340             //Print to the terminal the AST that was generated by the pararallel bit-stream compiler.
    341             llvm::raw_os_ostream cerr(std::cerr);
    342             cerr << "Final Pablo AST:\n";
    343             PabloPrinter::print(*function, cerr);
    344         } else {
    345             std::error_code error;
    346             llvm::raw_fd_ostream out(PabloOutputFilename, error, sys::fs::OpenFlags::F_None);
    347             PabloPrinter::print(*function, out);
    348         }
    349     }
    350 #ifdef PRINT_TIMING_INFORMATION
    351     std::cerr << "PABLO OPTIMIZATION TIME: " << (optimization_end - optimization_start) << std::endl;
    352     std::cerr << "  SIMPLIFICATION TIME: " << (simplification_end - simplification_start) << std::endl;
    353     std::cerr << "  COALESCING TIME: " << (coalescing_end - coalescing_start) << std::endl;
    354     std::cerr << "  SINKING TIME: " << (sinking_end - sinking_start) << std::endl;
    355     std::cerr << "  PRE-DISTRIBUTION TIME: " << (pre_distribution_end - pre_distribution_start) << std::endl;
    356     std::cerr << "  MULTIPLEXING TIME: " << (multiplexing_end - multiplexing_start) << std::endl;
    357     std::cerr << "  MULTIPLEXING SEED: " << MultiplexingPass::SEED << std::endl;
    358     std::cerr << "  MULTIPLEXING NODES USED: " << MultiplexingPass::NODES_USED << std::endl;
    359     std::cerr << "  MULTIPLEXING NODES ALLOCATED: " << MultiplexingPass::NODES_ALLOCATED << std::endl;
    360     std::cerr << "  LOWERING TIME: " << (lowering_end - lowering_start) << std::endl;
    361     std::cerr << "  POST-DISTRIBUTION TIME: " << (post_distribution_end - post_distribution_start) << std::endl;
    362     std::cerr << "  SCHEDULING TIME: " << (scheduling_end - scheduling_start) << std::endl;
    363     std::cerr << "PABLO STATEMENTS: " << COUNT_STATEMENTS(function) << std::endl;
    364     std::cerr << "PABLO ADVANCES: " << COUNT_ADVANCES(function) << std::endl;
    365     std::cerr << "PRE-LOWERING VARIADIC DISTRIBUTION: ";
    366     bool join = false;
    367     for (auto dist : distribution) {
    368         if (join) {
    369             std::cerr << ';';
    370         }
    371         std::cerr << dist.first << '|' << dist.second;
    372         join = true;
    373     }
    374     std::cerr << std::endl;
    375 #endif
     194        PabloVerifier::verify(*function, "post-optimization");
     195        //Print to the terminal the AST that was generated by the pararallel bit-stream compiler.
     196        llvm::raw_os_ostream cerr(std::cerr);
     197        cerr << "Final Pablo AST:\n";
     198        PabloPrinter::print(*function, cerr);
     199    }
    376200}
    377201
     
    411235    builder.setErrorStr(&errMessage);
    412236    builder.setMCPU(sys::getHostCPUName());
    413     CodeGenOpt::Level optLevel = CodeGenOpt::Level::None;
    414     switch (OptLevel) {
    415         case '0': optLevel = CodeGenOpt::None; break;
    416         case '1': optLevel = CodeGenOpt::Less; break;
    417         case '2': optLevel = CodeGenOpt::Default; break;
    418         case '3': optLevel = CodeGenOpt::Aggressive; break;
    419         default: errs() << OptLevel << " is an invalid optimization level.\n";
    420     }
    421     builder.setOptLevel(optLevel);
     237    builder.setOptLevel(CodeGenOpt::Level::None);
    422238
    423239#if (BLOCK_SIZE == 256)
     
    438254}
    439255
     256int total_count = 0;
     257
    440258extern "C" {
    441     void wrapped_report_match(uint64_t recordNum, uint64_t recordStart, uint64_t recordEnd) {
    442         printf("line %lu: (%lu, %lu)\n", recordNum, recordStart, recordEnd);
    443     }
    444 }
    445 
     259    void wrapped_report_match(uint64_t lineNum, uint64_t line_start, uint64_t line_end, const char * buffer, int filesize, char * filename) {
     260        if(CountOnly){
     261            total_count++;
     262            return;
     263        }
     264
     265        llvm::raw_os_ostream out(std::cout);
     266        if (ShowFileNames) {
     267            out << filename << ':';
     268        }
     269        if (ShowLineNumbers) {
     270            out << lineNum << ":";
     271        }
     272
     273        if ((buffer[line_start] == 0xA) && (line_start != line_end)) {
     274            // The line "starts" on the LF of a CRLF.  Really the end of the last line.
     275            line_start++;
     276        }
     277        if (line_end == filesize) {
     278            // The match position is at end-of-file.   We have a final unterminated line.
     279            out.write(&buffer[line_start], line_end - line_start);
     280            if (NormalizeLineBreaks) {
     281                out << '\n';  // terminate it
     282            }
     283            return;
     284        }
     285        unsigned char end_byte = (unsigned char)buffer[line_end];
     286        if (NormalizeLineBreaks) {
     287            if (end_byte == 0x85) {
     288                // Line terminated with NEL, on the second byte.  Back up 1.
     289                line_end--;
     290            } else if (end_byte > 0xD) {
     291                // Line terminated with PS or LS, on the third byte.  Back up 2.
     292                line_end -= 2;
     293            }
     294            out.write(&buffer[line_start], line_end - line_start);
     295            out << '\n';
     296        }
     297        else{   
     298            if (end_byte == 0x0D) {
     299                // Check for line_end on first byte of CRLF;  note that we don't
     300                // want to access past the end of buffer.
     301                if ((line_end + 1 < filesize) && (buffer[line_end + 1] == 0x0A)) {
     302                    // Found CRLF; preserve both bytes.
     303                    line_end++;
     304                }
     305            }
     306            out.write(&buffer[line_start], line_end - line_start + 1);
     307        }
     308    }
     309}
     310
     311
     312void PrintTotalCount(){
     313    if(CountOnly){
     314        std::cout << total_count << std::endl;
     315    }
     316}
     317
     318re::CC * parsedCodePointSet;
     319
     320extern "C" {
     321    void insert_codepoints(uint64_t lineNum, uint64_t line_start, uint64_t line_end, const char * buffer) {
     322       re::codepoint_t c = 0;
     323        ssize_t line_pos = line_start;
     324        while (isxdigit(buffer[line_pos])) {
     325            if (isdigit(buffer[line_pos])) {
     326                c = (c << 4) | (buffer[line_pos] - '0');
     327            }
     328            else {
     329                c = (c << 4) | (tolower(buffer[line_pos]) - 'a' + 10);
     330            }
     331            line_pos++;
     332        }
     333        assert(((line_pos - line_start) >= 4) && ((line_pos - line_start) <= 6)); // UCD format 4 to 6 hex digits.       
     334        parsedCodePointSet->insert(c);
     335    }
     336}
     337
     338void setParsedCodePointSet(){
     339    parsedCodePointSet = re::makeCC();
     340}
     341
     342re::CC * getParsedCodePointSet(){
     343    return parsedCodePointSet;
     344}
    446345
    447346extern "C" {
     
    465364            e->addGlobalMapping(cast<GlobalValue>(it), (void *)&wrapped_report_match);
    466365        }
     366        if (fnName == "insert_codepoints") {
     367            e->addGlobalMapping(cast<GlobalValue>(it), (void *)&insert_codepoints);
     368        }
    467369#ifndef DISABLE_PREGENERATED_UCD_FUNCTIONS
    468370        else {
  • icGREP/icgrep-devel/icgrep/toolchain.h

    r4900 r4939  
    2626void pablo_function_passes(pablo::PabloFunction * function);
    2727
    28 
    29 
    3028ExecutionEngine * JIT_to_ExecutionEngine (Module * m);
    3129
    3230void icgrep_Linking(Module * m, ExecutionEngine * e);
    3331
     32void PrintTotalCount();
     33re::CC * getParsedCodePointSet();
     34void setParsedCodePointSet();
     35
    3436#endif
Note: See TracChangeset for help on using the changeset viewer.