Skip to content

Commit 1b3fc40

Browse files
authored
[mlgo][coro] Assign coro split-ed functions a FunctionLevel (#68263)
1 parent 59c6e2e commit 1b3fc40

File tree

2 files changed

+54
-2
lines changed

2 files changed

+54
-2
lines changed

llvm/lib/Analysis/MLInlineAdvisor.cpp

+13-2
Original file line numberDiff line numberDiff line change
@@ -192,7 +192,9 @@ void MLInlineAdvisor::onPassEntry(LazyCallGraph::SCC *LastSCC) {
192192
// - in addition, if new Nodes were created by a pass (e.g. CoroSplit),
193193
// they'd be adjacent to Nodes in the last SCC. So we just need to check the
194194
// boundary of Nodes in NodesInLastSCC for Nodes we haven't seen. We don't
195-
// care about the nature of the Edge (call or ref).
195+
// care about the nature of the Edge (call or ref). `FunctionLevels`-wise, we
196+
// record them at the same level as the original node (this is a choice, may
197+
// need revisiting).
196198
NodeCount -= static_cast<int64_t>(NodesInLastSCC.size());
197199
while (!NodesInLastSCC.empty()) {
198200
const auto *N = *NodesInLastSCC.begin();
@@ -204,12 +206,15 @@ void MLInlineAdvisor::onPassEntry(LazyCallGraph::SCC *LastSCC) {
204206
}
205207
++NodeCount;
206208
EdgeCount += getLocalCalls(N->getFunction());
209+
const auto NLevel = FunctionLevels.at(N);
207210
for (const auto &E : *(*N)) {
208211
const auto *AdjNode = &E.getNode();
209212
assert(!AdjNode->isDead() && !AdjNode->getFunction().isDeclaration());
210213
auto I = AllNodes.insert(AdjNode);
211-
if (I.second)
214+
if (I.second) {
212215
NodesInLastSCC.insert(AdjNode);
216+
FunctionLevels[AdjNode] = NLevel;
217+
}
213218
}
214219
}
215220

@@ -461,6 +466,12 @@ void MLInlineAdvisor::print(raw_ostream &OS) const {
461466
OS << "\n";
462467
}
463468
OS << "\n";
469+
OS << "[MLInlineAdvisor] FuncLevels:\n";
470+
for (auto I : FunctionLevels)
471+
OS << (I.first->isDead() ? "<deleted>" : I.first->getFunction().getName())
472+
<< " : " << I.second << "\n";
473+
474+
OS << "\n";
464475
}
465476

466477
MLInlineAdvice::MLInlineAdvice(MLInlineAdvisor *Advisor, CallBase &CB,
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
; REQUIRES: llvm_inliner_model_autogenerated
2+
; RUN: opt -S -passes='coro-early,scc-oz-module-inliner,print<inline-advisor>' \
3+
; RUN: -enable-ml-inliner=release -keep-inline-advisor-for-printing < %s
4+
5+
define void @_Z5get_sv() presplitcoroutine {
6+
%1 = call token @llvm.coro.id(i32 0, ptr null, ptr null, ptr null)
7+
%2 = call ptr @llvm.coro.begin(token %1, ptr null)
8+
%3 = call token @llvm.coro.save(ptr null)
9+
%4 = call i8 @llvm.coro.suspend(token none, i1 false)
10+
call void @_ZN1S12promise_typeD2Ev()
11+
ret void
12+
}
13+
14+
declare token @llvm.coro.id(i32, ptr readnone, ptr nocapture readonly, ptr)
15+
declare ptr @llvm.coro.begin(token, ptr writeonly)
16+
declare token @llvm.coro.save(ptr)
17+
declare i8 @llvm.coro.suspend(token, i1)
18+
19+
declare void @__clang_call_terminate()
20+
21+
define void @_ZN1S12promise_typeD2Ev() personality ptr null {
22+
invoke void @_Z4funcv()
23+
to label %1 unwind label %2
24+
25+
1: ; preds = %0
26+
ret void
27+
28+
2: ; preds = %0
29+
%3 = landingpad { ptr, i32 }
30+
catch ptr null
31+
call void @__clang_call_terminate()
32+
unreachable
33+
}
34+
declare void @_Z4funcv()
35+
36+
; CHECK: [MLInlineAdvisor] FuncLevels:
37+
; CHECK-NEXT: _Z5get_sv : 1
38+
; CHECK-NEXT: _ZN1S12promise_typeD2Ev : 0
39+
; CHECK-NEXT: _Z5get_sv.resume : 1
40+
; CHECK-NEXT: _Z5get_sv.destroy : 1
41+
; CHECK-NEXT: _Z5get_sv.cleanup : 1

0 commit comments

Comments
 (0)