Ignore:
Timestamp:
Feb 25, 2017, 12:50:29 PM (3 years ago)
Author:
nmedfort
Message:

Added enable asserts (-ea) command line flag + restructured BlockOrientedKernels? to allow for inlined code.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • icGREP/icgrep-devel/icgrep/pablo/carry_manager.cpp

    r5340 r5347  
    8585
    8686/** ------------------------------------------------------------------------------------------------------------- *
    87  * @brief allocateCarryData
    88  ** ------------------------------------------------------------------------------------------------------------- */
    89 void CarryManager::allocateCarryData(PabloKernel * const kernel) {
    90 //    mKernel = kernel;
    91 //    mCarryScopes = 0;
    92 //    mCarryScopeIndex.push_back(0);
    93 //    mCurrentFrame = kernel->getScalarFieldPtr("carries");
    94 //    allocateCarryData (mCurrentFrame->getType());
    95 }
    96 
    97 ///** ------------------------------------------------------------------------------------------------------------- *
    98 // * @brief allocateCarryData
    99 // ** ------------------------------------------------------------------------------------------------------------- */
    100 //void CarryManager::allocateCarryData(Type * const type) {
    101 //    assert (type->isStructTy());
    102 
    103 //    const auto scopeIndex = mCarryScopes++;
    104 
    105 //    const unsigned vl = mCarryMetadata[scopeIndex].variableLength ? 4 : 0;
    106 
    107 //    if (LLVM_UNLIKELY(vl != 0)) {
    108 
    109 
    110 //        ConstantInt * const capacity = iBuilder->getSize(vl);
    111 //        Value * capacityPtr = iBuilder->CreateGEP(mCurrentFrame, {iBuilder->getInt32(0), iBuilder->getInt32(0)});
    112 //        iBuilder->CreateStore(capacity, capacityPtr, false);
    113 //        Value * arrayPtr = iBuilder->CreateGEP(mCurrentFrame, {iBuilder->getInt32(0), iBuilder->getInt32(1)});
    114 //        Value * carryStateType = arrayPtr->getType()->getPointerElementType();
    115 //        Value * array = iBuilder->CreateAlignedMalloc(carryStateType, capacity, iBuilder->getCacheAlignment());
    116 //        Constant * typeWidth = ConstantExpr::getIntegerCast(ConstantExpr::getSizeOf(carryStateType), iBuilder->getSizeTy(), false);
    117 //        iBuilder->CreateMemZero(array, iBuilder->CreateMul(capacity, typeWidth), iBuilder->getCacheAlignment());
    118 //        iBuilder->CreateStore(array, arrayPtr, false);
    119 
    120 
    121 
    122 
    123 //    } else {
    124 
    125 
    126 //        for (unsigned i = 0; i < type->getStructNumElements(); ++i) {
    127 
    128 
    129 
    130 //        }
    131 
    132 
    133 
    134 //    }
    135 
    136 
    137 
    138 
    139 
    140 
    141 //}
    142 
    143 
    144 /** ------------------------------------------------------------------------------------------------------------- *
    14587 * @brief initializeCodeGen
    14688 ** ------------------------------------------------------------------------------------------------------------- */
     
    207149    }
    208150
    209     if (LLVM_UNLIKELY(mCarryInfo->variableLength)) {
     151    if (LLVM_UNLIKELY(mCarryInfo->hasVariableLength())) {
    210152        // Check whether we need to resize the carry state
    211153        PHINode * index = iBuilder->CreatePHI(iBuilder->getSizeTy(), 2);
     
    230172
    231173        Constant * carryStateWidth = ConstantExpr::getIntegerCast(ConstantExpr::getSizeOf(carryStateType), capacity->getType(), false);
    232 
    233         Value * newCapacity = iBuilder->CreateMul(iBuilder->CreateAdd(index, iBuilder->getSize(1)), iBuilder->getSize(2));
     174        Value * newCapacity = iBuilder->CreateSelect(iBuilder->CreateICmpNE(index, ConstantInt::getNullValue(index->getType())), iBuilder->CreateMul(index, iBuilder->getSize(2)), iBuilder->getSize(4));
    234175        Value * newArray = iBuilder->CreateAlignedMalloc(carryStateType, newCapacity, iBuilder->getCacheAlignment());
    235176
     
    241182        iBuilder->CreateCondBr(isNullCarryState, zeroBlock, cleanUpBlock);
    242183        iBuilder->SetInsertPoint(cleanUpBlock);
     184
     185
    243186
    244187        iBuilder->CreateMemCpy(newArray, array, iBuilder->CreateMul(capacity, carryStateWidth), iBuilder->getCacheAlignment());
     
    275218        mCarrySummary.pop_back();
    276219    }
    277     if (LLVM_UNLIKELY(mCarryInfo->variableLength)) {
     220    if (LLVM_UNLIKELY(mCarryInfo->hasVariableLength())) {
    278221        assert (!mLoopIndicies.empty());
    279222        PHINode * index = mLoopIndicies.back();
     
    592535 ** ------------------------------------------------------------------------------------------------------------- */
    593536bool CarryManager::inCollapsingCarryMode() const {
    594     return (mCurrentScope->getBranch() && isa<While>(mCurrentScope->getBranch()) && !mCarryInfo->variableLength);
     537    return (mCurrentScope->getBranch() && isa<While>(mCurrentScope->getBranch()) && !mCarryInfo->hasVariableLength());
    595538}
    596539
     
    641584StructType * CarryManager::analyse(PabloBlock * const scope, const unsigned ifDepth, const unsigned loopDepth) {
    642585
     586    assert (scope != mKernel->getEntryBlock() || mCarryScopes == 0);
     587    assert (mCarryScopes < mCarryMetadata.size());
     588    assert (mCarryPackType);
     589
     590    CarryData & cd = mCarryMetadata[mCarryScopes++];
     591
    643592    std::vector<Type *> state;
    644593
    645     assert (mCarryPackType);
    646 
    647594    Type * const carryPackType = (loopDepth == 0) ? mCarryPackType : ArrayType::get(mCarryPackType, 2);
    648 
    649     const auto scopeIndex = mCarryScopes++;
    650 
    651     assert (scopeIndex < mCarryMetadata.size());
    652595
    653596    bool hasLongAdvances = false;
     
    678621    }
    679622
    680     CarryData & cd = mCarryMetadata[scopeIndex];
    681 
    682623    StructType * carryState = nullptr;
    683624
     
    705646        carryState = StructType::get(iBuilder->getContext(), state);
    706647        // If we in a loop and cannot use collapsing carry mode, convert the struct into a capacity and pointer pair.
    707         if (LLVM_UNLIKELY(cd.variableLength)) {
     648        if (LLVM_UNLIKELY(cd.hasVariableLength())) {
     649            mHasVariableLengthCarryData = true;
    708650            carryState = StructType::get(iBuilder->getSizeTy(), carryState->getPointerTo(), nullptr);
    709651        }
     
    730672, mIfDepth(0)
    731673, mHasLongAdvance(false)
     674, mHasVariableLengthCarryData(false)
    732675, mHasLoop(false)
    733676, mLoopDepth(0)
Note: See TracChangeset for help on using the changeset viewer.