[PATCH] D101379: [NewPM] Properly handle GlobalsAA in the default pipelines

Arthur Eubanks via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Tue Apr 27 09:37:58 PDT 2021


aeubanks created this revision.
aeubanks added reviewers: asbirlea, mtrofin.
Herald added subscribers: hiraditya, eraman.
aeubanks requested review of this revision.
Herald added a project: LLVM.
Herald added a subscriber: llvm-commits.

There are two issues currently with GlobalsAA in the new PM default
pipelines.

1. GlobalsAA is only created at the beginning of the inliner pipeline. If an AAManager is cached from previous passes, it won't get rebuilt to include the newly created GlobalsAA.
2. GlobalsAA is supposed to be recalculated at the beginning of the optimization pipeline to become more precise. GlobalsAA is never invalidated, but it can become too conservative in the face of optimizations. RequireAnalysisPass<> doesn't recalculate the analysis if it's already available. We need to first manually invalidate.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D101379

Files:
  llvm/include/llvm/Transforms/IPO/Inliner.h
  llvm/lib/Passes/PassBuilder.cpp


Index: llvm/lib/Passes/PassBuilder.cpp
===================================================================
--- llvm/lib/Passes/PassBuilder.cpp
+++ llvm/lib/Passes/PassBuilder.cpp
@@ -976,11 +976,15 @@
 
   // Require the GlobalsAA analysis for the module so we can query it within
   // the CGSCC pipeline.
-  MIWP.addRequiredModuleAnalysis<GlobalsAA>();
+  MIWP.addModulePass(RequireAnalysisPass<GlobalsAA, Module>());
+  // Invalidate AAManager so it can be recreated and pick up the newly available
+  // GlobalsAA.
+  MIWP.addModulePass(
+      createModuleToFunctionPassAdaptor(InvalidateAnalysisPass<AAManager>()));
 
   // Require the ProfileSummaryAnalysis for the module so we can query it within
   // the inliner pass.
-  MIWP.addRequiredModuleAnalysis<ProfileSummaryAnalysis>();
+  MIWP.addModulePass(RequireAnalysisPass<ProfileSummaryAnalysis, Module>());
 
   // Now begin the main postorder CGSCC pipeline.
   // FIXME: The current CGSCC pipeline has its origins in the legacy pass
@@ -1242,6 +1246,7 @@
   // information for all local globals here, the late loop passes and notably
   // the vectorizer will be able to use them to help recognize vectorizable
   // memory operations.
+  MPM.addPass(InvalidateAnalysisPass<GlobalsAA>());
   MPM.addPass(RequireAnalysisPass<GlobalsAA, Module>());
 
   FunctionPassManager OptimizePM(DebugLogging);
Index: llvm/include/llvm/Transforms/IPO/Inliner.h
===================================================================
--- llvm/include/llvm/Transforms/IPO/Inliner.h
+++ llvm/include/llvm/Transforms/IPO/Inliner.h
@@ -131,9 +131,9 @@
   /// before run is called, as part of pass pipeline building.
   CGSCCPassManager &getPM() { return PM; }
 
-  /// Allow adding module-level analyses benefiting the contained CGSCC passes.
-  template <class T> void addRequiredModuleAnalysis() {
-    MPM.addPass(RequireAnalysisPass<T, Module>());
+  /// Allow adding module-level passes benefiting the contained CGSCC passes.
+  template <class T> void addModulePass(T Pass) {
+    MPM.addPass(std::move(Pass));
   }
 
 private:


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D101379.340884.patch
Type: text/x-patch
Size: 2076 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20210427/8465c6d4/attachment.bin>


More information about the llvm-commits mailing list