LLVM API Documentation

R600InstrInfo.h
Go to the documentation of this file.
00001 //===-- R600InstrInfo.h - R600 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 R600InstrInfo
00012 //
00013 //===----------------------------------------------------------------------===//
00014 
00015 #ifndef LLVM_LIB_TARGET_R600_R600INSTRINFO_H
00016 #define LLVM_LIB_TARGET_R600_R600INSTRINFO_H
00017 
00018 #include "AMDGPUInstrInfo.h"
00019 #include "R600Defines.h"
00020 #include "R600RegisterInfo.h"
00021 #include <map>
00022 
00023 namespace llvm {
00024 
00025   class AMDGPUTargetMachine;
00026   class DFAPacketizer;
00027   class ScheduleDAG;
00028   class MachineFunction;
00029   class MachineInstr;
00030   class MachineInstrBuilder;
00031 
00032   class R600InstrInfo : public AMDGPUInstrInfo {
00033   private:
00034   const R600RegisterInfo RI;
00035 
00036   std::vector<std::pair<int, unsigned> >
00037   ExtractSrcs(MachineInstr *MI, const DenseMap<unsigned, unsigned> &PV, unsigned &ConstCount) const;
00038 
00039 
00040   MachineInstrBuilder buildIndirectRead(MachineBasicBlock *MBB,
00041                                         MachineBasicBlock::iterator I,
00042                                         unsigned ValueReg, unsigned Address,
00043                                         unsigned OffsetReg,
00044                                         unsigned AddrChan) const;
00045 
00046   MachineInstrBuilder buildIndirectWrite(MachineBasicBlock *MBB,
00047                                         MachineBasicBlock::iterator I,
00048                                         unsigned ValueReg, unsigned Address,
00049                                         unsigned OffsetReg,
00050                                         unsigned AddrChan) const;
00051   public:
00052   enum BankSwizzle {
00053     ALU_VEC_012_SCL_210 = 0,
00054     ALU_VEC_021_SCL_122,
00055     ALU_VEC_120_SCL_212,
00056     ALU_VEC_102_SCL_221,
00057     ALU_VEC_201,
00058     ALU_VEC_210
00059   };
00060 
00061   explicit R600InstrInfo(const AMDGPUSubtarget &st);
00062 
00063   const R600RegisterInfo &getRegisterInfo() const override;
00064   void copyPhysReg(MachineBasicBlock &MBB,
00065                    MachineBasicBlock::iterator MI, DebugLoc DL,
00066                    unsigned DestReg, unsigned SrcReg,
00067                    bool KillSrc) const override;
00068   bool isLegalToSplitMBBAt(MachineBasicBlock &MBB,
00069                            MachineBasicBlock::iterator MBBI) const override;
00070 
00071   bool isTrig(const MachineInstr &MI) const;
00072   bool isPlaceHolderOpcode(unsigned opcode) const;
00073   bool isReductionOp(unsigned opcode) const;
00074   bool isCubeOp(unsigned opcode) const;
00075 
00076   /// \returns true if this \p Opcode represents an ALU instruction.
00077   bool isALUInstr(unsigned Opcode) const;
00078   bool hasInstrModifiers(unsigned Opcode) const;
00079   bool isLDSInstr(unsigned Opcode) const;
00080   bool isLDSNoRetInstr(unsigned Opcode) const;
00081   bool isLDSRetInstr(unsigned Opcode) const;
00082 
00083   /// \returns true if this \p Opcode represents an ALU instruction or an
00084   /// instruction that will be lowered in ExpandSpecialInstrs Pass.
00085   bool canBeConsideredALU(const MachineInstr *MI) const;
00086 
00087   bool isTransOnly(unsigned Opcode) const;
00088   bool isTransOnly(const MachineInstr *MI) const;
00089   bool isVectorOnly(unsigned Opcode) const;
00090   bool isVectorOnly(const MachineInstr *MI) const;
00091   bool isExport(unsigned Opcode) const;
00092 
00093   bool usesVertexCache(unsigned Opcode) const;
00094   bool usesVertexCache(const MachineInstr *MI) const;
00095   bool usesTextureCache(unsigned Opcode) const;
00096   bool usesTextureCache(const MachineInstr *MI) const;
00097 
00098   bool mustBeLastInClause(unsigned Opcode) const;
00099   bool usesAddressRegister(MachineInstr *MI) const;
00100   bool definesAddressRegister(MachineInstr *MI) const;
00101   bool readsLDSSrcReg(const MachineInstr *MI) const;
00102 
00103   /// \returns The operand index for the given source number.  Legal values
00104   /// for SrcNum are 0, 1, and 2.
00105   int getSrcIdx(unsigned Opcode, unsigned SrcNum) const;
00106   /// \returns The operand Index for the Sel operand given an index to one
00107   /// of the instruction's src operands.
00108   int getSelIdx(unsigned Opcode, unsigned SrcIdx) const;
00109 
00110   /// \returns a pair for each src of an ALU instructions.
00111   /// The first member of a pair is the register id.
00112   /// If register is ALU_CONST, second member is SEL.
00113   /// If register is ALU_LITERAL, second member is IMM.
00114   /// Otherwise, second member value is undefined.
00115   SmallVector<std::pair<MachineOperand *, int64_t>, 3>
00116       getSrcs(MachineInstr *MI) const;
00117 
00118   unsigned  isLegalUpTo(
00119     const std::vector<std::vector<std::pair<int, unsigned> > > &IGSrcs,
00120     const std::vector<R600InstrInfo::BankSwizzle> &Swz,
00121     const std::vector<std::pair<int, unsigned> > &TransSrcs,
00122     R600InstrInfo::BankSwizzle TransSwz) const;
00123 
00124   bool FindSwizzleForVectorSlot(
00125     const std::vector<std::vector<std::pair<int, unsigned> > > &IGSrcs,
00126     std::vector<R600InstrInfo::BankSwizzle> &SwzCandidate,
00127     const std::vector<std::pair<int, unsigned> > &TransSrcs,
00128     R600InstrInfo::BankSwizzle TransSwz) const;
00129 
00130   /// Given the order VEC_012 < VEC_021 < VEC_120 < VEC_102 < VEC_201 < VEC_210
00131   /// returns true and the first (in lexical order) BankSwizzle affectation
00132   /// starting from the one already provided in the Instruction Group MIs that
00133   /// fits Read Port limitations in BS if available. Otherwise returns false
00134   /// and undefined content in BS.
00135   /// isLastAluTrans should be set if the last Alu of MIs will be executed on
00136   /// Trans ALU. In this case, ValidTSwizzle returns the BankSwizzle value to
00137   /// apply to the last instruction.
00138   /// PV holds GPR to PV registers in the Instruction Group MIs.
00139   bool fitsReadPortLimitations(const std::vector<MachineInstr *> &MIs,
00140                                const DenseMap<unsigned, unsigned> &PV,
00141                                std::vector<BankSwizzle> &BS,
00142                                bool isLastAluTrans) const;
00143 
00144   /// An instruction group can only access 2 channel pair (either [XY] or [ZW])
00145   /// from KCache bank on R700+. This function check if MI set in input meet
00146   /// this limitations
00147   bool fitsConstReadLimitations(const std::vector<MachineInstr *> &) const;
00148   /// Same but using const index set instead of MI set.
00149   bool fitsConstReadLimitations(const std::vector<unsigned>&) const;
00150 
00151   /// \brief Vector instructions are instructions that must fill all
00152   /// instruction slots within an instruction group.
00153   bool isVector(const MachineInstr &MI) const;
00154 
00155   bool isMov(unsigned Opcode) const override;
00156 
00157   DFAPacketizer *CreateTargetScheduleState(const TargetMachine *TM,
00158                                            const ScheduleDAG *DAG) const override;
00159 
00160   bool ReverseBranchCondition(SmallVectorImpl<MachineOperand> &Cond) const override;
00161 
00162   bool AnalyzeBranch(MachineBasicBlock &MBB, MachineBasicBlock *&TBB, MachineBasicBlock *&FBB,
00163                      SmallVectorImpl<MachineOperand> &Cond, bool AllowModify) const override;
00164 
00165   unsigned InsertBranch(MachineBasicBlock &MBB, MachineBasicBlock *TBB, MachineBasicBlock *FBB, const SmallVectorImpl<MachineOperand> &Cond, DebugLoc DL) const override;
00166 
00167   unsigned RemoveBranch(MachineBasicBlock &MBB) const override;
00168 
00169   bool isPredicated(const MachineInstr *MI) const override;
00170 
00171   bool isPredicable(MachineInstr *MI) const override;
00172 
00173   bool
00174    isProfitableToDupForIfCvt(MachineBasicBlock &MBB, unsigned NumCyles,
00175                              const BranchProbability &Probability) const override;
00176 
00177   bool isProfitableToIfCvt(MachineBasicBlock &MBB, unsigned NumCyles,
00178                            unsigned ExtraPredCycles,
00179                            const BranchProbability &Probability) const override ;
00180 
00181   bool
00182    isProfitableToIfCvt(MachineBasicBlock &TMBB,
00183                        unsigned NumTCycles, unsigned ExtraTCycles,
00184                        MachineBasicBlock &FMBB,
00185                        unsigned NumFCycles, unsigned ExtraFCycles,
00186                        const BranchProbability &Probability) const override;
00187 
00188   bool DefinesPredicate(MachineInstr *MI,
00189                                   std::vector<MachineOperand> &Pred) const override;
00190 
00191   bool SubsumesPredicate(const SmallVectorImpl<MachineOperand> &Pred1,
00192                          const SmallVectorImpl<MachineOperand> &Pred2) const override;
00193 
00194   bool isProfitableToUnpredicate(MachineBasicBlock &TMBB,
00195                                           MachineBasicBlock &FMBB) const override;
00196 
00197   bool PredicateInstruction(MachineInstr *MI,
00198                         const SmallVectorImpl<MachineOperand> &Pred) const override;
00199 
00200   unsigned int getPredicationCost(const MachineInstr *) const override;
00201 
00202   unsigned int getInstrLatency(const InstrItineraryData *ItinData,
00203                                const MachineInstr *MI,
00204                                unsigned *PredCost = nullptr) const override;
00205 
00206   int getInstrLatency(const InstrItineraryData *ItinData,
00207                       SDNode *Node) const override { return 1;}
00208 
00209   bool expandPostRAPseudo(MachineBasicBlock::iterator MI) const override;
00210 
00211   /// \brief Reserve the registers that may be accesed using indirect addressing.
00212   void reserveIndirectRegisters(BitVector &Reserved,
00213                                 const MachineFunction &MF) const;
00214 
00215   unsigned calculateIndirectAddress(unsigned RegIndex,
00216                                     unsigned Channel) const override;
00217 
00218   const TargetRegisterClass *getIndirectAddrRegClass() const override;
00219 
00220   MachineInstrBuilder buildIndirectWrite(MachineBasicBlock *MBB,
00221                           MachineBasicBlock::iterator I,
00222                           unsigned ValueReg, unsigned Address,
00223                           unsigned OffsetReg) const override;
00224 
00225   MachineInstrBuilder buildIndirectRead(MachineBasicBlock *MBB,
00226                                         MachineBasicBlock::iterator I,
00227                                         unsigned ValueReg, unsigned Address,
00228                                         unsigned OffsetReg) const override;
00229 
00230   unsigned getMaxAlusPerClause() const;
00231 
00232   ///buildDefaultInstruction - This function returns a MachineInstr with
00233   /// all the instruction modifiers initialized to their default values.
00234   /// You can use this function to avoid manually specifying each instruction
00235   /// modifier operand when building a new instruction.
00236   ///
00237   /// \returns a MachineInstr with all the instruction modifiers initialized
00238   /// to their default values.
00239   MachineInstrBuilder buildDefaultInstruction(MachineBasicBlock &MBB,
00240                                               MachineBasicBlock::iterator I,
00241                                               unsigned Opcode,
00242                                               unsigned DstReg,
00243                                               unsigned Src0Reg,
00244                                               unsigned Src1Reg = 0) const;
00245 
00246   MachineInstr *buildSlotOfVectorInstruction(MachineBasicBlock &MBB,
00247                                              MachineInstr *MI,
00248                                              unsigned Slot,
00249                                              unsigned DstReg) const;
00250 
00251   MachineInstr *buildMovImm(MachineBasicBlock &BB,
00252                                   MachineBasicBlock::iterator I,
00253                                   unsigned DstReg,
00254                                   uint64_t Imm) const;
00255 
00256   MachineInstr *buildMovInstr(MachineBasicBlock *MBB,
00257                               MachineBasicBlock::iterator I,
00258                               unsigned DstReg, unsigned SrcReg) const override;
00259 
00260   /// \brief Get the index of Op in the MachineInstr.
00261   ///
00262   /// \returns -1 if the Instruction does not contain the specified \p Op.
00263   int getOperandIdx(const MachineInstr &MI, unsigned Op) const;
00264 
00265   /// \brief Get the index of \p Op for the given Opcode.
00266   ///
00267   /// \returns -1 if the Instruction does not contain the specified \p Op.
00268   int getOperandIdx(unsigned Opcode, unsigned Op) const;
00269 
00270   /// \brief Helper function for setting instruction flag values.
00271   void setImmOperand(MachineInstr *MI, unsigned Op, int64_t Imm) const;
00272 
00273   /// \returns true if this instruction has an operand for storing target flags.
00274   bool hasFlagOperand(const MachineInstr &MI) const;
00275 
00276   ///\brief Add one of the MO_FLAG* flags to the specified \p Operand.
00277   void addFlag(MachineInstr *MI, unsigned Operand, unsigned Flag) const;
00278 
00279   ///\brief Determine if the specified \p Flag is set on this \p Operand.
00280   bool isFlagSet(const MachineInstr &MI, unsigned Operand, unsigned Flag) const;
00281 
00282   /// \param SrcIdx The register source to set the flag on (e.g src0, src1, src2)
00283   /// \param Flag The flag being set.
00284   ///
00285   /// \returns the operand containing the flags for this instruction.
00286   MachineOperand &getFlagOp(MachineInstr *MI, unsigned SrcIdx = 0,
00287                             unsigned Flag = 0) const;
00288 
00289   /// \brief Clear the specified flag on the instruction.
00290   void clearFlag(MachineInstr *MI, unsigned Operand, unsigned Flag) const;
00291 };
00292 
00293 namespace AMDGPU {
00294 
00295 int getLDSNoRetOp(uint16_t Opcode);
00296 
00297 } //End namespace AMDGPU
00298 
00299 } // End llvm namespace
00300 
00301 #endif