Changeset 5310 for icGREP


Ignore:
Timestamp:
Feb 10, 2017, 1:48:34 PM (2 years ago)
Author:
nmedfort
Message:

Adjusted pablo compiler to use getInputStream and getOutputStream when accessing packed stream fields.

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

Legend:

Unmodified
Added
Removed
  • icGREP/icgrep-devel/icgrep/array-test.cpp

    r5267 r5310  
    4141static cl::list<std::string> inputFiles(cl::Positional, cl::desc("<input file ...>"), cl::OneOrMore);
    4242
    43 void generate(PabloKernel * kernel, const unsigned size) {
     43void generate(PabloKernel * kernel) {
    4444
    4545    PabloBuilder pb(kernel->getEntryBlock());
    4646
    47     Var * input = kernel->addInput("input", kernel->getStreamSetTy(8));
    48     Var * matches = kernel->addOutput("matches", kernel->getStreamSetTy(size));
     47    Var * input = kernel->getInputStreamVar("input");
     48    Var * matches = kernel->getOutputStreamVar("matches");
    4949
    5050    PabloAST * basis[8];
     
    125125    s2pk.generateKernel({&ByteStream}, {&BasisBits});
    126126
    127     PabloKernel bm(iBuilder, "MatchParens");
    128     generate(&bm, count);
     127    PabloKernel bm(iBuilder, "MatchParens",
     128        {Binding{iBuilder->getStreamSetTy(8), "input"}},
     129        {Binding{iBuilder->getStreamSetTy(count), "matches"}});
     130
     131    generate(&bm);
    129132
    130133    bm.generateKernel({&BasisBits}, {&matches});
  • icGREP/icgrep-devel/icgrep/cc/cc_compiler.cpp

    r5299 r5310  
    1919namespace cc {
    2020
    21     CC_Compiler::CC_Compiler(PabloKernel * kernel, const unsigned encodingBits, const std::string prefix)
    22     : mBuilder(kernel->getEntryBlock())
    23     , mEncodingBits(encodingBits)
    24     , mBasisBit(encodingBits) {
     21//    CC_Compiler::CC_Compiler(PabloKernel * kernel, const unsigned encodingBits, const std::string prefix)
     22//    : mBuilder(kernel->getEntryBlock())
     23//    , mEncodingBits(encodingBits)
     24//    , mBasisBit(encodingBits) {
    2525       
    26         // TODO: basisBits should be defined prior and only retrieved here.
    27         Var * const basisBits = kernel->addInput(prefix, kernel->getStreamSetTy(encodingBits));
    28         for (unsigned i = 0; i != mEncodingBits; i++) {
    29             mBasisBit[i] = mBuilder.createExtract(basisBits, mBuilder.getInteger(i)); assert (mBasisBit[i]);
    30         }
    31         mEncodingMask = (static_cast<unsigned>(1) << encodingBits) - static_cast<unsigned>(1);
    32     }
     26//        // TODO: basisBits should be defined prior and only retrieved here.
     27//        Var * const basisBits = kernel->addInput(prefix, kernel->getStreamSetTy(encodingBits));
     28//        for (unsigned i = 0; i != mEncodingBits; i++) {
     29//            mBasisBit[i] = mBuilder.createExtract(basisBits, mBuilder.getInteger(i)); assert (mBasisBit[i]);
     30//        }
     31//        mEncodingMask = (static_cast<unsigned>(1) << encodingBits) - static_cast<unsigned>(1);
     32//    }
    3333   
    3434   
    3535    CC_Compiler::CC_Compiler(pablo::PabloKernel * kernel, pablo::Var * basisBits)
    3636    : mBuilder(kernel->getEntryBlock())
    37     , mEncodingBits(dyn_cast<ArrayType>(basisBits->getType())->getNumElements())
     37    , mEncodingBits(basisBits->getType()->getArrayNumElements())
    3838    , mBasisBit(mEncodingBits) {
    3939        for (unsigned i = 0; i != mEncodingBits; i++) {
  • icGREP/icgrep-devel/icgrep/cc/cc_compiler.h

    r5299 r5310  
    2424    using Vars = std::vector<pablo::Var *>;
    2525
    26     CC_Compiler(pablo::PabloKernel * kernel, const unsigned encodingBits = 8, const std::string prefix = "basis");
     26//    CC_Compiler(pablo::PabloKernel * kernel, const unsigned encodingBits = 8, const std::string prefix = "basis");
    2727   
    2828    CC_Compiler(pablo::PabloKernel * kernel, pablo::Var * basisBitSet);
  • icGREP/icgrep-devel/icgrep/editd/editd.cpp

    r5292 r5310  
    190190    PabloBuilder entry(kernel.getEntryBlock());
    191191
    192     Var * pat = kernel.addInput("pat", iBuilder->getStreamSetTy(4));
     192    Var * pat = kernel.getInputStreamVar("pat");
    193193
    194194    PabloAST * basisBits[4];
     
    228228    mmapK.setInitialArguments({fileSize});
    229229   
    230     PabloKernel editdk(iBuilder, "editd");
     230    PabloKernel editdk(iBuilder, "editd",
     231                        {Binding{iBuilder->getStreamSetTy(4), "pat"}},
     232                        {Binding{iBuilder->getStreamSetTy(editDistance + 1), "E"}});
    231233
    232234    buildPatternKernel(editdk, iBuilder, patterns);
     
    259261
    260262void buildPreprocessKernel(PabloKernel & kernel, IDISA::IDISA_Builder * iBuilder) {
    261     cc::CC_Compiler ccc(&kernel);
     263    cc::CC_Compiler ccc(&kernel, kernel.getInputStreamVar("basis"));
     264
    262265    PabloBuilder & pb = ccc.getBuilder();
    263266
     
    267270    PabloAST * G = ccc.compileCC(re::makeCC(re::makeCC(0x47), re::makeCC(0x67)), pb);
    268271
    269     Var * const pat = kernel.addOutput("pat", iBuilder->getStreamSetTy(4));
     272    Var * const pat = kernel.getOutputStreamVar("pat");
    270273
    271274    pb.createAssign(pb.createExtract(pat, 0), A);
     
    307310    std::unique_ptr<Module> s2pM = s2pk.createKernelModule({&ByteStream}, {&BasisBits});
    308311
    309     PabloKernel  ccck(iBuilder, "ccc");
     312    PabloKernel ccck(iBuilder, "ccc",
     313                {{iBuilder->getStreamSetTy(8), "basis"}},
     314                {{iBuilder->getStreamSetTy(4), "pat"}});
    310315
    311316    buildPreprocessKernel(ccck, iBuilder);
  • icGREP/icgrep-devel/icgrep/editd/pattern_compiler.cpp

    r5267 r5310  
    107107
    108108
    109     Var * output = mKernel.addOutput("E", mKernel.getBuilder()->getStreamSetTy(dist + 1));
     109    Var * output = mKernel.getOutputStreamVar("E");
    110110    for (int d = 0; d <= dist; d++) {
    111111        pb.createAssign(pb.createExtract(output, d), E[d]);
  • icGREP/icgrep-devel/icgrep/grep_engine.cpp

    r5294 r5310  
    224224#endif
    225225
    226     Module * cpuM = new Module(moduleName+":cpu", getGlobalContext());
     226    Module * cpuM = new Module(moduleName + ":cpu", getGlobalContext());
    227227    IDISA::IDISA_Builder * CPUBuilder = IDISA::GetIDISA_Builder(cpuM);
    228228
     
    234234    // segment size made availabe for each call to the mmap source kernel
    235235    const unsigned segmentSize = codegen::SegmentSize;
    236     unsigned bufferSegments = codegen::BufferSegments;
    237     if (segmentPipelineParallel)
    238         {
    239             bufferSegments = codegen::BufferSegments * codegen::ThreadNum;
    240         }
     236    const unsigned bufferSegments = segmentPipelineParallel ? (codegen::BufferSegments * codegen::ThreadNum) : codegen::BufferSegments;
    241237    const unsigned encodingBits = UTF_16 ? 16 : 8;
    242238
     
    302298    mmapK.setInitialArguments({fileSize});
    303299   
    304     CircularBuffer BasisBits(iBuilder, iBuilder->getStreamSetTy(8, 1), segmentSize * bufferSegments);
     300    CircularBuffer BasisBits(iBuilder, iBuilder->getStreamSetTy(8), segmentSize * bufferSegments);
    305301
    306302    kernel::S2PKernel  s2pk(iBuilder);
    307303    s2pk.generateKernel({&ByteStream}, {&BasisBits});
    308    
    309     pablo::PabloKernel icgrepK(iBuilder, "icgrep");
    310 
    311     re_ast = re::regular_expression_passes(re_ast);
    312     re::re2pablo_compiler(&icgrepK, encodingBits, re_ast, CountOnly);
     304       
     305    pablo::PabloKernel icgrepK(iBuilder, "icgrep", {Binding{iBuilder->getStreamSetTy(8), "basis"}});
     306    re::re2pablo_compiler(&icgrepK, re::regular_expression_passes(re_ast), CountOnly);
    313307    pablo_function_passes(&icgrepK);
    314308
     
    317311
    318312    if (CountOnly) {
    319         icgrepK.generateKernel({&BasisBits}, {});       
     313        icgrepK.generateKernel({&BasisBits}, {});
    320314        if (pipelineParallel){
    321315            generatePipelineParallel(iBuilder, {&mmapK, &s2pk, &icgrepK});
     
    325319            generatePipelineLoop(iBuilder, {&mmapK, &s2pk, &icgrepK});
    326320        }
    327 
    328         Value * matchCount = icgrepK.createGetAccumulatorCall(icgrepK.getInstance(), "matchedLineCount");
    329 
    330         iBuilder->CreateRet(matchCount);
    331 
     321        iBuilder->CreateRet(icgrepK.createGetAccumulatorCall(icgrepK.getInstance(), "matchedLineCount"));
    332322    } else {
    333323#ifdef CUDA_ENABLED
     
    342332#endif
    343333        if (CPU_Only) {
    344             CircularBuffer MatchResults(iBuilder, iBuilder->getStreamSetTy( 2, 1), segmentSize * bufferSegments);
     334            CircularBuffer MatchResults(iBuilder, iBuilder->getStreamSetTy(2, 1), segmentSize * bufferSegments);
    345335            MatchResults.allocateBuffer();
    346336
     
    378368    }
    379369#endif
    380    
    381      
     370
     371
    382372    mEngine = JIT_to_ExecutionEngine(cpuM);
    383373    ApplyObjectCache(mEngine);
  • icGREP/icgrep-devel/icgrep/kernels/cc_kernel.cpp

    r5297 r5310  
    6666, const std::vector<CC *> & charClasses
    6767, unsigned basisBitsCount)
    68 : PabloKernel(iBuilder, ccSetName +"_kernel") {
    69 
    70     CC_Compiler ccc(this, basisBitsCount);
     68: PabloKernel(iBuilder, ccSetName +"_kernel", {Binding{iBuilder->getStreamSetTy(basisBitsCount), "basis"}}) {
     69    CC_Compiler ccc(this, getInput(0));
    7170    auto & builder = ccc.getBuilder();
    7271    for (CC * cc : charClasses) {
  • icGREP/icgrep-devel/icgrep/kernels/kernel.cpp

    r5307 r5310  
    6262    }
    6363    for (unsigned i = 0; i < mStreamSetOutputs.size(); i++) {
    64         mStreamSetNameMap.emplace(mStreamSetOutputs[i].name, mStreamSetInputs.size() + i);
     64        mStreamSetNameMap.emplace(mStreamSetOutputs[i].name, i);
    6565    }
    6666}
     
    253253}
    254254
    255 inline static uint64_t log2(const uint64_t x) {
    256     return (64 - __builtin_clzll(x)) - 1;
    257 }
    258 
    259 inline static uint32_t log2(const uint32_t x) {
    260     return (32 - __builtin_clz(x)) - 1;
    261 }
    262 
    263255inline Value * KernelBuilder::computeBlockIndex(const std::vector<Binding> & bindings, const std::string & name, Value * itemCount) const {
    264256    for (const Binding & b : bindings) {
     
    266258            const auto divisor = (b.step == 0) ? iBuilder->getBitBlockWidth() : b.step;
    267259            if (LLVM_LIKELY((divisor & (divisor - 1)) == 0)) {
    268                 return iBuilder->CreateLShr(itemCount, log2(divisor));
     260                return iBuilder->CreateLShr(itemCount, std::log2(divisor));
    269261            } else {
    270262                return iBuilder->CreateUDiv(itemCount, iBuilder->getSize(divisor));
     
    277269Value * KernelBuilder::getInputStream(const std::string & name, Value * streamIndex) const {
    278270    Value * const blockIndex = computeBlockIndex(mStreamSetInputs, name, getProcessedItemCount(name));
    279     const StreamSetBuffer * const buf = getStreamSetBuffer(name);
     271    const StreamSetBuffer * const buf = getInputStreamSetBuffer(name);
    280272    return buf->getStream(getStreamSetBufferPtr(name), streamIndex, blockIndex);
    281273}
     
    283275Value * KernelBuilder::getInputStream(const std::string & name, Value * streamIndex, Value * packIndex) const {
    284276    Value * const blockIndex = computeBlockIndex(mStreamSetInputs, name, getProcessedItemCount(name));
    285     const StreamSetBuffer * const buf = getStreamSetBuffer(name);
     277    const StreamSetBuffer * const buf = getInputStreamSetBuffer(name);
    286278    return buf->getStream(getStreamSetBufferPtr(name), streamIndex, blockIndex, packIndex);
    287279}
     
    289281Value * KernelBuilder::getOutputStream(const std::string & name, Value * streamIndex) const {
    290282    Value * const blockIndex = computeBlockIndex(mStreamSetOutputs, name, getProducedItemCount(name));
    291     const StreamSetBuffer * const buf = getStreamSetBuffer(name);
     283    const StreamSetBuffer * const buf = getOutputStreamSetBuffer(name);
    292284    return buf->getStream(getStreamSetBufferPtr(name), streamIndex, blockIndex);
    293285}
     
    295287Value * KernelBuilder::getOutputStream(const std::string & name, Value * streamIndex, Value * packIndex) const {
    296288    Value * const blockIndex = computeBlockIndex(mStreamSetOutputs, name, getProducedItemCount(name));
    297     const StreamSetBuffer * const buf = getStreamSetBuffer(name);
     289    const StreamSetBuffer * const buf = getOutputStreamSetBuffer(name);
    298290    return buf->getStream(getStreamSetBufferPtr(name), streamIndex, blockIndex, packIndex);
    299291}
    300292
    301 Value * KernelBuilder::getRawItemPointer(const std::string & name, Value * streamIndex, Value * absolutePosition) const {
    302     return getStreamSetBuffer(name)->getRawItemPointer(getStreamSetBufferPtr(name), streamIndex, absolutePosition);
     293Value * KernelBuilder::getRawInputPointer(const std::string & name, Value * streamIndex, Value * absolutePosition) const {
     294    return getInputStreamSetBuffer(name)->getRawItemPointer(getStreamSetBufferPtr(name), streamIndex, absolutePosition);
     295}
     296
     297Value * KernelBuilder::getRawOutputPointer(const std::string & name, Value * streamIndex, Value * absolutePosition) const {
     298    return getOutputStreamSetBuffer(name)->getRawItemPointer(getStreamSetBufferPtr(name), streamIndex, absolutePosition);
    303299}
    304300
     
    306302    const auto f = mStreamSetNameMap.find(name);
    307303    if (LLVM_UNLIKELY(f == mStreamSetNameMap.end())) {
    308         report_fatal_error("Kernel " + getName() + " does not contain stream set: " + name);
     304        throw std::runtime_error("Kernel " + getName() + " does not contain stream set: " + name);
    309305    }
    310306    return f->second;
    311 }
    312 
    313 const StreamSetBuffer * KernelBuilder::getStreamSetBuffer(const std::string & name) const {
    314     const unsigned structIdx = getStreamSetIndex(name);
    315     if (structIdx < mStreamSetInputs.size()) {
    316         return mStreamSetInputBuffers[structIdx];
    317     } else {
    318         return mStreamSetOutputBuffers[structIdx - mStreamSetInputs.size()];
    319     }
    320307}
    321308
     
    341328}
    342329
    343 Value * KernelBuilder::getStreamSetPtr(const std::string & name, Value * blockNo) const {
    344     return getStreamSetBuffer(name)->getStreamSetPtr(getStreamSetBufferPtr(name), blockNo);
     330Value * KernelBuilder::getInputStreamSetPtr(const std::string & name, Value * blockNo) const {
     331    return getInputStreamSetBuffer(name)->getStreamSetPtr(getStreamSetBufferPtr(name), blockNo);
    345332}
    346333
  • icGREP/icgrep-devel/icgrep/kernels/kernel.h

    r5307 r5310  
    183183    llvm::Value * getOutputStream(const std::string & name, llvm::Value * streamIndex, llvm::Value * packIndex) const;
    184184
    185     llvm::Value * getRawItemPointer(const std::string & name, llvm::Value * streamIndex, llvm::Value * absolutePosition) const;
     185    llvm::Value * getRawInputPointer(const std::string & name, llvm::Value * streamIndex, llvm::Value * absolutePosition) const;
     186
     187    llvm::Value * getRawOutputPointer(const std::string & name, llvm::Value * streamIndex, llvm::Value * absolutePosition) const;
    186188
    187189    llvm::Value * getScalarFieldPtr(const std::string & name) const {
     
    193195    }
    194196
    195     llvm::Value * getStreamSetPtr(const std::string & name, llvm::Value * blockNo) const;
     197    llvm::Value * getInputStreamSetPtr(const std::string & name, llvm::Value * blockNo) const;
    196198
    197199    inline llvm::Value * getProcessedItemCount(const std::string & name) const {
     
    241243    unsigned getStreamSetIndex(const std::string & name) const;
    242244
    243     const parabix::StreamSetBuffer * getStreamSetBuffer(const std::string & name) const;
     245    const parabix::StreamSetBuffer * getInputStreamSetBuffer(const std::string & name) const {
     246        return mStreamSetInputBuffers[getStreamSetIndex(name)];
     247    }
     248
     249    const parabix::StreamSetBuffer * getOutputStreamSetBuffer(const std::string & name) const {
     250        return mStreamSetOutputBuffers[getStreamSetIndex(name)];
     251    }
    244252
    245253    void callGenerateInitMethod();
  • icGREP/icgrep-devel/icgrep/kernels/p2s_kernel.cpp

    r5307 r5310  
    182182    Value * i16UnitsFinal = iBuilder->CreateAdd(i16UnitsGenerated, iBuilder->CreateZExt(offset, iBuilder->getSizeTy()));
    183183    setProducedItemCount("i16Stream", i16UnitsFinal);
    184     const auto b  = getStreamSetBuffer("i16Stream");
     184    const auto b  = getOutputStreamSetBuffer("i16Stream");
    185185
    186186    if (auto cb = dyn_cast<CircularCopybackBuffer>(b)) {
  • icGREP/icgrep-devel/icgrep/kernels/stdout_kernel.cpp

    r5307 r5310  
    2626    Value * itemsToDo = iBuilder->CreateSub(producerPos[0], processed);
    2727    // There may be two memory areas if we are at the physical end of a circular buffer.
    28     const auto b  = getStreamSetBuffer("codeUnitBuffer");
     28    const auto b  = getInputStreamSetBuffer("codeUnitBuffer");
    2929    Value * wraparound = nullptr;
    3030    if (isa<CircularBuffer>(b) || isa<CircularCopybackBuffer>(b)) {
     
    9696    Value * itemsToDo = iBuilder->CreateSub(producerPos[0], processed);
    9797    // There may be two memory areas if we are at the physical end of a circular buffer.
    98     auto const &b  = getStreamSetBuffer("codeUnitBuffer");
     98    const auto b  = getInputStreamSetBuffer("codeUnitBuffer");
    9999    Value * wraparound = nullptr;
    100100    if (isa<CircularBuffer>(b) || isa<CircularCopybackBuffer>(b)) {
  • icGREP/icgrep-devel/icgrep/pablo/carry_manager.cpp

    r5307 r5310  
    6060
    6161    if (mHasLoop) {
    62         mKernel->addScalar(iBuilder->getInt32Ty(), "loopSelector");
     62        mKernel->addScalar(iBuilder->getInt32Ty(), "selector");
    6363    }
    6464}
     
    8282
    8383    if (mHasLoop) {
    84         mLoopSelector = mKernel->getScalarField("loopSelector");
     84        mLoopSelector = mKernel->getScalarField("selector");
    8585    }
    8686}
     
    9191void CarryManager::finalizeCodeGen() {
    9292    if (mHasLoop) {
    93         mKernel->setScalarField("loopSelector", iBuilder->CreateXor(mLoopSelector, iBuilder->getInt32(1)));
     93        mKernel->setScalarField("selector", iBuilder->CreateXor(mLoopSelector, iBuilder->getInt32(1)));
    9494    }
    9595}
  • icGREP/icgrep-devel/icgrep/pablo/pablo_compiler.cpp

    r5307 r5310  
    2626#include <pablo/carry_manager.h>
    2727#include <IR_Gen/idisa_builder.h>
     28#include <kernels/streamset.h>
    2829#include <llvm/IR/Module.h>
    2930#include <llvm/Support/raw_os_ostream.h>
     
    5859    for (unsigned i = 0; i < mKernel->getNumOfInputs(); ++i) {
    5960        Var * var = mKernel->getInput(i);
    60         std::string name = var->getName().str();
    61         Value * input = nullptr;
    62         if (var->getType()->isSingleValueType()) {
    63             input = mKernel->getScalarFieldPtr(name);
    64         } else {
    65             input = mKernel->getInputStream(name, iBuilder->getInt32(0));
    66         }
    67         mMarker.emplace(var, input);
     61        if (LLVM_UNLIKELY(var->isScalar())) {
     62            mMarker.emplace(var, mKernel->getScalarFieldPtr(var->getName()));
     63        }
    6864    }
    6965
    7066    for (unsigned i = 0; i < mKernel->getNumOfOutputs(); ++i) {
    7167        Var * var = mKernel->getOutput(i);
    72         std::string name = var->getName().str();
    73         Value * output = nullptr;
    74         if (var->getType()->isSingleValueType()) {
    75             output = mKernel->getScalarFieldPtr(name);
    76         } else {
    77             output = mKernel->getOutputStream(name, iBuilder->getInt32(0));
    78         }
    79         mMarker.emplace(var, output);
     68        if (LLVM_UNLIKELY(var->isScalar())) {
     69            mMarker.emplace(var, mKernel->getScalarFieldPtr(var->getName()));
     70        }
    8071    }
    8172
     
    145136            out << " is uninitialized prior to entering ";
    146137            ifStatement->print(out);
    147             llvm::report_fatal_error(out.str());
     138            report_fatal_error(out.str());
    148139        }
    149140        incoming.emplace_back(var, f->second);
     
    189180            var->print(out);
    190181            out << " was not assigned an outgoing value.";
    191             llvm::report_fatal_error(out.str());
     182            report_fatal_error(out.str());
    192183        }
    193184
     
    208199            out << ") within ";
    209200            ifStatement->print(out);
    210             llvm::report_fatal_error(out.str());
     201            report_fatal_error(out.str());
    211202        }
    212203
     
    262253            out << " is uninitialized prior to entering ";
    263254            whileStatement->print(out);
    264             llvm::report_fatal_error(out.str());
     255            report_fatal_error(out.str());
    265256        }
    266257        Value * entryValue = f->second;
     
    314305            var->print(out);
    315306            out << " is no longer assigned a value.";
    316             llvm::report_fatal_error(out.str());
     307            report_fatal_error(out.str());
    317308        }
    318309
     
    330321            out << ") within ";
    331322            whileStatement->print(out);
    332             llvm::report_fatal_error(out.str());
     323            report_fatal_error(out.str());
    333324        }
    334325
     
    345336}
    346337
    347 void PabloCompiler::compileStatement(const Statement * stmt) {
     338void PabloCompiler::compileStatement(const Statement * const stmt) {
    348339
    349340    if (LLVM_UNLIKELY(isa<If>(stmt))) {
     
    356347        if (LLVM_UNLIKELY(isa<Assign>(stmt))) {
    357348
     349            value = compileExpression(cast<Assign>(stmt)->getValue());
     350
    358351            expr = cast<Assign>(stmt)->getVariable();
    359             value = compileExpression(cast<Assign>(stmt)->getValue());
    360 
    361             bool storeInstRequired = false;
     352
     353            bool storeRequired = false;
     354
    362355            if (LLVM_LIKELY(isa<Var>(expr))) {
    363                 for (unsigned i = 0; i < mKernel->getNumOfOutputs(); ++i) {
    364                     if (expr == mKernel->getOutput(i)) {
    365                         storeInstRequired = true;
    366                         break;
    367                     }
     356                const Var * var = cast<Var>(expr);
     357                if (LLVM_UNLIKELY(var->isReadOnly())) {
     358                    std::string tmp;
     359                    raw_string_ostream out(tmp);
     360                    out << "cannot assign value to ";
     361                    var->print(out);
     362                    out << ": ";
     363                    var->print(out);
     364                    out << " is read only";
     365                    report_fatal_error(out.str());
    368366                }
    369             }
    370 
    371             if (LLVM_UNLIKELY(storeInstRequired || isa<Extract>(expr))) {
     367                storeRequired = var->isKernelParameter();
     368            }
     369
     370            if (storeRequired || isa<Extract>(expr)) {
    372371                const auto f = mMarker.find(expr);
    373372                if (LLVM_UNLIKELY(f == mMarker.end())) {
    374373                    std::string tmp;
    375374                    raw_string_ostream out(tmp);
    376                     out << "PabloCompiler: use-before-definition error: ";
     375                    out << "cannot assign value to ";
     376                    expr->print(out);
     377                    out << ": ";
    377378                    expr->print(out);
    378379                    out << " does not dominate ";
    379380                    stmt->print(out);
    380                     llvm::report_fatal_error(out.str());
     381                    report_fatal_error(out.str());
    381382                }
    382383                Value * const ptr = f->second;
     
    386387
    387388        } else if (const Extract * extract = dyn_cast<Extract>(stmt)) {
    388             Value * array = compileExpression(extract->getArray(), false);
    389389            Value * index = compileExpression(extract->getIndex());
    390             value = iBuilder->CreateGEP(array, index, stmt->getName());
     390            Var * const array = dyn_cast<Var>(extract->getArray());
     391            if (LLVM_LIKELY(array && array->isKernelParameter())) {
     392                if (array->isReadOnly()) {
     393                    value = mKernel->getInputStream(array->getName(), index);
     394                } else if (array->isReadNone()) {
     395                    value = mKernel->getOutputStream(array->getName(), index);
     396                } else {
     397                    std::string tmp;
     398                    raw_string_ostream out(tmp);
     399                    out << "stream ";
     400                    expr->print(out);
     401                    out << " cannot be read or written to";
     402                    report_fatal_error(out.str());
     403                }
     404            } else {
     405                Value * ptr = compileExpression(extract->getArray(), false);
     406                value = iBuilder->CreateGEP(ptr, {ConstantInt::getNullValue(index->getType()), index}, "extract");
     407            }
    391408        } else if (isa<And>(stmt)) {
    392409            value = compileExpression(stmt->getOperand(0));
     
    438455            const auto f = mAccumulator.find(c);
    439456            if (LLVM_UNLIKELY(f == mAccumulator.end())) {
    440                 llvm::report_fatal_error("Unknown accumulator: " + c->getName().str());
     457                report_fatal_error("Unknown accumulator: " + c->getName().str());
    441458            }
    442459            Value * ptr = mKernel->getScalarFieldPtr(f->second);
     
    474491            std::string inputName = cast<Var>(var)->getName().str();
    475492            Value * blockNo = mKernel->getBlockNo();
    476             Value * lookAhead_blockPtr  = mKernel->getStreamSetPtr(inputName, iBuilder->CreateAdd(blockNo, iBuilder->getSize(block_shift)));
     493            Value * lookAhead_blockPtr  = mKernel->getInputStreamSetPtr(inputName, iBuilder->CreateAdd(blockNo, iBuilder->getSize(block_shift)));
    477494            Value * lookAhead_inputPtr = iBuilder->CreateGEP(lookAhead_blockPtr, {iBuilder->getInt32(0), iBuilder->getInt32(index)});
    478495            Value * lookAhead = iBuilder->CreateBlockAlignedLoad(lookAhead_inputPtr);
     
    480497                value = lookAhead;
    481498            } else { // Need to form shift result from two adjacent blocks.
    482                 Value * lookAhead_blockPtr1  = mKernel->getStreamSetPtr(inputName, iBuilder->CreateAdd(blockNo, iBuilder->getSize(block_shift + 1)));
     499                Value * lookAhead_blockPtr1  = mKernel->getInputStreamSetPtr(inputName, iBuilder->CreateAdd(blockNo, iBuilder->getSize(block_shift + 1)));
    483500                Value * lookAhead_inputPtr1 = iBuilder->CreateGEP(lookAhead_blockPtr1, {iBuilder->getInt32(0), iBuilder->getInt32(index)});
    484501                Value * lookAhead1 = iBuilder->CreateBlockAlignedLoad(lookAhead_inputPtr1);
     
    496513        } else {
    497514            std::string tmp;
    498             llvm::raw_string_ostream out(tmp);
     515            raw_string_ostream out(tmp);
    499516            out << "Internal error: ";
    500517            stmt->print(out);
     
    521538        return iBuilder->allZeroes();
    522539    } else if (LLVM_UNLIKELY(isa<Integer>(expr))) {
    523         return iBuilder->getInt64(cast<Integer>(expr)->value());
     540        return ConstantInt::get(cast<Integer>(expr)->getType(), cast<Integer>(expr)->value());
    524541    } else if (LLVM_UNLIKELY(isa<Operator>(expr))) {
    525542        const Operator * op = cast<Operator>(expr);
     
    536553            rh->getType()->print(out);
    537554            out << ")";
    538             llvm::report_fatal_error(out.str());
     555            report_fatal_error(out.str());
    539556        }
    540557        switch (op->getClassTypeId()) {
     
    561578        expr->print(out);
    562579        out << " is not a valid Operator";
    563         llvm::report_fatal_error(out.str());
     580        report_fatal_error(out.str());
    564581    }
    565582    const auto f = mMarker.find(expr);
    566583    if (LLVM_UNLIKELY(f == mMarker.end())) {
    567584        std::string tmp;
    568         llvm::raw_string_ostream out(tmp);
     585        raw_string_ostream out(tmp);
    569586        out << "Compilation error: ";
    570587        expr->print(out);
    571588        out << " was used before definition!";
    572         llvm::report_fatal_error(out.str());
     589        report_fatal_error(out.str());
    573590    }
    574591    Value * value = f->second;
  • icGREP/icgrep-devel/icgrep/pablo/pablo_compiler.h

    r5297 r5310  
    99
    1010#include <unordered_map>
    11 #include <boost/container/flat_set.hpp>
    1211namespace IDISA { class IDISA_Builder; }
    1312namespace llvm { class Function; }
     
    2423
    2524class PabloCompiler {
    26     friend class CarryManager;
    27 
    28     using IntSet = boost::container::flat_set<unsigned>;
     25//    friend class CarryManager;
    2926
    3027    using TranslationMap = std::unordered_map<const PabloAST *, llvm::Value *>;
     
    5956    TranslationMap                  mMarker;
    6057    TranslationMap                  mAccumulator;
    61     IntSet                          mInputStreamOffset;
    6258
    6359};
  • icGREP/icgrep-devel/icgrep/pablo/pablo_kernel.cpp

    r5307 r5310  
    1010#include <pablo/pe_zeroes.h>
    1111#include <pablo/pe_ones.h>
    12 //#include <llvm/IR/Module.h>
    13 //#include <llvm/IR/Verifier.h>
    14 //#include <IR_Gen/idisa_builder.h>
    1512#include "llvm/Support/Debug.h"
    1613
     
    3128}
    3229
    33 Var * PabloKernel::getInputSet(std::string inputSetName) {
    34     unsigned ssIndex = getStreamSetIndex(inputSetName);
    35     return mInputs[ssIndex];
     30Var * PabloKernel::getInputStreamVar(const std::string & inputSetName) {
     31    return mInputs[getStreamSetIndex(inputSetName)];
    3632}
    3733
    38 Var * PabloKernel::getOutputSet(std::string outputSetName) {
    39     unsigned ssIndex = getStreamSetIndex(outputSetName);
    40     return mOutputs[ssIndex - mInputs.size()];
     34Var * PabloKernel::getOutputStreamVar(const std::string & outputSetName) {
     35    return mOutputs[getStreamSetIndex(outputSetName)];
    4136}
    4237
    43 
    44 Var * PabloKernel::getScalarOutput(std::string outputName) {
     38Var * PabloKernel::getOutputScalarVar(const std::string & outputName) {
    4539    const auto f = mScalarOutputNameMap.find(outputName);
    4640    if (LLVM_UNLIKELY(f == mScalarOutputNameMap.end())) {
    47         llvm::report_fatal_error("Kernel does not contain scalar: " + outputName);
     41        report_fatal_error("Kernel does not contain scalar: " + outputName);
    4842    }
    4943    return f->second;
     
    5145
    5246Var * PabloKernel::addInput(const std::string & name, Type * const type) {
    53     Var * param = new (mAllocator) Var(mSymbolTable->makeString(name, iBuilder), type, mAllocator, Var::ReadOnly);
     47    Var * param = new (mAllocator) Var(mSymbolTable->makeString(name, iBuilder), type, mAllocator, Var::KernelInputParameter);
    5448    param->addUser(this);
    5549    mInputs.push_back(param);
    5650    mVariables.push_back(param);
    5751    if (isStreamType(type)) {
    58         mStreamSetInputs.emplace_back(type, name);
     52        mStreamSetNameMap.emplace(name, mStreamSetInputs.size());
     53        mStreamSetInputs.emplace_back(type, name);       
    5954    } else {
    6055        mScalarInputs.emplace_back(type, name);
     56        param->setScalar();
    6157    }
    6258    assert (mStreamSetInputs.size() + mScalarInputs.size() == mInputs.size());
     
    6561
    6662Var * PabloKernel::addOutput(const std::string & name, Type * const type) {
    67     Var * result = new (mAllocator) Var(mSymbolTable->makeString(name, iBuilder), type, mAllocator, Var::ReadNone);
     63    Var * result = new (mAllocator) Var(mSymbolTable->makeString(name, iBuilder), type, mAllocator, Var::KernelOutputParameter);
    6864    result->addUser(this);
    6965    mOutputs.push_back(result);
    7066    mVariables.push_back(result);
    7167    if (isStreamType(type)) {
     68        mStreamSetNameMap.emplace(name, mStreamSetOutputs.size());
    7269        mStreamSetOutputs.emplace_back(type, name);
    7370    } else {
    7471        mScalarOutputs.emplace_back(type, name);
    7572        mScalarOutputNameMap.emplace(name, result);
     73        result->setScalar();
    7674    }
    7775    assert (mStreamSetOutputs.size() + mScalarOutputs.size() == mOutputs.size());
     
    130128}
    131129
    132 PabloKernel::PabloKernel(IDISA::IDISA_Builder * builder, std::string kernelName)
    133 : BlockOrientedKernel(builder, std::move(kernelName), {}, {}, {}, {}, {Binding{builder->getBitBlockType(), "EOFbit"}, Binding{builder->getBitBlockType(), "EOFmask"}})
    134 , PabloAST(PabloAST::ClassTypeId::Kernel, nullptr, mAllocator)
    135 , mPabloCompiler(new PabloCompiler(this))
    136 , mSymbolTable(new SymbolGenerator(mAllocator))
    137 , mEntryBlock(PabloBlock::Create(this)) {
    138     setDoBlockUpdatesProducedItemCountsAttribute(false);
    139 }
    140 
    141 PabloKernel::PabloKernel(IDISA::IDISA_Builder * builder, std::string kernelName,
    142                          std::vector<Binding> && stream_inputs,
    143                          std::vector<Binding> && stream_outputs,
    144                          std::vector<Binding> && scalar_outputs)
     130PabloKernel::PabloKernel(IDISA::IDISA_Builder * builder, std::string kernelName,
     131                         std::vector<Binding> stream_inputs,
     132                         std::vector<Binding> stream_outputs,
     133                         std::vector<Binding> scalar_parameters,
     134                         std::vector<Binding> scalar_outputs)
    145135: BlockOrientedKernel(builder, std::move(kernelName),
    146136                      std::move(stream_inputs), std::move(stream_outputs),
    147                       {}, std::move(scalar_outputs),
     137                      std::move(scalar_parameters), std::move(scalar_outputs),
    148138                      {Binding{builder->getBitBlockType(), "EOFbit"}, Binding{builder->getBitBlockType(), "EOFmask"}})
    149139, PabloAST(PabloAST::ClassTypeId::Kernel, nullptr, mAllocator)
     
    153143    setDoBlockUpdatesProducedItemCountsAttribute(false);
    154144    prepareKernelSignature();
    155     for (auto ss : mStreamSetInputs) {
    156         Var * param = new (mAllocator) Var(mSymbolTable->makeString(ss.name, iBuilder), ss.type, mAllocator, Var::ReadOnly);
     145    for (const Binding & ss : mStreamSetInputs) {
     146        Var * param = new (mAllocator) Var(mSymbolTable->makeString(ss.name, iBuilder), ss.type, mAllocator, Var::KernelInputParameter);
    157147        param->addUser(this);
    158148        mInputs.push_back(param);
    159149        mVariables.push_back(param);
    160150    }
    161     for (auto ss : mStreamSetOutputs) {
    162         Var * result = new (mAllocator) Var(mSymbolTable->makeString(ss.name, iBuilder), ss.type, mAllocator, Var::ReadNone);
     151    for (const Binding & ss : mStreamSetOutputs) {
     152        Var * result = new (mAllocator) Var(mSymbolTable->makeString(ss.name, iBuilder), ss.type, mAllocator, Var::KernelOutputParameter);
    163153        result->addUser(this);
    164154        mOutputs.push_back(result);
    165155        mVariables.push_back(result);
    166156    }
    167     for (auto ss : mScalarOutputs) {
    168         Var * result = new (mAllocator) Var(mSymbolTable->makeString(ss.name, iBuilder), ss.type, mAllocator, Var::ReadNone);
     157    for (const Binding & ss : mScalarOutputs) {
     158        Var * result = new (mAllocator) Var(mSymbolTable->makeString(ss.name, iBuilder), ss.type, mAllocator, Var::KernelOutputParameter);
    169159        result->addUser(this);
    170160        mOutputs.push_back(result);
  • icGREP/icgrep-devel/icgrep/pablo/pablo_kernel.h

    r5300 r5310  
    4646    }
    4747
    48     PabloKernel(IDISA::IDISA_Builder * builder, std::string kernelName);
    49    
    5048    PabloKernel(IDISA::IDISA_Builder * builder, std::string kernelName,                     
    51                     std::vector<Binding> && stream_inputs,
    52                     std::vector<Binding> && stream_outputs,
    53                     std::vector<Binding> && scalar_outputs);
     49                std::vector<Binding> stream_inputs = {},
     50                std::vector<Binding> stream_outputs = {},
     51                std::vector<Binding> scalar_parameters = {},
     52                std::vector<Binding> scalar_outputs = {});
    5453
    5554    virtual ~PabloKernel();
     
    6968    }
    7069   
    71     Var * getInputSet(std::string inputSetName);
     70    Var * getInputStreamVar(const std::string & inputSetName);
    7271
    7372    Var * getInput(const unsigned index) {
     
    8584    }
    8685   
    87     Var * getOutputSet(std::string inputSetName);
     86    Var * getOutputStreamVar(const std::string & inputSetName);
    8887   
    89     Var * getScalarOutput(std::string outputName);
     88    Var * getOutputScalarVar(const std::string & outputName);
    9089
    9190    Var * getOutput(const unsigned index) {
     
    119118    inline SymbolGenerator * getSymbolTable() const {
    120119        return mSymbolTable;
     120    }
     121
     122    void * operator new (std::size_t size) noexcept {
     123        return std::malloc(size);
    121124    }
    122125
  • icGREP/icgrep-devel/icgrep/pablo/pe_var.h

    r5283 r5310  
    2121
    2222    enum Attribute {
    23         None = 0
    24         , ReadOnly = 1
    25         , ReadNone = 2
     23        None = 0x00
     24        , ReadOnly = 0x01
     25        , ReadNone = 0x02
     26        , Scalar = 0x04
     27        , KernelParameter = 0x80
     28        // Composite attributes
     29        , KernelInputParameter = ReadOnly | KernelParameter
     30        , KernelOutputParameter = ReadNone | KernelParameter
    2631    };
    2732
     
    3338    }
    3439    bool isReadOnly() const {
    35         return mAttribute & Attribute::ReadOnly;
     40        return (mAttribute & Attribute::ReadOnly) != 0;
    3641    }
    3742    void setReadOnly(const bool value = true) {
     
    4348    }
    4449    bool isReadNone() const {
    45         return mAttribute & Attribute::ReadNone;
     50        return (mAttribute & Attribute::ReadNone) != 0;
    4651    }
    4752    void setReadNone(const bool value = true) {
     
    5257        }
    5358    }
    54 
     59    bool isKernelParameter() const {
     60        return (mAttribute & Attribute::KernelParameter) != 0;
     61    }
     62    void setKernelParameter(const bool value = true) {
     63        if (value) {
     64            mAttribute |= Attribute::KernelParameter;
     65        } else {
     66            mAttribute &= ~(Attribute::KernelParameter);
     67        }
     68    }
     69    bool isScalar() const {
     70        return (mAttribute & Attribute::Scalar) != 0;
     71    }
     72    void setScalar(const bool value = true) {
     73        if (value) {
     74            mAttribute |= Attribute::Scalar;
     75        } else {
     76            mAttribute &= ~(Attribute::Scalar);
     77        }
     78    }
    5579    const String & getName() const noexcept {
    5680        return *mName;
  • icGREP/icgrep-devel/icgrep/re/re_compiler.cpp

    r5308 r5310  
    4343void RE_Compiler::initializeRequiredStreams(const unsigned encodingBits) {
    4444    if (encodingBits == 8) {
    45       RE_Compiler::initializeRequiredStreams_utf8();
    46     }
    47     else if (encodingBits == 16) {
    48       RE_Compiler::initializeRequiredStreams_utf16();
     45        RE_Compiler::initializeRequiredStreams_utf8();
     46    } else if (encodingBits == 16) {
     47        RE_Compiler::initializeRequiredStreams_utf16();
    4948    }
    5049}
  • icGREP/icgrep-devel/icgrep/re/re_toolchain.cpp

    r5308 r5310  
    8585}
    8686   
    87 void re2pablo_compiler(PabloKernel * kernel, const unsigned encodingBits, RE * re_ast, const bool CountOnly) {
    88     cc::CC_Compiler cc_compiler(kernel, encodingBits);
     87void re2pablo_compiler(PabloKernel * kernel, RE * re_ast, const bool CountOnly) {
     88    Var * const basis = kernel->getInputStreamVar("basis");
     89    cc::CC_Compiler cc_compiler(kernel, basis);
    8990    re::RE_Compiler re_compiler(kernel, cc_compiler, CountOnly);
    90     re_compiler.initializeRequiredStreams(encodingBits);
     91    re_compiler.initializeRequiredStreams(basis->getType()->getArrayNumElements());
    9192    re_compiler.compileUnicodeNames(re_ast);
    9293    re_compiler.finalizeMatchResult(re_compiler.compile(re_ast), AlgorithmOptions.isSet(InvertMatches));
  • icGREP/icgrep-devel/icgrep/re/re_toolchain.h

    r5295 r5310  
    3131RE * regular_expression_passes(RE * re_ast);
    3232
    33 void re2pablo_compiler(pablo::PabloKernel * kernel, const unsigned encodingBits, RE * re_ast, const bool CountOnly = false);
     33void re2pablo_compiler(pablo::PabloKernel * kernel, RE * re_ast, const bool CountOnly = false);
    3434   
    3535}
  • icGREP/icgrep-devel/icgrep/u8u16.cpp

    r5306 r5310  
    5353    //  input: 8 basis bit streams
    5454   
    55     const auto u8bitSet = kernel->getInputSet("u8bit");
     55    const auto u8bitSet = kernel->getInputStreamVar("u8bit");
    5656   
    5757    //  output: 16 u8-indexed streams, + delmask stream + error stream
     
    237237    main.createAssign(u16_lo[7], main.createOr(main.createAnd(last_byte, u8_bits[7]), s43_lo7));
    238238   
    239     Var * output = kernel->getOutputSet("u16bit");
    240     Var * delmask_out = kernel->getOutputSet("delMask");
    241     Var * error_mask_out = kernel->getOutputSet("errMask");
     239    Var * output = kernel->getOutputStreamVar("u16bit");
     240    Var * delmask_out = kernel->getOutputStreamVar("delMask");
     241    Var * error_mask_out = kernel->getOutputStreamVar("errMask");
    242242   
    243243    for (unsigned i = 0; i < 8; i++) {
  • icGREP/icgrep-devel/icgrep/wc.cpp

    r5307 r5310  
    9090void wc_gen(PabloKernel * kernel) {
    9191    //  input: 8 basis bit streams
    92     const auto u8bitSet = kernel->getInputSet("u8bit");
     92    const auto u8bitSet = kernel->getInputStreamVar("u8bit");
    9393    //  output: 3 counters
    9494   
     
    9797    PabloBuilder & pb = ccc.getBuilder();
    9898
    99     Var * lc = kernel->getScalarOutput("lineCount");
    100     Var * wc = kernel->getScalarOutput("wordCount");
    101     Var * cc = kernel->getScalarOutput("charCount");
     99    Var * lc = kernel->getOutputScalarVar("lineCount");
     100    Var * wc = kernel->getOutputScalarVar("wordCount");
     101    Var * cc = kernel->getOutputScalarVar("charCount");
    102102
    103103    if (CountLines) {
Note: See TracChangeset for help on using the changeset viewer.