blob: 474c26f03d0c3a0c874473263afc90e5a06427a5 [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
Andrew Kaylor16c4da02015-09-28 20:33:22 +000064protected:
65 MachineInstr *commuteInstructionImpl(MachineInstr *MI,
66 bool NewMI,
67 unsigned OpIdx0,
68 unsigned OpIdx1) const override;
69
Tom Stellard75aadc22012-12-11 21:25:42 +000070public:
Tom Stellard2e59a452014-06-13 01:32:00 +000071 explicit SIInstrInfo(const AMDGPUSubtarget &st);
Tom Stellard75aadc22012-12-11 21:25:42 +000072
Craig Topper5656db42014-04-29 07:57:24 +000073 const SIRegisterInfo &getRegisterInfo() const override {
Matt Arsenault6dde3032014-03-11 00:01:34 +000074 return RI;
75 }
Tom Stellard75aadc22012-12-11 21:25:42 +000076
Matt Arsenaulta48b8662015-04-23 23:34:48 +000077 bool isReallyTriviallyReMaterializable(const MachineInstr *MI,
78 AliasAnalysis *AA) const override;
79
Matt Arsenaultc10853f2014-08-06 00:29:43 +000080 bool areLoadsFromSameBasePtr(SDNode *Load1, SDNode *Load2,
81 int64_t &Offset1,
82 int64_t &Offset2) const override;
83
Sanjoy Dasb666ea32015-06-15 18:44:14 +000084 bool getMemOpBaseRegImmOfs(MachineInstr *LdSt, unsigned &BaseReg,
85 unsigned &Offset,
86 const TargetRegisterInfo *TRI) const final;
Matt Arsenault1acc72f2014-07-29 21:34:55 +000087
Matt Arsenault0e75a062014-09-17 17:48:30 +000088 bool shouldClusterLoads(MachineInstr *FirstLdSt,
89 MachineInstr *SecondLdSt,
90 unsigned NumLoads) const final;
91
Craig Topper5656db42014-04-29 07:57:24 +000092 void copyPhysReg(MachineBasicBlock &MBB,
93 MachineBasicBlock::iterator MI, DebugLoc DL,
94 unsigned DestReg, unsigned SrcReg,
95 bool KillSrc) const override;
Tom Stellard75aadc22012-12-11 21:25:42 +000096
Tom Stellard96468902014-09-24 01:33:17 +000097 unsigned calculateLDSSpillAddress(MachineBasicBlock &MBB,
98 MachineBasicBlock::iterator MI,
99 RegScavenger *RS,
100 unsigned TmpReg,
101 unsigned Offset,
102 unsigned Size) const;
103
Tom Stellardc149dc02013-11-27 21:23:35 +0000104 void storeRegToStackSlot(MachineBasicBlock &MBB,
105 MachineBasicBlock::iterator MI,
106 unsigned SrcReg, bool isKill, 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
110 void loadRegFromStackSlot(MachineBasicBlock &MBB,
111 MachineBasicBlock::iterator MI,
112 unsigned DestReg, int FrameIndex,
113 const TargetRegisterClass *RC,
Craig Topper5656db42014-04-29 07:57:24 +0000114 const TargetRegisterInfo *TRI) const override;
Tom Stellardc149dc02013-11-27 21:23:35 +0000115
Benjamin Kramer8c90fd72014-09-03 11:41:21 +0000116 bool expandPostRAPseudo(MachineBasicBlock::iterator MI) const override;
Tom Stellardeba61072014-05-02 15:41:42 +0000117
Tom Stellardef3b8642015-01-07 19:56:17 +0000118 // \brief Returns an opcode that can be used to move a value to a \p DstRC
119 // register. If there is no hardware instruction that can store to \p
120 // DstRC, then AMDGPU::COPY is returned.
121 unsigned getMovOpcode(const TargetRegisterClass *DstRC) const;
Matt Arsenaultfa242962015-09-24 07:51:23 +0000122
123 LLVM_READONLY
Marek Olsakcfbdba22015-06-26 20:29:10 +0000124 int commuteOpcode(const MachineInstr &MI) const;
Christian Konig3c145802013-03-27 09:12:59 +0000125
Matt Arsenault92befe72014-09-26 17:54:54 +0000126 bool findCommutedOpIndices(MachineInstr *MI,
127 unsigned &SrcOpIdx1,
128 unsigned &SrcOpIdx2) const override;
Christian Konig76edd4f2013-02-26 17:52:29 +0000129
Matt Arsenaultc09cc3c2014-11-19 00:01:31 +0000130 bool areMemAccessesTriviallyDisjoint(
131 MachineInstr *MIa, MachineInstr *MIb,
132 AliasAnalysis *AA = nullptr) const override;
133
Tom Stellard26a3b672013-10-22 18:19:10 +0000134 MachineInstr *buildMovInstr(MachineBasicBlock *MBB,
135 MachineBasicBlock::iterator I,
Craig Topper5656db42014-04-29 07:57:24 +0000136 unsigned DstReg, unsigned SrcReg) const override;
137 bool isMov(unsigned Opcode) const override;
Tom Stellard75aadc22012-12-11 21:25:42 +0000138
Matt Arsenault0325d3d2015-02-21 21:29:07 +0000139 bool FoldImmediate(MachineInstr *UseMI, MachineInstr *DefMI,
140 unsigned Reg, MachineRegisterInfo *MRI) const final;
141
Tom Stellardf01af292015-05-09 00:56:07 +0000142 unsigned getMachineCSELookAheadLimit() const override { return 500; }
143
Tom Stellarddb5a11f2015-07-13 15:47:57 +0000144 MachineInstr *convertToThreeAddress(MachineFunction::iterator &MBB,
145 MachineBasicBlock::iterator &MI,
146 LiveVariables *LV) const override;
147
Matt Arsenaultc5f174d2014-12-01 15:52:46 +0000148 bool isSALU(uint16_t Opcode) const {
149 return get(Opcode).TSFlags & SIInstrFlags::SALU;
150 }
151
152 bool isVALU(uint16_t Opcode) const {
153 return get(Opcode).TSFlags & SIInstrFlags::VALU;
154 }
155
156 bool isSOP1(uint16_t Opcode) const {
157 return get(Opcode).TSFlags & SIInstrFlags::SOP1;
158 }
159
160 bool isSOP2(uint16_t Opcode) const {
161 return get(Opcode).TSFlags & SIInstrFlags::SOP2;
162 }
163
164 bool isSOPC(uint16_t Opcode) const {
165 return get(Opcode).TSFlags & SIInstrFlags::SOPC;
166 }
167
168 bool isSOPK(uint16_t Opcode) const {
169 return get(Opcode).TSFlags & SIInstrFlags::SOPK;
170 }
171
172 bool isSOPP(uint16_t Opcode) const {
173 return get(Opcode).TSFlags & SIInstrFlags::SOPP;
174 }
175
176 bool isVOP1(uint16_t Opcode) const {
177 return get(Opcode).TSFlags & SIInstrFlags::VOP1;
178 }
179
180 bool isVOP2(uint16_t Opcode) const {
181 return get(Opcode).TSFlags & SIInstrFlags::VOP2;
182 }
183
184 bool isVOP3(uint16_t Opcode) const {
185 return get(Opcode).TSFlags & SIInstrFlags::VOP3;
186 }
187
188 bool isVOPC(uint16_t Opcode) const {
189 return get(Opcode).TSFlags & SIInstrFlags::VOPC;
190 }
191
192 bool isMUBUF(uint16_t Opcode) const {
193 return get(Opcode).TSFlags & SIInstrFlags::MUBUF;
194 }
195
196 bool isMTBUF(uint16_t Opcode) const {
197 return get(Opcode).TSFlags & SIInstrFlags::MTBUF;
198 }
199
200 bool isSMRD(uint16_t Opcode) const {
201 return get(Opcode).TSFlags & SIInstrFlags::SMRD;
202 }
203
204 bool isDS(uint16_t Opcode) const {
205 return get(Opcode).TSFlags & SIInstrFlags::DS;
206 }
207
208 bool isMIMG(uint16_t Opcode) const {
209 return get(Opcode).TSFlags & SIInstrFlags::MIMG;
210 }
211
212 bool isFLAT(uint16_t Opcode) const {
213 return get(Opcode).TSFlags & SIInstrFlags::FLAT;
214 }
Matt Arsenaultc09cc3c2014-11-19 00:01:31 +0000215
Michel Danzer494391b2015-02-06 02:51:20 +0000216 bool isWQM(uint16_t Opcode) const {
217 return get(Opcode).TSFlags & SIInstrFlags::WQM;
218 }
219
Tom Stellarda77c3f72015-05-12 18:59:17 +0000220 bool isVGPRSpill(uint16_t Opcode) const {
221 return get(Opcode).TSFlags & SIInstrFlags::VGPRSpill;
222 }
223
Matt Arsenaultd7bdcc42014-03-31 19:54:27 +0000224 bool isInlineConstant(const APInt &Imm) const;
Matt Arsenault11a4d672015-02-13 19:05:03 +0000225 bool isInlineConstant(const MachineOperand &MO, unsigned OpSize) const;
226 bool isLiteralConstant(const MachineOperand &MO, unsigned OpSize) const;
Tom Stellardf3b2a1e2013-02-06 17:32:29 +0000227
Tom Stellardb02094e2014-07-21 15:45:01 +0000228 bool isImmOperandLegal(const MachineInstr *MI, unsigned OpNo,
229 const MachineOperand &MO) const;
230
Tom Stellard86d12eb2014-08-01 00:32:28 +0000231 /// \brief Return true if this 64-bit VALU instruction has a 32-bit encoding.
232 /// This function will return false if you pass it a 32-bit instruction.
233 bool hasVALU32BitEncoding(unsigned Opcode) const;
234
Tom Stellard73ae1cb2014-09-23 21:26:25 +0000235 /// \brief Returns true if this operand uses the constant bus.
236 bool usesConstantBus(const MachineRegisterInfo &MRI,
Matt Arsenault11a4d672015-02-13 19:05:03 +0000237 const MachineOperand &MO,
238 unsigned OpSize) const;
Tom Stellard73ae1cb2014-09-23 21:26:25 +0000239
Tom Stellardb4a313a2014-08-01 00:32:39 +0000240 /// \brief Return true if this instruction has any modifiers.
241 /// e.g. src[012]_mod, omod, clamp.
242 bool hasModifiers(unsigned Opcode) const;
Matt Arsenaultace5b762014-10-17 18:00:43 +0000243
244 bool hasModifiersSet(const MachineInstr &MI,
245 unsigned OpName) const;
246
Craig Topper5656db42014-04-29 07:57:24 +0000247 bool verifyInstruction(const MachineInstr *MI,
248 StringRef &ErrInfo) const override;
Tom Stellardf3b2a1e2013-02-06 17:32:29 +0000249
Matt Arsenaultf14032a2013-11-15 22:02:28 +0000250 static unsigned getVALUOp(const MachineInstr &MI);
Matt Arsenaultf35182c2014-03-24 20:08:05 +0000251
Tom Stellard82166022013-11-13 23:36:37 +0000252 bool isSALUOpSupportedOnVALU(const MachineInstr &MI) const;
253
254 /// \brief Return the correct register class for \p OpNo. For target-specific
255 /// instructions, this will return the register class that has been defined
256 /// in tablegen. For generic instructions, like REG_SEQUENCE it will return
257 /// the register class of its machine operand.
258 /// to infer the correct register class base on the other operands.
259 const TargetRegisterClass *getOpRegClass(const MachineInstr &MI,
Matt Arsenault11a4d672015-02-13 19:05:03 +0000260 unsigned OpNo) const;
261
262 /// \brief Return the size in bytes of the operand OpNo on the given
263 // instruction opcode.
264 unsigned getOpSize(uint16_t Opcode, unsigned OpNo) const {
265 const MCOperandInfo &OpInfo = get(Opcode).OpInfo[OpNo];
Matt Arsenault657b1cb2015-02-21 21:29:04 +0000266
267 if (OpInfo.RegClass == -1) {
268 // If this is an immediate operand, this must be a 32-bit literal.
269 assert(OpInfo.OperandType == MCOI::OPERAND_IMMEDIATE);
270 return 4;
271 }
272
Matt Arsenault11a4d672015-02-13 19:05:03 +0000273 return RI.getRegClass(OpInfo.RegClass)->getSize();
274 }
275
276 /// \brief This form should usually be preferred since it handles operands
277 /// with unknown register classes.
278 unsigned getOpSize(const MachineInstr &MI, unsigned OpNo) const {
279 return getOpRegClass(MI, OpNo)->getSize();
280 }
Tom Stellard82166022013-11-13 23:36:37 +0000281
282 /// \returns true if it is legal for the operand at index \p OpNo
283 /// to read a VGPR.
284 bool canReadVGPR(const MachineInstr &MI, unsigned OpNo) const;
285
286 /// \brief Legalize the \p OpIndex operand of this instruction by inserting
287 /// a MOV. For example:
288 /// ADD_I32_e32 VGPR0, 15
289 /// to
290 /// MOV VGPR1, 15
291 /// ADD_I32_e32 VGPR0, VGPR1
292 ///
293 /// If the operand being legalized is a register, then a COPY will be used
294 /// instead of MOV.
295 void legalizeOpWithMove(MachineInstr *MI, unsigned OpIdx) const;
296
Tom Stellard0e975cf2014-08-01 00:32:35 +0000297 /// \brief Check if \p MO is a legal operand if it was the \p OpIdx Operand
298 /// for \p MI.
299 bool isOperandLegal(const MachineInstr *MI, unsigned OpIdx,
300 const MachineOperand *MO = nullptr) const;
301
Tom Stellard82166022013-11-13 23:36:37 +0000302 /// \brief Legalize all operands in this instruction. This function may
303 /// create new instruction and insert them before \p MI.
304 void legalizeOperands(MachineInstr *MI) const;
305
Tom Stellard745f2ed2014-08-21 20:41:00 +0000306 /// \brief Split an SMRD instruction into two smaller loads of half the
307 // size storing the results in \p Lo and \p Hi.
308 void splitSMRD(MachineInstr *MI, const TargetRegisterClass *HalfRC,
309 unsigned HalfImmOp, unsigned HalfSGPROp,
310 MachineInstr *&Lo, MachineInstr *&Hi) const;
311
Matt Arsenaulte229c0c2015-09-25 22:21:19 +0000312 void moveSMRDToVALU(MachineInstr *MI, MachineRegisterInfo &MRI,
313 SmallVectorImpl<MachineInstr *> &Worklist) const;
Tom Stellard0c354f22014-04-30 15:31:29 +0000314
Tom Stellard82166022013-11-13 23:36:37 +0000315 /// \brief Replace this instruction's opcode with the equivalent VALU
316 /// opcode. This function will also move the users of \p MI to the
317 /// VALU if necessary.
318 void moveToVALU(MachineInstr &MI) const;
319
Craig Topper5656db42014-04-29 07:57:24 +0000320 unsigned calculateIndirectAddress(unsigned RegIndex,
321 unsigned Channel) const override;
Tom Stellardf3b2a1e2013-02-06 17:32:29 +0000322
Craig Topper5656db42014-04-29 07:57:24 +0000323 const TargetRegisterClass *getIndirectAddrRegClass() const override;
Tom Stellardf3b2a1e2013-02-06 17:32:29 +0000324
Craig Topper5656db42014-04-29 07:57:24 +0000325 MachineInstrBuilder buildIndirectWrite(MachineBasicBlock *MBB,
326 MachineBasicBlock::iterator I,
327 unsigned ValueReg,
328 unsigned Address,
329 unsigned OffsetReg) const override;
Tom Stellardf3b2a1e2013-02-06 17:32:29 +0000330
Craig Topper5656db42014-04-29 07:57:24 +0000331 MachineInstrBuilder buildIndirectRead(MachineBasicBlock *MBB,
332 MachineBasicBlock::iterator I,
333 unsigned ValueReg,
334 unsigned Address,
335 unsigned OffsetReg) const override;
Tom Stellard81d871d2013-11-13 23:36:50 +0000336 void reserveIndirectRegisters(BitVector &Reserved,
337 const MachineFunction &MF) const;
338
339 void LoadM0(MachineInstr *MoveRel, MachineBasicBlock::iterator I,
340 unsigned SavReg, unsigned IndexReg) const;
Tom Stellardeba61072014-05-02 15:41:42 +0000341
342 void insertNOPs(MachineBasicBlock::iterator MI, int Count) const;
Tom Stellard1aaad692014-07-21 16:55:33 +0000343
344 /// \brief Returns the operand named \p Op. If \p MI does not have an
345 /// operand named \c Op, this function returns nullptr.
Matt Arsenaultf743b832015-09-25 18:09:15 +0000346 LLVM_READONLY
Tom Stellard6407e1e2014-08-01 00:32:33 +0000347 MachineOperand *getNamedOperand(MachineInstr &MI, unsigned OperandName) const;
Matt Arsenaultace5b762014-10-17 18:00:43 +0000348
Matt Arsenaultf743b832015-09-25 18:09:15 +0000349 LLVM_READONLY
Matt Arsenaultace5b762014-10-17 18:00:43 +0000350 const MachineOperand *getNamedOperand(const MachineInstr &MI,
351 unsigned OpName) const {
352 return getNamedOperand(const_cast<MachineInstr &>(MI), OpName);
353 }
Tom Stellard794c8c02014-12-02 17:05:41 +0000354
355 uint64_t getDefaultRsrcDataFormat() const;
356
Tom Stellard81d871d2013-11-13 23:36:50 +0000357};
Tom Stellard75aadc22012-12-11 21:25:42 +0000358
Christian Konigf741fbf2013-02-26 17:52:42 +0000359namespace AMDGPU {
Matt Arsenaultfa242962015-09-24 07:51:23 +0000360 LLVM_READONLY
Christian Konigf741fbf2013-02-26 17:52:42 +0000361 int getVOPe64(uint16_t Opcode);
Matt Arsenaultfa242962015-09-24 07:51:23 +0000362
363 LLVM_READONLY
Tom Stellard1aaad692014-07-21 16:55:33 +0000364 int getVOPe32(uint16_t Opcode);
Matt Arsenaultfa242962015-09-24 07:51:23 +0000365
366 LLVM_READONLY
Christian Konig3c145802013-03-27 09:12:59 +0000367 int getCommuteRev(uint16_t Opcode);
Matt Arsenaultfa242962015-09-24 07:51:23 +0000368
369 LLVM_READONLY
Christian Konig3c145802013-03-27 09:12:59 +0000370 int getCommuteOrig(uint16_t Opcode);
Matt Arsenaultfa242962015-09-24 07:51:23 +0000371
372 LLVM_READONLY
Tom Stellard155bbb72014-08-11 22:18:17 +0000373 int getAddr64Inst(uint16_t Opcode);
Matt Arsenaultfa242962015-09-24 07:51:23 +0000374
375 LLVM_READONLY
Matt Arsenault9903ccf2014-09-08 15:07:27 +0000376 int getAtomicRetOp(uint16_t Opcode);
Matt Arsenaultfa242962015-09-24 07:51:23 +0000377
378 LLVM_READONLY
Matt Arsenault9903ccf2014-09-08 15:07:27 +0000379 int getAtomicNoRetOp(uint16_t Opcode);
Christian Konigf741fbf2013-02-26 17:52:42 +0000380
Tom Stellard15834092014-03-21 15:51:57 +0000381 const uint64_t RSRC_DATA_FORMAT = 0xf00000000000LL;
Tom Stellardb02094e2014-07-21 15:45:01 +0000382 const uint64_t RSRC_TID_ENABLE = 1LL << 55;
Tom Stellard15834092014-03-21 15:51:57 +0000383
Christian Konigf741fbf2013-02-26 17:52:42 +0000384} // End namespace AMDGPU
385
Tom Stellardec2e43c2014-09-22 15:35:29 +0000386namespace SI {
387namespace KernelInputOffsets {
388
389/// Offsets in bytes from the start of the input buffer
390enum Offsets {
391 NGROUPS_X = 0,
392 NGROUPS_Y = 4,
393 NGROUPS_Z = 8,
394 GLOBAL_SIZE_X = 12,
395 GLOBAL_SIZE_Y = 16,
396 GLOBAL_SIZE_Z = 20,
397 LOCAL_SIZE_X = 24,
398 LOCAL_SIZE_Y = 28,
399 LOCAL_SIZE_Z = 32
400};
401
402} // End namespace KernelInputOffsets
403} // End namespace SI
404
Tom Stellard75aadc22012-12-11 21:25:42 +0000405} // End namespace llvm
406
Benjamin Kramera7c40ef2014-08-13 16:26:38 +0000407#endif