Skip to content

Commit 972a170

Browse files
mtrofinAlexisPerry
authored andcommitted
[mlgo] add 2 new features whether caller/callee is available_externally (llvm#96585)
AvailableExternally linkage is interesting because, in ThinLTO cases, it means the function may get elided if it survives inlining - see `elim-avail-extern` pass.
1 parent ee3a8b1 commit 972a170

File tree

4 files changed

+37
-1
lines changed

4 files changed

+37
-1
lines changed

llvm/include/llvm/Analysis/InlineModelFeatureMaps.h

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -121,7 +121,15 @@ constexpr bool isHeuristicInlineCostFeature(InlineCostFeatureIndex Feature) {
121121
"number of blocks reached from a conditional instruction, in the callee") \
122122
M(int64_t, {1}, callee_users, \
123123
"number of module-internal users of the callee, +1 if the callee is " \
124-
"exposed externally")
124+
"exposed externally") \
125+
M(int64_t, {1}, is_callee_avail_external, \
126+
"Is callee an available-externally linkage type (i.e. could be DCEd if " \
127+
"not " \
128+
"fully inlined by ElimAvailExtern)") \
129+
M(int64_t, {1}, is_caller_avail_external, \
130+
"Is caller an available-externally linkage type (i.e. could be DCEd if " \
131+
"not " \
132+
"fully inlined by ElimAvailExtern)")
125133

126134
// clang-format off
127135
enum class FeatureIndex : size_t {

llvm/lib/Analysis/MLInlineAdvisor.cpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -427,6 +427,10 @@ std::unique_ptr<InlineAdvice> MLInlineAdvisor::getAdviceImpl(CallBase &CB) {
427427
*ModelRunner->getTensor<int64_t>(FeatureIndex::callee_users) =
428428
CalleeBefore.Uses;
429429
*ModelRunner->getTensor<int64_t>(FeatureIndex::cost_estimate) = CostEstimate;
430+
*ModelRunner->getTensor<int64_t>(FeatureIndex::is_callee_avail_external) =
431+
Callee.hasAvailableExternallyLinkage();
432+
*ModelRunner->getTensor<int64_t>(FeatureIndex::is_caller_avail_external) =
433+
Caller.hasAvailableExternallyLinkage();
430434

431435
// Add the cost features
432436
for (size_t I = 0;

llvm/lib/Analysis/models/gen-inline-oz-test-model.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,8 @@ def get_input_signature():
7171
"nested_inlines",
7272
"nested_inline_cost_estimate",
7373
"threshold",
74+
"is_callee_avail_external",
75+
"is_caller_avail_external",
7476
]
7577
]
7678

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
; REQUIRES: x86_64-linux
2+
; RUN: rm -rf %t.rundir
3+
; RUN: rm -rf %t.channel-basename.*
4+
; RUN: mkdir %t.rundir
5+
; RUN: cp %S/../../../../lib/Analysis/models/log_reader.py %t.rundir
6+
; RUN: cp %S/../../../../lib/Analysis/models/interactive_host.py %t.rundir
7+
; RUN: cp %S/Inputs/interactive_main.py %t.rundir
8+
; RUN: %python %t.rundir/interactive_main.py %t.channel-basename \
9+
; RUN: opt -passes=scc-oz-module-inliner -interactive-model-runner-echo-reply \
10+
; RUN: -enable-ml-inliner=release -inliner-interactive-channel-base=%t.channel-basename %s -S -o /dev/null | FileCheck %s
11+
12+
define available_externally void @g() {
13+
ret void
14+
}
15+
16+
define void @f(){
17+
call void @g()
18+
ret void
19+
}
20+
21+
; CHECK: is_callee_avail_external: 1
22+
; CHECK: is_caller_avail_external: 0

0 commit comments

Comments
 (0)