[llvm] [AMDGPU} Port AMDGPURewriteUndefForPHI to new pass manager (PR #66008)
via llvm-commits
llvm-commits at lists.llvm.org
Mon Sep 11 13:48:22 PDT 2023
llvmbot wrote:
@llvm/pr-subscribers-backend-amdgpu
<details>
<summary>Changes</summary>
This patch ports the AMDGPURewriteUndefForPHI pass to the new pass manager. With this, the pass is supported under both the legacy and the new pass managers.
--
Full diff: https://github.com/llvm/llvm-project/pull/66008.diff
4 Files Affected:
- (modified) llvm/lib/Target/AMDGPU/AMDGPU.h (+10)
- (modified) llvm/lib/Target/AMDGPU/AMDGPURewriteUndefForPHI.cpp (+14)
- (modified) llvm/lib/Target/AMDGPU/AMDGPUTargetMachine.cpp (+4)
- (modified) llvm/test/CodeGen/AMDGPU/rewrite-undef-for-phi.ll (+1)
<pre>
diff --git a/llvm/lib/Target/AMDGPU/AMDGPU.h b/llvm/lib/Target/AMDGPU/AMDGPU.h
index 157a02ec31b2ec6..434943490caeab3 100644
--- a/llvm/lib/Target/AMDGPU/AMDGPU.h
+++ b/llvm/lib/Target/AMDGPU/AMDGPU.h
@@ -291,6 +291,16 @@ FunctionPass *createAMDGPURewriteUndefForPHIPass();
void initializeAMDGPURewriteUndefForPHIPass(PassRegistry &);
extern char &AMDGPURewriteUndefForPHIPassID;
+class AMDGPURewriteUndefForPHIPass
+ : public PassInfoMixin<AMDGPURewriteUndefForPHIPass> {
+private:
+ TargetMachine &TM;
+
+public:
+ AMDGPURewriteUndefForPHIPass(TargetMachine &TM) : TM(TM){};
+ PreservedAnalyses run(Function &F, FunctionAnalysisManager &AM);
+};
+
void initializeSIAnnotateControlFlowPass(PassRegistry&);
extern char &SIAnnotateControlFlowPassID;
diff --git a/llvm/lib/Target/AMDGPU/AMDGPURewriteUndefForPHI.cpp b/llvm/lib/Target/AMDGPU/AMDGPURewriteUndefForPHI.cpp
index 9c07851243c9173..3e9625e954ea653 100644
--- a/llvm/lib/Target/AMDGPU/AMDGPURewriteUndefForPHI.cpp
+++ b/llvm/lib/Target/AMDGPU/AMDGPURewriteUndefForPHI.cpp
@@ -177,6 +177,20 @@ bool AMDGPURewriteUndefForPHI::runOnFunction(Function &F) {
return rewritePHIs(F, UA, DT);
}
+PreservedAnalyses
+AMDGPURewriteUndefForPHIPass::run(Function &F, FunctionAnalysisManager &AM) {
+ UniformityInfo &UA = AM.getResult<UniformityInfoAnalysis>(F);
+ DominatorTree *DT = &AM.getResult<DominatorTreeAnalysis>(F);
+ bool Changed = rewritePHIs(F, UA, DT);
+ if (Changed) {
+ PreservedAnalyses PA;
+ PA.preserveSet<CFGAnalyses>();
+ return PA;
+ }
+
+ return PreservedAnalyses::all();
+}
+
FunctionPass *llvm::createAMDGPURewriteUndefForPHIPass() {
return new AMDGPURewriteUndefForPHI();
}
diff --git a/llvm/lib/Target/AMDGPU/AMDGPUTargetMachine.cpp b/llvm/lib/Target/AMDGPU/AMDGPUTargetMachine.cpp
index 991681dafedaad1..befa036ee32df14 100644
--- a/llvm/lib/Target/AMDGPU/AMDGPUTargetMachine.cpp
+++ b/llvm/lib/Target/AMDGPU/AMDGPUTargetMachine.cpp
@@ -663,6 +663,10 @@ void AMDGPUTargetMachine::registerPassBuilderCallbacks(PassBuilder &PB) {
PM.addPass(AMDGPULowerKernelArgumentsPass(*this));
return true;
}
+ if (PassName == "amdgpu-rewrite-undef-for-phi") {
+ PM.addPass(AMDGPURewriteUndefForPHIPass(*this));
+ return true;
+ }
return false;
});
diff --git a/llvm/test/CodeGen/AMDGPU/rewrite-undef-for-phi.ll b/llvm/test/CodeGen/AMDGPU/rewrite-undef-for-phi.ll
index c0f6c5ae0240a69..4f6b9f474c13171 100644
--- a/llvm/test/CodeGen/AMDGPU/rewrite-undef-for-phi.ll
+++ b/llvm/test/CodeGen/AMDGPU/rewrite-undef-for-phi.ll
@@ -1,5 +1,6 @@
; NOTE: Assertions have been autogenerated by utils/update_test_checks.py
; RUN: opt -mtriple=amdgcn-- -S -amdgpu-rewrite-undef-for-phi %s | FileCheck -check-prefix=OPT %s
+; RUN: opt -mtriple=amdgcn-- -S -passes=amdgpu-rewrite-undef-for-phi %s | FileCheck -check-prefix=OPT %s
define amdgpu_ps float @basic(float inreg %c, i32 %x) #0 {
; OPT-LABEL: @basic(
</pre>
</details>
https://github.com/llvm/llvm-project/pull/66008
More information about the llvm-commits
mailing list