Changeset 4788


Ignore:
Timestamp:
Sep 23, 2015, 12:54:17 AM (3 years ago)
Author:
nmedfort
Message:

Misc changes + potential SIGBUS fix for issue reported by Hongpu.

Location:
icGREP/icgrep-devel/icgrep
Files:
18 edited

Legend:

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

    r4785 r4788  
    6060endif()
    6161if(USE_BOOST_MMAP)
    62   SET(REQ_BOOST_COMPONENTS ${REQ_BOOST_COMPONENTS} iostreams)
     62  SET(REQ_BOOST_COMPONENTS ${REQ_BOOST_COMPONENTS} iostreams filesystem)
    6363endif()
    6464
     
    105105
    106106if(ENABLE_MULTIPLEXING)
    107 set(MULTIPLEXING_FLAG -multiplexing) # -multiplexing-dist=${PROJECT_BINARY_DIR}/ucd-multiplexing.csv #-ldc=ldc.csv
     107set(MULTIPLEXING_FLAG -multiplexing -reassoc) # -multiplexing-dist=${PROJECT_BINARY_DIR}/ucd-multiplexing.csv #-ldc=ldc.csv
    108108endif()
    109109
    110110add_custom_command(OUTPUT ${PRECOMPILED_FILES}
    111111  COMMAND generate_predefined_ucd_functions
    112   ARGS -o ${PRECOMPILED_PROPERTIES_OBJ} -dir ${PROJECT_SOURCE_DIR}/UCD/ #{MULTIPLEXING_FLAG} -reassoc -DefaultIfHierarchy
     112  ARGS -o ${PRECOMPILED_PROPERTIES_OBJ} -dir ${PROJECT_SOURCE_DIR}/UCD/ ${MULTIPLEXING_FLAG} -DefaultIfHierarchy
    113113  DEPENDS generate_predefined_ucd_functions
    114114  COMMENT "Building predefined UCD functions..."
  • icGREP/icgrep-devel/icgrep/cc/cc_compiler.cpp

    r4681 r4788  
    158158    if (bit_terms.size() > 1) {
    159159        //Reduce the list so that all of the expressions are contained within a single expression.
    160         std::vector<PabloAST*> new_terms(bit_terms.size() / 2);
    161         do
    162         {
    163             new_terms.clear();
     160        std::vector<PabloAST*> new_terms;
     161        new_terms.reserve(bit_terms.size() / 2);
     162        do {
    164163            for (auto i = 0; i < (bit_terms.size() / 2); i++) {
    165164                new_terms.push_back(pb.createAnd(bit_terms[(2 * i) + 1], bit_terms[2 * i]));
     
    169168            }
    170169            bit_terms.swap(new_terms);
     170            new_terms.clear();
    171171        }
    172172        while (bit_terms.size() > 1);
  • icGREP/icgrep-devel/icgrep/do_grep.cpp

    r4778 r4788  
    2727#include "include/simd-lib/buffer.hpp"
    2828
     29#include <llvm/Support/raw_os_ostream.h>
     30
    2931// mmap system
    3032#ifdef USE_BOOST_MMAP
     33#include <boost/filesystem.hpp>
    3134#include <boost/iostreams/device/mapped_file.hpp>
     35using namespace boost::iostreams;
     36using namespace boost::filesystem;
    3237#else
    3338#include <sys/mman.h>
     
    3843#define BUFFER_SEGMENTS 15
    3944#define BUFFER_SIZE (BUFFER_SEGMENTS * SEGMENT_SIZE)
    40 
    41 BitBlock EOF_mask = simd<1>::constant<1>();
    4245
    4346//
     
    5255//
    5356
    54 ssize_t GrepExecutor::write_matches(char * buffer, ssize_t first_line_start) {
    55 
    56   ssize_t line_start = first_line_start;
    57   ssize_t match_pos;
    58   ssize_t line_end;
    59   while (mMatch_scanner.has_next()) {
    60     match_pos = mMatch_scanner.scan_to_next();
    61     // If we found a match, it must be at a line end.
    62     line_end = mLineBreak_scanner.scan_to_next();
    63     while (line_end < match_pos) {
    64       line_start = line_end + 1;
    65       line_no++;
    66       line_end = mLineBreak_scanner.scan_to_next();
    67     }
    68     if (mShowFileNameOption) {
    69       std::cout << mFileName;
    70     }
    71     if (mShowLineNumberingOption) {
    72       std::cout << line_no << ":";
    73     }
    74     if ((buffer[line_start] == 0xA) && (line_start != line_end)) {
    75         // The LF of a CRLF.  Really the end of the last line. 
    76         line_start++;
    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       }
    84       else if (end_byte > 0xD) {
    85           // Line terminated with PS or LS, on the third byte.  Back up 2.
    86           line_end -= 2;
    87       }
    88       std::cout.write(&buffer[line_start], line_end - line_start);
    89       std::cout << std::endl;
    90     }
    91     else {
    92       if (end_byte == 0x0) {
    93           // This must be a sentinel byte position at the end of file.
    94           // Do not write it.
    95           line_end--;
    96       }
    97       else if (end_byte == 0x0D) {
    98           // Check for line_end on first byte of CRLF;  note that to safely
    99           // access past line_end, even at the end of buffer, we require the
    100           // mmap_sentinel_bytes >= 1.
    101           if (buffer[line_end + 1] == 0x0A) {
    102               // Found CRLF; preserve both bytes.
    103               line_end++;
    104           }
    105       }
    106       std::cout.write(&buffer[line_start], line_end - line_start + 1);
    107     }
    108     line_start = line_end + 1;
    109     line_no++;
    110   }
    111   while(mLineBreak_scanner.has_next()) {
    112     line_end = mLineBreak_scanner.scan_to_next();
    113     line_start = line_end+1;
    114     line_no++;
    115   }
    116   return line_start;
     57ssize_t GrepExecutor::write_matches(llvm::raw_ostream & out, const char * buffer, ssize_t line_start) {
     58
     59    ssize_t match_pos;
     60    ssize_t line_end;
     61    while (mMatch_scanner.has_next()) {
     62        match_pos = mMatch_scanner.scan_to_next();
     63        // If we found a match, it must be at a line end.
     64        while (true) {
     65            line_end = mLineBreak_scanner.scan_to_next();
     66            if (line_end >= match_pos) {
     67                break;
     68            }
     69            line_start = line_end + 1;
     70            mLineNum++;
     71        }
     72        assert (buffer + line_end < mFileBuffer + mFileSize);
     73        if (mShowFileNameOption) {
     74            out << mFileName << ':';
     75        }
     76        if (mShowLineNumberingOption) {
     77            out << mLineNum << ":";
     78        }
     79        if ((buffer[line_start] == 0xA) && (line_start != line_end)) {
     80            // The LF of a CRLF.  Really the end of the last line.
     81            line_start++;
     82        }
     83        unsigned char end_byte = (unsigned char)buffer[line_end];
     84        if (mNormalizeLineBreaksOption) {
     85            if (end_byte == 0x85) {
     86                // Line terminated with NEL, on the second byte.  Back up 1.
     87                line_end--;
     88            } else if (end_byte > 0xD) {
     89                // Line terminated with PS or LS, on the third byte.  Back up 2.
     90                line_end -= 2;
     91            }
     92            out.write(&buffer[line_start], line_end - line_start);
     93            out << '\n';
     94        }
     95        else {
     96            if (end_byte == 0x0) {
     97                // This must be a sentinel byte position at the end of file.
     98                // Do not write it.
     99                line_end--;
     100            } else if (end_byte == 0x0D) {
     101                // Check for line_end on first byte of CRLF;  note that to safely
     102                // access past line_end, even at the end of buffer, we require the
     103                // MMAP_SENTINEL_BYTES >= 1.
     104                if (buffer[line_end + 1] == 0x0A) {
     105                    // Found CRLF; preserve both bytes.
     106                    line_end++;
     107                }
     108            }
     109            out.write(&buffer[line_start], line_end - line_start + 1);
     110        }
     111        line_start = line_end + 1;
     112        mLineNum++;
     113    }
     114    while(mLineBreak_scanner.has_next()) {
     115        line_end = mLineBreak_scanner.scan_to_next();
     116        line_start = line_end+1;
     117        mLineNum++;
     118    }
     119    return line_start;
    117120}
    118121
    119 bool GrepExecutor::finalLineIsUnterminated() {
     122bool GrepExecutor::finalLineIsUnterminated() const {
    120123    if (mFileSize == 0) return false;
    121124    unsigned char end_byte = static_cast<unsigned char>(mFileBuffer[mFileSize-1]);
     
    124127    // Other line breaks require at least two bytes.
    125128    if (mFileSize == 1) return true;
    126     // NEL 
     129    // NEL
    127130    unsigned char penult_byte = static_cast<unsigned char>(mFileBuffer[mFileSize-2]);
    128131    if ((end_byte == 0x85) && (penult_byte == 0xC2)) return false;
     
    133136}
    134137
    135 void GrepExecutor::doGrep(const std::string infilename) {
     138void GrepExecutor::doGrep(const std::string & fileName) {
    136139
    137140    Basis_bits basis_bits;
    138     BitBlock match_vector;
    139    
    140     mFileName = infilename + ":";
    141    
     141    BitBlock match_vector = simd<1>::constant<0>();
    142142    size_t match_count = 0;
    143     size_t blk = 0;
    144     size_t block_base  = 0;
    145     size_t block_pos   = 0;
    146143    size_t chars_avail = 0;
    147144    ssize_t line_start = 0;
    148     line_no = 1;
    149 
    150     match_vector = simd<1>::constant<0>();
    151     int fdSrc;
    152     struct stat infile_sb;
    153     fdSrc = open(infilename.c_str(), O_RDONLY);
    154     if (fdSrc == -1) {
    155         std::cerr << "Error: cannot open " << infilename << " for processing. Skipped.\n";
    156         return;
    157     }
    158     if (fstat(fdSrc, &infile_sb) == -1) {
    159         std::cerr << "Error: cannot stat " << infilename << " for processing. Skipped.\n";
    160         return;
    161     }
    162     if (S_ISDIR(infile_sb.st_mode)) {
    163         // Silently ignore directories.
    164         // std::cerr << "Error: " << infilename << " is a directory. Skipped.\n";
    165         return;
    166     }
    167     mFileSize = infile_sb.st_size;
    168     // Set 2 sentinel bytes, 1 for possible addition of LF for unterminated last line,
    169     // 1 guard byte.  PROT_WRITE enables writing the sentinel.
    170     const size_t mmap_sentinel_bytes = 2; 
     145
     146    mFileName = fileName;
     147    mLineNum = 1;
     148
    171149#ifdef USE_BOOST_MMAP
    172     boost::iostreams::mapped_file mFile;
     150    const path file(mFileName);
     151    if (exists(file)) {
     152        if (is_directory(file)) {
     153            return;
     154        }
     155    } else {
     156        std::cerr << "Error: cannot open " << mFileName << " for processing. Skipped.\n";
     157        return;
     158    }
     159
     160    mFileSize = file_size(file);
     161    mapped_file mFile;
    173162    try {
    174         mFile.open(
    175             infilename,
    176             boost::iostreams::mapped_file_base::mapmode::priv,
    177             mFileSize + mmap_sentinel_bytes, 0
    178         );
     163        mFile.open(mFileName, mapped_file::priv, mFileSize, 0);
    179164    } catch (std::ios_base::failure e) {
    180165        std::cerr << "Error: Boost mmap " << e.what() << std::endl;
     
    183168    mFileBuffer = mFile.data();
    184169#else
    185     mFileBuffer = (char *) mmap(NULL, mFileSize + mmap_sentinel_bytes, PROT_READ|PROT_WRITE, MAP_PRIVATE, fdSrc, 0);
     170    struct stat infile_sb;
     171    const int fdSrc = open(mFileName.c_str(), O_RDONLY);
     172    if (fdSrc == -1) {
     173        std::cerr << "Error: cannot open " << mFileName << " for processing. Skipped.\n";
     174        return;
     175    }
     176    if (fstat(fdSrc, &infile_sb) == -1) {
     177        std::cerr << "Error: cannot stat " << mFileName << " for processing. Skipped.\n";
     178        close (fdSrc);
     179        return;
     180    }
     181    if (S_ISDIR(infile_sb.st_mode)) {
     182        close (fdSrc);
     183        return;
     184    }
     185    mFileSize = infile_sb.st_size;
     186    mFileBuffer = (char *) mmap(NULL, mFileSize, PROT_READ, MAP_PRIVATE, fdSrc, 0);
    186187    if (mFileBuffer == MAP_FAILED) {
    187188        if (errno ==  ENOMEM) {
    188             std::cerr << "Error:  mmap of " << infilename << " failed: out of memory\n";
     189            std::cerr << "Error:  mmap of " << mFileName << " failed: out of memory\n";
    189190        }
    190191        else {
    191             std::cerr << "Error: mmap of " << infilename << " failed with errno " << errno << ". Skipped.\n";
     192            std::cerr << "Error: mmap of " << mFileName << " failed with errno " << errno << ". Skipped.\n";
    192193        }
    193194        return;
    194195    }
    195196#endif
    196     char * buffer_ptr;
    197197    size_t segment = 0;
    198     size_t segment_base = 0;
    199198    chars_avail = mFileSize;
    200    
    201 //////////////////////////////////////////////////////////////////////////////////////////
    202 // Full Segments
    203 //////////////////////////////////////////////////////////////////////////////////////////
     199
     200    llvm::raw_os_ostream out(std::cout);
     201    //////////////////////////////////////////////////////////////////////////////////////////
     202    // Full Segments
     203    //////////////////////////////////////////////////////////////////////////////////////////
    204204
    205205    while (chars_avail >= SEGMENT_SIZE) {
    206206
    207         segment_base = segment * SEGMENT_SIZE;
    208207        mLineBreak_scanner.init();
    209208        mMatch_scanner.init();
    210209
    211         for (blk = 0; blk < SEGMENT_BLOCKS; blk++) {
    212             block_base = blk*BLOCK_SIZE + segment_base;
    213             s2p_do_block((BytePack *) &mFileBuffer[block_base], basis_bits);
     210        for (size_t blk = 0; blk != SEGMENT_BLOCKS; ++blk) {
     211            s2p_do_block(reinterpret_cast<BytePack *>(mFileBuffer + (blk * BLOCK_SIZE) + (segment * SEGMENT_SIZE)), basis_bits);
    214212            Output output;
    215213            mProcessBlockFcn(basis_bits, output);
     
    218216            mLineBreak_scanner.load_block(output.LF, blk);
    219217
    220             if (mCountOnlyOption){
    221                 if (bitblock::any(output.matches))
    222                 {
    223                     if (bitblock::any(simd_and(match_vector, output.matches))){
     218            if (mCountOnlyOption) {
     219                if (bitblock::any(output.matches)) {
     220                    if (bitblock::any(simd_and(match_vector, output.matches))) {
    224221                        match_count += bitblock::popcount(match_vector);
    225222                        match_vector = output.matches;
    226                     }
    227                     else
    228                     {
     223                    } else {
    229224                        match_vector = simd_or(match_vector, output.matches);
    230225                    }
     
    233228        }
    234229
    235         buffer_ptr = &mFileBuffer[segment_base];
    236 
    237230        if (!mCountOnlyOption) {
    238           line_start = write_matches(buffer_ptr, line_start);
     231            line_start = write_matches(out, mFileBuffer + (segment * SEGMENT_SIZE), line_start);
    239232        }
    240233        segment++;
     
    243236    }
    244237
    245 //////////////////////////////////////////////////////////////////////////////////////////
    246 // For the Final Partial Segment.
    247 //////////////////////////////////////////////////////////////////////////////////////////
    248 
    249     segment_base = segment * SEGMENT_SIZE;
    250     int remaining = chars_avail;
    251        
     238    //////////////////////////////////////////////////////////////////////////////////////////
     239    // For the Final Partial Segment.
     240    //////////////////////////////////////////////////////////////////////////////////////////
     241
     242    size_t remaining = chars_avail;
     243    size_t blk = 0;
    252244
    253245    mLineBreak_scanner.init();
     
    255247
    256248    /* Full Blocks */
    257     blk = 0;
    258     while (remaining >= BLOCK_SIZE) {
    259         block_base = block_pos + segment_base;
    260         s2p_do_block((BytePack *) &mFileBuffer[block_base], basis_bits);
     249    for (; remaining >= BLOCK_SIZE; remaining -= BLOCK_SIZE, ++blk) {
     250        s2p_do_block(reinterpret_cast<BytePack *>(mFileBuffer + (blk * BLOCK_SIZE) + (segment * SEGMENT_SIZE)), basis_bits);
    261251        Output output;
    262252        mProcessBlockFcn(basis_bits, output);
     
    264254        mLineBreak_scanner.load_block(output.LF, blk);
    265255        mMatch_scanner.load_block(output.matches, blk);
    266         if (mCountOnlyOption)
    267         {
    268             if (bitblock::any(output.matches))
    269             {
    270                 if (bitblock::any(simd_and(match_vector, output.matches)))
    271                 {
     256        if (mCountOnlyOption) {
     257            if (bitblock::any(output.matches)) {
     258                if (bitblock::any(simd_and(match_vector, output.matches))) {
    272259                    match_count += bitblock::popcount(match_vector);
    273260                    match_vector = output.matches;
    274                 }
    275                 else
    276                 {
     261                } else {
    277262                    match_vector = simd_or(match_vector, output.matches);
    278263                }
    279264            }
    280265        }
    281 
    282         block_pos += BLOCK_SIZE;
    283         remaining -= BLOCK_SIZE;
    284         blk++;
    285     }
    286     block_base = block_pos;
     266    }
    287267
    288268    //Final Partial Block (may be empty, but there could be carries pending).
    289269   
    290     EOF_mask = bitblock::srl(simd<1>::constant<1>(), convert(BLOCK_SIZE-remaining));
     270    const auto EOF_mask = bitblock::srl(simd<1>::constant<1>(), convert(BLOCK_SIZE - remaining));
    291271   
    292     block_base = block_pos + segment_base;
    293     s2p_do_final_block((BytePack *) &mFileBuffer[block_base], basis_bits, EOF_mask);
     272    s2p_do_final_block(reinterpret_cast<BytePack *>(mFileBuffer + (blk * BLOCK_SIZE) + (segment * SEGMENT_SIZE)), basis_bits, EOF_mask);
    294273
    295274    if (finalLineIsUnterminated()) {
     
    299278        basis_bits.bit_4 = simd_or(basis_bits.bit_4, EOF_pos);
    300279        basis_bits.bit_6 = simd_or(basis_bits.bit_6, EOF_pos);
    301         // Add final sentinel byte so write_matches knows what to do.
    302         mFileBuffer[mFileSize] = 0x0;
    303280    }
    304281   
     
    306283    mProcessBlockFcn(basis_bits, output);
    307284
    308     if (mCountOnlyOption)
    309     {
     285    if (mCountOnlyOption) {
    310286        match_count += bitblock::popcount(match_vector);
    311         if (bitblock::any(output.matches))
    312         {
     287        if (bitblock::any(output.matches)) {
    313288            match_count += bitblock::popcount(output.matches);
    314289        }
    315290        if (mShowFileNameOption) {
    316             std::cout << mFileName;
    317         }
    318         std::cout << match_count << std::endl;
    319     }
    320     else
    321     {
     291            out << mFileName << ':';
     292        }
     293        out << match_count << '\n';
     294    } else {
    322295        mLineBreak_scanner.load_block(output.LF, blk);
    323296        mMatch_scanner.load_block(output.matches, blk);
    324         blk++;
    325         for (int i = blk; i < SEGMENT_BLOCKS; i++)
    326         {
    327             mLineBreak_scanner.load_block(simd<1>::constant<0>(), i);
    328             mMatch_scanner.load_block(simd<1>::constant<0>(), i);
    329         }
    330         buffer_ptr = &mFileBuffer[segment_base];
    331         line_start = write_matches(buffer_ptr, line_start);
    332     }
    333    
     297        while (++blk < SEGMENT_BLOCKS) {
     298            mLineBreak_scanner.load_block(simd<1>::constant<0>(), blk);
     299            mMatch_scanner.load_block(simd<1>::constant<0>(), blk);
     300        }
     301        line_start = write_matches(out, mFileBuffer + (segment * SEGMENT_SIZE), line_start);
     302    }
    334303#ifdef USE_BOOST_MMAP
    335304    mFile.close();
    336305#else
    337     munmap((void *) mFileBuffer, mFileSize + mmap_sentinel_bytes);
    338 #endif
     306    munmap((void *)mFileBuffer, mFileSize);
    339307    close(fdSrc);
    340     
     308#endif   
    341309}
  • icGREP/icgrep-devel/icgrep/do_grep.h

    r4726 r4788  
    3838#endif
    3939
     40typedef void (*process_block_fcn)(const Basis_bits & basis_bits, Output & output);
    4041
    41 typedef void (*process_block_fcn)(const Basis_bits & basis_bits, Output & output);
     42namespace llvm { class raw_ostream; }
    4243
    4344class GrepExecutor {
     
    5758    void setNormalizeLineBreaksOption(bool normLB = true) {mNormalizeLineBreaksOption = normLB;}
    5859   
    59     void doGrep(std::string fileName);
     60    void doGrep(const std::string & fileName);
    6061private:
    61     ssize_t write_matches(char * buffer, ssize_t first_line_start);
    62     bool finalLineIsUnterminated();
     62    ssize_t write_matches(llvm::raw_ostream & out, const char *buffer, ssize_t first_line_start);
     63    bool finalLineIsUnterminated() const;
    6364
    6465    bool mCountOnlyOption;
     
    7475    ScannerT mLineBreak_scanner;
    7576    ScannerT mMatch_scanner;
    76     size_t line_no;
     77    size_t mLineNum;
    7778};
    7879
  • icGREP/icgrep-devel/icgrep/generate_predefined_ucd_functions.cpp

    r4777 r4788  
    148148std::pair<unsigned, unsigned> computePabloDependencyChainMetrics(const PabloFunction * f) {
    149149    std::unordered_map<const PabloAST *, unsigned> G;
    150     G.insert(std::make_pair(f->getEntryBlock().createZeroes(), 0));
    151     G.insert(std::make_pair(f->getEntryBlock().createOnes(), 0));
     150    G.insert(std::make_pair(PabloBlock::createZeroes(), 0));
     151    G.insert(std::make_pair(PabloBlock::createOnes(), 0));
    152152    for (unsigned i = 0; i != f->getNumOfParameters(); ++i) {
    153153        G.insert(std::make_pair(f->getParameter(i), 0));
  • icGREP/icgrep-devel/icgrep/icgrep-devel.config

    r4284 r4788  
    1 #define USE_LLVM_3_5
     1#define USE_BOOST_MMAP
  • icGREP/icgrep-devel/icgrep/icgrep-devel.includes

    r4618 r4788  
    1010../ucd
    1111../QA/unit-tests
     12/usr/include/boost/filesystem
     13/usr/include/boost/iostreams
     14/usr/include/boost/system
  • icGREP/icgrep-devel/icgrep/icgrep.cpp

    r4775 r4788  
    101101    cl::desc("combine Advances whose inputs are mutual exclusive into the fewest number of advances possible (expensive)."),
    102102    cl::cat(cPabloOptimizationsOptions));
     103
     104static cl::opt<bool> EnableReassociation("reassoc", cl::init(false),
     105    cl::desc("perform reassocation and distribution law optimization."),
     106    cl::cat(cPabloOptimizationsOptions));
    103107#endif
    104108
     
    242246        pablo::CodeSinking::optimize(*function);
    243247    }
    244 #ifdef ENABLE_MULTIPLEXING
    245     pablo::BDDMinimizationPass::optimize(*function);
    246     //if (EnableMultiplexing) {
    247         pablo::AutoMultiplexing::optimize(*function);
    248     //}
    249     pablo::BooleanReassociationPass::optimize(*function);
     248#ifdef ENABLE_MULTIPLEXING   
     249    if (EnableMultiplexing) {
     250        pablo::BDDMinimizationPass::optimize(*function);
     251        pablo::AutoMultiplexing::optimize(*function);       
     252    }   
     253    if (EnableReassociation) {
     254        pablo::BooleanReassociationPass::optimize(*function);
     255    }
    250256#endif
    251257    if (PrintOptimizedREcode) {
     
    384390   
    385391    if (icgrep_MCptr) {
    386         GrepExecutor grepEngine = GrepExecutor(icgrep_MCptr);
     392        GrepExecutor grepEngine(icgrep_MCptr);
    387393        grepEngine.setCountOnlyOption(CountOnly);
    388394        grepEngine.setNormalizeLineBreaksOption(NormalizeLineBreaks);
     
    392398        }
    393399        for (unsigned i = firstInputFile; i != inputFiles.size(); ++i) {
    394             grepEngine.doGrep(inputFiles[i].c_str());
     400            grepEngine.doGrep(inputFiles[i]);
    395401        }
    396402    }
  • icGREP/icgrep-devel/icgrep/include/simd-lib/transpose.hpp

    r3850 r4788  
    1919
    2020static inline void s2p_do_block(BytePack U8[], Basis_bits & basis_bits);
    21 static inline void s2p_do_final_block(BytePack U8[], Basis_bits & basis_bits, BitBlock EOF_mask);
     21static inline void s2p_do_final_block(BytePack U8[], Basis_bits & basis_bits, const BitBlock & EOF_mask);
    2222
    2323static IDISA_ALWAYS_INLINE void s2p_do_block(BytePack U8[], Basis_bits & basis_bits) {
     
    2626}
    2727
    28 static IDISA_ALWAYS_INLINE void s2p_do_final_block(BytePack U8[], Basis_bits & basis_bits, BitBlock EOF_mask) {
     28static IDISA_ALWAYS_INLINE void s2p_do_final_block(BytePack U8[], Basis_bits & basis_bits, const BitBlock & EOF_mask) {
    2929  s2p_do_block(U8, basis_bits);
    3030  basis_bits.bit_0 = simd_and(basis_bits.bit_0, EOF_mask);
  • icGREP/icgrep-devel/icgrep/pablo/builder.hpp

    r4721 r4788  
    3535    }
    3636
    37     inline Zeroes * createZeroes() const {
    38         return mPb->createZeroes();
    39     }
    40 
    41     inline Ones * createOnes() const {
    42         return mPb->createOnes();
     37    static inline Zeroes * createZeroes() {
     38        return PabloBlock::createZeroes();
     39    }
     40
     41    static inline Ones * createOnes() {
     42        return PabloBlock::createOnes();
    4343    }
    4444
  • icGREP/icgrep-devel/icgrep/pablo/codegenstate.cpp

    r4761 r4788  
    88
    99namespace pablo {
     10
     11Zeroes * const PabloBlock::mZeroes = new Zeroes();
     12
     13Ones * const PabloBlock::mOnes = new Ones();
    1014
    1115inline PabloAST * PabloBlock::renameNonNamedNode(PabloAST * expr, const std::string && prefix) {
     
    549553PabloBlock::PabloBlock(SymbolGenerator & symbolGenerator)
    550554: PabloAST(PabloAST::ClassTypeId::Block)
    551 , mZeroes(new Zeroes())
    552 , mOnes(new Ones())
    553555, mSymbolGenerator(symbolGenerator)
    554556, mParent(nullptr)
     
    560562PabloBlock::PabloBlock(PabloBlock * predecessor)
    561563: PabloAST(PabloAST::ClassTypeId::Block)
    562 , mZeroes(predecessor->mZeroes) // inherit the original "Zeroes" variable for simplicity
    563 , mOnes(predecessor->mOnes) // inherit the original "Ones" variable for simplicity
    564564, mSymbolGenerator(predecessor->mSymbolGenerator)
    565565, mParent(predecessor)
  • icGREP/icgrep-devel/icgrep/pablo/codegenstate.h

    r4718 r4788  
    6969    PabloAST * createAdvance(PabloAST * expr, PabloAST * shiftAmount, const std::string prefix);
    7070
    71     inline Zeroes * createZeroes() const {
     71    static inline Zeroes * createZeroes() {
    7272        return mZeroes;
    7373    }
    7474
    75     inline Ones * createOnes() const {
     75    static inline Ones * createOnes() {
    7676        return mOnes;
    7777    }
     
    225225
    226226private:       
    227     Zeroes * const                                      mZeroes;
    228     Ones * const                                        mOnes;
     227    static Zeroes * const                               mZeroes;
     228    static Ones * const                                 mOnes;
    229229    SymbolGenerator &                                   mSymbolGenerator;
    230230    PabloBlock *                                        mParent;
  • icGREP/icgrep-devel/icgrep/pablo/optimizers/booleanreassociationpass.cpp

    r4778 r4788  
    8282}
    8383
     84inline PabloAST *& getValue(VertexData & data) {
     85    return std::get<1>(data);
     86}
     87
     88inline PabloAST * getValue(const VertexData & data) {
     89    return std::get<1>(data);
     90}
     91
    8492inline bool isAssociative(const VertexData & data) {
    8593    switch (getType(data)) {
     
    104112
    105113inline bool isNegated(const VertexData & data) {
    106     return getType(data) == TypeId::Not && (std::get<1>(data) != nullptr);
     114    return getType(data) == TypeId::Not && (getValue(data) != nullptr);
    107115}
    108116
     
    339347    flat_set<PabloAST *> sources;
    340348    for (const auto e : make_iterator_range(in_edges(u, G))) {
    341         PabloAST * expr = std::get<1>(G[source(e, G)]);
     349        PabloAST * expr = getValue(G[source(e, G)]);
    342350        assert ("G contains a null input variable!" && (expr != nullptr));
    343351        sources.insert(expr);
     
    346354    // Sort the queue in order of how the inputs were written
    347355    std::sort(Q.begin(), Q.end(), [&writtenAt](const PabloAST * const e1, const PabloAST * const e2) -> bool {
    348         const auto f1 = writtenAt.find(e1);
    349         const unsigned v1 = (f1 == writtenAt.end()) ? 0 : f1->second;
    350         const auto f2 = writtenAt.find(e2);
    351         const unsigned v2 = (f2 == writtenAt.end()) ? 0 : f2->second;
    352         return v1 < v2;
     356        const auto f1 = writtenAt.find(e1); assert (f1 != writtenAt.end());
     357        const auto f2 = writtenAt.find(e2); assert (f2 != writtenAt.end());
     358        return f1->second < f2->second;
    353359    });
    354360
    355361    const TypeId typeId = getType(G[u]);
    356362    while (Q.size() > 1) {
    357         PabloAST * e1 = Q.front(); Q.pop_front();
     363        PabloAST * e1 = Q.front(); Q.pop_front();       
    358364        PabloAST * e2 = Q.front(); Q.pop_front();
    359365        PabloAST * expr = nullptr;
    360         // Note: this switch ought to compile to an array of function pointers to the appropriate method.
    361366        switch (typeId) {
    362367            case TypeId::And:
     
    372377    PabloAST * const result = Q.front();
    373378    assert (result);
    374     std::get<1>(G[u]) = result;
     379    getValue(G[u]) = result;
    375380    return result;
    376381}
     
    391396void BooleanReassociationPass::rewriteAST(PabloBlock & block, Graph & G) {
    392397
     398//    // Clear out the current AST
     399//    std::vector<Statement *> currentAST;
     400//    for (Statement * stmt = block.front(); stmt; stmt = stmt->removeFromParent()) {
     401//        currentAST.push_back(stmt);
     402//    }
     403    // Rewrite the AST in accordance to G
    393404    circular_buffer<Vertex> Q(num_vertices(G));
    394405    topological_sort(G, std::back_inserter(Q));
     406
    395407    block.setInsertPoint(nullptr);
    396 
    397     unsigned index = 0;
     408    unsigned statementCount = 0;
    398409    WrittenAt writtenAt;
    399410    while (!Q.empty()) {
    400         const Vertex u = Q.back(); Q.pop_back();
     411        const Vertex u = Q.back();
     412        Q.pop_back();
     413        // Supress any isolated vertices; the AST must be a single connected component.
     414        if (in_degree(u, G) == 0 && out_degree(u, G) == 0) {
     415            continue;
     416        }
     417        unsigned statementIndex = 0;
     418        PabloAST * expr = getValue(G[u]);
    401419        if (LLVM_LIKELY(isMutable(G[u], block))) {
    402420            Statement * stmt = nullptr;
     
    405423                if (LLVM_LIKELY(inCurrentBlock(replacement, block))) {
    406424                    stmt = cast<Statement>(replacement);
    407                 } else { // optimization reduced this to a Constant, Var or an outer-scope statement
     425                } else { // optimization reduced this to a Constant, Var or a prior-scope statement
    408426                    getType(G[u]) = TypeId::Var;
    409427                    continue;
    410428                }
    411429            } else { // update any potential mappings
    412                 stmt = cast<Statement>(std::get<1>(G[u]));
     430                stmt = cast<Statement>(getValue(G[u]));
    413431            }
    414432            assert (stmt);
    415             assert (inCurrentBlock(stmt, block));           
    416433            for (auto e : make_iterator_range(out_edges(u, G))) {
    417434                if (G[e] && G[e] != stmt) {
    418                     PabloAST * expr = std::get<1>(G[target(e, G)]);
     435                    PabloAST * expr = getValue(G[target(e, G)]);
    419436                    if (expr) { // processing a yet-to-be created value
    420437                        cast<Statement>(expr)->replaceUsesOfWith(G[e], stmt);
     
    426443                continue;
    427444            }
    428             writtenAt.emplace(stmt, ++index);
    429445            block.insert(stmt);
    430         }
    431     }
     446            statementIndex = ++statementCount;
     447            expr = stmt;
     448        }
     449        writtenAt.emplace(expr, statementIndex);
     450    }
     451//    // Erase any AST node that weren't placed back into the AST
     452//    for (Statement * stmt : currentAST) {
     453//        if (stmt->getParent() == nullptr) {
     454//            stmt->eraseFromParent(true);
     455//        }
     456//    }
    432457}
    433458
     
    745770    VertexSet sinks;
    746771    for (const Vertex u : make_iterator_range(vertices(H))) {
    747         if (out_degree(u, H) == 0) {
     772        if (out_degree(u, H) == 0 && in_degree(u, G) != 0) {
    748773            sinks.push_back(u);
    749774        }
     
    892917            for (const Vertex t : sinks) {
    893918                const auto v = mapping[H[t]];
    894                 add_edge(std::get<1>(G[v]), y, v, G);
     919                add_edge(getValue(G[v]), y, v, G);
    895920            }
    896921
  • icGREP/icgrep-devel/icgrep/pablo/optimizers/pablo_automultiplexing.cpp

    r4775 r4788  
    301301
    302302    // Map the predefined 0/1 entries
    303     mCharacterizationMap[function.getEntryBlock().createZeroes()] = Zero();
    304     mCharacterizationMap[function.getEntryBlock().createOnes()] = One();
     303    mCharacterizationMap[PabloBlock::createZeroes()] = Zero();
     304    mCharacterizationMap[PabloBlock::createOnes()] = One();
    305305
    306306    // Order the variables so the input Vars are pushed to the end; they ought to
  • icGREP/icgrep-devel/icgrep/pablo/optimizers/pablo_bddminimization.cpp

    r4775 r4788  
    8383    Cudd_MakeTreeNode(mManager, 0, function.getNumOfParameters(), MTR_DEFAULT);
    8484    // Map the predefined 0/1 entries
    85     mCharacterizationMap[function.getEntryBlock().createZeroes()] = Zero();
    86     mCharacterizationMap[function.getEntryBlock().createOnes()] = One();   
     85    mCharacterizationMap[PabloBlock::createZeroes()] = Zero();
     86    mCharacterizationMap[PabloBlock::createOnes()] = One();
    8787    // Order the variables so the input Vars are pushed to the end; they ought to
    8888    // be the most complex to resolve.   
  • icGREP/icgrep-devel/icgrep/pablo/optimizers/pablo_simplifier.cpp

    r4775 r4788  
    107107            if (LLVM_UNLIKELY(isa<Zeroes>(ifNode->getCondition()))) {
    108108                for (Assign * defVar : ifNode->getDefined()) {
    109                     defVar->replaceWith(block.createZeroes(), false, true);
     109                    defVar->replaceWith(PabloBlock::createZeroes(), false, true);
    110110                }
    111111                stmt = stmt->eraseFromParent(true);
  • icGREP/icgrep-devel/icgrep/pablo/pabloAST.cpp

    r4775 r4788  
    217217    // body or we'll lose track of them.
    218218    if (LLVM_UNLIKELY(isa<If>(this) || isa<While>(this))) {
    219         if (isa<If>(this)) {
    220             // Eliminate the relationship between the If node and its defined vars ...
    221             for (PabloAST * var : cast<If>(this)->getDefined()) {
    222                 var->removeUser(this);
    223                 this->removeUser(var);
    224                 var->replaceAllUsesWith(mParent->createZeroes());
    225             }
    226         }
    227219        PabloBlock & body = isa<If>(this) ? cast<If>(this)->getBody() : cast<While>(this)->getBody();
    228220        Statement * stmt = body.front();
    229221        while (stmt) {
    230222            stmt = stmt->eraseFromParent(recursively);
    231         }       
    232     }
     223        }
     224    } else if (LLVM_UNLIKELY(isa<Assign>(this))) {
     225        for (PabloAST * use : mUsers) {
     226            if (If * ifNode = dyn_cast<If>(use)) {
     227                const auto & defs = ifNode->getDefined();
     228                if (LLVM_LIKELY(std::find(defs.begin(), defs.end(), this) != defs.end())) {
     229                    this->removeUser(ifNode);
     230                    ifNode->removeUser(this);
     231                    break;
     232                }
     233            }
     234        }
     235    } else if (LLVM_UNLIKELY(isa<Next>(this))) {
     236        for (PabloAST * use : mUsers) {
     237            if (While * whileNode = dyn_cast<While>(use)) {
     238                const auto & vars = whileNode->getVariants();
     239                if (LLVM_LIKELY(std::find(vars.begin(), vars.end(), this) != vars.end())) {
     240                    this->removeUser(whileNode);
     241                    whileNode->removeUser(this);
     242                    break;
     243                }
     244            }
     245        }
     246    }
     247
     248    replaceAllUsesWith(PabloBlock::createZeroes());
    233249
    234250    if (recursively) {
     
    240256        }
    241257    }
     258
    242259    return removeFromParent();
    243260}
  • icGREP/icgrep-devel/icgrep/pablo/printer_pablos.h

    r4611 r4788  
    1111#include <pablo/ps_if.h>
    1212#include <string>
    13 #include <llvm/Support/raw_os_ostream.h>
    1413
    15 namespace pablo {
    16     class PabloBlock;
    17 }
     14namespace pablo { class PabloBlock; }
     15
     16namespace llvm { class raw_ostream; }
    1817
    1918class PabloPrinter {
Note: See TracChangeset for help on using the changeset viewer.