blob: 434c91a523156082bd4600d36ca75f8b0a031d57 [file] [log] [blame]
Tom Stellardf98f2ce2012-12-11 21:25:42 +00001//===-- AMDGPUInstrInfo.cpp - Base class for AMD GPU InstrInfo ------------===//
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 Implementation of the TargetInstrInfo class that is common to all
12/// AMD GPUs.
13//
14//===----------------------------------------------------------------------===//
15
16#include "AMDGPUInstrInfo.h"
17#include "AMDGPURegisterInfo.h"
18#include "AMDGPUTargetMachine.h"
Tom Stellardf98f2ce2012-12-11 21:25:42 +000019#include "llvm/CodeGen/MachineFrameInfo.h"
20#include "llvm/CodeGen/MachineInstrBuilder.h"
21#include "llvm/CodeGen/MachineRegisterInfo.h"
22
23#define GET_INSTRINFO_CTOR
Tom Stellard5e48a0e2013-06-25 21:22:18 +000024#define GET_INSTRINFO_NAMED_OPS
Christian Konigf7670182013-02-26 17:52:42 +000025#define GET_INSTRMAP_INFO
Tom Stellardf98f2ce2012-12-11 21:25:42 +000026#include "AMDGPUGenInstrInfo.inc"
27
28using namespace llvm;
29
30AMDGPUInstrInfo::AMDGPUInstrInfo(TargetMachine &tm)
Vincent Lejeune5b00e832013-10-01 19:32:38 +000031 : AMDGPUGenInstrInfo(-1,-1), RI(tm), TM(tm) { }
Tom Stellardf98f2ce2012-12-11 21:25:42 +000032
33const AMDGPURegisterInfo &AMDGPUInstrInfo::getRegisterInfo() const {
34 return RI;
35}
36
37bool AMDGPUInstrInfo::isCoalescableExtInstr(const MachineInstr &MI,
38 unsigned &SrcReg, unsigned &DstReg,
39 unsigned &SubIdx) const {
40// TODO: Implement this function
41 return false;
42}
43
44unsigned AMDGPUInstrInfo::isLoadFromStackSlot(const MachineInstr *MI,
45 int &FrameIndex) const {
46// TODO: Implement this function
47 return 0;
48}
49
50unsigned AMDGPUInstrInfo::isLoadFromStackSlotPostFE(const MachineInstr *MI,
51 int &FrameIndex) const {
52// TODO: Implement this function
53 return 0;
54}
55
56bool AMDGPUInstrInfo::hasLoadFromStackSlot(const MachineInstr *MI,
57 const MachineMemOperand *&MMO,
58 int &FrameIndex) const {
59// TODO: Implement this function
60 return false;
61}
62unsigned AMDGPUInstrInfo::isStoreFromStackSlot(const MachineInstr *MI,
63 int &FrameIndex) const {
64// TODO: Implement this function
65 return 0;
66}
67unsigned AMDGPUInstrInfo::isStoreFromStackSlotPostFE(const MachineInstr *MI,
68 int &FrameIndex) const {
69// TODO: Implement this function
70 return 0;
71}
72bool AMDGPUInstrInfo::hasStoreFromStackSlot(const MachineInstr *MI,
73 const MachineMemOperand *&MMO,
74 int &FrameIndex) const {
75// TODO: Implement this function
76 return false;
77}
78
79MachineInstr *
80AMDGPUInstrInfo::convertToThreeAddress(MachineFunction::iterator &MFI,
81 MachineBasicBlock::iterator &MBBI,
82 LiveVariables *LV) const {
83// TODO: Implement this function
84 return NULL;
85}
86bool AMDGPUInstrInfo::getNextBranchInstr(MachineBasicBlock::iterator &iter,
87 MachineBasicBlock &MBB) const {
88 while (iter != MBB.end()) {
89 switch (iter->getOpcode()) {
90 default:
91 break;
92 case AMDGPU::BRANCH_COND_i32:
93 case AMDGPU::BRANCH_COND_f32:
94 case AMDGPU::BRANCH:
95 return true;
96 };
97 ++iter;
98 }
99 return false;
100}
101
Tom Stellardf98f2ce2012-12-11 21:25:42 +0000102void
103AMDGPUInstrInfo::storeRegToStackSlot(MachineBasicBlock &MBB,
104 MachineBasicBlock::iterator MI,
105 unsigned SrcReg, bool isKill,
106 int FrameIndex,
107 const TargetRegisterClass *RC,
108 const TargetRegisterInfo *TRI) const {
109 assert(!"Not Implemented");
110}
111
112void
113AMDGPUInstrInfo::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");
119}
120
Tom Stellard04c55952013-10-22 18:19:10 +0000121bool AMDGPUInstrInfo::expandPostRAPseudo (MachineBasicBlock::iterator MI) const {
122 MachineBasicBlock *MBB = MI->getParent();
123
124 switch(MI->getOpcode()) {
125 default:
126 if (isRegisterLoad(*MI)) {
127 unsigned RegIndex = MI->getOperand(2).getImm();
128 unsigned Channel = MI->getOperand(3).getImm();
129 unsigned Address = calculateIndirectAddress(RegIndex, Channel);
130 unsigned OffsetReg = MI->getOperand(1).getReg();
131 if (OffsetReg == AMDGPU::INDIRECT_BASE_ADDR) {
132 buildMovInstr(MBB, MI, MI->getOperand(0).getReg(),
133 getIndirectAddrRegClass()->getRegister(Address));
134 } else {
135 buildIndirectRead(MBB, MI, MI->getOperand(0).getReg(),
136 Address, OffsetReg);
137 }
138 } else if (isRegisterStore(*MI)) {
139 unsigned RegIndex = MI->getOperand(2).getImm();
140 unsigned Channel = MI->getOperand(3).getImm();
141 unsigned Address = calculateIndirectAddress(RegIndex, Channel);
142 unsigned OffsetReg = MI->getOperand(1).getReg();
143 if (OffsetReg == AMDGPU::INDIRECT_BASE_ADDR) {
144 buildMovInstr(MBB, MI, getIndirectAddrRegClass()->getRegister(Address),
145 MI->getOperand(0).getReg());
146 } else {
147 buildIndirectWrite(MBB, MI, MI->getOperand(0).getReg(),
148 calculateIndirectAddress(RegIndex, Channel),
149 OffsetReg);
150 }
151 } else {
152 return false;
153 }
154 }
155
156 MBB->erase(MI);
157 return true;
158}
159
160
Tom Stellardf98f2ce2012-12-11 21:25:42 +0000161MachineInstr *
162AMDGPUInstrInfo::foldMemoryOperandImpl(MachineFunction &MF,
163 MachineInstr *MI,
164 const SmallVectorImpl<unsigned> &Ops,
165 int FrameIndex) const {
166// TODO: Implement this function
167 return 0;
168}
169MachineInstr*
170AMDGPUInstrInfo::foldMemoryOperandImpl(MachineFunction &MF,
171 MachineInstr *MI,
172 const SmallVectorImpl<unsigned> &Ops,
173 MachineInstr *LoadMI) const {
174 // TODO: Implement this function
175 return 0;
176}
177bool
178AMDGPUInstrInfo::canFoldMemoryOperand(const MachineInstr *MI,
179 const SmallVectorImpl<unsigned> &Ops) const {
180 // TODO: Implement this function
181 return false;
182}
183bool
184AMDGPUInstrInfo::unfoldMemoryOperand(MachineFunction &MF, MachineInstr *MI,
185 unsigned Reg, bool UnfoldLoad,
186 bool UnfoldStore,
187 SmallVectorImpl<MachineInstr*> &NewMIs) const {
188 // TODO: Implement this function
189 return false;
190}
191
192bool
193AMDGPUInstrInfo::unfoldMemoryOperand(SelectionDAG &DAG, SDNode *N,
194 SmallVectorImpl<SDNode*> &NewNodes) const {
195 // TODO: Implement this function
196 return false;
197}
198
199unsigned
200AMDGPUInstrInfo::getOpcodeAfterMemoryUnfold(unsigned Opc,
201 bool UnfoldLoad, bool UnfoldStore,
202 unsigned *LoadRegIndex) const {
203 // TODO: Implement this function
204 return 0;
205}
206
207bool AMDGPUInstrInfo::shouldScheduleLoadsNear(SDNode *Load1, SDNode *Load2,
208 int64_t Offset1, int64_t Offset2,
209 unsigned NumLoads) const {
210 assert(Offset2 > Offset1
211 && "Second offset should be larger than first offset!");
212 // If we have less than 16 loads in a row, and the offsets are within 16,
213 // then schedule together.
214 // TODO: Make the loads schedule near if it fits in a cacheline
215 return (NumLoads < 16 && (Offset2 - Offset1) < 16);
216}
217
218bool
219AMDGPUInstrInfo::ReverseBranchCondition(SmallVectorImpl<MachineOperand> &Cond)
220 const {
221 // TODO: Implement this function
222 return true;
223}
224void AMDGPUInstrInfo::insertNoop(MachineBasicBlock &MBB,
225 MachineBasicBlock::iterator MI) const {
226 // TODO: Implement this function
227}
228
229bool AMDGPUInstrInfo::isPredicated(const MachineInstr *MI) const {
230 // TODO: Implement this function
231 return false;
232}
233bool
234AMDGPUInstrInfo::SubsumesPredicate(const SmallVectorImpl<MachineOperand> &Pred1,
235 const SmallVectorImpl<MachineOperand> &Pred2)
236 const {
237 // TODO: Implement this function
238 return false;
239}
240
241bool AMDGPUInstrInfo::DefinesPredicate(MachineInstr *MI,
242 std::vector<MachineOperand> &Pred) const {
243 // TODO: Implement this function
244 return false;
245}
246
247bool AMDGPUInstrInfo::isPredicable(MachineInstr *MI) const {
248 // TODO: Implement this function
249 return MI->getDesc().isPredicable();
250}
251
252bool
253AMDGPUInstrInfo::isSafeToMoveRegClassDefs(const TargetRegisterClass *RC) const {
254 // TODO: Implement this function
255 return true;
256}
Tom Stellardc0b0c672013-02-06 17:32:29 +0000257
258bool AMDGPUInstrInfo::isRegisterStore(const MachineInstr &MI) const {
259 return get(MI.getOpcode()).TSFlags & AMDGPU_FLAG_REGISTER_STORE;
260}
261
262bool AMDGPUInstrInfo::isRegisterLoad(const MachineInstr &MI) const {
263 return get(MI.getOpcode()).TSFlags & AMDGPU_FLAG_REGISTER_LOAD;
264}
265
266
Tom Stellardf98f2ce2012-12-11 21:25:42 +0000267void AMDGPUInstrInfo::convertToISA(MachineInstr & MI, MachineFunction &MF,
268 DebugLoc DL) const {
269 MachineRegisterInfo &MRI = MF.getRegInfo();
270 const AMDGPURegisterInfo & RI = getRegisterInfo();
271
272 for (unsigned i = 0; i < MI.getNumOperands(); i++) {
273 MachineOperand &MO = MI.getOperand(i);
274 // Convert dst regclass to one that is supported by the ISA
275 if (MO.isReg() && MO.isDef()) {
276 if (TargetRegisterInfo::isVirtualRegister(MO.getReg())) {
277 const TargetRegisterClass * oldRegClass = MRI.getRegClass(MO.getReg());
278 const TargetRegisterClass * newRegClass = RI.getISARegClass(oldRegClass);
279
280 assert(newRegClass);
281
282 MRI.setRegClass(MO.getReg(), newRegClass);
283 }
284 }
285 }
286}
Tom Stellard0f9eaaa2013-10-10 17:11:24 +0000287
288int AMDGPUInstrInfo::getMaskedMIMGOp(uint16_t Opcode, unsigned Channels) const {
289 switch (Channels) {
290 default: return Opcode;
291 case 1: return AMDGPU::getMaskedMIMGOp(Opcode, AMDGPU::Channels_1);
292 case 2: return AMDGPU::getMaskedMIMGOp(Opcode, AMDGPU::Channels_2);
293 case 3: return AMDGPU::getMaskedMIMGOp(Opcode, AMDGPU::Channels_3);
294 }
295}