AMDGPU/SI: Remove isTriviallyReMaterializable() function from SIInstrInfo
[oota-llvm.git] / lib / Target / AMDGPU / SIInstrInfo.h
1 //===-- SIInstrInfo.h - SI 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 SIInstrInfo.
12 //
13 //===----------------------------------------------------------------------===//
14
15
16 #ifndef LLVM_LIB_TARGET_R600_SIINSTRINFO_H
17 #define LLVM_LIB_TARGET_R600_SIINSTRINFO_H
18
19 #include "AMDGPUInstrInfo.h"
20 #include "SIDefines.h"
21 #include "SIRegisterInfo.h"
22
23 namespace llvm {
24
25 class SIInstrInfo : public AMDGPUInstrInfo {
26 private:
27   const SIRegisterInfo RI;
28
29   unsigned buildExtractSubReg(MachineBasicBlock::iterator MI,
30                               MachineRegisterInfo &MRI,
31                               MachineOperand &SuperReg,
32                               const TargetRegisterClass *SuperRC,
33                               unsigned SubIdx,
34                               const TargetRegisterClass *SubRC) const;
35   MachineOperand buildExtractSubRegOrImm(MachineBasicBlock::iterator MI,
36                                          MachineRegisterInfo &MRI,
37                                          MachineOperand &SuperReg,
38                                          const TargetRegisterClass *SuperRC,
39                                          unsigned SubIdx,
40                                          const TargetRegisterClass *SubRC) const;
41
42   unsigned split64BitImm(SmallVectorImpl<MachineInstr *> &Worklist,
43                          MachineBasicBlock::iterator MI,
44                          MachineRegisterInfo &MRI,
45                          const TargetRegisterClass *RC,
46                          const MachineOperand &Op) const;
47
48   void swapOperands(MachineBasicBlock::iterator Inst) const;
49
50   void splitScalar64BitUnaryOp(SmallVectorImpl<MachineInstr *> &Worklist,
51                                MachineInstr *Inst, unsigned Opcode) const;
52
53   void splitScalar64BitBinaryOp(SmallVectorImpl<MachineInstr *> &Worklist,
54                                 MachineInstr *Inst, unsigned Opcode) const;
55
56   void splitScalar64BitBCNT(SmallVectorImpl<MachineInstr *> &Worklist,
57                             MachineInstr *Inst) const;
58   void splitScalar64BitBFE(SmallVectorImpl<MachineInstr *> &Worklist,
59                            MachineInstr *Inst) const;
60
61   void addDescImplicitUseDef(const MCInstrDesc &Desc, MachineInstr *MI) const;
62
63   bool checkInstOffsetsDoNotOverlap(MachineInstr *MIa,
64                                     MachineInstr *MIb) const;
65
66   unsigned findUsedSGPR(const MachineInstr *MI, int OpIndices[3]) const;
67
68 public:
69   explicit SIInstrInfo(const AMDGPUSubtarget &st);
70
71   const SIRegisterInfo &getRegisterInfo() const override {
72     return RI;
73   }
74
75   bool isReallyTriviallyReMaterializable(const MachineInstr *MI,
76                                          AliasAnalysis *AA) const override;
77
78   bool areLoadsFromSameBasePtr(SDNode *Load1, SDNode *Load2,
79                                int64_t &Offset1,
80                                int64_t &Offset2) const override;
81
82   bool getMemOpBaseRegImmOfs(MachineInstr *LdSt, unsigned &BaseReg,
83                              unsigned &Offset,
84                              const TargetRegisterInfo *TRI) const final;
85
86   bool shouldClusterLoads(MachineInstr *FirstLdSt,
87                           MachineInstr *SecondLdSt,
88                           unsigned NumLoads) const final;
89
90   void copyPhysReg(MachineBasicBlock &MBB,
91                    MachineBasicBlock::iterator MI, DebugLoc DL,
92                    unsigned DestReg, unsigned SrcReg,
93                    bool KillSrc) const override;
94
95   unsigned calculateLDSSpillAddress(MachineBasicBlock &MBB,
96                                     MachineBasicBlock::iterator MI,
97                                     RegScavenger *RS,
98                                     unsigned TmpReg,
99                                     unsigned Offset,
100                                     unsigned Size) const;
101
102   void storeRegToStackSlot(MachineBasicBlock &MBB,
103                            MachineBasicBlock::iterator MI,
104                            unsigned SrcReg, bool isKill, int FrameIndex,
105                            const TargetRegisterClass *RC,
106                            const TargetRegisterInfo *TRI) const override;
107
108   void loadRegFromStackSlot(MachineBasicBlock &MBB,
109                             MachineBasicBlock::iterator MI,
110                             unsigned DestReg, int FrameIndex,
111                             const TargetRegisterClass *RC,
112                             const TargetRegisterInfo *TRI) const override;
113
114   bool expandPostRAPseudo(MachineBasicBlock::iterator MI) const override;
115
116   // \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;
120   int commuteOpcode(const MachineInstr &MI) const;
121
122   MachineInstr *commuteInstruction(MachineInstr *MI,
123                                    bool NewMI = false) const override;
124   bool findCommutedOpIndices(MachineInstr *MI,
125                              unsigned &SrcOpIdx1,
126                              unsigned &SrcOpIdx2) const override;
127
128   bool areMemAccessesTriviallyDisjoint(
129     MachineInstr *MIa, MachineInstr *MIb,
130     AliasAnalysis *AA = nullptr) const override;
131
132   MachineInstr *buildMovInstr(MachineBasicBlock *MBB,
133                               MachineBasicBlock::iterator I,
134                               unsigned DstReg, unsigned SrcReg) const override;
135   bool isMov(unsigned Opcode) const override;
136
137   bool isSafeToMoveRegClassDefs(const TargetRegisterClass *RC) const override;
138
139   bool FoldImmediate(MachineInstr *UseMI, MachineInstr *DefMI,
140                      unsigned Reg, MachineRegisterInfo *MRI) const final;
141
142   unsigned getMachineCSELookAheadLimit() const override { return 500; }
143
144   MachineInstr *convertToThreeAddress(MachineFunction::iterator &MBB,
145                                       MachineBasicBlock::iterator &MI,
146                                       LiveVariables *LV) const override;
147
148   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   }
215
216   bool isWQM(uint16_t Opcode) const {
217     return get(Opcode).TSFlags & SIInstrFlags::WQM;
218   }
219
220   bool isVGPRSpill(uint16_t Opcode) const {
221     return get(Opcode).TSFlags & SIInstrFlags::VGPRSpill;
222   }
223
224   bool isInlineConstant(const APInt &Imm) const;
225   bool isInlineConstant(const MachineOperand &MO, unsigned OpSize) const;
226   bool isLiteralConstant(const MachineOperand &MO, unsigned OpSize) const;
227
228   bool isImmOperandLegal(const MachineInstr *MI, unsigned OpNo,
229                          const MachineOperand &MO) const;
230
231   /// \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
235   /// \brief Returns true if this operand uses the constant bus.
236   bool usesConstantBus(const MachineRegisterInfo &MRI,
237                        const MachineOperand &MO,
238                        unsigned OpSize) const;
239
240   /// \brief Return true if this instruction has any modifiers.
241   ///  e.g. src[012]_mod, omod, clamp.
242   bool hasModifiers(unsigned Opcode) const;
243
244   bool hasModifiersSet(const MachineInstr &MI,
245                        unsigned OpName) const;
246
247   bool verifyInstruction(const MachineInstr *MI,
248                          StringRef &ErrInfo) const override;
249
250   static unsigned getVALUOp(const MachineInstr &MI);
251
252   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,
260                                            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];
266
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
273     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   }
281
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
297   /// \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
302   /// \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
306   /// \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
312   void moveSMRDToVALU(MachineInstr *MI, MachineRegisterInfo &MRI) const;
313
314   /// \brief Replace this instruction's opcode with the equivalent VALU
315   /// opcode.  This function will also move the users of \p MI to the
316   /// VALU if necessary.
317   void moveToVALU(MachineInstr &MI) const;
318
319   unsigned calculateIndirectAddress(unsigned RegIndex,
320                                     unsigned Channel) const override;
321
322   const TargetRegisterClass *getIndirectAddrRegClass() const override;
323
324   MachineInstrBuilder buildIndirectWrite(MachineBasicBlock *MBB,
325                                          MachineBasicBlock::iterator I,
326                                          unsigned ValueReg,
327                                          unsigned Address,
328                                          unsigned OffsetReg) const override;
329
330   MachineInstrBuilder buildIndirectRead(MachineBasicBlock *MBB,
331                                         MachineBasicBlock::iterator I,
332                                         unsigned ValueReg,
333                                         unsigned Address,
334                                         unsigned OffsetReg) const override;
335   void reserveIndirectRegisters(BitVector &Reserved,
336                                 const MachineFunction &MF) const;
337
338   void LoadM0(MachineInstr *MoveRel, MachineBasicBlock::iterator I,
339               unsigned SavReg, unsigned IndexReg) const;
340
341   void insertNOPs(MachineBasicBlock::iterator MI, int Count) const;
342
343   /// \brief Returns the operand named \p Op.  If \p MI does not have an
344   /// operand named \c Op, this function returns nullptr.
345   MachineOperand *getNamedOperand(MachineInstr &MI, unsigned OperandName) const;
346
347   const MachineOperand *getNamedOperand(const MachineInstr &MI,
348                                         unsigned OpName) const {
349     return getNamedOperand(const_cast<MachineInstr &>(MI), OpName);
350   }
351
352   uint64_t getDefaultRsrcDataFormat() const;
353
354 };
355
356 namespace AMDGPU {
357
358   int getVOPe64(uint16_t Opcode);
359   int getVOPe32(uint16_t Opcode);
360   int getCommuteRev(uint16_t Opcode);
361   int getCommuteOrig(uint16_t Opcode);
362   int getAddr64Inst(uint16_t Opcode);
363   int getAtomicRetOp(uint16_t Opcode);
364   int getAtomicNoRetOp(uint16_t Opcode);
365
366   const uint64_t RSRC_DATA_FORMAT = 0xf00000000000LL;
367   const uint64_t RSRC_TID_ENABLE = 1LL << 55;
368
369 } // End namespace AMDGPU
370
371 namespace SI {
372 namespace KernelInputOffsets {
373
374 /// Offsets in bytes from the start of the input buffer
375 enum Offsets {
376   NGROUPS_X = 0,
377   NGROUPS_Y = 4,
378   NGROUPS_Z = 8,
379   GLOBAL_SIZE_X = 12,
380   GLOBAL_SIZE_Y = 16,
381   GLOBAL_SIZE_Z = 20,
382   LOCAL_SIZE_X = 24,
383   LOCAL_SIZE_Y = 28,
384   LOCAL_SIZE_Z = 32
385 };
386
387 } // End namespace KernelInputOffsets
388 } // End namespace SI
389
390 } // End namespace llvm
391
392 #endif