blob: 6fafb945c9938de7350ac007e769cc16613cd26b [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
Matt Arsenaultbd995802014-03-24 18:26:52 +000042 unsigned split64BitImm(SmallVectorImpl<MachineInstr *> &Worklist,
43 MachineBasicBlock::iterator MI,
44 MachineRegisterInfo &MRI,
45 const TargetRegisterClass *RC,
46 const MachineOperand &Op) const;
47
Marek Olsakbe047802014-12-07 12:19:03 +000048 void swapOperands(MachineBasicBlock::iterator Inst) const;
49
Matt Arsenault689f3252014-06-09 16:36:31 +000050 void splitScalar64BitUnaryOp(SmallVectorImpl<MachineInstr *> &Worklist,
51 MachineInstr *Inst, unsigned Opcode) const;
52
53 void splitScalar64BitBinaryOp(SmallVectorImpl<MachineInstr *> &Worklist,
54 MachineInstr *Inst, unsigned Opcode) const;
Matt Arsenaultf35182c2014-03-24 20:08:05 +000055
Matt Arsenault8333e432014-06-10 19:18:24 +000056 void splitScalar64BitBCNT(SmallVectorImpl<MachineInstr *> &Worklist,
57 MachineInstr *Inst) const;
Matt Arsenault94812212014-11-14 18:18:16 +000058 void splitScalar64BitBFE(SmallVectorImpl<MachineInstr *> &Worklist,
59 MachineInstr *Inst) const;
Matt Arsenault8333e432014-06-10 19:18:24 +000060
Matt Arsenault27cc9582014-04-18 01:53:18 +000061 void addDescImplicitUseDef(const MCInstrDesc &Desc, MachineInstr *MI) const;
Matt Arsenaultf35182c2014-03-24 20:08:05 +000062
Matt Arsenaultc09cc3c2014-11-19 00:01:31 +000063 bool checkInstOffsetsDoNotOverlap(MachineInstr *MIa,
64 MachineInstr *MIb) const;
65
Matt Arsenaultee522bf2014-09-26 17:55:06 +000066 unsigned findUsedSGPR(const MachineInstr *MI, int OpIndices[3]) const;
67
Tom Stellard75aadc22012-12-11 21:25:42 +000068public:
Tom Stellard2e59a452014-06-13 01:32:00 +000069 explicit SIInstrInfo(const AMDGPUSubtarget &st);
Tom Stellard75aadc22012-12-11 21:25:42 +000070
Craig Topper5656db42014-04-29 07:57:24 +000071 const SIRegisterInfo &getRegisterInfo() const override {
Matt Arsenault6dde3032014-03-11 00:01:34 +000072 return RI;
73 }
Tom Stellard75aadc22012-12-11 21:25:42 +000074
Matt Arsenaulta48b8662015-04-23 23:34:48 +000075 bool isReallyTriviallyReMaterializable(const MachineInstr *MI,
76 AliasAnalysis *AA) const override;
77
Matt Arsenaultc10853f2014-08-06 00:29:43 +000078 bool areLoadsFromSameBasePtr(SDNode *Load1, SDNode *Load2,
79 int64_t &Offset1,
80 int64_t &Offset2) const override;
81
Sanjoy Dasb666ea32015-06-15 18:44:14 +000082 bool getMemOpBaseRegImmOfs(MachineInstr *LdSt, unsigned &BaseReg,
83 unsigned &Offset,
84 const TargetRegisterInfo *TRI) const final;
Matt Arsenault1acc72f2014-07-29 21:34:55 +000085
Matt Arsenault0e75a062014-09-17 17:48:30 +000086 bool shouldClusterLoads(MachineInstr *FirstLdSt,
87 MachineInstr *SecondLdSt,
88 unsigned NumLoads) const final;
89
Craig Topper5656db42014-04-29 07:57:24 +000090 void copyPhysReg(MachineBasicBlock &MBB,
91 MachineBasicBlock::iterator MI, DebugLoc DL,
92 unsigned DestReg, unsigned SrcReg,
93 bool KillSrc) const override;
Tom Stellard75aadc22012-12-11 21:25:42 +000094
Tom Stellard96468902014-09-24 01:33:17 +000095 unsigned calculateLDSSpillAddress(MachineBasicBlock &MBB,
96 MachineBasicBlock::iterator MI,
97 RegScavenger *RS,
98 unsigned TmpReg,
99 unsigned Offset,
100 unsigned Size) const;
101
Tom Stellardc149dc02013-11-27 21:23:35 +0000102 void storeRegToStackSlot(MachineBasicBlock &MBB,
103 MachineBasicBlock::iterator MI,
104 unsigned SrcReg, bool isKill, int FrameIndex,
105 const TargetRegisterClass *RC,
Craig Topper5656db42014-04-29 07:57:24 +0000106 const TargetRegisterInfo *TRI) const override;
Tom Stellardc149dc02013-11-27 21:23:35 +0000107
108 void loadRegFromStackSlot(MachineBasicBlock &MBB,
109 MachineBasicBlock::iterator MI,
110 unsigned DestReg, int FrameIndex,
111 const TargetRegisterClass *RC,
Craig Topper5656db42014-04-29 07:57:24 +0000112 const TargetRegisterInfo *TRI) const override;
Tom Stellardc149dc02013-11-27 21:23:35 +0000113
Benjamin Kramer8c90fd72014-09-03 11:41:21 +0000114 bool expandPostRAPseudo(MachineBasicBlock::iterator MI) const override;
Tom Stellardeba61072014-05-02 15:41:42 +0000115
Tom Stellardef3b8642015-01-07 19:56:17 +0000116 // \brief Returns an opcode that can be used to move a value to a \p DstRC
117 // register. If there is no hardware instruction that can store to \p
118 // DstRC, then AMDGPU::COPY is returned.
119 unsigned getMovOpcode(const TargetRegisterClass *DstRC) const;
Matt Arsenaultf5b2cd82015-03-23 18:45:30 +0000120 unsigned commuteOpcode(const MachineInstr &MI) const;
Christian Konig3c145802013-03-27 09:12:59 +0000121
Craig Topper5656db42014-04-29 07:57:24 +0000122 MachineInstr *commuteInstruction(MachineInstr *MI,
Matt Arsenault92befe72014-09-26 17:54:54 +0000123 bool NewMI = false) const override;
124 bool findCommutedOpIndices(MachineInstr *MI,
125 unsigned &SrcOpIdx1,
126 unsigned &SrcOpIdx2) const override;
Christian Konig76edd4f2013-02-26 17:52:29 +0000127
Tom Stellard30f59412014-03-31 14:01:56 +0000128 bool isTriviallyReMaterializable(const MachineInstr *MI,
Craig Toppere73658d2014-04-28 04:05:08 +0000129 AliasAnalysis *AA = nullptr) const;
Tom Stellard30f59412014-03-31 14:01:56 +0000130
Matt Arsenaultc09cc3c2014-11-19 00:01:31 +0000131 bool areMemAccessesTriviallyDisjoint(
132 MachineInstr *MIa, MachineInstr *MIb,
133 AliasAnalysis *AA = nullptr) const override;
134
Tom Stellard26a3b672013-10-22 18:19:10 +0000135 MachineInstr *buildMovInstr(MachineBasicBlock *MBB,
136 MachineBasicBlock::iterator I,
Craig Topper5656db42014-04-29 07:57:24 +0000137 unsigned DstReg, unsigned SrcReg) const override;
138 bool isMov(unsigned Opcode) const override;
Tom Stellard75aadc22012-12-11 21:25:42 +0000139
Craig Topper5656db42014-04-29 07:57:24 +0000140 bool isSafeToMoveRegClassDefs(const TargetRegisterClass *RC) const override;
Matt Arsenaultc5f174d2014-12-01 15:52:46 +0000141
Matt Arsenault0325d3d2015-02-21 21:29:07 +0000142 bool FoldImmediate(MachineInstr *UseMI, MachineInstr *DefMI,
143 unsigned Reg, MachineRegisterInfo *MRI) const final;
144
Tom Stellardf01af292015-05-09 00:56:07 +0000145 unsigned getMachineCSELookAheadLimit() const override { return 500; }
146
Matt Arsenaultc5f174d2014-12-01 15:52:46 +0000147 bool isSALU(uint16_t Opcode) const {
148 return get(Opcode).TSFlags & SIInstrFlags::SALU;
149 }
150
151 bool isVALU(uint16_t Opcode) const {
152 return get(Opcode).TSFlags & SIInstrFlags::VALU;
153 }
154
155 bool isSOP1(uint16_t Opcode) const {
156 return get(Opcode).TSFlags & SIInstrFlags::SOP1;
157 }
158
159 bool isSOP2(uint16_t Opcode) const {
160 return get(Opcode).TSFlags & SIInstrFlags::SOP2;
161 }
162
163 bool isSOPC(uint16_t Opcode) const {
164 return get(Opcode).TSFlags & SIInstrFlags::SOPC;
165 }
166
167 bool isSOPK(uint16_t Opcode) const {
168 return get(Opcode).TSFlags & SIInstrFlags::SOPK;
169 }
170
171 bool isSOPP(uint16_t Opcode) const {
172 return get(Opcode).TSFlags & SIInstrFlags::SOPP;
173 }
174
175 bool isVOP1(uint16_t Opcode) const {
176 return get(Opcode).TSFlags & SIInstrFlags::VOP1;
177 }
178
179 bool isVOP2(uint16_t Opcode) const {
180 return get(Opcode).TSFlags & SIInstrFlags::VOP2;
181 }
182
183 bool isVOP3(uint16_t Opcode) const {
184 return get(Opcode).TSFlags & SIInstrFlags::VOP3;
185 }
186
187 bool isVOPC(uint16_t Opcode) const {
188 return get(Opcode).TSFlags & SIInstrFlags::VOPC;
189 }
190
191 bool isMUBUF(uint16_t Opcode) const {
192 return get(Opcode).TSFlags & SIInstrFlags::MUBUF;
193 }
194
195 bool isMTBUF(uint16_t Opcode) const {
196 return get(Opcode).TSFlags & SIInstrFlags::MTBUF;
197 }
198
199 bool isSMRD(uint16_t Opcode) const {
200 return get(Opcode).TSFlags & SIInstrFlags::SMRD;
201 }
202
203 bool isDS(uint16_t Opcode) const {
204 return get(Opcode).TSFlags & SIInstrFlags::DS;
205 }
206
207 bool isMIMG(uint16_t Opcode) const {
208 return get(Opcode).TSFlags & SIInstrFlags::MIMG;
209 }
210
211 bool isFLAT(uint16_t Opcode) const {
212 return get(Opcode).TSFlags & SIInstrFlags::FLAT;
213 }
Matt Arsenaultc09cc3c2014-11-19 00:01:31 +0000214
Michel Danzer494391b2015-02-06 02:51:20 +0000215 bool isWQM(uint16_t Opcode) const {
216 return get(Opcode).TSFlags & SIInstrFlags::WQM;
217 }
218
Tom Stellarda77c3f72015-05-12 18:59:17 +0000219 bool isVGPRSpill(uint16_t Opcode) const {
220 return get(Opcode).TSFlags & SIInstrFlags::VGPRSpill;
221 }
222
Matt Arsenaultd7bdcc42014-03-31 19:54:27 +0000223 bool isInlineConstant(const APInt &Imm) const;
Matt Arsenault11a4d672015-02-13 19:05:03 +0000224 bool isInlineConstant(const MachineOperand &MO, unsigned OpSize) const;
225 bool isLiteralConstant(const MachineOperand &MO, unsigned OpSize) const;
Tom Stellardf3b2a1e2013-02-06 17:32:29 +0000226
Tom Stellardb02094e2014-07-21 15:45:01 +0000227 bool isImmOperandLegal(const MachineInstr *MI, unsigned OpNo,
228 const MachineOperand &MO) const;
229
Tom Stellard86d12eb2014-08-01 00:32:28 +0000230 /// \brief Return true if this 64-bit VALU instruction has a 32-bit encoding.
231 /// This function will return false if you pass it a 32-bit instruction.
232 bool hasVALU32BitEncoding(unsigned Opcode) const;
233
Tom Stellard73ae1cb2014-09-23 21:26:25 +0000234 /// \brief Returns true if this operand uses the constant bus.
235 bool usesConstantBus(const MachineRegisterInfo &MRI,
Matt Arsenault11a4d672015-02-13 19:05:03 +0000236 const MachineOperand &MO,
237 unsigned OpSize) const;
Tom Stellard73ae1cb2014-09-23 21:26:25 +0000238
Tom Stellardb4a313a2014-08-01 00:32:39 +0000239 /// \brief Return true if this instruction has any modifiers.
240 /// e.g. src[012]_mod, omod, clamp.
241 bool hasModifiers(unsigned Opcode) const;
Matt Arsenaultace5b762014-10-17 18:00:43 +0000242
243 bool hasModifiersSet(const MachineInstr &MI,
244 unsigned OpName) const;
245
Craig Topper5656db42014-04-29 07:57:24 +0000246 bool verifyInstruction(const MachineInstr *MI,
247 StringRef &ErrInfo) const override;
Tom Stellardf3b2a1e2013-02-06 17:32:29 +0000248
Matt Arsenaultf14032a2013-11-15 22:02:28 +0000249 static unsigned getVALUOp(const MachineInstr &MI);
Matt Arsenaultf35182c2014-03-24 20:08:05 +0000250
Tom Stellard82166022013-11-13 23:36:37 +0000251 bool isSALUOpSupportedOnVALU(const MachineInstr &MI) const;
252
253 /// \brief Return the correct register class for \p OpNo. For target-specific
254 /// instructions, this will return the register class that has been defined
255 /// in tablegen. For generic instructions, like REG_SEQUENCE it will return
256 /// the register class of its machine operand.
257 /// to infer the correct register class base on the other operands.
258 const TargetRegisterClass *getOpRegClass(const MachineInstr &MI,
Matt Arsenault11a4d672015-02-13 19:05:03 +0000259 unsigned OpNo) const;
260
261 /// \brief Return the size in bytes of the operand OpNo on the given
262 // instruction opcode.
263 unsigned getOpSize(uint16_t Opcode, unsigned OpNo) const {
264 const MCOperandInfo &OpInfo = get(Opcode).OpInfo[OpNo];
Matt Arsenault657b1cb2015-02-21 21:29:04 +0000265
266 if (OpInfo.RegClass == -1) {
267 // If this is an immediate operand, this must be a 32-bit literal.
268 assert(OpInfo.OperandType == MCOI::OPERAND_IMMEDIATE);
269 return 4;
270 }
271
Matt Arsenault11a4d672015-02-13 19:05:03 +0000272 return RI.getRegClass(OpInfo.RegClass)->getSize();
273 }
274
275 /// \brief This form should usually be preferred since it handles operands
276 /// with unknown register classes.
277 unsigned getOpSize(const MachineInstr &MI, unsigned OpNo) const {
278 return getOpRegClass(MI, OpNo)->getSize();
279 }
Tom Stellard82166022013-11-13 23:36:37 +0000280
281 /// \returns true if it is legal for the operand at index \p OpNo
282 /// to read a VGPR.
283 bool canReadVGPR(const MachineInstr &MI, unsigned OpNo) const;
284
285 /// \brief Legalize the \p OpIndex operand of this instruction by inserting
286 /// a MOV. For example:
287 /// ADD_I32_e32 VGPR0, 15
288 /// to
289 /// MOV VGPR1, 15
290 /// ADD_I32_e32 VGPR0, VGPR1
291 ///
292 /// If the operand being legalized is a register, then a COPY will be used
293 /// instead of MOV.
294 void legalizeOpWithMove(MachineInstr *MI, unsigned OpIdx) const;
295
Tom Stellard0e975cf2014-08-01 00:32:35 +0000296 /// \brief Check if \p MO is a legal operand if it was the \p OpIdx Operand
297 /// for \p MI.
298 bool isOperandLegal(const MachineInstr *MI, unsigned OpIdx,
299 const MachineOperand *MO = nullptr) const;
300
Tom Stellard82166022013-11-13 23:36:37 +0000301 /// \brief Legalize all operands in this instruction. This function may
302 /// create new instruction and insert them before \p MI.
303 void legalizeOperands(MachineInstr *MI) const;
304
Tom Stellard745f2ed2014-08-21 20:41:00 +0000305 /// \brief Split an SMRD instruction into two smaller loads of half the
306 // size storing the results in \p Lo and \p Hi.
307 void splitSMRD(MachineInstr *MI, const TargetRegisterClass *HalfRC,
308 unsigned HalfImmOp, unsigned HalfSGPROp,
309 MachineInstr *&Lo, MachineInstr *&Hi) const;
310
Tom Stellard0c354f22014-04-30 15:31:29 +0000311 void moveSMRDToVALU(MachineInstr *MI, MachineRegisterInfo &MRI) const;
312
Tom Stellard82166022013-11-13 23:36:37 +0000313 /// \brief Replace this instruction's opcode with the equivalent VALU
314 /// opcode. This function will also move the users of \p MI to the
315 /// VALU if necessary.
316 void moveToVALU(MachineInstr &MI) const;
317
Craig Topper5656db42014-04-29 07:57:24 +0000318 unsigned calculateIndirectAddress(unsigned RegIndex,
319 unsigned Channel) const override;
Tom Stellardf3b2a1e2013-02-06 17:32:29 +0000320
Craig Topper5656db42014-04-29 07:57:24 +0000321 const TargetRegisterClass *getIndirectAddrRegClass() const override;
Tom Stellardf3b2a1e2013-02-06 17:32:29 +0000322
Craig Topper5656db42014-04-29 07:57:24 +0000323 MachineInstrBuilder buildIndirectWrite(MachineBasicBlock *MBB,
324 MachineBasicBlock::iterator I,
325 unsigned ValueReg,
326 unsigned Address,
327 unsigned OffsetReg) const override;
Tom Stellardf3b2a1e2013-02-06 17:32:29 +0000328
Craig Topper5656db42014-04-29 07:57:24 +0000329 MachineInstrBuilder buildIndirectRead(MachineBasicBlock *MBB,
330 MachineBasicBlock::iterator I,
331 unsigned ValueReg,
332 unsigned Address,
333 unsigned OffsetReg) const override;
Tom Stellard81d871d2013-11-13 23:36:50 +0000334 void reserveIndirectRegisters(BitVector &Reserved,
335 const MachineFunction &MF) const;
336
337 void LoadM0(MachineInstr *MoveRel, MachineBasicBlock::iterator I,
338 unsigned SavReg, unsigned IndexReg) const;
Tom Stellardeba61072014-05-02 15:41:42 +0000339
340 void insertNOPs(MachineBasicBlock::iterator MI, int Count) const;
Tom Stellard1aaad692014-07-21 16:55:33 +0000341
342 /// \brief Returns the operand named \p Op. If \p MI does not have an
343 /// operand named \c Op, this function returns nullptr.
Tom Stellard6407e1e2014-08-01 00:32:33 +0000344 MachineOperand *getNamedOperand(MachineInstr &MI, unsigned OperandName) const;
Matt Arsenaultace5b762014-10-17 18:00:43 +0000345
346 const MachineOperand *getNamedOperand(const MachineInstr &MI,
347 unsigned OpName) const {
348 return getNamedOperand(const_cast<MachineInstr &>(MI), OpName);
349 }
Tom Stellard794c8c02014-12-02 17:05:41 +0000350
351 uint64_t getDefaultRsrcDataFormat() const;
352
Tom Stellard81d871d2013-11-13 23:36:50 +0000353};
Tom Stellard75aadc22012-12-11 21:25:42 +0000354
Christian Konigf741fbf2013-02-26 17:52:42 +0000355namespace AMDGPU {
356
357 int getVOPe64(uint16_t Opcode);
Tom Stellard1aaad692014-07-21 16:55:33 +0000358 int getVOPe32(uint16_t Opcode);
Christian Konig3c145802013-03-27 09:12:59 +0000359 int getCommuteRev(uint16_t Opcode);
360 int getCommuteOrig(uint16_t Opcode);
Tom Stellard155bbb72014-08-11 22:18:17 +0000361 int getAddr64Inst(uint16_t Opcode);
Matt Arsenault9903ccf2014-09-08 15:07:27 +0000362 int getAtomicRetOp(uint16_t Opcode);
363 int getAtomicNoRetOp(uint16_t Opcode);
Christian Konigf741fbf2013-02-26 17:52:42 +0000364
Tom Stellard15834092014-03-21 15:51:57 +0000365 const uint64_t RSRC_DATA_FORMAT = 0xf00000000000LL;
Tom Stellardb02094e2014-07-21 15:45:01 +0000366 const uint64_t RSRC_TID_ENABLE = 1LL << 55;
Tom Stellard15834092014-03-21 15:51:57 +0000367
Christian Konigf741fbf2013-02-26 17:52:42 +0000368} // End namespace AMDGPU
369
Tom Stellardec2e43c2014-09-22 15:35:29 +0000370namespace SI {
371namespace KernelInputOffsets {
372
373/// Offsets in bytes from the start of the input buffer
374enum Offsets {
375 NGROUPS_X = 0,
376 NGROUPS_Y = 4,
377 NGROUPS_Z = 8,
378 GLOBAL_SIZE_X = 12,
379 GLOBAL_SIZE_Y = 16,
380 GLOBAL_SIZE_Z = 20,
381 LOCAL_SIZE_X = 24,
382 LOCAL_SIZE_Y = 28,
383 LOCAL_SIZE_Z = 32
384};
385
386} // End namespace KernelInputOffsets
387} // End namespace SI
388
Tom Stellard75aadc22012-12-11 21:25:42 +0000389} // End namespace llvm
390
Benjamin Kramera7c40ef2014-08-13 16:26:38 +0000391#endif