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

Progress on parenthesis matching example

File:
1 edited

Legend:

Unmodified
Added
Removed
  • 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);
Note: See TracChangeset for help on using the changeset viewer.