blob: 6c3557af191372707496e5909145275b43498c35 [file] [log] [blame]
Tom Stellard75aadc22012-12-11 21:25:42 +00001//===-- R600InstrInfo.h - R600 Instruction Info Interface -------*- C++ -*-===//
2//
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 R600InstrInfo
12//
13//===----------------------------------------------------------------------===//
14
Matt Arsenault6b6a2c32016-03-11 08:00:27 +000015#ifndef LLVM_LIB_TARGET_AMDGPU_R600INSTRINFO_H
16#define LLVM_LIB_TARGET_AMDGPU_R600INSTRINFO_H
Tom Stellard75aadc22012-12-11 21:25:42 +000017
Tom Stellard75aadc22012-12-11 21:25:42 +000018#include "AMDGPUInstrInfo.h"
19#include "R600Defines.h"
20#include "R600RegisterInfo.h"
Tom Stellard75aadc22012-12-11 21:25:42 +000021
22namespace llvm {
Tom Stellard75aadc22012-12-11 21:25:42 +000023 class AMDGPUTargetMachine;
24 class DFAPacketizer;
Tom Stellard75aadc22012-12-11 21:25:42 +000025 class MachineFunction;
26 class MachineInstr;
27 class MachineInstrBuilder;
28
Matt Arsenault6b6a2c32016-03-11 08:00:27 +000029 class R600InstrInfo final : public AMDGPUInstrInfo {
Tom Stellard75aadc22012-12-11 21:25:42 +000030 private:
31 const R600RegisterInfo RI;
32
Vincent Lejeune0fca91d2013-05-17 16:50:02 +000033 std::vector<std::pair<int, unsigned> >
Vincent Lejeunebb8a87212013-06-29 19:32:29 +000034 ExtractSrcs(MachineInstr *MI, const DenseMap<unsigned, unsigned> &PV, unsigned &ConstCount) const;
Tom Stellard75aadc22012-12-11 21:25:42 +000035
Tom Stellard880a80a2014-06-17 16:53:14 +000036
37 MachineInstrBuilder buildIndirectRead(MachineBasicBlock *MBB,
38 MachineBasicBlock::iterator I,
39 unsigned ValueReg, unsigned Address,
40 unsigned OffsetReg,
41 unsigned AddrChan) const;
42
43 MachineInstrBuilder buildIndirectWrite(MachineBasicBlock *MBB,
44 MachineBasicBlock::iterator I,
45 unsigned ValueReg, unsigned Address,
46 unsigned OffsetReg,
47 unsigned AddrChan) const;
Tom Stellard75aadc22012-12-11 21:25:42 +000048 public:
Vincent Lejeune0fca91d2013-05-17 16:50:02 +000049 enum BankSwizzle {
Vincent Lejeunebb8a87212013-06-29 19:32:29 +000050 ALU_VEC_012_SCL_210 = 0,
51 ALU_VEC_021_SCL_122,
52 ALU_VEC_120_SCL_212,
53 ALU_VEC_102_SCL_221,
Vincent Lejeune0fca91d2013-05-17 16:50:02 +000054 ALU_VEC_201,
55 ALU_VEC_210
56 };
57
Tom Stellard2e59a452014-06-13 01:32:00 +000058 explicit R600InstrInfo(const AMDGPUSubtarget &st);
Tom Stellard75aadc22012-12-11 21:25:42 +000059
Craig Topper5656db42014-04-29 07:57:24 +000060 const R600RegisterInfo &getRegisterInfo() const override;
61 void copyPhysReg(MachineBasicBlock &MBB,
62 MachineBasicBlock::iterator MI, DebugLoc DL,
63 unsigned DestReg, unsigned SrcReg,
64 bool KillSrc) const override;
Tom Stellardcd6b0a62013-11-22 00:41:08 +000065 bool isLegalToSplitMBBAt(MachineBasicBlock &MBB,
Craig Topper5656db42014-04-29 07:57:24 +000066 MachineBasicBlock::iterator MBBI) const override;
Tom Stellard75aadc22012-12-11 21:25:42 +000067
68 bool isTrig(const MachineInstr &MI) const;
69 bool isPlaceHolderOpcode(unsigned opcode) const;
70 bool isReductionOp(unsigned opcode) const;
71 bool isCubeOp(unsigned opcode) const;
72
73 /// \returns true if this \p Opcode represents an ALU instruction.
74 bool isALUInstr(unsigned Opcode) const;
Tom Stellardc026e8b2013-06-28 15:47:08 +000075 bool hasInstrModifiers(unsigned Opcode) const;
76 bool isLDSInstr(unsigned Opcode) const;
Tom Stellard8f9fc202013-11-15 00:12:45 +000077 bool isLDSNoRetInstr(unsigned Opcode) const;
78 bool isLDSRetInstr(unsigned Opcode) const;
Tom Stellard75aadc22012-12-11 21:25:42 +000079
Vincent Lejeunea4da6fb2013-10-01 19:32:58 +000080 /// \returns true if this \p Opcode represents an ALU instruction or an
81 /// instruction that will be lowered in ExpandSpecialInstrs Pass.
82 bool canBeConsideredALU(const MachineInstr *MI) const;
83
Vincent Lejeune076c0b22013-04-30 00:14:17 +000084 bool isTransOnly(unsigned Opcode) const;
85 bool isTransOnly(const MachineInstr *MI) const;
Vincent Lejeune4d5c5e52013-09-04 19:53:30 +000086 bool isVectorOnly(unsigned Opcode) const;
87 bool isVectorOnly(const MachineInstr *MI) const;
Tom Stellard676c16d2013-08-16 01:11:51 +000088 bool isExport(unsigned Opcode) const;
Vincent Lejeune076c0b22013-04-30 00:14:17 +000089
Vincent Lejeunec2991642013-04-30 00:13:39 +000090 bool usesVertexCache(unsigned Opcode) const;
91 bool usesVertexCache(const MachineInstr *MI) const;
92 bool usesTextureCache(unsigned Opcode) const;
93 bool usesTextureCache(const MachineInstr *MI) const;
94
Tom Stellardce540332013-06-28 15:46:59 +000095 bool mustBeLastInClause(unsigned Opcode) const;
Tom Stellard26a3b672013-10-22 18:19:10 +000096 bool usesAddressRegister(MachineInstr *MI) const;
97 bool definesAddressRegister(MachineInstr *MI) const;
Tom Stellard7f6fa4c2013-09-12 02:55:06 +000098 bool readsLDSSrcReg(const MachineInstr *MI) const;
Tom Stellardce540332013-06-28 15:46:59 +000099
Tom Stellard84021442013-07-23 01:48:24 +0000100 /// \returns The operand index for the given source number. Legal values
101 /// for SrcNum are 0, 1, and 2.
102 int getSrcIdx(unsigned Opcode, unsigned SrcNum) const;
103 /// \returns The operand Index for the Sel operand given an index to one
104 /// of the instruction's src operands.
105 int getSelIdx(unsigned Opcode, unsigned SrcIdx) const;
106
Vincent Lejeune0fca91d2013-05-17 16:50:02 +0000107 /// \returns a pair for each src of an ALU instructions.
108 /// The first member of a pair is the register id.
109 /// If register is ALU_CONST, second member is SEL.
110 /// If register is ALU_LITERAL, second member is IMM.
111 /// Otherwise, second member value is undefined.
112 SmallVector<std::pair<MachineOperand *, int64_t>, 3>
113 getSrcs(MachineInstr *MI) const;
114
Vincent Lejeune77a83522013-06-29 19:32:43 +0000115 unsigned isLegalUpTo(
116 const std::vector<std::vector<std::pair<int, unsigned> > > &IGSrcs,
117 const std::vector<R600InstrInfo::BankSwizzle> &Swz,
118 const std::vector<std::pair<int, unsigned> > &TransSrcs,
119 R600InstrInfo::BankSwizzle TransSwz) const;
120
121 bool FindSwizzleForVectorSlot(
122 const std::vector<std::vector<std::pair<int, unsigned> > > &IGSrcs,
123 std::vector<R600InstrInfo::BankSwizzle> &SwzCandidate,
124 const std::vector<std::pair<int, unsigned> > &TransSrcs,
125 R600InstrInfo::BankSwizzle TransSwz) const;
Tom Stellardc026e8b2013-06-28 15:47:08 +0000126
Vincent Lejeune0fca91d2013-05-17 16:50:02 +0000127 /// Given the order VEC_012 < VEC_021 < VEC_120 < VEC_102 < VEC_201 < VEC_210
128 /// returns true and the first (in lexical order) BankSwizzle affectation
129 /// starting from the one already provided in the Instruction Group MIs that
130 /// fits Read Port limitations in BS if available. Otherwise returns false
131 /// and undefined content in BS.
Vincent Lejeune77a83522013-06-29 19:32:43 +0000132 /// isLastAluTrans should be set if the last Alu of MIs will be executed on
133 /// Trans ALU. In this case, ValidTSwizzle returns the BankSwizzle value to
134 /// apply to the last instruction.
Vincent Lejeune0fca91d2013-05-17 16:50:02 +0000135 /// PV holds GPR to PV registers in the Instruction Group MIs.
136 bool fitsReadPortLimitations(const std::vector<MachineInstr *> &MIs,
137 const DenseMap<unsigned, unsigned> &PV,
Vincent Lejeune77a83522013-06-29 19:32:43 +0000138 std::vector<BankSwizzle> &BS,
139 bool isLastAluTrans) const;
140
141 /// An instruction group can only access 2 channel pair (either [XY] or [ZW])
142 /// from KCache bank on R700+. This function check if MI set in input meet
143 /// this limitations
144 bool fitsConstReadLimitations(const std::vector<MachineInstr *> &) const;
145 /// Same but using const index set instead of MI set.
Vincent Lejeune0a22bc42013-03-14 15:50:45 +0000146 bool fitsConstReadLimitations(const std::vector<unsigned>&) const;
Vincent Lejeune0a22bc42013-03-14 15:50:45 +0000147
Alp Tokercb402912014-01-24 17:20:08 +0000148 /// \brief Vector instructions are instructions that must fill all
Tom Stellard75aadc22012-12-11 21:25:42 +0000149 /// instruction slots within an instruction group.
150 bool isVector(const MachineInstr &MI) const;
151
Tom Stellard2ff72622016-01-28 16:04:37 +0000152 bool isMov(unsigned Opcode) const;
Tom Stellard75aadc22012-12-11 21:25:42 +0000153
Eric Christopher143f02c2014-10-09 01:59:35 +0000154 DFAPacketizer *
155 CreateTargetScheduleState(const TargetSubtargetInfo &) const override;
Tom Stellard75aadc22012-12-11 21:25:42 +0000156
Craig Topper5656db42014-04-29 07:57:24 +0000157 bool ReverseBranchCondition(SmallVectorImpl<MachineOperand> &Cond) const override;
Tom Stellard75aadc22012-12-11 21:25:42 +0000158
159 bool AnalyzeBranch(MachineBasicBlock &MBB, MachineBasicBlock *&TBB, MachineBasicBlock *&FBB,
Craig Topper5656db42014-04-29 07:57:24 +0000160 SmallVectorImpl<MachineOperand> &Cond, bool AllowModify) const override;
Tom Stellard75aadc22012-12-11 21:25:42 +0000161
Ahmed Bougachac88bf542015-06-11 19:30:37 +0000162 unsigned InsertBranch(MachineBasicBlock &MBB, MachineBasicBlock *TBB,
163 MachineBasicBlock *FBB, ArrayRef<MachineOperand> Cond,
164 DebugLoc DL) const override;
Tom Stellard75aadc22012-12-11 21:25:42 +0000165
Craig Topper5656db42014-04-29 07:57:24 +0000166 unsigned RemoveBranch(MachineBasicBlock &MBB) const override;
Tom Stellard75aadc22012-12-11 21:25:42 +0000167
Duncan P. N. Exon Smith6307eb52016-02-23 02:46:52 +0000168 bool isPredicated(const MachineInstr &MI) const override;
Tom Stellard75aadc22012-12-11 21:25:42 +0000169
Duncan P. N. Exon Smith6307eb52016-02-23 02:46:52 +0000170 bool isPredicable(MachineInstr &MI) const override;
Tom Stellard75aadc22012-12-11 21:25:42 +0000171
172 bool
173 isProfitableToDupForIfCvt(MachineBasicBlock &MBB, unsigned NumCyles,
Cong Houc536bd92015-09-10 23:10:42 +0000174 BranchProbability Probability) const override;
Tom Stellard75aadc22012-12-11 21:25:42 +0000175
176 bool isProfitableToIfCvt(MachineBasicBlock &MBB, unsigned NumCyles,
177 unsigned ExtraPredCycles,
Cong Houc536bd92015-09-10 23:10:42 +0000178 BranchProbability Probability) const override ;
Tom Stellard75aadc22012-12-11 21:25:42 +0000179
180 bool
181 isProfitableToIfCvt(MachineBasicBlock &TMBB,
182 unsigned NumTCycles, unsigned ExtraTCycles,
183 MachineBasicBlock &FMBB,
184 unsigned NumFCycles, unsigned ExtraFCycles,
Cong Houc536bd92015-09-10 23:10:42 +0000185 BranchProbability Probability) const override;
Tom Stellard75aadc22012-12-11 21:25:42 +0000186
Duncan P. N. Exon Smith6307eb52016-02-23 02:46:52 +0000187 bool DefinesPredicate(MachineInstr &MI,
188 std::vector<MachineOperand> &Pred) const override;
Tom Stellard75aadc22012-12-11 21:25:42 +0000189
Ahmed Bougachac88bf542015-06-11 19:30:37 +0000190 bool SubsumesPredicate(ArrayRef<MachineOperand> Pred1,
191 ArrayRef<MachineOperand> Pred2) const override;
Tom Stellard75aadc22012-12-11 21:25:42 +0000192
193 bool isProfitableToUnpredicate(MachineBasicBlock &TMBB,
Craig Topper5656db42014-04-29 07:57:24 +0000194 MachineBasicBlock &FMBB) const override;
Tom Stellard75aadc22012-12-11 21:25:42 +0000195
Duncan P. N. Exon Smith6307eb52016-02-23 02:46:52 +0000196 bool PredicateInstruction(MachineInstr &MI,
Ahmed Bougachac88bf542015-06-11 19:30:37 +0000197 ArrayRef<MachineOperand> Pred) const override;
Tom Stellard75aadc22012-12-11 21:25:42 +0000198
Duncan P. N. Exon Smith6307eb52016-02-23 02:46:52 +0000199 unsigned int getPredicationCost(const MachineInstr &) const override;
Arnold Schwaighoferd2f96b92013-09-30 15:28:56 +0000200
Tom Stellard75aadc22012-12-11 21:25:42 +0000201 unsigned int getInstrLatency(const InstrItineraryData *ItinData,
202 const MachineInstr *MI,
Craig Topper5656db42014-04-29 07:57:24 +0000203 unsigned *PredCost = nullptr) const override;
Tom Stellard75aadc22012-12-11 21:25:42 +0000204
Craig Topper5656db42014-04-29 07:57:24 +0000205 int getInstrLatency(const InstrItineraryData *ItinData,
206 SDNode *Node) const override { return 1;}
Tom Stellard75aadc22012-12-11 21:25:42 +0000207
Benjamin Kramer8c90fd72014-09-03 11:41:21 +0000208 bool expandPostRAPseudo(MachineBasicBlock::iterator MI) const override;
Tom Stellard880a80a2014-06-17 16:53:14 +0000209
Tom Stellard81d871d2013-11-13 23:36:50 +0000210 /// \brief Reserve the registers that may be accesed using indirect addressing.
211 void reserveIndirectRegisters(BitVector &Reserved,
212 const MachineFunction &MF) const;
Tom Stellardf3b2a1e2013-02-06 17:32:29 +0000213
Tom Stellard1242ce92016-02-05 18:44:57 +0000214 /// Calculate the "Indirect Address" for the given \p RegIndex and
215 /// \p Channel
216 ///
217 /// We model indirect addressing using a virtual address space that can be
218 /// accesed with loads and stores. The "Indirect Address" is the memory
219 /// address in this virtual address space that maps to the given \p RegIndex
220 /// and \p Channel.
221 unsigned calculateIndirectAddress(unsigned RegIndex, unsigned Channel) const;
222
Tom Stellardf3b2a1e2013-02-06 17:32:29 +0000223
Craig Topper5656db42014-04-29 07:57:24 +0000224 const TargetRegisterClass *getIndirectAddrRegClass() const override;
Tom Stellardf3b2a1e2013-02-06 17:32:29 +0000225
Tom Stellard1242ce92016-02-05 18:44:57 +0000226 /// \brief Build instruction(s) for an indirect register write.
227 ///
228 /// \returns The instruction that performs the indirect register write
Craig Topper5656db42014-04-29 07:57:24 +0000229 MachineInstrBuilder buildIndirectWrite(MachineBasicBlock *MBB,
Tom Stellard1242ce92016-02-05 18:44:57 +0000230 MachineBasicBlock::iterator I,
231 unsigned ValueReg, unsigned Address,
232 unsigned OffsetReg) const;
Tom Stellardf3b2a1e2013-02-06 17:32:29 +0000233
Tom Stellard1242ce92016-02-05 18:44:57 +0000234 /// \brief Build instruction(s) for an indirect register read.
235 ///
236 /// \returns The instruction that performs the indirect register read
Craig Topper5656db42014-04-29 07:57:24 +0000237 MachineInstrBuilder buildIndirectRead(MachineBasicBlock *MBB,
238 MachineBasicBlock::iterator I,
239 unsigned ValueReg, unsigned Address,
Tom Stellard1242ce92016-02-05 18:44:57 +0000240 unsigned OffsetReg) const;
Tom Stellardf3b2a1e2013-02-06 17:32:29 +0000241
Vincent Lejeune80031d9f2013-04-03 16:49:34 +0000242 unsigned getMaxAlusPerClause() const;
Tom Stellardf3b2a1e2013-02-06 17:32:29 +0000243
244 ///buildDefaultInstruction - This function returns a MachineInstr with
245 /// all the instruction modifiers initialized to their default values.
Tom Stellard75aadc22012-12-11 21:25:42 +0000246 /// You can use this function to avoid manually specifying each instruction
247 /// modifier operand when building a new instruction.
248 ///
249 /// \returns a MachineInstr with all the instruction modifiers initialized
250 /// to their default values.
251 MachineInstrBuilder buildDefaultInstruction(MachineBasicBlock &MBB,
252 MachineBasicBlock::iterator I,
253 unsigned Opcode,
254 unsigned DstReg,
255 unsigned Src0Reg,
256 unsigned Src1Reg = 0) const;
257
Vincent Lejeune519f21e2013-05-17 16:50:32 +0000258 MachineInstr *buildSlotOfVectorInstruction(MachineBasicBlock &MBB,
259 MachineInstr *MI,
260 unsigned Slot,
261 unsigned DstReg) const;
262
Tom Stellard75aadc22012-12-11 21:25:42 +0000263 MachineInstr *buildMovImm(MachineBasicBlock &BB,
264 MachineBasicBlock::iterator I,
265 unsigned DstReg,
266 uint64_t Imm) const;
267
Tom Stellard26a3b672013-10-22 18:19:10 +0000268 MachineInstr *buildMovInstr(MachineBasicBlock *MBB,
269 MachineBasicBlock::iterator I,
Tom Stellard2ff72622016-01-28 16:04:37 +0000270 unsigned DstReg, unsigned SrcReg) const;
Tom Stellard26a3b672013-10-22 18:19:10 +0000271
Tom Stellard75aadc22012-12-11 21:25:42 +0000272 /// \brief Get the index of Op in the MachineInstr.
273 ///
274 /// \returns -1 if the Instruction does not contain the specified \p Op.
Tom Stellard02661d92013-06-25 21:22:18 +0000275 int getOperandIdx(const MachineInstr &MI, unsigned Op) const;
Tom Stellard75aadc22012-12-11 21:25:42 +0000276
277 /// \brief Get the index of \p Op for the given Opcode.
278 ///
279 /// \returns -1 if the Instruction does not contain the specified \p Op.
Tom Stellard02661d92013-06-25 21:22:18 +0000280 int getOperandIdx(unsigned Opcode, unsigned Op) const;
Tom Stellard75aadc22012-12-11 21:25:42 +0000281
282 /// \brief Helper function for setting instruction flag values.
Tom Stellard02661d92013-06-25 21:22:18 +0000283 void setImmOperand(MachineInstr *MI, unsigned Op, int64_t Imm) const;
Tom Stellard75aadc22012-12-11 21:25:42 +0000284
285 /// \returns true if this instruction has an operand for storing target flags.
286 bool hasFlagOperand(const MachineInstr &MI) const;
287
288 ///\brief Add one of the MO_FLAG* flags to the specified \p Operand.
289 void addFlag(MachineInstr *MI, unsigned Operand, unsigned Flag) const;
290
291 ///\brief Determine if the specified \p Flag is set on this \p Operand.
292 bool isFlagSet(const MachineInstr &MI, unsigned Operand, unsigned Flag) const;
293
294 /// \param SrcIdx The register source to set the flag on (e.g src0, src1, src2)
295 /// \param Flag The flag being set.
296 ///
297 /// \returns the operand containing the flags for this instruction.
298 MachineOperand &getFlagOp(MachineInstr *MI, unsigned SrcIdx = 0,
299 unsigned Flag = 0) const;
300
301 /// \brief Clear the specified flag on the instruction.
302 void clearFlag(MachineInstr *MI, unsigned Operand, unsigned Flag) const;
Tom Stellard2ff72622016-01-28 16:04:37 +0000303
304 // Helper functions that check the opcode for status information
305 bool isRegisterStore(const MachineInstr &MI) const;
306 bool isRegisterLoad(const MachineInstr &MI) const;
307
Tom Stellard75aadc22012-12-11 21:25:42 +0000308};
309
Tom Stellard13c68ef2013-09-05 18:38:09 +0000310namespace AMDGPU {
311
312int getLDSNoRetOp(uint16_t Opcode);
313
314} //End namespace AMDGPU
315
Alexander Kornienkof00654e2015-06-23 09:49:53 +0000316} // End llvm namespace
Tom Stellard75aadc22012-12-11 21:25:42 +0000317
Benjamin Kramera7c40ef2014-08-13 16:26:38 +0000318#endif