[PM/AA] Teach the AAManager how to handle module analyses in addition to
authorChandler Carruth <chandlerc@gmail.com>
Fri, 11 Mar 2016 09:15:11 +0000 (09:15 +0000)
committerChandler Carruth <chandlerc@gmail.com>
Fri, 11 Mar 2016 09:15:11 +0000 (09:15 +0000)
function analyses, and use it to wire up globals-aa to the new pass
manager.

llvm-svn: 263211

llvm/include/llvm/Analysis/AliasAnalysis.h
llvm/include/llvm/Analysis/GlobalsModRef.h
llvm/lib/Analysis/GlobalsModRef.cpp
llvm/lib/Passes/PassBuilder.cpp
llvm/lib/Passes/PassRegistry.def
llvm/test/Analysis/GlobalsModRef/aliastest.ll
llvm/test/Analysis/GlobalsModRef/indirect-global.ll

index 3a0f283..925bcb6 100644 (file)
@@ -845,27 +845,30 @@ public:
   // This type hase value semantics. We have to spell these out because MSVC
   // won't synthesize them.
   AAManager() {}
-  AAManager(AAManager &&Arg)
-      : FunctionResultGetters(std::move(Arg.FunctionResultGetters)) {}
-  AAManager(const AAManager &Arg)
-      : FunctionResultGetters(Arg.FunctionResultGetters) {}
+  AAManager(AAManager &&Arg) : ResultGetters(std::move(Arg.ResultGetters)) {}
+  AAManager(const AAManager &Arg) : ResultGetters(Arg.ResultGetters) {}
   AAManager &operator=(AAManager &&RHS) {
-    FunctionResultGetters = std::move(RHS.FunctionResultGetters);
+    ResultGetters = std::move(RHS.ResultGetters);
     return *this;
   }
   AAManager &operator=(const AAManager &RHS) {
-    FunctionResultGetters = RHS.FunctionResultGetters;
+    ResultGetters = RHS.ResultGetters;
     return *this;
   }
 
   /// Register a specific AA result.
   template <typename AnalysisT> void registerFunctionAnalysis() {
-    FunctionResultGetters.push_back(&getFunctionAAResultImpl<AnalysisT>);
+    ResultGetters.push_back(&getFunctionAAResultImpl<AnalysisT>);
+  }
+
+  /// Register a specific AA result.
+  template <typename AnalysisT> void registerModuleAnalysis() {
+    ResultGetters.push_back(&getModuleAAResultImpl<AnalysisT>);
   }
 
   Result run(Function &F, AnalysisManager<Function> *AM) {
     Result R(AM->getResult<TargetLibraryAnalysis>(F));
-    for (auto &Getter : FunctionResultGetters)
+    for (auto &Getter : ResultGetters)
       (*Getter)(F, *AM, R);
     return R;
   }
@@ -873,7 +876,7 @@ public:
 private:
   SmallVector<void (*)(Function &F, AnalysisManager<Function> &AM,
                        AAResults &AAResults),
-              4> FunctionResultGetters;
+              4> ResultGetters;
 
   template <typename AnalysisT>
   static void getFunctionAAResultImpl(Function &F,
@@ -881,6 +884,15 @@ private:
                                       AAResults &AAResults) {
     AAResults.addAAResult(AM.template getResult<AnalysisT>(F));
   }
+
+  template <typename AnalysisT>
+  static void getModuleAAResultImpl(Function &F, AnalysisManager<Function> &AM,
+                                    AAResults &AAResults) {
+    auto &MAM =
+        AM.getResult<ModuleAnalysisManagerFunctionProxy>(F).getManager();
+    if (auto *R = MAM.template getCachedResult<AnalysisT>(*F.getParent()))
+      AAResults.addAAResult(*R);
+  }
 };
 
 extern template class AnalysisBase<AAManager>;
index 2fa5f6c..45be116 100644 (file)
@@ -77,6 +77,7 @@ class GlobalsAAResult : public AAResultBase<GlobalsAAResult> {
 
 public:
   GlobalsAAResult(GlobalsAAResult &&Arg);
+  ~GlobalsAAResult();
 
   static GlobalsAAResult analyzeModule(Module &M, const TargetLibraryInfo &TLI,
                                        CallGraph &CG);
index 985fd22..8baaa0f 100644 (file)
@@ -917,6 +917,8 @@ GlobalsAAResult::GlobalsAAResult(GlobalsAAResult &&Arg)
   }
 }
 
+GlobalsAAResult::~GlobalsAAResult() {}
+
 /*static*/ GlobalsAAResult
 GlobalsAAResult::analyzeModule(Module &M, const TargetLibraryInfo &TLI,
                                CallGraph &CG) {
index aeb6b64..efe2f04 100644 (file)
@@ -25,6 +25,7 @@
 #include "llvm/Analysis/CGSCCPassManager.h"
 #include "llvm/Analysis/CallGraph.h"
 #include "llvm/Analysis/DominanceFrontier.h"
+#include "llvm/Analysis/GlobalsModRef.h"
 #include "llvm/Analysis/LazyCallGraph.h"
 #include "llvm/Analysis/LoopInfo.h"
 #include "llvm/Analysis/MemoryDependenceAnalysis.h"
@@ -337,6 +338,12 @@ bool PassBuilder::parseLoopPassName(LoopPassManager &FPM,
 }
 
 bool PassBuilder::parseAAPassName(AAManager &AA, StringRef Name) {
+#define MODULE_ALIAS_ANALYSIS(NAME, CREATE_PASS)                               \
+  if (Name == NAME) {                                                          \
+    AA.registerModuleAnalysis<                                                 \
+        std::remove_reference<decltype(CREATE_PASS)>::type>();                 \
+    return true;                                                               \
+  }
 #define FUNCTION_ALIAS_ANALYSIS(NAME, CREATE_PASS)                             \
   if (Name == NAME) {                                                          \
     AA.registerFunctionAnalysis<                                               \
index 325d919..3696e19 100644 (file)
@@ -23,6 +23,13 @@ MODULE_ANALYSIS("callgraph", CallGraphAnalysis())
 MODULE_ANALYSIS("lcg", LazyCallGraphAnalysis())
 MODULE_ANALYSIS("no-op-module", NoOpModuleAnalysis())
 MODULE_ANALYSIS("targetlibinfo", TargetLibraryAnalysis())
+
+#ifndef MODULE_ALIAS_ANALYSIS
+#define MODULE_ALIAS_ANALYSIS(NAME, CREATE_PASS)                             \
+  MODULE_ANALYSIS(NAME, CREATE_PASS)
+#endif
+MODULE_ALIAS_ANALYSIS("globals-aa", GlobalsAA())
+#undef MODULE_ALIAS_ANALYSIS
 #undef MODULE_ANALYSIS
 
 #ifndef MODULE_PASS
index ecc6bcc..3a0eee8 100644 (file)
@@ -1,4 +1,5 @@
 ; RUN: opt < %s -basicaa -globals-aa -gvn -S -enable-unsafe-globalsmodref-alias-results | FileCheck %s
+; RUN: opt < %s -aa-pipeline=basic-aa,globals-aa -passes="require<globals-aa>,function(gvn)" -S -enable-unsafe-globalsmodref-alias-results | FileCheck %s
 ;
 ; Note that this test relies on an unsafe feature of GlobalsModRef. While this
 ; test is correct and safe, GMR's technique for handling this isn't generally.
index a51f54b..39d5260 100644 (file)
@@ -1,4 +1,5 @@
 ; RUN: opt < %s -basicaa -globals-aa -gvn -instcombine -S -enable-unsafe-globalsmodref-alias-results | FileCheck %s
+; RUN: opt < %s -aa-pipeline=basic-aa,globals-aa -passes="require<globals-aa>,function(gvn,instcombine)" -S -enable-unsafe-globalsmodref-alias-results | FileCheck %s
 ;
 ; Note that this test relies on an unsafe feature of GlobalsModRef. While this
 ; test is correct and safe, GMR's technique for handling this isn't generally.