Ignore:
Timestamp:
May 6, 2015, 1:03:21 PM (4 years ago)
Author:
cameron
Message:

Separate CarryIn? and CarryOut? data; introduce mIfDepth and mWhileDepth

File:
1 edited

Legend:

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

    r4544 r4545  
    7070, mBasisBitsInputPtr(nullptr)
    7171, mCarryDataPtr(nullptr)
    72 , mNestingDepth(0)
     72, mWhileDepth(0)
     73, mIfDepth(0)
    7374, mZeroInitializer(ConstantAggregateZero::get(mBitBlockType))
    7475, mOneInitializer(ConstantVector::getAllOnesValue(mBitBlockType))
     
    7778, mBasisBitsAddr(nullptr)
    7879, mOutputAddrPtr(nullptr)
    79 , mMaxNestingDepth(0)
     80, mMaxWhileDepth(0)
    8081, mPrintRegisterFunction(nullptr)
    8182{
     
    110111CompiledPabloFunction PabloCompiler::compile(PabloBlock & pb)
    111112{
    112     mNestingDepth = 0;
    113     mMaxNestingDepth = 0;
     113    mWhileDepth = 0;
     114    mIfDepth = 0;
     115    mMaxWhileDepth = 0;
    114116    unsigned totalCarryDataSize = Examine(pb, 0);
    115     mCarryDataVector.resize(totalCarryDataSize);
     117    mCarryInVector.resize(totalCarryDataSize);
     118    mCarryOutVector.resize(totalCarryDataSize);
    116119    mCarryDataSummaryIdx.resize(totalCarryDataSize);
    117120    std::string errMessage;
     
    120123    builder.setMCPU(sys::getHostCPUName());
    121124    builder.setUseMCJIT(true);
    122     builder.setOptLevel(mMaxNestingDepth ? CodeGenOpt::Level::Less : CodeGenOpt::Level::None);
     125    builder.setOptLevel(mMaxWhileDepth ? CodeGenOpt::Level::Less : CodeGenOpt::Level::None);
    123126    mExecutionEngine = builder.create();
    124127    if (mExecutionEngine == nullptr) {
     
    137140    mOutputAddrPtr->setName("output");
    138141
    139     mNestingDepth = 0;
    140     mMaxNestingDepth = 0;
     142    mWhileDepth = 0;
     143    mIfDepth = 0;
     144    mMaxWhileDepth = 0;
    141145    mBasicBlock = BasicBlock::Create(mMod->getContext(), "parabix_entry", mFunction,0);
    142146
     
    153157    compileBlock(pb);
    154158
    155     if (LLVM_UNLIKELY(mNestingDepth != 0)) {
    156         throw std::runtime_error("Non-zero nesting depth error (" + std::to_string(mNestingDepth) + ")");
     159    if (LLVM_UNLIKELY(mWhileDepth != 0)) {
     160        throw std::runtime_error("Non-zero nesting depth error (" + std::to_string(mWhileDepth) + ")");
    157161    }
    158162
     
    369373//
    370374// Examine precomputes some CarryNumbering and AdvanceNumbering, as
    371 // well as mMaxNestingDepth of while loops.
     375// well as mMaxWhileDepth of while loops.
    372376//
    373377unsigned PabloCompiler::Examine(PabloBlock & blk, unsigned carryDataIndexIn) {
     
    397401        }
    398402        else if (If * ifStatement = dyn_cast<If>(stmt)) {
     403            ++mIfDepth;
    399404            const auto ifCarryDataSize = Examine(ifStatement->getBody(), carryDataIndex);
     405            --mIfDepth;
    400406            nestedCarryDataSize += ifCarryDataSize;
    401407            carryDataIndex += ifCarryDataSize;
    402408        }
    403409        else if (While * whileStatement = dyn_cast<While>(stmt)) {
    404             mMaxNestingDepth = std::max(mMaxNestingDepth, ++mNestingDepth);
     410            mMaxWhileDepth = std::max(mMaxWhileDepth, ++mWhileDepth);
    405411            const auto whileCarryDataSize = Examine(whileStatement->getBody(), carryDataIndex);
    406             --mNestingDepth;
     412            --mWhileDepth;
    407413            nestedCarryDataSize += whileCarryDataSize;
    408414            carryDataIndex += whileCarryDataSize;
     
    413419    blk.setLocalAdvanceCount(localAdvances);
    414420    unsigned totalCarryDataSize = localCarries + localAdvances + nestedCarryDataSize;
    415     if (totalCarryDataSize > 1) {
     421    if ((mIfDepth > 0) && (totalCarryDataSize > 1)) {
    416422        // Need extra space for the summary variable, always the last
    417         // entry within the block.
     423        // entry within an if block.
    418424        totalCarryDataSize += 1;
    419425    }
     
    506512                int s = mCarryDataSummaryIdx[c];
    507513                if (s == -1) {
    508                     Value* carryq_value = mCarryDataVector[c];
     514                    Value* carryq_value = mCarryOutVector[c];
    509515                    if (carry_summary == mZeroInitializer) {
    510516                        carry_summary = carryq_value;
     
    534540            PHINode * summary_phi = bEnd.CreatePHI(mBitBlockType, 2, "summary");
    535541            summary_phi->addIncoming(mZeroInitializer, ifEntryBlock);
    536             summary_phi->addIncoming(mCarryDataVector[carrySummaryIndex], mBasicBlock);
    537             mCarryDataVector[carrySummaryIndex] = summary_phi;
     542            summary_phi->addIncoming(mCarryOutVector[carrySummaryIndex], mBasicBlock);
     543            mCarryOutVector[carrySummaryIndex] = summary_phi;
    538544        }
    539545       
     
    546552        const unsigned carryDataSize = whileStatement->getBody().getTotalCarryDataSize();
    547553   
    548         if (mNestingDepth == 0) {
     554        if (mWhileDepth == 0) {
    549555            for (auto i = 0; i < carryDataSize; ++i) {
    550556                genCarryDataLoad(baseCarryDataIdx + i);
     
    560566
    561567        // Compile the initial iteration statements; the calls to genCarryDataStore will update the
    562         // mCarryDataVector with the appropriate values. Although we're not actually entering a new basic
     568        // mCarryOutVector with the appropriate values. Although we're not actually entering a new basic
    563569        // block yet, increment the nesting depth so that any calls to genCarryDataLoad or genCarryDataStore
    564570        // will refer to the previous value.
    565571
    566         ++mNestingDepth;
     572        ++mWhileDepth;
    567573
    568574        compileBlock(whileStatement->getBody());
     
    588594        for (index = 0; index < carryDataSize; ++index) {
    589595            PHINode * phi = bCond.CreatePHI(mBitBlockType, 2);
    590             phi->addIncoming(mCarryDataVector[baseCarryDataIdx + index], mBasicBlock);
    591             mCarryDataVector[baseCarryDataIdx + index] = mZeroInitializer; // (use phi for multi-carry mode.)
     596            phi->addIncoming(mCarryOutVector[baseCarryDataIdx + index], mBasicBlock);
     597            mCarryInVector[baseCarryDataIdx + index] = mZeroInitializer; // (use phi for multi-carry mode.)
    592598            phiNodes[index] = phi;
    593599        }
     
    606612
    607613        // BODY BLOCK
     614        std::cerr << "Compile loop body\n";
    608615        mBasicBlock = whileBodyBlock;
    609616        compileBlock(whileStatement->getBody());
     
    611618        IRBuilder<> bWhileBody(mBasicBlock);
    612619        for (index = 0; index < carryDataSize; ++index) {
    613             Value * carryOut = bWhileBody.CreateOr(phiNodes[index], mCarryDataVector[baseCarryDataIdx + index]);
    614620            PHINode * phi = phiNodes[index];
     621            Value * carryOut = bWhileBody.CreateOr(phi, mCarryOutVector[baseCarryDataIdx + index]);
    615622            phi->addIncoming(carryOut, mBasicBlock);
    616             mCarryDataVector[baseCarryDataIdx + index] = phi;
    617         }
     623            mCarryOutVector[baseCarryDataIdx + index] = phi;
     624        }
     625       
    618626        // and for any Next nodes in the loop body
    619627        for (const Next * n : nextNodes) {
     
    629637        // EXIT BLOCK
    630638        mBasicBlock = whileEndBlock;
    631         if (--mNestingDepth == 0) {
     639        if (--mWhileDepth == 0) {
    632640            for (index = 0; index < carryDataSize; ++index) {
    633641                genCarryDataStore(phiNodes[index], baseCarryDataIdx + index);
     
    879887//#define CARRY_DEBUG
    880888Value* PabloCompiler::genCarryDataLoad(const unsigned index) {
    881     assert (index < mCarryDataVector.size());
    882     if (mNestingDepth == 0) {
     889    assert (index < mCarryInVector.size());
     890    if (mWhileDepth == 0) {
    883891        IRBuilder<> b(mBasicBlock);
    884         mCarryDataVector[index] = b.CreateAlignedLoad(b.CreateGEP(mCarryDataPtr, b.getInt64(index)), BLOCK_SIZE/8, false);
     892        mCarryInVector[index] = b.CreateAlignedLoad(b.CreateGEP(mCarryDataPtr, b.getInt64(index)), BLOCK_SIZE/8, false);
    885893    }
    886894#ifdef CARRY_DEBUG
    887     genPrintRegister("carry_in_" + std::to_string(index), mCarryDataVector[index]);
     895    genPrintRegister("carry_in_" + std::to_string(index), mCarryInVector[index]);
    888896#endif
    889     return mCarryDataVector[index];
     897    return mCarryInVector[index];
    890898}
    891899
    892900void PabloCompiler::genCarryDataStore(Value* carryOut, const unsigned index ) {
    893901    assert (carryOut);
    894     assert (index < mCarryDataVector.size());
    895     if (mNestingDepth == 0) {
     902    assert (index < mCarryOutVector.size());
     903    if (mWhileDepth == 0) {
    896904        IRBuilder<> b(mBasicBlock);
    897905        b.CreateAlignedStore(carryOut, b.CreateGEP(mCarryDataPtr, b.getInt64(index)), BLOCK_SIZE/8, false);
     
    899907    mCarryDataSummaryIdx[index] = -1;
    900908#ifdef CARRY_DEBUG
    901     genPrintRegister("carry_out_" + std::to_string(index), mCarryDataVector[index]);
     909    genPrintRegister("carry_out_" + std::to_string(index), mCarryOutVector[index]);
    902910#endif
    903     mCarryDataVector[index] = carryOut;
     911    mCarryOutVector[index] = carryOut;
     912    std::cerr << "mCarryOutVector[" << index << "]]\n";
    904913}
    905914
Note: See TracChangeset for help on using the changeset viewer.