summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorNick Lewycky <nicholas@mxc.ca>2009-02-03 04:34:40 +0000
committerNick Lewycky <nicholas@mxc.ca>2009-02-03 04:34:40 +0000
commit12a130bd06ac94c20e1cf60c2ed9592c056c5e04 (patch)
tree95c47d076456aced73a4c5ccf18d9dc0d8e38a05
parent67cd395d4575ebf48bdf4fa4eda6eec7c2358cf3 (diff)
downloadbcm5719-llvm-12a130bd06ac94c20e1cf60c2ed9592c056c5e04.tar.gz
bcm5719-llvm-12a130bd06ac94c20e1cf60c2ed9592c056c5e04.zip
Update the callgraph when replacing InvokeInst with CallInst when inlining.
llvm-svn: 63600
-rw-r--r--llvm/lib/Transforms/Utils/InlineFunction.cpp11
-rw-r--r--llvm/test/Transforms/Inline/2009-02-02-InvokeUpdateCG.ll32
2 files changed, 40 insertions, 3 deletions
diff --git a/llvm/lib/Transforms/Utils/InlineFunction.cpp b/llvm/lib/Transforms/Utils/InlineFunction.cpp
index cee224aae52..eb136b50349 100644
--- a/llvm/lib/Transforms/Utils/InlineFunction.cpp
+++ b/llvm/lib/Transforms/Utils/InlineFunction.cpp
@@ -37,11 +37,12 @@ bool llvm::InlineFunction(InvokeInst *II, CallGraph *CG, const TargetData *TD) {
/// in the body of the inlined function into invokes and turn unwind
/// instructions into branches to the invoke unwind dest.
///
-/// II is the invoke instruction begin inlined. FirstNewBlock is the first
+/// II is the invoke instruction being inlined. FirstNewBlock is the first
/// 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;
@@ -93,6 +94,10 @@ static void HandleInlinedInvoke(InvokeInst *II, BasicBlock *FirstNewBlock,
// Make sure that anything using the call now uses the invoke!
CI->replaceAllUsesWith(II);
+ // Update the callgraph.
+ if (CG)
+ (*CG)[Caller]->replaceCallSite(CI, II);
+
// Delete the unconditional branch inserted by splitBasicBlock
BB->getInstList().pop_back();
Split->getInstList().pop_front(); // Delete the original call
@@ -433,7 +438,7 @@ bool llvm::InlineFunction(CallSite CS, CallGraph *CG, const TargetData *TD) {
// 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
diff --git a/llvm/test/Transforms/Inline/2009-02-02-InvokeUpdateCG.ll b/llvm/test/Transforms/Inline/2009-02-02-InvokeUpdateCG.ll
new file mode 100644
index 00000000000..38d759656f2
--- /dev/null
+++ b/llvm/test/Transforms/Inline/2009-02-02-InvokeUpdateCG.ll
@@ -0,0 +1,32 @@
+; RUN: llvm-as < %s | opt -inline -prune-eh
+; PR3367
+
+define void @f2() {
+ invoke void @f6()
+ to label %ok1 unwind label %lpad1
+
+ok1:
+ ret void
+
+lpad1:
+ invoke void @f4()
+ to label %ok2 unwind label %lpad2
+
+ok2:
+ call void @f8()
+ unreachable
+
+lpad2:
+ unreachable
+}
+
+declare void @f3()
+
+define void @f4() {
+ call void @f3()
+ ret void
+}
+
+declare void @f6() nounwind
+
+declare void @f8()
OpenPOWER on IntegriCloud