Skip to content

Commit b9491e4

Browse files
committed
[CodeGen][NPM] Port ExpandPostRAPseudos to NPM
1 parent c9a807e commit b9491e4

File tree

11 files changed

+70
-14
lines changed

11 files changed

+70
-14
lines changed
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
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
17+
: public PassInfoMixin<ExpandPostRAPseudosPass> {
18+
public:
19+
PreservedAnalyses run(MachineFunction &MF,
20+
MachineFunctionAnalysisManager &MFAM);
21+
};
22+
23+
} // namespace llvm
24+
25+
#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()))
@@ -264,7 +265,6 @@ DUMMY_MACHINE_FUNCTION_PASS("machineinstr-printer", MachineFunctionPrinterPass)
264265
DUMMY_MACHINE_FUNCTION_PASS("mirfs-discriminators", MIRAddFSDiscriminatorsPass)
265266
DUMMY_MACHINE_FUNCTION_PASS("patchable-function", PatchableFunctionPass)
266267
DUMMY_MACHINE_FUNCTION_PASS("postra-machine-sink", PostRAMachineSinkingPass)
267-
DUMMY_MACHINE_FUNCTION_PASS("postrapseudos", ExpandPostRAPseudosPass)
268268
DUMMY_MACHINE_FUNCTION_PASS("print-machine-uniformity", MachineUniformityInfoPrinterPass)
269269
DUMMY_MACHINE_FUNCTION_PASS("processimpdefs", ProcessImplicitDefsPass)
270270
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 & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
//
1212
//===----------------------------------------------------------------------===//
1313

14+
#include "llvm/CodeGen/ExpandPostRAPseudos.h"
1415
#include "llvm/CodeGen/MachineFunctionPass.h"
1516
#include "llvm/CodeGen/MachineInstr.h"
1617
#include "llvm/CodeGen/Passes.h"
@@ -20,20 +21,30 @@
2021
#include "llvm/InitializePasses.h"
2122
#include "llvm/Support/Debug.h"
2223
#include "llvm/Support/raw_ostream.h"
24+
#include <llvm/CodeGen/MachineDominators.h>
25+
#include <llvm/CodeGen/MachineLoopInfo.h>
2326

2427
using namespace llvm;
2528

2629
#define DEBUG_TYPE "postrapseudos"
2730

2831
namespace {
29-
struct ExpandPostRA : public MachineFunctionPass {
32+
struct ExpandPostRA {
33+
34+
bool run(MachineFunction&);
35+
3036
private:
3137
const TargetRegisterInfo *TRI = nullptr;
3238
const TargetInstrInfo *TII = nullptr;
3339

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

3849
void getAnalysisUsage(AnalysisUsage &AU) const override {
3950
AU.setPreservesCFG();
@@ -44,16 +55,25 @@ struct ExpandPostRA : public MachineFunctionPass {
4455

4556
/// runOnMachineFunction - pass entry point
4657
bool runOnMachineFunction(MachineFunction&) override;
47-
48-
private:
49-
bool LowerSubregToReg(MachineInstr *MI);
5058
};
5159
} // end anonymous namespace
5260

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

56-
INITIALIZE_PASS(ExpandPostRA, DEBUG_TYPE,
76+
INITIALIZE_PASS(ExpandPostRALegacy, DEBUG_TYPE,
5777
"Post-RA pseudo instruction expansion pass", false, false)
5878

5979
bool ExpandPostRA::LowerSubregToReg(MachineInstr *MI) {
@@ -115,10 +135,14 @@ bool ExpandPostRA::LowerSubregToReg(MachineInstr *MI) {
115135
return true;
116136
}
117137

138+
bool ExpandPostRALegacy::runOnMachineFunction(MachineFunction &MF) {
139+
return ExpandPostRA().run(MF);
140+
}
141+
118142
/// runOnMachineFunction - Reduce subregister inserts and extracts to register
119143
/// copies.
120144
///
121-
bool ExpandPostRA::runOnMachineFunction(MachineFunction &MF) {
145+
bool ExpandPostRA::run(MachineFunction &MF) {
122146
LLVM_DEBUG(dbgs() << "Machine Function\n"
123147
<< "********** EXPANDING POST-RA PSEUDO INSTRS **********\n"
124148
<< "********** Function: " << MF.getName() << '\n');

llvm/lib/Passes/PassBuilder.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
//===----------------------------------------------------------------------===//
1616

1717
#include "llvm/Passes/PassBuilder.h"
18+
#include "llvm/CodeGen/ExpandPostRAPseudos.h"
1819
#include "llvm/ADT/StringSwitch.h"
1920
#include "llvm/Analysis/AliasAnalysisEvaluator.h"
2021
#include "llvm/Analysis/AliasSetTracker.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)