Ignore:
Timestamp:
Mar 1, 2017, 4:17:24 PM (3 years ago)
Author:
nmedfort
Message:

Progress on parenthesis matching example

Location:
icGREP/icgrep-devel/icgrep/pablo
Files:
4 edited

Legend:

Unmodified
Added
Removed
  • icGREP/icgrep-devel/icgrep/pablo/carry_data.h

    r5347 r5353  
    3434    CarryData()
    3535    : summaryType(NoSummary)   
    36     , variableLength(false)
    37     {
     36    , carryCollapsingMode(false) {
    3837
    3938    }
     
    5554    }
    5655
    57     bool hasVariableLength() const {
    58         return variableLength;
     56    bool nonCarryCollapsingMode() const {
     57        return carryCollapsingMode;
    5958    }
    6059
     60    void setNonCarryCollapsingMode(const bool value = true) {
     61        carryCollapsingMode = value;
     62    }
    6163   
    6264protected:
    6365
    6466    SummaryType             summaryType;
    65     bool                    variableLength;
     67    bool                    carryCollapsingMode;
    6668
    6769};
  • icGREP/icgrep-devel/icgrep/pablo/carry_manager.cpp

    r5347 r5353  
    149149    }
    150150
    151     if (LLVM_UNLIKELY(mCarryInfo->hasVariableLength())) {
     151    if (LLVM_UNLIKELY(mCarryInfo->nonCarryCollapsingMode())) {
    152152        // Check whether we need to resize the carry state
    153153        PHINode * index = iBuilder->CreatePHI(iBuilder->getSizeTy(), 2);
     
    183183        iBuilder->SetInsertPoint(cleanUpBlock);
    184184
    185 
    186 
    187185        iBuilder->CreateMemCpy(newArray, array, iBuilder->CreateMul(capacity, carryStateWidth), iBuilder->getCacheAlignment());
    188186        iBuilder->CreateAlignedFree(array);
     
    218216        mCarrySummary.pop_back();
    219217    }
    220     if (LLVM_UNLIKELY(mCarryInfo->hasVariableLength())) {
     218    if (LLVM_UNLIKELY(mCarryInfo->nonCarryCollapsingMode())) {
    221219        assert (!mLoopIndicies.empty());
    222220        PHINode * index = mLoopIndicies.back();
     
    249247Value * CarryManager::generateSummaryTest(Value * condition) {
    250248    if (LLVM_LIKELY(mCarryInfo->hasSummary())) {
    251         ConstantInt * zero = iBuilder->getInt32(0);
    252         std::vector<Value *> indicies;
    253249        // enter the (potentially nested) struct and extract the summary element (always element 0)
    254250        unsigned count = 2;
     
    261257            }
    262258        }
    263         indicies.assign(count, zero);
    264         if (LLVM_UNLIKELY(mCarryInfo->hasImplicitSummary() && mLoopDepth > 0)) {
    265             indicies.push_back(zero);
    266             indicies.push_back(mLoopSelector);
    267         }
    268         Value * ptr = iBuilder->CreateGEP(mCurrentFrame, indicies);
     259        const bool useLoopSelector = mCarryInfo->hasImplicitSummary() && mLoopDepth > 0;
     260        const auto length = count + (useLoopSelector ? 2 : 0);
     261        Value * indicies[length];
     262        std::fill(indicies, indicies + (count + (useLoopSelector ? 1 : 0)), iBuilder->getInt32(0));
     263        if (LLVM_UNLIKELY(useLoopSelector)) {
     264            indicies[count + 1] = mLoopSelector;
     265        }
     266        ArrayRef<Value *> ar(indicies, length);
     267        Value * ptr = iBuilder->CreateGEP(mCurrentFrame, ar);
    269268        // Sanity check: make sure we're accessing a summary value
    270269        assert (ptr->getType()->getPointerElementType()->canLosslesslyBitCastTo(condition->getType()));
     
    334333    mCarryScopeIndex.push_back(++mCarryScopes);
    335334    mCarryInfo = &mCarryMetadata[mCarryScopes];
    336     // Check whether we're still within our struct bounds; if this fails, either the Pablo program changed within
     335    // Check whether we're still within our struct bounds; if this fails, either the Pablo program changed during
    337336    // compilation or a memory corruption has occured.
    338337    assert (mCurrentFrameIndex < mCurrentFrame->getType()->getPointerElementType()->getStructNumElements());
     
    535534 ** ------------------------------------------------------------------------------------------------------------- */
    536535bool CarryManager::inCollapsingCarryMode() const {
    537     return (mCurrentScope->getBranch() && isa<While>(mCurrentScope->getBranch()) && !mCarryInfo->hasVariableLength());
     536    return (mCurrentScope->getBranch() && isa<While>(mCurrentScope->getBranch()) && !mCarryInfo->nonCarryCollapsingMode());
    538537}
    539538
     
    551550
    552551/** ------------------------------------------------------------------------------------------------------------- *
    553  * @brief requiresVariableLengthMode
    554  ** ------------------------------------------------------------------------------------------------------------- */
    555 bool CarryManager::requiresVariableLengthMode(const PabloBlock * const scope) {
     552 * @brief hasIterationSpecificAssignment
     553 ** ------------------------------------------------------------------------------------------------------------- */
     554bool CarryManager::hasIterationSpecificAssignment(const PabloBlock * const scope) {
    556555    if (const Branch * const br = scope->getBranch()) {
    557556        for (const Var * var : br->getEscaped()) {
     
    628627        carryState = StructType::get(iBuilder->getContext());
    629628    } else {
    630         cd.variableLength = loopDepth > 0 && requiresVariableLengthMode(scope);
     629        cd.setNonCarryCollapsingMode(loopDepth > 0 && hasIterationSpecificAssignment(scope));
    631630        if (ifDepth > 0) {
    632631            // A non-collapsing loop requires a unique summary for each iteration. Thus whenever
     
    646645        carryState = StructType::get(iBuilder->getContext(), state);
    647646        // If we in a loop and cannot use collapsing carry mode, convert the struct into a capacity and pointer pair.
    648         if (LLVM_UNLIKELY(cd.hasVariableLength())) {
     647        if (LLVM_UNLIKELY(cd.nonCarryCollapsingMode())) {
    649648            mHasVariableLengthCarryData = true;
    650649            carryState = StructType::get(iBuilder->getSizeTy(), carryState->getPointerTo(), nullptr);
  • icGREP/icgrep-devel/icgrep/pablo/carry_manager.h

    r5347 r5353  
    8484    static unsigned getScopeCount(PabloBlock * const scope, unsigned index = 0);
    8585
    86     static bool requiresVariableLengthMode(const PabloBlock * const scope);
     86    static bool hasIterationSpecificAssignment(const PabloBlock * const scope);
    8787
    8888    llvm::StructType * analyse(PabloBlock * const scope, const unsigned ifDepth = 0, const unsigned whileDepth = 0);
  • icGREP/icgrep-devel/icgrep/pablo/pablo_compiler.cpp

    r5351 r5353  
    211211
    212212    BasicBlock * whileEntryBlock = iBuilder->GetInsertBlock();
    213     BasicBlock * whileBodyBlock = mKernel->CreateBasicBlock("while.body");
    214     BasicBlock * whileEndBlock = mKernel->CreateBasicBlock("while.end");
    215213
    216214    const auto escaped = whileStatement->getEscaped();
     
    238236
    239237    mCarryManager->enterLoopScope(whileBody);
     238
     239    BasicBlock * whileBodyBlock = mKernel->CreateBasicBlock("while.body");
    240240
    241241    iBuilder->CreateBr(whileBodyBlock);
     
    290290    BasicBlock * const whileExitBlock = iBuilder->GetInsertBlock();
    291291
    292     mCarryManager->leaveLoopBody(whileExitBlock);
    293 
    294292    // Terminate the while loop body with a conditional branch back.
    295293    Value * condition = compileExpression(whileStatement->getCondition());
    296294    if (condition->getType() == iBuilder->getBitBlockType()) {
    297         condition = iBuilder->bitblock_any(condition);
    298     }
     295        condition = iBuilder->bitblock_any(mCarryManager->generateSummaryTest(condition));
     296    }
     297
     298    mCarryManager->leaveLoopBody(whileExitBlock);
     299
     300
    299301#ifdef ENABLE_BOUNDED_WHILE
    300302    if (whileStatement->getBound()) {
     
    338340    }
    339341
     342    BasicBlock * whileEndBlock = mKernel->CreateBasicBlock("while.end");
     343
    340344    iBuilder->CreateCondBr(condition, whileBodyBlock, whileEndBlock);
    341 
    342     whileEndBlock->moveAfter(whileExitBlock);
    343345
    344346    iBuilder->SetInsertPoint(whileEndBlock);
Note: See TracChangeset for help on using the changeset viewer.