Skip to content

Commit 0fbaeaf

Browse files
authored
[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.
1 parent 7f90a5c commit 0fbaeaf

File tree

2 files changed

+18
-1
lines changed

2 files changed

+18
-1
lines changed

llvm/lib/Passes/PassBuilder.cpp

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2218,9 +2218,18 @@ Error PassBuilder::parseLoopPass(LoopPassManager &LPM,
22182218
Error PassBuilder::parseMachinePass(MachineFunctionPassManager &MFPM,
22192219
const PipelineElement &E) {
22202220
StringRef Name = E.Name;
2221-
if (!E.InnerPipeline.empty())
2221+
// Handle any nested pass managers.
2222+
if (!E.InnerPipeline.empty()) {
2223+
if (E.Name == "machine-function") {
2224+
MachineFunctionPassManager NestedPM;
2225+
if (auto Err = parseMachinePassPipeline(NestedPM, E.InnerPipeline))
2226+
return Err;
2227+
MFPM.addPass(std::move(NestedPM));
2228+
return Error::success();
2229+
}
22222230
return make_error<StringError>("invalid pipeline",
22232231
inconvertibleErrorCode());
2232+
}
22242233

22252234
#define MACHINE_MODULE_PASS(NAME, CREATE_PASS) \
22262235
if (Name == NAME) { \

llvm/test/tools/llc/new-pm/pipeline.mir

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,18 @@
11
# 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
22
# 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
33

4+
# Check same nested pass managers
5+
# RUN: llc -mtriple=x86_64-pc-linux-gnu -x mir \
6+
# RUN: -passes='function(machine-function(machine-function(machine-cp)))' \
7+
# RUN: -print-pipeline-passes < %s | FileCheck %s --check-prefix=NESTED
8+
9+
# RUN: not llc -mtriple=x86_64-pc-linux-gnu -x mir -passes='machine-function(whoops(verify))' -print-pipeline-passes < %s 2>&1
10+
411
# CHECK: function(machine-function(no-op-machine-function)),PrintMIRPreparePass,function(machine-function(verify,print))
512

613
# ANALYSIS: require<machine-dom-tree>,print<machine-dom-tree>
714

15+
# NESTED: function(machine-function(machine-cp))
816
---
917
name: f
1018
body: |

0 commit comments

Comments
 (0)