LLVM 20.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
17#include "AMDGPU.h"
23
24using namespace llvm;
25
26#define DEBUG_TYPE "amdgpu-reserve-wwm-regs"
27
28namespace {
29
30class AMDGPUReserveWWMRegs : public MachineFunctionPass {
31public:
32 static char ID;
33
34 AMDGPUReserveWWMRegs() : MachineFunctionPass(ID) {
36 }
37
38 bool runOnMachineFunction(MachineFunction &MF) override;
39
40 StringRef getPassName() const override {
41 return "AMDGPU Reserve WWM Registers";
42 }
43
44 void getAnalysisUsage(AnalysisUsage &AU) const override {
45 AU.setPreservesAll();
47 }
48};
49
50} // End anonymous namespace.
51
52INITIALIZE_PASS(AMDGPUReserveWWMRegs, DEBUG_TYPE,
53 "AMDGPU Reserve WWM Registers", false, false)
54
55char AMDGPUReserveWWMRegs::ID = 0;
56
57char &llvm::AMDGPUReserveWWMRegsID = AMDGPUReserveWWMRegs::ID;
58
59bool AMDGPUReserveWWMRegs::runOnMachineFunction(MachineFunction &MF) {
61
62 bool Changed = false;
63 for (MachineBasicBlock &MBB : MF) {
64 for (MachineInstr &MI : MBB) {
65 unsigned Opc = MI.getOpcode();
66 if (Opc != AMDGPU::SI_SPILL_S32_TO_VGPR &&
67 Opc != AMDGPU::SI_RESTORE_S32_FROM_VGPR)
68 continue;
69
70 Register Reg = Opc == AMDGPU::SI_SPILL_S32_TO_VGPR
71 ? MI.getOperand(0).getReg()
72 : MI.getOperand(1).getReg();
73
74 assert(Reg.isPhysical() &&
75 "All WWM registers should have been allocated by now.");
76
77 MFI->reserveWWMRegister(Reg);
78 Changed |= true;
79 }
80 }
81
82 // The renamable flag can't be set for reserved registers. Reset the flag for
83 // MOs involving wwm-regs as they will be reserved during vgpr-regalloc
84 // pipeline.
85 const MachineRegisterInfo &MRI = MF.getRegInfo();
86 for (Register Reg : MFI->getWWMReservedRegs()) {
87 for (MachineOperand &MO : MRI.reg_operands(Reg))
88 MO.setIsRenamable(false);
89 }
90
91 // Now clear the NonWWMRegMask earlier set during wwm-regalloc.
93
94 return Changed;
95}
unsigned const MachineRegisterInfo * MRI
Provides AMDGPU specific target descriptions.
#define DEBUG_TYPE
MachineBasicBlock & MBB
IRTranslator LLVM IR MI
#define INITIALIZE_PASS(passName, arg, name, cfg, analysis)
Definition: PassSupport.h:38
assert(ImpDefSCC.getReg()==AMDGPU::SCC &&ImpDefSCC.isDef())
Represent the analysis usage information of a pass.
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.
virtual bool runOnMachineFunction(MachineFunction &MF)=0
runOnMachineFunction - This method must be overloaded to perform the desired machine code transformat...
Representation of each machine instruction.
Definition: MachineInstr.h:69
MachineOperand class - Representation of each machine instruction operand.
MachineRegisterInfo - Keep track of information for virtual and physical registers,...
static PassRegistry * getPassRegistry()
getPassRegistry - Access the global registry object, which is automatically initialized at applicatio...
virtual StringRef getPassName() const
getPassName - Return a nice clean name for a pass.
Definition: Pass.cpp:81
Wrapper class representing virtual and physical registers.
Definition: Register.h:19
This class keeps track of the SPI_SP_INPUT_ADDR config register, which tells the hardware which inter...
const ReservedRegSet & getWWMReservedRegs() const
StringRef - Represent a constant reference to a string, i.e.
Definition: StringRef.h:51
unsigned ID
LLVM IR allows to use arbitrary numbers as calling convention identifiers.
Definition: CallingConv.h:24
Reg
All possible values of the reg field in the ModR/M byte.
This is an optimization pass for GlobalISel generic memory operations.
Definition: AddressRanges.h:18
void initializeAMDGPUReserveWWMRegsPass(PassRegistry &)
char & AMDGPUReserveWWMRegsID