Skip to content

Commit e0eb4ed

Browse files
authored
[CodeGen][NewPM] Port "FixupStatepointCallerSaved" pass to NPM (#129541)
1 parent 0fcbf14 commit e0eb4ed

14 files changed

+72
-15
lines changed
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
//===- llvm/CodeGen/FixupStatepointCallerSaved.h ----------------*- C++ -*-===//
2+
//
3+
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4+
// See https://llvm.org/LICENSE.txt for license information.
5+
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6+
//
7+
//===----------------------------------------------------------------------===//
8+
9+
#ifndef LLVM_CODEGEN_FIXUPSTATEPOINTCALLERSAVED_H
10+
#define LLVM_CODEGEN_FIXUPSTATEPOINTCALLERSAVED_H
11+
12+
#include "llvm/CodeGen/MachinePassManager.h"
13+
14+
namespace llvm {
15+
16+
class FixupStatepointCallerSavedPass
17+
: public PassInfoMixin<FixupStatepointCallerSavedPass> {
18+
public:
19+
PreservedAnalyses run(MachineFunction &MF,
20+
MachineFunctionAnalysisManager &MFAM);
21+
};
22+
23+
} // namespace llvm
24+
25+
#endif // LLVM_CODEGEN_FIXUPSTATEPOINTCALLERSAVED_H

llvm/include/llvm/InitializePasses.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -116,7 +116,7 @@ void initializeFEntryInserterPass(PassRegistry &);
116116
void initializeFinalizeISelPass(PassRegistry &);
117117
void initializeFinalizeMachineBundlesPass(PassRegistry &);
118118
void initializeFixIrreduciblePass(PassRegistry &);
119-
void initializeFixupStatepointCallerSavedPass(PassRegistry &);
119+
void initializeFixupStatepointCallerSavedLegacyPass(PassRegistry &);
120120
void initializeFlattenCFGLegacyPassPass(PassRegistry &);
121121
void initializeFuncletLayoutPass(PassRegistry &);
122122
void initializeGCEmptyBasicBlocksPass(PassRegistry &);

llvm/include/llvm/Passes/CodeGenPassBuilder.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@
3434
#include "llvm/CodeGen/ExpandPostRAPseudos.h"
3535
#include "llvm/CodeGen/ExpandReductions.h"
3636
#include "llvm/CodeGen/FinalizeISel.h"
37+
#include "llvm/CodeGen/FixupStatepointCallerSaved.h"
3738
#include "llvm/CodeGen/GCMetadata.h"
3839
#include "llvm/CodeGen/GlobalMerge.h"
3940
#include "llvm/CodeGen/GlobalMergeFunctions.h"
@@ -939,6 +940,7 @@ Error CodeGenPassBuilder<Derived, TargetMachineT>::addMachinePasses(
939940
derived().addPostRegAlloc(addPass);
940941

941942
addPass(RemoveRedundantDebugValuesPass());
943+
addPass(FixupStatepointCallerSavedPass());
942944

943945
// Insert prolog/epilog code. Eliminate abstract frame index references...
944946
if (getOptLevel() != CodeGenOptLevel::None) {

llvm/include/llvm/Passes/MachinePassRegistry.def

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -142,6 +142,7 @@ MACHINE_FUNCTION_PASS("early-ifcvt", EarlyIfConverterPass())
142142
MACHINE_FUNCTION_PASS("early-machinelicm", EarlyMachineLICMPass())
143143
MACHINE_FUNCTION_PASS("early-tailduplication", EarlyTailDuplicatePass())
144144
MACHINE_FUNCTION_PASS("finalize-isel", FinalizeISelPass())
145+
MACHINE_FUNCTION_PASS("fixup-statepoint-caller-saved", FixupStatepointCallerSavedPass())
145146
MACHINE_FUNCTION_PASS("localstackalloc", LocalStackSlotAllocationPass())
146147
MACHINE_FUNCTION_PASS("machine-cp", MachineCopyPropagationPass())
147148
MACHINE_FUNCTION_PASS("machine-cse", MachineCSEPass())
@@ -251,7 +252,6 @@ DUMMY_MACHINE_FUNCTION_PASS("cfi-instr-inserter", CFIInstrInserterPass)
251252
DUMMY_MACHINE_FUNCTION_PASS("detect-dead-lanes", DetectDeadLanesPass)
252253
DUMMY_MACHINE_FUNCTION_PASS("dot-machine-cfg", MachineCFGPrinter)
253254
DUMMY_MACHINE_FUNCTION_PASS("fentry-insert", FEntryInserterPass)
254-
DUMMY_MACHINE_FUNCTION_PASS("fixup-statepoint-caller-saved", FixupStatepointCallerSavedPass)
255255
DUMMY_MACHINE_FUNCTION_PASS("fs-profile-loader", MIRProfileLoaderNewPass)
256256
DUMMY_MACHINE_FUNCTION_PASS("funclet-layout", FuncletLayoutPass)
257257
DUMMY_MACHINE_FUNCTION_PASS("gc-empty-basic-blocks", GCEmptyBasicBlocksPass)

llvm/lib/CodeGen/CodeGen.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ void llvm::initializeCodeGen(PassRegistry &Registry) {
4646
initializeFEntryInserterPass(Registry);
4747
initializeFinalizeISelPass(Registry);
4848
initializeFinalizeMachineBundlesPass(Registry);
49-
initializeFixupStatepointCallerSavedPass(Registry);
49+
initializeFixupStatepointCallerSavedLegacyPass(Registry);
5050
initializeFuncletLayoutPass(Registry);
5151
initializeGCMachineCodeAnalysisPass(Registry);
5252
initializeGCModuleInfoPass(Registry);

llvm/lib/CodeGen/FixupStatepointCallerSaved.cpp

Lines changed: 34 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020
///
2121
//===----------------------------------------------------------------------===//
2222

23+
#include "llvm/CodeGen/FixupStatepointCallerSaved.h"
2324
#include "llvm/ADT/SmallSet.h"
2425
#include "llvm/ADT/Statistic.h"
2526
#include "llvm/CodeGen/MachineFrameInfo.h"
@@ -58,14 +59,18 @@ static cl::opt<unsigned> MaxStatepointsWithRegs(
5859

5960
namespace {
6061

61-
class FixupStatepointCallerSaved : public MachineFunctionPass {
62+
struct FixupStatepointCallerSavedImpl {
63+
bool run(MachineFunction &MF);
64+
};
65+
66+
class FixupStatepointCallerSavedLegacy : public MachineFunctionPass {
6267
public:
6368
static char ID;
6469

65-
FixupStatepointCallerSaved() : MachineFunctionPass(ID) {
66-
initializeFixupStatepointCallerSavedPass(*PassRegistry::getPassRegistry());
70+
FixupStatepointCallerSavedLegacy() : MachineFunctionPass(ID) {
71+
initializeFixupStatepointCallerSavedLegacyPass(
72+
*PassRegistry::getPassRegistry());
6773
}
68-
6974
void getAnalysisUsage(AnalysisUsage &AU) const override {
7075
AU.setPreservesCFG();
7176
MachineFunctionPass::getAnalysisUsage(AU);
@@ -80,12 +85,12 @@ class FixupStatepointCallerSaved : public MachineFunctionPass {
8085

8186
} // End anonymous namespace.
8287

83-
char FixupStatepointCallerSaved::ID = 0;
84-
char &llvm::FixupStatepointCallerSavedID = FixupStatepointCallerSaved::ID;
88+
char FixupStatepointCallerSavedLegacy::ID = 0;
89+
char &llvm::FixupStatepointCallerSavedID = FixupStatepointCallerSavedLegacy::ID;
8590

86-
INITIALIZE_PASS_BEGIN(FixupStatepointCallerSaved, DEBUG_TYPE,
91+
INITIALIZE_PASS_BEGIN(FixupStatepointCallerSavedLegacy, DEBUG_TYPE,
8792
"Fixup Statepoint Caller Saved", false, false)
88-
INITIALIZE_PASS_END(FixupStatepointCallerSaved, DEBUG_TYPE,
93+
INITIALIZE_PASS_END(FixupStatepointCallerSavedLegacy, DEBUG_TYPE,
8994
"Fixup Statepoint Caller Saved", false, false)
9095

9196
// Utility function to get size of the register.
@@ -590,10 +595,7 @@ class StatepointProcessor {
590595
};
591596
} // namespace
592597

593-
bool FixupStatepointCallerSaved::runOnMachineFunction(MachineFunction &MF) {
594-
if (skipFunction(MF.getFunction()))
595-
return false;
596-
598+
bool FixupStatepointCallerSavedImpl::run(MachineFunction &MF) {
597599
const Function &F = MF.getFunction();
598600
if (!F.hasGC())
599601
return false;
@@ -620,3 +622,23 @@ bool FixupStatepointCallerSaved::runOnMachineFunction(MachineFunction &MF) {
620622
}
621623
return Changed;
622624
}
625+
626+
bool FixupStatepointCallerSavedLegacy::runOnMachineFunction(
627+
MachineFunction &MF) {
628+
if (skipFunction(MF.getFunction()))
629+
return false;
630+
631+
return FixupStatepointCallerSavedImpl().run(MF);
632+
}
633+
634+
PreservedAnalyses
635+
FixupStatepointCallerSavedPass::run(MachineFunction &MF,
636+
MachineFunctionAnalysisManager &MFAM) {
637+
638+
if (!FixupStatepointCallerSavedImpl().run(MF))
639+
return PreservedAnalyses::all();
640+
641+
auto PA = getMachineFunctionPassPreservedAnalyses();
642+
PA.preserveSet<CFGAnalyses>();
643+
return PA;
644+
}

llvm/lib/Passes/PassBuilder.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -92,6 +92,7 @@
9292
#include "llvm/CodeGen/ExpandMemCmp.h"
9393
#include "llvm/CodeGen/ExpandPostRAPseudos.h"
9494
#include "llvm/CodeGen/FinalizeISel.h"
95+
#include "llvm/CodeGen/FixupStatepointCallerSaved.h"
9596
#include "llvm/CodeGen/GCMetadata.h"
9697
#include "llvm/CodeGen/GlobalMerge.h"
9798
#include "llvm/CodeGen/GlobalMergeFunctions.h"

llvm/test/CodeGen/X86/statepoint-fixup-call.mir

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
# NOTE: Assertions have been autogenerated by utils/update_mir_test_checks.py
22
# RUN: llc -o - %s -fixup-allow-gcptr-in-csr=false -run-pass fixup-statepoint-caller-saved | FileCheck %s
3+
# RUN: llc -o - %s -fixup-allow-gcptr-in-csr=false -passes='fixup-statepoint-caller-saved' | FileCheck %s
34
--- |
45
; ModuleID = 'test/CodeGen/X86/statepoint-fixup-call.ll'
56
source_filename = "test/CodeGen/X86/statepoint-fixup-call.ll"

llvm/test/CodeGen/X86/statepoint-fixup-copy-prop-neg.mir

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
# NOTE: Assertions have been autogenerated by utils/update_mir_test_checks.py
22
# RUN: llc -o - %s -run-pass fixup-statepoint-caller-saved -verify-machineinstrs | FileCheck %s
3+
# RUN: llc -o - %s -passes='fixup-statepoint-caller-saved' | FileCheck %s
34

45
# Check that COPY is not eliminated if dest register is used in
56
# non-meta arguments of statepoint.

llvm/test/CodeGen/X86/statepoint-fixup-copy-prop.mir

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
# RUN: llc -o - %s -run-pass fixup-statepoint-caller-saved -verify-machineinstrs | FileCheck %s
2+
# RUN: llc -o - %s -passes='fixup-statepoint-caller-saved' | FileCheck %s
23

34
--- |
45
target datalayout = "e-m:e-p270:32:32-p271:32:32-p272:64:64-i64:64-f80:128-n8:16:32:64-S128"

llvm/test/CodeGen/X86/statepoint-fixup-invoke.mir

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
# NOTE: Assertions have been autogenerated by utils/update_mir_test_checks.py
22
# RUN: llc -o - %s -fixup-allow-gcptr-in-csr=false -run-pass fixup-statepoint-caller-saved | FileCheck %s
3+
# RUN: llc -o - %s -fixup-allow-gcptr-in-csr=false -passes='fixup-statepoint-caller-saved' | FileCheck %s
34

45
--- |
56
; ModuleID = 'test/CodeGen/X86/statepoint-fixup-invoke.mir'

llvm/test/CodeGen/X86/statepoint-fixup-shared-ehpad.mir

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
# NOTE: Assertions have been autogenerated by utils/update_mir_test_checks.py
22
# RUN: llc -o - %s -fixup-allow-gcptr-in-csr=false -run-pass fixup-statepoint-caller-saved | FileCheck %s
3+
# RUN: llc -o - %s -fixup-allow-gcptr-in-csr=false -passes='fixup-statepoint-caller-saved' | FileCheck %s
34

45
# NOTE: MIR in this test was hand edited to have two statepoints share single landing pad.
56
# This is forbidden in IR, but is allowed in MIR. I just was unable to reproduce conditions

llvm/test/CodeGen/X86/statepoint-fixup-undef-def.mir

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
# NOTE: Assertions have been autogenerated by utils/update_mir_test_checks.py
22
# RUN: llc -x mir -run-pass fixup-statepoint-caller-saved -verify-machineinstrs < %s | FileCheck %s
3+
# RUN: llc -x mir -passes='fixup-statepoint-caller-saved' < %s | FileCheck %s
34

45
--- |
56
; ModuleID = 'undef.ll'

llvm/test/CodeGen/X86/statepoint-fixup-undef.mir

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
# NOTE: Assertions have been autogenerated by utils/update_mir_test_checks.py
22
# RUN: llc -x mir -run-pass fixup-statepoint-caller-saved -verify-machineinstrs < %s | FileCheck %s
3+
# RUN: llc -x mir -passes='fixup-statepoint-caller-saved' < %s | FileCheck %s
34
# RUN: llc -x mir -start-before fixup-statepoint-caller-saved -verify-machineinstrs < %s | FileCheck %s -check-prefix=STACKMAP
45

56
--- |

0 commit comments

Comments
 (0)