Changeset 5169


Ignore:
Timestamp:
Sep 28, 2016, 9:00:20 AM (3 years ago)
Author:
cameron
Message:

Preparing for Pablo bounded while statements

File:
1 edited

Legend:

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

    r5160 r5169  
    209209    std::vector<PHINode *> nextPhis;
    210210    nextPhis.reserve(nextNodes.size());
    211 
     211#ifdef ENABLE_BOUNDED_WHILE
     212    PHINode * bound_phi = nullptr;  // Needed for bounded while loops.
     213#endif
    212214    // On entry to the while structure, proceed to execute the first iteration
    213215    // of the loop body unconditionally.   The while condition is tested at the end of
     
    222224    // (2) Carry-out accumulators: (a) zero first iteration, (b) |= carry-out of each iteration
    223225    // (3) Next nodes: (a) values set up before loop, (b) modified values calculated in loop.
     226#ifdef ENABLE_BOUNDED_WHILE
     227    // (4) The loop bound, if any.
     228#endif
    224229
    225230    mCarryManager->initializeWhileEntryCarryDataPhis(whileEntryBlock);
     
    235240        nextPhis.push_back(phi);
    236241    }
     242#ifdef ENABLE_BOUNDED_WHILE
     243    if (whileStatement->getBound()) {
     244        PHINode * bound_phi = iBuilder->CreatePHI(iBuilder->getSizeTy());
     245        bound_phi->addIncoming(ConstantInt::get(iBuilder->getSizeTy(), whileStatement->getBound()));
     246    }
     247#endif
    237248
    238249    //
     
    242253    compileBlock(whileBody);
    243254
     255    // After the whileBody has been compiled, we may be in a different basic block.
    244256    BasicBlock * whileExitBlock = iBuilder->GetInsertBlock();
    245257
     
    250262
    251263    // Terminate the while loop body with a conditional branch back.
    252     iBuilder->CreateCondBr(iBuilder->bitblock_any(compileExpression(whileStatement->getCondition())), whileBodyBlock, whileEndBlock);
     264    Value * cond_expr = iBuilder->bitblock_any(compileExpression(whileStatement->getCondition()));
     265#ifdef ENABLE_BOUNDED_WHILE
     266    if (whileStatement->getBound()) {
     267        Value * new_bound = iBuilder->CreateSub(bound_phi, ConstantInt::get(iBuilder->getSizeTy(), 1));
     268        bound_phi->addIncoming(new_bound, whileExitBlock)));
     269        cond_expr = iBuilder->CreateAnd(cond_expr, iBuilder->CreateCmpGE(new_bound, ConstantInt::GetNullValue(iBuilder->getSizeTy()));
     270    }
     271#endif   
     272    iBuilder->CreateCondBr(cond_expr, whileBodyBlock, whileEndBlock);
    253273
    254274    // and for any Next nodes in the loop body
Note: See TracChangeset for help on using the changeset viewer.