blob: 53e8b23b3d62e73f4ca9d63cccf07804ed964eb6 [file] [log] [blame]
Tom Stellard75aadc22012-12-11 21:25:42 +00001//===-- 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 Kramera7c40ef2014-08-13 16:26:38 +000016#ifndef LLVM_LIB_TARGET_R600_AMDGPUINSTRINFO_H
17#define LLVM_LIB_TARGET_R600_AMDGPUINSTRINFO_H
Tom Stellard75aadc22012-12-11 21:25:42 +000018
Chandler Carruthbe810232013-01-02 10:22:59 +000019#include "AMDGPURegisterInfo.h"
Tom Stellard75aadc22012-12-11 21:25:42 +000020#include "llvm/Target/TargetInstrInfo.h"
Tom Stellard75aadc22012-12-11 21:25:42 +000021#include <map>
22
23#define GET_INSTRINFO_HEADER
24#define GET_INSTRINFO_ENUM
Tom Stellard02661d92013-06-25 21:22:18 +000025#define GET_INSTRINFO_OPERAND_ENUM
Tom Stellard75aadc22012-12-11 21:25:42 +000026#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
33namespace llvm {
34
Tom Stellard2e59a452014-06-13 01:32:00 +000035class AMDGPUSubtarget;
Tom Stellard75aadc22012-12-11 21:25:42 +000036class MachineFunction;
37class MachineInstr;
38class MachineInstrBuilder;
39
40class AMDGPUInstrInfo : public AMDGPUGenInstrInfo {
41private:
42 const AMDGPURegisterInfo RI;
Juergen Ributzkad12ccbd2013-11-19 00:57:56 +000043 virtual void anchor();
Tom Stellardf3b2a1e2013-02-06 17:32:29 +000044protected:
Tom Stellard2e59a452014-06-13 01:32:00 +000045 const AMDGPUSubtarget &ST;
Tom Stellard75aadc22012-12-11 21:25:42 +000046public:
Tom Stellard2e59a452014-06-13 01:32:00 +000047 explicit AMDGPUInstrInfo(const AMDGPUSubtarget &st);
Tom Stellard75aadc22012-12-11 21:25:42 +000048
49 virtual const AMDGPURegisterInfo &getRegisterInfo() const = 0;
50
51 bool isCoalescableExtInstr(const MachineInstr &MI, unsigned &SrcReg,
Craig Topper5656db42014-04-29 07:57:24 +000052 unsigned &DstReg, unsigned &SubIdx) const override;
Tom Stellard75aadc22012-12-11 21:25:42 +000053
Craig Topper5656db42014-04-29 07:57:24 +000054 unsigned isLoadFromStackSlot(const MachineInstr *MI,
55 int &FrameIndex) const override;
Tom Stellard75aadc22012-12-11 21:25:42 +000056 unsigned isLoadFromStackSlotPostFE(const MachineInstr *MI,
Craig Topper5656db42014-04-29 07:57:24 +000057 int &FrameIndex) const override;
Tom Stellard75aadc22012-12-11 21:25:42 +000058 bool hasLoadFromStackSlot(const MachineInstr *MI,
59 const MachineMemOperand *&MMO,
Craig Topper5656db42014-04-29 07:57:24 +000060 int &FrameIndex) const override;
Tom Stellard75aadc22012-12-11 21:25:42 +000061 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 Topper5656db42014-04-29 07:57:24 +000071 LiveVariables *LV) const override;
Tom Stellard75aadc22012-12-11 21:25:42 +000072
73
Craig Topper5656db42014-04-29 07:57:24 +000074 bool expandPostRAPseudo(MachineBasicBlock::iterator MI) const override;
Tom Stellard26a3b672013-10-22 18:19:10 +000075
Craig Topper5656db42014-04-29 07:57:24 +000076 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 Stellard75aadc22012-12-11 21:25:42 +000086
87protected:
Benjamin Kramerf1362f62015-02-28 12:04:00 +000088 MachineInstr *foldMemoryOperandImpl(MachineFunction &MF, MachineInstr *MI,
89 ArrayRef<unsigned> Ops,
Keno Fischere70b31f2015-06-08 20:09:58 +000090 MachineBasicBlock::iterator InsertPt,
Craig Topper5656db42014-04-29 07:57:24 +000091 int FrameIndex) const override;
Benjamin Kramerf1362f62015-02-28 12:04:00 +000092 MachineInstr *foldMemoryOperandImpl(MachineFunction &MF, MachineInstr *MI,
93 ArrayRef<unsigned> Ops,
Keno Fischere70b31f2015-06-08 20:09:58 +000094 MachineBasicBlock::iterator InsertPt,
Craig Topper5656db42014-04-29 07:57:24 +000095 MachineInstr *LoadMI) const override;
Benjamin Kramerf1362f62015-02-28 12:04:00 +000096
Matt Arsenault3f981402014-09-15 15:41:53 +000097public:
Tom Stellard81d871d2013-11-13 23:36:50 +000098 /// \returns the smallest register index that will be accessed by an indirect
99 /// read or write or -1 if indirect addressing is not used by this program.
Craig Topperee7b0f32014-04-30 05:53:27 +0000100 int getIndirectIndexBegin(const MachineFunction &MF) const;
Tom Stellard81d871d2013-11-13 23:36:50 +0000101
102 /// \returns the largest register index that will be accessed by an indirect
103 /// read or write or -1 if indirect addressing is not used by this program.
Craig Topperee7b0f32014-04-30 05:53:27 +0000104 int getIndirectIndexEnd(const MachineFunction &MF) const;
Tom Stellard81d871d2013-11-13 23:36:50 +0000105
Tom Stellard75aadc22012-12-11 21:25:42 +0000106 bool unfoldMemoryOperand(MachineFunction &MF, MachineInstr *MI,
Craig Topper5656db42014-04-29 07:57:24 +0000107 unsigned Reg, bool UnfoldLoad, bool UnfoldStore,
108 SmallVectorImpl<MachineInstr *> &NewMIs) const override;
Tom Stellard75aadc22012-12-11 21:25:42 +0000109 bool unfoldMemoryOperand(SelectionDAG &DAG, SDNode *N,
Craig Topper5656db42014-04-29 07:57:24 +0000110 SmallVectorImpl<SDNode *> &NewNodes) const override;
Tom Stellard75aadc22012-12-11 21:25:42 +0000111 unsigned getOpcodeAfterMemoryUnfold(unsigned Opc,
Craig Topper5656db42014-04-29 07:57:24 +0000112 bool UnfoldLoad, bool UnfoldStore,
113 unsigned *LoadRegIndex = nullptr) const override;
Matt Arsenault034d6662014-07-24 02:10:17 +0000114
115 bool enableClusterLoads() const override;
116
Tom Stellard75aadc22012-12-11 21:25:42 +0000117 bool shouldScheduleLoadsNear(SDNode *Load1, SDNode *Load2,
118 int64_t Offset1, int64_t Offset2,
Craig Topper5656db42014-04-29 07:57:24 +0000119 unsigned NumLoads) const override;
Tom Stellard75aadc22012-12-11 21:25:42 +0000120
Craig Topper5656db42014-04-29 07:57:24 +0000121 bool
122 ReverseBranchCondition(SmallVectorImpl<MachineOperand> &Cond) const override;
Tom Stellard75aadc22012-12-11 21:25:42 +0000123 void insertNoop(MachineBasicBlock &MBB,
Craig Topper5656db42014-04-29 07:57:24 +0000124 MachineBasicBlock::iterator MI) const override;
125 bool isPredicated(const MachineInstr *MI) const override;
Ahmed Bougachac88bf542015-06-11 19:30:37 +0000126 bool SubsumesPredicate(ArrayRef<MachineOperand> Pred1,
127 ArrayRef<MachineOperand> Pred2) const override;
Tom Stellard75aadc22012-12-11 21:25:42 +0000128 bool DefinesPredicate(MachineInstr *MI,
Craig Topper5656db42014-04-29 07:57:24 +0000129 std::vector<MachineOperand> &Pred) const override;
130 bool isPredicable(MachineInstr *MI) const override;
131 bool isSafeToMoveRegClassDefs(const TargetRegisterClass *RC) const override;
Tom Stellard75aadc22012-12-11 21:25:42 +0000132
133 // Helper functions that check the opcode for status information
Tom Stellardf3b2a1e2013-02-06 17:32:29 +0000134 bool isRegisterStore(const MachineInstr &MI) const;
135 bool isRegisterLoad(const MachineInstr &MI) const;
136
Marek Olsaka93603d2015-01-15 18:42:51 +0000137 /// \brief Return a target-specific opcode if Opcode is a pseudo instruction.
138 /// Return -1 if the target-specific opcode for the pseudo instruction does
139 /// not exist. If Opcode is not a pseudo instruction, this is identity.
140 int pseudoToMCOpcode(int Opcode) const;
141
Marek Olsak3db6ba82015-02-03 17:37:57 +0000142 /// \brief Return the descriptor of the target-specific machine instruction
143 /// that corresponds to the specified pseudo or native opcode.
144 const MCInstrDesc &getMCOpcodeFromPseudo(unsigned Opcode) const {
145 return get(pseudoToMCOpcode(Opcode));
146 }
147
Alex Lorenzef5c1962015-07-28 23:02:45 +0000148 ArrayRef<std::pair<int, const char *>>
149 getSerializableTargetIndices() const override;
150
Tom Stellardf3b2a1e2013-02-06 17:32:29 +0000151//===---------------------------------------------------------------------===//
152// Pure virtual funtions to be implemented by sub-classes.
153//===---------------------------------------------------------------------===//
Tom Stellard75aadc22012-12-11 21:25:42 +0000154
Tom Stellard75aadc22012-12-11 21:25:42 +0000155 virtual bool isMov(unsigned opcode) const = 0;
156
Tom Stellardf3b2a1e2013-02-06 17:32:29 +0000157 /// \brief Calculate the "Indirect Address" for the given \p RegIndex and
158 /// \p Channel
159 ///
160 /// We model indirect addressing using a virtual address space that can be
161 /// accesed with loads and stores. The "Indirect Address" is the memory
162 /// address in this virtual address space that maps to the given \p RegIndex
163 /// and \p Channel.
164 virtual unsigned calculateIndirectAddress(unsigned RegIndex,
165 unsigned Channel) const = 0;
166
Tom Stellard26a3b672013-10-22 18:19:10 +0000167 /// \returns The register class to be used for loading and storing values
168 /// from an "Indirect Address" .
169 virtual const TargetRegisterClass *getIndirectAddrRegClass() const = 0;
Tom Stellardf3b2a1e2013-02-06 17:32:29 +0000170
171 /// \brief Build instruction(s) for an indirect register write.
172 ///
173 /// \returns The instruction that performs the indirect register write
174 virtual MachineInstrBuilder buildIndirectWrite(MachineBasicBlock *MBB,
175 MachineBasicBlock::iterator I,
176 unsigned ValueReg, unsigned Address,
177 unsigned OffsetReg) const = 0;
178
179 /// \brief Build instruction(s) for an indirect register read.
180 ///
181 /// \returns The instruction that performs the indirect register read
182 virtual MachineInstrBuilder buildIndirectRead(MachineBasicBlock *MBB,
183 MachineBasicBlock::iterator I,
184 unsigned ValueReg, unsigned Address,
185 unsigned OffsetReg) const = 0;
186
Tom Stellard26a3b672013-10-22 18:19:10 +0000187 /// \brief Build a MOV instruction.
188 virtual MachineInstr *buildMovInstr(MachineBasicBlock *MBB,
189 MachineBasicBlock::iterator I,
190 unsigned DstReg, unsigned SrcReg) const = 0;
191
Tom Stellard682bfbc2013-10-10 17:11:24 +0000192 /// \brief Given a MIMG \p Opcode that writes all 4 channels, return the
193 /// equivalent opcode that writes \p Channels Channels.
194 int getMaskedMIMGOp(uint16_t Opcode, unsigned Channels) const;
Tom Stellard26a3b672013-10-22 18:19:10 +0000195
Tom Stellard75aadc22012-12-11 21:25:42 +0000196};
197
Tom Stellard02661d92013-06-25 21:22:18 +0000198namespace AMDGPU {
Matt Arsenaultf743b832015-09-25 18:09:15 +0000199 LLVM_READONLY
Tom Stellard02661d92013-06-25 21:22:18 +0000200 int16_t getNamedOperandIdx(uint16_t Opcode, uint16_t NamedIndex);
201} // End namespace AMDGPU
202
Alexander Kornienkof00654e2015-06-23 09:49:53 +0000203} // End llvm namespace
Tom Stellard75aadc22012-12-11 21:25:42 +0000204
Tom Stellardf3b2a1e2013-02-06 17:32:29 +0000205#define AMDGPU_FLAG_REGISTER_LOAD (UINT64_C(1) << 63)
206#define AMDGPU_FLAG_REGISTER_STORE (UINT64_C(1) << 62)
207
Benjamin Kramera7c40ef2014-08-13 16:26:38 +0000208#endif