LLVM 24.0.0git
AMDGPUReserveWWMRegs.cpp
Go to the documentation of this file.
1//===-- AMDGPUReserveWWMRegs.cpp - Add WWM Regs to reserved regs list -----===//
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/// \file
10/// This pass should be invoked at the end of wwm-regalloc pipeline.
11/// It identifies the WWM regs allocated during this pipeline and add
12/// them to the list of reserved registers so that they won't be available for
13/// per-thread VGPR allocation in the subsequent regalloc pipeline.
14//
15//===----------------------------------------------------------------------===//
16
18#include "AMDGPU.h"
24
25using namespace llvm;
26
27#define DEBUG_TYPE "amdgpu-reserve-wwm-regs"
28
29namespace {
30
31class AMDGPUReserveWWMRegsLegacy : public MachineFunctionPass {
32public:
33 static char ID;
34
35 AMDGPUReserveWWMRegsLegacy() : MachineFunctionPass(ID) {}
36
37 bool runOnMachineFunction(MachineFunction &MF) override;
38
39 StringRef getPassName() const override {
40 return "AMDGPU Reserve WWM Registers";
41 }
42
43 void getAnalysisUsage(AnalysisUsage &AU) const override {
45 AU.setPreservesAll();
47 }
48};
49
50class AMDGPUReserveWWMRegs {
52
53public:
54 explicit AMDGPUReserveWWMRegs(RegisterClassInfo &RCI) : RCI(RCI) {}
55
56 bool run(MachineFunction &MF);
57};
58
59} // End anonymous namespace.
60
61INITIALIZE_PASS_BEGIN(AMDGPUReserveWWMRegsLegacy, DEBUG_TYPE,
62 "AMDGPU Reserve WWM Registers", false, false)
64INITIALIZE_PASS_END(AMDGPUReserveWWMRegsLegacy, DEBUG_TYPE,
65 "AMDGPU Reserve WWM Registers", false, false)
66
67char AMDGPUReserveWWMRegsLegacy::ID = 0;
68
69char &llvm::AMDGPUReserveWWMRegsLegacyID = AMDGPUReserveWWMRegsLegacy::ID;
70
71bool AMDGPUReserveWWMRegsLegacy::runOnMachineFunction(MachineFunction &MF) {
72 auto &RCI = getAnalysis<MachineRegisterClassInfoWrapperPass>().getRCI();
73 return AMDGPUReserveWWMRegs(RCI).run(MF);
74}
75
79 auto &RCI = MFAM.getResult<MachineRegisterClassAnalysis>(MF);
80 AMDGPUReserveWWMRegs(RCI).run(MF);
81 // RegisterClassInfo was updated in place, so it need not be abandoned.
83}
84
85bool AMDGPUReserveWWMRegs::run(MachineFunction &MF) {
87
88 bool Changed = false;
89 for (MachineBasicBlock &MBB : MF) {
90 for (MachineInstr &MI : MBB) {
91 unsigned Opc = MI.getOpcode();
92 if (Opc != AMDGPU::SI_SPILL_S32_TO_VGPR &&
93 Opc != AMDGPU::SI_RESTORE_S32_FROM_VGPR)
94 continue;
95
96 Register Reg = Opc == AMDGPU::SI_SPILL_S32_TO_VGPR
97 ? MI.getOperand(0).getReg()
98 : MI.getOperand(1).getReg();
99
100 assert(Reg.isPhysical() &&
101 "All WWM registers should have been allocated by now.");
102
103 MFI->reserveWWMRegister(Reg);
104 Changed |= true;
105 }
106 }
107
108 // The renamable flag can't be set for reserved registers. Reset the flag for
109 // MOs involving wwm-regs as they will be reserved during vgpr-regalloc
110 // pipeline.
111 const MachineRegisterInfo &MRI = MF.getRegInfo();
112 for (Register Reg : MFI->getWWMReservedRegs()) {
113 for (MachineOperand &MO : MRI.reg_operands(Reg))
114 MO.setIsRenamable(false);
115 }
116
117 // Now clear the PerLaneVGPRMask earlier set during wwm-regalloc.
119
120 // reserveWWMRegister() and clearPerLaneVGPRAllocMask() both feed
121 // getReservedRegs(): the WWM registers are now reserved, the per-lane VGPRs
122 // no longer are. Refresh the shared RegisterClassInfo, as the register
123 // allocator refreshes only its own copy. Do not freeze the set into MRI:
124 // LiveIntervals does not extend a reserved register's unit ranges to its
125 // uses, so unreserving the per-lane VGPRs here would fail verification.
127 RCI.updateReservedRegs(TRI->getReservedRegs(MF));
128
129 return Changed;
130}
assert(UImm &&(UImm !=~static_cast< T >(0)) &&"Invalid immediate!")
MachineBasicBlock & MBB
#define DEBUG_TYPE
IRTranslator LLVM IR MI
Register Reg
Register const TargetRegisterInfo * TRI
#define INITIALIZE_PASS_DEPENDENCY(depName)
Definition PassSupport.h:42
#define INITIALIZE_PASS_END(passName, arg, name, cfg, analysis)
Definition PassSupport.h:44
#define INITIALIZE_PASS_BEGIN(passName, arg, name, cfg, analysis)
Definition PassSupport.h:39
PreservedAnalyses run(MachineFunction &MF, MachineFunctionAnalysisManager &MFAM)
PassT::Result & getResult(IRUnitT &IR, ExtraArgTs... ExtraArgs)
Get the result of an analysis pass for a given IR unit.
Represent the analysis usage information of a pass.
AnalysisUsage & addRequired()
void setPreservesAll()
Set by analyses that do not transform their input at all.
MachineFunctionPass - This class adapts the FunctionPass interface to allow convenient creation of pa...
void getAnalysisUsage(AnalysisUsage &AU) const override
getAnalysisUsage - Subclasses that override getAnalysisUsage must call this.
Ty * getInfo()
getInfo - Keep track of various per-function pieces of information for backends that would like to do...
Representation of each machine instruction.
MachineOperand class - Representation of each machine instruction operand.
Result run(MachineFunction &, MachineFunctionAnalysisManager &)
MachineRegisterInfo - Keep track of information for virtual and physical registers,...
iterator_range< reg_iterator > reg_operands(Register Reg) const
const TargetRegisterInfo * getTargetRegisterInfo() const
A set of analyses that are preserved following a run of a transformation pass.
Definition Analysis.h:112
static PreservedAnalyses all()
Construct a special preserved set that preserves all passes.
Definition Analysis.h:118
Wrapper class representing virtual and physical registers.
Definition Register.h:20
This class keeps track of the SPI_SP_INPUT_ADDR config register, which tells the hardware which inter...
const ReservedRegSet & getWWMReservedRegs() const
Represent a constant reference to a string, i.e.
Definition StringRef.h:56
TargetRegisterInfo base class - We assume that the target defines a static array of TargetRegisterDes...
Changed
This is an optimization pass for GlobalISel generic memory operations.
char & AMDGPUReserveWWMRegsLegacyID
AnalysisManager< MachineFunction > MachineFunctionAnalysisManager