liberty/lib/Utilities/InlineFunctionWithVmap.cpp
/// HandleCallsInBlockInlinedThroughInvoke - When we inline a basic block into
/// an invoke, we have to turn all of the calls that can throw into
/// invokes.  This function analyze BB to see if there are any calls, and if so,
/// it rewrites them to be invokes that jump to InvokeDest and fills in the PHI
/// nodes in that block with the values specified in InvokeDestPHIValues.
///
/// Returns true to indicate that the next block should be skipped.
When we inline a basic block into
an invoke, we have to turn all of the calls that can throw into
invokes.  This function analyze BB to see if there are any calls, and if so,
it rewrites them to be invokes that jump to InvokeDest and fills in the PHI
nodes in that block with the values specified in InvokeDestPHIValues.

Returns true to indicate that the next block should be skipped.
When we inline a basic block into an invoke we have to turn all of the calls that can throw into invokes . This function analyze BB to see if there are any calls and if so it rewrites them to be invokes that jump to InvokeDest and fills in the PHI nodes in that block with the values specified in InvokeDestPHIValues . Returns true to indicate that the next block should be skipped .
static bool HandleCallsInBlockInlinedThroughInvoke(BasicBlock *BB,
                                                   InvokeInliningInfo &Invoke,
                                                   CallsPromotedToInvoke &call2invoke) {
  LandingPadInst *LPI = Invoke.getLandingPadInst();
  for (BasicBlock::iterator BBI = BB->begin(), E = BB->end(); BBI != E; ) {
    Instruction *I = &*(BBI++);
    if (LandingPadInst *L = dyn_cast<LandingPadInst>(I)) {
      unsigned NumClauses = LPI->getNumClauses();
      L->reserveClauses(NumClauses);
      for (unsigned i = 0; i != NumClauses; ++i)
        L->addClause(LPI->getClause(i));
    }
    CallInst *CI = dyn_cast<CallInst>(I);
    if (!CI || CI->doesNotThrow())
      continue;
    BasicBlock *Split = BB->splitBasicBlock(CI, CI->getName()+".noexc");
    BB->getInstList().pop_back();
    ImmutableCallSite CS(CI);
    SmallVector<Value*, 8> InvokeArgs(CS.arg_begin(), CS.arg_end());
    InvokeInst *II = InvokeInst::Create(CI->getCalledValue(), Split,
                                        Invoke.getOuterResumeDest(),
                                        InvokeArgs, CI->getName(), BB);
    II->setCallingConv(CI->getCallingConv());
    II->setAttributes(CI->getAttributes());
    call2invoke.push_back(II);
    CI->replaceAllUsesWith(II);
    Split->getInstList().pop_front();
    Invoke.addIncomingPHIValuesFor(BB);
    return false;
  }
  return false;
}
static bool HandleCallsInBlockInlinedThroughInvoke ( BasicBlock * BB , InvokeInliningInfo & Invoke , CallsPromotedToInvoke & call2invoke ) { LandingPadInst * LPI = Invoke . getLandingPadInst ( ) ; for ( BasicBlock :: iterator BBI = BB -> begin ( ) , E = BB -> end ( ) ; BBI != E ; ) { Instruction * I = & * ( BBI ++ ) ; if ( LandingPadInst * L = dyn_cast < LandingPadInst > ( I ) ) { unsigned NumClauses = LPI -> getNumClauses ( ) ; L -> reserveClauses ( NumClauses ) ; for ( unsigned i = 0 ; i != NumClauses ; ++ i ) L -> addClause ( LPI -> getClause ( i ) ) ; } CallInst * CI = dyn_cast < CallInst > ( I ) ; if ( ! CI || CI -> doesNotThrow ( ) ) continue ; BasicBlock * Split = BB -> splitBasicBlock ( CI , CI -> getName ( ) + " " ) ; BB -> getInstList ( ) . pop_back ( ) ; ImmutableCallSite CS ( CI ) ; SmallVector < Value * , 8 > InvokeArgs ( CS . arg_begin ( ) , CS . arg_end ( ) ) ; InvokeInst * II = InvokeInst :: Create ( CI -> getCalledValue ( ) , Split , Invoke . getOuterResumeDest ( ) , InvokeArgs , CI -> getName ( ) , BB ) ; II -> setCallingConv ( CI -> getCallingConv ( ) ) ; II -> setAttributes ( CI -> getAttributes ( ) ) ; call2invoke . push_back ( II ) ; CI -> replaceAllUsesWith ( II ) ; Split -> getInstList ( ) . pop_front ( ) ; Invoke . addIncomingPHIValuesFor ( BB ) ; return false ; } return false ; }
HandleCallsInBlockInlinedThroughInvoke - When we inline a basic block into
an invoke, we have to turn all of the calls that can throw into
invokes.
HandleCallsInBlockInlinedThroughInvoke - When we inline a basic block into an invoke we have to turn all of the calls that can throw into invokes .
// We only need to check for function calls: inlined invoke // instructions require no special handling. // If this call cannot unwind, don't convert it to an invoke. // Convert this function call into an invoke instruction.  First, split the // basic block. // Delete the unconditional branch inserted by splitBasicBlock // Create the new invoke instruction. // Record this transformation // Make sure that anything using the call now uses the invoke!  This also // updates the CallGraph if present, because it uses a WeakVH. // Delete the original call // Update any PHI nodes in the exceptional block to indicate that there is // now a new entry in them.