[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
This commit is contained in:
Chandler Carruth 2016-03-11 09:15:11 +00:00
parent 4ddaadca76
commit 45a9c203a0
7 changed files with 40 additions and 9 deletions

View 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>;

View 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);

View File

@ -917,6 +917,8 @@ GlobalsAAResult::GlobalsAAResult(GlobalsAAResult &&Arg)
}
}
GlobalsAAResult::~GlobalsAAResult() {}
/*static*/ GlobalsAAResult
GlobalsAAResult::analyzeModule(Module &M, const TargetLibraryInfo &TLI,
CallGraph &CG) {

View 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< \

View 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

View 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.

View 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.