LLVM API Documentation

NVPTXISelLowering.cpp
Go to the documentation of this file.
00001 //
00002 //                     The LLVM Compiler Infrastructure
00003 //
00004 // This file is distributed under the University of Illinois Open Source
00005 // License. See LICENSE.TXT for details.
00006 //
00007 //===----------------------------------------------------------------------===//
00008 //
00009 // This file defines the interfaces that NVPTX uses to lower LLVM code into a
00010 // selection DAG.
00011 //
00012 //===----------------------------------------------------------------------===//
00013 
00014 #include "NVPTXISelLowering.h"
00015 #include "NVPTX.h"
00016 #include "NVPTXTargetMachine.h"
00017 #include "NVPTXTargetObjectFile.h"
00018 #include "NVPTXUtilities.h"
00019 #include "llvm/CodeGen/Analysis.h"
00020 #include "llvm/CodeGen/MachineFrameInfo.h"
00021 #include "llvm/CodeGen/MachineFunction.h"
00022 #include "llvm/CodeGen/MachineInstrBuilder.h"
00023 #include "llvm/CodeGen/MachineRegisterInfo.h"
00024 #include "llvm/CodeGen/TargetLoweringObjectFileImpl.h"
00025 #include "llvm/IR/CallSite.h"
00026 #include "llvm/IR/DerivedTypes.h"
00027 #include "llvm/IR/Function.h"
00028 #include "llvm/IR/GlobalValue.h"
00029 #include "llvm/IR/IntrinsicInst.h"
00030 #include "llvm/IR/Intrinsics.h"
00031 #include "llvm/IR/Module.h"
00032 #include "llvm/MC/MCSectionELF.h"
00033 #include "llvm/Support/CommandLine.h"
00034 #include "llvm/Support/Debug.h"
00035 #include "llvm/Support/ErrorHandling.h"
00036 #include "llvm/Support/MathExtras.h"
00037 #include "llvm/Support/raw_ostream.h"
00038 #include <sstream>
00039 
00040 #undef DEBUG_TYPE
00041 #define DEBUG_TYPE "nvptx-lower"
00042 
00043 using namespace llvm;
00044 
00045 static unsigned int uniqueCallSite = 0;
00046 
00047 static cl::opt<bool> sched4reg(
00048     "nvptx-sched4reg",
00049     cl::desc("NVPTX Specific: schedule for register pressue"), cl::init(false));
00050 
00051 static cl::opt<unsigned>
00052 FMAContractLevelOpt("nvptx-fma-level", cl::ZeroOrMore, cl::Hidden,
00053                     cl::desc("NVPTX Specific: FMA contraction (0: don't do it"
00054                              " 1: do it  2: do it aggressively"),
00055                     cl::init(2));
00056 
00057 static bool IsPTXVectorType(MVT VT) {
00058   switch (VT.SimpleTy) {
00059   default:
00060     return false;
00061   case MVT::v2i1:
00062   case MVT::v4i1:
00063   case MVT::v2i8:
00064   case MVT::v4i8:
00065   case MVT::v2i16:
00066   case MVT::v4i16:
00067   case MVT::v2i32:
00068   case MVT::v4i32:
00069   case MVT::v2i64:
00070   case MVT::v2f32:
00071   case MVT::v4f32:
00072   case MVT::v2f64:
00073     return true;
00074   }
00075 }
00076 
00077 /// ComputePTXValueVTs - For the given Type \p Ty, returns the set of primitive
00078 /// EVTs that compose it.  Unlike ComputeValueVTs, this will break apart vectors
00079 /// into their primitive components.
00080 /// NOTE: This is a band-aid for code that expects ComputeValueVTs to return the
00081 /// same number of types as the Ins/Outs arrays in LowerFormalArguments,
00082 /// LowerCall, and LowerReturn.
00083 static void ComputePTXValueVTs(const TargetLowering &TLI, Type *Ty,
00084                                SmallVectorImpl<EVT> &ValueVTs,
00085                                SmallVectorImpl<uint64_t> *Offsets = nullptr,
00086                                uint64_t StartingOffset = 0) {
00087   SmallVector<EVT, 16> TempVTs;
00088   SmallVector<uint64_t, 16> TempOffsets;
00089 
00090   ComputeValueVTs(TLI, Ty, TempVTs, &TempOffsets, StartingOffset);
00091   for (unsigned i = 0, e = TempVTs.size(); i != e; ++i) {
00092     EVT VT = TempVTs[i];
00093     uint64_t Off = TempOffsets[i];
00094     if (VT.isVector())
00095       for (unsigned j = 0, je = VT.getVectorNumElements(); j != je; ++j) {
00096         ValueVTs.push_back(VT.getVectorElementType());
00097         if (Offsets)
00098           Offsets->push_back(Off+j*VT.getVectorElementType().getStoreSize());
00099       }
00100     else {
00101       ValueVTs.push_back(VT);
00102       if (Offsets)
00103         Offsets->push_back(Off);
00104     }
00105   }
00106 }
00107 
00108 // NVPTXTargetLowering Constructor.
00109 NVPTXTargetLowering::NVPTXTargetLowering(const NVPTXTargetMachine &TM,
00110                                          const NVPTXSubtarget &STI)
00111     : TargetLowering(TM), nvTM(&TM), STI(STI) {
00112 
00113   // always lower memset, memcpy, and memmove intrinsics to load/store
00114   // instructions, rather
00115   // then generating calls to memset, mempcy or memmove.
00116   MaxStoresPerMemset = (unsigned) 0xFFFFFFFF;
00117   MaxStoresPerMemcpy = (unsigned) 0xFFFFFFFF;
00118   MaxStoresPerMemmove = (unsigned) 0xFFFFFFFF;
00119 
00120   setBooleanContents(ZeroOrNegativeOneBooleanContent);
00121   setBooleanVectorContents(ZeroOrNegativeOneBooleanContent);
00122 
00123   // Jump is Expensive. Don't create extra control flow for 'and', 'or'
00124   // condition branches.
00125   setJumpIsExpensive(true);
00126 
00127   // By default, use the Source scheduling
00128   if (sched4reg)
00129     setSchedulingPreference(Sched::RegPressure);
00130   else
00131     setSchedulingPreference(Sched::Source);
00132 
00133   addRegisterClass(MVT::i1, &NVPTX::Int1RegsRegClass);
00134   addRegisterClass(MVT::i16, &NVPTX::Int16RegsRegClass);
00135   addRegisterClass(MVT::i32, &NVPTX::Int32RegsRegClass);
00136   addRegisterClass(MVT::i64, &NVPTX::Int64RegsRegClass);
00137   addRegisterClass(MVT::f32, &NVPTX::Float32RegsRegClass);
00138   addRegisterClass(MVT::f64, &NVPTX::Float64RegsRegClass);
00139 
00140   // Operations not directly supported by NVPTX.
00141   setOperationAction(ISD::SELECT_CC, MVT::f32, Expand);
00142   setOperationAction(ISD::SELECT_CC, MVT::f64, Expand);
00143   setOperationAction(ISD::SELECT_CC, MVT::i1, Expand);
00144   setOperationAction(ISD::SELECT_CC, MVT::i8, Expand);
00145   setOperationAction(ISD::SELECT_CC, MVT::i16, Expand);
00146   setOperationAction(ISD::SELECT_CC, MVT::i32, Expand);
00147   setOperationAction(ISD::SELECT_CC, MVT::i64, Expand);
00148   setOperationAction(ISD::BR_CC, MVT::f32, Expand);
00149   setOperationAction(ISD::BR_CC, MVT::f64, Expand);
00150   setOperationAction(ISD::BR_CC, MVT::i1, Expand);
00151   setOperationAction(ISD::BR_CC, MVT::i8, Expand);
00152   setOperationAction(ISD::BR_CC, MVT::i16, Expand);
00153   setOperationAction(ISD::BR_CC, MVT::i32, Expand);
00154   setOperationAction(ISD::BR_CC, MVT::i64, Expand);
00155   // Some SIGN_EXTEND_INREG can be done using cvt instruction.
00156   // For others we will expand to a SHL/SRA pair.
00157   setOperationAction(ISD::SIGN_EXTEND_INREG, MVT::i64, Legal);
00158   setOperationAction(ISD::SIGN_EXTEND_INREG, MVT::i32, Legal);
00159   setOperationAction(ISD::SIGN_EXTEND_INREG, MVT::i16, Legal);
00160   setOperationAction(ISD::SIGN_EXTEND_INREG, MVT::i8 , Legal);
00161   setOperationAction(ISD::SIGN_EXTEND_INREG, MVT::i1, Expand);
00162 
00163   setOperationAction(ISD::SHL_PARTS, MVT::i32  , Custom);
00164   setOperationAction(ISD::SRA_PARTS, MVT::i32  , Custom);
00165   setOperationAction(ISD::SRL_PARTS, MVT::i32  , Custom);
00166   setOperationAction(ISD::SHL_PARTS, MVT::i64  , Custom);
00167   setOperationAction(ISD::SRA_PARTS, MVT::i64  , Custom);
00168   setOperationAction(ISD::SRL_PARTS, MVT::i64  , Custom);
00169 
00170   if (STI.hasROT64()) {
00171     setOperationAction(ISD::ROTL, MVT::i64, Legal);
00172     setOperationAction(ISD::ROTR, MVT::i64, Legal);
00173   } else {
00174     setOperationAction(ISD::ROTL, MVT::i64, Expand);
00175     setOperationAction(ISD::ROTR, MVT::i64, Expand);
00176   }
00177   if (STI.hasROT32()) {
00178     setOperationAction(ISD::ROTL, MVT::i32, Legal);
00179     setOperationAction(ISD::ROTR, MVT::i32, Legal);
00180   } else {
00181     setOperationAction(ISD::ROTL, MVT::i32, Expand);
00182     setOperationAction(ISD::ROTR, MVT::i32, Expand);
00183   }
00184 
00185   setOperationAction(ISD::ROTL, MVT::i16, Expand);
00186   setOperationAction(ISD::ROTR, MVT::i16, Expand);
00187   setOperationAction(ISD::ROTL, MVT::i8, Expand);
00188   setOperationAction(ISD::ROTR, MVT::i8, Expand);
00189   setOperationAction(ISD::BSWAP, MVT::i16, Expand);
00190   setOperationAction(ISD::BSWAP, MVT::i32, Expand);
00191   setOperationAction(ISD::BSWAP, MVT::i64, Expand);
00192 
00193   // Indirect branch is not supported.
00194   // This also disables Jump Table creation.
00195   setOperationAction(ISD::BR_JT, MVT::Other, Expand);
00196   setOperationAction(ISD::BRIND, MVT::Other, Expand);
00197 
00198   setOperationAction(ISD::GlobalAddress, MVT::i32, Custom);
00199   setOperationAction(ISD::GlobalAddress, MVT::i64, Custom);
00200 
00201   // We want to legalize constant related memmove and memcopy
00202   // intrinsics.
00203   setOperationAction(ISD::INTRINSIC_W_CHAIN, MVT::Other, Custom);
00204 
00205   // Turn FP extload into load/fextend
00206   setLoadExtAction(ISD::EXTLOAD, MVT::f32, MVT::f16, Expand);
00207   setLoadExtAction(ISD::EXTLOAD, MVT::f64, MVT::f16, Expand);
00208   setLoadExtAction(ISD::EXTLOAD, MVT::f64, MVT::f32, Expand);
00209   // Turn FP truncstore into trunc + store.
00210   setTruncStoreAction(MVT::f32, MVT::f16, Expand);
00211   setTruncStoreAction(MVT::f64, MVT::f16, Expand);
00212   setTruncStoreAction(MVT::f64, MVT::f32, Expand);
00213 
00214   // PTX does not support load / store predicate registers
00215   setOperationAction(ISD::LOAD, MVT::i1, Custom);
00216   setOperationAction(ISD::STORE, MVT::i1, Custom);
00217 
00218   for (MVT VT : MVT::integer_valuetypes()) {
00219     setLoadExtAction(ISD::SEXTLOAD, VT, MVT::i1, Promote);
00220     setLoadExtAction(ISD::ZEXTLOAD, VT, MVT::i1, Promote);
00221     setTruncStoreAction(VT, MVT::i1, Expand);
00222   }
00223 
00224   // This is legal in NVPTX
00225   setOperationAction(ISD::ConstantFP, MVT::f64, Legal);
00226   setOperationAction(ISD::ConstantFP, MVT::f32, Legal);
00227 
00228   // TRAP can be lowered to PTX trap
00229   setOperationAction(ISD::TRAP, MVT::Other, Legal);
00230 
00231   setOperationAction(ISD::ADDC, MVT::i64, Expand);
00232   setOperationAction(ISD::ADDE, MVT::i64, Expand);
00233 
00234   // Register custom handling for vector loads/stores
00235   for (MVT VT : MVT::vector_valuetypes()) {
00236     if (IsPTXVectorType(VT)) {
00237       setOperationAction(ISD::LOAD, VT, Custom);
00238       setOperationAction(ISD::STORE, VT, Custom);
00239       setOperationAction(ISD::INTRINSIC_W_CHAIN, VT, Custom);
00240     }
00241   }
00242 
00243   // Custom handling for i8 intrinsics
00244   setOperationAction(ISD::INTRINSIC_W_CHAIN, MVT::i8, Custom);
00245 
00246   setOperationAction(ISD::CTLZ, MVT::i16, Legal);
00247   setOperationAction(ISD::CTLZ, MVT::i32, Legal);
00248   setOperationAction(ISD::CTLZ, MVT::i64, Legal);
00249   setOperationAction(ISD::CTLZ_ZERO_UNDEF, MVT::i16, Legal);
00250   setOperationAction(ISD::CTLZ_ZERO_UNDEF, MVT::i32, Legal);
00251   setOperationAction(ISD::CTLZ_ZERO_UNDEF, MVT::i64, Legal);
00252   setOperationAction(ISD::CTTZ, MVT::i16, Expand);
00253   setOperationAction(ISD::CTTZ, MVT::i32, Expand);
00254   setOperationAction(ISD::CTTZ, MVT::i64, Expand);
00255   setOperationAction(ISD::CTTZ_ZERO_UNDEF, MVT::i16, Expand);
00256   setOperationAction(ISD::CTTZ_ZERO_UNDEF, MVT::i32, Expand);
00257   setOperationAction(ISD::CTTZ_ZERO_UNDEF, MVT::i64, Expand);
00258   setOperationAction(ISD::CTPOP, MVT::i16, Legal);
00259   setOperationAction(ISD::CTPOP, MVT::i32, Legal);
00260   setOperationAction(ISD::CTPOP, MVT::i64, Legal);
00261 
00262   // PTX does not directly support SELP of i1, so promote to i32 first
00263   setOperationAction(ISD::SELECT, MVT::i1, Custom);
00264 
00265   // We have some custom DAG combine patterns for these nodes
00266   setTargetDAGCombine(ISD::ADD);
00267   setTargetDAGCombine(ISD::AND);
00268   setTargetDAGCombine(ISD::FADD);
00269   setTargetDAGCombine(ISD::MUL);
00270   setTargetDAGCombine(ISD::SHL);
00271 
00272   // Now deduce the information based on the above mentioned
00273   // actions
00274   computeRegisterProperties(STI.getRegisterInfo());
00275 }
00276 
00277 const char *NVPTXTargetLowering::getTargetNodeName(unsigned Opcode) const {
00278   switch (Opcode) {
00279   default:
00280     return nullptr;
00281   case NVPTXISD::CALL:
00282     return "NVPTXISD::CALL";
00283   case NVPTXISD::RET_FLAG:
00284     return "NVPTXISD::RET_FLAG";
00285   case NVPTXISD::Wrapper:
00286     return "NVPTXISD::Wrapper";
00287   case NVPTXISD::DeclareParam:
00288     return "NVPTXISD::DeclareParam";
00289   case NVPTXISD::DeclareScalarParam:
00290     return "NVPTXISD::DeclareScalarParam";
00291   case NVPTXISD::DeclareRet:
00292     return "NVPTXISD::DeclareRet";
00293   case NVPTXISD::DeclareRetParam:
00294     return "NVPTXISD::DeclareRetParam";
00295   case NVPTXISD::PrintCall:
00296     return "NVPTXISD::PrintCall";
00297   case NVPTXISD::LoadParam:
00298     return "NVPTXISD::LoadParam";
00299   case NVPTXISD::LoadParamV2:
00300     return "NVPTXISD::LoadParamV2";
00301   case NVPTXISD::LoadParamV4:
00302     return "NVPTXISD::LoadParamV4";
00303   case NVPTXISD::StoreParam:
00304     return "NVPTXISD::StoreParam";
00305   case NVPTXISD::StoreParamV2:
00306     return "NVPTXISD::StoreParamV2";
00307   case NVPTXISD::StoreParamV4:
00308     return "NVPTXISD::StoreParamV4";
00309   case NVPTXISD::StoreParamS32:
00310     return "NVPTXISD::StoreParamS32";
00311   case NVPTXISD::StoreParamU32:
00312     return "NVPTXISD::StoreParamU32";
00313   case NVPTXISD::CallArgBegin:
00314     return "NVPTXISD::CallArgBegin";
00315   case NVPTXISD::CallArg:
00316     return "NVPTXISD::CallArg";
00317   case NVPTXISD::LastCallArg:
00318     return "NVPTXISD::LastCallArg";
00319   case NVPTXISD::CallArgEnd:
00320     return "NVPTXISD::CallArgEnd";
00321   case NVPTXISD::CallVoid:
00322     return "NVPTXISD::CallVoid";
00323   case NVPTXISD::CallVal:
00324     return "NVPTXISD::CallVal";
00325   case NVPTXISD::CallSymbol:
00326     return "NVPTXISD::CallSymbol";
00327   case NVPTXISD::Prototype:
00328     return "NVPTXISD::Prototype";
00329   case NVPTXISD::MoveParam:
00330     return "NVPTXISD::MoveParam";
00331   case NVPTXISD::StoreRetval:
00332     return "NVPTXISD::StoreRetval";
00333   case NVPTXISD::StoreRetvalV2:
00334     return "NVPTXISD::StoreRetvalV2";
00335   case NVPTXISD::StoreRetvalV4:
00336     return "NVPTXISD::StoreRetvalV4";
00337   case NVPTXISD::PseudoUseParam:
00338     return "NVPTXISD::PseudoUseParam";
00339   case NVPTXISD::RETURN:
00340     return "NVPTXISD::RETURN";
00341   case NVPTXISD::CallSeqBegin:
00342     return "NVPTXISD::CallSeqBegin";
00343   case NVPTXISD::CallSeqEnd:
00344     return "NVPTXISD::CallSeqEnd";
00345   case NVPTXISD::CallPrototype:
00346     return "NVPTXISD::CallPrototype";
00347   case NVPTXISD::LoadV2:
00348     return "NVPTXISD::LoadV2";
00349   case NVPTXISD::LoadV4:
00350     return "NVPTXISD::LoadV4";
00351   case NVPTXISD::LDGV2:
00352     return "NVPTXISD::LDGV2";
00353   case NVPTXISD::LDGV4:
00354     return "NVPTXISD::LDGV4";
00355   case NVPTXISD::LDUV2:
00356     return "NVPTXISD::LDUV2";
00357   case NVPTXISD::LDUV4:
00358     return "NVPTXISD::LDUV4";
00359   case NVPTXISD::StoreV2:
00360     return "NVPTXISD::StoreV2";
00361   case NVPTXISD::StoreV4:
00362     return "NVPTXISD::StoreV4";
00363   case NVPTXISD::FUN_SHFL_CLAMP:
00364     return "NVPTXISD::FUN_SHFL_CLAMP";
00365   case NVPTXISD::FUN_SHFR_CLAMP:
00366     return "NVPTXISD::FUN_SHFR_CLAMP";
00367   case NVPTXISD::IMAD:
00368     return "NVPTXISD::IMAD";
00369   case NVPTXISD::MUL_WIDE_SIGNED:
00370     return "NVPTXISD::MUL_WIDE_SIGNED";
00371   case NVPTXISD::MUL_WIDE_UNSIGNED:
00372     return "NVPTXISD::MUL_WIDE_UNSIGNED";
00373   case NVPTXISD::Tex1DFloatS32:        return "NVPTXISD::Tex1DFloatS32";
00374   case NVPTXISD::Tex1DFloatFloat:      return "NVPTXISD::Tex1DFloatFloat";
00375   case NVPTXISD::Tex1DFloatFloatLevel:
00376     return "NVPTXISD::Tex1DFloatFloatLevel";
00377   case NVPTXISD::Tex1DFloatFloatGrad:
00378     return "NVPTXISD::Tex1DFloatFloatGrad";
00379   case NVPTXISD::Tex1DS32S32:          return "NVPTXISD::Tex1DS32S32";
00380   case NVPTXISD::Tex1DS32Float:        return "NVPTXISD::Tex1DS32Float";
00381   case NVPTXISD::Tex1DS32FloatLevel:
00382     return "NVPTXISD::Tex1DS32FloatLevel";
00383   case NVPTXISD::Tex1DS32FloatGrad:
00384     return "NVPTXISD::Tex1DS32FloatGrad";
00385   case NVPTXISD::Tex1DU32S32:          return "NVPTXISD::Tex1DU32S32";
00386   case NVPTXISD::Tex1DU32Float:        return "NVPTXISD::Tex1DU32Float";
00387   case NVPTXISD::Tex1DU32FloatLevel:
00388     return "NVPTXISD::Tex1DU32FloatLevel";
00389   case NVPTXISD::Tex1DU32FloatGrad:
00390     return "NVPTXISD::Tex1DU32FloatGrad";
00391   case NVPTXISD::Tex1DArrayFloatS32:   return "NVPTXISD::Tex1DArrayFloatS32";
00392   case NVPTXISD::Tex1DArrayFloatFloat: return "NVPTXISD::Tex1DArrayFloatFloat";
00393   case NVPTXISD::Tex1DArrayFloatFloatLevel:
00394     return "NVPTXISD::Tex1DArrayFloatFloatLevel";
00395   case NVPTXISD::Tex1DArrayFloatFloatGrad:
00396     return "NVPTXISD::Tex1DArrayFloatFloatGrad";
00397   case NVPTXISD::Tex1DArrayS32S32:     return "NVPTXISD::Tex1DArrayS32S32";
00398   case NVPTXISD::Tex1DArrayS32Float:   return "NVPTXISD::Tex1DArrayS32Float";
00399   case NVPTXISD::Tex1DArrayS32FloatLevel:
00400     return "NVPTXISD::Tex1DArrayS32FloatLevel";
00401   case NVPTXISD::Tex1DArrayS32FloatGrad:
00402     return "NVPTXISD::Tex1DArrayS32FloatGrad";
00403   case NVPTXISD::Tex1DArrayU32S32:     return "NVPTXISD::Tex1DArrayU32S32";
00404   case NVPTXISD::Tex1DArrayU32Float:   return "NVPTXISD::Tex1DArrayU32Float";
00405   case NVPTXISD::Tex1DArrayU32FloatLevel:
00406     return "NVPTXISD::Tex1DArrayU32FloatLevel";
00407   case NVPTXISD::Tex1DArrayU32FloatGrad:
00408     return "NVPTXISD::Tex1DArrayU32FloatGrad";
00409   case NVPTXISD::Tex2DFloatS32:        return "NVPTXISD::Tex2DFloatS32";
00410   case NVPTXISD::Tex2DFloatFloat:      return "NVPTXISD::Tex2DFloatFloat";
00411   case NVPTXISD::Tex2DFloatFloatLevel:
00412     return "NVPTXISD::Tex2DFloatFloatLevel";
00413   case NVPTXISD::Tex2DFloatFloatGrad:
00414     return "NVPTXISD::Tex2DFloatFloatGrad";
00415   case NVPTXISD::Tex2DS32S32:          return "NVPTXISD::Tex2DS32S32";
00416   case NVPTXISD::Tex2DS32Float:        return "NVPTXISD::Tex2DS32Float";
00417   case NVPTXISD::Tex2DS32FloatLevel:
00418     return "NVPTXISD::Tex2DS32FloatLevel";
00419   case NVPTXISD::Tex2DS32FloatGrad:
00420     return "NVPTXISD::Tex2DS32FloatGrad";
00421   case NVPTXISD::Tex2DU32S32:          return "NVPTXISD::Tex2DU32S32";
00422   case NVPTXISD::Tex2DU32Float:        return "NVPTXISD::Tex2DU32Float";
00423   case NVPTXISD::Tex2DU32FloatLevel:
00424     return "NVPTXISD::Tex2DU32FloatLevel";
00425   case NVPTXISD::Tex2DU32FloatGrad:
00426     return "NVPTXISD::Tex2DU32FloatGrad";
00427   case NVPTXISD::Tex2DArrayFloatS32:   return "NVPTXISD::Tex2DArrayFloatS32";
00428   case NVPTXISD::Tex2DArrayFloatFloat: return "NVPTXISD::Tex2DArrayFloatFloat";
00429   case NVPTXISD::Tex2DArrayFloatFloatLevel:
00430     return "NVPTXISD::Tex2DArrayFloatFloatLevel";
00431   case NVPTXISD::Tex2DArrayFloatFloatGrad:
00432     return "NVPTXISD::Tex2DArrayFloatFloatGrad";
00433   case NVPTXISD::Tex2DArrayS32S32:     return "NVPTXISD::Tex2DArrayS32S32";
00434   case NVPTXISD::Tex2DArrayS32Float:   return "NVPTXISD::Tex2DArrayS32Float";
00435   case NVPTXISD::Tex2DArrayS32FloatLevel:
00436     return "NVPTXISD::Tex2DArrayS32FloatLevel";
00437   case NVPTXISD::Tex2DArrayS32FloatGrad:
00438     return "NVPTXISD::Tex2DArrayS32FloatGrad";
00439   case NVPTXISD::Tex2DArrayU32S32:     return "NVPTXISD::Tex2DArrayU32S32";
00440   case NVPTXISD::Tex2DArrayU32Float:   return "NVPTXISD::Tex2DArrayU32Float";
00441   case NVPTXISD::Tex2DArrayU32FloatLevel:
00442     return "NVPTXISD::Tex2DArrayU32FloatLevel";
00443   case NVPTXISD::Tex2DArrayU32FloatGrad:
00444     return "NVPTXISD::Tex2DArrayU32FloatGrad";
00445   case NVPTXISD::Tex3DFloatS32:        return "NVPTXISD::Tex3DFloatS32";
00446   case NVPTXISD::Tex3DFloatFloat:      return "NVPTXISD::Tex3DFloatFloat";
00447   case NVPTXISD::Tex3DFloatFloatLevel:
00448     return "NVPTXISD::Tex3DFloatFloatLevel";
00449   case NVPTXISD::Tex3DFloatFloatGrad:
00450     return "NVPTXISD::Tex3DFloatFloatGrad";
00451   case NVPTXISD::Tex3DS32S32:          return "NVPTXISD::Tex3DS32S32";
00452   case NVPTXISD::Tex3DS32Float:        return "NVPTXISD::Tex3DS32Float";
00453   case NVPTXISD::Tex3DS32FloatLevel:
00454     return "NVPTXISD::Tex3DS32FloatLevel";
00455   case NVPTXISD::Tex3DS32FloatGrad:
00456     return "NVPTXISD::Tex3DS32FloatGrad";
00457   case NVPTXISD::Tex3DU32S32:          return "NVPTXISD::Tex3DU32S32";
00458   case NVPTXISD::Tex3DU32Float:        return "NVPTXISD::Tex3DU32Float";
00459   case NVPTXISD::Tex3DU32FloatLevel:
00460     return "NVPTXISD::Tex3DU32FloatLevel";
00461   case NVPTXISD::Tex3DU32FloatGrad:
00462     return "NVPTXISD::Tex3DU32FloatGrad";
00463   case NVPTXISD::TexCubeFloatFloat:      return "NVPTXISD::TexCubeFloatFloat";
00464   case NVPTXISD::TexCubeFloatFloatLevel:
00465     return "NVPTXISD::TexCubeFloatFloatLevel";
00466   case NVPTXISD::TexCubeS32Float:        return "NVPTXISD::TexCubeS32Float";
00467   case NVPTXISD::TexCubeS32FloatLevel:
00468     return "NVPTXISD::TexCubeS32FloatLevel";
00469   case NVPTXISD::TexCubeU32Float:        return "NVPTXISD::TexCubeU32Float";
00470   case NVPTXISD::TexCubeU32FloatLevel:
00471     return "NVPTXISD::TexCubeU32FloatLevel";
00472   case NVPTXISD::TexCubeArrayFloatFloat:
00473     return "NVPTXISD::TexCubeArrayFloatFloat";
00474   case NVPTXISD::TexCubeArrayFloatFloatLevel:
00475     return "NVPTXISD::TexCubeArrayFloatFloatLevel";
00476   case NVPTXISD::TexCubeArrayS32Float:
00477     return "NVPTXISD::TexCubeArrayS32Float";
00478   case NVPTXISD::TexCubeArrayS32FloatLevel:
00479     return "NVPTXISD::TexCubeArrayS32FloatLevel";
00480   case NVPTXISD::TexCubeArrayU32Float:
00481     return "NVPTXISD::TexCubeArrayU32Float";
00482   case NVPTXISD::TexCubeArrayU32FloatLevel:
00483     return "NVPTXISD::TexCubeArrayU32FloatLevel";
00484   case NVPTXISD::Tld4R2DFloatFloat:
00485     return "NVPTXISD::Tld4R2DFloatFloat";
00486   case NVPTXISD::Tld4G2DFloatFloat:
00487     return "NVPTXISD::Tld4G2DFloatFloat";
00488   case NVPTXISD::Tld4B2DFloatFloat:
00489     return "NVPTXISD::Tld4B2DFloatFloat";
00490   case NVPTXISD::Tld4A2DFloatFloat:
00491     return "NVPTXISD::Tld4A2DFloatFloat";
00492   case NVPTXISD::Tld4R2DS64Float:
00493     return "NVPTXISD::Tld4R2DS64Float";
00494   case NVPTXISD::Tld4G2DS64Float:
00495     return "NVPTXISD::Tld4G2DS64Float";
00496   case NVPTXISD::Tld4B2DS64Float:
00497     return "NVPTXISD::Tld4B2DS64Float";
00498   case NVPTXISD::Tld4A2DS64Float:
00499     return "NVPTXISD::Tld4A2DS64Float";
00500   case NVPTXISD::Tld4R2DU64Float:
00501     return "NVPTXISD::Tld4R2DU64Float";
00502   case NVPTXISD::Tld4G2DU64Float:
00503     return "NVPTXISD::Tld4G2DU64Float";
00504   case NVPTXISD::Tld4B2DU64Float:
00505     return "NVPTXISD::Tld4B2DU64Float";
00506   case NVPTXISD::Tld4A2DU64Float:
00507     return "NVPTXISD::Tld4A2DU64Float";
00508 
00509   case NVPTXISD::TexUnified1DFloatS32:
00510     return "NVPTXISD::TexUnified1DFloatS32";
00511   case NVPTXISD::TexUnified1DFloatFloat:
00512     return "NVPTXISD::TexUnified1DFloatFloat";
00513   case NVPTXISD::TexUnified1DFloatFloatLevel:
00514     return "NVPTXISD::TexUnified1DFloatFloatLevel";
00515   case NVPTXISD::TexUnified1DFloatFloatGrad:
00516     return "NVPTXISD::TexUnified1DFloatFloatGrad";
00517   case NVPTXISD::TexUnified1DS32S32:
00518     return "NVPTXISD::TexUnified1DS32S32";
00519   case NVPTXISD::TexUnified1DS32Float:
00520     return "NVPTXISD::TexUnified1DS32Float";
00521   case NVPTXISD::TexUnified1DS32FloatLevel:
00522     return "NVPTXISD::TexUnified1DS32FloatLevel";
00523   case NVPTXISD::TexUnified1DS32FloatGrad:
00524     return "NVPTXISD::TexUnified1DS32FloatGrad";
00525   case NVPTXISD::TexUnified1DU32S32:
00526     return "NVPTXISD::TexUnified1DU32S32";
00527   case NVPTXISD::TexUnified1DU32Float:
00528     return "NVPTXISD::TexUnified1DU32Float";
00529   case NVPTXISD::TexUnified1DU32FloatLevel:
00530     return "NVPTXISD::TexUnified1DU32FloatLevel";
00531   case NVPTXISD::TexUnified1DU32FloatGrad:
00532     return "NVPTXISD::TexUnified1DU32FloatGrad";
00533   case NVPTXISD::TexUnified1DArrayFloatS32:
00534     return "NVPTXISD::TexUnified1DArrayFloatS32";
00535   case NVPTXISD::TexUnified1DArrayFloatFloat:
00536     return "NVPTXISD::TexUnified1DArrayFloatFloat";
00537   case NVPTXISD::TexUnified1DArrayFloatFloatLevel:
00538     return "NVPTXISD::TexUnified1DArrayFloatFloatLevel";
00539   case NVPTXISD::TexUnified1DArrayFloatFloatGrad:
00540     return "NVPTXISD::TexUnified1DArrayFloatFloatGrad";
00541   case NVPTXISD::TexUnified1DArrayS32S32:
00542     return "NVPTXISD::TexUnified1DArrayS32S32";
00543   case NVPTXISD::TexUnified1DArrayS32Float:
00544     return "NVPTXISD::TexUnified1DArrayS32Float";
00545   case NVPTXISD::TexUnified1DArrayS32FloatLevel:
00546     return "NVPTXISD::TexUnified1DArrayS32FloatLevel";
00547   case NVPTXISD::TexUnified1DArrayS32FloatGrad:
00548     return "NVPTXISD::TexUnified1DArrayS32FloatGrad";
00549   case NVPTXISD::TexUnified1DArrayU32S32:
00550     return "NVPTXISD::TexUnified1DArrayU32S32";
00551   case NVPTXISD::TexUnified1DArrayU32Float:
00552     return "NVPTXISD::TexUnified1DArrayU32Float";
00553   case NVPTXISD::TexUnified1DArrayU32FloatLevel:
00554     return "NVPTXISD::TexUnified1DArrayU32FloatLevel";
00555   case NVPTXISD::TexUnified1DArrayU32FloatGrad:
00556     return "NVPTXISD::TexUnified1DArrayU32FloatGrad";
00557   case NVPTXISD::TexUnified2DFloatS32:
00558     return "NVPTXISD::TexUnified2DFloatS32";
00559   case NVPTXISD::TexUnified2DFloatFloat:
00560     return "NVPTXISD::TexUnified2DFloatFloat";
00561   case NVPTXISD::TexUnified2DFloatFloatLevel:
00562     return "NVPTXISD::TexUnified2DFloatFloatLevel";
00563   case NVPTXISD::TexUnified2DFloatFloatGrad:
00564     return "NVPTXISD::TexUnified2DFloatFloatGrad";
00565   case NVPTXISD::TexUnified2DS32S32:
00566     return "NVPTXISD::TexUnified2DS32S32";
00567   case NVPTXISD::TexUnified2DS32Float:
00568     return "NVPTXISD::TexUnified2DS32Float";
00569   case NVPTXISD::TexUnified2DS32FloatLevel:
00570     return "NVPTXISD::TexUnified2DS32FloatLevel";
00571   case NVPTXISD::TexUnified2DS32FloatGrad:
00572     return "NVPTXISD::TexUnified2DS32FloatGrad";
00573   case NVPTXISD::TexUnified2DU32S32:
00574     return "NVPTXISD::TexUnified2DU32S32";
00575   case NVPTXISD::TexUnified2DU32Float:
00576     return "NVPTXISD::TexUnified2DU32Float";
00577   case NVPTXISD::TexUnified2DU32FloatLevel:
00578     return "NVPTXISD::TexUnified2DU32FloatLevel";
00579   case NVPTXISD::TexUnified2DU32FloatGrad:
00580     return "NVPTXISD::TexUnified2DU32FloatGrad";
00581   case NVPTXISD::TexUnified2DArrayFloatS32:
00582     return "NVPTXISD::TexUnified2DArrayFloatS32";
00583   case NVPTXISD::TexUnified2DArrayFloatFloat:
00584     return "NVPTXISD::TexUnified2DArrayFloatFloat";
00585   case NVPTXISD::TexUnified2DArrayFloatFloatLevel:
00586     return "NVPTXISD::TexUnified2DArrayFloatFloatLevel";
00587   case NVPTXISD::TexUnified2DArrayFloatFloatGrad:
00588     return "NVPTXISD::TexUnified2DArrayFloatFloatGrad";
00589   case NVPTXISD::TexUnified2DArrayS32S32:
00590     return "NVPTXISD::TexUnified2DArrayS32S32";
00591   case NVPTXISD::TexUnified2DArrayS32Float:
00592     return "NVPTXISD::TexUnified2DArrayS32Float";
00593   case NVPTXISD::TexUnified2DArrayS32FloatLevel:
00594     return "NVPTXISD::TexUnified2DArrayS32FloatLevel";
00595   case NVPTXISD::TexUnified2DArrayS32FloatGrad:
00596     return "NVPTXISD::TexUnified2DArrayS32FloatGrad";
00597   case NVPTXISD::TexUnified2DArrayU32S32:
00598     return "NVPTXISD::TexUnified2DArrayU32S32";
00599   case NVPTXISD::TexUnified2DArrayU32Float:
00600     return "NVPTXISD::TexUnified2DArrayU32Float";
00601   case NVPTXISD::TexUnified2DArrayU32FloatLevel:
00602     return "NVPTXISD::TexUnified2DArrayU32FloatLevel";
00603   case NVPTXISD::TexUnified2DArrayU32FloatGrad:
00604     return "NVPTXISD::TexUnified2DArrayU32FloatGrad";
00605   case NVPTXISD::TexUnified3DFloatS32:
00606     return "NVPTXISD::TexUnified3DFloatS32";
00607   case NVPTXISD::TexUnified3DFloatFloat:
00608     return "NVPTXISD::TexUnified3DFloatFloat";
00609   case NVPTXISD::TexUnified3DFloatFloatLevel:
00610     return "NVPTXISD::TexUnified3DFloatFloatLevel";
00611   case NVPTXISD::TexUnified3DFloatFloatGrad:
00612     return "NVPTXISD::TexUnified3DFloatFloatGrad";
00613   case NVPTXISD::TexUnified3DS32S32:
00614     return "NVPTXISD::TexUnified3DS32S32";
00615   case NVPTXISD::TexUnified3DS32Float:
00616     return "NVPTXISD::TexUnified3DS32Float";
00617   case NVPTXISD::TexUnified3DS32FloatLevel:
00618     return "NVPTXISD::TexUnified3DS32FloatLevel";
00619   case NVPTXISD::TexUnified3DS32FloatGrad:
00620     return "NVPTXISD::TexUnified3DS32FloatGrad";
00621   case NVPTXISD::TexUnified3DU32S32:
00622     return "NVPTXISD::TexUnified3DU32S32";
00623   case NVPTXISD::TexUnified3DU32Float:
00624     return "NVPTXISD::TexUnified3DU32Float";
00625   case NVPTXISD::TexUnified3DU32FloatLevel:
00626     return "NVPTXISD::TexUnified3DU32FloatLevel";
00627   case NVPTXISD::TexUnified3DU32FloatGrad:
00628     return "NVPTXISD::TexUnified3DU32FloatGrad";
00629   case NVPTXISD::TexUnifiedCubeFloatFloat:
00630     return "NVPTXISD::TexUnifiedCubeFloatFloat";
00631   case NVPTXISD::TexUnifiedCubeFloatFloatLevel:
00632     return "NVPTXISD::TexUnifiedCubeFloatFloatLevel";
00633   case NVPTXISD::TexUnifiedCubeS32Float:
00634     return "NVPTXISD::TexUnifiedCubeS32Float";
00635   case NVPTXISD::TexUnifiedCubeS32FloatLevel:
00636     return "NVPTXISD::TexUnifiedCubeS32FloatLevel";
00637   case NVPTXISD::TexUnifiedCubeU32Float:
00638     return "NVPTXISD::TexUnifiedCubeU32Float";
00639   case NVPTXISD::TexUnifiedCubeU32FloatLevel:
00640     return "NVPTXISD::TexUnifiedCubeU32FloatLevel";
00641   case NVPTXISD::TexUnifiedCubeArrayFloatFloat:
00642     return "NVPTXISD::TexUnifiedCubeArrayFloatFloat";
00643   case NVPTXISD::TexUnifiedCubeArrayFloatFloatLevel:
00644     return "NVPTXISD::TexUnifiedCubeArrayFloatFloatLevel";
00645   case NVPTXISD::TexUnifiedCubeArrayS32Float:
00646     return "NVPTXISD::TexUnifiedCubeArrayS32Float";
00647   case NVPTXISD::TexUnifiedCubeArrayS32FloatLevel:
00648     return "NVPTXISD::TexUnifiedCubeArrayS32FloatLevel";
00649   case NVPTXISD::TexUnifiedCubeArrayU32Float:
00650     return "NVPTXISD::TexUnifiedCubeArrayU32Float";
00651   case NVPTXISD::TexUnifiedCubeArrayU32FloatLevel:
00652     return "NVPTXISD::TexUnifiedCubeArrayU32FloatLevel";
00653   case NVPTXISD::Tld4UnifiedR2DFloatFloat:
00654     return "NVPTXISD::Tld4UnifiedR2DFloatFloat";
00655   case NVPTXISD::Tld4UnifiedG2DFloatFloat:
00656     return "NVPTXISD::Tld4UnifiedG2DFloatFloat";
00657   case NVPTXISD::Tld4UnifiedB2DFloatFloat:
00658     return "NVPTXISD::Tld4UnifiedB2DFloatFloat";
00659   case NVPTXISD::Tld4UnifiedA2DFloatFloat:
00660     return "NVPTXISD::Tld4UnifiedA2DFloatFloat";
00661   case NVPTXISD::Tld4UnifiedR2DS64Float:
00662     return "NVPTXISD::Tld4UnifiedR2DS64Float";
00663   case NVPTXISD::Tld4UnifiedG2DS64Float:
00664     return "NVPTXISD::Tld4UnifiedG2DS64Float";
00665   case NVPTXISD::Tld4UnifiedB2DS64Float:
00666     return "NVPTXISD::Tld4UnifiedB2DS64Float";
00667   case NVPTXISD::Tld4UnifiedA2DS64Float:
00668     return "NVPTXISD::Tld4UnifiedA2DS64Float";
00669   case NVPTXISD::Tld4UnifiedR2DU64Float:
00670     return "NVPTXISD::Tld4UnifiedR2DU64Float";
00671   case NVPTXISD::Tld4UnifiedG2DU64Float:
00672     return "NVPTXISD::Tld4UnifiedG2DU64Float";
00673   case NVPTXISD::Tld4UnifiedB2DU64Float:
00674     return "NVPTXISD::Tld4UnifiedB2DU64Float";
00675   case NVPTXISD::Tld4UnifiedA2DU64Float:
00676     return "NVPTXISD::Tld4UnifiedA2DU64Float";
00677 
00678   case NVPTXISD::Suld1DI8Clamp:          return "NVPTXISD::Suld1DI8Clamp";
00679   case NVPTXISD::Suld1DI16Clamp:         return "NVPTXISD::Suld1DI16Clamp";
00680   case NVPTXISD::Suld1DI32Clamp:         return "NVPTXISD::Suld1DI32Clamp";
00681   case NVPTXISD::Suld1DI64Clamp:         return "NVPTXISD::Suld1DI64Clamp";
00682   case NVPTXISD::Suld1DV2I8Clamp:        return "NVPTXISD::Suld1DV2I8Clamp";
00683   case NVPTXISD::Suld1DV2I16Clamp:       return "NVPTXISD::Suld1DV2I16Clamp";
00684   case NVPTXISD::Suld1DV2I32Clamp:       return "NVPTXISD::Suld1DV2I32Clamp";
00685   case NVPTXISD::Suld1DV2I64Clamp:       return "NVPTXISD::Suld1DV2I64Clamp";
00686   case NVPTXISD::Suld1DV4I8Clamp:        return "NVPTXISD::Suld1DV4I8Clamp";
00687   case NVPTXISD::Suld1DV4I16Clamp:       return "NVPTXISD::Suld1DV4I16Clamp";
00688   case NVPTXISD::Suld1DV4I32Clamp:       return "NVPTXISD::Suld1DV4I32Clamp";
00689 
00690   case NVPTXISD::Suld1DArrayI8Clamp:   return "NVPTXISD::Suld1DArrayI8Clamp";
00691   case NVPTXISD::Suld1DArrayI16Clamp:  return "NVPTXISD::Suld1DArrayI16Clamp";
00692   case NVPTXISD::Suld1DArrayI32Clamp:  return "NVPTXISD::Suld1DArrayI32Clamp";
00693   case NVPTXISD::Suld1DArrayI64Clamp:  return "NVPTXISD::Suld1DArrayI64Clamp";
00694   case NVPTXISD::Suld1DArrayV2I8Clamp: return "NVPTXISD::Suld1DArrayV2I8Clamp";
00695   case NVPTXISD::Suld1DArrayV2I16Clamp:return "NVPTXISD::Suld1DArrayV2I16Clamp";
00696   case NVPTXISD::Suld1DArrayV2I32Clamp:return "NVPTXISD::Suld1DArrayV2I32Clamp";
00697   case NVPTXISD::Suld1DArrayV2I64Clamp:return "NVPTXISD::Suld1DArrayV2I64Clamp";
00698   case NVPTXISD::Suld1DArrayV4I8Clamp: return "NVPTXISD::Suld1DArrayV4I8Clamp";
00699   case NVPTXISD::Suld1DArrayV4I16Clamp:return "NVPTXISD::Suld1DArrayV4I16Clamp";
00700   case NVPTXISD::Suld1DArrayV4I32Clamp:return "NVPTXISD::Suld1DArrayV4I32Clamp";
00701 
00702   case NVPTXISD::Suld2DI8Clamp:          return "NVPTXISD::Suld2DI8Clamp";
00703   case NVPTXISD::Suld2DI16Clamp:         return "NVPTXISD::Suld2DI16Clamp";
00704   case NVPTXISD::Suld2DI32Clamp:         return "NVPTXISD::Suld2DI32Clamp";
00705   case NVPTXISD::Suld2DI64Clamp:         return "NVPTXISD::Suld2DI64Clamp";
00706   case NVPTXISD::Suld2DV2I8Clamp:        return "NVPTXISD::Suld2DV2I8Clamp";
00707   case NVPTXISD::Suld2DV2I16Clamp:       return "NVPTXISD::Suld2DV2I16Clamp";
00708   case NVPTXISD::Suld2DV2I32Clamp:       return "NVPTXISD::Suld2DV2I32Clamp";
00709   case NVPTXISD::Suld2DV2I64Clamp:       return "NVPTXISD::Suld2DV2I64Clamp";
00710   case NVPTXISD::Suld2DV4I8Clamp:        return "NVPTXISD::Suld2DV4I8Clamp";
00711   case NVPTXISD::Suld2DV4I16Clamp:       return "NVPTXISD::Suld2DV4I16Clamp";
00712   case NVPTXISD::Suld2DV4I32Clamp:       return "NVPTXISD::Suld2DV4I32Clamp";
00713 
00714   case NVPTXISD::Suld2DArrayI8Clamp:   return "NVPTXISD::Suld2DArrayI8Clamp";
00715   case NVPTXISD::Suld2DArrayI16Clamp:  return "NVPTXISD::Suld2DArrayI16Clamp";
00716   case NVPTXISD::Suld2DArrayI32Clamp:  return "NVPTXISD::Suld2DArrayI32Clamp";
00717   case NVPTXISD::Suld2DArrayI64Clamp:  return "NVPTXISD::Suld2DArrayI64Clamp";
00718   case NVPTXISD::Suld2DArrayV2I8Clamp: return "NVPTXISD::Suld2DArrayV2I8Clamp";
00719   case NVPTXISD::Suld2DArrayV2I16Clamp:return "NVPTXISD::Suld2DArrayV2I16Clamp";
00720   case NVPTXISD::Suld2DArrayV2I32Clamp:return "NVPTXISD::Suld2DArrayV2I32Clamp";
00721   case NVPTXISD::Suld2DArrayV2I64Clamp:return "NVPTXISD::Suld2DArrayV2I64Clamp";
00722   case NVPTXISD::Suld2DArrayV4I8Clamp: return "NVPTXISD::Suld2DArrayV4I8Clamp";
00723   case NVPTXISD::Suld2DArrayV4I16Clamp:return "NVPTXISD::Suld2DArrayV4I16Clamp";
00724   case NVPTXISD::Suld2DArrayV4I32Clamp:return "NVPTXISD::Suld2DArrayV4I32Clamp";
00725 
00726   case NVPTXISD::Suld3DI8Clamp:          return "NVPTXISD::Suld3DI8Clamp";
00727   case NVPTXISD::Suld3DI16Clamp:         return "NVPTXISD::Suld3DI16Clamp";
00728   case NVPTXISD::Suld3DI32Clamp:         return "NVPTXISD::Suld3DI32Clamp";
00729   case NVPTXISD::Suld3DI64Clamp:         return "NVPTXISD::Suld3DI64Clamp";
00730   case NVPTXISD::Suld3DV2I8Clamp:        return "NVPTXISD::Suld3DV2I8Clamp";
00731   case NVPTXISD::Suld3DV2I16Clamp:       return "NVPTXISD::Suld3DV2I16Clamp";
00732   case NVPTXISD::Suld3DV2I32Clamp:       return "NVPTXISD::Suld3DV2I32Clamp";
00733   case NVPTXISD::Suld3DV2I64Clamp:       return "NVPTXISD::Suld3DV2I64Clamp";
00734   case NVPTXISD::Suld3DV4I8Clamp:        return "NVPTXISD::Suld3DV4I8Clamp";
00735   case NVPTXISD::Suld3DV4I16Clamp:       return "NVPTXISD::Suld3DV4I16Clamp";
00736   case NVPTXISD::Suld3DV4I32Clamp:       return "NVPTXISD::Suld3DV4I32Clamp";
00737 
00738   case NVPTXISD::Suld1DI8Trap:          return "NVPTXISD::Suld1DI8Trap";
00739   case NVPTXISD::Suld1DI16Trap:         return "NVPTXISD::Suld1DI16Trap";
00740   case NVPTXISD::Suld1DI32Trap:         return "NVPTXISD::Suld1DI32Trap";
00741   case NVPTXISD::Suld1DI64Trap:         return "NVPTXISD::Suld1DI64Trap";
00742   case NVPTXISD::Suld1DV2I8Trap:        return "NVPTXISD::Suld1DV2I8Trap";
00743   case NVPTXISD::Suld1DV2I16Trap:       return "NVPTXISD::Suld1DV2I16Trap";
00744   case NVPTXISD::Suld1DV2I32Trap:       return "NVPTXISD::Suld1DV2I32Trap";
00745   case NVPTXISD::Suld1DV2I64Trap:       return "NVPTXISD::Suld1DV2I64Trap";
00746   case NVPTXISD::Suld1DV4I8Trap:        return "NVPTXISD::Suld1DV4I8Trap";
00747   case NVPTXISD::Suld1DV4I16Trap:       return "NVPTXISD::Suld1DV4I16Trap";
00748   case NVPTXISD::Suld1DV4I32Trap:       return "NVPTXISD::Suld1DV4I32Trap";
00749 
00750   case NVPTXISD::Suld1DArrayI8Trap:     return "NVPTXISD::Suld1DArrayI8Trap";
00751   case NVPTXISD::Suld1DArrayI16Trap:    return "NVPTXISD::Suld1DArrayI16Trap";
00752   case NVPTXISD::Suld1DArrayI32Trap:    return "NVPTXISD::Suld1DArrayI32Trap";
00753   case NVPTXISD::Suld1DArrayI64Trap:    return "NVPTXISD::Suld1DArrayI64Trap";
00754   case NVPTXISD::Suld1DArrayV2I8Trap:   return "NVPTXISD::Suld1DArrayV2I8Trap";
00755   case NVPTXISD::Suld1DArrayV2I16Trap:  return "NVPTXISD::Suld1DArrayV2I16Trap";
00756   case NVPTXISD::Suld1DArrayV2I32Trap:  return "NVPTXISD::Suld1DArrayV2I32Trap";
00757   case NVPTXISD::Suld1DArrayV2I64Trap:  return "NVPTXISD::Suld1DArrayV2I64Trap";
00758   case NVPTXISD::Suld1DArrayV4I8Trap:   return "NVPTXISD::Suld1DArrayV4I8Trap";
00759   case NVPTXISD::Suld1DArrayV4I16Trap:  return "NVPTXISD::Suld1DArrayV4I16Trap";
00760   case NVPTXISD::Suld1DArrayV4I32Trap:  return "NVPTXISD::Suld1DArrayV4I32Trap";
00761 
00762   case NVPTXISD::Suld2DI8Trap:          return "NVPTXISD::Suld2DI8Trap";
00763   case NVPTXISD::Suld2DI16Trap:         return "NVPTXISD::Suld2DI16Trap";
00764   case NVPTXISD::Suld2DI32Trap:         return "NVPTXISD::Suld2DI32Trap";
00765   case NVPTXISD::Suld2DI64Trap:         return "NVPTXISD::Suld2DI64Trap";
00766   case NVPTXISD::Suld2DV2I8Trap:        return "NVPTXISD::Suld2DV2I8Trap";
00767   case NVPTXISD::Suld2DV2I16Trap:       return "NVPTXISD::Suld2DV2I16Trap";
00768   case NVPTXISD::Suld2DV2I32Trap:       return "NVPTXISD::Suld2DV2I32Trap";
00769   case NVPTXISD::Suld2DV2I64Trap:       return "NVPTXISD::Suld2DV2I64Trap";
00770   case NVPTXISD::Suld2DV4I8Trap:        return "NVPTXISD::Suld2DV4I8Trap";
00771   case NVPTXISD::Suld2DV4I16Trap:       return "NVPTXISD::Suld2DV4I16Trap";
00772   case NVPTXISD::Suld2DV4I32Trap:       return "NVPTXISD::Suld2DV4I32Trap";
00773 
00774   case NVPTXISD::Suld2DArrayI8Trap:     return "NVPTXISD::Suld2DArrayI8Trap";
00775   case NVPTXISD::Suld2DArrayI16Trap:    return "NVPTXISD::Suld2DArrayI16Trap";
00776   case NVPTXISD::Suld2DArrayI32Trap:    return "NVPTXISD::Suld2DArrayI32Trap";
00777   case NVPTXISD::Suld2DArrayI64Trap:    return "NVPTXISD::Suld2DArrayI64Trap";
00778   case NVPTXISD::Suld2DArrayV2I8Trap:   return "NVPTXISD::Suld2DArrayV2I8Trap";
00779   case NVPTXISD::Suld2DArrayV2I16Trap:  return "NVPTXISD::Suld2DArrayV2I16Trap";
00780   case NVPTXISD::Suld2DArrayV2I32Trap:  return "NVPTXISD::Suld2DArrayV2I32Trap";
00781   case NVPTXISD::Suld2DArrayV2I64Trap:  return "NVPTXISD::Suld2DArrayV2I64Trap";
00782   case NVPTXISD::Suld2DArrayV4I8Trap:   return "NVPTXISD::Suld2DArrayV4I8Trap";
00783   case NVPTXISD::Suld2DArrayV4I16Trap:  return "NVPTXISD::Suld2DArrayV4I16Trap";
00784   case NVPTXISD::Suld2DArrayV4I32Trap:  return "NVPTXISD::Suld2DArrayV4I32Trap";
00785 
00786   case NVPTXISD::Suld3DI8Trap:          return "NVPTXISD::Suld3DI8Trap";
00787   case NVPTXISD::Suld3DI16Trap:         return "NVPTXISD::Suld3DI16Trap";
00788   case NVPTXISD::Suld3DI32Trap:         return "NVPTXISD::Suld3DI32Trap";
00789   case NVPTXISD::Suld3DI64Trap:         return "NVPTXISD::Suld3DI64Trap";
00790   case NVPTXISD::Suld3DV2I8Trap:        return "NVPTXISD::Suld3DV2I8Trap";
00791   case NVPTXISD::Suld3DV2I16Trap:       return "NVPTXISD::Suld3DV2I16Trap";
00792   case NVPTXISD::Suld3DV2I32Trap:       return "NVPTXISD::Suld3DV2I32Trap";
00793   case NVPTXISD::Suld3DV2I64Trap:       return "NVPTXISD::Suld3DV2I64Trap";
00794   case NVPTXISD::Suld3DV4I8Trap:        return "NVPTXISD::Suld3DV4I8Trap";
00795   case NVPTXISD::Suld3DV4I16Trap:       return "NVPTXISD::Suld3DV4I16Trap";
00796   case NVPTXISD::Suld3DV4I32Trap:       return "NVPTXISD::Suld3DV4I32Trap";
00797 
00798   case NVPTXISD::Suld1DI8Zero:          return "NVPTXISD::Suld1DI8Zero";
00799   case NVPTXISD::Suld1DI16Zero:         return "NVPTXISD::Suld1DI16Zero";
00800   case NVPTXISD::Suld1DI32Zero:         return "NVPTXISD::Suld1DI32Zero";
00801   case NVPTXISD::Suld1DI64Zero:         return "NVPTXISD::Suld1DI64Zero";
00802   case NVPTXISD::Suld1DV2I8Zero:        return "NVPTXISD::Suld1DV2I8Zero";
00803   case NVPTXISD::Suld1DV2I16Zero:       return "NVPTXISD::Suld1DV2I16Zero";
00804   case NVPTXISD::Suld1DV2I32Zero:       return "NVPTXISD::Suld1DV2I32Zero";
00805   case NVPTXISD::Suld1DV2I64Zero:       return "NVPTXISD::Suld1DV2I64Zero";
00806   case NVPTXISD::Suld1DV4I8Zero:        return "NVPTXISD::Suld1DV4I8Zero";
00807   case NVPTXISD::Suld1DV4I16Zero:       return "NVPTXISD::Suld1DV4I16Zero";
00808   case NVPTXISD::Suld1DV4I32Zero:       return "NVPTXISD::Suld1DV4I32Zero";
00809 
00810   case NVPTXISD::Suld1DArrayI8Zero:     return "NVPTXISD::Suld1DArrayI8Zero";
00811   case NVPTXISD::Suld1DArrayI16Zero:    return "NVPTXISD::Suld1DArrayI16Zero";
00812   case NVPTXISD::Suld1DArrayI32Zero:    return "NVPTXISD::Suld1DArrayI32Zero";
00813   case NVPTXISD::Suld1DArrayI64Zero:    return "NVPTXISD::Suld1DArrayI64Zero";
00814   case NVPTXISD::Suld1DArrayV2I8Zero:   return "NVPTXISD::Suld1DArrayV2I8Zero";
00815   case NVPTXISD::Suld1DArrayV2I16Zero:  return "NVPTXISD::Suld1DArrayV2I16Zero";
00816   case NVPTXISD::Suld1DArrayV2I32Zero:  return "NVPTXISD::Suld1DArrayV2I32Zero";
00817   case NVPTXISD::Suld1DArrayV2I64Zero:  return "NVPTXISD::Suld1DArrayV2I64Zero";
00818   case NVPTXISD::Suld1DArrayV4I8Zero:   return "NVPTXISD::Suld1DArrayV4I8Zero";
00819   case NVPTXISD::Suld1DArrayV4I16Zero:  return "NVPTXISD::Suld1DArrayV4I16Zero";
00820   case NVPTXISD::Suld1DArrayV4I32Zero:  return "NVPTXISD::Suld1DArrayV4I32Zero";
00821 
00822   case NVPTXISD::Suld2DI8Zero:          return "NVPTXISD::Suld2DI8Zero";
00823   case NVPTXISD::Suld2DI16Zero:         return "NVPTXISD::Suld2DI16Zero";
00824   case NVPTXISD::Suld2DI32Zero:         return "NVPTXISD::Suld2DI32Zero";
00825   case NVPTXISD::Suld2DI64Zero:         return "NVPTXISD::Suld2DI64Zero";
00826   case NVPTXISD::Suld2DV2I8Zero:        return "NVPTXISD::Suld2DV2I8Zero";
00827   case NVPTXISD::Suld2DV2I16Zero:       return "NVPTXISD::Suld2DV2I16Zero";
00828   case NVPTXISD::Suld2DV2I32Zero:       return "NVPTXISD::Suld2DV2I32Zero";
00829   case NVPTXISD::Suld2DV2I64Zero:       return "NVPTXISD::Suld2DV2I64Zero";
00830   case NVPTXISD::Suld2DV4I8Zero:        return "NVPTXISD::Suld2DV4I8Zero";
00831   case NVPTXISD::Suld2DV4I16Zero:       return "NVPTXISD::Suld2DV4I16Zero";
00832   case NVPTXISD::Suld2DV4I32Zero:       return "NVPTXISD::Suld2DV4I32Zero";
00833 
00834   case NVPTXISD::Suld2DArrayI8Zero:     return "NVPTXISD::Suld2DArrayI8Zero";
00835   case NVPTXISD::Suld2DArrayI16Zero:    return "NVPTXISD::Suld2DArrayI16Zero";
00836   case NVPTXISD::Suld2DArrayI32Zero:    return "NVPTXISD::Suld2DArrayI32Zero";
00837   case NVPTXISD::Suld2DArrayI64Zero:    return "NVPTXISD::Suld2DArrayI64Zero";
00838   case NVPTXISD::Suld2DArrayV2I8Zero:   return "NVPTXISD::Suld2DArrayV2I8Zero";
00839   case NVPTXISD::Suld2DArrayV2I16Zero:  return "NVPTXISD::Suld2DArrayV2I16Zero";
00840   case NVPTXISD::Suld2DArrayV2I32Zero:  return "NVPTXISD::Suld2DArrayV2I32Zero";
00841   case NVPTXISD::Suld2DArrayV2I64Zero:  return "NVPTXISD::Suld2DArrayV2I64Zero";
00842   case NVPTXISD::Suld2DArrayV4I8Zero:   return "NVPTXISD::Suld2DArrayV4I8Zero";
00843   case NVPTXISD::Suld2DArrayV4I16Zero:  return "NVPTXISD::Suld2DArrayV4I16Zero";
00844   case NVPTXISD::Suld2DArrayV4I32Zero:  return "NVPTXISD::Suld2DArrayV4I32Zero";
00845 
00846   case NVPTXISD::Suld3DI8Zero:          return "NVPTXISD::Suld3DI8Zero";
00847   case NVPTXISD::Suld3DI16Zero:         return "NVPTXISD::Suld3DI16Zero";
00848   case NVPTXISD::Suld3DI32Zero:         return "NVPTXISD::Suld3DI32Zero";
00849   case NVPTXISD::Suld3DI64Zero:         return "NVPTXISD::Suld3DI64Zero";
00850   case NVPTXISD::Suld3DV2I8Zero:        return "NVPTXISD::Suld3DV2I8Zero";
00851   case NVPTXISD::Suld3DV2I16Zero:       return "NVPTXISD::Suld3DV2I16Zero";
00852   case NVPTXISD::Suld3DV2I32Zero:       return "NVPTXISD::Suld3DV2I32Zero";
00853   case NVPTXISD::Suld3DV2I64Zero:       return "NVPTXISD::Suld3DV2I64Zero";
00854   case NVPTXISD::Suld3DV4I8Zero:        return "NVPTXISD::Suld3DV4I8Zero";
00855   case NVPTXISD::Suld3DV4I16Zero:       return "NVPTXISD::Suld3DV4I16Zero";
00856   case NVPTXISD::Suld3DV4I32Zero:       return "NVPTXISD::Suld3DV4I32Zero";
00857   }
00858 }
00859 
00860 TargetLoweringBase::LegalizeTypeAction
00861 NVPTXTargetLowering::getPreferredVectorAction(EVT VT) const {
00862   if (VT.getVectorNumElements() != 1 && VT.getScalarType() == MVT::i1)
00863     return TypeSplitVector;
00864 
00865   return TargetLoweringBase::getPreferredVectorAction(VT);
00866 }
00867 
00868 SDValue
00869 NVPTXTargetLowering::LowerGlobalAddress(SDValue Op, SelectionDAG &DAG) const {
00870   SDLoc dl(Op);
00871   const GlobalValue *GV = cast<GlobalAddressSDNode>(Op)->getGlobal();
00872   Op = DAG.getTargetGlobalAddress(GV, dl, getPointerTy());
00873   return DAG.getNode(NVPTXISD::Wrapper, dl, getPointerTy(), Op);
00874 }
00875 
00876 std::string
00877 NVPTXTargetLowering::getPrototype(Type *retTy, const ArgListTy &Args,
00878                                   const SmallVectorImpl<ISD::OutputArg> &Outs,
00879                                   unsigned retAlignment,
00880                                   const ImmutableCallSite *CS) const {
00881 
00882   bool isABI = (STI.getSmVersion() >= 20);
00883   assert(isABI && "Non-ABI compilation is not supported");
00884   if (!isABI)
00885     return "";
00886 
00887   std::stringstream O;
00888   O << "prototype_" << uniqueCallSite << " : .callprototype ";
00889 
00890   if (retTy->getTypeID() == Type::VoidTyID) {
00891     O << "()";
00892   } else {
00893     O << "(";
00894     if (retTy->isFloatingPointTy() || retTy->isIntegerTy()) {
00895       unsigned size = 0;
00896       if (const IntegerType *ITy = dyn_cast<IntegerType>(retTy)) {
00897         size = ITy->getBitWidth();
00898         if (size < 32)
00899           size = 32;
00900       } else {
00901         assert(retTy->isFloatingPointTy() &&
00902                "Floating point type expected here");
00903         size = retTy->getPrimitiveSizeInBits();
00904       }
00905 
00906       O << ".param .b" << size << " _";
00907     } else if (isa<PointerType>(retTy)) {
00908       O << ".param .b" << getPointerTy().getSizeInBits() << " _";
00909     } else if ((retTy->getTypeID() == Type::StructTyID) ||
00910                isa<VectorType>(retTy)) {
00911       O << ".param .align "
00912         << retAlignment
00913         << " .b8 _["
00914         << getDataLayout()->getTypeAllocSize(retTy) << "]";
00915     } else {
00916       llvm_unreachable("Unknown return type");
00917     }
00918     O << ") ";
00919   }
00920   O << "_ (";
00921 
00922   bool first = true;
00923   MVT thePointerTy = getPointerTy();
00924 
00925   unsigned OIdx = 0;
00926   for (unsigned i = 0, e = Args.size(); i != e; ++i, ++OIdx) {
00927     Type *Ty = Args[i].Ty;
00928     if (!first) {
00929       O << ", ";
00930     }
00931     first = false;
00932 
00933     if (Outs[OIdx].Flags.isByVal() == false) {
00934       if (Ty->isAggregateType() || Ty->isVectorTy()) {
00935         unsigned align = 0;
00936         const CallInst *CallI = cast<CallInst>(CS->getInstruction());
00937         const DataLayout *TD = getDataLayout();
00938         // +1 because index 0 is reserved for return type alignment
00939         if (!llvm::getAlign(*CallI, i + 1, align))
00940           align = TD->getABITypeAlignment(Ty);
00941         unsigned sz = TD->getTypeAllocSize(Ty);
00942         O << ".param .align " << align << " .b8 ";
00943         O << "_";
00944         O << "[" << sz << "]";
00945         // update the index for Outs
00946         SmallVector<EVT, 16> vtparts;
00947         ComputeValueVTs(*this, Ty, vtparts);
00948         if (unsigned len = vtparts.size())
00949           OIdx += len - 1;
00950         continue;
00951       }
00952        // i8 types in IR will be i16 types in SDAG
00953       assert((getValueType(Ty) == Outs[OIdx].VT ||
00954              (getValueType(Ty) == MVT::i8 && Outs[OIdx].VT == MVT::i16)) &&
00955              "type mismatch between callee prototype and arguments");
00956       // scalar type
00957       unsigned sz = 0;
00958       if (isa<IntegerType>(Ty)) {
00959         sz = cast<IntegerType>(Ty)->getBitWidth();
00960         if (sz < 32)
00961           sz = 32;
00962       } else if (isa<PointerType>(Ty))
00963         sz = thePointerTy.getSizeInBits();
00964       else
00965         sz = Ty->getPrimitiveSizeInBits();
00966       O << ".param .b" << sz << " ";
00967       O << "_";
00968       continue;
00969     }
00970     const PointerType *PTy = dyn_cast<PointerType>(Ty);
00971     assert(PTy && "Param with byval attribute should be a pointer type");
00972     Type *ETy = PTy->getElementType();
00973 
00974     unsigned align = Outs[OIdx].Flags.getByValAlign();
00975     unsigned sz = getDataLayout()->getTypeAllocSize(ETy);
00976     O << ".param .align " << align << " .b8 ";
00977     O << "_";
00978     O << "[" << sz << "]";
00979   }
00980   O << ");";
00981   return O.str();
00982 }
00983 
00984 unsigned
00985 NVPTXTargetLowering::getArgumentAlignment(SDValue Callee,
00986                                           const ImmutableCallSite *CS,
00987                                           Type *Ty,
00988                                           unsigned Idx) const {
00989   const DataLayout *TD = getDataLayout();
00990   unsigned Align = 0;
00991   const Value *DirectCallee = CS->getCalledFunction();
00992 
00993   if (!DirectCallee) {
00994     // We don't have a direct function symbol, but that may be because of
00995     // constant cast instructions in the call.
00996     const Instruction *CalleeI = CS->getInstruction();
00997     assert(CalleeI && "Call target is not a function or derived value?");
00998 
00999     // With bitcast'd call targets, the instruction will be the call
01000     if (isa<CallInst>(CalleeI)) {
01001       // Check if we have call alignment metadata
01002       if (llvm::getAlign(*cast<CallInst>(CalleeI), Idx, Align))
01003         return Align;
01004 
01005       const Value *CalleeV = cast<CallInst>(CalleeI)->getCalledValue();
01006       // Ignore any bitcast instructions
01007       while(isa<ConstantExpr>(CalleeV)) {
01008         const ConstantExpr *CE = cast<ConstantExpr>(CalleeV);
01009         if (!CE->isCast())
01010           break;
01011         // Look through the bitcast
01012         CalleeV = cast<ConstantExpr>(CalleeV)->getOperand(0);
01013       }
01014 
01015       // We have now looked past all of the bitcasts.  Do we finally have a
01016       // Function?
01017       if (isa<Function>(CalleeV))
01018         DirectCallee = CalleeV;
01019     }
01020   }
01021 
01022   // Check for function alignment information if we found that the
01023   // ultimate target is a Function
01024   if (DirectCallee)
01025     if (llvm::getAlign(*cast<Function>(DirectCallee), Idx, Align))
01026       return Align;
01027 
01028   // Call is indirect or alignment information is not available, fall back to
01029   // the ABI type alignment
01030   return TD->getABITypeAlignment(Ty);
01031 }
01032 
01033 SDValue NVPTXTargetLowering::LowerCall(TargetLowering::CallLoweringInfo &CLI,
01034                                        SmallVectorImpl<SDValue> &InVals) const {
01035   SelectionDAG &DAG = CLI.DAG;
01036   SDLoc dl = CLI.DL;
01037   SmallVectorImpl<ISD::OutputArg> &Outs = CLI.Outs;
01038   SmallVectorImpl<SDValue> &OutVals = CLI.OutVals;
01039   SmallVectorImpl<ISD::InputArg> &Ins = CLI.Ins;
01040   SDValue Chain = CLI.Chain;
01041   SDValue Callee = CLI.Callee;
01042   bool &isTailCall = CLI.IsTailCall;
01043   ArgListTy &Args = CLI.getArgs();
01044   Type *retTy = CLI.RetTy;
01045   ImmutableCallSite *CS = CLI.CS;
01046 
01047   bool isABI = (STI.getSmVersion() >= 20);
01048   assert(isABI && "Non-ABI compilation is not supported");
01049   if (!isABI)
01050     return Chain;
01051   const DataLayout *TD = getDataLayout();
01052   MachineFunction &MF = DAG.getMachineFunction();
01053   const Function *F = MF.getFunction();
01054 
01055   SDValue tempChain = Chain;
01056   Chain =
01057       DAG.getCALLSEQ_START(Chain, DAG.getIntPtrConstant(uniqueCallSite, true),
01058                            dl);
01059   SDValue InFlag = Chain.getValue(1);
01060 
01061   unsigned paramCount = 0;
01062   // Args.size() and Outs.size() need not match.
01063   // Outs.size() will be larger
01064   //   * if there is an aggregate argument with multiple fields (each field
01065   //     showing up separately in Outs)
01066   //   * if there is a vector argument with more than typical vector-length
01067   //     elements (generally if more than 4) where each vector element is
01068   //     individually present in Outs.
01069   // So a different index should be used for indexing into Outs/OutVals.
01070   // See similar issue in LowerFormalArguments.
01071   unsigned OIdx = 0;
01072   // Declare the .params or .reg need to pass values
01073   // to the function
01074   for (unsigned i = 0, e = Args.size(); i != e; ++i, ++OIdx) {
01075     EVT VT = Outs[OIdx].VT;
01076     Type *Ty = Args[i].Ty;
01077 
01078     if (Outs[OIdx].Flags.isByVal() == false) {
01079       if (Ty->isAggregateType()) {
01080         // aggregate
01081         SmallVector<EVT, 16> vtparts;
01082         SmallVector<uint64_t, 16> Offsets;
01083         ComputePTXValueVTs(*this, Ty, vtparts, &Offsets, 0);
01084 
01085         unsigned align = getArgumentAlignment(Callee, CS, Ty, paramCount + 1);
01086         // declare .param .align <align> .b8 .param<n>[<size>];
01087         unsigned sz = TD->getTypeAllocSize(Ty);
01088         SDVTList DeclareParamVTs = DAG.getVTList(MVT::Other, MVT::Glue);
01089         SDValue DeclareParamOps[] = { Chain, DAG.getConstant(align, MVT::i32),
01090                                       DAG.getConstant(paramCount, MVT::i32),
01091                                       DAG.getConstant(sz, MVT::i32), InFlag };
01092         Chain = DAG.getNode(NVPTXISD::DeclareParam, dl, DeclareParamVTs,
01093                             DeclareParamOps);
01094         InFlag = Chain.getValue(1);
01095         for (unsigned j = 0, je = vtparts.size(); j != je; ++j) {
01096           EVT elemtype = vtparts[j];
01097           unsigned ArgAlign = GreatestCommonDivisor64(align, Offsets[j]);
01098           if (elemtype.isInteger() && (sz < 8))
01099             sz = 8;
01100           SDValue StVal = OutVals[OIdx];
01101           if (elemtype.getSizeInBits() < 16) {
01102             StVal = DAG.getNode(ISD::ANY_EXTEND, dl, MVT::i16, StVal);
01103           }
01104           SDVTList CopyParamVTs = DAG.getVTList(MVT::Other, MVT::Glue);
01105           SDValue CopyParamOps[] = { Chain,
01106                                      DAG.getConstant(paramCount, MVT::i32),
01107                                      DAG.getConstant(Offsets[j], MVT::i32),
01108                                      StVal, InFlag };
01109           Chain = DAG.getMemIntrinsicNode(NVPTXISD::StoreParam, dl,
01110                                           CopyParamVTs, CopyParamOps,
01111                                           elemtype, MachinePointerInfo(),
01112                                           ArgAlign);
01113           InFlag = Chain.getValue(1);
01114           ++OIdx;
01115         }
01116         if (vtparts.size() > 0)
01117           --OIdx;
01118         ++paramCount;
01119         continue;
01120       }
01121       if (Ty->isVectorTy()) {
01122         EVT ObjectVT = getValueType(Ty);
01123         unsigned align = getArgumentAlignment(Callee, CS, Ty, paramCount + 1);
01124         // declare .param .align <align> .b8 .param<n>[<size>];
01125         unsigned sz = TD->getTypeAllocSize(Ty);
01126         SDVTList DeclareParamVTs = DAG.getVTList(MVT::Other, MVT::Glue);
01127         SDValue DeclareParamOps[] = { Chain, DAG.getConstant(align, MVT::i32),
01128                                       DAG.getConstant(paramCount, MVT::i32),
01129                                       DAG.getConstant(sz, MVT::i32), InFlag };
01130         Chain = DAG.getNode(NVPTXISD::DeclareParam, dl, DeclareParamVTs,
01131                             DeclareParamOps);
01132         InFlag = Chain.getValue(1);
01133         unsigned NumElts = ObjectVT.getVectorNumElements();
01134         EVT EltVT = ObjectVT.getVectorElementType();
01135         EVT MemVT = EltVT;
01136         bool NeedExtend = false;
01137         if (EltVT.getSizeInBits() < 16) {
01138           NeedExtend = true;
01139           EltVT = MVT::i16;
01140         }
01141 
01142         // V1 store
01143         if (NumElts == 1) {
01144           SDValue Elt = OutVals[OIdx++];
01145           if (NeedExtend)
01146             Elt = DAG.getNode(ISD::ZERO_EXTEND, dl, MVT::i16, Elt);
01147 
01148           SDVTList CopyParamVTs = DAG.getVTList(MVT::Other, MVT::Glue);
01149           SDValue CopyParamOps[] = { Chain,
01150                                      DAG.getConstant(paramCount, MVT::i32),
01151                                      DAG.getConstant(0, MVT::i32), Elt,
01152                                      InFlag };
01153           Chain = DAG.getMemIntrinsicNode(NVPTXISD::StoreParam, dl,
01154                                           CopyParamVTs, CopyParamOps,
01155                                           MemVT, MachinePointerInfo());
01156           InFlag = Chain.getValue(1);
01157         } else if (NumElts == 2) {
01158           SDValue Elt0 = OutVals[OIdx++];
01159           SDValue Elt1 = OutVals[OIdx++];
01160           if (NeedExtend) {
01161             Elt0 = DAG.getNode(ISD::ZERO_EXTEND, dl, MVT::i16, Elt0);
01162             Elt1 = DAG.getNode(ISD::ZERO_EXTEND, dl, MVT::i16, Elt1);
01163           }
01164 
01165           SDVTList CopyParamVTs = DAG.getVTList(MVT::Other, MVT::Glue);
01166           SDValue CopyParamOps[] = { Chain,
01167                                      DAG.getConstant(paramCount, MVT::i32),
01168                                      DAG.getConstant(0, MVT::i32), Elt0, Elt1,
01169                                      InFlag };
01170           Chain = DAG.getMemIntrinsicNode(NVPTXISD::StoreParamV2, dl,
01171                                           CopyParamVTs, CopyParamOps,
01172                                           MemVT, MachinePointerInfo());
01173           InFlag = Chain.getValue(1);
01174         } else {
01175           unsigned curOffset = 0;
01176           // V4 stores
01177           // We have at least 4 elements (<3 x Ty> expands to 4 elements) and
01178           // the
01179           // vector will be expanded to a power of 2 elements, so we know we can
01180           // always round up to the next multiple of 4 when creating the vector
01181           // stores.
01182           // e.g.  4 elem => 1 st.v4
01183           //       6 elem => 2 st.v4
01184           //       8 elem => 2 st.v4
01185           //      11 elem => 3 st.v4
01186           unsigned VecSize = 4;
01187           if (EltVT.getSizeInBits() == 64)
01188             VecSize = 2;
01189 
01190           // This is potentially only part of a vector, so assume all elements
01191           // are packed together.
01192           unsigned PerStoreOffset = MemVT.getStoreSizeInBits() / 8 * VecSize;
01193 
01194           for (unsigned i = 0; i < NumElts; i += VecSize) {
01195             // Get values
01196             SDValue StoreVal;
01197             SmallVector<SDValue, 8> Ops;
01198             Ops.push_back(Chain);
01199             Ops.push_back(DAG.getConstant(paramCount, MVT::i32));
01200             Ops.push_back(DAG.getConstant(curOffset, MVT::i32));
01201 
01202             unsigned Opc = NVPTXISD::StoreParamV2;
01203 
01204             StoreVal = OutVals[OIdx++];
01205             if (NeedExtend)
01206               StoreVal = DAG.getNode(ISD::ZERO_EXTEND, dl, MVT::i16, StoreVal);
01207             Ops.push_back(StoreVal);
01208 
01209             if (i + 1 < NumElts) {
01210               StoreVal = OutVals[OIdx++];
01211               if (NeedExtend)
01212                 StoreVal =
01213                     DAG.getNode(ISD::ZERO_EXTEND, dl, MVT::i16, StoreVal);
01214             } else {
01215               StoreVal = DAG.getUNDEF(EltVT);
01216             }
01217             Ops.push_back(StoreVal);
01218 
01219             if (VecSize == 4) {
01220               Opc = NVPTXISD::StoreParamV4;
01221               if (i + 2 < NumElts) {
01222                 StoreVal = OutVals[OIdx++];
01223                 if (NeedExtend)
01224                   StoreVal =
01225                       DAG.getNode(ISD::ZERO_EXTEND, dl, MVT::i16, StoreVal);
01226               } else {
01227                 StoreVal = DAG.getUNDEF(EltVT);
01228               }
01229               Ops.push_back(StoreVal);
01230 
01231               if (i + 3 < NumElts) {
01232                 StoreVal = OutVals[OIdx++];
01233                 if (NeedExtend)
01234                   StoreVal =
01235                       DAG.getNode(ISD::ZERO_EXTEND, dl, MVT::i16, StoreVal);
01236               } else {
01237                 StoreVal = DAG.getUNDEF(EltVT);
01238               }
01239               Ops.push_back(StoreVal);
01240             }
01241 
01242             Ops.push_back(InFlag);
01243 
01244             SDVTList CopyParamVTs = DAG.getVTList(MVT::Other, MVT::Glue);
01245             Chain = DAG.getMemIntrinsicNode(Opc, dl, CopyParamVTs, Ops,
01246                                             MemVT, MachinePointerInfo());
01247             InFlag = Chain.getValue(1);
01248             curOffset += PerStoreOffset;
01249           }
01250         }
01251         ++paramCount;
01252         --OIdx;
01253         continue;
01254       }
01255       // Plain scalar
01256       // for ABI,    declare .param .b<size> .param<n>;
01257       unsigned sz = VT.getSizeInBits();
01258       bool needExtend = false;
01259       if (VT.isInteger()) {
01260         if (sz < 16)
01261           needExtend = true;
01262         if (sz < 32)
01263           sz = 32;
01264       }
01265       SDVTList DeclareParamVTs = DAG.getVTList(MVT::Other, MVT::Glue);
01266       SDValue DeclareParamOps[] = { Chain,
01267                                     DAG.getConstant(paramCount, MVT::i32),
01268                                     DAG.getConstant(sz, MVT::i32),
01269                                     DAG.getConstant(0, MVT::i32), InFlag };
01270       Chain = DAG.getNode(NVPTXISD::DeclareScalarParam, dl, DeclareParamVTs,
01271                           DeclareParamOps);
01272       InFlag = Chain.getValue(1);
01273       SDValue OutV = OutVals[OIdx];
01274       if (needExtend) {
01275         // zext/sext i1 to i16
01276         unsigned opc = ISD::ZERO_EXTEND;
01277         if (Outs[OIdx].Flags.isSExt())
01278           opc = ISD::SIGN_EXTEND;
01279         OutV = DAG.getNode(opc, dl, MVT::i16, OutV);
01280       }
01281       SDVTList CopyParamVTs = DAG.getVTList(MVT::Other, MVT::Glue);
01282       SDValue CopyParamOps[] = { Chain, DAG.getConstant(paramCount, MVT::i32),
01283                                  DAG.getConstant(0, MVT::i32), OutV, InFlag };
01284 
01285       unsigned opcode = NVPTXISD::StoreParam;
01286       if (Outs[OIdx].Flags.isZExt())
01287         opcode = NVPTXISD::StoreParamU32;
01288       else if (Outs[OIdx].Flags.isSExt())
01289         opcode = NVPTXISD::StoreParamS32;
01290       Chain = DAG.getMemIntrinsicNode(opcode, dl, CopyParamVTs, CopyParamOps,
01291                                       VT, MachinePointerInfo());
01292 
01293       InFlag = Chain.getValue(1);
01294       ++paramCount;
01295       continue;
01296     }
01297     // struct or vector
01298     SmallVector<EVT, 16> vtparts;
01299     SmallVector<uint64_t, 16> Offsets;
01300     const PointerType *PTy = dyn_cast<PointerType>(Args[i].Ty);
01301     assert(PTy && "Type of a byval parameter should be pointer");
01302     ComputePTXValueVTs(*this, PTy->getElementType(), vtparts, &Offsets, 0);
01303 
01304     // declare .param .align <align> .b8 .param<n>[<size>];
01305     unsigned sz = Outs[OIdx].Flags.getByValSize();
01306     SDVTList DeclareParamVTs = DAG.getVTList(MVT::Other, MVT::Glue);
01307     unsigned ArgAlign = Outs[OIdx].Flags.getByValAlign();
01308     // The ByValAlign in the Outs[OIdx].Flags is alway set at this point,
01309     // so we don't need to worry about natural alignment or not.
01310     // See TargetLowering::LowerCallTo().
01311     SDValue DeclareParamOps[] = {
01312       Chain, DAG.getConstant(Outs[OIdx].Flags.getByValAlign(), MVT::i32),
01313       DAG.getConstant(paramCount, MVT::i32), DAG.getConstant(sz, MVT::i32),
01314       InFlag
01315     };
01316     Chain = DAG.getNode(NVPTXISD::DeclareParam, dl, DeclareParamVTs,
01317                         DeclareParamOps);
01318     InFlag = Chain.getValue(1);
01319     for (unsigned j = 0, je = vtparts.size(); j != je; ++j) {
01320       EVT elemtype = vtparts[j];
01321       int curOffset = Offsets[j];
01322       unsigned PartAlign = GreatestCommonDivisor64(ArgAlign, curOffset);
01323       SDValue srcAddr =
01324           DAG.getNode(ISD::ADD, dl, getPointerTy(), OutVals[OIdx],
01325                       DAG.getConstant(curOffset, getPointerTy()));
01326       SDValue theVal = DAG.getLoad(elemtype, dl, tempChain, srcAddr,
01327                                    MachinePointerInfo(), false, false, false,
01328                                    PartAlign);
01329       if (elemtype.getSizeInBits() < 16) {
01330         theVal = DAG.getNode(ISD::ANY_EXTEND, dl, MVT::i16, theVal);
01331       }
01332       SDVTList CopyParamVTs = DAG.getVTList(MVT::Other, MVT::Glue);
01333       SDValue CopyParamOps[] = { Chain, DAG.getConstant(paramCount, MVT::i32),
01334                                  DAG.getConstant(curOffset, MVT::i32), theVal,
01335                                  InFlag };
01336       Chain = DAG.getMemIntrinsicNode(NVPTXISD::StoreParam, dl, CopyParamVTs,
01337                                       CopyParamOps, elemtype,
01338                                       MachinePointerInfo());
01339 
01340       InFlag = Chain.getValue(1);
01341     }
01342     ++paramCount;
01343   }
01344 
01345   GlobalAddressSDNode *Func = dyn_cast<GlobalAddressSDNode>(Callee.getNode());
01346   unsigned retAlignment = 0;
01347 
01348   // Handle Result
01349   if (Ins.size() > 0) {
01350     SmallVector<EVT, 16> resvtparts;
01351     ComputeValueVTs(*this, retTy, resvtparts);
01352 
01353     // Declare
01354     //  .param .align 16 .b8 retval0[<size-in-bytes>], or
01355     //  .param .b<size-in-bits> retval0
01356     unsigned resultsz = TD->getTypeAllocSizeInBits(retTy);
01357     // Emit ".param .b<size-in-bits> retval0" instead of byte arrays only for
01358     // these three types to match the logic in
01359     // NVPTXAsmPrinter::printReturnValStr and NVPTXTargetLowering::getPrototype.
01360     // Plus, this behavior is consistent with nvcc's.
01361     if (retTy->isFloatingPointTy() || retTy->isIntegerTy() ||
01362         retTy->isPointerTy()) {
01363       // Scalar needs to be at least 32bit wide
01364       if (resultsz < 32)
01365         resultsz = 32;
01366       SDVTList DeclareRetVTs = DAG.getVTList(MVT::Other, MVT::Glue);
01367       SDValue DeclareRetOps[] = { Chain, DAG.getConstant(1, MVT::i32),
01368                                   DAG.getConstant(resultsz, MVT::i32),
01369                                   DAG.getConstant(0, MVT::i32), InFlag };
01370       Chain = DAG.getNode(NVPTXISD::DeclareRet, dl, DeclareRetVTs,
01371                           DeclareRetOps);
01372       InFlag = Chain.getValue(1);
01373     } else {
01374       retAlignment = getArgumentAlignment(Callee, CS, retTy, 0);
01375       SDVTList DeclareRetVTs = DAG.getVTList(MVT::Other, MVT::Glue);
01376       SDValue DeclareRetOps[] = { Chain,
01377                                   DAG.getConstant(retAlignment, MVT::i32),
01378                                   DAG.getConstant(resultsz / 8, MVT::i32),
01379                                   DAG.getConstant(0, MVT::i32), InFlag };
01380       Chain = DAG.getNode(NVPTXISD::DeclareRetParam, dl, DeclareRetVTs,
01381                           DeclareRetOps);
01382       InFlag = Chain.getValue(1);
01383     }
01384   }
01385 
01386   if (!Func) {
01387     // This is indirect function call case : PTX requires a prototype of the
01388     // form
01389     // proto_0 : .callprototype(.param .b32 _) _ (.param .b32 _);
01390     // to be emitted, and the label has to used as the last arg of call
01391     // instruction.
01392     // The prototype is embedded in a string and put as the operand for a
01393     // CallPrototype SDNode which will print out to the value of the string.
01394     SDVTList ProtoVTs = DAG.getVTList(MVT::Other, MVT::Glue);
01395     std::string Proto = getPrototype(retTy, Args, Outs, retAlignment, CS);
01396     const char *ProtoStr =
01397       nvTM->getManagedStrPool()->getManagedString(Proto.c_str())->c_str();
01398     SDValue ProtoOps[] = {
01399       Chain, DAG.getTargetExternalSymbol(ProtoStr, MVT::i32), InFlag,
01400     };
01401     Chain = DAG.getNode(NVPTXISD::CallPrototype, dl, ProtoVTs, ProtoOps);
01402     InFlag = Chain.getValue(1);
01403   }
01404   // Op to just print "call"
01405   SDVTList PrintCallVTs = DAG.getVTList(MVT::Other, MVT::Glue);
01406   SDValue PrintCallOps[] = {
01407     Chain, DAG.getConstant((Ins.size() == 0) ? 0 : 1, MVT::i32), InFlag
01408   };
01409   Chain = DAG.getNode(Func ? (NVPTXISD::PrintCallUni) : (NVPTXISD::PrintCall),
01410                       dl, PrintCallVTs, PrintCallOps);
01411   InFlag = Chain.getValue(1);
01412 
01413   // Ops to print out the function name
01414   SDVTList CallVoidVTs = DAG.getVTList(MVT::Other, MVT::Glue);
01415   SDValue CallVoidOps[] = { Chain, Callee, InFlag };
01416   Chain = DAG.getNode(NVPTXISD::CallVoid, dl, CallVoidVTs, CallVoidOps);
01417   InFlag = Chain.getValue(1);
01418 
01419   // Ops to print out the param list
01420   SDVTList CallArgBeginVTs = DAG.getVTList(MVT::Other, MVT::Glue);
01421   SDValue CallArgBeginOps[] = { Chain, InFlag };
01422   Chain = DAG.getNode(NVPTXISD::CallArgBegin, dl, CallArgBeginVTs,
01423                       CallArgBeginOps);
01424   InFlag = Chain.getValue(1);
01425 
01426   for (unsigned i = 0, e = paramCount; i != e; ++i) {
01427     unsigned opcode;
01428     if (i == (e - 1))
01429       opcode = NVPTXISD::LastCallArg;
01430     else
01431       opcode = NVPTXISD::CallArg;
01432     SDVTList CallArgVTs = DAG.getVTList(MVT::Other, MVT::Glue);
01433     SDValue CallArgOps[] = { Chain, DAG.getConstant(1, MVT::i32),
01434                              DAG.getConstant(i, MVT::i32), InFlag };
01435     Chain = DAG.getNode(opcode, dl, CallArgVTs, CallArgOps);
01436     InFlag = Chain.getValue(1);
01437   }
01438   SDVTList CallArgEndVTs = DAG.getVTList(MVT::Other, MVT::Glue);
01439   SDValue CallArgEndOps[] = { Chain, DAG.getConstant(Func ? 1 : 0, MVT::i32),
01440                               InFlag };
01441   Chain = DAG.getNode(NVPTXISD::CallArgEnd, dl, CallArgEndVTs, CallArgEndOps);
01442   InFlag = Chain.getValue(1);
01443 
01444   if (!Func) {
01445     SDVTList PrototypeVTs = DAG.getVTList(MVT::Other, MVT::Glue);
01446     SDValue PrototypeOps[] = { Chain, DAG.getConstant(uniqueCallSite, MVT::i32),
01447                                InFlag };
01448     Chain = DAG.getNode(NVPTXISD::Prototype, dl, PrototypeVTs, PrototypeOps);
01449     InFlag = Chain.getValue(1);
01450   }
01451 
01452   // Generate loads from param memory/moves from registers for result
01453   if (Ins.size() > 0) {
01454     if (retTy && retTy->isVectorTy()) {
01455       EVT ObjectVT = getValueType(retTy);
01456       unsigned NumElts = ObjectVT.getVectorNumElements();
01457       EVT EltVT = ObjectVT.getVectorElementType();
01458       assert(STI.getTargetLowering()->getNumRegisters(F->getContext(),
01459                                                       ObjectVT) == NumElts &&
01460              "Vector was not scalarized");
01461       unsigned sz = EltVT.getSizeInBits();
01462       bool needTruncate = sz < 8 ? true : false;
01463 
01464       if (NumElts == 1) {
01465         // Just a simple load
01466         SmallVector<EVT, 4> LoadRetVTs;
01467         if (EltVT == MVT::i1 || EltVT == MVT::i8) {
01468           // If loading i1/i8 result, generate
01469           //   load.b8 i16
01470           //   if i1
01471           //   trunc i16 to i1
01472           LoadRetVTs.push_back(MVT::i16);
01473         } else
01474           LoadRetVTs.push_back(EltVT);
01475         LoadRetVTs.push_back(MVT::Other);
01476         LoadRetVTs.push_back(MVT::Glue);
01477         SDValue LoadRetOps[] = {Chain, DAG.getConstant(1, MVT::i32),
01478                                 DAG.getConstant(0, MVT::i32), InFlag};
01479         SDValue retval = DAG.getMemIntrinsicNode(
01480             NVPTXISD::LoadParam, dl,
01481             DAG.getVTList(LoadRetVTs), LoadRetOps, EltVT, MachinePointerInfo());
01482         Chain = retval.getValue(1);
01483         InFlag = retval.getValue(2);
01484         SDValue Ret0 = retval;
01485         if (needTruncate)
01486           Ret0 = DAG.getNode(ISD::TRUNCATE, dl, EltVT, Ret0);
01487         InVals.push_back(Ret0);
01488       } else if (NumElts == 2) {
01489         // LoadV2
01490         SmallVector<EVT, 4> LoadRetVTs;
01491         if (EltVT == MVT::i1 || EltVT == MVT::i8) {
01492           // If loading i1/i8 result, generate
01493           //   load.b8 i16
01494           //   if i1
01495           //   trunc i16 to i1
01496           LoadRetVTs.push_back(MVT::i16);
01497           LoadRetVTs.push_back(MVT::i16);
01498         } else {
01499           LoadRetVTs.push_back(EltVT);
01500           LoadRetVTs.push_back(EltVT);
01501         }
01502         LoadRetVTs.push_back(MVT::Other);
01503         LoadRetVTs.push_back(MVT::Glue);
01504         SDValue LoadRetOps[] = {Chain, DAG.getConstant(1, MVT::i32),
01505                                 DAG.getConstant(0, MVT::i32), InFlag};
01506         SDValue retval = DAG.getMemIntrinsicNode(
01507             NVPTXISD::LoadParamV2, dl,
01508             DAG.getVTList(LoadRetVTs), LoadRetOps, EltVT, MachinePointerInfo());
01509         Chain = retval.getValue(2);
01510         InFlag = retval.getValue(3);
01511         SDValue Ret0 = retval.getValue(0);
01512         SDValue Ret1 = retval.getValue(1);
01513         if (needTruncate) {
01514           Ret0 = DAG.getNode(ISD::TRUNCATE, dl, MVT::i1, Ret0);
01515           InVals.push_back(Ret0);
01516           Ret1 = DAG.getNode(ISD::TRUNCATE, dl, MVT::i1, Ret1);
01517           InVals.push_back(Ret1);
01518         } else {
01519           InVals.push_back(Ret0);
01520           InVals.push_back(Ret1);
01521         }
01522       } else {
01523         // Split into N LoadV4
01524         unsigned Ofst = 0;
01525         unsigned VecSize = 4;
01526         unsigned Opc = NVPTXISD::LoadParamV4;
01527         if (EltVT.getSizeInBits() == 64) {
01528           VecSize = 2;
01529           Opc = NVPTXISD::LoadParamV2;
01530         }
01531         EVT VecVT = EVT::getVectorVT(F->getContext(), EltVT, VecSize);
01532         for (unsigned i = 0; i < NumElts; i += VecSize) {
01533           SmallVector<EVT, 8> LoadRetVTs;
01534           if (EltVT == MVT::i1 || EltVT == MVT::i8) {
01535             // If loading i1/i8 result, generate
01536             //   load.b8 i16
01537             //   if i1
01538             //   trunc i16 to i1
01539             for (unsigned j = 0; j < VecSize; ++j)
01540               LoadRetVTs.push_back(MVT::i16);
01541           } else {
01542             for (unsigned j = 0; j < VecSize; ++j)
01543               LoadRetVTs.push_back(EltVT);
01544           }
01545           LoadRetVTs.push_back(MVT::Other);
01546           LoadRetVTs.push_back(MVT::Glue);
01547           SDValue LoadRetOps[] = {Chain, DAG.getConstant(1, MVT::i32),
01548                                   DAG.getConstant(Ofst, MVT::i32), InFlag};
01549           SDValue retval = DAG.getMemIntrinsicNode(
01550               Opc, dl, DAG.getVTList(LoadRetVTs),
01551               LoadRetOps, EltVT, MachinePointerInfo());
01552           if (VecSize == 2) {
01553             Chain = retval.getValue(2);
01554             InFlag = retval.getValue(3);
01555           } else {
01556             Chain = retval.getValue(4);
01557             InFlag = retval.getValue(5);
01558           }
01559 
01560           for (unsigned j = 0; j < VecSize; ++j) {
01561             if (i + j >= NumElts)
01562               break;
01563             SDValue Elt = retval.getValue(j);
01564             if (needTruncate)
01565               Elt = DAG.getNode(ISD::TRUNCATE, dl, EltVT, Elt);
01566             InVals.push_back(Elt);
01567           }
01568           Ofst += TD->getTypeAllocSize(VecVT.getTypeForEVT(F->getContext()));
01569         }
01570       }
01571     } else {
01572       SmallVector<EVT, 16> VTs;
01573       SmallVector<uint64_t, 16> Offsets;
01574       ComputePTXValueVTs(*this, retTy, VTs, &Offsets, 0);
01575       assert(VTs.size() == Ins.size() && "Bad value decomposition");
01576       unsigned RetAlign = getArgumentAlignment(Callee, CS, retTy, 0);
01577       for (unsigned i = 0, e = Ins.size(); i != e; ++i) {
01578         unsigned sz = VTs[i].getSizeInBits();
01579         unsigned AlignI = GreatestCommonDivisor64(RetAlign, Offsets[i]);
01580         bool needTruncate = sz < 8 ? true : false;
01581         if (VTs[i].isInteger() && (sz < 8))
01582           sz = 8;
01583 
01584         SmallVector<EVT, 4> LoadRetVTs;
01585         EVT TheLoadType = VTs[i];
01586         if (retTy->isIntegerTy() &&
01587             TD->getTypeAllocSizeInBits(retTy) < 32) {
01588           // This is for integer types only, and specifically not for
01589           // aggregates.
01590           LoadRetVTs.push_back(MVT::i32);
01591           TheLoadType = MVT::i32;
01592         } else if (sz < 16) {
01593           // If loading i1/i8 result, generate
01594           //   load i8 (-> i16)
01595           //   trunc i16 to i1/i8
01596           LoadRetVTs.push_back(MVT::i16);
01597         } else
01598           LoadRetVTs.push_back(Ins[i].VT);
01599         LoadRetVTs.push_back(MVT::Other);
01600         LoadRetVTs.push_back(MVT::Glue);
01601 
01602         SDValue LoadRetOps[] = {Chain, DAG.getConstant(1, MVT::i32),
01603                                 DAG.getConstant(Offsets[i], MVT::i32), InFlag};
01604         SDValue retval = DAG.getMemIntrinsicNode(
01605             NVPTXISD::LoadParam, dl,
01606             DAG.getVTList(LoadRetVTs), LoadRetOps,
01607             TheLoadType, MachinePointerInfo(), AlignI);
01608         Chain = retval.getValue(1);
01609         InFlag = retval.getValue(2);
01610         SDValue Ret0 = retval.getValue(0);
01611         if (needTruncate)
01612           Ret0 = DAG.getNode(ISD::TRUNCATE, dl, Ins[i].VT, Ret0);
01613         InVals.push_back(Ret0);
01614       }
01615     }
01616   }
01617 
01618   Chain = DAG.getCALLSEQ_END(Chain, DAG.getIntPtrConstant(uniqueCallSite, true),
01619                              DAG.getIntPtrConstant(uniqueCallSite + 1, true),
01620                              InFlag, dl);
01621   uniqueCallSite++;
01622 
01623   // set isTailCall to false for now, until we figure out how to express
01624   // tail call optimization in PTX
01625   isTailCall = false;
01626   return Chain;
01627 }
01628 
01629 // By default CONCAT_VECTORS is lowered by ExpandVectorBuildThroughStack()
01630 // (see LegalizeDAG.cpp). This is slow and uses local memory.
01631 // We use extract/insert/build vector just as what LegalizeOp() does in llvm 2.5
01632 SDValue
01633 NVPTXTargetLowering::LowerCONCAT_VECTORS(SDValue Op, SelectionDAG &DAG) const {
01634   SDNode *Node = Op.getNode();
01635   SDLoc dl(Node);
01636   SmallVector<SDValue, 8> Ops;
01637   unsigned NumOperands = Node->getNumOperands();
01638   for (unsigned i = 0; i < NumOperands; ++i) {
01639     SDValue SubOp = Node->getOperand(i);
01640     EVT VVT = SubOp.getNode()->getValueType(0);
01641     EVT EltVT = VVT.getVectorElementType();
01642     unsigned NumSubElem = VVT.getVectorNumElements();
01643     for (unsigned j = 0; j < NumSubElem; ++j) {
01644       Ops.push_back(DAG.getNode(ISD::EXTRACT_VECTOR_ELT, dl, EltVT, SubOp,
01645                                 DAG.getIntPtrConstant(j)));
01646     }
01647   }
01648   return DAG.getNode(ISD::BUILD_VECTOR, dl, Node->getValueType(0), Ops);
01649 }
01650 
01651 /// LowerShiftRightParts - Lower SRL_PARTS, SRA_PARTS, which
01652 /// 1) returns two i32 values and take a 2 x i32 value to shift plus a shift
01653 ///    amount, or
01654 /// 2) returns two i64 values and take a 2 x i64 value to shift plus a shift
01655 ///    amount.
01656 SDValue NVPTXTargetLowering::LowerShiftRightParts(SDValue Op,
01657                                                   SelectionDAG &DAG) const {
01658   assert(Op.getNumOperands() == 3 && "Not a double-shift!");
01659   assert(Op.getOpcode() == ISD::SRA_PARTS || Op.getOpcode() == ISD::SRL_PARTS);
01660 
01661   EVT VT = Op.getValueType();
01662   unsigned VTBits = VT.getSizeInBits();
01663   SDLoc dl(Op);
01664   SDValue ShOpLo = Op.getOperand(0);
01665   SDValue ShOpHi = Op.getOperand(1);
01666   SDValue ShAmt  = Op.getOperand(2);
01667   unsigned Opc = (Op.getOpcode() == ISD::SRA_PARTS) ? ISD::SRA : ISD::SRL;
01668 
01669   if (VTBits == 32 && STI.getSmVersion() >= 35) {
01670 
01671     // For 32bit and sm35, we can use the funnel shift 'shf' instruction.
01672     // {dHi, dLo} = {aHi, aLo} >> Amt
01673     //   dHi = aHi >> Amt
01674     //   dLo = shf.r.clamp aLo, aHi, Amt
01675 
01676     SDValue Hi = DAG.getNode(Opc, dl, VT, ShOpHi, ShAmt);
01677     SDValue Lo = DAG.getNode(NVPTXISD::FUN_SHFR_CLAMP, dl, VT, ShOpLo, ShOpHi,
01678                              ShAmt);
01679 
01680     SDValue Ops[2] = { Lo, Hi };
01681     return DAG.getMergeValues(Ops, dl);
01682   }
01683   else {
01684 
01685     // {dHi, dLo} = {aHi, aLo} >> Amt
01686     // - if (Amt>=size) then
01687     //      dLo = aHi >> (Amt-size)
01688     //      dHi = aHi >> Amt (this is either all 0 or all 1)
01689     //   else
01690     //      dLo = (aLo >>logic Amt) | (aHi << (size-Amt))
01691     //      dHi = aHi >> Amt
01692 
01693     SDValue RevShAmt = DAG.getNode(ISD::SUB, dl, MVT::i32,
01694                                    DAG.getConstant(VTBits, MVT::i32), ShAmt);
01695     SDValue Tmp1 = DAG.getNode(ISD::SRL, dl, VT, ShOpLo, ShAmt);
01696     SDValue ExtraShAmt = DAG.getNode(ISD::SUB, dl, MVT::i32, ShAmt,
01697                                      DAG.getConstant(VTBits, MVT::i32));
01698     SDValue Tmp2 = DAG.getNode(ISD::SHL, dl, VT, ShOpHi, RevShAmt);
01699     SDValue FalseVal = DAG.getNode(ISD::OR, dl, VT, Tmp1, Tmp2);
01700     SDValue TrueVal = DAG.getNode(Opc, dl, VT, ShOpHi, ExtraShAmt);
01701 
01702     SDValue Cmp = DAG.getSetCC(dl, MVT::i1, ShAmt,
01703                                DAG.getConstant(VTBits, MVT::i32), ISD::SETGE);
01704     SDValue Hi = DAG.getNode(Opc, dl, VT, ShOpHi, ShAmt);
01705     SDValue Lo = DAG.getNode(ISD::SELECT, dl, VT, Cmp, TrueVal, FalseVal);
01706 
01707     SDValue Ops[2] = { Lo, Hi };
01708     return DAG.getMergeValues(Ops, dl);
01709   }
01710 }
01711 
01712 /// LowerShiftLeftParts - Lower SHL_PARTS, which
01713 /// 1) returns two i32 values and take a 2 x i32 value to shift plus a shift
01714 ///    amount, or
01715 /// 2) returns two i64 values and take a 2 x i64 value to shift plus a shift
01716 ///    amount.
01717 SDValue NVPTXTargetLowering::LowerShiftLeftParts(SDValue Op,
01718                                                  SelectionDAG &DAG) const {
01719   assert(Op.getNumOperands() == 3 && "Not a double-shift!");
01720   assert(Op.getOpcode() == ISD::SHL_PARTS);
01721 
01722   EVT VT = Op.getValueType();
01723   unsigned VTBits = VT.getSizeInBits();
01724   SDLoc dl(Op);
01725   SDValue ShOpLo = Op.getOperand(0);
01726   SDValue ShOpHi = Op.getOperand(1);
01727   SDValue ShAmt  = Op.getOperand(2);
01728 
01729   if (VTBits == 32 && STI.getSmVersion() >= 35) {
01730 
01731     // For 32bit and sm35, we can use the funnel shift 'shf' instruction.
01732     // {dHi, dLo} = {aHi, aLo} << Amt
01733     //   dHi = shf.l.clamp aLo, aHi, Amt
01734     //   dLo = aLo << Amt
01735 
01736     SDValue Hi = DAG.getNode(NVPTXISD::FUN_SHFL_CLAMP, dl, VT, ShOpLo, ShOpHi,
01737                              ShAmt);
01738     SDValue Lo = DAG.getNode(ISD::SHL, dl, VT, ShOpLo, ShAmt);
01739 
01740     SDValue Ops[2] = { Lo, Hi };
01741     return DAG.getMergeValues(Ops, dl);
01742   }
01743   else {
01744 
01745     // {dHi, dLo} = {aHi, aLo} << Amt
01746     // - if (Amt>=size) then
01747     //      dLo = aLo << Amt (all 0)
01748     //      dLo = aLo << (Amt-size)
01749     //   else
01750     //      dLo = aLo << Amt
01751     //      dHi = (aHi << Amt) | (aLo >> (size-Amt))
01752 
01753     SDValue RevShAmt = DAG.getNode(ISD::SUB, dl, MVT::i32,
01754                                    DAG.getConstant(VTBits, MVT::i32), ShAmt);
01755     SDValue Tmp1 = DAG.getNode(ISD::SHL, dl, VT, ShOpHi, ShAmt);
01756     SDValue ExtraShAmt = DAG.getNode(ISD::SUB, dl, MVT::i32, ShAmt,
01757                                      DAG.getConstant(VTBits, MVT::i32));
01758     SDValue Tmp2 = DAG.getNode(ISD::SRL, dl, VT, ShOpLo, RevShAmt);
01759     SDValue FalseVal = DAG.getNode(ISD::OR, dl, VT, Tmp1, Tmp2);
01760     SDValue TrueVal = DAG.getNode(ISD::SHL, dl, VT, ShOpLo, ExtraShAmt);
01761 
01762     SDValue Cmp = DAG.getSetCC(dl, MVT::i1, ShAmt,
01763                                DAG.getConstant(VTBits, MVT::i32), ISD::SETGE);
01764     SDValue Lo = DAG.getNode(ISD::SHL, dl, VT, ShOpLo, ShAmt);
01765     SDValue Hi = DAG.getNode(ISD::SELECT, dl, VT, Cmp, TrueVal, FalseVal);
01766 
01767     SDValue Ops[2] = { Lo, Hi };
01768     return DAG.getMergeValues(Ops, dl);
01769   }
01770 }
01771 
01772 SDValue
01773 NVPTXTargetLowering::LowerOperation(SDValue Op, SelectionDAG &DAG) const {
01774   switch (Op.getOpcode()) {
01775   case ISD::RETURNADDR:
01776     return SDValue();
01777   case ISD::FRAMEADDR:
01778     return SDValue();
01779   case ISD::GlobalAddress:
01780     return LowerGlobalAddress(Op, DAG);
01781   case ISD::INTRINSIC_W_CHAIN:
01782     return Op;
01783   case ISD::BUILD_VECTOR:
01784   case ISD::EXTRACT_SUBVECTOR:
01785     return Op;
01786   case ISD::CONCAT_VECTORS:
01787     return LowerCONCAT_VECTORS(Op, DAG);
01788   case ISD::STORE:
01789     return LowerSTORE(Op, DAG);
01790   case ISD::LOAD:
01791     return LowerLOAD(Op, DAG);
01792   case ISD::SHL_PARTS:
01793     return LowerShiftLeftParts(Op, DAG);
01794   case ISD::SRA_PARTS:
01795   case ISD::SRL_PARTS:
01796     return LowerShiftRightParts(Op, DAG);
01797   case ISD::SELECT:
01798     return LowerSelect(Op, DAG);
01799   default:
01800     llvm_unreachable("Custom lowering not defined for operation");
01801   }
01802 }
01803 
01804 SDValue NVPTXTargetLowering::LowerSelect(SDValue Op, SelectionDAG &DAG) const {
01805   SDValue Op0 = Op->getOperand(0);
01806   SDValue Op1 = Op->getOperand(1);
01807   SDValue Op2 = Op->getOperand(2);
01808   SDLoc DL(Op.getNode());
01809 
01810   assert(Op.getValueType() == MVT::i1 && "Custom lowering enabled only for i1");
01811 
01812   Op1 = DAG.getNode(ISD::ANY_EXTEND, DL, MVT::i32, Op1);
01813   Op2 = DAG.getNode(ISD::ANY_EXTEND, DL, MVT::i32, Op2);
01814   SDValue Select = DAG.getNode(ISD::SELECT, DL, MVT::i32, Op0, Op1, Op2);
01815   SDValue Trunc = DAG.getNode(ISD::TRUNCATE, DL, MVT::i1, Select);
01816 
01817   return Trunc;
01818 }
01819 
01820 SDValue NVPTXTargetLowering::LowerLOAD(SDValue Op, SelectionDAG &DAG) const {
01821   if (Op.getValueType() == MVT::i1)
01822     return LowerLOADi1(Op, DAG);
01823   else
01824     return SDValue();
01825 }
01826 
01827 // v = ld i1* addr
01828 //   =>
01829 // v1 = ld i8* addr (-> i16)
01830 // v = trunc i16 to i1
01831 SDValue NVPTXTargetLowering::LowerLOADi1(SDValue Op, SelectionDAG &DAG) const {
01832   SDNode *Node = Op.getNode();
01833   LoadSDNode *LD = cast<LoadSDNode>(Node);
01834   SDLoc dl(Node);
01835   assert(LD->getExtensionType() == ISD::NON_EXTLOAD);
01836   assert(Node->getValueType(0) == MVT::i1 &&
01837          "Custom lowering for i1 load only");
01838   SDValue newLD =
01839       DAG.getLoad(MVT::i16, dl, LD->getChain(), LD->getBasePtr(),
01840                   LD->getPointerInfo(), LD->isVolatile(), LD->isNonTemporal(),
01841                   LD->isInvariant(), LD->getAlignment());
01842   SDValue result = DAG.getNode(ISD::TRUNCATE, dl, MVT::i1, newLD);
01843   // The legalizer (the caller) is expecting two values from the legalized
01844   // load, so we build a MergeValues node for it. See ExpandUnalignedLoad()
01845   // in LegalizeDAG.cpp which also uses MergeValues.
01846   SDValue Ops[] = { result, LD->getChain() };
01847   return DAG.getMergeValues(Ops, dl);
01848 }
01849 
01850 SDValue NVPTXTargetLowering::LowerSTORE(SDValue Op, SelectionDAG &DAG) const {
01851   EVT ValVT = Op.getOperand(1).getValueType();
01852   if (ValVT == MVT::i1)
01853     return LowerSTOREi1(Op, DAG);
01854   else if (ValVT.isVector())
01855     return LowerSTOREVector(Op, DAG);
01856   else
01857     return SDValue();
01858 }
01859 
01860 SDValue
01861 NVPTXTargetLowering::LowerSTOREVector(SDValue Op, SelectionDAG &DAG) const {
01862   SDNode *N = Op.getNode();
01863   SDValue Val = N->getOperand(1);
01864   SDLoc DL(N);
01865   EVT ValVT = Val.getValueType();
01866 
01867   if (ValVT.isVector()) {
01868     // We only handle "native" vector sizes for now, e.g. <4 x double> is not
01869     // legal.  We can (and should) split that into 2 stores of <2 x double> here
01870     // but I'm leaving that as a TODO for now.
01871     if (!ValVT.isSimple())
01872       return SDValue();
01873     switch (ValVT.getSimpleVT().SimpleTy) {
01874     default:
01875       return SDValue();
01876     case MVT::v2i8:
01877     case MVT::v2i16:
01878     case MVT::v2i32:
01879     case MVT::v2i64:
01880     case MVT::v2f32:
01881     case MVT::v2f64:
01882     case MVT::v4i8:
01883     case MVT::v4i16:
01884     case MVT::v4i32:
01885     case MVT::v4f32:
01886       // This is a "native" vector type
01887       break;
01888     }
01889 
01890     MemSDNode *MemSD = cast<MemSDNode>(N);
01891     const DataLayout *TD = getDataLayout();
01892 
01893     unsigned Align = MemSD->getAlignment();
01894     unsigned PrefAlign =
01895       TD->getPrefTypeAlignment(ValVT.getTypeForEVT(*DAG.getContext()));
01896     if (Align < PrefAlign) {
01897       // This store is not sufficiently aligned, so bail out and let this vector
01898       // store be scalarized.  Note that we may still be able to emit smaller
01899       // vector stores.  For example, if we are storing a <4 x float> with an
01900       // alignment of 8, this check will fail but the legalizer will try again
01901       // with 2 x <2 x float>, which will succeed with an alignment of 8.
01902       return SDValue();
01903     }
01904 
01905     unsigned Opcode = 0;
01906     EVT EltVT = ValVT.getVectorElementType();
01907     unsigned NumElts = ValVT.getVectorNumElements();
01908 
01909     // Since StoreV2 is a target node, we cannot rely on DAG type legalization.
01910     // Therefore, we must ensure the type is legal.  For i1 and i8, we set the
01911     // stored type to i16 and propagate the "real" type as the memory type.
01912     bool NeedExt = false;
01913     if (EltVT.getSizeInBits() < 16)
01914       NeedExt = true;
01915 
01916     switch (NumElts) {
01917     default:
01918       return SDValue();
01919     case 2:
01920       Opcode = NVPTXISD::StoreV2;
01921       break;
01922     case 4: {
01923       Opcode = NVPTXISD::StoreV4;
01924       break;
01925     }
01926     }
01927 
01928     SmallVector<SDValue, 8> Ops;
01929 
01930     // First is the chain
01931     Ops.push_back(N->getOperand(0));
01932 
01933     // Then the split values
01934     for (unsigned i = 0; i < NumElts; ++i) {
01935       SDValue ExtVal = DAG.getNode(ISD::EXTRACT_VECTOR_ELT, DL, EltVT, Val,
01936                                    DAG.getIntPtrConstant(i));
01937       if (NeedExt)
01938         ExtVal = DAG.getNode(ISD::ANY_EXTEND, DL, MVT::i16, ExtVal);
01939       Ops.push_back(ExtVal);
01940     }
01941 
01942     // Then any remaining arguments
01943     Ops.append(N->op_begin() + 2, N->op_end());
01944 
01945     SDValue NewSt = DAG.getMemIntrinsicNode(
01946         Opcode, DL, DAG.getVTList(MVT::Other), Ops,
01947         MemSD->getMemoryVT(), MemSD->getMemOperand());
01948 
01949     //return DCI.CombineTo(N, NewSt, true);
01950     return NewSt;
01951   }
01952 
01953   return SDValue();
01954 }
01955 
01956 // st i1 v, addr
01957 //    =>
01958 // v1 = zxt v to i16
01959 // st.u8 i16, addr
01960 SDValue NVPTXTargetLowering::LowerSTOREi1(SDValue Op, SelectionDAG &DAG) const {
01961   SDNode *Node = Op.getNode();
01962   SDLoc dl(Node);
01963   StoreSDNode *ST = cast<StoreSDNode>(Node);
01964   SDValue Tmp1 = ST->getChain();
01965   SDValue Tmp2 = ST->getBasePtr();
01966   SDValue Tmp3 = ST->getValue();
01967   assert(Tmp3.getValueType() == MVT::i1 && "Custom lowering for i1 store only");
01968   unsigned Alignment = ST->getAlignment();
01969   bool isVolatile = ST->isVolatile();
01970   bool isNonTemporal = ST->isNonTemporal();
01971   Tmp3 = DAG.getNode(ISD::ZERO_EXTEND, dl, MVT::i16, Tmp3);
01972   SDValue Result = DAG.getTruncStore(Tmp1, dl, Tmp3, Tmp2,
01973                                      ST->getPointerInfo(), MVT::i8, isNonTemporal,
01974                                      isVolatile, Alignment);
01975   return Result;
01976 }
01977 
01978 SDValue NVPTXTargetLowering::getExtSymb(SelectionDAG &DAG, const char *inname,
01979                                         int idx, EVT v) const {
01980   std::string *name = nvTM->getManagedStrPool()->getManagedString(inname);
01981   std::stringstream suffix;
01982   suffix << idx;
01983   *name += suffix.str();
01984   return DAG.getTargetExternalSymbol(name->c_str(), v);
01985 }
01986 
01987 SDValue
01988 NVPTXTargetLowering::getParamSymbol(SelectionDAG &DAG, int idx, EVT v) const {
01989   std::string ParamSym;
01990   raw_string_ostream ParamStr(ParamSym);
01991 
01992   ParamStr << DAG.getMachineFunction().getName() << "_param_" << idx;
01993   ParamStr.flush();
01994 
01995   std::string *SavedStr =
01996     nvTM->getManagedStrPool()->getManagedString(ParamSym.c_str());
01997   return DAG.getTargetExternalSymbol(SavedStr->c_str(), v);
01998 }
01999 
02000 SDValue NVPTXTargetLowering::getParamHelpSymbol(SelectionDAG &DAG, int idx) {
02001   return getExtSymb(DAG, ".HLPPARAM", idx);
02002 }
02003 
02004 // Check to see if the kernel argument is image*_t or sampler_t
02005 
02006 bool llvm::isImageOrSamplerVal(const Value *arg, const Module *context) {
02007   static const char *const specialTypes[] = { "struct._image2d_t",
02008                                               "struct._image3d_t",
02009                                               "struct._sampler_t" };
02010 
02011   const Type *Ty = arg->getType();
02012   const PointerType *PTy = dyn_cast<PointerType>(Ty);
02013 
02014   if (!PTy)
02015     return false;
02016 
02017   if (!context)
02018     return false;
02019 
02020   const StructType *STy = dyn_cast<StructType>(PTy->getElementType());
02021   const std::string TypeName = STy && !STy->isLiteral() ? STy->getName() : "";
02022 
02023   for (int i = 0, e = array_lengthof(specialTypes); i != e; ++i)
02024     if (TypeName == specialTypes[i])
02025       return true;
02026 
02027   return false;
02028 }
02029 
02030 SDValue NVPTXTargetLowering::LowerFormalArguments(
02031     SDValue Chain, CallingConv::ID CallConv, bool isVarArg,
02032     const SmallVectorImpl<ISD::InputArg> &Ins, SDLoc dl, SelectionDAG &DAG,
02033     SmallVectorImpl<SDValue> &InVals) const {
02034   MachineFunction &MF = DAG.getMachineFunction();
02035   const DataLayout *TD = getDataLayout();
02036 
02037   const Function *F = MF.getFunction();
02038   const AttributeSet &PAL = F->getAttributes();
02039   const TargetLowering *TLI = STI.getTargetLowering();
02040 
02041   SDValue Root = DAG.getRoot();
02042   std::vector<SDValue> OutChains;
02043 
02044   bool isKernel = llvm::isKernelFunction(*F);
02045   bool isABI = (STI.getSmVersion() >= 20);
02046   assert(isABI && "Non-ABI compilation is not supported");
02047   if (!isABI)
02048     return Chain;
02049 
02050   std::vector<Type *> argTypes;
02051   std::vector<const Argument *> theArgs;
02052   for (Function::const_arg_iterator I = F->arg_begin(), E = F->arg_end();
02053        I != E; ++I) {
02054     theArgs.push_back(I);
02055     argTypes.push_back(I->getType());
02056   }
02057   // argTypes.size() (or theArgs.size()) and Ins.size() need not match.
02058   // Ins.size() will be larger
02059   //   * if there is an aggregate argument with multiple fields (each field
02060   //     showing up separately in Ins)
02061   //   * if there is a vector argument with more than typical vector-length
02062   //     elements (generally if more than 4) where each vector element is
02063   //     individually present in Ins.
02064   // So a different index should be used for indexing into Ins.
02065   // See similar issue in LowerCall.
02066   unsigned InsIdx = 0;
02067 
02068   int idx = 0;
02069   for (unsigned i = 0, e = theArgs.size(); i != e; ++i, ++idx, ++InsIdx) {
02070     Type *Ty = argTypes[i];
02071 
02072     // If the kernel argument is image*_t or sampler_t, convert it to
02073     // a i32 constant holding the parameter position. This can later
02074     // matched in the AsmPrinter to output the correct mangled name.
02075     if (isImageOrSamplerVal(
02076             theArgs[i],
02077             (theArgs[i]->getParent() ? theArgs[i]->getParent()->getParent()
02078                                      : nullptr))) {
02079       assert(isKernel && "Only kernels can have image/sampler params");
02080       InVals.push_back(DAG.getConstant(i + 1, MVT::i32));
02081       continue;
02082     }
02083 
02084     if (theArgs[i]->use_empty()) {
02085       // argument is dead
02086       if (Ty->isAggregateType()) {
02087         SmallVector<EVT, 16> vtparts;
02088 
02089         ComputePTXValueVTs(*this, Ty, vtparts);
02090         assert(vtparts.size() > 0 && "empty aggregate type not expected");
02091         for (unsigned parti = 0, parte = vtparts.size(); parti != parte;
02092              ++parti) {
02093           InVals.push_back(DAG.getNode(ISD::UNDEF, dl, Ins[InsIdx].VT));
02094           ++InsIdx;
02095         }
02096         if (vtparts.size() > 0)
02097           --InsIdx;
02098         continue;
02099       }
02100       if (Ty->isVectorTy()) {
02101         EVT ObjectVT = getValueType(Ty);
02102         unsigned NumRegs = TLI->getNumRegisters(F->getContext(), ObjectVT);
02103         for (unsigned parti = 0; parti < NumRegs; ++parti) {
02104           InVals.push_back(DAG.getNode(ISD::UNDEF, dl, Ins[InsIdx].VT));
02105           ++InsIdx;
02106         }
02107         if (NumRegs > 0)
02108           --InsIdx;
02109         continue;
02110       }
02111       InVals.push_back(DAG.getNode(ISD::UNDEF, dl, Ins[InsIdx].VT));
02112       continue;
02113     }
02114 
02115     // In the following cases, assign a node order of "idx+1"
02116     // to newly created nodes. The SDNodes for params have to
02117     // appear in the same order as their order of appearance
02118     // in the original function. "idx+1" holds that order.
02119     if (PAL.hasAttribute(i + 1, Attribute::ByVal) == false) {
02120       if (Ty->isAggregateType()) {
02121         SmallVector<EVT, 16> vtparts;
02122         SmallVector<uint64_t, 16> offsets;
02123 
02124         // NOTE: Here, we lose the ability to issue vector loads for vectors
02125         // that are a part of a struct.  This should be investigated in the
02126         // future.
02127         ComputePTXValueVTs(*this, Ty, vtparts, &offsets, 0);
02128         assert(vtparts.size() > 0 && "empty aggregate type not expected");
02129         bool aggregateIsPacked = false;
02130         if (StructType *STy = llvm::dyn_cast<StructType>(Ty))
02131           aggregateIsPacked = STy->isPacked();
02132 
02133         SDValue Arg = getParamSymbol(DAG, idx, getPointerTy());
02134         for (unsigned parti = 0, parte = vtparts.size(); parti != parte;
02135              ++parti) {
02136           EVT partVT = vtparts[parti];
02137           Value *srcValue = Constant::getNullValue(
02138               PointerType::get(partVT.getTypeForEVT(F->getContext()),
02139                                llvm::ADDRESS_SPACE_PARAM));
02140           SDValue srcAddr =
02141               DAG.getNode(ISD::ADD, dl, getPointerTy(), Arg,
02142                           DAG.getConstant(offsets[parti], getPointerTy()));
02143           unsigned partAlign =
02144               aggregateIsPacked ? 1
02145                                 : TD->getABITypeAlignment(
02146                                       partVT.getTypeForEVT(F->getContext()));
02147           SDValue p;
02148           if (Ins[InsIdx].VT.getSizeInBits() > partVT.getSizeInBits()) {
02149             ISD::LoadExtType ExtOp = Ins[InsIdx].Flags.isSExt() ? 
02150                                      ISD::SEXTLOAD : ISD::ZEXTLOAD;
02151             p = DAG.getExtLoad(ExtOp, dl, Ins[InsIdx].VT, Root, srcAddr,
02152                                MachinePointerInfo(srcValue), partVT, false,
02153                                false, false, partAlign);
02154           } else {
02155             p = DAG.getLoad(partVT, dl, Root, srcAddr,
02156                             MachinePointerInfo(srcValue), false, false, false,
02157                             partAlign);
02158           }
02159           if (p.getNode())
02160             p.getNode()->setIROrder(idx + 1);
02161           InVals.push_back(p);
02162           ++InsIdx;
02163         }
02164         if (vtparts.size() > 0)
02165           --InsIdx;
02166         continue;
02167       }
02168       if (Ty->isVectorTy()) {
02169         EVT ObjectVT = getValueType(Ty);
02170         SDValue Arg = getParamSymbol(DAG, idx, getPointerTy());
02171         unsigned NumElts = ObjectVT.getVectorNumElements();
02172         assert(TLI->getNumRegisters(F->getContext(), ObjectVT) == NumElts &&
02173                "Vector was not scalarized");
02174         EVT EltVT = ObjectVT.getVectorElementType();
02175 
02176         // V1 load
02177         // f32 = load ...
02178         if (NumElts == 1) {
02179           // We only have one element, so just directly load it
02180           Value *SrcValue = Constant::getNullValue(PointerType::get(
02181               EltVT.getTypeForEVT(F->getContext()), llvm::ADDRESS_SPACE_PARAM));
02182           SDValue P = DAG.getLoad(
02183               EltVT, dl, Root, Arg, MachinePointerInfo(SrcValue), false,
02184               false, true,
02185               TD->getABITypeAlignment(EltVT.getTypeForEVT(F->getContext())));
02186           if (P.getNode())
02187             P.getNode()->setIROrder(idx + 1);
02188 
02189           if (Ins[InsIdx].VT.getSizeInBits() > EltVT.getSizeInBits())
02190             P = DAG.getNode(ISD::ANY_EXTEND, dl, Ins[InsIdx].VT, P);
02191           InVals.push_back(P);
02192           ++InsIdx;
02193         } else if (NumElts == 2) {
02194           // V2 load
02195           // f32,f32 = load ...
02196           EVT VecVT = EVT::getVectorVT(F->getContext(), EltVT, 2);
02197           Value *SrcValue = Constant::getNullValue(PointerType::get(
02198               VecVT.getTypeForEVT(F->getContext()), llvm::ADDRESS_SPACE_PARAM));
02199           SDValue P = DAG.getLoad(
02200               VecVT, dl, Root, Arg, MachinePointerInfo(SrcValue), false,
02201               false, true,
02202               TD->getABITypeAlignment(VecVT.getTypeForEVT(F->getContext())));
02203           if (P.getNode())
02204             P.getNode()->setIROrder(idx + 1);
02205 
02206           SDValue Elt0 = DAG.getNode(ISD::EXTRACT_VECTOR_ELT, dl, EltVT, P,
02207                                      DAG.getIntPtrConstant(0));
02208           SDValue Elt1 = DAG.getNode(ISD::EXTRACT_VECTOR_ELT, dl, EltVT, P,
02209                                      DAG.getIntPtrConstant(1));
02210 
02211           if (Ins[InsIdx].VT.getSizeInBits() > EltVT.getSizeInBits()) {
02212             Elt0 = DAG.getNode(ISD::ANY_EXTEND, dl, Ins[InsIdx].VT, Elt0);
02213             Elt1 = DAG.getNode(ISD::ANY_EXTEND, dl, Ins[InsIdx].VT, Elt1);
02214           }
02215 
02216           InVals.push_back(Elt0);
02217           InVals.push_back(Elt1);
02218           InsIdx += 2;
02219         } else {
02220           // V4 loads
02221           // We have at least 4 elements (<3 x Ty> expands to 4 elements) and
02222           // the
02223           // vector will be expanded to a power of 2 elements, so we know we can
02224           // always round up to the next multiple of 4 when creating the vector
02225           // loads.
02226           // e.g.  4 elem => 1 ld.v4
02227           //       6 elem => 2 ld.v4
02228           //       8 elem => 2 ld.v4
02229           //      11 elem => 3 ld.v4
02230           unsigned VecSize = 4;
02231           if (EltVT.getSizeInBits() == 64) {
02232             VecSize = 2;
02233           }
02234           EVT VecVT = EVT::getVectorVT(F->getContext(), EltVT, VecSize);
02235           unsigned Ofst = 0;
02236           for (unsigned i = 0; i < NumElts; i += VecSize) {
02237             Value *SrcValue = Constant::getNullValue(
02238                 PointerType::get(VecVT.getTypeForEVT(F->getContext()),
02239                                  llvm::ADDRESS_SPACE_PARAM));
02240             SDValue SrcAddr =
02241                 DAG.getNode(ISD::ADD, dl, getPointerTy(), Arg,
02242                             DAG.getConstant(Ofst, getPointerTy()));
02243             SDValue P = DAG.getLoad(
02244                 VecVT, dl, Root, SrcAddr, MachinePointerInfo(SrcValue), false,
02245                 false, true,
02246                 TD->getABITypeAlignment(VecVT.getTypeForEVT(F->getContext())));
02247             if (P.getNode())
02248               P.getNode()->setIROrder(idx + 1);
02249 
02250             for (unsigned j = 0; j < VecSize; ++j) {
02251               if (i + j >= NumElts)
02252                 break;
02253               SDValue Elt = DAG.getNode(ISD::EXTRACT_VECTOR_ELT, dl, EltVT, P,
02254                                         DAG.getIntPtrConstant(j));
02255               if (Ins[InsIdx].VT.getSizeInBits() > EltVT.getSizeInBits())
02256                 Elt = DAG.getNode(ISD::ANY_EXTEND, dl, Ins[InsIdx].VT, Elt);
02257               InVals.push_back(Elt);
02258             }
02259             Ofst += TD->getTypeAllocSize(VecVT.getTypeForEVT(F->getContext()));
02260           }
02261           InsIdx += NumElts;
02262         }
02263 
02264         if (NumElts > 0)
02265           --InsIdx;
02266         continue;
02267       }
02268       // A plain scalar.
02269       EVT ObjectVT = getValueType(Ty);
02270       // If ABI, load from the param symbol
02271       SDValue Arg = getParamSymbol(DAG, idx, getPointerTy());
02272       Value *srcValue = Constant::getNullValue(PointerType::get(
02273           ObjectVT.getTypeForEVT(F->getContext()), llvm::ADDRESS_SPACE_PARAM));
02274       SDValue p;
02275        if (ObjectVT.getSizeInBits() < Ins[InsIdx].VT.getSizeInBits()) {
02276         ISD::LoadExtType ExtOp = Ins[InsIdx].Flags.isSExt() ? 
02277                                        ISD::SEXTLOAD : ISD::ZEXTLOAD;
02278         p = DAG.getExtLoad(ExtOp, dl, Ins[InsIdx].VT, Root, Arg,
02279                            MachinePointerInfo(srcValue), ObjectVT, false, false,
02280                            false,
02281         TD->getABITypeAlignment(ObjectVT.getTypeForEVT(F->getContext())));
02282       } else {
02283         p = DAG.getLoad(Ins[InsIdx].VT, dl, Root, Arg,
02284                         MachinePointerInfo(srcValue), false, false, false,
02285         TD->getABITypeAlignment(ObjectVT.getTypeForEVT(F->getContext())));
02286       }
02287       if (p.getNode())
02288         p.getNode()->setIROrder(idx + 1);
02289       InVals.push_back(p);
02290       continue;
02291     }
02292 
02293     // Param has ByVal attribute
02294     // Return MoveParam(param symbol).
02295     // Ideally, the param symbol can be returned directly,
02296     // but when SDNode builder decides to use it in a CopyToReg(),
02297     // machine instruction fails because TargetExternalSymbol
02298     // (not lowered) is target dependent, and CopyToReg assumes
02299     // the source is lowered.
02300     EVT ObjectVT = getValueType(Ty);
02301     assert(ObjectVT == Ins[InsIdx].VT &&
02302            "Ins type did not match function type");
02303     SDValue Arg = getParamSymbol(DAG, idx, getPointerTy());
02304     SDValue p = DAG.getNode(NVPTXISD::MoveParam, dl, ObjectVT, Arg);
02305     if (p.getNode())
02306       p.getNode()->setIROrder(idx + 1);
02307     if (isKernel)
02308       InVals.push_back(p);
02309     else {
02310       SDValue p2 = DAG.getNode(
02311           ISD::INTRINSIC_WO_CHAIN, dl, ObjectVT,
02312           DAG.getConstant(Intrinsic::nvvm_ptr_local_to_gen, MVT::i32), p);
02313       InVals.push_back(p2);
02314     }
02315   }
02316 
02317   // Clang will check explicit VarArg and issue error if any. However, Clang
02318   // will let code with
02319   // implicit var arg like f() pass. See bug 617733.
02320   // We treat this case as if the arg list is empty.
02321   // if (F.isVarArg()) {
02322   // assert(0 && "VarArg not supported yet!");
02323   //}
02324 
02325   if (!OutChains.empty())
02326     DAG.setRoot(DAG.getNode(ISD::TokenFactor, dl, MVT::Other, OutChains));
02327 
02328   return Chain;
02329 }
02330 
02331 
02332 SDValue
02333 NVPTXTargetLowering::LowerReturn(SDValue Chain, CallingConv::ID CallConv,
02334                                  bool isVarArg,
02335                                  const SmallVectorImpl<ISD::OutputArg> &Outs,
02336                                  const SmallVectorImpl<SDValue> &OutVals,
02337                                  SDLoc dl, SelectionDAG &DAG) const {
02338   MachineFunction &MF = DAG.getMachineFunction();
02339   const Function *F = MF.getFunction();
02340   Type *RetTy = F->getReturnType();
02341   const DataLayout *TD = getDataLayout();
02342 
02343   bool isABI = (STI.getSmVersion() >= 20);
02344   assert(isABI && "Non-ABI compilation is not supported");
02345   if (!isABI)
02346     return Chain;
02347 
02348   if (VectorType *VTy = dyn_cast<VectorType>(RetTy)) {
02349     // If we have a vector type, the OutVals array will be the scalarized
02350     // components and we have combine them into 1 or more vector stores.
02351     unsigned NumElts = VTy->getNumElements();
02352     assert(NumElts == Outs.size() && "Bad scalarization of return value");
02353 
02354     // const_cast can be removed in later LLVM versions
02355     EVT EltVT = getValueType(RetTy).getVectorElementType();
02356     bool NeedExtend = false;
02357     if (EltVT.getSizeInBits() < 16)
02358       NeedExtend = true;
02359 
02360     // V1 store
02361     if (NumElts == 1) {
02362       SDValue StoreVal = OutVals[0];
02363       // We only have one element, so just directly store it
02364       if (NeedExtend)
02365         StoreVal = DAG.getNode(ISD::ZERO_EXTEND, dl, MVT::i16, StoreVal);
02366       SDValue Ops[] = { Chain, DAG.getConstant(0, MVT::i32), StoreVal };
02367       Chain = DAG.getMemIntrinsicNode(NVPTXISD::StoreRetval, dl,
02368                                       DAG.getVTList(MVT::Other), Ops,
02369                                       EltVT, MachinePointerInfo());
02370 
02371     } else if (NumElts == 2) {
02372       // V2 store
02373       SDValue StoreVal0 = OutVals[0];
02374       SDValue StoreVal1 = OutVals[1];
02375 
02376       if (NeedExtend) {
02377         StoreVal0 = DAG.getNode(ISD::ZERO_EXTEND, dl, MVT::i16, StoreVal0);
02378         StoreVal1 = DAG.getNode(ISD::ZERO_EXTEND, dl, MVT::i16, StoreVal1);
02379       }
02380 
02381       SDValue Ops[] = { Chain, DAG.getConstant(0, MVT::i32), StoreVal0,
02382                         StoreVal1 };
02383       Chain = DAG.getMemIntrinsicNode(NVPTXISD::StoreRetvalV2, dl,
02384                                       DAG.getVTList(MVT::Other), Ops,
02385                                       EltVT, MachinePointerInfo());
02386     } else {
02387       // V4 stores
02388       // We have at least 4 elements (<3 x Ty> expands to 4 elements) and the
02389       // vector will be expanded to a power of 2 elements, so we know we can
02390       // always round up to the next multiple of 4 when creating the vector
02391       // stores.
02392       // e.g.  4 elem => 1 st.v4
02393       //       6 elem => 2 st.v4
02394       //       8 elem => 2 st.v4
02395       //      11 elem => 3 st.v4
02396 
02397       unsigned VecSize = 4;
02398       if (OutVals[0].getValueType().getSizeInBits() == 64)
02399         VecSize = 2;
02400 
02401       unsigned Offset = 0;
02402 
02403       EVT VecVT =
02404           EVT::getVectorVT(F->getContext(), EltVT, VecSize);
02405       unsigned PerStoreOffset =
02406           TD->getTypeAllocSize(VecVT.getTypeForEVT(F->getContext()));
02407 
02408       for (unsigned i = 0; i < NumElts; i += VecSize) {
02409         // Get values
02410         SDValue StoreVal;
02411         SmallVector<SDValue, 8> Ops;
02412         Ops.push_back(Chain);
02413         Ops.push_back(DAG.getConstant(Offset, MVT::i32));
02414         unsigned Opc = NVPTXISD::StoreRetvalV2;
02415         EVT ExtendedVT = (NeedExtend) ? MVT::i16 : OutVals[0].getValueType();
02416 
02417         StoreVal = OutVals[i];
02418         if (NeedExtend)
02419           StoreVal = DAG.getNode(ISD::ZERO_EXTEND, dl, ExtendedVT, StoreVal);
02420         Ops.push_back(StoreVal);
02421 
02422         if (i + 1 < NumElts) {
02423           StoreVal = OutVals[i + 1];
02424           if (NeedExtend)
02425             StoreVal = DAG.getNode(ISD::ZERO_EXTEND, dl, ExtendedVT, StoreVal);
02426         } else {
02427           StoreVal = DAG.getUNDEF(ExtendedVT);
02428         }
02429         Ops.push_back(StoreVal);
02430 
02431         if (VecSize == 4) {
02432           Opc = NVPTXISD::StoreRetvalV4;
02433           if (i + 2 < NumElts) {
02434             StoreVal = OutVals[i + 2];
02435             if (NeedExtend)
02436               StoreVal =
02437                   DAG.getNode(ISD::ZERO_EXTEND, dl, ExtendedVT, StoreVal);
02438           } else {
02439             StoreVal = DAG.getUNDEF(ExtendedVT);
02440           }
02441           Ops.push_back(StoreVal);
02442 
02443           if (i + 3 < NumElts) {
02444             StoreVal = OutVals[i + 3];
02445             if (NeedExtend)
02446               StoreVal =
02447                   DAG.getNode(ISD::ZERO_EXTEND, dl, ExtendedVT, StoreVal);
02448           } else {
02449             StoreVal = DAG.getUNDEF(ExtendedVT);
02450           }
02451           Ops.push_back(StoreVal);
02452         }
02453 
02454         // Chain = DAG.getNode(Opc, dl, MVT::Other, &Ops[0], Ops.size());
02455         Chain =
02456             DAG.getMemIntrinsicNode(Opc, dl, DAG.getVTList(MVT::Other), Ops,
02457                                     EltVT, MachinePointerInfo());
02458         Offset += PerStoreOffset;
02459       }
02460     }
02461   } else {
02462     SmallVector<EVT, 16> ValVTs;
02463     SmallVector<uint64_t, 16> Offsets;
02464     ComputePTXValueVTs(*this, RetTy, ValVTs, &Offsets, 0);
02465     assert(ValVTs.size() == OutVals.size() && "Bad return value decomposition");
02466 
02467     for (unsigned i = 0, e = Outs.size(); i != e; ++i) {
02468       SDValue theVal = OutVals[i];
02469       EVT TheValType = theVal.getValueType();
02470       unsigned numElems = 1;
02471       if (TheValType.isVector())
02472         numElems = TheValType.getVectorNumElements();
02473       for (unsigned j = 0, je = numElems; j != je; ++j) {
02474         SDValue TmpVal = theVal;
02475         if (TheValType.isVector())
02476           TmpVal = DAG.getNode(ISD::EXTRACT_VECTOR_ELT, dl,
02477                                TheValType.getVectorElementType(), TmpVal,
02478                                DAG.getIntPtrConstant(j));
02479         EVT TheStoreType = ValVTs[i];
02480         if (RetTy->isIntegerTy() &&
02481             TD->getTypeAllocSizeInBits(RetTy) < 32) {
02482           // The following zero-extension is for integer types only, and
02483           // specifically not for aggregates.
02484           TmpVal = DAG.getNode(ISD::ZERO_EXTEND, dl, MVT::i32, TmpVal);
02485           TheStoreType = MVT::i32;
02486         }
02487         else if (TmpVal.getValueType().getSizeInBits() < 16)
02488           TmpVal = DAG.getNode(ISD::ANY_EXTEND, dl, MVT::i16, TmpVal);
02489 
02490         SDValue Ops[] = {
02491           Chain,
02492           DAG.getConstant(Offsets[i], MVT::i32),
02493           TmpVal };
02494         Chain = DAG.getMemIntrinsicNode(NVPTXISD::StoreRetval, dl,
02495                                         DAG.getVTList(MVT::Other), Ops,
02496                                         TheStoreType,
02497                                         MachinePointerInfo());
02498       }
02499     }
02500   }
02501 
02502   return DAG.getNode(NVPTXISD::RET_FLAG, dl, MVT::Other, Chain);
02503 }
02504 
02505 
02506 void NVPTXTargetLowering::LowerAsmOperandForConstraint(
02507     SDValue Op, std::string &Constraint, std::vector<SDValue> &Ops,
02508     SelectionDAG &DAG) const {
02509   if (Constraint.length() > 1)
02510     return;
02511   else
02512     TargetLowering::LowerAsmOperandForConstraint(Op, Constraint, Ops, DAG);
02513 }
02514 
02515 // NVPTX suuport vector of legal types of any length in Intrinsics because the
02516 // NVPTX specific type legalizer
02517 // will legalize them to the PTX supported length.
02518 bool NVPTXTargetLowering::isTypeSupportedInIntrinsic(MVT VT) const {
02519   if (isTypeLegal(VT))
02520     return true;
02521   if (VT.isVector()) {
02522     MVT eVT = VT.getVectorElementType();
02523     if (isTypeLegal(eVT))
02524       return true;
02525   }
02526   return false;
02527 }
02528 
02529 static unsigned getOpcForTextureInstr(unsigned Intrinsic) {
02530   switch (Intrinsic) {
02531   default:
02532     return 0;
02533 
02534   case Intrinsic::nvvm_tex_1d_v4f32_s32:
02535     return NVPTXISD::Tex1DFloatS32;
02536   case Intrinsic::nvvm_tex_1d_v4f32_f32:
02537     return NVPTXISD::Tex1DFloatFloat;
02538   case Intrinsic::nvvm_tex_1d_level_v4f32_f32:
02539     return NVPTXISD::Tex1DFloatFloatLevel;
02540   case Intrinsic::nvvm_tex_1d_grad_v4f32_f32:
02541     return NVPTXISD::Tex1DFloatFloatGrad;
02542   case Intrinsic::nvvm_tex_1d_v4s32_s32:
02543     return NVPTXISD::Tex1DS32S32;
02544   case Intrinsic::nvvm_tex_1d_v4s32_f32:
02545     return NVPTXISD::Tex1DS32Float;
02546   case Intrinsic::nvvm_tex_1d_level_v4s32_f32:
02547     return NVPTXISD::Tex1DS32FloatLevel;
02548   case Intrinsic::nvvm_tex_1d_grad_v4s32_f32:
02549     return NVPTXISD::Tex1DS32FloatGrad;
02550   case Intrinsic::nvvm_tex_1d_v4u32_s32:
02551     return NVPTXISD::Tex1DU32S32;
02552   case Intrinsic::nvvm_tex_1d_v4u32_f32:
02553     return NVPTXISD::Tex1DU32Float;
02554   case Intrinsic::nvvm_tex_1d_level_v4u32_f32:
02555     return NVPTXISD::Tex1DU32FloatLevel;
02556   case Intrinsic::nvvm_tex_1d_grad_v4u32_f32:
02557     return NVPTXISD::Tex1DU32FloatGrad;
02558 
02559   case Intrinsic::nvvm_tex_1d_array_v4f32_s32:
02560     return NVPTXISD::Tex1DArrayFloatS32;
02561   case Intrinsic::nvvm_tex_1d_array_v4f32_f32:
02562     return NVPTXISD::Tex1DArrayFloatFloat;
02563   case Intrinsic::nvvm_tex_1d_array_level_v4f32_f32:
02564     return NVPTXISD::Tex1DArrayFloatFloatLevel;
02565   case Intrinsic::nvvm_tex_1d_array_grad_v4f32_f32:
02566     return NVPTXISD::Tex1DArrayFloatFloatGrad;
02567   case Intrinsic::nvvm_tex_1d_array_v4s32_s32:
02568     return NVPTXISD::Tex1DArrayS32S32;
02569   case Intrinsic::nvvm_tex_1d_array_v4s32_f32:
02570     return NVPTXISD::Tex1DArrayS32Float;
02571   case Intrinsic::nvvm_tex_1d_array_level_v4s32_f32:
02572     return NVPTXISD::Tex1DArrayS32FloatLevel;
02573   case Intrinsic::nvvm_tex_1d_array_grad_v4s32_f32:
02574     return NVPTXISD::Tex1DArrayS32FloatGrad;
02575   case Intrinsic::nvvm_tex_1d_array_v4u32_s32:
02576     return NVPTXISD::Tex1DArrayU32S32;
02577   case Intrinsic::nvvm_tex_1d_array_v4u32_f32:
02578     return NVPTXISD::Tex1DArrayU32Float;
02579   case Intrinsic::nvvm_tex_1d_array_level_v4u32_f32:
02580     return NVPTXISD::Tex1DArrayU32FloatLevel;
02581   case Intrinsic::nvvm_tex_1d_array_grad_v4u32_f32:
02582     return NVPTXISD::Tex1DArrayU32FloatGrad;
02583 
02584   case Intrinsic::nvvm_tex_2d_v4f32_s32:
02585     return NVPTXISD::Tex2DFloatS32;
02586   case Intrinsic::nvvm_tex_2d_v4f32_f32:
02587     return NVPTXISD::Tex2DFloatFloat;
02588   case Intrinsic::nvvm_tex_2d_level_v4f32_f32:
02589     return NVPTXISD::Tex2DFloatFloatLevel;
02590   case Intrinsic::nvvm_tex_2d_grad_v4f32_f32:
02591     return NVPTXISD::Tex2DFloatFloatGrad;
02592   case Intrinsic::nvvm_tex_2d_v4s32_s32:
02593     return NVPTXISD::Tex2DS32S32;
02594   case Intrinsic::nvvm_tex_2d_v4s32_f32:
02595     return NVPTXISD::Tex2DS32Float;
02596   case Intrinsic::nvvm_tex_2d_level_v4s32_f32:
02597     return NVPTXISD::Tex2DS32FloatLevel;
02598   case Intrinsic::nvvm_tex_2d_grad_v4s32_f32:
02599     return NVPTXISD::Tex2DS32FloatGrad;
02600   case Intrinsic::nvvm_tex_2d_v4u32_s32:
02601     return NVPTXISD::Tex2DU32S32;
02602   case Intrinsic::nvvm_tex_2d_v4u32_f32:
02603     return NVPTXISD::Tex2DU32Float;
02604   case Intrinsic::nvvm_tex_2d_level_v4u32_f32:
02605     return NVPTXISD::Tex2DU32FloatLevel;
02606   case Intrinsic::nvvm_tex_2d_grad_v4u32_f32:
02607     return NVPTXISD::Tex2DU32FloatGrad;
02608 
02609   case Intrinsic::nvvm_tex_2d_array_v4f32_s32:
02610     return NVPTXISD::Tex2DArrayFloatS32;
02611   case Intrinsic::nvvm_tex_2d_array_v4f32_f32:
02612     return NVPTXISD::Tex2DArrayFloatFloat;
02613   case Intrinsic::nvvm_tex_2d_array_level_v4f32_f32:
02614     return NVPTXISD::Tex2DArrayFloatFloatLevel;
02615   case Intrinsic::nvvm_tex_2d_array_grad_v4f32_f32:
02616     return NVPTXISD::Tex2DArrayFloatFloatGrad;
02617   case Intrinsic::nvvm_tex_2d_array_v4s32_s32:
02618     return NVPTXISD::Tex2DArrayS32S32;
02619   case Intrinsic::nvvm_tex_2d_array_v4s32_f32:
02620     return NVPTXISD::Tex2DArrayS32Float;
02621   case Intrinsic::nvvm_tex_2d_array_level_v4s32_f32:
02622     return NVPTXISD::Tex2DArrayS32FloatLevel;
02623   case Intrinsic::nvvm_tex_2d_array_grad_v4s32_f32:
02624     return NVPTXISD::Tex2DArrayS32FloatGrad;
02625   case Intrinsic::nvvm_tex_2d_array_v4u32_s32:
02626     return NVPTXISD::Tex2DArrayU32S32;
02627   case Intrinsic::nvvm_tex_2d_array_v4u32_f32:
02628     return NVPTXISD::Tex2DArrayU32Float;
02629   case Intrinsic::nvvm_tex_2d_array_level_v4u32_f32:
02630     return NVPTXISD::Tex2DArrayU32FloatLevel;
02631   case Intrinsic::nvvm_tex_2d_array_grad_v4u32_f32:
02632     return NVPTXISD::Tex2DArrayU32FloatGrad;
02633 
02634   case Intrinsic::nvvm_tex_3d_v4f32_s32:
02635     return NVPTXISD::Tex3DFloatS32;
02636   case Intrinsic::nvvm_tex_3d_v4f32_f32:
02637     return NVPTXISD::Tex3DFloatFloat;
02638   case Intrinsic::nvvm_tex_3d_level_v4f32_f32:
02639     return NVPTXISD::Tex3DFloatFloatLevel;
02640   case Intrinsic::nvvm_tex_3d_grad_v4f32_f32:
02641     return NVPTXISD::Tex3DFloatFloatGrad;
02642   case Intrinsic::nvvm_tex_3d_v4s32_s32:
02643     return NVPTXISD::Tex3DS32S32;
02644   case Intrinsic::nvvm_tex_3d_v4s32_f32:
02645     return NVPTXISD::Tex3DS32Float;
02646   case Intrinsic::nvvm_tex_3d_level_v4s32_f32:
02647     return NVPTXISD::Tex3DS32FloatLevel;
02648   case Intrinsic::nvvm_tex_3d_grad_v4s32_f32:
02649     return NVPTXISD::Tex3DS32FloatGrad;
02650   case Intrinsic::nvvm_tex_3d_v4u32_s32:
02651     return NVPTXISD::Tex3DU32S32;
02652   case Intrinsic::nvvm_tex_3d_v4u32_f32:
02653     return NVPTXISD::Tex3DU32Float;
02654   case Intrinsic::nvvm_tex_3d_level_v4u32_f32:
02655     return NVPTXISD::Tex3DU32FloatLevel;
02656   case Intrinsic::nvvm_tex_3d_grad_v4u32_f32:
02657     return NVPTXISD::Tex3DU32FloatGrad;
02658 
02659   case Intrinsic::nvvm_tex_cube_v4f32_f32:
02660     return NVPTXISD::TexCubeFloatFloat;
02661   case Intrinsic::nvvm_tex_cube_level_v4f32_f32:
02662     return NVPTXISD::TexCubeFloatFloatLevel;
02663   case Intrinsic::nvvm_tex_cube_v4s32_f32:
02664     return NVPTXISD::TexCubeS32Float;
02665   case Intrinsic::nvvm_tex_cube_level_v4s32_f32:
02666     return NVPTXISD::TexCubeS32FloatLevel;
02667   case Intrinsic::nvvm_tex_cube_v4u32_f32:
02668     return NVPTXISD::TexCubeU32Float;
02669   case Intrinsic::nvvm_tex_cube_level_v4u32_f32:
02670     return NVPTXISD::TexCubeU32FloatLevel;
02671 
02672   case Intrinsic::nvvm_tex_cube_array_v4f32_f32:
02673     return NVPTXISD::TexCubeArrayFloatFloat;
02674   case Intrinsic::nvvm_tex_cube_array_level_v4f32_f32:
02675     return NVPTXISD::TexCubeArrayFloatFloatLevel;
02676   case Intrinsic::nvvm_tex_cube_array_v4s32_f32:
02677     return NVPTXISD::TexCubeArrayS32Float;
02678   case Intrinsic::nvvm_tex_cube_array_level_v4s32_f32:
02679     return NVPTXISD::TexCubeArrayS32FloatLevel;
02680   case Intrinsic::nvvm_tex_cube_array_v4u32_f32:
02681     return NVPTXISD::TexCubeArrayU32Float;
02682   case Intrinsic::nvvm_tex_cube_array_level_v4u32_f32:
02683     return NVPTXISD::TexCubeArrayU32FloatLevel;
02684 
02685   case Intrinsic::nvvm_tld4_r_2d_v4f32_f32:
02686     return NVPTXISD::Tld4R2DFloatFloat;
02687   case Intrinsic::nvvm_tld4_g_2d_v4f32_f32:
02688     return NVPTXISD::Tld4G2DFloatFloat;
02689   case Intrinsic::nvvm_tld4_b_2d_v4f32_f32:
02690     return NVPTXISD::Tld4B2DFloatFloat;
02691   case Intrinsic::nvvm_tld4_a_2d_v4f32_f32:
02692     return NVPTXISD::Tld4A2DFloatFloat;
02693   case Intrinsic::nvvm_tld4_r_2d_v4s32_f32:
02694     return NVPTXISD::Tld4R2DS64Float;
02695   case Intrinsic::nvvm_tld4_g_2d_v4s32_f32:
02696     return NVPTXISD::Tld4G2DS64Float;
02697   case Intrinsic::nvvm_tld4_b_2d_v4s32_f32:
02698     return NVPTXISD::Tld4B2DS64Float;
02699   case Intrinsic::nvvm_tld4_a_2d_v4s32_f32:
02700     return NVPTXISD::Tld4A2DS64Float;
02701   case Intrinsic::nvvm_tld4_r_2d_v4u32_f32:
02702     return NVPTXISD::Tld4R2DU64Float;
02703   case Intrinsic::nvvm_tld4_g_2d_v4u32_f32:
02704     return NVPTXISD::Tld4G2DU64Float;
02705   case Intrinsic::nvvm_tld4_b_2d_v4u32_f32:
02706     return NVPTXISD::Tld4B2DU64Float;
02707   case Intrinsic::nvvm_tld4_a_2d_v4u32_f32:
02708     return NVPTXISD::Tld4A2DU64Float;
02709 
02710   case Intrinsic::nvvm_tex_unified_1d_v4f32_s32:
02711     return NVPTXISD::TexUnified1DFloatS32;
02712   case Intrinsic::nvvm_tex_unified_1d_v4f32_f32:
02713     return NVPTXISD::TexUnified1DFloatFloat;
02714   case Intrinsic::nvvm_tex_unified_1d_level_v4f32_f32:
02715     return NVPTXISD::TexUnified1DFloatFloatLevel;
02716   case Intrinsic::nvvm_tex_unified_1d_grad_v4f32_f32:
02717     return NVPTXISD::TexUnified1DFloatFloatGrad;
02718   case Intrinsic::nvvm_tex_unified_1d_v4s32_s32:
02719     return NVPTXISD::TexUnified1DS32S32;
02720   case Intrinsic::nvvm_tex_unified_1d_v4s32_f32:
02721     return NVPTXISD::TexUnified1DS32Float;
02722   case Intrinsic::nvvm_tex_unified_1d_level_v4s32_f32:
02723     return NVPTXISD::TexUnified1DS32FloatLevel;
02724   case Intrinsic::nvvm_tex_unified_1d_grad_v4s32_f32:
02725     return NVPTXISD::TexUnified1DS32FloatGrad;
02726   case Intrinsic::nvvm_tex_unified_1d_v4u32_s32:
02727     return NVPTXISD::TexUnified1DU32S32;
02728   case Intrinsic::nvvm_tex_unified_1d_v4u32_f32:
02729     return NVPTXISD::TexUnified1DU32Float;
02730   case Intrinsic::nvvm_tex_unified_1d_level_v4u32_f32:
02731     return NVPTXISD::TexUnified1DU32FloatLevel;
02732   case Intrinsic::nvvm_tex_unified_1d_grad_v4u32_f32:
02733     return NVPTXISD::TexUnified1DU32FloatGrad;
02734 
02735   case Intrinsic::nvvm_tex_unified_1d_array_v4f32_s32:
02736     return NVPTXISD::TexUnified1DArrayFloatS32;
02737   case Intrinsic::nvvm_tex_unified_1d_array_v4f32_f32:
02738     return NVPTXISD::TexUnified1DArrayFloatFloat;
02739   case Intrinsic::nvvm_tex_unified_1d_array_level_v4f32_f32:
02740     return NVPTXISD::TexUnified1DArrayFloatFloatLevel;
02741   case Intrinsic::nvvm_tex_unified_1d_array_grad_v4f32_f32:
02742     return NVPTXISD::TexUnified1DArrayFloatFloatGrad;
02743   case Intrinsic::nvvm_tex_unified_1d_array_v4s32_s32:
02744     return NVPTXISD::TexUnified1DArrayS32S32;
02745   case Intrinsic::nvvm_tex_unified_1d_array_v4s32_f32:
02746     return NVPTXISD::TexUnified1DArrayS32Float;
02747   case Intrinsic::nvvm_tex_unified_1d_array_level_v4s32_f32:
02748     return NVPTXISD::TexUnified1DArrayS32FloatLevel;
02749   case Intrinsic::nvvm_tex_unified_1d_array_grad_v4s32_f32:
02750     return NVPTXISD::TexUnified1DArrayS32FloatGrad;
02751   case Intrinsic::nvvm_tex_unified_1d_array_v4u32_s32:
02752     return NVPTXISD::TexUnified1DArrayU32S32;
02753   case Intrinsic::nvvm_tex_unified_1d_array_v4u32_f32:
02754     return NVPTXISD::TexUnified1DArrayU32Float;
02755   case Intrinsic::nvvm_tex_unified_1d_array_level_v4u32_f32:
02756     return NVPTXISD::TexUnified1DArrayU32FloatLevel;
02757   case Intrinsic::nvvm_tex_unified_1d_array_grad_v4u32_f32:
02758     return NVPTXISD::TexUnified1DArrayU32FloatGrad;
02759 
02760   case Intrinsic::nvvm_tex_unified_2d_v4f32_s32:
02761     return NVPTXISD::TexUnified2DFloatS32;
02762   case Intrinsic::nvvm_tex_unified_2d_v4f32_f32:
02763     return NVPTXISD::TexUnified2DFloatFloat;
02764   case Intrinsic::nvvm_tex_unified_2d_level_v4f32_f32:
02765     return NVPTXISD::TexUnified2DFloatFloatLevel;
02766   case Intrinsic::nvvm_tex_unified_2d_grad_v4f32_f32:
02767     return NVPTXISD::TexUnified2DFloatFloatGrad;
02768   case Intrinsic::nvvm_tex_unified_2d_v4s32_s32:
02769     return NVPTXISD::TexUnified2DS32S32;
02770   case Intrinsic::nvvm_tex_unified_2d_v4s32_f32:
02771     return NVPTXISD::TexUnified2DS32Float;
02772   case Intrinsic::nvvm_tex_unified_2d_level_v4s32_f32:
02773     return NVPTXISD::TexUnified2DS32FloatLevel;
02774   case Intrinsic::nvvm_tex_unified_2d_grad_v4s32_f32:
02775     return NVPTXISD::TexUnified2DS32FloatGrad;
02776   case Intrinsic::nvvm_tex_unified_2d_v4u32_s32:
02777     return NVPTXISD::TexUnified2DU32S32;
02778   case Intrinsic::nvvm_tex_unified_2d_v4u32_f32:
02779     return NVPTXISD::TexUnified2DU32Float;
02780   case Intrinsic::nvvm_tex_unified_2d_level_v4u32_f32:
02781     return NVPTXISD::TexUnified2DU32FloatLevel;
02782   case Intrinsic::nvvm_tex_unified_2d_grad_v4u32_f32:
02783     return NVPTXISD::TexUnified2DU32FloatGrad;
02784 
02785   case Intrinsic::nvvm_tex_unified_2d_array_v4f32_s32:
02786     return NVPTXISD::TexUnified2DArrayFloatS32;
02787   case Intrinsic::nvvm_tex_unified_2d_array_v4f32_f32:
02788     return NVPTXISD::TexUnified2DArrayFloatFloat;
02789   case Intrinsic::nvvm_tex_unified_2d_array_level_v4f32_f32:
02790     return NVPTXISD::TexUnified2DArrayFloatFloatLevel;
02791   case Intrinsic::nvvm_tex_unified_2d_array_grad_v4f32_f32:
02792     return NVPTXISD::TexUnified2DArrayFloatFloatGrad;
02793   case Intrinsic::nvvm_tex_unified_2d_array_v4s32_s32:
02794     return NVPTXISD::TexUnified2DArrayS32S32;
02795   case Intrinsic::nvvm_tex_unified_2d_array_v4s32_f32:
02796     return NVPTXISD::TexUnified2DArrayS32Float;
02797   case Intrinsic::nvvm_tex_unified_2d_array_level_v4s32_f32:
02798     return NVPTXISD::TexUnified2DArrayS32FloatLevel;
02799   case Intrinsic::nvvm_tex_unified_2d_array_grad_v4s32_f32:
02800     return NVPTXISD::TexUnified2DArrayS32FloatGrad;
02801   case Intrinsic::nvvm_tex_unified_2d_array_v4u32_s32:
02802     return NVPTXISD::TexUnified2DArrayU32S32;
02803   case Intrinsic::nvvm_tex_unified_2d_array_v4u32_f32:
02804     return NVPTXISD::TexUnified2DArrayU32Float;
02805   case Intrinsic::nvvm_tex_unified_2d_array_level_v4u32_f32:
02806     return NVPTXISD::TexUnified2DArrayU32FloatLevel;
02807   case Intrinsic::nvvm_tex_unified_2d_array_grad_v4u32_f32:
02808     return NVPTXISD::TexUnified2DArrayU32FloatGrad;
02809 
02810   case Intrinsic::nvvm_tex_unified_3d_v4f32_s32:
02811     return NVPTXISD::TexUnified3DFloatS32;
02812   case Intrinsic::nvvm_tex_unified_3d_v4f32_f32:
02813     return NVPTXISD::TexUnified3DFloatFloat;
02814   case Intrinsic::nvvm_tex_unified_3d_level_v4f32_f32:
02815     return NVPTXISD::TexUnified3DFloatFloatLevel;
02816   case Intrinsic::nvvm_tex_unified_3d_grad_v4f32_f32:
02817     return NVPTXISD::TexUnified3DFloatFloatGrad;
02818   case Intrinsic::nvvm_tex_unified_3d_v4s32_s32:
02819     return NVPTXISD::TexUnified3DS32S32;
02820   case Intrinsic::nvvm_tex_unified_3d_v4s32_f32:
02821     return NVPTXISD::TexUnified3DS32Float;
02822   case Intrinsic::nvvm_tex_unified_3d_level_v4s32_f32:
02823     return NVPTXISD::TexUnified3DS32FloatLevel;
02824   case Intrinsic::nvvm_tex_unified_3d_grad_v4s32_f32:
02825     return NVPTXISD::TexUnified3DS32FloatGrad;
02826   case Intrinsic::nvvm_tex_unified_3d_v4u32_s32:
02827     return NVPTXISD::TexUnified3DU32S32;
02828   case Intrinsic::nvvm_tex_unified_3d_v4u32_f32:
02829     return NVPTXISD::TexUnified3DU32Float;
02830   case Intrinsic::nvvm_tex_unified_3d_level_v4u32_f32:
02831     return NVPTXISD::TexUnified3DU32FloatLevel;
02832   case Intrinsic::nvvm_tex_unified_3d_grad_v4u32_f32:
02833     return NVPTXISD::TexUnified3DU32FloatGrad;
02834 
02835   case Intrinsic::nvvm_tex_unified_cube_v4f32_f32:
02836     return NVPTXISD::TexUnifiedCubeFloatFloat;
02837   case Intrinsic::nvvm_tex_unified_cube_level_v4f32_f32:
02838     return NVPTXISD::TexUnifiedCubeFloatFloatLevel;
02839   case Intrinsic::nvvm_tex_unified_cube_v4s32_f32:
02840     return NVPTXISD::TexUnifiedCubeS32Float;
02841   case Intrinsic::nvvm_tex_unified_cube_level_v4s32_f32:
02842     return NVPTXISD::TexUnifiedCubeS32FloatLevel;
02843   case Intrinsic::nvvm_tex_unified_cube_v4u32_f32:
02844     return NVPTXISD::TexUnifiedCubeU32Float;
02845   case Intrinsic::nvvm_tex_unified_cube_level_v4u32_f32:
02846     return NVPTXISD::TexUnifiedCubeU32FloatLevel;
02847 
02848   case Intrinsic::nvvm_tex_unified_cube_array_v4f32_f32:
02849     return NVPTXISD::TexUnifiedCubeArrayFloatFloat;
02850   case Intrinsic::nvvm_tex_unified_cube_array_level_v4f32_f32:
02851     return NVPTXISD::TexUnifiedCubeArrayFloatFloatLevel;
02852   case Intrinsic::nvvm_tex_unified_cube_array_v4s32_f32:
02853     return NVPTXISD::TexUnifiedCubeArrayS32Float;
02854   case Intrinsic::nvvm_tex_unified_cube_array_level_v4s32_f32:
02855     return NVPTXISD::TexUnifiedCubeArrayS32FloatLevel;
02856   case Intrinsic::nvvm_tex_unified_cube_array_v4u32_f32:
02857     return NVPTXISD::TexUnifiedCubeArrayU32Float;
02858   case Intrinsic::nvvm_tex_unified_cube_array_level_v4u32_f32:
02859     return NVPTXISD::TexUnifiedCubeArrayU32FloatLevel;
02860 
02861   case Intrinsic::nvvm_tld4_unified_r_2d_v4f32_f32:
02862     return NVPTXISD::Tld4UnifiedR2DFloatFloat;
02863   case Intrinsic::nvvm_tld4_unified_g_2d_v4f32_f32:
02864     return NVPTXISD::Tld4UnifiedG2DFloatFloat;
02865   case Intrinsic::nvvm_tld4_unified_b_2d_v4f32_f32:
02866     return NVPTXISD::Tld4UnifiedB2DFloatFloat;
02867   case Intrinsic::nvvm_tld4_unified_a_2d_v4f32_f32:
02868     return NVPTXISD::Tld4UnifiedA2DFloatFloat;
02869   case Intrinsic::nvvm_tld4_unified_r_2d_v4s32_f32:
02870     return NVPTXISD::Tld4UnifiedR2DS64Float;
02871   case Intrinsic::nvvm_tld4_unified_g_2d_v4s32_f32:
02872     return NVPTXISD::Tld4UnifiedG2DS64Float;
02873   case Intrinsic::nvvm_tld4_unified_b_2d_v4s32_f32:
02874     return NVPTXISD::Tld4UnifiedB2DS64Float;
02875   case Intrinsic::nvvm_tld4_unified_a_2d_v4s32_f32:
02876     return NVPTXISD::Tld4UnifiedA2DS64Float;
02877   case Intrinsic::nvvm_tld4_unified_r_2d_v4u32_f32:
02878     return NVPTXISD::Tld4UnifiedR2DU64Float;
02879   case Intrinsic::nvvm_tld4_unified_g_2d_v4u32_f32:
02880     return NVPTXISD::Tld4UnifiedG2DU64Float;
02881   case Intrinsic::nvvm_tld4_unified_b_2d_v4u32_f32:
02882     return NVPTXISD::Tld4UnifiedB2DU64Float;
02883   case Intrinsic::nvvm_tld4_unified_a_2d_v4u32_f32:
02884     return NVPTXISD::Tld4UnifiedA2DU64Float;
02885   }
02886 }
02887 
02888 static unsigned getOpcForSurfaceInstr(unsigned Intrinsic) {
02889   switch (Intrinsic) {
02890   default:
02891     return 0;
02892   case Intrinsic::nvvm_suld_1d_i8_clamp:
02893     return NVPTXISD::Suld1DI8Clamp;
02894   case Intrinsic::nvvm_suld_1d_i16_clamp:
02895     return NVPTXISD::Suld1DI16Clamp;
02896   case Intrinsic::nvvm_suld_1d_i32_clamp:
02897     return NVPTXISD::Suld1DI32Clamp;
02898   case Intrinsic::nvvm_suld_1d_i64_clamp:
02899     return NVPTXISD::Suld1DI64Clamp;
02900   case Intrinsic::nvvm_suld_1d_v2i8_clamp:
02901     return NVPTXISD::Suld1DV2I8Clamp;
02902   case Intrinsic::nvvm_suld_1d_v2i16_clamp:
02903     return NVPTXISD::Suld1DV2I16Clamp;
02904   case Intrinsic::nvvm_suld_1d_v2i32_clamp:
02905     return NVPTXISD::Suld1DV2I32Clamp;
02906   case Intrinsic::nvvm_suld_1d_v2i64_clamp:
02907     return NVPTXISD::Suld1DV2I64Clamp;
02908   case Intrinsic::nvvm_suld_1d_v4i8_clamp:
02909     return NVPTXISD::Suld1DV4I8Clamp;
02910   case Intrinsic::nvvm_suld_1d_v4i16_clamp:
02911     return NVPTXISD::Suld1DV4I16Clamp;
02912   case Intrinsic::nvvm_suld_1d_v4i32_clamp:
02913     return NVPTXISD::Suld1DV4I32Clamp;
02914   case Intrinsic::nvvm_suld_1d_array_i8_clamp:
02915     return NVPTXISD::Suld1DArrayI8Clamp;
02916   case Intrinsic::nvvm_suld_1d_array_i16_clamp:
02917     return NVPTXISD::Suld1DArrayI16Clamp;
02918   case Intrinsic::nvvm_suld_1d_array_i32_clamp:
02919     return NVPTXISD::Suld1DArrayI32Clamp;
02920   case Intrinsic::nvvm_suld_1d_array_i64_clamp:
02921     return NVPTXISD::Suld1DArrayI64Clamp;
02922   case Intrinsic::nvvm_suld_1d_array_v2i8_clamp:
02923     return NVPTXISD::Suld1DArrayV2I8Clamp;
02924   case Intrinsic::nvvm_suld_1d_array_v2i16_clamp:
02925     return NVPTXISD::Suld1DArrayV2I16Clamp;
02926   case Intrinsic::nvvm_suld_1d_array_v2i32_clamp:
02927     return NVPTXISD::Suld1DArrayV2I32Clamp;
02928   case Intrinsic::nvvm_suld_1d_array_v2i64_clamp:
02929     return NVPTXISD::Suld1DArrayV2I64Clamp;
02930   case Intrinsic::nvvm_suld_1d_array_v4i8_clamp:
02931     return NVPTXISD::Suld1DArrayV4I8Clamp;
02932   case Intrinsic::nvvm_suld_1d_array_v4i16_clamp:
02933     return NVPTXISD::Suld1DArrayV4I16Clamp;
02934   case Intrinsic::nvvm_suld_1d_array_v4i32_clamp:
02935     return NVPTXISD::Suld1DArrayV4I32Clamp;
02936   case Intrinsic::nvvm_suld_2d_i8_clamp:
02937     return NVPTXISD::Suld2DI8Clamp;
02938   case Intrinsic::nvvm_suld_2d_i16_clamp:
02939     return NVPTXISD::Suld2DI16Clamp;
02940   case Intrinsic::nvvm_suld_2d_i32_clamp:
02941     return NVPTXISD::Suld2DI32Clamp;
02942   case Intrinsic::nvvm_suld_2d_i64_clamp:
02943     return NVPTXISD::Suld2DI64Clamp;
02944   case Intrinsic::nvvm_suld_2d_v2i8_clamp:
02945     return NVPTXISD::Suld2DV2I8Clamp;
02946   case Intrinsic::nvvm_suld_2d_v2i16_clamp:
02947     return NVPTXISD::Suld2DV2I16Clamp;
02948   case Intrinsic::nvvm_suld_2d_v2i32_clamp:
02949     return NVPTXISD::Suld2DV2I32Clamp;
02950   case Intrinsic::nvvm_suld_2d_v2i64_clamp:
02951     return NVPTXISD::Suld2DV2I64Clamp;
02952   case Intrinsic::nvvm_suld_2d_v4i8_clamp:
02953     return NVPTXISD::Suld2DV4I8Clamp;
02954   case Intrinsic::nvvm_suld_2d_v4i16_clamp:
02955     return NVPTXISD::Suld2DV4I16Clamp;
02956   case Intrinsic::nvvm_suld_2d_v4i32_clamp:
02957     return NVPTXISD::Suld2DV4I32Clamp;
02958   case Intrinsic::nvvm_suld_2d_array_i8_clamp:
02959     return NVPTXISD::Suld2DArrayI8Clamp;
02960   case Intrinsic::nvvm_suld_2d_array_i16_clamp:
02961     return NVPTXISD::Suld2DArrayI16Clamp;
02962   case Intrinsic::nvvm_suld_2d_array_i32_clamp:
02963     return NVPTXISD::Suld2DArrayI32Clamp;
02964   case Intrinsic::nvvm_suld_2d_array_i64_clamp:
02965     return NVPTXISD::Suld2DArrayI64Clamp;
02966   case Intrinsic::nvvm_suld_2d_array_v2i8_clamp:
02967     return NVPTXISD::Suld2DArrayV2I8Clamp;
02968   case Intrinsic::nvvm_suld_2d_array_v2i16_clamp:
02969     return NVPTXISD::Suld2DArrayV2I16Clamp;
02970   case Intrinsic::nvvm_suld_2d_array_v2i32_clamp:
02971     return NVPTXISD::Suld2DArrayV2I32Clamp;
02972   case Intrinsic::nvvm_suld_2d_array_v2i64_clamp:
02973     return NVPTXISD::Suld2DArrayV2I64Clamp;
02974   case Intrinsic::nvvm_suld_2d_array_v4i8_clamp:
02975     return NVPTXISD::Suld2DArrayV4I8Clamp;
02976   case Intrinsic::nvvm_suld_2d_array_v4i16_clamp:
02977     return NVPTXISD::Suld2DArrayV4I16Clamp;
02978   case Intrinsic::nvvm_suld_2d_array_v4i32_clamp:
02979     return NVPTXISD::Suld2DArrayV4I32Clamp;
02980   case Intrinsic::nvvm_suld_3d_i8_clamp:
02981     return NVPTXISD::Suld3DI8Clamp;
02982   case Intrinsic::nvvm_suld_3d_i16_clamp:
02983     return NVPTXISD::Suld3DI16Clamp;
02984   case Intrinsic::nvvm_suld_3d_i32_clamp:
02985     return NVPTXISD::Suld3DI32Clamp;
02986   case Intrinsic::nvvm_suld_3d_i64_clamp:
02987     return NVPTXISD::Suld3DI64Clamp;
02988   case Intrinsic::nvvm_suld_3d_v2i8_clamp:
02989     return NVPTXISD::Suld3DV2I8Clamp;
02990   case Intrinsic::nvvm_suld_3d_v2i16_clamp:
02991     return NVPTXISD::Suld3DV2I16Clamp;
02992   case Intrinsic::nvvm_suld_3d_v2i32_clamp:
02993     return NVPTXISD::Suld3DV2I32Clamp;
02994   case Intrinsic::nvvm_suld_3d_v2i64_clamp:
02995     return NVPTXISD::Suld3DV2I64Clamp;
02996   case Intrinsic::nvvm_suld_3d_v4i8_clamp:
02997     return NVPTXISD::Suld3DV4I8Clamp;
02998   case Intrinsic::nvvm_suld_3d_v4i16_clamp:
02999     return NVPTXISD::Suld3DV4I16Clamp;
03000   case Intrinsic::nvvm_suld_3d_v4i32_clamp:
03001     return NVPTXISD::Suld3DV4I32Clamp;
03002   case Intrinsic::nvvm_suld_1d_i8_trap:
03003     return NVPTXISD::Suld1DI8Trap;
03004   case Intrinsic::nvvm_suld_1d_i16_trap:
03005     return NVPTXISD::Suld1DI16Trap;
03006   case Intrinsic::nvvm_suld_1d_i32_trap:
03007     return NVPTXISD::Suld1DI32Trap;
03008   case Intrinsic::nvvm_suld_1d_i64_trap:
03009     return NVPTXISD::Suld1DI64Trap;
03010   case Intrinsic::nvvm_suld_1d_v2i8_trap:
03011     return NVPTXISD::Suld1DV2I8Trap;
03012   case Intrinsic::nvvm_suld_1d_v2i16_trap:
03013     return NVPTXISD::Suld1DV2I16Trap;
03014   case Intrinsic::nvvm_suld_1d_v2i32_trap:
03015     return NVPTXISD::Suld1DV2I32Trap;
03016   case Intrinsic::nvvm_suld_1d_v2i64_trap:
03017     return NVPTXISD::Suld1DV2I64Trap;
03018   case Intrinsic::nvvm_suld_1d_v4i8_trap:
03019     return NVPTXISD::Suld1DV4I8Trap;
03020   case Intrinsic::nvvm_suld_1d_v4i16_trap:
03021     return NVPTXISD::Suld1DV4I16Trap;
03022   case Intrinsic::nvvm_suld_1d_v4i32_trap:
03023     return NVPTXISD::Suld1DV4I32Trap;
03024   case Intrinsic::nvvm_suld_1d_array_i8_trap:
03025     return NVPTXISD::Suld1DArrayI8Trap;
03026   case Intrinsic::nvvm_suld_1d_array_i16_trap:
03027     return NVPTXISD::Suld1DArrayI16Trap;
03028   case Intrinsic::nvvm_suld_1d_array_i32_trap:
03029     return NVPTXISD::Suld1DArrayI32Trap;
03030   case Intrinsic::nvvm_suld_1d_array_i64_trap:
03031     return NVPTXISD::Suld1DArrayI64Trap;
03032   case Intrinsic::nvvm_suld_1d_array_v2i8_trap:
03033     return NVPTXISD::Suld1DArrayV2I8Trap;
03034   case Intrinsic::nvvm_suld_1d_array_v2i16_trap:
03035     return NVPTXISD::Suld1DArrayV2I16Trap;
03036   case Intrinsic::nvvm_suld_1d_array_v2i32_trap:
03037     return NVPTXISD::Suld1DArrayV2I32Trap;
03038   case Intrinsic::nvvm_suld_1d_array_v2i64_trap:
03039     return NVPTXISD::Suld1DArrayV2I64Trap;
03040   case Intrinsic::nvvm_suld_1d_array_v4i8_trap:
03041     return NVPTXISD::Suld1DArrayV4I8Trap;
03042   case Intrinsic::nvvm_suld_1d_array_v4i16_trap:
03043     return NVPTXISD::Suld1DArrayV4I16Trap;
03044   case Intrinsic::nvvm_suld_1d_array_v4i32_trap:
03045     return NVPTXISD::Suld1DArrayV4I32Trap;
03046   case Intrinsic::nvvm_suld_2d_i8_trap:
03047     return NVPTXISD::Suld2DI8Trap;
03048   case Intrinsic::nvvm_suld_2d_i16_trap:
03049     return NVPTXISD::Suld2DI16Trap;
03050   case Intrinsic::nvvm_suld_2d_i32_trap:
03051     return NVPTXISD::Suld2DI32Trap;
03052   case Intrinsic::nvvm_suld_2d_i64_trap:
03053     return NVPTXISD::Suld2DI64Trap;
03054   case Intrinsic::nvvm_suld_2d_v2i8_trap:
03055     return NVPTXISD::Suld2DV2I8Trap;
03056   case Intrinsic::nvvm_suld_2d_v2i16_trap:
03057     return NVPTXISD::Suld2DV2I16Trap;
03058   case Intrinsic::nvvm_suld_2d_v2i32_trap:
03059     return NVPTXISD::Suld2DV2I32Trap;
03060   case Intrinsic::nvvm_suld_2d_v2i64_trap:
03061     return NVPTXISD::Suld2DV2I64Trap;
03062   case Intrinsic::nvvm_suld_2d_v4i8_trap:
03063     return NVPTXISD::Suld2DV4I8Trap;
03064   case Intrinsic::nvvm_suld_2d_v4i16_trap:
03065     return NVPTXISD::Suld2DV4I16Trap;
03066   case Intrinsic::nvvm_suld_2d_v4i32_trap:
03067     return NVPTXISD::Suld2DV4I32Trap;
03068   case Intrinsic::nvvm_suld_2d_array_i8_trap:
03069     return NVPTXISD::Suld2DArrayI8Trap;
03070   case Intrinsic::nvvm_suld_2d_array_i16_trap:
03071     return NVPTXISD::Suld2DArrayI16Trap;
03072   case Intrinsic::nvvm_suld_2d_array_i32_trap:
03073     return NVPTXISD::Suld2DArrayI32Trap;
03074   case Intrinsic::nvvm_suld_2d_array_i64_trap:
03075     return NVPTXISD::Suld2DArrayI64Trap;
03076   case Intrinsic::nvvm_suld_2d_array_v2i8_trap:
03077     return NVPTXISD::Suld2DArrayV2I8Trap;
03078   case Intrinsic::nvvm_suld_2d_array_v2i16_trap:
03079     return NVPTXISD::Suld2DArrayV2I16Trap;
03080   case Intrinsic::nvvm_suld_2d_array_v2i32_trap:
03081     return NVPTXISD::Suld2DArrayV2I32Trap;
03082   case Intrinsic::nvvm_suld_2d_array_v2i64_trap:
03083     return NVPTXISD::Suld2DArrayV2I64Trap;
03084   case Intrinsic::nvvm_suld_2d_array_v4i8_trap:
03085     return NVPTXISD::Suld2DArrayV4I8Trap;
03086   case Intrinsic::nvvm_suld_2d_array_v4i16_trap:
03087     return NVPTXISD::Suld2DArrayV4I16Trap;
03088   case Intrinsic::nvvm_suld_2d_array_v4i32_trap:
03089     return NVPTXISD::Suld2DArrayV4I32Trap;
03090   case Intrinsic::nvvm_suld_3d_i8_trap:
03091     return NVPTXISD::Suld3DI8Trap;
03092   case Intrinsic::nvvm_suld_3d_i16_trap:
03093     return NVPTXISD::Suld3DI16Trap;
03094   case Intrinsic::nvvm_suld_3d_i32_trap:
03095     return NVPTXISD::Suld3DI32Trap;
03096   case Intrinsic::nvvm_suld_3d_i64_trap:
03097     return NVPTXISD::Suld3DI64Trap;
03098   case Intrinsic::nvvm_suld_3d_v2i8_trap:
03099     return NVPTXISD::Suld3DV2I8Trap;
03100   case Intrinsic::nvvm_suld_3d_v2i16_trap:
03101     return NVPTXISD::Suld3DV2I16Trap;
03102   case Intrinsic::nvvm_suld_3d_v2i32_trap:
03103     return NVPTXISD::Suld3DV2I32Trap;
03104   case Intrinsic::nvvm_suld_3d_v2i64_trap:
03105     return NVPTXISD::Suld3DV2I64Trap;
03106   case Intrinsic::nvvm_suld_3d_v4i8_trap:
03107     return NVPTXISD::Suld3DV4I8Trap;
03108   case Intrinsic::nvvm_suld_3d_v4i16_trap:
03109     return NVPTXISD::Suld3DV4I16Trap;
03110   case Intrinsic::nvvm_suld_3d_v4i32_trap:
03111     return NVPTXISD::Suld3DV4I32Trap;
03112   case Intrinsic::nvvm_suld_1d_i8_zero:
03113     return NVPTXISD::Suld1DI8Zero;
03114   case Intrinsic::nvvm_suld_1d_i16_zero:
03115     return NVPTXISD::Suld1DI16Zero;
03116   case Intrinsic::nvvm_suld_1d_i32_zero:
03117     return NVPTXISD::Suld1DI32Zero;
03118   case Intrinsic::nvvm_suld_1d_i64_zero:
03119     return NVPTXISD::Suld1DI64Zero;
03120   case Intrinsic::nvvm_suld_1d_v2i8_zero:
03121     return NVPTXISD::Suld1DV2I8Zero;
03122   case Intrinsic::nvvm_suld_1d_v2i16_zero:
03123     return NVPTXISD::Suld1DV2I16Zero;
03124   case Intrinsic::nvvm_suld_1d_v2i32_zero:
03125     return NVPTXISD::Suld1DV2I32Zero;
03126   case Intrinsic::nvvm_suld_1d_v2i64_zero:
03127     return NVPTXISD::Suld1DV2I64Zero;
03128   case Intrinsic::nvvm_suld_1d_v4i8_zero:
03129     return NVPTXISD::Suld1DV4I8Zero;
03130   case Intrinsic::nvvm_suld_1d_v4i16_zero:
03131     return NVPTXISD::Suld1DV4I16Zero;
03132   case Intrinsic::nvvm_suld_1d_v4i32_zero:
03133     return NVPTXISD::Suld1DV4I32Zero;
03134   case Intrinsic::nvvm_suld_1d_array_i8_zero:
03135     return NVPTXISD::Suld1DArrayI8Zero;
03136   case Intrinsic::nvvm_suld_1d_array_i16_zero:
03137     return NVPTXISD::Suld1DArrayI16Zero;
03138   case Intrinsic::nvvm_suld_1d_array_i32_zero:
03139     return NVPTXISD::Suld1DArrayI32Zero;
03140   case Intrinsic::nvvm_suld_1d_array_i64_zero:
03141     return NVPTXISD::Suld1DArrayI64Zero;
03142   case Intrinsic::nvvm_suld_1d_array_v2i8_zero:
03143     return NVPTXISD::Suld1DArrayV2I8Zero;
03144   case Intrinsic::nvvm_suld_1d_array_v2i16_zero:
03145     return NVPTXISD::Suld1DArrayV2I16Zero;
03146   case Intrinsic::nvvm_suld_1d_array_v2i32_zero:
03147     return NVPTXISD::Suld1DArrayV2I32Zero;
03148   case Intrinsic::nvvm_suld_1d_array_v2i64_zero:
03149     return NVPTXISD::Suld1DArrayV2I64Zero;
03150   case Intrinsic::nvvm_suld_1d_array_v4i8_zero:
03151     return NVPTXISD::Suld1DArrayV4I8Zero;
03152   case Intrinsic::nvvm_suld_1d_array_v4i16_zero:
03153     return NVPTXISD::Suld1DArrayV4I16Zero;
03154   case Intrinsic::nvvm_suld_1d_array_v4i32_zero:
03155     return NVPTXISD::Suld1DArrayV4I32Zero;
03156   case Intrinsic::nvvm_suld_2d_i8_zero:
03157     return NVPTXISD::Suld2DI8Zero;
03158   case Intrinsic::nvvm_suld_2d_i16_zero:
03159     return NVPTXISD::Suld2DI16Zero;
03160   case Intrinsic::nvvm_suld_2d_i32_zero:
03161     return NVPTXISD::Suld2DI32Zero;
03162   case Intrinsic::nvvm_suld_2d_i64_zero:
03163     return NVPTXISD::Suld2DI64Zero;
03164   case Intrinsic::nvvm_suld_2d_v2i8_zero:
03165     return NVPTXISD::Suld2DV2I8Zero;
03166   case Intrinsic::nvvm_suld_2d_v2i16_zero:
03167     return NVPTXISD::Suld2DV2I16Zero;
03168   case Intrinsic::nvvm_suld_2d_v2i32_zero:
03169     return NVPTXISD::Suld2DV2I32Zero;
03170   case Intrinsic::nvvm_suld_2d_v2i64_zero:
03171     return NVPTXISD::Suld2DV2I64Zero;
03172   case Intrinsic::nvvm_suld_2d_v4i8_zero:
03173     return NVPTXISD::Suld2DV4I8Zero;
03174   case Intrinsic::nvvm_suld_2d_v4i16_zero:
03175     return NVPTXISD::Suld2DV4I16Zero;
03176   case Intrinsic::nvvm_suld_2d_v4i32_zero:
03177     return NVPTXISD::Suld2DV4I32Zero;
03178   case Intrinsic::nvvm_suld_2d_array_i8_zero:
03179     return NVPTXISD::Suld2DArrayI8Zero;
03180   case Intrinsic::nvvm_suld_2d_array_i16_zero:
03181     return NVPTXISD::Suld2DArrayI16Zero;
03182   case Intrinsic::nvvm_suld_2d_array_i32_zero:
03183     return NVPTXISD::Suld2DArrayI32Zero;
03184   case Intrinsic::nvvm_suld_2d_array_i64_zero:
03185     return NVPTXISD::Suld2DArrayI64Zero;
03186   case Intrinsic::nvvm_suld_2d_array_v2i8_zero:
03187     return NVPTXISD::Suld2DArrayV2I8Zero;
03188   case Intrinsic::nvvm_suld_2d_array_v2i16_zero:
03189     return NVPTXISD::Suld2DArrayV2I16Zero;
03190   case Intrinsic::nvvm_suld_2d_array_v2i32_zero:
03191     return NVPTXISD::Suld2DArrayV2I32Zero;
03192   case Intrinsic::nvvm_suld_2d_array_v2i64_zero:
03193     return NVPTXISD::Suld2DArrayV2I64Zero;
03194   case Intrinsic::nvvm_suld_2d_array_v4i8_zero:
03195     return NVPTXISD::Suld2DArrayV4I8Zero;
03196   case Intrinsic::nvvm_suld_2d_array_v4i16_zero:
03197     return NVPTXISD::Suld2DArrayV4I16Zero;
03198   case Intrinsic::nvvm_suld_2d_array_v4i32_zero:
03199     return NVPTXISD::Suld2DArrayV4I32Zero;
03200   case Intrinsic::nvvm_suld_3d_i8_zero:
03201     return NVPTXISD::Suld3DI8Zero;
03202   case Intrinsic::nvvm_suld_3d_i16_zero:
03203     return NVPTXISD::Suld3DI16Zero;
03204   case Intrinsic::nvvm_suld_3d_i32_zero:
03205     return NVPTXISD::Suld3DI32Zero;
03206   case Intrinsic::nvvm_suld_3d_i64_zero:
03207     return NVPTXISD::Suld3DI64Zero;
03208   case Intrinsic::nvvm_suld_3d_v2i8_zero:
03209     return NVPTXISD::Suld3DV2I8Zero;
03210   case Intrinsic::nvvm_suld_3d_v2i16_zero:
03211     return NVPTXISD::Suld3DV2I16Zero;
03212   case Intrinsic::nvvm_suld_3d_v2i32_zero:
03213     return NVPTXISD::Suld3DV2I32Zero;
03214   case Intrinsic::nvvm_suld_3d_v2i64_zero:
03215     return NVPTXISD::Suld3DV2I64Zero;
03216   case Intrinsic::nvvm_suld_3d_v4i8_zero:
03217     return NVPTXISD::Suld3DV4I8Zero;
03218   case Intrinsic::nvvm_suld_3d_v4i16_zero:
03219     return NVPTXISD::Suld3DV4I16Zero;
03220   case Intrinsic::nvvm_suld_3d_v4i32_zero:
03221     return NVPTXISD::Suld3DV4I32Zero;
03222   }
03223 }
03224 
03225 // llvm.ptx.memcpy.const and llvm.ptx.memmove.const need to be modeled as
03226 // TgtMemIntrinsic
03227 // because we need the information that is only available in the "Value" type
03228 // of destination
03229 // pointer. In particular, the address space information.
03230 bool NVPTXTargetLowering::getTgtMemIntrinsic(
03231     IntrinsicInfo &Info, const CallInst &I, unsigned Intrinsic) const {
03232   switch (Intrinsic) {
03233   default:
03234     return false;
03235 
03236   case Intrinsic::nvvm_atomic_load_add_f32:
03237     Info.opc = ISD::INTRINSIC_W_CHAIN;
03238     Info.memVT = MVT::f32;
03239     Info.ptrVal = I.getArgOperand(0);
03240     Info.offset = 0;
03241     Info.vol = 0;
03242     Info.readMem = true;
03243     Info.writeMem = true;
03244     Info.align = 0;
03245     return true;
03246 
03247   case Intrinsic::nvvm_atomic_load_inc_32:
03248   case Intrinsic::nvvm_atomic_load_dec_32:
03249     Info.opc = ISD::INTRINSIC_W_CHAIN;
03250     Info.memVT = MVT::i32;
03251     Info.ptrVal = I.getArgOperand(0);
03252     Info.offset = 0;
03253     Info.vol = 0;
03254     Info.readMem = true;
03255     Info.writeMem = true;
03256     Info.align = 0;
03257     return true;
03258 
03259   case Intrinsic::nvvm_ldu_global_i:
03260   case Intrinsic::nvvm_ldu_global_f:
03261   case Intrinsic::nvvm_ldu_global_p: {
03262 
03263     Info.opc = ISD::INTRINSIC_W_CHAIN;
03264     if (Intrinsic == Intrinsic::nvvm_ldu_global_i)
03265       Info.memVT = getValueType(I.getType());
03266     else if(Intrinsic == Intrinsic::nvvm_ldu_global_p)
03267       Info.memVT = getPointerTy();
03268     else
03269       Info.memVT = getValueType(I.getType());
03270     Info.ptrVal = I.getArgOperand(0);
03271     Info.offset = 0;
03272     Info.vol = 0;
03273     Info.readMem = true;
03274     Info.writeMem = false;
03275     Info.align = cast<ConstantInt>(I.getArgOperand(1))->getZExtValue();
03276 
03277     return true;
03278   }
03279   case Intrinsic::nvvm_ldg_global_i:
03280   case Intrinsic::nvvm_ldg_global_f:
03281   case Intrinsic::nvvm_ldg_global_p: {
03282 
03283     Info.opc = ISD::INTRINSIC_W_CHAIN;
03284     if (Intrinsic == Intrinsic::nvvm_ldg_global_i)
03285       Info.memVT = getValueType(I.getType());
03286     else if(Intrinsic == Intrinsic::nvvm_ldg_global_p)
03287       Info.memVT = getPointerTy();
03288     else
03289       Info.memVT = getValueType(I.getType());
03290     Info.ptrVal = I.getArgOperand(0);
03291     Info.offset = 0;
03292     Info.vol = 0;
03293     Info.readMem = true;
03294     Info.writeMem = false;
03295     Info.align = cast<ConstantInt>(I.getArgOperand(1))->getZExtValue();
03296 
03297     return true;
03298   }
03299 
03300   case Intrinsic::nvvm_tex_1d_v4f32_s32:
03301   case Intrinsic::nvvm_tex_1d_v4f32_f32:
03302   case Intrinsic::nvvm_tex_1d_level_v4f32_f32:
03303   case Intrinsic::nvvm_tex_1d_grad_v4f32_f32:
03304   case Intrinsic::nvvm_tex_1d_array_v4f32_s32:
03305   case Intrinsic::nvvm_tex_1d_array_v4f32_f32:
03306   case Intrinsic::nvvm_tex_1d_array_level_v4f32_f32:
03307   case Intrinsic::nvvm_tex_1d_array_grad_v4f32_f32:
03308   case Intrinsic::nvvm_tex_2d_v4f32_s32:
03309   case Intrinsic::nvvm_tex_2d_v4f32_f32:
03310   case Intrinsic::nvvm_tex_2d_level_v4f32_f32:
03311   case Intrinsic::nvvm_tex_2d_grad_v4f32_f32:
03312   case Intrinsic::nvvm_tex_2d_array_v4f32_s32:
03313   case Intrinsic::nvvm_tex_2d_array_v4f32_f32:
03314   case Intrinsic::nvvm_tex_2d_array_level_v4f32_f32:
03315   case Intrinsic::nvvm_tex_2d_array_grad_v4f32_f32:
03316   case Intrinsic::nvvm_tex_3d_v4f32_s32:
03317   case Intrinsic::nvvm_tex_3d_v4f32_f32:
03318   case Intrinsic::nvvm_tex_3d_level_v4f32_f32:
03319   case Intrinsic::nvvm_tex_3d_grad_v4f32_f32:
03320   case Intrinsic::nvvm_tex_cube_v4f32_f32:
03321   case Intrinsic::nvvm_tex_cube_level_v4f32_f32:
03322   case Intrinsic::nvvm_tex_cube_array_v4f32_f32:
03323   case Intrinsic::nvvm_tex_cube_array_level_v4f32_f32:
03324   case Intrinsic::nvvm_tld4_r_2d_v4f32_f32:
03325   case Intrinsic::nvvm_tld4_g_2d_v4f32_f32:
03326   case Intrinsic::nvvm_tld4_b_2d_v4f32_f32:
03327   case Intrinsic::nvvm_tld4_a_2d_v4f32_f32:
03328   case Intrinsic::nvvm_tex_unified_1d_v4f32_s32:
03329   case Intrinsic::nvvm_tex_unified_1d_v4f32_f32:
03330   case Intrinsic::nvvm_tex_unified_1d_level_v4f32_f32:
03331   case Intrinsic::nvvm_tex_unified_1d_grad_v4f32_f32:
03332   case Intrinsic::nvvm_tex_unified_1d_array_v4f32_s32:
03333   case Intrinsic::nvvm_tex_unified_1d_array_v4f32_f32:
03334   case Intrinsic::nvvm_tex_unified_1d_array_level_v4f32_f32:
03335   case Intrinsic::nvvm_tex_unified_1d_array_grad_v4f32_f32:
03336   case Intrinsic::nvvm_tex_unified_2d_v4f32_s32:
03337   case Intrinsic::nvvm_tex_unified_2d_v4f32_f32:
03338   case Intrinsic::nvvm_tex_unified_2d_level_v4f32_f32:
03339   case Intrinsic::nvvm_tex_unified_2d_grad_v4f32_f32:
03340   case Intrinsic::nvvm_tex_unified_2d_array_v4f32_s32:
03341   case Intrinsic::nvvm_tex_unified_2d_array_v4f32_f32:
03342   case Intrinsic::nvvm_tex_unified_2d_array_level_v4f32_f32:
03343   case Intrinsic::nvvm_tex_unified_2d_array_grad_v4f32_f32:
03344   case Intrinsic::nvvm_tex_unified_3d_v4f32_s32:
03345   case Intrinsic::nvvm_tex_unified_3d_v4f32_f32:
03346   case Intrinsic::nvvm_tex_unified_3d_level_v4f32_f32:
03347   case Intrinsic::nvvm_tex_unified_3d_grad_v4f32_f32:
03348   case Intrinsic::nvvm_tex_unified_cube_v4f32_f32:
03349   case Intrinsic::nvvm_tex_unified_cube_level_v4f32_f32:
03350   case Intrinsic::nvvm_tex_unified_cube_array_v4f32_f32:
03351   case Intrinsic::nvvm_tex_unified_cube_array_level_v4f32_f32:
03352   case Intrinsic::nvvm_tld4_unified_r_2d_v4f32_f32:
03353   case Intrinsic::nvvm_tld4_unified_g_2d_v4f32_f32:
03354   case Intrinsic::nvvm_tld4_unified_b_2d_v4f32_f32:
03355   case Intrinsic::nvvm_tld4_unified_a_2d_v4f32_f32: {
03356     Info.opc = getOpcForTextureInstr(Intrinsic);
03357     Info.memVT = MVT::v4f32;
03358     Info.ptrVal = nullptr;
03359     Info.offset = 0;
03360     Info.vol = 0;
03361     Info.readMem = true;
03362     Info.writeMem = false;
03363     Info.align = 16;
03364     return true;
03365   }
03366   case Intrinsic::nvvm_tex_1d_v4s32_s32:
03367   case Intrinsic::nvvm_tex_1d_v4s32_f32:
03368   case Intrinsic::nvvm_tex_1d_level_v4s32_f32:
03369   case Intrinsic::nvvm_tex_1d_grad_v4s32_f32:
03370   case Intrinsic::nvvm_tex_1d_array_v4s32_s32:
03371   case Intrinsic::nvvm_tex_1d_array_v4s32_f32:
03372   case Intrinsic::nvvm_tex_1d_array_level_v4s32_f32:
03373   case Intrinsic::nvvm_tex_1d_array_grad_v4s32_f32:
03374   case Intrinsic::nvvm_tex_2d_v4s32_s32:
03375   case Intrinsic::nvvm_tex_2d_v4s32_f32:
03376   case Intrinsic::nvvm_tex_2d_level_v4s32_f32:
03377   case Intrinsic::nvvm_tex_2d_grad_v4s32_f32:
03378   case Intrinsic::nvvm_tex_2d_array_v4s32_s32:
03379   case Intrinsic::nvvm_tex_2d_array_v4s32_f32:
03380   case Intrinsic::nvvm_tex_2d_array_level_v4s32_f32:
03381   case Intrinsic::nvvm_tex_2d_array_grad_v4s32_f32:
03382   case Intrinsic::nvvm_tex_3d_v4s32_s32:
03383   case Intrinsic::nvvm_tex_3d_v4s32_f32:
03384   case Intrinsic::nvvm_tex_3d_level_v4s32_f32:
03385   case Intrinsic::nvvm_tex_3d_grad_v4s32_f32:
03386   case Intrinsic::nvvm_tex_cube_v4s32_f32:
03387   case Intrinsic::nvvm_tex_cube_level_v4s32_f32:
03388   case Intrinsic::nvvm_tex_cube_array_v4s32_f32:
03389   case Intrinsic::nvvm_tex_cube_array_level_v4s32_f32:
03390   case Intrinsic::nvvm_tex_cube_v4u32_f32:
03391   case Intrinsic::nvvm_tex_cube_level_v4u32_f32:
03392   case Intrinsic::nvvm_tex_cube_array_v4u32_f32:
03393   case Intrinsic::nvvm_tex_cube_array_level_v4u32_f32:
03394   case Intrinsic::nvvm_tex_1d_v4u32_s32:
03395   case Intrinsic::nvvm_tex_1d_v4u32_f32:
03396   case Intrinsic::nvvm_tex_1d_level_v4u32_f32:
03397   case Intrinsic::nvvm_tex_1d_grad_v4u32_f32:
03398   case Intrinsic::nvvm_tex_1d_array_v4u32_s32:
03399   case Intrinsic::nvvm_tex_1d_array_v4u32_f32:
03400   case Intrinsic::nvvm_tex_1d_array_level_v4u32_f32:
03401   case Intrinsic::nvvm_tex_1d_array_grad_v4u32_f32:
03402   case Intrinsic::nvvm_tex_2d_v4u32_s32:
03403   case Intrinsic::nvvm_tex_2d_v4u32_f32:
03404   case Intrinsic::nvvm_tex_2d_level_v4u32_f32:
03405   case Intrinsic::nvvm_tex_2d_grad_v4u32_f32:
03406   case Intrinsic::nvvm_tex_2d_array_v4u32_s32:
03407   case Intrinsic::nvvm_tex_2d_array_v4u32_f32:
03408   case Intrinsic::nvvm_tex_2d_array_level_v4u32_f32:
03409   case Intrinsic::nvvm_tex_2d_array_grad_v4u32_f32:
03410   case Intrinsic::nvvm_tex_3d_v4u32_s32:
03411   case Intrinsic::nvvm_tex_3d_v4u32_f32:
03412   case Intrinsic::nvvm_tex_3d_level_v4u32_f32:
03413   case Intrinsic::nvvm_tex_3d_grad_v4u32_f32:
03414   case Intrinsic::nvvm_tld4_r_2d_v4s32_f32:
03415   case Intrinsic::nvvm_tld4_g_2d_v4s32_f32:
03416   case Intrinsic::nvvm_tld4_b_2d_v4s32_f32:
03417   case Intrinsic::nvvm_tld4_a_2d_v4s32_f32:
03418   case Intrinsic::nvvm_tld4_r_2d_v4u32_f32:
03419   case Intrinsic::nvvm_tld4_g_2d_v4u32_f32:
03420   case Intrinsic::nvvm_tld4_b_2d_v4u32_f32:
03421   case Intrinsic::nvvm_tld4_a_2d_v4u32_f32:
03422   case Intrinsic::nvvm_tex_unified_1d_v4s32_s32:
03423   case Intrinsic::nvvm_tex_unified_1d_v4s32_f32:
03424   case Intrinsic::nvvm_tex_unified_1d_level_v4s32_f32:
03425   case Intrinsic::nvvm_tex_unified_1d_grad_v4s32_f32:
03426   case Intrinsic::nvvm_tex_unified_1d_array_v4s32_s32:
03427   case Intrinsic::nvvm_tex_unified_1d_array_v4s32_f32:
03428   case Intrinsic::nvvm_tex_unified_1d_array_level_v4s32_f32:
03429   case Intrinsic::nvvm_tex_unified_1d_array_grad_v4s32_f32:
03430   case Intrinsic::nvvm_tex_unified_2d_v4s32_s32:
03431   case Intrinsic::nvvm_tex_unified_2d_v4s32_f32:
03432   case Intrinsic::nvvm_tex_unified_2d_level_v4s32_f32:
03433   case Intrinsic::nvvm_tex_unified_2d_grad_v4s32_f32:
03434   case Intrinsic::nvvm_tex_unified_2d_array_v4s32_s32:
03435   case Intrinsic::nvvm_tex_unified_2d_array_v4s32_f32:
03436   case Intrinsic::nvvm_tex_unified_2d_array_level_v4s32_f32:
03437   case Intrinsic::nvvm_tex_unified_2d_array_grad_v4s32_f32:
03438   case Intrinsic::nvvm_tex_unified_3d_v4s32_s32:
03439   case Intrinsic::nvvm_tex_unified_3d_v4s32_f32:
03440   case Intrinsic::nvvm_tex_unified_3d_level_v4s32_f32:
03441   case Intrinsic::nvvm_tex_unified_3d_grad_v4s32_f32:
03442   case Intrinsic::nvvm_tex_unified_1d_v4u32_s32:
03443   case Intrinsic::nvvm_tex_unified_1d_v4u32_f32:
03444   case Intrinsic::nvvm_tex_unified_1d_level_v4u32_f32:
03445   case Intrinsic::nvvm_tex_unified_1d_grad_v4u32_f32:
03446   case Intrinsic::nvvm_tex_unified_1d_array_v4u32_s32:
03447   case Intrinsic::nvvm_tex_unified_1d_array_v4u32_f32:
03448   case Intrinsic::nvvm_tex_unified_1d_array_level_v4u32_f32:
03449   case Intrinsic::nvvm_tex_unified_1d_array_grad_v4u32_f32:
03450   case Intrinsic::nvvm_tex_unified_2d_v4u32_s32:
03451   case Intrinsic::nvvm_tex_unified_2d_v4u32_f32:
03452   case Intrinsic::nvvm_tex_unified_2d_level_v4u32_f32:
03453   case Intrinsic::nvvm_tex_unified_2d_grad_v4u32_f32:
03454   case Intrinsic::nvvm_tex_unified_2d_array_v4u32_s32:
03455   case Intrinsic::nvvm_tex_unified_2d_array_v4u32_f32:
03456   case Intrinsic::nvvm_tex_unified_2d_array_level_v4u32_f32:
03457   case Intrinsic::nvvm_tex_unified_2d_array_grad_v4u32_f32:
03458   case Intrinsic::nvvm_tex_unified_3d_v4u32_s32:
03459   case Intrinsic::nvvm_tex_unified_3d_v4u32_f32:
03460   case Intrinsic::nvvm_tex_unified_3d_level_v4u32_f32:
03461   case Intrinsic::nvvm_tex_unified_3d_grad_v4u32_f32:
03462   case Intrinsic::nvvm_tex_unified_cube_v4s32_f32:
03463   case Intrinsic::nvvm_tex_unified_cube_level_v4s32_f32:
03464   case Intrinsic::nvvm_tex_unified_cube_array_v4s32_f32:
03465   case Intrinsic::nvvm_tex_unified_cube_array_level_v4s32_f32:
03466   case Intrinsic::nvvm_tex_unified_cube_v4u32_f32:
03467   case Intrinsic::nvvm_tex_unified_cube_level_v4u32_f32:
03468   case Intrinsic::nvvm_tex_unified_cube_array_v4u32_f32:
03469   case Intrinsic::nvvm_tex_unified_cube_array_level_v4u32_f32:
03470   case Intrinsic::nvvm_tld4_unified_r_2d_v4s32_f32:
03471   case Intrinsic::nvvm_tld4_unified_g_2d_v4s32_f32:
03472   case Intrinsic::nvvm_tld4_unified_b_2d_v4s32_f32:
03473   case Intrinsic::nvvm_tld4_unified_a_2d_v4s32_f32:
03474   case Intrinsic::nvvm_tld4_unified_r_2d_v4u32_f32:
03475   case Intrinsic::nvvm_tld4_unified_g_2d_v4u32_f32:
03476   case Intrinsic::nvvm_tld4_unified_b_2d_v4u32_f32:
03477   case Intrinsic::nvvm_tld4_unified_a_2d_v4u32_f32: {
03478     Info.opc = getOpcForTextureInstr(Intrinsic);
03479     Info.memVT = MVT::v4i32;
03480     Info.ptrVal = nullptr;
03481     Info.offset = 0;
03482     Info.vol = 0;
03483     Info.readMem = true;
03484     Info.writeMem = false;
03485     Info.align = 16;
03486     return true;
03487   }
03488   case Intrinsic::nvvm_suld_1d_i8_clamp:
03489   case Intrinsic::nvvm_suld_1d_v2i8_clamp:
03490   case Intrinsic::nvvm_suld_1d_v4i8_clamp:
03491   case Intrinsic::nvvm_suld_1d_array_i8_clamp:
03492   case Intrinsic::nvvm_suld_1d_array_v2i8_clamp:
03493   case Intrinsic::nvvm_suld_1d_array_v4i8_clamp:
03494   case Intrinsic::nvvm_suld_2d_i8_clamp:
03495   case Intrinsic::nvvm_suld_2d_v2i8_clamp:
03496   case Intrinsic::nvvm_suld_2d_v4i8_clamp:
03497   case Intrinsic::nvvm_suld_2d_array_i8_clamp:
03498   case Intrinsic::nvvm_suld_2d_array_v2i8_clamp:
03499   case Intrinsic::nvvm_suld_2d_array_v4i8_clamp:
03500   case Intrinsic::nvvm_suld_3d_i8_clamp:
03501   case Intrinsic::nvvm_suld_3d_v2i8_clamp:
03502   case Intrinsic::nvvm_suld_3d_v4i8_clamp:
03503   case Intrinsic::nvvm_suld_1d_i8_trap:
03504   case Intrinsic::nvvm_suld_1d_v2i8_trap:
03505   case Intrinsic::nvvm_suld_1d_v4i8_trap:
03506   case Intrinsic::nvvm_suld_1d_array_i8_trap:
03507   case Intrinsic::nvvm_suld_1d_array_v2i8_trap:
03508   case Intrinsic::nvvm_suld_1d_array_v4i8_trap:
03509   case Intrinsic::nvvm_suld_2d_i8_trap:
03510   case Intrinsic::nvvm_suld_2d_v2i8_trap:
03511   case Intrinsic::nvvm_suld_2d_v4i8_trap:
03512   case Intrinsic::nvvm_suld_2d_array_i8_trap:
03513   case Intrinsic::nvvm_suld_2d_array_v2i8_trap:
03514   case Intrinsic::nvvm_suld_2d_array_v4i8_trap:
03515   case Intrinsic::nvvm_suld_3d_i8_trap:
03516   case Intrinsic::nvvm_suld_3d_v2i8_trap:
03517   case Intrinsic::nvvm_suld_3d_v4i8_trap:
03518   case Intrinsic::nvvm_suld_1d_i8_zero:
03519   case Intrinsic::nvvm_suld_1d_v2i8_zero:
03520   case Intrinsic::nvvm_suld_1d_v4i8_zero:
03521   case Intrinsic::nvvm_suld_1d_array_i8_zero:
03522   case Intrinsic::nvvm_suld_1d_array_v2i8_zero:
03523   case Intrinsic::nvvm_suld_1d_array_v4i8_zero:
03524   case Intrinsic::nvvm_suld_2d_i8_zero:
03525   case Intrinsic::nvvm_suld_2d_v2i8_zero:
03526   case Intrinsic::nvvm_suld_2d_v4i8_zero:
03527   case Intrinsic::nvvm_suld_2d_array_i8_zero:
03528   case Intrinsic::nvvm_suld_2d_array_v2i8_zero:
03529   case Intrinsic::nvvm_suld_2d_array_v4i8_zero:
03530   case Intrinsic::nvvm_suld_3d_i8_zero:
03531   case Intrinsic::nvvm_suld_3d_v2i8_zero:
03532   case Intrinsic::nvvm_suld_3d_v4i8_zero: {
03533     Info.opc = getOpcForSurfaceInstr(Intrinsic);
03534     Info.memVT = MVT::i8;
03535     Info.ptrVal = nullptr;
03536     Info.offset = 0;
03537     Info.vol = 0;
03538     Info.readMem = true;
03539     Info.writeMem = false;
03540     Info.align = 16;
03541     return true;
03542   }
03543   case Intrinsic::nvvm_suld_1d_i16_clamp:
03544   case Intrinsic::nvvm_suld_1d_v2i16_clamp:
03545   case Intrinsic::nvvm_suld_1d_v4i16_clamp:
03546   case Intrinsic::nvvm_suld_1d_array_i16_clamp:
03547   case Intrinsic::nvvm_suld_1d_array_v2i16_clamp:
03548   case Intrinsic::nvvm_suld_1d_array_v4i16_clamp:
03549   case Intrinsic::nvvm_suld_2d_i16_clamp:
03550   case Intrinsic::nvvm_suld_2d_v2i16_clamp:
03551   case Intrinsic::nvvm_suld_2d_v4i16_clamp:
03552   case Intrinsic::nvvm_suld_2d_array_i16_clamp:
03553   case Intrinsic::nvvm_suld_2d_array_v2i16_clamp:
03554   case Intrinsic::nvvm_suld_2d_array_v4i16_clamp:
03555   case Intrinsic::nvvm_suld_3d_i16_clamp:
03556   case Intrinsic::nvvm_suld_3d_v2i16_clamp:
03557   case Intrinsic::nvvm_suld_3d_v4i16_clamp:
03558   case Intrinsic::nvvm_suld_1d_i16_trap:
03559   case Intrinsic::nvvm_suld_1d_v2i16_trap:
03560   case Intrinsic::nvvm_suld_1d_v4i16_trap:
03561   case Intrinsic::nvvm_suld_1d_array_i16_trap:
03562   case Intrinsic::nvvm_suld_1d_array_v2i16_trap:
03563   case Intrinsic::nvvm_suld_1d_array_v4i16_trap:
03564   case Intrinsic::nvvm_suld_2d_i16_trap:
03565   case Intrinsic::nvvm_suld_2d_v2i16_trap:
03566   case Intrinsic::nvvm_suld_2d_v4i16_trap:
03567   case Intrinsic::nvvm_suld_2d_array_i16_trap:
03568   case Intrinsic::nvvm_suld_2d_array_v2i16_trap:
03569   case Intrinsic::nvvm_suld_2d_array_v4i16_trap:
03570   case Intrinsic::nvvm_suld_3d_i16_trap:
03571   case Intrinsic::nvvm_suld_3d_v2i16_trap:
03572   case Intrinsic::nvvm_suld_3d_v4i16_trap:
03573   case Intrinsic::nvvm_suld_1d_i16_zero:
03574   case Intrinsic::nvvm_suld_1d_v2i16_zero:
03575   case Intrinsic::nvvm_suld_1d_v4i16_zero:
03576   case Intrinsic::nvvm_suld_1d_array_i16_zero:
03577   case Intrinsic::nvvm_suld_1d_array_v2i16_zero:
03578   case Intrinsic::nvvm_suld_1d_array_v4i16_zero:
03579   case Intrinsic::nvvm_suld_2d_i16_zero:
03580   case Intrinsic::nvvm_suld_2d_v2i16_zero:
03581   case Intrinsic::nvvm_suld_2d_v4i16_zero:
03582   case Intrinsic::nvvm_suld_2d_array_i16_zero:
03583   case Intrinsic::nvvm_suld_2d_array_v2i16_zero:
03584   case Intrinsic::nvvm_suld_2d_array_v4i16_zero:
03585   case Intrinsic::nvvm_suld_3d_i16_zero:
03586   case Intrinsic::nvvm_suld_3d_v2i16_zero:
03587   case Intrinsic::nvvm_suld_3d_v4i16_zero: {
03588     Info.opc = getOpcForSurfaceInstr(Intrinsic);
03589     Info.memVT = MVT::i16;
03590     Info.ptrVal = nullptr;
03591     Info.offset = 0;
03592     Info.vol = 0;
03593     Info.readMem = true;
03594     Info.writeMem = false;
03595     Info.align = 16;
03596     return true;
03597   }
03598   case Intrinsic::nvvm_suld_1d_i32_clamp:
03599   case Intrinsic::nvvm_suld_1d_v2i32_clamp:
03600   case Intrinsic::nvvm_suld_1d_v4i32_clamp:
03601   case Intrinsic::nvvm_suld_1d_array_i32_clamp:
03602   case Intrinsic::nvvm_suld_1d_array_v2i32_clamp:
03603   case Intrinsic::nvvm_suld_1d_array_v4i32_clamp:
03604   case Intrinsic::nvvm_suld_2d_i32_clamp:
03605   case Intrinsic::nvvm_suld_2d_v2i32_clamp:
03606   case Intrinsic::nvvm_suld_2d_v4i32_clamp:
03607   case Intrinsic::nvvm_suld_2d_array_i32_clamp:
03608   case Intrinsic::nvvm_suld_2d_array_v2i32_clamp:
03609   case Intrinsic::nvvm_suld_2d_array_v4i32_clamp:
03610   case Intrinsic::nvvm_suld_3d_i32_clamp:
03611   case Intrinsic::nvvm_suld_3d_v2i32_clamp:
03612   case Intrinsic::nvvm_suld_3d_v4i32_clamp:
03613   case Intrinsic::nvvm_suld_1d_i32_trap:
03614   case Intrinsic::nvvm_suld_1d_v2i32_trap:
03615   case Intrinsic::nvvm_suld_1d_v4i32_trap:
03616   case Intrinsic::nvvm_suld_1d_array_i32_trap:
03617   case Intrinsic::nvvm_suld_1d_array_v2i32_trap:
03618   case Intrinsic::nvvm_suld_1d_array_v4i32_trap:
03619   case Intrinsic::nvvm_suld_2d_i32_trap:
03620   case Intrinsic::nvvm_suld_2d_v2i32_trap:
03621   case Intrinsic::nvvm_suld_2d_v4i32_trap:
03622   case Intrinsic::nvvm_suld_2d_array_i32_trap:
03623   case Intrinsic::nvvm_suld_2d_array_v2i32_trap:
03624   case Intrinsic::nvvm_suld_2d_array_v4i32_trap:
03625   case Intrinsic::nvvm_suld_3d_i32_trap:
03626   case Intrinsic::nvvm_suld_3d_v2i32_trap:
03627   case Intrinsic::nvvm_suld_3d_v4i32_trap:
03628   case Intrinsic::nvvm_suld_1d_i32_zero:
03629   case Intrinsic::nvvm_suld_1d_v2i32_zero:
03630   case Intrinsic::nvvm_suld_1d_v4i32_zero:
03631   case Intrinsic::nvvm_suld_1d_array_i32_zero:
03632   case Intrinsic::nvvm_suld_1d_array_v2i32_zero:
03633   case Intrinsic::nvvm_suld_1d_array_v4i32_zero:
03634   case Intrinsic::nvvm_suld_2d_i32_zero:
03635   case Intrinsic::nvvm_suld_2d_v2i32_zero:
03636   case Intrinsic::nvvm_suld_2d_v4i32_zero:
03637   case Intrinsic::nvvm_suld_2d_array_i32_zero:
03638   case Intrinsic::nvvm_suld_2d_array_v2i32_zero:
03639   case Intrinsic::nvvm_suld_2d_array_v4i32_zero:
03640   case Intrinsic::nvvm_suld_3d_i32_zero:
03641   case Intrinsic::nvvm_suld_3d_v2i32_zero:
03642   case Intrinsic::nvvm_suld_3d_v4i32_zero: {
03643     Info.opc = getOpcForSurfaceInstr(Intrinsic);
03644     Info.memVT = MVT::i32;
03645     Info.ptrVal = nullptr;
03646     Info.offset = 0;
03647     Info.vol = 0;
03648     Info.readMem = true;
03649     Info.writeMem = false;
03650     Info.align = 16;
03651     return true;
03652   }
03653   case Intrinsic::nvvm_suld_1d_i64_clamp:
03654   case Intrinsic::nvvm_suld_1d_v2i64_clamp:
03655   case Intrinsic::nvvm_suld_1d_array_i64_clamp:
03656   case Intrinsic::nvvm_suld_1d_array_v2i64_clamp:
03657   case Intrinsic::nvvm_suld_2d_i64_clamp:
03658   case Intrinsic::nvvm_suld_2d_v2i64_clamp:
03659   case Intrinsic::nvvm_suld_2d_array_i64_clamp:
03660   case Intrinsic::nvvm_suld_2d_array_v2i64_clamp:
03661   case Intrinsic::nvvm_suld_3d_i64_clamp:
03662   case Intrinsic::nvvm_suld_3d_v2i64_clamp:
03663   case Intrinsic::nvvm_suld_1d_i64_trap:
03664   case Intrinsic::nvvm_suld_1d_v2i64_trap:
03665   case Intrinsic::nvvm_suld_1d_array_i64_trap:
03666   case Intrinsic::nvvm_suld_1d_array_v2i64_trap:
03667   case Intrinsic::nvvm_suld_2d_i64_trap:
03668   case Intrinsic::nvvm_suld_2d_v2i64_trap:
03669   case Intrinsic::nvvm_suld_2d_array_i64_trap:
03670   case Intrinsic::nvvm_suld_2d_array_v2i64_trap:
03671   case Intrinsic::nvvm_suld_3d_i64_trap:
03672   case Intrinsic::nvvm_suld_3d_v2i64_trap:
03673   case Intrinsic::nvvm_suld_1d_i64_zero:
03674   case Intrinsic::nvvm_suld_1d_v2i64_zero:
03675   case Intrinsic::nvvm_suld_1d_array_i64_zero:
03676   case Intrinsic::nvvm_suld_1d_array_v2i64_zero:
03677   case Intrinsic::nvvm_suld_2d_i64_zero:
03678   case Intrinsic::nvvm_suld_2d_v2i64_zero:
03679   case Intrinsic::nvvm_suld_2d_array_i64_zero:
03680   case Intrinsic::nvvm_suld_2d_array_v2i64_zero:
03681   case Intrinsic::nvvm_suld_3d_i64_zero:
03682   case Intrinsic::nvvm_suld_3d_v2i64_zero: {
03683     Info.opc = getOpcForSurfaceInstr(Intrinsic);
03684     Info.memVT = MVT::i64;
03685     Info.ptrVal = nullptr;
03686     Info.offset = 0;
03687     Info.vol = 0;
03688     Info.readMem = true;
03689     Info.writeMem = false;
03690     Info.align = 16;
03691     return true;
03692   }
03693   }
03694   return false;
03695 }
03696 
03697 /// isLegalAddressingMode - Return true if the addressing mode represented
03698 /// by AM is legal for this target, for a load/store of the specified type.
03699 /// Used to guide target specific optimizations, like loop strength reduction
03700 /// (LoopStrengthReduce.cpp) and memory optimization for address mode
03701 /// (CodeGenPrepare.cpp)
03702 bool NVPTXTargetLowering::isLegalAddressingMode(const AddrMode &AM,
03703                                                 Type *Ty) const {
03704 
03705   // AddrMode - This represents an addressing mode of:
03706   //    BaseGV + BaseOffs + BaseReg + Scale*ScaleReg
03707   //
03708   // The legal address modes are
03709   // - [avar]
03710   // - [areg]
03711   // - [areg+immoff]
03712   // - [immAddr]
03713 
03714   if (AM.BaseGV) {
03715     if (AM.BaseOffs || AM.HasBaseReg || AM.Scale)
03716       return false;
03717     return true;
03718   }
03719 
03720   switch (AM.Scale) {
03721   case 0: // "r", "r+i" or "i" is allowed
03722     break;
03723   case 1:
03724     if (AM.HasBaseReg) // "r+r+i" or "r+r" is not allowed.
03725       return false;
03726     // Otherwise we have r+i.
03727     break;
03728   default:
03729     // No scale > 1 is allowed
03730     return false;
03731   }
03732   return true;
03733 }
03734 
03735 //===----------------------------------------------------------------------===//
03736 //                         NVPTX Inline Assembly Support
03737 //===----------------------------------------------------------------------===//
03738 
03739 /// getConstraintType - Given a constraint letter, return the type of
03740 /// constraint it is for this target.
03741 NVPTXTargetLowering::ConstraintType
03742 NVPTXTargetLowering::getConstraintType(const std::string &Constraint) const {
03743   if (Constraint.size() == 1) {
03744     switch (Constraint[0]) {
03745     default:
03746       break;
03747     case 'b':
03748     case 'r':
03749     case 'h':
03750     case 'c':
03751     case 'l':
03752     case 'f':
03753     case 'd':
03754     case '0':
03755     case 'N':
03756       return C_RegisterClass;
03757     }
03758   }
03759   return TargetLowering::getConstraintType(Constraint);
03760 }
03761 
03762 std::pair<unsigned, const TargetRegisterClass *>
03763 NVPTXTargetLowering::getRegForInlineAsmConstraint(const TargetRegisterInfo *TRI,
03764                                                   const std::string &Constraint,
03765                                                   MVT VT) const {
03766   if (Constraint.size() == 1) {
03767     switch (Constraint[0]) {
03768     case 'b':
03769       return std::make_pair(0U, &NVPTX::Int1RegsRegClass);
03770     case 'c':
03771       return std::make_pair(0U, &NVPTX::Int16RegsRegClass);
03772     case 'h':
03773       return std::make_pair(0U, &NVPTX::Int16RegsRegClass);
03774     case 'r':
03775       return std::make_pair(0U, &NVPTX::Int32RegsRegClass);
03776     case 'l':
03777     case 'N':
03778       return std::make_pair(0U, &NVPTX::Int64RegsRegClass);
03779     case 'f':
03780       return std::make_pair(0U, &NVPTX::Float32RegsRegClass);
03781     case 'd':
03782       return std::make_pair(0U, &NVPTX::Float64RegsRegClass);
03783     }
03784   }
03785   return TargetLowering::getRegForInlineAsmConstraint(TRI, Constraint, VT);
03786 }
03787 
03788 /// getFunctionAlignment - Return the Log2 alignment of this function.
03789 unsigned NVPTXTargetLowering::getFunctionAlignment(const Function *) const {
03790   return 4;
03791 }
03792 
03793 //===----------------------------------------------------------------------===//
03794 //                         NVPTX DAG Combining
03795 //===----------------------------------------------------------------------===//
03796 
03797 bool NVPTXTargetLowering::allowFMA(MachineFunction &MF,
03798                                    CodeGenOpt::Level OptLevel) const {
03799   const Function *F = MF.getFunction();
03800   const TargetOptions &TO = MF.getTarget().Options;
03801 
03802   // Always honor command-line argument
03803   if (FMAContractLevelOpt.getNumOccurrences() > 0) {
03804     return FMAContractLevelOpt > 0;
03805   } else if (OptLevel == 0) {
03806     // Do not contract if we're not optimizing the code
03807     return false;
03808   } else if (TO.AllowFPOpFusion == FPOpFusion::Fast || TO.UnsafeFPMath) {
03809     // Honor TargetOptions flags that explicitly say fusion is okay
03810     return true;
03811   } else if (F->hasFnAttribute("unsafe-fp-math")) {
03812     // Check for unsafe-fp-math=true coming from Clang
03813     Attribute Attr = F->getFnAttribute("unsafe-fp-math");
03814     StringRef Val = Attr.getValueAsString();
03815     if (Val == "true")
03816       return true;
03817   }
03818 
03819   // We did not have a clear indication that fusion is allowed, so assume not
03820   return false;
03821 }
03822 
03823 /// PerformADDCombineWithOperands - Try DAG combinations for an ADD with
03824 /// operands N0 and N1.  This is a helper for PerformADDCombine that is
03825 /// called with the default operands, and if that fails, with commuted
03826 /// operands.
03827 static SDValue PerformADDCombineWithOperands(SDNode *N, SDValue N0, SDValue N1,
03828                                            TargetLowering::DAGCombinerInfo &DCI,
03829                                              const NVPTXSubtarget &Subtarget,
03830                                              CodeGenOpt::Level OptLevel) {
03831   SelectionDAG  &DAG = DCI.DAG;
03832   // Skip non-integer, non-scalar case
03833   EVT VT=N0.getValueType();
03834   if (VT.isVector())
03835     return SDValue();
03836 
03837   // fold (add (mul a, b), c) -> (mad a, b, c)
03838   //
03839   if (N0.getOpcode() == ISD::MUL) {
03840     assert (VT.isInteger());
03841     // For integer:
03842     // Since integer multiply-add costs the same as integer multiply
03843     // but is more costly than integer add, do the fusion only when
03844     // the mul is only used in the add.
03845     if (OptLevel==CodeGenOpt::None || VT != MVT::i32 ||
03846         !N0.getNode()->hasOneUse())
03847       return SDValue();
03848 
03849     // Do the folding
03850     return DAG.getNode(NVPTXISD::IMAD, SDLoc(N), VT,
03851                        N0.getOperand(0), N0.getOperand(1), N1);
03852   }
03853   else if (N0.getOpcode() == ISD::FMUL) {
03854     if (VT == MVT::f32 || VT == MVT::f64) {
03855       const auto *TLI = static_cast<const NVPTXTargetLowering *>(
03856           &DAG.getTargetLoweringInfo());
03857       if (!TLI->allowFMA(DAG.getMachineFunction(), OptLevel))
03858         return SDValue();
03859 
03860       // For floating point:
03861       // Do the fusion only when the mul has less than 5 uses and all
03862       // are add.
03863       // The heuristic is that if a use is not an add, then that use
03864       // cannot be fused into fma, therefore mul is still needed anyway.
03865       // If there are more than 4 uses, even if they are all add, fusing
03866       // them will increase register pressue.
03867       //
03868       int numUses = 0;
03869       int nonAddCount = 0;
03870       for (SDNode::use_iterator UI = N0.getNode()->use_begin(),
03871            UE = N0.getNode()->use_end();
03872            UI != UE; ++UI) {
03873         numUses++;
03874         SDNode *User = *UI;
03875         if (User->getOpcode() != ISD::FADD)
03876           ++nonAddCount;
03877       }
03878       if (numUses >= 5)
03879         return SDValue();
03880       if (nonAddCount) {
03881         int orderNo = N->getIROrder();
03882         int orderNo2 = N0.getNode()->getIROrder();
03883         // simple heuristics here for considering potential register
03884         // pressure, the logics here is that the differnce are used
03885         // to measure the distance between def and use, the longer distance
03886         // more likely cause register pressure.
03887         if (orderNo - orderNo2 < 500)
03888           return SDValue();
03889 
03890         // Now, check if at least one of the FMUL's operands is live beyond the node N,
03891         // which guarantees that the FMA will not increase register pressure at node N.
03892         bool opIsLive = false;
03893         const SDNode *left = N0.getOperand(0).getNode();
03894         const SDNode *right = N0.getOperand(1).getNode();
03895 
03896         if (dyn_cast<ConstantSDNode>(left) || dyn_cast<ConstantSDNode>(right))
03897           opIsLive = true;
03898 
03899         if (!opIsLive)
03900           for (SDNode::use_iterator UI = left->use_begin(), UE = left->use_end(); UI != UE; ++UI) {
03901             SDNode *User = *UI;
03902             int orderNo3 = User->getIROrder();
03903             if (orderNo3 > orderNo) {
03904               opIsLive = true;
03905               break;
03906             }
03907           }
03908 
03909         if (!opIsLive)
03910           for (SDNode::use_iterator UI = right->use_begin(), UE = right->use_end(); UI != UE; ++UI) {
03911             SDNode *User = *UI;
03912             int orderNo3 = User->getIROrder();
03913             if (orderNo3 > orderNo) {
03914               opIsLive = true;
03915               break;
03916             }
03917           }
03918 
03919         if (!opIsLive)
03920           return SDValue();
03921       }
03922 
03923       return DAG.getNode(ISD::FMA, SDLoc(N), VT,
03924                          N0.getOperand(0), N0.getOperand(1), N1);
03925     }
03926   }
03927 
03928   return SDValue();
03929 }
03930 
03931 /// PerformADDCombine - Target-specific dag combine xforms for ISD::ADD.
03932 ///
03933 static SDValue PerformADDCombine(SDNode *N,
03934                                  TargetLowering::DAGCombinerInfo &DCI,
03935                                  const NVPTXSubtarget &Subtarget,
03936                                  CodeGenOpt::Level OptLevel) {
03937   SDValue N0 = N->getOperand(0);
03938   SDValue N1 = N->getOperand(1);
03939 
03940   // First try with the default operand order.
03941   SDValue Result = PerformADDCombineWithOperands(N, N0, N1, DCI, Subtarget,
03942                                                  OptLevel);
03943   if (Result.getNode())
03944     return Result;
03945 
03946   // If that didn't work, try again with the operands commuted.
03947   return PerformADDCombineWithOperands(N, N1, N0, DCI, Subtarget, OptLevel);
03948 }
03949 
03950 static SDValue PerformANDCombine(SDNode *N,
03951                                  TargetLowering::DAGCombinerInfo &DCI) {
03952   // The type legalizer turns a vector load of i8 values into a zextload to i16
03953   // registers, optionally ANY_EXTENDs it (if target type is integer),
03954   // and ANDs off the high 8 bits. Since we turn this load into a
03955   // target-specific DAG node, the DAG combiner fails to eliminate these AND
03956   // nodes. Do that here.
03957   SDValue Val = N->getOperand(0);
03958   SDValue Mask = N->getOperand(1);
03959 
03960   if (isa<ConstantSDNode>(Val)) {
03961     std::swap(Val, Mask);
03962   }
03963 
03964   SDValue AExt;
03965   // Generally, we will see zextload -> IMOV16rr -> ANY_EXTEND -> and
03966   if (Val.getOpcode() == ISD::ANY_EXTEND) {
03967     AExt = Val;
03968     Val = Val->getOperand(0);
03969   }
03970 
03971   if (Val->isMachineOpcode() && Val->getMachineOpcode() == NVPTX::IMOV16rr) {
03972     Val = Val->getOperand(0);
03973   }
03974 
03975   if (Val->getOpcode() == NVPTXISD::LoadV2 ||
03976       Val->getOpcode() == NVPTXISD::LoadV4) {
03977     ConstantSDNode *MaskCnst = dyn_cast<ConstantSDNode>(Mask);
03978     if (!MaskCnst) {
03979       // Not an AND with a constant
03980       return SDValue();
03981     }
03982 
03983     uint64_t MaskVal = MaskCnst->getZExtValue();
03984     if (MaskVal != 0xff) {
03985       // Not an AND that chops off top 8 bits
03986       return SDValue();
03987     }
03988 
03989     MemSDNode *Mem = dyn_cast<MemSDNode>(Val);
03990     if (!Mem) {
03991       // Not a MemSDNode?!?
03992       return SDValue();
03993     }
03994 
03995     EVT MemVT = Mem->getMemoryVT();
03996     if (MemVT != MVT::v2i8 && MemVT != MVT::v4i8) {
03997       // We only handle the i8 case
03998       return SDValue();
03999     }
04000 
04001     unsigned ExtType =
04002       cast<ConstantSDNode>(Val->getOperand(Val->getNumOperands()-1))->
04003         getZExtValue();
04004     if (ExtType == ISD::SEXTLOAD) {
04005       // If for some reason the load is a sextload, the and is needed to zero
04006       // out the high 8 bits
04007       return SDValue();
04008     }
04009 
04010     bool AddTo = false;
04011     if (AExt.getNode() != 0) {
04012       // Re-insert the ext as a zext.
04013       Val = DCI.DAG.getNode(ISD::ZERO_EXTEND, SDLoc(N),
04014                             AExt.getValueType(), Val);
04015       AddTo = true;
04016     }
04017 
04018     // If we get here, the AND is unnecessary.  Just replace it with the load
04019     DCI.CombineTo(N, Val, AddTo);
04020   }
04021 
04022   return SDValue();
04023 }
04024 
04025 enum OperandSignedness {
04026   Signed = 0,
04027   Unsigned,
04028   Unknown
04029 };
04030 
04031 /// IsMulWideOperandDemotable - Checks if the provided DAG node is an operand
04032 /// that can be demoted to \p OptSize bits without loss of information. The
04033 /// signedness of the operand, if determinable, is placed in \p S.
04034 static bool IsMulWideOperandDemotable(SDValue Op,
04035                                       unsigned OptSize,
04036                                       OperandSignedness &S) {
04037   S = Unknown;
04038 
04039   if (Op.getOpcode() == ISD::SIGN_EXTEND ||
04040       Op.getOpcode() == ISD::SIGN_EXTEND_INREG) {
04041     EVT OrigVT = Op.getOperand(0).getValueType();
04042     if (OrigVT.getSizeInBits() <= OptSize) {
04043       S = Signed;
04044       return true;
04045     }
04046   } else if (Op.getOpcode() == ISD::ZERO_EXTEND) {
04047     EVT OrigVT = Op.getOperand(0).getValueType();
04048     if (OrigVT.getSizeInBits() <= OptSize) {
04049       S = Unsigned;
04050       return true;
04051     }
04052   }
04053 
04054   return false;
04055 }
04056 
04057 /// AreMulWideOperandsDemotable - Checks if the given LHS and RHS operands can
04058 /// be demoted to \p OptSize bits without loss of information. If the operands
04059 /// contain a constant, it should appear as the RHS operand. The signedness of
04060 /// the operands is placed in \p IsSigned.
04061 static bool AreMulWideOperandsDemotable(SDValue LHS, SDValue RHS,
04062                                         unsigned OptSize,
04063                                         bool &IsSigned) {
04064 
04065   OperandSignedness LHSSign;
04066 
04067   // The LHS operand must be a demotable op
04068   if (!IsMulWideOperandDemotable(LHS, OptSize, LHSSign))
04069     return false;
04070 
04071   // We should have been able to determine the signedness from the LHS
04072   if (LHSSign == Unknown)
04073     return false;
04074 
04075   IsSigned = (LHSSign == Signed);
04076 
04077   // The RHS can be a demotable op or a constant
04078   if (ConstantSDNode *CI = dyn_cast<ConstantSDNode>(RHS)) {
04079     APInt Val = CI->getAPIntValue();
04080     if (LHSSign == Unsigned) {
04081       if (Val.isIntN(OptSize)) {
04082         return true;
04083       }
04084       return false;
04085     } else {
04086       if (Val.isSignedIntN(OptSize)) {
04087         return true;
04088       }
04089       return false;
04090     }
04091   } else {
04092     OperandSignedness RHSSign;
04093     if (!IsMulWideOperandDemotable(RHS, OptSize, RHSSign))
04094       return false;
04095 
04096     if (LHSSign != RHSSign)
04097       return false;
04098 
04099     return true;
04100   }
04101 }
04102 
04103 /// TryMULWIDECombine - Attempt to replace a multiply of M bits with a multiply
04104 /// of M/2 bits that produces an M-bit result (i.e. mul.wide). This transform
04105 /// works on both multiply DAG nodes and SHL DAG nodes with a constant shift
04106 /// amount.
04107 static SDValue TryMULWIDECombine(SDNode *N,
04108                                  TargetLowering::DAGCombinerInfo &DCI) {
04109   EVT MulType = N->getValueType(0);
04110   if (MulType != MVT::i32 && MulType != MVT::i64) {
04111     return SDValue();
04112   }
04113 
04114   unsigned OptSize = MulType.getSizeInBits() >> 1;
04115   SDValue LHS = N->getOperand(0);
04116   SDValue RHS = N->getOperand(1);
04117 
04118   // Canonicalize the multiply so the constant (if any) is on the right
04119   if (N->getOpcode() == ISD::MUL) {
04120     if (isa<ConstantSDNode>(LHS)) {
04121       std::swap(LHS, RHS);
04122     }
04123   }
04124 
04125   // If we have a SHL, determine the actual multiply amount
04126   if (N->getOpcode() == ISD::SHL) {
04127     ConstantSDNode *ShlRHS = dyn_cast<ConstantSDNode>(RHS);
04128     if (!ShlRHS) {
04129       return SDValue();
04130     }
04131 
04132     APInt ShiftAmt = ShlRHS->getAPIntValue();
04133     unsigned BitWidth = MulType.getSizeInBits();
04134     if (ShiftAmt.sge(0) && ShiftAmt.slt(BitWidth)) {
04135       APInt MulVal = APInt(BitWidth, 1) << ShiftAmt;
04136       RHS = DCI.DAG.getConstant(MulVal, MulType);
04137     } else {
04138       return SDValue();
04139     }
04140   }
04141 
04142   bool Signed;
04143   // Verify that our operands are demotable
04144   if (!AreMulWideOperandsDemotable(LHS, RHS, OptSize, Signed)) {
04145     return SDValue();
04146   }
04147 
04148   EVT DemotedVT;
04149   if (MulType == MVT::i32) {
04150     DemotedVT = MVT::i16;
04151   } else {
04152     DemotedVT = MVT::i32;
04153   }
04154 
04155   // Truncate the operands to the correct size. Note that these are just for
04156   // type consistency and will (likely) be eliminated in later phases.
04157   SDValue TruncLHS =
04158     DCI.DAG.getNode(ISD::TRUNCATE, SDLoc(N), DemotedVT, LHS);
04159   SDValue TruncRHS =
04160     DCI.DAG.getNode(ISD::TRUNCATE, SDLoc(N), DemotedVT, RHS);
04161 
04162   unsigned Opc;
04163   if (Signed) {
04164     Opc = NVPTXISD::MUL_WIDE_SIGNED;
04165   } else {
04166     Opc = NVPTXISD::MUL_WIDE_UNSIGNED;
04167   }
04168 
04169   return DCI.DAG.getNode(Opc, SDLoc(N), MulType, TruncLHS, TruncRHS);
04170 }
04171 
04172 /// PerformMULCombine - Runs PTX-specific DAG combine patterns on MUL nodes.
04173 static SDValue PerformMULCombine(SDNode *N,
04174                                  TargetLowering::DAGCombinerInfo &DCI,
04175                                  CodeGenOpt::Level OptLevel) {
04176   if (OptLevel > 0) {
04177     // Try mul.wide combining at OptLevel > 0
04178     SDValue Ret = TryMULWIDECombine(N, DCI);
04179     if (Ret.getNode())
04180       return Ret;
04181   }
04182 
04183   return SDValue();
04184 }
04185 
04186 /// PerformSHLCombine - Runs PTX-specific DAG combine patterns on SHL nodes.
04187 static SDValue PerformSHLCombine(SDNode *N,
04188                                  TargetLowering::DAGCombinerInfo &DCI,
04189                                  CodeGenOpt::Level OptLevel) {
04190   if (OptLevel > 0) {
04191     // Try mul.wide combining at OptLevel > 0
04192     SDValue Ret = TryMULWIDECombine(N, DCI);
04193     if (Ret.getNode())
04194       return Ret;
04195   }
04196 
04197   return SDValue();
04198 }
04199 
04200 SDValue NVPTXTargetLowering::PerformDAGCombine(SDNode *N,
04201                                                DAGCombinerInfo &DCI) const {
04202   CodeGenOpt::Level OptLevel = getTargetMachine().getOptLevel();
04203   switch (N->getOpcode()) {
04204     default: break;
04205     case ISD::ADD:
04206     case ISD::FADD:
04207       return PerformADDCombine(N, DCI, STI, OptLevel);
04208     case ISD::MUL:
04209       return PerformMULCombine(N, DCI, OptLevel);
04210     case ISD::SHL:
04211       return PerformSHLCombine(N, DCI, OptLevel);
04212     case ISD::AND:
04213       return PerformANDCombine(N, DCI);
04214   }
04215   return SDValue();
04216 }
04217 
04218 /// ReplaceVectorLoad - Convert vector loads into multi-output scalar loads.
04219 static void ReplaceLoadVector(SDNode *N, SelectionDAG &DAG,
04220                               const DataLayout *TD,
04221                               SmallVectorImpl<SDValue> &Results) {
04222   EVT ResVT = N->getValueType(0);
04223   SDLoc DL(N);
04224 
04225   assert(ResVT.isVector() && "Vector load must have vector type");
04226 
04227   // We only handle "native" vector sizes for now, e.g. <4 x double> is not
04228   // legal.  We can (and should) split that into 2 loads of <2 x double> here
04229   // but I'm leaving that as a TODO for now.
04230   assert(ResVT.isSimple() && "Can only handle simple types");
04231   switch (ResVT.getSimpleVT().SimpleTy) {
04232   default:
04233     return;
04234   case MVT::v2i8:
04235   case MVT::v2i16:
04236   case MVT::v2i32:
04237   case MVT::v2i64:
04238   case MVT::v2f32:
04239   case MVT::v2f64:
04240   case MVT::v4i8:
04241   case MVT::v4i16:
04242   case MVT::v4i32:
04243   case MVT::v4f32:
04244     // This is a "native" vector type
04245     break;
04246   }
04247 
04248   LoadSDNode *LD = cast<LoadSDNode>(N);
04249 
04250   unsigned Align = LD->getAlignment();
04251   unsigned PrefAlign =
04252     TD->getPrefTypeAlignment(ResVT.getTypeForEVT(*DAG.getContext()));
04253   if (Align < PrefAlign) {
04254     // This load is not sufficiently aligned, so bail out and let this vector
04255     // load be scalarized.  Note that we may still be able to emit smaller
04256     // vector loads.  For example, if we are loading a <4 x float> with an
04257     // alignment of 8, this check will fail but the legalizer will try again
04258     // with 2 x <2 x float>, which will succeed with an alignment of 8.
04259     return;
04260   }
04261 
04262   EVT EltVT = ResVT.getVectorElementType();
04263   unsigned NumElts = ResVT.getVectorNumElements();
04264 
04265   // Since LoadV2 is a target node, we cannot rely on DAG type legalization.
04266   // Therefore, we must ensure the type is legal.  For i1 and i8, we set the
04267   // loaded type to i16 and propagate the "real" type as the memory type.
04268   bool NeedTrunc = false;
04269   if (EltVT.getSizeInBits() < 16) {
04270     EltVT = MVT::i16;
04271     NeedTrunc = true;
04272   }
04273 
04274   unsigned Opcode = 0;
04275   SDVTList LdResVTs;
04276 
04277   switch (NumElts) {
04278   default:
04279     return;
04280   case 2:
04281     Opcode = NVPTXISD::LoadV2;
04282     LdResVTs = DAG.getVTList(EltVT, EltVT, MVT::Other);
04283     break;
04284   case 4: {
04285     Opcode = NVPTXISD::LoadV4;
04286     EVT ListVTs[] = { EltVT, EltVT, EltVT, EltVT, MVT::Other };
04287     LdResVTs = DAG.getVTList(ListVTs);
04288     break;
04289   }
04290   }
04291 
04292   // Copy regular operands
04293   SmallVector<SDValue, 8> OtherOps(N->op_begin(), N->op_end());
04294 
04295   // The select routine does not have access to the LoadSDNode instance, so
04296   // pass along the extension information
04297   OtherOps.push_back(DAG.getIntPtrConstant(LD->getExtensionType()));
04298 
04299   SDValue NewLD = DAG.getMemIntrinsicNode(Opcode, DL, LdResVTs, OtherOps,
04300                                           LD->getMemoryVT(),
04301                                           LD->getMemOperand());
04302 
04303   SmallVector<SDValue, 4> ScalarRes;
04304 
04305   for (unsigned i = 0; i < NumElts; ++i) {
04306     SDValue Res = NewLD.getValue(i);
04307     if (NeedTrunc)
04308       Res = DAG.getNode(ISD::TRUNCATE, DL, ResVT.getVectorElementType(), Res);
04309     ScalarRes.push_back(Res);
04310   }
04311 
04312   SDValue LoadChain = NewLD.getValue(NumElts);
04313 
04314   SDValue BuildVec = DAG.getNode(ISD::BUILD_VECTOR, DL, ResVT, ScalarRes);
04315 
04316   Results.push_back(BuildVec);
04317   Results.push_back(LoadChain);
04318 }
04319 
04320 static void ReplaceINTRINSIC_W_CHAIN(SDNode *N, SelectionDAG &DAG,
04321                                      SmallVectorImpl<SDValue> &Results) {
04322   SDValue Chain = N->getOperand(0);
04323   SDValue Intrin = N->getOperand(1);
04324   SDLoc DL(N);
04325 
04326   // Get the intrinsic ID
04327   unsigned IntrinNo = cast<ConstantSDNode>(Intrin.getNode())->getZExtValue();
04328   switch (IntrinNo) {
04329   default:
04330     return;
04331   case Intrinsic::nvvm_ldg_global_i:
04332   case Intrinsic::nvvm_ldg_global_f:
04333   case Intrinsic::nvvm_ldg_global_p:
04334   case Intrinsic::nvvm_ldu_global_i:
04335   case Intrinsic::nvvm_ldu_global_f:
04336   case Intrinsic::nvvm_ldu_global_p: {
04337     EVT ResVT = N->getValueType(0);
04338 
04339     if (ResVT.isVector()) {
04340       // Vector LDG/LDU
04341 
04342       unsigned NumElts = ResVT.getVectorNumElements();
04343       EVT EltVT = ResVT.getVectorElementType();
04344 
04345       // Since LDU/LDG are target nodes, we cannot rely on DAG type
04346       // legalization.
04347       // Therefore, we must ensure the type is legal.  For i1 and i8, we set the
04348       // loaded type to i16 and propagate the "real" type as the memory type.
04349       bool NeedTrunc = false;
04350       if (EltVT.getSizeInBits() < 16) {
04351         EltVT = MVT::i16;
04352         NeedTrunc = true;
04353       }
04354 
04355       unsigned Opcode = 0;
04356       SDVTList LdResVTs;
04357 
04358       switch (NumElts) {
04359       default:
04360         return;
04361       case 2:
04362         switch (IntrinNo) {
04363         default:
04364           return;
04365         case Intrinsic::nvvm_ldg_global_i:
04366         case Intrinsic::nvvm_ldg_global_f:
04367         case Intrinsic::nvvm_ldg_global_p:
04368           Opcode = NVPTXISD::LDGV2;
04369           break;
04370         case Intrinsic::nvvm_ldu_global_i:
04371         case Intrinsic::nvvm_ldu_global_f:
04372         case Intrinsic::nvvm_ldu_global_p:
04373           Opcode = NVPTXISD::LDUV2;
04374           break;
04375         }
04376         LdResVTs = DAG.getVTList(EltVT, EltVT, MVT::Other);
04377         break;
04378       case 4: {
04379         switch (IntrinNo) {
04380         default:
04381           return;
04382         case Intrinsic::nvvm_ldg_global_i:
04383         case Intrinsic::nvvm_ldg_global_f:
04384         case Intrinsic::nvvm_ldg_global_p:
04385           Opcode = NVPTXISD::LDGV4;
04386           break;
04387         case Intrinsic::nvvm_ldu_global_i:
04388         case Intrinsic::nvvm_ldu_global_f:
04389         case Intrinsic::nvvm_ldu_global_p:
04390           Opcode = NVPTXISD::LDUV4;
04391           break;
04392         }
04393         EVT ListVTs[] = { EltVT, EltVT, EltVT, EltVT, MVT::Other };
04394         LdResVTs = DAG.getVTList(ListVTs);
04395         break;
04396       }
04397       }
04398 
04399       SmallVector<SDValue, 8> OtherOps;
04400 
04401       // Copy regular operands
04402 
04403       OtherOps.push_back(Chain); // Chain
04404                                  // Skip operand 1 (intrinsic ID)
04405       // Others
04406       OtherOps.append(N->op_begin() + 2, N->op_end());
04407 
04408       MemIntrinsicSDNode *MemSD = cast<MemIntrinsicSDNode>(N);
04409 
04410       SDValue NewLD = DAG.getMemIntrinsicNode(Opcode, DL, LdResVTs, OtherOps,
04411                                               MemSD->getMemoryVT(),
04412                                               MemSD->getMemOperand());
04413 
04414       SmallVector<SDValue, 4> ScalarRes;
04415 
04416       for (unsigned i = 0; i < NumElts; ++i) {
04417         SDValue Res = NewLD.getValue(i);
04418         if (NeedTrunc)
04419           Res =
04420               DAG.getNode(ISD::TRUNCATE, DL, ResVT.getVectorElementType(), Res);
04421         ScalarRes.push_back(Res);
04422       }
04423 
04424       SDValue LoadChain = NewLD.getValue(NumElts);
04425 
04426       SDValue BuildVec =
04427           DAG.getNode(ISD::BUILD_VECTOR, DL, ResVT, ScalarRes);
04428 
04429       Results.push_back(BuildVec);
04430       Results.push_back(LoadChain);
04431     } else {
04432       // i8 LDG/LDU
04433       assert(ResVT.isSimple() && ResVT.getSimpleVT().SimpleTy == MVT::i8 &&
04434              "Custom handling of non-i8 ldu/ldg?");
04435 
04436       // Just copy all operands as-is
04437       SmallVector<SDValue, 4> Ops(N->op_begin(), N->op_end());
04438 
04439       // Force output to i16
04440       SDVTList LdResVTs = DAG.getVTList(MVT::i16, MVT::Other);
04441 
04442       MemIntrinsicSDNode *MemSD = cast<MemIntrinsicSDNode>(N);
04443 
04444       // We make sure the memory type is i8, which will be used during isel
04445       // to select the proper instruction.
04446       SDValue NewLD =
04447           DAG.getMemIntrinsicNode(ISD::INTRINSIC_W_CHAIN, DL, LdResVTs, Ops,
04448                                   MVT::i8, MemSD->getMemOperand());
04449 
04450       Results.push_back(DAG.getNode(ISD::TRUNCATE, DL, MVT::i8,
04451                                     NewLD.getValue(0)));
04452       Results.push_back(NewLD.getValue(1));
04453     }
04454   }
04455   }
04456 }
04457 
04458 void NVPTXTargetLowering::ReplaceNodeResults(
04459     SDNode *N, SmallVectorImpl<SDValue> &Results, SelectionDAG &DAG) const {
04460   switch (N->getOpcode()) {
04461   default:
04462     report_fatal_error("Unhandled custom legalization");
04463   case ISD::LOAD:
04464     ReplaceLoadVector(N, DAG, getDataLayout(), Results);
04465     return;
04466   case ISD::INTRINSIC_W_CHAIN:
04467     ReplaceINTRINSIC_W_CHAIN(N, DAG, Results);
04468     return;
04469   }
04470 }
04471 
04472 // Pin NVPTXSection's and NVPTXTargetObjectFile's vtables to this file.
04473 void NVPTXSection::anchor() {}
04474 
04475 NVPTXTargetObjectFile::~NVPTXTargetObjectFile() {
04476   delete TextSection;
04477   delete DataSection;
04478   delete BSSSection;
04479   delete ReadOnlySection;
04480 
04481   delete StaticCtorSection;
04482   delete StaticDtorSection;
04483   delete LSDASection;
04484   delete EHFrameSection;
04485   delete DwarfAbbrevSection;
04486   delete DwarfInfoSection;
04487   delete DwarfLineSection;
04488   delete DwarfFrameSection;
04489   delete DwarfPubTypesSection;
04490   delete DwarfDebugInlineSection;
04491   delete DwarfStrSection;
04492   delete DwarfLocSection;
04493   delete DwarfARangesSection;
04494   delete DwarfRangesSection;
04495 }
04496 
04497 const MCSection *
04498 NVPTXTargetObjectFile::SelectSectionForGlobal(const GlobalValue *GV,
04499                                               SectionKind Kind, Mangler &Mang,
04500                                               const TargetMachine &TM) const {
04501   return getDataSection();
04502 }