123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712271327142715271627172718271927202721272227232724272527262727272827292730273127322733273427352736273727382739274027412742274327442745274627472748274927502751275227532754275527562757275827592760276127622763276427652766276727682769277027712772277327742775277627772778277927802781278227832784278527862787278827892790279127922793279427952796279727982799280028012802280328042805280628072808280928102811281228132814281528162817281828192820282128222823282428252826282728282829283028312832283328342835283628372838283928402841284228432844284528462847284828492850285128522853285428552856285728582859286028612862286328642865286628672868286928702871287228732874287528762877287828792880288128822883288428852886288728882889289028912892289328942895289628972898289929002901290229032904290529062907290829092910291129122913291429152916291729182919292029212922292329242925292629272928292929302931293229332934293529362937293829392940294129422943294429452946294729482949295029512952295329542955295629572958295929602961296229632964296529662967296829692970297129722973297429752976297729782979298029812982298329842985298629872988298929902991299229932994299529962997299829993000300130023003300430053006300730083009301030113012301330143015301630173018301930203021302230233024302530263027302830293030303130323033303430353036303730383039304030413042304330443045304630473048304930503051305230533054305530563057305830593060306130623063306430653066306730683069307030713072307330743075307630773078307930803081308230833084308530863087308830893090309130923093309430953096309730983099310031013102310331043105310631073108310931103111311231133114311531163117311831193120312131223123312431253126312731283129313031313132313331343135313631373138313931403141314231433144314531463147314831493150315131523153315431553156315731583159316031613162316331643165316631673168316931703171317231733174317531763177317831793180318131823183318431853186318731883189319031913192319331943195319631973198319932003201320232033204320532063207320832093210321132123213321432153216321732183219322032213222322332243225322632273228322932303231323232333234323532363237323832393240324132423243324432453246324732483249325032513252325332543255325632573258325932603261326232633264326532663267326832693270327132723273327432753276327732783279328032813282328332843285328632873288328932903291329232933294329532963297329832993300330133023303330433053306330733083309331033113312331333143315331633173318331933203321332233233324332533263327332833293330333133323333333433353336333733383339334033413342334333443345334633473348334933503351335233533354335533563357335833593360336133623363336433653366336733683369337033713372337333743375337633773378337933803381338233833384338533863387338833893390339133923393339433953396339733983399340034013402340334043405340634073408340934103411341234133414341534163417341834193420342134223423342434253426342734283429343034313432343334343435343634373438343934403441344234433444344534463447344834493450345134523453345434553456345734583459346034613462346334643465346634673468346934703471347234733474347534763477347834793480348134823483348434853486348734883489349034913492349334943495349634973498349935003501350235033504350535063507350835093510351135123513351435153516351735183519352035213522352335243525352635273528352935303531353235333534353535363537353835393540354135423543354435453546354735483549355035513552355335543555355635573558355935603561356235633564356535663567356835693570357135723573357435753576357735783579358035813582358335843585358635873588358935903591359235933594359535963597359835993600360136023603360436053606360736083609361036113612361336143615361636173618361936203621362236233624362536263627362836293630363136323633363436353636363736383639364036413642364336443645364636473648364936503651365236533654365536563657365836593660366136623663366436653666366736683669367036713672367336743675367636773678367936803681368236833684368536863687368836893690369136923693369436953696369736983699370037013702370337043705370637073708370937103711371237133714371537163717371837193720372137223723372437253726372737283729373037313732373337343735373637373738373937403741374237433744374537463747374837493750375137523753375437553756375737583759376037613762376337643765 |
- //===-- NVPTXISelDAGToDAG.cpp - A dag to dag inst selector for NVPTX ------===//
- //
- // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
- // See https://llvm.org/LICENSE.txt for license information.
- // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
- //
- //===----------------------------------------------------------------------===//
- //
- // This file defines an instruction selector for the NVPTX target.
- //
- //===----------------------------------------------------------------------===//
- #include "NVPTXISelDAGToDAG.h"
- #include "MCTargetDesc/NVPTXBaseInfo.h"
- #include "NVPTXUtilities.h"
- #include "llvm/Analysis/ValueTracking.h"
- #include "llvm/IR/GlobalValue.h"
- #include "llvm/IR/Instructions.h"
- #include "llvm/IR/IntrinsicsNVPTX.h"
- #include "llvm/Support/AtomicOrdering.h"
- #include "llvm/Support/CommandLine.h"
- #include "llvm/Support/Debug.h"
- #include "llvm/Support/ErrorHandling.h"
- #include "llvm/Support/raw_ostream.h"
- #include "llvm/Target/TargetIntrinsicInfo.h"
- using namespace llvm;
- #define DEBUG_TYPE "nvptx-isel"
- /// createNVPTXISelDag - This pass converts a legalized DAG into a
- /// NVPTX-specific DAG, ready for instruction scheduling.
- FunctionPass *llvm::createNVPTXISelDag(NVPTXTargetMachine &TM,
- llvm::CodeGenOpt::Level OptLevel) {
- return new NVPTXDAGToDAGISel(TM, OptLevel);
- }
- NVPTXDAGToDAGISel::NVPTXDAGToDAGISel(NVPTXTargetMachine &tm,
- CodeGenOpt::Level OptLevel)
- : SelectionDAGISel(tm, OptLevel), TM(tm) {
- doMulWide = (OptLevel > 0);
- }
- bool NVPTXDAGToDAGISel::runOnMachineFunction(MachineFunction &MF) {
- Subtarget = &static_cast<const NVPTXSubtarget &>(MF.getSubtarget());
- return SelectionDAGISel::runOnMachineFunction(MF);
- }
- int NVPTXDAGToDAGISel::getDivF32Level() const {
- return Subtarget->getTargetLowering()->getDivF32Level();
- }
- bool NVPTXDAGToDAGISel::usePrecSqrtF32() const {
- return Subtarget->getTargetLowering()->usePrecSqrtF32();
- }
- bool NVPTXDAGToDAGISel::useF32FTZ() const {
- return Subtarget->getTargetLowering()->useF32FTZ(*MF);
- }
- bool NVPTXDAGToDAGISel::allowFMA() const {
- const NVPTXTargetLowering *TL = Subtarget->getTargetLowering();
- return TL->allowFMA(*MF, OptLevel);
- }
- bool NVPTXDAGToDAGISel::allowUnsafeFPMath() const {
- const NVPTXTargetLowering *TL = Subtarget->getTargetLowering();
- return TL->allowUnsafeFPMath(*MF);
- }
- bool NVPTXDAGToDAGISel::useShortPointers() const {
- return TM.useShortPointers();
- }
- /// Select - Select instructions not customized! Used for
- /// expanded, promoted and normal instructions.
- void NVPTXDAGToDAGISel::Select(SDNode *N) {
- if (N->isMachineOpcode()) {
- N->setNodeId(-1);
- return; // Already selected.
- }
- switch (N->getOpcode()) {
- case ISD::LOAD:
- case ISD::ATOMIC_LOAD:
- if (tryLoad(N))
- return;
- break;
- case ISD::STORE:
- case ISD::ATOMIC_STORE:
- if (tryStore(N))
- return;
- break;
- case ISD::EXTRACT_VECTOR_ELT:
- if (tryEXTRACT_VECTOR_ELEMENT(N))
- return;
- break;
- case NVPTXISD::SETP_F16X2:
- SelectSETP_F16X2(N);
- return;
- case NVPTXISD::LoadV2:
- case NVPTXISD::LoadV4:
- if (tryLoadVector(N))
- return;
- break;
- case NVPTXISD::LDGV2:
- case NVPTXISD::LDGV4:
- case NVPTXISD::LDUV2:
- case NVPTXISD::LDUV4:
- if (tryLDGLDU(N))
- return;
- break;
- case NVPTXISD::StoreV2:
- case NVPTXISD::StoreV4:
- if (tryStoreVector(N))
- return;
- break;
- case NVPTXISD::LoadParam:
- case NVPTXISD::LoadParamV2:
- case NVPTXISD::LoadParamV4:
- if (tryLoadParam(N))
- return;
- break;
- case NVPTXISD::StoreRetval:
- case NVPTXISD::StoreRetvalV2:
- case NVPTXISD::StoreRetvalV4:
- if (tryStoreRetval(N))
- return;
- break;
- case NVPTXISD::StoreParam:
- case NVPTXISD::StoreParamV2:
- case NVPTXISD::StoreParamV4:
- case NVPTXISD::StoreParamS32:
- case NVPTXISD::StoreParamU32:
- if (tryStoreParam(N))
- return;
- break;
- case ISD::INTRINSIC_WO_CHAIN:
- if (tryIntrinsicNoChain(N))
- return;
- break;
- case ISD::INTRINSIC_W_CHAIN:
- if (tryIntrinsicChain(N))
- return;
- break;
- case NVPTXISD::Tex1DFloatS32:
- case NVPTXISD::Tex1DFloatFloat:
- case NVPTXISD::Tex1DFloatFloatLevel:
- case NVPTXISD::Tex1DFloatFloatGrad:
- case NVPTXISD::Tex1DS32S32:
- case NVPTXISD::Tex1DS32Float:
- case NVPTXISD::Tex1DS32FloatLevel:
- case NVPTXISD::Tex1DS32FloatGrad:
- case NVPTXISD::Tex1DU32S32:
- case NVPTXISD::Tex1DU32Float:
- case NVPTXISD::Tex1DU32FloatLevel:
- case NVPTXISD::Tex1DU32FloatGrad:
- case NVPTXISD::Tex1DArrayFloatS32:
- case NVPTXISD::Tex1DArrayFloatFloat:
- case NVPTXISD::Tex1DArrayFloatFloatLevel:
- case NVPTXISD::Tex1DArrayFloatFloatGrad:
- case NVPTXISD::Tex1DArrayS32S32:
- case NVPTXISD::Tex1DArrayS32Float:
- case NVPTXISD::Tex1DArrayS32FloatLevel:
- case NVPTXISD::Tex1DArrayS32FloatGrad:
- case NVPTXISD::Tex1DArrayU32S32:
- case NVPTXISD::Tex1DArrayU32Float:
- case NVPTXISD::Tex1DArrayU32FloatLevel:
- case NVPTXISD::Tex1DArrayU32FloatGrad:
- case NVPTXISD::Tex2DFloatS32:
- case NVPTXISD::Tex2DFloatFloat:
- case NVPTXISD::Tex2DFloatFloatLevel:
- case NVPTXISD::Tex2DFloatFloatGrad:
- case NVPTXISD::Tex2DS32S32:
- case NVPTXISD::Tex2DS32Float:
- case NVPTXISD::Tex2DS32FloatLevel:
- case NVPTXISD::Tex2DS32FloatGrad:
- case NVPTXISD::Tex2DU32S32:
- case NVPTXISD::Tex2DU32Float:
- case NVPTXISD::Tex2DU32FloatLevel:
- case NVPTXISD::Tex2DU32FloatGrad:
- case NVPTXISD::Tex2DArrayFloatS32:
- case NVPTXISD::Tex2DArrayFloatFloat:
- case NVPTXISD::Tex2DArrayFloatFloatLevel:
- case NVPTXISD::Tex2DArrayFloatFloatGrad:
- case NVPTXISD::Tex2DArrayS32S32:
- case NVPTXISD::Tex2DArrayS32Float:
- case NVPTXISD::Tex2DArrayS32FloatLevel:
- case NVPTXISD::Tex2DArrayS32FloatGrad:
- case NVPTXISD::Tex2DArrayU32S32:
- case NVPTXISD::Tex2DArrayU32Float:
- case NVPTXISD::Tex2DArrayU32FloatLevel:
- case NVPTXISD::Tex2DArrayU32FloatGrad:
- case NVPTXISD::Tex3DFloatS32:
- case NVPTXISD::Tex3DFloatFloat:
- case NVPTXISD::Tex3DFloatFloatLevel:
- case NVPTXISD::Tex3DFloatFloatGrad:
- case NVPTXISD::Tex3DS32S32:
- case NVPTXISD::Tex3DS32Float:
- case NVPTXISD::Tex3DS32FloatLevel:
- case NVPTXISD::Tex3DS32FloatGrad:
- case NVPTXISD::Tex3DU32S32:
- case NVPTXISD::Tex3DU32Float:
- case NVPTXISD::Tex3DU32FloatLevel:
- case NVPTXISD::Tex3DU32FloatGrad:
- case NVPTXISD::TexCubeFloatFloat:
- case NVPTXISD::TexCubeFloatFloatLevel:
- case NVPTXISD::TexCubeS32Float:
- case NVPTXISD::TexCubeS32FloatLevel:
- case NVPTXISD::TexCubeU32Float:
- case NVPTXISD::TexCubeU32FloatLevel:
- case NVPTXISD::TexCubeArrayFloatFloat:
- case NVPTXISD::TexCubeArrayFloatFloatLevel:
- case NVPTXISD::TexCubeArrayS32Float:
- case NVPTXISD::TexCubeArrayS32FloatLevel:
- case NVPTXISD::TexCubeArrayU32Float:
- case NVPTXISD::TexCubeArrayU32FloatLevel:
- case NVPTXISD::Tld4R2DFloatFloat:
- case NVPTXISD::Tld4G2DFloatFloat:
- case NVPTXISD::Tld4B2DFloatFloat:
- case NVPTXISD::Tld4A2DFloatFloat:
- case NVPTXISD::Tld4R2DS64Float:
- case NVPTXISD::Tld4G2DS64Float:
- case NVPTXISD::Tld4B2DS64Float:
- case NVPTXISD::Tld4A2DS64Float:
- case NVPTXISD::Tld4R2DU64Float:
- case NVPTXISD::Tld4G2DU64Float:
- case NVPTXISD::Tld4B2DU64Float:
- case NVPTXISD::Tld4A2DU64Float:
- case NVPTXISD::TexUnified1DFloatS32:
- case NVPTXISD::TexUnified1DFloatFloat:
- case NVPTXISD::TexUnified1DFloatFloatLevel:
- case NVPTXISD::TexUnified1DFloatFloatGrad:
- case NVPTXISD::TexUnified1DS32S32:
- case NVPTXISD::TexUnified1DS32Float:
- case NVPTXISD::TexUnified1DS32FloatLevel:
- case NVPTXISD::TexUnified1DS32FloatGrad:
- case NVPTXISD::TexUnified1DU32S32:
- case NVPTXISD::TexUnified1DU32Float:
- case NVPTXISD::TexUnified1DU32FloatLevel:
- case NVPTXISD::TexUnified1DU32FloatGrad:
- case NVPTXISD::TexUnified1DArrayFloatS32:
- case NVPTXISD::TexUnified1DArrayFloatFloat:
- case NVPTXISD::TexUnified1DArrayFloatFloatLevel:
- case NVPTXISD::TexUnified1DArrayFloatFloatGrad:
- case NVPTXISD::TexUnified1DArrayS32S32:
- case NVPTXISD::TexUnified1DArrayS32Float:
- case NVPTXISD::TexUnified1DArrayS32FloatLevel:
- case NVPTXISD::TexUnified1DArrayS32FloatGrad:
- case NVPTXISD::TexUnified1DArrayU32S32:
- case NVPTXISD::TexUnified1DArrayU32Float:
- case NVPTXISD::TexUnified1DArrayU32FloatLevel:
- case NVPTXISD::TexUnified1DArrayU32FloatGrad:
- case NVPTXISD::TexUnified2DFloatS32:
- case NVPTXISD::TexUnified2DFloatFloat:
- case NVPTXISD::TexUnified2DFloatFloatLevel:
- case NVPTXISD::TexUnified2DFloatFloatGrad:
- case NVPTXISD::TexUnified2DS32S32:
- case NVPTXISD::TexUnified2DS32Float:
- case NVPTXISD::TexUnified2DS32FloatLevel:
- case NVPTXISD::TexUnified2DS32FloatGrad:
- case NVPTXISD::TexUnified2DU32S32:
- case NVPTXISD::TexUnified2DU32Float:
- case NVPTXISD::TexUnified2DU32FloatLevel:
- case NVPTXISD::TexUnified2DU32FloatGrad:
- case NVPTXISD::TexUnified2DArrayFloatS32:
- case NVPTXISD::TexUnified2DArrayFloatFloat:
- case NVPTXISD::TexUnified2DArrayFloatFloatLevel:
- case NVPTXISD::TexUnified2DArrayFloatFloatGrad:
- case NVPTXISD::TexUnified2DArrayS32S32:
- case NVPTXISD::TexUnified2DArrayS32Float:
- case NVPTXISD::TexUnified2DArrayS32FloatLevel:
- case NVPTXISD::TexUnified2DArrayS32FloatGrad:
- case NVPTXISD::TexUnified2DArrayU32S32:
- case NVPTXISD::TexUnified2DArrayU32Float:
- case NVPTXISD::TexUnified2DArrayU32FloatLevel:
- case NVPTXISD::TexUnified2DArrayU32FloatGrad:
- case NVPTXISD::TexUnified3DFloatS32:
- case NVPTXISD::TexUnified3DFloatFloat:
- case NVPTXISD::TexUnified3DFloatFloatLevel:
- case NVPTXISD::TexUnified3DFloatFloatGrad:
- case NVPTXISD::TexUnified3DS32S32:
- case NVPTXISD::TexUnified3DS32Float:
- case NVPTXISD::TexUnified3DS32FloatLevel:
- case NVPTXISD::TexUnified3DS32FloatGrad:
- case NVPTXISD::TexUnified3DU32S32:
- case NVPTXISD::TexUnified3DU32Float:
- case NVPTXISD::TexUnified3DU32FloatLevel:
- case NVPTXISD::TexUnified3DU32FloatGrad:
- case NVPTXISD::TexUnifiedCubeFloatFloat:
- case NVPTXISD::TexUnifiedCubeFloatFloatLevel:
- case NVPTXISD::TexUnifiedCubeS32Float:
- case NVPTXISD::TexUnifiedCubeS32FloatLevel:
- case NVPTXISD::TexUnifiedCubeU32Float:
- case NVPTXISD::TexUnifiedCubeU32FloatLevel:
- case NVPTXISD::TexUnifiedCubeArrayFloatFloat:
- case NVPTXISD::TexUnifiedCubeArrayFloatFloatLevel:
- case NVPTXISD::TexUnifiedCubeArrayS32Float:
- case NVPTXISD::TexUnifiedCubeArrayS32FloatLevel:
- case NVPTXISD::TexUnifiedCubeArrayU32Float:
- case NVPTXISD::TexUnifiedCubeArrayU32FloatLevel:
- case NVPTXISD::Tld4UnifiedR2DFloatFloat:
- case NVPTXISD::Tld4UnifiedG2DFloatFloat:
- case NVPTXISD::Tld4UnifiedB2DFloatFloat:
- case NVPTXISD::Tld4UnifiedA2DFloatFloat:
- case NVPTXISD::Tld4UnifiedR2DS64Float:
- case NVPTXISD::Tld4UnifiedG2DS64Float:
- case NVPTXISD::Tld4UnifiedB2DS64Float:
- case NVPTXISD::Tld4UnifiedA2DS64Float:
- case NVPTXISD::Tld4UnifiedR2DU64Float:
- case NVPTXISD::Tld4UnifiedG2DU64Float:
- case NVPTXISD::Tld4UnifiedB2DU64Float:
- case NVPTXISD::Tld4UnifiedA2DU64Float:
- if (tryTextureIntrinsic(N))
- return;
- break;
- case NVPTXISD::Suld1DI8Clamp:
- case NVPTXISD::Suld1DI16Clamp:
- case NVPTXISD::Suld1DI32Clamp:
- case NVPTXISD::Suld1DI64Clamp:
- case NVPTXISD::Suld1DV2I8Clamp:
- case NVPTXISD::Suld1DV2I16Clamp:
- case NVPTXISD::Suld1DV2I32Clamp:
- case NVPTXISD::Suld1DV2I64Clamp:
- case NVPTXISD::Suld1DV4I8Clamp:
- case NVPTXISD::Suld1DV4I16Clamp:
- case NVPTXISD::Suld1DV4I32Clamp:
- case NVPTXISD::Suld1DArrayI8Clamp:
- case NVPTXISD::Suld1DArrayI16Clamp:
- case NVPTXISD::Suld1DArrayI32Clamp:
- case NVPTXISD::Suld1DArrayI64Clamp:
- case NVPTXISD::Suld1DArrayV2I8Clamp:
- case NVPTXISD::Suld1DArrayV2I16Clamp:
- case NVPTXISD::Suld1DArrayV2I32Clamp:
- case NVPTXISD::Suld1DArrayV2I64Clamp:
- case NVPTXISD::Suld1DArrayV4I8Clamp:
- case NVPTXISD::Suld1DArrayV4I16Clamp:
- case NVPTXISD::Suld1DArrayV4I32Clamp:
- case NVPTXISD::Suld2DI8Clamp:
- case NVPTXISD::Suld2DI16Clamp:
- case NVPTXISD::Suld2DI32Clamp:
- case NVPTXISD::Suld2DI64Clamp:
- case NVPTXISD::Suld2DV2I8Clamp:
- case NVPTXISD::Suld2DV2I16Clamp:
- case NVPTXISD::Suld2DV2I32Clamp:
- case NVPTXISD::Suld2DV2I64Clamp:
- case NVPTXISD::Suld2DV4I8Clamp:
- case NVPTXISD::Suld2DV4I16Clamp:
- case NVPTXISD::Suld2DV4I32Clamp:
- case NVPTXISD::Suld2DArrayI8Clamp:
- case NVPTXISD::Suld2DArrayI16Clamp:
- case NVPTXISD::Suld2DArrayI32Clamp:
- case NVPTXISD::Suld2DArrayI64Clamp:
- case NVPTXISD::Suld2DArrayV2I8Clamp:
- case NVPTXISD::Suld2DArrayV2I16Clamp:
- case NVPTXISD::Suld2DArrayV2I32Clamp:
- case NVPTXISD::Suld2DArrayV2I64Clamp:
- case NVPTXISD::Suld2DArrayV4I8Clamp:
- case NVPTXISD::Suld2DArrayV4I16Clamp:
- case NVPTXISD::Suld2DArrayV4I32Clamp:
- case NVPTXISD::Suld3DI8Clamp:
- case NVPTXISD::Suld3DI16Clamp:
- case NVPTXISD::Suld3DI32Clamp:
- case NVPTXISD::Suld3DI64Clamp:
- case NVPTXISD::Suld3DV2I8Clamp:
- case NVPTXISD::Suld3DV2I16Clamp:
- case NVPTXISD::Suld3DV2I32Clamp:
- case NVPTXISD::Suld3DV2I64Clamp:
- case NVPTXISD::Suld3DV4I8Clamp:
- case NVPTXISD::Suld3DV4I16Clamp:
- case NVPTXISD::Suld3DV4I32Clamp:
- case NVPTXISD::Suld1DI8Trap:
- case NVPTXISD::Suld1DI16Trap:
- case NVPTXISD::Suld1DI32Trap:
- case NVPTXISD::Suld1DI64Trap:
- case NVPTXISD::Suld1DV2I8Trap:
- case NVPTXISD::Suld1DV2I16Trap:
- case NVPTXISD::Suld1DV2I32Trap:
- case NVPTXISD::Suld1DV2I64Trap:
- case NVPTXISD::Suld1DV4I8Trap:
- case NVPTXISD::Suld1DV4I16Trap:
- case NVPTXISD::Suld1DV4I32Trap:
- case NVPTXISD::Suld1DArrayI8Trap:
- case NVPTXISD::Suld1DArrayI16Trap:
- case NVPTXISD::Suld1DArrayI32Trap:
- case NVPTXISD::Suld1DArrayI64Trap:
- case NVPTXISD::Suld1DArrayV2I8Trap:
- case NVPTXISD::Suld1DArrayV2I16Trap:
- case NVPTXISD::Suld1DArrayV2I32Trap:
- case NVPTXISD::Suld1DArrayV2I64Trap:
- case NVPTXISD::Suld1DArrayV4I8Trap:
- case NVPTXISD::Suld1DArrayV4I16Trap:
- case NVPTXISD::Suld1DArrayV4I32Trap:
- case NVPTXISD::Suld2DI8Trap:
- case NVPTXISD::Suld2DI16Trap:
- case NVPTXISD::Suld2DI32Trap:
- case NVPTXISD::Suld2DI64Trap:
- case NVPTXISD::Suld2DV2I8Trap:
- case NVPTXISD::Suld2DV2I16Trap:
- case NVPTXISD::Suld2DV2I32Trap:
- case NVPTXISD::Suld2DV2I64Trap:
- case NVPTXISD::Suld2DV4I8Trap:
- case NVPTXISD::Suld2DV4I16Trap:
- case NVPTXISD::Suld2DV4I32Trap:
- case NVPTXISD::Suld2DArrayI8Trap:
- case NVPTXISD::Suld2DArrayI16Trap:
- case NVPTXISD::Suld2DArrayI32Trap:
- case NVPTXISD::Suld2DArrayI64Trap:
- case NVPTXISD::Suld2DArrayV2I8Trap:
- case NVPTXISD::Suld2DArrayV2I16Trap:
- case NVPTXISD::Suld2DArrayV2I32Trap:
- case NVPTXISD::Suld2DArrayV2I64Trap:
- case NVPTXISD::Suld2DArrayV4I8Trap:
- case NVPTXISD::Suld2DArrayV4I16Trap:
- case NVPTXISD::Suld2DArrayV4I32Trap:
- case NVPTXISD::Suld3DI8Trap:
- case NVPTXISD::Suld3DI16Trap:
- case NVPTXISD::Suld3DI32Trap:
- case NVPTXISD::Suld3DI64Trap:
- case NVPTXISD::Suld3DV2I8Trap:
- case NVPTXISD::Suld3DV2I16Trap:
- case NVPTXISD::Suld3DV2I32Trap:
- case NVPTXISD::Suld3DV2I64Trap:
- case NVPTXISD::Suld3DV4I8Trap:
- case NVPTXISD::Suld3DV4I16Trap:
- case NVPTXISD::Suld3DV4I32Trap:
- case NVPTXISD::Suld1DI8Zero:
- case NVPTXISD::Suld1DI16Zero:
- case NVPTXISD::Suld1DI32Zero:
- case NVPTXISD::Suld1DI64Zero:
- case NVPTXISD::Suld1DV2I8Zero:
- case NVPTXISD::Suld1DV2I16Zero:
- case NVPTXISD::Suld1DV2I32Zero:
- case NVPTXISD::Suld1DV2I64Zero:
- case NVPTXISD::Suld1DV4I8Zero:
- case NVPTXISD::Suld1DV4I16Zero:
- case NVPTXISD::Suld1DV4I32Zero:
- case NVPTXISD::Suld1DArrayI8Zero:
- case NVPTXISD::Suld1DArrayI16Zero:
- case NVPTXISD::Suld1DArrayI32Zero:
- case NVPTXISD::Suld1DArrayI64Zero:
- case NVPTXISD::Suld1DArrayV2I8Zero:
- case NVPTXISD::Suld1DArrayV2I16Zero:
- case NVPTXISD::Suld1DArrayV2I32Zero:
- case NVPTXISD::Suld1DArrayV2I64Zero:
- case NVPTXISD::Suld1DArrayV4I8Zero:
- case NVPTXISD::Suld1DArrayV4I16Zero:
- case NVPTXISD::Suld1DArrayV4I32Zero:
- case NVPTXISD::Suld2DI8Zero:
- case NVPTXISD::Suld2DI16Zero:
- case NVPTXISD::Suld2DI32Zero:
- case NVPTXISD::Suld2DI64Zero:
- case NVPTXISD::Suld2DV2I8Zero:
- case NVPTXISD::Suld2DV2I16Zero:
- case NVPTXISD::Suld2DV2I32Zero:
- case NVPTXISD::Suld2DV2I64Zero:
- case NVPTXISD::Suld2DV4I8Zero:
- case NVPTXISD::Suld2DV4I16Zero:
- case NVPTXISD::Suld2DV4I32Zero:
- case NVPTXISD::Suld2DArrayI8Zero:
- case NVPTXISD::Suld2DArrayI16Zero:
- case NVPTXISD::Suld2DArrayI32Zero:
- case NVPTXISD::Suld2DArrayI64Zero:
- case NVPTXISD::Suld2DArrayV2I8Zero:
- case NVPTXISD::Suld2DArrayV2I16Zero:
- case NVPTXISD::Suld2DArrayV2I32Zero:
- case NVPTXISD::Suld2DArrayV2I64Zero:
- case NVPTXISD::Suld2DArrayV4I8Zero:
- case NVPTXISD::Suld2DArrayV4I16Zero:
- case NVPTXISD::Suld2DArrayV4I32Zero:
- case NVPTXISD::Suld3DI8Zero:
- case NVPTXISD::Suld3DI16Zero:
- case NVPTXISD::Suld3DI32Zero:
- case NVPTXISD::Suld3DI64Zero:
- case NVPTXISD::Suld3DV2I8Zero:
- case NVPTXISD::Suld3DV2I16Zero:
- case NVPTXISD::Suld3DV2I32Zero:
- case NVPTXISD::Suld3DV2I64Zero:
- case NVPTXISD::Suld3DV4I8Zero:
- case NVPTXISD::Suld3DV4I16Zero:
- case NVPTXISD::Suld3DV4I32Zero:
- if (trySurfaceIntrinsic(N))
- return;
- break;
- case ISD::AND:
- case ISD::SRA:
- case ISD::SRL:
- // Try to select BFE
- if (tryBFE(N))
- return;
- break;
- case ISD::ADDRSPACECAST:
- SelectAddrSpaceCast(N);
- return;
- case ISD::ConstantFP:
- if (tryConstantFP16(N))
- return;
- break;
- default:
- break;
- }
- SelectCode(N);
- }
- bool NVPTXDAGToDAGISel::tryIntrinsicChain(SDNode *N) {
- unsigned IID = cast<ConstantSDNode>(N->getOperand(1))->getZExtValue();
- switch (IID) {
- default:
- return false;
- case Intrinsic::nvvm_ldg_global_f:
- case Intrinsic::nvvm_ldg_global_i:
- case Intrinsic::nvvm_ldg_global_p:
- case Intrinsic::nvvm_ldu_global_f:
- case Intrinsic::nvvm_ldu_global_i:
- case Intrinsic::nvvm_ldu_global_p:
- return tryLDGLDU(N);
- }
- }
- // There's no way to specify FP16 immediates in .f16 ops, so we have to
- // load them into an .f16 register first.
- bool NVPTXDAGToDAGISel::tryConstantFP16(SDNode *N) {
- if (N->getValueType(0) != MVT::f16)
- return false;
- SDValue Val = CurDAG->getTargetConstantFP(
- cast<ConstantFPSDNode>(N)->getValueAPF(), SDLoc(N), MVT::f16);
- SDNode *LoadConstF16 =
- CurDAG->getMachineNode(NVPTX::LOAD_CONST_F16, SDLoc(N), MVT::f16, Val);
- ReplaceNode(N, LoadConstF16);
- return true;
- }
- // Map ISD:CONDCODE value to appropriate CmpMode expected by
- // NVPTXInstPrinter::printCmpMode()
- static unsigned getPTXCmpMode(const CondCodeSDNode &CondCode, bool FTZ) {
- using NVPTX::PTXCmpMode::CmpMode;
- unsigned PTXCmpMode = [](ISD::CondCode CC) {
- switch (CC) {
- default:
- llvm_unreachable("Unexpected condition code.");
- case ISD::SETOEQ:
- return CmpMode::EQ;
- case ISD::SETOGT:
- return CmpMode::GT;
- case ISD::SETOGE:
- return CmpMode::GE;
- case ISD::SETOLT:
- return CmpMode::LT;
- case ISD::SETOLE:
- return CmpMode::LE;
- case ISD::SETONE:
- return CmpMode::NE;
- case ISD::SETO:
- return CmpMode::NUM;
- case ISD::SETUO:
- return CmpMode::NotANumber;
- case ISD::SETUEQ:
- return CmpMode::EQU;
- case ISD::SETUGT:
- return CmpMode::GTU;
- case ISD::SETUGE:
- return CmpMode::GEU;
- case ISD::SETULT:
- return CmpMode::LTU;
- case ISD::SETULE:
- return CmpMode::LEU;
- case ISD::SETUNE:
- return CmpMode::NEU;
- case ISD::SETEQ:
- return CmpMode::EQ;
- case ISD::SETGT:
- return CmpMode::GT;
- case ISD::SETGE:
- return CmpMode::GE;
- case ISD::SETLT:
- return CmpMode::LT;
- case ISD::SETLE:
- return CmpMode::LE;
- case ISD::SETNE:
- return CmpMode::NE;
- }
- }(CondCode.get());
- if (FTZ)
- PTXCmpMode |= NVPTX::PTXCmpMode::FTZ_FLAG;
- return PTXCmpMode;
- }
- bool NVPTXDAGToDAGISel::SelectSETP_F16X2(SDNode *N) {
- unsigned PTXCmpMode =
- getPTXCmpMode(*cast<CondCodeSDNode>(N->getOperand(2)), useF32FTZ());
- SDLoc DL(N);
- SDNode *SetP = CurDAG->getMachineNode(
- NVPTX::SETP_f16x2rr, DL, MVT::i1, MVT::i1, N->getOperand(0),
- N->getOperand(1), CurDAG->getTargetConstant(PTXCmpMode, DL, MVT::i32));
- ReplaceNode(N, SetP);
- return true;
- }
- // Find all instances of extract_vector_elt that use this v2f16 vector
- // and coalesce them into a scattering move instruction.
- bool NVPTXDAGToDAGISel::tryEXTRACT_VECTOR_ELEMENT(SDNode *N) {
- SDValue Vector = N->getOperand(0);
- // We only care about f16x2 as it's the only real vector type we
- // need to deal with.
- if (Vector.getSimpleValueType() != MVT::v2f16)
- return false;
- // Find and record all uses of this vector that extract element 0 or 1.
- SmallVector<SDNode *, 4> E0, E1;
- for (auto U : Vector.getNode()->uses()) {
- if (U->getOpcode() != ISD::EXTRACT_VECTOR_ELT)
- continue;
- if (U->getOperand(0) != Vector)
- continue;
- if (const ConstantSDNode *IdxConst =
- dyn_cast<ConstantSDNode>(U->getOperand(1))) {
- if (IdxConst->getZExtValue() == 0)
- E0.push_back(U);
- else if (IdxConst->getZExtValue() == 1)
- E1.push_back(U);
- else
- llvm_unreachable("Invalid vector index.");
- }
- }
- // There's no point scattering f16x2 if we only ever access one
- // element of it.
- if (E0.empty() || E1.empty())
- return false;
- unsigned Op = NVPTX::SplitF16x2;
- // If the vector has been BITCAST'ed from i32, we can use original
- // value directly and avoid register-to-register move.
- SDValue Source = Vector;
- if (Vector->getOpcode() == ISD::BITCAST) {
- Op = NVPTX::SplitI32toF16x2;
- Source = Vector->getOperand(0);
- }
- // Merge (f16 extractelt(V, 0), f16 extractelt(V,1))
- // into f16,f16 SplitF16x2(V)
- SDNode *ScatterOp =
- CurDAG->getMachineNode(Op, SDLoc(N), MVT::f16, MVT::f16, Source);
- for (auto *Node : E0)
- ReplaceUses(SDValue(Node, 0), SDValue(ScatterOp, 0));
- for (auto *Node : E1)
- ReplaceUses(SDValue(Node, 0), SDValue(ScatterOp, 1));
- return true;
- }
- static unsigned int getCodeAddrSpace(MemSDNode *N) {
- const Value *Src = N->getMemOperand()->getValue();
- if (!Src)
- return NVPTX::PTXLdStInstCode::GENERIC;
- if (auto *PT = dyn_cast<PointerType>(Src->getType())) {
- switch (PT->getAddressSpace()) {
- case llvm::ADDRESS_SPACE_LOCAL: return NVPTX::PTXLdStInstCode::LOCAL;
- case llvm::ADDRESS_SPACE_GLOBAL: return NVPTX::PTXLdStInstCode::GLOBAL;
- case llvm::ADDRESS_SPACE_SHARED: return NVPTX::PTXLdStInstCode::SHARED;
- case llvm::ADDRESS_SPACE_GENERIC: return NVPTX::PTXLdStInstCode::GENERIC;
- case llvm::ADDRESS_SPACE_PARAM: return NVPTX::PTXLdStInstCode::PARAM;
- case llvm::ADDRESS_SPACE_CONST: return NVPTX::PTXLdStInstCode::CONSTANT;
- default: break;
- }
- }
- return NVPTX::PTXLdStInstCode::GENERIC;
- }
- static bool canLowerToLDG(MemSDNode *N, const NVPTXSubtarget &Subtarget,
- unsigned CodeAddrSpace, MachineFunction *F) {
- // We use ldg (i.e. ld.global.nc) for invariant loads from the global address
- // space.
- //
- // We have two ways of identifying invariant loads: Loads may be explicitly
- // marked as invariant, or we may infer them to be invariant.
- //
- // We currently infer invariance for loads from
- // - constant global variables, and
- // - kernel function pointer params that are noalias (i.e. __restrict) and
- // never written to.
- //
- // TODO: Perform a more powerful invariance analysis (ideally IPO, and ideally
- // not during the SelectionDAG phase).
- //
- // TODO: Infer invariance only at -O2. We still want to use ldg at -O0 for
- // explicitly invariant loads because these are how clang tells us to use ldg
- // when the user uses a builtin.
- if (!Subtarget.hasLDG() || CodeAddrSpace != NVPTX::PTXLdStInstCode::GLOBAL)
- return false;
- if (N->isInvariant())
- return true;
- bool IsKernelFn = isKernelFunction(F->getFunction());
- // We use getUnderlyingObjects() here instead of getUnderlyingObject() mainly
- // because the former looks through phi nodes while the latter does not. We
- // need to look through phi nodes to handle pointer induction variables.
- SmallVector<const Value *, 8> Objs;
- getUnderlyingObjects(N->getMemOperand()->getValue(), Objs);
- return all_of(Objs, [&](const Value *V) {
- if (auto *A = dyn_cast<const Argument>(V))
- return IsKernelFn && A->onlyReadsMemory() && A->hasNoAliasAttr();
- if (auto *GV = dyn_cast<const GlobalVariable>(V))
- return GV->isConstant();
- return false;
- });
- }
- bool NVPTXDAGToDAGISel::tryIntrinsicNoChain(SDNode *N) {
- unsigned IID = cast<ConstantSDNode>(N->getOperand(0))->getZExtValue();
- switch (IID) {
- default:
- return false;
- case Intrinsic::nvvm_texsurf_handle_internal:
- SelectTexSurfHandle(N);
- return true;
- }
- }
- void NVPTXDAGToDAGISel::SelectTexSurfHandle(SDNode *N) {
- // Op 0 is the intrinsic ID
- SDValue Wrapper = N->getOperand(1);
- SDValue GlobalVal = Wrapper.getOperand(0);
- ReplaceNode(N, CurDAG->getMachineNode(NVPTX::texsurf_handles, SDLoc(N),
- MVT::i64, GlobalVal));
- }
- void NVPTXDAGToDAGISel::SelectAddrSpaceCast(SDNode *N) {
- SDValue Src = N->getOperand(0);
- AddrSpaceCastSDNode *CastN = cast<AddrSpaceCastSDNode>(N);
- unsigned SrcAddrSpace = CastN->getSrcAddressSpace();
- unsigned DstAddrSpace = CastN->getDestAddressSpace();
- assert(SrcAddrSpace != DstAddrSpace &&
- "addrspacecast must be between different address spaces");
- if (DstAddrSpace == ADDRESS_SPACE_GENERIC) {
- // Specific to generic
- unsigned Opc;
- switch (SrcAddrSpace) {
- default: report_fatal_error("Bad address space in addrspacecast");
- case ADDRESS_SPACE_GLOBAL:
- Opc = TM.is64Bit() ? NVPTX::cvta_global_yes_64 : NVPTX::cvta_global_yes;
- break;
- case ADDRESS_SPACE_SHARED:
- Opc = TM.is64Bit() ? (useShortPointers() ? NVPTX::cvta_shared_yes_6432
- : NVPTX::cvta_shared_yes_64)
- : NVPTX::cvta_shared_yes;
- break;
- case ADDRESS_SPACE_CONST:
- Opc = TM.is64Bit() ? (useShortPointers() ? NVPTX::cvta_const_yes_6432
- : NVPTX::cvta_const_yes_64)
- : NVPTX::cvta_const_yes;
- break;
- case ADDRESS_SPACE_LOCAL:
- Opc = TM.is64Bit() ? (useShortPointers() ? NVPTX::cvta_local_yes_6432
- : NVPTX::cvta_local_yes_64)
- : NVPTX::cvta_local_yes;
- break;
- }
- ReplaceNode(N, CurDAG->getMachineNode(Opc, SDLoc(N), N->getValueType(0),
- Src));
- return;
- } else {
- // Generic to specific
- if (SrcAddrSpace != 0)
- report_fatal_error("Cannot cast between two non-generic address spaces");
- unsigned Opc;
- switch (DstAddrSpace) {
- default: report_fatal_error("Bad address space in addrspacecast");
- case ADDRESS_SPACE_GLOBAL:
- Opc = TM.is64Bit() ? NVPTX::cvta_to_global_yes_64
- : NVPTX::cvta_to_global_yes;
- break;
- case ADDRESS_SPACE_SHARED:
- Opc = TM.is64Bit() ? (useShortPointers() ? NVPTX::cvta_to_shared_yes_3264
- : NVPTX::cvta_to_shared_yes_64)
- : NVPTX::cvta_to_shared_yes;
- break;
- case ADDRESS_SPACE_CONST:
- Opc = TM.is64Bit() ? (useShortPointers() ? NVPTX::cvta_to_const_yes_3264
- : NVPTX::cvta_to_const_yes_64)
- : NVPTX::cvta_to_const_yes;
- break;
- case ADDRESS_SPACE_LOCAL:
- Opc = TM.is64Bit() ? (useShortPointers() ? NVPTX::cvta_to_local_yes_3264
- : NVPTX::cvta_to_local_yes_64)
- : NVPTX::cvta_to_local_yes;
- break;
- case ADDRESS_SPACE_PARAM:
- Opc = TM.is64Bit() ? NVPTX::nvvm_ptr_gen_to_param_64
- : NVPTX::nvvm_ptr_gen_to_param;
- break;
- }
- ReplaceNode(N, CurDAG->getMachineNode(Opc, SDLoc(N), N->getValueType(0),
- Src));
- return;
- }
- }
- // Helper function template to reduce amount of boilerplate code for
- // opcode selection.
- static Optional<unsigned> pickOpcodeForVT(
- MVT::SimpleValueType VT, unsigned Opcode_i8, unsigned Opcode_i16,
- unsigned Opcode_i32, Optional<unsigned> Opcode_i64, unsigned Opcode_f16,
- unsigned Opcode_f16x2, unsigned Opcode_f32, Optional<unsigned> Opcode_f64) {
- switch (VT) {
- case MVT::i1:
- case MVT::i8:
- return Opcode_i8;
- case MVT::i16:
- return Opcode_i16;
- case MVT::i32:
- return Opcode_i32;
- case MVT::i64:
- return Opcode_i64;
- case MVT::f16:
- return Opcode_f16;
- case MVT::v2f16:
- return Opcode_f16x2;
- case MVT::f32:
- return Opcode_f32;
- case MVT::f64:
- return Opcode_f64;
- default:
- return None;
- }
- }
- bool NVPTXDAGToDAGISel::tryLoad(SDNode *N) {
- SDLoc dl(N);
- MemSDNode *LD = cast<MemSDNode>(N);
- assert(LD->readMem() && "Expected load");
- LoadSDNode *PlainLoad = dyn_cast<LoadSDNode>(N);
- EVT LoadedVT = LD->getMemoryVT();
- SDNode *NVPTXLD = nullptr;
- // do not support pre/post inc/dec
- if (PlainLoad && PlainLoad->isIndexed())
- return false;
- if (!LoadedVT.isSimple())
- return false;
- AtomicOrdering Ordering = LD->getSuccessOrdering();
- // In order to lower atomic loads with stronger guarantees we would need to
- // use load.acquire or insert fences. However these features were only added
- // with PTX ISA 6.0 / sm_70.
- // TODO: Check if we can actually use the new instructions and implement them.
- if (isStrongerThanMonotonic(Ordering))
- return false;
- // Address Space Setting
- unsigned int CodeAddrSpace = getCodeAddrSpace(LD);
- if (canLowerToLDG(LD, *Subtarget, CodeAddrSpace, MF)) {
- return tryLDGLDU(N);
- }
- unsigned int PointerSize =
- CurDAG->getDataLayout().getPointerSizeInBits(LD->getAddressSpace());
- // Volatile Setting
- // - .volatile is only available for .global and .shared
- // - .volatile has the same memory synchronization semantics as .relaxed.sys
- bool isVolatile = LD->isVolatile() || Ordering == AtomicOrdering::Monotonic;
- if (CodeAddrSpace != NVPTX::PTXLdStInstCode::GLOBAL &&
- CodeAddrSpace != NVPTX::PTXLdStInstCode::SHARED &&
- CodeAddrSpace != NVPTX::PTXLdStInstCode::GENERIC)
- isVolatile = false;
- // Type Setting: fromType + fromTypeWidth
- //
- // Sign : ISD::SEXTLOAD
- // Unsign : ISD::ZEXTLOAD, ISD::NON_EXTLOAD or ISD::EXTLOAD and the
- // type is integer
- // Float : ISD::NON_EXTLOAD or ISD::EXTLOAD and the type is float
- MVT SimpleVT = LoadedVT.getSimpleVT();
- MVT ScalarVT = SimpleVT.getScalarType();
- // Read at least 8 bits (predicates are stored as 8-bit values)
- unsigned fromTypeWidth = std::max(8U, (unsigned)ScalarVT.getSizeInBits());
- unsigned int fromType;
- // Vector Setting
- unsigned vecType = NVPTX::PTXLdStInstCode::Scalar;
- if (SimpleVT.isVector()) {
- assert(LoadedVT == MVT::v2f16 && "Unexpected vector type");
- // v2f16 is loaded using ld.b32
- fromTypeWidth = 32;
- }
- if (PlainLoad && (PlainLoad->getExtensionType() == ISD::SEXTLOAD))
- fromType = NVPTX::PTXLdStInstCode::Signed;
- else if (ScalarVT.isFloatingPoint())
- // f16 uses .b16 as its storage type.
- fromType = ScalarVT.SimpleTy == MVT::f16 ? NVPTX::PTXLdStInstCode::Untyped
- : NVPTX::PTXLdStInstCode::Float;
- else
- fromType = NVPTX::PTXLdStInstCode::Unsigned;
- // Create the machine instruction DAG
- SDValue Chain = N->getOperand(0);
- SDValue N1 = N->getOperand(1);
- SDValue Addr;
- SDValue Offset, Base;
- Optional<unsigned> Opcode;
- MVT::SimpleValueType TargetVT = LD->getSimpleValueType(0).SimpleTy;
- if (SelectDirectAddr(N1, Addr)) {
- Opcode = pickOpcodeForVT(
- TargetVT, NVPTX::LD_i8_avar, NVPTX::LD_i16_avar, NVPTX::LD_i32_avar,
- NVPTX::LD_i64_avar, NVPTX::LD_f16_avar, NVPTX::LD_f16x2_avar,
- NVPTX::LD_f32_avar, NVPTX::LD_f64_avar);
- if (!Opcode)
- return false;
- SDValue Ops[] = { getI32Imm(isVolatile, dl), getI32Imm(CodeAddrSpace, dl),
- getI32Imm(vecType, dl), getI32Imm(fromType, dl),
- getI32Imm(fromTypeWidth, dl), Addr, Chain };
- NVPTXLD = CurDAG->getMachineNode(Opcode.getValue(), dl, TargetVT,
- MVT::Other, Ops);
- } else if (PointerSize == 64 ? SelectADDRsi64(N1.getNode(), N1, Base, Offset)
- : SelectADDRsi(N1.getNode(), N1, Base, Offset)) {
- Opcode = pickOpcodeForVT(TargetVT, NVPTX::LD_i8_asi, NVPTX::LD_i16_asi,
- NVPTX::LD_i32_asi, NVPTX::LD_i64_asi,
- NVPTX::LD_f16_asi, NVPTX::LD_f16x2_asi,
- NVPTX::LD_f32_asi, NVPTX::LD_f64_asi);
- if (!Opcode)
- return false;
- SDValue Ops[] = { getI32Imm(isVolatile, dl), getI32Imm(CodeAddrSpace, dl),
- getI32Imm(vecType, dl), getI32Imm(fromType, dl),
- getI32Imm(fromTypeWidth, dl), Base, Offset, Chain };
- NVPTXLD = CurDAG->getMachineNode(Opcode.getValue(), dl, TargetVT,
- MVT::Other, Ops);
- } else if (PointerSize == 64 ? SelectADDRri64(N1.getNode(), N1, Base, Offset)
- : SelectADDRri(N1.getNode(), N1, Base, Offset)) {
- if (PointerSize == 64)
- Opcode = pickOpcodeForVT(
- TargetVT, NVPTX::LD_i8_ari_64, NVPTX::LD_i16_ari_64,
- NVPTX::LD_i32_ari_64, NVPTX::LD_i64_ari_64, NVPTX::LD_f16_ari_64,
- NVPTX::LD_f16x2_ari_64, NVPTX::LD_f32_ari_64, NVPTX::LD_f64_ari_64);
- else
- Opcode = pickOpcodeForVT(
- TargetVT, NVPTX::LD_i8_ari, NVPTX::LD_i16_ari, NVPTX::LD_i32_ari,
- NVPTX::LD_i64_ari, NVPTX::LD_f16_ari, NVPTX::LD_f16x2_ari,
- NVPTX::LD_f32_ari, NVPTX::LD_f64_ari);
- if (!Opcode)
- return false;
- SDValue Ops[] = { getI32Imm(isVolatile, dl), getI32Imm(CodeAddrSpace, dl),
- getI32Imm(vecType, dl), getI32Imm(fromType, dl),
- getI32Imm(fromTypeWidth, dl), Base, Offset, Chain };
- NVPTXLD = CurDAG->getMachineNode(Opcode.getValue(), dl, TargetVT,
- MVT::Other, Ops);
- } else {
- if (PointerSize == 64)
- Opcode = pickOpcodeForVT(
- TargetVT, NVPTX::LD_i8_areg_64, NVPTX::LD_i16_areg_64,
- NVPTX::LD_i32_areg_64, NVPTX::LD_i64_areg_64, NVPTX::LD_f16_areg_64,
- NVPTX::LD_f16x2_areg_64, NVPTX::LD_f32_areg_64,
- NVPTX::LD_f64_areg_64);
- else
- Opcode = pickOpcodeForVT(
- TargetVT, NVPTX::LD_i8_areg, NVPTX::LD_i16_areg, NVPTX::LD_i32_areg,
- NVPTX::LD_i64_areg, NVPTX::LD_f16_areg, NVPTX::LD_f16x2_areg,
- NVPTX::LD_f32_areg, NVPTX::LD_f64_areg);
- if (!Opcode)
- return false;
- SDValue Ops[] = { getI32Imm(isVolatile, dl), getI32Imm(CodeAddrSpace, dl),
- getI32Imm(vecType, dl), getI32Imm(fromType, dl),
- getI32Imm(fromTypeWidth, dl), N1, Chain };
- NVPTXLD = CurDAG->getMachineNode(Opcode.getValue(), dl, TargetVT,
- MVT::Other, Ops);
- }
- if (!NVPTXLD)
- return false;
- MachineMemOperand *MemRef = cast<MemSDNode>(N)->getMemOperand();
- CurDAG->setNodeMemRefs(cast<MachineSDNode>(NVPTXLD), {MemRef});
- ReplaceNode(N, NVPTXLD);
- return true;
- }
- bool NVPTXDAGToDAGISel::tryLoadVector(SDNode *N) {
- SDValue Chain = N->getOperand(0);
- SDValue Op1 = N->getOperand(1);
- SDValue Addr, Offset, Base;
- Optional<unsigned> Opcode;
- SDLoc DL(N);
- SDNode *LD;
- MemSDNode *MemSD = cast<MemSDNode>(N);
- EVT LoadedVT = MemSD->getMemoryVT();
- if (!LoadedVT.isSimple())
- return false;
- // Address Space Setting
- unsigned int CodeAddrSpace = getCodeAddrSpace(MemSD);
- if (canLowerToLDG(MemSD, *Subtarget, CodeAddrSpace, MF)) {
- return tryLDGLDU(N);
- }
- unsigned int PointerSize =
- CurDAG->getDataLayout().getPointerSizeInBits(MemSD->getAddressSpace());
- // Volatile Setting
- // - .volatile is only availalble for .global and .shared
- bool IsVolatile = MemSD->isVolatile();
- if (CodeAddrSpace != NVPTX::PTXLdStInstCode::GLOBAL &&
- CodeAddrSpace != NVPTX::PTXLdStInstCode::SHARED &&
- CodeAddrSpace != NVPTX::PTXLdStInstCode::GENERIC)
- IsVolatile = false;
- // Vector Setting
- MVT SimpleVT = LoadedVT.getSimpleVT();
- // Type Setting: fromType + fromTypeWidth
- //
- // Sign : ISD::SEXTLOAD
- // Unsign : ISD::ZEXTLOAD, ISD::NON_EXTLOAD or ISD::EXTLOAD and the
- // type is integer
- // Float : ISD::NON_EXTLOAD or ISD::EXTLOAD and the type is float
- MVT ScalarVT = SimpleVT.getScalarType();
- // Read at least 8 bits (predicates are stored as 8-bit values)
- unsigned FromTypeWidth = std::max(8U, (unsigned)ScalarVT.getSizeInBits());
- unsigned int FromType;
- // The last operand holds the original LoadSDNode::getExtensionType() value
- unsigned ExtensionType = cast<ConstantSDNode>(
- N->getOperand(N->getNumOperands() - 1))->getZExtValue();
- if (ExtensionType == ISD::SEXTLOAD)
- FromType = NVPTX::PTXLdStInstCode::Signed;
- else if (ScalarVT.isFloatingPoint())
- FromType = ScalarVT.SimpleTy == MVT::f16 ? NVPTX::PTXLdStInstCode::Untyped
- : NVPTX::PTXLdStInstCode::Float;
- else
- FromType = NVPTX::PTXLdStInstCode::Unsigned;
- unsigned VecType;
- switch (N->getOpcode()) {
- case NVPTXISD::LoadV2:
- VecType = NVPTX::PTXLdStInstCode::V2;
- break;
- case NVPTXISD::LoadV4:
- VecType = NVPTX::PTXLdStInstCode::V4;
- break;
- default:
- return false;
- }
- EVT EltVT = N->getValueType(0);
- // v8f16 is a special case. PTX doesn't have ld.v8.f16
- // instruction. Instead, we split the vector into v2f16 chunks and
- // load them with ld.v4.b32.
- if (EltVT == MVT::v2f16) {
- assert(N->getOpcode() == NVPTXISD::LoadV4 && "Unexpected load opcode.");
- EltVT = MVT::i32;
- FromType = NVPTX::PTXLdStInstCode::Untyped;
- FromTypeWidth = 32;
- }
- if (SelectDirectAddr(Op1, Addr)) {
- switch (N->getOpcode()) {
- default:
- return false;
- case NVPTXISD::LoadV2:
- Opcode = pickOpcodeForVT(EltVT.getSimpleVT().SimpleTy,
- NVPTX::LDV_i8_v2_avar, NVPTX::LDV_i16_v2_avar,
- NVPTX::LDV_i32_v2_avar, NVPTX::LDV_i64_v2_avar,
- NVPTX::LDV_f16_v2_avar, NVPTX::LDV_f16x2_v2_avar,
- NVPTX::LDV_f32_v2_avar, NVPTX::LDV_f64_v2_avar);
- break;
- case NVPTXISD::LoadV4:
- Opcode =
- pickOpcodeForVT(EltVT.getSimpleVT().SimpleTy, NVPTX::LDV_i8_v4_avar,
- NVPTX::LDV_i16_v4_avar, NVPTX::LDV_i32_v4_avar, None,
- NVPTX::LDV_f16_v4_avar, NVPTX::LDV_f16x2_v4_avar,
- NVPTX::LDV_f32_v4_avar, None);
- break;
- }
- if (!Opcode)
- return false;
- SDValue Ops[] = { getI32Imm(IsVolatile, DL), getI32Imm(CodeAddrSpace, DL),
- getI32Imm(VecType, DL), getI32Imm(FromType, DL),
- getI32Imm(FromTypeWidth, DL), Addr, Chain };
- LD = CurDAG->getMachineNode(Opcode.getValue(), DL, N->getVTList(), Ops);
- } else if (PointerSize == 64
- ? SelectADDRsi64(Op1.getNode(), Op1, Base, Offset)
- : SelectADDRsi(Op1.getNode(), Op1, Base, Offset)) {
- switch (N->getOpcode()) {
- default:
- return false;
- case NVPTXISD::LoadV2:
- Opcode = pickOpcodeForVT(EltVT.getSimpleVT().SimpleTy,
- NVPTX::LDV_i8_v2_asi, NVPTX::LDV_i16_v2_asi,
- NVPTX::LDV_i32_v2_asi, NVPTX::LDV_i64_v2_asi,
- NVPTX::LDV_f16_v2_asi, NVPTX::LDV_f16x2_v2_asi,
- NVPTX::LDV_f32_v2_asi, NVPTX::LDV_f64_v2_asi);
- break;
- case NVPTXISD::LoadV4:
- Opcode =
- pickOpcodeForVT(EltVT.getSimpleVT().SimpleTy, NVPTX::LDV_i8_v4_asi,
- NVPTX::LDV_i16_v4_asi, NVPTX::LDV_i32_v4_asi, None,
- NVPTX::LDV_f16_v4_asi, NVPTX::LDV_f16x2_v4_asi,
- NVPTX::LDV_f32_v4_asi, None);
- break;
- }
- if (!Opcode)
- return false;
- SDValue Ops[] = { getI32Imm(IsVolatile, DL), getI32Imm(CodeAddrSpace, DL),
- getI32Imm(VecType, DL), getI32Imm(FromType, DL),
- getI32Imm(FromTypeWidth, DL), Base, Offset, Chain };
- LD = CurDAG->getMachineNode(Opcode.getValue(), DL, N->getVTList(), Ops);
- } else if (PointerSize == 64
- ? SelectADDRri64(Op1.getNode(), Op1, Base, Offset)
- : SelectADDRri(Op1.getNode(), Op1, Base, Offset)) {
- if (PointerSize == 64) {
- switch (N->getOpcode()) {
- default:
- return false;
- case NVPTXISD::LoadV2:
- Opcode = pickOpcodeForVT(
- EltVT.getSimpleVT().SimpleTy, NVPTX::LDV_i8_v2_ari_64,
- NVPTX::LDV_i16_v2_ari_64, NVPTX::LDV_i32_v2_ari_64,
- NVPTX::LDV_i64_v2_ari_64, NVPTX::LDV_f16_v2_ari_64,
- NVPTX::LDV_f16x2_v2_ari_64, NVPTX::LDV_f32_v2_ari_64,
- NVPTX::LDV_f64_v2_ari_64);
- break;
- case NVPTXISD::LoadV4:
- Opcode = pickOpcodeForVT(
- EltVT.getSimpleVT().SimpleTy, NVPTX::LDV_i8_v4_ari_64,
- NVPTX::LDV_i16_v4_ari_64, NVPTX::LDV_i32_v4_ari_64, None,
- NVPTX::LDV_f16_v4_ari_64, NVPTX::LDV_f16x2_v4_ari_64,
- NVPTX::LDV_f32_v4_ari_64, None);
- break;
- }
- } else {
- switch (N->getOpcode()) {
- default:
- return false;
- case NVPTXISD::LoadV2:
- Opcode = pickOpcodeForVT(EltVT.getSimpleVT().SimpleTy,
- NVPTX::LDV_i8_v2_ari, NVPTX::LDV_i16_v2_ari,
- NVPTX::LDV_i32_v2_ari, NVPTX::LDV_i64_v2_ari,
- NVPTX::LDV_f16_v2_ari, NVPTX::LDV_f16x2_v2_ari,
- NVPTX::LDV_f32_v2_ari, NVPTX::LDV_f64_v2_ari);
- break;
- case NVPTXISD::LoadV4:
- Opcode =
- pickOpcodeForVT(EltVT.getSimpleVT().SimpleTy, NVPTX::LDV_i8_v4_ari,
- NVPTX::LDV_i16_v4_ari, NVPTX::LDV_i32_v4_ari, None,
- NVPTX::LDV_f16_v4_ari, NVPTX::LDV_f16x2_v4_ari,
- NVPTX::LDV_f32_v4_ari, None);
- break;
- }
- }
- if (!Opcode)
- return false;
- SDValue Ops[] = { getI32Imm(IsVolatile, DL), getI32Imm(CodeAddrSpace, DL),
- getI32Imm(VecType, DL), getI32Imm(FromType, DL),
- getI32Imm(FromTypeWidth, DL), Base, Offset, Chain };
- LD = CurDAG->getMachineNode(Opcode.getValue(), DL, N->getVTList(), Ops);
- } else {
- if (PointerSize == 64) {
- switch (N->getOpcode()) {
- default:
- return false;
- case NVPTXISD::LoadV2:
- Opcode = pickOpcodeForVT(
- EltVT.getSimpleVT().SimpleTy, NVPTX::LDV_i8_v2_areg_64,
- NVPTX::LDV_i16_v2_areg_64, NVPTX::LDV_i32_v2_areg_64,
- NVPTX::LDV_i64_v2_areg_64, NVPTX::LDV_f16_v2_areg_64,
- NVPTX::LDV_f16x2_v2_areg_64, NVPTX::LDV_f32_v2_areg_64,
- NVPTX::LDV_f64_v2_areg_64);
- break;
- case NVPTXISD::LoadV4:
- Opcode = pickOpcodeForVT(
- EltVT.getSimpleVT().SimpleTy, NVPTX::LDV_i8_v4_areg_64,
- NVPTX::LDV_i16_v4_areg_64, NVPTX::LDV_i32_v4_areg_64, None,
- NVPTX::LDV_f16_v4_areg_64, NVPTX::LDV_f16x2_v4_areg_64,
- NVPTX::LDV_f32_v4_areg_64, None);
- break;
- }
- } else {
- switch (N->getOpcode()) {
- default:
- return false;
- case NVPTXISD::LoadV2:
- Opcode =
- pickOpcodeForVT(EltVT.getSimpleVT().SimpleTy, NVPTX::LDV_i8_v2_areg,
- NVPTX::LDV_i16_v2_areg, NVPTX::LDV_i32_v2_areg,
- NVPTX::LDV_i64_v2_areg, NVPTX::LDV_f16_v2_areg,
- NVPTX::LDV_f16x2_v2_areg, NVPTX::LDV_f32_v2_areg,
- NVPTX::LDV_f64_v2_areg);
- break;
- case NVPTXISD::LoadV4:
- Opcode = pickOpcodeForVT(
- EltVT.getSimpleVT().SimpleTy, NVPTX::LDV_i8_v4_areg,
- NVPTX::LDV_i16_v4_areg, NVPTX::LDV_i32_v4_areg, None,
- NVPTX::LDV_f16_v4_areg, NVPTX::LDV_f16x2_v4_areg,
- NVPTX::LDV_f32_v4_areg, None);
- break;
- }
- }
- if (!Opcode)
- return false;
- SDValue Ops[] = { getI32Imm(IsVolatile, DL), getI32Imm(CodeAddrSpace, DL),
- getI32Imm(VecType, DL), getI32Imm(FromType, DL),
- getI32Imm(FromTypeWidth, DL), Op1, Chain };
- LD = CurDAG->getMachineNode(Opcode.getValue(), DL, N->getVTList(), Ops);
- }
- MachineMemOperand *MemRef = cast<MemSDNode>(N)->getMemOperand();
- CurDAG->setNodeMemRefs(cast<MachineSDNode>(LD), {MemRef});
- ReplaceNode(N, LD);
- return true;
- }
- bool NVPTXDAGToDAGISel::tryLDGLDU(SDNode *N) {
- SDValue Chain = N->getOperand(0);
- SDValue Op1;
- MemSDNode *Mem;
- bool IsLDG = true;
- // If this is an LDG intrinsic, the address is the third operand. If its an
- // LDG/LDU SD node (from custom vector handling), then its the second operand
- if (N->getOpcode() == ISD::INTRINSIC_W_CHAIN) {
- Op1 = N->getOperand(2);
- Mem = cast<MemIntrinsicSDNode>(N);
- unsigned IID = cast<ConstantSDNode>(N->getOperand(1))->getZExtValue();
- switch (IID) {
- default:
- return false;
- case Intrinsic::nvvm_ldg_global_f:
- case Intrinsic::nvvm_ldg_global_i:
- case Intrinsic::nvvm_ldg_global_p:
- IsLDG = true;
- break;
- case Intrinsic::nvvm_ldu_global_f:
- case Intrinsic::nvvm_ldu_global_i:
- case Intrinsic::nvvm_ldu_global_p:
- IsLDG = false;
- break;
- }
- } else {
- Op1 = N->getOperand(1);
- Mem = cast<MemSDNode>(N);
- }
- Optional<unsigned> Opcode;
- SDLoc DL(N);
- SDNode *LD;
- SDValue Base, Offset, Addr;
- EVT EltVT = Mem->getMemoryVT();
- unsigned NumElts = 1;
- if (EltVT.isVector()) {
- NumElts = EltVT.getVectorNumElements();
- EltVT = EltVT.getVectorElementType();
- // vectors of f16 are loaded/stored as multiples of v2f16 elements.
- if (EltVT == MVT::f16 && N->getValueType(0) == MVT::v2f16) {
- assert(NumElts % 2 == 0 && "Vector must have even number of elements");
- EltVT = MVT::v2f16;
- NumElts /= 2;
- }
- }
- // Build the "promoted" result VTList for the load. If we are really loading
- // i8s, then the return type will be promoted to i16 since we do not expose
- // 8-bit registers in NVPTX.
- EVT NodeVT = (EltVT == MVT::i8) ? MVT::i16 : EltVT;
- SmallVector<EVT, 5> InstVTs;
- for (unsigned i = 0; i != NumElts; ++i) {
- InstVTs.push_back(NodeVT);
- }
- InstVTs.push_back(MVT::Other);
- SDVTList InstVTList = CurDAG->getVTList(InstVTs);
- if (SelectDirectAddr(Op1, Addr)) {
- switch (N->getOpcode()) {
- default:
- return false;
- case ISD::LOAD:
- case ISD::INTRINSIC_W_CHAIN:
- if (IsLDG)
- Opcode = pickOpcodeForVT(EltVT.getSimpleVT().SimpleTy,
- NVPTX::INT_PTX_LDG_GLOBAL_i8avar,
- NVPTX::INT_PTX_LDG_GLOBAL_i16avar,
- NVPTX::INT_PTX_LDG_GLOBAL_i32avar,
- NVPTX::INT_PTX_LDG_GLOBAL_i64avar,
- NVPTX::INT_PTX_LDG_GLOBAL_f16avar,
- NVPTX::INT_PTX_LDG_GLOBAL_f16x2avar,
- NVPTX::INT_PTX_LDG_GLOBAL_f32avar,
- NVPTX::INT_PTX_LDG_GLOBAL_f64avar);
- else
- Opcode = pickOpcodeForVT(EltVT.getSimpleVT().SimpleTy,
- NVPTX::INT_PTX_LDU_GLOBAL_i8avar,
- NVPTX::INT_PTX_LDU_GLOBAL_i16avar,
- NVPTX::INT_PTX_LDU_GLOBAL_i32avar,
- NVPTX::INT_PTX_LDU_GLOBAL_i64avar,
- NVPTX::INT_PTX_LDU_GLOBAL_f16avar,
- NVPTX::INT_PTX_LDU_GLOBAL_f16x2avar,
- NVPTX::INT_PTX_LDU_GLOBAL_f32avar,
- NVPTX::INT_PTX_LDU_GLOBAL_f64avar);
- break;
- case NVPTXISD::LoadV2:
- case NVPTXISD::LDGV2:
- Opcode = pickOpcodeForVT(EltVT.getSimpleVT().SimpleTy,
- NVPTX::INT_PTX_LDG_G_v2i8_ELE_avar,
- NVPTX::INT_PTX_LDG_G_v2i16_ELE_avar,
- NVPTX::INT_PTX_LDG_G_v2i32_ELE_avar,
- NVPTX::INT_PTX_LDG_G_v2i64_ELE_avar,
- NVPTX::INT_PTX_LDG_G_v2f16_ELE_avar,
- NVPTX::INT_PTX_LDG_G_v2f16x2_ELE_avar,
- NVPTX::INT_PTX_LDG_G_v2f32_ELE_avar,
- NVPTX::INT_PTX_LDG_G_v2f64_ELE_avar);
- break;
- case NVPTXISD::LDUV2:
- Opcode = pickOpcodeForVT(EltVT.getSimpleVT().SimpleTy,
- NVPTX::INT_PTX_LDU_G_v2i8_ELE_avar,
- NVPTX::INT_PTX_LDU_G_v2i16_ELE_avar,
- NVPTX::INT_PTX_LDU_G_v2i32_ELE_avar,
- NVPTX::INT_PTX_LDU_G_v2i64_ELE_avar,
- NVPTX::INT_PTX_LDU_G_v2f16_ELE_avar,
- NVPTX::INT_PTX_LDU_G_v2f16x2_ELE_avar,
- NVPTX::INT_PTX_LDU_G_v2f32_ELE_avar,
- NVPTX::INT_PTX_LDU_G_v2f64_ELE_avar);
- break;
- case NVPTXISD::LoadV4:
- case NVPTXISD::LDGV4:
- Opcode = pickOpcodeForVT(EltVT.getSimpleVT().SimpleTy,
- NVPTX::INT_PTX_LDG_G_v4i8_ELE_avar,
- NVPTX::INT_PTX_LDG_G_v4i16_ELE_avar,
- NVPTX::INT_PTX_LDG_G_v4i32_ELE_avar, None,
- NVPTX::INT_PTX_LDG_G_v4f16_ELE_avar,
- NVPTX::INT_PTX_LDG_G_v4f16x2_ELE_avar,
- NVPTX::INT_PTX_LDG_G_v4f32_ELE_avar, None);
- break;
- case NVPTXISD::LDUV4:
- Opcode = pickOpcodeForVT(EltVT.getSimpleVT().SimpleTy,
- NVPTX::INT_PTX_LDU_G_v4i8_ELE_avar,
- NVPTX::INT_PTX_LDU_G_v4i16_ELE_avar,
- NVPTX::INT_PTX_LDU_G_v4i32_ELE_avar, None,
- NVPTX::INT_PTX_LDU_G_v4f16_ELE_avar,
- NVPTX::INT_PTX_LDU_G_v4f16x2_ELE_avar,
- NVPTX::INT_PTX_LDU_G_v4f32_ELE_avar, None);
- break;
- }
- if (!Opcode)
- return false;
- SDValue Ops[] = { Addr, Chain };
- LD = CurDAG->getMachineNode(Opcode.getValue(), DL, InstVTList, Ops);
- } else if (TM.is64Bit() ? SelectADDRri64(Op1.getNode(), Op1, Base, Offset)
- : SelectADDRri(Op1.getNode(), Op1, Base, Offset)) {
- if (TM.is64Bit()) {
- switch (N->getOpcode()) {
- default:
- return false;
- case ISD::LOAD:
- case ISD::INTRINSIC_W_CHAIN:
- if (IsLDG)
- Opcode = pickOpcodeForVT(EltVT.getSimpleVT().SimpleTy,
- NVPTX::INT_PTX_LDG_GLOBAL_i8ari64,
- NVPTX::INT_PTX_LDG_GLOBAL_i16ari64,
- NVPTX::INT_PTX_LDG_GLOBAL_i32ari64,
- NVPTX::INT_PTX_LDG_GLOBAL_i64ari64,
- NVPTX::INT_PTX_LDG_GLOBAL_f16ari64,
- NVPTX::INT_PTX_LDG_GLOBAL_f16x2ari64,
- NVPTX::INT_PTX_LDG_GLOBAL_f32ari64,
- NVPTX::INT_PTX_LDG_GLOBAL_f64ari64);
- else
- Opcode = pickOpcodeForVT(EltVT.getSimpleVT().SimpleTy,
- NVPTX::INT_PTX_LDU_GLOBAL_i8ari64,
- NVPTX::INT_PTX_LDU_GLOBAL_i16ari64,
- NVPTX::INT_PTX_LDU_GLOBAL_i32ari64,
- NVPTX::INT_PTX_LDU_GLOBAL_i64ari64,
- NVPTX::INT_PTX_LDU_GLOBAL_f16ari64,
- NVPTX::INT_PTX_LDU_GLOBAL_f16x2ari64,
- NVPTX::INT_PTX_LDU_GLOBAL_f32ari64,
- NVPTX::INT_PTX_LDU_GLOBAL_f64ari64);
- break;
- case NVPTXISD::LoadV2:
- case NVPTXISD::LDGV2:
- Opcode = pickOpcodeForVT(EltVT.getSimpleVT().SimpleTy,
- NVPTX::INT_PTX_LDG_G_v2i8_ELE_ari64,
- NVPTX::INT_PTX_LDG_G_v2i16_ELE_ari64,
- NVPTX::INT_PTX_LDG_G_v2i32_ELE_ari64,
- NVPTX::INT_PTX_LDG_G_v2i64_ELE_ari64,
- NVPTX::INT_PTX_LDG_G_v2f16_ELE_ari64,
- NVPTX::INT_PTX_LDG_G_v2f16x2_ELE_ari64,
- NVPTX::INT_PTX_LDG_G_v2f32_ELE_ari64,
- NVPTX::INT_PTX_LDG_G_v2f64_ELE_ari64);
- break;
- case NVPTXISD::LDUV2:
- Opcode = pickOpcodeForVT(EltVT.getSimpleVT().SimpleTy,
- NVPTX::INT_PTX_LDU_G_v2i8_ELE_ari64,
- NVPTX::INT_PTX_LDU_G_v2i16_ELE_ari64,
- NVPTX::INT_PTX_LDU_G_v2i32_ELE_ari64,
- NVPTX::INT_PTX_LDU_G_v2i64_ELE_ari64,
- NVPTX::INT_PTX_LDU_G_v2f16_ELE_ari64,
- NVPTX::INT_PTX_LDU_G_v2f16x2_ELE_ari64,
- NVPTX::INT_PTX_LDU_G_v2f32_ELE_ari64,
- NVPTX::INT_PTX_LDU_G_v2f64_ELE_ari64);
- break;
- case NVPTXISD::LoadV4:
- case NVPTXISD::LDGV4:
- Opcode = pickOpcodeForVT(EltVT.getSimpleVT().SimpleTy,
- NVPTX::INT_PTX_LDG_G_v4i8_ELE_ari64,
- NVPTX::INT_PTX_LDG_G_v4i16_ELE_ari64,
- NVPTX::INT_PTX_LDG_G_v4i32_ELE_ari64, None,
- NVPTX::INT_PTX_LDG_G_v4f16_ELE_ari64,
- NVPTX::INT_PTX_LDG_G_v4f16x2_ELE_ari64,
- NVPTX::INT_PTX_LDG_G_v4f32_ELE_ari64, None);
- break;
- case NVPTXISD::LDUV4:
- Opcode = pickOpcodeForVT(EltVT.getSimpleVT().SimpleTy,
- NVPTX::INT_PTX_LDU_G_v4i8_ELE_ari64,
- NVPTX::INT_PTX_LDU_G_v4i16_ELE_ari64,
- NVPTX::INT_PTX_LDU_G_v4i32_ELE_ari64, None,
- NVPTX::INT_PTX_LDU_G_v4f16_ELE_ari64,
- NVPTX::INT_PTX_LDU_G_v4f16x2_ELE_ari64,
- NVPTX::INT_PTX_LDU_G_v4f32_ELE_ari64, None);
- break;
- }
- } else {
- switch (N->getOpcode()) {
- default:
- return false;
- case ISD::LOAD:
- case ISD::INTRINSIC_W_CHAIN:
- if (IsLDG)
- Opcode = pickOpcodeForVT(EltVT.getSimpleVT().SimpleTy,
- NVPTX::INT_PTX_LDG_GLOBAL_i8ari,
- NVPTX::INT_PTX_LDG_GLOBAL_i16ari,
- NVPTX::INT_PTX_LDG_GLOBAL_i32ari,
- NVPTX::INT_PTX_LDG_GLOBAL_i64ari,
- NVPTX::INT_PTX_LDG_GLOBAL_f16ari,
- NVPTX::INT_PTX_LDG_GLOBAL_f16x2ari,
- NVPTX::INT_PTX_LDG_GLOBAL_f32ari,
- NVPTX::INT_PTX_LDG_GLOBAL_f64ari);
- else
- Opcode = pickOpcodeForVT(EltVT.getSimpleVT().SimpleTy,
- NVPTX::INT_PTX_LDU_GLOBAL_i8ari,
- NVPTX::INT_PTX_LDU_GLOBAL_i16ari,
- NVPTX::INT_PTX_LDU_GLOBAL_i32ari,
- NVPTX::INT_PTX_LDU_GLOBAL_i64ari,
- NVPTX::INT_PTX_LDU_GLOBAL_f16ari,
- NVPTX::INT_PTX_LDU_GLOBAL_f16x2ari,
- NVPTX::INT_PTX_LDU_GLOBAL_f32ari,
- NVPTX::INT_PTX_LDU_GLOBAL_f64ari);
- break;
- case NVPTXISD::LoadV2:
- case NVPTXISD::LDGV2:
- Opcode = pickOpcodeForVT(EltVT.getSimpleVT().SimpleTy,
- NVPTX::INT_PTX_LDG_G_v2i8_ELE_ari32,
- NVPTX::INT_PTX_LDG_G_v2i16_ELE_ari32,
- NVPTX::INT_PTX_LDG_G_v2i32_ELE_ari32,
- NVPTX::INT_PTX_LDG_G_v2i64_ELE_ari32,
- NVPTX::INT_PTX_LDG_G_v2f16_ELE_ari32,
- NVPTX::INT_PTX_LDG_G_v2f16x2_ELE_ari32,
- NVPTX::INT_PTX_LDG_G_v2f32_ELE_ari32,
- NVPTX::INT_PTX_LDG_G_v2f64_ELE_ari32);
- break;
- case NVPTXISD::LDUV2:
- Opcode = pickOpcodeForVT(EltVT.getSimpleVT().SimpleTy,
- NVPTX::INT_PTX_LDU_G_v2i8_ELE_ari32,
- NVPTX::INT_PTX_LDU_G_v2i16_ELE_ari32,
- NVPTX::INT_PTX_LDU_G_v2i32_ELE_ari32,
- NVPTX::INT_PTX_LDU_G_v2i64_ELE_ari32,
- NVPTX::INT_PTX_LDU_G_v2f16_ELE_ari32,
- NVPTX::INT_PTX_LDU_G_v2f16x2_ELE_ari32,
- NVPTX::INT_PTX_LDU_G_v2f32_ELE_ari32,
- NVPTX::INT_PTX_LDU_G_v2f64_ELE_ari32);
- break;
- case NVPTXISD::LoadV4:
- case NVPTXISD::LDGV4:
- Opcode = pickOpcodeForVT(EltVT.getSimpleVT().SimpleTy,
- NVPTX::INT_PTX_LDG_G_v4i8_ELE_ari32,
- NVPTX::INT_PTX_LDG_G_v4i16_ELE_ari32,
- NVPTX::INT_PTX_LDG_G_v4i32_ELE_ari32, None,
- NVPTX::INT_PTX_LDG_G_v4f16_ELE_ari32,
- NVPTX::INT_PTX_LDG_G_v4f16x2_ELE_ari32,
- NVPTX::INT_PTX_LDG_G_v4f32_ELE_ari32, None);
- break;
- case NVPTXISD::LDUV4:
- Opcode = pickOpcodeForVT(EltVT.getSimpleVT().SimpleTy,
- NVPTX::INT_PTX_LDU_G_v4i8_ELE_ari32,
- NVPTX::INT_PTX_LDU_G_v4i16_ELE_ari32,
- NVPTX::INT_PTX_LDU_G_v4i32_ELE_ari32, None,
- NVPTX::INT_PTX_LDU_G_v4f16_ELE_ari32,
- NVPTX::INT_PTX_LDU_G_v4f16x2_ELE_ari32,
- NVPTX::INT_PTX_LDU_G_v4f32_ELE_ari32, None);
- break;
- }
- }
- if (!Opcode)
- return false;
- SDValue Ops[] = {Base, Offset, Chain};
- LD = CurDAG->getMachineNode(Opcode.getValue(), DL, InstVTList, Ops);
- } else {
- if (TM.is64Bit()) {
- switch (N->getOpcode()) {
- default:
- return false;
- case ISD::LOAD:
- case ISD::INTRINSIC_W_CHAIN:
- if (IsLDG)
- Opcode = pickOpcodeForVT(EltVT.getSimpleVT().SimpleTy,
- NVPTX::INT_PTX_LDG_GLOBAL_i8areg64,
- NVPTX::INT_PTX_LDG_GLOBAL_i16areg64,
- NVPTX::INT_PTX_LDG_GLOBAL_i32areg64,
- NVPTX::INT_PTX_LDG_GLOBAL_i64areg64,
- NVPTX::INT_PTX_LDG_GLOBAL_f16areg64,
- NVPTX::INT_PTX_LDG_GLOBAL_f16x2areg64,
- NVPTX::INT_PTX_LDG_GLOBAL_f32areg64,
- NVPTX::INT_PTX_LDG_GLOBAL_f64areg64);
- else
- Opcode = pickOpcodeForVT(EltVT.getSimpleVT().SimpleTy,
- NVPTX::INT_PTX_LDU_GLOBAL_i8areg64,
- NVPTX::INT_PTX_LDU_GLOBAL_i16areg64,
- NVPTX::INT_PTX_LDU_GLOBAL_i32areg64,
- NVPTX::INT_PTX_LDU_GLOBAL_i64areg64,
- NVPTX::INT_PTX_LDU_GLOBAL_f16areg64,
- NVPTX::INT_PTX_LDU_GLOBAL_f16x2areg64,
- NVPTX::INT_PTX_LDU_GLOBAL_f32areg64,
- NVPTX::INT_PTX_LDU_GLOBAL_f64areg64);
- break;
- case NVPTXISD::LoadV2:
- case NVPTXISD::LDGV2:
- Opcode = pickOpcodeForVT(EltVT.getSimpleVT().SimpleTy,
- NVPTX::INT_PTX_LDG_G_v2i8_ELE_areg64,
- NVPTX::INT_PTX_LDG_G_v2i16_ELE_areg64,
- NVPTX::INT_PTX_LDG_G_v2i32_ELE_areg64,
- NVPTX::INT_PTX_LDG_G_v2i64_ELE_areg64,
- NVPTX::INT_PTX_LDG_G_v2f16_ELE_areg64,
- NVPTX::INT_PTX_LDG_G_v2f16x2_ELE_areg64,
- NVPTX::INT_PTX_LDG_G_v2f32_ELE_areg64,
- NVPTX::INT_PTX_LDG_G_v2f64_ELE_areg64);
- break;
- case NVPTXISD::LDUV2:
- Opcode = pickOpcodeForVT(EltVT.getSimpleVT().SimpleTy,
- NVPTX::INT_PTX_LDU_G_v2i8_ELE_areg64,
- NVPTX::INT_PTX_LDU_G_v2i16_ELE_areg64,
- NVPTX::INT_PTX_LDU_G_v2i32_ELE_areg64,
- NVPTX::INT_PTX_LDU_G_v2i64_ELE_areg64,
- NVPTX::INT_PTX_LDU_G_v2f16_ELE_areg64,
- NVPTX::INT_PTX_LDU_G_v2f16x2_ELE_areg64,
- NVPTX::INT_PTX_LDU_G_v2f32_ELE_areg64,
- NVPTX::INT_PTX_LDU_G_v2f64_ELE_areg64);
- break;
- case NVPTXISD::LoadV4:
- case NVPTXISD::LDGV4:
- Opcode = pickOpcodeForVT(EltVT.getSimpleVT().SimpleTy,
- NVPTX::INT_PTX_LDG_G_v4i8_ELE_areg64,
- NVPTX::INT_PTX_LDG_G_v4i16_ELE_areg64,
- NVPTX::INT_PTX_LDG_G_v4i32_ELE_areg64, None,
- NVPTX::INT_PTX_LDG_G_v4f16_ELE_areg64,
- NVPTX::INT_PTX_LDG_G_v4f16x2_ELE_areg64,
- NVPTX::INT_PTX_LDG_G_v4f32_ELE_areg64, None);
- break;
- case NVPTXISD::LDUV4:
- Opcode = pickOpcodeForVT(EltVT.getSimpleVT().SimpleTy,
- NVPTX::INT_PTX_LDU_G_v4i8_ELE_areg64,
- NVPTX::INT_PTX_LDU_G_v4i16_ELE_areg64,
- NVPTX::INT_PTX_LDU_G_v4i32_ELE_areg64, None,
- NVPTX::INT_PTX_LDU_G_v4f16_ELE_areg64,
- NVPTX::INT_PTX_LDU_G_v4f16x2_ELE_areg64,
- NVPTX::INT_PTX_LDU_G_v4f32_ELE_areg64, None);
- break;
- }
- } else {
- switch (N->getOpcode()) {
- default:
- return false;
- case ISD::LOAD:
- case ISD::INTRINSIC_W_CHAIN:
- if (IsLDG)
- Opcode = pickOpcodeForVT(EltVT.getSimpleVT().SimpleTy,
- NVPTX::INT_PTX_LDG_GLOBAL_i8areg,
- NVPTX::INT_PTX_LDG_GLOBAL_i16areg,
- NVPTX::INT_PTX_LDG_GLOBAL_i32areg,
- NVPTX::INT_PTX_LDG_GLOBAL_i64areg,
- NVPTX::INT_PTX_LDG_GLOBAL_f16areg,
- NVPTX::INT_PTX_LDG_GLOBAL_f16x2areg,
- NVPTX::INT_PTX_LDG_GLOBAL_f32areg,
- NVPTX::INT_PTX_LDG_GLOBAL_f64areg);
- else
- Opcode = pickOpcodeForVT(EltVT.getSimpleVT().SimpleTy,
- NVPTX::INT_PTX_LDU_GLOBAL_i8areg,
- NVPTX::INT_PTX_LDU_GLOBAL_i16areg,
- NVPTX::INT_PTX_LDU_GLOBAL_i32areg,
- NVPTX::INT_PTX_LDU_GLOBAL_i64areg,
- NVPTX::INT_PTX_LDU_GLOBAL_f16areg,
- NVPTX::INT_PTX_LDU_GLOBAL_f16x2areg,
- NVPTX::INT_PTX_LDU_GLOBAL_f32areg,
- NVPTX::INT_PTX_LDU_GLOBAL_f64areg);
- break;
- case NVPTXISD::LoadV2:
- case NVPTXISD::LDGV2:
- Opcode = pickOpcodeForVT(EltVT.getSimpleVT().SimpleTy,
- NVPTX::INT_PTX_LDG_G_v2i8_ELE_areg32,
- NVPTX::INT_PTX_LDG_G_v2i16_ELE_areg32,
- NVPTX::INT_PTX_LDG_G_v2i32_ELE_areg32,
- NVPTX::INT_PTX_LDG_G_v2i64_ELE_areg32,
- NVPTX::INT_PTX_LDG_G_v2f16_ELE_areg32,
- NVPTX::INT_PTX_LDG_G_v2f16x2_ELE_areg32,
- NVPTX::INT_PTX_LDG_G_v2f32_ELE_areg32,
- NVPTX::INT_PTX_LDG_G_v2f64_ELE_areg32);
- break;
- case NVPTXISD::LDUV2:
- Opcode = pickOpcodeForVT(EltVT.getSimpleVT().SimpleTy,
- NVPTX::INT_PTX_LDU_G_v2i8_ELE_areg32,
- NVPTX::INT_PTX_LDU_G_v2i16_ELE_areg32,
- NVPTX::INT_PTX_LDU_G_v2i32_ELE_areg32,
- NVPTX::INT_PTX_LDU_G_v2i64_ELE_areg32,
- NVPTX::INT_PTX_LDU_G_v2f16_ELE_areg32,
- NVPTX::INT_PTX_LDU_G_v2f16x2_ELE_areg32,
- NVPTX::INT_PTX_LDU_G_v2f32_ELE_areg32,
- NVPTX::INT_PTX_LDU_G_v2f64_ELE_areg32);
- break;
- case NVPTXISD::LoadV4:
- case NVPTXISD::LDGV4:
- Opcode = pickOpcodeForVT(EltVT.getSimpleVT().SimpleTy,
- NVPTX::INT_PTX_LDG_G_v4i8_ELE_areg32,
- NVPTX::INT_PTX_LDG_G_v4i16_ELE_areg32,
- NVPTX::INT_PTX_LDG_G_v4i32_ELE_areg32, None,
- NVPTX::INT_PTX_LDG_G_v4f16_ELE_areg32,
- NVPTX::INT_PTX_LDG_G_v4f16x2_ELE_areg32,
- NVPTX::INT_PTX_LDG_G_v4f32_ELE_areg32, None);
- break;
- case NVPTXISD::LDUV4:
- Opcode = pickOpcodeForVT(EltVT.getSimpleVT().SimpleTy,
- NVPTX::INT_PTX_LDU_G_v4i8_ELE_areg32,
- NVPTX::INT_PTX_LDU_G_v4i16_ELE_areg32,
- NVPTX::INT_PTX_LDU_G_v4i32_ELE_areg32, None,
- NVPTX::INT_PTX_LDU_G_v4f16_ELE_areg32,
- NVPTX::INT_PTX_LDU_G_v4f16x2_ELE_areg32,
- NVPTX::INT_PTX_LDU_G_v4f32_ELE_areg32, None);
- break;
- }
- }
- if (!Opcode)
- return false;
- SDValue Ops[] = { Op1, Chain };
- LD = CurDAG->getMachineNode(Opcode.getValue(), DL, InstVTList, Ops);
- }
- MachineMemOperand *MemRef = Mem->getMemOperand();
- CurDAG->setNodeMemRefs(cast<MachineSDNode>(LD), {MemRef});
- // For automatic generation of LDG (through SelectLoad[Vector], not the
- // intrinsics), we may have an extending load like:
- //
- // i32,ch = load<LD1[%data1(addrspace=1)], zext from i8> t0, t7, undef:i64
- //
- // In this case, the matching logic above will select a load for the original
- // memory type (in this case, i8) and our types will not match (the node needs
- // to return an i32 in this case). Our LDG/LDU nodes do not support the
- // concept of sign-/zero-extension, so emulate it here by adding an explicit
- // CVT instruction. Ptxas should clean up any redundancies here.
- EVT OrigType = N->getValueType(0);
- LoadSDNode *LdNode = dyn_cast<LoadSDNode>(N);
- if (OrigType != EltVT && LdNode) {
- // We have an extending-load. The instruction we selected operates on the
- // smaller type, but the SDNode we are replacing has the larger type. We
- // need to emit a CVT to make the types match.
- bool IsSigned = LdNode->getExtensionType() == ISD::SEXTLOAD;
- unsigned CvtOpc = GetConvertOpcode(OrigType.getSimpleVT(),
- EltVT.getSimpleVT(), IsSigned);
- // For each output value, apply the manual sign/zero-extension and make sure
- // all users of the load go through that CVT.
- for (unsigned i = 0; i != NumElts; ++i) {
- SDValue Res(LD, i);
- SDValue OrigVal(N, i);
- SDNode *CvtNode =
- CurDAG->getMachineNode(CvtOpc, DL, OrigType, Res,
- CurDAG->getTargetConstant(NVPTX::PTXCvtMode::NONE,
- DL, MVT::i32));
- ReplaceUses(OrigVal, SDValue(CvtNode, 0));
- }
- }
- ReplaceNode(N, LD);
- return true;
- }
- bool NVPTXDAGToDAGISel::tryStore(SDNode *N) {
- SDLoc dl(N);
- MemSDNode *ST = cast<MemSDNode>(N);
- assert(ST->writeMem() && "Expected store");
- StoreSDNode *PlainStore = dyn_cast<StoreSDNode>(N);
- AtomicSDNode *AtomicStore = dyn_cast<AtomicSDNode>(N);
- assert((PlainStore || AtomicStore) && "Expected store");
- EVT StoreVT = ST->getMemoryVT();
- SDNode *NVPTXST = nullptr;
- // do not support pre/post inc/dec
- if (PlainStore && PlainStore->isIndexed())
- return false;
- if (!StoreVT.isSimple())
- return false;
- AtomicOrdering Ordering = ST->getSuccessOrdering();
- // In order to lower atomic loads with stronger guarantees we would need to
- // use store.release or insert fences. However these features were only added
- // with PTX ISA 6.0 / sm_70.
- // TODO: Check if we can actually use the new instructions and implement them.
- if (isStrongerThanMonotonic(Ordering))
- return false;
- // Address Space Setting
- unsigned int CodeAddrSpace = getCodeAddrSpace(ST);
- unsigned int PointerSize =
- CurDAG->getDataLayout().getPointerSizeInBits(ST->getAddressSpace());
- // Volatile Setting
- // - .volatile is only available for .global and .shared
- // - .volatile has the same memory synchronization semantics as .relaxed.sys
- bool isVolatile = ST->isVolatile() || Ordering == AtomicOrdering::Monotonic;
- if (CodeAddrSpace != NVPTX::PTXLdStInstCode::GLOBAL &&
- CodeAddrSpace != NVPTX::PTXLdStInstCode::SHARED &&
- CodeAddrSpace != NVPTX::PTXLdStInstCode::GENERIC)
- isVolatile = false;
- // Vector Setting
- MVT SimpleVT = StoreVT.getSimpleVT();
- unsigned vecType = NVPTX::PTXLdStInstCode::Scalar;
- // Type Setting: toType + toTypeWidth
- // - for integer type, always use 'u'
- //
- MVT ScalarVT = SimpleVT.getScalarType();
- unsigned toTypeWidth = ScalarVT.getSizeInBits();
- if (SimpleVT.isVector()) {
- assert(StoreVT == MVT::v2f16 && "Unexpected vector type");
- // v2f16 is stored using st.b32
- toTypeWidth = 32;
- }
- unsigned int toType;
- if (ScalarVT.isFloatingPoint())
- // f16 uses .b16 as its storage type.
- toType = ScalarVT.SimpleTy == MVT::f16 ? NVPTX::PTXLdStInstCode::Untyped
- : NVPTX::PTXLdStInstCode::Float;
- else
- toType = NVPTX::PTXLdStInstCode::Unsigned;
- // Create the machine instruction DAG
- SDValue Chain = ST->getChain();
- SDValue Value = PlainStore ? PlainStore->getValue() : AtomicStore->getVal();
- SDValue BasePtr = ST->getBasePtr();
- SDValue Addr;
- SDValue Offset, Base;
- Optional<unsigned> Opcode;
- MVT::SimpleValueType SourceVT =
- Value.getNode()->getSimpleValueType(0).SimpleTy;
- if (SelectDirectAddr(BasePtr, Addr)) {
- Opcode = pickOpcodeForVT(SourceVT, NVPTX::ST_i8_avar, NVPTX::ST_i16_avar,
- NVPTX::ST_i32_avar, NVPTX::ST_i64_avar,
- NVPTX::ST_f16_avar, NVPTX::ST_f16x2_avar,
- NVPTX::ST_f32_avar, NVPTX::ST_f64_avar);
- if (!Opcode)
- return false;
- SDValue Ops[] = {Value,
- getI32Imm(isVolatile, dl),
- getI32Imm(CodeAddrSpace, dl),
- getI32Imm(vecType, dl),
- getI32Imm(toType, dl),
- getI32Imm(toTypeWidth, dl),
- Addr,
- Chain};
- NVPTXST = CurDAG->getMachineNode(Opcode.getValue(), dl, MVT::Other, Ops);
- } else if (PointerSize == 64
- ? SelectADDRsi64(BasePtr.getNode(), BasePtr, Base, Offset)
- : SelectADDRsi(BasePtr.getNode(), BasePtr, Base, Offset)) {
- Opcode = pickOpcodeForVT(SourceVT, NVPTX::ST_i8_asi, NVPTX::ST_i16_asi,
- NVPTX::ST_i32_asi, NVPTX::ST_i64_asi,
- NVPTX::ST_f16_asi, NVPTX::ST_f16x2_asi,
- NVPTX::ST_f32_asi, NVPTX::ST_f64_asi);
- if (!Opcode)
- return false;
- SDValue Ops[] = {Value,
- getI32Imm(isVolatile, dl),
- getI32Imm(CodeAddrSpace, dl),
- getI32Imm(vecType, dl),
- getI32Imm(toType, dl),
- getI32Imm(toTypeWidth, dl),
- Base,
- Offset,
- Chain};
- NVPTXST = CurDAG->getMachineNode(Opcode.getValue(), dl, MVT::Other, Ops);
- } else if (PointerSize == 64
- ? SelectADDRri64(BasePtr.getNode(), BasePtr, Base, Offset)
- : SelectADDRri(BasePtr.getNode(), BasePtr, Base, Offset)) {
- if (PointerSize == 64)
- Opcode = pickOpcodeForVT(
- SourceVT, NVPTX::ST_i8_ari_64, NVPTX::ST_i16_ari_64,
- NVPTX::ST_i32_ari_64, NVPTX::ST_i64_ari_64, NVPTX::ST_f16_ari_64,
- NVPTX::ST_f16x2_ari_64, NVPTX::ST_f32_ari_64, NVPTX::ST_f64_ari_64);
- else
- Opcode = pickOpcodeForVT(SourceVT, NVPTX::ST_i8_ari, NVPTX::ST_i16_ari,
- NVPTX::ST_i32_ari, NVPTX::ST_i64_ari,
- NVPTX::ST_f16_ari, NVPTX::ST_f16x2_ari,
- NVPTX::ST_f32_ari, NVPTX::ST_f64_ari);
- if (!Opcode)
- return false;
- SDValue Ops[] = {Value,
- getI32Imm(isVolatile, dl),
- getI32Imm(CodeAddrSpace, dl),
- getI32Imm(vecType, dl),
- getI32Imm(toType, dl),
- getI32Imm(toTypeWidth, dl),
- Base,
- Offset,
- Chain};
- NVPTXST = CurDAG->getMachineNode(Opcode.getValue(), dl, MVT::Other, Ops);
- } else {
- if (PointerSize == 64)
- Opcode =
- pickOpcodeForVT(SourceVT, NVPTX::ST_i8_areg_64, NVPTX::ST_i16_areg_64,
- NVPTX::ST_i32_areg_64, NVPTX::ST_i64_areg_64,
- NVPTX::ST_f16_areg_64, NVPTX::ST_f16x2_areg_64,
- NVPTX::ST_f32_areg_64, NVPTX::ST_f64_areg_64);
- else
- Opcode = pickOpcodeForVT(SourceVT, NVPTX::ST_i8_areg, NVPTX::ST_i16_areg,
- NVPTX::ST_i32_areg, NVPTX::ST_i64_areg,
- NVPTX::ST_f16_areg, NVPTX::ST_f16x2_areg,
- NVPTX::ST_f32_areg, NVPTX::ST_f64_areg);
- if (!Opcode)
- return false;
- SDValue Ops[] = {Value,
- getI32Imm(isVolatile, dl),
- getI32Imm(CodeAddrSpace, dl),
- getI32Imm(vecType, dl),
- getI32Imm(toType, dl),
- getI32Imm(toTypeWidth, dl),
- BasePtr,
- Chain};
- NVPTXST = CurDAG->getMachineNode(Opcode.getValue(), dl, MVT::Other, Ops);
- }
- if (!NVPTXST)
- return false;
- MachineMemOperand *MemRef = cast<MemSDNode>(N)->getMemOperand();
- CurDAG->setNodeMemRefs(cast<MachineSDNode>(NVPTXST), {MemRef});
- ReplaceNode(N, NVPTXST);
- return true;
- }
- bool NVPTXDAGToDAGISel::tryStoreVector(SDNode *N) {
- SDValue Chain = N->getOperand(0);
- SDValue Op1 = N->getOperand(1);
- SDValue Addr, Offset, Base;
- Optional<unsigned> Opcode;
- SDLoc DL(N);
- SDNode *ST;
- EVT EltVT = Op1.getValueType();
- MemSDNode *MemSD = cast<MemSDNode>(N);
- EVT StoreVT = MemSD->getMemoryVT();
- // Address Space Setting
- unsigned CodeAddrSpace = getCodeAddrSpace(MemSD);
- if (CodeAddrSpace == NVPTX::PTXLdStInstCode::CONSTANT) {
- report_fatal_error("Cannot store to pointer that points to constant "
- "memory space");
- }
- unsigned int PointerSize =
- CurDAG->getDataLayout().getPointerSizeInBits(MemSD->getAddressSpace());
- // Volatile Setting
- // - .volatile is only availalble for .global and .shared
- bool IsVolatile = MemSD->isVolatile();
- if (CodeAddrSpace != NVPTX::PTXLdStInstCode::GLOBAL &&
- CodeAddrSpace != NVPTX::PTXLdStInstCode::SHARED &&
- CodeAddrSpace != NVPTX::PTXLdStInstCode::GENERIC)
- IsVolatile = false;
- // Type Setting: toType + toTypeWidth
- // - for integer type, always use 'u'
- assert(StoreVT.isSimple() && "Store value is not simple");
- MVT ScalarVT = StoreVT.getSimpleVT().getScalarType();
- unsigned ToTypeWidth = ScalarVT.getSizeInBits();
- unsigned ToType;
- if (ScalarVT.isFloatingPoint())
- ToType = ScalarVT.SimpleTy == MVT::f16 ? NVPTX::PTXLdStInstCode::Untyped
- : NVPTX::PTXLdStInstCode::Float;
- else
- ToType = NVPTX::PTXLdStInstCode::Unsigned;
- SmallVector<SDValue, 12> StOps;
- SDValue N2;
- unsigned VecType;
- switch (N->getOpcode()) {
- case NVPTXISD::StoreV2:
- VecType = NVPTX::PTXLdStInstCode::V2;
- StOps.push_back(N->getOperand(1));
- StOps.push_back(N->getOperand(2));
- N2 = N->getOperand(3);
- break;
- case NVPTXISD::StoreV4:
- VecType = NVPTX::PTXLdStInstCode::V4;
- StOps.push_back(N->getOperand(1));
- StOps.push_back(N->getOperand(2));
- StOps.push_back(N->getOperand(3));
- StOps.push_back(N->getOperand(4));
- N2 = N->getOperand(5);
- break;
- default:
- return false;
- }
- // v8f16 is a special case. PTX doesn't have st.v8.f16
- // instruction. Instead, we split the vector into v2f16 chunks and
- // store them with st.v4.b32.
- if (EltVT == MVT::v2f16) {
- assert(N->getOpcode() == NVPTXISD::StoreV4 && "Unexpected load opcode.");
- EltVT = MVT::i32;
- ToType = NVPTX::PTXLdStInstCode::Untyped;
- ToTypeWidth = 32;
- }
- StOps.push_back(getI32Imm(IsVolatile, DL));
- StOps.push_back(getI32Imm(CodeAddrSpace, DL));
- StOps.push_back(getI32Imm(VecType, DL));
- StOps.push_back(getI32Imm(ToType, DL));
- StOps.push_back(getI32Imm(ToTypeWidth, DL));
- if (SelectDirectAddr(N2, Addr)) {
- switch (N->getOpcode()) {
- default:
- return false;
- case NVPTXISD::StoreV2:
- Opcode = pickOpcodeForVT(EltVT.getSimpleVT().SimpleTy,
- NVPTX::STV_i8_v2_avar, NVPTX::STV_i16_v2_avar,
- NVPTX::STV_i32_v2_avar, NVPTX::STV_i64_v2_avar,
- NVPTX::STV_f16_v2_avar, NVPTX::STV_f16x2_v2_avar,
- NVPTX::STV_f32_v2_avar, NVPTX::STV_f64_v2_avar);
- break;
- case NVPTXISD::StoreV4:
- Opcode =
- pickOpcodeForVT(EltVT.getSimpleVT().SimpleTy, NVPTX::STV_i8_v4_avar,
- NVPTX::STV_i16_v4_avar, NVPTX::STV_i32_v4_avar, None,
- NVPTX::STV_f16_v4_avar, NVPTX::STV_f16x2_v4_avar,
- NVPTX::STV_f32_v4_avar, None);
- break;
- }
- StOps.push_back(Addr);
- } else if (PointerSize == 64 ? SelectADDRsi64(N2.getNode(), N2, Base, Offset)
- : SelectADDRsi(N2.getNode(), N2, Base, Offset)) {
- switch (N->getOpcode()) {
- default:
- return false;
- case NVPTXISD::StoreV2:
- Opcode = pickOpcodeForVT(EltVT.getSimpleVT().SimpleTy,
- NVPTX::STV_i8_v2_asi, NVPTX::STV_i16_v2_asi,
- NVPTX::STV_i32_v2_asi, NVPTX::STV_i64_v2_asi,
- NVPTX::STV_f16_v2_asi, NVPTX::STV_f16x2_v2_asi,
- NVPTX::STV_f32_v2_asi, NVPTX::STV_f64_v2_asi);
- break;
- case NVPTXISD::StoreV4:
- Opcode =
- pickOpcodeForVT(EltVT.getSimpleVT().SimpleTy, NVPTX::STV_i8_v4_asi,
- NVPTX::STV_i16_v4_asi, NVPTX::STV_i32_v4_asi, None,
- NVPTX::STV_f16_v4_asi, NVPTX::STV_f16x2_v4_asi,
- NVPTX::STV_f32_v4_asi, None);
- break;
- }
- StOps.push_back(Base);
- StOps.push_back(Offset);
- } else if (PointerSize == 64 ? SelectADDRri64(N2.getNode(), N2, Base, Offset)
- : SelectADDRri(N2.getNode(), N2, Base, Offset)) {
- if (PointerSize == 64) {
- switch (N->getOpcode()) {
- default:
- return false;
- case NVPTXISD::StoreV2:
- Opcode = pickOpcodeForVT(
- EltVT.getSimpleVT().SimpleTy, NVPTX::STV_i8_v2_ari_64,
- NVPTX::STV_i16_v2_ari_64, NVPTX::STV_i32_v2_ari_64,
- NVPTX::STV_i64_v2_ari_64, NVPTX::STV_f16_v2_ari_64,
- NVPTX::STV_f16x2_v2_ari_64, NVPTX::STV_f32_v2_ari_64,
- NVPTX::STV_f64_v2_ari_64);
- break;
- case NVPTXISD::StoreV4:
- Opcode = pickOpcodeForVT(
- EltVT.getSimpleVT().SimpleTy, NVPTX::STV_i8_v4_ari_64,
- NVPTX::STV_i16_v4_ari_64, NVPTX::STV_i32_v4_ari_64, None,
- NVPTX::STV_f16_v4_ari_64, NVPTX::STV_f16x2_v4_ari_64,
- NVPTX::STV_f32_v4_ari_64, None);
- break;
- }
- } else {
- switch (N->getOpcode()) {
- default:
- return false;
- case NVPTXISD::StoreV2:
- Opcode = pickOpcodeForVT(EltVT.getSimpleVT().SimpleTy,
- NVPTX::STV_i8_v2_ari, NVPTX::STV_i16_v2_ari,
- NVPTX::STV_i32_v2_ari, NVPTX::STV_i64_v2_ari,
- NVPTX::STV_f16_v2_ari, NVPTX::STV_f16x2_v2_ari,
- NVPTX::STV_f32_v2_ari, NVPTX::STV_f64_v2_ari);
- break;
- case NVPTXISD::StoreV4:
- Opcode =
- pickOpcodeForVT(EltVT.getSimpleVT().SimpleTy, NVPTX::STV_i8_v4_ari,
- NVPTX::STV_i16_v4_ari, NVPTX::STV_i32_v4_ari, None,
- NVPTX::STV_f16_v4_ari, NVPTX::STV_f16x2_v4_ari,
- NVPTX::STV_f32_v4_ari, None);
- break;
- }
- }
- StOps.push_back(Base);
- StOps.push_back(Offset);
- } else {
- if (PointerSize == 64) {
- switch (N->getOpcode()) {
- default:
- return false;
- case NVPTXISD::StoreV2:
- Opcode = pickOpcodeForVT(
- EltVT.getSimpleVT().SimpleTy, NVPTX::STV_i8_v2_areg_64,
- NVPTX::STV_i16_v2_areg_64, NVPTX::STV_i32_v2_areg_64,
- NVPTX::STV_i64_v2_areg_64, NVPTX::STV_f16_v2_areg_64,
- NVPTX::STV_f16x2_v2_areg_64, NVPTX::STV_f32_v2_areg_64,
- NVPTX::STV_f64_v2_areg_64);
- break;
- case NVPTXISD::StoreV4:
- Opcode = pickOpcodeForVT(
- EltVT.getSimpleVT().SimpleTy, NVPTX::STV_i8_v4_areg_64,
- NVPTX::STV_i16_v4_areg_64, NVPTX::STV_i32_v4_areg_64, None,
- NVPTX::STV_f16_v4_areg_64, NVPTX::STV_f16x2_v4_areg_64,
- NVPTX::STV_f32_v4_areg_64, None);
- break;
- }
- } else {
- switch (N->getOpcode()) {
- default:
- return false;
- case NVPTXISD::StoreV2:
- Opcode =
- pickOpcodeForVT(EltVT.getSimpleVT().SimpleTy, NVPTX::STV_i8_v2_areg,
- NVPTX::STV_i16_v2_areg, NVPTX::STV_i32_v2_areg,
- NVPTX::STV_i64_v2_areg, NVPTX::STV_f16_v2_areg,
- NVPTX::STV_f16x2_v2_areg, NVPTX::STV_f32_v2_areg,
- NVPTX::STV_f64_v2_areg);
- break;
- case NVPTXISD::StoreV4:
- Opcode =
- pickOpcodeForVT(EltVT.getSimpleVT().SimpleTy, NVPTX::STV_i8_v4_areg,
- NVPTX::STV_i16_v4_areg, NVPTX::STV_i32_v4_areg, None,
- NVPTX::STV_f16_v4_areg, NVPTX::STV_f16x2_v4_areg,
- NVPTX::STV_f32_v4_areg, None);
- break;
- }
- }
- StOps.push_back(N2);
- }
- if (!Opcode)
- return false;
- StOps.push_back(Chain);
- ST = CurDAG->getMachineNode(Opcode.getValue(), DL, MVT::Other, StOps);
- MachineMemOperand *MemRef = cast<MemSDNode>(N)->getMemOperand();
- CurDAG->setNodeMemRefs(cast<MachineSDNode>(ST), {MemRef});
- ReplaceNode(N, ST);
- return true;
- }
- bool NVPTXDAGToDAGISel::tryLoadParam(SDNode *Node) {
- SDValue Chain = Node->getOperand(0);
- SDValue Offset = Node->getOperand(2);
- SDValue Flag = Node->getOperand(3);
- SDLoc DL(Node);
- MemSDNode *Mem = cast<MemSDNode>(Node);
- unsigned VecSize;
- switch (Node->getOpcode()) {
- default:
- return false;
- case NVPTXISD::LoadParam:
- VecSize = 1;
- break;
- case NVPTXISD::LoadParamV2:
- VecSize = 2;
- break;
- case NVPTXISD::LoadParamV4:
- VecSize = 4;
- break;
- }
- EVT EltVT = Node->getValueType(0);
- EVT MemVT = Mem->getMemoryVT();
- Optional<unsigned> Opcode;
- switch (VecSize) {
- default:
- return false;
- case 1:
- Opcode = pickOpcodeForVT(MemVT.getSimpleVT().SimpleTy,
- NVPTX::LoadParamMemI8, NVPTX::LoadParamMemI16,
- NVPTX::LoadParamMemI32, NVPTX::LoadParamMemI64,
- NVPTX::LoadParamMemF16, NVPTX::LoadParamMemF16x2,
- NVPTX::LoadParamMemF32, NVPTX::LoadParamMemF64);
- break;
- case 2:
- Opcode =
- pickOpcodeForVT(MemVT.getSimpleVT().SimpleTy, NVPTX::LoadParamMemV2I8,
- NVPTX::LoadParamMemV2I16, NVPTX::LoadParamMemV2I32,
- NVPTX::LoadParamMemV2I64, NVPTX::LoadParamMemV2F16,
- NVPTX::LoadParamMemV2F16x2, NVPTX::LoadParamMemV2F32,
- NVPTX::LoadParamMemV2F64);
- break;
- case 4:
- Opcode = pickOpcodeForVT(
- MemVT.getSimpleVT().SimpleTy, NVPTX::LoadParamMemV4I8,
- NVPTX::LoadParamMemV4I16, NVPTX::LoadParamMemV4I32, None,
- NVPTX::LoadParamMemV4F16, NVPTX::LoadParamMemV4F16x2,
- NVPTX::LoadParamMemV4F32, None);
- break;
- }
- if (!Opcode)
- return false;
- SDVTList VTs;
- if (VecSize == 1) {
- VTs = CurDAG->getVTList(EltVT, MVT::Other, MVT::Glue);
- } else if (VecSize == 2) {
- VTs = CurDAG->getVTList(EltVT, EltVT, MVT::Other, MVT::Glue);
- } else {
- EVT EVTs[] = { EltVT, EltVT, EltVT, EltVT, MVT::Other, MVT::Glue };
- VTs = CurDAG->getVTList(EVTs);
- }
- unsigned OffsetVal = cast<ConstantSDNode>(Offset)->getZExtValue();
- SmallVector<SDValue, 2> Ops;
- Ops.push_back(CurDAG->getTargetConstant(OffsetVal, DL, MVT::i32));
- Ops.push_back(Chain);
- Ops.push_back(Flag);
- ReplaceNode(Node, CurDAG->getMachineNode(Opcode.getValue(), DL, VTs, Ops));
- return true;
- }
- bool NVPTXDAGToDAGISel::tryStoreRetval(SDNode *N) {
- SDLoc DL(N);
- SDValue Chain = N->getOperand(0);
- SDValue Offset = N->getOperand(1);
- unsigned OffsetVal = cast<ConstantSDNode>(Offset)->getZExtValue();
- MemSDNode *Mem = cast<MemSDNode>(N);
- // How many elements do we have?
- unsigned NumElts = 1;
- switch (N->getOpcode()) {
- default:
- return false;
- case NVPTXISD::StoreRetval:
- NumElts = 1;
- break;
- case NVPTXISD::StoreRetvalV2:
- NumElts = 2;
- break;
- case NVPTXISD::StoreRetvalV4:
- NumElts = 4;
- break;
- }
- // Build vector of operands
- SmallVector<SDValue, 6> Ops;
- for (unsigned i = 0; i < NumElts; ++i)
- Ops.push_back(N->getOperand(i + 2));
- Ops.push_back(CurDAG->getTargetConstant(OffsetVal, DL, MVT::i32));
- Ops.push_back(Chain);
- // Determine target opcode
- // If we have an i1, use an 8-bit store. The lowering code in
- // NVPTXISelLowering will have already emitted an upcast.
- Optional<unsigned> Opcode = 0;
- switch (NumElts) {
- default:
- return false;
- case 1:
- Opcode = pickOpcodeForVT(Mem->getMemoryVT().getSimpleVT().SimpleTy,
- NVPTX::StoreRetvalI8, NVPTX::StoreRetvalI16,
- NVPTX::StoreRetvalI32, NVPTX::StoreRetvalI64,
- NVPTX::StoreRetvalF16, NVPTX::StoreRetvalF16x2,
- NVPTX::StoreRetvalF32, NVPTX::StoreRetvalF64);
- break;
- case 2:
- Opcode = pickOpcodeForVT(Mem->getMemoryVT().getSimpleVT().SimpleTy,
- NVPTX::StoreRetvalV2I8, NVPTX::StoreRetvalV2I16,
- NVPTX::StoreRetvalV2I32, NVPTX::StoreRetvalV2I64,
- NVPTX::StoreRetvalV2F16, NVPTX::StoreRetvalV2F16x2,
- NVPTX::StoreRetvalV2F32, NVPTX::StoreRetvalV2F64);
- break;
- case 4:
- Opcode = pickOpcodeForVT(Mem->getMemoryVT().getSimpleVT().SimpleTy,
- NVPTX::StoreRetvalV4I8, NVPTX::StoreRetvalV4I16,
- NVPTX::StoreRetvalV4I32, None,
- NVPTX::StoreRetvalV4F16, NVPTX::StoreRetvalV4F16x2,
- NVPTX::StoreRetvalV4F32, None);
- break;
- }
- if (!Opcode)
- return false;
- SDNode *Ret = CurDAG->getMachineNode(Opcode.getValue(), DL, MVT::Other, Ops);
- MachineMemOperand *MemRef = cast<MemSDNode>(N)->getMemOperand();
- CurDAG->setNodeMemRefs(cast<MachineSDNode>(Ret), {MemRef});
- ReplaceNode(N, Ret);
- return true;
- }
- bool NVPTXDAGToDAGISel::tryStoreParam(SDNode *N) {
- SDLoc DL(N);
- SDValue Chain = N->getOperand(0);
- SDValue Param = N->getOperand(1);
- unsigned ParamVal = cast<ConstantSDNode>(Param)->getZExtValue();
- SDValue Offset = N->getOperand(2);
- unsigned OffsetVal = cast<ConstantSDNode>(Offset)->getZExtValue();
- MemSDNode *Mem = cast<MemSDNode>(N);
- SDValue Flag = N->getOperand(N->getNumOperands() - 1);
- // How many elements do we have?
- unsigned NumElts = 1;
- switch (N->getOpcode()) {
- default:
- return false;
- case NVPTXISD::StoreParamU32:
- case NVPTXISD::StoreParamS32:
- case NVPTXISD::StoreParam:
- NumElts = 1;
- break;
- case NVPTXISD::StoreParamV2:
- NumElts = 2;
- break;
- case NVPTXISD::StoreParamV4:
- NumElts = 4;
- break;
- }
- // Build vector of operands
- SmallVector<SDValue, 8> Ops;
- for (unsigned i = 0; i < NumElts; ++i)
- Ops.push_back(N->getOperand(i + 3));
- Ops.push_back(CurDAG->getTargetConstant(ParamVal, DL, MVT::i32));
- Ops.push_back(CurDAG->getTargetConstant(OffsetVal, DL, MVT::i32));
- Ops.push_back(Chain);
- Ops.push_back(Flag);
- // Determine target opcode
- // If we have an i1, use an 8-bit store. The lowering code in
- // NVPTXISelLowering will have already emitted an upcast.
- Optional<unsigned> Opcode = 0;
- switch (N->getOpcode()) {
- default:
- switch (NumElts) {
- default:
- return false;
- case 1:
- Opcode = pickOpcodeForVT(Mem->getMemoryVT().getSimpleVT().SimpleTy,
- NVPTX::StoreParamI8, NVPTX::StoreParamI16,
- NVPTX::StoreParamI32, NVPTX::StoreParamI64,
- NVPTX::StoreParamF16, NVPTX::StoreParamF16x2,
- NVPTX::StoreParamF32, NVPTX::StoreParamF64);
- break;
- case 2:
- Opcode = pickOpcodeForVT(Mem->getMemoryVT().getSimpleVT().SimpleTy,
- NVPTX::StoreParamV2I8, NVPTX::StoreParamV2I16,
- NVPTX::StoreParamV2I32, NVPTX::StoreParamV2I64,
- NVPTX::StoreParamV2F16, NVPTX::StoreParamV2F16x2,
- NVPTX::StoreParamV2F32, NVPTX::StoreParamV2F64);
- break;
- case 4:
- Opcode = pickOpcodeForVT(Mem->getMemoryVT().getSimpleVT().SimpleTy,
- NVPTX::StoreParamV4I8, NVPTX::StoreParamV4I16,
- NVPTX::StoreParamV4I32, None,
- NVPTX::StoreParamV4F16, NVPTX::StoreParamV4F16x2,
- NVPTX::StoreParamV4F32, None);
- break;
- }
- if (!Opcode)
- return false;
- break;
- // Special case: if we have a sign-extend/zero-extend node, insert the
- // conversion instruction first, and use that as the value operand to
- // the selected StoreParam node.
- case NVPTXISD::StoreParamU32: {
- Opcode = NVPTX::StoreParamI32;
- SDValue CvtNone = CurDAG->getTargetConstant(NVPTX::PTXCvtMode::NONE, DL,
- MVT::i32);
- SDNode *Cvt = CurDAG->getMachineNode(NVPTX::CVT_u32_u16, DL,
- MVT::i32, Ops[0], CvtNone);
- Ops[0] = SDValue(Cvt, 0);
- break;
- }
- case NVPTXISD::StoreParamS32: {
- Opcode = NVPTX::StoreParamI32;
- SDValue CvtNone = CurDAG->getTargetConstant(NVPTX::PTXCvtMode::NONE, DL,
- MVT::i32);
- SDNode *Cvt = CurDAG->getMachineNode(NVPTX::CVT_s32_s16, DL,
- MVT::i32, Ops[0], CvtNone);
- Ops[0] = SDValue(Cvt, 0);
- break;
- }
- }
- SDVTList RetVTs = CurDAG->getVTList(MVT::Other, MVT::Glue);
- SDNode *Ret =
- CurDAG->getMachineNode(Opcode.getValue(), DL, RetVTs, Ops);
- MachineMemOperand *MemRef = cast<MemSDNode>(N)->getMemOperand();
- CurDAG->setNodeMemRefs(cast<MachineSDNode>(Ret), {MemRef});
- ReplaceNode(N, Ret);
- return true;
- }
- bool NVPTXDAGToDAGISel::tryTextureIntrinsic(SDNode *N) {
- unsigned Opc = 0;
- switch (N->getOpcode()) {
- default: return false;
- case NVPTXISD::Tex1DFloatS32:
- Opc = NVPTX::TEX_1D_F32_S32_RR;
- break;
- case NVPTXISD::Tex1DFloatFloat:
- Opc = NVPTX::TEX_1D_F32_F32_RR;
- break;
- case NVPTXISD::Tex1DFloatFloatLevel:
- Opc = NVPTX::TEX_1D_F32_F32_LEVEL_RR;
- break;
- case NVPTXISD::Tex1DFloatFloatGrad:
- Opc = NVPTX::TEX_1D_F32_F32_GRAD_RR;
- break;
- case NVPTXISD::Tex1DS32S32:
- Opc = NVPTX::TEX_1D_S32_S32_RR;
- break;
- case NVPTXISD::Tex1DS32Float:
- Opc = NVPTX::TEX_1D_S32_F32_RR;
- break;
- case NVPTXISD::Tex1DS32FloatLevel:
- Opc = NVPTX::TEX_1D_S32_F32_LEVEL_RR;
- break;
- case NVPTXISD::Tex1DS32FloatGrad:
- Opc = NVPTX::TEX_1D_S32_F32_GRAD_RR;
- break;
- case NVPTXISD::Tex1DU32S32:
- Opc = NVPTX::TEX_1D_U32_S32_RR;
- break;
- case NVPTXISD::Tex1DU32Float:
- Opc = NVPTX::TEX_1D_U32_F32_RR;
- break;
- case NVPTXISD::Tex1DU32FloatLevel:
- Opc = NVPTX::TEX_1D_U32_F32_LEVEL_RR;
- break;
- case NVPTXISD::Tex1DU32FloatGrad:
- Opc = NVPTX::TEX_1D_U32_F32_GRAD_RR;
- break;
- case NVPTXISD::Tex1DArrayFloatS32:
- Opc = NVPTX::TEX_1D_ARRAY_F32_S32_RR;
- break;
- case NVPTXISD::Tex1DArrayFloatFloat:
- Opc = NVPTX::TEX_1D_ARRAY_F32_F32_RR;
- break;
- case NVPTXISD::Tex1DArrayFloatFloatLevel:
- Opc = NVPTX::TEX_1D_ARRAY_F32_F32_LEVEL_RR;
- break;
- case NVPTXISD::Tex1DArrayFloatFloatGrad:
- Opc = NVPTX::TEX_1D_ARRAY_F32_F32_GRAD_RR;
- break;
- case NVPTXISD::Tex1DArrayS32S32:
- Opc = NVPTX::TEX_1D_ARRAY_S32_S32_RR;
- break;
- case NVPTXISD::Tex1DArrayS32Float:
- Opc = NVPTX::TEX_1D_ARRAY_S32_F32_RR;
- break;
- case NVPTXISD::Tex1DArrayS32FloatLevel:
- Opc = NVPTX::TEX_1D_ARRAY_S32_F32_LEVEL_RR;
- break;
- case NVPTXISD::Tex1DArrayS32FloatGrad:
- Opc = NVPTX::TEX_1D_ARRAY_S32_F32_GRAD_RR;
- break;
- case NVPTXISD::Tex1DArrayU32S32:
- Opc = NVPTX::TEX_1D_ARRAY_U32_S32_RR;
- break;
- case NVPTXISD::Tex1DArrayU32Float:
- Opc = NVPTX::TEX_1D_ARRAY_U32_F32_RR;
- break;
- case NVPTXISD::Tex1DArrayU32FloatLevel:
- Opc = NVPTX::TEX_1D_ARRAY_U32_F32_LEVEL_RR;
- break;
- case NVPTXISD::Tex1DArrayU32FloatGrad:
- Opc = NVPTX::TEX_1D_ARRAY_U32_F32_GRAD_RR;
- break;
- case NVPTXISD::Tex2DFloatS32:
- Opc = NVPTX::TEX_2D_F32_S32_RR;
- break;
- case NVPTXISD::Tex2DFloatFloat:
- Opc = NVPTX::TEX_2D_F32_F32_RR;
- break;
- case NVPTXISD::Tex2DFloatFloatLevel:
- Opc = NVPTX::TEX_2D_F32_F32_LEVEL_RR;
- break;
- case NVPTXISD::Tex2DFloatFloatGrad:
- Opc = NVPTX::TEX_2D_F32_F32_GRAD_RR;
- break;
- case NVPTXISD::Tex2DS32S32:
- Opc = NVPTX::TEX_2D_S32_S32_RR;
- break;
- case NVPTXISD::Tex2DS32Float:
- Opc = NVPTX::TEX_2D_S32_F32_RR;
- break;
- case NVPTXISD::Tex2DS32FloatLevel:
- Opc = NVPTX::TEX_2D_S32_F32_LEVEL_RR;
- break;
- case NVPTXISD::Tex2DS32FloatGrad:
- Opc = NVPTX::TEX_2D_S32_F32_GRAD_RR;
- break;
- case NVPTXISD::Tex2DU32S32:
- Opc = NVPTX::TEX_2D_U32_S32_RR;
- break;
- case NVPTXISD::Tex2DU32Float:
- Opc = NVPTX::TEX_2D_U32_F32_RR;
- break;
- case NVPTXISD::Tex2DU32FloatLevel:
- Opc = NVPTX::TEX_2D_U32_F32_LEVEL_RR;
- break;
- case NVPTXISD::Tex2DU32FloatGrad:
- Opc = NVPTX::TEX_2D_U32_F32_GRAD_RR;
- break;
- case NVPTXISD::Tex2DArrayFloatS32:
- Opc = NVPTX::TEX_2D_ARRAY_F32_S32_RR;
- break;
- case NVPTXISD::Tex2DArrayFloatFloat:
- Opc = NVPTX::TEX_2D_ARRAY_F32_F32_RR;
- break;
- case NVPTXISD::Tex2DArrayFloatFloatLevel:
- Opc = NVPTX::TEX_2D_ARRAY_F32_F32_LEVEL_RR;
- break;
- case NVPTXISD::Tex2DArrayFloatFloatGrad:
- Opc = NVPTX::TEX_2D_ARRAY_F32_F32_GRAD_RR;
- break;
- case NVPTXISD::Tex2DArrayS32S32:
- Opc = NVPTX::TEX_2D_ARRAY_S32_S32_RR;
- break;
- case NVPTXISD::Tex2DArrayS32Float:
- Opc = NVPTX::TEX_2D_ARRAY_S32_F32_RR;
- break;
- case NVPTXISD::Tex2DArrayS32FloatLevel:
- Opc = NVPTX::TEX_2D_ARRAY_S32_F32_LEVEL_RR;
- break;
- case NVPTXISD::Tex2DArrayS32FloatGrad:
- Opc = NVPTX::TEX_2D_ARRAY_S32_F32_GRAD_RR;
- break;
- case NVPTXISD::Tex2DArrayU32S32:
- Opc = NVPTX::TEX_2D_ARRAY_U32_S32_RR;
- break;
- case NVPTXISD::Tex2DArrayU32Float:
- Opc = NVPTX::TEX_2D_ARRAY_U32_F32_RR;
- break;
- case NVPTXISD::Tex2DArrayU32FloatLevel:
- Opc = NVPTX::TEX_2D_ARRAY_U32_F32_LEVEL_RR;
- break;
- case NVPTXISD::Tex2DArrayU32FloatGrad:
- Opc = NVPTX::TEX_2D_ARRAY_U32_F32_GRAD_RR;
- break;
- case NVPTXISD::Tex3DFloatS32:
- Opc = NVPTX::TEX_3D_F32_S32_RR;
- break;
- case NVPTXISD::Tex3DFloatFloat:
- Opc = NVPTX::TEX_3D_F32_F32_RR;
- break;
- case NVPTXISD::Tex3DFloatFloatLevel:
- Opc = NVPTX::TEX_3D_F32_F32_LEVEL_RR;
- break;
- case NVPTXISD::Tex3DFloatFloatGrad:
- Opc = NVPTX::TEX_3D_F32_F32_GRAD_RR;
- break;
- case NVPTXISD::Tex3DS32S32:
- Opc = NVPTX::TEX_3D_S32_S32_RR;
- break;
- case NVPTXISD::Tex3DS32Float:
- Opc = NVPTX::TEX_3D_S32_F32_RR;
- break;
- case NVPTXISD::Tex3DS32FloatLevel:
- Opc = NVPTX::TEX_3D_S32_F32_LEVEL_RR;
- break;
- case NVPTXISD::Tex3DS32FloatGrad:
- Opc = NVPTX::TEX_3D_S32_F32_GRAD_RR;
- break;
- case NVPTXISD::Tex3DU32S32:
- Opc = NVPTX::TEX_3D_U32_S32_RR;
- break;
- case NVPTXISD::Tex3DU32Float:
- Opc = NVPTX::TEX_3D_U32_F32_RR;
- break;
- case NVPTXISD::Tex3DU32FloatLevel:
- Opc = NVPTX::TEX_3D_U32_F32_LEVEL_RR;
- break;
- case NVPTXISD::Tex3DU32FloatGrad:
- Opc = NVPTX::TEX_3D_U32_F32_GRAD_RR;
- break;
- case NVPTXISD::TexCubeFloatFloat:
- Opc = NVPTX::TEX_CUBE_F32_F32_RR;
- break;
- case NVPTXISD::TexCubeFloatFloatLevel:
- Opc = NVPTX::TEX_CUBE_F32_F32_LEVEL_RR;
- break;
- case NVPTXISD::TexCubeS32Float:
- Opc = NVPTX::TEX_CUBE_S32_F32_RR;
- break;
- case NVPTXISD::TexCubeS32FloatLevel:
- Opc = NVPTX::TEX_CUBE_S32_F32_LEVEL_RR;
- break;
- case NVPTXISD::TexCubeU32Float:
- Opc = NVPTX::TEX_CUBE_U32_F32_RR;
- break;
- case NVPTXISD::TexCubeU32FloatLevel:
- Opc = NVPTX::TEX_CUBE_U32_F32_LEVEL_RR;
- break;
- case NVPTXISD::TexCubeArrayFloatFloat:
- Opc = NVPTX::TEX_CUBE_ARRAY_F32_F32_RR;
- break;
- case NVPTXISD::TexCubeArrayFloatFloatLevel:
- Opc = NVPTX::TEX_CUBE_ARRAY_F32_F32_LEVEL_RR;
- break;
- case NVPTXISD::TexCubeArrayS32Float:
- Opc = NVPTX::TEX_CUBE_ARRAY_S32_F32_RR;
- break;
- case NVPTXISD::TexCubeArrayS32FloatLevel:
- Opc = NVPTX::TEX_CUBE_ARRAY_S32_F32_LEVEL_RR;
- break;
- case NVPTXISD::TexCubeArrayU32Float:
- Opc = NVPTX::TEX_CUBE_ARRAY_U32_F32_RR;
- break;
- case NVPTXISD::TexCubeArrayU32FloatLevel:
- Opc = NVPTX::TEX_CUBE_ARRAY_U32_F32_LEVEL_RR;
- break;
- case NVPTXISD::Tld4R2DFloatFloat:
- Opc = NVPTX::TLD4_R_2D_F32_F32_RR;
- break;
- case NVPTXISD::Tld4G2DFloatFloat:
- Opc = NVPTX::TLD4_G_2D_F32_F32_RR;
- break;
- case NVPTXISD::Tld4B2DFloatFloat:
- Opc = NVPTX::TLD4_B_2D_F32_F32_RR;
- break;
- case NVPTXISD::Tld4A2DFloatFloat:
- Opc = NVPTX::TLD4_A_2D_F32_F32_RR;
- break;
- case NVPTXISD::Tld4R2DS64Float:
- Opc = NVPTX::TLD4_R_2D_S32_F32_RR;
- break;
- case NVPTXISD::Tld4G2DS64Float:
- Opc = NVPTX::TLD4_G_2D_S32_F32_RR;
- break;
- case NVPTXISD::Tld4B2DS64Float:
- Opc = NVPTX::TLD4_B_2D_S32_F32_RR;
- break;
- case NVPTXISD::Tld4A2DS64Float:
- Opc = NVPTX::TLD4_A_2D_S32_F32_RR;
- break;
- case NVPTXISD::Tld4R2DU64Float:
- Opc = NVPTX::TLD4_R_2D_U32_F32_RR;
- break;
- case NVPTXISD::Tld4G2DU64Float:
- Opc = NVPTX::TLD4_G_2D_U32_F32_RR;
- break;
- case NVPTXISD::Tld4B2DU64Float:
- Opc = NVPTX::TLD4_B_2D_U32_F32_RR;
- break;
- case NVPTXISD::Tld4A2DU64Float:
- Opc = NVPTX::TLD4_A_2D_U32_F32_RR;
- break;
- case NVPTXISD::TexUnified1DFloatS32:
- Opc = NVPTX::TEX_UNIFIED_1D_F32_S32_R;
- break;
- case NVPTXISD::TexUnified1DFloatFloat:
- Opc = NVPTX::TEX_UNIFIED_1D_F32_F32_R;
- break;
- case NVPTXISD::TexUnified1DFloatFloatLevel:
- Opc = NVPTX::TEX_UNIFIED_1D_F32_F32_LEVEL_R;
- break;
- case NVPTXISD::TexUnified1DFloatFloatGrad:
- Opc = NVPTX::TEX_UNIFIED_1D_F32_F32_GRAD_R;
- break;
- case NVPTXISD::TexUnified1DS32S32:
- Opc = NVPTX::TEX_UNIFIED_1D_S32_S32_R;
- break;
- case NVPTXISD::TexUnified1DS32Float:
- Opc = NVPTX::TEX_UNIFIED_1D_S32_F32_R;
- break;
- case NVPTXISD::TexUnified1DS32FloatLevel:
- Opc = NVPTX::TEX_UNIFIED_1D_S32_F32_LEVEL_R;
- break;
- case NVPTXISD::TexUnified1DS32FloatGrad:
- Opc = NVPTX::TEX_UNIFIED_1D_S32_F32_GRAD_R;
- break;
- case NVPTXISD::TexUnified1DU32S32:
- Opc = NVPTX::TEX_UNIFIED_1D_U32_S32_R;
- break;
- case NVPTXISD::TexUnified1DU32Float:
- Opc = NVPTX::TEX_UNIFIED_1D_U32_F32_R;
- break;
- case NVPTXISD::TexUnified1DU32FloatLevel:
- Opc = NVPTX::TEX_UNIFIED_1D_U32_F32_LEVEL_R;
- break;
- case NVPTXISD::TexUnified1DU32FloatGrad:
- Opc = NVPTX::TEX_UNIFIED_1D_U32_F32_GRAD_R;
- break;
- case NVPTXISD::TexUnified1DArrayFloatS32:
- Opc = NVPTX::TEX_UNIFIED_1D_ARRAY_F32_S32_R;
- break;
- case NVPTXISD::TexUnified1DArrayFloatFloat:
- Opc = NVPTX::TEX_UNIFIED_1D_ARRAY_F32_F32_R;
- break;
- case NVPTXISD::TexUnified1DArrayFloatFloatLevel:
- Opc = NVPTX::TEX_UNIFIED_1D_ARRAY_F32_F32_LEVEL_R;
- break;
- case NVPTXISD::TexUnified1DArrayFloatFloatGrad:
- Opc = NVPTX::TEX_UNIFIED_1D_ARRAY_F32_F32_GRAD_R;
- break;
- case NVPTXISD::TexUnified1DArrayS32S32:
- Opc = NVPTX::TEX_UNIFIED_1D_ARRAY_S32_S32_R;
- break;
- case NVPTXISD::TexUnified1DArrayS32Float:
- Opc = NVPTX::TEX_UNIFIED_1D_ARRAY_S32_F32_R;
- break;
- case NVPTXISD::TexUnified1DArrayS32FloatLevel:
- Opc = NVPTX::TEX_UNIFIED_1D_ARRAY_S32_F32_LEVEL_R;
- break;
- case NVPTXISD::TexUnified1DArrayS32FloatGrad:
- Opc = NVPTX::TEX_UNIFIED_1D_ARRAY_S32_F32_GRAD_R;
- break;
- case NVPTXISD::TexUnified1DArrayU32S32:
- Opc = NVPTX::TEX_UNIFIED_1D_ARRAY_U32_S32_R;
- break;
- case NVPTXISD::TexUnified1DArrayU32Float:
- Opc = NVPTX::TEX_UNIFIED_1D_ARRAY_U32_F32_R;
- break;
- case NVPTXISD::TexUnified1DArrayU32FloatLevel:
- Opc = NVPTX::TEX_UNIFIED_1D_ARRAY_U32_F32_LEVEL_R;
- break;
- case NVPTXISD::TexUnified1DArrayU32FloatGrad:
- Opc = NVPTX::TEX_UNIFIED_1D_ARRAY_U32_F32_GRAD_R;
- break;
- case NVPTXISD::TexUnified2DFloatS32:
- Opc = NVPTX::TEX_UNIFIED_2D_F32_S32_R;
- break;
- case NVPTXISD::TexUnified2DFloatFloat:
- Opc = NVPTX::TEX_UNIFIED_2D_F32_F32_R;
- break;
- case NVPTXISD::TexUnified2DFloatFloatLevel:
- Opc = NVPTX::TEX_UNIFIED_2D_F32_F32_LEVEL_R;
- break;
- case NVPTXISD::TexUnified2DFloatFloatGrad:
- Opc = NVPTX::TEX_UNIFIED_2D_F32_F32_GRAD_R;
- break;
- case NVPTXISD::TexUnified2DS32S32:
- Opc = NVPTX::TEX_UNIFIED_2D_S32_S32_R;
- break;
- case NVPTXISD::TexUnified2DS32Float:
- Opc = NVPTX::TEX_UNIFIED_2D_S32_F32_R;
- break;
- case NVPTXISD::TexUnified2DS32FloatLevel:
- Opc = NVPTX::TEX_UNIFIED_2D_S32_F32_LEVEL_R;
- break;
- case NVPTXISD::TexUnified2DS32FloatGrad:
- Opc = NVPTX::TEX_UNIFIED_2D_S32_F32_GRAD_R;
- break;
- case NVPTXISD::TexUnified2DU32S32:
- Opc = NVPTX::TEX_UNIFIED_2D_U32_S32_R;
- break;
- case NVPTXISD::TexUnified2DU32Float:
- Opc = NVPTX::TEX_UNIFIED_2D_U32_F32_R;
- break;
- case NVPTXISD::TexUnified2DU32FloatLevel:
- Opc = NVPTX::TEX_UNIFIED_2D_U32_F32_LEVEL_R;
- break;
- case NVPTXISD::TexUnified2DU32FloatGrad:
- Opc = NVPTX::TEX_UNIFIED_2D_U32_F32_GRAD_R;
- break;
- case NVPTXISD::TexUnified2DArrayFloatS32:
- Opc = NVPTX::TEX_UNIFIED_2D_ARRAY_F32_S32_R;
- break;
- case NVPTXISD::TexUnified2DArrayFloatFloat:
- Opc = NVPTX::TEX_UNIFIED_2D_ARRAY_F32_F32_R;
- break;
- case NVPTXISD::TexUnified2DArrayFloatFloatLevel:
- Opc = NVPTX::TEX_UNIFIED_2D_ARRAY_F32_F32_LEVEL_R;
- break;
- case NVPTXISD::TexUnified2DArrayFloatFloatGrad:
- Opc = NVPTX::TEX_UNIFIED_2D_ARRAY_F32_F32_GRAD_R;
- break;
- case NVPTXISD::TexUnified2DArrayS32S32:
- Opc = NVPTX::TEX_UNIFIED_2D_ARRAY_S32_S32_R;
- break;
- case NVPTXISD::TexUnified2DArrayS32Float:
- Opc = NVPTX::TEX_UNIFIED_2D_ARRAY_S32_F32_R;
- break;
- case NVPTXISD::TexUnified2DArrayS32FloatLevel:
- Opc = NVPTX::TEX_UNIFIED_2D_ARRAY_S32_F32_LEVEL_R;
- break;
- case NVPTXISD::TexUnified2DArrayS32FloatGrad:
- Opc = NVPTX::TEX_UNIFIED_2D_ARRAY_S32_F32_GRAD_R;
- break;
- case NVPTXISD::TexUnified2DArrayU32S32:
- Opc = NVPTX::TEX_UNIFIED_2D_ARRAY_U32_S32_R;
- break;
- case NVPTXISD::TexUnified2DArrayU32Float:
- Opc = NVPTX::TEX_UNIFIED_2D_ARRAY_U32_F32_R;
- break;
- case NVPTXISD::TexUnified2DArrayU32FloatLevel:
- Opc = NVPTX::TEX_UNIFIED_2D_ARRAY_U32_F32_LEVEL_R;
- break;
- case NVPTXISD::TexUnified2DArrayU32FloatGrad:
- Opc = NVPTX::TEX_UNIFIED_2D_ARRAY_U32_F32_GRAD_R;
- break;
- case NVPTXISD::TexUnified3DFloatS32:
- Opc = NVPTX::TEX_UNIFIED_3D_F32_S32_R;
- break;
- case NVPTXISD::TexUnified3DFloatFloat:
- Opc = NVPTX::TEX_UNIFIED_3D_F32_F32_R;
- break;
- case NVPTXISD::TexUnified3DFloatFloatLevel:
- Opc = NVPTX::TEX_UNIFIED_3D_F32_F32_LEVEL_R;
- break;
- case NVPTXISD::TexUnified3DFloatFloatGrad:
- Opc = NVPTX::TEX_UNIFIED_3D_F32_F32_GRAD_R;
- break;
- case NVPTXISD::TexUnified3DS32S32:
- Opc = NVPTX::TEX_UNIFIED_3D_S32_S32_R;
- break;
- case NVPTXISD::TexUnified3DS32Float:
- Opc = NVPTX::TEX_UNIFIED_3D_S32_F32_R;
- break;
- case NVPTXISD::TexUnified3DS32FloatLevel:
- Opc = NVPTX::TEX_UNIFIED_3D_S32_F32_LEVEL_R;
- break;
- case NVPTXISD::TexUnified3DS32FloatGrad:
- Opc = NVPTX::TEX_UNIFIED_3D_S32_F32_GRAD_R;
- break;
- case NVPTXISD::TexUnified3DU32S32:
- Opc = NVPTX::TEX_UNIFIED_3D_U32_S32_R;
- break;
- case NVPTXISD::TexUnified3DU32Float:
- Opc = NVPTX::TEX_UNIFIED_3D_U32_F32_R;
- break;
- case NVPTXISD::TexUnified3DU32FloatLevel:
- Opc = NVPTX::TEX_UNIFIED_3D_U32_F32_LEVEL_R;
- break;
- case NVPTXISD::TexUnified3DU32FloatGrad:
- Opc = NVPTX::TEX_UNIFIED_3D_U32_F32_GRAD_R;
- break;
- case NVPTXISD::TexUnifiedCubeFloatFloat:
- Opc = NVPTX::TEX_UNIFIED_CUBE_F32_F32_R;
- break;
- case NVPTXISD::TexUnifiedCubeFloatFloatLevel:
- Opc = NVPTX::TEX_UNIFIED_CUBE_F32_F32_LEVEL_R;
- break;
- case NVPTXISD::TexUnifiedCubeS32Float:
- Opc = NVPTX::TEX_UNIFIED_CUBE_S32_F32_R;
- break;
- case NVPTXISD::TexUnifiedCubeS32FloatLevel:
- Opc = NVPTX::TEX_UNIFIED_CUBE_S32_F32_LEVEL_R;
- break;
- case NVPTXISD::TexUnifiedCubeU32Float:
- Opc = NVPTX::TEX_UNIFIED_CUBE_U32_F32_R;
- break;
- case NVPTXISD::TexUnifiedCubeU32FloatLevel:
- Opc = NVPTX::TEX_UNIFIED_CUBE_U32_F32_LEVEL_R;
- break;
- case NVPTXISD::TexUnifiedCubeArrayFloatFloat:
- Opc = NVPTX::TEX_UNIFIED_CUBE_ARRAY_F32_F32_R;
- break;
- case NVPTXISD::TexUnifiedCubeArrayFloatFloatLevel:
- Opc = NVPTX::TEX_UNIFIED_CUBE_ARRAY_F32_F32_LEVEL_R;
- break;
- case NVPTXISD::TexUnifiedCubeArrayS32Float:
- Opc = NVPTX::TEX_UNIFIED_CUBE_ARRAY_S32_F32_R;
- break;
- case NVPTXISD::TexUnifiedCubeArrayS32FloatLevel:
- Opc = NVPTX::TEX_UNIFIED_CUBE_ARRAY_S32_F32_LEVEL_R;
- break;
- case NVPTXISD::TexUnifiedCubeArrayU32Float:
- Opc = NVPTX::TEX_UNIFIED_CUBE_ARRAY_U32_F32_R;
- break;
- case NVPTXISD::TexUnifiedCubeArrayU32FloatLevel:
- Opc = NVPTX::TEX_UNIFIED_CUBE_ARRAY_U32_F32_LEVEL_R;
- break;
- case NVPTXISD::Tld4UnifiedR2DFloatFloat:
- Opc = NVPTX::TLD4_UNIFIED_R_2D_F32_F32_R;
- break;
- case NVPTXISD::Tld4UnifiedG2DFloatFloat:
- Opc = NVPTX::TLD4_UNIFIED_G_2D_F32_F32_R;
- break;
- case NVPTXISD::Tld4UnifiedB2DFloatFloat:
- Opc = NVPTX::TLD4_UNIFIED_B_2D_F32_F32_R;
- break;
- case NVPTXISD::Tld4UnifiedA2DFloatFloat:
- Opc = NVPTX::TLD4_UNIFIED_A_2D_F32_F32_R;
- break;
- case NVPTXISD::Tld4UnifiedR2DS64Float:
- Opc = NVPTX::TLD4_UNIFIED_R_2D_S32_F32_R;
- break;
- case NVPTXISD::Tld4UnifiedG2DS64Float:
- Opc = NVPTX::TLD4_UNIFIED_G_2D_S32_F32_R;
- break;
- case NVPTXISD::Tld4UnifiedB2DS64Float:
- Opc = NVPTX::TLD4_UNIFIED_B_2D_S32_F32_R;
- break;
- case NVPTXISD::Tld4UnifiedA2DS64Float:
- Opc = NVPTX::TLD4_UNIFIED_A_2D_S32_F32_R;
- break;
- case NVPTXISD::Tld4UnifiedR2DU64Float:
- Opc = NVPTX::TLD4_UNIFIED_R_2D_U32_F32_R;
- break;
- case NVPTXISD::Tld4UnifiedG2DU64Float:
- Opc = NVPTX::TLD4_UNIFIED_G_2D_U32_F32_R;
- break;
- case NVPTXISD::Tld4UnifiedB2DU64Float:
- Opc = NVPTX::TLD4_UNIFIED_B_2D_U32_F32_R;
- break;
- case NVPTXISD::Tld4UnifiedA2DU64Float:
- Opc = NVPTX::TLD4_UNIFIED_A_2D_U32_F32_R;
- break;
- }
- // Copy over operands
- SmallVector<SDValue, 8> Ops(drop_begin(N->ops()));
- Ops.push_back(N->getOperand(0)); // Move chain to the back.
- ReplaceNode(N, CurDAG->getMachineNode(Opc, SDLoc(N), N->getVTList(), Ops));
- return true;
- }
- bool NVPTXDAGToDAGISel::trySurfaceIntrinsic(SDNode *N) {
- unsigned Opc = 0;
- switch (N->getOpcode()) {
- default: return false;
- case NVPTXISD::Suld1DI8Clamp:
- Opc = NVPTX::SULD_1D_I8_CLAMP_R;
- break;
- case NVPTXISD::Suld1DI16Clamp:
- Opc = NVPTX::SULD_1D_I16_CLAMP_R;
- break;
- case NVPTXISD::Suld1DI32Clamp:
- Opc = NVPTX::SULD_1D_I32_CLAMP_R;
- break;
- case NVPTXISD::Suld1DI64Clamp:
- Opc = NVPTX::SULD_1D_I64_CLAMP_R;
- break;
- case NVPTXISD::Suld1DV2I8Clamp:
- Opc = NVPTX::SULD_1D_V2I8_CLAMP_R;
- break;
- case NVPTXISD::Suld1DV2I16Clamp:
- Opc = NVPTX::SULD_1D_V2I16_CLAMP_R;
- break;
- case NVPTXISD::Suld1DV2I32Clamp:
- Opc = NVPTX::SULD_1D_V2I32_CLAMP_R;
- break;
- case NVPTXISD::Suld1DV2I64Clamp:
- Opc = NVPTX::SULD_1D_V2I64_CLAMP_R;
- break;
- case NVPTXISD::Suld1DV4I8Clamp:
- Opc = NVPTX::SULD_1D_V4I8_CLAMP_R;
- break;
- case NVPTXISD::Suld1DV4I16Clamp:
- Opc = NVPTX::SULD_1D_V4I16_CLAMP_R;
- break;
- case NVPTXISD::Suld1DV4I32Clamp:
- Opc = NVPTX::SULD_1D_V4I32_CLAMP_R;
- break;
- case NVPTXISD::Suld1DArrayI8Clamp:
- Opc = NVPTX::SULD_1D_ARRAY_I8_CLAMP_R;
- break;
- case NVPTXISD::Suld1DArrayI16Clamp:
- Opc = NVPTX::SULD_1D_ARRAY_I16_CLAMP_R;
- break;
- case NVPTXISD::Suld1DArrayI32Clamp:
- Opc = NVPTX::SULD_1D_ARRAY_I32_CLAMP_R;
- break;
- case NVPTXISD::Suld1DArrayI64Clamp:
- Opc = NVPTX::SULD_1D_ARRAY_I64_CLAMP_R;
- break;
- case NVPTXISD::Suld1DArrayV2I8Clamp:
- Opc = NVPTX::SULD_1D_ARRAY_V2I8_CLAMP_R;
- break;
- case NVPTXISD::Suld1DArrayV2I16Clamp:
- Opc = NVPTX::SULD_1D_ARRAY_V2I16_CLAMP_R;
- break;
- case NVPTXISD::Suld1DArrayV2I32Clamp:
- Opc = NVPTX::SULD_1D_ARRAY_V2I32_CLAMP_R;
- break;
- case NVPTXISD::Suld1DArrayV2I64Clamp:
- Opc = NVPTX::SULD_1D_ARRAY_V2I64_CLAMP_R;
- break;
- case NVPTXISD::Suld1DArrayV4I8Clamp:
- Opc = NVPTX::SULD_1D_ARRAY_V4I8_CLAMP_R;
- break;
- case NVPTXISD::Suld1DArrayV4I16Clamp:
- Opc = NVPTX::SULD_1D_ARRAY_V4I16_CLAMP_R;
- break;
- case NVPTXISD::Suld1DArrayV4I32Clamp:
- Opc = NVPTX::SULD_1D_ARRAY_V4I32_CLAMP_R;
- break;
- case NVPTXISD::Suld2DI8Clamp:
- Opc = NVPTX::SULD_2D_I8_CLAMP_R;
- break;
- case NVPTXISD::Suld2DI16Clamp:
- Opc = NVPTX::SULD_2D_I16_CLAMP_R;
- break;
- case NVPTXISD::Suld2DI32Clamp:
- Opc = NVPTX::SULD_2D_I32_CLAMP_R;
- break;
- case NVPTXISD::Suld2DI64Clamp:
- Opc = NVPTX::SULD_2D_I64_CLAMP_R;
- break;
- case NVPTXISD::Suld2DV2I8Clamp:
- Opc = NVPTX::SULD_2D_V2I8_CLAMP_R;
- break;
- case NVPTXISD::Suld2DV2I16Clamp:
- Opc = NVPTX::SULD_2D_V2I16_CLAMP_R;
- break;
- case NVPTXISD::Suld2DV2I32Clamp:
- Opc = NVPTX::SULD_2D_V2I32_CLAMP_R;
- break;
- case NVPTXISD::Suld2DV2I64Clamp:
- Opc = NVPTX::SULD_2D_V2I64_CLAMP_R;
- break;
- case NVPTXISD::Suld2DV4I8Clamp:
- Opc = NVPTX::SULD_2D_V4I8_CLAMP_R;
- break;
- case NVPTXISD::Suld2DV4I16Clamp:
- Opc = NVPTX::SULD_2D_V4I16_CLAMP_R;
- break;
- case NVPTXISD::Suld2DV4I32Clamp:
- Opc = NVPTX::SULD_2D_V4I32_CLAMP_R;
- break;
- case NVPTXISD::Suld2DArrayI8Clamp:
- Opc = NVPTX::SULD_2D_ARRAY_I8_CLAMP_R;
- break;
- case NVPTXISD::Suld2DArrayI16Clamp:
- Opc = NVPTX::SULD_2D_ARRAY_I16_CLAMP_R;
- break;
- case NVPTXISD::Suld2DArrayI32Clamp:
- Opc = NVPTX::SULD_2D_ARRAY_I32_CLAMP_R;
- break;
- case NVPTXISD::Suld2DArrayI64Clamp:
- Opc = NVPTX::SULD_2D_ARRAY_I64_CLAMP_R;
- break;
- case NVPTXISD::Suld2DArrayV2I8Clamp:
- Opc = NVPTX::SULD_2D_ARRAY_V2I8_CLAMP_R;
- break;
- case NVPTXISD::Suld2DArrayV2I16Clamp:
- Opc = NVPTX::SULD_2D_ARRAY_V2I16_CLAMP_R;
- break;
- case NVPTXISD::Suld2DArrayV2I32Clamp:
- Opc = NVPTX::SULD_2D_ARRAY_V2I32_CLAMP_R;
- break;
- case NVPTXISD::Suld2DArrayV2I64Clamp:
- Opc = NVPTX::SULD_2D_ARRAY_V2I64_CLAMP_R;
- break;
- case NVPTXISD::Suld2DArrayV4I8Clamp:
- Opc = NVPTX::SULD_2D_ARRAY_V4I8_CLAMP_R;
- break;
- case NVPTXISD::Suld2DArrayV4I16Clamp:
- Opc = NVPTX::SULD_2D_ARRAY_V4I16_CLAMP_R;
- break;
- case NVPTXISD::Suld2DArrayV4I32Clamp:
- Opc = NVPTX::SULD_2D_ARRAY_V4I32_CLAMP_R;
- break;
- case NVPTXISD::Suld3DI8Clamp:
- Opc = NVPTX::SULD_3D_I8_CLAMP_R;
- break;
- case NVPTXISD::Suld3DI16Clamp:
- Opc = NVPTX::SULD_3D_I16_CLAMP_R;
- break;
- case NVPTXISD::Suld3DI32Clamp:
- Opc = NVPTX::SULD_3D_I32_CLAMP_R;
- break;
- case NVPTXISD::Suld3DI64Clamp:
- Opc = NVPTX::SULD_3D_I64_CLAMP_R;
- break;
- case NVPTXISD::Suld3DV2I8Clamp:
- Opc = NVPTX::SULD_3D_V2I8_CLAMP_R;
- break;
- case NVPTXISD::Suld3DV2I16Clamp:
- Opc = NVPTX::SULD_3D_V2I16_CLAMP_R;
- break;
- case NVPTXISD::Suld3DV2I32Clamp:
- Opc = NVPTX::SULD_3D_V2I32_CLAMP_R;
- break;
- case NVPTXISD::Suld3DV2I64Clamp:
- Opc = NVPTX::SULD_3D_V2I64_CLAMP_R;
- break;
- case NVPTXISD::Suld3DV4I8Clamp:
- Opc = NVPTX::SULD_3D_V4I8_CLAMP_R;
- break;
- case NVPTXISD::Suld3DV4I16Clamp:
- Opc = NVPTX::SULD_3D_V4I16_CLAMP_R;
- break;
- case NVPTXISD::Suld3DV4I32Clamp:
- Opc = NVPTX::SULD_3D_V4I32_CLAMP_R;
- break;
- case NVPTXISD::Suld1DI8Trap:
- Opc = NVPTX::SULD_1D_I8_TRAP_R;
- break;
- case NVPTXISD::Suld1DI16Trap:
- Opc = NVPTX::SULD_1D_I16_TRAP_R;
- break;
- case NVPTXISD::Suld1DI32Trap:
- Opc = NVPTX::SULD_1D_I32_TRAP_R;
- break;
- case NVPTXISD::Suld1DI64Trap:
- Opc = NVPTX::SULD_1D_I64_TRAP_R;
- break;
- case NVPTXISD::Suld1DV2I8Trap:
- Opc = NVPTX::SULD_1D_V2I8_TRAP_R;
- break;
- case NVPTXISD::Suld1DV2I16Trap:
- Opc = NVPTX::SULD_1D_V2I16_TRAP_R;
- break;
- case NVPTXISD::Suld1DV2I32Trap:
- Opc = NVPTX::SULD_1D_V2I32_TRAP_R;
- break;
- case NVPTXISD::Suld1DV2I64Trap:
- Opc = NVPTX::SULD_1D_V2I64_TRAP_R;
- break;
- case NVPTXISD::Suld1DV4I8Trap:
- Opc = NVPTX::SULD_1D_V4I8_TRAP_R;
- break;
- case NVPTXISD::Suld1DV4I16Trap:
- Opc = NVPTX::SULD_1D_V4I16_TRAP_R;
- break;
- case NVPTXISD::Suld1DV4I32Trap:
- Opc = NVPTX::SULD_1D_V4I32_TRAP_R;
- break;
- case NVPTXISD::Suld1DArrayI8Trap:
- Opc = NVPTX::SULD_1D_ARRAY_I8_TRAP_R;
- break;
- case NVPTXISD::Suld1DArrayI16Trap:
- Opc = NVPTX::SULD_1D_ARRAY_I16_TRAP_R;
- break;
- case NVPTXISD::Suld1DArrayI32Trap:
- Opc = NVPTX::SULD_1D_ARRAY_I32_TRAP_R;
- break;
- case NVPTXISD::Suld1DArrayI64Trap:
- Opc = NVPTX::SULD_1D_ARRAY_I64_TRAP_R;
- break;
- case NVPTXISD::Suld1DArrayV2I8Trap:
- Opc = NVPTX::SULD_1D_ARRAY_V2I8_TRAP_R;
- break;
- case NVPTXISD::Suld1DArrayV2I16Trap:
- Opc = NVPTX::SULD_1D_ARRAY_V2I16_TRAP_R;
- break;
- case NVPTXISD::Suld1DArrayV2I32Trap:
- Opc = NVPTX::SULD_1D_ARRAY_V2I32_TRAP_R;
- break;
- case NVPTXISD::Suld1DArrayV2I64Trap:
- Opc = NVPTX::SULD_1D_ARRAY_V2I64_TRAP_R;
- break;
- case NVPTXISD::Suld1DArrayV4I8Trap:
- Opc = NVPTX::SULD_1D_ARRAY_V4I8_TRAP_R;
- break;
- case NVPTXISD::Suld1DArrayV4I16Trap:
- Opc = NVPTX::SULD_1D_ARRAY_V4I16_TRAP_R;
- break;
- case NVPTXISD::Suld1DArrayV4I32Trap:
- Opc = NVPTX::SULD_1D_ARRAY_V4I32_TRAP_R;
- break;
- case NVPTXISD::Suld2DI8Trap:
- Opc = NVPTX::SULD_2D_I8_TRAP_R;
- break;
- case NVPTXISD::Suld2DI16Trap:
- Opc = NVPTX::SULD_2D_I16_TRAP_R;
- break;
- case NVPTXISD::Suld2DI32Trap:
- Opc = NVPTX::SULD_2D_I32_TRAP_R;
- break;
- case NVPTXISD::Suld2DI64Trap:
- Opc = NVPTX::SULD_2D_I64_TRAP_R;
- break;
- case NVPTXISD::Suld2DV2I8Trap:
- Opc = NVPTX::SULD_2D_V2I8_TRAP_R;
- break;
- case NVPTXISD::Suld2DV2I16Trap:
- Opc = NVPTX::SULD_2D_V2I16_TRAP_R;
- break;
- case NVPTXISD::Suld2DV2I32Trap:
- Opc = NVPTX::SULD_2D_V2I32_TRAP_R;
- break;
- case NVPTXISD::Suld2DV2I64Trap:
- Opc = NVPTX::SULD_2D_V2I64_TRAP_R;
- break;
- case NVPTXISD::Suld2DV4I8Trap:
- Opc = NVPTX::SULD_2D_V4I8_TRAP_R;
- break;
- case NVPTXISD::Suld2DV4I16Trap:
- Opc = NVPTX::SULD_2D_V4I16_TRAP_R;
- break;
- case NVPTXISD::Suld2DV4I32Trap:
- Opc = NVPTX::SULD_2D_V4I32_TRAP_R;
- break;
- case NVPTXISD::Suld2DArrayI8Trap:
- Opc = NVPTX::SULD_2D_ARRAY_I8_TRAP_R;
- break;
- case NVPTXISD::Suld2DArrayI16Trap:
- Opc = NVPTX::SULD_2D_ARRAY_I16_TRAP_R;
- break;
- case NVPTXISD::Suld2DArrayI32Trap:
- Opc = NVPTX::SULD_2D_ARRAY_I32_TRAP_R;
- break;
- case NVPTXISD::Suld2DArrayI64Trap:
- Opc = NVPTX::SULD_2D_ARRAY_I64_TRAP_R;
- break;
- case NVPTXISD::Suld2DArrayV2I8Trap:
- Opc = NVPTX::SULD_2D_ARRAY_V2I8_TRAP_R;
- break;
- case NVPTXISD::Suld2DArrayV2I16Trap:
- Opc = NVPTX::SULD_2D_ARRAY_V2I16_TRAP_R;
- break;
- case NVPTXISD::Suld2DArrayV2I32Trap:
- Opc = NVPTX::SULD_2D_ARRAY_V2I32_TRAP_R;
- break;
- case NVPTXISD::Suld2DArrayV2I64Trap:
- Opc = NVPTX::SULD_2D_ARRAY_V2I64_TRAP_R;
- break;
- case NVPTXISD::Suld2DArrayV4I8Trap:
- Opc = NVPTX::SULD_2D_ARRAY_V4I8_TRAP_R;
- break;
- case NVPTXISD::Suld2DArrayV4I16Trap:
- Opc = NVPTX::SULD_2D_ARRAY_V4I16_TRAP_R;
- break;
- case NVPTXISD::Suld2DArrayV4I32Trap:
- Opc = NVPTX::SULD_2D_ARRAY_V4I32_TRAP_R;
- break;
- case NVPTXISD::Suld3DI8Trap:
- Opc = NVPTX::SULD_3D_I8_TRAP_R;
- break;
- case NVPTXISD::Suld3DI16Trap:
- Opc = NVPTX::SULD_3D_I16_TRAP_R;
- break;
- case NVPTXISD::Suld3DI32Trap:
- Opc = NVPTX::SULD_3D_I32_TRAP_R;
- break;
- case NVPTXISD::Suld3DI64Trap:
- Opc = NVPTX::SULD_3D_I64_TRAP_R;
- break;
- case NVPTXISD::Suld3DV2I8Trap:
- Opc = NVPTX::SULD_3D_V2I8_TRAP_R;
- break;
- case NVPTXISD::Suld3DV2I16Trap:
- Opc = NVPTX::SULD_3D_V2I16_TRAP_R;
- break;
- case NVPTXISD::Suld3DV2I32Trap:
- Opc = NVPTX::SULD_3D_V2I32_TRAP_R;
- break;
- case NVPTXISD::Suld3DV2I64Trap:
- Opc = NVPTX::SULD_3D_V2I64_TRAP_R;
- break;
- case NVPTXISD::Suld3DV4I8Trap:
- Opc = NVPTX::SULD_3D_V4I8_TRAP_R;
- break;
- case NVPTXISD::Suld3DV4I16Trap:
- Opc = NVPTX::SULD_3D_V4I16_TRAP_R;
- break;
- case NVPTXISD::Suld3DV4I32Trap:
- Opc = NVPTX::SULD_3D_V4I32_TRAP_R;
- break;
- case NVPTXISD::Suld1DI8Zero:
- Opc = NVPTX::SULD_1D_I8_ZERO_R;
- break;
- case NVPTXISD::Suld1DI16Zero:
- Opc = NVPTX::SULD_1D_I16_ZERO_R;
- break;
- case NVPTXISD::Suld1DI32Zero:
- Opc = NVPTX::SULD_1D_I32_ZERO_R;
- break;
- case NVPTXISD::Suld1DI64Zero:
- Opc = NVPTX::SULD_1D_I64_ZERO_R;
- break;
- case NVPTXISD::Suld1DV2I8Zero:
- Opc = NVPTX::SULD_1D_V2I8_ZERO_R;
- break;
- case NVPTXISD::Suld1DV2I16Zero:
- Opc = NVPTX::SULD_1D_V2I16_ZERO_R;
- break;
- case NVPTXISD::Suld1DV2I32Zero:
- Opc = NVPTX::SULD_1D_V2I32_ZERO_R;
- break;
- case NVPTXISD::Suld1DV2I64Zero:
- Opc = NVPTX::SULD_1D_V2I64_ZERO_R;
- break;
- case NVPTXISD::Suld1DV4I8Zero:
- Opc = NVPTX::SULD_1D_V4I8_ZERO_R;
- break;
- case NVPTXISD::Suld1DV4I16Zero:
- Opc = NVPTX::SULD_1D_V4I16_ZERO_R;
- break;
- case NVPTXISD::Suld1DV4I32Zero:
- Opc = NVPTX::SULD_1D_V4I32_ZERO_R;
- break;
- case NVPTXISD::Suld1DArrayI8Zero:
- Opc = NVPTX::SULD_1D_ARRAY_I8_ZERO_R;
- break;
- case NVPTXISD::Suld1DArrayI16Zero:
- Opc = NVPTX::SULD_1D_ARRAY_I16_ZERO_R;
- break;
- case NVPTXISD::Suld1DArrayI32Zero:
- Opc = NVPTX::SULD_1D_ARRAY_I32_ZERO_R;
- break;
- case NVPTXISD::Suld1DArrayI64Zero:
- Opc = NVPTX::SULD_1D_ARRAY_I64_ZERO_R;
- break;
- case NVPTXISD::Suld1DArrayV2I8Zero:
- Opc = NVPTX::SULD_1D_ARRAY_V2I8_ZERO_R;
- break;
- case NVPTXISD::Suld1DArrayV2I16Zero:
- Opc = NVPTX::SULD_1D_ARRAY_V2I16_ZERO_R;
- break;
- case NVPTXISD::Suld1DArrayV2I32Zero:
- Opc = NVPTX::SULD_1D_ARRAY_V2I32_ZERO_R;
- break;
- case NVPTXISD::Suld1DArrayV2I64Zero:
- Opc = NVPTX::SULD_1D_ARRAY_V2I64_ZERO_R;
- break;
- case NVPTXISD::Suld1DArrayV4I8Zero:
- Opc = NVPTX::SULD_1D_ARRAY_V4I8_ZERO_R;
- break;
- case NVPTXISD::Suld1DArrayV4I16Zero:
- Opc = NVPTX::SULD_1D_ARRAY_V4I16_ZERO_R;
- break;
- case NVPTXISD::Suld1DArrayV4I32Zero:
- Opc = NVPTX::SULD_1D_ARRAY_V4I32_ZERO_R;
- break;
- case NVPTXISD::Suld2DI8Zero:
- Opc = NVPTX::SULD_2D_I8_ZERO_R;
- break;
- case NVPTXISD::Suld2DI16Zero:
- Opc = NVPTX::SULD_2D_I16_ZERO_R;
- break;
- case NVPTXISD::Suld2DI32Zero:
- Opc = NVPTX::SULD_2D_I32_ZERO_R;
- break;
- case NVPTXISD::Suld2DI64Zero:
- Opc = NVPTX::SULD_2D_I64_ZERO_R;
- break;
- case NVPTXISD::Suld2DV2I8Zero:
- Opc = NVPTX::SULD_2D_V2I8_ZERO_R;
- break;
- case NVPTXISD::Suld2DV2I16Zero:
- Opc = NVPTX::SULD_2D_V2I16_ZERO_R;
- break;
- case NVPTXISD::Suld2DV2I32Zero:
- Opc = NVPTX::SULD_2D_V2I32_ZERO_R;
- break;
- case NVPTXISD::Suld2DV2I64Zero:
- Opc = NVPTX::SULD_2D_V2I64_ZERO_R;
- break;
- case NVPTXISD::Suld2DV4I8Zero:
- Opc = NVPTX::SULD_2D_V4I8_ZERO_R;
- break;
- case NVPTXISD::Suld2DV4I16Zero:
- Opc = NVPTX::SULD_2D_V4I16_ZERO_R;
- break;
- case NVPTXISD::Suld2DV4I32Zero:
- Opc = NVPTX::SULD_2D_V4I32_ZERO_R;
- break;
- case NVPTXISD::Suld2DArrayI8Zero:
- Opc = NVPTX::SULD_2D_ARRAY_I8_ZERO_R;
- break;
- case NVPTXISD::Suld2DArrayI16Zero:
- Opc = NVPTX::SULD_2D_ARRAY_I16_ZERO_R;
- break;
- case NVPTXISD::Suld2DArrayI32Zero:
- Opc = NVPTX::SULD_2D_ARRAY_I32_ZERO_R;
- break;
- case NVPTXISD::Suld2DArrayI64Zero:
- Opc = NVPTX::SULD_2D_ARRAY_I64_ZERO_R;
- break;
- case NVPTXISD::Suld2DArrayV2I8Zero:
- Opc = NVPTX::SULD_2D_ARRAY_V2I8_ZERO_R;
- break;
- case NVPTXISD::Suld2DArrayV2I16Zero:
- Opc = NVPTX::SULD_2D_ARRAY_V2I16_ZERO_R;
- break;
- case NVPTXISD::Suld2DArrayV2I32Zero:
- Opc = NVPTX::SULD_2D_ARRAY_V2I32_ZERO_R;
- break;
- case NVPTXISD::Suld2DArrayV2I64Zero:
- Opc = NVPTX::SULD_2D_ARRAY_V2I64_ZERO_R;
- break;
- case NVPTXISD::Suld2DArrayV4I8Zero:
- Opc = NVPTX::SULD_2D_ARRAY_V4I8_ZERO_R;
- break;
- case NVPTXISD::Suld2DArrayV4I16Zero:
- Opc = NVPTX::SULD_2D_ARRAY_V4I16_ZERO_R;
- break;
- case NVPTXISD::Suld2DArrayV4I32Zero:
- Opc = NVPTX::SULD_2D_ARRAY_V4I32_ZERO_R;
- break;
- case NVPTXISD::Suld3DI8Zero:
- Opc = NVPTX::SULD_3D_I8_ZERO_R;
- break;
- case NVPTXISD::Suld3DI16Zero:
- Opc = NVPTX::SULD_3D_I16_ZERO_R;
- break;
- case NVPTXISD::Suld3DI32Zero:
- Opc = NVPTX::SULD_3D_I32_ZERO_R;
- break;
- case NVPTXISD::Suld3DI64Zero:
- Opc = NVPTX::SULD_3D_I64_ZERO_R;
- break;
- case NVPTXISD::Suld3DV2I8Zero:
- Opc = NVPTX::SULD_3D_V2I8_ZERO_R;
- break;
- case NVPTXISD::Suld3DV2I16Zero:
- Opc = NVPTX::SULD_3D_V2I16_ZERO_R;
- break;
- case NVPTXISD::Suld3DV2I32Zero:
- Opc = NVPTX::SULD_3D_V2I32_ZERO_R;
- break;
- case NVPTXISD::Suld3DV2I64Zero:
- Opc = NVPTX::SULD_3D_V2I64_ZERO_R;
- break;
- case NVPTXISD::Suld3DV4I8Zero:
- Opc = NVPTX::SULD_3D_V4I8_ZERO_R;
- break;
- case NVPTXISD::Suld3DV4I16Zero:
- Opc = NVPTX::SULD_3D_V4I16_ZERO_R;
- break;
- case NVPTXISD::Suld3DV4I32Zero:
- Opc = NVPTX::SULD_3D_V4I32_ZERO_R;
- break;
- }
- // Copy over operands
- SmallVector<SDValue, 8> Ops(drop_begin(N->ops()));
- Ops.push_back(N->getOperand(0)); // Move chain to the back.
- ReplaceNode(N, CurDAG->getMachineNode(Opc, SDLoc(N), N->getVTList(), Ops));
- return true;
- }
- /// SelectBFE - Look for instruction sequences that can be made more efficient
- /// by using the 'bfe' (bit-field extract) PTX instruction
- bool NVPTXDAGToDAGISel::tryBFE(SDNode *N) {
- SDLoc DL(N);
- SDValue LHS = N->getOperand(0);
- SDValue RHS = N->getOperand(1);
- SDValue Len;
- SDValue Start;
- SDValue Val;
- bool IsSigned = false;
- if (N->getOpcode() == ISD::AND) {
- // Canonicalize the operands
- // We want 'and %val, %mask'
- if (isa<ConstantSDNode>(LHS) && !isa<ConstantSDNode>(RHS)) {
- std::swap(LHS, RHS);
- }
- ConstantSDNode *Mask = dyn_cast<ConstantSDNode>(RHS);
- if (!Mask) {
- // We need a constant mask on the RHS of the AND
- return false;
- }
- // Extract the mask bits
- uint64_t MaskVal = Mask->getZExtValue();
- if (!isMask_64(MaskVal)) {
- // We *could* handle shifted masks here, but doing so would require an
- // 'and' operation to fix up the low-order bits so we would trade
- // shr+and for bfe+and, which has the same throughput
- return false;
- }
- // How many bits are in our mask?
- uint64_t NumBits = countTrailingOnes(MaskVal);
- Len = CurDAG->getTargetConstant(NumBits, DL, MVT::i32);
- if (LHS.getOpcode() == ISD::SRL || LHS.getOpcode() == ISD::SRA) {
- // We have a 'srl/and' pair, extract the effective start bit and length
- Val = LHS.getNode()->getOperand(0);
- Start = LHS.getNode()->getOperand(1);
- ConstantSDNode *StartConst = dyn_cast<ConstantSDNode>(Start);
- if (StartConst) {
- uint64_t StartVal = StartConst->getZExtValue();
- // How many "good" bits do we have left? "good" is defined here as bits
- // that exist in the original value, not shifted in.
- uint64_t GoodBits = Start.getValueSizeInBits() - StartVal;
- if (NumBits > GoodBits) {
- // Do not handle the case where bits have been shifted in. In theory
- // we could handle this, but the cost is likely higher than just
- // emitting the srl/and pair.
- return false;
- }
- Start = CurDAG->getTargetConstant(StartVal, DL, MVT::i32);
- } else {
- // Do not handle the case where the shift amount (can be zero if no srl
- // was found) is not constant. We could handle this case, but it would
- // require run-time logic that would be more expensive than just
- // emitting the srl/and pair.
- return false;
- }
- } else {
- // Do not handle the case where the LHS of the and is not a shift. While
- // it would be trivial to handle this case, it would just transform
- // 'and' -> 'bfe', but 'and' has higher-throughput.
- return false;
- }
- } else if (N->getOpcode() == ISD::SRL || N->getOpcode() == ISD::SRA) {
- if (LHS->getOpcode() == ISD::AND) {
- ConstantSDNode *ShiftCnst = dyn_cast<ConstantSDNode>(RHS);
- if (!ShiftCnst) {
- // Shift amount must be constant
- return false;
- }
- uint64_t ShiftAmt = ShiftCnst->getZExtValue();
- SDValue AndLHS = LHS->getOperand(0);
- SDValue AndRHS = LHS->getOperand(1);
- // Canonicalize the AND to have the mask on the RHS
- if (isa<ConstantSDNode>(AndLHS)) {
- std::swap(AndLHS, AndRHS);
- }
- ConstantSDNode *MaskCnst = dyn_cast<ConstantSDNode>(AndRHS);
- if (!MaskCnst) {
- // Mask must be constant
- return false;
- }
- uint64_t MaskVal = MaskCnst->getZExtValue();
- uint64_t NumZeros;
- uint64_t NumBits;
- if (isMask_64(MaskVal)) {
- NumZeros = 0;
- // The number of bits in the result bitfield will be the number of
- // trailing ones (the AND) minus the number of bits we shift off
- NumBits = countTrailingOnes(MaskVal) - ShiftAmt;
- } else if (isShiftedMask_64(MaskVal)) {
- NumZeros = countTrailingZeros(MaskVal);
- unsigned NumOnes = countTrailingOnes(MaskVal >> NumZeros);
- // The number of bits in the result bitfield will be the number of
- // trailing zeros plus the number of set bits in the mask minus the
- // number of bits we shift off
- NumBits = NumZeros + NumOnes - ShiftAmt;
- } else {
- // This is not a mask we can handle
- return false;
- }
- if (ShiftAmt < NumZeros) {
- // Handling this case would require extra logic that would make this
- // transformation non-profitable
- return false;
- }
- Val = AndLHS;
- Start = CurDAG->getTargetConstant(ShiftAmt, DL, MVT::i32);
- Len = CurDAG->getTargetConstant(NumBits, DL, MVT::i32);
- } else if (LHS->getOpcode() == ISD::SHL) {
- // Here, we have a pattern like:
- //
- // (sra (shl val, NN), MM)
- // or
- // (srl (shl val, NN), MM)
- //
- // If MM >= NN, we can efficiently optimize this with bfe
- Val = LHS->getOperand(0);
- SDValue ShlRHS = LHS->getOperand(1);
- ConstantSDNode *ShlCnst = dyn_cast<ConstantSDNode>(ShlRHS);
- if (!ShlCnst) {
- // Shift amount must be constant
- return false;
- }
- uint64_t InnerShiftAmt = ShlCnst->getZExtValue();
- SDValue ShrRHS = RHS;
- ConstantSDNode *ShrCnst = dyn_cast<ConstantSDNode>(ShrRHS);
- if (!ShrCnst) {
- // Shift amount must be constant
- return false;
- }
- uint64_t OuterShiftAmt = ShrCnst->getZExtValue();
- // To avoid extra codegen and be profitable, we need Outer >= Inner
- if (OuterShiftAmt < InnerShiftAmt) {
- return false;
- }
- // If the outer shift is more than the type size, we have no bitfield to
- // extract (since we also check that the inner shift is <= the outer shift
- // then this also implies that the inner shift is < the type size)
- if (OuterShiftAmt >= Val.getValueSizeInBits()) {
- return false;
- }
- Start = CurDAG->getTargetConstant(OuterShiftAmt - InnerShiftAmt, DL,
- MVT::i32);
- Len = CurDAG->getTargetConstant(Val.getValueSizeInBits() - OuterShiftAmt,
- DL, MVT::i32);
- if (N->getOpcode() == ISD::SRA) {
- // If we have a arithmetic right shift, we need to use the signed bfe
- // variant
- IsSigned = true;
- }
- } else {
- // No can do...
- return false;
- }
- } else {
- // No can do...
- return false;
- }
- unsigned Opc;
- // For the BFE operations we form here from "and" and "srl", always use the
- // unsigned variants.
- if (Val.getValueType() == MVT::i32) {
- if (IsSigned) {
- Opc = NVPTX::BFE_S32rii;
- } else {
- Opc = NVPTX::BFE_U32rii;
- }
- } else if (Val.getValueType() == MVT::i64) {
- if (IsSigned) {
- Opc = NVPTX::BFE_S64rii;
- } else {
- Opc = NVPTX::BFE_U64rii;
- }
- } else {
- // We cannot handle this type
- return false;
- }
- SDValue Ops[] = {
- Val, Start, Len
- };
- ReplaceNode(N, CurDAG->getMachineNode(Opc, DL, N->getVTList(), Ops));
- return true;
- }
- // SelectDirectAddr - Match a direct address for DAG.
- // A direct address could be a globaladdress or externalsymbol.
- bool NVPTXDAGToDAGISel::SelectDirectAddr(SDValue N, SDValue &Address) {
- // Return true if TGA or ES.
- if (N.getOpcode() == ISD::TargetGlobalAddress ||
- N.getOpcode() == ISD::TargetExternalSymbol) {
- Address = N;
- return true;
- }
- if (N.getOpcode() == NVPTXISD::Wrapper) {
- Address = N.getOperand(0);
- return true;
- }
- // addrspacecast(MoveParam(arg_symbol) to addrspace(PARAM)) -> arg_symbol
- if (AddrSpaceCastSDNode *CastN = dyn_cast<AddrSpaceCastSDNode>(N)) {
- if (CastN->getSrcAddressSpace() == ADDRESS_SPACE_GENERIC &&
- CastN->getDestAddressSpace() == ADDRESS_SPACE_PARAM &&
- CastN->getOperand(0).getOpcode() == NVPTXISD::MoveParam)
- return SelectDirectAddr(CastN->getOperand(0).getOperand(0), Address);
- }
- return false;
- }
- // symbol+offset
- bool NVPTXDAGToDAGISel::SelectADDRsi_imp(
- SDNode *OpNode, SDValue Addr, SDValue &Base, SDValue &Offset, MVT mvt) {
- if (Addr.getOpcode() == ISD::ADD) {
- if (ConstantSDNode *CN = dyn_cast<ConstantSDNode>(Addr.getOperand(1))) {
- SDValue base = Addr.getOperand(0);
- if (SelectDirectAddr(base, Base)) {
- Offset = CurDAG->getTargetConstant(CN->getZExtValue(), SDLoc(OpNode),
- mvt);
- return true;
- }
- }
- }
- return false;
- }
- // symbol+offset
- bool NVPTXDAGToDAGISel::SelectADDRsi(SDNode *OpNode, SDValue Addr,
- SDValue &Base, SDValue &Offset) {
- return SelectADDRsi_imp(OpNode, Addr, Base, Offset, MVT::i32);
- }
- // symbol+offset
- bool NVPTXDAGToDAGISel::SelectADDRsi64(SDNode *OpNode, SDValue Addr,
- SDValue &Base, SDValue &Offset) {
- return SelectADDRsi_imp(OpNode, Addr, Base, Offset, MVT::i64);
- }
- // register+offset
- bool NVPTXDAGToDAGISel::SelectADDRri_imp(
- SDNode *OpNode, SDValue Addr, SDValue &Base, SDValue &Offset, MVT mvt) {
- if (FrameIndexSDNode *FIN = dyn_cast<FrameIndexSDNode>(Addr)) {
- Base = CurDAG->getTargetFrameIndex(FIN->getIndex(), mvt);
- Offset = CurDAG->getTargetConstant(0, SDLoc(OpNode), mvt);
- return true;
- }
- if (Addr.getOpcode() == ISD::TargetExternalSymbol ||
- Addr.getOpcode() == ISD::TargetGlobalAddress)
- return false; // direct calls.
- if (Addr.getOpcode() == ISD::ADD) {
- if (SelectDirectAddr(Addr.getOperand(0), Addr)) {
- return false;
- }
- if (ConstantSDNode *CN = dyn_cast<ConstantSDNode>(Addr.getOperand(1))) {
- if (FrameIndexSDNode *FIN =
- dyn_cast<FrameIndexSDNode>(Addr.getOperand(0)))
- // Constant offset from frame ref.
- Base = CurDAG->getTargetFrameIndex(FIN->getIndex(), mvt);
- else
- Base = Addr.getOperand(0);
- Offset = CurDAG->getTargetConstant(CN->getZExtValue(), SDLoc(OpNode),
- mvt);
- return true;
- }
- }
- return false;
- }
- // register+offset
- bool NVPTXDAGToDAGISel::SelectADDRri(SDNode *OpNode, SDValue Addr,
- SDValue &Base, SDValue &Offset) {
- return SelectADDRri_imp(OpNode, Addr, Base, Offset, MVT::i32);
- }
- // register+offset
- bool NVPTXDAGToDAGISel::SelectADDRri64(SDNode *OpNode, SDValue Addr,
- SDValue &Base, SDValue &Offset) {
- return SelectADDRri_imp(OpNode, Addr, Base, Offset, MVT::i64);
- }
- bool NVPTXDAGToDAGISel::ChkMemSDNodeAddressSpace(SDNode *N,
- unsigned int spN) const {
- const Value *Src = nullptr;
- if (MemSDNode *mN = dyn_cast<MemSDNode>(N)) {
- if (spN == 0 && mN->getMemOperand()->getPseudoValue())
- return true;
- Src = mN->getMemOperand()->getValue();
- }
- if (!Src)
- return false;
- if (auto *PT = dyn_cast<PointerType>(Src->getType()))
- return (PT->getAddressSpace() == spN);
- return false;
- }
- /// SelectInlineAsmMemoryOperand - Implement addressing mode selection for
- /// inline asm expressions.
- bool NVPTXDAGToDAGISel::SelectInlineAsmMemoryOperand(
- const SDValue &Op, unsigned ConstraintID, std::vector<SDValue> &OutOps) {
- SDValue Op0, Op1;
- switch (ConstraintID) {
- default:
- return true;
- case InlineAsm::Constraint_m: // memory
- if (SelectDirectAddr(Op, Op0)) {
- OutOps.push_back(Op0);
- OutOps.push_back(CurDAG->getTargetConstant(0, SDLoc(Op), MVT::i32));
- return false;
- }
- if (SelectADDRri(Op.getNode(), Op, Op0, Op1)) {
- OutOps.push_back(Op0);
- OutOps.push_back(Op1);
- return false;
- }
- break;
- }
- return true;
- }
- /// GetConvertOpcode - Returns the CVT_ instruction opcode that implements a
- /// conversion from \p SrcTy to \p DestTy.
- unsigned NVPTXDAGToDAGISel::GetConvertOpcode(MVT DestTy, MVT SrcTy,
- bool IsSigned) {
- switch (SrcTy.SimpleTy) {
- default:
- llvm_unreachable("Unhandled source type");
- case MVT::i8:
- switch (DestTy.SimpleTy) {
- default:
- llvm_unreachable("Unhandled dest type");
- case MVT::i16:
- return IsSigned ? NVPTX::CVT_s16_s8 : NVPTX::CVT_u16_u8;
- case MVT::i32:
- return IsSigned ? NVPTX::CVT_s32_s8 : NVPTX::CVT_u32_u8;
- case MVT::i64:
- return IsSigned ? NVPTX::CVT_s64_s8 : NVPTX::CVT_u64_u8;
- }
- case MVT::i16:
- switch (DestTy.SimpleTy) {
- default:
- llvm_unreachable("Unhandled dest type");
- case MVT::i8:
- return IsSigned ? NVPTX::CVT_s8_s16 : NVPTX::CVT_u8_u16;
- case MVT::i32:
- return IsSigned ? NVPTX::CVT_s32_s16 : NVPTX::CVT_u32_u16;
- case MVT::i64:
- return IsSigned ? NVPTX::CVT_s64_s16 : NVPTX::CVT_u64_u16;
- }
- case MVT::i32:
- switch (DestTy.SimpleTy) {
- default:
- llvm_unreachable("Unhandled dest type");
- case MVT::i8:
- return IsSigned ? NVPTX::CVT_s8_s32 : NVPTX::CVT_u8_u32;
- case MVT::i16:
- return IsSigned ? NVPTX::CVT_s16_s32 : NVPTX::CVT_u16_u32;
- case MVT::i64:
- return IsSigned ? NVPTX::CVT_s64_s32 : NVPTX::CVT_u64_u32;
- }
- case MVT::i64:
- switch (DestTy.SimpleTy) {
- default:
- llvm_unreachable("Unhandled dest type");
- case MVT::i8:
- return IsSigned ? NVPTX::CVT_s8_s64 : NVPTX::CVT_u8_u64;
- case MVT::i16:
- return IsSigned ? NVPTX::CVT_s16_s64 : NVPTX::CVT_u16_u64;
- case MVT::i32:
- return IsSigned ? NVPTX::CVT_s32_s64 : NVPTX::CVT_u32_u64;
- }
- }
- }
|