Skip to content

[mlgo] add 2 new features whether caller/callee is available_externally #96585

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Jun 25, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 9 additions & 1 deletion llvm/include/llvm/Analysis/InlineModelFeatureMaps.h
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,15 @@ constexpr bool isHeuristicInlineCostFeature(InlineCostFeatureIndex Feature) {
"number of blocks reached from a conditional instruction, in the callee") \
M(int64_t, {1}, callee_users, \
"number of module-internal users of the callee, +1 if the callee is " \
"exposed externally")
"exposed externally") \
M(int64_t, {1}, is_callee_avail_external, \
"Is callee an available-externally linkage type (i.e. could be DCEd if " \
"not " \
"fully inlined by ElimAvailExtern)") \
M(int64_t, {1}, is_caller_avail_external, \
"Is caller an available-externally linkage type (i.e. could be DCEd if " \
"not " \
"fully inlined by ElimAvailExtern)")

// clang-format off
enum class FeatureIndex : size_t {
Expand Down
4 changes: 4 additions & 0 deletions llvm/lib/Analysis/MLInlineAdvisor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -427,6 +427,10 @@ std::unique_ptr<InlineAdvice> MLInlineAdvisor::getAdviceImpl(CallBase &CB) {
*ModelRunner->getTensor<int64_t>(FeatureIndex::callee_users) =
CalleeBefore.Uses;
*ModelRunner->getTensor<int64_t>(FeatureIndex::cost_estimate) = CostEstimate;
*ModelRunner->getTensor<int64_t>(FeatureIndex::is_callee_avail_external) =
Callee.hasAvailableExternallyLinkage();
*ModelRunner->getTensor<int64_t>(FeatureIndex::is_caller_avail_external) =
Caller.hasAvailableExternallyLinkage();

// Add the cost features
for (size_t I = 0;
Expand Down
2 changes: 2 additions & 0 deletions llvm/lib/Analysis/models/gen-inline-oz-test-model.py
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,8 @@ def get_input_signature():
"nested_inlines",
"nested_inline_cost_estimate",
"threshold",
"is_callee_avail_external",
"is_caller_avail_external",
]
]

Expand Down
22 changes: 22 additions & 0 deletions llvm/test/Transforms/Inline/ML/avail-external.ll
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
; REQUIRES: x86_64-linux
; RUN: rm -rf %t.rundir
; RUN: rm -rf %t.channel-basename.*
; RUN: mkdir %t.rundir
; RUN: cp %S/../../../../lib/Analysis/models/log_reader.py %t.rundir
; RUN: cp %S/../../../../lib/Analysis/models/interactive_host.py %t.rundir
; RUN: cp %S/Inputs/interactive_main.py %t.rundir
; RUN: %python %t.rundir/interactive_main.py %t.channel-basename \
; RUN: opt -passes=scc-oz-module-inliner -interactive-model-runner-echo-reply \
; RUN: -enable-ml-inliner=release -inliner-interactive-channel-base=%t.channel-basename %s -S -o /dev/null | FileCheck %s

define available_externally void @g() {
ret void
}

define void @f(){
call void @g()
ret void
}

; CHECK: is_callee_avail_external: 1
; CHECK: is_caller_avail_external: 0
Loading