Skip to content

[CodeGen][NewPM] Port "FixupStatepointCallerSaved" pass to NPM #129541

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Mar 4, 2025

Conversation

vikramRH
Copy link
Contributor

@vikramRH vikramRH commented Mar 3, 2025

No description provided.

@llvmbot
Copy link
Member

llvmbot commented Mar 3, 2025

@llvm/pr-subscribers-backend-x86

Author: Vikram Hegde (vikramRH)

Changes

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

14 Files Affected:

  • (added) llvm/include/llvm/CodeGen/FixupStatepointCallerSaved.h (+25)
  • (modified) llvm/include/llvm/InitializePasses.h (+1-1)
  • (modified) llvm/include/llvm/Passes/CodeGenPassBuilder.h (+1)
  • (modified) llvm/include/llvm/Passes/MachinePassRegistry.def (+1-1)
  • (modified) llvm/lib/CodeGen/CodeGen.cpp (+1-1)
  • (modified) llvm/lib/CodeGen/FixupStatepointCallerSaved.cpp (+34-12)
  • (modified) llvm/lib/Passes/PassBuilder.cpp (+1)
  • (modified) llvm/test/CodeGen/X86/statepoint-fixup-call.mir (+1)
  • (modified) llvm/test/CodeGen/X86/statepoint-fixup-copy-prop-neg.mir (+1)
  • (modified) llvm/test/CodeGen/X86/statepoint-fixup-copy-prop.mir (+1)
  • (modified) llvm/test/CodeGen/X86/statepoint-fixup-invoke.mir (+1)
  • (modified) llvm/test/CodeGen/X86/statepoint-fixup-shared-ehpad.mir (+1)
  • (modified) llvm/test/CodeGen/X86/statepoint-fixup-undef-def.mir (+1)
  • (modified) llvm/test/CodeGen/X86/statepoint-fixup-undef.mir (+1)
diff --git a/llvm/include/llvm/CodeGen/FixupStatepointCallerSaved.h b/llvm/include/llvm/CodeGen/FixupStatepointCallerSaved.h
new file mode 100644
index 0000000000000..43c40340032ce
--- /dev/null
+++ b/llvm/include/llvm/CodeGen/FixupStatepointCallerSaved.h
@@ -0,0 +1,25 @@
+//===- llvm/CodeGen/FixupStatepointCallerSaved.h ----------------*- C++ -*-===//
+//
+// 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_FIXUPSTATEPOINTCALLERSAVED_H
+#define LLVM_CODEGEN_FIXUPSTATEPOINTCALLERSAVED_H
+
+#include "llvm/CodeGen/MachinePassManager.h"
+
+namespace llvm {
+
+class FixupStatepointCallerSavedPass
+    : public PassInfoMixin<FixupStatepointCallerSavedPass> {
+public:
+  PreservedAnalyses run(MachineFunction &MF,
+                        MachineFunctionAnalysisManager &MFAM);
+};
+
+} // namespace llvm
+
+#endif // LLVM_CODEGEN_FIXUPSTATEPOINTCALLERSAVED_H
diff --git a/llvm/include/llvm/InitializePasses.h b/llvm/include/llvm/InitializePasses.h
index 0dfb46a210c7e..510ec3da5e515 100644
--- a/llvm/include/llvm/InitializePasses.h
+++ b/llvm/include/llvm/InitializePasses.h
@@ -116,7 +116,7 @@ void initializeFEntryInserterPass(PassRegistry &);
 void initializeFinalizeISelPass(PassRegistry &);
 void initializeFinalizeMachineBundlesPass(PassRegistry &);
 void initializeFixIrreduciblePass(PassRegistry &);
-void initializeFixupStatepointCallerSavedPass(PassRegistry &);
+void initializeFixupStatepointCallerSavedLegacyPass(PassRegistry &);
 void initializeFlattenCFGLegacyPassPass(PassRegistry &);
 void initializeFuncletLayoutPass(PassRegistry &);
 void initializeGCEmptyBasicBlocksPass(PassRegistry &);
diff --git a/llvm/include/llvm/Passes/CodeGenPassBuilder.h b/llvm/include/llvm/Passes/CodeGenPassBuilder.h
index 30f0742fd2c26..3011409dc58b1 100644
--- a/llvm/include/llvm/Passes/CodeGenPassBuilder.h
+++ b/llvm/include/llvm/Passes/CodeGenPassBuilder.h
@@ -33,6 +33,7 @@
 #include "llvm/CodeGen/ExpandMemCmp.h"
 #include "llvm/CodeGen/ExpandReductions.h"
 #include "llvm/CodeGen/FinalizeISel.h"
+#include "llvm/CodeGen/FixupStatepointCallerSaved.h"
 #include "llvm/CodeGen/GCMetadata.h"
 #include "llvm/CodeGen/GlobalMerge.h"
 #include "llvm/CodeGen/GlobalMergeFunctions.h"
diff --git a/llvm/include/llvm/Passes/MachinePassRegistry.def b/llvm/include/llvm/Passes/MachinePassRegistry.def
index 67eab42b014c9..53a246f6f6a94 100644
--- a/llvm/include/llvm/Passes/MachinePassRegistry.def
+++ b/llvm/include/llvm/Passes/MachinePassRegistry.def
@@ -141,6 +141,7 @@ MACHINE_FUNCTION_PASS("early-ifcvt", EarlyIfConverterPass())
 MACHINE_FUNCTION_PASS("early-machinelicm", EarlyMachineLICMPass())
 MACHINE_FUNCTION_PASS("early-tailduplication", EarlyTailDuplicatePass())
 MACHINE_FUNCTION_PASS("finalize-isel", FinalizeISelPass())
+MACHINE_FUNCTION_PASS("fixup-statepoint-caller-saved", FixupStatepointCallerSavedPass())
 MACHINE_FUNCTION_PASS("localstackalloc", LocalStackSlotAllocationPass())
 MACHINE_FUNCTION_PASS("machine-cp", MachineCopyPropagationPass())
 MACHINE_FUNCTION_PASS("machine-cse", MachineCSEPass())
@@ -231,7 +232,6 @@ DUMMY_MACHINE_FUNCTION_PASS("cfi-instr-inserter", CFIInstrInserterPass)
 DUMMY_MACHINE_FUNCTION_PASS("detect-dead-lanes", DetectDeadLanesPass)
 DUMMY_MACHINE_FUNCTION_PASS("dot-machine-cfg", MachineCFGPrinter)
 DUMMY_MACHINE_FUNCTION_PASS("fentry-insert", FEntryInserterPass)
-DUMMY_MACHINE_FUNCTION_PASS("fixup-statepoint-caller-saved", FixupStatepointCallerSavedPass)
 DUMMY_MACHINE_FUNCTION_PASS("fs-profile-loader", MIRProfileLoaderNewPass)
 DUMMY_MACHINE_FUNCTION_PASS("funclet-layout", FuncletLayoutPass)
 DUMMY_MACHINE_FUNCTION_PASS("gc-empty-basic-blocks", GCEmptyBasicBlocksPass)
diff --git a/llvm/lib/CodeGen/CodeGen.cpp b/llvm/lib/CodeGen/CodeGen.cpp
index 046a3ee42dd6b..335c0cf6da426 100644
--- a/llvm/lib/CodeGen/CodeGen.cpp
+++ b/llvm/lib/CodeGen/CodeGen.cpp
@@ -46,7 +46,7 @@ void llvm::initializeCodeGen(PassRegistry &Registry) {
   initializeFEntryInserterPass(Registry);
   initializeFinalizeISelPass(Registry);
   initializeFinalizeMachineBundlesPass(Registry);
-  initializeFixupStatepointCallerSavedPass(Registry);
+  initializeFixupStatepointCallerSavedLegacyPass(Registry);
   initializeFuncletLayoutPass(Registry);
   initializeGCMachineCodeAnalysisPass(Registry);
   initializeGCModuleInfoPass(Registry);
diff --git a/llvm/lib/CodeGen/FixupStatepointCallerSaved.cpp b/llvm/lib/CodeGen/FixupStatepointCallerSaved.cpp
index 0d6ec8975689b..ae805a683aac0 100644
--- a/llvm/lib/CodeGen/FixupStatepointCallerSaved.cpp
+++ b/llvm/lib/CodeGen/FixupStatepointCallerSaved.cpp
@@ -20,6 +20,7 @@
 ///
 //===----------------------------------------------------------------------===//
 
+#include "llvm/CodeGen/FixupStatepointCallerSaved.h"
 #include "llvm/ADT/SmallSet.h"
 #include "llvm/ADT/Statistic.h"
 #include "llvm/CodeGen/MachineFrameInfo.h"
@@ -58,14 +59,18 @@ static cl::opt<unsigned> MaxStatepointsWithRegs(
 
 namespace {
 
-class FixupStatepointCallerSaved : public MachineFunctionPass {
+struct FixupStatepointCallerSavedImpl {
+  bool run(MachineFunction &MF);
+};
+
+class FixupStatepointCallerSavedLegacy : public MachineFunctionPass {
 public:
   static char ID;
 
-  FixupStatepointCallerSaved() : MachineFunctionPass(ID) {
-    initializeFixupStatepointCallerSavedPass(*PassRegistry::getPassRegistry());
+  FixupStatepointCallerSavedLegacy() : MachineFunctionPass(ID) {
+    initializeFixupStatepointCallerSavedLegacyPass(
+        *PassRegistry::getPassRegistry());
   }
-
   void getAnalysisUsage(AnalysisUsage &AU) const override {
     AU.setPreservesCFG();
     MachineFunctionPass::getAnalysisUsage(AU);
@@ -80,12 +85,12 @@ class FixupStatepointCallerSaved : public MachineFunctionPass {
 
 } // End anonymous namespace.
 
-char FixupStatepointCallerSaved::ID = 0;
-char &llvm::FixupStatepointCallerSavedID = FixupStatepointCallerSaved::ID;
+char FixupStatepointCallerSavedLegacy::ID = 0;
+char &llvm::FixupStatepointCallerSavedID = FixupStatepointCallerSavedLegacy::ID;
 
-INITIALIZE_PASS_BEGIN(FixupStatepointCallerSaved, DEBUG_TYPE,
+INITIALIZE_PASS_BEGIN(FixupStatepointCallerSavedLegacy, DEBUG_TYPE,
                       "Fixup Statepoint Caller Saved", false, false)
-INITIALIZE_PASS_END(FixupStatepointCallerSaved, DEBUG_TYPE,
+INITIALIZE_PASS_END(FixupStatepointCallerSavedLegacy, DEBUG_TYPE,
                     "Fixup Statepoint Caller Saved", false, false)
 
 // Utility function to get size of the register.
@@ -588,10 +593,7 @@ class StatepointProcessor {
 };
 } // namespace
 
-bool FixupStatepointCallerSaved::runOnMachineFunction(MachineFunction &MF) {
-  if (skipFunction(MF.getFunction()))
-    return false;
-
+bool FixupStatepointCallerSavedImpl::run(MachineFunction &MF) {
   const Function &F = MF.getFunction();
   if (!F.hasGC())
     return false;
@@ -618,3 +620,23 @@ bool FixupStatepointCallerSaved::runOnMachineFunction(MachineFunction &MF) {
   }
   return Changed;
 }
+
+bool FixupStatepointCallerSavedLegacy::runOnMachineFunction(
+    MachineFunction &MF) {
+  if (skipFunction(MF.getFunction()))
+    return false;
+
+  return FixupStatepointCallerSavedImpl().run(MF);
+}
+
+PreservedAnalyses
+FixupStatepointCallerSavedPass::run(MachineFunction &MF,
+                                    MachineFunctionAnalysisManager &MFAM) {
+
+  if (!FixupStatepointCallerSavedImpl().run(MF))
+    return PreservedAnalyses::all();
+
+  auto PA = getMachineFunctionPassPreservedAnalyses();
+  PA.preserveSet<CFGAnalyses>();
+  return PA;
+}
diff --git a/llvm/lib/Passes/PassBuilder.cpp b/llvm/lib/Passes/PassBuilder.cpp
index c9825dfc89d3d..4b36226b73989 100644
--- a/llvm/lib/Passes/PassBuilder.cpp
+++ b/llvm/lib/Passes/PassBuilder.cpp
@@ -91,6 +91,7 @@
 #include "llvm/CodeGen/ExpandLargeFpConvert.h"
 #include "llvm/CodeGen/ExpandMemCmp.h"
 #include "llvm/CodeGen/FinalizeISel.h"
+#include "llvm/CodeGen/FixupStatepointCallerSaved.h"
 #include "llvm/CodeGen/GCMetadata.h"
 #include "llvm/CodeGen/GlobalMerge.h"
 #include "llvm/CodeGen/GlobalMergeFunctions.h"
diff --git a/llvm/test/CodeGen/X86/statepoint-fixup-call.mir b/llvm/test/CodeGen/X86/statepoint-fixup-call.mir
index 6ab95c2ebd0c9..32a6825d54842 100644
--- a/llvm/test/CodeGen/X86/statepoint-fixup-call.mir
+++ b/llvm/test/CodeGen/X86/statepoint-fixup-call.mir
@@ -1,5 +1,6 @@
 # NOTE: Assertions have been autogenerated by utils/update_mir_test_checks.py
 # RUN: llc -o - %s -fixup-allow-gcptr-in-csr=false -run-pass fixup-statepoint-caller-saved | FileCheck %s
+# RUN: llc -o - %s -fixup-allow-gcptr-in-csr=false -passes="fixup-statepoint-caller-saved" | FileCheck %s
 --- |
   ; ModuleID = 'test/CodeGen/X86/statepoint-fixup-call.ll'
   source_filename = "test/CodeGen/X86/statepoint-fixup-call.ll"
diff --git a/llvm/test/CodeGen/X86/statepoint-fixup-copy-prop-neg.mir b/llvm/test/CodeGen/X86/statepoint-fixup-copy-prop-neg.mir
index c87b287241518..92b335baf5f7a 100644
--- a/llvm/test/CodeGen/X86/statepoint-fixup-copy-prop-neg.mir
+++ b/llvm/test/CodeGen/X86/statepoint-fixup-copy-prop-neg.mir
@@ -1,5 +1,6 @@
 # NOTE: Assertions have been autogenerated by utils/update_mir_test_checks.py
 # RUN: llc -o - %s -run-pass fixup-statepoint-caller-saved -verify-machineinstrs | FileCheck %s
+# RUN: llc -o - %s -passes="fixup-statepoint-caller-saved" | FileCheck %s
 
 # Check that COPY is not eliminated if dest register is used in
 # non-meta arguments of statepoint.
diff --git a/llvm/test/CodeGen/X86/statepoint-fixup-copy-prop.mir b/llvm/test/CodeGen/X86/statepoint-fixup-copy-prop.mir
index 6b3d3db98b9f3..ae6c763f958b6 100644
--- a/llvm/test/CodeGen/X86/statepoint-fixup-copy-prop.mir
+++ b/llvm/test/CodeGen/X86/statepoint-fixup-copy-prop.mir
@@ -1,4 +1,5 @@
 # RUN: llc -o - %s -run-pass fixup-statepoint-caller-saved -verify-machineinstrs | FileCheck %s
+# RUN: llc -o - %s -passes="fixup-statepoint-caller-saved" | FileCheck %s
 
 --- |
   target datalayout = "e-m:e-p270:32:32-p271:32:32-p272:64:64-i64:64-f80:128-n8:16:32:64-S128"
diff --git a/llvm/test/CodeGen/X86/statepoint-fixup-invoke.mir b/llvm/test/CodeGen/X86/statepoint-fixup-invoke.mir
index f29dbfaf0622a..de0396c311c05 100644
--- a/llvm/test/CodeGen/X86/statepoint-fixup-invoke.mir
+++ b/llvm/test/CodeGen/X86/statepoint-fixup-invoke.mir
@@ -1,5 +1,6 @@
 # NOTE: Assertions have been autogenerated by utils/update_mir_test_checks.py
 # RUN: llc -o - %s -fixup-allow-gcptr-in-csr=false -run-pass fixup-statepoint-caller-saved | FileCheck %s
+# RUN: llc -o - %s -fixup-allow-gcptr-in-csr=false -passes="fixup-statepoint-caller-saved" | FileCheck %s
 
 --- |
   ; ModuleID = 'test/CodeGen/X86/statepoint-fixup-invoke.mir'
diff --git a/llvm/test/CodeGen/X86/statepoint-fixup-shared-ehpad.mir b/llvm/test/CodeGen/X86/statepoint-fixup-shared-ehpad.mir
index d16c3d93cfc20..369acf7bddfe3 100644
--- a/llvm/test/CodeGen/X86/statepoint-fixup-shared-ehpad.mir
+++ b/llvm/test/CodeGen/X86/statepoint-fixup-shared-ehpad.mir
@@ -1,5 +1,6 @@
 # NOTE: Assertions have been autogenerated by utils/update_mir_test_checks.py
 # RUN: llc -o - %s -fixup-allow-gcptr-in-csr=false -run-pass fixup-statepoint-caller-saved | FileCheck %s
+# RUN: llc -o - %s -fixup-allow-gcptr-in-csr=false -passes="fixup-statepoint-caller-saved" | FileCheck %s
 
 # NOTE: MIR in this test was hand edited to have two statepoints share single landing pad.
 # This is forbidden in IR, but is allowed in MIR. I just was unable to reproduce conditions
diff --git a/llvm/test/CodeGen/X86/statepoint-fixup-undef-def.mir b/llvm/test/CodeGen/X86/statepoint-fixup-undef-def.mir
index 7c48625e99353..c7313f99bb201 100644
--- a/llvm/test/CodeGen/X86/statepoint-fixup-undef-def.mir
+++ b/llvm/test/CodeGen/X86/statepoint-fixup-undef-def.mir
@@ -1,5 +1,6 @@
 # NOTE: Assertions have been autogenerated by utils/update_mir_test_checks.py
 # RUN: llc -x mir -run-pass fixup-statepoint-caller-saved -verify-machineinstrs < %s | FileCheck %s
+# RUN: llc -x mir -passes="fixup-statepoint-caller-saved" < %s | FileCheck %s
 
 --- |
   ; ModuleID = 'undef.ll'
diff --git a/llvm/test/CodeGen/X86/statepoint-fixup-undef.mir b/llvm/test/CodeGen/X86/statepoint-fixup-undef.mir
index edb0d517d5d52..d68c52bb98f51 100644
--- a/llvm/test/CodeGen/X86/statepoint-fixup-undef.mir
+++ b/llvm/test/CodeGen/X86/statepoint-fixup-undef.mir
@@ -1,5 +1,6 @@
 # NOTE: Assertions have been autogenerated by utils/update_mir_test_checks.py
 # RUN: llc -x mir -run-pass fixup-statepoint-caller-saved -verify-machineinstrs < %s | FileCheck %s
+# RUN: llc -x mir -passes="fixup-statepoint-caller-saved" < %s | FileCheck %s
 # RUN: llc -x mir -start-before fixup-statepoint-caller-saved -verify-machineinstrs < %s | FileCheck %s -check-prefix=STACKMAP
 
 --- |

@vikramRH vikramRH merged commit e0eb4ed into llvm:main Mar 4, 2025
11 checks passed
jph-13 pushed a commit to jph-13/llvm-project that referenced this pull request Mar 21, 2025
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.

4 participants