InstBuilderAuto.cpp 224 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602260326042605260626072608260926102611261226132614261526162617261826192620262126222623262426252626262726282629263026312632263326342635263626372638263926402641264226432644264526462647264826492650265126522653265426552656265726582659266026612662266326642665266626672668266926702671267226732674267526762677267826792680268126822683268426852686268726882689269026912692269326942695269626972698269927002701270227032704270527062707270827092710271127122713271427152716271727182719272027212722272327242725272627272728272927302731273227332734273527362737273827392740274127422743274427452746274727482749275027512752275327542755275627572758275927602761276227632764276527662767276827692770277127722773277427752776277727782779278027812782278327842785278627872788278927902791279227932794279527962797279827992800280128022803280428052806280728082809281028112812281328142815281628172818281928202821282228232824282528262827282828292830283128322833283428352836283728382839284028412842284328442845284628472848284928502851285228532854285528562857285828592860286128622863286428652866286728682869287028712872287328742875287628772878287928802881288228832884288528862887288828892890289128922893289428952896289728982899290029012902290329042905290629072908290929102911291229132914291529162917291829192920292129222923292429252926292729282929293029312932293329342935293629372938293929402941294229432944294529462947294829492950295129522953295429552956295729582959296029612962296329642965296629672968296929702971297229732974297529762977297829792980298129822983298429852986298729882989299029912992299329942995299629972998299930003001300230033004300530063007300830093010301130123013301430153016301730183019302030213022302330243025302630273028302930303031303230333034303530363037303830393040304130423043304430453046304730483049305030513052305330543055305630573058305930603061306230633064306530663067306830693070307130723073307430753076307730783079308030813082308330843085308630873088308930903091309230933094309530963097309830993100310131023103310431053106310731083109311031113112311331143115311631173118311931203121312231233124312531263127312831293130313131323133313431353136313731383139314031413142314331443145314631473148314931503151315231533154315531563157315831593160316131623163316431653166316731683169317031713172317331743175317631773178317931803181318231833184318531863187318831893190319131923193319431953196319731983199320032013202320332043205320632073208320932103211321232133214321532163217321832193220322132223223322432253226322732283229323032313232323332343235323632373238323932403241324232433244324532463247324832493250325132523253325432553256325732583259326032613262326332643265326632673268326932703271327232733274327532763277327832793280328132823283328432853286328732883289329032913292329332943295329632973298329933003301330233033304330533063307330833093310331133123313331433153316331733183319332033213322332333243325332633273328332933303331333233333334333533363337333833393340334133423343334433453346334733483349335033513352335333543355335633573358335933603361336233633364336533663367336833693370337133723373337433753376337733783379338033813382338333843385338633873388338933903391339233933394339533963397339833993400340134023403340434053406340734083409341034113412341334143415341634173418341934203421342234233424342534263427342834293430343134323433343434353436343734383439344034413442344334443445344634473448344934503451345234533454345534563457345834593460346134623463346434653466346734683469347034713472347334743475347634773478347934803481348234833484348534863487348834893490349134923493349434953496349734983499350035013502350335043505350635073508350935103511351235133514351535163517351835193520352135223523352435253526352735283529353035313532353335343535353635373538353935403541354235433544354535463547354835493550355135523553355435553556355735583559356035613562356335643565356635673568356935703571357235733574357535763577357835793580358135823583358435853586358735883589359035913592359335943595359635973598359936003601360236033604360536063607360836093610361136123613361436153616361736183619362036213622362336243625362636273628362936303631363236333634363536363637363836393640364136423643364436453646364736483649365036513652365336543655365636573658365936603661366236633664366536663667366836693670367136723673367436753676367736783679368036813682368336843685368636873688368936903691369236933694369536963697369836993700370137023703370437053706370737083709371037113712371337143715371637173718371937203721372237233724372537263727372837293730373137323733373437353736373737383739374037413742374337443745374637473748374937503751375237533754375537563757375837593760376137623763376437653766376737683769377037713772377337743775377637773778377937803781378237833784378537863787378837893790379137923793379437953796379737983799380038013802380338043805380638073808380938103811381238133814381538163817381838193820382138223823382438253826382738283829383038313832383338343835383638373838383938403841384238433844384538463847384838493850385138523853385438553856385738583859386038613862386338643865386638673868386938703871387238733874387538763877387838793880388138823883388438853886388738883889389038913892389338943895389638973898389939003901390239033904390539063907390839093910391139123913391439153916391739183919392039213922392339243925392639273928392939303931393239333934393539363937393839393940394139423943394439453946394739483949395039513952395339543955395639573958395939603961396239633964396539663967396839693970397139723973397439753976397739783979398039813982398339843985398639873988398939903991399239933994399539963997399839994000400140024003400440054006400740084009401040114012401340144015401640174018401940204021402240234024402540264027402840294030403140324033403440354036403740384039404040414042404340444045404640474048404940504051405240534054405540564057405840594060406140624063406440654066406740684069407040714072407340744075407640774078407940804081408240834084408540864087408840894090409140924093409440954096409740984099410041014102410341044105410641074108410941104111411241134114411541164117411841194120412141224123412441254126412741284129413041314132413341344135413641374138413941404141414241434144414541464147414841494150415141524153415441554156415741584159416041614162416341644165416641674168416941704171417241734174417541764177417841794180418141824183418441854186418741884189419041914192419341944195419641974198419942004201420242034204420542064207420842094210421142124213421442154216421742184219422042214222422342244225422642274228422942304231423242334234423542364237423842394240424142424243424442454246424742484249425042514252425342544255425642574258425942604261426242634264426542664267426842694270427142724273427442754276427742784279428042814282428342844285428642874288428942904291429242934294429542964297429842994300430143024303430443054306430743084309431043114312431343144315431643174318431943204321432243234324432543264327432843294330433143324333433443354336433743384339434043414342434343444345434643474348434943504351435243534354435543564357435843594360436143624363436443654366436743684369437043714372437343744375437643774378437943804381438243834384438543864387438843894390439143924393439443954396439743984399440044014402440344044405440644074408440944104411441244134414441544164417441844194420442144224423442444254426442744284429443044314432443344344435443644374438443944404441444244434444444544464447444844494450445144524453445444554456445744584459446044614462446344644465446644674468446944704471447244734474447544764477447844794480448144824483448444854486448744884489449044914492449344944495449644974498449945004501450245034504450545064507450845094510451145124513451445154516451745184519452045214522452345244525452645274528452945304531453245334534453545364537453845394540454145424543454445454546454745484549455045514552455345544555455645574558455945604561456245634564456545664567456845694570457145724573457445754576457745784579458045814582458345844585458645874588458945904591459245934594459545964597459845994600460146024603460446054606460746084609461046114612461346144615461646174618461946204621462246234624462546264627462846294630463146324633463446354636463746384639464046414642464346444645464646474648464946504651465246534654465546564657465846594660466146624663466446654666466746684669467046714672467346744675467646774678467946804681468246834684468546864687468846894690469146924693469446954696469746984699470047014702470347044705470647074708470947104711471247134714471547164717471847194720472147224723472447254726472747284729473047314732473347344735473647374738473947404741474247434744474547464747474847494750475147524753475447554756475747584759476047614762476347644765476647674768476947704771477247734774477547764777477847794780478147824783478447854786478747884789479047914792479347944795479647974798479948004801480248034804480548064807480848094810481148124813481448154816481748184819482048214822482348244825482648274828482948304831483248334834483548364837483848394840484148424843484448454846484748484849485048514852485348544855485648574858485948604861486248634864486548664867486848694870487148724873487448754876487748784879488048814882488348844885488648874888488948904891489248934894489548964897489848994900490149024903490449054906490749084909491049114912491349144915491649174918491949204921492249234924492549264927492849294930493149324933493449354936493749384939494049414942494349444945494649474948494949504951495249534954495549564957495849594960496149624963496449654966496749684969497049714972497349744975497649774978497949804981498249834984498549864987498849894990499149924993499449954996499749984999500050015002500350045005500650075008500950105011501250135014501550165017501850195020502150225023502450255026502750285029503050315032503350345035503650375038503950405041504250435044504550465047504850495050505150525053505450555056505750585059506050615062506350645065506650675068506950705071507250735074507550765077507850795080508150825083508450855086508750885089509050915092509350945095509650975098509951005101510251035104510551065107510851095110511151125113511451155116511751185119512051215122512351245125512651275128512951305131513251335134513551365137513851395140514151425143514451455146514751485149515051515152515351545155515651575158515951605161516251635164516551665167516851695170517151725173517451755176517751785179518051815182518351845185518651875188518951905191519251935194519551965197519851995200520152025203520452055206520752085209521052115212521352145215521652175218521952205221522252235224522552265227522852295230523152325233523452355236523752385239524052415242524352445245524652475248524952505251525252535254525552565257525852595260526152625263526452655266526752685269527052715272527352745275527652775278527952805281528252835284528552865287528852895290529152925293529452955296529752985299530053015302530353045305530653075308530953105311531253135314531553165317531853195320532153225323532453255326532753285329533053315332533353345335533653375338533953405341534253435344534553465347534853495350535153525353535453555356535753585359536053615362536353645365536653675368536953705371537253735374537553765377537853795380538153825383538453855386538753885389539053915392539353945395539653975398539954005401540254035404540554065407540854095410541154125413541454155416541754185419542054215422542354245425542654275428542954305431543254335434543554365437543854395440544154425443544454455446544754485449545054515452545354545455545654575458545954605461546254635464546554665467546854695470547154725473547454755476547754785479548054815482548354845485548654875488548954905491549254935494549554965497549854995500550155025503550455055506550755085509551055115512551355145515551655175518551955205521552255235524552555265527552855295530553155325533553455355536553755385539554055415542554355445545554655475548554955505551555255535554555555565557555855595560556155625563556455655566556755685569557055715572557355745575557655775578557955805581558255835584558555865587558855895590559155925593559455955596559755985599560056015602560356045605560656075608560956105611561256135614561556165617561856195620562156225623562456255626562756285629563056315632563356345635563656375638563956405641564256435644564556465647564856495650565156525653565456555656565756585659566056615662566356645665566656675668566956705671567256735674567556765677567856795680568156825683568456855686568756885689569056915692569356945695569656975698569957005701570257035704570557065707570857095710571157125713571457155716571757185719572057215722572357245725572657275728572957305731573257335734573557365737573857395740574157425743574457455746574757485749575057515752575357545755575657575758575957605761576257635764576557665767576857695770577157725773577457755776577757785779578057815782578357845785578657875788578957905791579257935794579557965797579857995800580158025803580458055806580758085809581058115812581358145815581658175818581958205821582258235824582558265827582858295830583158325833583458355836583758385839584058415842584358445845584658475848584958505851585258535854585558565857585858595860586158625863586458655866586758685869587058715872587358745875587658775878587958805881588258835884588558865887588858895890589158925893589458955896589758985899590059015902590359045905590659075908590959105911591259135914591559165917591859195920592159225923592459255926592759285929593059315932593359345935593659375938593959405941594259435944594559465947594859495950595159525953595459555956595759585959596059615962596359645965596659675968596959705971597259735974597559765977597859795980598159825983598459855986598759885989599059915992599359945995599659975998599960006001600260036004600560066007600860096010601160126013601460156016601760186019602060216022602360246025602660276028602960306031603260336034603560366037603860396040604160426043604460456046604760486049605060516052605360546055605660576058605960606061606260636064606560666067606860696070607160726073607460756076607760786079608060816082608360846085608660876088608960906091609260936094609560966097609860996100610161026103610461056106610761086109611061116112611361146115611661176118611961206121612261236124612561266127612861296130613161326133613461356136613761386139614061416142614361446145614661476148614961506151615261536154615561566157615861596160616161626163616461656166616761686169617061716172617361746175617661776178617961806181618261836184618561866187618861896190619161926193619461956196619761986199620062016202620362046205620662076208620962106211621262136214621562166217621862196220622162226223622462256226622762286229623062316232623362346235623662376238623962406241624262436244624562466247624862496250625162526253625462556256625762586259626062616262626362646265626662676268626962706271627262736274627562766277627862796280628162826283628462856286628762886289629062916292629362946295629662976298629963006301630263036304630563066307630863096310631163126313631463156316631763186319632063216322632363246325632663276328632963306331633263336334633563366337633863396340634163426343634463456346634763486349635063516352635363546355635663576358635963606361636263636364636563666367636863696370637163726373637463756376637763786379638063816382638363846385638663876388638963906391639263936394639563966397639863996400640164026403640464056406640764086409641064116412641364146415641664176418641964206421642264236424642564266427642864296430643164326433643464356436643764386439644064416442644364446445644664476448644964506451645264536454645564566457645864596460646164626463646464656466646764686469647064716472647364746475647664776478647964806481648264836484648564866487648864896490649164926493649464956496649764986499650065016502650365046505650665076508650965106511651265136514651565166517651865196520652165226523652465256526652765286529653065316532653365346535653665376538653965406541654265436544654565466547654865496550655165526553655465556556655765586559656065616562656365646565656665676568656965706571657265736574657565766577657865796580658165826583658465856586658765886589659065916592659365946595659665976598659966006601660266036604660566066607660866096610661166126613661466156616661766186619662066216622662366246625662666276628662966306631663266336634663566366637663866396640664166426643664466456646664766486649665066516652665366546655665666576658665966606661666266636664666566666667666866696670667166726673667466756676667766786679668066816682668366846685668666876688668966906691669266936694669566966697669866996700670167026703670467056706670767086709671067116712671367146715671667176718671967206721672267236724672567266727672867296730673167326733673467356736673767386739674067416742674367446745674667476748674967506751675267536754675567566757675867596760676167626763676467656766676767686769677067716772677367746775677667776778677967806781678267836784678567866787678867896790679167926793679467956796679767986799680068016802680368046805680668076808680968106811681268136814681568166817681868196820682168226823682468256826682768286829683068316832683368346835683668376838683968406841684268436844684568466847684868496850685168526853685468556856685768586859686068616862686368646865686668676868686968706871687268736874687568766877687868796880688168826883688468856886688768886889689068916892689368946895689668976898689969006901690269036904690569066907690869096910691169126913691469156916691769186919692069216922692369246925692669276928692969306931693269336934693569366937693869396940694169426943694469456946694769486949695069516952695369546955695669576958695969606961696269636964696569666967696869696970697169726973697469756976697769786979698069816982698369846985698669876988698969906991699269936994699569966997699869997000700170027003700470057006700770087009701070117012701370147015701670177018701970207021702270237024702570267027702870297030703170327033703470357036703770387039704070417042704370447045704670477048704970507051705270537054705570567057705870597060706170627063706470657066706770687069707070717072707370747075707670777078707970807081708270837084708570867087708870897090709170927093709470957096709770987099710071017102710371047105710671077108710971107111711271137114711571167117711871197120712171227123712471257126712771287129713071317132713371347135713671377138713971407141714271437144714571467147714871497150715171527153715471557156715771587159716071617162716371647165716671677168716971707171717271737174717571767177717871797180718171827183718471857186718771887189719071917192719371947195719671977198719972007201720272037204720572067207720872097210721172127213721472157216721772187219722072217222722372247225722672277228722972307231723272337234723572367237723872397240724172427243724472457246724772487249725072517252725372547255725672577258725972607261726272637264726572667267726872697270727172727273727472757276727772787279728072817282728372847285728672877288728972907291729272937294729572967297729872997300730173027303730473057306730773087309731073117312731373147315731673177318731973207321732273237324732573267327732873297330733173327333733473357336733773387339734073417342734373447345734673477348734973507351735273537354735573567357735873597360736173627363736473657366736773687369737073717372737373747375737673777378737973807381738273837384738573867387738873897390739173927393739473957396739773987399740074017402740374047405740674077408740974107411741274137414741574167417741874197420742174227423742474257426742774287429743074317432743374347435743674377438743974407441744274437444744574467447744874497450745174527453745474557456745774587459746074617462746374647465746674677468746974707471747274737474747574767477747874797480748174827483748474857486748774887489749074917492749374947495749674977498749975007501750275037504750575067507750875097510751175127513751475157516751775187519752075217522752375247525752675277528752975307531753275337534753575367537753875397540754175427543754475457546754775487549755075517552755375547555755675577558755975607561756275637564756575667567756875697570757175727573757475757576757775787579758075817582758375847585758675877588758975907591759275937594759575967597759875997600760176027603760476057606760776087609761076117612761376147615761676177618761976207621762276237624762576267627762876297630763176327633763476357636763776387639764076417642764376447645764676477648764976507651765276537654765576567657765876597660766176627663766476657666766776687669767076717672767376747675767676777678767976807681768276837684768576867687768876897690769176927693769476957696769776987699770077017702770377047705770677077708770977107711771277137714771577167717771877197720772177227723772477257726772777287729773077317732773377347735773677377738773977407741774277437744774577467747774877497750775177527753775477557756775777587759776077617762776377647765776677677768776977707771777277737774777577767777777877797780778177827783778477857786778777887789779077917792779377947795779677977798779978007801780278037804780578067807780878097810781178127813781478157816781778187819782078217822782378247825782678277828782978307831783278337834783578367837783878397840784178427843784478457846784778487849785078517852785378547855785678577858785978607861786278637864786578667867786878697870787178727873787478757876787778787879788078817882788378847885788678877888788978907891789278937894789578967897789878997900790179027903790479057906790779087909791079117912791379147915791679177918791979207921792279237924792579267927792879297930793179327933793479357936793779387939794079417942794379447945794679477948794979507951795279537954795579567957795879597960796179627963796479657966796779687969797079717972797379747975797679777978797979807981798279837984798579867987798879897990799179927993799479957996799779987999800080018002800380048005800680078008800980108011801280138014801580168017801880198020802180228023802480258026802780288029803080318032803380348035803680378038803980408041804280438044804580468047804880498050805180528053805480558056805780588059806080618062806380648065806680678068806980708071807280738074807580768077807880798080808180828083808480858086808780888089809080918092809380948095809680978098809981008101810281038104810581068107810881098110811181128113811481158116811781188119812081218122812381248125812681278128812981308131813281338134813581368137813881398140814181428143814481458146814781488149815081518152815381548155815681578158815981608161816281638164816581668167816881698170817181728173817481758176817781788179818081818182818381848185818681878188818981908191819281938194819581968197819881998200820182028203820482058206820782088209821082118212821382148215821682178218821982208221822282238224822582268227822882298230823182328233823482358236823782388239824082418242824382448245824682478248824982508251825282538254825582568257825882598260826182628263826482658266826782688269827082718272827382748275827682778278827982808281828282838284828582868287828882898290829182928293829482958296829782988299830083018302830383048305830683078308830983108311831283138314831583168317
  1. //===-- InstBuilder.cpp - SPIR-V instruction builder ------------*- C++ -*-===//
  2. //
  3. // The LLVM Compiler Infrastructure
  4. //
  5. // This file is distributed under the University of Illinois Open Source
  6. // License. See LICENSE.TXT for details.
  7. //
  8. //===----------------------------------------------------------------------===//
  9. // AUTOMATICALLY GENERATED from the SPIR-V JSON grammar:
  10. // spirv.core.grammar.json.
  11. // DO NOT MODIFY!
  12. #include "clang/SPIRV/InstBuilder.h"
  13. namespace clang {
  14. namespace spirv {
  15. static_assert(spv::Version == 0x00010200 && spv::Revision == 3,
  16. "Needs to regenerate outdated InstBuilder");
  17. namespace {
  18. inline bool bitEnumContains(spv::ImageOperandsMask bits,
  19. spv::ImageOperandsMask bit) {
  20. return (uint32_t(bits) & uint32_t(bit)) != 0;
  21. }
  22. inline bool bitEnumContains(spv::LoopControlMask bits,
  23. spv::LoopControlMask bit) {
  24. return (uint32_t(bits) & uint32_t(bit)) != 0;
  25. }
  26. inline bool bitEnumContains(spv::MemoryAccessMask bits,
  27. spv::MemoryAccessMask bit) {
  28. return (uint32_t(bits) & uint32_t(bit)) != 0;
  29. }
  30. } // namespace
  31. InstBuilder::InstBuilder(WordConsumer consumer)
  32. : TheConsumer(consumer), TheStatus(Status::Success) {}
  33. void InstBuilder::setConsumer(WordConsumer consumer) { TheConsumer = consumer; }
  34. const WordConsumer &InstBuilder::getConsumer() const { return TheConsumer; }
  35. InstBuilder::Status InstBuilder::x() {
  36. if (TheConsumer == nullptr)
  37. return Status::NullConsumer;
  38. if (TheStatus != Status::Success)
  39. return TheStatus;
  40. if (!Expectation.empty()) {
  41. switch (Expectation.front()) {
  42. case OperandKind::BuiltIn:
  43. return Status::ExpectBuiltIn;
  44. case OperandKind::FPFastMathMode:
  45. return Status::ExpectFPFastMathMode;
  46. case OperandKind::FPRoundingMode:
  47. return Status::ExpectFPRoundingMode;
  48. case OperandKind::FunctionParameterAttribute:
  49. return Status::ExpectFunctionParameterAttribute;
  50. case OperandKind::IdRef:
  51. return Status::ExpectIdRef;
  52. case OperandKind::LinkageType:
  53. return Status::ExpectLinkageType;
  54. case OperandKind::LiteralInteger:
  55. return Status::ExpectLiteralInteger;
  56. case OperandKind::LiteralString:
  57. return Status::ExpectLiteralString;
  58. }
  59. }
  60. if (!TheInst.empty())
  61. TheInst.front() |= uint32_t(TheInst.size()) << 16;
  62. TheConsumer(std::move(TheInst));
  63. TheInst.clear();
  64. return TheStatus;
  65. }
  66. void InstBuilder::clear() {
  67. TheInst.clear();
  68. Expectation.clear();
  69. TheStatus = Status::Success;
  70. }
  71. InstBuilder &InstBuilder::opNop() {
  72. if (!TheInst.empty()) {
  73. TheStatus = Status::NestedInst;
  74. return *this;
  75. }
  76. TheInst.reserve(1);
  77. TheInst.emplace_back(static_cast<uint32_t>(spv::Op::OpNop));
  78. return *this;
  79. }
  80. InstBuilder &InstBuilder::opUndef(uint32_t result_type, uint32_t result_id) {
  81. if (!TheInst.empty()) {
  82. TheStatus = Status::NestedInst;
  83. return *this;
  84. }
  85. if (result_type == 0) {
  86. TheStatus = Status::ZeroResultType;
  87. return *this;
  88. }
  89. if (result_id == 0) {
  90. TheStatus = Status::ZeroResultId;
  91. return *this;
  92. }
  93. TheInst.reserve(3);
  94. TheInst.emplace_back(static_cast<uint32_t>(spv::Op::OpUndef));
  95. TheInst.emplace_back(result_type);
  96. TheInst.emplace_back(result_id);
  97. return *this;
  98. }
  99. InstBuilder &InstBuilder::opSourceContinued(std::string continued_source) {
  100. if (!TheInst.empty()) {
  101. TheStatus = Status::NestedInst;
  102. return *this;
  103. }
  104. TheInst.reserve(2);
  105. TheInst.emplace_back(static_cast<uint32_t>(spv::Op::OpSourceContinued));
  106. encodeString(continued_source);
  107. return *this;
  108. }
  109. InstBuilder &InstBuilder::opSource(spv::SourceLanguage source_language,
  110. uint32_t version,
  111. llvm::Optional<uint32_t> file,
  112. llvm::Optional<std::string> source) {
  113. if (!TheInst.empty()) {
  114. TheStatus = Status::NestedInst;
  115. return *this;
  116. }
  117. TheInst.reserve(5);
  118. TheInst.emplace_back(static_cast<uint32_t>(spv::Op::OpSource));
  119. TheInst.emplace_back(static_cast<uint32_t>(source_language));
  120. TheInst.emplace_back(version);
  121. if (file.hasValue()) {
  122. const auto &val = file.getValue();
  123. TheInst.emplace_back(val);
  124. }
  125. if (source.hasValue()) {
  126. const auto &val = source.getValue();
  127. encodeString(val);
  128. }
  129. return *this;
  130. }
  131. InstBuilder &InstBuilder::opSourceExtension(std::string extension) {
  132. if (!TheInst.empty()) {
  133. TheStatus = Status::NestedInst;
  134. return *this;
  135. }
  136. TheInst.reserve(2);
  137. TheInst.emplace_back(static_cast<uint32_t>(spv::Op::OpSourceExtension));
  138. encodeString(extension);
  139. return *this;
  140. }
  141. InstBuilder &InstBuilder::opName(uint32_t target, std::string name) {
  142. if (!TheInst.empty()) {
  143. TheStatus = Status::NestedInst;
  144. return *this;
  145. }
  146. TheInst.reserve(3);
  147. TheInst.emplace_back(static_cast<uint32_t>(spv::Op::OpName));
  148. TheInst.emplace_back(target);
  149. encodeString(name);
  150. return *this;
  151. }
  152. InstBuilder &InstBuilder::opMemberName(uint32_t type, uint32_t member,
  153. std::string name) {
  154. if (!TheInst.empty()) {
  155. TheStatus = Status::NestedInst;
  156. return *this;
  157. }
  158. TheInst.reserve(4);
  159. TheInst.emplace_back(static_cast<uint32_t>(spv::Op::OpMemberName));
  160. TheInst.emplace_back(type);
  161. TheInst.emplace_back(member);
  162. encodeString(name);
  163. return *this;
  164. }
  165. InstBuilder &InstBuilder::opString(uint32_t result_id, std::string string) {
  166. if (!TheInst.empty()) {
  167. TheStatus = Status::NestedInst;
  168. return *this;
  169. }
  170. if (result_id == 0) {
  171. TheStatus = Status::ZeroResultId;
  172. return *this;
  173. }
  174. TheInst.reserve(3);
  175. TheInst.emplace_back(static_cast<uint32_t>(spv::Op::OpString));
  176. TheInst.emplace_back(result_id);
  177. encodeString(string);
  178. return *this;
  179. }
  180. InstBuilder &InstBuilder::opLine(uint32_t file, uint32_t line,
  181. uint32_t column) {
  182. if (!TheInst.empty()) {
  183. TheStatus = Status::NestedInst;
  184. return *this;
  185. }
  186. TheInst.reserve(4);
  187. TheInst.emplace_back(static_cast<uint32_t>(spv::Op::OpLine));
  188. TheInst.emplace_back(file);
  189. TheInst.emplace_back(line);
  190. TheInst.emplace_back(column);
  191. return *this;
  192. }
  193. InstBuilder &InstBuilder::opExtension(std::string name) {
  194. if (!TheInst.empty()) {
  195. TheStatus = Status::NestedInst;
  196. return *this;
  197. }
  198. TheInst.reserve(2);
  199. TheInst.emplace_back(static_cast<uint32_t>(spv::Op::OpExtension));
  200. encodeString(name);
  201. return *this;
  202. }
  203. InstBuilder &InstBuilder::opExtInstImport(uint32_t result_id,
  204. std::string name) {
  205. if (!TheInst.empty()) {
  206. TheStatus = Status::NestedInst;
  207. return *this;
  208. }
  209. if (result_id == 0) {
  210. TheStatus = Status::ZeroResultId;
  211. return *this;
  212. }
  213. TheInst.reserve(3);
  214. TheInst.emplace_back(static_cast<uint32_t>(spv::Op::OpExtInstImport));
  215. TheInst.emplace_back(result_id);
  216. encodeString(name);
  217. return *this;
  218. }
  219. InstBuilder &
  220. InstBuilder::opExtInst(uint32_t result_type, uint32_t result_id, uint32_t set,
  221. uint32_t instruction,
  222. llvm::ArrayRef<uint32_t> operand_1_operand_2_) {
  223. if (!TheInst.empty()) {
  224. TheStatus = Status::NestedInst;
  225. return *this;
  226. }
  227. if (result_type == 0) {
  228. TheStatus = Status::ZeroResultType;
  229. return *this;
  230. }
  231. if (result_id == 0) {
  232. TheStatus = Status::ZeroResultId;
  233. return *this;
  234. }
  235. TheInst.reserve(6);
  236. TheInst.emplace_back(static_cast<uint32_t>(spv::Op::OpExtInst));
  237. TheInst.emplace_back(result_type);
  238. TheInst.emplace_back(result_id);
  239. TheInst.emplace_back(set);
  240. TheInst.emplace_back(instruction);
  241. TheInst.insert(TheInst.end(), operand_1_operand_2_.begin(),
  242. operand_1_operand_2_.end());
  243. return *this;
  244. }
  245. InstBuilder &InstBuilder::opMemoryModel(spv::AddressingModel addressing_model,
  246. spv::MemoryModel memory_model) {
  247. if (!TheInst.empty()) {
  248. TheStatus = Status::NestedInst;
  249. return *this;
  250. }
  251. TheInst.reserve(3);
  252. TheInst.emplace_back(static_cast<uint32_t>(spv::Op::OpMemoryModel));
  253. TheInst.emplace_back(static_cast<uint32_t>(addressing_model));
  254. TheInst.emplace_back(static_cast<uint32_t>(memory_model));
  255. return *this;
  256. }
  257. InstBuilder &InstBuilder::opEntryPoint(spv::ExecutionModel execution_model,
  258. uint32_t entry_point, std::string name,
  259. llvm::ArrayRef<uint32_t> interface) {
  260. if (!TheInst.empty()) {
  261. TheStatus = Status::NestedInst;
  262. return *this;
  263. }
  264. TheInst.reserve(5);
  265. TheInst.emplace_back(static_cast<uint32_t>(spv::Op::OpEntryPoint));
  266. TheInst.emplace_back(static_cast<uint32_t>(execution_model));
  267. TheInst.emplace_back(entry_point);
  268. encodeString(name);
  269. TheInst.insert(TheInst.end(), interface.begin(), interface.end());
  270. return *this;
  271. }
  272. InstBuilder &InstBuilder::opExecutionMode(uint32_t entry_point,
  273. spv::ExecutionMode mode) {
  274. if (!TheInst.empty()) {
  275. TheStatus = Status::NestedInst;
  276. return *this;
  277. }
  278. TheInst.reserve(3);
  279. TheInst.emplace_back(static_cast<uint32_t>(spv::Op::OpExecutionMode));
  280. TheInst.emplace_back(entry_point);
  281. encodeExecutionMode(mode);
  282. return *this;
  283. }
  284. InstBuilder &InstBuilder::opCapability(spv::Capability capability) {
  285. if (!TheInst.empty()) {
  286. TheStatus = Status::NestedInst;
  287. return *this;
  288. }
  289. TheInst.reserve(2);
  290. TheInst.emplace_back(static_cast<uint32_t>(spv::Op::OpCapability));
  291. TheInst.emplace_back(static_cast<uint32_t>(capability));
  292. return *this;
  293. }
  294. InstBuilder &InstBuilder::opTypeVoid(uint32_t result_id) {
  295. if (!TheInst.empty()) {
  296. TheStatus = Status::NestedInst;
  297. return *this;
  298. }
  299. if (result_id == 0) {
  300. TheStatus = Status::ZeroResultId;
  301. return *this;
  302. }
  303. TheInst.reserve(2);
  304. TheInst.emplace_back(static_cast<uint32_t>(spv::Op::OpTypeVoid));
  305. TheInst.emplace_back(result_id);
  306. return *this;
  307. }
  308. InstBuilder &InstBuilder::opTypeBool(uint32_t result_id) {
  309. if (!TheInst.empty()) {
  310. TheStatus = Status::NestedInst;
  311. return *this;
  312. }
  313. if (result_id == 0) {
  314. TheStatus = Status::ZeroResultId;
  315. return *this;
  316. }
  317. TheInst.reserve(2);
  318. TheInst.emplace_back(static_cast<uint32_t>(spv::Op::OpTypeBool));
  319. TheInst.emplace_back(result_id);
  320. return *this;
  321. }
  322. InstBuilder &InstBuilder::opTypeInt(uint32_t result_id, uint32_t width,
  323. uint32_t signedness) {
  324. if (!TheInst.empty()) {
  325. TheStatus = Status::NestedInst;
  326. return *this;
  327. }
  328. if (result_id == 0) {
  329. TheStatus = Status::ZeroResultId;
  330. return *this;
  331. }
  332. TheInst.reserve(4);
  333. TheInst.emplace_back(static_cast<uint32_t>(spv::Op::OpTypeInt));
  334. TheInst.emplace_back(result_id);
  335. TheInst.emplace_back(width);
  336. TheInst.emplace_back(signedness);
  337. return *this;
  338. }
  339. InstBuilder &InstBuilder::opTypeFloat(uint32_t result_id, uint32_t width) {
  340. if (!TheInst.empty()) {
  341. TheStatus = Status::NestedInst;
  342. return *this;
  343. }
  344. if (result_id == 0) {
  345. TheStatus = Status::ZeroResultId;
  346. return *this;
  347. }
  348. TheInst.reserve(3);
  349. TheInst.emplace_back(static_cast<uint32_t>(spv::Op::OpTypeFloat));
  350. TheInst.emplace_back(result_id);
  351. TheInst.emplace_back(width);
  352. return *this;
  353. }
  354. InstBuilder &InstBuilder::opTypeVector(uint32_t result_id,
  355. uint32_t component_type,
  356. uint32_t component_count) {
  357. if (!TheInst.empty()) {
  358. TheStatus = Status::NestedInst;
  359. return *this;
  360. }
  361. if (result_id == 0) {
  362. TheStatus = Status::ZeroResultId;
  363. return *this;
  364. }
  365. TheInst.reserve(4);
  366. TheInst.emplace_back(static_cast<uint32_t>(spv::Op::OpTypeVector));
  367. TheInst.emplace_back(result_id);
  368. TheInst.emplace_back(component_type);
  369. TheInst.emplace_back(component_count);
  370. return *this;
  371. }
  372. InstBuilder &InstBuilder::opTypeMatrix(uint32_t result_id, uint32_t column_type,
  373. uint32_t column_count) {
  374. if (!TheInst.empty()) {
  375. TheStatus = Status::NestedInst;
  376. return *this;
  377. }
  378. if (result_id == 0) {
  379. TheStatus = Status::ZeroResultId;
  380. return *this;
  381. }
  382. TheInst.reserve(4);
  383. TheInst.emplace_back(static_cast<uint32_t>(spv::Op::OpTypeMatrix));
  384. TheInst.emplace_back(result_id);
  385. TheInst.emplace_back(column_type);
  386. TheInst.emplace_back(column_count);
  387. return *this;
  388. }
  389. InstBuilder &InstBuilder::opTypeImage(
  390. uint32_t result_id, uint32_t sampled_type, spv::Dim dim, uint32_t depth,
  391. uint32_t arrayed, uint32_t ms, uint32_t sampled,
  392. spv::ImageFormat image_format,
  393. llvm::Optional<spv::AccessQualifier> access_qualifier) {
  394. if (!TheInst.empty()) {
  395. TheStatus = Status::NestedInst;
  396. return *this;
  397. }
  398. if (result_id == 0) {
  399. TheStatus = Status::ZeroResultId;
  400. return *this;
  401. }
  402. TheInst.reserve(10);
  403. TheInst.emplace_back(static_cast<uint32_t>(spv::Op::OpTypeImage));
  404. TheInst.emplace_back(result_id);
  405. TheInst.emplace_back(sampled_type);
  406. TheInst.emplace_back(static_cast<uint32_t>(dim));
  407. TheInst.emplace_back(depth);
  408. TheInst.emplace_back(arrayed);
  409. TheInst.emplace_back(ms);
  410. TheInst.emplace_back(sampled);
  411. TheInst.emplace_back(static_cast<uint32_t>(image_format));
  412. if (access_qualifier.hasValue()) {
  413. const auto &val = access_qualifier.getValue();
  414. TheInst.emplace_back(static_cast<uint32_t>(val));
  415. }
  416. return *this;
  417. }
  418. InstBuilder &InstBuilder::opTypeSampler(uint32_t result_id) {
  419. if (!TheInst.empty()) {
  420. TheStatus = Status::NestedInst;
  421. return *this;
  422. }
  423. if (result_id == 0) {
  424. TheStatus = Status::ZeroResultId;
  425. return *this;
  426. }
  427. TheInst.reserve(2);
  428. TheInst.emplace_back(static_cast<uint32_t>(spv::Op::OpTypeSampler));
  429. TheInst.emplace_back(result_id);
  430. return *this;
  431. }
  432. InstBuilder &InstBuilder::opTypeSampledImage(uint32_t result_id,
  433. uint32_t image_type) {
  434. if (!TheInst.empty()) {
  435. TheStatus = Status::NestedInst;
  436. return *this;
  437. }
  438. if (result_id == 0) {
  439. TheStatus = Status::ZeroResultId;
  440. return *this;
  441. }
  442. TheInst.reserve(3);
  443. TheInst.emplace_back(static_cast<uint32_t>(spv::Op::OpTypeSampledImage));
  444. TheInst.emplace_back(result_id);
  445. TheInst.emplace_back(image_type);
  446. return *this;
  447. }
  448. InstBuilder &InstBuilder::opTypeArray(uint32_t result_id, uint32_t element_type,
  449. uint32_t length) {
  450. if (!TheInst.empty()) {
  451. TheStatus = Status::NestedInst;
  452. return *this;
  453. }
  454. if (result_id == 0) {
  455. TheStatus = Status::ZeroResultId;
  456. return *this;
  457. }
  458. TheInst.reserve(4);
  459. TheInst.emplace_back(static_cast<uint32_t>(spv::Op::OpTypeArray));
  460. TheInst.emplace_back(result_id);
  461. TheInst.emplace_back(element_type);
  462. TheInst.emplace_back(length);
  463. return *this;
  464. }
  465. InstBuilder &InstBuilder::opTypeRuntimeArray(uint32_t result_id,
  466. uint32_t element_type) {
  467. if (!TheInst.empty()) {
  468. TheStatus = Status::NestedInst;
  469. return *this;
  470. }
  471. if (result_id == 0) {
  472. TheStatus = Status::ZeroResultId;
  473. return *this;
  474. }
  475. TheInst.reserve(3);
  476. TheInst.emplace_back(static_cast<uint32_t>(spv::Op::OpTypeRuntimeArray));
  477. TheInst.emplace_back(result_id);
  478. TheInst.emplace_back(element_type);
  479. return *this;
  480. }
  481. InstBuilder &InstBuilder::opTypeStruct(
  482. uint32_t result_id, llvm::ArrayRef<uint32_t> member_0_type_member_1_type_) {
  483. if (!TheInst.empty()) {
  484. TheStatus = Status::NestedInst;
  485. return *this;
  486. }
  487. if (result_id == 0) {
  488. TheStatus = Status::ZeroResultId;
  489. return *this;
  490. }
  491. TheInst.reserve(3);
  492. TheInst.emplace_back(static_cast<uint32_t>(spv::Op::OpTypeStruct));
  493. TheInst.emplace_back(result_id);
  494. TheInst.insert(TheInst.end(), member_0_type_member_1_type_.begin(),
  495. member_0_type_member_1_type_.end());
  496. return *this;
  497. }
  498. InstBuilder &
  499. InstBuilder::opTypeOpaque(uint32_t result_id,
  500. std::string the_name_of_the_opaque_type) {
  501. if (!TheInst.empty()) {
  502. TheStatus = Status::NestedInst;
  503. return *this;
  504. }
  505. if (result_id == 0) {
  506. TheStatus = Status::ZeroResultId;
  507. return *this;
  508. }
  509. TheInst.reserve(3);
  510. TheInst.emplace_back(static_cast<uint32_t>(spv::Op::OpTypeOpaque));
  511. TheInst.emplace_back(result_id);
  512. encodeString(the_name_of_the_opaque_type);
  513. return *this;
  514. }
  515. InstBuilder &InstBuilder::opTypePointer(uint32_t result_id,
  516. spv::StorageClass storage_class,
  517. uint32_t type) {
  518. if (!TheInst.empty()) {
  519. TheStatus = Status::NestedInst;
  520. return *this;
  521. }
  522. if (result_id == 0) {
  523. TheStatus = Status::ZeroResultId;
  524. return *this;
  525. }
  526. TheInst.reserve(4);
  527. TheInst.emplace_back(static_cast<uint32_t>(spv::Op::OpTypePointer));
  528. TheInst.emplace_back(result_id);
  529. TheInst.emplace_back(static_cast<uint32_t>(storage_class));
  530. TheInst.emplace_back(type);
  531. return *this;
  532. }
  533. InstBuilder &InstBuilder::opTypeFunction(
  534. uint32_t result_id, uint32_t return_type,
  535. llvm::ArrayRef<uint32_t> parameter_0_type_parameter_1_type_) {
  536. if (!TheInst.empty()) {
  537. TheStatus = Status::NestedInst;
  538. return *this;
  539. }
  540. if (result_id == 0) {
  541. TheStatus = Status::ZeroResultId;
  542. return *this;
  543. }
  544. TheInst.reserve(4);
  545. TheInst.emplace_back(static_cast<uint32_t>(spv::Op::OpTypeFunction));
  546. TheInst.emplace_back(result_id);
  547. TheInst.emplace_back(return_type);
  548. TheInst.insert(TheInst.end(), parameter_0_type_parameter_1_type_.begin(),
  549. parameter_0_type_parameter_1_type_.end());
  550. return *this;
  551. }
  552. InstBuilder &InstBuilder::opTypeEvent(uint32_t result_id) {
  553. if (!TheInst.empty()) {
  554. TheStatus = Status::NestedInst;
  555. return *this;
  556. }
  557. if (result_id == 0) {
  558. TheStatus = Status::ZeroResultId;
  559. return *this;
  560. }
  561. TheInst.reserve(2);
  562. TheInst.emplace_back(static_cast<uint32_t>(spv::Op::OpTypeEvent));
  563. TheInst.emplace_back(result_id);
  564. return *this;
  565. }
  566. InstBuilder &InstBuilder::opTypeDeviceEvent(uint32_t result_id) {
  567. if (!TheInst.empty()) {
  568. TheStatus = Status::NestedInst;
  569. return *this;
  570. }
  571. if (result_id == 0) {
  572. TheStatus = Status::ZeroResultId;
  573. return *this;
  574. }
  575. TheInst.reserve(2);
  576. TheInst.emplace_back(static_cast<uint32_t>(spv::Op::OpTypeDeviceEvent));
  577. TheInst.emplace_back(result_id);
  578. return *this;
  579. }
  580. InstBuilder &InstBuilder::opTypeReserveId(uint32_t result_id) {
  581. if (!TheInst.empty()) {
  582. TheStatus = Status::NestedInst;
  583. return *this;
  584. }
  585. if (result_id == 0) {
  586. TheStatus = Status::ZeroResultId;
  587. return *this;
  588. }
  589. TheInst.reserve(2);
  590. TheInst.emplace_back(static_cast<uint32_t>(spv::Op::OpTypeReserveId));
  591. TheInst.emplace_back(result_id);
  592. return *this;
  593. }
  594. InstBuilder &InstBuilder::opTypeQueue(uint32_t result_id) {
  595. if (!TheInst.empty()) {
  596. TheStatus = Status::NestedInst;
  597. return *this;
  598. }
  599. if (result_id == 0) {
  600. TheStatus = Status::ZeroResultId;
  601. return *this;
  602. }
  603. TheInst.reserve(2);
  604. TheInst.emplace_back(static_cast<uint32_t>(spv::Op::OpTypeQueue));
  605. TheInst.emplace_back(result_id);
  606. return *this;
  607. }
  608. InstBuilder &InstBuilder::opTypePipe(uint32_t result_id,
  609. spv::AccessQualifier qualifier) {
  610. if (!TheInst.empty()) {
  611. TheStatus = Status::NestedInst;
  612. return *this;
  613. }
  614. if (result_id == 0) {
  615. TheStatus = Status::ZeroResultId;
  616. return *this;
  617. }
  618. TheInst.reserve(3);
  619. TheInst.emplace_back(static_cast<uint32_t>(spv::Op::OpTypePipe));
  620. TheInst.emplace_back(result_id);
  621. TheInst.emplace_back(static_cast<uint32_t>(qualifier));
  622. return *this;
  623. }
  624. InstBuilder &
  625. InstBuilder::opTypeForwardPointer(uint32_t pointer_type,
  626. spv::StorageClass storage_class) {
  627. if (!TheInst.empty()) {
  628. TheStatus = Status::NestedInst;
  629. return *this;
  630. }
  631. TheInst.reserve(3);
  632. TheInst.emplace_back(static_cast<uint32_t>(spv::Op::OpTypeForwardPointer));
  633. TheInst.emplace_back(pointer_type);
  634. TheInst.emplace_back(static_cast<uint32_t>(storage_class));
  635. return *this;
  636. }
  637. InstBuilder &InstBuilder::opConstantTrue(uint32_t result_type,
  638. uint32_t result_id) {
  639. if (!TheInst.empty()) {
  640. TheStatus = Status::NestedInst;
  641. return *this;
  642. }
  643. if (result_type == 0) {
  644. TheStatus = Status::ZeroResultType;
  645. return *this;
  646. }
  647. if (result_id == 0) {
  648. TheStatus = Status::ZeroResultId;
  649. return *this;
  650. }
  651. TheInst.reserve(3);
  652. TheInst.emplace_back(static_cast<uint32_t>(spv::Op::OpConstantTrue));
  653. TheInst.emplace_back(result_type);
  654. TheInst.emplace_back(result_id);
  655. return *this;
  656. }
  657. InstBuilder &InstBuilder::opConstantFalse(uint32_t result_type,
  658. uint32_t result_id) {
  659. if (!TheInst.empty()) {
  660. TheStatus = Status::NestedInst;
  661. return *this;
  662. }
  663. if (result_type == 0) {
  664. TheStatus = Status::ZeroResultType;
  665. return *this;
  666. }
  667. if (result_id == 0) {
  668. TheStatus = Status::ZeroResultId;
  669. return *this;
  670. }
  671. TheInst.reserve(3);
  672. TheInst.emplace_back(static_cast<uint32_t>(spv::Op::OpConstantFalse));
  673. TheInst.emplace_back(result_type);
  674. TheInst.emplace_back(result_id);
  675. return *this;
  676. }
  677. InstBuilder &
  678. InstBuilder::opConstantComposite(uint32_t result_type, uint32_t result_id,
  679. llvm::ArrayRef<uint32_t> constituents) {
  680. if (!TheInst.empty()) {
  681. TheStatus = Status::NestedInst;
  682. return *this;
  683. }
  684. if (result_type == 0) {
  685. TheStatus = Status::ZeroResultType;
  686. return *this;
  687. }
  688. if (result_id == 0) {
  689. TheStatus = Status::ZeroResultId;
  690. return *this;
  691. }
  692. TheInst.reserve(4);
  693. TheInst.emplace_back(static_cast<uint32_t>(spv::Op::OpConstantComposite));
  694. TheInst.emplace_back(result_type);
  695. TheInst.emplace_back(result_id);
  696. TheInst.insert(TheInst.end(), constituents.begin(), constituents.end());
  697. return *this;
  698. }
  699. InstBuilder &InstBuilder::opConstantSampler(
  700. uint32_t result_type, uint32_t result_id,
  701. spv::SamplerAddressingMode sampler_addressing_mode, uint32_t param,
  702. spv::SamplerFilterMode sampler_filter_mode) {
  703. if (!TheInst.empty()) {
  704. TheStatus = Status::NestedInst;
  705. return *this;
  706. }
  707. if (result_type == 0) {
  708. TheStatus = Status::ZeroResultType;
  709. return *this;
  710. }
  711. if (result_id == 0) {
  712. TheStatus = Status::ZeroResultId;
  713. return *this;
  714. }
  715. TheInst.reserve(6);
  716. TheInst.emplace_back(static_cast<uint32_t>(spv::Op::OpConstantSampler));
  717. TheInst.emplace_back(result_type);
  718. TheInst.emplace_back(result_id);
  719. TheInst.emplace_back(static_cast<uint32_t>(sampler_addressing_mode));
  720. TheInst.emplace_back(param);
  721. TheInst.emplace_back(static_cast<uint32_t>(sampler_filter_mode));
  722. return *this;
  723. }
  724. InstBuilder &InstBuilder::opConstantNull(uint32_t result_type,
  725. uint32_t result_id) {
  726. if (!TheInst.empty()) {
  727. TheStatus = Status::NestedInst;
  728. return *this;
  729. }
  730. if (result_type == 0) {
  731. TheStatus = Status::ZeroResultType;
  732. return *this;
  733. }
  734. if (result_id == 0) {
  735. TheStatus = Status::ZeroResultId;
  736. return *this;
  737. }
  738. TheInst.reserve(3);
  739. TheInst.emplace_back(static_cast<uint32_t>(spv::Op::OpConstantNull));
  740. TheInst.emplace_back(result_type);
  741. TheInst.emplace_back(result_id);
  742. return *this;
  743. }
  744. InstBuilder &InstBuilder::opSpecConstantTrue(uint32_t result_type,
  745. uint32_t result_id) {
  746. if (!TheInst.empty()) {
  747. TheStatus = Status::NestedInst;
  748. return *this;
  749. }
  750. if (result_type == 0) {
  751. TheStatus = Status::ZeroResultType;
  752. return *this;
  753. }
  754. if (result_id == 0) {
  755. TheStatus = Status::ZeroResultId;
  756. return *this;
  757. }
  758. TheInst.reserve(3);
  759. TheInst.emplace_back(static_cast<uint32_t>(spv::Op::OpSpecConstantTrue));
  760. TheInst.emplace_back(result_type);
  761. TheInst.emplace_back(result_id);
  762. return *this;
  763. }
  764. InstBuilder &InstBuilder::opSpecConstantFalse(uint32_t result_type,
  765. uint32_t result_id) {
  766. if (!TheInst.empty()) {
  767. TheStatus = Status::NestedInst;
  768. return *this;
  769. }
  770. if (result_type == 0) {
  771. TheStatus = Status::ZeroResultType;
  772. return *this;
  773. }
  774. if (result_id == 0) {
  775. TheStatus = Status::ZeroResultId;
  776. return *this;
  777. }
  778. TheInst.reserve(3);
  779. TheInst.emplace_back(static_cast<uint32_t>(spv::Op::OpSpecConstantFalse));
  780. TheInst.emplace_back(result_type);
  781. TheInst.emplace_back(result_id);
  782. return *this;
  783. }
  784. InstBuilder &
  785. InstBuilder::opSpecConstantComposite(uint32_t result_type, uint32_t result_id,
  786. llvm::ArrayRef<uint32_t> constituents) {
  787. if (!TheInst.empty()) {
  788. TheStatus = Status::NestedInst;
  789. return *this;
  790. }
  791. if (result_type == 0) {
  792. TheStatus = Status::ZeroResultType;
  793. return *this;
  794. }
  795. if (result_id == 0) {
  796. TheStatus = Status::ZeroResultId;
  797. return *this;
  798. }
  799. TheInst.reserve(4);
  800. TheInst.emplace_back(static_cast<uint32_t>(spv::Op::OpSpecConstantComposite));
  801. TheInst.emplace_back(result_type);
  802. TheInst.emplace_back(result_id);
  803. TheInst.insert(TheInst.end(), constituents.begin(), constituents.end());
  804. return *this;
  805. }
  806. InstBuilder &InstBuilder::opSpecConstantOp(uint32_t result_type,
  807. uint32_t result_id, spv::Op opcode) {
  808. if (!TheInst.empty()) {
  809. TheStatus = Status::NestedInst;
  810. return *this;
  811. }
  812. if (result_type == 0) {
  813. TheStatus = Status::ZeroResultType;
  814. return *this;
  815. }
  816. if (result_id == 0) {
  817. TheStatus = Status::ZeroResultId;
  818. return *this;
  819. }
  820. TheInst.reserve(4);
  821. TheInst.emplace_back(static_cast<uint32_t>(spv::Op::OpSpecConstantOp));
  822. TheInst.emplace_back(result_type);
  823. TheInst.emplace_back(result_id);
  824. TheInst.emplace_back(static_cast<uint32_t>(opcode));
  825. return *this;
  826. }
  827. InstBuilder &InstBuilder::opFunction(uint32_t result_type, uint32_t result_id,
  828. spv::FunctionControlMask function_control,
  829. uint32_t function_type) {
  830. if (!TheInst.empty()) {
  831. TheStatus = Status::NestedInst;
  832. return *this;
  833. }
  834. if (result_type == 0) {
  835. TheStatus = Status::ZeroResultType;
  836. return *this;
  837. }
  838. if (result_id == 0) {
  839. TheStatus = Status::ZeroResultId;
  840. return *this;
  841. }
  842. TheInst.reserve(5);
  843. TheInst.emplace_back(static_cast<uint32_t>(spv::Op::OpFunction));
  844. TheInst.emplace_back(result_type);
  845. TheInst.emplace_back(result_id);
  846. TheInst.emplace_back(static_cast<uint32_t>(function_control));
  847. TheInst.emplace_back(function_type);
  848. return *this;
  849. }
  850. InstBuilder &InstBuilder::opFunctionParameter(uint32_t result_type,
  851. uint32_t result_id) {
  852. if (!TheInst.empty()) {
  853. TheStatus = Status::NestedInst;
  854. return *this;
  855. }
  856. if (result_type == 0) {
  857. TheStatus = Status::ZeroResultType;
  858. return *this;
  859. }
  860. if (result_id == 0) {
  861. TheStatus = Status::ZeroResultId;
  862. return *this;
  863. }
  864. TheInst.reserve(3);
  865. TheInst.emplace_back(static_cast<uint32_t>(spv::Op::OpFunctionParameter));
  866. TheInst.emplace_back(result_type);
  867. TheInst.emplace_back(result_id);
  868. return *this;
  869. }
  870. InstBuilder &InstBuilder::opFunctionEnd() {
  871. if (!TheInst.empty()) {
  872. TheStatus = Status::NestedInst;
  873. return *this;
  874. }
  875. TheInst.reserve(1);
  876. TheInst.emplace_back(static_cast<uint32_t>(spv::Op::OpFunctionEnd));
  877. return *this;
  878. }
  879. InstBuilder &
  880. InstBuilder::opFunctionCall(uint32_t result_type, uint32_t result_id,
  881. uint32_t function,
  882. llvm::ArrayRef<uint32_t> argument_0_argument_1_) {
  883. if (!TheInst.empty()) {
  884. TheStatus = Status::NestedInst;
  885. return *this;
  886. }
  887. if (result_type == 0) {
  888. TheStatus = Status::ZeroResultType;
  889. return *this;
  890. }
  891. if (result_id == 0) {
  892. TheStatus = Status::ZeroResultId;
  893. return *this;
  894. }
  895. TheInst.reserve(5);
  896. TheInst.emplace_back(static_cast<uint32_t>(spv::Op::OpFunctionCall));
  897. TheInst.emplace_back(result_type);
  898. TheInst.emplace_back(result_id);
  899. TheInst.emplace_back(function);
  900. TheInst.insert(TheInst.end(), argument_0_argument_1_.begin(),
  901. argument_0_argument_1_.end());
  902. return *this;
  903. }
  904. InstBuilder &InstBuilder::opVariable(uint32_t result_type, uint32_t result_id,
  905. spv::StorageClass storage_class,
  906. llvm::Optional<uint32_t> initializer) {
  907. if (!TheInst.empty()) {
  908. TheStatus = Status::NestedInst;
  909. return *this;
  910. }
  911. if (result_type == 0) {
  912. TheStatus = Status::ZeroResultType;
  913. return *this;
  914. }
  915. if (result_id == 0) {
  916. TheStatus = Status::ZeroResultId;
  917. return *this;
  918. }
  919. TheInst.reserve(5);
  920. TheInst.emplace_back(static_cast<uint32_t>(spv::Op::OpVariable));
  921. TheInst.emplace_back(result_type);
  922. TheInst.emplace_back(result_id);
  923. TheInst.emplace_back(static_cast<uint32_t>(storage_class));
  924. if (initializer.hasValue()) {
  925. const auto &val = initializer.getValue();
  926. TheInst.emplace_back(val);
  927. }
  928. return *this;
  929. }
  930. InstBuilder &InstBuilder::opImageTexelPointer(uint32_t result_type,
  931. uint32_t result_id,
  932. uint32_t image,
  933. uint32_t coordinate,
  934. uint32_t sample) {
  935. if (!TheInst.empty()) {
  936. TheStatus = Status::NestedInst;
  937. return *this;
  938. }
  939. if (result_type == 0) {
  940. TheStatus = Status::ZeroResultType;
  941. return *this;
  942. }
  943. if (result_id == 0) {
  944. TheStatus = Status::ZeroResultId;
  945. return *this;
  946. }
  947. TheInst.reserve(6);
  948. TheInst.emplace_back(static_cast<uint32_t>(spv::Op::OpImageTexelPointer));
  949. TheInst.emplace_back(result_type);
  950. TheInst.emplace_back(result_id);
  951. TheInst.emplace_back(image);
  952. TheInst.emplace_back(coordinate);
  953. TheInst.emplace_back(sample);
  954. return *this;
  955. }
  956. InstBuilder &
  957. InstBuilder::opLoad(uint32_t result_type, uint32_t result_id, uint32_t pointer,
  958. llvm::Optional<spv::MemoryAccessMask> memory_access) {
  959. if (!TheInst.empty()) {
  960. TheStatus = Status::NestedInst;
  961. return *this;
  962. }
  963. if (result_type == 0) {
  964. TheStatus = Status::ZeroResultType;
  965. return *this;
  966. }
  967. if (result_id == 0) {
  968. TheStatus = Status::ZeroResultId;
  969. return *this;
  970. }
  971. TheInst.reserve(5);
  972. TheInst.emplace_back(static_cast<uint32_t>(spv::Op::OpLoad));
  973. TheInst.emplace_back(result_type);
  974. TheInst.emplace_back(result_id);
  975. TheInst.emplace_back(pointer);
  976. if (memory_access.hasValue()) {
  977. const auto &val = memory_access.getValue();
  978. encodeMemoryAccess(val);
  979. }
  980. return *this;
  981. }
  982. InstBuilder &
  983. InstBuilder::opStore(uint32_t pointer, uint32_t object,
  984. llvm::Optional<spv::MemoryAccessMask> memory_access) {
  985. if (!TheInst.empty()) {
  986. TheStatus = Status::NestedInst;
  987. return *this;
  988. }
  989. TheInst.reserve(4);
  990. TheInst.emplace_back(static_cast<uint32_t>(spv::Op::OpStore));
  991. TheInst.emplace_back(pointer);
  992. TheInst.emplace_back(object);
  993. if (memory_access.hasValue()) {
  994. const auto &val = memory_access.getValue();
  995. encodeMemoryAccess(val);
  996. }
  997. return *this;
  998. }
  999. InstBuilder &
  1000. InstBuilder::opCopyMemory(uint32_t target, uint32_t source,
  1001. llvm::Optional<spv::MemoryAccessMask> memory_access) {
  1002. if (!TheInst.empty()) {
  1003. TheStatus = Status::NestedInst;
  1004. return *this;
  1005. }
  1006. TheInst.reserve(4);
  1007. TheInst.emplace_back(static_cast<uint32_t>(spv::Op::OpCopyMemory));
  1008. TheInst.emplace_back(target);
  1009. TheInst.emplace_back(source);
  1010. if (memory_access.hasValue()) {
  1011. const auto &val = memory_access.getValue();
  1012. encodeMemoryAccess(val);
  1013. }
  1014. return *this;
  1015. }
  1016. InstBuilder &InstBuilder::opCopyMemorySized(
  1017. uint32_t target, uint32_t source, uint32_t size,
  1018. llvm::Optional<spv::MemoryAccessMask> memory_access) {
  1019. if (!TheInst.empty()) {
  1020. TheStatus = Status::NestedInst;
  1021. return *this;
  1022. }
  1023. TheInst.reserve(5);
  1024. TheInst.emplace_back(static_cast<uint32_t>(spv::Op::OpCopyMemorySized));
  1025. TheInst.emplace_back(target);
  1026. TheInst.emplace_back(source);
  1027. TheInst.emplace_back(size);
  1028. if (memory_access.hasValue()) {
  1029. const auto &val = memory_access.getValue();
  1030. encodeMemoryAccess(val);
  1031. }
  1032. return *this;
  1033. }
  1034. InstBuilder &InstBuilder::opAccessChain(uint32_t result_type,
  1035. uint32_t result_id, uint32_t base,
  1036. llvm::ArrayRef<uint32_t> indexes) {
  1037. if (!TheInst.empty()) {
  1038. TheStatus = Status::NestedInst;
  1039. return *this;
  1040. }
  1041. if (result_type == 0) {
  1042. TheStatus = Status::ZeroResultType;
  1043. return *this;
  1044. }
  1045. if (result_id == 0) {
  1046. TheStatus = Status::ZeroResultId;
  1047. return *this;
  1048. }
  1049. TheInst.reserve(5);
  1050. TheInst.emplace_back(static_cast<uint32_t>(spv::Op::OpAccessChain));
  1051. TheInst.emplace_back(result_type);
  1052. TheInst.emplace_back(result_id);
  1053. TheInst.emplace_back(base);
  1054. TheInst.insert(TheInst.end(), indexes.begin(), indexes.end());
  1055. return *this;
  1056. }
  1057. InstBuilder &
  1058. InstBuilder::opInBoundsAccessChain(uint32_t result_type, uint32_t result_id,
  1059. uint32_t base,
  1060. llvm::ArrayRef<uint32_t> indexes) {
  1061. if (!TheInst.empty()) {
  1062. TheStatus = Status::NestedInst;
  1063. return *this;
  1064. }
  1065. if (result_type == 0) {
  1066. TheStatus = Status::ZeroResultType;
  1067. return *this;
  1068. }
  1069. if (result_id == 0) {
  1070. TheStatus = Status::ZeroResultId;
  1071. return *this;
  1072. }
  1073. TheInst.reserve(5);
  1074. TheInst.emplace_back(static_cast<uint32_t>(spv::Op::OpInBoundsAccessChain));
  1075. TheInst.emplace_back(result_type);
  1076. TheInst.emplace_back(result_id);
  1077. TheInst.emplace_back(base);
  1078. TheInst.insert(TheInst.end(), indexes.begin(), indexes.end());
  1079. return *this;
  1080. }
  1081. InstBuilder &InstBuilder::opPtrAccessChain(uint32_t result_type,
  1082. uint32_t result_id, uint32_t base,
  1083. uint32_t element,
  1084. llvm::ArrayRef<uint32_t> indexes) {
  1085. if (!TheInst.empty()) {
  1086. TheStatus = Status::NestedInst;
  1087. return *this;
  1088. }
  1089. if (result_type == 0) {
  1090. TheStatus = Status::ZeroResultType;
  1091. return *this;
  1092. }
  1093. if (result_id == 0) {
  1094. TheStatus = Status::ZeroResultId;
  1095. return *this;
  1096. }
  1097. TheInst.reserve(6);
  1098. TheInst.emplace_back(static_cast<uint32_t>(spv::Op::OpPtrAccessChain));
  1099. TheInst.emplace_back(result_type);
  1100. TheInst.emplace_back(result_id);
  1101. TheInst.emplace_back(base);
  1102. TheInst.emplace_back(element);
  1103. TheInst.insert(TheInst.end(), indexes.begin(), indexes.end());
  1104. return *this;
  1105. }
  1106. InstBuilder &InstBuilder::opArrayLength(uint32_t result_type,
  1107. uint32_t result_id, uint32_t structure,
  1108. uint32_t array_member) {
  1109. if (!TheInst.empty()) {
  1110. TheStatus = Status::NestedInst;
  1111. return *this;
  1112. }
  1113. if (result_type == 0) {
  1114. TheStatus = Status::ZeroResultType;
  1115. return *this;
  1116. }
  1117. if (result_id == 0) {
  1118. TheStatus = Status::ZeroResultId;
  1119. return *this;
  1120. }
  1121. TheInst.reserve(5);
  1122. TheInst.emplace_back(static_cast<uint32_t>(spv::Op::OpArrayLength));
  1123. TheInst.emplace_back(result_type);
  1124. TheInst.emplace_back(result_id);
  1125. TheInst.emplace_back(structure);
  1126. TheInst.emplace_back(array_member);
  1127. return *this;
  1128. }
  1129. InstBuilder &InstBuilder::opGenericPtrMemSemantics(uint32_t result_type,
  1130. uint32_t result_id,
  1131. uint32_t pointer) {
  1132. if (!TheInst.empty()) {
  1133. TheStatus = Status::NestedInst;
  1134. return *this;
  1135. }
  1136. if (result_type == 0) {
  1137. TheStatus = Status::ZeroResultType;
  1138. return *this;
  1139. }
  1140. if (result_id == 0) {
  1141. TheStatus = Status::ZeroResultId;
  1142. return *this;
  1143. }
  1144. TheInst.reserve(4);
  1145. TheInst.emplace_back(
  1146. static_cast<uint32_t>(spv::Op::OpGenericPtrMemSemantics));
  1147. TheInst.emplace_back(result_type);
  1148. TheInst.emplace_back(result_id);
  1149. TheInst.emplace_back(pointer);
  1150. return *this;
  1151. }
  1152. InstBuilder &
  1153. InstBuilder::opInBoundsPtrAccessChain(uint32_t result_type, uint32_t result_id,
  1154. uint32_t base, uint32_t element,
  1155. llvm::ArrayRef<uint32_t> indexes) {
  1156. if (!TheInst.empty()) {
  1157. TheStatus = Status::NestedInst;
  1158. return *this;
  1159. }
  1160. if (result_type == 0) {
  1161. TheStatus = Status::ZeroResultType;
  1162. return *this;
  1163. }
  1164. if (result_id == 0) {
  1165. TheStatus = Status::ZeroResultId;
  1166. return *this;
  1167. }
  1168. TheInst.reserve(6);
  1169. TheInst.emplace_back(
  1170. static_cast<uint32_t>(spv::Op::OpInBoundsPtrAccessChain));
  1171. TheInst.emplace_back(result_type);
  1172. TheInst.emplace_back(result_id);
  1173. TheInst.emplace_back(base);
  1174. TheInst.emplace_back(element);
  1175. TheInst.insert(TheInst.end(), indexes.begin(), indexes.end());
  1176. return *this;
  1177. }
  1178. InstBuilder &InstBuilder::opDecorate(uint32_t target,
  1179. spv::Decoration decoration) {
  1180. if (!TheInst.empty()) {
  1181. TheStatus = Status::NestedInst;
  1182. return *this;
  1183. }
  1184. TheInst.reserve(3);
  1185. TheInst.emplace_back(static_cast<uint32_t>(spv::Op::OpDecorate));
  1186. TheInst.emplace_back(target);
  1187. encodeDecoration(decoration);
  1188. return *this;
  1189. }
  1190. InstBuilder &InstBuilder::opMemberDecorate(uint32_t structure_type,
  1191. uint32_t member,
  1192. spv::Decoration decoration) {
  1193. if (!TheInst.empty()) {
  1194. TheStatus = Status::NestedInst;
  1195. return *this;
  1196. }
  1197. TheInst.reserve(4);
  1198. TheInst.emplace_back(static_cast<uint32_t>(spv::Op::OpMemberDecorate));
  1199. TheInst.emplace_back(structure_type);
  1200. TheInst.emplace_back(member);
  1201. encodeDecoration(decoration);
  1202. return *this;
  1203. }
  1204. InstBuilder &InstBuilder::opDecorationGroup(uint32_t result_id) {
  1205. if (!TheInst.empty()) {
  1206. TheStatus = Status::NestedInst;
  1207. return *this;
  1208. }
  1209. if (result_id == 0) {
  1210. TheStatus = Status::ZeroResultId;
  1211. return *this;
  1212. }
  1213. TheInst.reserve(2);
  1214. TheInst.emplace_back(static_cast<uint32_t>(spv::Op::OpDecorationGroup));
  1215. TheInst.emplace_back(result_id);
  1216. return *this;
  1217. }
  1218. InstBuilder &InstBuilder::opGroupDecorate(uint32_t decoration_group,
  1219. llvm::ArrayRef<uint32_t> targets) {
  1220. if (!TheInst.empty()) {
  1221. TheStatus = Status::NestedInst;
  1222. return *this;
  1223. }
  1224. TheInst.reserve(3);
  1225. TheInst.emplace_back(static_cast<uint32_t>(spv::Op::OpGroupDecorate));
  1226. TheInst.emplace_back(decoration_group);
  1227. TheInst.insert(TheInst.end(), targets.begin(), targets.end());
  1228. return *this;
  1229. }
  1230. InstBuilder &InstBuilder::opGroupMemberDecorate(
  1231. uint32_t decoration_group,
  1232. llvm::ArrayRef<std::pair<uint32_t, uint32_t>> targets) {
  1233. if (!TheInst.empty()) {
  1234. TheStatus = Status::NestedInst;
  1235. return *this;
  1236. }
  1237. TheInst.reserve(3);
  1238. TheInst.emplace_back(static_cast<uint32_t>(spv::Op::OpGroupMemberDecorate));
  1239. TheInst.emplace_back(decoration_group);
  1240. for (const auto &param : targets) {
  1241. TheInst.emplace_back(param.first);
  1242. TheInst.emplace_back(param.second);
  1243. ;
  1244. }
  1245. return *this;
  1246. }
  1247. InstBuilder &InstBuilder::opVectorExtractDynamic(uint32_t result_type,
  1248. uint32_t result_id,
  1249. uint32_t vector,
  1250. uint32_t index) {
  1251. if (!TheInst.empty()) {
  1252. TheStatus = Status::NestedInst;
  1253. return *this;
  1254. }
  1255. if (result_type == 0) {
  1256. TheStatus = Status::ZeroResultType;
  1257. return *this;
  1258. }
  1259. if (result_id == 0) {
  1260. TheStatus = Status::ZeroResultId;
  1261. return *this;
  1262. }
  1263. TheInst.reserve(5);
  1264. TheInst.emplace_back(static_cast<uint32_t>(spv::Op::OpVectorExtractDynamic));
  1265. TheInst.emplace_back(result_type);
  1266. TheInst.emplace_back(result_id);
  1267. TheInst.emplace_back(vector);
  1268. TheInst.emplace_back(index);
  1269. return *this;
  1270. }
  1271. InstBuilder &InstBuilder::opVectorInsertDynamic(uint32_t result_type,
  1272. uint32_t result_id,
  1273. uint32_t vector,
  1274. uint32_t component,
  1275. uint32_t index) {
  1276. if (!TheInst.empty()) {
  1277. TheStatus = Status::NestedInst;
  1278. return *this;
  1279. }
  1280. if (result_type == 0) {
  1281. TheStatus = Status::ZeroResultType;
  1282. return *this;
  1283. }
  1284. if (result_id == 0) {
  1285. TheStatus = Status::ZeroResultId;
  1286. return *this;
  1287. }
  1288. TheInst.reserve(6);
  1289. TheInst.emplace_back(static_cast<uint32_t>(spv::Op::OpVectorInsertDynamic));
  1290. TheInst.emplace_back(result_type);
  1291. TheInst.emplace_back(result_id);
  1292. TheInst.emplace_back(vector);
  1293. TheInst.emplace_back(component);
  1294. TheInst.emplace_back(index);
  1295. return *this;
  1296. }
  1297. InstBuilder &InstBuilder::opVectorShuffle(uint32_t result_type,
  1298. uint32_t result_id, uint32_t vector_1,
  1299. uint32_t vector_2,
  1300. llvm::ArrayRef<uint32_t> components) {
  1301. if (!TheInst.empty()) {
  1302. TheStatus = Status::NestedInst;
  1303. return *this;
  1304. }
  1305. if (result_type == 0) {
  1306. TheStatus = Status::ZeroResultType;
  1307. return *this;
  1308. }
  1309. if (result_id == 0) {
  1310. TheStatus = Status::ZeroResultId;
  1311. return *this;
  1312. }
  1313. TheInst.reserve(6);
  1314. TheInst.emplace_back(static_cast<uint32_t>(spv::Op::OpVectorShuffle));
  1315. TheInst.emplace_back(result_type);
  1316. TheInst.emplace_back(result_id);
  1317. TheInst.emplace_back(vector_1);
  1318. TheInst.emplace_back(vector_2);
  1319. for (const auto &param : components) {
  1320. TheInst.emplace_back(param);
  1321. ;
  1322. }
  1323. return *this;
  1324. }
  1325. InstBuilder &
  1326. InstBuilder::opCompositeConstruct(uint32_t result_type, uint32_t result_id,
  1327. llvm::ArrayRef<uint32_t> constituents) {
  1328. if (!TheInst.empty()) {
  1329. TheStatus = Status::NestedInst;
  1330. return *this;
  1331. }
  1332. if (result_type == 0) {
  1333. TheStatus = Status::ZeroResultType;
  1334. return *this;
  1335. }
  1336. if (result_id == 0) {
  1337. TheStatus = Status::ZeroResultId;
  1338. return *this;
  1339. }
  1340. TheInst.reserve(4);
  1341. TheInst.emplace_back(static_cast<uint32_t>(spv::Op::OpCompositeConstruct));
  1342. TheInst.emplace_back(result_type);
  1343. TheInst.emplace_back(result_id);
  1344. TheInst.insert(TheInst.end(), constituents.begin(), constituents.end());
  1345. return *this;
  1346. }
  1347. InstBuilder &InstBuilder::opCompositeExtract(uint32_t result_type,
  1348. uint32_t result_id,
  1349. uint32_t composite,
  1350. llvm::ArrayRef<uint32_t> indexes) {
  1351. if (!TheInst.empty()) {
  1352. TheStatus = Status::NestedInst;
  1353. return *this;
  1354. }
  1355. if (result_type == 0) {
  1356. TheStatus = Status::ZeroResultType;
  1357. return *this;
  1358. }
  1359. if (result_id == 0) {
  1360. TheStatus = Status::ZeroResultId;
  1361. return *this;
  1362. }
  1363. TheInst.reserve(5);
  1364. TheInst.emplace_back(static_cast<uint32_t>(spv::Op::OpCompositeExtract));
  1365. TheInst.emplace_back(result_type);
  1366. TheInst.emplace_back(result_id);
  1367. TheInst.emplace_back(composite);
  1368. for (const auto &param : indexes) {
  1369. TheInst.emplace_back(param);
  1370. ;
  1371. }
  1372. return *this;
  1373. }
  1374. InstBuilder &InstBuilder::opCompositeInsert(uint32_t result_type,
  1375. uint32_t result_id, uint32_t object,
  1376. uint32_t composite,
  1377. llvm::ArrayRef<uint32_t> indexes) {
  1378. if (!TheInst.empty()) {
  1379. TheStatus = Status::NestedInst;
  1380. return *this;
  1381. }
  1382. if (result_type == 0) {
  1383. TheStatus = Status::ZeroResultType;
  1384. return *this;
  1385. }
  1386. if (result_id == 0) {
  1387. TheStatus = Status::ZeroResultId;
  1388. return *this;
  1389. }
  1390. TheInst.reserve(6);
  1391. TheInst.emplace_back(static_cast<uint32_t>(spv::Op::OpCompositeInsert));
  1392. TheInst.emplace_back(result_type);
  1393. TheInst.emplace_back(result_id);
  1394. TheInst.emplace_back(object);
  1395. TheInst.emplace_back(composite);
  1396. for (const auto &param : indexes) {
  1397. TheInst.emplace_back(param);
  1398. ;
  1399. }
  1400. return *this;
  1401. }
  1402. InstBuilder &InstBuilder::opCopyObject(uint32_t result_type, uint32_t result_id,
  1403. uint32_t operand) {
  1404. if (!TheInst.empty()) {
  1405. TheStatus = Status::NestedInst;
  1406. return *this;
  1407. }
  1408. if (result_type == 0) {
  1409. TheStatus = Status::ZeroResultType;
  1410. return *this;
  1411. }
  1412. if (result_id == 0) {
  1413. TheStatus = Status::ZeroResultId;
  1414. return *this;
  1415. }
  1416. TheInst.reserve(4);
  1417. TheInst.emplace_back(static_cast<uint32_t>(spv::Op::OpCopyObject));
  1418. TheInst.emplace_back(result_type);
  1419. TheInst.emplace_back(result_id);
  1420. TheInst.emplace_back(operand);
  1421. return *this;
  1422. }
  1423. InstBuilder &InstBuilder::opTranspose(uint32_t result_type, uint32_t result_id,
  1424. uint32_t matrix) {
  1425. if (!TheInst.empty()) {
  1426. TheStatus = Status::NestedInst;
  1427. return *this;
  1428. }
  1429. if (result_type == 0) {
  1430. TheStatus = Status::ZeroResultType;
  1431. return *this;
  1432. }
  1433. if (result_id == 0) {
  1434. TheStatus = Status::ZeroResultId;
  1435. return *this;
  1436. }
  1437. TheInst.reserve(4);
  1438. TheInst.emplace_back(static_cast<uint32_t>(spv::Op::OpTranspose));
  1439. TheInst.emplace_back(result_type);
  1440. TheInst.emplace_back(result_id);
  1441. TheInst.emplace_back(matrix);
  1442. return *this;
  1443. }
  1444. InstBuilder &InstBuilder::opSampledImage(uint32_t result_type,
  1445. uint32_t result_id, uint32_t image,
  1446. uint32_t sampler) {
  1447. if (!TheInst.empty()) {
  1448. TheStatus = Status::NestedInst;
  1449. return *this;
  1450. }
  1451. if (result_type == 0) {
  1452. TheStatus = Status::ZeroResultType;
  1453. return *this;
  1454. }
  1455. if (result_id == 0) {
  1456. TheStatus = Status::ZeroResultId;
  1457. return *this;
  1458. }
  1459. TheInst.reserve(5);
  1460. TheInst.emplace_back(static_cast<uint32_t>(spv::Op::OpSampledImage));
  1461. TheInst.emplace_back(result_type);
  1462. TheInst.emplace_back(result_id);
  1463. TheInst.emplace_back(image);
  1464. TheInst.emplace_back(sampler);
  1465. return *this;
  1466. }
  1467. InstBuilder &InstBuilder::opImageSampleImplicitLod(
  1468. uint32_t result_type, uint32_t result_id, uint32_t sampled_image,
  1469. uint32_t coordinate,
  1470. llvm::Optional<spv::ImageOperandsMask> image_operands) {
  1471. if (!TheInst.empty()) {
  1472. TheStatus = Status::NestedInst;
  1473. return *this;
  1474. }
  1475. if (result_type == 0) {
  1476. TheStatus = Status::ZeroResultType;
  1477. return *this;
  1478. }
  1479. if (result_id == 0) {
  1480. TheStatus = Status::ZeroResultId;
  1481. return *this;
  1482. }
  1483. TheInst.reserve(6);
  1484. TheInst.emplace_back(
  1485. static_cast<uint32_t>(spv::Op::OpImageSampleImplicitLod));
  1486. TheInst.emplace_back(result_type);
  1487. TheInst.emplace_back(result_id);
  1488. TheInst.emplace_back(sampled_image);
  1489. TheInst.emplace_back(coordinate);
  1490. if (image_operands.hasValue()) {
  1491. const auto &val = image_operands.getValue();
  1492. encodeImageOperands(val);
  1493. }
  1494. return *this;
  1495. }
  1496. InstBuilder &InstBuilder::opImageSampleExplicitLod(
  1497. uint32_t result_type, uint32_t result_id, uint32_t sampled_image,
  1498. uint32_t coordinate, spv::ImageOperandsMask image_operands) {
  1499. if (!TheInst.empty()) {
  1500. TheStatus = Status::NestedInst;
  1501. return *this;
  1502. }
  1503. if (result_type == 0) {
  1504. TheStatus = Status::ZeroResultType;
  1505. return *this;
  1506. }
  1507. if (result_id == 0) {
  1508. TheStatus = Status::ZeroResultId;
  1509. return *this;
  1510. }
  1511. TheInst.reserve(6);
  1512. TheInst.emplace_back(
  1513. static_cast<uint32_t>(spv::Op::OpImageSampleExplicitLod));
  1514. TheInst.emplace_back(result_type);
  1515. TheInst.emplace_back(result_id);
  1516. TheInst.emplace_back(sampled_image);
  1517. TheInst.emplace_back(coordinate);
  1518. encodeImageOperands(image_operands);
  1519. return *this;
  1520. }
  1521. InstBuilder &InstBuilder::opImageSampleDrefImplicitLod(
  1522. uint32_t result_type, uint32_t result_id, uint32_t sampled_image,
  1523. uint32_t coordinate, uint32_t dref,
  1524. llvm::Optional<spv::ImageOperandsMask> image_operands) {
  1525. if (!TheInst.empty()) {
  1526. TheStatus = Status::NestedInst;
  1527. return *this;
  1528. }
  1529. if (result_type == 0) {
  1530. TheStatus = Status::ZeroResultType;
  1531. return *this;
  1532. }
  1533. if (result_id == 0) {
  1534. TheStatus = Status::ZeroResultId;
  1535. return *this;
  1536. }
  1537. TheInst.reserve(7);
  1538. TheInst.emplace_back(
  1539. static_cast<uint32_t>(spv::Op::OpImageSampleDrefImplicitLod));
  1540. TheInst.emplace_back(result_type);
  1541. TheInst.emplace_back(result_id);
  1542. TheInst.emplace_back(sampled_image);
  1543. TheInst.emplace_back(coordinate);
  1544. TheInst.emplace_back(dref);
  1545. if (image_operands.hasValue()) {
  1546. const auto &val = image_operands.getValue();
  1547. encodeImageOperands(val);
  1548. }
  1549. return *this;
  1550. }
  1551. InstBuilder &InstBuilder::opImageSampleDrefExplicitLod(
  1552. uint32_t result_type, uint32_t result_id, uint32_t sampled_image,
  1553. uint32_t coordinate, uint32_t dref, spv::ImageOperandsMask image_operands) {
  1554. if (!TheInst.empty()) {
  1555. TheStatus = Status::NestedInst;
  1556. return *this;
  1557. }
  1558. if (result_type == 0) {
  1559. TheStatus = Status::ZeroResultType;
  1560. return *this;
  1561. }
  1562. if (result_id == 0) {
  1563. TheStatus = Status::ZeroResultId;
  1564. return *this;
  1565. }
  1566. TheInst.reserve(7);
  1567. TheInst.emplace_back(
  1568. static_cast<uint32_t>(spv::Op::OpImageSampleDrefExplicitLod));
  1569. TheInst.emplace_back(result_type);
  1570. TheInst.emplace_back(result_id);
  1571. TheInst.emplace_back(sampled_image);
  1572. TheInst.emplace_back(coordinate);
  1573. TheInst.emplace_back(dref);
  1574. encodeImageOperands(image_operands);
  1575. return *this;
  1576. }
  1577. InstBuilder &InstBuilder::opImageSampleProjImplicitLod(
  1578. uint32_t result_type, uint32_t result_id, uint32_t sampled_image,
  1579. uint32_t coordinate,
  1580. llvm::Optional<spv::ImageOperandsMask> image_operands) {
  1581. if (!TheInst.empty()) {
  1582. TheStatus = Status::NestedInst;
  1583. return *this;
  1584. }
  1585. if (result_type == 0) {
  1586. TheStatus = Status::ZeroResultType;
  1587. return *this;
  1588. }
  1589. if (result_id == 0) {
  1590. TheStatus = Status::ZeroResultId;
  1591. return *this;
  1592. }
  1593. TheInst.reserve(6);
  1594. TheInst.emplace_back(
  1595. static_cast<uint32_t>(spv::Op::OpImageSampleProjImplicitLod));
  1596. TheInst.emplace_back(result_type);
  1597. TheInst.emplace_back(result_id);
  1598. TheInst.emplace_back(sampled_image);
  1599. TheInst.emplace_back(coordinate);
  1600. if (image_operands.hasValue()) {
  1601. const auto &val = image_operands.getValue();
  1602. encodeImageOperands(val);
  1603. }
  1604. return *this;
  1605. }
  1606. InstBuilder &InstBuilder::opImageSampleProjExplicitLod(
  1607. uint32_t result_type, uint32_t result_id, uint32_t sampled_image,
  1608. uint32_t coordinate, spv::ImageOperandsMask image_operands) {
  1609. if (!TheInst.empty()) {
  1610. TheStatus = Status::NestedInst;
  1611. return *this;
  1612. }
  1613. if (result_type == 0) {
  1614. TheStatus = Status::ZeroResultType;
  1615. return *this;
  1616. }
  1617. if (result_id == 0) {
  1618. TheStatus = Status::ZeroResultId;
  1619. return *this;
  1620. }
  1621. TheInst.reserve(6);
  1622. TheInst.emplace_back(
  1623. static_cast<uint32_t>(spv::Op::OpImageSampleProjExplicitLod));
  1624. TheInst.emplace_back(result_type);
  1625. TheInst.emplace_back(result_id);
  1626. TheInst.emplace_back(sampled_image);
  1627. TheInst.emplace_back(coordinate);
  1628. encodeImageOperands(image_operands);
  1629. return *this;
  1630. }
  1631. InstBuilder &InstBuilder::opImageSampleProjDrefImplicitLod(
  1632. uint32_t result_type, uint32_t result_id, uint32_t sampled_image,
  1633. uint32_t coordinate, uint32_t dref,
  1634. llvm::Optional<spv::ImageOperandsMask> image_operands) {
  1635. if (!TheInst.empty()) {
  1636. TheStatus = Status::NestedInst;
  1637. return *this;
  1638. }
  1639. if (result_type == 0) {
  1640. TheStatus = Status::ZeroResultType;
  1641. return *this;
  1642. }
  1643. if (result_id == 0) {
  1644. TheStatus = Status::ZeroResultId;
  1645. return *this;
  1646. }
  1647. TheInst.reserve(7);
  1648. TheInst.emplace_back(
  1649. static_cast<uint32_t>(spv::Op::OpImageSampleProjDrefImplicitLod));
  1650. TheInst.emplace_back(result_type);
  1651. TheInst.emplace_back(result_id);
  1652. TheInst.emplace_back(sampled_image);
  1653. TheInst.emplace_back(coordinate);
  1654. TheInst.emplace_back(dref);
  1655. if (image_operands.hasValue()) {
  1656. const auto &val = image_operands.getValue();
  1657. encodeImageOperands(val);
  1658. }
  1659. return *this;
  1660. }
  1661. InstBuilder &InstBuilder::opImageSampleProjDrefExplicitLod(
  1662. uint32_t result_type, uint32_t result_id, uint32_t sampled_image,
  1663. uint32_t coordinate, uint32_t dref, spv::ImageOperandsMask image_operands) {
  1664. if (!TheInst.empty()) {
  1665. TheStatus = Status::NestedInst;
  1666. return *this;
  1667. }
  1668. if (result_type == 0) {
  1669. TheStatus = Status::ZeroResultType;
  1670. return *this;
  1671. }
  1672. if (result_id == 0) {
  1673. TheStatus = Status::ZeroResultId;
  1674. return *this;
  1675. }
  1676. TheInst.reserve(7);
  1677. TheInst.emplace_back(
  1678. static_cast<uint32_t>(spv::Op::OpImageSampleProjDrefExplicitLod));
  1679. TheInst.emplace_back(result_type);
  1680. TheInst.emplace_back(result_id);
  1681. TheInst.emplace_back(sampled_image);
  1682. TheInst.emplace_back(coordinate);
  1683. TheInst.emplace_back(dref);
  1684. encodeImageOperands(image_operands);
  1685. return *this;
  1686. }
  1687. InstBuilder &InstBuilder::opImageFetch(
  1688. uint32_t result_type, uint32_t result_id, uint32_t image,
  1689. uint32_t coordinate,
  1690. llvm::Optional<spv::ImageOperandsMask> image_operands) {
  1691. if (!TheInst.empty()) {
  1692. TheStatus = Status::NestedInst;
  1693. return *this;
  1694. }
  1695. if (result_type == 0) {
  1696. TheStatus = Status::ZeroResultType;
  1697. return *this;
  1698. }
  1699. if (result_id == 0) {
  1700. TheStatus = Status::ZeroResultId;
  1701. return *this;
  1702. }
  1703. TheInst.reserve(6);
  1704. TheInst.emplace_back(static_cast<uint32_t>(spv::Op::OpImageFetch));
  1705. TheInst.emplace_back(result_type);
  1706. TheInst.emplace_back(result_id);
  1707. TheInst.emplace_back(image);
  1708. TheInst.emplace_back(coordinate);
  1709. if (image_operands.hasValue()) {
  1710. const auto &val = image_operands.getValue();
  1711. encodeImageOperands(val);
  1712. }
  1713. return *this;
  1714. }
  1715. InstBuilder &InstBuilder::opImageGather(
  1716. uint32_t result_type, uint32_t result_id, uint32_t sampled_image,
  1717. uint32_t coordinate, uint32_t component,
  1718. llvm::Optional<spv::ImageOperandsMask> image_operands) {
  1719. if (!TheInst.empty()) {
  1720. TheStatus = Status::NestedInst;
  1721. return *this;
  1722. }
  1723. if (result_type == 0) {
  1724. TheStatus = Status::ZeroResultType;
  1725. return *this;
  1726. }
  1727. if (result_id == 0) {
  1728. TheStatus = Status::ZeroResultId;
  1729. return *this;
  1730. }
  1731. TheInst.reserve(7);
  1732. TheInst.emplace_back(static_cast<uint32_t>(spv::Op::OpImageGather));
  1733. TheInst.emplace_back(result_type);
  1734. TheInst.emplace_back(result_id);
  1735. TheInst.emplace_back(sampled_image);
  1736. TheInst.emplace_back(coordinate);
  1737. TheInst.emplace_back(component);
  1738. if (image_operands.hasValue()) {
  1739. const auto &val = image_operands.getValue();
  1740. encodeImageOperands(val);
  1741. }
  1742. return *this;
  1743. }
  1744. InstBuilder &InstBuilder::opImageDrefGather(
  1745. uint32_t result_type, uint32_t result_id, uint32_t sampled_image,
  1746. uint32_t coordinate, uint32_t dref,
  1747. llvm::Optional<spv::ImageOperandsMask> image_operands) {
  1748. if (!TheInst.empty()) {
  1749. TheStatus = Status::NestedInst;
  1750. return *this;
  1751. }
  1752. if (result_type == 0) {
  1753. TheStatus = Status::ZeroResultType;
  1754. return *this;
  1755. }
  1756. if (result_id == 0) {
  1757. TheStatus = Status::ZeroResultId;
  1758. return *this;
  1759. }
  1760. TheInst.reserve(7);
  1761. TheInst.emplace_back(static_cast<uint32_t>(spv::Op::OpImageDrefGather));
  1762. TheInst.emplace_back(result_type);
  1763. TheInst.emplace_back(result_id);
  1764. TheInst.emplace_back(sampled_image);
  1765. TheInst.emplace_back(coordinate);
  1766. TheInst.emplace_back(dref);
  1767. if (image_operands.hasValue()) {
  1768. const auto &val = image_operands.getValue();
  1769. encodeImageOperands(val);
  1770. }
  1771. return *this;
  1772. }
  1773. InstBuilder &InstBuilder::opImageRead(
  1774. uint32_t result_type, uint32_t result_id, uint32_t image,
  1775. uint32_t coordinate,
  1776. llvm::Optional<spv::ImageOperandsMask> image_operands) {
  1777. if (!TheInst.empty()) {
  1778. TheStatus = Status::NestedInst;
  1779. return *this;
  1780. }
  1781. if (result_type == 0) {
  1782. TheStatus = Status::ZeroResultType;
  1783. return *this;
  1784. }
  1785. if (result_id == 0) {
  1786. TheStatus = Status::ZeroResultId;
  1787. return *this;
  1788. }
  1789. TheInst.reserve(6);
  1790. TheInst.emplace_back(static_cast<uint32_t>(spv::Op::OpImageRead));
  1791. TheInst.emplace_back(result_type);
  1792. TheInst.emplace_back(result_id);
  1793. TheInst.emplace_back(image);
  1794. TheInst.emplace_back(coordinate);
  1795. if (image_operands.hasValue()) {
  1796. const auto &val = image_operands.getValue();
  1797. encodeImageOperands(val);
  1798. }
  1799. return *this;
  1800. }
  1801. InstBuilder &InstBuilder::opImageWrite(
  1802. uint32_t image, uint32_t coordinate, uint32_t texel,
  1803. llvm::Optional<spv::ImageOperandsMask> image_operands) {
  1804. if (!TheInst.empty()) {
  1805. TheStatus = Status::NestedInst;
  1806. return *this;
  1807. }
  1808. TheInst.reserve(5);
  1809. TheInst.emplace_back(static_cast<uint32_t>(spv::Op::OpImageWrite));
  1810. TheInst.emplace_back(image);
  1811. TheInst.emplace_back(coordinate);
  1812. TheInst.emplace_back(texel);
  1813. if (image_operands.hasValue()) {
  1814. const auto &val = image_operands.getValue();
  1815. encodeImageOperands(val);
  1816. }
  1817. return *this;
  1818. }
  1819. InstBuilder &InstBuilder::opImage(uint32_t result_type, uint32_t result_id,
  1820. uint32_t sampled_image) {
  1821. if (!TheInst.empty()) {
  1822. TheStatus = Status::NestedInst;
  1823. return *this;
  1824. }
  1825. if (result_type == 0) {
  1826. TheStatus = Status::ZeroResultType;
  1827. return *this;
  1828. }
  1829. if (result_id == 0) {
  1830. TheStatus = Status::ZeroResultId;
  1831. return *this;
  1832. }
  1833. TheInst.reserve(4);
  1834. TheInst.emplace_back(static_cast<uint32_t>(spv::Op::OpImage));
  1835. TheInst.emplace_back(result_type);
  1836. TheInst.emplace_back(result_id);
  1837. TheInst.emplace_back(sampled_image);
  1838. return *this;
  1839. }
  1840. InstBuilder &InstBuilder::opImageQueryFormat(uint32_t result_type,
  1841. uint32_t result_id,
  1842. uint32_t image) {
  1843. if (!TheInst.empty()) {
  1844. TheStatus = Status::NestedInst;
  1845. return *this;
  1846. }
  1847. if (result_type == 0) {
  1848. TheStatus = Status::ZeroResultType;
  1849. return *this;
  1850. }
  1851. if (result_id == 0) {
  1852. TheStatus = Status::ZeroResultId;
  1853. return *this;
  1854. }
  1855. TheInst.reserve(4);
  1856. TheInst.emplace_back(static_cast<uint32_t>(spv::Op::OpImageQueryFormat));
  1857. TheInst.emplace_back(result_type);
  1858. TheInst.emplace_back(result_id);
  1859. TheInst.emplace_back(image);
  1860. return *this;
  1861. }
  1862. InstBuilder &InstBuilder::opImageQueryOrder(uint32_t result_type,
  1863. uint32_t result_id,
  1864. uint32_t image) {
  1865. if (!TheInst.empty()) {
  1866. TheStatus = Status::NestedInst;
  1867. return *this;
  1868. }
  1869. if (result_type == 0) {
  1870. TheStatus = Status::ZeroResultType;
  1871. return *this;
  1872. }
  1873. if (result_id == 0) {
  1874. TheStatus = Status::ZeroResultId;
  1875. return *this;
  1876. }
  1877. TheInst.reserve(4);
  1878. TheInst.emplace_back(static_cast<uint32_t>(spv::Op::OpImageQueryOrder));
  1879. TheInst.emplace_back(result_type);
  1880. TheInst.emplace_back(result_id);
  1881. TheInst.emplace_back(image);
  1882. return *this;
  1883. }
  1884. InstBuilder &InstBuilder::opImageQuerySizeLod(uint32_t result_type,
  1885. uint32_t result_id,
  1886. uint32_t image,
  1887. uint32_t level_of_detail) {
  1888. if (!TheInst.empty()) {
  1889. TheStatus = Status::NestedInst;
  1890. return *this;
  1891. }
  1892. if (result_type == 0) {
  1893. TheStatus = Status::ZeroResultType;
  1894. return *this;
  1895. }
  1896. if (result_id == 0) {
  1897. TheStatus = Status::ZeroResultId;
  1898. return *this;
  1899. }
  1900. TheInst.reserve(5);
  1901. TheInst.emplace_back(static_cast<uint32_t>(spv::Op::OpImageQuerySizeLod));
  1902. TheInst.emplace_back(result_type);
  1903. TheInst.emplace_back(result_id);
  1904. TheInst.emplace_back(image);
  1905. TheInst.emplace_back(level_of_detail);
  1906. return *this;
  1907. }
  1908. InstBuilder &InstBuilder::opImageQuerySize(uint32_t result_type,
  1909. uint32_t result_id, uint32_t image) {
  1910. if (!TheInst.empty()) {
  1911. TheStatus = Status::NestedInst;
  1912. return *this;
  1913. }
  1914. if (result_type == 0) {
  1915. TheStatus = Status::ZeroResultType;
  1916. return *this;
  1917. }
  1918. if (result_id == 0) {
  1919. TheStatus = Status::ZeroResultId;
  1920. return *this;
  1921. }
  1922. TheInst.reserve(4);
  1923. TheInst.emplace_back(static_cast<uint32_t>(spv::Op::OpImageQuerySize));
  1924. TheInst.emplace_back(result_type);
  1925. TheInst.emplace_back(result_id);
  1926. TheInst.emplace_back(image);
  1927. return *this;
  1928. }
  1929. InstBuilder &InstBuilder::opImageQueryLod(uint32_t result_type,
  1930. uint32_t result_id,
  1931. uint32_t sampled_image,
  1932. uint32_t coordinate) {
  1933. if (!TheInst.empty()) {
  1934. TheStatus = Status::NestedInst;
  1935. return *this;
  1936. }
  1937. if (result_type == 0) {
  1938. TheStatus = Status::ZeroResultType;
  1939. return *this;
  1940. }
  1941. if (result_id == 0) {
  1942. TheStatus = Status::ZeroResultId;
  1943. return *this;
  1944. }
  1945. TheInst.reserve(5);
  1946. TheInst.emplace_back(static_cast<uint32_t>(spv::Op::OpImageQueryLod));
  1947. TheInst.emplace_back(result_type);
  1948. TheInst.emplace_back(result_id);
  1949. TheInst.emplace_back(sampled_image);
  1950. TheInst.emplace_back(coordinate);
  1951. return *this;
  1952. }
  1953. InstBuilder &InstBuilder::opImageQueryLevels(uint32_t result_type,
  1954. uint32_t result_id,
  1955. uint32_t image) {
  1956. if (!TheInst.empty()) {
  1957. TheStatus = Status::NestedInst;
  1958. return *this;
  1959. }
  1960. if (result_type == 0) {
  1961. TheStatus = Status::ZeroResultType;
  1962. return *this;
  1963. }
  1964. if (result_id == 0) {
  1965. TheStatus = Status::ZeroResultId;
  1966. return *this;
  1967. }
  1968. TheInst.reserve(4);
  1969. TheInst.emplace_back(static_cast<uint32_t>(spv::Op::OpImageQueryLevels));
  1970. TheInst.emplace_back(result_type);
  1971. TheInst.emplace_back(result_id);
  1972. TheInst.emplace_back(image);
  1973. return *this;
  1974. }
  1975. InstBuilder &InstBuilder::opImageQuerySamples(uint32_t result_type,
  1976. uint32_t result_id,
  1977. uint32_t image) {
  1978. if (!TheInst.empty()) {
  1979. TheStatus = Status::NestedInst;
  1980. return *this;
  1981. }
  1982. if (result_type == 0) {
  1983. TheStatus = Status::ZeroResultType;
  1984. return *this;
  1985. }
  1986. if (result_id == 0) {
  1987. TheStatus = Status::ZeroResultId;
  1988. return *this;
  1989. }
  1990. TheInst.reserve(4);
  1991. TheInst.emplace_back(static_cast<uint32_t>(spv::Op::OpImageQuerySamples));
  1992. TheInst.emplace_back(result_type);
  1993. TheInst.emplace_back(result_id);
  1994. TheInst.emplace_back(image);
  1995. return *this;
  1996. }
  1997. InstBuilder &InstBuilder::opConvertFToU(uint32_t result_type,
  1998. uint32_t result_id,
  1999. uint32_t float_value) {
  2000. if (!TheInst.empty()) {
  2001. TheStatus = Status::NestedInst;
  2002. return *this;
  2003. }
  2004. if (result_type == 0) {
  2005. TheStatus = Status::ZeroResultType;
  2006. return *this;
  2007. }
  2008. if (result_id == 0) {
  2009. TheStatus = Status::ZeroResultId;
  2010. return *this;
  2011. }
  2012. TheInst.reserve(4);
  2013. TheInst.emplace_back(static_cast<uint32_t>(spv::Op::OpConvertFToU));
  2014. TheInst.emplace_back(result_type);
  2015. TheInst.emplace_back(result_id);
  2016. TheInst.emplace_back(float_value);
  2017. return *this;
  2018. }
  2019. InstBuilder &InstBuilder::opConvertFToS(uint32_t result_type,
  2020. uint32_t result_id,
  2021. uint32_t float_value) {
  2022. if (!TheInst.empty()) {
  2023. TheStatus = Status::NestedInst;
  2024. return *this;
  2025. }
  2026. if (result_type == 0) {
  2027. TheStatus = Status::ZeroResultType;
  2028. return *this;
  2029. }
  2030. if (result_id == 0) {
  2031. TheStatus = Status::ZeroResultId;
  2032. return *this;
  2033. }
  2034. TheInst.reserve(4);
  2035. TheInst.emplace_back(static_cast<uint32_t>(spv::Op::OpConvertFToS));
  2036. TheInst.emplace_back(result_type);
  2037. TheInst.emplace_back(result_id);
  2038. TheInst.emplace_back(float_value);
  2039. return *this;
  2040. }
  2041. InstBuilder &InstBuilder::opConvertSToF(uint32_t result_type,
  2042. uint32_t result_id,
  2043. uint32_t signed_value) {
  2044. if (!TheInst.empty()) {
  2045. TheStatus = Status::NestedInst;
  2046. return *this;
  2047. }
  2048. if (result_type == 0) {
  2049. TheStatus = Status::ZeroResultType;
  2050. return *this;
  2051. }
  2052. if (result_id == 0) {
  2053. TheStatus = Status::ZeroResultId;
  2054. return *this;
  2055. }
  2056. TheInst.reserve(4);
  2057. TheInst.emplace_back(static_cast<uint32_t>(spv::Op::OpConvertSToF));
  2058. TheInst.emplace_back(result_type);
  2059. TheInst.emplace_back(result_id);
  2060. TheInst.emplace_back(signed_value);
  2061. return *this;
  2062. }
  2063. InstBuilder &InstBuilder::opConvertUToF(uint32_t result_type,
  2064. uint32_t result_id,
  2065. uint32_t unsigned_value) {
  2066. if (!TheInst.empty()) {
  2067. TheStatus = Status::NestedInst;
  2068. return *this;
  2069. }
  2070. if (result_type == 0) {
  2071. TheStatus = Status::ZeroResultType;
  2072. return *this;
  2073. }
  2074. if (result_id == 0) {
  2075. TheStatus = Status::ZeroResultId;
  2076. return *this;
  2077. }
  2078. TheInst.reserve(4);
  2079. TheInst.emplace_back(static_cast<uint32_t>(spv::Op::OpConvertUToF));
  2080. TheInst.emplace_back(result_type);
  2081. TheInst.emplace_back(result_id);
  2082. TheInst.emplace_back(unsigned_value);
  2083. return *this;
  2084. }
  2085. InstBuilder &InstBuilder::opUConvert(uint32_t result_type, uint32_t result_id,
  2086. uint32_t unsigned_value) {
  2087. if (!TheInst.empty()) {
  2088. TheStatus = Status::NestedInst;
  2089. return *this;
  2090. }
  2091. if (result_type == 0) {
  2092. TheStatus = Status::ZeroResultType;
  2093. return *this;
  2094. }
  2095. if (result_id == 0) {
  2096. TheStatus = Status::ZeroResultId;
  2097. return *this;
  2098. }
  2099. TheInst.reserve(4);
  2100. TheInst.emplace_back(static_cast<uint32_t>(spv::Op::OpUConvert));
  2101. TheInst.emplace_back(result_type);
  2102. TheInst.emplace_back(result_id);
  2103. TheInst.emplace_back(unsigned_value);
  2104. return *this;
  2105. }
  2106. InstBuilder &InstBuilder::opSConvert(uint32_t result_type, uint32_t result_id,
  2107. uint32_t signed_value) {
  2108. if (!TheInst.empty()) {
  2109. TheStatus = Status::NestedInst;
  2110. return *this;
  2111. }
  2112. if (result_type == 0) {
  2113. TheStatus = Status::ZeroResultType;
  2114. return *this;
  2115. }
  2116. if (result_id == 0) {
  2117. TheStatus = Status::ZeroResultId;
  2118. return *this;
  2119. }
  2120. TheInst.reserve(4);
  2121. TheInst.emplace_back(static_cast<uint32_t>(spv::Op::OpSConvert));
  2122. TheInst.emplace_back(result_type);
  2123. TheInst.emplace_back(result_id);
  2124. TheInst.emplace_back(signed_value);
  2125. return *this;
  2126. }
  2127. InstBuilder &InstBuilder::opFConvert(uint32_t result_type, uint32_t result_id,
  2128. uint32_t float_value) {
  2129. if (!TheInst.empty()) {
  2130. TheStatus = Status::NestedInst;
  2131. return *this;
  2132. }
  2133. if (result_type == 0) {
  2134. TheStatus = Status::ZeroResultType;
  2135. return *this;
  2136. }
  2137. if (result_id == 0) {
  2138. TheStatus = Status::ZeroResultId;
  2139. return *this;
  2140. }
  2141. TheInst.reserve(4);
  2142. TheInst.emplace_back(static_cast<uint32_t>(spv::Op::OpFConvert));
  2143. TheInst.emplace_back(result_type);
  2144. TheInst.emplace_back(result_id);
  2145. TheInst.emplace_back(float_value);
  2146. return *this;
  2147. }
  2148. InstBuilder &InstBuilder::opQuantizeToF16(uint32_t result_type,
  2149. uint32_t result_id, uint32_t value) {
  2150. if (!TheInst.empty()) {
  2151. TheStatus = Status::NestedInst;
  2152. return *this;
  2153. }
  2154. if (result_type == 0) {
  2155. TheStatus = Status::ZeroResultType;
  2156. return *this;
  2157. }
  2158. if (result_id == 0) {
  2159. TheStatus = Status::ZeroResultId;
  2160. return *this;
  2161. }
  2162. TheInst.reserve(4);
  2163. TheInst.emplace_back(static_cast<uint32_t>(spv::Op::OpQuantizeToF16));
  2164. TheInst.emplace_back(result_type);
  2165. TheInst.emplace_back(result_id);
  2166. TheInst.emplace_back(value);
  2167. return *this;
  2168. }
  2169. InstBuilder &InstBuilder::opConvertPtrToU(uint32_t result_type,
  2170. uint32_t result_id,
  2171. uint32_t pointer) {
  2172. if (!TheInst.empty()) {
  2173. TheStatus = Status::NestedInst;
  2174. return *this;
  2175. }
  2176. if (result_type == 0) {
  2177. TheStatus = Status::ZeroResultType;
  2178. return *this;
  2179. }
  2180. if (result_id == 0) {
  2181. TheStatus = Status::ZeroResultId;
  2182. return *this;
  2183. }
  2184. TheInst.reserve(4);
  2185. TheInst.emplace_back(static_cast<uint32_t>(spv::Op::OpConvertPtrToU));
  2186. TheInst.emplace_back(result_type);
  2187. TheInst.emplace_back(result_id);
  2188. TheInst.emplace_back(pointer);
  2189. return *this;
  2190. }
  2191. InstBuilder &InstBuilder::opSatConvertSToU(uint32_t result_type,
  2192. uint32_t result_id,
  2193. uint32_t signed_value) {
  2194. if (!TheInst.empty()) {
  2195. TheStatus = Status::NestedInst;
  2196. return *this;
  2197. }
  2198. if (result_type == 0) {
  2199. TheStatus = Status::ZeroResultType;
  2200. return *this;
  2201. }
  2202. if (result_id == 0) {
  2203. TheStatus = Status::ZeroResultId;
  2204. return *this;
  2205. }
  2206. TheInst.reserve(4);
  2207. TheInst.emplace_back(static_cast<uint32_t>(spv::Op::OpSatConvertSToU));
  2208. TheInst.emplace_back(result_type);
  2209. TheInst.emplace_back(result_id);
  2210. TheInst.emplace_back(signed_value);
  2211. return *this;
  2212. }
  2213. InstBuilder &InstBuilder::opSatConvertUToS(uint32_t result_type,
  2214. uint32_t result_id,
  2215. uint32_t unsigned_value) {
  2216. if (!TheInst.empty()) {
  2217. TheStatus = Status::NestedInst;
  2218. return *this;
  2219. }
  2220. if (result_type == 0) {
  2221. TheStatus = Status::ZeroResultType;
  2222. return *this;
  2223. }
  2224. if (result_id == 0) {
  2225. TheStatus = Status::ZeroResultId;
  2226. return *this;
  2227. }
  2228. TheInst.reserve(4);
  2229. TheInst.emplace_back(static_cast<uint32_t>(spv::Op::OpSatConvertUToS));
  2230. TheInst.emplace_back(result_type);
  2231. TheInst.emplace_back(result_id);
  2232. TheInst.emplace_back(unsigned_value);
  2233. return *this;
  2234. }
  2235. InstBuilder &InstBuilder::opConvertUToPtr(uint32_t result_type,
  2236. uint32_t result_id,
  2237. uint32_t integer_value) {
  2238. if (!TheInst.empty()) {
  2239. TheStatus = Status::NestedInst;
  2240. return *this;
  2241. }
  2242. if (result_type == 0) {
  2243. TheStatus = Status::ZeroResultType;
  2244. return *this;
  2245. }
  2246. if (result_id == 0) {
  2247. TheStatus = Status::ZeroResultId;
  2248. return *this;
  2249. }
  2250. TheInst.reserve(4);
  2251. TheInst.emplace_back(static_cast<uint32_t>(spv::Op::OpConvertUToPtr));
  2252. TheInst.emplace_back(result_type);
  2253. TheInst.emplace_back(result_id);
  2254. TheInst.emplace_back(integer_value);
  2255. return *this;
  2256. }
  2257. InstBuilder &InstBuilder::opPtrCastToGeneric(uint32_t result_type,
  2258. uint32_t result_id,
  2259. uint32_t pointer) {
  2260. if (!TheInst.empty()) {
  2261. TheStatus = Status::NestedInst;
  2262. return *this;
  2263. }
  2264. if (result_type == 0) {
  2265. TheStatus = Status::ZeroResultType;
  2266. return *this;
  2267. }
  2268. if (result_id == 0) {
  2269. TheStatus = Status::ZeroResultId;
  2270. return *this;
  2271. }
  2272. TheInst.reserve(4);
  2273. TheInst.emplace_back(static_cast<uint32_t>(spv::Op::OpPtrCastToGeneric));
  2274. TheInst.emplace_back(result_type);
  2275. TheInst.emplace_back(result_id);
  2276. TheInst.emplace_back(pointer);
  2277. return *this;
  2278. }
  2279. InstBuilder &InstBuilder::opGenericCastToPtr(uint32_t result_type,
  2280. uint32_t result_id,
  2281. uint32_t pointer) {
  2282. if (!TheInst.empty()) {
  2283. TheStatus = Status::NestedInst;
  2284. return *this;
  2285. }
  2286. if (result_type == 0) {
  2287. TheStatus = Status::ZeroResultType;
  2288. return *this;
  2289. }
  2290. if (result_id == 0) {
  2291. TheStatus = Status::ZeroResultId;
  2292. return *this;
  2293. }
  2294. TheInst.reserve(4);
  2295. TheInst.emplace_back(static_cast<uint32_t>(spv::Op::OpGenericCastToPtr));
  2296. TheInst.emplace_back(result_type);
  2297. TheInst.emplace_back(result_id);
  2298. TheInst.emplace_back(pointer);
  2299. return *this;
  2300. }
  2301. InstBuilder &
  2302. InstBuilder::opGenericCastToPtrExplicit(uint32_t result_type,
  2303. uint32_t result_id, uint32_t pointer,
  2304. spv::StorageClass storage) {
  2305. if (!TheInst.empty()) {
  2306. TheStatus = Status::NestedInst;
  2307. return *this;
  2308. }
  2309. if (result_type == 0) {
  2310. TheStatus = Status::ZeroResultType;
  2311. return *this;
  2312. }
  2313. if (result_id == 0) {
  2314. TheStatus = Status::ZeroResultId;
  2315. return *this;
  2316. }
  2317. TheInst.reserve(5);
  2318. TheInst.emplace_back(
  2319. static_cast<uint32_t>(spv::Op::OpGenericCastToPtrExplicit));
  2320. TheInst.emplace_back(result_type);
  2321. TheInst.emplace_back(result_id);
  2322. TheInst.emplace_back(pointer);
  2323. TheInst.emplace_back(static_cast<uint32_t>(storage));
  2324. return *this;
  2325. }
  2326. InstBuilder &InstBuilder::opBitcast(uint32_t result_type, uint32_t result_id,
  2327. uint32_t operand) {
  2328. if (!TheInst.empty()) {
  2329. TheStatus = Status::NestedInst;
  2330. return *this;
  2331. }
  2332. if (result_type == 0) {
  2333. TheStatus = Status::ZeroResultType;
  2334. return *this;
  2335. }
  2336. if (result_id == 0) {
  2337. TheStatus = Status::ZeroResultId;
  2338. return *this;
  2339. }
  2340. TheInst.reserve(4);
  2341. TheInst.emplace_back(static_cast<uint32_t>(spv::Op::OpBitcast));
  2342. TheInst.emplace_back(result_type);
  2343. TheInst.emplace_back(result_id);
  2344. TheInst.emplace_back(operand);
  2345. return *this;
  2346. }
  2347. InstBuilder &InstBuilder::opSNegate(uint32_t result_type, uint32_t result_id,
  2348. uint32_t operand) {
  2349. if (!TheInst.empty()) {
  2350. TheStatus = Status::NestedInst;
  2351. return *this;
  2352. }
  2353. if (result_type == 0) {
  2354. TheStatus = Status::ZeroResultType;
  2355. return *this;
  2356. }
  2357. if (result_id == 0) {
  2358. TheStatus = Status::ZeroResultId;
  2359. return *this;
  2360. }
  2361. TheInst.reserve(4);
  2362. TheInst.emplace_back(static_cast<uint32_t>(spv::Op::OpSNegate));
  2363. TheInst.emplace_back(result_type);
  2364. TheInst.emplace_back(result_id);
  2365. TheInst.emplace_back(operand);
  2366. return *this;
  2367. }
  2368. InstBuilder &InstBuilder::opFNegate(uint32_t result_type, uint32_t result_id,
  2369. uint32_t operand) {
  2370. if (!TheInst.empty()) {
  2371. TheStatus = Status::NestedInst;
  2372. return *this;
  2373. }
  2374. if (result_type == 0) {
  2375. TheStatus = Status::ZeroResultType;
  2376. return *this;
  2377. }
  2378. if (result_id == 0) {
  2379. TheStatus = Status::ZeroResultId;
  2380. return *this;
  2381. }
  2382. TheInst.reserve(4);
  2383. TheInst.emplace_back(static_cast<uint32_t>(spv::Op::OpFNegate));
  2384. TheInst.emplace_back(result_type);
  2385. TheInst.emplace_back(result_id);
  2386. TheInst.emplace_back(operand);
  2387. return *this;
  2388. }
  2389. InstBuilder &InstBuilder::opIAdd(uint32_t result_type, uint32_t result_id,
  2390. uint32_t operand_1, uint32_t operand_2) {
  2391. if (!TheInst.empty()) {
  2392. TheStatus = Status::NestedInst;
  2393. return *this;
  2394. }
  2395. if (result_type == 0) {
  2396. TheStatus = Status::ZeroResultType;
  2397. return *this;
  2398. }
  2399. if (result_id == 0) {
  2400. TheStatus = Status::ZeroResultId;
  2401. return *this;
  2402. }
  2403. TheInst.reserve(5);
  2404. TheInst.emplace_back(static_cast<uint32_t>(spv::Op::OpIAdd));
  2405. TheInst.emplace_back(result_type);
  2406. TheInst.emplace_back(result_id);
  2407. TheInst.emplace_back(operand_1);
  2408. TheInst.emplace_back(operand_2);
  2409. return *this;
  2410. }
  2411. InstBuilder &InstBuilder::opFAdd(uint32_t result_type, uint32_t result_id,
  2412. uint32_t operand_1, uint32_t operand_2) {
  2413. if (!TheInst.empty()) {
  2414. TheStatus = Status::NestedInst;
  2415. return *this;
  2416. }
  2417. if (result_type == 0) {
  2418. TheStatus = Status::ZeroResultType;
  2419. return *this;
  2420. }
  2421. if (result_id == 0) {
  2422. TheStatus = Status::ZeroResultId;
  2423. return *this;
  2424. }
  2425. TheInst.reserve(5);
  2426. TheInst.emplace_back(static_cast<uint32_t>(spv::Op::OpFAdd));
  2427. TheInst.emplace_back(result_type);
  2428. TheInst.emplace_back(result_id);
  2429. TheInst.emplace_back(operand_1);
  2430. TheInst.emplace_back(operand_2);
  2431. return *this;
  2432. }
  2433. InstBuilder &InstBuilder::opISub(uint32_t result_type, uint32_t result_id,
  2434. uint32_t operand_1, uint32_t operand_2) {
  2435. if (!TheInst.empty()) {
  2436. TheStatus = Status::NestedInst;
  2437. return *this;
  2438. }
  2439. if (result_type == 0) {
  2440. TheStatus = Status::ZeroResultType;
  2441. return *this;
  2442. }
  2443. if (result_id == 0) {
  2444. TheStatus = Status::ZeroResultId;
  2445. return *this;
  2446. }
  2447. TheInst.reserve(5);
  2448. TheInst.emplace_back(static_cast<uint32_t>(spv::Op::OpISub));
  2449. TheInst.emplace_back(result_type);
  2450. TheInst.emplace_back(result_id);
  2451. TheInst.emplace_back(operand_1);
  2452. TheInst.emplace_back(operand_2);
  2453. return *this;
  2454. }
  2455. InstBuilder &InstBuilder::opFSub(uint32_t result_type, uint32_t result_id,
  2456. uint32_t operand_1, uint32_t operand_2) {
  2457. if (!TheInst.empty()) {
  2458. TheStatus = Status::NestedInst;
  2459. return *this;
  2460. }
  2461. if (result_type == 0) {
  2462. TheStatus = Status::ZeroResultType;
  2463. return *this;
  2464. }
  2465. if (result_id == 0) {
  2466. TheStatus = Status::ZeroResultId;
  2467. return *this;
  2468. }
  2469. TheInst.reserve(5);
  2470. TheInst.emplace_back(static_cast<uint32_t>(spv::Op::OpFSub));
  2471. TheInst.emplace_back(result_type);
  2472. TheInst.emplace_back(result_id);
  2473. TheInst.emplace_back(operand_1);
  2474. TheInst.emplace_back(operand_2);
  2475. return *this;
  2476. }
  2477. InstBuilder &InstBuilder::opIMul(uint32_t result_type, uint32_t result_id,
  2478. uint32_t operand_1, uint32_t operand_2) {
  2479. if (!TheInst.empty()) {
  2480. TheStatus = Status::NestedInst;
  2481. return *this;
  2482. }
  2483. if (result_type == 0) {
  2484. TheStatus = Status::ZeroResultType;
  2485. return *this;
  2486. }
  2487. if (result_id == 0) {
  2488. TheStatus = Status::ZeroResultId;
  2489. return *this;
  2490. }
  2491. TheInst.reserve(5);
  2492. TheInst.emplace_back(static_cast<uint32_t>(spv::Op::OpIMul));
  2493. TheInst.emplace_back(result_type);
  2494. TheInst.emplace_back(result_id);
  2495. TheInst.emplace_back(operand_1);
  2496. TheInst.emplace_back(operand_2);
  2497. return *this;
  2498. }
  2499. InstBuilder &InstBuilder::opFMul(uint32_t result_type, uint32_t result_id,
  2500. uint32_t operand_1, uint32_t operand_2) {
  2501. if (!TheInst.empty()) {
  2502. TheStatus = Status::NestedInst;
  2503. return *this;
  2504. }
  2505. if (result_type == 0) {
  2506. TheStatus = Status::ZeroResultType;
  2507. return *this;
  2508. }
  2509. if (result_id == 0) {
  2510. TheStatus = Status::ZeroResultId;
  2511. return *this;
  2512. }
  2513. TheInst.reserve(5);
  2514. TheInst.emplace_back(static_cast<uint32_t>(spv::Op::OpFMul));
  2515. TheInst.emplace_back(result_type);
  2516. TheInst.emplace_back(result_id);
  2517. TheInst.emplace_back(operand_1);
  2518. TheInst.emplace_back(operand_2);
  2519. return *this;
  2520. }
  2521. InstBuilder &InstBuilder::opUDiv(uint32_t result_type, uint32_t result_id,
  2522. uint32_t operand_1, uint32_t operand_2) {
  2523. if (!TheInst.empty()) {
  2524. TheStatus = Status::NestedInst;
  2525. return *this;
  2526. }
  2527. if (result_type == 0) {
  2528. TheStatus = Status::ZeroResultType;
  2529. return *this;
  2530. }
  2531. if (result_id == 0) {
  2532. TheStatus = Status::ZeroResultId;
  2533. return *this;
  2534. }
  2535. TheInst.reserve(5);
  2536. TheInst.emplace_back(static_cast<uint32_t>(spv::Op::OpUDiv));
  2537. TheInst.emplace_back(result_type);
  2538. TheInst.emplace_back(result_id);
  2539. TheInst.emplace_back(operand_1);
  2540. TheInst.emplace_back(operand_2);
  2541. return *this;
  2542. }
  2543. InstBuilder &InstBuilder::opSDiv(uint32_t result_type, uint32_t result_id,
  2544. uint32_t operand_1, uint32_t operand_2) {
  2545. if (!TheInst.empty()) {
  2546. TheStatus = Status::NestedInst;
  2547. return *this;
  2548. }
  2549. if (result_type == 0) {
  2550. TheStatus = Status::ZeroResultType;
  2551. return *this;
  2552. }
  2553. if (result_id == 0) {
  2554. TheStatus = Status::ZeroResultId;
  2555. return *this;
  2556. }
  2557. TheInst.reserve(5);
  2558. TheInst.emplace_back(static_cast<uint32_t>(spv::Op::OpSDiv));
  2559. TheInst.emplace_back(result_type);
  2560. TheInst.emplace_back(result_id);
  2561. TheInst.emplace_back(operand_1);
  2562. TheInst.emplace_back(operand_2);
  2563. return *this;
  2564. }
  2565. InstBuilder &InstBuilder::opFDiv(uint32_t result_type, uint32_t result_id,
  2566. uint32_t operand_1, uint32_t operand_2) {
  2567. if (!TheInst.empty()) {
  2568. TheStatus = Status::NestedInst;
  2569. return *this;
  2570. }
  2571. if (result_type == 0) {
  2572. TheStatus = Status::ZeroResultType;
  2573. return *this;
  2574. }
  2575. if (result_id == 0) {
  2576. TheStatus = Status::ZeroResultId;
  2577. return *this;
  2578. }
  2579. TheInst.reserve(5);
  2580. TheInst.emplace_back(static_cast<uint32_t>(spv::Op::OpFDiv));
  2581. TheInst.emplace_back(result_type);
  2582. TheInst.emplace_back(result_id);
  2583. TheInst.emplace_back(operand_1);
  2584. TheInst.emplace_back(operand_2);
  2585. return *this;
  2586. }
  2587. InstBuilder &InstBuilder::opUMod(uint32_t result_type, uint32_t result_id,
  2588. uint32_t operand_1, uint32_t operand_2) {
  2589. if (!TheInst.empty()) {
  2590. TheStatus = Status::NestedInst;
  2591. return *this;
  2592. }
  2593. if (result_type == 0) {
  2594. TheStatus = Status::ZeroResultType;
  2595. return *this;
  2596. }
  2597. if (result_id == 0) {
  2598. TheStatus = Status::ZeroResultId;
  2599. return *this;
  2600. }
  2601. TheInst.reserve(5);
  2602. TheInst.emplace_back(static_cast<uint32_t>(spv::Op::OpUMod));
  2603. TheInst.emplace_back(result_type);
  2604. TheInst.emplace_back(result_id);
  2605. TheInst.emplace_back(operand_1);
  2606. TheInst.emplace_back(operand_2);
  2607. return *this;
  2608. }
  2609. InstBuilder &InstBuilder::opSRem(uint32_t result_type, uint32_t result_id,
  2610. uint32_t operand_1, uint32_t operand_2) {
  2611. if (!TheInst.empty()) {
  2612. TheStatus = Status::NestedInst;
  2613. return *this;
  2614. }
  2615. if (result_type == 0) {
  2616. TheStatus = Status::ZeroResultType;
  2617. return *this;
  2618. }
  2619. if (result_id == 0) {
  2620. TheStatus = Status::ZeroResultId;
  2621. return *this;
  2622. }
  2623. TheInst.reserve(5);
  2624. TheInst.emplace_back(static_cast<uint32_t>(spv::Op::OpSRem));
  2625. TheInst.emplace_back(result_type);
  2626. TheInst.emplace_back(result_id);
  2627. TheInst.emplace_back(operand_1);
  2628. TheInst.emplace_back(operand_2);
  2629. return *this;
  2630. }
  2631. InstBuilder &InstBuilder::opSMod(uint32_t result_type, uint32_t result_id,
  2632. uint32_t operand_1, uint32_t operand_2) {
  2633. if (!TheInst.empty()) {
  2634. TheStatus = Status::NestedInst;
  2635. return *this;
  2636. }
  2637. if (result_type == 0) {
  2638. TheStatus = Status::ZeroResultType;
  2639. return *this;
  2640. }
  2641. if (result_id == 0) {
  2642. TheStatus = Status::ZeroResultId;
  2643. return *this;
  2644. }
  2645. TheInst.reserve(5);
  2646. TheInst.emplace_back(static_cast<uint32_t>(spv::Op::OpSMod));
  2647. TheInst.emplace_back(result_type);
  2648. TheInst.emplace_back(result_id);
  2649. TheInst.emplace_back(operand_1);
  2650. TheInst.emplace_back(operand_2);
  2651. return *this;
  2652. }
  2653. InstBuilder &InstBuilder::opFRem(uint32_t result_type, uint32_t result_id,
  2654. uint32_t operand_1, uint32_t operand_2) {
  2655. if (!TheInst.empty()) {
  2656. TheStatus = Status::NestedInst;
  2657. return *this;
  2658. }
  2659. if (result_type == 0) {
  2660. TheStatus = Status::ZeroResultType;
  2661. return *this;
  2662. }
  2663. if (result_id == 0) {
  2664. TheStatus = Status::ZeroResultId;
  2665. return *this;
  2666. }
  2667. TheInst.reserve(5);
  2668. TheInst.emplace_back(static_cast<uint32_t>(spv::Op::OpFRem));
  2669. TheInst.emplace_back(result_type);
  2670. TheInst.emplace_back(result_id);
  2671. TheInst.emplace_back(operand_1);
  2672. TheInst.emplace_back(operand_2);
  2673. return *this;
  2674. }
  2675. InstBuilder &InstBuilder::opFMod(uint32_t result_type, uint32_t result_id,
  2676. uint32_t operand_1, uint32_t operand_2) {
  2677. if (!TheInst.empty()) {
  2678. TheStatus = Status::NestedInst;
  2679. return *this;
  2680. }
  2681. if (result_type == 0) {
  2682. TheStatus = Status::ZeroResultType;
  2683. return *this;
  2684. }
  2685. if (result_id == 0) {
  2686. TheStatus = Status::ZeroResultId;
  2687. return *this;
  2688. }
  2689. TheInst.reserve(5);
  2690. TheInst.emplace_back(static_cast<uint32_t>(spv::Op::OpFMod));
  2691. TheInst.emplace_back(result_type);
  2692. TheInst.emplace_back(result_id);
  2693. TheInst.emplace_back(operand_1);
  2694. TheInst.emplace_back(operand_2);
  2695. return *this;
  2696. }
  2697. InstBuilder &InstBuilder::opVectorTimesScalar(uint32_t result_type,
  2698. uint32_t result_id,
  2699. uint32_t vector,
  2700. uint32_t scalar) {
  2701. if (!TheInst.empty()) {
  2702. TheStatus = Status::NestedInst;
  2703. return *this;
  2704. }
  2705. if (result_type == 0) {
  2706. TheStatus = Status::ZeroResultType;
  2707. return *this;
  2708. }
  2709. if (result_id == 0) {
  2710. TheStatus = Status::ZeroResultId;
  2711. return *this;
  2712. }
  2713. TheInst.reserve(5);
  2714. TheInst.emplace_back(static_cast<uint32_t>(spv::Op::OpVectorTimesScalar));
  2715. TheInst.emplace_back(result_type);
  2716. TheInst.emplace_back(result_id);
  2717. TheInst.emplace_back(vector);
  2718. TheInst.emplace_back(scalar);
  2719. return *this;
  2720. }
  2721. InstBuilder &InstBuilder::opMatrixTimesScalar(uint32_t result_type,
  2722. uint32_t result_id,
  2723. uint32_t matrix,
  2724. uint32_t scalar) {
  2725. if (!TheInst.empty()) {
  2726. TheStatus = Status::NestedInst;
  2727. return *this;
  2728. }
  2729. if (result_type == 0) {
  2730. TheStatus = Status::ZeroResultType;
  2731. return *this;
  2732. }
  2733. if (result_id == 0) {
  2734. TheStatus = Status::ZeroResultId;
  2735. return *this;
  2736. }
  2737. TheInst.reserve(5);
  2738. TheInst.emplace_back(static_cast<uint32_t>(spv::Op::OpMatrixTimesScalar));
  2739. TheInst.emplace_back(result_type);
  2740. TheInst.emplace_back(result_id);
  2741. TheInst.emplace_back(matrix);
  2742. TheInst.emplace_back(scalar);
  2743. return *this;
  2744. }
  2745. InstBuilder &InstBuilder::opVectorTimesMatrix(uint32_t result_type,
  2746. uint32_t result_id,
  2747. uint32_t vector,
  2748. uint32_t matrix) {
  2749. if (!TheInst.empty()) {
  2750. TheStatus = Status::NestedInst;
  2751. return *this;
  2752. }
  2753. if (result_type == 0) {
  2754. TheStatus = Status::ZeroResultType;
  2755. return *this;
  2756. }
  2757. if (result_id == 0) {
  2758. TheStatus = Status::ZeroResultId;
  2759. return *this;
  2760. }
  2761. TheInst.reserve(5);
  2762. TheInst.emplace_back(static_cast<uint32_t>(spv::Op::OpVectorTimesMatrix));
  2763. TheInst.emplace_back(result_type);
  2764. TheInst.emplace_back(result_id);
  2765. TheInst.emplace_back(vector);
  2766. TheInst.emplace_back(matrix);
  2767. return *this;
  2768. }
  2769. InstBuilder &InstBuilder::opMatrixTimesVector(uint32_t result_type,
  2770. uint32_t result_id,
  2771. uint32_t matrix,
  2772. uint32_t vector) {
  2773. if (!TheInst.empty()) {
  2774. TheStatus = Status::NestedInst;
  2775. return *this;
  2776. }
  2777. if (result_type == 0) {
  2778. TheStatus = Status::ZeroResultType;
  2779. return *this;
  2780. }
  2781. if (result_id == 0) {
  2782. TheStatus = Status::ZeroResultId;
  2783. return *this;
  2784. }
  2785. TheInst.reserve(5);
  2786. TheInst.emplace_back(static_cast<uint32_t>(spv::Op::OpMatrixTimesVector));
  2787. TheInst.emplace_back(result_type);
  2788. TheInst.emplace_back(result_id);
  2789. TheInst.emplace_back(matrix);
  2790. TheInst.emplace_back(vector);
  2791. return *this;
  2792. }
  2793. InstBuilder &InstBuilder::opMatrixTimesMatrix(uint32_t result_type,
  2794. uint32_t result_id,
  2795. uint32_t left_matrix,
  2796. uint32_t right_matrix) {
  2797. if (!TheInst.empty()) {
  2798. TheStatus = Status::NestedInst;
  2799. return *this;
  2800. }
  2801. if (result_type == 0) {
  2802. TheStatus = Status::ZeroResultType;
  2803. return *this;
  2804. }
  2805. if (result_id == 0) {
  2806. TheStatus = Status::ZeroResultId;
  2807. return *this;
  2808. }
  2809. TheInst.reserve(5);
  2810. TheInst.emplace_back(static_cast<uint32_t>(spv::Op::OpMatrixTimesMatrix));
  2811. TheInst.emplace_back(result_type);
  2812. TheInst.emplace_back(result_id);
  2813. TheInst.emplace_back(left_matrix);
  2814. TheInst.emplace_back(right_matrix);
  2815. return *this;
  2816. }
  2817. InstBuilder &InstBuilder::opOuterProduct(uint32_t result_type,
  2818. uint32_t result_id, uint32_t vector_1,
  2819. uint32_t vector_2) {
  2820. if (!TheInst.empty()) {
  2821. TheStatus = Status::NestedInst;
  2822. return *this;
  2823. }
  2824. if (result_type == 0) {
  2825. TheStatus = Status::ZeroResultType;
  2826. return *this;
  2827. }
  2828. if (result_id == 0) {
  2829. TheStatus = Status::ZeroResultId;
  2830. return *this;
  2831. }
  2832. TheInst.reserve(5);
  2833. TheInst.emplace_back(static_cast<uint32_t>(spv::Op::OpOuterProduct));
  2834. TheInst.emplace_back(result_type);
  2835. TheInst.emplace_back(result_id);
  2836. TheInst.emplace_back(vector_1);
  2837. TheInst.emplace_back(vector_2);
  2838. return *this;
  2839. }
  2840. InstBuilder &InstBuilder::opDot(uint32_t result_type, uint32_t result_id,
  2841. uint32_t vector_1, uint32_t vector_2) {
  2842. if (!TheInst.empty()) {
  2843. TheStatus = Status::NestedInst;
  2844. return *this;
  2845. }
  2846. if (result_type == 0) {
  2847. TheStatus = Status::ZeroResultType;
  2848. return *this;
  2849. }
  2850. if (result_id == 0) {
  2851. TheStatus = Status::ZeroResultId;
  2852. return *this;
  2853. }
  2854. TheInst.reserve(5);
  2855. TheInst.emplace_back(static_cast<uint32_t>(spv::Op::OpDot));
  2856. TheInst.emplace_back(result_type);
  2857. TheInst.emplace_back(result_id);
  2858. TheInst.emplace_back(vector_1);
  2859. TheInst.emplace_back(vector_2);
  2860. return *this;
  2861. }
  2862. InstBuilder &InstBuilder::opIAddCarry(uint32_t result_type, uint32_t result_id,
  2863. uint32_t operand_1, uint32_t operand_2) {
  2864. if (!TheInst.empty()) {
  2865. TheStatus = Status::NestedInst;
  2866. return *this;
  2867. }
  2868. if (result_type == 0) {
  2869. TheStatus = Status::ZeroResultType;
  2870. return *this;
  2871. }
  2872. if (result_id == 0) {
  2873. TheStatus = Status::ZeroResultId;
  2874. return *this;
  2875. }
  2876. TheInst.reserve(5);
  2877. TheInst.emplace_back(static_cast<uint32_t>(spv::Op::OpIAddCarry));
  2878. TheInst.emplace_back(result_type);
  2879. TheInst.emplace_back(result_id);
  2880. TheInst.emplace_back(operand_1);
  2881. TheInst.emplace_back(operand_2);
  2882. return *this;
  2883. }
  2884. InstBuilder &InstBuilder::opISubBorrow(uint32_t result_type, uint32_t result_id,
  2885. uint32_t operand_1, uint32_t operand_2) {
  2886. if (!TheInst.empty()) {
  2887. TheStatus = Status::NestedInst;
  2888. return *this;
  2889. }
  2890. if (result_type == 0) {
  2891. TheStatus = Status::ZeroResultType;
  2892. return *this;
  2893. }
  2894. if (result_id == 0) {
  2895. TheStatus = Status::ZeroResultId;
  2896. return *this;
  2897. }
  2898. TheInst.reserve(5);
  2899. TheInst.emplace_back(static_cast<uint32_t>(spv::Op::OpISubBorrow));
  2900. TheInst.emplace_back(result_type);
  2901. TheInst.emplace_back(result_id);
  2902. TheInst.emplace_back(operand_1);
  2903. TheInst.emplace_back(operand_2);
  2904. return *this;
  2905. }
  2906. InstBuilder &InstBuilder::opUMulExtended(uint32_t result_type,
  2907. uint32_t result_id, uint32_t operand_1,
  2908. uint32_t operand_2) {
  2909. if (!TheInst.empty()) {
  2910. TheStatus = Status::NestedInst;
  2911. return *this;
  2912. }
  2913. if (result_type == 0) {
  2914. TheStatus = Status::ZeroResultType;
  2915. return *this;
  2916. }
  2917. if (result_id == 0) {
  2918. TheStatus = Status::ZeroResultId;
  2919. return *this;
  2920. }
  2921. TheInst.reserve(5);
  2922. TheInst.emplace_back(static_cast<uint32_t>(spv::Op::OpUMulExtended));
  2923. TheInst.emplace_back(result_type);
  2924. TheInst.emplace_back(result_id);
  2925. TheInst.emplace_back(operand_1);
  2926. TheInst.emplace_back(operand_2);
  2927. return *this;
  2928. }
  2929. InstBuilder &InstBuilder::opSMulExtended(uint32_t result_type,
  2930. uint32_t result_id, uint32_t operand_1,
  2931. uint32_t operand_2) {
  2932. if (!TheInst.empty()) {
  2933. TheStatus = Status::NestedInst;
  2934. return *this;
  2935. }
  2936. if (result_type == 0) {
  2937. TheStatus = Status::ZeroResultType;
  2938. return *this;
  2939. }
  2940. if (result_id == 0) {
  2941. TheStatus = Status::ZeroResultId;
  2942. return *this;
  2943. }
  2944. TheInst.reserve(5);
  2945. TheInst.emplace_back(static_cast<uint32_t>(spv::Op::OpSMulExtended));
  2946. TheInst.emplace_back(result_type);
  2947. TheInst.emplace_back(result_id);
  2948. TheInst.emplace_back(operand_1);
  2949. TheInst.emplace_back(operand_2);
  2950. return *this;
  2951. }
  2952. InstBuilder &InstBuilder::opAny(uint32_t result_type, uint32_t result_id,
  2953. uint32_t vector) {
  2954. if (!TheInst.empty()) {
  2955. TheStatus = Status::NestedInst;
  2956. return *this;
  2957. }
  2958. if (result_type == 0) {
  2959. TheStatus = Status::ZeroResultType;
  2960. return *this;
  2961. }
  2962. if (result_id == 0) {
  2963. TheStatus = Status::ZeroResultId;
  2964. return *this;
  2965. }
  2966. TheInst.reserve(4);
  2967. TheInst.emplace_back(static_cast<uint32_t>(spv::Op::OpAny));
  2968. TheInst.emplace_back(result_type);
  2969. TheInst.emplace_back(result_id);
  2970. TheInst.emplace_back(vector);
  2971. return *this;
  2972. }
  2973. InstBuilder &InstBuilder::opAll(uint32_t result_type, uint32_t result_id,
  2974. uint32_t vector) {
  2975. if (!TheInst.empty()) {
  2976. TheStatus = Status::NestedInst;
  2977. return *this;
  2978. }
  2979. if (result_type == 0) {
  2980. TheStatus = Status::ZeroResultType;
  2981. return *this;
  2982. }
  2983. if (result_id == 0) {
  2984. TheStatus = Status::ZeroResultId;
  2985. return *this;
  2986. }
  2987. TheInst.reserve(4);
  2988. TheInst.emplace_back(static_cast<uint32_t>(spv::Op::OpAll));
  2989. TheInst.emplace_back(result_type);
  2990. TheInst.emplace_back(result_id);
  2991. TheInst.emplace_back(vector);
  2992. return *this;
  2993. }
  2994. InstBuilder &InstBuilder::opIsNan(uint32_t result_type, uint32_t result_id,
  2995. uint32_t x) {
  2996. if (!TheInst.empty()) {
  2997. TheStatus = Status::NestedInst;
  2998. return *this;
  2999. }
  3000. if (result_type == 0) {
  3001. TheStatus = Status::ZeroResultType;
  3002. return *this;
  3003. }
  3004. if (result_id == 0) {
  3005. TheStatus = Status::ZeroResultId;
  3006. return *this;
  3007. }
  3008. TheInst.reserve(4);
  3009. TheInst.emplace_back(static_cast<uint32_t>(spv::Op::OpIsNan));
  3010. TheInst.emplace_back(result_type);
  3011. TheInst.emplace_back(result_id);
  3012. TheInst.emplace_back(x);
  3013. return *this;
  3014. }
  3015. InstBuilder &InstBuilder::opIsInf(uint32_t result_type, uint32_t result_id,
  3016. uint32_t x) {
  3017. if (!TheInst.empty()) {
  3018. TheStatus = Status::NestedInst;
  3019. return *this;
  3020. }
  3021. if (result_type == 0) {
  3022. TheStatus = Status::ZeroResultType;
  3023. return *this;
  3024. }
  3025. if (result_id == 0) {
  3026. TheStatus = Status::ZeroResultId;
  3027. return *this;
  3028. }
  3029. TheInst.reserve(4);
  3030. TheInst.emplace_back(static_cast<uint32_t>(spv::Op::OpIsInf));
  3031. TheInst.emplace_back(result_type);
  3032. TheInst.emplace_back(result_id);
  3033. TheInst.emplace_back(x);
  3034. return *this;
  3035. }
  3036. InstBuilder &InstBuilder::opIsFinite(uint32_t result_type, uint32_t result_id,
  3037. uint32_t x) {
  3038. if (!TheInst.empty()) {
  3039. TheStatus = Status::NestedInst;
  3040. return *this;
  3041. }
  3042. if (result_type == 0) {
  3043. TheStatus = Status::ZeroResultType;
  3044. return *this;
  3045. }
  3046. if (result_id == 0) {
  3047. TheStatus = Status::ZeroResultId;
  3048. return *this;
  3049. }
  3050. TheInst.reserve(4);
  3051. TheInst.emplace_back(static_cast<uint32_t>(spv::Op::OpIsFinite));
  3052. TheInst.emplace_back(result_type);
  3053. TheInst.emplace_back(result_id);
  3054. TheInst.emplace_back(x);
  3055. return *this;
  3056. }
  3057. InstBuilder &InstBuilder::opIsNormal(uint32_t result_type, uint32_t result_id,
  3058. uint32_t x) {
  3059. if (!TheInst.empty()) {
  3060. TheStatus = Status::NestedInst;
  3061. return *this;
  3062. }
  3063. if (result_type == 0) {
  3064. TheStatus = Status::ZeroResultType;
  3065. return *this;
  3066. }
  3067. if (result_id == 0) {
  3068. TheStatus = Status::ZeroResultId;
  3069. return *this;
  3070. }
  3071. TheInst.reserve(4);
  3072. TheInst.emplace_back(static_cast<uint32_t>(spv::Op::OpIsNormal));
  3073. TheInst.emplace_back(result_type);
  3074. TheInst.emplace_back(result_id);
  3075. TheInst.emplace_back(x);
  3076. return *this;
  3077. }
  3078. InstBuilder &InstBuilder::opSignBitSet(uint32_t result_type, uint32_t result_id,
  3079. uint32_t x) {
  3080. if (!TheInst.empty()) {
  3081. TheStatus = Status::NestedInst;
  3082. return *this;
  3083. }
  3084. if (result_type == 0) {
  3085. TheStatus = Status::ZeroResultType;
  3086. return *this;
  3087. }
  3088. if (result_id == 0) {
  3089. TheStatus = Status::ZeroResultId;
  3090. return *this;
  3091. }
  3092. TheInst.reserve(4);
  3093. TheInst.emplace_back(static_cast<uint32_t>(spv::Op::OpSignBitSet));
  3094. TheInst.emplace_back(result_type);
  3095. TheInst.emplace_back(result_id);
  3096. TheInst.emplace_back(x);
  3097. return *this;
  3098. }
  3099. InstBuilder &InstBuilder::opLessOrGreater(uint32_t result_type,
  3100. uint32_t result_id, uint32_t x,
  3101. uint32_t y) {
  3102. if (!TheInst.empty()) {
  3103. TheStatus = Status::NestedInst;
  3104. return *this;
  3105. }
  3106. if (result_type == 0) {
  3107. TheStatus = Status::ZeroResultType;
  3108. return *this;
  3109. }
  3110. if (result_id == 0) {
  3111. TheStatus = Status::ZeroResultId;
  3112. return *this;
  3113. }
  3114. TheInst.reserve(5);
  3115. TheInst.emplace_back(static_cast<uint32_t>(spv::Op::OpLessOrGreater));
  3116. TheInst.emplace_back(result_type);
  3117. TheInst.emplace_back(result_id);
  3118. TheInst.emplace_back(x);
  3119. TheInst.emplace_back(y);
  3120. return *this;
  3121. }
  3122. InstBuilder &InstBuilder::opOrdered(uint32_t result_type, uint32_t result_id,
  3123. uint32_t x, uint32_t y) {
  3124. if (!TheInst.empty()) {
  3125. TheStatus = Status::NestedInst;
  3126. return *this;
  3127. }
  3128. if (result_type == 0) {
  3129. TheStatus = Status::ZeroResultType;
  3130. return *this;
  3131. }
  3132. if (result_id == 0) {
  3133. TheStatus = Status::ZeroResultId;
  3134. return *this;
  3135. }
  3136. TheInst.reserve(5);
  3137. TheInst.emplace_back(static_cast<uint32_t>(spv::Op::OpOrdered));
  3138. TheInst.emplace_back(result_type);
  3139. TheInst.emplace_back(result_id);
  3140. TheInst.emplace_back(x);
  3141. TheInst.emplace_back(y);
  3142. return *this;
  3143. }
  3144. InstBuilder &InstBuilder::opUnordered(uint32_t result_type, uint32_t result_id,
  3145. uint32_t x, uint32_t y) {
  3146. if (!TheInst.empty()) {
  3147. TheStatus = Status::NestedInst;
  3148. return *this;
  3149. }
  3150. if (result_type == 0) {
  3151. TheStatus = Status::ZeroResultType;
  3152. return *this;
  3153. }
  3154. if (result_id == 0) {
  3155. TheStatus = Status::ZeroResultId;
  3156. return *this;
  3157. }
  3158. TheInst.reserve(5);
  3159. TheInst.emplace_back(static_cast<uint32_t>(spv::Op::OpUnordered));
  3160. TheInst.emplace_back(result_type);
  3161. TheInst.emplace_back(result_id);
  3162. TheInst.emplace_back(x);
  3163. TheInst.emplace_back(y);
  3164. return *this;
  3165. }
  3166. InstBuilder &InstBuilder::opLogicalEqual(uint32_t result_type,
  3167. uint32_t result_id, uint32_t operand_1,
  3168. uint32_t operand_2) {
  3169. if (!TheInst.empty()) {
  3170. TheStatus = Status::NestedInst;
  3171. return *this;
  3172. }
  3173. if (result_type == 0) {
  3174. TheStatus = Status::ZeroResultType;
  3175. return *this;
  3176. }
  3177. if (result_id == 0) {
  3178. TheStatus = Status::ZeroResultId;
  3179. return *this;
  3180. }
  3181. TheInst.reserve(5);
  3182. TheInst.emplace_back(static_cast<uint32_t>(spv::Op::OpLogicalEqual));
  3183. TheInst.emplace_back(result_type);
  3184. TheInst.emplace_back(result_id);
  3185. TheInst.emplace_back(operand_1);
  3186. TheInst.emplace_back(operand_2);
  3187. return *this;
  3188. }
  3189. InstBuilder &InstBuilder::opLogicalNotEqual(uint32_t result_type,
  3190. uint32_t result_id,
  3191. uint32_t operand_1,
  3192. uint32_t operand_2) {
  3193. if (!TheInst.empty()) {
  3194. TheStatus = Status::NestedInst;
  3195. return *this;
  3196. }
  3197. if (result_type == 0) {
  3198. TheStatus = Status::ZeroResultType;
  3199. return *this;
  3200. }
  3201. if (result_id == 0) {
  3202. TheStatus = Status::ZeroResultId;
  3203. return *this;
  3204. }
  3205. TheInst.reserve(5);
  3206. TheInst.emplace_back(static_cast<uint32_t>(spv::Op::OpLogicalNotEqual));
  3207. TheInst.emplace_back(result_type);
  3208. TheInst.emplace_back(result_id);
  3209. TheInst.emplace_back(operand_1);
  3210. TheInst.emplace_back(operand_2);
  3211. return *this;
  3212. }
  3213. InstBuilder &InstBuilder::opLogicalOr(uint32_t result_type, uint32_t result_id,
  3214. uint32_t operand_1, uint32_t operand_2) {
  3215. if (!TheInst.empty()) {
  3216. TheStatus = Status::NestedInst;
  3217. return *this;
  3218. }
  3219. if (result_type == 0) {
  3220. TheStatus = Status::ZeroResultType;
  3221. return *this;
  3222. }
  3223. if (result_id == 0) {
  3224. TheStatus = Status::ZeroResultId;
  3225. return *this;
  3226. }
  3227. TheInst.reserve(5);
  3228. TheInst.emplace_back(static_cast<uint32_t>(spv::Op::OpLogicalOr));
  3229. TheInst.emplace_back(result_type);
  3230. TheInst.emplace_back(result_id);
  3231. TheInst.emplace_back(operand_1);
  3232. TheInst.emplace_back(operand_2);
  3233. return *this;
  3234. }
  3235. InstBuilder &InstBuilder::opLogicalAnd(uint32_t result_type, uint32_t result_id,
  3236. uint32_t operand_1, uint32_t operand_2) {
  3237. if (!TheInst.empty()) {
  3238. TheStatus = Status::NestedInst;
  3239. return *this;
  3240. }
  3241. if (result_type == 0) {
  3242. TheStatus = Status::ZeroResultType;
  3243. return *this;
  3244. }
  3245. if (result_id == 0) {
  3246. TheStatus = Status::ZeroResultId;
  3247. return *this;
  3248. }
  3249. TheInst.reserve(5);
  3250. TheInst.emplace_back(static_cast<uint32_t>(spv::Op::OpLogicalAnd));
  3251. TheInst.emplace_back(result_type);
  3252. TheInst.emplace_back(result_id);
  3253. TheInst.emplace_back(operand_1);
  3254. TheInst.emplace_back(operand_2);
  3255. return *this;
  3256. }
  3257. InstBuilder &InstBuilder::opLogicalNot(uint32_t result_type, uint32_t result_id,
  3258. uint32_t operand) {
  3259. if (!TheInst.empty()) {
  3260. TheStatus = Status::NestedInst;
  3261. return *this;
  3262. }
  3263. if (result_type == 0) {
  3264. TheStatus = Status::ZeroResultType;
  3265. return *this;
  3266. }
  3267. if (result_id == 0) {
  3268. TheStatus = Status::ZeroResultId;
  3269. return *this;
  3270. }
  3271. TheInst.reserve(4);
  3272. TheInst.emplace_back(static_cast<uint32_t>(spv::Op::OpLogicalNot));
  3273. TheInst.emplace_back(result_type);
  3274. TheInst.emplace_back(result_id);
  3275. TheInst.emplace_back(operand);
  3276. return *this;
  3277. }
  3278. InstBuilder &InstBuilder::opSelect(uint32_t result_type, uint32_t result_id,
  3279. uint32_t condition, uint32_t object_1,
  3280. uint32_t object_2) {
  3281. if (!TheInst.empty()) {
  3282. TheStatus = Status::NestedInst;
  3283. return *this;
  3284. }
  3285. if (result_type == 0) {
  3286. TheStatus = Status::ZeroResultType;
  3287. return *this;
  3288. }
  3289. if (result_id == 0) {
  3290. TheStatus = Status::ZeroResultId;
  3291. return *this;
  3292. }
  3293. TheInst.reserve(6);
  3294. TheInst.emplace_back(static_cast<uint32_t>(spv::Op::OpSelect));
  3295. TheInst.emplace_back(result_type);
  3296. TheInst.emplace_back(result_id);
  3297. TheInst.emplace_back(condition);
  3298. TheInst.emplace_back(object_1);
  3299. TheInst.emplace_back(object_2);
  3300. return *this;
  3301. }
  3302. InstBuilder &InstBuilder::opIEqual(uint32_t result_type, uint32_t result_id,
  3303. uint32_t operand_1, uint32_t operand_2) {
  3304. if (!TheInst.empty()) {
  3305. TheStatus = Status::NestedInst;
  3306. return *this;
  3307. }
  3308. if (result_type == 0) {
  3309. TheStatus = Status::ZeroResultType;
  3310. return *this;
  3311. }
  3312. if (result_id == 0) {
  3313. TheStatus = Status::ZeroResultId;
  3314. return *this;
  3315. }
  3316. TheInst.reserve(5);
  3317. TheInst.emplace_back(static_cast<uint32_t>(spv::Op::OpIEqual));
  3318. TheInst.emplace_back(result_type);
  3319. TheInst.emplace_back(result_id);
  3320. TheInst.emplace_back(operand_1);
  3321. TheInst.emplace_back(operand_2);
  3322. return *this;
  3323. }
  3324. InstBuilder &InstBuilder::opINotEqual(uint32_t result_type, uint32_t result_id,
  3325. uint32_t operand_1, uint32_t operand_2) {
  3326. if (!TheInst.empty()) {
  3327. TheStatus = Status::NestedInst;
  3328. return *this;
  3329. }
  3330. if (result_type == 0) {
  3331. TheStatus = Status::ZeroResultType;
  3332. return *this;
  3333. }
  3334. if (result_id == 0) {
  3335. TheStatus = Status::ZeroResultId;
  3336. return *this;
  3337. }
  3338. TheInst.reserve(5);
  3339. TheInst.emplace_back(static_cast<uint32_t>(spv::Op::OpINotEqual));
  3340. TheInst.emplace_back(result_type);
  3341. TheInst.emplace_back(result_id);
  3342. TheInst.emplace_back(operand_1);
  3343. TheInst.emplace_back(operand_2);
  3344. return *this;
  3345. }
  3346. InstBuilder &InstBuilder::opUGreaterThan(uint32_t result_type,
  3347. uint32_t result_id, uint32_t operand_1,
  3348. uint32_t operand_2) {
  3349. if (!TheInst.empty()) {
  3350. TheStatus = Status::NestedInst;
  3351. return *this;
  3352. }
  3353. if (result_type == 0) {
  3354. TheStatus = Status::ZeroResultType;
  3355. return *this;
  3356. }
  3357. if (result_id == 0) {
  3358. TheStatus = Status::ZeroResultId;
  3359. return *this;
  3360. }
  3361. TheInst.reserve(5);
  3362. TheInst.emplace_back(static_cast<uint32_t>(spv::Op::OpUGreaterThan));
  3363. TheInst.emplace_back(result_type);
  3364. TheInst.emplace_back(result_id);
  3365. TheInst.emplace_back(operand_1);
  3366. TheInst.emplace_back(operand_2);
  3367. return *this;
  3368. }
  3369. InstBuilder &InstBuilder::opSGreaterThan(uint32_t result_type,
  3370. uint32_t result_id, uint32_t operand_1,
  3371. uint32_t operand_2) {
  3372. if (!TheInst.empty()) {
  3373. TheStatus = Status::NestedInst;
  3374. return *this;
  3375. }
  3376. if (result_type == 0) {
  3377. TheStatus = Status::ZeroResultType;
  3378. return *this;
  3379. }
  3380. if (result_id == 0) {
  3381. TheStatus = Status::ZeroResultId;
  3382. return *this;
  3383. }
  3384. TheInst.reserve(5);
  3385. TheInst.emplace_back(static_cast<uint32_t>(spv::Op::OpSGreaterThan));
  3386. TheInst.emplace_back(result_type);
  3387. TheInst.emplace_back(result_id);
  3388. TheInst.emplace_back(operand_1);
  3389. TheInst.emplace_back(operand_2);
  3390. return *this;
  3391. }
  3392. InstBuilder &InstBuilder::opUGreaterThanEqual(uint32_t result_type,
  3393. uint32_t result_id,
  3394. uint32_t operand_1,
  3395. uint32_t operand_2) {
  3396. if (!TheInst.empty()) {
  3397. TheStatus = Status::NestedInst;
  3398. return *this;
  3399. }
  3400. if (result_type == 0) {
  3401. TheStatus = Status::ZeroResultType;
  3402. return *this;
  3403. }
  3404. if (result_id == 0) {
  3405. TheStatus = Status::ZeroResultId;
  3406. return *this;
  3407. }
  3408. TheInst.reserve(5);
  3409. TheInst.emplace_back(static_cast<uint32_t>(spv::Op::OpUGreaterThanEqual));
  3410. TheInst.emplace_back(result_type);
  3411. TheInst.emplace_back(result_id);
  3412. TheInst.emplace_back(operand_1);
  3413. TheInst.emplace_back(operand_2);
  3414. return *this;
  3415. }
  3416. InstBuilder &InstBuilder::opSGreaterThanEqual(uint32_t result_type,
  3417. uint32_t result_id,
  3418. uint32_t operand_1,
  3419. uint32_t operand_2) {
  3420. if (!TheInst.empty()) {
  3421. TheStatus = Status::NestedInst;
  3422. return *this;
  3423. }
  3424. if (result_type == 0) {
  3425. TheStatus = Status::ZeroResultType;
  3426. return *this;
  3427. }
  3428. if (result_id == 0) {
  3429. TheStatus = Status::ZeroResultId;
  3430. return *this;
  3431. }
  3432. TheInst.reserve(5);
  3433. TheInst.emplace_back(static_cast<uint32_t>(spv::Op::OpSGreaterThanEqual));
  3434. TheInst.emplace_back(result_type);
  3435. TheInst.emplace_back(result_id);
  3436. TheInst.emplace_back(operand_1);
  3437. TheInst.emplace_back(operand_2);
  3438. return *this;
  3439. }
  3440. InstBuilder &InstBuilder::opULessThan(uint32_t result_type, uint32_t result_id,
  3441. uint32_t operand_1, uint32_t operand_2) {
  3442. if (!TheInst.empty()) {
  3443. TheStatus = Status::NestedInst;
  3444. return *this;
  3445. }
  3446. if (result_type == 0) {
  3447. TheStatus = Status::ZeroResultType;
  3448. return *this;
  3449. }
  3450. if (result_id == 0) {
  3451. TheStatus = Status::ZeroResultId;
  3452. return *this;
  3453. }
  3454. TheInst.reserve(5);
  3455. TheInst.emplace_back(static_cast<uint32_t>(spv::Op::OpULessThan));
  3456. TheInst.emplace_back(result_type);
  3457. TheInst.emplace_back(result_id);
  3458. TheInst.emplace_back(operand_1);
  3459. TheInst.emplace_back(operand_2);
  3460. return *this;
  3461. }
  3462. InstBuilder &InstBuilder::opSLessThan(uint32_t result_type, uint32_t result_id,
  3463. uint32_t operand_1, uint32_t operand_2) {
  3464. if (!TheInst.empty()) {
  3465. TheStatus = Status::NestedInst;
  3466. return *this;
  3467. }
  3468. if (result_type == 0) {
  3469. TheStatus = Status::ZeroResultType;
  3470. return *this;
  3471. }
  3472. if (result_id == 0) {
  3473. TheStatus = Status::ZeroResultId;
  3474. return *this;
  3475. }
  3476. TheInst.reserve(5);
  3477. TheInst.emplace_back(static_cast<uint32_t>(spv::Op::OpSLessThan));
  3478. TheInst.emplace_back(result_type);
  3479. TheInst.emplace_back(result_id);
  3480. TheInst.emplace_back(operand_1);
  3481. TheInst.emplace_back(operand_2);
  3482. return *this;
  3483. }
  3484. InstBuilder &InstBuilder::opULessThanEqual(uint32_t result_type,
  3485. uint32_t result_id,
  3486. uint32_t operand_1,
  3487. uint32_t operand_2) {
  3488. if (!TheInst.empty()) {
  3489. TheStatus = Status::NestedInst;
  3490. return *this;
  3491. }
  3492. if (result_type == 0) {
  3493. TheStatus = Status::ZeroResultType;
  3494. return *this;
  3495. }
  3496. if (result_id == 0) {
  3497. TheStatus = Status::ZeroResultId;
  3498. return *this;
  3499. }
  3500. TheInst.reserve(5);
  3501. TheInst.emplace_back(static_cast<uint32_t>(spv::Op::OpULessThanEqual));
  3502. TheInst.emplace_back(result_type);
  3503. TheInst.emplace_back(result_id);
  3504. TheInst.emplace_back(operand_1);
  3505. TheInst.emplace_back(operand_2);
  3506. return *this;
  3507. }
  3508. InstBuilder &InstBuilder::opSLessThanEqual(uint32_t result_type,
  3509. uint32_t result_id,
  3510. uint32_t operand_1,
  3511. uint32_t operand_2) {
  3512. if (!TheInst.empty()) {
  3513. TheStatus = Status::NestedInst;
  3514. return *this;
  3515. }
  3516. if (result_type == 0) {
  3517. TheStatus = Status::ZeroResultType;
  3518. return *this;
  3519. }
  3520. if (result_id == 0) {
  3521. TheStatus = Status::ZeroResultId;
  3522. return *this;
  3523. }
  3524. TheInst.reserve(5);
  3525. TheInst.emplace_back(static_cast<uint32_t>(spv::Op::OpSLessThanEqual));
  3526. TheInst.emplace_back(result_type);
  3527. TheInst.emplace_back(result_id);
  3528. TheInst.emplace_back(operand_1);
  3529. TheInst.emplace_back(operand_2);
  3530. return *this;
  3531. }
  3532. InstBuilder &InstBuilder::opFOrdEqual(uint32_t result_type, uint32_t result_id,
  3533. uint32_t operand_1, uint32_t operand_2) {
  3534. if (!TheInst.empty()) {
  3535. TheStatus = Status::NestedInst;
  3536. return *this;
  3537. }
  3538. if (result_type == 0) {
  3539. TheStatus = Status::ZeroResultType;
  3540. return *this;
  3541. }
  3542. if (result_id == 0) {
  3543. TheStatus = Status::ZeroResultId;
  3544. return *this;
  3545. }
  3546. TheInst.reserve(5);
  3547. TheInst.emplace_back(static_cast<uint32_t>(spv::Op::OpFOrdEqual));
  3548. TheInst.emplace_back(result_type);
  3549. TheInst.emplace_back(result_id);
  3550. TheInst.emplace_back(operand_1);
  3551. TheInst.emplace_back(operand_2);
  3552. return *this;
  3553. }
  3554. InstBuilder &InstBuilder::opFUnordEqual(uint32_t result_type,
  3555. uint32_t result_id, uint32_t operand_1,
  3556. uint32_t operand_2) {
  3557. if (!TheInst.empty()) {
  3558. TheStatus = Status::NestedInst;
  3559. return *this;
  3560. }
  3561. if (result_type == 0) {
  3562. TheStatus = Status::ZeroResultType;
  3563. return *this;
  3564. }
  3565. if (result_id == 0) {
  3566. TheStatus = Status::ZeroResultId;
  3567. return *this;
  3568. }
  3569. TheInst.reserve(5);
  3570. TheInst.emplace_back(static_cast<uint32_t>(spv::Op::OpFUnordEqual));
  3571. TheInst.emplace_back(result_type);
  3572. TheInst.emplace_back(result_id);
  3573. TheInst.emplace_back(operand_1);
  3574. TheInst.emplace_back(operand_2);
  3575. return *this;
  3576. }
  3577. InstBuilder &InstBuilder::opFOrdNotEqual(uint32_t result_type,
  3578. uint32_t result_id, uint32_t operand_1,
  3579. uint32_t operand_2) {
  3580. if (!TheInst.empty()) {
  3581. TheStatus = Status::NestedInst;
  3582. return *this;
  3583. }
  3584. if (result_type == 0) {
  3585. TheStatus = Status::ZeroResultType;
  3586. return *this;
  3587. }
  3588. if (result_id == 0) {
  3589. TheStatus = Status::ZeroResultId;
  3590. return *this;
  3591. }
  3592. TheInst.reserve(5);
  3593. TheInst.emplace_back(static_cast<uint32_t>(spv::Op::OpFOrdNotEqual));
  3594. TheInst.emplace_back(result_type);
  3595. TheInst.emplace_back(result_id);
  3596. TheInst.emplace_back(operand_1);
  3597. TheInst.emplace_back(operand_2);
  3598. return *this;
  3599. }
  3600. InstBuilder &InstBuilder::opFUnordNotEqual(uint32_t result_type,
  3601. uint32_t result_id,
  3602. uint32_t operand_1,
  3603. uint32_t operand_2) {
  3604. if (!TheInst.empty()) {
  3605. TheStatus = Status::NestedInst;
  3606. return *this;
  3607. }
  3608. if (result_type == 0) {
  3609. TheStatus = Status::ZeroResultType;
  3610. return *this;
  3611. }
  3612. if (result_id == 0) {
  3613. TheStatus = Status::ZeroResultId;
  3614. return *this;
  3615. }
  3616. TheInst.reserve(5);
  3617. TheInst.emplace_back(static_cast<uint32_t>(spv::Op::OpFUnordNotEqual));
  3618. TheInst.emplace_back(result_type);
  3619. TheInst.emplace_back(result_id);
  3620. TheInst.emplace_back(operand_1);
  3621. TheInst.emplace_back(operand_2);
  3622. return *this;
  3623. }
  3624. InstBuilder &InstBuilder::opFOrdLessThan(uint32_t result_type,
  3625. uint32_t result_id, uint32_t operand_1,
  3626. uint32_t operand_2) {
  3627. if (!TheInst.empty()) {
  3628. TheStatus = Status::NestedInst;
  3629. return *this;
  3630. }
  3631. if (result_type == 0) {
  3632. TheStatus = Status::ZeroResultType;
  3633. return *this;
  3634. }
  3635. if (result_id == 0) {
  3636. TheStatus = Status::ZeroResultId;
  3637. return *this;
  3638. }
  3639. TheInst.reserve(5);
  3640. TheInst.emplace_back(static_cast<uint32_t>(spv::Op::OpFOrdLessThan));
  3641. TheInst.emplace_back(result_type);
  3642. TheInst.emplace_back(result_id);
  3643. TheInst.emplace_back(operand_1);
  3644. TheInst.emplace_back(operand_2);
  3645. return *this;
  3646. }
  3647. InstBuilder &InstBuilder::opFUnordLessThan(uint32_t result_type,
  3648. uint32_t result_id,
  3649. uint32_t operand_1,
  3650. uint32_t operand_2) {
  3651. if (!TheInst.empty()) {
  3652. TheStatus = Status::NestedInst;
  3653. return *this;
  3654. }
  3655. if (result_type == 0) {
  3656. TheStatus = Status::ZeroResultType;
  3657. return *this;
  3658. }
  3659. if (result_id == 0) {
  3660. TheStatus = Status::ZeroResultId;
  3661. return *this;
  3662. }
  3663. TheInst.reserve(5);
  3664. TheInst.emplace_back(static_cast<uint32_t>(spv::Op::OpFUnordLessThan));
  3665. TheInst.emplace_back(result_type);
  3666. TheInst.emplace_back(result_id);
  3667. TheInst.emplace_back(operand_1);
  3668. TheInst.emplace_back(operand_2);
  3669. return *this;
  3670. }
  3671. InstBuilder &InstBuilder::opFOrdGreaterThan(uint32_t result_type,
  3672. uint32_t result_id,
  3673. uint32_t operand_1,
  3674. uint32_t operand_2) {
  3675. if (!TheInst.empty()) {
  3676. TheStatus = Status::NestedInst;
  3677. return *this;
  3678. }
  3679. if (result_type == 0) {
  3680. TheStatus = Status::ZeroResultType;
  3681. return *this;
  3682. }
  3683. if (result_id == 0) {
  3684. TheStatus = Status::ZeroResultId;
  3685. return *this;
  3686. }
  3687. TheInst.reserve(5);
  3688. TheInst.emplace_back(static_cast<uint32_t>(spv::Op::OpFOrdGreaterThan));
  3689. TheInst.emplace_back(result_type);
  3690. TheInst.emplace_back(result_id);
  3691. TheInst.emplace_back(operand_1);
  3692. TheInst.emplace_back(operand_2);
  3693. return *this;
  3694. }
  3695. InstBuilder &InstBuilder::opFUnordGreaterThan(uint32_t result_type,
  3696. uint32_t result_id,
  3697. uint32_t operand_1,
  3698. uint32_t operand_2) {
  3699. if (!TheInst.empty()) {
  3700. TheStatus = Status::NestedInst;
  3701. return *this;
  3702. }
  3703. if (result_type == 0) {
  3704. TheStatus = Status::ZeroResultType;
  3705. return *this;
  3706. }
  3707. if (result_id == 0) {
  3708. TheStatus = Status::ZeroResultId;
  3709. return *this;
  3710. }
  3711. TheInst.reserve(5);
  3712. TheInst.emplace_back(static_cast<uint32_t>(spv::Op::OpFUnordGreaterThan));
  3713. TheInst.emplace_back(result_type);
  3714. TheInst.emplace_back(result_id);
  3715. TheInst.emplace_back(operand_1);
  3716. TheInst.emplace_back(operand_2);
  3717. return *this;
  3718. }
  3719. InstBuilder &InstBuilder::opFOrdLessThanEqual(uint32_t result_type,
  3720. uint32_t result_id,
  3721. uint32_t operand_1,
  3722. uint32_t operand_2) {
  3723. if (!TheInst.empty()) {
  3724. TheStatus = Status::NestedInst;
  3725. return *this;
  3726. }
  3727. if (result_type == 0) {
  3728. TheStatus = Status::ZeroResultType;
  3729. return *this;
  3730. }
  3731. if (result_id == 0) {
  3732. TheStatus = Status::ZeroResultId;
  3733. return *this;
  3734. }
  3735. TheInst.reserve(5);
  3736. TheInst.emplace_back(static_cast<uint32_t>(spv::Op::OpFOrdLessThanEqual));
  3737. TheInst.emplace_back(result_type);
  3738. TheInst.emplace_back(result_id);
  3739. TheInst.emplace_back(operand_1);
  3740. TheInst.emplace_back(operand_2);
  3741. return *this;
  3742. }
  3743. InstBuilder &InstBuilder::opFUnordLessThanEqual(uint32_t result_type,
  3744. uint32_t result_id,
  3745. uint32_t operand_1,
  3746. uint32_t operand_2) {
  3747. if (!TheInst.empty()) {
  3748. TheStatus = Status::NestedInst;
  3749. return *this;
  3750. }
  3751. if (result_type == 0) {
  3752. TheStatus = Status::ZeroResultType;
  3753. return *this;
  3754. }
  3755. if (result_id == 0) {
  3756. TheStatus = Status::ZeroResultId;
  3757. return *this;
  3758. }
  3759. TheInst.reserve(5);
  3760. TheInst.emplace_back(static_cast<uint32_t>(spv::Op::OpFUnordLessThanEqual));
  3761. TheInst.emplace_back(result_type);
  3762. TheInst.emplace_back(result_id);
  3763. TheInst.emplace_back(operand_1);
  3764. TheInst.emplace_back(operand_2);
  3765. return *this;
  3766. }
  3767. InstBuilder &InstBuilder::opFOrdGreaterThanEqual(uint32_t result_type,
  3768. uint32_t result_id,
  3769. uint32_t operand_1,
  3770. uint32_t operand_2) {
  3771. if (!TheInst.empty()) {
  3772. TheStatus = Status::NestedInst;
  3773. return *this;
  3774. }
  3775. if (result_type == 0) {
  3776. TheStatus = Status::ZeroResultType;
  3777. return *this;
  3778. }
  3779. if (result_id == 0) {
  3780. TheStatus = Status::ZeroResultId;
  3781. return *this;
  3782. }
  3783. TheInst.reserve(5);
  3784. TheInst.emplace_back(static_cast<uint32_t>(spv::Op::OpFOrdGreaterThanEqual));
  3785. TheInst.emplace_back(result_type);
  3786. TheInst.emplace_back(result_id);
  3787. TheInst.emplace_back(operand_1);
  3788. TheInst.emplace_back(operand_2);
  3789. return *this;
  3790. }
  3791. InstBuilder &InstBuilder::opFUnordGreaterThanEqual(uint32_t result_type,
  3792. uint32_t result_id,
  3793. uint32_t operand_1,
  3794. uint32_t operand_2) {
  3795. if (!TheInst.empty()) {
  3796. TheStatus = Status::NestedInst;
  3797. return *this;
  3798. }
  3799. if (result_type == 0) {
  3800. TheStatus = Status::ZeroResultType;
  3801. return *this;
  3802. }
  3803. if (result_id == 0) {
  3804. TheStatus = Status::ZeroResultId;
  3805. return *this;
  3806. }
  3807. TheInst.reserve(5);
  3808. TheInst.emplace_back(
  3809. static_cast<uint32_t>(spv::Op::OpFUnordGreaterThanEqual));
  3810. TheInst.emplace_back(result_type);
  3811. TheInst.emplace_back(result_id);
  3812. TheInst.emplace_back(operand_1);
  3813. TheInst.emplace_back(operand_2);
  3814. return *this;
  3815. }
  3816. InstBuilder &InstBuilder::opShiftRightLogical(uint32_t result_type,
  3817. uint32_t result_id, uint32_t base,
  3818. uint32_t shift) {
  3819. if (!TheInst.empty()) {
  3820. TheStatus = Status::NestedInst;
  3821. return *this;
  3822. }
  3823. if (result_type == 0) {
  3824. TheStatus = Status::ZeroResultType;
  3825. return *this;
  3826. }
  3827. if (result_id == 0) {
  3828. TheStatus = Status::ZeroResultId;
  3829. return *this;
  3830. }
  3831. TheInst.reserve(5);
  3832. TheInst.emplace_back(static_cast<uint32_t>(spv::Op::OpShiftRightLogical));
  3833. TheInst.emplace_back(result_type);
  3834. TheInst.emplace_back(result_id);
  3835. TheInst.emplace_back(base);
  3836. TheInst.emplace_back(shift);
  3837. return *this;
  3838. }
  3839. InstBuilder &InstBuilder::opShiftRightArithmetic(uint32_t result_type,
  3840. uint32_t result_id,
  3841. uint32_t base,
  3842. uint32_t shift) {
  3843. if (!TheInst.empty()) {
  3844. TheStatus = Status::NestedInst;
  3845. return *this;
  3846. }
  3847. if (result_type == 0) {
  3848. TheStatus = Status::ZeroResultType;
  3849. return *this;
  3850. }
  3851. if (result_id == 0) {
  3852. TheStatus = Status::ZeroResultId;
  3853. return *this;
  3854. }
  3855. TheInst.reserve(5);
  3856. TheInst.emplace_back(static_cast<uint32_t>(spv::Op::OpShiftRightArithmetic));
  3857. TheInst.emplace_back(result_type);
  3858. TheInst.emplace_back(result_id);
  3859. TheInst.emplace_back(base);
  3860. TheInst.emplace_back(shift);
  3861. return *this;
  3862. }
  3863. InstBuilder &InstBuilder::opShiftLeftLogical(uint32_t result_type,
  3864. uint32_t result_id, uint32_t base,
  3865. uint32_t shift) {
  3866. if (!TheInst.empty()) {
  3867. TheStatus = Status::NestedInst;
  3868. return *this;
  3869. }
  3870. if (result_type == 0) {
  3871. TheStatus = Status::ZeroResultType;
  3872. return *this;
  3873. }
  3874. if (result_id == 0) {
  3875. TheStatus = Status::ZeroResultId;
  3876. return *this;
  3877. }
  3878. TheInst.reserve(5);
  3879. TheInst.emplace_back(static_cast<uint32_t>(spv::Op::OpShiftLeftLogical));
  3880. TheInst.emplace_back(result_type);
  3881. TheInst.emplace_back(result_id);
  3882. TheInst.emplace_back(base);
  3883. TheInst.emplace_back(shift);
  3884. return *this;
  3885. }
  3886. InstBuilder &InstBuilder::opBitwiseOr(uint32_t result_type, uint32_t result_id,
  3887. uint32_t operand_1, uint32_t operand_2) {
  3888. if (!TheInst.empty()) {
  3889. TheStatus = Status::NestedInst;
  3890. return *this;
  3891. }
  3892. if (result_type == 0) {
  3893. TheStatus = Status::ZeroResultType;
  3894. return *this;
  3895. }
  3896. if (result_id == 0) {
  3897. TheStatus = Status::ZeroResultId;
  3898. return *this;
  3899. }
  3900. TheInst.reserve(5);
  3901. TheInst.emplace_back(static_cast<uint32_t>(spv::Op::OpBitwiseOr));
  3902. TheInst.emplace_back(result_type);
  3903. TheInst.emplace_back(result_id);
  3904. TheInst.emplace_back(operand_1);
  3905. TheInst.emplace_back(operand_2);
  3906. return *this;
  3907. }
  3908. InstBuilder &InstBuilder::opBitwiseXor(uint32_t result_type, uint32_t result_id,
  3909. uint32_t operand_1, uint32_t operand_2) {
  3910. if (!TheInst.empty()) {
  3911. TheStatus = Status::NestedInst;
  3912. return *this;
  3913. }
  3914. if (result_type == 0) {
  3915. TheStatus = Status::ZeroResultType;
  3916. return *this;
  3917. }
  3918. if (result_id == 0) {
  3919. TheStatus = Status::ZeroResultId;
  3920. return *this;
  3921. }
  3922. TheInst.reserve(5);
  3923. TheInst.emplace_back(static_cast<uint32_t>(spv::Op::OpBitwiseXor));
  3924. TheInst.emplace_back(result_type);
  3925. TheInst.emplace_back(result_id);
  3926. TheInst.emplace_back(operand_1);
  3927. TheInst.emplace_back(operand_2);
  3928. return *this;
  3929. }
  3930. InstBuilder &InstBuilder::opBitwiseAnd(uint32_t result_type, uint32_t result_id,
  3931. uint32_t operand_1, uint32_t operand_2) {
  3932. if (!TheInst.empty()) {
  3933. TheStatus = Status::NestedInst;
  3934. return *this;
  3935. }
  3936. if (result_type == 0) {
  3937. TheStatus = Status::ZeroResultType;
  3938. return *this;
  3939. }
  3940. if (result_id == 0) {
  3941. TheStatus = Status::ZeroResultId;
  3942. return *this;
  3943. }
  3944. TheInst.reserve(5);
  3945. TheInst.emplace_back(static_cast<uint32_t>(spv::Op::OpBitwiseAnd));
  3946. TheInst.emplace_back(result_type);
  3947. TheInst.emplace_back(result_id);
  3948. TheInst.emplace_back(operand_1);
  3949. TheInst.emplace_back(operand_2);
  3950. return *this;
  3951. }
  3952. InstBuilder &InstBuilder::opNot(uint32_t result_type, uint32_t result_id,
  3953. uint32_t operand) {
  3954. if (!TheInst.empty()) {
  3955. TheStatus = Status::NestedInst;
  3956. return *this;
  3957. }
  3958. if (result_type == 0) {
  3959. TheStatus = Status::ZeroResultType;
  3960. return *this;
  3961. }
  3962. if (result_id == 0) {
  3963. TheStatus = Status::ZeroResultId;
  3964. return *this;
  3965. }
  3966. TheInst.reserve(4);
  3967. TheInst.emplace_back(static_cast<uint32_t>(spv::Op::OpNot));
  3968. TheInst.emplace_back(result_type);
  3969. TheInst.emplace_back(result_id);
  3970. TheInst.emplace_back(operand);
  3971. return *this;
  3972. }
  3973. InstBuilder &InstBuilder::opBitFieldInsert(uint32_t result_type,
  3974. uint32_t result_id, uint32_t base,
  3975. uint32_t insert, uint32_t offset,
  3976. uint32_t count) {
  3977. if (!TheInst.empty()) {
  3978. TheStatus = Status::NestedInst;
  3979. return *this;
  3980. }
  3981. if (result_type == 0) {
  3982. TheStatus = Status::ZeroResultType;
  3983. return *this;
  3984. }
  3985. if (result_id == 0) {
  3986. TheStatus = Status::ZeroResultId;
  3987. return *this;
  3988. }
  3989. TheInst.reserve(7);
  3990. TheInst.emplace_back(static_cast<uint32_t>(spv::Op::OpBitFieldInsert));
  3991. TheInst.emplace_back(result_type);
  3992. TheInst.emplace_back(result_id);
  3993. TheInst.emplace_back(base);
  3994. TheInst.emplace_back(insert);
  3995. TheInst.emplace_back(offset);
  3996. TheInst.emplace_back(count);
  3997. return *this;
  3998. }
  3999. InstBuilder &InstBuilder::opBitFieldSExtract(uint32_t result_type,
  4000. uint32_t result_id, uint32_t base,
  4001. uint32_t offset, uint32_t count) {
  4002. if (!TheInst.empty()) {
  4003. TheStatus = Status::NestedInst;
  4004. return *this;
  4005. }
  4006. if (result_type == 0) {
  4007. TheStatus = Status::ZeroResultType;
  4008. return *this;
  4009. }
  4010. if (result_id == 0) {
  4011. TheStatus = Status::ZeroResultId;
  4012. return *this;
  4013. }
  4014. TheInst.reserve(6);
  4015. TheInst.emplace_back(static_cast<uint32_t>(spv::Op::OpBitFieldSExtract));
  4016. TheInst.emplace_back(result_type);
  4017. TheInst.emplace_back(result_id);
  4018. TheInst.emplace_back(base);
  4019. TheInst.emplace_back(offset);
  4020. TheInst.emplace_back(count);
  4021. return *this;
  4022. }
  4023. InstBuilder &InstBuilder::opBitFieldUExtract(uint32_t result_type,
  4024. uint32_t result_id, uint32_t base,
  4025. uint32_t offset, uint32_t count) {
  4026. if (!TheInst.empty()) {
  4027. TheStatus = Status::NestedInst;
  4028. return *this;
  4029. }
  4030. if (result_type == 0) {
  4031. TheStatus = Status::ZeroResultType;
  4032. return *this;
  4033. }
  4034. if (result_id == 0) {
  4035. TheStatus = Status::ZeroResultId;
  4036. return *this;
  4037. }
  4038. TheInst.reserve(6);
  4039. TheInst.emplace_back(static_cast<uint32_t>(spv::Op::OpBitFieldUExtract));
  4040. TheInst.emplace_back(result_type);
  4041. TheInst.emplace_back(result_id);
  4042. TheInst.emplace_back(base);
  4043. TheInst.emplace_back(offset);
  4044. TheInst.emplace_back(count);
  4045. return *this;
  4046. }
  4047. InstBuilder &InstBuilder::opBitReverse(uint32_t result_type, uint32_t result_id,
  4048. uint32_t base) {
  4049. if (!TheInst.empty()) {
  4050. TheStatus = Status::NestedInst;
  4051. return *this;
  4052. }
  4053. if (result_type == 0) {
  4054. TheStatus = Status::ZeroResultType;
  4055. return *this;
  4056. }
  4057. if (result_id == 0) {
  4058. TheStatus = Status::ZeroResultId;
  4059. return *this;
  4060. }
  4061. TheInst.reserve(4);
  4062. TheInst.emplace_back(static_cast<uint32_t>(spv::Op::OpBitReverse));
  4063. TheInst.emplace_back(result_type);
  4064. TheInst.emplace_back(result_id);
  4065. TheInst.emplace_back(base);
  4066. return *this;
  4067. }
  4068. InstBuilder &InstBuilder::opBitCount(uint32_t result_type, uint32_t result_id,
  4069. uint32_t base) {
  4070. if (!TheInst.empty()) {
  4071. TheStatus = Status::NestedInst;
  4072. return *this;
  4073. }
  4074. if (result_type == 0) {
  4075. TheStatus = Status::ZeroResultType;
  4076. return *this;
  4077. }
  4078. if (result_id == 0) {
  4079. TheStatus = Status::ZeroResultId;
  4080. return *this;
  4081. }
  4082. TheInst.reserve(4);
  4083. TheInst.emplace_back(static_cast<uint32_t>(spv::Op::OpBitCount));
  4084. TheInst.emplace_back(result_type);
  4085. TheInst.emplace_back(result_id);
  4086. TheInst.emplace_back(base);
  4087. return *this;
  4088. }
  4089. InstBuilder &InstBuilder::opDPdx(uint32_t result_type, uint32_t result_id,
  4090. uint32_t p) {
  4091. if (!TheInst.empty()) {
  4092. TheStatus = Status::NestedInst;
  4093. return *this;
  4094. }
  4095. if (result_type == 0) {
  4096. TheStatus = Status::ZeroResultType;
  4097. return *this;
  4098. }
  4099. if (result_id == 0) {
  4100. TheStatus = Status::ZeroResultId;
  4101. return *this;
  4102. }
  4103. TheInst.reserve(4);
  4104. TheInst.emplace_back(static_cast<uint32_t>(spv::Op::OpDPdx));
  4105. TheInst.emplace_back(result_type);
  4106. TheInst.emplace_back(result_id);
  4107. TheInst.emplace_back(p);
  4108. return *this;
  4109. }
  4110. InstBuilder &InstBuilder::opDPdy(uint32_t result_type, uint32_t result_id,
  4111. uint32_t p) {
  4112. if (!TheInst.empty()) {
  4113. TheStatus = Status::NestedInst;
  4114. return *this;
  4115. }
  4116. if (result_type == 0) {
  4117. TheStatus = Status::ZeroResultType;
  4118. return *this;
  4119. }
  4120. if (result_id == 0) {
  4121. TheStatus = Status::ZeroResultId;
  4122. return *this;
  4123. }
  4124. TheInst.reserve(4);
  4125. TheInst.emplace_back(static_cast<uint32_t>(spv::Op::OpDPdy));
  4126. TheInst.emplace_back(result_type);
  4127. TheInst.emplace_back(result_id);
  4128. TheInst.emplace_back(p);
  4129. return *this;
  4130. }
  4131. InstBuilder &InstBuilder::opFwidth(uint32_t result_type, uint32_t result_id,
  4132. uint32_t p) {
  4133. if (!TheInst.empty()) {
  4134. TheStatus = Status::NestedInst;
  4135. return *this;
  4136. }
  4137. if (result_type == 0) {
  4138. TheStatus = Status::ZeroResultType;
  4139. return *this;
  4140. }
  4141. if (result_id == 0) {
  4142. TheStatus = Status::ZeroResultId;
  4143. return *this;
  4144. }
  4145. TheInst.reserve(4);
  4146. TheInst.emplace_back(static_cast<uint32_t>(spv::Op::OpFwidth));
  4147. TheInst.emplace_back(result_type);
  4148. TheInst.emplace_back(result_id);
  4149. TheInst.emplace_back(p);
  4150. return *this;
  4151. }
  4152. InstBuilder &InstBuilder::opDPdxFine(uint32_t result_type, uint32_t result_id,
  4153. uint32_t p) {
  4154. if (!TheInst.empty()) {
  4155. TheStatus = Status::NestedInst;
  4156. return *this;
  4157. }
  4158. if (result_type == 0) {
  4159. TheStatus = Status::ZeroResultType;
  4160. return *this;
  4161. }
  4162. if (result_id == 0) {
  4163. TheStatus = Status::ZeroResultId;
  4164. return *this;
  4165. }
  4166. TheInst.reserve(4);
  4167. TheInst.emplace_back(static_cast<uint32_t>(spv::Op::OpDPdxFine));
  4168. TheInst.emplace_back(result_type);
  4169. TheInst.emplace_back(result_id);
  4170. TheInst.emplace_back(p);
  4171. return *this;
  4172. }
  4173. InstBuilder &InstBuilder::opDPdyFine(uint32_t result_type, uint32_t result_id,
  4174. uint32_t p) {
  4175. if (!TheInst.empty()) {
  4176. TheStatus = Status::NestedInst;
  4177. return *this;
  4178. }
  4179. if (result_type == 0) {
  4180. TheStatus = Status::ZeroResultType;
  4181. return *this;
  4182. }
  4183. if (result_id == 0) {
  4184. TheStatus = Status::ZeroResultId;
  4185. return *this;
  4186. }
  4187. TheInst.reserve(4);
  4188. TheInst.emplace_back(static_cast<uint32_t>(spv::Op::OpDPdyFine));
  4189. TheInst.emplace_back(result_type);
  4190. TheInst.emplace_back(result_id);
  4191. TheInst.emplace_back(p);
  4192. return *this;
  4193. }
  4194. InstBuilder &InstBuilder::opFwidthFine(uint32_t result_type, uint32_t result_id,
  4195. uint32_t p) {
  4196. if (!TheInst.empty()) {
  4197. TheStatus = Status::NestedInst;
  4198. return *this;
  4199. }
  4200. if (result_type == 0) {
  4201. TheStatus = Status::ZeroResultType;
  4202. return *this;
  4203. }
  4204. if (result_id == 0) {
  4205. TheStatus = Status::ZeroResultId;
  4206. return *this;
  4207. }
  4208. TheInst.reserve(4);
  4209. TheInst.emplace_back(static_cast<uint32_t>(spv::Op::OpFwidthFine));
  4210. TheInst.emplace_back(result_type);
  4211. TheInst.emplace_back(result_id);
  4212. TheInst.emplace_back(p);
  4213. return *this;
  4214. }
  4215. InstBuilder &InstBuilder::opDPdxCoarse(uint32_t result_type, uint32_t result_id,
  4216. uint32_t p) {
  4217. if (!TheInst.empty()) {
  4218. TheStatus = Status::NestedInst;
  4219. return *this;
  4220. }
  4221. if (result_type == 0) {
  4222. TheStatus = Status::ZeroResultType;
  4223. return *this;
  4224. }
  4225. if (result_id == 0) {
  4226. TheStatus = Status::ZeroResultId;
  4227. return *this;
  4228. }
  4229. TheInst.reserve(4);
  4230. TheInst.emplace_back(static_cast<uint32_t>(spv::Op::OpDPdxCoarse));
  4231. TheInst.emplace_back(result_type);
  4232. TheInst.emplace_back(result_id);
  4233. TheInst.emplace_back(p);
  4234. return *this;
  4235. }
  4236. InstBuilder &InstBuilder::opDPdyCoarse(uint32_t result_type, uint32_t result_id,
  4237. uint32_t p) {
  4238. if (!TheInst.empty()) {
  4239. TheStatus = Status::NestedInst;
  4240. return *this;
  4241. }
  4242. if (result_type == 0) {
  4243. TheStatus = Status::ZeroResultType;
  4244. return *this;
  4245. }
  4246. if (result_id == 0) {
  4247. TheStatus = Status::ZeroResultId;
  4248. return *this;
  4249. }
  4250. TheInst.reserve(4);
  4251. TheInst.emplace_back(static_cast<uint32_t>(spv::Op::OpDPdyCoarse));
  4252. TheInst.emplace_back(result_type);
  4253. TheInst.emplace_back(result_id);
  4254. TheInst.emplace_back(p);
  4255. return *this;
  4256. }
  4257. InstBuilder &InstBuilder::opFwidthCoarse(uint32_t result_type,
  4258. uint32_t result_id, uint32_t p) {
  4259. if (!TheInst.empty()) {
  4260. TheStatus = Status::NestedInst;
  4261. return *this;
  4262. }
  4263. if (result_type == 0) {
  4264. TheStatus = Status::ZeroResultType;
  4265. return *this;
  4266. }
  4267. if (result_id == 0) {
  4268. TheStatus = Status::ZeroResultId;
  4269. return *this;
  4270. }
  4271. TheInst.reserve(4);
  4272. TheInst.emplace_back(static_cast<uint32_t>(spv::Op::OpFwidthCoarse));
  4273. TheInst.emplace_back(result_type);
  4274. TheInst.emplace_back(result_id);
  4275. TheInst.emplace_back(p);
  4276. return *this;
  4277. }
  4278. InstBuilder &InstBuilder::opEmitVertex() {
  4279. if (!TheInst.empty()) {
  4280. TheStatus = Status::NestedInst;
  4281. return *this;
  4282. }
  4283. TheInst.reserve(1);
  4284. TheInst.emplace_back(static_cast<uint32_t>(spv::Op::OpEmitVertex));
  4285. return *this;
  4286. }
  4287. InstBuilder &InstBuilder::opEndPrimitive() {
  4288. if (!TheInst.empty()) {
  4289. TheStatus = Status::NestedInst;
  4290. return *this;
  4291. }
  4292. TheInst.reserve(1);
  4293. TheInst.emplace_back(static_cast<uint32_t>(spv::Op::OpEndPrimitive));
  4294. return *this;
  4295. }
  4296. InstBuilder &InstBuilder::opEmitStreamVertex(uint32_t stream) {
  4297. if (!TheInst.empty()) {
  4298. TheStatus = Status::NestedInst;
  4299. return *this;
  4300. }
  4301. TheInst.reserve(2);
  4302. TheInst.emplace_back(static_cast<uint32_t>(spv::Op::OpEmitStreamVertex));
  4303. TheInst.emplace_back(stream);
  4304. return *this;
  4305. }
  4306. InstBuilder &InstBuilder::opEndStreamPrimitive(uint32_t stream) {
  4307. if (!TheInst.empty()) {
  4308. TheStatus = Status::NestedInst;
  4309. return *this;
  4310. }
  4311. TheInst.reserve(2);
  4312. TheInst.emplace_back(static_cast<uint32_t>(spv::Op::OpEndStreamPrimitive));
  4313. TheInst.emplace_back(stream);
  4314. return *this;
  4315. }
  4316. InstBuilder &InstBuilder::opControlBarrier(uint32_t execution, uint32_t memory,
  4317. uint32_t semantics) {
  4318. if (!TheInst.empty()) {
  4319. TheStatus = Status::NestedInst;
  4320. return *this;
  4321. }
  4322. TheInst.reserve(4);
  4323. TheInst.emplace_back(static_cast<uint32_t>(spv::Op::OpControlBarrier));
  4324. TheInst.emplace_back(execution);
  4325. TheInst.emplace_back(memory);
  4326. TheInst.emplace_back(semantics);
  4327. return *this;
  4328. }
  4329. InstBuilder &InstBuilder::opMemoryBarrier(uint32_t memory, uint32_t semantics) {
  4330. if (!TheInst.empty()) {
  4331. TheStatus = Status::NestedInst;
  4332. return *this;
  4333. }
  4334. TheInst.reserve(3);
  4335. TheInst.emplace_back(static_cast<uint32_t>(spv::Op::OpMemoryBarrier));
  4336. TheInst.emplace_back(memory);
  4337. TheInst.emplace_back(semantics);
  4338. return *this;
  4339. }
  4340. InstBuilder &InstBuilder::opAtomicLoad(uint32_t result_type, uint32_t result_id,
  4341. uint32_t pointer, uint32_t scope,
  4342. uint32_t semantics) {
  4343. if (!TheInst.empty()) {
  4344. TheStatus = Status::NestedInst;
  4345. return *this;
  4346. }
  4347. if (result_type == 0) {
  4348. TheStatus = Status::ZeroResultType;
  4349. return *this;
  4350. }
  4351. if (result_id == 0) {
  4352. TheStatus = Status::ZeroResultId;
  4353. return *this;
  4354. }
  4355. TheInst.reserve(6);
  4356. TheInst.emplace_back(static_cast<uint32_t>(spv::Op::OpAtomicLoad));
  4357. TheInst.emplace_back(result_type);
  4358. TheInst.emplace_back(result_id);
  4359. TheInst.emplace_back(pointer);
  4360. TheInst.emplace_back(scope);
  4361. TheInst.emplace_back(semantics);
  4362. return *this;
  4363. }
  4364. InstBuilder &InstBuilder::opAtomicStore(uint32_t pointer, uint32_t scope,
  4365. uint32_t semantics, uint32_t value) {
  4366. if (!TheInst.empty()) {
  4367. TheStatus = Status::NestedInst;
  4368. return *this;
  4369. }
  4370. TheInst.reserve(5);
  4371. TheInst.emplace_back(static_cast<uint32_t>(spv::Op::OpAtomicStore));
  4372. TheInst.emplace_back(pointer);
  4373. TheInst.emplace_back(scope);
  4374. TheInst.emplace_back(semantics);
  4375. TheInst.emplace_back(value);
  4376. return *this;
  4377. }
  4378. InstBuilder &InstBuilder::opAtomicExchange(uint32_t result_type,
  4379. uint32_t result_id, uint32_t pointer,
  4380. uint32_t scope, uint32_t semantics,
  4381. uint32_t value) {
  4382. if (!TheInst.empty()) {
  4383. TheStatus = Status::NestedInst;
  4384. return *this;
  4385. }
  4386. if (result_type == 0) {
  4387. TheStatus = Status::ZeroResultType;
  4388. return *this;
  4389. }
  4390. if (result_id == 0) {
  4391. TheStatus = Status::ZeroResultId;
  4392. return *this;
  4393. }
  4394. TheInst.reserve(7);
  4395. TheInst.emplace_back(static_cast<uint32_t>(spv::Op::OpAtomicExchange));
  4396. TheInst.emplace_back(result_type);
  4397. TheInst.emplace_back(result_id);
  4398. TheInst.emplace_back(pointer);
  4399. TheInst.emplace_back(scope);
  4400. TheInst.emplace_back(semantics);
  4401. TheInst.emplace_back(value);
  4402. return *this;
  4403. }
  4404. InstBuilder &InstBuilder::opAtomicCompareExchange(
  4405. uint32_t result_type, uint32_t result_id, uint32_t pointer, uint32_t scope,
  4406. uint32_t equal, uint32_t unequal, uint32_t value, uint32_t comparator) {
  4407. if (!TheInst.empty()) {
  4408. TheStatus = Status::NestedInst;
  4409. return *this;
  4410. }
  4411. if (result_type == 0) {
  4412. TheStatus = Status::ZeroResultType;
  4413. return *this;
  4414. }
  4415. if (result_id == 0) {
  4416. TheStatus = Status::ZeroResultId;
  4417. return *this;
  4418. }
  4419. TheInst.reserve(9);
  4420. TheInst.emplace_back(static_cast<uint32_t>(spv::Op::OpAtomicCompareExchange));
  4421. TheInst.emplace_back(result_type);
  4422. TheInst.emplace_back(result_id);
  4423. TheInst.emplace_back(pointer);
  4424. TheInst.emplace_back(scope);
  4425. TheInst.emplace_back(equal);
  4426. TheInst.emplace_back(unequal);
  4427. TheInst.emplace_back(value);
  4428. TheInst.emplace_back(comparator);
  4429. return *this;
  4430. }
  4431. InstBuilder &InstBuilder::opAtomicCompareExchangeWeak(
  4432. uint32_t result_type, uint32_t result_id, uint32_t pointer, uint32_t scope,
  4433. uint32_t equal, uint32_t unequal, uint32_t value, uint32_t comparator) {
  4434. if (!TheInst.empty()) {
  4435. TheStatus = Status::NestedInst;
  4436. return *this;
  4437. }
  4438. if (result_type == 0) {
  4439. TheStatus = Status::ZeroResultType;
  4440. return *this;
  4441. }
  4442. if (result_id == 0) {
  4443. TheStatus = Status::ZeroResultId;
  4444. return *this;
  4445. }
  4446. TheInst.reserve(9);
  4447. TheInst.emplace_back(
  4448. static_cast<uint32_t>(spv::Op::OpAtomicCompareExchangeWeak));
  4449. TheInst.emplace_back(result_type);
  4450. TheInst.emplace_back(result_id);
  4451. TheInst.emplace_back(pointer);
  4452. TheInst.emplace_back(scope);
  4453. TheInst.emplace_back(equal);
  4454. TheInst.emplace_back(unequal);
  4455. TheInst.emplace_back(value);
  4456. TheInst.emplace_back(comparator);
  4457. return *this;
  4458. }
  4459. InstBuilder &InstBuilder::opAtomicIIncrement(uint32_t result_type,
  4460. uint32_t result_id,
  4461. uint32_t pointer, uint32_t scope,
  4462. uint32_t semantics) {
  4463. if (!TheInst.empty()) {
  4464. TheStatus = Status::NestedInst;
  4465. return *this;
  4466. }
  4467. if (result_type == 0) {
  4468. TheStatus = Status::ZeroResultType;
  4469. return *this;
  4470. }
  4471. if (result_id == 0) {
  4472. TheStatus = Status::ZeroResultId;
  4473. return *this;
  4474. }
  4475. TheInst.reserve(6);
  4476. TheInst.emplace_back(static_cast<uint32_t>(spv::Op::OpAtomicIIncrement));
  4477. TheInst.emplace_back(result_type);
  4478. TheInst.emplace_back(result_id);
  4479. TheInst.emplace_back(pointer);
  4480. TheInst.emplace_back(scope);
  4481. TheInst.emplace_back(semantics);
  4482. return *this;
  4483. }
  4484. InstBuilder &InstBuilder::opAtomicIDecrement(uint32_t result_type,
  4485. uint32_t result_id,
  4486. uint32_t pointer, uint32_t scope,
  4487. uint32_t semantics) {
  4488. if (!TheInst.empty()) {
  4489. TheStatus = Status::NestedInst;
  4490. return *this;
  4491. }
  4492. if (result_type == 0) {
  4493. TheStatus = Status::ZeroResultType;
  4494. return *this;
  4495. }
  4496. if (result_id == 0) {
  4497. TheStatus = Status::ZeroResultId;
  4498. return *this;
  4499. }
  4500. TheInst.reserve(6);
  4501. TheInst.emplace_back(static_cast<uint32_t>(spv::Op::OpAtomicIDecrement));
  4502. TheInst.emplace_back(result_type);
  4503. TheInst.emplace_back(result_id);
  4504. TheInst.emplace_back(pointer);
  4505. TheInst.emplace_back(scope);
  4506. TheInst.emplace_back(semantics);
  4507. return *this;
  4508. }
  4509. InstBuilder &InstBuilder::opAtomicIAdd(uint32_t result_type, uint32_t result_id,
  4510. uint32_t pointer, uint32_t scope,
  4511. uint32_t semantics, uint32_t value) {
  4512. if (!TheInst.empty()) {
  4513. TheStatus = Status::NestedInst;
  4514. return *this;
  4515. }
  4516. if (result_type == 0) {
  4517. TheStatus = Status::ZeroResultType;
  4518. return *this;
  4519. }
  4520. if (result_id == 0) {
  4521. TheStatus = Status::ZeroResultId;
  4522. return *this;
  4523. }
  4524. TheInst.reserve(7);
  4525. TheInst.emplace_back(static_cast<uint32_t>(spv::Op::OpAtomicIAdd));
  4526. TheInst.emplace_back(result_type);
  4527. TheInst.emplace_back(result_id);
  4528. TheInst.emplace_back(pointer);
  4529. TheInst.emplace_back(scope);
  4530. TheInst.emplace_back(semantics);
  4531. TheInst.emplace_back(value);
  4532. return *this;
  4533. }
  4534. InstBuilder &InstBuilder::opAtomicISub(uint32_t result_type, uint32_t result_id,
  4535. uint32_t pointer, uint32_t scope,
  4536. uint32_t semantics, uint32_t value) {
  4537. if (!TheInst.empty()) {
  4538. TheStatus = Status::NestedInst;
  4539. return *this;
  4540. }
  4541. if (result_type == 0) {
  4542. TheStatus = Status::ZeroResultType;
  4543. return *this;
  4544. }
  4545. if (result_id == 0) {
  4546. TheStatus = Status::ZeroResultId;
  4547. return *this;
  4548. }
  4549. TheInst.reserve(7);
  4550. TheInst.emplace_back(static_cast<uint32_t>(spv::Op::OpAtomicISub));
  4551. TheInst.emplace_back(result_type);
  4552. TheInst.emplace_back(result_id);
  4553. TheInst.emplace_back(pointer);
  4554. TheInst.emplace_back(scope);
  4555. TheInst.emplace_back(semantics);
  4556. TheInst.emplace_back(value);
  4557. return *this;
  4558. }
  4559. InstBuilder &InstBuilder::opAtomicSMin(uint32_t result_type, uint32_t result_id,
  4560. uint32_t pointer, uint32_t scope,
  4561. uint32_t semantics, uint32_t value) {
  4562. if (!TheInst.empty()) {
  4563. TheStatus = Status::NestedInst;
  4564. return *this;
  4565. }
  4566. if (result_type == 0) {
  4567. TheStatus = Status::ZeroResultType;
  4568. return *this;
  4569. }
  4570. if (result_id == 0) {
  4571. TheStatus = Status::ZeroResultId;
  4572. return *this;
  4573. }
  4574. TheInst.reserve(7);
  4575. TheInst.emplace_back(static_cast<uint32_t>(spv::Op::OpAtomicSMin));
  4576. TheInst.emplace_back(result_type);
  4577. TheInst.emplace_back(result_id);
  4578. TheInst.emplace_back(pointer);
  4579. TheInst.emplace_back(scope);
  4580. TheInst.emplace_back(semantics);
  4581. TheInst.emplace_back(value);
  4582. return *this;
  4583. }
  4584. InstBuilder &InstBuilder::opAtomicUMin(uint32_t result_type, uint32_t result_id,
  4585. uint32_t pointer, uint32_t scope,
  4586. uint32_t semantics, uint32_t value) {
  4587. if (!TheInst.empty()) {
  4588. TheStatus = Status::NestedInst;
  4589. return *this;
  4590. }
  4591. if (result_type == 0) {
  4592. TheStatus = Status::ZeroResultType;
  4593. return *this;
  4594. }
  4595. if (result_id == 0) {
  4596. TheStatus = Status::ZeroResultId;
  4597. return *this;
  4598. }
  4599. TheInst.reserve(7);
  4600. TheInst.emplace_back(static_cast<uint32_t>(spv::Op::OpAtomicUMin));
  4601. TheInst.emplace_back(result_type);
  4602. TheInst.emplace_back(result_id);
  4603. TheInst.emplace_back(pointer);
  4604. TheInst.emplace_back(scope);
  4605. TheInst.emplace_back(semantics);
  4606. TheInst.emplace_back(value);
  4607. return *this;
  4608. }
  4609. InstBuilder &InstBuilder::opAtomicSMax(uint32_t result_type, uint32_t result_id,
  4610. uint32_t pointer, uint32_t scope,
  4611. uint32_t semantics, uint32_t value) {
  4612. if (!TheInst.empty()) {
  4613. TheStatus = Status::NestedInst;
  4614. return *this;
  4615. }
  4616. if (result_type == 0) {
  4617. TheStatus = Status::ZeroResultType;
  4618. return *this;
  4619. }
  4620. if (result_id == 0) {
  4621. TheStatus = Status::ZeroResultId;
  4622. return *this;
  4623. }
  4624. TheInst.reserve(7);
  4625. TheInst.emplace_back(static_cast<uint32_t>(spv::Op::OpAtomicSMax));
  4626. TheInst.emplace_back(result_type);
  4627. TheInst.emplace_back(result_id);
  4628. TheInst.emplace_back(pointer);
  4629. TheInst.emplace_back(scope);
  4630. TheInst.emplace_back(semantics);
  4631. TheInst.emplace_back(value);
  4632. return *this;
  4633. }
  4634. InstBuilder &InstBuilder::opAtomicUMax(uint32_t result_type, uint32_t result_id,
  4635. uint32_t pointer, uint32_t scope,
  4636. uint32_t semantics, uint32_t value) {
  4637. if (!TheInst.empty()) {
  4638. TheStatus = Status::NestedInst;
  4639. return *this;
  4640. }
  4641. if (result_type == 0) {
  4642. TheStatus = Status::ZeroResultType;
  4643. return *this;
  4644. }
  4645. if (result_id == 0) {
  4646. TheStatus = Status::ZeroResultId;
  4647. return *this;
  4648. }
  4649. TheInst.reserve(7);
  4650. TheInst.emplace_back(static_cast<uint32_t>(spv::Op::OpAtomicUMax));
  4651. TheInst.emplace_back(result_type);
  4652. TheInst.emplace_back(result_id);
  4653. TheInst.emplace_back(pointer);
  4654. TheInst.emplace_back(scope);
  4655. TheInst.emplace_back(semantics);
  4656. TheInst.emplace_back(value);
  4657. return *this;
  4658. }
  4659. InstBuilder &InstBuilder::opAtomicAnd(uint32_t result_type, uint32_t result_id,
  4660. uint32_t pointer, uint32_t scope,
  4661. uint32_t semantics, uint32_t value) {
  4662. if (!TheInst.empty()) {
  4663. TheStatus = Status::NestedInst;
  4664. return *this;
  4665. }
  4666. if (result_type == 0) {
  4667. TheStatus = Status::ZeroResultType;
  4668. return *this;
  4669. }
  4670. if (result_id == 0) {
  4671. TheStatus = Status::ZeroResultId;
  4672. return *this;
  4673. }
  4674. TheInst.reserve(7);
  4675. TheInst.emplace_back(static_cast<uint32_t>(spv::Op::OpAtomicAnd));
  4676. TheInst.emplace_back(result_type);
  4677. TheInst.emplace_back(result_id);
  4678. TheInst.emplace_back(pointer);
  4679. TheInst.emplace_back(scope);
  4680. TheInst.emplace_back(semantics);
  4681. TheInst.emplace_back(value);
  4682. return *this;
  4683. }
  4684. InstBuilder &InstBuilder::opAtomicOr(uint32_t result_type, uint32_t result_id,
  4685. uint32_t pointer, uint32_t scope,
  4686. uint32_t semantics, uint32_t value) {
  4687. if (!TheInst.empty()) {
  4688. TheStatus = Status::NestedInst;
  4689. return *this;
  4690. }
  4691. if (result_type == 0) {
  4692. TheStatus = Status::ZeroResultType;
  4693. return *this;
  4694. }
  4695. if (result_id == 0) {
  4696. TheStatus = Status::ZeroResultId;
  4697. return *this;
  4698. }
  4699. TheInst.reserve(7);
  4700. TheInst.emplace_back(static_cast<uint32_t>(spv::Op::OpAtomicOr));
  4701. TheInst.emplace_back(result_type);
  4702. TheInst.emplace_back(result_id);
  4703. TheInst.emplace_back(pointer);
  4704. TheInst.emplace_back(scope);
  4705. TheInst.emplace_back(semantics);
  4706. TheInst.emplace_back(value);
  4707. return *this;
  4708. }
  4709. InstBuilder &InstBuilder::opAtomicXor(uint32_t result_type, uint32_t result_id,
  4710. uint32_t pointer, uint32_t scope,
  4711. uint32_t semantics, uint32_t value) {
  4712. if (!TheInst.empty()) {
  4713. TheStatus = Status::NestedInst;
  4714. return *this;
  4715. }
  4716. if (result_type == 0) {
  4717. TheStatus = Status::ZeroResultType;
  4718. return *this;
  4719. }
  4720. if (result_id == 0) {
  4721. TheStatus = Status::ZeroResultId;
  4722. return *this;
  4723. }
  4724. TheInst.reserve(7);
  4725. TheInst.emplace_back(static_cast<uint32_t>(spv::Op::OpAtomicXor));
  4726. TheInst.emplace_back(result_type);
  4727. TheInst.emplace_back(result_id);
  4728. TheInst.emplace_back(pointer);
  4729. TheInst.emplace_back(scope);
  4730. TheInst.emplace_back(semantics);
  4731. TheInst.emplace_back(value);
  4732. return *this;
  4733. }
  4734. InstBuilder &InstBuilder::opPhi(
  4735. uint32_t result_type, uint32_t result_id,
  4736. llvm::ArrayRef<std::pair<uint32_t, uint32_t>> variable_parent_) {
  4737. if (!TheInst.empty()) {
  4738. TheStatus = Status::NestedInst;
  4739. return *this;
  4740. }
  4741. if (result_type == 0) {
  4742. TheStatus = Status::ZeroResultType;
  4743. return *this;
  4744. }
  4745. if (result_id == 0) {
  4746. TheStatus = Status::ZeroResultId;
  4747. return *this;
  4748. }
  4749. TheInst.reserve(4);
  4750. TheInst.emplace_back(static_cast<uint32_t>(spv::Op::OpPhi));
  4751. TheInst.emplace_back(result_type);
  4752. TheInst.emplace_back(result_id);
  4753. for (const auto &param : variable_parent_) {
  4754. TheInst.emplace_back(param.first);
  4755. TheInst.emplace_back(param.second);
  4756. ;
  4757. }
  4758. return *this;
  4759. }
  4760. InstBuilder &InstBuilder::opLoopMerge(uint32_t merge_block,
  4761. uint32_t continue_target,
  4762. spv::LoopControlMask loop_control) {
  4763. if (!TheInst.empty()) {
  4764. TheStatus = Status::NestedInst;
  4765. return *this;
  4766. }
  4767. TheInst.reserve(4);
  4768. TheInst.emplace_back(static_cast<uint32_t>(spv::Op::OpLoopMerge));
  4769. TheInst.emplace_back(merge_block);
  4770. TheInst.emplace_back(continue_target);
  4771. encodeLoopControl(loop_control);
  4772. return *this;
  4773. }
  4774. InstBuilder &
  4775. InstBuilder::opSelectionMerge(uint32_t merge_block,
  4776. spv::SelectionControlMask selection_control) {
  4777. if (!TheInst.empty()) {
  4778. TheStatus = Status::NestedInst;
  4779. return *this;
  4780. }
  4781. TheInst.reserve(3);
  4782. TheInst.emplace_back(static_cast<uint32_t>(spv::Op::OpSelectionMerge));
  4783. TheInst.emplace_back(merge_block);
  4784. TheInst.emplace_back(static_cast<uint32_t>(selection_control));
  4785. return *this;
  4786. }
  4787. InstBuilder &InstBuilder::opLabel(uint32_t result_id) {
  4788. if (!TheInst.empty()) {
  4789. TheStatus = Status::NestedInst;
  4790. return *this;
  4791. }
  4792. if (result_id == 0) {
  4793. TheStatus = Status::ZeroResultId;
  4794. return *this;
  4795. }
  4796. TheInst.reserve(2);
  4797. TheInst.emplace_back(static_cast<uint32_t>(spv::Op::OpLabel));
  4798. TheInst.emplace_back(result_id);
  4799. return *this;
  4800. }
  4801. InstBuilder &InstBuilder::opBranch(uint32_t target_label) {
  4802. if (!TheInst.empty()) {
  4803. TheStatus = Status::NestedInst;
  4804. return *this;
  4805. }
  4806. TheInst.reserve(2);
  4807. TheInst.emplace_back(static_cast<uint32_t>(spv::Op::OpBranch));
  4808. TheInst.emplace_back(target_label);
  4809. return *this;
  4810. }
  4811. InstBuilder &
  4812. InstBuilder::opBranchConditional(uint32_t condition, uint32_t true_label,
  4813. uint32_t false_label,
  4814. llvm::ArrayRef<uint32_t> branch_weights) {
  4815. if (!TheInst.empty()) {
  4816. TheStatus = Status::NestedInst;
  4817. return *this;
  4818. }
  4819. TheInst.reserve(5);
  4820. TheInst.emplace_back(static_cast<uint32_t>(spv::Op::OpBranchConditional));
  4821. TheInst.emplace_back(condition);
  4822. TheInst.emplace_back(true_label);
  4823. TheInst.emplace_back(false_label);
  4824. for (const auto &param : branch_weights) {
  4825. TheInst.emplace_back(param);
  4826. ;
  4827. }
  4828. return *this;
  4829. }
  4830. InstBuilder &
  4831. InstBuilder::opSwitch(uint32_t selector, uint32_t default_target,
  4832. llvm::ArrayRef<std::pair<uint32_t, uint32_t>> target) {
  4833. if (!TheInst.empty()) {
  4834. TheStatus = Status::NestedInst;
  4835. return *this;
  4836. }
  4837. TheInst.reserve(4);
  4838. TheInst.emplace_back(static_cast<uint32_t>(spv::Op::OpSwitch));
  4839. TheInst.emplace_back(selector);
  4840. TheInst.emplace_back(default_target);
  4841. for (const auto &param : target) {
  4842. TheInst.emplace_back(param.first);
  4843. TheInst.emplace_back(param.second);
  4844. ;
  4845. }
  4846. return *this;
  4847. }
  4848. InstBuilder &InstBuilder::opKill() {
  4849. if (!TheInst.empty()) {
  4850. TheStatus = Status::NestedInst;
  4851. return *this;
  4852. }
  4853. TheInst.reserve(1);
  4854. TheInst.emplace_back(static_cast<uint32_t>(spv::Op::OpKill));
  4855. return *this;
  4856. }
  4857. InstBuilder &InstBuilder::opReturn() {
  4858. if (!TheInst.empty()) {
  4859. TheStatus = Status::NestedInst;
  4860. return *this;
  4861. }
  4862. TheInst.reserve(1);
  4863. TheInst.emplace_back(static_cast<uint32_t>(spv::Op::OpReturn));
  4864. return *this;
  4865. }
  4866. InstBuilder &InstBuilder::opReturnValue(uint32_t value) {
  4867. if (!TheInst.empty()) {
  4868. TheStatus = Status::NestedInst;
  4869. return *this;
  4870. }
  4871. TheInst.reserve(2);
  4872. TheInst.emplace_back(static_cast<uint32_t>(spv::Op::OpReturnValue));
  4873. TheInst.emplace_back(value);
  4874. return *this;
  4875. }
  4876. InstBuilder &InstBuilder::opUnreachable() {
  4877. if (!TheInst.empty()) {
  4878. TheStatus = Status::NestedInst;
  4879. return *this;
  4880. }
  4881. TheInst.reserve(1);
  4882. TheInst.emplace_back(static_cast<uint32_t>(spv::Op::OpUnreachable));
  4883. return *this;
  4884. }
  4885. InstBuilder &InstBuilder::opLifetimeStart(uint32_t pointer, uint32_t size) {
  4886. if (!TheInst.empty()) {
  4887. TheStatus = Status::NestedInst;
  4888. return *this;
  4889. }
  4890. TheInst.reserve(3);
  4891. TheInst.emplace_back(static_cast<uint32_t>(spv::Op::OpLifetimeStart));
  4892. TheInst.emplace_back(pointer);
  4893. TheInst.emplace_back(size);
  4894. return *this;
  4895. }
  4896. InstBuilder &InstBuilder::opLifetimeStop(uint32_t pointer, uint32_t size) {
  4897. if (!TheInst.empty()) {
  4898. TheStatus = Status::NestedInst;
  4899. return *this;
  4900. }
  4901. TheInst.reserve(3);
  4902. TheInst.emplace_back(static_cast<uint32_t>(spv::Op::OpLifetimeStop));
  4903. TheInst.emplace_back(pointer);
  4904. TheInst.emplace_back(size);
  4905. return *this;
  4906. }
  4907. InstBuilder &
  4908. InstBuilder::opGroupAsyncCopy(uint32_t result_type, uint32_t result_id,
  4909. uint32_t execution, uint32_t destination,
  4910. uint32_t source, uint32_t num_elements,
  4911. uint32_t stride, uint32_t event) {
  4912. if (!TheInst.empty()) {
  4913. TheStatus = Status::NestedInst;
  4914. return *this;
  4915. }
  4916. if (result_type == 0) {
  4917. TheStatus = Status::ZeroResultType;
  4918. return *this;
  4919. }
  4920. if (result_id == 0) {
  4921. TheStatus = Status::ZeroResultId;
  4922. return *this;
  4923. }
  4924. TheInst.reserve(9);
  4925. TheInst.emplace_back(static_cast<uint32_t>(spv::Op::OpGroupAsyncCopy));
  4926. TheInst.emplace_back(result_type);
  4927. TheInst.emplace_back(result_id);
  4928. TheInst.emplace_back(execution);
  4929. TheInst.emplace_back(destination);
  4930. TheInst.emplace_back(source);
  4931. TheInst.emplace_back(num_elements);
  4932. TheInst.emplace_back(stride);
  4933. TheInst.emplace_back(event);
  4934. return *this;
  4935. }
  4936. InstBuilder &InstBuilder::opGroupWaitEvents(uint32_t execution,
  4937. uint32_t num_events,
  4938. uint32_t events_list) {
  4939. if (!TheInst.empty()) {
  4940. TheStatus = Status::NestedInst;
  4941. return *this;
  4942. }
  4943. TheInst.reserve(4);
  4944. TheInst.emplace_back(static_cast<uint32_t>(spv::Op::OpGroupWaitEvents));
  4945. TheInst.emplace_back(execution);
  4946. TheInst.emplace_back(num_events);
  4947. TheInst.emplace_back(events_list);
  4948. return *this;
  4949. }
  4950. InstBuilder &InstBuilder::opGroupAll(uint32_t result_type, uint32_t result_id,
  4951. uint32_t execution, uint32_t predicate) {
  4952. if (!TheInst.empty()) {
  4953. TheStatus = Status::NestedInst;
  4954. return *this;
  4955. }
  4956. if (result_type == 0) {
  4957. TheStatus = Status::ZeroResultType;
  4958. return *this;
  4959. }
  4960. if (result_id == 0) {
  4961. TheStatus = Status::ZeroResultId;
  4962. return *this;
  4963. }
  4964. TheInst.reserve(5);
  4965. TheInst.emplace_back(static_cast<uint32_t>(spv::Op::OpGroupAll));
  4966. TheInst.emplace_back(result_type);
  4967. TheInst.emplace_back(result_id);
  4968. TheInst.emplace_back(execution);
  4969. TheInst.emplace_back(predicate);
  4970. return *this;
  4971. }
  4972. InstBuilder &InstBuilder::opGroupAny(uint32_t result_type, uint32_t result_id,
  4973. uint32_t execution, uint32_t predicate) {
  4974. if (!TheInst.empty()) {
  4975. TheStatus = Status::NestedInst;
  4976. return *this;
  4977. }
  4978. if (result_type == 0) {
  4979. TheStatus = Status::ZeroResultType;
  4980. return *this;
  4981. }
  4982. if (result_id == 0) {
  4983. TheStatus = Status::ZeroResultId;
  4984. return *this;
  4985. }
  4986. TheInst.reserve(5);
  4987. TheInst.emplace_back(static_cast<uint32_t>(spv::Op::OpGroupAny));
  4988. TheInst.emplace_back(result_type);
  4989. TheInst.emplace_back(result_id);
  4990. TheInst.emplace_back(execution);
  4991. TheInst.emplace_back(predicate);
  4992. return *this;
  4993. }
  4994. InstBuilder &InstBuilder::opGroupBroadcast(uint32_t result_type,
  4995. uint32_t result_id,
  4996. uint32_t execution, uint32_t value,
  4997. uint32_t local_id) {
  4998. if (!TheInst.empty()) {
  4999. TheStatus = Status::NestedInst;
  5000. return *this;
  5001. }
  5002. if (result_type == 0) {
  5003. TheStatus = Status::ZeroResultType;
  5004. return *this;
  5005. }
  5006. if (result_id == 0) {
  5007. TheStatus = Status::ZeroResultId;
  5008. return *this;
  5009. }
  5010. TheInst.reserve(6);
  5011. TheInst.emplace_back(static_cast<uint32_t>(spv::Op::OpGroupBroadcast));
  5012. TheInst.emplace_back(result_type);
  5013. TheInst.emplace_back(result_id);
  5014. TheInst.emplace_back(execution);
  5015. TheInst.emplace_back(value);
  5016. TheInst.emplace_back(local_id);
  5017. return *this;
  5018. }
  5019. InstBuilder &InstBuilder::opGroupIAdd(uint32_t result_type, uint32_t result_id,
  5020. uint32_t execution,
  5021. spv::GroupOperation operation,
  5022. uint32_t x) {
  5023. if (!TheInst.empty()) {
  5024. TheStatus = Status::NestedInst;
  5025. return *this;
  5026. }
  5027. if (result_type == 0) {
  5028. TheStatus = Status::ZeroResultType;
  5029. return *this;
  5030. }
  5031. if (result_id == 0) {
  5032. TheStatus = Status::ZeroResultId;
  5033. return *this;
  5034. }
  5035. TheInst.reserve(6);
  5036. TheInst.emplace_back(static_cast<uint32_t>(spv::Op::OpGroupIAdd));
  5037. TheInst.emplace_back(result_type);
  5038. TheInst.emplace_back(result_id);
  5039. TheInst.emplace_back(execution);
  5040. TheInst.emplace_back(static_cast<uint32_t>(operation));
  5041. TheInst.emplace_back(x);
  5042. return *this;
  5043. }
  5044. InstBuilder &InstBuilder::opGroupFAdd(uint32_t result_type, uint32_t result_id,
  5045. uint32_t execution,
  5046. spv::GroupOperation operation,
  5047. uint32_t x) {
  5048. if (!TheInst.empty()) {
  5049. TheStatus = Status::NestedInst;
  5050. return *this;
  5051. }
  5052. if (result_type == 0) {
  5053. TheStatus = Status::ZeroResultType;
  5054. return *this;
  5055. }
  5056. if (result_id == 0) {
  5057. TheStatus = Status::ZeroResultId;
  5058. return *this;
  5059. }
  5060. TheInst.reserve(6);
  5061. TheInst.emplace_back(static_cast<uint32_t>(spv::Op::OpGroupFAdd));
  5062. TheInst.emplace_back(result_type);
  5063. TheInst.emplace_back(result_id);
  5064. TheInst.emplace_back(execution);
  5065. TheInst.emplace_back(static_cast<uint32_t>(operation));
  5066. TheInst.emplace_back(x);
  5067. return *this;
  5068. }
  5069. InstBuilder &InstBuilder::opGroupFMin(uint32_t result_type, uint32_t result_id,
  5070. uint32_t execution,
  5071. spv::GroupOperation operation,
  5072. uint32_t x) {
  5073. if (!TheInst.empty()) {
  5074. TheStatus = Status::NestedInst;
  5075. return *this;
  5076. }
  5077. if (result_type == 0) {
  5078. TheStatus = Status::ZeroResultType;
  5079. return *this;
  5080. }
  5081. if (result_id == 0) {
  5082. TheStatus = Status::ZeroResultId;
  5083. return *this;
  5084. }
  5085. TheInst.reserve(6);
  5086. TheInst.emplace_back(static_cast<uint32_t>(spv::Op::OpGroupFMin));
  5087. TheInst.emplace_back(result_type);
  5088. TheInst.emplace_back(result_id);
  5089. TheInst.emplace_back(execution);
  5090. TheInst.emplace_back(static_cast<uint32_t>(operation));
  5091. TheInst.emplace_back(x);
  5092. return *this;
  5093. }
  5094. InstBuilder &InstBuilder::opGroupUMin(uint32_t result_type, uint32_t result_id,
  5095. uint32_t execution,
  5096. spv::GroupOperation operation,
  5097. uint32_t x) {
  5098. if (!TheInst.empty()) {
  5099. TheStatus = Status::NestedInst;
  5100. return *this;
  5101. }
  5102. if (result_type == 0) {
  5103. TheStatus = Status::ZeroResultType;
  5104. return *this;
  5105. }
  5106. if (result_id == 0) {
  5107. TheStatus = Status::ZeroResultId;
  5108. return *this;
  5109. }
  5110. TheInst.reserve(6);
  5111. TheInst.emplace_back(static_cast<uint32_t>(spv::Op::OpGroupUMin));
  5112. TheInst.emplace_back(result_type);
  5113. TheInst.emplace_back(result_id);
  5114. TheInst.emplace_back(execution);
  5115. TheInst.emplace_back(static_cast<uint32_t>(operation));
  5116. TheInst.emplace_back(x);
  5117. return *this;
  5118. }
  5119. InstBuilder &InstBuilder::opGroupSMin(uint32_t result_type, uint32_t result_id,
  5120. uint32_t execution,
  5121. spv::GroupOperation operation,
  5122. uint32_t x) {
  5123. if (!TheInst.empty()) {
  5124. TheStatus = Status::NestedInst;
  5125. return *this;
  5126. }
  5127. if (result_type == 0) {
  5128. TheStatus = Status::ZeroResultType;
  5129. return *this;
  5130. }
  5131. if (result_id == 0) {
  5132. TheStatus = Status::ZeroResultId;
  5133. return *this;
  5134. }
  5135. TheInst.reserve(6);
  5136. TheInst.emplace_back(static_cast<uint32_t>(spv::Op::OpGroupSMin));
  5137. TheInst.emplace_back(result_type);
  5138. TheInst.emplace_back(result_id);
  5139. TheInst.emplace_back(execution);
  5140. TheInst.emplace_back(static_cast<uint32_t>(operation));
  5141. TheInst.emplace_back(x);
  5142. return *this;
  5143. }
  5144. InstBuilder &InstBuilder::opGroupFMax(uint32_t result_type, uint32_t result_id,
  5145. uint32_t execution,
  5146. spv::GroupOperation operation,
  5147. uint32_t x) {
  5148. if (!TheInst.empty()) {
  5149. TheStatus = Status::NestedInst;
  5150. return *this;
  5151. }
  5152. if (result_type == 0) {
  5153. TheStatus = Status::ZeroResultType;
  5154. return *this;
  5155. }
  5156. if (result_id == 0) {
  5157. TheStatus = Status::ZeroResultId;
  5158. return *this;
  5159. }
  5160. TheInst.reserve(6);
  5161. TheInst.emplace_back(static_cast<uint32_t>(spv::Op::OpGroupFMax));
  5162. TheInst.emplace_back(result_type);
  5163. TheInst.emplace_back(result_id);
  5164. TheInst.emplace_back(execution);
  5165. TheInst.emplace_back(static_cast<uint32_t>(operation));
  5166. TheInst.emplace_back(x);
  5167. return *this;
  5168. }
  5169. InstBuilder &InstBuilder::opGroupUMax(uint32_t result_type, uint32_t result_id,
  5170. uint32_t execution,
  5171. spv::GroupOperation operation,
  5172. uint32_t x) {
  5173. if (!TheInst.empty()) {
  5174. TheStatus = Status::NestedInst;
  5175. return *this;
  5176. }
  5177. if (result_type == 0) {
  5178. TheStatus = Status::ZeroResultType;
  5179. return *this;
  5180. }
  5181. if (result_id == 0) {
  5182. TheStatus = Status::ZeroResultId;
  5183. return *this;
  5184. }
  5185. TheInst.reserve(6);
  5186. TheInst.emplace_back(static_cast<uint32_t>(spv::Op::OpGroupUMax));
  5187. TheInst.emplace_back(result_type);
  5188. TheInst.emplace_back(result_id);
  5189. TheInst.emplace_back(execution);
  5190. TheInst.emplace_back(static_cast<uint32_t>(operation));
  5191. TheInst.emplace_back(x);
  5192. return *this;
  5193. }
  5194. InstBuilder &InstBuilder::opGroupSMax(uint32_t result_type, uint32_t result_id,
  5195. uint32_t execution,
  5196. spv::GroupOperation operation,
  5197. uint32_t x) {
  5198. if (!TheInst.empty()) {
  5199. TheStatus = Status::NestedInst;
  5200. return *this;
  5201. }
  5202. if (result_type == 0) {
  5203. TheStatus = Status::ZeroResultType;
  5204. return *this;
  5205. }
  5206. if (result_id == 0) {
  5207. TheStatus = Status::ZeroResultId;
  5208. return *this;
  5209. }
  5210. TheInst.reserve(6);
  5211. TheInst.emplace_back(static_cast<uint32_t>(spv::Op::OpGroupSMax));
  5212. TheInst.emplace_back(result_type);
  5213. TheInst.emplace_back(result_id);
  5214. TheInst.emplace_back(execution);
  5215. TheInst.emplace_back(static_cast<uint32_t>(operation));
  5216. TheInst.emplace_back(x);
  5217. return *this;
  5218. }
  5219. InstBuilder &InstBuilder::opReadPipe(uint32_t result_type, uint32_t result_id,
  5220. uint32_t pipe, uint32_t pointer,
  5221. uint32_t packet_size,
  5222. uint32_t packet_alignment) {
  5223. if (!TheInst.empty()) {
  5224. TheStatus = Status::NestedInst;
  5225. return *this;
  5226. }
  5227. if (result_type == 0) {
  5228. TheStatus = Status::ZeroResultType;
  5229. return *this;
  5230. }
  5231. if (result_id == 0) {
  5232. TheStatus = Status::ZeroResultId;
  5233. return *this;
  5234. }
  5235. TheInst.reserve(7);
  5236. TheInst.emplace_back(static_cast<uint32_t>(spv::Op::OpReadPipe));
  5237. TheInst.emplace_back(result_type);
  5238. TheInst.emplace_back(result_id);
  5239. TheInst.emplace_back(pipe);
  5240. TheInst.emplace_back(pointer);
  5241. TheInst.emplace_back(packet_size);
  5242. TheInst.emplace_back(packet_alignment);
  5243. return *this;
  5244. }
  5245. InstBuilder &InstBuilder::opWritePipe(uint32_t result_type, uint32_t result_id,
  5246. uint32_t pipe, uint32_t pointer,
  5247. uint32_t packet_size,
  5248. uint32_t packet_alignment) {
  5249. if (!TheInst.empty()) {
  5250. TheStatus = Status::NestedInst;
  5251. return *this;
  5252. }
  5253. if (result_type == 0) {
  5254. TheStatus = Status::ZeroResultType;
  5255. return *this;
  5256. }
  5257. if (result_id == 0) {
  5258. TheStatus = Status::ZeroResultId;
  5259. return *this;
  5260. }
  5261. TheInst.reserve(7);
  5262. TheInst.emplace_back(static_cast<uint32_t>(spv::Op::OpWritePipe));
  5263. TheInst.emplace_back(result_type);
  5264. TheInst.emplace_back(result_id);
  5265. TheInst.emplace_back(pipe);
  5266. TheInst.emplace_back(pointer);
  5267. TheInst.emplace_back(packet_size);
  5268. TheInst.emplace_back(packet_alignment);
  5269. return *this;
  5270. }
  5271. InstBuilder &InstBuilder::opReservedReadPipe(uint32_t result_type,
  5272. uint32_t result_id, uint32_t pipe,
  5273. uint32_t reserve_id,
  5274. uint32_t index, uint32_t pointer,
  5275. uint32_t packet_size,
  5276. uint32_t packet_alignment) {
  5277. if (!TheInst.empty()) {
  5278. TheStatus = Status::NestedInst;
  5279. return *this;
  5280. }
  5281. if (result_type == 0) {
  5282. TheStatus = Status::ZeroResultType;
  5283. return *this;
  5284. }
  5285. if (result_id == 0) {
  5286. TheStatus = Status::ZeroResultId;
  5287. return *this;
  5288. }
  5289. TheInst.reserve(9);
  5290. TheInst.emplace_back(static_cast<uint32_t>(spv::Op::OpReservedReadPipe));
  5291. TheInst.emplace_back(result_type);
  5292. TheInst.emplace_back(result_id);
  5293. TheInst.emplace_back(pipe);
  5294. TheInst.emplace_back(reserve_id);
  5295. TheInst.emplace_back(index);
  5296. TheInst.emplace_back(pointer);
  5297. TheInst.emplace_back(packet_size);
  5298. TheInst.emplace_back(packet_alignment);
  5299. return *this;
  5300. }
  5301. InstBuilder &InstBuilder::opReservedWritePipe(uint32_t result_type,
  5302. uint32_t result_id, uint32_t pipe,
  5303. uint32_t reserve_id,
  5304. uint32_t index, uint32_t pointer,
  5305. uint32_t packet_size,
  5306. uint32_t packet_alignment) {
  5307. if (!TheInst.empty()) {
  5308. TheStatus = Status::NestedInst;
  5309. return *this;
  5310. }
  5311. if (result_type == 0) {
  5312. TheStatus = Status::ZeroResultType;
  5313. return *this;
  5314. }
  5315. if (result_id == 0) {
  5316. TheStatus = Status::ZeroResultId;
  5317. return *this;
  5318. }
  5319. TheInst.reserve(9);
  5320. TheInst.emplace_back(static_cast<uint32_t>(spv::Op::OpReservedWritePipe));
  5321. TheInst.emplace_back(result_type);
  5322. TheInst.emplace_back(result_id);
  5323. TheInst.emplace_back(pipe);
  5324. TheInst.emplace_back(reserve_id);
  5325. TheInst.emplace_back(index);
  5326. TheInst.emplace_back(pointer);
  5327. TheInst.emplace_back(packet_size);
  5328. TheInst.emplace_back(packet_alignment);
  5329. return *this;
  5330. }
  5331. InstBuilder &InstBuilder::opReserveReadPipePackets(
  5332. uint32_t result_type, uint32_t result_id, uint32_t pipe,
  5333. uint32_t num_packets, uint32_t packet_size, uint32_t packet_alignment) {
  5334. if (!TheInst.empty()) {
  5335. TheStatus = Status::NestedInst;
  5336. return *this;
  5337. }
  5338. if (result_type == 0) {
  5339. TheStatus = Status::ZeroResultType;
  5340. return *this;
  5341. }
  5342. if (result_id == 0) {
  5343. TheStatus = Status::ZeroResultId;
  5344. return *this;
  5345. }
  5346. TheInst.reserve(7);
  5347. TheInst.emplace_back(
  5348. static_cast<uint32_t>(spv::Op::OpReserveReadPipePackets));
  5349. TheInst.emplace_back(result_type);
  5350. TheInst.emplace_back(result_id);
  5351. TheInst.emplace_back(pipe);
  5352. TheInst.emplace_back(num_packets);
  5353. TheInst.emplace_back(packet_size);
  5354. TheInst.emplace_back(packet_alignment);
  5355. return *this;
  5356. }
  5357. InstBuilder &InstBuilder::opReserveWritePipePackets(
  5358. uint32_t result_type, uint32_t result_id, uint32_t pipe,
  5359. uint32_t num_packets, uint32_t packet_size, uint32_t packet_alignment) {
  5360. if (!TheInst.empty()) {
  5361. TheStatus = Status::NestedInst;
  5362. return *this;
  5363. }
  5364. if (result_type == 0) {
  5365. TheStatus = Status::ZeroResultType;
  5366. return *this;
  5367. }
  5368. if (result_id == 0) {
  5369. TheStatus = Status::ZeroResultId;
  5370. return *this;
  5371. }
  5372. TheInst.reserve(7);
  5373. TheInst.emplace_back(
  5374. static_cast<uint32_t>(spv::Op::OpReserveWritePipePackets));
  5375. TheInst.emplace_back(result_type);
  5376. TheInst.emplace_back(result_id);
  5377. TheInst.emplace_back(pipe);
  5378. TheInst.emplace_back(num_packets);
  5379. TheInst.emplace_back(packet_size);
  5380. TheInst.emplace_back(packet_alignment);
  5381. return *this;
  5382. }
  5383. InstBuilder &InstBuilder::opCommitReadPipe(uint32_t pipe, uint32_t reserve_id,
  5384. uint32_t packet_size,
  5385. uint32_t packet_alignment) {
  5386. if (!TheInst.empty()) {
  5387. TheStatus = Status::NestedInst;
  5388. return *this;
  5389. }
  5390. TheInst.reserve(5);
  5391. TheInst.emplace_back(static_cast<uint32_t>(spv::Op::OpCommitReadPipe));
  5392. TheInst.emplace_back(pipe);
  5393. TheInst.emplace_back(reserve_id);
  5394. TheInst.emplace_back(packet_size);
  5395. TheInst.emplace_back(packet_alignment);
  5396. return *this;
  5397. }
  5398. InstBuilder &InstBuilder::opCommitWritePipe(uint32_t pipe, uint32_t reserve_id,
  5399. uint32_t packet_size,
  5400. uint32_t packet_alignment) {
  5401. if (!TheInst.empty()) {
  5402. TheStatus = Status::NestedInst;
  5403. return *this;
  5404. }
  5405. TheInst.reserve(5);
  5406. TheInst.emplace_back(static_cast<uint32_t>(spv::Op::OpCommitWritePipe));
  5407. TheInst.emplace_back(pipe);
  5408. TheInst.emplace_back(reserve_id);
  5409. TheInst.emplace_back(packet_size);
  5410. TheInst.emplace_back(packet_alignment);
  5411. return *this;
  5412. }
  5413. InstBuilder &InstBuilder::opIsValidReserveId(uint32_t result_type,
  5414. uint32_t result_id,
  5415. uint32_t reserve_id) {
  5416. if (!TheInst.empty()) {
  5417. TheStatus = Status::NestedInst;
  5418. return *this;
  5419. }
  5420. if (result_type == 0) {
  5421. TheStatus = Status::ZeroResultType;
  5422. return *this;
  5423. }
  5424. if (result_id == 0) {
  5425. TheStatus = Status::ZeroResultId;
  5426. return *this;
  5427. }
  5428. TheInst.reserve(4);
  5429. TheInst.emplace_back(static_cast<uint32_t>(spv::Op::OpIsValidReserveId));
  5430. TheInst.emplace_back(result_type);
  5431. TheInst.emplace_back(result_id);
  5432. TheInst.emplace_back(reserve_id);
  5433. return *this;
  5434. }
  5435. InstBuilder &InstBuilder::opGetNumPipePackets(uint32_t result_type,
  5436. uint32_t result_id, uint32_t pipe,
  5437. uint32_t packet_size,
  5438. uint32_t packet_alignment) {
  5439. if (!TheInst.empty()) {
  5440. TheStatus = Status::NestedInst;
  5441. return *this;
  5442. }
  5443. if (result_type == 0) {
  5444. TheStatus = Status::ZeroResultType;
  5445. return *this;
  5446. }
  5447. if (result_id == 0) {
  5448. TheStatus = Status::ZeroResultId;
  5449. return *this;
  5450. }
  5451. TheInst.reserve(6);
  5452. TheInst.emplace_back(static_cast<uint32_t>(spv::Op::OpGetNumPipePackets));
  5453. TheInst.emplace_back(result_type);
  5454. TheInst.emplace_back(result_id);
  5455. TheInst.emplace_back(pipe);
  5456. TheInst.emplace_back(packet_size);
  5457. TheInst.emplace_back(packet_alignment);
  5458. return *this;
  5459. }
  5460. InstBuilder &InstBuilder::opGetMaxPipePackets(uint32_t result_type,
  5461. uint32_t result_id, uint32_t pipe,
  5462. uint32_t packet_size,
  5463. uint32_t packet_alignment) {
  5464. if (!TheInst.empty()) {
  5465. TheStatus = Status::NestedInst;
  5466. return *this;
  5467. }
  5468. if (result_type == 0) {
  5469. TheStatus = Status::ZeroResultType;
  5470. return *this;
  5471. }
  5472. if (result_id == 0) {
  5473. TheStatus = Status::ZeroResultId;
  5474. return *this;
  5475. }
  5476. TheInst.reserve(6);
  5477. TheInst.emplace_back(static_cast<uint32_t>(spv::Op::OpGetMaxPipePackets));
  5478. TheInst.emplace_back(result_type);
  5479. TheInst.emplace_back(result_id);
  5480. TheInst.emplace_back(pipe);
  5481. TheInst.emplace_back(packet_size);
  5482. TheInst.emplace_back(packet_alignment);
  5483. return *this;
  5484. }
  5485. InstBuilder &InstBuilder::opGroupReserveReadPipePackets(
  5486. uint32_t result_type, uint32_t result_id, uint32_t execution, uint32_t pipe,
  5487. uint32_t num_packets, uint32_t packet_size, uint32_t packet_alignment) {
  5488. if (!TheInst.empty()) {
  5489. TheStatus = Status::NestedInst;
  5490. return *this;
  5491. }
  5492. if (result_type == 0) {
  5493. TheStatus = Status::ZeroResultType;
  5494. return *this;
  5495. }
  5496. if (result_id == 0) {
  5497. TheStatus = Status::ZeroResultId;
  5498. return *this;
  5499. }
  5500. TheInst.reserve(8);
  5501. TheInst.emplace_back(
  5502. static_cast<uint32_t>(spv::Op::OpGroupReserveReadPipePackets));
  5503. TheInst.emplace_back(result_type);
  5504. TheInst.emplace_back(result_id);
  5505. TheInst.emplace_back(execution);
  5506. TheInst.emplace_back(pipe);
  5507. TheInst.emplace_back(num_packets);
  5508. TheInst.emplace_back(packet_size);
  5509. TheInst.emplace_back(packet_alignment);
  5510. return *this;
  5511. }
  5512. InstBuilder &InstBuilder::opGroupReserveWritePipePackets(
  5513. uint32_t result_type, uint32_t result_id, uint32_t execution, uint32_t pipe,
  5514. uint32_t num_packets, uint32_t packet_size, uint32_t packet_alignment) {
  5515. if (!TheInst.empty()) {
  5516. TheStatus = Status::NestedInst;
  5517. return *this;
  5518. }
  5519. if (result_type == 0) {
  5520. TheStatus = Status::ZeroResultType;
  5521. return *this;
  5522. }
  5523. if (result_id == 0) {
  5524. TheStatus = Status::ZeroResultId;
  5525. return *this;
  5526. }
  5527. TheInst.reserve(8);
  5528. TheInst.emplace_back(
  5529. static_cast<uint32_t>(spv::Op::OpGroupReserveWritePipePackets));
  5530. TheInst.emplace_back(result_type);
  5531. TheInst.emplace_back(result_id);
  5532. TheInst.emplace_back(execution);
  5533. TheInst.emplace_back(pipe);
  5534. TheInst.emplace_back(num_packets);
  5535. TheInst.emplace_back(packet_size);
  5536. TheInst.emplace_back(packet_alignment);
  5537. return *this;
  5538. }
  5539. InstBuilder &InstBuilder::opGroupCommitReadPipe(uint32_t execution,
  5540. uint32_t pipe,
  5541. uint32_t reserve_id,
  5542. uint32_t packet_size,
  5543. uint32_t packet_alignment) {
  5544. if (!TheInst.empty()) {
  5545. TheStatus = Status::NestedInst;
  5546. return *this;
  5547. }
  5548. TheInst.reserve(6);
  5549. TheInst.emplace_back(static_cast<uint32_t>(spv::Op::OpGroupCommitReadPipe));
  5550. TheInst.emplace_back(execution);
  5551. TheInst.emplace_back(pipe);
  5552. TheInst.emplace_back(reserve_id);
  5553. TheInst.emplace_back(packet_size);
  5554. TheInst.emplace_back(packet_alignment);
  5555. return *this;
  5556. }
  5557. InstBuilder &InstBuilder::opGroupCommitWritePipe(uint32_t execution,
  5558. uint32_t pipe,
  5559. uint32_t reserve_id,
  5560. uint32_t packet_size,
  5561. uint32_t packet_alignment) {
  5562. if (!TheInst.empty()) {
  5563. TheStatus = Status::NestedInst;
  5564. return *this;
  5565. }
  5566. TheInst.reserve(6);
  5567. TheInst.emplace_back(static_cast<uint32_t>(spv::Op::OpGroupCommitWritePipe));
  5568. TheInst.emplace_back(execution);
  5569. TheInst.emplace_back(pipe);
  5570. TheInst.emplace_back(reserve_id);
  5571. TheInst.emplace_back(packet_size);
  5572. TheInst.emplace_back(packet_alignment);
  5573. return *this;
  5574. }
  5575. InstBuilder &InstBuilder::opEnqueueMarker(uint32_t result_type,
  5576. uint32_t result_id, uint32_t queue,
  5577. uint32_t num_events,
  5578. uint32_t wait_events,
  5579. uint32_t ret_event) {
  5580. if (!TheInst.empty()) {
  5581. TheStatus = Status::NestedInst;
  5582. return *this;
  5583. }
  5584. if (result_type == 0) {
  5585. TheStatus = Status::ZeroResultType;
  5586. return *this;
  5587. }
  5588. if (result_id == 0) {
  5589. TheStatus = Status::ZeroResultId;
  5590. return *this;
  5591. }
  5592. TheInst.reserve(7);
  5593. TheInst.emplace_back(static_cast<uint32_t>(spv::Op::OpEnqueueMarker));
  5594. TheInst.emplace_back(result_type);
  5595. TheInst.emplace_back(result_id);
  5596. TheInst.emplace_back(queue);
  5597. TheInst.emplace_back(num_events);
  5598. TheInst.emplace_back(wait_events);
  5599. TheInst.emplace_back(ret_event);
  5600. return *this;
  5601. }
  5602. InstBuilder &InstBuilder::opEnqueueKernel(
  5603. uint32_t result_type, uint32_t result_id, uint32_t queue, uint32_t flags,
  5604. uint32_t nd_range, uint32_t num_events, uint32_t wait_events,
  5605. uint32_t ret_event, uint32_t invoke, uint32_t param, uint32_t param_size,
  5606. uint32_t param_align, llvm::ArrayRef<uint32_t> local_size) {
  5607. if (!TheInst.empty()) {
  5608. TheStatus = Status::NestedInst;
  5609. return *this;
  5610. }
  5611. if (result_type == 0) {
  5612. TheStatus = Status::ZeroResultType;
  5613. return *this;
  5614. }
  5615. if (result_id == 0) {
  5616. TheStatus = Status::ZeroResultId;
  5617. return *this;
  5618. }
  5619. TheInst.reserve(14);
  5620. TheInst.emplace_back(static_cast<uint32_t>(spv::Op::OpEnqueueKernel));
  5621. TheInst.emplace_back(result_type);
  5622. TheInst.emplace_back(result_id);
  5623. TheInst.emplace_back(queue);
  5624. TheInst.emplace_back(flags);
  5625. TheInst.emplace_back(nd_range);
  5626. TheInst.emplace_back(num_events);
  5627. TheInst.emplace_back(wait_events);
  5628. TheInst.emplace_back(ret_event);
  5629. TheInst.emplace_back(invoke);
  5630. TheInst.emplace_back(param);
  5631. TheInst.emplace_back(param_size);
  5632. TheInst.emplace_back(param_align);
  5633. TheInst.insert(TheInst.end(), local_size.begin(), local_size.end());
  5634. return *this;
  5635. }
  5636. InstBuilder &InstBuilder::opGetKernelNDrangeSubGroupCount(
  5637. uint32_t result_type, uint32_t result_id, uint32_t nd_range,
  5638. uint32_t invoke, uint32_t param, uint32_t param_size,
  5639. uint32_t param_align) {
  5640. if (!TheInst.empty()) {
  5641. TheStatus = Status::NestedInst;
  5642. return *this;
  5643. }
  5644. if (result_type == 0) {
  5645. TheStatus = Status::ZeroResultType;
  5646. return *this;
  5647. }
  5648. if (result_id == 0) {
  5649. TheStatus = Status::ZeroResultId;
  5650. return *this;
  5651. }
  5652. TheInst.reserve(8);
  5653. TheInst.emplace_back(
  5654. static_cast<uint32_t>(spv::Op::OpGetKernelNDrangeSubGroupCount));
  5655. TheInst.emplace_back(result_type);
  5656. TheInst.emplace_back(result_id);
  5657. TheInst.emplace_back(nd_range);
  5658. TheInst.emplace_back(invoke);
  5659. TheInst.emplace_back(param);
  5660. TheInst.emplace_back(param_size);
  5661. TheInst.emplace_back(param_align);
  5662. return *this;
  5663. }
  5664. InstBuilder &InstBuilder::opGetKernelNDrangeMaxSubGroupSize(
  5665. uint32_t result_type, uint32_t result_id, uint32_t nd_range,
  5666. uint32_t invoke, uint32_t param, uint32_t param_size,
  5667. uint32_t param_align) {
  5668. if (!TheInst.empty()) {
  5669. TheStatus = Status::NestedInst;
  5670. return *this;
  5671. }
  5672. if (result_type == 0) {
  5673. TheStatus = Status::ZeroResultType;
  5674. return *this;
  5675. }
  5676. if (result_id == 0) {
  5677. TheStatus = Status::ZeroResultId;
  5678. return *this;
  5679. }
  5680. TheInst.reserve(8);
  5681. TheInst.emplace_back(
  5682. static_cast<uint32_t>(spv::Op::OpGetKernelNDrangeMaxSubGroupSize));
  5683. TheInst.emplace_back(result_type);
  5684. TheInst.emplace_back(result_id);
  5685. TheInst.emplace_back(nd_range);
  5686. TheInst.emplace_back(invoke);
  5687. TheInst.emplace_back(param);
  5688. TheInst.emplace_back(param_size);
  5689. TheInst.emplace_back(param_align);
  5690. return *this;
  5691. }
  5692. InstBuilder &InstBuilder::opGetKernelWorkGroupSize(
  5693. uint32_t result_type, uint32_t result_id, uint32_t invoke, uint32_t param,
  5694. uint32_t param_size, uint32_t param_align) {
  5695. if (!TheInst.empty()) {
  5696. TheStatus = Status::NestedInst;
  5697. return *this;
  5698. }
  5699. if (result_type == 0) {
  5700. TheStatus = Status::ZeroResultType;
  5701. return *this;
  5702. }
  5703. if (result_id == 0) {
  5704. TheStatus = Status::ZeroResultId;
  5705. return *this;
  5706. }
  5707. TheInst.reserve(7);
  5708. TheInst.emplace_back(
  5709. static_cast<uint32_t>(spv::Op::OpGetKernelWorkGroupSize));
  5710. TheInst.emplace_back(result_type);
  5711. TheInst.emplace_back(result_id);
  5712. TheInst.emplace_back(invoke);
  5713. TheInst.emplace_back(param);
  5714. TheInst.emplace_back(param_size);
  5715. TheInst.emplace_back(param_align);
  5716. return *this;
  5717. }
  5718. InstBuilder &InstBuilder::opGetKernelPreferredWorkGroupSizeMultiple(
  5719. uint32_t result_type, uint32_t result_id, uint32_t invoke, uint32_t param,
  5720. uint32_t param_size, uint32_t param_align) {
  5721. if (!TheInst.empty()) {
  5722. TheStatus = Status::NestedInst;
  5723. return *this;
  5724. }
  5725. if (result_type == 0) {
  5726. TheStatus = Status::ZeroResultType;
  5727. return *this;
  5728. }
  5729. if (result_id == 0) {
  5730. TheStatus = Status::ZeroResultId;
  5731. return *this;
  5732. }
  5733. TheInst.reserve(7);
  5734. TheInst.emplace_back(static_cast<uint32_t>(
  5735. spv::Op::OpGetKernelPreferredWorkGroupSizeMultiple));
  5736. TheInst.emplace_back(result_type);
  5737. TheInst.emplace_back(result_id);
  5738. TheInst.emplace_back(invoke);
  5739. TheInst.emplace_back(param);
  5740. TheInst.emplace_back(param_size);
  5741. TheInst.emplace_back(param_align);
  5742. return *this;
  5743. }
  5744. InstBuilder &InstBuilder::opRetainEvent(uint32_t event) {
  5745. if (!TheInst.empty()) {
  5746. TheStatus = Status::NestedInst;
  5747. return *this;
  5748. }
  5749. TheInst.reserve(2);
  5750. TheInst.emplace_back(static_cast<uint32_t>(spv::Op::OpRetainEvent));
  5751. TheInst.emplace_back(event);
  5752. return *this;
  5753. }
  5754. InstBuilder &InstBuilder::opReleaseEvent(uint32_t event) {
  5755. if (!TheInst.empty()) {
  5756. TheStatus = Status::NestedInst;
  5757. return *this;
  5758. }
  5759. TheInst.reserve(2);
  5760. TheInst.emplace_back(static_cast<uint32_t>(spv::Op::OpReleaseEvent));
  5761. TheInst.emplace_back(event);
  5762. return *this;
  5763. }
  5764. InstBuilder &InstBuilder::opCreateUserEvent(uint32_t result_type,
  5765. uint32_t result_id) {
  5766. if (!TheInst.empty()) {
  5767. TheStatus = Status::NestedInst;
  5768. return *this;
  5769. }
  5770. if (result_type == 0) {
  5771. TheStatus = Status::ZeroResultType;
  5772. return *this;
  5773. }
  5774. if (result_id == 0) {
  5775. TheStatus = Status::ZeroResultId;
  5776. return *this;
  5777. }
  5778. TheInst.reserve(3);
  5779. TheInst.emplace_back(static_cast<uint32_t>(spv::Op::OpCreateUserEvent));
  5780. TheInst.emplace_back(result_type);
  5781. TheInst.emplace_back(result_id);
  5782. return *this;
  5783. }
  5784. InstBuilder &InstBuilder::opIsValidEvent(uint32_t result_type,
  5785. uint32_t result_id, uint32_t event) {
  5786. if (!TheInst.empty()) {
  5787. TheStatus = Status::NestedInst;
  5788. return *this;
  5789. }
  5790. if (result_type == 0) {
  5791. TheStatus = Status::ZeroResultType;
  5792. return *this;
  5793. }
  5794. if (result_id == 0) {
  5795. TheStatus = Status::ZeroResultId;
  5796. return *this;
  5797. }
  5798. TheInst.reserve(4);
  5799. TheInst.emplace_back(static_cast<uint32_t>(spv::Op::OpIsValidEvent));
  5800. TheInst.emplace_back(result_type);
  5801. TheInst.emplace_back(result_id);
  5802. TheInst.emplace_back(event);
  5803. return *this;
  5804. }
  5805. InstBuilder &InstBuilder::opSetUserEventStatus(uint32_t event,
  5806. uint32_t status) {
  5807. if (!TheInst.empty()) {
  5808. TheStatus = Status::NestedInst;
  5809. return *this;
  5810. }
  5811. TheInst.reserve(3);
  5812. TheInst.emplace_back(static_cast<uint32_t>(spv::Op::OpSetUserEventStatus));
  5813. TheInst.emplace_back(event);
  5814. TheInst.emplace_back(status);
  5815. return *this;
  5816. }
  5817. InstBuilder &InstBuilder::opCaptureEventProfilingInfo(uint32_t event,
  5818. uint32_t profiling_info,
  5819. uint32_t value) {
  5820. if (!TheInst.empty()) {
  5821. TheStatus = Status::NestedInst;
  5822. return *this;
  5823. }
  5824. TheInst.reserve(4);
  5825. TheInst.emplace_back(
  5826. static_cast<uint32_t>(spv::Op::OpCaptureEventProfilingInfo));
  5827. TheInst.emplace_back(event);
  5828. TheInst.emplace_back(profiling_info);
  5829. TheInst.emplace_back(value);
  5830. return *this;
  5831. }
  5832. InstBuilder &InstBuilder::opGetDefaultQueue(uint32_t result_type,
  5833. uint32_t result_id) {
  5834. if (!TheInst.empty()) {
  5835. TheStatus = Status::NestedInst;
  5836. return *this;
  5837. }
  5838. if (result_type == 0) {
  5839. TheStatus = Status::ZeroResultType;
  5840. return *this;
  5841. }
  5842. if (result_id == 0) {
  5843. TheStatus = Status::ZeroResultId;
  5844. return *this;
  5845. }
  5846. TheInst.reserve(3);
  5847. TheInst.emplace_back(static_cast<uint32_t>(spv::Op::OpGetDefaultQueue));
  5848. TheInst.emplace_back(result_type);
  5849. TheInst.emplace_back(result_id);
  5850. return *this;
  5851. }
  5852. InstBuilder &InstBuilder::opBuildNDRange(uint32_t result_type,
  5853. uint32_t result_id,
  5854. uint32_t global_work_size,
  5855. uint32_t local_work_size,
  5856. uint32_t global_work_offset) {
  5857. if (!TheInst.empty()) {
  5858. TheStatus = Status::NestedInst;
  5859. return *this;
  5860. }
  5861. if (result_type == 0) {
  5862. TheStatus = Status::ZeroResultType;
  5863. return *this;
  5864. }
  5865. if (result_id == 0) {
  5866. TheStatus = Status::ZeroResultId;
  5867. return *this;
  5868. }
  5869. TheInst.reserve(6);
  5870. TheInst.emplace_back(static_cast<uint32_t>(spv::Op::OpBuildNDRange));
  5871. TheInst.emplace_back(result_type);
  5872. TheInst.emplace_back(result_id);
  5873. TheInst.emplace_back(global_work_size);
  5874. TheInst.emplace_back(local_work_size);
  5875. TheInst.emplace_back(global_work_offset);
  5876. return *this;
  5877. }
  5878. InstBuilder &InstBuilder::opImageSparseSampleImplicitLod(
  5879. uint32_t result_type, uint32_t result_id, uint32_t sampled_image,
  5880. uint32_t coordinate,
  5881. llvm::Optional<spv::ImageOperandsMask> image_operands) {
  5882. if (!TheInst.empty()) {
  5883. TheStatus = Status::NestedInst;
  5884. return *this;
  5885. }
  5886. if (result_type == 0) {
  5887. TheStatus = Status::ZeroResultType;
  5888. return *this;
  5889. }
  5890. if (result_id == 0) {
  5891. TheStatus = Status::ZeroResultId;
  5892. return *this;
  5893. }
  5894. TheInst.reserve(6);
  5895. TheInst.emplace_back(
  5896. static_cast<uint32_t>(spv::Op::OpImageSparseSampleImplicitLod));
  5897. TheInst.emplace_back(result_type);
  5898. TheInst.emplace_back(result_id);
  5899. TheInst.emplace_back(sampled_image);
  5900. TheInst.emplace_back(coordinate);
  5901. if (image_operands.hasValue()) {
  5902. const auto &val = image_operands.getValue();
  5903. encodeImageOperands(val);
  5904. }
  5905. return *this;
  5906. }
  5907. InstBuilder &InstBuilder::opImageSparseSampleExplicitLod(
  5908. uint32_t result_type, uint32_t result_id, uint32_t sampled_image,
  5909. uint32_t coordinate, spv::ImageOperandsMask image_operands) {
  5910. if (!TheInst.empty()) {
  5911. TheStatus = Status::NestedInst;
  5912. return *this;
  5913. }
  5914. if (result_type == 0) {
  5915. TheStatus = Status::ZeroResultType;
  5916. return *this;
  5917. }
  5918. if (result_id == 0) {
  5919. TheStatus = Status::ZeroResultId;
  5920. return *this;
  5921. }
  5922. TheInst.reserve(6);
  5923. TheInst.emplace_back(
  5924. static_cast<uint32_t>(spv::Op::OpImageSparseSampleExplicitLod));
  5925. TheInst.emplace_back(result_type);
  5926. TheInst.emplace_back(result_id);
  5927. TheInst.emplace_back(sampled_image);
  5928. TheInst.emplace_back(coordinate);
  5929. encodeImageOperands(image_operands);
  5930. return *this;
  5931. }
  5932. InstBuilder &InstBuilder::opImageSparseSampleDrefImplicitLod(
  5933. uint32_t result_type, uint32_t result_id, uint32_t sampled_image,
  5934. uint32_t coordinate, uint32_t dref,
  5935. llvm::Optional<spv::ImageOperandsMask> image_operands) {
  5936. if (!TheInst.empty()) {
  5937. TheStatus = Status::NestedInst;
  5938. return *this;
  5939. }
  5940. if (result_type == 0) {
  5941. TheStatus = Status::ZeroResultType;
  5942. return *this;
  5943. }
  5944. if (result_id == 0) {
  5945. TheStatus = Status::ZeroResultId;
  5946. return *this;
  5947. }
  5948. TheInst.reserve(7);
  5949. TheInst.emplace_back(
  5950. static_cast<uint32_t>(spv::Op::OpImageSparseSampleDrefImplicitLod));
  5951. TheInst.emplace_back(result_type);
  5952. TheInst.emplace_back(result_id);
  5953. TheInst.emplace_back(sampled_image);
  5954. TheInst.emplace_back(coordinate);
  5955. TheInst.emplace_back(dref);
  5956. if (image_operands.hasValue()) {
  5957. const auto &val = image_operands.getValue();
  5958. encodeImageOperands(val);
  5959. }
  5960. return *this;
  5961. }
  5962. InstBuilder &InstBuilder::opImageSparseSampleDrefExplicitLod(
  5963. uint32_t result_type, uint32_t result_id, uint32_t sampled_image,
  5964. uint32_t coordinate, uint32_t dref, spv::ImageOperandsMask image_operands) {
  5965. if (!TheInst.empty()) {
  5966. TheStatus = Status::NestedInst;
  5967. return *this;
  5968. }
  5969. if (result_type == 0) {
  5970. TheStatus = Status::ZeroResultType;
  5971. return *this;
  5972. }
  5973. if (result_id == 0) {
  5974. TheStatus = Status::ZeroResultId;
  5975. return *this;
  5976. }
  5977. TheInst.reserve(7);
  5978. TheInst.emplace_back(
  5979. static_cast<uint32_t>(spv::Op::OpImageSparseSampleDrefExplicitLod));
  5980. TheInst.emplace_back(result_type);
  5981. TheInst.emplace_back(result_id);
  5982. TheInst.emplace_back(sampled_image);
  5983. TheInst.emplace_back(coordinate);
  5984. TheInst.emplace_back(dref);
  5985. encodeImageOperands(image_operands);
  5986. return *this;
  5987. }
  5988. InstBuilder &InstBuilder::opImageSparseSampleProjImplicitLod(
  5989. uint32_t result_type, uint32_t result_id, uint32_t sampled_image,
  5990. uint32_t coordinate,
  5991. llvm::Optional<spv::ImageOperandsMask> image_operands) {
  5992. if (!TheInst.empty()) {
  5993. TheStatus = Status::NestedInst;
  5994. return *this;
  5995. }
  5996. if (result_type == 0) {
  5997. TheStatus = Status::ZeroResultType;
  5998. return *this;
  5999. }
  6000. if (result_id == 0) {
  6001. TheStatus = Status::ZeroResultId;
  6002. return *this;
  6003. }
  6004. TheInst.reserve(6);
  6005. TheInst.emplace_back(
  6006. static_cast<uint32_t>(spv::Op::OpImageSparseSampleProjImplicitLod));
  6007. TheInst.emplace_back(result_type);
  6008. TheInst.emplace_back(result_id);
  6009. TheInst.emplace_back(sampled_image);
  6010. TheInst.emplace_back(coordinate);
  6011. if (image_operands.hasValue()) {
  6012. const auto &val = image_operands.getValue();
  6013. encodeImageOperands(val);
  6014. }
  6015. return *this;
  6016. }
  6017. InstBuilder &InstBuilder::opImageSparseSampleProjExplicitLod(
  6018. uint32_t result_type, uint32_t result_id, uint32_t sampled_image,
  6019. uint32_t coordinate, spv::ImageOperandsMask image_operands) {
  6020. if (!TheInst.empty()) {
  6021. TheStatus = Status::NestedInst;
  6022. return *this;
  6023. }
  6024. if (result_type == 0) {
  6025. TheStatus = Status::ZeroResultType;
  6026. return *this;
  6027. }
  6028. if (result_id == 0) {
  6029. TheStatus = Status::ZeroResultId;
  6030. return *this;
  6031. }
  6032. TheInst.reserve(6);
  6033. TheInst.emplace_back(
  6034. static_cast<uint32_t>(spv::Op::OpImageSparseSampleProjExplicitLod));
  6035. TheInst.emplace_back(result_type);
  6036. TheInst.emplace_back(result_id);
  6037. TheInst.emplace_back(sampled_image);
  6038. TheInst.emplace_back(coordinate);
  6039. encodeImageOperands(image_operands);
  6040. return *this;
  6041. }
  6042. InstBuilder &InstBuilder::opImageSparseSampleProjDrefImplicitLod(
  6043. uint32_t result_type, uint32_t result_id, uint32_t sampled_image,
  6044. uint32_t coordinate, uint32_t dref,
  6045. llvm::Optional<spv::ImageOperandsMask> image_operands) {
  6046. if (!TheInst.empty()) {
  6047. TheStatus = Status::NestedInst;
  6048. return *this;
  6049. }
  6050. if (result_type == 0) {
  6051. TheStatus = Status::ZeroResultType;
  6052. return *this;
  6053. }
  6054. if (result_id == 0) {
  6055. TheStatus = Status::ZeroResultId;
  6056. return *this;
  6057. }
  6058. TheInst.reserve(7);
  6059. TheInst.emplace_back(
  6060. static_cast<uint32_t>(spv::Op::OpImageSparseSampleProjDrefImplicitLod));
  6061. TheInst.emplace_back(result_type);
  6062. TheInst.emplace_back(result_id);
  6063. TheInst.emplace_back(sampled_image);
  6064. TheInst.emplace_back(coordinate);
  6065. TheInst.emplace_back(dref);
  6066. if (image_operands.hasValue()) {
  6067. const auto &val = image_operands.getValue();
  6068. encodeImageOperands(val);
  6069. }
  6070. return *this;
  6071. }
  6072. InstBuilder &InstBuilder::opImageSparseSampleProjDrefExplicitLod(
  6073. uint32_t result_type, uint32_t result_id, uint32_t sampled_image,
  6074. uint32_t coordinate, uint32_t dref, spv::ImageOperandsMask image_operands) {
  6075. if (!TheInst.empty()) {
  6076. TheStatus = Status::NestedInst;
  6077. return *this;
  6078. }
  6079. if (result_type == 0) {
  6080. TheStatus = Status::ZeroResultType;
  6081. return *this;
  6082. }
  6083. if (result_id == 0) {
  6084. TheStatus = Status::ZeroResultId;
  6085. return *this;
  6086. }
  6087. TheInst.reserve(7);
  6088. TheInst.emplace_back(
  6089. static_cast<uint32_t>(spv::Op::OpImageSparseSampleProjDrefExplicitLod));
  6090. TheInst.emplace_back(result_type);
  6091. TheInst.emplace_back(result_id);
  6092. TheInst.emplace_back(sampled_image);
  6093. TheInst.emplace_back(coordinate);
  6094. TheInst.emplace_back(dref);
  6095. encodeImageOperands(image_operands);
  6096. return *this;
  6097. }
  6098. InstBuilder &InstBuilder::opImageSparseFetch(
  6099. uint32_t result_type, uint32_t result_id, uint32_t image,
  6100. uint32_t coordinate,
  6101. llvm::Optional<spv::ImageOperandsMask> image_operands) {
  6102. if (!TheInst.empty()) {
  6103. TheStatus = Status::NestedInst;
  6104. return *this;
  6105. }
  6106. if (result_type == 0) {
  6107. TheStatus = Status::ZeroResultType;
  6108. return *this;
  6109. }
  6110. if (result_id == 0) {
  6111. TheStatus = Status::ZeroResultId;
  6112. return *this;
  6113. }
  6114. TheInst.reserve(6);
  6115. TheInst.emplace_back(static_cast<uint32_t>(spv::Op::OpImageSparseFetch));
  6116. TheInst.emplace_back(result_type);
  6117. TheInst.emplace_back(result_id);
  6118. TheInst.emplace_back(image);
  6119. TheInst.emplace_back(coordinate);
  6120. if (image_operands.hasValue()) {
  6121. const auto &val = image_operands.getValue();
  6122. encodeImageOperands(val);
  6123. }
  6124. return *this;
  6125. }
  6126. InstBuilder &InstBuilder::opImageSparseGather(
  6127. uint32_t result_type, uint32_t result_id, uint32_t sampled_image,
  6128. uint32_t coordinate, uint32_t component,
  6129. llvm::Optional<spv::ImageOperandsMask> image_operands) {
  6130. if (!TheInst.empty()) {
  6131. TheStatus = Status::NestedInst;
  6132. return *this;
  6133. }
  6134. if (result_type == 0) {
  6135. TheStatus = Status::ZeroResultType;
  6136. return *this;
  6137. }
  6138. if (result_id == 0) {
  6139. TheStatus = Status::ZeroResultId;
  6140. return *this;
  6141. }
  6142. TheInst.reserve(7);
  6143. TheInst.emplace_back(static_cast<uint32_t>(spv::Op::OpImageSparseGather));
  6144. TheInst.emplace_back(result_type);
  6145. TheInst.emplace_back(result_id);
  6146. TheInst.emplace_back(sampled_image);
  6147. TheInst.emplace_back(coordinate);
  6148. TheInst.emplace_back(component);
  6149. if (image_operands.hasValue()) {
  6150. const auto &val = image_operands.getValue();
  6151. encodeImageOperands(val);
  6152. }
  6153. return *this;
  6154. }
  6155. InstBuilder &InstBuilder::opImageSparseDrefGather(
  6156. uint32_t result_type, uint32_t result_id, uint32_t sampled_image,
  6157. uint32_t coordinate, uint32_t dref,
  6158. llvm::Optional<spv::ImageOperandsMask> image_operands) {
  6159. if (!TheInst.empty()) {
  6160. TheStatus = Status::NestedInst;
  6161. return *this;
  6162. }
  6163. if (result_type == 0) {
  6164. TheStatus = Status::ZeroResultType;
  6165. return *this;
  6166. }
  6167. if (result_id == 0) {
  6168. TheStatus = Status::ZeroResultId;
  6169. return *this;
  6170. }
  6171. TheInst.reserve(7);
  6172. TheInst.emplace_back(static_cast<uint32_t>(spv::Op::OpImageSparseDrefGather));
  6173. TheInst.emplace_back(result_type);
  6174. TheInst.emplace_back(result_id);
  6175. TheInst.emplace_back(sampled_image);
  6176. TheInst.emplace_back(coordinate);
  6177. TheInst.emplace_back(dref);
  6178. if (image_operands.hasValue()) {
  6179. const auto &val = image_operands.getValue();
  6180. encodeImageOperands(val);
  6181. }
  6182. return *this;
  6183. }
  6184. InstBuilder &InstBuilder::opImageSparseTexelsResident(uint32_t result_type,
  6185. uint32_t result_id,
  6186. uint32_t resident_code) {
  6187. if (!TheInst.empty()) {
  6188. TheStatus = Status::NestedInst;
  6189. return *this;
  6190. }
  6191. if (result_type == 0) {
  6192. TheStatus = Status::ZeroResultType;
  6193. return *this;
  6194. }
  6195. if (result_id == 0) {
  6196. TheStatus = Status::ZeroResultId;
  6197. return *this;
  6198. }
  6199. TheInst.reserve(4);
  6200. TheInst.emplace_back(
  6201. static_cast<uint32_t>(spv::Op::OpImageSparseTexelsResident));
  6202. TheInst.emplace_back(result_type);
  6203. TheInst.emplace_back(result_id);
  6204. TheInst.emplace_back(resident_code);
  6205. return *this;
  6206. }
  6207. InstBuilder &InstBuilder::opNoLine() {
  6208. if (!TheInst.empty()) {
  6209. TheStatus = Status::NestedInst;
  6210. return *this;
  6211. }
  6212. TheInst.reserve(1);
  6213. TheInst.emplace_back(static_cast<uint32_t>(spv::Op::OpNoLine));
  6214. return *this;
  6215. }
  6216. InstBuilder &InstBuilder::opAtomicFlagTestAndSet(uint32_t result_type,
  6217. uint32_t result_id,
  6218. uint32_t pointer,
  6219. uint32_t scope,
  6220. uint32_t semantics) {
  6221. if (!TheInst.empty()) {
  6222. TheStatus = Status::NestedInst;
  6223. return *this;
  6224. }
  6225. if (result_type == 0) {
  6226. TheStatus = Status::ZeroResultType;
  6227. return *this;
  6228. }
  6229. if (result_id == 0) {
  6230. TheStatus = Status::ZeroResultId;
  6231. return *this;
  6232. }
  6233. TheInst.reserve(6);
  6234. TheInst.emplace_back(static_cast<uint32_t>(spv::Op::OpAtomicFlagTestAndSet));
  6235. TheInst.emplace_back(result_type);
  6236. TheInst.emplace_back(result_id);
  6237. TheInst.emplace_back(pointer);
  6238. TheInst.emplace_back(scope);
  6239. TheInst.emplace_back(semantics);
  6240. return *this;
  6241. }
  6242. InstBuilder &InstBuilder::opAtomicFlagClear(uint32_t pointer, uint32_t scope,
  6243. uint32_t semantics) {
  6244. if (!TheInst.empty()) {
  6245. TheStatus = Status::NestedInst;
  6246. return *this;
  6247. }
  6248. TheInst.reserve(4);
  6249. TheInst.emplace_back(static_cast<uint32_t>(spv::Op::OpAtomicFlagClear));
  6250. TheInst.emplace_back(pointer);
  6251. TheInst.emplace_back(scope);
  6252. TheInst.emplace_back(semantics);
  6253. return *this;
  6254. }
  6255. InstBuilder &InstBuilder::opImageSparseRead(
  6256. uint32_t result_type, uint32_t result_id, uint32_t image,
  6257. uint32_t coordinate,
  6258. llvm::Optional<spv::ImageOperandsMask> image_operands) {
  6259. if (!TheInst.empty()) {
  6260. TheStatus = Status::NestedInst;
  6261. return *this;
  6262. }
  6263. if (result_type == 0) {
  6264. TheStatus = Status::ZeroResultType;
  6265. return *this;
  6266. }
  6267. if (result_id == 0) {
  6268. TheStatus = Status::ZeroResultId;
  6269. return *this;
  6270. }
  6271. TheInst.reserve(6);
  6272. TheInst.emplace_back(static_cast<uint32_t>(spv::Op::OpImageSparseRead));
  6273. TheInst.emplace_back(result_type);
  6274. TheInst.emplace_back(result_id);
  6275. TheInst.emplace_back(image);
  6276. TheInst.emplace_back(coordinate);
  6277. if (image_operands.hasValue()) {
  6278. const auto &val = image_operands.getValue();
  6279. encodeImageOperands(val);
  6280. }
  6281. return *this;
  6282. }
  6283. InstBuilder &InstBuilder::opSizeOf(uint32_t result_type, uint32_t result_id,
  6284. uint32_t pointer) {
  6285. if (!TheInst.empty()) {
  6286. TheStatus = Status::NestedInst;
  6287. return *this;
  6288. }
  6289. if (result_type == 0) {
  6290. TheStatus = Status::ZeroResultType;
  6291. return *this;
  6292. }
  6293. if (result_id == 0) {
  6294. TheStatus = Status::ZeroResultId;
  6295. return *this;
  6296. }
  6297. TheInst.reserve(4);
  6298. TheInst.emplace_back(static_cast<uint32_t>(spv::Op::OpSizeOf));
  6299. TheInst.emplace_back(result_type);
  6300. TheInst.emplace_back(result_id);
  6301. TheInst.emplace_back(pointer);
  6302. return *this;
  6303. }
  6304. InstBuilder &InstBuilder::opTypePipeStorage(uint32_t result_id) {
  6305. if (!TheInst.empty()) {
  6306. TheStatus = Status::NestedInst;
  6307. return *this;
  6308. }
  6309. if (result_id == 0) {
  6310. TheStatus = Status::ZeroResultId;
  6311. return *this;
  6312. }
  6313. TheInst.reserve(2);
  6314. TheInst.emplace_back(static_cast<uint32_t>(spv::Op::OpTypePipeStorage));
  6315. TheInst.emplace_back(result_id);
  6316. return *this;
  6317. }
  6318. InstBuilder &InstBuilder::opConstantPipeStorage(uint32_t result_type,
  6319. uint32_t result_id,
  6320. uint32_t packet_size,
  6321. uint32_t packet_alignment,
  6322. uint32_t capacity) {
  6323. if (!TheInst.empty()) {
  6324. TheStatus = Status::NestedInst;
  6325. return *this;
  6326. }
  6327. if (result_type == 0) {
  6328. TheStatus = Status::ZeroResultType;
  6329. return *this;
  6330. }
  6331. if (result_id == 0) {
  6332. TheStatus = Status::ZeroResultId;
  6333. return *this;
  6334. }
  6335. TheInst.reserve(6);
  6336. TheInst.emplace_back(static_cast<uint32_t>(spv::Op::OpConstantPipeStorage));
  6337. TheInst.emplace_back(result_type);
  6338. TheInst.emplace_back(result_id);
  6339. TheInst.emplace_back(packet_size);
  6340. TheInst.emplace_back(packet_alignment);
  6341. TheInst.emplace_back(capacity);
  6342. return *this;
  6343. }
  6344. InstBuilder &InstBuilder::opCreatePipeFromPipeStorage(uint32_t result_type,
  6345. uint32_t result_id,
  6346. uint32_t pipe_storage) {
  6347. if (!TheInst.empty()) {
  6348. TheStatus = Status::NestedInst;
  6349. return *this;
  6350. }
  6351. if (result_type == 0) {
  6352. TheStatus = Status::ZeroResultType;
  6353. return *this;
  6354. }
  6355. if (result_id == 0) {
  6356. TheStatus = Status::ZeroResultId;
  6357. return *this;
  6358. }
  6359. TheInst.reserve(4);
  6360. TheInst.emplace_back(
  6361. static_cast<uint32_t>(spv::Op::OpCreatePipeFromPipeStorage));
  6362. TheInst.emplace_back(result_type);
  6363. TheInst.emplace_back(result_id);
  6364. TheInst.emplace_back(pipe_storage);
  6365. return *this;
  6366. }
  6367. InstBuilder &InstBuilder::opGetKernelLocalSizeForSubgroupCount(
  6368. uint32_t result_type, uint32_t result_id, uint32_t subgroup_count,
  6369. uint32_t invoke, uint32_t param, uint32_t param_size,
  6370. uint32_t param_align) {
  6371. if (!TheInst.empty()) {
  6372. TheStatus = Status::NestedInst;
  6373. return *this;
  6374. }
  6375. if (result_type == 0) {
  6376. TheStatus = Status::ZeroResultType;
  6377. return *this;
  6378. }
  6379. if (result_id == 0) {
  6380. TheStatus = Status::ZeroResultId;
  6381. return *this;
  6382. }
  6383. TheInst.reserve(8);
  6384. TheInst.emplace_back(
  6385. static_cast<uint32_t>(spv::Op::OpGetKernelLocalSizeForSubgroupCount));
  6386. TheInst.emplace_back(result_type);
  6387. TheInst.emplace_back(result_id);
  6388. TheInst.emplace_back(subgroup_count);
  6389. TheInst.emplace_back(invoke);
  6390. TheInst.emplace_back(param);
  6391. TheInst.emplace_back(param_size);
  6392. TheInst.emplace_back(param_align);
  6393. return *this;
  6394. }
  6395. InstBuilder &InstBuilder::opGetKernelMaxNumSubgroups(
  6396. uint32_t result_type, uint32_t result_id, uint32_t invoke, uint32_t param,
  6397. uint32_t param_size, uint32_t param_align) {
  6398. if (!TheInst.empty()) {
  6399. TheStatus = Status::NestedInst;
  6400. return *this;
  6401. }
  6402. if (result_type == 0) {
  6403. TheStatus = Status::ZeroResultType;
  6404. return *this;
  6405. }
  6406. if (result_id == 0) {
  6407. TheStatus = Status::ZeroResultId;
  6408. return *this;
  6409. }
  6410. TheInst.reserve(7);
  6411. TheInst.emplace_back(
  6412. static_cast<uint32_t>(spv::Op::OpGetKernelMaxNumSubgroups));
  6413. TheInst.emplace_back(result_type);
  6414. TheInst.emplace_back(result_id);
  6415. TheInst.emplace_back(invoke);
  6416. TheInst.emplace_back(param);
  6417. TheInst.emplace_back(param_size);
  6418. TheInst.emplace_back(param_align);
  6419. return *this;
  6420. }
  6421. InstBuilder &InstBuilder::opTypeNamedBarrier(uint32_t result_id) {
  6422. if (!TheInst.empty()) {
  6423. TheStatus = Status::NestedInst;
  6424. return *this;
  6425. }
  6426. if (result_id == 0) {
  6427. TheStatus = Status::ZeroResultId;
  6428. return *this;
  6429. }
  6430. TheInst.reserve(2);
  6431. TheInst.emplace_back(static_cast<uint32_t>(spv::Op::OpTypeNamedBarrier));
  6432. TheInst.emplace_back(result_id);
  6433. return *this;
  6434. }
  6435. InstBuilder &InstBuilder::opNamedBarrierInitialize(uint32_t result_type,
  6436. uint32_t result_id,
  6437. uint32_t subgroup_count) {
  6438. if (!TheInst.empty()) {
  6439. TheStatus = Status::NestedInst;
  6440. return *this;
  6441. }
  6442. if (result_type == 0) {
  6443. TheStatus = Status::ZeroResultType;
  6444. return *this;
  6445. }
  6446. if (result_id == 0) {
  6447. TheStatus = Status::ZeroResultId;
  6448. return *this;
  6449. }
  6450. TheInst.reserve(4);
  6451. TheInst.emplace_back(
  6452. static_cast<uint32_t>(spv::Op::OpNamedBarrierInitialize));
  6453. TheInst.emplace_back(result_type);
  6454. TheInst.emplace_back(result_id);
  6455. TheInst.emplace_back(subgroup_count);
  6456. return *this;
  6457. }
  6458. InstBuilder &InstBuilder::opMemoryNamedBarrier(uint32_t named_barrier,
  6459. uint32_t memory,
  6460. uint32_t semantics) {
  6461. if (!TheInst.empty()) {
  6462. TheStatus = Status::NestedInst;
  6463. return *this;
  6464. }
  6465. TheInst.reserve(4);
  6466. TheInst.emplace_back(static_cast<uint32_t>(spv::Op::OpMemoryNamedBarrier));
  6467. TheInst.emplace_back(named_barrier);
  6468. TheInst.emplace_back(memory);
  6469. TheInst.emplace_back(semantics);
  6470. return *this;
  6471. }
  6472. InstBuilder &InstBuilder::opModuleProcessed(std::string process) {
  6473. if (!TheInst.empty()) {
  6474. TheStatus = Status::NestedInst;
  6475. return *this;
  6476. }
  6477. TheInst.reserve(2);
  6478. TheInst.emplace_back(static_cast<uint32_t>(spv::Op::OpModuleProcessed));
  6479. encodeString(process);
  6480. return *this;
  6481. }
  6482. InstBuilder &InstBuilder::opExecutionModeId(uint32_t entry_point,
  6483. spv::ExecutionMode mode) {
  6484. if (!TheInst.empty()) {
  6485. TheStatus = Status::NestedInst;
  6486. return *this;
  6487. }
  6488. TheInst.reserve(3);
  6489. TheInst.emplace_back(static_cast<uint32_t>(spv::Op::OpExecutionModeId));
  6490. TheInst.emplace_back(entry_point);
  6491. encodeExecutionMode(mode);
  6492. return *this;
  6493. }
  6494. InstBuilder &InstBuilder::opDecorateId(uint32_t target,
  6495. spv::Decoration decoration) {
  6496. if (!TheInst.empty()) {
  6497. TheStatus = Status::NestedInst;
  6498. return *this;
  6499. }
  6500. TheInst.reserve(3);
  6501. TheInst.emplace_back(static_cast<uint32_t>(spv::Op::OpDecorateId));
  6502. TheInst.emplace_back(target);
  6503. encodeDecoration(decoration);
  6504. return *this;
  6505. }
  6506. InstBuilder &InstBuilder::opSubgroupBallotKHR(uint32_t result_type,
  6507. uint32_t result_id,
  6508. uint32_t predicate) {
  6509. if (!TheInst.empty()) {
  6510. TheStatus = Status::NestedInst;
  6511. return *this;
  6512. }
  6513. if (result_type == 0) {
  6514. TheStatus = Status::ZeroResultType;
  6515. return *this;
  6516. }
  6517. if (result_id == 0) {
  6518. TheStatus = Status::ZeroResultId;
  6519. return *this;
  6520. }
  6521. TheInst.reserve(4);
  6522. TheInst.emplace_back(static_cast<uint32_t>(spv::Op::OpSubgroupBallotKHR));
  6523. TheInst.emplace_back(result_type);
  6524. TheInst.emplace_back(result_id);
  6525. TheInst.emplace_back(predicate);
  6526. return *this;
  6527. }
  6528. InstBuilder &InstBuilder::opSubgroupFirstInvocationKHR(uint32_t result_type,
  6529. uint32_t result_id,
  6530. uint32_t value) {
  6531. if (!TheInst.empty()) {
  6532. TheStatus = Status::NestedInst;
  6533. return *this;
  6534. }
  6535. if (result_type == 0) {
  6536. TheStatus = Status::ZeroResultType;
  6537. return *this;
  6538. }
  6539. if (result_id == 0) {
  6540. TheStatus = Status::ZeroResultId;
  6541. return *this;
  6542. }
  6543. TheInst.reserve(4);
  6544. TheInst.emplace_back(
  6545. static_cast<uint32_t>(spv::Op::OpSubgroupFirstInvocationKHR));
  6546. TheInst.emplace_back(result_type);
  6547. TheInst.emplace_back(result_id);
  6548. TheInst.emplace_back(value);
  6549. return *this;
  6550. }
  6551. InstBuilder &InstBuilder::opSubgroupAllKHR(uint32_t result_type,
  6552. uint32_t result_id,
  6553. uint32_t predicate) {
  6554. if (!TheInst.empty()) {
  6555. TheStatus = Status::NestedInst;
  6556. return *this;
  6557. }
  6558. if (result_type == 0) {
  6559. TheStatus = Status::ZeroResultType;
  6560. return *this;
  6561. }
  6562. if (result_id == 0) {
  6563. TheStatus = Status::ZeroResultId;
  6564. return *this;
  6565. }
  6566. TheInst.reserve(4);
  6567. TheInst.emplace_back(static_cast<uint32_t>(spv::Op::OpSubgroupAllKHR));
  6568. TheInst.emplace_back(result_type);
  6569. TheInst.emplace_back(result_id);
  6570. TheInst.emplace_back(predicate);
  6571. return *this;
  6572. }
  6573. InstBuilder &InstBuilder::opSubgroupAnyKHR(uint32_t result_type,
  6574. uint32_t result_id,
  6575. uint32_t predicate) {
  6576. if (!TheInst.empty()) {
  6577. TheStatus = Status::NestedInst;
  6578. return *this;
  6579. }
  6580. if (result_type == 0) {
  6581. TheStatus = Status::ZeroResultType;
  6582. return *this;
  6583. }
  6584. if (result_id == 0) {
  6585. TheStatus = Status::ZeroResultId;
  6586. return *this;
  6587. }
  6588. TheInst.reserve(4);
  6589. TheInst.emplace_back(static_cast<uint32_t>(spv::Op::OpSubgroupAnyKHR));
  6590. TheInst.emplace_back(result_type);
  6591. TheInst.emplace_back(result_id);
  6592. TheInst.emplace_back(predicate);
  6593. return *this;
  6594. }
  6595. InstBuilder &InstBuilder::opSubgroupAllEqualKHR(uint32_t result_type,
  6596. uint32_t result_id,
  6597. uint32_t predicate) {
  6598. if (!TheInst.empty()) {
  6599. TheStatus = Status::NestedInst;
  6600. return *this;
  6601. }
  6602. if (result_type == 0) {
  6603. TheStatus = Status::ZeroResultType;
  6604. return *this;
  6605. }
  6606. if (result_id == 0) {
  6607. TheStatus = Status::ZeroResultId;
  6608. return *this;
  6609. }
  6610. TheInst.reserve(4);
  6611. TheInst.emplace_back(static_cast<uint32_t>(spv::Op::OpSubgroupAllEqualKHR));
  6612. TheInst.emplace_back(result_type);
  6613. TheInst.emplace_back(result_id);
  6614. TheInst.emplace_back(predicate);
  6615. return *this;
  6616. }
  6617. InstBuilder &InstBuilder::opSubgroupReadInvocationKHR(uint32_t result_type,
  6618. uint32_t result_id,
  6619. uint32_t value,
  6620. uint32_t index) {
  6621. if (!TheInst.empty()) {
  6622. TheStatus = Status::NestedInst;
  6623. return *this;
  6624. }
  6625. if (result_type == 0) {
  6626. TheStatus = Status::ZeroResultType;
  6627. return *this;
  6628. }
  6629. if (result_id == 0) {
  6630. TheStatus = Status::ZeroResultId;
  6631. return *this;
  6632. }
  6633. TheInst.reserve(5);
  6634. TheInst.emplace_back(
  6635. static_cast<uint32_t>(spv::Op::OpSubgroupReadInvocationKHR));
  6636. TheInst.emplace_back(result_type);
  6637. TheInst.emplace_back(result_id);
  6638. TheInst.emplace_back(value);
  6639. TheInst.emplace_back(index);
  6640. return *this;
  6641. }
  6642. InstBuilder &InstBuilder::opGroupIAddNonUniformAMD(
  6643. uint32_t result_type, uint32_t result_id, uint32_t execution,
  6644. spv::GroupOperation operation, uint32_t x) {
  6645. if (!TheInst.empty()) {
  6646. TheStatus = Status::NestedInst;
  6647. return *this;
  6648. }
  6649. if (result_type == 0) {
  6650. TheStatus = Status::ZeroResultType;
  6651. return *this;
  6652. }
  6653. if (result_id == 0) {
  6654. TheStatus = Status::ZeroResultId;
  6655. return *this;
  6656. }
  6657. TheInst.reserve(6);
  6658. TheInst.emplace_back(
  6659. static_cast<uint32_t>(spv::Op::OpGroupIAddNonUniformAMD));
  6660. TheInst.emplace_back(result_type);
  6661. TheInst.emplace_back(result_id);
  6662. TheInst.emplace_back(execution);
  6663. TheInst.emplace_back(static_cast<uint32_t>(operation));
  6664. TheInst.emplace_back(x);
  6665. return *this;
  6666. }
  6667. InstBuilder &InstBuilder::opGroupFAddNonUniformAMD(
  6668. uint32_t result_type, uint32_t result_id, uint32_t execution,
  6669. spv::GroupOperation operation, uint32_t x) {
  6670. if (!TheInst.empty()) {
  6671. TheStatus = Status::NestedInst;
  6672. return *this;
  6673. }
  6674. if (result_type == 0) {
  6675. TheStatus = Status::ZeroResultType;
  6676. return *this;
  6677. }
  6678. if (result_id == 0) {
  6679. TheStatus = Status::ZeroResultId;
  6680. return *this;
  6681. }
  6682. TheInst.reserve(6);
  6683. TheInst.emplace_back(
  6684. static_cast<uint32_t>(spv::Op::OpGroupFAddNonUniformAMD));
  6685. TheInst.emplace_back(result_type);
  6686. TheInst.emplace_back(result_id);
  6687. TheInst.emplace_back(execution);
  6688. TheInst.emplace_back(static_cast<uint32_t>(operation));
  6689. TheInst.emplace_back(x);
  6690. return *this;
  6691. }
  6692. InstBuilder &InstBuilder::opGroupFMinNonUniformAMD(
  6693. uint32_t result_type, uint32_t result_id, uint32_t execution,
  6694. spv::GroupOperation operation, uint32_t x) {
  6695. if (!TheInst.empty()) {
  6696. TheStatus = Status::NestedInst;
  6697. return *this;
  6698. }
  6699. if (result_type == 0) {
  6700. TheStatus = Status::ZeroResultType;
  6701. return *this;
  6702. }
  6703. if (result_id == 0) {
  6704. TheStatus = Status::ZeroResultId;
  6705. return *this;
  6706. }
  6707. TheInst.reserve(6);
  6708. TheInst.emplace_back(
  6709. static_cast<uint32_t>(spv::Op::OpGroupFMinNonUniformAMD));
  6710. TheInst.emplace_back(result_type);
  6711. TheInst.emplace_back(result_id);
  6712. TheInst.emplace_back(execution);
  6713. TheInst.emplace_back(static_cast<uint32_t>(operation));
  6714. TheInst.emplace_back(x);
  6715. return *this;
  6716. }
  6717. InstBuilder &InstBuilder::opGroupUMinNonUniformAMD(
  6718. uint32_t result_type, uint32_t result_id, uint32_t execution,
  6719. spv::GroupOperation operation, uint32_t x) {
  6720. if (!TheInst.empty()) {
  6721. TheStatus = Status::NestedInst;
  6722. return *this;
  6723. }
  6724. if (result_type == 0) {
  6725. TheStatus = Status::ZeroResultType;
  6726. return *this;
  6727. }
  6728. if (result_id == 0) {
  6729. TheStatus = Status::ZeroResultId;
  6730. return *this;
  6731. }
  6732. TheInst.reserve(6);
  6733. TheInst.emplace_back(
  6734. static_cast<uint32_t>(spv::Op::OpGroupUMinNonUniformAMD));
  6735. TheInst.emplace_back(result_type);
  6736. TheInst.emplace_back(result_id);
  6737. TheInst.emplace_back(execution);
  6738. TheInst.emplace_back(static_cast<uint32_t>(operation));
  6739. TheInst.emplace_back(x);
  6740. return *this;
  6741. }
  6742. InstBuilder &InstBuilder::opGroupSMinNonUniformAMD(
  6743. uint32_t result_type, uint32_t result_id, uint32_t execution,
  6744. spv::GroupOperation operation, uint32_t x) {
  6745. if (!TheInst.empty()) {
  6746. TheStatus = Status::NestedInst;
  6747. return *this;
  6748. }
  6749. if (result_type == 0) {
  6750. TheStatus = Status::ZeroResultType;
  6751. return *this;
  6752. }
  6753. if (result_id == 0) {
  6754. TheStatus = Status::ZeroResultId;
  6755. return *this;
  6756. }
  6757. TheInst.reserve(6);
  6758. TheInst.emplace_back(
  6759. static_cast<uint32_t>(spv::Op::OpGroupSMinNonUniformAMD));
  6760. TheInst.emplace_back(result_type);
  6761. TheInst.emplace_back(result_id);
  6762. TheInst.emplace_back(execution);
  6763. TheInst.emplace_back(static_cast<uint32_t>(operation));
  6764. TheInst.emplace_back(x);
  6765. return *this;
  6766. }
  6767. InstBuilder &InstBuilder::opGroupFMaxNonUniformAMD(
  6768. uint32_t result_type, uint32_t result_id, uint32_t execution,
  6769. spv::GroupOperation operation, uint32_t x) {
  6770. if (!TheInst.empty()) {
  6771. TheStatus = Status::NestedInst;
  6772. return *this;
  6773. }
  6774. if (result_type == 0) {
  6775. TheStatus = Status::ZeroResultType;
  6776. return *this;
  6777. }
  6778. if (result_id == 0) {
  6779. TheStatus = Status::ZeroResultId;
  6780. return *this;
  6781. }
  6782. TheInst.reserve(6);
  6783. TheInst.emplace_back(
  6784. static_cast<uint32_t>(spv::Op::OpGroupFMaxNonUniformAMD));
  6785. TheInst.emplace_back(result_type);
  6786. TheInst.emplace_back(result_id);
  6787. TheInst.emplace_back(execution);
  6788. TheInst.emplace_back(static_cast<uint32_t>(operation));
  6789. TheInst.emplace_back(x);
  6790. return *this;
  6791. }
  6792. InstBuilder &InstBuilder::opGroupUMaxNonUniformAMD(
  6793. uint32_t result_type, uint32_t result_id, uint32_t execution,
  6794. spv::GroupOperation operation, uint32_t x) {
  6795. if (!TheInst.empty()) {
  6796. TheStatus = Status::NestedInst;
  6797. return *this;
  6798. }
  6799. if (result_type == 0) {
  6800. TheStatus = Status::ZeroResultType;
  6801. return *this;
  6802. }
  6803. if (result_id == 0) {
  6804. TheStatus = Status::ZeroResultId;
  6805. return *this;
  6806. }
  6807. TheInst.reserve(6);
  6808. TheInst.emplace_back(
  6809. static_cast<uint32_t>(spv::Op::OpGroupUMaxNonUniformAMD));
  6810. TheInst.emplace_back(result_type);
  6811. TheInst.emplace_back(result_id);
  6812. TheInst.emplace_back(execution);
  6813. TheInst.emplace_back(static_cast<uint32_t>(operation));
  6814. TheInst.emplace_back(x);
  6815. return *this;
  6816. }
  6817. InstBuilder &InstBuilder::opGroupSMaxNonUniformAMD(
  6818. uint32_t result_type, uint32_t result_id, uint32_t execution,
  6819. spv::GroupOperation operation, uint32_t x) {
  6820. if (!TheInst.empty()) {
  6821. TheStatus = Status::NestedInst;
  6822. return *this;
  6823. }
  6824. if (result_type == 0) {
  6825. TheStatus = Status::ZeroResultType;
  6826. return *this;
  6827. }
  6828. if (result_id == 0) {
  6829. TheStatus = Status::ZeroResultId;
  6830. return *this;
  6831. }
  6832. TheInst.reserve(6);
  6833. TheInst.emplace_back(
  6834. static_cast<uint32_t>(spv::Op::OpGroupSMaxNonUniformAMD));
  6835. TheInst.emplace_back(result_type);
  6836. TheInst.emplace_back(result_id);
  6837. TheInst.emplace_back(execution);
  6838. TheInst.emplace_back(static_cast<uint32_t>(operation));
  6839. TheInst.emplace_back(x);
  6840. return *this;
  6841. }
  6842. InstBuilder &InstBuilder::opFragmentMaskFetchAMD(uint32_t result_type,
  6843. uint32_t result_id,
  6844. uint32_t image,
  6845. uint32_t coordinate) {
  6846. if (!TheInst.empty()) {
  6847. TheStatus = Status::NestedInst;
  6848. return *this;
  6849. }
  6850. if (result_type == 0) {
  6851. TheStatus = Status::ZeroResultType;
  6852. return *this;
  6853. }
  6854. if (result_id == 0) {
  6855. TheStatus = Status::ZeroResultId;
  6856. return *this;
  6857. }
  6858. TheInst.reserve(5);
  6859. TheInst.emplace_back(static_cast<uint32_t>(spv::Op::OpFragmentMaskFetchAMD));
  6860. TheInst.emplace_back(result_type);
  6861. TheInst.emplace_back(result_id);
  6862. TheInst.emplace_back(image);
  6863. TheInst.emplace_back(coordinate);
  6864. return *this;
  6865. }
  6866. InstBuilder &InstBuilder::opFragmentFetchAMD(uint32_t result_type,
  6867. uint32_t result_id, uint32_t image,
  6868. uint32_t coordinate,
  6869. uint32_t fragment_index) {
  6870. if (!TheInst.empty()) {
  6871. TheStatus = Status::NestedInst;
  6872. return *this;
  6873. }
  6874. if (result_type == 0) {
  6875. TheStatus = Status::ZeroResultType;
  6876. return *this;
  6877. }
  6878. if (result_id == 0) {
  6879. TheStatus = Status::ZeroResultId;
  6880. return *this;
  6881. }
  6882. TheInst.reserve(6);
  6883. TheInst.emplace_back(static_cast<uint32_t>(spv::Op::OpFragmentFetchAMD));
  6884. TheInst.emplace_back(result_type);
  6885. TheInst.emplace_back(result_id);
  6886. TheInst.emplace_back(image);
  6887. TheInst.emplace_back(coordinate);
  6888. TheInst.emplace_back(fragment_index);
  6889. return *this;
  6890. }
  6891. InstBuilder &InstBuilder::opSubgroupShuffleINTEL(uint32_t result_type,
  6892. uint32_t result_id,
  6893. uint32_t data,
  6894. uint32_t invocation_id) {
  6895. if (!TheInst.empty()) {
  6896. TheStatus = Status::NestedInst;
  6897. return *this;
  6898. }
  6899. if (result_type == 0) {
  6900. TheStatus = Status::ZeroResultType;
  6901. return *this;
  6902. }
  6903. if (result_id == 0) {
  6904. TheStatus = Status::ZeroResultId;
  6905. return *this;
  6906. }
  6907. TheInst.reserve(5);
  6908. TheInst.emplace_back(static_cast<uint32_t>(spv::Op::OpSubgroupShuffleINTEL));
  6909. TheInst.emplace_back(result_type);
  6910. TheInst.emplace_back(result_id);
  6911. TheInst.emplace_back(data);
  6912. TheInst.emplace_back(invocation_id);
  6913. return *this;
  6914. }
  6915. InstBuilder &InstBuilder::opSubgroupShuffleDownINTEL(uint32_t result_type,
  6916. uint32_t result_id,
  6917. uint32_t current,
  6918. uint32_t next,
  6919. uint32_t delta) {
  6920. if (!TheInst.empty()) {
  6921. TheStatus = Status::NestedInst;
  6922. return *this;
  6923. }
  6924. if (result_type == 0) {
  6925. TheStatus = Status::ZeroResultType;
  6926. return *this;
  6927. }
  6928. if (result_id == 0) {
  6929. TheStatus = Status::ZeroResultId;
  6930. return *this;
  6931. }
  6932. TheInst.reserve(6);
  6933. TheInst.emplace_back(
  6934. static_cast<uint32_t>(spv::Op::OpSubgroupShuffleDownINTEL));
  6935. TheInst.emplace_back(result_type);
  6936. TheInst.emplace_back(result_id);
  6937. TheInst.emplace_back(current);
  6938. TheInst.emplace_back(next);
  6939. TheInst.emplace_back(delta);
  6940. return *this;
  6941. }
  6942. InstBuilder &InstBuilder::opSubgroupShuffleUpINTEL(uint32_t result_type,
  6943. uint32_t result_id,
  6944. uint32_t previous,
  6945. uint32_t current,
  6946. uint32_t delta) {
  6947. if (!TheInst.empty()) {
  6948. TheStatus = Status::NestedInst;
  6949. return *this;
  6950. }
  6951. if (result_type == 0) {
  6952. TheStatus = Status::ZeroResultType;
  6953. return *this;
  6954. }
  6955. if (result_id == 0) {
  6956. TheStatus = Status::ZeroResultId;
  6957. return *this;
  6958. }
  6959. TheInst.reserve(6);
  6960. TheInst.emplace_back(
  6961. static_cast<uint32_t>(spv::Op::OpSubgroupShuffleUpINTEL));
  6962. TheInst.emplace_back(result_type);
  6963. TheInst.emplace_back(result_id);
  6964. TheInst.emplace_back(previous);
  6965. TheInst.emplace_back(current);
  6966. TheInst.emplace_back(delta);
  6967. return *this;
  6968. }
  6969. InstBuilder &InstBuilder::opSubgroupShuffleXorINTEL(uint32_t result_type,
  6970. uint32_t result_id,
  6971. uint32_t data,
  6972. uint32_t value) {
  6973. if (!TheInst.empty()) {
  6974. TheStatus = Status::NestedInst;
  6975. return *this;
  6976. }
  6977. if (result_type == 0) {
  6978. TheStatus = Status::ZeroResultType;
  6979. return *this;
  6980. }
  6981. if (result_id == 0) {
  6982. TheStatus = Status::ZeroResultId;
  6983. return *this;
  6984. }
  6985. TheInst.reserve(5);
  6986. TheInst.emplace_back(
  6987. static_cast<uint32_t>(spv::Op::OpSubgroupShuffleXorINTEL));
  6988. TheInst.emplace_back(result_type);
  6989. TheInst.emplace_back(result_id);
  6990. TheInst.emplace_back(data);
  6991. TheInst.emplace_back(value);
  6992. return *this;
  6993. }
  6994. InstBuilder &InstBuilder::opSubgroupBlockReadINTEL(uint32_t result_type,
  6995. uint32_t result_id,
  6996. uint32_t ptr) {
  6997. if (!TheInst.empty()) {
  6998. TheStatus = Status::NestedInst;
  6999. return *this;
  7000. }
  7001. if (result_type == 0) {
  7002. TheStatus = Status::ZeroResultType;
  7003. return *this;
  7004. }
  7005. if (result_id == 0) {
  7006. TheStatus = Status::ZeroResultId;
  7007. return *this;
  7008. }
  7009. TheInst.reserve(4);
  7010. TheInst.emplace_back(
  7011. static_cast<uint32_t>(spv::Op::OpSubgroupBlockReadINTEL));
  7012. TheInst.emplace_back(result_type);
  7013. TheInst.emplace_back(result_id);
  7014. TheInst.emplace_back(ptr);
  7015. return *this;
  7016. }
  7017. InstBuilder &InstBuilder::opSubgroupBlockWriteINTEL(uint32_t ptr,
  7018. uint32_t data) {
  7019. if (!TheInst.empty()) {
  7020. TheStatus = Status::NestedInst;
  7021. return *this;
  7022. }
  7023. TheInst.reserve(3);
  7024. TheInst.emplace_back(
  7025. static_cast<uint32_t>(spv::Op::OpSubgroupBlockWriteINTEL));
  7026. TheInst.emplace_back(ptr);
  7027. TheInst.emplace_back(data);
  7028. return *this;
  7029. }
  7030. InstBuilder &InstBuilder::opSubgroupImageBlockReadINTEL(uint32_t result_type,
  7031. uint32_t result_id,
  7032. uint32_t image,
  7033. uint32_t coordinate) {
  7034. if (!TheInst.empty()) {
  7035. TheStatus = Status::NestedInst;
  7036. return *this;
  7037. }
  7038. if (result_type == 0) {
  7039. TheStatus = Status::ZeroResultType;
  7040. return *this;
  7041. }
  7042. if (result_id == 0) {
  7043. TheStatus = Status::ZeroResultId;
  7044. return *this;
  7045. }
  7046. TheInst.reserve(5);
  7047. TheInst.emplace_back(
  7048. static_cast<uint32_t>(spv::Op::OpSubgroupImageBlockReadINTEL));
  7049. TheInst.emplace_back(result_type);
  7050. TheInst.emplace_back(result_id);
  7051. TheInst.emplace_back(image);
  7052. TheInst.emplace_back(coordinate);
  7053. return *this;
  7054. }
  7055. InstBuilder &InstBuilder::opSubgroupImageBlockWriteINTEL(uint32_t image,
  7056. uint32_t coordinate,
  7057. uint32_t data) {
  7058. if (!TheInst.empty()) {
  7059. TheStatus = Status::NestedInst;
  7060. return *this;
  7061. }
  7062. TheInst.reserve(4);
  7063. TheInst.emplace_back(
  7064. static_cast<uint32_t>(spv::Op::OpSubgroupImageBlockWriteINTEL));
  7065. TheInst.emplace_back(image);
  7066. TheInst.emplace_back(coordinate);
  7067. TheInst.emplace_back(data);
  7068. return *this;
  7069. }
  7070. void InstBuilder::encodeImageOperands(spv::ImageOperandsMask value) {
  7071. if (bitEnumContains(value, spv::ImageOperandsMask::Bias)) {
  7072. Expectation.emplace_back(OperandKind::IdRef);
  7073. }
  7074. if (bitEnumContains(value, spv::ImageOperandsMask::Lod)) {
  7075. Expectation.emplace_back(OperandKind::IdRef);
  7076. }
  7077. if (bitEnumContains(value, spv::ImageOperandsMask::Grad)) {
  7078. Expectation.emplace_back(OperandKind::IdRef);
  7079. Expectation.emplace_back(OperandKind::IdRef);
  7080. }
  7081. if (bitEnumContains(value, spv::ImageOperandsMask::ConstOffset)) {
  7082. Expectation.emplace_back(OperandKind::IdRef);
  7083. }
  7084. if (bitEnumContains(value, spv::ImageOperandsMask::Offset)) {
  7085. Expectation.emplace_back(OperandKind::IdRef);
  7086. }
  7087. if (bitEnumContains(value, spv::ImageOperandsMask::ConstOffsets)) {
  7088. Expectation.emplace_back(OperandKind::IdRef);
  7089. }
  7090. if (bitEnumContains(value, spv::ImageOperandsMask::Sample)) {
  7091. Expectation.emplace_back(OperandKind::IdRef);
  7092. }
  7093. if (bitEnumContains(value, spv::ImageOperandsMask::MinLod)) {
  7094. Expectation.emplace_back(OperandKind::IdRef);
  7095. }
  7096. TheInst.emplace_back(static_cast<uint32_t>(value));
  7097. }
  7098. void InstBuilder::encodeLoopControl(spv::LoopControlMask value) {
  7099. if (bitEnumContains(value, spv::LoopControlMask::DependencyLength)) {
  7100. Expectation.emplace_back(OperandKind::LiteralInteger);
  7101. }
  7102. TheInst.emplace_back(static_cast<uint32_t>(value));
  7103. }
  7104. void InstBuilder::encodeMemoryAccess(spv::MemoryAccessMask value) {
  7105. if (bitEnumContains(value, spv::MemoryAccessMask::Aligned)) {
  7106. Expectation.emplace_back(OperandKind::LiteralInteger);
  7107. }
  7108. TheInst.emplace_back(static_cast<uint32_t>(value));
  7109. }
  7110. void InstBuilder::encodeExecutionMode(spv::ExecutionMode value) {
  7111. switch (value) {
  7112. case spv::ExecutionMode::Invocations: {
  7113. Expectation.emplace_back(OperandKind::LiteralInteger);
  7114. } break;
  7115. case spv::ExecutionMode::LocalSize: {
  7116. Expectation.emplace_back(OperandKind::LiteralInteger);
  7117. Expectation.emplace_back(OperandKind::LiteralInteger);
  7118. Expectation.emplace_back(OperandKind::LiteralInteger);
  7119. } break;
  7120. case spv::ExecutionMode::LocalSizeHint: {
  7121. Expectation.emplace_back(OperandKind::LiteralInteger);
  7122. Expectation.emplace_back(OperandKind::LiteralInteger);
  7123. Expectation.emplace_back(OperandKind::LiteralInteger);
  7124. } break;
  7125. case spv::ExecutionMode::OutputVertices: {
  7126. Expectation.emplace_back(OperandKind::LiteralInteger);
  7127. } break;
  7128. case spv::ExecutionMode::VecTypeHint: {
  7129. Expectation.emplace_back(OperandKind::LiteralInteger);
  7130. } break;
  7131. case spv::ExecutionMode::SubgroupSize: {
  7132. Expectation.emplace_back(OperandKind::LiteralInteger);
  7133. } break;
  7134. case spv::ExecutionMode::SubgroupsPerWorkgroup: {
  7135. Expectation.emplace_back(OperandKind::LiteralInteger);
  7136. } break;
  7137. case spv::ExecutionMode::SubgroupsPerWorkgroupId: {
  7138. Expectation.emplace_back(OperandKind::IdRef);
  7139. } break;
  7140. case spv::ExecutionMode::LocalSizeId: {
  7141. Expectation.emplace_back(OperandKind::IdRef);
  7142. Expectation.emplace_back(OperandKind::IdRef);
  7143. Expectation.emplace_back(OperandKind::IdRef);
  7144. } break;
  7145. case spv::ExecutionMode::LocalSizeHintId: {
  7146. Expectation.emplace_back(OperandKind::IdRef);
  7147. } break;
  7148. default:
  7149. break;
  7150. }
  7151. TheInst.emplace_back(static_cast<uint32_t>(value));
  7152. }
  7153. void InstBuilder::encodeDecoration(spv::Decoration value) {
  7154. switch (value) {
  7155. case spv::Decoration::SpecId: {
  7156. Expectation.emplace_back(OperandKind::LiteralInteger);
  7157. } break;
  7158. case spv::Decoration::ArrayStride: {
  7159. Expectation.emplace_back(OperandKind::LiteralInteger);
  7160. } break;
  7161. case spv::Decoration::MatrixStride: {
  7162. Expectation.emplace_back(OperandKind::LiteralInteger);
  7163. } break;
  7164. case spv::Decoration::BuiltIn: {
  7165. Expectation.emplace_back(OperandKind::BuiltIn);
  7166. } break;
  7167. case spv::Decoration::Stream: {
  7168. Expectation.emplace_back(OperandKind::LiteralInteger);
  7169. } break;
  7170. case spv::Decoration::Location: {
  7171. Expectation.emplace_back(OperandKind::LiteralInteger);
  7172. } break;
  7173. case spv::Decoration::Component: {
  7174. Expectation.emplace_back(OperandKind::LiteralInteger);
  7175. } break;
  7176. case spv::Decoration::Index: {
  7177. Expectation.emplace_back(OperandKind::LiteralInteger);
  7178. } break;
  7179. case spv::Decoration::Binding: {
  7180. Expectation.emplace_back(OperandKind::LiteralInteger);
  7181. } break;
  7182. case spv::Decoration::DescriptorSet: {
  7183. Expectation.emplace_back(OperandKind::LiteralInteger);
  7184. } break;
  7185. case spv::Decoration::Offset: {
  7186. Expectation.emplace_back(OperandKind::LiteralInteger);
  7187. } break;
  7188. case spv::Decoration::XfbBuffer: {
  7189. Expectation.emplace_back(OperandKind::LiteralInteger);
  7190. } break;
  7191. case spv::Decoration::XfbStride: {
  7192. Expectation.emplace_back(OperandKind::LiteralInteger);
  7193. } break;
  7194. case spv::Decoration::FuncParamAttr: {
  7195. Expectation.emplace_back(OperandKind::FunctionParameterAttribute);
  7196. } break;
  7197. case spv::Decoration::FPRoundingMode: {
  7198. Expectation.emplace_back(OperandKind::FPRoundingMode);
  7199. } break;
  7200. case spv::Decoration::FPFastMathMode: {
  7201. Expectation.emplace_back(OperandKind::FPFastMathMode);
  7202. } break;
  7203. case spv::Decoration::LinkageAttributes: {
  7204. Expectation.emplace_back(OperandKind::LiteralString);
  7205. Expectation.emplace_back(OperandKind::LinkageType);
  7206. } break;
  7207. case spv::Decoration::InputAttachmentIndex: {
  7208. Expectation.emplace_back(OperandKind::LiteralInteger);
  7209. } break;
  7210. case spv::Decoration::Alignment: {
  7211. Expectation.emplace_back(OperandKind::LiteralInteger);
  7212. } break;
  7213. case spv::Decoration::MaxByteOffset: {
  7214. Expectation.emplace_back(OperandKind::LiteralInteger);
  7215. } break;
  7216. case spv::Decoration::AlignmentId: {
  7217. Expectation.emplace_back(OperandKind::IdRef);
  7218. } break;
  7219. case spv::Decoration::MaxByteOffsetId: {
  7220. Expectation.emplace_back(OperandKind::IdRef);
  7221. } break;
  7222. case spv::Decoration::SecondaryViewportRelativeNV: {
  7223. Expectation.emplace_back(OperandKind::LiteralInteger);
  7224. } break;
  7225. default:
  7226. break;
  7227. }
  7228. TheInst.emplace_back(static_cast<uint32_t>(value));
  7229. }
  7230. InstBuilder &InstBuilder::fPFastMathMode(spv::FPFastMathModeMask value) {
  7231. if (Expectation.front() != OperandKind::FPFastMathMode) {
  7232. TheStatus = Status::ExpectFPFastMathMode;
  7233. return *this;
  7234. }
  7235. Expectation.pop_front();
  7236. TheInst.emplace_back(static_cast<uint32_t>(value));
  7237. return *this;
  7238. }
  7239. InstBuilder &InstBuilder::fPRoundingMode(spv::FPRoundingMode value) {
  7240. if (Expectation.front() != OperandKind::FPRoundingMode) {
  7241. TheStatus = Status::ExpectFPRoundingMode;
  7242. return *this;
  7243. }
  7244. Expectation.pop_front();
  7245. TheInst.emplace_back(static_cast<uint32_t>(value));
  7246. return *this;
  7247. }
  7248. InstBuilder &InstBuilder::linkageType(spv::LinkageType value) {
  7249. if (Expectation.front() != OperandKind::LinkageType) {
  7250. TheStatus = Status::ExpectLinkageType;
  7251. return *this;
  7252. }
  7253. Expectation.pop_front();
  7254. TheInst.emplace_back(static_cast<uint32_t>(value));
  7255. return *this;
  7256. }
  7257. InstBuilder &
  7258. InstBuilder::functionParameterAttribute(spv::FunctionParameterAttribute value) {
  7259. if (Expectation.front() != OperandKind::FunctionParameterAttribute) {
  7260. TheStatus = Status::ExpectFunctionParameterAttribute;
  7261. return *this;
  7262. }
  7263. Expectation.pop_front();
  7264. TheInst.emplace_back(static_cast<uint32_t>(value));
  7265. return *this;
  7266. }
  7267. InstBuilder &InstBuilder::builtIn(spv::BuiltIn value) {
  7268. if (Expectation.front() != OperandKind::BuiltIn) {
  7269. TheStatus = Status::ExpectBuiltIn;
  7270. return *this;
  7271. }
  7272. Expectation.pop_front();
  7273. TheInst.emplace_back(static_cast<uint32_t>(value));
  7274. return *this;
  7275. }
  7276. InstBuilder &InstBuilder::idRef(uint32_t value) {
  7277. if (Expectation.front() != OperandKind::IdRef) {
  7278. TheStatus = Status::ExpectIdRef;
  7279. return *this;
  7280. }
  7281. Expectation.pop_front();
  7282. TheInst.emplace_back(value);
  7283. return *this;
  7284. }
  7285. InstBuilder &InstBuilder::literalInteger(uint32_t value) {
  7286. if (Expectation.front() != OperandKind::LiteralInteger) {
  7287. TheStatus = Status::ExpectLiteralInteger;
  7288. return *this;
  7289. }
  7290. Expectation.pop_front();
  7291. TheInst.emplace_back(value);
  7292. return *this;
  7293. }
  7294. InstBuilder &InstBuilder::literalString(std::string value) {
  7295. if (Expectation.front() != OperandKind::LiteralString) {
  7296. TheStatus = Status::ExpectLiteralString;
  7297. return *this;
  7298. }
  7299. Expectation.pop_front();
  7300. encodeString(value);
  7301. return *this;
  7302. }
  7303. } // end namespace spirv
  7304. } // end namespace clang