InstBuilderAuto.cpp 254 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534253525362537253825392540254125422543254425452546254725482549255025512552255325542555255625572558255925602561256225632564256525662567256825692570257125722573257425752576257725782579258025812582258325842585258625872588258925902591259225932594259525962597259825992600260126022603260426052606260726082609261026112612261326142615261626172618261926202621262226232624262526262627262826292630263126322633263426352636263726382639264026412642264326442645264626472648264926502651265226532654265526562657265826592660266126622663266426652666266726682669267026712672267326742675267626772678267926802681268226832684268526862687268826892690269126922693269426952696269726982699270027012702270327042705270627072708270927102711271227132714271527162717271827192720272127222723272427252726272727282729273027312732273327342735273627372738273927402741274227432744274527462747274827492750275127522753275427552756275727582759276027612762276327642765276627672768276927702771277227732774277527762777277827792780278127822783278427852786278727882789279027912792279327942795279627972798279928002801280228032804280528062807280828092810281128122813281428152816281728182819282028212822282328242825282628272828282928302831283228332834283528362837283828392840284128422843284428452846284728482849285028512852285328542855285628572858285928602861286228632864286528662867286828692870287128722873287428752876287728782879288028812882288328842885288628872888288928902891289228932894289528962897289828992900290129022903290429052906290729082909291029112912291329142915291629172918291929202921292229232924292529262927292829292930293129322933293429352936293729382939294029412942294329442945294629472948294929502951295229532954295529562957295829592960296129622963296429652966296729682969297029712972297329742975297629772978297929802981298229832984298529862987298829892990299129922993299429952996299729982999300030013002300330043005300630073008300930103011301230133014301530163017301830193020302130223023302430253026302730283029303030313032303330343035303630373038303930403041304230433044304530463047304830493050305130523053305430553056305730583059306030613062306330643065306630673068306930703071307230733074307530763077307830793080308130823083308430853086308730883089309030913092309330943095309630973098309931003101310231033104310531063107310831093110311131123113311431153116311731183119312031213122312331243125312631273128312931303131313231333134313531363137313831393140314131423143314431453146314731483149315031513152315331543155315631573158315931603161316231633164316531663167316831693170317131723173317431753176317731783179318031813182318331843185318631873188318931903191319231933194319531963197319831993200320132023203320432053206320732083209321032113212321332143215321632173218321932203221322232233224322532263227322832293230323132323233323432353236323732383239324032413242324332443245324632473248324932503251325232533254325532563257325832593260326132623263326432653266326732683269327032713272327332743275327632773278327932803281328232833284328532863287328832893290329132923293329432953296329732983299330033013302330333043305330633073308330933103311331233133314331533163317331833193320332133223323332433253326332733283329333033313332333333343335333633373338333933403341334233433344334533463347334833493350335133523353335433553356335733583359336033613362336333643365336633673368336933703371337233733374337533763377337833793380338133823383338433853386338733883389339033913392339333943395339633973398339934003401340234033404340534063407340834093410341134123413341434153416341734183419342034213422342334243425342634273428342934303431343234333434343534363437343834393440344134423443344434453446344734483449345034513452345334543455345634573458345934603461346234633464346534663467346834693470347134723473347434753476347734783479348034813482348334843485348634873488348934903491349234933494349534963497349834993500350135023503350435053506350735083509351035113512351335143515351635173518351935203521352235233524352535263527352835293530353135323533353435353536353735383539354035413542354335443545354635473548354935503551355235533554355535563557355835593560356135623563356435653566356735683569357035713572357335743575357635773578357935803581358235833584358535863587358835893590359135923593359435953596359735983599360036013602360336043605360636073608360936103611361236133614361536163617361836193620362136223623362436253626362736283629363036313632363336343635363636373638363936403641364236433644364536463647364836493650365136523653365436553656365736583659366036613662366336643665366636673668366936703671367236733674367536763677367836793680368136823683368436853686368736883689369036913692369336943695369636973698369937003701370237033704370537063707370837093710371137123713371437153716371737183719372037213722372337243725372637273728372937303731373237333734373537363737373837393740374137423743374437453746374737483749375037513752375337543755375637573758375937603761376237633764376537663767376837693770377137723773377437753776377737783779378037813782378337843785378637873788378937903791379237933794379537963797379837993800380138023803380438053806380738083809381038113812381338143815381638173818381938203821382238233824382538263827382838293830383138323833383438353836383738383839384038413842384338443845384638473848384938503851385238533854385538563857385838593860386138623863386438653866386738683869387038713872387338743875387638773878387938803881388238833884388538863887388838893890389138923893389438953896389738983899390039013902390339043905390639073908390939103911391239133914391539163917391839193920392139223923392439253926392739283929393039313932393339343935393639373938393939403941394239433944394539463947394839493950395139523953395439553956395739583959396039613962396339643965396639673968396939703971397239733974397539763977397839793980398139823983398439853986398739883989399039913992399339943995399639973998399940004001400240034004400540064007400840094010401140124013401440154016401740184019402040214022402340244025402640274028402940304031403240334034403540364037403840394040404140424043404440454046404740484049405040514052405340544055405640574058405940604061406240634064406540664067406840694070407140724073407440754076407740784079408040814082408340844085408640874088408940904091409240934094409540964097409840994100410141024103410441054106410741084109411041114112411341144115411641174118411941204121412241234124412541264127412841294130413141324133413441354136413741384139414041414142414341444145414641474148414941504151415241534154415541564157415841594160416141624163416441654166416741684169417041714172417341744175417641774178417941804181418241834184418541864187418841894190419141924193419441954196419741984199420042014202420342044205420642074208420942104211421242134214421542164217421842194220422142224223422442254226422742284229423042314232423342344235423642374238423942404241424242434244424542464247424842494250425142524253425442554256425742584259426042614262426342644265426642674268426942704271427242734274427542764277427842794280428142824283428442854286428742884289429042914292429342944295429642974298429943004301430243034304430543064307430843094310431143124313431443154316431743184319432043214322432343244325432643274328432943304331433243334334433543364337433843394340434143424343434443454346434743484349435043514352435343544355435643574358435943604361436243634364436543664367436843694370437143724373437443754376437743784379438043814382438343844385438643874388438943904391439243934394439543964397439843994400440144024403440444054406440744084409441044114412441344144415441644174418441944204421442244234424442544264427442844294430443144324433443444354436443744384439444044414442444344444445444644474448444944504451445244534454445544564457445844594460446144624463446444654466446744684469447044714472447344744475447644774478447944804481448244834484448544864487448844894490449144924493449444954496449744984499450045014502450345044505450645074508450945104511451245134514451545164517451845194520452145224523452445254526452745284529453045314532453345344535453645374538453945404541454245434544454545464547454845494550455145524553455445554556455745584559456045614562456345644565456645674568456945704571457245734574457545764577457845794580458145824583458445854586458745884589459045914592459345944595459645974598459946004601460246034604460546064607460846094610461146124613461446154616461746184619462046214622462346244625462646274628462946304631463246334634463546364637463846394640464146424643464446454646464746484649465046514652465346544655465646574658465946604661466246634664466546664667466846694670467146724673467446754676467746784679468046814682468346844685468646874688468946904691469246934694469546964697469846994700470147024703470447054706470747084709471047114712471347144715471647174718471947204721472247234724472547264727472847294730473147324733473447354736473747384739474047414742474347444745474647474748474947504751475247534754475547564757475847594760476147624763476447654766476747684769477047714772477347744775477647774778477947804781478247834784478547864787478847894790479147924793479447954796479747984799480048014802480348044805480648074808480948104811481248134814481548164817481848194820482148224823482448254826482748284829483048314832483348344835483648374838483948404841484248434844484548464847484848494850485148524853485448554856485748584859486048614862486348644865486648674868486948704871487248734874487548764877487848794880488148824883488448854886488748884889489048914892489348944895489648974898489949004901490249034904490549064907490849094910491149124913491449154916491749184919492049214922492349244925492649274928492949304931493249334934493549364937493849394940494149424943494449454946494749484949495049514952495349544955495649574958495949604961496249634964496549664967496849694970497149724973497449754976497749784979498049814982498349844985498649874988498949904991499249934994499549964997499849995000500150025003500450055006500750085009501050115012501350145015501650175018501950205021502250235024502550265027502850295030503150325033503450355036503750385039504050415042504350445045504650475048504950505051505250535054505550565057505850595060506150625063506450655066506750685069507050715072507350745075507650775078507950805081508250835084508550865087508850895090509150925093509450955096509750985099510051015102510351045105510651075108510951105111511251135114511551165117511851195120512151225123512451255126512751285129513051315132513351345135513651375138513951405141514251435144514551465147514851495150515151525153515451555156515751585159516051615162516351645165516651675168516951705171517251735174517551765177517851795180518151825183518451855186518751885189519051915192519351945195519651975198519952005201520252035204520552065207520852095210521152125213521452155216521752185219522052215222522352245225522652275228522952305231523252335234523552365237523852395240524152425243524452455246524752485249525052515252525352545255525652575258525952605261526252635264526552665267526852695270527152725273527452755276527752785279528052815282528352845285528652875288528952905291529252935294529552965297529852995300530153025303530453055306530753085309531053115312531353145315531653175318531953205321532253235324532553265327532853295330533153325333533453355336533753385339534053415342534353445345534653475348534953505351535253535354535553565357535853595360536153625363536453655366536753685369537053715372537353745375537653775378537953805381538253835384538553865387538853895390539153925393539453955396539753985399540054015402540354045405540654075408540954105411541254135414541554165417541854195420542154225423542454255426542754285429543054315432543354345435543654375438543954405441544254435444544554465447544854495450545154525453545454555456545754585459546054615462546354645465546654675468546954705471547254735474547554765477547854795480548154825483548454855486548754885489549054915492549354945495549654975498549955005501550255035504550555065507550855095510551155125513551455155516551755185519552055215522552355245525552655275528552955305531553255335534553555365537553855395540554155425543554455455546554755485549555055515552555355545555555655575558555955605561556255635564556555665567556855695570557155725573557455755576557755785579558055815582558355845585558655875588558955905591559255935594559555965597559855995600560156025603560456055606560756085609561056115612561356145615561656175618561956205621562256235624562556265627562856295630563156325633563456355636563756385639564056415642564356445645564656475648564956505651565256535654565556565657565856595660566156625663566456655666566756685669567056715672567356745675567656775678567956805681568256835684568556865687568856895690569156925693569456955696569756985699570057015702570357045705570657075708570957105711571257135714571557165717571857195720572157225723572457255726572757285729573057315732573357345735573657375738573957405741574257435744574557465747574857495750575157525753575457555756575757585759576057615762576357645765576657675768576957705771577257735774577557765777577857795780578157825783578457855786578757885789579057915792579357945795579657975798579958005801580258035804580558065807580858095810581158125813581458155816581758185819582058215822582358245825582658275828582958305831583258335834583558365837583858395840584158425843584458455846584758485849585058515852585358545855585658575858585958605861586258635864586558665867586858695870587158725873587458755876587758785879588058815882588358845885588658875888588958905891589258935894589558965897589858995900590159025903590459055906590759085909591059115912591359145915591659175918591959205921592259235924592559265927592859295930593159325933593459355936593759385939594059415942594359445945594659475948594959505951595259535954595559565957595859595960596159625963596459655966596759685969597059715972597359745975597659775978597959805981598259835984598559865987598859895990599159925993599459955996599759985999600060016002600360046005600660076008600960106011601260136014601560166017601860196020602160226023602460256026602760286029603060316032603360346035603660376038603960406041604260436044604560466047604860496050605160526053605460556056605760586059606060616062606360646065606660676068606960706071607260736074607560766077607860796080608160826083608460856086608760886089609060916092609360946095609660976098609961006101610261036104610561066107610861096110611161126113611461156116611761186119612061216122612361246125612661276128612961306131613261336134613561366137613861396140614161426143614461456146614761486149615061516152615361546155615661576158615961606161616261636164616561666167616861696170617161726173617461756176617761786179618061816182618361846185618661876188618961906191619261936194619561966197619861996200620162026203620462056206620762086209621062116212621362146215621662176218621962206221622262236224622562266227622862296230623162326233623462356236623762386239624062416242624362446245624662476248624962506251625262536254625562566257625862596260626162626263626462656266626762686269627062716272627362746275627662776278627962806281628262836284628562866287628862896290629162926293629462956296629762986299630063016302630363046305630663076308630963106311631263136314631563166317631863196320632163226323632463256326632763286329633063316332633363346335633663376338633963406341634263436344634563466347634863496350635163526353635463556356635763586359636063616362636363646365636663676368636963706371637263736374637563766377637863796380638163826383638463856386638763886389639063916392639363946395639663976398639964006401640264036404640564066407640864096410641164126413641464156416641764186419642064216422642364246425642664276428642964306431643264336434643564366437643864396440644164426443644464456446644764486449645064516452645364546455645664576458645964606461646264636464646564666467646864696470647164726473647464756476647764786479648064816482648364846485648664876488648964906491649264936494649564966497649864996500650165026503650465056506650765086509651065116512651365146515651665176518651965206521652265236524652565266527652865296530653165326533653465356536653765386539654065416542654365446545654665476548654965506551655265536554655565566557655865596560656165626563656465656566656765686569657065716572657365746575657665776578657965806581658265836584658565866587658865896590659165926593659465956596659765986599660066016602660366046605660666076608660966106611661266136614661566166617661866196620662166226623662466256626662766286629663066316632663366346635663666376638663966406641664266436644664566466647664866496650665166526653665466556656665766586659666066616662666366646665666666676668666966706671667266736674667566766677667866796680668166826683668466856686668766886689669066916692669366946695669666976698669967006701670267036704670567066707670867096710671167126713671467156716671767186719672067216722672367246725672667276728672967306731673267336734673567366737673867396740674167426743674467456746674767486749675067516752675367546755675667576758675967606761676267636764676567666767676867696770677167726773677467756776677767786779678067816782678367846785678667876788678967906791679267936794679567966797679867996800680168026803680468056806680768086809681068116812681368146815681668176818681968206821682268236824682568266827682868296830683168326833683468356836683768386839684068416842684368446845684668476848684968506851685268536854685568566857685868596860686168626863686468656866686768686869687068716872687368746875687668776878687968806881688268836884688568866887688868896890689168926893689468956896689768986899690069016902690369046905690669076908690969106911691269136914691569166917691869196920692169226923692469256926692769286929693069316932693369346935693669376938693969406941694269436944694569466947694869496950695169526953695469556956695769586959696069616962696369646965696669676968696969706971697269736974697569766977697869796980698169826983698469856986698769886989699069916992699369946995699669976998699970007001700270037004700570067007700870097010701170127013701470157016701770187019702070217022702370247025702670277028702970307031703270337034703570367037703870397040704170427043704470457046704770487049705070517052705370547055705670577058705970607061706270637064706570667067706870697070707170727073707470757076707770787079708070817082708370847085708670877088708970907091709270937094709570967097709870997100710171027103710471057106710771087109711071117112711371147115711671177118711971207121712271237124712571267127712871297130713171327133713471357136713771387139714071417142714371447145714671477148714971507151715271537154715571567157715871597160716171627163716471657166716771687169717071717172717371747175717671777178717971807181718271837184718571867187718871897190719171927193719471957196719771987199720072017202720372047205720672077208720972107211721272137214721572167217721872197220722172227223722472257226722772287229723072317232723372347235723672377238723972407241724272437244724572467247724872497250725172527253725472557256725772587259726072617262726372647265726672677268726972707271727272737274727572767277727872797280728172827283728472857286728772887289729072917292729372947295729672977298729973007301730273037304730573067307730873097310731173127313731473157316731773187319732073217322732373247325732673277328732973307331733273337334733573367337733873397340734173427343734473457346734773487349735073517352735373547355735673577358735973607361736273637364736573667367736873697370737173727373737473757376737773787379738073817382738373847385738673877388738973907391739273937394739573967397739873997400740174027403740474057406740774087409741074117412741374147415741674177418741974207421742274237424742574267427742874297430743174327433743474357436743774387439744074417442744374447445744674477448744974507451745274537454745574567457745874597460746174627463746474657466746774687469747074717472747374747475747674777478747974807481748274837484748574867487748874897490749174927493749474957496749774987499750075017502750375047505750675077508750975107511751275137514751575167517751875197520752175227523752475257526752775287529753075317532753375347535753675377538753975407541754275437544754575467547754875497550755175527553755475557556755775587559756075617562756375647565756675677568756975707571757275737574757575767577757875797580758175827583758475857586758775887589759075917592759375947595759675977598759976007601760276037604760576067607760876097610761176127613761476157616761776187619762076217622762376247625762676277628762976307631763276337634763576367637763876397640764176427643764476457646764776487649765076517652765376547655765676577658765976607661766276637664766576667667766876697670767176727673767476757676767776787679768076817682768376847685768676877688768976907691769276937694769576967697769876997700770177027703770477057706770777087709771077117712771377147715771677177718771977207721772277237724772577267727772877297730773177327733773477357736773777387739774077417742774377447745774677477748774977507751775277537754775577567757775877597760776177627763776477657766776777687769777077717772777377747775777677777778777977807781778277837784778577867787778877897790779177927793779477957796779777987799780078017802780378047805780678077808780978107811781278137814781578167817781878197820782178227823782478257826782778287829783078317832783378347835783678377838783978407841784278437844784578467847784878497850785178527853785478557856785778587859786078617862786378647865786678677868786978707871787278737874787578767877787878797880788178827883788478857886788778887889789078917892789378947895789678977898789979007901790279037904790579067907790879097910791179127913791479157916791779187919792079217922792379247925792679277928792979307931793279337934793579367937793879397940794179427943794479457946794779487949795079517952795379547955795679577958795979607961796279637964796579667967796879697970797179727973797479757976797779787979798079817982798379847985798679877988798979907991799279937994799579967997799879998000800180028003800480058006800780088009801080118012801380148015801680178018801980208021802280238024802580268027802880298030803180328033803480358036803780388039804080418042804380448045804680478048804980508051805280538054805580568057805880598060806180628063806480658066806780688069807080718072807380748075807680778078807980808081808280838084808580868087808880898090809180928093809480958096809780988099810081018102810381048105810681078108810981108111811281138114811581168117811881198120812181228123812481258126812781288129813081318132813381348135813681378138813981408141814281438144814581468147814881498150815181528153815481558156815781588159816081618162816381648165816681678168816981708171817281738174817581768177817881798180818181828183818481858186818781888189819081918192819381948195819681978198819982008201820282038204820582068207820882098210821182128213821482158216821782188219822082218222822382248225822682278228822982308231823282338234823582368237823882398240824182428243824482458246824782488249825082518252825382548255825682578258825982608261826282638264826582668267826882698270827182728273827482758276827782788279828082818282828382848285828682878288828982908291829282938294829582968297829882998300830183028303830483058306830783088309831083118312831383148315831683178318831983208321832283238324832583268327832883298330833183328333833483358336833783388339834083418342834383448345834683478348834983508351835283538354835583568357835883598360836183628363836483658366836783688369837083718372837383748375837683778378837983808381838283838384838583868387838883898390839183928393839483958396839783988399840084018402840384048405840684078408840984108411841284138414841584168417841884198420842184228423842484258426842784288429843084318432843384348435843684378438843984408441844284438444844584468447844884498450845184528453845484558456845784588459846084618462846384648465846684678468846984708471847284738474847584768477847884798480848184828483848484858486848784888489849084918492849384948495849684978498849985008501850285038504850585068507850885098510851185128513851485158516851785188519852085218522852385248525852685278528852985308531853285338534853585368537853885398540854185428543854485458546854785488549855085518552855385548555855685578558855985608561856285638564856585668567856885698570857185728573857485758576857785788579858085818582858385848585858685878588858985908591859285938594859585968597859885998600860186028603860486058606860786088609861086118612861386148615861686178618861986208621862286238624862586268627862886298630863186328633863486358636863786388639864086418642864386448645864686478648864986508651865286538654865586568657865886598660866186628663866486658666866786688669867086718672867386748675867686778678867986808681868286838684868586868687868886898690869186928693869486958696869786988699870087018702870387048705870687078708870987108711871287138714871587168717871887198720872187228723872487258726872787288729873087318732873387348735873687378738873987408741874287438744874587468747874887498750875187528753875487558756875787588759876087618762876387648765876687678768876987708771877287738774877587768777877887798780878187828783878487858786878787888789879087918792879387948795879687978798879988008801880288038804880588068807880888098810881188128813881488158816881788188819882088218822882388248825882688278828882988308831883288338834883588368837883888398840884188428843884488458846884788488849885088518852885388548855885688578858885988608861886288638864886588668867886888698870887188728873887488758876887788788879888088818882888388848885888688878888888988908891889288938894889588968897889888998900890189028903890489058906890789088909891089118912891389148915891689178918891989208921892289238924892589268927892889298930893189328933893489358936893789388939894089418942894389448945894689478948894989508951895289538954895589568957895889598960896189628963896489658966896789688969897089718972897389748975897689778978897989808981898289838984898589868987898889898990899189928993899489958996899789988999900090019002900390049005900690079008900990109011901290139014901590169017901890199020902190229023902490259026902790289029903090319032903390349035903690379038903990409041904290439044904590469047904890499050905190529053905490559056905790589059906090619062906390649065906690679068906990709071907290739074907590769077907890799080908190829083908490859086908790889089909090919092909390949095909690979098909991009101910291039104910591069107910891099110911191129113911491159116911791189119912091219122912391249125912691279128912991309131913291339134913591369137913891399140914191429143914491459146914791489149915091519152915391549155915691579158915991609161916291639164916591669167916891699170917191729173917491759176917791789179918091819182918391849185918691879188918991909191919291939194919591969197919891999200920192029203920492059206920792089209921092119212921392149215921692179218921992209221922292239224922592269227922892299230923192329233923492359236923792389239924092419242924392449245924692479248924992509251925292539254925592569257925892599260926192629263926492659266926792689269927092719272927392749275927692779278927992809281928292839284928592869287928892899290929192929293929492959296929792989299930093019302930393049305930693079308930993109311931293139314931593169317931893199320932193229323932493259326932793289329933093319332933393349335933693379338933993409341934293439344934593469347934893499350935193529353935493559356935793589359936093619362936393649365936693679368936993709371937293739374937593769377937893799380938193829383938493859386
  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 == 0x00010300 && spv::Revision == 1,
  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::opGroupNonUniformElect(uint32_t result_type,
  6507. uint32_t result_id,
  6508. uint32_t execution) {
  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::OpGroupNonUniformElect));
  6523. TheInst.emplace_back(result_type);
  6524. TheInst.emplace_back(result_id);
  6525. TheInst.emplace_back(execution);
  6526. return *this;
  6527. }
  6528. InstBuilder &InstBuilder::opGroupNonUniformAll(uint32_t result_type,
  6529. uint32_t result_id,
  6530. uint32_t execution,
  6531. uint32_t predicate) {
  6532. if (!TheInst.empty()) {
  6533. TheStatus = Status::NestedInst;
  6534. return *this;
  6535. }
  6536. if (result_type == 0) {
  6537. TheStatus = Status::ZeroResultType;
  6538. return *this;
  6539. }
  6540. if (result_id == 0) {
  6541. TheStatus = Status::ZeroResultId;
  6542. return *this;
  6543. }
  6544. TheInst.reserve(5);
  6545. TheInst.emplace_back(static_cast<uint32_t>(spv::Op::OpGroupNonUniformAll));
  6546. TheInst.emplace_back(result_type);
  6547. TheInst.emplace_back(result_id);
  6548. TheInst.emplace_back(execution);
  6549. TheInst.emplace_back(predicate);
  6550. return *this;
  6551. }
  6552. InstBuilder &InstBuilder::opGroupNonUniformAny(uint32_t result_type,
  6553. uint32_t result_id,
  6554. uint32_t execution,
  6555. uint32_t predicate) {
  6556. if (!TheInst.empty()) {
  6557. TheStatus = Status::NestedInst;
  6558. return *this;
  6559. }
  6560. if (result_type == 0) {
  6561. TheStatus = Status::ZeroResultType;
  6562. return *this;
  6563. }
  6564. if (result_id == 0) {
  6565. TheStatus = Status::ZeroResultId;
  6566. return *this;
  6567. }
  6568. TheInst.reserve(5);
  6569. TheInst.emplace_back(static_cast<uint32_t>(spv::Op::OpGroupNonUniformAny));
  6570. TheInst.emplace_back(result_type);
  6571. TheInst.emplace_back(result_id);
  6572. TheInst.emplace_back(execution);
  6573. TheInst.emplace_back(predicate);
  6574. return *this;
  6575. }
  6576. InstBuilder &InstBuilder::opGroupNonUniformAllEqual(uint32_t result_type,
  6577. uint32_t result_id,
  6578. uint32_t execution,
  6579. uint32_t value) {
  6580. if (!TheInst.empty()) {
  6581. TheStatus = Status::NestedInst;
  6582. return *this;
  6583. }
  6584. if (result_type == 0) {
  6585. TheStatus = Status::ZeroResultType;
  6586. return *this;
  6587. }
  6588. if (result_id == 0) {
  6589. TheStatus = Status::ZeroResultId;
  6590. return *this;
  6591. }
  6592. TheInst.reserve(5);
  6593. TheInst.emplace_back(
  6594. static_cast<uint32_t>(spv::Op::OpGroupNonUniformAllEqual));
  6595. TheInst.emplace_back(result_type);
  6596. TheInst.emplace_back(result_id);
  6597. TheInst.emplace_back(execution);
  6598. TheInst.emplace_back(value);
  6599. return *this;
  6600. }
  6601. InstBuilder &InstBuilder::opGroupNonUniformBroadcast(uint32_t result_type,
  6602. uint32_t result_id,
  6603. uint32_t execution,
  6604. uint32_t value,
  6605. uint32_t id) {
  6606. if (!TheInst.empty()) {
  6607. TheStatus = Status::NestedInst;
  6608. return *this;
  6609. }
  6610. if (result_type == 0) {
  6611. TheStatus = Status::ZeroResultType;
  6612. return *this;
  6613. }
  6614. if (result_id == 0) {
  6615. TheStatus = Status::ZeroResultId;
  6616. return *this;
  6617. }
  6618. TheInst.reserve(6);
  6619. TheInst.emplace_back(
  6620. static_cast<uint32_t>(spv::Op::OpGroupNonUniformBroadcast));
  6621. TheInst.emplace_back(result_type);
  6622. TheInst.emplace_back(result_id);
  6623. TheInst.emplace_back(execution);
  6624. TheInst.emplace_back(value);
  6625. TheInst.emplace_back(id);
  6626. return *this;
  6627. }
  6628. InstBuilder &InstBuilder::opGroupNonUniformBroadcastFirst(uint32_t result_type,
  6629. uint32_t result_id,
  6630. uint32_t execution,
  6631. uint32_t value) {
  6632. if (!TheInst.empty()) {
  6633. TheStatus = Status::NestedInst;
  6634. return *this;
  6635. }
  6636. if (result_type == 0) {
  6637. TheStatus = Status::ZeroResultType;
  6638. return *this;
  6639. }
  6640. if (result_id == 0) {
  6641. TheStatus = Status::ZeroResultId;
  6642. return *this;
  6643. }
  6644. TheInst.reserve(5);
  6645. TheInst.emplace_back(
  6646. static_cast<uint32_t>(spv::Op::OpGroupNonUniformBroadcastFirst));
  6647. TheInst.emplace_back(result_type);
  6648. TheInst.emplace_back(result_id);
  6649. TheInst.emplace_back(execution);
  6650. TheInst.emplace_back(value);
  6651. return *this;
  6652. }
  6653. InstBuilder &InstBuilder::opGroupNonUniformBallot(uint32_t result_type,
  6654. uint32_t result_id,
  6655. uint32_t execution,
  6656. uint32_t predicate) {
  6657. if (!TheInst.empty()) {
  6658. TheStatus = Status::NestedInst;
  6659. return *this;
  6660. }
  6661. if (result_type == 0) {
  6662. TheStatus = Status::ZeroResultType;
  6663. return *this;
  6664. }
  6665. if (result_id == 0) {
  6666. TheStatus = Status::ZeroResultId;
  6667. return *this;
  6668. }
  6669. TheInst.reserve(5);
  6670. TheInst.emplace_back(static_cast<uint32_t>(spv::Op::OpGroupNonUniformBallot));
  6671. TheInst.emplace_back(result_type);
  6672. TheInst.emplace_back(result_id);
  6673. TheInst.emplace_back(execution);
  6674. TheInst.emplace_back(predicate);
  6675. return *this;
  6676. }
  6677. InstBuilder &InstBuilder::opGroupNonUniformInverseBallot(uint32_t result_type,
  6678. uint32_t result_id,
  6679. uint32_t execution,
  6680. uint32_t value) {
  6681. if (!TheInst.empty()) {
  6682. TheStatus = Status::NestedInst;
  6683. return *this;
  6684. }
  6685. if (result_type == 0) {
  6686. TheStatus = Status::ZeroResultType;
  6687. return *this;
  6688. }
  6689. if (result_id == 0) {
  6690. TheStatus = Status::ZeroResultId;
  6691. return *this;
  6692. }
  6693. TheInst.reserve(5);
  6694. TheInst.emplace_back(
  6695. static_cast<uint32_t>(spv::Op::OpGroupNonUniformInverseBallot));
  6696. TheInst.emplace_back(result_type);
  6697. TheInst.emplace_back(result_id);
  6698. TheInst.emplace_back(execution);
  6699. TheInst.emplace_back(value);
  6700. return *this;
  6701. }
  6702. InstBuilder &InstBuilder::opGroupNonUniformBallotBitExtract(
  6703. uint32_t result_type, uint32_t result_id, uint32_t execution,
  6704. uint32_t value, uint32_t index) {
  6705. if (!TheInst.empty()) {
  6706. TheStatus = Status::NestedInst;
  6707. return *this;
  6708. }
  6709. if (result_type == 0) {
  6710. TheStatus = Status::ZeroResultType;
  6711. return *this;
  6712. }
  6713. if (result_id == 0) {
  6714. TheStatus = Status::ZeroResultId;
  6715. return *this;
  6716. }
  6717. TheInst.reserve(6);
  6718. TheInst.emplace_back(
  6719. static_cast<uint32_t>(spv::Op::OpGroupNonUniformBallotBitExtract));
  6720. TheInst.emplace_back(result_type);
  6721. TheInst.emplace_back(result_id);
  6722. TheInst.emplace_back(execution);
  6723. TheInst.emplace_back(value);
  6724. TheInst.emplace_back(index);
  6725. return *this;
  6726. }
  6727. InstBuilder &InstBuilder::opGroupNonUniformBallotBitCount(
  6728. uint32_t result_type, uint32_t result_id, uint32_t execution,
  6729. spv::GroupOperation operation, uint32_t value) {
  6730. if (!TheInst.empty()) {
  6731. TheStatus = Status::NestedInst;
  6732. return *this;
  6733. }
  6734. if (result_type == 0) {
  6735. TheStatus = Status::ZeroResultType;
  6736. return *this;
  6737. }
  6738. if (result_id == 0) {
  6739. TheStatus = Status::ZeroResultId;
  6740. return *this;
  6741. }
  6742. TheInst.reserve(6);
  6743. TheInst.emplace_back(
  6744. static_cast<uint32_t>(spv::Op::OpGroupNonUniformBallotBitCount));
  6745. TheInst.emplace_back(result_type);
  6746. TheInst.emplace_back(result_id);
  6747. TheInst.emplace_back(execution);
  6748. TheInst.emplace_back(static_cast<uint32_t>(operation));
  6749. TheInst.emplace_back(value);
  6750. return *this;
  6751. }
  6752. InstBuilder &InstBuilder::opGroupNonUniformBallotFindLSB(uint32_t result_type,
  6753. uint32_t result_id,
  6754. uint32_t execution,
  6755. uint32_t value) {
  6756. if (!TheInst.empty()) {
  6757. TheStatus = Status::NestedInst;
  6758. return *this;
  6759. }
  6760. if (result_type == 0) {
  6761. TheStatus = Status::ZeroResultType;
  6762. return *this;
  6763. }
  6764. if (result_id == 0) {
  6765. TheStatus = Status::ZeroResultId;
  6766. return *this;
  6767. }
  6768. TheInst.reserve(5);
  6769. TheInst.emplace_back(
  6770. static_cast<uint32_t>(spv::Op::OpGroupNonUniformBallotFindLSB));
  6771. TheInst.emplace_back(result_type);
  6772. TheInst.emplace_back(result_id);
  6773. TheInst.emplace_back(execution);
  6774. TheInst.emplace_back(value);
  6775. return *this;
  6776. }
  6777. InstBuilder &InstBuilder::opGroupNonUniformBallotFindMSB(uint32_t result_type,
  6778. uint32_t result_id,
  6779. uint32_t execution,
  6780. uint32_t value) {
  6781. if (!TheInst.empty()) {
  6782. TheStatus = Status::NestedInst;
  6783. return *this;
  6784. }
  6785. if (result_type == 0) {
  6786. TheStatus = Status::ZeroResultType;
  6787. return *this;
  6788. }
  6789. if (result_id == 0) {
  6790. TheStatus = Status::ZeroResultId;
  6791. return *this;
  6792. }
  6793. TheInst.reserve(5);
  6794. TheInst.emplace_back(
  6795. static_cast<uint32_t>(spv::Op::OpGroupNonUniformBallotFindMSB));
  6796. TheInst.emplace_back(result_type);
  6797. TheInst.emplace_back(result_id);
  6798. TheInst.emplace_back(execution);
  6799. TheInst.emplace_back(value);
  6800. return *this;
  6801. }
  6802. InstBuilder &InstBuilder::opGroupNonUniformShuffle(uint32_t result_type,
  6803. uint32_t result_id,
  6804. uint32_t execution,
  6805. uint32_t value,
  6806. uint32_t id) {
  6807. if (!TheInst.empty()) {
  6808. TheStatus = Status::NestedInst;
  6809. return *this;
  6810. }
  6811. if (result_type == 0) {
  6812. TheStatus = Status::ZeroResultType;
  6813. return *this;
  6814. }
  6815. if (result_id == 0) {
  6816. TheStatus = Status::ZeroResultId;
  6817. return *this;
  6818. }
  6819. TheInst.reserve(6);
  6820. TheInst.emplace_back(
  6821. static_cast<uint32_t>(spv::Op::OpGroupNonUniformShuffle));
  6822. TheInst.emplace_back(result_type);
  6823. TheInst.emplace_back(result_id);
  6824. TheInst.emplace_back(execution);
  6825. TheInst.emplace_back(value);
  6826. TheInst.emplace_back(id);
  6827. return *this;
  6828. }
  6829. InstBuilder &InstBuilder::opGroupNonUniformShuffleXor(uint32_t result_type,
  6830. uint32_t result_id,
  6831. uint32_t execution,
  6832. uint32_t value,
  6833. uint32_t mask) {
  6834. if (!TheInst.empty()) {
  6835. TheStatus = Status::NestedInst;
  6836. return *this;
  6837. }
  6838. if (result_type == 0) {
  6839. TheStatus = Status::ZeroResultType;
  6840. return *this;
  6841. }
  6842. if (result_id == 0) {
  6843. TheStatus = Status::ZeroResultId;
  6844. return *this;
  6845. }
  6846. TheInst.reserve(6);
  6847. TheInst.emplace_back(
  6848. static_cast<uint32_t>(spv::Op::OpGroupNonUniformShuffleXor));
  6849. TheInst.emplace_back(result_type);
  6850. TheInst.emplace_back(result_id);
  6851. TheInst.emplace_back(execution);
  6852. TheInst.emplace_back(value);
  6853. TheInst.emplace_back(mask);
  6854. return *this;
  6855. }
  6856. InstBuilder &InstBuilder::opGroupNonUniformShuffleUp(uint32_t result_type,
  6857. uint32_t result_id,
  6858. uint32_t execution,
  6859. uint32_t value,
  6860. uint32_t delta) {
  6861. if (!TheInst.empty()) {
  6862. TheStatus = Status::NestedInst;
  6863. return *this;
  6864. }
  6865. if (result_type == 0) {
  6866. TheStatus = Status::ZeroResultType;
  6867. return *this;
  6868. }
  6869. if (result_id == 0) {
  6870. TheStatus = Status::ZeroResultId;
  6871. return *this;
  6872. }
  6873. TheInst.reserve(6);
  6874. TheInst.emplace_back(
  6875. static_cast<uint32_t>(spv::Op::OpGroupNonUniformShuffleUp));
  6876. TheInst.emplace_back(result_type);
  6877. TheInst.emplace_back(result_id);
  6878. TheInst.emplace_back(execution);
  6879. TheInst.emplace_back(value);
  6880. TheInst.emplace_back(delta);
  6881. return *this;
  6882. }
  6883. InstBuilder &InstBuilder::opGroupNonUniformShuffleDown(uint32_t result_type,
  6884. uint32_t result_id,
  6885. uint32_t execution,
  6886. uint32_t value,
  6887. uint32_t delta) {
  6888. if (!TheInst.empty()) {
  6889. TheStatus = Status::NestedInst;
  6890. return *this;
  6891. }
  6892. if (result_type == 0) {
  6893. TheStatus = Status::ZeroResultType;
  6894. return *this;
  6895. }
  6896. if (result_id == 0) {
  6897. TheStatus = Status::ZeroResultId;
  6898. return *this;
  6899. }
  6900. TheInst.reserve(6);
  6901. TheInst.emplace_back(
  6902. static_cast<uint32_t>(spv::Op::OpGroupNonUniformShuffleDown));
  6903. TheInst.emplace_back(result_type);
  6904. TheInst.emplace_back(result_id);
  6905. TheInst.emplace_back(execution);
  6906. TheInst.emplace_back(value);
  6907. TheInst.emplace_back(delta);
  6908. return *this;
  6909. }
  6910. InstBuilder &InstBuilder::opGroupNonUniformIAdd(
  6911. uint32_t result_type, uint32_t result_id, uint32_t execution,
  6912. spv::GroupOperation operation, uint32_t value,
  6913. llvm::Optional<uint32_t> cluster_size) {
  6914. if (!TheInst.empty()) {
  6915. TheStatus = Status::NestedInst;
  6916. return *this;
  6917. }
  6918. if (result_type == 0) {
  6919. TheStatus = Status::ZeroResultType;
  6920. return *this;
  6921. }
  6922. if (result_id == 0) {
  6923. TheStatus = Status::ZeroResultId;
  6924. return *this;
  6925. }
  6926. TheInst.reserve(7);
  6927. TheInst.emplace_back(static_cast<uint32_t>(spv::Op::OpGroupNonUniformIAdd));
  6928. TheInst.emplace_back(result_type);
  6929. TheInst.emplace_back(result_id);
  6930. TheInst.emplace_back(execution);
  6931. TheInst.emplace_back(static_cast<uint32_t>(operation));
  6932. TheInst.emplace_back(value);
  6933. if (cluster_size.hasValue()) {
  6934. const auto &val = cluster_size.getValue();
  6935. TheInst.emplace_back(val);
  6936. }
  6937. return *this;
  6938. }
  6939. InstBuilder &InstBuilder::opGroupNonUniformFAdd(
  6940. uint32_t result_type, uint32_t result_id, uint32_t execution,
  6941. spv::GroupOperation operation, uint32_t value,
  6942. llvm::Optional<uint32_t> cluster_size) {
  6943. if (!TheInst.empty()) {
  6944. TheStatus = Status::NestedInst;
  6945. return *this;
  6946. }
  6947. if (result_type == 0) {
  6948. TheStatus = Status::ZeroResultType;
  6949. return *this;
  6950. }
  6951. if (result_id == 0) {
  6952. TheStatus = Status::ZeroResultId;
  6953. return *this;
  6954. }
  6955. TheInst.reserve(7);
  6956. TheInst.emplace_back(static_cast<uint32_t>(spv::Op::OpGroupNonUniformFAdd));
  6957. TheInst.emplace_back(result_type);
  6958. TheInst.emplace_back(result_id);
  6959. TheInst.emplace_back(execution);
  6960. TheInst.emplace_back(static_cast<uint32_t>(operation));
  6961. TheInst.emplace_back(value);
  6962. if (cluster_size.hasValue()) {
  6963. const auto &val = cluster_size.getValue();
  6964. TheInst.emplace_back(val);
  6965. }
  6966. return *this;
  6967. }
  6968. InstBuilder &InstBuilder::opGroupNonUniformIMul(
  6969. uint32_t result_type, uint32_t result_id, uint32_t execution,
  6970. spv::GroupOperation operation, uint32_t value,
  6971. llvm::Optional<uint32_t> cluster_size) {
  6972. if (!TheInst.empty()) {
  6973. TheStatus = Status::NestedInst;
  6974. return *this;
  6975. }
  6976. if (result_type == 0) {
  6977. TheStatus = Status::ZeroResultType;
  6978. return *this;
  6979. }
  6980. if (result_id == 0) {
  6981. TheStatus = Status::ZeroResultId;
  6982. return *this;
  6983. }
  6984. TheInst.reserve(7);
  6985. TheInst.emplace_back(static_cast<uint32_t>(spv::Op::OpGroupNonUniformIMul));
  6986. TheInst.emplace_back(result_type);
  6987. TheInst.emplace_back(result_id);
  6988. TheInst.emplace_back(execution);
  6989. TheInst.emplace_back(static_cast<uint32_t>(operation));
  6990. TheInst.emplace_back(value);
  6991. if (cluster_size.hasValue()) {
  6992. const auto &val = cluster_size.getValue();
  6993. TheInst.emplace_back(val);
  6994. }
  6995. return *this;
  6996. }
  6997. InstBuilder &InstBuilder::opGroupNonUniformFMul(
  6998. uint32_t result_type, uint32_t result_id, uint32_t execution,
  6999. spv::GroupOperation operation, uint32_t value,
  7000. llvm::Optional<uint32_t> cluster_size) {
  7001. if (!TheInst.empty()) {
  7002. TheStatus = Status::NestedInst;
  7003. return *this;
  7004. }
  7005. if (result_type == 0) {
  7006. TheStatus = Status::ZeroResultType;
  7007. return *this;
  7008. }
  7009. if (result_id == 0) {
  7010. TheStatus = Status::ZeroResultId;
  7011. return *this;
  7012. }
  7013. TheInst.reserve(7);
  7014. TheInst.emplace_back(static_cast<uint32_t>(spv::Op::OpGroupNonUniformFMul));
  7015. TheInst.emplace_back(result_type);
  7016. TheInst.emplace_back(result_id);
  7017. TheInst.emplace_back(execution);
  7018. TheInst.emplace_back(static_cast<uint32_t>(operation));
  7019. TheInst.emplace_back(value);
  7020. if (cluster_size.hasValue()) {
  7021. const auto &val = cluster_size.getValue();
  7022. TheInst.emplace_back(val);
  7023. }
  7024. return *this;
  7025. }
  7026. InstBuilder &InstBuilder::opGroupNonUniformSMin(
  7027. uint32_t result_type, uint32_t result_id, uint32_t execution,
  7028. spv::GroupOperation operation, uint32_t value,
  7029. llvm::Optional<uint32_t> cluster_size) {
  7030. if (!TheInst.empty()) {
  7031. TheStatus = Status::NestedInst;
  7032. return *this;
  7033. }
  7034. if (result_type == 0) {
  7035. TheStatus = Status::ZeroResultType;
  7036. return *this;
  7037. }
  7038. if (result_id == 0) {
  7039. TheStatus = Status::ZeroResultId;
  7040. return *this;
  7041. }
  7042. TheInst.reserve(7);
  7043. TheInst.emplace_back(static_cast<uint32_t>(spv::Op::OpGroupNonUniformSMin));
  7044. TheInst.emplace_back(result_type);
  7045. TheInst.emplace_back(result_id);
  7046. TheInst.emplace_back(execution);
  7047. TheInst.emplace_back(static_cast<uint32_t>(operation));
  7048. TheInst.emplace_back(value);
  7049. if (cluster_size.hasValue()) {
  7050. const auto &val = cluster_size.getValue();
  7051. TheInst.emplace_back(val);
  7052. }
  7053. return *this;
  7054. }
  7055. InstBuilder &InstBuilder::opGroupNonUniformUMin(
  7056. uint32_t result_type, uint32_t result_id, uint32_t execution,
  7057. spv::GroupOperation operation, uint32_t value,
  7058. llvm::Optional<uint32_t> cluster_size) {
  7059. if (!TheInst.empty()) {
  7060. TheStatus = Status::NestedInst;
  7061. return *this;
  7062. }
  7063. if (result_type == 0) {
  7064. TheStatus = Status::ZeroResultType;
  7065. return *this;
  7066. }
  7067. if (result_id == 0) {
  7068. TheStatus = Status::ZeroResultId;
  7069. return *this;
  7070. }
  7071. TheInst.reserve(7);
  7072. TheInst.emplace_back(static_cast<uint32_t>(spv::Op::OpGroupNonUniformUMin));
  7073. TheInst.emplace_back(result_type);
  7074. TheInst.emplace_back(result_id);
  7075. TheInst.emplace_back(execution);
  7076. TheInst.emplace_back(static_cast<uint32_t>(operation));
  7077. TheInst.emplace_back(value);
  7078. if (cluster_size.hasValue()) {
  7079. const auto &val = cluster_size.getValue();
  7080. TheInst.emplace_back(val);
  7081. }
  7082. return *this;
  7083. }
  7084. InstBuilder &InstBuilder::opGroupNonUniformFMin(
  7085. uint32_t result_type, uint32_t result_id, uint32_t execution,
  7086. spv::GroupOperation operation, uint32_t value,
  7087. llvm::Optional<uint32_t> cluster_size) {
  7088. if (!TheInst.empty()) {
  7089. TheStatus = Status::NestedInst;
  7090. return *this;
  7091. }
  7092. if (result_type == 0) {
  7093. TheStatus = Status::ZeroResultType;
  7094. return *this;
  7095. }
  7096. if (result_id == 0) {
  7097. TheStatus = Status::ZeroResultId;
  7098. return *this;
  7099. }
  7100. TheInst.reserve(7);
  7101. TheInst.emplace_back(static_cast<uint32_t>(spv::Op::OpGroupNonUniformFMin));
  7102. TheInst.emplace_back(result_type);
  7103. TheInst.emplace_back(result_id);
  7104. TheInst.emplace_back(execution);
  7105. TheInst.emplace_back(static_cast<uint32_t>(operation));
  7106. TheInst.emplace_back(value);
  7107. if (cluster_size.hasValue()) {
  7108. const auto &val = cluster_size.getValue();
  7109. TheInst.emplace_back(val);
  7110. }
  7111. return *this;
  7112. }
  7113. InstBuilder &InstBuilder::opGroupNonUniformSMax(
  7114. uint32_t result_type, uint32_t result_id, uint32_t execution,
  7115. spv::GroupOperation operation, uint32_t value,
  7116. llvm::Optional<uint32_t> cluster_size) {
  7117. if (!TheInst.empty()) {
  7118. TheStatus = Status::NestedInst;
  7119. return *this;
  7120. }
  7121. if (result_type == 0) {
  7122. TheStatus = Status::ZeroResultType;
  7123. return *this;
  7124. }
  7125. if (result_id == 0) {
  7126. TheStatus = Status::ZeroResultId;
  7127. return *this;
  7128. }
  7129. TheInst.reserve(7);
  7130. TheInst.emplace_back(static_cast<uint32_t>(spv::Op::OpGroupNonUniformSMax));
  7131. TheInst.emplace_back(result_type);
  7132. TheInst.emplace_back(result_id);
  7133. TheInst.emplace_back(execution);
  7134. TheInst.emplace_back(static_cast<uint32_t>(operation));
  7135. TheInst.emplace_back(value);
  7136. if (cluster_size.hasValue()) {
  7137. const auto &val = cluster_size.getValue();
  7138. TheInst.emplace_back(val);
  7139. }
  7140. return *this;
  7141. }
  7142. InstBuilder &InstBuilder::opGroupNonUniformUMax(
  7143. uint32_t result_type, uint32_t result_id, uint32_t execution,
  7144. spv::GroupOperation operation, uint32_t value,
  7145. llvm::Optional<uint32_t> cluster_size) {
  7146. if (!TheInst.empty()) {
  7147. TheStatus = Status::NestedInst;
  7148. return *this;
  7149. }
  7150. if (result_type == 0) {
  7151. TheStatus = Status::ZeroResultType;
  7152. return *this;
  7153. }
  7154. if (result_id == 0) {
  7155. TheStatus = Status::ZeroResultId;
  7156. return *this;
  7157. }
  7158. TheInst.reserve(7);
  7159. TheInst.emplace_back(static_cast<uint32_t>(spv::Op::OpGroupNonUniformUMax));
  7160. TheInst.emplace_back(result_type);
  7161. TheInst.emplace_back(result_id);
  7162. TheInst.emplace_back(execution);
  7163. TheInst.emplace_back(static_cast<uint32_t>(operation));
  7164. TheInst.emplace_back(value);
  7165. if (cluster_size.hasValue()) {
  7166. const auto &val = cluster_size.getValue();
  7167. TheInst.emplace_back(val);
  7168. }
  7169. return *this;
  7170. }
  7171. InstBuilder &InstBuilder::opGroupNonUniformFMax(
  7172. uint32_t result_type, uint32_t result_id, uint32_t execution,
  7173. spv::GroupOperation operation, uint32_t value,
  7174. llvm::Optional<uint32_t> cluster_size) {
  7175. if (!TheInst.empty()) {
  7176. TheStatus = Status::NestedInst;
  7177. return *this;
  7178. }
  7179. if (result_type == 0) {
  7180. TheStatus = Status::ZeroResultType;
  7181. return *this;
  7182. }
  7183. if (result_id == 0) {
  7184. TheStatus = Status::ZeroResultId;
  7185. return *this;
  7186. }
  7187. TheInst.reserve(7);
  7188. TheInst.emplace_back(static_cast<uint32_t>(spv::Op::OpGroupNonUniformFMax));
  7189. TheInst.emplace_back(result_type);
  7190. TheInst.emplace_back(result_id);
  7191. TheInst.emplace_back(execution);
  7192. TheInst.emplace_back(static_cast<uint32_t>(operation));
  7193. TheInst.emplace_back(value);
  7194. if (cluster_size.hasValue()) {
  7195. const auto &val = cluster_size.getValue();
  7196. TheInst.emplace_back(val);
  7197. }
  7198. return *this;
  7199. }
  7200. InstBuilder &InstBuilder::opGroupNonUniformBitwiseAnd(
  7201. uint32_t result_type, uint32_t result_id, uint32_t execution,
  7202. spv::GroupOperation operation, uint32_t value,
  7203. llvm::Optional<uint32_t> cluster_size) {
  7204. if (!TheInst.empty()) {
  7205. TheStatus = Status::NestedInst;
  7206. return *this;
  7207. }
  7208. if (result_type == 0) {
  7209. TheStatus = Status::ZeroResultType;
  7210. return *this;
  7211. }
  7212. if (result_id == 0) {
  7213. TheStatus = Status::ZeroResultId;
  7214. return *this;
  7215. }
  7216. TheInst.reserve(7);
  7217. TheInst.emplace_back(
  7218. static_cast<uint32_t>(spv::Op::OpGroupNonUniformBitwiseAnd));
  7219. TheInst.emplace_back(result_type);
  7220. TheInst.emplace_back(result_id);
  7221. TheInst.emplace_back(execution);
  7222. TheInst.emplace_back(static_cast<uint32_t>(operation));
  7223. TheInst.emplace_back(value);
  7224. if (cluster_size.hasValue()) {
  7225. const auto &val = cluster_size.getValue();
  7226. TheInst.emplace_back(val);
  7227. }
  7228. return *this;
  7229. }
  7230. InstBuilder &InstBuilder::opGroupNonUniformBitwiseOr(
  7231. uint32_t result_type, uint32_t result_id, uint32_t execution,
  7232. spv::GroupOperation operation, uint32_t value,
  7233. llvm::Optional<uint32_t> cluster_size) {
  7234. if (!TheInst.empty()) {
  7235. TheStatus = Status::NestedInst;
  7236. return *this;
  7237. }
  7238. if (result_type == 0) {
  7239. TheStatus = Status::ZeroResultType;
  7240. return *this;
  7241. }
  7242. if (result_id == 0) {
  7243. TheStatus = Status::ZeroResultId;
  7244. return *this;
  7245. }
  7246. TheInst.reserve(7);
  7247. TheInst.emplace_back(
  7248. static_cast<uint32_t>(spv::Op::OpGroupNonUniformBitwiseOr));
  7249. TheInst.emplace_back(result_type);
  7250. TheInst.emplace_back(result_id);
  7251. TheInst.emplace_back(execution);
  7252. TheInst.emplace_back(static_cast<uint32_t>(operation));
  7253. TheInst.emplace_back(value);
  7254. if (cluster_size.hasValue()) {
  7255. const auto &val = cluster_size.getValue();
  7256. TheInst.emplace_back(val);
  7257. }
  7258. return *this;
  7259. }
  7260. InstBuilder &InstBuilder::opGroupNonUniformBitwiseXor(
  7261. uint32_t result_type, uint32_t result_id, uint32_t execution,
  7262. spv::GroupOperation operation, uint32_t value,
  7263. llvm::Optional<uint32_t> cluster_size) {
  7264. if (!TheInst.empty()) {
  7265. TheStatus = Status::NestedInst;
  7266. return *this;
  7267. }
  7268. if (result_type == 0) {
  7269. TheStatus = Status::ZeroResultType;
  7270. return *this;
  7271. }
  7272. if (result_id == 0) {
  7273. TheStatus = Status::ZeroResultId;
  7274. return *this;
  7275. }
  7276. TheInst.reserve(7);
  7277. TheInst.emplace_back(
  7278. static_cast<uint32_t>(spv::Op::OpGroupNonUniformBitwiseXor));
  7279. TheInst.emplace_back(result_type);
  7280. TheInst.emplace_back(result_id);
  7281. TheInst.emplace_back(execution);
  7282. TheInst.emplace_back(static_cast<uint32_t>(operation));
  7283. TheInst.emplace_back(value);
  7284. if (cluster_size.hasValue()) {
  7285. const auto &val = cluster_size.getValue();
  7286. TheInst.emplace_back(val);
  7287. }
  7288. return *this;
  7289. }
  7290. InstBuilder &InstBuilder::opGroupNonUniformLogicalAnd(
  7291. uint32_t result_type, uint32_t result_id, uint32_t execution,
  7292. spv::GroupOperation operation, uint32_t value,
  7293. llvm::Optional<uint32_t> cluster_size) {
  7294. if (!TheInst.empty()) {
  7295. TheStatus = Status::NestedInst;
  7296. return *this;
  7297. }
  7298. if (result_type == 0) {
  7299. TheStatus = Status::ZeroResultType;
  7300. return *this;
  7301. }
  7302. if (result_id == 0) {
  7303. TheStatus = Status::ZeroResultId;
  7304. return *this;
  7305. }
  7306. TheInst.reserve(7);
  7307. TheInst.emplace_back(
  7308. static_cast<uint32_t>(spv::Op::OpGroupNonUniformLogicalAnd));
  7309. TheInst.emplace_back(result_type);
  7310. TheInst.emplace_back(result_id);
  7311. TheInst.emplace_back(execution);
  7312. TheInst.emplace_back(static_cast<uint32_t>(operation));
  7313. TheInst.emplace_back(value);
  7314. if (cluster_size.hasValue()) {
  7315. const auto &val = cluster_size.getValue();
  7316. TheInst.emplace_back(val);
  7317. }
  7318. return *this;
  7319. }
  7320. InstBuilder &InstBuilder::opGroupNonUniformLogicalOr(
  7321. uint32_t result_type, uint32_t result_id, uint32_t execution,
  7322. spv::GroupOperation operation, uint32_t value,
  7323. llvm::Optional<uint32_t> cluster_size) {
  7324. if (!TheInst.empty()) {
  7325. TheStatus = Status::NestedInst;
  7326. return *this;
  7327. }
  7328. if (result_type == 0) {
  7329. TheStatus = Status::ZeroResultType;
  7330. return *this;
  7331. }
  7332. if (result_id == 0) {
  7333. TheStatus = Status::ZeroResultId;
  7334. return *this;
  7335. }
  7336. TheInst.reserve(7);
  7337. TheInst.emplace_back(
  7338. static_cast<uint32_t>(spv::Op::OpGroupNonUniformLogicalOr));
  7339. TheInst.emplace_back(result_type);
  7340. TheInst.emplace_back(result_id);
  7341. TheInst.emplace_back(execution);
  7342. TheInst.emplace_back(static_cast<uint32_t>(operation));
  7343. TheInst.emplace_back(value);
  7344. if (cluster_size.hasValue()) {
  7345. const auto &val = cluster_size.getValue();
  7346. TheInst.emplace_back(val);
  7347. }
  7348. return *this;
  7349. }
  7350. InstBuilder &InstBuilder::opGroupNonUniformLogicalXor(
  7351. uint32_t result_type, uint32_t result_id, uint32_t execution,
  7352. spv::GroupOperation operation, uint32_t value,
  7353. llvm::Optional<uint32_t> cluster_size) {
  7354. if (!TheInst.empty()) {
  7355. TheStatus = Status::NestedInst;
  7356. return *this;
  7357. }
  7358. if (result_type == 0) {
  7359. TheStatus = Status::ZeroResultType;
  7360. return *this;
  7361. }
  7362. if (result_id == 0) {
  7363. TheStatus = Status::ZeroResultId;
  7364. return *this;
  7365. }
  7366. TheInst.reserve(7);
  7367. TheInst.emplace_back(
  7368. static_cast<uint32_t>(spv::Op::OpGroupNonUniformLogicalXor));
  7369. TheInst.emplace_back(result_type);
  7370. TheInst.emplace_back(result_id);
  7371. TheInst.emplace_back(execution);
  7372. TheInst.emplace_back(static_cast<uint32_t>(operation));
  7373. TheInst.emplace_back(value);
  7374. if (cluster_size.hasValue()) {
  7375. const auto &val = cluster_size.getValue();
  7376. TheInst.emplace_back(val);
  7377. }
  7378. return *this;
  7379. }
  7380. InstBuilder &InstBuilder::opGroupNonUniformQuadBroadcast(uint32_t result_type,
  7381. uint32_t result_id,
  7382. uint32_t execution,
  7383. uint32_t value,
  7384. uint32_t index) {
  7385. if (!TheInst.empty()) {
  7386. TheStatus = Status::NestedInst;
  7387. return *this;
  7388. }
  7389. if (result_type == 0) {
  7390. TheStatus = Status::ZeroResultType;
  7391. return *this;
  7392. }
  7393. if (result_id == 0) {
  7394. TheStatus = Status::ZeroResultId;
  7395. return *this;
  7396. }
  7397. TheInst.reserve(6);
  7398. TheInst.emplace_back(
  7399. static_cast<uint32_t>(spv::Op::OpGroupNonUniformQuadBroadcast));
  7400. TheInst.emplace_back(result_type);
  7401. TheInst.emplace_back(result_id);
  7402. TheInst.emplace_back(execution);
  7403. TheInst.emplace_back(value);
  7404. TheInst.emplace_back(index);
  7405. return *this;
  7406. }
  7407. InstBuilder &InstBuilder::opGroupNonUniformQuadSwap(uint32_t result_type,
  7408. uint32_t result_id,
  7409. uint32_t execution,
  7410. uint32_t value,
  7411. uint32_t direction) {
  7412. if (!TheInst.empty()) {
  7413. TheStatus = Status::NestedInst;
  7414. return *this;
  7415. }
  7416. if (result_type == 0) {
  7417. TheStatus = Status::ZeroResultType;
  7418. return *this;
  7419. }
  7420. if (result_id == 0) {
  7421. TheStatus = Status::ZeroResultId;
  7422. return *this;
  7423. }
  7424. TheInst.reserve(6);
  7425. TheInst.emplace_back(
  7426. static_cast<uint32_t>(spv::Op::OpGroupNonUniformQuadSwap));
  7427. TheInst.emplace_back(result_type);
  7428. TheInst.emplace_back(result_id);
  7429. TheInst.emplace_back(execution);
  7430. TheInst.emplace_back(value);
  7431. TheInst.emplace_back(direction);
  7432. return *this;
  7433. }
  7434. InstBuilder &InstBuilder::opSubgroupBallotKHR(uint32_t result_type,
  7435. uint32_t result_id,
  7436. uint32_t predicate) {
  7437. if (!TheInst.empty()) {
  7438. TheStatus = Status::NestedInst;
  7439. return *this;
  7440. }
  7441. if (result_type == 0) {
  7442. TheStatus = Status::ZeroResultType;
  7443. return *this;
  7444. }
  7445. if (result_id == 0) {
  7446. TheStatus = Status::ZeroResultId;
  7447. return *this;
  7448. }
  7449. TheInst.reserve(4);
  7450. TheInst.emplace_back(static_cast<uint32_t>(spv::Op::OpSubgroupBallotKHR));
  7451. TheInst.emplace_back(result_type);
  7452. TheInst.emplace_back(result_id);
  7453. TheInst.emplace_back(predicate);
  7454. return *this;
  7455. }
  7456. InstBuilder &InstBuilder::opSubgroupFirstInvocationKHR(uint32_t result_type,
  7457. uint32_t result_id,
  7458. uint32_t value) {
  7459. if (!TheInst.empty()) {
  7460. TheStatus = Status::NestedInst;
  7461. return *this;
  7462. }
  7463. if (result_type == 0) {
  7464. TheStatus = Status::ZeroResultType;
  7465. return *this;
  7466. }
  7467. if (result_id == 0) {
  7468. TheStatus = Status::ZeroResultId;
  7469. return *this;
  7470. }
  7471. TheInst.reserve(4);
  7472. TheInst.emplace_back(
  7473. static_cast<uint32_t>(spv::Op::OpSubgroupFirstInvocationKHR));
  7474. TheInst.emplace_back(result_type);
  7475. TheInst.emplace_back(result_id);
  7476. TheInst.emplace_back(value);
  7477. return *this;
  7478. }
  7479. InstBuilder &InstBuilder::opSubgroupAllKHR(uint32_t result_type,
  7480. uint32_t result_id,
  7481. uint32_t predicate) {
  7482. if (!TheInst.empty()) {
  7483. TheStatus = Status::NestedInst;
  7484. return *this;
  7485. }
  7486. if (result_type == 0) {
  7487. TheStatus = Status::ZeroResultType;
  7488. return *this;
  7489. }
  7490. if (result_id == 0) {
  7491. TheStatus = Status::ZeroResultId;
  7492. return *this;
  7493. }
  7494. TheInst.reserve(4);
  7495. TheInst.emplace_back(static_cast<uint32_t>(spv::Op::OpSubgroupAllKHR));
  7496. TheInst.emplace_back(result_type);
  7497. TheInst.emplace_back(result_id);
  7498. TheInst.emplace_back(predicate);
  7499. return *this;
  7500. }
  7501. InstBuilder &InstBuilder::opSubgroupAnyKHR(uint32_t result_type,
  7502. uint32_t result_id,
  7503. uint32_t predicate) {
  7504. if (!TheInst.empty()) {
  7505. TheStatus = Status::NestedInst;
  7506. return *this;
  7507. }
  7508. if (result_type == 0) {
  7509. TheStatus = Status::ZeroResultType;
  7510. return *this;
  7511. }
  7512. if (result_id == 0) {
  7513. TheStatus = Status::ZeroResultId;
  7514. return *this;
  7515. }
  7516. TheInst.reserve(4);
  7517. TheInst.emplace_back(static_cast<uint32_t>(spv::Op::OpSubgroupAnyKHR));
  7518. TheInst.emplace_back(result_type);
  7519. TheInst.emplace_back(result_id);
  7520. TheInst.emplace_back(predicate);
  7521. return *this;
  7522. }
  7523. InstBuilder &InstBuilder::opSubgroupAllEqualKHR(uint32_t result_type,
  7524. uint32_t result_id,
  7525. uint32_t predicate) {
  7526. if (!TheInst.empty()) {
  7527. TheStatus = Status::NestedInst;
  7528. return *this;
  7529. }
  7530. if (result_type == 0) {
  7531. TheStatus = Status::ZeroResultType;
  7532. return *this;
  7533. }
  7534. if (result_id == 0) {
  7535. TheStatus = Status::ZeroResultId;
  7536. return *this;
  7537. }
  7538. TheInst.reserve(4);
  7539. TheInst.emplace_back(static_cast<uint32_t>(spv::Op::OpSubgroupAllEqualKHR));
  7540. TheInst.emplace_back(result_type);
  7541. TheInst.emplace_back(result_id);
  7542. TheInst.emplace_back(predicate);
  7543. return *this;
  7544. }
  7545. InstBuilder &InstBuilder::opSubgroupReadInvocationKHR(uint32_t result_type,
  7546. uint32_t result_id,
  7547. uint32_t value,
  7548. uint32_t index) {
  7549. if (!TheInst.empty()) {
  7550. TheStatus = Status::NestedInst;
  7551. return *this;
  7552. }
  7553. if (result_type == 0) {
  7554. TheStatus = Status::ZeroResultType;
  7555. return *this;
  7556. }
  7557. if (result_id == 0) {
  7558. TheStatus = Status::ZeroResultId;
  7559. return *this;
  7560. }
  7561. TheInst.reserve(5);
  7562. TheInst.emplace_back(
  7563. static_cast<uint32_t>(spv::Op::OpSubgroupReadInvocationKHR));
  7564. TheInst.emplace_back(result_type);
  7565. TheInst.emplace_back(result_id);
  7566. TheInst.emplace_back(value);
  7567. TheInst.emplace_back(index);
  7568. return *this;
  7569. }
  7570. InstBuilder &InstBuilder::opGroupIAddNonUniformAMD(
  7571. uint32_t result_type, uint32_t result_id, uint32_t execution,
  7572. spv::GroupOperation operation, uint32_t x) {
  7573. if (!TheInst.empty()) {
  7574. TheStatus = Status::NestedInst;
  7575. return *this;
  7576. }
  7577. if (result_type == 0) {
  7578. TheStatus = Status::ZeroResultType;
  7579. return *this;
  7580. }
  7581. if (result_id == 0) {
  7582. TheStatus = Status::ZeroResultId;
  7583. return *this;
  7584. }
  7585. TheInst.reserve(6);
  7586. TheInst.emplace_back(
  7587. static_cast<uint32_t>(spv::Op::OpGroupIAddNonUniformAMD));
  7588. TheInst.emplace_back(result_type);
  7589. TheInst.emplace_back(result_id);
  7590. TheInst.emplace_back(execution);
  7591. TheInst.emplace_back(static_cast<uint32_t>(operation));
  7592. TheInst.emplace_back(x);
  7593. return *this;
  7594. }
  7595. InstBuilder &InstBuilder::opGroupFAddNonUniformAMD(
  7596. uint32_t result_type, uint32_t result_id, uint32_t execution,
  7597. spv::GroupOperation operation, uint32_t x) {
  7598. if (!TheInst.empty()) {
  7599. TheStatus = Status::NestedInst;
  7600. return *this;
  7601. }
  7602. if (result_type == 0) {
  7603. TheStatus = Status::ZeroResultType;
  7604. return *this;
  7605. }
  7606. if (result_id == 0) {
  7607. TheStatus = Status::ZeroResultId;
  7608. return *this;
  7609. }
  7610. TheInst.reserve(6);
  7611. TheInst.emplace_back(
  7612. static_cast<uint32_t>(spv::Op::OpGroupFAddNonUniformAMD));
  7613. TheInst.emplace_back(result_type);
  7614. TheInst.emplace_back(result_id);
  7615. TheInst.emplace_back(execution);
  7616. TheInst.emplace_back(static_cast<uint32_t>(operation));
  7617. TheInst.emplace_back(x);
  7618. return *this;
  7619. }
  7620. InstBuilder &InstBuilder::opGroupFMinNonUniformAMD(
  7621. uint32_t result_type, uint32_t result_id, uint32_t execution,
  7622. spv::GroupOperation operation, uint32_t x) {
  7623. if (!TheInst.empty()) {
  7624. TheStatus = Status::NestedInst;
  7625. return *this;
  7626. }
  7627. if (result_type == 0) {
  7628. TheStatus = Status::ZeroResultType;
  7629. return *this;
  7630. }
  7631. if (result_id == 0) {
  7632. TheStatus = Status::ZeroResultId;
  7633. return *this;
  7634. }
  7635. TheInst.reserve(6);
  7636. TheInst.emplace_back(
  7637. static_cast<uint32_t>(spv::Op::OpGroupFMinNonUniformAMD));
  7638. TheInst.emplace_back(result_type);
  7639. TheInst.emplace_back(result_id);
  7640. TheInst.emplace_back(execution);
  7641. TheInst.emplace_back(static_cast<uint32_t>(operation));
  7642. TheInst.emplace_back(x);
  7643. return *this;
  7644. }
  7645. InstBuilder &InstBuilder::opGroupUMinNonUniformAMD(
  7646. uint32_t result_type, uint32_t result_id, uint32_t execution,
  7647. spv::GroupOperation operation, uint32_t x) {
  7648. if (!TheInst.empty()) {
  7649. TheStatus = Status::NestedInst;
  7650. return *this;
  7651. }
  7652. if (result_type == 0) {
  7653. TheStatus = Status::ZeroResultType;
  7654. return *this;
  7655. }
  7656. if (result_id == 0) {
  7657. TheStatus = Status::ZeroResultId;
  7658. return *this;
  7659. }
  7660. TheInst.reserve(6);
  7661. TheInst.emplace_back(
  7662. static_cast<uint32_t>(spv::Op::OpGroupUMinNonUniformAMD));
  7663. TheInst.emplace_back(result_type);
  7664. TheInst.emplace_back(result_id);
  7665. TheInst.emplace_back(execution);
  7666. TheInst.emplace_back(static_cast<uint32_t>(operation));
  7667. TheInst.emplace_back(x);
  7668. return *this;
  7669. }
  7670. InstBuilder &InstBuilder::opGroupSMinNonUniformAMD(
  7671. uint32_t result_type, uint32_t result_id, uint32_t execution,
  7672. spv::GroupOperation operation, uint32_t x) {
  7673. if (!TheInst.empty()) {
  7674. TheStatus = Status::NestedInst;
  7675. return *this;
  7676. }
  7677. if (result_type == 0) {
  7678. TheStatus = Status::ZeroResultType;
  7679. return *this;
  7680. }
  7681. if (result_id == 0) {
  7682. TheStatus = Status::ZeroResultId;
  7683. return *this;
  7684. }
  7685. TheInst.reserve(6);
  7686. TheInst.emplace_back(
  7687. static_cast<uint32_t>(spv::Op::OpGroupSMinNonUniformAMD));
  7688. TheInst.emplace_back(result_type);
  7689. TheInst.emplace_back(result_id);
  7690. TheInst.emplace_back(execution);
  7691. TheInst.emplace_back(static_cast<uint32_t>(operation));
  7692. TheInst.emplace_back(x);
  7693. return *this;
  7694. }
  7695. InstBuilder &InstBuilder::opGroupFMaxNonUniformAMD(
  7696. uint32_t result_type, uint32_t result_id, uint32_t execution,
  7697. spv::GroupOperation operation, uint32_t x) {
  7698. if (!TheInst.empty()) {
  7699. TheStatus = Status::NestedInst;
  7700. return *this;
  7701. }
  7702. if (result_type == 0) {
  7703. TheStatus = Status::ZeroResultType;
  7704. return *this;
  7705. }
  7706. if (result_id == 0) {
  7707. TheStatus = Status::ZeroResultId;
  7708. return *this;
  7709. }
  7710. TheInst.reserve(6);
  7711. TheInst.emplace_back(
  7712. static_cast<uint32_t>(spv::Op::OpGroupFMaxNonUniformAMD));
  7713. TheInst.emplace_back(result_type);
  7714. TheInst.emplace_back(result_id);
  7715. TheInst.emplace_back(execution);
  7716. TheInst.emplace_back(static_cast<uint32_t>(operation));
  7717. TheInst.emplace_back(x);
  7718. return *this;
  7719. }
  7720. InstBuilder &InstBuilder::opGroupUMaxNonUniformAMD(
  7721. uint32_t result_type, uint32_t result_id, uint32_t execution,
  7722. spv::GroupOperation operation, uint32_t x) {
  7723. if (!TheInst.empty()) {
  7724. TheStatus = Status::NestedInst;
  7725. return *this;
  7726. }
  7727. if (result_type == 0) {
  7728. TheStatus = Status::ZeroResultType;
  7729. return *this;
  7730. }
  7731. if (result_id == 0) {
  7732. TheStatus = Status::ZeroResultId;
  7733. return *this;
  7734. }
  7735. TheInst.reserve(6);
  7736. TheInst.emplace_back(
  7737. static_cast<uint32_t>(spv::Op::OpGroupUMaxNonUniformAMD));
  7738. TheInst.emplace_back(result_type);
  7739. TheInst.emplace_back(result_id);
  7740. TheInst.emplace_back(execution);
  7741. TheInst.emplace_back(static_cast<uint32_t>(operation));
  7742. TheInst.emplace_back(x);
  7743. return *this;
  7744. }
  7745. InstBuilder &InstBuilder::opGroupSMaxNonUniformAMD(
  7746. uint32_t result_type, uint32_t result_id, uint32_t execution,
  7747. spv::GroupOperation operation, uint32_t x) {
  7748. if (!TheInst.empty()) {
  7749. TheStatus = Status::NestedInst;
  7750. return *this;
  7751. }
  7752. if (result_type == 0) {
  7753. TheStatus = Status::ZeroResultType;
  7754. return *this;
  7755. }
  7756. if (result_id == 0) {
  7757. TheStatus = Status::ZeroResultId;
  7758. return *this;
  7759. }
  7760. TheInst.reserve(6);
  7761. TheInst.emplace_back(
  7762. static_cast<uint32_t>(spv::Op::OpGroupSMaxNonUniformAMD));
  7763. TheInst.emplace_back(result_type);
  7764. TheInst.emplace_back(result_id);
  7765. TheInst.emplace_back(execution);
  7766. TheInst.emplace_back(static_cast<uint32_t>(operation));
  7767. TheInst.emplace_back(x);
  7768. return *this;
  7769. }
  7770. InstBuilder &InstBuilder::opFragmentMaskFetchAMD(uint32_t result_type,
  7771. uint32_t result_id,
  7772. uint32_t image,
  7773. uint32_t coordinate) {
  7774. if (!TheInst.empty()) {
  7775. TheStatus = Status::NestedInst;
  7776. return *this;
  7777. }
  7778. if (result_type == 0) {
  7779. TheStatus = Status::ZeroResultType;
  7780. return *this;
  7781. }
  7782. if (result_id == 0) {
  7783. TheStatus = Status::ZeroResultId;
  7784. return *this;
  7785. }
  7786. TheInst.reserve(5);
  7787. TheInst.emplace_back(static_cast<uint32_t>(spv::Op::OpFragmentMaskFetchAMD));
  7788. TheInst.emplace_back(result_type);
  7789. TheInst.emplace_back(result_id);
  7790. TheInst.emplace_back(image);
  7791. TheInst.emplace_back(coordinate);
  7792. return *this;
  7793. }
  7794. InstBuilder &InstBuilder::opFragmentFetchAMD(uint32_t result_type,
  7795. uint32_t result_id, uint32_t image,
  7796. uint32_t coordinate,
  7797. uint32_t fragment_index) {
  7798. if (!TheInst.empty()) {
  7799. TheStatus = Status::NestedInst;
  7800. return *this;
  7801. }
  7802. if (result_type == 0) {
  7803. TheStatus = Status::ZeroResultType;
  7804. return *this;
  7805. }
  7806. if (result_id == 0) {
  7807. TheStatus = Status::ZeroResultId;
  7808. return *this;
  7809. }
  7810. TheInst.reserve(6);
  7811. TheInst.emplace_back(static_cast<uint32_t>(spv::Op::OpFragmentFetchAMD));
  7812. TheInst.emplace_back(result_type);
  7813. TheInst.emplace_back(result_id);
  7814. TheInst.emplace_back(image);
  7815. TheInst.emplace_back(coordinate);
  7816. TheInst.emplace_back(fragment_index);
  7817. return *this;
  7818. }
  7819. InstBuilder &InstBuilder::opSubgroupShuffleINTEL(uint32_t result_type,
  7820. uint32_t result_id,
  7821. uint32_t data,
  7822. uint32_t invocation_id) {
  7823. if (!TheInst.empty()) {
  7824. TheStatus = Status::NestedInst;
  7825. return *this;
  7826. }
  7827. if (result_type == 0) {
  7828. TheStatus = Status::ZeroResultType;
  7829. return *this;
  7830. }
  7831. if (result_id == 0) {
  7832. TheStatus = Status::ZeroResultId;
  7833. return *this;
  7834. }
  7835. TheInst.reserve(5);
  7836. TheInst.emplace_back(static_cast<uint32_t>(spv::Op::OpSubgroupShuffleINTEL));
  7837. TheInst.emplace_back(result_type);
  7838. TheInst.emplace_back(result_id);
  7839. TheInst.emplace_back(data);
  7840. TheInst.emplace_back(invocation_id);
  7841. return *this;
  7842. }
  7843. InstBuilder &InstBuilder::opSubgroupShuffleDownINTEL(uint32_t result_type,
  7844. uint32_t result_id,
  7845. uint32_t current,
  7846. uint32_t next,
  7847. uint32_t delta) {
  7848. if (!TheInst.empty()) {
  7849. TheStatus = Status::NestedInst;
  7850. return *this;
  7851. }
  7852. if (result_type == 0) {
  7853. TheStatus = Status::ZeroResultType;
  7854. return *this;
  7855. }
  7856. if (result_id == 0) {
  7857. TheStatus = Status::ZeroResultId;
  7858. return *this;
  7859. }
  7860. TheInst.reserve(6);
  7861. TheInst.emplace_back(
  7862. static_cast<uint32_t>(spv::Op::OpSubgroupShuffleDownINTEL));
  7863. TheInst.emplace_back(result_type);
  7864. TheInst.emplace_back(result_id);
  7865. TheInst.emplace_back(current);
  7866. TheInst.emplace_back(next);
  7867. TheInst.emplace_back(delta);
  7868. return *this;
  7869. }
  7870. InstBuilder &InstBuilder::opSubgroupShuffleUpINTEL(uint32_t result_type,
  7871. uint32_t result_id,
  7872. uint32_t previous,
  7873. uint32_t current,
  7874. uint32_t delta) {
  7875. if (!TheInst.empty()) {
  7876. TheStatus = Status::NestedInst;
  7877. return *this;
  7878. }
  7879. if (result_type == 0) {
  7880. TheStatus = Status::ZeroResultType;
  7881. return *this;
  7882. }
  7883. if (result_id == 0) {
  7884. TheStatus = Status::ZeroResultId;
  7885. return *this;
  7886. }
  7887. TheInst.reserve(6);
  7888. TheInst.emplace_back(
  7889. static_cast<uint32_t>(spv::Op::OpSubgroupShuffleUpINTEL));
  7890. TheInst.emplace_back(result_type);
  7891. TheInst.emplace_back(result_id);
  7892. TheInst.emplace_back(previous);
  7893. TheInst.emplace_back(current);
  7894. TheInst.emplace_back(delta);
  7895. return *this;
  7896. }
  7897. InstBuilder &InstBuilder::opSubgroupShuffleXorINTEL(uint32_t result_type,
  7898. uint32_t result_id,
  7899. uint32_t data,
  7900. uint32_t value) {
  7901. if (!TheInst.empty()) {
  7902. TheStatus = Status::NestedInst;
  7903. return *this;
  7904. }
  7905. if (result_type == 0) {
  7906. TheStatus = Status::ZeroResultType;
  7907. return *this;
  7908. }
  7909. if (result_id == 0) {
  7910. TheStatus = Status::ZeroResultId;
  7911. return *this;
  7912. }
  7913. TheInst.reserve(5);
  7914. TheInst.emplace_back(
  7915. static_cast<uint32_t>(spv::Op::OpSubgroupShuffleXorINTEL));
  7916. TheInst.emplace_back(result_type);
  7917. TheInst.emplace_back(result_id);
  7918. TheInst.emplace_back(data);
  7919. TheInst.emplace_back(value);
  7920. return *this;
  7921. }
  7922. InstBuilder &InstBuilder::opSubgroupBlockReadINTEL(uint32_t result_type,
  7923. uint32_t result_id,
  7924. uint32_t ptr) {
  7925. if (!TheInst.empty()) {
  7926. TheStatus = Status::NestedInst;
  7927. return *this;
  7928. }
  7929. if (result_type == 0) {
  7930. TheStatus = Status::ZeroResultType;
  7931. return *this;
  7932. }
  7933. if (result_id == 0) {
  7934. TheStatus = Status::ZeroResultId;
  7935. return *this;
  7936. }
  7937. TheInst.reserve(4);
  7938. TheInst.emplace_back(
  7939. static_cast<uint32_t>(spv::Op::OpSubgroupBlockReadINTEL));
  7940. TheInst.emplace_back(result_type);
  7941. TheInst.emplace_back(result_id);
  7942. TheInst.emplace_back(ptr);
  7943. return *this;
  7944. }
  7945. InstBuilder &InstBuilder::opSubgroupBlockWriteINTEL(uint32_t ptr,
  7946. uint32_t data) {
  7947. if (!TheInst.empty()) {
  7948. TheStatus = Status::NestedInst;
  7949. return *this;
  7950. }
  7951. TheInst.reserve(3);
  7952. TheInst.emplace_back(
  7953. static_cast<uint32_t>(spv::Op::OpSubgroupBlockWriteINTEL));
  7954. TheInst.emplace_back(ptr);
  7955. TheInst.emplace_back(data);
  7956. return *this;
  7957. }
  7958. InstBuilder &InstBuilder::opSubgroupImageBlockReadINTEL(uint32_t result_type,
  7959. uint32_t result_id,
  7960. uint32_t image,
  7961. uint32_t coordinate) {
  7962. if (!TheInst.empty()) {
  7963. TheStatus = Status::NestedInst;
  7964. return *this;
  7965. }
  7966. if (result_type == 0) {
  7967. TheStatus = Status::ZeroResultType;
  7968. return *this;
  7969. }
  7970. if (result_id == 0) {
  7971. TheStatus = Status::ZeroResultId;
  7972. return *this;
  7973. }
  7974. TheInst.reserve(5);
  7975. TheInst.emplace_back(
  7976. static_cast<uint32_t>(spv::Op::OpSubgroupImageBlockReadINTEL));
  7977. TheInst.emplace_back(result_type);
  7978. TheInst.emplace_back(result_id);
  7979. TheInst.emplace_back(image);
  7980. TheInst.emplace_back(coordinate);
  7981. return *this;
  7982. }
  7983. InstBuilder &InstBuilder::opSubgroupImageBlockWriteINTEL(uint32_t image,
  7984. uint32_t coordinate,
  7985. uint32_t data) {
  7986. if (!TheInst.empty()) {
  7987. TheStatus = Status::NestedInst;
  7988. return *this;
  7989. }
  7990. TheInst.reserve(4);
  7991. TheInst.emplace_back(
  7992. static_cast<uint32_t>(spv::Op::OpSubgroupImageBlockWriteINTEL));
  7993. TheInst.emplace_back(image);
  7994. TheInst.emplace_back(coordinate);
  7995. TheInst.emplace_back(data);
  7996. return *this;
  7997. }
  7998. InstBuilder &InstBuilder::opDecorateStringGOOGLE(uint32_t target,
  7999. spv::Decoration decoration) {
  8000. if (!TheInst.empty()) {
  8001. TheStatus = Status::NestedInst;
  8002. return *this;
  8003. }
  8004. TheInst.reserve(3);
  8005. TheInst.emplace_back(static_cast<uint32_t>(spv::Op::OpDecorateStringGOOGLE));
  8006. TheInst.emplace_back(target);
  8007. encodeDecoration(decoration);
  8008. return *this;
  8009. }
  8010. InstBuilder &
  8011. InstBuilder::opMemberDecorateStringGOOGLE(uint32_t struct_type, uint32_t member,
  8012. spv::Decoration decoration) {
  8013. if (!TheInst.empty()) {
  8014. TheStatus = Status::NestedInst;
  8015. return *this;
  8016. }
  8017. TheInst.reserve(4);
  8018. TheInst.emplace_back(
  8019. static_cast<uint32_t>(spv::Op::OpMemberDecorateStringGOOGLE));
  8020. TheInst.emplace_back(struct_type);
  8021. TheInst.emplace_back(member);
  8022. encodeDecoration(decoration);
  8023. return *this;
  8024. }
  8025. void InstBuilder::encodeImageOperands(spv::ImageOperandsMask value) {
  8026. if (bitEnumContains(value, spv::ImageOperandsMask::Bias)) {
  8027. Expectation.emplace_back(OperandKind::IdRef);
  8028. }
  8029. if (bitEnumContains(value, spv::ImageOperandsMask::Lod)) {
  8030. Expectation.emplace_back(OperandKind::IdRef);
  8031. }
  8032. if (bitEnumContains(value, spv::ImageOperandsMask::Grad)) {
  8033. Expectation.emplace_back(OperandKind::IdRef);
  8034. Expectation.emplace_back(OperandKind::IdRef);
  8035. }
  8036. if (bitEnumContains(value, spv::ImageOperandsMask::ConstOffset)) {
  8037. Expectation.emplace_back(OperandKind::IdRef);
  8038. }
  8039. if (bitEnumContains(value, spv::ImageOperandsMask::Offset)) {
  8040. Expectation.emplace_back(OperandKind::IdRef);
  8041. }
  8042. if (bitEnumContains(value, spv::ImageOperandsMask::ConstOffsets)) {
  8043. Expectation.emplace_back(OperandKind::IdRef);
  8044. }
  8045. if (bitEnumContains(value, spv::ImageOperandsMask::Sample)) {
  8046. Expectation.emplace_back(OperandKind::IdRef);
  8047. }
  8048. if (bitEnumContains(value, spv::ImageOperandsMask::MinLod)) {
  8049. Expectation.emplace_back(OperandKind::IdRef);
  8050. }
  8051. TheInst.emplace_back(static_cast<uint32_t>(value));
  8052. }
  8053. void InstBuilder::encodeLoopControl(spv::LoopControlMask value) {
  8054. if (bitEnumContains(value, spv::LoopControlMask::DependencyLength)) {
  8055. Expectation.emplace_back(OperandKind::LiteralInteger);
  8056. }
  8057. TheInst.emplace_back(static_cast<uint32_t>(value));
  8058. }
  8059. void InstBuilder::encodeMemoryAccess(spv::MemoryAccessMask value) {
  8060. if (bitEnumContains(value, spv::MemoryAccessMask::Aligned)) {
  8061. Expectation.emplace_back(OperandKind::LiteralInteger);
  8062. }
  8063. TheInst.emplace_back(static_cast<uint32_t>(value));
  8064. }
  8065. void InstBuilder::encodeExecutionMode(spv::ExecutionMode value) {
  8066. switch (value) {
  8067. case spv::ExecutionMode::Invocations: {
  8068. Expectation.emplace_back(OperandKind::LiteralInteger);
  8069. } break;
  8070. case spv::ExecutionMode::LocalSize: {
  8071. Expectation.emplace_back(OperandKind::LiteralInteger);
  8072. Expectation.emplace_back(OperandKind::LiteralInteger);
  8073. Expectation.emplace_back(OperandKind::LiteralInteger);
  8074. } break;
  8075. case spv::ExecutionMode::LocalSizeHint: {
  8076. Expectation.emplace_back(OperandKind::LiteralInteger);
  8077. Expectation.emplace_back(OperandKind::LiteralInteger);
  8078. Expectation.emplace_back(OperandKind::LiteralInteger);
  8079. } break;
  8080. case spv::ExecutionMode::OutputVertices: {
  8081. Expectation.emplace_back(OperandKind::LiteralInteger);
  8082. } break;
  8083. case spv::ExecutionMode::VecTypeHint: {
  8084. Expectation.emplace_back(OperandKind::LiteralInteger);
  8085. } break;
  8086. case spv::ExecutionMode::SubgroupSize: {
  8087. Expectation.emplace_back(OperandKind::LiteralInteger);
  8088. } break;
  8089. case spv::ExecutionMode::SubgroupsPerWorkgroup: {
  8090. Expectation.emplace_back(OperandKind::LiteralInteger);
  8091. } break;
  8092. case spv::ExecutionMode::SubgroupsPerWorkgroupId: {
  8093. Expectation.emplace_back(OperandKind::IdRef);
  8094. } break;
  8095. case spv::ExecutionMode::LocalSizeId: {
  8096. Expectation.emplace_back(OperandKind::IdRef);
  8097. Expectation.emplace_back(OperandKind::IdRef);
  8098. Expectation.emplace_back(OperandKind::IdRef);
  8099. } break;
  8100. case spv::ExecutionMode::LocalSizeHintId: {
  8101. Expectation.emplace_back(OperandKind::IdRef);
  8102. } break;
  8103. default:
  8104. break;
  8105. }
  8106. TheInst.emplace_back(static_cast<uint32_t>(value));
  8107. }
  8108. void InstBuilder::encodeDecoration(spv::Decoration value) {
  8109. switch (value) {
  8110. case spv::Decoration::SpecId: {
  8111. Expectation.emplace_back(OperandKind::LiteralInteger);
  8112. } break;
  8113. case spv::Decoration::ArrayStride: {
  8114. Expectation.emplace_back(OperandKind::LiteralInteger);
  8115. } break;
  8116. case spv::Decoration::MatrixStride: {
  8117. Expectation.emplace_back(OperandKind::LiteralInteger);
  8118. } break;
  8119. case spv::Decoration::BuiltIn: {
  8120. Expectation.emplace_back(OperandKind::BuiltIn);
  8121. } break;
  8122. case spv::Decoration::Stream: {
  8123. Expectation.emplace_back(OperandKind::LiteralInteger);
  8124. } break;
  8125. case spv::Decoration::Location: {
  8126. Expectation.emplace_back(OperandKind::LiteralInteger);
  8127. } break;
  8128. case spv::Decoration::Component: {
  8129. Expectation.emplace_back(OperandKind::LiteralInteger);
  8130. } break;
  8131. case spv::Decoration::Index: {
  8132. Expectation.emplace_back(OperandKind::LiteralInteger);
  8133. } break;
  8134. case spv::Decoration::Binding: {
  8135. Expectation.emplace_back(OperandKind::LiteralInteger);
  8136. } break;
  8137. case spv::Decoration::DescriptorSet: {
  8138. Expectation.emplace_back(OperandKind::LiteralInteger);
  8139. } break;
  8140. case spv::Decoration::Offset: {
  8141. Expectation.emplace_back(OperandKind::LiteralInteger);
  8142. } break;
  8143. case spv::Decoration::XfbBuffer: {
  8144. Expectation.emplace_back(OperandKind::LiteralInteger);
  8145. } break;
  8146. case spv::Decoration::XfbStride: {
  8147. Expectation.emplace_back(OperandKind::LiteralInteger);
  8148. } break;
  8149. case spv::Decoration::FuncParamAttr: {
  8150. Expectation.emplace_back(OperandKind::FunctionParameterAttribute);
  8151. } break;
  8152. case spv::Decoration::FPRoundingMode: {
  8153. Expectation.emplace_back(OperandKind::FPRoundingMode);
  8154. } break;
  8155. case spv::Decoration::FPFastMathMode: {
  8156. Expectation.emplace_back(OperandKind::FPFastMathMode);
  8157. } break;
  8158. case spv::Decoration::LinkageAttributes: {
  8159. Expectation.emplace_back(OperandKind::LiteralString);
  8160. Expectation.emplace_back(OperandKind::LinkageType);
  8161. } break;
  8162. case spv::Decoration::InputAttachmentIndex: {
  8163. Expectation.emplace_back(OperandKind::LiteralInteger);
  8164. } break;
  8165. case spv::Decoration::Alignment: {
  8166. Expectation.emplace_back(OperandKind::LiteralInteger);
  8167. } break;
  8168. case spv::Decoration::MaxByteOffset: {
  8169. Expectation.emplace_back(OperandKind::LiteralInteger);
  8170. } break;
  8171. case spv::Decoration::AlignmentId: {
  8172. Expectation.emplace_back(OperandKind::IdRef);
  8173. } break;
  8174. case spv::Decoration::MaxByteOffsetId: {
  8175. Expectation.emplace_back(OperandKind::IdRef);
  8176. } break;
  8177. case spv::Decoration::SecondaryViewportRelativeNV: {
  8178. Expectation.emplace_back(OperandKind::LiteralInteger);
  8179. } break;
  8180. case spv::Decoration::HlslCounterBufferGOOGLE: {
  8181. Expectation.emplace_back(OperandKind::IdRef);
  8182. } break;
  8183. case spv::Decoration::HlslSemanticGOOGLE: {
  8184. Expectation.emplace_back(OperandKind::LiteralString);
  8185. } break;
  8186. default:
  8187. break;
  8188. }
  8189. TheInst.emplace_back(static_cast<uint32_t>(value));
  8190. }
  8191. InstBuilder &InstBuilder::fPFastMathMode(spv::FPFastMathModeMask value) {
  8192. if (Expectation.front() != OperandKind::FPFastMathMode) {
  8193. TheStatus = Status::ExpectFPFastMathMode;
  8194. return *this;
  8195. }
  8196. Expectation.pop_front();
  8197. TheInst.emplace_back(static_cast<uint32_t>(value));
  8198. return *this;
  8199. }
  8200. InstBuilder &InstBuilder::fPRoundingMode(spv::FPRoundingMode value) {
  8201. if (Expectation.front() != OperandKind::FPRoundingMode) {
  8202. TheStatus = Status::ExpectFPRoundingMode;
  8203. return *this;
  8204. }
  8205. Expectation.pop_front();
  8206. TheInst.emplace_back(static_cast<uint32_t>(value));
  8207. return *this;
  8208. }
  8209. InstBuilder &InstBuilder::linkageType(spv::LinkageType value) {
  8210. if (Expectation.front() != OperandKind::LinkageType) {
  8211. TheStatus = Status::ExpectLinkageType;
  8212. return *this;
  8213. }
  8214. Expectation.pop_front();
  8215. TheInst.emplace_back(static_cast<uint32_t>(value));
  8216. return *this;
  8217. }
  8218. InstBuilder &
  8219. InstBuilder::functionParameterAttribute(spv::FunctionParameterAttribute value) {
  8220. if (Expectation.front() != OperandKind::FunctionParameterAttribute) {
  8221. TheStatus = Status::ExpectFunctionParameterAttribute;
  8222. return *this;
  8223. }
  8224. Expectation.pop_front();
  8225. TheInst.emplace_back(static_cast<uint32_t>(value));
  8226. return *this;
  8227. }
  8228. InstBuilder &InstBuilder::builtIn(spv::BuiltIn value) {
  8229. if (Expectation.front() != OperandKind::BuiltIn) {
  8230. TheStatus = Status::ExpectBuiltIn;
  8231. return *this;
  8232. }
  8233. Expectation.pop_front();
  8234. TheInst.emplace_back(static_cast<uint32_t>(value));
  8235. return *this;
  8236. }
  8237. InstBuilder &InstBuilder::idRef(uint32_t value) {
  8238. if (Expectation.front() != OperandKind::IdRef) {
  8239. TheStatus = Status::ExpectIdRef;
  8240. return *this;
  8241. }
  8242. Expectation.pop_front();
  8243. TheInst.emplace_back(value);
  8244. return *this;
  8245. }
  8246. InstBuilder &InstBuilder::literalInteger(uint32_t value) {
  8247. if (Expectation.front() != OperandKind::LiteralInteger) {
  8248. TheStatus = Status::ExpectLiteralInteger;
  8249. return *this;
  8250. }
  8251. Expectation.pop_front();
  8252. TheInst.emplace_back(value);
  8253. return *this;
  8254. }
  8255. InstBuilder &InstBuilder::literalString(std::string value) {
  8256. if (Expectation.front() != OperandKind::LiteralString) {
  8257. TheStatus = Status::ExpectLiteralString;
  8258. return *this;
  8259. }
  8260. Expectation.pop_front();
  8261. encodeString(value);
  8262. return *this;
  8263. }
  8264. } // end namespace spirv
  8265. } // end namespace clang