R600: Add support for i16 and i8 global stores
[oota-llvm.git] / lib / Target / R600 / AMDGPUISelLowering.cpp
1 //===-- 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"
17 #include "AMDGPU.h"
18 #include "AMDGPURegisterInfo.h"
19 #include "AMDGPUSubtarget.h"
20 #include "AMDILIntrinsicInfo.h"
21 #include "R600MachineFunctionInfo.h"
22 #include "SIMachineFunctionInfo.h"
23 #include "llvm/CodeGen/CallingConvLower.h"
24 #include "llvm/CodeGen/MachineFunction.h"
25 #include "llvm/CodeGen/MachineRegisterInfo.h"
26 #include "llvm/CodeGen/SelectionDAG.h"
27 #include "llvm/CodeGen/TargetLoweringObjectFileImpl.h"
28 #include "llvm/IR/DataLayout.h"
29
30 using namespace llvm;
31
32 #include "AMDGPUGenCallingConv.inc"
33
34 AMDGPUTargetLowering::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
53   // The hardware supports ROTR, but not ROTL
54   setOperationAction(ISD::ROTL, MVT::i32, Expand);
55
56   // 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
61   setOperationAction(ISD::STORE, MVT::v2f32, Promote);
62   AddPromotedToType(ISD::STORE, MVT::v2f32, MVT::v2i32);
63
64   setOperationAction(ISD::STORE, MVT::v4f32, Promote);
65   AddPromotedToType(ISD::STORE, MVT::v4f32, MVT::v4i32);
66
67   setOperationAction(ISD::STORE, MVT::f64, Promote);
68   AddPromotedToType(ISD::STORE, MVT::f64, MVT::i64);
69
70   setOperationAction(ISD::LOAD, MVT::f32, Promote);
71   AddPromotedToType(ISD::LOAD, MVT::f32, MVT::i32);
72
73   setOperationAction(ISD::LOAD, MVT::v2f32, Promote);
74   AddPromotedToType(ISD::LOAD, MVT::v2f32, MVT::v2i32);
75
76   setOperationAction(ISD::LOAD, MVT::v4f32, Promote);
77   AddPromotedToType(ISD::LOAD, MVT::v4f32, MVT::v4i32);
78
79   setOperationAction(ISD::LOAD, MVT::f64, Promote);
80   AddPromotedToType(ISD::LOAD, MVT::f64, MVT::i64);
81
82   setOperationAction(ISD::CONCAT_VECTORS, MVT::v4i32, Custom);
83   setOperationAction(ISD::CONCAT_VECTORS, MVT::v4f32, Custom);
84   setOperationAction(ISD::EXTRACT_SUBVECTOR, MVT::v2i32, Custom);
85   setOperationAction(ISD::EXTRACT_SUBVECTOR, MVT::v2f32, Custom);
86
87   setOperationAction(ISD::FNEG, MVT::v2f32, Expand);
88   setOperationAction(ISD::FNEG, MVT::v4f32, Expand);
89
90   setOperationAction(ISD::MUL, MVT::i64, Expand);
91
92   setOperationAction(ISD::UDIV, MVT::i32, Expand);
93   setOperationAction(ISD::UDIVREM, MVT::i32, Custom);
94   setOperationAction(ISD::UREM, MVT::i32, Expand);
95   setOperationAction(ISD::VSELECT, MVT::v2f32, Expand);
96   setOperationAction(ISD::VSELECT, MVT::v4f32, Expand);
97
98   static const int types[] = {
99     (int)MVT::v2i32,
100     (int)MVT::v4i32
101   };
102   const size_t NumTypes = array_lengthof(types);
103
104   for (unsigned int x  = 0; x < NumTypes; ++x) {
105     MVT::SimpleValueType VT = (MVT::SimpleValueType)types[x];
106     //Expand the following operations for the current type by default
107     setOperationAction(ISD::ADD,  VT, Expand);
108     setOperationAction(ISD::AND,  VT, Expand);
109     setOperationAction(ISD::FP_TO_SINT, VT, Expand);
110     setOperationAction(ISD::FP_TO_UINT, VT, Expand);
111     setOperationAction(ISD::MUL,  VT, Expand);
112     setOperationAction(ISD::OR,   VT, Expand);
113     setOperationAction(ISD::SHL,  VT, Expand);
114     setOperationAction(ISD::SINT_TO_FP, VT, Expand);
115     setOperationAction(ISD::SRL,  VT, Expand);
116     setOperationAction(ISD::SRA,  VT, Expand);
117     setOperationAction(ISD::SUB,  VT, Expand);
118     setOperationAction(ISD::UDIV, VT, Expand);
119     setOperationAction(ISD::UINT_TO_FP, VT, Expand);
120     setOperationAction(ISD::UREM, VT, Expand);
121     setOperationAction(ISD::VSELECT, VT, Expand);
122     setOperationAction(ISD::XOR,  VT, Expand);
123   }
124 }
125
126 //===----------------------------------------------------------------------===//
127 // Target Information
128 //===----------------------------------------------------------------------===//
129
130 MVT AMDGPUTargetLowering::getVectorIdxTy() const {
131   return MVT::i32;
132 }
133
134
135 //===---------------------------------------------------------------------===//
136 // Target Properties
137 //===---------------------------------------------------------------------===//
138
139 bool AMDGPUTargetLowering::isFAbsFree(EVT VT) const {
140   assert(VT.isFloatingPoint());
141   return VT == MVT::f32;
142 }
143
144 bool AMDGPUTargetLowering::isFNegFree(EVT VT) const {
145   assert(VT.isFloatingPoint());
146   return VT == MVT::f32;
147 }
148
149 //===---------------------------------------------------------------------===//
150 // TargetLowering Callbacks
151 //===---------------------------------------------------------------------===//
152
153 void AMDGPUTargetLowering::AnalyzeFormalArguments(CCState &State,
154                              const SmallVectorImpl<ISD::InputArg> &Ins) const {
155
156   State.AnalyzeFormalArguments(Ins, CC_AMDGPU);
157 }
158
159 SDValue AMDGPUTargetLowering::LowerReturn(
160                                      SDValue Chain,
161                                      CallingConv::ID CallConv,
162                                      bool isVarArg,
163                                      const SmallVectorImpl<ISD::OutputArg> &Outs,
164                                      const SmallVectorImpl<SDValue> &OutVals,
165                                      SDLoc DL, SelectionDAG &DAG) const {
166   return DAG.getNode(AMDGPUISD::RET_FLAG, DL, MVT::Other, Chain);
167 }
168
169 //===---------------------------------------------------------------------===//
170 // Target specific lowering
171 //===---------------------------------------------------------------------===//
172
173 SDValue AMDGPUTargetLowering::LowerOperation(SDValue Op, SelectionDAG &DAG)
174     const {
175   switch (Op.getOpcode()) {
176   default:
177     Op.getNode()->dump();
178     assert(0 && "Custom lowering code for this"
179         "instruction is not implemented yet!");
180     break;
181   // AMDIL DAG lowering
182   case ISD::SDIV: return LowerSDIV(Op, DAG);
183   case ISD::SREM: return LowerSREM(Op, DAG);
184   case ISD::SIGN_EXTEND_INREG: return LowerSIGN_EXTEND_INREG(Op, DAG);
185   case ISD::BRCOND: return LowerBRCOND(Op, DAG);
186   // AMDGPU DAG lowering
187   case ISD::CONCAT_VECTORS: return LowerCONCAT_VECTORS(Op, DAG);
188   case ISD::EXTRACT_SUBVECTOR: return LowerEXTRACT_SUBVECTOR(Op, DAG);
189   case ISD::INTRINSIC_WO_CHAIN: return LowerINTRINSIC_WO_CHAIN(Op, DAG);
190   case ISD::UDIVREM: return LowerUDIVREM(Op, DAG);
191   }
192   return Op;
193 }
194
195 SDValue AMDGPUTargetLowering::LowerGlobalAddress(AMDGPUMachineFunction* MFI,
196                                                  SDValue Op,
197                                                  SelectionDAG &DAG) const {
198
199   const DataLayout *TD = getTargetMachine().getDataLayout();
200   GlobalAddressSDNode *G = cast<GlobalAddressSDNode>(Op);
201   // XXX: What does the value of G->getOffset() mean?
202   assert(G->getOffset() == 0 &&
203          "Do not know what to do with an non-zero offset");
204
205   unsigned Offset = MFI->LDSSize;
206   const GlobalValue *GV = G->getGlobal();
207   uint64_t Size = TD->getTypeAllocSize(GV->getType()->getElementType());
208
209   // XXX: Account for alignment?
210   MFI->LDSSize += Size;
211
212   return DAG.getConstant(Offset, TD->getPointerSize() == 8 ? MVT::i64 : MVT::i32);
213 }
214
215 void AMDGPUTargetLowering::ExtractVectorElements(SDValue Op, SelectionDAG &DAG,
216                                          SmallVectorImpl<SDValue> &Args,
217                                          unsigned Start,
218                                          unsigned Count) const {
219   EVT VT = Op.getValueType();
220   for (unsigned i = Start, e = Start + Count; i != e; ++i) {
221     Args.push_back(DAG.getNode(ISD::EXTRACT_VECTOR_ELT, SDLoc(Op),
222                                VT.getVectorElementType(),
223                                Op, DAG.getConstant(i, MVT::i32)));
224   }
225 }
226
227 SDValue AMDGPUTargetLowering::LowerCONCAT_VECTORS(SDValue Op,
228                                                   SelectionDAG &DAG) const {
229   SmallVector<SDValue, 8> Args;
230   SDValue A = Op.getOperand(0);
231   SDValue B = Op.getOperand(1);
232
233   ExtractVectorElements(A, DAG, Args, 0,
234                         A.getValueType().getVectorNumElements());
235   ExtractVectorElements(B, DAG, Args, 0,
236                         B.getValueType().getVectorNumElements());
237
238   return DAG.getNode(ISD::BUILD_VECTOR, SDLoc(Op), Op.getValueType(),
239                      &Args[0], Args.size());
240 }
241
242 SDValue AMDGPUTargetLowering::LowerEXTRACT_SUBVECTOR(SDValue Op,
243                                                      SelectionDAG &DAG) const {
244
245   SmallVector<SDValue, 8> Args;
246   EVT VT = Op.getValueType();
247   unsigned Start = cast<ConstantSDNode>(Op.getOperand(1))->getZExtValue();
248   ExtractVectorElements(Op.getOperand(0), DAG, Args, Start,
249                         VT.getVectorNumElements());
250
251   return DAG.getNode(ISD::BUILD_VECTOR, SDLoc(Op), Op.getValueType(),
252                      &Args[0], Args.size());
253 }
254
255
256 SDValue AMDGPUTargetLowering::LowerINTRINSIC_WO_CHAIN(SDValue Op,
257     SelectionDAG &DAG) const {
258   unsigned IntrinsicID = cast<ConstantSDNode>(Op.getOperand(0))->getZExtValue();
259   SDLoc DL(Op);
260   EVT VT = Op.getValueType();
261
262   switch (IntrinsicID) {
263     default: return Op;
264     case AMDGPUIntrinsic::AMDIL_abs:
265       return LowerIntrinsicIABS(Op, DAG);
266     case AMDGPUIntrinsic::AMDIL_exp:
267       return DAG.getNode(ISD::FEXP2, DL, VT, Op.getOperand(1));
268     case AMDGPUIntrinsic::AMDGPU_lrp:
269       return LowerIntrinsicLRP(Op, DAG);
270     case AMDGPUIntrinsic::AMDIL_fraction:
271       return DAG.getNode(AMDGPUISD::FRACT, DL, VT, Op.getOperand(1));
272     case AMDGPUIntrinsic::AMDIL_max:
273       return DAG.getNode(AMDGPUISD::FMAX, DL, VT, Op.getOperand(1),
274                                                   Op.getOperand(2));
275     case AMDGPUIntrinsic::AMDGPU_imax:
276       return DAG.getNode(AMDGPUISD::SMAX, DL, VT, Op.getOperand(1),
277                                                   Op.getOperand(2));
278     case AMDGPUIntrinsic::AMDGPU_umax:
279       return DAG.getNode(AMDGPUISD::UMAX, DL, VT, Op.getOperand(1),
280                                                   Op.getOperand(2));
281     case AMDGPUIntrinsic::AMDIL_min:
282       return DAG.getNode(AMDGPUISD::FMIN, DL, VT, Op.getOperand(1),
283                                                   Op.getOperand(2));
284     case AMDGPUIntrinsic::AMDGPU_imin:
285       return DAG.getNode(AMDGPUISD::SMIN, DL, VT, Op.getOperand(1),
286                                                   Op.getOperand(2));
287     case AMDGPUIntrinsic::AMDGPU_umin:
288       return DAG.getNode(AMDGPUISD::UMIN, DL, VT, Op.getOperand(1),
289                                                   Op.getOperand(2));
290     case AMDGPUIntrinsic::AMDIL_round_nearest:
291       return DAG.getNode(ISD::FRINT, DL, VT, Op.getOperand(1));
292   }
293 }
294
295 ///IABS(a) = SMAX(sub(0, a), a)
296 SDValue AMDGPUTargetLowering::LowerIntrinsicIABS(SDValue Op,
297     SelectionDAG &DAG) const {
298
299   SDLoc DL(Op);
300   EVT VT = Op.getValueType();
301   SDValue Neg = DAG.getNode(ISD::SUB, DL, VT, DAG.getConstant(0, VT),
302                                               Op.getOperand(1));
303
304   return DAG.getNode(AMDGPUISD::SMAX, DL, VT, Neg, Op.getOperand(1));
305 }
306
307 /// Linear Interpolation
308 /// LRP(a, b, c) = muladd(a,  b, (1 - a) * c)
309 SDValue AMDGPUTargetLowering::LowerIntrinsicLRP(SDValue Op,
310     SelectionDAG &DAG) const {
311   SDLoc DL(Op);
312   EVT VT = Op.getValueType();
313   SDValue OneSubA = DAG.getNode(ISD::FSUB, DL, VT,
314                                 DAG.getConstantFP(1.0f, MVT::f32),
315                                 Op.getOperand(1));
316   SDValue OneSubAC = DAG.getNode(ISD::FMUL, DL, VT, OneSubA,
317                                                     Op.getOperand(3));
318   return DAG.getNode(ISD::FADD, DL, VT,
319       DAG.getNode(ISD::FMUL, DL, VT, Op.getOperand(1), Op.getOperand(2)),
320       OneSubAC);
321 }
322
323 /// \brief Generate Min/Max node
324 SDValue AMDGPUTargetLowering::LowerMinMax(SDValue Op,
325     SelectionDAG &DAG) const {
326   SDLoc DL(Op);
327   EVT VT = Op.getValueType();
328
329   SDValue LHS = Op.getOperand(0);
330   SDValue RHS = Op.getOperand(1);
331   SDValue True = Op.getOperand(2);
332   SDValue False = Op.getOperand(3);
333   SDValue CC = Op.getOperand(4);
334
335   if (VT != MVT::f32 ||
336       !((LHS == True && RHS == False) || (LHS == False && RHS == True))) {
337     return SDValue();
338   }
339
340   ISD::CondCode CCOpcode = cast<CondCodeSDNode>(CC)->get();
341   switch (CCOpcode) {
342   case ISD::SETOEQ:
343   case ISD::SETONE:
344   case ISD::SETUNE:
345   case ISD::SETNE:
346   case ISD::SETUEQ:
347   case ISD::SETEQ:
348   case ISD::SETFALSE:
349   case ISD::SETFALSE2:
350   case ISD::SETTRUE:
351   case ISD::SETTRUE2:
352   case ISD::SETUO:
353   case ISD::SETO:
354     assert(0 && "Operation should already be optimised !");
355   case ISD::SETULE:
356   case ISD::SETULT:
357   case ISD::SETOLE:
358   case ISD::SETOLT:
359   case ISD::SETLE:
360   case ISD::SETLT: {
361     if (LHS == True)
362       return DAG.getNode(AMDGPUISD::FMIN, DL, VT, LHS, RHS);
363     else
364       return DAG.getNode(AMDGPUISD::FMAX, DL, VT, LHS, RHS);
365   }
366   case ISD::SETGT:
367   case ISD::SETGE:
368   case ISD::SETUGE:
369   case ISD::SETOGE:
370   case ISD::SETUGT:
371   case ISD::SETOGT: {
372     if (LHS == True)
373       return DAG.getNode(AMDGPUISD::FMAX, DL, VT, LHS, RHS);
374     else
375       return DAG.getNode(AMDGPUISD::FMIN, DL, VT, LHS, RHS);
376   }
377   case ISD::SETCC_INVALID:
378     assert(0 && "Invalid setcc condcode !");
379   }
380   return Op;
381 }
382
383
384
385 SDValue AMDGPUTargetLowering::LowerUDIVREM(SDValue Op,
386     SelectionDAG &DAG) const {
387   SDLoc DL(Op);
388   EVT VT = Op.getValueType();
389
390   SDValue Num = Op.getOperand(0);
391   SDValue Den = Op.getOperand(1);
392
393   SmallVector<SDValue, 8> Results;
394
395   // RCP =  URECIP(Den) = 2^32 / Den + e
396   // e is rounding error.
397   SDValue RCP = DAG.getNode(AMDGPUISD::URECIP, DL, VT, Den);
398
399   // RCP_LO = umulo(RCP, Den) */
400   SDValue RCP_LO = DAG.getNode(ISD::UMULO, DL, VT, RCP, Den);
401
402   // RCP_HI = mulhu (RCP, Den) */
403   SDValue RCP_HI = DAG.getNode(ISD::MULHU, DL, VT, RCP, Den);
404
405   // NEG_RCP_LO = -RCP_LO
406   SDValue NEG_RCP_LO = DAG.getNode(ISD::SUB, DL, VT, DAG.getConstant(0, VT),
407                                                      RCP_LO);
408
409   // ABS_RCP_LO = (RCP_HI == 0 ? NEG_RCP_LO : RCP_LO)
410   SDValue ABS_RCP_LO = DAG.getSelectCC(DL, RCP_HI, DAG.getConstant(0, VT),
411                                            NEG_RCP_LO, RCP_LO,
412                                            ISD::SETEQ);
413   // Calculate the rounding error from the URECIP instruction
414   // E = mulhu(ABS_RCP_LO, RCP)
415   SDValue E = DAG.getNode(ISD::MULHU, DL, VT, ABS_RCP_LO, RCP);
416
417   // RCP_A_E = RCP + E
418   SDValue RCP_A_E = DAG.getNode(ISD::ADD, DL, VT, RCP, E);
419
420   // RCP_S_E = RCP - E
421   SDValue RCP_S_E = DAG.getNode(ISD::SUB, DL, VT, RCP, E);
422
423   // Tmp0 = (RCP_HI == 0 ? RCP_A_E : RCP_SUB_E)
424   SDValue Tmp0 = DAG.getSelectCC(DL, RCP_HI, DAG.getConstant(0, VT),
425                                      RCP_A_E, RCP_S_E,
426                                      ISD::SETEQ);
427   // Quotient = mulhu(Tmp0, Num)
428   SDValue Quotient = DAG.getNode(ISD::MULHU, DL, VT, Tmp0, Num);
429
430   // Num_S_Remainder = Quotient * Den
431   SDValue Num_S_Remainder = DAG.getNode(ISD::UMULO, DL, VT, Quotient, Den);
432
433   // Remainder = Num - Num_S_Remainder
434   SDValue Remainder = DAG.getNode(ISD::SUB, DL, VT, Num, Num_S_Remainder);
435
436   // Remainder_GE_Den = (Remainder >= Den ? -1 : 0)
437   SDValue Remainder_GE_Den = DAG.getSelectCC(DL, Remainder, Den,
438                                                  DAG.getConstant(-1, VT),
439                                                  DAG.getConstant(0, VT),
440                                                  ISD::SETGE);
441   // Remainder_GE_Zero = (Remainder >= 0 ? -1 : 0)
442   SDValue Remainder_GE_Zero = DAG.getSelectCC(DL, Remainder,
443                                                   DAG.getConstant(0, VT),
444                                                   DAG.getConstant(-1, VT),
445                                                   DAG.getConstant(0, VT),
446                                                   ISD::SETGE);
447   // Tmp1 = Remainder_GE_Den & Remainder_GE_Zero
448   SDValue Tmp1 = DAG.getNode(ISD::AND, DL, VT, Remainder_GE_Den,
449                                                Remainder_GE_Zero);
450
451   // Calculate Division result:
452
453   // Quotient_A_One = Quotient + 1
454   SDValue Quotient_A_One = DAG.getNode(ISD::ADD, DL, VT, Quotient,
455                                                          DAG.getConstant(1, VT));
456
457   // Quotient_S_One = Quotient - 1
458   SDValue Quotient_S_One = DAG.getNode(ISD::SUB, DL, VT, Quotient,
459                                                          DAG.getConstant(1, VT));
460
461   // Div = (Tmp1 == 0 ? Quotient : Quotient_A_One)
462   SDValue Div = DAG.getSelectCC(DL, Tmp1, DAG.getConstant(0, VT),
463                                      Quotient, Quotient_A_One, ISD::SETEQ);
464
465   // Div = (Remainder_GE_Zero == 0 ? Quotient_S_One : Div)
466   Div = DAG.getSelectCC(DL, Remainder_GE_Zero, DAG.getConstant(0, VT),
467                             Quotient_S_One, Div, ISD::SETEQ);
468
469   // Calculate Rem result:
470
471   // Remainder_S_Den = Remainder - Den
472   SDValue Remainder_S_Den = DAG.getNode(ISD::SUB, DL, VT, Remainder, Den);
473
474   // Remainder_A_Den = Remainder + Den
475   SDValue Remainder_A_Den = DAG.getNode(ISD::ADD, DL, VT, Remainder, Den);
476
477   // Rem = (Tmp1 == 0 ? Remainder : Remainder_S_Den)
478   SDValue Rem = DAG.getSelectCC(DL, Tmp1, DAG.getConstant(0, VT),
479                                     Remainder, Remainder_S_Den, ISD::SETEQ);
480
481   // Rem = (Remainder_GE_Zero == 0 ? Remainder_A_Den : Rem)
482   Rem = DAG.getSelectCC(DL, Remainder_GE_Zero, DAG.getConstant(0, VT),
483                             Remainder_A_Den, Rem, ISD::SETEQ);
484   SDValue Ops[2];
485   Ops[0] = Div;
486   Ops[1] = Rem;
487   return DAG.getMergeValues(Ops, 2, DL);
488 }
489
490 //===----------------------------------------------------------------------===//
491 // Helper functions
492 //===----------------------------------------------------------------------===//
493
494 bool AMDGPUTargetLowering::isHWTrueValue(SDValue Op) const {
495   if (ConstantFPSDNode * CFP = dyn_cast<ConstantFPSDNode>(Op)) {
496     return CFP->isExactlyValue(1.0);
497   }
498   if (ConstantSDNode *C = dyn_cast<ConstantSDNode>(Op)) {
499     return C->isAllOnesValue();
500   }
501   return false;
502 }
503
504 bool AMDGPUTargetLowering::isHWFalseValue(SDValue Op) const {
505   if (ConstantFPSDNode * CFP = dyn_cast<ConstantFPSDNode>(Op)) {
506     return CFP->getValueAPF().isZero();
507   }
508   if (ConstantSDNode *C = dyn_cast<ConstantSDNode>(Op)) {
509     return C->isNullValue();
510   }
511   return false;
512 }
513
514 SDValue AMDGPUTargetLowering::CreateLiveInRegister(SelectionDAG &DAG,
515                                                   const TargetRegisterClass *RC,
516                                                    unsigned Reg, EVT VT) const {
517   MachineFunction &MF = DAG.getMachineFunction();
518   MachineRegisterInfo &MRI = MF.getRegInfo();
519   unsigned VirtualRegister;
520   if (!MRI.isLiveIn(Reg)) {
521     VirtualRegister = MRI.createVirtualRegister(RC);
522     MRI.addLiveIn(Reg, VirtualRegister);
523   } else {
524     VirtualRegister = MRI.getLiveInVirtReg(Reg);
525   }
526   return DAG.getRegister(VirtualRegister, VT);
527 }
528
529 #define NODE_NAME_CASE(node) case AMDGPUISD::node: return #node;
530
531 const char* AMDGPUTargetLowering::getTargetNodeName(unsigned Opcode) const {
532   switch (Opcode) {
533   default: return 0;
534   // AMDIL DAG nodes
535   NODE_NAME_CASE(CALL);
536   NODE_NAME_CASE(UMUL);
537   NODE_NAME_CASE(DIV_INF);
538   NODE_NAME_CASE(RET_FLAG);
539   NODE_NAME_CASE(BRANCH_COND);
540
541   // AMDGPU DAG nodes
542   NODE_NAME_CASE(DWORDADDR)
543   NODE_NAME_CASE(FRACT)
544   NODE_NAME_CASE(FMAX)
545   NODE_NAME_CASE(SMAX)
546   NODE_NAME_CASE(UMAX)
547   NODE_NAME_CASE(FMIN)
548   NODE_NAME_CASE(SMIN)
549   NODE_NAME_CASE(UMIN)
550   NODE_NAME_CASE(URECIP)
551   NODE_NAME_CASE(EXPORT)
552   NODE_NAME_CASE(CONST_ADDRESS)
553   NODE_NAME_CASE(REGISTER_LOAD)
554   NODE_NAME_CASE(REGISTER_STORE)
555   NODE_NAME_CASE(LOAD_CONSTANT)
556   NODE_NAME_CASE(LOAD_INPUT)
557   NODE_NAME_CASE(SAMPLE)
558   NODE_NAME_CASE(SAMPLEB)
559   NODE_NAME_CASE(SAMPLED)
560   NODE_NAME_CASE(SAMPLEL)
561   NODE_NAME_CASE(STORE_MSKOR)
562   }
563 }