llvm.org GIT mirror llvm / 0cb12ca
Allow subclassing ExternalAA This allows testing AMDGPU alias analysis like any other alias analysis pass. This fixes the existing test pointlessly running opt -O3 when it really just wants to run the one analysis. Before there was no way to test this using -aa-eval with opt, since the default constructed pass is run. The wrapper subclass allows the default constructor to pass the necessary callback. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@346353 91177308-0d34-0410-b5e6-96231b3b80d8 Matt Arsenault 10 months ago
7 changed file(s) with 49 addition(s) and 31 deletion(s). Raw diff Collapse all Expand all
10731073 void getAnalysisUsage(AnalysisUsage &AU) const override;
10741074 };
10751075
1076 /// A wrapper pass for external alias analyses. This just squirrels away the
1077 /// callback used to run any analyses and register their results.
1078 struct ExternalAAWrapperPass : ImmutablePass {
1079 using CallbackT = std::function;
1080
1081 CallbackT CB;
1082
1083 static char ID;
1084
1085 ExternalAAWrapperPass() : ImmutablePass(ID) {
1086 initializeExternalAAWrapperPassPass(*PassRegistry::getPassRegistry());
1087 }
1088
1089 explicit ExternalAAWrapperPass(CallbackT CB)
1090 : ImmutablePass(ID), CB(std::move(CB)) {
1091 initializeExternalAAWrapperPassPass(*PassRegistry::getPassRegistry());
1092 }
1093
1094 void getAnalysisUsage(AnalysisUsage &AU) const override {
1095 AU.setPreservesAll();
1096 }
1097 };
1098
10761099 FunctionPass *createAAResultsWrapperPass();
10771100
10781101 /// A wrapper pass around a callback which can be used to populate the
639639
640640 namespace {
641641
642 /// A wrapper pass for external alias analyses. This just squirrels away the
643 /// callback used to run any analyses and register their results.
644 struct ExternalAAWrapperPass : ImmutablePass {
645 using CallbackT = std::function;
646
647 CallbackT CB;
648
649 static char ID;
650
651 ExternalAAWrapperPass() : ImmutablePass(ID) {
652 initializeExternalAAWrapperPassPass(*PassRegistry::getPassRegistry());
653 }
654
655 explicit ExternalAAWrapperPass(CallbackT CB)
656 : ImmutablePass(ID), CB(std::move(CB)) {
657 initializeExternalAAWrapperPassPass(*PassRegistry::getPassRegistry());
658 }
659
660 void getAnalysisUsage(AnalysisUsage &AU) const override {
661 AU.setPreservesAll();
662 }
663 };
664642
665643 } // end anonymous namespace
666644
197197
198198 ImmutablePass *createAMDGPUAAWrapperPass();
199199 void initializeAMDGPUAAWrapperPassPass(PassRegistry&);
200 ImmutablePass *createAMDGPUExternalAAWrapperPass();
201 void initializeAMDGPUExternalAAWrapperPass(PassRegistry&);
200202
201203 void initializeAMDGPUArgumentUsageInfoPass(PassRegistry &);
202204
3333
3434 // Register this pass...
3535 char AMDGPUAAWrapperPass::ID = 0;
36 char AMDGPUExternalAAWrapper::ID = 0;
3637
3738 INITIALIZE_PASS(AMDGPUAAWrapperPass, "amdgpu-aa",
3839 "AMDGPU Address space based Alias Analysis", false, true)
3940
41 INITIALIZE_PASS(AMDGPUExternalAAWrapper, "amdgpu-aa-wrapper",
42 "AMDGPU Address space based Alias Analysis Wrapper", false, true)
43
4044 ImmutablePass *llvm::createAMDGPUAAWrapperPass() {
4145 return new AMDGPUAAWrapperPass();
46 }
47
48 ImmutablePass *llvm::createAMDGPUExternalAAWrapperPass() {
49 return new AMDGPUExternalAAWrapper();
4250 }
4351
4452 void AMDGPUAAWrapperPass::getAnalysisUsage(AnalysisUsage &AU) const {
9595 void getAnalysisUsage(AnalysisUsage &AU) const override;
9696 };
9797
98 // Wrapper around ExternalAAWrapperPass so that the default constructor gets the
99 // callback.
100 class AMDGPUExternalAAWrapper : public ExternalAAWrapperPass {
101 public:
102 static char ID;
103
104 AMDGPUExternalAAWrapper() : ExternalAAWrapperPass(
105 [](Pass &P, Function &, AAResults &AAR) {
106 if (auto *WrapperPass = P.getAnalysisIfAvailable())
107 AAR.addAAResult(WrapperPass->getResult());
108 }) {}
109 };
110
98111 } // end namespace llvm
99112
100113 #endif // LLVM_LIB_TARGET_AMDGPU_AMDGPUALIASANALYSIS_H
191191 initializeSIFormMemoryClausesPass(*PR);
192192 initializeAMDGPUUnifyDivergentExitNodesPass(*PR);
193193 initializeAMDGPUAAWrapperPassPass(*PR);
194 initializeAMDGPUExternalAAWrapperPass(*PR);
194195 initializeAMDGPUUseNativeCallsPass(*PR);
195196 initializeAMDGPUSimplifyLibCallsPass(*PR);
196197 initializeAMDGPUInlinerPass(*PR);
337338 return FSAttr.hasAttribute(Attribute::None) ?
338339 getTargetFeatureString() :
339340 FSAttr.getValueAsString();
340 }
341
342 static ImmutablePass *createAMDGPUExternalAAWrapperPass() {
343 return createExternalAAWrapperPass([](Pass &P, Function &, AAResults &AAR) {
344 if (auto *WrapperPass = P.getAnalysisIfAvailable())
345 AAR.addAAResult(WrapperPass->getResult());
346 });
347341 }
348342
349343 /// Predicate for Internalize pass.
None ; RUN: opt -mtriple=amdgcn-- -O3 -aa-eval -print-all-alias-modref-info -disable-output < %s 2>&1 | FileCheck %s
1 ; RUN: opt -mtriple=r600-- -O3 -aa-eval -print-all-alias-modref-info -disable-output < %s 2>&1 | FileCheck %s
0 ; RUN: opt -mtriple=amdgcn-- -aa-eval -amdgpu-aa -amdgpu-aa-wrapper -disable-basicaa -print-all-alias-modref-info -disable-output < %s 2>&1 | FileCheck %s
1 ; RUN: opt -mtriple=r600-- -aa-eval -amdgpu-aa -amdgpu-aa-wrapper -disable-basicaa -print-all-alias-modref-info -disable-output < %s 2>&1 | FileCheck %s
22
33 ; CHECK: NoAlias: i8 addrspace(1)* %p1, i8 addrspace(5)* %p
44