1 //===-- SIInstrInfo.h - SI Instruction Info Interface -----------*- C++ -*-===//
3 // The LLVM Compiler Infrastructure
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
8 //===----------------------------------------------------------------------===//
11 /// \brief Interface definition for SIInstrInfo.
13 //===----------------------------------------------------------------------===//
16 #ifndef LLVM_LIB_TARGET_R600_SIINSTRINFO_H
17 #define LLVM_LIB_TARGET_R600_SIINSTRINFO_H
19 #include "AMDGPUInstrInfo.h"
20 #include "SIDefines.h"
21 #include "SIRegisterInfo.h"
25 class SIInstrInfo : public AMDGPUInstrInfo {
27 const SIRegisterInfo RI;
29 unsigned buildExtractSubReg(MachineBasicBlock::iterator MI,
30 MachineRegisterInfo &MRI,
31 MachineOperand &SuperReg,
32 const TargetRegisterClass *SuperRC,
34 const TargetRegisterClass *SubRC) const;
35 MachineOperand buildExtractSubRegOrImm(MachineBasicBlock::iterator MI,
36 MachineRegisterInfo &MRI,
37 MachineOperand &SuperReg,
38 const TargetRegisterClass *SuperRC,
40 const TargetRegisterClass *SubRC) const;
42 void swapOperands(MachineBasicBlock::iterator Inst) const;
44 void splitScalar64BitUnaryOp(SmallVectorImpl<MachineInstr *> &Worklist,
45 MachineInstr *Inst, unsigned Opcode) const;
47 void splitScalar64BitBinaryOp(SmallVectorImpl<MachineInstr *> &Worklist,
48 MachineInstr *Inst, unsigned Opcode) const;
50 void splitScalar64BitBCNT(SmallVectorImpl<MachineInstr *> &Worklist,
51 MachineInstr *Inst) const;
52 void splitScalar64BitBFE(SmallVectorImpl<MachineInstr *> &Worklist,
53 MachineInstr *Inst) const;
55 void addUsersToMoveToVALUWorklist(
56 unsigned Reg, MachineRegisterInfo &MRI,
57 SmallVectorImpl<MachineInstr *> &Worklist) const;
59 bool checkInstOffsetsDoNotOverlap(MachineInstr *MIa,
60 MachineInstr *MIb) const;
62 unsigned findUsedSGPR(const MachineInstr *MI, int OpIndices[3]) const;
65 explicit SIInstrInfo(const AMDGPUSubtarget &st);
67 const SIRegisterInfo &getRegisterInfo() const override {
71 bool isReallyTriviallyReMaterializable(const MachineInstr *MI,
72 AliasAnalysis *AA) const override;
74 bool areLoadsFromSameBasePtr(SDNode *Load1, SDNode *Load2,
76 int64_t &Offset2) const override;
78 bool getMemOpBaseRegImmOfs(MachineInstr *LdSt, unsigned &BaseReg,
80 const TargetRegisterInfo *TRI) const final;
82 bool shouldClusterLoads(MachineInstr *FirstLdSt,
83 MachineInstr *SecondLdSt,
84 unsigned NumLoads) const final;
86 void copyPhysReg(MachineBasicBlock &MBB,
87 MachineBasicBlock::iterator MI, DebugLoc DL,
88 unsigned DestReg, unsigned SrcReg,
89 bool KillSrc) const override;
91 unsigned calculateLDSSpillAddress(MachineBasicBlock &MBB,
92 MachineBasicBlock::iterator MI,
98 void storeRegToStackSlot(MachineBasicBlock &MBB,
99 MachineBasicBlock::iterator MI,
100 unsigned SrcReg, bool isKill, int FrameIndex,
101 const TargetRegisterClass *RC,
102 const TargetRegisterInfo *TRI) const override;
104 void loadRegFromStackSlot(MachineBasicBlock &MBB,
105 MachineBasicBlock::iterator MI,
106 unsigned DestReg, int FrameIndex,
107 const TargetRegisterClass *RC,
108 const TargetRegisterInfo *TRI) const override;
110 bool expandPostRAPseudo(MachineBasicBlock::iterator MI) const override;
112 // \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;
116 int commuteOpcode(const MachineInstr &MI) const;
118 MachineInstr *commuteInstruction(MachineInstr *MI,
119 bool NewMI = false) const override;
120 bool findCommutedOpIndices(MachineInstr *MI,
122 unsigned &SrcOpIdx2) const override;
124 bool areMemAccessesTriviallyDisjoint(
125 MachineInstr *MIa, MachineInstr *MIb,
126 AliasAnalysis *AA = nullptr) const override;
128 MachineInstr *buildMovInstr(MachineBasicBlock *MBB,
129 MachineBasicBlock::iterator I,
130 unsigned DstReg, unsigned SrcReg) const override;
131 bool isMov(unsigned Opcode) const override;
133 bool FoldImmediate(MachineInstr *UseMI, MachineInstr *DefMI,
134 unsigned Reg, MachineRegisterInfo *MRI) const final;
136 unsigned getMachineCSELookAheadLimit() const override { return 500; }
138 MachineInstr *convertToThreeAddress(MachineFunction::iterator &MBB,
139 MachineBasicBlock::iterator &MI,
140 LiveVariables *LV) const override;
142 bool isSALU(uint16_t Opcode) const {
143 return get(Opcode).TSFlags & SIInstrFlags::SALU;
146 bool isVALU(uint16_t Opcode) const {
147 return get(Opcode).TSFlags & SIInstrFlags::VALU;
150 bool isSOP1(uint16_t Opcode) const {
151 return get(Opcode).TSFlags & SIInstrFlags::SOP1;
154 bool isSOP2(uint16_t Opcode) const {
155 return get(Opcode).TSFlags & SIInstrFlags::SOP2;
158 bool isSOPC(uint16_t Opcode) const {
159 return get(Opcode).TSFlags & SIInstrFlags::SOPC;
162 bool isSOPK(uint16_t Opcode) const {
163 return get(Opcode).TSFlags & SIInstrFlags::SOPK;
166 bool isSOPP(uint16_t Opcode) const {
167 return get(Opcode).TSFlags & SIInstrFlags::SOPP;
170 bool isVOP1(uint16_t Opcode) const {
171 return get(Opcode).TSFlags & SIInstrFlags::VOP1;
174 bool isVOP2(uint16_t Opcode) const {
175 return get(Opcode).TSFlags & SIInstrFlags::VOP2;
178 bool isVOP3(uint16_t Opcode) const {
179 return get(Opcode).TSFlags & SIInstrFlags::VOP3;
182 bool isVOPC(uint16_t Opcode) const {
183 return get(Opcode).TSFlags & SIInstrFlags::VOPC;
186 bool isMUBUF(uint16_t Opcode) const {
187 return get(Opcode).TSFlags & SIInstrFlags::MUBUF;
190 bool isMTBUF(uint16_t Opcode) const {
191 return get(Opcode).TSFlags & SIInstrFlags::MTBUF;
194 bool isSMRD(uint16_t Opcode) const {
195 return get(Opcode).TSFlags & SIInstrFlags::SMRD;
198 bool isDS(uint16_t Opcode) const {
199 return get(Opcode).TSFlags & SIInstrFlags::DS;
202 bool isMIMG(uint16_t Opcode) const {
203 return get(Opcode).TSFlags & SIInstrFlags::MIMG;
206 bool isFLAT(uint16_t Opcode) const {
207 return get(Opcode).TSFlags & SIInstrFlags::FLAT;
210 bool isWQM(uint16_t Opcode) const {
211 return get(Opcode).TSFlags & SIInstrFlags::WQM;
214 bool isVGPRSpill(uint16_t Opcode) const {
215 return get(Opcode).TSFlags & SIInstrFlags::VGPRSpill;
218 bool isInlineConstant(const APInt &Imm) const;
219 bool isInlineConstant(const MachineOperand &MO, unsigned OpSize) const;
220 bool isLiteralConstant(const MachineOperand &MO, unsigned OpSize) const;
222 bool isImmOperandLegal(const MachineInstr *MI, unsigned OpNo,
223 const MachineOperand &MO) const;
225 /// \brief Return true if this 64-bit VALU instruction has a 32-bit encoding.
226 /// This function will return false if you pass it a 32-bit instruction.
227 bool hasVALU32BitEncoding(unsigned Opcode) const;
229 /// \brief Returns true if this operand uses the constant bus.
230 bool usesConstantBus(const MachineRegisterInfo &MRI,
231 const MachineOperand &MO,
232 unsigned OpSize) const;
234 /// \brief Return true if this instruction has any modifiers.
235 /// e.g. src[012]_mod, omod, clamp.
236 bool hasModifiers(unsigned Opcode) const;
238 bool hasModifiersSet(const MachineInstr &MI,
239 unsigned OpName) const;
241 bool verifyInstruction(const MachineInstr *MI,
242 StringRef &ErrInfo) const override;
244 static unsigned getVALUOp(const MachineInstr &MI);
246 bool isSALUOpSupportedOnVALU(const MachineInstr &MI) const;
248 /// \brief Return the correct register class for \p OpNo. For target-specific
249 /// instructions, this will return the register class that has been defined
250 /// in tablegen. For generic instructions, like REG_SEQUENCE it will return
251 /// the register class of its machine operand.
252 /// to infer the correct register class base on the other operands.
253 const TargetRegisterClass *getOpRegClass(const MachineInstr &MI,
254 unsigned OpNo) const;
256 /// \brief Return the size in bytes of the operand OpNo on the given
257 // instruction opcode.
258 unsigned getOpSize(uint16_t Opcode, unsigned OpNo) const {
259 const MCOperandInfo &OpInfo = get(Opcode).OpInfo[OpNo];
261 if (OpInfo.RegClass == -1) {
262 // If this is an immediate operand, this must be a 32-bit literal.
263 assert(OpInfo.OperandType == MCOI::OPERAND_IMMEDIATE);
267 return RI.getRegClass(OpInfo.RegClass)->getSize();
270 /// \brief This form should usually be preferred since it handles operands
271 /// with unknown register classes.
272 unsigned getOpSize(const MachineInstr &MI, unsigned OpNo) const {
273 return getOpRegClass(MI, OpNo)->getSize();
276 /// \returns true if it is legal for the operand at index \p OpNo
278 bool canReadVGPR(const MachineInstr &MI, unsigned OpNo) const;
280 /// \brief Legalize the \p OpIndex operand of this instruction by inserting
281 /// a MOV. For example:
282 /// ADD_I32_e32 VGPR0, 15
285 /// ADD_I32_e32 VGPR0, VGPR1
287 /// If the operand being legalized is a register, then a COPY will be used
289 void legalizeOpWithMove(MachineInstr *MI, unsigned OpIdx) const;
291 /// \brief Check if \p MO is a legal operand if it was the \p OpIdx Operand
293 bool isOperandLegal(const MachineInstr *MI, unsigned OpIdx,
294 const MachineOperand *MO = nullptr) const;
296 /// \brief Legalize all operands in this instruction. This function may
297 /// create new instruction and insert them before \p MI.
298 void legalizeOperands(MachineInstr *MI) const;
300 /// \brief Split an SMRD instruction into two smaller loads of half the
301 // size storing the results in \p Lo and \p Hi.
302 void splitSMRD(MachineInstr *MI, const TargetRegisterClass *HalfRC,
303 unsigned HalfImmOp, unsigned HalfSGPROp,
304 MachineInstr *&Lo, MachineInstr *&Hi) const;
306 void moveSMRDToVALU(MachineInstr *MI, MachineRegisterInfo &MRI) const;
308 /// \brief Replace this instruction's opcode with the equivalent VALU
309 /// opcode. This function will also move the users of \p MI to the
310 /// VALU if necessary.
311 void moveToVALU(MachineInstr &MI) const;
313 unsigned calculateIndirectAddress(unsigned RegIndex,
314 unsigned Channel) const override;
316 const TargetRegisterClass *getIndirectAddrRegClass() const override;
318 MachineInstrBuilder buildIndirectWrite(MachineBasicBlock *MBB,
319 MachineBasicBlock::iterator I,
322 unsigned OffsetReg) const override;
324 MachineInstrBuilder buildIndirectRead(MachineBasicBlock *MBB,
325 MachineBasicBlock::iterator I,
328 unsigned OffsetReg) const override;
329 void reserveIndirectRegisters(BitVector &Reserved,
330 const MachineFunction &MF) const;
332 void LoadM0(MachineInstr *MoveRel, MachineBasicBlock::iterator I,
333 unsigned SavReg, unsigned IndexReg) const;
335 void insertNOPs(MachineBasicBlock::iterator MI, int Count) const;
337 /// \brief Returns the operand named \p Op. If \p MI does not have an
338 /// operand named \c Op, this function returns nullptr.
339 MachineOperand *getNamedOperand(MachineInstr &MI, unsigned OperandName) const;
341 const MachineOperand *getNamedOperand(const MachineInstr &MI,
342 unsigned OpName) const {
343 return getNamedOperand(const_cast<MachineInstr &>(MI), OpName);
346 uint64_t getDefaultRsrcDataFormat() const;
352 int getVOPe64(uint16_t Opcode);
353 int getVOPe32(uint16_t Opcode);
354 int getCommuteRev(uint16_t Opcode);
355 int getCommuteOrig(uint16_t Opcode);
356 int getAddr64Inst(uint16_t Opcode);
357 int getAtomicRetOp(uint16_t Opcode);
358 int getAtomicNoRetOp(uint16_t Opcode);
360 const uint64_t RSRC_DATA_FORMAT = 0xf00000000000LL;
361 const uint64_t RSRC_TID_ENABLE = 1LL << 55;
363 } // End namespace AMDGPU
366 namespace KernelInputOffsets {
368 /// Offsets in bytes from the start of the input buffer
381 } // End namespace KernelInputOffsets
382 } // End namespace SI
384 } // End namespace llvm