[all-commits] [llvm/llvm-project] 71497c: [CGSCC] Fix compile time blowup with large RefSCCs...

Arthur Eubanks via All-commits all-commits at lists.llvm.org
Tue Jun 11 09:50:35 PDT 2024


  Branch: refs/heads/main
  Home:   https://github.com/llvm/llvm-project
  Commit: 71497cc7a4695d22fc5dfd64958744816c15a19e
      https://github.com/llvm/llvm-project/commit/71497cc7a4695d22fc5dfd64958744816c15a19e
  Author: Arthur Eubanks <aeubanks at google.com>
  Date:   2024-06-11 (Tue, 11 Jun 2024)

  Changed paths:
    M llvm/include/llvm/Analysis/CGSCCPassManager.h
    M llvm/include/llvm/Analysis/LazyCallGraph.h
    M llvm/lib/Analysis/CGSCCPassManager.cpp
    M llvm/lib/Analysis/LazyCallGraph.cpp
    M llvm/lib/Transforms/IPO/Inliner.cpp
    M llvm/lib/Transforms/Utils/CallGraphUpdater.cpp
    M llvm/test/Other/cgscc-refscc-mutation-order.ll
    M llvm/test/Other/devirt-invalidated.ll
    M llvm/test/Transforms/Attributor/ArgumentPromotion/live_called_from_dead.ll
    M llvm/test/Transforms/Attributor/ArgumentPromotion/live_called_from_dead_2.ll
    M llvm/test/Transforms/Inline/cgscc-cycle-debug.ll
    M llvm/unittests/Analysis/CGSCCPassManagerTest.cpp
    M llvm/unittests/Analysis/LazyCallGraphTest.cpp

  Log Message:
  -----------
  [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



To unsubscribe from these emails, change your notification settings at https://github.com/llvm/llvm-project/settings/notifications


More information about the All-commits mailing list