[PATCH] D17010: Add an "addUsedAAAnalyses" helper function

Sanjoy Das via llvm-commits llvm-commits at lists.llvm.org
Mon Feb 8 16:40:19 PST 2016


sanjoy created this revision.
sanjoy added a reviewer: chandlerc.
sanjoy added a subscriber: llvm-commits.
Herald added a subscriber: mcrosier.

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

http://reviews.llvm.org/D17010

Files:
  include/llvm/Analysis/AliasAnalysis.h
  lib/Analysis/AliasAnalysis.cpp
  lib/Transforms/IPO/ArgumentPromotion.cpp
  lib/Transforms/IPO/FunctionAttrs.cpp
  lib/Transforms/IPO/Inliner.cpp
  test/Analysis/alias-analysis-uses.ll

Index: test/Analysis/alias-analysis-uses.ll
===================================================================
--- /dev/null
+++ test/Analysis/alias-analysis-uses.ll
@@ -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
+}
Index: lib/Transforms/IPO/Inliner.cpp
===================================================================
--- lib/Transforms/IPO/Inliner.cpp
+++ lib/Transforms/IPO/Inliner.cpp
@@ -58,6 +58,7 @@
 void Inliner::getAnalysisUsage(AnalysisUsage &AU) const {
   AU.addRequired<AssumptionCacheTracker>();
   AU.addRequired<TargetLibraryInfoWrapperPass>();
+  addUsedAAAnalyses(AU);
   CallGraphSCCPass::getAnalysisUsage(AU);
 }
 
Index: lib/Transforms/IPO/FunctionAttrs.cpp
===================================================================
--- lib/Transforms/IPO/FunctionAttrs.cpp
+++ lib/Transforms/IPO/FunctionAttrs.cpp
@@ -64,6 +64,7 @@
     AU.setPreservesCFG();
     AU.addRequired<AssumptionCacheTracker>();
     AU.addRequired<TargetLibraryInfoWrapperPass>();
+    addUsedAAAnalyses(AU);
     CallGraphSCCPass::getAnalysisUsage(AU);
   }
 
Index: lib/Transforms/IPO/ArgumentPromotion.cpp
===================================================================
--- lib/Transforms/IPO/ArgumentPromotion.cpp
+++ lib/Transforms/IPO/ArgumentPromotion.cpp
@@ -68,6 +68,7 @@
     void getAnalysisUsage(AnalysisUsage &AU) const override {
       AU.addRequired<AssumptionCacheTracker>();
       AU.addRequired<TargetLibraryInfoWrapperPass>();
+      addUsedAAAnalyses(AU);
       CallGraphSCCPass::getAnalysisUsage(AU);
     }
 
Index: lib/Analysis/AliasAnalysis.cpp
===================================================================
--- lib/Analysis/AliasAnalysis.cpp
+++ lib/Analysis/AliasAnalysis.cpp
@@ -563,3 +563,11 @@
 bool llvm::isIdentifiedFunctionLocal(const Value *V) {
   return isa<AllocaInst>(V) || isNoAliasCall(V) || isNoAliasArgument(V);
 }
+
+void llvm::addUsedAAAnalyses(AnalysisUsage &AU) {
+  AU.addUsedIfAvailable<ScopedNoAliasAAWrapperPass>();
+  AU.addUsedIfAvailable<TypeBasedAAWrapperPass>();
+  AU.addUsedIfAvailable<objcarc::ObjCARCAAWrapperPass>();
+  AU.addUsedIfAvailable<GlobalsAAWrapperPass>();
+  AU.addUsedIfAvailable<CFLAAWrapperPass>();
+}
Index: include/llvm/Analysis/AliasAnalysis.h
===================================================================
--- include/llvm/Analysis/AliasAnalysis.h
+++ include/llvm/Analysis/AliasAnalysis.h
@@ -1057,8 +1057,16 @@
 /// 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


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D17010.47273.patch
Type: text/x-patch
Size: 3414 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20160209/224a84f0/attachment-0001.bin>


More information about the llvm-commits mailing list