blob: 272b65104a8398dd91285f3c61a9f96afd5c2004 [file] [log] [blame]
Matt Arsenaultdf90c022013-10-15 23:44:45 +00001//===-- SIInstrInfo.h - SI Instruction Info Interface -----------*- C++ -*-===//
Tom Stellard75aadc22012-12-11 21:25:42 +00002//
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 SIInstrInfo.
12//
13//===----------------------------------------------------------------------===//
14
15
Benjamin Kramera7c40ef2014-08-13 16:26:38 +000016#ifndef LLVM_LIB_TARGET_R600_SIINSTRINFO_H
17#define LLVM_LIB_TARGET_R600_SIINSTRINFO_H
Tom Stellard75aadc22012-12-11 21:25:42 +000018
19#include "AMDGPUInstrInfo.h"
Matt Arsenaultc5f174d2014-12-01 15:52:46 +000020#include "SIDefines.h"
Tom Stellard75aadc22012-12-11 21:25:42 +000021#include "SIRegisterInfo.h"
22
23namespace llvm {
24
25class SIInstrInfo : public AMDGPUInstrInfo {
26private:
27 const SIRegisterInfo RI;
28
Tom Stellard15834092014-03-21 15:51:57 +000029 unsigned buildExtractSubReg(MachineBasicBlock::iterator MI,
30 MachineRegisterInfo &MRI,
31 MachineOperand &SuperReg,
32 const TargetRegisterClass *SuperRC,
33 unsigned SubIdx,
34 const TargetRegisterClass *SubRC) const;
Matt Arsenault248b7b62014-03-24 20:08:09 +000035 MachineOperand buildExtractSubRegOrImm(MachineBasicBlock::iterator MI,
36 MachineRegisterInfo &MRI,
37 MachineOperand &SuperReg,
38 const TargetRegisterClass *SuperRC,
39 unsigned SubIdx,
40 const TargetRegisterClass *SubRC) const;
Tom Stellard15834092014-03-21 15:51:57 +000041
Marek Olsakbe047802014-12-07 12:19:03 +000042 void swapOperands(MachineBasicBlock::iterator Inst) const;
43
Matt Arsenault689f3252014-06-09 16:36:31 +000044 void splitScalar64BitUnaryOp(SmallVectorImpl<MachineInstr *> &Worklist,
45 MachineInstr *Inst, unsigned Opcode) const;
46
47 void splitScalar64BitBinaryOp(SmallVectorImpl<MachineInstr *> &Worklist,
48 MachineInstr *Inst, unsigned Opcode) const;
Matt Arsenaultf35182c2014-03-24 20:08:05 +000049
Matt Arsenault8333e432014-06-10 19:18:24 +000050 void splitScalar64BitBCNT(SmallVectorImpl<MachineInstr *> &Worklist,
51 MachineInstr *Inst) const;
Matt Arsenault94812212014-11-14 18:18:16 +000052 void splitScalar64BitBFE(SmallVectorImpl<MachineInstr *> &Worklist,
53 MachineInstr *Inst) const;
Matt Arsenault8333e432014-06-10 19:18:24 +000054
Matt Arsenaultf003c382015-08-26 20:47:50 +000055 void addUsersToMoveToVALUWorklist(
56 unsigned Reg, MachineRegisterInfo &MRI,
57 SmallVectorImpl<MachineInstr *> &Worklist) const;
58
Matt Arsenaultc09cc3c2014-11-19 00:01:31 +000059 bool checkInstOffsetsDoNotOverlap(MachineInstr *MIa,
60 MachineInstr *MIb) const;
61
Matt Arsenaultee522bf2014-09-26 17:55:06 +000062 unsigned findUsedSGPR(const MachineInstr *MI, int OpIndices[3]) const;
63
Tom Stellard75aadc22012-12-11 21:25:42 +000064public:
Tom Stellard2e59a452014-06-13 01:32:00 +000065 explicit SIInstrInfo(const AMDGPUSubtarget &st);
Tom Stellard75aadc22012-12-11 21:25:42 +000066
Craig Topper5656db42014-04-29 07:57:24 +000067 const SIRegisterInfo &getRegisterInfo() const override {
Matt Arsenault6dde3032014-03-11 00:01:34 +000068 return RI;
69 }
Tom Stellard75aadc22012-12-11 21:25:42 +000070
Matt Arsenaulta48b8662015-04-23 23:34:48 +000071 bool isReallyTriviallyReMaterializable(const MachineInstr *MI,
72 AliasAnalysis *AA) const override;
73
Matt Arsenaultc10853f2014-08-06 00:29:43 +000074 bool areLoadsFromSameBasePtr(SDNode *Load1, SDNode *Load2,
75 int64_t &Offset1,
76 int64_t &Offset2) const override;
77
Sanjoy Dasb666ea32015-06-15 18:44:14 +000078 bool getMemOpBaseRegImmOfs(MachineInstr *LdSt, unsigned &BaseReg,
79 unsigned &Offset,
80 const TargetRegisterInfo *TRI) const final;
Matt Arsenault1acc72f2014-07-29 21:34:55 +000081
Matt Arsenault0e75a062014-09-17 17:48:30 +000082 bool shouldClusterLoads(MachineInstr *FirstLdSt,
83 MachineInstr *SecondLdSt,
84 unsigned NumLoads) const final;
85
Craig Topper5656db42014-04-29 07:57:24 +000086 void copyPhysReg(MachineBasicBlock &MBB,
87 MachineBasicBlock::iterator MI, DebugLoc DL,
88 unsigned DestReg, unsigned SrcReg,
89 bool KillSrc) const override;
Tom Stellard75aadc22012-12-11 21:25:42 +000090
Tom Stellard96468902014-09-24 01:33:17 +000091 unsigned calculateLDSSpillAddress(MachineBasicBlock &MBB,
92 MachineBasicBlock::iterator MI,
93 RegScavenger *RS,
94 unsigned TmpReg,
95 unsigned Offset,
96 unsigned Size) const;
97
Tom Stellardc149dc02013-11-27 21:23:35 +000098 void storeRegToStackSlot(MachineBasicBlock &MBB,
99 MachineBasicBlock::iterator MI,
100 unsigned SrcReg, bool isKill, int FrameIndex,
101 const TargetRegisterClass *RC,
Craig Topper5656db42014-04-29 07:57:24 +0000102 const TargetRegisterInfo *TRI) const override;
Tom Stellardc149dc02013-11-27 21:23:35 +0000103
104 void loadRegFromStackSlot(MachineBasicBlock &MBB,
105 MachineBasicBlock::iterator MI,
106 unsigned DestReg, int FrameIndex,
107 const TargetRegisterClass *RC,
Craig Topper5656db42014-04-29 07:57:24 +0000108 const TargetRegisterInfo *TRI) const override;
Tom Stellardc149dc02013-11-27 21:23:35 +0000109
Benjamin Kramer8c90fd72014-09-03 11:41:21 +0000110 bool expandPostRAPseudo(MachineBasicBlock::iterator MI) const override;
Tom Stellardeba61072014-05-02 15:41:42 +0000111
Tom Stellardef3b8642015-01-07 19:56:17 +0000112 // \brief Returns an opcode that can be used to move a value to a \p DstRC
113 // register. If there is no hardware instruction that can store to \p
114 // DstRC, then AMDGPU::COPY is returned.
115 unsigned getMovOpcode(const TargetRegisterClass *DstRC) const;
Matt Arsenaultfa242962015-09-24 07:51:23 +0000116
117 LLVM_READONLY
Marek Olsakcfbdba22015-06-26 20:29:10 +0000118 int commuteOpcode(const MachineInstr &MI) const;
Christian Konig3c145802013-03-27 09:12:59 +0000119
Craig Topper5656db42014-04-29 07:57:24 +0000120 MachineInstr *commuteInstruction(MachineInstr *MI,
Matt Arsenault92befe72014-09-26 17:54:54 +0000121 bool NewMI = false) const override;
122 bool findCommutedOpIndices(MachineInstr *MI,
123 unsigned &SrcOpIdx1,
124 unsigned &SrcOpIdx2) const override;
Christian Konig76edd4f2013-02-26 17:52:29 +0000125
Matt Arsenaultc09cc3c2014-11-19 00:01:31 +0000126 bool areMemAccessesTriviallyDisjoint(
127 MachineInstr *MIa, MachineInstr *MIb,
128 AliasAnalysis *AA = nullptr) const override;
129
Tom Stellard26a3b672013-10-22 18:19:10 +0000130 MachineInstr *buildMovInstr(MachineBasicBlock *MBB,
131 MachineBasicBlock::iterator I,
Craig Topper5656db42014-04-29 07:57:24 +0000132 unsigned DstReg, unsigned SrcReg) const override;
133 bool isMov(unsigned Opcode) const override;
Tom Stellard75aadc22012-12-11 21:25:42 +0000134
Matt Arsenault0325d3d2015-02-21 21:29:07 +0000135 bool FoldImmediate(MachineInstr *UseMI, MachineInstr *DefMI,
136 unsigned Reg, MachineRegisterInfo *MRI) const final;
137
Tom Stellardf01af292015-05-09 00:56:07 +0000138 unsigned getMachineCSELookAheadLimit() const override { return 500; }
139
Tom Stellarddb5a11f2015-07-13 15:47:57 +0000140 MachineInstr *convertToThreeAddress(MachineFunction::iterator &MBB,
141 MachineBasicBlock::iterator &MI,
142 LiveVariables *LV) const override;
143
Matt Arsenaultc5f174d2014-12-01 15:52:46 +0000144 bool isSALU(uint16_t Opcode) const {
145 return get(Opcode).TSFlags & SIInstrFlags::SALU;
146 }
147
148 bool isVALU(uint16_t Opcode) const {
149 return get(Opcode).TSFlags & SIInstrFlags::VALU;
150 }
151
152 bool isSOP1(uint16_t Opcode) const {
153 return get(Opcode).TSFlags & SIInstrFlags::SOP1;
154 }
155
156 bool isSOP2(uint16_t Opcode) const {
157 return get(Opcode).TSFlags & SIInstrFlags::SOP2;
158 }
159
160 bool isSOPC(uint16_t Opcode) const {
161 return get(Opcode).TSFlags & SIInstrFlags::SOPC;
162 }
163
164 bool isSOPK(uint16_t Opcode) const {
165 return get(Opcode).TSFlags & SIInstrFlags::SOPK;
166 }
167
168 bool isSOPP(uint16_t Opcode) const {
169 return get(Opcode).TSFlags & SIInstrFlags::SOPP;
170 }
171
172 bool isVOP1(uint16_t Opcode) const {
173 return get(Opcode).TSFlags & SIInstrFlags::VOP1;
174 }
175
176 bool isVOP2(uint16_t Opcode) const {
177 return get(Opcode).TSFlags & SIInstrFlags::VOP2;
178 }
179
180 bool isVOP3(uint16_t Opcode) const {
181 return get(Opcode).TSFlags & SIInstrFlags::VOP3;
182 }
183
184 bool isVOPC(uint16_t Opcode) const {
185 return get(Opcode).TSFlags & SIInstrFlags::VOPC;
186 }
187
188 bool isMUBUF(uint16_t Opcode) const {
189 return get(Opcode).TSFlags & SIInstrFlags::MUBUF;
190 }
191
192 bool isMTBUF(uint16_t Opcode) const {
193 return get(Opcode).TSFlags & SIInstrFlags::MTBUF;
194 }
195
196 bool isSMRD(uint16_t Opcode) const {
197 return get(Opcode).TSFlags & SIInstrFlags::SMRD;
198 }
199
200 bool isDS(uint16_t Opcode) const {
201 return get(Opcode).TSFlags & SIInstrFlags::DS;
202 }
203
204 bool isMIMG(uint16_t Opcode) const {
205 return get(Opcode).TSFlags & SIInstrFlags::MIMG;
206 }
207
208 bool isFLAT(uint16_t Opcode) const {
209 return get(Opcode).TSFlags & SIInstrFlags::FLAT;
210 }
Matt Arsenaultc09cc3c2014-11-19 00:01:31 +0000211
Michel Danzer494391b2015-02-06 02:51:20 +0000212 bool isWQM(uint16_t Opcode) const {
213 return get(Opcode).TSFlags & SIInstrFlags::WQM;
214 }
215
Tom Stellarda77c3f72015-05-12 18:59:17 +0000216 bool isVGPRSpill(uint16_t Opcode) const {
217 return get(Opcode).TSFlags & SIInstrFlags::VGPRSpill;
218 }
219
Matt Arsenaultd7bdcc42014-03-31 19:54:27 +0000220 bool isInlineConstant(const APInt &Imm) const;
Matt Arsenault11a4d672015-02-13 19:05:03 +0000221 bool isInlineConstant(const MachineOperand &MO, unsigned OpSize) const;
222 bool isLiteralConstant(const MachineOperand &MO, unsigned OpSize) const;
Tom Stellardf3b2a1e2013-02-06 17:32:29 +0000223
Tom Stellardb02094e2014-07-21 15:45:01 +0000224 bool isImmOperandLegal(const MachineInstr *MI, unsigned OpNo,
225 const MachineOperand &MO) const;
226
Tom Stellard86d12eb2014-08-01 00:32:28 +0000227 /// \brief Return true if this 64-bit VALU instruction has a 32-bit encoding.
228 /// This function will return false if you pass it a 32-bit instruction.
229 bool hasVALU32BitEncoding(unsigned Opcode) const;
230
Tom Stellard73ae1cb2014-09-23 21:26:25 +0000231 /// \brief Returns true if this operand uses the constant bus.
232 bool usesConstantBus(const MachineRegisterInfo &MRI,
Matt Arsenault11a4d672015-02-13 19:05:03 +0000233 const MachineOperand &MO,
234 unsigned OpSize) const;
Tom Stellard73ae1cb2014-09-23 21:26:25 +0000235
Tom Stellardb4a313a2014-08-01 00:32:39 +0000236 /// \brief Return true if this instruction has any modifiers.
237 /// e.g. src[012]_mod, omod, clamp.
238 bool hasModifiers(unsigned Opcode) const;
Matt Arsenaultace5b762014-10-17 18:00:43 +0000239
240 bool hasModifiersSet(const MachineInstr &MI,
241 unsigned OpName) const;
242
Craig Topper5656db42014-04-29 07:57:24 +0000243 bool verifyInstruction(const MachineInstr *MI,
244 StringRef &ErrInfo) const override;
Tom Stellardf3b2a1e2013-02-06 17:32:29 +0000245
Matt Arsenaultf14032a2013-11-15 22:02:28 +0000246 static unsigned getVALUOp(const MachineInstr &MI);
Matt Arsenaultf35182c2014-03-24 20:08:05 +0000247
Tom Stellard82166022013-11-13 23:36:37 +0000248 bool isSALUOpSupportedOnVALU(const MachineInstr &MI) const;
249
250 /// \brief Return the correct register class for \p OpNo. For target-specific
251 /// instructions, this will return the register class that has been defined
252 /// in tablegen. For generic instructions, like REG_SEQUENCE it will return
253 /// the register class of its machine operand.
254 /// to infer the correct register class base on the other operands.
255 const TargetRegisterClass *getOpRegClass(const MachineInstr &MI,
Matt Arsenault11a4d672015-02-13 19:05:03 +0000256 unsigned OpNo) const;
257
258 /// \brief Return the size in bytes of the operand OpNo on the given
259 // instruction opcode.
260 unsigned getOpSize(uint16_t Opcode, unsigned OpNo) const {
261 const MCOperandInfo &OpInfo = get(Opcode).OpInfo[OpNo];
Matt Arsenault657b1cb2015-02-21 21:29:04 +0000262
263 if (OpInfo.RegClass == -1) {
264 // If this is an immediate operand, this must be a 32-bit literal.
265 assert(OpInfo.OperandType == MCOI::OPERAND_IMMEDIATE);
266 return 4;
267 }
268
Matt Arsenault11a4d672015-02-13 19:05:03 +0000269 return RI.getRegClass(OpInfo.RegClass)->getSize();
270 }
271
272 /// \brief This form should usually be preferred since it handles operands
273 /// with unknown register classes.
274 unsigned getOpSize(const MachineInstr &MI, unsigned OpNo) const {
275 return getOpRegClass(MI, OpNo)->getSize();
276 }
Tom Stellard82166022013-11-13 23:36:37 +0000277
278 /// \returns true if it is legal for the operand at index \p OpNo
279 /// to read a VGPR.
280 bool canReadVGPR(const MachineInstr &MI, unsigned OpNo) const;
281
282 /// \brief Legalize the \p OpIndex operand of this instruction by inserting
283 /// a MOV. For example:
284 /// ADD_I32_e32 VGPR0, 15
285 /// to
286 /// MOV VGPR1, 15
287 /// ADD_I32_e32 VGPR0, VGPR1
288 ///
289 /// If the operand being legalized is a register, then a COPY will be used
290 /// instead of MOV.
291 void legalizeOpWithMove(MachineInstr *MI, unsigned OpIdx) const;
292
Tom Stellard0e975cf2014-08-01 00:32:35 +0000293 /// \brief Check if \p MO is a legal operand if it was the \p OpIdx Operand
294 /// for \p MI.
295 bool isOperandLegal(const MachineInstr *MI, unsigned OpIdx,
296 const MachineOperand *MO = nullptr) const;
297
Tom Stellard82166022013-11-13 23:36:37 +0000298 /// \brief Legalize all operands in this instruction. This function may
299 /// create new instruction and insert them before \p MI.
300 void legalizeOperands(MachineInstr *MI) const;
301
Tom Stellard745f2ed2014-08-21 20:41:00 +0000302 /// \brief Split an SMRD instruction into two smaller loads of half the
303 // size storing the results in \p Lo and \p Hi.
304 void splitSMRD(MachineInstr *MI, const TargetRegisterClass *HalfRC,
305 unsigned HalfImmOp, unsigned HalfSGPROp,
306 MachineInstr *&Lo, MachineInstr *&Hi) const;
307
Tom Stellard0c354f22014-04-30 15:31:29 +0000308 void moveSMRDToVALU(MachineInstr *MI, MachineRegisterInfo &MRI) const;
309
Tom Stellard82166022013-11-13 23:36:37 +0000310 /// \brief Replace this instruction's opcode with the equivalent VALU
311 /// opcode. This function will also move the users of \p MI to the
312 /// VALU if necessary.
313 void moveToVALU(MachineInstr &MI) const;
314
Craig Topper5656db42014-04-29 07:57:24 +0000315 unsigned calculateIndirectAddress(unsigned RegIndex,
316 unsigned Channel) const override;
Tom Stellardf3b2a1e2013-02-06 17:32:29 +0000317
Craig Topper5656db42014-04-29 07:57:24 +0000318 const TargetRegisterClass *getIndirectAddrRegClass() const override;
Tom Stellardf3b2a1e2013-02-06 17:32:29 +0000319
Craig Topper5656db42014-04-29 07:57:24 +0000320 MachineInstrBuilder buildIndirectWrite(MachineBasicBlock *MBB,
321 MachineBasicBlock::iterator I,
322 unsigned ValueReg,
323 unsigned Address,
324 unsigned OffsetReg) const override;
Tom Stellardf3b2a1e2013-02-06 17:32:29 +0000325
Craig Topper5656db42014-04-29 07:57:24 +0000326 MachineInstrBuilder buildIndirectRead(MachineBasicBlock *MBB,
327 MachineBasicBlock::iterator I,
328 unsigned ValueReg,
329 unsigned Address,
330 unsigned OffsetReg) const override;
Tom Stellard81d871d2013-11-13 23:36:50 +0000331 void reserveIndirectRegisters(BitVector &Reserved,
332 const MachineFunction &MF) const;
333
334 void LoadM0(MachineInstr *MoveRel, MachineBasicBlock::iterator I,
335 unsigned SavReg, unsigned IndexReg) const;
Tom Stellardeba61072014-05-02 15:41:42 +0000336
337 void insertNOPs(MachineBasicBlock::iterator MI, int Count) const;
Tom Stellard1aaad692014-07-21 16:55:33 +0000338
339 /// \brief Returns the operand named \p Op. If \p MI does not have an
340 /// operand named \c Op, this function returns nullptr.
Tom Stellard6407e1e2014-08-01 00:32:33 +0000341 MachineOperand *getNamedOperand(MachineInstr &MI, unsigned OperandName) const;
Matt Arsenaultace5b762014-10-17 18:00:43 +0000342
343 const MachineOperand *getNamedOperand(const MachineInstr &MI,
344 unsigned OpName) const {
345 return getNamedOperand(const_cast<MachineInstr &>(MI), OpName);
346 }
Tom Stellard794c8c02014-12-02 17:05:41 +0000347
348 uint64_t getDefaultRsrcDataFormat() const;
349
Tom Stellard81d871d2013-11-13 23:36:50 +0000350};
Tom Stellard75aadc22012-12-11 21:25:42 +0000351
Christian Konigf741fbf2013-02-26 17:52:42 +0000352namespace AMDGPU {
Matt Arsenaultfa242962015-09-24 07:51:23 +0000353 LLVM_READONLY
Christian Konigf741fbf2013-02-26 17:52:42 +0000354 int getVOPe64(uint16_t Opcode);
Matt Arsenaultfa242962015-09-24 07:51:23 +0000355
356 LLVM_READONLY
Tom Stellard1aaad692014-07-21 16:55:33 +0000357 int getVOPe32(uint16_t Opcode);
Matt Arsenaultfa242962015-09-24 07:51:23 +0000358
359 LLVM_READONLY
Christian Konig3c145802013-03-27 09:12:59 +0000360 int getCommuteRev(uint16_t Opcode);
Matt Arsenaultfa242962015-09-24 07:51:23 +0000361
362 LLVM_READONLY
Christian Konig3c145802013-03-27 09:12:59 +0000363 int getCommuteOrig(uint16_t Opcode);
Matt Arsenaultfa242962015-09-24 07:51:23 +0000364
365 LLVM_READONLY
Tom Stellard155bbb72014-08-11 22:18:17 +0000366 int getAddr64Inst(uint16_t Opcode);
Matt Arsenaultfa242962015-09-24 07:51:23 +0000367
368 LLVM_READONLY
Matt Arsenault9903ccf2014-09-08 15:07:27 +0000369 int getAtomicRetOp(uint16_t Opcode);
Matt Arsenaultfa242962015-09-24 07:51:23 +0000370
371 LLVM_READONLY
Matt Arsenault9903ccf2014-09-08 15:07:27 +0000372 int getAtomicNoRetOp(uint16_t Opcode);
Christian Konigf741fbf2013-02-26 17:52:42 +0000373
Tom Stellard15834092014-03-21 15:51:57 +0000374 const uint64_t RSRC_DATA_FORMAT = 0xf00000000000LL;
Tom Stellardb02094e2014-07-21 15:45:01 +0000375 const uint64_t RSRC_TID_ENABLE = 1LL << 55;
Tom Stellard15834092014-03-21 15:51:57 +0000376
Christian Konigf741fbf2013-02-26 17:52:42 +0000377} // End namespace AMDGPU
378
Tom Stellardec2e43c2014-09-22 15:35:29 +0000379namespace SI {
380namespace KernelInputOffsets {
381
382/// Offsets in bytes from the start of the input buffer
383enum Offsets {
384 NGROUPS_X = 0,
385 NGROUPS_Y = 4,
386 NGROUPS_Z = 8,
387 GLOBAL_SIZE_X = 12,
388 GLOBAL_SIZE_Y = 16,
389 GLOBAL_SIZE_Z = 20,
390 LOCAL_SIZE_X = 24,
391 LOCAL_SIZE_Y = 28,
392 LOCAL_SIZE_Z = 32
393};
394
395} // End namespace KernelInputOffsets
396} // End namespace SI
397
Tom Stellard75aadc22012-12-11 21:25:42 +0000398} // End namespace llvm
399
Benjamin Kramera7c40ef2014-08-13 16:26:38 +0000400#endif