blob: 592dcbf4ffc4dd71a5ca36e5db22c32a93d6b6bf [file] [log] [blame]
Tom Stellard75aadc22012-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 Stellard75aadc22012-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 Stellard02661d92013-06-25 21:22:18 +000024#define GET_INSTRINFO_NAMED_OPS
Christian Konigf741fbf2013-02-26 17:52:42 +000025#define GET_INSTRMAP_INFO
Tom Stellard75aadc22012-12-11 21:25:42 +000026#include "AMDGPUGenInstrInfo.inc"
27
28using namespace llvm;
29
30AMDGPUInstrInfo::AMDGPUInstrInfo(TargetMachine &tm)
Vincent Lejeune269708b2013-10-01 19:32:38 +000031 : AMDGPUGenInstrInfo(-1,-1), RI(tm), TM(tm) { }
Tom Stellard75aadc22012-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 Stellard75aadc22012-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 Stellard26a3b672013-10-22 18:19:10 +0000121bool AMDGPUInstrInfo::expandPostRAPseudo (MachineBasicBlock::iterator MI) const {
122 MachineBasicBlock *MBB = MI->getParent();
123
Aaron Ballman9ab670f2013-10-29 20:40:52 +0000124 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));
Tom Stellard26a3b672013-10-22 18:19:10 +0000132 } else {
Aaron Ballman9ab670f2013-10-29 20:40:52 +0000133 buildIndirectRead(MBB, MI, MI->getOperand(0).getReg(),
134 Address, OffsetReg);
Tom Stellard26a3b672013-10-22 18:19:10 +0000135 }
Aaron Ballman9ab670f2013-10-29 20:40:52 +0000136 } 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());
144 } else {
145 buildIndirectWrite(MBB, MI, MI->getOperand(0).getReg(),
146 calculateIndirectAddress(RegIndex, Channel),
147 OffsetReg);
148 }
149 } else {
150 return false;
Tom Stellard26a3b672013-10-22 18:19:10 +0000151 }
152
153 MBB->erase(MI);
154 return true;
155}
156
157
Tom Stellard75aadc22012-12-11 21:25:42 +0000158MachineInstr *
159AMDGPUInstrInfo::foldMemoryOperandImpl(MachineFunction &MF,
160 MachineInstr *MI,
161 const SmallVectorImpl<unsigned> &Ops,
162 int FrameIndex) const {
163// TODO: Implement this function
164 return 0;
165}
166MachineInstr*
167AMDGPUInstrInfo::foldMemoryOperandImpl(MachineFunction &MF,
168 MachineInstr *MI,
169 const SmallVectorImpl<unsigned> &Ops,
170 MachineInstr *LoadMI) const {
171 // TODO: Implement this function
172 return 0;
173}
174bool
175AMDGPUInstrInfo::canFoldMemoryOperand(const MachineInstr *MI,
176 const SmallVectorImpl<unsigned> &Ops) const {
177 // TODO: Implement this function
178 return false;
179}
180bool
181AMDGPUInstrInfo::unfoldMemoryOperand(MachineFunction &MF, MachineInstr *MI,
182 unsigned Reg, bool UnfoldLoad,
183 bool UnfoldStore,
184 SmallVectorImpl<MachineInstr*> &NewMIs) const {
185 // TODO: Implement this function
186 return false;
187}
188
189bool
190AMDGPUInstrInfo::unfoldMemoryOperand(SelectionDAG &DAG, SDNode *N,
191 SmallVectorImpl<SDNode*> &NewNodes) const {
192 // TODO: Implement this function
193 return false;
194}
195
196unsigned
197AMDGPUInstrInfo::getOpcodeAfterMemoryUnfold(unsigned Opc,
198 bool UnfoldLoad, bool UnfoldStore,
199 unsigned *LoadRegIndex) const {
200 // TODO: Implement this function
201 return 0;
202}
203
204bool 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);
213}
214
215bool
216AMDGPUInstrInfo::ReverseBranchCondition(SmallVectorImpl<MachineOperand> &Cond)
217 const {
218 // TODO: Implement this function
219 return true;
220}
221void AMDGPUInstrInfo::insertNoop(MachineBasicBlock &MBB,
222 MachineBasicBlock::iterator MI) const {
223 // TODO: Implement this function
224}
225
226bool AMDGPUInstrInfo::isPredicated(const MachineInstr *MI) const {
227 // TODO: Implement this function
228 return false;
229}
230bool
231AMDGPUInstrInfo::SubsumesPredicate(const SmallVectorImpl<MachineOperand> &Pred1,
232 const SmallVectorImpl<MachineOperand> &Pred2)
233 const {
234 // TODO: Implement this function
235 return false;
236}
237
238bool AMDGPUInstrInfo::DefinesPredicate(MachineInstr *MI,
239 std::vector<MachineOperand> &Pred) const {
240 // TODO: Implement this function
241 return false;
242}
243
244bool AMDGPUInstrInfo::isPredicable(MachineInstr *MI) const {
245 // TODO: Implement this function
246 return MI->getDesc().isPredicable();
247}
248
249bool
250AMDGPUInstrInfo::isSafeToMoveRegClassDefs(const TargetRegisterClass *RC) const {
251 // TODO: Implement this function
252 return true;
253}
Tom Stellardf3b2a1e2013-02-06 17:32:29 +0000254
255bool AMDGPUInstrInfo::isRegisterStore(const MachineInstr &MI) const {
256 return get(MI.getOpcode()).TSFlags & AMDGPU_FLAG_REGISTER_STORE;
257}
258
259bool AMDGPUInstrInfo::isRegisterLoad(const MachineInstr &MI) const {
260 return get(MI.getOpcode()).TSFlags & AMDGPU_FLAG_REGISTER_LOAD;
261}
262
263
Tom Stellard75aadc22012-12-11 21:25:42 +0000264void AMDGPUInstrInfo::convertToISA(MachineInstr & MI, MachineFunction &MF,
265 DebugLoc DL) const {
266 MachineRegisterInfo &MRI = MF.getRegInfo();
267 const AMDGPURegisterInfo & RI = getRegisterInfo();
268
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);
276
277 assert(newRegClass);
278
279 MRI.setRegClass(MO.getReg(), newRegClass);
280 }
281 }
282 }
283}
Tom Stellard682bfbc2013-10-10 17:11:24 +0000284
285int AMDGPUInstrInfo::getMaskedMIMGOp(uint16_t Opcode, unsigned Channels) const {
286 switch (Channels) {
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);
291 }
292}