Changeset 5329 for icGREP


Ignore:
Timestamp:
Feb 18, 2017, 4:13:44 PM (2 years ago)
Author:
nmedfort
Message:

Continued work on parenthesis matching; addition of Pablo ScanTo? and AdvanceThenScanTo/Thru? statements. Bug fix for Pablo Compiler for escaping variables.

Location:
icGREP/icgrep-devel/icgrep
Files:
1 deleted
22 edited

Legend:

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

    r5314 r5329  
    8080add_executable(wc wc.cpp toolchain.cpp)
    8181add_executable(editd editd/editd.cpp editd/pattern_compiler.cpp toolchain.cpp editd/editdscan_kernel.cpp editd/editd_gpu_kernel.cpp editd/editd_cpu_kernel.cpp)
    82 add_executable(array-test array-test.cpp toolchain.cpp)
     82add_executable(array-test array-test.cpp toolchain.cpp kernels/alignedprint.cpp)
    8383
    8484## IWYU detects superfluous includes and when the include can be replaced with a forward declaration.
  • icGREP/icgrep-devel/icgrep/IR_Gen/idisa_target.cpp

    r5324 r5329  
    2323    }
    2424    Triple T(mod->getTargetTriple());
    25     unsigned registerWidth = 0;
     25    unsigned registerWidth = 32;
    2626    if (T.isArch64Bit()) {
    2727        registerWidth = 64;
  • icGREP/icgrep-devel/icgrep/array-test.cpp

    r5320 r5329  
    99#include <kernels/mmap_kernel.h>                   // for MMapSourceKernel
    1010#include <kernels/s2p_kernel.h>                    // for S2PKernel
     11#include <kernels/alignedprint.h>
    1112#include <kernels/streamset.h>                     // for SingleBlockBuffer
    1213#include <kernels/pipeline.h>
     
    1920#include <pablo/pablo_kernel.h>                    // for PabloKernel
    2021#include <pablo/pe_zeroes.h>
     22#include <pablo/pe_ones.h>
    2123#include <toolchain.h>                             // for JIT_to_ExecutionEn...
    2224#include <pablo/builder.hpp>                       // for PabloBuilder
     
    2931#include "llvm/IR/Value.h"                         // for Value
    3032#include "llvm/Support/Debug.h"                    // for dbgs
     33#include <pablo/pablo_toolchain.h>
    3134#include <iostream>
     35
    3236namespace llvm { class Type; }
    3337namespace pablo { class Integer; }
     
    4650
    4751    Var * input = kernel->getInputStreamVar("input");
    48     Var * matches = kernel->getOutputStreamVar("matches");
    4952
    5053    PabloAST * basis[8];
     
    5356    }
    5457
    55     PabloAST * temp1 = pb.createOr(basis[0], basis[1]);
    56     PabloAST * temp2 = pb.createAnd(basis[2], pb.createNot(basis[3]));
    57     PabloAST * temp3 = pb.createAnd(temp2, pb.createNot(temp1));
    58     PabloAST * temp4 = pb.createAnd(basis[4], pb.createNot(basis[5]));
    59     PabloAST * temp5 = pb.createOr(basis[6], basis[7]);
    60     PabloAST * temp6 = pb.createAnd(temp4, pb.createNot(temp5));
     58    PabloAST * temp1 = pb.createOr(basis[0], basis[1], "temp1");
     59    PabloAST * temp2 = pb.createAnd(basis[2], pb.createNot(basis[3]), "temp2");
     60    PabloAST * temp3 = pb.createAnd(temp2, pb.createNot(temp1), "temp3");
     61    PabloAST * temp4 = pb.createAnd(basis[4], pb.createNot(basis[5]), "temp4");
     62    PabloAST * temp5 = pb.createOr(basis[6], basis[7], "temp5");
     63    PabloAST * temp6 = pb.createAnd(temp4, pb.createNot(temp5), "temp6");
    6164    PabloAST * lparen = pb.createAnd(temp3, temp6, "lparens");
    62     PabloAST * temp7 = pb.createAnd(basis[7], pb.createNot(basis[6]));
    63     PabloAST * temp8 = pb.createAnd(temp4, temp7);
     65    PabloAST * temp7 = pb.createAnd(basis[7], pb.createNot(basis[6]), "temp7");
     66    PabloAST * temp8 = pb.createAnd(temp4, temp7, "temp8");
    6467    PabloAST * rparen = pb.createAnd(temp3, temp8, "rparens");
    65     PabloAST * parens = pb.createOr(lparen, rparen);
    66     PabloAST * pscan = pb.createScanTo(pb.createAdvance(lparen, 1), parens, "pscan");
    67     PabloAST * closed = pb.createAnd(pscan, rparen, "closed");
    68 
    69     pb.createAssign(pb.createExtract(matches, 0), closed);
    70 
    71     Var * const all_closed = pb.createVar("all_closed", closed);
    72     Var * const pending_lparen = pb.createVar("pending_lparen", pb.createAnd(pscan, lparen));
    73     PabloAST * unmatched_rparen = pb.createAnd(rparen, pb.createNot(closed));
    74     Var * const in_play = pb.createVar("in_play", pb.createOr(pending_lparen, unmatched_rparen));
    75     Var * const errors = pb.createVar("errors", pb.createZeroes());
    76 
    77     Integer * const one = pb.getInteger(1);
    78     Var * const index = pb.createVar("i", one);
     68    PabloAST * parens = pb.createOr(lparen, rparen, "parens");
     69
     70
     71    Var * const pending_lparen = pb.createVar("pending_lparen", lparen);
     72    Var * const all_closed = pb.createVar("all_closed", pb.createZeroes());
     73    Var * const accumulated_errors = pb.createVar("accumulated_errors", pb.createZeroes());
     74    Var * const in_play = pb.createVar("in_play", parens);
     75    Var * const index = pb.createVar("i", pb.getInteger(0));
     76
     77    Var * matches = kernel->getOutputStreamVar("matches");
    7978
    8079    PabloBuilder body = PabloBuilder::Create(pb);
     
    8281    pb.createWhile(pending_lparen, body);
    8382
    84         pscan = body.createScanTo(body.createAdvance(pending_lparen, 1), in_play);
    85         closed = body.createAnd(pscan, rparen);
     83        PabloAST * pscan = body.createAdvanceThenScanTo(pending_lparen, in_play, "pscan");
     84
     85        PabloAST * closed = body.createAnd(pscan, rparen, "closed");
     86        body.createAssign(all_closed, body.createOr(all_closed, closed));
     87
     88        body.createAssign(pending_lparen, body.createAnd(pscan, lparen));
     89        // Mark any opening paren without a matching closer as an error.
     90        body.createAssign(accumulated_errors, body.createOr(accumulated_errors, body.createAtEOF(pscan)));
     91
    8692        body.createAssign(body.createExtract(matches, index), closed);
    87         body.createAssign(all_closed, body.createOr(all_closed, closed));
    88         body.createAssign(errors, body.createOr(errors, body.createAtEOF(pscan)));
    89 
    90         body.createAssign(pending_lparen, body.createAnd(pscan, lparen));
    91 
    92         unmatched_rparen = body.createAnd(rparen, body.createNot(all_closed));
    93         body.createAssign(in_play, body.createOr(pending_lparen, unmatched_rparen));
    94         body.createAssign(index, body.createAdd(index, one));
    95 
    96 
    97     pb.createAssign(errors, pb.createOr(errors, pb.createAnd(rparen, pb.createNot(all_closed))));
    98     pb.createAssign(kernel->getOutputStreamVar("errors"), errors);
    99 
    100     pb.print(errs());
    101 
    102 }
    103 
    104 //42    def Match_Parens(lex, matches):
    105 //43            parens = lex.LParen | lex.RParen
    106 //44            i = 0
    107 //45            pscan = pablo.AdvanceThenScanTo(lex.LParen, parens)
    108 //46            matches.closed[0] = pscan & lex.RParen
    109 //47            all_closed = matches.closed[0]
    110 //48            matches.error = pablo.atEOF(pscan)
    111 //49            # Not matched, still pending.
    112 //50            pending_LParen = pscan & lex.LParen
    113 //51            RParen_unmatched = lex.RParen &~ matches.closed[0]
    114 //52            inPlay = pending_LParen | RParen_unmatched
    115 //53            while pending_LParen:
    116 //54                    i += 1
    117 //55                    pscan = pablo.AdvanceThenScanTo(pending_LParen, inPlay)
    118 //56                    matches.closed[i] = pscan & lex.RParen
    119 //57                    all_closed |= matches.closed[i]
    120 //58                    matches.error |= pablo.atEOF(pscan)
    121 //59                    pending_LParen = pscan & lex.LParen
    122 //60                    RParen_unmatched = lex.RParen &~ all_closed
    123 //61                    inPlay = pending_LParen | RParen_unmatched
    124 //62            #
    125 //63            # Any closing paren that was not actually used to close
    126 //64            # an opener is in error.
    127 //65            matches.error |= lex.RParen &~ all_closed
     93
     94        PabloAST * pending_rparen = body.createAnd(rparen, body.createNot(all_closed), "pending_rparen");
     95        body.createAssign(in_play, body.createOr(pending_lparen, pending_rparen));
     96        body.createAssign(index, body.createAdd(index, body.getInteger(1)));
     97
     98    // Mark any closing paren that was not actually used to close an opener as an error.
     99    PabloAST * const unmatched_rparen = pb.createAnd(rparen, pb.createNot(all_closed), "unmatched_rparen");
     100    pb.createAssign(kernel->getOutputStreamVar("errors"), pb.createOr(accumulated_errors, unmatched_rparen));
     101
     102}
     103
    128104
    129105Function * pipeline(IDISA::IDISA_Builder * iBuilder, const unsigned count) {
    130106
    131     Type * byteStreamTy = iBuilder->getStreamSetTy(1, 8);
     107    Type * byteStreamTy = iBuilder->getStreamSetTy(1, 2);
    132108
    133109    Module * const mod = iBuilder->getModule();
     
    146122    ExpandableBuffer matches(iBuilder, iBuilder->getStreamSetTy(count, 1), 2);
    147123    SingleBlockBuffer errors(iBuilder, iBuilder->getStreamTy());
     124    ExpandableBuffer output(iBuilder, iBuilder->getStreamSetTy(count * 8, 8), 2);
    148125
    149126    MMapSourceKernel mmapK(iBuilder);
     
    159136
    160137    generate(&bm);
     138    pablo_function_passes(&bm);
    161139
    162140    bm.generateKernel({&BasisBits}, {&matches, &errors});
     141
     142    PrintableStreamSet pss(iBuilder);
     143    pss.generateKernel({&matches}, {&output});
    163144
    164145    iBuilder->SetInsertPoint(BasicBlock::Create(mod->getContext(), "entry", main, 0));
     
    168149    matches.allocateBuffer();
    169150    errors.allocateBuffer();
    170 
    171     generatePipelineLoop(iBuilder, {&mmapK, &s2pk, &bm});
     151    output.allocateBuffer();
     152
     153    generatePipelineLoop(iBuilder, {&mmapK, &s2pk, &bm, &pss});
    172154    iBuilder->CreateRetVoid();
    173155
     
    182164    IDISA::IDISA_Builder * idb = IDISA::GetIDISA_Builder(M);
    183165
    184     llvm::Function * f = pipeline(idb, 2);
     166    llvm::Function * f = pipeline(idb, 3);
    185167
    186168    verifyModule(*M, &dbgs());
  • icGREP/icgrep-devel/icgrep/grep_engine.cpp

    r5321 r5329  
    474474extern "C" {
    475475    void wrapped_report_match(size_t lineNum, size_t line_start, size_t line_end, const char * buffer, size_t filesize, int fileIdx) {
    476 
     476        assert (buffer);
    477477#ifdef CUDA_ENABLED
    478478    if (codegen::NVPTX){
     
    563563extern "C" {
    564564    void insert_codepoints(size_t lineNum, size_t line_start, size_t line_end, const char * buffer) {
     565        assert (buffer);
    565566        re::codepoint_t c = 0;
    566567        ssize_t line_pos = line_start;
  • icGREP/icgrep-devel/icgrep/icgrep-devel.files

    r5298 r5329  
    212212object_cache.cpp
    213213object_cache.h
    214 symboltable.cpp
    215214toolchain.cpp
    216215toolchain.h
  • icGREP/icgrep-devel/icgrep/kernels/alignedprint.cpp

    r5326 r5329  
    1818}
    1919
    20 inline void p2s(IDISA::IDISA_Builder * iBuilder, Value * p[], Value * s[]) {
     20void p2s(IDISA::IDISA_Builder * iBuilder, Value * p[], Value * s[]) {
    2121    Value * bit00004444[2];
    2222    Value * bit22226666[2];
     
    8585}
    8686
    87 PrintableBits::PrintableBits(IDISA::IDISA_Builder * builder)
    88 : BlockOrientedKernel(builder, "PrintableBits", {Binding{builder->getStreamSetTy(1, 1), "bitStream"}}, {Binding{builder->getStreamSetTy(1, 8), "byteStream"}}, {}, {}, {})
    89 {
    90     setNoTerminateAttribute(true);
    91     setDoBlockUpdatesProducedItemCountsAttribute(false);
    92 
    93 }
    94 
    95 SelectStream::SelectStream(IDISA::IDISA_Builder * builder, unsigned sizeInputStreamSet, unsigned streamIndex)
    96 : BlockOrientedKernel(builder, "SelectStream", {Binding{builder->getStreamSetTy(sizeInputStreamSet, 1), "bitStreams"}}, {Binding{builder->getStreamSetTy(1, 1), "bitStream"}}, {}, {}, {}), mSizeInputStreamSet(sizeInputStreamSet), mStreamIndex(streamIndex)
    97 {
    98     setNoTerminateAttribute(true);
    99     setDoBlockUpdatesProducedItemCountsAttribute(false);
    100 
    101 }
    102 
    10387void SelectStream::generateDoBlockMethod() {
    10488    if (mStreamIndex >= mSizeInputStreamSet)
     
    10993    storeOutputStreamBlock("bitStream", iBuilder->getInt32(0), bitStrmVal);
    11094}
     95
     96void PrintableStreamSet::generateDoBlockMethod() {
     97
     98    /*
     99    00110001 is the Unicode codepoint for '1' and 00101110 is the codepoint for '.'.
     100    We want to output a byte stream that is aligned with the input bitstream such that it contains 00110001 in each 1 position and 00101110 in each 0 position.
     101
     102    For example, consider input bitstream 101. Our desired output is:
     103    00110001 00101110 00110001
     104
     105    We can do the bitstream to bytestream conversion in parallel by viewing the output stream in terms of parallel bit streams.
     106
     107    0   0   0 -> First bit position of every byte is all zeros
     108    0   0   0 -> Same for second bit
     109    1   1   1 -> Third bit is all ones
     110    1   0   1 -> 4th bit is 1 for a '1' byte and '0' for a zero byte. Matches input bit stream
     111    0   1   0 -> opposite
     112    0   1   0 -> opposite
     113    0   1   0 -> opposite
     114    1   0   1 -> same as 4th bit position.
     115
     116    Armed with the above we can do the bit->byte conversion all at once
     117    rather than byte at a time! That's what we do below.
     118    */
     119
     120    BasicBlock * entry = iBuilder->GetInsertBlock();
     121    BasicBlock * cond = CreateBasicBlock("cond");
     122    BasicBlock * body = CreateBasicBlock("body");
     123    BasicBlock * exit = CreateBasicBlock("exit");
     124
     125    Value * count = getInputStreamSetCount("bitStream");
     126    iBuilder->CreateBr(cond);
     127    iBuilder->SetInsertPoint(cond);
     128    PHINode * i = iBuilder->CreatePHI(iBuilder->getSizeTy(), 2, "i");
     129    i->addIncoming(iBuilder->getSize(0), entry);
     130
     131    iBuilder->CreateCondBr(iBuilder->CreateICmpNE(i, count), body, exit);
     132    iBuilder->SetInsertPoint(body);
     133    // Load current block
     134    Value * bitStrmVal = loadInputStreamBlock("bitStream", i);
     135
     136    Value * bits[8];
     137
     138    bits[0] = ConstantInt::getNullValue(iBuilder->getBitBlockType());
     139    bits[1] = ConstantInt::getNullValue(iBuilder->getBitBlockType());
     140    bits[2] = ConstantInt::getAllOnesValue(iBuilder->getBitBlockType());
     141    bits[3] = bitStrmVal;
     142    Value * negBitStrmVal = iBuilder->simd_not(bitStrmVal);
     143    bits[4] = negBitStrmVal;
     144    bits[5] = negBitStrmVal;
     145    bits[6] = negBitStrmVal;
     146    bits[7] = bitStrmVal;
     147
     148    // Reassemble the paralell bit streams into a byte stream
     149    Value * printableBytes[8];
     150    p2s(iBuilder, bits, printableBytes);
     151    for (unsigned j = 0; j < 8; ++j) {
     152        storeOutputStreamPack("byteStream", i, iBuilder->getInt32(j), iBuilder->bitCast(printableBytes[j]));
     153    }
     154
     155    i->addIncoming(iBuilder->CreateAdd(i, iBuilder->getSize(1)), iBuilder->GetInsertBlock());
     156    iBuilder->CreateBr(cond);
     157
     158    iBuilder->SetInsertPoint(exit);
    111159}
     160
     161PrintableBits::PrintableBits(IDISA::IDISA_Builder * builder)
     162: BlockOrientedKernel(builder, "PrintableBits", {Binding{builder->getStreamSetTy(1), "bitStream"}}, {Binding{builder->getStreamSetTy(1, 8), "byteStream"}}, {}, {}, {})
     163{
     164    setNoTerminateAttribute(true);
     165    setDoBlockUpdatesProducedItemCountsAttribute(false);
     166}
     167
     168SelectStream::SelectStream(IDISA::IDISA_Builder * builder, unsigned sizeInputStreamSet, unsigned streamIndex)
     169: BlockOrientedKernel(builder, "SelectStream", {Binding{builder->getStreamSetTy(sizeInputStreamSet), "bitStreams"}}, {Binding{builder->getStreamSetTy(1, 1), "bitStream"}}, {}, {}, {}), mSizeInputStreamSet(sizeInputStreamSet), mStreamIndex(streamIndex)
     170{
     171    setNoTerminateAttribute(true);
     172    setDoBlockUpdatesProducedItemCountsAttribute(false);
     173
     174}
     175
     176PrintableStreamSet::PrintableStreamSet(IDISA::IDISA_Builder * builder)
     177: BlockOrientedKernel(builder, "PrintableStreamSet", {Binding{builder->getStreamSetTy(0), "bitStream"}}, {Binding{builder->getStreamSetTy(0, 8), "byteStream"}}, {}, {}, {}) {
     178    setNoTerminateAttribute(true);
     179    setDoBlockUpdatesProducedItemCountsAttribute(false);
     180}
     181
     182
     183
     184}
  • icGREP/icgrep-devel/icgrep/kernels/alignedprint.h

    r5297 r5329  
    3030};
    3131
     32class PrintableStreamSet : public BlockOrientedKernel {
     33public:
     34    PrintableStreamSet(IDISA::IDISA_Builder * builder);
     35    virtual ~PrintableStreamSet() {}
     36private:
     37    void generateDoBlockMethod() override;
     38};
     39
    3240}
    3341#endif
  • icGREP/icgrep-devel/icgrep/kernels/kernel.cpp

    r5328 r5329  
    1414#include <llvm/IR/LegacyPassManager.h>
    1515#include <llvm/Transforms/Scalar.h>
     16#ifndef NDEBUG
     17#include <llvm/IR/Verifier.h>
     18#endif
    1619
    1720static const auto DO_BLOCK_SUFFIX = "_DoBlock";
     
    323326}
    324327
     328llvm::Value * KernelBuilder::getInputStreamSetCount(const std::string & name) const {
     329    return getInputStreamSetBuffer(name)->getStreamSetCount(getStreamSetBufferPtr(name));
     330}
     331
    325332llvm::Value * KernelBuilder::getAdjustedInputStreamBlockPtr(Value * blockAdjustment, const std::string & name, llvm::Value * streamIndex) const {
    326333    Value * blockIndex = computeBlockIndex(mStreamSetInputs, name, getProcessedItemCount(name));
     
    350357}
    351358
     359llvm::Value * KernelBuilder::getOutputStreamSetCount(const std::string & name) const {
     360    return getOutputStreamSetBuffer(name)->getStreamSetCount(getStreamSetBufferPtr(name));
     361}
     362
    352363Value * KernelBuilder::getRawInputPointer(const std::string & name, Value * streamIndex, Value * absolutePosition) const {
    353364    return getInputStreamSetBuffer(name)->getRawItemPointer(getStreamSetBufferPtr(name), streamIndex, absolutePosition);
     
    361372    const auto f = mStreamSetNameMap.find(name);
    362373    if (LLVM_UNLIKELY(f == mStreamSetNameMap.end())) {
    363         throw std::runtime_error(getName() + " does not contain stream set: " + name);
     374        report_fatal_error(getName() + " does not contain stream set: " + name);
    364375    }
    365376    return f->second;
     
    524535    generateDoBlockMethod(); // must be implemented by the KernelBuilder subtype
    525536    iBuilder->CreateRetVoid();
    526 
     537    #ifndef NDEBUG
     538    std::string tmp;
     539    raw_string_ostream out(tmp);
     540    if (verifyFunction(*mCurrentFunction, &out)) {
     541        mCurrentFunction->dump();
     542        report_fatal_error(getName() + ": " + out.str());
     543    }
     544    #endif
    527545    // Use the pass manager to optimize the function.
    528546    FunctionPassManager fpm(iBuilder->getModule());
  • icGREP/icgrep-devel/icgrep/kernels/kernel.h

    r5317 r5329  
    172172
    173173    llvm::Value * getInputStreamBlockPtr(const std::string & name, llvm::Value * streamIndex) const;
    174    
     174
    175175    llvm::Value * loadInputStreamBlock(const std::string & name, llvm::Value * streamIndex) const;
    176176   
     
    179179    llvm::Value * loadInputStreamPack(const std::string & name, llvm::Value * streamIndex, llvm::Value * packIndex) const;
    180180   
     181    llvm::Value * getInputStreamSetCount(const std::string & name) const;
     182
    181183    llvm::Value * getOutputStreamBlockPtr(const std::string & name, llvm::Value * streamIndex) const;
    182184   
     
    186188   
    187189    void storeOutputStreamPack(const std::string & name, llvm::Value * streamIndex, llvm::Value * packIndex, llvm::Value * toStore) const;
    188    
     190
     191    llvm::Value * getOutputStreamSetCount(const std::string & name) const;
     192
    189193    llvm::Value * getAdjustedInputStreamBlockPtr(llvm::Value * blockAdjustment, const std::string & name, llvm::Value * streamIndex) const;
    190194
  • icGREP/icgrep-devel/icgrep/kernels/streamset.cpp

    r5320 r5329  
    3535Value * StreamSetBuffer::getStreamPackPtr(Value * self, Value * streamIndex, Value * blockIndex, Value * packIndex) const {
    3636    return iBuilder->CreateGEP(getStreamSetBlockPtr(self, blockIndex), {iBuilder->getInt32(0), streamIndex, packIndex});
     37}
     38
     39llvm::Value * StreamSetBuffer::getStreamSetCount(Value *) const {
     40    uint64_t count = 1;
     41    if (isa<ArrayType>(mBaseType)) {
     42        count = mBaseType->getArrayNumElements();
     43    }
     44    return iBuilder->getInt32(count);
    3745}
    3846
     
    100108
    101109Value * ExternalFileBuffer::getLinearlyAccessibleItems(llvm::Value *) const {
    102     report_fatal_error("External buffers: getLinearlyAccessibleItems not supported.");
     110    report_fatal_error("External buffers: getLinearlyAccessibleItems is not supported.");
    103111}
    104112
     
    177185// Expandable Buffer
    178186
    179 // Expandable Buffer
    180 
    181187void ExpandableBuffer::allocateBuffer() {
    182188    mStreamSetBufferPtr = iBuilder->CreateCacheAlignedAlloca(getType());
     
    269275}
    270276
     277llvm::Value * ExpandableBuffer::getStreamSetCount(llvm::Value * self) const {
     278    return iBuilder->CreateLoad(iBuilder->CreateGEP(self, {iBuilder->getInt32(0), iBuilder->getInt32(0)}));
     279}
     280
    271281Value * ExpandableBuffer::getStreamSetBlockPtr(Value *, Value *) const {
    272     report_fatal_error("Expandable buffers: getStreamSetPtr is not supported.");
     282    report_fatal_error("Expandable buffers: getStreamSetBlockPtr is not supported.");
    273283}
    274284
  • icGREP/icgrep-devel/icgrep/kernels/streamset.h

    r5320 r5329  
    5151    virtual llvm::Value * getStreamPackPtr(llvm::Value * self, llvm::Value * streamIndex, llvm::Value * blockIndex, llvm::Value * packIndex) const;
    5252   
     53    virtual llvm::Value * getStreamSetCount(llvm::Value * self) const;
     54
    5355    llvm::Value * getRawItemPointer(llvm::Value * self, llvm::Value * streamIndex, llvm::Value * absolutePosition) const;
    5456
     
    165167    void allocateBuffer() override;
    166168
     169    llvm::Value * getStreamSetCount(llvm::Value * self) const override;
     170
    167171protected:
    168172
  • icGREP/icgrep-devel/icgrep/pablo/builder.cpp

    r5283 r5329  
    495495}
    496496
     497PabloAST * PabloBuilder::createScanTo(PabloAST * from, PabloAST * to) {
     498    if (isa<Zeroes>(from)) {
     499        return from;
     500    }
     501    MAKE_BINARY(createScanTo, TypeId::ScanTo, from, to);
     502    return result;
     503}
     504
     505PabloAST * PabloBuilder::createScanTo(PabloAST * from, PabloAST * to, const llvm::StringRef & prefix) {
     506    if (isa<Zeroes>(from)) {
     507        return from;
     508    }
     509    MAKE_NAMED_BINARY(createScanTo, TypeId::ScanTo, prefix, from, to);
     510    return result;
     511}
     512
     513PabloAST * PabloBuilder::createAdvanceThenScanThru(PabloAST * from, PabloAST * thru) {
     514    if (isa<Zeroes>(from) || isa<Zeroes>(thru)) {
     515        return from;
     516    }
     517    MAKE_BINARY(createAdvanceThenScanThru, TypeId::AdvanceThenScanThru, from, thru);
     518    return result;
     519}
     520
     521PabloAST * PabloBuilder::createAdvanceThenScanThru(PabloAST * from, PabloAST * thru, const llvm::StringRef & prefix) {
     522    if (isa<Zeroes>(from) || isa<Zeroes>(thru)) {
     523        return from;
     524    }
     525    MAKE_NAMED_BINARY(createAdvanceThenScanThru, TypeId::AdvanceThenScanThru, prefix, from, thru);
     526    return result;
     527}
     528
     529PabloAST * PabloBuilder::createAdvanceThenScanTo(PabloAST * from, PabloAST * to) {
     530    if (isa<Zeroes>(from)) {
     531        return from;
     532    }
     533    MAKE_BINARY(createAdvanceThenScanTo, TypeId::ScanTo, from, to);
     534    return result;
     535}
     536
     537PabloAST * PabloBuilder::createAdvanceThenScanTo(PabloAST * from, PabloAST * to, const llvm::StringRef & prefix) {
     538    if (isa<Zeroes>(from)) {
     539        return from;
     540    }
     541    MAKE_NAMED_BINARY(createAdvanceThenScanTo, TypeId::ScanTo, prefix, from, to);
     542    return result;
     543}
    497544
    498545PabloAST * PabloBuilder::createSel(PabloAST * condition, PabloAST * trueExpr, PabloAST * falseExpr) {
  • icGREP/icgrep-devel/icgrep/pablo/builder.hpp

    r5320 r5329  
    6666    }
    6767
    68     inline Var * createVar(const llvm::StringRef name, llvm::Type * const type = nullptr) {
     68    inline Var * createVar(const llvm::StringRef & name, llvm::Type * const type = nullptr) {
    6969        return createVar(makeName(name), type);
    7070    }
    7171
    72     inline Var * createVar(const llvm::StringRef name, PabloAST * value) {
     72    inline Var * createVar(const llvm::StringRef & name, PabloAST * value) {
    7373        Var * var = createVar(name, value->getType());
    7474        createAssign(var, value);
     
    148148    PabloAST * createScanThru(PabloAST * from, PabloAST * thru, const llvm::StringRef & prefix);
    149149
    150     PabloAST * createScanTo(PabloAST * from, PabloAST * to) {
    151         return createScanThru(from, createNot(to));
    152     }
    153 
    154     PabloAST * createScanTo(PabloAST * from, PabloAST * to, const llvm::StringRef & prefix) {
    155         return createScanThru(from, createNot(to), prefix);
    156     }
     150    PabloAST * createScanTo(PabloAST * from, PabloAST * to);
     151
     152    PabloAST * createScanTo(PabloAST * from, PabloAST * to, const llvm::StringRef & prefix);
     153
     154    PabloAST * createAdvanceThenScanThru(PabloAST * from, PabloAST * thru);
     155
     156    PabloAST * createAdvanceThenScanThru(PabloAST * from, PabloAST * thru, const llvm::StringRef & prefix);
     157
     158    PabloAST * createAdvanceThenScanTo(PabloAST * from, PabloAST * to);
     159
     160    PabloAST * createAdvanceThenScanTo(PabloAST * from, PabloAST * to, const llvm::StringRef & prefix);
    157161
    158162    PabloAST * createSel(PabloAST * condition, PabloAST * trueExpr, PabloAST * falseExpr);
  • icGREP/icgrep-devel/icgrep/pablo/carry_manager.cpp

    r5312 r5329  
    2828inline static unsigned ceil_udiv(const unsigned x, const unsigned y) {
    2929    return (((x - 1) | (y - 1)) + 1) / y;
     30}
     31
     32using TypeId = PabloAST::ClassTypeId;
     33
     34inline static bool isNonAdvanceCarryGeneratingStatement(const Statement * const stmt) {
     35    switch (stmt->getClassTypeId()) {
     36        case TypeId::ScanThru:
     37        case TypeId::AdvanceThenScanThru:
     38        case TypeId::ScanTo:
     39        case TypeId::AdvanceThenScanTo:
     40        case TypeId::MatchStar:
     41            return true;
     42        default:
     43            return false;
     44    }
    3045}
    3146
     
    338353 * @brief addCarryInCarryOut
    339354 ** ------------------------------------------------------------------------------------------------------------- */
    340 Value * CarryManager::addCarryInCarryOut(const Statement * operation, Value * const e1, Value * const e2) {
    341     assert (dyn_cast_or_null<ScanThru>(operation) || dyn_cast_or_null<MatchStar>(operation));
     355Value * CarryManager::addCarryInCarryOut(const Statement * const operation, Value * const e1, Value * const e2) {
     356    assert (operation && (isNonAdvanceCarryGeneratingStatement(operation)));
    342357    Value * const carryIn = getNextCarryIn();
    343358    Value * carryOut, * result;
     
    351366 * @brief advanceCarryInCarryOut
    352367 ** ------------------------------------------------------------------------------------------------------------- */
    353 Value * CarryManager::advanceCarryInCarryOut(const Advance * advance, Value * const value) {
     368Value * CarryManager::advanceCarryInCarryOut(const Advance * const advance, Value * const value) {
    354369    const auto shiftAmount = advance->getAmount();
    355370    if (LLVM_LIKELY(shiftAmount <= mBitBlockWidth)) {
     
    577592                state.push_back(type);
    578593            }
    579         } else if (LLVM_UNLIKELY(isa<ScanThru>(stmt) || isa<MatchStar>(stmt))) {
     594        } else if (LLVM_UNLIKELY(isNonAdvanceCarryGeneratingStatement(stmt))) {
    580595            state.push_back(carryPackType);
    581596        } else if (LLVM_UNLIKELY(isa<If>(stmt))) {
  • icGREP/icgrep-devel/icgrep/pablo/codegenstate.cpp

    r5298 r5329  
    255255}
    256256
     257ScanTo * PabloBlock::createScanTo(PabloAST * from, PabloAST * to, String * name) {
     258    CHECK_SAME_TYPE(from, to);
     259    if (name == nullptr) {
     260        name = makeName("scanto");
     261    }
     262    return insertAtInsertionPoint(new (mAllocator) ScanTo(from, to, name, mAllocator));
     263}
     264
     265AdvanceThenScanThru * PabloBlock::createAdvanceThenScanThru(PabloAST * from, PabloAST * thru, String * name) {
     266    CHECK_SAME_TYPE(from, thru);
     267    if (name == nullptr) {
     268        name = makeName("advscanthru");
     269    }
     270    return insertAtInsertionPoint(new (mAllocator) AdvanceThenScanThru(from, thru, name, mAllocator));
     271}
     272
     273AdvanceThenScanTo * PabloBlock::createAdvanceThenScanTo(PabloAST * from, PabloAST * to, String * name) {
     274    CHECK_SAME_TYPE(from, to);
     275    if (name == nullptr) {
     276        name = makeName("advscanto");
     277    }
     278    return insertAtInsertionPoint(new (mAllocator) AdvanceThenScanTo(from, to, name, mAllocator));
     279}
     280
    257281If * PabloBlock::createIf(PabloAST * condition, PabloBlock * body) {
    258282    assert (condition);
  • icGREP/icgrep-devel/icgrep/pablo/codegenstate.h

    r5307 r5329  
    1515namespace pablo { class Add; }
    1616namespace pablo { class Advance; }
     17namespace pablo { class AdvanceThenScanThru; }
     18namespace pablo { class AdvanceThenScanTo; }
    1719namespace pablo { class And; }
    1820namespace pablo { class Assign; }
     
    3234namespace pablo { class PabloKernel; }
    3335namespace pablo { class ScanThru; }
     36namespace pablo { class ScanTo; }
    3437namespace pablo { class Sel; }
    3538namespace pablo { class String; }
     
    238241    ScanThru * createScanThru(PabloAST * from, PabloAST * thru, String * name);
    239242
     243    ScanTo * createScanTo(PabloAST * from, PabloAST * to) {
     244        return createScanTo(from, to, nullptr);
     245    }
     246
     247    ScanTo * createScanTo(PabloAST * from, PabloAST * to, const llvm::StringRef & prefix) {
     248        return createScanTo(from, to, makeName(prefix));
     249    }
     250
     251    ScanTo * createScanTo(PabloAST * from, PabloAST * to, String * name);
     252
     253    AdvanceThenScanThru * createAdvanceThenScanThru(PabloAST * from, PabloAST * thru) {
     254        return createAdvanceThenScanThru(from, thru, nullptr);
     255    }
     256
     257    AdvanceThenScanThru * createAdvanceThenScanThru(PabloAST * from, PabloAST * thru, const llvm::StringRef & prefix) {
     258        return createAdvanceThenScanThru(from, thru, makeName(prefix));
     259    }
     260
     261    AdvanceThenScanThru * createAdvanceThenScanThru(PabloAST * from, PabloAST * thru, String * name);
     262
     263    AdvanceThenScanTo * createAdvanceThenScanTo(PabloAST * from, PabloAST * to) {
     264        return createAdvanceThenScanTo(from, to, nullptr);
     265    }
     266
     267    AdvanceThenScanTo * createAdvanceThenScanTo(PabloAST * from, PabloAST * to, const llvm::StringRef & prefix) {
     268        return createAdvanceThenScanTo(from, to, makeName(prefix));
     269    }
     270
     271    AdvanceThenScanTo * createAdvanceThenScanTo(PabloAST * from, PabloAST * to, String * name);
     272
    240273    If * createIf(PabloAST * condition, PabloBlock * body);
    241274
    242275    While * createWhile(PabloAST * condition, PabloBlock * body);
    243276
    244 //    llvm::Type * getStreamTy(const unsigned FieldWidth = 1) {
    245 //        return mParent->getStreamTy(FieldWidth);
    246 //    }
    247    
    248277    llvm::Type * getStreamSetTy(const unsigned NumElements = 1, const unsigned FieldWidth = 1) {
    249278        return mParent->getStreamSetTy(NumElements, FieldWidth);
  • icGREP/icgrep-devel/icgrep/pablo/optimizers/pablo_simplifier.cpp

    r5267 r5329  
    1616#include <pablo/analysis/pabloverifier.hpp>
    1717#endif
     18#include <llvm/Support/raw_ostream.h>
     19
    1820
    1921using namespace boost;
     
    614616 ** ------------------------------------------------------------------------------------------------------------- */
    615617void Simplifier::strengthReduction(PabloBlock * const block) {
     618
    616619    Statement * stmt = block->front();
    617620    while (stmt) {
     
    636639                Advance * adv = cast<Advance>(scanThru->getScanFrom());
    637640                if (LLVM_UNLIKELY(adv->getNumUses() == 1)) {
    638                     block->setInsertPoint(scanThru->getPrevNode());
    639                     PabloAST * expr = block->createAdvance(adv->getOperand(0), block->getInteger(adv->getAmount() - 1));
    640                     scanThru->setOperand(0, expr);
    641                     scanThru->setOperand(1, block->createOr(scanThru->getOperand(1), expr));
     641                    PabloAST * stream = adv->getExpression();
     642                    block->setInsertPoint(stmt);
     643                    if (LLVM_UNLIKELY(adv->getAmount() != 1)) {
     644                        stream = block->createAdvance(stream, block->getInteger(adv->getAmount() - 1));
     645                    }
     646                    stmt = scanThru->replaceWith(block->createAdvanceThenScanThru(stream, scanThru->getScanThru()));
    642647                    adv->eraseFromParent(false);
     648                    continue;
    643649                }
    644650            } else if (LLVM_UNLIKELY(isa<And>(scanThru->getScanFrom()))) {
     
    651657
    652658
     659            }
     660        } else if (LLVM_UNLIKELY(isa<ScanTo>(stmt))) {
     661            ScanTo * scanTo = cast<ScanTo>(stmt);
     662            if (LLVM_UNLIKELY(isa<Advance>(scanTo->getScanFrom()))) {
     663                // Replace a ScanTo(Advance(x,n),y) with an ScanTo(Advance(x, n - 1), Advance(x, n - 1) | y), where Advance(x, 0) = x
     664                Advance * adv = cast<Advance>(scanTo->getScanFrom());
     665                if (LLVM_UNLIKELY(adv->getNumUses() == 1)) {
     666                    PabloAST * stream = adv->getExpression();
     667                    block->setInsertPoint(stmt);
     668                    if (LLVM_UNLIKELY(adv->getAmount() != 1)) {
     669                        stream = block->createAdvance(stream, block->getInteger(adv->getAmount() - 1));
     670                    }
     671                    stmt = scanTo->replaceWith(block->createAdvanceThenScanTo(stream, scanTo->getScanTo()));
     672                    adv->eraseFromParent(false);
     673                    continue;
     674                }
    653675            }
    654676        }
  • icGREP/icgrep-devel/icgrep/pablo/pabloAST.h

    r5283 r5329  
    7777        , Advance
    7878        , ScanThru
     79        , AdvanceThenScanThru
     80        , ScanTo
     81        , AdvanceThenScanTo
    7982        , Lookahead
    8083        , MatchStar
  • icGREP/icgrep-devel/icgrep/pablo/pablo_compiler.cpp

    r5320 r5329  
    337337
    338338        incomingPhi->addIncoming(outgoingValue, whileExitBlock);
    339         f->second = incomingPhi;
    340339    }
    341340
     
    457456            value = iBuilder->simd_or(iBuilder->simd_xor(sum, cc), marker);
    458457        } else if (const ScanThru * sthru = dyn_cast<ScanThru>(stmt)) {
     458            Value * const from = compileExpression(sthru->getScanFrom());
     459            Value * const thru = compileExpression(sthru->getScanThru());
     460            Value * const sum = mCarryManager->addCarryInCarryOut(sthru, from, thru);
     461            value = iBuilder->simd_and(sum, iBuilder->simd_not(thru));
     462        } else if (const ScanTo * sthru = dyn_cast<ScanTo>(stmt)) {
    459463            Value * const marker_expr = compileExpression(sthru->getScanFrom());
    460             Value * const cc_expr = compileExpression(sthru->getScanThru());
    461             Value * const sum = mCarryManager->addCarryInCarryOut(sthru, marker_expr, cc_expr);
    462             value = iBuilder->simd_and(sum, iBuilder->simd_not(cc_expr));
     464            Value * const to = iBuilder->simd_xor(compileExpression(sthru->getScanTo()), mKernel->getScalarField("EOFmask"));
     465            Value * const sum = mCarryManager->addCarryInCarryOut(sthru, marker_expr, iBuilder->simd_not(to));
     466            value = iBuilder->simd_and(sum, to);
     467        } else if (const AdvanceThenScanThru * sthru = dyn_cast<AdvanceThenScanThru>(stmt)) {
     468            Value * const from = compileExpression(sthru->getScanFrom());
     469            Value * const thru = compileExpression(sthru->getScanThru());
     470            Value * const sum = mCarryManager->addCarryInCarryOut(sthru, from, iBuilder->simd_or(from, thru));
     471            value = iBuilder->simd_and(sum, iBuilder->simd_not(thru));
     472        } else if (const AdvanceThenScanTo * sthru = dyn_cast<AdvanceThenScanTo>(stmt)) {
     473            Value * const from = compileExpression(sthru->getScanFrom());
     474            Value * const to = iBuilder->simd_xor(compileExpression(sthru->getScanTo()), mKernel->getScalarField("EOFmask"));
     475            Value * const sum = mCarryManager->addCarryInCarryOut(sthru, from, iBuilder->simd_or(from, iBuilder->simd_not(to)));
     476            value = iBuilder->simd_and(sum, to);
    463477        } else if (const InFile * e = dyn_cast<InFile>(stmt)) {
    464478            Value * EOFmask = mKernel->getScalarField("EOFmask");
     
    546560        if (DebugOptionIsSet(DumpTrace)) {
    547561            const String & name = isa<Var>(expr) ? cast<Var>(expr)->getName() : cast<Statement>(expr)->getName();
     562            if (value->getType()->isPointerTy()) {
     563                value = iBuilder->CreateLoad(value);
     564            }
    548565            if (value->getType()->isVectorTy()) {
    549566                iBuilder->CallPrintRegister(name.str(), value);
  • icGREP/icgrep-devel/icgrep/pablo/pe_scanthru.h

    r5230 r5329  
    3636};
    3737
     38class ScanTo : public Statement {
     39    friend class PabloBlock;
     40public:
     41    static inline bool classof(const PabloAST * e) {
     42        return e->getClassTypeId() == ClassTypeId::ScanTo;
     43    }
     44    static inline bool classof(const void *) {
     45        return false;
     46    }
     47    virtual ~ScanTo() {
     48    }
     49    PabloAST * getScanFrom() const {
     50        return getOperand(0);
     51    }
     52    PabloAST * getScanTo() const {
     53        return getOperand(1);
     54    }
     55protected:
     56    ScanTo(PabloAST * from, PabloAST * to, const String * name, Allocator & allocator)
     57    : Statement(ClassTypeId::ScanTo, from->getType(), {from, to}, name, allocator) {
     58
     59    }
     60};
     61
     62class AdvanceThenScanThru : public Statement {
     63    friend class PabloBlock;
     64public:
     65    static inline bool classof(const PabloAST * e) {
     66        return e->getClassTypeId() == ClassTypeId::AdvanceThenScanThru;
     67    }
     68    static inline bool classof(const void *) {
     69        return false;
     70    }
     71    virtual ~AdvanceThenScanThru() {
     72    }
     73    PabloAST * getScanFrom() const {
     74        return getOperand(0);
     75    }
     76    PabloAST * getScanThru() const {
     77        return getOperand(1);
     78    }
     79protected:
     80    AdvanceThenScanThru(PabloAST * from, PabloAST * thru, const String * name, Allocator & allocator)
     81    : Statement(ClassTypeId::AdvanceThenScanThru, from->getType(), {from, thru}, name, allocator) {
     82
     83    }
     84};
     85
     86class AdvanceThenScanTo : public Statement {
     87    friend class PabloBlock;
     88public:
     89    static inline bool classof(const PabloAST * e) {
     90        return e->getClassTypeId() == ClassTypeId::AdvanceThenScanTo;
     91    }
     92    static inline bool classof(const void *) {
     93        return false;
     94    }
     95    virtual ~AdvanceThenScanTo() {
     96    }
     97    PabloAST * getScanFrom() const {
     98        return getOperand(0);
     99    }
     100    PabloAST * getScanTo() const {
     101        return getOperand(1);
     102    }
     103protected:
     104    AdvanceThenScanTo(PabloAST * from, PabloAST * to, const String * name, Allocator & allocator)
     105    : Statement(ClassTypeId::AdvanceThenScanTo, from->getType(), {from, to}, name, allocator) {
     106
     107    }
     108};
     109
    38110}
    39111
  • icGREP/icgrep-devel/icgrep/pablo/printer_pablos.cpp

    r5283 r5329  
    114114            out << ", ";
    115115            print(sthru->getScanThru(), out);
     116            out << ")";
     117        } else if (const ScanTo * sto = dyn_cast<ScanTo>(stmt)) {
     118            out << " = pablo.ScanTo(";
     119            print(sto->getScanFrom(), out);
     120            out << ", ";
     121            print(sto->getScanTo(), out);
     122            out << ")";
     123        } else if (const AdvanceThenScanThru * sthru = dyn_cast<AdvanceThenScanThru>(stmt)) {
     124            out << " = pablo.AdvanceThenScanThru(";
     125            print(sthru->getScanFrom(), out);
     126            out << ", ";
     127            print(sthru->getScanThru(), out);
     128            out << ")";
     129        } else if (const AdvanceThenScanTo * sto = dyn_cast<AdvanceThenScanTo>(stmt)) {
     130            out << " = pablo.AdvanceThenScanTo(";
     131            print(sto->getScanFrom(), out);
     132            out << ", ";
     133            print(sto->getScanTo(), out);
    116134            out << ")";
    117135        } else if (const Count * count = dyn_cast<Count>(stmt)) {
  • icGREP/icgrep-devel/icgrep/wc.cpp

    r5319 r5329  
    196196static ExecutionEngine * wcEngine = nullptr;
    197197
    198 wcFunctionType wcCodeGen(void) { 
     198wcFunctionType wcCodeGen(void) {
    199199    Module * M = new Module("wc", getGlobalContext());
    200200    IDISA::IDISA_Builder * idb = IDISA::GetIDISA_Builder(M);
Note: See TracChangeset for help on using the changeset viewer.