1 //===-- AMDGPUInstrInfo.cpp - Base class for AMD GPU InstrInfo ------------===//
3 // The LLVM Compiler Infrastructure
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
8 //===----------------------------------------------------------------------===//
11 /// \brief Implementation of the TargetInstrInfo class that is common to all
14 //===----------------------------------------------------------------------===//
16 #include "AMDGPUInstrInfo.h"
17 #include "AMDGPURegisterInfo.h"
18 #include "AMDGPUTargetMachine.h"
19 #include "llvm/CodeGen/MachineFrameInfo.h"
20 #include "llvm/CodeGen/MachineInstrBuilder.h"
21 #include "llvm/CodeGen/MachineRegisterInfo.h"
23 #define GET_INSTRINFO_CTOR
24 #define GET_INSTRINFO_NAMED_OPS
25 #define GET_INSTRMAP_INFO
26 #include "AMDGPUGenInstrInfo.inc"
30 AMDGPUInstrInfo::AMDGPUInstrInfo(TargetMachine &tm)
31 : AMDGPUGenInstrInfo(-1,-1), RI(tm), TM(tm) { }
33 const AMDGPURegisterInfo &AMDGPUInstrInfo::getRegisterInfo() const {
37 bool AMDGPUInstrInfo::isCoalescableExtInstr(const MachineInstr &MI,
38 unsigned &SrcReg, unsigned &DstReg,
39 unsigned &SubIdx) const {
40 // TODO: Implement this function
44 unsigned AMDGPUInstrInfo::isLoadFromStackSlot(const MachineInstr *MI,
45 int &FrameIndex) const {
46 // TODO: Implement this function
50 unsigned AMDGPUInstrInfo::isLoadFromStackSlotPostFE(const MachineInstr *MI,
51 int &FrameIndex) const {
52 // TODO: Implement this function
56 bool AMDGPUInstrInfo::hasLoadFromStackSlot(const MachineInstr *MI,
57 const MachineMemOperand *&MMO,
58 int &FrameIndex) const {
59 // TODO: Implement this function
62 unsigned AMDGPUInstrInfo::isStoreFromStackSlot(const MachineInstr *MI,
63 int &FrameIndex) const {
64 // TODO: Implement this function
67 unsigned AMDGPUInstrInfo::isStoreFromStackSlotPostFE(const MachineInstr *MI,
68 int &FrameIndex) const {
69 // TODO: Implement this function
72 bool AMDGPUInstrInfo::hasStoreFromStackSlot(const MachineInstr *MI,
73 const MachineMemOperand *&MMO,
74 int &FrameIndex) const {
75 // TODO: Implement this function
80 AMDGPUInstrInfo::convertToThreeAddress(MachineFunction::iterator &MFI,
81 MachineBasicBlock::iterator &MBBI,
82 LiveVariables *LV) const {
83 // TODO: Implement this function
86 bool AMDGPUInstrInfo::getNextBranchInstr(MachineBasicBlock::iterator &iter,
87 MachineBasicBlock &MBB) const {
88 while (iter != MBB.end()) {
89 switch (iter->getOpcode()) {
92 case AMDGPU::BRANCH_COND_i32:
93 case AMDGPU::BRANCH_COND_f32:
103 AMDGPUInstrInfo::storeRegToStackSlot(MachineBasicBlock &MBB,
104 MachineBasicBlock::iterator MI,
105 unsigned SrcReg, bool isKill,
107 const TargetRegisterClass *RC,
108 const TargetRegisterInfo *TRI) const {
109 assert(!"Not Implemented");
113 AMDGPUInstrInfo::loadRegFromStackSlot(MachineBasicBlock &MBB,
114 MachineBasicBlock::iterator MI,
115 unsigned DestReg, int FrameIndex,
116 const TargetRegisterClass *RC,
117 const TargetRegisterInfo *TRI) const {
118 assert(!"Not Implemented");
121 bool AMDGPUInstrInfo::expandPostRAPseudo (MachineBasicBlock::iterator MI) const {
122 MachineBasicBlock *MBB = MI->getParent();
124 if (isRegisterLoad(*MI)) {
125 unsigned RegIndex = MI->getOperand(2).getImm();
126 unsigned Channel = MI->getOperand(3).getImm();
127 unsigned Address = calculateIndirectAddress(RegIndex, Channel);
128 unsigned OffsetReg = MI->getOperand(1).getReg();
129 if (OffsetReg == AMDGPU::INDIRECT_BASE_ADDR) {
130 buildMovInstr(MBB, MI, MI->getOperand(0).getReg(),
131 getIndirectAddrRegClass()->getRegister(Address));
133 buildIndirectRead(MBB, MI, MI->getOperand(0).getReg(),
136 } else if (isRegisterStore(*MI)) {
137 unsigned RegIndex = MI->getOperand(2).getImm();
138 unsigned Channel = MI->getOperand(3).getImm();
139 unsigned Address = calculateIndirectAddress(RegIndex, Channel);
140 unsigned OffsetReg = MI->getOperand(1).getReg();
141 if (OffsetReg == AMDGPU::INDIRECT_BASE_ADDR) {
142 buildMovInstr(MBB, MI, getIndirectAddrRegClass()->getRegister(Address),
143 MI->getOperand(0).getReg());
145 buildIndirectWrite(MBB, MI, MI->getOperand(0).getReg(),
146 calculateIndirectAddress(RegIndex, Channel),
159 AMDGPUInstrInfo::foldMemoryOperandImpl(MachineFunction &MF,
161 const SmallVectorImpl<unsigned> &Ops,
162 int FrameIndex) const {
163 // TODO: Implement this function
167 AMDGPUInstrInfo::foldMemoryOperandImpl(MachineFunction &MF,
169 const SmallVectorImpl<unsigned> &Ops,
170 MachineInstr *LoadMI) const {
171 // TODO: Implement this function
175 AMDGPUInstrInfo::canFoldMemoryOperand(const MachineInstr *MI,
176 const SmallVectorImpl<unsigned> &Ops) const {
177 // TODO: Implement this function
181 AMDGPUInstrInfo::unfoldMemoryOperand(MachineFunction &MF, MachineInstr *MI,
182 unsigned Reg, bool UnfoldLoad,
184 SmallVectorImpl<MachineInstr*> &NewMIs) const {
185 // TODO: Implement this function
190 AMDGPUInstrInfo::unfoldMemoryOperand(SelectionDAG &DAG, SDNode *N,
191 SmallVectorImpl<SDNode*> &NewNodes) const {
192 // TODO: Implement this function
197 AMDGPUInstrInfo::getOpcodeAfterMemoryUnfold(unsigned Opc,
198 bool UnfoldLoad, bool UnfoldStore,
199 unsigned *LoadRegIndex) const {
200 // TODO: Implement this function
204 bool AMDGPUInstrInfo::shouldScheduleLoadsNear(SDNode *Load1, SDNode *Load2,
205 int64_t Offset1, int64_t Offset2,
206 unsigned NumLoads) const {
207 assert(Offset2 > Offset1
208 && "Second offset should be larger than first offset!");
209 // If we have less than 16 loads in a row, and the offsets are within 16,
210 // then schedule together.
211 // TODO: Make the loads schedule near if it fits in a cacheline
212 return (NumLoads < 16 && (Offset2 - Offset1) < 16);
216 AMDGPUInstrInfo::ReverseBranchCondition(SmallVectorImpl<MachineOperand> &Cond)
218 // TODO: Implement this function
221 void AMDGPUInstrInfo::insertNoop(MachineBasicBlock &MBB,
222 MachineBasicBlock::iterator MI) const {
223 // TODO: Implement this function
226 bool AMDGPUInstrInfo::isPredicated(const MachineInstr *MI) const {
227 // TODO: Implement this function
231 AMDGPUInstrInfo::SubsumesPredicate(const SmallVectorImpl<MachineOperand> &Pred1,
232 const SmallVectorImpl<MachineOperand> &Pred2)
234 // TODO: Implement this function
238 bool AMDGPUInstrInfo::DefinesPredicate(MachineInstr *MI,
239 std::vector<MachineOperand> &Pred) const {
240 // TODO: Implement this function
244 bool AMDGPUInstrInfo::isPredicable(MachineInstr *MI) const {
245 // TODO: Implement this function
246 return MI->getDesc().isPredicable();
250 AMDGPUInstrInfo::isSafeToMoveRegClassDefs(const TargetRegisterClass *RC) const {
251 // TODO: Implement this function
255 bool AMDGPUInstrInfo::isRegisterStore(const MachineInstr &MI) const {
256 return get(MI.getOpcode()).TSFlags & AMDGPU_FLAG_REGISTER_STORE;
259 bool AMDGPUInstrInfo::isRegisterLoad(const MachineInstr &MI) const {
260 return get(MI.getOpcode()).TSFlags & AMDGPU_FLAG_REGISTER_LOAD;
264 void AMDGPUInstrInfo::convertToISA(MachineInstr & MI, MachineFunction &MF,
266 MachineRegisterInfo &MRI = MF.getRegInfo();
267 const AMDGPURegisterInfo & RI = getRegisterInfo();
269 for (unsigned i = 0; i < MI.getNumOperands(); i++) {
270 MachineOperand &MO = MI.getOperand(i);
271 // Convert dst regclass to one that is supported by the ISA
272 if (MO.isReg() && MO.isDef()) {
273 if (TargetRegisterInfo::isVirtualRegister(MO.getReg())) {
274 const TargetRegisterClass * oldRegClass = MRI.getRegClass(MO.getReg());
275 const TargetRegisterClass * newRegClass = RI.getISARegClass(oldRegClass);
279 MRI.setRegClass(MO.getReg(), newRegClass);
285 int AMDGPUInstrInfo::getMaskedMIMGOp(uint16_t Opcode, unsigned Channels) const {
287 default: return Opcode;
288 case 1: return AMDGPU::getMaskedMIMGOp(Opcode, AMDGPU::Channels_1);
289 case 2: return AMDGPU::getMaskedMIMGOp(Opcode, AMDGPU::Channels_2);
290 case 3: return AMDGPU::getMaskedMIMGOp(Opcode, AMDGPU::Channels_3);