R600/SI: Fix 64-bit bit ops that require the VALU.
[oota-llvm.git] / lib / Target / R600 / 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 SIINSTRINFO_H
17 #define SIINSTRINFO_H
18
19 #include "AMDGPUInstrInfo.h"
20 #include "SIRegisterInfo.h"
21
22 namespace llvm {
23
24 class SIInstrInfo : public AMDGPUInstrInfo {
25 private:
26   const SIRegisterInfo RI;
27
28   unsigned buildExtractSubReg(MachineBasicBlock::iterator MI,
29                               MachineRegisterInfo &MRI,
30                               MachineOperand &SuperReg,
31                               const TargetRegisterClass *SuperRC,
32                               unsigned SubIdx,
33                               const TargetRegisterClass *SubRC) const;
34
35   unsigned split64BitImm(SmallVectorImpl<MachineInstr *> &Worklist,
36                          MachineBasicBlock::iterator MI,
37                          MachineRegisterInfo &MRI,
38                          const TargetRegisterClass *RC,
39                          const MachineOperand &Op) const;
40
41   void splitScalar64BitOp(SmallVectorImpl<MachineInstr *> &Worklist,
42                           MachineInstr *Inst, unsigned Opcode) const;
43
44
45 public:
46   explicit SIInstrInfo(AMDGPUTargetMachine &tm);
47
48   const SIRegisterInfo &getRegisterInfo() const {
49     return RI;
50   }
51
52   virtual void copyPhysReg(MachineBasicBlock &MBB,
53                            MachineBasicBlock::iterator MI, DebugLoc DL,
54                            unsigned DestReg, unsigned SrcReg,
55                            bool KillSrc) const;
56
57   void storeRegToStackSlot(MachineBasicBlock &MBB,
58                            MachineBasicBlock::iterator MI,
59                            unsigned SrcReg, bool isKill, int FrameIndex,
60                            const TargetRegisterClass *RC,
61                            const TargetRegisterInfo *TRI) const;
62
63   void loadRegFromStackSlot(MachineBasicBlock &MBB,
64                             MachineBasicBlock::iterator MI,
65                             unsigned DestReg, int FrameIndex,
66                             const TargetRegisterClass *RC,
67                             const TargetRegisterInfo *TRI) const;
68
69   unsigned commuteOpcode(unsigned Opcode) const;
70
71   virtual MachineInstr *commuteInstruction(MachineInstr *MI,
72                                            bool NewMI=false) const;
73
74   virtual unsigned getIEQOpcode() const {
75     llvm_unreachable("Unimplemented");
76   }
77
78   MachineInstr *buildMovInstr(MachineBasicBlock *MBB,
79                               MachineBasicBlock::iterator I,
80                               unsigned DstReg, unsigned SrcReg) const;
81   virtual bool isMov(unsigned Opcode) const;
82
83   virtual bool isSafeToMoveRegClassDefs(const TargetRegisterClass *RC) const;
84   bool isDS(uint16_t Opcode) const;
85   int isMIMG(uint16_t Opcode) const;
86   int isSMRD(uint16_t Opcode) const;
87   bool isVOP1(uint16_t Opcode) const;
88   bool isVOP2(uint16_t Opcode) const;
89   bool isVOP3(uint16_t Opcode) const;
90   bool isVOPC(uint16_t Opcode) const;
91   bool isInlineConstant(const MachineOperand &MO) const;
92   bool isLiteralConstant(const MachineOperand &MO) const;
93
94   virtual bool verifyInstruction(const MachineInstr *MI,
95                                  StringRef &ErrInfo) const;
96
97   bool isSALUInstr(const MachineInstr &MI) const;
98   static unsigned getVALUOp(const MachineInstr &MI);
99
100   bool isSALUOpSupportedOnVALU(const MachineInstr &MI) const;
101
102   /// \brief Return the correct register class for \p OpNo.  For target-specific
103   /// instructions, this will return the register class that has been defined
104   /// in tablegen.  For generic instructions, like REG_SEQUENCE it will return
105   /// the register class of its machine operand.
106   /// to infer the correct register class base on the other operands.
107   const TargetRegisterClass *getOpRegClass(const MachineInstr &MI,
108                                            unsigned OpNo) const;\
109
110   /// \returns true if it is legal for the operand at index \p OpNo
111   /// to read a VGPR.
112   bool canReadVGPR(const MachineInstr &MI, unsigned OpNo) const;
113
114   /// \brief Legalize the \p OpIndex operand of this instruction by inserting
115   /// a MOV.  For example:
116   /// ADD_I32_e32 VGPR0, 15
117   /// to
118   /// MOV VGPR1, 15
119   /// ADD_I32_e32 VGPR0, VGPR1
120   ///
121   /// If the operand being legalized is a register, then a COPY will be used
122   /// instead of MOV.
123   void legalizeOpWithMove(MachineInstr *MI, unsigned OpIdx) const;
124
125   /// \brief Legalize all operands in this instruction.  This function may
126   /// create new instruction and insert them before \p MI.
127   void legalizeOperands(MachineInstr *MI) const;
128
129   /// \brief Replace this instruction's opcode with the equivalent VALU
130   /// opcode.  This function will also move the users of \p MI to the
131   /// VALU if necessary.
132   void moveToVALU(MachineInstr &MI) const;
133
134   virtual unsigned calculateIndirectAddress(unsigned RegIndex,
135                                             unsigned Channel) const;
136
137   virtual const TargetRegisterClass *getIndirectAddrRegClass() const;
138
139   virtual MachineInstrBuilder buildIndirectWrite(MachineBasicBlock *MBB,
140                                                  MachineBasicBlock::iterator I,
141                                                  unsigned ValueReg,
142                                                  unsigned Address,
143                                                  unsigned OffsetReg) const;
144
145   virtual MachineInstrBuilder buildIndirectRead(MachineBasicBlock *MBB,
146                                                 MachineBasicBlock::iterator I,
147                                                 unsigned ValueReg,
148                                                 unsigned Address,
149                                                 unsigned OffsetReg) const;
150   void reserveIndirectRegisters(BitVector &Reserved,
151                                 const MachineFunction &MF) const;
152
153   void LoadM0(MachineInstr *MoveRel, MachineBasicBlock::iterator I,
154               unsigned SavReg, unsigned IndexReg) const;
155 };
156
157 namespace AMDGPU {
158
159   int getVOPe64(uint16_t Opcode);
160   int getCommuteRev(uint16_t Opcode);
161   int getCommuteOrig(uint16_t Opcode);
162
163   const uint64_t RSRC_DATA_FORMAT = 0xf00000000000LL;
164
165
166 } // End namespace AMDGPU
167
168 } // End namespace llvm
169
170 namespace SIInstrFlags {
171   enum Flags {
172     // First 4 bits are the instruction encoding
173     VM_CNT = 1 << 0,
174     EXP_CNT = 1 << 1,
175     LGKM_CNT = 1 << 2
176   };
177 }
178
179 #endif //SIINSTRINFO_H