LLVM  5.0.0
SIRegisterInfo.h
Go to the documentation of this file.
1 //===-- SIRegisterInfo.h - SI Register Info Interface ----------*- C++ -*--===//
2 //
3 // The LLVM Compiler Infrastructure
4 //
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
7 //
8 //===----------------------------------------------------------------------===//
9 //
10 /// \file
11 /// \brief Interface definition for SIRegisterInfo
12 //
13 //===----------------------------------------------------------------------===//
14 
15 #ifndef LLVM_LIB_TARGET_AMDGPU_SIREGISTERINFO_H
16 #define LLVM_LIB_TARGET_AMDGPU_SIREGISTERINFO_H
17 
18 #include "AMDGPURegisterInfo.h"
20 #include "SIDefines.h"
22 
23 namespace llvm {
24 
25 class MachineRegisterInfo;
26 class SISubtarget;
27 class SIMachineFunctionInfo;
28 
29 class SIRegisterInfo final : public AMDGPURegisterInfo {
30 private:
31  unsigned SGPRSetID;
32  unsigned VGPRSetID;
33  BitVector SGPRPressureSets;
34  BitVector VGPRPressureSets;
35  bool SpillSGPRToVGPR;
36  bool SpillSGPRToSMEM;
37 
38  void reserveRegisterTuples(BitVector &, unsigned Reg) const;
39  void classifyPressureSet(unsigned PSetID, unsigned Reg,
40  BitVector &PressureSets) const;
41 public:
43 
44  bool spillSGPRToVGPR() const {
45  return SpillSGPRToVGPR;
46  }
47 
48  bool spillSGPRToSMEM() const {
49  return SpillSGPRToSMEM;
50  }
51 
52  /// Return the end register initially reserved for the scratch buffer in case
53  /// spilling is needed.
54  unsigned reservedPrivateSegmentBufferReg(const MachineFunction &MF) const;
55 
56  /// Return the end register initially reserved for the scratch wave offset in
57  /// case spilling is needed.
59  const MachineFunction &MF) const;
60 
61  unsigned reservedStackPtrOffsetReg(const MachineFunction &MF) const;
62 
63  BitVector getReservedRegs(const MachineFunction &MF) const override;
64 
65  const MCPhysReg *getCalleeSavedRegs(const MachineFunction *MF) const override;
67  CallingConv::ID) const override;
68 
69  // Stack access is very expensive. CSRs are also the high registers, and we
70  // want to minimize the number of used registers.
71  unsigned getCSRFirstUseCost() const override {
72  return 100;
73  }
74 
75  unsigned getFrameRegister(const MachineFunction &MF) const override;
76 
77  bool requiresRegisterScavenging(const MachineFunction &Fn) const override;
78 
79  bool requiresFrameIndexScavenging(const MachineFunction &MF) const override;
81  const MachineFunction &MF) const override;
82  bool requiresVirtualBaseRegisters(const MachineFunction &Fn) const override;
83  bool trackLivenessAfterRegAlloc(const MachineFunction &MF) const override;
84 
85  int64_t getMUBUFInstrOffset(const MachineInstr *MI) const;
86 
88  int Idx) const override;
89 
90  bool needsFrameBaseReg(MachineInstr *MI, int64_t Offset) const override;
91 
93  unsigned BaseReg, int FrameIdx,
94  int64_t Offset) const override;
95 
96  void resolveFrameIndex(MachineInstr &MI, unsigned BaseReg,
97  int64_t Offset) const override;
98 
99  bool isFrameOffsetLegal(const MachineInstr *MI, unsigned BaseReg,
100  int64_t Offset) const override;
101 
103  const MachineFunction &MF, unsigned Kind = 0) const override;
104 
105  /// If \p OnlyToVGPR is true, this will only succeed if this
107  int FI, RegScavenger *RS,
108  bool OnlyToVGPR = false) const;
109 
111  int FI, RegScavenger *RS,
112  bool OnlyToVGPR = false) const;
113 
115  unsigned FIOperandNum,
116  RegScavenger *RS) const override;
117 
119  int FI, RegScavenger *RS) const;
120 
121  StringRef getRegAsmName(unsigned Reg) const override;
122 
123  unsigned getHWRegIndex(unsigned Reg) const {
124  return getEncodingValue(Reg) & 0xff;
125  }
126 
127  /// \brief Return the 'base' register class for this register.
128  /// e.g. SGPR0 => SReg_32, VGPR => VGPR_32 SGPR0_SGPR1 -> SReg_32, etc.
129  const TargetRegisterClass *getPhysRegClass(unsigned Reg) const;
130 
131  /// \returns true if this class contains only SGPR registers
132  bool isSGPRClass(const TargetRegisterClass *RC) const {
133  return !hasVGPRs(RC);
134  }
135 
136  /// \returns true if this class ID contains only SGPR registers
137  bool isSGPRClassID(unsigned RCID) const {
138  return isSGPRClass(getRegClass(RCID));
139  }
140 
141  bool isSGPRReg(const MachineRegisterInfo &MRI, unsigned Reg) const {
142  const TargetRegisterClass *RC;
144  RC = MRI.getRegClass(Reg);
145  else
146  RC = getPhysRegClass(Reg);
147  return isSGPRClass(RC);
148  }
149 
150  /// \returns true if this class contains VGPR registers.
151  bool hasVGPRs(const TargetRegisterClass *RC) const;
152 
153  /// \returns A VGPR reg class with the same width as \p SRC
155  const TargetRegisterClass *SRC) const;
156 
157  /// \returns A SGPR reg class with the same width as \p SRC
159  const TargetRegisterClass *VRC) const;
160 
161  /// \returns The register class that is used for a sub-register of \p RC for
162  /// the given \p SubIdx. If \p SubIdx equals NoSubRegister, \p RC will
163  /// be returned.
165  unsigned SubIdx) const;
166 
167  bool shouldRewriteCopySrc(const TargetRegisterClass *DefRC,
168  unsigned DefSubReg,
169  const TargetRegisterClass *SrcRC,
170  unsigned SrcSubReg) const override;
171 
172  /// \returns True if operands defined with this operand type can accept
173  /// a literal constant (i.e. any 32-bit immediate).
174  bool opCanUseLiteralConstant(unsigned OpType) const {
175  // TODO: 64-bit operands have extending behavior from 32-bit literal.
176  return OpType >= AMDGPU::OPERAND_REG_IMM_FIRST &&
178  }
179 
180  /// \returns True if operands defined with this operand type can accept
181  /// an inline constant. i.e. An integer value in the range (-16, 64) or
182  /// -4.0f, -2.0f, -1.0f, -0.5f, 0.0f, 0.5f, 1.0f, 2.0f, 4.0f.
183  bool opCanUseInlineConstant(unsigned OpType) const {
184  return OpType >= AMDGPU::OPERAND_SRC_FIRST &&
185  OpType <= AMDGPU::OPERAND_SRC_LAST;
186  }
187 
189  // SGPRS:
201 
202  // VGPRS:
207  };
208 
209  /// \brief Returns the physical register that \p Value is stored in.
210  unsigned getPreloadedValue(const MachineFunction &MF,
211  enum PreloadedValue Value) const;
212 
214  const TargetRegisterClass *RC,
215  const MachineFunction &MF) const;
216 
217  unsigned getSGPRPressureSet() const { return SGPRSetID; };
218  unsigned getVGPRPressureSet() const { return VGPRSetID; };
219 
221  unsigned Reg) const;
222  bool isVGPR(const MachineRegisterInfo &MRI, unsigned Reg) const;
223 
224  bool isSGPRPressureSet(unsigned SetID) const {
225  return SGPRPressureSets.test(SetID) && !VGPRPressureSets.test(SetID);
226  }
227  bool isVGPRPressureSet(unsigned SetID) const {
228  return VGPRPressureSets.test(SetID) && !SGPRPressureSets.test(SetID);
229  }
230 
232  unsigned EltSize) const;
233 
235  const TargetRegisterClass *SrcRC,
236  unsigned SubReg,
237  const TargetRegisterClass *DstRC,
238  unsigned DstSubReg,
239  const TargetRegisterClass *NewRC) const override;
240 
241  unsigned getRegPressureLimit(const TargetRegisterClass *RC,
242  MachineFunction &MF) const override;
243 
244  unsigned getRegPressureSetLimit(const MachineFunction &MF,
245  unsigned Idx) const override;
246 
247  const int *getRegUnitPressureSets(unsigned RegUnit) const override;
248 
249  unsigned getReturnAddressReg(const MachineFunction &MF) const {
250  // Not a callee saved register.
251  return AMDGPU::SGPR30_SGPR31;
252  }
253 
254 private:
255  void buildSpillLoadStore(MachineBasicBlock::iterator MI,
256  unsigned LoadStoreOp,
257  int Index,
258  unsigned ValueReg,
259  bool ValueIsKill,
260  unsigned ScratchRsrcReg,
261  unsigned ScratchOffsetReg,
262  int64_t InstrOffset,
263  MachineMemOperand *MMO,
264  RegScavenger *RS) const;
265 };
266 
267 } // End namespace llvm
268 
269 #endif
const MCPhysReg * getCalleeSavedRegs(const MachineFunction *MF) const override
void materializeFrameBaseRegister(MachineBasicBlock *MBB, unsigned BaseReg, int FrameIdx, int64_t Offset) const override
bool eliminateSGPRToVGPRSpillFrameIndex(MachineBasicBlock::iterator MI, int FI, RegScavenger *RS) const
Special case of eliminateFrameIndex.
bool requiresRegisterScavenging(const MachineFunction &Fn) const override
unsigned reservedStackPtrOffsetReg(const MachineFunction &MF) const
bool spillSGPRToSMEM() const
SIRegisterInfo(const SISubtarget &ST)
ArrayRef< int16_t > getRegSplitParts(const TargetRegisterClass *RC, unsigned EltSize) const
bool trackLivenessAfterRegAlloc(const MachineFunction &MF) const override
bool opCanUseInlineConstant(unsigned OpType) const
bool isVGPR(const MachineRegisterInfo &MRI, unsigned Reg) const
unsigned getRegPressureLimit(const TargetRegisterClass *RC, MachineFunction &MF) const override
bool isFrameOffsetLegal(const MachineInstr *MI, unsigned BaseReg, int64_t Offset) const override
StringRef getRegAsmName(unsigned Reg) const override
bool isSGPRPressureSet(unsigned SetID) const
const uint32_t * getCallPreservedMask(const MachineFunction &MF, CallingConv::ID) const override
static bool isVirtualRegister(unsigned Reg)
Return true if the specified register number is in the virtual register namespace.
const TargetRegisterClass * getRegClassForReg(const MachineRegisterInfo &MRI, unsigned Reg) const
bool requiresVirtualBaseRegisters(const MachineFunction &Fn) const override
bool isSGPRClass(const TargetRegisterClass *RC) const
int64_t getFrameIndexInstrOffset(const MachineInstr *MI, int Idx) const override
void resolveFrameIndex(MachineInstr &MI, unsigned BaseReg, int64_t Offset) const override
bool spillSGPRToVGPR() const
const TargetRegisterClass * getSubRegClass(const TargetRegisterClass *RC, unsigned SubIdx) const
unsigned getHWRegIndex(unsigned Reg) const
bool requiresFrameIndexScavenging(const MachineFunction &MF) const override
unsigned reservedPrivateSegmentWaveByteOffsetReg(const MachineFunction &MF) const
Return the end register initially reserved for the scratch wave offset in case spilling is needed...
A description of a memory reference used in the backend.
bool needsFrameBaseReg(MachineInstr *MI, int64_t Offset) const override
unsigned SubReg
const TargetRegisterClass * getRegClass(unsigned Reg) const
Return the register class of the specified virtual register.
Reg
All possible values of the reg field in the ModR/M byte.
static int getRegClass(RegisterKind Is, unsigned RegWidth)
bool opCanUseLiteralConstant(unsigned OpType) const
TargetRegisterInfo interface that is implemented by all hw codegen targets.
bool shouldRewriteCopySrc(const TargetRegisterClass *DefRC, unsigned DefSubReg, const TargetRegisterClass *SrcRC, unsigned SrcSubReg) const override
int64_t getMUBUFInstrOffset(const MachineInstr *MI) const
ArrayRef - Represent a constant reference to an array (0 or more elements consecutively in memory)...
Definition: APInt.h:33
unsigned getCSRFirstUseCost() const override
bool requiresFrameIndexReplacementScavenging(const MachineFunction &MF) const override
const int * getRegUnitPressureSets(unsigned RegUnit) const override
unsigned getVGPRPressureSet() const
uint16_t MCPhysReg
An unsigned integer type large enough to represent all physical registers, but not necessarily virtua...
bool restoreSGPR(MachineBasicBlock::iterator MI, int FI, RegScavenger *RS, bool OnlyToVGPR=false) const
const TargetRegisterClass * getEquivalentVGPRClass(const TargetRegisterClass *SRC) const
unsigned const MachineRegisterInfo * MRI
unsigned getFrameRegister(const MachineFunction &MF) const override
bool hasVGPRs(const TargetRegisterClass *RC) const
unsigned getPreloadedValue(const MachineFunction &MF, enum PreloadedValue Value) const
Returns the physical register that Value is stored in.
bool shouldCoalesce(MachineInstr *MI, const TargetRegisterClass *SrcRC, unsigned SubReg, const TargetRegisterClass *DstRC, unsigned DstSubReg, const TargetRegisterClass *NewRC) const override
const TargetRegisterClass * getEquivalentSGPRClass(const TargetRegisterClass *VRC) const
bool isSGPRClassID(unsigned RCID) const
void eliminateFrameIndex(MachineBasicBlock::iterator MI, int SPAdj, unsigned FIOperandNum, RegScavenger *RS) const override
BitVector getReservedRegs(const MachineFunction &MF) const override
unsigned getReturnAddressReg(const MachineFunction &MF) const
unsigned getRegPressureSetLimit(const MachineFunction &MF, unsigned Idx) const override
bool test(unsigned Idx) const
Definition: BitVector.h:502
bool isSGPRReg(const MachineRegisterInfo &MRI, unsigned Reg) const
const TargetRegisterClass * getPhysRegClass(unsigned Reg) const
Return the 'base' register class for this register.
MachineRegisterInfo - Keep track of information for virtual and physical registers, including vreg register classes, use/def chains for registers, etc.
Provides AMDGPU specific target descriptions.
Representation of each machine instruction.
Definition: MachineInstr.h:59
unsigned findUnusedRegister(const MachineRegisterInfo &MRI, const TargetRegisterClass *RC, const MachineFunction &MF) const
Returns a register that is not used at any point in the function.
const TargetRegisterClass * getPointerRegClass(const MachineFunction &MF, unsigned Kind=0) const override
unsigned getSGPRPressureSet() const
const unsigned Kind
bool isVGPRPressureSet(unsigned SetID) const
bool spillSGPR(MachineBasicBlock::iterator MI, int FI, RegScavenger *RS, bool OnlyToVGPR=false) const
If OnlyToVGPR is true, this will only succeed if this.
LLVM Value Representation.
Definition: Value.h:73
unsigned reservedPrivateSegmentBufferReg(const MachineFunction &MF) const
Return the end register initially reserved for the scratch buffer in case spilling is needed...
IRTranslator LLVM IR MI
StringRef - Represent a constant reference to a string, i.e.
Definition: StringRef.h:49