NVPTXISelDAGToDAG.cpp 135 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712271327142715271627172718271927202721272227232724272527262727272827292730273127322733273427352736273727382739274027412742274327442745274627472748274927502751275227532754275527562757275827592760276127622763276427652766276727682769277027712772277327742775277627772778277927802781278227832784278527862787278827892790279127922793279427952796279727982799280028012802280328042805280628072808280928102811281228132814281528162817281828192820282128222823282428252826282728282829283028312832283328342835283628372838283928402841284228432844284528462847284828492850285128522853285428552856285728582859286028612862286328642865286628672868286928702871287228732874287528762877287828792880288128822883288428852886288728882889289028912892289328942895289628972898289929002901290229032904290529062907290829092910291129122913291429152916291729182919292029212922292329242925292629272928292929302931293229332934293529362937293829392940294129422943294429452946294729482949295029512952295329542955295629572958295929602961296229632964296529662967296829692970297129722973297429752976297729782979298029812982298329842985298629872988298929902991299229932994299529962997299829993000300130023003300430053006300730083009301030113012301330143015301630173018301930203021302230233024302530263027302830293030303130323033303430353036303730383039304030413042304330443045304630473048304930503051305230533054305530563057305830593060306130623063306430653066306730683069307030713072307330743075307630773078307930803081308230833084308530863087308830893090309130923093309430953096309730983099310031013102310331043105310631073108310931103111311231133114311531163117311831193120312131223123312431253126312731283129313031313132313331343135313631373138313931403141314231433144314531463147314831493150315131523153315431553156315731583159316031613162316331643165316631673168316931703171317231733174317531763177317831793180318131823183318431853186318731883189319031913192319331943195319631973198319932003201320232033204320532063207320832093210321132123213321432153216321732183219322032213222322332243225322632273228322932303231323232333234323532363237323832393240324132423243324432453246324732483249325032513252325332543255325632573258325932603261326232633264326532663267326832693270327132723273327432753276327732783279328032813282328332843285328632873288328932903291329232933294329532963297329832993300330133023303330433053306330733083309331033113312331333143315331633173318331933203321332233233324332533263327332833293330333133323333333433353336333733383339334033413342334333443345334633473348334933503351335233533354335533563357335833593360336133623363336433653366336733683369337033713372337333743375337633773378337933803381338233833384338533863387338833893390339133923393339433953396339733983399340034013402340334043405340634073408340934103411341234133414341534163417341834193420342134223423342434253426342734283429343034313432343334343435343634373438343934403441344234433444344534463447344834493450345134523453345434553456345734583459346034613462346334643465346634673468346934703471347234733474347534763477347834793480348134823483348434853486348734883489349034913492349334943495349634973498349935003501350235033504350535063507350835093510351135123513351435153516351735183519352035213522352335243525352635273528352935303531353235333534353535363537353835393540354135423543354435453546354735483549355035513552355335543555355635573558355935603561356235633564356535663567356835693570357135723573357435753576357735783579358035813582358335843585358635873588358935903591359235933594359535963597359835993600360136023603360436053606360736083609361036113612361336143615361636173618361936203621362236233624362536263627362836293630363136323633363436353636363736383639364036413642364336443645364636473648364936503651365236533654365536563657365836593660366136623663366436653666366736683669367036713672367336743675367636773678367936803681368236833684368536863687368836893690369136923693369436953696369736983699370037013702370337043705370637073708370937103711371237133714371537163717371837193720372137223723372437253726372737283729373037313732373337343735373637373738373937403741374237433744374537463747374837493750375137523753375437553756375737583759376037613762376337643765
  1. //===-- NVPTXISelDAGToDAG.cpp - A dag to dag inst selector for NVPTX ------===//
  2. //
  3. // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
  4. // See https://llvm.org/LICENSE.txt for license information.
  5. // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
  6. //
  7. //===----------------------------------------------------------------------===//
  8. //
  9. // This file defines an instruction selector for the NVPTX target.
  10. //
  11. //===----------------------------------------------------------------------===//
  12. #include "NVPTXISelDAGToDAG.h"
  13. #include "MCTargetDesc/NVPTXBaseInfo.h"
  14. #include "NVPTXUtilities.h"
  15. #include "llvm/Analysis/ValueTracking.h"
  16. #include "llvm/IR/GlobalValue.h"
  17. #include "llvm/IR/Instructions.h"
  18. #include "llvm/IR/IntrinsicsNVPTX.h"
  19. #include "llvm/Support/AtomicOrdering.h"
  20. #include "llvm/Support/CommandLine.h"
  21. #include "llvm/Support/Debug.h"
  22. #include "llvm/Support/ErrorHandling.h"
  23. #include "llvm/Support/raw_ostream.h"
  24. #include "llvm/Target/TargetIntrinsicInfo.h"
  25. using namespace llvm;
  26. #define DEBUG_TYPE "nvptx-isel"
  27. /// createNVPTXISelDag - This pass converts a legalized DAG into a
  28. /// NVPTX-specific DAG, ready for instruction scheduling.
  29. FunctionPass *llvm::createNVPTXISelDag(NVPTXTargetMachine &TM,
  30. llvm::CodeGenOpt::Level OptLevel) {
  31. return new NVPTXDAGToDAGISel(TM, OptLevel);
  32. }
  33. NVPTXDAGToDAGISel::NVPTXDAGToDAGISel(NVPTXTargetMachine &tm,
  34. CodeGenOpt::Level OptLevel)
  35. : SelectionDAGISel(tm, OptLevel), TM(tm) {
  36. doMulWide = (OptLevel > 0);
  37. }
  38. bool NVPTXDAGToDAGISel::runOnMachineFunction(MachineFunction &MF) {
  39. Subtarget = &static_cast<const NVPTXSubtarget &>(MF.getSubtarget());
  40. return SelectionDAGISel::runOnMachineFunction(MF);
  41. }
  42. int NVPTXDAGToDAGISel::getDivF32Level() const {
  43. return Subtarget->getTargetLowering()->getDivF32Level();
  44. }
  45. bool NVPTXDAGToDAGISel::usePrecSqrtF32() const {
  46. return Subtarget->getTargetLowering()->usePrecSqrtF32();
  47. }
  48. bool NVPTXDAGToDAGISel::useF32FTZ() const {
  49. return Subtarget->getTargetLowering()->useF32FTZ(*MF);
  50. }
  51. bool NVPTXDAGToDAGISel::allowFMA() const {
  52. const NVPTXTargetLowering *TL = Subtarget->getTargetLowering();
  53. return TL->allowFMA(*MF, OptLevel);
  54. }
  55. bool NVPTXDAGToDAGISel::allowUnsafeFPMath() const {
  56. const NVPTXTargetLowering *TL = Subtarget->getTargetLowering();
  57. return TL->allowUnsafeFPMath(*MF);
  58. }
  59. bool NVPTXDAGToDAGISel::useShortPointers() const {
  60. return TM.useShortPointers();
  61. }
  62. /// Select - Select instructions not customized! Used for
  63. /// expanded, promoted and normal instructions.
  64. void NVPTXDAGToDAGISel::Select(SDNode *N) {
  65. if (N->isMachineOpcode()) {
  66. N->setNodeId(-1);
  67. return; // Already selected.
  68. }
  69. switch (N->getOpcode()) {
  70. case ISD::LOAD:
  71. case ISD::ATOMIC_LOAD:
  72. if (tryLoad(N))
  73. return;
  74. break;
  75. case ISD::STORE:
  76. case ISD::ATOMIC_STORE:
  77. if (tryStore(N))
  78. return;
  79. break;
  80. case ISD::EXTRACT_VECTOR_ELT:
  81. if (tryEXTRACT_VECTOR_ELEMENT(N))
  82. return;
  83. break;
  84. case NVPTXISD::SETP_F16X2:
  85. SelectSETP_F16X2(N);
  86. return;
  87. case NVPTXISD::LoadV2:
  88. case NVPTXISD::LoadV4:
  89. if (tryLoadVector(N))
  90. return;
  91. break;
  92. case NVPTXISD::LDGV2:
  93. case NVPTXISD::LDGV4:
  94. case NVPTXISD::LDUV2:
  95. case NVPTXISD::LDUV4:
  96. if (tryLDGLDU(N))
  97. return;
  98. break;
  99. case NVPTXISD::StoreV2:
  100. case NVPTXISD::StoreV4:
  101. if (tryStoreVector(N))
  102. return;
  103. break;
  104. case NVPTXISD::LoadParam:
  105. case NVPTXISD::LoadParamV2:
  106. case NVPTXISD::LoadParamV4:
  107. if (tryLoadParam(N))
  108. return;
  109. break;
  110. case NVPTXISD::StoreRetval:
  111. case NVPTXISD::StoreRetvalV2:
  112. case NVPTXISD::StoreRetvalV4:
  113. if (tryStoreRetval(N))
  114. return;
  115. break;
  116. case NVPTXISD::StoreParam:
  117. case NVPTXISD::StoreParamV2:
  118. case NVPTXISD::StoreParamV4:
  119. case NVPTXISD::StoreParamS32:
  120. case NVPTXISD::StoreParamU32:
  121. if (tryStoreParam(N))
  122. return;
  123. break;
  124. case ISD::INTRINSIC_WO_CHAIN:
  125. if (tryIntrinsicNoChain(N))
  126. return;
  127. break;
  128. case ISD::INTRINSIC_W_CHAIN:
  129. if (tryIntrinsicChain(N))
  130. return;
  131. break;
  132. case NVPTXISD::Tex1DFloatS32:
  133. case NVPTXISD::Tex1DFloatFloat:
  134. case NVPTXISD::Tex1DFloatFloatLevel:
  135. case NVPTXISD::Tex1DFloatFloatGrad:
  136. case NVPTXISD::Tex1DS32S32:
  137. case NVPTXISD::Tex1DS32Float:
  138. case NVPTXISD::Tex1DS32FloatLevel:
  139. case NVPTXISD::Tex1DS32FloatGrad:
  140. case NVPTXISD::Tex1DU32S32:
  141. case NVPTXISD::Tex1DU32Float:
  142. case NVPTXISD::Tex1DU32FloatLevel:
  143. case NVPTXISD::Tex1DU32FloatGrad:
  144. case NVPTXISD::Tex1DArrayFloatS32:
  145. case NVPTXISD::Tex1DArrayFloatFloat:
  146. case NVPTXISD::Tex1DArrayFloatFloatLevel:
  147. case NVPTXISD::Tex1DArrayFloatFloatGrad:
  148. case NVPTXISD::Tex1DArrayS32S32:
  149. case NVPTXISD::Tex1DArrayS32Float:
  150. case NVPTXISD::Tex1DArrayS32FloatLevel:
  151. case NVPTXISD::Tex1DArrayS32FloatGrad:
  152. case NVPTXISD::Tex1DArrayU32S32:
  153. case NVPTXISD::Tex1DArrayU32Float:
  154. case NVPTXISD::Tex1DArrayU32FloatLevel:
  155. case NVPTXISD::Tex1DArrayU32FloatGrad:
  156. case NVPTXISD::Tex2DFloatS32:
  157. case NVPTXISD::Tex2DFloatFloat:
  158. case NVPTXISD::Tex2DFloatFloatLevel:
  159. case NVPTXISD::Tex2DFloatFloatGrad:
  160. case NVPTXISD::Tex2DS32S32:
  161. case NVPTXISD::Tex2DS32Float:
  162. case NVPTXISD::Tex2DS32FloatLevel:
  163. case NVPTXISD::Tex2DS32FloatGrad:
  164. case NVPTXISD::Tex2DU32S32:
  165. case NVPTXISD::Tex2DU32Float:
  166. case NVPTXISD::Tex2DU32FloatLevel:
  167. case NVPTXISD::Tex2DU32FloatGrad:
  168. case NVPTXISD::Tex2DArrayFloatS32:
  169. case NVPTXISD::Tex2DArrayFloatFloat:
  170. case NVPTXISD::Tex2DArrayFloatFloatLevel:
  171. case NVPTXISD::Tex2DArrayFloatFloatGrad:
  172. case NVPTXISD::Tex2DArrayS32S32:
  173. case NVPTXISD::Tex2DArrayS32Float:
  174. case NVPTXISD::Tex2DArrayS32FloatLevel:
  175. case NVPTXISD::Tex2DArrayS32FloatGrad:
  176. case NVPTXISD::Tex2DArrayU32S32:
  177. case NVPTXISD::Tex2DArrayU32Float:
  178. case NVPTXISD::Tex2DArrayU32FloatLevel:
  179. case NVPTXISD::Tex2DArrayU32FloatGrad:
  180. case NVPTXISD::Tex3DFloatS32:
  181. case NVPTXISD::Tex3DFloatFloat:
  182. case NVPTXISD::Tex3DFloatFloatLevel:
  183. case NVPTXISD::Tex3DFloatFloatGrad:
  184. case NVPTXISD::Tex3DS32S32:
  185. case NVPTXISD::Tex3DS32Float:
  186. case NVPTXISD::Tex3DS32FloatLevel:
  187. case NVPTXISD::Tex3DS32FloatGrad:
  188. case NVPTXISD::Tex3DU32S32:
  189. case NVPTXISD::Tex3DU32Float:
  190. case NVPTXISD::Tex3DU32FloatLevel:
  191. case NVPTXISD::Tex3DU32FloatGrad:
  192. case NVPTXISD::TexCubeFloatFloat:
  193. case NVPTXISD::TexCubeFloatFloatLevel:
  194. case NVPTXISD::TexCubeS32Float:
  195. case NVPTXISD::TexCubeS32FloatLevel:
  196. case NVPTXISD::TexCubeU32Float:
  197. case NVPTXISD::TexCubeU32FloatLevel:
  198. case NVPTXISD::TexCubeArrayFloatFloat:
  199. case NVPTXISD::TexCubeArrayFloatFloatLevel:
  200. case NVPTXISD::TexCubeArrayS32Float:
  201. case NVPTXISD::TexCubeArrayS32FloatLevel:
  202. case NVPTXISD::TexCubeArrayU32Float:
  203. case NVPTXISD::TexCubeArrayU32FloatLevel:
  204. case NVPTXISD::Tld4R2DFloatFloat:
  205. case NVPTXISD::Tld4G2DFloatFloat:
  206. case NVPTXISD::Tld4B2DFloatFloat:
  207. case NVPTXISD::Tld4A2DFloatFloat:
  208. case NVPTXISD::Tld4R2DS64Float:
  209. case NVPTXISD::Tld4G2DS64Float:
  210. case NVPTXISD::Tld4B2DS64Float:
  211. case NVPTXISD::Tld4A2DS64Float:
  212. case NVPTXISD::Tld4R2DU64Float:
  213. case NVPTXISD::Tld4G2DU64Float:
  214. case NVPTXISD::Tld4B2DU64Float:
  215. case NVPTXISD::Tld4A2DU64Float:
  216. case NVPTXISD::TexUnified1DFloatS32:
  217. case NVPTXISD::TexUnified1DFloatFloat:
  218. case NVPTXISD::TexUnified1DFloatFloatLevel:
  219. case NVPTXISD::TexUnified1DFloatFloatGrad:
  220. case NVPTXISD::TexUnified1DS32S32:
  221. case NVPTXISD::TexUnified1DS32Float:
  222. case NVPTXISD::TexUnified1DS32FloatLevel:
  223. case NVPTXISD::TexUnified1DS32FloatGrad:
  224. case NVPTXISD::TexUnified1DU32S32:
  225. case NVPTXISD::TexUnified1DU32Float:
  226. case NVPTXISD::TexUnified1DU32FloatLevel:
  227. case NVPTXISD::TexUnified1DU32FloatGrad:
  228. case NVPTXISD::TexUnified1DArrayFloatS32:
  229. case NVPTXISD::TexUnified1DArrayFloatFloat:
  230. case NVPTXISD::TexUnified1DArrayFloatFloatLevel:
  231. case NVPTXISD::TexUnified1DArrayFloatFloatGrad:
  232. case NVPTXISD::TexUnified1DArrayS32S32:
  233. case NVPTXISD::TexUnified1DArrayS32Float:
  234. case NVPTXISD::TexUnified1DArrayS32FloatLevel:
  235. case NVPTXISD::TexUnified1DArrayS32FloatGrad:
  236. case NVPTXISD::TexUnified1DArrayU32S32:
  237. case NVPTXISD::TexUnified1DArrayU32Float:
  238. case NVPTXISD::TexUnified1DArrayU32FloatLevel:
  239. case NVPTXISD::TexUnified1DArrayU32FloatGrad:
  240. case NVPTXISD::TexUnified2DFloatS32:
  241. case NVPTXISD::TexUnified2DFloatFloat:
  242. case NVPTXISD::TexUnified2DFloatFloatLevel:
  243. case NVPTXISD::TexUnified2DFloatFloatGrad:
  244. case NVPTXISD::TexUnified2DS32S32:
  245. case NVPTXISD::TexUnified2DS32Float:
  246. case NVPTXISD::TexUnified2DS32FloatLevel:
  247. case NVPTXISD::TexUnified2DS32FloatGrad:
  248. case NVPTXISD::TexUnified2DU32S32:
  249. case NVPTXISD::TexUnified2DU32Float:
  250. case NVPTXISD::TexUnified2DU32FloatLevel:
  251. case NVPTXISD::TexUnified2DU32FloatGrad:
  252. case NVPTXISD::TexUnified2DArrayFloatS32:
  253. case NVPTXISD::TexUnified2DArrayFloatFloat:
  254. case NVPTXISD::TexUnified2DArrayFloatFloatLevel:
  255. case NVPTXISD::TexUnified2DArrayFloatFloatGrad:
  256. case NVPTXISD::TexUnified2DArrayS32S32:
  257. case NVPTXISD::TexUnified2DArrayS32Float:
  258. case NVPTXISD::TexUnified2DArrayS32FloatLevel:
  259. case NVPTXISD::TexUnified2DArrayS32FloatGrad:
  260. case NVPTXISD::TexUnified2DArrayU32S32:
  261. case NVPTXISD::TexUnified2DArrayU32Float:
  262. case NVPTXISD::TexUnified2DArrayU32FloatLevel:
  263. case NVPTXISD::TexUnified2DArrayU32FloatGrad:
  264. case NVPTXISD::TexUnified3DFloatS32:
  265. case NVPTXISD::TexUnified3DFloatFloat:
  266. case NVPTXISD::TexUnified3DFloatFloatLevel:
  267. case NVPTXISD::TexUnified3DFloatFloatGrad:
  268. case NVPTXISD::TexUnified3DS32S32:
  269. case NVPTXISD::TexUnified3DS32Float:
  270. case NVPTXISD::TexUnified3DS32FloatLevel:
  271. case NVPTXISD::TexUnified3DS32FloatGrad:
  272. case NVPTXISD::TexUnified3DU32S32:
  273. case NVPTXISD::TexUnified3DU32Float:
  274. case NVPTXISD::TexUnified3DU32FloatLevel:
  275. case NVPTXISD::TexUnified3DU32FloatGrad:
  276. case NVPTXISD::TexUnifiedCubeFloatFloat:
  277. case NVPTXISD::TexUnifiedCubeFloatFloatLevel:
  278. case NVPTXISD::TexUnifiedCubeS32Float:
  279. case NVPTXISD::TexUnifiedCubeS32FloatLevel:
  280. case NVPTXISD::TexUnifiedCubeU32Float:
  281. case NVPTXISD::TexUnifiedCubeU32FloatLevel:
  282. case NVPTXISD::TexUnifiedCubeArrayFloatFloat:
  283. case NVPTXISD::TexUnifiedCubeArrayFloatFloatLevel:
  284. case NVPTXISD::TexUnifiedCubeArrayS32Float:
  285. case NVPTXISD::TexUnifiedCubeArrayS32FloatLevel:
  286. case NVPTXISD::TexUnifiedCubeArrayU32Float:
  287. case NVPTXISD::TexUnifiedCubeArrayU32FloatLevel:
  288. case NVPTXISD::Tld4UnifiedR2DFloatFloat:
  289. case NVPTXISD::Tld4UnifiedG2DFloatFloat:
  290. case NVPTXISD::Tld4UnifiedB2DFloatFloat:
  291. case NVPTXISD::Tld4UnifiedA2DFloatFloat:
  292. case NVPTXISD::Tld4UnifiedR2DS64Float:
  293. case NVPTXISD::Tld4UnifiedG2DS64Float:
  294. case NVPTXISD::Tld4UnifiedB2DS64Float:
  295. case NVPTXISD::Tld4UnifiedA2DS64Float:
  296. case NVPTXISD::Tld4UnifiedR2DU64Float:
  297. case NVPTXISD::Tld4UnifiedG2DU64Float:
  298. case NVPTXISD::Tld4UnifiedB2DU64Float:
  299. case NVPTXISD::Tld4UnifiedA2DU64Float:
  300. if (tryTextureIntrinsic(N))
  301. return;
  302. break;
  303. case NVPTXISD::Suld1DI8Clamp:
  304. case NVPTXISD::Suld1DI16Clamp:
  305. case NVPTXISD::Suld1DI32Clamp:
  306. case NVPTXISD::Suld1DI64Clamp:
  307. case NVPTXISD::Suld1DV2I8Clamp:
  308. case NVPTXISD::Suld1DV2I16Clamp:
  309. case NVPTXISD::Suld1DV2I32Clamp:
  310. case NVPTXISD::Suld1DV2I64Clamp:
  311. case NVPTXISD::Suld1DV4I8Clamp:
  312. case NVPTXISD::Suld1DV4I16Clamp:
  313. case NVPTXISD::Suld1DV4I32Clamp:
  314. case NVPTXISD::Suld1DArrayI8Clamp:
  315. case NVPTXISD::Suld1DArrayI16Clamp:
  316. case NVPTXISD::Suld1DArrayI32Clamp:
  317. case NVPTXISD::Suld1DArrayI64Clamp:
  318. case NVPTXISD::Suld1DArrayV2I8Clamp:
  319. case NVPTXISD::Suld1DArrayV2I16Clamp:
  320. case NVPTXISD::Suld1DArrayV2I32Clamp:
  321. case NVPTXISD::Suld1DArrayV2I64Clamp:
  322. case NVPTXISD::Suld1DArrayV4I8Clamp:
  323. case NVPTXISD::Suld1DArrayV4I16Clamp:
  324. case NVPTXISD::Suld1DArrayV4I32Clamp:
  325. case NVPTXISD::Suld2DI8Clamp:
  326. case NVPTXISD::Suld2DI16Clamp:
  327. case NVPTXISD::Suld2DI32Clamp:
  328. case NVPTXISD::Suld2DI64Clamp:
  329. case NVPTXISD::Suld2DV2I8Clamp:
  330. case NVPTXISD::Suld2DV2I16Clamp:
  331. case NVPTXISD::Suld2DV2I32Clamp:
  332. case NVPTXISD::Suld2DV2I64Clamp:
  333. case NVPTXISD::Suld2DV4I8Clamp:
  334. case NVPTXISD::Suld2DV4I16Clamp:
  335. case NVPTXISD::Suld2DV4I32Clamp:
  336. case NVPTXISD::Suld2DArrayI8Clamp:
  337. case NVPTXISD::Suld2DArrayI16Clamp:
  338. case NVPTXISD::Suld2DArrayI32Clamp:
  339. case NVPTXISD::Suld2DArrayI64Clamp:
  340. case NVPTXISD::Suld2DArrayV2I8Clamp:
  341. case NVPTXISD::Suld2DArrayV2I16Clamp:
  342. case NVPTXISD::Suld2DArrayV2I32Clamp:
  343. case NVPTXISD::Suld2DArrayV2I64Clamp:
  344. case NVPTXISD::Suld2DArrayV4I8Clamp:
  345. case NVPTXISD::Suld2DArrayV4I16Clamp:
  346. case NVPTXISD::Suld2DArrayV4I32Clamp:
  347. case NVPTXISD::Suld3DI8Clamp:
  348. case NVPTXISD::Suld3DI16Clamp:
  349. case NVPTXISD::Suld3DI32Clamp:
  350. case NVPTXISD::Suld3DI64Clamp:
  351. case NVPTXISD::Suld3DV2I8Clamp:
  352. case NVPTXISD::Suld3DV2I16Clamp:
  353. case NVPTXISD::Suld3DV2I32Clamp:
  354. case NVPTXISD::Suld3DV2I64Clamp:
  355. case NVPTXISD::Suld3DV4I8Clamp:
  356. case NVPTXISD::Suld3DV4I16Clamp:
  357. case NVPTXISD::Suld3DV4I32Clamp:
  358. case NVPTXISD::Suld1DI8Trap:
  359. case NVPTXISD::Suld1DI16Trap:
  360. case NVPTXISD::Suld1DI32Trap:
  361. case NVPTXISD::Suld1DI64Trap:
  362. case NVPTXISD::Suld1DV2I8Trap:
  363. case NVPTXISD::Suld1DV2I16Trap:
  364. case NVPTXISD::Suld1DV2I32Trap:
  365. case NVPTXISD::Suld1DV2I64Trap:
  366. case NVPTXISD::Suld1DV4I8Trap:
  367. case NVPTXISD::Suld1DV4I16Trap:
  368. case NVPTXISD::Suld1DV4I32Trap:
  369. case NVPTXISD::Suld1DArrayI8Trap:
  370. case NVPTXISD::Suld1DArrayI16Trap:
  371. case NVPTXISD::Suld1DArrayI32Trap:
  372. case NVPTXISD::Suld1DArrayI64Trap:
  373. case NVPTXISD::Suld1DArrayV2I8Trap:
  374. case NVPTXISD::Suld1DArrayV2I16Trap:
  375. case NVPTXISD::Suld1DArrayV2I32Trap:
  376. case NVPTXISD::Suld1DArrayV2I64Trap:
  377. case NVPTXISD::Suld1DArrayV4I8Trap:
  378. case NVPTXISD::Suld1DArrayV4I16Trap:
  379. case NVPTXISD::Suld1DArrayV4I32Trap:
  380. case NVPTXISD::Suld2DI8Trap:
  381. case NVPTXISD::Suld2DI16Trap:
  382. case NVPTXISD::Suld2DI32Trap:
  383. case NVPTXISD::Suld2DI64Trap:
  384. case NVPTXISD::Suld2DV2I8Trap:
  385. case NVPTXISD::Suld2DV2I16Trap:
  386. case NVPTXISD::Suld2DV2I32Trap:
  387. case NVPTXISD::Suld2DV2I64Trap:
  388. case NVPTXISD::Suld2DV4I8Trap:
  389. case NVPTXISD::Suld2DV4I16Trap:
  390. case NVPTXISD::Suld2DV4I32Trap:
  391. case NVPTXISD::Suld2DArrayI8Trap:
  392. case NVPTXISD::Suld2DArrayI16Trap:
  393. case NVPTXISD::Suld2DArrayI32Trap:
  394. case NVPTXISD::Suld2DArrayI64Trap:
  395. case NVPTXISD::Suld2DArrayV2I8Trap:
  396. case NVPTXISD::Suld2DArrayV2I16Trap:
  397. case NVPTXISD::Suld2DArrayV2I32Trap:
  398. case NVPTXISD::Suld2DArrayV2I64Trap:
  399. case NVPTXISD::Suld2DArrayV4I8Trap:
  400. case NVPTXISD::Suld2DArrayV4I16Trap:
  401. case NVPTXISD::Suld2DArrayV4I32Trap:
  402. case NVPTXISD::Suld3DI8Trap:
  403. case NVPTXISD::Suld3DI16Trap:
  404. case NVPTXISD::Suld3DI32Trap:
  405. case NVPTXISD::Suld3DI64Trap:
  406. case NVPTXISD::Suld3DV2I8Trap:
  407. case NVPTXISD::Suld3DV2I16Trap:
  408. case NVPTXISD::Suld3DV2I32Trap:
  409. case NVPTXISD::Suld3DV2I64Trap:
  410. case NVPTXISD::Suld3DV4I8Trap:
  411. case NVPTXISD::Suld3DV4I16Trap:
  412. case NVPTXISD::Suld3DV4I32Trap:
  413. case NVPTXISD::Suld1DI8Zero:
  414. case NVPTXISD::Suld1DI16Zero:
  415. case NVPTXISD::Suld1DI32Zero:
  416. case NVPTXISD::Suld1DI64Zero:
  417. case NVPTXISD::Suld1DV2I8Zero:
  418. case NVPTXISD::Suld1DV2I16Zero:
  419. case NVPTXISD::Suld1DV2I32Zero:
  420. case NVPTXISD::Suld1DV2I64Zero:
  421. case NVPTXISD::Suld1DV4I8Zero:
  422. case NVPTXISD::Suld1DV4I16Zero:
  423. case NVPTXISD::Suld1DV4I32Zero:
  424. case NVPTXISD::Suld1DArrayI8Zero:
  425. case NVPTXISD::Suld1DArrayI16Zero:
  426. case NVPTXISD::Suld1DArrayI32Zero:
  427. case NVPTXISD::Suld1DArrayI64Zero:
  428. case NVPTXISD::Suld1DArrayV2I8Zero:
  429. case NVPTXISD::Suld1DArrayV2I16Zero:
  430. case NVPTXISD::Suld1DArrayV2I32Zero:
  431. case NVPTXISD::Suld1DArrayV2I64Zero:
  432. case NVPTXISD::Suld1DArrayV4I8Zero:
  433. case NVPTXISD::Suld1DArrayV4I16Zero:
  434. case NVPTXISD::Suld1DArrayV4I32Zero:
  435. case NVPTXISD::Suld2DI8Zero:
  436. case NVPTXISD::Suld2DI16Zero:
  437. case NVPTXISD::Suld2DI32Zero:
  438. case NVPTXISD::Suld2DI64Zero:
  439. case NVPTXISD::Suld2DV2I8Zero:
  440. case NVPTXISD::Suld2DV2I16Zero:
  441. case NVPTXISD::Suld2DV2I32Zero:
  442. case NVPTXISD::Suld2DV2I64Zero:
  443. case NVPTXISD::Suld2DV4I8Zero:
  444. case NVPTXISD::Suld2DV4I16Zero:
  445. case NVPTXISD::Suld2DV4I32Zero:
  446. case NVPTXISD::Suld2DArrayI8Zero:
  447. case NVPTXISD::Suld2DArrayI16Zero:
  448. case NVPTXISD::Suld2DArrayI32Zero:
  449. case NVPTXISD::Suld2DArrayI64Zero:
  450. case NVPTXISD::Suld2DArrayV2I8Zero:
  451. case NVPTXISD::Suld2DArrayV2I16Zero:
  452. case NVPTXISD::Suld2DArrayV2I32Zero:
  453. case NVPTXISD::Suld2DArrayV2I64Zero:
  454. case NVPTXISD::Suld2DArrayV4I8Zero:
  455. case NVPTXISD::Suld2DArrayV4I16Zero:
  456. case NVPTXISD::Suld2DArrayV4I32Zero:
  457. case NVPTXISD::Suld3DI8Zero:
  458. case NVPTXISD::Suld3DI16Zero:
  459. case NVPTXISD::Suld3DI32Zero:
  460. case NVPTXISD::Suld3DI64Zero:
  461. case NVPTXISD::Suld3DV2I8Zero:
  462. case NVPTXISD::Suld3DV2I16Zero:
  463. case NVPTXISD::Suld3DV2I32Zero:
  464. case NVPTXISD::Suld3DV2I64Zero:
  465. case NVPTXISD::Suld3DV4I8Zero:
  466. case NVPTXISD::Suld3DV4I16Zero:
  467. case NVPTXISD::Suld3DV4I32Zero:
  468. if (trySurfaceIntrinsic(N))
  469. return;
  470. break;
  471. case ISD::AND:
  472. case ISD::SRA:
  473. case ISD::SRL:
  474. // Try to select BFE
  475. if (tryBFE(N))
  476. return;
  477. break;
  478. case ISD::ADDRSPACECAST:
  479. SelectAddrSpaceCast(N);
  480. return;
  481. case ISD::ConstantFP:
  482. if (tryConstantFP16(N))
  483. return;
  484. break;
  485. default:
  486. break;
  487. }
  488. SelectCode(N);
  489. }
  490. bool NVPTXDAGToDAGISel::tryIntrinsicChain(SDNode *N) {
  491. unsigned IID = cast<ConstantSDNode>(N->getOperand(1))->getZExtValue();
  492. switch (IID) {
  493. default:
  494. return false;
  495. case Intrinsic::nvvm_ldg_global_f:
  496. case Intrinsic::nvvm_ldg_global_i:
  497. case Intrinsic::nvvm_ldg_global_p:
  498. case Intrinsic::nvvm_ldu_global_f:
  499. case Intrinsic::nvvm_ldu_global_i:
  500. case Intrinsic::nvvm_ldu_global_p:
  501. return tryLDGLDU(N);
  502. }
  503. }
  504. // There's no way to specify FP16 immediates in .f16 ops, so we have to
  505. // load them into an .f16 register first.
  506. bool NVPTXDAGToDAGISel::tryConstantFP16(SDNode *N) {
  507. if (N->getValueType(0) != MVT::f16)
  508. return false;
  509. SDValue Val = CurDAG->getTargetConstantFP(
  510. cast<ConstantFPSDNode>(N)->getValueAPF(), SDLoc(N), MVT::f16);
  511. SDNode *LoadConstF16 =
  512. CurDAG->getMachineNode(NVPTX::LOAD_CONST_F16, SDLoc(N), MVT::f16, Val);
  513. ReplaceNode(N, LoadConstF16);
  514. return true;
  515. }
  516. // Map ISD:CONDCODE value to appropriate CmpMode expected by
  517. // NVPTXInstPrinter::printCmpMode()
  518. static unsigned getPTXCmpMode(const CondCodeSDNode &CondCode, bool FTZ) {
  519. using NVPTX::PTXCmpMode::CmpMode;
  520. unsigned PTXCmpMode = [](ISD::CondCode CC) {
  521. switch (CC) {
  522. default:
  523. llvm_unreachable("Unexpected condition code.");
  524. case ISD::SETOEQ:
  525. return CmpMode::EQ;
  526. case ISD::SETOGT:
  527. return CmpMode::GT;
  528. case ISD::SETOGE:
  529. return CmpMode::GE;
  530. case ISD::SETOLT:
  531. return CmpMode::LT;
  532. case ISD::SETOLE:
  533. return CmpMode::LE;
  534. case ISD::SETONE:
  535. return CmpMode::NE;
  536. case ISD::SETO:
  537. return CmpMode::NUM;
  538. case ISD::SETUO:
  539. return CmpMode::NotANumber;
  540. case ISD::SETUEQ:
  541. return CmpMode::EQU;
  542. case ISD::SETUGT:
  543. return CmpMode::GTU;
  544. case ISD::SETUGE:
  545. return CmpMode::GEU;
  546. case ISD::SETULT:
  547. return CmpMode::LTU;
  548. case ISD::SETULE:
  549. return CmpMode::LEU;
  550. case ISD::SETUNE:
  551. return CmpMode::NEU;
  552. case ISD::SETEQ:
  553. return CmpMode::EQ;
  554. case ISD::SETGT:
  555. return CmpMode::GT;
  556. case ISD::SETGE:
  557. return CmpMode::GE;
  558. case ISD::SETLT:
  559. return CmpMode::LT;
  560. case ISD::SETLE:
  561. return CmpMode::LE;
  562. case ISD::SETNE:
  563. return CmpMode::NE;
  564. }
  565. }(CondCode.get());
  566. if (FTZ)
  567. PTXCmpMode |= NVPTX::PTXCmpMode::FTZ_FLAG;
  568. return PTXCmpMode;
  569. }
  570. bool NVPTXDAGToDAGISel::SelectSETP_F16X2(SDNode *N) {
  571. unsigned PTXCmpMode =
  572. getPTXCmpMode(*cast<CondCodeSDNode>(N->getOperand(2)), useF32FTZ());
  573. SDLoc DL(N);
  574. SDNode *SetP = CurDAG->getMachineNode(
  575. NVPTX::SETP_f16x2rr, DL, MVT::i1, MVT::i1, N->getOperand(0),
  576. N->getOperand(1), CurDAG->getTargetConstant(PTXCmpMode, DL, MVT::i32));
  577. ReplaceNode(N, SetP);
  578. return true;
  579. }
  580. // Find all instances of extract_vector_elt that use this v2f16 vector
  581. // and coalesce them into a scattering move instruction.
  582. bool NVPTXDAGToDAGISel::tryEXTRACT_VECTOR_ELEMENT(SDNode *N) {
  583. SDValue Vector = N->getOperand(0);
  584. // We only care about f16x2 as it's the only real vector type we
  585. // need to deal with.
  586. if (Vector.getSimpleValueType() != MVT::v2f16)
  587. return false;
  588. // Find and record all uses of this vector that extract element 0 or 1.
  589. SmallVector<SDNode *, 4> E0, E1;
  590. for (auto U : Vector.getNode()->uses()) {
  591. if (U->getOpcode() != ISD::EXTRACT_VECTOR_ELT)
  592. continue;
  593. if (U->getOperand(0) != Vector)
  594. continue;
  595. if (const ConstantSDNode *IdxConst =
  596. dyn_cast<ConstantSDNode>(U->getOperand(1))) {
  597. if (IdxConst->getZExtValue() == 0)
  598. E0.push_back(U);
  599. else if (IdxConst->getZExtValue() == 1)
  600. E1.push_back(U);
  601. else
  602. llvm_unreachable("Invalid vector index.");
  603. }
  604. }
  605. // There's no point scattering f16x2 if we only ever access one
  606. // element of it.
  607. if (E0.empty() || E1.empty())
  608. return false;
  609. unsigned Op = NVPTX::SplitF16x2;
  610. // If the vector has been BITCAST'ed from i32, we can use original
  611. // value directly and avoid register-to-register move.
  612. SDValue Source = Vector;
  613. if (Vector->getOpcode() == ISD::BITCAST) {
  614. Op = NVPTX::SplitI32toF16x2;
  615. Source = Vector->getOperand(0);
  616. }
  617. // Merge (f16 extractelt(V, 0), f16 extractelt(V,1))
  618. // into f16,f16 SplitF16x2(V)
  619. SDNode *ScatterOp =
  620. CurDAG->getMachineNode(Op, SDLoc(N), MVT::f16, MVT::f16, Source);
  621. for (auto *Node : E0)
  622. ReplaceUses(SDValue(Node, 0), SDValue(ScatterOp, 0));
  623. for (auto *Node : E1)
  624. ReplaceUses(SDValue(Node, 0), SDValue(ScatterOp, 1));
  625. return true;
  626. }
  627. static unsigned int getCodeAddrSpace(MemSDNode *N) {
  628. const Value *Src = N->getMemOperand()->getValue();
  629. if (!Src)
  630. return NVPTX::PTXLdStInstCode::GENERIC;
  631. if (auto *PT = dyn_cast<PointerType>(Src->getType())) {
  632. switch (PT->getAddressSpace()) {
  633. case llvm::ADDRESS_SPACE_LOCAL: return NVPTX::PTXLdStInstCode::LOCAL;
  634. case llvm::ADDRESS_SPACE_GLOBAL: return NVPTX::PTXLdStInstCode::GLOBAL;
  635. case llvm::ADDRESS_SPACE_SHARED: return NVPTX::PTXLdStInstCode::SHARED;
  636. case llvm::ADDRESS_SPACE_GENERIC: return NVPTX::PTXLdStInstCode::GENERIC;
  637. case llvm::ADDRESS_SPACE_PARAM: return NVPTX::PTXLdStInstCode::PARAM;
  638. case llvm::ADDRESS_SPACE_CONST: return NVPTX::PTXLdStInstCode::CONSTANT;
  639. default: break;
  640. }
  641. }
  642. return NVPTX::PTXLdStInstCode::GENERIC;
  643. }
  644. static bool canLowerToLDG(MemSDNode *N, const NVPTXSubtarget &Subtarget,
  645. unsigned CodeAddrSpace, MachineFunction *F) {
  646. // We use ldg (i.e. ld.global.nc) for invariant loads from the global address
  647. // space.
  648. //
  649. // We have two ways of identifying invariant loads: Loads may be explicitly
  650. // marked as invariant, or we may infer them to be invariant.
  651. //
  652. // We currently infer invariance for loads from
  653. // - constant global variables, and
  654. // - kernel function pointer params that are noalias (i.e. __restrict) and
  655. // never written to.
  656. //
  657. // TODO: Perform a more powerful invariance analysis (ideally IPO, and ideally
  658. // not during the SelectionDAG phase).
  659. //
  660. // TODO: Infer invariance only at -O2. We still want to use ldg at -O0 for
  661. // explicitly invariant loads because these are how clang tells us to use ldg
  662. // when the user uses a builtin.
  663. if (!Subtarget.hasLDG() || CodeAddrSpace != NVPTX::PTXLdStInstCode::GLOBAL)
  664. return false;
  665. if (N->isInvariant())
  666. return true;
  667. bool IsKernelFn = isKernelFunction(F->getFunction());
  668. // We use getUnderlyingObjects() here instead of getUnderlyingObject() mainly
  669. // because the former looks through phi nodes while the latter does not. We
  670. // need to look through phi nodes to handle pointer induction variables.
  671. SmallVector<const Value *, 8> Objs;
  672. getUnderlyingObjects(N->getMemOperand()->getValue(), Objs);
  673. return all_of(Objs, [&](const Value *V) {
  674. if (auto *A = dyn_cast<const Argument>(V))
  675. return IsKernelFn && A->onlyReadsMemory() && A->hasNoAliasAttr();
  676. if (auto *GV = dyn_cast<const GlobalVariable>(V))
  677. return GV->isConstant();
  678. return false;
  679. });
  680. }
  681. bool NVPTXDAGToDAGISel::tryIntrinsicNoChain(SDNode *N) {
  682. unsigned IID = cast<ConstantSDNode>(N->getOperand(0))->getZExtValue();
  683. switch (IID) {
  684. default:
  685. return false;
  686. case Intrinsic::nvvm_texsurf_handle_internal:
  687. SelectTexSurfHandle(N);
  688. return true;
  689. }
  690. }
  691. void NVPTXDAGToDAGISel::SelectTexSurfHandle(SDNode *N) {
  692. // Op 0 is the intrinsic ID
  693. SDValue Wrapper = N->getOperand(1);
  694. SDValue GlobalVal = Wrapper.getOperand(0);
  695. ReplaceNode(N, CurDAG->getMachineNode(NVPTX::texsurf_handles, SDLoc(N),
  696. MVT::i64, GlobalVal));
  697. }
  698. void NVPTXDAGToDAGISel::SelectAddrSpaceCast(SDNode *N) {
  699. SDValue Src = N->getOperand(0);
  700. AddrSpaceCastSDNode *CastN = cast<AddrSpaceCastSDNode>(N);
  701. unsigned SrcAddrSpace = CastN->getSrcAddressSpace();
  702. unsigned DstAddrSpace = CastN->getDestAddressSpace();
  703. assert(SrcAddrSpace != DstAddrSpace &&
  704. "addrspacecast must be between different address spaces");
  705. if (DstAddrSpace == ADDRESS_SPACE_GENERIC) {
  706. // Specific to generic
  707. unsigned Opc;
  708. switch (SrcAddrSpace) {
  709. default: report_fatal_error("Bad address space in addrspacecast");
  710. case ADDRESS_SPACE_GLOBAL:
  711. Opc = TM.is64Bit() ? NVPTX::cvta_global_yes_64 : NVPTX::cvta_global_yes;
  712. break;
  713. case ADDRESS_SPACE_SHARED:
  714. Opc = TM.is64Bit() ? (useShortPointers() ? NVPTX::cvta_shared_yes_6432
  715. : NVPTX::cvta_shared_yes_64)
  716. : NVPTX::cvta_shared_yes;
  717. break;
  718. case ADDRESS_SPACE_CONST:
  719. Opc = TM.is64Bit() ? (useShortPointers() ? NVPTX::cvta_const_yes_6432
  720. : NVPTX::cvta_const_yes_64)
  721. : NVPTX::cvta_const_yes;
  722. break;
  723. case ADDRESS_SPACE_LOCAL:
  724. Opc = TM.is64Bit() ? (useShortPointers() ? NVPTX::cvta_local_yes_6432
  725. : NVPTX::cvta_local_yes_64)
  726. : NVPTX::cvta_local_yes;
  727. break;
  728. }
  729. ReplaceNode(N, CurDAG->getMachineNode(Opc, SDLoc(N), N->getValueType(0),
  730. Src));
  731. return;
  732. } else {
  733. // Generic to specific
  734. if (SrcAddrSpace != 0)
  735. report_fatal_error("Cannot cast between two non-generic address spaces");
  736. unsigned Opc;
  737. switch (DstAddrSpace) {
  738. default: report_fatal_error("Bad address space in addrspacecast");
  739. case ADDRESS_SPACE_GLOBAL:
  740. Opc = TM.is64Bit() ? NVPTX::cvta_to_global_yes_64
  741. : NVPTX::cvta_to_global_yes;
  742. break;
  743. case ADDRESS_SPACE_SHARED:
  744. Opc = TM.is64Bit() ? (useShortPointers() ? NVPTX::cvta_to_shared_yes_3264
  745. : NVPTX::cvta_to_shared_yes_64)
  746. : NVPTX::cvta_to_shared_yes;
  747. break;
  748. case ADDRESS_SPACE_CONST:
  749. Opc = TM.is64Bit() ? (useShortPointers() ? NVPTX::cvta_to_const_yes_3264
  750. : NVPTX::cvta_to_const_yes_64)
  751. : NVPTX::cvta_to_const_yes;
  752. break;
  753. case ADDRESS_SPACE_LOCAL:
  754. Opc = TM.is64Bit() ? (useShortPointers() ? NVPTX::cvta_to_local_yes_3264
  755. : NVPTX::cvta_to_local_yes_64)
  756. : NVPTX::cvta_to_local_yes;
  757. break;
  758. case ADDRESS_SPACE_PARAM:
  759. Opc = TM.is64Bit() ? NVPTX::nvvm_ptr_gen_to_param_64
  760. : NVPTX::nvvm_ptr_gen_to_param;
  761. break;
  762. }
  763. ReplaceNode(N, CurDAG->getMachineNode(Opc, SDLoc(N), N->getValueType(0),
  764. Src));
  765. return;
  766. }
  767. }
  768. // Helper function template to reduce amount of boilerplate code for
  769. // opcode selection.
  770. static Optional<unsigned> pickOpcodeForVT(
  771. MVT::SimpleValueType VT, unsigned Opcode_i8, unsigned Opcode_i16,
  772. unsigned Opcode_i32, Optional<unsigned> Opcode_i64, unsigned Opcode_f16,
  773. unsigned Opcode_f16x2, unsigned Opcode_f32, Optional<unsigned> Opcode_f64) {
  774. switch (VT) {
  775. case MVT::i1:
  776. case MVT::i8:
  777. return Opcode_i8;
  778. case MVT::i16:
  779. return Opcode_i16;
  780. case MVT::i32:
  781. return Opcode_i32;
  782. case MVT::i64:
  783. return Opcode_i64;
  784. case MVT::f16:
  785. return Opcode_f16;
  786. case MVT::v2f16:
  787. return Opcode_f16x2;
  788. case MVT::f32:
  789. return Opcode_f32;
  790. case MVT::f64:
  791. return Opcode_f64;
  792. default:
  793. return None;
  794. }
  795. }
  796. bool NVPTXDAGToDAGISel::tryLoad(SDNode *N) {
  797. SDLoc dl(N);
  798. MemSDNode *LD = cast<MemSDNode>(N);
  799. assert(LD->readMem() && "Expected load");
  800. LoadSDNode *PlainLoad = dyn_cast<LoadSDNode>(N);
  801. EVT LoadedVT = LD->getMemoryVT();
  802. SDNode *NVPTXLD = nullptr;
  803. // do not support pre/post inc/dec
  804. if (PlainLoad && PlainLoad->isIndexed())
  805. return false;
  806. if (!LoadedVT.isSimple())
  807. return false;
  808. AtomicOrdering Ordering = LD->getSuccessOrdering();
  809. // In order to lower atomic loads with stronger guarantees we would need to
  810. // use load.acquire or insert fences. However these features were only added
  811. // with PTX ISA 6.0 / sm_70.
  812. // TODO: Check if we can actually use the new instructions and implement them.
  813. if (isStrongerThanMonotonic(Ordering))
  814. return false;
  815. // Address Space Setting
  816. unsigned int CodeAddrSpace = getCodeAddrSpace(LD);
  817. if (canLowerToLDG(LD, *Subtarget, CodeAddrSpace, MF)) {
  818. return tryLDGLDU(N);
  819. }
  820. unsigned int PointerSize =
  821. CurDAG->getDataLayout().getPointerSizeInBits(LD->getAddressSpace());
  822. // Volatile Setting
  823. // - .volatile is only available for .global and .shared
  824. // - .volatile has the same memory synchronization semantics as .relaxed.sys
  825. bool isVolatile = LD->isVolatile() || Ordering == AtomicOrdering::Monotonic;
  826. if (CodeAddrSpace != NVPTX::PTXLdStInstCode::GLOBAL &&
  827. CodeAddrSpace != NVPTX::PTXLdStInstCode::SHARED &&
  828. CodeAddrSpace != NVPTX::PTXLdStInstCode::GENERIC)
  829. isVolatile = false;
  830. // Type Setting: fromType + fromTypeWidth
  831. //
  832. // Sign : ISD::SEXTLOAD
  833. // Unsign : ISD::ZEXTLOAD, ISD::NON_EXTLOAD or ISD::EXTLOAD and the
  834. // type is integer
  835. // Float : ISD::NON_EXTLOAD or ISD::EXTLOAD and the type is float
  836. MVT SimpleVT = LoadedVT.getSimpleVT();
  837. MVT ScalarVT = SimpleVT.getScalarType();
  838. // Read at least 8 bits (predicates are stored as 8-bit values)
  839. unsigned fromTypeWidth = std::max(8U, (unsigned)ScalarVT.getSizeInBits());
  840. unsigned int fromType;
  841. // Vector Setting
  842. unsigned vecType = NVPTX::PTXLdStInstCode::Scalar;
  843. if (SimpleVT.isVector()) {
  844. assert(LoadedVT == MVT::v2f16 && "Unexpected vector type");
  845. // v2f16 is loaded using ld.b32
  846. fromTypeWidth = 32;
  847. }
  848. if (PlainLoad && (PlainLoad->getExtensionType() == ISD::SEXTLOAD))
  849. fromType = NVPTX::PTXLdStInstCode::Signed;
  850. else if (ScalarVT.isFloatingPoint())
  851. // f16 uses .b16 as its storage type.
  852. fromType = ScalarVT.SimpleTy == MVT::f16 ? NVPTX::PTXLdStInstCode::Untyped
  853. : NVPTX::PTXLdStInstCode::Float;
  854. else
  855. fromType = NVPTX::PTXLdStInstCode::Unsigned;
  856. // Create the machine instruction DAG
  857. SDValue Chain = N->getOperand(0);
  858. SDValue N1 = N->getOperand(1);
  859. SDValue Addr;
  860. SDValue Offset, Base;
  861. Optional<unsigned> Opcode;
  862. MVT::SimpleValueType TargetVT = LD->getSimpleValueType(0).SimpleTy;
  863. if (SelectDirectAddr(N1, Addr)) {
  864. Opcode = pickOpcodeForVT(
  865. TargetVT, NVPTX::LD_i8_avar, NVPTX::LD_i16_avar, NVPTX::LD_i32_avar,
  866. NVPTX::LD_i64_avar, NVPTX::LD_f16_avar, NVPTX::LD_f16x2_avar,
  867. NVPTX::LD_f32_avar, NVPTX::LD_f64_avar);
  868. if (!Opcode)
  869. return false;
  870. SDValue Ops[] = { getI32Imm(isVolatile, dl), getI32Imm(CodeAddrSpace, dl),
  871. getI32Imm(vecType, dl), getI32Imm(fromType, dl),
  872. getI32Imm(fromTypeWidth, dl), Addr, Chain };
  873. NVPTXLD = CurDAG->getMachineNode(Opcode.getValue(), dl, TargetVT,
  874. MVT::Other, Ops);
  875. } else if (PointerSize == 64 ? SelectADDRsi64(N1.getNode(), N1, Base, Offset)
  876. : SelectADDRsi(N1.getNode(), N1, Base, Offset)) {
  877. Opcode = pickOpcodeForVT(TargetVT, NVPTX::LD_i8_asi, NVPTX::LD_i16_asi,
  878. NVPTX::LD_i32_asi, NVPTX::LD_i64_asi,
  879. NVPTX::LD_f16_asi, NVPTX::LD_f16x2_asi,
  880. NVPTX::LD_f32_asi, NVPTX::LD_f64_asi);
  881. if (!Opcode)
  882. return false;
  883. SDValue Ops[] = { getI32Imm(isVolatile, dl), getI32Imm(CodeAddrSpace, dl),
  884. getI32Imm(vecType, dl), getI32Imm(fromType, dl),
  885. getI32Imm(fromTypeWidth, dl), Base, Offset, Chain };
  886. NVPTXLD = CurDAG->getMachineNode(Opcode.getValue(), dl, TargetVT,
  887. MVT::Other, Ops);
  888. } else if (PointerSize == 64 ? SelectADDRri64(N1.getNode(), N1, Base, Offset)
  889. : SelectADDRri(N1.getNode(), N1, Base, Offset)) {
  890. if (PointerSize == 64)
  891. Opcode = pickOpcodeForVT(
  892. TargetVT, NVPTX::LD_i8_ari_64, NVPTX::LD_i16_ari_64,
  893. NVPTX::LD_i32_ari_64, NVPTX::LD_i64_ari_64, NVPTX::LD_f16_ari_64,
  894. NVPTX::LD_f16x2_ari_64, NVPTX::LD_f32_ari_64, NVPTX::LD_f64_ari_64);
  895. else
  896. Opcode = pickOpcodeForVT(
  897. TargetVT, NVPTX::LD_i8_ari, NVPTX::LD_i16_ari, NVPTX::LD_i32_ari,
  898. NVPTX::LD_i64_ari, NVPTX::LD_f16_ari, NVPTX::LD_f16x2_ari,
  899. NVPTX::LD_f32_ari, NVPTX::LD_f64_ari);
  900. if (!Opcode)
  901. return false;
  902. SDValue Ops[] = { getI32Imm(isVolatile, dl), getI32Imm(CodeAddrSpace, dl),
  903. getI32Imm(vecType, dl), getI32Imm(fromType, dl),
  904. getI32Imm(fromTypeWidth, dl), Base, Offset, Chain };
  905. NVPTXLD = CurDAG->getMachineNode(Opcode.getValue(), dl, TargetVT,
  906. MVT::Other, Ops);
  907. } else {
  908. if (PointerSize == 64)
  909. Opcode = pickOpcodeForVT(
  910. TargetVT, NVPTX::LD_i8_areg_64, NVPTX::LD_i16_areg_64,
  911. NVPTX::LD_i32_areg_64, NVPTX::LD_i64_areg_64, NVPTX::LD_f16_areg_64,
  912. NVPTX::LD_f16x2_areg_64, NVPTX::LD_f32_areg_64,
  913. NVPTX::LD_f64_areg_64);
  914. else
  915. Opcode = pickOpcodeForVT(
  916. TargetVT, NVPTX::LD_i8_areg, NVPTX::LD_i16_areg, NVPTX::LD_i32_areg,
  917. NVPTX::LD_i64_areg, NVPTX::LD_f16_areg, NVPTX::LD_f16x2_areg,
  918. NVPTX::LD_f32_areg, NVPTX::LD_f64_areg);
  919. if (!Opcode)
  920. return false;
  921. SDValue Ops[] = { getI32Imm(isVolatile, dl), getI32Imm(CodeAddrSpace, dl),
  922. getI32Imm(vecType, dl), getI32Imm(fromType, dl),
  923. getI32Imm(fromTypeWidth, dl), N1, Chain };
  924. NVPTXLD = CurDAG->getMachineNode(Opcode.getValue(), dl, TargetVT,
  925. MVT::Other, Ops);
  926. }
  927. if (!NVPTXLD)
  928. return false;
  929. MachineMemOperand *MemRef = cast<MemSDNode>(N)->getMemOperand();
  930. CurDAG->setNodeMemRefs(cast<MachineSDNode>(NVPTXLD), {MemRef});
  931. ReplaceNode(N, NVPTXLD);
  932. return true;
  933. }
  934. bool NVPTXDAGToDAGISel::tryLoadVector(SDNode *N) {
  935. SDValue Chain = N->getOperand(0);
  936. SDValue Op1 = N->getOperand(1);
  937. SDValue Addr, Offset, Base;
  938. Optional<unsigned> Opcode;
  939. SDLoc DL(N);
  940. SDNode *LD;
  941. MemSDNode *MemSD = cast<MemSDNode>(N);
  942. EVT LoadedVT = MemSD->getMemoryVT();
  943. if (!LoadedVT.isSimple())
  944. return false;
  945. // Address Space Setting
  946. unsigned int CodeAddrSpace = getCodeAddrSpace(MemSD);
  947. if (canLowerToLDG(MemSD, *Subtarget, CodeAddrSpace, MF)) {
  948. return tryLDGLDU(N);
  949. }
  950. unsigned int PointerSize =
  951. CurDAG->getDataLayout().getPointerSizeInBits(MemSD->getAddressSpace());
  952. // Volatile Setting
  953. // - .volatile is only availalble for .global and .shared
  954. bool IsVolatile = MemSD->isVolatile();
  955. if (CodeAddrSpace != NVPTX::PTXLdStInstCode::GLOBAL &&
  956. CodeAddrSpace != NVPTX::PTXLdStInstCode::SHARED &&
  957. CodeAddrSpace != NVPTX::PTXLdStInstCode::GENERIC)
  958. IsVolatile = false;
  959. // Vector Setting
  960. MVT SimpleVT = LoadedVT.getSimpleVT();
  961. // Type Setting: fromType + fromTypeWidth
  962. //
  963. // Sign : ISD::SEXTLOAD
  964. // Unsign : ISD::ZEXTLOAD, ISD::NON_EXTLOAD or ISD::EXTLOAD and the
  965. // type is integer
  966. // Float : ISD::NON_EXTLOAD or ISD::EXTLOAD and the type is float
  967. MVT ScalarVT = SimpleVT.getScalarType();
  968. // Read at least 8 bits (predicates are stored as 8-bit values)
  969. unsigned FromTypeWidth = std::max(8U, (unsigned)ScalarVT.getSizeInBits());
  970. unsigned int FromType;
  971. // The last operand holds the original LoadSDNode::getExtensionType() value
  972. unsigned ExtensionType = cast<ConstantSDNode>(
  973. N->getOperand(N->getNumOperands() - 1))->getZExtValue();
  974. if (ExtensionType == ISD::SEXTLOAD)
  975. FromType = NVPTX::PTXLdStInstCode::Signed;
  976. else if (ScalarVT.isFloatingPoint())
  977. FromType = ScalarVT.SimpleTy == MVT::f16 ? NVPTX::PTXLdStInstCode::Untyped
  978. : NVPTX::PTXLdStInstCode::Float;
  979. else
  980. FromType = NVPTX::PTXLdStInstCode::Unsigned;
  981. unsigned VecType;
  982. switch (N->getOpcode()) {
  983. case NVPTXISD::LoadV2:
  984. VecType = NVPTX::PTXLdStInstCode::V2;
  985. break;
  986. case NVPTXISD::LoadV4:
  987. VecType = NVPTX::PTXLdStInstCode::V4;
  988. break;
  989. default:
  990. return false;
  991. }
  992. EVT EltVT = N->getValueType(0);
  993. // v8f16 is a special case. PTX doesn't have ld.v8.f16
  994. // instruction. Instead, we split the vector into v2f16 chunks and
  995. // load them with ld.v4.b32.
  996. if (EltVT == MVT::v2f16) {
  997. assert(N->getOpcode() == NVPTXISD::LoadV4 && "Unexpected load opcode.");
  998. EltVT = MVT::i32;
  999. FromType = NVPTX::PTXLdStInstCode::Untyped;
  1000. FromTypeWidth = 32;
  1001. }
  1002. if (SelectDirectAddr(Op1, Addr)) {
  1003. switch (N->getOpcode()) {
  1004. default:
  1005. return false;
  1006. case NVPTXISD::LoadV2:
  1007. Opcode = pickOpcodeForVT(EltVT.getSimpleVT().SimpleTy,
  1008. NVPTX::LDV_i8_v2_avar, NVPTX::LDV_i16_v2_avar,
  1009. NVPTX::LDV_i32_v2_avar, NVPTX::LDV_i64_v2_avar,
  1010. NVPTX::LDV_f16_v2_avar, NVPTX::LDV_f16x2_v2_avar,
  1011. NVPTX::LDV_f32_v2_avar, NVPTX::LDV_f64_v2_avar);
  1012. break;
  1013. case NVPTXISD::LoadV4:
  1014. Opcode =
  1015. pickOpcodeForVT(EltVT.getSimpleVT().SimpleTy, NVPTX::LDV_i8_v4_avar,
  1016. NVPTX::LDV_i16_v4_avar, NVPTX::LDV_i32_v4_avar, None,
  1017. NVPTX::LDV_f16_v4_avar, NVPTX::LDV_f16x2_v4_avar,
  1018. NVPTX::LDV_f32_v4_avar, None);
  1019. break;
  1020. }
  1021. if (!Opcode)
  1022. return false;
  1023. SDValue Ops[] = { getI32Imm(IsVolatile, DL), getI32Imm(CodeAddrSpace, DL),
  1024. getI32Imm(VecType, DL), getI32Imm(FromType, DL),
  1025. getI32Imm(FromTypeWidth, DL), Addr, Chain };
  1026. LD = CurDAG->getMachineNode(Opcode.getValue(), DL, N->getVTList(), Ops);
  1027. } else if (PointerSize == 64
  1028. ? SelectADDRsi64(Op1.getNode(), Op1, Base, Offset)
  1029. : SelectADDRsi(Op1.getNode(), Op1, Base, Offset)) {
  1030. switch (N->getOpcode()) {
  1031. default:
  1032. return false;
  1033. case NVPTXISD::LoadV2:
  1034. Opcode = pickOpcodeForVT(EltVT.getSimpleVT().SimpleTy,
  1035. NVPTX::LDV_i8_v2_asi, NVPTX::LDV_i16_v2_asi,
  1036. NVPTX::LDV_i32_v2_asi, NVPTX::LDV_i64_v2_asi,
  1037. NVPTX::LDV_f16_v2_asi, NVPTX::LDV_f16x2_v2_asi,
  1038. NVPTX::LDV_f32_v2_asi, NVPTX::LDV_f64_v2_asi);
  1039. break;
  1040. case NVPTXISD::LoadV4:
  1041. Opcode =
  1042. pickOpcodeForVT(EltVT.getSimpleVT().SimpleTy, NVPTX::LDV_i8_v4_asi,
  1043. NVPTX::LDV_i16_v4_asi, NVPTX::LDV_i32_v4_asi, None,
  1044. NVPTX::LDV_f16_v4_asi, NVPTX::LDV_f16x2_v4_asi,
  1045. NVPTX::LDV_f32_v4_asi, None);
  1046. break;
  1047. }
  1048. if (!Opcode)
  1049. return false;
  1050. SDValue Ops[] = { getI32Imm(IsVolatile, DL), getI32Imm(CodeAddrSpace, DL),
  1051. getI32Imm(VecType, DL), getI32Imm(FromType, DL),
  1052. getI32Imm(FromTypeWidth, DL), Base, Offset, Chain };
  1053. LD = CurDAG->getMachineNode(Opcode.getValue(), DL, N->getVTList(), Ops);
  1054. } else if (PointerSize == 64
  1055. ? SelectADDRri64(Op1.getNode(), Op1, Base, Offset)
  1056. : SelectADDRri(Op1.getNode(), Op1, Base, Offset)) {
  1057. if (PointerSize == 64) {
  1058. switch (N->getOpcode()) {
  1059. default:
  1060. return false;
  1061. case NVPTXISD::LoadV2:
  1062. Opcode = pickOpcodeForVT(
  1063. EltVT.getSimpleVT().SimpleTy, NVPTX::LDV_i8_v2_ari_64,
  1064. NVPTX::LDV_i16_v2_ari_64, NVPTX::LDV_i32_v2_ari_64,
  1065. NVPTX::LDV_i64_v2_ari_64, NVPTX::LDV_f16_v2_ari_64,
  1066. NVPTX::LDV_f16x2_v2_ari_64, NVPTX::LDV_f32_v2_ari_64,
  1067. NVPTX::LDV_f64_v2_ari_64);
  1068. break;
  1069. case NVPTXISD::LoadV4:
  1070. Opcode = pickOpcodeForVT(
  1071. EltVT.getSimpleVT().SimpleTy, NVPTX::LDV_i8_v4_ari_64,
  1072. NVPTX::LDV_i16_v4_ari_64, NVPTX::LDV_i32_v4_ari_64, None,
  1073. NVPTX::LDV_f16_v4_ari_64, NVPTX::LDV_f16x2_v4_ari_64,
  1074. NVPTX::LDV_f32_v4_ari_64, None);
  1075. break;
  1076. }
  1077. } else {
  1078. switch (N->getOpcode()) {
  1079. default:
  1080. return false;
  1081. case NVPTXISD::LoadV2:
  1082. Opcode = pickOpcodeForVT(EltVT.getSimpleVT().SimpleTy,
  1083. NVPTX::LDV_i8_v2_ari, NVPTX::LDV_i16_v2_ari,
  1084. NVPTX::LDV_i32_v2_ari, NVPTX::LDV_i64_v2_ari,
  1085. NVPTX::LDV_f16_v2_ari, NVPTX::LDV_f16x2_v2_ari,
  1086. NVPTX::LDV_f32_v2_ari, NVPTX::LDV_f64_v2_ari);
  1087. break;
  1088. case NVPTXISD::LoadV4:
  1089. Opcode =
  1090. pickOpcodeForVT(EltVT.getSimpleVT().SimpleTy, NVPTX::LDV_i8_v4_ari,
  1091. NVPTX::LDV_i16_v4_ari, NVPTX::LDV_i32_v4_ari, None,
  1092. NVPTX::LDV_f16_v4_ari, NVPTX::LDV_f16x2_v4_ari,
  1093. NVPTX::LDV_f32_v4_ari, None);
  1094. break;
  1095. }
  1096. }
  1097. if (!Opcode)
  1098. return false;
  1099. SDValue Ops[] = { getI32Imm(IsVolatile, DL), getI32Imm(CodeAddrSpace, DL),
  1100. getI32Imm(VecType, DL), getI32Imm(FromType, DL),
  1101. getI32Imm(FromTypeWidth, DL), Base, Offset, Chain };
  1102. LD = CurDAG->getMachineNode(Opcode.getValue(), DL, N->getVTList(), Ops);
  1103. } else {
  1104. if (PointerSize == 64) {
  1105. switch (N->getOpcode()) {
  1106. default:
  1107. return false;
  1108. case NVPTXISD::LoadV2:
  1109. Opcode = pickOpcodeForVT(
  1110. EltVT.getSimpleVT().SimpleTy, NVPTX::LDV_i8_v2_areg_64,
  1111. NVPTX::LDV_i16_v2_areg_64, NVPTX::LDV_i32_v2_areg_64,
  1112. NVPTX::LDV_i64_v2_areg_64, NVPTX::LDV_f16_v2_areg_64,
  1113. NVPTX::LDV_f16x2_v2_areg_64, NVPTX::LDV_f32_v2_areg_64,
  1114. NVPTX::LDV_f64_v2_areg_64);
  1115. break;
  1116. case NVPTXISD::LoadV4:
  1117. Opcode = pickOpcodeForVT(
  1118. EltVT.getSimpleVT().SimpleTy, NVPTX::LDV_i8_v4_areg_64,
  1119. NVPTX::LDV_i16_v4_areg_64, NVPTX::LDV_i32_v4_areg_64, None,
  1120. NVPTX::LDV_f16_v4_areg_64, NVPTX::LDV_f16x2_v4_areg_64,
  1121. NVPTX::LDV_f32_v4_areg_64, None);
  1122. break;
  1123. }
  1124. } else {
  1125. switch (N->getOpcode()) {
  1126. default:
  1127. return false;
  1128. case NVPTXISD::LoadV2:
  1129. Opcode =
  1130. pickOpcodeForVT(EltVT.getSimpleVT().SimpleTy, NVPTX::LDV_i8_v2_areg,
  1131. NVPTX::LDV_i16_v2_areg, NVPTX::LDV_i32_v2_areg,
  1132. NVPTX::LDV_i64_v2_areg, NVPTX::LDV_f16_v2_areg,
  1133. NVPTX::LDV_f16x2_v2_areg, NVPTX::LDV_f32_v2_areg,
  1134. NVPTX::LDV_f64_v2_areg);
  1135. break;
  1136. case NVPTXISD::LoadV4:
  1137. Opcode = pickOpcodeForVT(
  1138. EltVT.getSimpleVT().SimpleTy, NVPTX::LDV_i8_v4_areg,
  1139. NVPTX::LDV_i16_v4_areg, NVPTX::LDV_i32_v4_areg, None,
  1140. NVPTX::LDV_f16_v4_areg, NVPTX::LDV_f16x2_v4_areg,
  1141. NVPTX::LDV_f32_v4_areg, None);
  1142. break;
  1143. }
  1144. }
  1145. if (!Opcode)
  1146. return false;
  1147. SDValue Ops[] = { getI32Imm(IsVolatile, DL), getI32Imm(CodeAddrSpace, DL),
  1148. getI32Imm(VecType, DL), getI32Imm(FromType, DL),
  1149. getI32Imm(FromTypeWidth, DL), Op1, Chain };
  1150. LD = CurDAG->getMachineNode(Opcode.getValue(), DL, N->getVTList(), Ops);
  1151. }
  1152. MachineMemOperand *MemRef = cast<MemSDNode>(N)->getMemOperand();
  1153. CurDAG->setNodeMemRefs(cast<MachineSDNode>(LD), {MemRef});
  1154. ReplaceNode(N, LD);
  1155. return true;
  1156. }
  1157. bool NVPTXDAGToDAGISel::tryLDGLDU(SDNode *N) {
  1158. SDValue Chain = N->getOperand(0);
  1159. SDValue Op1;
  1160. MemSDNode *Mem;
  1161. bool IsLDG = true;
  1162. // If this is an LDG intrinsic, the address is the third operand. If its an
  1163. // LDG/LDU SD node (from custom vector handling), then its the second operand
  1164. if (N->getOpcode() == ISD::INTRINSIC_W_CHAIN) {
  1165. Op1 = N->getOperand(2);
  1166. Mem = cast<MemIntrinsicSDNode>(N);
  1167. unsigned IID = cast<ConstantSDNode>(N->getOperand(1))->getZExtValue();
  1168. switch (IID) {
  1169. default:
  1170. return false;
  1171. case Intrinsic::nvvm_ldg_global_f:
  1172. case Intrinsic::nvvm_ldg_global_i:
  1173. case Intrinsic::nvvm_ldg_global_p:
  1174. IsLDG = true;
  1175. break;
  1176. case Intrinsic::nvvm_ldu_global_f:
  1177. case Intrinsic::nvvm_ldu_global_i:
  1178. case Intrinsic::nvvm_ldu_global_p:
  1179. IsLDG = false;
  1180. break;
  1181. }
  1182. } else {
  1183. Op1 = N->getOperand(1);
  1184. Mem = cast<MemSDNode>(N);
  1185. }
  1186. Optional<unsigned> Opcode;
  1187. SDLoc DL(N);
  1188. SDNode *LD;
  1189. SDValue Base, Offset, Addr;
  1190. EVT EltVT = Mem->getMemoryVT();
  1191. unsigned NumElts = 1;
  1192. if (EltVT.isVector()) {
  1193. NumElts = EltVT.getVectorNumElements();
  1194. EltVT = EltVT.getVectorElementType();
  1195. // vectors of f16 are loaded/stored as multiples of v2f16 elements.
  1196. if (EltVT == MVT::f16 && N->getValueType(0) == MVT::v2f16) {
  1197. assert(NumElts % 2 == 0 && "Vector must have even number of elements");
  1198. EltVT = MVT::v2f16;
  1199. NumElts /= 2;
  1200. }
  1201. }
  1202. // Build the "promoted" result VTList for the load. If we are really loading
  1203. // i8s, then the return type will be promoted to i16 since we do not expose
  1204. // 8-bit registers in NVPTX.
  1205. EVT NodeVT = (EltVT == MVT::i8) ? MVT::i16 : EltVT;
  1206. SmallVector<EVT, 5> InstVTs;
  1207. for (unsigned i = 0; i != NumElts; ++i) {
  1208. InstVTs.push_back(NodeVT);
  1209. }
  1210. InstVTs.push_back(MVT::Other);
  1211. SDVTList InstVTList = CurDAG->getVTList(InstVTs);
  1212. if (SelectDirectAddr(Op1, Addr)) {
  1213. switch (N->getOpcode()) {
  1214. default:
  1215. return false;
  1216. case ISD::LOAD:
  1217. case ISD::INTRINSIC_W_CHAIN:
  1218. if (IsLDG)
  1219. Opcode = pickOpcodeForVT(EltVT.getSimpleVT().SimpleTy,
  1220. NVPTX::INT_PTX_LDG_GLOBAL_i8avar,
  1221. NVPTX::INT_PTX_LDG_GLOBAL_i16avar,
  1222. NVPTX::INT_PTX_LDG_GLOBAL_i32avar,
  1223. NVPTX::INT_PTX_LDG_GLOBAL_i64avar,
  1224. NVPTX::INT_PTX_LDG_GLOBAL_f16avar,
  1225. NVPTX::INT_PTX_LDG_GLOBAL_f16x2avar,
  1226. NVPTX::INT_PTX_LDG_GLOBAL_f32avar,
  1227. NVPTX::INT_PTX_LDG_GLOBAL_f64avar);
  1228. else
  1229. Opcode = pickOpcodeForVT(EltVT.getSimpleVT().SimpleTy,
  1230. NVPTX::INT_PTX_LDU_GLOBAL_i8avar,
  1231. NVPTX::INT_PTX_LDU_GLOBAL_i16avar,
  1232. NVPTX::INT_PTX_LDU_GLOBAL_i32avar,
  1233. NVPTX::INT_PTX_LDU_GLOBAL_i64avar,
  1234. NVPTX::INT_PTX_LDU_GLOBAL_f16avar,
  1235. NVPTX::INT_PTX_LDU_GLOBAL_f16x2avar,
  1236. NVPTX::INT_PTX_LDU_GLOBAL_f32avar,
  1237. NVPTX::INT_PTX_LDU_GLOBAL_f64avar);
  1238. break;
  1239. case NVPTXISD::LoadV2:
  1240. case NVPTXISD::LDGV2:
  1241. Opcode = pickOpcodeForVT(EltVT.getSimpleVT().SimpleTy,
  1242. NVPTX::INT_PTX_LDG_G_v2i8_ELE_avar,
  1243. NVPTX::INT_PTX_LDG_G_v2i16_ELE_avar,
  1244. NVPTX::INT_PTX_LDG_G_v2i32_ELE_avar,
  1245. NVPTX::INT_PTX_LDG_G_v2i64_ELE_avar,
  1246. NVPTX::INT_PTX_LDG_G_v2f16_ELE_avar,
  1247. NVPTX::INT_PTX_LDG_G_v2f16x2_ELE_avar,
  1248. NVPTX::INT_PTX_LDG_G_v2f32_ELE_avar,
  1249. NVPTX::INT_PTX_LDG_G_v2f64_ELE_avar);
  1250. break;
  1251. case NVPTXISD::LDUV2:
  1252. Opcode = pickOpcodeForVT(EltVT.getSimpleVT().SimpleTy,
  1253. NVPTX::INT_PTX_LDU_G_v2i8_ELE_avar,
  1254. NVPTX::INT_PTX_LDU_G_v2i16_ELE_avar,
  1255. NVPTX::INT_PTX_LDU_G_v2i32_ELE_avar,
  1256. NVPTX::INT_PTX_LDU_G_v2i64_ELE_avar,
  1257. NVPTX::INT_PTX_LDU_G_v2f16_ELE_avar,
  1258. NVPTX::INT_PTX_LDU_G_v2f16x2_ELE_avar,
  1259. NVPTX::INT_PTX_LDU_G_v2f32_ELE_avar,
  1260. NVPTX::INT_PTX_LDU_G_v2f64_ELE_avar);
  1261. break;
  1262. case NVPTXISD::LoadV4:
  1263. case NVPTXISD::LDGV4:
  1264. Opcode = pickOpcodeForVT(EltVT.getSimpleVT().SimpleTy,
  1265. NVPTX::INT_PTX_LDG_G_v4i8_ELE_avar,
  1266. NVPTX::INT_PTX_LDG_G_v4i16_ELE_avar,
  1267. NVPTX::INT_PTX_LDG_G_v4i32_ELE_avar, None,
  1268. NVPTX::INT_PTX_LDG_G_v4f16_ELE_avar,
  1269. NVPTX::INT_PTX_LDG_G_v4f16x2_ELE_avar,
  1270. NVPTX::INT_PTX_LDG_G_v4f32_ELE_avar, None);
  1271. break;
  1272. case NVPTXISD::LDUV4:
  1273. Opcode = pickOpcodeForVT(EltVT.getSimpleVT().SimpleTy,
  1274. NVPTX::INT_PTX_LDU_G_v4i8_ELE_avar,
  1275. NVPTX::INT_PTX_LDU_G_v4i16_ELE_avar,
  1276. NVPTX::INT_PTX_LDU_G_v4i32_ELE_avar, None,
  1277. NVPTX::INT_PTX_LDU_G_v4f16_ELE_avar,
  1278. NVPTX::INT_PTX_LDU_G_v4f16x2_ELE_avar,
  1279. NVPTX::INT_PTX_LDU_G_v4f32_ELE_avar, None);
  1280. break;
  1281. }
  1282. if (!Opcode)
  1283. return false;
  1284. SDValue Ops[] = { Addr, Chain };
  1285. LD = CurDAG->getMachineNode(Opcode.getValue(), DL, InstVTList, Ops);
  1286. } else if (TM.is64Bit() ? SelectADDRri64(Op1.getNode(), Op1, Base, Offset)
  1287. : SelectADDRri(Op1.getNode(), Op1, Base, Offset)) {
  1288. if (TM.is64Bit()) {
  1289. switch (N->getOpcode()) {
  1290. default:
  1291. return false;
  1292. case ISD::LOAD:
  1293. case ISD::INTRINSIC_W_CHAIN:
  1294. if (IsLDG)
  1295. Opcode = pickOpcodeForVT(EltVT.getSimpleVT().SimpleTy,
  1296. NVPTX::INT_PTX_LDG_GLOBAL_i8ari64,
  1297. NVPTX::INT_PTX_LDG_GLOBAL_i16ari64,
  1298. NVPTX::INT_PTX_LDG_GLOBAL_i32ari64,
  1299. NVPTX::INT_PTX_LDG_GLOBAL_i64ari64,
  1300. NVPTX::INT_PTX_LDG_GLOBAL_f16ari64,
  1301. NVPTX::INT_PTX_LDG_GLOBAL_f16x2ari64,
  1302. NVPTX::INT_PTX_LDG_GLOBAL_f32ari64,
  1303. NVPTX::INT_PTX_LDG_GLOBAL_f64ari64);
  1304. else
  1305. Opcode = pickOpcodeForVT(EltVT.getSimpleVT().SimpleTy,
  1306. NVPTX::INT_PTX_LDU_GLOBAL_i8ari64,
  1307. NVPTX::INT_PTX_LDU_GLOBAL_i16ari64,
  1308. NVPTX::INT_PTX_LDU_GLOBAL_i32ari64,
  1309. NVPTX::INT_PTX_LDU_GLOBAL_i64ari64,
  1310. NVPTX::INT_PTX_LDU_GLOBAL_f16ari64,
  1311. NVPTX::INT_PTX_LDU_GLOBAL_f16x2ari64,
  1312. NVPTX::INT_PTX_LDU_GLOBAL_f32ari64,
  1313. NVPTX::INT_PTX_LDU_GLOBAL_f64ari64);
  1314. break;
  1315. case NVPTXISD::LoadV2:
  1316. case NVPTXISD::LDGV2:
  1317. Opcode = pickOpcodeForVT(EltVT.getSimpleVT().SimpleTy,
  1318. NVPTX::INT_PTX_LDG_G_v2i8_ELE_ari64,
  1319. NVPTX::INT_PTX_LDG_G_v2i16_ELE_ari64,
  1320. NVPTX::INT_PTX_LDG_G_v2i32_ELE_ari64,
  1321. NVPTX::INT_PTX_LDG_G_v2i64_ELE_ari64,
  1322. NVPTX::INT_PTX_LDG_G_v2f16_ELE_ari64,
  1323. NVPTX::INT_PTX_LDG_G_v2f16x2_ELE_ari64,
  1324. NVPTX::INT_PTX_LDG_G_v2f32_ELE_ari64,
  1325. NVPTX::INT_PTX_LDG_G_v2f64_ELE_ari64);
  1326. break;
  1327. case NVPTXISD::LDUV2:
  1328. Opcode = pickOpcodeForVT(EltVT.getSimpleVT().SimpleTy,
  1329. NVPTX::INT_PTX_LDU_G_v2i8_ELE_ari64,
  1330. NVPTX::INT_PTX_LDU_G_v2i16_ELE_ari64,
  1331. NVPTX::INT_PTX_LDU_G_v2i32_ELE_ari64,
  1332. NVPTX::INT_PTX_LDU_G_v2i64_ELE_ari64,
  1333. NVPTX::INT_PTX_LDU_G_v2f16_ELE_ari64,
  1334. NVPTX::INT_PTX_LDU_G_v2f16x2_ELE_ari64,
  1335. NVPTX::INT_PTX_LDU_G_v2f32_ELE_ari64,
  1336. NVPTX::INT_PTX_LDU_G_v2f64_ELE_ari64);
  1337. break;
  1338. case NVPTXISD::LoadV4:
  1339. case NVPTXISD::LDGV4:
  1340. Opcode = pickOpcodeForVT(EltVT.getSimpleVT().SimpleTy,
  1341. NVPTX::INT_PTX_LDG_G_v4i8_ELE_ari64,
  1342. NVPTX::INT_PTX_LDG_G_v4i16_ELE_ari64,
  1343. NVPTX::INT_PTX_LDG_G_v4i32_ELE_ari64, None,
  1344. NVPTX::INT_PTX_LDG_G_v4f16_ELE_ari64,
  1345. NVPTX::INT_PTX_LDG_G_v4f16x2_ELE_ari64,
  1346. NVPTX::INT_PTX_LDG_G_v4f32_ELE_ari64, None);
  1347. break;
  1348. case NVPTXISD::LDUV4:
  1349. Opcode = pickOpcodeForVT(EltVT.getSimpleVT().SimpleTy,
  1350. NVPTX::INT_PTX_LDU_G_v4i8_ELE_ari64,
  1351. NVPTX::INT_PTX_LDU_G_v4i16_ELE_ari64,
  1352. NVPTX::INT_PTX_LDU_G_v4i32_ELE_ari64, None,
  1353. NVPTX::INT_PTX_LDU_G_v4f16_ELE_ari64,
  1354. NVPTX::INT_PTX_LDU_G_v4f16x2_ELE_ari64,
  1355. NVPTX::INT_PTX_LDU_G_v4f32_ELE_ari64, None);
  1356. break;
  1357. }
  1358. } else {
  1359. switch (N->getOpcode()) {
  1360. default:
  1361. return false;
  1362. case ISD::LOAD:
  1363. case ISD::INTRINSIC_W_CHAIN:
  1364. if (IsLDG)
  1365. Opcode = pickOpcodeForVT(EltVT.getSimpleVT().SimpleTy,
  1366. NVPTX::INT_PTX_LDG_GLOBAL_i8ari,
  1367. NVPTX::INT_PTX_LDG_GLOBAL_i16ari,
  1368. NVPTX::INT_PTX_LDG_GLOBAL_i32ari,
  1369. NVPTX::INT_PTX_LDG_GLOBAL_i64ari,
  1370. NVPTX::INT_PTX_LDG_GLOBAL_f16ari,
  1371. NVPTX::INT_PTX_LDG_GLOBAL_f16x2ari,
  1372. NVPTX::INT_PTX_LDG_GLOBAL_f32ari,
  1373. NVPTX::INT_PTX_LDG_GLOBAL_f64ari);
  1374. else
  1375. Opcode = pickOpcodeForVT(EltVT.getSimpleVT().SimpleTy,
  1376. NVPTX::INT_PTX_LDU_GLOBAL_i8ari,
  1377. NVPTX::INT_PTX_LDU_GLOBAL_i16ari,
  1378. NVPTX::INT_PTX_LDU_GLOBAL_i32ari,
  1379. NVPTX::INT_PTX_LDU_GLOBAL_i64ari,
  1380. NVPTX::INT_PTX_LDU_GLOBAL_f16ari,
  1381. NVPTX::INT_PTX_LDU_GLOBAL_f16x2ari,
  1382. NVPTX::INT_PTX_LDU_GLOBAL_f32ari,
  1383. NVPTX::INT_PTX_LDU_GLOBAL_f64ari);
  1384. break;
  1385. case NVPTXISD::LoadV2:
  1386. case NVPTXISD::LDGV2:
  1387. Opcode = pickOpcodeForVT(EltVT.getSimpleVT().SimpleTy,
  1388. NVPTX::INT_PTX_LDG_G_v2i8_ELE_ari32,
  1389. NVPTX::INT_PTX_LDG_G_v2i16_ELE_ari32,
  1390. NVPTX::INT_PTX_LDG_G_v2i32_ELE_ari32,
  1391. NVPTX::INT_PTX_LDG_G_v2i64_ELE_ari32,
  1392. NVPTX::INT_PTX_LDG_G_v2f16_ELE_ari32,
  1393. NVPTX::INT_PTX_LDG_G_v2f16x2_ELE_ari32,
  1394. NVPTX::INT_PTX_LDG_G_v2f32_ELE_ari32,
  1395. NVPTX::INT_PTX_LDG_G_v2f64_ELE_ari32);
  1396. break;
  1397. case NVPTXISD::LDUV2:
  1398. Opcode = pickOpcodeForVT(EltVT.getSimpleVT().SimpleTy,
  1399. NVPTX::INT_PTX_LDU_G_v2i8_ELE_ari32,
  1400. NVPTX::INT_PTX_LDU_G_v2i16_ELE_ari32,
  1401. NVPTX::INT_PTX_LDU_G_v2i32_ELE_ari32,
  1402. NVPTX::INT_PTX_LDU_G_v2i64_ELE_ari32,
  1403. NVPTX::INT_PTX_LDU_G_v2f16_ELE_ari32,
  1404. NVPTX::INT_PTX_LDU_G_v2f16x2_ELE_ari32,
  1405. NVPTX::INT_PTX_LDU_G_v2f32_ELE_ari32,
  1406. NVPTX::INT_PTX_LDU_G_v2f64_ELE_ari32);
  1407. break;
  1408. case NVPTXISD::LoadV4:
  1409. case NVPTXISD::LDGV4:
  1410. Opcode = pickOpcodeForVT(EltVT.getSimpleVT().SimpleTy,
  1411. NVPTX::INT_PTX_LDG_G_v4i8_ELE_ari32,
  1412. NVPTX::INT_PTX_LDG_G_v4i16_ELE_ari32,
  1413. NVPTX::INT_PTX_LDG_G_v4i32_ELE_ari32, None,
  1414. NVPTX::INT_PTX_LDG_G_v4f16_ELE_ari32,
  1415. NVPTX::INT_PTX_LDG_G_v4f16x2_ELE_ari32,
  1416. NVPTX::INT_PTX_LDG_G_v4f32_ELE_ari32, None);
  1417. break;
  1418. case NVPTXISD::LDUV4:
  1419. Opcode = pickOpcodeForVT(EltVT.getSimpleVT().SimpleTy,
  1420. NVPTX::INT_PTX_LDU_G_v4i8_ELE_ari32,
  1421. NVPTX::INT_PTX_LDU_G_v4i16_ELE_ari32,
  1422. NVPTX::INT_PTX_LDU_G_v4i32_ELE_ari32, None,
  1423. NVPTX::INT_PTX_LDU_G_v4f16_ELE_ari32,
  1424. NVPTX::INT_PTX_LDU_G_v4f16x2_ELE_ari32,
  1425. NVPTX::INT_PTX_LDU_G_v4f32_ELE_ari32, None);
  1426. break;
  1427. }
  1428. }
  1429. if (!Opcode)
  1430. return false;
  1431. SDValue Ops[] = {Base, Offset, Chain};
  1432. LD = CurDAG->getMachineNode(Opcode.getValue(), DL, InstVTList, Ops);
  1433. } else {
  1434. if (TM.is64Bit()) {
  1435. switch (N->getOpcode()) {
  1436. default:
  1437. return false;
  1438. case ISD::LOAD:
  1439. case ISD::INTRINSIC_W_CHAIN:
  1440. if (IsLDG)
  1441. Opcode = pickOpcodeForVT(EltVT.getSimpleVT().SimpleTy,
  1442. NVPTX::INT_PTX_LDG_GLOBAL_i8areg64,
  1443. NVPTX::INT_PTX_LDG_GLOBAL_i16areg64,
  1444. NVPTX::INT_PTX_LDG_GLOBAL_i32areg64,
  1445. NVPTX::INT_PTX_LDG_GLOBAL_i64areg64,
  1446. NVPTX::INT_PTX_LDG_GLOBAL_f16areg64,
  1447. NVPTX::INT_PTX_LDG_GLOBAL_f16x2areg64,
  1448. NVPTX::INT_PTX_LDG_GLOBAL_f32areg64,
  1449. NVPTX::INT_PTX_LDG_GLOBAL_f64areg64);
  1450. else
  1451. Opcode = pickOpcodeForVT(EltVT.getSimpleVT().SimpleTy,
  1452. NVPTX::INT_PTX_LDU_GLOBAL_i8areg64,
  1453. NVPTX::INT_PTX_LDU_GLOBAL_i16areg64,
  1454. NVPTX::INT_PTX_LDU_GLOBAL_i32areg64,
  1455. NVPTX::INT_PTX_LDU_GLOBAL_i64areg64,
  1456. NVPTX::INT_PTX_LDU_GLOBAL_f16areg64,
  1457. NVPTX::INT_PTX_LDU_GLOBAL_f16x2areg64,
  1458. NVPTX::INT_PTX_LDU_GLOBAL_f32areg64,
  1459. NVPTX::INT_PTX_LDU_GLOBAL_f64areg64);
  1460. break;
  1461. case NVPTXISD::LoadV2:
  1462. case NVPTXISD::LDGV2:
  1463. Opcode = pickOpcodeForVT(EltVT.getSimpleVT().SimpleTy,
  1464. NVPTX::INT_PTX_LDG_G_v2i8_ELE_areg64,
  1465. NVPTX::INT_PTX_LDG_G_v2i16_ELE_areg64,
  1466. NVPTX::INT_PTX_LDG_G_v2i32_ELE_areg64,
  1467. NVPTX::INT_PTX_LDG_G_v2i64_ELE_areg64,
  1468. NVPTX::INT_PTX_LDG_G_v2f16_ELE_areg64,
  1469. NVPTX::INT_PTX_LDG_G_v2f16x2_ELE_areg64,
  1470. NVPTX::INT_PTX_LDG_G_v2f32_ELE_areg64,
  1471. NVPTX::INT_PTX_LDG_G_v2f64_ELE_areg64);
  1472. break;
  1473. case NVPTXISD::LDUV2:
  1474. Opcode = pickOpcodeForVT(EltVT.getSimpleVT().SimpleTy,
  1475. NVPTX::INT_PTX_LDU_G_v2i8_ELE_areg64,
  1476. NVPTX::INT_PTX_LDU_G_v2i16_ELE_areg64,
  1477. NVPTX::INT_PTX_LDU_G_v2i32_ELE_areg64,
  1478. NVPTX::INT_PTX_LDU_G_v2i64_ELE_areg64,
  1479. NVPTX::INT_PTX_LDU_G_v2f16_ELE_areg64,
  1480. NVPTX::INT_PTX_LDU_G_v2f16x2_ELE_areg64,
  1481. NVPTX::INT_PTX_LDU_G_v2f32_ELE_areg64,
  1482. NVPTX::INT_PTX_LDU_G_v2f64_ELE_areg64);
  1483. break;
  1484. case NVPTXISD::LoadV4:
  1485. case NVPTXISD::LDGV4:
  1486. Opcode = pickOpcodeForVT(EltVT.getSimpleVT().SimpleTy,
  1487. NVPTX::INT_PTX_LDG_G_v4i8_ELE_areg64,
  1488. NVPTX::INT_PTX_LDG_G_v4i16_ELE_areg64,
  1489. NVPTX::INT_PTX_LDG_G_v4i32_ELE_areg64, None,
  1490. NVPTX::INT_PTX_LDG_G_v4f16_ELE_areg64,
  1491. NVPTX::INT_PTX_LDG_G_v4f16x2_ELE_areg64,
  1492. NVPTX::INT_PTX_LDG_G_v4f32_ELE_areg64, None);
  1493. break;
  1494. case NVPTXISD::LDUV4:
  1495. Opcode = pickOpcodeForVT(EltVT.getSimpleVT().SimpleTy,
  1496. NVPTX::INT_PTX_LDU_G_v4i8_ELE_areg64,
  1497. NVPTX::INT_PTX_LDU_G_v4i16_ELE_areg64,
  1498. NVPTX::INT_PTX_LDU_G_v4i32_ELE_areg64, None,
  1499. NVPTX::INT_PTX_LDU_G_v4f16_ELE_areg64,
  1500. NVPTX::INT_PTX_LDU_G_v4f16x2_ELE_areg64,
  1501. NVPTX::INT_PTX_LDU_G_v4f32_ELE_areg64, None);
  1502. break;
  1503. }
  1504. } else {
  1505. switch (N->getOpcode()) {
  1506. default:
  1507. return false;
  1508. case ISD::LOAD:
  1509. case ISD::INTRINSIC_W_CHAIN:
  1510. if (IsLDG)
  1511. Opcode = pickOpcodeForVT(EltVT.getSimpleVT().SimpleTy,
  1512. NVPTX::INT_PTX_LDG_GLOBAL_i8areg,
  1513. NVPTX::INT_PTX_LDG_GLOBAL_i16areg,
  1514. NVPTX::INT_PTX_LDG_GLOBAL_i32areg,
  1515. NVPTX::INT_PTX_LDG_GLOBAL_i64areg,
  1516. NVPTX::INT_PTX_LDG_GLOBAL_f16areg,
  1517. NVPTX::INT_PTX_LDG_GLOBAL_f16x2areg,
  1518. NVPTX::INT_PTX_LDG_GLOBAL_f32areg,
  1519. NVPTX::INT_PTX_LDG_GLOBAL_f64areg);
  1520. else
  1521. Opcode = pickOpcodeForVT(EltVT.getSimpleVT().SimpleTy,
  1522. NVPTX::INT_PTX_LDU_GLOBAL_i8areg,
  1523. NVPTX::INT_PTX_LDU_GLOBAL_i16areg,
  1524. NVPTX::INT_PTX_LDU_GLOBAL_i32areg,
  1525. NVPTX::INT_PTX_LDU_GLOBAL_i64areg,
  1526. NVPTX::INT_PTX_LDU_GLOBAL_f16areg,
  1527. NVPTX::INT_PTX_LDU_GLOBAL_f16x2areg,
  1528. NVPTX::INT_PTX_LDU_GLOBAL_f32areg,
  1529. NVPTX::INT_PTX_LDU_GLOBAL_f64areg);
  1530. break;
  1531. case NVPTXISD::LoadV2:
  1532. case NVPTXISD::LDGV2:
  1533. Opcode = pickOpcodeForVT(EltVT.getSimpleVT().SimpleTy,
  1534. NVPTX::INT_PTX_LDG_G_v2i8_ELE_areg32,
  1535. NVPTX::INT_PTX_LDG_G_v2i16_ELE_areg32,
  1536. NVPTX::INT_PTX_LDG_G_v2i32_ELE_areg32,
  1537. NVPTX::INT_PTX_LDG_G_v2i64_ELE_areg32,
  1538. NVPTX::INT_PTX_LDG_G_v2f16_ELE_areg32,
  1539. NVPTX::INT_PTX_LDG_G_v2f16x2_ELE_areg32,
  1540. NVPTX::INT_PTX_LDG_G_v2f32_ELE_areg32,
  1541. NVPTX::INT_PTX_LDG_G_v2f64_ELE_areg32);
  1542. break;
  1543. case NVPTXISD::LDUV2:
  1544. Opcode = pickOpcodeForVT(EltVT.getSimpleVT().SimpleTy,
  1545. NVPTX::INT_PTX_LDU_G_v2i8_ELE_areg32,
  1546. NVPTX::INT_PTX_LDU_G_v2i16_ELE_areg32,
  1547. NVPTX::INT_PTX_LDU_G_v2i32_ELE_areg32,
  1548. NVPTX::INT_PTX_LDU_G_v2i64_ELE_areg32,
  1549. NVPTX::INT_PTX_LDU_G_v2f16_ELE_areg32,
  1550. NVPTX::INT_PTX_LDU_G_v2f16x2_ELE_areg32,
  1551. NVPTX::INT_PTX_LDU_G_v2f32_ELE_areg32,
  1552. NVPTX::INT_PTX_LDU_G_v2f64_ELE_areg32);
  1553. break;
  1554. case NVPTXISD::LoadV4:
  1555. case NVPTXISD::LDGV4:
  1556. Opcode = pickOpcodeForVT(EltVT.getSimpleVT().SimpleTy,
  1557. NVPTX::INT_PTX_LDG_G_v4i8_ELE_areg32,
  1558. NVPTX::INT_PTX_LDG_G_v4i16_ELE_areg32,
  1559. NVPTX::INT_PTX_LDG_G_v4i32_ELE_areg32, None,
  1560. NVPTX::INT_PTX_LDG_G_v4f16_ELE_areg32,
  1561. NVPTX::INT_PTX_LDG_G_v4f16x2_ELE_areg32,
  1562. NVPTX::INT_PTX_LDG_G_v4f32_ELE_areg32, None);
  1563. break;
  1564. case NVPTXISD::LDUV4:
  1565. Opcode = pickOpcodeForVT(EltVT.getSimpleVT().SimpleTy,
  1566. NVPTX::INT_PTX_LDU_G_v4i8_ELE_areg32,
  1567. NVPTX::INT_PTX_LDU_G_v4i16_ELE_areg32,
  1568. NVPTX::INT_PTX_LDU_G_v4i32_ELE_areg32, None,
  1569. NVPTX::INT_PTX_LDU_G_v4f16_ELE_areg32,
  1570. NVPTX::INT_PTX_LDU_G_v4f16x2_ELE_areg32,
  1571. NVPTX::INT_PTX_LDU_G_v4f32_ELE_areg32, None);
  1572. break;
  1573. }
  1574. }
  1575. if (!Opcode)
  1576. return false;
  1577. SDValue Ops[] = { Op1, Chain };
  1578. LD = CurDAG->getMachineNode(Opcode.getValue(), DL, InstVTList, Ops);
  1579. }
  1580. MachineMemOperand *MemRef = Mem->getMemOperand();
  1581. CurDAG->setNodeMemRefs(cast<MachineSDNode>(LD), {MemRef});
  1582. // For automatic generation of LDG (through SelectLoad[Vector], not the
  1583. // intrinsics), we may have an extending load like:
  1584. //
  1585. // i32,ch = load<LD1[%data1(addrspace=1)], zext from i8> t0, t7, undef:i64
  1586. //
  1587. // In this case, the matching logic above will select a load for the original
  1588. // memory type (in this case, i8) and our types will not match (the node needs
  1589. // to return an i32 in this case). Our LDG/LDU nodes do not support the
  1590. // concept of sign-/zero-extension, so emulate it here by adding an explicit
  1591. // CVT instruction. Ptxas should clean up any redundancies here.
  1592. EVT OrigType = N->getValueType(0);
  1593. LoadSDNode *LdNode = dyn_cast<LoadSDNode>(N);
  1594. if (OrigType != EltVT && LdNode) {
  1595. // We have an extending-load. The instruction we selected operates on the
  1596. // smaller type, but the SDNode we are replacing has the larger type. We
  1597. // need to emit a CVT to make the types match.
  1598. bool IsSigned = LdNode->getExtensionType() == ISD::SEXTLOAD;
  1599. unsigned CvtOpc = GetConvertOpcode(OrigType.getSimpleVT(),
  1600. EltVT.getSimpleVT(), IsSigned);
  1601. // For each output value, apply the manual sign/zero-extension and make sure
  1602. // all users of the load go through that CVT.
  1603. for (unsigned i = 0; i != NumElts; ++i) {
  1604. SDValue Res(LD, i);
  1605. SDValue OrigVal(N, i);
  1606. SDNode *CvtNode =
  1607. CurDAG->getMachineNode(CvtOpc, DL, OrigType, Res,
  1608. CurDAG->getTargetConstant(NVPTX::PTXCvtMode::NONE,
  1609. DL, MVT::i32));
  1610. ReplaceUses(OrigVal, SDValue(CvtNode, 0));
  1611. }
  1612. }
  1613. ReplaceNode(N, LD);
  1614. return true;
  1615. }
  1616. bool NVPTXDAGToDAGISel::tryStore(SDNode *N) {
  1617. SDLoc dl(N);
  1618. MemSDNode *ST = cast<MemSDNode>(N);
  1619. assert(ST->writeMem() && "Expected store");
  1620. StoreSDNode *PlainStore = dyn_cast<StoreSDNode>(N);
  1621. AtomicSDNode *AtomicStore = dyn_cast<AtomicSDNode>(N);
  1622. assert((PlainStore || AtomicStore) && "Expected store");
  1623. EVT StoreVT = ST->getMemoryVT();
  1624. SDNode *NVPTXST = nullptr;
  1625. // do not support pre/post inc/dec
  1626. if (PlainStore && PlainStore->isIndexed())
  1627. return false;
  1628. if (!StoreVT.isSimple())
  1629. return false;
  1630. AtomicOrdering Ordering = ST->getSuccessOrdering();
  1631. // In order to lower atomic loads with stronger guarantees we would need to
  1632. // use store.release or insert fences. However these features were only added
  1633. // with PTX ISA 6.0 / sm_70.
  1634. // TODO: Check if we can actually use the new instructions and implement them.
  1635. if (isStrongerThanMonotonic(Ordering))
  1636. return false;
  1637. // Address Space Setting
  1638. unsigned int CodeAddrSpace = getCodeAddrSpace(ST);
  1639. unsigned int PointerSize =
  1640. CurDAG->getDataLayout().getPointerSizeInBits(ST->getAddressSpace());
  1641. // Volatile Setting
  1642. // - .volatile is only available for .global and .shared
  1643. // - .volatile has the same memory synchronization semantics as .relaxed.sys
  1644. bool isVolatile = ST->isVolatile() || Ordering == AtomicOrdering::Monotonic;
  1645. if (CodeAddrSpace != NVPTX::PTXLdStInstCode::GLOBAL &&
  1646. CodeAddrSpace != NVPTX::PTXLdStInstCode::SHARED &&
  1647. CodeAddrSpace != NVPTX::PTXLdStInstCode::GENERIC)
  1648. isVolatile = false;
  1649. // Vector Setting
  1650. MVT SimpleVT = StoreVT.getSimpleVT();
  1651. unsigned vecType = NVPTX::PTXLdStInstCode::Scalar;
  1652. // Type Setting: toType + toTypeWidth
  1653. // - for integer type, always use 'u'
  1654. //
  1655. MVT ScalarVT = SimpleVT.getScalarType();
  1656. unsigned toTypeWidth = ScalarVT.getSizeInBits();
  1657. if (SimpleVT.isVector()) {
  1658. assert(StoreVT == MVT::v2f16 && "Unexpected vector type");
  1659. // v2f16 is stored using st.b32
  1660. toTypeWidth = 32;
  1661. }
  1662. unsigned int toType;
  1663. if (ScalarVT.isFloatingPoint())
  1664. // f16 uses .b16 as its storage type.
  1665. toType = ScalarVT.SimpleTy == MVT::f16 ? NVPTX::PTXLdStInstCode::Untyped
  1666. : NVPTX::PTXLdStInstCode::Float;
  1667. else
  1668. toType = NVPTX::PTXLdStInstCode::Unsigned;
  1669. // Create the machine instruction DAG
  1670. SDValue Chain = ST->getChain();
  1671. SDValue Value = PlainStore ? PlainStore->getValue() : AtomicStore->getVal();
  1672. SDValue BasePtr = ST->getBasePtr();
  1673. SDValue Addr;
  1674. SDValue Offset, Base;
  1675. Optional<unsigned> Opcode;
  1676. MVT::SimpleValueType SourceVT =
  1677. Value.getNode()->getSimpleValueType(0).SimpleTy;
  1678. if (SelectDirectAddr(BasePtr, Addr)) {
  1679. Opcode = pickOpcodeForVT(SourceVT, NVPTX::ST_i8_avar, NVPTX::ST_i16_avar,
  1680. NVPTX::ST_i32_avar, NVPTX::ST_i64_avar,
  1681. NVPTX::ST_f16_avar, NVPTX::ST_f16x2_avar,
  1682. NVPTX::ST_f32_avar, NVPTX::ST_f64_avar);
  1683. if (!Opcode)
  1684. return false;
  1685. SDValue Ops[] = {Value,
  1686. getI32Imm(isVolatile, dl),
  1687. getI32Imm(CodeAddrSpace, dl),
  1688. getI32Imm(vecType, dl),
  1689. getI32Imm(toType, dl),
  1690. getI32Imm(toTypeWidth, dl),
  1691. Addr,
  1692. Chain};
  1693. NVPTXST = CurDAG->getMachineNode(Opcode.getValue(), dl, MVT::Other, Ops);
  1694. } else if (PointerSize == 64
  1695. ? SelectADDRsi64(BasePtr.getNode(), BasePtr, Base, Offset)
  1696. : SelectADDRsi(BasePtr.getNode(), BasePtr, Base, Offset)) {
  1697. Opcode = pickOpcodeForVT(SourceVT, NVPTX::ST_i8_asi, NVPTX::ST_i16_asi,
  1698. NVPTX::ST_i32_asi, NVPTX::ST_i64_asi,
  1699. NVPTX::ST_f16_asi, NVPTX::ST_f16x2_asi,
  1700. NVPTX::ST_f32_asi, NVPTX::ST_f64_asi);
  1701. if (!Opcode)
  1702. return false;
  1703. SDValue Ops[] = {Value,
  1704. getI32Imm(isVolatile, dl),
  1705. getI32Imm(CodeAddrSpace, dl),
  1706. getI32Imm(vecType, dl),
  1707. getI32Imm(toType, dl),
  1708. getI32Imm(toTypeWidth, dl),
  1709. Base,
  1710. Offset,
  1711. Chain};
  1712. NVPTXST = CurDAG->getMachineNode(Opcode.getValue(), dl, MVT::Other, Ops);
  1713. } else if (PointerSize == 64
  1714. ? SelectADDRri64(BasePtr.getNode(), BasePtr, Base, Offset)
  1715. : SelectADDRri(BasePtr.getNode(), BasePtr, Base, Offset)) {
  1716. if (PointerSize == 64)
  1717. Opcode = pickOpcodeForVT(
  1718. SourceVT, NVPTX::ST_i8_ari_64, NVPTX::ST_i16_ari_64,
  1719. NVPTX::ST_i32_ari_64, NVPTX::ST_i64_ari_64, NVPTX::ST_f16_ari_64,
  1720. NVPTX::ST_f16x2_ari_64, NVPTX::ST_f32_ari_64, NVPTX::ST_f64_ari_64);
  1721. else
  1722. Opcode = pickOpcodeForVT(SourceVT, NVPTX::ST_i8_ari, NVPTX::ST_i16_ari,
  1723. NVPTX::ST_i32_ari, NVPTX::ST_i64_ari,
  1724. NVPTX::ST_f16_ari, NVPTX::ST_f16x2_ari,
  1725. NVPTX::ST_f32_ari, NVPTX::ST_f64_ari);
  1726. if (!Opcode)
  1727. return false;
  1728. SDValue Ops[] = {Value,
  1729. getI32Imm(isVolatile, dl),
  1730. getI32Imm(CodeAddrSpace, dl),
  1731. getI32Imm(vecType, dl),
  1732. getI32Imm(toType, dl),
  1733. getI32Imm(toTypeWidth, dl),
  1734. Base,
  1735. Offset,
  1736. Chain};
  1737. NVPTXST = CurDAG->getMachineNode(Opcode.getValue(), dl, MVT::Other, Ops);
  1738. } else {
  1739. if (PointerSize == 64)
  1740. Opcode =
  1741. pickOpcodeForVT(SourceVT, NVPTX::ST_i8_areg_64, NVPTX::ST_i16_areg_64,
  1742. NVPTX::ST_i32_areg_64, NVPTX::ST_i64_areg_64,
  1743. NVPTX::ST_f16_areg_64, NVPTX::ST_f16x2_areg_64,
  1744. NVPTX::ST_f32_areg_64, NVPTX::ST_f64_areg_64);
  1745. else
  1746. Opcode = pickOpcodeForVT(SourceVT, NVPTX::ST_i8_areg, NVPTX::ST_i16_areg,
  1747. NVPTX::ST_i32_areg, NVPTX::ST_i64_areg,
  1748. NVPTX::ST_f16_areg, NVPTX::ST_f16x2_areg,
  1749. NVPTX::ST_f32_areg, NVPTX::ST_f64_areg);
  1750. if (!Opcode)
  1751. return false;
  1752. SDValue Ops[] = {Value,
  1753. getI32Imm(isVolatile, dl),
  1754. getI32Imm(CodeAddrSpace, dl),
  1755. getI32Imm(vecType, dl),
  1756. getI32Imm(toType, dl),
  1757. getI32Imm(toTypeWidth, dl),
  1758. BasePtr,
  1759. Chain};
  1760. NVPTXST = CurDAG->getMachineNode(Opcode.getValue(), dl, MVT::Other, Ops);
  1761. }
  1762. if (!NVPTXST)
  1763. return false;
  1764. MachineMemOperand *MemRef = cast<MemSDNode>(N)->getMemOperand();
  1765. CurDAG->setNodeMemRefs(cast<MachineSDNode>(NVPTXST), {MemRef});
  1766. ReplaceNode(N, NVPTXST);
  1767. return true;
  1768. }
  1769. bool NVPTXDAGToDAGISel::tryStoreVector(SDNode *N) {
  1770. SDValue Chain = N->getOperand(0);
  1771. SDValue Op1 = N->getOperand(1);
  1772. SDValue Addr, Offset, Base;
  1773. Optional<unsigned> Opcode;
  1774. SDLoc DL(N);
  1775. SDNode *ST;
  1776. EVT EltVT = Op1.getValueType();
  1777. MemSDNode *MemSD = cast<MemSDNode>(N);
  1778. EVT StoreVT = MemSD->getMemoryVT();
  1779. // Address Space Setting
  1780. unsigned CodeAddrSpace = getCodeAddrSpace(MemSD);
  1781. if (CodeAddrSpace == NVPTX::PTXLdStInstCode::CONSTANT) {
  1782. report_fatal_error("Cannot store to pointer that points to constant "
  1783. "memory space");
  1784. }
  1785. unsigned int PointerSize =
  1786. CurDAG->getDataLayout().getPointerSizeInBits(MemSD->getAddressSpace());
  1787. // Volatile Setting
  1788. // - .volatile is only availalble for .global and .shared
  1789. bool IsVolatile = MemSD->isVolatile();
  1790. if (CodeAddrSpace != NVPTX::PTXLdStInstCode::GLOBAL &&
  1791. CodeAddrSpace != NVPTX::PTXLdStInstCode::SHARED &&
  1792. CodeAddrSpace != NVPTX::PTXLdStInstCode::GENERIC)
  1793. IsVolatile = false;
  1794. // Type Setting: toType + toTypeWidth
  1795. // - for integer type, always use 'u'
  1796. assert(StoreVT.isSimple() && "Store value is not simple");
  1797. MVT ScalarVT = StoreVT.getSimpleVT().getScalarType();
  1798. unsigned ToTypeWidth = ScalarVT.getSizeInBits();
  1799. unsigned ToType;
  1800. if (ScalarVT.isFloatingPoint())
  1801. ToType = ScalarVT.SimpleTy == MVT::f16 ? NVPTX::PTXLdStInstCode::Untyped
  1802. : NVPTX::PTXLdStInstCode::Float;
  1803. else
  1804. ToType = NVPTX::PTXLdStInstCode::Unsigned;
  1805. SmallVector<SDValue, 12> StOps;
  1806. SDValue N2;
  1807. unsigned VecType;
  1808. switch (N->getOpcode()) {
  1809. case NVPTXISD::StoreV2:
  1810. VecType = NVPTX::PTXLdStInstCode::V2;
  1811. StOps.push_back(N->getOperand(1));
  1812. StOps.push_back(N->getOperand(2));
  1813. N2 = N->getOperand(3);
  1814. break;
  1815. case NVPTXISD::StoreV4:
  1816. VecType = NVPTX::PTXLdStInstCode::V4;
  1817. StOps.push_back(N->getOperand(1));
  1818. StOps.push_back(N->getOperand(2));
  1819. StOps.push_back(N->getOperand(3));
  1820. StOps.push_back(N->getOperand(4));
  1821. N2 = N->getOperand(5);
  1822. break;
  1823. default:
  1824. return false;
  1825. }
  1826. // v8f16 is a special case. PTX doesn't have st.v8.f16
  1827. // instruction. Instead, we split the vector into v2f16 chunks and
  1828. // store them with st.v4.b32.
  1829. if (EltVT == MVT::v2f16) {
  1830. assert(N->getOpcode() == NVPTXISD::StoreV4 && "Unexpected load opcode.");
  1831. EltVT = MVT::i32;
  1832. ToType = NVPTX::PTXLdStInstCode::Untyped;
  1833. ToTypeWidth = 32;
  1834. }
  1835. StOps.push_back(getI32Imm(IsVolatile, DL));
  1836. StOps.push_back(getI32Imm(CodeAddrSpace, DL));
  1837. StOps.push_back(getI32Imm(VecType, DL));
  1838. StOps.push_back(getI32Imm(ToType, DL));
  1839. StOps.push_back(getI32Imm(ToTypeWidth, DL));
  1840. if (SelectDirectAddr(N2, Addr)) {
  1841. switch (N->getOpcode()) {
  1842. default:
  1843. return false;
  1844. case NVPTXISD::StoreV2:
  1845. Opcode = pickOpcodeForVT(EltVT.getSimpleVT().SimpleTy,
  1846. NVPTX::STV_i8_v2_avar, NVPTX::STV_i16_v2_avar,
  1847. NVPTX::STV_i32_v2_avar, NVPTX::STV_i64_v2_avar,
  1848. NVPTX::STV_f16_v2_avar, NVPTX::STV_f16x2_v2_avar,
  1849. NVPTX::STV_f32_v2_avar, NVPTX::STV_f64_v2_avar);
  1850. break;
  1851. case NVPTXISD::StoreV4:
  1852. Opcode =
  1853. pickOpcodeForVT(EltVT.getSimpleVT().SimpleTy, NVPTX::STV_i8_v4_avar,
  1854. NVPTX::STV_i16_v4_avar, NVPTX::STV_i32_v4_avar, None,
  1855. NVPTX::STV_f16_v4_avar, NVPTX::STV_f16x2_v4_avar,
  1856. NVPTX::STV_f32_v4_avar, None);
  1857. break;
  1858. }
  1859. StOps.push_back(Addr);
  1860. } else if (PointerSize == 64 ? SelectADDRsi64(N2.getNode(), N2, Base, Offset)
  1861. : SelectADDRsi(N2.getNode(), N2, Base, Offset)) {
  1862. switch (N->getOpcode()) {
  1863. default:
  1864. return false;
  1865. case NVPTXISD::StoreV2:
  1866. Opcode = pickOpcodeForVT(EltVT.getSimpleVT().SimpleTy,
  1867. NVPTX::STV_i8_v2_asi, NVPTX::STV_i16_v2_asi,
  1868. NVPTX::STV_i32_v2_asi, NVPTX::STV_i64_v2_asi,
  1869. NVPTX::STV_f16_v2_asi, NVPTX::STV_f16x2_v2_asi,
  1870. NVPTX::STV_f32_v2_asi, NVPTX::STV_f64_v2_asi);
  1871. break;
  1872. case NVPTXISD::StoreV4:
  1873. Opcode =
  1874. pickOpcodeForVT(EltVT.getSimpleVT().SimpleTy, NVPTX::STV_i8_v4_asi,
  1875. NVPTX::STV_i16_v4_asi, NVPTX::STV_i32_v4_asi, None,
  1876. NVPTX::STV_f16_v4_asi, NVPTX::STV_f16x2_v4_asi,
  1877. NVPTX::STV_f32_v4_asi, None);
  1878. break;
  1879. }
  1880. StOps.push_back(Base);
  1881. StOps.push_back(Offset);
  1882. } else if (PointerSize == 64 ? SelectADDRri64(N2.getNode(), N2, Base, Offset)
  1883. : SelectADDRri(N2.getNode(), N2, Base, Offset)) {
  1884. if (PointerSize == 64) {
  1885. switch (N->getOpcode()) {
  1886. default:
  1887. return false;
  1888. case NVPTXISD::StoreV2:
  1889. Opcode = pickOpcodeForVT(
  1890. EltVT.getSimpleVT().SimpleTy, NVPTX::STV_i8_v2_ari_64,
  1891. NVPTX::STV_i16_v2_ari_64, NVPTX::STV_i32_v2_ari_64,
  1892. NVPTX::STV_i64_v2_ari_64, NVPTX::STV_f16_v2_ari_64,
  1893. NVPTX::STV_f16x2_v2_ari_64, NVPTX::STV_f32_v2_ari_64,
  1894. NVPTX::STV_f64_v2_ari_64);
  1895. break;
  1896. case NVPTXISD::StoreV4:
  1897. Opcode = pickOpcodeForVT(
  1898. EltVT.getSimpleVT().SimpleTy, NVPTX::STV_i8_v4_ari_64,
  1899. NVPTX::STV_i16_v4_ari_64, NVPTX::STV_i32_v4_ari_64, None,
  1900. NVPTX::STV_f16_v4_ari_64, NVPTX::STV_f16x2_v4_ari_64,
  1901. NVPTX::STV_f32_v4_ari_64, None);
  1902. break;
  1903. }
  1904. } else {
  1905. switch (N->getOpcode()) {
  1906. default:
  1907. return false;
  1908. case NVPTXISD::StoreV2:
  1909. Opcode = pickOpcodeForVT(EltVT.getSimpleVT().SimpleTy,
  1910. NVPTX::STV_i8_v2_ari, NVPTX::STV_i16_v2_ari,
  1911. NVPTX::STV_i32_v2_ari, NVPTX::STV_i64_v2_ari,
  1912. NVPTX::STV_f16_v2_ari, NVPTX::STV_f16x2_v2_ari,
  1913. NVPTX::STV_f32_v2_ari, NVPTX::STV_f64_v2_ari);
  1914. break;
  1915. case NVPTXISD::StoreV4:
  1916. Opcode =
  1917. pickOpcodeForVT(EltVT.getSimpleVT().SimpleTy, NVPTX::STV_i8_v4_ari,
  1918. NVPTX::STV_i16_v4_ari, NVPTX::STV_i32_v4_ari, None,
  1919. NVPTX::STV_f16_v4_ari, NVPTX::STV_f16x2_v4_ari,
  1920. NVPTX::STV_f32_v4_ari, None);
  1921. break;
  1922. }
  1923. }
  1924. StOps.push_back(Base);
  1925. StOps.push_back(Offset);
  1926. } else {
  1927. if (PointerSize == 64) {
  1928. switch (N->getOpcode()) {
  1929. default:
  1930. return false;
  1931. case NVPTXISD::StoreV2:
  1932. Opcode = pickOpcodeForVT(
  1933. EltVT.getSimpleVT().SimpleTy, NVPTX::STV_i8_v2_areg_64,
  1934. NVPTX::STV_i16_v2_areg_64, NVPTX::STV_i32_v2_areg_64,
  1935. NVPTX::STV_i64_v2_areg_64, NVPTX::STV_f16_v2_areg_64,
  1936. NVPTX::STV_f16x2_v2_areg_64, NVPTX::STV_f32_v2_areg_64,
  1937. NVPTX::STV_f64_v2_areg_64);
  1938. break;
  1939. case NVPTXISD::StoreV4:
  1940. Opcode = pickOpcodeForVT(
  1941. EltVT.getSimpleVT().SimpleTy, NVPTX::STV_i8_v4_areg_64,
  1942. NVPTX::STV_i16_v4_areg_64, NVPTX::STV_i32_v4_areg_64, None,
  1943. NVPTX::STV_f16_v4_areg_64, NVPTX::STV_f16x2_v4_areg_64,
  1944. NVPTX::STV_f32_v4_areg_64, None);
  1945. break;
  1946. }
  1947. } else {
  1948. switch (N->getOpcode()) {
  1949. default:
  1950. return false;
  1951. case NVPTXISD::StoreV2:
  1952. Opcode =
  1953. pickOpcodeForVT(EltVT.getSimpleVT().SimpleTy, NVPTX::STV_i8_v2_areg,
  1954. NVPTX::STV_i16_v2_areg, NVPTX::STV_i32_v2_areg,
  1955. NVPTX::STV_i64_v2_areg, NVPTX::STV_f16_v2_areg,
  1956. NVPTX::STV_f16x2_v2_areg, NVPTX::STV_f32_v2_areg,
  1957. NVPTX::STV_f64_v2_areg);
  1958. break;
  1959. case NVPTXISD::StoreV4:
  1960. Opcode =
  1961. pickOpcodeForVT(EltVT.getSimpleVT().SimpleTy, NVPTX::STV_i8_v4_areg,
  1962. NVPTX::STV_i16_v4_areg, NVPTX::STV_i32_v4_areg, None,
  1963. NVPTX::STV_f16_v4_areg, NVPTX::STV_f16x2_v4_areg,
  1964. NVPTX::STV_f32_v4_areg, None);
  1965. break;
  1966. }
  1967. }
  1968. StOps.push_back(N2);
  1969. }
  1970. if (!Opcode)
  1971. return false;
  1972. StOps.push_back(Chain);
  1973. ST = CurDAG->getMachineNode(Opcode.getValue(), DL, MVT::Other, StOps);
  1974. MachineMemOperand *MemRef = cast<MemSDNode>(N)->getMemOperand();
  1975. CurDAG->setNodeMemRefs(cast<MachineSDNode>(ST), {MemRef});
  1976. ReplaceNode(N, ST);
  1977. return true;
  1978. }
  1979. bool NVPTXDAGToDAGISel::tryLoadParam(SDNode *Node) {
  1980. SDValue Chain = Node->getOperand(0);
  1981. SDValue Offset = Node->getOperand(2);
  1982. SDValue Flag = Node->getOperand(3);
  1983. SDLoc DL(Node);
  1984. MemSDNode *Mem = cast<MemSDNode>(Node);
  1985. unsigned VecSize;
  1986. switch (Node->getOpcode()) {
  1987. default:
  1988. return false;
  1989. case NVPTXISD::LoadParam:
  1990. VecSize = 1;
  1991. break;
  1992. case NVPTXISD::LoadParamV2:
  1993. VecSize = 2;
  1994. break;
  1995. case NVPTXISD::LoadParamV4:
  1996. VecSize = 4;
  1997. break;
  1998. }
  1999. EVT EltVT = Node->getValueType(0);
  2000. EVT MemVT = Mem->getMemoryVT();
  2001. Optional<unsigned> Opcode;
  2002. switch (VecSize) {
  2003. default:
  2004. return false;
  2005. case 1:
  2006. Opcode = pickOpcodeForVT(MemVT.getSimpleVT().SimpleTy,
  2007. NVPTX::LoadParamMemI8, NVPTX::LoadParamMemI16,
  2008. NVPTX::LoadParamMemI32, NVPTX::LoadParamMemI64,
  2009. NVPTX::LoadParamMemF16, NVPTX::LoadParamMemF16x2,
  2010. NVPTX::LoadParamMemF32, NVPTX::LoadParamMemF64);
  2011. break;
  2012. case 2:
  2013. Opcode =
  2014. pickOpcodeForVT(MemVT.getSimpleVT().SimpleTy, NVPTX::LoadParamMemV2I8,
  2015. NVPTX::LoadParamMemV2I16, NVPTX::LoadParamMemV2I32,
  2016. NVPTX::LoadParamMemV2I64, NVPTX::LoadParamMemV2F16,
  2017. NVPTX::LoadParamMemV2F16x2, NVPTX::LoadParamMemV2F32,
  2018. NVPTX::LoadParamMemV2F64);
  2019. break;
  2020. case 4:
  2021. Opcode = pickOpcodeForVT(
  2022. MemVT.getSimpleVT().SimpleTy, NVPTX::LoadParamMemV4I8,
  2023. NVPTX::LoadParamMemV4I16, NVPTX::LoadParamMemV4I32, None,
  2024. NVPTX::LoadParamMemV4F16, NVPTX::LoadParamMemV4F16x2,
  2025. NVPTX::LoadParamMemV4F32, None);
  2026. break;
  2027. }
  2028. if (!Opcode)
  2029. return false;
  2030. SDVTList VTs;
  2031. if (VecSize == 1) {
  2032. VTs = CurDAG->getVTList(EltVT, MVT::Other, MVT::Glue);
  2033. } else if (VecSize == 2) {
  2034. VTs = CurDAG->getVTList(EltVT, EltVT, MVT::Other, MVT::Glue);
  2035. } else {
  2036. EVT EVTs[] = { EltVT, EltVT, EltVT, EltVT, MVT::Other, MVT::Glue };
  2037. VTs = CurDAG->getVTList(EVTs);
  2038. }
  2039. unsigned OffsetVal = cast<ConstantSDNode>(Offset)->getZExtValue();
  2040. SmallVector<SDValue, 2> Ops;
  2041. Ops.push_back(CurDAG->getTargetConstant(OffsetVal, DL, MVT::i32));
  2042. Ops.push_back(Chain);
  2043. Ops.push_back(Flag);
  2044. ReplaceNode(Node, CurDAG->getMachineNode(Opcode.getValue(), DL, VTs, Ops));
  2045. return true;
  2046. }
  2047. bool NVPTXDAGToDAGISel::tryStoreRetval(SDNode *N) {
  2048. SDLoc DL(N);
  2049. SDValue Chain = N->getOperand(0);
  2050. SDValue Offset = N->getOperand(1);
  2051. unsigned OffsetVal = cast<ConstantSDNode>(Offset)->getZExtValue();
  2052. MemSDNode *Mem = cast<MemSDNode>(N);
  2053. // How many elements do we have?
  2054. unsigned NumElts = 1;
  2055. switch (N->getOpcode()) {
  2056. default:
  2057. return false;
  2058. case NVPTXISD::StoreRetval:
  2059. NumElts = 1;
  2060. break;
  2061. case NVPTXISD::StoreRetvalV2:
  2062. NumElts = 2;
  2063. break;
  2064. case NVPTXISD::StoreRetvalV4:
  2065. NumElts = 4;
  2066. break;
  2067. }
  2068. // Build vector of operands
  2069. SmallVector<SDValue, 6> Ops;
  2070. for (unsigned i = 0; i < NumElts; ++i)
  2071. Ops.push_back(N->getOperand(i + 2));
  2072. Ops.push_back(CurDAG->getTargetConstant(OffsetVal, DL, MVT::i32));
  2073. Ops.push_back(Chain);
  2074. // Determine target opcode
  2075. // If we have an i1, use an 8-bit store. The lowering code in
  2076. // NVPTXISelLowering will have already emitted an upcast.
  2077. Optional<unsigned> Opcode = 0;
  2078. switch (NumElts) {
  2079. default:
  2080. return false;
  2081. case 1:
  2082. Opcode = pickOpcodeForVT(Mem->getMemoryVT().getSimpleVT().SimpleTy,
  2083. NVPTX::StoreRetvalI8, NVPTX::StoreRetvalI16,
  2084. NVPTX::StoreRetvalI32, NVPTX::StoreRetvalI64,
  2085. NVPTX::StoreRetvalF16, NVPTX::StoreRetvalF16x2,
  2086. NVPTX::StoreRetvalF32, NVPTX::StoreRetvalF64);
  2087. break;
  2088. case 2:
  2089. Opcode = pickOpcodeForVT(Mem->getMemoryVT().getSimpleVT().SimpleTy,
  2090. NVPTX::StoreRetvalV2I8, NVPTX::StoreRetvalV2I16,
  2091. NVPTX::StoreRetvalV2I32, NVPTX::StoreRetvalV2I64,
  2092. NVPTX::StoreRetvalV2F16, NVPTX::StoreRetvalV2F16x2,
  2093. NVPTX::StoreRetvalV2F32, NVPTX::StoreRetvalV2F64);
  2094. break;
  2095. case 4:
  2096. Opcode = pickOpcodeForVT(Mem->getMemoryVT().getSimpleVT().SimpleTy,
  2097. NVPTX::StoreRetvalV4I8, NVPTX::StoreRetvalV4I16,
  2098. NVPTX::StoreRetvalV4I32, None,
  2099. NVPTX::StoreRetvalV4F16, NVPTX::StoreRetvalV4F16x2,
  2100. NVPTX::StoreRetvalV4F32, None);
  2101. break;
  2102. }
  2103. if (!Opcode)
  2104. return false;
  2105. SDNode *Ret = CurDAG->getMachineNode(Opcode.getValue(), DL, MVT::Other, Ops);
  2106. MachineMemOperand *MemRef = cast<MemSDNode>(N)->getMemOperand();
  2107. CurDAG->setNodeMemRefs(cast<MachineSDNode>(Ret), {MemRef});
  2108. ReplaceNode(N, Ret);
  2109. return true;
  2110. }
  2111. bool NVPTXDAGToDAGISel::tryStoreParam(SDNode *N) {
  2112. SDLoc DL(N);
  2113. SDValue Chain = N->getOperand(0);
  2114. SDValue Param = N->getOperand(1);
  2115. unsigned ParamVal = cast<ConstantSDNode>(Param)->getZExtValue();
  2116. SDValue Offset = N->getOperand(2);
  2117. unsigned OffsetVal = cast<ConstantSDNode>(Offset)->getZExtValue();
  2118. MemSDNode *Mem = cast<MemSDNode>(N);
  2119. SDValue Flag = N->getOperand(N->getNumOperands() - 1);
  2120. // How many elements do we have?
  2121. unsigned NumElts = 1;
  2122. switch (N->getOpcode()) {
  2123. default:
  2124. return false;
  2125. case NVPTXISD::StoreParamU32:
  2126. case NVPTXISD::StoreParamS32:
  2127. case NVPTXISD::StoreParam:
  2128. NumElts = 1;
  2129. break;
  2130. case NVPTXISD::StoreParamV2:
  2131. NumElts = 2;
  2132. break;
  2133. case NVPTXISD::StoreParamV4:
  2134. NumElts = 4;
  2135. break;
  2136. }
  2137. // Build vector of operands
  2138. SmallVector<SDValue, 8> Ops;
  2139. for (unsigned i = 0; i < NumElts; ++i)
  2140. Ops.push_back(N->getOperand(i + 3));
  2141. Ops.push_back(CurDAG->getTargetConstant(ParamVal, DL, MVT::i32));
  2142. Ops.push_back(CurDAG->getTargetConstant(OffsetVal, DL, MVT::i32));
  2143. Ops.push_back(Chain);
  2144. Ops.push_back(Flag);
  2145. // Determine target opcode
  2146. // If we have an i1, use an 8-bit store. The lowering code in
  2147. // NVPTXISelLowering will have already emitted an upcast.
  2148. Optional<unsigned> Opcode = 0;
  2149. switch (N->getOpcode()) {
  2150. default:
  2151. switch (NumElts) {
  2152. default:
  2153. return false;
  2154. case 1:
  2155. Opcode = pickOpcodeForVT(Mem->getMemoryVT().getSimpleVT().SimpleTy,
  2156. NVPTX::StoreParamI8, NVPTX::StoreParamI16,
  2157. NVPTX::StoreParamI32, NVPTX::StoreParamI64,
  2158. NVPTX::StoreParamF16, NVPTX::StoreParamF16x2,
  2159. NVPTX::StoreParamF32, NVPTX::StoreParamF64);
  2160. break;
  2161. case 2:
  2162. Opcode = pickOpcodeForVT(Mem->getMemoryVT().getSimpleVT().SimpleTy,
  2163. NVPTX::StoreParamV2I8, NVPTX::StoreParamV2I16,
  2164. NVPTX::StoreParamV2I32, NVPTX::StoreParamV2I64,
  2165. NVPTX::StoreParamV2F16, NVPTX::StoreParamV2F16x2,
  2166. NVPTX::StoreParamV2F32, NVPTX::StoreParamV2F64);
  2167. break;
  2168. case 4:
  2169. Opcode = pickOpcodeForVT(Mem->getMemoryVT().getSimpleVT().SimpleTy,
  2170. NVPTX::StoreParamV4I8, NVPTX::StoreParamV4I16,
  2171. NVPTX::StoreParamV4I32, None,
  2172. NVPTX::StoreParamV4F16, NVPTX::StoreParamV4F16x2,
  2173. NVPTX::StoreParamV4F32, None);
  2174. break;
  2175. }
  2176. if (!Opcode)
  2177. return false;
  2178. break;
  2179. // Special case: if we have a sign-extend/zero-extend node, insert the
  2180. // conversion instruction first, and use that as the value operand to
  2181. // the selected StoreParam node.
  2182. case NVPTXISD::StoreParamU32: {
  2183. Opcode = NVPTX::StoreParamI32;
  2184. SDValue CvtNone = CurDAG->getTargetConstant(NVPTX::PTXCvtMode::NONE, DL,
  2185. MVT::i32);
  2186. SDNode *Cvt = CurDAG->getMachineNode(NVPTX::CVT_u32_u16, DL,
  2187. MVT::i32, Ops[0], CvtNone);
  2188. Ops[0] = SDValue(Cvt, 0);
  2189. break;
  2190. }
  2191. case NVPTXISD::StoreParamS32: {
  2192. Opcode = NVPTX::StoreParamI32;
  2193. SDValue CvtNone = CurDAG->getTargetConstant(NVPTX::PTXCvtMode::NONE, DL,
  2194. MVT::i32);
  2195. SDNode *Cvt = CurDAG->getMachineNode(NVPTX::CVT_s32_s16, DL,
  2196. MVT::i32, Ops[0], CvtNone);
  2197. Ops[0] = SDValue(Cvt, 0);
  2198. break;
  2199. }
  2200. }
  2201. SDVTList RetVTs = CurDAG->getVTList(MVT::Other, MVT::Glue);
  2202. SDNode *Ret =
  2203. CurDAG->getMachineNode(Opcode.getValue(), DL, RetVTs, Ops);
  2204. MachineMemOperand *MemRef = cast<MemSDNode>(N)->getMemOperand();
  2205. CurDAG->setNodeMemRefs(cast<MachineSDNode>(Ret), {MemRef});
  2206. ReplaceNode(N, Ret);
  2207. return true;
  2208. }
  2209. bool NVPTXDAGToDAGISel::tryTextureIntrinsic(SDNode *N) {
  2210. unsigned Opc = 0;
  2211. switch (N->getOpcode()) {
  2212. default: return false;
  2213. case NVPTXISD::Tex1DFloatS32:
  2214. Opc = NVPTX::TEX_1D_F32_S32_RR;
  2215. break;
  2216. case NVPTXISD::Tex1DFloatFloat:
  2217. Opc = NVPTX::TEX_1D_F32_F32_RR;
  2218. break;
  2219. case NVPTXISD::Tex1DFloatFloatLevel:
  2220. Opc = NVPTX::TEX_1D_F32_F32_LEVEL_RR;
  2221. break;
  2222. case NVPTXISD::Tex1DFloatFloatGrad:
  2223. Opc = NVPTX::TEX_1D_F32_F32_GRAD_RR;
  2224. break;
  2225. case NVPTXISD::Tex1DS32S32:
  2226. Opc = NVPTX::TEX_1D_S32_S32_RR;
  2227. break;
  2228. case NVPTXISD::Tex1DS32Float:
  2229. Opc = NVPTX::TEX_1D_S32_F32_RR;
  2230. break;
  2231. case NVPTXISD::Tex1DS32FloatLevel:
  2232. Opc = NVPTX::TEX_1D_S32_F32_LEVEL_RR;
  2233. break;
  2234. case NVPTXISD::Tex1DS32FloatGrad:
  2235. Opc = NVPTX::TEX_1D_S32_F32_GRAD_RR;
  2236. break;
  2237. case NVPTXISD::Tex1DU32S32:
  2238. Opc = NVPTX::TEX_1D_U32_S32_RR;
  2239. break;
  2240. case NVPTXISD::Tex1DU32Float:
  2241. Opc = NVPTX::TEX_1D_U32_F32_RR;
  2242. break;
  2243. case NVPTXISD::Tex1DU32FloatLevel:
  2244. Opc = NVPTX::TEX_1D_U32_F32_LEVEL_RR;
  2245. break;
  2246. case NVPTXISD::Tex1DU32FloatGrad:
  2247. Opc = NVPTX::TEX_1D_U32_F32_GRAD_RR;
  2248. break;
  2249. case NVPTXISD::Tex1DArrayFloatS32:
  2250. Opc = NVPTX::TEX_1D_ARRAY_F32_S32_RR;
  2251. break;
  2252. case NVPTXISD::Tex1DArrayFloatFloat:
  2253. Opc = NVPTX::TEX_1D_ARRAY_F32_F32_RR;
  2254. break;
  2255. case NVPTXISD::Tex1DArrayFloatFloatLevel:
  2256. Opc = NVPTX::TEX_1D_ARRAY_F32_F32_LEVEL_RR;
  2257. break;
  2258. case NVPTXISD::Tex1DArrayFloatFloatGrad:
  2259. Opc = NVPTX::TEX_1D_ARRAY_F32_F32_GRAD_RR;
  2260. break;
  2261. case NVPTXISD::Tex1DArrayS32S32:
  2262. Opc = NVPTX::TEX_1D_ARRAY_S32_S32_RR;
  2263. break;
  2264. case NVPTXISD::Tex1DArrayS32Float:
  2265. Opc = NVPTX::TEX_1D_ARRAY_S32_F32_RR;
  2266. break;
  2267. case NVPTXISD::Tex1DArrayS32FloatLevel:
  2268. Opc = NVPTX::TEX_1D_ARRAY_S32_F32_LEVEL_RR;
  2269. break;
  2270. case NVPTXISD::Tex1DArrayS32FloatGrad:
  2271. Opc = NVPTX::TEX_1D_ARRAY_S32_F32_GRAD_RR;
  2272. break;
  2273. case NVPTXISD::Tex1DArrayU32S32:
  2274. Opc = NVPTX::TEX_1D_ARRAY_U32_S32_RR;
  2275. break;
  2276. case NVPTXISD::Tex1DArrayU32Float:
  2277. Opc = NVPTX::TEX_1D_ARRAY_U32_F32_RR;
  2278. break;
  2279. case NVPTXISD::Tex1DArrayU32FloatLevel:
  2280. Opc = NVPTX::TEX_1D_ARRAY_U32_F32_LEVEL_RR;
  2281. break;
  2282. case NVPTXISD::Tex1DArrayU32FloatGrad:
  2283. Opc = NVPTX::TEX_1D_ARRAY_U32_F32_GRAD_RR;
  2284. break;
  2285. case NVPTXISD::Tex2DFloatS32:
  2286. Opc = NVPTX::TEX_2D_F32_S32_RR;
  2287. break;
  2288. case NVPTXISD::Tex2DFloatFloat:
  2289. Opc = NVPTX::TEX_2D_F32_F32_RR;
  2290. break;
  2291. case NVPTXISD::Tex2DFloatFloatLevel:
  2292. Opc = NVPTX::TEX_2D_F32_F32_LEVEL_RR;
  2293. break;
  2294. case NVPTXISD::Tex2DFloatFloatGrad:
  2295. Opc = NVPTX::TEX_2D_F32_F32_GRAD_RR;
  2296. break;
  2297. case NVPTXISD::Tex2DS32S32:
  2298. Opc = NVPTX::TEX_2D_S32_S32_RR;
  2299. break;
  2300. case NVPTXISD::Tex2DS32Float:
  2301. Opc = NVPTX::TEX_2D_S32_F32_RR;
  2302. break;
  2303. case NVPTXISD::Tex2DS32FloatLevel:
  2304. Opc = NVPTX::TEX_2D_S32_F32_LEVEL_RR;
  2305. break;
  2306. case NVPTXISD::Tex2DS32FloatGrad:
  2307. Opc = NVPTX::TEX_2D_S32_F32_GRAD_RR;
  2308. break;
  2309. case NVPTXISD::Tex2DU32S32:
  2310. Opc = NVPTX::TEX_2D_U32_S32_RR;
  2311. break;
  2312. case NVPTXISD::Tex2DU32Float:
  2313. Opc = NVPTX::TEX_2D_U32_F32_RR;
  2314. break;
  2315. case NVPTXISD::Tex2DU32FloatLevel:
  2316. Opc = NVPTX::TEX_2D_U32_F32_LEVEL_RR;
  2317. break;
  2318. case NVPTXISD::Tex2DU32FloatGrad:
  2319. Opc = NVPTX::TEX_2D_U32_F32_GRAD_RR;
  2320. break;
  2321. case NVPTXISD::Tex2DArrayFloatS32:
  2322. Opc = NVPTX::TEX_2D_ARRAY_F32_S32_RR;
  2323. break;
  2324. case NVPTXISD::Tex2DArrayFloatFloat:
  2325. Opc = NVPTX::TEX_2D_ARRAY_F32_F32_RR;
  2326. break;
  2327. case NVPTXISD::Tex2DArrayFloatFloatLevel:
  2328. Opc = NVPTX::TEX_2D_ARRAY_F32_F32_LEVEL_RR;
  2329. break;
  2330. case NVPTXISD::Tex2DArrayFloatFloatGrad:
  2331. Opc = NVPTX::TEX_2D_ARRAY_F32_F32_GRAD_RR;
  2332. break;
  2333. case NVPTXISD::Tex2DArrayS32S32:
  2334. Opc = NVPTX::TEX_2D_ARRAY_S32_S32_RR;
  2335. break;
  2336. case NVPTXISD::Tex2DArrayS32Float:
  2337. Opc = NVPTX::TEX_2D_ARRAY_S32_F32_RR;
  2338. break;
  2339. case NVPTXISD::Tex2DArrayS32FloatLevel:
  2340. Opc = NVPTX::TEX_2D_ARRAY_S32_F32_LEVEL_RR;
  2341. break;
  2342. case NVPTXISD::Tex2DArrayS32FloatGrad:
  2343. Opc = NVPTX::TEX_2D_ARRAY_S32_F32_GRAD_RR;
  2344. break;
  2345. case NVPTXISD::Tex2DArrayU32S32:
  2346. Opc = NVPTX::TEX_2D_ARRAY_U32_S32_RR;
  2347. break;
  2348. case NVPTXISD::Tex2DArrayU32Float:
  2349. Opc = NVPTX::TEX_2D_ARRAY_U32_F32_RR;
  2350. break;
  2351. case NVPTXISD::Tex2DArrayU32FloatLevel:
  2352. Opc = NVPTX::TEX_2D_ARRAY_U32_F32_LEVEL_RR;
  2353. break;
  2354. case NVPTXISD::Tex2DArrayU32FloatGrad:
  2355. Opc = NVPTX::TEX_2D_ARRAY_U32_F32_GRAD_RR;
  2356. break;
  2357. case NVPTXISD::Tex3DFloatS32:
  2358. Opc = NVPTX::TEX_3D_F32_S32_RR;
  2359. break;
  2360. case NVPTXISD::Tex3DFloatFloat:
  2361. Opc = NVPTX::TEX_3D_F32_F32_RR;
  2362. break;
  2363. case NVPTXISD::Tex3DFloatFloatLevel:
  2364. Opc = NVPTX::TEX_3D_F32_F32_LEVEL_RR;
  2365. break;
  2366. case NVPTXISD::Tex3DFloatFloatGrad:
  2367. Opc = NVPTX::TEX_3D_F32_F32_GRAD_RR;
  2368. break;
  2369. case NVPTXISD::Tex3DS32S32:
  2370. Opc = NVPTX::TEX_3D_S32_S32_RR;
  2371. break;
  2372. case NVPTXISD::Tex3DS32Float:
  2373. Opc = NVPTX::TEX_3D_S32_F32_RR;
  2374. break;
  2375. case NVPTXISD::Tex3DS32FloatLevel:
  2376. Opc = NVPTX::TEX_3D_S32_F32_LEVEL_RR;
  2377. break;
  2378. case NVPTXISD::Tex3DS32FloatGrad:
  2379. Opc = NVPTX::TEX_3D_S32_F32_GRAD_RR;
  2380. break;
  2381. case NVPTXISD::Tex3DU32S32:
  2382. Opc = NVPTX::TEX_3D_U32_S32_RR;
  2383. break;
  2384. case NVPTXISD::Tex3DU32Float:
  2385. Opc = NVPTX::TEX_3D_U32_F32_RR;
  2386. break;
  2387. case NVPTXISD::Tex3DU32FloatLevel:
  2388. Opc = NVPTX::TEX_3D_U32_F32_LEVEL_RR;
  2389. break;
  2390. case NVPTXISD::Tex3DU32FloatGrad:
  2391. Opc = NVPTX::TEX_3D_U32_F32_GRAD_RR;
  2392. break;
  2393. case NVPTXISD::TexCubeFloatFloat:
  2394. Opc = NVPTX::TEX_CUBE_F32_F32_RR;
  2395. break;
  2396. case NVPTXISD::TexCubeFloatFloatLevel:
  2397. Opc = NVPTX::TEX_CUBE_F32_F32_LEVEL_RR;
  2398. break;
  2399. case NVPTXISD::TexCubeS32Float:
  2400. Opc = NVPTX::TEX_CUBE_S32_F32_RR;
  2401. break;
  2402. case NVPTXISD::TexCubeS32FloatLevel:
  2403. Opc = NVPTX::TEX_CUBE_S32_F32_LEVEL_RR;
  2404. break;
  2405. case NVPTXISD::TexCubeU32Float:
  2406. Opc = NVPTX::TEX_CUBE_U32_F32_RR;
  2407. break;
  2408. case NVPTXISD::TexCubeU32FloatLevel:
  2409. Opc = NVPTX::TEX_CUBE_U32_F32_LEVEL_RR;
  2410. break;
  2411. case NVPTXISD::TexCubeArrayFloatFloat:
  2412. Opc = NVPTX::TEX_CUBE_ARRAY_F32_F32_RR;
  2413. break;
  2414. case NVPTXISD::TexCubeArrayFloatFloatLevel:
  2415. Opc = NVPTX::TEX_CUBE_ARRAY_F32_F32_LEVEL_RR;
  2416. break;
  2417. case NVPTXISD::TexCubeArrayS32Float:
  2418. Opc = NVPTX::TEX_CUBE_ARRAY_S32_F32_RR;
  2419. break;
  2420. case NVPTXISD::TexCubeArrayS32FloatLevel:
  2421. Opc = NVPTX::TEX_CUBE_ARRAY_S32_F32_LEVEL_RR;
  2422. break;
  2423. case NVPTXISD::TexCubeArrayU32Float:
  2424. Opc = NVPTX::TEX_CUBE_ARRAY_U32_F32_RR;
  2425. break;
  2426. case NVPTXISD::TexCubeArrayU32FloatLevel:
  2427. Opc = NVPTX::TEX_CUBE_ARRAY_U32_F32_LEVEL_RR;
  2428. break;
  2429. case NVPTXISD::Tld4R2DFloatFloat:
  2430. Opc = NVPTX::TLD4_R_2D_F32_F32_RR;
  2431. break;
  2432. case NVPTXISD::Tld4G2DFloatFloat:
  2433. Opc = NVPTX::TLD4_G_2D_F32_F32_RR;
  2434. break;
  2435. case NVPTXISD::Tld4B2DFloatFloat:
  2436. Opc = NVPTX::TLD4_B_2D_F32_F32_RR;
  2437. break;
  2438. case NVPTXISD::Tld4A2DFloatFloat:
  2439. Opc = NVPTX::TLD4_A_2D_F32_F32_RR;
  2440. break;
  2441. case NVPTXISD::Tld4R2DS64Float:
  2442. Opc = NVPTX::TLD4_R_2D_S32_F32_RR;
  2443. break;
  2444. case NVPTXISD::Tld4G2DS64Float:
  2445. Opc = NVPTX::TLD4_G_2D_S32_F32_RR;
  2446. break;
  2447. case NVPTXISD::Tld4B2DS64Float:
  2448. Opc = NVPTX::TLD4_B_2D_S32_F32_RR;
  2449. break;
  2450. case NVPTXISD::Tld4A2DS64Float:
  2451. Opc = NVPTX::TLD4_A_2D_S32_F32_RR;
  2452. break;
  2453. case NVPTXISD::Tld4R2DU64Float:
  2454. Opc = NVPTX::TLD4_R_2D_U32_F32_RR;
  2455. break;
  2456. case NVPTXISD::Tld4G2DU64Float:
  2457. Opc = NVPTX::TLD4_G_2D_U32_F32_RR;
  2458. break;
  2459. case NVPTXISD::Tld4B2DU64Float:
  2460. Opc = NVPTX::TLD4_B_2D_U32_F32_RR;
  2461. break;
  2462. case NVPTXISD::Tld4A2DU64Float:
  2463. Opc = NVPTX::TLD4_A_2D_U32_F32_RR;
  2464. break;
  2465. case NVPTXISD::TexUnified1DFloatS32:
  2466. Opc = NVPTX::TEX_UNIFIED_1D_F32_S32_R;
  2467. break;
  2468. case NVPTXISD::TexUnified1DFloatFloat:
  2469. Opc = NVPTX::TEX_UNIFIED_1D_F32_F32_R;
  2470. break;
  2471. case NVPTXISD::TexUnified1DFloatFloatLevel:
  2472. Opc = NVPTX::TEX_UNIFIED_1D_F32_F32_LEVEL_R;
  2473. break;
  2474. case NVPTXISD::TexUnified1DFloatFloatGrad:
  2475. Opc = NVPTX::TEX_UNIFIED_1D_F32_F32_GRAD_R;
  2476. break;
  2477. case NVPTXISD::TexUnified1DS32S32:
  2478. Opc = NVPTX::TEX_UNIFIED_1D_S32_S32_R;
  2479. break;
  2480. case NVPTXISD::TexUnified1DS32Float:
  2481. Opc = NVPTX::TEX_UNIFIED_1D_S32_F32_R;
  2482. break;
  2483. case NVPTXISD::TexUnified1DS32FloatLevel:
  2484. Opc = NVPTX::TEX_UNIFIED_1D_S32_F32_LEVEL_R;
  2485. break;
  2486. case NVPTXISD::TexUnified1DS32FloatGrad:
  2487. Opc = NVPTX::TEX_UNIFIED_1D_S32_F32_GRAD_R;
  2488. break;
  2489. case NVPTXISD::TexUnified1DU32S32:
  2490. Opc = NVPTX::TEX_UNIFIED_1D_U32_S32_R;
  2491. break;
  2492. case NVPTXISD::TexUnified1DU32Float:
  2493. Opc = NVPTX::TEX_UNIFIED_1D_U32_F32_R;
  2494. break;
  2495. case NVPTXISD::TexUnified1DU32FloatLevel:
  2496. Opc = NVPTX::TEX_UNIFIED_1D_U32_F32_LEVEL_R;
  2497. break;
  2498. case NVPTXISD::TexUnified1DU32FloatGrad:
  2499. Opc = NVPTX::TEX_UNIFIED_1D_U32_F32_GRAD_R;
  2500. break;
  2501. case NVPTXISD::TexUnified1DArrayFloatS32:
  2502. Opc = NVPTX::TEX_UNIFIED_1D_ARRAY_F32_S32_R;
  2503. break;
  2504. case NVPTXISD::TexUnified1DArrayFloatFloat:
  2505. Opc = NVPTX::TEX_UNIFIED_1D_ARRAY_F32_F32_R;
  2506. break;
  2507. case NVPTXISD::TexUnified1DArrayFloatFloatLevel:
  2508. Opc = NVPTX::TEX_UNIFIED_1D_ARRAY_F32_F32_LEVEL_R;
  2509. break;
  2510. case NVPTXISD::TexUnified1DArrayFloatFloatGrad:
  2511. Opc = NVPTX::TEX_UNIFIED_1D_ARRAY_F32_F32_GRAD_R;
  2512. break;
  2513. case NVPTXISD::TexUnified1DArrayS32S32:
  2514. Opc = NVPTX::TEX_UNIFIED_1D_ARRAY_S32_S32_R;
  2515. break;
  2516. case NVPTXISD::TexUnified1DArrayS32Float:
  2517. Opc = NVPTX::TEX_UNIFIED_1D_ARRAY_S32_F32_R;
  2518. break;
  2519. case NVPTXISD::TexUnified1DArrayS32FloatLevel:
  2520. Opc = NVPTX::TEX_UNIFIED_1D_ARRAY_S32_F32_LEVEL_R;
  2521. break;
  2522. case NVPTXISD::TexUnified1DArrayS32FloatGrad:
  2523. Opc = NVPTX::TEX_UNIFIED_1D_ARRAY_S32_F32_GRAD_R;
  2524. break;
  2525. case NVPTXISD::TexUnified1DArrayU32S32:
  2526. Opc = NVPTX::TEX_UNIFIED_1D_ARRAY_U32_S32_R;
  2527. break;
  2528. case NVPTXISD::TexUnified1DArrayU32Float:
  2529. Opc = NVPTX::TEX_UNIFIED_1D_ARRAY_U32_F32_R;
  2530. break;
  2531. case NVPTXISD::TexUnified1DArrayU32FloatLevel:
  2532. Opc = NVPTX::TEX_UNIFIED_1D_ARRAY_U32_F32_LEVEL_R;
  2533. break;
  2534. case NVPTXISD::TexUnified1DArrayU32FloatGrad:
  2535. Opc = NVPTX::TEX_UNIFIED_1D_ARRAY_U32_F32_GRAD_R;
  2536. break;
  2537. case NVPTXISD::TexUnified2DFloatS32:
  2538. Opc = NVPTX::TEX_UNIFIED_2D_F32_S32_R;
  2539. break;
  2540. case NVPTXISD::TexUnified2DFloatFloat:
  2541. Opc = NVPTX::TEX_UNIFIED_2D_F32_F32_R;
  2542. break;
  2543. case NVPTXISD::TexUnified2DFloatFloatLevel:
  2544. Opc = NVPTX::TEX_UNIFIED_2D_F32_F32_LEVEL_R;
  2545. break;
  2546. case NVPTXISD::TexUnified2DFloatFloatGrad:
  2547. Opc = NVPTX::TEX_UNIFIED_2D_F32_F32_GRAD_R;
  2548. break;
  2549. case NVPTXISD::TexUnified2DS32S32:
  2550. Opc = NVPTX::TEX_UNIFIED_2D_S32_S32_R;
  2551. break;
  2552. case NVPTXISD::TexUnified2DS32Float:
  2553. Opc = NVPTX::TEX_UNIFIED_2D_S32_F32_R;
  2554. break;
  2555. case NVPTXISD::TexUnified2DS32FloatLevel:
  2556. Opc = NVPTX::TEX_UNIFIED_2D_S32_F32_LEVEL_R;
  2557. break;
  2558. case NVPTXISD::TexUnified2DS32FloatGrad:
  2559. Opc = NVPTX::TEX_UNIFIED_2D_S32_F32_GRAD_R;
  2560. break;
  2561. case NVPTXISD::TexUnified2DU32S32:
  2562. Opc = NVPTX::TEX_UNIFIED_2D_U32_S32_R;
  2563. break;
  2564. case NVPTXISD::TexUnified2DU32Float:
  2565. Opc = NVPTX::TEX_UNIFIED_2D_U32_F32_R;
  2566. break;
  2567. case NVPTXISD::TexUnified2DU32FloatLevel:
  2568. Opc = NVPTX::TEX_UNIFIED_2D_U32_F32_LEVEL_R;
  2569. break;
  2570. case NVPTXISD::TexUnified2DU32FloatGrad:
  2571. Opc = NVPTX::TEX_UNIFIED_2D_U32_F32_GRAD_R;
  2572. break;
  2573. case NVPTXISD::TexUnified2DArrayFloatS32:
  2574. Opc = NVPTX::TEX_UNIFIED_2D_ARRAY_F32_S32_R;
  2575. break;
  2576. case NVPTXISD::TexUnified2DArrayFloatFloat:
  2577. Opc = NVPTX::TEX_UNIFIED_2D_ARRAY_F32_F32_R;
  2578. break;
  2579. case NVPTXISD::TexUnified2DArrayFloatFloatLevel:
  2580. Opc = NVPTX::TEX_UNIFIED_2D_ARRAY_F32_F32_LEVEL_R;
  2581. break;
  2582. case NVPTXISD::TexUnified2DArrayFloatFloatGrad:
  2583. Opc = NVPTX::TEX_UNIFIED_2D_ARRAY_F32_F32_GRAD_R;
  2584. break;
  2585. case NVPTXISD::TexUnified2DArrayS32S32:
  2586. Opc = NVPTX::TEX_UNIFIED_2D_ARRAY_S32_S32_R;
  2587. break;
  2588. case NVPTXISD::TexUnified2DArrayS32Float:
  2589. Opc = NVPTX::TEX_UNIFIED_2D_ARRAY_S32_F32_R;
  2590. break;
  2591. case NVPTXISD::TexUnified2DArrayS32FloatLevel:
  2592. Opc = NVPTX::TEX_UNIFIED_2D_ARRAY_S32_F32_LEVEL_R;
  2593. break;
  2594. case NVPTXISD::TexUnified2DArrayS32FloatGrad:
  2595. Opc = NVPTX::TEX_UNIFIED_2D_ARRAY_S32_F32_GRAD_R;
  2596. break;
  2597. case NVPTXISD::TexUnified2DArrayU32S32:
  2598. Opc = NVPTX::TEX_UNIFIED_2D_ARRAY_U32_S32_R;
  2599. break;
  2600. case NVPTXISD::TexUnified2DArrayU32Float:
  2601. Opc = NVPTX::TEX_UNIFIED_2D_ARRAY_U32_F32_R;
  2602. break;
  2603. case NVPTXISD::TexUnified2DArrayU32FloatLevel:
  2604. Opc = NVPTX::TEX_UNIFIED_2D_ARRAY_U32_F32_LEVEL_R;
  2605. break;
  2606. case NVPTXISD::TexUnified2DArrayU32FloatGrad:
  2607. Opc = NVPTX::TEX_UNIFIED_2D_ARRAY_U32_F32_GRAD_R;
  2608. break;
  2609. case NVPTXISD::TexUnified3DFloatS32:
  2610. Opc = NVPTX::TEX_UNIFIED_3D_F32_S32_R;
  2611. break;
  2612. case NVPTXISD::TexUnified3DFloatFloat:
  2613. Opc = NVPTX::TEX_UNIFIED_3D_F32_F32_R;
  2614. break;
  2615. case NVPTXISD::TexUnified3DFloatFloatLevel:
  2616. Opc = NVPTX::TEX_UNIFIED_3D_F32_F32_LEVEL_R;
  2617. break;
  2618. case NVPTXISD::TexUnified3DFloatFloatGrad:
  2619. Opc = NVPTX::TEX_UNIFIED_3D_F32_F32_GRAD_R;
  2620. break;
  2621. case NVPTXISD::TexUnified3DS32S32:
  2622. Opc = NVPTX::TEX_UNIFIED_3D_S32_S32_R;
  2623. break;
  2624. case NVPTXISD::TexUnified3DS32Float:
  2625. Opc = NVPTX::TEX_UNIFIED_3D_S32_F32_R;
  2626. break;
  2627. case NVPTXISD::TexUnified3DS32FloatLevel:
  2628. Opc = NVPTX::TEX_UNIFIED_3D_S32_F32_LEVEL_R;
  2629. break;
  2630. case NVPTXISD::TexUnified3DS32FloatGrad:
  2631. Opc = NVPTX::TEX_UNIFIED_3D_S32_F32_GRAD_R;
  2632. break;
  2633. case NVPTXISD::TexUnified3DU32S32:
  2634. Opc = NVPTX::TEX_UNIFIED_3D_U32_S32_R;
  2635. break;
  2636. case NVPTXISD::TexUnified3DU32Float:
  2637. Opc = NVPTX::TEX_UNIFIED_3D_U32_F32_R;
  2638. break;
  2639. case NVPTXISD::TexUnified3DU32FloatLevel:
  2640. Opc = NVPTX::TEX_UNIFIED_3D_U32_F32_LEVEL_R;
  2641. break;
  2642. case NVPTXISD::TexUnified3DU32FloatGrad:
  2643. Opc = NVPTX::TEX_UNIFIED_3D_U32_F32_GRAD_R;
  2644. break;
  2645. case NVPTXISD::TexUnifiedCubeFloatFloat:
  2646. Opc = NVPTX::TEX_UNIFIED_CUBE_F32_F32_R;
  2647. break;
  2648. case NVPTXISD::TexUnifiedCubeFloatFloatLevel:
  2649. Opc = NVPTX::TEX_UNIFIED_CUBE_F32_F32_LEVEL_R;
  2650. break;
  2651. case NVPTXISD::TexUnifiedCubeS32Float:
  2652. Opc = NVPTX::TEX_UNIFIED_CUBE_S32_F32_R;
  2653. break;
  2654. case NVPTXISD::TexUnifiedCubeS32FloatLevel:
  2655. Opc = NVPTX::TEX_UNIFIED_CUBE_S32_F32_LEVEL_R;
  2656. break;
  2657. case NVPTXISD::TexUnifiedCubeU32Float:
  2658. Opc = NVPTX::TEX_UNIFIED_CUBE_U32_F32_R;
  2659. break;
  2660. case NVPTXISD::TexUnifiedCubeU32FloatLevel:
  2661. Opc = NVPTX::TEX_UNIFIED_CUBE_U32_F32_LEVEL_R;
  2662. break;
  2663. case NVPTXISD::TexUnifiedCubeArrayFloatFloat:
  2664. Opc = NVPTX::TEX_UNIFIED_CUBE_ARRAY_F32_F32_R;
  2665. break;
  2666. case NVPTXISD::TexUnifiedCubeArrayFloatFloatLevel:
  2667. Opc = NVPTX::TEX_UNIFIED_CUBE_ARRAY_F32_F32_LEVEL_R;
  2668. break;
  2669. case NVPTXISD::TexUnifiedCubeArrayS32Float:
  2670. Opc = NVPTX::TEX_UNIFIED_CUBE_ARRAY_S32_F32_R;
  2671. break;
  2672. case NVPTXISD::TexUnifiedCubeArrayS32FloatLevel:
  2673. Opc = NVPTX::TEX_UNIFIED_CUBE_ARRAY_S32_F32_LEVEL_R;
  2674. break;
  2675. case NVPTXISD::TexUnifiedCubeArrayU32Float:
  2676. Opc = NVPTX::TEX_UNIFIED_CUBE_ARRAY_U32_F32_R;
  2677. break;
  2678. case NVPTXISD::TexUnifiedCubeArrayU32FloatLevel:
  2679. Opc = NVPTX::TEX_UNIFIED_CUBE_ARRAY_U32_F32_LEVEL_R;
  2680. break;
  2681. case NVPTXISD::Tld4UnifiedR2DFloatFloat:
  2682. Opc = NVPTX::TLD4_UNIFIED_R_2D_F32_F32_R;
  2683. break;
  2684. case NVPTXISD::Tld4UnifiedG2DFloatFloat:
  2685. Opc = NVPTX::TLD4_UNIFIED_G_2D_F32_F32_R;
  2686. break;
  2687. case NVPTXISD::Tld4UnifiedB2DFloatFloat:
  2688. Opc = NVPTX::TLD4_UNIFIED_B_2D_F32_F32_R;
  2689. break;
  2690. case NVPTXISD::Tld4UnifiedA2DFloatFloat:
  2691. Opc = NVPTX::TLD4_UNIFIED_A_2D_F32_F32_R;
  2692. break;
  2693. case NVPTXISD::Tld4UnifiedR2DS64Float:
  2694. Opc = NVPTX::TLD4_UNIFIED_R_2D_S32_F32_R;
  2695. break;
  2696. case NVPTXISD::Tld4UnifiedG2DS64Float:
  2697. Opc = NVPTX::TLD4_UNIFIED_G_2D_S32_F32_R;
  2698. break;
  2699. case NVPTXISD::Tld4UnifiedB2DS64Float:
  2700. Opc = NVPTX::TLD4_UNIFIED_B_2D_S32_F32_R;
  2701. break;
  2702. case NVPTXISD::Tld4UnifiedA2DS64Float:
  2703. Opc = NVPTX::TLD4_UNIFIED_A_2D_S32_F32_R;
  2704. break;
  2705. case NVPTXISD::Tld4UnifiedR2DU64Float:
  2706. Opc = NVPTX::TLD4_UNIFIED_R_2D_U32_F32_R;
  2707. break;
  2708. case NVPTXISD::Tld4UnifiedG2DU64Float:
  2709. Opc = NVPTX::TLD4_UNIFIED_G_2D_U32_F32_R;
  2710. break;
  2711. case NVPTXISD::Tld4UnifiedB2DU64Float:
  2712. Opc = NVPTX::TLD4_UNIFIED_B_2D_U32_F32_R;
  2713. break;
  2714. case NVPTXISD::Tld4UnifiedA2DU64Float:
  2715. Opc = NVPTX::TLD4_UNIFIED_A_2D_U32_F32_R;
  2716. break;
  2717. }
  2718. // Copy over operands
  2719. SmallVector<SDValue, 8> Ops(drop_begin(N->ops()));
  2720. Ops.push_back(N->getOperand(0)); // Move chain to the back.
  2721. ReplaceNode(N, CurDAG->getMachineNode(Opc, SDLoc(N), N->getVTList(), Ops));
  2722. return true;
  2723. }
  2724. bool NVPTXDAGToDAGISel::trySurfaceIntrinsic(SDNode *N) {
  2725. unsigned Opc = 0;
  2726. switch (N->getOpcode()) {
  2727. default: return false;
  2728. case NVPTXISD::Suld1DI8Clamp:
  2729. Opc = NVPTX::SULD_1D_I8_CLAMP_R;
  2730. break;
  2731. case NVPTXISD::Suld1DI16Clamp:
  2732. Opc = NVPTX::SULD_1D_I16_CLAMP_R;
  2733. break;
  2734. case NVPTXISD::Suld1DI32Clamp:
  2735. Opc = NVPTX::SULD_1D_I32_CLAMP_R;
  2736. break;
  2737. case NVPTXISD::Suld1DI64Clamp:
  2738. Opc = NVPTX::SULD_1D_I64_CLAMP_R;
  2739. break;
  2740. case NVPTXISD::Suld1DV2I8Clamp:
  2741. Opc = NVPTX::SULD_1D_V2I8_CLAMP_R;
  2742. break;
  2743. case NVPTXISD::Suld1DV2I16Clamp:
  2744. Opc = NVPTX::SULD_1D_V2I16_CLAMP_R;
  2745. break;
  2746. case NVPTXISD::Suld1DV2I32Clamp:
  2747. Opc = NVPTX::SULD_1D_V2I32_CLAMP_R;
  2748. break;
  2749. case NVPTXISD::Suld1DV2I64Clamp:
  2750. Opc = NVPTX::SULD_1D_V2I64_CLAMP_R;
  2751. break;
  2752. case NVPTXISD::Suld1DV4I8Clamp:
  2753. Opc = NVPTX::SULD_1D_V4I8_CLAMP_R;
  2754. break;
  2755. case NVPTXISD::Suld1DV4I16Clamp:
  2756. Opc = NVPTX::SULD_1D_V4I16_CLAMP_R;
  2757. break;
  2758. case NVPTXISD::Suld1DV4I32Clamp:
  2759. Opc = NVPTX::SULD_1D_V4I32_CLAMP_R;
  2760. break;
  2761. case NVPTXISD::Suld1DArrayI8Clamp:
  2762. Opc = NVPTX::SULD_1D_ARRAY_I8_CLAMP_R;
  2763. break;
  2764. case NVPTXISD::Suld1DArrayI16Clamp:
  2765. Opc = NVPTX::SULD_1D_ARRAY_I16_CLAMP_R;
  2766. break;
  2767. case NVPTXISD::Suld1DArrayI32Clamp:
  2768. Opc = NVPTX::SULD_1D_ARRAY_I32_CLAMP_R;
  2769. break;
  2770. case NVPTXISD::Suld1DArrayI64Clamp:
  2771. Opc = NVPTX::SULD_1D_ARRAY_I64_CLAMP_R;
  2772. break;
  2773. case NVPTXISD::Suld1DArrayV2I8Clamp:
  2774. Opc = NVPTX::SULD_1D_ARRAY_V2I8_CLAMP_R;
  2775. break;
  2776. case NVPTXISD::Suld1DArrayV2I16Clamp:
  2777. Opc = NVPTX::SULD_1D_ARRAY_V2I16_CLAMP_R;
  2778. break;
  2779. case NVPTXISD::Suld1DArrayV2I32Clamp:
  2780. Opc = NVPTX::SULD_1D_ARRAY_V2I32_CLAMP_R;
  2781. break;
  2782. case NVPTXISD::Suld1DArrayV2I64Clamp:
  2783. Opc = NVPTX::SULD_1D_ARRAY_V2I64_CLAMP_R;
  2784. break;
  2785. case NVPTXISD::Suld1DArrayV4I8Clamp:
  2786. Opc = NVPTX::SULD_1D_ARRAY_V4I8_CLAMP_R;
  2787. break;
  2788. case NVPTXISD::Suld1DArrayV4I16Clamp:
  2789. Opc = NVPTX::SULD_1D_ARRAY_V4I16_CLAMP_R;
  2790. break;
  2791. case NVPTXISD::Suld1DArrayV4I32Clamp:
  2792. Opc = NVPTX::SULD_1D_ARRAY_V4I32_CLAMP_R;
  2793. break;
  2794. case NVPTXISD::Suld2DI8Clamp:
  2795. Opc = NVPTX::SULD_2D_I8_CLAMP_R;
  2796. break;
  2797. case NVPTXISD::Suld2DI16Clamp:
  2798. Opc = NVPTX::SULD_2D_I16_CLAMP_R;
  2799. break;
  2800. case NVPTXISD::Suld2DI32Clamp:
  2801. Opc = NVPTX::SULD_2D_I32_CLAMP_R;
  2802. break;
  2803. case NVPTXISD::Suld2DI64Clamp:
  2804. Opc = NVPTX::SULD_2D_I64_CLAMP_R;
  2805. break;
  2806. case NVPTXISD::Suld2DV2I8Clamp:
  2807. Opc = NVPTX::SULD_2D_V2I8_CLAMP_R;
  2808. break;
  2809. case NVPTXISD::Suld2DV2I16Clamp:
  2810. Opc = NVPTX::SULD_2D_V2I16_CLAMP_R;
  2811. break;
  2812. case NVPTXISD::Suld2DV2I32Clamp:
  2813. Opc = NVPTX::SULD_2D_V2I32_CLAMP_R;
  2814. break;
  2815. case NVPTXISD::Suld2DV2I64Clamp:
  2816. Opc = NVPTX::SULD_2D_V2I64_CLAMP_R;
  2817. break;
  2818. case NVPTXISD::Suld2DV4I8Clamp:
  2819. Opc = NVPTX::SULD_2D_V4I8_CLAMP_R;
  2820. break;
  2821. case NVPTXISD::Suld2DV4I16Clamp:
  2822. Opc = NVPTX::SULD_2D_V4I16_CLAMP_R;
  2823. break;
  2824. case NVPTXISD::Suld2DV4I32Clamp:
  2825. Opc = NVPTX::SULD_2D_V4I32_CLAMP_R;
  2826. break;
  2827. case NVPTXISD::Suld2DArrayI8Clamp:
  2828. Opc = NVPTX::SULD_2D_ARRAY_I8_CLAMP_R;
  2829. break;
  2830. case NVPTXISD::Suld2DArrayI16Clamp:
  2831. Opc = NVPTX::SULD_2D_ARRAY_I16_CLAMP_R;
  2832. break;
  2833. case NVPTXISD::Suld2DArrayI32Clamp:
  2834. Opc = NVPTX::SULD_2D_ARRAY_I32_CLAMP_R;
  2835. break;
  2836. case NVPTXISD::Suld2DArrayI64Clamp:
  2837. Opc = NVPTX::SULD_2D_ARRAY_I64_CLAMP_R;
  2838. break;
  2839. case NVPTXISD::Suld2DArrayV2I8Clamp:
  2840. Opc = NVPTX::SULD_2D_ARRAY_V2I8_CLAMP_R;
  2841. break;
  2842. case NVPTXISD::Suld2DArrayV2I16Clamp:
  2843. Opc = NVPTX::SULD_2D_ARRAY_V2I16_CLAMP_R;
  2844. break;
  2845. case NVPTXISD::Suld2DArrayV2I32Clamp:
  2846. Opc = NVPTX::SULD_2D_ARRAY_V2I32_CLAMP_R;
  2847. break;
  2848. case NVPTXISD::Suld2DArrayV2I64Clamp:
  2849. Opc = NVPTX::SULD_2D_ARRAY_V2I64_CLAMP_R;
  2850. break;
  2851. case NVPTXISD::Suld2DArrayV4I8Clamp:
  2852. Opc = NVPTX::SULD_2D_ARRAY_V4I8_CLAMP_R;
  2853. break;
  2854. case NVPTXISD::Suld2DArrayV4I16Clamp:
  2855. Opc = NVPTX::SULD_2D_ARRAY_V4I16_CLAMP_R;
  2856. break;
  2857. case NVPTXISD::Suld2DArrayV4I32Clamp:
  2858. Opc = NVPTX::SULD_2D_ARRAY_V4I32_CLAMP_R;
  2859. break;
  2860. case NVPTXISD::Suld3DI8Clamp:
  2861. Opc = NVPTX::SULD_3D_I8_CLAMP_R;
  2862. break;
  2863. case NVPTXISD::Suld3DI16Clamp:
  2864. Opc = NVPTX::SULD_3D_I16_CLAMP_R;
  2865. break;
  2866. case NVPTXISD::Suld3DI32Clamp:
  2867. Opc = NVPTX::SULD_3D_I32_CLAMP_R;
  2868. break;
  2869. case NVPTXISD::Suld3DI64Clamp:
  2870. Opc = NVPTX::SULD_3D_I64_CLAMP_R;
  2871. break;
  2872. case NVPTXISD::Suld3DV2I8Clamp:
  2873. Opc = NVPTX::SULD_3D_V2I8_CLAMP_R;
  2874. break;
  2875. case NVPTXISD::Suld3DV2I16Clamp:
  2876. Opc = NVPTX::SULD_3D_V2I16_CLAMP_R;
  2877. break;
  2878. case NVPTXISD::Suld3DV2I32Clamp:
  2879. Opc = NVPTX::SULD_3D_V2I32_CLAMP_R;
  2880. break;
  2881. case NVPTXISD::Suld3DV2I64Clamp:
  2882. Opc = NVPTX::SULD_3D_V2I64_CLAMP_R;
  2883. break;
  2884. case NVPTXISD::Suld3DV4I8Clamp:
  2885. Opc = NVPTX::SULD_3D_V4I8_CLAMP_R;
  2886. break;
  2887. case NVPTXISD::Suld3DV4I16Clamp:
  2888. Opc = NVPTX::SULD_3D_V4I16_CLAMP_R;
  2889. break;
  2890. case NVPTXISD::Suld3DV4I32Clamp:
  2891. Opc = NVPTX::SULD_3D_V4I32_CLAMP_R;
  2892. break;
  2893. case NVPTXISD::Suld1DI8Trap:
  2894. Opc = NVPTX::SULD_1D_I8_TRAP_R;
  2895. break;
  2896. case NVPTXISD::Suld1DI16Trap:
  2897. Opc = NVPTX::SULD_1D_I16_TRAP_R;
  2898. break;
  2899. case NVPTXISD::Suld1DI32Trap:
  2900. Opc = NVPTX::SULD_1D_I32_TRAP_R;
  2901. break;
  2902. case NVPTXISD::Suld1DI64Trap:
  2903. Opc = NVPTX::SULD_1D_I64_TRAP_R;
  2904. break;
  2905. case NVPTXISD::Suld1DV2I8Trap:
  2906. Opc = NVPTX::SULD_1D_V2I8_TRAP_R;
  2907. break;
  2908. case NVPTXISD::Suld1DV2I16Trap:
  2909. Opc = NVPTX::SULD_1D_V2I16_TRAP_R;
  2910. break;
  2911. case NVPTXISD::Suld1DV2I32Trap:
  2912. Opc = NVPTX::SULD_1D_V2I32_TRAP_R;
  2913. break;
  2914. case NVPTXISD::Suld1DV2I64Trap:
  2915. Opc = NVPTX::SULD_1D_V2I64_TRAP_R;
  2916. break;
  2917. case NVPTXISD::Suld1DV4I8Trap:
  2918. Opc = NVPTX::SULD_1D_V4I8_TRAP_R;
  2919. break;
  2920. case NVPTXISD::Suld1DV4I16Trap:
  2921. Opc = NVPTX::SULD_1D_V4I16_TRAP_R;
  2922. break;
  2923. case NVPTXISD::Suld1DV4I32Trap:
  2924. Opc = NVPTX::SULD_1D_V4I32_TRAP_R;
  2925. break;
  2926. case NVPTXISD::Suld1DArrayI8Trap:
  2927. Opc = NVPTX::SULD_1D_ARRAY_I8_TRAP_R;
  2928. break;
  2929. case NVPTXISD::Suld1DArrayI16Trap:
  2930. Opc = NVPTX::SULD_1D_ARRAY_I16_TRAP_R;
  2931. break;
  2932. case NVPTXISD::Suld1DArrayI32Trap:
  2933. Opc = NVPTX::SULD_1D_ARRAY_I32_TRAP_R;
  2934. break;
  2935. case NVPTXISD::Suld1DArrayI64Trap:
  2936. Opc = NVPTX::SULD_1D_ARRAY_I64_TRAP_R;
  2937. break;
  2938. case NVPTXISD::Suld1DArrayV2I8Trap:
  2939. Opc = NVPTX::SULD_1D_ARRAY_V2I8_TRAP_R;
  2940. break;
  2941. case NVPTXISD::Suld1DArrayV2I16Trap:
  2942. Opc = NVPTX::SULD_1D_ARRAY_V2I16_TRAP_R;
  2943. break;
  2944. case NVPTXISD::Suld1DArrayV2I32Trap:
  2945. Opc = NVPTX::SULD_1D_ARRAY_V2I32_TRAP_R;
  2946. break;
  2947. case NVPTXISD::Suld1DArrayV2I64Trap:
  2948. Opc = NVPTX::SULD_1D_ARRAY_V2I64_TRAP_R;
  2949. break;
  2950. case NVPTXISD::Suld1DArrayV4I8Trap:
  2951. Opc = NVPTX::SULD_1D_ARRAY_V4I8_TRAP_R;
  2952. break;
  2953. case NVPTXISD::Suld1DArrayV4I16Trap:
  2954. Opc = NVPTX::SULD_1D_ARRAY_V4I16_TRAP_R;
  2955. break;
  2956. case NVPTXISD::Suld1DArrayV4I32Trap:
  2957. Opc = NVPTX::SULD_1D_ARRAY_V4I32_TRAP_R;
  2958. break;
  2959. case NVPTXISD::Suld2DI8Trap:
  2960. Opc = NVPTX::SULD_2D_I8_TRAP_R;
  2961. break;
  2962. case NVPTXISD::Suld2DI16Trap:
  2963. Opc = NVPTX::SULD_2D_I16_TRAP_R;
  2964. break;
  2965. case NVPTXISD::Suld2DI32Trap:
  2966. Opc = NVPTX::SULD_2D_I32_TRAP_R;
  2967. break;
  2968. case NVPTXISD::Suld2DI64Trap:
  2969. Opc = NVPTX::SULD_2D_I64_TRAP_R;
  2970. break;
  2971. case NVPTXISD::Suld2DV2I8Trap:
  2972. Opc = NVPTX::SULD_2D_V2I8_TRAP_R;
  2973. break;
  2974. case NVPTXISD::Suld2DV2I16Trap:
  2975. Opc = NVPTX::SULD_2D_V2I16_TRAP_R;
  2976. break;
  2977. case NVPTXISD::Suld2DV2I32Trap:
  2978. Opc = NVPTX::SULD_2D_V2I32_TRAP_R;
  2979. break;
  2980. case NVPTXISD::Suld2DV2I64Trap:
  2981. Opc = NVPTX::SULD_2D_V2I64_TRAP_R;
  2982. break;
  2983. case NVPTXISD::Suld2DV4I8Trap:
  2984. Opc = NVPTX::SULD_2D_V4I8_TRAP_R;
  2985. break;
  2986. case NVPTXISD::Suld2DV4I16Trap:
  2987. Opc = NVPTX::SULD_2D_V4I16_TRAP_R;
  2988. break;
  2989. case NVPTXISD::Suld2DV4I32Trap:
  2990. Opc = NVPTX::SULD_2D_V4I32_TRAP_R;
  2991. break;
  2992. case NVPTXISD::Suld2DArrayI8Trap:
  2993. Opc = NVPTX::SULD_2D_ARRAY_I8_TRAP_R;
  2994. break;
  2995. case NVPTXISD::Suld2DArrayI16Trap:
  2996. Opc = NVPTX::SULD_2D_ARRAY_I16_TRAP_R;
  2997. break;
  2998. case NVPTXISD::Suld2DArrayI32Trap:
  2999. Opc = NVPTX::SULD_2D_ARRAY_I32_TRAP_R;
  3000. break;
  3001. case NVPTXISD::Suld2DArrayI64Trap:
  3002. Opc = NVPTX::SULD_2D_ARRAY_I64_TRAP_R;
  3003. break;
  3004. case NVPTXISD::Suld2DArrayV2I8Trap:
  3005. Opc = NVPTX::SULD_2D_ARRAY_V2I8_TRAP_R;
  3006. break;
  3007. case NVPTXISD::Suld2DArrayV2I16Trap:
  3008. Opc = NVPTX::SULD_2D_ARRAY_V2I16_TRAP_R;
  3009. break;
  3010. case NVPTXISD::Suld2DArrayV2I32Trap:
  3011. Opc = NVPTX::SULD_2D_ARRAY_V2I32_TRAP_R;
  3012. break;
  3013. case NVPTXISD::Suld2DArrayV2I64Trap:
  3014. Opc = NVPTX::SULD_2D_ARRAY_V2I64_TRAP_R;
  3015. break;
  3016. case NVPTXISD::Suld2DArrayV4I8Trap:
  3017. Opc = NVPTX::SULD_2D_ARRAY_V4I8_TRAP_R;
  3018. break;
  3019. case NVPTXISD::Suld2DArrayV4I16Trap:
  3020. Opc = NVPTX::SULD_2D_ARRAY_V4I16_TRAP_R;
  3021. break;
  3022. case NVPTXISD::Suld2DArrayV4I32Trap:
  3023. Opc = NVPTX::SULD_2D_ARRAY_V4I32_TRAP_R;
  3024. break;
  3025. case NVPTXISD::Suld3DI8Trap:
  3026. Opc = NVPTX::SULD_3D_I8_TRAP_R;
  3027. break;
  3028. case NVPTXISD::Suld3DI16Trap:
  3029. Opc = NVPTX::SULD_3D_I16_TRAP_R;
  3030. break;
  3031. case NVPTXISD::Suld3DI32Trap:
  3032. Opc = NVPTX::SULD_3D_I32_TRAP_R;
  3033. break;
  3034. case NVPTXISD::Suld3DI64Trap:
  3035. Opc = NVPTX::SULD_3D_I64_TRAP_R;
  3036. break;
  3037. case NVPTXISD::Suld3DV2I8Trap:
  3038. Opc = NVPTX::SULD_3D_V2I8_TRAP_R;
  3039. break;
  3040. case NVPTXISD::Suld3DV2I16Trap:
  3041. Opc = NVPTX::SULD_3D_V2I16_TRAP_R;
  3042. break;
  3043. case NVPTXISD::Suld3DV2I32Trap:
  3044. Opc = NVPTX::SULD_3D_V2I32_TRAP_R;
  3045. break;
  3046. case NVPTXISD::Suld3DV2I64Trap:
  3047. Opc = NVPTX::SULD_3D_V2I64_TRAP_R;
  3048. break;
  3049. case NVPTXISD::Suld3DV4I8Trap:
  3050. Opc = NVPTX::SULD_3D_V4I8_TRAP_R;
  3051. break;
  3052. case NVPTXISD::Suld3DV4I16Trap:
  3053. Opc = NVPTX::SULD_3D_V4I16_TRAP_R;
  3054. break;
  3055. case NVPTXISD::Suld3DV4I32Trap:
  3056. Opc = NVPTX::SULD_3D_V4I32_TRAP_R;
  3057. break;
  3058. case NVPTXISD::Suld1DI8Zero:
  3059. Opc = NVPTX::SULD_1D_I8_ZERO_R;
  3060. break;
  3061. case NVPTXISD::Suld1DI16Zero:
  3062. Opc = NVPTX::SULD_1D_I16_ZERO_R;
  3063. break;
  3064. case NVPTXISD::Suld1DI32Zero:
  3065. Opc = NVPTX::SULD_1D_I32_ZERO_R;
  3066. break;
  3067. case NVPTXISD::Suld1DI64Zero:
  3068. Opc = NVPTX::SULD_1D_I64_ZERO_R;
  3069. break;
  3070. case NVPTXISD::Suld1DV2I8Zero:
  3071. Opc = NVPTX::SULD_1D_V2I8_ZERO_R;
  3072. break;
  3073. case NVPTXISD::Suld1DV2I16Zero:
  3074. Opc = NVPTX::SULD_1D_V2I16_ZERO_R;
  3075. break;
  3076. case NVPTXISD::Suld1DV2I32Zero:
  3077. Opc = NVPTX::SULD_1D_V2I32_ZERO_R;
  3078. break;
  3079. case NVPTXISD::Suld1DV2I64Zero:
  3080. Opc = NVPTX::SULD_1D_V2I64_ZERO_R;
  3081. break;
  3082. case NVPTXISD::Suld1DV4I8Zero:
  3083. Opc = NVPTX::SULD_1D_V4I8_ZERO_R;
  3084. break;
  3085. case NVPTXISD::Suld1DV4I16Zero:
  3086. Opc = NVPTX::SULD_1D_V4I16_ZERO_R;
  3087. break;
  3088. case NVPTXISD::Suld1DV4I32Zero:
  3089. Opc = NVPTX::SULD_1D_V4I32_ZERO_R;
  3090. break;
  3091. case NVPTXISD::Suld1DArrayI8Zero:
  3092. Opc = NVPTX::SULD_1D_ARRAY_I8_ZERO_R;
  3093. break;
  3094. case NVPTXISD::Suld1DArrayI16Zero:
  3095. Opc = NVPTX::SULD_1D_ARRAY_I16_ZERO_R;
  3096. break;
  3097. case NVPTXISD::Suld1DArrayI32Zero:
  3098. Opc = NVPTX::SULD_1D_ARRAY_I32_ZERO_R;
  3099. break;
  3100. case NVPTXISD::Suld1DArrayI64Zero:
  3101. Opc = NVPTX::SULD_1D_ARRAY_I64_ZERO_R;
  3102. break;
  3103. case NVPTXISD::Suld1DArrayV2I8Zero:
  3104. Opc = NVPTX::SULD_1D_ARRAY_V2I8_ZERO_R;
  3105. break;
  3106. case NVPTXISD::Suld1DArrayV2I16Zero:
  3107. Opc = NVPTX::SULD_1D_ARRAY_V2I16_ZERO_R;
  3108. break;
  3109. case NVPTXISD::Suld1DArrayV2I32Zero:
  3110. Opc = NVPTX::SULD_1D_ARRAY_V2I32_ZERO_R;
  3111. break;
  3112. case NVPTXISD::Suld1DArrayV2I64Zero:
  3113. Opc = NVPTX::SULD_1D_ARRAY_V2I64_ZERO_R;
  3114. break;
  3115. case NVPTXISD::Suld1DArrayV4I8Zero:
  3116. Opc = NVPTX::SULD_1D_ARRAY_V4I8_ZERO_R;
  3117. break;
  3118. case NVPTXISD::Suld1DArrayV4I16Zero:
  3119. Opc = NVPTX::SULD_1D_ARRAY_V4I16_ZERO_R;
  3120. break;
  3121. case NVPTXISD::Suld1DArrayV4I32Zero:
  3122. Opc = NVPTX::SULD_1D_ARRAY_V4I32_ZERO_R;
  3123. break;
  3124. case NVPTXISD::Suld2DI8Zero:
  3125. Opc = NVPTX::SULD_2D_I8_ZERO_R;
  3126. break;
  3127. case NVPTXISD::Suld2DI16Zero:
  3128. Opc = NVPTX::SULD_2D_I16_ZERO_R;
  3129. break;
  3130. case NVPTXISD::Suld2DI32Zero:
  3131. Opc = NVPTX::SULD_2D_I32_ZERO_R;
  3132. break;
  3133. case NVPTXISD::Suld2DI64Zero:
  3134. Opc = NVPTX::SULD_2D_I64_ZERO_R;
  3135. break;
  3136. case NVPTXISD::Suld2DV2I8Zero:
  3137. Opc = NVPTX::SULD_2D_V2I8_ZERO_R;
  3138. break;
  3139. case NVPTXISD::Suld2DV2I16Zero:
  3140. Opc = NVPTX::SULD_2D_V2I16_ZERO_R;
  3141. break;
  3142. case NVPTXISD::Suld2DV2I32Zero:
  3143. Opc = NVPTX::SULD_2D_V2I32_ZERO_R;
  3144. break;
  3145. case NVPTXISD::Suld2DV2I64Zero:
  3146. Opc = NVPTX::SULD_2D_V2I64_ZERO_R;
  3147. break;
  3148. case NVPTXISD::Suld2DV4I8Zero:
  3149. Opc = NVPTX::SULD_2D_V4I8_ZERO_R;
  3150. break;
  3151. case NVPTXISD::Suld2DV4I16Zero:
  3152. Opc = NVPTX::SULD_2D_V4I16_ZERO_R;
  3153. break;
  3154. case NVPTXISD::Suld2DV4I32Zero:
  3155. Opc = NVPTX::SULD_2D_V4I32_ZERO_R;
  3156. break;
  3157. case NVPTXISD::Suld2DArrayI8Zero:
  3158. Opc = NVPTX::SULD_2D_ARRAY_I8_ZERO_R;
  3159. break;
  3160. case NVPTXISD::Suld2DArrayI16Zero:
  3161. Opc = NVPTX::SULD_2D_ARRAY_I16_ZERO_R;
  3162. break;
  3163. case NVPTXISD::Suld2DArrayI32Zero:
  3164. Opc = NVPTX::SULD_2D_ARRAY_I32_ZERO_R;
  3165. break;
  3166. case NVPTXISD::Suld2DArrayI64Zero:
  3167. Opc = NVPTX::SULD_2D_ARRAY_I64_ZERO_R;
  3168. break;
  3169. case NVPTXISD::Suld2DArrayV2I8Zero:
  3170. Opc = NVPTX::SULD_2D_ARRAY_V2I8_ZERO_R;
  3171. break;
  3172. case NVPTXISD::Suld2DArrayV2I16Zero:
  3173. Opc = NVPTX::SULD_2D_ARRAY_V2I16_ZERO_R;
  3174. break;
  3175. case NVPTXISD::Suld2DArrayV2I32Zero:
  3176. Opc = NVPTX::SULD_2D_ARRAY_V2I32_ZERO_R;
  3177. break;
  3178. case NVPTXISD::Suld2DArrayV2I64Zero:
  3179. Opc = NVPTX::SULD_2D_ARRAY_V2I64_ZERO_R;
  3180. break;
  3181. case NVPTXISD::Suld2DArrayV4I8Zero:
  3182. Opc = NVPTX::SULD_2D_ARRAY_V4I8_ZERO_R;
  3183. break;
  3184. case NVPTXISD::Suld2DArrayV4I16Zero:
  3185. Opc = NVPTX::SULD_2D_ARRAY_V4I16_ZERO_R;
  3186. break;
  3187. case NVPTXISD::Suld2DArrayV4I32Zero:
  3188. Opc = NVPTX::SULD_2D_ARRAY_V4I32_ZERO_R;
  3189. break;
  3190. case NVPTXISD::Suld3DI8Zero:
  3191. Opc = NVPTX::SULD_3D_I8_ZERO_R;
  3192. break;
  3193. case NVPTXISD::Suld3DI16Zero:
  3194. Opc = NVPTX::SULD_3D_I16_ZERO_R;
  3195. break;
  3196. case NVPTXISD::Suld3DI32Zero:
  3197. Opc = NVPTX::SULD_3D_I32_ZERO_R;
  3198. break;
  3199. case NVPTXISD::Suld3DI64Zero:
  3200. Opc = NVPTX::SULD_3D_I64_ZERO_R;
  3201. break;
  3202. case NVPTXISD::Suld3DV2I8Zero:
  3203. Opc = NVPTX::SULD_3D_V2I8_ZERO_R;
  3204. break;
  3205. case NVPTXISD::Suld3DV2I16Zero:
  3206. Opc = NVPTX::SULD_3D_V2I16_ZERO_R;
  3207. break;
  3208. case NVPTXISD::Suld3DV2I32Zero:
  3209. Opc = NVPTX::SULD_3D_V2I32_ZERO_R;
  3210. break;
  3211. case NVPTXISD::Suld3DV2I64Zero:
  3212. Opc = NVPTX::SULD_3D_V2I64_ZERO_R;
  3213. break;
  3214. case NVPTXISD::Suld3DV4I8Zero:
  3215. Opc = NVPTX::SULD_3D_V4I8_ZERO_R;
  3216. break;
  3217. case NVPTXISD::Suld3DV4I16Zero:
  3218. Opc = NVPTX::SULD_3D_V4I16_ZERO_R;
  3219. break;
  3220. case NVPTXISD::Suld3DV4I32Zero:
  3221. Opc = NVPTX::SULD_3D_V4I32_ZERO_R;
  3222. break;
  3223. }
  3224. // Copy over operands
  3225. SmallVector<SDValue, 8> Ops(drop_begin(N->ops()));
  3226. Ops.push_back(N->getOperand(0)); // Move chain to the back.
  3227. ReplaceNode(N, CurDAG->getMachineNode(Opc, SDLoc(N), N->getVTList(), Ops));
  3228. return true;
  3229. }
  3230. /// SelectBFE - Look for instruction sequences that can be made more efficient
  3231. /// by using the 'bfe' (bit-field extract) PTX instruction
  3232. bool NVPTXDAGToDAGISel::tryBFE(SDNode *N) {
  3233. SDLoc DL(N);
  3234. SDValue LHS = N->getOperand(0);
  3235. SDValue RHS = N->getOperand(1);
  3236. SDValue Len;
  3237. SDValue Start;
  3238. SDValue Val;
  3239. bool IsSigned = false;
  3240. if (N->getOpcode() == ISD::AND) {
  3241. // Canonicalize the operands
  3242. // We want 'and %val, %mask'
  3243. if (isa<ConstantSDNode>(LHS) && !isa<ConstantSDNode>(RHS)) {
  3244. std::swap(LHS, RHS);
  3245. }
  3246. ConstantSDNode *Mask = dyn_cast<ConstantSDNode>(RHS);
  3247. if (!Mask) {
  3248. // We need a constant mask on the RHS of the AND
  3249. return false;
  3250. }
  3251. // Extract the mask bits
  3252. uint64_t MaskVal = Mask->getZExtValue();
  3253. if (!isMask_64(MaskVal)) {
  3254. // We *could* handle shifted masks here, but doing so would require an
  3255. // 'and' operation to fix up the low-order bits so we would trade
  3256. // shr+and for bfe+and, which has the same throughput
  3257. return false;
  3258. }
  3259. // How many bits are in our mask?
  3260. uint64_t NumBits = countTrailingOnes(MaskVal);
  3261. Len = CurDAG->getTargetConstant(NumBits, DL, MVT::i32);
  3262. if (LHS.getOpcode() == ISD::SRL || LHS.getOpcode() == ISD::SRA) {
  3263. // We have a 'srl/and' pair, extract the effective start bit and length
  3264. Val = LHS.getNode()->getOperand(0);
  3265. Start = LHS.getNode()->getOperand(1);
  3266. ConstantSDNode *StartConst = dyn_cast<ConstantSDNode>(Start);
  3267. if (StartConst) {
  3268. uint64_t StartVal = StartConst->getZExtValue();
  3269. // How many "good" bits do we have left? "good" is defined here as bits
  3270. // that exist in the original value, not shifted in.
  3271. uint64_t GoodBits = Start.getValueSizeInBits() - StartVal;
  3272. if (NumBits > GoodBits) {
  3273. // Do not handle the case where bits have been shifted in. In theory
  3274. // we could handle this, but the cost is likely higher than just
  3275. // emitting the srl/and pair.
  3276. return false;
  3277. }
  3278. Start = CurDAG->getTargetConstant(StartVal, DL, MVT::i32);
  3279. } else {
  3280. // Do not handle the case where the shift amount (can be zero if no srl
  3281. // was found) is not constant. We could handle this case, but it would
  3282. // require run-time logic that would be more expensive than just
  3283. // emitting the srl/and pair.
  3284. return false;
  3285. }
  3286. } else {
  3287. // Do not handle the case where the LHS of the and is not a shift. While
  3288. // it would be trivial to handle this case, it would just transform
  3289. // 'and' -> 'bfe', but 'and' has higher-throughput.
  3290. return false;
  3291. }
  3292. } else if (N->getOpcode() == ISD::SRL || N->getOpcode() == ISD::SRA) {
  3293. if (LHS->getOpcode() == ISD::AND) {
  3294. ConstantSDNode *ShiftCnst = dyn_cast<ConstantSDNode>(RHS);
  3295. if (!ShiftCnst) {
  3296. // Shift amount must be constant
  3297. return false;
  3298. }
  3299. uint64_t ShiftAmt = ShiftCnst->getZExtValue();
  3300. SDValue AndLHS = LHS->getOperand(0);
  3301. SDValue AndRHS = LHS->getOperand(1);
  3302. // Canonicalize the AND to have the mask on the RHS
  3303. if (isa<ConstantSDNode>(AndLHS)) {
  3304. std::swap(AndLHS, AndRHS);
  3305. }
  3306. ConstantSDNode *MaskCnst = dyn_cast<ConstantSDNode>(AndRHS);
  3307. if (!MaskCnst) {
  3308. // Mask must be constant
  3309. return false;
  3310. }
  3311. uint64_t MaskVal = MaskCnst->getZExtValue();
  3312. uint64_t NumZeros;
  3313. uint64_t NumBits;
  3314. if (isMask_64(MaskVal)) {
  3315. NumZeros = 0;
  3316. // The number of bits in the result bitfield will be the number of
  3317. // trailing ones (the AND) minus the number of bits we shift off
  3318. NumBits = countTrailingOnes(MaskVal) - ShiftAmt;
  3319. } else if (isShiftedMask_64(MaskVal)) {
  3320. NumZeros = countTrailingZeros(MaskVal);
  3321. unsigned NumOnes = countTrailingOnes(MaskVal >> NumZeros);
  3322. // The number of bits in the result bitfield will be the number of
  3323. // trailing zeros plus the number of set bits in the mask minus the
  3324. // number of bits we shift off
  3325. NumBits = NumZeros + NumOnes - ShiftAmt;
  3326. } else {
  3327. // This is not a mask we can handle
  3328. return false;
  3329. }
  3330. if (ShiftAmt < NumZeros) {
  3331. // Handling this case would require extra logic that would make this
  3332. // transformation non-profitable
  3333. return false;
  3334. }
  3335. Val = AndLHS;
  3336. Start = CurDAG->getTargetConstant(ShiftAmt, DL, MVT::i32);
  3337. Len = CurDAG->getTargetConstant(NumBits, DL, MVT::i32);
  3338. } else if (LHS->getOpcode() == ISD::SHL) {
  3339. // Here, we have a pattern like:
  3340. //
  3341. // (sra (shl val, NN), MM)
  3342. // or
  3343. // (srl (shl val, NN), MM)
  3344. //
  3345. // If MM >= NN, we can efficiently optimize this with bfe
  3346. Val = LHS->getOperand(0);
  3347. SDValue ShlRHS = LHS->getOperand(1);
  3348. ConstantSDNode *ShlCnst = dyn_cast<ConstantSDNode>(ShlRHS);
  3349. if (!ShlCnst) {
  3350. // Shift amount must be constant
  3351. return false;
  3352. }
  3353. uint64_t InnerShiftAmt = ShlCnst->getZExtValue();
  3354. SDValue ShrRHS = RHS;
  3355. ConstantSDNode *ShrCnst = dyn_cast<ConstantSDNode>(ShrRHS);
  3356. if (!ShrCnst) {
  3357. // Shift amount must be constant
  3358. return false;
  3359. }
  3360. uint64_t OuterShiftAmt = ShrCnst->getZExtValue();
  3361. // To avoid extra codegen and be profitable, we need Outer >= Inner
  3362. if (OuterShiftAmt < InnerShiftAmt) {
  3363. return false;
  3364. }
  3365. // If the outer shift is more than the type size, we have no bitfield to
  3366. // extract (since we also check that the inner shift is <= the outer shift
  3367. // then this also implies that the inner shift is < the type size)
  3368. if (OuterShiftAmt >= Val.getValueSizeInBits()) {
  3369. return false;
  3370. }
  3371. Start = CurDAG->getTargetConstant(OuterShiftAmt - InnerShiftAmt, DL,
  3372. MVT::i32);
  3373. Len = CurDAG->getTargetConstant(Val.getValueSizeInBits() - OuterShiftAmt,
  3374. DL, MVT::i32);
  3375. if (N->getOpcode() == ISD::SRA) {
  3376. // If we have a arithmetic right shift, we need to use the signed bfe
  3377. // variant
  3378. IsSigned = true;
  3379. }
  3380. } else {
  3381. // No can do...
  3382. return false;
  3383. }
  3384. } else {
  3385. // No can do...
  3386. return false;
  3387. }
  3388. unsigned Opc;
  3389. // For the BFE operations we form here from "and" and "srl", always use the
  3390. // unsigned variants.
  3391. if (Val.getValueType() == MVT::i32) {
  3392. if (IsSigned) {
  3393. Opc = NVPTX::BFE_S32rii;
  3394. } else {
  3395. Opc = NVPTX::BFE_U32rii;
  3396. }
  3397. } else if (Val.getValueType() == MVT::i64) {
  3398. if (IsSigned) {
  3399. Opc = NVPTX::BFE_S64rii;
  3400. } else {
  3401. Opc = NVPTX::BFE_U64rii;
  3402. }
  3403. } else {
  3404. // We cannot handle this type
  3405. return false;
  3406. }
  3407. SDValue Ops[] = {
  3408. Val, Start, Len
  3409. };
  3410. ReplaceNode(N, CurDAG->getMachineNode(Opc, DL, N->getVTList(), Ops));
  3411. return true;
  3412. }
  3413. // SelectDirectAddr - Match a direct address for DAG.
  3414. // A direct address could be a globaladdress or externalsymbol.
  3415. bool NVPTXDAGToDAGISel::SelectDirectAddr(SDValue N, SDValue &Address) {
  3416. // Return true if TGA or ES.
  3417. if (N.getOpcode() == ISD::TargetGlobalAddress ||
  3418. N.getOpcode() == ISD::TargetExternalSymbol) {
  3419. Address = N;
  3420. return true;
  3421. }
  3422. if (N.getOpcode() == NVPTXISD::Wrapper) {
  3423. Address = N.getOperand(0);
  3424. return true;
  3425. }
  3426. // addrspacecast(MoveParam(arg_symbol) to addrspace(PARAM)) -> arg_symbol
  3427. if (AddrSpaceCastSDNode *CastN = dyn_cast<AddrSpaceCastSDNode>(N)) {
  3428. if (CastN->getSrcAddressSpace() == ADDRESS_SPACE_GENERIC &&
  3429. CastN->getDestAddressSpace() == ADDRESS_SPACE_PARAM &&
  3430. CastN->getOperand(0).getOpcode() == NVPTXISD::MoveParam)
  3431. return SelectDirectAddr(CastN->getOperand(0).getOperand(0), Address);
  3432. }
  3433. return false;
  3434. }
  3435. // symbol+offset
  3436. bool NVPTXDAGToDAGISel::SelectADDRsi_imp(
  3437. SDNode *OpNode, SDValue Addr, SDValue &Base, SDValue &Offset, MVT mvt) {
  3438. if (Addr.getOpcode() == ISD::ADD) {
  3439. if (ConstantSDNode *CN = dyn_cast<ConstantSDNode>(Addr.getOperand(1))) {
  3440. SDValue base = Addr.getOperand(0);
  3441. if (SelectDirectAddr(base, Base)) {
  3442. Offset = CurDAG->getTargetConstant(CN->getZExtValue(), SDLoc(OpNode),
  3443. mvt);
  3444. return true;
  3445. }
  3446. }
  3447. }
  3448. return false;
  3449. }
  3450. // symbol+offset
  3451. bool NVPTXDAGToDAGISel::SelectADDRsi(SDNode *OpNode, SDValue Addr,
  3452. SDValue &Base, SDValue &Offset) {
  3453. return SelectADDRsi_imp(OpNode, Addr, Base, Offset, MVT::i32);
  3454. }
  3455. // symbol+offset
  3456. bool NVPTXDAGToDAGISel::SelectADDRsi64(SDNode *OpNode, SDValue Addr,
  3457. SDValue &Base, SDValue &Offset) {
  3458. return SelectADDRsi_imp(OpNode, Addr, Base, Offset, MVT::i64);
  3459. }
  3460. // register+offset
  3461. bool NVPTXDAGToDAGISel::SelectADDRri_imp(
  3462. SDNode *OpNode, SDValue Addr, SDValue &Base, SDValue &Offset, MVT mvt) {
  3463. if (FrameIndexSDNode *FIN = dyn_cast<FrameIndexSDNode>(Addr)) {
  3464. Base = CurDAG->getTargetFrameIndex(FIN->getIndex(), mvt);
  3465. Offset = CurDAG->getTargetConstant(0, SDLoc(OpNode), mvt);
  3466. return true;
  3467. }
  3468. if (Addr.getOpcode() == ISD::TargetExternalSymbol ||
  3469. Addr.getOpcode() == ISD::TargetGlobalAddress)
  3470. return false; // direct calls.
  3471. if (Addr.getOpcode() == ISD::ADD) {
  3472. if (SelectDirectAddr(Addr.getOperand(0), Addr)) {
  3473. return false;
  3474. }
  3475. if (ConstantSDNode *CN = dyn_cast<ConstantSDNode>(Addr.getOperand(1))) {
  3476. if (FrameIndexSDNode *FIN =
  3477. dyn_cast<FrameIndexSDNode>(Addr.getOperand(0)))
  3478. // Constant offset from frame ref.
  3479. Base = CurDAG->getTargetFrameIndex(FIN->getIndex(), mvt);
  3480. else
  3481. Base = Addr.getOperand(0);
  3482. Offset = CurDAG->getTargetConstant(CN->getZExtValue(), SDLoc(OpNode),
  3483. mvt);
  3484. return true;
  3485. }
  3486. }
  3487. return false;
  3488. }
  3489. // register+offset
  3490. bool NVPTXDAGToDAGISel::SelectADDRri(SDNode *OpNode, SDValue Addr,
  3491. SDValue &Base, SDValue &Offset) {
  3492. return SelectADDRri_imp(OpNode, Addr, Base, Offset, MVT::i32);
  3493. }
  3494. // register+offset
  3495. bool NVPTXDAGToDAGISel::SelectADDRri64(SDNode *OpNode, SDValue Addr,
  3496. SDValue &Base, SDValue &Offset) {
  3497. return SelectADDRri_imp(OpNode, Addr, Base, Offset, MVT::i64);
  3498. }
  3499. bool NVPTXDAGToDAGISel::ChkMemSDNodeAddressSpace(SDNode *N,
  3500. unsigned int spN) const {
  3501. const Value *Src = nullptr;
  3502. if (MemSDNode *mN = dyn_cast<MemSDNode>(N)) {
  3503. if (spN == 0 && mN->getMemOperand()->getPseudoValue())
  3504. return true;
  3505. Src = mN->getMemOperand()->getValue();
  3506. }
  3507. if (!Src)
  3508. return false;
  3509. if (auto *PT = dyn_cast<PointerType>(Src->getType()))
  3510. return (PT->getAddressSpace() == spN);
  3511. return false;
  3512. }
  3513. /// SelectInlineAsmMemoryOperand - Implement addressing mode selection for
  3514. /// inline asm expressions.
  3515. bool NVPTXDAGToDAGISel::SelectInlineAsmMemoryOperand(
  3516. const SDValue &Op, unsigned ConstraintID, std::vector<SDValue> &OutOps) {
  3517. SDValue Op0, Op1;
  3518. switch (ConstraintID) {
  3519. default:
  3520. return true;
  3521. case InlineAsm::Constraint_m: // memory
  3522. if (SelectDirectAddr(Op, Op0)) {
  3523. OutOps.push_back(Op0);
  3524. OutOps.push_back(CurDAG->getTargetConstant(0, SDLoc(Op), MVT::i32));
  3525. return false;
  3526. }
  3527. if (SelectADDRri(Op.getNode(), Op, Op0, Op1)) {
  3528. OutOps.push_back(Op0);
  3529. OutOps.push_back(Op1);
  3530. return false;
  3531. }
  3532. break;
  3533. }
  3534. return true;
  3535. }
  3536. /// GetConvertOpcode - Returns the CVT_ instruction opcode that implements a
  3537. /// conversion from \p SrcTy to \p DestTy.
  3538. unsigned NVPTXDAGToDAGISel::GetConvertOpcode(MVT DestTy, MVT SrcTy,
  3539. bool IsSigned) {
  3540. switch (SrcTy.SimpleTy) {
  3541. default:
  3542. llvm_unreachable("Unhandled source type");
  3543. case MVT::i8:
  3544. switch (DestTy.SimpleTy) {
  3545. default:
  3546. llvm_unreachable("Unhandled dest type");
  3547. case MVT::i16:
  3548. return IsSigned ? NVPTX::CVT_s16_s8 : NVPTX::CVT_u16_u8;
  3549. case MVT::i32:
  3550. return IsSigned ? NVPTX::CVT_s32_s8 : NVPTX::CVT_u32_u8;
  3551. case MVT::i64:
  3552. return IsSigned ? NVPTX::CVT_s64_s8 : NVPTX::CVT_u64_u8;
  3553. }
  3554. case MVT::i16:
  3555. switch (DestTy.SimpleTy) {
  3556. default:
  3557. llvm_unreachable("Unhandled dest type");
  3558. case MVT::i8:
  3559. return IsSigned ? NVPTX::CVT_s8_s16 : NVPTX::CVT_u8_u16;
  3560. case MVT::i32:
  3561. return IsSigned ? NVPTX::CVT_s32_s16 : NVPTX::CVT_u32_u16;
  3562. case MVT::i64:
  3563. return IsSigned ? NVPTX::CVT_s64_s16 : NVPTX::CVT_u64_u16;
  3564. }
  3565. case MVT::i32:
  3566. switch (DestTy.SimpleTy) {
  3567. default:
  3568. llvm_unreachable("Unhandled dest type");
  3569. case MVT::i8:
  3570. return IsSigned ? NVPTX::CVT_s8_s32 : NVPTX::CVT_u8_u32;
  3571. case MVT::i16:
  3572. return IsSigned ? NVPTX::CVT_s16_s32 : NVPTX::CVT_u16_u32;
  3573. case MVT::i64:
  3574. return IsSigned ? NVPTX::CVT_s64_s32 : NVPTX::CVT_u64_u32;
  3575. }
  3576. case MVT::i64:
  3577. switch (DestTy.SimpleTy) {
  3578. default:
  3579. llvm_unreachable("Unhandled dest type");
  3580. case MVT::i8:
  3581. return IsSigned ? NVPTX::CVT_s8_s64 : NVPTX::CVT_u8_u64;
  3582. case MVT::i16:
  3583. return IsSigned ? NVPTX::CVT_s16_s64 : NVPTX::CVT_u16_u64;
  3584. case MVT::i32:
  3585. return IsSigned ? NVPTX::CVT_s32_s64 : NVPTX::CVT_u32_u64;
  3586. }
  3587. }
  3588. }