Skip to content

Commit 12a130b

Browse files
committed
Update the callgraph when replacing InvokeInst with CallInst when inlining.
llvm-svn: 63600
1 parent 67cd395 commit 12a130b

File tree

2 files changed

+40
-3
lines changed

2 files changed

+40
-3
lines changed

llvm/lib/Transforms/Utils/InlineFunction.cpp

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -37,11 +37,12 @@ bool llvm::InlineFunction(InvokeInst *II, CallGraph *CG, const TargetData *TD) {
3737
/// in the body of the inlined function into invokes and turn unwind
3838
/// instructions into branches to the invoke unwind dest.
3939
///
40-
/// II is the invoke instruction begin inlined. FirstNewBlock is the first
40+
/// II is the invoke instruction being inlined. FirstNewBlock is the first
4141
/// block of the inlined code (the last block is the end of the function),
4242
/// and InlineCodeInfo is information about the code that got inlined.
4343
static void HandleInlinedInvoke(InvokeInst *II, BasicBlock *FirstNewBlock,
44-
ClonedCodeInfo &InlinedCodeInfo) {
44+
ClonedCodeInfo &InlinedCodeInfo,
45+
CallGraph *CG) {
4546
BasicBlock *InvokeDest = II->getUnwindDest();
4647
std::vector<Value*> InvokeDestPHIValues;
4748

@@ -93,6 +94,10 @@ static void HandleInlinedInvoke(InvokeInst *II, BasicBlock *FirstNewBlock,
9394
// Make sure that anything using the call now uses the invoke!
9495
CI->replaceAllUsesWith(II);
9596

97+
// Update the callgraph.
98+
if (CG)
99+
(*CG)[Caller]->replaceCallSite(CI, II);
100+
96101
// Delete the unconditional branch inserted by splitBasicBlock
97102
BB->getInstList().pop_back();
98103
Split->getInstList().pop_front(); // Delete the original call
@@ -433,7 +438,7 @@ bool llvm::InlineFunction(CallSite CS, CallGraph *CG, const TargetData *TD) {
433438
// any inlined 'unwind' instructions into branches to the invoke exception
434439
// destination, and call instructions into invoke instructions.
435440
if (InvokeInst *II = dyn_cast<InvokeInst>(TheCall))
436-
HandleInlinedInvoke(II, FirstNewBlock, InlinedFunctionInfo);
441+
HandleInlinedInvoke(II, FirstNewBlock, InlinedFunctionInfo, CG);
437442

438443
// If we cloned in _exactly one_ basic block, and if that block ends in a
439444
// return instruction, we splice the body of the inlined callee directly into
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
; RUN: llvm-as < %s | opt -inline -prune-eh
2+
; PR3367
3+
4+
define void @f2() {
5+
invoke void @f6()
6+
to label %ok1 unwind label %lpad1
7+
8+
ok1:
9+
ret void
10+
11+
lpad1:
12+
invoke void @f4()
13+
to label %ok2 unwind label %lpad2
14+
15+
ok2:
16+
call void @f8()
17+
unreachable
18+
19+
lpad2:
20+
unreachable
21+
}
22+
23+
declare void @f3()
24+
25+
define void @f4() {
26+
call void @f3()
27+
ret void
28+
}
29+
30+
declare void @f6() nounwind
31+
32+
declare void @f8()

0 commit comments

Comments
 (0)