forked from OSchip/llvm-project
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. llvm-svn: 346353
This commit is contained in:
parent
e06fb482a9
commit
8ba740a5a8
|
@ -1074,6 +1074,29 @@ public:
|
|||
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<void(Pass &, Function &, AAResults &)>;
|
||||
|
||||
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
|
||||
|
|
|
@ -640,28 +640,6 @@ AnalysisKey AAManager::Key;
|
|||
|
||||
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<void(Pass &, Function &, AAResults &)>;
|
||||
|
||||
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
|
||||
|
||||
|
|
|
@ -198,6 +198,8 @@ extern char &AMDGPUUnifyDivergentExitNodesID;
|
|||
|
||||
ImmutablePass *createAMDGPUAAWrapperPass();
|
||||
void initializeAMDGPUAAWrapperPassPass(PassRegistry&);
|
||||
ImmutablePass *createAMDGPUExternalAAWrapperPass();
|
||||
void initializeAMDGPUExternalAAWrapperPass(PassRegistry&);
|
||||
|
||||
void initializeAMDGPUArgumentUsageInfoPass(PassRegistry &);
|
||||
|
||||
|
|
|
@ -34,14 +34,22 @@ using namespace llvm;
|
|||
|
||||
// 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();
|
||||
}
|
||||
|
|
|
@ -96,6 +96,19 @@ public:
|
|||
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<AMDGPUAAWrapperPass>())
|
||||
AAR.addAAResult(WrapperPass->getResult());
|
||||
}) {}
|
||||
};
|
||||
|
||||
} // end namespace llvm
|
||||
|
||||
#endif // LLVM_LIB_TARGET_AMDGPU_AMDGPUALIASANALYSIS_H
|
||||
|
|
|
@ -192,6 +192,7 @@ extern "C" void LLVMInitializeAMDGPUTarget() {
|
|||
initializeSIFormMemoryClausesPass(*PR);
|
||||
initializeAMDGPUUnifyDivergentExitNodesPass(*PR);
|
||||
initializeAMDGPUAAWrapperPassPass(*PR);
|
||||
initializeAMDGPUExternalAAWrapperPass(*PR);
|
||||
initializeAMDGPUUseNativeCallsPass(*PR);
|
||||
initializeAMDGPUSimplifyLibCallsPass(*PR);
|
||||
initializeAMDGPUInlinerPass(*PR);
|
||||
|
@ -340,13 +341,6 @@ StringRef AMDGPUTargetMachine::getFeatureString(const Function &F) const {
|
|||
FSAttr.getValueAsString();
|
||||
}
|
||||
|
||||
static ImmutablePass *createAMDGPUExternalAAWrapperPass() {
|
||||
return createExternalAAWrapperPass([](Pass &P, Function &, AAResults &AAR) {
|
||||
if (auto *WrapperPass = P.getAnalysisIfAvailable<AMDGPUAAWrapperPass>())
|
||||
AAR.addAAResult(WrapperPass->getResult());
|
||||
});
|
||||
}
|
||||
|
||||
/// Predicate for Internalize pass.
|
||||
static bool mustPreserveGV(const GlobalValue &GV) {
|
||||
if (const Function *F = dyn_cast<Function>(&GV))
|
||||
|
|
|
@ -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
|
||||
|
||||
|
|
Loading…
Reference in New Issue