[llvm] 0fbaeaf - [CodeGen][NPM] Allow nested MF pass managers for -passes (#128852)

via llvm-commits llvm-commits at lists.llvm.org
Sun Jul 6 23:40:31 PDT 2025


Author: Akshat Oke
Date: 2025-07-07T12:10:28+05:30
New Revision: 0fbaeafd7ff725d6e7705d934638a7917fc8a3f1

URL: https://github.com/llvm/llvm-project/commit/0fbaeafd7ff725d6e7705d934638a7917fc8a3f1
DIFF: https://github.com/llvm/llvm-project/commit/0fbaeafd7ff725d6e7705d934638a7917fc8a3f1.diff

LOG: [CodeGen][NPM] Allow nested MF pass managers for -passes (#128852)

This allows `machine-function(p1,machine-function(...))` instead of
erroring.

Effectively it is flattened to a single MFPM.

Added: 
    

Modified: 
    llvm/lib/Passes/PassBuilder.cpp
    llvm/test/tools/llc/new-pm/pipeline.mir

Removed: 
    


################################################################################
diff  --git a/llvm/lib/Passes/PassBuilder.cpp b/llvm/lib/Passes/PassBuilder.cpp
index 0697a0a6b4c74..874fce05841e2 100644
--- a/llvm/lib/Passes/PassBuilder.cpp
+++ b/llvm/lib/Passes/PassBuilder.cpp
@@ -2218,9 +2218,18 @@ Error PassBuilder::parseLoopPass(LoopPassManager &LPM,
 Error PassBuilder::parseMachinePass(MachineFunctionPassManager &MFPM,
                                     const PipelineElement &E) {
   StringRef Name = E.Name;
-  if (!E.InnerPipeline.empty())
+  // Handle any nested pass managers.
+  if (!E.InnerPipeline.empty()) {
+    if (E.Name == "machine-function") {
+      MachineFunctionPassManager NestedPM;
+      if (auto Err = parseMachinePassPipeline(NestedPM, E.InnerPipeline))
+        return Err;
+      MFPM.addPass(std::move(NestedPM));
+      return Error::success();
+    }
     return make_error<StringError>("invalid pipeline",
                                    inconvertibleErrorCode());
+  }
 
 #define MACHINE_MODULE_PASS(NAME, CREATE_PASS)                                 \
   if (Name == NAME) {                                                          \

diff  --git a/llvm/test/tools/llc/new-pm/pipeline.mir b/llvm/test/tools/llc/new-pm/pipeline.mir
index 761a3a424ee67..1113f2a26c449 100644
--- a/llvm/test/tools/llc/new-pm/pipeline.mir
+++ b/llvm/test/tools/llc/new-pm/pipeline.mir
@@ -1,10 +1,18 @@
 # RUN: llc -mtriple=x86_64-pc-linux-gnu -x mir -passes=no-op-machine-function --print-pipeline-passes -filetype=null < %s | FileCheck %s --match-full-lines
 # RUN: llc -mtriple=x86_64-pc-linux-gnu -x mir -passes='require<machine-dom-tree>,print<machine-dom-tree>' -print-pipeline-passes < %s | FileCheck --check-prefix=ANALYSIS %s
 
+# Check same nested pass managers
+# RUN: llc -mtriple=x86_64-pc-linux-gnu -x mir \
+# RUN:     -passes='function(machine-function(machine-function(machine-cp)))' \
+# RUN:     -print-pipeline-passes < %s | FileCheck %s --check-prefix=NESTED
+
+# RUN: not llc -mtriple=x86_64-pc-linux-gnu -x mir -passes='machine-function(whoops(verify))' -print-pipeline-passes < %s 2>&1
+
 # CHECK: function(machine-function(no-op-machine-function)),PrintMIRPreparePass,function(machine-function(verify,print))
 
 # ANALYSIS: require<machine-dom-tree>,print<machine-dom-tree>
 
+# NESTED: function(machine-function(machine-cp))
 ---
 name: f
 body: |


        


More information about the llvm-commits mailing list