Changeset 4694


Ignore:
Timestamp:
Jul 23, 2015, 8:05:59 PM (4 years ago)
Author:
cameron
Message:

Carry manager refactoring, progress towards bit packing

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

Legend:

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

    r4692 r4694  
    3939    unsigned totalCarryDataBits = enumerate(pb, 0, 0);
    4040   
    41     mTotalCarryDataBitBlocks = (totalCarryDataBits + BLOCK_SIZE - 1)/BLOCK_SIZE + 1; // One extra element for the block no.
    42     mBlockNoPtr = mBuilder->CreateBitCast(mBuilder->CreateGEP(mCarryDataPtr, mBuilder->getInt64(mTotalCarryDataBitBlocks - 1)), Type::getInt64PtrTy(mBuilder->getContext()));
     41    mTotalCarryDataBitBlocks = (totalCarryDataBits + BLOCK_SIZE - 1)/BLOCK_SIZE;
     42    // Carry Data area will have one extra bit block to store the block number.
     43    mBlockNoPtr = mBuilder->CreateBitCast(mBuilder->CreateGEP(mCarryDataPtr, mBuilder->getInt64(mTotalCarryDataBitBlocks)), Type::getInt64PtrTy(mBuilder->getContext()));
    4344    mBlockNo = mBuilder->CreateLoad(mBlockNoPtr);
    44     mCarryInVector.resize(mTotalCarryDataBitBlocks);
     45    mCarryPackPtr.resize(mTotalCarryDataBitBlocks);
     46    mCarryInPack.resize(mTotalCarryDataBitBlocks);
    4547    mCarryInPhis.resize(mTotalCarryDataBitBlocks);
    4648    mCarryOutAccumPhis.resize(mTotalCarryDataBitBlocks);
    4749    mCarryOutVector.resize(mTotalCarryDataBitBlocks);
     50    for (auto i = 0; i < mTotalCarryDataBitBlocks; i++) mCarryInPack[i]=nullptr;
    4851   
    4952    /*  Set the current scope to PabloRoot */
     
    5255    mCarryInfo = mCarryInfoVector[0];
    5356
    54     return mTotalCarryDataBitBlocks;
     57    return mTotalCarryDataBitBlocks + 1; // One extra element for the block no.
    5558}
    5659   
     
    6265    return mBlockNoPtr;
    6366}
     67
    6468
    6569unsigned CarryManager::enumerate(PabloBlock * blk, unsigned ifDepth, unsigned whileDepth) {
     
    138142}
    139143
     144
     145/* Helper routines */
     146
     147
     148Value * CarryManager::getCarryPack(unsigned packIndex) {
     149    if (mCarryInPack[packIndex] == nullptr) {
     150        Value * packPtr = mBuilder->CreateGEP(mCarryDataPtr, mBuilder->getInt64(packIndex));
     151        mCarryPackPtr[packIndex] = packPtr;
     152        mCarryInPack[packIndex] = mBuilder->CreateAlignedLoad(packPtr, PACK_SIZE/8);
     153    }
     154    return mCarryInPack[packIndex];
     155}
     156
     157void CarryManager::CarryPackStore(unsigned packIndex) {
     158    mBuilder->CreateAlignedStore(mCarryOutVector[packIndex], mCarryPackPtr[packIndex], PACK_SIZE/8);
     159}
     160
     161Value * CarryManager::genCarryInRange(unsigned carryBit_lo, unsigned carryRangeSize) {
     162
     163    unsigned packIndex = carryBit_lo / PACK_SIZE;
     164    unsigned carryOffset = carryBit_lo % PACK_SIZE;
     165    unsigned hiOffset = carryBit_lo + carryRangeSize - 1;
     166   
     167    Value * carryItem = getCarryPack(packIndex);
     168    if (carryRangeSize < PACK_SIZE) {
     169       carryItem = mBuilder->CreateAnd(carryItem, mBuilder->getInt64((1 << hiOffset) - 1));
     170    }
     171    if (carryOffset > 0) {
     172       carryItem = mBuilder->CreateLShr(carryItem, mBuilder->getInt64(carryOffset));
     173    }
     174    return carryItem;
     175}
     176   
     177 
     178Value * CarryManager::genCarryInBit(unsigned carryBitPos) {
     179    return genCarryInRange(carryBitPos, 1);
     180}
    140181    /* Methods for getting and setting individual carry values. */
    141182   
     
    143184Value * CarryManager::getCarryOpCarryIn(int localIndex) {
    144185    unsigned cd_index = mCurrentFrameIndex + mCarryInfo->carryOpCarryDataOffset(localIndex);
    145 #ifndef LOAD_STORE_ON_BLOCK_ENTRY_EXIT
    146     if (mCarryInfo->getWhileDepth() == 0) {
    147        Value * packPtr = mBuilder->CreateGEP(mCarryDataPtr, mBuilder->getInt64(cd_index));
    148        mCarryInVector[cd_index] = mBuilder->CreateAlignedLoad(packPtr, BLOCK_SIZE/8);
    149     }
    150 #endif
    151     return mCarryInVector[cd_index];
     186    return getCarryPack(cd_index);
    152187}
    153188
     
    157192#ifndef LOAD_STORE_ON_BLOCK_ENTRY_EXIT
    158193    if (mCarryInfo->getWhileDepth() == 0) {
    159        Value * packPtr = mBuilder->CreateGEP(mCarryDataPtr, mBuilder->getInt64(cd_index));
    160        mBuilder->CreateAlignedStore(carry_out, packPtr, BLOCK_SIZE/8);
     194        CarryPackStore(cd_index);
    161195    }
    162196#endif
     
    180214    unsigned carryDataIndex = mCurrentFrameIndex + mCarryInfo->unitAdvanceCarryDataOffset(localIndex);
    181215    mCarryOutVector[carryDataIndex] = strm;
     216    Value * carry_in = getCarryPack(carryDataIndex);
    182217#ifndef LOAD_STORE_ON_BLOCK_ENTRY_EXIT
    183218    if (mCarryInfo->getWhileDepth() == 0) {
    184         Value * packPtr = mBuilder->CreateGEP(mCarryDataPtr, mBuilder->getInt64(carryDataIndex));
    185         mCarryInVector[carryDataIndex] = mBuilder->CreateAlignedLoad(packPtr, BLOCK_SIZE/8);
    186         mBuilder->CreateAlignedStore(strm, packPtr, BLOCK_SIZE/8);
    187     }
    188 #endif
    189     Value * carry_in = mCarryInVector[carryDataIndex];
     219        CarryPackStore(carryDataIndex);
     220    }
     221#endif
    190222    Value* result_value;
    191223   
     
    206238    unsigned carryDataIndex = mCurrentFrameIndex + mCarryInfo->shortAdvanceCarryDataOffset(localIndex);
    207239    mCarryOutVector[carryDataIndex] = strm;
     240    Value * carry_in = getCarryPack(carryDataIndex);
    208241#ifndef LOAD_STORE_ON_BLOCK_ENTRY_EXIT
    209242    if (mCarryInfo->getWhileDepth() == 0) {
    210         Value * packPtr = mBuilder->CreateGEP(mCarryDataPtr, mBuilder->getInt64(carryDataIndex));
    211         mCarryInVector[carryDataIndex] = mBuilder->CreateAlignedLoad(packPtr, BLOCK_SIZE/8);
    212         mBuilder->CreateAlignedStore(strm, packPtr, BLOCK_SIZE/8);
    213     }
    214 #endif
    215     Value * carry_in = mCarryInVector[carryDataIndex];
     243        CarryPackStore(carryDataIndex);
     244    }
     245#endif
    216246    Value* advanceq_longint = mBuilder->CreateBitCast(carry_in, mBuilder->getIntNTy(BLOCK_SIZE));
    217247    Value* strm_longint = mBuilder->CreateBitCast(strm, mBuilder->getIntNTy(BLOCK_SIZE));
     
    286316Value * CarryManager::getCarrySummaryExpr() {
    287317    unsigned summary_idx = mCurrentFrameIndex + mCarryInfo->summaryCarryDataIndex();
    288     Value * packPtr = mBuilder->CreateGEP(mCarryDataPtr, mBuilder->getInt64(summary_idx));
    289     Value * summary_expr = mBuilder->CreateAlignedLoad(packPtr, BLOCK_SIZE/8);
    290     // If the scopeCarryDataSize is 1, then the carry summary is also the pack expr.
    291     mCarryInVector[summary_idx] = summary_expr;
    292     return summary_expr;
     318    return getCarryPack(summary_idx);
    293319}
    294320
     
    354380    // available in case it must included by parent blocks.
    355381    mCarryOutVector[carrySummaryIndex] = carry_summary;
    356     Value * packPtr = mBuilder->CreateGEP(mCarryDataPtr, mBuilder->getInt64(carrySummaryIndex));
    357     mBuilder->CreateAlignedStore(carry_summary, packPtr, BLOCK_SIZE/8);
     382    CarryPackStore(carrySummaryIndex);
    358383}
    359384
     
    367392        //std::cerr << "ensureCarriesLoadedLocal: localCarryIndex =  " << localCarryIndex << "localCarryPacks =  " << localCarryPacks << std::endl;
    368393        for (auto i = localCarryIndex; i < localCarryIndex + localCarryPacks; i++) {       
    369             mCarryInVector[i] = mBuilder->CreateAlignedLoad(mBuilder->CreateGEP(mCarryDataPtr, mBuilder->getInt64(i)), BLOCK_SIZE/8, false);
     394            mCarryInPack[i] = mBuilder->CreateAlignedLoad(mBuilder->CreateGEP(mCarryDataPtr, mBuilder->getInt64(i)), BLOCK_SIZE/8, false);
    370395        }
    371396    }
     
    392417    if (mCarryInfo->getWhileDepth() == 1) {
    393418        for (auto i = mCurrentFrameIndex; i < mCurrentFrameIndex + scopeCarryDataSize; ++i) {
    394             mCarryInVector[i] = mBuilder->CreateAlignedLoad(mBuilder->CreateGEP(mCarryDataPtr, mBuilder->getInt64(i)), BLOCK_SIZE/8, false);
     419            getCarryPack(i);
    395420        }
    396421    }
     
    403428#ifdef SET_WHILE_CARRY_IN_TO_ZERO_AFTER_FIRST_ITERATION
    404429        PHINode * phi_in = mBuilder->CreatePHI(mBitBlockType, 2);
    405         phi_in->addIncoming(mCarryInVector[index], whileEntryBlock);
     430        phi_in->addIncoming(mCarryInPack[index], whileEntryBlock);
    406431        mCarryInPhis[index] = phi_in;
    407432#endif
     
    432457    if (mCarryInfo->getWhileDepth() == 1) {
    433458        for (auto i = mCurrentFrameIndex; i < mCurrentFrameIndex + scopeCarryDataSize; ++i) {
    434             Value * storePtr = mBuilder->CreateGEP(mCarryDataPtr, mBuilder->getInt64(i));
    435             mBuilder->CreateAlignedStore(mCarryOutVector[i], storePtr, BLOCK_SIZE/8, false);
    436         }
    437     }
    438 }
    439 
    440 }
    441 
     459            CarryPackStore(i);
     460        }
     461    }
     462}
     463
     464}
     465
  • icGREP/icgrep-devel/icgrep/pablo/carry_manager.h

    r4691 r4694  
    3838    : mBuilder(b)
    3939    , mBitBlockType(bitBlockType)
     40#ifdef PACKING
     41    , mPackType(b->getIntNTy(PACK_SIZE))
     42#endif
    4043    , mZeroInitializer(zero)
    4144    , mOneInitializer(one)
     
    6770    void leaveScope();
    6871   
     72/* Helper routines */
     73
     74
     75Value * getCarryPack(unsigned packIndex);
     76
     77void CarryPackStore(unsigned packIndex);
     78
     79Value * genCarryInRange(unsigned carryBit_lo, unsigned carryRangeSize);
     80 
     81Value * genCarryInBit(unsigned carryBitPos);
     82
    6983    /* Methods for processing individual carry-generating operations. */
    7084   
     
    105119    IRBuilder <> * mBuilder;
    106120    VectorType * mBitBlockType;
     121#ifdef PACKING
     122    Type * mPackType;
     123#endif
    107124    ConstantAggregateZero * mZeroInitializer;
    108125    Constant * mOneInitializer;
     
    120137
    121138
    122     std::vector<Value *> mCarryInVector;
     139    std::vector<Value *> mCarryPackPtr;
     140    std::vector<Value *> mCarryInPack;
    123141    std::vector<PHINode *> mCarryInPhis; 
    124142    std::vector<PHINode *> mCarryOutAccumPhis; 
Note: See TracChangeset for help on using the changeset viewer.