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