Skip to content
This repository was archived by the owner on Feb 5, 2019. It is now read-only.

Commit 4f2b179

Browse files
sanjoyBjörn Steinbrink
authored andcommitted
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
1 parent 63f3a1b commit 4f2b179

File tree

6 files changed

+32
-0
lines changed

6 files changed

+32
-0
lines changed

include/llvm/Analysis/AliasAnalysis.h

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1065,8 +1065,16 @@ ImmutablePass *createExternalAAWrapperPass(
10651065
/// A helper for the legacy pass manager to create a \c AAResults
10661066
/// object populated to the best of our ability for a particular function when
10671067
/// inside of a \c ModulePass or a \c CallGraphSCCPass.
1068+
///
1069+
/// If a \c ModulePass or a \c CallGraphSCCPass calls \p
1070+
/// createLegacyPMAAResults, it also needs to call \p addUsedAAAnalyses in \p
1071+
/// getAnalysisUsage.
10681072
AAResults createLegacyPMAAResults(Pass &P, Function &F, BasicAAResult &BAR);
10691073

1074+
/// A helper for the legacy pass manager to populate \p AU to add uses to make
1075+
/// sure the analyses required by \p createLegacyPMAAResults are available.
1076+
void addUsedAAAnalyses(AnalysisUsage &AU);
1077+
10701078
} // End llvm namespace
10711079

10721080
#endif

lib/Analysis/AliasAnalysis.cpp

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -583,3 +583,14 @@ bool llvm::isIdentifiedFunctionLocal(const Value *V)
583583
{
584584
return isa<AllocaInst>(V) || isNoAliasCall(V) || isNoAliasArgument(V);
585585
}
586+
587+
void llvm::addUsedAAAnalyses(AnalysisUsage &AU) {
588+
// This function needs to be in sync with llvm::createLegacyPMAAResults -- if
589+
// more alias analyses are added to llvm::createLegacyPMAAResults, they need
590+
// to be added here also.
591+
AU.addUsedIfAvailable<ScopedNoAliasAAWrapperPass>();
592+
AU.addUsedIfAvailable<TypeBasedAAWrapperPass>();
593+
AU.addUsedIfAvailable<objcarc::ObjCARCAAWrapperPass>();
594+
AU.addUsedIfAvailable<GlobalsAAWrapperPass>();
595+
AU.addUsedIfAvailable<CFLAAWrapperPass>();
596+
}

lib/Transforms/IPO/ArgumentPromotion.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,7 @@ namespace {
6868
void getAnalysisUsage(AnalysisUsage &AU) const override {
6969
AU.addRequired<AssumptionCacheTracker>();
7070
AU.addRequired<TargetLibraryInfoWrapperPass>();
71+
addUsedAAAnalyses(AU);
7172
CallGraphSCCPass::getAnalysisUsage(AU);
7273
}
7374

lib/Transforms/IPO/FunctionAttrs.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,7 @@ struct PostOrderFunctionAttrs : public CallGraphSCCPass {
6464
AU.setPreservesCFG();
6565
AU.addRequired<AssumptionCacheTracker>();
6666
AU.addRequired<TargetLibraryInfoWrapperPass>();
67+
addUsedAAAnalyses(AU);
6768
CallGraphSCCPass::getAnalysisUsage(AU);
6869
}
6970

lib/Transforms/IPO/Inliner.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -81,6 +81,7 @@ Inliner::Inliner(char &ID, int Threshold, bool InsertLifetime)
8181
void Inliner::getAnalysisUsage(AnalysisUsage &AU) const {
8282
AU.addRequired<AssumptionCacheTracker>();
8383
AU.addRequired<TargetLibraryInfoWrapperPass>();
84+
addUsedAAAnalyses(AU);
8485
CallGraphSCCPass::getAnalysisUsage(AU);
8586
}
8687

test/Analysis/alias-analysis-uses.ll

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
; RUN: opt -debug-pass=Executions -globals-aa -functionattrs -disable-output < %s 2>&1 | FileCheck %s
2+
3+
; CHECK: Executing Pass 'Globals Alias Analysis'
4+
; CHECK-NOT: Freeing Pass 'Globals Alias Analysis'
5+
; CHECK: Executing Pass 'Deduce function attributes'
6+
; CHECK: Freeing Pass 'Globals Alias Analysis'
7+
8+
define void @test(i8* %p) {
9+
ret void
10+
}

0 commit comments

Comments
 (0)