Skip to content

Commit 64314de

Browse files
authored
[InlineCost] Print inline cost for invoke call sites as well (#114476)
Previously InlineCostAnnotationPrinter only prints inline cost for call instructions. I don't think there is any reason not to analyze invoke and its callee, and this patch adds such support.
1 parent faa385a commit 64314de

File tree

2 files changed

+35
-4
lines changed

2 files changed

+35
-4
lines changed

llvm/lib/Analysis/InlineCost.cpp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3257,16 +3257,16 @@ InlineCostAnnotationPrinterPass::run(Function &F,
32573257
const InlineParams Params = llvm::getInlineParams();
32583258
for (BasicBlock &BB : F) {
32593259
for (Instruction &I : BB) {
3260-
if (CallInst *CI = dyn_cast<CallInst>(&I)) {
3261-
Function *CalledFunction = CI->getCalledFunction();
3260+
if (auto *CB = dyn_cast<CallBase>(&I)) {
3261+
Function *CalledFunction = CB->getCalledFunction();
32623262
if (!CalledFunction || CalledFunction->isDeclaration())
32633263
continue;
32643264
OptimizationRemarkEmitter ORE(CalledFunction);
3265-
InlineCostCallAnalyzer ICCA(*CalledFunction, *CI, Params, TTI,
3265+
InlineCostCallAnalyzer ICCA(*CalledFunction, *CB, Params, TTI,
32663266
GetAssumptionCache, nullptr, &PSI, &ORE);
32673267
ICCA.analyze();
32683268
OS << " Analyzing call of " << CalledFunction->getName()
3269-
<< "... (caller:" << CI->getCaller()->getName() << ")\n";
3269+
<< "... (caller:" << CB->getCaller()->getName() << ")\n";
32703270
ICCA.print(OS);
32713271
OS << "\n";
32723272
}

llvm/test/Transforms/Inline/inline-cost-annotation-pass.ll

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,3 +33,34 @@ define ptr @main() {
3333
%2 = call ptr @foo()
3434
ret ptr %1
3535
}
36+
37+
; Make sure it also analyzes invoke call sites.
38+
39+
; CHECK: Analyzing call of g... (caller:f)
40+
; CHECK: define i32 @g(i32 %v) {
41+
; CHECK: ; cost before = {{.*}}, cost after = {{.*}}, threshold before = {{.*}}, threshold after = {{.*}}, cost delta = {{.*}}
42+
; CHECK: %p = icmp ugt i32 %v, 35
43+
; CHECK: ; cost before = {{.*}}, cost after = {{.*}}, threshold before = {{.*}}, threshold after = {{.*}}, cost delta = {{.*}}
44+
; CHECK: %r = select i1 %p, i32 %v, i32 7
45+
; CHECK: ; cost before = {{.*}}, cost after = {{.*}}, threshold before = {{.*}}, threshold after = {{.*}}, cost delta = {{.*}}
46+
; CHECK: ret i32 %r
47+
; CHECK: }
48+
define i32 @g(i32 %v) {
49+
%p = icmp ugt i32 %v, 35
50+
%r = select i1 %p, i32 %v, i32 7
51+
ret i32 %r
52+
}
53+
54+
define void @f(i32 %v, ptr %dst) personality ptr @__gxx_personality_v0 {
55+
%v1 = invoke i32 @g(i32 %v)
56+
to label %bb1 unwind label %bb2
57+
bb1:
58+
store i32 %v1, ptr %dst
59+
ret void
60+
bb2:
61+
%lpad.loopexit80 = landingpad { ptr, i32 }
62+
cleanup
63+
ret void
64+
}
65+
66+
declare i32 @__gxx_personality_v0(...)

0 commit comments

Comments
 (0)