LLVM 22.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"
23
24using namespace llvm;
25
26#define DEBUG_TYPE "amdgpu-reserve-wwm-regs"
27
28namespace {
29
30class AMDGPUReserveWWMRegsLegacy : public MachineFunctionPass {
31public:
32 static char ID;
33
34 AMDGPUReserveWWMRegsLegacy() : MachineFunctionPass(ID) {}
35
36 bool runOnMachineFunction(MachineFunction &MF) override;
37
38 StringRef getPassName() const override {
39 return "AMDGPU Reserve WWM Registers";
40 }
41
42 void getAnalysisUsage(AnalysisUsage &AU) const override {
43 AU.setPreservesAll();
45 }
46};
47
48class AMDGPUReserveWWMRegs {
49public:
50 bool run(MachineFunction &MF);
51};
52
53} // End anonymous namespace.
54
55INITIALIZE_PASS(AMDGPUReserveWWMRegsLegacy, DEBUG_TYPE,
56 "AMDGPU Reserve WWM Registers", false, false)
57
58char AMDGPUReserveWWMRegsLegacy::ID = 0;
59
60char &llvm::AMDGPUReserveWWMRegsLegacyID = AMDGPUReserveWWMRegsLegacy::ID;
61
62bool AMDGPUReserveWWMRegsLegacy::runOnMachineFunction(MachineFunction &MF) {
63 return AMDGPUReserveWWMRegs().run(MF);
64}
65
69 AMDGPUReserveWWMRegs().run(MF);
70 // TODO: This should abandon RegisterClassInfo once it is turned into an
71 // analysis.
73}
74
75bool AMDGPUReserveWWMRegs::run(MachineFunction &MF) {
77
78 bool Changed = false;
79 for (MachineBasicBlock &MBB : MF) {
80 for (MachineInstr &MI : MBB) {
81 unsigned Opc = MI.getOpcode();
82 if (Opc != AMDGPU::SI_SPILL_S32_TO_VGPR &&
83 Opc != AMDGPU::SI_RESTORE_S32_FROM_VGPR)
84 continue;
85
86 Register Reg = Opc == AMDGPU::SI_SPILL_S32_TO_VGPR
87 ? MI.getOperand(0).getReg()
88 : MI.getOperand(1).getReg();
89
90 assert(Reg.isPhysical() &&
91 "All WWM registers should have been allocated by now.");
92
93 MFI->reserveWWMRegister(Reg);
94 Changed |= true;
95 }
96 }
97
98 // The renamable flag can't be set for reserved registers. Reset the flag for
99 // MOs involving wwm-regs as they will be reserved during vgpr-regalloc
100 // pipeline.
101 const MachineRegisterInfo &MRI = MF.getRegInfo();
102 for (Register Reg : MFI->getWWMReservedRegs()) {
103 for (MachineOperand &MO : MRI.reg_operands(Reg))
104 MO.setIsRenamable(false);
105 }
106
107 // Now clear the NonWWMRegMask earlier set during wwm-regalloc.
109
110 return Changed;
111}
unsigned const MachineRegisterInfo * MRI
assert(UImm &&(UImm !=~static_cast< T >(0)) &&"Invalid immediate!")
Provides AMDGPU specific target descriptions.
MachineBasicBlock & MBB
#define DEBUG_TYPE
IRTranslator LLVM IR MI
Register Reg
#define INITIALIZE_PASS(passName, arg, name, cfg, analysis)
Definition PassSupport.h:56
PreservedAnalyses run(MachineFunction &MF, MachineFunctionAnalysisManager &MFAM)
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.
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.
MachineRegisterInfo - Keep track of information for virtual and physical registers,...
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: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:55
Changed
unsigned ID
LLVM IR allows to use arbitrary numbers as calling convention identifiers.
Definition CallingConv.h:24
This is an optimization pass for GlobalISel generic memory operations.
char & AMDGPUReserveWWMRegsLegacyID
AnalysisManager< MachineFunction > MachineFunctionAnalysisManager