Changeset 5836 for icGREP/icgrep-devel


Ignore:
Timestamp:
Jan 16, 2018, 4:22:13 PM (14 months ago)
Author:
nmedfort
Message:

Added PabloBlock/Builder? createScope() methods + minor code changes.

Location:
icGREP/icgrep-devel/icgrep
Files:
8 deleted
40 edited

Legend:

Unmodified
Added
Removed
  • icGREP/icgrep-devel/icgrep/UCD/ucd_compiler.cpp

    r5805 r5836  
    201201        }
    202202        if (mTargetValue.size() > 0) {
    203             PabloBuilder inner_block = PabloBuilder::Create(builder);
     203            auto inner_block = builder.createScope();
    204204            builder.createIf(ifTestCompiler(range.first, range.second, builder), inner_block);
    205205            generateRange(inner, range.first, range.second, inner_block);
  • icGREP/icgrep-devel/icgrep/cc/cc_compiler.cpp

    r5828 r5836  
    2323
    2424CC_Compiler::CC_Compiler(pablo::PabloKernel * kernel, pablo::Var * basisBits)
    25 : mBuilder(kernel->getEntryBlock())
     25: mBuilder(kernel->getEntryScope())
    2626, mEncodingBits(basisBits->getType()->getArrayNumElements())
    2727, mBasisBit(mEncodingBits) {
  • icGREP/icgrep-devel/icgrep/cc/multiplex_CCs.cpp

    r5816 r5836  
    123123        cc::doMultiplexCCs(CCs, mExclusiveSetIDs, mMultiplexedCCs);
    124124}
    125 
    126 const Alphabet * MultiplexedAlphabet::getSourceAlphabet() const {
    127     return mSourceAlphabet;
    128 }
    129 
    130 std::vector<std::vector<unsigned>> MultiplexedAlphabet::getExclusiveSetIDs() {
    131     return mExclusiveSetIDs;
    132 }
    133 
    134 std::vector<re::CC *> MultiplexedAlphabet::getMultiplexedCCs() {
    135     return mMultiplexedCCs;
    136 }
    137125   
    138126re::CC * MultiplexedAlphabet::transformCC(const re::CC * sourceCC) const {
    139     if (sourceCC->getAlphabet() != mSourceAlphabet) llvm::report_fatal_error("Mismatched source alphabets for transformCC");
    140    
    141     const auto index = find(mUnicodeSets.begin(), mUnicodeSets.end(), sourceCC) - mUnicodeSets.begin();
    142     if (index >= mUnicodeSets.size()) {
    143         llvm::errs() << Printer_RE::PrintRE(sourceCC) << " not found\n";
     127    if (sourceCC->getAlphabet() != mSourceAlphabet) {
     128        llvm::report_fatal_error("Mismatched source alphabets for transformCC");
    144129    }
     130    const auto f = find(mUnicodeSets.begin(), mUnicodeSets.end(), sourceCC);
     131    if (f == mUnicodeSets.end()) {
     132        llvm::report_fatal_error(Printer_RE::PrintRE(sourceCC) + " not found");
     133    }
     134    const auto index = f - mUnicodeSets.begin();
    145135    const auto exclusive_IDs = mExclusiveSetIDs[index];
    146136    re::CC * CC_union = re::makeCC(this);
  • icGREP/icgrep-devel/icgrep/cc/multiplex_CCs.h

    r5816 r5836  
    2323    const unsigned getSize() const override {return mUnicodeSets.size() + 1;}
    2424
    25     const Alphabet * getSourceAlphabet() const;
     25    const Alphabet * getSourceAlphabet() const {
     26        return mSourceAlphabet;
     27    }
    2628   
    27     std::vector<std::vector<unsigned>> getExclusiveSetIDs();
     29    const std::vector<std::vector<unsigned>> & getExclusiveSetIDs() const {
     30        return mExclusiveSetIDs;
     31    }
    2832   
    29     std::vector<re::CC *> getMultiplexedCCs();
     33    const std::vector<re::CC *> & getMultiplexedCCs() const {
     34        return mMultiplexedCCs;
     35    }
    3036   
    3137    re::CC * transformCC(const re::CC * sourceCC) const;
  • icGREP/icgrep-devel/icgrep/editd/editd.cpp

    r5793 r5836  
    210210
    211211void PatternKernel::generatePabloMethod() {
    212     PabloBuilder entry(getEntryBlock());
     212    PabloBuilder entry(getEntryScope());
    213213    Var * const pat = getInputStreamVar("pat");
    214214    PabloAST * basisBits[4];
  • icGREP/icgrep-devel/icgrep/editd/pattern_compiler.cpp

    r5310 r5836  
    2626
    2727void optimizer(const std::string & patt, PabloAST * basisBits[], std::vector<std::vector<PabloAST *>> & e, unsigned i, PabloAST * cond, PabloBuilder & main, PabloBuilder & pb, int dist, int stepSize){
    28     PabloBuilder it = PabloBuilder::Create(pb);
     28    auto it = pb.createScope();
    2929
    3030    Zeroes * zeroes = pb.createZeroes();
  • icGREP/icgrep-devel/icgrep/kernels/delmask_kernel.cpp

    r5625 r5836  
    3737   
    3838    PabloAST * ASCII = ccc.compileCC("ASCII", re::makeCC(0x0, 0x7F), main);
    39     PabloBuilder ascii = PabloBuilder::Create(main);
     39    auto ascii = main.createScope();
    4040    main.createIf(ASCII, ascii);
    4141    PabloAST * u8pfx = ccc.compileCC("u8pfx", re::makeCC(0xC0, 0xFF), main);
    4242    PabloAST * nonASCII = ccc.compileCC("u8pfx", re::makeCC(0x80, 0xFF), main);
    43     PabloBuilder it = PabloBuilder::Create(main);
     43    auto it = main.createScope();
    4444    main.createIf(nonASCII, it);
    4545    Var * u8invalid = it.createVar("u8invalid", zeroes);
     
    5151    // Two-byte sequences
    5252    Var * u8scope22 = it.createVar("u8scope22", zeroes);
    53     PabloBuilder it2 = PabloBuilder::Create(it);
     53    auto it2 = it.createScope();
    5454    it.createIf(u8pfx2, it2);
    5555    it2.createAssign(u8scope22, it2.createAdvance(u8pfx2, 1));
     
    5959    Var * EX_invalid = it.createVar("EX_invalid", zeroes);
    6060    Var * del3 = it.createVar("del3", zeroes);
    61     PabloBuilder it3 = PabloBuilder::Create(it);
     61    auto it3 = it.createScope();
    6262    it.createIf(u8pfx3, it3);
    6363    PabloAST * u8scope32 = it3.createAdvance(u8pfx3, 1, "u8scope32");
     
    7474    Var * FX_invalid = it.createVar("FX_invalid", zeroes);
    7575    Var * del4 = it.createVar("del4", zeroes);
    76     PabloBuilder it4 = PabloBuilder::Create(it);
     76    auto it4 = it.createScope();
    7777    it.createIf(u8pfx4, it4);
    7878    PabloAST * u8scope42 = it4.createAdvance(u8pfx4, 1, "u8scope42");
  • icGREP/icgrep-devel/icgrep/kernels/grep_kernel.cpp

    r5819 r5836  
    88#include <re/printer_re.h>
    99#include <re/re_toolchain.h>
     10#include <re/re_reverse.h>
    1011#include <pablo/pablo_toolchain.h>
    1112#include <kernels/kernel_builder.h>
     
    5152    Var * const valid_pfx = pb.createVar("valid_pfx", u8pfx);
    5253
    53     PabloBuilder it = PabloBuilder::Create(pb);
    54 
     54    auto it = pb.createScope();
    5555    pb.createIf(u8pfx, it);
    5656    PabloAST * const u8pfx2 = ccc.compileCC(makeByte(0xC2, 0xDF), it);
     
    6262    // Two-byte sequences
    6363    Var * const anyscope = it.createVar("anyscope", ZEROES);
    64     PabloBuilder it2 = PabloBuilder::Create(it);
     64    auto it2 = it.createScope();
    6565    it.createIf(u8pfx2, it2);
    6666    it2.createAssign(anyscope, it2.createAdvance(u8pfx2, 1));
     
    6969    // Three-byte sequences   
    7070    Var * const EF_invalid = it.createVar("EF_invalid", ZEROES);
    71     PabloBuilder it3 = PabloBuilder::Create(it);
     71    auto it3 = it.createScope();
    7272    it.createIf(u8pfx3, it3);
    7373    PabloAST * const u8scope32 = it3.createAdvance(u8pfx3, 1);
     
    8484    //
    8585    // Four-byte sequences
    86     PabloBuilder it4 = PabloBuilder::Create(it);
     86    auto it4 = it.createScope();
    8787    it.createIf(u8pfx4, it4);
    8888    PabloAST * const u8scope42 = it4.createAdvance(u8pfx4, 1, "u8scope42");
     
    178178
    179179// Helper to compute stream set inputs to pass into PabloKernel constructor.
    180 std::vector<Binding> icGrepInputs(const std::unique_ptr<kernel::KernelBuilder> & iBuilder, std::vector<cc::Alphabet *> alphabets) {
    181     std::vector<Binding> streamSetInputs = {Binding{iBuilder->getStreamSetTy(8), "basis"},
    182         Binding{iBuilder->getStreamSetTy(1, 1), "linebreak"},
    183         Binding{iBuilder->getStreamSetTy(1, 1), "cr+lf"},
    184         Binding{iBuilder->getStreamSetTy(3, 1), "required"}};
    185     for (unsigned i = 0; i < alphabets.size(); i++) {
    186         unsigned basis_size = cast<cc::MultiplexedAlphabet>(alphabets[i])->getMultiplexedCCs().size();
    187         streamSetInputs.push_back(Binding{iBuilder->getStreamSetTy(basis_size, 1), alphabets[i]->getName() + "_basis"});
     180inline std::vector<Binding> icGrepInputs(const std::unique_ptr<kernel::KernelBuilder> & b,
     181                                         const std::vector<cc::Alphabet *> & alphabets) {
     182    std::vector<Binding> streamSetInputs = {
     183        Binding{b->getStreamSetTy(8), "basis"},
     184        Binding{b->getStreamSetTy(1, 1), "linebreak"},
     185        Binding{b->getStreamSetTy(1, 1), "cr+lf"},
     186        Binding{b->getStreamSetTy(3, 1), "required"}
     187    };
     188    for (const auto & alphabet : alphabets) {
     189        unsigned basis_size = cast<cc::MultiplexedAlphabet>(alphabet)->getMultiplexedCCs().size();
     190        streamSetInputs.push_back(Binding{b->getStreamSetTy(basis_size, 1), alphabet->getName() + "_basis"});
    188191    }
    189192    return streamSetInputs;
    190193}
    191194
    192 ICGrepKernel::ICGrepKernel(const std::unique_ptr<kernel::KernelBuilder> & iBuilder, RE * const re, std::vector<cc::Alphabet *> alphabets)
     195ICGrepKernel::ICGrepKernel(const std::unique_ptr<kernel::KernelBuilder> & b, RE * const re, std::vector<cc::Alphabet *> alphabets)
    193196: ICGrepSignature(re)
    194 , PabloKernel(iBuilder, "ic" + sha1sum(mSignature),
     197, PabloKernel(b, "ic" + sha1sum(mSignature),
    195198// inputs
    196 icGrepInputs(iBuilder, alphabets),
    197 // output
    198 {Binding{iBuilder->getStreamSetTy(1, 1), "matches", FixedRate(), Add1()}}) {
    199     mAlphabets = alphabets;
     199icGrepInputs(b, alphabets),
     200// output
     201{Binding{b->getStreamSetTy(1, 1), "matches", FixedRate(), Add1()}})
     202, mAlphabets(alphabets) {
     203
    200204}
    201205
     
    208212    cc::CC_Compiler cc_compiler(this, basis);
    209213    RE_Compiler re_compiler(this, cc_compiler);
    210     for (unsigned i = 0; i < mAlphabets.size(); i++) {
    211         auto basis = getInputStreamVar(mAlphabets[i]->getName() + "_basis");
    212         re_compiler.addAlphabet(mAlphabets[i], basis);
     214    for (auto a : mAlphabets) {
     215        auto basis = getInputStreamVar(a->getName() + "_basis");
     216        re_compiler.addAlphabet(a, basis);
    213217    }
    214     PabloAST * const match_post = re_compiler.compile(mRE);
    215     PabloBlock * const pb = getEntryBlock();
     218    PabloAST * const matches = re_compiler.compile(mRE);
     219    PabloBlock * const pb = getEntryScope();
    216220    Var * const output = getOutputStreamVar("matches");
    217     pb->createAssign(pb->createExtract(output, pb->getInteger(0)), match_post);
     221    pb->createAssign(pb->createExtract(output, pb->getInteger(0)), matches);
    218222}
    219223
    220224void MatchedLinesKernel::generatePabloMethod() {
    221     auto pb = this->getEntryBlock();
     225    auto pb = this->getEntryScope();
    222226    PabloAST * matchResults = pb->createExtract(getInputStreamVar("matchResults"), pb->getInteger(0));
    223227    PabloAST * lineBreaks = pb->createExtract(getInputStreamVar("lineBreaks"), pb->getInteger(0));
     
    259263
    260264void PopcountKernel::generatePabloMethod() {
    261     auto pb = this->getEntryBlock();
     265    auto pb = this->getEntryScope();
    262266    const auto toCount = pb->createExtract(getInputStreamVar("toCount"), pb->getInteger(0));
    263267    pablo::Var * countResult = getOutputScalarVar("countResult");
     
    267271PopcountKernel::PopcountKernel (const std::unique_ptr<kernel::KernelBuilder> & iBuilder)
    268272: PabloKernel(iBuilder, "Popcount",
    269               {Binding{iBuilder->getStreamSetTy(1), "toCount"}},
    270               {},
    271               {},
    272               {Binding{iBuilder->getSizeTy(), "countResult"}}) {
    273 }
     273{Binding{iBuilder->getStreamSetTy(1), "toCount"}},
     274{},
     275{},
     276{Binding{iBuilder->getSizeTy(), "countResult"}}) {
     277
     278}
  • icGREP/icgrep-devel/icgrep/kernels/interface.h

    r5793 r5836  
    99#include <kernels/processing_rate.h>
    1010#include <kernels/attributes.h>
     11#include <llvm/Support/Compiler.h>
    1112#include <memory>
    1213#include <string>
  • icGREP/icgrep-devel/icgrep/kernels/linebreak_kernel.cpp

    r5824 r5836  
    2222using namespace llvm;
    2323
    24 
    25 DirectLineFeedBuilder::DirectLineFeedBuilder(const std::unique_ptr<kernel::KernelBuilder> & b)
    26 : PabloKernel(b, "lf_byte",
     24LineFeedKernelBuilder::LineFeedKernelBuilder(const std::unique_ptr<kernel::KernelBuilder> & b, const unsigned codeUnitWidth)
     25: PabloKernel(b, "lf" + std::to_string(codeUnitWidth),
    2726// input
    28 {Binding{b->getStreamSetTy(1, 8), "codeUnitStream", FixedRate(), Principal()}},
    29 // output
    30 {Binding{b->getStreamSetTy(1), "lf"}}) {
    31 
    32 }
    33 
    34 void DirectLineFeedBuilder::generatePabloMethod() {
    35     PabloBuilder pb(getEntryBlock());
    36     PabloAST * LF = compileCCfromCodeUnitStream(makeByte(0x0A), getInput(0), pb);
    37     pb.createAssign(pb.createExtract(getOutput(0), pb.getInteger(0)), LF);
    38 }
    39 
    40 
    41 LineFeedKernelBuilder::LineFeedKernelBuilder(const std::unique_ptr<kernel::KernelBuilder> & b, const unsigned basisBitsCount)
    42 : PabloKernel(b, "lf" + std::to_string(basisBitsCount),
    43 // input
    44 {Binding{b->getStreamSetTy(basisBitsCount), "basis", FixedRate(), Principal()}},
     27#ifdef USE_DIRECT_LF_BUILDER
     28{Binding{b->getStreamSetTy(1, codeUnitWidth), "byteStream", FixedRate(), Principal()}},
     29#else
     30{Binding{b->getStreamSetTy(codeUnitWidth), "basis", FixedRate(), Principal()}},
     31#endif
    4532// output
    4633{Binding{b->getStreamSetTy(1), "lf"}}) {
     
    4936
    5037void LineFeedKernelBuilder::generatePabloMethod() {
     38    #ifdef USE_DIRECT_LF_BUILDER
     39    PabloBuilder pb(getEntryScope());
     40    PabloAST * LF = compileCCfromCodeUnitStream(makeByte(0x0A), getInput(0), pb);
     41    #else
    5142    CC_Compiler ccc(this, getInput(0));
    5243    auto & pb = ccc.getBuilder();
    5344    PabloAST * LF = ccc.compileCC("LF", makeByte(0x0A), pb);
    54     pb.createAssign(pb.createExtract(getOutput(0), pb.getInteger(0)), LF);
     45    #endif
     46    pb.createAssign(pb.createExtract(getOutput(0), 0), LF);
    5547}
    5648
     
    7971    // Remove the CR of any CR+LF
    8072    Var * const CRLF = pb.createVar("CRLF", pb.createZeroes());
    81     PabloBuilder crb = PabloBuilder::Create(pb);
     73    auto crb = pb.createScope();
    8274    pb.createIf(CR, crb);
    8375    PabloAST * const lookaheadLF = crb.createLookahead(LF, 1, "lookaheadLF");
     
    9183    // Check for Unicode Line Breaks
    9284    PabloAST * u8pfx = ccc.compileCC(makeByte(0xC0, 0xFF));
    93     PabloBuilder it = PabloBuilder::Create(pb);
     85    auto it = pb.createScope();
    9486    pb.createIf(u8pfx, it);
    9587    PabloAST * u8pfx2 = ccc.compileCC(makeByte(0xC2, 0xDF), it);
     
    9789
    9890    // Two-byte sequences
    99     PabloBuilder it2 = PabloBuilder::Create(it);
     91    auto it2 = it.createScope();
    10092    it.createIf(u8pfx2, it2);
    10193    PabloAST * NEL = it2.createAnd(it2.createAdvance(ccc.compileCC(makeByte(0xC2), it2), 1), ccc.compileCC(makeByte(0x85), it2), "NEL");
     
    10395
    10496    // Three-byte sequences
    105     PabloBuilder it3 = PabloBuilder::Create(it);
     97    auto it3 = it.createScope();
    10698    it.createIf(u8pfx3, it3);
    10799    PabloAST * E2_80 = it3.createAnd(it3.createAdvance(ccc.compileCC(makeByte(0xE2), it3), 1), ccc.compileCC(makeByte(0x80), it3));
  • icGREP/icgrep-devel/icgrep/kernels/linebreak_kernel.h

    r5824 r5836  
    88#include <pablo/pablo_kernel.h>  // for PabloKernel
    99
     10#define USE_DIRECT_LF_BUILDER
     11
    1012namespace kernel { class KernelBuilder; }
    1113
    1214namespace kernel {
    1315
    14 class DirectLineFeedBuilder final : public pablo::PabloKernel {
    15 public:
    16     DirectLineFeedBuilder(const std::unique_ptr<KernelBuilder> & b);
    17     bool isCachable() const override { return true; }
    18     bool hasSignature() const override { return false; }
    19 protected:
    20     void generatePabloMethod() override;
    21 };
    22 
    23 
    2416class LineFeedKernelBuilder final : public pablo::PabloKernel {
    2517public:
    26     LineFeedKernelBuilder(const std::unique_ptr<KernelBuilder> & b, unsigned basisBitsCount);
     18    LineFeedKernelBuilder(const std::unique_ptr<KernelBuilder> & b, unsigned codeUnitWidth = 8);
    2719    bool isCachable() const override { return true; }
    2820    bool hasSignature() const override { return false; }
  • icGREP/icgrep-devel/icgrep/kernels/pdep_kernel.cpp

    r5755 r5836  
    2525}
    2626
    27 Value * PDEPkernel::generateMultiBlockLogic(const std::unique_ptr<KernelBuilder> & kb, Value * const numOfStrides) {
     27void PDEPkernel::generateMultiBlockLogic(const std::unique_ptr<KernelBuilder> & kb, Value * const numOfStrides) {
    2828    BasicBlock * entry = kb->GetInsertBlock();
    2929    BasicBlock * checkLoopCond = kb->CreateBasicBlock("checkLoopCond");
     
    136136    kb->setProcessedItemCount("sourceStreamSet", updatedProcessedBitsPhi);
    137137
    138     return numOfStrides;
    139138}
    140139
  • icGREP/icgrep-devel/icgrep/kernels/pdep_kernel.h

    r5755 r5836  
    7474    const unsigned mSwizzleFactor;
    7575    const unsigned mPDEPWidth;
    76     llvm::Value * generateMultiBlockLogic(const std::unique_ptr<KernelBuilder> & kb, llvm::Value * const numOfStrides) override;
     76    void generateMultiBlockLogic(const std::unique_ptr<KernelBuilder> & kb, llvm::Value * const numOfStrides) override;
    7777    std::vector<llvm::Value *> get_PDEP_masks(const std::unique_ptr<KernelBuilder> & kb, llvm::Value * PDEP_ms_blk,
    7878                                              const unsigned mask_width);
  • icGREP/icgrep-devel/icgrep/kernels/streamset.cpp

    r5793 r5836  
    287287Value * SourceBuffer::getLinearlyAccessibleItems(IDISA::IDISA_Builder * const b, Value * const handle, Value * fromPosition, Value * availItems, bool reverse) const {
    288288    if (reverse) report_fatal_error("SourceBuffer cannot be accessed in reverse");
    289     Value * maxAvail = b->CreateSub(getBufferedSize(b, handle), fromPosition);
     289    Value * maxAvail = b->CreateNUWSub(getBufferedSize(b, handle), fromPosition);
    290290    return b->CreateSelect(b->CreateICmpULT(availItems, maxAvail), availItems, maxAvail);
    291291}
  • icGREP/icgrep-devel/icgrep/kernels/u8u32_kernel.cpp

    r5798 r5836  
    5454   
    5555    PabloAST * ASCII = ccc.compileCC("ASCII", re::makeByte(0x0, 0x7F), main);
    56     PabloBuilder ascii = PabloBuilder::Create(main);
     56    auto ascii = main.createScope();
    5757    for (int i = 1; i <= 7; i++) {
    5858        ascii.createAssign(u32_2[i], ascii.createOr(u32_2[i], ascii.createAnd(ASCII, u8_bits[i])));
     
    6262    PabloAST * u8pfx = ccc.compileCC("u8pfx", re::makeByte(0xC0, 0xFF), main);
    6363    PabloAST * nonASCII = ccc.compileCC("u8pfx", re::makeByte(0x80, 0xFF), main);
    64     PabloBuilder it = PabloBuilder::Create(main);
     64    auto it = main.createScope();
    6565    main.createIf(nonASCII, it);
    6666   
     
    7676    // Two-byte sequences
    7777    Var * u8scope22 = it.createVar("u8scope22", zeroes);
    78     PabloBuilder it2 = PabloBuilder::Create(it);
     78    auto it2 = it.createScope();
    7979    it.createIf(u8pfx2, it2);
    8080    it2.createAssign(u8scope22, it2.createAdvance(u8pfx2, 1));
     
    9595    Var * del3 = it.createVar("del3", zeroes);
    9696
    97     PabloBuilder it3 = PabloBuilder::Create(it);
     97    auto it3 = it.createScope();
    9898    it.createIf(u8pfx3, it3);
    9999   
     
    125125    Var * del4 = it.createVar("del4", zeroes);
    126126   
    127     PabloBuilder it4 = PabloBuilder::Create(it);
     127    auto it4 = it.createScope();
    128128    it.createIf(u8pfx4, it4);
    129129    PabloAST * u8scope42 = it4.createAdvance(u8pfx4, 1, "u8scope42");
  • icGREP/icgrep-devel/icgrep/pablo/analysis/pabloverifier.cpp

    r5828 r5836  
    153153void verifyUseDefInformation(const PabloKernel * kernel) {
    154154    ScopeSet validScopes;
    155     gatherValidScopes(kernel->getEntryBlock(), validScopes);
     155    gatherValidScopes(kernel->getEntryScope(), validScopes);
    156156    for (unsigned i = 0; i < kernel->getNumOfInputs(); ++i) {
    157157        testUsers(kernel->getInput(i), validScopes);
     
    160160        testUsers(kernel->getOutput(i), validScopes);
    161161    }
    162     verifyUseDefInformation(kernel->getEntryBlock(), validScopes);
     162    verifyUseDefInformation(kernel->getEntryScope(), validScopes);
    163163}
    164164
     
    286286inline void verifyProgramStructure(const PabloKernel * kernel) {
    287287    unsigned nestingDepth = 0;
    288     verifyProgramStructure(kernel->getEntryBlock(), nestingDepth);
     288    verifyProgramStructure(kernel->getEntryScope(), nestingDepth);
    289289    if (LLVM_UNLIKELY(nestingDepth != 0)) {
    290290        // This error isn't actually possible to occur with the current AST structure but that could change
     
    317317
    318318void verifyAllPathsDominate(const PabloKernel * kernel) {
    319     verifyAllPathsDominate(kernel->getEntryBlock());
     319    verifyAllPathsDominate(kernel->getEntryScope());
    320320}
    321321
     
    415415//        A.insert(kernel->getOutput(i));
    416416//    }
    417 //    verifyVariableUsages(kernel->getEntryBlock(), A);
     417//    verifyVariableUsages(kernel->getEntryScope(), A);
    418418//}
    419419
  • icGREP/icgrep-devel/icgrep/pablo/branch.h

    r5706 r5836  
    1414public:
    1515    using EscapedVars = std::vector<Var *>;
    16     static inline bool classof(const PabloAST * e) {
     16    static bool classof(const PabloAST * e) {
    1717        switch (e->getClassTypeId()) {
    1818            case ClassTypeId::If:
     
    2323        }
    2424    }
    25     static inline bool classof(const void *) {
     25    static bool classof(const void *) {
    2626        return false;
    2727    }
    28     inline PabloAST * getCondition() const {
     28    PabloAST * getCondition() const {
    2929        return getOperand(0);
    3030    }
    31     inline void setCondition(PabloAST * const condition) {
     31    void setCondition(PabloAST * const condition) {
    3232        return setOperand(0, condition);
    3333    }
    34     inline PabloBlock * getBody() {
     34    PabloBlock * getBody() const {
    3535        return mBody;
    3636    }
    37     inline  PabloBlock * getBody() const {
    38         return mBody;
    39     }
    40     inline bool isRegular() const {
     37    bool isRegular() const {
    4138        return mRegular;
    4239    }
    43     inline void setRegular(const bool value) {
     40    void setRegular(const bool value) {
    4441        mRegular = value;
    4542    }
  • icGREP/icgrep-devel/icgrep/pablo/builder.hpp

    r5828 r5836  
    2323    };
    2424
    25     explicit PabloBuilder(PabloBlock * block)
     25    using iterator = PabloBlock::iterator;
     26
     27    using const_iterator = PabloBlock::const_iterator;
     28
     29    PabloBuilder(not_null<PabloBlock *> block)
    2630    : mPb(block), mParent(nullptr), mExprTable(nullptr) {
    2731
    2832    }
    2933
    30     PabloBuilder & operator=(PabloBuilder) = delete;
    31 
    32     PabloBuilder & operator=(PabloBuilder &) = delete;
    33 
    34     PabloBuilder(PabloBuilder && builder)
    35     : mPb(builder.mPb)
    36     , mParent(builder.mParent)
    37     , mExprTable(std::move(builder.mExprTable)) {
    38 
    39     }
    40 
    41     PabloBuilder & operator=(PabloBuilder && builder) {
    42         mPb = builder.mPb;
    43         mParent = builder.mParent;
    44         mExprTable = std::move(builder.mExprTable);
    45         return *this;
    46     }
    47 
    48     using iterator = PabloBlock::iterator;
    49 
    50     using const_iterator = PabloBlock::const_iterator;
    51 
    52     static PabloBuilder Create(PabloBlock * block) noexcept {
    53         return PabloBuilder(block);
    54     }
    55 
    56     static PabloBuilder Create(PabloBuilder & builder) noexcept {
    57         return PabloBuilder(PabloBlock::Create(builder.getPabloBlock()->getParent()), builder);
     34    PabloBuilder createScope() noexcept {
     35        return PabloBuilder(&mPb->createScope(), this);
    5836    }
    5937
     
    308286protected:
    309287
    310     explicit PabloBuilder(PabloBlock * block, PabloBuilder & parent)
    311     : mPb(block), mParent(&parent), mExprTable(&(parent.mExprTable)) {
     288    PabloBuilder(not_null<PabloBlock *> block, not_null<PabloBuilder *> parent)
     289    : mPb(block), mParent(parent), mExprTable(&(parent->mExprTable)) {
    312290
    313291    }
     
    315293private:
    316294
    317     PabloBlock *        mPb;
    318     PabloBuilder *      mParent;
    319     ExpressionTable     mExprTable;
     295    PabloBlock * const          mPb;
     296    PabloBuilder * const        mParent;
     297    ExpressionTable             mExprTable;
    320298};
    321299
  • icGREP/icgrep-devel/icgrep/pablo/carry_manager.cpp

    r5828 r5836  
    9595
    9696    assert (mKernel == nullptr);
    97     mCurrentScope = kernel->getEntryBlock();
     97    mCurrentScope = kernel->getEntryScope();
    9898    mKernel = kernel;
    9999
     
    977977    assert ("scope cannot be null!" && scope);
    978978    assert ("entry scope (and only the entry scope) must be in scope 0"
    979             && (mCarryScopes == 0 ? (scope == mKernel->getEntryBlock()) : (scope != mKernel->getEntryBlock())));
     979            && (mCarryScopes == 0 ? (scope == mKernel->getEntryScope()) : (scope != mKernel->getEntryScope())));
    980980    assert (mCarryScopes < mCarryMetadata.size());
    981981    Type * const carryTy = b->getBitBlockType();
  • icGREP/icgrep-devel/icgrep/pablo/carrypack_manager.cpp

    r5771 r5836  
    115115    assert (mKernel == nullptr);
    116116
    117     mCurrentScope = kernel->getEntryBlock();
     117    mCurrentScope = kernel->getEntryScope();
    118118    mKernel = kernel;
    119119
     
    125125    mCarryScopes = 0;
    126126    mCarryMetadata.resize(getScopeCount(mCurrentScope));
    127     mCarryGroup.resize(assignDefaultCarryGroups(kernel->getEntryBlock()));
     127    mCarryGroup.resize(assignDefaultCarryGroups(kernel->getEntryScope()));
    128128
    129129    kernel->setCarryDataTy(analyse(iBuilder, mCurrentScope));
     
    11061106    assert ("scope cannot be null!" && scope);
    11071107    assert ("the entry scope -- and only the entry scope -- must be in carry scope 0"
    1108             && (mCarryScopes == 0 ? (scope == mKernel->getEntryBlock()) : (scope != mKernel->getEntryBlock())));
     1108            && (mCarryScopes == 0 ? (scope == mKernel->getEntryScope()) : (scope != mKernel->getEntryScope())));
    11091109    assert (mCarryScopes < mCarryMetadata.size());
    11101110
  • icGREP/icgrep-devel/icgrep/pablo/codegenstate.cpp

    r5834 r5836  
    4949///
    5050
    51 Count * PabloBlock::createCount(PabloAST * const expr) {
     51Count * PabloBlock::createCount(PabloAST * const expr, const String * const name) {
    5252    IntegerType * const type = getParent()->getSizeTy();
    53     return insertAtInsertionPoint(new (mAllocator) Count(expr, makeName("count"), type, mAllocator));
    54 }
    55 
    56 Count * PabloBlock::createCount(PabloAST * const expr, const llvm::StringRef & prefix)  {
    57     IntegerType * const type = getParent()->getSizeTy();
    58     return insertAtInsertionPoint(new (mAllocator) Count(expr, makeName(prefix), type, mAllocator));
    59 }
    60 
    61 Not * PabloBlock::createNot(PabloAST * expr, String * name) {
     53    return insertAtInsertionPoint(new (mAllocator) Count(expr, name, type, mAllocator));
     54}
     55
     56Not * PabloBlock::createNot(PabloAST * expr, const String * const name) {
    6257    assert (expr);
    6358    return insertAtInsertionPoint(new (mAllocator) Not(expr, name, mAllocator));
    6459}
    6560
    66 Var * PabloBlock::createVar(String * name, Type * type) {
     61Var * PabloBlock::createVar(const String * const name, Type * type) {
    6762    if (type == nullptr) {
    6863        type = getParent()->getStreamTy();
     
    7166        throw std::runtime_error("Var objects must have a String name");
    7267    }
    73     return mParent->makeVariable(cast<String>(name), type);
    74 }
    75 
    76 InFile * PabloBlock::createInFile(PabloAST * expr, String * name) {
     68    return mParent->makeVariable(name, type);
     69}
     70
     71InFile * PabloBlock::createInFile(PabloAST * expr, const String * const name) {
    7772    assert (expr);
    7873    return insertAtInsertionPoint(new (mAllocator) InFile(expr, name, mAllocator));
    7974}
    8075
    81 AtEOF * PabloBlock::createAtEOF(PabloAST * expr, String * name) {
     76AtEOF * PabloBlock::createAtEOF(PabloAST * expr, const String * const name) {
    8277    assert (expr);
    8378    return insertAtInsertionPoint(new (mAllocator) AtEOF(expr, name, mAllocator));
     
    8681/// BINARY CREATE FUNCTIONS
    8782
    88 Advance * PabloBlock::createAdvance(PabloAST * expr, Integer * shiftAmount, String * name) {
     83Advance * PabloBlock::createAdvance(PabloAST * expr, Integer * shiftAmount, const String * const name) {
    8984    return insertAtInsertionPoint(new (mAllocator) Advance(expr, shiftAmount, name, mAllocator));
    9085}
    9186
    92 Lookahead * PabloBlock::createLookahead(PabloAST * expr, Integer * shiftAmount, String * name) {
     87Lookahead * PabloBlock::createLookahead(PabloAST * expr, Integer * shiftAmount, const String * const name) {
    9388    return insertAtInsertionPoint(new (mAllocator) Lookahead(expr, shiftAmount, name, mAllocator));
    9489}
     
    112107}
    113108
    114 And * PabloBlock::createAnd(PabloAST * expr1, PabloAST * expr2, String * name) {
     109And * PabloBlock::createAnd(PabloAST * expr1, PabloAST * expr2, const String * const name) {
    115110    CHECK_SAME_TYPE(expr1, expr2);
    116111    return insertAtInsertionPoint(new (mAllocator) And(expr1->getType(), expr1, expr2, name, mAllocator));
    117112}
    118113
    119 Or * PabloBlock::createOr(PabloAST * expr1, PabloAST * expr2, String * name) {
     114Or * PabloBlock::createOr(PabloAST * expr1, PabloAST * expr2, const String * const name) {
    120115    CHECK_SAME_TYPE(expr1, expr2);
    121116    return insertAtInsertionPoint(new (mAllocator) Or(expr1->getType(), expr1, expr2, name, mAllocator));
    122117}
    123118
    124 Xor * PabloBlock::createXor(PabloAST * expr1, PabloAST * expr2, String * name) {
     119Xor * PabloBlock::createXor(PabloAST * expr1, PabloAST * expr2, const String * const name) {
    125120    CHECK_SAME_TYPE(expr1, expr2);
    126121    return insertAtInsertionPoint(new (mAllocator) Xor(expr1->getType(), expr1, expr2, name, mAllocator));
     
    186181}
    187182
    188 MatchStar * PabloBlock::createMatchStar(PabloAST * marker, PabloAST * charclass, String * name) {
     183MatchStar * PabloBlock::createMatchStar(PabloAST * marker, PabloAST * charclass, const String * const name) {
    189184    CHECK_SAME_TYPE(marker, charclass);
    190185    return insertAtInsertionPoint(new (mAllocator) MatchStar(marker, charclass, name, mAllocator));
    191186}
    192187
    193 ScanThru * PabloBlock::createScanThru(PabloAST * from, PabloAST * thru, String * name) {
     188ScanThru * PabloBlock::createScanThru(PabloAST * from, PabloAST * thru, const String * const name) {
    194189    CHECK_SAME_TYPE(from, thru);
    195190    return insertAtInsertionPoint(new (mAllocator) ScanThru(from, thru, name, mAllocator));
    196191}
    197192
    198 ScanTo * PabloBlock::createScanTo(PabloAST * from, PabloAST * to, String * name) {
     193ScanTo * PabloBlock::createScanTo(PabloAST * from, PabloAST * to, const String * const name) {
    199194    CHECK_SAME_TYPE(from, to);
    200195    return insertAtInsertionPoint(new (mAllocator) ScanTo(from, to, name, mAllocator));
    201196}
    202197
    203 AdvanceThenScanThru * PabloBlock::createAdvanceThenScanThru(PabloAST * from, PabloAST * thru, String * name) {
     198AdvanceThenScanThru * PabloBlock::createAdvanceThenScanThru(PabloAST * from, PabloAST * thru, const String * const name) {
    204199    CHECK_SAME_TYPE(from, thru);
    205200    return insertAtInsertionPoint(new (mAllocator) AdvanceThenScanThru(from, thru, name, mAllocator));
    206201}
    207202
    208 AdvanceThenScanTo * PabloBlock::createAdvanceThenScanTo(PabloAST * from, PabloAST * to, String * name) {
     203AdvanceThenScanTo * PabloBlock::createAdvanceThenScanTo(PabloAST * from, PabloAST * to, const String * const name) {
    209204    CHECK_SAME_TYPE(from, to);
    210205    return insertAtInsertionPoint(new (mAllocator) AdvanceThenScanTo(from, to, name, mAllocator));
     
    225220}
    226221
    227 Repeat * PabloBlock::createRepeat(Integer * fieldWidth, PabloAST * value, String * name) {
     222Repeat * PabloBlock::createRepeat(Integer * fieldWidth, PabloAST * value, const String * const name) {
    228223    assert (fieldWidth && value);
    229224    Type * const type = VectorType::get(IntegerType::get(value->getType()->getContext(), fieldWidth->value()), 0);
     
    231226}
    232227
    233 PackH * PabloBlock::createPackH(Integer * fieldWidth, PabloAST * value, String * name) {
     228PackH * PabloBlock::createPackH(Integer * fieldWidth, PabloAST * value, const String * const name) {
    234229    assert (fieldWidth && value);
    235230    Type * const type = VectorType::get(IntegerType::get(value->getType()->getContext(), fieldWidth->value()), 0);
     
    237232}
    238233
    239 PackL * PabloBlock::createPackL(Integer * fieldWidth, PabloAST * value, String * name) {
     234PackL * PabloBlock::createPackL(Integer * fieldWidth, PabloAST * value, const String * const name) {
    240235    assert (fieldWidth && value);
    241236    Type * const type = VectorType::get(IntegerType::get(value->getType()->getContext(), fieldWidth->value()), 0);
     
    245240/// TERNARY CREATE FUNCTIONS
    246241
    247 Sel * PabloBlock::createSel(PabloAST * condition, PabloAST * trueExpr, PabloAST * falseExpr, String * name) {
     242Sel * PabloBlock::createSel(PabloAST * condition, PabloAST * trueExpr, PabloAST * falseExpr, const String * const name) {
    248243    CHECK_SAME_TYPE(trueExpr, falseExpr);
    249244    return insertAtInsertionPoint(new (mAllocator) Sel(condition, trueExpr, falseExpr, name, mAllocator));
    250245}
    251246
    252 IndexedAdvance * PabloBlock::createIndexedAdvance(PabloAST * expr, PabloAST * indexStream, Integer * shiftAmount, String * name) {
     247IndexedAdvance * PabloBlock::createIndexedAdvance(PabloAST * expr, PabloAST * indexStream, Integer * shiftAmount, const String * const name) {
    253248    return insertAtInsertionPoint(new (mAllocator) IndexedAdvance(expr, indexStream, shiftAmount, name, mAllocator));
    254249}
     
    256251
    257252/** ------------------------------------------------------------------------------------------------------------- *
    258  * @brief Create
    259  ** ------------------------------------------------------------------------------------------------------------- */
    260 PabloBlock * PabloBlock::Create(PabloKernel * const parent) noexcept {
    261     Allocator & allocator = parent->mAllocator;
    262     return new (allocator) PabloBlock(parent, allocator);
     253 * @brief createScope
     254 ** ------------------------------------------------------------------------------------------------------------- */
     255PabloBlock & PabloBlock::createScope() noexcept {
     256    return *new (mAllocator) PabloBlock(mParent, mAllocator);
    263257}
    264258
  • icGREP/icgrep-devel/icgrep/pablo/codegenstate.h

    r5834 r5836  
    5656public:
    5757
    58     static inline bool classof(const PabloBlock *) {
     58    static bool classof(const PabloBlock *) {
    5959        return true;
    6060    }
    61     static inline bool classof(const Statement *) {
     61    static bool classof(const Statement *) {
    6262        return false;
    6363    }
    64     static inline bool classof(const PabloAST * e) {
     64    static bool classof(const PabloAST * e) {
    6565        return e->getClassTypeId() == ClassTypeId::Block;
    6666    }
    67     static inline bool classof(const void *) {
     67    static bool classof(const void *) {
    6868        return false;
    6969    }
    7070
    71     static PabloBlock * Create(PabloKernel * const parent) noexcept;
     71    PabloBlock & createScope() noexcept;
    7272
    7373    Advance * createAdvance(PabloAST * expr, Integer * shiftAmount) {
     
    7979    }
    8080   
    81     Advance * createAdvance(PabloAST * expr, Integer * shiftAmount, String * name);
     81    Advance * createAdvance(PabloAST * expr, Integer * shiftAmount, const String * const name);
    8282   
    8383    IndexedAdvance * createIndexedAdvance(PabloAST * expr, PabloAST * indexStream, Integer * shiftAmount) {
     
    8989    }
    9090   
    91     IndexedAdvance * createIndexedAdvance(PabloAST * expr, PabloAST * indexStream, Integer * shiftAmount, String * name);
     91    IndexedAdvance * createIndexedAdvance(PabloAST * expr, PabloAST * indexStream, Integer * shiftAmount, const String * const name);
    9292   
    9393    Lookahead * createLookahead(PabloAST * expr, Integer * shiftAmount) {
     
    9999    }
    100100
    101     Lookahead * createLookahead(PabloAST * expr, Integer * shiftAmount, String * name);
    102 
    103     inline Zeroes * createZeroes(llvm::Type * const type = nullptr) {
     101    Lookahead * createLookahead(PabloAST * expr, Integer * shiftAmount, const String * const name);
     102
     103    Zeroes * createZeroes(llvm::Type * const type = nullptr) {
    104104        return mParent->getNullValue(type);
    105105    }
    106106
    107     inline Ones * createOnes(llvm::Type * const type = nullptr) {
     107    Ones * createOnes(llvm::Type * const type = nullptr) {
    108108        return mParent->getAllOnesValue(type);
    109109    }
     
    117117    }
    118118
    119     Not * createNot(PabloAST * expr, String * name);
    120 
    121     inline Var * createVar(const llvm::StringRef & name, llvm::Type * const type = nullptr) {
     119    Not * createNot(PabloAST * expr, const String * const name);
     120
     121    Var * createVar(const llvm::StringRef & name, llvm::Type * const type = nullptr) {
    122122        return createVar(makeName(name), type);
    123123    }
    124124
    125     Var * createVar(String * name, llvm::Type * const type = nullptr);
    126 
    127     Count * createCount(PabloAST * expr);
    128 
    129     Count * createCount(PabloAST * expr, const llvm::StringRef & prefix);
    130 
    131     InFile * createInFile(PabloAST * expr) {
    132         return createInFile(expr, nullptr);
    133     }
     125    Var * createVar(const String * const name, llvm::Type * const type = nullptr);
     126
     127    Count * createCount(PabloAST * expr, const llvm::StringRef & prefix) {
     128        return createCount(expr, makeName(prefix));
     129    }
     130
     131    Count * createCount(PabloAST * expr, const String * const name = nullptr);
    134132
    135133    InFile * createInFile(PabloAST * expr, const llvm::StringRef & prefix) {
     
    137135    }
    138136
    139     InFile * createInFile(PabloAST * expr, String * name);
    140 
    141     AtEOF * createAtEOF(PabloAST * expr) {
    142         return createAtEOF(expr, nullptr);
    143     }
     137    InFile * createInFile(PabloAST * expr, const String * const name = nullptr);
    144138
    145139    AtEOF * createAtEOF(PabloAST * expr, const llvm::StringRef & prefix) {
     
    147141    }
    148142
    149     AtEOF * createAtEOF(PabloAST * expr, String * name);
     143    AtEOF * createAtEOF(PabloAST * expr, const String * const name = nullptr);
    150144
    151145    Extract * createExtract(Var * array, Integer * index);
    152146
    153147    Assign * createAssign(PabloAST * const var, PabloAST * const value);
    154 
    155     And * createAnd(PabloAST * expr1, PabloAST * expr2) {
    156         return createAnd(expr1, expr2, nullptr);
    157     }
    158148
    159149    And * createAnd(PabloAST * expr1, PabloAST * expr2, const llvm::StringRef & prefix) {
     
    161151    }
    162152
    163     And * createAnd(PabloAST * expr1, PabloAST * expr2, String * name);
    164 
    165     Or * createOr(PabloAST * expr1, PabloAST * expr2) {
    166         return createOr(expr1, expr2, nullptr);
    167     }
     153    And * createAnd(PabloAST * expr1, PabloAST * expr2, const String * const name = nullptr);
    168154
    169155    Or * createOr(PabloAST * expr1, PabloAST * expr2, const llvm::StringRef & prefix) {
     
    171157    }
    172158
    173     Or * createOr(PabloAST * expr1, PabloAST * expr2, String * name);
    174 
    175     Xor * createXor(PabloAST * expr1, PabloAST * expr2) {
    176         return createXor(expr1, expr2, nullptr);
    177     }
     159    Or * createOr(PabloAST * expr1, PabloAST * expr2, const String * const name = nullptr);
    178160
    179161    Xor * createXor(PabloAST * expr1, PabloAST * expr2, const llvm::StringRef & prefix) {
     
    181163    }
    182164
    183     Xor * createXor(PabloAST * expr1, PabloAST * expr2, String * name);
    184 
    185     Sel * createSel(PabloAST * condition, PabloAST * trueExpr, PabloAST * falseExpr) {
    186         return createSel(condition, trueExpr, falseExpr, nullptr);
    187     }
     165    Xor * createXor(PabloAST * expr1, PabloAST * expr2, const String * const name = nullptr);
    188166
    189167    Sel * createSel(PabloAST * condition, PabloAST * trueExpr, PabloAST * falseExpr, const llvm::StringRef & prefix) {
     
    191169    }
    192170
    193     Sel * createSel(PabloAST * condition, PabloAST * trueExpr, PabloAST * falseExpr, String * name);
     171    Sel * createSel(PabloAST * condition, PabloAST * trueExpr, PabloAST * falseExpr, const String * const name = nullptr);
    194172
    195173    Add * createAdd(PabloAST * expr1, PabloAST * expr2);
     
    200178
    201179    Equals * createEquals(PabloAST * expr1, PabloAST * expr2);
    202 
    203     MatchStar * createMatchStar(PabloAST * marker, PabloAST * charclass) {
    204         return createMatchStar(marker, charclass, nullptr);
    205     }
    206180
    207181    MatchStar * createMatchStar(PabloAST * marker, PabloAST * charclass, const llvm::StringRef & prefix) {
     
    209183    }
    210184
    211     MatchStar * createMatchStar(PabloAST * marker, PabloAST * charclass, String * name);
    212 
    213     ScanThru * createScanThru(PabloAST * from, PabloAST * thru) {
    214         return createScanThru(from, thru, nullptr);
    215     }
     185    MatchStar * createMatchStar(PabloAST * marker, PabloAST * charclass, const String * const name = nullptr);
    216186
    217187    ScanThru * createScanThru(PabloAST * from, PabloAST * thru, const llvm::StringRef & prefix) {
     
    219189    }
    220190
    221     ScanThru * createScanThru(PabloAST * from, PabloAST * thru, String * name);
    222 
    223     ScanTo * createScanTo(PabloAST * from, PabloAST * to) {
    224         return createScanTo(from, to, nullptr);
    225     }
     191    ScanThru * createScanThru(PabloAST * from, PabloAST * thru, const String * const name = nullptr);
    226192
    227193    ScanTo * createScanTo(PabloAST * from, PabloAST * to, const llvm::StringRef & prefix) {
     
    229195    }
    230196
    231     ScanTo * createScanTo(PabloAST * from, PabloAST * to, String * name);
    232 
    233     AdvanceThenScanThru * createAdvanceThenScanThru(PabloAST * from, PabloAST * thru) {
    234         return createAdvanceThenScanThru(from, thru, nullptr);
    235     }
     197    ScanTo * createScanTo(PabloAST * from, PabloAST * to, const String * const name = nullptr);
    236198
    237199    AdvanceThenScanThru * createAdvanceThenScanThru(PabloAST * from, PabloAST * thru, const llvm::StringRef & prefix) {
     
    239201    }
    240202
    241     AdvanceThenScanThru * createAdvanceThenScanThru(PabloAST * from, PabloAST * thru, String * name);
    242 
    243     AdvanceThenScanTo * createAdvanceThenScanTo(PabloAST * from, PabloAST * to) {
    244         return createAdvanceThenScanTo(from, to, nullptr);
    245     }
     203    AdvanceThenScanThru * createAdvanceThenScanThru(PabloAST * from, PabloAST * thru, const String * const name = nullptr);
    246204
    247205    AdvanceThenScanTo * createAdvanceThenScanTo(PabloAST * from, PabloAST * to, const llvm::StringRef & prefix) {
     
    249207    }
    250208
    251     AdvanceThenScanTo * createAdvanceThenScanTo(PabloAST * from, PabloAST * to, String * name);
     209    AdvanceThenScanTo * createAdvanceThenScanTo(PabloAST * from, PabloAST * to, const String * const name = nullptr);
    252210
    253211    If * createIf(PabloAST * condition, PabloBlock * body);
    254212
    255213    While * createWhile(PabloAST * condition, PabloBlock * body);
    256 
    257     Repeat * createRepeat(Integer * fieldWidth, PabloAST * value) {
    258         return createRepeat(fieldWidth, value, nullptr);
    259     }
    260214
    261215    Repeat * createRepeat(Integer * fieldWidth, PabloAST * value, const llvm::StringRef & prefix) {
     
    263217    }
    264218
    265     Repeat * createRepeat(Integer * fieldWidth, PabloAST * value, String * name);
    266 
    267     PackH * createPackH(Integer * fieldWidth, PabloAST * value) {
    268         return createPackH(fieldWidth, value, nullptr);
    269     }
     219    Repeat * createRepeat(Integer * fieldWidth, PabloAST * value, const String * const name = nullptr);
    270220
    271221    PackH * createPackH(Integer * width, PabloAST * value, const llvm::StringRef & prefix) {
     
    273223    }
    274224
    275     PackH * createPackH(Integer * fieldWidth, PabloAST * value, String * name);
    276 
    277     PackL * createPackL(Integer * fieldWidth, PabloAST * value) {
    278         return createPackL(fieldWidth, value, nullptr);
    279     }
     225    PackH * createPackH(Integer * fieldWidth, PabloAST * value, const String * const name = nullptr);
    280226
    281227    PackL * createPackL(Integer * fieldWidth, PabloAST * value, const llvm::StringRef & prefix) {
     
    283229    }
    284230
    285     PackL * createPackL(Integer * fieldWidth, PabloAST * value, String * name);
     231    PackL * createPackL(Integer * fieldWidth, PabloAST * value, const String * const name = nullptr);
    286232
    287233    PabloBlock * getPredecessor() const;
    288234
    289     inline PabloKernel * getParent() const {
     235    PabloKernel * getParent() const {
    290236        return mParent;
    291237    }
     
    295241    void eraseFromParent(const bool recursively = false);
    296242
    297     inline Branch * getBranch() const {
     243    Branch * getBranch() const {
    298244        return mBranch;
    299245    }
    300246
    301     inline void setBranch(Branch * const branch) {
     247    void setBranch(Branch * const branch) {
    302248        mBranch = branch;
    303249    }
    304250
    305     inline String * makeName(const llvm::StringRef & prefix) const {
     251    String * makeName(const llvm::StringRef & prefix) const {
    306252        return mParent->makeName(prefix);
    307253    }
    308254
    309     inline Integer * getInteger(const int64_t value) const {
     255    Integer * getInteger(const int64_t value) const {
    310256        return mParent->getInteger(value);
    311257    }
     
    330276
    331277    template<typename Type>
    332     inline Type * insertAtInsertionPoint(Type * expr) {
     278    Type * insertAtInsertionPoint(Type * expr) {
    333279        if (llvm::isa<Statement>(expr)) {
    334280            insert(llvm::cast<Statement>(expr));
  • icGREP/icgrep-devel/icgrep/pablo/expression_map.hpp

    r5834 r5836  
    1515    friend struct ExpressionTable;
    1616
    17     explicit FixedArgMap(Type * predecessor = nullptr) noexcept
     17    explicit FixedArgMap(const Type * predecessor = nullptr) noexcept
    1818    : mPredecessor(predecessor) {
    1919
     
    9292
    9393private:
    94     Type *                      mPredecessor;
     94    const Type *                mPredecessor;
    9595    std::map<Key, PabloAST *>   mMap;
    9696};
  • icGREP/icgrep-devel/icgrep/pablo/optimizers/codemotionpass.cpp

    r5620 r5836  
    8888                mScopes.insert(cast<Statement>(use)->getParent());
    8989            } else if (LLVM_UNLIKELY(isa<PabloKernel>(use))) {
    90                 mScopes.insert(cast<PabloKernel>(use)->getEntryBlock());
     90                mScopes.insert(cast<PabloKernel>(use)->getEntryScope());
    9191            }
    9292        }
     
    127127        }
    128128        if (LLVM_UNLIKELY(mScopes.empty())) {
    129             assert (!isa<Assign>(stmt));
    130             // should not occur unless we have a branch with no escaped vars or a statement
    131             // that has no users. In either event, the statement itself should be removed.
    132             stmt->eraseFromParent(true);
    133129            return;
    134130        }
     
    274270bool CodeMotionPass::optimize(PabloKernel * kernel) {
    275271    CodeMotionPassContainer C;
    276     C.doCodeMovement(kernel->getEntryBlock());
     272    C.doCodeMovement(kernel->getEntryScope());
    277273    #ifndef NDEBUG
    278274    PabloVerifier::verify(kernel, "post-code-motion");
  • icGREP/icgrep-devel/icgrep/pablo/optimizers/distributivepass.cpp

    r5706 r5836  
    130130     ** ------------------------------------------------------------------------------------------------------------- */
    131131    bool run(PabloKernel * const kernel) {
    132         readAST(kernel->getEntryBlock());
     132        readAST(kernel->getEntryScope());
    133133        if (LLVM_LIKELY(simplifyGraph())) {
    134             rewriteAST(kernel->getEntryBlock());
     134            rewriteAST(kernel->getEntryScope());
    135135            return true;
    136136        }
  • icGREP/icgrep-devel/icgrep/pablo/optimizers/pablo_automultiplexing.cpp

    r5267 r5836  
    7171void MultiplexingPass::optimize() {
    7272    // Map the constants and input variables
    73     PabloBlock * entryBlock = mFunction.getEntryBlock();
     73    PabloBlock * entryBlock = mFunction.getEntryScope();
    7474    add(entryBlock->createZeroes(), Z3_mk_false(mContext), -1);
    7575    add(entryBlock->createOnes(), Z3_mk_true(mContext), -1);
     
    7777        add(mFunction.getParameter(i), makeVar(), -1);
    7878    }
    79     optimize(mFunction.getEntryBlock());
     79    optimize(mFunction.getEntryScope());
    8080}
    8181
  • icGREP/icgrep-devel/icgrep/pablo/optimizers/pablo_simplifier.cpp

    r5834 r5836  
    7171 ** ------------------------------------------------------------------------------------------------------------- */
    7272void run(PabloKernel * const kernel) {
    73     redundancyElimination(kernel->getEntryBlock(), nullptr, nullptr);
    74     strengthReduction(kernel->getEntryBlock());
    75     deadCodeElimination(kernel->getEntryBlock());
     73    redundancyElimination(kernel->getEntryScope(), nullptr, nullptr);
     74    strengthReduction(kernel->getEntryScope());
     75    deadCodeElimination(kernel->getEntryScope());
    7676}
    7777
  • icGREP/icgrep-devel/icgrep/pablo/optimizers/schedulingprepass.cpp

    r5706 r5836  
    377377    #else
    378378    SchedulingPrePassContainer S;
    379     S.run(kernel->getEntryBlock());
     379    S.run(kernel->getEntryScope());
    380380    PabloVerifier::verify(kernel, "post-scheduling-prepass");
    381381    return true;
  • icGREP/icgrep-devel/icgrep/pablo/pabloAST.cpp

    r5834 r5836  
    3535 *  false may be returned i some cases when the exprs are equivalent.
    3636 ** ------------------------------------------------------------------------------------------------------------- */
    37 bool equals(const PabloAST * const expr1, const PabloAST * const expr2) {
     37bool equals(const PabloAST * const expr1, const PabloAST * const expr2) noexcept {
    3838    assert (expr1 && expr2);
    3939    if (LLVM_UNLIKELY(expr1 == expr2)) {
     
    136136
    137137/** ------------------------------------------------------------------------------------------------------------- *
    138  * @brief replaceUsesOfWith
    139  ** ------------------------------------------------------------------------------------------------------------- */
    140 void Statement::replaceUsesOfWith(PabloAST * const from, PabloAST * const to) {
    141     if (LLVM_LIKELY(from != to)) {
    142         for (unsigned i = 0; i != getNumOperands(); ++i) {
    143            if (getOperand(i) == from) {
    144                setOperand(i, to);
    145            }
    146         }
    147     }
    148 }
    149 
    150 /** ------------------------------------------------------------------------------------------------------------- *
    151  * @brief setOperand
    152  ** ------------------------------------------------------------------------------------------------------------- */
    153 void Statement::setOperand(const unsigned index, PabloAST * const value) {   
    154     assert ("Operand cannot be null!" && value);
    155     assert (index < getNumOperands());
    156     PabloAST * const prior = getOperand(index);
    157     assert ("Operand cannot be null!" && prior);
    158     if (LLVM_UNLIKELY(prior == value)) {
    159         return;
    160     }     
    161     if (LLVM_UNLIKELY(prior->getType() != value->getType())) {
    162         std::string tmp;
    163         raw_string_ostream out(tmp);
    164         out << "Type mismatch replacing operand ";
    165         prior->print(out);
    166         out << " with ";
    167         value->print(out);
    168         out << " in statement ";
    169         this->print(out);
    170         llvm::report_fatal_error(out.str());
    171     }
    172     prior->removeUser(this);
    173     mOperand[index] = value;
    174     value->addUser(this);
    175 }
    176 
    177 /** ------------------------------------------------------------------------------------------------------------- *
    178  * @brief insertBefore
    179  ** ------------------------------------------------------------------------------------------------------------- */
    180 void Statement::insertBefore(Statement * const statement) {
    181     if (LLVM_UNLIKELY(statement == this)) {
    182         return;
    183     } else if (LLVM_UNLIKELY(statement == nullptr)) {
    184         llvm::report_fatal_error("cannot insert before null statement!");
    185     } else if (LLVM_UNLIKELY(statement->mParent == nullptr)) {
    186         llvm::report_fatal_error("statement is not contained in a pablo block!");
    187     }
    188     removeFromParent();
    189     mParent = statement->mParent;
    190     if (LLVM_UNLIKELY(mParent->mFirst == statement)) {
    191         mParent->mFirst = this;
    192     }
    193     mNext = statement;
    194     mPrev = statement->mPrev;
    195     statement->mPrev = this;
    196     if (LLVM_LIKELY(mPrev != nullptr)) {
    197         mPrev->mNext = this;
    198     }
    199 }
    200 
    201 /** ------------------------------------------------------------------------------------------------------------- *
    202  * @brief insertAfter
    203  ** ------------------------------------------------------------------------------------------------------------- */
    204 void Statement::insertAfter(Statement * const statement) {
    205     if (LLVM_UNLIKELY(statement == this)) {
    206         return;
    207     } else if (LLVM_UNLIKELY(statement == nullptr)) {
    208         llvm::report_fatal_error("cannot insert after null statement!");
    209     } else if (LLVM_UNLIKELY(statement->mParent == nullptr)) {
    210         llvm::report_fatal_error("statement is not contained in a pablo block!");
    211     }
    212     removeFromParent();
    213     mParent = statement->mParent;
    214     if (LLVM_UNLIKELY(mParent->mLast == statement)) {
    215         mParent->mLast = this;
    216     }
    217     mPrev = statement;
    218     mNext = statement->mNext;
    219     statement->mNext = this;
    220     if (LLVM_LIKELY(mNext != nullptr)) {
    221         mNext->mPrev = this;
    222     }
    223 }
    224 
    225 /** ------------------------------------------------------------------------------------------------------------- *
    226  * @brief removeFromParent
    227  ** ------------------------------------------------------------------------------------------------------------- */
    228 Statement * Statement::removeFromParent() noexcept {
    229     Statement * next = mNext;
    230     if (LLVM_LIKELY(mParent != nullptr)) {
    231         if (LLVM_UNLIKELY(mParent->mFirst == this)) {
    232             mParent->mFirst = mNext;
    233         }
    234         if (LLVM_UNLIKELY(mParent->mLast == this)) {
    235             mParent->mLast = mPrev;
    236         }
    237         if (LLVM_UNLIKELY(mParent->mInsertionPoint == this)) {
    238             mParent->mInsertionPoint = mPrev;
    239         }
    240         if (LLVM_LIKELY(mPrev != nullptr)) {
    241             mPrev->mNext = mNext;
    242         }
    243         if (LLVM_LIKELY(mNext != nullptr)) {
    244             mNext->mPrev = mPrev;
    245         }
    246     }
    247     mPrev = nullptr;
    248     mNext = nullptr;
    249     mParent = nullptr;
    250     return next;
    251 }
    252 
    253 /** ------------------------------------------------------------------------------------------------------------- *
    254  * @brief eraseFromParent
    255  ** ------------------------------------------------------------------------------------------------------------- */
    256 Statement * Statement::eraseFromParent(const bool recursively) noexcept {
    257 
    258     if (LLVM_UNLIKELY(getParent() == nullptr)) {
    259         return nullptr;
    260     }
    261 
    262     if (LLVM_UNLIKELY(isa<Branch>(this))) {
    263         cast<Branch>(this)->getBody()->eraseFromParent(recursively);
    264     } else if (LLVM_LIKELY(!isa<Assign>(this))) {
    265         replaceAllUsesWith(getParent()->createZeroes(getType()));
    266     }
    267 
    268     Statement * const next = removeFromParent();
    269     for (unsigned i = 0; i != mOperands; ++i) {
    270         PabloAST * const op = mOperand[i]; assert (op);
    271         op->removeUser(this);
    272         if (LLVM_UNLIKELY(recursively && op->getNumUses() == 0)) {
    273             if (LLVM_LIKELY(isa<Statement>(op))) {
    274                 cast<Statement>(op)->eraseFromParent(true);
    275             }
    276         }
    277         mOperand[i] = nullptr;
    278     }
    279 
    280     return next;
    281 }
    282 
    283 /** ------------------------------------------------------------------------------------------------------------- *
    284  * @brief replaceWith
    285  ** ------------------------------------------------------------------------------------------------------------- */
    286 Statement * Statement::replaceWith(PabloAST * const expr, const bool rename, const bool recursively) noexcept {
    287     assert (expr);
    288     if (LLVM_UNLIKELY(expr == this)) {
    289         return getNextNode();
    290     }
    291     if (LLVM_LIKELY(rename && isa<Statement>(expr))) {
    292         if (mName && cast<Statement>(expr)->mName == nullptr) {
    293             cast<Statement>(expr)->setName(mName);
    294         }
    295     }
    296     replaceAllUsesWith(expr);
    297     return eraseFromParent(recursively);
     138 * @brief setName
     139 ** ------------------------------------------------------------------------------------------------------------- */
     140void NamedPabloAST::setName(const String * const name) {
     141    if (LLVM_UNLIKELY(name == nullptr)) {
     142        llvm::report_fatal_error("name cannot be null");
     143    }
     144    mName = name;
    298145}
    299146
     
    344191
    345192/** ------------------------------------------------------------------------------------------------------------- *
    346  * @brief setName
    347  ** ------------------------------------------------------------------------------------------------------------- */
    348 void Statement::setName(const String * const name) {
    349     if (LLVM_UNLIKELY(name == nullptr)) {
    350         llvm::report_fatal_error("Statement name cannot be null!");
    351     }
    352     mName = name;
     193 * @brief replaceUsesOfWith
     194 ** ------------------------------------------------------------------------------------------------------------- */
     195void Statement::replaceUsesOfWith(PabloAST * const from, PabloAST * const to) {
     196    if (LLVM_LIKELY(from != to)) {
     197        for (unsigned i = 0; i != getNumOperands(); ++i) {
     198           if (getOperand(i) == from) {
     199               setOperand(i, to);
     200           }
     201        }
     202    }
     203}
     204
     205/** ------------------------------------------------------------------------------------------------------------- *
     206 * @brief setOperand
     207 ** ------------------------------------------------------------------------------------------------------------- */
     208void Statement::setOperand(const unsigned index, PabloAST * const value) {   
     209    assert ("Operand cannot be null!" && value);
     210    assert (index < getNumOperands());
     211    PabloAST * const prior = getOperand(index);
     212    assert ("Operand cannot be null!" && prior);
     213    if (LLVM_UNLIKELY(prior == value)) {
     214        return;
     215    }     
     216    if (LLVM_UNLIKELY(prior->getType() != value->getType())) {
     217        std::string tmp;
     218        raw_string_ostream out(tmp);
     219        out << "Type mismatch replacing operand ";
     220        prior->print(out);
     221        out << " with ";
     222        value->print(out);
     223        out << " in statement ";
     224        this->print(out);
     225        llvm::report_fatal_error(out.str());
     226    }
     227    prior->removeUser(this);
     228    mOperand[index] = value;
     229    value->addUser(this);
     230}
     231
     232/** ------------------------------------------------------------------------------------------------------------- *
     233 * @brief insertBefore
     234 ** ------------------------------------------------------------------------------------------------------------- */
     235void Statement::insertBefore(Statement * const statement) {
     236    if (LLVM_UNLIKELY(statement == this)) {
     237        return;
     238    } else if (LLVM_UNLIKELY(statement == nullptr)) {
     239        llvm::report_fatal_error("cannot insert before null statement!");
     240    } else if (LLVM_UNLIKELY(statement->mParent == nullptr)) {
     241        llvm::report_fatal_error("statement is not contained in a pablo block!");
     242    }
     243    removeFromParent();
     244    mParent = statement->mParent;
     245    if (LLVM_UNLIKELY(mParent->mFirst == statement)) {
     246        mParent->mFirst = this;
     247    }
     248    mNext = statement;
     249    mPrev = statement->mPrev;
     250    statement->mPrev = this;
     251    if (LLVM_LIKELY(mPrev != nullptr)) {
     252        mPrev->mNext = this;
     253    }
     254}
     255
     256/** ------------------------------------------------------------------------------------------------------------- *
     257 * @brief insertAfter
     258 ** ------------------------------------------------------------------------------------------------------------- */
     259void Statement::insertAfter(Statement * const statement) {
     260    if (LLVM_UNLIKELY(statement == this)) {
     261        return;
     262    } else if (LLVM_UNLIKELY(statement == nullptr)) {
     263        llvm::report_fatal_error("cannot insert after null statement!");
     264    } else if (LLVM_UNLIKELY(statement->mParent == nullptr)) {
     265        llvm::report_fatal_error("statement is not contained in a pablo block!");
     266    }
     267    removeFromParent();
     268    mParent = statement->mParent;
     269    if (LLVM_UNLIKELY(mParent->mLast == statement)) {
     270        mParent->mLast = this;
     271    }
     272    mPrev = statement;
     273    mNext = statement->mNext;
     274    statement->mNext = this;
     275    if (LLVM_LIKELY(mNext != nullptr)) {
     276        mNext->mPrev = this;
     277    }
     278}
     279
     280/** ------------------------------------------------------------------------------------------------------------- *
     281 * @brief removeFromParent
     282 ** ------------------------------------------------------------------------------------------------------------- */
     283Statement * Statement::removeFromParent() noexcept {
     284    Statement * next = mNext;
     285    if (LLVM_LIKELY(mParent != nullptr)) {
     286        if (LLVM_UNLIKELY(mParent->mFirst == this)) {
     287            mParent->mFirst = mNext;
     288        }
     289        if (LLVM_UNLIKELY(mParent->mLast == this)) {
     290            mParent->mLast = mPrev;
     291        }
     292        if (LLVM_UNLIKELY(mParent->mInsertionPoint == this)) {
     293            mParent->mInsertionPoint = mPrev;
     294        }
     295        if (LLVM_LIKELY(mPrev != nullptr)) {
     296            mPrev->mNext = mNext;
     297        }
     298        if (LLVM_LIKELY(mNext != nullptr)) {
     299            mNext->mPrev = mPrev;
     300        }
     301    }
     302    mPrev = nullptr;
     303    mNext = nullptr;
     304    mParent = nullptr;
     305    return next;
     306}
     307
     308/** ------------------------------------------------------------------------------------------------------------- *
     309 * @brief eraseFromParent
     310 ** ------------------------------------------------------------------------------------------------------------- */
     311Statement * Statement::eraseFromParent(const bool recursively) noexcept {
     312
     313    if (LLVM_UNLIKELY(getParent() == nullptr)) {
     314        return nullptr;
     315    }
     316
     317    if (LLVM_UNLIKELY(isa<Branch>(this))) {
     318        cast<Branch>(this)->getBody()->eraseFromParent(recursively);
     319    } else if (LLVM_LIKELY(!isa<Assign>(this))) {
     320        replaceAllUsesWith(getParent()->createZeroes(getType()));
     321    }
     322
     323    Statement * const next = removeFromParent();
     324    for (unsigned i = 0; i != mOperands; ++i) {
     325        PabloAST * const op = mOperand[i]; assert (op);
     326        op->removeUser(this);
     327        if (LLVM_UNLIKELY(recursively && op->getNumUses() == 0)) {
     328            if (LLVM_LIKELY(isa<Statement>(op))) {
     329                cast<Statement>(op)->eraseFromParent(true);
     330            }
     331        }
     332        mOperand[i] = nullptr;
     333    }
     334
     335    return next;
     336}
     337
     338/** ------------------------------------------------------------------------------------------------------------- *
     339 * @brief replaceWith
     340 ** ------------------------------------------------------------------------------------------------------------- */
     341Statement * Statement::replaceWith(PabloAST * const expr, const bool rename, const bool recursively) noexcept {
     342    assert (expr);
     343    if (LLVM_UNLIKELY(expr == this)) {
     344        return getNextNode();
     345    }
     346    if (LLVM_UNLIKELY(mName && rename)) {
     347        if (LLVM_LIKELY(isa<Statement>(expr) && cast<Statement>(expr)->mName == nullptr)) {
     348            cast<Statement>(expr)->setName(mName);
     349            mName = nullptr;
     350        }
     351    }
     352    replaceAllUsesWith(expr);
     353    return eraseFromParent(recursively);
    353354}
    354355
     
    356357 * @brief contains
    357358 ** ------------------------------------------------------------------------------------------------------------- */
    358 bool StatementList::contains(const Statement * const statement) const {
     359bool StatementList::contains(const Statement * const statement) const noexcept {
    359360    for (const Statement * stmt : *this) {
    360361        if (statement == stmt) {
     
    379380 * 6. Assign a, t           6 >> 6
    380381 ** ------------------------------------------------------------------------------------------------------------- */
    381 bool dominates(const PabloAST * const expr1, const PabloAST * const expr2) {
     382bool dominates(const PabloAST * const expr1, const PabloAST * const expr2) noexcept {
    382383    if (LLVM_UNLIKELY(expr1 == nullptr || expr2 == nullptr)) {
    383384        return (expr2 == nullptr);
     
    428429 * 6. Assign a, t           6 << 1, 2, 3, 4, 5, 6
    429430 ** ------------------------------------------------------------------------------------------------------------- */
    430 bool postdominates(const PabloAST * const expr1, const PabloAST * const expr2) {
     431bool postdominates(const PabloAST * const expr1, const PabloAST * const expr2) noexcept {
    431432    throw std::runtime_error("not implemented yet!");
    432433}
  • icGREP/icgrep-devel/icgrep/pablo/pabloAST.h

    r5834 r5836  
    170170};
    171171
    172 bool equals(const PabloAST * const expr1, const PabloAST * const expr2);
    173 
    174 bool dominates(const PabloAST * const expr1, const PabloAST * const expr2);
    175 
    176 inline bool strictly_dominates(const PabloAST * const expr1, const PabloAST * const expr2) {
     172bool equals(const PabloAST * const expr1, const PabloAST * const expr2) noexcept;
     173
     174bool dominates(const PabloAST * const expr1, const PabloAST * const expr2) noexcept;
     175
     176inline bool strictly_dominates(const PabloAST * const expr1, const PabloAST * const expr2) noexcept {
    177177    return (expr1 != expr2) && dominates(expr1, expr2);
    178178}
    179179
    180 bool postdominates(const PabloAST * const expr1, const PabloAST * const expr2);
    181 
    182 inline bool strictly_postdominates(const PabloAST * const expr1, const PabloAST * const expr2) {
     180bool postdominates(const PabloAST * const expr1, const PabloAST * const expr2) noexcept;
     181
     182inline bool strictly_postdominates(const PabloAST * const expr1, const PabloAST * const expr2) noexcept {
    183183    return (expr1 != expr2) && postdominates(expr1, expr2);
    184184}
    185185
     186class String;
     187
     188class NamedPabloAST : public PabloAST {
     189public:
     190    virtual const String & getName() const = 0;
     191    void setName(const String * const name);
     192protected:
     193    explicit NamedPabloAST(const ClassTypeId id, llvm::Type * const type, const String * const name, Allocator & allocator)
     194    : PabloAST(id, type, allocator)
     195    , mName(name) {
     196
     197    }
     198protected:
     199    mutable const String * mName;
     200};
     201
    186202class StatementList;
    187203
    188 class String;
    189 
    190 class Statement : public PabloAST {
     204class Statement : public NamedPabloAST {
    191205    friend class StatementList;
    192206    friend class If;
     
    207221    void replaceUsesOfWith(PabloAST * const from, PabloAST * const to);
    208222
    209     // NOTE: getName() can generate a default name if one is does not exist for it
    210     const String & getName() const;
    211 
    212223    inline PabloAST * getOperand(const unsigned index) const noexcept {
    213224        assert (index < getNumOperands());
     
    237248    }
    238249
     250    const String & getName() const final;
     251
    239252    virtual ~Statement() = default;
    240253
    241     void setName(const String * const name);
    242 
    243254protected:
    244255
    245256    explicit Statement(const ClassTypeId id, llvm::Type * const type, std::initializer_list<PabloAST *> operands, const String * const name, Allocator & allocator)
    246     : PabloAST(id, type, allocator)
     257    : NamedPabloAST(id, type, name, allocator)
    247258    , mOperands(operands.size())
    248259    , mOperand(allocator.allocate(mOperands))
    249260    , mNext(nullptr)
    250261    , mPrev(nullptr)
    251     , mName(name)
    252262    , mParent(nullptr) {
    253263        unsigned i = 0;
     
    261271
    262272protected:   
    263     unsigned                mOperands;
    264     PabloAST **             mOperand;
     273    const unsigned          mOperands;
     274    PabloAST ** const       mOperand;
    265275    Statement *             mNext;
    266276    Statement *             mPrev;
    267     mutable const String *  mName;
    268277    PabloBlock *            mParent;
    269278};
     
    569578    }
    570579
    571     bool contains(const Statement * const statement) const;
     580    bool contains(const Statement * const statement) const noexcept;
    572581
    573582protected:
  • icGREP/icgrep-devel/icgrep/pablo/pablo_compiler.cpp

    r5834 r5836  
    5656void PabloCompiler::initializeKernelData(const std::unique_ptr<kernel::KernelBuilder> & b) {
    5757    mBranchCount = 0;
    58     examineBlock(b, mKernel->getEntryBlock());
     58    examineBlock(b, mKernel->getEntryScope());
    5959    mCarryManager->initializeCarryData(b, mKernel);
    6060    if (CompileOptionIsSet(PabloCompilationFlags::EnableProfiling)) {
     
    7575void PabloCompiler::compile(const std::unique_ptr<kernel::KernelBuilder> & b) {
    7676    mCarryManager->initializeCodeGen(b);
    77     PabloBlock * const entryBlock = mKernel->getEntryBlock(); assert (entryBlock);
     77    PabloBlock * const entryBlock = mKernel->getEntryScope(); assert (entryBlock);
    7878    mMarker.emplace(entryBlock->createZeroes(), b->allZeroes());
    7979    mMarker.emplace(entryBlock->createOnes(), b->allOnes());
  • icGREP/icgrep-devel/icgrep/pablo/pablo_kernel.cpp

    r5828 r5836  
    4949}
    5050
    51 Var * PabloKernel::makeVariable(String * name, Type * const type) {
     51Var * PabloKernel::makeVariable(const String * name, Type * const type) {
    5252    Var * const var = new (mAllocator) Var(name, type, mAllocator);
    5353    mVariables.push_back(var);
     
    8787    mStreamTy = b->getStreamTy();
    8888    mSymbolTable = new SymbolGenerator(b->getContext(), mAllocator);
    89     mEntryBlock = PabloBlock::Create(this);
     89    mEntryScope = new (mAllocator) PabloBlock(this, mAllocator);
    9090    mContext = &b->getContext();
    9191    for (const Binding & ss : mStreamSetInputs) {
     
    211211, mPabloCompiler(nullptr)
    212212, mSymbolTable(nullptr)
    213 , mEntryBlock(nullptr)
     213, mEntryScope(nullptr)
    214214, mSizeTy(nullptr)
    215215, mStreamTy(nullptr)
  • icGREP/icgrep-devel/icgrep/pablo/pablo_kernel.h

    r5828 r5836  
    5252    virtual ~PabloKernel();
    5353
    54     PabloBlock * getEntryBlock() const {
    55         return mEntryBlock;
    56     }
    57 
    58     PabloBlock * setEntryBlock(PabloBlock * entryBlock) {
     54    PabloBlock * getEntryScope() const {
     55        return mEntryScope;
     56    }
     57
     58    PabloBlock * setEntryScope(PabloBlock * entryBlock) {
    5959        assert (entryBlock);
    60         std::swap(mEntryBlock, entryBlock);
     60        std::swap(mEntryScope, entryBlock);
    6161        return entryBlock;
    6262    }
     
    159159    }
    160160
    161     Var * makeVariable(String * name, llvm::Type * const type);
     161    Var * makeVariable(const String * name, llvm::Type * const type);
    162162
    163163    // A custom method for preparing kernel declarations is needed,
     
    186186    PabloCompiler *                 mPabloCompiler;
    187187    SymbolGenerator *               mSymbolTable;
    188     PabloBlock *                    mEntryBlock;
     188    PabloBlock *                    mEntryScope;
    189189    llvm::IntegerType *             mSizeTy;
    190190    llvm::VectorType *              mStreamTy;
  • icGREP/icgrep-devel/icgrep/pablo/passes/flattenif.cpp

    r5267 r5836  
    3737 ** ------------------------------------------------------------------------------------------------------------- */
    3838void FlattenIf::transform(PabloKernel * function) {
    39     flattenIf(function->getEntryBlock());
     39    flattenIf(function->getEntryScope());
    4040    #ifndef NDEBUG
    4141    PabloVerifier::verify(function, "flatten-if");
  • icGREP/icgrep-devel/icgrep/pablo/pe_var.h

    r5828 r5836  
    1313namespace pablo {
    1414
    15 class Var : public PabloAST {
     15class Var : public NamedPabloAST {
    1616    friend class PabloBlock;
    1717    friend class PabloAST;
     
    7777        }
    7878    }
    79     const String & getName() const noexcept {
     79
     80    const String & getName() const final {
     81        assert (mName);
    8082        return *mName;
    8183    }
     
    8385protected:
    8486    Var(const String * name, llvm::Type * const type, Allocator & allocator, const Attribute attr = Attribute::None)
    85     : PabloAST(ClassTypeId::Var, type, allocator)
    86     , mAttribute(attr)
    87     , mName(name) {
     87    : NamedPabloAST(ClassTypeId::Var, type, name, allocator)
     88    , mAttribute(attr) {
    8889
    8990    }
    9091private:
    9192    unsigned mAttribute;
    92     const String * const mName;
    9393};
    9494
  • icGREP/icgrep-devel/icgrep/pablo/printer_pablos.cpp

    r5834 r5836  
    3434
    3535void PabloPrinter::print(const PabloKernel * kernel, raw_ostream & out) {
    36     print(kernel->getEntryBlock(), out, true);
     36    print(kernel->getEntryScope(), out, true);
    3737}
    3838
  • icGREP/icgrep-devel/icgrep/re/re_compiler.cpp

    r5835 r5836  
    194194        NameMap nestedMap(mCompiledName);
    195195        mCompiledName = &nestedMap;
    196         PabloBuilder nested = PabloBuilder::Create(pb);
     196        auto nested = pb.createScope();
    197197        MarkerType m1 = compileSeqTail(current, end, 0, marker, nested);
    198198        nested.createAssign(m, markerVar(m1));
     
    317317    if (/*j > IfInsertionGap*/ false) {
    318318        Var * repeated = pb.createVar("repeated", pb.createZeroes());
    319         PabloBuilder nested = PabloBuilder::Create(pb);
     319        auto nested = pb.createScope();
    320320        NameMap nestedMap(mCompiledName);
    321321        mCompiledName = &nestedMap;
     
    407407    }
    408408    Var * m = pb.createVar("m", pb.createZeroes());
    409     PabloBuilder nested = PabloBuilder::Create(pb);
     409    auto nested = pb.createScope();
    410410    NameMap nestedMap(mCompiledName);
    411411    mCompiledName = &nestedMap;
     
    473473    }
    474474    Var * const m1a = pb.createVar("m", pb.createZeroes());
    475     PabloBuilder nested = PabloBuilder::Create(pb);
     475    auto nested = pb.createScope();
    476476    NameMap nestedMap(mCompiledName);
    477477    mCompiledName = &nestedMap;
     
    517517        Var * whileAccum = pb.createVar("accum", base);
    518518        mWhileTest = pb.createZeroes();
    519         PabloBuilder wb = PabloBuilder::Create(pb);
     519        auto wb = pb.createScope();
    520520        NameMap nestedMap(mCompiledName);
    521521        mCompiledName = &nestedMap;
  • icGREP/icgrep-devel/icgrep/re/re_name_resolve.h

    r5786 r5836  
    11#ifndef RE_NAME_RESOLVE_H
    22#define RE_NAME_RESOLVE_H
    3 
    4 #include <UCD/ucd_compiler.hpp>
    53
    64namespace re {
  • icGREP/icgrep-devel/icgrep/toolchain/grep_pipeline.cpp

    r5793 r5836  
    6262    pxDriver.makeKernelCall(sourceK, {}, {ByteStream});
    6363   
     64    StreamSetBuffer * LineFeedStream = pxDriver.addBuffer<CircularBuffer>(idb, idb->getStreamSetTy(1, 1), segmentSize);
     65    #ifdef USE_DIRECT_LF_BUILDER
     66    kernel::Kernel * linefeedK = pxDriver.addKernelInstance<kernel::LineFeedKernelBuilder>(idb, 8);
     67    pxDriver.makeKernelCall(linefeedK, {ByteStream}, {LineFeedStream});
     68    #endif
     69
    6470    StreamSetBuffer * BasisBits = pxDriver.addBuffer<CircularBuffer>(idb, idb->getStreamSetTy(8, 1), segmentSize);
    6571    kernel::Kernel * s2pk = pxDriver.addKernelInstance<kernel::S2PKernel>(idb);
    6672    pxDriver.makeKernelCall(s2pk, {ByteStream}, {BasisBits});
    67    
     73
     74    #ifndef USE_DIRECT_LF_BUILDER
    6875    kernel::Kernel * linefeedK = pxDriver.addKernelInstance<kernel::LineFeedKernelBuilder>(idb, 8);
    69     StreamSetBuffer * LineFeedStream = pxDriver.addBuffer<CircularBuffer>(idb, idb->getStreamSetTy(1, 1), segmentSize);
    7076    pxDriver.makeKernelCall(linefeedK, {BasisBits}, {LineFeedStream});
     77    #endif
    7178
    7279    kernel::Kernel * linebreakK = pxDriver.addKernelInstance<kernel::LineBreakKernelBuilder>(idb, 8);
  • icGREP/icgrep-devel/icgrep/u8u16.cpp

    r5797 r5836  
    9595
    9696    // Builder for the if statement handling all non-ASCII logic
    97     PabloBuilder nAb = PabloBuilder::Create(main);
     97    auto nAb = main.createScope();
    9898    // Bits 3 through 7 of a 2-byte prefix are data bits, needed to
    9999    // produce the UTF-16 code unit data ...,
     
    107107    PabloAST * pfx34 = ccc.compileCC(re::makeByte(0xE0, 0xFF), nAb);
    108108    // Builder for the if statement handling all logic for 3- and 4-byte sequences.
    109     PabloBuilder p34b = PabloBuilder::Create(nAb);
     109    auto p34b = nAb.createScope();
    110110    // Bits 4 through 7 of a 3-byte prefix are data bits.  They must be moved
    111111    // to the final position of the 3-byte sequence.
     
    126126    PabloAST * pfx4 = ccc.compileCC(re::makeByte(0xF0, 0xFF), p34b);
    127127    // Builder for the if statement handling all logic for 4-byte sequences only.
    128     PabloBuilder p4b = PabloBuilder::Create(p34b);
     128    auto p4b = p34b.createScope();
    129129    // Illegal 4-byte sequences
    130130    PabloAST * F0 = ccc.compileCC(re::makeByte(0xF0), p4b);
Note: See TracChangeset for help on using the changeset viewer.