Skip to content

Commit 1d43145

Browse files
committed
[AMDGPU][NewPM] Port SILowerWWMCopies to NPM
1 parent fe7cb15 commit 1d43145

File tree

5 files changed

+105
-31
lines changed

5 files changed

+105
-31
lines changed

llvm/lib/Target/AMDGPU/AMDGPU.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -180,8 +180,8 @@ extern char &SIFixSGPRCopiesLegacyID;
180180
void initializeSIFixVGPRCopiesPass(PassRegistry &);
181181
extern char &SIFixVGPRCopiesID;
182182

183-
void initializeSILowerWWMCopiesPass(PassRegistry &);
184-
extern char &SILowerWWMCopiesID;
183+
void initializeSILowerWWMCopiesLegacyPass(PassRegistry &);
184+
extern char &SILowerWWMCopiesLegacyID;
185185

186186
void initializeSILowerI1CopiesLegacyPass(PassRegistry &);
187187
extern char &SILowerI1CopiesLegacyID;

llvm/lib/Target/AMDGPU/AMDGPUPassRegistry.def

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -104,6 +104,7 @@ MACHINE_FUNCTION_PASS("gcn-dpp-combine", GCNDPPCombinePass())
104104
MACHINE_FUNCTION_PASS("si-load-store-opt", SILoadStoreOptimizerPass())
105105
MACHINE_FUNCTION_PASS("si-lower-control-flow", SILowerControlFlowPass())
106106
MACHINE_FUNCTION_PASS("si-lower-sgpr-spills", SILowerSGPRSpillsPass())
107+
MACHINE_FUNCTION_PASS("si-lower-wwm-copies", SILowerWWMCopiesPass())
107108
MACHINE_FUNCTION_PASS("si-opt-vgpr-liverange", SIOptimizeVGPRLiveRangePass())
108109
MACHINE_FUNCTION_PASS("si-optimize-exec-masking", SIOptimizeExecMaskingPass())
109110
MACHINE_FUNCTION_PASS("si-peephole-sdwa", SIPeepholeSDWAPass())

llvm/lib/Target/AMDGPU/AMDGPUTargetMachine.cpp

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@
4040
#include "SILoadStoreOptimizer.h"
4141
#include "SILowerControlFlow.h"
4242
#include "SILowerSGPRSpills.h"
43+
#include "SILowerWWMCopies.h"
4344
#include "SIMachineFunctionInfo.h"
4445
#include "SIMachineScheduler.h"
4546
#include "SIOptimizeExecMasking.h"
@@ -482,7 +483,7 @@ extern "C" LLVM_EXTERNAL_VISIBILITY void LLVMInitializeAMDGPUTarget() {
482483
initializeAMDGPUGlobalISelDivergenceLoweringPass(*PR);
483484
initializeAMDGPURegBankSelectPass(*PR);
484485
initializeAMDGPURegBankLegalizePass(*PR);
485-
initializeSILowerWWMCopiesPass(*PR);
486+
initializeSILowerWWMCopiesLegacyPass(*PR);
486487
initializeAMDGPUMarkLastScratchLoadPass(*PR);
487488
initializeSILowerSGPRSpillsLegacyPass(*PR);
488489
initializeSIFixSGPRCopiesLegacyPass(*PR);
@@ -1581,7 +1582,7 @@ bool GCNPassConfig::addRegAssignAndRewriteFast() {
15811582
// For allocating other wwm register operands.
15821583
addPass(createWWMRegAllocPass(false));
15831584

1584-
addPass(&SILowerWWMCopiesID);
1585+
addPass(&SILowerWWMCopiesLegacyID);
15851586
addPass(&AMDGPUReserveWWMRegsID);
15861587

15871588
// For allocating per-thread VGPRs.
@@ -1617,7 +1618,7 @@ bool GCNPassConfig::addRegAssignAndRewriteOptimized() {
16171618

16181619
// For allocating other whole wave mode registers.
16191620
addPass(createWWMRegAllocPass(true));
1620-
addPass(&SILowerWWMCopiesID);
1621+
addPass(&SILowerWWMCopiesLegacyID);
16211622
addPass(createVirtRegRewriter(false));
16221623
addPass(&AMDGPUReserveWWMRegsID);
16231624

llvm/lib/Target/AMDGPU/SILowerWWMCopies.cpp

Lines changed: 55 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
//
1616
//===----------------------------------------------------------------------===//
1717

18+
#include "SILowerWWMCopies.h"
1819
#include "AMDGPU.h"
1920
#include "GCNSubtarget.h"
2021
#include "MCTargetDesc/AMDGPUMCTargetDesc.h"
@@ -30,12 +31,30 @@ using namespace llvm;
3031

3132
namespace {
3233

33-
class SILowerWWMCopies : public MachineFunctionPass {
34+
class SILowerWWMCopies {
35+
public:
36+
SILowerWWMCopies(LiveIntervals *LIS, SlotIndexes *SI, VirtRegMap *VRM)
37+
: LIS(LIS), Indexes(SI), VRM(VRM) {}
38+
bool run(MachineFunction &MF);
39+
40+
private:
41+
bool isSCCLiveAtMI(const MachineInstr &MI);
42+
void addToWWMSpills(MachineFunction &MF, Register Reg);
43+
44+
LiveIntervals *LIS;
45+
SlotIndexes *Indexes;
46+
VirtRegMap *VRM;
47+
const SIRegisterInfo *TRI;
48+
const MachineRegisterInfo *MRI;
49+
SIMachineFunctionInfo *MFI;
50+
};
51+
52+
class SILowerWWMCopiesLegacy : public MachineFunctionPass {
3453
public:
3554
static char ID;
3655

37-
SILowerWWMCopies() : MachineFunctionPass(ID) {
38-
initializeSILowerWWMCopiesPass(*PassRegistry::getPassRegistry());
56+
SILowerWWMCopiesLegacy() : MachineFunctionPass(ID) {
57+
initializeSILowerWWMCopiesLegacyPass(*PassRegistry::getPassRegistry());
3958
}
4059

4160
bool runOnMachineFunction(MachineFunction &MF) override;
@@ -46,31 +65,20 @@ class SILowerWWMCopies : public MachineFunctionPass {
4665
AU.setPreservesAll();
4766
MachineFunctionPass::getAnalysisUsage(AU);
4867
}
49-
50-
private:
51-
bool isSCCLiveAtMI(const MachineInstr &MI);
52-
void addToWWMSpills(MachineFunction &MF, Register Reg);
53-
54-
LiveIntervals *LIS;
55-
SlotIndexes *Indexes;
56-
VirtRegMap *VRM;
57-
const SIRegisterInfo *TRI;
58-
const MachineRegisterInfo *MRI;
59-
SIMachineFunctionInfo *MFI;
6068
};
6169

6270
} // End anonymous namespace.
6371

64-
INITIALIZE_PASS_BEGIN(SILowerWWMCopies, DEBUG_TYPE, "SI Lower WWM Copies",
72+
INITIALIZE_PASS_BEGIN(SILowerWWMCopiesLegacy, DEBUG_TYPE, "SI Lower WWM Copies",
6573
false, false)
6674
INITIALIZE_PASS_DEPENDENCY(LiveIntervalsWrapperPass)
6775
INITIALIZE_PASS_DEPENDENCY(VirtRegMapWrapperLegacy)
68-
INITIALIZE_PASS_END(SILowerWWMCopies, DEBUG_TYPE, "SI Lower WWM Copies", false,
69-
false)
76+
INITIALIZE_PASS_END(SILowerWWMCopiesLegacy, DEBUG_TYPE, "SI Lower WWM Copies",
77+
false, false)
7078

71-
char SILowerWWMCopies::ID = 0;
79+
char SILowerWWMCopiesLegacy::ID = 0;
7280

73-
char &llvm::SILowerWWMCopiesID = SILowerWWMCopies::ID;
81+
char &llvm::SILowerWWMCopiesLegacyID = SILowerWWMCopiesLegacy::ID;
7482

7583
bool SILowerWWMCopies::isSCCLiveAtMI(const MachineInstr &MI) {
7684
// We can't determine the liveness info if LIS isn't available. Early return
@@ -90,23 +98,44 @@ void SILowerWWMCopies::addToWWMSpills(MachineFunction &MF, Register Reg) {
9098
if (Reg.isPhysical())
9199
return;
92100

101+
// FIXME: VRM is not an optional requirement, we check it for assignment here
93102
MCRegister PhysReg = VRM->getPhys(Reg);
94103
assert(PhysReg && "should have allocated a physical register");
95104

96105
MFI->allocateWWMSpill(MF, PhysReg);
97106
}
98107

99-
bool SILowerWWMCopies::runOnMachineFunction(MachineFunction &MF) {
108+
bool SILowerWWMCopiesLegacy::runOnMachineFunction(MachineFunction &MF) {
109+
auto *LISWrapper = getAnalysisIfAvailable<LiveIntervalsWrapperPass>();
110+
auto *LIS = LISWrapper ? &LISWrapper->getLIS() : nullptr;
111+
112+
auto *SIWrapper = getAnalysisIfAvailable<SlotIndexesWrapperPass>();
113+
auto *Indexes = SIWrapper ? &SIWrapper->getSI() : nullptr;
114+
115+
auto *VRMWrapper = getAnalysisIfAvailable<VirtRegMapWrapperLegacy>();
116+
auto *VRM = VRMWrapper ? &VRMWrapper->getVRM() : nullptr;
117+
118+
SILowerWWMCopies Impl(LIS, Indexes, VRM);
119+
return Impl.run(MF);
120+
}
121+
122+
PreservedAnalyses
123+
SILowerWWMCopiesPass::run(MachineFunction &MF,
124+
MachineFunctionAnalysisManager &MFAM) {
125+
auto *LIS = MFAM.getCachedResult<LiveIntervalsAnalysis>(MF);
126+
auto *Indexes = MFAM.getCachedResult<SlotIndexesAnalysis>(MF);
127+
auto *VRM = MFAM.getCachedResult<VirtRegMapAnalysis>(MF);
128+
129+
SILowerWWMCopies Impl(LIS, Indexes, VRM);
130+
Impl.run(MF);
131+
return PreservedAnalyses::all();
132+
}
133+
134+
bool SILowerWWMCopies::run(MachineFunction &MF) {
100135
const GCNSubtarget &ST = MF.getSubtarget<GCNSubtarget>();
101136
const SIInstrInfo *TII = ST.getInstrInfo();
102137

103138
MFI = MF.getInfo<SIMachineFunctionInfo>();
104-
auto *LISWrapper = getAnalysisIfAvailable<LiveIntervalsWrapperPass>();
105-
LIS = LISWrapper ? &LISWrapper->getLIS() : nullptr;
106-
auto *SIWrapper = getAnalysisIfAvailable<SlotIndexesWrapperPass>();
107-
Indexes = SIWrapper ? &SIWrapper->getSI() : nullptr;
108-
auto *VRMWrapper = getAnalysisIfAvailable<VirtRegMapWrapperLegacy>();
109-
VRM = VRMWrapper ? &VRMWrapper->getVRM() : nullptr;
110139
TRI = ST.getRegisterInfo();
111140
MRI = &MF.getRegInfo();
112141

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
# NOTE: Assertions have been autogenerated by utils/update_mir_test_checks.py UTC_ARGS: --version 5
2+
3+
# RUN: llc -mtriple=amdgcn-amd-amdhsa -mcpu=gfx900 -run-pass=liveintervals,virtregmap,si-lower-wwm-copies -o - %s | FileCheck %s
4+
# RUN: llc -mtriple=amdgcn-amd-amdhsa -mcpu=gfx900 -passes="require<live-intervals>,require<virtregmap>,si-lower-wwm-copies" -o - %s | FileCheck %s
5+
6+
# Check for two cases of $scc being live and dead.
7+
---
8+
name: lower-wwm-copies
9+
registers:
10+
- { id: 1, class: vgpr_32, flags: [ WWM_REG ]}
11+
machineFunctionInfo:
12+
sgprForEXECCopy: '$sgpr2_sgpr3'
13+
tracksRegLiveness: true
14+
body: |
15+
; CHECK-LABEL: name: lower-wwm-copies
16+
; CHECK: bb.0:
17+
; CHECK-NEXT: successors: %bb.1(0x80000000)
18+
; CHECK-NEXT: liveins: $vgpr0, $scc
19+
; CHECK-NEXT: {{ $}}
20+
; CHECK-NEXT: [[DEF:%[0-9]+]]:sgpr_32 = IMPLICIT_DEF
21+
; CHECK-NEXT: S_CMP_EQ_U32 [[DEF]], 0, implicit-def $scc
22+
; CHECK-NEXT: $sgpr2_sgpr3 = S_MOV_B64 killed $exec
23+
; CHECK-NEXT: $exec = S_MOV_B64 -1
24+
; CHECK-NEXT: $vgpr1 = COPY $vgpr0
25+
; CHECK-NEXT: $exec = S_MOV_B64 killed $sgpr2_sgpr3
26+
; CHECK-NEXT: S_CBRANCH_SCC1 %bb.1, implicit $scc
27+
; CHECK-NEXT: {{ $}}
28+
; CHECK-NEXT: bb.1:
29+
; CHECK-NEXT: liveins: $vgpr1
30+
; CHECK-NEXT: {{ $}}
31+
; CHECK-NEXT: $sgpr2_sgpr3 = S_OR_SAVEEXEC_B64 -1, implicit-def $exec, implicit-def dead $scc, implicit $exec
32+
; CHECK-NEXT: $vgpr2 = COPY $vgpr1
33+
; CHECK-NEXT: $exec = S_MOV_B64 killed $sgpr2_sgpr3
34+
bb.0:
35+
liveins: $vgpr0, $scc
36+
%0:sgpr_32 = IMPLICIT_DEF
37+
S_CMP_EQ_U32 %0, 0, implicit-def $scc
38+
$vgpr1 = WWM_COPY $vgpr0
39+
S_CBRANCH_SCC1 %bb.1, implicit killed $scc
40+
41+
bb.1:
42+
liveins: $vgpr1
43+
$vgpr2 = WWM_COPY $vgpr1

0 commit comments

Comments
 (0)