From 45a9c203a01b46afe43885843134926449cc1a5f Mon Sep 17 00:00:00 2001 From: Chandler Carruth Date: Fri, 11 Mar 2016 09:15:11 +0000 Subject: [PATCH] [PM/AA] Teach the AAManager how to handle module analyses in addition to function analyses, and use it to wire up globals-aa to the new pass manager. llvm-svn: 263211 --- llvm/include/llvm/Analysis/AliasAnalysis.h | 30 +++++++++++++++------- llvm/include/llvm/Analysis/GlobalsModRef.h | 1 + llvm/lib/Analysis/GlobalsModRef.cpp | 2 ++ llvm/lib/Passes/PassBuilder.cpp | 7 +++++ llvm/lib/Passes/PassRegistry.def | 7 +++++ llvm/test/Analysis/GlobalsModRef/aliastest.ll | 1 + .../test/Analysis/GlobalsModRef/indirect-global.ll | 1 + 7 files changed, 40 insertions(+), 9 deletions(-) diff --git a/llvm/include/llvm/Analysis/AliasAnalysis.h b/llvm/include/llvm/Analysis/AliasAnalysis.h index 3a0f283..925bcb6 100644 --- a/llvm/include/llvm/Analysis/AliasAnalysis.h +++ b/llvm/include/llvm/Analysis/AliasAnalysis.h @@ -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 void registerFunctionAnalysis() { - FunctionResultGetters.push_back(&getFunctionAAResultImpl); + ResultGetters.push_back(&getFunctionAAResultImpl); + } + + /// Register a specific AA result. + template void registerModuleAnalysis() { + ResultGetters.push_back(&getModuleAAResultImpl); } Result run(Function &F, AnalysisManager *AM) { Result R(AM->getResult(F)); - for (auto &Getter : FunctionResultGetters) + for (auto &Getter : ResultGetters) (*Getter)(F, *AM, R); return R; } @@ -873,7 +876,7 @@ public: private: SmallVector &AM, AAResults &AAResults), - 4> FunctionResultGetters; + 4> ResultGetters; template static void getFunctionAAResultImpl(Function &F, @@ -881,6 +884,15 @@ private: AAResults &AAResults) { AAResults.addAAResult(AM.template getResult(F)); } + + template + static void getModuleAAResultImpl(Function &F, AnalysisManager &AM, + AAResults &AAResults) { + auto &MAM = + AM.getResult(F).getManager(); + if (auto *R = MAM.template getCachedResult(*F.getParent())) + AAResults.addAAResult(*R); + } }; extern template class AnalysisBase; diff --git a/llvm/include/llvm/Analysis/GlobalsModRef.h b/llvm/include/llvm/Analysis/GlobalsModRef.h index 2fa5f6c..45be116 100644 --- a/llvm/include/llvm/Analysis/GlobalsModRef.h +++ b/llvm/include/llvm/Analysis/GlobalsModRef.h @@ -77,6 +77,7 @@ class GlobalsAAResult : public AAResultBase { public: GlobalsAAResult(GlobalsAAResult &&Arg); + ~GlobalsAAResult(); static GlobalsAAResult analyzeModule(Module &M, const TargetLibraryInfo &TLI, CallGraph &CG); diff --git a/llvm/lib/Analysis/GlobalsModRef.cpp b/llvm/lib/Analysis/GlobalsModRef.cpp index 985fd22..8baaa0f 100644 --- a/llvm/lib/Analysis/GlobalsModRef.cpp +++ b/llvm/lib/Analysis/GlobalsModRef.cpp @@ -917,6 +917,8 @@ GlobalsAAResult::GlobalsAAResult(GlobalsAAResult &&Arg) } } +GlobalsAAResult::~GlobalsAAResult() {} + /*static*/ GlobalsAAResult GlobalsAAResult::analyzeModule(Module &M, const TargetLibraryInfo &TLI, CallGraph &CG) { diff --git a/llvm/lib/Passes/PassBuilder.cpp b/llvm/lib/Passes/PassBuilder.cpp index aeb6b64..efe2f04 100644 --- a/llvm/lib/Passes/PassBuilder.cpp +++ b/llvm/lib/Passes/PassBuilder.cpp @@ -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::type>(); \ + return true; \ + } #define FUNCTION_ALIAS_ANALYSIS(NAME, CREATE_PASS) \ if (Name == NAME) { \ AA.registerFunctionAnalysis< \ diff --git a/llvm/lib/Passes/PassRegistry.def b/llvm/lib/Passes/PassRegistry.def index 325d919..3696e19 100644 --- a/llvm/lib/Passes/PassRegistry.def +++ b/llvm/lib/Passes/PassRegistry.def @@ -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 diff --git a/llvm/test/Analysis/GlobalsModRef/aliastest.ll b/llvm/test/Analysis/GlobalsModRef/aliastest.ll index ecc6bcc..3a0eee8 100644 --- a/llvm/test/Analysis/GlobalsModRef/aliastest.ll +++ b/llvm/test/Analysis/GlobalsModRef/aliastest.ll @@ -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,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. diff --git a/llvm/test/Analysis/GlobalsModRef/indirect-global.ll b/llvm/test/Analysis/GlobalsModRef/indirect-global.ll index a51f54b..39d5260 100644 --- a/llvm/test/Analysis/GlobalsModRef/indirect-global.ll +++ b/llvm/test/Analysis/GlobalsModRef/indirect-global.ll @@ -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,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. -- 2.7.4