Changeset 4276


Ignore:
Timestamp:
Oct 30, 2014, 1:19:34 PM (4 years ago)
Author:
nmedfort
Message:

Created an "insertion friendly" Pablo AST structure similar to LLVM; fixed engine builder bug when creating a unicode class.

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

Legend:

Unmodified
Added
Removed
  • icGREP/icgrep-devel/icgrep/compiler.cpp

    r4270 r4276  
    100100    #ifdef DEBUG_PRINT_PBIX_AST
    101101    //Print to the terminal the AST that was generated by the character class compiler.
    102     std::cerr << "Pablo CC AST:" << std::endl << StatementPrinter::Print_CC_PabloStmts(main.statements()) << std::endl;
     102    std::cerr << "Pablo CC AST:" << std::endl << PabloPrinter::print(main.statements()) << std::endl;
    103103    #endif
    104104
     
    107107    #ifdef DEBUG_PRINT_PBIX_AST
    108108    //Print to the terminal the AST that was generated by the pararallel bit-stream compiler.
    109     std::cerr << "Final Pablo AST:" << StatementPrinter::Print_CC_PabloStmts(main.statements()) << ")" << std::endl;
     109    std::cerr << "Final Pablo AST:" << PabloPrinter::print(main.statements()) << ")" << std::endl;
    110110    #endif
     111
     112    RE::release_memory();
    111113
    112114    PabloCompiler pablo_compiler(basisBits);
     
    128130    }
    129131
     132    PabloAST::release_memory();
     133
    130134    return retVal;
    131135}
  • icGREP/icgrep-devel/icgrep/pablo/analysis/useanalysis.cpp

    r4270 r4276  
    77    UseAnalysis analyzer;
    88    analyzer.gatherUseDefInformation(analyzer.mRoot, block.statements());
    9 
     9    analyzer.identifyDeadVariables();
    1010}
    1111
  • icGREP/icgrep-devel/icgrep/pablo/codegenstate.h

    r4270 r4276  
    196196    };
    197197
     198
     199    inline StatementList & statements() {
     200        return mStatements;
     201    }
     202
    198203    inline const StatementList & statements() const {
    199204        return mStatements;
    200205    }
     206
    201207private:       
    202208    Zeroes * const                                      mZeroes;
  • icGREP/icgrep-devel/icgrep/pablo/pabloAST.cpp

    r4272 r4276  
    1919#include "pe_zeroes.h"
    2020#include "pe_ones.h"
     21#include <llvm/Support/Compiler.h>
    2122
    2223namespace pablo {
     
    3334
    3435bool equals(const PabloAST * expr1, const PabloAST * expr2) {
     36    assert (expr1 && expr2);
    3537    if (expr1->getClassTypeId() == expr2->getClassTypeId()) {
    3638        if ((isa<const Zeroes>(expr1)) || (isa<const Ones>(expr1))) {
     
    9092}
    9193
     94void StatementList::push_back(Statement * const statement) {
     95    if (LLVM_UNLIKELY(mLast == nullptr)) {
     96        mFirst = mLast = statement;
     97    }
     98    else {
     99        statement->insertAfter(mLast);
     100        mLast = statement;
     101    }
    92102}
     103
     104}
  • icGREP/icgrep-devel/icgrep/pablo/pabloAST.h

    r4272 r4276  
    1010#include <llvm/Support/Casting.h>
    1111#include <slab_allocator.h>
    12 #include <vector>
     12#include <iterator>
    1313
    1414using namespace llvm;
     
    5252
    5353    }
    54     static Allocator mAllocator;
     54    static Allocator    mAllocator;
    5555private:
    5656    const ClassTypeId   mClassTypeId;
     
    5959bool equals(const PabloAST * expr1, const PabloAST *expr2);
    6060
    61 typedef std::vector<PabloAST *> StatementList;
     61class Statement : public PabloAST {
     62    friend class StatementList;
     63public:
     64    Statement(const ClassTypeId id)
     65    : PabloAST(id)
     66    , mNext(nullptr)
     67    , mPrev(nullptr)
     68    {
     69
     70    }
     71    inline void insertBefore(Statement * const statement) {
     72        assert (statement);
     73        mNext = statement;
     74        mPrev = statement->mPrev;
     75        statement->mPrev = this;
     76    }
     77    inline void insertAfter(Statement * const statement) {
     78        assert (statement);
     79        mPrev = statement;
     80        mNext = statement->mNext;
     81        statement->mNext = this;
     82    }
     83private:
     84    Statement * mNext;
     85    Statement * mPrev;
     86};
     87
     88class StatementList {
     89
     90    class iterator: public std::iterator<std::forward_iterator_tag, Statement> {
     91    public:
     92        iterator(): mCurrent(nullptr) {}
     93
     94        iterator(Statement* base): mCurrent(base) {}
     95
     96        iterator(const iterator& other): mCurrent(other.mCurrent) {}
     97
     98        const iterator& operator=(const iterator& other) {
     99            mCurrent = other.mCurrent; return other;
     100        }
     101
     102        inline iterator& operator++() {
     103            assert (mCurrent);
     104            mCurrent = mCurrent->mNext;
     105            return *this;
     106        }
     107
     108        iterator  operator++(int) {
     109            iterator tmp(*this);
     110            ++(*this);
     111            return tmp;
     112        }
     113
     114        bool operator==(const iterator& other) const {
     115            return  mCurrent == other.mCurrent;
     116        }
     117
     118        bool operator!=(const iterator& other) const {
     119            return  mCurrent != other.mCurrent;
     120        }
     121
     122        Statement* operator*() {return mCurrent;}
     123        Statement* operator->(){return mCurrent;}
     124
     125    private:
     126        Statement * mCurrent;
     127        friend class const_iterator;
     128    };
     129
     130    class const_iterator: public std::iterator<std::forward_iterator_tag, Statement> {
     131    public:
     132        const_iterator(): mCurrent(nullptr) {}
     133        const_iterator(const Statement* base): mCurrent(base) {}
     134        const_iterator(const const_iterator& other): mCurrent(other.mCurrent) {}
     135        const const_iterator& operator=(const const_iterator& other) {mCurrent = other.mCurrent; return other;}
     136
     137        inline const_iterator& operator++() {
     138            assert (mCurrent);
     139            mCurrent = mCurrent->mNext;
     140            return *this;
     141        }
     142
     143        const_iterator  operator++(int) {
     144            const_iterator tmp(*this);
     145            ++(*this);
     146            return tmp;
     147        }
     148
     149        bool operator==(const const_iterator & other) const {
     150            return  mCurrent == other.mCurrent;
     151        }
     152        bool operator!=(const const_iterator & other) const {
     153            return  mCurrent != other.mCurrent;
     154        }
     155
     156        const Statement* operator*() {return mCurrent;}
     157        const Statement* operator->(){return mCurrent;}
     158
     159    private:
     160        const Statement * mCurrent;
     161        friend class iterator;
     162    };
     163
     164public:
     165
     166    StatementList()
     167    : mFirst(nullptr)
     168    , mLast(nullptr)
     169    {
     170
     171    }
     172
     173    StatementList(StatementList && other)
     174    : mFirst(other.mFirst)
     175    , mLast(other.mLast)
     176    {
     177        other.mFirst = nullptr;
     178        other.mLast = nullptr;
     179    }
     180
     181    iterator begin() {
     182        return iterator(mFirst);
     183    }
     184
     185    iterator end() {
     186        return iterator(nullptr);
     187    }
     188
     189    const_iterator begin() const {
     190        return const_iterator(mFirst);
     191    }
     192
     193    const_iterator end() const {
     194        return const_iterator(nullptr);
     195    }
     196
     197    const_iterator cbegin() const {
     198        return const_iterator(mFirst);
     199    }
     200
     201    const_iterator cend() const {
     202        return const_iterator(nullptr);
     203    }
     204
     205    void push_back(Statement * const statement);
     206
     207private:
     208    Statement * mFirst;
     209    Statement * mLast;
     210};
    62211
    63212}
  • icGREP/icgrep-devel/icgrep/pablo/pablo_compiler.cpp

    r4275 r4276  
    5555#include <llvm/Bitcode/ReaderWriter.h>
    5656#include <llvm/Support/MemoryBuffer.h>
    57 
    5857#include <llvm/IR/IRBuilder.h>
    5958
     
    130129, mBasisBitsAddr(nullptr)
    131130, mOutputAddrPtr(nullptr)
    132 , mMaxPabloWhileDepth(0)
     131, mMaxNestingDepth(0)
    133132{
    134133    //Create the jit execution engine.up
     
    178177LLVM_Gen_RetVal PabloCompiler::compile(PabloBlock & pb)
    179178{
     179    mNestingDepth = 0;
     180    mMaxNestingDepth = 0;
    180181    mCarryQueueSize = 0;
    181     DeclareCallFunctions(pb.statements());
     182    Examine(pb.statements());
    182183    mCarryQueueVector.resize(mCarryQueueSize);
     184
     185    std::string errMessage;
     186    EngineBuilder builder(mMod);
     187    builder.setErrorStr(&errMessage);
     188    builder.setMCPU(sys::getHostCPUName());
     189    builder.setUseMCJIT(true);
     190    builder.setOptLevel(mMaxNestingDepth > 1 ? CodeGenOpt::Level::Less : CodeGenOpt::Level::None);
     191    mExecutionEngine = builder.create();
     192    if (mExecutionEngine == nullptr) {
     193        throw std::runtime_error("Could not create ExecutionEngine: " + errMessage);
     194    }
     195
     196    if (!mCalleeMap.empty()) {
     197        DeclareCallFunctions();
     198    }
    183199
    184200    Function::arg_iterator args = mFunction->arg_begin();
     
    193209    mCarryQueueIdx = 0;
    194210    mNestingDepth = 0;
     211    mMaxNestingDepth = 0;
    195212    mBasicBlock = BasicBlock::Create(mMod->getContext(), "parabix_entry", mFunction,0);
    196213
     
    228245    //Use the pass manager to run optimizations on the function.
    229246    FunctionPassManager fpm(mMod);
    230     if (true) {
    231         std::string errMessage;
    232         EngineBuilder builder(mMod);
    233         builder.setErrorStr(&errMessage);
    234         builder.setMCPU(sys::getHostCPUName());
    235         builder.setUseMCJIT(true);
    236         builder.setOptLevel(mMaxPabloWhileDepth == 0 ? CodeGenOpt::Level::None : CodeGenOpt::Level::Less);
    237         mExecutionEngine = builder.create();
    238         if (mExecutionEngine == nullptr) {
    239             throw std::runtime_error("Could not create ExecutionEngine: " + errMessage);
    240         }
    241     }
    242 #ifdef USE_LLVM_3_5
     247 #ifdef USE_LLVM_3_5
    243248    mMod->setDataLayout(mExecutionEngine->getDataLayout());
    244249    // Set up the optimizer pipeline.  Start with registering info about how the target lays out data structures.
     
    249254    fpm.add(new DataLayout(*mExecutionEngine->getDataLayout()));
    250255#endif
    251 
    252     //fpm.add(createPromoteMemoryToRegisterPass()); //Transform to SSA form.
    253     //fpm.add(createBasicAliasAnalysisPass());      //Provide basic AliasAnalysis support for GVN. (Global Value Numbering)
    254     //fpm.add(createCFGSimplificationPass());       //Simplify the control flow graph.
    255256
    256257    fpm.add(createCorrelatedValuePropagationPass());
     
    260261    fpm.add(createGVNPass());                     //Eliminate common subexpressions.   
    261262
    262 
    263     // -O1 is based on -O0
    264 
    265     // adds: -adce -always-inline -basicaa -basiccg -correlated-propagation -deadargelim -dse -early-cse -functionattrs -globalopt -indvars
    266     // -inline-cost -instcombine -ipsccp -jump-threading -lazy-value-info -lcssa -licm -loop-deletion -loop-idiom -loop-rotate -loop-simplify
    267     // -loop-unroll -loop-unswitch -loops -lower-expect -memcpyopt -memdep -no-aa -notti -prune-eh -reassociate -scalar-evolution -sccp
    268     // -simplifycfg -sroa -strip-dead-prototypes -tailcallelim -tbaa
    269 
    270 /// no noticable impact on performance
    271 
    272 //    fpm.add(createConstantPropagationPass());
    273 //    fpm.add(createDeadCodeEliminationPass());
    274 //    fpm.add(createJumpThreadingPass());
    275 //    fpm.add(createLoopIdiomPass());
    276 //    fpm.add(createLoopRotatePass());
    277 //    fpm.add(createLCSSAPass());
    278 //    fpm.add(createLazyValueInfoPass());
    279 //    fpm.add(createLowerExpectIntrinsicPass());
    280 //    fpm.add(createLoopStrengthReducePass());
    281 //    fpm.add(createLoopUnswitchPass());
    282 //    fpm.add(createSCCPPass());
    283 //    fpm.add(createLICMPass());
    284 
    285 /// hurt performance significantly
    286 
    287 //    fpm.add(createLoopUnrollPass());
    288 //    fpm.add(createIndVarSimplifyPass());
    289263    fpm.doInitialization();
    290264
     
    440414}
    441415
    442 void PabloCompiler::DeclareCallFunctions(const StatementList & stmts) {
    443     for (PabloAST * stmt : stmts) {
    444         if (const Assign * assign = dyn_cast<Assign>(stmt)) {
    445             DeclareCallFunctions(assign->getExpr());
    446         }
    447         if (const Next * next = dyn_cast<Next>(stmt)) {
    448             DeclareCallFunctions(next->getExpr());
     416void PabloCompiler::Examine(StatementList & stmts) {
     417    for (Statement * stmt : stmts) {
     418        if (Assign * assign = dyn_cast<Assign>(stmt)) {
     419            Examine(assign->getExpr());
     420        }
     421        if (Next * next = dyn_cast<Next>(stmt)) {
     422            Examine(next->getExpr());
    449423        }
    450424        else if (If * ifStatement = dyn_cast<If>(stmt)) {
    451425            const auto preIfCarryCount = mCarryQueueSize;
    452             DeclareCallFunctions(ifStatement->getCondition());
    453             DeclareCallFunctions(ifStatement->getBody());
     426            Examine(ifStatement->getCondition());
     427            mMaxNestingDepth = std::max(mMaxNestingDepth, ++mNestingDepth);
     428            Examine(ifStatement->getBody());
     429            --mNestingDepth;
    454430            ifStatement->setInclusiveCarryCount(mCarryQueueSize - preIfCarryCount);
    455431        }
    456432        else if (While * whileStatement = dyn_cast<While>(stmt)) {
    457433            const auto preWhileCarryCount = mCarryQueueSize;
    458             DeclareCallFunctions(whileStatement->getCondition());
    459             DeclareCallFunctions(whileStatement->getBody());
     434            Examine(whileStatement->getCondition());
     435            mMaxNestingDepth = std::max(mMaxNestingDepth, ++mNestingDepth);
     436            Examine(whileStatement->getBody());
     437            --mNestingDepth;
    460438            whileStatement->setInclusiveCarryCount(mCarryQueueSize - preWhileCarryCount);
    461439        }
     
    463441}
    464442
    465 void PabloCompiler::DeclareCallFunctions(const PabloAST * expr)
     443void PabloCompiler::Examine(PabloAST *expr)
    466444{
    467     if (const Call * call = dyn_cast<const Call>(expr)) {
    468         const String * const callee = call->getCallee();
    469         assert (callee);
    470         if (mCalleeMap.find(callee) == mCalleeMap.end()) {
    471             void * callee_ptr = nullptr;
    472             #define CHECK_GENERAL_CODE_CATEGORY(SUFFIX) \
    473                 if (callee->str() == #SUFFIX) { \
    474                     callee_ptr = (void*)&__get_category_##SUFFIX; \
    475                 } else
    476             CHECK_GENERAL_CODE_CATEGORY(Cc)
    477             CHECK_GENERAL_CODE_CATEGORY(Cf)
    478             CHECK_GENERAL_CODE_CATEGORY(Cn)
    479             CHECK_GENERAL_CODE_CATEGORY(Co)
    480             CHECK_GENERAL_CODE_CATEGORY(Cs)
    481             CHECK_GENERAL_CODE_CATEGORY(Ll)
    482             CHECK_GENERAL_CODE_CATEGORY(Lm)
    483             CHECK_GENERAL_CODE_CATEGORY(Lo)
    484             CHECK_GENERAL_CODE_CATEGORY(Lt)
    485             CHECK_GENERAL_CODE_CATEGORY(Lu)
    486             CHECK_GENERAL_CODE_CATEGORY(Mc)
    487             CHECK_GENERAL_CODE_CATEGORY(Me)
    488             CHECK_GENERAL_CODE_CATEGORY(Mn)
    489             CHECK_GENERAL_CODE_CATEGORY(Nd)
    490             CHECK_GENERAL_CODE_CATEGORY(Nl)
    491             CHECK_GENERAL_CODE_CATEGORY(No)
    492             CHECK_GENERAL_CODE_CATEGORY(Pc)
    493             CHECK_GENERAL_CODE_CATEGORY(Pd)
    494             CHECK_GENERAL_CODE_CATEGORY(Pe)
    495             CHECK_GENERAL_CODE_CATEGORY(Pf)
    496             CHECK_GENERAL_CODE_CATEGORY(Pi)
    497             CHECK_GENERAL_CODE_CATEGORY(Po)
    498             CHECK_GENERAL_CODE_CATEGORY(Ps)
    499             CHECK_GENERAL_CODE_CATEGORY(Sc)
    500             CHECK_GENERAL_CODE_CATEGORY(Sk)
    501             CHECK_GENERAL_CODE_CATEGORY(Sm)
    502             CHECK_GENERAL_CODE_CATEGORY(So)
    503             CHECK_GENERAL_CODE_CATEGORY(Zl)
    504             CHECK_GENERAL_CODE_CATEGORY(Zp)
    505             CHECK_GENERAL_CODE_CATEGORY(Zs)
    506             // OTHERWISE ...
    507             throw std::runtime_error("Unknown unicode category \"" + callee->str() + "\"");
    508             #undef CHECK_GENERAL_CODE_CATEGORY
    509             Value * unicodeCategory = mMod->getOrInsertFunction("__get_category_" + callee->str(), mBitBlockType, mBasisBitsInputPtr, NULL);
    510             if (unicodeCategory == nullptr) {
    511                 throw std::runtime_error("Could not create static method call for unicode category \"" + callee->str() + "\"");
    512             }
    513             mExecutionEngine->addGlobalMapping(cast<GlobalValue>(unicodeCategory), callee_ptr);
    514             mCalleeMap.insert(std::make_pair(callee, unicodeCategory));
    515         }
    516     }
    517     else if (const And * pablo_and = dyn_cast<const And>(expr))
    518     {
    519         DeclareCallFunctions(pablo_and->getExpr1());
    520         DeclareCallFunctions(pablo_and->getExpr2());
    521     }
    522     else if (const Or * pablo_or = dyn_cast<const Or>(expr))
    523     {
    524         DeclareCallFunctions(pablo_or->getExpr1());
    525         DeclareCallFunctions(pablo_or->getExpr2());
    526     }
    527     else if (const Sel * pablo_sel = dyn_cast<const Sel>(expr))
    528     {
    529         DeclareCallFunctions(pablo_sel->getCondition());
    530         DeclareCallFunctions(pablo_sel->getTrueExpr());
    531         DeclareCallFunctions(pablo_sel->getFalseExpr());
    532     }
    533     else if (const Not * pablo_not = dyn_cast<const Not>(expr))
    534     {
    535         DeclareCallFunctions(pablo_not->getExpr());
    536     }
    537     else if (const Advance * adv = dyn_cast<const Advance>(expr))
    538     {
     445    if (Call * call = dyn_cast<Call>(expr)) {
     446        mCalleeMap.insert(std::make_pair(call->getCallee(), nullptr));
     447    }
     448    else if (And * pablo_and = dyn_cast<And>(expr)) {
     449        Examine(pablo_and->getExpr1());
     450        Examine(pablo_and->getExpr2());
     451    }
     452    else if (Or * pablo_or = dyn_cast<Or>(expr)) {
     453        Examine(pablo_or->getExpr1());
     454        Examine(pablo_or->getExpr2());
     455    }
     456    else if (Sel * pablo_sel = dyn_cast<Sel>(expr)) {
     457        Examine(pablo_sel->getCondition());
     458        Examine(pablo_sel->getTrueExpr());
     459        Examine(pablo_sel->getFalseExpr());
     460    }
     461    else if (Not * pablo_not = dyn_cast<Not>(expr)) {
     462        Examine(pablo_not->getExpr());
     463    }
     464    else if (Advance * adv = dyn_cast<Advance>(expr)) {
    539465        ++mCarryQueueSize;
    540         DeclareCallFunctions(adv->getExpr());
    541     }
    542     else if (const MatchStar * mstar = dyn_cast<const MatchStar>(expr))
    543     {
     466        Examine(adv->getExpr());
     467    }
     468    else if (MatchStar * mstar = dyn_cast<MatchStar>(expr)) {
    544469        ++mCarryQueueSize;
    545         DeclareCallFunctions(mstar->getMarker());
    546         DeclareCallFunctions(mstar->getCharClass());
    547     }
    548     else if (const ScanThru * sthru = dyn_cast<const ScanThru>(expr))
    549     {
     470        Examine(mstar->getMarker());
     471        Examine(mstar->getCharClass());
     472    }
     473    else if (ScanThru * sthru = dyn_cast<ScanThru>(expr)) {
    550474        ++mCarryQueueSize;
    551         DeclareCallFunctions(sthru->getScanFrom());
    552         DeclareCallFunctions(sthru->getScanThru());
     475        Examine(sthru->getScanFrom());
     476        Examine(sthru->getScanThru());
     477    }
     478}
     479
     480void PabloCompiler::DeclareCallFunctions() {
     481    for (auto mapping : mCalleeMap) {
     482        const String * callee = mapping.first;
     483        void * callee_ptr = nullptr;
     484        #define CHECK_GENERAL_CODE_CATEGORY(SUFFIX) \
     485            if (callee->str() == #SUFFIX) { \
     486                callee_ptr = (void*)&__get_category_##SUFFIX; \
     487            } else
     488        CHECK_GENERAL_CODE_CATEGORY(Cc)
     489        CHECK_GENERAL_CODE_CATEGORY(Cf)
     490        CHECK_GENERAL_CODE_CATEGORY(Cn)
     491        CHECK_GENERAL_CODE_CATEGORY(Co)
     492        CHECK_GENERAL_CODE_CATEGORY(Cs)
     493        CHECK_GENERAL_CODE_CATEGORY(Ll)
     494        CHECK_GENERAL_CODE_CATEGORY(Lm)
     495        CHECK_GENERAL_CODE_CATEGORY(Lo)
     496        CHECK_GENERAL_CODE_CATEGORY(Lt)
     497        CHECK_GENERAL_CODE_CATEGORY(Lu)
     498        CHECK_GENERAL_CODE_CATEGORY(Mc)
     499        CHECK_GENERAL_CODE_CATEGORY(Me)
     500        CHECK_GENERAL_CODE_CATEGORY(Mn)
     501        CHECK_GENERAL_CODE_CATEGORY(Nd)
     502        CHECK_GENERAL_CODE_CATEGORY(Nl)
     503        CHECK_GENERAL_CODE_CATEGORY(No)
     504        CHECK_GENERAL_CODE_CATEGORY(Pc)
     505        CHECK_GENERAL_CODE_CATEGORY(Pd)
     506        CHECK_GENERAL_CODE_CATEGORY(Pe)
     507        CHECK_GENERAL_CODE_CATEGORY(Pf)
     508        CHECK_GENERAL_CODE_CATEGORY(Pi)
     509        CHECK_GENERAL_CODE_CATEGORY(Po)
     510        CHECK_GENERAL_CODE_CATEGORY(Ps)
     511        CHECK_GENERAL_CODE_CATEGORY(Sc)
     512        CHECK_GENERAL_CODE_CATEGORY(Sk)
     513        CHECK_GENERAL_CODE_CATEGORY(Sm)
     514        CHECK_GENERAL_CODE_CATEGORY(So)
     515        CHECK_GENERAL_CODE_CATEGORY(Zl)
     516        CHECK_GENERAL_CODE_CATEGORY(Zp)
     517        CHECK_GENERAL_CODE_CATEGORY(Zs)
     518        // OTHERWISE ...
     519        throw std::runtime_error("Unknown unicode category \"" + callee->str() + "\"");
     520        #undef CHECK_GENERAL_CODE_CATEGORY
     521        Value * unicodeCategory = mMod->getOrInsertFunction("__get_category_" + callee->str(), mBitBlockType, mBasisBitsInputPtr, NULL);
     522        if (unicodeCategory == nullptr) {
     523            throw std::runtime_error("Could not create static method call for unicode category \"" + callee->str() + "\"");
     524        }
     525        mExecutionEngine->addGlobalMapping(cast<GlobalValue>(unicodeCategory), callee_ptr);
     526        mCalleeMap[callee] = unicodeCategory;
    553527    }
    554528}
     
    556530Value * PabloCompiler::compileStatements(const StatementList & stmts) {
    557531    Value * retVal = nullptr;
    558     for (PabloAST * statement : stmts) {
     532    for (const PabloAST * statement : stmts) {
    559533        retVal = compileStatement(statement);
    560534    }
     
    641615        }       
    642616
    643         SmallVector<Next*, 4> nextNodes;
    644         for (PabloAST * node : whileStatement->getBody()) {
     617        SmallVector<const Next*, 4> nextNodes;
     618        for (const PabloAST * node : whileStatement->getBody()) {
    645619            if (isa<Next>(node)) {
    646620                nextNodes.push_back(cast<Next>(node));
     
    651625        // mCarryQueueVector with the appropriate values. Although we're not actually entering a new basic
    652626        // block yet, increment the nesting depth so that any calls to genCarryInLoad or genCarryOutStore
    653         // will refer to the previous value.
     627        // will refer to the previous value.       
     628
    654629        ++mNestingDepth;
    655         if (mMaxPabloWhileDepth < mNestingDepth) mMaxPabloWhileDepth = mNestingDepth;
     630
    656631        compileStatements(whileStatement->getBody());
    657632       
     
    682657        }
    683658        // and for any Next nodes in the loop body
    684         for (Next * n : nextNodes) {
     659        for (const Next * n : nextNodes) {
    685660            PHINode * phi = bCond.CreatePHI(mBitBlockType, 2, n->getName()->str());
    686661            auto f = mMarkerMap.find(n->getName());
     
    706681        }
    707682        // and for any Next nodes in the loop body
    708         for (Next * n : nextNodes) {
     683        for (const Next * n : nextNodes) {
    709684            auto f = mMarkerMap.find(n->getName());
    710685            assert (f != mMarkerMap.end());
  • icGREP/icgrep-devel/icgrep/pablo/pablo_compiler.h

    r4275 r4276  
    6161    void DefineTypes();
    6262    void DeclareFunctions();
    63     void DeclareCallFunctions(const StatementList & stmts);
    64     void DeclareCallFunctions(const PabloAST * expr);
     63    void Examine(StatementList & stmts);
     64    void Examine(PabloAST * expr);
     65    void DeclareCallFunctions();
    6566    void SetOutputValue(Value * marker, const unsigned index);
    6667
     
    109110    Value*                              mOutputAddrPtr;
    110111
    111     int                                 mMaxPabloWhileDepth;
     112    unsigned                            mMaxNestingDepth;
    112113
    113114    StringToValueMap                    mCalleeMap;
  • icGREP/icgrep-devel/icgrep/pablo/pe_next.h

    r4272 r4276  
    99class Assign;
    1010
    11 class Next : public PabloAST {
     11class Next : public Statement {
    1212    friend class PabloBlock;
    1313public:
     
    3232    }
    3333    Next(const PabloAST * initial, PabloAST * expr)
    34     : PabloAST(ClassTypeId::Next)
     34    : Statement(ClassTypeId::Next)
    3535    , mInitial(cast<Assign>(initial))
    3636    , mExpr(expr)
  • icGREP/icgrep-devel/icgrep/pablo/printer_pablos.cpp

    r4268 r4276  
    3838using namespace pablo;
    3939
    40 std::string StatementPrinter::PrintStmts(const PabloBlock & cg_state)
     40std::string PabloPrinter::print(const PabloBlock & block)
    4141{
    4242    std::string strOut = "[";
     
    4545    strOut += "],[";
    4646
    47     strOut += Print_PB_PabloStmts(cg_state.statements());
     47    strOut += print(block.statements());
    4848
    4949    strOut = strOut.substr(0, strOut.length() - 1);
     
    5353}
    5454
    55 std::string StatementPrinter::Print_PB_PabloStmts(const StatementList & stmts) {
     55std::string PabloPrinter::print(const StatementList & stmts) {
    5656    std::string strOut = "";
    57     for (const auto stmt : stmts) {
    58         strOut += ShowPabloS(stmt);
     57    for (const Statement * stmt : stmts) {
     58        strOut += print(stmt) + "\n";
    5959    }
    6060    return strOut;
    6161}
    6262
    63 std::string StatementPrinter::Print_CC_PabloStmts(const pablo::StatementList &stmts) {
    64     std::string strOut = "Total Statements: " + std::to_string(stmts.size()) + "\n";
    65     for (const auto stmt : stmts) {
    66         strOut += ShowPabloS(stmt) + "\n";
    67     }
    68     return strOut;
    69 }
    70 
    71 std::string StatementPrinter::ShowPabloS(const PabloAST * stmt)
     63std::string PabloPrinter::print(const Statement * stmt)
    7264{
    7365    if (const Assign * an = dyn_cast<const Assign>(stmt)) {
    74         std::string result = "Assign('" + an->getName()->str() + "', " + ShowPabloAST(an->getExpr());
     66        std::string result = "Assign('" + an->getName()->str() + "'," + print(an->getExpr());
    7567        if (an->isOutputAssignment()) {
    76             result += ", Output=" + std::to_string(an->getOutputIndex());
     68            result += ",Output=" + std::to_string(an->getOutputIndex());
    7769        }
    78         return result + "),";
     70        return result + ")";
    7971    }
    8072    else if (const Next * next = dyn_cast<const Next>(stmt)) {
    81         return "Next(" + next->getName()->str() + ", " + ShowPabloAST(next->getExpr()) + ")";
     73        return "Next(" + next->getName()->str() + "," + print(next->getExpr()) + ")";
    8274    }
    8375    else if (const If * ifstmt = dyn_cast<const If>(stmt)) {
    84         return "If(" + ShowPabloAST(ifstmt->getCondition()) + ", " + Print_PB_PabloStmts(ifstmt->getBody()) + ")";
     76        return "If(" + print(ifstmt->getCondition()) + "," + print(ifstmt->getBody()) + ")";
    8577    }
    8678    else if (const While * whl = dyn_cast<const While>(stmt)) {
    87         return "While(" + ShowPabloAST(whl->getCondition()) + ", " + Print_PB_PabloStmts(whl->getBody()) + ")";
     79        return "While(" + print(whl->getCondition()) + "," + print(whl->getBody()) + ")";
    8880    }
    8981    return "???";
    9082}
    9183
    92 std::string StatementPrinter::ShowPabloAST(const PabloAST *expr) {
     84std::string PabloPrinter::print(const PabloAST *expr) {
    9385    if (isa<const Zeroes>(expr)) {
    9486        return "Zeroes";
     
    10496    }
    10597    else if (const And * pablo_and = dyn_cast<const And>(expr)) {
    106         return "And(" + ShowPabloAST(pablo_and->getExpr1()) +", " + ShowPabloAST(pablo_and->getExpr2()) + ")";
     98        return "And(" + print(pablo_and->getExpr1()) +"," + print(pablo_and->getExpr2()) + ")";
    10799    }
    108100    else if (const Or * pablo_or = dyn_cast<const Or>(expr)) {
    109         return "Or(" + ShowPabloAST(pablo_or->getExpr1()) + ", " + ShowPabloAST(pablo_or->getExpr2()) + ")";
     101        return "Or(" + print(pablo_or->getExpr1()) + "," + print(pablo_or->getExpr2()) + ")";
    110102    }
    111103    else if (const Sel * pablo_sel = dyn_cast<const Sel>(expr)) {
    112         return "((" + ShowPabloAST(pablo_sel->getCondition()) + "And " + ShowPabloAST(pablo_sel->getTrueExpr()) +
    113                 ")|(Not(" + ShowPabloAST(pablo_sel->getCondition()) + ") And " + ShowPabloAST(pablo_sel->getFalseExpr()) + ")";
     104        return "(" + print(pablo_sel->getCondition()) + " ? " + print(pablo_sel->getTrueExpr()) + " : " + print(pablo_sel->getFalseExpr()) + ")";
    114105    }
    115106    else if (const Not * pablo_not = dyn_cast<const Not>(expr)) {
    116         return "Not (" + ShowPabloAST(pablo_not->getExpr()) + ")";
     107        return "Not (" + print(pablo_not->getExpr()) + ")";
    117108    }
    118109    else if (const Advance * adv = dyn_cast<const Advance>(expr)) {
    119         return "Advance(" + ShowPabloAST(adv->getExpr()) + ", " + std::to_string(adv->getAdvanceAmount()) + ")";
     110        return "Advance(" + print(adv->getExpr()) + ", " + std::to_string(adv->getAdvanceAmount()) + ")";
    120111    }
    121112    else if (const MatchStar * mstar = dyn_cast<const MatchStar>(expr)) {
    122         return "MatchStar (" + ShowPabloAST(mstar->getMarker()) + ", " + ShowPabloAST(mstar->getCharClass()) + ")";
     113        return "MatchStar(" + print(mstar->getMarker()) + ", " + print(mstar->getCharClass()) + ")";
    123114    }
    124115    else if (const ScanThru * sthru = dyn_cast<const ScanThru>(expr)) {
    125         return "ScanThru (" + ShowPabloAST(sthru->getScanFrom()) + ", " + ShowPabloAST(sthru->getScanThru()) + ")";
     116        return "ScanThru(" + print(sthru->getScanFrom()) + ", " + print(sthru->getScanThru()) + ")";
    126117    }
    127118    return "???";
  • icGREP/icgrep-devel/icgrep/pablo/printer_pablos.h

    r4264 r4276  
    1515}
    1616
    17 class StatementPrinter {
     17class PabloPrinter {
    1818public:
    19     static std::string PrintStmts(const pablo::PabloBlock & cg_state);
    20     static std::string Print_CC_PabloStmts(const pablo::StatementList & stmts);
    21     static std::string Print_PB_PabloStmts(const pablo::StatementList & stmts);
    22     static std::string ShowPabloAST(const pablo::PabloAST * expr);
    23     static std::string ShowPabloS(const pablo::PabloAST *stmt);
     19    static std::string print(const pablo::PabloBlock & block);
     20    static std::string print(const pablo::StatementList & stmts);
     21    static std::string print(const pablo::PabloAST * expr);
     22    static std::string print(const pablo::Statement *stmt);
    2423};
    2524
  • icGREP/icgrep-devel/icgrep/pablo/ps_assign.h

    r4272 r4276  
    1212namespace pablo {
    1313
    14 class Assign : public PabloAST {
     14class Assign : public Statement {
    1515    friend class PabloBlock;
    1616    friend class Next;
     
    4141    }
    4242    Assign(PabloAST * name, PabloAST * expr, const int outputIndex)
    43     : PabloAST(ClassTypeId::Assign)
     43    : Statement(ClassTypeId::Assign)
    4444    , mName(cast<String>(name))
    4545    , mExpr(expr)
  • icGREP/icgrep-devel/icgrep/pablo/ps_if.h

    r4272 r4276  
    1212namespace pablo {
    1313
    14 class If : public PabloAST {
     14class If : public Statement {
    1515    friend class PabloBlock;
    1616public:
     
    2525    inline PabloAST * getCondition() const {
    2626        return mExpr;
     27    }
     28    inline StatementList & getBody() {
     29        return mBody;
    2730    }
    2831    inline const StatementList & getBody() const {
     
    4043    }
    4144    If(PabloAST * expr, StatementList && body)
    42     : PabloAST(ClassTypeId::If)
     45    : Statement(ClassTypeId::If)
    4346    , mExpr(expr)
    4447    , mBody(std::move(body))
  • icGREP/icgrep-devel/icgrep/pablo/ps_while.h

    r4272 r4276  
    1212namespace pablo {
    1313
    14 class While : public PabloAST {
     14class While : public Statement {
    1515    friend class PabloBlock;
    1616public:
     
    2525    inline PabloAST * getCondition() const {
    2626        return mExpr;
     27    }
     28    inline StatementList & getBody() {
     29        return mBody;
    2730    }
    2831    inline const StatementList & getBody() const {
     
    4043    }
    4144    While(PabloAST * expr, StatementList && body)
    42     : PabloAST(ClassTypeId::While)
     45    : Statement(ClassTypeId::While)
    4346    , mExpr(expr)
    4447    , mBody(std::move(body))
Note: See TracChangeset for help on using the changeset viewer.