blob: c90176b8f88d5ba6fbbb82645dcaf10efb585d3e [file] [log] [blame]
Tom Stellardf98f2ce2012-12-11 21:25:42 +00001//===-- AMDGPUISelLowering.cpp - AMDGPU Common DAG lowering functions -----===//
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 This is the parent TargetLowering class for hardware code gen
12/// targets.
13//
14//===----------------------------------------------------------------------===//
15
16#include "AMDGPUISelLowering.h"
Tom Stellarde7397ee2013-06-03 17:40:11 +000017#include "AMDGPU.h"
Christian Konig90c64cb2013-03-07 09:03:52 +000018#include "AMDGPURegisterInfo.h"
Christian Konig90c64cb2013-03-07 09:03:52 +000019#include "AMDGPUSubtarget.h"
Benjamin Kramer5c352902013-05-23 17:10:37 +000020#include "AMDILIntrinsicInfo.h"
Tom Stellardf502c292013-07-23 01:48:05 +000021#include "R600MachineFunctionInfo.h"
Tom Stellarde7397ee2013-06-03 17:40:11 +000022#include "SIMachineFunctionInfo.h"
Christian Konig90c64cb2013-03-07 09:03:52 +000023#include "llvm/CodeGen/CallingConvLower.h"
Tom Stellardf98f2ce2012-12-11 21:25:42 +000024#include "llvm/CodeGen/MachineFunction.h"
25#include "llvm/CodeGen/MachineRegisterInfo.h"
26#include "llvm/CodeGen/SelectionDAG.h"
27#include "llvm/CodeGen/TargetLoweringObjectFileImpl.h"
Tom Stellarde3d4cbc2013-06-28 15:47:08 +000028#include "llvm/IR/DataLayout.h"
Tom Stellardf98f2ce2012-12-11 21:25:42 +000029
30using namespace llvm;
31
Christian Konig90c64cb2013-03-07 09:03:52 +000032#include "AMDGPUGenCallingConv.inc"
33
Tom Stellardf98f2ce2012-12-11 21:25:42 +000034AMDGPUTargetLowering::AMDGPUTargetLowering(TargetMachine &TM) :
35 TargetLowering(TM, new TargetLoweringObjectFileELF()) {
36
37 // Initialize target lowering borrowed from AMDIL
38 InitAMDILLowering();
39
40 // We need to custom lower some of the intrinsics
41 setOperationAction(ISD::INTRINSIC_WO_CHAIN, MVT::Other, Custom);
42
43 // Library functions. These default to Expand, but we have instructions
44 // for them.
45 setOperationAction(ISD::FCEIL, MVT::f32, Legal);
46 setOperationAction(ISD::FEXP2, MVT::f32, Legal);
47 setOperationAction(ISD::FPOW, MVT::f32, Legal);
48 setOperationAction(ISD::FLOG2, MVT::f32, Legal);
49 setOperationAction(ISD::FABS, MVT::f32, Legal);
50 setOperationAction(ISD::FFLOOR, MVT::f32, Legal);
51 setOperationAction(ISD::FRINT, MVT::f32, Legal);
52
Tom Stellardba534c22013-05-20 15:02:19 +000053 // The hardware supports ROTR, but not ROTL
54 setOperationAction(ISD::ROTL, MVT::i32, Expand);
55
Tom Stellardf98f2ce2012-12-11 21:25:42 +000056 // Lower floating point store/load to integer store/load to reduce the number
57 // of patterns in tablegen.
58 setOperationAction(ISD::STORE, MVT::f32, Promote);
59 AddPromotedToType(ISD::STORE, MVT::f32, MVT::i32);
60
Tom Stellardfc047272013-07-18 21:43:42 +000061 setOperationAction(ISD::STORE, MVT::v2f32, Promote);
62 AddPromotedToType(ISD::STORE, MVT::v2f32, MVT::v2i32);
63
Tom Stellardf98f2ce2012-12-11 21:25:42 +000064 setOperationAction(ISD::STORE, MVT::v4f32, Promote);
65 AddPromotedToType(ISD::STORE, MVT::v4f32, MVT::v4i32);
66
Tom Stellard68e13282013-07-12 18:14:56 +000067 setOperationAction(ISD::STORE, MVT::f64, Promote);
68 AddPromotedToType(ISD::STORE, MVT::f64, MVT::i64);
69
Tom Stellardf98f2ce2012-12-11 21:25:42 +000070 setOperationAction(ISD::LOAD, MVT::f32, Promote);
71 AddPromotedToType(ISD::LOAD, MVT::f32, MVT::i32);
72
Tom Stellardac85f3f2013-07-18 21:43:48 +000073 setOperationAction(ISD::LOAD, MVT::v2f32, Promote);
74 AddPromotedToType(ISD::LOAD, MVT::v2f32, MVT::v2i32);
75
Tom Stellardf98f2ce2012-12-11 21:25:42 +000076 setOperationAction(ISD::LOAD, MVT::v4f32, Promote);
77 AddPromotedToType(ISD::LOAD, MVT::v4f32, MVT::v4i32);
78
Tom Stellard68e13282013-07-12 18:14:56 +000079 setOperationAction(ISD::LOAD, MVT::f64, Promote);
80 AddPromotedToType(ISD::LOAD, MVT::f64, MVT::i64);
81
Tom Stellardd7a472c2013-07-23 01:47:46 +000082 setOperationAction(ISD::FNEG, MVT::v2f32, Expand);
83 setOperationAction(ISD::FNEG, MVT::v4f32, Expand);
84
Christian Konig45b14e32013-03-27 09:12:51 +000085 setOperationAction(ISD::MUL, MVT::i64, Expand);
86
Tom Stellardf98f2ce2012-12-11 21:25:42 +000087 setOperationAction(ISD::UDIV, MVT::i32, Expand);
88 setOperationAction(ISD::UDIVREM, MVT::i32, Custom);
89 setOperationAction(ISD::UREM, MVT::i32, Expand);
Tom Stellardf5660aa2013-07-18 21:43:35 +000090 setOperationAction(ISD::VSELECT, MVT::v2f32, Expand);
91 setOperationAction(ISD::VSELECT, MVT::v4f32, Expand);
Aaron Watryf97c7fe2013-06-25 13:55:57 +000092
Craig Topper787e71d2013-07-15 06:39:13 +000093 static const int types[] = {
Aaron Watryf97c7fe2013-06-25 13:55:57 +000094 (int)MVT::v2i32,
95 (int)MVT::v4i32
96 };
Craig Topperb9df53a2013-07-15 04:27:47 +000097 const size_t NumTypes = array_lengthof(types);
Aaron Watryf97c7fe2013-06-25 13:55:57 +000098
99 for (unsigned int x = 0; x < NumTypes; ++x) {
100 MVT::SimpleValueType VT = (MVT::SimpleValueType)types[x];
101 //Expand the following operations for the current type by default
102 setOperationAction(ISD::ADD, VT, Expand);
103 setOperationAction(ISD::AND, VT, Expand);
104 setOperationAction(ISD::MUL, VT, Expand);
105 setOperationAction(ISD::OR, VT, Expand);
106 setOperationAction(ISD::SHL, VT, Expand);
107 setOperationAction(ISD::SRL, VT, Expand);
108 setOperationAction(ISD::SRA, VT, Expand);
109 setOperationAction(ISD::SUB, VT, Expand);
110 setOperationAction(ISD::UDIV, VT, Expand);
111 setOperationAction(ISD::UREM, VT, Expand);
Tom Stellardf5660aa2013-07-18 21:43:35 +0000112 setOperationAction(ISD::VSELECT, VT, Expand);
Aaron Watryf97c7fe2013-06-25 13:55:57 +0000113 setOperationAction(ISD::XOR, VT, Expand);
114 }
Tom Stellardf98f2ce2012-12-11 21:25:42 +0000115}
116
117//===---------------------------------------------------------------------===//
118// TargetLowering Callbacks
119//===---------------------------------------------------------------------===//
120
Christian Konig90c64cb2013-03-07 09:03:52 +0000121void AMDGPUTargetLowering::AnalyzeFormalArguments(CCState &State,
122 const SmallVectorImpl<ISD::InputArg> &Ins) const {
123
124 State.AnalyzeFormalArguments(Ins, CC_AMDGPU);
Tom Stellardf98f2ce2012-12-11 21:25:42 +0000125}
126
127SDValue AMDGPUTargetLowering::LowerReturn(
128 SDValue Chain,
129 CallingConv::ID CallConv,
130 bool isVarArg,
131 const SmallVectorImpl<ISD::OutputArg> &Outs,
132 const SmallVectorImpl<SDValue> &OutVals,
Andrew Trickac6d9be2013-05-25 02:42:55 +0000133 SDLoc DL, SelectionDAG &DAG) const {
Tom Stellardf98f2ce2012-12-11 21:25:42 +0000134 return DAG.getNode(AMDGPUISD::RET_FLAG, DL, MVT::Other, Chain);
135}
136
137//===---------------------------------------------------------------------===//
138// Target specific lowering
139//===---------------------------------------------------------------------===//
140
141SDValue AMDGPUTargetLowering::LowerOperation(SDValue Op, SelectionDAG &DAG)
142 const {
143 switch (Op.getOpcode()) {
144 default:
145 Op.getNode()->dump();
146 assert(0 && "Custom lowering code for this"
147 "instruction is not implemented yet!");
148 break;
149 // AMDIL DAG lowering
150 case ISD::SDIV: return LowerSDIV(Op, DAG);
151 case ISD::SREM: return LowerSREM(Op, DAG);
152 case ISD::SIGN_EXTEND_INREG: return LowerSIGN_EXTEND_INREG(Op, DAG);
153 case ISD::BRCOND: return LowerBRCOND(Op, DAG);
154 // AMDGPU DAG lowering
155 case ISD::INTRINSIC_WO_CHAIN: return LowerINTRINSIC_WO_CHAIN(Op, DAG);
156 case ISD::UDIVREM: return LowerUDIVREM(Op, DAG);
157 }
158 return Op;
159}
160
Tom Stellarde3d4cbc2013-06-28 15:47:08 +0000161SDValue AMDGPUTargetLowering::LowerGlobalAddress(AMDGPUMachineFunction* MFI,
162 SDValue Op,
163 SelectionDAG &DAG) const {
164
165 const DataLayout *TD = getTargetMachine().getDataLayout();
166 GlobalAddressSDNode *G = cast<GlobalAddressSDNode>(Op);
167 // XXX: What does the value of G->getOffset() mean?
168 assert(G->getOffset() == 0 &&
169 "Do not know what to do with an non-zero offset");
170
171 unsigned Offset = MFI->LDSSize;
172 const GlobalValue *GV = G->getGlobal();
173 uint64_t Size = TD->getTypeAllocSize(GV->getType()->getElementType());
174
175 // XXX: Account for alignment?
176 MFI->LDSSize += Size;
177
Michel Danzera3e39dc2013-07-10 16:37:07 +0000178 return DAG.getConstant(Offset, TD->getPointerSize() == 8 ? MVT::i64 : MVT::i32);
Tom Stellarde3d4cbc2013-06-28 15:47:08 +0000179}
180
Tom Stellardf98f2ce2012-12-11 21:25:42 +0000181SDValue AMDGPUTargetLowering::LowerINTRINSIC_WO_CHAIN(SDValue Op,
182 SelectionDAG &DAG) const {
183 unsigned IntrinsicID = cast<ConstantSDNode>(Op.getOperand(0))->getZExtValue();
Andrew Trickac6d9be2013-05-25 02:42:55 +0000184 SDLoc DL(Op);
Tom Stellardf98f2ce2012-12-11 21:25:42 +0000185 EVT VT = Op.getValueType();
186
187 switch (IntrinsicID) {
188 default: return Op;
189 case AMDGPUIntrinsic::AMDIL_abs:
190 return LowerIntrinsicIABS(Op, DAG);
191 case AMDGPUIntrinsic::AMDIL_exp:
192 return DAG.getNode(ISD::FEXP2, DL, VT, Op.getOperand(1));
193 case AMDGPUIntrinsic::AMDGPU_lrp:
194 return LowerIntrinsicLRP(Op, DAG);
195 case AMDGPUIntrinsic::AMDIL_fraction:
196 return DAG.getNode(AMDGPUISD::FRACT, DL, VT, Op.getOperand(1));
Tom Stellardf98f2ce2012-12-11 21:25:42 +0000197 case AMDGPUIntrinsic::AMDIL_max:
198 return DAG.getNode(AMDGPUISD::FMAX, DL, VT, Op.getOperand(1),
199 Op.getOperand(2));
200 case AMDGPUIntrinsic::AMDGPU_imax:
201 return DAG.getNode(AMDGPUISD::SMAX, DL, VT, Op.getOperand(1),
202 Op.getOperand(2));
203 case AMDGPUIntrinsic::AMDGPU_umax:
204 return DAG.getNode(AMDGPUISD::UMAX, DL, VT, Op.getOperand(1),
205 Op.getOperand(2));
206 case AMDGPUIntrinsic::AMDIL_min:
207 return DAG.getNode(AMDGPUISD::FMIN, DL, VT, Op.getOperand(1),
208 Op.getOperand(2));
209 case AMDGPUIntrinsic::AMDGPU_imin:
210 return DAG.getNode(AMDGPUISD::SMIN, DL, VT, Op.getOperand(1),
211 Op.getOperand(2));
212 case AMDGPUIntrinsic::AMDGPU_umin:
213 return DAG.getNode(AMDGPUISD::UMIN, DL, VT, Op.getOperand(1),
214 Op.getOperand(2));
215 case AMDGPUIntrinsic::AMDIL_round_nearest:
216 return DAG.getNode(ISD::FRINT, DL, VT, Op.getOperand(1));
217 }
218}
219
220///IABS(a) = SMAX(sub(0, a), a)
221SDValue AMDGPUTargetLowering::LowerIntrinsicIABS(SDValue Op,
222 SelectionDAG &DAG) const {
223
Andrew Trickac6d9be2013-05-25 02:42:55 +0000224 SDLoc DL(Op);
Tom Stellardf98f2ce2012-12-11 21:25:42 +0000225 EVT VT = Op.getValueType();
226 SDValue Neg = DAG.getNode(ISD::SUB, DL, VT, DAG.getConstant(0, VT),
227 Op.getOperand(1));
228
229 return DAG.getNode(AMDGPUISD::SMAX, DL, VT, Neg, Op.getOperand(1));
230}
231
232/// Linear Interpolation
233/// LRP(a, b, c) = muladd(a, b, (1 - a) * c)
234SDValue AMDGPUTargetLowering::LowerIntrinsicLRP(SDValue Op,
235 SelectionDAG &DAG) const {
Andrew Trickac6d9be2013-05-25 02:42:55 +0000236 SDLoc DL(Op);
Tom Stellardf98f2ce2012-12-11 21:25:42 +0000237 EVT VT = Op.getValueType();
238 SDValue OneSubA = DAG.getNode(ISD::FSUB, DL, VT,
239 DAG.getConstantFP(1.0f, MVT::f32),
240 Op.getOperand(1));
241 SDValue OneSubAC = DAG.getNode(ISD::FMUL, DL, VT, OneSubA,
242 Op.getOperand(3));
Vincent Lejeunee3111962013-02-18 14:11:28 +0000243 return DAG.getNode(ISD::FADD, DL, VT,
244 DAG.getNode(ISD::FMUL, DL, VT, Op.getOperand(1), Op.getOperand(2)),
245 OneSubAC);
Tom Stellardf98f2ce2012-12-11 21:25:42 +0000246}
247
248/// \brief Generate Min/Max node
249SDValue AMDGPUTargetLowering::LowerMinMax(SDValue Op,
250 SelectionDAG &DAG) const {
Andrew Trickac6d9be2013-05-25 02:42:55 +0000251 SDLoc DL(Op);
Tom Stellardf98f2ce2012-12-11 21:25:42 +0000252 EVT VT = Op.getValueType();
253
254 SDValue LHS = Op.getOperand(0);
255 SDValue RHS = Op.getOperand(1);
256 SDValue True = Op.getOperand(2);
257 SDValue False = Op.getOperand(3);
258 SDValue CC = Op.getOperand(4);
259
260 if (VT != MVT::f32 ||
261 !((LHS == True && RHS == False) || (LHS == False && RHS == True))) {
262 return SDValue();
263 }
264
265 ISD::CondCode CCOpcode = cast<CondCodeSDNode>(CC)->get();
266 switch (CCOpcode) {
267 case ISD::SETOEQ:
268 case ISD::SETONE:
269 case ISD::SETUNE:
270 case ISD::SETNE:
271 case ISD::SETUEQ:
272 case ISD::SETEQ:
273 case ISD::SETFALSE:
274 case ISD::SETFALSE2:
275 case ISD::SETTRUE:
276 case ISD::SETTRUE2:
277 case ISD::SETUO:
278 case ISD::SETO:
279 assert(0 && "Operation should already be optimised !");
280 case ISD::SETULE:
281 case ISD::SETULT:
282 case ISD::SETOLE:
283 case ISD::SETOLT:
284 case ISD::SETLE:
285 case ISD::SETLT: {
286 if (LHS == True)
287 return DAG.getNode(AMDGPUISD::FMIN, DL, VT, LHS, RHS);
288 else
289 return DAG.getNode(AMDGPUISD::FMAX, DL, VT, LHS, RHS);
290 }
291 case ISD::SETGT:
292 case ISD::SETGE:
293 case ISD::SETUGE:
294 case ISD::SETOGE:
295 case ISD::SETUGT:
296 case ISD::SETOGT: {
297 if (LHS == True)
298 return DAG.getNode(AMDGPUISD::FMAX, DL, VT, LHS, RHS);
299 else
300 return DAG.getNode(AMDGPUISD::FMIN, DL, VT, LHS, RHS);
301 }
302 case ISD::SETCC_INVALID:
303 assert(0 && "Invalid setcc condcode !");
304 }
305 return Op;
306}
307
308
309
310SDValue AMDGPUTargetLowering::LowerUDIVREM(SDValue Op,
311 SelectionDAG &DAG) const {
Andrew Trickac6d9be2013-05-25 02:42:55 +0000312 SDLoc DL(Op);
Tom Stellardf98f2ce2012-12-11 21:25:42 +0000313 EVT VT = Op.getValueType();
314
315 SDValue Num = Op.getOperand(0);
316 SDValue Den = Op.getOperand(1);
317
318 SmallVector<SDValue, 8> Results;
319
320 // RCP = URECIP(Den) = 2^32 / Den + e
321 // e is rounding error.
322 SDValue RCP = DAG.getNode(AMDGPUISD::URECIP, DL, VT, Den);
323
324 // RCP_LO = umulo(RCP, Den) */
325 SDValue RCP_LO = DAG.getNode(ISD::UMULO, DL, VT, RCP, Den);
326
327 // RCP_HI = mulhu (RCP, Den) */
328 SDValue RCP_HI = DAG.getNode(ISD::MULHU, DL, VT, RCP, Den);
329
330 // NEG_RCP_LO = -RCP_LO
331 SDValue NEG_RCP_LO = DAG.getNode(ISD::SUB, DL, VT, DAG.getConstant(0, VT),
332 RCP_LO);
333
334 // ABS_RCP_LO = (RCP_HI == 0 ? NEG_RCP_LO : RCP_LO)
335 SDValue ABS_RCP_LO = DAG.getSelectCC(DL, RCP_HI, DAG.getConstant(0, VT),
336 NEG_RCP_LO, RCP_LO,
337 ISD::SETEQ);
338 // Calculate the rounding error from the URECIP instruction
339 // E = mulhu(ABS_RCP_LO, RCP)
340 SDValue E = DAG.getNode(ISD::MULHU, DL, VT, ABS_RCP_LO, RCP);
341
342 // RCP_A_E = RCP + E
343 SDValue RCP_A_E = DAG.getNode(ISD::ADD, DL, VT, RCP, E);
344
345 // RCP_S_E = RCP - E
346 SDValue RCP_S_E = DAG.getNode(ISD::SUB, DL, VT, RCP, E);
347
348 // Tmp0 = (RCP_HI == 0 ? RCP_A_E : RCP_SUB_E)
349 SDValue Tmp0 = DAG.getSelectCC(DL, RCP_HI, DAG.getConstant(0, VT),
350 RCP_A_E, RCP_S_E,
351 ISD::SETEQ);
352 // Quotient = mulhu(Tmp0, Num)
353 SDValue Quotient = DAG.getNode(ISD::MULHU, DL, VT, Tmp0, Num);
354
355 // Num_S_Remainder = Quotient * Den
356 SDValue Num_S_Remainder = DAG.getNode(ISD::UMULO, DL, VT, Quotient, Den);
357
358 // Remainder = Num - Num_S_Remainder
359 SDValue Remainder = DAG.getNode(ISD::SUB, DL, VT, Num, Num_S_Remainder);
360
361 // Remainder_GE_Den = (Remainder >= Den ? -1 : 0)
362 SDValue Remainder_GE_Den = DAG.getSelectCC(DL, Remainder, Den,
363 DAG.getConstant(-1, VT),
364 DAG.getConstant(0, VT),
365 ISD::SETGE);
366 // Remainder_GE_Zero = (Remainder >= 0 ? -1 : 0)
367 SDValue Remainder_GE_Zero = DAG.getSelectCC(DL, Remainder,
368 DAG.getConstant(0, VT),
369 DAG.getConstant(-1, VT),
370 DAG.getConstant(0, VT),
371 ISD::SETGE);
372 // Tmp1 = Remainder_GE_Den & Remainder_GE_Zero
373 SDValue Tmp1 = DAG.getNode(ISD::AND, DL, VT, Remainder_GE_Den,
374 Remainder_GE_Zero);
375
376 // Calculate Division result:
377
378 // Quotient_A_One = Quotient + 1
379 SDValue Quotient_A_One = DAG.getNode(ISD::ADD, DL, VT, Quotient,
380 DAG.getConstant(1, VT));
381
382 // Quotient_S_One = Quotient - 1
383 SDValue Quotient_S_One = DAG.getNode(ISD::SUB, DL, VT, Quotient,
384 DAG.getConstant(1, VT));
385
386 // Div = (Tmp1 == 0 ? Quotient : Quotient_A_One)
387 SDValue Div = DAG.getSelectCC(DL, Tmp1, DAG.getConstant(0, VT),
388 Quotient, Quotient_A_One, ISD::SETEQ);
389
390 // Div = (Remainder_GE_Zero == 0 ? Quotient_S_One : Div)
391 Div = DAG.getSelectCC(DL, Remainder_GE_Zero, DAG.getConstant(0, VT),
392 Quotient_S_One, Div, ISD::SETEQ);
393
394 // Calculate Rem result:
395
396 // Remainder_S_Den = Remainder - Den
397 SDValue Remainder_S_Den = DAG.getNode(ISD::SUB, DL, VT, Remainder, Den);
398
399 // Remainder_A_Den = Remainder + Den
400 SDValue Remainder_A_Den = DAG.getNode(ISD::ADD, DL, VT, Remainder, Den);
401
402 // Rem = (Tmp1 == 0 ? Remainder : Remainder_S_Den)
403 SDValue Rem = DAG.getSelectCC(DL, Tmp1, DAG.getConstant(0, VT),
404 Remainder, Remainder_S_Den, ISD::SETEQ);
405
406 // Rem = (Remainder_GE_Zero == 0 ? Remainder_A_Den : Rem)
407 Rem = DAG.getSelectCC(DL, Remainder_GE_Zero, DAG.getConstant(0, VT),
408 Remainder_A_Den, Rem, ISD::SETEQ);
409 SDValue Ops[2];
410 Ops[0] = Div;
411 Ops[1] = Rem;
412 return DAG.getMergeValues(Ops, 2, DL);
413}
414
415//===----------------------------------------------------------------------===//
416// Helper functions
417//===----------------------------------------------------------------------===//
418
419bool AMDGPUTargetLowering::isHWTrueValue(SDValue Op) const {
420 if (ConstantFPSDNode * CFP = dyn_cast<ConstantFPSDNode>(Op)) {
421 return CFP->isExactlyValue(1.0);
422 }
423 if (ConstantSDNode *C = dyn_cast<ConstantSDNode>(Op)) {
424 return C->isAllOnesValue();
425 }
426 return false;
427}
428
429bool AMDGPUTargetLowering::isHWFalseValue(SDValue Op) const {
430 if (ConstantFPSDNode * CFP = dyn_cast<ConstantFPSDNode>(Op)) {
431 return CFP->getValueAPF().isZero();
432 }
433 if (ConstantSDNode *C = dyn_cast<ConstantSDNode>(Op)) {
434 return C->isNullValue();
435 }
436 return false;
437}
438
439SDValue AMDGPUTargetLowering::CreateLiveInRegister(SelectionDAG &DAG,
440 const TargetRegisterClass *RC,
441 unsigned Reg, EVT VT) const {
442 MachineFunction &MF = DAG.getMachineFunction();
443 MachineRegisterInfo &MRI = MF.getRegInfo();
444 unsigned VirtualRegister;
445 if (!MRI.isLiveIn(Reg)) {
446 VirtualRegister = MRI.createVirtualRegister(RC);
447 MRI.addLiveIn(Reg, VirtualRegister);
448 } else {
449 VirtualRegister = MRI.getLiveInVirtReg(Reg);
450 }
451 return DAG.getRegister(VirtualRegister, VT);
452}
453
454#define NODE_NAME_CASE(node) case AMDGPUISD::node: return #node;
455
456const char* AMDGPUTargetLowering::getTargetNodeName(unsigned Opcode) const {
457 switch (Opcode) {
458 default: return 0;
459 // AMDIL DAG nodes
Tom Stellardf98f2ce2012-12-11 21:25:42 +0000460 NODE_NAME_CASE(CALL);
461 NODE_NAME_CASE(UMUL);
462 NODE_NAME_CASE(DIV_INF);
463 NODE_NAME_CASE(RET_FLAG);
464 NODE_NAME_CASE(BRANCH_COND);
465
466 // AMDGPU DAG nodes
467 NODE_NAME_CASE(DWORDADDR)
468 NODE_NAME_CASE(FRACT)
469 NODE_NAME_CASE(FMAX)
470 NODE_NAME_CASE(SMAX)
471 NODE_NAME_CASE(UMAX)
472 NODE_NAME_CASE(FMIN)
473 NODE_NAME_CASE(SMIN)
474 NODE_NAME_CASE(UMIN)
475 NODE_NAME_CASE(URECIP)
Tom Stellardf98f2ce2012-12-11 21:25:42 +0000476 NODE_NAME_CASE(EXPORT)
Tom Stellardc7e18882013-01-23 02:09:03 +0000477 NODE_NAME_CASE(CONST_ADDRESS)
Tom Stellardc0b0c672013-02-06 17:32:29 +0000478 NODE_NAME_CASE(REGISTER_LOAD)
479 NODE_NAME_CASE(REGISTER_STORE)
Tom Stellardf98f2ce2012-12-11 21:25:42 +0000480 }
481}