Executor/Execution.cpp
// SwitchToNewBasicBlock - This method is used to jump to a new basic block.
// This function handles the actual updating of block and instruction iterators
// as well as execution of all of the PHI nodes in the destination block.
//
// This method does this because all of the PHI nodes must be executed
// atomically, reading their inputs before any of the results are updated.  Not
// doing this can cause problems if the PHI nodes depend on other PHI nodes for
// their inputs.  If the input PHI node is updated before it is read, incorrect
// results can happen.  Thus we use a two phase approach.
//
This method is used to jump to a new basic block.
This function handles the actual updating of block and instruction iterators
as well as execution of all of the PHI nodes in the destination block.

This method does this because all of the PHI nodes must be executed
atomically, reading their inputs before any of the results are updated.  Not
doing this can cause problems if the PHI nodes depend on other PHI nodes for
their inputs.  If the input PHI node is updated before it is read, incorrect
results can happen.  Thus we use a two phase approach.
This method is used to jump to a new basic block . This function handles the actual updating of block and instruction iterators as well as execution of all of the PHI nodes in the destination block . This method does this because all of the PHI nodes must be executed atomically reading their inputs before any of the results are updated . Not doing this can cause problems if the PHI nodes depend on other PHI nodes for their inputs . If the input PHI node is updated before it is read incorrect results can happen . Thus we use a two phase approach .
void borealis::ExecutionEngine::SwitchToNewBasicBlock(BasicBlock *Dest, ExecutorContext &SF){
    TRACE_FUNC;
    BasicBlock *PrevBB = SF.CurBB;      
    SF.CurBB   = Dest;                  
    SF.CurInst = SF.CurBB->begin();     
    if (!isa<PHINode>(SF.CurInst)) return;  
    std::vector<GenericValue> ResultValues;
    for (; PHINode *PN = dyn_cast<PHINode>(SF.CurInst); ++SF.CurInst) {
        int i = PN->getBasicBlockIndex(PrevBB);
        ASSERTC(i != -1 && "PHINode doesn't contain entry for predecessor??");
        Value *IncomingValue = PN->getIncomingValue(i);
        ResultValues.push_back(getOperandValue(IncomingValue, SF));
    }
    SF.CurInst = SF.CurBB->begin();
    for (unsigned i = 0; isa<PHINode>(SF.CurInst); ++SF.CurInst, ++i) {
        PHINode *PN = cast<PHINode>(SF.CurInst);
        SetValue(PN, ResultValues[i], SF);
    }
}
void borealis :: ExecutionEngine :: SwitchToNewBasicBlock ( BasicBlock * Dest , ExecutorContext & SF ) { TRACE_FUNC ; BasicBlock * PrevBB = SF . CurBB ; SF . CurBB = Dest ; SF . CurInst = SF . CurBB -> begin ( ) ; if ( ! isa < PHINode > ( SF . CurInst ) ) return ; std :: vector < GenericValue > ResultValues ; for ( ; PHINode * PN = dyn_cast < PHINode > ( SF . CurInst ) ; ++ SF . CurInst ) { int i = PN -> getBasicBlockIndex ( PrevBB ) ; ASSERTC ( i != -1 && " " ) ; Value * IncomingValue = PN -> getIncomingValue ( i ) ; ResultValues . push_back ( getOperandValue ( IncomingValue , SF ) ) ; } SF . CurInst = SF . CurBB -> begin ( ) ; for ( unsigned i = 0 ; isa < PHINode > ( SF . CurInst ) ; ++ SF . CurInst , ++ i ) { PHINode * PN = cast < PHINode > ( SF . CurInst ) ; SetValue ( PN , ResultValues [ i ] , SF ) ; } }
SwitchToNewBasicBlock - This method is used to jump to a new basic block.
SwitchToNewBasicBlock - This method is used to jump to a new basic block .
// Remember where we came from... // Update CurBB to branch destination // Update new instruction ptr... // Nothing fancy to do // Loop over all of the PHI nodes in the current block, reading their inputs. // Search for the value corresponding to this previous bb... // Save the incoming value for this PHI node... // Now loop over all of the PHI nodes setting their values...