Skip to content

Commit af4ec59

Browse files
authored
[CodeGen][NPM] Port ExpandPostRAPseudos to NPM (#129509)
1 parent 6c87ec4 commit af4ec59

File tree

11 files changed

+69
-15
lines changed

11 files changed

+69
-15
lines changed
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
//===- llvm/CodeGen/ExpandPostRAPseudos.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_EXPANDPOSTRAPSEUDOS_H
10+
#define LLVM_CODEGEN_EXPANDPOSTRAPSEUDOS_H
11+
12+
#include "llvm/CodeGen/MachinePassManager.h"
13+
14+
namespace llvm {
15+
16+
class ExpandPostRAPseudosPass : public PassInfoMixin<ExpandPostRAPseudosPass> {
17+
public:
18+
PreservedAnalyses run(MachineFunction &MF,
19+
MachineFunctionAnalysisManager &MFAM);
20+
};
21+
22+
} // namespace llvm
23+
24+
#endif // LLVM_CODEGEN_EXPANDPOSTRAPSEUDOS_H

llvm/include/llvm/InitializePasses.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -108,7 +108,7 @@ void initializeEHContGuardCatchretPass(PassRegistry &);
108108
void initializeExpandLargeFpConvertLegacyPassPass(PassRegistry &);
109109
void initializeExpandLargeDivRemLegacyPassPass(PassRegistry &);
110110
void initializeExpandMemCmpLegacyPassPass(PassRegistry &);
111-
void initializeExpandPostRAPass(PassRegistry &);
111+
void initializeExpandPostRALegacyPass(PassRegistry &);
112112
void initializeExpandReductionsPass(PassRegistry &);
113113
void initializeExpandVariadicsPass(PassRegistry &);
114114
void initializeExternalAAWrapperPassPass(PassRegistry &);

llvm/include/llvm/Passes/CodeGenPassBuilder.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@
3131
#include "llvm/CodeGen/ExpandLargeDivRem.h"
3232
#include "llvm/CodeGen/ExpandLargeFpConvert.h"
3333
#include "llvm/CodeGen/ExpandMemCmp.h"
34+
#include "llvm/CodeGen/ExpandPostRAPseudos.h"
3435
#include "llvm/CodeGen/ExpandReductions.h"
3536
#include "llvm/CodeGen/FinalizeISel.h"
3637
#include "llvm/CodeGen/GCMetadata.h"

llvm/include/llvm/Passes/MachinePassRegistry.def

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -154,6 +154,7 @@ MACHINE_FUNCTION_PASS("peephole-opt", PeepholeOptimizerPass())
154154
MACHINE_FUNCTION_PASS("phi-node-elimination", PHIEliminationPass())
155155
MACHINE_FUNCTION_PASS("post-RA-sched", PostRASchedulerPass(TM))
156156
MACHINE_FUNCTION_PASS("postmisched", PostMachineSchedulerPass(TM))
157+
MACHINE_FUNCTION_PASS("post-ra-pseudos", ExpandPostRAPseudosPass())
157158
MACHINE_FUNCTION_PASS("print", PrintMIRPass())
158159
MACHINE_FUNCTION_PASS("print<livedebugvars>", LiveDebugVariablesPrinterPass(errs()))
159160
MACHINE_FUNCTION_PASS("print<live-intervals>", LiveIntervalsPrinterPass(errs()))
@@ -271,7 +272,6 @@ DUMMY_MACHINE_FUNCTION_PASS("machineinstr-printer", MachineFunctionPrinterPass)
271272
DUMMY_MACHINE_FUNCTION_PASS("mirfs-discriminators", MIRAddFSDiscriminatorsPass)
272273
DUMMY_MACHINE_FUNCTION_PASS("patchable-function", PatchableFunctionPass)
273274
DUMMY_MACHINE_FUNCTION_PASS("postra-machine-sink", PostRAMachineSinkingPass)
274-
DUMMY_MACHINE_FUNCTION_PASS("postrapseudos", ExpandPostRAPseudosPass)
275275
DUMMY_MACHINE_FUNCTION_PASS("print-machine-uniformity", MachineUniformityInfoPrinterPass)
276276
DUMMY_MACHINE_FUNCTION_PASS("processimpdefs", ProcessImplicitDefsPass)
277277
DUMMY_MACHINE_FUNCTION_PASS("prologepilog", PrologEpilogInserterPass)

llvm/lib/CodeGen/CodeGen.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ void llvm::initializeCodeGen(PassRegistry &Registry) {
4242
initializeExpandLargeDivRemLegacyPassPass(Registry);
4343
initializeExpandLargeFpConvertLegacyPassPass(Registry);
4444
initializeExpandMemCmpLegacyPassPass(Registry);
45-
initializeExpandPostRAPass(Registry);
45+
initializeExpandPostRALegacyPass(Registry);
4646
initializeFEntryInserterPass(Registry);
4747
initializeFinalizeISelPass(Registry);
4848
initializeFinalizeMachineBundlesPass(Registry);

llvm/lib/CodeGen/ExpandPostRAPseudos.cpp

Lines changed: 35 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,11 @@
1111
//
1212
//===----------------------------------------------------------------------===//
1313

14+
#include "llvm/CodeGen/ExpandPostRAPseudos.h"
15+
#include "llvm/CodeGen/MachineDominators.h"
1416
#include "llvm/CodeGen/MachineFunctionPass.h"
1517
#include "llvm/CodeGen/MachineInstr.h"
18+
#include "llvm/CodeGen/MachineLoopInfo.h"
1619
#include "llvm/CodeGen/Passes.h"
1720
#include "llvm/CodeGen/TargetInstrInfo.h"
1821
#include "llvm/CodeGen/TargetRegisterInfo.h"
@@ -26,14 +29,21 @@ using namespace llvm;
2629
#define DEBUG_TYPE "postrapseudos"
2730

2831
namespace {
29-
struct ExpandPostRA : public MachineFunctionPass {
32+
struct ExpandPostRA {
33+
bool run(MachineFunction &);
34+
3035
private:
3136
const TargetRegisterInfo *TRI = nullptr;
3237
const TargetInstrInfo *TII = nullptr;
3338

34-
public:
35-
static char ID; // Pass identification, replacement for typeid
36-
ExpandPostRA() : MachineFunctionPass(ID) {}
39+
bool LowerSubregToReg(MachineInstr *MI);
40+
};
41+
42+
struct ExpandPostRALegacy : public MachineFunctionPass {
43+
static char ID;
44+
ExpandPostRALegacy() : MachineFunctionPass(ID) {
45+
initializeExpandPostRALegacyPass(*PassRegistry::getPassRegistry());
46+
}
3747

3848
void getAnalysisUsage(AnalysisUsage &AU) const override {
3949
AU.setPreservesCFG();
@@ -43,17 +53,26 @@ struct ExpandPostRA : public MachineFunctionPass {
4353
}
4454

4555
/// runOnMachineFunction - pass entry point
46-
bool runOnMachineFunction(MachineFunction&) override;
47-
48-
private:
49-
bool LowerSubregToReg(MachineInstr *MI);
56+
bool runOnMachineFunction(MachineFunction &) override;
5057
};
5158
} // end anonymous namespace
5259

53-
char ExpandPostRA::ID = 0;
54-
char &llvm::ExpandPostRAPseudosID = ExpandPostRA::ID;
60+
PreservedAnalyses
61+
ExpandPostRAPseudosPass::run(MachineFunction &MF,
62+
MachineFunctionAnalysisManager &MFAM) {
63+
if (!ExpandPostRA().run(MF))
64+
return PreservedAnalyses::all();
65+
66+
return getMachineFunctionPassPreservedAnalyses()
67+
.preserveSet<CFGAnalyses>()
68+
.preserve<MachineLoopAnalysis>()
69+
.preserve<MachineDominatorTreeAnalysis>();
70+
}
71+
72+
char ExpandPostRALegacy::ID = 0;
73+
char &llvm::ExpandPostRAPseudosID = ExpandPostRALegacy::ID;
5574

56-
INITIALIZE_PASS(ExpandPostRA, DEBUG_TYPE,
75+
INITIALIZE_PASS(ExpandPostRALegacy, DEBUG_TYPE,
5776
"Post-RA pseudo instruction expansion pass", false, false)
5877

5978
bool ExpandPostRA::LowerSubregToReg(MachineInstr *MI) {
@@ -115,10 +134,14 @@ bool ExpandPostRA::LowerSubregToReg(MachineInstr *MI) {
115134
return true;
116135
}
117136

137+
bool ExpandPostRALegacy::runOnMachineFunction(MachineFunction &MF) {
138+
return ExpandPostRA().run(MF);
139+
}
140+
118141
/// runOnMachineFunction - Reduce subregister inserts and extracts to register
119142
/// copies.
120143
///
121-
bool ExpandPostRA::runOnMachineFunction(MachineFunction &MF) {
144+
bool ExpandPostRA::run(MachineFunction &MF) {
122145
LLVM_DEBUG(dbgs() << "Machine Function\n"
123146
<< "********** EXPANDING POST-RA PSEUDO INSTRS **********\n"
124147
<< "********** Function: " << MF.getName() << '\n');

llvm/lib/Passes/PassBuilder.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -90,6 +90,7 @@
9090
#include "llvm/CodeGen/ExpandLargeDivRem.h"
9191
#include "llvm/CodeGen/ExpandLargeFpConvert.h"
9292
#include "llvm/CodeGen/ExpandMemCmp.h"
93+
#include "llvm/CodeGen/ExpandPostRAPseudos.h"
9394
#include "llvm/CodeGen/FinalizeISel.h"
9495
#include "llvm/CodeGen/GCMetadata.h"
9596
#include "llvm/CodeGen/GlobalMerge.h"

llvm/test/CodeGen/AArch64/seqpaircopy.mir

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
# RUN: llc -o - %s -mtriple=aarch64-- -mattr=+v8.1a -run-pass=postrapseudos | FileCheck %s
2+
# RUN: llc -o - %s -mtriple=aarch64-- -mattr=+v8.1a -passes=post-ra-pseudos | FileCheck %s
23
---
34
# CHECK-LABEL: name: copy_xseqpairs
45
name: copy_xseqpairs

llvm/test/CodeGen/AMDGPU/accvgpr-copy.mir

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@
33
# RUN: llc -mtriple=amdgcn -mcpu=gfx90a -run-pass postrapseudos -verify-machineinstrs -o - %s | FileCheck -check-prefix=GFX90A %s
44
# RUN: llc -mtriple=amdgcn -mcpu=gfx942 -run-pass postrapseudos -verify-machineinstrs -o - %s | FileCheck -check-prefix=GFX942 %s
55

6+
# RUN: llc -mtriple=amdgcn -mcpu=gfx942 -passes=post-ra-pseudos -verify-machineinstrs -o - %s | FileCheck -check-prefix=GFX942 %s
7+
68
--- |
79
define amdgpu_kernel void @a_to_v() #0 { ret void }
810
define amdgpu_kernel void @a2_to_v2() #0 { ret void }

llvm/test/CodeGen/RISCV/rvv/vmv-copy.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 -verify-machineinstrs -mtriple riscv64 -run-pass=postrapseudos %s -o - | FileCheck %s
3+
# RUN: llc -verify-machineinstrs -mtriple riscv64 -passes=post-ra-pseudos %s -o - | FileCheck %s
34

45
...
56
---

llvm/test/CodeGen/SystemZ/copy-phys-reg-gr64-to-fp64.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 UTC_ARGS: --version 4
22
# RUN: llc -mtriple=s390x-ibm-linux -mcpu=z13 -run-pass=postrapseudos -o - %s | FileCheck %s
3+
# RUN: llc -mtriple=s390x-ibm-linux -mcpu=z13 -passes=post-ra-pseudos -o - %s | FileCheck %s
34
---
45
name: copy_fp64_to_gr64__f3d_to_r1d
56
tracksRegLiveness: true

0 commit comments

Comments
 (0)