[llvm] 77e68fb - AMDGPU/NewPM: Port AMDGPUAnnotateUniformValues to new pass manager (#102654)
via llvm-commits
llvm-commits at lists.llvm.org
Fri Aug 9 20:06:12 PDT 2024
Author: Matt Arsenault
Date: 2024-08-10T07:06:08+04:00
New Revision: 77e68fbdd3fdc205bafa042fcb87014011dc7799
URL: https://github.com/llvm/llvm-project/commit/77e68fbdd3fdc205bafa042fcb87014011dc7799
DIFF: https://github.com/llvm/llvm-project/commit/77e68fbdd3fdc205bafa042fcb87014011dc7799.diff
LOG: AMDGPU/NewPM: Port AMDGPUAnnotateUniformValues to new pass manager (#102654)
Added:
Modified:
llvm/lib/Target/AMDGPU/AMDGPU.h
llvm/lib/Target/AMDGPU/AMDGPUAnnotateUniformValues.cpp
llvm/lib/Target/AMDGPU/AMDGPUPassRegistry.def
llvm/lib/Target/AMDGPU/AMDGPUTargetMachine.cpp
llvm/test/CodeGen/AMDGPU/annotate-noclobber.ll
Removed:
################################################################################
diff --git a/llvm/lib/Target/AMDGPU/AMDGPU.h b/llvm/lib/Target/AMDGPU/AMDGPU.h
index 9a856ca19211b..80a20beb9f6b0 100644
--- a/llvm/lib/Target/AMDGPU/AMDGPU.h
+++ b/llvm/lib/Target/AMDGPU/AMDGPU.h
@@ -300,7 +300,14 @@ class AMDGPUAttributorPass : public PassInfoMixin<AMDGPUAttributorPass> {
PreservedAnalyses run(Module &M, ModuleAnalysisManager &AM);
};
-FunctionPass *createAMDGPUAnnotateUniformValues();
+class AMDGPUAnnotateUniformValuesPass
+ : public PassInfoMixin<AMDGPUAnnotateUniformValuesPass> {
+public:
+ AMDGPUAnnotateUniformValuesPass() {}
+ PreservedAnalyses run(Function &F, FunctionAnalysisManager &AM);
+};
+
+FunctionPass *createAMDGPUAnnotateUniformValuesLegacy();
ModulePass *createAMDGPUPrintfRuntimeBinding();
void initializeAMDGPUPrintfRuntimeBindingPass(PassRegistry&);
@@ -328,8 +335,8 @@ extern char &SIOptimizeExecMaskingPreRAID;
void initializeSIOptimizeVGPRLiveRangePass(PassRegistry &);
extern char &SIOptimizeVGPRLiveRangeID;
-void initializeAMDGPUAnnotateUniformValuesPass(PassRegistry&);
-extern char &AMDGPUAnnotateUniformValuesPassID;
+void initializeAMDGPUAnnotateUniformValuesLegacyPass(PassRegistry &);
+extern char &AMDGPUAnnotateUniformValuesLegacyPassID;
void initializeAMDGPUCodeGenPreparePass(PassRegistry&);
extern char &AMDGPUCodeGenPrepareID;
diff --git a/llvm/lib/Target/AMDGPU/AMDGPUAnnotateUniformValues.cpp b/llvm/lib/Target/AMDGPU/AMDGPUAnnotateUniformValues.cpp
index 6a409f0dcbe77..fa66d53bd7c64 100644
--- a/llvm/lib/Target/AMDGPU/AMDGPUAnnotateUniformValues.cpp
+++ b/llvm/lib/Target/AMDGPU/AMDGPUAnnotateUniformValues.cpp
@@ -27,8 +27,8 @@ using namespace llvm;
namespace {
-class AMDGPUAnnotateUniformValues : public FunctionPass,
- public InstVisitor<AMDGPUAnnotateUniformValues> {
+class AMDGPUAnnotateUniformValues
+ : public InstVisitor<AMDGPUAnnotateUniformValues> {
UniformityInfo *UA;
MemorySSA *MSSA;
AliasAnalysis *AA;
@@ -46,37 +46,19 @@ class AMDGPUAnnotateUniformValues : public FunctionPass,
}
public:
- static char ID;
- AMDGPUAnnotateUniformValues() :
- FunctionPass(ID) { }
- bool doInitialization(Module &M) override;
- bool runOnFunction(Function &F) override;
- StringRef getPassName() const override {
- return "AMDGPU Annotate Uniform Values";
- }
- void getAnalysisUsage(AnalysisUsage &AU) const override {
- AU.addRequired<UniformityInfoWrapperPass>();
- AU.addRequired<MemorySSAWrapperPass>();
- AU.addRequired<AAResultsWrapperPass>();
- AU.setPreservesAll();
- }
+ AMDGPUAnnotateUniformValues(UniformityInfo &UA, MemorySSA &MSSA,
+ AliasAnalysis &AA, const Function &F)
+ : UA(&UA), MSSA(&MSSA), AA(&AA),
+ isEntryFunc(AMDGPU::isEntryFunctionCC(F.getCallingConv())) {}
void visitBranchInst(BranchInst &I);
void visitLoadInst(LoadInst &I);
+
+ bool changed() const { return Changed; }
};
} // End anonymous namespace
-INITIALIZE_PASS_BEGIN(AMDGPUAnnotateUniformValues, DEBUG_TYPE,
- "Add AMDGPU uniform metadata", false, false)
-INITIALIZE_PASS_DEPENDENCY(UniformityInfoWrapperPass)
-INITIALIZE_PASS_DEPENDENCY(MemorySSAWrapperPass)
-INITIALIZE_PASS_DEPENDENCY(AAResultsWrapperPass)
-INITIALIZE_PASS_END(AMDGPUAnnotateUniformValues, DEBUG_TYPE,
- "Add AMDGPU uniform metadata", false, false)
-
-char AMDGPUAnnotateUniformValues::ID = 0;
-
void AMDGPUAnnotateUniformValues::visitBranchInst(BranchInst &I) {
if (UA->isUniform(&I))
setUniformMetadata(&I);
@@ -100,25 +82,70 @@ void AMDGPUAnnotateUniformValues::visitLoadInst(LoadInst &I) {
setNoClobberMetadata(&I);
}
-bool AMDGPUAnnotateUniformValues::doInitialization(Module &M) {
- return false;
+PreservedAnalyses
+AMDGPUAnnotateUniformValuesPass::run(Function &F,
+ FunctionAnalysisManager &FAM) {
+ UniformityInfo &UI = FAM.getResult<UniformityInfoAnalysis>(F);
+ MemorySSA &MSSA = FAM.getResult<MemorySSAAnalysis>(F).getMSSA();
+ AAResults &AA = FAM.getResult<AAManager>(F);
+
+ AMDGPUAnnotateUniformValues Impl(UI, MSSA, AA, F);
+ Impl.visit(F);
+
+ PreservedAnalyses PA = PreservedAnalyses::none();
+ if (!Impl.changed())
+ return PA;
+
+ // TODO: Should preserve nearly everything
+ PA.preserveSet<CFGAnalyses>();
+ return PA;
}
-bool AMDGPUAnnotateUniformValues::runOnFunction(Function &F) {
+class AMDGPUAnnotateUniformValuesLegacy : public FunctionPass {
+public:
+ static char ID;
+
+ AMDGPUAnnotateUniformValuesLegacy() : FunctionPass(ID) {}
+
+ bool doInitialization(Module &M) override { return false; }
+
+ bool runOnFunction(Function &F) override;
+ StringRef getPassName() const override {
+ return "AMDGPU Annotate Uniform Values";
+ }
+
+ void getAnalysisUsage(AnalysisUsage &AU) const override {
+ AU.addRequired<UniformityInfoWrapperPass>();
+ AU.addRequired<MemorySSAWrapperPass>();
+ AU.addRequired<AAResultsWrapperPass>();
+ AU.setPreservesAll();
+ }
+};
+
+bool AMDGPUAnnotateUniformValuesLegacy::runOnFunction(Function &F) {
if (skipFunction(F))
return false;
- UA = &getAnalysis<UniformityInfoWrapperPass>().getUniformityInfo();
- MSSA = &getAnalysis<MemorySSAWrapperPass>().getMSSA();
- AA = &getAnalysis<AAResultsWrapperPass>().getAAResults();
- isEntryFunc = AMDGPU::isEntryFunctionCC(F.getCallingConv());
+ UniformityInfo &UI =
+ getAnalysis<UniformityInfoWrapperPass>().getUniformityInfo();
+ MemorySSA &MSSA = getAnalysis<MemorySSAWrapperPass>().getMSSA();
+ AliasAnalysis &AA = getAnalysis<AAResultsWrapperPass>().getAAResults();
- Changed = false;
- visit(F);
- return Changed;
+ AMDGPUAnnotateUniformValues Impl(UI, MSSA, AA, F);
+ Impl.visit(F);
+ return Impl.changed();
}
-FunctionPass *
-llvm::createAMDGPUAnnotateUniformValues() {
- return new AMDGPUAnnotateUniformValues();
+INITIALIZE_PASS_BEGIN(AMDGPUAnnotateUniformValuesLegacy, DEBUG_TYPE,
+ "Add AMDGPU uniform metadata", false, false)
+INITIALIZE_PASS_DEPENDENCY(UniformityInfoWrapperPass)
+INITIALIZE_PASS_DEPENDENCY(MemorySSAWrapperPass)
+INITIALIZE_PASS_DEPENDENCY(AAResultsWrapperPass)
+INITIALIZE_PASS_END(AMDGPUAnnotateUniformValuesLegacy, DEBUG_TYPE,
+ "Add AMDGPU uniform metadata", false, false)
+
+char AMDGPUAnnotateUniformValuesLegacy::ID = 0;
+
+FunctionPass *llvm::createAMDGPUAnnotateUniformValuesLegacy() {
+ return new AMDGPUAnnotateUniformValuesLegacy();
}
diff --git a/llvm/lib/Target/AMDGPU/AMDGPUPassRegistry.def b/llvm/lib/Target/AMDGPU/AMDGPUPassRegistry.def
index 5391e0dc97cf1..f7a3cf04a4d50 100644
--- a/llvm/lib/Target/AMDGPU/AMDGPUPassRegistry.def
+++ b/llvm/lib/Target/AMDGPU/AMDGPUPassRegistry.def
@@ -39,6 +39,7 @@ MODULE_PASS_WITH_PARAMS(
#ifndef FUNCTION_PASS
#define FUNCTION_PASS(NAME, CREATE_PASS)
#endif
+FUNCTION_PASS("amdgpu-annotate-uniform", AMDGPUAnnotateUniformValuesPass())
FUNCTION_PASS("amdgpu-codegenprepare", AMDGPUCodeGenPreparePass(*this))
FUNCTION_PASS("amdgpu-image-intrinsic-opt",
AMDGPUImageIntrinsicOptimizerPass(*this))
diff --git a/llvm/lib/Target/AMDGPU/AMDGPUTargetMachine.cpp b/llvm/lib/Target/AMDGPU/AMDGPUTargetMachine.cpp
index 393bd7cce07d4..0f413090a1878 100644
--- a/llvm/lib/Target/AMDGPU/AMDGPUTargetMachine.cpp
+++ b/llvm/lib/Target/AMDGPU/AMDGPUTargetMachine.cpp
@@ -413,7 +413,7 @@ extern "C" LLVM_EXTERNAL_VISIBILITY void LLVMInitializeAMDGPUTarget() {
initializeAMDGPUAlwaysInlinePass(*PR);
initializeAMDGPUAttributorLegacyPass(*PR);
initializeAMDGPUAnnotateKernelFeaturesPass(*PR);
- initializeAMDGPUAnnotateUniformValuesPass(*PR);
+ initializeAMDGPUAnnotateUniformValuesLegacyPass(*PR);
initializeAMDGPUArgumentUsageInfoPass(*PR);
initializeAMDGPUAtomicOptimizerPass(*PR);
initializeAMDGPULowerKernelArgumentsPass(*PR);
@@ -1238,7 +1238,7 @@ bool GCNPassConfig::addPreISel() {
}
addPass(createStructurizeCFGPass(false)); // true -> SkipUniformRegions
}
- addPass(createAMDGPUAnnotateUniformValues());
+ addPass(createAMDGPUAnnotateUniformValuesLegacy());
if (!LateCFGStructurize && !DisableStructurizer) {
addPass(createSIAnnotateControlFlowLegacyPass());
// TODO: Move this right after structurizeCFG to avoid extra divergence
diff --git a/llvm/test/CodeGen/AMDGPU/annotate-noclobber.ll b/llvm/test/CodeGen/AMDGPU/annotate-noclobber.ll
index 4b20a3ef40270..63b0ae269c318 100644
--- a/llvm/test/CodeGen/AMDGPU/annotate-noclobber.ll
+++ b/llvm/test/CodeGen/AMDGPU/annotate-noclobber.ll
@@ -1,4 +1,5 @@
-; RUN: opt -S --amdgpu-annotate-uniform < %s | FileCheck -check-prefix=OPT %s
+; RUN: opt -S -mtriple=amdgcn-amd-amdhsa --amdgpu-annotate-uniform < %s | FileCheck -check-prefix=OPT %s
+; RUN: opt -S -mtriple=amdgcn-amd-amdhsa -passes=amdgpu-annotate-uniform < %s | FileCheck -check-prefix=OPT %s
target datalayout = "A5"
More information about the llvm-commits
mailing list