-
Notifications
You must be signed in to change notification settings - Fork 14.3k
[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
Changes from 1 commit
a866a0a
2d80021
5c5ceaa
29718c6
c395ebb
47a6968
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -187,8 +187,8 @@ unsigned MLInlineAdvisor::getInitialFunctionLevel(const Function &F) const { | |
return CG.lookup(F) ? FunctionLevels.at(CG.lookup(F)) : 0; | ||
} | ||
|
||
void MLInlineAdvisor::onPassEntry(LazyCallGraph::SCC *LastSCC) { | ||
if (!LastSCC || ForceStop) | ||
void MLInlineAdvisor::onPassEntry(LazyCallGraph::SCC *CurSCC) { | ||
if (!CurSCC || ForceStop) | ||
return; | ||
FPICache.clear(); | ||
// Function passes executed between InlinerPass runs may have changed the | ||
|
@@ -206,23 +206,18 @@ void MLInlineAdvisor::onPassEntry(LazyCallGraph::SCC *LastSCC) { | |
// 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(); | ||
assert(!N->isDead()); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. could you add a note in the comment blurb above the There was a problem hiding this comment. Choose a reason for hiding this commentThe 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; | ||
} | ||
++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) { | ||
++NodeCount; | ||
aeubanks marked this conversation as resolved.
Show resolved
Hide resolved
|
||
NodesInLastSCC.insert(AdjNode); | ||
FunctionLevels[AdjNode] = NLevel; | ||
} | ||
|
@@ -235,31 +230,29 @@ void MLInlineAdvisor::onPassEntry(LazyCallGraph::SCC *LastSCC) { | |
// (Re)use NodesInLastSCC to remember the nodes in the SCC right now, | ||
// in case the SCC is split before onPassExit and some nodes are split out | ||
assert(NodesInLastSCC.empty()); | ||
for (const auto &N : *LastSCC) | ||
for (const auto &N : *CurSCC) | ||
NodesInLastSCC.insert(&N); | ||
} | ||
|
||
void MLInlineAdvisor::onPassExit(LazyCallGraph::SCC *LastSCC) { | ||
void MLInlineAdvisor::onPassExit(LazyCallGraph::SCC *CurSCC) { | ||
// No need to keep this around - function passes will invalidate it. | ||
if (!KeepFPICache) | ||
FPICache.clear(); | ||
if (!LastSCC || ForceStop) | ||
if (!CurSCC || ForceStop) | ||
return; | ||
// Keep track of the nodes and edges we last saw. Then, in onPassEntry, | ||
// we update the node count and edge count from the subset of these nodes that | ||
// survived. | ||
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 | ||
for (const auto &N : *LastSCC) { | ||
for (const auto &N : *CurSCC) { | ||
assert(!N.isDead()); | ||
auto I = NodesInLastSCC.insert(&N); | ||
if (I.second) | ||
|
@@ -306,11 +299,18 @@ void MLInlineAdvisor::onSuccessfulInlining(const MLInlineAdvice &Advice, | |
int64_t NewCallerAndCalleeEdges = | ||
getCachedFPI(*Caller).DirectCallsToDefinedFunctions; | ||
|
||
if (CalleeWasDeleted) | ||
// 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; | ||
else | ||
LazyCallGraph::Node *CalleeN = CG.lookup(*Callee); | ||
NodesInLastSCC.erase(CalleeN); | ||
AllNodes.erase(CalleeN); | ||
} else { | ||
NewCallerAndCalleeEdges += | ||
getCachedFPI(*Callee).DirectCallsToDefinedFunctions; | ||
} | ||
EdgeCount += (NewCallerAndCalleeEdges - Advice.CallerAndCalleeEdges); | ||
assert(CurrentIRSize >= 0 && EdgeCount >= 0 && NodeCount >= 0); | ||
} | ||
|
@@ -484,8 +484,7 @@ void MLInlineAdvisor::print(raw_ostream &OS) const { | |
OS << "\n"; | ||
OS << "[MLInlineAdvisor] FuncLevels:\n"; | ||
for (auto I : FunctionLevels) | ||
OS << (I.first->isDead() ? "<deleted>" : I.first->getFunction().getName()) | ||
<< " : " << I.second << "\n"; | ||
OS << I.first->getFunction().getName() << " : " << I.second << "\n"; | ||
aeubanks marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
OS << "\n"; | ||
} | ||
|
Uh oh!
There was an error while loading. Please reload this page.