aboutsummaryrefslogtreecommitdiff
path: root/llvm/unittests/Analysis/CGSCCPassManagerTest.cpp
diff options
context:
space:
mode:
authorArthur Eubanks <aeubanks@google.com>2024-06-11 10:50:13 -0600
committerGitHub <noreply@github.com>2024-06-11 09:50:13 -0700
commit71497cc7a4695d22fc5dfd64958744816c15a19e (patch)
treed11ee580a32384decfe7fb2845b829128ff06deb /llvm/unittests/Analysis/CGSCCPassManagerTest.cpp
parenta03e93e1b2172791085f3f8c293b8e5d6ed8d841 (diff)
downloadllvm-71497cc7a4695d22fc5dfd64958744816c15a19e.zip
llvm-71497cc7a4695d22fc5dfd64958744816c15a19e.tar.gz
llvm-71497cc7a4695d22fc5dfd64958744816c15a19e.tar.bz2
[CGSCC] Fix compile time blowup with large RefSCCs (#94815)
In some modules, e.g. Kotlin-generated IR, we end up with a huge RefSCC and the call graph updates done as a result of the inliner take a long time. This is due to RefSCC::removeInternalRefEdges() getting called many times, each time removing one function from the RefSCC, but each call to removeInternalRefEdges() is proportional to the size of the RefSCC. There are two places that call removeInternalRefEdges(), in updateCGAndAnalysisManagerForPass() and LazyCallGraph::removeDeadFunction(). 1) Since LazyCallGraph can deal with spurious (edges that exist in the graph but not in the IR) ref edges, we can simply not call removeInternalRefEdges() in updateCGAndAnalysisManagerForPass(). 2) LazyCallGraph::removeDeadFunction() still ends up taking the brunt of compile time with the above change for the original reason. So instead we batch all the dead function removals so we can call removeInternalRefEdges() just once. This requires some changes to callers of removeDeadFunction() to not actually erase the function from the module, but defer it to when we batch delete dead functions at the end of the CGSCC run, leaving the function body as "unreachable" in the meantime. We still need to ensure that call edges are accurate. I had also tried deleting dead functions after visiting a RefSCC, but deleting them all at once at the end was simpler. Many test changes are due to not performing unnecessary revisits of an SCC (the CGSCC infrastructure deems ref edge refinements as unimportant when it comes to revisiting SCCs, although that seems to not be consistently true given these changes) because we don't remove some ref edges. Specifically for devirt-invalidated.ll this seems to expose an inlining order issue with the inliner. Probably unimportant for this type of intentionally weird call graph. Compile time: https://llvm-compile-time-tracker.com/compare.php?from=6f2c61071c274a1b5e212e6ad4114641ec7c7fc3&to=b08c90d05e290dd065755ea776ceaf1420680224&stat=instructions:u
Diffstat (limited to 'llvm/unittests/Analysis/CGSCCPassManagerTest.cpp')
-rw-r--r--llvm/unittests/Analysis/CGSCCPassManagerTest.cpp12
1 files changed, 5 insertions, 7 deletions
diff --git a/llvm/unittests/Analysis/CGSCCPassManagerTest.cpp b/llvm/unittests/Analysis/CGSCCPassManagerTest.cpp
index b33567d..aab148c 100644
--- a/llvm/unittests/Analysis/CGSCCPassManagerTest.cpp
+++ b/llvm/unittests/Analysis/CGSCCPassManagerTest.cpp
@@ -1659,18 +1659,16 @@ TEST_F(CGSCCPassManagerTest, TestUpdateCGAndAnalysisManagerForPasses9) {
Function *FnF = M->getFunction("f");
// Use the CallGraphUpdater to update the call graph.
- {
- CallGraphUpdater CGU;
- CGU.initialize(CG, C, AM, UR);
- ASSERT_NO_FATAL_FAILURE(CGU.removeFunction(*FnF));
- ASSERT_EQ(M->getFunctionList().size(), 6U);
- }
- ASSERT_EQ(M->getFunctionList().size(), 5U);
+ CallGraphUpdater CGU;
+ CGU.initialize(CG, C, AM, UR);
+ ASSERT_NO_FATAL_FAILURE(CGU.removeFunction(*FnF));
+ ASSERT_EQ(M->getFunctionList().size(), 6U);
}));
ModulePassManager MPM;
MPM.addPass(createModuleToPostOrderCGSCCPassAdaptor(std::move(CGPM)));
MPM.run(*M, MAM);
+ ASSERT_EQ(M->getFunctionList().size(), 5U);
}
TEST_F(CGSCCPassManagerTest, TestUpdateCGAndAnalysisManagerForPasses10) {