[llvm-branch-commits] [llvm] AMDGPU/NewPM: Port AMDGPUAnnotateUniformValues to new pass manager (PR #102654)
via llvm-branch-commits
llvm-branch-commits at lists.llvm.org
Fri Aug 9 11:02:04 PDT 2024
llvmbot wrote:
<!--LLVM PR SUMMARY COMMENT-->
@llvm/pr-subscribers-backend-amdgpu
Author: Matt Arsenault (arsenm)
<details>
<summary>Changes</summary>
---
Full diff: https://github.com/llvm/llvm-project/pull/102654.diff
5 Files Affected:
- (modified) llvm/lib/Target/AMDGPU/AMDGPU.h (+10-3)
- (modified) llvm/lib/Target/AMDGPU/AMDGPUAnnotateUniformValues.cpp (+66-39)
- (modified) llvm/lib/Target/AMDGPU/AMDGPUPassRegistry.def (+1)
- (modified) llvm/lib/Target/AMDGPU/AMDGPUTargetMachine.cpp (+2-2)
- (modified) llvm/test/CodeGen/AMDGPU/annotate-noclobber.ll (+2-1)
``````````diff
diff --git a/llvm/lib/Target/AMDGPU/AMDGPU.h b/llvm/lib/Target/AMDGPU/AMDGPU.h
index 6b5754dad1770..99b04d6e4cfc3 100644
--- a/llvm/lib/Target/AMDGPU/AMDGPU.h
+++ b/llvm/lib/Target/AMDGPU/AMDGPU.h
@@ -293,7 +293,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&);
@@ -321,8 +328,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 c08b6d33d6a76..cbb19c003a264 100644
--- a/llvm/lib/Target/AMDGPU/AMDGPUPassRegistry.def
+++ b/llvm/lib/Target/AMDGPU/AMDGPUPassRegistry.def
@@ -29,6 +29,7 @@ MODULE_PASS("amdgpu-unify-metadata", AMDGPUUnifyMetadataPass())
#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 f8abfceb76987..3cc0d314a7c5d 100644
--- a/llvm/lib/Target/AMDGPU/AMDGPUTargetMachine.cpp
+++ b/llvm/lib/Target/AMDGPU/AMDGPUTargetMachine.cpp
@@ -417,7 +417,7 @@ extern "C" LLVM_EXTERNAL_VISIBILITY void LLVMInitializeAMDGPUTarget() {
initializeAMDGPUAlwaysInlinePass(*PR);
initializeAMDGPUAttributorLegacyPass(*PR);
initializeAMDGPUAnnotateKernelFeaturesPass(*PR);
- initializeAMDGPUAnnotateUniformValuesPass(*PR);
+ initializeAMDGPUAnnotateUniformValuesLegacyPass(*PR);
initializeAMDGPUArgumentUsageInfoPass(*PR);
initializeAMDGPUAtomicOptimizerPass(*PR);
initializeAMDGPULowerKernelArgumentsPass(*PR);
@@ -1218,7 +1218,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"
``````````
</details>
https://github.com/llvm/llvm-project/pull/102654
More information about the llvm-branch-commits
mailing list