LLVM  5.0.0
R600ISelLowering.cpp
Go to the documentation of this file.
1 //===-- R600ISelLowering.cpp - R600 DAG Lowering Implementation -----------===//
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 Custom DAG lowering for R600
12 //
13 //===----------------------------------------------------------------------===//
14 
15 #include "R600ISelLowering.h"
16 #include "AMDGPUFrameLowering.h"
17 #include "AMDGPUIntrinsicInfo.h"
18 #include "AMDGPUSubtarget.h"
19 #include "R600Defines.h"
20 #include "R600FrameLowering.h"
21 #include "R600InstrInfo.h"
23 #include "Utils/AMDGPUBaseInfo.h"
24 #include "llvm/ADT/APFloat.h"
25 #include "llvm/ADT/APInt.h"
26 #include "llvm/ADT/ArrayRef.h"
27 #include "llvm/ADT/DenseMap.h"
28 #include "llvm/ADT/SmallVector.h"
40 #include "llvm/IR/Constants.h"
41 #include "llvm/IR/DerivedTypes.h"
42 #include "llvm/Support/Casting.h"
43 #include "llvm/Support/Compiler.h"
45 #include <cassert>
46 #include <cstdint>
47 #include <iterator>
48 #include <utility>
49 #include <vector>
50 
51 using namespace llvm;
52 
54  const R600Subtarget &STI)
55  : AMDGPUTargetLowering(TM, STI), Gen(STI.getGeneration()) {
56  addRegisterClass(MVT::f32, &AMDGPU::R600_Reg32RegClass);
57  addRegisterClass(MVT::i32, &AMDGPU::R600_Reg32RegClass);
58  addRegisterClass(MVT::v2f32, &AMDGPU::R600_Reg64RegClass);
59  addRegisterClass(MVT::v2i32, &AMDGPU::R600_Reg64RegClass);
60  addRegisterClass(MVT::v4f32, &AMDGPU::R600_Reg128RegClass);
61  addRegisterClass(MVT::v4i32, &AMDGPU::R600_Reg128RegClass);
62 
64 
65  // Legalize loads and stores to the private address space.
69 
70  // EXTLOAD should be the same as ZEXTLOAD. It is legal for some address
71  // spaces, so it is custom lowered to handle those where it isn't.
72  for (MVT VT : MVT::integer_valuetypes()) {
76 
80 
84  }
85 
86  // Workaround for LegalizeDAG asserting on expansion of i1 vector loads.
90 
94 
99 
102  // We need to include these since trunc STORES to PRIVATE need
103  // special handling to accommodate RMW
114 
115  // Workaround for LegalizeDAG asserting on expansion of i1 vector stores.
118 
119  // Set condition code actions
132 
137 
140 
143 
147 
149 
152 
159 
164 
165  // ADD, SUB overflow.
166  // TODO: turn these into Legal?
167  if (Subtarget->hasCARRY())
169 
170  if (Subtarget->hasBORROW())
172 
173  // Expand sign extension of vectors
174  if (!Subtarget->hasBFE())
176 
179 
180  if (!Subtarget->hasBFE())
184 
185  if (!Subtarget->hasBFE())
189 
193 
195 
197 
202 
207 
208  // We don't have 64-bit shifts. Thus we need either SHX i64 or SHX_PARTS i32
209  // to be Legal/Custom in order to avoid library calls.
213 
215 
216  const MVT ScalarIntVTs[] = { MVT::i32, MVT::i64 };
217  for (MVT VT : ScalarIntVTs) {
222  }
223 
224  // LLVM will expand these to atomic_cmp_swap(0)
225  // and atomic_swap, respectively.
228 
229  // We need to custom lower some of the intrinsics
232 
234 
241 }
242 
244  return static_cast<const R600Subtarget *>(Subtarget);
245 }
246 
247 static inline bool isEOP(MachineBasicBlock::iterator I) {
248  if (std::next(I) == I->getParent()->end())
249  return false;
250  return std::next(I)->getOpcode() == AMDGPU::RETURN;
251 }
252 
255  MachineBasicBlock *BB) const {
256  MachineFunction *MF = BB->getParent();
260 
261  switch (MI.getOpcode()) {
262  default:
263  // Replace LDS_*_RET instruction that don't have any uses with the
264  // equivalent LDS_*_NORET instruction.
265  if (TII->isLDSRetInstr(MI.getOpcode())) {
266  int DstIdx = TII->getOperandIdx(MI.getOpcode(), AMDGPU::OpName::dst);
267  assert(DstIdx != -1);
268  MachineInstrBuilder NewMI;
269  // FIXME: getLDSNoRetOp method only handles LDS_1A1D LDS ops. Add
270  // LDS_1A2D support and remove this special case.
271  if (!MRI.use_empty(MI.getOperand(DstIdx).getReg()) ||
272  MI.getOpcode() == AMDGPU::LDS_CMPST_RET)
273  return BB;
274 
275  NewMI = BuildMI(*BB, I, BB->findDebugLoc(I),
276  TII->get(AMDGPU::getLDSNoRetOp(MI.getOpcode())));
277  for (unsigned i = 1, e = MI.getNumOperands(); i < e; ++i) {
278  NewMI.add(MI.getOperand(i));
279  }
280  } else {
282  }
283  break;
284  case AMDGPU::CLAMP_R600: {
286  *BB, I, AMDGPU::MOV, MI.getOperand(0).getReg(),
287  MI.getOperand(1).getReg());
288  TII->addFlag(*NewMI, 0, MO_FLAG_CLAMP);
289  break;
290  }
291 
292  case AMDGPU::FABS_R600: {
294  *BB, I, AMDGPU::MOV, MI.getOperand(0).getReg(),
295  MI.getOperand(1).getReg());
296  TII->addFlag(*NewMI, 0, MO_FLAG_ABS);
297  break;
298  }
299 
300  case AMDGPU::FNEG_R600: {
302  *BB, I, AMDGPU::MOV, MI.getOperand(0).getReg(),
303  MI.getOperand(1).getReg());
304  TII->addFlag(*NewMI, 0, MO_FLAG_NEG);
305  break;
306  }
307 
308  case AMDGPU::MASK_WRITE: {
309  unsigned maskedRegister = MI.getOperand(0).getReg();
311  MachineInstr * defInstr = MRI.getVRegDef(maskedRegister);
312  TII->addFlag(*defInstr, 0, MO_FLAG_MASK);
313  break;
314  }
315 
316  case AMDGPU::MOV_IMM_F32:
317  TII->buildMovImm(*BB, I, MI.getOperand(0).getReg(), MI.getOperand(1)
318  .getFPImm()
319  ->getValueAPF()
320  .bitcastToAPInt()
321  .getZExtValue());
322  break;
323 
324  case AMDGPU::MOV_IMM_I32:
325  TII->buildMovImm(*BB, I, MI.getOperand(0).getReg(),
326  MI.getOperand(1).getImm());
327  break;
328 
329  case AMDGPU::MOV_IMM_GLOBAL_ADDR: {
330  //TODO: Perhaps combine this instruction with the next if possible
331  auto MIB = TII->buildDefaultInstruction(
332  *BB, MI, AMDGPU::MOV, MI.getOperand(0).getReg(), AMDGPU::ALU_LITERAL_X);
333  int Idx = TII->getOperandIdx(*MIB, AMDGPU::OpName::literal);
334  //TODO: Ugh this is rather ugly
335  MIB->getOperand(Idx) = MI.getOperand(1);
336  break;
337  }
338 
339  case AMDGPU::CONST_COPY: {
341  *BB, MI, AMDGPU::MOV, MI.getOperand(0).getReg(), AMDGPU::ALU_CONST);
342  TII->setImmOperand(*NewMI, AMDGPU::OpName::src0_sel,
343  MI.getOperand(1).getImm());
344  break;
345  }
346 
347  case AMDGPU::RAT_WRITE_CACHELESS_32_eg:
348  case AMDGPU::RAT_WRITE_CACHELESS_64_eg:
349  case AMDGPU::RAT_WRITE_CACHELESS_128_eg:
350  BuildMI(*BB, I, BB->findDebugLoc(I), TII->get(MI.getOpcode()))
351  .add(MI.getOperand(0))
352  .add(MI.getOperand(1))
353  .addImm(isEOP(I)); // Set End of program bit
354  break;
355 
356  case AMDGPU::RAT_STORE_TYPED_eg:
357  BuildMI(*BB, I, BB->findDebugLoc(I), TII->get(MI.getOpcode()))
358  .add(MI.getOperand(0))
359  .add(MI.getOperand(1))
360  .add(MI.getOperand(2))
361  .addImm(isEOP(I)); // Set End of program bit
362  break;
363 
364  case AMDGPU::BRANCH:
365  BuildMI(*BB, I, BB->findDebugLoc(I), TII->get(AMDGPU::JUMP))
366  .add(MI.getOperand(0));
367  break;
368 
369  case AMDGPU::BRANCH_COND_f32: {
370  MachineInstr *NewMI =
371  BuildMI(*BB, I, BB->findDebugLoc(I), TII->get(AMDGPU::PRED_X),
372  AMDGPU::PREDICATE_BIT)
373  .add(MI.getOperand(1))
374  .addImm(AMDGPU::PRED_SETNE)
375  .addImm(0); // Flags
376  TII->addFlag(*NewMI, 0, MO_FLAG_PUSH);
377  BuildMI(*BB, I, BB->findDebugLoc(I), TII->get(AMDGPU::JUMP_COND))
378  .add(MI.getOperand(0))
379  .addReg(AMDGPU::PREDICATE_BIT, RegState::Kill);
380  break;
381  }
382 
383  case AMDGPU::BRANCH_COND_i32: {
384  MachineInstr *NewMI =
385  BuildMI(*BB, I, BB->findDebugLoc(I), TII->get(AMDGPU::PRED_X),
386  AMDGPU::PREDICATE_BIT)
387  .add(MI.getOperand(1))
388  .addImm(AMDGPU::PRED_SETNE_INT)
389  .addImm(0); // Flags
390  TII->addFlag(*NewMI, 0, MO_FLAG_PUSH);
391  BuildMI(*BB, I, BB->findDebugLoc(I), TII->get(AMDGPU::JUMP_COND))
392  .add(MI.getOperand(0))
393  .addReg(AMDGPU::PREDICATE_BIT, RegState::Kill);
394  break;
395  }
396 
397  case AMDGPU::EG_ExportSwz:
398  case AMDGPU::R600_ExportSwz: {
399  // Instruction is left unmodified if its not the last one of its type
400  bool isLastInstructionOfItsType = true;
401  unsigned InstExportType = MI.getOperand(1).getImm();
402  for (MachineBasicBlock::iterator NextExportInst = std::next(I),
403  EndBlock = BB->end(); NextExportInst != EndBlock;
404  NextExportInst = std::next(NextExportInst)) {
405  if (NextExportInst->getOpcode() == AMDGPU::EG_ExportSwz ||
406  NextExportInst->getOpcode() == AMDGPU::R600_ExportSwz) {
407  unsigned CurrentInstExportType = NextExportInst->getOperand(1)
408  .getImm();
409  if (CurrentInstExportType == InstExportType) {
410  isLastInstructionOfItsType = false;
411  break;
412  }
413  }
414  }
415  bool EOP = isEOP(I);
416  if (!EOP && !isLastInstructionOfItsType)
417  return BB;
418  unsigned CfInst = (MI.getOpcode() == AMDGPU::EG_ExportSwz) ? 84 : 40;
419  BuildMI(*BB, I, BB->findDebugLoc(I), TII->get(MI.getOpcode()))
420  .add(MI.getOperand(0))
421  .add(MI.getOperand(1))
422  .add(MI.getOperand(2))
423  .add(MI.getOperand(3))
424  .add(MI.getOperand(4))
425  .add(MI.getOperand(5))
426  .add(MI.getOperand(6))
427  .addImm(CfInst)
428  .addImm(EOP);
429  break;
430  }
431  case AMDGPU::RETURN: {
432  return BB;
433  }
434  }
435 
436  MI.eraseFromParent();
437  return BB;
438 }
439 
440 //===----------------------------------------------------------------------===//
441 // Custom DAG Lowering Operations
442 //===----------------------------------------------------------------------===//
443 
447  switch (Op.getOpcode()) {
448  default: return AMDGPUTargetLowering::LowerOperation(Op, DAG);
449  case ISD::EXTRACT_VECTOR_ELT: return LowerEXTRACT_VECTOR_ELT(Op, DAG);
450  case ISD::INSERT_VECTOR_ELT: return LowerINSERT_VECTOR_ELT(Op, DAG);
451  case ISD::SHL_PARTS: return LowerSHLParts(Op, DAG);
452  case ISD::SRA_PARTS:
453  case ISD::SRL_PARTS: return LowerSRXParts(Op, DAG);
454  case ISD::UADDO: return LowerUADDSUBO(Op, DAG, ISD::ADD, AMDGPUISD::CARRY);
455  case ISD::USUBO: return LowerUADDSUBO(Op, DAG, ISD::SUB, AMDGPUISD::BORROW);
456  case ISD::FCOS:
457  case ISD::FSIN: return LowerTrig(Op, DAG);
458  case ISD::SELECT_CC: return LowerSELECT_CC(Op, DAG);
459  case ISD::STORE: return LowerSTORE(Op, DAG);
460  case ISD::LOAD: {
461  SDValue Result = LowerLOAD(Op, DAG);
462  assert((!Result.getNode() ||
463  Result.getNode()->getNumValues() == 2) &&
464  "Load should return a value and a chain");
465  return Result;
466  }
467 
468  case ISD::BRCOND: return LowerBRCOND(Op, DAG);
469  case ISD::GlobalAddress: return LowerGlobalAddress(MFI, Op, DAG);
470  case ISD::FrameIndex: return lowerFrameIndex(Op, DAG);
471  case ISD::INTRINSIC_VOID: {
472  SDValue Chain = Op.getOperand(0);
473  unsigned IntrinsicID =
474  cast<ConstantSDNode>(Op.getOperand(1))->getZExtValue();
475  switch (IntrinsicID) {
476  case AMDGPUIntrinsic::r600_store_swizzle: {
477  SDLoc DL(Op);
478  const SDValue Args[8] = {
479  Chain,
480  Op.getOperand(2), // Export Value
481  Op.getOperand(3), // ArrayBase
482  Op.getOperand(4), // Type
483  DAG.getConstant(0, DL, MVT::i32), // SWZ_X
484  DAG.getConstant(1, DL, MVT::i32), // SWZ_Y
485  DAG.getConstant(2, DL, MVT::i32), // SWZ_Z
486  DAG.getConstant(3, DL, MVT::i32) // SWZ_W
487  };
488  return DAG.getNode(AMDGPUISD::R600_EXPORT, DL, Op.getValueType(), Args);
489  }
490 
491  // default for switch(IntrinsicID)
492  default: break;
493  }
494  // break out of case ISD::INTRINSIC_VOID in switch(Op.getOpcode())
495  break;
496  }
498  unsigned IntrinsicID =
499  cast<ConstantSDNode>(Op.getOperand(0))->getZExtValue();
500  EVT VT = Op.getValueType();
501  SDLoc DL(Op);
502  switch (IntrinsicID) {
503  case AMDGPUIntrinsic::r600_tex:
504  case AMDGPUIntrinsic::r600_texc: {
505  unsigned TextureOp;
506  switch (IntrinsicID) {
507  case AMDGPUIntrinsic::r600_tex:
508  TextureOp = 0;
509  break;
510  case AMDGPUIntrinsic::r600_texc:
511  TextureOp = 1;
512  break;
513  default:
514  llvm_unreachable("unhandled texture operation");
515  }
516 
517  SDValue TexArgs[19] = {
518  DAG.getConstant(TextureOp, DL, MVT::i32),
519  Op.getOperand(1),
520  DAG.getConstant(0, DL, MVT::i32),
521  DAG.getConstant(1, DL, MVT::i32),
522  DAG.getConstant(2, DL, MVT::i32),
523  DAG.getConstant(3, DL, MVT::i32),
524  Op.getOperand(2),
525  Op.getOperand(3),
526  Op.getOperand(4),
527  DAG.getConstant(0, DL, MVT::i32),
528  DAG.getConstant(1, DL, MVT::i32),
529  DAG.getConstant(2, DL, MVT::i32),
530  DAG.getConstant(3, DL, MVT::i32),
531  Op.getOperand(5),
532  Op.getOperand(6),
533  Op.getOperand(7),
534  Op.getOperand(8),
535  Op.getOperand(9),
536  Op.getOperand(10)
537  };
538  return DAG.getNode(AMDGPUISD::TEXTURE_FETCH, DL, MVT::v4f32, TexArgs);
539  }
540  case AMDGPUIntrinsic::r600_dot4: {
541  SDValue Args[8] = {
543  DAG.getConstant(0, DL, MVT::i32)),
545  DAG.getConstant(0, DL, MVT::i32)),
547  DAG.getConstant(1, DL, MVT::i32)),
549  DAG.getConstant(1, DL, MVT::i32)),
551  DAG.getConstant(2, DL, MVT::i32)),
553  DAG.getConstant(2, DL, MVT::i32)),
555  DAG.getConstant(3, DL, MVT::i32)),
557  DAG.getConstant(3, DL, MVT::i32))
558  };
559  return DAG.getNode(AMDGPUISD::DOT4, DL, MVT::f32, Args);
560  }
561 
562  case Intrinsic::r600_implicitarg_ptr: {
565  return DAG.getConstant(ByteOffset, DL, PtrVT);
566  }
567  case Intrinsic::r600_read_ngroups_x:
568  return LowerImplicitParameter(DAG, VT, DL, 0);
569  case Intrinsic::r600_read_ngroups_y:
570  return LowerImplicitParameter(DAG, VT, DL, 1);
571  case Intrinsic::r600_read_ngroups_z:
572  return LowerImplicitParameter(DAG, VT, DL, 2);
573  case Intrinsic::r600_read_global_size_x:
574  return LowerImplicitParameter(DAG, VT, DL, 3);
575  case Intrinsic::r600_read_global_size_y:
576  return LowerImplicitParameter(DAG, VT, DL, 4);
577  case Intrinsic::r600_read_global_size_z:
578  return LowerImplicitParameter(DAG, VT, DL, 5);
579  case Intrinsic::r600_read_local_size_x:
580  return LowerImplicitParameter(DAG, VT, DL, 6);
581  case Intrinsic::r600_read_local_size_y:
582  return LowerImplicitParameter(DAG, VT, DL, 7);
583  case Intrinsic::r600_read_local_size_z:
584  return LowerImplicitParameter(DAG, VT, DL, 8);
585 
586  case Intrinsic::r600_read_tgid_x:
587  return CreateLiveInRegisterRaw(DAG, &AMDGPU::R600_TReg32RegClass,
588  AMDGPU::T1_X, VT);
589  case Intrinsic::r600_read_tgid_y:
590  return CreateLiveInRegisterRaw(DAG, &AMDGPU::R600_TReg32RegClass,
591  AMDGPU::T1_Y, VT);
592  case Intrinsic::r600_read_tgid_z:
593  return CreateLiveInRegisterRaw(DAG, &AMDGPU::R600_TReg32RegClass,
594  AMDGPU::T1_Z, VT);
595  case Intrinsic::r600_read_tidig_x:
596  return CreateLiveInRegisterRaw(DAG, &AMDGPU::R600_TReg32RegClass,
597  AMDGPU::T0_X, VT);
598  case Intrinsic::r600_read_tidig_y:
599  return CreateLiveInRegisterRaw(DAG, &AMDGPU::R600_TReg32RegClass,
600  AMDGPU::T0_Y, VT);
601  case Intrinsic::r600_read_tidig_z:
602  return CreateLiveInRegisterRaw(DAG, &AMDGPU::R600_TReg32RegClass,
603  AMDGPU::T0_Z, VT);
604 
605  case Intrinsic::r600_recipsqrt_ieee:
606  return DAG.getNode(AMDGPUISD::RSQ, DL, VT, Op.getOperand(1));
607 
608  case Intrinsic::r600_recipsqrt_clamped:
609  return DAG.getNode(AMDGPUISD::RSQ_CLAMP, DL, VT, Op.getOperand(1));
610  default:
611  return Op;
612  }
613 
614  // break out of case ISD::INTRINSIC_WO_CHAIN in switch(Op.getOpcode())
615  break;
616  }
617  } // end switch(Op.getOpcode())
618  return SDValue();
619 }
620 
623  SelectionDAG &DAG) const {
624  switch (N->getOpcode()) {
625  default:
627  return;
628  case ISD::FP_TO_UINT:
629  if (N->getValueType(0) == MVT::i1) {
630  Results.push_back(lowerFP_TO_UINT(N->getOperand(0), DAG));
631  return;
632  }
633  // Since we don't care about out of bounds values we can use FP_TO_SINT for
634  // uints too. The DAGLegalizer code for uint considers some extra cases
635  // which are not necessary here.
637  case ISD::FP_TO_SINT: {
638  if (N->getValueType(0) == MVT::i1) {
639  Results.push_back(lowerFP_TO_SINT(N->getOperand(0), DAG));
640  return;
641  }
642 
643  SDValue Result;
644  if (expandFP_TO_SINT(N, Result, DAG))
645  Results.push_back(Result);
646  return;
647  }
648  case ISD::SDIVREM: {
649  SDValue Op = SDValue(N, 1);
650  SDValue RES = LowerSDIVREM(Op, DAG);
651  Results.push_back(RES);
652  Results.push_back(RES.getValue(1));
653  break;
654  }
655  case ISD::UDIVREM: {
656  SDValue Op = SDValue(N, 0);
657  LowerUDIVREM64(Op, DAG, Results);
658  break;
659  }
660  }
661 }
662 
663 SDValue R600TargetLowering::vectorToVerticalVector(SelectionDAG &DAG,
664  SDValue Vector) const {
665  SDLoc DL(Vector);
666  EVT VecVT = Vector.getValueType();
667  EVT EltVT = VecVT.getVectorElementType();
669 
670  for (unsigned i = 0, e = VecVT.getVectorNumElements(); i != e; ++i) {
671  Args.push_back(DAG.getNode(
672  ISD::EXTRACT_VECTOR_ELT, DL, EltVT, Vector,
673  DAG.getConstant(i, DL, getVectorIdxTy(DAG.getDataLayout()))));
674  }
675 
676  return DAG.getNode(AMDGPUISD::BUILD_VERTICAL_VECTOR, DL, VecVT, Args);
677 }
678 
679 SDValue R600TargetLowering::LowerEXTRACT_VECTOR_ELT(SDValue Op,
680  SelectionDAG &DAG) const {
681  SDLoc DL(Op);
682  SDValue Vector = Op.getOperand(0);
683  SDValue Index = Op.getOperand(1);
684 
685  if (isa<ConstantSDNode>(Index) ||
687  return Op;
688 
689  Vector = vectorToVerticalVector(DAG, Vector);
691  Vector, Index);
692 }
693 
694 SDValue R600TargetLowering::LowerINSERT_VECTOR_ELT(SDValue Op,
695  SelectionDAG &DAG) const {
696  SDLoc DL(Op);
697  SDValue Vector = Op.getOperand(0);
698  SDValue Value = Op.getOperand(1);
699  SDValue Index = Op.getOperand(2);
700 
701  if (isa<ConstantSDNode>(Index) ||
703  return Op;
704 
705  Vector = vectorToVerticalVector(DAG, Vector);
707  Vector, Value, Index);
708  return vectorToVerticalVector(DAG, Insert);
709 }
710 
711 SDValue R600TargetLowering::LowerGlobalAddress(AMDGPUMachineFunction *MFI,
712  SDValue Op,
713  SelectionDAG &DAG) const {
714  GlobalAddressSDNode *GSD = cast<GlobalAddressSDNode>(Op);
716  return AMDGPUTargetLowering::LowerGlobalAddress(MFI, Op, DAG);
717 
718  const DataLayout &DL = DAG.getDataLayout();
719  const GlobalValue *GV = GSD->getGlobal();
720  MVT ConstPtrVT = getPointerTy(DL, AMDGPUASI.CONSTANT_ADDRESS);
721 
722  SDValue GA = DAG.getTargetGlobalAddress(GV, SDLoc(GSD), ConstPtrVT);
723  return DAG.getNode(AMDGPUISD::CONST_DATA_PTR, SDLoc(GSD), ConstPtrVT, GA);
724 }
725 
726 SDValue R600TargetLowering::LowerTrig(SDValue Op, SelectionDAG &DAG) const {
727  // On hw >= R700, COS/SIN input must be between -1. and 1.
728  // Thus we lower them to TRIG ( FRACT ( x / 2Pi + 0.5) - 0.5)
729  EVT VT = Op.getValueType();
730  SDValue Arg = Op.getOperand(0);
731  SDLoc DL(Op);
732 
733  // TODO: Should this propagate fast-math-flags?
734  SDValue FractPart = DAG.getNode(AMDGPUISD::FRACT, DL, VT,
735  DAG.getNode(ISD::FADD, DL, VT,
736  DAG.getNode(ISD::FMUL, DL, VT, Arg,
737  DAG.getConstantFP(0.15915494309, DL, MVT::f32)),
738  DAG.getConstantFP(0.5, DL, MVT::f32)));
739  unsigned TrigNode;
740  switch (Op.getOpcode()) {
741  case ISD::FCOS:
742  TrigNode = AMDGPUISD::COS_HW;
743  break;
744  case ISD::FSIN:
745  TrigNode = AMDGPUISD::SIN_HW;
746  break;
747  default:
748  llvm_unreachable("Wrong trig opcode");
749  }
750  SDValue TrigVal = DAG.getNode(TrigNode, DL, VT,
751  DAG.getNode(ISD::FADD, DL, VT, FractPart,
752  DAG.getConstantFP(-0.5, DL, MVT::f32)));
753  if (Gen >= R600Subtarget::R700)
754  return TrigVal;
755  // On R600 hw, COS/SIN input must be between -Pi and Pi.
756  return DAG.getNode(ISD::FMUL, DL, VT, TrigVal,
757  DAG.getConstantFP(3.14159265359, DL, MVT::f32));
758 }
759 
760 SDValue R600TargetLowering::LowerSHLParts(SDValue Op, SelectionDAG &DAG) const {
761  SDLoc DL(Op);
762  EVT VT = Op.getValueType();
763 
764  SDValue Lo = Op.getOperand(0);
765  SDValue Hi = Op.getOperand(1);
766  SDValue Shift = Op.getOperand(2);
767  SDValue Zero = DAG.getConstant(0, DL, VT);
768  SDValue One = DAG.getConstant(1, DL, VT);
769 
770  SDValue Width = DAG.getConstant(VT.getSizeInBits(), DL, VT);
771  SDValue Width1 = DAG.getConstant(VT.getSizeInBits() - 1, DL, VT);
772  SDValue BigShift = DAG.getNode(ISD::SUB, DL, VT, Shift, Width);
773  SDValue CompShift = DAG.getNode(ISD::SUB, DL, VT, Width1, Shift);
774 
775  // The dance around Width1 is necessary for 0 special case.
776  // Without it the CompShift might be 32, producing incorrect results in
777  // Overflow. So we do the shift in two steps, the alternative is to
778  // add a conditional to filter the special case.
779 
780  SDValue Overflow = DAG.getNode(ISD::SRL, DL, VT, Lo, CompShift);
781  Overflow = DAG.getNode(ISD::SRL, DL, VT, Overflow, One);
782 
783  SDValue HiSmall = DAG.getNode(ISD::SHL, DL, VT, Hi, Shift);
784  HiSmall = DAG.getNode(ISD::OR, DL, VT, HiSmall, Overflow);
785  SDValue LoSmall = DAG.getNode(ISD::SHL, DL, VT, Lo, Shift);
786 
787  SDValue HiBig = DAG.getNode(ISD::SHL, DL, VT, Lo, BigShift);
788  SDValue LoBig = Zero;
789 
790  Hi = DAG.getSelectCC(DL, Shift, Width, HiSmall, HiBig, ISD::SETULT);
791  Lo = DAG.getSelectCC(DL, Shift, Width, LoSmall, LoBig, ISD::SETULT);
792 
793  return DAG.getNode(ISD::MERGE_VALUES, DL, DAG.getVTList(VT,VT), Lo, Hi);
794 }
795 
796 SDValue R600TargetLowering::LowerSRXParts(SDValue Op, SelectionDAG &DAG) const {
797  SDLoc DL(Op);
798  EVT VT = Op.getValueType();
799 
800  SDValue Lo = Op.getOperand(0);
801  SDValue Hi = Op.getOperand(1);
802  SDValue Shift = Op.getOperand(2);
803  SDValue Zero = DAG.getConstant(0, DL, VT);
804  SDValue One = DAG.getConstant(1, DL, VT);
805 
806  const bool SRA = Op.getOpcode() == ISD::SRA_PARTS;
807 
808  SDValue Width = DAG.getConstant(VT.getSizeInBits(), DL, VT);
809  SDValue Width1 = DAG.getConstant(VT.getSizeInBits() - 1, DL, VT);
810  SDValue BigShift = DAG.getNode(ISD::SUB, DL, VT, Shift, Width);
811  SDValue CompShift = DAG.getNode(ISD::SUB, DL, VT, Width1, Shift);
812 
813  // The dance around Width1 is necessary for 0 special case.
814  // Without it the CompShift might be 32, producing incorrect results in
815  // Overflow. So we do the shift in two steps, the alternative is to
816  // add a conditional to filter the special case.
817 
818  SDValue Overflow = DAG.getNode(ISD::SHL, DL, VT, Hi, CompShift);
819  Overflow = DAG.getNode(ISD::SHL, DL, VT, Overflow, One);
820 
821  SDValue HiSmall = DAG.getNode(SRA ? ISD::SRA : ISD::SRL, DL, VT, Hi, Shift);
822  SDValue LoSmall = DAG.getNode(ISD::SRL, DL, VT, Lo, Shift);
823  LoSmall = DAG.getNode(ISD::OR, DL, VT, LoSmall, Overflow);
824 
825  SDValue LoBig = DAG.getNode(SRA ? ISD::SRA : ISD::SRL, DL, VT, Hi, BigShift);
826  SDValue HiBig = SRA ? DAG.getNode(ISD::SRA, DL, VT, Hi, Width1) : Zero;
827 
828  Hi = DAG.getSelectCC(DL, Shift, Width, HiSmall, HiBig, ISD::SETULT);
829  Lo = DAG.getSelectCC(DL, Shift, Width, LoSmall, LoBig, ISD::SETULT);
830 
831  return DAG.getNode(ISD::MERGE_VALUES, DL, DAG.getVTList(VT,VT), Lo, Hi);
832 }
833 
834 SDValue R600TargetLowering::LowerUADDSUBO(SDValue Op, SelectionDAG &DAG,
835  unsigned mainop, unsigned ovf) const {
836  SDLoc DL(Op);
837  EVT VT = Op.getValueType();
838 
839  SDValue Lo = Op.getOperand(0);
840  SDValue Hi = Op.getOperand(1);
841 
842  SDValue OVF = DAG.getNode(ovf, DL, VT, Lo, Hi);
843  // Extend sign.
844  OVF = DAG.getNode(ISD::SIGN_EXTEND_INREG, DL, VT, OVF,
845  DAG.getValueType(MVT::i1));
846 
847  SDValue Res = DAG.getNode(mainop, DL, VT, Lo, Hi);
848 
849  return DAG.getNode(ISD::MERGE_VALUES, DL, DAG.getVTList(VT, VT), Res, OVF);
850 }
851 
852 SDValue R600TargetLowering::lowerFP_TO_UINT(SDValue Op, SelectionDAG &DAG) const {
853  SDLoc DL(Op);
854  return DAG.getNode(
855  ISD::SETCC,
856  DL,
857  MVT::i1,
858  Op, DAG.getConstantFP(1.0f, DL, MVT::f32),
859  DAG.getCondCode(ISD::SETEQ));
860 }
861 
862 SDValue R600TargetLowering::lowerFP_TO_SINT(SDValue Op, SelectionDAG &DAG) const {
863  SDLoc DL(Op);
864  return DAG.getNode(
865  ISD::SETCC,
866  DL,
867  MVT::i1,
868  Op, DAG.getConstantFP(-1.0f, DL, MVT::f32),
869  DAG.getCondCode(ISD::SETEQ));
870 }
871 
872 SDValue R600TargetLowering::LowerImplicitParameter(SelectionDAG &DAG, EVT VT,
873  const SDLoc &DL,
874  unsigned DwordOffset) const {
875  unsigned ByteOffset = DwordOffset * 4;
876  PointerType * PtrType = PointerType::get(VT.getTypeForEVT(*DAG.getContext()),
878 
879  // We shouldn't be using an offset wider than 16-bits for implicit parameters.
880  assert(isInt<16>(ByteOffset));
881 
882  return DAG.getLoad(VT, DL, DAG.getEntryNode(),
883  DAG.getConstant(ByteOffset, DL, MVT::i32), // PTR
885 }
886 
887 bool R600TargetLowering::isZero(SDValue Op) const {
888  if(ConstantSDNode *Cst = dyn_cast<ConstantSDNode>(Op)) {
889  return Cst->isNullValue();
890  } else if(ConstantFPSDNode *CstFP = dyn_cast<ConstantFPSDNode>(Op)){
891  return CstFP->isZero();
892  } else {
893  return false;
894  }
895 }
896 
897 bool R600TargetLowering::isHWTrueValue(SDValue Op) const {
898  if (ConstantFPSDNode * CFP = dyn_cast<ConstantFPSDNode>(Op)) {
899  return CFP->isExactlyValue(1.0);
900  }
901  return isAllOnesConstant(Op);
902 }
903 
904 bool R600TargetLowering::isHWFalseValue(SDValue Op) const {
905  if (ConstantFPSDNode * CFP = dyn_cast<ConstantFPSDNode>(Op)) {
906  return CFP->getValueAPF().isZero();
907  }
908  return isNullConstant(Op);
909 }
910 
911 SDValue R600TargetLowering::LowerSELECT_CC(SDValue Op, SelectionDAG &DAG) const {
912  SDLoc DL(Op);
913  EVT VT = Op.getValueType();
914 
915  SDValue LHS = Op.getOperand(0);
916  SDValue RHS = Op.getOperand(1);
917  SDValue True = Op.getOperand(2);
918  SDValue False = Op.getOperand(3);
919  SDValue CC = Op.getOperand(4);
920  SDValue Temp;
921 
922  if (VT == MVT::f32) {
923  DAGCombinerInfo DCI(DAG, AfterLegalizeVectorOps, true, nullptr);
924  SDValue MinMax = combineFMinMaxLegacy(DL, VT, LHS, RHS, True, False, CC, DCI);
925  if (MinMax)
926  return MinMax;
927  }
928 
929  // LHS and RHS are guaranteed to be the same value type
930  EVT CompareVT = LHS.getValueType();
931 
932  // Check if we can lower this to a native operation.
933 
934  // Try to lower to a SET* instruction:
935  //
936  // SET* can match the following patterns:
937  //
938  // select_cc f32, f32, -1, 0, cc_supported
939  // select_cc f32, f32, 1.0f, 0.0f, cc_supported
940  // select_cc i32, i32, -1, 0, cc_supported
941  //
942 
943  // Move hardware True/False values to the correct operand.
944  ISD::CondCode CCOpcode = cast<CondCodeSDNode>(CC)->get();
945  ISD::CondCode InverseCC =
946  ISD::getSetCCInverse(CCOpcode, CompareVT == MVT::i32);
947  if (isHWTrueValue(False) && isHWFalseValue(True)) {
948  if (isCondCodeLegal(InverseCC, CompareVT.getSimpleVT())) {
949  std::swap(False, True);
950  CC = DAG.getCondCode(InverseCC);
951  } else {
952  ISD::CondCode SwapInvCC = ISD::getSetCCSwappedOperands(InverseCC);
953  if (isCondCodeLegal(SwapInvCC, CompareVT.getSimpleVT())) {
954  std::swap(False, True);
955  std::swap(LHS, RHS);
956  CC = DAG.getCondCode(SwapInvCC);
957  }
958  }
959  }
960 
961  if (isHWTrueValue(True) && isHWFalseValue(False) &&
962  (CompareVT == VT || VT == MVT::i32)) {
963  // This can be matched by a SET* instruction.
964  return DAG.getNode(ISD::SELECT_CC, DL, VT, LHS, RHS, True, False, CC);
965  }
966 
967  // Try to lower to a CND* instruction:
968  //
969  // CND* can match the following patterns:
970  //
971  // select_cc f32, 0.0, f32, f32, cc_supported
972  // select_cc f32, 0.0, i32, i32, cc_supported
973  // select_cc i32, 0, f32, f32, cc_supported
974  // select_cc i32, 0, i32, i32, cc_supported
975  //
976 
977  // Try to move the zero value to the RHS
978  if (isZero(LHS)) {
979  ISD::CondCode CCOpcode = cast<CondCodeSDNode>(CC)->get();
980  // Try swapping the operands
981  ISD::CondCode CCSwapped = ISD::getSetCCSwappedOperands(CCOpcode);
982  if (isCondCodeLegal(CCSwapped, CompareVT.getSimpleVT())) {
983  std::swap(LHS, RHS);
984  CC = DAG.getCondCode(CCSwapped);
985  } else {
986  // Try inverting the conditon and then swapping the operands
987  ISD::CondCode CCInv = ISD::getSetCCInverse(CCOpcode, CompareVT.isInteger());
988  CCSwapped = ISD::getSetCCSwappedOperands(CCInv);
989  if (isCondCodeLegal(CCSwapped, CompareVT.getSimpleVT())) {
990  std::swap(True, False);
991  std::swap(LHS, RHS);
992  CC = DAG.getCondCode(CCSwapped);
993  }
994  }
995  }
996  if (isZero(RHS)) {
997  SDValue Cond = LHS;
998  SDValue Zero = RHS;
999  ISD::CondCode CCOpcode = cast<CondCodeSDNode>(CC)->get();
1000  if (CompareVT != VT) {
1001  // Bitcast True / False to the correct types. This will end up being
1002  // a nop, but it allows us to define only a single pattern in the
1003  // .TD files for each CND* instruction rather than having to have
1004  // one pattern for integer True/False and one for fp True/False
1005  True = DAG.getNode(ISD::BITCAST, DL, CompareVT, True);
1006  False = DAG.getNode(ISD::BITCAST, DL, CompareVT, False);
1007  }
1008 
1009  switch (CCOpcode) {
1010  case ISD::SETONE:
1011  case ISD::SETUNE:
1012  case ISD::SETNE:
1013  CCOpcode = ISD::getSetCCInverse(CCOpcode, CompareVT == MVT::i32);
1014  Temp = True;
1015  True = False;
1016  False = Temp;
1017  break;
1018  default:
1019  break;
1020  }
1021  SDValue SelectNode = DAG.getNode(ISD::SELECT_CC, DL, CompareVT,
1022  Cond, Zero,
1023  True, False,
1024  DAG.getCondCode(CCOpcode));
1025  return DAG.getNode(ISD::BITCAST, DL, VT, SelectNode);
1026  }
1027 
1028  // If we make it this for it means we have no native instructions to handle
1029  // this SELECT_CC, so we must lower it.
1030  SDValue HWTrue, HWFalse;
1031 
1032  if (CompareVT == MVT::f32) {
1033  HWTrue = DAG.getConstantFP(1.0f, DL, CompareVT);
1034  HWFalse = DAG.getConstantFP(0.0f, DL, CompareVT);
1035  } else if (CompareVT == MVT::i32) {
1036  HWTrue = DAG.getConstant(-1, DL, CompareVT);
1037  HWFalse = DAG.getConstant(0, DL, CompareVT);
1038  }
1039  else {
1040  llvm_unreachable("Unhandled value type in LowerSELECT_CC");
1041  }
1042 
1043  // Lower this unsupported SELECT_CC into a combination of two supported
1044  // SELECT_CC operations.
1045  SDValue Cond = DAG.getNode(ISD::SELECT_CC, DL, CompareVT, LHS, RHS, HWTrue, HWFalse, CC);
1046 
1047  return DAG.getNode(ISD::SELECT_CC, DL, VT,
1048  Cond, HWFalse,
1049  True, False,
1050  DAG.getCondCode(ISD::SETNE));
1051 }
1052 
1053 /// LLVM generates byte-addressed pointers. For indirect addressing, we need to
1054 /// convert these pointers to a register index. Each register holds
1055 /// 16 bytes, (4 x 32bit sub-register), but we need to take into account the
1056 /// \p StackWidth, which tells us how many of the 4 sub-registrers will be used
1057 /// for indirect addressing.
1058 SDValue R600TargetLowering::stackPtrToRegIndex(SDValue Ptr,
1059  unsigned StackWidth,
1060  SelectionDAG &DAG) const {
1061  unsigned SRLPad;
1062  switch(StackWidth) {
1063  case 1:
1064  SRLPad = 2;
1065  break;
1066  case 2:
1067  SRLPad = 3;
1068  break;
1069  case 4:
1070  SRLPad = 4;
1071  break;
1072  default: llvm_unreachable("Invalid stack width");
1073  }
1074 
1075  SDLoc DL(Ptr);
1076  return DAG.getNode(ISD::SRL, DL, Ptr.getValueType(), Ptr,
1077  DAG.getConstant(SRLPad, DL, MVT::i32));
1078 }
1079 
1080 void R600TargetLowering::getStackAddress(unsigned StackWidth,
1081  unsigned ElemIdx,
1082  unsigned &Channel,
1083  unsigned &PtrIncr) const {
1084  switch (StackWidth) {
1085  default:
1086  case 1:
1087  Channel = 0;
1088  if (ElemIdx > 0) {
1089  PtrIncr = 1;
1090  } else {
1091  PtrIncr = 0;
1092  }
1093  break;
1094  case 2:
1095  Channel = ElemIdx % 2;
1096  if (ElemIdx == 2) {
1097  PtrIncr = 1;
1098  } else {
1099  PtrIncr = 0;
1100  }
1101  break;
1102  case 4:
1103  Channel = ElemIdx;
1104  PtrIncr = 0;
1105  break;
1106  }
1107 }
1108 
1109 SDValue R600TargetLowering::lowerPrivateTruncStore(StoreSDNode *Store,
1110  SelectionDAG &DAG) const {
1111  SDLoc DL(Store);
1112  //TODO: Who creates the i8 stores?
1113  assert(Store->isTruncatingStore()
1114  || Store->getValue().getValueType() == MVT::i8);
1116 
1117  SDValue Mask;
1118  if (Store->getMemoryVT() == MVT::i8) {
1119  assert(Store->getAlignment() >= 1);
1120  Mask = DAG.getConstant(0xff, DL, MVT::i32);
1121  } else if (Store->getMemoryVT() == MVT::i16) {
1122  assert(Store->getAlignment() >= 2);
1123  Mask = DAG.getConstant(0xffff, DL, MVT::i32);
1124  } else {
1125  llvm_unreachable("Unsupported private trunc store");
1126  }
1127 
1128  SDValue OldChain = Store->getChain();
1129  bool VectorTrunc = (OldChain.getOpcode() == AMDGPUISD::DUMMY_CHAIN);
1130  // Skip dummy
1131  SDValue Chain = VectorTrunc ? OldChain->getOperand(0) : OldChain;
1132  SDValue BasePtr = Store->getBasePtr();
1133  SDValue Offset = Store->getOffset();
1134  EVT MemVT = Store->getMemoryVT();
1135 
1136  SDValue LoadPtr = BasePtr;
1137  if (!Offset.isUndef()) {
1138  LoadPtr = DAG.getNode(ISD::ADD, DL, MVT::i32, BasePtr, Offset);
1139  }
1140 
1141  // Get dword location
1142  // TODO: this should be eliminated by the future SHR ptr, 2
1143  SDValue Ptr = DAG.getNode(ISD::AND, DL, MVT::i32, LoadPtr,
1144  DAG.getConstant(0xfffffffc, DL, MVT::i32));
1145 
1146  // Load dword
1147  // TODO: can we be smarter about machine pointer info?
1148  SDValue Dst = DAG.getLoad(MVT::i32, DL, Chain, Ptr, MachinePointerInfo());
1149 
1150  Chain = Dst.getValue(1);
1151 
1152  // Get offset in dword
1153  SDValue ByteIdx = DAG.getNode(ISD::AND, DL, MVT::i32, LoadPtr,
1154  DAG.getConstant(0x3, DL, MVT::i32));
1155 
1156  // Convert byte offset to bit shift
1157  SDValue ShiftAmt = DAG.getNode(ISD::SHL, DL, MVT::i32, ByteIdx,
1158  DAG.getConstant(3, DL, MVT::i32));
1159 
1160  // TODO: Contrary to the name of the functiom,
1161  // it also handles sub i32 non-truncating stores (like i1)
1162  SDValue SExtValue = DAG.getNode(ISD::SIGN_EXTEND, DL, MVT::i32,
1163  Store->getValue());
1164 
1165  // Mask the value to the right type
1166  SDValue MaskedValue = DAG.getZeroExtendInReg(SExtValue, DL, MemVT);
1167 
1168  // Shift the value in place
1169  SDValue ShiftedValue = DAG.getNode(ISD::SHL, DL, MVT::i32,
1170  MaskedValue, ShiftAmt);
1171 
1172  // Shift the mask in place
1173  SDValue DstMask = DAG.getNode(ISD::SHL, DL, MVT::i32, Mask, ShiftAmt);
1174 
1175  // Invert the mask. NOTE: if we had native ROL instructions we could
1176  // use inverted mask
1177  DstMask = DAG.getNOT(DL, DstMask, MVT::i32);
1178 
1179  // Cleanup the target bits
1180  Dst = DAG.getNode(ISD::AND, DL, MVT::i32, Dst, DstMask);
1181 
1182  // Add the new bits
1183  SDValue Value = DAG.getNode(ISD::OR, DL, MVT::i32, Dst, ShiftedValue);
1184 
1185  // Store dword
1186  // TODO: Can we be smarter about MachinePointerInfo?
1187  SDValue NewStore = DAG.getStore(Chain, DL, Value, Ptr, MachinePointerInfo());
1188 
1189  // If we are part of expanded vector, make our neighbors depend on this store
1190  if (VectorTrunc) {
1191  // Make all other vector elements depend on this store
1192  Chain = DAG.getNode(AMDGPUISD::DUMMY_CHAIN, DL, MVT::Other, NewStore);
1193  DAG.ReplaceAllUsesOfValueWith(OldChain, Chain);
1194  }
1195  return NewStore;
1196 }
1197 
1198 SDValue R600TargetLowering::LowerSTORE(SDValue Op, SelectionDAG &DAG) const {
1199  StoreSDNode *StoreNode = cast<StoreSDNode>(Op);
1200  unsigned AS = StoreNode->getAddressSpace();
1201 
1202  SDValue Chain = StoreNode->getChain();
1203  SDValue Ptr = StoreNode->getBasePtr();
1204  SDValue Value = StoreNode->getValue();
1205 
1206  EVT VT = Value.getValueType();
1207  EVT MemVT = StoreNode->getMemoryVT();
1208  EVT PtrVT = Ptr.getValueType();
1209 
1210  SDLoc DL(Op);
1211 
1212  // Neither LOCAL nor PRIVATE can do vectors at the moment
1213  if ((AS == AMDGPUASI.LOCAL_ADDRESS || AS == AMDGPUASI.PRIVATE_ADDRESS) &&
1214  VT.isVector()) {
1215  if ((AS == AMDGPUASI.PRIVATE_ADDRESS) &&
1216  StoreNode->isTruncatingStore()) {
1217  // Add an extra level of chain to isolate this vector
1218  SDValue NewChain = DAG.getNode(AMDGPUISD::DUMMY_CHAIN, DL, MVT::Other, Chain);
1219  // TODO: can the chain be replaced without creating a new store?
1220  SDValue NewStore = DAG.getTruncStore(
1221  NewChain, DL, Value, Ptr, StoreNode->getPointerInfo(),
1222  MemVT, StoreNode->getAlignment(),
1223  StoreNode->getMemOperand()->getFlags(), StoreNode->getAAInfo());
1224  StoreNode = cast<StoreSDNode>(NewStore);
1225  }
1226 
1227  return scalarizeVectorStore(StoreNode, DAG);
1228  }
1229 
1230  unsigned Align = StoreNode->getAlignment();
1231  if (Align < MemVT.getStoreSize() &&
1232  !allowsMisalignedMemoryAccesses(MemVT, AS, Align, nullptr)) {
1233  return expandUnalignedStore(StoreNode, DAG);
1234  }
1235 
1236  SDValue DWordAddr = DAG.getNode(ISD::SRL, DL, PtrVT, Ptr,
1237  DAG.getConstant(2, DL, PtrVT));
1238 
1239  if (AS == AMDGPUASI.GLOBAL_ADDRESS) {
1240  // It is beneficial to create MSKOR here instead of combiner to avoid
1241  // artificial dependencies introduced by RMW
1242  if (StoreNode->isTruncatingStore()) {
1243  assert(VT.bitsLE(MVT::i32));
1244  SDValue MaskConstant;
1245  if (MemVT == MVT::i8) {
1246  MaskConstant = DAG.getConstant(0xFF, DL, MVT::i32);
1247  } else {
1248  assert(MemVT == MVT::i16);
1249  assert(StoreNode->getAlignment() >= 2);
1250  MaskConstant = DAG.getConstant(0xFFFF, DL, MVT::i32);
1251  }
1252 
1253  SDValue ByteIndex = DAG.getNode(ISD::AND, DL, PtrVT, Ptr,
1254  DAG.getConstant(0x00000003, DL, PtrVT));
1255  SDValue BitShift = DAG.getNode(ISD::SHL, DL, VT, ByteIndex,
1256  DAG.getConstant(3, DL, VT));
1257 
1258  // Put the mask in correct place
1259  SDValue Mask = DAG.getNode(ISD::SHL, DL, VT, MaskConstant, BitShift);
1260 
1261  // Put the value bits in correct place
1262  SDValue TruncValue = DAG.getNode(ISD::AND, DL, VT, Value, MaskConstant);
1263  SDValue ShiftedValue = DAG.getNode(ISD::SHL, DL, VT, TruncValue, BitShift);
1264 
1265  // XXX: If we add a 64-bit ZW register class, then we could use a 2 x i32
1266  // vector instead.
1267  SDValue Src[4] = {
1268  ShiftedValue,
1269  DAG.getConstant(0, DL, MVT::i32),
1270  DAG.getConstant(0, DL, MVT::i32),
1271  Mask
1272  };
1273  SDValue Input = DAG.getBuildVector(MVT::v4i32, DL, Src);
1274  SDValue Args[3] = { Chain, Input, DWordAddr };
1276  Op->getVTList(), Args, MemVT,
1277  StoreNode->getMemOperand());
1278  } else if (Ptr->getOpcode() != AMDGPUISD::DWORDADDR && VT.bitsGE(MVT::i32)) {
1279  // Convert pointer from byte address to dword address.
1280  Ptr = DAG.getNode(AMDGPUISD::DWORDADDR, DL, PtrVT, DWordAddr);
1281 
1282  if (StoreNode->isTruncatingStore() || StoreNode->isIndexed()) {
1283  llvm_unreachable("Truncated and indexed stores not supported yet");
1284  } else {
1285  Chain = DAG.getStore(Chain, DL, Value, Ptr, StoreNode->getMemOperand());
1286  }
1287  return Chain;
1288  }
1289  }
1290 
1291  // GLOBAL_ADDRESS has been handled above, LOCAL_ADDRESS allows all sizes
1292  if (AS != AMDGPUASI.PRIVATE_ADDRESS)
1293  return SDValue();
1294 
1295  if (MemVT.bitsLT(MVT::i32))
1296  return lowerPrivateTruncStore(StoreNode, DAG);
1297 
1298  // Standard i32+ store, tag it with DWORDADDR to note that the address
1299  // has been shifted
1300  if (Ptr.getOpcode() != AMDGPUISD::DWORDADDR) {
1301  Ptr = DAG.getNode(AMDGPUISD::DWORDADDR, DL, PtrVT, DWordAddr);
1302  return DAG.getStore(Chain, DL, Value, Ptr, StoreNode->getMemOperand());
1303  }
1304 
1305  // Tagged i32+ stores will be matched by patterns
1306  return SDValue();
1307 }
1308 
1309 // return (512 + (kc_bank << 12)
1310 static int
1312  switch (AddressSpace) {
1313  case AMDGPUASI.CONSTANT_BUFFER_0:
1314  return 512;
1315  case AMDGPUASI.CONSTANT_BUFFER_1:
1316  return 512 + 4096;
1317  case AMDGPUASI.CONSTANT_BUFFER_2:
1318  return 512 + 4096 * 2;
1319  case AMDGPUASI.CONSTANT_BUFFER_3:
1320  return 512 + 4096 * 3;
1321  case AMDGPUASI.CONSTANT_BUFFER_4:
1322  return 512 + 4096 * 4;
1323  case AMDGPUASI.CONSTANT_BUFFER_5:
1324  return 512 + 4096 * 5;
1325  case AMDGPUASI.CONSTANT_BUFFER_6:
1326  return 512 + 4096 * 6;
1327  case AMDGPUASI.CONSTANT_BUFFER_7:
1328  return 512 + 4096 * 7;
1329  case AMDGPUASI.CONSTANT_BUFFER_8:
1330  return 512 + 4096 * 8;
1331  case AMDGPUASI.CONSTANT_BUFFER_9:
1332  return 512 + 4096 * 9;
1333  case AMDGPUASI.CONSTANT_BUFFER_10:
1334  return 512 + 4096 * 10;
1335  case AMDGPUASI.CONSTANT_BUFFER_11:
1336  return 512 + 4096 * 11;
1337  case AMDGPUASI.CONSTANT_BUFFER_12:
1338  return 512 + 4096 * 12;
1339  case AMDGPUASI.CONSTANT_BUFFER_13:
1340  return 512 + 4096 * 13;
1341  case AMDGPUASI.CONSTANT_BUFFER_14:
1342  return 512 + 4096 * 14;
1343  case AMDGPUASI.CONSTANT_BUFFER_15:
1344  return 512 + 4096 * 15;
1345  default:
1346  return -1;
1347  }
1348 }
1349 
1350 SDValue R600TargetLowering::lowerPrivateExtLoad(SDValue Op,
1351  SelectionDAG &DAG) const {
1352  SDLoc DL(Op);
1353  LoadSDNode *Load = cast<LoadSDNode>(Op);
1354  ISD::LoadExtType ExtType = Load->getExtensionType();
1355  EVT MemVT = Load->getMemoryVT();
1356  assert(Load->getAlignment() >= MemVT.getStoreSize());
1357 
1358  SDValue BasePtr = Load->getBasePtr();
1359  SDValue Chain = Load->getChain();
1360  SDValue Offset = Load->getOffset();
1361 
1362  SDValue LoadPtr = BasePtr;
1363  if (!Offset.isUndef()) {
1364  LoadPtr = DAG.getNode(ISD::ADD, DL, MVT::i32, BasePtr, Offset);
1365  }
1366 
1367  // Get dword location
1368  // NOTE: this should be eliminated by the future SHR ptr, 2
1369  SDValue Ptr = DAG.getNode(ISD::AND, DL, MVT::i32, LoadPtr,
1370  DAG.getConstant(0xfffffffc, DL, MVT::i32));
1371 
1372  // Load dword
1373  // TODO: can we be smarter about machine pointer info?
1374  SDValue Read = DAG.getLoad(MVT::i32, DL, Chain, Ptr, MachinePointerInfo());
1375 
1376  // Get offset within the register.
1377  SDValue ByteIdx = DAG.getNode(ISD::AND, DL, MVT::i32,
1378  LoadPtr, DAG.getConstant(0x3, DL, MVT::i32));
1379 
1380  // Bit offset of target byte (byteIdx * 8).
1381  SDValue ShiftAmt = DAG.getNode(ISD::SHL, DL, MVT::i32, ByteIdx,
1382  DAG.getConstant(3, DL, MVT::i32));
1383 
1384  // Shift to the right.
1385  SDValue Ret = DAG.getNode(ISD::SRL, DL, MVT::i32, Read, ShiftAmt);
1386 
1387  // Eliminate the upper bits by setting them to ...
1388  EVT MemEltVT = MemVT.getScalarType();
1389 
1390  if (ExtType == ISD::SEXTLOAD) { // ... ones.
1391  SDValue MemEltVTNode = DAG.getValueType(MemEltVT);
1392  Ret = DAG.getNode(ISD::SIGN_EXTEND_INREG, DL, MVT::i32, Ret, MemEltVTNode);
1393  } else { // ... or zeros.
1394  Ret = DAG.getZeroExtendInReg(Ret, DL, MemEltVT);
1395  }
1396 
1397  SDValue Ops[] = {
1398  Ret,
1399  Read.getValue(1) // This should be our output chain
1400  };
1401 
1402  return DAG.getMergeValues(Ops, DL);
1403 }
1404 
1405 SDValue R600TargetLowering::LowerLOAD(SDValue Op, SelectionDAG &DAG) const {
1406  LoadSDNode *LoadNode = cast<LoadSDNode>(Op);
1407  unsigned AS = LoadNode->getAddressSpace();
1408  EVT MemVT = LoadNode->getMemoryVT();
1409  ISD::LoadExtType ExtType = LoadNode->getExtensionType();
1410 
1411  if (AS == AMDGPUASI.PRIVATE_ADDRESS &&
1412  ExtType != ISD::NON_EXTLOAD && MemVT.bitsLT(MVT::i32)) {
1413  return lowerPrivateExtLoad(Op, DAG);
1414  }
1415 
1416  SDLoc DL(Op);
1417  EVT VT = Op.getValueType();
1418  SDValue Chain = LoadNode->getChain();
1419  SDValue Ptr = LoadNode->getBasePtr();
1420 
1421  if ((LoadNode->getAddressSpace() == AMDGPUASI.LOCAL_ADDRESS ||
1422  LoadNode->getAddressSpace() == AMDGPUASI.PRIVATE_ADDRESS) &&
1423  VT.isVector()) {
1424  return scalarizeVectorLoad(LoadNode, DAG);
1425  }
1426 
1427  int ConstantBlock = ConstantAddressBlock(LoadNode->getAddressSpace(),
1428  AMDGPUASI);
1429  if (ConstantBlock > -1 &&
1430  ((LoadNode->getExtensionType() == ISD::NON_EXTLOAD) ||
1431  (LoadNode->getExtensionType() == ISD::ZEXTLOAD))) {
1432  SDValue Result;
1433  if (isa<ConstantExpr>(LoadNode->getMemOperand()->getValue()) ||
1434  isa<Constant>(LoadNode->getMemOperand()->getValue()) ||
1435  isa<ConstantSDNode>(Ptr)) {
1436  SDValue Slots[4];
1437  for (unsigned i = 0; i < 4; i++) {
1438  // We want Const position encoded with the following formula :
1439  // (((512 + (kc_bank << 12) + const_index) << 2) + chan)
1440  // const_index is Ptr computed by llvm using an alignment of 16.
1441  // Thus we add (((512 + (kc_bank << 12)) + chan ) * 4 here and
1442  // then div by 4 at the ISel step
1443  SDValue NewPtr = DAG.getNode(ISD::ADD, DL, Ptr.getValueType(), Ptr,
1444  DAG.getConstant(4 * i + ConstantBlock * 16, DL, MVT::i32));
1445  Slots[i] = DAG.getNode(AMDGPUISD::CONST_ADDRESS, DL, MVT::i32, NewPtr);
1446  }
1447  EVT NewVT = MVT::v4i32;
1448  unsigned NumElements = 4;
1449  if (VT.isVector()) {
1450  NewVT = VT;
1451  NumElements = VT.getVectorNumElements();
1452  }
1453  Result = DAG.getBuildVector(NewVT, DL, makeArrayRef(Slots, NumElements));
1454  } else {
1455  // non-constant ptr can't be folded, keeps it as a v4f32 load
1456  Result = DAG.getNode(AMDGPUISD::CONST_ADDRESS, DL, MVT::v4i32,
1457  DAG.getNode(ISD::SRL, DL, MVT::i32, Ptr,
1458  DAG.getConstant(4, DL, MVT::i32)),
1459  DAG.getConstant(LoadNode->getAddressSpace() -
1461  );
1462  }
1463 
1464  if (!VT.isVector()) {
1465  Result = DAG.getNode(ISD::EXTRACT_VECTOR_ELT, DL, MVT::i32, Result,
1466  DAG.getConstant(0, DL, MVT::i32));
1467  }
1468 
1469  SDValue MergedValues[2] = {
1470  Result,
1471  Chain
1472  };
1473  return DAG.getMergeValues(MergedValues, DL);
1474  }
1475 
1476  // For most operations returning SDValue() will result in the node being
1477  // expanded by the DAG Legalizer. This is not the case for ISD::LOAD, so we
1478  // need to manually expand loads that may be legal in some address spaces and
1479  // illegal in others. SEXT loads from CONSTANT_BUFFER_0 are supported for
1480  // compute shaders, since the data is sign extended when it is uploaded to the
1481  // buffer. However SEXT loads from other address spaces are not supported, so
1482  // we need to expand them here.
1483  if (LoadNode->getExtensionType() == ISD::SEXTLOAD) {
1484  EVT MemVT = LoadNode->getMemoryVT();
1485  assert(!MemVT.isVector() && (MemVT == MVT::i16 || MemVT == MVT::i8));
1486  SDValue NewLoad = DAG.getExtLoad(
1487  ISD::EXTLOAD, DL, VT, Chain, Ptr, LoadNode->getPointerInfo(), MemVT,
1488  LoadNode->getAlignment(), LoadNode->getMemOperand()->getFlags());
1489  SDValue Res = DAG.getNode(ISD::SIGN_EXTEND_INREG, DL, VT, NewLoad,
1490  DAG.getValueType(MemVT));
1491 
1492  SDValue MergedValues[2] = { Res, Chain };
1493  return DAG.getMergeValues(MergedValues, DL);
1494  }
1495 
1496  if (LoadNode->getAddressSpace() != AMDGPUASI.PRIVATE_ADDRESS) {
1497  return SDValue();
1498  }
1499 
1500  // DWORDADDR ISD marks already shifted address
1501  if (Ptr.getOpcode() != AMDGPUISD::DWORDADDR) {
1502  assert(VT == MVT::i32);
1503  Ptr = DAG.getNode(ISD::SRL, DL, MVT::i32, Ptr, DAG.getConstant(2, DL, MVT::i32));
1504  Ptr = DAG.getNode(AMDGPUISD::DWORDADDR, DL, MVT::i32, Ptr);
1505  return DAG.getLoad(MVT::i32, DL, Chain, Ptr, LoadNode->getMemOperand());
1506  }
1507  return SDValue();
1508 }
1509 
1510 SDValue R600TargetLowering::LowerBRCOND(SDValue Op, SelectionDAG &DAG) const {
1511  SDValue Chain = Op.getOperand(0);
1512  SDValue Cond = Op.getOperand(1);
1513  SDValue Jump = Op.getOperand(2);
1514 
1515  return DAG.getNode(AMDGPUISD::BRANCH_COND, SDLoc(Op), Op.getValueType(),
1516  Chain, Jump, Cond);
1517 }
1518 
1519 SDValue R600TargetLowering::lowerFrameIndex(SDValue Op,
1520  SelectionDAG &DAG) const {
1521  MachineFunction &MF = DAG.getMachineFunction();
1523 
1524  FrameIndexSDNode *FIN = cast<FrameIndexSDNode>(Op);
1525 
1526  unsigned FrameIndex = FIN->getIndex();
1527  unsigned IgnoredFrameReg;
1528  unsigned Offset =
1529  TFL->getFrameIndexReference(MF, FrameIndex, IgnoredFrameReg);
1530  return DAG.getConstant(Offset * 4 * TFL->getStackWidth(MF), SDLoc(Op),
1531  Op.getValueType());
1532 }
1533 
1534 /// XXX Only kernel functions are supported, so we can assume for now that
1535 /// every function is a kernel function, but in the future we should use
1536 /// separate calling conventions for kernel and non-kernel functions.
1538  SDValue Chain, CallingConv::ID CallConv, bool isVarArg,
1539  const SmallVectorImpl<ISD::InputArg> &Ins, const SDLoc &DL,
1540  SelectionDAG &DAG, SmallVectorImpl<SDValue> &InVals) const {
1542  CCState CCInfo(CallConv, isVarArg, DAG.getMachineFunction(), ArgLocs,
1543  *DAG.getContext());
1544  MachineFunction &MF = DAG.getMachineFunction();
1545  R600MachineFunctionInfo *MFI = MF.getInfo<R600MachineFunctionInfo>();
1546 
1548 
1549  if (AMDGPU::isShader(CallConv)) {
1550  CCInfo.AnalyzeFormalArguments(Ins, CCAssignFnForCall(CallConv, isVarArg));
1551  } else {
1552  analyzeFormalArgumentsCompute(CCInfo, Ins);
1553  }
1554 
1555  for (unsigned i = 0, e = Ins.size(); i < e; ++i) {
1556  CCValAssign &VA = ArgLocs[i];
1557  const ISD::InputArg &In = Ins[i];
1558  EVT VT = In.VT;
1559  EVT MemVT = VA.getLocVT();
1560  if (!VT.isVector() && MemVT.isVector()) {
1561  // Get load source type if scalarized.
1562  MemVT = MemVT.getVectorElementType();
1563  }
1564 
1565  if (AMDGPU::isShader(CallConv)) {
1566  unsigned Reg = MF.addLiveIn(VA.getLocReg(), &AMDGPU::R600_Reg128RegClass);
1567  SDValue Register = DAG.getCopyFromReg(Chain, DL, Reg, VT);
1568  InVals.push_back(Register);
1569  continue;
1570  }
1571 
1574 
1575  // i64 isn't a legal type, so the register type used ends up as i32, which
1576  // isn't expected here. It attempts to create this sextload, but it ends up
1577  // being invalid. Somehow this seems to work with i64 arguments, but breaks
1578  // for <1 x i64>.
1579 
1580  // The first 36 bytes of the input buffer contains information about
1581  // thread group and global sizes.
1583  if (MemVT.getScalarSizeInBits() != VT.getScalarSizeInBits()) {
1584  // FIXME: This should really check the extload type, but the handling of
1585  // extload vector parameters seems to be broken.
1586 
1587  // Ext = In.Flags.isSExt() ? ISD::SEXTLOAD : ISD::ZEXTLOAD;
1588  Ext = ISD::SEXTLOAD;
1589  }
1590 
1591  // Compute the offset from the value.
1592  // XXX - I think PartOffset should give you this, but it seems to give the
1593  // size of the register which isn't useful.
1594 
1595  unsigned ValBase = ArgLocs[In.getOrigArgIndex()].getLocMemOffset();
1596  unsigned PartOffset = VA.getLocMemOffset();
1597  unsigned Offset = Subtarget->getExplicitKernelArgOffset(MF) + VA.getLocMemOffset();
1598 
1599  MachinePointerInfo PtrInfo(UndefValue::get(PtrTy), PartOffset - ValBase);
1600  SDValue Arg = DAG.getLoad(
1601  ISD::UNINDEXED, Ext, VT, DL, Chain,
1602  DAG.getConstant(Offset, DL, MVT::i32), DAG.getUNDEF(MVT::i32), PtrInfo,
1603  MemVT, /* Alignment = */ 4, MachineMemOperand::MONonTemporal |
1606 
1607  // 4 is the preferred alignment for the CONSTANT memory space.
1608  InVals.push_back(Arg);
1609  MFI->setABIArgOffset(Offset + MemVT.getStoreSize());
1610  }
1611  return Chain;
1612 }
1613 
1615  EVT VT) const {
1616  if (!VT.isVector())
1617  return MVT::i32;
1619 }
1620 
1622  const SelectionDAG &DAG) const {
1623  // Local and Private addresses do not handle vectors. Limit to i32
1624  if ((AS == AMDGPUASI.LOCAL_ADDRESS || AS == AMDGPUASI.PRIVATE_ADDRESS)) {
1625  return (MemVT.getSizeInBits() <= 32);
1626  }
1627  return true;
1628 }
1629 
1631  unsigned AddrSpace,
1632  unsigned Align,
1633  bool *IsFast) const {
1634  if (IsFast)
1635  *IsFast = false;
1636 
1637  if (!VT.isSimple() || VT == MVT::Other)
1638  return false;
1639 
1640  if (VT.bitsLT(MVT::i32))
1641  return false;
1642 
1643  // TODO: This is a rough estimate.
1644  if (IsFast)
1645  *IsFast = true;
1646 
1647  return VT.bitsGT(MVT::i32) && Align % 4 == 0;
1648 }
1649 
1651  SelectionDAG &DAG, SDValue VectorEntry,
1652  DenseMap<unsigned, unsigned> &RemapSwizzle) {
1653  assert(VectorEntry.getOpcode() == ISD::BUILD_VECTOR);
1654  assert(RemapSwizzle.empty());
1655  SDValue NewBldVec[4] = {
1656  VectorEntry.getOperand(0),
1657  VectorEntry.getOperand(1),
1658  VectorEntry.getOperand(2),
1659  VectorEntry.getOperand(3)
1660  };
1661 
1662  for (unsigned i = 0; i < 4; i++) {
1663  if (NewBldVec[i].isUndef())
1664  // We mask write here to teach later passes that the ith element of this
1665  // vector is undef. Thus we can use it to reduce 128 bits reg usage,
1666  // break false dependencies and additionnaly make assembly easier to read.
1667  RemapSwizzle[i] = 7; // SEL_MASK_WRITE
1668  if (ConstantFPSDNode *C = dyn_cast<ConstantFPSDNode>(NewBldVec[i])) {
1669  if (C->isZero()) {
1670  RemapSwizzle[i] = 4; // SEL_0
1671  NewBldVec[i] = DAG.getUNDEF(MVT::f32);
1672  } else if (C->isExactlyValue(1.0)) {
1673  RemapSwizzle[i] = 5; // SEL_1
1674  NewBldVec[i] = DAG.getUNDEF(MVT::f32);
1675  }
1676  }
1677 
1678  if (NewBldVec[i].isUndef())
1679  continue;
1680  for (unsigned j = 0; j < i; j++) {
1681  if (NewBldVec[i] == NewBldVec[j]) {
1682  NewBldVec[i] = DAG.getUNDEF(NewBldVec[i].getValueType());
1683  RemapSwizzle[i] = j;
1684  break;
1685  }
1686  }
1687  }
1688 
1689  return DAG.getBuildVector(VectorEntry.getValueType(), SDLoc(VectorEntry),
1690  NewBldVec);
1691 }
1692 
1694  DenseMap<unsigned, unsigned> &RemapSwizzle) {
1695  assert(VectorEntry.getOpcode() == ISD::BUILD_VECTOR);
1696  assert(RemapSwizzle.empty());
1697  SDValue NewBldVec[4] = {
1698  VectorEntry.getOperand(0),
1699  VectorEntry.getOperand(1),
1700  VectorEntry.getOperand(2),
1701  VectorEntry.getOperand(3)
1702  };
1703  bool isUnmovable[4] = { false, false, false, false };
1704  for (unsigned i = 0; i < 4; i++) {
1705  RemapSwizzle[i] = i;
1706  if (NewBldVec[i].getOpcode() == ISD::EXTRACT_VECTOR_ELT) {
1707  unsigned Idx = dyn_cast<ConstantSDNode>(NewBldVec[i].getOperand(1))
1708  ->getZExtValue();
1709  if (i == Idx)
1710  isUnmovable[Idx] = true;
1711  }
1712  }
1713 
1714  for (unsigned i = 0; i < 4; i++) {
1715  if (NewBldVec[i].getOpcode() == ISD::EXTRACT_VECTOR_ELT) {
1716  unsigned Idx = dyn_cast<ConstantSDNode>(NewBldVec[i].getOperand(1))
1717  ->getZExtValue();
1718  if (isUnmovable[Idx])
1719  continue;
1720  // Swap i and Idx
1721  std::swap(NewBldVec[Idx], NewBldVec[i]);
1722  std::swap(RemapSwizzle[i], RemapSwizzle[Idx]);
1723  break;
1724  }
1725  }
1726 
1727  return DAG.getBuildVector(VectorEntry.getValueType(), SDLoc(VectorEntry),
1728  NewBldVec);
1729 }
1730 
1731 SDValue R600TargetLowering::OptimizeSwizzle(SDValue BuildVector, SDValue Swz[4],
1732  SelectionDAG &DAG,
1733  const SDLoc &DL) const {
1734  assert(BuildVector.getOpcode() == ISD::BUILD_VECTOR);
1735  // Old -> New swizzle values
1736  DenseMap<unsigned, unsigned> SwizzleRemap;
1737 
1738  BuildVector = CompactSwizzlableVector(DAG, BuildVector, SwizzleRemap);
1739  for (unsigned i = 0; i < 4; i++) {
1740  unsigned Idx = cast<ConstantSDNode>(Swz[i])->getZExtValue();
1741  if (SwizzleRemap.find(Idx) != SwizzleRemap.end())
1742  Swz[i] = DAG.getConstant(SwizzleRemap[Idx], DL, MVT::i32);
1743  }
1744 
1745  SwizzleRemap.clear();
1746  BuildVector = ReorganizeVector(DAG, BuildVector, SwizzleRemap);
1747  for (unsigned i = 0; i < 4; i++) {
1748  unsigned Idx = cast<ConstantSDNode>(Swz[i])->getZExtValue();
1749  if (SwizzleRemap.find(Idx) != SwizzleRemap.end())
1750  Swz[i] = DAG.getConstant(SwizzleRemap[Idx], DL, MVT::i32);
1751  }
1752 
1753  return BuildVector;
1754 }
1755 
1756 //===----------------------------------------------------------------------===//
1757 // Custom DAG Optimizations
1758 //===----------------------------------------------------------------------===//
1759 
1761  DAGCombinerInfo &DCI) const {
1762  SelectionDAG &DAG = DCI.DAG;
1763  SDLoc DL(N);
1764 
1765  switch (N->getOpcode()) {
1766  // (f32 fp_round (f64 uint_to_fp a)) -> (f32 uint_to_fp a)
1767  case ISD::FP_ROUND: {
1768  SDValue Arg = N->getOperand(0);
1769  if (Arg.getOpcode() == ISD::UINT_TO_FP && Arg.getValueType() == MVT::f64) {
1770  return DAG.getNode(ISD::UINT_TO_FP, DL, N->getValueType(0),
1771  Arg.getOperand(0));
1772  }
1773  break;
1774  }
1775 
1776  // (i32 fp_to_sint (fneg (select_cc f32, f32, 1.0, 0.0 cc))) ->
1777  // (i32 select_cc f32, f32, -1, 0 cc)
1778  //
1779  // Mesa's GLSL frontend generates the above pattern a lot and we can lower
1780  // this to one of the SET*_DX10 instructions.
1781  case ISD::FP_TO_SINT: {
1782  SDValue FNeg = N->getOperand(0);
1783  if (FNeg.getOpcode() != ISD::FNEG) {
1784  return SDValue();
1785  }
1786  SDValue SelectCC = FNeg.getOperand(0);
1787  if (SelectCC.getOpcode() != ISD::SELECT_CC ||
1788  SelectCC.getOperand(0).getValueType() != MVT::f32 || // LHS
1789  SelectCC.getOperand(2).getValueType() != MVT::f32 || // True
1790  !isHWTrueValue(SelectCC.getOperand(2)) ||
1791  !isHWFalseValue(SelectCC.getOperand(3))) {
1792  return SDValue();
1793  }
1794 
1795  return DAG.getNode(ISD::SELECT_CC, DL, N->getValueType(0),
1796  SelectCC.getOperand(0), // LHS
1797  SelectCC.getOperand(1), // RHS
1798  DAG.getConstant(-1, DL, MVT::i32), // True
1799  DAG.getConstant(0, DL, MVT::i32), // False
1800  SelectCC.getOperand(4)); // CC
1801 
1802  break;
1803  }
1804 
1805  // insert_vector_elt (build_vector elt0, ... , eltN), NewEltIdx, idx
1806  // => build_vector elt0, ... , NewEltIdx, ... , eltN
1807  case ISD::INSERT_VECTOR_ELT: {
1808  SDValue InVec = N->getOperand(0);
1809  SDValue InVal = N->getOperand(1);
1810  SDValue EltNo = N->getOperand(2);
1811 
1812  // If the inserted element is an UNDEF, just use the input vector.
1813  if (InVal.isUndef())
1814  return InVec;
1815 
1816  EVT VT = InVec.getValueType();
1817 
1818  // If we can't generate a legal BUILD_VECTOR, exit
1820  return SDValue();
1821 
1822  // Check that we know which element is being inserted
1823  if (!isa<ConstantSDNode>(EltNo))
1824  return SDValue();
1825  unsigned Elt = cast<ConstantSDNode>(EltNo)->getZExtValue();
1826 
1827  // Check that the operand is a BUILD_VECTOR (or UNDEF, which can essentially
1828  // be converted to a BUILD_VECTOR). Fill in the Ops vector with the
1829  // vector elements.
1831  if (InVec.getOpcode() == ISD::BUILD_VECTOR) {
1832  Ops.append(InVec.getNode()->op_begin(),
1833  InVec.getNode()->op_end());
1834  } else if (InVec.isUndef()) {
1835  unsigned NElts = VT.getVectorNumElements();
1836  Ops.append(NElts, DAG.getUNDEF(InVal.getValueType()));
1837  } else {
1838  return SDValue();
1839  }
1840 
1841  // Insert the element
1842  if (Elt < Ops.size()) {
1843  // All the operands of BUILD_VECTOR must have the same type;
1844  // we enforce that here.
1845  EVT OpVT = Ops[0].getValueType();
1846  if (InVal.getValueType() != OpVT)
1847  InVal = OpVT.bitsGT(InVal.getValueType()) ?
1848  DAG.getNode(ISD::ANY_EXTEND, DL, OpVT, InVal) :
1849  DAG.getNode(ISD::TRUNCATE, DL, OpVT, InVal);
1850  Ops[Elt] = InVal;
1851  }
1852 
1853  // Return the new vector
1854  return DAG.getBuildVector(VT, DL, Ops);
1855  }
1856 
1857  // Extract_vec (Build_vector) generated by custom lowering
1858  // also needs to be customly combined
1859  case ISD::EXTRACT_VECTOR_ELT: {
1860  SDValue Arg = N->getOperand(0);
1861  if (Arg.getOpcode() == ISD::BUILD_VECTOR) {
1862  if (ConstantSDNode *Const = dyn_cast<ConstantSDNode>(N->getOperand(1))) {
1863  unsigned Element = Const->getZExtValue();
1864  return Arg->getOperand(Element);
1865  }
1866  }
1867  if (Arg.getOpcode() == ISD::BITCAST &&
1868  Arg.getOperand(0).getOpcode() == ISD::BUILD_VECTOR &&
1871  if (ConstantSDNode *Const = dyn_cast<ConstantSDNode>(N->getOperand(1))) {
1872  unsigned Element = Const->getZExtValue();
1873  return DAG.getNode(ISD::BITCAST, DL, N->getVTList(),
1874  Arg->getOperand(0).getOperand(Element));
1875  }
1876  }
1877  break;
1878  }
1879 
1880  case ISD::SELECT_CC: {
1881  // Try common optimizations
1883  return Ret;
1884 
1885  // fold selectcc (selectcc x, y, a, b, cc), b, a, b, seteq ->
1886  // selectcc x, y, a, b, inv(cc)
1887  //
1888  // fold selectcc (selectcc x, y, a, b, cc), b, a, b, setne ->
1889  // selectcc x, y, a, b, cc
1890  SDValue LHS = N->getOperand(0);
1891  if (LHS.getOpcode() != ISD::SELECT_CC) {
1892  return SDValue();
1893  }
1894 
1895  SDValue RHS = N->getOperand(1);
1896  SDValue True = N->getOperand(2);
1897  SDValue False = N->getOperand(3);
1898  ISD::CondCode NCC = cast<CondCodeSDNode>(N->getOperand(4))->get();
1899 
1900  if (LHS.getOperand(2).getNode() != True.getNode() ||
1901  LHS.getOperand(3).getNode() != False.getNode() ||
1902  RHS.getNode() != False.getNode()) {
1903  return SDValue();
1904  }
1905 
1906  switch (NCC) {
1907  default: return SDValue();
1908  case ISD::SETNE: return LHS;
1909  case ISD::SETEQ: {
1910  ISD::CondCode LHSCC = cast<CondCodeSDNode>(LHS.getOperand(4))->get();
1911  LHSCC = ISD::getSetCCInverse(LHSCC,
1912  LHS.getOperand(0).getValueType().isInteger());
1913  if (DCI.isBeforeLegalizeOps() ||
1915  return DAG.getSelectCC(DL,
1916  LHS.getOperand(0),
1917  LHS.getOperand(1),
1918  LHS.getOperand(2),
1919  LHS.getOperand(3),
1920  LHSCC);
1921  break;
1922  }
1923  }
1924  return SDValue();
1925  }
1926 
1927  case AMDGPUISD::R600_EXPORT: {
1928  SDValue Arg = N->getOperand(1);
1929  if (Arg.getOpcode() != ISD::BUILD_VECTOR)
1930  break;
1931 
1932  SDValue NewArgs[8] = {
1933  N->getOperand(0), // Chain
1934  SDValue(),
1935  N->getOperand(2), // ArrayBase
1936  N->getOperand(3), // Type
1937  N->getOperand(4), // SWZ_X
1938  N->getOperand(5), // SWZ_Y
1939  N->getOperand(6), // SWZ_Z
1940  N->getOperand(7) // SWZ_W
1941  };
1942  NewArgs[1] = OptimizeSwizzle(N->getOperand(1), &NewArgs[4], DAG, DL);
1943  return DAG.getNode(AMDGPUISD::R600_EXPORT, DL, N->getVTList(), NewArgs);
1944  }
1945  case AMDGPUISD::TEXTURE_FETCH: {
1946  SDValue Arg = N->getOperand(1);
1947  if (Arg.getOpcode() != ISD::BUILD_VECTOR)
1948  break;
1949 
1950  SDValue NewArgs[19] = {
1951  N->getOperand(0),
1952  N->getOperand(1),
1953  N->getOperand(2),
1954  N->getOperand(3),
1955  N->getOperand(4),
1956  N->getOperand(5),
1957  N->getOperand(6),
1958  N->getOperand(7),
1959  N->getOperand(8),
1960  N->getOperand(9),
1961  N->getOperand(10),
1962  N->getOperand(11),
1963  N->getOperand(12),
1964  N->getOperand(13),
1965  N->getOperand(14),
1966  N->getOperand(15),
1967  N->getOperand(16),
1968  N->getOperand(17),
1969  N->getOperand(18),
1970  };
1971  NewArgs[1] = OptimizeSwizzle(N->getOperand(1), &NewArgs[2], DAG, DL);
1972  return DAG.getNode(AMDGPUISD::TEXTURE_FETCH, DL, N->getVTList(), NewArgs);
1973  }
1974  default: break;
1975  }
1976 
1978 }
1979 
1980 bool R600TargetLowering::FoldOperand(SDNode *ParentNode, unsigned SrcIdx,
1981  SDValue &Src, SDValue &Neg, SDValue &Abs,
1982  SDValue &Sel, SDValue &Imm,
1983  SelectionDAG &DAG) const {
1985  if (!Src.isMachineOpcode())
1986  return false;
1987 
1988  switch (Src.getMachineOpcode()) {
1989  case AMDGPU::FNEG_R600:
1990  if (!Neg.getNode())
1991  return false;
1992  Src = Src.getOperand(0);
1993  Neg = DAG.getTargetConstant(1, SDLoc(ParentNode), MVT::i32);
1994  return true;
1995  case AMDGPU::FABS_R600:
1996  if (!Abs.getNode())
1997  return false;
1998  Src = Src.getOperand(0);
1999  Abs = DAG.getTargetConstant(1, SDLoc(ParentNode), MVT::i32);
2000  return true;
2001  case AMDGPU::CONST_COPY: {
2002  unsigned Opcode = ParentNode->getMachineOpcode();
2003  bool HasDst = TII->getOperandIdx(Opcode, AMDGPU::OpName::dst) > -1;
2004 
2005  if (!Sel.getNode())
2006  return false;
2007 
2008  SDValue CstOffset = Src.getOperand(0);
2009  if (ParentNode->getValueType(0).isVector())
2010  return false;
2011 
2012  // Gather constants values
2013  int SrcIndices[] = {
2014  TII->getOperandIdx(Opcode, AMDGPU::OpName::src0),
2015  TII->getOperandIdx(Opcode, AMDGPU::OpName::src1),
2016  TII->getOperandIdx(Opcode, AMDGPU::OpName::src2),
2017  TII->getOperandIdx(Opcode, AMDGPU::OpName::src0_X),
2018  TII->getOperandIdx(Opcode, AMDGPU::OpName::src0_Y),
2019  TII->getOperandIdx(Opcode, AMDGPU::OpName::src0_Z),
2020  TII->getOperandIdx(Opcode, AMDGPU::OpName::src0_W),
2021  TII->getOperandIdx(Opcode, AMDGPU::OpName::src1_X),
2022  TII->getOperandIdx(Opcode, AMDGPU::OpName::src1_Y),
2023  TII->getOperandIdx(Opcode, AMDGPU::OpName::src1_Z),
2024  TII->getOperandIdx(Opcode, AMDGPU::OpName::src1_W)
2025  };
2026  std::vector<unsigned> Consts;
2027  for (int OtherSrcIdx : SrcIndices) {
2028  int OtherSelIdx = TII->getSelIdx(Opcode, OtherSrcIdx);
2029  if (OtherSrcIdx < 0 || OtherSelIdx < 0)
2030  continue;
2031  if (HasDst) {
2032  OtherSrcIdx--;
2033  OtherSelIdx--;
2034  }
2035  if (RegisterSDNode *Reg =
2036  dyn_cast<RegisterSDNode>(ParentNode->getOperand(OtherSrcIdx))) {
2037  if (Reg->getReg() == AMDGPU::ALU_CONST) {
2038  ConstantSDNode *Cst
2039  = cast<ConstantSDNode>(ParentNode->getOperand(OtherSelIdx));
2040  Consts.push_back(Cst->getZExtValue());
2041  }
2042  }
2043  }
2044 
2045  ConstantSDNode *Cst = cast<ConstantSDNode>(CstOffset);
2046  Consts.push_back(Cst->getZExtValue());
2047  if (!TII->fitsConstReadLimitations(Consts)) {
2048  return false;
2049  }
2050 
2051  Sel = CstOffset;
2052  Src = DAG.getRegister(AMDGPU::ALU_CONST, MVT::f32);
2053  return true;
2054  }
2055  case AMDGPU::MOV_IMM_GLOBAL_ADDR:
2056  // Check if the Imm slot is used. Taken from below.
2057  if (cast<ConstantSDNode>(Imm)->getZExtValue())
2058  return false;
2059  Imm = Src.getOperand(0);
2060  Src = DAG.getRegister(AMDGPU::ALU_LITERAL_X, MVT::i32);
2061  return true;
2062  case AMDGPU::MOV_IMM_I32:
2063  case AMDGPU::MOV_IMM_F32: {
2064  unsigned ImmReg = AMDGPU::ALU_LITERAL_X;
2065  uint64_t ImmValue = 0;
2066 
2067  if (Src.getMachineOpcode() == AMDGPU::MOV_IMM_F32) {
2069  float FloatValue = FPC->getValueAPF().convertToFloat();
2070  if (FloatValue == 0.0) {
2071  ImmReg = AMDGPU::ZERO;
2072  } else if (FloatValue == 0.5) {
2073  ImmReg = AMDGPU::HALF;
2074  } else if (FloatValue == 1.0) {
2075  ImmReg = AMDGPU::ONE;
2076  } else {
2077  ImmValue = FPC->getValueAPF().bitcastToAPInt().getZExtValue();
2078  }
2079  } else {
2081  uint64_t Value = C->getZExtValue();
2082  if (Value == 0) {
2083  ImmReg = AMDGPU::ZERO;
2084  } else if (Value == 1) {
2085  ImmReg = AMDGPU::ONE_INT;
2086  } else {
2087  ImmValue = Value;
2088  }
2089  }
2090 
2091  // Check that we aren't already using an immediate.
2092  // XXX: It's possible for an instruction to have more than one
2093  // immediate operand, but this is not supported yet.
2094  if (ImmReg == AMDGPU::ALU_LITERAL_X) {
2095  if (!Imm.getNode())
2096  return false;
2098  assert(C);
2099  if (C->getZExtValue())
2100  return false;
2101  Imm = DAG.getTargetConstant(ImmValue, SDLoc(ParentNode), MVT::i32);
2102  }
2103  Src = DAG.getRegister(ImmReg, MVT::i32);
2104  return true;
2105  }
2106  default:
2107  return false;
2108  }
2109 }
2110 
2111 /// \brief Fold the instructions after selecting them
2112 SDNode *R600TargetLowering::PostISelFolding(MachineSDNode *Node,
2113  SelectionDAG &DAG) const {
2114  const R600InstrInfo *TII = getSubtarget()->getInstrInfo();
2115  if (!Node->isMachineOpcode())
2116  return Node;
2117 
2118  unsigned Opcode = Node->getMachineOpcode();
2119  SDValue FakeOp;
2120 
2121  std::vector<SDValue> Ops(Node->op_begin(), Node->op_end());
2122 
2123  if (Opcode == AMDGPU::DOT_4) {
2124  int OperandIdx[] = {
2125  TII->getOperandIdx(Opcode, AMDGPU::OpName::src0_X),
2126  TII->getOperandIdx(Opcode, AMDGPU::OpName::src0_Y),
2127  TII->getOperandIdx(Opcode, AMDGPU::OpName::src0_Z),
2128  TII->getOperandIdx(Opcode, AMDGPU::OpName::src0_W),
2129  TII->getOperandIdx(Opcode, AMDGPU::OpName::src1_X),
2130  TII->getOperandIdx(Opcode, AMDGPU::OpName::src1_Y),
2131  TII->getOperandIdx(Opcode, AMDGPU::OpName::src1_Z),
2132  TII->getOperandIdx(Opcode, AMDGPU::OpName::src1_W)
2133  };
2134  int NegIdx[] = {
2135  TII->getOperandIdx(Opcode, AMDGPU::OpName::src0_neg_X),
2136  TII->getOperandIdx(Opcode, AMDGPU::OpName::src0_neg_Y),
2137  TII->getOperandIdx(Opcode, AMDGPU::OpName::src0_neg_Z),
2138  TII->getOperandIdx(Opcode, AMDGPU::OpName::src0_neg_W),
2139  TII->getOperandIdx(Opcode, AMDGPU::OpName::src1_neg_X),
2140  TII->getOperandIdx(Opcode, AMDGPU::OpName::src1_neg_Y),
2141  TII->getOperandIdx(Opcode, AMDGPU::OpName::src1_neg_Z),
2142  TII->getOperandIdx(Opcode, AMDGPU::OpName::src1_neg_W)
2143  };
2144  int AbsIdx[] = {
2145  TII->getOperandIdx(Opcode, AMDGPU::OpName::src0_abs_X),
2146  TII->getOperandIdx(Opcode, AMDGPU::OpName::src0_abs_Y),
2147  TII->getOperandIdx(Opcode, AMDGPU::OpName::src0_abs_Z),
2148  TII->getOperandIdx(Opcode, AMDGPU::OpName::src0_abs_W),
2149  TII->getOperandIdx(Opcode, AMDGPU::OpName::src1_abs_X),
2150  TII->getOperandIdx(Opcode, AMDGPU::OpName::src1_abs_Y),
2151  TII->getOperandIdx(Opcode, AMDGPU::OpName::src1_abs_Z),
2152  TII->getOperandIdx(Opcode, AMDGPU::OpName::src1_abs_W)
2153  };
2154  for (unsigned i = 0; i < 8; i++) {
2155  if (OperandIdx[i] < 0)
2156  return Node;
2157  SDValue &Src = Ops[OperandIdx[i] - 1];
2158  SDValue &Neg = Ops[NegIdx[i] - 1];
2159  SDValue &Abs = Ops[AbsIdx[i] - 1];
2160  bool HasDst = TII->getOperandIdx(Opcode, AMDGPU::OpName::dst) > -1;
2161  int SelIdx = TII->getSelIdx(Opcode, OperandIdx[i]);
2162  if (HasDst)
2163  SelIdx--;
2164  SDValue &Sel = (SelIdx > -1) ? Ops[SelIdx] : FakeOp;
2165  if (FoldOperand(Node, i, Src, Neg, Abs, Sel, FakeOp, DAG))
2166  return DAG.getMachineNode(Opcode, SDLoc(Node), Node->getVTList(), Ops);
2167  }
2168  } else if (Opcode == AMDGPU::REG_SEQUENCE) {
2169  for (unsigned i = 1, e = Node->getNumOperands(); i < e; i += 2) {
2170  SDValue &Src = Ops[i];
2171  if (FoldOperand(Node, i, Src, FakeOp, FakeOp, FakeOp, FakeOp, DAG))
2172  return DAG.getMachineNode(Opcode, SDLoc(Node), Node->getVTList(), Ops);
2173  }
2174  } else if (Opcode == AMDGPU::CLAMP_R600) {
2175  SDValue Src = Node->getOperand(0);
2176  if (!Src.isMachineOpcode() ||
2177  !TII->hasInstrModifiers(Src.getMachineOpcode()))
2178  return Node;
2179  int ClampIdx = TII->getOperandIdx(Src.getMachineOpcode(),
2180  AMDGPU::OpName::clamp);
2181  if (ClampIdx < 0)
2182  return Node;
2183  SDLoc DL(Node);
2184  std::vector<SDValue> Ops(Src->op_begin(), Src->op_end());
2185  Ops[ClampIdx - 1] = DAG.getTargetConstant(1, DL, MVT::i32);
2186  return DAG.getMachineNode(Src.getMachineOpcode(), DL,
2187  Node->getVTList(), Ops);
2188  } else {
2189  if (!TII->hasInstrModifiers(Opcode))
2190  return Node;
2191  int OperandIdx[] = {
2192  TII->getOperandIdx(Opcode, AMDGPU::OpName::src0),
2193  TII->getOperandIdx(Opcode, AMDGPU::OpName::src1),
2194  TII->getOperandIdx(Opcode, AMDGPU::OpName::src2)
2195  };
2196  int NegIdx[] = {
2197  TII->getOperandIdx(Opcode, AMDGPU::OpName::src0_neg),
2198  TII->getOperandIdx(Opcode, AMDGPU::OpName::src1_neg),
2199  TII->getOperandIdx(Opcode, AMDGPU::OpName::src2_neg)
2200  };
2201  int AbsIdx[] = {
2202  TII->getOperandIdx(Opcode, AMDGPU::OpName::src0_abs),
2203  TII->getOperandIdx(Opcode, AMDGPU::OpName::src1_abs),
2204  -1
2205  };
2206  for (unsigned i = 0; i < 3; i++) {
2207  if (OperandIdx[i] < 0)
2208  return Node;
2209  SDValue &Src = Ops[OperandIdx[i] - 1];
2210  SDValue &Neg = Ops[NegIdx[i] - 1];
2211  SDValue FakeAbs;
2212  SDValue &Abs = (AbsIdx[i] > -1) ? Ops[AbsIdx[i] - 1] : FakeAbs;
2213  bool HasDst = TII->getOperandIdx(Opcode, AMDGPU::OpName::dst) > -1;
2214  int SelIdx = TII->getSelIdx(Opcode, OperandIdx[i]);
2215  int ImmIdx = TII->getOperandIdx(Opcode, AMDGPU::OpName::literal);
2216  if (HasDst) {
2217  SelIdx--;
2218  ImmIdx--;
2219  }
2220  SDValue &Sel = (SelIdx > -1) ? Ops[SelIdx] : FakeOp;
2221  SDValue &Imm = Ops[ImmIdx];
2222  if (FoldOperand(Node, i, Src, Neg, Abs, Sel, Imm, DAG))
2223  return DAG.getMachineNode(Opcode, SDLoc(Node), Node->getVTList(), Ops);
2224  }
2225  }
2226 
2227  return Node;
2228 }
MVT getSimpleValueType() const
Return the simple ValueType of the referenced return value.
SDValue getStore(SDValue Chain, const SDLoc &dl, SDValue Val, SDValue Ptr, MachinePointerInfo PtrInfo, unsigned Alignment=0, MachineMemOperand::Flags MMOFlags=MachineMemOperand::MONone, const AAMDNodes &AAInfo=AAMDNodes())
Helper function to build ISD::STORE nodes.
static const unsigned CONSTANT_BUFFER_3
Definition: AMDGPU.h:187
BITCAST - This operator converts between integer, vector and FP values, as if the value was stored to...
Definition: ISDOpcodes.h:544
X = FP_ROUND(Y, TRUNC) - Rounding 'Y' from a larger floating point type down to the precision of the ...
Definition: ISDOpcodes.h:511
static const unsigned CONSTANT_BUFFER_12
Definition: AMDGPU.h:196
static SDValue CompactSwizzlableVector(SelectionDAG &DAG, SDValue VectorEntry, DenseMap< unsigned, unsigned > &RemapSwizzle)
const MachineFunction * getParent() const
Return the MachineFunction containing this basic block.
A parsed version of the target data layout string in and methods for querying it. ...
Definition: DataLayout.h:109
SDValue getValue(unsigned R) const
void addFlag(MachineInstr &MI, unsigned Operand, unsigned Flag) const
Add one of the MO_FLAG* flags to the specified Operand.
void setLoadExtAction(unsigned ExtType, MVT ValVT, MVT MemVT, LegalizeAction Action)
Indicate that the specified load with extension does not work with the specified type and indicate wh...
Flags getFlags() const
Return the raw flags of the source value,.
LLVMContext * getContext() const
Definition: SelectionDAG.h:381
AMDGPU specific subclass of TargetSubtarget.
uint64_t getZExtValue() const
Get zero extended value.
Definition: APInt.h:1542
SDValue PerformDAGCombine(SDNode *N, DAGCombinerInfo &DCI) const override
This method will be invoked for all target nodes and for any target-independent nodes that the target...
SDValue scalarizeVectorStore(StoreSDNode *ST, SelectionDAG &DAG) const
void LowerUDIVREM64(SDValue Op, SelectionDAG &DAG, SmallVectorImpl< SDValue > &Results) const
BR_CC - Conditional branch.
Definition: ISDOpcodes.h:616
virtual MachineBasicBlock * EmitInstrWithCustomInserter(MachineInstr &MI, MachineBasicBlock *MBB) const
This method should be implemented by targets that mark instructions with the 'usesCustomInserter' fla...
static const unsigned CONSTANT_BUFFER_8
Definition: AMDGPU.h:192
InputArg - This struct carries flags and type information about a single incoming (formal) argument o...
Interface definition for R600InstrInfo.
static const unsigned CONSTANT_BUFFER_5
Definition: AMDGPU.h:189
const ConstantFP * getFPImm() const
float convertToFloat() const
Definition: APFloat.h:1098
bool canMergeStoresTo(unsigned AS, EVT MemVT, const SelectionDAG &DAG) const override
Returns if it's reasonable to merge stores to MemVT size.
SDVTList getVTList() const
virtual SDValue LowerGlobalAddress(AMDGPUMachineFunction *MFI, SDValue Op, SelectionDAG &DAG) const
Carry-setting nodes for multiple precision addition and subtraction.
Definition: ISDOpcodes.h:222
DataLayout DL
static bool isVirtualRegister(unsigned Reg)
Return true if the specified register number is in the virtual register namespace.
const MachineInstrBuilder & add(const MachineOperand &MO) const
const GlobalValue * getGlobal() const
static PointerType * get(Type *ElementType, unsigned AddressSpace)
This constructs a pointer to an object of the specified type in a numbered address space...
Definition: Type.cpp:617
MachineBasicBlock * EmitInstrWithCustomInserter(MachineInstr &MI, MachineBasicBlock *BB) const override
This method should be implemented by targets that mark instructions with the 'usesCustomInserter' fla...
unsigned getOpcode() const
Return the SelectionDAG opcode value for this node.
Function Alias Analysis Results
Type * getTypeForEVT(LLVMContext &Context) const
This method returns an LLVM type corresponding to the specified EVT.
Definition: ValueTypes.cpp:205
unsigned getNumOperands() const
Return the number of values used by this operation.
constexpr bool isInt< 16 >(int64_t x)
Definition: MathExtras.h:298
const SDValue & getOperand(unsigned Num) const
bool expandFP_TO_SINT(SDNode *N, SDValue &Result, SelectionDAG &DAG) const
Expand float(f32) to SINT(i64) conversion.
SDValue getTruncStore(SDValue Chain, const SDLoc &dl, SDValue Val, SDValue Ptr, MachinePointerInfo PtrInfo, EVT TVT, unsigned Alignment=0, MachineMemOperand::Flags MMOFlags=MachineMemOperand::MONone, const AAMDNodes &AAInfo=AAMDNodes())
SDValue getNode(unsigned Opcode, const SDLoc &DL, EVT VT, ArrayRef< SDUse > Ops)
Gets or creates the specified node.
SDValue scalarizeVectorLoad(LoadSDNode *LD, SelectionDAG &DAG) const
Turn load of vector type into a load of the individual elements.
const SDValue & getBasePtr() const
Select with condition operator - This selects between a true value and a false value (ops #2 and #3) ...
Definition: ISDOpcodes.h:403
bool bitsLT(EVT VT) const
Return true if this has less bits than VT.
Definition: ValueTypes.h:241
void setTruncStoreAction(MVT ValVT, MVT MemVT, LegalizeAction Action)
Indicate that the specified truncating store does not work with the specified type and indicate what ...
static const unsigned LOCAL_ADDRESS
Address space for local memory.
Definition: AMDGPU.h:175
SDIVREM/UDIVREM - Divide two integers and produce both a quotient and remainder result.
Definition: ISDOpcodes.h:209
SDValue expandUnalignedStore(StoreSDNode *ST, SelectionDAG &DAG) const
Expands an unaligned store to 2 half-size stores for integer values, and possibly more for vectors...
SHL_PARTS/SRA_PARTS/SRL_PARTS - These operators are used for expanded integer shift operations...
Definition: ISDOpcodes.h:432
bool isVector() const
Return true if this is a vector value type.
Definition: ValueTypes.h:151
Pointer to the start of the shader's constant data.
OpenCL uses address spaces to differentiate between various memory regions on the hardware...
Definition: AMDGPU.h:164
static const unsigned CONSTANT_BUFFER_15
Definition: AMDGPU.h:199
const HexagonInstrInfo * TII
ArrayRef< T > makeArrayRef(const T &OneElt)
Construct an ArrayRef from a single element.
Definition: ArrayRef.h:451
#define MO_FLAG_ABS
Definition: R600Defines.h:19
Shift and rotation operations.
Definition: ISDOpcodes.h:378
EVT getValueType(unsigned ResNo) const
Return the type of a specified result.
int getFrameIndexReference(const MachineFunction &MF, int FI, unsigned &FrameReg) const override
MachineSDNode * getMachineNode(unsigned Opcode, const SDLoc &dl, EVT VT)
These are used for target selectors to create a new node with specified return type(s), MachineInstr opcode, and operands.
MachineFunction & getMachineFunction() const
Definition: SelectionDAG.h:375
int getLDSNoRetOp(uint16_t Opcode)
This class consists of common code factored out of the SmallVector class to reduce code duplication b...
Definition: APFloat.h:42
void eraseFromParent()
Unlink 'this' from the containing basic block and delete it.
unsigned getAddressSpace() const
Reg
All possible values of the reg field in the ModR/M byte.
void setCondCodeAction(ISD::CondCode CC, MVT VT, LegalizeAction Action)
Indicate that the specified condition code is or isn't supported on the target and indicate what to d...
APInt bitcastToAPInt() const
Definition: APFloat.h:1094
The memory access is dereferenceable (i.e., doesn't trap).
EVT getScalarType() const
If this is a vector type, return the element type, otherwise return this.
Definition: ValueTypes.h:260
MachineInstr * buildMovImm(MachineBasicBlock &BB, MachineBasicBlock::iterator I, unsigned DstReg, uint64_t Imm) const
SDValue combineFMinMaxLegacy(const SDLoc &DL, EVT VT, SDValue LHS, SDValue RHS, SDValue True, SDValue False, SDValue CC, DAGCombinerInfo &DCI) const
Generate Min/Max node.
void setOperationAction(unsigned Op, MVT VT, LegalizeAction Action)
Indicate that the specified operation does not work with the specified type and indicate what to do a...
unsigned getMachineOpcode() const
bool bitsGE(EVT VT) const
Return true if this has no less bits than VT.
Definition: ValueTypes.h:235
SDVTList getVTList(EVT VT)
Return an SDVTList that represents the list of values specified.
Interface to describe a layout of a stack frame on an AMDGPU target.
SDValue LowerOperation(SDValue Op, SelectionDAG &DAG) const override
This callback is invoked for operations that are unsupported by the target, which are registered to u...
bool isInteger() const
Return true if this is an integer or a vector integer type.
Definition: ValueTypes.h:141
This file implements a class to represent arbitrary precision integral constant values and operations...
SDValue getExtLoad(ISD::LoadExtType ExtType, const SDLoc &dl, EVT VT, SDValue Chain, SDValue Ptr, MachinePointerInfo PtrInfo, EVT MemVT, unsigned Alignment=0, MachineMemOperand::Flags MMOFlags=MachineMemOperand::MONone, const AAMDNodes &AAInfo=AAMDNodes())
unsigned getNumOperands() const
Access to explicit operands of the instruction.
Definition: MachineInstr.h:282
bool hasInstrModifiers(unsigned Opcode) const
SDValue getMergeValues(ArrayRef< SDValue > Ops, const SDLoc &dl)
Create a MERGE_VALUES node from the given operands.
EVT getVectorElementType() const
Given a vector type, return the type of each element.
Definition: ValueTypes.h:265
void ReplaceNodeResults(SDNode *N, SmallVectorImpl< SDValue > &Results, SelectionDAG &DAG) const override
This callback is invoked when a node result type is illegal for the target, and the operation was reg...
static const unsigned CONSTANT_BUFFER_9
Definition: AMDGPU.h:193
unsigned getLocReg() const
void computeRegisterProperties(const TargetRegisterInfo *TRI)
Once all of the register classes are added, this allows us to compute derived properties we expose...
const AMDGPUSubtarget * Subtarget
unsigned getNumValues() const
Return the number of values defined/returned by this operator.
#define MO_FLAG_NEG
Definition: R600Defines.h:18
Simple integer binary arithmetic operators.
Definition: ISDOpcodes.h:200
const SDValue & getBasePtr() const
SDValue getUNDEF(EVT VT)
Return an UNDEF node. UNDEF does not have a useful SDLoc.
Definition: SelectionDAG.h:816
CondCode
ISD::CondCode enum - These are ordered carefully to make the bitfields below work out...
Definition: ISDOpcodes.h:909
static const unsigned CONSTANT_BUFFER_7
Definition: AMDGPU.h:191
EVT getValueType(const DataLayout &DL, Type *Ty, bool AllowUnknown=false) const
Return the EVT corresponding to this LLVM type.
EVT getMemoryVT() const
Return the type of the in-memory value.
int64_t getImm() const
SDValue getTargetConstant(uint64_t Val, const SDLoc &DL, EVT VT, bool isOpaque=false)
Definition: SelectionDAG.h:546
RESULT = INTRINSIC_WO_CHAIN(INTRINSICID, arg1, arg2, ...) This node represents a target intrinsic fun...
Definition: ISDOpcodes.h:151
const DataLayout & getDataLayout() const
Definition: SelectionDAG.h:376
bool bitsLE(EVT VT) const
Return true if this has no more bits than VT.
Definition: ValueTypes.h:247
Class to represent pointers.
Definition: DerivedTypes.h:467
This class is used to represent ISD::STORE nodes.
unsigned getOpcode() const
Returns the opcode of this MachineInstr.
Definition: MachineInstr.h:279
FP_TO_[US]INT - Convert a floating point value to a signed or unsigned integer.
Definition: ISDOpcodes.h:497
This node is for VLIW targets and it is used to represent a vector that is stored in consecutive regi...
SDValue LowerOperation(SDValue Op, SelectionDAG &DAG) const override
This callback is invoked for operations that are unsupported by the target, which are registered to u...
BUILD_VECTOR(ELT0, ELT1, ELT2, ELT3,...) - Return a vector with the specified, possibly variable...
Definition: ISDOpcodes.h:301
const R600FrameLowering * getFrameLowering() const override
SDNode * getNode() const
get the SDNode which holds the desired result
MachineInstrBuilder BuildMI(MachineFunction &MF, const DebugLoc &DL, const MCInstrDesc &MCID)
Builder interface. Specify how to create the initial instruction itself.
unsigned getScalarSizeInBits() const
Definition: ValueTypes.h:298
unsigned getStoreSize() const
Return the number of bytes overwritten by a store of the specified value type.
Definition: ValueTypes.h:304
static const unsigned CONSTANT_BUFFER_4
Definition: AMDGPU.h:188
OUTCHAIN = INTRINSIC_VOID(INCHAIN, INTRINSICID, arg1, arg2, ...) This node represents a target intrin...
Definition: ISDOpcodes.h:166
void setImmOperand(MachineInstr &MI, unsigned Op, int64_t Imm) const
Helper function for setting instruction flag values.
unsigned const MachineRegisterInfo * MRI
static ConstantPointerNull * get(PointerType *T)
Static factory methods - Return objects of the specified value.
Definition: Constants.cpp:1306
Machine Value Type.
const SDValue & getOperand(unsigned i) const
This is an important class for using LLVM in a threaded context.
Definition: LLVMContext.h:68
void addRegisterClass(MVT VT, const TargetRegisterClass *RC)
Add the specified register class as an available regclass for the specified value type...
Simple binary floating point operators.
Definition: ISDOpcodes.h:259
void setTargetDAGCombine(ISD::NodeType NT)
Targets should invoke this method for each target independent node that they want to provide a custom...
SDValue getMemIntrinsicNode(unsigned Opcode, const SDLoc &dl, SDVTList VTList, ArrayRef< SDValue > Ops, EVT MemVT, MachinePointerInfo PtrInfo, unsigned Align=0, bool Vol=false, bool ReadMem=true, bool WriteMem=true, unsigned Size=0)
Creates a MemIntrinsicNode that may produce a result and takes a list of operands.
static int ConstantAddressBlock(unsigned AddressSpace, AMDGPUAS AMDGPUASI)
MVT getLocVT() const
LoadExtType
LoadExtType enum - This enum defines the three variants of LOADEXT (load with extension).
Definition: ISDOpcodes.h:884
DebugLoc findDebugLoc(instr_iterator MBBI)
Find the next valid DebugLoc starting at MBBI, skipping any DBG_VALUE instructions.
INSERT_VECTOR_ELT(VECTOR, VAL, IDX) - Returns VECTOR with the element at IDX replaced with VAL...
Definition: ISDOpcodes.h:306
constexpr char Args[]
Key for Kernel::Metadata::mArgs.
This file contains the declarations for the subclasses of Constant, which represent the different fla...
const MachineOperand & getOperand(unsigned i) const
Definition: MachineInstr.h:284
Carry-using nodes for multiple precision addition and subtraction.
Definition: ISDOpcodes.h:231
bool isOperationLegal(unsigned Op, EVT VT) const
Return true if the specified operation is legal on this target.
This file declares a class to represent arbitrary precision floating point values and provide a varie...
const R600InstrInfo * getInstrInfo() const override
Ty * getInfo()
getInfo - Keep track of various per-function pieces of information for backends that would like to do...
unsigned getOpcode() const
int getOperandIdx(const MachineInstr &MI, unsigned Op) const
Get the index of Op in the MachineInstr.
SDValue LowerFormalArguments(SDValue Chain, CallingConv::ID CallConv, bool isVarArg, const SmallVectorImpl< ISD::InputArg > &Ins, const SDLoc &DL, SelectionDAG &DAG, SmallVectorImpl< SDValue > &InVals) const override
XXX Only kernel functions are supported, so we can assume for now that every function is a kernel fun...
The memory access is non-temporal.
CondCode getSetCCSwappedOperands(CondCode Operation)
Return the operation corresponding to (Y op X) when given the operation for (X op Y)...
const SDValue & getValue() const
Extended Value Type.
Definition: ValueTypes.h:34
static UndefValue * get(Type *T)
Static factory methods - Return an 'undef' object of the specified type.
Definition: Constants.cpp:1320
const APFloat & getValueAPF() const
This class contains a discriminated union of information about pointers in memory operands...
#define MO_FLAG_CLAMP
Definition: R600Defines.h:17
static SDValue ReorganizeVector(SelectionDAG &DAG, SDValue VectorEntry, DenseMap< unsigned, unsigned > &RemapSwizzle)
SDValue getLoad(EVT VT, const SDLoc &dl, SDValue Chain, SDValue Ptr, MachinePointerInfo PtrInfo, unsigned Alignment=0, MachineMemOperand::Flags MMOFlags=MachineMemOperand::MONone, const AAMDNodes &AAInfo=AAMDNodes(), const MDNode *Ranges=nullptr)
Loads are not normal binary operators: their result type is not determined by their operands...
const MachinePointerInfo & getPointerInfo() const
static const unsigned CONSTANT_BUFFER_13
Definition: AMDGPU.h:197
static CCAssignFn * CCAssignFnForCall(CallingConv::ID CC, bool IsVarArg)
Selects the correct CCAssignFn for a given CallingConvention value.
const SDValue & getOffset() const
bool bitsGT(EVT VT) const
Return true if this has more bits than VT.
Definition: ValueTypes.h:229
const R600RegisterInfo * getRegisterInfo() const override
void ReplaceNodeResults(SDNode *N, SmallVectorImpl< SDValue > &Results, SelectionDAG &DAG) const override
This callback is invoked when a node result type is illegal for the target, and the operation was reg...
static const unsigned CONSTANT_BUFFER_0
Definition: AMDGPU.h:184
CCState - This class holds information needed while lowering arguments and return values...
EXTRACT_VECTOR_ELT(VECTOR, IDX) - Returns a single element from VECTOR identified by the (potentially...
Definition: ISDOpcodes.h:313
This is used to represent a portion of an LLVM function in a low-level Data Dependence DAG representa...
Definition: SelectionDAG.h:209
This is a 'vector' (really, a variable-sized array), optimized for the case when the array is small...
Definition: SmallVector.h:861
SDValue getBuildVector(EVT VT, const SDLoc &DL, ArrayRef< SDValue > Ops)
Return an ISD::BUILD_VECTOR node.
Definition: SelectionDAG.h:698
CCValAssign - Represent assignment of one arg/retval to a location.
AddressSpace
Definition: NVPTXBaseInfo.h:22
BRCOND - Conditional branch.
Definition: ISDOpcodes.h:610
SDValue PerformDAGCombine(SDNode *N, DAGCombinerInfo &DCI) const override
This method will be invoked for all target nodes and for any target-independent nodes that the target...
An SDNode that represents everything that will be needed to construct a MachineInstr.
const SDValue & getChain() const
static const unsigned CONSTANT_BUFFER_10
Definition: AMDGPU.h:194
Promote Memory to Register
Definition: Mem2Reg.cpp:101
const size_t N
MachineMemOperand * getMemOperand() const
Return a MachineMemOperand object describing the memory reference performed by operation.
static const unsigned CONSTANT_BUFFER_14
Definition: AMDGPU.h:198
const R600Subtarget * getSubtarget() const
Wrapper class for IR location info (IR ordering and DebugLoc) to be passed into SDNode creation funct...
bool isMachineOpcode() const
unsigned getStackWidth(const MachineFunction &MF) const
Represents one node in the SelectionDAG.
static const unsigned CONSTANT_BUFFER_6
Definition: AMDGPU.h:190
CondCode getSetCCInverse(CondCode Operation, bool isInteger)
Return the operation corresponding to !(X op Y), where 'op' is a valid SetCC operation.
static const unsigned CONSTANT_BUFFER_2
Definition: AMDGPU.h:186
SDValue getNOT(const SDLoc &DL, SDValue Val, EVT VT)
Create a bitwise NOT operation as (XOR Val, -1).
AAMDNodes getAAInfo() const
Returns the AA info that describes the dereference.
static mvt_range integer_valuetypes()
void swap(llvm::BitVector &LHS, llvm::BitVector &RHS)
Implement std::swap in terms of BitVector swap.
Definition: BitVector.h:923
ISD::LoadExtType getExtensionType() const
Return whether this is a plain node, or one of the varieties of value-extending loads.
static const unsigned PARAM_I_ADDRESS
Address space for indirect addressible parameter memory (VTX1)
Definition: AMDGPU.h:177
const Value * getValue() const
Return the base address of the memory access.
SDValue getConstantFP(double Val, const SDLoc &DL, EVT VT, bool isTarget=false)
Create a ConstantFPSDNode wrapping a constant value.
bool isShader(CallingConv::ID cc)
Select(COND, TRUEVAL, FALSEVAL).
Definition: ISDOpcodes.h:388
Interface for the AMDGPU Implementation of the Intrinsic Info class.
op_iterator op_begin() const
SDValue CreateLiveInRegisterRaw(SelectionDAG &DAG, const TargetRegisterClass *RC, unsigned Reg, EVT VT) const
static const unsigned CONSTANT_BUFFER_11
Definition: AMDGPU.h:195
ANY_EXTEND - Used for integer types. The high bits are undefined.
Definition: ISDOpcodes.h:447
void append(in_iter in_start, in_iter in_end)
Add the specified range to the end of the SmallVector.
Definition: SmallVector.h:395
int getSelIdx(unsigned Opcode, unsigned SrcIdx) const
llvm_unreachable("Unknown RegBank!")
unsigned getAddressSpace() const
Return the address space for the associated pointer.
MachineRegisterInfo - Keep track of information for virtual and physical registers, including vreg register classes, use/def chains for registers, etc.
Representation of each machine instruction.
Definition: MachineInstr.h:59
MachineInstrBuilder buildDefaultInstruction(MachineBasicBlock &MBB, MachineBasicBlock::iterator I, unsigned Opcode, unsigned DstReg, unsigned Src0Reg, unsigned Src1Reg=0) const
buildDefaultInstruction - This function returns a MachineInstr with all the instruction modifiers ini...
Bitwise operators - logical and, logical or, logical xor.
Definition: ISDOpcodes.h:361
bool isUndef() const
SDValue getCopyFromReg(SDValue Chain, const SDLoc &dl, unsigned Reg, EVT VT)
Definition: SelectionDAG.h:669
static const unsigned CONSTANT_BUFFER_1
Definition: AMDGPU.h:185
MachineRegisterInfo & getRegInfo()
getRegInfo - Return information about the registers currently in use.
R600TargetLowering(const TargetMachine &TM, const R600Subtarget &STI)
R600 DAG Lowering interface definition.
SIGN_EXTEND_INREG - This operator atomically performs a SHL/SRA pair to sign extend a small value in ...
Definition: ISDOpcodes.h:462
#define C
Definition: LargeTest.cpp:25
LOAD and STORE have token chains as their first operand, then the same operands as an LLVM load/store...
Definition: ISDOpcodes.h:580
unsigned getSizeInBits() const
Return the size of the specified value type in bits.
Definition: ValueTypes.h:292
unsigned getOrigArgIndex() const
#define I(x, y, z)
Definition: MD5.cpp:58
LLVM_ATTRIBUTE_ALWAYS_INLINE size_type size() const
Definition: SmallVector.h:135
bool isIndexed() const
Return true if this is a pre/post inc/dec load/store.
constexpr char Align[]
Key for Kernel::Arg::Metadata::mAlign.
The memory access always returns the same value (or traps).
op_iterator op_end() const
unsigned getExplicitKernelArgOffset(const MachineFunction &MF) const
Returns the offset in bytes from the start of the input buffer of the first explicit kernel argument...
const SDValue & getOffset() const
void analyzeFormalArgumentsCompute(CCState &State, const SmallVectorImpl< ISD::InputArg > &Ins) const
The SelectionDAGBuilder will automatically promote function arguments with illegal types...
LLVM_NODISCARD std::enable_if<!is_simple_type< Y >::value, typename cast_retty< X, const Y >::ret_type >::type dyn_cast(const Y &Val)
Definition: Casting.h:323
static volatile int Zero
static const unsigned CONSTANT_ADDRESS
Address space for constant memory (VTX2)
Definition: AMDGPU.h:174
EVT getValueType() const
Return the ValueType of the referenced return value.
SDValue getConstant(uint64_t Val, const SDLoc &DL, EVT VT, bool isTarget=false, bool isOpaque=false)
Create a ConstantSDNode wrapping a constant value.
MachineInstr * getVRegDef(unsigned Reg) const
getVRegDef - Return the machine instr that defines the specified virtual register or null if none is ...
SDValue getCondCode(ISD::CondCode Cond)
LLVM_NODISCARD bool empty() const
Definition: DenseMap.h:84
const APFloat & getValueAPF() const
Definition: Constants.h:294
static const unsigned GLOBAL_ADDRESS
Address space for global memory (RAT0, VTX0).
Definition: AMDGPU.h:173
void setABIArgOffset(unsigned NewOffset)
unsigned getReg() const
getReg - Returns the register number.
assert(ImpDefSCC.getReg()==AMDGPU::SCC &&ImpDefSCC.isDef())
bool isAllOnesConstant(SDValue V)
Returns true if V is an integer constant with all bits set.
bool isSimple() const
Test if the given EVT is simple (as opposed to being extended).
Definition: ValueTypes.h:126
MVT getPointerTy(const DataLayout &DL, uint32_t AS=0) const
Return the pointer type for the given address space, defaults to the pointer type from the data layou...
void setSchedulingPreference(Sched::Preference Pref)
Specify the target scheduling preference.
LLVM Value Representation.
Definition: Value.h:73
SDValue getRegister(unsigned Reg, EVT VT)
bool isNullConstant(SDValue V)
Returns true if V is a constant integer zero.
bool isTruncatingStore() const
Return true if the op does a truncation before store.
SDValue getSelectCC(const SDLoc &DL, SDValue LHS, SDValue RHS, SDValue True, SDValue False, ISD::CondCode Cond)
Helper function to make it easier to build SelectCC's if you just have an ISD::CondCode instead of an...
Definition: SelectionDAG.h:910
#define LLVM_FALLTHROUGH
LLVM_FALLTHROUGH - Mark fallthrough cases in switch statements.
Definition: Compiler.h:235
bool allowsMisalignedMemoryAccesses(EVT VT, unsigned AS, unsigned Align, bool *IsFast) const override
Determine if the target supports unaligned memory accesses.
SDValue getValueType(EVT)
std::underlying_type< E >::type Mask()
Get a bitmask with 1s in all places up to the high-order bit of E's largest value.
Definition: BitmaskEnum.h:81
static bool isEOP(MachineBasicBlock::iterator I)
void ReplaceAllUsesOfValueWith(SDValue From, SDValue To)
Replace any uses of From with To, leaving uses of other values produced by From.Val alone...
Primary interface to the complete machine description for the target machine.
Definition: TargetMachine.h:56
IRTranslator LLVM IR MI
#define MO_FLAG_MASK
Definition: R600Defines.h:20
SetCC operator - This evaluates to a true value iff the condition is true.
Definition: ISDOpcodes.h:411
uint32_t getImplicitParameterOffset(const AMDGPUMachineFunction *MFI, const ImplicitParameter Param) const
Helper function that returns the byte offset of the given type of implicit parameter.
MERGE_VALUES - This node takes multiple discrete operands and returns them all as its individual resu...
Definition: ISDOpcodes.h:197
unsigned getLocMemOffset() const
Conversion operators.
Definition: ISDOpcodes.h:441
bool fitsConstReadLimitations(const std::vector< MachineInstr * > &) const
An instruction group can only access 2 channel pair (either [XY] or [ZW]) from KCache bank on R700+...
int * Ptr
SDValue getEntryNode() const
Return the token chain corresponding to the entry of the function.
Definition: SelectionDAG.h:434
bool isLDSRetInstr(unsigned Opcode) const
SDValue LowerSDIVREM(SDValue Op, SelectionDAG &DAG) const
OUTCHAIN = ATOMIC_STORE(INCHAIN, ptr, val) This corresponds to "store atomic" instruction.
Definition: ISDOpcodes.h:749
SDValue getZeroExtendInReg(SDValue Op, const SDLoc &DL, EVT SrcTy)
Return the expression required to zero extend the Op value assuming it was the smaller SrcTy value...
TRUNCATE - Completely drop the high bits.
Definition: ISDOpcodes.h:450
unsigned getAlignment() const
bool isCondCodeLegal(ISD::CondCode CC, MVT VT) const
Return true if the specified condition code is legal on this target.
Unlike LLVM values, Selection DAG nodes may return multiple values as the result of a computation...
EVT getSetCCResultType(const DataLayout &DL, LLVMContext &, EVT VT) const override
Return the ValueType of the result of SETCC operations.
FNEG, FABS, FSQRT, FSIN, FCOS, FPOWI, FPOW, FLOG, FLOG2, FLOG10, FEXP, FEXP2, FCEIL, FTRUNC, FRINT, FNEARBYINT, FROUND, FFLOOR - Perform various unary floating point operations.
Definition: ISDOpcodes.h:560
Val, OUTCHAIN = ATOMIC_LOAD(INCHAIN, ptr) This corresponds to "load atomic" instruction.
Definition: ISDOpcodes.h:745
MVT getVectorIdxTy(const DataLayout &) const override
Returns the type to be used for the index operand of: ISD::INSERT_VECTOR_ELT, ISD::EXTRACT_VECTOR_ELT...
EVT changeVectorElementTypeToInteger() const
Return a vector with the same number of elements as this vector, but with the element type converted ...
Definition: ValueTypes.h:96
MVT getSimpleVT() const
Return the SimpleValueType held in the specified simple EVT.
Definition: ValueTypes.h:253
unsigned PRIVATE_ADDRESS
Address space for private memory.
Definition: AMDGPU.h:166
#define MO_FLAG_PUSH
Definition: R600Defines.h:21
bool isMachineOpcode() const
Test if this node has a post-isel opcode, directly corresponding to a MachineInstr opcode...
unsigned getMachineOpcode() const
This may only be called if isMachineOpcode returns true.
bool use_empty(unsigned RegNo) const
use_empty - Return true if there are no instructions using the specified register.
SDValue getTargetGlobalAddress(const GlobalValue *GV, const SDLoc &DL, EVT VT, int64_t offset=0, unsigned char TargetFlags=0)
Definition: SelectionDAG.h:588
uint64_t getZExtValue() const
unsigned getVectorNumElements() const
Given a vector type, return the number of elements it contains.
Definition: ValueTypes.h:273
This class is used to represent ISD::LOAD nodes.