Ignore:
Timestamp:
Oct 22, 2014, 10:38:57 AM (5 years ago)
Author:
nmedfort
Message:

Couple changes in preperation for using phi nodes for test/accum variables.

File:
1 edited

Legend:

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

    r4257 r4258  
    516516    if (const Assign * assign = dyn_cast<const Assign>(stmt))
    517517    {
    518         Value * expr = compileExpression(assign->getExpr());
    519         Value * marker = GetMarker(assign->getName());
     518        Value* expr = compileExpression(assign->getExpr());
     519        Value* marker = GetMarker(assign->getName());
    520520        IRBuilder<> b(mBasicBlock);
    521521        b.CreateAlignedStore(expr, marker, BLOCK_SIZE/8, false);
     
    535535    {
    536536        BasicBlock * ifEntryBlock = mBasicBlock;
    537         BasicBlock * ifBodyBlock = BasicBlock::Create(mMod->getContext(), "if.body",mFunc_process_block, 0);
    538         BasicBlock * ifEndBlock = BasicBlock::Create(mMod->getContext(), "if.end",mFunc_process_block, 0);
     537        BasicBlock * ifBodyBlock = BasicBlock::Create(mMod->getContext(), "if.body", mFunc_process_block, 0);
     538        BasicBlock * ifEndBlock = BasicBlock::Create(mMod->getContext(), "if.end", mFunc_process_block, 0);
    539539
    540540        int if_start_idx = mCarryQueueIdx;
     
    545545           final carry index.  */
    546546
    547         IRBuilder<> b_ifbody(ifBodyBlock);
     547        IRBuilder<> bIfBody(ifBodyBlock);
    548548        mBasicBlock = ifBodyBlock;
    549549
     
    562562            {
    563563                Value* carryq_value = genCarryInLoad(c);
    564                 if_carry_accum_value = b_ifbody.CreateOr(carryq_value, if_carry_accum_value);
     564                if_carry_accum_value = bIfBody.CreateOr(carryq_value, if_carry_accum_value);
    565565            }
    566566            genCarryOutStore(if_carry_accum_value, if_accum_idx);
    567567
    568568        }
    569         b_ifbody.CreateBr(ifEndBlock);
     569        bIfBody.CreateBr(ifEndBlock);
    570570
    571571        IRBuilder<> b_entry(ifEntryBlock);
     
    584584        retVal = returnMarker;
    585585    }
    586     else if (const While* whl = dyn_cast<const While>(stmt))
    587     {
    588         BasicBlock* entryBlock = mBasicBlock;
    589 
     586    else if (const While * whl = dyn_cast<const While>(stmt))
     587    {
    590588        const auto baseCarryQueueIdx = mCarryQueueIdx;
    591589        if (mNestingDepth == 0) {
     
    596594
    597595        // First compile the initial iteration statements; the calls to genCarryOutStore will update the
    598         // mCarryQueueVector with the appropriate values.
     596        // mCarryQueueVector with the appropriate values. Although we're not actually entering a new basic
     597        // block yet, increment the nesting depth so that any calls to genCarryInLoad or genCarryOutStore
     598        // will refer to the previous value.
    599599        ++mNestingDepth;
    600         Value * returnMarker = compileStatements(whl->getBody());
    601 
     600        compileStatements(whl->getBody());
     601        // Reset the carry queue index. Note: this ought to be changed in the future. Currently this assumes
     602        // that compiling the while body twice will generate the equivalent IR. This is not necessarily true
     603        // but works for now.
    602604        mCarryQueueIdx = baseCarryQueueIdx;
    603605
     
    606608        BasicBlock* whileEndBlock = BasicBlock::Create(mMod->getContext(), "while.end", mFunc_process_block, 0);
    607609
    608         IRBuilder<> b(mBasicBlock);
    609         b.CreateBr(whileCondBlock);
     610        // Note: compileStatements may update the mBasicBlock pointer if the body contains nested loops. Do not
     611        // assume it is the same one in which we entered the function with.
     612        IRBuilder<> bEntry(mBasicBlock);
     613        bEntry.CreateBr(whileCondBlock);
    610614
    611615        // CONDITION BLOCK
     
    616620            PHINode * phi = bCond.CreatePHI(mXi64Vect, 2);
    617621            phi->addIncoming(mCarryQueueVector[baseCarryQueueIdx + i], mBasicBlock);
    618             mCarryQueueVector[baseCarryQueueIdx + i] = mZeroInitializer; // phi;
     622            mCarryQueueVector[baseCarryQueueIdx + i] = mZeroInitializer; // phi; // (use phi for multi-carry mode.)
    619623            carryQueuePhiNodes[i] = phi;
    620624        }
     
    625629        // BODY BLOCK
    626630        mBasicBlock = whileBodyBlock;
    627         returnMarker = compileStatements(whl->getBody());
     631        retVal = compileStatements(whl->getBody());
    628632        // update phi nodes for any carry propogating instruction
    629633        IRBuilder<> bWhileBody(mBasicBlock);
     
    643647            }
    644648        }
    645         retVal = returnMarker;
    646649    }
    647650    return retVal;
     
    783786}
    784787
    785 Value* PabloCompiler::genCarryInLoad(const unsigned index) {
    786     IRBuilder<> b(mBasicBlock);
     788Value* PabloCompiler::genCarryInLoad(const unsigned index) {   
     789    assert (index < mCarryQueueVector.size());
    787790    if (mNestingDepth == 0) {
    788         LoadInst * carryIn = b.CreateAlignedLoad(b.CreateGEP(mCarryQueuePtr, b.getInt64(index)), BLOCK_SIZE/8, false);
    789         mCarryQueueVector[index] = carryIn;
    790         return carryIn;
    791     }
    792     else { // we're in a potentially-nested while/if block
    793         assert (index < mCarryQueueVector.size());
    794         return mCarryQueueVector[index];
    795     }
     791        IRBuilder<> b(mBasicBlock);
     792        mCarryQueueVector[index] = b.CreateAlignedLoad(b.CreateGEP(mCarryQueuePtr, b.getInt64(index)), BLOCK_SIZE/8, false);
     793    }
     794    return mCarryQueueVector[index];
    796795}
    797796
    798797void PabloCompiler::genCarryOutStore(Value* carryOut, const unsigned index ) {
    799     IRBuilder<> b(mBasicBlock);
    800798    assert (carryOut);
    801799    assert (index < mCarryQueueVector.size());
    802     if (mNestingDepth == 0) {
     800    if (mNestingDepth == 0) {       
     801        IRBuilder<> b(mBasicBlock);
    803802        b.CreateAlignedStore(carryOut, b.CreateGEP(mCarryQueuePtr, b.getInt64(index)), BLOCK_SIZE/8, false);
    804803    }
     
    806805}
    807806
    808 inline Value* PabloCompiler::genBitBlockAny(Value* e) {
     807inline Value* PabloCompiler::genBitBlockAny(Value* test) {
    809808    IRBuilder<> b(mBasicBlock);
    810     Value* cast_marker_value_1 = b.CreateBitCast(e, IntegerType::get(mMod->getContext(), BLOCK_SIZE));
     809    Value* cast_marker_value_1 = b.CreateBitCast(test, IntegerType::get(mMod->getContext(), BLOCK_SIZE));
    811810    return b.CreateICmpEQ(cast_marker_value_1, ConstantInt::get(IntegerType::get(mMod->getContext(), BLOCK_SIZE), 0));
    812811}
Note: See TracChangeset for help on using the changeset viewer.