Index: include/llvm/Analysis/AliasAnalysis.h =================================================================== --- include/llvm/Analysis/AliasAnalysis.h +++ include/llvm/Analysis/AliasAnalysis.h @@ -1075,6 +1075,29 @@ void getAnalysisUsage(AnalysisUsage &AU) const override; }; +/// A wrapper pass for external alias analyses. This just squirrels away the +/// callback used to run any analyses and register their results. +struct ExternalAAWrapperPass : ImmutablePass { + using CallbackT = std::function; + + CallbackT CB; + + static char ID; + + ExternalAAWrapperPass() : ImmutablePass(ID) { + initializeExternalAAWrapperPassPass(*PassRegistry::getPassRegistry()); + } + + explicit ExternalAAWrapperPass(CallbackT CB) + : ImmutablePass(ID), CB(std::move(CB)) { + initializeExternalAAWrapperPassPass(*PassRegistry::getPassRegistry()); + } + + void getAnalysisUsage(AnalysisUsage &AU) const override { + AU.setPreservesAll(); + } +}; + FunctionPass *createAAResultsWrapperPass(); /// A wrapper pass around a callback which can be used to populate the Index: lib/Analysis/AliasAnalysis.cpp =================================================================== --- lib/Analysis/AliasAnalysis.cpp +++ lib/Analysis/AliasAnalysis.cpp @@ -640,28 +640,6 @@ namespace { -/// A wrapper pass for external alias analyses. This just squirrels away the -/// callback used to run any analyses and register their results. -struct ExternalAAWrapperPass : ImmutablePass { - using CallbackT = std::function; - - CallbackT CB; - - static char ID; - - ExternalAAWrapperPass() : ImmutablePass(ID) { - initializeExternalAAWrapperPassPass(*PassRegistry::getPassRegistry()); - } - - explicit ExternalAAWrapperPass(CallbackT CB) - : ImmutablePass(ID), CB(std::move(CB)) { - initializeExternalAAWrapperPassPass(*PassRegistry::getPassRegistry()); - } - - void getAnalysisUsage(AnalysisUsage &AU) const override { - AU.setPreservesAll(); - } -}; } // end anonymous namespace Index: lib/Target/AMDGPU/AMDGPU.h =================================================================== --- lib/Target/AMDGPU/AMDGPU.h +++ lib/Target/AMDGPU/AMDGPU.h @@ -190,6 +190,8 @@ ImmutablePass *createAMDGPUAAWrapperPass(); void initializeAMDGPUAAWrapperPassPass(PassRegistry&); +ImmutablePass *createAMDGPUExternalAAWrapperPass(); +void initializeAMDGPUExternalAAWrapperPass(PassRegistry&); void initializeAMDGPUArgumentUsageInfoPass(PassRegistry &); Index: lib/Target/AMDGPU/AMDGPUAliasAnalysis.h =================================================================== --- lib/Target/AMDGPU/AMDGPUAliasAnalysis.h +++ lib/Target/AMDGPU/AMDGPUAliasAnalysis.h @@ -107,6 +107,19 @@ void getAnalysisUsage(AnalysisUsage &AU) const override; }; +// Wrapper around ExternalAAWrapperPass so that the default constructor gets the +// callback. +class AMDGPUExternalAAWrapper : public ExternalAAWrapperPass { +public: + static char ID; + + AMDGPUExternalAAWrapper() : ExternalAAWrapperPass( + [](Pass &P, Function &, AAResults &AAR) { + if (auto *WrapperPass = P.getAnalysisIfAvailable()) + AAR.addAAResult(WrapperPass->getResult()); + }) {} +}; + } // end namespace llvm #endif // LLVM_LIB_TARGET_AMDGPU_AMDGPUALIASANALYSIS_H Index: lib/Target/AMDGPU/AMDGPUAliasAnalysis.cpp =================================================================== --- lib/Target/AMDGPU/AMDGPUAliasAnalysis.cpp +++ lib/Target/AMDGPU/AMDGPUAliasAnalysis.cpp @@ -34,14 +34,22 @@ // Register this pass... char AMDGPUAAWrapperPass::ID = 0; +char AMDGPUExternalAAWrapper::ID = 0; INITIALIZE_PASS(AMDGPUAAWrapperPass, "amdgpu-aa", "AMDGPU Address space based Alias Analysis", false, true) +INITIALIZE_PASS(AMDGPUExternalAAWrapper, "amdgpu-aa-wrapper", + "AMDGPU Address space based Alias Analysis Wrapper", false, true) + ImmutablePass *llvm::createAMDGPUAAWrapperPass() { return new AMDGPUAAWrapperPass(); } +ImmutablePass *llvm::createAMDGPUExternalAAWrapperPass() { + return new AMDGPUExternalAAWrapper(); +} + void AMDGPUAAWrapperPass::getAnalysisUsage(AnalysisUsage &AU) const { AU.setPreservesAll(); } Index: lib/Target/AMDGPU/AMDGPUTargetMachine.cpp =================================================================== --- lib/Target/AMDGPU/AMDGPUTargetMachine.cpp +++ lib/Target/AMDGPU/AMDGPUTargetMachine.cpp @@ -182,6 +182,7 @@ initializeSIFormMemoryClausesPass(*PR); initializeAMDGPUUnifyDivergentExitNodesPass(*PR); initializeAMDGPUAAWrapperPassPass(*PR); + initializeAMDGPUExternalAAWrapperPass(*PR); initializeAMDGPUUseNativeCallsPass(*PR); initializeAMDGPUSimplifyLibCallsPass(*PR); initializeAMDGPUInlinerPass(*PR); @@ -330,13 +331,6 @@ FSAttr.getValueAsString(); } -static ImmutablePass *createAMDGPUExternalAAWrapperPass() { - return createExternalAAWrapperPass([](Pass &P, Function &, AAResults &AAR) { - if (auto *WrapperPass = P.getAnalysisIfAvailable()) - AAR.addAAResult(WrapperPass->getResult()); - }); -} - /// Predicate for Internalize pass. static bool mustPreserveGV(const GlobalValue &GV) { if (const Function *F = dyn_cast(&GV)) Index: test/CodeGen/AMDGPU/amdgpu-alias-analysis.ll =================================================================== --- test/CodeGen/AMDGPU/amdgpu-alias-analysis.ll +++ test/CodeGen/AMDGPU/amdgpu-alias-analysis.ll @@ -1,5 +1,5 @@ -; RUN: opt -mtriple=amdgcn-- -O3 -aa-eval -print-all-alias-modref-info -disable-output < %s 2>&1 | FileCheck %s -; RUN: opt -mtriple=r600-- -O3 -aa-eval -print-all-alias-modref-info -disable-output < %s 2>&1 | FileCheck %s +; 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 +; 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 ; CHECK: NoAlias: i8 addrspace(1)* %p1, i8 addrspace(5)* %p