LLVM  5.0.0
NVPTXISelLowering.cpp
Go to the documentation of this file.
1 //===-- NVPTXISelLowering.cpp - NVPTX 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 // This file defines the interfaces that NVPTX uses to lower LLVM code into a
11 // selection DAG.
12 //
13 //===----------------------------------------------------------------------===//
14 
15 #include "NVPTXISelLowering.h"
17 #include "NVPTX.h"
18 #include "NVPTXSection.h"
19 #include "NVPTXSubtarget.h"
20 #include "NVPTXTargetMachine.h"
21 #include "NVPTXTargetObjectFile.h"
22 #include "NVPTXUtilities.h"
23 #include "llvm/ADT/APInt.h"
24 #include "llvm/ADT/SmallVector.h"
25 #include "llvm/ADT/StringRef.h"
26 #include "llvm/CodeGen/Analysis.h"
33 #include "llvm/IR/Argument.h"
34 #include "llvm/IR/Attributes.h"
35 #include "llvm/IR/CallSite.h"
36 #include "llvm/IR/Constants.h"
37 #include "llvm/IR/DataLayout.h"
38 #include "llvm/IR/DerivedTypes.h"
39 #include "llvm/IR/Function.h"
40 #include "llvm/IR/GlobalValue.h"
41 #include "llvm/IR/Instruction.h"
42 #include "llvm/IR/Instructions.h"
43 #include "llvm/IR/Module.h"
44 #include "llvm/IR/Type.h"
45 #include "llvm/IR/Value.h"
46 #include "llvm/Support/Casting.h"
47 #include "llvm/Support/CodeGen.h"
56 #include <algorithm>
57 #include <cassert>
58 #include <cstdint>
59 #include <iterator>
60 #include <sstream>
61 #include <string>
62 #include <utility>
63 #include <vector>
64 
65 #define DEBUG_TYPE "nvptx-lower"
66 
67 using namespace llvm;
68 
69 static unsigned int uniqueCallSite = 0;
70 
72  "nvptx-sched4reg",
73  cl::desc("NVPTX Specific: schedule for register pressue"), cl::init(false));
74 
75 static cl::opt<unsigned>
77  cl::desc("NVPTX Specific: FMA contraction (0: don't do it"
78  " 1: do it 2: do it aggressively"),
79  cl::init(2));
80 
82  "nvptx-prec-divf32", cl::ZeroOrMore, cl::Hidden,
83  cl::desc("NVPTX Specifies: 0 use div.approx, 1 use div.full, 2 use"
84  " IEEE Compliant F32 div.rnd if available."),
85  cl::init(2));
86 
88  "nvptx-prec-sqrtf32", cl::Hidden,
89  cl::desc("NVPTX Specific: 0 use sqrt.approx, 1 use sqrt.rn."),
90  cl::init(true));
91 
93  "nvptx-f32ftz", cl::ZeroOrMore, cl::Hidden,
94  cl::desc("NVPTX Specific: Flush f32 subnormals to sign-preserving zero."),
95  cl::init(false));
96 
98  if (UsePrecDivF32.getNumOccurrences() > 0) {
99  // If nvptx-prec-div32=N is used on the command-line, always honor it
100  return UsePrecDivF32;
101  } else {
102  // Otherwise, use div.approx if fast math is enabled
104  return 0;
105  else
106  return 2;
107  }
108 }
109 
111  if (UsePrecSqrtF32.getNumOccurrences() > 0) {
112  // If nvptx-prec-sqrtf32 is used on the command-line, always honor it
113  return UsePrecSqrtF32;
114  } else {
115  // Otherwise, use sqrt.approx if fast math is enabled
117  }
118 }
119 
121  // TODO: Get rid of this flag; there can be only one way to do this.
122  if (FtzEnabled.getNumOccurrences() > 0) {
123  // If nvptx-f32ftz is used on the command-line, always honor it
124  return FtzEnabled;
125  } else {
126  const Function *F = MF.getFunction();
127  // Otherwise, check for an nvptx-f32ftz attribute on the function
128  if (F->hasFnAttribute("nvptx-f32ftz"))
129  return F->getFnAttribute("nvptx-f32ftz").getValueAsString() == "true";
130  else
131  return false;
132  }
133 }
134 
135 static bool IsPTXVectorType(MVT VT) {
136  switch (VT.SimpleTy) {
137  default:
138  return false;
139  case MVT::v2i1:
140  case MVT::v4i1:
141  case MVT::v2i8:
142  case MVT::v4i8:
143  case MVT::v2i16:
144  case MVT::v4i16:
145  case MVT::v2i32:
146  case MVT::v4i32:
147  case MVT::v2i64:
148  case MVT::v2f16:
149  case MVT::v4f16:
150  case MVT::v8f16: // <4 x f16x2>
151  case MVT::v2f32:
152  case MVT::v4f32:
153  case MVT::v2f64:
154  return true;
155  }
156 }
157 
158 /// ComputePTXValueVTs - For the given Type \p Ty, returns the set of primitive
159 /// EVTs that compose it. Unlike ComputeValueVTs, this will break apart vectors
160 /// into their primitive components.
161 /// NOTE: This is a band-aid for code that expects ComputeValueVTs to return the
162 /// same number of types as the Ins/Outs arrays in LowerFormalArguments,
163 /// LowerCall, and LowerReturn.
164 static void ComputePTXValueVTs(const TargetLowering &TLI, const DataLayout &DL,
165  Type *Ty, SmallVectorImpl<EVT> &ValueVTs,
167  uint64_t StartingOffset = 0) {
168  SmallVector<EVT, 16> TempVTs;
169  SmallVector<uint64_t, 16> TempOffsets;
170 
171  ComputeValueVTs(TLI, DL, Ty, TempVTs, &TempOffsets, StartingOffset);
172  for (unsigned i = 0, e = TempVTs.size(); i != e; ++i) {
173  EVT VT = TempVTs[i];
174  uint64_t Off = TempOffsets[i];
175  // Split vectors into individual elements, except for v2f16, which
176  // we will pass as a single scalar.
177  if (VT.isVector()) {
178  unsigned NumElts = VT.getVectorNumElements();
179  EVT EltVT = VT.getVectorElementType();
180  // Vectors with an even number of f16 elements will be passed to
181  // us as an array of v2f16 elements. We must match this so we
182  // stay in sync with Ins/Outs.
183  if (EltVT == MVT::f16 && NumElts % 2 == 0) {
184  EltVT = MVT::v2f16;
185  NumElts /= 2;
186  }
187  for (unsigned j = 0; j != NumElts; ++j) {
188  ValueVTs.push_back(EltVT);
189  if (Offsets)
190  Offsets->push_back(Off + j * EltVT.getStoreSize());
191  }
192  } else {
193  ValueVTs.push_back(VT);
194  if (Offsets)
195  Offsets->push_back(Off);
196  }
197  }
198 }
199 
200 // Check whether we can merge loads/stores of some of the pieces of a
201 // flattened function parameter or return value into a single vector
202 // load/store.
203 //
204 // The flattened parameter is represented as a list of EVTs and
205 // offsets, and the whole structure is aligned to ParamAlignment. This
206 // function determines whether we can load/store pieces of the
207 // parameter starting at index Idx using a single vectorized op of
208 // size AccessSize. If so, it returns the number of param pieces
209 // covered by the vector op. Otherwise, it returns 1.
211  unsigned Idx, uint32_t AccessSize, const SmallVectorImpl<EVT> &ValueVTs,
212  const SmallVectorImpl<uint64_t> &Offsets, unsigned ParamAlignment) {
213  assert(isPowerOf2_32(AccessSize) && "must be a power of 2!");
214 
215  // Can't vectorize if param alignment is not sufficient.
216  if (AccessSize > ParamAlignment)
217  return 1;
218  // Can't vectorize if offset is not aligned.
219  if (Offsets[Idx] & (AccessSize - 1))
220  return 1;
221 
222  EVT EltVT = ValueVTs[Idx];
223  unsigned EltSize = EltVT.getStoreSize();
224 
225  // Element is too large to vectorize.
226  if (EltSize >= AccessSize)
227  return 1;
228 
229  unsigned NumElts = AccessSize / EltSize;
230  // Can't vectorize if AccessBytes if not a multiple of EltSize.
231  if (AccessSize != EltSize * NumElts)
232  return 1;
233 
234  // We don't have enough elements to vectorize.
235  if (Idx + NumElts > ValueVTs.size())
236  return 1;
237 
238  // PTX ISA can only deal with 2- and 4-element vector ops.
239  if (NumElts != 4 && NumElts != 2)
240  return 1;
241 
242  for (unsigned j = Idx + 1; j < Idx + NumElts; ++j) {
243  // Types do not match.
244  if (ValueVTs[j] != EltVT)
245  return 1;
246 
247  // Elements are not contiguous.
248  if (Offsets[j] - Offsets[j - 1] != EltSize)
249  return 1;
250  }
251  // OK. We can vectorize ValueVTs[i..i+NumElts)
252  return NumElts;
253 }
254 
255 // Flags for tracking per-element vectorization state of loads/stores
256 // of a flattened function parameter or return value.
258  PVF_INNER = 0x0, // Middle elements of a vector.
259  PVF_FIRST = 0x1, // First element of the vector.
260  PVF_LAST = 0x2, // Last element of the vector.
261  // Scalar is effectively a 1-element vector.
263 };
264 
265 // Computes whether and how we can vectorize the loads/stores of a
266 // flattened function parameter or return value.
267 //
268 // The flattened parameter is represented as the list of ValueVTs and
269 // Offsets, and is aligned to ParamAlignment bytes. We return a vector
270 // of the same size as ValueVTs indicating how each piece should be
271 // loaded/stored (i.e. as a scalar, or as part of a vector
272 // load/store).
276  unsigned ParamAlignment) {
277  // Set vector size to match ValueVTs and mark all elements as
278  // scalars by default.
280  VectorInfo.assign(ValueVTs.size(), PVF_SCALAR);
281 
282  // Check what we can vectorize using 128/64/32-bit accesses.
283  for (int I = 0, E = ValueVTs.size(); I != E; ++I) {
284  // Skip elements we've already processed.
285  assert(VectorInfo[I] == PVF_SCALAR && "Unexpected vector info state.");
286  for (unsigned AccessSize : {16, 8, 4, 2}) {
287  unsigned NumElts = CanMergeParamLoadStoresStartingAt(
288  I, AccessSize, ValueVTs, Offsets, ParamAlignment);
289  // Mark vectorized elements.
290  switch (NumElts) {
291  default:
292  llvm_unreachable("Unexpected return value");
293  case 1:
294  // Can't vectorize using this size, try next smaller size.
295  continue;
296  case 2:
297  assert(I + 1 < E && "Not enough elements.");
298  VectorInfo[I] = PVF_FIRST;
299  VectorInfo[I + 1] = PVF_LAST;
300  I += 1;
301  break;
302  case 4:
303  assert(I + 3 < E && "Not enough elements.");
304  VectorInfo[I] = PVF_FIRST;
305  VectorInfo[I + 1] = PVF_INNER;
306  VectorInfo[I + 2] = PVF_INNER;
307  VectorInfo[I + 3] = PVF_LAST;
308  I += 3;
309  break;
310  }
311  // Break out of the inner loop because we've already succeeded
312  // using largest possible AccessSize.
313  break;
314  }
315  }
316  return VectorInfo;
317 }
318 
319 // NVPTXTargetLowering Constructor.
321  const NVPTXSubtarget &STI)
322  : TargetLowering(TM), nvTM(&TM), STI(STI) {
323  // always lower memset, memcpy, and memmove intrinsics to load/store
324  // instructions, rather
325  // then generating calls to memset, mempcy or memmove.
326  MaxStoresPerMemset = (unsigned) 0xFFFFFFFF;
327  MaxStoresPerMemcpy = (unsigned) 0xFFFFFFFF;
328  MaxStoresPerMemmove = (unsigned) 0xFFFFFFFF;
329 
332 
333  // Jump is Expensive. Don't create extra control flow for 'and', 'or'
334  // condition branches.
335  setJumpIsExpensive(true);
336 
337  // Wide divides are _very_ slow. Try to reduce the width of the divide if
338  // possible.
339  addBypassSlowDiv(64, 32);
340 
341  // By default, use the Source scheduling
342  if (sched4reg)
344  else
346 
347  auto setFP16OperationAction = [&](unsigned Op, MVT VT, LegalizeAction Action,
348  LegalizeAction NoF16Action) {
349  setOperationAction(Op, VT, STI.allowFP16Math() ? Action : NoF16Action);
350  };
351 
352  addRegisterClass(MVT::i1, &NVPTX::Int1RegsRegClass);
353  addRegisterClass(MVT::i16, &NVPTX::Int16RegsRegClass);
354  addRegisterClass(MVT::i32, &NVPTX::Int32RegsRegClass);
355  addRegisterClass(MVT::i64, &NVPTX::Int64RegsRegClass);
356  addRegisterClass(MVT::f32, &NVPTX::Float32RegsRegClass);
357  addRegisterClass(MVT::f64, &NVPTX::Float64RegsRegClass);
358  addRegisterClass(MVT::f16, &NVPTX::Float16RegsRegClass);
359  addRegisterClass(MVT::v2f16, &NVPTX::Float16x2RegsRegClass);
360 
361  // Conversion to/from FP16/FP16x2 is always legal.
366 
367  setFP16OperationAction(ISD::SETCC, MVT::f16, Legal, Promote);
368  setFP16OperationAction(ISD::SETCC, MVT::v2f16, Legal, Expand);
369 
370  // Operations not directly supported by NVPTX.
389  // Some SIGN_EXTEND_INREG can be done using cvt instruction.
390  // For others we will expand to a SHL/SRA pair.
396 
403 
406 
407  if (STI.hasROT64()) {
410  } else {
413  }
414  if (STI.hasROT32()) {
417  } else {
420  }
421 
429 
430  // Indirect branch is not supported.
431  // This also disables Jump Table creation.
434 
437 
438  // We want to legalize constant related memmove and memcopy
439  // intrinsics.
441 
442  // Turn FP extload into load/fpextend
452  // Turn FP truncstore into trunc + store.
453  // FIXME: vector types should also be expanded
457 
458  // PTX does not support load / store predicate registers
461 
462  for (MVT VT : MVT::integer_valuetypes()) {
466  }
467 
468  // This is legal in NVPTX
472 
473  // TRAP can be lowered to PTX trap
475 
478 
479  // Register custom handling for vector loads/stores
480  for (MVT VT : MVT::vector_valuetypes()) {
481  if (IsPTXVectorType(VT)) {
485  }
486  }
487 
488  // Custom handling for i8 intrinsics
490 
491  for (const auto& Ty : {MVT::i16, MVT::i32, MVT::i64}) {
497 
500  }
501 
505 
506  // PTX does not directly support SELP of i1, so promote to i32 first
508 
509  // PTX cannot multiply two i64s in a single instruction.
512 
513  // We have some custom DAG combine patterns for these nodes
521 
522  // setcc for f16x2 needs special handling to prevent legalizer's
523  // attempt to scalarize it due to v2i1 not being legal.
524  if (STI.allowFP16Math())
526 
527  // Promote fp16 arithmetic if fp16 hardware isn't available or the
528  // user passed --nvptx-no-fp16-math. The flag is useful because,
529  // although sm_53+ GPUs have some sort of FP16 support in
530  // hardware, only sm_53 and sm_60 have full implementation. Others
531  // only have token amount of hardware and are likely to run faster
532  // by using fp32 units instead.
533  for (const auto &Op : {ISD::FADD, ISD::FMUL, ISD::FSUB, ISD::FMA}) {
534  setFP16OperationAction(Op, MVT::f16, Legal, Promote);
535  setFP16OperationAction(Op, MVT::v2f16, Legal, Expand);
536  }
537 
538  // There's no neg.f16 instruction. Expand to (0-x).
541 
542  // (would be) Library functions.
543 
544  // These map to conversion instructions for scalar FP types.
545  for (const auto &Op : {ISD::FCEIL, ISD::FFLOOR, ISD::FNEARBYINT, ISD::FRINT,
551  }
552 
553  // 'Expand' implements FCOPYSIGN without calling an external library.
558 
559  // These map to corresponding instructions for f32/f64. f16 must be
560  // promoted to f32. v2f16 is expanded to f16, which is then promoted
561  // to f32.
562  for (const auto &Op : {ISD::FDIV, ISD::FREM, ISD::FSQRT, ISD::FSIN, ISD::FCOS,
568  }
573 
574  // No FEXP2, FLOG2. The PTX ex2 and log2 functions are always approximate.
575  // No FPOW or FREM in PTX.
576 
577  // Now deduce the information based on the above mentioned
578  // actions
580 }
581 
582 const char *NVPTXTargetLowering::getTargetNodeName(unsigned Opcode) const {
583  switch ((NVPTXISD::NodeType)Opcode) {
585  break;
586  case NVPTXISD::CALL:
587  return "NVPTXISD::CALL";
588  case NVPTXISD::RET_FLAG:
589  return "NVPTXISD::RET_FLAG";
591  return "NVPTXISD::LOAD_PARAM";
592  case NVPTXISD::Wrapper:
593  return "NVPTXISD::Wrapper";
595  return "NVPTXISD::DeclareParam";
597  return "NVPTXISD::DeclareScalarParam";
599  return "NVPTXISD::DeclareRet";
601  return "NVPTXISD::DeclareScalarRet";
603  return "NVPTXISD::DeclareRetParam";
604  case NVPTXISD::PrintCall:
605  return "NVPTXISD::PrintCall";
607  return "NVPTXISD::PrintConvergentCall";
609  return "NVPTXISD::PrintCallUni";
611  return "NVPTXISD::PrintConvergentCallUni";
612  case NVPTXISD::LoadParam:
613  return "NVPTXISD::LoadParam";
615  return "NVPTXISD::LoadParamV2";
617  return "NVPTXISD::LoadParamV4";
619  return "NVPTXISD::StoreParam";
621  return "NVPTXISD::StoreParamV2";
623  return "NVPTXISD::StoreParamV4";
625  return "NVPTXISD::StoreParamS32";
627  return "NVPTXISD::StoreParamU32";
629  return "NVPTXISD::CallArgBegin";
630  case NVPTXISD::CallArg:
631  return "NVPTXISD::CallArg";
633  return "NVPTXISD::LastCallArg";
635  return "NVPTXISD::CallArgEnd";
636  case NVPTXISD::CallVoid:
637  return "NVPTXISD::CallVoid";
638  case NVPTXISD::CallVal:
639  return "NVPTXISD::CallVal";
641  return "NVPTXISD::CallSymbol";
642  case NVPTXISD::Prototype:
643  return "NVPTXISD::Prototype";
644  case NVPTXISD::MoveParam:
645  return "NVPTXISD::MoveParam";
647  return "NVPTXISD::StoreRetval";
649  return "NVPTXISD::StoreRetvalV2";
651  return "NVPTXISD::StoreRetvalV4";
653  return "NVPTXISD::PseudoUseParam";
654  case NVPTXISD::RETURN:
655  return "NVPTXISD::RETURN";
657  return "NVPTXISD::CallSeqBegin";
659  return "NVPTXISD::CallSeqEnd";
661  return "NVPTXISD::CallPrototype";
662  case NVPTXISD::LoadV2:
663  return "NVPTXISD::LoadV2";
664  case NVPTXISD::LoadV4:
665  return "NVPTXISD::LoadV4";
666  case NVPTXISD::LDGV2:
667  return "NVPTXISD::LDGV2";
668  case NVPTXISD::LDGV4:
669  return "NVPTXISD::LDGV4";
670  case NVPTXISD::LDUV2:
671  return "NVPTXISD::LDUV2";
672  case NVPTXISD::LDUV4:
673  return "NVPTXISD::LDUV4";
674  case NVPTXISD::StoreV2:
675  return "NVPTXISD::StoreV2";
676  case NVPTXISD::StoreV4:
677  return "NVPTXISD::StoreV4";
679  return "NVPTXISD::FUN_SHFL_CLAMP";
681  return "NVPTXISD::FUN_SHFR_CLAMP";
682  case NVPTXISD::IMAD:
683  return "NVPTXISD::IMAD";
685  return "NVPTXISD::SETP_F16X2";
686  case NVPTXISD::Dummy:
687  return "NVPTXISD::Dummy";
689  return "NVPTXISD::MUL_WIDE_SIGNED";
691  return "NVPTXISD::MUL_WIDE_UNSIGNED";
692  case NVPTXISD::Tex1DFloatS32: return "NVPTXISD::Tex1DFloatS32";
693  case NVPTXISD::Tex1DFloatFloat: return "NVPTXISD::Tex1DFloatFloat";
695  return "NVPTXISD::Tex1DFloatFloatLevel";
697  return "NVPTXISD::Tex1DFloatFloatGrad";
698  case NVPTXISD::Tex1DS32S32: return "NVPTXISD::Tex1DS32S32";
699  case NVPTXISD::Tex1DS32Float: return "NVPTXISD::Tex1DS32Float";
701  return "NVPTXISD::Tex1DS32FloatLevel";
703  return "NVPTXISD::Tex1DS32FloatGrad";
704  case NVPTXISD::Tex1DU32S32: return "NVPTXISD::Tex1DU32S32";
705  case NVPTXISD::Tex1DU32Float: return "NVPTXISD::Tex1DU32Float";
707  return "NVPTXISD::Tex1DU32FloatLevel";
709  return "NVPTXISD::Tex1DU32FloatGrad";
710  case NVPTXISD::Tex1DArrayFloatS32: return "NVPTXISD::Tex1DArrayFloatS32";
711  case NVPTXISD::Tex1DArrayFloatFloat: return "NVPTXISD::Tex1DArrayFloatFloat";
713  return "NVPTXISD::Tex1DArrayFloatFloatLevel";
715  return "NVPTXISD::Tex1DArrayFloatFloatGrad";
716  case NVPTXISD::Tex1DArrayS32S32: return "NVPTXISD::Tex1DArrayS32S32";
717  case NVPTXISD::Tex1DArrayS32Float: return "NVPTXISD::Tex1DArrayS32Float";
719  return "NVPTXISD::Tex1DArrayS32FloatLevel";
721  return "NVPTXISD::Tex1DArrayS32FloatGrad";
722  case NVPTXISD::Tex1DArrayU32S32: return "NVPTXISD::Tex1DArrayU32S32";
723  case NVPTXISD::Tex1DArrayU32Float: return "NVPTXISD::Tex1DArrayU32Float";
725  return "NVPTXISD::Tex1DArrayU32FloatLevel";
727  return "NVPTXISD::Tex1DArrayU32FloatGrad";
728  case NVPTXISD::Tex2DFloatS32: return "NVPTXISD::Tex2DFloatS32";
729  case NVPTXISD::Tex2DFloatFloat: return "NVPTXISD::Tex2DFloatFloat";
731  return "NVPTXISD::Tex2DFloatFloatLevel";
733  return "NVPTXISD::Tex2DFloatFloatGrad";
734  case NVPTXISD::Tex2DS32S32: return "NVPTXISD::Tex2DS32S32";
735  case NVPTXISD::Tex2DS32Float: return "NVPTXISD::Tex2DS32Float";
737  return "NVPTXISD::Tex2DS32FloatLevel";
739  return "NVPTXISD::Tex2DS32FloatGrad";
740  case NVPTXISD::Tex2DU32S32: return "NVPTXISD::Tex2DU32S32";
741  case NVPTXISD::Tex2DU32Float: return "NVPTXISD::Tex2DU32Float";
743  return "NVPTXISD::Tex2DU32FloatLevel";
745  return "NVPTXISD::Tex2DU32FloatGrad";
746  case NVPTXISD::Tex2DArrayFloatS32: return "NVPTXISD::Tex2DArrayFloatS32";
747  case NVPTXISD::Tex2DArrayFloatFloat: return "NVPTXISD::Tex2DArrayFloatFloat";
749  return "NVPTXISD::Tex2DArrayFloatFloatLevel";
751  return "NVPTXISD::Tex2DArrayFloatFloatGrad";
752  case NVPTXISD::Tex2DArrayS32S32: return "NVPTXISD::Tex2DArrayS32S32";
753  case NVPTXISD::Tex2DArrayS32Float: return "NVPTXISD::Tex2DArrayS32Float";
755  return "NVPTXISD::Tex2DArrayS32FloatLevel";
757  return "NVPTXISD::Tex2DArrayS32FloatGrad";
758  case NVPTXISD::Tex2DArrayU32S32: return "NVPTXISD::Tex2DArrayU32S32";
759  case NVPTXISD::Tex2DArrayU32Float: return "NVPTXISD::Tex2DArrayU32Float";
761  return "NVPTXISD::Tex2DArrayU32FloatLevel";
763  return "NVPTXISD::Tex2DArrayU32FloatGrad";
764  case NVPTXISD::Tex3DFloatS32: return "NVPTXISD::Tex3DFloatS32";
765  case NVPTXISD::Tex3DFloatFloat: return "NVPTXISD::Tex3DFloatFloat";
767  return "NVPTXISD::Tex3DFloatFloatLevel";
769  return "NVPTXISD::Tex3DFloatFloatGrad";
770  case NVPTXISD::Tex3DS32S32: return "NVPTXISD::Tex3DS32S32";
771  case NVPTXISD::Tex3DS32Float: return "NVPTXISD::Tex3DS32Float";
773  return "NVPTXISD::Tex3DS32FloatLevel";
775  return "NVPTXISD::Tex3DS32FloatGrad";
776  case NVPTXISD::Tex3DU32S32: return "NVPTXISD::Tex3DU32S32";
777  case NVPTXISD::Tex3DU32Float: return "NVPTXISD::Tex3DU32Float";
779  return "NVPTXISD::Tex3DU32FloatLevel";
781  return "NVPTXISD::Tex3DU32FloatGrad";
782  case NVPTXISD::TexCubeFloatFloat: return "NVPTXISD::TexCubeFloatFloat";
784  return "NVPTXISD::TexCubeFloatFloatLevel";
785  case NVPTXISD::TexCubeS32Float: return "NVPTXISD::TexCubeS32Float";
787  return "NVPTXISD::TexCubeS32FloatLevel";
788  case NVPTXISD::TexCubeU32Float: return "NVPTXISD::TexCubeU32Float";
790  return "NVPTXISD::TexCubeU32FloatLevel";
792  return "NVPTXISD::TexCubeArrayFloatFloat";
794  return "NVPTXISD::TexCubeArrayFloatFloatLevel";
796  return "NVPTXISD::TexCubeArrayS32Float";
798  return "NVPTXISD::TexCubeArrayS32FloatLevel";
800  return "NVPTXISD::TexCubeArrayU32Float";
802  return "NVPTXISD::TexCubeArrayU32FloatLevel";
804  return "NVPTXISD::Tld4R2DFloatFloat";
806  return "NVPTXISD::Tld4G2DFloatFloat";
808  return "NVPTXISD::Tld4B2DFloatFloat";
810  return "NVPTXISD::Tld4A2DFloatFloat";
812  return "NVPTXISD::Tld4R2DS64Float";
814  return "NVPTXISD::Tld4G2DS64Float";
816  return "NVPTXISD::Tld4B2DS64Float";
818  return "NVPTXISD::Tld4A2DS64Float";
820  return "NVPTXISD::Tld4R2DU64Float";
822  return "NVPTXISD::Tld4G2DU64Float";
824  return "NVPTXISD::Tld4B2DU64Float";
826  return "NVPTXISD::Tld4A2DU64Float";
827 
829  return "NVPTXISD::TexUnified1DFloatS32";
831  return "NVPTXISD::TexUnified1DFloatFloat";
833  return "NVPTXISD::TexUnified1DFloatFloatLevel";
835  return "NVPTXISD::TexUnified1DFloatFloatGrad";
837  return "NVPTXISD::TexUnified1DS32S32";
839  return "NVPTXISD::TexUnified1DS32Float";
841  return "NVPTXISD::TexUnified1DS32FloatLevel";
843  return "NVPTXISD::TexUnified1DS32FloatGrad";
845  return "NVPTXISD::TexUnified1DU32S32";
847  return "NVPTXISD::TexUnified1DU32Float";
849  return "NVPTXISD::TexUnified1DU32FloatLevel";
851  return "NVPTXISD::TexUnified1DU32FloatGrad";
853  return "NVPTXISD::TexUnified1DArrayFloatS32";
855  return "NVPTXISD::TexUnified1DArrayFloatFloat";
857  return "NVPTXISD::TexUnified1DArrayFloatFloatLevel";
859  return "NVPTXISD::TexUnified1DArrayFloatFloatGrad";
861  return "NVPTXISD::TexUnified1DArrayS32S32";
863  return "NVPTXISD::TexUnified1DArrayS32Float";
865  return "NVPTXISD::TexUnified1DArrayS32FloatLevel";
867  return "NVPTXISD::TexUnified1DArrayS32FloatGrad";
869  return "NVPTXISD::TexUnified1DArrayU32S32";
871  return "NVPTXISD::TexUnified1DArrayU32Float";
873  return "NVPTXISD::TexUnified1DArrayU32FloatLevel";
875  return "NVPTXISD::TexUnified1DArrayU32FloatGrad";
877  return "NVPTXISD::TexUnified2DFloatS32";
879  return "NVPTXISD::TexUnified2DFloatFloat";
881  return "NVPTXISD::TexUnified2DFloatFloatLevel";
883  return "NVPTXISD::TexUnified2DFloatFloatGrad";
885  return "NVPTXISD::TexUnified2DS32S32";
887  return "NVPTXISD::TexUnified2DS32Float";
889  return "NVPTXISD::TexUnified2DS32FloatLevel";
891  return "NVPTXISD::TexUnified2DS32FloatGrad";
893  return "NVPTXISD::TexUnified2DU32S32";
895  return "NVPTXISD::TexUnified2DU32Float";
897  return "NVPTXISD::TexUnified2DU32FloatLevel";
899  return "NVPTXISD::TexUnified2DU32FloatGrad";
901  return "NVPTXISD::TexUnified2DArrayFloatS32";
903  return "NVPTXISD::TexUnified2DArrayFloatFloat";
905  return "NVPTXISD::TexUnified2DArrayFloatFloatLevel";
907  return "NVPTXISD::TexUnified2DArrayFloatFloatGrad";
909  return "NVPTXISD::TexUnified2DArrayS32S32";
911  return "NVPTXISD::TexUnified2DArrayS32Float";
913  return "NVPTXISD::TexUnified2DArrayS32FloatLevel";
915  return "NVPTXISD::TexUnified2DArrayS32FloatGrad";
917  return "NVPTXISD::TexUnified2DArrayU32S32";
919  return "NVPTXISD::TexUnified2DArrayU32Float";
921  return "NVPTXISD::TexUnified2DArrayU32FloatLevel";
923  return "NVPTXISD::TexUnified2DArrayU32FloatGrad";
925  return "NVPTXISD::TexUnified3DFloatS32";
927  return "NVPTXISD::TexUnified3DFloatFloat";
929  return "NVPTXISD::TexUnified3DFloatFloatLevel";
931  return "NVPTXISD::TexUnified3DFloatFloatGrad";
933  return "NVPTXISD::TexUnified3DS32S32";
935  return "NVPTXISD::TexUnified3DS32Float";
937  return "NVPTXISD::TexUnified3DS32FloatLevel";
939  return "NVPTXISD::TexUnified3DS32FloatGrad";
941  return "NVPTXISD::TexUnified3DU32S32";
943  return "NVPTXISD::TexUnified3DU32Float";
945  return "NVPTXISD::TexUnified3DU32FloatLevel";
947  return "NVPTXISD::TexUnified3DU32FloatGrad";
949  return "NVPTXISD::TexUnifiedCubeFloatFloat";
951  return "NVPTXISD::TexUnifiedCubeFloatFloatLevel";
953  return "NVPTXISD::TexUnifiedCubeS32Float";
955  return "NVPTXISD::TexUnifiedCubeS32FloatLevel";
957  return "NVPTXISD::TexUnifiedCubeU32Float";
959  return "NVPTXISD::TexUnifiedCubeU32FloatLevel";
961  return "NVPTXISD::TexUnifiedCubeArrayFloatFloat";
963  return "NVPTXISD::TexUnifiedCubeArrayFloatFloatLevel";
965  return "NVPTXISD::TexUnifiedCubeArrayS32Float";
967  return "NVPTXISD::TexUnifiedCubeArrayS32FloatLevel";
969  return "NVPTXISD::TexUnifiedCubeArrayU32Float";
971  return "NVPTXISD::TexUnifiedCubeArrayU32FloatLevel";
973  return "NVPTXISD::Tld4UnifiedR2DFloatFloat";
975  return "NVPTXISD::Tld4UnifiedG2DFloatFloat";
977  return "NVPTXISD::Tld4UnifiedB2DFloatFloat";
979  return "NVPTXISD::Tld4UnifiedA2DFloatFloat";
981  return "NVPTXISD::Tld4UnifiedR2DS64Float";
983  return "NVPTXISD::Tld4UnifiedG2DS64Float";
985  return "NVPTXISD::Tld4UnifiedB2DS64Float";
987  return "NVPTXISD::Tld4UnifiedA2DS64Float";
989  return "NVPTXISD::Tld4UnifiedR2DU64Float";
991  return "NVPTXISD::Tld4UnifiedG2DU64Float";
993  return "NVPTXISD::Tld4UnifiedB2DU64Float";
995  return "NVPTXISD::Tld4UnifiedA2DU64Float";
996 
997  case NVPTXISD::Suld1DI8Clamp: return "NVPTXISD::Suld1DI8Clamp";
998  case NVPTXISD::Suld1DI16Clamp: return "NVPTXISD::Suld1DI16Clamp";
999  case NVPTXISD::Suld1DI32Clamp: return "NVPTXISD::Suld1DI32Clamp";
1000  case NVPTXISD::Suld1DI64Clamp: return "NVPTXISD::Suld1DI64Clamp";
1001  case NVPTXISD::Suld1DV2I8Clamp: return "NVPTXISD::Suld1DV2I8Clamp";
1002  case NVPTXISD::Suld1DV2I16Clamp: return "NVPTXISD::Suld1DV2I16Clamp";
1003  case NVPTXISD::Suld1DV2I32Clamp: return "NVPTXISD::Suld1DV2I32Clamp";
1004  case NVPTXISD::Suld1DV2I64Clamp: return "NVPTXISD::Suld1DV2I64Clamp";
1005  case NVPTXISD::Suld1DV4I8Clamp: return "NVPTXISD::Suld1DV4I8Clamp";
1006  case NVPTXISD::Suld1DV4I16Clamp: return "NVPTXISD::Suld1DV4I16Clamp";
1007  case NVPTXISD::Suld1DV4I32Clamp: return "NVPTXISD::Suld1DV4I32Clamp";
1008 
1009  case NVPTXISD::Suld1DArrayI8Clamp: return "NVPTXISD::Suld1DArrayI8Clamp";
1010  case NVPTXISD::Suld1DArrayI16Clamp: return "NVPTXISD::Suld1DArrayI16Clamp";
1011  case NVPTXISD::Suld1DArrayI32Clamp: return "NVPTXISD::Suld1DArrayI32Clamp";
1012  case NVPTXISD::Suld1DArrayI64Clamp: return "NVPTXISD::Suld1DArrayI64Clamp";
1013  case NVPTXISD::Suld1DArrayV2I8Clamp: return "NVPTXISD::Suld1DArrayV2I8Clamp";
1014  case NVPTXISD::Suld1DArrayV2I16Clamp:return "NVPTXISD::Suld1DArrayV2I16Clamp";
1015  case NVPTXISD::Suld1DArrayV2I32Clamp:return "NVPTXISD::Suld1DArrayV2I32Clamp";
1016  case NVPTXISD::Suld1DArrayV2I64Clamp:return "NVPTXISD::Suld1DArrayV2I64Clamp";
1017  case NVPTXISD::Suld1DArrayV4I8Clamp: return "NVPTXISD::Suld1DArrayV4I8Clamp";
1018  case NVPTXISD::Suld1DArrayV4I16Clamp:return "NVPTXISD::Suld1DArrayV4I16Clamp";
1019  case NVPTXISD::Suld1DArrayV4I32Clamp:return "NVPTXISD::Suld1DArrayV4I32Clamp";
1020 
1021  case NVPTXISD::Suld2DI8Clamp: return "NVPTXISD::Suld2DI8Clamp";
1022  case NVPTXISD::Suld2DI16Clamp: return "NVPTXISD::Suld2DI16Clamp";
1023  case NVPTXISD::Suld2DI32Clamp: return "NVPTXISD::Suld2DI32Clamp";
1024  case NVPTXISD::Suld2DI64Clamp: return "NVPTXISD::Suld2DI64Clamp";
1025  case NVPTXISD::Suld2DV2I8Clamp: return "NVPTXISD::Suld2DV2I8Clamp";
1026  case NVPTXISD::Suld2DV2I16Clamp: return "NVPTXISD::Suld2DV2I16Clamp";
1027  case NVPTXISD::Suld2DV2I32Clamp: return "NVPTXISD::Suld2DV2I32Clamp";
1028  case NVPTXISD::Suld2DV2I64Clamp: return "NVPTXISD::Suld2DV2I64Clamp";
1029  case NVPTXISD::Suld2DV4I8Clamp: return "NVPTXISD::Suld2DV4I8Clamp";
1030  case NVPTXISD::Suld2DV4I16Clamp: return "NVPTXISD::Suld2DV4I16Clamp";
1031  case NVPTXISD::Suld2DV4I32Clamp: return "NVPTXISD::Suld2DV4I32Clamp";
1032 
1033  case NVPTXISD::Suld2DArrayI8Clamp: return "NVPTXISD::Suld2DArrayI8Clamp";
1034  case NVPTXISD::Suld2DArrayI16Clamp: return "NVPTXISD::Suld2DArrayI16Clamp";
1035  case NVPTXISD::Suld2DArrayI32Clamp: return "NVPTXISD::Suld2DArrayI32Clamp";
1036  case NVPTXISD::Suld2DArrayI64Clamp: return "NVPTXISD::Suld2DArrayI64Clamp";
1037  case NVPTXISD::Suld2DArrayV2I8Clamp: return "NVPTXISD::Suld2DArrayV2I8Clamp";
1038  case NVPTXISD::Suld2DArrayV2I16Clamp:return "NVPTXISD::Suld2DArrayV2I16Clamp";
1039  case NVPTXISD::Suld2DArrayV2I32Clamp:return "NVPTXISD::Suld2DArrayV2I32Clamp";
1040  case NVPTXISD::Suld2DArrayV2I64Clamp:return "NVPTXISD::Suld2DArrayV2I64Clamp";
1041  case NVPTXISD::Suld2DArrayV4I8Clamp: return "NVPTXISD::Suld2DArrayV4I8Clamp";
1042  case NVPTXISD::Suld2DArrayV4I16Clamp:return "NVPTXISD::Suld2DArrayV4I16Clamp";
1043  case NVPTXISD::Suld2DArrayV4I32Clamp:return "NVPTXISD::Suld2DArrayV4I32Clamp";
1044 
1045  case NVPTXISD::Suld3DI8Clamp: return "NVPTXISD::Suld3DI8Clamp";
1046  case NVPTXISD::Suld3DI16Clamp: return "NVPTXISD::Suld3DI16Clamp";
1047  case NVPTXISD::Suld3DI32Clamp: return "NVPTXISD::Suld3DI32Clamp";
1048  case NVPTXISD::Suld3DI64Clamp: return "NVPTXISD::Suld3DI64Clamp";
1049  case NVPTXISD::Suld3DV2I8Clamp: return "NVPTXISD::Suld3DV2I8Clamp";
1050  case NVPTXISD::Suld3DV2I16Clamp: return "NVPTXISD::Suld3DV2I16Clamp";
1051  case NVPTXISD::Suld3DV2I32Clamp: return "NVPTXISD::Suld3DV2I32Clamp";
1052  case NVPTXISD::Suld3DV2I64Clamp: return "NVPTXISD::Suld3DV2I64Clamp";
1053  case NVPTXISD::Suld3DV4I8Clamp: return "NVPTXISD::Suld3DV4I8Clamp";
1054  case NVPTXISD::Suld3DV4I16Clamp: return "NVPTXISD::Suld3DV4I16Clamp";
1055  case NVPTXISD::Suld3DV4I32Clamp: return "NVPTXISD::Suld3DV4I32Clamp";
1056 
1057  case NVPTXISD::Suld1DI8Trap: return "NVPTXISD::Suld1DI8Trap";
1058  case NVPTXISD::Suld1DI16Trap: return "NVPTXISD::Suld1DI16Trap";
1059  case NVPTXISD::Suld1DI32Trap: return "NVPTXISD::Suld1DI32Trap";
1060  case NVPTXISD::Suld1DI64Trap: return "NVPTXISD::Suld1DI64Trap";
1061  case NVPTXISD::Suld1DV2I8Trap: return "NVPTXISD::Suld1DV2I8Trap";
1062  case NVPTXISD::Suld1DV2I16Trap: return "NVPTXISD::Suld1DV2I16Trap";
1063  case NVPTXISD::Suld1DV2I32Trap: return "NVPTXISD::Suld1DV2I32Trap";
1064  case NVPTXISD::Suld1DV2I64Trap: return "NVPTXISD::Suld1DV2I64Trap";
1065  case NVPTXISD::Suld1DV4I8Trap: return "NVPTXISD::Suld1DV4I8Trap";
1066  case NVPTXISD::Suld1DV4I16Trap: return "NVPTXISD::Suld1DV4I16Trap";
1067  case NVPTXISD::Suld1DV4I32Trap: return "NVPTXISD::Suld1DV4I32Trap";
1068 
1069  case NVPTXISD::Suld1DArrayI8Trap: return "NVPTXISD::Suld1DArrayI8Trap";
1070  case NVPTXISD::Suld1DArrayI16Trap: return "NVPTXISD::Suld1DArrayI16Trap";
1071  case NVPTXISD::Suld1DArrayI32Trap: return "NVPTXISD::Suld1DArrayI32Trap";
1072  case NVPTXISD::Suld1DArrayI64Trap: return "NVPTXISD::Suld1DArrayI64Trap";
1073  case NVPTXISD::Suld1DArrayV2I8Trap: return "NVPTXISD::Suld1DArrayV2I8Trap";
1074  case NVPTXISD::Suld1DArrayV2I16Trap: return "NVPTXISD::Suld1DArrayV2I16Trap";
1075  case NVPTXISD::Suld1DArrayV2I32Trap: return "NVPTXISD::Suld1DArrayV2I32Trap";
1076  case NVPTXISD::Suld1DArrayV2I64Trap: return "NVPTXISD::Suld1DArrayV2I64Trap";
1077  case NVPTXISD::Suld1DArrayV4I8Trap: return "NVPTXISD::Suld1DArrayV4I8Trap";
1078  case NVPTXISD::Suld1DArrayV4I16Trap: return "NVPTXISD::Suld1DArrayV4I16Trap";
1079  case NVPTXISD::Suld1DArrayV4I32Trap: return "NVPTXISD::Suld1DArrayV4I32Trap";
1080 
1081  case NVPTXISD::Suld2DI8Trap: return "NVPTXISD::Suld2DI8Trap";
1082  case NVPTXISD::Suld2DI16Trap: return "NVPTXISD::Suld2DI16Trap";
1083  case NVPTXISD::Suld2DI32Trap: return "NVPTXISD::Suld2DI32Trap";
1084  case NVPTXISD::Suld2DI64Trap: return "NVPTXISD::Suld2DI64Trap";
1085  case NVPTXISD::Suld2DV2I8Trap: return "NVPTXISD::Suld2DV2I8Trap";
1086  case NVPTXISD::Suld2DV2I16Trap: return "NVPTXISD::Suld2DV2I16Trap";
1087  case NVPTXISD::Suld2DV2I32Trap: return "NVPTXISD::Suld2DV2I32Trap";
1088  case NVPTXISD::Suld2DV2I64Trap: return "NVPTXISD::Suld2DV2I64Trap";
1089  case NVPTXISD::Suld2DV4I8Trap: return "NVPTXISD::Suld2DV4I8Trap";
1090  case NVPTXISD::Suld2DV4I16Trap: return "NVPTXISD::Suld2DV4I16Trap";
1091  case NVPTXISD::Suld2DV4I32Trap: return "NVPTXISD::Suld2DV4I32Trap";
1092 
1093  case NVPTXISD::Suld2DArrayI8Trap: return "NVPTXISD::Suld2DArrayI8Trap";
1094  case NVPTXISD::Suld2DArrayI16Trap: return "NVPTXISD::Suld2DArrayI16Trap";
1095  case NVPTXISD::Suld2DArrayI32Trap: return "NVPTXISD::Suld2DArrayI32Trap";
1096  case NVPTXISD::Suld2DArrayI64Trap: return "NVPTXISD::Suld2DArrayI64Trap";
1097  case NVPTXISD::Suld2DArrayV2I8Trap: return "NVPTXISD::Suld2DArrayV2I8Trap";
1098  case NVPTXISD::Suld2DArrayV2I16Trap: return "NVPTXISD::Suld2DArrayV2I16Trap";
1099  case NVPTXISD::Suld2DArrayV2I32Trap: return "NVPTXISD::Suld2DArrayV2I32Trap";
1100  case NVPTXISD::Suld2DArrayV2I64Trap: return "NVPTXISD::Suld2DArrayV2I64Trap";
1101  case NVPTXISD::Suld2DArrayV4I8Trap: return "NVPTXISD::Suld2DArrayV4I8Trap";
1102  case NVPTXISD::Suld2DArrayV4I16Trap: return "NVPTXISD::Suld2DArrayV4I16Trap";
1103  case NVPTXISD::Suld2DArrayV4I32Trap: return "NVPTXISD::Suld2DArrayV4I32Trap";
1104 
1105  case NVPTXISD::Suld3DI8Trap: return "NVPTXISD::Suld3DI8Trap";
1106  case NVPTXISD::Suld3DI16Trap: return "NVPTXISD::Suld3DI16Trap";
1107  case NVPTXISD::Suld3DI32Trap: return "NVPTXISD::Suld3DI32Trap";
1108  case NVPTXISD::Suld3DI64Trap: return "NVPTXISD::Suld3DI64Trap";
1109  case NVPTXISD::Suld3DV2I8Trap: return "NVPTXISD::Suld3DV2I8Trap";
1110  case NVPTXISD::Suld3DV2I16Trap: return "NVPTXISD::Suld3DV2I16Trap";
1111  case NVPTXISD::Suld3DV2I32Trap: return "NVPTXISD::Suld3DV2I32Trap";
1112  case NVPTXISD::Suld3DV2I64Trap: return "NVPTXISD::Suld3DV2I64Trap";
1113  case NVPTXISD::Suld3DV4I8Trap: return "NVPTXISD::Suld3DV4I8Trap";
1114  case NVPTXISD::Suld3DV4I16Trap: return "NVPTXISD::Suld3DV4I16Trap";
1115  case NVPTXISD::Suld3DV4I32Trap: return "NVPTXISD::Suld3DV4I32Trap";
1116 
1117  case NVPTXISD::Suld1DI8Zero: return "NVPTXISD::Suld1DI8Zero";
1118  case NVPTXISD::Suld1DI16Zero: return "NVPTXISD::Suld1DI16Zero";
1119  case NVPTXISD::Suld1DI32Zero: return "NVPTXISD::Suld1DI32Zero";
1120  case NVPTXISD::Suld1DI64Zero: return "NVPTXISD::Suld1DI64Zero";
1121  case NVPTXISD::Suld1DV2I8Zero: return "NVPTXISD::Suld1DV2I8Zero";
1122  case NVPTXISD::Suld1DV2I16Zero: return "NVPTXISD::Suld1DV2I16Zero";
1123  case NVPTXISD::Suld1DV2I32Zero: return "NVPTXISD::Suld1DV2I32Zero";
1124  case NVPTXISD::Suld1DV2I64Zero: return "NVPTXISD::Suld1DV2I64Zero";
1125  case NVPTXISD::Suld1DV4I8Zero: return "NVPTXISD::Suld1DV4I8Zero";
1126  case NVPTXISD::Suld1DV4I16Zero: return "NVPTXISD::Suld1DV4I16Zero";
1127  case NVPTXISD::Suld1DV4I32Zero: return "NVPTXISD::Suld1DV4I32Zero";
1128 
1129  case NVPTXISD::Suld1DArrayI8Zero: return "NVPTXISD::Suld1DArrayI8Zero";
1130  case NVPTXISD::Suld1DArrayI16Zero: return "NVPTXISD::Suld1DArrayI16Zero";
1131  case NVPTXISD::Suld1DArrayI32Zero: return "NVPTXISD::Suld1DArrayI32Zero";
1132  case NVPTXISD::Suld1DArrayI64Zero: return "NVPTXISD::Suld1DArrayI64Zero";
1133  case NVPTXISD::Suld1DArrayV2I8Zero: return "NVPTXISD::Suld1DArrayV2I8Zero";
1134  case NVPTXISD::Suld1DArrayV2I16Zero: return "NVPTXISD::Suld1DArrayV2I16Zero";
1135  case NVPTXISD::Suld1DArrayV2I32Zero: return "NVPTXISD::Suld1DArrayV2I32Zero";
1136  case NVPTXISD::Suld1DArrayV2I64Zero: return "NVPTXISD::Suld1DArrayV2I64Zero";
1137  case NVPTXISD::Suld1DArrayV4I8Zero: return "NVPTXISD::Suld1DArrayV4I8Zero";
1138  case NVPTXISD::Suld1DArrayV4I16Zero: return "NVPTXISD::Suld1DArrayV4I16Zero";
1139  case NVPTXISD::Suld1DArrayV4I32Zero: return "NVPTXISD::Suld1DArrayV4I32Zero";
1140 
1141  case NVPTXISD::Suld2DI8Zero: return "NVPTXISD::Suld2DI8Zero";
1142  case NVPTXISD::Suld2DI16Zero: return "NVPTXISD::Suld2DI16Zero";
1143  case NVPTXISD::Suld2DI32Zero: return "NVPTXISD::Suld2DI32Zero";
1144  case NVPTXISD::Suld2DI64Zero: return "NVPTXISD::Suld2DI64Zero";
1145  case NVPTXISD::Suld2DV2I8Zero: return "NVPTXISD::Suld2DV2I8Zero";
1146  case NVPTXISD::Suld2DV2I16Zero: return "NVPTXISD::Suld2DV2I16Zero";
1147  case NVPTXISD::Suld2DV2I32Zero: return "NVPTXISD::Suld2DV2I32Zero";
1148  case NVPTXISD::Suld2DV2I64Zero: return "NVPTXISD::Suld2DV2I64Zero";
1149  case NVPTXISD::Suld2DV4I8Zero: return "NVPTXISD::Suld2DV4I8Zero";
1150  case NVPTXISD::Suld2DV4I16Zero: return "NVPTXISD::Suld2DV4I16Zero";
1151  case NVPTXISD::Suld2DV4I32Zero: return "NVPTXISD::Suld2DV4I32Zero";
1152 
1153  case NVPTXISD::Suld2DArrayI8Zero: return "NVPTXISD::Suld2DArrayI8Zero";
1154  case NVPTXISD::Suld2DArrayI16Zero: return "NVPTXISD::Suld2DArrayI16Zero";
1155  case NVPTXISD::Suld2DArrayI32Zero: return "NVPTXISD::Suld2DArrayI32Zero";
1156  case NVPTXISD::Suld2DArrayI64Zero: return "NVPTXISD::Suld2DArrayI64Zero";
1157  case NVPTXISD::Suld2DArrayV2I8Zero: return "NVPTXISD::Suld2DArrayV2I8Zero";
1158  case NVPTXISD::Suld2DArrayV2I16Zero: return "NVPTXISD::Suld2DArrayV2I16Zero";
1159  case NVPTXISD::Suld2DArrayV2I32Zero: return "NVPTXISD::Suld2DArrayV2I32Zero";
1160  case NVPTXISD::Suld2DArrayV2I64Zero: return "NVPTXISD::Suld2DArrayV2I64Zero";
1161  case NVPTXISD::Suld2DArrayV4I8Zero: return "NVPTXISD::Suld2DArrayV4I8Zero";
1162  case NVPTXISD::Suld2DArrayV4I16Zero: return "NVPTXISD::Suld2DArrayV4I16Zero";
1163  case NVPTXISD::Suld2DArrayV4I32Zero: return "NVPTXISD::Suld2DArrayV4I32Zero";
1164 
1165  case NVPTXISD::Suld3DI8Zero: return "NVPTXISD::Suld3DI8Zero";
1166  case NVPTXISD::Suld3DI16Zero: return "NVPTXISD::Suld3DI16Zero";
1167  case NVPTXISD::Suld3DI32Zero: return "NVPTXISD::Suld3DI32Zero";
1168  case NVPTXISD::Suld3DI64Zero: return "NVPTXISD::Suld3DI64Zero";
1169  case NVPTXISD::Suld3DV2I8Zero: return "NVPTXISD::Suld3DV2I8Zero";
1170  case NVPTXISD::Suld3DV2I16Zero: return "NVPTXISD::Suld3DV2I16Zero";
1171  case NVPTXISD::Suld3DV2I32Zero: return "NVPTXISD::Suld3DV2I32Zero";
1172  case NVPTXISD::Suld3DV2I64Zero: return "NVPTXISD::Suld3DV2I64Zero";
1173  case NVPTXISD::Suld3DV4I8Zero: return "NVPTXISD::Suld3DV4I8Zero";
1174  case NVPTXISD::Suld3DV4I16Zero: return "NVPTXISD::Suld3DV4I16Zero";
1175  case NVPTXISD::Suld3DV4I32Zero: return "NVPTXISD::Suld3DV4I32Zero";
1176  }
1177  return nullptr;
1178 }
1179 
1182  if (VT.getVectorNumElements() != 1 && VT.getScalarType() == MVT::i1)
1183  return TypeSplitVector;
1184  if (VT == MVT::v2f16)
1185  return TypeLegal;
1187 }
1188 
1190  int Enabled, int &ExtraSteps,
1191  bool &UseOneConst,
1192  bool Reciprocal) const {
1193  if (!(Enabled == ReciprocalEstimate::Enabled ||
1194  (Enabled == ReciprocalEstimate::Unspecified && !usePrecSqrtF32())))
1195  return SDValue();
1196 
1197  if (ExtraSteps == ReciprocalEstimate::Unspecified)
1198  ExtraSteps = 0;
1199 
1200  SDLoc DL(Operand);
1201  EVT VT = Operand.getValueType();
1202  bool Ftz = useF32FTZ(DAG.getMachineFunction());
1203 
1204  auto MakeIntrinsicCall = [&](Intrinsic::ID IID) {
1205  return DAG.getNode(ISD::INTRINSIC_WO_CHAIN, DL, VT,
1206  DAG.getConstant(IID, DL, MVT::i32), Operand);
1207  };
1208 
1209  // The sqrt and rsqrt refinement processes assume we always start out with an
1210  // approximation of the rsqrt. Therefore, if we're going to do any refinement
1211  // (i.e. ExtraSteps > 0), we must return an rsqrt. But if we're *not* doing
1212  // any refinement, we must return a regular sqrt.
1213  if (Reciprocal || ExtraSteps > 0) {
1214  if (VT == MVT::f32)
1215  return MakeIntrinsicCall(Ftz ? Intrinsic::nvvm_rsqrt_approx_ftz_f
1216  : Intrinsic::nvvm_rsqrt_approx_f);
1217  else if (VT == MVT::f64)
1218  return MakeIntrinsicCall(Intrinsic::nvvm_rsqrt_approx_d);
1219  else
1220  return SDValue();
1221  } else {
1222  if (VT == MVT::f32)
1223  return MakeIntrinsicCall(Ftz ? Intrinsic::nvvm_sqrt_approx_ftz_f
1224  : Intrinsic::nvvm_sqrt_approx_f);
1225  else {
1226  // There's no sqrt.approx.f64 instruction, so we emit
1227  // reciprocal(rsqrt(x)). This is faster than
1228  // select(x == 0, 0, x * rsqrt(x)). (In fact, it's faster than plain
1229  // x * rsqrt(x).)
1230  return DAG.getNode(
1231  ISD::INTRINSIC_WO_CHAIN, DL, VT,
1232  DAG.getConstant(Intrinsic::nvvm_rcp_approx_ftz_d, DL, MVT::i32),
1233  MakeIntrinsicCall(Intrinsic::nvvm_rsqrt_approx_d));
1234  }
1235  }
1236 }
1237 
1238 SDValue
1240  SDLoc dl(Op);
1241  const GlobalValue *GV = cast<GlobalAddressSDNode>(Op)->getGlobal();
1242  auto PtrVT = getPointerTy(DAG.getDataLayout());
1243  Op = DAG.getTargetGlobalAddress(GV, dl, PtrVT);
1244  return DAG.getNode(NVPTXISD::Wrapper, dl, PtrVT, Op);
1245 }
1246 
1248  const DataLayout &DL, Type *retTy, const ArgListTy &Args,
1249  const SmallVectorImpl<ISD::OutputArg> &Outs, unsigned retAlignment,
1250  const ImmutableCallSite *CS) const {
1251  auto PtrVT = getPointerTy(DL);
1252 
1253  bool isABI = (STI.getSmVersion() >= 20);
1254  assert(isABI && "Non-ABI compilation is not supported");
1255  if (!isABI)
1256  return "";
1257 
1258  std::stringstream O;
1259  O << "prototype_" << uniqueCallSite << " : .callprototype ";
1260 
1261  if (retTy->getTypeID() == Type::VoidTyID) {
1262  O << "()";
1263  } else {
1264  O << "(";
1265  if (retTy->isFloatingPointTy() || retTy->isIntegerTy()) {
1266  unsigned size = 0;
1267  if (auto *ITy = dyn_cast<IntegerType>(retTy)) {
1268  size = ITy->getBitWidth();
1269  } else {
1270  assert(retTy->isFloatingPointTy() &&
1271  "Floating point type expected here");
1272  size = retTy->getPrimitiveSizeInBits();
1273  }
1274  // PTX ABI requires all scalar return values to be at least 32
1275  // bits in size. fp16 normally uses .b16 as its storage type in
1276  // PTX, so its size must be adjusted here, too.
1277  if (size < 32)
1278  size = 32;
1279 
1280  O << ".param .b" << size << " _";
1281  } else if (isa<PointerType>(retTy)) {
1282  O << ".param .b" << PtrVT.getSizeInBits() << " _";
1283  } else if (retTy->isAggregateType() || retTy->isVectorTy()) {
1284  auto &DL = CS->getCalledFunction()->getParent()->getDataLayout();
1285  O << ".param .align " << retAlignment << " .b8 _["
1286  << DL.getTypeAllocSize(retTy) << "]";
1287  } else {
1288  llvm_unreachable("Unknown return type");
1289  }
1290  O << ") ";
1291  }
1292  O << "_ (";
1293 
1294  bool first = true;
1295 
1296  unsigned OIdx = 0;
1297  for (unsigned i = 0, e = Args.size(); i != e; ++i, ++OIdx) {
1298  Type *Ty = Args[i].Ty;
1299  if (!first) {
1300  O << ", ";
1301  }
1302  first = false;
1303 
1304  if (!Outs[OIdx].Flags.isByVal()) {
1305  if (Ty->isAggregateType() || Ty->isVectorTy()) {
1306  unsigned align = 0;
1307  const CallInst *CallI = cast<CallInst>(CS->getInstruction());
1308  // +1 because index 0 is reserved for return type alignment
1309  if (!getAlign(*CallI, i + 1, align))
1310  align = DL.getABITypeAlignment(Ty);
1311  unsigned sz = DL.getTypeAllocSize(Ty);
1312  O << ".param .align " << align << " .b8 ";
1313  O << "_";
1314  O << "[" << sz << "]";
1315  // update the index for Outs
1316  SmallVector<EVT, 16> vtparts;
1317  ComputeValueVTs(*this, DL, Ty, vtparts);
1318  if (unsigned len = vtparts.size())
1319  OIdx += len - 1;
1320  continue;
1321  }
1322  // i8 types in IR will be i16 types in SDAG
1323  assert((getValueType(DL, Ty) == Outs[OIdx].VT ||
1324  (getValueType(DL, Ty) == MVT::i8 && Outs[OIdx].VT == MVT::i16)) &&
1325  "type mismatch between callee prototype and arguments");
1326  // scalar type
1327  unsigned sz = 0;
1328  if (isa<IntegerType>(Ty)) {
1329  sz = cast<IntegerType>(Ty)->getBitWidth();
1330  if (sz < 32)
1331  sz = 32;
1332  } else if (isa<PointerType>(Ty)) {
1333  sz = PtrVT.getSizeInBits();
1334  } else if (Ty->isHalfTy())
1335  // PTX ABI requires all scalar parameters to be at least 32
1336  // bits in size. fp16 normally uses .b16 as its storage type
1337  // in PTX, so its size must be adjusted here, too.
1338  sz = 32;
1339  else
1340  sz = Ty->getPrimitiveSizeInBits();
1341  O << ".param .b" << sz << " ";
1342  O << "_";
1343  continue;
1344  }
1345  auto *PTy = dyn_cast<PointerType>(Ty);
1346  assert(PTy && "Param with byval attribute should be a pointer type");
1347  Type *ETy = PTy->getElementType();
1348 
1349  unsigned align = Outs[OIdx].Flags.getByValAlign();
1350  unsigned sz = DL.getTypeAllocSize(ETy);
1351  O << ".param .align " << align << " .b8 ";
1352  O << "_";
1353  O << "[" << sz << "]";
1354  }
1355  O << ");";
1356  return O.str();
1357 }
1358 
1359 unsigned NVPTXTargetLowering::getArgumentAlignment(SDValue Callee,
1360  const ImmutableCallSite *CS,
1361  Type *Ty, unsigned Idx,
1362  const DataLayout &DL) const {
1363  if (!CS) {
1364  // CallSite is zero, fallback to ABI type alignment
1365  return DL.getABITypeAlignment(Ty);
1366  }
1367 
1368  unsigned Align = 0;
1369  const Value *DirectCallee = CS->getCalledFunction();
1370 
1371  if (!DirectCallee) {
1372  // We don't have a direct function symbol, but that may be because of
1373  // constant cast instructions in the call.
1374  const Instruction *CalleeI = CS->getInstruction();
1375  assert(CalleeI && "Call target is not a function or derived value?");
1376 
1377  // With bitcast'd call targets, the instruction will be the call
1378  if (isa<CallInst>(CalleeI)) {
1379  // Check if we have call alignment metadata
1380  if (getAlign(*cast<CallInst>(CalleeI), Idx, Align))
1381  return Align;
1382 
1383  const Value *CalleeV = cast<CallInst>(CalleeI)->getCalledValue();
1384  // Ignore any bitcast instructions
1385  while (isa<ConstantExpr>(CalleeV)) {
1386  const ConstantExpr *CE = cast<ConstantExpr>(CalleeV);
1387  if (!CE->isCast())
1388  break;
1389  // Look through the bitcast
1390  CalleeV = cast<ConstantExpr>(CalleeV)->getOperand(0);
1391  }
1392 
1393  // We have now looked past all of the bitcasts. Do we finally have a
1394  // Function?
1395  if (isa<Function>(CalleeV))
1396  DirectCallee = CalleeV;
1397  }
1398  }
1399 
1400  // Check for function alignment information if we found that the
1401  // ultimate target is a Function
1402  if (DirectCallee)
1403  if (getAlign(*cast<Function>(DirectCallee), Idx, Align))
1404  return Align;
1405 
1406  // Call is indirect or alignment information is not available, fall back to
1407  // the ABI type alignment
1408  return DL.getABITypeAlignment(Ty);
1409 }
1410 
1412  SmallVectorImpl<SDValue> &InVals) const {
1413  SelectionDAG &DAG = CLI.DAG;
1414  SDLoc dl = CLI.DL;
1416  SmallVectorImpl<SDValue> &OutVals = CLI.OutVals;
1418  SDValue Chain = CLI.Chain;
1419  SDValue Callee = CLI.Callee;
1420  bool &isTailCall = CLI.IsTailCall;
1421  ArgListTy &Args = CLI.getArgs();
1422  Type *RetTy = CLI.RetTy;
1423  ImmutableCallSite *CS = CLI.CS;
1424  const DataLayout &DL = DAG.getDataLayout();
1425 
1426  bool isABI = (STI.getSmVersion() >= 20);
1427  assert(isABI && "Non-ABI compilation is not supported");
1428  if (!isABI)
1429  return Chain;
1430 
1431  SDValue tempChain = Chain;
1432  Chain = DAG.getCALLSEQ_START(Chain, uniqueCallSite, 0, dl);
1433  SDValue InFlag = Chain.getValue(1);
1434 
1435  unsigned paramCount = 0;
1436  // Args.size() and Outs.size() need not match.
1437  // Outs.size() will be larger
1438  // * if there is an aggregate argument with multiple fields (each field
1439  // showing up separately in Outs)
1440  // * if there is a vector argument with more than typical vector-length
1441  // elements (generally if more than 4) where each vector element is
1442  // individually present in Outs.
1443  // So a different index should be used for indexing into Outs/OutVals.
1444  // See similar issue in LowerFormalArguments.
1445  unsigned OIdx = 0;
1446  // Declare the .params or .reg need to pass values
1447  // to the function
1448  for (unsigned i = 0, e = Args.size(); i != e; ++i, ++OIdx) {
1449  EVT VT = Outs[OIdx].VT;
1450  Type *Ty = Args[i].Ty;
1451 
1452  if (!Outs[OIdx].Flags.isByVal()) {
1455  ComputePTXValueVTs(*this, DL, Ty, VTs, &Offsets);
1456  unsigned ArgAlign =
1457  getArgumentAlignment(Callee, CS, Ty, paramCount + 1, DL);
1458  unsigned AllocSize = DL.getTypeAllocSize(Ty);
1459  SDVTList DeclareParamVTs = DAG.getVTList(MVT::Other, MVT::Glue);
1460  bool NeedAlign; // Does argument declaration specify alignment?
1461  if (Ty->isAggregateType() || Ty->isVectorTy()) {
1462  // declare .param .align <align> .b8 .param<n>[<size>];
1463  SDValue DeclareParamOps[] = {
1464  Chain, DAG.getConstant(ArgAlign, dl, MVT::i32),
1465  DAG.getConstant(paramCount, dl, MVT::i32),
1466  DAG.getConstant(AllocSize, dl, MVT::i32), InFlag};
1467  Chain = DAG.getNode(NVPTXISD::DeclareParam, dl, DeclareParamVTs,
1468  DeclareParamOps);
1469  NeedAlign = true;
1470  } else {
1471  // declare .param .b<size> .param<n>;
1472  if ((VT.isInteger() || VT.isFloatingPoint()) && AllocSize < 4) {
1473  // PTX ABI requires integral types to be at least 32 bits in
1474  // size. FP16 is loaded/stored using i16, so it's handled
1475  // here as well.
1476  AllocSize = 4;
1477  }
1478  SDValue DeclareScalarParamOps[] = {
1479  Chain, DAG.getConstant(paramCount, dl, MVT::i32),
1480  DAG.getConstant(AllocSize * 8, dl, MVT::i32),
1481  DAG.getConstant(0, dl, MVT::i32), InFlag};
1482  Chain = DAG.getNode(NVPTXISD::DeclareScalarParam, dl, DeclareParamVTs,
1483  DeclareScalarParamOps);
1484  NeedAlign = false;
1485  }
1486  InFlag = Chain.getValue(1);
1487 
1488  // PTX Interoperability Guide 3.3(A): [Integer] Values shorter
1489  // than 32-bits are sign extended or zero extended, depending on
1490  // whether they are signed or unsigned types. This case applies
1491  // only to scalar parameters and not to aggregate values.
1492  bool ExtendIntegerParam =
1493  Ty->isIntegerTy() && DL.getTypeAllocSizeInBits(Ty) < 32;
1494 
1495  auto VectorInfo = VectorizePTXValueVTs(VTs, Offsets, ArgAlign);
1496  SmallVector<SDValue, 6> StoreOperands;
1497  for (unsigned j = 0, je = VTs.size(); j != je; ++j) {
1498  // New store.
1499  if (VectorInfo[j] & PVF_FIRST) {
1500  assert(StoreOperands.empty() && "Unfinished preceeding store.");
1501  StoreOperands.push_back(Chain);
1502  StoreOperands.push_back(DAG.getConstant(paramCount, dl, MVT::i32));
1503  StoreOperands.push_back(DAG.getConstant(Offsets[j], dl, MVT::i32));
1504  }
1505 
1506  EVT EltVT = VTs[j];
1507  SDValue StVal = OutVals[OIdx];
1508  if (ExtendIntegerParam) {
1509  assert(VTs.size() == 1 && "Scalar can't have multiple parts.");
1510  // zext/sext to i32
1511  StVal = DAG.getNode(Outs[OIdx].Flags.isSExt() ? ISD::SIGN_EXTEND
1512  : ISD::ZERO_EXTEND,
1513  dl, MVT::i32, StVal);
1514  } else if (EltVT.getSizeInBits() < 16) {
1515  // Use 16-bit registers for small stores as it's the
1516  // smallest general purpose register size supported by NVPTX.
1517  StVal = DAG.getNode(ISD::ANY_EXTEND, dl, MVT::i16, StVal);
1518  }
1519 
1520  // Record the value to store.
1521  StoreOperands.push_back(StVal);
1522 
1523  if (VectorInfo[j] & PVF_LAST) {
1524  unsigned NumElts = StoreOperands.size() - 3;
1526  switch (NumElts) {
1527  case 1:
1528  Op = NVPTXISD::StoreParam;
1529  break;
1530  case 2:
1532  break;
1533  case 4:
1535  break;
1536  default:
1537  llvm_unreachable("Invalid vector info.");
1538  }
1539 
1540  StoreOperands.push_back(InFlag);
1541 
1542  // Adjust type of the store op if we've extended the scalar
1543  // return value.
1544  EVT TheStoreType = ExtendIntegerParam ? MVT::i32 : VTs[j];
1545  unsigned EltAlign =
1546  NeedAlign ? GreatestCommonDivisor64(ArgAlign, Offsets[j]) : 0;
1547 
1548  Chain = DAG.getMemIntrinsicNode(
1549  Op, dl, DAG.getVTList(MVT::Other, MVT::Glue), StoreOperands,
1550  TheStoreType, MachinePointerInfo(), EltAlign,
1551  /* Volatile */ false, /* ReadMem */ false,
1552  /* WriteMem */ true, /* Size */ 0);
1553  InFlag = Chain.getValue(1);
1554 
1555  // Cleanup.
1556  StoreOperands.clear();
1557  }
1558  ++OIdx;
1559  }
1560  assert(StoreOperands.empty() && "Unfinished parameter store.");
1561  if (VTs.size() > 0)
1562  --OIdx;
1563  ++paramCount;
1564  continue;
1565  }
1566 
1567  // ByVal arguments
1570  auto *PTy = dyn_cast<PointerType>(Args[i].Ty);
1571  assert(PTy && "Type of a byval parameter should be pointer");
1572  ComputePTXValueVTs(*this, DL, PTy->getElementType(), VTs, &Offsets, 0);
1573 
1574  // declare .param .align <align> .b8 .param<n>[<size>];
1575  unsigned sz = Outs[OIdx].Flags.getByValSize();
1576  SDVTList DeclareParamVTs = DAG.getVTList(MVT::Other, MVT::Glue);
1577  unsigned ArgAlign = Outs[OIdx].Flags.getByValAlign();
1578  // The ByValAlign in the Outs[OIdx].Flags is alway set at this point,
1579  // so we don't need to worry about natural alignment or not.
1580  // See TargetLowering::LowerCallTo().
1581 
1582  // Enforce minumum alignment of 4 to work around ptxas miscompile
1583  // for sm_50+. See corresponding alignment adjustment in
1584  // emitFunctionParamList() for details.
1585  if (ArgAlign < 4)
1586  ArgAlign = 4;
1587  SDValue DeclareParamOps[] = {Chain, DAG.getConstant(ArgAlign, dl, MVT::i32),
1588  DAG.getConstant(paramCount, dl, MVT::i32),
1589  DAG.getConstant(sz, dl, MVT::i32), InFlag};
1590  Chain = DAG.getNode(NVPTXISD::DeclareParam, dl, DeclareParamVTs,
1591  DeclareParamOps);
1592  InFlag = Chain.getValue(1);
1593  for (unsigned j = 0, je = VTs.size(); j != je; ++j) {
1594  EVT elemtype = VTs[j];
1595  int curOffset = Offsets[j];
1596  unsigned PartAlign = GreatestCommonDivisor64(ArgAlign, curOffset);
1597  auto PtrVT = getPointerTy(DL);
1598  SDValue srcAddr = DAG.getNode(ISD::ADD, dl, PtrVT, OutVals[OIdx],
1599  DAG.getConstant(curOffset, dl, PtrVT));
1600  SDValue theVal = DAG.getLoad(elemtype, dl, tempChain, srcAddr,
1601  MachinePointerInfo(), PartAlign);
1602  if (elemtype.getSizeInBits() < 16) {
1603  theVal = DAG.getNode(ISD::ANY_EXTEND, dl, MVT::i16, theVal);
1604  }
1605  SDVTList CopyParamVTs = DAG.getVTList(MVT::Other, MVT::Glue);
1606  SDValue CopyParamOps[] = { Chain,
1607  DAG.getConstant(paramCount, dl, MVT::i32),
1608  DAG.getConstant(curOffset, dl, MVT::i32),
1609  theVal, InFlag };
1610  Chain = DAG.getMemIntrinsicNode(NVPTXISD::StoreParam, dl, CopyParamVTs,
1611  CopyParamOps, elemtype,
1612  MachinePointerInfo(), /* Align */ 0,
1613  /* Volatile */ false, /* ReadMem */ false,
1614  /* WriteMem */ true, /* Size */ 0);
1615 
1616  InFlag = Chain.getValue(1);
1617  }
1618  ++paramCount;
1619  }
1620 
1622  unsigned retAlignment = 0;
1623 
1624  // Handle Result
1625  if (Ins.size() > 0) {
1626  SmallVector<EVT, 16> resvtparts;
1627  ComputeValueVTs(*this, DL, RetTy, resvtparts);
1628 
1629  // Declare
1630  // .param .align 16 .b8 retval0[<size-in-bytes>], or
1631  // .param .b<size-in-bits> retval0
1632  unsigned resultsz = DL.getTypeAllocSizeInBits(RetTy);
1633  // Emit ".param .b<size-in-bits> retval0" instead of byte arrays only for
1634  // these three types to match the logic in
1635  // NVPTXAsmPrinter::printReturnValStr and NVPTXTargetLowering::getPrototype.
1636  // Plus, this behavior is consistent with nvcc's.
1637  if (RetTy->isFloatingPointTy() || RetTy->isIntegerTy() ||
1638  RetTy->isPointerTy()) {
1639  // Scalar needs to be at least 32bit wide
1640  if (resultsz < 32)
1641  resultsz = 32;
1642  SDVTList DeclareRetVTs = DAG.getVTList(MVT::Other, MVT::Glue);
1643  SDValue DeclareRetOps[] = { Chain, DAG.getConstant(1, dl, MVT::i32),
1644  DAG.getConstant(resultsz, dl, MVT::i32),
1645  DAG.getConstant(0, dl, MVT::i32), InFlag };
1646  Chain = DAG.getNode(NVPTXISD::DeclareRet, dl, DeclareRetVTs,
1647  DeclareRetOps);
1648  InFlag = Chain.getValue(1);
1649  } else {
1650  retAlignment = getArgumentAlignment(Callee, CS, RetTy, 0, DL);
1651  SDVTList DeclareRetVTs = DAG.getVTList(MVT::Other, MVT::Glue);
1652  SDValue DeclareRetOps[] = { Chain,
1653  DAG.getConstant(retAlignment, dl, MVT::i32),
1654  DAG.getConstant(resultsz / 8, dl, MVT::i32),
1655  DAG.getConstant(0, dl, MVT::i32), InFlag };
1656  Chain = DAG.getNode(NVPTXISD::DeclareRetParam, dl, DeclareRetVTs,
1657  DeclareRetOps);
1658  InFlag = Chain.getValue(1);
1659  }
1660  }
1661 
1662  if (!Func) {
1663  // This is indirect function call case : PTX requires a prototype of the
1664  // form
1665  // proto_0 : .callprototype(.param .b32 _) _ (.param .b32 _);
1666  // to be emitted, and the label has to used as the last arg of call
1667  // instruction.
1668  // The prototype is embedded in a string and put as the operand for a
1669  // CallPrototype SDNode which will print out to the value of the string.
1670  SDVTList ProtoVTs = DAG.getVTList(MVT::Other, MVT::Glue);
1671  std::string Proto = getPrototype(DL, RetTy, Args, Outs, retAlignment, CS);
1672  const char *ProtoStr =
1673  nvTM->getManagedStrPool()->getManagedString(Proto.c_str())->c_str();
1674  SDValue ProtoOps[] = {
1675  Chain, DAG.getTargetExternalSymbol(ProtoStr, MVT::i32), InFlag,
1676  };
1677  Chain = DAG.getNode(NVPTXISD::CallPrototype, dl, ProtoVTs, ProtoOps);
1678  InFlag = Chain.getValue(1);
1679  }
1680  // Op to just print "call"
1681  SDVTList PrintCallVTs = DAG.getVTList(MVT::Other, MVT::Glue);
1682  SDValue PrintCallOps[] = {
1683  Chain, DAG.getConstant((Ins.size() == 0) ? 0 : 1, dl, MVT::i32), InFlag
1684  };
1685  // We model convergent calls as separate opcodes.
1686  unsigned Opcode = Func ? NVPTXISD::PrintCallUni : NVPTXISD::PrintCall;
1687  if (CLI.IsConvergent)
1690  Chain = DAG.getNode(Opcode, dl, PrintCallVTs, PrintCallOps);
1691  InFlag = Chain.getValue(1);
1692 
1693  // Ops to print out the function name
1694  SDVTList CallVoidVTs = DAG.getVTList(MVT::Other, MVT::Glue);
1695  SDValue CallVoidOps[] = { Chain, Callee, InFlag };
1696  Chain = DAG.getNode(NVPTXISD::CallVoid, dl, CallVoidVTs, CallVoidOps);
1697  InFlag = Chain.getValue(1);
1698 
1699  // Ops to print out the param list
1700  SDVTList CallArgBeginVTs = DAG.getVTList(MVT::Other, MVT::Glue);
1701  SDValue CallArgBeginOps[] = { Chain, InFlag };
1702  Chain = DAG.getNode(NVPTXISD::CallArgBegin, dl, CallArgBeginVTs,
1703  CallArgBeginOps);
1704  InFlag = Chain.getValue(1);
1705 
1706  for (unsigned i = 0, e = paramCount; i != e; ++i) {
1707  unsigned opcode;
1708  if (i == (e - 1))
1709  opcode = NVPTXISD::LastCallArg;
1710  else
1711  opcode = NVPTXISD::CallArg;
1712  SDVTList CallArgVTs = DAG.getVTList(MVT::Other, MVT::Glue);
1713  SDValue CallArgOps[] = { Chain, DAG.getConstant(1, dl, MVT::i32),
1714  DAG.getConstant(i, dl, MVT::i32), InFlag };
1715  Chain = DAG.getNode(opcode, dl, CallArgVTs, CallArgOps);
1716  InFlag = Chain.getValue(1);
1717  }
1718  SDVTList CallArgEndVTs = DAG.getVTList(MVT::Other, MVT::Glue);
1719  SDValue CallArgEndOps[] = { Chain,
1720  DAG.getConstant(Func ? 1 : 0, dl, MVT::i32),
1721  InFlag };
1722  Chain = DAG.getNode(NVPTXISD::CallArgEnd, dl, CallArgEndVTs, CallArgEndOps);
1723  InFlag = Chain.getValue(1);
1724 
1725  if (!Func) {
1726  SDVTList PrototypeVTs = DAG.getVTList(MVT::Other, MVT::Glue);
1727  SDValue PrototypeOps[] = { Chain,
1729  InFlag };
1730  Chain = DAG.getNode(NVPTXISD::Prototype, dl, PrototypeVTs, PrototypeOps);
1731  InFlag = Chain.getValue(1);
1732  }
1733 
1734  // Generate loads from param memory/moves from registers for result
1735  if (Ins.size() > 0) {
1738  ComputePTXValueVTs(*this, DL, RetTy, VTs, &Offsets, 0);
1739  assert(VTs.size() == Ins.size() && "Bad value decomposition");
1740 
1741  unsigned RetAlign = getArgumentAlignment(Callee, CS, RetTy, 0, DL);
1742  auto VectorInfo = VectorizePTXValueVTs(VTs, Offsets, RetAlign);
1743 
1744  SmallVector<EVT, 6> LoadVTs;
1745  int VecIdx = -1; // Index of the first element of the vector.
1746 
1747  // PTX Interoperability Guide 3.3(A): [Integer] Values shorter than
1748  // 32-bits are sign extended or zero extended, depending on whether
1749  // they are signed or unsigned types.
1750  bool ExtendIntegerRetVal =
1751  RetTy->isIntegerTy() && DL.getTypeAllocSizeInBits(RetTy) < 32;
1752 
1753  for (unsigned i = 0, e = VTs.size(); i != e; ++i) {
1754  bool needTruncate = false;
1755  EVT TheLoadType = VTs[i];
1756  EVT EltType = Ins[i].VT;
1757  unsigned EltAlign = GreatestCommonDivisor64(RetAlign, Offsets[i]);
1758  if (ExtendIntegerRetVal) {
1759  TheLoadType = MVT::i32;
1760  EltType = MVT::i32;
1761  needTruncate = true;
1762  } else if (TheLoadType.getSizeInBits() < 16) {
1763  if (VTs[i].isInteger())
1764  needTruncate = true;
1765  EltType = MVT::i16;
1766  }
1767 
1768  // Record index of the very first element of the vector.
1769  if (VectorInfo[i] & PVF_FIRST) {
1770  assert(VecIdx == -1 && LoadVTs.empty() && "Orphaned operand list.");
1771  VecIdx = i;
1772  }
1773 
1774  LoadVTs.push_back(EltType);
1775 
1776  if (VectorInfo[i] & PVF_LAST) {
1777  unsigned NumElts = LoadVTs.size();
1778  LoadVTs.push_back(MVT::Other);
1779  LoadVTs.push_back(MVT::Glue);
1781  switch (NumElts) {
1782  case 1:
1783  Op = NVPTXISD::LoadParam;
1784  break;
1785  case 2:
1786  Op = NVPTXISD::LoadParamV2;
1787  break;
1788  case 4:
1789  Op = NVPTXISD::LoadParamV4;
1790  break;
1791  default:
1792  llvm_unreachable("Invalid vector info.");
1793  }
1794 
1795  SDValue LoadOperands[] = {
1796  Chain, DAG.getConstant(1, dl, MVT::i32),
1797  DAG.getConstant(Offsets[VecIdx], dl, MVT::i32), InFlag};
1798  SDValue RetVal = DAG.getMemIntrinsicNode(
1799  Op, dl, DAG.getVTList(LoadVTs), LoadOperands, TheLoadType,
1800  MachinePointerInfo(), EltAlign, /* Volatile */ false,
1801  /* ReadMem */ true, /* WriteMem */ false, /* Size */ 0);
1802 
1803  for (unsigned j = 0; j < NumElts; ++j) {
1804  SDValue Ret = RetVal.getValue(j);
1805  if (needTruncate)
1806  Ret = DAG.getNode(ISD::TRUNCATE, dl, Ins[VecIdx + j].VT, Ret);
1807  InVals.push_back(Ret);
1808  }
1809  Chain = RetVal.getValue(NumElts);
1810  InFlag = RetVal.getValue(NumElts + 1);
1811 
1812  // Cleanup
1813  VecIdx = -1;
1814  LoadVTs.clear();
1815  }
1816  }
1817  }
1818 
1819  Chain = DAG.getCALLSEQ_END(Chain,
1820  DAG.getIntPtrConstant(uniqueCallSite, dl, true),
1821  DAG.getIntPtrConstant(uniqueCallSite + 1, dl,
1822  true),
1823  InFlag, dl);
1824  uniqueCallSite++;
1825 
1826  // set isTailCall to false for now, until we figure out how to express
1827  // tail call optimization in PTX
1828  isTailCall = false;
1829  return Chain;
1830 }
1831 
1832 // By default CONCAT_VECTORS is lowered by ExpandVectorBuildThroughStack()
1833 // (see LegalizeDAG.cpp). This is slow and uses local memory.
1834 // We use extract/insert/build vector just as what LegalizeOp() does in llvm 2.5
1835 SDValue
1836 NVPTXTargetLowering::LowerCONCAT_VECTORS(SDValue Op, SelectionDAG &DAG) const {
1837  SDNode *Node = Op.getNode();
1838  SDLoc dl(Node);
1840  unsigned NumOperands = Node->getNumOperands();
1841  for (unsigned i = 0; i < NumOperands; ++i) {
1842  SDValue SubOp = Node->getOperand(i);
1843  EVT VVT = SubOp.getNode()->getValueType(0);
1844  EVT EltVT = VVT.getVectorElementType();
1845  unsigned NumSubElem = VVT.getVectorNumElements();
1846  for (unsigned j = 0; j < NumSubElem; ++j) {
1847  Ops.push_back(DAG.getNode(ISD::EXTRACT_VECTOR_ELT, dl, EltVT, SubOp,
1848  DAG.getIntPtrConstant(j, dl)));
1849  }
1850  }
1851  return DAG.getBuildVector(Node->getValueType(0), dl, Ops);
1852 }
1853 
1854 // We can init constant f16x2 with a single .b32 move. Normally it
1855 // would get lowered as two constant loads and vector-packing move.
1856 // mov.b16 %h1, 0x4000;
1857 // mov.b16 %h2, 0x3C00;
1858 // mov.b32 %hh2, {%h2, %h1};
1859 // Instead we want just a constant move:
1860 // mov.b32 %hh2, 0x40003C00
1861 //
1862 // This results in better SASS code with CUDA 7.x. Ptxas in CUDA 8.0
1863 // generates good SASS in both cases.
1864 SDValue NVPTXTargetLowering::LowerBUILD_VECTOR(SDValue Op,
1865  SelectionDAG &DAG) const {
1866  //return Op;
1867  if (!(Op->getValueType(0) == MVT::v2f16 &&
1868  isa<ConstantFPSDNode>(Op->getOperand(0)) &&
1869  isa<ConstantFPSDNode>(Op->getOperand(1))))
1870  return Op;
1871 
1872  APInt E0 =
1873  cast<ConstantFPSDNode>(Op->getOperand(0))->getValueAPF().bitcastToAPInt();
1874  APInt E1 =
1875  cast<ConstantFPSDNode>(Op->getOperand(1))->getValueAPF().bitcastToAPInt();
1876  SDValue Const =
1877  DAG.getConstant(E1.zext(32).shl(16) | E0.zext(32), SDLoc(Op), MVT::i32);
1878  return DAG.getNode(ISD::BITCAST, SDLoc(Op), MVT::v2f16, Const);
1879 }
1880 
1881 SDValue NVPTXTargetLowering::LowerEXTRACT_VECTOR_ELT(SDValue Op,
1882  SelectionDAG &DAG) const {
1883  SDValue Index = Op->getOperand(1);
1884  // Constant index will be matched by tablegen.
1885  if (isa<ConstantSDNode>(Index.getNode()))
1886  return Op;
1887 
1888  // Extract individual elements and select one of them.
1889  SDValue Vector = Op->getOperand(0);
1890  EVT VectorVT = Vector.getValueType();
1891  assert(VectorVT == MVT::v2f16 && "Unexpected vector type.");
1892  EVT EltVT = VectorVT.getVectorElementType();
1893 
1894  SDLoc dl(Op.getNode());
1895  SDValue E0 = DAG.getNode(ISD::EXTRACT_VECTOR_ELT, dl, EltVT, Vector,
1896  DAG.getIntPtrConstant(0, dl));
1897  SDValue E1 = DAG.getNode(ISD::EXTRACT_VECTOR_ELT, dl, EltVT, Vector,
1898  DAG.getIntPtrConstant(1, dl));
1899  return DAG.getSelectCC(dl, Index, DAG.getIntPtrConstant(0, dl), E0, E1,
1901 }
1902 
1903 /// LowerShiftRightParts - Lower SRL_PARTS, SRA_PARTS, which
1904 /// 1) returns two i32 values and take a 2 x i32 value to shift plus a shift
1905 /// amount, or
1906 /// 2) returns two i64 values and take a 2 x i64 value to shift plus a shift
1907 /// amount.
1908 SDValue NVPTXTargetLowering::LowerShiftRightParts(SDValue Op,
1909  SelectionDAG &DAG) const {
1910  assert(Op.getNumOperands() == 3 && "Not a double-shift!");
1912 
1913  EVT VT = Op.getValueType();
1914  unsigned VTBits = VT.getSizeInBits();
1915  SDLoc dl(Op);
1916  SDValue ShOpLo = Op.getOperand(0);
1917  SDValue ShOpHi = Op.getOperand(1);
1918  SDValue ShAmt = Op.getOperand(2);
1919  unsigned Opc = (Op.getOpcode() == ISD::SRA_PARTS) ? ISD::SRA : ISD::SRL;
1920 
1921  if (VTBits == 32 && STI.getSmVersion() >= 35) {
1922  // For 32bit and sm35, we can use the funnel shift 'shf' instruction.
1923  // {dHi, dLo} = {aHi, aLo} >> Amt
1924  // dHi = aHi >> Amt
1925  // dLo = shf.r.clamp aLo, aHi, Amt
1926 
1927  SDValue Hi = DAG.getNode(Opc, dl, VT, ShOpHi, ShAmt);
1928  SDValue Lo = DAG.getNode(NVPTXISD::FUN_SHFR_CLAMP, dl, VT, ShOpLo, ShOpHi,
1929  ShAmt);
1930 
1931  SDValue Ops[2] = { Lo, Hi };
1932  return DAG.getMergeValues(Ops, dl);
1933  }
1934  else {
1935  // {dHi, dLo} = {aHi, aLo} >> Amt
1936  // - if (Amt>=size) then
1937  // dLo = aHi >> (Amt-size)
1938  // dHi = aHi >> Amt (this is either all 0 or all 1)
1939  // else
1940  // dLo = (aLo >>logic Amt) | (aHi << (size-Amt))
1941  // dHi = aHi >> Amt
1942 
1943  SDValue RevShAmt = DAG.getNode(ISD::SUB, dl, MVT::i32,
1944  DAG.getConstant(VTBits, dl, MVT::i32),
1945  ShAmt);
1946  SDValue Tmp1 = DAG.getNode(ISD::SRL, dl, VT, ShOpLo, ShAmt);
1947  SDValue ExtraShAmt = DAG.getNode(ISD::SUB, dl, MVT::i32, ShAmt,
1948  DAG.getConstant(VTBits, dl, MVT::i32));
1949  SDValue Tmp2 = DAG.getNode(ISD::SHL, dl, VT, ShOpHi, RevShAmt);
1950  SDValue FalseVal = DAG.getNode(ISD::OR, dl, VT, Tmp1, Tmp2);
1951  SDValue TrueVal = DAG.getNode(Opc, dl, VT, ShOpHi, ExtraShAmt);
1952 
1953  SDValue Cmp = DAG.getSetCC(dl, MVT::i1, ShAmt,
1954  DAG.getConstant(VTBits, dl, MVT::i32),
1955  ISD::SETGE);
1956  SDValue Hi = DAG.getNode(Opc, dl, VT, ShOpHi, ShAmt);
1957  SDValue Lo = DAG.getNode(ISD::SELECT, dl, VT, Cmp, TrueVal, FalseVal);
1958 
1959  SDValue Ops[2] = { Lo, Hi };
1960  return DAG.getMergeValues(Ops, dl);
1961  }
1962 }
1963 
1964 /// LowerShiftLeftParts - Lower SHL_PARTS, which
1965 /// 1) returns two i32 values and take a 2 x i32 value to shift plus a shift
1966 /// amount, or
1967 /// 2) returns two i64 values and take a 2 x i64 value to shift plus a shift
1968 /// amount.
1969 SDValue NVPTXTargetLowering::LowerShiftLeftParts(SDValue Op,
1970  SelectionDAG &DAG) const {
1971  assert(Op.getNumOperands() == 3 && "Not a double-shift!");
1972  assert(Op.getOpcode() == ISD::SHL_PARTS);
1973 
1974  EVT VT = Op.getValueType();
1975  unsigned VTBits = VT.getSizeInBits();
1976  SDLoc dl(Op);
1977  SDValue ShOpLo = Op.getOperand(0);
1978  SDValue ShOpHi = Op.getOperand(1);
1979  SDValue ShAmt = Op.getOperand(2);
1980 
1981  if (VTBits == 32 && STI.getSmVersion() >= 35) {
1982  // For 32bit and sm35, we can use the funnel shift 'shf' instruction.
1983  // {dHi, dLo} = {aHi, aLo} << Amt
1984  // dHi = shf.l.clamp aLo, aHi, Amt
1985  // dLo = aLo << Amt
1986 
1987  SDValue Hi = DAG.getNode(NVPTXISD::FUN_SHFL_CLAMP, dl, VT, ShOpLo, ShOpHi,
1988  ShAmt);
1989  SDValue Lo = DAG.getNode(ISD::SHL, dl, VT, ShOpLo, ShAmt);
1990 
1991  SDValue Ops[2] = { Lo, Hi };
1992  return DAG.getMergeValues(Ops, dl);
1993  }
1994  else {
1995  // {dHi, dLo} = {aHi, aLo} << Amt
1996  // - if (Amt>=size) then
1997  // dLo = aLo << Amt (all 0)
1998  // dLo = aLo << (Amt-size)
1999  // else
2000  // dLo = aLo << Amt
2001  // dHi = (aHi << Amt) | (aLo >> (size-Amt))
2002 
2003  SDValue RevShAmt = DAG.getNode(ISD::SUB, dl, MVT::i32,
2004  DAG.getConstant(VTBits, dl, MVT::i32),
2005  ShAmt);
2006  SDValue Tmp1 = DAG.getNode(ISD::SHL, dl, VT, ShOpHi, ShAmt);
2007  SDValue ExtraShAmt = DAG.getNode(ISD::SUB, dl, MVT::i32, ShAmt,
2008  DAG.getConstant(VTBits, dl, MVT::i32));
2009  SDValue Tmp2 = DAG.getNode(ISD::SRL, dl, VT, ShOpLo, RevShAmt);
2010  SDValue FalseVal = DAG.getNode(ISD::OR, dl, VT, Tmp1, Tmp2);
2011  SDValue TrueVal = DAG.getNode(ISD::SHL, dl, VT, ShOpLo, ExtraShAmt);
2012 
2013  SDValue Cmp = DAG.getSetCC(dl, MVT::i1, ShAmt,
2014  DAG.getConstant(VTBits, dl, MVT::i32),
2015  ISD::SETGE);
2016  SDValue Lo = DAG.getNode(ISD::SHL, dl, VT, ShOpLo, ShAmt);
2017  SDValue Hi = DAG.getNode(ISD::SELECT, dl, VT, Cmp, TrueVal, FalseVal);
2018 
2019  SDValue Ops[2] = { Lo, Hi };
2020  return DAG.getMergeValues(Ops, dl);
2021  }
2022 }
2023 
2024 SDValue
2026  switch (Op.getOpcode()) {
2027  case ISD::RETURNADDR:
2028  return SDValue();
2029  case ISD::FRAMEADDR:
2030  return SDValue();
2031  case ISD::GlobalAddress:
2032  return LowerGlobalAddress(Op, DAG);
2034  return Op;
2035  case ISD::BUILD_VECTOR:
2036  return LowerBUILD_VECTOR(Op, DAG);
2038  return Op;
2040  return LowerEXTRACT_VECTOR_ELT(Op, DAG);
2041  case ISD::CONCAT_VECTORS:
2042  return LowerCONCAT_VECTORS(Op, DAG);
2043  case ISD::STORE:
2044  return LowerSTORE(Op, DAG);
2045  case ISD::LOAD:
2046  return LowerLOAD(Op, DAG);
2047  case ISD::SHL_PARTS:
2048  return LowerShiftLeftParts(Op, DAG);
2049  case ISD::SRA_PARTS:
2050  case ISD::SRL_PARTS:
2051  return LowerShiftRightParts(Op, DAG);
2052  case ISD::SELECT:
2053  return LowerSelect(Op, DAG);
2054  default:
2055  llvm_unreachable("Custom lowering not defined for operation");
2056  }
2057 }
2058 
2059 SDValue NVPTXTargetLowering::LowerSelect(SDValue Op, SelectionDAG &DAG) const {
2060  SDValue Op0 = Op->getOperand(0);
2061  SDValue Op1 = Op->getOperand(1);
2062  SDValue Op2 = Op->getOperand(2);
2063  SDLoc DL(Op.getNode());
2064 
2065  assert(Op.getValueType() == MVT::i1 && "Custom lowering enabled only for i1");
2066 
2067  Op1 = DAG.getNode(ISD::ANY_EXTEND, DL, MVT::i32, Op1);
2068  Op2 = DAG.getNode(ISD::ANY_EXTEND, DL, MVT::i32, Op2);
2069  SDValue Select = DAG.getNode(ISD::SELECT, DL, MVT::i32, Op0, Op1, Op2);
2070  SDValue Trunc = DAG.getNode(ISD::TRUNCATE, DL, MVT::i1, Select);
2071 
2072  return Trunc;
2073 }
2074 
2075 SDValue NVPTXTargetLowering::LowerLOAD(SDValue Op, SelectionDAG &DAG) const {
2076  if (Op.getValueType() == MVT::i1)
2077  return LowerLOADi1(Op, DAG);
2078 
2079  // v2f16 is legal, so we can't rely on legalizer to handle unaligned
2080  // loads and have to handle it here.
2081  if (Op.getValueType() == MVT::v2f16) {
2082  LoadSDNode *Load = cast<LoadSDNode>(Op);
2083  EVT MemVT = Load->getMemoryVT();
2084  if (!allowsMemoryAccess(*DAG.getContext(), DAG.getDataLayout(), MemVT,
2085  Load->getAddressSpace(), Load->getAlignment())) {
2086  SDValue Ops[2];
2087  std::tie(Ops[0], Ops[1]) = expandUnalignedLoad(Load, DAG);
2088  return DAG.getMergeValues(Ops, SDLoc(Op));
2089  }
2090  }
2091 
2092  return SDValue();
2093 }
2094 
2095 // v = ld i1* addr
2096 // =>
2097 // v1 = ld i8* addr (-> i16)
2098 // v = trunc i16 to i1
2099 SDValue NVPTXTargetLowering::LowerLOADi1(SDValue Op, SelectionDAG &DAG) const {
2100  SDNode *Node = Op.getNode();
2101  LoadSDNode *LD = cast<LoadSDNode>(Node);
2102  SDLoc dl(Node);
2104  assert(Node->getValueType(0) == MVT::i1 &&
2105  "Custom lowering for i1 load only");
2106  SDValue newLD = DAG.getLoad(MVT::i16, dl, LD->getChain(), LD->getBasePtr(),
2107  LD->getPointerInfo(), LD->getAlignment(),
2108  LD->getMemOperand()->getFlags());
2109  SDValue result = DAG.getNode(ISD::TRUNCATE, dl, MVT::i1, newLD);
2110  // The legalizer (the caller) is expecting two values from the legalized
2111  // load, so we build a MergeValues node for it. See ExpandUnalignedLoad()
2112  // in LegalizeDAG.cpp which also uses MergeValues.
2113  SDValue Ops[] = { result, LD->getChain() };
2114  return DAG.getMergeValues(Ops, dl);
2115 }
2116 
2117 SDValue NVPTXTargetLowering::LowerSTORE(SDValue Op, SelectionDAG &DAG) const {
2118  StoreSDNode *Store = cast<StoreSDNode>(Op);
2119  EVT VT = Store->getMemoryVT();
2120 
2121  if (VT == MVT::i1)
2122  return LowerSTOREi1(Op, DAG);
2123 
2124  // v2f16 is legal, so we can't rely on legalizer to handle unaligned
2125  // stores and have to handle it here.
2126  if (VT == MVT::v2f16 &&
2127  !allowsMemoryAccess(*DAG.getContext(), DAG.getDataLayout(), VT,
2128  Store->getAddressSpace(), Store->getAlignment()))
2129  return expandUnalignedStore(Store, DAG);
2130 
2131  if (VT.isVector())
2132  return LowerSTOREVector(Op, DAG);
2133 
2134  return SDValue();
2135 }
2136 
2137 SDValue
2138 NVPTXTargetLowering::LowerSTOREVector(SDValue Op, SelectionDAG &DAG) const {
2139  SDNode *N = Op.getNode();
2140  SDValue Val = N->getOperand(1);
2141  SDLoc DL(N);
2142  EVT ValVT = Val.getValueType();
2143 
2144  if (ValVT.isVector()) {
2145  // We only handle "native" vector sizes for now, e.g. <4 x double> is not
2146  // legal. We can (and should) split that into 2 stores of <2 x double> here
2147  // but I'm leaving that as a TODO for now.
2148  if (!ValVT.isSimple())
2149  return SDValue();
2150  switch (ValVT.getSimpleVT().SimpleTy) {
2151  default:
2152  return SDValue();
2153  case MVT::v2i8:
2154  case MVT::v2i16:
2155  case MVT::v2i32:
2156  case MVT::v2i64:
2157  case MVT::v2f16:
2158  case MVT::v2f32:
2159  case MVT::v2f64:
2160  case MVT::v4i8:
2161  case MVT::v4i16:
2162  case MVT::v4i32:
2163  case MVT::v4f16:
2164  case MVT::v4f32:
2165  case MVT::v8f16: // <4 x f16x2>
2166  // This is a "native" vector type
2167  break;
2168  }
2169 
2170  MemSDNode *MemSD = cast<MemSDNode>(N);
2171  const DataLayout &TD = DAG.getDataLayout();
2172 
2173  unsigned Align = MemSD->getAlignment();
2174  unsigned PrefAlign =
2175  TD.getPrefTypeAlignment(ValVT.getTypeForEVT(*DAG.getContext()));
2176  if (Align < PrefAlign) {
2177  // This store is not sufficiently aligned, so bail out and let this vector
2178  // store be scalarized. Note that we may still be able to emit smaller
2179  // vector stores. For example, if we are storing a <4 x float> with an
2180  // alignment of 8, this check will fail but the legalizer will try again
2181  // with 2 x <2 x float>, which will succeed with an alignment of 8.
2182  return SDValue();
2183  }
2184 
2185  unsigned Opcode = 0;
2186  EVT EltVT = ValVT.getVectorElementType();
2187  unsigned NumElts = ValVT.getVectorNumElements();
2188 
2189  // Since StoreV2 is a target node, we cannot rely on DAG type legalization.
2190  // Therefore, we must ensure the type is legal. For i1 and i8, we set the
2191  // stored type to i16 and propagate the "real" type as the memory type.
2192  bool NeedExt = false;
2193  if (EltVT.getSizeInBits() < 16)
2194  NeedExt = true;
2195 
2196  bool StoreF16x2 = false;
2197  switch (NumElts) {
2198  default:
2199  return SDValue();
2200  case 2:
2201  Opcode = NVPTXISD::StoreV2;
2202  break;
2203  case 4:
2204  Opcode = NVPTXISD::StoreV4;
2205  break;
2206  case 8:
2207  // v8f16 is a special case. PTX doesn't have st.v8.f16
2208  // instruction. Instead, we split the vector into v2f16 chunks and
2209  // store them with st.v4.b32.
2210  assert(EltVT == MVT::f16 && "Wrong type for the vector.");
2211  Opcode = NVPTXISD::StoreV4;
2212  StoreF16x2 = true;
2213  break;
2214  }
2215 
2217 
2218  // First is the chain
2219  Ops.push_back(N->getOperand(0));
2220 
2221  if (StoreF16x2) {
2222  // Combine f16,f16 -> v2f16
2223  NumElts /= 2;
2224  for (unsigned i = 0; i < NumElts; ++i) {
2225  SDValue E0 = DAG.getNode(ISD::EXTRACT_VECTOR_ELT, DL, MVT::f16, Val,
2226  DAG.getIntPtrConstant(i * 2, DL));
2227  SDValue E1 = DAG.getNode(ISD::EXTRACT_VECTOR_ELT, DL, MVT::f16, Val,
2228  DAG.getIntPtrConstant(i * 2 + 1, DL));
2229  SDValue V2 = DAG.getNode(ISD::BUILD_VECTOR, DL, MVT::v2f16, E0, E1);
2230  Ops.push_back(V2);
2231  }
2232  } else {
2233  // Then the split values
2234  for (unsigned i = 0; i < NumElts; ++i) {
2235  SDValue ExtVal = DAG.getNode(ISD::EXTRACT_VECTOR_ELT, DL, EltVT, Val,
2236  DAG.getIntPtrConstant(i, DL));
2237  if (NeedExt)
2238  ExtVal = DAG.getNode(ISD::ANY_EXTEND, DL, MVT::i16, ExtVal);
2239  Ops.push_back(ExtVal);
2240  }
2241  }
2242 
2243  // Then any remaining arguments
2244  Ops.append(N->op_begin() + 2, N->op_end());
2245 
2246  SDValue NewSt =
2247  DAG.getMemIntrinsicNode(Opcode, DL, DAG.getVTList(MVT::Other), Ops,
2248  MemSD->getMemoryVT(), MemSD->getMemOperand());
2249 
2250  // return DCI.CombineTo(N, NewSt, true);
2251  return NewSt;
2252  }
2253 
2254  return SDValue();
2255 }
2256 
2257 // st i1 v, addr
2258 // =>
2259 // v1 = zxt v to i16
2260 // st.u8 i16, addr
2261 SDValue NVPTXTargetLowering::LowerSTOREi1(SDValue Op, SelectionDAG &DAG) const {
2262  SDNode *Node = Op.getNode();
2263  SDLoc dl(Node);
2264  StoreSDNode *ST = cast<StoreSDNode>(Node);
2265  SDValue Tmp1 = ST->getChain();
2266  SDValue Tmp2 = ST->getBasePtr();
2267  SDValue Tmp3 = ST->getValue();
2268  assert(Tmp3.getValueType() == MVT::i1 && "Custom lowering for i1 store only");
2269  Tmp3 = DAG.getNode(ISD::ZERO_EXTEND, dl, MVT::i16, Tmp3);
2270  SDValue Result =
2271  DAG.getTruncStore(Tmp1, dl, Tmp3, Tmp2, ST->getPointerInfo(), MVT::i8,
2272  ST->getAlignment(), ST->getMemOperand()->getFlags());
2273  return Result;
2274 }
2275 
2276 SDValue
2277 NVPTXTargetLowering::getParamSymbol(SelectionDAG &DAG, int idx, EVT v) const {
2278  std::string ParamSym;
2279  raw_string_ostream ParamStr(ParamSym);
2280 
2281  ParamStr << DAG.getMachineFunction().getName() << "_param_" << idx;
2282  ParamStr.flush();
2283 
2284  std::string *SavedStr =
2285  nvTM->getManagedStrPool()->getManagedString(ParamSym.c_str());
2286  return DAG.getTargetExternalSymbol(SavedStr->c_str(), v);
2287 }
2288 
2289 // Check to see if the kernel argument is image*_t or sampler_t
2290 
2291 static bool isImageOrSamplerVal(const Value *arg, const Module *context) {
2292  static const char *const specialTypes[] = { "struct._image2d_t",
2293  "struct._image3d_t",
2294  "struct._sampler_t" };
2295 
2296  Type *Ty = arg->getType();
2297  auto *PTy = dyn_cast<PointerType>(Ty);
2298 
2299  if (!PTy)
2300  return false;
2301 
2302  if (!context)
2303  return false;
2304 
2305  auto *STy = dyn_cast<StructType>(PTy->getElementType());
2306  if (!STy || STy->isLiteral())
2307  return false;
2308 
2309  return std::find(std::begin(specialTypes), std::end(specialTypes),
2310  STy->getName()) != std::end(specialTypes);
2311 }
2312 
2314  SDValue Chain, CallingConv::ID CallConv, bool isVarArg,
2315  const SmallVectorImpl<ISD::InputArg> &Ins, const SDLoc &dl,
2316  SelectionDAG &DAG, SmallVectorImpl<SDValue> &InVals) const {
2317  MachineFunction &MF = DAG.getMachineFunction();
2318  const DataLayout &DL = DAG.getDataLayout();
2319  auto PtrVT = getPointerTy(DAG.getDataLayout());
2320 
2321  const Function *F = MF.getFunction();
2322  const AttributeList &PAL = F->getAttributes();
2323  const TargetLowering *TLI = STI.getTargetLowering();
2324 
2325  SDValue Root = DAG.getRoot();
2326  std::vector<SDValue> OutChains;
2327 
2328  bool isABI = (STI.getSmVersion() >= 20);
2329  assert(isABI && "Non-ABI compilation is not supported");
2330  if (!isABI)
2331  return Chain;
2332 
2333  std::vector<Type *> argTypes;
2334  std::vector<const Argument *> theArgs;
2335  for (const Argument &I : F->args()) {
2336  theArgs.push_back(&I);
2337  argTypes.push_back(I.getType());
2338  }
2339  // argTypes.size() (or theArgs.size()) and Ins.size() need not match.
2340  // Ins.size() will be larger
2341  // * if there is an aggregate argument with multiple fields (each field
2342  // showing up separately in Ins)
2343  // * if there is a vector argument with more than typical vector-length
2344  // elements (generally if more than 4) where each vector element is
2345  // individually present in Ins.
2346  // So a different index should be used for indexing into Ins.
2347  // See similar issue in LowerCall.
2348  unsigned InsIdx = 0;
2349 
2350  int idx = 0;
2351  for (unsigned i = 0, e = theArgs.size(); i != e; ++i, ++idx, ++InsIdx) {
2352  Type *Ty = argTypes[i];
2353 
2354  // If the kernel argument is image*_t or sampler_t, convert it to
2355  // a i32 constant holding the parameter position. This can later
2356  // matched in the AsmPrinter to output the correct mangled name.
2357  if (isImageOrSamplerVal(
2358  theArgs[i],
2359  (theArgs[i]->getParent() ? theArgs[i]->getParent()->getParent()
2360  : nullptr))) {
2361  assert(isKernelFunction(*F) &&
2362  "Only kernels can have image/sampler params");
2363  InVals.push_back(DAG.getConstant(i + 1, dl, MVT::i32));
2364  continue;
2365  }
2366 
2367  if (theArgs[i]->use_empty()) {
2368  // argument is dead
2369  if (Ty->isAggregateType()) {
2370  SmallVector<EVT, 16> vtparts;
2371 
2372  ComputePTXValueVTs(*this, DAG.getDataLayout(), Ty, vtparts);
2373  assert(vtparts.size() > 0 && "empty aggregate type not expected");
2374  for (unsigned parti = 0, parte = vtparts.size(); parti != parte;
2375  ++parti) {
2376  InVals.push_back(DAG.getNode(ISD::UNDEF, dl, Ins[InsIdx].VT));
2377  ++InsIdx;
2378  }
2379  if (vtparts.size() > 0)
2380  --InsIdx;
2381  continue;
2382  }
2383  if (Ty->isVectorTy()) {
2384  EVT ObjectVT = getValueType(DL, Ty);
2385  unsigned NumRegs = TLI->getNumRegisters(F->getContext(), ObjectVT);
2386  for (unsigned parti = 0; parti < NumRegs; ++parti) {
2387  InVals.push_back(DAG.getNode(ISD::UNDEF, dl, Ins[InsIdx].VT));
2388  ++InsIdx;
2389  }
2390  if (NumRegs > 0)
2391  --InsIdx;
2392  continue;
2393  }
2394  InVals.push_back(DAG.getNode(ISD::UNDEF, dl, Ins[InsIdx].VT));
2395  continue;
2396  }
2397 
2398  // In the following cases, assign a node order of "idx+1"
2399  // to newly created nodes. The SDNodes for params have to
2400  // appear in the same order as their order of appearance
2401  // in the original function. "idx+1" holds that order.
2402  if (!PAL.hasParamAttribute(i, Attribute::ByVal)) {
2403  bool aggregateIsPacked = false;
2404  if (StructType *STy = dyn_cast<StructType>(Ty))
2405  aggregateIsPacked = STy->isPacked();
2406 
2409  ComputePTXValueVTs(*this, DL, Ty, VTs, &Offsets, 0);
2410  assert(VTs.size() > 0 && "Unexpected empty type.");
2411  auto VectorInfo =
2412  VectorizePTXValueVTs(VTs, Offsets, DL.getABITypeAlignment(Ty));
2413 
2414  SDValue Arg = getParamSymbol(DAG, idx, PtrVT);
2415  int VecIdx = -1; // Index of the first element of the current vector.
2416  for (unsigned parti = 0, parte = VTs.size(); parti != parte; ++parti) {
2417  if (VectorInfo[parti] & PVF_FIRST) {
2418  assert(VecIdx == -1 && "Orphaned vector.");
2419  VecIdx = parti;
2420  }
2421 
2422  // That's the last element of this store op.
2423  if (VectorInfo[parti] & PVF_LAST) {
2424  unsigned NumElts = parti - VecIdx + 1;
2425  EVT EltVT = VTs[parti];
2426  // i1 is loaded/stored as i8.
2427  EVT LoadVT = EltVT;
2428  if (EltVT == MVT::i1)
2429  LoadVT = MVT::i8;
2430  else if (EltVT == MVT::v2f16)
2431  // getLoad needs a vector type, but it can't handle
2432  // vectors which contain v2f16 elements. So we must load
2433  // using i32 here and then bitcast back.
2434  LoadVT = MVT::i32;
2435 
2436  EVT VecVT = EVT::getVectorVT(F->getContext(), LoadVT, NumElts);
2437  SDValue VecAddr =
2438  DAG.getNode(ISD::ADD, dl, PtrVT, Arg,
2439  DAG.getConstant(Offsets[VecIdx], dl, PtrVT));
2441  EltVT.getTypeForEVT(F->getContext()), ADDRESS_SPACE_PARAM));
2442  SDValue P =
2443  DAG.getLoad(VecVT, dl, Root, VecAddr,
2444  MachinePointerInfo(srcValue), aggregateIsPacked,
2447  if (P.getNode())
2448  P.getNode()->setIROrder(idx + 1);
2449  for (unsigned j = 0; j < NumElts; ++j) {
2450  SDValue Elt = DAG.getNode(ISD::EXTRACT_VECTOR_ELT, dl, LoadVT, P,
2451  DAG.getIntPtrConstant(j, dl));
2452  // We've loaded i1 as an i8 and now must truncate it back to i1
2453  if (EltVT == MVT::i1)
2454  Elt = DAG.getNode(ISD::TRUNCATE, dl, MVT::i1, Elt);
2455  // v2f16 was loaded as an i32. Now we must bitcast it back.
2456  else if (EltVT == MVT::v2f16)
2457  Elt = DAG.getNode(ISD::BITCAST, dl, MVT::v2f16, Elt);
2458  // Extend the element if necessary (e.g. an i8 is loaded
2459  // into an i16 register)
2460  if (Ins[InsIdx].VT.isInteger() &&
2461  Ins[InsIdx].VT.getSizeInBits() > LoadVT.getSizeInBits()) {
2462  unsigned Extend = Ins[InsIdx].Flags.isSExt() ? ISD::SIGN_EXTEND
2463  : ISD::ZERO_EXTEND;
2464  Elt = DAG.getNode(Extend, dl, Ins[InsIdx].VT, Elt);
2465  }
2466  InVals.push_back(Elt);
2467  }
2468 
2469  // Reset vector tracking state.
2470  VecIdx = -1;
2471  }
2472  ++InsIdx;
2473  }
2474  if (VTs.size() > 0)
2475  --InsIdx;
2476  continue;
2477  }
2478 
2479  // Param has ByVal attribute
2480  // Return MoveParam(param symbol).
2481  // Ideally, the param symbol can be returned directly,
2482  // but when SDNode builder decides to use it in a CopyToReg(),
2483  // machine instruction fails because TargetExternalSymbol
2484  // (not lowered) is target dependent, and CopyToReg assumes
2485  // the source is lowered.
2486  EVT ObjectVT = getValueType(DL, Ty);
2487  assert(ObjectVT == Ins[InsIdx].VT &&
2488  "Ins type did not match function type");
2489  SDValue Arg = getParamSymbol(DAG, idx, PtrVT);
2490  SDValue p = DAG.getNode(NVPTXISD::MoveParam, dl, ObjectVT, Arg);
2491  if (p.getNode())
2492  p.getNode()->setIROrder(idx + 1);
2493  InVals.push_back(p);
2494  }
2495 
2496  // Clang will check explicit VarArg and issue error if any. However, Clang
2497  // will let code with
2498  // implicit var arg like f() pass. See bug 617733.
2499  // We treat this case as if the arg list is empty.
2500  // if (F.isVarArg()) {
2501  // assert(0 && "VarArg not supported yet!");
2502  //}
2503 
2504  if (!OutChains.empty())
2505  DAG.setRoot(DAG.getNode(ISD::TokenFactor, dl, MVT::Other, OutChains));
2506 
2507  return Chain;
2508 }
2509 
2510 SDValue
2512  bool isVarArg,
2513  const SmallVectorImpl<ISD::OutputArg> &Outs,
2514  const SmallVectorImpl<SDValue> &OutVals,
2515  const SDLoc &dl, SelectionDAG &DAG) const {
2516  MachineFunction &MF = DAG.getMachineFunction();
2517  Type *RetTy = MF.getFunction()->getReturnType();
2518 
2519  bool isABI = (STI.getSmVersion() >= 20);
2520  assert(isABI && "Non-ABI compilation is not supported");
2521  if (!isABI)
2522  return Chain;
2523 
2524  const DataLayout DL = DAG.getDataLayout();
2527  ComputePTXValueVTs(*this, DL, RetTy, VTs, &Offsets);
2528  assert(VTs.size() == OutVals.size() && "Bad return value decomposition");
2529 
2530  auto VectorInfo = VectorizePTXValueVTs(
2531  VTs, Offsets, RetTy->isSized() ? DL.getABITypeAlignment(RetTy) : 1);
2532 
2533  // PTX Interoperability Guide 3.3(A): [Integer] Values shorter than
2534  // 32-bits are sign extended or zero extended, depending on whether
2535  // they are signed or unsigned types.
2536  bool ExtendIntegerRetVal =
2537  RetTy->isIntegerTy() && DL.getTypeAllocSizeInBits(RetTy) < 32;
2538 
2539  SmallVector<SDValue, 6> StoreOperands;
2540  for (unsigned i = 0, e = VTs.size(); i != e; ++i) {
2541  // New load/store. Record chain and offset operands.
2542  if (VectorInfo[i] & PVF_FIRST) {
2543  assert(StoreOperands.empty() && "Orphaned operand list.");
2544  StoreOperands.push_back(Chain);
2545  StoreOperands.push_back(DAG.getConstant(Offsets[i], dl, MVT::i32));
2546  }
2547 
2548  SDValue RetVal = OutVals[i];
2549  if (ExtendIntegerRetVal) {
2550  RetVal = DAG.getNode(Outs[i].Flags.isSExt() ? ISD::SIGN_EXTEND
2551  : ISD::ZERO_EXTEND,
2552  dl, MVT::i32, RetVal);
2553  } else if (RetVal.getValueSizeInBits() < 16) {
2554  // Use 16-bit registers for small load-stores as it's the
2555  // smallest general purpose register size supported by NVPTX.
2556  RetVal = DAG.getNode(ISD::ANY_EXTEND, dl, MVT::i16, RetVal);
2557  }
2558 
2559  // Record the value to return.
2560  StoreOperands.push_back(RetVal);
2561 
2562  // That's the last element of this store op.
2563  if (VectorInfo[i] & PVF_LAST) {
2565  unsigned NumElts = StoreOperands.size() - 2;
2566  switch (NumElts) {
2567  case 1:
2568  Op = NVPTXISD::StoreRetval;
2569  break;
2570  case 2:
2572  break;
2573  case 4:
2575  break;
2576  default:
2577  llvm_unreachable("Invalid vector info.");
2578  }
2579 
2580  // Adjust type of load/store op if we've extended the scalar
2581  // return value.
2582  EVT TheStoreType = ExtendIntegerRetVal ? MVT::i32 : VTs[i];
2583  Chain = DAG.getMemIntrinsicNode(Op, dl, DAG.getVTList(MVT::Other),
2584  StoreOperands, TheStoreType,
2585  MachinePointerInfo(), /* Align */ 1,
2586  /* Volatile */ false, /* ReadMem */ false,
2587  /* WriteMem */ true, /* Size */ 0);
2588  // Cleanup vector state.
2589  StoreOperands.clear();
2590  }
2591  }
2592 
2593  return DAG.getNode(NVPTXISD::RET_FLAG, dl, MVT::Other, Chain);
2594 }
2595 
2597  SDValue Op, std::string &Constraint, std::vector<SDValue> &Ops,
2598  SelectionDAG &DAG) const {
2599  if (Constraint.length() > 1)
2600  return;
2601  else
2602  TargetLowering::LowerAsmOperandForConstraint(Op, Constraint, Ops, DAG);
2603 }
2604 
2605 static unsigned getOpcForTextureInstr(unsigned Intrinsic) {
2606  switch (Intrinsic) {
2607  default:
2608  return 0;
2609 
2610  case Intrinsic::nvvm_tex_1d_v4f32_s32:
2611  return NVPTXISD::Tex1DFloatS32;
2612  case Intrinsic::nvvm_tex_1d_v4f32_f32:
2614  case Intrinsic::nvvm_tex_1d_level_v4f32_f32:
2616  case Intrinsic::nvvm_tex_1d_grad_v4f32_f32:
2618  case Intrinsic::nvvm_tex_1d_v4s32_s32:
2619  return NVPTXISD::Tex1DS32S32;
2620  case Intrinsic::nvvm_tex_1d_v4s32_f32:
2621  return NVPTXISD::Tex1DS32Float;
2622  case Intrinsic::nvvm_tex_1d_level_v4s32_f32:
2624  case Intrinsic::nvvm_tex_1d_grad_v4s32_f32:
2626  case Intrinsic::nvvm_tex_1d_v4u32_s32:
2627  return NVPTXISD::Tex1DU32S32;
2628  case Intrinsic::nvvm_tex_1d_v4u32_f32:
2629  return NVPTXISD::Tex1DU32Float;
2630  case Intrinsic::nvvm_tex_1d_level_v4u32_f32:
2632  case Intrinsic::nvvm_tex_1d_grad_v4u32_f32:
2634 
2635  case Intrinsic::nvvm_tex_1d_array_v4f32_s32:
2637  case Intrinsic::nvvm_tex_1d_array_v4f32_f32:
2639  case Intrinsic::nvvm_tex_1d_array_level_v4f32_f32:
2641  case Intrinsic::nvvm_tex_1d_array_grad_v4f32_f32:
2643  case Intrinsic::nvvm_tex_1d_array_v4s32_s32:
2645  case Intrinsic::nvvm_tex_1d_array_v4s32_f32:
2647  case Intrinsic::nvvm_tex_1d_array_level_v4s32_f32:
2649  case Intrinsic::nvvm_tex_1d_array_grad_v4s32_f32:
2651  case Intrinsic::nvvm_tex_1d_array_v4u32_s32:
2653  case Intrinsic::nvvm_tex_1d_array_v4u32_f32:
2655  case Intrinsic::nvvm_tex_1d_array_level_v4u32_f32:
2657  case Intrinsic::nvvm_tex_1d_array_grad_v4u32_f32:
2659 
2660  case Intrinsic::nvvm_tex_2d_v4f32_s32:
2661  return NVPTXISD::Tex2DFloatS32;
2662  case Intrinsic::nvvm_tex_2d_v4f32_f32:
2664  case Intrinsic::nvvm_tex_2d_level_v4f32_f32:
2666  case Intrinsic::nvvm_tex_2d_grad_v4f32_f32:
2668  case Intrinsic::nvvm_tex_2d_v4s32_s32:
2669  return NVPTXISD::Tex2DS32S32;
2670  case Intrinsic::nvvm_tex_2d_v4s32_f32:
2671  return NVPTXISD::Tex2DS32Float;
2672  case Intrinsic::nvvm_tex_2d_level_v4s32_f32:
2674  case Intrinsic::nvvm_tex_2d_grad_v4s32_f32:
2676  case Intrinsic::nvvm_tex_2d_v4u32_s32:
2677  return NVPTXISD::Tex2DU32S32;
2678  case Intrinsic::nvvm_tex_2d_v4u32_f32:
2679  return NVPTXISD::Tex2DU32Float;
2680  case Intrinsic::nvvm_tex_2d_level_v4u32_f32:
2682  case Intrinsic::nvvm_tex_2d_grad_v4u32_f32:
2684 
2685  case Intrinsic::nvvm_tex_2d_array_v4f32_s32:
2687  case Intrinsic::nvvm_tex_2d_array_v4f32_f32:
2689  case Intrinsic::nvvm_tex_2d_array_level_v4f32_f32:
2691  case Intrinsic::nvvm_tex_2d_array_grad_v4f32_f32:
2693  case Intrinsic::nvvm_tex_2d_array_v4s32_s32:
2695  case Intrinsic::nvvm_tex_2d_array_v4s32_f32:
2697  case Intrinsic::nvvm_tex_2d_array_level_v4s32_f32:
2699  case Intrinsic::nvvm_tex_2d_array_grad_v4s32_f32:
2701  case Intrinsic::nvvm_tex_2d_array_v4u32_s32:
2703  case Intrinsic::nvvm_tex_2d_array_v4u32_f32:
2705  case Intrinsic::nvvm_tex_2d_array_level_v4u32_f32:
2707  case Intrinsic::nvvm_tex_2d_array_grad_v4u32_f32:
2709 
2710  case Intrinsic::nvvm_tex_3d_v4f32_s32:
2711  return NVPTXISD::Tex3DFloatS32;
2712  case Intrinsic::nvvm_tex_3d_v4f32_f32:
2714  case Intrinsic::nvvm_tex_3d_level_v4f32_f32:
2716  case Intrinsic::nvvm_tex_3d_grad_v4f32_f32:
2718  case Intrinsic::nvvm_tex_3d_v4s32_s32:
2719  return NVPTXISD::Tex3DS32S32;
2720  case Intrinsic::nvvm_tex_3d_v4s32_f32:
2721  return NVPTXISD::Tex3DS32Float;
2722  case Intrinsic::nvvm_tex_3d_level_v4s32_f32:
2724  case Intrinsic::nvvm_tex_3d_grad_v4s32_f32:
2726  case Intrinsic::nvvm_tex_3d_v4u32_s32:
2727  return NVPTXISD::Tex3DU32S32;
2728  case Intrinsic::nvvm_tex_3d_v4u32_f32:
2729  return NVPTXISD::Tex3DU32Float;
2730  case Intrinsic::nvvm_tex_3d_level_v4u32_f32:
2732  case Intrinsic::nvvm_tex_3d_grad_v4u32_f32:
2734 
2735  case Intrinsic::nvvm_tex_cube_v4f32_f32:
2737  case Intrinsic::nvvm_tex_cube_level_v4f32_f32:
2739  case Intrinsic::nvvm_tex_cube_v4s32_f32:
2741  case Intrinsic::nvvm_tex_cube_level_v4s32_f32:
2743  case Intrinsic::nvvm_tex_cube_v4u32_f32:
2745  case Intrinsic::nvvm_tex_cube_level_v4u32_f32:
2747 
2748  case Intrinsic::nvvm_tex_cube_array_v4f32_f32:
2750  case Intrinsic::nvvm_tex_cube_array_level_v4f32_f32:
2752  case Intrinsic::nvvm_tex_cube_array_v4s32_f32:
2754  case Intrinsic::nvvm_tex_cube_array_level_v4s32_f32:
2756  case Intrinsic::nvvm_tex_cube_array_v4u32_f32:
2758  case Intrinsic::nvvm_tex_cube_array_level_v4u32_f32:
2760 
2761  case Intrinsic::nvvm_tld4_r_2d_v4f32_f32:
2763  case Intrinsic::nvvm_tld4_g_2d_v4f32_f32:
2765  case Intrinsic::nvvm_tld4_b_2d_v4f32_f32:
2767  case Intrinsic::nvvm_tld4_a_2d_v4f32_f32:
2769  case Intrinsic::nvvm_tld4_r_2d_v4s32_f32:
2771  case Intrinsic::nvvm_tld4_g_2d_v4s32_f32:
2773  case Intrinsic::nvvm_tld4_b_2d_v4s32_f32:
2775  case Intrinsic::nvvm_tld4_a_2d_v4s32_f32:
2777  case Intrinsic::nvvm_tld4_r_2d_v4u32_f32:
2779  case Intrinsic::nvvm_tld4_g_2d_v4u32_f32:
2781  case Intrinsic::nvvm_tld4_b_2d_v4u32_f32:
2783  case Intrinsic::nvvm_tld4_a_2d_v4u32_f32:
2785 
2786  case Intrinsic::nvvm_tex_unified_1d_v4f32_s32:
2788  case Intrinsic::nvvm_tex_unified_1d_v4f32_f32:
2790  case Intrinsic::nvvm_tex_unified_1d_level_v4f32_f32:
2792  case Intrinsic::nvvm_tex_unified_1d_grad_v4f32_f32:
2794  case Intrinsic::nvvm_tex_unified_1d_v4s32_s32:
2796  case Intrinsic::nvvm_tex_unified_1d_v4s32_f32:
2798  case Intrinsic::nvvm_tex_unified_1d_level_v4s32_f32:
2800  case Intrinsic::nvvm_tex_unified_1d_grad_v4s32_f32:
2802  case Intrinsic::nvvm_tex_unified_1d_v4u32_s32:
2804  case Intrinsic::nvvm_tex_unified_1d_v4u32_f32:
2806  case Intrinsic::nvvm_tex_unified_1d_level_v4u32_f32:
2808  case Intrinsic::nvvm_tex_unified_1d_grad_v4u32_f32:
2810 
2811  case Intrinsic::nvvm_tex_unified_1d_array_v4f32_s32:
2813  case Intrinsic::nvvm_tex_unified_1d_array_v4f32_f32:
2815  case Intrinsic::nvvm_tex_unified_1d_array_level_v4f32_f32:
2817  case Intrinsic::nvvm_tex_unified_1d_array_grad_v4f32_f32:
2819  case Intrinsic::nvvm_tex_unified_1d_array_v4s32_s32:
2821  case Intrinsic::nvvm_tex_unified_1d_array_v4s32_f32:
2823  case Intrinsic::nvvm_tex_unified_1d_array_level_v4s32_f32:
2825  case Intrinsic::nvvm_tex_unified_1d_array_grad_v4s32_f32:
2827  case Intrinsic::nvvm_tex_unified_1d_array_v4u32_s32:
2829  case Intrinsic::nvvm_tex_unified_1d_array_v4u32_f32:
2831  case Intrinsic::nvvm_tex_unified_1d_array_level_v4u32_f32:
2833  case Intrinsic::nvvm_tex_unified_1d_array_grad_v4u32_f32:
2835 
2836  case Intrinsic::nvvm_tex_unified_2d_v4f32_s32:
2838  case Intrinsic::nvvm_tex_unified_2d_v4f32_f32:
2840  case Intrinsic::nvvm_tex_unified_2d_level_v4f32_f32:
2842  case Intrinsic::nvvm_tex_unified_2d_grad_v4f32_f32:
2844  case Intrinsic::nvvm_tex_unified_2d_v4s32_s32:
2846  case Intrinsic::nvvm_tex_unified_2d_v4s32_f32:
2848  case Intrinsic::nvvm_tex_unified_2d_level_v4s32_f32:
2850  case Intrinsic::nvvm_tex_unified_2d_grad_v4s32_f32:
2852  case Intrinsic::nvvm_tex_unified_2d_v4u32_s32:
2854  case Intrinsic::nvvm_tex_unified_2d_v4u32_f32:
2856  case Intrinsic::nvvm_tex_unified_2d_level_v4u32_f32:
2858  case Intrinsic::nvvm_tex_unified_2d_grad_v4u32_f32:
2860 
2861  case Intrinsic::nvvm_tex_unified_2d_array_v4f32_s32:
2863  case Intrinsic::nvvm_tex_unified_2d_array_v4f32_f32:
2865  case Intrinsic::nvvm_tex_unified_2d_array_level_v4f32_f32:
2867  case Intrinsic::nvvm_tex_unified_2d_array_grad_v4f32_f32:
2869  case Intrinsic::nvvm_tex_unified_2d_array_v4s32_s32:
2871  case Intrinsic::nvvm_tex_unified_2d_array_v4s32_f32:
2873  case Intrinsic::nvvm_tex_unified_2d_array_level_v4s32_f32:
2875  case Intrinsic::nvvm_tex_unified_2d_array_grad_v4s32_f32:
2877  case Intrinsic::nvvm_tex_unified_2d_array_v4u32_s32:
2879  case Intrinsic::nvvm_tex_unified_2d_array_v4u32_f32:
2881  case Intrinsic::nvvm_tex_unified_2d_array_level_v4u32_f32:
2883  case Intrinsic::nvvm_tex_unified_2d_array_grad_v4u32_f32:
2885 
2886  case Intrinsic::nvvm_tex_unified_3d_v4f32_s32:
2888  case Intrinsic::nvvm_tex_unified_3d_v4f32_f32:
2890  case Intrinsic::nvvm_tex_unified_3d_level_v4f32_f32:
2892  case Intrinsic::nvvm_tex_unified_3d_grad_v4f32_f32:
2894  case Intrinsic::nvvm_tex_unified_3d_v4s32_s32:
2896  case Intrinsic::nvvm_tex_unified_3d_v4s32_f32:
2898  case Intrinsic::nvvm_tex_unified_3d_level_v4s32_f32:
2900  case Intrinsic::nvvm_tex_unified_3d_grad_v4s32_f32:
2902  case Intrinsic::nvvm_tex_unified_3d_v4u32_s32:
2904  case Intrinsic::nvvm_tex_unified_3d_v4u32_f32:
2906  case Intrinsic::nvvm_tex_unified_3d_level_v4u32_f32:
2908  case Intrinsic::nvvm_tex_unified_3d_grad_v4u32_f32:
2910 
2911  case Intrinsic::nvvm_tex_unified_cube_v4f32_f32:
2913  case Intrinsic::nvvm_tex_unified_cube_level_v4f32_f32:
2915  case Intrinsic::nvvm_tex_unified_cube_v4s32_f32:
2917  case Intrinsic::nvvm_tex_unified_cube_level_v4s32_f32:
2919  case Intrinsic::nvvm_tex_unified_cube_v4u32_f32:
2921  case Intrinsic::nvvm_tex_unified_cube_level_v4u32_f32:
2923 
2924  case Intrinsic::nvvm_tex_unified_cube_array_v4f32_f32:
2926  case Intrinsic::nvvm_tex_unified_cube_array_level_v4f32_f32:
2928  case Intrinsic::nvvm_tex_unified_cube_array_v4s32_f32:
2930  case Intrinsic::nvvm_tex_unified_cube_array_level_v4s32_f32:
2932  case Intrinsic::nvvm_tex_unified_cube_array_v4u32_f32:
2934  case Intrinsic::nvvm_tex_unified_cube_array_level_v4u32_f32:
2936 
2937  case Intrinsic::nvvm_tld4_unified_r_2d_v4f32_f32:
2939  case Intrinsic::nvvm_tld4_unified_g_2d_v4f32_f32:
2941  case Intrinsic::nvvm_tld4_unified_b_2d_v4f32_f32:
2943  case Intrinsic::nvvm_tld4_unified_a_2d_v4f32_f32:
2945  case Intrinsic::nvvm_tld4_unified_r_2d_v4s32_f32:
2947  case Intrinsic::nvvm_tld4_unified_g_2d_v4s32_f32:
2949  case Intrinsic::nvvm_tld4_unified_b_2d_v4s32_f32:
2951  case Intrinsic::nvvm_tld4_unified_a_2d_v4s32_f32:
2953  case Intrinsic::nvvm_tld4_unified_r_2d_v4u32_f32:
2955  case Intrinsic::nvvm_tld4_unified_g_2d_v4u32_f32:
2957  case Intrinsic::nvvm_tld4_unified_b_2d_v4u32_f32:
2959  case Intrinsic::nvvm_tld4_unified_a_2d_v4u32_f32:
2961  }
2962 }
2963 
2964 static unsigned getOpcForSurfaceInstr(unsigned Intrinsic) {
2965  switch (Intrinsic) {
2966  default:
2967  return 0;
2968  case Intrinsic::nvvm_suld_1d_i8_clamp:
2969  return NVPTXISD::Suld1DI8Clamp;
2970  case Intrinsic::nvvm_suld_1d_i16_clamp:
2971  return NVPTXISD::Suld1DI16Clamp;
2972  case Intrinsic::nvvm_suld_1d_i32_clamp:
2973  return NVPTXISD::Suld1DI32Clamp;
2974  case Intrinsic::nvvm_suld_1d_i64_clamp:
2975  return NVPTXISD::Suld1DI64Clamp;
2976  case Intrinsic::nvvm_suld_1d_v2i8_clamp:
2978  case Intrinsic::nvvm_suld_1d_v2i16_clamp:
2980  case Intrinsic::nvvm_suld_1d_v2i32_clamp:
2982  case Intrinsic::nvvm_suld_1d_v2i64_clamp:
2984  case Intrinsic::nvvm_suld_1d_v4i8_clamp:
2986  case Intrinsic::nvvm_suld_1d_v4i16_clamp:
2988  case Intrinsic::nvvm_suld_1d_v4i32_clamp:
2990  case Intrinsic::nvvm_suld_1d_array_i8_clamp:
2992  case Intrinsic::nvvm_suld_1d_array_i16_clamp:
2994  case Intrinsic::nvvm_suld_1d_array_i32_clamp:
2996  case Intrinsic::nvvm_suld_1d_array_i64_clamp:
2998  case Intrinsic::nvvm_suld_1d_array_v2i8_clamp:
3000  case Intrinsic::nvvm_suld_1d_array_v2i16_clamp:
3002  case Intrinsic::nvvm_suld_1d_array_v2i32_clamp:
3004  case Intrinsic::nvvm_suld_1d_array_v2i64_clamp:
3006  case Intrinsic::nvvm_suld_1d_array_v4i8_clamp:
3008  case Intrinsic::nvvm_suld_1d_array_v4i16_clamp:
3010  case Intrinsic::nvvm_suld_1d_array_v4i32_clamp:
3012  case Intrinsic::nvvm_suld_2d_i8_clamp:
3013  return NVPTXISD::Suld2DI8Clamp;
3014  case Intrinsic::nvvm_suld_2d_i16_clamp:
3015  return NVPTXISD::Suld2DI16Clamp;
3016  case Intrinsic::nvvm_suld_2d_i32_clamp:
3017  return NVPTXISD::Suld2DI32Clamp;
3018  case Intrinsic::nvvm_suld_2d_i64_clamp:
3019  return NVPTXISD::Suld2DI64Clamp;
3020  case Intrinsic::nvvm_suld_2d_v2i8_clamp:
3022  case Intrinsic::nvvm_suld_2d_v2i16_clamp:
3024  case Intrinsic::nvvm_suld_2d_v2i32_clamp:
3026  case Intrinsic::nvvm_suld_2d_v2i64_clamp:
3028  case Intrinsic::nvvm_suld_2d_v4i8_clamp:
3030  case Intrinsic::nvvm_suld_2d_v4i16_clamp:
3032  case Intrinsic::nvvm_suld_2d_v4i32_clamp:
3034  case Intrinsic::nvvm_suld_2d_array_i8_clamp:
3036  case Intrinsic::nvvm_suld_2d_array_i16_clamp:
3038  case Intrinsic::nvvm_suld_2d_array_i32_clamp:
3040  case Intrinsic::nvvm_suld_2d_array_i64_clamp:
3042  case Intrinsic::nvvm_suld_2d_array_v2i8_clamp:
3044  case Intrinsic::nvvm_suld_2d_array_v2i16_clamp:
3046  case Intrinsic::nvvm_suld_2d_array_v2i32_clamp:
3048  case Intrinsic::nvvm_suld_2d_array_v2i64_clamp:
3050  case Intrinsic::nvvm_suld_2d_array_v4i8_clamp:
3052  case Intrinsic::nvvm_suld_2d_array_v4i16_clamp:
3054  case Intrinsic::nvvm_suld_2d_array_v4i32_clamp:
3056  case Intrinsic::nvvm_suld_3d_i8_clamp:
3057  return NVPTXISD::Suld3DI8Clamp;
3058  case Intrinsic::nvvm_suld_3d_i16_clamp:
3059  return NVPTXISD::Suld3DI16Clamp;
3060  case Intrinsic::nvvm_suld_3d_i32_clamp:
3061  return NVPTXISD::Suld3DI32Clamp;
3062  case Intrinsic::nvvm_suld_3d_i64_clamp:
3063  return NVPTXISD::Suld3DI64Clamp;
3064  case Intrinsic::nvvm_suld_3d_v2i8_clamp:
3066  case Intrinsic::nvvm_suld_3d_v2i16_clamp:
3068  case Intrinsic::nvvm_suld_3d_v2i32_clamp:
3070  case Intrinsic::nvvm_suld_3d_v2i64_clamp:
3072  case Intrinsic::nvvm_suld_3d_v4i8_clamp:
3074  case Intrinsic::nvvm_suld_3d_v4i16_clamp:
3076  case Intrinsic::nvvm_suld_3d_v4i32_clamp:
3078  case Intrinsic::nvvm_suld_1d_i8_trap:
3079  return NVPTXISD::Suld1DI8Trap;
3080  case Intrinsic::nvvm_suld_1d_i16_trap:
3081  return NVPTXISD::Suld1DI16Trap;
3082  case Intrinsic::nvvm_suld_1d_i32_trap:
3083  return NVPTXISD::Suld1DI32Trap;
3084  case Intrinsic::nvvm_suld_1d_i64_trap:
3085  return NVPTXISD::Suld1DI64Trap;
3086  case Intrinsic::nvvm_suld_1d_v2i8_trap:
3087  return NVPTXISD::Suld1DV2I8Trap;
3088  case Intrinsic::nvvm_suld_1d_v2i16_trap:
3090  case Intrinsic::nvvm_suld_1d_v2i32_trap:
3092  case Intrinsic::nvvm_suld_1d_v2i64_trap:
3094  case Intrinsic::nvvm_suld_1d_v4i8_trap:
3095  return NVPTXISD::Suld1DV4I8Trap;
3096  case Intrinsic::nvvm_suld_1d_v4i16_trap:
3098  case Intrinsic::nvvm_suld_1d_v4i32_trap:
3100  case Intrinsic::nvvm_suld_1d_array_i8_trap:
3102  case Intrinsic::nvvm_suld_1d_array_i16_trap:
3104  case Intrinsic::nvvm_suld_1d_array_i32_trap:
3106  case Intrinsic::nvvm_suld_1d_array_i64_trap:
3108  case Intrinsic::nvvm_suld_1d_array_v2i8_trap:
3110  case Intrinsic::nvvm_suld_1d_array_v2i16_trap:
3112  case Intrinsic::nvvm_suld_1d_array_v2i32_trap:
3114  case Intrinsic::nvvm_suld_1d_array_v2i64_trap:
3116  case Intrinsic::nvvm_suld_1d_array_v4i8_trap:
3118  case Intrinsic::nvvm_suld_1d_array_v4i16_trap:
3120  case Intrinsic::nvvm_suld_1d_array_v4i32_trap:
3122  case Intrinsic::nvvm_suld_2d_i8_trap:
3123  return NVPTXISD::Suld2DI8Trap;
3124  case Intrinsic::nvvm_suld_2d_i16_trap:
3125  return NVPTXISD::Suld2DI16Trap;
3126  case Intrinsic::nvvm_suld_2d_i32_trap:
3127  return NVPTXISD::Suld2DI32Trap;
3128  case Intrinsic::nvvm_suld_2d_i64_trap:
3129  return NVPTXISD::Suld2DI64Trap;
3130  case Intrinsic::nvvm_suld_2d_v2i8_trap:
3131  return NVPTXISD::Suld2DV2I8Trap;
3132  case Intrinsic::nvvm_suld_2d_v2i16_trap:
3134  case Intrinsic::nvvm_suld_2d_v2i32_trap:
3136  case Intrinsic::nvvm_suld_2d_v2i64_trap:
3138  case Intrinsic::nvvm_suld_2d_v4i8_trap:
3139  return NVPTXISD::Suld2DV4I8Trap;
3140  case Intrinsic::nvvm_suld_2d_v4i16_trap:
3142  case Intrinsic::nvvm_suld_2d_v4i32_trap:
3144  case Intrinsic::nvvm_suld_2d_array_i8_trap:
3146  case Intrinsic::nvvm_suld_2d_array_i16_trap:
3148  case Intrinsic::nvvm_suld_2d_array_i32_trap:
3150  case Intrinsic::nvvm_suld_2d_array_i64_trap:
3152  case Intrinsic::nvvm_suld_2d_array_v2i8_trap:
3154  case Intrinsic::nvvm_suld_2d_array_v2i16_trap:
3156  case Intrinsic::nvvm_suld_2d_array_v2i32_trap:
3158  case Intrinsic::nvvm_suld_2d_array_v2i64_trap:
3160  case Intrinsic::nvvm_suld_2d_array_v4i8_trap:
3162  case Intrinsic::nvvm_suld_2d_array_v4i16_trap:
3164  case Intrinsic::nvvm_suld_2d_array_v4i32_trap:
3166  case Intrinsic::nvvm_suld_3d_i8_trap:
3167  return NVPTXISD::Suld3DI8Trap;
3168  case Intrinsic::nvvm_suld_3d_i16_trap:
3169  return NVPTXISD::Suld3DI16Trap;
3170  case Intrinsic::nvvm_suld_3d_i32_trap:
3171  return NVPTXISD::Suld3DI32Trap;
3172  case Intrinsic::nvvm_suld_3d_i64_trap:
3173  return NVPTXISD::Suld3DI64Trap;
3174  case Intrinsic::nvvm_suld_3d_v2i8_trap:
3175  return NVPTXISD::Suld3DV2I8Trap;
3176  case Intrinsic::nvvm_suld_3d_v2i16_trap:
3178  case Intrinsic::nvvm_suld_3d_v2i32_trap:
3180  case Intrinsic::nvvm_suld_3d_v2i64_trap:
3182  case Intrinsic::nvvm_suld_3d_v4i8_trap:
3183  return NVPTXISD::Suld3DV4I8Trap;
3184  case Intrinsic::nvvm_suld_3d_v4i16_trap:
3186  case Intrinsic::nvvm_suld_3d_v4i32_trap:
3188  case Intrinsic::nvvm_suld_1d_i8_zero:
3189  return NVPTXISD::Suld1DI8Zero;
3190  case Intrinsic::nvvm_suld_1d_i16_zero:
3191  return NVPTXISD::Suld1DI16Zero;
3192  case Intrinsic::nvvm_suld_1d_i32_zero:
3193  return NVPTXISD::Suld1DI32Zero;
3194  case Intrinsic::nvvm_suld_1d_i64_zero:
3195  return NVPTXISD::Suld1DI64Zero;
3196  case Intrinsic::nvvm_suld_1d_v2i8_zero:
3197  return NVPTXISD::Suld1DV2I8Zero;
3198  case Intrinsic::nvvm_suld_1d_v2i16_zero:
3200  case Intrinsic::nvvm_suld_1d_v2i32_zero:
3202  case Intrinsic::nvvm_suld_1d_v2i64_zero:
3204  case Intrinsic::nvvm_suld_1d_v4i8_zero:
3205  return NVPTXISD::Suld1DV4I8Zero;
3206  case Intrinsic::nvvm_suld_1d_v4i16_zero:
3208  case Intrinsic::nvvm_suld_1d_v4i32_zero:
3210  case Intrinsic::nvvm_suld_1d_array_i8_zero:
3212  case Intrinsic::nvvm_suld_1d_array_i16_zero:
3214  case Intrinsic::nvvm_suld_1d_array_i32_zero:
3216  case Intrinsic::nvvm_suld_1d_array_i64_zero:
3218  case Intrinsic::nvvm_suld_1d_array_v2i8_zero:
3220  case Intrinsic::nvvm_suld_1d_array_v2i16_zero:
3222  case Intrinsic::nvvm_suld_1d_array_v2i32_zero:
3224  case Intrinsic::nvvm_suld_1d_array_v2i64_zero:
3226  case Intrinsic::nvvm_suld_1d_array_v4i8_zero:
3228  case Intrinsic::nvvm_suld_1d_array_v4i16_zero:
3230  case Intrinsic::nvvm_suld_1d_array_v4i32_zero:
3232  case Intrinsic::nvvm_suld_2d_i8_zero:
3233  return NVPTXISD::Suld2DI8Zero;
3234  case Intrinsic::nvvm_suld_2d_i16_zero:
3235  return NVPTXISD::Suld2DI16Zero;
3236  case Intrinsic::nvvm_suld_2d_i32_zero:
3237  return NVPTXISD::Suld2DI32Zero;
3238  case Intrinsic::nvvm_suld_2d_i64_zero:
3239  return NVPTXISD::Suld2DI64Zero;
3240  case Intrinsic::nvvm_suld_2d_v2i8_zero:
3241  return NVPTXISD::Suld2DV2I8Zero;
3242  case Intrinsic::nvvm_suld_2d_v2i16_zero:
3244  case Intrinsic::nvvm_suld_2d_v2i32_zero:
3246  case Intrinsic::nvvm_suld_2d_v2i64_zero:
3248  case Intrinsic::nvvm_suld_2d_v4i8_zero:
3249  return NVPTXISD::Suld2DV4I8Zero;
3250  case Intrinsic::nvvm_suld_2d_v4i16_zero:
3252  case Intrinsic::nvvm_suld_2d_v4i32_zero:
3254  case Intrinsic::nvvm_suld_2d_array_i8_zero:
3256  case Intrinsic::nvvm_suld_2d_array_i16_zero:
3258  case Intrinsic::nvvm_suld_2d_array_i32_zero:
3260  case Intrinsic::nvvm_suld_2d_array_i64_zero:
3262  case Intrinsic::nvvm_suld_2d_array_v2i8_zero:
3264  case Intrinsic::nvvm_suld_2d_array_v2i16_zero:
3266  case Intrinsic::nvvm_suld_2d_array_v2i32_zero:
3268  case Intrinsic::nvvm_suld_2d_array_v2i64_zero:
3270  case Intrinsic::nvvm_suld_2d_array_v4i8_zero:
3272  case Intrinsic::nvvm_suld_2d_array_v4i16_zero:
3274  case Intrinsic::nvvm_suld_2d_array_v4i32_zero:
3276  case Intrinsic::nvvm_suld_3d_i8_zero:
3277  return NVPTXISD::Suld3DI8Zero;
3278  case Intrinsic::nvvm_suld_3d_i16_zero:
3279  return NVPTXISD::Suld3DI16Zero;
3280  case Intrinsic::nvvm_suld_3d_i32_zero:
3281  return NVPTXISD::Suld3DI32Zero;
3282  case Intrinsic::nvvm_suld_3d_i64_zero:
3283  return NVPTXISD::Suld3DI64Zero;
3284  case Intrinsic::nvvm_suld_3d_v2i8_zero:
3285  return NVPTXISD::Suld3DV2I8Zero;
3286  case Intrinsic::nvvm_suld_3d_v2i16_zero:
3288  case Intrinsic::nvvm_suld_3d_v2i32_zero:
3290  case Intrinsic::nvvm_suld_3d_v2i64_zero:
3292  case Intrinsic::nvvm_suld_3d_v4i8_zero:
3293  return NVPTXISD::Suld3DV4I8Zero;
3294  case Intrinsic::nvvm_suld_3d_v4i16_zero:
3296  case Intrinsic::nvvm_suld_3d_v4i32_zero:
3298  }
3299 }
3300 
3301 // llvm.ptx.memcpy.const and llvm.ptx.memmove.const need to be modeled as
3302 // TgtMemIntrinsic
3303 // because we need the information that is only available in the "Value" type
3304 // of destination
3305 // pointer. In particular, the address space information.
3307  IntrinsicInfo &Info, const CallInst &I, unsigned Intrinsic) const {
3308  switch (Intrinsic) {
3309  default:
3310  return false;
3311 
3312  case Intrinsic::nvvm_atomic_load_add_f32:
3313  case Intrinsic::nvvm_atomic_load_inc_32:
3314  case Intrinsic::nvvm_atomic_load_dec_32:
3315 
3316  case Intrinsic::nvvm_atomic_add_gen_f_cta:
3317  case Intrinsic::nvvm_atomic_add_gen_f_sys:
3318  case Intrinsic::nvvm_atomic_add_gen_i_cta:
3319  case Intrinsic::nvvm_atomic_add_gen_i_sys:
3320  case Intrinsic::nvvm_atomic_and_gen_i_cta:
3321  case Intrinsic::nvvm_atomic_and_gen_i_sys:
3322  case Intrinsic::nvvm_atomic_cas_gen_i_cta:
3323  case Intrinsic::nvvm_atomic_cas_gen_i_sys:
3324  case Intrinsic::nvvm_atomic_dec_gen_i_cta:
3325  case Intrinsic::nvvm_atomic_dec_gen_i_sys:
3326  case Intrinsic::nvvm_atomic_inc_gen_i_cta:
3327  case Intrinsic::nvvm_atomic_inc_gen_i_sys:
3328  case Intrinsic::nvvm_atomic_max_gen_i_cta:
3329  case Intrinsic::nvvm_atomic_max_gen_i_sys:
3330  case Intrinsic::nvvm_atomic_min_gen_i_cta:
3331  case Intrinsic::nvvm_atomic_min_gen_i_sys:
3332  case Intrinsic::nvvm_atomic_or_gen_i_cta:
3333  case Intrinsic::nvvm_atomic_or_gen_i_sys:
3334  case Intrinsic::nvvm_atomic_exch_gen_i_cta:
3335  case Intrinsic::nvvm_atomic_exch_gen_i_sys:
3336  case Intrinsic::nvvm_atomic_xor_gen_i_cta:
3337  case Intrinsic::nvvm_atomic_xor_gen_i_sys: {
3338  auto &DL = I.getModule()->getDataLayout();
3339  Info.opc = ISD::INTRINSIC_W_CHAIN;
3340  Info.memVT = getValueType(DL, I.getType());
3341  Info.ptrVal = I.getArgOperand(0);
3342  Info.offset = 0;
3343  Info.vol = false;
3344  Info.readMem = true;
3345  Info.writeMem = true;
3346  Info.align = 0;
3347  return true;
3348  }
3349 
3350  case Intrinsic::nvvm_ldu_global_i:
3351  case Intrinsic::nvvm_ldu_global_f:
3352  case Intrinsic::nvvm_ldu_global_p: {
3353  auto &DL = I.getModule()->getDataLayout();
3354  Info.opc = ISD::INTRINSIC_W_CHAIN;
3355  if (Intrinsic == Intrinsic::nvvm_ldu_global_i)
3356  Info.memVT = getValueType(DL, I.getType());
3357  else if(Intrinsic == Intrinsic::nvvm_ldu_global_p)
3358  Info.memVT = getPointerTy(DL);
3359  else
3360  Info.memVT = getValueType(DL, I.getType());
3361  Info.ptrVal = I.getArgOperand(0);
3362  Info.offset = 0;
3363  Info.vol = false;
3364  Info.readMem = true;
3365  Info.writeMem = false;
3366  Info.align = cast<ConstantInt>(I.getArgOperand(1))->getZExtValue();
3367 
3368  return true;
3369  }
3370  case Intrinsic::nvvm_ldg_global_i:
3371  case Intrinsic::nvvm_ldg_global_f:
3372  case Intrinsic::nvvm_ldg_global_p: {
3373  auto &DL = I.getModule()->getDataLayout();
3374 
3375  Info.opc = ISD::INTRINSIC_W_CHAIN;
3376  if (Intrinsic == Intrinsic::nvvm_ldg_global_i)
3377  Info.memVT = getValueType(DL, I.getType());
3378  else if(Intrinsic == Intrinsic::nvvm_ldg_global_p)
3379  Info.memVT = getPointerTy(DL);
3380  else
3381  Info.memVT = getValueType(DL, I.getType());
3382  Info.ptrVal = I.getArgOperand(0);
3383  Info.offset = 0;
3384  Info.vol = false;
3385  Info.readMem = true;
3386  Info.writeMem = false;
3387  Info.align = cast<ConstantInt>(I.getArgOperand(1))->getZExtValue();
3388 
3389  return true;
3390  }
3391 
3392  case Intrinsic::nvvm_tex_1d_v4f32_s32:
3393  case Intrinsic::nvvm_tex_1d_v4f32_f32:
3394  case Intrinsic::nvvm_tex_1d_level_v4f32_f32:
3395  case Intrinsic::nvvm_tex_1d_grad_v4f32_f32:
3396  case Intrinsic::nvvm_tex_1d_array_v4f32_s32:
3397  case Intrinsic::nvvm_tex_1d_array_v4f32_f32:
3398  case Intrinsic::nvvm_tex_1d_array_level_v4f32_f32:
3399  case Intrinsic::nvvm_tex_1d_array_grad_v4f32_f32:
3400  case Intrinsic::nvvm_tex_2d_v4f32_s32:
3401  case Intrinsic::nvvm_tex_2d_v4f32_f32:
3402  case Intrinsic::nvvm_tex_2d_level_v4f32_f32:
3403  case Intrinsic::nvvm_tex_2d_grad_v4f32_f32:
3404  case Intrinsic::nvvm_tex_2d_array_v4f32_s32:
3405  case Intrinsic::nvvm_tex_2d_array_v4f32_f32:
3406  case Intrinsic::nvvm_tex_2d_array_level_v4f32_f32:
3407  case Intrinsic::nvvm_tex_2d_array_grad_v4f32_f32:
3408  case Intrinsic::nvvm_tex_3d_v4f32_s32:
3409  case Intrinsic::nvvm_tex_3d_v4f32_f32:
3410  case Intrinsic::nvvm_tex_3d_level_v4f32_f32:
3411  case Intrinsic::nvvm_tex_3d_grad_v4f32_f32:
3412  case Intrinsic::nvvm_tex_cube_v4f32_f32:
3413  case Intrinsic::nvvm_tex_cube_level_v4f32_f32:
3414  case Intrinsic::nvvm_tex_cube_array_v4f32_f32:
3415  case Intrinsic::nvvm_tex_cube_array_level_v4f32_f32:
3416  case Intrinsic::nvvm_tld4_r_2d_v4f32_f32:
3417  case Intrinsic::nvvm_tld4_g_2d_v4f32_f32:
3418  case Intrinsic::nvvm_tld4_b_2d_v4f32_f32:
3419  case Intrinsic::nvvm_tld4_a_2d_v4f32_f32:
3420  case Intrinsic::nvvm_tex_unified_1d_v4f32_s32:
3421  case Intrinsic::nvvm_tex_unified_1d_v4f32_f32:
3422  case Intrinsic::nvvm_tex_unified_1d_level_v4f32_f32:
3423  case Intrinsic::nvvm_tex_unified_1d_grad_v4f32_f32:
3424  case Intrinsic::nvvm_tex_unified_1d_array_v4f32_s32:
3425  case Intrinsic::nvvm_tex_unified_1d_array_v4f32_f32:
3426  case Intrinsic::nvvm_tex_unified_1d_array_level_v4f32_f32:
3427  case Intrinsic::nvvm_tex_unified_1d_array_grad_v4f32_f32:
3428  case Intrinsic::nvvm_tex_unified_2d_v4f32_s32:
3429  case Intrinsic::nvvm_tex_unified_2d_v4f32_f32:
3430  case Intrinsic::nvvm_tex_unified_2d_level_v4f32_f32:
3431  case Intrinsic::nvvm_tex_unified_2d_grad_v4f32_f32:
3432  case Intrinsic::nvvm_tex_unified_2d_array_v4f32_s32:
3433  case Intrinsic::nvvm_tex_unified_2d_array_v4f32_f32:
3434  case Intrinsic::nvvm_tex_unified_2d_array_level_v4f32_f32:
3435  case Intrinsic::nvvm_tex_unified_2d_array_grad_v4f32_f32:
3436  case Intrinsic::nvvm_tex_unified_3d_v4f32_s32:
3437  case Intrinsic::nvvm_tex_unified_3d_v4f32_f32:
3438  case Intrinsic::nvvm_tex_unified_3d_level_v4f32_f32:
3439  case Intrinsic::nvvm_tex_unified_3d_grad_v4f32_f32:
3440  case Intrinsic::nvvm_tex_unified_cube_v4f32_f32:
3441  case Intrinsic::nvvm_tex_unified_cube_level_v4f32_f32:
3442  case Intrinsic::nvvm_tex_unified_cube_array_v4f32_f32:
3443  case Intrinsic::nvvm_tex_unified_cube_array_level_v4f32_f32:
3444  case Intrinsic::nvvm_tld4_unified_r_2d_v4f32_f32:
3445  case Intrinsic::nvvm_tld4_unified_g_2d_v4f32_f32:
3446  case Intrinsic::nvvm_tld4_unified_b_2d_v4f32_f32:
3447  case Intrinsic::nvvm_tld4_unified_a_2d_v4f32_f32:
3448  Info.opc = getOpcForTextureInstr(Intrinsic);
3449  Info.memVT = MVT::v4f32;
3450  Info.ptrVal = nullptr;
3451  Info.offset = 0;
3452  Info.vol = false;
3453  Info.readMem = true;
3454  Info.writeMem = false;
3455  Info.align = 16;
3456  return true;
3457 
3458  case Intrinsic::nvvm_tex_1d_v4s32_s32:
3459  case Intrinsic::nvvm_tex_1d_v4s32_f32:
3460  case Intrinsic::nvvm_tex_1d_level_v4s32_f32:
3461  case Intrinsic::nvvm_tex_1d_grad_v4s32_f32:
3462  case Intrinsic::nvvm_tex_1d_array_v4s32_s32:
3463  case Intrinsic::nvvm_tex_1d_array_v4s32_f32:
3464  case Intrinsic::nvvm_tex_1d_array_level_v4s32_f32:
3465  case Intrinsic::nvvm_tex_1d_array_grad_v4s32_f32:
3466  case Intrinsic::nvvm_tex_2d_v4s32_s32:
3467  case Intrinsic::nvvm_tex_2d_v4s32_f32:
3468  case Intrinsic::nvvm_tex_2d_level_v4s32_f32:
3469  case Intrinsic::nvvm_tex_2d_grad_v4s32_f32:
3470  case Intrinsic::nvvm_tex_2d_array_v4s32_s32:
3471  case Intrinsic::nvvm_tex_2d_array_v4s32_f32:
3472  case Intrinsic::nvvm_tex_2d_array_level_v4s32_f32:
3473  case Intrinsic::nvvm_tex_2d_array_grad_v4s32_f32:
3474  case Intrinsic::nvvm_tex_3d_v4s32_s32:
3475  case Intrinsic::nvvm_tex_3d_v4s32_f32:
3476  case Intrinsic::nvvm_tex_3d_level_v4s32_f32:
3477  case Intrinsic::nvvm_tex_3d_grad_v4s32_f32:
3478  case Intrinsic::nvvm_tex_cube_v4s32_f32:
3479  case Intrinsic::nvvm_tex_cube_level_v4s32_f32:
3480  case Intrinsic::nvvm_tex_cube_array_v4s32_f32:
3481  case Intrinsic::nvvm_tex_cube_array_level_v4s32_f32:
3482  case Intrinsic::nvvm_tex_cube_v4u32_f32:
3483  case Intrinsic::nvvm_tex_cube_level_v4u32_f32:
3484  case Intrinsic::nvvm_tex_cube_array_v4u32_f32:
3485  case Intrinsic::nvvm_tex_cube_array_level_v4u32_f32:
3486  case Intrinsic::nvvm_tex_1d_v4u32_s32:
3487  case Intrinsic::nvvm_tex_1d_v4u32_f32:
3488  case Intrinsic::nvvm_tex_1d_level_v4u32_f32:
3489  case Intrinsic::nvvm_tex_1d_grad_v4u32_f32:
3490  case Intrinsic::nvvm_tex_1d_array_v4u32_s32:
3491  case Intrinsic::nvvm_tex_1d_array_v4u32_f32:
3492  case Intrinsic::nvvm_tex_1d_array_level_v4u32_f32:
3493  case Intrinsic::nvvm_tex_1d_array_grad_v4u32_f32:
3494  case Intrinsic::nvvm_tex_2d_v4u32_s32:
3495  case Intrinsic::nvvm_tex_2d_v4u32_f32:
3496  case Intrinsic::nvvm_tex_2d_level_v4u32_f32:
3497  case Intrinsic::nvvm_tex_2d_grad_v4u32_f32:
3498  case Intrinsic::nvvm_tex_2d_array_v4u32_s32:
3499  case Intrinsic::nvvm_tex_2d_array_v4u32_f32:
3500  case Intrinsic::nvvm_tex_2d_array_level_v4u32_f32:
3501  case Intrinsic::nvvm_tex_2d_array_grad_v4u32_f32:
3502  case Intrinsic::nvvm_tex_3d_v4u32_s32:
3503  case Intrinsic::nvvm_tex_3d_v4u32_f32:
3504  case Intrinsic::nvvm_tex_3d_level_v4u32_f32:
3505  case Intrinsic::nvvm_tex_3d_grad_v4u32_f32:
3506  case Intrinsic::nvvm_tld4_r_2d_v4s32_f32:
3507  case Intrinsic::nvvm_tld4_g_2d_v4s32_f32:
3508  case Intrinsic::nvvm_tld4_b_2d_v4s32_f32:
3509  case Intrinsic::nvvm_tld4_a_2d_v4s32_f32:
3510  case Intrinsic::nvvm_tld4_r_2d_v4u32_f32:
3511  case Intrinsic::nvvm_tld4_g_2d_v4u32_f32:
3512  case Intrinsic::nvvm_tld4_b_2d_v4u32_f32:
3513  case Intrinsic::nvvm_tld4_a_2d_v4u32_f32:
3514  case Intrinsic::nvvm_tex_unified_1d_v4s32_s32:
3515  case Intrinsic::nvvm_tex_unified_1d_v4s32_f32:
3516  case Intrinsic::nvvm_tex_unified_1d_level_v4s32_f32:
3517  case Intrinsic::nvvm_tex_unified_1d_grad_v4s32_f32:
3518  case Intrinsic::nvvm_tex_unified_1d_array_v4s32_s32:
3519  case Intrinsic::nvvm_tex_unified_1d_array_v4s32_f32:
3520  case Intrinsic::nvvm_tex_unified_1d_array_level_v4s32_f32:
3521  case Intrinsic::nvvm_tex_unified_1d_array_grad_v4s32_f32:
3522  case Intrinsic::nvvm_tex_unified_2d_v4s32_s32:
3523  case Intrinsic::nvvm_tex_unified_2d_v4s32_f32:
3524  case Intrinsic::nvvm_tex_unified_2d_level_v4s32_f32:
3525  case Intrinsic::nvvm_tex_unified_2d_grad_v4s32_f32:
3526  case Intrinsic::nvvm_tex_unified_2d_array_v4s32_s32:
3527  case Intrinsic::nvvm_tex_unified_2d_array_v4s32_f32:
3528  case Intrinsic::nvvm_tex_unified_2d_array_level_v4s32_f32:
3529  case Intrinsic::nvvm_tex_unified_2d_array_grad_v4s32_f32:
3530  case Intrinsic::nvvm_tex_unified_3d_v4s32_s32:
3531  case Intrinsic::nvvm_tex_unified_3d_v4s32_f32:
3532  case Intrinsic::nvvm_tex_unified_3d_level_v4s32_f32:
3533  case Intrinsic::nvvm_tex_unified_3d_grad_v4s32_f32:
3534  case Intrinsic::nvvm_tex_unified_1d_v4u32_s32:
3535  case Intrinsic::nvvm_tex_unified_1d_v4u32_f32:
3536  case Intrinsic::nvvm_tex_unified_1d_level_v4u32_f32:
3537  case Intrinsic::nvvm_tex_unified_1d_grad_v4u32_f32:
3538  case Intrinsic::nvvm_tex_unified_1d_array_v4u32_s32:
3539  case Intrinsic::nvvm_tex_unified_1d_array_v4u32_f32:
3540  case Intrinsic::nvvm_tex_unified_1d_array_level_v4u32_f32:
3541  case Intrinsic::nvvm_tex_unified_1d_array_grad_v4u32_f32:
3542  case Intrinsic::nvvm_tex_unified_2d_v4u32_s32:
3543  case Intrinsic::nvvm_tex_unified_2d_v4u32_f32:
3544  case Intrinsic::nvvm_tex_unified_2d_level_v4u32_f32:
3545  case Intrinsic::nvvm_tex_unified_2d_grad_v4u32_f32:
3546  case Intrinsic::nvvm_tex_unified_2d_array_v4u32_s32:
3547  case Intrinsic::nvvm_tex_unified_2d_array_v4u32_f32:
3548  case Intrinsic::nvvm_tex_unified_2d_array_level_v4u32_f32:
3549  case Intrinsic::nvvm_tex_unified_2d_array_grad_v4u32_f32:
3550  case Intrinsic::nvvm_tex_unified_3d_v4u32_s32:
3551  case Intrinsic::nvvm_tex_unified_3d_v4u32_f32:
3552  case Intrinsic::nvvm_tex_unified_3d_level_v4u32_f32:
3553  case Intrinsic::nvvm_tex_unified_3d_grad_v4u32_f32:
3554  case Intrinsic::nvvm_tex_unified_cube_v4s32_f32:
3555  case Intrinsic::nvvm_tex_unified_cube_level_v4s32_f32:
3556  case Intrinsic::nvvm_tex_unified_cube_array_v4s32_f32:
3557  case Intrinsic::nvvm_tex_unified_cube_array_level_v4s32_f32:
3558  case Intrinsic::nvvm_tex_unified_cube_v4u32_f32:
3559  case Intrinsic::nvvm_tex_unified_cube_level_v4u32_f32:
3560  case Intrinsic::nvvm_tex_unified_cube_array_v4u32_f32:
3561  case Intrinsic::nvvm_tex_unified_cube_array_level_v4u32_f32:
3562  case Intrinsic::nvvm_tld4_unified_r_2d_v4s32_f32:
3563  case Intrinsic::nvvm_tld4_unified_g_2d_v4s32_f32:
3564  case Intrinsic::nvvm_tld4_unified_b_2d_v4s32_f32:
3565  case Intrinsic::nvvm_tld4_unified_a_2d_v4s32_f32:
3566  case Intrinsic::nvvm_tld4_unified_r_2d_v4u32_f32:
3567  case Intrinsic::nvvm_tld4_unified_g_2d_v4u32_f32:
3568  case Intrinsic::nvvm_tld4_unified_b_2d_v4u32_f32:
3569  case Intrinsic::nvvm_tld4_unified_a_2d_v4u32_f32:
3570  Info.opc = getOpcForTextureInstr(Intrinsic);
3571  Info.memVT = MVT::v4i32;
3572  Info.ptrVal = nullptr;
3573  Info.offset = 0;
3574  Info.vol = false;
3575  Info.readMem = true;
3576  Info.writeMem = false;
3577  Info.align = 16;
3578  return true;
3579 
3580  case Intrinsic::nvvm_suld_1d_i8_clamp:
3581  case Intrinsic::nvvm_suld_1d_v2i8_clamp:
3582  case Intrinsic::nvvm_suld_1d_v4i8_clamp:
3583  case Intrinsic::nvvm_suld_1d_array_i8_clamp:
3584  case Intrinsic::nvvm_suld_1d_array_v2i8_clamp:
3585  case Intrinsic::nvvm_suld_1d_array_v4i8_clamp:
3586  case Intrinsic::nvvm_suld_2d_i8_clamp:
3587  case Intrinsic::nvvm_suld_2d_v2i8_clamp:
3588  case Intrinsic::nvvm_suld_2d_v4i8_clamp:
3589  case Intrinsic::nvvm_suld_2d_array_i8_clamp:
3590  case Intrinsic::nvvm_suld_2d_array_v2i8_clamp:
3591  case Intrinsic::nvvm_suld_2d_array_v4i8_clamp:
3592  case Intrinsic::nvvm_suld_3d_i8_clamp:
3593  case Intrinsic::nvvm_suld_3d_v2i8_clamp:
3594  case Intrinsic::nvvm_suld_3d_v4i8_clamp:
3595  case Intrinsic::nvvm_suld_1d_i8_trap:
3596  case Intrinsic::nvvm_suld_1d_v2i8_trap:
3597  case Intrinsic::nvvm_suld_1d_v4i8_trap:
3598  case Intrinsic::nvvm_suld_1d_array_i8_trap:
3599  case Intrinsic::nvvm_suld_1d_array_v2i8_trap:
3600  case Intrinsic::nvvm_suld_1d_array_v4i8_trap:
3601  case Intrinsic::nvvm_suld_2d_i8_trap:
3602  case Intrinsic::nvvm_suld_2d_v2i8_trap:
3603  case Intrinsic::nvvm_suld_2d_v4i8_trap:
3604  case Intrinsic::nvvm_suld_2d_array_i8_trap:
3605  case Intrinsic::nvvm_suld_2d_array_v2i8_trap:
3606  case Intrinsic::nvvm_suld_2d_array_v4i8_trap:
3607  case Intrinsic::nvvm_suld_3d_i8_trap:
3608  case Intrinsic::nvvm_suld_3d_v2i8_trap:
3609  case Intrinsic::nvvm_suld_3d_v4i8_trap:
3610  case Intrinsic::nvvm_suld_1d_i8_zero:
3611  case Intrinsic::nvvm_suld_1d_v2i8_zero:
3612  case Intrinsic::nvvm_suld_1d_v4i8_zero:
3613  case Intrinsic::nvvm_suld_1d_array_i8_zero:
3614  case Intrinsic::nvvm_suld_1d_array_v2i8_zero:
3615  case Intrinsic::nvvm_suld_1d_array_v4i8_zero:
3616  case Intrinsic::nvvm_suld_2d_i8_zero:
3617  case Intrinsic::nvvm_suld_2d_v2i8_zero:
3618  case Intrinsic::nvvm_suld_2d_v4i8_zero:
3619  case Intrinsic::nvvm_suld_2d_array_i8_zero:
3620  case Intrinsic::nvvm_suld_2d_array_v2i8_zero:
3621  case Intrinsic::nvvm_suld_2d_array_v4i8_zero:
3622  case Intrinsic::nvvm_suld_3d_i8_zero:
3623  case Intrinsic::nvvm_suld_3d_v2i8_zero:
3624  case Intrinsic::nvvm_suld_3d_v4i8_zero:
3625  Info.opc = getOpcForSurfaceInstr(Intrinsic);
3626  Info.memVT = MVT::i8;
3627  Info.ptrVal = nullptr;
3628  Info.offset = 0;
3629  Info.vol = false;
3630  Info.readMem = true;
3631  Info.writeMem = false;
3632  Info.align = 16;
3633  return true;
3634 
3635  case Intrinsic::nvvm_suld_1d_i16_clamp:
3636  case Intrinsic::nvvm_suld_1d_v2i16_clamp:
3637  case Intrinsic::nvvm_suld_1d_v4i16_clamp:
3638  case Intrinsic::nvvm_suld_1d_array_i16_clamp:
3639  case Intrinsic::nvvm_suld_1d_array_v2i16_clamp:
3640  case Intrinsic::nvvm_suld_1d_array_v4i16_clamp:
3641  case Intrinsic::nvvm_suld_2d_i16_clamp:
3642  case Intrinsic::nvvm_suld_2d_v2i16_clamp:
3643  case Intrinsic::nvvm_suld_2d_v4i16_clamp:
3644  case Intrinsic::nvvm_suld_2d_array_i16_clamp:
3645  case Intrinsic::nvvm_suld_2d_array_v2i16_clamp:
3646  case Intrinsic::nvvm_suld_2d_array_v4i16_clamp:
3647  case Intrinsic::nvvm_suld_3d_i16_clamp:
3648  case Intrinsic::nvvm_suld_3d_v2i16_clamp:
3649  case Intrinsic::nvvm_suld_3d_v4i16_clamp:
3650  case Intrinsic::nvvm_suld_1d_i16_trap:
3651  case Intrinsic::nvvm_suld_1d_v2i16_trap:
3652  case Intrinsic::nvvm_suld_1d_v4i16_trap:
3653  case Intrinsic::nvvm_suld_1d_array_i16_trap:
3654  case Intrinsic::nvvm_suld_1d_array_v2i16_trap:
3655  case Intrinsic::nvvm_suld_1d_array_v4i16_trap:
3656  case Intrinsic::nvvm_suld_2d_i16_trap:
3657  case Intrinsic::nvvm_suld_2d_v2i16_trap:
3658  case Intrinsic::nvvm_suld_2d_v4i16_trap:
3659  case Intrinsic::nvvm_suld_2d_array_i16_trap:
3660  case Intrinsic::nvvm_suld_2d_array_v2i16_trap:
3661  case Intrinsic::nvvm_suld_2d_array_v4i16_trap:
3662  case Intrinsic::nvvm_suld_3d_i16_trap:
3663  case Intrinsic::nvvm_suld_3d_v2i16_trap:
3664  case Intrinsic::nvvm_suld_3d_v4i16_trap:
3665  case Intrinsic::nvvm_suld_1d_i16_zero:
3666  case Intrinsic::nvvm_suld_1d_v2i16_zero:
3667  case Intrinsic::nvvm_suld_1d_v4i16_zero:
3668  case Intrinsic::nvvm_suld_1d_array_i16_zero:
3669  case Intrinsic::nvvm_suld_1d_array_v2i16_zero:
3670  case Intrinsic::nvvm_suld_1d_array_v4i16_zero:
3671  case Intrinsic::nvvm_suld_2d_i16_zero:
3672  case Intrinsic::nvvm_suld_2d_v2i16_zero:
3673  case Intrinsic::nvvm_suld_2d_v4i16_zero:
3674  case Intrinsic::nvvm_suld_2d_array_i16_zero:
3675  case Intrinsic::nvvm_suld_2d_array_v2i16_zero:
3676  case Intrinsic::nvvm_suld_2d_array_v4i16_zero:
3677  case Intrinsic::nvvm_suld_3d_i16_zero:
3678  case Intrinsic::nvvm_suld_3d_v2i16_zero:
3679  case Intrinsic::nvvm_suld_3d_v4i16_zero:
3680  Info.opc = getOpcForSurfaceInstr(Intrinsic);
3681  Info.memVT = MVT::i16;
3682  Info.ptrVal = nullptr;
3683  Info.offset = 0;
3684  Info.vol = false;
3685  Info.readMem = true;
3686  Info.writeMem = false;
3687  Info.align = 16;
3688  return true;
3689 
3690  case Intrinsic::nvvm_suld_1d_i32_clamp:
3691  case Intrinsic::nvvm_suld_1d_v2i32_clamp:
3692  case Intrinsic::nvvm_suld_1d_v4i32_clamp:
3693  case Intrinsic::nvvm_suld_1d_array_i32_clamp:
3694  case Intrinsic::nvvm_suld_1d_array_v2i32_clamp:
3695  case Intrinsic::nvvm_suld_1d_array_v4i32_clamp:
3696  case Intrinsic::nvvm_suld_2d_i32_clamp:
3697  case Intrinsic::nvvm_suld_2d_v2i32_clamp:
3698  case Intrinsic::nvvm_suld_2d_v4i32_clamp:
3699  case Intrinsic::nvvm_suld_2d_array_i32_clamp:
3700  case Intrinsic::nvvm_suld_2d_array_v2i32_clamp:
3701  case Intrinsic::nvvm_suld_2d_array_v4i32_clamp:
3702  case Intrinsic::nvvm_suld_3d_i32_clamp:
3703  case Intrinsic::nvvm_suld_3d_v2i32_clamp:
3704  case Intrinsic::nvvm_suld_3d_v4i32_clamp:
3705  case Intrinsic::nvvm_suld_1d_i32_trap:
3706  case Intrinsic::nvvm_suld_1d_v2i32_trap:
3707  case Intrinsic::nvvm_suld_1d_v4i32_trap:
3708  case Intrinsic::nvvm_suld_1d_array_i32_trap:
3709  case Intrinsic::nvvm_suld_1d_array_v2i32_trap:
3710  case Intrinsic::nvvm_suld_1d_array_v4i32_trap:
3711  case Intrinsic::nvvm_suld_2d_i32_trap:
3712  case Intrinsic::nvvm_suld_2d_v2i32_trap:
3713  case Intrinsic::nvvm_suld_2d_v4i32_trap:
3714  case Intrinsic::nvvm_suld_2d_array_i32_trap:
3715  case Intrinsic::nvvm_suld_2d_array_v2i32_trap:
3716  case Intrinsic::nvvm_suld_2d_array_v4i32_trap:
3717  case Intrinsic::nvvm_suld_3d_i32_trap:
3718  case Intrinsic::nvvm_suld_3d_v2i32_trap:
3719  case Intrinsic::nvvm_suld_3d_v4i32_trap:
3720  case Intrinsic::nvvm_suld_1d_i32_zero:
3721  case Intrinsic::nvvm_suld_1d_v2i32_zero:
3722  case Intrinsic::nvvm_suld_1d_v4i32_zero:
3723  case Intrinsic::nvvm_suld_1d_array_i32_zero:
3724  case Intrinsic::nvvm_suld_1d_array_v2i32_zero:
3725  case Intrinsic::nvvm_suld_1d_array_v4i32_zero:
3726  case Intrinsic::nvvm_suld_2d_i32_zero:
3727  case Intrinsic::nvvm_suld_2d_v2i32_zero:
3728  case Intrinsic::nvvm_suld_2d_v4i32_zero:
3729  case Intrinsic::nvvm_suld_2d_array_i32_zero:
3730  case Intrinsic::nvvm_suld_2d_array_v2i32_zero:
3731  case Intrinsic::nvvm_suld_2d_array_v4i32_zero:
3732  case Intrinsic::nvvm_suld_3d_i32_zero:
3733  case Intrinsic::nvvm_suld_3d_v2i32_zero:
3734  case Intrinsic::nvvm_suld_3d_v4i32_zero:
3735  Info.opc = getOpcForSurfaceInstr(Intrinsic);
3736  Info.memVT = MVT::i32;
3737  Info.ptrVal = nullptr;
3738  Info.offset = 0;
3739  Info.vol = false;
3740  Info.readMem = true;
3741  Info.writeMem = false;
3742  Info.align = 16;
3743  return true;
3744 
3745  case Intrinsic::nvvm_suld_1d_i64_clamp:
3746  case Intrinsic::nvvm_suld_1d_v2i64_clamp:
3747  case Intrinsic::nvvm_suld_1d_array_i64_clamp:
3748  case Intrinsic::nvvm_suld_1d_array_v2i64_clamp:
3749  case Intrinsic::nvvm_suld_2d_i64_clamp:
3750  case Intrinsic::nvvm_suld_2d_v2i64_clamp:
3751  case Intrinsic::nvvm_suld_2d_array_i64_clamp:
3752  case Intrinsic::nvvm_suld_2d_array_v2i64_clamp:
3753  case Intrinsic::nvvm_suld_3d_i64_clamp:
3754  case Intrinsic::nvvm_suld_3d_v2i64_clamp:
3755  case Intrinsic::nvvm_suld_1d_i64_trap:
3756  case Intrinsic::nvvm_suld_1d_v2i64_trap:
3757  case Intrinsic::nvvm_suld_1d_array_i64_trap:
3758  case Intrinsic::nvvm_suld_1d_array_v2i64_trap:
3759  case Intrinsic::nvvm_suld_2d_i64_trap:
3760  case Intrinsic::nvvm_suld_2d_v2i64_trap:
3761  case Intrinsic::nvvm_suld_2d_array_i64_trap:
3762  case Intrinsic::nvvm_suld_2d_array_v2i64_trap:
3763  case Intrinsic::nvvm_suld_3d_i64_trap:
3764  case Intrinsic::nvvm_suld_3d_v2i64_trap:
3765  case Intrinsic::nvvm_suld_1d_i64_zero:
3766  case Intrinsic::nvvm_suld_1d_v2i64_zero:
3767  case Intrinsic::nvvm_suld_1d_array_i64_zero:
3768  case Intrinsic::nvvm_suld_1d_array_v2i64_zero:
3769  case Intrinsic::nvvm_suld_2d_i64_zero:
3770  case Intrinsic::nvvm_suld_2d_v2i64_zero:
3771  case Intrinsic::nvvm_suld_2d_array_i64_zero:
3772  case Intrinsic::nvvm_suld_2d_array_v2i64_zero:
3773  case Intrinsic::nvvm_suld_3d_i64_zero:
3774  case Intrinsic::nvvm_suld_3d_v2i64_zero:
3775  Info.opc = getOpcForSurfaceInstr(Intrinsic);
3776  Info.memVT = MVT::i64;
3777  Info.ptrVal = nullptr;
3778  Info.offset = 0;
3779  Info.vol = false;
3780  Info.readMem = true;
3781  Info.writeMem = false;
3782  Info.align = 16;
3783  return true;
3784  }
3785  return false;
3786 }
3787 
3788 /// isLegalAddressingMode - Return true if the addressing mode represented
3789 /// by AM is legal for this target, for a load/store of the specified type.
3790 /// Used to guide target specific optimizations, like loop strength reduction
3791 /// (LoopStrengthReduce.cpp) and memory optimization for address mode
3792 /// (CodeGenPrepare.cpp)
3794  const AddrMode &AM, Type *Ty,
3795  unsigned AS) const {
3796  // AddrMode - This represents an addressing mode of:
3797  // BaseGV + BaseOffs + BaseReg + Scale*ScaleReg
3798  //
3799  // The legal address modes are
3800  // - [avar]
3801  // - [areg]
3802  // - [areg+immoff]
3803  // - [immAddr]
3804 
3805  if (AM.BaseGV) {
3806  return !AM.BaseOffs && !AM.HasBaseReg && !AM.Scale;
3807  }
3808 
3809  switch (AM.Scale) {
3810  case 0: // "r", "r+i" or "i" is allowed
3811  break;
3812  case 1:
3813  if (AM.HasBaseReg) // "r+r+i" or "r+r" is not allowed.
3814  return false;
3815  // Otherwise we have r+i.
3816  break;
3817  default:
3818  // No scale > 1 is allowed
3819  return false;
3820  }
3821  return true;
3822 }
3823 
3824 //===----------------------------------------------------------------------===//
3825 // NVPTX Inline Assembly Support
3826 //===----------------------------------------------------------------------===//
3827 
3828 /// getConstraintType - Given a constraint letter, return the type of
3829 /// constraint it is for this target.
3832  if (Constraint.size() == 1) {
3833  switch (Constraint[0]) {
3834  default:
3835  break;
3836  case 'b':
3837  case 'r':
3838  case 'h':
3839  case 'c':
3840  case 'l':
3841  case 'f':
3842  case 'd':
3843  case '0':
3844  case 'N':
3845  return C_RegisterClass;
3846  }
3847  }
3848  return TargetLowering::getConstraintType(Constraint);
3849 }
3850 
3851 std::pair<unsigned, const TargetRegisterClass *>
3853  StringRef Constraint,
3854  MVT VT) const {
3855  if (Constraint.size() == 1) {
3856  switch (Constraint[0]) {
3857  case 'b':
3858  return std::make_pair(0U, &NVPTX::Int1RegsRegClass);
3859  case 'c':
3860  return std::make_pair(0U, &NVPTX::Int16RegsRegClass);
3861  case 'h':
3862  return std::make_pair(0U, &NVPTX::Int16RegsRegClass);
3863  case 'r':
3864  return std::make_pair(0U, &NVPTX::Int32RegsRegClass);
3865  case 'l':
3866  case 'N':
3867  return std::make_pair(0U, &NVPTX::Int64RegsRegClass);
3868  case 'f':
3869  return std::make_pair(0U, &NVPTX::Float32RegsRegClass);
3870  case 'd':
3871  return std::make_pair(0U, &NVPTX::Float64RegsRegClass);
3872  }
3873  }
3874  return TargetLowering::getRegForInlineAsmConstraint(TRI, Constraint, VT);
3875 }
3876 
3877 //===----------------------------------------------------------------------===//
3878 // NVPTX DAG Combining
3879 //===----------------------------------------------------------------------===//
3880 
3882  CodeGenOpt::Level OptLevel) const {
3883  // Always honor command-line argument
3884  if (FMAContractLevelOpt.getNumOccurrences() > 0)
3885  return FMAContractLevelOpt > 0;
3886 
3887  // Do not contract if we're not optimizing the code.
3888  if (OptLevel == 0)
3889  return false;
3890 
3891  // Honor TargetOptions flags that explicitly say fusion is okay.
3893  return true;
3894 
3895  return allowUnsafeFPMath(MF);
3896 }
3897 
3899  // Honor TargetOptions flags that explicitly say unsafe math is okay.
3900  if (MF.getTarget().Options.UnsafeFPMath)
3901  return true;
3902 
3903  // Allow unsafe math if unsafe-fp-math attribute explicitly says so.
3904  const Function *F = MF.getFunction();
3905  if (F->hasFnAttribute("unsafe-fp-math")) {
3906  Attribute Attr = F->getFnAttribute("unsafe-fp-math");
3907  StringRef Val = Attr.getValueAsString();
3908  if (Val == "true")
3909  return true;
3910  }
3911 
3912  return false;
3913 }
3914 
3915 /// PerformADDCombineWithOperands - Try DAG combinations for an ADD with
3916 /// operands N0 and N1. This is a helper for PerformADDCombine that is
3917 /// called with the default operands, and if that fails, with commuted
3918 /// operands.
3921  const NVPTXSubtarget &Subtarget,
3922  CodeGenOpt::Level OptLevel) {
3923  SelectionDAG &DAG = DCI.DAG;
3924  // Skip non-integer, non-scalar case
3925  EVT VT=N0.getValueType();
3926  if (VT.isVector())
3927  return SDValue();
3928 
3929  // fold (add (mul a, b), c) -> (mad a, b, c)
3930  //
3931  if (N0.getOpcode() == ISD::MUL) {
3932  assert (VT.isInteger());
3933  // For integer:
3934  // Since integer multiply-add costs the same as integer multiply
3935  // but is more costly than integer add, do the fusion only when
3936  // the mul is only used in the add.
3937  if (OptLevel==CodeGenOpt::None || VT != MVT::i32 ||
3938  !N0.getNode()->hasOneUse())
3939  return SDValue();
3940 
3941  // Do the folding
3942  return DAG.getNode(NVPTXISD::IMAD, SDLoc(N), VT,
3943  N0.getOperand(0), N0.getOperand(1), N1);
3944  }
3945  else if (N0.getOpcode() == ISD::FMUL) {
3946  if (VT == MVT::f32 || VT == MVT::f64) {
3947  const auto *TLI = static_cast<const NVPTXTargetLowering *>(
3948  &DAG.getTargetLoweringInfo());
3949  if (!TLI->allowFMA(DAG.getMachineFunction(), OptLevel))
3950  return SDValue();
3951 
3952  // For floating point:
3953  // Do the fusion only when the mul has less than 5 uses and all
3954  // are add.
3955  // The heuristic is that if a use is not an add, then that use
3956  // cannot be fused into fma, therefore mul is still needed anyway.
3957  // If there are more than 4 uses, even if they are all add, fusing
3958  // them will increase register pressue.
3959  //
3960  int numUses = 0;
3961  int nonAddCount = 0;
3962  for (SDNode::use_iterator UI = N0.getNode()->use_begin(),
3963  UE = N0.getNode()->use_end();
3964  UI != UE; ++UI) {
3965  numUses++;
3966  SDNode *User = *UI;
3967  if (User->getOpcode() != ISD::FADD)
3968  ++nonAddCount;
3969  }
3970  if (numUses >= 5)
3971  return SDValue();
3972  if (nonAddCount) {
3973  int orderNo = N->getIROrder();
3974  int orderNo2 = N0.getNode()->getIROrder();
3975  // simple heuristics here for considering potential register
3976  // pressure, the logics here is that the differnce are used
3977  // to measure the distance between def and use, the longer distance
3978  // more likely cause register pressure.
3979  if (orderNo - orderNo2 < 500)
3980  return SDValue();
3981 
3982  // Now, check if at least one of the FMUL's operands is live beyond the node N,
3983  // which guarantees that the FMA will not increase register pressure at node N.
3984  bool opIsLive = false;
3985  const SDNode *left = N0.getOperand(0).getNode();
3986  const SDNode *right = N0.getOperand(1).getNode();
3987 
3988  if (isa<ConstantSDNode>(left) || isa<ConstantSDNode>(right))
3989  opIsLive = true;
3990 
3991  if (!opIsLive)
3992  for (SDNode::use_iterator UI = left->use_begin(), UE = left->use_end(); UI != UE; ++UI) {
3993  SDNode *User = *UI;
3994  int orderNo3 = User->getIROrder();
3995  if (orderNo3 > orderNo) {
3996  opIsLive = true;
3997  break;
3998  }
3999  }
4000 
4001  if (!opIsLive)
4002  for (SDNode::use_iterator UI = right->use_begin(), UE = right->use_end(); UI != UE; ++UI) {
4003  SDNode *User = *UI;
4004  int orderNo3 = User->getIROrder();
4005  if (orderNo3 > orderNo) {
4006  opIsLive = true;
4007  break;
4008  }
4009  }
4010 
4011  if (!opIsLive)
4012  return SDValue();
4013  }
4014 
4015  return DAG.getNode(ISD::FMA, SDLoc(N), VT,
4016  N0.getOperand(0), N0.getOperand(1), N1);
4017  }
4018  }
4019 
4020  return SDValue();
4021 }
4022 
4023 /// PerformADDCombine - Target-specific dag combine xforms for ISD::ADD.
4024 ///
4027  const NVPTXSubtarget &Subtarget,
4028  CodeGenOpt::Level OptLevel) {
4029  SDValue N0 = N->getOperand(0);
4030  SDValue N1 = N->getOperand(1);
4031 
4032  // First try with the default operand order.
4033  if (SDValue Result =
4034  PerformADDCombineWithOperands(N, N0, N1, DCI, Subtarget, OptLevel))
4035  return Result;
4036 
4037  // If that didn't work, try again with the operands commuted.
4038  return PerformADDCombineWithOperands(N, N1, N0, DCI, Subtarget, OptLevel);
4039 }
4040 
4043  // The type legalizer turns a vector load of i8 values into a zextload to i16
4044  // registers, optionally ANY_EXTENDs it (if target type is integer),
4045  // and ANDs off the high 8 bits. Since we turn this load into a
4046  // target-specific DAG node, the DAG combiner fails to eliminate these AND
4047  // nodes. Do that here.
4048  SDValue Val = N->getOperand(0);
4049  SDValue Mask = N->getOperand(1);
4050 
4051  if (isa<ConstantSDNode>(Val)) {
4052  std::swap(Val, Mask);
4053  }
4054 
4055  SDValue AExt;
4056  // Generally, we will see zextload -> IMOV16rr -> ANY_EXTEND -> and
4057  if (Val.getOpcode() == ISD::ANY_EXTEND) {
4058  AExt = Val;
4059  Val = Val->getOperand(0);
4060  }
4061 
4062  if (Val->isMachineOpcode() && Val->getMachineOpcode() == NVPTX::IMOV16rr) {
4063  Val = Val->getOperand(0);
4064  }
4065 
4066  if (Val->getOpcode() == NVPTXISD::LoadV2 ||
4067  Val->getOpcode() == NVPTXISD::LoadV4) {
4069  if (!MaskCnst) {
4070  // Not an AND with a constant
4071  return SDValue();
4072  }
4073 
4074  uint64_t MaskVal = MaskCnst->getZExtValue();
4075  if (MaskVal != 0xff) {
4076  // Not an AND that chops off top 8 bits
4077  return SDValue();
4078  }
4079 
4080  MemSDNode *Mem = dyn_cast<MemSDNode>(Val);
4081  if (!Mem) {
4082  // Not a MemSDNode?!?
4083  return SDValue();
4084  }
4085 
4086  EVT MemVT = Mem->getMemoryVT();
4087  if (MemVT != MVT::v2i8 && MemVT != MVT::v4i8) {
4088  // We only handle the i8 case
4089  return SDValue();
4090  }
4091 
4092  unsigned ExtType =
4093  cast<ConstantSDNode>(Val->getOperand(Val->getNumOperands()-1))->
4094  getZExtValue();
4095  if (ExtType == ISD::SEXTLOAD) {
4096  // If for some reason the load is a sextload, the and is needed to zero
4097  // out the high 8 bits
4098  return SDValue();
4099  }
4100 
4101  bool AddTo = false;
4102  if (AExt.getNode() != nullptr) {
4103  // Re-insert the ext as a zext.
4104  Val = DCI.DAG.getNode(ISD::ZERO_EXTEND, SDLoc(N),
4105  AExt.getValueType(), Val);
4106  AddTo = true;
4107  }
4108 
4109  // If we get here, the AND is unnecessary. Just replace it with the load
4110  DCI.CombineTo(N, Val, AddTo);
4111  }
4112 
4113  return SDValue();
4114 }
4115 
4118  CodeGenOpt::Level OptLevel) {
4119  assert(N->getOpcode() == ISD::SREM || N->getOpcode() == ISD::UREM);
4120 
4121  // Don't do anything at less than -O2.
4122  if (OptLevel < CodeGenOpt::Default)
4123  return SDValue();
4124 
4125  SelectionDAG &DAG = DCI.DAG;
4126  SDLoc DL(N);
4127  EVT VT = N->getValueType(0);
4128  bool IsSigned = N->getOpcode() == ISD::SREM;
4129  unsigned DivOpc = IsSigned ? ISD::SDIV : ISD::UDIV;
4130 
4131  const SDValue &Num = N->getOperand(0);
4132  const SDValue &Den = N->getOperand(1);
4133 
4134  for (const SDNode *U : Num->uses()) {
4135  if (U->getOpcode() == DivOpc && U->getOperand(0) == Num &&
4136  U->getOperand(1) == Den) {
4137  // Num % Den -> Num - (Num / Den) * Den
4138  return DAG.getNode(ISD::SUB, DL, VT, Num,
4139  DAG.getNode(ISD::MUL, DL, VT,
4140  DAG.getNode(DivOpc, DL, VT, Num, Den),
4141  Den));
4142  }
4143  }
4144  return SDValue();
4145 }
4146 
4148  Signed = 0,
4150  Unknown
4151 };
4152 
4153 /// IsMulWideOperandDemotable - Checks if the provided DAG node is an operand
4154 /// that can be demoted to \p OptSize bits without loss of information. The
4155 /// signedness of the operand, if determinable, is placed in \p S.
4157  unsigned OptSize,
4158  OperandSignedness &S) {
4159  S = Unknown;
4160 
4161  if (Op.getOpcode() == ISD::SIGN_EXTEND ||
4163  EVT OrigVT = Op.getOperand(0).getValueType();
4164  if (OrigVT.getSizeInBits() <= OptSize) {
4165  S = Signed;
4166  return true;
4167  }
4168  } else if (Op.getOpcode() == ISD::ZERO_EXTEND) {
4169  EVT OrigVT = Op.getOperand(0).getValueType();
4170  if (OrigVT.getSizeInBits() <= OptSize) {
4171  S = Unsigned;
4172  return true;
4173  }
4174  }
4175 
4176  return false;
4177 }
4178 
4179 /// AreMulWideOperandsDemotable - Checks if the given LHS and RHS operands can
4180 /// be demoted to \p OptSize bits without loss of information. If the operands
4181 /// contain a constant, it should appear as the RHS operand. The signedness of
4182 /// the operands is placed in \p IsSigned.
4184  unsigned OptSize,
4185  bool &IsSigned) {
4186  OperandSignedness LHSSign;
4187 
4188  // The LHS operand must be a demotable op
4189  if (!IsMulWideOperandDemotable(LHS, OptSize, LHSSign))
4190  return false;
4191 
4192  // We should have been able to determine the signedness from the LHS
4193  if (LHSSign == Unknown)
4194  return false;
4195 
4196  IsSigned = (LHSSign == Signed);
4197 
4198  // The RHS can be a demotable op or a constant
4199  if (ConstantSDNode *CI = dyn_cast<ConstantSDNode>(RHS)) {
4200  const APInt &Val = CI->getAPIntValue();
4201  if (LHSSign == Unsigned) {
4202  return Val.isIntN(OptSize);
4203  } else {
4204  return Val.isSignedIntN(OptSize);
4205  }
4206  } else {
4207  OperandSignedness RHSSign;
4208  if (!IsMulWideOperandDemotable(RHS, OptSize, RHSSign))
4209  return false;
4210 
4211  return LHSSign == RHSSign;
4212  }
4213 }
4214 
4215 /// TryMULWIDECombine - Attempt to replace a multiply of M bits with a multiply
4216 /// of M/2 bits that produces an M-bit result (i.e. mul.wide). This transform
4217 /// works on both multiply DAG nodes and SHL DAG nodes with a constant shift
4218 /// amount.
4221  EVT MulType = N->getValueType(0);
4222  if (MulType != MVT::i32 && MulType != MVT::i64) {
4223  return SDValue();
4224  }
4225 
4226  SDLoc DL(N);
4227  unsigned OptSize = MulType.getSizeInBits() >> 1;
4228  SDValue LHS = N->getOperand(0);
4229  SDValue RHS = N->getOperand(1);
4230 
4231  // Canonicalize the multiply so the constant (if any) is on the right
4232  if (N->getOpcode() == ISD::MUL) {
4233  if (isa<ConstantSDNode>(LHS)) {
4234  std::swap(LHS, RHS);
4235  }
4236  }
4237 
4238  // If we have a SHL, determine the actual multiply amount
4239  if (N->getOpcode() == ISD::SHL) {
4240  ConstantSDNode *ShlRHS = dyn_cast<ConstantSDNode>(RHS);
4241  if (!ShlRHS) {
4242  return SDValue();
4243  }
4244 
4245  APInt ShiftAmt = ShlRHS->getAPIntValue();
4246  unsigned BitWidth = MulType.getSizeInBits();
4247  if (ShiftAmt.sge(0) && ShiftAmt.slt(BitWidth)) {
4248  APInt MulVal = APInt(BitWidth, 1) << ShiftAmt;
4249  RHS = DCI.DAG.getConstant(MulVal, DL, MulType);
4250  } else {
4251  return SDValue();
4252  }
4253  }
4254 
4255  bool Signed;
4256  // Verify that our operands are demotable
4257  if (!AreMulWideOperandsDemotable(LHS, RHS, OptSize, Signed)) {
4258  return SDValue();
4259  }
4260 
4261  EVT DemotedVT;
4262  if (MulType == MVT::i32) {
4263  DemotedVT = MVT::i16;
4264  } else {
4265  DemotedVT = MVT::i32;
4266  }
4267 
4268  // Truncate the operands to the correct size. Note that these are just for
4269  // type consistency and will (likely) be eliminated in later phases.
4270  SDValue TruncLHS =
4271  DCI.DAG.getNode(ISD::TRUNCATE, DL, DemotedVT, LHS);
4272  SDValue TruncRHS =
4273  DCI.DAG.getNode(ISD::TRUNCATE, DL, DemotedVT, RHS);
4274 
4275  unsigned Opc;
4276  if (Signed) {
4278  } else {
4280  }
4281 
4282  return DCI.DAG.getNode(Opc, DL, MulType, TruncLHS, TruncRHS);
4283 }
4284 
4285 /// PerformMULCombine - Runs PTX-specific DAG combine patterns on MUL nodes.
4288  CodeGenOpt::Level OptLevel) {
4289  if (OptLevel > 0) {
4290  // Try mul.wide combining at OptLevel > 0
4291  if (SDValue Ret = TryMULWIDECombine(N, DCI))
4292  return Ret;
4293  }
4294 
4295  return SDValue();
4296 }
4297 
4298 /// PerformSHLCombine - Runs PTX-specific DAG combine patterns on SHL nodes.
4301  CodeGenOpt::Level OptLevel) {
4302  if (OptLevel > 0) {
4303  // Try mul.wide combining at OptLevel > 0
4304  if (SDValue Ret = TryMULWIDECombine(N, DCI))
4305  return Ret;
4306  }
4307 
4308  return SDValue();
4309 }
4310 
4313  EVT CCType = N->getValueType(0);
4314  SDValue A = N->getOperand(0);
4315  SDValue B = N->getOperand(1);
4316 
4317  if (CCType != MVT::v2i1 || A.getValueType() != MVT::v2f16)
4318  return SDValue();
4319 
4320  SDLoc DL(N);
4321  // setp.f16x2 returns two scalar predicates, which we need to
4322  // convert back to v2i1. The returned result will be scalarized by
4323  // the legalizer, but the comparison will remain a single vector
4324  // instruction.
4325  SDValue CCNode = DCI.DAG.getNode(NVPTXISD::SETP_F16X2, DL,
4326  DCI.DAG.getVTList(MVT::i1, MVT::i1),
4327  {A, B, N->getOperand(2)});
4328  return DCI.DAG.getNode(ISD::BUILD_VECTOR, DL, CCType, CCNode.getValue(0),
4329  CCNode.getValue(1));
4330 }
4331 
4332 SDValue NVPTXTargetLowering::PerformDAGCombine(SDNode *N,
4333  DAGCombinerInfo &DCI) const {
4335  switch (N->getOpcode()) {
4336  default: break;
4337  case ISD::ADD:
4338  case ISD::FADD:
4339  return PerformADDCombine(N, DCI, STI, OptLevel);
4340  case ISD::MUL:
4341  return PerformMULCombine(N, DCI, OptLevel);
4342  case ISD::SHL:
4343  return PerformSHLCombine(N, DCI, OptLevel);
4344  case ISD::AND:
4345  return PerformANDCombine(N, DCI);
4346  case ISD::UREM:
4347  case ISD::SREM:
4348  return PerformREMCombine(N, DCI, OptLevel);
4349  case ISD::SETCC:
4350  return PerformSETCCCombine(N, DCI);
4351  }
4352  return SDValue();
4353 }
4354 
4355 /// ReplaceVectorLoad - Convert vector loads into multi-output scalar loads.
4358  EVT ResVT = N->getValueType(0);
4359  SDLoc DL(N);
4360 
4361  assert(ResVT.isVector() && "Vector load must have vector type");
4362 
4363  // We only handle "native" vector sizes for now, e.g. <4 x double> is not
4364  // legal. We can (and should) split that into 2 loads of <2 x double> here
4365  // but I'm leaving that as a TODO for now.
4366  assert(ResVT.isSimple() && "Can only handle simple types");
4367  switch (ResVT.getSimpleVT().SimpleTy) {
4368  default:
4369  return;
4370  case MVT::v2i8:
4371  case MVT::v2i16:
4372  case MVT::v2i32:
4373  case MVT::v2i64:
4374  case MVT::v2f16:
4375  case MVT::v2f32:
4376  case MVT::v2f64:
4377  case MVT::v4i8:
4378  case MVT::v4i16:
4379  case MVT::v4i32:
4380  case MVT::v4f16:
4381  case MVT::v4f32:
4382  case MVT::v8f16: // <4 x f16x2>
4383  // This is a "native" vector type
4384  break;
4385  }
4386 
4387  LoadSDNode *LD = cast<LoadSDNode>(N);
4388 
4389  unsigned Align = LD->getAlignment();
4390  auto &TD = DAG.getDataLayout();
4391  unsigned PrefAlign =
4392  TD.getPrefTypeAlignment(ResVT.getTypeForEVT(*DAG.getContext()));
4393  if (Align < PrefAlign) {
4394  // This load is not sufficiently aligned, so bail out and let this vector
4395  // load be scalarized. Note that we may still be able to emit smaller
4396  // vector loads. For example, if we are loading a <4 x float> with an
4397  // alignment of 8, this check will fail but the legalizer will try again
4398  // with 2 x <2 x float>, which will succeed with an alignment of 8.
4399  return;
4400  }
4401 
4402  EVT EltVT = ResVT.getVectorElementType();
4403  unsigned NumElts = ResVT.getVectorNumElements();
4404 
4405  // Since LoadV2 is a target node, we cannot rely on DAG type legalization.
4406  // Therefore, we must ensure the type is legal. For i1 and i8, we set the
4407  // loaded type to i16 and propagate the "real" type as the memory type.
4408  bool NeedTrunc = false;
4409  if (EltVT.getSizeInBits() < 16) {
4410  EltVT = MVT::i16;
4411  NeedTrunc = true;
4412  }
4413 
4414  unsigned Opcode = 0;
4415  SDVTList LdResVTs;
4416  bool LoadF16x2 = false;
4417 
4418  switch (NumElts) {
4419  default:
4420  return;
4421  case 2:
4422  Opcode = NVPTXISD::LoadV2;
4423  LdResVTs = DAG.getVTList(EltVT, EltVT, MVT::Other);
4424  break;
4425  case 4: {
4426  Opcode = NVPTXISD::LoadV4;
4427  EVT ListVTs[] = { EltVT, EltVT, EltVT, EltVT, MVT::Other };
4428  LdResVTs = DAG.getVTList(ListVTs);
4429  break;
4430  }
4431  case 8: {
4432  // v8f16 is a special case. PTX doesn't have ld.v8.f16
4433  // instruction. Instead, we split the vector into v2f16 chunks and
4434  // load them with ld.v4.b32.
4435  assert(EltVT == MVT::f16 && "Unsupported v8 vector type.");
4436  LoadF16x2 = true;
4437  Opcode = NVPTXISD::LoadV4;
4438  EVT ListVTs[] = {MVT::v2f16, MVT::v2f16, MVT::v2f16, MVT::v2f16,
4439  MVT::Other};
4440  LdResVTs = DAG.getVTList(ListVTs);
4441  break;
4442  }
4443  }
4444 
4445  // Copy regular operands
4446  SmallVector<SDValue, 8> OtherOps(N->op_begin(), N->op_end());
4447 
4448  // The select routine does not have access to the LoadSDNode instance, so
4449  // pass along the extension information
4450  OtherOps.push_back(DAG.getIntPtrConstant(LD->getExtensionType(), DL));
4451 
4452  SDValue NewLD = DAG.getMemIntrinsicNode(Opcode, DL, LdResVTs, OtherOps,
4453  LD->getMemoryVT(),
4454  LD->getMemOperand());
4455 
4456  SmallVector<SDValue, 8> ScalarRes;
4457  if (LoadF16x2) {
4458  // Split v2f16 subvectors back into individual elements.
4459  NumElts /= 2;
4460  for (unsigned i = 0; i < NumElts; ++i) {
4461  SDValue SubVector = NewLD.getValue(i);
4462  SDValue E0 = DAG.getNode(ISD::EXTRACT_VECTOR_ELT, DL, EltVT, SubVector,
4463  DAG.getIntPtrConstant(0, DL));
4464  SDValue E1 = DAG.getNode(ISD::EXTRACT_VECTOR_ELT, DL, EltVT, SubVector,
4465  DAG.getIntPtrConstant(1, DL));
4466  ScalarRes.push_back(E0);
4467  ScalarRes.push_back(E1);
4468  }
4469  } else {
4470  for (unsigned i = 0; i < NumElts; ++i) {
4471  SDValue Res = NewLD.getValue(i);
4472  if (NeedTrunc)
4473  Res = DAG.getNode(ISD::TRUNCATE, DL, ResVT.getVectorElementType(), Res);
4474  ScalarRes.push_back(Res);
4475  }
4476  }
4477 
4478  SDValue LoadChain = NewLD.getValue(NumElts);
4479 
4480  SDValue BuildVec = DAG.getBuildVector(ResVT, DL, ScalarRes);
4481 
4482  Results.push_back(BuildVec);
4483  Results.push_back(LoadChain);
4484 }
4485 
4488  SDValue Chain = N->getOperand(0);
4489  SDValue Intrin = N->getOperand(1);
4490  SDLoc DL(N);
4491 
4492  // Get the intrinsic ID
4493  unsigned IntrinNo = cast<ConstantSDNode>(Intrin.getNode())->getZExtValue();
4494  switch (IntrinNo) {
4495  default:
4496  return;
4497  case Intrinsic::nvvm_ldg_global_i:
4498  case Intrinsic::nvvm_ldg_global_f:
4499  case Intrinsic::nvvm_ldg_global_p:
4500  case Intrinsic::nvvm_ldu_global_i:
4501  case Intrinsic::nvvm_ldu_global_f:
4502  case Intrinsic::nvvm_ldu_global_p: {
4503  EVT ResVT = N->getValueType(0);
4504 
4505  if (ResVT.isVector()) {
4506  // Vector LDG/LDU
4507 
4508  unsigned NumElts = ResVT.getVectorNumElements();
4509  EVT EltVT = ResVT.getVectorElementType();
4510 
4511  // Since LDU/LDG are target nodes, we cannot rely on DAG type
4512  // legalization.
4513  // Therefore, we must ensure the type is legal. For i1 and i8, we set the
4514  // loaded type to i16 and propagate the "real" type as the memory type.
4515  bool NeedTrunc = false;
4516  if (EltVT.getSizeInBits() < 16) {
4517  EltVT = MVT::i16;
4518  NeedTrunc = true;
4519  }
4520 
4521  unsigned Opcode = 0;
4522  SDVTList LdResVTs;
4523 
4524  switch (NumElts) {
4525  default:
4526  return;
4527  case 2:
4528  switch (IntrinNo) {
4529  default:
4530  return;
4531  case Intrinsic::nvvm_ldg_global_i:
4532  case Intrinsic::nvvm_ldg_global_f:
4533  case Intrinsic::nvvm_ldg_global_p:
4534  Opcode = NVPTXISD::LDGV2;
4535  break;
4536  case Intrinsic::nvvm_ldu_global_i:
4537  case Intrinsic::nvvm_ldu_global_f:
4538  case Intrinsic::nvvm_ldu_global_p:
4539  Opcode = NVPTXISD::LDUV2;
4540  break;
4541  }
4542  LdResVTs = DAG.getVTList(EltVT, EltVT, MVT::Other);
4543  break;
4544  case 4: {
4545  switch (IntrinNo) {
4546  default:
4547  return;
4548  case Intrinsic::nvvm_ldg_global_i:
4549  case Intrinsic::nvvm_ldg_global_f:
4550  case Intrinsic::nvvm_ldg_global_p:
4551  Opcode = NVPTXISD::LDGV4;
4552  break;
4553  case Intrinsic::nvvm_ldu_global_i:
4554  case Intrinsic::nvvm_ldu_global_f:
4555  case Intrinsic::nvvm_ldu_global_p:
4556  Opcode = NVPTXISD::LDUV4;
4557  break;
4558  }
4559  EVT ListVTs[] = { EltVT, EltVT, EltVT, EltVT, MVT::Other };
4560  LdResVTs = DAG.getVTList(ListVTs);
4561  break;
4562  }
4563  }
4564 
4565  SmallVector<SDValue, 8> OtherOps;
4566 
4567  // Copy regular operands
4568 
4569  OtherOps.push_back(Chain); // Chain
4570  // Skip operand 1 (intrinsic ID)
4571  // Others
4572  OtherOps.append(N->op_begin() + 2, N->op_end());
4573 
4574  MemIntrinsicSDNode *MemSD = cast<MemIntrinsicSDNode>(N);
4575 
4576  SDValue NewLD = DAG.getMemIntrinsicNode(Opcode, DL, LdResVTs, OtherOps,
4577  MemSD->getMemoryVT(),
4578  MemSD->getMemOperand());
4579 
4580  SmallVector<SDValue, 4> ScalarRes;
4581 
4582  for (unsigned i = 0; i < NumElts; ++i) {
4583  SDValue Res = NewLD.getValue(i);
4584  if (NeedTrunc)
4585  Res =
4586  DAG.getNode(ISD::TRUNCATE, DL, ResVT.getVectorElementType(), Res);
4587  ScalarRes.push_back(Res);
4588  }
4589 
4590  SDValue LoadChain = NewLD.getValue(NumElts);
4591 
4592  SDValue BuildVec =
4593  DAG.getBuildVector(ResVT, DL, ScalarRes);
4594 
4595  Results.push_back(BuildVec);
4596  Results.push_back(LoadChain);
4597  } else {
4598  // i8 LDG/LDU
4599  assert(ResVT.isSimple() && ResVT.getSimpleVT().SimpleTy == MVT::i8 &&
4600  "Custom handling of non-i8 ldu/ldg?");
4601 
4602  // Just copy all operands as-is
4603  SmallVector<SDValue, 4> Ops(N->op_begin(), N->op_end());
4604 
4605  // Force output to i16
4606  SDVTList LdResVTs = DAG.getVTList(MVT::i16, MVT::Other);
4607 
4608  MemIntrinsicSDNode *MemSD = cast<MemIntrinsicSDNode>(N);
4609 
4610  // We make sure the memory type is i8, which will be used during isel
4611  // to select the proper instruction.
4612  SDValue NewLD =
4613  DAG.getMemIntrinsicNode(ISD::INTRINSIC_W_CHAIN, DL, LdResVTs, Ops,
4614  MVT::i8, MemSD->getMemOperand());
4615 
4616  Results.push_back(DAG.getNode(ISD::TRUNCATE, DL, MVT::i8,
4617  NewLD.getValue(0)));
4618  Results.push_back(NewLD.getValue(1));
4619  }
4620  }
4621  }
4622 }
4623 
4624 void NVPTXTargetLowering::ReplaceNodeResults(
4626  switch (N->getOpcode()) {
4627  default:
4628  report_fatal_error("Unhandled custom legalization");
4629  case ISD::LOAD:
4630  ReplaceLoadVector(N, DAG, Results);
4631  return;
4633  ReplaceINTRINSIC_W_CHAIN(N, DAG, Results);
4634  return;
4635  }
4636 }
4637 
4638 // Pin NVPTXSection's and NVPTXTargetObjectFile's vtables to this file.
4639 void NVPTXSection::anchor() {}
4640 
4642  delete static_cast<NVPTXSection *>(TextSection);
4643  delete static_cast<NVPTXSection *>(DataSection);
4644  delete static_cast<NVPTXSection *>(BSSSection);
4645  delete static_cast<NVPTXSection *>(ReadOnlySection);
4646 
4647  delete static_cast<NVPTXSection *>(StaticCtorSection);
4648  delete static_cast<NVPTXSection *>(StaticDtorSection);
4649  delete static_cast<NVPTXSection *>(LSDASection);
4650  delete static_cast<NVPTXSection *>(EHFrameSection);
4651  delete static_cast<NVPTXSection *>(DwarfAbbrevSection);
4652  delete static_cast<NVPTXSection *>(DwarfInfoSection);
4653  delete static_cast<NVPTXSection *>(DwarfLineSection);
4654  delete static_cast<NVPTXSection *>(DwarfFrameSection);
4655  delete static_cast<NVPTXSection *>(DwarfPubTypesSection);
4656  delete static_cast<const NVPTXSection *>(DwarfDebugInlineSection);
4657  delete static_cast<NVPTXSection *>(DwarfStrSection);
4658  delete static_cast<NVPTXSection *>(DwarfLocSection);
4659  delete static_cast<NVPTXSection *>(DwarfARangesSection);
4660  delete static_cast<NVPTXSection *>(DwarfRangesSection);
4661  delete static_cast<NVPTXSection *>(DwarfMacinfoSection);
4662 }
4663 
4665  const GlobalObject *GO, SectionKind Kind, const TargetMachine &TM) const {
4666  return getDataSection();
4667 }
static unsigned getBitWidth(Type *Ty, const DataLayout &DL)
Returns the bitwidth of the given scalar or pointer type.
BITCAST - This operator converts between integer, vector and FP values, as if the value was stored to...
Definition: ISDOpcodes.h:544
Instances of this class represent a uniqued identifier for a section in the current translation unit...
Definition: MCSection.h:39
A parsed version of the target data layout string in and methods for querying it. ...
Definition: DataLayout.h:109
const_iterator end(StringRef path)
Get end iterator over path.
Definition: Path.cpp:243
FMINNUM/FMAXNUM - Perform floating-point minimum or maximum on two values.
Definition: ISDOpcodes.h:568
SDValue getValue(unsigned R) const
This represents an addressing mode of: BaseGV + BaseOffs + BaseReg + Scale*ScaleReg If BaseGV is null...
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...
bool isLegalAddressingMode(const DataLayout &DL, const AddrMode &AM, Type *Ty, unsigned AS) const override
isLegalAddressingMode - Return true if the addressing mode represented by AM is legal for this target...
This SDNode is used for target intrinsics that touch memory and need an associated MachineMemOperand...
virtual ConstraintType getConstraintType(StringRef Constraint) const
Given a constraint, return the type of constraint it is for this target.
Flags getFlags() const
Return the raw flags of the source value,.
LLVMContext * getContext() const
Definition: SelectionDAG.h:381
This class represents an incoming formal argument to a Function.
Definition: Argument.h:30
const_iterator begin(StringRef path, Style style=Style::native)
Get begin iterator over path.
Definition: Path.cpp:234
SDValue getSetCC(const SDLoc &DL, EVT VT, SDValue LHS, SDValue RHS, ISD::CondCode Cond)
Helper function to make it easier to build SetCC's if you just have an ISD::CondCode instead of an SD...
Definition: SelectionDAG.h:884
SDValue CombineTo(SDNode *N, ArrayRef< SDValue > To, bool AddTo=true)
SDValue getCALLSEQ_END(SDValue Chain, SDValue Op1, SDValue Op2, SDValue InGlue, const SDLoc &DL)
Return a new CALLSEQ_END node, which always must have a glue result (to ensure it's not CSE'd)...
Definition: SelectionDAG.h:800
static unsigned CanMergeParamLoadStoresStartingAt(unsigned Idx, uint32_t AccessSize, const SmallVectorImpl< EVT > &ValueVTs, const SmallVectorImpl< uint64_t > &Offsets, unsigned ParamAlignment)
uint64_t GreatestCommonDivisor64(uint64_t A, uint64_t B)
Return the greatest common divisor of the values using Euclid's algorithm.
Definition: MathExtras.h:555
bool getAlign(const Function &F, unsigned index, unsigned &align)
EXTRACT_SUBVECTOR(VECTOR, IDX) - Returns a subvector from VECTOR (an vector value) starting with the ...
Definition: ISDOpcodes.h:332
LLVM_ATTRIBUTE_NORETURN void report_fatal_error(Error Err, bool gen_crash_diag=true)
Report a serious error, calling any installed error handler.
Definition: Error.cpp:103
BR_CC - Conditional branch.
Definition: ISDOpcodes.h:616
unsigned getNumRegisters(LLVMContext &Context, EVT VT) const
Return the number of registers that this ValueType will eventually require.
MCSection * DwarfPubTypesSection
bool hasOneUse() const
Return true if there is exactly one use of this node.
A Module instance is used to store all the information related to an LLVM module. ...
Definition: Module.h:63
bool hasROT32() const
const TargetMachine & getTargetMachine() const
static cl::opt< unsigned > FMAContractLevelOpt("nvptx-fma-level", cl::ZeroOrMore, cl::Hidden, cl::desc("NVPTX Specific: FMA contraction (0: don't do it"" 1: do it 2: do it aggressively"), cl::init(2))
Carry-setting nodes for multiple precision addition and subtraction.
Definition: ISDOpcodes.h:222
MCSection * TextSection
Section directive for standard text.
MCSection * StaticCtorSection
This section contains the static constructor pointer list.
DataLayout DL
This class represents a function call, abstracting a target machine's calling convention.
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
unsigned getOpcode() const
Return the SelectionDAG opcode value for this node.
std::string getPrototype(const DataLayout &DL, Type *, const ArgListTy &, const SmallVectorImpl< ISD::OutputArg > &, unsigned retAlignment, const ImmutableCallSite *CS) const
static bool IsMulWideOperandDemotable(SDValue Op, unsigned OptSize, OperandSignedness &S)
IsMulWideOperandDemotable - Checks if the provided DAG node is an operand that can be demoted to OptS...
static bool isImageOrSamplerVal(const Value *arg, const Module *context)
Offsets
Offsets in bytes from the start of the input buffer.
Definition: SIInstrInfo.h:864
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.
void setBooleanVectorContents(BooleanContent Ty)
Specify how the target extends the result of a vector boolean value from a vector of i1 to a wider ty...
MCSection * getDataSection() const
unsigned getNumOperands() const
unsigned getValueSizeInBits() const
Returns the size of the value in bits.
const SDValue & getOperand(unsigned Num) const
ConstraintType getConstraintType(StringRef Constraint) const override
getConstraintType - Given a constraint letter, return the type of constraint it is for this target...
Attribute getFnAttribute(Attribute::AttrKind Kind) const
Return the attribute for the given attribute kind.
Definition: Function.h:262
const Function * getFunction() const
getFunction - Return the LLVM function that this machine code represents
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())
[US]{MIN/MAX} - Binary minimum or maximum or signed or unsigned integers.
Definition: ISDOpcodes.h:358
SDValue getTargetExternalSymbol(const char *Sym, EVT VT, unsigned char TargetFlags=0)
SDValue getNode(unsigned Opcode, const SDLoc &DL, EVT VT, ArrayRef< SDUse > Ops)
Gets or creates the specified node.
const SDValue & setRoot(SDValue N)
Set the current root tag of the SelectionDAG.
Definition: SelectionDAG.h:440
const SDValue & getBasePtr() const
SDValue LowerCall(CallLoweringInfo &CLI, SmallVectorImpl< SDValue > &InVals) const override
This hook must be implemented to lower calls into the specified DAG.
void LowerAsmOperandForConstraint(SDValue Op, std::string &Constraint, std::vector< SDValue > &Ops, SelectionDAG &DAG) const override
Lower the specified operand into the Ops vector.
Select with condition operator - This selects between a true value and a false value (ops #2 and #3) ...
Definition: ISDOpcodes.h:403
uint64_t getTypeAllocSizeInBits(Type *Ty) const
Returns the offset in bits between successive objects of the specified type, including alignment padd...
Definition: DataLayout.h:415
void setTruncStoreAction(MVT ValVT, MVT MemVT, LegalizeAction Action)
Indicate that the specified truncating store does not work with the specified type and indicate what ...
RESULT,OUTCHAIN = INTRINSIC_W_CHAIN(INCHAIN, INTRINSICID, arg1, ...) This node represents a target in...
Definition: ISDOpcodes.h:159
static Constant * getNullValue(Type *Ty)
Constructor to create a '0' constant of arbitrary type.
Definition: Constants.cpp:207
SDValue LowerReturn(SDValue Chain, CallingConv::ID CallConv, bool isVarArg, const SmallVectorImpl< ISD::OutputArg > &Outs, const SmallVectorImpl< SDValue > &OutVals, const SDLoc &dl, SelectionDAG &DAG) const override
This hook must be implemented to lower outgoing return values, described by the Outs array...
MCSection * SelectSectionForGlobal(const GlobalObject *GO, SectionKind Kind, const TargetMachine &TM) const override
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
SDValue getIntPtrConstant(uint64_t Val, const SDLoc &DL, bool isTarget=false)
static SDValue PerformREMCombine(SDNode *N, TargetLowering::DAGCombinerInfo &DCI, CodeGenOpt::Level OptLevel)
static unsigned int uniqueCallSite
static bool AreMulWideOperandsDemotable(SDValue LHS, SDValue RHS, unsigned OptSize, bool &IsSigned)
AreMulWideOperandsDemotable - Checks if the given LHS and RHS operands can be demoted to OptSize bits...
SDValue LowerGlobalAddress(SDValue Op, SelectionDAG &DAG) const
bool hasROT64() const
static cl::opt< bool > UsePrecSqrtF32("nvptx-prec-sqrtf32", cl::Hidden, cl::desc("NVPTX Specific: 0 use sqrt.approx, 1 use sqrt.rn."), cl::init(true))
Shift and rotation operations.
Definition: ISDOpcodes.h:378
static void ComputePTXValueVTs(const TargetLowering &TLI, const DataLayout &DL, Type *Ty, SmallVectorImpl< EVT > &ValueVTs, SmallVectorImpl< uint64_t > *Offsets=nullptr, uint64_t StartingOffset=0)
ComputePTXValueVTs - For the given Type Ty, returns the set of primitive EVTs that compose it...
Class to represent struct types.
Definition: DerivedTypes.h:201
EVT getValueType(unsigned ResNo) const
Return the type of a specified result.
ABS - Determine the unsigned absolute value of a signed integer value of the same bitwidth...
Definition: ISDOpcodes.h:367
MachineFunction & getMachineFunction() const
Definition: SelectionDAG.h:375
This class consists of common code factored out of the SmallVector class to reduce code duplication b...
Definition: APFloat.h:42
This file contains the simple types necessary to represent the attributes associated with functions a...
SimpleValueType SimpleTy
void addBypassSlowDiv(unsigned int SlowBitWidth, unsigned int FastBitWidth)
Tells the code generator which bitwidths to bypass.
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
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...
bool isIntN(unsigned N) const
Check if this APInt has an N-bits unsigned integer value.
Definition: APInt.h:443
SDVTList getVTList(EVT VT)
Return an SDVTList that represents the list of values specified.
FRAMEADDR, RETURNADDR - These nodes represent llvm.frameaddress and llvm.returnaddress on the DAG...
Definition: ISDOpcodes.h:73
static void ReplaceLoadVector(SDNode *N, SelectionDAG &DAG, SmallVectorImpl< SDValue > &Results)
ReplaceVectorLoad - Convert vector loads into multi-output scalar loads.
void setJumpIsExpensive(bool isExpensive=true)
Tells the code generator not to expand logic operations on comparison predicates into separate sequen...
This class defines information used to lower LLVM code to legal SelectionDAG operators that the targe...
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...
This represents a list of ValueType's that has been intern'd by a SelectionDAG.
LLVM_NODISCARD bool empty() const
Definition: SmallVector.h:60
SmallVector< ISD::InputArg, 32 > Ins
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 assign(size_type NumElts, const T &Elt)
Definition: SmallVector.h:424
APInt shl(unsigned shiftAmt) const
Left-shift function.
Definition: APInt.h:981
A constant value that is initialized with an expression using other constant values.
Definition: Constants.h:862
bool isKernelFunction(const Function &F)
#define F(x, y, z)
Definition: MD5.cpp:55
unsigned getIROrder() const
Return the node ordering.
const MCSection * DwarfDebugInlineSection
void computeRegisterProperties(const TargetRegisterInfo *TRI)
Once all of the register classes are added, this allows us to compute derived properties we expose...
[SU]INT_TO_FP - These operators convert integers (whose interpreted sign depends on the first letter)...
Definition: ISDOpcodes.h:454
unsigned int getSmVersion() const
bool isHalfTy() const
Return true if this is 'half', a 16-bit IEEE fp type.
Definition: Type.h:144
bool hasParamAttribute(unsigned ArgNo, Attribute::AttrKind Kind) const
Equivalent to hasAttribute(ArgNo + FirstArgIndex, Kind).
Simple integer binary arithmetic operators.
Definition: ISDOpcodes.h:200
MCSection * StaticDtorSection
This section contains the static destructor pointer list.
SmallVector< ISD::OutputArg, 32 > Outs
TypeID getTypeID() const
Return the type id for the type.
Definition: Type.h:138
bool isFloatingPointTy() const
Return true if this is one of the six floating-point types.
Definition: Type.h:162
AttributeSet getAttributes(unsigned Index) const
The attributes for the specified index are returned.
SDValue LowerFormalArguments(SDValue Chain, CallingConv::ID CallConv, bool isVarArg, const SmallVectorImpl< ISD::InputArg > &Ins, const SDLoc &dl, SelectionDAG &DAG, SmallVectorImpl< SDValue > &InVals) const override
This hook must be implemented to lower the incoming (formal) arguments, described by the Ins array...
const SDValue & getBasePtr() const
const APInt & getAPIntValue() const
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.
CodeGenOpt::Level getOptLevel() const
Returns the optimization level: None, Less, Default, or Aggressive.
static SDValue PerformADDCombine(SDNode *N, TargetLowering::DAGCombinerInfo &DCI, const NVPTXSubtarget &Subtarget, CodeGenOpt::Level OptLevel)
PerformADDCombine - Target-specific dag combine xforms for ISD::ADD.
void setIROrder(unsigned Order)
Set the node ordering.
LLVM_NODISCARD LLVM_ATTRIBUTE_ALWAYS_INLINE size_t size() const
size - Get the string size.
Definition: StringRef.h:138
static SDValue PerformANDCombine(SDNode *N, TargetLowering::DAGCombinerInfo &DCI)
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
void ComputeValueVTs(const TargetLowering &TLI, const DataLayout &DL, Type *Ty, SmallVectorImpl< EVT > &ValueVTs, SmallVectorImpl< uint64_t > *Offsets=nullptr, uint64_t StartingOffset=0)
ComputeValueVTs - Given an LLVM IR type, compute a sequence of EVTs that represent all the individual...
Definition: Analysis.cpp:85
MCSection * DataSection
Section directive for standard data.
Class to represent pointers.
Definition: DerivedTypes.h:467
UNDEF - An undefined node.
Definition: ISDOpcodes.h:178
This class is used to represent ISD::STORE nodes.
static SDValue PerformADDCombineWithOperands(SDNode *N, SDValue N0, SDValue N1, TargetLowering::DAGCombinerInfo &DCI, const NVPTXSubtarget &Subtarget, CodeGenOpt::Level OptLevel)
PerformADDCombineWithOperands - Try DAG combinations for an ADD with operands N0 and N1...
FP_TO_[US]INT - Convert a floating point value to a signed or unsigned integer.
Definition: ISDOpcodes.h:497
static cl::opt< int > UsePrecDivF32("nvptx-prec-divf32", cl::ZeroOrMore, cl::Hidden, cl::desc("NVPTX Specifies: 0 use div.approx, 1 use div.full, 2 use"" IEEE Compliant F32 div.rnd if available."), cl::init(2))
BUILD_VECTOR(ELT0, ELT1, ELT2, ELT3,...) - Return a vector with the specified, possibly variable...
Definition: ISDOpcodes.h:301
bool isSized(SmallPtrSetImpl< Type * > *Visited=nullptr) const
Return true if it makes sense to take the size of this type.
Definition: Type.h:262
SDNode * getNode() const
get the SDNode which holds the desired result
unsigned getStoreSize() const
Return the number of bytes overwritten by a store of the specified value type.
Definition: ValueTypes.h:304
0: type with no size
Definition: Type.h:57
#define P(N)
Type * getReturnType() const
Returns the type of the ret val.
Definition: Function.h:142
initializer< Ty > init(const Ty &Val)
Definition: CommandLine.h:401
unsigned UnsafeFPMath
UnsafeFPMath - This flag is enabled when the -enable-unsafe-fp-math flag is specified on the command ...
FPOpFusion::FPOpFusionMode AllowFPOpFusion
AllowFPOpFusion - This flag is set by the -fuse-fp-ops=xxx option.
std::pair< SDValue, SDValue > expandUnalignedLoad(LoadSDNode *LD, SelectionDAG &DAG) const
Expands an unaligned load to 2 half-size loads for an integer, and possibly more for vectors...
bool allowFMA(MachineFunction &MF, CodeGenOpt::Level OptLevel) const
constexpr bool isPowerOf2_32(uint32_t Value)
Return true if the argument is a power of two > 0.
Definition: MathExtras.h:421
Machine Value Type.
ParamVectorizationFlags
const SDValue & getOperand(unsigned i) const
The instances of the Type class are immutable: once they are created, they are never changed...
Definition: Type.h:46
void addRegisterClass(MVT VT, const TargetRegisterClass *RC)
Add the specified register class as an available regclass for the specified value type...
static cl::opt< bool > sched4reg("nvptx-sched4reg", cl::desc("NVPTX Specific: schedule for register pressue"), cl::init(false))
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...
bool isVectorTy() const
True if this is an instance of VectorType.
Definition: Type.h:227
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.
bool sge(const APInt &RHS) const
Signed greather or equal comparison.
Definition: APInt.h:1288
constexpr char Args[]
Key for Kernel::Metadata::mArgs.
This file contains the declarations for the subclasses of Constant, which represent the different fla...
const NVPTXTargetLowering * getTargetLowering() const override
Carry-using nodes for multiple precision addition and subtraction.
Definition: ISDOpcodes.h:231
#define A
Definition: LargeTest.cpp:12
SDValue getCALLSEQ_START(SDValue Chain, uint64_t InSize, uint64_t OutSize, const SDLoc &DL)
Return a new CALLSEQ_START node, that starts new call frame, in which InSize bytes are set up inside ...
Definition: SelectionDAG.h:788
void setBooleanContents(BooleanContent Ty)
Specify how the target extends the result of integer and floating point boolean values from i1 to a w...
static unsigned getOpcForSurfaceInstr(unsigned Intrinsic)
virtual std::pair< unsigned, const TargetRegisterClass * > getRegForInlineAsmConstraint(const TargetRegisterInfo *TRI, StringRef Constraint, MVT VT) const
Given a physical register constraint (e.g.
This class provides iterator support for SDUse operands that use a specific SDNode.
std::pair< unsigned, const TargetRegisterClass * > getRegForInlineAsmConstraint(const TargetRegisterInfo *TRI, StringRef Constraint, MVT VT) const override
Given a physical register constraint (e.g.
unsigned getOpcode() const
TRAP - Trapping instruction.
Definition: ISDOpcodes.h:727
ManagedStringPool * getManagedStrPool() const
SectionKind - This is a simple POD value that classifies the properties of a section.
Definition: SectionKind.h:23
bool allowUnsafeFPMath(MachineFunction &MF) const
static mvt_range vector_valuetypes()
use_iterator use_begin() const
Provide iteration support to walk over all uses of an SDNode.
const SDValue & getValue() const
unsigned MaxStoresPerMemmove
Specify maximum bytes of store instructions per memmove call.
const char * getTargetNodeName(unsigned Opcode) const override
This method returns the name of a target specific DAG node.
static void ReplaceINTRINSIC_W_CHAIN(SDNode *N, SelectionDAG &DAG, SmallVectorImpl< SDValue > &Results)
std::vector< ArgListEntry > ArgListTy
Extended Value Type.
Definition: ValueTypes.h:34
bool isPointerTy() const
True if this is an instance of PointerType.
Definition: Type.h:221
static SDValue PerformSHLCombine(SDNode *N, TargetLowering::DAGCombinerInfo &DCI, CodeGenOpt::Level OptLevel)
PerformSHLCombine - Runs PTX-specific DAG combine patterns on SHL nodes.
TargetRegisterInfo base class - We assume that the target defines a static array of TargetRegisterDes...
This structure contains all information that is necessary for lowering calls.
This class contains a discriminated union of information about pointers in memory operands...
static bool IsPTXVectorType(MVT VT)
const SDValue & getRoot() const
Return the root tag of the SelectionDAG.
Definition: SelectionDAG.h:431
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...
MCSection * DwarfAbbrevSection
unsigned first
const MachinePointerInfo & getPointerInfo() const
static SDValue TryMULWIDECombine(SDNode *N, TargetLowering::DAGCombinerInfo &DCI)
TryMULWIDECombine - Attempt to replace a multiply of M bits with a multiply of M/2 bits that produces...
MCSection * EHFrameSection
EH frame section.
LegalizeAction
This enum indicates whether operations are valid for a target, and if not, what action should be used...
TokenFactor - This node takes multiple tokens as input and produces a single token result...
Definition: ISDOpcodes.h:50
unsigned getABITypeAlignment(Type *Ty) const
Returns the minimum ABI-required alignment for the specified type.
Definition: DataLayout.cpp:680
TargetLoweringBase::LegalizeTypeAction getPreferredVectorAction(EVT VT) const override
Return the preferred vector type legalization action.
SmallVectorImpl< T >::const_pointer c_str(SmallVectorImpl< T > &str)
#define E
Definition: LargeTest.cpp:27
auto find(R &&Range, const T &Val) -> decltype(std::begin(Range))
Provide wrappers to std::find which take ranges instead of having to pass begin/end explicitly...
Definition: STLExtras.h:839
InstrTy * getInstruction() const
Definition: CallSite.h:89
#define B
Definition: LargeTest.cpp:24
std::string * getManagedString(const char *S)
bool getTgtMemIntrinsic(IntrinsicInfo &Info, const CallInst &I, unsigned Intrinsic) const override
Given an intrinsic, checks if on the target the intrinsic will need to map to a MemIntrinsicNode (tou...
SDValue getSqrtEstimate(SDValue Operand, SelectionDAG &DAG, int Enabled, int &ExtraSteps, bool &UseOneConst, bool Reciprocal) const override
Hooks for building estimates in place of slower divisions and square roots.
EXTRACT_VECTOR_ELT(VECTOR, IDX) - Returns a single element from VECTOR identified by the (potentially...
Definition: ISDOpcodes.h:313
uint64_t getTypeAllocSize(Type *Ty) const
Returns the offset in bytes between successive objects of the specified type, including alignment pad...
Definition: DataLayout.h:405
This is used to represent a portion of an LLVM function in a low-level Data Dependence DAG representa...
Definition: SelectionDAG.h:209
const Module * getModule() const
Return the module owning the function this instruction belongs to or nullptr it the function does not...
Definition: Instruction.cpp:57
This is a 'vector' (really, a variable-sized array), optimized for the case when the array is small...
Definition: SmallVector.h:861
Module.h This file contains the declarations for the Module class.
Type * getType() const
All values are typed, get the type of this value.
Definition: Value.h:245
NVPTXTargetLowering(const NVPTXTargetMachine &TM, const NVPTXSubtarget &STI)
SDValue getBuildVector(EVT VT, const SDLoc &DL, ArrayRef< SDValue > Ops)
Return an ISD::BUILD_VECTOR node.
Definition: SelectionDAG.h:698
MCSection * DwarfRangesSection
const SDValue & getChain() const
Byte Swap and Counting operators.
Definition: ISDOpcodes.h:381
const size_t N
MachineMemOperand * getMemOperand() const
Return a MachineMemOperand object describing the memory reference performed by operation.
This is an abstract virtual class for memory operations.
MCSection * DwarfARangesSection
Wrapper class for IR location info (IR ordering and DebugLoc) to be passed into SDNode creation funct...
Represents one node in the SelectionDAG.
static bool Enabled
Definition: Statistic.cpp:49
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
Value * getArgOperand(unsigned i) const
getArgOperand/setArgOperand - Return/set the i-th call argument.
ISD::LoadExtType getExtensionType() const
Return whether this is a plain node, or one of the varieties of value-extending loads.
static EVT getVectorVT(LLVMContext &Context, EVT VT, unsigned NumElements, bool IsScalable=false)
Returns the EVT that represents a vector NumElements in length, where each element is of type VT...
Definition: ValueTypes.h:73
Class for arbitrary precision integers.
Definition: APInt.h:69
bool isCast() const
Return true if this is a convert constant expression.
Definition: Constants.cpp:1050
bool isSignedIntN(unsigned N) const
Check if this APInt has an N-bits signed integer value.
Definition: APInt.h:449
static SDValue PerformMULCombine(SDNode *N, TargetLowering::DAGCombinerInfo &DCI, CodeGenOpt::Level OptLevel)
PerformMULCombine - Runs PTX-specific DAG combine patterns on MUL nodes.
iterator_range< use_iterator > uses()
Select(COND, TRUEVAL, FALSEVAL).
Definition: ISDOpcodes.h:388
op_iterator op_begin() const
bool isIntegerTy() const
True if this is an instance of IntegerType.
Definition: Type.h:197
static use_iterator use_end()
ZERO_EXTEND - Used for integer types, zeroing the new bits.
Definition: ISDOpcodes.h:444
ANY_EXTEND - Used for integer types. The high bits are undefined.
Definition: ISDOpcodes.h:447
static cl::opt< bool > FtzEnabled("nvptx-f32ftz", cl::ZeroOrMore, cl::Hidden, cl::desc("NVPTX Specific: Flush f32 subnormals to sign-preserving zero."), cl::init(false))
FCOPYSIGN(X, Y) - Return the value of X with the sign of Y.
Definition: ISDOpcodes.h:286
FMINNAN/FMAXNAN - Behave identically to FMINNUM/FMAXNUM, except that when a single input is NaN...
Definition: ISDOpcodes.h:571
virtual TargetLoweringBase::LegalizeTypeAction getPreferredVectorAction(EVT VT) const
Return the preferred vector type legalization action.
void append(in_iter in_start, in_iter in_end)
Add the specified range to the end of the SmallVector.
Definition: SmallVector.h:395
llvm_unreachable("Unknown RegBank!")
unsigned getAddressSpace() const
Return the address space for the associated pointer.
BR_JT - Jumptable branch.
Definition: ISDOpcodes.h:604
static std::vector< std::string > Flags
Definition: FlagsTest.cpp:8
const DataLayout & getDataLayout() const
Get the data layout for the module's target platform.
Definition: Module.cpp:361
NVPTXTargetMachine.
SmallVector< SDValue, 32 > OutVals
MCSection * LSDASection
If exception handling is supported by the target, this is the section the Language Specific Data Area...
Bitwise operators - logical and, logical or, logical xor.
Definition: ISDOpcodes.h:361
bool hasFnAttribute(Attribute::AttrKind Kind) const
Return true if the function has the attribute.
Definition: Function.h:254
bool isAggregateType() const
Return true if the type is an aggregate type.
Definition: Type.h:255
virtual void LowerAsmOperandForConstraint(SDValue Op, std::string &Constraint, std::vector< SDValue > &Ops, SelectionDAG &DAG) const
Lower the specified operand into the Ops vector.
SMUL_LOHI/UMUL_LOHI - Multiply two integers of type iN, producing a signed/unsigned value of type i[2...
Definition: ISDOpcodes.h:205
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...
static SDValue PerformSETCCCombine(SDNode *N, TargetLowering::DAGCombinerInfo &DCI)
SIGN_EXTEND_INREG - This operator atomically performs a SHL/SRA pair to sign extend a small value in ...
Definition: ISDOpcodes.h:462
Represents a section in PTX PTX does not have sections.
Definition: NVPTXSection.h:25
LOAD and STORE have token chains as their first operand, then the same operands as an LLVM load/store...
Definition: ISDOpcodes.h:580
TargetOptions Options
Definition: TargetMachine.h:95
Establish a view to a call site for examination.
Definition: CallSite.h:687
unsigned getSizeInBits() const
Return the size of the specified value type in bits.
Definition: ValueTypes.h:292
#define I(x, y, z)
Definition: MD5.cpp:58
LLVM_ATTRIBUTE_ALWAYS_INLINE size_type size() const
Definition: SmallVector.h:135
constexpr char Align[]
Key for Kernel::Arg::Metadata::mAlign.
The memory access always returns the same value (or traps).
op_iterator op_end() const
const TargetMachine & getTarget() const
getTarget - Return the target machine this machine code is compiled with
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
unsigned MaxStoresPerMemcpy
Specify maximum bytes of store instructions per memcpy call.
static SmallVector< ParamVectorizationFlags, 16 > VectorizePTXValueVTs(const SmallVectorImpl< EVT > &ValueVTs, const SmallVectorImpl< uint64_t > &Offsets, unsigned ParamAlignment)
bool useF32FTZ(const MachineFunction &MF) const
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.
OperandSignedness
const unsigned Kind
CONCAT_VECTORS(VECTOR0, VECTOR1, ...) - Given a number of values of vector type with the same length ...
Definition: ISDOpcodes.h:319
StringRef getValueAsString() const
Return the attribute's value as a string.
Definition: Attributes.cpp:195
bool isFloatingPoint() const
Return true if this is a FP or a vector FP type.
Definition: ValueTypes.h:136
assert(ImpDefSCC.getReg()==AMDGPU::SCC &&ImpDefSCC.isDef())
LegalizeTypeAction
This enum indicates whether a types are legal for a target, and if not, what action should be used to...
bool allowsMemoryAccess(LLVMContext &Context, const DataLayout &DL, EVT VT, unsigned AddrSpace=0, unsigned Alignment=1, bool *Fast=nullptr) const
Return true if the target supports a memory access of this type for the given address space and align...
bool isSimple() const
Test if the given EVT is simple (as opposed to being extended).
Definition: ValueTypes.h:126
A raw_ostream that writes to an std::string.
Definition: raw_ostream.h:463
FunTy * getCalledFunction() const
Return the function being called if this is a direct call, otherwise return null (if it's an indirect...
Definition: CallSite.h:104
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.
unsigned getPrimitiveSizeInBits() const LLVM_READONLY
Return the basic size of this type if it is a primitive type.
Definition: Type.cpp:115
Module * getParent()
Get the module that this global value is contained inside of...
Definition: GlobalValue.h:545
LLVM Value Representation.
Definition: Value.h:73
FMA - Perform a * b + c with no intermediate rounding step.
Definition: ISDOpcodes.h:276
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
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 const Function * getParent(const Value *V)
const TargetLowering & getTargetLoweringInfo() const
Definition: SelectionDAG.h:379
Primary interface to the complete machine description for the target machine.
Definition: TargetMachine.h:56
MCSection * BSSSection
Section that is default initialized to zero.
StringRef - Represent a constant reference to a string, i.e.
Definition: StringRef.h:49
APInt zext(unsigned width) const
Zero extend to a new width.
Definition: APInt.cpp:865
SetCC operator - This evaluates to a true value iff the condition is true.
Definition: ISDOpcodes.h:411
MCSection * ReadOnlySection
Section that is readonly and can contain arbitrary initialized data.
unsigned MaxStoresPerMemset
Specify maximum number of store instructions per memset call.
bool allowFP16Math() const
MCSection * DwarfMacinfoSection
StringRef getName() const
getName - Return the name of the corresponding LLVM function.
Conversion operators.
Definition: ISDOpcodes.h:441
TRUNCATE - Completely drop the high bits.
Definition: ISDOpcodes.h:450
unsigned getAlignment() const
Unlike LLVM values, Selection DAG nodes may return multiple values as the result of a computation...
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
MVT getSimpleVT() const
Return the SimpleValueType held in the specified simple EVT.
Definition: ValueTypes.h:253
static unsigned getOpcForTextureInstr(unsigned Intrinsic)
bool isMachineOpcode() const
Test if this node has a post-isel opcode, directly corresponding to a MachineInstr opcode...
This file describes how to lower LLVM code to machine code.
unsigned getMachineOpcode() const
This may only be called if isMachineOpcode returns true.
SDValue getTargetGlobalAddress(const GlobalValue *GV, const SDLoc &DL, EVT VT, int64_t offset=0, unsigned char TargetFlags=0)
Definition: SelectionDAG.h:588
const NVPTXRegisterInfo * getRegisterInfo() const override
uint64_t getZExtValue() const
BRIND - Indirect branch.
Definition: ISDOpcodes.h:600
bool slt(const APInt &RHS) const
Signed less than comparison.
Definition: APInt.h:1183
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.
const NVPTXTargetMachine * nvTM