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 { +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..2841df2707a76 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" @@ -935,6 +936,7 @@ Error CodeGenPassBuilder::addMachinePasses( derived().addPostRegAlloc(addPass); addPass(RemoveRedundantDebugValuesPass()); + addPass(FixupStatepointCallerSavedPass()); // Insert prolog/epilog code. Eliminate abstract frame index references... if (getOptLevel() != CodeGenOptLevel::None) { 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 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(); + 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..2e0efa9d963dc 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..e87e4d7ae67c8 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..0d8d4dc59f435 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..a44b62583460d 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..a2a194b651b3a 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..1a88a17213813 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..05d04f5b3efdc 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 --- |