https://github.com/vikramRH updated 
https://github.com/llvm/llvm-project/pull/148111

>From 85f834967d5d32b9c687543b705271ffac2bbb32 Mon Sep 17 00:00:00 2001
From: vikhegde <vikram.he...@amd.com>
Date: Thu, 10 Jul 2025 16:24:23 +0530
Subject: [PATCH 1/2] [CodeGen][NPM] Account inserted passes for -start/stop
 options

---
 llvm/include/llvm/Passes/CodeGenPassBuilder.h     |  6 ++++--
 llvm/test/tools/llc/new-pm/start-stop-inserted.ll | 15 +++++++++++++++
 2 files changed, 19 insertions(+), 2 deletions(-)
 create mode 100644 llvm/test/tools/llc/new-pm/start-stop-inserted.ll

diff --git a/llvm/include/llvm/Passes/CodeGenPassBuilder.h 
b/llvm/include/llvm/Passes/CodeGenPassBuilder.h
index dc5f3f80f547e..44024a4c0a8da 100644
--- a/llvm/include/llvm/Passes/CodeGenPassBuilder.h
+++ b/llvm/include/llvm/Passes/CodeGenPassBuilder.h
@@ -579,8 +579,10 @@ template <typename DerivedT, typename TargetMachineT> 
class CodeGenPassBuilder {
   void insertPass(InsertedPassT &&Pass) const {
     AfterCallbacks.emplace_back(
         [&](StringRef Name, MachineFunctionPassManager &MFPM) mutable {
-          if (Name == TargetPassT::name())
-            MFPM.addPass(std::forward<InsertedPassT>(Pass));
+          if (Name == TargetPassT::name()) {
+            if (runBeforeAdding(InsertedPassT::name()))
+              MFPM.addPass(std::forward<InsertedPassT>(Pass));
+          }
         });
   }
 
diff --git a/llvm/test/tools/llc/new-pm/start-stop-inserted.ll 
b/llvm/test/tools/llc/new-pm/start-stop-inserted.ll
new file mode 100644
index 0000000000000..ce5ad2d9e5065
--- /dev/null
+++ b/llvm/test/tools/llc/new-pm/start-stop-inserted.ll
@@ -0,0 +1,15 @@
+; REQUIRES: amdgpu-registered-target
+
+; AMDGPU inserts the fourth instance of dead-mi-elimination pass after 
detect-dead-lanes
+; This checks that the pipeline stops before that.
+
+; RUN: llc -mtriple=amdgcn-amd-amdhsa -O3 -enable-new-pm 
-stop-before=dead-mi-elimination,4 --print-pipeline-passes -filetype=null %s | 
FileCheck %s
+
+; There is no way to -start-after an inserted pass right now.
+; RUN: not llc -mtriple=amdgcn-amd-amdhsa -O3 -enable-new-pm 
-start-after=dead-mi-elimination,4 --print-pipeline-passes -filetype=null %s
+
+
+; CHECK: dead-mi-elimination
+; CHECK: dead-mi-elimination
+; CHECK: dead-mi-elimination
+; CHECK-NOT: dead-mi-elimination

>From 7f105c019984693d21e5e4870c53ff9445764ee9 Mon Sep 17 00:00:00 2001
From: vikhegde <vikram.he...@amd.com>
Date: Mon, 14 Jul 2025 11:38:59 +0530
Subject: [PATCH 2/2] review comment

---
 llvm/include/llvm/Passes/CodeGenPassBuilder.h | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)

diff --git a/llvm/include/llvm/Passes/CodeGenPassBuilder.h 
b/llvm/include/llvm/Passes/CodeGenPassBuilder.h
index 44024a4c0a8da..a8176ebb776cf 100644
--- a/llvm/include/llvm/Passes/CodeGenPassBuilder.h
+++ b/llvm/include/llvm/Passes/CodeGenPassBuilder.h
@@ -579,9 +579,9 @@ template <typename DerivedT, typename TargetMachineT> class 
CodeGenPassBuilder {
   void insertPass(InsertedPassT &&Pass) const {
     AfterCallbacks.emplace_back(
         [&](StringRef Name, MachineFunctionPassManager &MFPM) mutable {
-          if (Name == TargetPassT::name()) {
-            if (runBeforeAdding(InsertedPassT::name()))
-              MFPM.addPass(std::forward<InsertedPassT>(Pass));
+          if (Name == TargetPassT::name() &&
+              runBeforeAdding(InsertedPassT::name())) {
+            MFPM.addPass(std::forward<InsertedPassT>(Pass));
           }
         });
   }

_______________________________________________
llvm-branch-commits mailing list
llvm-branch-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits

Reply via email to