Changeset 4703 for icGREP


Ignore:
Timestamp:
Jul 28, 2015, 11:50:42 AM (4 years ago)
Author:
cameron
Message:

Carry manager bit packing partially working, but disabled by default.

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

Legend:

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

    r4700 r4703  
    1212#include <ostream>
    1313#include <llvm/Support/raw_os_ostream.h>
     14#include <llvm/IR/Module.h>
     15
    1416/*
    1517 * Carry Data system.
     
    4749}
    4850
     51#ifdef PACKING
    4952static void EnsurePackHasSpace(unsigned & packedTotalBits, unsigned addedBits) {
    5053    unsigned bitsInCurrentPack = packedTotalBits % PACK_SIZE;
     
    5356    }
    5457}
     58#endif
    5559
    5660
     
    141145    unsigned scopeCarryDataBits;
    142146   
     147    llvm::Value * ifEntryPack;
     148   
    143149};
    144150
  • icGREP/icgrep-devel/icgrep/pablo/carry_manager.cpp

    r4700 r4703  
    4848   
    4949    unsigned totalCarryDataBits = enumerate(pb, 0, 0);
    50    
    5150    mTotalCarryDataBitBlocks = (totalCarryDataBits + BLOCK_SIZE - 1)/BLOCK_SIZE;
    5251    // Carry Data area will have one extra bit block to store the block number.
    5352    mBlockNoPtr = mBuilder->CreateBitCast(mBuilder->CreateGEP(carryPtr, mBuilder->getInt64(mTotalCarryDataBitBlocks)), Type::getInt64PtrTy(mBuilder->getContext()));
    5453    mBlockNo = mBuilder->CreateLoad(mBlockNoPtr);
     54#ifdef PACKING
     55    unsigned totalPackCount = (totalCarryDataBits + PACK_SIZE - 1)/PACK_SIZE;
     56    mCarryPackPtr.resize(totalPackCount);
     57    mCarryInPack.resize(totalPackCount);
     58    mCarryOutPack.resize(totalPackCount);
     59    for (auto i = 0; i < totalPackCount; i++) mCarryInPack[i]=nullptr;
     60#else
    5561    mCarryPackPtr.resize(mTotalCarryDataBitBlocks);
    5662    mCarryInPack.resize(mTotalCarryDataBitBlocks);
    5763    mCarryOutPack.resize(mTotalCarryDataBitBlocks);
    5864    for (auto i = 0; i < mTotalCarryDataBitBlocks; i++) mCarryInPack[i]=nullptr;
    59    
     65#endif   
    6066    /*  Set the current scope to PabloRoot */
    6167    mCurrentScope = mPabloRoot;
     
    147153
    148154void CarryManager::leaveScope() {
     155#ifdef PACKING
     156    if ((mCurrentFrameIndex % PACK_SIZE) == 0) {
     157        // Write out all local packs.
     158        auto localCarryIndex = localBasePack();
     159        auto localCarryPacks = mCarryInfo->getLocalCarryPackCount();
     160        for (auto i = localCarryIndex; i < localCarryIndex + localCarryPacks; i++) {
     161            storeCarryPack(i);
     162        }
     163    }
     164#endif
    149165    mCurrentFrameIndex -= mCarryInfo->getFrameIndex();
    150     mCurrentScope = mCurrentScope->getParent();
    151     mCarryInfo = mCarryInfoVector[mCurrentScope->getScopeIndex()];
     166    if (mCurrentScope != mPabloRoot) {
     167        mCurrentScope = mCurrentScope->getParent();
     168        mCarryInfo = mCarryInfoVector[mCurrentScope->getScopeIndex()];
     169    }
    152170    //std::cerr << "leaveScope:  mCurrentFrameIndex = " << mCurrentFrameIndex << std::endl;
    153171}
     
    230248    unsigned packIndex = carryBit_lo / PACK_SIZE;
    231249    unsigned carryOffset = carryBit_lo % PACK_SIZE;
    232     unsigned hiOffset = carryBit_lo + carryRangeSize - 1;
     250    unsigned hiLimit = carryBit_lo + carryRangeSize;
    233251   
    234252    Value * carryItem = getCarryPack(packIndex);
    235     if (carryRangeSize < PACK_SIZE) {
    236        carryItem = mBuilder->CreateAnd(carryItem, mBuilder->getInt64((1 << hiOffset) - 1));
     253    if (hiLimit < PACK_SIZE) {
     254       carryItem = mBuilder->CreateAnd(carryItem, mBuilder->getInt64((1 << hiLimit) - 1));
    237255    }
    238256    if (carryOffset > 0) {
     
    246264}
    247265   
    248 void CarryManager::setCarryBits(unsigned carryBit_lo, Value * bits) {
     266/*  NOTE: In the following the mCarryOutPack is an accumulator.
     267    It must be created at the appropriate outer level.  */
     268void CarryManager::setCarryBits(unsigned carryBit_lo, unsigned carryRangeSize, Value * bits) {
    249269   
    250270    unsigned packIndex = carryBit_lo / PACK_SIZE;
     
    267287    unsigned posn = carryOpPosition(localIndex);
    268288#ifdef PACKING
    269     return getCarryBit(posn);
     289    return  mBuilder->CreateBitCast(mBuilder->CreateZExt(getCarryBit(posn), mBuilder->getIntNTy(BLOCK_SIZE)), mBitBlockType);
    270290#else
    271291    return getCarryPack(posn);
     
    274294   
    275295   
    276 void CarryManager::setCarryOpCarryOut(unsigned localIndex, Value * carry_out) {
     296void CarryManager::setCarryOpCarryOut(unsigned localIndex, Value * carry_out_strm) {
    277297    unsigned posn = carryOpPosition(localIndex);
    278298#ifdef PACKING
    279     setCarryBits(posn, carry_out);
    280 #else
    281     mCarryOutPack[posn] = carry_out;
     299    Value * field = iBuilder->mvmd_extract(PACK_SIZE, carry_out_strm, 0);
     300    //setCarryBits(posn, mBuilder->CreateLShr(field, mBuilder->getInt64(PACK_SIZE - 1)));
     301    setCarryBits(posn, 1, field);
     302#else
     303    mCarryOutPack[posn] = carry_out_strm;
    282304    if (mCarryInfo->getWhileDepth() == 0) {
    283305        storeCarryPack(posn);
     
    311333        field = mBuilder->CreateAnd(field, mBuilder->getInt64(1<<offset));
    312334    }
    313     setCarryBits(posn - offset, field);
     335    setCarryBits(posn - offset, 1, field);
    314336    Value* carry_longint = mBuilder->CreateZExt(getCarryBit(posn), mBuilder->getIntNTy(BLOCK_SIZE));
    315337    Value* strm_longint = mBuilder->CreateBitCast(strm, mBuilder->getIntNTy(BLOCK_SIZE));
     
    351373        field = mBuilder->CreateAnd(field, mBuilder->getInt64(((1<<shift_amount) - 1) << offset));
    352374    }   
    353     setCarryBits(posn - offset, field);
     375    setCarryBits(posn - offset, shift_amount, field);
    354376    Value* carry_longint = mBuilder->CreateZExt(getCarryRange(posn, shift_amount), mBuilder->getIntNTy(BLOCK_SIZE));
    355377    Value* strm_longint = mBuilder->CreateBitCast(strm, mBuilder->getIntNTy(BLOCK_SIZE));
    356     Value* adv_longint = mBuilder->CreateOr(mBuilder->CreateShl(strm_longint, 1), carry_longint);
     378    Value* adv_longint = mBuilder->CreateOr(mBuilder->CreateShl(strm_longint, shift_amount), carry_longint);
    357379    Value* result_value = mBuilder->CreateBitCast(adv_longint, mBitBlockType);
    358380    return result_value;
     
    443465}
    444466
     467    void CarryManager::initializeCarryDataAtIfEntry() {
     468        if (mCarryOutPack[scopeBasePack()] == nullptr) {
     469            mCarryInfo->ifEntryPack = mZeroInitializer;
     470        }
     471        else {
     472            mCarryInfo->ifEntryPack = mCarryOutPack[scopeBasePack()];
     473        }
     474    }
     475   
     476    void CarryManager::buildCarryDataPhisAfterIfBody(BasicBlock * ifEntryBlock, BasicBlock * ifBodyFinalBlock) {
     477        unsigned const ifScopeCarryBits = mCarryInfo->scopeCarryDataBits;
     478        if (ifScopeCarryBits == 0) {
     479            // No carry data, therefore no phi nodes.
     480            return;
     481        }
     482        if (ifScopeCarryBits < PACK_SIZE) {
     483            unsigned const ifPackIndex = scopeBasePack();
     484            PHINode * ifPack_phi = mBuilder->CreatePHI(mCarryPackType, 2, "ifPack");
     485            ifPack_phi->addIncoming(mCarryInfo->ifEntryPack, ifEntryBlock);
     486            ifPack_phi->addIncoming(mCarryOutPack[ifPackIndex], ifBodyFinalBlock);
     487            mCarryOutPack[ifPackIndex] = ifPack_phi;
     488        }
     489        else if ((ifScopeCarryBits > PACK_SIZE) && (mCarryInfo->getIfDepth() > 1)) {
     490            const unsigned summaryPackIndex = summaryPosition();
     491            PHINode * summary_phi = mBuilder->CreatePHI(mCarryPackType, 2, "summary");
     492            summary_phi->addIncoming(mZeroInitializer, ifEntryBlock);
     493            summary_phi->addIncoming(mCarryOutPack[summaryPackIndex], ifBodyFinalBlock);
     494            mCarryOutPack[summaryPackIndex] = summary_phi;
     495        }
     496    }
     497   
    445498void CarryManager::addSummaryPhiIfNeeded(BasicBlock * ifEntryBlock, BasicBlock * ifBodyFinalBlock) {
    446499    if ((mCarryInfo->getIfDepth() <= 1) || !mCarryInfo->blockHasCarries()){
     
    455508    mCarryOutPack[carrySummaryIndex] = summary_phi;
    456509}
    457 
     510   
    458511void CarryManager::generateCarryOutSummaryCodeIfNeeded() {
    459512   
     
    506559}
    507560
    508 
    509 
    510561void CarryManager::ensureCarriesLoadedRecursive() {
    511562    const unsigned scopeCarryPacks = mCarryInfo->getScopeCarryPackCount();
  • icGREP/icgrep-devel/icgrep/pablo/carry_manager.h

    r4700 r4703  
    7979    bool blockHasCarries();
    8080   
     81    void initializeCarryDataAtIfEntry();
     82   
    8183    Value * getCarrySummaryExpr();
    8284   
    8385    void generateCarryOutSummaryCodeIfNeeded();
     86   
     87    void buildCarryDataPhisAfterIfBody(BasicBlock * ifEntryBlock, BasicBlock * ifBodyFinalBlock);
    8488   
    8589    void addSummaryPhiIfNeeded(BasicBlock * ifEntryBlock, BasicBlock * ifBodyFinalBlock);
     
    135139    Value * getCarryRange(unsigned carryBit_lo, unsigned carryRangeSize);     
    136140    Value * getCarryBit(unsigned carryBitPos);
    137     void setCarryBits(unsigned carryBit_lo, Value * bits);
     141    void setCarryBits(unsigned carryBit_lo, unsigned carryRangeSize, Value * bits);
    138142
    139143    unsigned absPosition(unsigned frameOffsetinBits, unsigned relPos);
  • icGREP/icgrep-devel/icgrep/pablo/pablo_compiler.cpp

    r4696 r4703  
    187187    compileBlock(mainScope);
    188188   
     189    mCarryManager->leaveScope();
     190   
     191   
    189192    mCarryManager->generateBlockNoIncrement();
    190193
     
    423426    mBuilder->SetInsertPoint(ifBodyBlock);
    424427   
    425    
    426     ++mIfDepth;
     428    mCarryManager->initializeCarryDataAtIfEntry();
    427429    compileBlock(ifBody);
    428     --mIfDepth;
    429430    if (mCarryManager->blockHasCarries()) {
    430431        mCarryManager->generateCarryOutSummaryCodeIfNeeded();
     
    444445    }
    445446    // Create the phi Node for the summary variable, if needed.
    446     mCarryManager->addSummaryPhiIfNeeded(ifEntryBlock, ifBodyFinalBlock);
     447    mCarryManager->buildCarryDataPhisAfterIfBody(ifEntryBlock, ifBodyFinalBlock);
     448    //mCarryManager->addSummaryPhiIfNeeded(ifEntryBlock, ifBodyFinalBlock);
    447449    mCarryManager->leaveScope();
    448450}
Note: See TracChangeset for help on using the changeset viewer.