Changeset 4433


Ignore:
Timestamp:
Jan 22, 2015, 3:04:10 PM (4 years ago)
Author:
nmedfort
Message:

Possible fix for segfault issue. CC seems to be generating the same charclass multiple times.

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

Legend:

Unmodified
Added
Removed
  • icGREP/icgrep-devel/icgrep/icgrep-devel.files

    r4284 r4433  
    227227pablo/ps_if.cpp
    228228pablo/pe_metadata.h
     229CMakeLists.txt
     230compiler.cpp
     231compiler.h
     232do_grep.cpp
     233do_grep.h
     234hrtime.h
     235icgrep.cpp
     236icgrep.h
     237icgrep-devel.config
     238icgrep-devel.creator
     239icgrep-devel.creator.user
     240icgrep-devel.files
     241icgrep-devel.includes
     242resolve_properties.cpp
     243slab_allocator.h
     244utf8_encoder.cpp
     245utf8_encoder.h
     246utf_encoding.h
     247pablo/optimizers/pablo_automultiplexing.cpp
     248pablo/optimizers/pablo_automultiplexing.hpp
     249pablo/optimizers/pablo_simplifier.cpp
     250pablo/optimizers/pablo_simplifier.hpp
     251pablo/builder.hpp
     252pablo/codegenstate.cpp
     253pablo/codegenstate.h
     254pablo/expression_map.hpp
     255pablo/pablo_compiler.cpp
     256pablo/pablo_compiler.h
     257pablo/pabloAST.cpp
     258pablo/pabloAST.h
     259pablo/pe_advance.h
     260pablo/pe_and.cpp
     261pablo/pe_and.h
     262pablo/pe_call.h
     263pablo/pe_integer.h
     264pablo/pe_matchstar.h
     265pablo/pe_next.h
     266pablo/pe_not.cpp
     267pablo/pe_not.h
     268pablo/pe_ones.h
     269pablo/pe_or.cpp
     270pablo/pe_or.h
     271pablo/pe_scanthru.h
     272pablo/pe_sel.cpp
     273pablo/pe_sel.h
     274pablo/pe_string.h
     275pablo/pe_var.h
     276pablo/pe_xor.cpp
     277pablo/pe_xor.h
     278pablo/pe_zeroes.h
     279pablo/printer_pablos.cpp
     280pablo/printer_pablos.h
     281pablo/ps_assign.cpp
     282pablo/ps_assign.h
     283pablo/ps_if.cpp
     284pablo/ps_if.h
     285pablo/ps_while.cpp
     286pablo/ps_while.h
     287pablo/symbol_generator.cpp
     288pablo/symbol_generator.h
  • icGREP/icgrep-devel/icgrep/icgrep-devel.includes

    r4268 r4433  
    44pablo
    55pablo/analysis
     6pablo/optimizers
  • icGREP/icgrep-devel/icgrep/pablo/codegenstate.cpp

    r4432 r4433  
    1212
    1313Assign * PabloBlock::createAssign(const std::string prefix, PabloAST * expr, const int outputIndex)  {
    14     return insertAtInsertionPoint(new Assign(expr, outputIndex, mSymbolGenerator->make(prefix), this));
     14    return insertAtInsertionPoint(new Assign(expr, outputIndex, makeName(prefix, false), this));
    1515}
    1616
     
    3030
    3131Call * PabloBlock::createCall(String * name) {
     32    assert (name);
    3233    return insertAtInsertionPoint(new Call(name, this));
    3334}
    3435
    3536PabloAST * PabloBlock::createNot(PabloAST * expr) {
     37    assert (expr);
    3638    if (isa<Ones>(expr)) {
    3739        return createZeroes();
     
    4749
    4850Var * PabloBlock::createVar(String * name) {
     51    assert (name);
    4952    return insertAtInsertionPoint(new Var(name, this));
    5053}
     
    5356
    5457Next * PabloBlock::createNext(Assign * assign, PabloAST * expr) {
     58    assert (assign && expr);
    5559    return insertAtInsertionPoint(new Next(assign, expr, this));
    5660}
    5761
    5862PabloAST * PabloBlock::createMatchStar(PabloAST * marker, PabloAST * charclass) {
     63    assert (marker && charclass);
    5964    if (isa<Zeroes>(marker) || isa<Zeroes>(charclass)) {
    6065        return marker;
     
    6469
    6570PabloAST * PabloBlock::createScanThru(PabloAST * from, PabloAST * thru) {
     71    assert (from && thru);
    6672    if (isa<Zeroes>(from) || isa<Zeroes>(thru)) {
    6773        return from;
     
    7177
    7278PabloAST * PabloBlock::createAnd(PabloAST * expr1, PabloAST * expr2) {
     79    assert (expr1 && expr2);
    7380    if (isa<Zeroes>(expr2) || isa<Ones>(expr1)) {
    7481        return expr2;
     
    101108
    102109PabloAST * PabloBlock::createOr(PabloAST * expr1, PabloAST * expr2) {
     110    assert (expr1 && expr2);
    103111    if (isa<Zeroes>(expr2) || isa<Ones>(expr1)) {
    104112        return expr1;
     
    147155
    148156PabloAST * PabloBlock::createXor(PabloAST * expr1, PabloAST * expr2) {
     157    assert (expr1 && expr2);
    149158    if (isa<Ones>(expr1)) {
    150159        return createNot(expr2);
     
    170179
    171180PabloAST * PabloBlock::createSel(PabloAST * condition, PabloAST * trueExpr, PabloAST * falseExpr) {
    172     assert (condition && trueExpr && falseExpr && pb);
     181    assert (condition && trueExpr && falseExpr);
    173182
    174183    if (isa<Ones>(condition)) {
     
    203212
    204213If * PabloBlock::createIf(PabloAST * condition, std::vector<Assign *> && definedVars, PabloBlock & body) {
     214    assert (condition);
    205215    return insertAtInsertionPoint(new If(condition, std::move(definedVars), body, this));
    206216}
    207217
    208 While * PabloBlock::createWhile(PabloAST * cond, PabloBlock & body) {
    209     return insertAtInsertionPoint(new While(cond, body, this));
     218While * PabloBlock::createWhile(PabloAST * condition, PabloBlock & body) {
     219    assert (condition);
     220    return insertAtInsertionPoint(new While(condition, body, this));
    210221}
    211222
  • icGREP/icgrep-devel/icgrep/pablo/codegenstate.h

    r4432 r4433  
    9191
    9292    inline Call * createCall(const std::string name) {
    93         return createCall(getName(name));
     93        return createCall(getName(name, false));
    9494    }
    9595
     
    9999
    100100    inline Var * createVar(const std::string name) {
    101         return createVar(getName(name));
     101        return createVar(getName(name, false));
    102102    }
    103103
     
    126126    If * createIf(PabloAST * condition, std::vector<Assign *> && definedVars, PabloBlock & body);
    127127
    128     While * createWhile(PabloAST * cond, PabloBlock & body);
     128    While * createWhile(PabloAST * condition, PabloBlock & body);
    129129
    130130    inline StatementList & statements() {
     
    136136    }
    137137
    138     inline String * getName(const std::string name) const {
    139         return mSymbolGenerator->get(name);
     138    inline String * getName(const std::string name, const bool generated = true) const {
     139        return mSymbolGenerator->get(name, generated);
    140140    }
    141141
    142     inline String * makeName(const std::string prefix) const {
    143         return mSymbolGenerator->make(prefix);
     142    inline String * makeName(const std::string prefix, const bool generated = true) const {
     143        return mSymbolGenerator->make(prefix, generated);
    144144    }
    145145
  • icGREP/icgrep-devel/icgrep/pablo/optimizers/pablo_simplifier.cpp

    r4432 r4433  
    2828}
    2929
     30#ifndef NDEBUG
     31static bool verifyStatementIsInSameBlock(const Statement * const stmt, const PabloBlock & block) {
     32    Statement * curr = block.front();
     33    while (curr) {
     34        if (curr == stmt) {
     35            return true;
     36        }
     37        curr = curr->getNextNode();
     38    }
     39    return false;
     40}
     41#endif
    3042
    3143void Simplifier::eliminateRedundantCode(PabloBlock & block, ExpressionTable * predecessor) {
     
    3345
    3446    Statement * stmt = block.front();
     47
    3548    while (stmt) {
    36         if (isa<Assign>(stmt)) {
    37             Assign * assign = cast<Assign>(stmt);
     49
     50        assert (stmt);
     51        assert (verifyStatementIsInSameBlock(stmt, block));
     52
     53        if (Assign * assign = dyn_cast<Assign>(stmt)) {
    3854            // If we have an Assign whose users do not contain an If or Next node, we can replace its users with
    39             // the Assign's expression directly. However, since Assigns were likely named for clarity, propagate
    40             // it's name upwards into the expression's statement.
    41             if (assign->isConstant()) {
    42                 PabloAST * expr = assign->getExpr();
    43                 if (isa<Statement>(expr)) {
    44                     cast<Statement>(expr)->setName(assign->getName());
    45                 }
    46                 assign->replaceAllUsesWith(expr);
    47                 // Note: we cannot delete recursively yet because our "encountered" table may would not be
    48                 // updated properly. The dead code elimination pass will perform any final clean-up.
    49                 stmt = assign->eraseFromParent();
     55            // the Assign's expression directly.
     56            if (assign->superfluous()) {
     57                stmt = (stmt->getNumUses() == 0) ? assign->eraseFromParent() : assign->replaceWith(assign->getExpr());
    5058                continue;
    5159            }
    5260        }
    53         else { // non-Assign node
     61        else if (isa<If>(stmt)) {
     62            eliminateRedundantCode(cast<If>(stmt)->getBody(), &encountered);
     63        }
     64        else if (isa<While>(stmt)) {
     65            eliminateRedundantCode(cast<While>(stmt)->getBody(), &encountered);
     66        }       
     67        else if (stmt->getNumUses() == 0) {
     68            // If this statement has no users, we can discard it. If a future "identical" statement occurs that does
     69            // have users, we can use that statement instead.
     70            stmt = stmt->eraseFromParent();
     71            continue;
     72        }
     73        else if (canTriviallyFold(stmt)) { // non-Assign node
    5474
    5575            // Do a trivial folding test to see if we're using all 0s or 1s as an operand.
    56             if (canTriviallyFold(stmt)) {
    57                 PabloAST * expr = nullptr;
    58                 block.setInsertPoint(stmt->getPrevNode());
    59                 switch (stmt->getClassTypeId()) {
    60                     case PabloAST::ClassTypeId::Advance:
    61                         expr = block.createAdvance(stmt->getOperand(0), stmt->getOperand(1));
    62                         break;
    63                     case PabloAST::ClassTypeId::And:
    64                         expr = block.createAnd(stmt->getOperand(0), stmt->getOperand(1));
    65                         break;
    66                     case PabloAST::ClassTypeId::Or:
    67                         expr = block.createOr(stmt->getOperand(0), stmt->getOperand(1));
    68                         break;
    69                     case PabloAST::ClassTypeId::Not:
    70                         expr = block.createNot(stmt->getOperand(0));
    71                         break;
    72                     case PabloAST::ClassTypeId::Xor:
    73                         expr = block.createXor(stmt->getOperand(0), stmt->getOperand(1));
    74                         break;
    75                     case PabloAST::ClassTypeId::Sel:
    76                         expr = block.createSel(stmt->getOperand(0), stmt->getOperand(1), stmt->getOperand(2));
    77                         break;
    78                     case PabloAST::ClassTypeId::ScanThru:
    79                         expr = block.createScanThru(stmt->getOperand(0), stmt->getOperand(1));
    80                         break;
    81                     case PabloAST::ClassTypeId::MatchStar:
    82                         expr = block.createMatchStar(stmt->getOperand(0), stmt->getOperand(1));
    83                         break;
    84                     default:
    85                         throw std::runtime_error("Unhandled trivial folding optimization!");
    86                 }
    87                 assert (expr);
    88                 stmt = stmt->replaceWith(expr);               
    89                 // the next statement could be an Assign; just restart the loop.
    90                 continue;
     76            PabloAST * expr = nullptr;
     77            block.setInsertPoint(stmt->getPrevNode());
     78            switch (stmt->getClassTypeId()) {
     79                case PabloAST::ClassTypeId::Advance:
     80                    expr = block.createAdvance(stmt->getOperand(0), stmt->getOperand(1));
     81                    break;
     82                case PabloAST::ClassTypeId::And:
     83                    expr = block.createAnd(stmt->getOperand(0), stmt->getOperand(1));
     84                    break;
     85                case PabloAST::ClassTypeId::Or:
     86                    expr = block.createOr(stmt->getOperand(0), stmt->getOperand(1));
     87                    break;
     88                case PabloAST::ClassTypeId::Not:
     89                    expr = block.createNot(stmt->getOperand(0));
     90                    break;
     91                case PabloAST::ClassTypeId::Xor:
     92                    expr = block.createXor(stmt->getOperand(0), stmt->getOperand(1));
     93                    break;
     94                case PabloAST::ClassTypeId::Sel:
     95                    expr = block.createSel(stmt->getOperand(0), stmt->getOperand(1), stmt->getOperand(2));
     96                    break;
     97                case PabloAST::ClassTypeId::ScanThru:
     98                    expr = block.createScanThru(stmt->getOperand(0), stmt->getOperand(1));
     99                    break;
     100                case PabloAST::ClassTypeId::MatchStar:
     101                    expr = block.createMatchStar(stmt->getOperand(0), stmt->getOperand(1));
     102                    break;
     103                default:
     104                    throw std::runtime_error("Unhandled trivial folding optimization!");
    91105            }
    92             else if (isa<If>(stmt)) {
    93                 eliminateRedundantCode(cast<If>(stmt)->getBody(), &encountered);
    94             }
    95             else if (isa<While>(stmt)) {
    96                 eliminateRedundantCode(cast<While>(stmt)->getBody(), &encountered);
    97             }
    98             else if (stmt->getNumUses() == 0) {
    99                 // If this statement has no users, we can discard it. If a future "identical" statement occurs that does
    100                 // have users, we can use that statement instead.
    101                 stmt = stmt->eraseFromParent();
    102                 continue;
    103             }
    104             else {
    105                 // When we're creating the Pablo program, it's possible to have multiple instances of an "identical"
    106                 // statement. By recording which statements have already been seen, we can detect the redundant statements
    107                 // as any having the same type and operands. If so, we can replace its users with the prior statement.
    108                 // and erase this statement from the AST
    109                 const auto f = encountered.insert(stmt);
    110                 if (!std::get<1>(f)) {
    111                     stmt->replaceAllUsesWith(std::get<0>(f));
    112                     stmt = stmt->eraseFromParent();
    113                     continue;
    114                 }
    115             }
     106            stmt = stmt->replaceWith(expr);
     107            // the next statement could be an Assign; just restart the loop.
     108            continue;
    116109        }
     110
     111        // When we're creating the Pablo program, it's possible to have multiple instances of an "identical"
     112        // statement. By recording which statements have already been seen, we can detect the redundant statements
     113        // as any having the same type and operands. If so, we can replace its users with the prior statement.
     114        // and erase this statement from the AST
     115        const auto f = encountered.insert(stmt);
     116        if (!std::get<1>(f)) {
     117            stmt = stmt->replaceWith(std::get<0>(f));
     118            continue;
     119        }
     120
     121        assert (stmt);
    117122        stmt = stmt->getNextNode();
    118123    }
  • icGREP/icgrep-devel/icgrep/pablo/pabloAST.cpp

    r4432 r4433  
    8181
    8282void PabloAST::replaceAllUsesWith(PabloAST * expr) {
     83    assert (expr);
    8384    while (!mUsers.empty()) {
    8485        PabloAST * user = mUsers.pop_back_val();
     
    188189}
    189190
    190 Statement * Statement::replaceWith(PabloAST * const expr) {
     191Statement * Statement::replaceWith(PabloAST * const expr, const bool rename) {
     192    assert (expr);
    191193    if (LLVM_UNLIKELY(expr == this)) {
    192194        return getNextNode();
     195    }
     196    if (LLVM_LIKELY(rename && isa<Statement>(expr))) {
     197        Statement * const stmt = cast<Statement>(expr);
     198        if (getName()->isUserDefined() && stmt->getName()->isGenerated()) {
     199            stmt->setName(getName());
     200        }
    193201    }
    194202    replaceAllUsesWith(expr);
  • icGREP/icgrep-devel/icgrep/pablo/pabloAST.h

    r4432 r4433  
    9494
    9595    }
    96     inline void addUser(PabloAST * user) {       
     96    inline void addUser(PabloAST * user) {
     97        assert (user);
    9798        mUsers.insert(user);
    9899    }
    99100    inline void removeUser(PabloAST * user) {
     101        assert (user);
    100102        mUsers.remove(user);
    101103    }
     
    164166    Statement * removeFromParent();
    165167    Statement * eraseFromParent(const bool recursively = false);
    166     Statement * replaceWith(PabloAST * const expr);
     168    Statement * replaceWith(PabloAST * const expr, const bool rename = true);
    167169
    168170    inline const String * getName() const {
  • icGREP/icgrep-devel/icgrep/pablo/pablo_compiler.cpp

    r4422 r4433  
    166166    compileStatements(pb.statements());
    167167
    168     assert (mCarryQueueIdx == mCarryQueueSize);
    169     assert (mAdvanceQueueIdx == mAdvanceQueueSize);
    170     assert (mNestingDepth == 0);
     168    if (LLVM_UNLIKELY(mCarryQueueIdx != mCarryQueueSize)) {
     169        throw std::runtime_error("Actual carry queue size (" + std::to_string(mCarryQueueIdx) + ") does not match expected (" + std::to_string(mCarryQueueSize) + ")");
     170    }
     171    if (LLVM_UNLIKELY(mAdvanceQueueIdx != mAdvanceQueueSize)) {
     172        throw std::runtime_error("Actual advance queue size (" + std::to_string(mAdvanceQueueIdx) + ") does not match expected (" + std::to_string(mAdvanceQueueSize) + ")");
     173    }
     174    if (LLVM_UNLIKELY(mNestingDepth != 0)) {
     175        throw std::runtime_error("Non-zero nesting depth error (" + std::to_string(mNestingDepth) + ")");
     176    }
     177
    171178    //Terminate the block
    172179    ReturnInst::Create(mMod->getContext(), mBasicBlock);
    173180
    174181    //Display the IR that has been generated by this module.
    175     if (DumpGeneratedIR) {
    176       mMod->dump();
    177     }
    178 
    179 
    180 
     182    if (LLVM_UNLIKELY(DumpGeneratedIR)) {
     183        mMod->dump();
     184    }
    181185    //Create a verifier.  The verifier will print an error message if our module is malformed in any way.
    182186    #ifdef USE_LLVM_3_5
     
    204208    LLVM_Gen_RetVal retVal;
    205209    //Return the required size of the carry queue and a pointer to the process_block function.
    206     retVal.carry_q_size = mCarryQueueVector.size();
    207     retVal.advance_q_size = mAdvanceQueueVector.size();
     210    retVal.carry_q_size = mCarryQueueSize;
     211    retVal.advance_q_size = mAdvanceQueueSize;
    208212    retVal.process_block_fptr = mExecutionEngine->getPointerToFunction(mFunction);
    209213
     
    421425void PabloCompiler::Examine(StatementList & stmts) {
    422426    for (Statement * stmt : stmts) {
    423         if (Assign * assign = dyn_cast<Assign>(stmt)) {
    424             Examine(assign->getExpr());
    425         }
    426         if (Next * next = dyn_cast<Next>(stmt)) {
    427             Examine(next->getExpr());
     427
     428        if (Advance * adv = dyn_cast<Advance>(stmt)) {
     429            mAdvanceQueueSize += (((adv->getAdvanceAmount() - 1) / BLOCK_SIZE) + 1);
     430        }
     431        else if (isa<MatchStar>(stmt) || isa<ScanThru>(stmt)) {
     432            ++mCarryQueueSize;
     433        }
     434        if (Call * call = dyn_cast<Call>(stmt)) {
     435            mCalleeMap.insert(std::make_pair(call->getCallee(), nullptr));
    428436        }
    429437        else if (If * ifStatement = dyn_cast<If>(stmt)) {
    430438            const auto preIfCarryCount = mCarryQueueSize;
    431439            const auto preIfAdvanceCount = mAdvanceQueueSize;
    432             Examine(ifStatement->getCondition());
    433440            Examine(ifStatement->getBody());
    434441            int ifCarryCount = mCarryQueueSize - preIfCarryCount;
     
    444451            const auto preWhileCarryCount = mCarryQueueSize;
    445452            const auto preWhileAdvanceCount = mAdvanceQueueSize;
    446             Examine(whileStatement->getCondition());
    447453            mMaxNestingDepth = std::max(mMaxNestingDepth, ++mNestingDepth);
    448454            Examine(whileStatement->getBody());
     
    451457            whileStatement->setInclusiveAdvanceCount(mAdvanceQueueSize - preWhileAdvanceCount);
    452458        }
    453     }
    454 }
    455 
    456 void PabloCompiler::Examine(PabloAST *expr)
    457 {
    458     if (Call * call = dyn_cast<Call>(expr)) {
    459         mCalleeMap.insert(std::make_pair(call->getCallee(), nullptr));
    460     }
    461     else if (And * pablo_and = dyn_cast<And>(expr)) {
    462         Examine(pablo_and->getExpr1());
    463         Examine(pablo_and->getExpr2());
    464     }
    465     else if (Or * pablo_or = dyn_cast<Or>(expr)) {
    466         Examine(pablo_or->getExpr1());
    467         Examine(pablo_or->getExpr2());
    468     }
    469     else if (Xor * pablo_xor = dyn_cast<Xor>(expr)) {
    470         Examine(pablo_xor->getExpr1());
    471         Examine(pablo_xor->getExpr2());
    472     }
    473     else if (Sel * pablo_sel = dyn_cast<Sel>(expr)) {
    474         Examine(pablo_sel->getCondition());
    475         Examine(pablo_sel->getTrueExpr());
    476         Examine(pablo_sel->getFalseExpr());
    477     }
    478     else if (Not * pablo_not = dyn_cast<Not>(expr)) {
    479         Examine(pablo_not->getExpr());
    480     }
    481     else if (Advance * adv = dyn_cast<Advance>(expr)) {
    482         int shift_amount = adv->getAdvanceAmount();
    483         int advEntries = (shift_amount - 1) / BLOCK_SIZE + 1;
    484         mAdvanceQueueSize += advEntries;
    485         Examine(adv->getExpr());
    486     }
    487     else if (MatchStar * mstar = dyn_cast<MatchStar>(expr)) {
    488         ++mCarryQueueSize;
    489         Examine(mstar->getMarker());
    490         Examine(mstar->getCharClass());
    491     }
    492     else if (ScanThru * sthru = dyn_cast<ScanThru>(expr)) {
    493         ++mCarryQueueSize;
    494         Examine(sthru->getScanFrom());
    495         Examine(sthru->getScanThru());
    496459    }
    497460}
  • icGREP/icgrep-devel/icgrep/pablo/pablo_compiler.h

    r4421 r4433  
    7979    void DeclareFunctions();
    8080    void Examine(StatementList & stmts);
    81     void Examine(PabloAST * expr);
    8281    void DeclareCallFunctions();
    8382    void SetOutputValue(Value * marker, const unsigned index);
  • icGREP/icgrep-devel/icgrep/pablo/pe_string.h

    r4416 r4433  
    2525        return mValue;
    2626    }
     27    inline bool isGenerated() const {
     28        return mGenerated;
     29    }
     30    inline bool isUserDefined() const {
     31        return !mGenerated;
     32    }
    2733protected:
    28     String(const std::string && value) noexcept
     34    String(const std::string && value, const bool generated) noexcept
    2935    : PabloAST(ClassTypeId::String)
    3036    , mValue(value)
     37    , mGenerated(generated)
    3138    {
    3239
    3340    }
    3441private:
    35     const std::string mValue;
     42    const std::string   mValue;
     43    const bool          mGenerated;
    3644};
    3745
  • icGREP/icgrep-devel/icgrep/pablo/printer_pablos.cpp

    r4416 r4433  
    154154}
    155155
    156 void PabloPrinter::print(const PabloAST *expr, std::ostream & strm) {
     156void PabloPrinter::print(const PabloAST * expr, std::ostream & strm) {
    157157    if (expr == nullptr) {
    158158        strm << "<null-expr>";
     
    164164        strm << "1";
    165165    }
    166     else if (const Var * pablo_var = dyn_cast<const Var>(expr)) {
    167         strm << pablo_var->getName()->str();
     166    else if (const Var * var = dyn_cast<const Var>(expr)) {
     167        strm << var->getName()->str();
    168168    }
    169     else if (isa<Statement>(expr)) {
    170         strm << cast<Statement>(expr)->getName()->str();
     169    else if (const Statement * stmt = dyn_cast<Statement>(expr)) {
     170        strm << stmt->getName()->str();
    171171    }
    172172    else {
  • icGREP/icgrep-devel/icgrep/pablo/ps_assign.cpp

    r4432 r4433  
    55namespace pablo {
    66
    7 bool Assign::isConstant() const {
     7bool Assign::superfluous() const {
    88    if (LLVM_UNLIKELY(isOutputAssignment())) {
     9        // If this Assign is an assignment to an output variable, it cannot be superfluous.
    910        return false;
    1011    }
    11     for (const PabloAST * inst : users()) {
     12    for (const PabloAST * inst : users()) {       
    1213        if (isa<Next>(inst)) {
     14            // If this Assign has a Next node, it cannot be superfluous.
    1315            return false;
    1416        }
    1517        if (isa<If>(inst)) {
    16             // if this Assign is the condition of an If node but not a defined var,
    17             // then this Assign is a "constant".
    18             if (cast<If>(inst)->getCondition() == this) {
    19                 const auto & dv = cast<If>(inst)->getDefined();
    20                 if (LLVM_LIKELY(std::find(dv.begin(), dv.end(), this) == dv.end())) {
    21                     continue;
    22                 }
     18            // If this Assign is a defined variable of an If node, it cannot be superfluous.
     19            const auto & dv = cast<If>(inst)->getDefined();
     20            if (LLVM_UNLIKELY(std::find(dv.begin(), dv.end(), this) != dv.end())) {
     21                return false;
    2322            }
    24             return false;
    2523        }
    2624    }
  • icGREP/icgrep-devel/icgrep/pablo/ps_assign.h

    r4432 r4433  
    3434        return mOutputIndex;
    3535    }
    36     bool isConstant() const;
     36    bool superfluous() const;
    3737protected:
    3838    explicit Assign(PabloAST * expr, int outputIndex, String * name, PabloBlock * parent)
  • icGREP/icgrep-devel/icgrep/pablo/symbol_generator.cpp

    r4432 r4433  
    1717}
    1818
    19 String * SymbolGenerator::get(const std::string name) {
     19String * SymbolGenerator::get(const std::string name, const bool generated) {
    2020    auto f = mStringMap.find(name);
    2121    String * result;
    2222    if (f == mStringMap.end()) {
    23         result = new String(std::move(name));
     23        result = new String(std::move(name), generated);
    2424        mStringMap.insert(std::make_pair(name, result));
    2525    }
     
    4444}
    4545
    46 String * SymbolGenerator::make(const std::string prefix) {
     46String * SymbolGenerator::make(const std::string prefix, const bool generated) {
    4747    auto f = mPrefixMap.find(prefix);
    4848    unsigned count = 0;
    4949    if (f == mPrefixMap.end()) {
    5050        mPrefixMap.insert(std::make_pair(prefix, 1));
    51         return get(prefix);
     51        return get(prefix, generated);
    5252    }
    5353    else {
    5454        count = f->second++;
    55         return get(prefix + std::to_string(count));
     55        return get(prefix + std::to_string(count), generated);
    5656    }
    5757}
  • icGREP/icgrep-devel/icgrep/pablo/symbol_generator.h

    r4432 r4433  
    2121public:
    2222    typedef u_int64_t integer_t;
    23     String * get(const std::string name);
    24     String * make(const std::string prefix);
     23    String * get(const std::string name, const bool generated = true);
     24    String * make(const std::string prefix, const bool generated = true);
    2525    Integer * getInteger(const integer_t value);
    2626    ~SymbolGenerator();
Note: See TracChangeset for help on using the changeset viewer.