Changeset 4696 for icGREP/icgrep-devel


Ignore:
Timestamp:
Jul 24, 2015, 8:18:18 AM (4 years ago)
Author:
cameron
Message:

Carry manager progress

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

Legend:

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

    r4691 r4696  
    124124    unsigned getLocalCarryPackIndex () { return shortAdvance.frameOffsetinBits / PACK_SIZE; }
    125125
    126     unsigned getLocalCarryDataSize () { return fullOrPartialBlocks(nested.frameOffsetinBits - shortAdvance.frameOffsetinBits, PACK_SIZE); }
     126    unsigned getLocalCarryPackCount () { return fullOrPartialBlocks(nested.frameOffsetinBits - shortAdvance.frameOffsetinBits, PACK_SIZE); }
    127127
    128     unsigned getScopeCarryDataSize () { return fullOrPartialBlocks(scopeCarryDataBits, PACK_SIZE); }
     128    unsigned getScopeCarryPackCount () { return fullOrPartialBlocks(scopeCarryDataBits, PACK_SIZE); }
    129129   
    130130    bool blockHasCarries() const { return scopeCarryDataBits > 0;}
  • icGREP/icgrep-devel/icgrep/pablo/carry_manager.cpp

    r4694 r4696  
    4545    mCarryPackPtr.resize(mTotalCarryDataBitBlocks);
    4646    mCarryInPack.resize(mTotalCarryDataBitBlocks);
    47     mCarryInPhis.resize(mTotalCarryDataBitBlocks);
    48     mCarryOutAccumPhis.resize(mTotalCarryDataBitBlocks);
    49     mCarryOutVector.resize(mTotalCarryDataBitBlocks);
     47    mCarryOutPack.resize(mTotalCarryDataBitBlocks);
    5048    for (auto i = 0; i < mTotalCarryDataBitBlocks; i++) mCarryInPack[i]=nullptr;
    5149   
     
    8987            if (cd->maxNestingDepth <= nestedBlockData->maxNestingDepth) cd->maxNestingDepth = nestedBlockData->maxNestingDepth + 1;
    9088            cd->nested.entries++;
     89#ifndef NDEBUG
     90            nestedBlockData->dumpCarryData(cerr);
     91#endif
    9192        }
    9293        else if (While * whileStatement = dyn_cast<While>(stmt)) {
     
    101102            if (cd->maxNestingDepth <= nestedBlockData->maxNestingDepth) cd->maxNestingDepth = nestedBlockData->maxNestingDepth + 1;
    102103            cd->nested.entries++;
     104#ifndef NDEBUG
     105            nestedBlockData->dumpCarryData(cerr);
     106#endif
    103107        }
    104108    }
     
    118122        cd->summary.allocatedBits = cd->scopeCarryDataBits;
    119123    }
    120 #ifndef NDEBUG
    121     cd->dumpCarryData(cerr);
    122 #endif
    123124    return cd->scopeCarryDataBits;
    124125}
     
    155156}
    156157
    157 void CarryManager::CarryPackStore(unsigned packIndex) {
    158     mBuilder->CreateAlignedStore(mCarryOutVector[packIndex], mCarryPackPtr[packIndex], PACK_SIZE/8);
    159 }
    160 
    161 Value * CarryManager::genCarryInRange(unsigned carryBit_lo, unsigned carryRangeSize) {
     158void CarryManager::storeCarryPack(unsigned packIndex) {
     159    mBuilder->CreateAlignedStore(mCarryOutPack[packIndex], mCarryPackPtr[packIndex], PACK_SIZE/8);
     160}
     161
     162Value * CarryManager::getCarryRange(unsigned carryBit_lo, unsigned carryRangeSize) {
    162163
    163164    unsigned packIndex = carryBit_lo / PACK_SIZE;
     
    175176}
    176177   
    177  
    178 Value * CarryManager::genCarryInBit(unsigned carryBitPos) {
    179     return genCarryInRange(carryBitPos, 1);
    180 }
    181     /* Methods for getting and setting individual carry values. */
    182    
    183 //#define LOAD_STORE_ON_BLOCK_ENTRY_EXIT   
     178Value * CarryManager::getCarryBit(unsigned carryBitPos) {
     179    return getCarryRange(carryBitPos, 1);
     180}
     181   
     182void CarryManager::setCarryBits(unsigned carryBit_lo, Value * bits) {
     183   
     184    unsigned packIndex = carryBit_lo / PACK_SIZE;
     185    unsigned carryOffset = carryBit_lo % PACK_SIZE;
     186    if (carryOffset > 0) {
     187        bits = mBuilder->CreateLShr(bits, mBuilder->getInt64(carryOffset));
     188    }
     189    if (mCarryOutPack[packIndex] == nullptr) {
     190        mCarryOutPack[packIndex] = bits;
     191    }
     192    else {
     193        mCarryOutPack[packIndex] = mBuilder->CreateOr(mCarryOutPack[packIndex], bits);
     194    }
     195}
     196   
     197   
     198/* Methods for getting and setting individual carry values. */
     199   
    184200Value * CarryManager::getCarryOpCarryIn(int localIndex) {
    185201    unsigned cd_index = mCurrentFrameIndex + mCarryInfo->carryOpCarryDataOffset(localIndex);
     202#ifdef PACKING
     203    return getCarryBit(cd_index);
     204#else
    186205    return getCarryPack(cd_index);
    187 }
    188 
     206#endif
     207}
     208   
     209   
    189210void CarryManager::setCarryOpCarryOut(unsigned localIndex, Value * carry_out) {
     211#ifdef PACKING
     212#else
    190213    unsigned cd_index = mCurrentFrameIndex + mCarryInfo->carryOpCarryDataOffset(localIndex);
    191     mCarryOutVector[cd_index] = carry_out;
    192 #ifndef LOAD_STORE_ON_BLOCK_ENTRY_EXIT
     214    mCarryOutPack[cd_index] = carry_out;
    193215    if (mCarryInfo->getWhileDepth() == 0) {
    194         CarryPackStore(cd_index);
     216        storeCarryPack(cd_index);
    195217    }
    196218#endif
     
    211233
    212234Value * CarryManager::unitAdvanceCarryInCarryOut(int localIndex, Value * strm) {
     235#ifdef PACKING
     236#else
    213237   
    214238    unsigned carryDataIndex = mCurrentFrameIndex + mCarryInfo->unitAdvanceCarryDataOffset(localIndex);
    215     mCarryOutVector[carryDataIndex] = strm;
     239    mCarryOutPack[carryDataIndex] = strm;
    216240    Value * carry_in = getCarryPack(carryDataIndex);
    217 #ifndef LOAD_STORE_ON_BLOCK_ENTRY_EXIT
    218241    if (mCarryInfo->getWhileDepth() == 0) {
    219         CarryPackStore(carryDataIndex);
    220     }
    221 #endif
     242        storeCarryPack(carryDataIndex);
     243    }
    222244    Value* result_value;
    223245   
     
    233255#endif
    234256    return result_value;
     257#endif
    235258}
    236259
    237260Value * CarryManager::shortAdvanceCarryInCarryOut(int localIndex, int shift_amount, Value * strm) {
     261#ifdef PACKING
     262#else
    238263    unsigned carryDataIndex = mCurrentFrameIndex + mCarryInfo->shortAdvanceCarryDataOffset(localIndex);
    239     mCarryOutVector[carryDataIndex] = strm;
     264    mCarryOutPack[carryDataIndex] = strm;
    240265    Value * carry_in = getCarryPack(carryDataIndex);
    241 #ifndef LOAD_STORE_ON_BLOCK_ENTRY_EXIT
    242266    if (mCarryInfo->getWhileDepth() == 0) {
    243         CarryPackStore(carryDataIndex);
    244     }
    245 #endif
     267        storeCarryPack(carryDataIndex);
     268    }
    246269    Value* advanceq_longint = mBuilder->CreateBitCast(carry_in, mBuilder->getIntNTy(BLOCK_SIZE));
    247270    Value* strm_longint = mBuilder->CreateBitCast(strm, mBuilder->getIntNTy(BLOCK_SIZE));
    248271    Value* adv_longint = mBuilder->CreateOr(mBuilder->CreateShl(strm_longint, shift_amount), mBuilder->CreateLShr(advanceq_longint, BLOCK_SIZE - shift_amount), "advance");
    249272    return mBuilder->CreateBitCast(adv_longint, mBitBlockType);
     273#endif
    250274}
    251275   
     
    315339
    316340Value * CarryManager::getCarrySummaryExpr() {
     341#ifdef PACKING
     342#else
    317343    unsigned summary_idx = mCurrentFrameIndex + mCarryInfo->summaryCarryDataIndex();
    318344    return getCarryPack(summary_idx);
     345#endif
    319346}
    320347
     
    328355    PHINode * summary_phi = mBuilder->CreatePHI(mBitBlockType, 2, "summary");
    329356    summary_phi->addIncoming(mZeroInitializer, ifEntryBlock);
    330     summary_phi->addIncoming(mCarryOutVector[carrySummaryIndex], ifBodyFinalBlock);
    331     mCarryOutVector[carrySummaryIndex] = summary_phi;
     357    summary_phi->addIncoming(mCarryOutPack[carrySummaryIndex], ifBodyFinalBlock);
     358    mCarryOutPack[carrySummaryIndex] = summary_phi;
    332359}
    333360
     
    350377    else {
    351378        auto localCarryIndex = mCurrentFrameIndex + mCarryInfo->getLocalCarryPackIndex();
    352         auto localCarryPacks = mCarryInfo->getLocalCarryDataSize();
     379        auto localCarryPacks = mCarryInfo->getLocalCarryPackCount();
    353380        if (localCarryPacks > 0) {
    354             carry_summary = mCarryOutVector[localCarryIndex];
     381            carry_summary = mCarryOutPack[localCarryIndex];
    355382            for (auto i = 1; i < localCarryPacks; i++) {
    356383                //carry_summary = mBuilder->CreateOr(carry_summary, mPabloBlock->mCarryOutPack[i]);           
    357                 carry_summary = mBuilder->CreateOr(carry_summary, mCarryOutVector[localCarryIndex+i]);
     384                carry_summary = mBuilder->CreateOr(carry_summary, mCarryOutPack[localCarryIndex+i]);
    358385            }
    359386        }
     
    363390                enterScope(inner_blk);
    364391                if (blockHasCarries()) {
    365                   carry_summary = mBuilder->CreateOr(carry_summary, mCarryOutVector[mCurrentFrameIndex + mCarryInfo->summaryCarryDataIndex()]);
     392                  carry_summary = mBuilder->CreateOr(carry_summary, mCarryOutPack[mCurrentFrameIndex + mCarryInfo->summaryCarryDataIndex()]);
    366393                }
    367394                leaveScope();
     
    371398                enterScope(inner_blk);
    372399                if (blockHasCarries()) {
    373                     carry_summary = mBuilder->CreateOr(carry_summary, mCarryOutVector[mCurrentFrameIndex + mCarryInfo->summaryCarryDataIndex()]);
     400                    carry_summary = mBuilder->CreateOr(carry_summary, mCarryOutPack[mCurrentFrameIndex + mCarryInfo->summaryCarryDataIndex()]);
    374401                }
    375402                leaveScope();
     
    379406    // Calculation of the carry out summary is complete.   Store it and make it
    380407    // available in case it must included by parent blocks.
    381     mCarryOutVector[carrySummaryIndex] = carry_summary;
    382     CarryPackStore(carrySummaryIndex);
    383 }
    384 
    385 
    386 void CarryManager::ensureCarriesLoadedLocal() {
    387 #ifdef LOAD_STORE_ON_BLOCK_ENTRY_EXIT
    388     if ((mCarryInfo->getScopeCarryDataSize() == 0 ) || (mCarryInfo->getWhileDepth() > 0)) return;
    389     if ((mCarryInfo->getIfDepth() == 0) || mCarryInfo->explicitSummaryRequired()) {
    390         auto localCarryIndex = mCurrentFrameIndex + mCarryInfo->getLocalCarryPackIndex();
    391         auto localCarryPacks = mCarryInfo->getLocalCarryDataSize();
    392         //std::cerr << "ensureCarriesLoadedLocal: localCarryIndex =  " << localCarryIndex << "localCarryPacks =  " << localCarryPacks << std::endl;
    393         for (auto i = localCarryIndex; i < localCarryIndex + localCarryPacks; i++) {       
    394             mCarryInPack[i] = mBuilder->CreateAlignedLoad(mBuilder->CreateGEP(mCarryDataPtr, mBuilder->getInt64(i)), BLOCK_SIZE/8, false);
    395         }
    396     }
    397 #endif
    398 }
    399 
    400 void CarryManager::ensureCarriesStoredLocal() {
    401 #ifdef LOAD_STORE_ON_BLOCK_ENTRY_EXIT
    402     if ((mCarryInfo->getScopeCarryDataSize() == 0 ) || (mCarryInfo->getWhileDepth() > 0)) return;
    403     auto localCarryIndex = mCurrentFrameIndex + mCarryInfo->getLocalCarryPackIndex();
    404     auto localCarryPacks = mCarryInfo->getLocalCarryDataSize();
    405     //std::cerr << "ensureCarriesStoredLocal: localCarryIndex =  " << localCarryIndex << "localCarryPacks =  " << localCarryPacks << std::endl;
    406     for (auto i = localCarryIndex; i < localCarryIndex + localCarryPacks; i++) {       
    407         Value * storePtr = mBuilder->CreateGEP(mCarryDataPtr, mBuilder->getInt64(i));
    408         mBuilder->CreateAlignedStore(mCarryOutVector[i], storePtr, BLOCK_SIZE/8, false);
    409     }
    410 #endif
     408    mCarryOutPack[carrySummaryIndex] = carry_summary;
     409    storeCarryPack(carrySummaryIndex);
    411410}
    412411
     
    414413
    415414void CarryManager::ensureCarriesLoadedRecursive() {
    416     const unsigned scopeCarryDataSize = mCarryInfo->getScopeCarryDataSize();
     415    const unsigned scopeCarryPacks = mCarryInfo->getScopeCarryPackCount();
    417416    if (mCarryInfo->getWhileDepth() == 1) {
    418         for (auto i = mCurrentFrameIndex; i < mCurrentFrameIndex + scopeCarryDataSize; ++i) {
     417        for (auto i = mCurrentFrameIndex; i < mCurrentFrameIndex + scopeCarryPacks; ++i) {
    419418            getCarryPack(i);
    420419        }
     
    424423
    425424void CarryManager::initializeCarryDataPhisAtWhileEntry(BasicBlock * whileEntryBlock) {
    426     const unsigned scopeCarryDataSize = mCarryInfo->getScopeCarryDataSize();
    427     for (unsigned index = mCurrentFrameIndex; index < mCurrentFrameIndex + scopeCarryDataSize; ++index) {
     425    const unsigned scopeCarryPacks = mCarryInfo->getScopeCarryPackCount();
     426    mCarryOutAccumPhis.resize(scopeCarryPacks);
     427#ifdef SET_WHILE_CARRY_IN_TO_ZERO_AFTER_FIRST_ITERATION
     428    mCarryInPhis.resize(scopeCarryPacks);
     429#endif
     430    for (unsigned index = 0; index < scopeCarryPacks; ++index) {
    428431#ifdef SET_WHILE_CARRY_IN_TO_ZERO_AFTER_FIRST_ITERATION
    429432        PHINode * phi_in = mBuilder->CreatePHI(mBitBlockType, 2);
    430         phi_in->addIncoming(mCarryInPack[index], whileEntryBlock);
     433        phi_in->addIncoming(mCarryInPack[mCurrentFrameIndex+index], whileEntryBlock);
    431434        mCarryInPhis[index] = phi_in;
    432435#endif
     
    439442
    440443void CarryManager::extendCarryDataPhisAtWhileBodyFinalBlock(BasicBlock * whileBodyFinalBlock) {
    441     const unsigned scopeCarryDataSize = mCarryInfo->getScopeCarryDataSize();
    442     for (unsigned index = mCurrentFrameIndex; index < mCurrentFrameIndex + scopeCarryDataSize; ++index) {
     444    const unsigned scopeCarryPacks = mCarryInfo->getScopeCarryPackCount();
     445    for (unsigned index = 0; index < scopeCarryPacks; ++index) {
    443446#ifdef SET_WHILE_CARRY_IN_TO_ZERO_AFTER_FIRST_ITERATION
    444447        mCarryInPhis[index]->addIncoming(mZeroInitializer, whileBodyFinalBlock);
    445448#endif
    446449        PHINode * phi = mCarryOutAccumPhis[index];
    447         assert (phi);
    448         assert (mCarryOutVector[index]);
    449         Value * carryOut = mBuilder->CreateOr(phi, mCarryOutVector[index]);
     450        Value * carryOut = mBuilder->CreateOr(phi, mCarryOutPack[mCurrentFrameIndex+index]);
    450451        phi->addIncoming(carryOut, whileBodyFinalBlock);
    451         mCarryOutVector[index] = carryOut;
     452        mCarryOutPack[mCurrentFrameIndex+index] = carryOut;
    452453    }
    453454}
    454455
    455456void CarryManager::ensureCarriesStoredRecursive() {
    456     const unsigned scopeCarryDataSize = mCarryInfo->getScopeCarryDataSize();
     457    const unsigned scopeCarryPacks = mCarryInfo->getScopeCarryPackCount();
    457458    if (mCarryInfo->getWhileDepth() == 1) {
    458         for (auto i = mCurrentFrameIndex; i < mCurrentFrameIndex + scopeCarryDataSize; ++i) {
    459             CarryPackStore(i);
    460         }
    461     }
    462 }
    463 
    464 }
    465 
     459        for (auto i = mCurrentFrameIndex; i < mCurrentFrameIndex + scopeCarryPacks; ++i) {
     460            storeCarryPack(i);
     461        }
     462    }
     463}
     464
     465}
     466
  • icGREP/icgrep-devel/icgrep/pablo/carry_manager.h

    r4694 r4696  
    6060    unsigned enumerate(PabloBlock * blk, unsigned ifDepth, unsigned whileDepth);
    6161   
    62     void generateBlockNoIncrement();
    63    
     62    void generateBlockNoIncrement();   
    6463    Value * getBlockNoPtr();
    6564   
     
    6766   
    6867    void enterScope(PabloBlock * blk);
    69 
    7068    void leaveScope();
    7169   
    72 /* Helper routines */
    73 
    74 
    75 Value * getCarryPack(unsigned packIndex);
    76 
    77 void CarryPackStore(unsigned packIndex);
    78 
    79 Value * genCarryInRange(unsigned carryBit_lo, unsigned carryRangeSize);
    80  
    81 Value * genCarryInBit(unsigned carryBitPos);
    82 
    8370    /* Methods for processing individual carry-generating operations. */
    8471   
    8572    Value * getCarryOpCarryIn(int localIndex);
    86 
    8773    void setCarryOpCarryOut(unsigned idx, Value * carry_out);
    8874
     
    9884   
    9985    void addSummaryPhiIfNeeded(BasicBlock * ifEntryBlock, BasicBlock * ifBodyFinalBlock);
    100    
    101     /* Methods for load/store of carries for non-while blocks. */
    102    
    103     void ensureCarriesLoadedLocal();
    104 
    105     void ensureCarriesStoredLocal();
    10686   
    10787    /* Methods for handling while statements */
     
    141121    std::vector<PHINode *> mCarryInPhis; 
    142122    std::vector<PHINode *> mCarryOutAccumPhis; 
    143     std::vector<Value *> mCarryOutVector;
     123    std::vector<Value *> mCarryOutPack;
    144124
    145125    Value * unitAdvanceCarryInCarryOut(int localIndex, Value * strm);
    146126    Value * shortAdvanceCarryInCarryOut(int localIndex, int shift_amount, Value * strm);
    147127    Value * longAdvanceCarryInCarryOut(int localIndex, int shift_amount, Value * strm);
     128   
     129   
     130    /* Helper routines */
     131    Value * getCarryPack(unsigned packIndex);
     132    void storeCarryPack(unsigned packIndex);
     133   
     134    Value * getCarryRange(unsigned carryBit_lo, unsigned carryRangeSize);     
     135    Value * getCarryBit(unsigned carryBitPos);
     136    void setCarryBits(unsigned carryBit_lo, Value * bits);
     137
     138   
    148139   
    149140};
  • icGREP/icgrep-devel/icgrep/pablo/pablo_compiler.cpp

    r4692 r4696  
    356356void PabloCompiler::compileBlock(PabloBlock & block) {
    357357    mPabloBlock = & block;
    358     mCarryManager->ensureCarriesLoadedLocal();
    359358    for (const Statement * statement : block) {
    360359        compileStatement(statement);
    361360    }
    362     mCarryManager->ensureCarriesStoredLocal();
    363361    mPabloBlock = block.getParent();
    364362}
Note: See TracChangeset for help on using the changeset viewer.