[llvm] [Analysis] Avoid running transform passes that have just been run (PR #112092)

Jay Foad via llvm-commits llvm-commits at lists.llvm.org
Tue Oct 15 03:02:00 PDT 2024


================
@@ -5538,8 +5539,15 @@ void InstCombinePass::printPipeline(
   OS << '>';
 }
 
+char InstCombinePass::ID = 0;
+
 PreservedAnalyses InstCombinePass::run(Function &F,
                                        FunctionAnalysisManager &AM) {
+  auto &LRT = AM.getResult<LastRunTrackingAnalysis>(F);
+  // No changes since last InstCombine pass, exit early.
+  if (LRT.shouldSkip(&ID, Options))
+    return PreservedAnalyses::all();
----------------
jayfoad wrote:

I don't know much about the new pass manager, but conceptually there is a lot of overlap between:
- tracking which analyses are valid, and invalidating them when a pass changes something (and doesn't explicitly preserve that analysis)
- tracking which passes have been run, and no pass since then has changed anything.

In the old pass manager you could _almost_ implement this by making a pass P depend on itself:
```
  AU.addUsedIfAvailableID(ID); // depend on myself
```
and then in its `runOn*` method, check whether it is still "available" from a previous run (obviously you would only do this part in an idempotent pass):
```
  if (mustPreserveAnalysisID(ID)) // is my ID still available?
    return false;
```
Is there any way to do something similar in the new pass manager? I.e. have the pass manager be responsible for tracking which passes are still "available", even if it does not know which ones are idempotent?

https://github.com/llvm/llvm-project/pull/112092


More information about the llvm-commits mailing list