blob: a5cd2e18ef47698e41afe38f8f200d7a331eed48 [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
Matt Arsenault6b6a2c32016-03-11 08:00:27 +000016#ifndef LLVM_LIB_TARGET_AMDGPU_SIINSTRINFO_H
17#define LLVM_LIB_TARGET_AMDGPU_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
Matt Arsenault6b6a2c32016-03-11 08:00:27 +000025class SIInstrInfo final : public AMDGPUInstrInfo {
Tom Stellard75aadc22012-12-11 21:25:42 +000026private:
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
Marek Olsak7ed6b2f2015-11-25 21:22:45 +000044 void lowerScalarAbs(SmallVectorImpl<MachineInstr *> &Worklist,
45 MachineInstr *Inst) const;
46
Matt Arsenault689f3252014-06-09 16:36:31 +000047 void splitScalar64BitUnaryOp(SmallVectorImpl<MachineInstr *> &Worklist,
48 MachineInstr *Inst, unsigned Opcode) const;
49
50 void splitScalar64BitBinaryOp(SmallVectorImpl<MachineInstr *> &Worklist,
51 MachineInstr *Inst, unsigned Opcode) const;
Matt Arsenaultf35182c2014-03-24 20:08:05 +000052
Matt Arsenault8333e432014-06-10 19:18:24 +000053 void splitScalar64BitBCNT(SmallVectorImpl<MachineInstr *> &Worklist,
54 MachineInstr *Inst) const;
Matt Arsenault94812212014-11-14 18:18:16 +000055 void splitScalar64BitBFE(SmallVectorImpl<MachineInstr *> &Worklist,
56 MachineInstr *Inst) const;
Matt Arsenault8333e432014-06-10 19:18:24 +000057
Matt Arsenaultf003c382015-08-26 20:47:50 +000058 void addUsersToMoveToVALUWorklist(
59 unsigned Reg, MachineRegisterInfo &MRI,
60 SmallVectorImpl<MachineInstr *> &Worklist) const;
61
Tom Stellardbc4497b2016-02-12 23:45:29 +000062 void addSCCDefUsersToVALUWorklist(
63 MachineInstr *SCCDefInst, SmallVectorImpl<MachineInstr *> &Worklist) const;
64
Matt Arsenaultba6aae72015-09-28 20:54:57 +000065 const TargetRegisterClass *
66 getDestEquivalentVGPRClass(const MachineInstr &Inst) const;
67
Matt Arsenaultc09cc3c2014-11-19 00:01:31 +000068 bool checkInstOffsetsDoNotOverlap(MachineInstr *MIa,
69 MachineInstr *MIb) const;
70
Matt Arsenaultee522bf2014-09-26 17:55:06 +000071 unsigned findUsedSGPR(const MachineInstr *MI, int OpIndices[3]) const;
72
Andrew Kaylor16c4da02015-09-28 20:33:22 +000073protected:
74 MachineInstr *commuteInstructionImpl(MachineInstr *MI,
75 bool NewMI,
76 unsigned OpIdx0,
77 unsigned OpIdx1) const override;
78
Tom Stellard75aadc22012-12-11 21:25:42 +000079public:
Tom Stellard2e59a452014-06-13 01:32:00 +000080 explicit SIInstrInfo(const AMDGPUSubtarget &st);
Tom Stellard75aadc22012-12-11 21:25:42 +000081
Craig Topper5656db42014-04-29 07:57:24 +000082 const SIRegisterInfo &getRegisterInfo() const override {
Matt Arsenault6dde3032014-03-11 00:01:34 +000083 return RI;
84 }
Tom Stellard75aadc22012-12-11 21:25:42 +000085
Matt Arsenaulta48b8662015-04-23 23:34:48 +000086 bool isReallyTriviallyReMaterializable(const MachineInstr *MI,
87 AliasAnalysis *AA) const override;
88
Matt Arsenaultc10853f2014-08-06 00:29:43 +000089 bool areLoadsFromSameBasePtr(SDNode *Load1, SDNode *Load2,
90 int64_t &Offset1,
91 int64_t &Offset2) const override;
92
Sanjoy Dasb666ea32015-06-15 18:44:14 +000093 bool getMemOpBaseRegImmOfs(MachineInstr *LdSt, unsigned &BaseReg,
Chad Rosierc27a18f2016-03-09 16:00:35 +000094 int64_t &Offset,
Sanjoy Dasb666ea32015-06-15 18:44:14 +000095 const TargetRegisterInfo *TRI) const final;
Matt Arsenault1acc72f2014-07-29 21:34:55 +000096
Jun Bum Lim4c5bd582016-04-15 14:58:38 +000097 bool shouldClusterMemOps(MachineInstr *FirstLdSt,
98 MachineInstr *SecondLdSt,
99 unsigned NumLoads) const final;
Matt Arsenault0e75a062014-09-17 17:48:30 +0000100
Craig Topper5656db42014-04-29 07:57:24 +0000101 void copyPhysReg(MachineBasicBlock &MBB,
102 MachineBasicBlock::iterator MI, DebugLoc DL,
103 unsigned DestReg, unsigned SrcReg,
104 bool KillSrc) const override;
Tom Stellard75aadc22012-12-11 21:25:42 +0000105
Tom Stellard96468902014-09-24 01:33:17 +0000106 unsigned calculateLDSSpillAddress(MachineBasicBlock &MBB,
107 MachineBasicBlock::iterator MI,
108 RegScavenger *RS,
109 unsigned TmpReg,
110 unsigned Offset,
111 unsigned Size) const;
112
Tom Stellardc149dc02013-11-27 21:23:35 +0000113 void storeRegToStackSlot(MachineBasicBlock &MBB,
114 MachineBasicBlock::iterator MI,
115 unsigned SrcReg, bool isKill, int FrameIndex,
116 const TargetRegisterClass *RC,
Craig Topper5656db42014-04-29 07:57:24 +0000117 const TargetRegisterInfo *TRI) const override;
Tom Stellardc149dc02013-11-27 21:23:35 +0000118
119 void loadRegFromStackSlot(MachineBasicBlock &MBB,
120 MachineBasicBlock::iterator MI,
121 unsigned DestReg, int FrameIndex,
122 const TargetRegisterClass *RC,
Craig Topper5656db42014-04-29 07:57:24 +0000123 const TargetRegisterInfo *TRI) const override;
Tom Stellardc149dc02013-11-27 21:23:35 +0000124
Benjamin Kramer8c90fd72014-09-03 11:41:21 +0000125 bool expandPostRAPseudo(MachineBasicBlock::iterator MI) const override;
Tom Stellardeba61072014-05-02 15:41:42 +0000126
Tom Stellardef3b8642015-01-07 19:56:17 +0000127 // \brief Returns an opcode that can be used to move a value to a \p DstRC
128 // register. If there is no hardware instruction that can store to \p
129 // DstRC, then AMDGPU::COPY is returned.
130 unsigned getMovOpcode(const TargetRegisterClass *DstRC) const;
Matt Arsenaultfa242962015-09-24 07:51:23 +0000131
132 LLVM_READONLY
Marek Olsakcfbdba22015-06-26 20:29:10 +0000133 int commuteOpcode(const MachineInstr &MI) const;
Christian Konig3c145802013-03-27 09:12:59 +0000134
Matt Arsenault92befe72014-09-26 17:54:54 +0000135 bool findCommutedOpIndices(MachineInstr *MI,
136 unsigned &SrcOpIdx1,
137 unsigned &SrcOpIdx2) const override;
Christian Konig76edd4f2013-02-26 17:52:29 +0000138
Matt Arsenaultc09cc3c2014-11-19 00:01:31 +0000139 bool areMemAccessesTriviallyDisjoint(
140 MachineInstr *MIa, MachineInstr *MIb,
141 AliasAnalysis *AA = nullptr) const override;
142
Matt Arsenault0325d3d2015-02-21 21:29:07 +0000143 bool FoldImmediate(MachineInstr *UseMI, MachineInstr *DefMI,
144 unsigned Reg, MachineRegisterInfo *MRI) const final;
145
Tom Stellardf01af292015-05-09 00:56:07 +0000146 unsigned getMachineCSELookAheadLimit() const override { return 500; }
147
Tom Stellarddb5a11f2015-07-13 15:47:57 +0000148 MachineInstr *convertToThreeAddress(MachineFunction::iterator &MBB,
149 MachineBasicBlock::iterator &MI,
150 LiveVariables *LV) const override;
151
Nicolai Haehnle213e87f2016-03-21 20:28:33 +0000152 bool isSchedulingBoundary(const MachineInstr *MI,
153 const MachineBasicBlock *MBB,
154 const MachineFunction &MF) const override;
155
Matt Arsenault3add6432015-10-20 04:35:43 +0000156 static bool isSALU(const MachineInstr &MI) {
157 return MI.getDesc().TSFlags & SIInstrFlags::SALU;
158 }
159
Matt Arsenaultc5f174d2014-12-01 15:52:46 +0000160 bool isSALU(uint16_t Opcode) const {
161 return get(Opcode).TSFlags & SIInstrFlags::SALU;
162 }
163
Matt Arsenault3add6432015-10-20 04:35:43 +0000164 static bool isVALU(const MachineInstr &MI) {
165 return MI.getDesc().TSFlags & SIInstrFlags::VALU;
166 }
167
Matt Arsenaultc5f174d2014-12-01 15:52:46 +0000168 bool isVALU(uint16_t Opcode) const {
169 return get(Opcode).TSFlags & SIInstrFlags::VALU;
170 }
171
Matt Arsenault3add6432015-10-20 04:35:43 +0000172 static bool isSOP1(const MachineInstr &MI) {
173 return MI.getDesc().TSFlags & SIInstrFlags::SOP1;
174 }
175
Matt Arsenaultc5f174d2014-12-01 15:52:46 +0000176 bool isSOP1(uint16_t Opcode) const {
177 return get(Opcode).TSFlags & SIInstrFlags::SOP1;
178 }
179
Matt Arsenault3add6432015-10-20 04:35:43 +0000180 static bool isSOP2(const MachineInstr &MI) {
181 return MI.getDesc().TSFlags & SIInstrFlags::SOP2;
182 }
183
Matt Arsenaultc5f174d2014-12-01 15:52:46 +0000184 bool isSOP2(uint16_t Opcode) const {
185 return get(Opcode).TSFlags & SIInstrFlags::SOP2;
186 }
187
Matt Arsenault3add6432015-10-20 04:35:43 +0000188 static bool isSOPC(const MachineInstr &MI) {
189 return MI.getDesc().TSFlags & SIInstrFlags::SOPC;
190 }
191
Matt Arsenaultc5f174d2014-12-01 15:52:46 +0000192 bool isSOPC(uint16_t Opcode) const {
193 return get(Opcode).TSFlags & SIInstrFlags::SOPC;
194 }
195
Matt Arsenault3add6432015-10-20 04:35:43 +0000196 static bool isSOPK(const MachineInstr &MI) {
197 return MI.getDesc().TSFlags & SIInstrFlags::SOPK;
198 }
199
Matt Arsenaultc5f174d2014-12-01 15:52:46 +0000200 bool isSOPK(uint16_t Opcode) const {
201 return get(Opcode).TSFlags & SIInstrFlags::SOPK;
202 }
203
Matt Arsenault3add6432015-10-20 04:35:43 +0000204 static bool isSOPP(const MachineInstr &MI) {
205 return MI.getDesc().TSFlags & SIInstrFlags::SOPP;
206 }
207
Matt Arsenaultc5f174d2014-12-01 15:52:46 +0000208 bool isSOPP(uint16_t Opcode) const {
209 return get(Opcode).TSFlags & SIInstrFlags::SOPP;
210 }
211
Matt Arsenault3add6432015-10-20 04:35:43 +0000212 static bool isVOP1(const MachineInstr &MI) {
213 return MI.getDesc().TSFlags & SIInstrFlags::VOP1;
214 }
215
Matt Arsenaultc5f174d2014-12-01 15:52:46 +0000216 bool isVOP1(uint16_t Opcode) const {
217 return get(Opcode).TSFlags & SIInstrFlags::VOP1;
218 }
219
Matt Arsenault3add6432015-10-20 04:35:43 +0000220 static bool isVOP2(const MachineInstr &MI) {
221 return MI.getDesc().TSFlags & SIInstrFlags::VOP2;
222 }
223
Matt Arsenaultc5f174d2014-12-01 15:52:46 +0000224 bool isVOP2(uint16_t Opcode) const {
225 return get(Opcode).TSFlags & SIInstrFlags::VOP2;
226 }
227
Matt Arsenault3add6432015-10-20 04:35:43 +0000228 static bool isVOP3(const MachineInstr &MI) {
229 return MI.getDesc().TSFlags & SIInstrFlags::VOP3;
230 }
231
Matt Arsenaultc5f174d2014-12-01 15:52:46 +0000232 bool isVOP3(uint16_t Opcode) const {
233 return get(Opcode).TSFlags & SIInstrFlags::VOP3;
234 }
235
Matt Arsenault3add6432015-10-20 04:35:43 +0000236 static bool isVOPC(const MachineInstr &MI) {
237 return MI.getDesc().TSFlags & SIInstrFlags::VOPC;
238 }
239
Matt Arsenaultc5f174d2014-12-01 15:52:46 +0000240 bool isVOPC(uint16_t Opcode) const {
241 return get(Opcode).TSFlags & SIInstrFlags::VOPC;
242 }
243
Matt Arsenault3add6432015-10-20 04:35:43 +0000244 static bool isMUBUF(const MachineInstr &MI) {
245 return MI.getDesc().TSFlags & SIInstrFlags::MUBUF;
246 }
247
Matt Arsenaultc5f174d2014-12-01 15:52:46 +0000248 bool isMUBUF(uint16_t Opcode) const {
249 return get(Opcode).TSFlags & SIInstrFlags::MUBUF;
250 }
251
Matt Arsenault3add6432015-10-20 04:35:43 +0000252 static bool isMTBUF(const MachineInstr &MI) {
253 return MI.getDesc().TSFlags & SIInstrFlags::MTBUF;
254 }
255
Matt Arsenaultc5f174d2014-12-01 15:52:46 +0000256 bool isMTBUF(uint16_t Opcode) const {
257 return get(Opcode).TSFlags & SIInstrFlags::MTBUF;
258 }
259
Matt Arsenault3add6432015-10-20 04:35:43 +0000260 static bool isSMRD(const MachineInstr &MI) {
261 return MI.getDesc().TSFlags & SIInstrFlags::SMRD;
262 }
263
Matt Arsenaultc5f174d2014-12-01 15:52:46 +0000264 bool isSMRD(uint16_t Opcode) const {
265 return get(Opcode).TSFlags & SIInstrFlags::SMRD;
266 }
267
Matt Arsenault3add6432015-10-20 04:35:43 +0000268 static bool isDS(const MachineInstr &MI) {
269 return MI.getDesc().TSFlags & SIInstrFlags::DS;
270 }
271
Matt Arsenaultc5f174d2014-12-01 15:52:46 +0000272 bool isDS(uint16_t Opcode) const {
273 return get(Opcode).TSFlags & SIInstrFlags::DS;
274 }
275
Matt Arsenault3add6432015-10-20 04:35:43 +0000276 static bool isMIMG(const MachineInstr &MI) {
277 return MI.getDesc().TSFlags & SIInstrFlags::MIMG;
278 }
279
Matt Arsenaultc5f174d2014-12-01 15:52:46 +0000280 bool isMIMG(uint16_t Opcode) const {
281 return get(Opcode).TSFlags & SIInstrFlags::MIMG;
282 }
283
Matt Arsenault3add6432015-10-20 04:35:43 +0000284 static bool isFLAT(const MachineInstr &MI) {
285 return MI.getDesc().TSFlags & SIInstrFlags::FLAT;
286 }
287
Matt Arsenaultc5f174d2014-12-01 15:52:46 +0000288 bool isFLAT(uint16_t Opcode) const {
289 return get(Opcode).TSFlags & SIInstrFlags::FLAT;
290 }
Matt Arsenaultc09cc3c2014-11-19 00:01:31 +0000291
Matt Arsenault3add6432015-10-20 04:35:43 +0000292 static bool isWQM(const MachineInstr &MI) {
293 return MI.getDesc().TSFlags & SIInstrFlags::WQM;
294 }
295
Michel Danzer494391b2015-02-06 02:51:20 +0000296 bool isWQM(uint16_t Opcode) const {
297 return get(Opcode).TSFlags & SIInstrFlags::WQM;
298 }
299
Matt Arsenault3add6432015-10-20 04:35:43 +0000300 static bool isVGPRSpill(const MachineInstr &MI) {
301 return MI.getDesc().TSFlags & SIInstrFlags::VGPRSpill;
302 }
303
Tom Stellarda77c3f72015-05-12 18:59:17 +0000304 bool isVGPRSpill(uint16_t Opcode) const {
305 return get(Opcode).TSFlags & SIInstrFlags::VGPRSpill;
306 }
307
Tom Stellard331f9812016-03-14 17:05:56 +0000308 static bool isDPP(const MachineInstr &MI) {
309 return MI.getDesc().TSFlags & SIInstrFlags::DPP;
310 }
311
312 bool isDPP(uint16_t Opcode) const {
313 return get(Opcode).TSFlags & SIInstrFlags::DPP;
314 }
315
Matt Arsenaultd7bdcc42014-03-31 19:54:27 +0000316 bool isInlineConstant(const APInt &Imm) const;
Matt Arsenault11a4d672015-02-13 19:05:03 +0000317 bool isInlineConstant(const MachineOperand &MO, unsigned OpSize) const;
318 bool isLiteralConstant(const MachineOperand &MO, unsigned OpSize) const;
Tom Stellardf3b2a1e2013-02-06 17:32:29 +0000319
Tom Stellardb02094e2014-07-21 15:45:01 +0000320 bool isImmOperandLegal(const MachineInstr *MI, unsigned OpNo,
321 const MachineOperand &MO) const;
322
Tom Stellard86d12eb2014-08-01 00:32:28 +0000323 /// \brief Return true if this 64-bit VALU instruction has a 32-bit encoding.
324 /// This function will return false if you pass it a 32-bit instruction.
325 bool hasVALU32BitEncoding(unsigned Opcode) const;
326
Tom Stellard73ae1cb2014-09-23 21:26:25 +0000327 /// \brief Returns true if this operand uses the constant bus.
328 bool usesConstantBus(const MachineRegisterInfo &MRI,
Matt Arsenault11a4d672015-02-13 19:05:03 +0000329 const MachineOperand &MO,
330 unsigned OpSize) const;
Tom Stellard73ae1cb2014-09-23 21:26:25 +0000331
Tom Stellardb4a313a2014-08-01 00:32:39 +0000332 /// \brief Return true if this instruction has any modifiers.
333 /// e.g. src[012]_mod, omod, clamp.
334 bool hasModifiers(unsigned Opcode) const;
Matt Arsenaultace5b762014-10-17 18:00:43 +0000335
336 bool hasModifiersSet(const MachineInstr &MI,
337 unsigned OpName) const;
338
Craig Topper5656db42014-04-29 07:57:24 +0000339 bool verifyInstruction(const MachineInstr *MI,
340 StringRef &ErrInfo) const override;
Tom Stellardf3b2a1e2013-02-06 17:32:29 +0000341
Matt Arsenaultf14032a2013-11-15 22:02:28 +0000342 static unsigned getVALUOp(const MachineInstr &MI);
Matt Arsenaultf35182c2014-03-24 20:08:05 +0000343
Tom Stellard82166022013-11-13 23:36:37 +0000344 bool isSALUOpSupportedOnVALU(const MachineInstr &MI) const;
345
346 /// \brief Return the correct register class for \p OpNo. For target-specific
347 /// instructions, this will return the register class that has been defined
348 /// in tablegen. For generic instructions, like REG_SEQUENCE it will return
349 /// the register class of its machine operand.
350 /// to infer the correct register class base on the other operands.
351 const TargetRegisterClass *getOpRegClass(const MachineInstr &MI,
Matt Arsenault11a4d672015-02-13 19:05:03 +0000352 unsigned OpNo) const;
353
354 /// \brief Return the size in bytes of the operand OpNo on the given
355 // instruction opcode.
356 unsigned getOpSize(uint16_t Opcode, unsigned OpNo) const {
357 const MCOperandInfo &OpInfo = get(Opcode).OpInfo[OpNo];
Matt Arsenault657b1cb2015-02-21 21:29:04 +0000358
359 if (OpInfo.RegClass == -1) {
360 // If this is an immediate operand, this must be a 32-bit literal.
361 assert(OpInfo.OperandType == MCOI::OPERAND_IMMEDIATE);
362 return 4;
363 }
364
Matt Arsenault11a4d672015-02-13 19:05:03 +0000365 return RI.getRegClass(OpInfo.RegClass)->getSize();
366 }
367
368 /// \brief This form should usually be preferred since it handles operands
369 /// with unknown register classes.
370 unsigned getOpSize(const MachineInstr &MI, unsigned OpNo) const {
371 return getOpRegClass(MI, OpNo)->getSize();
372 }
Tom Stellard82166022013-11-13 23:36:37 +0000373
374 /// \returns true if it is legal for the operand at index \p OpNo
375 /// to read a VGPR.
376 bool canReadVGPR(const MachineInstr &MI, unsigned OpNo) const;
377
378 /// \brief Legalize the \p OpIndex operand of this instruction by inserting
379 /// a MOV. For example:
380 /// ADD_I32_e32 VGPR0, 15
381 /// to
382 /// MOV VGPR1, 15
383 /// ADD_I32_e32 VGPR0, VGPR1
384 ///
385 /// If the operand being legalized is a register, then a COPY will be used
386 /// instead of MOV.
387 void legalizeOpWithMove(MachineInstr *MI, unsigned OpIdx) const;
388
Tom Stellard0e975cf2014-08-01 00:32:35 +0000389 /// \brief Check if \p MO is a legal operand if it was the \p OpIdx Operand
390 /// for \p MI.
391 bool isOperandLegal(const MachineInstr *MI, unsigned OpIdx,
392 const MachineOperand *MO = nullptr) const;
393
Matt Arsenault856d1922015-12-01 19:57:17 +0000394 /// \brief Check if \p MO would be a valid operand for the given operand
395 /// definition \p OpInfo. Note this does not attempt to validate constant bus
396 /// restrictions (e.g. literal constant usage).
397 bool isLegalVSrcOperand(const MachineRegisterInfo &MRI,
398 const MCOperandInfo &OpInfo,
399 const MachineOperand &MO) const;
400
401 /// \brief Check if \p MO (a register operand) is a legal register for the
402 /// given operand description.
403 bool isLegalRegOperand(const MachineRegisterInfo &MRI,
404 const MCOperandInfo &OpInfo,
405 const MachineOperand &MO) const;
406
407 /// \brief Legalize operands in \p MI by either commuting it or inserting a
408 /// copy of src1.
409 void legalizeOperandsVOP2(MachineRegisterInfo &MRI, MachineInstr *MI) const;
410
Matt Arsenault6005fcb2015-10-21 21:51:02 +0000411 /// \brief Fix operands in \p MI to satisfy constant bus requirements.
412 void legalizeOperandsVOP3(MachineRegisterInfo &MRI, MachineInstr *MI) const;
413
Tom Stellard1397d492016-02-11 21:45:07 +0000414 /// Copy a value from a VGPR (\p SrcReg) to SGPR. This function can only
415 /// be used when it is know that the value in SrcReg is same across all
416 /// threads in the wave.
417 /// \returns The SGPR register that \p SrcReg was copied to.
418 unsigned readlaneVGPRToSGPR(unsigned SrcReg, MachineInstr *UseMI,
419 MachineRegisterInfo &MRI) const;
420
Tom Stellard467b5b92016-02-20 00:37:25 +0000421 void legalizeOperandsSMRD(MachineRegisterInfo &MRI, MachineInstr *MI) const;
422
Tom Stellard82166022013-11-13 23:36:37 +0000423 /// \brief Legalize all operands in this instruction. This function may
424 /// create new instruction and insert them before \p MI.
425 void legalizeOperands(MachineInstr *MI) const;
426
427 /// \brief Replace this instruction's opcode with the equivalent VALU
428 /// opcode. This function will also move the users of \p MI to the
429 /// VALU if necessary.
430 void moveToVALU(MachineInstr &MI) const;
431
Craig Topper5656db42014-04-29 07:57:24 +0000432 const TargetRegisterClass *getIndirectAddrRegClass() const override;
Tom Stellardf3b2a1e2013-02-06 17:32:29 +0000433
Tom Stellard81d871d2013-11-13 23:36:50 +0000434 void reserveIndirectRegisters(BitVector &Reserved,
435 const MachineFunction &MF) const;
436
437 void LoadM0(MachineInstr *MoveRel, MachineBasicBlock::iterator I,
438 unsigned SavReg, unsigned IndexReg) const;
Tom Stellardeba61072014-05-02 15:41:42 +0000439
Tom Stellardd37630e2016-04-07 14:47:07 +0000440 void insertWaitStates(MachineBasicBlock &MBB,MachineBasicBlock::iterator MI,
441 int Count) const;
Tom Stellard1aaad692014-07-21 16:55:33 +0000442
443 /// \brief Returns the operand named \p Op. If \p MI does not have an
444 /// operand named \c Op, this function returns nullptr.
Matt Arsenaultf743b832015-09-25 18:09:15 +0000445 LLVM_READONLY
Tom Stellard6407e1e2014-08-01 00:32:33 +0000446 MachineOperand *getNamedOperand(MachineInstr &MI, unsigned OperandName) const;
Matt Arsenaultace5b762014-10-17 18:00:43 +0000447
Matt Arsenaultf743b832015-09-25 18:09:15 +0000448 LLVM_READONLY
Matt Arsenaultace5b762014-10-17 18:00:43 +0000449 const MachineOperand *getNamedOperand(const MachineInstr &MI,
450 unsigned OpName) const {
451 return getNamedOperand(const_cast<MachineInstr &>(MI), OpName);
452 }
Tom Stellard794c8c02014-12-02 17:05:41 +0000453
Matt Arsenaulta40450c2015-11-05 02:46:56 +0000454 /// Get required immediate operand
455 int64_t getNamedImmOperand(const MachineInstr &MI, unsigned OpName) const {
456 int Idx = AMDGPU::getNamedOperandIdx(MI.getOpcode(), OpName);
457 return MI.getOperand(Idx).getImm();
458 }
459
Tom Stellard794c8c02014-12-02 17:05:41 +0000460 uint64_t getDefaultRsrcDataFormat() const;
Marek Olsakd1a69a22015-09-29 23:37:32 +0000461 uint64_t getScratchRsrcWords23() const;
Nicolai Haehnle02c32912016-01-13 16:10:10 +0000462
463 bool isLowLatencyInstruction(const MachineInstr *MI) const;
464 bool isHighLatencyInstruction(const MachineInstr *MI) const;
Tom Stellard2ff72622016-01-28 16:04:37 +0000465
466 /// \brief Return the descriptor of the target-specific machine instruction
467 /// that corresponds to the specified pseudo or native opcode.
468 const MCInstrDesc &getMCOpcodeFromPseudo(unsigned Opcode) const {
469 return get(pseudoToMCOpcode(Opcode));
470 }
471
472 ArrayRef<std::pair<int, const char *>>
473 getSerializableTargetIndices() const override;
474
Tom Stellard81d871d2013-11-13 23:36:50 +0000475};
Tom Stellard75aadc22012-12-11 21:25:42 +0000476
Christian Konigf741fbf2013-02-26 17:52:42 +0000477namespace AMDGPU {
Matt Arsenaultfa242962015-09-24 07:51:23 +0000478 LLVM_READONLY
Christian Konigf741fbf2013-02-26 17:52:42 +0000479 int getVOPe64(uint16_t Opcode);
Matt Arsenaultfa242962015-09-24 07:51:23 +0000480
481 LLVM_READONLY
Tom Stellard1aaad692014-07-21 16:55:33 +0000482 int getVOPe32(uint16_t Opcode);
Matt Arsenaultfa242962015-09-24 07:51:23 +0000483
484 LLVM_READONLY
Christian Konig3c145802013-03-27 09:12:59 +0000485 int getCommuteRev(uint16_t Opcode);
Matt Arsenaultfa242962015-09-24 07:51:23 +0000486
487 LLVM_READONLY
Christian Konig3c145802013-03-27 09:12:59 +0000488 int getCommuteOrig(uint16_t Opcode);
Matt Arsenaultfa242962015-09-24 07:51:23 +0000489
490 LLVM_READONLY
Tom Stellard155bbb72014-08-11 22:18:17 +0000491 int getAddr64Inst(uint16_t Opcode);
Matt Arsenaultfa242962015-09-24 07:51:23 +0000492
493 LLVM_READONLY
Matt Arsenault9903ccf2014-09-08 15:07:27 +0000494 int getAtomicRetOp(uint16_t Opcode);
Matt Arsenaultfa242962015-09-24 07:51:23 +0000495
496 LLVM_READONLY
Matt Arsenault9903ccf2014-09-08 15:07:27 +0000497 int getAtomicNoRetOp(uint16_t Opcode);
Christian Konigf741fbf2013-02-26 17:52:42 +0000498
Tom Stellard15834092014-03-21 15:51:57 +0000499 const uint64_t RSRC_DATA_FORMAT = 0xf00000000000LL;
Tom Stellardb02094e2014-07-21 15:45:01 +0000500 const uint64_t RSRC_TID_ENABLE = 1LL << 55;
Matt Arsenault24ee0782016-02-12 02:40:47 +0000501 const uint64_t RSRC_ELEMENT_SIZE_SHIFT = 51;
Christian Konigf741fbf2013-02-26 17:52:42 +0000502} // End namespace AMDGPU
503
Tom Stellardec2e43c2014-09-22 15:35:29 +0000504namespace SI {
505namespace KernelInputOffsets {
506
507/// Offsets in bytes from the start of the input buffer
508enum Offsets {
509 NGROUPS_X = 0,
510 NGROUPS_Y = 4,
511 NGROUPS_Z = 8,
512 GLOBAL_SIZE_X = 12,
513 GLOBAL_SIZE_Y = 16,
514 GLOBAL_SIZE_Z = 20,
515 LOCAL_SIZE_X = 24,
516 LOCAL_SIZE_Y = 28,
517 LOCAL_SIZE_Z = 32
518};
519
520} // End namespace KernelInputOffsets
521} // End namespace SI
522
Tom Stellard75aadc22012-12-11 21:25:42 +0000523} // End namespace llvm
524
Benjamin Kramera7c40ef2014-08-13 16:26:38 +0000525#endif