[llvm] 9afd75f - [NewPM] Port FuncletLayout to the new pass manager (#217490)

via llvm-commits llvm-commits at lists.llvm.org
Wed Aug 19 17:20:40 PDT 2026


Author: Bill Wendling
Date: 2026-08-20T00:20:35Z
New Revision: 9afd75f86d856a53a3925572302513f65129ba26

URL: https://github.com/llvm/llvm-project/commit/9afd75f86d856a53a3925572302513f65129ba26
DIFF: https://github.com/llvm/llvm-project/commit/9afd75f86d856a53a3925572302513f65129ba26.diff

LOG: [NewPM] Port FuncletLayout to the new pass manager (#217490)

Adds a newPM pass for FuncletLayout (funclet-layout).

- Extracts the pass's logic (which has no per-instance state) into a
shared runFuncletLayout free function, called by both the legacy pass
and the new pass manager pass.
- Renames the old pass with the "Legacy" suffix.
- Adds the new pass manager pass FuncletLayoutPass, using
RequiredPassInfoMixin: the legacy pass's runOnMachineFunction never
calls skipFunction, so it always runs unconditionally and should not be
skippable in the new PM either.
- Updates MachinePassRegistry.def, PassBuilder, and CodeGenPassBuilder
-- FuncletLayoutPass was already unconditionally invoked from
CodeGenPassBuilder.h via a DUMMY_MACHINE_FUNCTION_PASS stub, so no
separate enablement change was needed.
- Fixes four pipeline-dump tests (X86, RISC-V x2, Lanai) whose CHECK
lines expected the stub's class-name fallback ("FuncletLayoutPass")
rather than the real pass's registered pipeline name ("funclet-layout").
- Adds a -enable-new-pm RUN line to branchfolding-catchpads.ll, an
existing multi-funclet WinEH test, since no dedicated small unit test
existed to extend the way other newPM ports have done.

Assisted-by: Claude Sonnet 5

Added: 
    llvm/include/llvm/CodeGen/FuncletLayout.h

Modified: 
    llvm/include/llvm/InitializePasses.h
    llvm/include/llvm/Passes/CodeGenPassBuilder.h
    llvm/include/llvm/Passes/MachinePassRegistry.def
    llvm/lib/CodeGen/CodeGen.cpp
    llvm/lib/CodeGen/FuncletLayout.cpp
    llvm/lib/Passes/PassBuilder.cpp
    llvm/test/CodeGen/Lanai/llc-pipeline-npm.ll
    llvm/test/CodeGen/RISCV/O1-newpm-pipeline.ll
    llvm/test/CodeGen/RISCV/O3-newpm-pipeline.ll
    llvm/test/CodeGen/X86/branchfolding-catchpads.ll
    llvm/test/CodeGen/X86/llc-pipeline-npm.ll

Removed: 
    


################################################################################
diff  --git a/llvm/include/llvm/CodeGen/FuncletLayout.h b/llvm/include/llvm/CodeGen/FuncletLayout.h
new file mode 100644
index 0000000000000..6ea8cdabafe8a
--- /dev/null
+++ b/llvm/include/llvm/CodeGen/FuncletLayout.h
@@ -0,0 +1,28 @@
+//===----------------------------------------------------------------------===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===----------------------------------------------------------------------===//
+
+#ifndef LLVM_CODEGEN_FUNCLETLAYOUT_H
+#define LLVM_CODEGEN_FUNCLETLAYOUT_H
+
+#include "llvm/CodeGen/MachinePassManager.h"
+
+namespace llvm {
+
+class FuncletLayoutPass : public RequiredPassInfoMixin<FuncletLayoutPass> {
+public:
+  LLVM_ABI PreservedAnalyses run(MachineFunction &MF,
+                                 MachineFunctionAnalysisManager &MFAM);
+
+  MachineFunctionProperties getRequiredProperties() const {
+    return MachineFunctionProperties().setNoVRegs();
+  }
+};
+
+} // namespace llvm
+
+#endif // LLVM_CODEGEN_FUNCLETLAYOUT_H

diff  --git a/llvm/include/llvm/InitializePasses.h b/llvm/include/llvm/InitializePasses.h
index b5e51e5db037d..29f82acbbca51 100644
--- a/llvm/include/llvm/InitializePasses.h
+++ b/llvm/include/llvm/InitializePasses.h
@@ -122,7 +122,7 @@ LLVM_ABI void initializeFinalizeISelPass(PassRegistry &);
 LLVM_ABI void initializeFixIrreduciblePass(PassRegistry &);
 LLVM_ABI void initializeFixupStatepointCallerSavedLegacyPass(PassRegistry &);
 LLVM_ABI void initializeFlattenCFGLegacyPassPass(PassRegistry &);
-LLVM_ABI void initializeFuncletLayoutPass(PassRegistry &);
+LLVM_ABI void initializeFuncletLayoutLegacyPass(PassRegistry &);
 LLVM_ABI void initializeGCEmptyBasicBlocksLegacyPass(PassRegistry &);
 LLVM_ABI void initializeGCMachineCodeAnalysisPass(PassRegistry &);
 LLVM_ABI void initializeGCModuleInfoPass(PassRegistry &);

diff  --git a/llvm/include/llvm/Passes/CodeGenPassBuilder.h b/llvm/include/llvm/Passes/CodeGenPassBuilder.h
index 55ee1c755e4e4..129b4485b727b 100644
--- a/llvm/include/llvm/Passes/CodeGenPassBuilder.h
+++ b/llvm/include/llvm/Passes/CodeGenPassBuilder.h
@@ -36,6 +36,7 @@
 #include "llvm/CodeGen/FEntryInserter.h"
 #include "llvm/CodeGen/FinalizeISel.h"
 #include "llvm/CodeGen/FixupStatepointCallerSaved.h"
+#include "llvm/CodeGen/FuncletLayout.h"
 #include "llvm/CodeGen/GCEmptyBasicBlocks.h"
 #include "llvm/CodeGen/GCMetadata.h"
 #include "llvm/CodeGen/GlobalMerge.h"

diff  --git a/llvm/include/llvm/Passes/MachinePassRegistry.def b/llvm/include/llvm/Passes/MachinePassRegistry.def
index 2629280a5d6ac..a6addb7547073 100644
--- a/llvm/include/llvm/Passes/MachinePassRegistry.def
+++ b/llvm/include/llvm/Passes/MachinePassRegistry.def
@@ -79,6 +79,7 @@ MACHINE_FUNCTION_PASS("fentry-insert", FEntryInserterPass())
 MACHINE_FUNCTION_PASS("finalize-isel", FinalizeISelPass())
 MACHINE_FUNCTION_PASS("finalizebundle-test", FinalizeBundleTestPass())
 MACHINE_FUNCTION_PASS("fixup-statepoint-caller-saved", FixupStatepointCallerSavedPass())
+MACHINE_FUNCTION_PASS("funclet-layout", FuncletLayoutPass())
 MACHINE_FUNCTION_PASS("init-undef", InitUndefPass())
 MACHINE_FUNCTION_PASS("implicit-null-checks", ImplicitNullChecksPass())
 MACHINE_FUNCTION_PASS("ir-translator", IRTranslatorPass(TM->getOptLevel()))
@@ -245,7 +246,6 @@ DUMMY_MACHINE_FUNCTION_PASS("cfguard-longjmp", CFGuardLongjmpPass)
 DUMMY_MACHINE_FUNCTION_PASS("cfi-instr-inserter", CFIInstrInserterPass)
 DUMMY_MACHINE_FUNCTION_PASS("eh-cont-guard-targets", EHContGuardTargetsPass)
 DUMMY_MACHINE_FUNCTION_PASS("fs-profile-loader", MIRProfileLoaderNewPass)
-DUMMY_MACHINE_FUNCTION_PASS("funclet-layout", FuncletLayoutPass)
 DUMMY_MACHINE_FUNCTION_PASS("instruction-select", InstructionSelectPass)
 DUMMY_MACHINE_FUNCTION_PASS("lrshrink", LiveRangeShrinkPass)
 DUMMY_MACHINE_FUNCTION_PASS("machine-function-splitter", MachineFunctionSplitterPass)

diff  --git a/llvm/lib/CodeGen/CodeGen.cpp b/llvm/lib/CodeGen/CodeGen.cpp
index 161ccf3b92b4b..a42528d8bff64 100644
--- a/llvm/lib/CodeGen/CodeGen.cpp
+++ b/llvm/lib/CodeGen/CodeGen.cpp
@@ -49,7 +49,7 @@ void llvm::initializeCodeGen(PassRegistry &Registry) {
   initializeFEntryInserterLegacyPass(Registry);
   initializeFinalizeISelPass(Registry);
   initializeFixupStatepointCallerSavedLegacyPass(Registry);
-  initializeFuncletLayoutPass(Registry);
+  initializeFuncletLayoutLegacyPass(Registry);
   initializeGCEmptyBasicBlocksLegacyPass(Registry);
   initializeGCMachineCodeAnalysisPass(Registry);
   initializeGCModuleInfoPass(Registry);

diff  --git a/llvm/lib/CodeGen/FuncletLayout.cpp b/llvm/lib/CodeGen/FuncletLayout.cpp
index 75839c2511adf..bd2bbb4924444 100644
--- a/llvm/lib/CodeGen/FuncletLayout.cpp
+++ b/llvm/lib/CodeGen/FuncletLayout.cpp
@@ -10,6 +10,7 @@
 // funclets being contiguous.
 //
 //===----------------------------------------------------------------------===//
+#include "llvm/CodeGen/FuncletLayout.h"
 #include "llvm/CodeGen/Analysis.h"
 #include "llvm/CodeGen/MachineFunction.h"
 #include "llvm/CodeGen/MachineFunctionPass.h"
@@ -19,25 +20,7 @@ using namespace llvm;
 
 #define DEBUG_TYPE "funclet-layout"
 
-namespace {
-class FuncletLayout : public MachineFunctionPass {
-public:
-  static char ID; // Pass identification, replacement for typeid
-  FuncletLayout() : MachineFunctionPass(ID) {}
-
-  bool runOnMachineFunction(MachineFunction &F) override;
-  MachineFunctionProperties getRequiredProperties() const override {
-    return MachineFunctionProperties().setNoVRegs();
-  }
-};
-}
-
-char FuncletLayout::ID = 0;
-char &llvm::FuncletLayoutID = FuncletLayout::ID;
-INITIALIZE_PASS(FuncletLayout, DEBUG_TYPE,
-                "Contiguously Lay Out Funclets", false, false)
-
-bool FuncletLayout::runOnMachineFunction(MachineFunction &F) {
+static bool runFuncletLayout(MachineFunction &F) {
   // Even though this gets information from getEHScopeMembership(), this pass is
   // only necessary for funclet-based EH personalities, in which these EH scopes
   // are outlined at the end.
@@ -57,3 +40,32 @@ bool FuncletLayout::runOnMachineFunction(MachineFunction &F) {
   // Conservatively assume we changed something.
   return true;
 }
+
+namespace {
+class FuncletLayoutLegacy : public MachineFunctionPass {
+public:
+  static char ID; // Pass identification, replacement for typeid
+  FuncletLayoutLegacy() : MachineFunctionPass(ID) {}
+
+  bool runOnMachineFunction(MachineFunction &F) override {
+    return runFuncletLayout(F);
+  }
+  MachineFunctionProperties getRequiredProperties() const override {
+    return MachineFunctionProperties().setNoVRegs();
+  }
+};
+} // namespace
+
+char FuncletLayoutLegacy::ID = 0;
+char &llvm::FuncletLayoutID = FuncletLayoutLegacy::ID;
+INITIALIZE_PASS(FuncletLayoutLegacy, DEBUG_TYPE,
+                "Contiguously Lay Out Funclets", false, false)
+
+PreservedAnalyses FuncletLayoutPass::run(MachineFunction &MF,
+                                         MachineFunctionAnalysisManager &MFAM) {
+  MFPropsModifier _(*this, MF);
+  if (!runFuncletLayout(MF))
+    return PreservedAnalyses::all();
+
+  return getMachineFunctionPassPreservedAnalyses();
+}

diff  --git a/llvm/lib/Passes/PassBuilder.cpp b/llvm/lib/Passes/PassBuilder.cpp
index e886bf909c833..ccda9a3705db8 100644
--- a/llvm/lib/Passes/PassBuilder.cpp
+++ b/llvm/lib/Passes/PassBuilder.cpp
@@ -101,6 +101,7 @@
 #include "llvm/CodeGen/FEntryInserter.h"
 #include "llvm/CodeGen/FinalizeISel.h"
 #include "llvm/CodeGen/FixupStatepointCallerSaved.h"
+#include "llvm/CodeGen/FuncletLayout.h"
 #include "llvm/CodeGen/GCEmptyBasicBlocks.h"
 #include "llvm/CodeGen/GCMetadata.h"
 #include "llvm/CodeGen/GlobalISel/CSEInfo.h"

diff  --git a/llvm/test/CodeGen/Lanai/llc-pipeline-npm.ll b/llvm/test/CodeGen/Lanai/llc-pipeline-npm.ll
index 965f23399114c..6e641e5e76569 100644
--- a/llvm/test/CodeGen/Lanai/llc-pipeline-npm.ll
+++ b/llvm/test/CodeGen/Lanai/llc-pipeline-npm.ll
@@ -80,7 +80,7 @@
 ; CHECK:     xray-instrumentation
 ; CHECK:     patchable-function
 ; CHECK:     lanai-delay-slot-fillter
-; CHECK:     FuncletLayoutPass
+; CHECK:     funclet-layout
 ; CHECK:     remove-loads-into-fake-uses
 ; CHECK:     StackMapLivenessPass
 ; CHECK:     live-debug-values

diff  --git a/llvm/test/CodeGen/RISCV/O1-newpm-pipeline.ll b/llvm/test/CodeGen/RISCV/O1-newpm-pipeline.ll
index 57fc4ce5bd9c5..3ee448b9bf0e4 100644
--- a/llvm/test/CodeGen/RISCV/O1-newpm-pipeline.ll
+++ b/llvm/test/CodeGen/RISCV/O1-newpm-pipeline.ll
@@ -89,7 +89,7 @@
 ; CHECK-NEXT:     xray-instrumentation
 ; CHECK-NEXT:     patchable-function
 ; CHECK-NEXT:     branch-relaxation
-; CHECK-NEXT:     FuncletLayoutPass
+; CHECK-NEXT:     funclet-layout
 ; CHECK-NEXT:     remove-loads-into-fake-uses
 ; CHECK-NEXT:     StackMapLivenessPass
 ; CHECK-NEXT:     live-debug-values<emit-debug-entry-values>

diff  --git a/llvm/test/CodeGen/RISCV/O3-newpm-pipeline.ll b/llvm/test/CodeGen/RISCV/O3-newpm-pipeline.ll
index 6f6edc02ea7bd..df66649031b4f 100644
--- a/llvm/test/CodeGen/RISCV/O3-newpm-pipeline.ll
+++ b/llvm/test/CodeGen/RISCV/O3-newpm-pipeline.ll
@@ -90,7 +90,7 @@
 ; CHECK-NEXT:     patchable-function
 ; CHECK-NEXT:     machine-cp
 ; CHECK-NEXT:     branch-relaxation
-; CHECK-NEXT:     FuncletLayoutPass
+; CHECK-NEXT:     funclet-layout
 ; CHECK-NEXT:     remove-loads-into-fake-uses
 ; CHECK-NEXT:     StackMapLivenessPass
 ; CHECK-NEXT:     live-debug-values<emit-debug-entry-values>

diff  --git a/llvm/test/CodeGen/X86/branchfolding-catchpads.ll b/llvm/test/CodeGen/X86/branchfolding-catchpads.ll
index 3059a702b6a49..ca6f7fdd0c2ce 100644
--- a/llvm/test/CodeGen/X86/branchfolding-catchpads.ll
+++ b/llvm/test/CodeGen/X86/branchfolding-catchpads.ll
@@ -1,4 +1,5 @@
 ; RUN: llc -mtriple=x86_64-pc-windows-msvc < %s | FileCheck %s
+; RUN: llc -enable-new-pm -mtriple=x86_64-pc-windows-msvc < %s | FileCheck %s
 
 declare i32 @__CxxFrameHandler3(...)
 

diff  --git a/llvm/test/CodeGen/X86/llc-pipeline-npm.ll b/llvm/test/CodeGen/X86/llc-pipeline-npm.ll
index 9b96d201d8676..4cee66ec41f89 100644
--- a/llvm/test/CodeGen/X86/llc-pipeline-npm.ll
+++ b/llvm/test/CodeGen/X86/llc-pipeline-npm.ll
@@ -66,7 +66,7 @@
 ; O0-NEXT:     x86-insert-vzeroupper
 ; O0-NEXT:     x86-compress-evex
 ; O0-NEXT:     x86-insert-x87-wait
-; O0-NEXT:     FuncletLayoutPass
+; O0-NEXT:     funclet-layout
 ; O0-NEXT:     remove-loads-into-fake-uses
 ; O0-NEXT:     StackMapLivenessPass
 ; O0-NEXT:     live-debug-values<emit-debug-entry-values>
@@ -192,7 +192,7 @@
 ; O2-NEXT:     x86-fixup-inst-tuning
 ; O2-NEXT:     x86-compress-evex
 ; O2-NEXT:     x86-insert-x87-wait
-; O2-NEXT:     FuncletLayoutPass
+; O2-NEXT:     funclet-layout
 ; O2-NEXT:     remove-loads-into-fake-uses
 ; O2-NEXT:     StackMapLivenessPass
 ; O2-NEXT:     live-debug-values<emit-debug-entry-values>
@@ -264,7 +264,7 @@
 ; O0-WINDOWS-NEXT:     x86-insert-vzeroupper
 ; O0-WINDOWS-NEXT:     x86-compress-evex
 ; O0-WINDOWS-NEXT:     x86-insert-x87-wait
-; O0-WINDOWS-NEXT:     FuncletLayoutPass
+; O0-WINDOWS-NEXT:     funclet-layout
 ; O0-WINDOWS-NEXT:     remove-loads-into-fake-uses
 ; O0-WINDOWS-NEXT:     StackMapLivenessPass
 ; O0-WINDOWS-NEXT:     live-debug-values<emit-debug-entry-values>
@@ -393,7 +393,7 @@
 ; O3-WINDOWS-NEXT:     x86-fixup-inst-tuning
 ; O3-WINDOWS-NEXT:     x86-compress-evex
 ; O3-WINDOWS-NEXT:     x86-insert-x87-wait
-; O3-WINDOWS-NEXT:     FuncletLayoutPass
+; O3-WINDOWS-NEXT:     funclet-layout
 ; O3-WINDOWS-NEXT:     remove-loads-into-fake-uses
 ; O3-WINDOWS-NEXT:     StackMapLivenessPass
 ; O3-WINDOWS-NEXT:     live-debug-values<emit-debug-entry-values>


        


More information about the llvm-commits mailing list