1 //===-- SIRegisterInfo.h - SI Register Info Interface ----------*- C++ -*--===//
3 // The LLVM Compiler Infrastructure
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
8 //===----------------------------------------------------------------------===//
11 /// \brief Interface definition for SIRegisterInfo
13 //===----------------------------------------------------------------------===//
15 #ifndef LLVM_LIB_TARGET_AMDGPU_SIREGISTERINFO_H
16 #define LLVM_LIB_TARGET_AMDGPU_SIREGISTERINFO_H
18 #include "AMDGPURegisterInfo.h"
19 #include "llvm/CodeGen/MachineRegisterInfo.h"
24 class MachineRegisterInfo;
26 class SIRegisterInfo final : public AMDGPURegisterInfo {
30 BitVector SGPRPressureSets;
31 BitVector VGPRPressureSets;
33 void reserveRegisterTuples(BitVector &, unsigned Reg) const;
34 void classifyPressureSet(unsigned PSetID, unsigned Reg,
35 BitVector &PressureSets) const;
40 /// Return the end register initially reserved for the scratch buffer in case
41 /// spilling is needed.
42 unsigned reservedPrivateSegmentBufferReg(const MachineFunction &MF) const;
44 /// Return the end register initially reserved for the scratch wave offset in
45 /// case spilling is needed.
46 unsigned reservedPrivateSegmentWaveByteOffsetReg(
47 const MachineFunction &MF) const;
49 BitVector getReservedRegs(const MachineFunction &MF) const override;
51 bool requiresRegisterScavenging(const MachineFunction &Fn) const override;
54 bool requiresFrameIndexScavenging(const MachineFunction &MF) const override;
55 bool requiresVirtualBaseRegisters(const MachineFunction &Fn) const override;
56 bool trackLivenessAfterRegAlloc(const MachineFunction &MF) const override;
58 int64_t getFrameIndexInstrOffset(const MachineInstr *MI,
59 int Idx) const override;
61 bool needsFrameBaseReg(MachineInstr *MI, int64_t Offset) const override;
63 void materializeFrameBaseRegister(MachineBasicBlock *MBB,
64 unsigned BaseReg, int FrameIdx,
65 int64_t Offset) const override;
67 void resolveFrameIndex(MachineInstr &MI, unsigned BaseReg,
68 int64_t Offset) const override;
70 bool isFrameOffsetLegal(const MachineInstr *MI, unsigned BaseReg,
71 int64_t Offset) const override;
73 const TargetRegisterClass *getPointerRegClass(
74 const MachineFunction &MF, unsigned Kind = 0) const override;
76 void spillSGPR(MachineBasicBlock::iterator MI,
77 int FI, RegScavenger *RS) const;
79 void restoreSGPR(MachineBasicBlock::iterator MI,
80 int FI, RegScavenger *RS) const;
82 void eliminateFrameIndex(MachineBasicBlock::iterator MI, int SPAdj,
83 unsigned FIOperandNum,
84 RegScavenger *RS) const override;
86 unsigned getHWRegIndex(unsigned Reg) const {
87 return getEncodingValue(Reg) & 0xff;
90 /// \brief Return the 'base' register class for this register.
91 /// e.g. SGPR0 => SReg_32, VGPR => VGPR_32 SGPR0_SGPR1 -> SReg_32, etc.
92 const TargetRegisterClass *getPhysRegClass(unsigned Reg) const;
94 /// \returns true if this class contains only SGPR registers
95 bool isSGPRClass(const TargetRegisterClass *RC) const {
99 /// \returns true if this class ID contains only SGPR registers
100 bool isSGPRClassID(unsigned RCID) const {
101 return isSGPRClass(getRegClass(RCID));
104 bool isSGPRReg(const MachineRegisterInfo &MRI, unsigned Reg) const {
105 const TargetRegisterClass *RC;
106 if (TargetRegisterInfo::isVirtualRegister(Reg))
107 RC = MRI.getRegClass(Reg);
109 RC = getPhysRegClass(Reg);
110 return isSGPRClass(RC);
113 /// \returns true if this class contains VGPR registers.
114 bool hasVGPRs(const TargetRegisterClass *RC) const;
116 /// \returns A VGPR reg class with the same width as \p SRC
117 const TargetRegisterClass *getEquivalentVGPRClass(
118 const TargetRegisterClass *SRC) const;
120 /// \returns A SGPR reg class with the same width as \p SRC
121 const TargetRegisterClass *getEquivalentSGPRClass(
122 const TargetRegisterClass *VRC) const;
124 /// \returns The register class that is used for a sub-register of \p RC for
125 /// the given \p SubIdx. If \p SubIdx equals NoSubRegister, \p RC will
127 const TargetRegisterClass *getSubRegClass(const TargetRegisterClass *RC,
128 unsigned SubIdx) const;
130 bool shouldRewriteCopySrc(const TargetRegisterClass *DefRC,
132 const TargetRegisterClass *SrcRC,
133 unsigned SrcSubReg) const override;
135 /// \returns True if operands defined with this operand type can accept
136 /// a literal constant (i.e. any 32-bit immediate).
137 bool opCanUseLiteralConstant(unsigned OpType) const;
139 /// \returns True if operands defined with this operand type can accept
140 /// an inline constant. i.e. An integer value in the range (-16, 64) or
141 /// -4.0f, -2.0f, -1.0f, -0.5f, 0.0f, 0.5f, 1.0f, 2.0f, 4.0f.
142 bool opCanUseInlineConstant(unsigned OpType) const;
144 enum PreloadedValue {
146 PRIVATE_SEGMENT_BUFFER = 0,
149 KERNARG_SEGMENT_PTR = 3,
151 FLAT_SCRATCH_INIT = 5,
155 PRIVATE_SEGMENT_WAVE_BYTE_OFFSET = 14,
158 FIRST_VGPR_VALUE = 15,
159 WORKITEM_ID_X = FIRST_VGPR_VALUE,
164 /// \brief Returns the physical register that \p Value is stored in.
165 unsigned getPreloadedValue(const MachineFunction &MF,
166 enum PreloadedValue Value) const;
168 unsigned findUnusedRegister(const MachineRegisterInfo &MRI,
169 const TargetRegisterClass *RC,
170 const MachineFunction &MF) const;
172 unsigned getSGPRPressureSet() const { return SGPRSetID; };
173 unsigned getVGPRPressureSet() const { return VGPRSetID; };
175 const TargetRegisterClass *getRegClassForReg(const MachineRegisterInfo &MRI,
177 bool isVGPR(const MachineRegisterInfo &MRI, unsigned Reg) const;
179 bool isSGPRPressureSet(unsigned SetID) const {
180 return SGPRPressureSets.test(SetID) && !VGPRPressureSets.test(SetID);
182 bool isVGPRPressureSet(unsigned SetID) const {
183 return VGPRPressureSets.test(SetID) && !SGPRPressureSets.test(SetID);
186 /// \returns SGPR allocation granularity supported by the subtarget.
187 unsigned getSGPRAllocGranule() const {
191 /// \returns Total number of SGPRs supported by the subtarget.
192 unsigned getTotalNumSGPRs(const SISubtarget &ST) const;
194 /// \returns Number of addressable SGPRs supported by the subtarget.
195 unsigned getNumAddressableSGPRs(const SISubtarget &ST) const;
197 /// \returns Number of reserved SGPRs supported by the subtarget.
198 unsigned getNumReservedSGPRs(const SISubtarget &ST) const;
200 /// \returns Minimum number of SGPRs that meets given number of waves per
201 /// execution unit requirement for given subtarget.
202 unsigned getMinNumSGPRs(const SISubtarget &ST, unsigned WavesPerEU) const;
204 /// \returns Maximum number of SGPRs that meets given number of waves per
205 /// execution unit requirement for given subtarget.
206 unsigned getMaxNumSGPRs(const SISubtarget &ST, unsigned WavesPerEU) const;
208 /// \returns Maximum number of SGPRs that meets number of waves per execution
209 /// unit requirement for function \p MF, or number of SGPRs explicitly
210 /// requested using "amdgpu-num-sgpr" attribute attached to function \p MF.
212 /// \returns Value that meets number of waves per execution unit requirement
213 /// if explicitly requested value cannot be converted to integer, violates
214 /// subtarget's specifications, or does not meet number of waves per execution
215 /// unit requirement.
216 unsigned getMaxNumSGPRs(const MachineFunction &MF) const;
218 /// \returns VGPR allocation granularity supported by the subtarget.
219 unsigned getVGPRAllocGranule() const {
223 /// \returns Total number of VGPRs supported by the subtarget.
224 unsigned getTotalNumVGPRs() const {
228 /// \returns Number of reserved VGPRs for debugger use supported by the
230 unsigned getNumDebuggerReservedVGPRs(const SISubtarget &ST) const;
232 /// \returns Minimum number of SGPRs that meets given number of waves per
233 /// execution unit requirement.
234 unsigned getMinNumVGPRs(unsigned WavesPerEU) const;
236 /// \returns Maximum number of VGPRs that meets given number of waves per
237 /// execution unit requirement.
238 unsigned getMaxNumVGPRs(unsigned WavesPerEU) const;
240 /// \returns Maximum number of VGPRs that meets number of waves per execution
241 /// unit requirement for function \p MF, or number of VGPRs explicitly
242 /// requested using "amdgpu-num-vgpr" attribute attached to function \p MF.
244 /// \returns Value that meets number of waves per execution unit requirement
245 /// if explicitly requested value cannot be converted to integer, violates
246 /// subtarget's specifications, or does not meet number of waves per execution
247 /// unit requirement.
248 unsigned getMaxNumVGPRs(const MachineFunction &MF) const;
250 ArrayRef<int16_t> getRegSplitParts(const TargetRegisterClass *RC,
251 unsigned EltSize) const;
254 void buildSpillLoadStore(MachineBasicBlock::iterator MI,
255 unsigned LoadStoreOp, const MachineOperand *SrcDst,
256 unsigned ScratchRsrcReg, unsigned ScratchOffset,
258 RegScavenger *RS) const;
261 } // End namespace llvm