/// block of the inlined code (the last block is the end of the function),
/// and InlineCodeInfo is information about the code that got inlined.
static void HandleInlinedInvoke(InvokeInst *II, BasicBlock *FirstNewBlock,
- ClonedCodeInfo &InlinedCodeInfo) {
+ ClonedCodeInfo &InlinedCodeInfo,
+ CallGraph *CG) {
BasicBlock *InvokeDest = II->getUnwindDest();
std::vector<Value*> InvokeDestPHIValues;
// Make sure that anything using the call now uses the invoke!
CI->replaceAllUsesWith(II);
+ // Update the callgraph.
+ if (CG) {
+ // We should be able to do this:
+ // (*CG)[Caller]->replaceCallSite(CI, II);
+ // but that fails if the old call site isn't in the call graph,
+ // which, because of LLVM bug 3601, it sometimes isn't.
+ CallGraphNode *CGN = (*CG)[Caller];
+ for (CallGraphNode::iterator NI = CGN->begin(), NE = CGN->end();
+ NI != NE; ++NI) {
+ if (NI->first == CI) {
+ NI->first = II;
+ break;
+ }
+ }
+ }
+
// Delete the unconditional branch inserted by splitBasicBlock
BB->getInstList().pop_back();
Split->getInstList().pop_front(); // Delete the original call
// any inlined 'unwind' instructions into branches to the invoke exception
// destination, and call instructions into invoke instructions.
if (InvokeInst *II = dyn_cast<InvokeInst>(TheCall))
- HandleInlinedInvoke(II, FirstNewBlock, InlinedFunctionInfo);
+ HandleInlinedInvoke(II, FirstNewBlock, InlinedFunctionInfo, CG);
// If we cloned in _exactly one_ basic block, and if that block ends in a
// return instruction, we splice the body of the inlined callee directly into