Add an "addUsedAAAnalyses" helper function

Summary:
Passes that call `getAnalysisIfAvailable<T>` also need to call
`addUsedIfAvailable<T>` in `getAnalysisUsage` to indicate to the
legacy pass manager that it uses `T`.  This contract was being
violated by passes that used `createLegacyPMAAResults`.  This change
fixes this by exposing a helper in AliasAnalysis.h,
`addUsedAAAnalyses`, that is complementary to createLegacyPMAAResults
and does the right thing when called from `getAnalysisUsage`.

Reviewers: chandlerc

Subscribers: mcrosier, llvm-commits

Differential Revision: http://reviews.llvm.org/D17010

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@260183 91177308-0d34-0410-b5e6-96231b3b80d8
This commit is contained in:
Sanjoy Das 2016-02-09 01:21:57 +00:00
parent 38e2fe6213
commit 81c2fc4c81
6 changed files with 32 additions and 0 deletions

View File

@ -1057,8 +1057,16 @@ ImmutablePass *createExternalAAWrapperPass(
/// A helper for the legacy pass manager to create a \c AAResults
/// object populated to the best of our ability for a particular function when
/// inside of a \c ModulePass or a \c CallGraphSCCPass.
///
/// If a \c ModulePass or a \c CallGraphSCCPass calls \p
/// createLegacyPMAAResults, it also needs to call \p addUsedAAAnalyses in \p
/// getAnalysisUsage.
AAResults createLegacyPMAAResults(Pass &P, Function &F, BasicAAResult &BAR);
/// A helper for the legacy pass manager to populate \p AU to add uses to make
/// sure the analyses required by \p createLegacyPMAAResults are available.
void addUsedAAAnalyses(AnalysisUsage &AU);
} // End llvm namespace
#endif

View File

@ -563,3 +563,14 @@ bool llvm::isIdentifiedObject(const Value *V) {
bool llvm::isIdentifiedFunctionLocal(const Value *V) {
return isa<AllocaInst>(V) || isNoAliasCall(V) || isNoAliasArgument(V);
}
void llvm::addUsedAAAnalyses(AnalysisUsage &AU) {
// This function needs to be in sync with llvm::createLegacyPMAAResults -- if
// more alias analyses are added to llvm::createLegacyPMAAResults, they need
// to be added here also.
AU.addUsedIfAvailable<ScopedNoAliasAAWrapperPass>();
AU.addUsedIfAvailable<TypeBasedAAWrapperPass>();
AU.addUsedIfAvailable<objcarc::ObjCARCAAWrapperPass>();
AU.addUsedIfAvailable<GlobalsAAWrapperPass>();
AU.addUsedIfAvailable<CFLAAWrapperPass>();
}

View File

@ -68,6 +68,7 @@ namespace {
void getAnalysisUsage(AnalysisUsage &AU) const override {
AU.addRequired<AssumptionCacheTracker>();
AU.addRequired<TargetLibraryInfoWrapperPass>();
addUsedAAAnalyses(AU);
CallGraphSCCPass::getAnalysisUsage(AU);
}

View File

@ -64,6 +64,7 @@ struct PostOrderFunctionAttrs : public CallGraphSCCPass {
AU.setPreservesCFG();
AU.addRequired<AssumptionCacheTracker>();
AU.addRequired<TargetLibraryInfoWrapperPass>();
addUsedAAAnalyses(AU);
CallGraphSCCPass::getAnalysisUsage(AU);
}

View File

@ -58,6 +58,7 @@ Inliner::Inliner(char &ID, bool InsertLifetime)
void Inliner::getAnalysisUsage(AnalysisUsage &AU) const {
AU.addRequired<AssumptionCacheTracker>();
AU.addRequired<TargetLibraryInfoWrapperPass>();
addUsedAAAnalyses(AU);
CallGraphSCCPass::getAnalysisUsage(AU);
}

View File

@ -0,0 +1,10 @@
; RUN: opt -debug-pass=Executions -globals-aa -functionattrs -disable-output < %s 2>&1 | FileCheck %s
; CHECK: Executing Pass 'Globals Alias Analysis'
; CHECK-NOT: Freeing Pass 'Globals Alias Analysis'
; CHECK: Executing Pass 'Deduce function attributes'
; CHECK: Freeing Pass 'Globals Alias Analysis'
define void @test(i8* %p) {
ret void
}