diff options
author | Arthur Eubanks <aeubanks@google.com> | 2024-06-11 10:50:13 -0600 |
---|---|---|
committer | GitHub <noreply@github.com> | 2024-06-11 09:50:13 -0700 |
commit | 71497cc7a4695d22fc5dfd64958744816c15a19e (patch) | |
tree | d11ee580a32384decfe7fb2845b829128ff06deb /llvm/unittests/Analysis/LazyCallGraphTest.cpp | |
parent | a03e93e1b2172791085f3f8c293b8e5d6ed8d841 (diff) | |
download | llvm-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/LazyCallGraphTest.cpp')
-rw-r--r-- | llvm/unittests/Analysis/LazyCallGraphTest.cpp | 29 |
1 files changed, 17 insertions, 12 deletions
diff --git a/llvm/unittests/Analysis/LazyCallGraphTest.cpp b/llvm/unittests/Analysis/LazyCallGraphTest.cpp index 69af7d9..64b6ccd 100644 --- a/llvm/unittests/Analysis/LazyCallGraphTest.cpp +++ b/llvm/unittests/Analysis/LazyCallGraphTest.cpp @@ -1169,7 +1169,7 @@ TEST(LazyCallGraphTest, InlineAndDeleteFunction) { LazyCallGraph::SCC &NewDC = *NewCs.begin(); EXPECT_EQ(&NewDC, CG.lookupSCC(D1)); EXPECT_EQ(&NewDC, CG.lookupSCC(D3)); - auto NewRCs = DRC.removeInternalRefEdge(D1, {&D2}); + auto NewRCs = DRC.removeInternalRefEdges({{&D1, &D2}}); ASSERT_EQ(2u, NewRCs.size()); LazyCallGraph::RefSCC &NewDRC = *NewRCs[0]; EXPECT_EQ(&NewDRC, CG.lookupRefSCC(D1)); @@ -1186,7 +1186,8 @@ TEST(LazyCallGraphTest, InlineAndDeleteFunction) { EXPECT_TRUE(D2RC.isParentOf(NewDRC)); // Now that we've updated the call graph, D2 is dead, so remove it. - CG.removeDeadFunction(D2F); + CG.markDeadFunction(D2F); + CG.removeDeadFunctions({&D2F}); // Check that the graph still looks the same. EXPECT_EQ(&ARC, CG.lookupRefSCC(A1)); @@ -1344,7 +1345,7 @@ TEST(LazyCallGraphTest, InternalEdgeRemoval) { // Remove the edge from b -> a, which should leave the 3 functions still in // a single connected component because of a -> b -> c -> a. SmallVector<LazyCallGraph::RefSCC *, 1> NewRCs = - RC.removeInternalRefEdge(B, {&A}); + RC.removeInternalRefEdges({{&B, &A}}); EXPECT_EQ(0u, NewRCs.size()); EXPECT_EQ(&RC, CG.lookupRefSCC(A)); EXPECT_EQ(&RC, CG.lookupRefSCC(B)); @@ -1360,7 +1361,7 @@ TEST(LazyCallGraphTest, InternalEdgeRemoval) { // Remove the edge from c -> a, which should leave 'a' in the original RefSCC // and form a new RefSCC for 'b' and 'c'. - NewRCs = RC.removeInternalRefEdge(C, {&A}); + NewRCs = RC.removeInternalRefEdges({{&C, &A}}); ASSERT_EQ(2u, NewRCs.size()); LazyCallGraph::RefSCC &BCRC = *NewRCs[0]; LazyCallGraph::RefSCC &ARC = *NewRCs[1]; @@ -1425,7 +1426,7 @@ TEST(LazyCallGraphTest, InternalMultiEdgeRemoval) { // Remove the edges from b -> a and b -> c, leaving b in its own RefSCC. SmallVector<LazyCallGraph::RefSCC *, 1> NewRCs = - RC.removeInternalRefEdge(B, {&A, &C}); + RC.removeInternalRefEdges({{&B, &A}, {&B, &C}}); ASSERT_EQ(2u, NewRCs.size()); LazyCallGraph::RefSCC &BRC = *NewRCs[0]; @@ -1494,7 +1495,7 @@ TEST(LazyCallGraphTest, InternalNoOpEdgeRemoval) { // Remove the edge from a -> c which doesn't change anything. SmallVector<LazyCallGraph::RefSCC *, 1> NewRCs = - RC.removeInternalRefEdge(AN, {&CN}); + RC.removeInternalRefEdges({{&AN, &CN}}); EXPECT_EQ(0u, NewRCs.size()); EXPECT_EQ(&RC, CG.lookupRefSCC(AN)); EXPECT_EQ(&RC, CG.lookupRefSCC(BN)); @@ -1509,8 +1510,8 @@ TEST(LazyCallGraphTest, InternalNoOpEdgeRemoval) { // Remove the edge from b -> a and c -> b; again this doesn't change // anything. - NewRCs = RC.removeInternalRefEdge(BN, {&AN}); - NewRCs = RC.removeInternalRefEdge(CN, {&BN}); + NewRCs = RC.removeInternalRefEdges({{&BN, &AN}}); + NewRCs = RC.removeInternalRefEdges({{&CN, &BN}}); EXPECT_EQ(0u, NewRCs.size()); EXPECT_EQ(&RC, CG.lookupRefSCC(AN)); EXPECT_EQ(&RC, CG.lookupRefSCC(BN)); @@ -2163,7 +2164,8 @@ TEST(LazyCallGraphTest, RemoveFunctionWithSpuriousRef) { // Now delete 'dead'. There are no uses of this function but there are // spurious references. - CG.removeDeadFunction(DeadN.getFunction()); + CG.markDeadFunction(DeadN.getFunction()); + CG.removeDeadFunctions({&DeadN.getFunction()}); // The only observable change should be that the RefSCC is gone from the // postorder sequence. @@ -2212,7 +2214,8 @@ TEST(LazyCallGraphTest, RemoveFunctionWithSpuriousRefRecursive) { // Now delete 'a'. There are no uses of this function but there are // spurious references. - CG.removeDeadFunction(AN.getFunction()); + CG.markDeadFunction(AN.getFunction()); + CG.removeDeadFunctions({&AN.getFunction()}); // The only observable change should be that the RefSCC is gone from the // postorder sequence. @@ -2269,7 +2272,8 @@ TEST(LazyCallGraphTest, RemoveFunctionWithSpuriousRefRecursive2) { // Now delete 'a'. There are no uses of this function but there are // spurious references. - CG.removeDeadFunction(AN.getFunction()); + CG.markDeadFunction(AN.getFunction()); + CG.removeDeadFunctions({&AN.getFunction()}); // The only observable change should be that the RefSCC is gone from the // postorder sequence. @@ -2320,7 +2324,8 @@ TEST(LazyCallGraphTest, RemoveFunctionWithSpuriousRefRecursive3) { // Now delete 'a'. There are no uses of this function but there are // spurious references. - CG.removeDeadFunction(AN.getFunction()); + CG.markDeadFunction(AN.getFunction()); + CG.removeDeadFunctions({&AN.getFunction()}); // The only observable change should be that the RefSCC is gone from the // postorder sequence. |