Skip to content

[mlgo][coro] Assign coro split-ed functions a FunctionLevel #68263

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
Oct 5, 2023
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
15 changes: 13 additions & 2 deletions llvm/lib/Analysis/MLInlineAdvisor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -192,7 +192,9 @@ void MLInlineAdvisor::onPassEntry(LazyCallGraph::SCC *LastSCC) {
// - in addition, if new Nodes were created by a pass (e.g. CoroSplit),
// they'd be adjacent to Nodes in the last SCC. So we just need to check the
// boundary of Nodes in NodesInLastSCC for Nodes we haven't seen. We don't
// care about the nature of the Edge (call or ref).
// care about the nature of the Edge (call or ref). `FunctionLevels`-wise, we
// record them at the same level as the original node (this is a choice, may
// need revisiting).
NodeCount -= static_cast<int64_t>(NodesInLastSCC.size());
while (!NodesInLastSCC.empty()) {
const auto *N = *NodesInLastSCC.begin();
Expand All @@ -204,12 +206,15 @@ void MLInlineAdvisor::onPassEntry(LazyCallGraph::SCC *LastSCC) {
}
++NodeCount;
EdgeCount += getLocalCalls(N->getFunction());
const auto NLevel = FunctionLevels.at(N);
for (const auto &E : *(*N)) {
const auto *AdjNode = &E.getNode();
assert(!AdjNode->isDead() && !AdjNode->getFunction().isDeclaration());
auto I = AllNodes.insert(AdjNode);
if (I.second)
if (I.second) {
NodesInLastSCC.insert(AdjNode);
FunctionLevels[AdjNode] = NLevel;
}
}
}

Expand Down Expand Up @@ -461,6 +466,12 @@ void MLInlineAdvisor::print(raw_ostream &OS) const {
OS << "\n";
}
OS << "\n";
OS << "[MLInlineAdvisor] FuncLevels:\n";
for (auto I : FunctionLevels)
OS << (I.first->isDead() ? "<deleted>" : I.first->getFunction().getName())
<< " : " << I.second << "\n";

OS << "\n";
}

MLInlineAdvice::MLInlineAdvice(MLInlineAdvisor *Advisor, CallBase &CB,
Expand Down
41 changes: 41 additions & 0 deletions llvm/test/Transforms/Inline/ML/coro-split-func-levels.ll
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
; REQUIRES: llvm_inliner_model_autogenerated
; RUN: opt -S -passes='coro-early,scc-oz-module-inliner,print<inline-advisor>' \
; RUN: -enable-ml-inliner=release -keep-inline-advisor-for-printing < %s

define void @_Z5get_sv() presplitcoroutine {
%1 = call token @llvm.coro.id(i32 0, ptr null, ptr null, ptr null)
%2 = call ptr @llvm.coro.begin(token %1, ptr null)
%3 = call token @llvm.coro.save(ptr null)
%4 = call i8 @llvm.coro.suspend(token none, i1 false)
call void @_ZN1S12promise_typeD2Ev()
ret void
}

declare token @llvm.coro.id(i32, ptr readnone, ptr nocapture readonly, ptr)
declare ptr @llvm.coro.begin(token, ptr writeonly)
declare token @llvm.coro.save(ptr)
declare i8 @llvm.coro.suspend(token, i1)

declare void @__clang_call_terminate()

define void @_ZN1S12promise_typeD2Ev() personality ptr null {
invoke void @_Z4funcv()
to label %1 unwind label %2

1: ; preds = %0
ret void

2: ; preds = %0
%3 = landingpad { ptr, i32 }
catch ptr null
call void @__clang_call_terminate()
unreachable
}
declare void @_Z4funcv()

; CHECK: [MLInlineAdvisor] FuncLevels:
; CHECK-NEXT: _Z5get_sv : 1
; CHECK-NEXT: _ZN1S12promise_typeD2Ev : 0
; CHECK-NEXT: _Z5get_sv.resume : 1
; CHECK-NEXT: _Z5get_sv.destroy : 1
; CHECK-NEXT: _Z5get_sv.cleanup : 1