Skip to content

[AMDGPU] Port AMDGPURewriteUndefForPHI to new pass manager #66008

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Sep 12, 2023

Conversation

jwanggit86
Copy link
Contributor

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.

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.
@jwanggit86 jwanggit86 requested a review from arsenm September 11, 2023 20:47
@jwanggit86 jwanggit86 requested a review from a team as a code owner September 11, 2023 20:47
@llvmbot
Copy link
Member

llvmbot commented Sep 11, 2023

@llvm/pr-subscribers-backend-amdgpu

Changes

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)
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 {
+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(F);
+  DominatorTree *DT = &AM.getResult(F);
+  bool Changed = rewritePHIs(F, UA, DT);
+  if (Changed) {
+    PreservedAnalyses PA;
+    PA.preserveSet();
+    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(

@jwanggit86 jwanggit86 changed the title [AMDGPU} Port AMDGPURewriteUndefForPHI to new pass manager [AMDGPU] Port AMDGPURewriteUndefForPHI to new pass manager Sep 11, 2023

return PreservedAnalyses::all();
}

FunctionPass *llvm::createAMDGPURewriteUndefForPHIPass() {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should rename all the legacy pass bits to end with "LegacyPass"

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should the class "AMDGPURewriteUndefForPHI" be renamed "AMDGPURewriteUndefForPHILegacy" or "AMDGPURewriteUndefForPHILegacyPass"? If the latter, we will end up with a function named "initializeAMDGPURewriteUndefForPHILegacyPassPass".

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

AMDGPURewriteUndefForPHILegacy, some places have always been stuck with "PassPass"

@jwanggit86 jwanggit86 force-pushed the port-rewrite-undef-to-new-pass-mgr branch from f2068b9 to c68ad69 Compare September 11, 2023 21:01
Jun Wang added 2 commits September 12, 2023 12:23
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.
PreservedAnalyses
AMDGPURewriteUndefForPHIPass::run(Function &F, FunctionAnalysisManager &AM) {
UniformityInfo &UA = AM.getResult<UniformityInfoAnalysis>(F);
DominatorTree *DT = &AM.getResult<DominatorTreeAnalysis>(F);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why address of here?

@jwanggit86 jwanggit86 merged commit b853988 into llvm:main Sep 12, 2023
@jwanggit86 jwanggit86 deleted the port-rewrite-undef-to-new-pass-mgr branch September 12, 2023 20:32
ZijunZhaoCCK pushed a commit to ZijunZhaoCCK/llvm-project that referenced this pull request Sep 19, 2023
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.

---------

Co-authored-by: Jun Wang <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants