Skip to content

[NewPM] Teach llc -passes to handle target machine analysis - #191704

Merged
macurtis-amd merged 3 commits into
llvm:mainfrom
macurtis-amd:parse-tgt-analysis-require
Apr 15, 2026
Merged

macurtis-amd merged 3 commits into
llvm:mainfrom
macurtis-amd:parse-tgt-analysis-require

Conversation

@macurtis-amd

Copy link
Copy Markdown
Contributor

No description provided.

@llvmbot

llvmbot commented Apr 12, 2026

Copy link
Copy Markdown
Member

@llvm/pr-subscribers-backend-amdgpu

Author: macurtis-amd

Changes

Full diff: https://github.com/llvm/llvm-project/pull/191704.diff

2 Files Affected:

  • (modified) llvm/include/llvm/Passes/TargetPassRegistry.inc (+18)
  • (added) llvm/test/CodeGen/AMDGPU/new-pm-req-machine-analysis.mir (+9)
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
+...
+
+

@paperchalice paperchalice left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Could you also add invalidate<pass-name> support? Thanks!

#undef MACHINE_FUNCTION_ANALYSIS
return false;
});

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

This is implementation is for machine function analysis only, target like DirectX has some IR analyses, so it is worth to support other IR kinds.
Maybe we could introduce something like <IRUnit>PassManager::IRUnitT to simplifiy it, but this is out of scope for this pr.

Comment thread llvm/test/CodeGen/AMDGPU/new-pm-machine-analysis.mir
@kmitropoulou

Copy link
Copy Markdown
Contributor

LGTM

@macurtis-amd
macurtis-amd merged commit 0563360 into llvm:main Apr 15, 2026
10 checks passed
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.

5 participants