]> CyberLeo.Net >> Repos - FreeBSD/FreeBSD.git/blob - contrib/llvm/lib/Target/AMDGPU/SIRegisterInfo.h
Merge llvm, clang, lld, lldb, compiler-rt and libc++ r303571, and update
[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 "SIDefines.h"
20 #include "MCTargetDesc/AMDGPUMCTargetDesc.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   unsigned getFrameRegister(const MachineFunction &MF) const override;
70
71   bool requiresRegisterScavenging(const MachineFunction &Fn) const override;
72
73   bool requiresFrameIndexScavenging(const MachineFunction &MF) const override;
74   bool requiresFrameIndexReplacementScavenging(
75     const MachineFunction &MF) const override;
76   bool requiresVirtualBaseRegisters(const MachineFunction &Fn) const override;
77   bool trackLivenessAfterRegAlloc(const MachineFunction &MF) const override;
78
79   int64_t getMUBUFInstrOffset(const MachineInstr *MI) const;
80
81   int64_t getFrameIndexInstrOffset(const MachineInstr *MI,
82                                    int Idx) const override;
83
84   bool needsFrameBaseReg(MachineInstr *MI, int64_t Offset) const override;
85
86   void materializeFrameBaseRegister(MachineBasicBlock *MBB,
87                                     unsigned BaseReg, int FrameIdx,
88                                     int64_t Offset) const override;
89
90   void resolveFrameIndex(MachineInstr &MI, unsigned BaseReg,
91                          int64_t Offset) const override;
92
93   bool isFrameOffsetLegal(const MachineInstr *MI, unsigned BaseReg,
94                           int64_t Offset) const override;
95
96   const TargetRegisterClass *getPointerRegClass(
97     const MachineFunction &MF, unsigned Kind = 0) const override;
98
99   /// If \p OnlyToVGPR is true, this will only succeed if this
100   bool spillSGPR(MachineBasicBlock::iterator MI,
101                  int FI, RegScavenger *RS,
102                  bool OnlyToVGPR = false) const;
103
104   bool restoreSGPR(MachineBasicBlock::iterator MI,
105                    int FI, RegScavenger *RS,
106                    bool OnlyToVGPR = false) const;
107
108   void eliminateFrameIndex(MachineBasicBlock::iterator MI, int SPAdj,
109                            unsigned FIOperandNum,
110                            RegScavenger *RS) const override;
111
112   bool eliminateSGPRToVGPRSpillFrameIndex(MachineBasicBlock::iterator MI,
113                                           int FI, RegScavenger *RS) const;
114
115   unsigned getHWRegIndex(unsigned Reg) const {
116     return getEncodingValue(Reg) & 0xff;
117   }
118
119   /// \brief Return the 'base' register class for this register.
120   /// e.g. SGPR0 => SReg_32, VGPR => VGPR_32 SGPR0_SGPR1 -> SReg_32, etc.
121   const TargetRegisterClass *getPhysRegClass(unsigned Reg) const;
122
123   /// \returns true if this class contains only SGPR registers
124   bool isSGPRClass(const TargetRegisterClass *RC) const {
125     return !hasVGPRs(RC);
126   }
127
128   /// \returns true if this class ID contains only SGPR registers
129   bool isSGPRClassID(unsigned RCID) const {
130     return isSGPRClass(getRegClass(RCID));
131   }
132
133   bool isSGPRReg(const MachineRegisterInfo &MRI, unsigned Reg) const {
134     const TargetRegisterClass *RC;
135     if (TargetRegisterInfo::isVirtualRegister(Reg))
136       RC = MRI.getRegClass(Reg);
137     else
138       RC = getPhysRegClass(Reg);
139     return isSGPRClass(RC);
140   }
141
142   /// \returns true if this class contains VGPR registers.
143   bool hasVGPRs(const TargetRegisterClass *RC) const;
144
145   /// \returns A VGPR reg class with the same width as \p SRC
146   const TargetRegisterClass *getEquivalentVGPRClass(
147                                           const TargetRegisterClass *SRC) const;
148
149   /// \returns A SGPR reg class with the same width as \p SRC
150   const TargetRegisterClass *getEquivalentSGPRClass(
151                                            const TargetRegisterClass *VRC) const;
152
153   /// \returns The register class that is used for a sub-register of \p RC for
154   /// the given \p SubIdx.  If \p SubIdx equals NoSubRegister, \p RC will
155   /// be returned.
156   const TargetRegisterClass *getSubRegClass(const TargetRegisterClass *RC,
157                                             unsigned SubIdx) const;
158
159   bool shouldRewriteCopySrc(const TargetRegisterClass *DefRC,
160                             unsigned DefSubReg,
161                             const TargetRegisterClass *SrcRC,
162                             unsigned SrcSubReg) const override;
163
164   /// \returns True if operands defined with this operand type can accept
165   /// a literal constant (i.e. any 32-bit immediate).
166   bool opCanUseLiteralConstant(unsigned OpType) const {
167     // TODO: 64-bit operands have extending behavior from 32-bit literal.
168     return OpType >= AMDGPU::OPERAND_REG_IMM_FIRST &&
169            OpType <= AMDGPU::OPERAND_REG_IMM_LAST;
170   }
171
172   /// \returns True if operands defined with this operand type can accept
173   /// an inline constant. i.e. An integer value in the range (-16, 64) or
174   /// -4.0f, -2.0f, -1.0f, -0.5f, 0.0f, 0.5f, 1.0f, 2.0f, 4.0f.
175   bool opCanUseInlineConstant(unsigned OpType) const {
176     return OpType >= AMDGPU::OPERAND_SRC_FIRST &&
177            OpType <= AMDGPU::OPERAND_SRC_LAST;
178   }
179
180   enum PreloadedValue {
181     // SGPRS:
182     PRIVATE_SEGMENT_BUFFER = 0,
183     DISPATCH_PTR        =  1,
184     QUEUE_PTR           =  2,
185     KERNARG_SEGMENT_PTR =  3,
186     DISPATCH_ID         =  4,
187     FLAT_SCRATCH_INIT   =  5,
188     WORKGROUP_ID_X      = 10,
189     WORKGROUP_ID_Y      = 11,
190     WORKGROUP_ID_Z      = 12,
191     PRIVATE_SEGMENT_WAVE_BYTE_OFFSET = 14,
192
193     // VGPRS:
194     FIRST_VGPR_VALUE    = 15,
195     WORKITEM_ID_X       = FIRST_VGPR_VALUE,
196     WORKITEM_ID_Y       = 16,
197     WORKITEM_ID_Z       = 17
198   };
199
200   /// \brief Returns the physical register that \p Value is stored in.
201   unsigned getPreloadedValue(const MachineFunction &MF,
202                              enum PreloadedValue Value) const;
203
204   unsigned findUnusedRegister(const MachineRegisterInfo &MRI,
205                               const TargetRegisterClass *RC,
206                               const MachineFunction &MF) const;
207
208   unsigned getSGPRPressureSet() const { return SGPRSetID; };
209   unsigned getVGPRPressureSet() const { return VGPRSetID; };
210
211   const TargetRegisterClass *getRegClassForReg(const MachineRegisterInfo &MRI,
212                                                unsigned Reg) const;
213   bool isVGPR(const MachineRegisterInfo &MRI, unsigned Reg) const;
214
215   bool isSGPRPressureSet(unsigned SetID) const {
216     return SGPRPressureSets.test(SetID) && !VGPRPressureSets.test(SetID);
217   }
218   bool isVGPRPressureSet(unsigned SetID) const {
219     return VGPRPressureSets.test(SetID) && !SGPRPressureSets.test(SetID);
220   }
221
222   ArrayRef<int16_t> getRegSplitParts(const TargetRegisterClass *RC,
223                                      unsigned EltSize) const;
224
225   bool shouldCoalesce(MachineInstr *MI,
226                       const TargetRegisterClass *SrcRC,
227                       unsigned SubReg,
228                       const TargetRegisterClass *DstRC,
229                       unsigned DstSubReg,
230                       const TargetRegisterClass *NewRC) const override;
231
232   unsigned getRegPressureLimit(const TargetRegisterClass *RC,
233                                MachineFunction &MF) const override;
234
235   unsigned getRegPressureSetLimit(const MachineFunction &MF,
236                                   unsigned Idx) const override;
237
238   const int *getRegUnitPressureSets(unsigned RegUnit) const override;
239
240   unsigned getReturnAddressReg(const MachineFunction &MF) const {
241     // Not a callee saved register.
242     return AMDGPU::SGPR30_SGPR31;
243   }
244
245 private:
246   void buildSpillLoadStore(MachineBasicBlock::iterator MI,
247                            unsigned LoadStoreOp,
248                            int Index,
249                            unsigned ValueReg,
250                            bool ValueIsKill,
251                            unsigned ScratchRsrcReg,
252                            unsigned ScratchOffsetReg,
253                            int64_t InstrOffset,
254                            MachineMemOperand *MMO,
255                            RegScavenger *RS) const;
256 };
257
258 } // End namespace llvm
259
260 #endif