]> CyberLeo.Net >> Repos - FreeBSD/FreeBSD.git/blob - contrib/llvm/lib/Target/AMDGPU/SIRegisterInfo.h
Merge ^/head r320398 through r320572.
[FreeBSD/FreeBSD.git] / contrib / llvm / lib / Target / AMDGPU / SIRegisterInfo.h
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"
19 #include "MCTargetDesc/AMDGPUMCTargetDesc.h"
20 #include "SIDefines.h"
21 #include "llvm/CodeGen/MachineRegisterInfo.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:
42   SIRegisterInfo(const SISubtarget &ST);
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.
58   unsigned reservedPrivateSegmentWaveByteOffsetReg(
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;
66   const uint32_t *getCallPreservedMask(const MachineFunction &MF,
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;
80   bool requiresFrameIndexReplacementScavenging(
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
87   int64_t getFrameIndexInstrOffset(const MachineInstr *MI,
88                                    int Idx) const override;
89
90   bool needsFrameBaseReg(MachineInstr *MI, int64_t Offset) const override;
91
92   void materializeFrameBaseRegister(MachineBasicBlock *MBB,
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
102   const TargetRegisterClass *getPointerRegClass(
103     const MachineFunction &MF, unsigned Kind = 0) const override;
104
105   /// If \p OnlyToVGPR is true, this will only succeed if this
106   bool spillSGPR(MachineBasicBlock::iterator MI,
107                  int FI, RegScavenger *RS,
108                  bool OnlyToVGPR = false) const;
109
110   bool restoreSGPR(MachineBasicBlock::iterator MI,
111                    int FI, RegScavenger *RS,
112                    bool OnlyToVGPR = false) const;
113
114   void eliminateFrameIndex(MachineBasicBlock::iterator MI, int SPAdj,
115                            unsigned FIOperandNum,
116                            RegScavenger *RS) const override;
117
118   bool eliminateSGPRToVGPRSpillFrameIndex(MachineBasicBlock::iterator MI,
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;
143     if (TargetRegisterInfo::isVirtualRegister(Reg))
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
154   const TargetRegisterClass *getEquivalentVGPRClass(
155                                           const TargetRegisterClass *SRC) const;
156
157   /// \returns A SGPR reg class with the same width as \p SRC
158   const TargetRegisterClass *getEquivalentSGPRClass(
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.
164   const TargetRegisterClass *getSubRegClass(const TargetRegisterClass *RC,
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 &&
177            OpType <= AMDGPU::OPERAND_REG_IMM_LAST;
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
188   enum PreloadedValue {
189     // SGPRS:
190     PRIVATE_SEGMENT_BUFFER = 0,
191     DISPATCH_PTR        =  1,
192     QUEUE_PTR           =  2,
193     KERNARG_SEGMENT_PTR =  3,
194     DISPATCH_ID         =  4,
195     FLAT_SCRATCH_INIT   =  5,
196     WORKGROUP_ID_X      = 10,
197     WORKGROUP_ID_Y      = 11,
198     WORKGROUP_ID_Z      = 12,
199     PRIVATE_SEGMENT_WAVE_BYTE_OFFSET = 14,
200     IMPLICIT_BUFFER_PTR = 15,
201
202     // VGPRS:
203     FIRST_VGPR_VALUE    = 16,
204     WORKITEM_ID_X       = FIRST_VGPR_VALUE,
205     WORKITEM_ID_Y       = 17,
206     WORKITEM_ID_Z       = 18
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
213   unsigned findUnusedRegister(const MachineRegisterInfo &MRI,
214                               const TargetRegisterClass *RC,
215                               const MachineFunction &MF) const;
216
217   unsigned getSGPRPressureSet() const { return SGPRSetID; };
218   unsigned getVGPRPressureSet() const { return VGPRSetID; };
219
220   const TargetRegisterClass *getRegClassForReg(const MachineRegisterInfo &MRI,
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
231   ArrayRef<int16_t> getRegSplitParts(const TargetRegisterClass *RC,
232                                      unsigned EltSize) const;
233
234   bool shouldCoalesce(MachineInstr *MI,
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