LLVM API Documentation
00001 //===-- SIInstrInfo.h - SI Instruction Info Interface -----------*- C++ -*-===// 00002 // 00003 // The LLVM Compiler Infrastructure 00004 // 00005 // This file is distributed under the University of Illinois Open Source 00006 // License. See LICENSE.TXT for details. 00007 // 00008 //===----------------------------------------------------------------------===// 00009 // 00010 /// \file 00011 /// \brief Interface definition for SIInstrInfo. 00012 // 00013 //===----------------------------------------------------------------------===// 00014 00015 00016 #ifndef LLVM_LIB_TARGET_R600_SIINSTRINFO_H 00017 #define LLVM_LIB_TARGET_R600_SIINSTRINFO_H 00018 00019 #include "AMDGPUInstrInfo.h" 00020 #include "SIRegisterInfo.h" 00021 00022 namespace llvm { 00023 00024 class SIInstrInfo : public AMDGPUInstrInfo { 00025 private: 00026 const SIRegisterInfo RI; 00027 00028 unsigned buildExtractSubReg(MachineBasicBlock::iterator MI, 00029 MachineRegisterInfo &MRI, 00030 MachineOperand &SuperReg, 00031 const TargetRegisterClass *SuperRC, 00032 unsigned SubIdx, 00033 const TargetRegisterClass *SubRC) const; 00034 MachineOperand buildExtractSubRegOrImm(MachineBasicBlock::iterator MI, 00035 MachineRegisterInfo &MRI, 00036 MachineOperand &SuperReg, 00037 const TargetRegisterClass *SuperRC, 00038 unsigned SubIdx, 00039 const TargetRegisterClass *SubRC) const; 00040 00041 unsigned split64BitImm(SmallVectorImpl<MachineInstr *> &Worklist, 00042 MachineBasicBlock::iterator MI, 00043 MachineRegisterInfo &MRI, 00044 const TargetRegisterClass *RC, 00045 const MachineOperand &Op) const; 00046 00047 void splitScalar64BitUnaryOp(SmallVectorImpl<MachineInstr *> &Worklist, 00048 MachineInstr *Inst, unsigned Opcode) const; 00049 00050 void splitScalar64BitBinaryOp(SmallVectorImpl<MachineInstr *> &Worklist, 00051 MachineInstr *Inst, unsigned Opcode) const; 00052 00053 void splitScalar64BitBCNT(SmallVectorImpl<MachineInstr *> &Worklist, 00054 MachineInstr *Inst) const; 00055 00056 void addDescImplicitUseDef(const MCInstrDesc &Desc, MachineInstr *MI) const; 00057 00058 public: 00059 explicit SIInstrInfo(const AMDGPUSubtarget &st); 00060 00061 const SIRegisterInfo &getRegisterInfo() const override { 00062 return RI; 00063 } 00064 00065 bool areLoadsFromSameBasePtr(SDNode *Load1, SDNode *Load2, 00066 int64_t &Offset1, 00067 int64_t &Offset2) const override; 00068 00069 bool getLdStBaseRegImmOfs(MachineInstr *LdSt, 00070 unsigned &BaseReg, unsigned &Offset, 00071 const TargetRegisterInfo *TRI) const final; 00072 00073 bool shouldClusterLoads(MachineInstr *FirstLdSt, 00074 MachineInstr *SecondLdSt, 00075 unsigned NumLoads) const final; 00076 00077 void copyPhysReg(MachineBasicBlock &MBB, 00078 MachineBasicBlock::iterator MI, DebugLoc DL, 00079 unsigned DestReg, unsigned SrcReg, 00080 bool KillSrc) const override; 00081 00082 void storeRegToStackSlot(MachineBasicBlock &MBB, 00083 MachineBasicBlock::iterator MI, 00084 unsigned SrcReg, bool isKill, int FrameIndex, 00085 const TargetRegisterClass *RC, 00086 const TargetRegisterInfo *TRI) const override; 00087 00088 void loadRegFromStackSlot(MachineBasicBlock &MBB, 00089 MachineBasicBlock::iterator MI, 00090 unsigned DestReg, int FrameIndex, 00091 const TargetRegisterClass *RC, 00092 const TargetRegisterInfo *TRI) const override; 00093 00094 bool expandPostRAPseudo(MachineBasicBlock::iterator MI) const override; 00095 00096 unsigned commuteOpcode(unsigned Opcode) const; 00097 00098 MachineInstr *commuteInstruction(MachineInstr *MI, 00099 bool NewMI=false) const override; 00100 00101 bool isTriviallyReMaterializable(const MachineInstr *MI, 00102 AliasAnalysis *AA = nullptr) const; 00103 00104 MachineInstr *buildMovInstr(MachineBasicBlock *MBB, 00105 MachineBasicBlock::iterator I, 00106 unsigned DstReg, unsigned SrcReg) const override; 00107 bool isMov(unsigned Opcode) const override; 00108 00109 bool isSafeToMoveRegClassDefs(const TargetRegisterClass *RC) const override; 00110 bool isDS(uint16_t Opcode) const; 00111 bool isMIMG(uint16_t Opcode) const; 00112 bool isSMRD(uint16_t Opcode) const; 00113 bool isMUBUF(uint16_t Opcode) const; 00114 bool isMTBUF(uint16_t Opcode) const; 00115 bool isFLAT(uint16_t Opcode) const; 00116 bool isVOP1(uint16_t Opcode) const; 00117 bool isVOP2(uint16_t Opcode) const; 00118 bool isVOP3(uint16_t Opcode) const; 00119 bool isVOPC(uint16_t Opcode) const; 00120 bool isInlineConstant(const APInt &Imm) const; 00121 bool isInlineConstant(const MachineOperand &MO) const; 00122 bool isLiteralConstant(const MachineOperand &MO) const; 00123 00124 bool isImmOperandLegal(const MachineInstr *MI, unsigned OpNo, 00125 const MachineOperand &MO) const; 00126 00127 /// \brief Return true if the given offset Size in bytes can be folded into 00128 /// the immediate offsets of a memory instruction for the given address space. 00129 static bool canFoldOffset(unsigned OffsetSize, unsigned AS) LLVM_READNONE; 00130 00131 /// \brief Return true if this 64-bit VALU instruction has a 32-bit encoding. 00132 /// This function will return false if you pass it a 32-bit instruction. 00133 bool hasVALU32BitEncoding(unsigned Opcode) const; 00134 00135 /// \brief Return true if this instruction has any modifiers. 00136 /// e.g. src[012]_mod, omod, clamp. 00137 bool hasModifiers(unsigned Opcode) const; 00138 bool verifyInstruction(const MachineInstr *MI, 00139 StringRef &ErrInfo) const override; 00140 00141 bool isSALUInstr(const MachineInstr &MI) const; 00142 static unsigned getVALUOp(const MachineInstr &MI); 00143 00144 bool isSALUOpSupportedOnVALU(const MachineInstr &MI) const; 00145 00146 /// \brief Return the correct register class for \p OpNo. For target-specific 00147 /// instructions, this will return the register class that has been defined 00148 /// in tablegen. For generic instructions, like REG_SEQUENCE it will return 00149 /// the register class of its machine operand. 00150 /// to infer the correct register class base on the other operands. 00151 const TargetRegisterClass *getOpRegClass(const MachineInstr &MI, 00152 unsigned OpNo) const;\ 00153 00154 /// \returns true if it is legal for the operand at index \p OpNo 00155 /// to read a VGPR. 00156 bool canReadVGPR(const MachineInstr &MI, unsigned OpNo) const; 00157 00158 /// \brief Legalize the \p OpIndex operand of this instruction by inserting 00159 /// a MOV. For example: 00160 /// ADD_I32_e32 VGPR0, 15 00161 /// to 00162 /// MOV VGPR1, 15 00163 /// ADD_I32_e32 VGPR0, VGPR1 00164 /// 00165 /// If the operand being legalized is a register, then a COPY will be used 00166 /// instead of MOV. 00167 void legalizeOpWithMove(MachineInstr *MI, unsigned OpIdx) const; 00168 00169 /// \brief Check if \p MO is a legal operand if it was the \p OpIdx Operand 00170 /// for \p MI. 00171 bool isOperandLegal(const MachineInstr *MI, unsigned OpIdx, 00172 const MachineOperand *MO = nullptr) const; 00173 00174 /// \brief Legalize all operands in this instruction. This function may 00175 /// create new instruction and insert them before \p MI. 00176 void legalizeOperands(MachineInstr *MI) const; 00177 00178 /// \brief Split an SMRD instruction into two smaller loads of half the 00179 // size storing the results in \p Lo and \p Hi. 00180 void splitSMRD(MachineInstr *MI, const TargetRegisterClass *HalfRC, 00181 unsigned HalfImmOp, unsigned HalfSGPROp, 00182 MachineInstr *&Lo, MachineInstr *&Hi) const; 00183 00184 void moveSMRDToVALU(MachineInstr *MI, MachineRegisterInfo &MRI) const; 00185 00186 /// \brief Replace this instruction's opcode with the equivalent VALU 00187 /// opcode. This function will also move the users of \p MI to the 00188 /// VALU if necessary. 00189 void moveToVALU(MachineInstr &MI) const; 00190 00191 unsigned calculateIndirectAddress(unsigned RegIndex, 00192 unsigned Channel) const override; 00193 00194 const TargetRegisterClass *getIndirectAddrRegClass() const override; 00195 00196 MachineInstrBuilder buildIndirectWrite(MachineBasicBlock *MBB, 00197 MachineBasicBlock::iterator I, 00198 unsigned ValueReg, 00199 unsigned Address, 00200 unsigned OffsetReg) const override; 00201 00202 MachineInstrBuilder buildIndirectRead(MachineBasicBlock *MBB, 00203 MachineBasicBlock::iterator I, 00204 unsigned ValueReg, 00205 unsigned Address, 00206 unsigned OffsetReg) const override; 00207 void reserveIndirectRegisters(BitVector &Reserved, 00208 const MachineFunction &MF) const; 00209 00210 void LoadM0(MachineInstr *MoveRel, MachineBasicBlock::iterator I, 00211 unsigned SavReg, unsigned IndexReg) const; 00212 00213 void insertNOPs(MachineBasicBlock::iterator MI, int Count) const; 00214 00215 /// \brief Returns the operand named \p Op. If \p MI does not have an 00216 /// operand named \c Op, this function returns nullptr. 00217 MachineOperand *getNamedOperand(MachineInstr &MI, unsigned OperandName) const; 00218 }; 00219 00220 namespace AMDGPU { 00221 00222 int getVOPe64(uint16_t Opcode); 00223 int getVOPe32(uint16_t Opcode); 00224 int getCommuteRev(uint16_t Opcode); 00225 int getCommuteOrig(uint16_t Opcode); 00226 int getMCOpcode(uint16_t Opcode, unsigned Gen); 00227 int getAddr64Inst(uint16_t Opcode); 00228 int getAtomicRetOp(uint16_t Opcode); 00229 int getAtomicNoRetOp(uint16_t Opcode); 00230 00231 const uint64_t RSRC_DATA_FORMAT = 0xf00000000000LL; 00232 const uint64_t RSRC_TID_ENABLE = 1LL << 55; 00233 00234 } // End namespace AMDGPU 00235 00236 } // End namespace llvm 00237 00238 namespace SIInstrFlags { 00239 enum Flags { 00240 // First 4 bits are the instruction encoding 00241 VM_CNT = 1 << 0, 00242 EXP_CNT = 1 << 1, 00243 LGKM_CNT = 1 << 2 00244 }; 00245 } 00246 00247 namespace SISrcMods { 00248 enum { 00249 NEG = 1 << 0, 00250 ABS = 1 << 1 00251 }; 00252 } 00253 00254 #endif