[llvm] [NewPM] Teach llc -passes to handle target machine analysis (PR #191704)

via llvm-commits llvm-commits at lists.llvm.org
Mon Apr 13 04:47:40 PDT 2026


https://github.com/macurtis-amd updated https://github.com/llvm/llvm-project/pull/191704

>From db41b450f308b3fea9ae17ddc93a752ea249f848 Mon Sep 17 00:00:00 2001
From: Matthew Curtis <macurtis at amd.com>
Date: Sun, 12 Apr 2026 07:20:58 -0500
Subject: [PATCH 1/3] [NewPM] Teach llc -passes to handle target machine
 analysis

---
 .../include/llvm/Passes/TargetPassRegistry.inc | 18 ++++++++++++++++++
 .../AMDGPU/new-pm-req-machine-analysis.mir     |  9 +++++++++
 2 files changed, 27 insertions(+)
 create mode 100644 llvm/test/CodeGen/AMDGPU/new-pm-req-machine-analysis.mir

diff --git a/llvm/include/llvm/Passes/TargetPassRegistry.inc b/llvm/include/llvm/Passes/TargetPassRegistry.inc
index 068b27794191c..4e778e77fa128 100644
--- a/llvm/include/llvm/Passes/TargetPassRegistry.inc
+++ b/llvm/include/llvm/Passes/TargetPassRegistry.inc
@@ -92,6 +92,14 @@ if (PIC) {
     return true;                                                               \
   }
 
+#define ADD_ANALYSIS_PASS(NAME, CREATE_PASS)                                   \
+  if (Name == "require<" NAME ">") {                                           \
+    PM.addPass(                                                                \
+        RequireAnalysisPass<std::remove_reference_t<decltype(CREATE_PASS)>,    \
+                            MachineFunction>());                               \
+    return true;                                                               \
+  }
+
 PB.registerPipelineParsingCallback([=](StringRef Name, ModulePassManager &PM,
                                        ArrayRef<PassBuilder::PipelineElement>) {
 #define MODULE_PASS(NAME, CREATE_PASS) ADD_PASS(NAME, CREATE_PASS)
@@ -151,6 +159,16 @@ PB.registerPipelineParsingCallback([=](StringRef Name, FunctionPassManager &PM,
   return false;
 });
 
+PB.registerPipelineParsingCallback([=](StringRef Name,
+                                       MachineFunctionPassManager &PM,
+                                       ArrayRef<PassBuilder::PipelineElement>) {
+#define MACHINE_FUNCTION_ANALYSIS(NAME, CREATE_PASS)                           \
+  ADD_ANALYSIS_PASS(NAME, CREATE_PASS)
+#include GET_PASS_REGISTRY
+#undef MACHINE_FUNCTION_ANALYSIS
+  return false;
+});
+
 #undef ADD_PASS
 #undef ADD_PASS_WITH_PARAMS
 
diff --git a/llvm/test/CodeGen/AMDGPU/new-pm-req-machine-analysis.mir b/llvm/test/CodeGen/AMDGPU/new-pm-req-machine-analysis.mir
new file mode 100644
index 0000000000000..ab7d84be8d617
--- /dev/null
+++ b/llvm/test/CodeGen/AMDGPU/new-pm-req-machine-analysis.mir
@@ -0,0 +1,9 @@
+# RUN: llc -mtriple=amdgcn "-passes=require<amdgpu-resource-usage>" -filetype=null %s
+---
+name:            test
+body:             |
+  bb.0:
+    S_NOP 0
+...
+
+

>From e69122cde812b811d1b0112298a33bf1531f5e08 Mon Sep 17 00:00:00 2001
From: Matthew Curtis <macurtis at amd.com>
Date: Mon, 13 Apr 2026 05:48:01 -0500
Subject: [PATCH 2/3] fixup! [NewPM] Teach llc -passes to handle target machine
 analysis

---
 llvm/include/llvm/Passes/TargetPassRegistry.inc       |  5 +++++
 llvm/test/CodeGen/AMDGPU/new-pm-machine-analysis.mir  | 11 +++++++++++
 .../CodeGen/AMDGPU/new-pm-req-machine-analysis.mir    |  9 ---------
 3 files changed, 16 insertions(+), 9 deletions(-)
 create mode 100644 llvm/test/CodeGen/AMDGPU/new-pm-machine-analysis.mir
 delete mode 100644 llvm/test/CodeGen/AMDGPU/new-pm-req-machine-analysis.mir

diff --git a/llvm/include/llvm/Passes/TargetPassRegistry.inc b/llvm/include/llvm/Passes/TargetPassRegistry.inc
index 4e778e77fa128..de2fefa471529 100644
--- a/llvm/include/llvm/Passes/TargetPassRegistry.inc
+++ b/llvm/include/llvm/Passes/TargetPassRegistry.inc
@@ -93,6 +93,11 @@ if (PIC) {
   }
 
 #define ADD_ANALYSIS_PASS(NAME, CREATE_PASS)                                   \
+  if (Name == "invalidate<" NAME ">") {                                        \
+    PM.addPass(InvalidateAnalysisPass<                                         \
+               std::remove_reference_t<decltype(CREATE_PASS)>>());             \
+    return true;                                                               \
+  }                                                                            \
   if (Name == "require<" NAME ">") {                                           \
     PM.addPass(                                                                \
         RequireAnalysisPass<std::remove_reference_t<decltype(CREATE_PASS)>,    \
diff --git a/llvm/test/CodeGen/AMDGPU/new-pm-machine-analysis.mir b/llvm/test/CodeGen/AMDGPU/new-pm-machine-analysis.mir
new file mode 100644
index 0000000000000..1c96911737717
--- /dev/null
+++ b/llvm/test/CodeGen/AMDGPU/new-pm-machine-analysis.mir
@@ -0,0 +1,11 @@
+# RUN: llc -mtriple=amdgcn \
+# RUN:     "-passes=require<amdgpu-resource-usage>,invalidate<amdgpu-resource-usage>" \
+# RUN:     -filetype=null %s
+---
+name:            test
+body:             |
+  bb.0:
+    S_NOP 0
+...
+
+
diff --git a/llvm/test/CodeGen/AMDGPU/new-pm-req-machine-analysis.mir b/llvm/test/CodeGen/AMDGPU/new-pm-req-machine-analysis.mir
deleted file mode 100644
index ab7d84be8d617..0000000000000
--- a/llvm/test/CodeGen/AMDGPU/new-pm-req-machine-analysis.mir
+++ /dev/null
@@ -1,9 +0,0 @@
-# RUN: llc -mtriple=amdgcn "-passes=require<amdgpu-resource-usage>" -filetype=null %s
----
-name:            test
-body:             |
-  bb.0:
-    S_NOP 0
-...
-
-

>From 545e08d654ecf87cc04b3bbb2f2f4b1f39f113d5 Mon Sep 17 00:00:00 2001
From: Matthew Curtis <macurtis at amd.com>
Date: Mon, 13 Apr 2026 06:47:18 -0500
Subject: [PATCH 3/3] fixup! [NewPM] Teach llc -passes to handle target machine
 analysis

---
 llvm/test/CodeGen/AMDGPU/new-pm-machine-analysis.mir | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)

diff --git a/llvm/test/CodeGen/AMDGPU/new-pm-machine-analysis.mir b/llvm/test/CodeGen/AMDGPU/new-pm-machine-analysis.mir
index 1c96911737717..d11ef50cbdc8f 100644
--- a/llvm/test/CodeGen/AMDGPU/new-pm-machine-analysis.mir
+++ b/llvm/test/CodeGen/AMDGPU/new-pm-machine-analysis.mir
@@ -1,6 +1,8 @@
 # RUN: llc -mtriple=amdgcn \
 # RUN:     "-passes=require<amdgpu-resource-usage>,invalidate<amdgpu-resource-usage>" \
-# RUN:     -filetype=null %s
+# RUN:     --print-pipeline-passes --filetype=null %s | FileCheck %s
+
+# CHECK: machine-function(require<amdgpu-resource-usage>,invalidate<amdgpu-resource-usage>)
 ---
 name:            test
 body:             |



More information about the llvm-commits mailing list