Tom Stellard | 75aadc2 | 2012-12-11 21:25:42 +0000 | [diff] [blame] | 1 | //===-- AMDGPUInstrInfo.h - AMDGPU Instruction Information ------*- 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 Contains the definition of a TargetInstrInfo class that is common |
| 12 | /// to all AMD GPUs. |
| 13 | // |
| 14 | //===----------------------------------------------------------------------===// |
| 15 | |
Benjamin Kramer | a7c40ef | 2014-08-13 16:26:38 +0000 | [diff] [blame] | 16 | #ifndef LLVM_LIB_TARGET_R600_AMDGPUINSTRINFO_H |
| 17 | #define LLVM_LIB_TARGET_R600_AMDGPUINSTRINFO_H |
Tom Stellard | 75aadc2 | 2012-12-11 21:25:42 +0000 | [diff] [blame] | 18 | |
Chandler Carruth | be81023 | 2013-01-02 10:22:59 +0000 | [diff] [blame] | 19 | #include "AMDGPURegisterInfo.h" |
Tom Stellard | 75aadc2 | 2012-12-11 21:25:42 +0000 | [diff] [blame] | 20 | #include "llvm/Target/TargetInstrInfo.h" |
Tom Stellard | 75aadc2 | 2012-12-11 21:25:42 +0000 | [diff] [blame] | 21 | #include <map> |
| 22 | |
| 23 | #define GET_INSTRINFO_HEADER |
| 24 | #define GET_INSTRINFO_ENUM |
Tom Stellard | 02661d9 | 2013-06-25 21:22:18 +0000 | [diff] [blame] | 25 | #define GET_INSTRINFO_OPERAND_ENUM |
Tom Stellard | 75aadc2 | 2012-12-11 21:25:42 +0000 | [diff] [blame] | 26 | #include "AMDGPUGenInstrInfo.inc" |
| 27 | |
| 28 | #define OPCODE_IS_ZERO_INT AMDGPU::PRED_SETE_INT |
| 29 | #define OPCODE_IS_NOT_ZERO_INT AMDGPU::PRED_SETNE_INT |
| 30 | #define OPCODE_IS_ZERO AMDGPU::PRED_SETE |
| 31 | #define OPCODE_IS_NOT_ZERO AMDGPU::PRED_SETNE |
| 32 | |
| 33 | namespace llvm { |
| 34 | |
Tom Stellard | 2e59a45 | 2014-06-13 01:32:00 +0000 | [diff] [blame] | 35 | class AMDGPUSubtarget; |
Tom Stellard | 75aadc2 | 2012-12-11 21:25:42 +0000 | [diff] [blame] | 36 | class MachineFunction; |
| 37 | class MachineInstr; |
| 38 | class MachineInstrBuilder; |
| 39 | |
| 40 | class AMDGPUInstrInfo : public AMDGPUGenInstrInfo { |
| 41 | private: |
| 42 | const AMDGPURegisterInfo RI; |
Juergen Ributzka | d12ccbd | 2013-11-19 00:57:56 +0000 | [diff] [blame] | 43 | virtual void anchor(); |
Tom Stellard | f3b2a1e | 2013-02-06 17:32:29 +0000 | [diff] [blame] | 44 | protected: |
Tom Stellard | 2e59a45 | 2014-06-13 01:32:00 +0000 | [diff] [blame] | 45 | const AMDGPUSubtarget &ST; |
Tom Stellard | 75aadc2 | 2012-12-11 21:25:42 +0000 | [diff] [blame] | 46 | public: |
Tom Stellard | 2e59a45 | 2014-06-13 01:32:00 +0000 | [diff] [blame] | 47 | explicit AMDGPUInstrInfo(const AMDGPUSubtarget &st); |
Tom Stellard | 75aadc2 | 2012-12-11 21:25:42 +0000 | [diff] [blame] | 48 | |
| 49 | virtual const AMDGPURegisterInfo &getRegisterInfo() const = 0; |
| 50 | |
| 51 | bool isCoalescableExtInstr(const MachineInstr &MI, unsigned &SrcReg, |
Craig Topper | 5656db4 | 2014-04-29 07:57:24 +0000 | [diff] [blame] | 52 | unsigned &DstReg, unsigned &SubIdx) const override; |
Tom Stellard | 75aadc2 | 2012-12-11 21:25:42 +0000 | [diff] [blame] | 53 | |
Craig Topper | 5656db4 | 2014-04-29 07:57:24 +0000 | [diff] [blame] | 54 | unsigned isLoadFromStackSlot(const MachineInstr *MI, |
| 55 | int &FrameIndex) const override; |
Tom Stellard | 75aadc2 | 2012-12-11 21:25:42 +0000 | [diff] [blame] | 56 | unsigned isLoadFromStackSlotPostFE(const MachineInstr *MI, |
Craig Topper | 5656db4 | 2014-04-29 07:57:24 +0000 | [diff] [blame] | 57 | int &FrameIndex) const override; |
Tom Stellard | 75aadc2 | 2012-12-11 21:25:42 +0000 | [diff] [blame] | 58 | bool hasLoadFromStackSlot(const MachineInstr *MI, |
| 59 | const MachineMemOperand *&MMO, |
Craig Topper | 5656db4 | 2014-04-29 07:57:24 +0000 | [diff] [blame] | 60 | int &FrameIndex) const override; |
Tom Stellard | 75aadc2 | 2012-12-11 21:25:42 +0000 | [diff] [blame] | 61 | unsigned isStoreFromStackSlot(const MachineInstr *MI, int &FrameIndex) const; |
| 62 | unsigned isStoreFromStackSlotPostFE(const MachineInstr *MI, |
| 63 | int &FrameIndex) const; |
| 64 | bool hasStoreFromStackSlot(const MachineInstr *MI, |
| 65 | const MachineMemOperand *&MMO, |
| 66 | int &FrameIndex) const; |
| 67 | |
| 68 | MachineInstr * |
| 69 | convertToThreeAddress(MachineFunction::iterator &MFI, |
| 70 | MachineBasicBlock::iterator &MBBI, |
Craig Topper | 5656db4 | 2014-04-29 07:57:24 +0000 | [diff] [blame] | 71 | LiveVariables *LV) const override; |
Tom Stellard | 75aadc2 | 2012-12-11 21:25:42 +0000 | [diff] [blame] | 72 | |
| 73 | |
Craig Topper | 5656db4 | 2014-04-29 07:57:24 +0000 | [diff] [blame] | 74 | bool expandPostRAPseudo(MachineBasicBlock::iterator MI) const override; |
Tom Stellard | 26a3b67 | 2013-10-22 18:19:10 +0000 | [diff] [blame] | 75 | |
Craig Topper | 5656db4 | 2014-04-29 07:57:24 +0000 | [diff] [blame] | 76 | void storeRegToStackSlot(MachineBasicBlock &MBB, |
| 77 | MachineBasicBlock::iterator MI, |
| 78 | unsigned SrcReg, bool isKill, int FrameIndex, |
| 79 | const TargetRegisterClass *RC, |
| 80 | const TargetRegisterInfo *TRI) const override; |
| 81 | void loadRegFromStackSlot(MachineBasicBlock &MBB, |
| 82 | MachineBasicBlock::iterator MI, |
| 83 | unsigned DestReg, int FrameIndex, |
| 84 | const TargetRegisterClass *RC, |
| 85 | const TargetRegisterInfo *TRI) const override; |
Tom Stellard | 75aadc2 | 2012-12-11 21:25:42 +0000 | [diff] [blame] | 86 | |
| 87 | protected: |
| 88 | MachineInstr *foldMemoryOperandImpl(MachineFunction &MF, |
| 89 | MachineInstr *MI, |
| 90 | const SmallVectorImpl<unsigned> &Ops, |
Craig Topper | 5656db4 | 2014-04-29 07:57:24 +0000 | [diff] [blame] | 91 | int FrameIndex) const override; |
Tom Stellard | 75aadc2 | 2012-12-11 21:25:42 +0000 | [diff] [blame] | 92 | MachineInstr *foldMemoryOperandImpl(MachineFunction &MF, |
| 93 | MachineInstr *MI, |
| 94 | const SmallVectorImpl<unsigned> &Ops, |
Craig Topper | 5656db4 | 2014-04-29 07:57:24 +0000 | [diff] [blame] | 95 | MachineInstr *LoadMI) const override; |
Matt Arsenault | 3f98140 | 2014-09-15 15:41:53 +0000 | [diff] [blame] | 96 | public: |
Tom Stellard | 81d871d | 2013-11-13 23:36:50 +0000 | [diff] [blame] | 97 | /// \returns the smallest register index that will be accessed by an indirect |
| 98 | /// read or write or -1 if indirect addressing is not used by this program. |
Craig Topper | ee7b0f3 | 2014-04-30 05:53:27 +0000 | [diff] [blame] | 99 | int getIndirectIndexBegin(const MachineFunction &MF) const; |
Tom Stellard | 81d871d | 2013-11-13 23:36:50 +0000 | [diff] [blame] | 100 | |
| 101 | /// \returns the largest register index that will be accessed by an indirect |
| 102 | /// read or write or -1 if indirect addressing is not used by this program. |
Craig Topper | ee7b0f3 | 2014-04-30 05:53:27 +0000 | [diff] [blame] | 103 | int getIndirectIndexEnd(const MachineFunction &MF) const; |
Tom Stellard | 81d871d | 2013-11-13 23:36:50 +0000 | [diff] [blame] | 104 | |
Tom Stellard | 75aadc2 | 2012-12-11 21:25:42 +0000 | [diff] [blame] | 105 | bool canFoldMemoryOperand(const MachineInstr *MI, |
Craig Topper | 5656db4 | 2014-04-29 07:57:24 +0000 | [diff] [blame] | 106 | const SmallVectorImpl<unsigned> &Ops) const override; |
Tom Stellard | 75aadc2 | 2012-12-11 21:25:42 +0000 | [diff] [blame] | 107 | bool unfoldMemoryOperand(MachineFunction &MF, MachineInstr *MI, |
Craig Topper | 5656db4 | 2014-04-29 07:57:24 +0000 | [diff] [blame] | 108 | unsigned Reg, bool UnfoldLoad, bool UnfoldStore, |
| 109 | SmallVectorImpl<MachineInstr *> &NewMIs) const override; |
Tom Stellard | 75aadc2 | 2012-12-11 21:25:42 +0000 | [diff] [blame] | 110 | bool unfoldMemoryOperand(SelectionDAG &DAG, SDNode *N, |
Craig Topper | 5656db4 | 2014-04-29 07:57:24 +0000 | [diff] [blame] | 111 | SmallVectorImpl<SDNode *> &NewNodes) const override; |
Tom Stellard | 75aadc2 | 2012-12-11 21:25:42 +0000 | [diff] [blame] | 112 | unsigned getOpcodeAfterMemoryUnfold(unsigned Opc, |
Craig Topper | 5656db4 | 2014-04-29 07:57:24 +0000 | [diff] [blame] | 113 | bool UnfoldLoad, bool UnfoldStore, |
| 114 | unsigned *LoadRegIndex = nullptr) const override; |
Matt Arsenault | 034d666 | 2014-07-24 02:10:17 +0000 | [diff] [blame] | 115 | |
| 116 | bool enableClusterLoads() const override; |
| 117 | |
Tom Stellard | 75aadc2 | 2012-12-11 21:25:42 +0000 | [diff] [blame] | 118 | bool shouldScheduleLoadsNear(SDNode *Load1, SDNode *Load2, |
| 119 | int64_t Offset1, int64_t Offset2, |
Craig Topper | 5656db4 | 2014-04-29 07:57:24 +0000 | [diff] [blame] | 120 | unsigned NumLoads) const override; |
Tom Stellard | 75aadc2 | 2012-12-11 21:25:42 +0000 | [diff] [blame] | 121 | |
Craig Topper | 5656db4 | 2014-04-29 07:57:24 +0000 | [diff] [blame] | 122 | bool |
| 123 | ReverseBranchCondition(SmallVectorImpl<MachineOperand> &Cond) const override; |
Tom Stellard | 75aadc2 | 2012-12-11 21:25:42 +0000 | [diff] [blame] | 124 | void insertNoop(MachineBasicBlock &MBB, |
Craig Topper | 5656db4 | 2014-04-29 07:57:24 +0000 | [diff] [blame] | 125 | MachineBasicBlock::iterator MI) const override; |
| 126 | bool isPredicated(const MachineInstr *MI) const override; |
Tom Stellard | 75aadc2 | 2012-12-11 21:25:42 +0000 | [diff] [blame] | 127 | bool SubsumesPredicate(const SmallVectorImpl<MachineOperand> &Pred1, |
Craig Topper | 5656db4 | 2014-04-29 07:57:24 +0000 | [diff] [blame] | 128 | const SmallVectorImpl<MachineOperand> &Pred2) const override; |
Tom Stellard | 75aadc2 | 2012-12-11 21:25:42 +0000 | [diff] [blame] | 129 | bool DefinesPredicate(MachineInstr *MI, |
Craig Topper | 5656db4 | 2014-04-29 07:57:24 +0000 | [diff] [blame] | 130 | std::vector<MachineOperand> &Pred) const override; |
| 131 | bool isPredicable(MachineInstr *MI) const override; |
| 132 | bool isSafeToMoveRegClassDefs(const TargetRegisterClass *RC) const override; |
Tom Stellard | 75aadc2 | 2012-12-11 21:25:42 +0000 | [diff] [blame] | 133 | |
| 134 | // Helper functions that check the opcode for status information |
Tom Stellard | f3b2a1e | 2013-02-06 17:32:29 +0000 | [diff] [blame] | 135 | bool isRegisterStore(const MachineInstr &MI) const; |
| 136 | bool isRegisterLoad(const MachineInstr &MI) const; |
| 137 | |
Marek Olsak | a93603d | 2015-01-15 18:42:51 +0000 | [diff] [blame] | 138 | /// \brief Return a target-specific opcode if Opcode is a pseudo instruction. |
| 139 | /// Return -1 if the target-specific opcode for the pseudo instruction does |
| 140 | /// not exist. If Opcode is not a pseudo instruction, this is identity. |
| 141 | int pseudoToMCOpcode(int Opcode) const; |
| 142 | |
Marek Olsak | 3db6ba8 | 2015-02-03 17:37:57 +0000 | [diff] [blame^] | 143 | /// \brief Return the descriptor of the target-specific machine instruction |
| 144 | /// that corresponds to the specified pseudo or native opcode. |
| 145 | const MCInstrDesc &getMCOpcodeFromPseudo(unsigned Opcode) const { |
| 146 | return get(pseudoToMCOpcode(Opcode)); |
| 147 | } |
| 148 | |
Tom Stellard | f3b2a1e | 2013-02-06 17:32:29 +0000 | [diff] [blame] | 149 | //===---------------------------------------------------------------------===// |
| 150 | // Pure virtual funtions to be implemented by sub-classes. |
| 151 | //===---------------------------------------------------------------------===// |
Tom Stellard | 75aadc2 | 2012-12-11 21:25:42 +0000 | [diff] [blame] | 152 | |
Tom Stellard | 75aadc2 | 2012-12-11 21:25:42 +0000 | [diff] [blame] | 153 | virtual bool isMov(unsigned opcode) const = 0; |
| 154 | |
Tom Stellard | f3b2a1e | 2013-02-06 17:32:29 +0000 | [diff] [blame] | 155 | /// \brief Calculate the "Indirect Address" for the given \p RegIndex and |
| 156 | /// \p Channel |
| 157 | /// |
| 158 | /// We model indirect addressing using a virtual address space that can be |
| 159 | /// accesed with loads and stores. The "Indirect Address" is the memory |
| 160 | /// address in this virtual address space that maps to the given \p RegIndex |
| 161 | /// and \p Channel. |
| 162 | virtual unsigned calculateIndirectAddress(unsigned RegIndex, |
| 163 | unsigned Channel) const = 0; |
| 164 | |
Tom Stellard | 26a3b67 | 2013-10-22 18:19:10 +0000 | [diff] [blame] | 165 | /// \returns The register class to be used for loading and storing values |
| 166 | /// from an "Indirect Address" . |
| 167 | virtual const TargetRegisterClass *getIndirectAddrRegClass() const = 0; |
Tom Stellard | f3b2a1e | 2013-02-06 17:32:29 +0000 | [diff] [blame] | 168 | |
| 169 | /// \brief Build instruction(s) for an indirect register write. |
| 170 | /// |
| 171 | /// \returns The instruction that performs the indirect register write |
| 172 | virtual MachineInstrBuilder buildIndirectWrite(MachineBasicBlock *MBB, |
| 173 | MachineBasicBlock::iterator I, |
| 174 | unsigned ValueReg, unsigned Address, |
| 175 | unsigned OffsetReg) const = 0; |
| 176 | |
| 177 | /// \brief Build instruction(s) for an indirect register read. |
| 178 | /// |
| 179 | /// \returns The instruction that performs the indirect register read |
| 180 | virtual MachineInstrBuilder buildIndirectRead(MachineBasicBlock *MBB, |
| 181 | MachineBasicBlock::iterator I, |
| 182 | unsigned ValueReg, unsigned Address, |
| 183 | unsigned OffsetReg) const = 0; |
| 184 | |
Tom Stellard | 26a3b67 | 2013-10-22 18:19:10 +0000 | [diff] [blame] | 185 | /// \brief Build a MOV instruction. |
| 186 | virtual MachineInstr *buildMovInstr(MachineBasicBlock *MBB, |
| 187 | MachineBasicBlock::iterator I, |
| 188 | unsigned DstReg, unsigned SrcReg) const = 0; |
| 189 | |
Tom Stellard | 682bfbc | 2013-10-10 17:11:24 +0000 | [diff] [blame] | 190 | /// \brief Given a MIMG \p Opcode that writes all 4 channels, return the |
| 191 | /// equivalent opcode that writes \p Channels Channels. |
| 192 | int getMaskedMIMGOp(uint16_t Opcode, unsigned Channels) const; |
Tom Stellard | 26a3b67 | 2013-10-22 18:19:10 +0000 | [diff] [blame] | 193 | |
Tom Stellard | 75aadc2 | 2012-12-11 21:25:42 +0000 | [diff] [blame] | 194 | }; |
| 195 | |
Tom Stellard | 02661d9 | 2013-06-25 21:22:18 +0000 | [diff] [blame] | 196 | namespace AMDGPU { |
| 197 | int16_t getNamedOperandIdx(uint16_t Opcode, uint16_t NamedIndex); |
| 198 | } // End namespace AMDGPU |
| 199 | |
Tom Stellard | 75aadc2 | 2012-12-11 21:25:42 +0000 | [diff] [blame] | 200 | } // End llvm namespace |
| 201 | |
Tom Stellard | f3b2a1e | 2013-02-06 17:32:29 +0000 | [diff] [blame] | 202 | #define AMDGPU_FLAG_REGISTER_LOAD (UINT64_C(1) << 63) |
| 203 | #define AMDGPU_FLAG_REGISTER_STORE (UINT64_C(1) << 62) |
| 204 | |
Benjamin Kramer | a7c40ef | 2014-08-13 16:26:38 +0000 | [diff] [blame] | 205 | #endif |