1 //===-- AMDGPUISelLowering.cpp - AMDGPU Common DAG lowering functions -----===//
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 This is the parent TargetLowering class for hardware code gen
14 //===----------------------------------------------------------------------===//
16 #include "AMDGPUISelLowering.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"
32 #include "AMDGPUGenCallingConv.inc"
34 AMDGPUTargetLowering::AMDGPUTargetLowering(TargetMachine &TM) :
35 TargetLowering(TM, new TargetLoweringObjectFileELF()) {
37 // Initialize target lowering borrowed from AMDIL
40 // We need to custom lower some of the intrinsics
41 setOperationAction(ISD::INTRINSIC_WO_CHAIN, MVT::Other, Custom);
43 // Library functions. These default to Expand, but we have instructions
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);
53 // The hardware supports ROTR, but not ROTL
54 setOperationAction(ISD::ROTL, MVT::i32, Expand);
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);
61 setOperationAction(ISD::STORE, MVT::v2f32, Promote);
62 AddPromotedToType(ISD::STORE, MVT::v2f32, MVT::v2i32);
64 setOperationAction(ISD::STORE, MVT::v4f32, Promote);
65 AddPromotedToType(ISD::STORE, MVT::v4f32, MVT::v4i32);
67 setOperationAction(ISD::STORE, MVT::f64, Promote);
68 AddPromotedToType(ISD::STORE, MVT::f64, MVT::i64);
70 setTruncStoreAction(MVT::v2i32, MVT::v2i16, Custom);
71 setTruncStoreAction(MVT::v2i32, MVT::v2i8, Custom);
72 setTruncStoreAction(MVT::v4i32, MVT::v4i8, Custom);
73 // XXX: This can be change to Custom, once ExpandVectorStores can
74 // handle 64-bit stores.
75 setTruncStoreAction(MVT::v4i32, MVT::v4i16, Expand);
77 setOperationAction(ISD::LOAD, MVT::f32, Promote);
78 AddPromotedToType(ISD::LOAD, MVT::f32, MVT::i32);
80 setOperationAction(ISD::LOAD, MVT::v2f32, Promote);
81 AddPromotedToType(ISD::LOAD, MVT::v2f32, MVT::v2i32);
83 setOperationAction(ISD::LOAD, MVT::v4f32, Promote);
84 AddPromotedToType(ISD::LOAD, MVT::v4f32, MVT::v4i32);
86 setOperationAction(ISD::LOAD, MVT::f64, Promote);
87 AddPromotedToType(ISD::LOAD, MVT::f64, MVT::i64);
89 setOperationAction(ISD::CONCAT_VECTORS, MVT::v4i32, Custom);
90 setOperationAction(ISD::CONCAT_VECTORS, MVT::v4f32, Custom);
91 setOperationAction(ISD::EXTRACT_SUBVECTOR, MVT::v2i32, Custom);
92 setOperationAction(ISD::EXTRACT_SUBVECTOR, MVT::v2f32, Custom);
94 setLoadExtAction(ISD::EXTLOAD, MVT::v2i8, Expand);
95 setLoadExtAction(ISD::SEXTLOAD, MVT::v2i8, Expand);
96 setLoadExtAction(ISD::ZEXTLOAD, MVT::v2i8, Expand);
97 setLoadExtAction(ISD::EXTLOAD, MVT::v4i8, Expand);
98 setLoadExtAction(ISD::SEXTLOAD, MVT::v4i8, Expand);
99 setLoadExtAction(ISD::ZEXTLOAD, MVT::v4i8, Expand);
100 setLoadExtAction(ISD::EXTLOAD, MVT::v2i16, Expand);
101 setLoadExtAction(ISD::SEXTLOAD, MVT::v2i16, Expand);
102 setLoadExtAction(ISD::ZEXTLOAD, MVT::v2i16, Expand);
103 setLoadExtAction(ISD::EXTLOAD, MVT::v4i16, Expand);
104 setLoadExtAction(ISD::SEXTLOAD, MVT::v4i16, Expand);
105 setLoadExtAction(ISD::ZEXTLOAD, MVT::v4i16, Expand);
107 setOperationAction(ISD::FNEG, MVT::v2f32, Expand);
108 setOperationAction(ISD::FNEG, MVT::v4f32, Expand);
110 setOperationAction(ISD::MUL, MVT::i64, Expand);
112 setOperationAction(ISD::UDIV, MVT::i32, Expand);
113 setOperationAction(ISD::UDIVREM, MVT::i32, Custom);
114 setOperationAction(ISD::UREM, MVT::i32, Expand);
115 setOperationAction(ISD::VSELECT, MVT::v2f32, Expand);
116 setOperationAction(ISD::VSELECT, MVT::v4f32, Expand);
118 static const int types[] = {
122 const size_t NumTypes = array_lengthof(types);
124 for (unsigned int x = 0; x < NumTypes; ++x) {
125 MVT::SimpleValueType VT = (MVT::SimpleValueType)types[x];
126 //Expand the following operations for the current type by default
127 setOperationAction(ISD::ADD, VT, Expand);
128 setOperationAction(ISD::AND, VT, Expand);
129 setOperationAction(ISD::FP_TO_SINT, VT, Expand);
130 setOperationAction(ISD::FP_TO_UINT, VT, Expand);
131 setOperationAction(ISD::MUL, VT, Expand);
132 setOperationAction(ISD::OR, VT, Expand);
133 setOperationAction(ISD::SHL, VT, Expand);
134 setOperationAction(ISD::SINT_TO_FP, VT, Expand);
135 setOperationAction(ISD::SRL, VT, Expand);
136 setOperationAction(ISD::SRA, VT, Expand);
137 setOperationAction(ISD::SUB, VT, Expand);
138 setOperationAction(ISD::UDIV, VT, Expand);
139 setOperationAction(ISD::UINT_TO_FP, VT, Expand);
140 setOperationAction(ISD::UREM, VT, Expand);
141 setOperationAction(ISD::VSELECT, VT, Expand);
142 setOperationAction(ISD::XOR, VT, Expand);
146 //===----------------------------------------------------------------------===//
147 // Target Information
148 //===----------------------------------------------------------------------===//
150 MVT AMDGPUTargetLowering::getVectorIdxTy() const {
155 //===---------------------------------------------------------------------===//
157 //===---------------------------------------------------------------------===//
159 bool AMDGPUTargetLowering::isFAbsFree(EVT VT) const {
160 assert(VT.isFloatingPoint());
161 return VT == MVT::f32;
164 bool AMDGPUTargetLowering::isFNegFree(EVT VT) const {
165 assert(VT.isFloatingPoint());
166 return VT == MVT::f32;
169 //===---------------------------------------------------------------------===//
170 // TargetLowering Callbacks
171 //===---------------------------------------------------------------------===//
173 void AMDGPUTargetLowering::AnalyzeFormalArguments(CCState &State,
174 const SmallVectorImpl<ISD::InputArg> &Ins) const {
176 State.AnalyzeFormalArguments(Ins, CC_AMDGPU);
179 SDValue AMDGPUTargetLowering::LowerReturn(
181 CallingConv::ID CallConv,
183 const SmallVectorImpl<ISD::OutputArg> &Outs,
184 const SmallVectorImpl<SDValue> &OutVals,
185 SDLoc DL, SelectionDAG &DAG) const {
186 return DAG.getNode(AMDGPUISD::RET_FLAG, DL, MVT::Other, Chain);
189 //===---------------------------------------------------------------------===//
190 // Target specific lowering
191 //===---------------------------------------------------------------------===//
193 SDValue AMDGPUTargetLowering::LowerOperation(SDValue Op, SelectionDAG &DAG)
195 switch (Op.getOpcode()) {
197 Op.getNode()->dump();
198 assert(0 && "Custom lowering code for this"
199 "instruction is not implemented yet!");
201 // AMDIL DAG lowering
202 case ISD::SDIV: return LowerSDIV(Op, DAG);
203 case ISD::SREM: return LowerSREM(Op, DAG);
204 case ISD::SIGN_EXTEND_INREG: return LowerSIGN_EXTEND_INREG(Op, DAG);
205 case ISD::BRCOND: return LowerBRCOND(Op, DAG);
206 // AMDGPU DAG lowering
207 case ISD::CONCAT_VECTORS: return LowerCONCAT_VECTORS(Op, DAG);
208 case ISD::EXTRACT_SUBVECTOR: return LowerEXTRACT_SUBVECTOR(Op, DAG);
209 case ISD::INTRINSIC_WO_CHAIN: return LowerINTRINSIC_WO_CHAIN(Op, DAG);
210 case ISD::STORE: return LowerVectorStore(Op, DAG);
211 case ISD::UDIVREM: return LowerUDIVREM(Op, DAG);
216 SDValue AMDGPUTargetLowering::LowerGlobalAddress(AMDGPUMachineFunction* MFI,
218 SelectionDAG &DAG) const {
220 const DataLayout *TD = getTargetMachine().getDataLayout();
221 GlobalAddressSDNode *G = cast<GlobalAddressSDNode>(Op);
222 // XXX: What does the value of G->getOffset() mean?
223 assert(G->getOffset() == 0 &&
224 "Do not know what to do with an non-zero offset");
226 unsigned Offset = MFI->LDSSize;
227 const GlobalValue *GV = G->getGlobal();
228 uint64_t Size = TD->getTypeAllocSize(GV->getType()->getElementType());
230 // XXX: Account for alignment?
231 MFI->LDSSize += Size;
233 return DAG.getConstant(Offset, TD->getPointerSize() == 8 ? MVT::i64 : MVT::i32);
236 void AMDGPUTargetLowering::ExtractVectorElements(SDValue Op, SelectionDAG &DAG,
237 SmallVectorImpl<SDValue> &Args,
239 unsigned Count) const {
240 EVT VT = Op.getValueType();
241 for (unsigned i = Start, e = Start + Count; i != e; ++i) {
242 Args.push_back(DAG.getNode(ISD::EXTRACT_VECTOR_ELT, SDLoc(Op),
243 VT.getVectorElementType(),
244 Op, DAG.getConstant(i, MVT::i32)));
248 SDValue AMDGPUTargetLowering::LowerCONCAT_VECTORS(SDValue Op,
249 SelectionDAG &DAG) const {
250 SmallVector<SDValue, 8> Args;
251 SDValue A = Op.getOperand(0);
252 SDValue B = Op.getOperand(1);
254 ExtractVectorElements(A, DAG, Args, 0,
255 A.getValueType().getVectorNumElements());
256 ExtractVectorElements(B, DAG, Args, 0,
257 B.getValueType().getVectorNumElements());
259 return DAG.getNode(ISD::BUILD_VECTOR, SDLoc(Op), Op.getValueType(),
260 &Args[0], Args.size());
263 SDValue AMDGPUTargetLowering::LowerEXTRACT_SUBVECTOR(SDValue Op,
264 SelectionDAG &DAG) const {
266 SmallVector<SDValue, 8> Args;
267 EVT VT = Op.getValueType();
268 unsigned Start = cast<ConstantSDNode>(Op.getOperand(1))->getZExtValue();
269 ExtractVectorElements(Op.getOperand(0), DAG, Args, Start,
270 VT.getVectorNumElements());
272 return DAG.getNode(ISD::BUILD_VECTOR, SDLoc(Op), Op.getValueType(),
273 &Args[0], Args.size());
277 SDValue AMDGPUTargetLowering::LowerINTRINSIC_WO_CHAIN(SDValue Op,
278 SelectionDAG &DAG) const {
279 unsigned IntrinsicID = cast<ConstantSDNode>(Op.getOperand(0))->getZExtValue();
281 EVT VT = Op.getValueType();
283 switch (IntrinsicID) {
285 case AMDGPUIntrinsic::AMDIL_abs:
286 return LowerIntrinsicIABS(Op, DAG);
287 case AMDGPUIntrinsic::AMDIL_exp:
288 return DAG.getNode(ISD::FEXP2, DL, VT, Op.getOperand(1));
289 case AMDGPUIntrinsic::AMDGPU_lrp:
290 return LowerIntrinsicLRP(Op, DAG);
291 case AMDGPUIntrinsic::AMDIL_fraction:
292 return DAG.getNode(AMDGPUISD::FRACT, DL, VT, Op.getOperand(1));
293 case AMDGPUIntrinsic::AMDIL_max:
294 return DAG.getNode(AMDGPUISD::FMAX, DL, VT, Op.getOperand(1),
296 case AMDGPUIntrinsic::AMDGPU_imax:
297 return DAG.getNode(AMDGPUISD::SMAX, DL, VT, Op.getOperand(1),
299 case AMDGPUIntrinsic::AMDGPU_umax:
300 return DAG.getNode(AMDGPUISD::UMAX, DL, VT, Op.getOperand(1),
302 case AMDGPUIntrinsic::AMDIL_min:
303 return DAG.getNode(AMDGPUISD::FMIN, DL, VT, Op.getOperand(1),
305 case AMDGPUIntrinsic::AMDGPU_imin:
306 return DAG.getNode(AMDGPUISD::SMIN, DL, VT, Op.getOperand(1),
308 case AMDGPUIntrinsic::AMDGPU_umin:
309 return DAG.getNode(AMDGPUISD::UMIN, DL, VT, Op.getOperand(1),
311 case AMDGPUIntrinsic::AMDIL_round_nearest:
312 return DAG.getNode(ISD::FRINT, DL, VT, Op.getOperand(1));
316 ///IABS(a) = SMAX(sub(0, a), a)
317 SDValue AMDGPUTargetLowering::LowerIntrinsicIABS(SDValue Op,
318 SelectionDAG &DAG) const {
321 EVT VT = Op.getValueType();
322 SDValue Neg = DAG.getNode(ISD::SUB, DL, VT, DAG.getConstant(0, VT),
325 return DAG.getNode(AMDGPUISD::SMAX, DL, VT, Neg, Op.getOperand(1));
328 /// Linear Interpolation
329 /// LRP(a, b, c) = muladd(a, b, (1 - a) * c)
330 SDValue AMDGPUTargetLowering::LowerIntrinsicLRP(SDValue Op,
331 SelectionDAG &DAG) const {
333 EVT VT = Op.getValueType();
334 SDValue OneSubA = DAG.getNode(ISD::FSUB, DL, VT,
335 DAG.getConstantFP(1.0f, MVT::f32),
337 SDValue OneSubAC = DAG.getNode(ISD::FMUL, DL, VT, OneSubA,
339 return DAG.getNode(ISD::FADD, DL, VT,
340 DAG.getNode(ISD::FMUL, DL, VT, Op.getOperand(1), Op.getOperand(2)),
344 /// \brief Generate Min/Max node
345 SDValue AMDGPUTargetLowering::LowerMinMax(SDValue Op,
346 SelectionDAG &DAG) const {
348 EVT VT = Op.getValueType();
350 SDValue LHS = Op.getOperand(0);
351 SDValue RHS = Op.getOperand(1);
352 SDValue True = Op.getOperand(2);
353 SDValue False = Op.getOperand(3);
354 SDValue CC = Op.getOperand(4);
356 if (VT != MVT::f32 ||
357 !((LHS == True && RHS == False) || (LHS == False && RHS == True))) {
361 ISD::CondCode CCOpcode = cast<CondCodeSDNode>(CC)->get();
375 assert(0 && "Operation should already be optimised !");
383 return DAG.getNode(AMDGPUISD::FMIN, DL, VT, LHS, RHS);
385 return DAG.getNode(AMDGPUISD::FMAX, DL, VT, LHS, RHS);
394 return DAG.getNode(AMDGPUISD::FMAX, DL, VT, LHS, RHS);
396 return DAG.getNode(AMDGPUISD::FMIN, DL, VT, LHS, RHS);
398 case ISD::SETCC_INVALID:
399 assert(0 && "Invalid setcc condcode !");
406 SDValue AMDGPUTargetLowering::LowerUDIVREM(SDValue Op,
407 SelectionDAG &DAG) const {
409 EVT VT = Op.getValueType();
411 SDValue Num = Op.getOperand(0);
412 SDValue Den = Op.getOperand(1);
414 SmallVector<SDValue, 8> Results;
416 // RCP = URECIP(Den) = 2^32 / Den + e
417 // e is rounding error.
418 SDValue RCP = DAG.getNode(AMDGPUISD::URECIP, DL, VT, Den);
420 // RCP_LO = umulo(RCP, Den) */
421 SDValue RCP_LO = DAG.getNode(ISD::UMULO, DL, VT, RCP, Den);
423 // RCP_HI = mulhu (RCP, Den) */
424 SDValue RCP_HI = DAG.getNode(ISD::MULHU, DL, VT, RCP, Den);
426 // NEG_RCP_LO = -RCP_LO
427 SDValue NEG_RCP_LO = DAG.getNode(ISD::SUB, DL, VT, DAG.getConstant(0, VT),
430 // ABS_RCP_LO = (RCP_HI == 0 ? NEG_RCP_LO : RCP_LO)
431 SDValue ABS_RCP_LO = DAG.getSelectCC(DL, RCP_HI, DAG.getConstant(0, VT),
434 // Calculate the rounding error from the URECIP instruction
435 // E = mulhu(ABS_RCP_LO, RCP)
436 SDValue E = DAG.getNode(ISD::MULHU, DL, VT, ABS_RCP_LO, RCP);
439 SDValue RCP_A_E = DAG.getNode(ISD::ADD, DL, VT, RCP, E);
442 SDValue RCP_S_E = DAG.getNode(ISD::SUB, DL, VT, RCP, E);
444 // Tmp0 = (RCP_HI == 0 ? RCP_A_E : RCP_SUB_E)
445 SDValue Tmp0 = DAG.getSelectCC(DL, RCP_HI, DAG.getConstant(0, VT),
448 // Quotient = mulhu(Tmp0, Num)
449 SDValue Quotient = DAG.getNode(ISD::MULHU, DL, VT, Tmp0, Num);
451 // Num_S_Remainder = Quotient * Den
452 SDValue Num_S_Remainder = DAG.getNode(ISD::UMULO, DL, VT, Quotient, Den);
454 // Remainder = Num - Num_S_Remainder
455 SDValue Remainder = DAG.getNode(ISD::SUB, DL, VT, Num, Num_S_Remainder);
457 // Remainder_GE_Den = (Remainder >= Den ? -1 : 0)
458 SDValue Remainder_GE_Den = DAG.getSelectCC(DL, Remainder, Den,
459 DAG.getConstant(-1, VT),
460 DAG.getConstant(0, VT),
462 // Remainder_GE_Zero = (Remainder >= 0 ? -1 : 0)
463 SDValue Remainder_GE_Zero = DAG.getSelectCC(DL, Remainder,
464 DAG.getConstant(0, VT),
465 DAG.getConstant(-1, VT),
466 DAG.getConstant(0, VT),
468 // Tmp1 = Remainder_GE_Den & Remainder_GE_Zero
469 SDValue Tmp1 = DAG.getNode(ISD::AND, DL, VT, Remainder_GE_Den,
472 // Calculate Division result:
474 // Quotient_A_One = Quotient + 1
475 SDValue Quotient_A_One = DAG.getNode(ISD::ADD, DL, VT, Quotient,
476 DAG.getConstant(1, VT));
478 // Quotient_S_One = Quotient - 1
479 SDValue Quotient_S_One = DAG.getNode(ISD::SUB, DL, VT, Quotient,
480 DAG.getConstant(1, VT));
482 // Div = (Tmp1 == 0 ? Quotient : Quotient_A_One)
483 SDValue Div = DAG.getSelectCC(DL, Tmp1, DAG.getConstant(0, VT),
484 Quotient, Quotient_A_One, ISD::SETEQ);
486 // Div = (Remainder_GE_Zero == 0 ? Quotient_S_One : Div)
487 Div = DAG.getSelectCC(DL, Remainder_GE_Zero, DAG.getConstant(0, VT),
488 Quotient_S_One, Div, ISD::SETEQ);
490 // Calculate Rem result:
492 // Remainder_S_Den = Remainder - Den
493 SDValue Remainder_S_Den = DAG.getNode(ISD::SUB, DL, VT, Remainder, Den);
495 // Remainder_A_Den = Remainder + Den
496 SDValue Remainder_A_Den = DAG.getNode(ISD::ADD, DL, VT, Remainder, Den);
498 // Rem = (Tmp1 == 0 ? Remainder : Remainder_S_Den)
499 SDValue Rem = DAG.getSelectCC(DL, Tmp1, DAG.getConstant(0, VT),
500 Remainder, Remainder_S_Den, ISD::SETEQ);
502 // Rem = (Remainder_GE_Zero == 0 ? Remainder_A_Den : Rem)
503 Rem = DAG.getSelectCC(DL, Remainder_GE_Zero, DAG.getConstant(0, VT),
504 Remainder_A_Den, Rem, ISD::SETEQ);
508 return DAG.getMergeValues(Ops, 2, DL);
511 SDValue AMDGPUTargetLowering::LowerVectorStore(const SDValue &Op,
512 SelectionDAG &DAG) const {
513 StoreSDNode *Store = dyn_cast<StoreSDNode>(Op);
514 EVT MemVT = Store->getMemoryVT();
515 unsigned MemBits = MemVT.getSizeInBits();
517 // Byte stores are really expensive, so if possible, try to pack
518 // 32-bit vector truncatating store into an i32 store.
519 // XXX: We could also handle optimize other vector bitwidths
520 if (!MemVT.isVector() || MemBits > 32) {
525 const SDValue &Value = Store->getValue();
526 EVT VT = Value.getValueType();
527 const SDValue &Ptr = Store->getBasePtr();
528 EVT MemEltVT = MemVT.getVectorElementType();
529 unsigned MemEltBits = MemEltVT.getSizeInBits();
530 unsigned MemNumElements = MemVT.getVectorNumElements();
531 EVT PackedVT = EVT::getIntegerVT(*DAG.getContext(), MemVT.getSizeInBits());
535 Mask = DAG.getConstant(0xFF, PackedVT);
538 Mask = DAG.getConstant(0xFFFF, PackedVT);
541 llvm_unreachable("Cannot lower this vector store");
544 for (unsigned i = 0; i < MemNumElements; ++i) {
545 EVT ElemVT = VT.getVectorElementType();
546 SDValue Elt = DAG.getNode(ISD::EXTRACT_VECTOR_ELT, DL, ElemVT, Value,
547 DAG.getConstant(i, MVT::i32));
548 Elt = DAG.getZExtOrTrunc(Elt, DL, PackedVT);
549 Elt = DAG.getNode(ISD::AND, DL, PackedVT, Elt, Mask);
550 SDValue Shift = DAG.getConstant(MemEltBits * i, PackedVT);
551 Elt = DAG.getNode(ISD::SHL, DL, PackedVT, Elt, Shift);
555 PackedValue = DAG.getNode(ISD::OR, DL, PackedVT, PackedValue, Elt);
558 return DAG.getStore(Store->getChain(), DL, PackedValue, Ptr,
559 MachinePointerInfo(Store->getMemOperand()->getValue()),
560 Store->isVolatile(), Store->isNonTemporal(),
561 Store->getAlignment());
564 //===----------------------------------------------------------------------===//
566 //===----------------------------------------------------------------------===//
568 bool AMDGPUTargetLowering::isHWTrueValue(SDValue Op) const {
569 if (ConstantFPSDNode * CFP = dyn_cast<ConstantFPSDNode>(Op)) {
570 return CFP->isExactlyValue(1.0);
572 if (ConstantSDNode *C = dyn_cast<ConstantSDNode>(Op)) {
573 return C->isAllOnesValue();
578 bool AMDGPUTargetLowering::isHWFalseValue(SDValue Op) const {
579 if (ConstantFPSDNode * CFP = dyn_cast<ConstantFPSDNode>(Op)) {
580 return CFP->getValueAPF().isZero();
582 if (ConstantSDNode *C = dyn_cast<ConstantSDNode>(Op)) {
583 return C->isNullValue();
588 SDValue AMDGPUTargetLowering::CreateLiveInRegister(SelectionDAG &DAG,
589 const TargetRegisterClass *RC,
590 unsigned Reg, EVT VT) const {
591 MachineFunction &MF = DAG.getMachineFunction();
592 MachineRegisterInfo &MRI = MF.getRegInfo();
593 unsigned VirtualRegister;
594 if (!MRI.isLiveIn(Reg)) {
595 VirtualRegister = MRI.createVirtualRegister(RC);
596 MRI.addLiveIn(Reg, VirtualRegister);
598 VirtualRegister = MRI.getLiveInVirtReg(Reg);
600 return DAG.getRegister(VirtualRegister, VT);
603 #define NODE_NAME_CASE(node) case AMDGPUISD::node: return #node;
605 const char* AMDGPUTargetLowering::getTargetNodeName(unsigned Opcode) const {
609 NODE_NAME_CASE(CALL);
610 NODE_NAME_CASE(UMUL);
611 NODE_NAME_CASE(DIV_INF);
612 NODE_NAME_CASE(RET_FLAG);
613 NODE_NAME_CASE(BRANCH_COND);
616 NODE_NAME_CASE(DWORDADDR)
617 NODE_NAME_CASE(FRACT)
624 NODE_NAME_CASE(URECIP)
625 NODE_NAME_CASE(EXPORT)
626 NODE_NAME_CASE(CONST_ADDRESS)
627 NODE_NAME_CASE(REGISTER_LOAD)
628 NODE_NAME_CASE(REGISTER_STORE)
629 NODE_NAME_CASE(LOAD_CONSTANT)
630 NODE_NAME_CASE(LOAD_INPUT)
631 NODE_NAME_CASE(SAMPLE)
632 NODE_NAME_CASE(SAMPLEB)
633 NODE_NAME_CASE(SAMPLED)
634 NODE_NAME_CASE(SAMPLEL)
635 NODE_NAME_CASE(STORE_MSKOR)