Skip to content

[MLInliner] Handle CGSCC changes from #94815 #96274

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 6 commits into from
Jul 3, 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
20 changes: 10 additions & 10 deletions llvm/lib/Analysis/MLInlineAdvisor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -211,14 +211,12 @@ void MLInlineAdvisor::onPassEntry(LazyCallGraph::SCC *CurSCC) {
// 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).
// - nodes are only deleted at the end of a call graph walk where they are
// batch deleted, so we shouldn't see any dead nodes here.
while (!NodesInLastSCC.empty()) {
const auto *N = *NodesInLastSCC.begin();
assert(!N->isDead());
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

could you add a note in the comment blurb above the while, to the "The cgscc pass manager rules", saying "Nodes are never deleted"? (IIUC that's now the case, right?)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

added comment

NodesInLastSCC.erase(N);
// The Function wrapped by N could have been deleted since we last saw it.
if (N->isDead()) {
assert(!N->getFunction().isDeclaration());
continue;
}
EdgeCount += getLocalCalls(N->getFunction());
const auto NLevel = FunctionLevels.at(N);
for (const auto &E : *(*N)) {
Expand Down Expand Up @@ -256,11 +254,9 @@ void MLInlineAdvisor::onPassExit(LazyCallGraph::SCC *CurSCC) {
EdgesOfLastSeenNodes = 0;

// Check on nodes that were in SCC onPassEntry
for (auto I = NodesInLastSCC.begin(); I != NodesInLastSCC.end();) {
if ((*I)->isDead())
NodesInLastSCC.erase(*I++);
else
EdgesOfLastSeenNodes += getLocalCalls((*I++)->getFunction());
for (const LazyCallGraph::Node *N : NodesInLastSCC) {
assert(!N->isDead());
EdgesOfLastSeenNodes += getLocalCalls(N->getFunction());
}

// Check on nodes that may have got added to SCC
Expand Down Expand Up @@ -311,8 +307,12 @@ void MLInlineAdvisor::onSuccessfulInlining(const MLInlineAdvice &Advice,
int64_t NewCallerAndCalleeEdges =
getCachedFPI(*Caller).DirectCallsToDefinedFunctions;

// A dead function's node is not actually removed from the call graph until
// the end of the call graph walk, but the node no longer belongs to any valid
// SCC.
if (CalleeWasDeleted) {
--NodeCount;
NodesInLastSCC.erase(CG.lookup(*Callee));
DeadFunctions.insert(Callee);
} else {
NewCallerAndCalleeEdges +=
Expand Down
17 changes: 17 additions & 0 deletions llvm/test/Transforms/Inline/ML/dead-callee.ll
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
; REQUIRES: llvm_inliner_model_autogenerated
; RUN: opt -passes=inliner-ml-advisor-release -S < %s | FileCheck %s

; Check that our accounting works when a function in a non-trivial SCC is dead.

; CHECK: define void @f
; CHECK-NOT: @g

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

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