LangRef.rst 620 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534253525362537253825392540254125422543254425452546254725482549255025512552255325542555255625572558255925602561256225632564256525662567256825692570257125722573257425752576257725782579258025812582258325842585258625872588258925902591259225932594259525962597259825992600260126022603260426052606260726082609261026112612261326142615261626172618261926202621262226232624262526262627262826292630263126322633263426352636263726382639264026412642264326442645264626472648264926502651265226532654265526562657265826592660266126622663266426652666266726682669267026712672267326742675267626772678267926802681268226832684268526862687268826892690269126922693269426952696269726982699270027012702270327042705270627072708270927102711271227132714271527162717271827192720272127222723272427252726272727282729273027312732273327342735273627372738273927402741274227432744274527462747274827492750275127522753275427552756275727582759276027612762276327642765276627672768276927702771277227732774277527762777277827792780278127822783278427852786278727882789279027912792279327942795279627972798279928002801280228032804280528062807280828092810281128122813281428152816281728182819282028212822282328242825282628272828282928302831283228332834283528362837283828392840284128422843284428452846284728482849285028512852285328542855285628572858285928602861286228632864286528662867286828692870287128722873287428752876287728782879288028812882288328842885288628872888288928902891289228932894289528962897289828992900290129022903290429052906290729082909291029112912291329142915291629172918291929202921292229232924292529262927292829292930293129322933293429352936293729382939294029412942294329442945294629472948294929502951295229532954295529562957295829592960296129622963296429652966296729682969297029712972297329742975297629772978297929802981298229832984298529862987298829892990299129922993299429952996299729982999300030013002300330043005300630073008300930103011301230133014301530163017301830193020302130223023302430253026302730283029303030313032303330343035303630373038303930403041304230433044304530463047304830493050305130523053305430553056305730583059306030613062306330643065306630673068306930703071307230733074307530763077307830793080308130823083308430853086308730883089309030913092309330943095309630973098309931003101310231033104310531063107310831093110311131123113311431153116311731183119312031213122312331243125312631273128312931303131313231333134313531363137313831393140314131423143314431453146314731483149315031513152315331543155315631573158315931603161316231633164316531663167316831693170317131723173317431753176317731783179318031813182318331843185318631873188318931903191319231933194319531963197319831993200320132023203320432053206320732083209321032113212321332143215321632173218321932203221322232233224322532263227322832293230323132323233323432353236323732383239324032413242324332443245324632473248324932503251325232533254325532563257325832593260326132623263326432653266326732683269327032713272327332743275327632773278327932803281328232833284328532863287328832893290329132923293329432953296329732983299330033013302330333043305330633073308330933103311331233133314331533163317331833193320332133223323332433253326332733283329333033313332333333343335333633373338333933403341334233433344334533463347334833493350335133523353335433553356335733583359336033613362336333643365336633673368336933703371337233733374337533763377337833793380338133823383338433853386338733883389339033913392339333943395339633973398339934003401340234033404340534063407340834093410341134123413341434153416341734183419342034213422342334243425342634273428342934303431343234333434343534363437343834393440344134423443344434453446344734483449345034513452345334543455345634573458345934603461346234633464346534663467346834693470347134723473347434753476347734783479348034813482348334843485348634873488348934903491349234933494349534963497349834993500350135023503350435053506350735083509351035113512351335143515351635173518351935203521352235233524352535263527352835293530353135323533353435353536353735383539354035413542354335443545354635473548354935503551355235533554355535563557355835593560356135623563356435653566356735683569357035713572357335743575357635773578357935803581358235833584358535863587358835893590359135923593359435953596359735983599360036013602360336043605360636073608360936103611361236133614361536163617361836193620362136223623362436253626362736283629363036313632363336343635363636373638363936403641364236433644364536463647364836493650365136523653365436553656365736583659366036613662366336643665366636673668366936703671367236733674367536763677367836793680368136823683368436853686368736883689369036913692369336943695369636973698369937003701370237033704370537063707370837093710371137123713371437153716371737183719372037213722372337243725372637273728372937303731373237333734373537363737373837393740374137423743374437453746374737483749375037513752375337543755375637573758375937603761376237633764376537663767376837693770377137723773377437753776377737783779378037813782378337843785378637873788378937903791379237933794379537963797379837993800380138023803380438053806380738083809381038113812381338143815381638173818381938203821382238233824382538263827382838293830383138323833383438353836383738383839384038413842384338443845384638473848384938503851385238533854385538563857385838593860386138623863386438653866386738683869387038713872387338743875387638773878387938803881388238833884388538863887388838893890389138923893389438953896389738983899390039013902390339043905390639073908390939103911391239133914391539163917391839193920392139223923392439253926392739283929393039313932393339343935393639373938393939403941394239433944394539463947394839493950395139523953395439553956395739583959396039613962396339643965396639673968396939703971397239733974397539763977397839793980398139823983398439853986398739883989399039913992399339943995399639973998399940004001400240034004400540064007400840094010401140124013401440154016401740184019402040214022402340244025402640274028402940304031403240334034403540364037403840394040404140424043404440454046404740484049405040514052405340544055405640574058405940604061406240634064406540664067406840694070407140724073407440754076407740784079408040814082408340844085408640874088408940904091409240934094409540964097409840994100410141024103410441054106410741084109411041114112411341144115411641174118411941204121412241234124412541264127412841294130413141324133413441354136413741384139414041414142414341444145414641474148414941504151415241534154415541564157415841594160416141624163416441654166416741684169417041714172417341744175417641774178417941804181418241834184418541864187418841894190419141924193419441954196419741984199420042014202420342044205420642074208420942104211421242134214421542164217421842194220422142224223422442254226422742284229423042314232423342344235423642374238423942404241424242434244424542464247424842494250425142524253425442554256425742584259426042614262426342644265426642674268426942704271427242734274427542764277427842794280428142824283428442854286428742884289429042914292429342944295429642974298429943004301430243034304430543064307430843094310431143124313431443154316431743184319432043214322432343244325432643274328432943304331433243334334433543364337433843394340434143424343434443454346434743484349435043514352435343544355435643574358435943604361436243634364436543664367436843694370437143724373437443754376437743784379438043814382438343844385438643874388438943904391439243934394439543964397439843994400440144024403440444054406440744084409441044114412441344144415441644174418441944204421442244234424442544264427442844294430443144324433443444354436443744384439444044414442444344444445444644474448444944504451445244534454445544564457445844594460446144624463446444654466446744684469447044714472447344744475447644774478447944804481448244834484448544864487448844894490449144924493449444954496449744984499450045014502450345044505450645074508450945104511451245134514451545164517451845194520452145224523452445254526452745284529453045314532453345344535453645374538453945404541454245434544454545464547454845494550455145524553455445554556455745584559456045614562456345644565456645674568456945704571457245734574457545764577457845794580458145824583458445854586458745884589459045914592459345944595459645974598459946004601460246034604460546064607460846094610461146124613461446154616461746184619462046214622462346244625462646274628462946304631463246334634463546364637463846394640464146424643464446454646464746484649465046514652465346544655465646574658465946604661466246634664466546664667466846694670467146724673467446754676467746784679468046814682468346844685468646874688468946904691469246934694469546964697469846994700470147024703470447054706470747084709471047114712471347144715471647174718471947204721472247234724472547264727472847294730473147324733473447354736473747384739474047414742474347444745474647474748474947504751475247534754475547564757475847594760476147624763476447654766476747684769477047714772477347744775477647774778477947804781478247834784478547864787478847894790479147924793479447954796479747984799480048014802480348044805480648074808480948104811481248134814481548164817481848194820482148224823482448254826482748284829483048314832483348344835483648374838483948404841484248434844484548464847484848494850485148524853485448554856485748584859486048614862486348644865486648674868486948704871487248734874487548764877487848794880488148824883488448854886488748884889489048914892489348944895489648974898489949004901490249034904490549064907490849094910491149124913491449154916491749184919492049214922492349244925492649274928492949304931493249334934493549364937493849394940494149424943494449454946494749484949495049514952495349544955495649574958495949604961496249634964496549664967496849694970497149724973497449754976497749784979498049814982498349844985498649874988498949904991499249934994499549964997499849995000500150025003500450055006500750085009501050115012501350145015501650175018501950205021502250235024502550265027502850295030503150325033503450355036503750385039504050415042504350445045504650475048504950505051505250535054505550565057505850595060506150625063506450655066506750685069507050715072507350745075507650775078507950805081508250835084508550865087508850895090509150925093509450955096509750985099510051015102510351045105510651075108510951105111511251135114511551165117511851195120512151225123512451255126512751285129513051315132513351345135513651375138513951405141514251435144514551465147514851495150515151525153515451555156515751585159516051615162516351645165516651675168516951705171517251735174517551765177517851795180518151825183518451855186518751885189519051915192519351945195519651975198519952005201520252035204520552065207520852095210521152125213521452155216521752185219522052215222522352245225522652275228522952305231523252335234523552365237523852395240524152425243524452455246524752485249525052515252525352545255525652575258525952605261526252635264526552665267526852695270527152725273527452755276527752785279528052815282528352845285528652875288528952905291529252935294529552965297529852995300530153025303530453055306530753085309531053115312531353145315531653175318531953205321532253235324532553265327532853295330533153325333533453355336533753385339534053415342534353445345534653475348534953505351535253535354535553565357535853595360536153625363536453655366536753685369537053715372537353745375537653775378537953805381538253835384538553865387538853895390539153925393539453955396539753985399540054015402540354045405540654075408540954105411541254135414541554165417541854195420542154225423542454255426542754285429543054315432543354345435543654375438543954405441544254435444544554465447544854495450545154525453545454555456545754585459546054615462546354645465546654675468546954705471547254735474547554765477547854795480548154825483548454855486548754885489549054915492549354945495549654975498549955005501550255035504550555065507550855095510551155125513551455155516551755185519552055215522552355245525552655275528552955305531553255335534553555365537553855395540554155425543554455455546554755485549555055515552555355545555555655575558555955605561556255635564556555665567556855695570557155725573557455755576557755785579558055815582558355845585558655875588558955905591559255935594559555965597559855995600560156025603560456055606560756085609561056115612561356145615561656175618561956205621562256235624562556265627562856295630563156325633563456355636563756385639564056415642564356445645564656475648564956505651565256535654565556565657565856595660566156625663566456655666566756685669567056715672567356745675567656775678567956805681568256835684568556865687568856895690569156925693569456955696569756985699570057015702570357045705570657075708570957105711571257135714571557165717571857195720572157225723572457255726572757285729573057315732573357345735573657375738573957405741574257435744574557465747574857495750575157525753575457555756575757585759576057615762576357645765576657675768576957705771577257735774577557765777577857795780578157825783578457855786578757885789579057915792579357945795579657975798579958005801580258035804580558065807580858095810581158125813581458155816581758185819582058215822582358245825582658275828582958305831583258335834583558365837583858395840584158425843584458455846584758485849585058515852585358545855585658575858585958605861586258635864586558665867586858695870587158725873587458755876587758785879588058815882588358845885588658875888588958905891589258935894589558965897589858995900590159025903590459055906590759085909591059115912591359145915591659175918591959205921592259235924592559265927592859295930593159325933593459355936593759385939594059415942594359445945594659475948594959505951595259535954595559565957595859595960596159625963596459655966596759685969597059715972597359745975597659775978597959805981598259835984598559865987598859895990599159925993599459955996599759985999600060016002600360046005600660076008600960106011601260136014601560166017601860196020602160226023602460256026602760286029603060316032603360346035603660376038603960406041604260436044604560466047604860496050605160526053605460556056605760586059606060616062606360646065606660676068606960706071607260736074607560766077607860796080608160826083608460856086608760886089609060916092609360946095609660976098609961006101610261036104610561066107610861096110611161126113611461156116611761186119612061216122612361246125612661276128612961306131613261336134613561366137613861396140614161426143614461456146614761486149615061516152615361546155615661576158615961606161616261636164616561666167616861696170617161726173617461756176617761786179618061816182618361846185618661876188618961906191619261936194619561966197619861996200620162026203620462056206620762086209621062116212621362146215621662176218621962206221622262236224622562266227622862296230623162326233623462356236623762386239624062416242624362446245624662476248624962506251625262536254625562566257625862596260626162626263626462656266626762686269627062716272627362746275627662776278627962806281628262836284628562866287628862896290629162926293629462956296629762986299630063016302630363046305630663076308630963106311631263136314631563166317631863196320632163226323632463256326632763286329633063316332633363346335633663376338633963406341634263436344634563466347634863496350635163526353635463556356635763586359636063616362636363646365636663676368636963706371637263736374637563766377637863796380638163826383638463856386638763886389639063916392639363946395639663976398639964006401640264036404640564066407640864096410641164126413641464156416641764186419642064216422642364246425642664276428642964306431643264336434643564366437643864396440644164426443644464456446644764486449645064516452645364546455645664576458645964606461646264636464646564666467646864696470647164726473647464756476647764786479648064816482648364846485648664876488648964906491649264936494649564966497649864996500650165026503650465056506650765086509651065116512651365146515651665176518651965206521652265236524652565266527652865296530653165326533653465356536653765386539654065416542654365446545654665476548654965506551655265536554655565566557655865596560656165626563656465656566656765686569657065716572657365746575657665776578657965806581658265836584658565866587658865896590659165926593659465956596659765986599660066016602660366046605660666076608660966106611661266136614661566166617661866196620662166226623662466256626662766286629663066316632663366346635663666376638663966406641664266436644664566466647664866496650665166526653665466556656665766586659666066616662666366646665666666676668666966706671667266736674667566766677667866796680668166826683668466856686668766886689669066916692669366946695669666976698669967006701670267036704670567066707670867096710671167126713671467156716671767186719672067216722672367246725672667276728672967306731673267336734673567366737673867396740674167426743674467456746674767486749675067516752675367546755675667576758675967606761676267636764676567666767676867696770677167726773677467756776677767786779678067816782678367846785678667876788678967906791679267936794679567966797679867996800680168026803680468056806680768086809681068116812681368146815681668176818681968206821682268236824682568266827682868296830683168326833683468356836683768386839684068416842684368446845684668476848684968506851685268536854685568566857685868596860686168626863686468656866686768686869687068716872687368746875687668776878687968806881688268836884688568866887688868896890689168926893689468956896689768986899690069016902690369046905690669076908690969106911691269136914691569166917691869196920692169226923692469256926692769286929693069316932693369346935693669376938693969406941694269436944694569466947694869496950695169526953695469556956695769586959696069616962696369646965696669676968696969706971697269736974697569766977697869796980698169826983698469856986698769886989699069916992699369946995699669976998699970007001700270037004700570067007700870097010701170127013701470157016701770187019702070217022702370247025702670277028702970307031703270337034703570367037703870397040704170427043704470457046704770487049705070517052705370547055705670577058705970607061706270637064706570667067706870697070707170727073707470757076707770787079708070817082708370847085708670877088708970907091709270937094709570967097709870997100710171027103710471057106710771087109711071117112711371147115711671177118711971207121712271237124712571267127712871297130713171327133713471357136713771387139714071417142714371447145714671477148714971507151715271537154715571567157715871597160716171627163716471657166716771687169717071717172717371747175717671777178717971807181718271837184718571867187718871897190719171927193719471957196719771987199720072017202720372047205720672077208720972107211721272137214721572167217721872197220722172227223722472257226722772287229723072317232723372347235723672377238723972407241724272437244724572467247724872497250725172527253725472557256725772587259726072617262726372647265726672677268726972707271727272737274727572767277727872797280728172827283728472857286728772887289729072917292729372947295729672977298729973007301730273037304730573067307730873097310731173127313731473157316731773187319732073217322732373247325732673277328732973307331733273337334733573367337733873397340734173427343734473457346734773487349735073517352735373547355735673577358735973607361736273637364736573667367736873697370737173727373737473757376737773787379738073817382738373847385738673877388738973907391739273937394739573967397739873997400740174027403740474057406740774087409741074117412741374147415741674177418741974207421742274237424742574267427742874297430743174327433743474357436743774387439744074417442744374447445744674477448744974507451745274537454745574567457745874597460746174627463746474657466746774687469747074717472747374747475747674777478747974807481748274837484748574867487748874897490749174927493749474957496749774987499750075017502750375047505750675077508750975107511751275137514751575167517751875197520752175227523752475257526752775287529753075317532753375347535753675377538753975407541754275437544754575467547754875497550755175527553755475557556755775587559756075617562756375647565756675677568756975707571757275737574757575767577757875797580758175827583758475857586758775887589759075917592759375947595759675977598759976007601760276037604760576067607760876097610761176127613761476157616761776187619762076217622762376247625762676277628762976307631763276337634763576367637763876397640764176427643764476457646764776487649765076517652765376547655765676577658765976607661766276637664766576667667766876697670767176727673767476757676767776787679768076817682768376847685768676877688768976907691769276937694769576967697769876997700770177027703770477057706770777087709771077117712771377147715771677177718771977207721772277237724772577267727772877297730773177327733773477357736773777387739774077417742774377447745774677477748774977507751775277537754775577567757775877597760776177627763776477657766776777687769777077717772777377747775777677777778777977807781778277837784778577867787778877897790779177927793779477957796779777987799780078017802780378047805780678077808780978107811781278137814781578167817781878197820782178227823782478257826782778287829783078317832783378347835783678377838783978407841784278437844784578467847784878497850785178527853785478557856785778587859786078617862786378647865786678677868786978707871787278737874787578767877787878797880788178827883788478857886788778887889789078917892789378947895789678977898789979007901790279037904790579067907790879097910791179127913791479157916791779187919792079217922792379247925792679277928792979307931793279337934793579367937793879397940794179427943794479457946794779487949795079517952795379547955795679577958795979607961796279637964796579667967796879697970797179727973797479757976797779787979798079817982798379847985798679877988798979907991799279937994799579967997799879998000800180028003800480058006800780088009801080118012801380148015801680178018801980208021802280238024802580268027802880298030803180328033803480358036803780388039804080418042804380448045804680478048804980508051805280538054805580568057805880598060806180628063806480658066806780688069807080718072807380748075807680778078807980808081808280838084808580868087808880898090809180928093809480958096809780988099810081018102810381048105810681078108810981108111811281138114811581168117811881198120812181228123812481258126812781288129813081318132813381348135813681378138813981408141814281438144814581468147814881498150815181528153815481558156815781588159816081618162816381648165816681678168816981708171817281738174817581768177817881798180818181828183818481858186818781888189819081918192819381948195819681978198819982008201820282038204820582068207820882098210821182128213821482158216821782188219822082218222822382248225822682278228822982308231823282338234823582368237823882398240824182428243824482458246824782488249825082518252825382548255825682578258825982608261826282638264826582668267826882698270827182728273827482758276827782788279828082818282828382848285828682878288828982908291829282938294829582968297829882998300830183028303830483058306830783088309831083118312831383148315831683178318831983208321832283238324832583268327832883298330833183328333833483358336833783388339834083418342834383448345834683478348834983508351835283538354835583568357835883598360836183628363836483658366836783688369837083718372837383748375837683778378837983808381838283838384838583868387838883898390839183928393839483958396839783988399840084018402840384048405840684078408840984108411841284138414841584168417841884198420842184228423842484258426842784288429843084318432843384348435843684378438843984408441844284438444844584468447844884498450845184528453845484558456845784588459846084618462846384648465846684678468846984708471847284738474847584768477847884798480848184828483848484858486848784888489849084918492849384948495849684978498849985008501850285038504850585068507850885098510851185128513851485158516851785188519852085218522852385248525852685278528852985308531853285338534853585368537853885398540854185428543854485458546854785488549855085518552855385548555855685578558855985608561856285638564856585668567856885698570857185728573857485758576857785788579858085818582858385848585858685878588858985908591859285938594859585968597859885998600860186028603860486058606860786088609861086118612861386148615861686178618861986208621862286238624862586268627862886298630863186328633863486358636863786388639864086418642864386448645864686478648864986508651865286538654865586568657865886598660866186628663866486658666866786688669867086718672867386748675867686778678867986808681868286838684868586868687868886898690869186928693869486958696869786988699870087018702870387048705870687078708870987108711871287138714871587168717871887198720872187228723872487258726872787288729873087318732873387348735873687378738873987408741874287438744874587468747874887498750875187528753875487558756875787588759876087618762876387648765876687678768876987708771877287738774877587768777877887798780878187828783878487858786878787888789879087918792879387948795879687978798879988008801880288038804880588068807880888098810881188128813881488158816881788188819882088218822882388248825882688278828882988308831883288338834883588368837883888398840884188428843884488458846884788488849885088518852885388548855885688578858885988608861886288638864886588668867886888698870887188728873887488758876887788788879888088818882888388848885888688878888888988908891889288938894889588968897889888998900890189028903890489058906890789088909891089118912891389148915891689178918891989208921892289238924892589268927892889298930893189328933893489358936893789388939894089418942894389448945894689478948894989508951895289538954895589568957895889598960896189628963896489658966896789688969897089718972897389748975897689778978897989808981898289838984898589868987898889898990899189928993899489958996899789988999900090019002900390049005900690079008900990109011901290139014901590169017901890199020902190229023902490259026902790289029903090319032903390349035903690379038903990409041904290439044904590469047904890499050905190529053905490559056905790589059906090619062906390649065906690679068906990709071907290739074907590769077907890799080908190829083908490859086908790889089909090919092909390949095909690979098909991009101910291039104910591069107910891099110911191129113911491159116911791189119912091219122912391249125912691279128912991309131913291339134913591369137913891399140914191429143914491459146914791489149915091519152915391549155915691579158915991609161916291639164916591669167916891699170917191729173917491759176917791789179918091819182918391849185918691879188918991909191919291939194919591969197919891999200920192029203920492059206920792089209921092119212921392149215921692179218921992209221922292239224922592269227922892299230923192329233923492359236923792389239924092419242924392449245924692479248924992509251925292539254925592569257925892599260926192629263926492659266926792689269927092719272927392749275927692779278927992809281928292839284928592869287928892899290929192929293929492959296929792989299930093019302930393049305930693079308930993109311931293139314931593169317931893199320932193229323932493259326932793289329933093319332933393349335933693379338933993409341934293439344934593469347934893499350935193529353935493559356935793589359936093619362936393649365936693679368936993709371937293739374937593769377937893799380938193829383938493859386938793889389939093919392939393949395939693979398939994009401940294039404940594069407940894099410941194129413941494159416941794189419942094219422942394249425942694279428942994309431943294339434943594369437943894399440944194429443944494459446944794489449945094519452945394549455945694579458945994609461946294639464946594669467946894699470947194729473947494759476947794789479948094819482948394849485948694879488948994909491949294939494949594969497949894999500950195029503950495059506950795089509951095119512951395149515951695179518951995209521952295239524952595269527952895299530953195329533953495359536953795389539954095419542954395449545954695479548954995509551955295539554955595569557955895599560956195629563956495659566956795689569957095719572957395749575957695779578957995809581958295839584958595869587958895899590959195929593959495959596959795989599960096019602960396049605960696079608960996109611961296139614961596169617961896199620962196229623962496259626962796289629963096319632963396349635963696379638963996409641964296439644964596469647964896499650965196529653965496559656965796589659966096619662966396649665966696679668966996709671967296739674967596769677967896799680968196829683968496859686968796889689969096919692969396949695969696979698969997009701970297039704970597069707970897099710971197129713971497159716971797189719972097219722972397249725972697279728972997309731973297339734973597369737973897399740974197429743974497459746974797489749975097519752975397549755975697579758975997609761976297639764976597669767976897699770977197729773977497759776977797789779978097819782978397849785978697879788978997909791979297939794979597969797979897999800980198029803980498059806980798089809981098119812981398149815981698179818981998209821982298239824982598269827982898299830983198329833983498359836983798389839984098419842984398449845984698479848984998509851985298539854985598569857985898599860986198629863986498659866986798689869987098719872987398749875987698779878987998809881988298839884988598869887988898899890989198929893989498959896989798989899990099019902990399049905990699079908990999109911991299139914991599169917991899199920992199229923992499259926992799289929993099319932993399349935993699379938993999409941994299439944994599469947994899499950995199529953995499559956995799589959996099619962996399649965996699679968996999709971997299739974997599769977997899799980998199829983998499859986998799889989999099919992999399949995999699979998999910000100011000210003100041000510006100071000810009100101001110012100131001410015100161001710018100191002010021100221002310024100251002610027100281002910030100311003210033100341003510036100371003810039100401004110042100431004410045100461004710048100491005010051100521005310054100551005610057100581005910060100611006210063100641006510066100671006810069100701007110072100731007410075100761007710078100791008010081100821008310084100851008610087100881008910090100911009210093100941009510096100971009810099101001010110102101031010410105101061010710108101091011010111101121011310114101151011610117101181011910120101211012210123101241012510126101271012810129101301013110132101331013410135101361013710138101391014010141101421014310144101451014610147101481014910150101511015210153101541015510156101571015810159101601016110162101631016410165101661016710168101691017010171101721017310174101751017610177101781017910180101811018210183101841018510186101871018810189101901019110192101931019410195101961019710198101991020010201102021020310204102051020610207102081020910210102111021210213102141021510216102171021810219102201022110222102231022410225102261022710228102291023010231102321023310234102351023610237102381023910240102411024210243102441024510246102471024810249102501025110252102531025410255102561025710258102591026010261102621026310264102651026610267102681026910270102711027210273102741027510276102771027810279102801028110282102831028410285102861028710288102891029010291102921029310294102951029610297102981029910300103011030210303103041030510306103071030810309103101031110312103131031410315103161031710318103191032010321103221032310324103251032610327103281032910330103311033210333103341033510336103371033810339103401034110342103431034410345103461034710348103491035010351103521035310354103551035610357103581035910360103611036210363103641036510366103671036810369103701037110372103731037410375103761037710378103791038010381103821038310384103851038610387103881038910390103911039210393103941039510396103971039810399104001040110402104031040410405104061040710408104091041010411104121041310414104151041610417104181041910420104211042210423104241042510426104271042810429104301043110432104331043410435104361043710438104391044010441104421044310444104451044610447104481044910450104511045210453104541045510456104571045810459104601046110462104631046410465104661046710468104691047010471104721047310474104751047610477104781047910480104811048210483104841048510486104871048810489104901049110492104931049410495104961049710498104991050010501105021050310504105051050610507105081050910510105111051210513105141051510516105171051810519105201052110522105231052410525105261052710528105291053010531105321053310534105351053610537105381053910540105411054210543105441054510546105471054810549105501055110552105531055410555105561055710558105591056010561105621056310564105651056610567105681056910570105711057210573105741057510576105771057810579105801058110582105831058410585105861058710588105891059010591105921059310594105951059610597105981059910600106011060210603106041060510606106071060810609106101061110612106131061410615106161061710618106191062010621106221062310624106251062610627106281062910630106311063210633106341063510636106371063810639106401064110642106431064410645106461064710648106491065010651106521065310654106551065610657106581065910660106611066210663106641066510666106671066810669106701067110672106731067410675106761067710678106791068010681106821068310684106851068610687106881068910690106911069210693106941069510696106971069810699107001070110702107031070410705107061070710708107091071010711107121071310714107151071610717107181071910720107211072210723107241072510726107271072810729107301073110732107331073410735107361073710738107391074010741107421074310744107451074610747107481074910750107511075210753107541075510756107571075810759107601076110762107631076410765107661076710768107691077010771107721077310774107751077610777107781077910780107811078210783107841078510786107871078810789107901079110792107931079410795107961079710798107991080010801108021080310804108051080610807108081080910810108111081210813108141081510816108171081810819108201082110822108231082410825108261082710828108291083010831108321083310834108351083610837108381083910840108411084210843108441084510846108471084810849108501085110852108531085410855108561085710858108591086010861108621086310864108651086610867108681086910870108711087210873108741087510876108771087810879108801088110882108831088410885108861088710888108891089010891108921089310894108951089610897108981089910900109011090210903109041090510906109071090810909109101091110912109131091410915109161091710918109191092010921109221092310924109251092610927109281092910930109311093210933109341093510936109371093810939109401094110942109431094410945109461094710948109491095010951109521095310954109551095610957109581095910960109611096210963109641096510966109671096810969109701097110972109731097410975109761097710978109791098010981109821098310984109851098610987109881098910990109911099210993109941099510996109971099810999110001100111002110031100411005110061100711008110091101011011110121101311014110151101611017110181101911020110211102211023110241102511026110271102811029110301103111032110331103411035110361103711038110391104011041110421104311044110451104611047110481104911050110511105211053110541105511056110571105811059110601106111062110631106411065110661106711068110691107011071110721107311074110751107611077110781107911080110811108211083110841108511086110871108811089110901109111092110931109411095110961109711098110991110011101111021110311104111051110611107111081110911110111111111211113111141111511116111171111811119111201112111122111231112411125111261112711128111291113011131111321113311134111351113611137111381113911140111411114211143111441114511146111471114811149111501115111152111531115411155111561115711158111591116011161111621116311164111651116611167111681116911170111711117211173111741117511176111771117811179111801118111182111831118411185111861118711188111891119011191111921119311194111951119611197111981119911200112011120211203112041120511206112071120811209112101121111212112131121411215112161121711218112191122011221112221122311224112251122611227112281122911230112311123211233112341123511236112371123811239112401124111242112431124411245112461124711248112491125011251112521125311254112551125611257112581125911260112611126211263112641126511266112671126811269112701127111272112731127411275112761127711278112791128011281112821128311284112851128611287112881128911290112911129211293112941129511296112971129811299113001130111302113031130411305113061130711308113091131011311113121131311314113151131611317113181131911320113211132211323113241132511326113271132811329113301133111332113331133411335113361133711338113391134011341113421134311344113451134611347113481134911350113511135211353113541135511356113571135811359113601136111362113631136411365113661136711368113691137011371113721137311374113751137611377113781137911380113811138211383113841138511386113871138811389113901139111392113931139411395113961139711398113991140011401114021140311404114051140611407114081140911410114111141211413114141141511416114171141811419114201142111422114231142411425114261142711428114291143011431114321143311434114351143611437114381143911440114411144211443114441144511446114471144811449114501145111452114531145411455114561145711458114591146011461114621146311464114651146611467114681146911470114711147211473114741147511476114771147811479114801148111482114831148411485114861148711488114891149011491114921149311494114951149611497114981149911500115011150211503115041150511506115071150811509115101151111512115131151411515115161151711518115191152011521115221152311524115251152611527115281152911530115311153211533115341153511536115371153811539115401154111542115431154411545115461154711548115491155011551115521155311554115551155611557115581155911560115611156211563115641156511566115671156811569115701157111572115731157411575115761157711578115791158011581115821158311584115851158611587115881158911590115911159211593115941159511596115971159811599116001160111602116031160411605116061160711608116091161011611116121161311614116151161611617116181161911620116211162211623116241162511626116271162811629116301163111632116331163411635116361163711638116391164011641116421164311644116451164611647116481164911650116511165211653116541165511656116571165811659116601166111662116631166411665116661166711668116691167011671116721167311674116751167611677116781167911680116811168211683116841168511686116871168811689116901169111692116931169411695116961169711698116991170011701117021170311704117051170611707117081170911710117111171211713117141171511716117171171811719117201172111722117231172411725117261172711728117291173011731117321173311734117351173611737117381173911740117411174211743117441174511746117471174811749117501175111752117531175411755117561175711758117591176011761117621176311764117651176611767117681176911770117711177211773117741177511776117771177811779117801178111782117831178411785117861178711788117891179011791117921179311794117951179611797117981179911800118011180211803118041180511806118071180811809118101181111812118131181411815118161181711818118191182011821118221182311824118251182611827118281182911830118311183211833118341183511836118371183811839118401184111842118431184411845118461184711848118491185011851118521185311854118551185611857118581185911860118611186211863118641186511866118671186811869118701187111872118731187411875118761187711878118791188011881118821188311884118851188611887118881188911890118911189211893118941189511896118971189811899119001190111902119031190411905119061190711908119091191011911119121191311914119151191611917119181191911920119211192211923119241192511926119271192811929119301193111932119331193411935119361193711938119391194011941119421194311944119451194611947119481194911950119511195211953119541195511956119571195811959119601196111962119631196411965119661196711968119691197011971119721197311974119751197611977119781197911980119811198211983119841198511986119871198811989119901199111992119931199411995119961199711998119991200012001120021200312004120051200612007120081200912010120111201212013120141201512016120171201812019120201202112022120231202412025120261202712028120291203012031120321203312034120351203612037120381203912040120411204212043120441204512046120471204812049120501205112052120531205412055120561205712058120591206012061120621206312064120651206612067120681206912070120711207212073120741207512076120771207812079120801208112082120831208412085120861208712088120891209012091120921209312094120951209612097120981209912100121011210212103121041210512106121071210812109121101211112112121131211412115121161211712118121191212012121121221212312124121251212612127121281212912130121311213212133121341213512136121371213812139121401214112142121431214412145121461214712148121491215012151121521215312154121551215612157121581215912160121611216212163121641216512166121671216812169121701217112172121731217412175121761217712178121791218012181121821218312184121851218612187121881218912190121911219212193121941219512196121971219812199122001220112202122031220412205122061220712208122091221012211122121221312214122151221612217122181221912220122211222212223122241222512226122271222812229122301223112232122331223412235122361223712238122391224012241122421224312244122451224612247122481224912250122511225212253122541225512256122571225812259122601226112262122631226412265122661226712268122691227012271122721227312274122751227612277122781227912280122811228212283122841228512286122871228812289122901229112292122931229412295122961229712298122991230012301123021230312304123051230612307123081230912310123111231212313123141231512316123171231812319123201232112322123231232412325123261232712328123291233012331123321233312334123351233612337123381233912340123411234212343123441234512346123471234812349123501235112352123531235412355123561235712358123591236012361123621236312364123651236612367123681236912370123711237212373123741237512376123771237812379123801238112382123831238412385123861238712388123891239012391123921239312394123951239612397123981239912400124011240212403124041240512406124071240812409124101241112412124131241412415124161241712418124191242012421124221242312424124251242612427124281242912430124311243212433124341243512436124371243812439124401244112442124431244412445124461244712448124491245012451124521245312454124551245612457124581245912460124611246212463124641246512466124671246812469124701247112472124731247412475124761247712478124791248012481124821248312484124851248612487124881248912490124911249212493124941249512496124971249812499125001250112502125031250412505125061250712508125091251012511125121251312514125151251612517125181251912520125211252212523125241252512526125271252812529125301253112532125331253412535125361253712538125391254012541125421254312544125451254612547125481254912550125511255212553125541255512556125571255812559125601256112562125631256412565125661256712568125691257012571125721257312574125751257612577125781257912580125811258212583125841258512586125871258812589125901259112592125931259412595125961259712598125991260012601126021260312604126051260612607126081260912610126111261212613126141261512616126171261812619126201262112622126231262412625126261262712628126291263012631126321263312634126351263612637126381263912640126411264212643126441264512646126471264812649126501265112652126531265412655126561265712658126591266012661126621266312664126651266612667126681266912670126711267212673126741267512676126771267812679126801268112682126831268412685126861268712688126891269012691126921269312694126951269612697126981269912700127011270212703127041270512706127071270812709127101271112712127131271412715127161271712718127191272012721127221272312724127251272612727127281272912730127311273212733127341273512736127371273812739127401274112742127431274412745127461274712748127491275012751127521275312754127551275612757127581275912760127611276212763127641276512766127671276812769127701277112772127731277412775127761277712778127791278012781127821278312784127851278612787127881278912790127911279212793127941279512796127971279812799128001280112802128031280412805128061280712808128091281012811128121281312814128151281612817128181281912820128211282212823128241282512826128271282812829128301283112832128331283412835128361283712838128391284012841128421284312844128451284612847128481284912850128511285212853128541285512856128571285812859128601286112862128631286412865128661286712868128691287012871128721287312874128751287612877128781287912880128811288212883128841288512886128871288812889128901289112892128931289412895128961289712898128991290012901129021290312904129051290612907129081290912910129111291212913129141291512916129171291812919129201292112922129231292412925129261292712928129291293012931129321293312934129351293612937129381293912940129411294212943129441294512946129471294812949129501295112952129531295412955129561295712958129591296012961129621296312964129651296612967129681296912970129711297212973129741297512976129771297812979129801298112982129831298412985129861298712988129891299012991129921299312994129951299612997129981299913000130011300213003130041300513006130071300813009130101301113012130131301413015130161301713018130191302013021130221302313024130251302613027130281302913030130311303213033130341303513036130371303813039130401304113042130431304413045130461304713048130491305013051130521305313054130551305613057130581305913060130611306213063130641306513066130671306813069130701307113072130731307413075130761307713078130791308013081130821308313084130851308613087130881308913090130911309213093130941309513096130971309813099131001310113102131031310413105131061310713108131091311013111131121311313114131151311613117131181311913120131211312213123131241312513126131271312813129131301313113132131331313413135131361313713138131391314013141131421314313144131451314613147131481314913150131511315213153131541315513156131571315813159131601316113162131631316413165131661316713168131691317013171131721317313174131751317613177131781317913180131811318213183131841318513186131871318813189131901319113192131931319413195131961319713198131991320013201132021320313204132051320613207132081320913210132111321213213132141321513216132171321813219132201322113222132231322413225132261322713228132291323013231132321323313234132351323613237132381323913240132411324213243132441324513246132471324813249132501325113252132531325413255132561325713258132591326013261132621326313264132651326613267132681326913270132711327213273132741327513276132771327813279132801328113282132831328413285132861328713288132891329013291132921329313294132951329613297132981329913300133011330213303133041330513306133071330813309133101331113312133131331413315133161331713318133191332013321133221332313324133251332613327133281332913330133311333213333133341333513336133371333813339133401334113342133431334413345133461334713348133491335013351133521335313354133551335613357133581335913360133611336213363133641336513366133671336813369133701337113372133731337413375133761337713378133791338013381133821338313384133851338613387133881338913390133911339213393133941339513396133971339813399134001340113402134031340413405134061340713408134091341013411134121341313414134151341613417134181341913420134211342213423134241342513426134271342813429134301343113432134331343413435134361343713438134391344013441134421344313444134451344613447134481344913450134511345213453134541345513456134571345813459134601346113462134631346413465134661346713468134691347013471134721347313474134751347613477134781347913480134811348213483134841348513486134871348813489134901349113492134931349413495134961349713498134991350013501135021350313504135051350613507135081350913510135111351213513135141351513516135171351813519135201352113522135231352413525135261352713528135291353013531135321353313534135351353613537135381353913540135411354213543135441354513546135471354813549135501355113552135531355413555135561355713558135591356013561135621356313564135651356613567135681356913570135711357213573135741357513576135771357813579135801358113582135831358413585135861358713588135891359013591135921359313594135951359613597135981359913600136011360213603136041360513606136071360813609136101361113612136131361413615136161361713618136191362013621136221362313624136251362613627136281362913630136311363213633136341363513636136371363813639136401364113642136431364413645136461364713648136491365013651136521365313654136551365613657136581365913660136611366213663136641366513666136671366813669136701367113672136731367413675136761367713678136791368013681136821368313684136851368613687136881368913690136911369213693136941369513696136971369813699137001370113702137031370413705137061370713708137091371013711137121371313714137151371613717137181371913720137211372213723137241372513726137271372813729137301373113732137331373413735137361373713738137391374013741137421374313744137451374613747137481374913750137511375213753137541375513756137571375813759137601376113762137631376413765137661376713768137691377013771137721377313774137751377613777137781377913780137811378213783137841378513786137871378813789137901379113792137931379413795137961379713798137991380013801138021380313804138051380613807138081380913810138111381213813138141381513816138171381813819138201382113822138231382413825138261382713828138291383013831138321383313834138351383613837138381383913840138411384213843138441384513846138471384813849138501385113852138531385413855138561385713858138591386013861138621386313864138651386613867138681386913870138711387213873138741387513876138771387813879138801388113882138831388413885138861388713888138891389013891138921389313894138951389613897138981389913900139011390213903139041390513906139071390813909139101391113912139131391413915139161391713918139191392013921139221392313924139251392613927139281392913930139311393213933139341393513936139371393813939139401394113942139431394413945139461394713948139491395013951139521395313954139551395613957139581395913960139611396213963139641396513966139671396813969139701397113972139731397413975139761397713978139791398013981139821398313984139851398613987139881398913990139911399213993139941399513996139971399813999140001400114002140031400414005140061400714008140091401014011140121401314014140151401614017140181401914020140211402214023140241402514026140271402814029140301403114032140331403414035140361403714038140391404014041140421404314044140451404614047140481404914050140511405214053140541405514056140571405814059140601406114062140631406414065140661406714068140691407014071140721407314074140751407614077140781407914080140811408214083140841408514086140871408814089140901409114092140931409414095140961409714098140991410014101141021410314104141051410614107141081410914110141111411214113141141411514116141171411814119141201412114122141231412414125141261412714128141291413014131141321413314134141351413614137141381413914140141411414214143141441414514146141471414814149141501415114152141531415414155141561415714158141591416014161141621416314164141651416614167141681416914170141711417214173141741417514176141771417814179141801418114182141831418414185141861418714188141891419014191141921419314194141951419614197141981419914200142011420214203142041420514206142071420814209142101421114212142131421414215142161421714218142191422014221142221422314224142251422614227142281422914230142311423214233142341423514236142371423814239142401424114242142431424414245142461424714248142491425014251142521425314254142551425614257142581425914260142611426214263142641426514266142671426814269142701427114272142731427414275142761427714278142791428014281142821428314284142851428614287142881428914290142911429214293142941429514296142971429814299143001430114302143031430414305143061430714308143091431014311143121431314314143151431614317143181431914320143211432214323143241432514326143271432814329143301433114332143331433414335143361433714338143391434014341143421434314344143451434614347143481434914350143511435214353143541435514356143571435814359143601436114362143631436414365143661436714368143691437014371143721437314374143751437614377143781437914380143811438214383143841438514386143871438814389143901439114392143931439414395143961439714398143991440014401144021440314404144051440614407144081440914410144111441214413144141441514416144171441814419144201442114422144231442414425144261442714428144291443014431144321443314434144351443614437144381443914440144411444214443144441444514446144471444814449144501445114452144531445414455144561445714458144591446014461144621446314464144651446614467144681446914470144711447214473144741447514476144771447814479144801448114482144831448414485144861448714488144891449014491144921449314494144951449614497144981449914500145011450214503145041450514506145071450814509145101451114512145131451414515145161451714518145191452014521145221452314524145251452614527145281452914530145311453214533145341453514536145371453814539145401454114542145431454414545145461454714548145491455014551145521455314554145551455614557145581455914560145611456214563145641456514566145671456814569145701457114572145731457414575145761457714578145791458014581145821458314584145851458614587145881458914590145911459214593145941459514596145971459814599146001460114602146031460414605146061460714608146091461014611146121461314614146151461614617146181461914620146211462214623146241462514626146271462814629146301463114632146331463414635146361463714638146391464014641146421464314644146451464614647146481464914650146511465214653146541465514656146571465814659146601466114662146631466414665146661466714668146691467014671146721467314674146751467614677146781467914680146811468214683146841468514686146871468814689146901469114692146931469414695146961469714698146991470014701147021470314704147051470614707147081470914710147111471214713147141471514716147171471814719147201472114722147231472414725147261472714728147291473014731147321473314734147351473614737147381473914740147411474214743147441474514746147471474814749147501475114752147531475414755147561475714758147591476014761147621476314764147651476614767147681476914770147711477214773147741477514776147771477814779147801478114782147831478414785147861478714788147891479014791147921479314794147951479614797147981479914800148011480214803148041480514806148071480814809148101481114812148131481414815148161481714818148191482014821148221482314824148251482614827148281482914830148311483214833148341483514836148371483814839148401484114842148431484414845148461484714848148491485014851148521485314854148551485614857148581485914860148611486214863148641486514866148671486814869148701487114872148731487414875148761487714878148791488014881148821488314884148851488614887148881488914890148911489214893148941489514896148971489814899149001490114902149031490414905149061490714908149091491014911149121491314914149151491614917149181491914920149211492214923149241492514926149271492814929149301493114932149331493414935149361493714938149391494014941149421494314944149451494614947149481494914950149511495214953149541495514956149571495814959149601496114962149631496414965149661496714968149691497014971149721497314974149751497614977149781497914980149811498214983149841498514986149871498814989149901499114992149931499414995149961499714998149991500015001150021500315004150051500615007150081500915010150111501215013150141501515016150171501815019150201502115022150231502415025150261502715028150291503015031150321503315034150351503615037150381503915040150411504215043150441504515046150471504815049150501505115052150531505415055150561505715058150591506015061150621506315064150651506615067150681506915070150711507215073150741507515076150771507815079150801508115082150831508415085150861508715088150891509015091150921509315094150951509615097150981509915100151011510215103151041510515106151071510815109151101511115112151131511415115151161511715118151191512015121151221512315124151251512615127151281512915130151311513215133151341513515136151371513815139151401514115142151431514415145151461514715148151491515015151151521515315154151551515615157151581515915160151611516215163151641516515166151671516815169151701517115172151731517415175151761517715178151791518015181151821518315184151851518615187151881518915190151911519215193151941519515196151971519815199152001520115202152031520415205152061520715208152091521015211152121521315214152151521615217152181521915220152211522215223152241522515226152271522815229152301523115232152331523415235152361523715238152391524015241152421524315244152451524615247152481524915250152511525215253152541525515256152571525815259152601526115262152631526415265152661526715268152691527015271152721527315274152751527615277152781527915280152811528215283152841528515286152871528815289152901529115292152931529415295152961529715298152991530015301153021530315304153051530615307153081530915310153111531215313153141531515316153171531815319153201532115322153231532415325153261532715328153291533015331153321533315334153351533615337153381533915340153411534215343153441534515346153471534815349153501535115352153531535415355153561535715358153591536015361153621536315364153651536615367153681536915370153711537215373153741537515376153771537815379153801538115382153831538415385153861538715388153891539015391153921539315394153951539615397153981539915400154011540215403154041540515406154071540815409154101541115412154131541415415154161541715418154191542015421154221542315424154251542615427154281542915430154311543215433154341543515436154371543815439154401544115442154431544415445154461544715448154491545015451154521545315454154551545615457154581545915460154611546215463154641546515466154671546815469154701547115472154731547415475154761547715478154791548015481154821548315484154851548615487154881548915490154911549215493154941549515496154971549815499155001550115502155031550415505155061550715508155091551015511155121551315514155151551615517155181551915520155211552215523155241552515526155271552815529155301553115532155331553415535155361553715538155391554015541155421554315544155451554615547155481554915550155511555215553155541555515556155571555815559155601556115562155631556415565155661556715568155691557015571155721557315574155751557615577155781557915580155811558215583155841558515586155871558815589155901559115592155931559415595155961559715598155991560015601156021560315604156051560615607156081560915610156111561215613156141561515616156171561815619156201562115622156231562415625156261562715628156291563015631156321563315634156351563615637156381563915640156411564215643156441564515646156471564815649156501565115652156531565415655156561565715658156591566015661156621566315664156651566615667156681566915670156711567215673156741567515676156771567815679156801568115682156831568415685156861568715688156891569015691156921569315694156951569615697156981569915700157011570215703157041570515706157071570815709157101571115712157131571415715157161571715718157191572015721157221572315724157251572615727157281572915730157311573215733157341573515736157371573815739157401574115742157431574415745157461574715748157491575015751157521575315754157551575615757157581575915760157611576215763157641576515766157671576815769157701577115772157731577415775157761577715778157791578015781157821578315784157851578615787157881578915790157911579215793157941579515796157971579815799158001580115802158031580415805158061580715808158091581015811158121581315814158151581615817158181581915820158211582215823158241582515826158271582815829158301583115832158331583415835158361583715838158391584015841158421584315844158451584615847158481584915850158511585215853158541585515856158571585815859158601586115862158631586415865158661586715868158691587015871158721587315874158751587615877158781587915880158811588215883158841588515886158871588815889158901589115892158931589415895158961589715898158991590015901159021590315904159051590615907159081590915910159111591215913159141591515916159171591815919159201592115922159231592415925159261592715928159291593015931159321593315934159351593615937159381593915940159411594215943159441594515946159471594815949159501595115952159531595415955159561595715958159591596015961159621596315964159651596615967159681596915970159711597215973159741597515976159771597815979159801598115982159831598415985159861598715988159891599015991159921599315994159951599615997159981599916000160011600216003160041600516006160071600816009160101601116012160131601416015160161601716018160191602016021160221602316024160251602616027160281602916030160311603216033160341603516036160371603816039160401604116042160431604416045160461604716048160491605016051160521605316054160551605616057160581605916060160611606216063160641606516066160671606816069160701607116072160731607416075160761607716078160791608016081160821608316084160851608616087160881608916090160911609216093160941609516096160971609816099161001610116102161031610416105161061610716108161091611016111161121611316114161151611616117161181611916120161211612216123161241612516126161271612816129161301613116132161331613416135161361613716138161391614016141161421614316144161451614616147161481614916150161511615216153161541615516156161571615816159161601616116162161631616416165161661616716168161691617016171161721617316174161751617616177161781617916180161811618216183161841618516186161871618816189161901619116192161931619416195161961619716198161991620016201162021620316204162051620616207162081620916210162111621216213162141621516216162171621816219162201622116222162231622416225162261622716228162291623016231162321623316234162351623616237162381623916240162411624216243162441624516246162471624816249162501625116252162531625416255162561625716258162591626016261162621626316264162651626616267162681626916270162711627216273162741627516276162771627816279162801628116282162831628416285162861628716288162891629016291162921629316294162951629616297162981629916300163011630216303163041630516306163071630816309163101631116312163131631416315163161631716318163191632016321163221632316324163251632616327163281632916330163311633216333163341633516336163371633816339163401634116342163431634416345163461634716348163491635016351163521635316354163551635616357163581635916360163611636216363163641636516366163671636816369163701637116372163731637416375163761637716378163791638016381163821638316384163851638616387163881638916390163911639216393163941639516396163971639816399164001640116402164031640416405164061640716408164091641016411164121641316414164151641616417164181641916420164211642216423164241642516426164271642816429164301643116432164331643416435164361643716438164391644016441164421644316444164451644616447164481644916450164511645216453164541645516456164571645816459164601646116462164631646416465164661646716468164691647016471164721647316474164751647616477164781647916480164811648216483164841648516486164871648816489164901649116492164931649416495164961649716498164991650016501165021650316504165051650616507165081650916510165111651216513165141651516516165171651816519165201652116522165231652416525165261652716528165291653016531165321653316534165351653616537165381653916540165411654216543165441654516546165471654816549165501655116552165531655416555165561655716558165591656016561165621656316564165651656616567165681656916570165711657216573165741657516576165771657816579165801658116582165831658416585165861658716588165891659016591165921659316594165951659616597165981659916600166011660216603166041660516606166071660816609166101661116612166131661416615166161661716618166191662016621166221662316624166251662616627166281662916630166311663216633166341663516636166371663816639166401664116642166431664416645166461664716648166491665016651166521665316654166551665616657166581665916660166611666216663166641666516666166671666816669166701667116672166731667416675166761667716678166791668016681166821668316684166851668616687166881668916690166911669216693166941669516696166971669816699167001670116702167031670416705167061670716708167091671016711167121671316714167151671616717167181671916720167211672216723167241672516726167271672816729167301673116732167331673416735167361673716738167391674016741167421674316744167451674616747167481674916750167511675216753167541675516756167571675816759167601676116762167631676416765167661676716768167691677016771167721677316774167751677616777167781677916780167811678216783167841678516786167871678816789167901679116792167931679416795167961679716798167991680016801168021680316804168051680616807168081680916810168111681216813168141681516816168171681816819168201682116822168231682416825168261682716828168291683016831168321683316834168351683616837168381683916840168411684216843168441684516846168471684816849168501685116852168531685416855168561685716858168591686016861168621686316864168651686616867168681686916870168711687216873168741687516876168771687816879168801688116882168831688416885168861688716888168891689016891168921689316894168951689616897168981689916900169011690216903169041690516906169071690816909169101691116912169131691416915169161691716918169191692016921169221692316924169251692616927169281692916930169311693216933169341693516936169371693816939169401694116942169431694416945169461694716948169491695016951169521695316954169551695616957169581695916960169611696216963169641696516966169671696816969169701697116972169731697416975169761697716978169791698016981169821698316984169851698616987169881698916990169911699216993169941699516996169971699816999170001700117002170031700417005170061700717008170091701017011170121701317014170151701617017170181701917020170211702217023170241702517026170271702817029170301703117032170331703417035170361703717038170391704017041170421704317044170451704617047170481704917050170511705217053170541705517056170571705817059170601706117062170631706417065170661706717068170691707017071170721707317074170751707617077170781707917080170811708217083170841708517086170871708817089170901709117092170931709417095170961709717098170991710017101171021710317104171051710617107171081710917110171111711217113171141711517116171171711817119171201712117122171231712417125171261712717128171291713017131171321713317134171351713617137171381713917140171411714217143171441714517146171471714817149171501715117152171531715417155171561715717158171591716017161171621716317164171651716617167171681716917170171711717217173171741717517176171771717817179171801718117182171831718417185171861718717188171891719017191171921719317194171951719617197171981719917200172011720217203172041720517206172071720817209172101721117212172131721417215172161721717218172191722017221172221722317224172251722617227172281722917230172311723217233172341723517236172371723817239172401724117242172431724417245172461724717248172491725017251172521725317254172551725617257172581725917260172611726217263172641726517266172671726817269172701727117272172731727417275172761727717278172791728017281172821728317284172851728617287172881728917290172911729217293172941729517296172971729817299173001730117302173031730417305173061730717308173091731017311173121731317314173151731617317173181731917320173211732217323173241732517326173271732817329173301733117332173331733417335173361733717338173391734017341173421734317344173451734617347173481734917350173511735217353173541735517356173571735817359173601736117362173631736417365173661736717368173691737017371173721737317374173751737617377173781737917380173811738217383173841738517386173871738817389173901739117392173931739417395173961739717398173991740017401174021740317404174051740617407174081740917410174111741217413174141741517416174171741817419174201742117422174231742417425174261742717428174291743017431174321743317434174351743617437174381743917440174411744217443174441744517446174471744817449174501745117452174531745417455174561745717458174591746017461174621746317464174651746617467174681746917470174711747217473174741747517476174771747817479174801748117482174831748417485174861748717488174891749017491174921749317494174951749617497174981749917500175011750217503175041750517506175071750817509175101751117512175131751417515175161751717518175191752017521175221752317524175251752617527175281752917530175311753217533175341753517536175371753817539175401754117542175431754417545175461754717548175491755017551175521755317554175551755617557175581755917560175611756217563175641756517566175671756817569175701757117572175731757417575175761757717578175791758017581175821758317584175851758617587175881758917590175911759217593175941759517596175971759817599176001760117602176031760417605176061760717608176091761017611176121761317614176151761617617176181761917620176211762217623176241762517626176271762817629176301763117632176331763417635176361763717638176391764017641176421764317644176451764617647176481764917650176511765217653176541765517656176571765817659176601766117662176631766417665176661766717668176691767017671176721767317674176751767617677176781767917680176811768217683176841768517686176871768817689176901769117692176931769417695176961769717698176991770017701177021770317704
  1. ==============================
  2. LLVM Language Reference Manual
  3. ==============================
  4. .. contents::
  5. :local:
  6. :depth: 4
  7. Abstract
  8. ========
  9. This document is a reference manual for the LLVM assembly language. LLVM
  10. is a Static Single Assignment (SSA) based representation that provides
  11. type safety, low-level operations, flexibility, and the capability of
  12. representing 'all' high-level languages cleanly. It is the common code
  13. representation used throughout all phases of the LLVM compilation
  14. strategy.
  15. Introduction
  16. ============
  17. The LLVM code representation is designed to be used in three different
  18. forms: as an in-memory compiler IR, as an on-disk bitcode representation
  19. (suitable for fast loading by a Just-In-Time compiler), and as a human
  20. readable assembly language representation. This allows LLVM to provide a
  21. powerful intermediate representation for efficient compiler
  22. transformations and analysis, while providing a natural means to debug
  23. and visualize the transformations. The three different forms of LLVM are
  24. all equivalent. This document describes the human readable
  25. representation and notation.
  26. The LLVM representation aims to be light-weight and low-level while
  27. being expressive, typed, and extensible at the same time. It aims to be
  28. a "universal IR" of sorts, by being at a low enough level that
  29. high-level ideas may be cleanly mapped to it (similar to how
  30. microprocessors are "universal IR's", allowing many source languages to
  31. be mapped to them). By providing type information, LLVM can be used as
  32. the target of optimizations: for example, through pointer analysis, it
  33. can be proven that a C automatic variable is never accessed outside of
  34. the current function, allowing it to be promoted to a simple SSA value
  35. instead of a memory location.
  36. .. _wellformed:
  37. Well-Formedness
  38. ---------------
  39. It is important to note that this document describes 'well formed' LLVM
  40. assembly language. There is a difference between what the parser accepts
  41. and what is considered 'well formed'. For example, the following
  42. instruction is syntactically okay, but not well formed:
  43. .. code-block:: llvm
  44. %x = add i32 1, %x
  45. because the definition of ``%x`` does not dominate all of its uses. The
  46. LLVM infrastructure provides a verification pass that may be used to
  47. verify that an LLVM module is well formed. This pass is automatically
  48. run by the parser after parsing input assembly and by the optimizer
  49. before it outputs bitcode. The violations pointed out by the verifier
  50. pass indicate bugs in transformation passes or input to the parser.
  51. .. _identifiers:
  52. Identifiers
  53. ===========
  54. LLVM identifiers come in two basic types: global and local. Global
  55. identifiers (functions, global variables) begin with the ``'@'``
  56. character. Local identifiers (register names, types) begin with the
  57. ``'%'`` character. Additionally, there are three different formats for
  58. identifiers, for different purposes:
  59. #. Named values are represented as a string of characters with their
  60. prefix. For example, ``%foo``, ``@DivisionByZero``,
  61. ``%a.really.long.identifier``. The actual regular expression used is
  62. '``[%@][-a-zA-Z$._][-a-zA-Z$._0-9]*``'. Identifiers that require other
  63. characters in their names can be surrounded with quotes. Special
  64. characters may be escaped using ``"\xx"`` where ``xx`` is the ASCII
  65. code for the character in hexadecimal. In this way, any character can
  66. be used in a name value, even quotes themselves. The ``"\01"`` prefix
  67. can be used on global values to suppress mangling.
  68. #. Unnamed values are represented as an unsigned numeric value with
  69. their prefix. For example, ``%12``, ``@2``, ``%44``.
  70. #. Constants, which are described in the section Constants_ below.
  71. LLVM requires that values start with a prefix for two reasons: Compilers
  72. don't need to worry about name clashes with reserved words, and the set
  73. of reserved words may be expanded in the future without penalty.
  74. Additionally, unnamed identifiers allow a compiler to quickly come up
  75. with a temporary variable without having to avoid symbol table
  76. conflicts.
  77. Reserved words in LLVM are very similar to reserved words in other
  78. languages. There are keywords for different opcodes ('``add``',
  79. '``bitcast``', '``ret``', etc...), for primitive type names ('``void``',
  80. '``i32``', etc...), and others. These reserved words cannot conflict
  81. with variable names, because none of them start with a prefix character
  82. (``'%'`` or ``'@'``).
  83. Here is an example of LLVM code to multiply the integer variable
  84. '``%X``' by 8:
  85. The easy way:
  86. .. code-block:: llvm
  87. %result = mul i32 %X, 8
  88. After strength reduction:
  89. .. code-block:: llvm
  90. %result = shl i32 %X, 3
  91. And the hard way:
  92. .. code-block:: llvm
  93. %0 = add i32 %X, %X ; yields i32:%0
  94. %1 = add i32 %0, %0 ; yields i32:%1
  95. %result = add i32 %1, %1
  96. This last way of multiplying ``%X`` by 8 illustrates several important
  97. lexical features of LLVM:
  98. #. Comments are delimited with a '``;``' and go until the end of line.
  99. #. Unnamed temporaries are created when the result of a computation is
  100. not assigned to a named value.
  101. #. Unnamed temporaries are numbered sequentially (using a per-function
  102. incrementing counter, starting with 0). Note that basic blocks and unnamed
  103. function parameters are included in this numbering. For example, if the
  104. entry basic block is not given a label name and all function parameters are
  105. named, then it will get number 0.
  106. It also shows a convention that we follow in this document. When
  107. demonstrating instructions, we will follow an instruction with a comment
  108. that defines the type and name of value produced.
  109. High Level Structure
  110. ====================
  111. Module Structure
  112. ----------------
  113. LLVM programs are composed of ``Module``'s, each of which is a
  114. translation unit of the input programs. Each module consists of
  115. functions, global variables, and symbol table entries. Modules may be
  116. combined together with the LLVM linker, which merges function (and
  117. global variable) definitions, resolves forward declarations, and merges
  118. symbol table entries. Here is an example of the "hello world" module:
  119. .. code-block:: llvm
  120. ; Declare the string constant as a global constant.
  121. @.str = private unnamed_addr constant [13 x i8] c"hello world\0A\00"
  122. ; External declaration of the puts function
  123. declare i32 @puts(i8* nocapture) nounwind
  124. ; Definition of main function
  125. define i32 @main() { ; i32()*
  126. ; Convert [13 x i8]* to i8*...
  127. %cast210 = getelementptr [13 x i8], [13 x i8]* @.str, i64 0, i64 0
  128. ; Call puts function to write out the string to stdout.
  129. call i32 @puts(i8* %cast210)
  130. ret i32 0
  131. }
  132. ; Named metadata
  133. !0 = !{i32 42, null, !"string"}
  134. !foo = !{!0}
  135. This example is made up of a :ref:`global variable <globalvars>` named
  136. "``.str``", an external declaration of the "``puts``" function, a
  137. :ref:`function definition <functionstructure>` for "``main``" and
  138. :ref:`named metadata <namedmetadatastructure>` "``foo``".
  139. In general, a module is made up of a list of global values (where both
  140. functions and global variables are global values). Global values are
  141. represented by a pointer to a memory location (in this case, a pointer
  142. to an array of char, and a pointer to a function), and have one of the
  143. following :ref:`linkage types <linkage>`.
  144. .. _linkage:
  145. Linkage Types
  146. -------------
  147. All Global Variables and Functions have one of the following types of
  148. linkage:
  149. ``private``
  150. Global values with "``private``" linkage are only directly
  151. accessible by objects in the current module. In particular, linking
  152. code into a module with a private global value may cause the
  153. private to be renamed as necessary to avoid collisions. Because the
  154. symbol is private to the module, all references can be updated. This
  155. doesn't show up in any symbol table in the object file.
  156. ``internal``
  157. Similar to private, but the value shows as a local symbol
  158. (``STB_LOCAL`` in the case of ELF) in the object file. This
  159. corresponds to the notion of the '``static``' keyword in C.
  160. ``available_externally``
  161. Globals with "``available_externally``" linkage are never emitted into
  162. the object file corresponding to the LLVM module. From the linker's
  163. perspective, an ``available_externally`` global is equivalent to
  164. an external declaration. They exist to allow inlining and other
  165. optimizations to take place given knowledge of the definition of the
  166. global, which is known to be somewhere outside the module. Globals
  167. with ``available_externally`` linkage are allowed to be discarded at
  168. will, and allow inlining and other optimizations. This linkage type is
  169. only allowed on definitions, not declarations.
  170. ``linkonce``
  171. Globals with "``linkonce``" linkage are merged with other globals of
  172. the same name when linkage occurs. This can be used to implement
  173. some forms of inline functions, templates, or other code which must
  174. be generated in each translation unit that uses it, but where the
  175. body may be overridden with a more definitive definition later.
  176. Unreferenced ``linkonce`` globals are allowed to be discarded. Note
  177. that ``linkonce`` linkage does not actually allow the optimizer to
  178. inline the body of this function into callers because it doesn't
  179. know if this definition of the function is the definitive definition
  180. within the program or whether it will be overridden by a stronger
  181. definition. To enable inlining and other optimizations, use
  182. "``linkonce_odr``" linkage.
  183. ``weak``
  184. "``weak``" linkage has the same merging semantics as ``linkonce``
  185. linkage, except that unreferenced globals with ``weak`` linkage may
  186. not be discarded. This is used for globals that are declared "weak"
  187. in C source code.
  188. ``common``
  189. "``common``" linkage is most similar to "``weak``" linkage, but they
  190. are used for tentative definitions in C, such as "``int X;``" at
  191. global scope. Symbols with "``common``" linkage are merged in the
  192. same way as ``weak symbols``, and they may not be deleted if
  193. unreferenced. ``common`` symbols may not have an explicit section,
  194. must have a zero initializer, and may not be marked
  195. ':ref:`constant <globalvars>`'. Functions and aliases may not have
  196. common linkage.
  197. .. _linkage_appending:
  198. ``appending``
  199. "``appending``" linkage may only be applied to global variables of
  200. pointer to array type. When two global variables with appending
  201. linkage are linked together, the two global arrays are appended
  202. together. This is the LLVM, typesafe, equivalent of having the
  203. system linker append together "sections" with identical names when
  204. .o files are linked.
  205. Unfortunately this doesn't correspond to any feature in .o files, so it
  206. can only be used for variables like ``llvm.global_ctors`` which llvm
  207. interprets specially.
  208. ``extern_weak``
  209. The semantics of this linkage follow the ELF object file model: the
  210. symbol is weak until linked, if not linked, the symbol becomes null
  211. instead of being an undefined reference.
  212. ``linkonce_odr``, ``weak_odr``
  213. Some languages allow differing globals to be merged, such as two
  214. functions with different semantics. Other languages, such as
  215. ``C++``, ensure that only equivalent globals are ever merged (the
  216. "one definition rule" --- "ODR"). Such languages can use the
  217. ``linkonce_odr`` and ``weak_odr`` linkage types to indicate that the
  218. global will only be merged with equivalent globals. These linkage
  219. types are otherwise the same as their non-``odr`` versions.
  220. ``external``
  221. If none of the above identifiers are used, the global is externally
  222. visible, meaning that it participates in linkage and can be used to
  223. resolve external symbol references.
  224. It is illegal for a function *declaration* to have any linkage type
  225. other than ``external`` or ``extern_weak``.
  226. .. _callingconv:
  227. Calling Conventions
  228. -------------------
  229. LLVM :ref:`functions <functionstructure>`, :ref:`calls <i_call>` and
  230. :ref:`invokes <i_invoke>` can all have an optional calling convention
  231. specified for the call. The calling convention of any pair of dynamic
  232. caller/callee must match, or the behavior of the program is undefined.
  233. The following calling conventions are supported by LLVM, and more may be
  234. added in the future:
  235. "``ccc``" - The C calling convention
  236. This calling convention (the default if no other calling convention
  237. is specified) matches the target C calling conventions. This calling
  238. convention supports varargs function calls and tolerates some
  239. mismatch in the declared prototype and implemented declaration of
  240. the function (as does normal C).
  241. "``fastcc``" - The fast calling convention
  242. This calling convention attempts to make calls as fast as possible
  243. (e.g. by passing things in registers). This calling convention
  244. allows the target to use whatever tricks it wants to produce fast
  245. code for the target, without having to conform to an externally
  246. specified ABI (Application Binary Interface). `Tail calls can only
  247. be optimized when this, the GHC or the HiPE convention is
  248. used. <CodeGenerator.html#id80>`_ This calling convention does not
  249. support varargs and requires the prototype of all callees to exactly
  250. match the prototype of the function definition.
  251. "``coldcc``" - The cold calling convention
  252. This calling convention attempts to make code in the caller as
  253. efficient as possible under the assumption that the call is not
  254. commonly executed. As such, these calls often preserve all registers
  255. so that the call does not break any live ranges in the caller side.
  256. This calling convention does not support varargs and requires the
  257. prototype of all callees to exactly match the prototype of the
  258. function definition. Furthermore the inliner doesn't consider such function
  259. calls for inlining.
  260. "``cc 10``" - GHC convention
  261. This calling convention has been implemented specifically for use by
  262. the `Glasgow Haskell Compiler (GHC) <http://www.haskell.org/ghc>`_.
  263. It passes everything in registers, going to extremes to achieve this
  264. by disabling callee save registers. This calling convention should
  265. not be used lightly but only for specific situations such as an
  266. alternative to the *register pinning* performance technique often
  267. used when implementing functional programming languages. At the
  268. moment only X86 supports this convention and it has the following
  269. limitations:
  270. - On *X86-32* only supports up to 4 bit type parameters. No
  271. floating-point types are supported.
  272. - On *X86-64* only supports up to 10 bit type parameters and 6
  273. floating-point parameters.
  274. This calling convention supports `tail call
  275. optimization <CodeGenerator.html#id80>`_ but requires both the
  276. caller and callee are using it.
  277. "``cc 11``" - The HiPE calling convention
  278. This calling convention has been implemented specifically for use by
  279. the `High-Performance Erlang
  280. (HiPE) <http://www.it.uu.se/research/group/hipe/>`_ compiler, *the*
  281. native code compiler of the `Ericsson's Open Source Erlang/OTP
  282. system <http://www.erlang.org/download.shtml>`_. It uses more
  283. registers for argument passing than the ordinary C calling
  284. convention and defines no callee-saved registers. The calling
  285. convention properly supports `tail call
  286. optimization <CodeGenerator.html#id80>`_ but requires that both the
  287. caller and the callee use it. It uses a *register pinning*
  288. mechanism, similar to GHC's convention, for keeping frequently
  289. accessed runtime components pinned to specific hardware registers.
  290. At the moment only X86 supports this convention (both 32 and 64
  291. bit).
  292. "``webkit_jscc``" - WebKit's JavaScript calling convention
  293. This calling convention has been implemented for `WebKit FTL JIT
  294. <https://trac.webkit.org/wiki/FTLJIT>`_. It passes arguments on the
  295. stack right to left (as cdecl does), and returns a value in the
  296. platform's customary return register.
  297. "``anyregcc``" - Dynamic calling convention for code patching
  298. This is a special convention that supports patching an arbitrary code
  299. sequence in place of a call site. This convention forces the call
  300. arguments into registers but allows them to be dynamically
  301. allocated. This can currently only be used with calls to
  302. llvm.experimental.patchpoint because only this intrinsic records
  303. the location of its arguments in a side table. See :doc:`StackMaps`.
  304. "``preserve_mostcc``" - The `PreserveMost` calling convention
  305. This calling convention attempts to make the code in the caller as
  306. unintrusive as possible. This convention behaves identically to the `C`
  307. calling convention on how arguments and return values are passed, but it
  308. uses a different set of caller/callee-saved registers. This alleviates the
  309. burden of saving and recovering a large register set before and after the
  310. call in the caller. If the arguments are passed in callee-saved registers,
  311. then they will be preserved by the callee across the call. This doesn't
  312. apply for values returned in callee-saved registers.
  313. - On X86-64 the callee preserves all general purpose registers, except for
  314. R11. R11 can be used as a scratch register. Floating-point registers
  315. (XMMs/YMMs) are not preserved and need to be saved by the caller.
  316. The idea behind this convention is to support calls to runtime functions
  317. that have a hot path and a cold path. The hot path is usually a small piece
  318. of code that doesn't use many registers. The cold path might need to call out to
  319. another function and therefore only needs to preserve the caller-saved
  320. registers, which haven't already been saved by the caller. The
  321. `PreserveMost` calling convention is very similar to the `cold` calling
  322. convention in terms of caller/callee-saved registers, but they are used for
  323. different types of function calls. `coldcc` is for function calls that are
  324. rarely executed, whereas `preserve_mostcc` function calls are intended to be
  325. on the hot path and definitely executed a lot. Furthermore `preserve_mostcc`
  326. doesn't prevent the inliner from inlining the function call.
  327. This calling convention will be used by a future version of the ObjectiveC
  328. runtime and should therefore still be considered experimental at this time.
  329. Although this convention was created to optimize certain runtime calls to
  330. the ObjectiveC runtime, it is not limited to this runtime and might be used
  331. by other runtimes in the future too. The current implementation only
  332. supports X86-64, but the intention is to support more architectures in the
  333. future.
  334. "``preserve_allcc``" - The `PreserveAll` calling convention
  335. This calling convention attempts to make the code in the caller even less
  336. intrusive than the `PreserveMost` calling convention. This calling
  337. convention also behaves identical to the `C` calling convention on how
  338. arguments and return values are passed, but it uses a different set of
  339. caller/callee-saved registers. This removes the burden of saving and
  340. recovering a large register set before and after the call in the caller. If
  341. the arguments are passed in callee-saved registers, then they will be
  342. preserved by the callee across the call. This doesn't apply for values
  343. returned in callee-saved registers.
  344. - On X86-64 the callee preserves all general purpose registers, except for
  345. R11. R11 can be used as a scratch register. Furthermore it also preserves
  346. all floating-point registers (XMMs/YMMs).
  347. The idea behind this convention is to support calls to runtime functions
  348. that don't need to call out to any other functions.
  349. This calling convention, like the `PreserveMost` calling convention, will be
  350. used by a future version of the ObjectiveC runtime and should be considered
  351. experimental at this time.
  352. "``cxx_fast_tlscc``" - The `CXX_FAST_TLS` calling convention for access functions
  353. Clang generates an access function to access C++-style TLS. The access
  354. function generally has an entry block, an exit block and an initialization
  355. block that is run at the first time. The entry and exit blocks can access
  356. a few TLS IR variables, each access will be lowered to a platform-specific
  357. sequence.
  358. This calling convention aims to minimize overhead in the caller by
  359. preserving as many registers as possible (all the registers that are
  360. preserved on the fast path, composed of the entry and exit blocks).
  361. This calling convention behaves identical to the `C` calling convention on
  362. how arguments and return values are passed, but it uses a different set of
  363. caller/callee-saved registers.
  364. Given that each platform has its own lowering sequence, hence its own set
  365. of preserved registers, we can't use the existing `PreserveMost`.
  366. - On X86-64 the callee preserves all general purpose registers, except for
  367. RDI and RAX.
  368. "``swiftcc``" - This calling convention is used for Swift language.
  369. - On X86-64 RCX and R8 are available for additional integer returns, and
  370. XMM2 and XMM3 are available for additional FP/vector returns.
  371. - On iOS platforms, we use AAPCS-VFP calling convention.
  372. "``cc <n>``" - Numbered convention
  373. Any calling convention may be specified by number, allowing
  374. target-specific calling conventions to be used. Target specific
  375. calling conventions start at 64.
  376. More calling conventions can be added/defined on an as-needed basis, to
  377. support Pascal conventions or any other well-known target-independent
  378. convention.
  379. .. _visibilitystyles:
  380. Visibility Styles
  381. -----------------
  382. All Global Variables and Functions have one of the following visibility
  383. styles:
  384. "``default``" - Default style
  385. On targets that use the ELF object file format, default visibility
  386. means that the declaration is visible to other modules and, in
  387. shared libraries, means that the declared entity may be overridden.
  388. On Darwin, default visibility means that the declaration is visible
  389. to other modules. Default visibility corresponds to "external
  390. linkage" in the language.
  391. "``hidden``" - Hidden style
  392. Two declarations of an object with hidden visibility refer to the
  393. same object if they are in the same shared object. Usually, hidden
  394. visibility indicates that the symbol will not be placed into the
  395. dynamic symbol table, so no other module (executable or shared
  396. library) can reference it directly.
  397. "``protected``" - Protected style
  398. On ELF, protected visibility indicates that the symbol will be
  399. placed in the dynamic symbol table, but that references within the
  400. defining module will bind to the local symbol. That is, the symbol
  401. cannot be overridden by another module.
  402. A symbol with ``internal`` or ``private`` linkage must have ``default``
  403. visibility.
  404. .. _dllstorageclass:
  405. DLL Storage Classes
  406. -------------------
  407. All Global Variables, Functions and Aliases can have one of the following
  408. DLL storage class:
  409. ``dllimport``
  410. "``dllimport``" causes the compiler to reference a function or variable via
  411. a global pointer to a pointer that is set up by the DLL exporting the
  412. symbol. On Microsoft Windows targets, the pointer name is formed by
  413. combining ``__imp_`` and the function or variable name.
  414. ``dllexport``
  415. "``dllexport``" causes the compiler to provide a global pointer to a pointer
  416. in a DLL, so that it can be referenced with the ``dllimport`` attribute. On
  417. Microsoft Windows targets, the pointer name is formed by combining
  418. ``__imp_`` and the function or variable name. Since this storage class
  419. exists for defining a dll interface, the compiler, assembler and linker know
  420. it is externally referenced and must refrain from deleting the symbol.
  421. .. _tls_model:
  422. Thread Local Storage Models
  423. ---------------------------
  424. A variable may be defined as ``thread_local``, which means that it will
  425. not be shared by threads (each thread will have a separated copy of the
  426. variable). Not all targets support thread-local variables. Optionally, a
  427. TLS model may be specified:
  428. ``localdynamic``
  429. For variables that are only used within the current shared library.
  430. ``initialexec``
  431. For variables in modules that will not be loaded dynamically.
  432. ``localexec``
  433. For variables defined in the executable and only used within it.
  434. If no explicit model is given, the "general dynamic" model is used.
  435. The models correspond to the ELF TLS models; see `ELF Handling For
  436. Thread-Local Storage <http://people.redhat.com/drepper/tls.pdf>`_ for
  437. more information on under which circumstances the different models may
  438. be used. The target may choose a different TLS model if the specified
  439. model is not supported, or if a better choice of model can be made.
  440. A model can also be specified in an alias, but then it only governs how
  441. the alias is accessed. It will not have any effect in the aliasee.
  442. For platforms without linker support of ELF TLS model, the -femulated-tls
  443. flag can be used to generate GCC compatible emulated TLS code.
  444. .. _runtime_preemption_model:
  445. Runtime Preemption Specifiers
  446. -----------------------------
  447. Global variables, functions and aliases may have an optional runtime preemption
  448. specifier. If a preemption specifier isn't given explicitly, then a
  449. symbol is assumed to be ``dso_preemptable``.
  450. ``dso_preemptable``
  451. Indicates that the function or variable may be replaced by a symbol from
  452. outside the linkage unit at runtime.
  453. ``dso_local``
  454. The compiler may assume that a function or variable marked as ``dso_local``
  455. will resolve to a symbol within the same linkage unit. Direct access will
  456. be generated even if the definition is not within this compilation unit.
  457. .. _namedtypes:
  458. Structure Types
  459. ---------------
  460. LLVM IR allows you to specify both "identified" and "literal" :ref:`structure
  461. types <t_struct>`. Literal types are uniqued structurally, but identified types
  462. are never uniqued. An :ref:`opaque structural type <t_opaque>` can also be used
  463. to forward declare a type that is not yet available.
  464. An example of an identified structure specification is:
  465. .. code-block:: llvm
  466. %mytype = type { %mytype*, i32 }
  467. Prior to the LLVM 3.0 release, identified types were structurally uniqued. Only
  468. literal types are uniqued in recent versions of LLVM.
  469. .. _nointptrtype:
  470. Non-Integral Pointer Type
  471. -------------------------
  472. Note: non-integral pointer types are a work in progress, and they should be
  473. considered experimental at this time.
  474. LLVM IR optionally allows the frontend to denote pointers in certain address
  475. spaces as "non-integral" via the :ref:`datalayout string<langref_datalayout>`.
  476. Non-integral pointer types represent pointers that have an *unspecified* bitwise
  477. representation; that is, the integral representation may be target dependent or
  478. unstable (not backed by a fixed integer).
  479. ``inttoptr`` instructions converting integers to non-integral pointer types are
  480. ill-typed, and so are ``ptrtoint`` instructions converting values of
  481. non-integral pointer types to integers. Vector versions of said instructions
  482. are ill-typed as well.
  483. .. _globalvars:
  484. Global Variables
  485. ----------------
  486. Global variables define regions of memory allocated at compilation time
  487. instead of run-time.
  488. Global variable definitions must be initialized.
  489. Global variables in other translation units can also be declared, in which
  490. case they don't have an initializer.
  491. Either global variable definitions or declarations may have an explicit section
  492. to be placed in and may have an optional explicit alignment specified. If there
  493. is a mismatch between the explicit or inferred section information for the
  494. variable declaration and its definition the resulting behavior is undefined.
  495. A variable may be defined as a global ``constant``, which indicates that
  496. the contents of the variable will **never** be modified (enabling better
  497. optimization, allowing the global data to be placed in the read-only
  498. section of an executable, etc). Note that variables that need runtime
  499. initialization cannot be marked ``constant`` as there is a store to the
  500. variable.
  501. LLVM explicitly allows *declarations* of global variables to be marked
  502. constant, even if the final definition of the global is not. This
  503. capability can be used to enable slightly better optimization of the
  504. program, but requires the language definition to guarantee that
  505. optimizations based on the 'constantness' are valid for the translation
  506. units that do not include the definition.
  507. As SSA values, global variables define pointer values that are in scope
  508. (i.e. they dominate) all basic blocks in the program. Global variables
  509. always define a pointer to their "content" type because they describe a
  510. region of memory, and all memory objects in LLVM are accessed through
  511. pointers.
  512. Global variables can be marked with ``unnamed_addr`` which indicates
  513. that the address is not significant, only the content. Constants marked
  514. like this can be merged with other constants if they have the same
  515. initializer. Note that a constant with significant address *can* be
  516. merged with a ``unnamed_addr`` constant, the result being a constant
  517. whose address is significant.
  518. If the ``local_unnamed_addr`` attribute is given, the address is known to
  519. not be significant within the module.
  520. A global variable may be declared to reside in a target-specific
  521. numbered address space. For targets that support them, address spaces
  522. may affect how optimizations are performed and/or what target
  523. instructions are used to access the variable. The default address space
  524. is zero. The address space qualifier must precede any other attributes.
  525. LLVM allows an explicit section to be specified for globals. If the
  526. target supports it, it will emit globals to the section specified.
  527. Additionally, the global can placed in a comdat if the target has the necessary
  528. support.
  529. External declarations may have an explicit section specified. Section
  530. information is retained in LLVM IR for targets that make use of this
  531. information. Attaching section information to an external declaration is an
  532. assertion that its definition is located in the specified section. If the
  533. definition is located in a different section, the behavior is undefined.
  534. By default, global initializers are optimized by assuming that global
  535. variables defined within the module are not modified from their
  536. initial values before the start of the global initializer. This is
  537. true even for variables potentially accessible from outside the
  538. module, including those with external linkage or appearing in
  539. ``@llvm.used`` or dllexported variables. This assumption may be suppressed
  540. by marking the variable with ``externally_initialized``.
  541. An explicit alignment may be specified for a global, which must be a
  542. power of 2. If not present, or if the alignment is set to zero, the
  543. alignment of the global is set by the target to whatever it feels
  544. convenient. If an explicit alignment is specified, the global is forced
  545. to have exactly that alignment. Targets and optimizers are not allowed
  546. to over-align the global if the global has an assigned section. In this
  547. case, the extra alignment could be observable: for example, code could
  548. assume that the globals are densely packed in their section and try to
  549. iterate over them as an array, alignment padding would break this
  550. iteration. The maximum alignment is ``1 << 29``.
  551. Globals can also have a :ref:`DLL storage class <dllstorageclass>`,
  552. an optional :ref:`runtime preemption specifier <runtime_preemption_model>`,
  553. an optional :ref:`global attributes <glattrs>` and
  554. an optional list of attached :ref:`metadata <metadata>`.
  555. Variables and aliases can have a
  556. :ref:`Thread Local Storage Model <tls_model>`.
  557. :ref:`Scalable vectors <t_vector>` cannot be global variables or members of
  558. structs or arrays because their size is unknown at compile time.
  559. Syntax::
  560. @<GlobalVarName> = [Linkage] [PreemptionSpecifier] [Visibility]
  561. [DLLStorageClass] [ThreadLocal]
  562. [(unnamed_addr|local_unnamed_addr)] [AddrSpace]
  563. [ExternallyInitialized]
  564. <global | constant> <Type> [<InitializerConstant>]
  565. [, section "name"] [, comdat [($name)]]
  566. [, align <Alignment>] (, !name !N)*
  567. For example, the following defines a global in a numbered address space
  568. with an initializer, section, and alignment:
  569. .. code-block:: llvm
  570. @G = addrspace(5) constant float 1.0, section "foo", align 4
  571. The following example just declares a global variable
  572. .. code-block:: llvm
  573. @G = external global i32
  574. The following example defines a thread-local global with the
  575. ``initialexec`` TLS model:
  576. .. code-block:: llvm
  577. @G = thread_local(initialexec) global i32 0, align 4
  578. .. _functionstructure:
  579. Functions
  580. ---------
  581. LLVM function definitions consist of the "``define``" keyword, an
  582. optional :ref:`linkage type <linkage>`, an optional :ref:`runtime preemption
  583. specifier <runtime_preemption_model>`, an optional :ref:`visibility
  584. style <visibility>`, an optional :ref:`DLL storage class <dllstorageclass>`,
  585. an optional :ref:`calling convention <callingconv>`,
  586. an optional ``unnamed_addr`` attribute, a return type, an optional
  587. :ref:`parameter attribute <paramattrs>` for the return type, a function
  588. name, a (possibly empty) argument list (each with optional :ref:`parameter
  589. attributes <paramattrs>`), optional :ref:`function attributes <fnattrs>`,
  590. an optional address space, an optional section, an optional alignment,
  591. an optional :ref:`comdat <langref_comdats>`,
  592. an optional :ref:`garbage collector name <gc>`, an optional :ref:`prefix <prefixdata>`,
  593. an optional :ref:`prologue <prologuedata>`,
  594. an optional :ref:`personality <personalityfn>`,
  595. an optional list of attached :ref:`metadata <metadata>`,
  596. an opening curly brace, a list of basic blocks, and a closing curly brace.
  597. LLVM function declarations consist of the "``declare``" keyword, an
  598. optional :ref:`linkage type <linkage>`, an optional :ref:`visibility style
  599. <visibility>`, an optional :ref:`DLL storage class <dllstorageclass>`, an
  600. optional :ref:`calling convention <callingconv>`, an optional ``unnamed_addr``
  601. or ``local_unnamed_addr`` attribute, an optional address space, a return type,
  602. an optional :ref:`parameter attribute <paramattrs>` for the return type, a function name, a possibly
  603. empty list of arguments, an optional alignment, an optional :ref:`garbage
  604. collector name <gc>`, an optional :ref:`prefix <prefixdata>`, and an optional
  605. :ref:`prologue <prologuedata>`.
  606. A function definition contains a list of basic blocks, forming the CFG (Control
  607. Flow Graph) for the function. Each basic block may optionally start with a label
  608. (giving the basic block a symbol table entry), contains a list of instructions,
  609. and ends with a :ref:`terminator <terminators>` instruction (such as a branch or
  610. function return). If an explicit label name is not provided, a block is assigned
  611. an implicit numbered label, using the next value from the same counter as used
  612. for unnamed temporaries (:ref:`see above<identifiers>`). For example, if a
  613. function entry block does not have an explicit label, it will be assigned label
  614. "%0", then the first unnamed temporary in that block will be "%1", etc. If a
  615. numeric label is explicitly specified, it must match the numeric label that
  616. would be used implicitly.
  617. The first basic block in a function is special in two ways: it is
  618. immediately executed on entrance to the function, and it is not allowed
  619. to have predecessor basic blocks (i.e. there can not be any branches to
  620. the entry block of a function). Because the block can have no
  621. predecessors, it also cannot have any :ref:`PHI nodes <i_phi>`.
  622. LLVM allows an explicit section to be specified for functions. If the
  623. target supports it, it will emit functions to the section specified.
  624. Additionally, the function can be placed in a COMDAT.
  625. An explicit alignment may be specified for a function. If not present,
  626. or if the alignment is set to zero, the alignment of the function is set
  627. by the target to whatever it feels convenient. If an explicit alignment
  628. is specified, the function is forced to have at least that much
  629. alignment. All alignments must be a power of 2.
  630. If the ``unnamed_addr`` attribute is given, the address is known to not
  631. be significant and two identical functions can be merged.
  632. If the ``local_unnamed_addr`` attribute is given, the address is known to
  633. not be significant within the module.
  634. If an explicit address space is not given, it will default to the program
  635. address space from the :ref:`datalayout string<langref_datalayout>`.
  636. Syntax::
  637. define [linkage] [PreemptionSpecifier] [visibility] [DLLStorageClass]
  638. [cconv] [ret attrs]
  639. <ResultType> @<FunctionName> ([argument list])
  640. [(unnamed_addr|local_unnamed_addr)] [AddrSpace] [fn Attrs]
  641. [section "name"] [comdat [($name)]] [align N] [gc] [prefix Constant]
  642. [prologue Constant] [personality Constant] (!name !N)* { ... }
  643. The argument list is a comma separated sequence of arguments where each
  644. argument is of the following form:
  645. Syntax::
  646. <type> [parameter Attrs] [name]
  647. .. _langref_aliases:
  648. Aliases
  649. -------
  650. Aliases, unlike function or variables, don't create any new data. They
  651. are just a new symbol and metadata for an existing position.
  652. Aliases have a name and an aliasee that is either a global value or a
  653. constant expression.
  654. Aliases may have an optional :ref:`linkage type <linkage>`, an optional
  655. :ref:`runtime preemption specifier <runtime_preemption_model>`, an optional
  656. :ref:`visibility style <visibility>`, an optional :ref:`DLL storage class
  657. <dllstorageclass>` and an optional :ref:`tls model <tls_model>`.
  658. Syntax::
  659. @<Name> = [Linkage] [PreemptionSpecifier] [Visibility] [DLLStorageClass] [ThreadLocal] [(unnamed_addr|local_unnamed_addr)] alias <AliaseeTy>, <AliaseeTy>* @<Aliasee>
  660. The linkage must be one of ``private``, ``internal``, ``linkonce``, ``weak``,
  661. ``linkonce_odr``, ``weak_odr``, ``external``. Note that some system linkers
  662. might not correctly handle dropping a weak symbol that is aliased.
  663. Aliases that are not ``unnamed_addr`` are guaranteed to have the same address as
  664. the aliasee expression. ``unnamed_addr`` ones are only guaranteed to point
  665. to the same content.
  666. If the ``local_unnamed_addr`` attribute is given, the address is known to
  667. not be significant within the module.
  668. Since aliases are only a second name, some restrictions apply, of which
  669. some can only be checked when producing an object file:
  670. * The expression defining the aliasee must be computable at assembly
  671. time. Since it is just a name, no relocations can be used.
  672. * No alias in the expression can be weak as the possibility of the
  673. intermediate alias being overridden cannot be represented in an
  674. object file.
  675. * No global value in the expression can be a declaration, since that
  676. would require a relocation, which is not possible.
  677. .. _langref_ifunc:
  678. IFuncs
  679. -------
  680. IFuncs, like as aliases, don't create any new data or func. They are just a new
  681. symbol that dynamic linker resolves at runtime by calling a resolver function.
  682. IFuncs have a name and a resolver that is a function called by dynamic linker
  683. that returns address of another function associated with the name.
  684. IFunc may have an optional :ref:`linkage type <linkage>` and an optional
  685. :ref:`visibility style <visibility>`.
  686. Syntax::
  687. @<Name> = [Linkage] [Visibility] ifunc <IFuncTy>, <ResolverTy>* @<Resolver>
  688. .. _langref_comdats:
  689. Comdats
  690. -------
  691. Comdat IR provides access to COFF and ELF object file COMDAT functionality.
  692. Comdats have a name which represents the COMDAT key. All global objects that
  693. specify this key will only end up in the final object file if the linker chooses
  694. that key over some other key. Aliases are placed in the same COMDAT that their
  695. aliasee computes to, if any.
  696. Comdats have a selection kind to provide input on how the linker should
  697. choose between keys in two different object files.
  698. Syntax::
  699. $<Name> = comdat SelectionKind
  700. The selection kind must be one of the following:
  701. ``any``
  702. The linker may choose any COMDAT key, the choice is arbitrary.
  703. ``exactmatch``
  704. The linker may choose any COMDAT key but the sections must contain the
  705. same data.
  706. ``largest``
  707. The linker will choose the section containing the largest COMDAT key.
  708. ``noduplicates``
  709. The linker requires that only section with this COMDAT key exist.
  710. ``samesize``
  711. The linker may choose any COMDAT key but the sections must contain the
  712. same amount of data.
  713. Note that the Mach-O platform doesn't support COMDATs, and ELF and WebAssembly
  714. only support ``any`` as a selection kind.
  715. Here is an example of a COMDAT group where a function will only be selected if
  716. the COMDAT key's section is the largest:
  717. .. code-block:: text
  718. $foo = comdat largest
  719. @foo = global i32 2, comdat($foo)
  720. define void @bar() comdat($foo) {
  721. ret void
  722. }
  723. As a syntactic sugar the ``$name`` can be omitted if the name is the same as
  724. the global name:
  725. .. code-block:: text
  726. $foo = comdat any
  727. @foo = global i32 2, comdat
  728. In a COFF object file, this will create a COMDAT section with selection kind
  729. ``IMAGE_COMDAT_SELECT_LARGEST`` containing the contents of the ``@foo`` symbol
  730. and another COMDAT section with selection kind
  731. ``IMAGE_COMDAT_SELECT_ASSOCIATIVE`` which is associated with the first COMDAT
  732. section and contains the contents of the ``@bar`` symbol.
  733. There are some restrictions on the properties of the global object.
  734. It, or an alias to it, must have the same name as the COMDAT group when
  735. targeting COFF.
  736. The contents and size of this object may be used during link-time to determine
  737. which COMDAT groups get selected depending on the selection kind.
  738. Because the name of the object must match the name of the COMDAT group, the
  739. linkage of the global object must not be local; local symbols can get renamed
  740. if a collision occurs in the symbol table.
  741. The combined use of COMDATS and section attributes may yield surprising results.
  742. For example:
  743. .. code-block:: text
  744. $foo = comdat any
  745. $bar = comdat any
  746. @g1 = global i32 42, section "sec", comdat($foo)
  747. @g2 = global i32 42, section "sec", comdat($bar)
  748. From the object file perspective, this requires the creation of two sections
  749. with the same name. This is necessary because both globals belong to different
  750. COMDAT groups and COMDATs, at the object file level, are represented by
  751. sections.
  752. Note that certain IR constructs like global variables and functions may
  753. create COMDATs in the object file in addition to any which are specified using
  754. COMDAT IR. This arises when the code generator is configured to emit globals
  755. in individual sections (e.g. when `-data-sections` or `-function-sections`
  756. is supplied to `llc`).
  757. .. _namedmetadatastructure:
  758. Named Metadata
  759. --------------
  760. Named metadata is a collection of metadata. :ref:`Metadata
  761. nodes <metadata>` (but not metadata strings) are the only valid
  762. operands for a named metadata.
  763. #. Named metadata are represented as a string of characters with the
  764. metadata prefix. The rules for metadata names are the same as for
  765. identifiers, but quoted names are not allowed. ``"\xx"`` type escapes
  766. are still valid, which allows any character to be part of a name.
  767. Syntax::
  768. ; Some unnamed metadata nodes, which are referenced by the named metadata.
  769. !0 = !{!"zero"}
  770. !1 = !{!"one"}
  771. !2 = !{!"two"}
  772. ; A named metadata.
  773. !name = !{!0, !1, !2}
  774. .. _paramattrs:
  775. Parameter Attributes
  776. --------------------
  777. The return type and each parameter of a function type may have a set of
  778. *parameter attributes* associated with them. Parameter attributes are
  779. used to communicate additional information about the result or
  780. parameters of a function. Parameter attributes are considered to be part
  781. of the function, not of the function type, so functions with different
  782. parameter attributes can have the same function type.
  783. Parameter attributes are simple keywords that follow the type specified.
  784. If multiple parameter attributes are needed, they are space separated.
  785. For example:
  786. .. code-block:: llvm
  787. declare i32 @printf(i8* noalias nocapture, ...)
  788. declare i32 @atoi(i8 zeroext)
  789. declare signext i8 @returns_signed_char()
  790. Note that any attributes for the function result (``nounwind``,
  791. ``readonly``) come immediately after the argument list.
  792. Currently, only the following parameter attributes are defined:
  793. ``zeroext``
  794. This indicates to the code generator that the parameter or return
  795. value should be zero-extended to the extent required by the target's
  796. ABI by the caller (for a parameter) or the callee (for a return value).
  797. ``signext``
  798. This indicates to the code generator that the parameter or return
  799. value should be sign-extended to the extent required by the target's
  800. ABI (which is usually 32-bits) by the caller (for a parameter) or
  801. the callee (for a return value).
  802. ``inreg``
  803. This indicates that this parameter or return value should be treated
  804. in a special target-dependent fashion while emitting code for
  805. a function call or return (usually, by putting it in a register as
  806. opposed to memory, though some targets use it to distinguish between
  807. two different kinds of registers). Use of this attribute is
  808. target-specific.
  809. ``byval`` or ``byval(<ty>)``
  810. This indicates that the pointer parameter should really be passed by
  811. value to the function. The attribute implies that a hidden copy of
  812. the pointee is made between the caller and the callee, so the callee
  813. is unable to modify the value in the caller. This attribute is only
  814. valid on LLVM pointer arguments. It is generally used to pass
  815. structs and arrays by value, but is also valid on pointers to
  816. scalars. The copy is considered to belong to the caller not the
  817. callee (for example, ``readonly`` functions should not write to
  818. ``byval`` parameters). This is not a valid attribute for return
  819. values.
  820. The byval attribute also supports an optional type argument, which must be
  821. the same as the pointee type of the argument.
  822. The byval attribute also supports specifying an alignment with the
  823. align attribute. It indicates the alignment of the stack slot to
  824. form and the known alignment of the pointer specified to the call
  825. site. If the alignment is not specified, then the code generator
  826. makes a target-specific assumption.
  827. .. _attr_inalloca:
  828. ``inalloca``
  829. The ``inalloca`` argument attribute allows the caller to take the
  830. address of outgoing stack arguments. An ``inalloca`` argument must
  831. be a pointer to stack memory produced by an ``alloca`` instruction.
  832. The alloca, or argument allocation, must also be tagged with the
  833. inalloca keyword. Only the last argument may have the ``inalloca``
  834. attribute, and that argument is guaranteed to be passed in memory.
  835. An argument allocation may be used by a call at most once because
  836. the call may deallocate it. The ``inalloca`` attribute cannot be
  837. used in conjunction with other attributes that affect argument
  838. storage, like ``inreg``, ``nest``, ``sret``, or ``byval``. The
  839. ``inalloca`` attribute also disables LLVM's implicit lowering of
  840. large aggregate return values, which means that frontend authors
  841. must lower them with ``sret`` pointers.
  842. When the call site is reached, the argument allocation must have
  843. been the most recent stack allocation that is still live, or the
  844. behavior is undefined. It is possible to allocate additional stack
  845. space after an argument allocation and before its call site, but it
  846. must be cleared off with :ref:`llvm.stackrestore
  847. <int_stackrestore>`.
  848. See :doc:`InAlloca` for more information on how to use this
  849. attribute.
  850. ``sret``
  851. This indicates that the pointer parameter specifies the address of a
  852. structure that is the return value of the function in the source
  853. program. This pointer must be guaranteed by the caller to be valid:
  854. loads and stores to the structure may be assumed by the callee not
  855. to trap and to be properly aligned. This is not a valid attribute
  856. for return values.
  857. .. _attr_align:
  858. ``align <n>``
  859. This indicates that the pointer value may be assumed by the optimizer to
  860. have the specified alignment. If the pointer value does not have the
  861. specified alignment, behavior is undefined.
  862. Note that this attribute has additional semantics when combined with the
  863. ``byval`` attribute, which are documented there.
  864. .. _noalias:
  865. ``noalias``
  866. This indicates that objects accessed via pointer values
  867. :ref:`based <pointeraliasing>` on the argument or return value are not also
  868. accessed, during the execution of the function, via pointer values not
  869. *based* on the argument or return value. The attribute on a return value
  870. also has additional semantics described below. The caller shares the
  871. responsibility with the callee for ensuring that these requirements are met.
  872. For further details, please see the discussion of the NoAlias response in
  873. :ref:`alias analysis <Must, May, or No>`.
  874. Note that this definition of ``noalias`` is intentionally similar
  875. to the definition of ``restrict`` in C99 for function arguments.
  876. For function return values, C99's ``restrict`` is not meaningful,
  877. while LLVM's ``noalias`` is. Furthermore, the semantics of the ``noalias``
  878. attribute on return values are stronger than the semantics of the attribute
  879. when used on function arguments. On function return values, the ``noalias``
  880. attribute indicates that the function acts like a system memory allocation
  881. function, returning a pointer to allocated storage disjoint from the
  882. storage for any other object accessible to the caller.
  883. ``nocapture``
  884. This indicates that the callee does not make any copies of the
  885. pointer that outlive the callee itself. This is not a valid
  886. attribute for return values. Addresses used in volatile operations
  887. are considered to be captured.
  888. .. _nest:
  889. ``nest``
  890. This indicates that the pointer parameter can be excised using the
  891. :ref:`trampoline intrinsics <int_trampoline>`. This is not a valid
  892. attribute for return values and can only be applied to one parameter.
  893. ``returned``
  894. This indicates that the function always returns the argument as its return
  895. value. This is a hint to the optimizer and code generator used when
  896. generating the caller, allowing value propagation, tail call optimization,
  897. and omission of register saves and restores in some cases; it is not
  898. checked or enforced when generating the callee. The parameter and the
  899. function return type must be valid operands for the
  900. :ref:`bitcast instruction <i_bitcast>`. This is not a valid attribute for
  901. return values and can only be applied to one parameter.
  902. ``nonnull``
  903. This indicates that the parameter or return pointer is not null. This
  904. attribute may only be applied to pointer typed parameters. This is not
  905. checked or enforced by LLVM; if the parameter or return pointer is null,
  906. the behavior is undefined.
  907. ``dereferenceable(<n>)``
  908. This indicates that the parameter or return pointer is dereferenceable. This
  909. attribute may only be applied to pointer typed parameters. A pointer that
  910. is dereferenceable can be loaded from speculatively without a risk of
  911. trapping. The number of bytes known to be dereferenceable must be provided
  912. in parentheses. It is legal for the number of bytes to be less than the
  913. size of the pointee type. The ``nonnull`` attribute does not imply
  914. dereferenceability (consider a pointer to one element past the end of an
  915. array), however ``dereferenceable(<n>)`` does imply ``nonnull`` in
  916. ``addrspace(0)`` (which is the default address space).
  917. ``dereferenceable_or_null(<n>)``
  918. This indicates that the parameter or return value isn't both
  919. non-null and non-dereferenceable (up to ``<n>`` bytes) at the same
  920. time. All non-null pointers tagged with
  921. ``dereferenceable_or_null(<n>)`` are ``dereferenceable(<n>)``.
  922. For address space 0 ``dereferenceable_or_null(<n>)`` implies that
  923. a pointer is exactly one of ``dereferenceable(<n>)`` or ``null``,
  924. and in other address spaces ``dereferenceable_or_null(<n>)``
  925. implies that a pointer is at least one of ``dereferenceable(<n>)``
  926. or ``null`` (i.e. it may be both ``null`` and
  927. ``dereferenceable(<n>)``). This attribute may only be applied to
  928. pointer typed parameters.
  929. ``swiftself``
  930. This indicates that the parameter is the self/context parameter. This is not
  931. a valid attribute for return values and can only be applied to one
  932. parameter.
  933. ``swifterror``
  934. This attribute is motivated to model and optimize Swift error handling. It
  935. can be applied to a parameter with pointer to pointer type or a
  936. pointer-sized alloca. At the call site, the actual argument that corresponds
  937. to a ``swifterror`` parameter has to come from a ``swifterror`` alloca or
  938. the ``swifterror`` parameter of the caller. A ``swifterror`` value (either
  939. the parameter or the alloca) can only be loaded and stored from, or used as
  940. a ``swifterror`` argument. This is not a valid attribute for return values
  941. and can only be applied to one parameter.
  942. These constraints allow the calling convention to optimize access to
  943. ``swifterror`` variables by associating them with a specific register at
  944. call boundaries rather than placing them in memory. Since this does change
  945. the calling convention, a function which uses the ``swifterror`` attribute
  946. on a parameter is not ABI-compatible with one which does not.
  947. These constraints also allow LLVM to assume that a ``swifterror`` argument
  948. does not alias any other memory visible within a function and that a
  949. ``swifterror`` alloca passed as an argument does not escape.
  950. ``immarg``
  951. This indicates the parameter is required to be an immediate
  952. value. This must be a trivial immediate integer or floating-point
  953. constant. Undef or constant expressions are not valid. This is
  954. only valid on intrinsic declarations and cannot be applied to a
  955. call site or arbitrary function.
  956. .. _gc:
  957. Garbage Collector Strategy Names
  958. --------------------------------
  959. Each function may specify a garbage collector strategy name, which is simply a
  960. string:
  961. .. code-block:: llvm
  962. define void @f() gc "name" { ... }
  963. The supported values of *name* includes those :ref:`built in to LLVM
  964. <builtin-gc-strategies>` and any provided by loaded plugins. Specifying a GC
  965. strategy will cause the compiler to alter its output in order to support the
  966. named garbage collection algorithm. Note that LLVM itself does not contain a
  967. garbage collector, this functionality is restricted to generating machine code
  968. which can interoperate with a collector provided externally.
  969. .. _prefixdata:
  970. Prefix Data
  971. -----------
  972. Prefix data is data associated with a function which the code
  973. generator will emit immediately before the function's entrypoint.
  974. The purpose of this feature is to allow frontends to associate
  975. language-specific runtime metadata with specific functions and make it
  976. available through the function pointer while still allowing the
  977. function pointer to be called.
  978. To access the data for a given function, a program may bitcast the
  979. function pointer to a pointer to the constant's type and dereference
  980. index -1. This implies that the IR symbol points just past the end of
  981. the prefix data. For instance, take the example of a function annotated
  982. with a single ``i32``,
  983. .. code-block:: llvm
  984. define void @f() prefix i32 123 { ... }
  985. The prefix data can be referenced as,
  986. .. code-block:: llvm
  987. %0 = bitcast void* () @f to i32*
  988. %a = getelementptr inbounds i32, i32* %0, i32 -1
  989. %b = load i32, i32* %a
  990. Prefix data is laid out as if it were an initializer for a global variable
  991. of the prefix data's type. The function will be placed such that the
  992. beginning of the prefix data is aligned. This means that if the size
  993. of the prefix data is not a multiple of the alignment size, the
  994. function's entrypoint will not be aligned. If alignment of the
  995. function's entrypoint is desired, padding must be added to the prefix
  996. data.
  997. A function may have prefix data but no body. This has similar semantics
  998. to the ``available_externally`` linkage in that the data may be used by the
  999. optimizers but will not be emitted in the object file.
  1000. .. _prologuedata:
  1001. Prologue Data
  1002. -------------
  1003. The ``prologue`` attribute allows arbitrary code (encoded as bytes) to
  1004. be inserted prior to the function body. This can be used for enabling
  1005. function hot-patching and instrumentation.
  1006. To maintain the semantics of ordinary function calls, the prologue data must
  1007. have a particular format. Specifically, it must begin with a sequence of
  1008. bytes which decode to a sequence of machine instructions, valid for the
  1009. module's target, which transfer control to the point immediately succeeding
  1010. the prologue data, without performing any other visible action. This allows
  1011. the inliner and other passes to reason about the semantics of the function
  1012. definition without needing to reason about the prologue data. Obviously this
  1013. makes the format of the prologue data highly target dependent.
  1014. A trivial example of valid prologue data for the x86 architecture is ``i8 144``,
  1015. which encodes the ``nop`` instruction:
  1016. .. code-block:: text
  1017. define void @f() prologue i8 144 { ... }
  1018. Generally prologue data can be formed by encoding a relative branch instruction
  1019. which skips the metadata, as in this example of valid prologue data for the
  1020. x86_64 architecture, where the first two bytes encode ``jmp .+10``:
  1021. .. code-block:: text
  1022. %0 = type <{ i8, i8, i8* }>
  1023. define void @f() prologue %0 <{ i8 235, i8 8, i8* @md}> { ... }
  1024. A function may have prologue data but no body. This has similar semantics
  1025. to the ``available_externally`` linkage in that the data may be used by the
  1026. optimizers but will not be emitted in the object file.
  1027. .. _personalityfn:
  1028. Personality Function
  1029. --------------------
  1030. The ``personality`` attribute permits functions to specify what function
  1031. to use for exception handling.
  1032. .. _attrgrp:
  1033. Attribute Groups
  1034. ----------------
  1035. Attribute groups are groups of attributes that are referenced by objects within
  1036. the IR. They are important for keeping ``.ll`` files readable, because a lot of
  1037. functions will use the same set of attributes. In the degenerative case of a
  1038. ``.ll`` file that corresponds to a single ``.c`` file, the single attribute
  1039. group will capture the important command line flags used to build that file.
  1040. An attribute group is a module-level object. To use an attribute group, an
  1041. object references the attribute group's ID (e.g. ``#37``). An object may refer
  1042. to more than one attribute group. In that situation, the attributes from the
  1043. different groups are merged.
  1044. Here is an example of attribute groups for a function that should always be
  1045. inlined, has a stack alignment of 4, and which shouldn't use SSE instructions:
  1046. .. code-block:: llvm
  1047. ; Target-independent attributes:
  1048. attributes #0 = { alwaysinline alignstack=4 }
  1049. ; Target-dependent attributes:
  1050. attributes #1 = { "no-sse" }
  1051. ; Function @f has attributes: alwaysinline, alignstack=4, and "no-sse".
  1052. define void @f() #0 #1 { ... }
  1053. .. _fnattrs:
  1054. Function Attributes
  1055. -------------------
  1056. Function attributes are set to communicate additional information about
  1057. a function. Function attributes are considered to be part of the
  1058. function, not of the function type, so functions with different function
  1059. attributes can have the same function type.
  1060. Function attributes are simple keywords that follow the type specified.
  1061. If multiple attributes are needed, they are space separated. For
  1062. example:
  1063. .. code-block:: llvm
  1064. define void @f() noinline { ... }
  1065. define void @f() alwaysinline { ... }
  1066. define void @f() alwaysinline optsize { ... }
  1067. define void @f() optsize { ... }
  1068. ``alignstack(<n>)``
  1069. This attribute indicates that, when emitting the prologue and
  1070. epilogue, the backend should forcibly align the stack pointer.
  1071. Specify the desired alignment, which must be a power of two, in
  1072. parentheses.
  1073. ``allocsize(<EltSizeParam>[, <NumEltsParam>])``
  1074. This attribute indicates that the annotated function will always return at
  1075. least a given number of bytes (or null). Its arguments are zero-indexed
  1076. parameter numbers; if one argument is provided, then it's assumed that at
  1077. least ``CallSite.Args[EltSizeParam]`` bytes will be available at the
  1078. returned pointer. If two are provided, then it's assumed that
  1079. ``CallSite.Args[EltSizeParam] * CallSite.Args[NumEltsParam]`` bytes are
  1080. available. The referenced parameters must be integer types. No assumptions
  1081. are made about the contents of the returned block of memory.
  1082. ``alwaysinline``
  1083. This attribute indicates that the inliner should attempt to inline
  1084. this function into callers whenever possible, ignoring any active
  1085. inlining size threshold for this caller.
  1086. ``builtin``
  1087. This indicates that the callee function at a call site should be
  1088. recognized as a built-in function, even though the function's declaration
  1089. uses the ``nobuiltin`` attribute. This is only valid at call sites for
  1090. direct calls to functions that are declared with the ``nobuiltin``
  1091. attribute.
  1092. ``cold``
  1093. This attribute indicates that this function is rarely called. When
  1094. computing edge weights, basic blocks post-dominated by a cold
  1095. function call are also considered to be cold; and, thus, given low
  1096. weight.
  1097. ``convergent``
  1098. In some parallel execution models, there exist operations that cannot be
  1099. made control-dependent on any additional values. We call such operations
  1100. ``convergent``, and mark them with this attribute.
  1101. The ``convergent`` attribute may appear on functions or call/invoke
  1102. instructions. When it appears on a function, it indicates that calls to
  1103. this function should not be made control-dependent on additional values.
  1104. For example, the intrinsic ``llvm.nvvm.barrier0`` is ``convergent``, so
  1105. calls to this intrinsic cannot be made control-dependent on additional
  1106. values.
  1107. When it appears on a call/invoke, the ``convergent`` attribute indicates
  1108. that we should treat the call as though we're calling a convergent
  1109. function. This is particularly useful on indirect calls; without this we
  1110. may treat such calls as though the target is non-convergent.
  1111. The optimizer may remove the ``convergent`` attribute on functions when it
  1112. can prove that the function does not execute any convergent operations.
  1113. Similarly, the optimizer may remove ``convergent`` on calls/invokes when it
  1114. can prove that the call/invoke cannot call a convergent function.
  1115. ``inaccessiblememonly``
  1116. This attribute indicates that the function may only access memory that
  1117. is not accessible by the module being compiled. This is a weaker form
  1118. of ``readnone``. If the function reads or writes other memory, the
  1119. behavior is undefined.
  1120. ``inaccessiblemem_or_argmemonly``
  1121. This attribute indicates that the function may only access memory that is
  1122. either not accessible by the module being compiled, or is pointed to
  1123. by its pointer arguments. This is a weaker form of ``argmemonly``. If the
  1124. function reads or writes other memory, the behavior is undefined.
  1125. ``inlinehint``
  1126. This attribute indicates that the source code contained a hint that
  1127. inlining this function is desirable (such as the "inline" keyword in
  1128. C/C++). It is just a hint; it imposes no requirements on the
  1129. inliner.
  1130. ``jumptable``
  1131. This attribute indicates that the function should be added to a
  1132. jump-instruction table at code-generation time, and that all address-taken
  1133. references to this function should be replaced with a reference to the
  1134. appropriate jump-instruction-table function pointer. Note that this creates
  1135. a new pointer for the original function, which means that code that depends
  1136. on function-pointer identity can break. So, any function annotated with
  1137. ``jumptable`` must also be ``unnamed_addr``.
  1138. ``minsize``
  1139. This attribute suggests that optimization passes and code generator
  1140. passes make choices that keep the code size of this function as small
  1141. as possible and perform optimizations that may sacrifice runtime
  1142. performance in order to minimize the size of the generated code.
  1143. ``naked``
  1144. This attribute disables prologue / epilogue emission for the
  1145. function. This can have very system-specific consequences.
  1146. ``no-jump-tables``
  1147. When this attribute is set to true, the jump tables and lookup tables that
  1148. can be generated from a switch case lowering are disabled.
  1149. ``nobuiltin``
  1150. This indicates that the callee function at a call site is not recognized as
  1151. a built-in function. LLVM will retain the original call and not replace it
  1152. with equivalent code based on the semantics of the built-in function, unless
  1153. the call site uses the ``builtin`` attribute. This is valid at call sites
  1154. and on function declarations and definitions.
  1155. ``noduplicate``
  1156. This attribute indicates that calls to the function cannot be
  1157. duplicated. A call to a ``noduplicate`` function may be moved
  1158. within its parent function, but may not be duplicated within
  1159. its parent function.
  1160. A function containing a ``noduplicate`` call may still
  1161. be an inlining candidate, provided that the call is not
  1162. duplicated by inlining. That implies that the function has
  1163. internal linkage and only has one call site, so the original
  1164. call is dead after inlining.
  1165. ``nofree``
  1166. This function attribute indicates that the function does not, directly or
  1167. indirectly, call a memory-deallocation function (free, for example). As a
  1168. result, uncaptured pointers that are known to be dereferenceable prior to a
  1169. call to a function with the ``nofree`` attribute are still known to be
  1170. dereferenceable after the call (the capturing condition is necessary in
  1171. environments where the function might communicate the pointer to another thread
  1172. which then deallocates the memory).
  1173. ``noimplicitfloat``
  1174. This attributes disables implicit floating-point instructions.
  1175. ``noinline``
  1176. This attribute indicates that the inliner should never inline this
  1177. function in any situation. This attribute may not be used together
  1178. with the ``alwaysinline`` attribute.
  1179. ``nonlazybind``
  1180. This attribute suppresses lazy symbol binding for the function. This
  1181. may make calls to the function faster, at the cost of extra program
  1182. startup time if the function is not called during program startup.
  1183. ``noredzone``
  1184. This attribute indicates that the code generator should not use a
  1185. red zone, even if the target-specific ABI normally permits it.
  1186. ``indirect-tls-seg-refs``
  1187. This attribute indicates that the code generator should not use
  1188. direct TLS access through segment registers, even if the
  1189. target-specific ABI normally permits it.
  1190. ``noreturn``
  1191. This function attribute indicates that the function never returns
  1192. normally, hence through a return instruction. This produces undefined
  1193. behavior at runtime if the function ever does dynamically return. Annotated
  1194. functions may still raise an exception, i.a., ``nounwind`` is not implied.
  1195. ``norecurse``
  1196. This function attribute indicates that the function does not call itself
  1197. either directly or indirectly down any possible call path. This produces
  1198. undefined behavior at runtime if the function ever does recurse.
  1199. ``willreturn``
  1200. This function attribute indicates that a call of this function will
  1201. either exhibit undefined behavior or comes back and continues execution
  1202. at a point in the existing call stack that includes the current invocation.
  1203. Annotated functions may still raise an exception, i.a., ``nounwind`` is not implied.
  1204. If an invocation of an annotated function does not return control back
  1205. to a point in the call stack, the behavior is undefined.
  1206. ``nosync``
  1207. This function attribute indicates that the function does not communicate
  1208. (synchronize) with another thread through memory or other well-defined means.
  1209. Synchronization is considered possible in the presence of `atomic` accesses
  1210. that enforce an order, thus not "unordered" and "monotonic", `volatile` accesses,
  1211. as well as `convergent` function calls. Note that through `convergent` function calls
  1212. non-memory communication, e.g., cross-lane operations, are possible and are also
  1213. considered synchronization. However `convergent` does not contradict `nosync`.
  1214. If an annotated function does ever synchronize with another thread,
  1215. the behavior is undefined.
  1216. ``nounwind``
  1217. This function attribute indicates that the function never raises an
  1218. exception. If the function does raise an exception, its runtime
  1219. behavior is undefined. However, functions marked nounwind may still
  1220. trap or generate asynchronous exceptions. Exception handling schemes
  1221. that are recognized by LLVM to handle asynchronous exceptions, such
  1222. as SEH, will still provide their implementation defined semantics.
  1223. ``"null-pointer-is-valid"``
  1224. If ``"null-pointer-is-valid"`` is set to ``"true"``, then ``null`` address
  1225. in address-space 0 is considered to be a valid address for memory loads and
  1226. stores. Any analysis or optimization should not treat dereferencing a
  1227. pointer to ``null`` as undefined behavior in this function.
  1228. Note: Comparing address of a global variable to ``null`` may still
  1229. evaluate to false because of a limitation in querying this attribute inside
  1230. constant expressions.
  1231. ``optforfuzzing``
  1232. This attribute indicates that this function should be optimized
  1233. for maximum fuzzing signal.
  1234. ``optnone``
  1235. This function attribute indicates that most optimization passes will skip
  1236. this function, with the exception of interprocedural optimization passes.
  1237. Code generation defaults to the "fast" instruction selector.
  1238. This attribute cannot be used together with the ``alwaysinline``
  1239. attribute; this attribute is also incompatible
  1240. with the ``minsize`` attribute and the ``optsize`` attribute.
  1241. This attribute requires the ``noinline`` attribute to be specified on
  1242. the function as well, so the function is never inlined into any caller.
  1243. Only functions with the ``alwaysinline`` attribute are valid
  1244. candidates for inlining into the body of this function.
  1245. ``optsize``
  1246. This attribute suggests that optimization passes and code generator
  1247. passes make choices that keep the code size of this function low,
  1248. and otherwise do optimizations specifically to reduce code size as
  1249. long as they do not significantly impact runtime performance.
  1250. ``"patchable-function"``
  1251. This attribute tells the code generator that the code
  1252. generated for this function needs to follow certain conventions that
  1253. make it possible for a runtime function to patch over it later.
  1254. The exact effect of this attribute depends on its string value,
  1255. for which there currently is one legal possibility:
  1256. * ``"prologue-short-redirect"`` - This style of patchable
  1257. function is intended to support patching a function prologue to
  1258. redirect control away from the function in a thread safe
  1259. manner. It guarantees that the first instruction of the
  1260. function will be large enough to accommodate a short jump
  1261. instruction, and will be sufficiently aligned to allow being
  1262. fully changed via an atomic compare-and-swap instruction.
  1263. While the first requirement can be satisfied by inserting large
  1264. enough NOP, LLVM can and will try to re-purpose an existing
  1265. instruction (i.e. one that would have to be emitted anyway) as
  1266. the patchable instruction larger than a short jump.
  1267. ``"prologue-short-redirect"`` is currently only supported on
  1268. x86-64.
  1269. This attribute by itself does not imply restrictions on
  1270. inter-procedural optimizations. All of the semantic effects the
  1271. patching may have to be separately conveyed via the linkage type.
  1272. ``"probe-stack"``
  1273. This attribute indicates that the function will trigger a guard region
  1274. in the end of the stack. It ensures that accesses to the stack must be
  1275. no further apart than the size of the guard region to a previous
  1276. access of the stack. It takes one required string value, the name of
  1277. the stack probing function that will be called.
  1278. If a function that has a ``"probe-stack"`` attribute is inlined into
  1279. a function with another ``"probe-stack"`` attribute, the resulting
  1280. function has the ``"probe-stack"`` attribute of the caller. If a
  1281. function that has a ``"probe-stack"`` attribute is inlined into a
  1282. function that has no ``"probe-stack"`` attribute at all, the resulting
  1283. function has the ``"probe-stack"`` attribute of the callee.
  1284. ``readnone``
  1285. On a function, this attribute indicates that the function computes its
  1286. result (or decides to unwind an exception) based strictly on its arguments,
  1287. without dereferencing any pointer arguments or otherwise accessing
  1288. any mutable state (e.g. memory, control registers, etc) visible to
  1289. caller functions. It does not write through any pointer arguments
  1290. (including ``byval`` arguments) and never changes any state visible
  1291. to callers. This means while it cannot unwind exceptions by calling
  1292. the ``C++`` exception throwing methods (since they write to memory), there may
  1293. be non-``C++`` mechanisms that throw exceptions without writing to LLVM
  1294. visible memory.
  1295. On an argument, this attribute indicates that the function does not
  1296. dereference that pointer argument, even though it may read or write the
  1297. memory that the pointer points to if accessed through other pointers.
  1298. If a readnone function reads or writes memory visible to the program, or
  1299. has other side-effects, the behavior is undefined. If a function reads from
  1300. or writes to a readnone pointer argument, the behavior is undefined.
  1301. ``readonly``
  1302. On a function, this attribute indicates that the function does not write
  1303. through any pointer arguments (including ``byval`` arguments) or otherwise
  1304. modify any state (e.g. memory, control registers, etc) visible to
  1305. caller functions. It may dereference pointer arguments and read
  1306. state that may be set in the caller. A readonly function always
  1307. returns the same value (or unwinds an exception identically) when
  1308. called with the same set of arguments and global state. This means while it
  1309. cannot unwind exceptions by calling the ``C++`` exception throwing methods
  1310. (since they write to memory), there may be non-``C++`` mechanisms that throw
  1311. exceptions without writing to LLVM visible memory.
  1312. On an argument, this attribute indicates that the function does not write
  1313. through this pointer argument, even though it may write to the memory that
  1314. the pointer points to.
  1315. If a readonly function writes memory visible to the program, or
  1316. has other side-effects, the behavior is undefined. If a function writes to
  1317. a readonly pointer argument, the behavior is undefined.
  1318. ``"stack-probe-size"``
  1319. This attribute controls the behavior of stack probes: either
  1320. the ``"probe-stack"`` attribute, or ABI-required stack probes, if any.
  1321. It defines the size of the guard region. It ensures that if the function
  1322. may use more stack space than the size of the guard region, stack probing
  1323. sequence will be emitted. It takes one required integer value, which
  1324. is 4096 by default.
  1325. If a function that has a ``"stack-probe-size"`` attribute is inlined into
  1326. a function with another ``"stack-probe-size"`` attribute, the resulting
  1327. function has the ``"stack-probe-size"`` attribute that has the lower
  1328. numeric value. If a function that has a ``"stack-probe-size"`` attribute is
  1329. inlined into a function that has no ``"stack-probe-size"`` attribute
  1330. at all, the resulting function has the ``"stack-probe-size"`` attribute
  1331. of the callee.
  1332. ``"no-stack-arg-probe"``
  1333. This attribute disables ABI-required stack probes, if any.
  1334. ``writeonly``
  1335. On a function, this attribute indicates that the function may write to but
  1336. does not read from memory.
  1337. On an argument, this attribute indicates that the function may write to but
  1338. does not read through this pointer argument (even though it may read from
  1339. the memory that the pointer points to).
  1340. If a writeonly function reads memory visible to the program, or
  1341. has other side-effects, the behavior is undefined. If a function reads
  1342. from a writeonly pointer argument, the behavior is undefined.
  1343. ``argmemonly``
  1344. This attribute indicates that the only memory accesses inside function are
  1345. loads and stores from objects pointed to by its pointer-typed arguments,
  1346. with arbitrary offsets. Or in other words, all memory operations in the
  1347. function can refer to memory only using pointers based on its function
  1348. arguments.
  1349. Note that ``argmemonly`` can be used together with ``readonly`` attribute
  1350. in order to specify that function reads only from its arguments.
  1351. If an argmemonly function reads or writes memory other than the pointer
  1352. arguments, or has other side-effects, the behavior is undefined.
  1353. ``returns_twice``
  1354. This attribute indicates that this function can return twice. The C
  1355. ``setjmp`` is an example of such a function. The compiler disables
  1356. some optimizations (like tail calls) in the caller of these
  1357. functions.
  1358. ``safestack``
  1359. This attribute indicates that
  1360. `SafeStack <http://clang.llvm.org/docs/SafeStack.html>`_
  1361. protection is enabled for this function.
  1362. If a function that has a ``safestack`` attribute is inlined into a
  1363. function that doesn't have a ``safestack`` attribute or which has an
  1364. ``ssp``, ``sspstrong`` or ``sspreq`` attribute, then the resulting
  1365. function will have a ``safestack`` attribute.
  1366. ``sanitize_address``
  1367. This attribute indicates that AddressSanitizer checks
  1368. (dynamic address safety analysis) are enabled for this function.
  1369. ``sanitize_memory``
  1370. This attribute indicates that MemorySanitizer checks (dynamic detection
  1371. of accesses to uninitialized memory) are enabled for this function.
  1372. ``sanitize_thread``
  1373. This attribute indicates that ThreadSanitizer checks
  1374. (dynamic thread safety analysis) are enabled for this function.
  1375. ``sanitize_hwaddress``
  1376. This attribute indicates that HWAddressSanitizer checks
  1377. (dynamic address safety analysis based on tagged pointers) are enabled for
  1378. this function.
  1379. ``sanitize_memtag``
  1380. This attribute indicates that MemTagSanitizer checks
  1381. (dynamic address safety analysis based on Armv8 MTE) are enabled for
  1382. this function.
  1383. ``speculative_load_hardening``
  1384. This attribute indicates that
  1385. `Speculative Load Hardening <https://llvm.org/docs/SpeculativeLoadHardening.html>`_
  1386. should be enabled for the function body.
  1387. Speculative Load Hardening is a best-effort mitigation against
  1388. information leak attacks that make use of control flow
  1389. miss-speculation - specifically miss-speculation of whether a branch
  1390. is taken or not. Typically vulnerabilities enabling such attacks are
  1391. classified as "Spectre variant #1". Notably, this does not attempt to
  1392. mitigate against miss-speculation of branch target, classified as
  1393. "Spectre variant #2" vulnerabilities.
  1394. When inlining, the attribute is sticky. Inlining a function that carries
  1395. this attribute will cause the caller to gain the attribute. This is intended
  1396. to provide a maximally conservative model where the code in a function
  1397. annotated with this attribute will always (even after inlining) end up
  1398. hardened.
  1399. ``speculatable``
  1400. This function attribute indicates that the function does not have any
  1401. effects besides calculating its result and does not have undefined behavior.
  1402. Note that ``speculatable`` is not enough to conclude that along any
  1403. particular execution path the number of calls to this function will not be
  1404. externally observable. This attribute is only valid on functions
  1405. and declarations, not on individual call sites. If a function is
  1406. incorrectly marked as speculatable and really does exhibit
  1407. undefined behavior, the undefined behavior may be observed even
  1408. if the call site is dead code.
  1409. ``ssp``
  1410. This attribute indicates that the function should emit a stack
  1411. smashing protector. It is in the form of a "canary" --- a random value
  1412. placed on the stack before the local variables that's checked upon
  1413. return from the function to see if it has been overwritten. A
  1414. heuristic is used to determine if a function needs stack protectors
  1415. or not. The heuristic used will enable protectors for functions with:
  1416. - Character arrays larger than ``ssp-buffer-size`` (default 8).
  1417. - Aggregates containing character arrays larger than ``ssp-buffer-size``.
  1418. - Calls to alloca() with variable sizes or constant sizes greater than
  1419. ``ssp-buffer-size``.
  1420. Variables that are identified as requiring a protector will be arranged
  1421. on the stack such that they are adjacent to the stack protector guard.
  1422. If a function that has an ``ssp`` attribute is inlined into a
  1423. function that doesn't have an ``ssp`` attribute, then the resulting
  1424. function will have an ``ssp`` attribute.
  1425. ``sspreq``
  1426. This attribute indicates that the function should *always* emit a
  1427. stack smashing protector. This overrides the ``ssp`` function
  1428. attribute.
  1429. Variables that are identified as requiring a protector will be arranged
  1430. on the stack such that they are adjacent to the stack protector guard.
  1431. The specific layout rules are:
  1432. #. Large arrays and structures containing large arrays
  1433. (``>= ssp-buffer-size``) are closest to the stack protector.
  1434. #. Small arrays and structures containing small arrays
  1435. (``< ssp-buffer-size``) are 2nd closest to the protector.
  1436. #. Variables that have had their address taken are 3rd closest to the
  1437. protector.
  1438. If a function that has an ``sspreq`` attribute is inlined into a
  1439. function that doesn't have an ``sspreq`` attribute or which has an
  1440. ``ssp`` or ``sspstrong`` attribute, then the resulting function will have
  1441. an ``sspreq`` attribute.
  1442. ``sspstrong``
  1443. This attribute indicates that the function should emit a stack smashing
  1444. protector. This attribute causes a strong heuristic to be used when
  1445. determining if a function needs stack protectors. The strong heuristic
  1446. will enable protectors for functions with:
  1447. - Arrays of any size and type
  1448. - Aggregates containing an array of any size and type.
  1449. - Calls to alloca().
  1450. - Local variables that have had their address taken.
  1451. Variables that are identified as requiring a protector will be arranged
  1452. on the stack such that they are adjacent to the stack protector guard.
  1453. The specific layout rules are:
  1454. #. Large arrays and structures containing large arrays
  1455. (``>= ssp-buffer-size``) are closest to the stack protector.
  1456. #. Small arrays and structures containing small arrays
  1457. (``< ssp-buffer-size``) are 2nd closest to the protector.
  1458. #. Variables that have had their address taken are 3rd closest to the
  1459. protector.
  1460. This overrides the ``ssp`` function attribute.
  1461. If a function that has an ``sspstrong`` attribute is inlined into a
  1462. function that doesn't have an ``sspstrong`` attribute, then the
  1463. resulting function will have an ``sspstrong`` attribute.
  1464. ``strictfp``
  1465. This attribute indicates that the function was called from a scope that
  1466. requires strict floating-point semantics. LLVM will not attempt any
  1467. optimizations that require assumptions about the floating-point rounding
  1468. mode or that might alter the state of floating-point status flags that
  1469. might otherwise be set or cleared by calling this function.
  1470. ``"thunk"``
  1471. This attribute indicates that the function will delegate to some other
  1472. function with a tail call. The prototype of a thunk should not be used for
  1473. optimization purposes. The caller is expected to cast the thunk prototype to
  1474. match the thunk target prototype.
  1475. ``uwtable``
  1476. This attribute indicates that the ABI being targeted requires that
  1477. an unwind table entry be produced for this function even if we can
  1478. show that no exceptions passes by it. This is normally the case for
  1479. the ELF x86-64 abi, but it can be disabled for some compilation
  1480. units.
  1481. ``nocf_check``
  1482. This attribute indicates that no control-flow check will be performed on
  1483. the attributed entity. It disables -fcf-protection=<> for a specific
  1484. entity to fine grain the HW control flow protection mechanism. The flag
  1485. is target independent and currently appertains to a function or function
  1486. pointer.
  1487. ``shadowcallstack``
  1488. This attribute indicates that the ShadowCallStack checks are enabled for
  1489. the function. The instrumentation checks that the return address for the
  1490. function has not changed between the function prolog and eiplog. It is
  1491. currently x86_64-specific.
  1492. .. _glattrs:
  1493. Global Attributes
  1494. -----------------
  1495. Attributes may be set to communicate additional information about a global variable.
  1496. Unlike :ref:`function attributes <fnattrs>`, attributes on a global variable
  1497. are grouped into a single :ref:`attribute group <attrgrp>`.
  1498. .. _opbundles:
  1499. Operand Bundles
  1500. ---------------
  1501. Operand bundles are tagged sets of SSA values that can be associated
  1502. with certain LLVM instructions (currently only ``call`` s and
  1503. ``invoke`` s). In a way they are like metadata, but dropping them is
  1504. incorrect and will change program semantics.
  1505. Syntax::
  1506. operand bundle set ::= '[' operand bundle (, operand bundle )* ']'
  1507. operand bundle ::= tag '(' [ bundle operand ] (, bundle operand )* ')'
  1508. bundle operand ::= SSA value
  1509. tag ::= string constant
  1510. Operand bundles are **not** part of a function's signature, and a
  1511. given function may be called from multiple places with different kinds
  1512. of operand bundles. This reflects the fact that the operand bundles
  1513. are conceptually a part of the ``call`` (or ``invoke``), not the
  1514. callee being dispatched to.
  1515. Operand bundles are a generic mechanism intended to support
  1516. runtime-introspection-like functionality for managed languages. While
  1517. the exact semantics of an operand bundle depend on the bundle tag,
  1518. there are certain limitations to how much the presence of an operand
  1519. bundle can influence the semantics of a program. These restrictions
  1520. are described as the semantics of an "unknown" operand bundle. As
  1521. long as the behavior of an operand bundle is describable within these
  1522. restrictions, LLVM does not need to have special knowledge of the
  1523. operand bundle to not miscompile programs containing it.
  1524. - The bundle operands for an unknown operand bundle escape in unknown
  1525. ways before control is transferred to the callee or invokee.
  1526. - Calls and invokes with operand bundles have unknown read / write
  1527. effect on the heap on entry and exit (even if the call target is
  1528. ``readnone`` or ``readonly``), unless they're overridden with
  1529. callsite specific attributes.
  1530. - An operand bundle at a call site cannot change the implementation
  1531. of the called function. Inter-procedural optimizations work as
  1532. usual as long as they take into account the first two properties.
  1533. More specific types of operand bundles are described below.
  1534. .. _deopt_opbundles:
  1535. Deoptimization Operand Bundles
  1536. ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  1537. Deoptimization operand bundles are characterized by the ``"deopt"``
  1538. operand bundle tag. These operand bundles represent an alternate
  1539. "safe" continuation for the call site they're attached to, and can be
  1540. used by a suitable runtime to deoptimize the compiled frame at the
  1541. specified call site. There can be at most one ``"deopt"`` operand
  1542. bundle attached to a call site. Exact details of deoptimization is
  1543. out of scope for the language reference, but it usually involves
  1544. rewriting a compiled frame into a set of interpreted frames.
  1545. From the compiler's perspective, deoptimization operand bundles make
  1546. the call sites they're attached to at least ``readonly``. They read
  1547. through all of their pointer typed operands (even if they're not
  1548. otherwise escaped) and the entire visible heap. Deoptimization
  1549. operand bundles do not capture their operands except during
  1550. deoptimization, in which case control will not be returned to the
  1551. compiled frame.
  1552. The inliner knows how to inline through calls that have deoptimization
  1553. operand bundles. Just like inlining through a normal call site
  1554. involves composing the normal and exceptional continuations, inlining
  1555. through a call site with a deoptimization operand bundle needs to
  1556. appropriately compose the "safe" deoptimization continuation. The
  1557. inliner does this by prepending the parent's deoptimization
  1558. continuation to every deoptimization continuation in the inlined body.
  1559. E.g. inlining ``@f`` into ``@g`` in the following example
  1560. .. code-block:: llvm
  1561. define void @f() {
  1562. call void @x() ;; no deopt state
  1563. call void @y() [ "deopt"(i32 10) ]
  1564. call void @y() [ "deopt"(i32 10), "unknown"(i8* null) ]
  1565. ret void
  1566. }
  1567. define void @g() {
  1568. call void @f() [ "deopt"(i32 20) ]
  1569. ret void
  1570. }
  1571. will result in
  1572. .. code-block:: llvm
  1573. define void @g() {
  1574. call void @x() ;; still no deopt state
  1575. call void @y() [ "deopt"(i32 20, i32 10) ]
  1576. call void @y() [ "deopt"(i32 20, i32 10), "unknown"(i8* null) ]
  1577. ret void
  1578. }
  1579. It is the frontend's responsibility to structure or encode the
  1580. deoptimization state in a way that syntactically prepending the
  1581. caller's deoptimization state to the callee's deoptimization state is
  1582. semantically equivalent to composing the caller's deoptimization
  1583. continuation after the callee's deoptimization continuation.
  1584. .. _ob_funclet:
  1585. Funclet Operand Bundles
  1586. ^^^^^^^^^^^^^^^^^^^^^^^
  1587. Funclet operand bundles are characterized by the ``"funclet"``
  1588. operand bundle tag. These operand bundles indicate that a call site
  1589. is within a particular funclet. There can be at most one
  1590. ``"funclet"`` operand bundle attached to a call site and it must have
  1591. exactly one bundle operand.
  1592. If any funclet EH pads have been "entered" but not "exited" (per the
  1593. `description in the EH doc\ <ExceptionHandling.html#wineh-constraints>`_),
  1594. it is undefined behavior to execute a ``call`` or ``invoke`` which:
  1595. * does not have a ``"funclet"`` bundle and is not a ``call`` to a nounwind
  1596. intrinsic, or
  1597. * has a ``"funclet"`` bundle whose operand is not the most-recently-entered
  1598. not-yet-exited funclet EH pad.
  1599. Similarly, if no funclet EH pads have been entered-but-not-yet-exited,
  1600. executing a ``call`` or ``invoke`` with a ``"funclet"`` bundle is undefined behavior.
  1601. GC Transition Operand Bundles
  1602. ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  1603. GC transition operand bundles are characterized by the
  1604. ``"gc-transition"`` operand bundle tag. These operand bundles mark a
  1605. call as a transition between a function with one GC strategy to a
  1606. function with a different GC strategy. If coordinating the transition
  1607. between GC strategies requires additional code generation at the call
  1608. site, these bundles may contain any values that are needed by the
  1609. generated code. For more details, see :ref:`GC Transitions
  1610. <gc_transition_args>`.
  1611. .. _moduleasm:
  1612. Module-Level Inline Assembly
  1613. ----------------------------
  1614. Modules may contain "module-level inline asm" blocks, which corresponds
  1615. to the GCC "file scope inline asm" blocks. These blocks are internally
  1616. concatenated by LLVM and treated as a single unit, but may be separated
  1617. in the ``.ll`` file if desired. The syntax is very simple:
  1618. .. code-block:: llvm
  1619. module asm "inline asm code goes here"
  1620. module asm "more can go here"
  1621. The strings can contain any character by escaping non-printable
  1622. characters. The escape sequence used is simply "\\xx" where "xx" is the
  1623. two digit hex code for the number.
  1624. Note that the assembly string *must* be parseable by LLVM's integrated assembler
  1625. (unless it is disabled), even when emitting a ``.s`` file.
  1626. .. _langref_datalayout:
  1627. Data Layout
  1628. -----------
  1629. A module may specify a target specific data layout string that specifies
  1630. how data is to be laid out in memory. The syntax for the data layout is
  1631. simply:
  1632. .. code-block:: llvm
  1633. target datalayout = "layout specification"
  1634. The *layout specification* consists of a list of specifications
  1635. separated by the minus sign character ('-'). Each specification starts
  1636. with a letter and may include other information after the letter to
  1637. define some aspect of the data layout. The specifications accepted are
  1638. as follows:
  1639. ``E``
  1640. Specifies that the target lays out data in big-endian form. That is,
  1641. the bits with the most significance have the lowest address
  1642. location.
  1643. ``e``
  1644. Specifies that the target lays out data in little-endian form. That
  1645. is, the bits with the least significance have the lowest address
  1646. location.
  1647. ``S<size>``
  1648. Specifies the natural alignment of the stack in bits. Alignment
  1649. promotion of stack variables is limited to the natural stack
  1650. alignment to avoid dynamic stack realignment. The stack alignment
  1651. must be a multiple of 8-bits. If omitted, the natural stack
  1652. alignment defaults to "unspecified", which does not prevent any
  1653. alignment promotions.
  1654. ``P<address space>``
  1655. Specifies the address space that corresponds to program memory.
  1656. Harvard architectures can use this to specify what space LLVM
  1657. should place things such as functions into. If omitted, the
  1658. program memory space defaults to the default address space of 0,
  1659. which corresponds to a Von Neumann architecture that has code
  1660. and data in the same space.
  1661. ``A<address space>``
  1662. Specifies the address space of objects created by '``alloca``'.
  1663. Defaults to the default address space of 0.
  1664. ``p[n]:<size>:<abi>:<pref>:<idx>``
  1665. This specifies the *size* of a pointer and its ``<abi>`` and
  1666. ``<pref>``\erred alignments for address space ``n``. The fourth parameter
  1667. ``<idx>`` is a size of index that used for address calculation. If not
  1668. specified, the default index size is equal to the pointer size. All sizes
  1669. are in bits. The address space, ``n``, is optional, and if not specified,
  1670. denotes the default address space 0. The value of ``n`` must be
  1671. in the range [1,2^23).
  1672. ``i<size>:<abi>:<pref>``
  1673. This specifies the alignment for an integer type of a given bit
  1674. ``<size>``. The value of ``<size>`` must be in the range [1,2^23).
  1675. ``v<size>:<abi>:<pref>``
  1676. This specifies the alignment for a vector type of a given bit
  1677. ``<size>``.
  1678. ``f<size>:<abi>:<pref>``
  1679. This specifies the alignment for a floating-point type of a given bit
  1680. ``<size>``. Only values of ``<size>`` that are supported by the target
  1681. will work. 32 (float) and 64 (double) are supported on all targets; 80
  1682. or 128 (different flavors of long double) are also supported on some
  1683. targets.
  1684. ``a:<abi>:<pref>``
  1685. This specifies the alignment for an object of aggregate type.
  1686. ``F<type><abi>``
  1687. This specifies the alignment for function pointers.
  1688. The options for ``<type>`` are:
  1689. * ``i``: The alignment of function pointers is independent of the alignment
  1690. of functions, and is a multiple of ``<abi>``.
  1691. * ``n``: The alignment of function pointers is a multiple of the explicit
  1692. alignment specified on the function, and is a multiple of ``<abi>``.
  1693. ``m:<mangling>``
  1694. If present, specifies that llvm names are mangled in the output. Symbols
  1695. prefixed with the mangling escape character ``\01`` are passed through
  1696. directly to the assembler without the escape character. The mangling style
  1697. options are
  1698. * ``e``: ELF mangling: Private symbols get a ``.L`` prefix.
  1699. * ``m``: Mips mangling: Private symbols get a ``$`` prefix.
  1700. * ``o``: Mach-O mangling: Private symbols get ``L`` prefix. Other
  1701. symbols get a ``_`` prefix.
  1702. * ``x``: Windows x86 COFF mangling: Private symbols get the usual prefix.
  1703. Regular C symbols get a ``_`` prefix. Functions with ``__stdcall``,
  1704. ``__fastcall``, and ``__vectorcall`` have custom mangling that appends
  1705. ``@N`` where N is the number of bytes used to pass parameters. C++ symbols
  1706. starting with ``?`` are not mangled in any way.
  1707. * ``w``: Windows COFF mangling: Similar to ``x``, except that normal C
  1708. symbols do not receive a ``_`` prefix.
  1709. ``n<size1>:<size2>:<size3>...``
  1710. This specifies a set of native integer widths for the target CPU in
  1711. bits. For example, it might contain ``n32`` for 32-bit PowerPC,
  1712. ``n32:64`` for PowerPC 64, or ``n8:16:32:64`` for X86-64. Elements of
  1713. this set are considered to support most general arithmetic operations
  1714. efficiently.
  1715. ``ni:<address space0>:<address space1>:<address space2>...``
  1716. This specifies pointer types with the specified address spaces
  1717. as :ref:`Non-Integral Pointer Type <nointptrtype>` s. The ``0``
  1718. address space cannot be specified as non-integral.
  1719. On every specification that takes a ``<abi>:<pref>``, specifying the
  1720. ``<pref>`` alignment is optional. If omitted, the preceding ``:``
  1721. should be omitted too and ``<pref>`` will be equal to ``<abi>``.
  1722. When constructing the data layout for a given target, LLVM starts with a
  1723. default set of specifications which are then (possibly) overridden by
  1724. the specifications in the ``datalayout`` keyword. The default
  1725. specifications are given in this list:
  1726. - ``E`` - big endian
  1727. - ``p:64:64:64`` - 64-bit pointers with 64-bit alignment.
  1728. - ``p[n]:64:64:64`` - Other address spaces are assumed to be the
  1729. same as the default address space.
  1730. - ``S0`` - natural stack alignment is unspecified
  1731. - ``i1:8:8`` - i1 is 8-bit (byte) aligned
  1732. - ``i8:8:8`` - i8 is 8-bit (byte) aligned
  1733. - ``i16:16:16`` - i16 is 16-bit aligned
  1734. - ``i32:32:32`` - i32 is 32-bit aligned
  1735. - ``i64:32:64`` - i64 has ABI alignment of 32-bits but preferred
  1736. alignment of 64-bits
  1737. - ``f16:16:16`` - half is 16-bit aligned
  1738. - ``f32:32:32`` - float is 32-bit aligned
  1739. - ``f64:64:64`` - double is 64-bit aligned
  1740. - ``f128:128:128`` - quad is 128-bit aligned
  1741. - ``v64:64:64`` - 64-bit vector is 64-bit aligned
  1742. - ``v128:128:128`` - 128-bit vector is 128-bit aligned
  1743. - ``a:0:64`` - aggregates are 64-bit aligned
  1744. When LLVM is determining the alignment for a given type, it uses the
  1745. following rules:
  1746. #. If the type sought is an exact match for one of the specifications,
  1747. that specification is used.
  1748. #. If no match is found, and the type sought is an integer type, then
  1749. the smallest integer type that is larger than the bitwidth of the
  1750. sought type is used. If none of the specifications are larger than
  1751. the bitwidth then the largest integer type is used. For example,
  1752. given the default specifications above, the i7 type will use the
  1753. alignment of i8 (next largest) while both i65 and i256 will use the
  1754. alignment of i64 (largest specified).
  1755. #. If no match is found, and the type sought is a vector type, then the
  1756. largest vector type that is smaller than the sought vector type will
  1757. be used as a fall back. This happens because <128 x double> can be
  1758. implemented in terms of 64 <2 x double>, for example.
  1759. The function of the data layout string may not be what you expect.
  1760. Notably, this is not a specification from the frontend of what alignment
  1761. the code generator should use.
  1762. Instead, if specified, the target data layout is required to match what
  1763. the ultimate *code generator* expects. This string is used by the
  1764. mid-level optimizers to improve code, and this only works if it matches
  1765. what the ultimate code generator uses. There is no way to generate IR
  1766. that does not embed this target-specific detail into the IR. If you
  1767. don't specify the string, the default specifications will be used to
  1768. generate a Data Layout and the optimization phases will operate
  1769. accordingly and introduce target specificity into the IR with respect to
  1770. these default specifications.
  1771. .. _langref_triple:
  1772. Target Triple
  1773. -------------
  1774. A module may specify a target triple string that describes the target
  1775. host. The syntax for the target triple is simply:
  1776. .. code-block:: llvm
  1777. target triple = "x86_64-apple-macosx10.7.0"
  1778. The *target triple* string consists of a series of identifiers delimited
  1779. by the minus sign character ('-'). The canonical forms are:
  1780. ::
  1781. ARCHITECTURE-VENDOR-OPERATING_SYSTEM
  1782. ARCHITECTURE-VENDOR-OPERATING_SYSTEM-ENVIRONMENT
  1783. This information is passed along to the backend so that it generates
  1784. code for the proper architecture. It's possible to override this on the
  1785. command line with the ``-mtriple`` command line option.
  1786. .. _pointeraliasing:
  1787. Pointer Aliasing Rules
  1788. ----------------------
  1789. Any memory access must be done through a pointer value associated with
  1790. an address range of the memory access, otherwise the behavior is
  1791. undefined. Pointer values are associated with address ranges according
  1792. to the following rules:
  1793. - A pointer value is associated with the addresses associated with any
  1794. value it is *based* on.
  1795. - An address of a global variable is associated with the address range
  1796. of the variable's storage.
  1797. - The result value of an allocation instruction is associated with the
  1798. address range of the allocated storage.
  1799. - A null pointer in the default address-space is associated with no
  1800. address.
  1801. - An :ref:`undef value <undefvalues>` in *any* address-space is
  1802. associated with no address.
  1803. - An integer constant other than zero or a pointer value returned from
  1804. a function not defined within LLVM may be associated with address
  1805. ranges allocated through mechanisms other than those provided by
  1806. LLVM. Such ranges shall not overlap with any ranges of addresses
  1807. allocated by mechanisms provided by LLVM.
  1808. A pointer value is *based* on another pointer value according to the
  1809. following rules:
  1810. - A pointer value formed from a scalar ``getelementptr`` operation is *based* on
  1811. the pointer-typed operand of the ``getelementptr``.
  1812. - The pointer in lane *l* of the result of a vector ``getelementptr`` operation
  1813. is *based* on the pointer in lane *l* of the vector-of-pointers-typed operand
  1814. of the ``getelementptr``.
  1815. - The result value of a ``bitcast`` is *based* on the operand of the
  1816. ``bitcast``.
  1817. - A pointer value formed by an ``inttoptr`` is *based* on all pointer
  1818. values that contribute (directly or indirectly) to the computation of
  1819. the pointer's value.
  1820. - The "*based* on" relationship is transitive.
  1821. Note that this definition of *"based"* is intentionally similar to the
  1822. definition of *"based"* in C99, though it is slightly weaker.
  1823. LLVM IR does not associate types with memory. The result type of a
  1824. ``load`` merely indicates the size and alignment of the memory from
  1825. which to load, as well as the interpretation of the value. The first
  1826. operand type of a ``store`` similarly only indicates the size and
  1827. alignment of the store.
  1828. Consequently, type-based alias analysis, aka TBAA, aka
  1829. ``-fstrict-aliasing``, is not applicable to general unadorned LLVM IR.
  1830. :ref:`Metadata <metadata>` may be used to encode additional information
  1831. which specialized optimization passes may use to implement type-based
  1832. alias analysis.
  1833. .. _volatile:
  1834. Volatile Memory Accesses
  1835. ------------------------
  1836. Certain memory accesses, such as :ref:`load <i_load>`'s,
  1837. :ref:`store <i_store>`'s, and :ref:`llvm.memcpy <int_memcpy>`'s may be
  1838. marked ``volatile``. The optimizers must not change the number of
  1839. volatile operations or change their order of execution relative to other
  1840. volatile operations. The optimizers *may* change the order of volatile
  1841. operations relative to non-volatile operations. This is not Java's
  1842. "volatile" and has no cross-thread synchronization behavior.
  1843. A volatile load or store may have additional target-specific semantics.
  1844. Any volatile operation can have side effects, and any volatile operation
  1845. can read and/or modify state which is not accessible via a regular load
  1846. or store in this module. Volatile operations may use addresses which do
  1847. not point to memory (like MMIO registers). This means the compiler may
  1848. not use a volatile operation to prove a non-volatile access to that
  1849. address has defined behavior.
  1850. The allowed side-effects for volatile accesses are limited. If a
  1851. non-volatile store to a given address would be legal, a volatile
  1852. operation may modify the memory at that address. A volatile operation
  1853. may not modify any other memory accessible by the module being compiled.
  1854. A volatile operation may not call any code in the current module.
  1855. The compiler may assume execution will continue after a volatile operation,
  1856. so operations which modify memory or may have undefined behavior can be
  1857. hoisted past a volatile operation.
  1858. IR-level volatile loads and stores cannot safely be optimized into
  1859. llvm.memcpy or llvm.memmove intrinsics even when those intrinsics are
  1860. flagged volatile. Likewise, the backend should never split or merge
  1861. target-legal volatile load/store instructions.
  1862. .. admonition:: Rationale
  1863. Platforms may rely on volatile loads and stores of natively supported
  1864. data width to be executed as single instruction. For example, in C
  1865. this holds for an l-value of volatile primitive type with native
  1866. hardware support, but not necessarily for aggregate types. The
  1867. frontend upholds these expectations, which are intentionally
  1868. unspecified in the IR. The rules above ensure that IR transformations
  1869. do not violate the frontend's contract with the language.
  1870. .. _memmodel:
  1871. Memory Model for Concurrent Operations
  1872. --------------------------------------
  1873. The LLVM IR does not define any way to start parallel threads of
  1874. execution or to register signal handlers. Nonetheless, there are
  1875. platform-specific ways to create them, and we define LLVM IR's behavior
  1876. in their presence. This model is inspired by the C++0x memory model.
  1877. For a more informal introduction to this model, see the :doc:`Atomics`.
  1878. We define a *happens-before* partial order as the least partial order
  1879. that
  1880. - Is a superset of single-thread program order, and
  1881. - When a *synchronizes-with* ``b``, includes an edge from ``a`` to
  1882. ``b``. *Synchronizes-with* pairs are introduced by platform-specific
  1883. techniques, like pthread locks, thread creation, thread joining,
  1884. etc., and by atomic instructions. (See also :ref:`Atomic Memory Ordering
  1885. Constraints <ordering>`).
  1886. Note that program order does not introduce *happens-before* edges
  1887. between a thread and signals executing inside that thread.
  1888. Every (defined) read operation (load instructions, memcpy, atomic
  1889. loads/read-modify-writes, etc.) R reads a series of bytes written by
  1890. (defined) write operations (store instructions, atomic
  1891. stores/read-modify-writes, memcpy, etc.). For the purposes of this
  1892. section, initialized globals are considered to have a write of the
  1893. initializer which is atomic and happens before any other read or write
  1894. of the memory in question. For each byte of a read R, R\ :sub:`byte`
  1895. may see any write to the same byte, except:
  1896. - If write\ :sub:`1` happens before write\ :sub:`2`, and
  1897. write\ :sub:`2` happens before R\ :sub:`byte`, then
  1898. R\ :sub:`byte` does not see write\ :sub:`1`.
  1899. - If R\ :sub:`byte` happens before write\ :sub:`3`, then
  1900. R\ :sub:`byte` does not see write\ :sub:`3`.
  1901. Given that definition, R\ :sub:`byte` is defined as follows:
  1902. - If R is volatile, the result is target-dependent. (Volatile is
  1903. supposed to give guarantees which can support ``sig_atomic_t`` in
  1904. C/C++, and may be used for accesses to addresses that do not behave
  1905. like normal memory. It does not generally provide cross-thread
  1906. synchronization.)
  1907. - Otherwise, if there is no write to the same byte that happens before
  1908. R\ :sub:`byte`, R\ :sub:`byte` returns ``undef`` for that byte.
  1909. - Otherwise, if R\ :sub:`byte` may see exactly one write,
  1910. R\ :sub:`byte` returns the value written by that write.
  1911. - Otherwise, if R is atomic, and all the writes R\ :sub:`byte` may
  1912. see are atomic, it chooses one of the values written. See the :ref:`Atomic
  1913. Memory Ordering Constraints <ordering>` section for additional
  1914. constraints on how the choice is made.
  1915. - Otherwise R\ :sub:`byte` returns ``undef``.
  1916. R returns the value composed of the series of bytes it read. This
  1917. implies that some bytes within the value may be ``undef`` **without**
  1918. the entire value being ``undef``. Note that this only defines the
  1919. semantics of the operation; it doesn't mean that targets will emit more
  1920. than one instruction to read the series of bytes.
  1921. Note that in cases where none of the atomic intrinsics are used, this
  1922. model places only one restriction on IR transformations on top of what
  1923. is required for single-threaded execution: introducing a store to a byte
  1924. which might not otherwise be stored is not allowed in general.
  1925. (Specifically, in the case where another thread might write to and read
  1926. from an address, introducing a store can change a load that may see
  1927. exactly one write into a load that may see multiple writes.)
  1928. .. _ordering:
  1929. Atomic Memory Ordering Constraints
  1930. ----------------------------------
  1931. Atomic instructions (:ref:`cmpxchg <i_cmpxchg>`,
  1932. :ref:`atomicrmw <i_atomicrmw>`, :ref:`fence <i_fence>`,
  1933. :ref:`atomic load <i_load>`, and :ref:`atomic store <i_store>`) take
  1934. ordering parameters that determine which other atomic instructions on
  1935. the same address they *synchronize with*. These semantics are borrowed
  1936. from Java and C++0x, but are somewhat more colloquial. If these
  1937. descriptions aren't precise enough, check those specs (see spec
  1938. references in the :doc:`atomics guide <Atomics>`).
  1939. :ref:`fence <i_fence>` instructions treat these orderings somewhat
  1940. differently since they don't take an address. See that instruction's
  1941. documentation for details.
  1942. For a simpler introduction to the ordering constraints, see the
  1943. :doc:`Atomics`.
  1944. ``unordered``
  1945. The set of values that can be read is governed by the happens-before
  1946. partial order. A value cannot be read unless some operation wrote
  1947. it. This is intended to provide a guarantee strong enough to model
  1948. Java's non-volatile shared variables. This ordering cannot be
  1949. specified for read-modify-write operations; it is not strong enough
  1950. to make them atomic in any interesting way.
  1951. ``monotonic``
  1952. In addition to the guarantees of ``unordered``, there is a single
  1953. total order for modifications by ``monotonic`` operations on each
  1954. address. All modification orders must be compatible with the
  1955. happens-before order. There is no guarantee that the modification
  1956. orders can be combined to a global total order for the whole program
  1957. (and this often will not be possible). The read in an atomic
  1958. read-modify-write operation (:ref:`cmpxchg <i_cmpxchg>` and
  1959. :ref:`atomicrmw <i_atomicrmw>`) reads the value in the modification
  1960. order immediately before the value it writes. If one atomic read
  1961. happens before another atomic read of the same address, the later
  1962. read must see the same value or a later value in the address's
  1963. modification order. This disallows reordering of ``monotonic`` (or
  1964. stronger) operations on the same address. If an address is written
  1965. ``monotonic``-ally by one thread, and other threads ``monotonic``-ally
  1966. read that address repeatedly, the other threads must eventually see
  1967. the write. This corresponds to the C++0x/C1x
  1968. ``memory_order_relaxed``.
  1969. ``acquire``
  1970. In addition to the guarantees of ``monotonic``, a
  1971. *synchronizes-with* edge may be formed with a ``release`` operation.
  1972. This is intended to model C++'s ``memory_order_acquire``.
  1973. ``release``
  1974. In addition to the guarantees of ``monotonic``, if this operation
  1975. writes a value which is subsequently read by an ``acquire``
  1976. operation, it *synchronizes-with* that operation. (This isn't a
  1977. complete description; see the C++0x definition of a release
  1978. sequence.) This corresponds to the C++0x/C1x
  1979. ``memory_order_release``.
  1980. ``acq_rel`` (acquire+release)
  1981. Acts as both an ``acquire`` and ``release`` operation on its
  1982. address. This corresponds to the C++0x/C1x ``memory_order_acq_rel``.
  1983. ``seq_cst`` (sequentially consistent)
  1984. In addition to the guarantees of ``acq_rel`` (``acquire`` for an
  1985. operation that only reads, ``release`` for an operation that only
  1986. writes), there is a global total order on all
  1987. sequentially-consistent operations on all addresses, which is
  1988. consistent with the *happens-before* partial order and with the
  1989. modification orders of all the affected addresses. Each
  1990. sequentially-consistent read sees the last preceding write to the
  1991. same address in this global order. This corresponds to the C++0x/C1x
  1992. ``memory_order_seq_cst`` and Java volatile.
  1993. .. _syncscope:
  1994. If an atomic operation is marked ``syncscope("singlethread")``, it only
  1995. *synchronizes with* and only participates in the seq\_cst total orderings of
  1996. other operations running in the same thread (for example, in signal handlers).
  1997. If an atomic operation is marked ``syncscope("<target-scope>")``, where
  1998. ``<target-scope>`` is a target specific synchronization scope, then it is target
  1999. dependent if it *synchronizes with* and participates in the seq\_cst total
  2000. orderings of other operations.
  2001. Otherwise, an atomic operation that is not marked ``syncscope("singlethread")``
  2002. or ``syncscope("<target-scope>")`` *synchronizes with* and participates in the
  2003. seq\_cst total orderings of other operations that are not marked
  2004. ``syncscope("singlethread")`` or ``syncscope("<target-scope>")``.
  2005. .. _floatenv:
  2006. Floating-Point Environment
  2007. --------------------------
  2008. The default LLVM floating-point environment assumes that floating-point
  2009. instructions do not have side effects. Results assume the round-to-nearest
  2010. rounding mode. No floating-point exception state is maintained in this
  2011. environment. Therefore, there is no attempt to create or preserve invalid
  2012. operation (SNaN) or division-by-zero exceptions.
  2013. The benefit of this exception-free assumption is that floating-point
  2014. operations may be speculated freely without any other fast-math relaxations
  2015. to the floating-point model.
  2016. Code that requires different behavior than this should use the
  2017. :ref:`Constrained Floating-Point Intrinsics <constrainedfp>`.
  2018. .. _fastmath:
  2019. Fast-Math Flags
  2020. ---------------
  2021. LLVM IR floating-point operations (:ref:`fadd <i_fadd>`,
  2022. :ref:`fsub <i_fsub>`, :ref:`fmul <i_fmul>`, :ref:`fdiv <i_fdiv>`,
  2023. :ref:`frem <i_frem>`, :ref:`fcmp <i_fcmp>`) and :ref:`call <i_call>`
  2024. may use the following flags to enable otherwise unsafe
  2025. floating-point transformations.
  2026. ``nnan``
  2027. No NaNs - Allow optimizations to assume the arguments and result are not
  2028. NaN. If an argument is a nan, or the result would be a nan, it produces
  2029. a :ref:`poison value <poisonvalues>` instead.
  2030. ``ninf``
  2031. No Infs - Allow optimizations to assume the arguments and result are not
  2032. +/-Inf. If an argument is +/-Inf, or the result would be +/-Inf, it
  2033. produces a :ref:`poison value <poisonvalues>` instead.
  2034. ``nsz``
  2035. No Signed Zeros - Allow optimizations to treat the sign of a zero
  2036. argument or result as insignificant.
  2037. ``arcp``
  2038. Allow Reciprocal - Allow optimizations to use the reciprocal of an
  2039. argument rather than perform division.
  2040. ``contract``
  2041. Allow floating-point contraction (e.g. fusing a multiply followed by an
  2042. addition into a fused multiply-and-add).
  2043. ``afn``
  2044. Approximate functions - Allow substitution of approximate calculations for
  2045. functions (sin, log, sqrt, etc). See floating-point intrinsic definitions
  2046. for places where this can apply to LLVM's intrinsic math functions.
  2047. ``reassoc``
  2048. Allow reassociation transformations for floating-point instructions.
  2049. This may dramatically change results in floating-point.
  2050. ``fast``
  2051. This flag implies all of the others.
  2052. .. _uselistorder:
  2053. Use-list Order Directives
  2054. -------------------------
  2055. Use-list directives encode the in-memory order of each use-list, allowing the
  2056. order to be recreated. ``<order-indexes>`` is a comma-separated list of
  2057. indexes that are assigned to the referenced value's uses. The referenced
  2058. value's use-list is immediately sorted by these indexes.
  2059. Use-list directives may appear at function scope or global scope. They are not
  2060. instructions, and have no effect on the semantics of the IR. When they're at
  2061. function scope, they must appear after the terminator of the final basic block.
  2062. If basic blocks have their address taken via ``blockaddress()`` expressions,
  2063. ``uselistorder_bb`` can be used to reorder their use-lists from outside their
  2064. function's scope.
  2065. :Syntax:
  2066. ::
  2067. uselistorder <ty> <value>, { <order-indexes> }
  2068. uselistorder_bb @function, %block { <order-indexes> }
  2069. :Examples:
  2070. ::
  2071. define void @foo(i32 %arg1, i32 %arg2) {
  2072. entry:
  2073. ; ... instructions ...
  2074. bb:
  2075. ; ... instructions ...
  2076. ; At function scope.
  2077. uselistorder i32 %arg1, { 1, 0, 2 }
  2078. uselistorder label %bb, { 1, 0 }
  2079. }
  2080. ; At global scope.
  2081. uselistorder i32* @global, { 1, 2, 0 }
  2082. uselistorder i32 7, { 1, 0 }
  2083. uselistorder i32 (i32) @bar, { 1, 0 }
  2084. uselistorder_bb @foo, %bb, { 5, 1, 3, 2, 0, 4 }
  2085. .. _source_filename:
  2086. Source Filename
  2087. ---------------
  2088. The *source filename* string is set to the original module identifier,
  2089. which will be the name of the compiled source file when compiling from
  2090. source through the clang front end, for example. It is then preserved through
  2091. the IR and bitcode.
  2092. This is currently necessary to generate a consistent unique global
  2093. identifier for local functions used in profile data, which prepends the
  2094. source file name to the local function name.
  2095. The syntax for the source file name is simply:
  2096. .. code-block:: text
  2097. source_filename = "/path/to/source.c"
  2098. .. _typesystem:
  2099. Type System
  2100. ===========
  2101. The LLVM type system is one of the most important features of the
  2102. intermediate representation. Being typed enables a number of
  2103. optimizations to be performed on the intermediate representation
  2104. directly, without having to do extra analyses on the side before the
  2105. transformation. A strong type system makes it easier to read the
  2106. generated code and enables novel analyses and transformations that are
  2107. not feasible to perform on normal three address code representations.
  2108. .. _t_void:
  2109. Void Type
  2110. ---------
  2111. :Overview:
  2112. The void type does not represent any value and has no size.
  2113. :Syntax:
  2114. ::
  2115. void
  2116. .. _t_function:
  2117. Function Type
  2118. -------------
  2119. :Overview:
  2120. The function type can be thought of as a function signature. It consists of a
  2121. return type and a list of formal parameter types. The return type of a function
  2122. type is a void type or first class type --- except for :ref:`label <t_label>`
  2123. and :ref:`metadata <t_metadata>` types.
  2124. :Syntax:
  2125. ::
  2126. <returntype> (<parameter list>)
  2127. ...where '``<parameter list>``' is a comma-separated list of type
  2128. specifiers. Optionally, the parameter list may include a type ``...``, which
  2129. indicates that the function takes a variable number of arguments. Variable
  2130. argument functions can access their arguments with the :ref:`variable argument
  2131. handling intrinsic <int_varargs>` functions. '``<returntype>``' is any type
  2132. except :ref:`label <t_label>` and :ref:`metadata <t_metadata>`.
  2133. :Examples:
  2134. +---------------------------------+---------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  2135. | ``i32 (i32)`` | function taking an ``i32``, returning an ``i32`` |
  2136. +---------------------------------+---------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  2137. | ``float (i16, i32 *) *`` | :ref:`Pointer <t_pointer>` to a function that takes an ``i16`` and a :ref:`pointer <t_pointer>` to ``i32``, returning ``float``. |
  2138. +---------------------------------+---------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  2139. | ``i32 (i8*, ...)`` | A vararg function that takes at least one :ref:`pointer <t_pointer>` to ``i8`` (char in C), which returns an integer. This is the signature for ``printf`` in LLVM. |
  2140. +---------------------------------+---------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  2141. | ``{i32, i32} (i32)`` | A function taking an ``i32``, returning a :ref:`structure <t_struct>` containing two ``i32`` values |
  2142. +---------------------------------+---------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  2143. .. _t_firstclass:
  2144. First Class Types
  2145. -----------------
  2146. The :ref:`first class <t_firstclass>` types are perhaps the most important.
  2147. Values of these types are the only ones which can be produced by
  2148. instructions.
  2149. .. _t_single_value:
  2150. Single Value Types
  2151. ^^^^^^^^^^^^^^^^^^
  2152. These are the types that are valid in registers from CodeGen's perspective.
  2153. .. _t_integer:
  2154. Integer Type
  2155. """"""""""""
  2156. :Overview:
  2157. The integer type is a very simple type that simply specifies an
  2158. arbitrary bit width for the integer type desired. Any bit width from 1
  2159. bit to 2\ :sup:`23`\ -1 (about 8 million) can be specified.
  2160. :Syntax:
  2161. ::
  2162. iN
  2163. The number of bits the integer will occupy is specified by the ``N``
  2164. value.
  2165. Examples:
  2166. *********
  2167. +----------------+------------------------------------------------+
  2168. | ``i1`` | a single-bit integer. |
  2169. +----------------+------------------------------------------------+
  2170. | ``i32`` | a 32-bit integer. |
  2171. +----------------+------------------------------------------------+
  2172. | ``i1942652`` | a really big integer of over 1 million bits. |
  2173. +----------------+------------------------------------------------+
  2174. .. _t_floating:
  2175. Floating-Point Types
  2176. """"""""""""""""""""
  2177. .. list-table::
  2178. :header-rows: 1
  2179. * - Type
  2180. - Description
  2181. * - ``half``
  2182. - 16-bit floating-point value
  2183. * - ``float``
  2184. - 32-bit floating-point value
  2185. * - ``double``
  2186. - 64-bit floating-point value
  2187. * - ``fp128``
  2188. - 128-bit floating-point value (112-bit mantissa)
  2189. * - ``x86_fp80``
  2190. - 80-bit floating-point value (X87)
  2191. * - ``ppc_fp128``
  2192. - 128-bit floating-point value (two 64-bits)
  2193. The binary format of half, float, double, and fp128 correspond to the
  2194. IEEE-754-2008 specifications for binary16, binary32, binary64, and binary128
  2195. respectively.
  2196. X86_mmx Type
  2197. """"""""""""
  2198. :Overview:
  2199. The x86_mmx type represents a value held in an MMX register on an x86
  2200. machine. The operations allowed on it are quite limited: parameters and
  2201. return values, load and store, and bitcast. User-specified MMX
  2202. instructions are represented as intrinsic or asm calls with arguments
  2203. and/or results of this type. There are no arrays, vectors or constants
  2204. of this type.
  2205. :Syntax:
  2206. ::
  2207. x86_mmx
  2208. .. _t_pointer:
  2209. Pointer Type
  2210. """"""""""""
  2211. :Overview:
  2212. The pointer type is used to specify memory locations. Pointers are
  2213. commonly used to reference objects in memory.
  2214. Pointer types may have an optional address space attribute defining the
  2215. numbered address space where the pointed-to object resides. The default
  2216. address space is number zero. The semantics of non-zero address spaces
  2217. are target-specific.
  2218. Note that LLVM does not permit pointers to void (``void*``) nor does it
  2219. permit pointers to labels (``label*``). Use ``i8*`` instead.
  2220. :Syntax:
  2221. ::
  2222. <type> *
  2223. :Examples:
  2224. +-------------------------+--------------------------------------------------------------------------------------------------------------+
  2225. | ``[4 x i32]*`` | A :ref:`pointer <t_pointer>` to :ref:`array <t_array>` of four ``i32`` values. |
  2226. +-------------------------+--------------------------------------------------------------------------------------------------------------+
  2227. | ``i32 (i32*) *`` | A :ref:`pointer <t_pointer>` to a :ref:`function <t_function>` that takes an ``i32*``, returning an ``i32``. |
  2228. +-------------------------+--------------------------------------------------------------------------------------------------------------+
  2229. | ``i32 addrspace(5)*`` | A :ref:`pointer <t_pointer>` to an ``i32`` value that resides in address space #5. |
  2230. +-------------------------+--------------------------------------------------------------------------------------------------------------+
  2231. .. _t_vector:
  2232. Vector Type
  2233. """""""""""
  2234. :Overview:
  2235. A vector type is a simple derived type that represents a vector of
  2236. elements. Vector types are used when multiple primitive data are
  2237. operated in parallel using a single instruction (SIMD). A vector type
  2238. requires a size (number of elements), an underlying primitive data type,
  2239. and a scalable property to represent vectors where the exact hardware
  2240. vector length is unknown at compile time. Vector types are considered
  2241. :ref:`first class <t_firstclass>`.
  2242. :Syntax:
  2243. ::
  2244. < <# elements> x <elementtype> > ; Fixed-length vector
  2245. < vscale x <# elements> x <elementtype> > ; Scalable vector
  2246. The number of elements is a constant integer value larger than 0;
  2247. elementtype may be any integer, floating-point or pointer type. Vectors
  2248. of size zero are not allowed. For scalable vectors, the total number of
  2249. elements is a constant multiple (called vscale) of the specified number
  2250. of elements; vscale is a positive integer that is unknown at compile time
  2251. and the same hardware-dependent constant for all scalable vectors at run
  2252. time. The size of a specific scalable vector type is thus constant within
  2253. IR, even if the exact size in bytes cannot be determined until run time.
  2254. :Examples:
  2255. +------------------------+----------------------------------------------------+
  2256. | ``<4 x i32>`` | Vector of 4 32-bit integer values. |
  2257. +------------------------+----------------------------------------------------+
  2258. | ``<8 x float>`` | Vector of 8 32-bit floating-point values. |
  2259. +------------------------+----------------------------------------------------+
  2260. | ``<2 x i64>`` | Vector of 2 64-bit integer values. |
  2261. +------------------------+----------------------------------------------------+
  2262. | ``<4 x i64*>`` | Vector of 4 pointers to 64-bit integer values. |
  2263. +------------------------+----------------------------------------------------+
  2264. | ``<vscale x 4 x i32>`` | Vector with a multiple of 4 32-bit integer values. |
  2265. +------------------------+----------------------------------------------------+
  2266. .. _t_label:
  2267. Label Type
  2268. ^^^^^^^^^^
  2269. :Overview:
  2270. The label type represents code labels.
  2271. :Syntax:
  2272. ::
  2273. label
  2274. .. _t_token:
  2275. Token Type
  2276. ^^^^^^^^^^
  2277. :Overview:
  2278. The token type is used when a value is associated with an instruction
  2279. but all uses of the value must not attempt to introspect or obscure it.
  2280. As such, it is not appropriate to have a :ref:`phi <i_phi>` or
  2281. :ref:`select <i_select>` of type token.
  2282. :Syntax:
  2283. ::
  2284. token
  2285. .. _t_metadata:
  2286. Metadata Type
  2287. ^^^^^^^^^^^^^
  2288. :Overview:
  2289. The metadata type represents embedded metadata. No derived types may be
  2290. created from metadata except for :ref:`function <t_function>` arguments.
  2291. :Syntax:
  2292. ::
  2293. metadata
  2294. .. _t_aggregate:
  2295. Aggregate Types
  2296. ^^^^^^^^^^^^^^^
  2297. Aggregate Types are a subset of derived types that can contain multiple
  2298. member types. :ref:`Arrays <t_array>` and :ref:`structs <t_struct>` are
  2299. aggregate types. :ref:`Vectors <t_vector>` are not considered to be
  2300. aggregate types.
  2301. .. _t_array:
  2302. Array Type
  2303. """"""""""
  2304. :Overview:
  2305. The array type is a very simple derived type that arranges elements
  2306. sequentially in memory. The array type requires a size (number of
  2307. elements) and an underlying data type.
  2308. :Syntax:
  2309. ::
  2310. [<# elements> x <elementtype>]
  2311. The number of elements is a constant integer value; ``elementtype`` may
  2312. be any type with a size.
  2313. :Examples:
  2314. +------------------+--------------------------------------+
  2315. | ``[40 x i32]`` | Array of 40 32-bit integer values. |
  2316. +------------------+--------------------------------------+
  2317. | ``[41 x i32]`` | Array of 41 32-bit integer values. |
  2318. +------------------+--------------------------------------+
  2319. | ``[4 x i8]`` | Array of 4 8-bit integer values. |
  2320. +------------------+--------------------------------------+
  2321. Here are some examples of multidimensional arrays:
  2322. +-----------------------------+----------------------------------------------------------+
  2323. | ``[3 x [4 x i32]]`` | 3x4 array of 32-bit integer values. |
  2324. +-----------------------------+----------------------------------------------------------+
  2325. | ``[12 x [10 x float]]`` | 12x10 array of single precision floating-point values. |
  2326. +-----------------------------+----------------------------------------------------------+
  2327. | ``[2 x [3 x [4 x i16]]]`` | 2x3x4 array of 16-bit integer values. |
  2328. +-----------------------------+----------------------------------------------------------+
  2329. There is no restriction on indexing beyond the end of the array implied
  2330. by a static type (though there are restrictions on indexing beyond the
  2331. bounds of an allocated object in some cases). This means that
  2332. single-dimension 'variable sized array' addressing can be implemented in
  2333. LLVM with a zero length array type. An implementation of 'pascal style
  2334. arrays' in LLVM could use the type "``{ i32, [0 x float]}``", for
  2335. example.
  2336. .. _t_struct:
  2337. Structure Type
  2338. """"""""""""""
  2339. :Overview:
  2340. The structure type is used to represent a collection of data members
  2341. together in memory. The elements of a structure may be any type that has
  2342. a size.
  2343. Structures in memory are accessed using '``load``' and '``store``' by
  2344. getting a pointer to a field with the '``getelementptr``' instruction.
  2345. Structures in registers are accessed using the '``extractvalue``' and
  2346. '``insertvalue``' instructions.
  2347. Structures may optionally be "packed" structures, which indicate that
  2348. the alignment of the struct is one byte, and that there is no padding
  2349. between the elements. In non-packed structs, padding between field types
  2350. is inserted as defined by the DataLayout string in the module, which is
  2351. required to match what the underlying code generator expects.
  2352. Structures can either be "literal" or "identified". A literal structure
  2353. is defined inline with other types (e.g. ``{i32, i32}*``) whereas
  2354. identified types are always defined at the top level with a name.
  2355. Literal types are uniqued by their contents and can never be recursive
  2356. or opaque since there is no way to write one. Identified types can be
  2357. recursive, can be opaqued, and are never uniqued.
  2358. :Syntax:
  2359. ::
  2360. %T1 = type { <type list> } ; Identified normal struct type
  2361. %T2 = type <{ <type list> }> ; Identified packed struct type
  2362. :Examples:
  2363. +------------------------------+---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  2364. | ``{ i32, i32, i32 }`` | A triple of three ``i32`` values |
  2365. +------------------------------+---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  2366. | ``{ float, i32 (i32) * }`` | A pair, where the first element is a ``float`` and the second element is a :ref:`pointer <t_pointer>` to a :ref:`function <t_function>` that takes an ``i32``, returning an ``i32``. |
  2367. +------------------------------+---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  2368. | ``<{ i8, i32 }>`` | A packed struct known to be 5 bytes in size. |
  2369. +------------------------------+---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  2370. .. _t_opaque:
  2371. Opaque Structure Types
  2372. """"""""""""""""""""""
  2373. :Overview:
  2374. Opaque structure types are used to represent named structure types that
  2375. do not have a body specified. This corresponds (for example) to the C
  2376. notion of a forward declared structure.
  2377. :Syntax:
  2378. ::
  2379. %X = type opaque
  2380. %52 = type opaque
  2381. :Examples:
  2382. +--------------+-------------------+
  2383. | ``opaque`` | An opaque type. |
  2384. +--------------+-------------------+
  2385. .. _constants:
  2386. Constants
  2387. =========
  2388. LLVM has several different basic types of constants. This section
  2389. describes them all and their syntax.
  2390. Simple Constants
  2391. ----------------
  2392. **Boolean constants**
  2393. The two strings '``true``' and '``false``' are both valid constants
  2394. of the ``i1`` type.
  2395. **Integer constants**
  2396. Standard integers (such as '4') are constants of the
  2397. :ref:`integer <t_integer>` type. Negative numbers may be used with
  2398. integer types.
  2399. **Floating-point constants**
  2400. Floating-point constants use standard decimal notation (e.g.
  2401. 123.421), exponential notation (e.g. 1.23421e+2), or a more precise
  2402. hexadecimal notation (see below). The assembler requires the exact
  2403. decimal value of a floating-point constant. For example, the
  2404. assembler accepts 1.25 but rejects 1.3 because 1.3 is a repeating
  2405. decimal in binary. Floating-point constants must have a
  2406. :ref:`floating-point <t_floating>` type.
  2407. **Null pointer constants**
  2408. The identifier '``null``' is recognized as a null pointer constant
  2409. and must be of :ref:`pointer type <t_pointer>`.
  2410. **Token constants**
  2411. The identifier '``none``' is recognized as an empty token constant
  2412. and must be of :ref:`token type <t_token>`.
  2413. The one non-intuitive notation for constants is the hexadecimal form of
  2414. floating-point constants. For example, the form
  2415. '``double 0x432ff973cafa8000``' is equivalent to (but harder to read
  2416. than) '``double 4.5e+15``'. The only time hexadecimal floating-point
  2417. constants are required (and the only time that they are generated by the
  2418. disassembler) is when a floating-point constant must be emitted but it
  2419. cannot be represented as a decimal floating-point number in a reasonable
  2420. number of digits. For example, NaN's, infinities, and other special
  2421. values are represented in their IEEE hexadecimal format so that assembly
  2422. and disassembly do not cause any bits to change in the constants.
  2423. When using the hexadecimal form, constants of types half, float, and
  2424. double are represented using the 16-digit form shown above (which
  2425. matches the IEEE754 representation for double); half and float values
  2426. must, however, be exactly representable as IEEE 754 half and single
  2427. precision, respectively. Hexadecimal format is always used for long
  2428. double, and there are three forms of long double. The 80-bit format used
  2429. by x86 is represented as ``0xK`` followed by 20 hexadecimal digits. The
  2430. 128-bit format used by PowerPC (two adjacent doubles) is represented by
  2431. ``0xM`` followed by 32 hexadecimal digits. The IEEE 128-bit format is
  2432. represented by ``0xL`` followed by 32 hexadecimal digits. Long doubles
  2433. will only work if they match the long double format on your target.
  2434. The IEEE 16-bit format (half precision) is represented by ``0xH``
  2435. followed by 4 hexadecimal digits. All hexadecimal formats are big-endian
  2436. (sign bit at the left).
  2437. There are no constants of type x86_mmx.
  2438. .. _complexconstants:
  2439. Complex Constants
  2440. -----------------
  2441. Complex constants are a (potentially recursive) combination of simple
  2442. constants and smaller complex constants.
  2443. **Structure constants**
  2444. Structure constants are represented with notation similar to
  2445. structure type definitions (a comma separated list of elements,
  2446. surrounded by braces (``{}``)). For example:
  2447. "``{ i32 4, float 17.0, i32* @G }``", where "``@G``" is declared as
  2448. "``@G = external global i32``". Structure constants must have
  2449. :ref:`structure type <t_struct>`, and the number and types of elements
  2450. must match those specified by the type.
  2451. **Array constants**
  2452. Array constants are represented with notation similar to array type
  2453. definitions (a comma separated list of elements, surrounded by
  2454. square brackets (``[]``)). For example:
  2455. "``[ i32 42, i32 11, i32 74 ]``". Array constants must have
  2456. :ref:`array type <t_array>`, and the number and types of elements must
  2457. match those specified by the type. As a special case, character array
  2458. constants may also be represented as a double-quoted string using the ``c``
  2459. prefix. For example: "``c"Hello World\0A\00"``".
  2460. **Vector constants**
  2461. Vector constants are represented with notation similar to vector
  2462. type definitions (a comma separated list of elements, surrounded by
  2463. less-than/greater-than's (``<>``)). For example:
  2464. "``< i32 42, i32 11, i32 74, i32 100 >``". Vector constants
  2465. must have :ref:`vector type <t_vector>`, and the number and types of
  2466. elements must match those specified by the type.
  2467. **Zero initialization**
  2468. The string '``zeroinitializer``' can be used to zero initialize a
  2469. value to zero of *any* type, including scalar and
  2470. :ref:`aggregate <t_aggregate>` types. This is often used to avoid
  2471. having to print large zero initializers (e.g. for large arrays) and
  2472. is always exactly equivalent to using explicit zero initializers.
  2473. **Metadata node**
  2474. A metadata node is a constant tuple without types. For example:
  2475. "``!{!0, !{!2, !0}, !"test"}``". Metadata can reference constant values,
  2476. for example: "``!{!0, i32 0, i8* @global, i64 (i64)* @function, !"str"}``".
  2477. Unlike other typed constants that are meant to be interpreted as part of
  2478. the instruction stream, metadata is a place to attach additional
  2479. information such as debug info.
  2480. Global Variable and Function Addresses
  2481. --------------------------------------
  2482. The addresses of :ref:`global variables <globalvars>` and
  2483. :ref:`functions <functionstructure>` are always implicitly valid
  2484. (link-time) constants. These constants are explicitly referenced when
  2485. the :ref:`identifier for the global <identifiers>` is used and always have
  2486. :ref:`pointer <t_pointer>` type. For example, the following is a legal LLVM
  2487. file:
  2488. .. code-block:: llvm
  2489. @X = global i32 17
  2490. @Y = global i32 42
  2491. @Z = global [2 x i32*] [ i32* @X, i32* @Y ]
  2492. .. _undefvalues:
  2493. Undefined Values
  2494. ----------------
  2495. The string '``undef``' can be used anywhere a constant is expected, and
  2496. indicates that the user of the value may receive an unspecified
  2497. bit-pattern. Undefined values may be of any type (other than '``label``'
  2498. or '``void``') and be used anywhere a constant is permitted.
  2499. Undefined values are useful because they indicate to the compiler that
  2500. the program is well defined no matter what value is used. This gives the
  2501. compiler more freedom to optimize. Here are some examples of
  2502. (potentially surprising) transformations that are valid (in pseudo IR):
  2503. .. code-block:: llvm
  2504. %A = add %X, undef
  2505. %B = sub %X, undef
  2506. %C = xor %X, undef
  2507. Safe:
  2508. %A = undef
  2509. %B = undef
  2510. %C = undef
  2511. This is safe because all of the output bits are affected by the undef
  2512. bits. Any output bit can have a zero or one depending on the input bits.
  2513. .. code-block:: llvm
  2514. %A = or %X, undef
  2515. %B = and %X, undef
  2516. Safe:
  2517. %A = -1
  2518. %B = 0
  2519. Safe:
  2520. %A = %X ;; By choosing undef as 0
  2521. %B = %X ;; By choosing undef as -1
  2522. Unsafe:
  2523. %A = undef
  2524. %B = undef
  2525. These logical operations have bits that are not always affected by the
  2526. input. For example, if ``%X`` has a zero bit, then the output of the
  2527. '``and``' operation will always be a zero for that bit, no matter what
  2528. the corresponding bit from the '``undef``' is. As such, it is unsafe to
  2529. optimize or assume that the result of the '``and``' is '``undef``'.
  2530. However, it is safe to assume that all bits of the '``undef``' could be
  2531. 0, and optimize the '``and``' to 0. Likewise, it is safe to assume that
  2532. all the bits of the '``undef``' operand to the '``or``' could be set,
  2533. allowing the '``or``' to be folded to -1.
  2534. .. code-block:: llvm
  2535. %A = select undef, %X, %Y
  2536. %B = select undef, 42, %Y
  2537. %C = select %X, %Y, undef
  2538. Safe:
  2539. %A = %X (or %Y)
  2540. %B = 42 (or %Y)
  2541. %C = %Y
  2542. Unsafe:
  2543. %A = undef
  2544. %B = undef
  2545. %C = undef
  2546. This set of examples shows that undefined '``select``' (and conditional
  2547. branch) conditions can go *either way*, but they have to come from one
  2548. of the two operands. In the ``%A`` example, if ``%X`` and ``%Y`` were
  2549. both known to have a clear low bit, then ``%A`` would have to have a
  2550. cleared low bit. However, in the ``%C`` example, the optimizer is
  2551. allowed to assume that the '``undef``' operand could be the same as
  2552. ``%Y``, allowing the whole '``select``' to be eliminated.
  2553. .. code-block:: text
  2554. %A = xor undef, undef
  2555. %B = undef
  2556. %C = xor %B, %B
  2557. %D = undef
  2558. %E = icmp slt %D, 4
  2559. %F = icmp gte %D, 4
  2560. Safe:
  2561. %A = undef
  2562. %B = undef
  2563. %C = undef
  2564. %D = undef
  2565. %E = undef
  2566. %F = undef
  2567. This example points out that two '``undef``' operands are not
  2568. necessarily the same. This can be surprising to people (and also matches
  2569. C semantics) where they assume that "``X^X``" is always zero, even if
  2570. ``X`` is undefined. This isn't true for a number of reasons, but the
  2571. short answer is that an '``undef``' "variable" can arbitrarily change
  2572. its value over its "live range". This is true because the variable
  2573. doesn't actually *have a live range*. Instead, the value is logically
  2574. read from arbitrary registers that happen to be around when needed, so
  2575. the value is not necessarily consistent over time. In fact, ``%A`` and
  2576. ``%C`` need to have the same semantics or the core LLVM "replace all
  2577. uses with" concept would not hold.
  2578. .. code-block:: llvm
  2579. %A = sdiv undef, %X
  2580. %B = sdiv %X, undef
  2581. Safe:
  2582. %A = 0
  2583. b: unreachable
  2584. These examples show the crucial difference between an *undefined value*
  2585. and *undefined behavior*. An undefined value (like '``undef``') is
  2586. allowed to have an arbitrary bit-pattern. This means that the ``%A``
  2587. operation can be constant folded to '``0``', because the '``undef``'
  2588. could be zero, and zero divided by any value is zero.
  2589. However, in the second example, we can make a more aggressive
  2590. assumption: because the ``undef`` is allowed to be an arbitrary value,
  2591. we are allowed to assume that it could be zero. Since a divide by zero
  2592. has *undefined behavior*, we are allowed to assume that the operation
  2593. does not execute at all. This allows us to delete the divide and all
  2594. code after it. Because the undefined operation "can't happen", the
  2595. optimizer can assume that it occurs in dead code.
  2596. .. code-block:: text
  2597. a: store undef -> %X
  2598. b: store %X -> undef
  2599. Safe:
  2600. a: <deleted>
  2601. b: unreachable
  2602. A store *of* an undefined value can be assumed to not have any effect;
  2603. we can assume that the value is overwritten with bits that happen to
  2604. match what was already there. However, a store *to* an undefined
  2605. location could clobber arbitrary memory, therefore, it has undefined
  2606. behavior.
  2607. **MemorySanitizer**, a detector of uses of uninitialized memory,
  2608. defines a branch with condition that depends on an undef value (or
  2609. certain other values, like e.g. a result of a load from heap-allocated
  2610. memory that has never been stored to) to have an externally visible
  2611. side effect. For this reason functions with *sanitize_memory*
  2612. attribute are not allowed to produce such branches "out of thin
  2613. air". More strictly, an optimization that inserts a conditional branch
  2614. is only valid if in all executions where the branch condition has at
  2615. least one undefined bit, the same branch condition is evaluated in the
  2616. input IR as well.
  2617. .. _poisonvalues:
  2618. Poison Values
  2619. -------------
  2620. In order to facilitate speculative execution, many instructions do not
  2621. invoke immediate undefined behavior when provided with illegal operands,
  2622. and return a poison value instead.
  2623. There is currently no way of representing a poison value in the IR; they
  2624. only exist when produced by operations such as :ref:`add <i_add>` with
  2625. the ``nsw`` flag.
  2626. Poison value behavior is defined in terms of value *dependence*:
  2627. - Values other than :ref:`phi <i_phi>` nodes depend on their operands.
  2628. - :ref:`Phi <i_phi>` nodes depend on the operand corresponding to
  2629. their dynamic predecessor basic block.
  2630. - Function arguments depend on the corresponding actual argument values
  2631. in the dynamic callers of their functions.
  2632. - :ref:`Call <i_call>` instructions depend on the :ref:`ret <i_ret>`
  2633. instructions that dynamically transfer control back to them.
  2634. - :ref:`Invoke <i_invoke>` instructions depend on the
  2635. :ref:`ret <i_ret>`, :ref:`resume <i_resume>`, or exception-throwing
  2636. call instructions that dynamically transfer control back to them.
  2637. - Non-volatile loads and stores depend on the most recent stores to all
  2638. of the referenced memory addresses, following the order in the IR
  2639. (including loads and stores implied by intrinsics such as
  2640. :ref:`@llvm.memcpy <int_memcpy>`.)
  2641. - An instruction with externally visible side effects depends on the
  2642. most recent preceding instruction with externally visible side
  2643. effects, following the order in the IR. (This includes :ref:`volatile
  2644. operations <volatile>`.)
  2645. - An instruction *control-depends* on a :ref:`terminator
  2646. instruction <terminators>` if the terminator instruction has
  2647. multiple successors and the instruction is always executed when
  2648. control transfers to one of the successors, and may not be executed
  2649. when control is transferred to another.
  2650. - Additionally, an instruction also *control-depends* on a terminator
  2651. instruction if the set of instructions it otherwise depends on would
  2652. be different if the terminator had transferred control to a different
  2653. successor.
  2654. - Dependence is transitive.
  2655. An instruction that *depends* on a poison value, produces a poison value
  2656. itself. A poison value may be relaxed into an
  2657. :ref:`undef value <undefvalues>`, which takes an arbitrary bit-pattern.
  2658. This means that immediate undefined behavior occurs if a poison value is
  2659. used as an instruction operand that has any values that trigger undefined
  2660. behavior. Notably this includes (but is not limited to):
  2661. - The pointer operand of a :ref:`load <i_load>`, :ref:`store <i_store>` or
  2662. any other pointer dereferencing instruction (independent of address
  2663. space).
  2664. - The divisor operand of a ``udiv``, ``sdiv``, ``urem`` or ``srem``
  2665. instruction.
  2666. Additionally, undefined behavior occurs if a side effect *depends* on poison.
  2667. This includes side effects that are control dependent on a poisoned branch.
  2668. Here are some examples:
  2669. .. code-block:: llvm
  2670. entry:
  2671. %poison = sub nuw i32 0, 1 ; Results in a poison value.
  2672. %still_poison = and i32 %poison, 0 ; 0, but also poison.
  2673. %poison_yet_again = getelementptr i32, i32* @h, i32 %still_poison
  2674. store i32 0, i32* %poison_yet_again ; Undefined behavior due to
  2675. ; store to poison.
  2676. store i32 %poison, i32* @g ; Poison value stored to memory.
  2677. %poison2 = load i32, i32* @g ; Poison value loaded back from memory.
  2678. %narrowaddr = bitcast i32* @g to i16*
  2679. %wideaddr = bitcast i32* @g to i64*
  2680. %poison3 = load i16, i16* %narrowaddr ; Returns a poison value.
  2681. %poison4 = load i64, i64* %wideaddr ; Returns a poison value.
  2682. %cmp = icmp slt i32 %poison, 0 ; Returns a poison value.
  2683. br i1 %cmp, label %true, label %end ; Branch to either destination.
  2684. true:
  2685. store volatile i32 0, i32* @g ; This is control-dependent on %cmp, so
  2686. ; it has undefined behavior.
  2687. br label %end
  2688. end:
  2689. %p = phi i32 [ 0, %entry ], [ 1, %true ]
  2690. ; Both edges into this PHI are
  2691. ; control-dependent on %cmp, so this
  2692. ; always results in a poison value.
  2693. store volatile i32 0, i32* @g ; This would depend on the store in %true
  2694. ; if %cmp is true, or the store in %entry
  2695. ; otherwise, so this is undefined behavior.
  2696. br i1 %cmp, label %second_true, label %second_end
  2697. ; The same branch again, but this time the
  2698. ; true block doesn't have side effects.
  2699. second_true:
  2700. ; No side effects!
  2701. ret void
  2702. second_end:
  2703. store volatile i32 0, i32* @g ; This time, the instruction always depends
  2704. ; on the store in %end. Also, it is
  2705. ; control-equivalent to %end, so this is
  2706. ; well-defined (ignoring earlier undefined
  2707. ; behavior in this example).
  2708. .. _blockaddress:
  2709. Addresses of Basic Blocks
  2710. -------------------------
  2711. ``blockaddress(@function, %block)``
  2712. The '``blockaddress``' constant computes the address of the specified
  2713. basic block in the specified function, and always has an ``i8*`` type.
  2714. Taking the address of the entry block is illegal.
  2715. This value only has defined behavior when used as an operand to the
  2716. ':ref:`indirectbr <i_indirectbr>`' or ':ref:`callbr <i_callbr>`'instruction, or
  2717. for comparisons against null. Pointer equality tests between labels addresses
  2718. results in undefined behavior --- though, again, comparison against null is ok,
  2719. and no label is equal to the null pointer. This may be passed around as an
  2720. opaque pointer sized value as long as the bits are not inspected. This
  2721. allows ``ptrtoint`` and arithmetic to be performed on these values so
  2722. long as the original value is reconstituted before the ``indirectbr`` or
  2723. ``callbr`` instruction.
  2724. Finally, some targets may provide defined semantics when using the value
  2725. as the operand to an inline assembly, but that is target specific.
  2726. .. _constantexprs:
  2727. Constant Expressions
  2728. --------------------
  2729. Constant expressions are used to allow expressions involving other
  2730. constants to be used as constants. Constant expressions may be of any
  2731. :ref:`first class <t_firstclass>` type and may involve any LLVM operation
  2732. that does not have side effects (e.g. load and call are not supported).
  2733. The following is the syntax for constant expressions:
  2734. ``trunc (CST to TYPE)``
  2735. Perform the :ref:`trunc operation <i_trunc>` on constants.
  2736. ``zext (CST to TYPE)``
  2737. Perform the :ref:`zext operation <i_zext>` on constants.
  2738. ``sext (CST to TYPE)``
  2739. Perform the :ref:`sext operation <i_sext>` on constants.
  2740. ``fptrunc (CST to TYPE)``
  2741. Truncate a floating-point constant to another floating-point type.
  2742. The size of CST must be larger than the size of TYPE. Both types
  2743. must be floating-point.
  2744. ``fpext (CST to TYPE)``
  2745. Floating-point extend a constant to another type. The size of CST
  2746. must be smaller or equal to the size of TYPE. Both types must be
  2747. floating-point.
  2748. ``fptoui (CST to TYPE)``
  2749. Convert a floating-point constant to the corresponding unsigned
  2750. integer constant. TYPE must be a scalar or vector integer type. CST
  2751. must be of scalar or vector floating-point type. Both CST and TYPE
  2752. must be scalars, or vectors of the same number of elements. If the
  2753. value won't fit in the integer type, the result is a
  2754. :ref:`poison value <poisonvalues>`.
  2755. ``fptosi (CST to TYPE)``
  2756. Convert a floating-point constant to the corresponding signed
  2757. integer constant. TYPE must be a scalar or vector integer type. CST
  2758. must be of scalar or vector floating-point type. Both CST and TYPE
  2759. must be scalars, or vectors of the same number of elements. If the
  2760. value won't fit in the integer type, the result is a
  2761. :ref:`poison value <poisonvalues>`.
  2762. ``uitofp (CST to TYPE)``
  2763. Convert an unsigned integer constant to the corresponding
  2764. floating-point constant. TYPE must be a scalar or vector floating-point
  2765. type. CST must be of scalar or vector integer type. Both CST and TYPE must
  2766. be scalars, or vectors of the same number of elements.
  2767. ``sitofp (CST to TYPE)``
  2768. Convert a signed integer constant to the corresponding floating-point
  2769. constant. TYPE must be a scalar or vector floating-point type.
  2770. CST must be of scalar or vector integer type. Both CST and TYPE must
  2771. be scalars, or vectors of the same number of elements.
  2772. ``ptrtoint (CST to TYPE)``
  2773. Perform the :ref:`ptrtoint operation <i_ptrtoint>` on constants.
  2774. ``inttoptr (CST to TYPE)``
  2775. Perform the :ref:`inttoptr operation <i_inttoptr>` on constants.
  2776. This one is *really* dangerous!
  2777. ``bitcast (CST to TYPE)``
  2778. Convert a constant, CST, to another TYPE.
  2779. The constraints of the operands are the same as those for the
  2780. :ref:`bitcast instruction <i_bitcast>`.
  2781. ``addrspacecast (CST to TYPE)``
  2782. Convert a constant pointer or constant vector of pointer, CST, to another
  2783. TYPE in a different address space. The constraints of the operands are the
  2784. same as those for the :ref:`addrspacecast instruction <i_addrspacecast>`.
  2785. ``getelementptr (TY, CSTPTR, IDX0, IDX1, ...)``, ``getelementptr inbounds (TY, CSTPTR, IDX0, IDX1, ...)``
  2786. Perform the :ref:`getelementptr operation <i_getelementptr>` on
  2787. constants. As with the :ref:`getelementptr <i_getelementptr>`
  2788. instruction, the index list may have one or more indexes, which are
  2789. required to make sense for the type of "pointer to TY".
  2790. ``select (COND, VAL1, VAL2)``
  2791. Perform the :ref:`select operation <i_select>` on constants.
  2792. ``icmp COND (VAL1, VAL2)``
  2793. Perform the :ref:`icmp operation <i_icmp>` on constants.
  2794. ``fcmp COND (VAL1, VAL2)``
  2795. Perform the :ref:`fcmp operation <i_fcmp>` on constants.
  2796. ``extractelement (VAL, IDX)``
  2797. Perform the :ref:`extractelement operation <i_extractelement>` on
  2798. constants.
  2799. ``insertelement (VAL, ELT, IDX)``
  2800. Perform the :ref:`insertelement operation <i_insertelement>` on
  2801. constants.
  2802. ``shufflevector (VEC1, VEC2, IDXMASK)``
  2803. Perform the :ref:`shufflevector operation <i_shufflevector>` on
  2804. constants.
  2805. ``extractvalue (VAL, IDX0, IDX1, ...)``
  2806. Perform the :ref:`extractvalue operation <i_extractvalue>` on
  2807. constants. The index list is interpreted in a similar manner as
  2808. indices in a ':ref:`getelementptr <i_getelementptr>`' operation. At
  2809. least one index value must be specified.
  2810. ``insertvalue (VAL, ELT, IDX0, IDX1, ...)``
  2811. Perform the :ref:`insertvalue operation <i_insertvalue>` on constants.
  2812. The index list is interpreted in a similar manner as indices in a
  2813. ':ref:`getelementptr <i_getelementptr>`' operation. At least one index
  2814. value must be specified.
  2815. ``OPCODE (LHS, RHS)``
  2816. Perform the specified operation of the LHS and RHS constants. OPCODE
  2817. may be any of the :ref:`binary <binaryops>` or :ref:`bitwise
  2818. binary <bitwiseops>` operations. The constraints on operands are
  2819. the same as those for the corresponding instruction (e.g. no bitwise
  2820. operations on floating-point values are allowed).
  2821. Other Values
  2822. ============
  2823. .. _inlineasmexprs:
  2824. Inline Assembler Expressions
  2825. ----------------------------
  2826. LLVM supports inline assembler expressions (as opposed to :ref:`Module-Level
  2827. Inline Assembly <moduleasm>`) through the use of a special value. This value
  2828. represents the inline assembler as a template string (containing the
  2829. instructions to emit), a list of operand constraints (stored as a string), a
  2830. flag that indicates whether or not the inline asm expression has side effects,
  2831. and a flag indicating whether the function containing the asm needs to align its
  2832. stack conservatively.
  2833. The template string supports argument substitution of the operands using "``$``"
  2834. followed by a number, to indicate substitution of the given register/memory
  2835. location, as specified by the constraint string. "``${NUM:MODIFIER}``" may also
  2836. be used, where ``MODIFIER`` is a target-specific annotation for how to print the
  2837. operand (See :ref:`inline-asm-modifiers`).
  2838. A literal "``$``" may be included by using "``$$``" in the template. To include
  2839. other special characters into the output, the usual "``\XX``" escapes may be
  2840. used, just as in other strings. Note that after template substitution, the
  2841. resulting assembly string is parsed by LLVM's integrated assembler unless it is
  2842. disabled -- even when emitting a ``.s`` file -- and thus must contain assembly
  2843. syntax known to LLVM.
  2844. LLVM also supports a few more substitutions useful for writing inline assembly:
  2845. - ``${:uid}``: Expands to a decimal integer unique to this inline assembly blob.
  2846. This substitution is useful when declaring a local label. Many standard
  2847. compiler optimizations, such as inlining, may duplicate an inline asm blob.
  2848. Adding a blob-unique identifier ensures that the two labels will not conflict
  2849. during assembly. This is used to implement `GCC's %= special format
  2850. string <https://gcc.gnu.org/onlinedocs/gcc/Extended-Asm.html>`_.
  2851. - ``${:comment}``: Expands to the comment character of the current target's
  2852. assembly dialect. This is usually ``#``, but many targets use other strings,
  2853. such as ``;``, ``//``, or ``!``.
  2854. - ``${:private}``: Expands to the assembler private label prefix. Labels with
  2855. this prefix will not appear in the symbol table of the assembled object.
  2856. Typically the prefix is ``L``, but targets may use other strings. ``.L`` is
  2857. relatively popular.
  2858. LLVM's support for inline asm is modeled closely on the requirements of Clang's
  2859. GCC-compatible inline-asm support. Thus, the feature-set and the constraint and
  2860. modifier codes listed here are similar or identical to those in GCC's inline asm
  2861. support. However, to be clear, the syntax of the template and constraint strings
  2862. described here is *not* the same as the syntax accepted by GCC and Clang, and,
  2863. while most constraint letters are passed through as-is by Clang, some get
  2864. translated to other codes when converting from the C source to the LLVM
  2865. assembly.
  2866. An example inline assembler expression is:
  2867. .. code-block:: llvm
  2868. i32 (i32) asm "bswap $0", "=r,r"
  2869. Inline assembler expressions may **only** be used as the callee operand
  2870. of a :ref:`call <i_call>` or an :ref:`invoke <i_invoke>` instruction.
  2871. Thus, typically we have:
  2872. .. code-block:: llvm
  2873. %X = call i32 asm "bswap $0", "=r,r"(i32 %Y)
  2874. Inline asms with side effects not visible in the constraint list must be
  2875. marked as having side effects. This is done through the use of the
  2876. '``sideeffect``' keyword, like so:
  2877. .. code-block:: llvm
  2878. call void asm sideeffect "eieio", ""()
  2879. In some cases inline asms will contain code that will not work unless
  2880. the stack is aligned in some way, such as calls or SSE instructions on
  2881. x86, yet will not contain code that does that alignment within the asm.
  2882. The compiler should make conservative assumptions about what the asm
  2883. might contain and should generate its usual stack alignment code in the
  2884. prologue if the '``alignstack``' keyword is present:
  2885. .. code-block:: llvm
  2886. call void asm alignstack "eieio", ""()
  2887. Inline asms also support using non-standard assembly dialects. The
  2888. assumed dialect is ATT. When the '``inteldialect``' keyword is present,
  2889. the inline asm is using the Intel dialect. Currently, ATT and Intel are
  2890. the only supported dialects. An example is:
  2891. .. code-block:: llvm
  2892. call void asm inteldialect "eieio", ""()
  2893. If multiple keywords appear the '``sideeffect``' keyword must come
  2894. first, the '``alignstack``' keyword second and the '``inteldialect``'
  2895. keyword last.
  2896. Inline Asm Constraint String
  2897. ^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  2898. The constraint list is a comma-separated string, each element containing one or
  2899. more constraint codes.
  2900. For each element in the constraint list an appropriate register or memory
  2901. operand will be chosen, and it will be made available to assembly template
  2902. string expansion as ``$0`` for the first constraint in the list, ``$1`` for the
  2903. second, etc.
  2904. There are three different types of constraints, which are distinguished by a
  2905. prefix symbol in front of the constraint code: Output, Input, and Clobber. The
  2906. constraints must always be given in that order: outputs first, then inputs, then
  2907. clobbers. They cannot be intermingled.
  2908. There are also three different categories of constraint codes:
  2909. - Register constraint. This is either a register class, or a fixed physical
  2910. register. This kind of constraint will allocate a register, and if necessary,
  2911. bitcast the argument or result to the appropriate type.
  2912. - Memory constraint. This kind of constraint is for use with an instruction
  2913. taking a memory operand. Different constraints allow for different addressing
  2914. modes used by the target.
  2915. - Immediate value constraint. This kind of constraint is for an integer or other
  2916. immediate value which can be rendered directly into an instruction. The
  2917. various target-specific constraints allow the selection of a value in the
  2918. proper range for the instruction you wish to use it with.
  2919. Output constraints
  2920. """"""""""""""""""
  2921. Output constraints are specified by an "``=``" prefix (e.g. "``=r``"). This
  2922. indicates that the assembly will write to this operand, and the operand will
  2923. then be made available as a return value of the ``asm`` expression. Output
  2924. constraints do not consume an argument from the call instruction. (Except, see
  2925. below about indirect outputs).
  2926. Normally, it is expected that no output locations are written to by the assembly
  2927. expression until *all* of the inputs have been read. As such, LLVM may assign
  2928. the same register to an output and an input. If this is not safe (e.g. if the
  2929. assembly contains two instructions, where the first writes to one output, and
  2930. the second reads an input and writes to a second output), then the "``&``"
  2931. modifier must be used (e.g. "``=&r``") to specify that the output is an
  2932. "early-clobber" output. Marking an output as "early-clobber" ensures that LLVM
  2933. will not use the same register for any inputs (other than an input tied to this
  2934. output).
  2935. Input constraints
  2936. """""""""""""""""
  2937. Input constraints do not have a prefix -- just the constraint codes. Each input
  2938. constraint will consume one argument from the call instruction. It is not
  2939. permitted for the asm to write to any input register or memory location (unless
  2940. that input is tied to an output). Note also that multiple inputs may all be
  2941. assigned to the same register, if LLVM can determine that they necessarily all
  2942. contain the same value.
  2943. Instead of providing a Constraint Code, input constraints may also "tie"
  2944. themselves to an output constraint, by providing an integer as the constraint
  2945. string. Tied inputs still consume an argument from the call instruction, and
  2946. take up a position in the asm template numbering as is usual -- they will simply
  2947. be constrained to always use the same register as the output they've been tied
  2948. to. For example, a constraint string of "``=r,0``" says to assign a register for
  2949. output, and use that register as an input as well (it being the 0'th
  2950. constraint).
  2951. It is permitted to tie an input to an "early-clobber" output. In that case, no
  2952. *other* input may share the same register as the input tied to the early-clobber
  2953. (even when the other input has the same value).
  2954. You may only tie an input to an output which has a register constraint, not a
  2955. memory constraint. Only a single input may be tied to an output.
  2956. There is also an "interesting" feature which deserves a bit of explanation: if a
  2957. register class constraint allocates a register which is too small for the value
  2958. type operand provided as input, the input value will be split into multiple
  2959. registers, and all of them passed to the inline asm.
  2960. However, this feature is often not as useful as you might think.
  2961. Firstly, the registers are *not* guaranteed to be consecutive. So, on those
  2962. architectures that have instructions which operate on multiple consecutive
  2963. instructions, this is not an appropriate way to support them. (e.g. the 32-bit
  2964. SparcV8 has a 64-bit load, which instruction takes a single 32-bit register. The
  2965. hardware then loads into both the named register, and the next register. This
  2966. feature of inline asm would not be useful to support that.)
  2967. A few of the targets provide a template string modifier allowing explicit access
  2968. to the second register of a two-register operand (e.g. MIPS ``L``, ``M``, and
  2969. ``D``). On such an architecture, you can actually access the second allocated
  2970. register (yet, still, not any subsequent ones). But, in that case, you're still
  2971. probably better off simply splitting the value into two separate operands, for
  2972. clarity. (e.g. see the description of the ``A`` constraint on X86, which,
  2973. despite existing only for use with this feature, is not really a good idea to
  2974. use)
  2975. Indirect inputs and outputs
  2976. """""""""""""""""""""""""""
  2977. Indirect output or input constraints can be specified by the "``*``" modifier
  2978. (which goes after the "``=``" in case of an output). This indicates that the asm
  2979. will write to or read from the contents of an *address* provided as an input
  2980. argument. (Note that in this way, indirect outputs act more like an *input* than
  2981. an output: just like an input, they consume an argument of the call expression,
  2982. rather than producing a return value. An indirect output constraint is an
  2983. "output" only in that the asm is expected to write to the contents of the input
  2984. memory location, instead of just read from it).
  2985. This is most typically used for memory constraint, e.g. "``=*m``", to pass the
  2986. address of a variable as a value.
  2987. It is also possible to use an indirect *register* constraint, but only on output
  2988. (e.g. "``=*r``"). This will cause LLVM to allocate a register for an output
  2989. value normally, and then, separately emit a store to the address provided as
  2990. input, after the provided inline asm. (It's not clear what value this
  2991. functionality provides, compared to writing the store explicitly after the asm
  2992. statement, and it can only produce worse code, since it bypasses many
  2993. optimization passes. I would recommend not using it.)
  2994. Clobber constraints
  2995. """""""""""""""""""
  2996. A clobber constraint is indicated by a "``~``" prefix. A clobber does not
  2997. consume an input operand, nor generate an output. Clobbers cannot use any of the
  2998. general constraint code letters -- they may use only explicit register
  2999. constraints, e.g. "``~{eax}``". The one exception is that a clobber string of
  3000. "``~{memory}``" indicates that the assembly writes to arbitrary undeclared
  3001. memory locations -- not only the memory pointed to by a declared indirect
  3002. output.
  3003. Note that clobbering named registers that are also present in output
  3004. constraints is not legal.
  3005. Constraint Codes
  3006. """"""""""""""""
  3007. After a potential prefix comes constraint code, or codes.
  3008. A Constraint Code is either a single letter (e.g. "``r``"), a "``^``" character
  3009. followed by two letters (e.g. "``^wc``"), or "``{``" register-name "``}``"
  3010. (e.g. "``{eax}``").
  3011. The one and two letter constraint codes are typically chosen to be the same as
  3012. GCC's constraint codes.
  3013. A single constraint may include one or more than constraint code in it, leaving
  3014. it up to LLVM to choose which one to use. This is included mainly for
  3015. compatibility with the translation of GCC inline asm coming from clang.
  3016. There are two ways to specify alternatives, and either or both may be used in an
  3017. inline asm constraint list:
  3018. 1) Append the codes to each other, making a constraint code set. E.g. "``im``"
  3019. or "``{eax}m``". This means "choose any of the options in the set". The
  3020. choice of constraint is made independently for each constraint in the
  3021. constraint list.
  3022. 2) Use "``|``" between constraint code sets, creating alternatives. Every
  3023. constraint in the constraint list must have the same number of alternative
  3024. sets. With this syntax, the same alternative in *all* of the items in the
  3025. constraint list will be chosen together.
  3026. Putting those together, you might have a two operand constraint string like
  3027. ``"rm|r,ri|rm"``. This indicates that if operand 0 is ``r`` or ``m``, then
  3028. operand 1 may be one of ``r`` or ``i``. If operand 0 is ``r``, then operand 1
  3029. may be one of ``r`` or ``m``. But, operand 0 and 1 cannot both be of type m.
  3030. However, the use of either of the alternatives features is *NOT* recommended, as
  3031. LLVM is not able to make an intelligent choice about which one to use. (At the
  3032. point it currently needs to choose, not enough information is available to do so
  3033. in a smart way.) Thus, it simply tries to make a choice that's most likely to
  3034. compile, not one that will be optimal performance. (e.g., given "``rm``", it'll
  3035. always choose to use memory, not registers). And, if given multiple registers,
  3036. or multiple register classes, it will simply choose the first one. (In fact, it
  3037. doesn't currently even ensure explicitly specified physical registers are
  3038. unique, so specifying multiple physical registers as alternatives, like
  3039. ``{r11}{r12},{r11}{r12}``, will assign r11 to both operands, not at all what was
  3040. intended.)
  3041. Supported Constraint Code List
  3042. """"""""""""""""""""""""""""""
  3043. The constraint codes are, in general, expected to behave the same way they do in
  3044. GCC. LLVM's support is often implemented on an 'as-needed' basis, to support C
  3045. inline asm code which was supported by GCC. A mismatch in behavior between LLVM
  3046. and GCC likely indicates a bug in LLVM.
  3047. Some constraint codes are typically supported by all targets:
  3048. - ``r``: A register in the target's general purpose register class.
  3049. - ``m``: A memory address operand. It is target-specific what addressing modes
  3050. are supported, typical examples are register, or register + register offset,
  3051. or register + immediate offset (of some target-specific size).
  3052. - ``i``: An integer constant (of target-specific width). Allows either a simple
  3053. immediate, or a relocatable value.
  3054. - ``n``: An integer constant -- *not* including relocatable values.
  3055. - ``s``: An integer constant, but allowing *only* relocatable values.
  3056. - ``X``: Allows an operand of any kind, no constraint whatsoever. Typically
  3057. useful to pass a label for an asm branch or call.
  3058. .. FIXME: but that surely isn't actually okay to jump out of an asm
  3059. block without telling llvm about the control transfer???)
  3060. - ``{register-name}``: Requires exactly the named physical register.
  3061. Other constraints are target-specific:
  3062. AArch64:
  3063. - ``z``: An immediate integer 0. Outputs ``WZR`` or ``XZR``, as appropriate.
  3064. - ``I``: An immediate integer valid for an ``ADD`` or ``SUB`` instruction,
  3065. i.e. 0 to 4095 with optional shift by 12.
  3066. - ``J``: An immediate integer that, when negated, is valid for an ``ADD`` or
  3067. ``SUB`` instruction, i.e. -1 to -4095 with optional left shift by 12.
  3068. - ``K``: An immediate integer that is valid for the 'bitmask immediate 32' of a
  3069. logical instruction like ``AND``, ``EOR``, or ``ORR`` with a 32-bit register.
  3070. - ``L``: An immediate integer that is valid for the 'bitmask immediate 64' of a
  3071. logical instruction like ``AND``, ``EOR``, or ``ORR`` with a 64-bit register.
  3072. - ``M``: An immediate integer for use with the ``MOV`` assembly alias on a
  3073. 32-bit register. This is a superset of ``K``: in addition to the bitmask
  3074. immediate, also allows immediate integers which can be loaded with a single
  3075. ``MOVZ`` or ``MOVL`` instruction.
  3076. - ``N``: An immediate integer for use with the ``MOV`` assembly alias on a
  3077. 64-bit register. This is a superset of ``L``.
  3078. - ``Q``: Memory address operand must be in a single register (no
  3079. offsets). (However, LLVM currently does this for the ``m`` constraint as
  3080. well.)
  3081. - ``r``: A 32 or 64-bit integer register (W* or X*).
  3082. - ``w``: A 32, 64, or 128-bit floating-point, SIMD or SVE vector register.
  3083. - ``x``: Like w, but restricted to registers 0 to 15 inclusive.
  3084. - ``y``: Like w, but restricted to SVE vector registers Z0 to Z7 inclusive.
  3085. - ``Upl``: One of the low eight SVE predicate registers (P0 to P7)
  3086. - ``Upa``: Any of the SVE predicate registers (P0 to P15)
  3087. AMDGPU:
  3088. - ``r``: A 32 or 64-bit integer register.
  3089. - ``[0-9]v``: The 32-bit VGPR register, number 0-9.
  3090. - ``[0-9]s``: The 32-bit SGPR register, number 0-9.
  3091. All ARM modes:
  3092. - ``Q``, ``Um``, ``Un``, ``Uq``, ``Us``, ``Ut``, ``Uv``, ``Uy``: Memory address
  3093. operand. Treated the same as operand ``m``, at the moment.
  3094. - ``Te``: An even general-purpose 32-bit integer register: ``r0,r2,...,r12,r14``
  3095. - ``To``: An odd general-purpose 32-bit integer register: ``r1,r3,...,r11``
  3096. ARM and ARM's Thumb2 mode:
  3097. - ``j``: An immediate integer between 0 and 65535 (valid for ``MOVW``)
  3098. - ``I``: An immediate integer valid for a data-processing instruction.
  3099. - ``J``: An immediate integer between -4095 and 4095.
  3100. - ``K``: An immediate integer whose bitwise inverse is valid for a
  3101. data-processing instruction. (Can be used with template modifier "``B``" to
  3102. print the inverted value).
  3103. - ``L``: An immediate integer whose negation is valid for a data-processing
  3104. instruction. (Can be used with template modifier "``n``" to print the negated
  3105. value).
  3106. - ``M``: A power of two or a integer between 0 and 32.
  3107. - ``N``: Invalid immediate constraint.
  3108. - ``O``: Invalid immediate constraint.
  3109. - ``r``: A general-purpose 32-bit integer register (``r0-r15``).
  3110. - ``l``: In Thumb2 mode, low 32-bit GPR registers (``r0-r7``). In ARM mode, same
  3111. as ``r``.
  3112. - ``h``: In Thumb2 mode, a high 32-bit GPR register (``r8-r15``). In ARM mode,
  3113. invalid.
  3114. - ``w``: A 32, 64, or 128-bit floating-point/SIMD register: ``s0-s31``,
  3115. ``d0-d31``, or ``q0-q15``.
  3116. - ``x``: A 32, 64, or 128-bit floating-point/SIMD register: ``s0-s15``,
  3117. ``d0-d7``, or ``q0-q3``.
  3118. - ``t``: A low floating-point/SIMD register: ``s0-s31``, ``d0-d16``, or
  3119. ``q0-q8``.
  3120. ARM's Thumb1 mode:
  3121. - ``I``: An immediate integer between 0 and 255.
  3122. - ``J``: An immediate integer between -255 and -1.
  3123. - ``K``: An immediate integer between 0 and 255, with optional left-shift by
  3124. some amount.
  3125. - ``L``: An immediate integer between -7 and 7.
  3126. - ``M``: An immediate integer which is a multiple of 4 between 0 and 1020.
  3127. - ``N``: An immediate integer between 0 and 31.
  3128. - ``O``: An immediate integer which is a multiple of 4 between -508 and 508.
  3129. - ``r``: A low 32-bit GPR register (``r0-r7``).
  3130. - ``l``: A low 32-bit GPR register (``r0-r7``).
  3131. - ``h``: A high GPR register (``r0-r7``).
  3132. - ``w``: A 32, 64, or 128-bit floating-point/SIMD register: ``s0-s31``,
  3133. ``d0-d31``, or ``q0-q15``.
  3134. - ``x``: A 32, 64, or 128-bit floating-point/SIMD register: ``s0-s15``,
  3135. ``d0-d7``, or ``q0-q3``.
  3136. - ``t``: A low floating-point/SIMD register: ``s0-s31``, ``d0-d16``, or
  3137. ``q0-q8``.
  3138. Hexagon:
  3139. - ``o``, ``v``: A memory address operand, treated the same as constraint ``m``,
  3140. at the moment.
  3141. - ``r``: A 32 or 64-bit register.
  3142. MSP430:
  3143. - ``r``: An 8 or 16-bit register.
  3144. MIPS:
  3145. - ``I``: An immediate signed 16-bit integer.
  3146. - ``J``: An immediate integer zero.
  3147. - ``K``: An immediate unsigned 16-bit integer.
  3148. - ``L``: An immediate 32-bit integer, where the lower 16 bits are 0.
  3149. - ``N``: An immediate integer between -65535 and -1.
  3150. - ``O``: An immediate signed 15-bit integer.
  3151. - ``P``: An immediate integer between 1 and 65535.
  3152. - ``m``: A memory address operand. In MIPS-SE mode, allows a base address
  3153. register plus 16-bit immediate offset. In MIPS mode, just a base register.
  3154. - ``R``: A memory address operand. In MIPS-SE mode, allows a base address
  3155. register plus a 9-bit signed offset. In MIPS mode, the same as constraint
  3156. ``m``.
  3157. - ``ZC``: A memory address operand, suitable for use in a ``pref``, ``ll``, or
  3158. ``sc`` instruction on the given subtarget (details vary).
  3159. - ``r``, ``d``, ``y``: A 32 or 64-bit GPR register.
  3160. - ``f``: A 32 or 64-bit FPU register (``F0-F31``), or a 128-bit MSA register
  3161. (``W0-W31``). In the case of MSA registers, it is recommended to use the ``w``
  3162. argument modifier for compatibility with GCC.
  3163. - ``c``: A 32-bit or 64-bit GPR register suitable for indirect jump (always
  3164. ``25``).
  3165. - ``l``: The ``lo`` register, 32 or 64-bit.
  3166. - ``x``: Invalid.
  3167. NVPTX:
  3168. - ``b``: A 1-bit integer register.
  3169. - ``c`` or ``h``: A 16-bit integer register.
  3170. - ``r``: A 32-bit integer register.
  3171. - ``l`` or ``N``: A 64-bit integer register.
  3172. - ``f``: A 32-bit float register.
  3173. - ``d``: A 64-bit float register.
  3174. PowerPC:
  3175. - ``I``: An immediate signed 16-bit integer.
  3176. - ``J``: An immediate unsigned 16-bit integer, shifted left 16 bits.
  3177. - ``K``: An immediate unsigned 16-bit integer.
  3178. - ``L``: An immediate signed 16-bit integer, shifted left 16 bits.
  3179. - ``M``: An immediate integer greater than 31.
  3180. - ``N``: An immediate integer that is an exact power of 2.
  3181. - ``O``: The immediate integer constant 0.
  3182. - ``P``: An immediate integer constant whose negation is a signed 16-bit
  3183. constant.
  3184. - ``es``, ``o``, ``Q``, ``Z``, ``Zy``: A memory address operand, currently
  3185. treated the same as ``m``.
  3186. - ``r``: A 32 or 64-bit integer register.
  3187. - ``b``: A 32 or 64-bit integer register, excluding ``R0`` (that is:
  3188. ``R1-R31``).
  3189. - ``f``: A 32 or 64-bit float register (``F0-F31``), or when QPX is enabled, a
  3190. 128 or 256-bit QPX register (``Q0-Q31``; aliases the ``F`` registers).
  3191. - ``v``: For ``4 x f32`` or ``4 x f64`` types, when QPX is enabled, a
  3192. 128 or 256-bit QPX register (``Q0-Q31``), otherwise a 128-bit
  3193. altivec vector register (``V0-V31``).
  3194. .. FIXME: is this a bug that v accepts QPX registers? I think this
  3195. is supposed to only use the altivec vector registers?
  3196. - ``y``: Condition register (``CR0-CR7``).
  3197. - ``wc``: An individual CR bit in a CR register.
  3198. - ``wa``, ``wd``, ``wf``: Any 128-bit VSX vector register, from the full VSX
  3199. register set (overlapping both the floating-point and vector register files).
  3200. - ``ws``: A 32 or 64-bit floating-point register, from the full VSX register
  3201. set.
  3202. RISC-V:
  3203. - ``A``: An address operand (using a general-purpose register, without an
  3204. offset).
  3205. - ``I``: A 12-bit signed integer immediate operand.
  3206. - ``J``: A zero integer immediate operand.
  3207. - ``K``: A 5-bit unsigned integer immediate operand.
  3208. - ``f``: A 32- or 64-bit floating-point register (requires F or D extension).
  3209. - ``r``: A 32- or 64-bit general-purpose register (depending on the platform
  3210. ``XLEN``).
  3211. Sparc:
  3212. - ``I``: An immediate 13-bit signed integer.
  3213. - ``r``: A 32-bit integer register.
  3214. - ``f``: Any floating-point register on SparcV8, or a floating-point
  3215. register in the "low" half of the registers on SparcV9.
  3216. - ``e``: Any floating-point register. (Same as ``f`` on SparcV8.)
  3217. SystemZ:
  3218. - ``I``: An immediate unsigned 8-bit integer.
  3219. - ``J``: An immediate unsigned 12-bit integer.
  3220. - ``K``: An immediate signed 16-bit integer.
  3221. - ``L``: An immediate signed 20-bit integer.
  3222. - ``M``: An immediate integer 0x7fffffff.
  3223. - ``Q``: A memory address operand with a base address and a 12-bit immediate
  3224. unsigned displacement.
  3225. - ``R``: A memory address operand with a base address, a 12-bit immediate
  3226. unsigned displacement, and an index register.
  3227. - ``S``: A memory address operand with a base address and a 20-bit immediate
  3228. signed displacement.
  3229. - ``T``: A memory address operand with a base address, a 20-bit immediate
  3230. signed displacement, and an index register.
  3231. - ``r`` or ``d``: A 32, 64, or 128-bit integer register.
  3232. - ``a``: A 32, 64, or 128-bit integer address register (excludes R0, which in an
  3233. address context evaluates as zero).
  3234. - ``h``: A 32-bit value in the high part of a 64bit data register
  3235. (LLVM-specific)
  3236. - ``f``: A 32, 64, or 128-bit floating-point register.
  3237. X86:
  3238. - ``I``: An immediate integer between 0 and 31.
  3239. - ``J``: An immediate integer between 0 and 64.
  3240. - ``K``: An immediate signed 8-bit integer.
  3241. - ``L``: An immediate integer, 0xff or 0xffff or (in 64-bit mode only)
  3242. 0xffffffff.
  3243. - ``M``: An immediate integer between 0 and 3.
  3244. - ``N``: An immediate unsigned 8-bit integer.
  3245. - ``O``: An immediate integer between 0 and 127.
  3246. - ``e``: An immediate 32-bit signed integer.
  3247. - ``Z``: An immediate 32-bit unsigned integer.
  3248. - ``o``, ``v``: Treated the same as ``m``, at the moment.
  3249. - ``q``: An 8, 16, 32, or 64-bit register which can be accessed as an 8-bit
  3250. ``l`` integer register. On X86-32, this is the ``a``, ``b``, ``c``, and ``d``
  3251. registers, and on X86-64, it is all of the integer registers.
  3252. - ``Q``: An 8, 16, 32, or 64-bit register which can be accessed as an 8-bit
  3253. ``h`` integer register. This is the ``a``, ``b``, ``c``, and ``d`` registers.
  3254. - ``r`` or ``l``: An 8, 16, 32, or 64-bit integer register.
  3255. - ``R``: An 8, 16, 32, or 64-bit "legacy" integer register -- one which has
  3256. existed since i386, and can be accessed without the REX prefix.
  3257. - ``f``: A 32, 64, or 80-bit '387 FPU stack pseudo-register.
  3258. - ``y``: A 64-bit MMX register, if MMX is enabled.
  3259. - ``x``: If SSE is enabled: a 32 or 64-bit scalar operand, or 128-bit vector
  3260. operand in a SSE register. If AVX is also enabled, can also be a 256-bit
  3261. vector operand in an AVX register. If AVX-512 is also enabled, can also be a
  3262. 512-bit vector operand in an AVX512 register, Otherwise, an error.
  3263. - ``Y``: The same as ``x``, if *SSE2* is enabled, otherwise an error.
  3264. - ``A``: Special case: allocates EAX first, then EDX, for a single operand (in
  3265. 32-bit mode, a 64-bit integer operand will get split into two registers). It
  3266. is not recommended to use this constraint, as in 64-bit mode, the 64-bit
  3267. operand will get allocated only to RAX -- if two 32-bit operands are needed,
  3268. you're better off splitting it yourself, before passing it to the asm
  3269. statement.
  3270. XCore:
  3271. - ``r``: A 32-bit integer register.
  3272. .. _inline-asm-modifiers:
  3273. Asm template argument modifiers
  3274. ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  3275. In the asm template string, modifiers can be used on the operand reference, like
  3276. "``${0:n}``".
  3277. The modifiers are, in general, expected to behave the same way they do in
  3278. GCC. LLVM's support is often implemented on an 'as-needed' basis, to support C
  3279. inline asm code which was supported by GCC. A mismatch in behavior between LLVM
  3280. and GCC likely indicates a bug in LLVM.
  3281. Target-independent:
  3282. - ``c``: Print an immediate integer constant unadorned, without
  3283. the target-specific immediate punctuation (e.g. no ``$`` prefix).
  3284. - ``n``: Negate and print immediate integer constant unadorned, without the
  3285. target-specific immediate punctuation (e.g. no ``$`` prefix).
  3286. - ``l``: Print as an unadorned label, without the target-specific label
  3287. punctuation (e.g. no ``$`` prefix).
  3288. AArch64:
  3289. - ``w``: Print a GPR register with a ``w*`` name instead of ``x*`` name. E.g.,
  3290. instead of ``x30``, print ``w30``.
  3291. - ``x``: Print a GPR register with a ``x*`` name. (this is the default, anyhow).
  3292. - ``b``, ``h``, ``s``, ``d``, ``q``: Print a floating-point/SIMD register with a
  3293. ``b*``, ``h*``, ``s*``, ``d*``, or ``q*`` name, rather than the default of
  3294. ``v*``.
  3295. AMDGPU:
  3296. - ``r``: No effect.
  3297. ARM:
  3298. - ``a``: Print an operand as an address (with ``[`` and ``]`` surrounding a
  3299. register).
  3300. - ``P``: No effect.
  3301. - ``q``: No effect.
  3302. - ``y``: Print a VFP single-precision register as an indexed double (e.g. print
  3303. as ``d4[1]`` instead of ``s9``)
  3304. - ``B``: Bitwise invert and print an immediate integer constant without ``#``
  3305. prefix.
  3306. - ``L``: Print the low 16-bits of an immediate integer constant.
  3307. - ``M``: Print as a register set suitable for ldm/stm. Also prints *all*
  3308. register operands subsequent to the specified one (!), so use carefully.
  3309. - ``Q``: Print the low-order register of a register-pair, or the low-order
  3310. register of a two-register operand.
  3311. - ``R``: Print the high-order register of a register-pair, or the high-order
  3312. register of a two-register operand.
  3313. - ``H``: Print the second register of a register-pair. (On a big-endian system,
  3314. ``H`` is equivalent to ``Q``, and on little-endian system, ``H`` is equivalent
  3315. to ``R``.)
  3316. .. FIXME: H doesn't currently support printing the second register
  3317. of a two-register operand.
  3318. - ``e``: Print the low doubleword register of a NEON quad register.
  3319. - ``f``: Print the high doubleword register of a NEON quad register.
  3320. - ``m``: Print the base register of a memory operand without the ``[`` and ``]``
  3321. adornment.
  3322. Hexagon:
  3323. - ``L``: Print the second register of a two-register operand. Requires that it
  3324. has been allocated consecutively to the first.
  3325. .. FIXME: why is it restricted to consecutive ones? And there's
  3326. nothing that ensures that happens, is there?
  3327. - ``I``: Print the letter 'i' if the operand is an integer constant, otherwise
  3328. nothing. Used to print 'addi' vs 'add' instructions.
  3329. MSP430:
  3330. No additional modifiers.
  3331. MIPS:
  3332. - ``X``: Print an immediate integer as hexadecimal
  3333. - ``x``: Print the low 16 bits of an immediate integer as hexadecimal.
  3334. - ``d``: Print an immediate integer as decimal.
  3335. - ``m``: Subtract one and print an immediate integer as decimal.
  3336. - ``z``: Print $0 if an immediate zero, otherwise print normally.
  3337. - ``L``: Print the low-order register of a two-register operand, or prints the
  3338. address of the low-order word of a double-word memory operand.
  3339. .. FIXME: L seems to be missing memory operand support.
  3340. - ``M``: Print the high-order register of a two-register operand, or prints the
  3341. address of the high-order word of a double-word memory operand.
  3342. .. FIXME: M seems to be missing memory operand support.
  3343. - ``D``: Print the second register of a two-register operand, or prints the
  3344. second word of a double-word memory operand. (On a big-endian system, ``D`` is
  3345. equivalent to ``L``, and on little-endian system, ``D`` is equivalent to
  3346. ``M``.)
  3347. - ``w``: No effect. Provided for compatibility with GCC which requires this
  3348. modifier in order to print MSA registers (``W0-W31``) with the ``f``
  3349. constraint.
  3350. NVPTX:
  3351. - ``r``: No effect.
  3352. PowerPC:
  3353. - ``L``: Print the second register of a two-register operand. Requires that it
  3354. has been allocated consecutively to the first.
  3355. .. FIXME: why is it restricted to consecutive ones? And there's
  3356. nothing that ensures that happens, is there?
  3357. - ``I``: Print the letter 'i' if the operand is an integer constant, otherwise
  3358. nothing. Used to print 'addi' vs 'add' instructions.
  3359. - ``y``: For a memory operand, prints formatter for a two-register X-form
  3360. instruction. (Currently always prints ``r0,OPERAND``).
  3361. - ``U``: Prints 'u' if the memory operand is an update form, and nothing
  3362. otherwise. (NOTE: LLVM does not support update form, so this will currently
  3363. always print nothing)
  3364. - ``X``: Prints 'x' if the memory operand is an indexed form. (NOTE: LLVM does
  3365. not support indexed form, so this will currently always print nothing)
  3366. Sparc:
  3367. - ``r``: No effect.
  3368. SystemZ:
  3369. SystemZ implements only ``n``, and does *not* support any of the other
  3370. target-independent modifiers.
  3371. X86:
  3372. - ``c``: Print an unadorned integer or symbol name. (The latter is
  3373. target-specific behavior for this typically target-independent modifier).
  3374. - ``A``: Print a register name with a '``*``' before it.
  3375. - ``b``: Print an 8-bit register name (e.g. ``al``); do nothing on a memory
  3376. operand.
  3377. - ``h``: Print the upper 8-bit register name (e.g. ``ah``); do nothing on a
  3378. memory operand.
  3379. - ``w``: Print the 16-bit register name (e.g. ``ax``); do nothing on a memory
  3380. operand.
  3381. - ``k``: Print the 32-bit register name (e.g. ``eax``); do nothing on a memory
  3382. operand.
  3383. - ``q``: Print the 64-bit register name (e.g. ``rax``), if 64-bit registers are
  3384. available, otherwise the 32-bit register name; do nothing on a memory operand.
  3385. - ``n``: Negate and print an unadorned integer, or, for operands other than an
  3386. immediate integer (e.g. a relocatable symbol expression), print a '-' before
  3387. the operand. (The behavior for relocatable symbol expressions is a
  3388. target-specific behavior for this typically target-independent modifier)
  3389. - ``H``: Print a memory reference with additional offset +8.
  3390. - ``P``: Print a memory reference or operand for use as the argument of a call
  3391. instruction. (E.g. omit ``(rip)``, even though it's PC-relative.)
  3392. XCore:
  3393. No additional modifiers.
  3394. Inline Asm Metadata
  3395. ^^^^^^^^^^^^^^^^^^^
  3396. The call instructions that wrap inline asm nodes may have a
  3397. "``!srcloc``" MDNode attached to it that contains a list of constant
  3398. integers. If present, the code generator will use the integer as the
  3399. location cookie value when report errors through the ``LLVMContext``
  3400. error reporting mechanisms. This allows a front-end to correlate backend
  3401. errors that occur with inline asm back to the source code that produced
  3402. it. For example:
  3403. .. code-block:: llvm
  3404. call void asm sideeffect "something bad", ""(), !srcloc !42
  3405. ...
  3406. !42 = !{ i32 1234567 }
  3407. It is up to the front-end to make sense of the magic numbers it places
  3408. in the IR. If the MDNode contains multiple constants, the code generator
  3409. will use the one that corresponds to the line of the asm that the error
  3410. occurs on.
  3411. .. _metadata:
  3412. Metadata
  3413. ========
  3414. LLVM IR allows metadata to be attached to instructions in the program
  3415. that can convey extra information about the code to the optimizers and
  3416. code generator. One example application of metadata is source-level
  3417. debug information. There are two metadata primitives: strings and nodes.
  3418. Metadata does not have a type, and is not a value. If referenced from a
  3419. ``call`` instruction, it uses the ``metadata`` type.
  3420. All metadata are identified in syntax by a exclamation point ('``!``').
  3421. .. _metadata-string:
  3422. Metadata Nodes and Metadata Strings
  3423. -----------------------------------
  3424. A metadata string is a string surrounded by double quotes. It can
  3425. contain any character by escaping non-printable characters with
  3426. "``\xx``" where "``xx``" is the two digit hex code. For example:
  3427. "``!"test\00"``".
  3428. Metadata nodes are represented with notation similar to structure
  3429. constants (a comma separated list of elements, surrounded by braces and
  3430. preceded by an exclamation point). Metadata nodes can have any values as
  3431. their operand. For example:
  3432. .. code-block:: llvm
  3433. !{ !"test\00", i32 10}
  3434. Metadata nodes that aren't uniqued use the ``distinct`` keyword. For example:
  3435. .. code-block:: text
  3436. !0 = distinct !{!"test\00", i32 10}
  3437. ``distinct`` nodes are useful when nodes shouldn't be merged based on their
  3438. content. They can also occur when transformations cause uniquing collisions
  3439. when metadata operands change.
  3440. A :ref:`named metadata <namedmetadatastructure>` is a collection of
  3441. metadata nodes, which can be looked up in the module symbol table. For
  3442. example:
  3443. .. code-block:: llvm
  3444. !foo = !{!4, !3}
  3445. Metadata can be used as function arguments. Here the ``llvm.dbg.value``
  3446. intrinsic is using three metadata arguments:
  3447. .. code-block:: llvm
  3448. call void @llvm.dbg.value(metadata !24, metadata !25, metadata !26)
  3449. Metadata can be attached to an instruction. Here metadata ``!21`` is attached
  3450. to the ``add`` instruction using the ``!dbg`` identifier:
  3451. .. code-block:: llvm
  3452. %indvar.next = add i64 %indvar, 1, !dbg !21
  3453. Metadata can also be attached to a function or a global variable. Here metadata
  3454. ``!22`` is attached to the ``f1`` and ``f2 functions, and the globals ``g1``
  3455. and ``g2`` using the ``!dbg`` identifier:
  3456. .. code-block:: llvm
  3457. declare !dbg !22 void @f1()
  3458. define void @f2() !dbg !22 {
  3459. ret void
  3460. }
  3461. @g1 = global i32 0, !dbg !22
  3462. @g2 = external global i32, !dbg !22
  3463. A transformation is required to drop any metadata attachment that it does not
  3464. know or know it can't preserve. Currently there is an exception for metadata
  3465. attachment to globals for ``!type`` and ``!absolute_symbol`` which can't be
  3466. unconditionally dropped unless the global is itself deleted.
  3467. Metadata attached to a module using named metadata may not be dropped, with
  3468. the exception of debug metadata (named metadata with the name ``!llvm.dbg.*``).
  3469. More information about specific metadata nodes recognized by the
  3470. optimizers and code generator is found below.
  3471. .. _specialized-metadata:
  3472. Specialized Metadata Nodes
  3473. ^^^^^^^^^^^^^^^^^^^^^^^^^^
  3474. Specialized metadata nodes are custom data structures in metadata (as opposed
  3475. to generic tuples). Their fields are labelled, and can be specified in any
  3476. order.
  3477. These aren't inherently debug info centric, but currently all the specialized
  3478. metadata nodes are related to debug info.
  3479. .. _DICompileUnit:
  3480. DICompileUnit
  3481. """""""""""""
  3482. ``DICompileUnit`` nodes represent a compile unit. The ``enums:``,
  3483. ``retainedTypes:``, ``globals:``, ``imports:`` and ``macros:`` fields are tuples
  3484. containing the debug info to be emitted along with the compile unit, regardless
  3485. of code optimizations (some nodes are only emitted if there are references to
  3486. them from instructions). The ``debugInfoForProfiling:`` field is a boolean
  3487. indicating whether or not line-table discriminators are updated to provide
  3488. more-accurate debug info for profiling results.
  3489. .. code-block:: text
  3490. !0 = !DICompileUnit(language: DW_LANG_C99, file: !1, producer: "clang",
  3491. isOptimized: true, flags: "-O2", runtimeVersion: 2,
  3492. splitDebugFilename: "abc.debug", emissionKind: FullDebug,
  3493. enums: !2, retainedTypes: !3, globals: !4, imports: !5,
  3494. macros: !6, dwoId: 0x0abcd)
  3495. Compile unit descriptors provide the root scope for objects declared in a
  3496. specific compilation unit. File descriptors are defined using this scope. These
  3497. descriptors are collected by a named metadata node ``!llvm.dbg.cu``. They keep
  3498. track of global variables, type information, and imported entities (declarations
  3499. and namespaces).
  3500. .. _DIFile:
  3501. DIFile
  3502. """"""
  3503. ``DIFile`` nodes represent files. The ``filename:`` can include slashes.
  3504. .. code-block:: none
  3505. !0 = !DIFile(filename: "path/to/file", directory: "/path/to/dir",
  3506. checksumkind: CSK_MD5,
  3507. checksum: "000102030405060708090a0b0c0d0e0f")
  3508. Files are sometimes used in ``scope:`` fields, and are the only valid target
  3509. for ``file:`` fields.
  3510. Valid values for ``checksumkind:`` field are: {CSK_None, CSK_MD5, CSK_SHA1}
  3511. .. _DIBasicType:
  3512. DIBasicType
  3513. """""""""""
  3514. ``DIBasicType`` nodes represent primitive types, such as ``int``, ``bool`` and
  3515. ``float``. ``tag:`` defaults to ``DW_TAG_base_type``.
  3516. .. code-block:: text
  3517. !0 = !DIBasicType(name: "unsigned char", size: 8, align: 8,
  3518. encoding: DW_ATE_unsigned_char)
  3519. !1 = !DIBasicType(tag: DW_TAG_unspecified_type, name: "decltype(nullptr)")
  3520. The ``encoding:`` describes the details of the type. Usually it's one of the
  3521. following:
  3522. .. code-block:: text
  3523. DW_ATE_address = 1
  3524. DW_ATE_boolean = 2
  3525. DW_ATE_float = 4
  3526. DW_ATE_signed = 5
  3527. DW_ATE_signed_char = 6
  3528. DW_ATE_unsigned = 7
  3529. DW_ATE_unsigned_char = 8
  3530. .. _DISubroutineType:
  3531. DISubroutineType
  3532. """"""""""""""""
  3533. ``DISubroutineType`` nodes represent subroutine types. Their ``types:`` field
  3534. refers to a tuple; the first operand is the return type, while the rest are the
  3535. types of the formal arguments in order. If the first operand is ``null``, that
  3536. represents a function with no return value (such as ``void foo() {}`` in C++).
  3537. .. code-block:: text
  3538. !0 = !BasicType(name: "int", size: 32, align: 32, DW_ATE_signed)
  3539. !1 = !BasicType(name: "char", size: 8, align: 8, DW_ATE_signed_char)
  3540. !2 = !DISubroutineType(types: !{null, !0, !1}) ; void (int, char)
  3541. .. _DIDerivedType:
  3542. DIDerivedType
  3543. """""""""""""
  3544. ``DIDerivedType`` nodes represent types derived from other types, such as
  3545. qualified types.
  3546. .. code-block:: text
  3547. !0 = !DIBasicType(name: "unsigned char", size: 8, align: 8,
  3548. encoding: DW_ATE_unsigned_char)
  3549. !1 = !DIDerivedType(tag: DW_TAG_pointer_type, baseType: !0, size: 32,
  3550. align: 32)
  3551. The following ``tag:`` values are valid:
  3552. .. code-block:: text
  3553. DW_TAG_member = 13
  3554. DW_TAG_pointer_type = 15
  3555. DW_TAG_reference_type = 16
  3556. DW_TAG_typedef = 22
  3557. DW_TAG_inheritance = 28
  3558. DW_TAG_ptr_to_member_type = 31
  3559. DW_TAG_const_type = 38
  3560. DW_TAG_friend = 42
  3561. DW_TAG_volatile_type = 53
  3562. DW_TAG_restrict_type = 55
  3563. DW_TAG_atomic_type = 71
  3564. .. _DIDerivedTypeMember:
  3565. ``DW_TAG_member`` is used to define a member of a :ref:`composite type
  3566. <DICompositeType>`. The type of the member is the ``baseType:``. The
  3567. ``offset:`` is the member's bit offset. If the composite type has an ODR
  3568. ``identifier:`` and does not set ``flags: DIFwdDecl``, then the member is
  3569. uniqued based only on its ``name:`` and ``scope:``.
  3570. ``DW_TAG_inheritance`` and ``DW_TAG_friend`` are used in the ``elements:``
  3571. field of :ref:`composite types <DICompositeType>` to describe parents and
  3572. friends.
  3573. ``DW_TAG_typedef`` is used to provide a name for the ``baseType:``.
  3574. ``DW_TAG_pointer_type``, ``DW_TAG_reference_type``, ``DW_TAG_const_type``,
  3575. ``DW_TAG_volatile_type``, ``DW_TAG_restrict_type`` and ``DW_TAG_atomic_type``
  3576. are used to qualify the ``baseType:``.
  3577. Note that the ``void *`` type is expressed as a type derived from NULL.
  3578. .. _DICompositeType:
  3579. DICompositeType
  3580. """""""""""""""
  3581. ``DICompositeType`` nodes represent types composed of other types, like
  3582. structures and unions. ``elements:`` points to a tuple of the composed types.
  3583. If the source language supports ODR, the ``identifier:`` field gives the unique
  3584. identifier used for type merging between modules. When specified,
  3585. :ref:`subprogram declarations <DISubprogramDeclaration>` and :ref:`member
  3586. derived types <DIDerivedTypeMember>` that reference the ODR-type in their
  3587. ``scope:`` change uniquing rules.
  3588. For a given ``identifier:``, there should only be a single composite type that
  3589. does not have ``flags: DIFlagFwdDecl`` set. LLVM tools that link modules
  3590. together will unique such definitions at parse time via the ``identifier:``
  3591. field, even if the nodes are ``distinct``.
  3592. .. code-block:: text
  3593. !0 = !DIEnumerator(name: "SixKind", value: 7)
  3594. !1 = !DIEnumerator(name: "SevenKind", value: 7)
  3595. !2 = !DIEnumerator(name: "NegEightKind", value: -8)
  3596. !3 = !DICompositeType(tag: DW_TAG_enumeration_type, name: "Enum", file: !12,
  3597. line: 2, size: 32, align: 32, identifier: "_M4Enum",
  3598. elements: !{!0, !1, !2})
  3599. The following ``tag:`` values are valid:
  3600. .. code-block:: text
  3601. DW_TAG_array_type = 1
  3602. DW_TAG_class_type = 2
  3603. DW_TAG_enumeration_type = 4
  3604. DW_TAG_structure_type = 19
  3605. DW_TAG_union_type = 23
  3606. For ``DW_TAG_array_type``, the ``elements:`` should be :ref:`subrange
  3607. descriptors <DISubrange>`, each representing the range of subscripts at that
  3608. level of indexing. The ``DIFlagVector`` flag to ``flags:`` indicates that an
  3609. array type is a native packed vector.
  3610. For ``DW_TAG_enumeration_type``, the ``elements:`` should be :ref:`enumerator
  3611. descriptors <DIEnumerator>`, each representing the definition of an enumeration
  3612. value for the set. All enumeration type descriptors are collected in the
  3613. ``enums:`` field of the :ref:`compile unit <DICompileUnit>`.
  3614. For ``DW_TAG_structure_type``, ``DW_TAG_class_type``, and
  3615. ``DW_TAG_union_type``, the ``elements:`` should be :ref:`derived types
  3616. <DIDerivedType>` with ``tag: DW_TAG_member``, ``tag: DW_TAG_inheritance``, or
  3617. ``tag: DW_TAG_friend``; or :ref:`subprograms <DISubprogram>` with
  3618. ``isDefinition: false``.
  3619. .. _DISubrange:
  3620. DISubrange
  3621. """"""""""
  3622. ``DISubrange`` nodes are the elements for ``DW_TAG_array_type`` variants of
  3623. :ref:`DICompositeType`.
  3624. - ``count: -1`` indicates an empty array.
  3625. - ``count: !9`` describes the count with a :ref:`DILocalVariable`.
  3626. - ``count: !11`` describes the count with a :ref:`DIGlobalVariable`.
  3627. .. code-block:: text
  3628. !0 = !DISubrange(count: 5, lowerBound: 0) ; array counting from 0
  3629. !1 = !DISubrange(count: 5, lowerBound: 1) ; array counting from 1
  3630. !2 = !DISubrange(count: -1) ; empty array.
  3631. ; Scopes used in rest of example
  3632. !6 = !DIFile(filename: "vla.c", directory: "/path/to/file")
  3633. !7 = distinct !DICompileUnit(language: DW_LANG_C99, file: !6)
  3634. !8 = distinct !DISubprogram(name: "foo", scope: !7, file: !6, line: 5)
  3635. ; Use of local variable as count value
  3636. !9 = !DIBasicType(name: "int", size: 32, encoding: DW_ATE_signed)
  3637. !10 = !DILocalVariable(name: "count", scope: !8, file: !6, line: 42, type: !9)
  3638. !11 = !DISubrange(count: !10, lowerBound: 0)
  3639. ; Use of global variable as count value
  3640. !12 = !DIGlobalVariable(name: "count", scope: !8, file: !6, line: 22, type: !9)
  3641. !13 = !DISubrange(count: !12, lowerBound: 0)
  3642. .. _DIEnumerator:
  3643. DIEnumerator
  3644. """"""""""""
  3645. ``DIEnumerator`` nodes are the elements for ``DW_TAG_enumeration_type``
  3646. variants of :ref:`DICompositeType`.
  3647. .. code-block:: text
  3648. !0 = !DIEnumerator(name: "SixKind", value: 7)
  3649. !1 = !DIEnumerator(name: "SevenKind", value: 7)
  3650. !2 = !DIEnumerator(name: "NegEightKind", value: -8)
  3651. DITemplateTypeParameter
  3652. """""""""""""""""""""""
  3653. ``DITemplateTypeParameter`` nodes represent type parameters to generic source
  3654. language constructs. They are used (optionally) in :ref:`DICompositeType` and
  3655. :ref:`DISubprogram` ``templateParams:`` fields.
  3656. .. code-block:: text
  3657. !0 = !DITemplateTypeParameter(name: "Ty", type: !1)
  3658. DITemplateValueParameter
  3659. """"""""""""""""""""""""
  3660. ``DITemplateValueParameter`` nodes represent value parameters to generic source
  3661. language constructs. ``tag:`` defaults to ``DW_TAG_template_value_parameter``,
  3662. but if specified can also be set to ``DW_TAG_GNU_template_template_param`` or
  3663. ``DW_TAG_GNU_template_param_pack``. They are used (optionally) in
  3664. :ref:`DICompositeType` and :ref:`DISubprogram` ``templateParams:`` fields.
  3665. .. code-block:: text
  3666. !0 = !DITemplateValueParameter(name: "Ty", type: !1, value: i32 7)
  3667. DINamespace
  3668. """""""""""
  3669. ``DINamespace`` nodes represent namespaces in the source language.
  3670. .. code-block:: text
  3671. !0 = !DINamespace(name: "myawesomeproject", scope: !1, file: !2, line: 7)
  3672. .. _DIGlobalVariable:
  3673. DIGlobalVariable
  3674. """"""""""""""""
  3675. ``DIGlobalVariable`` nodes represent global variables in the source language.
  3676. .. code-block:: text
  3677. @foo = global i32, !dbg !0
  3678. !0 = !DIGlobalVariableExpression(var: !1, expr: !DIExpression())
  3679. !1 = !DIGlobalVariable(name: "foo", linkageName: "foo", scope: !2,
  3680. file: !3, line: 7, type: !4, isLocal: true,
  3681. isDefinition: false, declaration: !5)
  3682. DIGlobalVariableExpression
  3683. """"""""""""""""""""""""""
  3684. ``DIGlobalVariableExpression`` nodes tie a :ref:`DIGlobalVariable` together
  3685. with a :ref:`DIExpression`.
  3686. .. code-block:: text
  3687. @lower = global i32, !dbg !0
  3688. @upper = global i32, !dbg !1
  3689. !0 = !DIGlobalVariableExpression(
  3690. var: !2,
  3691. expr: !DIExpression(DW_OP_LLVM_fragment, 0, 32)
  3692. )
  3693. !1 = !DIGlobalVariableExpression(
  3694. var: !2,
  3695. expr: !DIExpression(DW_OP_LLVM_fragment, 32, 32)
  3696. )
  3697. !2 = !DIGlobalVariable(name: "split64", linkageName: "split64", scope: !3,
  3698. file: !4, line: 8, type: !5, declaration: !6)
  3699. All global variable expressions should be referenced by the `globals:` field of
  3700. a :ref:`compile unit <DICompileUnit>`.
  3701. .. _DISubprogram:
  3702. DISubprogram
  3703. """"""""""""
  3704. ``DISubprogram`` nodes represent functions from the source language. A
  3705. distinct ``DISubprogram`` may be attached to a function definition using
  3706. ``!dbg`` metadata. A unique ``DISubprogram`` may be attached to a function
  3707. declaration used for call site debug info. The ``variables:`` field points at
  3708. :ref:`variables <DILocalVariable>` that must be retained, even if their IR
  3709. counterparts are optimized out of the IR. The ``type:`` field must point at an
  3710. :ref:`DISubroutineType`.
  3711. .. _DISubprogramDeclaration:
  3712. When ``isDefinition: false``, subprograms describe a declaration in the type
  3713. tree as opposed to a definition of a function. If the scope is a composite
  3714. type with an ODR ``identifier:`` and that does not set ``flags: DIFwdDecl``,
  3715. then the subprogram declaration is uniqued based only on its ``linkageName:``
  3716. and ``scope:``.
  3717. .. code-block:: text
  3718. define void @_Z3foov() !dbg !0 {
  3719. ...
  3720. }
  3721. !0 = distinct !DISubprogram(name: "foo", linkageName: "_Zfoov", scope: !1,
  3722. file: !2, line: 7, type: !3, isLocal: true,
  3723. isDefinition: true, scopeLine: 8,
  3724. containingType: !4,
  3725. virtuality: DW_VIRTUALITY_pure_virtual,
  3726. virtualIndex: 10, flags: DIFlagPrototyped,
  3727. isOptimized: true, unit: !5, templateParams: !6,
  3728. declaration: !7, variables: !8, thrownTypes: !9)
  3729. .. _DILexicalBlock:
  3730. DILexicalBlock
  3731. """"""""""""""
  3732. ``DILexicalBlock`` nodes describe nested blocks within a :ref:`subprogram
  3733. <DISubprogram>`. The line number and column numbers are used to distinguish
  3734. two lexical blocks at same depth. They are valid targets for ``scope:``
  3735. fields.
  3736. .. code-block:: text
  3737. !0 = distinct !DILexicalBlock(scope: !1, file: !2, line: 7, column: 35)
  3738. Usually lexical blocks are ``distinct`` to prevent node merging based on
  3739. operands.
  3740. .. _DILexicalBlockFile:
  3741. DILexicalBlockFile
  3742. """"""""""""""""""
  3743. ``DILexicalBlockFile`` nodes are used to discriminate between sections of a
  3744. :ref:`lexical block <DILexicalBlock>`. The ``file:`` field can be changed to
  3745. indicate textual inclusion, or the ``discriminator:`` field can be used to
  3746. discriminate between control flow within a single block in the source language.
  3747. .. code-block:: text
  3748. !0 = !DILexicalBlock(scope: !3, file: !4, line: 7, column: 35)
  3749. !1 = !DILexicalBlockFile(scope: !0, file: !4, discriminator: 0)
  3750. !2 = !DILexicalBlockFile(scope: !0, file: !4, discriminator: 1)
  3751. .. _DILocation:
  3752. DILocation
  3753. """"""""""
  3754. ``DILocation`` nodes represent source debug locations. The ``scope:`` field is
  3755. mandatory, and points at an :ref:`DILexicalBlockFile`, an
  3756. :ref:`DILexicalBlock`, or an :ref:`DISubprogram`.
  3757. .. code-block:: text
  3758. !0 = !DILocation(line: 2900, column: 42, scope: !1, inlinedAt: !2)
  3759. .. _DILocalVariable:
  3760. DILocalVariable
  3761. """""""""""""""
  3762. ``DILocalVariable`` nodes represent local variables in the source language. If
  3763. the ``arg:`` field is set to non-zero, then this variable is a subprogram
  3764. parameter, and it will be included in the ``variables:`` field of its
  3765. :ref:`DISubprogram`.
  3766. .. code-block:: text
  3767. !0 = !DILocalVariable(name: "this", arg: 1, scope: !3, file: !2, line: 7,
  3768. type: !3, flags: DIFlagArtificial)
  3769. !1 = !DILocalVariable(name: "x", arg: 2, scope: !4, file: !2, line: 7,
  3770. type: !3)
  3771. !2 = !DILocalVariable(name: "y", scope: !5, file: !2, line: 7, type: !3)
  3772. .. _DIExpression:
  3773. DIExpression
  3774. """"""""""""
  3775. ``DIExpression`` nodes represent expressions that are inspired by the DWARF
  3776. expression language. They are used in :ref:`debug intrinsics<dbg_intrinsics>`
  3777. (such as ``llvm.dbg.declare`` and ``llvm.dbg.value``) to describe how the
  3778. referenced LLVM variable relates to the source language variable. Debug
  3779. intrinsics are interpreted left-to-right: start by pushing the value/address
  3780. operand of the intrinsic onto a stack, then repeatedly push and evaluate
  3781. opcodes from the DIExpression until the final variable description is produced.
  3782. The current supported opcode vocabulary is limited:
  3783. - ``DW_OP_deref`` dereferences the top of the expression stack.
  3784. - ``DW_OP_plus`` pops the last two entries from the expression stack, adds
  3785. them together and appends the result to the expression stack.
  3786. - ``DW_OP_minus`` pops the last two entries from the expression stack, subtracts
  3787. the last entry from the second last entry and appends the result to the
  3788. expression stack.
  3789. - ``DW_OP_plus_uconst, 93`` adds ``93`` to the working expression.
  3790. - ``DW_OP_LLVM_fragment, 16, 8`` specifies the offset and size (``16`` and ``8``
  3791. here, respectively) of the variable fragment from the working expression. Note
  3792. that contrary to DW_OP_bit_piece, the offset is describing the location
  3793. within the described source variable.
  3794. - ``DW_OP_LLVM_convert, 16, DW_ATE_signed`` specifies a bit size and encoding
  3795. (``16`` and ``DW_ATE_signed`` here, respectively) to which the top of the
  3796. expression stack is to be converted. Maps into a ``DW_OP_convert`` operation
  3797. that references a base type constructed from the supplied values.
  3798. - ``DW_OP_LLVM_tag_offset, tag_offset`` specifies that a memory tag should be
  3799. optionally applied to the pointer. The memory tag is derived from the
  3800. given tag offset in an implementation-defined manner.
  3801. - ``DW_OP_swap`` swaps top two stack entries.
  3802. - ``DW_OP_xderef`` provides extended dereference mechanism. The entry at the top
  3803. of the stack is treated as an address. The second stack entry is treated as an
  3804. address space identifier.
  3805. - ``DW_OP_stack_value`` marks a constant value.
  3806. - If an expression is marked with ``DW_OP_entry_value`` all register and
  3807. memory read operations refer to the respective value at the function entry.
  3808. The first operand of ``DW_OP_entry_value`` is the size of following
  3809. DWARF expression.
  3810. ``DW_OP_entry_value`` may appear after the ``LiveDebugValues`` pass.
  3811. LLVM only supports entry values for function parameters
  3812. that are unmodified throughout a function and that are described as
  3813. simple register location descriptions.
  3814. ``DW_OP_entry_value`` may also appear after the ``AsmPrinter`` pass when
  3815. a call site parameter value (``DW_AT_call_site_parameter_value``)
  3816. is represented as entry value of the parameter.
  3817. - ``DW_OP_breg`` (or ``DW_OP_bregx``) represents a content on the provided
  3818. signed offset of the specified register. The opcode is only generated by the
  3819. ``AsmPrinter`` pass to describe call site parameter value which requires an
  3820. expression over two registers.
  3821. DWARF specifies three kinds of simple location descriptions: Register, memory,
  3822. and implicit location descriptions. Note that a location description is
  3823. defined over certain ranges of a program, i.e the location of a variable may
  3824. change over the course of the program. Register and memory location
  3825. descriptions describe the *concrete location* of a source variable (in the
  3826. sense that a debugger might modify its value), whereas *implicit locations*
  3827. describe merely the actual *value* of a source variable which might not exist
  3828. in registers or in memory (see ``DW_OP_stack_value``).
  3829. A ``llvm.dbg.addr`` or ``llvm.dbg.declare`` intrinsic describes an indirect
  3830. value (the address) of a source variable. The first operand of the intrinsic
  3831. must be an address of some kind. A DIExpression attached to the intrinsic
  3832. refines this address to produce a concrete location for the source variable.
  3833. A ``llvm.dbg.value`` intrinsic describes the direct value of a source variable.
  3834. The first operand of the intrinsic may be a direct or indirect value. A
  3835. DIExpresion attached to the intrinsic refines the first operand to produce a
  3836. direct value. For example, if the first operand is an indirect value, it may be
  3837. necessary to insert ``DW_OP_deref`` into the DIExpresion in order to produce a
  3838. valid debug intrinsic.
  3839. .. note::
  3840. A DIExpression is interpreted in the same way regardless of which kind of
  3841. debug intrinsic it's attached to.
  3842. .. code-block:: text
  3843. !0 = !DIExpression(DW_OP_deref)
  3844. !1 = !DIExpression(DW_OP_plus_uconst, 3)
  3845. !1 = !DIExpression(DW_OP_constu, 3, DW_OP_plus)
  3846. !2 = !DIExpression(DW_OP_bit_piece, 3, 7)
  3847. !3 = !DIExpression(DW_OP_deref, DW_OP_constu, 3, DW_OP_plus, DW_OP_LLVM_fragment, 3, 7)
  3848. !4 = !DIExpression(DW_OP_constu, 2, DW_OP_swap, DW_OP_xderef)
  3849. !5 = !DIExpression(DW_OP_constu, 42, DW_OP_stack_value)
  3850. DIFlags
  3851. """""""""""""""
  3852. These flags encode various properties of DINodes.
  3853. The `ArgumentNotModified` flag marks a function argument whose value
  3854. is not modified throughout of a function. This flag is used to decide
  3855. whether a DW_OP_entry_value can be used in a location description
  3856. after the function prologue. The language frontend is expected to compute
  3857. this property for each DILocalVariable. The flag should be used
  3858. only in optimized code.
  3859. The `ExportSymbols` flag marks a class, struct or union whose members
  3860. may be referenced as if they were defined in the containing class or
  3861. union. This flag is used to decide whether the DW_AT_export_symbols can
  3862. be used for the structure type.
  3863. DIObjCProperty
  3864. """"""""""""""
  3865. ``DIObjCProperty`` nodes represent Objective-C property nodes.
  3866. .. code-block:: text
  3867. !3 = !DIObjCProperty(name: "foo", file: !1, line: 7, setter: "setFoo",
  3868. getter: "getFoo", attributes: 7, type: !2)
  3869. DIImportedEntity
  3870. """"""""""""""""
  3871. ``DIImportedEntity`` nodes represent entities (such as modules) imported into a
  3872. compile unit.
  3873. .. code-block:: text
  3874. !2 = !DIImportedEntity(tag: DW_TAG_imported_module, name: "foo", scope: !0,
  3875. entity: !1, line: 7)
  3876. DIMacro
  3877. """""""
  3878. ``DIMacro`` nodes represent definition or undefinition of a macro identifiers.
  3879. The ``name:`` field is the macro identifier, followed by macro parameters when
  3880. defining a function-like macro, and the ``value`` field is the token-string
  3881. used to expand the macro identifier.
  3882. .. code-block:: text
  3883. !2 = !DIMacro(macinfo: DW_MACINFO_define, line: 7, name: "foo(x)",
  3884. value: "((x) + 1)")
  3885. !3 = !DIMacro(macinfo: DW_MACINFO_undef, line: 30, name: "foo")
  3886. DIMacroFile
  3887. """""""""""
  3888. ``DIMacroFile`` nodes represent inclusion of source files.
  3889. The ``nodes:`` field is a list of ``DIMacro`` and ``DIMacroFile`` nodes that
  3890. appear in the included source file.
  3891. .. code-block:: text
  3892. !2 = !DIMacroFile(macinfo: DW_MACINFO_start_file, line: 7, file: !2,
  3893. nodes: !3)
  3894. '``tbaa``' Metadata
  3895. ^^^^^^^^^^^^^^^^^^^
  3896. In LLVM IR, memory does not have types, so LLVM's own type system is not
  3897. suitable for doing type based alias analysis (TBAA). Instead, metadata is
  3898. added to the IR to describe a type system of a higher level language. This
  3899. can be used to implement C/C++ strict type aliasing rules, but it can also
  3900. be used to implement custom alias analysis behavior for other languages.
  3901. This description of LLVM's TBAA system is broken into two parts:
  3902. :ref:`Semantics<tbaa_node_semantics>` talks about high level issues, and
  3903. :ref:`Representation<tbaa_node_representation>` talks about the metadata
  3904. encoding of various entities.
  3905. It is always possible to trace any TBAA node to a "root" TBAA node (details
  3906. in the :ref:`Representation<tbaa_node_representation>` section). TBAA
  3907. nodes with different roots have an unknown aliasing relationship, and LLVM
  3908. conservatively infers ``MayAlias`` between them. The rules mentioned in
  3909. this section only pertain to TBAA nodes living under the same root.
  3910. .. _tbaa_node_semantics:
  3911. Semantics
  3912. """""""""
  3913. The TBAA metadata system, referred to as "struct path TBAA" (not to be
  3914. confused with ``tbaa.struct``), consists of the following high level
  3915. concepts: *Type Descriptors*, further subdivided into scalar type
  3916. descriptors and struct type descriptors; and *Access Tags*.
  3917. **Type descriptors** describe the type system of the higher level language
  3918. being compiled. **Scalar type descriptors** describe types that do not
  3919. contain other types. Each scalar type has a parent type, which must also
  3920. be a scalar type or the TBAA root. Via this parent relation, scalar types
  3921. within a TBAA root form a tree. **Struct type descriptors** denote types
  3922. that contain a sequence of other type descriptors, at known offsets. These
  3923. contained type descriptors can either be struct type descriptors themselves
  3924. or scalar type descriptors.
  3925. **Access tags** are metadata nodes attached to load and store instructions.
  3926. Access tags use type descriptors to describe the *location* being accessed
  3927. in terms of the type system of the higher level language. Access tags are
  3928. tuples consisting of a base type, an access type and an offset. The base
  3929. type is a scalar type descriptor or a struct type descriptor, the access
  3930. type is a scalar type descriptor, and the offset is a constant integer.
  3931. The access tag ``(BaseTy, AccessTy, Offset)`` can describe one of two
  3932. things:
  3933. * If ``BaseTy`` is a struct type, the tag describes a memory access (load
  3934. or store) of a value of type ``AccessTy`` contained in the struct type
  3935. ``BaseTy`` at offset ``Offset``.
  3936. * If ``BaseTy`` is a scalar type, ``Offset`` must be 0 and ``BaseTy`` and
  3937. ``AccessTy`` must be the same; and the access tag describes a scalar
  3938. access with scalar type ``AccessTy``.
  3939. We first define an ``ImmediateParent`` relation on ``(BaseTy, Offset)``
  3940. tuples this way:
  3941. * If ``BaseTy`` is a scalar type then ``ImmediateParent(BaseTy, 0)`` is
  3942. ``(ParentTy, 0)`` where ``ParentTy`` is the parent of the scalar type as
  3943. described in the TBAA metadata. ``ImmediateParent(BaseTy, Offset)`` is
  3944. undefined if ``Offset`` is non-zero.
  3945. * If ``BaseTy`` is a struct type then ``ImmediateParent(BaseTy, Offset)``
  3946. is ``(NewTy, NewOffset)`` where ``NewTy`` is the type contained in
  3947. ``BaseTy`` at offset ``Offset`` and ``NewOffset`` is ``Offset`` adjusted
  3948. to be relative within that inner type.
  3949. A memory access with an access tag ``(BaseTy1, AccessTy1, Offset1)``
  3950. aliases a memory access with an access tag ``(BaseTy2, AccessTy2,
  3951. Offset2)`` if either ``(BaseTy1, Offset1)`` is reachable from ``(Base2,
  3952. Offset2)`` via the ``Parent`` relation or vice versa.
  3953. As a concrete example, the type descriptor graph for the following program
  3954. .. code-block:: c
  3955. struct Inner {
  3956. int i; // offset 0
  3957. float f; // offset 4
  3958. };
  3959. struct Outer {
  3960. float f; // offset 0
  3961. double d; // offset 4
  3962. struct Inner inner_a; // offset 12
  3963. };
  3964. void f(struct Outer* outer, struct Inner* inner, float* f, int* i, char* c) {
  3965. outer->f = 0; // tag0: (OuterStructTy, FloatScalarTy, 0)
  3966. outer->inner_a.i = 0; // tag1: (OuterStructTy, IntScalarTy, 12)
  3967. outer->inner_a.f = 0.0; // tag2: (OuterStructTy, FloatScalarTy, 16)
  3968. *f = 0.0; // tag3: (FloatScalarTy, FloatScalarTy, 0)
  3969. }
  3970. is (note that in C and C++, ``char`` can be used to access any arbitrary
  3971. type):
  3972. .. code-block:: text
  3973. Root = "TBAA Root"
  3974. CharScalarTy = ("char", Root, 0)
  3975. FloatScalarTy = ("float", CharScalarTy, 0)
  3976. DoubleScalarTy = ("double", CharScalarTy, 0)
  3977. IntScalarTy = ("int", CharScalarTy, 0)
  3978. InnerStructTy = {"Inner" (IntScalarTy, 0), (FloatScalarTy, 4)}
  3979. OuterStructTy = {"Outer", (FloatScalarTy, 0), (DoubleScalarTy, 4),
  3980. (InnerStructTy, 12)}
  3981. with (e.g.) ``ImmediateParent(OuterStructTy, 12)`` = ``(InnerStructTy,
  3982. 0)``, ``ImmediateParent(InnerStructTy, 0)`` = ``(IntScalarTy, 0)``, and
  3983. ``ImmediateParent(IntScalarTy, 0)`` = ``(CharScalarTy, 0)``.
  3984. .. _tbaa_node_representation:
  3985. Representation
  3986. """"""""""""""
  3987. The root node of a TBAA type hierarchy is an ``MDNode`` with 0 operands or
  3988. with exactly one ``MDString`` operand.
  3989. Scalar type descriptors are represented as an ``MDNode`` s with two
  3990. operands. The first operand is an ``MDString`` denoting the name of the
  3991. struct type. LLVM does not assign meaning to the value of this operand, it
  3992. only cares about it being an ``MDString``. The second operand is an
  3993. ``MDNode`` which points to the parent for said scalar type descriptor,
  3994. which is either another scalar type descriptor or the TBAA root. Scalar
  3995. type descriptors can have an optional third argument, but that must be the
  3996. constant integer zero.
  3997. Struct type descriptors are represented as ``MDNode`` s with an odd number
  3998. of operands greater than 1. The first operand is an ``MDString`` denoting
  3999. the name of the struct type. Like in scalar type descriptors the actual
  4000. value of this name operand is irrelevant to LLVM. After the name operand,
  4001. the struct type descriptors have a sequence of alternating ``MDNode`` and
  4002. ``ConstantInt`` operands. With N starting from 1, the 2N - 1 th operand,
  4003. an ``MDNode``, denotes a contained field, and the 2N th operand, a
  4004. ``ConstantInt``, is the offset of the said contained field. The offsets
  4005. must be in non-decreasing order.
  4006. Access tags are represented as ``MDNode`` s with either 3 or 4 operands.
  4007. The first operand is an ``MDNode`` pointing to the node representing the
  4008. base type. The second operand is an ``MDNode`` pointing to the node
  4009. representing the access type. The third operand is a ``ConstantInt`` that
  4010. states the offset of the access. If a fourth field is present, it must be
  4011. a ``ConstantInt`` valued at 0 or 1. If it is 1 then the access tag states
  4012. that the location being accessed is "constant" (meaning
  4013. ``pointsToConstantMemory`` should return true; see `other useful
  4014. AliasAnalysis methods <AliasAnalysis.html#OtherItfs>`_). The TBAA root of
  4015. the access type and the base type of an access tag must be the same, and
  4016. that is the TBAA root of the access tag.
  4017. '``tbaa.struct``' Metadata
  4018. ^^^^^^^^^^^^^^^^^^^^^^^^^^
  4019. The :ref:`llvm.memcpy <int_memcpy>` is often used to implement
  4020. aggregate assignment operations in C and similar languages, however it
  4021. is defined to copy a contiguous region of memory, which is more than
  4022. strictly necessary for aggregate types which contain holes due to
  4023. padding. Also, it doesn't contain any TBAA information about the fields
  4024. of the aggregate.
  4025. ``!tbaa.struct`` metadata can describe which memory subregions in a
  4026. memcpy are padding and what the TBAA tags of the struct are.
  4027. The current metadata format is very simple. ``!tbaa.struct`` metadata
  4028. nodes are a list of operands which are in conceptual groups of three.
  4029. For each group of three, the first operand gives the byte offset of a
  4030. field in bytes, the second gives its size in bytes, and the third gives
  4031. its tbaa tag. e.g.:
  4032. .. code-block:: llvm
  4033. !4 = !{ i64 0, i64 4, !1, i64 8, i64 4, !2 }
  4034. This describes a struct with two fields. The first is at offset 0 bytes
  4035. with size 4 bytes, and has tbaa tag !1. The second is at offset 8 bytes
  4036. and has size 4 bytes and has tbaa tag !2.
  4037. Note that the fields need not be contiguous. In this example, there is a
  4038. 4 byte gap between the two fields. This gap represents padding which
  4039. does not carry useful data and need not be preserved.
  4040. '``noalias``' and '``alias.scope``' Metadata
  4041. ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  4042. ``noalias`` and ``alias.scope`` metadata provide the ability to specify generic
  4043. noalias memory-access sets. This means that some collection of memory access
  4044. instructions (loads, stores, memory-accessing calls, etc.) that carry
  4045. ``noalias`` metadata can specifically be specified not to alias with some other
  4046. collection of memory access instructions that carry ``alias.scope`` metadata.
  4047. Each type of metadata specifies a list of scopes where each scope has an id and
  4048. a domain.
  4049. When evaluating an aliasing query, if for some domain, the set
  4050. of scopes with that domain in one instruction's ``alias.scope`` list is a
  4051. subset of (or equal to) the set of scopes for that domain in another
  4052. instruction's ``noalias`` list, then the two memory accesses are assumed not to
  4053. alias.
  4054. Because scopes in one domain don't affect scopes in other domains, separate
  4055. domains can be used to compose multiple independent noalias sets. This is
  4056. used for example during inlining. As the noalias function parameters are
  4057. turned into noalias scope metadata, a new domain is used every time the
  4058. function is inlined.
  4059. The metadata identifying each domain is itself a list containing one or two
  4060. entries. The first entry is the name of the domain. Note that if the name is a
  4061. string then it can be combined across functions and translation units. A
  4062. self-reference can be used to create globally unique domain names. A
  4063. descriptive string may optionally be provided as a second list entry.
  4064. The metadata identifying each scope is also itself a list containing two or
  4065. three entries. The first entry is the name of the scope. Note that if the name
  4066. is a string then it can be combined across functions and translation units. A
  4067. self-reference can be used to create globally unique scope names. A metadata
  4068. reference to the scope's domain is the second entry. A descriptive string may
  4069. optionally be provided as a third list entry.
  4070. For example,
  4071. .. code-block:: llvm
  4072. ; Two scope domains:
  4073. !0 = !{!0}
  4074. !1 = !{!1}
  4075. ; Some scopes in these domains:
  4076. !2 = !{!2, !0}
  4077. !3 = !{!3, !0}
  4078. !4 = !{!4, !1}
  4079. ; Some scope lists:
  4080. !5 = !{!4} ; A list containing only scope !4
  4081. !6 = !{!4, !3, !2}
  4082. !7 = !{!3}
  4083. ; These two instructions don't alias:
  4084. %0 = load float, float* %c, align 4, !alias.scope !5
  4085. store float %0, float* %arrayidx.i, align 4, !noalias !5
  4086. ; These two instructions also don't alias (for domain !1, the set of scopes
  4087. ; in the !alias.scope equals that in the !noalias list):
  4088. %2 = load float, float* %c, align 4, !alias.scope !5
  4089. store float %2, float* %arrayidx.i2, align 4, !noalias !6
  4090. ; These two instructions may alias (for domain !0, the set of scopes in
  4091. ; the !noalias list is not a superset of, or equal to, the scopes in the
  4092. ; !alias.scope list):
  4093. %2 = load float, float* %c, align 4, !alias.scope !6
  4094. store float %0, float* %arrayidx.i, align 4, !noalias !7
  4095. '``fpmath``' Metadata
  4096. ^^^^^^^^^^^^^^^^^^^^^
  4097. ``fpmath`` metadata may be attached to any instruction of floating-point
  4098. type. It can be used to express the maximum acceptable error in the
  4099. result of that instruction, in ULPs, thus potentially allowing the
  4100. compiler to use a more efficient but less accurate method of computing
  4101. it. ULP is defined as follows:
  4102. If ``x`` is a real number that lies between two finite consecutive
  4103. floating-point numbers ``a`` and ``b``, without being equal to one
  4104. of them, then ``ulp(x) = |b - a|``, otherwise ``ulp(x)`` is the
  4105. distance between the two non-equal finite floating-point numbers
  4106. nearest ``x``. Moreover, ``ulp(NaN)`` is ``NaN``.
  4107. The metadata node shall consist of a single positive float type number
  4108. representing the maximum relative error, for example:
  4109. .. code-block:: llvm
  4110. !0 = !{ float 2.5 } ; maximum acceptable inaccuracy is 2.5 ULPs
  4111. .. _range-metadata:
  4112. '``range``' Metadata
  4113. ^^^^^^^^^^^^^^^^^^^^
  4114. ``range`` metadata may be attached only to ``load``, ``call`` and ``invoke`` of
  4115. integer types. It expresses the possible ranges the loaded value or the value
  4116. returned by the called function at this call site is in. If the loaded or
  4117. returned value is not in the specified range, the behavior is undefined. The
  4118. ranges are represented with a flattened list of integers. The loaded value or
  4119. the value returned is known to be in the union of the ranges defined by each
  4120. consecutive pair. Each pair has the following properties:
  4121. - The type must match the type loaded by the instruction.
  4122. - The pair ``a,b`` represents the range ``[a,b)``.
  4123. - Both ``a`` and ``b`` are constants.
  4124. - The range is allowed to wrap.
  4125. - The range should not represent the full or empty set. That is,
  4126. ``a!=b``.
  4127. In addition, the pairs must be in signed order of the lower bound and
  4128. they must be non-contiguous.
  4129. Examples:
  4130. .. code-block:: llvm
  4131. %a = load i8, i8* %x, align 1, !range !0 ; Can only be 0 or 1
  4132. %b = load i8, i8* %y, align 1, !range !1 ; Can only be 255 (-1), 0 or 1
  4133. %c = call i8 @foo(), !range !2 ; Can only be 0, 1, 3, 4 or 5
  4134. %d = invoke i8 @bar() to label %cont
  4135. unwind label %lpad, !range !3 ; Can only be -2, -1, 3, 4 or 5
  4136. ...
  4137. !0 = !{ i8 0, i8 2 }
  4138. !1 = !{ i8 255, i8 2 }
  4139. !2 = !{ i8 0, i8 2, i8 3, i8 6 }
  4140. !3 = !{ i8 -2, i8 0, i8 3, i8 6 }
  4141. '``absolute_symbol``' Metadata
  4142. ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  4143. ``absolute_symbol`` metadata may be attached to a global variable
  4144. declaration. It marks the declaration as a reference to an absolute symbol,
  4145. which causes the backend to use absolute relocations for the symbol even
  4146. in position independent code, and expresses the possible ranges that the
  4147. global variable's *address* (not its value) is in, in the same format as
  4148. ``range`` metadata, with the extension that the pair ``all-ones,all-ones``
  4149. may be used to represent the full set.
  4150. Example (assuming 64-bit pointers):
  4151. .. code-block:: llvm
  4152. @a = external global i8, !absolute_symbol !0 ; Absolute symbol in range [0,256)
  4153. @b = external global i8, !absolute_symbol !1 ; Absolute symbol in range [0,2^64)
  4154. ...
  4155. !0 = !{ i64 0, i64 256 }
  4156. !1 = !{ i64 -1, i64 -1 }
  4157. '``callees``' Metadata
  4158. ^^^^^^^^^^^^^^^^^^^^^^
  4159. ``callees`` metadata may be attached to indirect call sites. If ``callees``
  4160. metadata is attached to a call site, and any callee is not among the set of
  4161. functions provided by the metadata, the behavior is undefined. The intent of
  4162. this metadata is to facilitate optimizations such as indirect-call promotion.
  4163. For example, in the code below, the call instruction may only target the
  4164. ``add`` or ``sub`` functions:
  4165. .. code-block:: llvm
  4166. %result = call i64 %binop(i64 %x, i64 %y), !callees !0
  4167. ...
  4168. !0 = !{i64 (i64, i64)* @add, i64 (i64, i64)* @sub}
  4169. '``callback``' Metadata
  4170. ^^^^^^^^^^^^^^^^^^^^^^^
  4171. ``callback`` metadata may be attached to a function declaration, or definition.
  4172. (Call sites are excluded only due to the lack of a use case.) For ease of
  4173. exposition, we'll refer to the function annotated w/ metadata as a broker
  4174. function. The metadata describes how the arguments of a call to the broker are
  4175. in turn passed to the callback function specified by the metadata. Thus, the
  4176. ``callback`` metadata provides a partial description of a call site inside the
  4177. broker function with regards to the arguments of a call to the broker. The only
  4178. semantic restriction on the broker function itself is that it is not allowed to
  4179. inspect or modify arguments referenced in the ``callback`` metadata as
  4180. pass-through to the callback function.
  4181. The broker is not required to actually invoke the callback function at runtime.
  4182. However, the assumptions about not inspecting or modifying arguments that would
  4183. be passed to the specified callback function still hold, even if the callback
  4184. function is not dynamically invoked. The broker is allowed to invoke the
  4185. callback function more than once per invocation of the broker. The broker is
  4186. also allowed to invoke (directly or indirectly) the function passed as a
  4187. callback through another use. Finally, the broker is also allowed to relay the
  4188. callback callee invocation to a different thread.
  4189. The metadata is structured as follows: At the outer level, ``callback``
  4190. metadata is a list of ``callback`` encodings. Each encoding starts with a
  4191. constant ``i64`` which describes the argument position of the callback function
  4192. in the call to the broker. The following elements, except the last, describe
  4193. what arguments are passed to the callback function. Each element is again an
  4194. ``i64`` constant identifying the argument of the broker that is passed through,
  4195. or ``i64 -1`` to indicate an unknown or inspected argument. The order in which
  4196. they are listed has to be the same in which they are passed to the callback
  4197. callee. The last element of the encoding is a boolean which specifies how
  4198. variadic arguments of the broker are handled. If it is true, all variadic
  4199. arguments of the broker are passed through to the callback function *after* the
  4200. arguments encoded explicitly before.
  4201. In the code below, the ``pthread_create`` function is marked as a broker
  4202. through the ``!callback !1`` metadata. In the example, there is only one
  4203. callback encoding, namely ``!2``, associated with the broker. This encoding
  4204. identifies the callback function as the second argument of the broker (``i64
  4205. 2``) and the sole argument of the callback function as the third one of the
  4206. broker function (``i64 3``).
  4207. .. FIXME why does the llvm-sphinx-docs builder give a highlighting
  4208. error if the below is set to highlight as 'llvm', despite that we
  4209. have misc.highlighting_failure set?
  4210. .. code-block:: text
  4211. declare !callback !1 dso_local i32 @pthread_create(i64*, %union.pthread_attr_t*, i8* (i8*)*, i8*)
  4212. ...
  4213. !2 = !{i64 2, i64 3, i1 false}
  4214. !1 = !{!2}
  4215. Another example is shown below. The callback callee is the second argument of
  4216. the ``__kmpc_fork_call`` function (``i64 2``). The callee is given two unknown
  4217. values (each identified by a ``i64 -1``) and afterwards all
  4218. variadic arguments that are passed to the ``__kmpc_fork_call`` call (due to the
  4219. final ``i1 true``).
  4220. .. FIXME why does the llvm-sphinx-docs builder give a highlighting
  4221. error if the below is set to highlight as 'llvm', despite that we
  4222. have misc.highlighting_failure set?
  4223. .. code-block:: text
  4224. declare !callback !0 dso_local void @__kmpc_fork_call(%struct.ident_t*, i32, void (i32*, i32*, ...)*, ...)
  4225. ...
  4226. !1 = !{i64 2, i64 -1, i64 -1, i1 true}
  4227. !0 = !{!1}
  4228. '``unpredictable``' Metadata
  4229. ^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  4230. ``unpredictable`` metadata may be attached to any branch or switch
  4231. instruction. It can be used to express the unpredictability of control
  4232. flow. Similar to the llvm.expect intrinsic, it may be used to alter
  4233. optimizations related to compare and branch instructions. The metadata
  4234. is treated as a boolean value; if it exists, it signals that the branch
  4235. or switch that it is attached to is completely unpredictable.
  4236. .. _md_dereferenceable:
  4237. '``dereferenceable``' Metadata
  4238. ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  4239. The existence of the ``!dereferenceable`` metadata on the instruction
  4240. tells the optimizer that the value loaded is known to be dereferenceable.
  4241. The number of bytes known to be dereferenceable is specified by the integer
  4242. value in the metadata node. This is analogous to the ''dereferenceable''
  4243. attribute on parameters and return values.
  4244. .. _md_dereferenceable_or_null:
  4245. '``dereferenceable_or_null``' Metadata
  4246. ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  4247. The existence of the ``!dereferenceable_or_null`` metadata on the
  4248. instruction tells the optimizer that the value loaded is known to be either
  4249. dereferenceable or null.
  4250. The number of bytes known to be dereferenceable is specified by the integer
  4251. value in the metadata node. This is analogous to the ''dereferenceable_or_null''
  4252. attribute on parameters and return values.
  4253. .. _llvm.loop:
  4254. '``llvm.loop``'
  4255. ^^^^^^^^^^^^^^^
  4256. It is sometimes useful to attach information to loop constructs. Currently,
  4257. loop metadata is implemented as metadata attached to the branch instruction
  4258. in the loop latch block. This type of metadata refer to a metadata node that is
  4259. guaranteed to be separate for each loop. The loop identifier metadata is
  4260. specified with the name ``llvm.loop``.
  4261. The loop identifier metadata is implemented using a metadata that refers to
  4262. itself to avoid merging it with any other identifier metadata, e.g.,
  4263. during module linkage or function inlining. That is, each loop should refer
  4264. to their own identification metadata even if they reside in separate functions.
  4265. The following example contains loop identifier metadata for two separate loop
  4266. constructs:
  4267. .. code-block:: llvm
  4268. !0 = !{!0}
  4269. !1 = !{!1}
  4270. The loop identifier metadata can be used to specify additional
  4271. per-loop metadata. Any operands after the first operand can be treated
  4272. as user-defined metadata. For example the ``llvm.loop.unroll.count``
  4273. suggests an unroll factor to the loop unroller:
  4274. .. code-block:: llvm
  4275. br i1 %exitcond, label %._crit_edge, label %.lr.ph, !llvm.loop !0
  4276. ...
  4277. !0 = !{!0, !1}
  4278. !1 = !{!"llvm.loop.unroll.count", i32 4}
  4279. '``llvm.loop.disable_nonforced``'
  4280. ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  4281. This metadata disables all optional loop transformations unless
  4282. explicitly instructed using other transformation metadata such as
  4283. ``llvm.loop.unroll.enable``. That is, no heuristic will try to determine
  4284. whether a transformation is profitable. The purpose is to avoid that the
  4285. loop is transformed to a different loop before an explicitly requested
  4286. (forced) transformation is applied. For instance, loop fusion can make
  4287. other transformations impossible. Mandatory loop canonicalizations such
  4288. as loop rotation are still applied.
  4289. It is recommended to use this metadata in addition to any llvm.loop.*
  4290. transformation directive. Also, any loop should have at most one
  4291. directive applied to it (and a sequence of transformations built using
  4292. followup-attributes). Otherwise, which transformation will be applied
  4293. depends on implementation details such as the pass pipeline order.
  4294. See :ref:`transformation-metadata` for details.
  4295. '``llvm.loop.vectorize``' and '``llvm.loop.interleave``'
  4296. ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  4297. Metadata prefixed with ``llvm.loop.vectorize`` or ``llvm.loop.interleave`` are
  4298. used to control per-loop vectorization and interleaving parameters such as
  4299. vectorization width and interleave count. These metadata should be used in
  4300. conjunction with ``llvm.loop`` loop identification metadata. The
  4301. ``llvm.loop.vectorize`` and ``llvm.loop.interleave`` metadata are only
  4302. optimization hints and the optimizer will only interleave and vectorize loops if
  4303. it believes it is safe to do so. The ``llvm.loop.parallel_accesses`` metadata
  4304. which contains information about loop-carried memory dependencies can be helpful
  4305. in determining the safety of these transformations.
  4306. '``llvm.loop.interleave.count``' Metadata
  4307. ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  4308. This metadata suggests an interleave count to the loop interleaver.
  4309. The first operand is the string ``llvm.loop.interleave.count`` and the
  4310. second operand is an integer specifying the interleave count. For
  4311. example:
  4312. .. code-block:: llvm
  4313. !0 = !{!"llvm.loop.interleave.count", i32 4}
  4314. Note that setting ``llvm.loop.interleave.count`` to 1 disables interleaving
  4315. multiple iterations of the loop. If ``llvm.loop.interleave.count`` is set to 0
  4316. then the interleave count will be determined automatically.
  4317. '``llvm.loop.vectorize.enable``' Metadata
  4318. ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  4319. This metadata selectively enables or disables vectorization for the loop. The
  4320. first operand is the string ``llvm.loop.vectorize.enable`` and the second operand
  4321. is a bit. If the bit operand value is 1 vectorization is enabled. A value of
  4322. 0 disables vectorization:
  4323. .. code-block:: llvm
  4324. !0 = !{!"llvm.loop.vectorize.enable", i1 0}
  4325. !1 = !{!"llvm.loop.vectorize.enable", i1 1}
  4326. '``llvm.loop.vectorize.predicate.enable``' Metadata
  4327. ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  4328. This metadata selectively enables or disables creating predicated instructions
  4329. for the loop, which can enable folding of the scalar epilogue loop into the
  4330. main loop. The first operand is the string
  4331. ``llvm.loop.vectorize.predicate.enable`` and the second operand is a bit. If
  4332. the bit operand value is 1 vectorization is enabled. A value of 0 disables
  4333. vectorization:
  4334. .. code-block:: llvm
  4335. !0 = !{!"llvm.loop.vectorize.predicate.enable", i1 0}
  4336. !1 = !{!"llvm.loop.vectorize.predicate.enable", i1 1}
  4337. '``llvm.loop.vectorize.width``' Metadata
  4338. ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  4339. This metadata sets the target width of the vectorizer. The first
  4340. operand is the string ``llvm.loop.vectorize.width`` and the second
  4341. operand is an integer specifying the width. For example:
  4342. .. code-block:: llvm
  4343. !0 = !{!"llvm.loop.vectorize.width", i32 4}
  4344. Note that setting ``llvm.loop.vectorize.width`` to 1 disables
  4345. vectorization of the loop. If ``llvm.loop.vectorize.width`` is set to
  4346. 0 or if the loop does not have this metadata the width will be
  4347. determined automatically.
  4348. '``llvm.loop.vectorize.followup_vectorized``' Metadata
  4349. ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  4350. This metadata defines which loop attributes the vectorized loop will
  4351. have. See :ref:`transformation-metadata` for details.
  4352. '``llvm.loop.vectorize.followup_epilogue``' Metadata
  4353. ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  4354. This metadata defines which loop attributes the epilogue will have. The
  4355. epilogue is not vectorized and is executed when either the vectorized
  4356. loop is not known to preserve semantics (because e.g., it processes two
  4357. arrays that are found to alias by a runtime check) or for the last
  4358. iterations that do not fill a complete set of vector lanes. See
  4359. :ref:`Transformation Metadata <transformation-metadata>` for details.
  4360. '``llvm.loop.vectorize.followup_all``' Metadata
  4361. ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  4362. Attributes in the metadata will be added to both the vectorized and
  4363. epilogue loop.
  4364. See :ref:`Transformation Metadata <transformation-metadata>` for details.
  4365. '``llvm.loop.unroll``'
  4366. ^^^^^^^^^^^^^^^^^^^^^^
  4367. Metadata prefixed with ``llvm.loop.unroll`` are loop unrolling
  4368. optimization hints such as the unroll factor. ``llvm.loop.unroll``
  4369. metadata should be used in conjunction with ``llvm.loop`` loop
  4370. identification metadata. The ``llvm.loop.unroll`` metadata are only
  4371. optimization hints and the unrolling will only be performed if the
  4372. optimizer believes it is safe to do so.
  4373. '``llvm.loop.unroll.count``' Metadata
  4374. ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  4375. This metadata suggests an unroll factor to the loop unroller. The
  4376. first operand is the string ``llvm.loop.unroll.count`` and the second
  4377. operand is a positive integer specifying the unroll factor. For
  4378. example:
  4379. .. code-block:: llvm
  4380. !0 = !{!"llvm.loop.unroll.count", i32 4}
  4381. If the trip count of the loop is less than the unroll count the loop
  4382. will be partially unrolled.
  4383. '``llvm.loop.unroll.disable``' Metadata
  4384. ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  4385. This metadata disables loop unrolling. The metadata has a single operand
  4386. which is the string ``llvm.loop.unroll.disable``. For example:
  4387. .. code-block:: llvm
  4388. !0 = !{!"llvm.loop.unroll.disable"}
  4389. '``llvm.loop.unroll.runtime.disable``' Metadata
  4390. ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  4391. This metadata disables runtime loop unrolling. The metadata has a single
  4392. operand which is the string ``llvm.loop.unroll.runtime.disable``. For example:
  4393. .. code-block:: llvm
  4394. !0 = !{!"llvm.loop.unroll.runtime.disable"}
  4395. '``llvm.loop.unroll.enable``' Metadata
  4396. ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  4397. This metadata suggests that the loop should be fully unrolled if the trip count
  4398. is known at compile time and partially unrolled if the trip count is not known
  4399. at compile time. The metadata has a single operand which is the string
  4400. ``llvm.loop.unroll.enable``. For example:
  4401. .. code-block:: llvm
  4402. !0 = !{!"llvm.loop.unroll.enable"}
  4403. '``llvm.loop.unroll.full``' Metadata
  4404. ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  4405. This metadata suggests that the loop should be unrolled fully. The
  4406. metadata has a single operand which is the string ``llvm.loop.unroll.full``.
  4407. For example:
  4408. .. code-block:: llvm
  4409. !0 = !{!"llvm.loop.unroll.full"}
  4410. '``llvm.loop.unroll.followup``' Metadata
  4411. ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  4412. This metadata defines which loop attributes the unrolled loop will have.
  4413. See :ref:`Transformation Metadata <transformation-metadata>` for details.
  4414. '``llvm.loop.unroll.followup_remainder``' Metadata
  4415. ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  4416. This metadata defines which loop attributes the remainder loop after
  4417. partial/runtime unrolling will have. See
  4418. :ref:`Transformation Metadata <transformation-metadata>` for details.
  4419. '``llvm.loop.unroll_and_jam``'
  4420. ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  4421. This metadata is treated very similarly to the ``llvm.loop.unroll`` metadata
  4422. above, but affect the unroll and jam pass. In addition any loop with
  4423. ``llvm.loop.unroll`` metadata but no ``llvm.loop.unroll_and_jam`` metadata will
  4424. disable unroll and jam (so ``llvm.loop.unroll`` metadata will be left to the
  4425. unroller, plus ``llvm.loop.unroll.disable`` metadata will disable unroll and jam
  4426. too.)
  4427. The metadata for unroll and jam otherwise is the same as for ``unroll``.
  4428. ``llvm.loop.unroll_and_jam.enable``, ``llvm.loop.unroll_and_jam.disable`` and
  4429. ``llvm.loop.unroll_and_jam.count`` do the same as for unroll.
  4430. ``llvm.loop.unroll_and_jam.full`` is not supported. Again these are only hints
  4431. and the normal safety checks will still be performed.
  4432. '``llvm.loop.unroll_and_jam.count``' Metadata
  4433. ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  4434. This metadata suggests an unroll and jam factor to use, similarly to
  4435. ``llvm.loop.unroll.count``. The first operand is the string
  4436. ``llvm.loop.unroll_and_jam.count`` and the second operand is a positive integer
  4437. specifying the unroll factor. For example:
  4438. .. code-block:: llvm
  4439. !0 = !{!"llvm.loop.unroll_and_jam.count", i32 4}
  4440. If the trip count of the loop is less than the unroll count the loop
  4441. will be partially unroll and jammed.
  4442. '``llvm.loop.unroll_and_jam.disable``' Metadata
  4443. ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  4444. This metadata disables loop unroll and jamming. The metadata has a single
  4445. operand which is the string ``llvm.loop.unroll_and_jam.disable``. For example:
  4446. .. code-block:: llvm
  4447. !0 = !{!"llvm.loop.unroll_and_jam.disable"}
  4448. '``llvm.loop.unroll_and_jam.enable``' Metadata
  4449. ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  4450. This metadata suggests that the loop should be fully unroll and jammed if the
  4451. trip count is known at compile time and partially unrolled if the trip count is
  4452. not known at compile time. The metadata has a single operand which is the
  4453. string ``llvm.loop.unroll_and_jam.enable``. For example:
  4454. .. code-block:: llvm
  4455. !0 = !{!"llvm.loop.unroll_and_jam.enable"}
  4456. '``llvm.loop.unroll_and_jam.followup_outer``' Metadata
  4457. ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  4458. This metadata defines which loop attributes the outer unrolled loop will
  4459. have. See :ref:`Transformation Metadata <transformation-metadata>` for
  4460. details.
  4461. '``llvm.loop.unroll_and_jam.followup_inner``' Metadata
  4462. ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  4463. This metadata defines which loop attributes the inner jammed loop will
  4464. have. See :ref:`Transformation Metadata <transformation-metadata>` for
  4465. details.
  4466. '``llvm.loop.unroll_and_jam.followup_remainder_outer``' Metadata
  4467. ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  4468. This metadata defines which attributes the epilogue of the outer loop
  4469. will have. This loop is usually unrolled, meaning there is no such
  4470. loop. This attribute will be ignored in this case. See
  4471. :ref:`Transformation Metadata <transformation-metadata>` for details.
  4472. '``llvm.loop.unroll_and_jam.followup_remainder_inner``' Metadata
  4473. ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  4474. This metadata defines which attributes the inner loop of the epilogue
  4475. will have. The outer epilogue will usually be unrolled, meaning there
  4476. can be multiple inner remainder loops. See
  4477. :ref:`Transformation Metadata <transformation-metadata>` for details.
  4478. '``llvm.loop.unroll_and_jam.followup_all``' Metadata
  4479. ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  4480. Attributes specified in the metadata is added to all
  4481. ``llvm.loop.unroll_and_jam.*`` loops. See
  4482. :ref:`Transformation Metadata <transformation-metadata>` for details.
  4483. '``llvm.loop.licm_versioning.disable``' Metadata
  4484. ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  4485. This metadata indicates that the loop should not be versioned for the purpose
  4486. of enabling loop-invariant code motion (LICM). The metadata has a single operand
  4487. which is the string ``llvm.loop.licm_versioning.disable``. For example:
  4488. .. code-block:: llvm
  4489. !0 = !{!"llvm.loop.licm_versioning.disable"}
  4490. '``llvm.loop.distribute.enable``' Metadata
  4491. ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  4492. Loop distribution allows splitting a loop into multiple loops. Currently,
  4493. this is only performed if the entire loop cannot be vectorized due to unsafe
  4494. memory dependencies. The transformation will attempt to isolate the unsafe
  4495. dependencies into their own loop.
  4496. This metadata can be used to selectively enable or disable distribution of the
  4497. loop. The first operand is the string ``llvm.loop.distribute.enable`` and the
  4498. second operand is a bit. If the bit operand value is 1 distribution is
  4499. enabled. A value of 0 disables distribution:
  4500. .. code-block:: llvm
  4501. !0 = !{!"llvm.loop.distribute.enable", i1 0}
  4502. !1 = !{!"llvm.loop.distribute.enable", i1 1}
  4503. This metadata should be used in conjunction with ``llvm.loop`` loop
  4504. identification metadata.
  4505. '``llvm.loop.distribute.followup_coincident``' Metadata
  4506. ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  4507. This metadata defines which attributes extracted loops with no cyclic
  4508. dependencies will have (i.e. can be vectorized). See
  4509. :ref:`Transformation Metadata <transformation-metadata>` for details.
  4510. '``llvm.loop.distribute.followup_sequential``' Metadata
  4511. ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  4512. This metadata defines which attributes the isolated loops with unsafe
  4513. memory dependencies will have. See
  4514. :ref:`Transformation Metadata <transformation-metadata>` for details.
  4515. '``llvm.loop.distribute.followup_fallback``' Metadata
  4516. ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  4517. If loop versioning is necessary, this metadata defined the attributes
  4518. the non-distributed fallback version will have. See
  4519. :ref:`Transformation Metadata <transformation-metadata>` for details.
  4520. '``llvm.loop.distribute.followup_all``' Metadata
  4521. ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  4522. The attributes in this metadata is added to all followup loops of the
  4523. loop distribution pass. See
  4524. :ref:`Transformation Metadata <transformation-metadata>` for details.
  4525. '``llvm.licm.disable``' Metadata
  4526. ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  4527. This metadata indicates that loop-invariant code motion (LICM) should not be
  4528. performed on this loop. The metadata has a single operand which is the string
  4529. ``llvm.licm.disable``. For example:
  4530. .. code-block:: llvm
  4531. !0 = !{!"llvm.licm.disable"}
  4532. Note that although it operates per loop it isn't given the llvm.loop prefix
  4533. as it is not affected by the ``llvm.loop.disable_nonforced`` metadata.
  4534. '``llvm.access.group``' Metadata
  4535. ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  4536. ``llvm.access.group`` metadata can be attached to any instruction that
  4537. potentially accesses memory. It can point to a single distinct metadata
  4538. node, which we call access group. This node represents all memory access
  4539. instructions referring to it via ``llvm.access.group``. When an
  4540. instruction belongs to multiple access groups, it can also point to a
  4541. list of accesses groups, illustrated by the following example.
  4542. .. code-block:: llvm
  4543. %val = load i32, i32* %arrayidx, !llvm.access.group !0
  4544. ...
  4545. !0 = !{!1, !2}
  4546. !1 = distinct !{}
  4547. !2 = distinct !{}
  4548. It is illegal for the list node to be empty since it might be confused
  4549. with an access group.
  4550. The access group metadata node must be 'distinct' to avoid collapsing
  4551. multiple access groups by content. A access group metadata node must
  4552. always be empty which can be used to distinguish an access group
  4553. metadata node from a list of access groups. Being empty avoids the
  4554. situation that the content must be updated which, because metadata is
  4555. immutable by design, would required finding and updating all references
  4556. to the access group node.
  4557. The access group can be used to refer to a memory access instruction
  4558. without pointing to it directly (which is not possible in global
  4559. metadata). Currently, the only metadata making use of it is
  4560. ``llvm.loop.parallel_accesses``.
  4561. '``llvm.loop.parallel_accesses``' Metadata
  4562. ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  4563. The ``llvm.loop.parallel_accesses`` metadata refers to one or more
  4564. access group metadata nodes (see ``llvm.access.group``). It denotes that
  4565. no loop-carried memory dependence exist between it and other instructions
  4566. in the loop with this metadata.
  4567. Let ``m1`` and ``m2`` be two instructions that both have the
  4568. ``llvm.access.group`` metadata to the access group ``g1``, respectively
  4569. ``g2`` (which might be identical). If a loop contains both access groups
  4570. in its ``llvm.loop.parallel_accesses`` metadata, then the compiler can
  4571. assume that there is no dependency between ``m1`` and ``m2`` carried by
  4572. this loop. Instructions that belong to multiple access groups are
  4573. considered having this property if at least one of the access groups
  4574. matches the ``llvm.loop.parallel_accesses`` list.
  4575. If all memory-accessing instructions in a loop have
  4576. ``llvm.loop.parallel_accesses`` metadata that refers to that loop, then the
  4577. loop has no loop carried memory dependences and is considered to be a
  4578. parallel loop.
  4579. Note that if not all memory access instructions belong to an access
  4580. group referred to by ``llvm.loop.parallel_accesses``, then the loop must
  4581. not be considered trivially parallel. Additional
  4582. memory dependence analysis is required to make that determination. As a fail
  4583. safe mechanism, this causes loops that were originally parallel to be considered
  4584. sequential (if optimization passes that are unaware of the parallel semantics
  4585. insert new memory instructions into the loop body).
  4586. Example of a loop that is considered parallel due to its correct use of
  4587. both ``llvm.access.group`` and ``llvm.loop.parallel_accesses``
  4588. metadata types.
  4589. .. code-block:: llvm
  4590. for.body:
  4591. ...
  4592. %val0 = load i32, i32* %arrayidx, !llvm.access.group !1
  4593. ...
  4594. store i32 %val0, i32* %arrayidx1, !llvm.access.group !1
  4595. ...
  4596. br i1 %exitcond, label %for.end, label %for.body, !llvm.loop !0
  4597. for.end:
  4598. ...
  4599. !0 = distinct !{!0, !{!"llvm.loop.parallel_accesses", !1}}
  4600. !1 = distinct !{}
  4601. It is also possible to have nested parallel loops:
  4602. .. code-block:: llvm
  4603. outer.for.body:
  4604. ...
  4605. %val1 = load i32, i32* %arrayidx3, !llvm.access.group !4
  4606. ...
  4607. br label %inner.for.body
  4608. inner.for.body:
  4609. ...
  4610. %val0 = load i32, i32* %arrayidx1, !llvm.access.group !3
  4611. ...
  4612. store i32 %val0, i32* %arrayidx2, !llvm.access.group !3
  4613. ...
  4614. br i1 %exitcond, label %inner.for.end, label %inner.for.body, !llvm.loop !1
  4615. inner.for.end:
  4616. ...
  4617. store i32 %val1, i32* %arrayidx4, !llvm.access.group !4
  4618. ...
  4619. br i1 %exitcond, label %outer.for.end, label %outer.for.body, !llvm.loop !2
  4620. outer.for.end: ; preds = %for.body
  4621. ...
  4622. !1 = distinct !{!1, !{!"llvm.loop.parallel_accesses", !3}} ; metadata for the inner loop
  4623. !2 = distinct !{!2, !{!"llvm.loop.parallel_accesses", !3, !4}} ; metadata for the outer loop
  4624. !3 = distinct !{} ; access group for instructions in the inner loop (which are implicitly contained in outer loop as well)
  4625. !4 = distinct !{} ; access group for instructions in the outer, but not the inner loop
  4626. '``irr_loop``' Metadata
  4627. ^^^^^^^^^^^^^^^^^^^^^^^
  4628. ``irr_loop`` metadata may be attached to the terminator instruction of a basic
  4629. block that's an irreducible loop header (note that an irreducible loop has more
  4630. than once header basic blocks.) If ``irr_loop`` metadata is attached to the
  4631. terminator instruction of a basic block that is not really an irreducible loop
  4632. header, the behavior is undefined. The intent of this metadata is to improve the
  4633. accuracy of the block frequency propagation. For example, in the code below, the
  4634. block ``header0`` may have a loop header weight (relative to the other headers of
  4635. the irreducible loop) of 100:
  4636. .. code-block:: llvm
  4637. header0:
  4638. ...
  4639. br i1 %cmp, label %t1, label %t2, !irr_loop !0
  4640. ...
  4641. !0 = !{"loop_header_weight", i64 100}
  4642. Irreducible loop header weights are typically based on profile data.
  4643. .. _md_invariant.group:
  4644. '``invariant.group``' Metadata
  4645. ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  4646. The experimental ``invariant.group`` metadata may be attached to
  4647. ``load``/``store`` instructions referencing a single metadata with no entries.
  4648. The existence of the ``invariant.group`` metadata on the instruction tells
  4649. the optimizer that every ``load`` and ``store`` to the same pointer operand
  4650. can be assumed to load or store the same
  4651. value (but see the ``llvm.launder.invariant.group`` intrinsic which affects
  4652. when two pointers are considered the same). Pointers returned by bitcast or
  4653. getelementptr with only zero indices are considered the same.
  4654. Examples:
  4655. .. code-block:: llvm
  4656. @unknownPtr = external global i8
  4657. ...
  4658. %ptr = alloca i8
  4659. store i8 42, i8* %ptr, !invariant.group !0
  4660. call void @foo(i8* %ptr)
  4661. %a = load i8, i8* %ptr, !invariant.group !0 ; Can assume that value under %ptr didn't change
  4662. call void @foo(i8* %ptr)
  4663. %newPtr = call i8* @getPointer(i8* %ptr)
  4664. %c = load i8, i8* %newPtr, !invariant.group !0 ; Can't assume anything, because we only have information about %ptr
  4665. %unknownValue = load i8, i8* @unknownPtr
  4666. store i8 %unknownValue, i8* %ptr, !invariant.group !0 ; Can assume that %unknownValue == 42
  4667. call void @foo(i8* %ptr)
  4668. %newPtr2 = call i8* @llvm.launder.invariant.group(i8* %ptr)
  4669. %d = load i8, i8* %newPtr2, !invariant.group !0 ; Can't step through launder.invariant.group to get value of %ptr
  4670. ...
  4671. declare void @foo(i8*)
  4672. declare i8* @getPointer(i8*)
  4673. declare i8* @llvm.launder.invariant.group(i8*)
  4674. !0 = !{}
  4675. The invariant.group metadata must be dropped when replacing one pointer by
  4676. another based on aliasing information. This is because invariant.group is tied
  4677. to the SSA value of the pointer operand.
  4678. .. code-block:: llvm
  4679. %v = load i8, i8* %x, !invariant.group !0
  4680. ; if %x mustalias %y then we can replace the above instruction with
  4681. %v = load i8, i8* %y
  4682. Note that this is an experimental feature, which means that its semantics might
  4683. change in the future.
  4684. '``type``' Metadata
  4685. ^^^^^^^^^^^^^^^^^^^
  4686. See :doc:`TypeMetadata`.
  4687. '``associated``' Metadata
  4688. ^^^^^^^^^^^^^^^^^^^^^^^^^
  4689. The ``associated`` metadata may be attached to a global object
  4690. declaration with a single argument that references another global object.
  4691. This metadata prevents discarding of the global object in linker GC
  4692. unless the referenced object is also discarded. The linker support for
  4693. this feature is spotty. For best compatibility, globals carrying this
  4694. metadata may also:
  4695. - Be in a comdat with the referenced global.
  4696. - Be in @llvm.compiler.used.
  4697. - Have an explicit section with a name which is a valid C identifier.
  4698. It does not have any effect on non-ELF targets.
  4699. Example:
  4700. .. code-block:: text
  4701. $a = comdat any
  4702. @a = global i32 1, comdat $a
  4703. @b = internal global i32 2, comdat $a, section "abc", !associated !0
  4704. !0 = !{i32* @a}
  4705. '``prof``' Metadata
  4706. ^^^^^^^^^^^^^^^^^^^
  4707. The ``prof`` metadata is used to record profile data in the IR.
  4708. The first operand of the metadata node indicates the profile metadata
  4709. type. There are currently 3 types:
  4710. :ref:`branch_weights<prof_node_branch_weights>`,
  4711. :ref:`function_entry_count<prof_node_function_entry_count>`, and
  4712. :ref:`VP<prof_node_VP>`.
  4713. .. _prof_node_branch_weights:
  4714. branch_weights
  4715. """"""""""""""
  4716. Branch weight metadata attached to a branch, select, switch or call instruction
  4717. represents the likeliness of the associated branch being taken.
  4718. For more information, see :doc:`BranchWeightMetadata`.
  4719. .. _prof_node_function_entry_count:
  4720. function_entry_count
  4721. """"""""""""""""""""
  4722. Function entry count metadata can be attached to function definitions
  4723. to record the number of times the function is called. Used with BFI
  4724. information, it is also used to derive the basic block profile count.
  4725. For more information, see :doc:`BranchWeightMetadata`.
  4726. .. _prof_node_VP:
  4727. VP
  4728. ""
  4729. VP (value profile) metadata can be attached to instructions that have
  4730. value profile information. Currently this is indirect calls (where it
  4731. records the hottest callees) and calls to memory intrinsics such as memcpy,
  4732. memmove, and memset (where it records the hottest byte lengths).
  4733. Each VP metadata node contains "VP" string, then a uint32_t value for the value
  4734. profiling kind, a uint64_t value for the total number of times the instruction
  4735. is executed, followed by uint64_t value and execution count pairs.
  4736. The value profiling kind is 0 for indirect call targets and 1 for memory
  4737. operations. For indirect call targets, each profile value is a hash
  4738. of the callee function name, and for memory operations each value is the
  4739. byte length.
  4740. Note that the value counts do not need to add up to the total count
  4741. listed in the third operand (in practice only the top hottest values
  4742. are tracked and reported).
  4743. Indirect call example:
  4744. .. code-block:: llvm
  4745. call void %f(), !prof !1
  4746. !1 = !{!"VP", i32 0, i64 1600, i64 7651369219802541373, i64 1030, i64 -4377547752858689819, i64 410}
  4747. Note that the VP type is 0 (the second operand), which indicates this is
  4748. an indirect call value profile data. The third operand indicates that the
  4749. indirect call executed 1600 times. The 4th and 6th operands give the
  4750. hashes of the 2 hottest target functions' names (this is the same hash used
  4751. to represent function names in the profile database), and the 5th and 7th
  4752. operands give the execution count that each of the respective prior target
  4753. functions was called.
  4754. Module Flags Metadata
  4755. =====================
  4756. Information about the module as a whole is difficult to convey to LLVM's
  4757. subsystems. The LLVM IR isn't sufficient to transmit this information.
  4758. The ``llvm.module.flags`` named metadata exists in order to facilitate
  4759. this. These flags are in the form of key / value pairs --- much like a
  4760. dictionary --- making it easy for any subsystem who cares about a flag to
  4761. look it up.
  4762. The ``llvm.module.flags`` metadata contains a list of metadata triplets.
  4763. Each triplet has the following form:
  4764. - The first element is a *behavior* flag, which specifies the behavior
  4765. when two (or more) modules are merged together, and it encounters two
  4766. (or more) metadata with the same ID. The supported behaviors are
  4767. described below.
  4768. - The second element is a metadata string that is a unique ID for the
  4769. metadata. Each module may only have one flag entry for each unique ID (not
  4770. including entries with the **Require** behavior).
  4771. - The third element is the value of the flag.
  4772. When two (or more) modules are merged together, the resulting
  4773. ``llvm.module.flags`` metadata is the union of the modules' flags. That is, for
  4774. each unique metadata ID string, there will be exactly one entry in the merged
  4775. modules ``llvm.module.flags`` metadata table, and the value for that entry will
  4776. be determined by the merge behavior flag, as described below. The only exception
  4777. is that entries with the *Require* behavior are always preserved.
  4778. The following behaviors are supported:
  4779. .. list-table::
  4780. :header-rows: 1
  4781. :widths: 10 90
  4782. * - Value
  4783. - Behavior
  4784. * - 1
  4785. - **Error**
  4786. Emits an error if two values disagree, otherwise the resulting value
  4787. is that of the operands.
  4788. * - 2
  4789. - **Warning**
  4790. Emits a warning if two values disagree. The result value will be the
  4791. operand for the flag from the first module being linked.
  4792. * - 3
  4793. - **Require**
  4794. Adds a requirement that another module flag be present and have a
  4795. specified value after linking is performed. The value must be a
  4796. metadata pair, where the first element of the pair is the ID of the
  4797. module flag to be restricted, and the second element of the pair is
  4798. the value the module flag should be restricted to. This behavior can
  4799. be used to restrict the allowable results (via triggering of an
  4800. error) of linking IDs with the **Override** behavior.
  4801. * - 4
  4802. - **Override**
  4803. Uses the specified value, regardless of the behavior or value of the
  4804. other module. If both modules specify **Override**, but the values
  4805. differ, an error will be emitted.
  4806. * - 5
  4807. - **Append**
  4808. Appends the two values, which are required to be metadata nodes.
  4809. * - 6
  4810. - **AppendUnique**
  4811. Appends the two values, which are required to be metadata
  4812. nodes. However, duplicate entries in the second list are dropped
  4813. during the append operation.
  4814. * - 7
  4815. - **Max**
  4816. Takes the max of the two values, which are required to be integers.
  4817. It is an error for a particular unique flag ID to have multiple behaviors,
  4818. except in the case of **Require** (which adds restrictions on another metadata
  4819. value) or **Override**.
  4820. An example of module flags:
  4821. .. code-block:: llvm
  4822. !0 = !{ i32 1, !"foo", i32 1 }
  4823. !1 = !{ i32 4, !"bar", i32 37 }
  4824. !2 = !{ i32 2, !"qux", i32 42 }
  4825. !3 = !{ i32 3, !"qux",
  4826. !{
  4827. !"foo", i32 1
  4828. }
  4829. }
  4830. !llvm.module.flags = !{ !0, !1, !2, !3 }
  4831. - Metadata ``!0`` has the ID ``!"foo"`` and the value '1'. The behavior
  4832. if two or more ``!"foo"`` flags are seen is to emit an error if their
  4833. values are not equal.
  4834. - Metadata ``!1`` has the ID ``!"bar"`` and the value '37'. The
  4835. behavior if two or more ``!"bar"`` flags are seen is to use the value
  4836. '37'.
  4837. - Metadata ``!2`` has the ID ``!"qux"`` and the value '42'. The
  4838. behavior if two or more ``!"qux"`` flags are seen is to emit a
  4839. warning if their values are not equal.
  4840. - Metadata ``!3`` has the ID ``!"qux"`` and the value:
  4841. ::
  4842. !{ !"foo", i32 1 }
  4843. The behavior is to emit an error if the ``llvm.module.flags`` does not
  4844. contain a flag with the ID ``!"foo"`` that has the value '1' after linking is
  4845. performed.
  4846. Objective-C Garbage Collection Module Flags Metadata
  4847. ----------------------------------------------------
  4848. On the Mach-O platform, Objective-C stores metadata about garbage
  4849. collection in a special section called "image info". The metadata
  4850. consists of a version number and a bitmask specifying what types of
  4851. garbage collection are supported (if any) by the file. If two or more
  4852. modules are linked together their garbage collection metadata needs to
  4853. be merged rather than appended together.
  4854. The Objective-C garbage collection module flags metadata consists of the
  4855. following key-value pairs:
  4856. .. list-table::
  4857. :header-rows: 1
  4858. :widths: 30 70
  4859. * - Key
  4860. - Value
  4861. * - ``Objective-C Version``
  4862. - **[Required]** --- The Objective-C ABI version. Valid values are 1 and 2.
  4863. * - ``Objective-C Image Info Version``
  4864. - **[Required]** --- The version of the image info section. Currently
  4865. always 0.
  4866. * - ``Objective-C Image Info Section``
  4867. - **[Required]** --- The section to place the metadata. Valid values are
  4868. ``"__OBJC, __image_info, regular"`` for Objective-C ABI version 1, and
  4869. ``"__DATA,__objc_imageinfo, regular, no_dead_strip"`` for
  4870. Objective-C ABI version 2.
  4871. * - ``Objective-C Garbage Collection``
  4872. - **[Required]** --- Specifies whether garbage collection is supported or
  4873. not. Valid values are 0, for no garbage collection, and 2, for garbage
  4874. collection supported.
  4875. * - ``Objective-C GC Only``
  4876. - **[Optional]** --- Specifies that only garbage collection is supported.
  4877. If present, its value must be 6. This flag requires that the
  4878. ``Objective-C Garbage Collection`` flag have the value 2.
  4879. Some important flag interactions:
  4880. - If a module with ``Objective-C Garbage Collection`` set to 0 is
  4881. merged with a module with ``Objective-C Garbage Collection`` set to
  4882. 2, then the resulting module has the
  4883. ``Objective-C Garbage Collection`` flag set to 0.
  4884. - A module with ``Objective-C Garbage Collection`` set to 0 cannot be
  4885. merged with a module with ``Objective-C GC Only`` set to 6.
  4886. C type width Module Flags Metadata
  4887. ----------------------------------
  4888. The ARM backend emits a section into each generated object file describing the
  4889. options that it was compiled with (in a compiler-independent way) to prevent
  4890. linking incompatible objects, and to allow automatic library selection. Some
  4891. of these options are not visible at the IR level, namely wchar_t width and enum
  4892. width.
  4893. To pass this information to the backend, these options are encoded in module
  4894. flags metadata, using the following key-value pairs:
  4895. .. list-table::
  4896. :header-rows: 1
  4897. :widths: 30 70
  4898. * - Key
  4899. - Value
  4900. * - short_wchar
  4901. - * 0 --- sizeof(wchar_t) == 4
  4902. * 1 --- sizeof(wchar_t) == 2
  4903. * - short_enum
  4904. - * 0 --- Enums are at least as large as an ``int``.
  4905. * 1 --- Enums are stored in the smallest integer type which can
  4906. represent all of its values.
  4907. For example, the following metadata section specifies that the module was
  4908. compiled with a ``wchar_t`` width of 4 bytes, and the underlying type of an
  4909. enum is the smallest type which can represent all of its values::
  4910. !llvm.module.flags = !{!0, !1}
  4911. !0 = !{i32 1, !"short_wchar", i32 1}
  4912. !1 = !{i32 1, !"short_enum", i32 0}
  4913. Automatic Linker Flags Named Metadata
  4914. =====================================
  4915. Some targets support embedding of flags to the linker inside individual object
  4916. files. Typically this is used in conjunction with language extensions which
  4917. allow source files to contain linker command line options, and have these
  4918. automatically be transmitted to the linker via object files.
  4919. These flags are encoded in the IR using named metadata with the name
  4920. ``!llvm.linker.options``. Each operand is expected to be a metadata node
  4921. which should be a list of other metadata nodes, each of which should be a
  4922. list of metadata strings defining linker options.
  4923. For example, the following metadata section specifies two separate sets of
  4924. linker options, presumably to link against ``libz`` and the ``Cocoa``
  4925. framework::
  4926. !0 = !{ !"-lz" }
  4927. !1 = !{ !"-framework", !"Cocoa" }
  4928. !llvm.linker.options = !{ !0, !1 }
  4929. The metadata encoding as lists of lists of options, as opposed to a collapsed
  4930. list of options, is chosen so that the IR encoding can use multiple option
  4931. strings to specify e.g., a single library, while still having that specifier be
  4932. preserved as an atomic element that can be recognized by a target specific
  4933. assembly writer or object file emitter.
  4934. Each individual option is required to be either a valid option for the target's
  4935. linker, or an option that is reserved by the target specific assembly writer or
  4936. object file emitter. No other aspect of these options is defined by the IR.
  4937. Dependent Libs Named Metadata
  4938. =============================
  4939. Some targets support embedding of strings into object files to indicate
  4940. a set of libraries to add to the link. Typically this is used in conjunction
  4941. with language extensions which allow source files to explicitly declare the
  4942. libraries they depend on, and have these automatically be transmitted to the
  4943. linker via object files.
  4944. The list is encoded in the IR using named metadata with the name
  4945. ``!llvm.dependent-libraries``. Each operand is expected to be a metadata node
  4946. which should contain a single string operand.
  4947. For example, the following metadata section contains two library specfiers::
  4948. !0 = !{!"a library specifier"}
  4949. !1 = !{!"another library specifier"}
  4950. !llvm.dependent-libraries = !{ !0, !1 }
  4951. Each library specifier will be handled independently by the consuming linker.
  4952. The effect of the library specifiers are defined by the consuming linker.
  4953. .. _summary:
  4954. ThinLTO Summary
  4955. ===============
  4956. Compiling with `ThinLTO <https://clang.llvm.org/docs/ThinLTO.html>`_
  4957. causes the building of a compact summary of the module that is emitted into
  4958. the bitcode. The summary is emitted into the LLVM assembly and identified
  4959. in syntax by a caret ('``^``').
  4960. The summary is parsed into a bitcode output, along with the Module
  4961. IR, via the "``llvm-as``" tool. Tools that parse the Module IR for the purposes
  4962. of optimization (e.g. "``clang -x ir``" and "``opt``"), will ignore the
  4963. summary entries (just as they currently ignore summary entries in a bitcode
  4964. input file).
  4965. Eventually, the summary will be parsed into a ModuleSummaryIndex object under
  4966. the same conditions where summary index is currently built from bitcode.
  4967. Specifically, tools that test the Thin Link portion of a ThinLTO compile
  4968. (i.e. llvm-lto and llvm-lto2), or when parsing a combined index
  4969. for a distributed ThinLTO backend via clang's "``-fthinlto-index=<>``" flag
  4970. (this part is not yet implemented, use llvm-as to create a bitcode object
  4971. before feeding into thin link tools for now).
  4972. There are currently 3 types of summary entries in the LLVM assembly:
  4973. :ref:`module paths<module_path_summary>`,
  4974. :ref:`global values<gv_summary>`, and
  4975. :ref:`type identifiers<typeid_summary>`.
  4976. .. _module_path_summary:
  4977. Module Path Summary Entry
  4978. -------------------------
  4979. Each module path summary entry lists a module containing global values included
  4980. in the summary. For a single IR module there will be one such entry, but
  4981. in a combined summary index produced during the thin link, there will be
  4982. one module path entry per linked module with summary.
  4983. Example:
  4984. .. code-block:: text
  4985. ^0 = module: (path: "/path/to/file.o", hash: (2468601609, 1329373163, 1565878005, 638838075, 3148790418))
  4986. The ``path`` field is a string path to the bitcode file, and the ``hash``
  4987. field is the 160-bit SHA-1 hash of the IR bitcode contents, used for
  4988. incremental builds and caching.
  4989. .. _gv_summary:
  4990. Global Value Summary Entry
  4991. --------------------------
  4992. Each global value summary entry corresponds to a global value defined or
  4993. referenced by a summarized module.
  4994. Example:
  4995. .. code-block:: text
  4996. ^4 = gv: (name: "f"[, summaries: (Summary)[, (Summary)]*]?) ; guid = 14740650423002898831
  4997. For declarations, there will not be a summary list. For definitions, a
  4998. global value will contain a list of summaries, one per module containing
  4999. a definition. There can be multiple entries in a combined summary index
  5000. for symbols with weak linkage.
  5001. Each ``Summary`` format will depend on whether the global value is a
  5002. :ref:`function<function_summary>`, :ref:`variable<variable_summary>`, or
  5003. :ref:`alias<alias_summary>`.
  5004. .. _function_summary:
  5005. Function Summary
  5006. ^^^^^^^^^^^^^^^^
  5007. If the global value is a function, the ``Summary`` entry will look like:
  5008. .. code-block:: text
  5009. function: (module: ^0, flags: (linkage: external, notEligibleToImport: 0, live: 0, dsoLocal: 0), insts: 2[, FuncFlags]?[, Calls]?[, TypeIdInfo]?[, Refs]?
  5010. The ``module`` field includes the summary entry id for the module containing
  5011. this definition, and the ``flags`` field contains information such as
  5012. the linkage type, a flag indicating whether it is legal to import the
  5013. definition, whether it is globally live and whether the linker resolved it
  5014. to a local definition (the latter two are populated during the thin link).
  5015. The ``insts`` field contains the number of IR instructions in the function.
  5016. Finally, there are several optional fields: :ref:`FuncFlags<funcflags_summary>`,
  5017. :ref:`Calls<calls_summary>`, :ref:`TypeIdInfo<typeidinfo_summary>`,
  5018. :ref:`Refs<refs_summary>`.
  5019. .. _variable_summary:
  5020. Global Variable Summary
  5021. ^^^^^^^^^^^^^^^^^^^^^^^
  5022. If the global value is a variable, the ``Summary`` entry will look like:
  5023. .. code-block:: text
  5024. variable: (module: ^0, flags: (linkage: external, notEligibleToImport: 0, live: 0, dsoLocal: 0)[, Refs]?
  5025. The variable entry contains a subset of the fields in a
  5026. :ref:`function summary <function_summary>`, see the descriptions there.
  5027. .. _alias_summary:
  5028. Alias Summary
  5029. ^^^^^^^^^^^^^
  5030. If the global value is an alias, the ``Summary`` entry will look like:
  5031. .. code-block:: text
  5032. alias: (module: ^0, flags: (linkage: external, notEligibleToImport: 0, live: 0, dsoLocal: 0), aliasee: ^2)
  5033. The ``module`` and ``flags`` fields are as described for a
  5034. :ref:`function summary <function_summary>`. The ``aliasee`` field
  5035. contains a reference to the global value summary entry of the aliasee.
  5036. .. _funcflags_summary:
  5037. Function Flags
  5038. ^^^^^^^^^^^^^^
  5039. The optional ``FuncFlags`` field looks like:
  5040. .. code-block:: text
  5041. funcFlags: (readNone: 0, readOnly: 0, noRecurse: 0, returnDoesNotAlias: 0)
  5042. If unspecified, flags are assumed to hold the conservative ``false`` value of
  5043. ``0``.
  5044. .. _calls_summary:
  5045. Calls
  5046. ^^^^^
  5047. The optional ``Calls`` field looks like:
  5048. .. code-block:: text
  5049. calls: ((Callee)[, (Callee)]*)
  5050. where each ``Callee`` looks like:
  5051. .. code-block:: text
  5052. callee: ^1[, hotness: None]?[, relbf: 0]?
  5053. The ``callee`` refers to the summary entry id of the callee. At most one
  5054. of ``hotness`` (which can take the values ``Unknown``, ``Cold``, ``None``,
  5055. ``Hot``, and ``Critical``), and ``relbf`` (which holds the integer
  5056. branch frequency relative to the entry frequency, scaled down by 2^8)
  5057. may be specified. The defaults are ``Unknown`` and ``0``, respectively.
  5058. .. _refs_summary:
  5059. Refs
  5060. ^^^^
  5061. The optional ``Refs`` field looks like:
  5062. .. code-block:: text
  5063. refs: ((Ref)[, (Ref)]*)
  5064. where each ``Ref`` contains a reference to the summary id of the referenced
  5065. value (e.g. ``^1``).
  5066. .. _typeidinfo_summary:
  5067. TypeIdInfo
  5068. ^^^^^^^^^^
  5069. The optional ``TypeIdInfo`` field, used for
  5070. `Control Flow Integrity <http://clang.llvm.org/docs/ControlFlowIntegrity.html>`_,
  5071. looks like:
  5072. .. code-block:: text
  5073. typeIdInfo: [(TypeTests)]?[, (TypeTestAssumeVCalls)]?[, (TypeCheckedLoadVCalls)]?[, (TypeTestAssumeConstVCalls)]?[, (TypeCheckedLoadConstVCalls)]?
  5074. These optional fields have the following forms:
  5075. TypeTests
  5076. """""""""
  5077. .. code-block:: text
  5078. typeTests: (TypeIdRef[, TypeIdRef]*)
  5079. Where each ``TypeIdRef`` refers to a :ref:`type id<typeid_summary>`
  5080. by summary id or ``GUID``.
  5081. TypeTestAssumeVCalls
  5082. """"""""""""""""""""
  5083. .. code-block:: text
  5084. typeTestAssumeVCalls: (VFuncId[, VFuncId]*)
  5085. Where each VFuncId has the format:
  5086. .. code-block:: text
  5087. vFuncId: (TypeIdRef, offset: 16)
  5088. Where each ``TypeIdRef`` refers to a :ref:`type id<typeid_summary>`
  5089. by summary id or ``GUID`` preceded by a ``guid:`` tag.
  5090. TypeCheckedLoadVCalls
  5091. """""""""""""""""""""
  5092. .. code-block:: text
  5093. typeCheckedLoadVCalls: (VFuncId[, VFuncId]*)
  5094. Where each VFuncId has the format described for ``TypeTestAssumeVCalls``.
  5095. TypeTestAssumeConstVCalls
  5096. """""""""""""""""""""""""
  5097. .. code-block:: text
  5098. typeTestAssumeConstVCalls: (ConstVCall[, ConstVCall]*)
  5099. Where each ConstVCall has the format:
  5100. .. code-block:: text
  5101. (VFuncId, args: (Arg[, Arg]*))
  5102. and where each VFuncId has the format described for ``TypeTestAssumeVCalls``,
  5103. and each Arg is an integer argument number.
  5104. TypeCheckedLoadConstVCalls
  5105. """"""""""""""""""""""""""
  5106. .. code-block:: text
  5107. typeCheckedLoadConstVCalls: (ConstVCall[, ConstVCall]*)
  5108. Where each ConstVCall has the format described for
  5109. ``TypeTestAssumeConstVCalls``.
  5110. .. _typeid_summary:
  5111. Type ID Summary Entry
  5112. ---------------------
  5113. Each type id summary entry corresponds to a type identifier resolution
  5114. which is generated during the LTO link portion of the compile when building
  5115. with `Control Flow Integrity <http://clang.llvm.org/docs/ControlFlowIntegrity.html>`_,
  5116. so these are only present in a combined summary index.
  5117. Example:
  5118. .. code-block:: text
  5119. ^4 = typeid: (name: "_ZTS1A", summary: (typeTestRes: (kind: allOnes, sizeM1BitWidth: 7[, alignLog2: 0]?[, sizeM1: 0]?[, bitMask: 0]?[, inlineBits: 0]?)[, WpdResolutions]?)) ; guid = 7004155349499253778
  5120. The ``typeTestRes`` gives the type test resolution ``kind`` (which may
  5121. be ``unsat``, ``byteArray``, ``inline``, ``single``, or ``allOnes``), and
  5122. the ``size-1`` bit width. It is followed by optional flags, which default to 0,
  5123. and an optional WpdResolutions (whole program devirtualization resolution)
  5124. field that looks like:
  5125. .. code-block:: text
  5126. wpdResolutions: ((offset: 0, WpdRes)[, (offset: 1, WpdRes)]*
  5127. where each entry is a mapping from the given byte offset to the whole-program
  5128. devirtualization resolution WpdRes, that has one of the following formats:
  5129. .. code-block:: text
  5130. wpdRes: (kind: branchFunnel)
  5131. wpdRes: (kind: singleImpl, singleImplName: "_ZN1A1nEi")
  5132. wpdRes: (kind: indir)
  5133. Additionally, each wpdRes has an optional ``resByArg`` field, which
  5134. describes the resolutions for calls with all constant integer arguments:
  5135. .. code-block:: text
  5136. resByArg: (ResByArg[, ResByArg]*)
  5137. where ResByArg is:
  5138. .. code-block:: text
  5139. args: (Arg[, Arg]*), byArg: (kind: UniformRetVal[, info: 0][, byte: 0][, bit: 0])
  5140. Where the ``kind`` can be ``Indir``, ``UniformRetVal``, ``UniqueRetVal``
  5141. or ``VirtualConstProp``. The ``info`` field is only used if the kind
  5142. is ``UniformRetVal`` (indicates the uniform return value), or
  5143. ``UniqueRetVal`` (holds the return value associated with the unique vtable
  5144. (0 or 1)). The ``byte`` and ``bit`` fields are only used if the target does
  5145. not support the use of absolute symbols to store constants.
  5146. .. _intrinsicglobalvariables:
  5147. Intrinsic Global Variables
  5148. ==========================
  5149. LLVM has a number of "magic" global variables that contain data that
  5150. affect code generation or other IR semantics. These are documented here.
  5151. All globals of this sort should have a section specified as
  5152. "``llvm.metadata``". This section and all globals that start with
  5153. "``llvm.``" are reserved for use by LLVM.
  5154. .. _gv_llvmused:
  5155. The '``llvm.used``' Global Variable
  5156. -----------------------------------
  5157. The ``@llvm.used`` global is an array which has
  5158. :ref:`appending linkage <linkage_appending>`. This array contains a list of
  5159. pointers to named global variables, functions and aliases which may optionally
  5160. have a pointer cast formed of bitcast or getelementptr. For example, a legal
  5161. use of it is:
  5162. .. code-block:: llvm
  5163. @X = global i8 4
  5164. @Y = global i32 123
  5165. @llvm.used = appending global [2 x i8*] [
  5166. i8* @X,
  5167. i8* bitcast (i32* @Y to i8*)
  5168. ], section "llvm.metadata"
  5169. If a symbol appears in the ``@llvm.used`` list, then the compiler, assembler,
  5170. and linker are required to treat the symbol as if there is a reference to the
  5171. symbol that it cannot see (which is why they have to be named). For example, if
  5172. a variable has internal linkage and no references other than that from the
  5173. ``@llvm.used`` list, it cannot be deleted. This is commonly used to represent
  5174. references from inline asms and other things the compiler cannot "see", and
  5175. corresponds to "``attribute((used))``" in GNU C.
  5176. On some targets, the code generator must emit a directive to the
  5177. assembler or object file to prevent the assembler and linker from
  5178. molesting the symbol.
  5179. .. _gv_llvmcompilerused:
  5180. The '``llvm.compiler.used``' Global Variable
  5181. --------------------------------------------
  5182. The ``@llvm.compiler.used`` directive is the same as the ``@llvm.used``
  5183. directive, except that it only prevents the compiler from touching the
  5184. symbol. On targets that support it, this allows an intelligent linker to
  5185. optimize references to the symbol without being impeded as it would be
  5186. by ``@llvm.used``.
  5187. This is a rare construct that should only be used in rare circumstances,
  5188. and should not be exposed to source languages.
  5189. .. _gv_llvmglobalctors:
  5190. The '``llvm.global_ctors``' Global Variable
  5191. -------------------------------------------
  5192. .. code-block:: llvm
  5193. %0 = type { i32, void ()*, i8* }
  5194. @llvm.global_ctors = appending global [1 x %0] [%0 { i32 65535, void ()* @ctor, i8* @data }]
  5195. The ``@llvm.global_ctors`` array contains a list of constructor
  5196. functions, priorities, and an associated global or function.
  5197. The functions referenced by this array will be called in ascending order
  5198. of priority (i.e. lowest first) when the module is loaded. The order of
  5199. functions with the same priority is not defined.
  5200. If the third field is non-null, and points to a global variable
  5201. or function, the initializer function will only run if the associated
  5202. data from the current module is not discarded.
  5203. .. _llvmglobaldtors:
  5204. The '``llvm.global_dtors``' Global Variable
  5205. -------------------------------------------
  5206. .. code-block:: llvm
  5207. %0 = type { i32, void ()*, i8* }
  5208. @llvm.global_dtors = appending global [1 x %0] [%0 { i32 65535, void ()* @dtor, i8* @data }]
  5209. The ``@llvm.global_dtors`` array contains a list of destructor
  5210. functions, priorities, and an associated global or function.
  5211. The functions referenced by this array will be called in descending
  5212. order of priority (i.e. highest first) when the module is unloaded. The
  5213. order of functions with the same priority is not defined.
  5214. If the third field is non-null, and points to a global variable
  5215. or function, the destructor function will only run if the associated
  5216. data from the current module is not discarded.
  5217. Instruction Reference
  5218. =====================
  5219. The LLVM instruction set consists of several different classifications
  5220. of instructions: :ref:`terminator instructions <terminators>`, :ref:`binary
  5221. instructions <binaryops>`, :ref:`bitwise binary
  5222. instructions <bitwiseops>`, :ref:`memory instructions <memoryops>`, and
  5223. :ref:`other instructions <otherops>`.
  5224. .. _terminators:
  5225. Terminator Instructions
  5226. -----------------------
  5227. As mentioned :ref:`previously <functionstructure>`, every basic block in a
  5228. program ends with a "Terminator" instruction, which indicates which
  5229. block should be executed after the current block is finished. These
  5230. terminator instructions typically yield a '``void``' value: they produce
  5231. control flow, not values (the one exception being the
  5232. ':ref:`invoke <i_invoke>`' instruction).
  5233. The terminator instructions are: ':ref:`ret <i_ret>`',
  5234. ':ref:`br <i_br>`', ':ref:`switch <i_switch>`',
  5235. ':ref:`indirectbr <i_indirectbr>`', ':ref:`invoke <i_invoke>`',
  5236. ':ref:`callbr <i_callbr>`'
  5237. ':ref:`resume <i_resume>`', ':ref:`catchswitch <i_catchswitch>`',
  5238. ':ref:`catchret <i_catchret>`',
  5239. ':ref:`cleanupret <i_cleanupret>`',
  5240. and ':ref:`unreachable <i_unreachable>`'.
  5241. .. _i_ret:
  5242. '``ret``' Instruction
  5243. ^^^^^^^^^^^^^^^^^^^^^
  5244. Syntax:
  5245. """""""
  5246. ::
  5247. ret <type> <value> ; Return a value from a non-void function
  5248. ret void ; Return from void function
  5249. Overview:
  5250. """""""""
  5251. The '``ret``' instruction is used to return control flow (and optionally
  5252. a value) from a function back to the caller.
  5253. There are two forms of the '``ret``' instruction: one that returns a
  5254. value and then causes control flow, and one that just causes control
  5255. flow to occur.
  5256. Arguments:
  5257. """"""""""
  5258. The '``ret``' instruction optionally accepts a single argument, the
  5259. return value. The type of the return value must be a ':ref:`first
  5260. class <t_firstclass>`' type.
  5261. A function is not :ref:`well formed <wellformed>` if it has a non-void
  5262. return type and contains a '``ret``' instruction with no return value or
  5263. a return value with a type that does not match its type, or if it has a
  5264. void return type and contains a '``ret``' instruction with a return
  5265. value.
  5266. Semantics:
  5267. """"""""""
  5268. When the '``ret``' instruction is executed, control flow returns back to
  5269. the calling function's context. If the caller is a
  5270. ":ref:`call <i_call>`" instruction, execution continues at the
  5271. instruction after the call. If the caller was an
  5272. ":ref:`invoke <i_invoke>`" instruction, execution continues at the
  5273. beginning of the "normal" destination block. If the instruction returns
  5274. a value, that value shall set the call or invoke instruction's return
  5275. value.
  5276. Example:
  5277. """"""""
  5278. .. code-block:: llvm
  5279. ret i32 5 ; Return an integer value of 5
  5280. ret void ; Return from a void function
  5281. ret { i32, i8 } { i32 4, i8 2 } ; Return a struct of values 4 and 2
  5282. .. _i_br:
  5283. '``br``' Instruction
  5284. ^^^^^^^^^^^^^^^^^^^^
  5285. Syntax:
  5286. """""""
  5287. ::
  5288. br i1 <cond>, label <iftrue>, label <iffalse>
  5289. br label <dest> ; Unconditional branch
  5290. Overview:
  5291. """""""""
  5292. The '``br``' instruction is used to cause control flow to transfer to a
  5293. different basic block in the current function. There are two forms of
  5294. this instruction, corresponding to a conditional branch and an
  5295. unconditional branch.
  5296. Arguments:
  5297. """"""""""
  5298. The conditional branch form of the '``br``' instruction takes a single
  5299. '``i1``' value and two '``label``' values. The unconditional form of the
  5300. '``br``' instruction takes a single '``label``' value as a target.
  5301. Semantics:
  5302. """"""""""
  5303. Upon execution of a conditional '``br``' instruction, the '``i1``'
  5304. argument is evaluated. If the value is ``true``, control flows to the
  5305. '``iftrue``' ``label`` argument. If "cond" is ``false``, control flows
  5306. to the '``iffalse``' ``label`` argument.
  5307. Example:
  5308. """"""""
  5309. .. code-block:: llvm
  5310. Test:
  5311. %cond = icmp eq i32 %a, %b
  5312. br i1 %cond, label %IfEqual, label %IfUnequal
  5313. IfEqual:
  5314. ret i32 1
  5315. IfUnequal:
  5316. ret i32 0
  5317. .. _i_switch:
  5318. '``switch``' Instruction
  5319. ^^^^^^^^^^^^^^^^^^^^^^^^
  5320. Syntax:
  5321. """""""
  5322. ::
  5323. switch <intty> <value>, label <defaultdest> [ <intty> <val>, label <dest> ... ]
  5324. Overview:
  5325. """""""""
  5326. The '``switch``' instruction is used to transfer control flow to one of
  5327. several different places. It is a generalization of the '``br``'
  5328. instruction, allowing a branch to occur to one of many possible
  5329. destinations.
  5330. Arguments:
  5331. """"""""""
  5332. The '``switch``' instruction uses three parameters: an integer
  5333. comparison value '``value``', a default '``label``' destination, and an
  5334. array of pairs of comparison value constants and '``label``'s. The table
  5335. is not allowed to contain duplicate constant entries.
  5336. Semantics:
  5337. """"""""""
  5338. The ``switch`` instruction specifies a table of values and destinations.
  5339. When the '``switch``' instruction is executed, this table is searched
  5340. for the given value. If the value is found, control flow is transferred
  5341. to the corresponding destination; otherwise, control flow is transferred
  5342. to the default destination.
  5343. Implementation:
  5344. """""""""""""""
  5345. Depending on properties of the target machine and the particular
  5346. ``switch`` instruction, this instruction may be code generated in
  5347. different ways. For example, it could be generated as a series of
  5348. chained conditional branches or with a lookup table.
  5349. Example:
  5350. """"""""
  5351. .. code-block:: llvm
  5352. ; Emulate a conditional br instruction
  5353. %Val = zext i1 %value to i32
  5354. switch i32 %Val, label %truedest [ i32 0, label %falsedest ]
  5355. ; Emulate an unconditional br instruction
  5356. switch i32 0, label %dest [ ]
  5357. ; Implement a jump table:
  5358. switch i32 %val, label %otherwise [ i32 0, label %onzero
  5359. i32 1, label %onone
  5360. i32 2, label %ontwo ]
  5361. .. _i_indirectbr:
  5362. '``indirectbr``' Instruction
  5363. ^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  5364. Syntax:
  5365. """""""
  5366. ::
  5367. indirectbr <somety>* <address>, [ label <dest1>, label <dest2>, ... ]
  5368. Overview:
  5369. """""""""
  5370. The '``indirectbr``' instruction implements an indirect branch to a
  5371. label within the current function, whose address is specified by
  5372. "``address``". Address must be derived from a
  5373. :ref:`blockaddress <blockaddress>` constant.
  5374. Arguments:
  5375. """"""""""
  5376. The '``address``' argument is the address of the label to jump to. The
  5377. rest of the arguments indicate the full set of possible destinations
  5378. that the address may point to. Blocks are allowed to occur multiple
  5379. times in the destination list, though this isn't particularly useful.
  5380. This destination list is required so that dataflow analysis has an
  5381. accurate understanding of the CFG.
  5382. Semantics:
  5383. """"""""""
  5384. Control transfers to the block specified in the address argument. All
  5385. possible destination blocks must be listed in the label list, otherwise
  5386. this instruction has undefined behavior. This implies that jumps to
  5387. labels defined in other functions have undefined behavior as well.
  5388. Implementation:
  5389. """""""""""""""
  5390. This is typically implemented with a jump through a register.
  5391. Example:
  5392. """"""""
  5393. .. code-block:: llvm
  5394. indirectbr i8* %Addr, [ label %bb1, label %bb2, label %bb3 ]
  5395. .. _i_invoke:
  5396. '``invoke``' Instruction
  5397. ^^^^^^^^^^^^^^^^^^^^^^^^
  5398. Syntax:
  5399. """""""
  5400. ::
  5401. <result> = invoke [cconv] [ret attrs] [addrspace(<num>)] <ty>|<fnty> <fnptrval>(<function args>) [fn attrs]
  5402. [operand bundles] to label <normal label> unwind label <exception label>
  5403. Overview:
  5404. """""""""
  5405. The '``invoke``' instruction causes control to transfer to a specified
  5406. function, with the possibility of control flow transfer to either the
  5407. '``normal``' label or the '``exception``' label. If the callee function
  5408. returns with the "``ret``" instruction, control flow will return to the
  5409. "normal" label. If the callee (or any indirect callees) returns via the
  5410. ":ref:`resume <i_resume>`" instruction or other exception handling
  5411. mechanism, control is interrupted and continued at the dynamically
  5412. nearest "exception" label.
  5413. The '``exception``' label is a `landing
  5414. pad <ExceptionHandling.html#overview>`_ for the exception. As such,
  5415. '``exception``' label is required to have the
  5416. ":ref:`landingpad <i_landingpad>`" instruction, which contains the
  5417. information about the behavior of the program after unwinding happens,
  5418. as its first non-PHI instruction. The restrictions on the
  5419. "``landingpad``" instruction's tightly couples it to the "``invoke``"
  5420. instruction, so that the important information contained within the
  5421. "``landingpad``" instruction can't be lost through normal code motion.
  5422. Arguments:
  5423. """"""""""
  5424. This instruction requires several arguments:
  5425. #. The optional "cconv" marker indicates which :ref:`calling
  5426. convention <callingconv>` the call should use. If none is
  5427. specified, the call defaults to using C calling conventions.
  5428. #. The optional :ref:`Parameter Attributes <paramattrs>` list for return
  5429. values. Only '``zeroext``', '``signext``', and '``inreg``' attributes
  5430. are valid here.
  5431. #. The optional addrspace attribute can be used to indicate the address space
  5432. of the called function. If it is not specified, the program address space
  5433. from the :ref:`datalayout string<langref_datalayout>` will be used.
  5434. #. '``ty``': the type of the call instruction itself which is also the
  5435. type of the return value. Functions that return no value are marked
  5436. ``void``.
  5437. #. '``fnty``': shall be the signature of the function being invoked. The
  5438. argument types must match the types implied by this signature. This
  5439. type can be omitted if the function is not varargs.
  5440. #. '``fnptrval``': An LLVM value containing a pointer to a function to
  5441. be invoked. In most cases, this is a direct function invocation, but
  5442. indirect ``invoke``'s are just as possible, calling an arbitrary pointer
  5443. to function value.
  5444. #. '``function args``': argument list whose types match the function
  5445. signature argument types and parameter attributes. All arguments must
  5446. be of :ref:`first class <t_firstclass>` type. If the function signature
  5447. indicates the function accepts a variable number of arguments, the
  5448. extra arguments can be specified.
  5449. #. '``normal label``': the label reached when the called function
  5450. executes a '``ret``' instruction.
  5451. #. '``exception label``': the label reached when a callee returns via
  5452. the :ref:`resume <i_resume>` instruction or other exception handling
  5453. mechanism.
  5454. #. The optional :ref:`function attributes <fnattrs>` list.
  5455. #. The optional :ref:`operand bundles <opbundles>` list.
  5456. Semantics:
  5457. """"""""""
  5458. This instruction is designed to operate as a standard '``call``'
  5459. instruction in most regards. The primary difference is that it
  5460. establishes an association with a label, which is used by the runtime
  5461. library to unwind the stack.
  5462. This instruction is used in languages with destructors to ensure that
  5463. proper cleanup is performed in the case of either a ``longjmp`` or a
  5464. thrown exception. Additionally, this is important for implementation of
  5465. '``catch``' clauses in high-level languages that support them.
  5466. For the purposes of the SSA form, the definition of the value returned
  5467. by the '``invoke``' instruction is deemed to occur on the edge from the
  5468. current block to the "normal" label. If the callee unwinds then no
  5469. return value is available.
  5470. Example:
  5471. """"""""
  5472. .. code-block:: llvm
  5473. %retval = invoke i32 @Test(i32 15) to label %Continue
  5474. unwind label %TestCleanup ; i32:retval set
  5475. %retval = invoke coldcc i32 %Testfnptr(i32 15) to label %Continue
  5476. unwind label %TestCleanup ; i32:retval set
  5477. .. _i_callbr:
  5478. '``callbr``' Instruction
  5479. ^^^^^^^^^^^^^^^^^^^^^^^^
  5480. Syntax:
  5481. """""""
  5482. ::
  5483. <result> = callbr [cconv] [ret attrs] [addrspace(<num>)] <ty>|<fnty> <fnptrval>(<function args>) [fn attrs]
  5484. [operand bundles] to label <normal label> or jump [other labels]
  5485. Overview:
  5486. """""""""
  5487. The '``callbr``' instruction causes control to transfer to a specified
  5488. function, with the possibility of control flow transfer to either the
  5489. '``normal``' label or one of the '``other``' labels.
  5490. This instruction should only be used to implement the "goto" feature of gcc
  5491. style inline assembly. Any other usage is an error in the IR verifier.
  5492. Arguments:
  5493. """"""""""
  5494. This instruction requires several arguments:
  5495. #. The optional "cconv" marker indicates which :ref:`calling
  5496. convention <callingconv>` the call should use. If none is
  5497. specified, the call defaults to using C calling conventions.
  5498. #. The optional :ref:`Parameter Attributes <paramattrs>` list for return
  5499. values. Only '``zeroext``', '``signext``', and '``inreg``' attributes
  5500. are valid here.
  5501. #. The optional addrspace attribute can be used to indicate the address space
  5502. of the called function. If it is not specified, the program address space
  5503. from the :ref:`datalayout string<langref_datalayout>` will be used.
  5504. #. '``ty``': the type of the call instruction itself which is also the
  5505. type of the return value. Functions that return no value are marked
  5506. ``void``.
  5507. #. '``fnty``': shall be the signature of the function being called. The
  5508. argument types must match the types implied by this signature. This
  5509. type can be omitted if the function is not varargs.
  5510. #. '``fnptrval``': An LLVM value containing a pointer to a function to
  5511. be called. In most cases, this is a direct function call, but
  5512. indirect ``callbr``'s are just as possible, calling an arbitrary pointer
  5513. to function value.
  5514. #. '``function args``': argument list whose types match the function
  5515. signature argument types and parameter attributes. All arguments must
  5516. be of :ref:`first class <t_firstclass>` type. If the function signature
  5517. indicates the function accepts a variable number of arguments, the
  5518. extra arguments can be specified.
  5519. #. '``normal label``': the label reached when the called function
  5520. executes a '``ret``' instruction.
  5521. #. '``other labels``': the labels reached when a callee transfers control
  5522. to a location other than the normal '``normal label``'
  5523. #. The optional :ref:`function attributes <fnattrs>` list.
  5524. #. The optional :ref:`operand bundles <opbundles>` list.
  5525. Semantics:
  5526. """"""""""
  5527. This instruction is designed to operate as a standard '``call``'
  5528. instruction in most regards. The primary difference is that it
  5529. establishes an association with additional labels to define where control
  5530. flow goes after the call.
  5531. The only use of this today is to implement the "goto" feature of gcc inline
  5532. assembly where additional labels can be provided as locations for the inline
  5533. assembly to jump to.
  5534. Example:
  5535. """"""""
  5536. .. code-block:: text
  5537. callbr void asm "", "r,x"(i32 %x, i8 *blockaddress(@foo, %fail))
  5538. to label %normal or jump [label %fail]
  5539. .. _i_resume:
  5540. '``resume``' Instruction
  5541. ^^^^^^^^^^^^^^^^^^^^^^^^
  5542. Syntax:
  5543. """""""
  5544. ::
  5545. resume <type> <value>
  5546. Overview:
  5547. """""""""
  5548. The '``resume``' instruction is a terminator instruction that has no
  5549. successors.
  5550. Arguments:
  5551. """"""""""
  5552. The '``resume``' instruction requires one argument, which must have the
  5553. same type as the result of any '``landingpad``' instruction in the same
  5554. function.
  5555. Semantics:
  5556. """"""""""
  5557. The '``resume``' instruction resumes propagation of an existing
  5558. (in-flight) exception whose unwinding was interrupted with a
  5559. :ref:`landingpad <i_landingpad>` instruction.
  5560. Example:
  5561. """"""""
  5562. .. code-block:: llvm
  5563. resume { i8*, i32 } %exn
  5564. .. _i_catchswitch:
  5565. '``catchswitch``' Instruction
  5566. ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  5567. Syntax:
  5568. """""""
  5569. ::
  5570. <resultval> = catchswitch within <parent> [ label <handler1>, label <handler2>, ... ] unwind to caller
  5571. <resultval> = catchswitch within <parent> [ label <handler1>, label <handler2>, ... ] unwind label <default>
  5572. Overview:
  5573. """""""""
  5574. The '``catchswitch``' instruction is used by `LLVM's exception handling system
  5575. <ExceptionHandling.html#overview>`_ to describe the set of possible catch handlers
  5576. that may be executed by the :ref:`EH personality routine <personalityfn>`.
  5577. Arguments:
  5578. """"""""""
  5579. The ``parent`` argument is the token of the funclet that contains the
  5580. ``catchswitch`` instruction. If the ``catchswitch`` is not inside a funclet,
  5581. this operand may be the token ``none``.
  5582. The ``default`` argument is the label of another basic block beginning with
  5583. either a ``cleanuppad`` or ``catchswitch`` instruction. This unwind destination
  5584. must be a legal target with respect to the ``parent`` links, as described in
  5585. the `exception handling documentation\ <ExceptionHandling.html#wineh-constraints>`_.
  5586. The ``handlers`` are a nonempty list of successor blocks that each begin with a
  5587. :ref:`catchpad <i_catchpad>` instruction.
  5588. Semantics:
  5589. """"""""""
  5590. Executing this instruction transfers control to one of the successors in
  5591. ``handlers``, if appropriate, or continues to unwind via the unwind label if
  5592. present.
  5593. The ``catchswitch`` is both a terminator and a "pad" instruction, meaning that
  5594. it must be both the first non-phi instruction and last instruction in the basic
  5595. block. Therefore, it must be the only non-phi instruction in the block.
  5596. Example:
  5597. """"""""
  5598. .. code-block:: text
  5599. dispatch1:
  5600. %cs1 = catchswitch within none [label %handler0, label %handler1] unwind to caller
  5601. dispatch2:
  5602. %cs2 = catchswitch within %parenthandler [label %handler0] unwind label %cleanup
  5603. .. _i_catchret:
  5604. '``catchret``' Instruction
  5605. ^^^^^^^^^^^^^^^^^^^^^^^^^^
  5606. Syntax:
  5607. """""""
  5608. ::
  5609. catchret from <token> to label <normal>
  5610. Overview:
  5611. """""""""
  5612. The '``catchret``' instruction is a terminator instruction that has a
  5613. single successor.
  5614. Arguments:
  5615. """"""""""
  5616. The first argument to a '``catchret``' indicates which ``catchpad`` it
  5617. exits. It must be a :ref:`catchpad <i_catchpad>`.
  5618. The second argument to a '``catchret``' specifies where control will
  5619. transfer to next.
  5620. Semantics:
  5621. """"""""""
  5622. The '``catchret``' instruction ends an existing (in-flight) exception whose
  5623. unwinding was interrupted with a :ref:`catchpad <i_catchpad>` instruction. The
  5624. :ref:`personality function <personalityfn>` gets a chance to execute arbitrary
  5625. code to, for example, destroy the active exception. Control then transfers to
  5626. ``normal``.
  5627. The ``token`` argument must be a token produced by a ``catchpad`` instruction.
  5628. If the specified ``catchpad`` is not the most-recently-entered not-yet-exited
  5629. funclet pad (as described in the `EH documentation\ <ExceptionHandling.html#wineh-constraints>`_),
  5630. the ``catchret``'s behavior is undefined.
  5631. Example:
  5632. """"""""
  5633. .. code-block:: text
  5634. catchret from %catch label %continue
  5635. .. _i_cleanupret:
  5636. '``cleanupret``' Instruction
  5637. ^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  5638. Syntax:
  5639. """""""
  5640. ::
  5641. cleanupret from <value> unwind label <continue>
  5642. cleanupret from <value> unwind to caller
  5643. Overview:
  5644. """""""""
  5645. The '``cleanupret``' instruction is a terminator instruction that has
  5646. an optional successor.
  5647. Arguments:
  5648. """"""""""
  5649. The '``cleanupret``' instruction requires one argument, which indicates
  5650. which ``cleanuppad`` it exits, and must be a :ref:`cleanuppad <i_cleanuppad>`.
  5651. If the specified ``cleanuppad`` is not the most-recently-entered not-yet-exited
  5652. funclet pad (as described in the `EH documentation\ <ExceptionHandling.html#wineh-constraints>`_),
  5653. the ``cleanupret``'s behavior is undefined.
  5654. The '``cleanupret``' instruction also has an optional successor, ``continue``,
  5655. which must be the label of another basic block beginning with either a
  5656. ``cleanuppad`` or ``catchswitch`` instruction. This unwind destination must
  5657. be a legal target with respect to the ``parent`` links, as described in the
  5658. `exception handling documentation\ <ExceptionHandling.html#wineh-constraints>`_.
  5659. Semantics:
  5660. """"""""""
  5661. The '``cleanupret``' instruction indicates to the
  5662. :ref:`personality function <personalityfn>` that one
  5663. :ref:`cleanuppad <i_cleanuppad>` it transferred control to has ended.
  5664. It transfers control to ``continue`` or unwinds out of the function.
  5665. Example:
  5666. """"""""
  5667. .. code-block:: text
  5668. cleanupret from %cleanup unwind to caller
  5669. cleanupret from %cleanup unwind label %continue
  5670. .. _i_unreachable:
  5671. '``unreachable``' Instruction
  5672. ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  5673. Syntax:
  5674. """""""
  5675. ::
  5676. unreachable
  5677. Overview:
  5678. """""""""
  5679. The '``unreachable``' instruction has no defined semantics. This
  5680. instruction is used to inform the optimizer that a particular portion of
  5681. the code is not reachable. This can be used to indicate that the code
  5682. after a no-return function cannot be reached, and other facts.
  5683. Semantics:
  5684. """"""""""
  5685. The '``unreachable``' instruction has no defined semantics.
  5686. .. _unaryops:
  5687. Unary Operations
  5688. -----------------
  5689. Unary operators require a single operand, execute an operation on
  5690. it, and produce a single value. The operand might represent multiple
  5691. data, as is the case with the :ref:`vector <t_vector>` data type. The
  5692. result value has the same type as its operand.
  5693. .. _i_fneg:
  5694. '``fneg``' Instruction
  5695. ^^^^^^^^^^^^^^^^^^^^^^
  5696. Syntax:
  5697. """""""
  5698. ::
  5699. <result> = fneg [fast-math flags]* <ty> <op1> ; yields ty:result
  5700. Overview:
  5701. """""""""
  5702. The '``fneg``' instruction returns the negation of its operand.
  5703. Arguments:
  5704. """"""""""
  5705. The argument to the '``fneg``' instruction must be a
  5706. :ref:`floating-point <t_floating>` or :ref:`vector <t_vector>` of
  5707. floating-point values.
  5708. Semantics:
  5709. """"""""""
  5710. The value produced is a copy of the operand with its sign bit flipped.
  5711. This instruction can also take any number of :ref:`fast-math
  5712. flags <fastmath>`, which are optimization hints to enable otherwise
  5713. unsafe floating-point optimizations:
  5714. Example:
  5715. """"""""
  5716. .. code-block:: text
  5717. <result> = fneg float %val ; yields float:result = -%var
  5718. .. _binaryops:
  5719. Binary Operations
  5720. -----------------
  5721. Binary operators are used to do most of the computation in a program.
  5722. They require two operands of the same type, execute an operation on
  5723. them, and produce a single value. The operands might represent multiple
  5724. data, as is the case with the :ref:`vector <t_vector>` data type. The
  5725. result value has the same type as its operands.
  5726. There are several different binary operators:
  5727. .. _i_add:
  5728. '``add``' Instruction
  5729. ^^^^^^^^^^^^^^^^^^^^^
  5730. Syntax:
  5731. """""""
  5732. ::
  5733. <result> = add <ty> <op1>, <op2> ; yields ty:result
  5734. <result> = add nuw <ty> <op1>, <op2> ; yields ty:result
  5735. <result> = add nsw <ty> <op1>, <op2> ; yields ty:result
  5736. <result> = add nuw nsw <ty> <op1>, <op2> ; yields ty:result
  5737. Overview:
  5738. """""""""
  5739. The '``add``' instruction returns the sum of its two operands.
  5740. Arguments:
  5741. """"""""""
  5742. The two arguments to the '``add``' instruction must be
  5743. :ref:`integer <t_integer>` or :ref:`vector <t_vector>` of integer values. Both
  5744. arguments must have identical types.
  5745. Semantics:
  5746. """"""""""
  5747. The value produced is the integer sum of the two operands.
  5748. If the sum has unsigned overflow, the result returned is the
  5749. mathematical result modulo 2\ :sup:`n`\ , where n is the bit width of
  5750. the result.
  5751. Because LLVM integers use a two's complement representation, this
  5752. instruction is appropriate for both signed and unsigned integers.
  5753. ``nuw`` and ``nsw`` stand for "No Unsigned Wrap" and "No Signed Wrap",
  5754. respectively. If the ``nuw`` and/or ``nsw`` keywords are present, the
  5755. result value of the ``add`` is a :ref:`poison value <poisonvalues>` if
  5756. unsigned and/or signed overflow, respectively, occurs.
  5757. Example:
  5758. """"""""
  5759. .. code-block:: text
  5760. <result> = add i32 4, %var ; yields i32:result = 4 + %var
  5761. .. _i_fadd:
  5762. '``fadd``' Instruction
  5763. ^^^^^^^^^^^^^^^^^^^^^^
  5764. Syntax:
  5765. """""""
  5766. ::
  5767. <result> = fadd [fast-math flags]* <ty> <op1>, <op2> ; yields ty:result
  5768. Overview:
  5769. """""""""
  5770. The '``fadd``' instruction returns the sum of its two operands.
  5771. Arguments:
  5772. """"""""""
  5773. The two arguments to the '``fadd``' instruction must be
  5774. :ref:`floating-point <t_floating>` or :ref:`vector <t_vector>` of
  5775. floating-point values. Both arguments must have identical types.
  5776. Semantics:
  5777. """"""""""
  5778. The value produced is the floating-point sum of the two operands.
  5779. This instruction is assumed to execute in the default :ref:`floating-point
  5780. environment <floatenv>`.
  5781. This instruction can also take any number of :ref:`fast-math
  5782. flags <fastmath>`, which are optimization hints to enable otherwise
  5783. unsafe floating-point optimizations:
  5784. Example:
  5785. """"""""
  5786. .. code-block:: text
  5787. <result> = fadd float 4.0, %var ; yields float:result = 4.0 + %var
  5788. '``sub``' Instruction
  5789. ^^^^^^^^^^^^^^^^^^^^^
  5790. Syntax:
  5791. """""""
  5792. ::
  5793. <result> = sub <ty> <op1>, <op2> ; yields ty:result
  5794. <result> = sub nuw <ty> <op1>, <op2> ; yields ty:result
  5795. <result> = sub nsw <ty> <op1>, <op2> ; yields ty:result
  5796. <result> = sub nuw nsw <ty> <op1>, <op2> ; yields ty:result
  5797. Overview:
  5798. """""""""
  5799. The '``sub``' instruction returns the difference of its two operands.
  5800. Note that the '``sub``' instruction is used to represent the '``neg``'
  5801. instruction present in most other intermediate representations.
  5802. Arguments:
  5803. """"""""""
  5804. The two arguments to the '``sub``' instruction must be
  5805. :ref:`integer <t_integer>` or :ref:`vector <t_vector>` of integer values. Both
  5806. arguments must have identical types.
  5807. Semantics:
  5808. """"""""""
  5809. The value produced is the integer difference of the two operands.
  5810. If the difference has unsigned overflow, the result returned is the
  5811. mathematical result modulo 2\ :sup:`n`\ , where n is the bit width of
  5812. the result.
  5813. Because LLVM integers use a two's complement representation, this
  5814. instruction is appropriate for both signed and unsigned integers.
  5815. ``nuw`` and ``nsw`` stand for "No Unsigned Wrap" and "No Signed Wrap",
  5816. respectively. If the ``nuw`` and/or ``nsw`` keywords are present, the
  5817. result value of the ``sub`` is a :ref:`poison value <poisonvalues>` if
  5818. unsigned and/or signed overflow, respectively, occurs.
  5819. Example:
  5820. """"""""
  5821. .. code-block:: text
  5822. <result> = sub i32 4, %var ; yields i32:result = 4 - %var
  5823. <result> = sub i32 0, %val ; yields i32:result = -%var
  5824. .. _i_fsub:
  5825. '``fsub``' Instruction
  5826. ^^^^^^^^^^^^^^^^^^^^^^
  5827. Syntax:
  5828. """""""
  5829. ::
  5830. <result> = fsub [fast-math flags]* <ty> <op1>, <op2> ; yields ty:result
  5831. Overview:
  5832. """""""""
  5833. The '``fsub``' instruction returns the difference of its two operands.
  5834. Arguments:
  5835. """"""""""
  5836. The two arguments to the '``fsub``' instruction must be
  5837. :ref:`floating-point <t_floating>` or :ref:`vector <t_vector>` of
  5838. floating-point values. Both arguments must have identical types.
  5839. Semantics:
  5840. """"""""""
  5841. The value produced is the floating-point difference of the two operands.
  5842. This instruction is assumed to execute in the default :ref:`floating-point
  5843. environment <floatenv>`.
  5844. This instruction can also take any number of :ref:`fast-math
  5845. flags <fastmath>`, which are optimization hints to enable otherwise
  5846. unsafe floating-point optimizations:
  5847. Example:
  5848. """"""""
  5849. .. code-block:: text
  5850. <result> = fsub float 4.0, %var ; yields float:result = 4.0 - %var
  5851. <result> = fsub float -0.0, %val ; yields float:result = -%var
  5852. '``mul``' Instruction
  5853. ^^^^^^^^^^^^^^^^^^^^^
  5854. Syntax:
  5855. """""""
  5856. ::
  5857. <result> = mul <ty> <op1>, <op2> ; yields ty:result
  5858. <result> = mul nuw <ty> <op1>, <op2> ; yields ty:result
  5859. <result> = mul nsw <ty> <op1>, <op2> ; yields ty:result
  5860. <result> = mul nuw nsw <ty> <op1>, <op2> ; yields ty:result
  5861. Overview:
  5862. """""""""
  5863. The '``mul``' instruction returns the product of its two operands.
  5864. Arguments:
  5865. """"""""""
  5866. The two arguments to the '``mul``' instruction must be
  5867. :ref:`integer <t_integer>` or :ref:`vector <t_vector>` of integer values. Both
  5868. arguments must have identical types.
  5869. Semantics:
  5870. """"""""""
  5871. The value produced is the integer product of the two operands.
  5872. If the result of the multiplication has unsigned overflow, the result
  5873. returned is the mathematical result modulo 2\ :sup:`n`\ , where n is the
  5874. bit width of the result.
  5875. Because LLVM integers use a two's complement representation, and the
  5876. result is the same width as the operands, this instruction returns the
  5877. correct result for both signed and unsigned integers. If a full product
  5878. (e.g. ``i32`` * ``i32`` -> ``i64``) is needed, the operands should be
  5879. sign-extended or zero-extended as appropriate to the width of the full
  5880. product.
  5881. ``nuw`` and ``nsw`` stand for "No Unsigned Wrap" and "No Signed Wrap",
  5882. respectively. If the ``nuw`` and/or ``nsw`` keywords are present, the
  5883. result value of the ``mul`` is a :ref:`poison value <poisonvalues>` if
  5884. unsigned and/or signed overflow, respectively, occurs.
  5885. Example:
  5886. """"""""
  5887. .. code-block:: text
  5888. <result> = mul i32 4, %var ; yields i32:result = 4 * %var
  5889. .. _i_fmul:
  5890. '``fmul``' Instruction
  5891. ^^^^^^^^^^^^^^^^^^^^^^
  5892. Syntax:
  5893. """""""
  5894. ::
  5895. <result> = fmul [fast-math flags]* <ty> <op1>, <op2> ; yields ty:result
  5896. Overview:
  5897. """""""""
  5898. The '``fmul``' instruction returns the product of its two operands.
  5899. Arguments:
  5900. """"""""""
  5901. The two arguments to the '``fmul``' instruction must be
  5902. :ref:`floating-point <t_floating>` or :ref:`vector <t_vector>` of
  5903. floating-point values. Both arguments must have identical types.
  5904. Semantics:
  5905. """"""""""
  5906. The value produced is the floating-point product of the two operands.
  5907. This instruction is assumed to execute in the default :ref:`floating-point
  5908. environment <floatenv>`.
  5909. This instruction can also take any number of :ref:`fast-math
  5910. flags <fastmath>`, which are optimization hints to enable otherwise
  5911. unsafe floating-point optimizations:
  5912. Example:
  5913. """"""""
  5914. .. code-block:: text
  5915. <result> = fmul float 4.0, %var ; yields float:result = 4.0 * %var
  5916. '``udiv``' Instruction
  5917. ^^^^^^^^^^^^^^^^^^^^^^
  5918. Syntax:
  5919. """""""
  5920. ::
  5921. <result> = udiv <ty> <op1>, <op2> ; yields ty:result
  5922. <result> = udiv exact <ty> <op1>, <op2> ; yields ty:result
  5923. Overview:
  5924. """""""""
  5925. The '``udiv``' instruction returns the quotient of its two operands.
  5926. Arguments:
  5927. """"""""""
  5928. The two arguments to the '``udiv``' instruction must be
  5929. :ref:`integer <t_integer>` or :ref:`vector <t_vector>` of integer values. Both
  5930. arguments must have identical types.
  5931. Semantics:
  5932. """"""""""
  5933. The value produced is the unsigned integer quotient of the two operands.
  5934. Note that unsigned integer division and signed integer division are
  5935. distinct operations; for signed integer division, use '``sdiv``'.
  5936. Division by zero is undefined behavior. For vectors, if any element
  5937. of the divisor is zero, the operation has undefined behavior.
  5938. If the ``exact`` keyword is present, the result value of the ``udiv`` is
  5939. a :ref:`poison value <poisonvalues>` if %op1 is not a multiple of %op2 (as
  5940. such, "((a udiv exact b) mul b) == a").
  5941. Example:
  5942. """"""""
  5943. .. code-block:: text
  5944. <result> = udiv i32 4, %var ; yields i32:result = 4 / %var
  5945. '``sdiv``' Instruction
  5946. ^^^^^^^^^^^^^^^^^^^^^^
  5947. Syntax:
  5948. """""""
  5949. ::
  5950. <result> = sdiv <ty> <op1>, <op2> ; yields ty:result
  5951. <result> = sdiv exact <ty> <op1>, <op2> ; yields ty:result
  5952. Overview:
  5953. """""""""
  5954. The '``sdiv``' instruction returns the quotient of its two operands.
  5955. Arguments:
  5956. """"""""""
  5957. The two arguments to the '``sdiv``' instruction must be
  5958. :ref:`integer <t_integer>` or :ref:`vector <t_vector>` of integer values. Both
  5959. arguments must have identical types.
  5960. Semantics:
  5961. """"""""""
  5962. The value produced is the signed integer quotient of the two operands
  5963. rounded towards zero.
  5964. Note that signed integer division and unsigned integer division are
  5965. distinct operations; for unsigned integer division, use '``udiv``'.
  5966. Division by zero is undefined behavior. For vectors, if any element
  5967. of the divisor is zero, the operation has undefined behavior.
  5968. Overflow also leads to undefined behavior; this is a rare case, but can
  5969. occur, for example, by doing a 32-bit division of -2147483648 by -1.
  5970. If the ``exact`` keyword is present, the result value of the ``sdiv`` is
  5971. a :ref:`poison value <poisonvalues>` if the result would be rounded.
  5972. Example:
  5973. """"""""
  5974. .. code-block:: text
  5975. <result> = sdiv i32 4, %var ; yields i32:result = 4 / %var
  5976. .. _i_fdiv:
  5977. '``fdiv``' Instruction
  5978. ^^^^^^^^^^^^^^^^^^^^^^
  5979. Syntax:
  5980. """""""
  5981. ::
  5982. <result> = fdiv [fast-math flags]* <ty> <op1>, <op2> ; yields ty:result
  5983. Overview:
  5984. """""""""
  5985. The '``fdiv``' instruction returns the quotient of its two operands.
  5986. Arguments:
  5987. """"""""""
  5988. The two arguments to the '``fdiv``' instruction must be
  5989. :ref:`floating-point <t_floating>` or :ref:`vector <t_vector>` of
  5990. floating-point values. Both arguments must have identical types.
  5991. Semantics:
  5992. """"""""""
  5993. The value produced is the floating-point quotient of the two operands.
  5994. This instruction is assumed to execute in the default :ref:`floating-point
  5995. environment <floatenv>`.
  5996. This instruction can also take any number of :ref:`fast-math
  5997. flags <fastmath>`, which are optimization hints to enable otherwise
  5998. unsafe floating-point optimizations:
  5999. Example:
  6000. """"""""
  6001. .. code-block:: text
  6002. <result> = fdiv float 4.0, %var ; yields float:result = 4.0 / %var
  6003. '``urem``' Instruction
  6004. ^^^^^^^^^^^^^^^^^^^^^^
  6005. Syntax:
  6006. """""""
  6007. ::
  6008. <result> = urem <ty> <op1>, <op2> ; yields ty:result
  6009. Overview:
  6010. """""""""
  6011. The '``urem``' instruction returns the remainder from the unsigned
  6012. division of its two arguments.
  6013. Arguments:
  6014. """"""""""
  6015. The two arguments to the '``urem``' instruction must be
  6016. :ref:`integer <t_integer>` or :ref:`vector <t_vector>` of integer values. Both
  6017. arguments must have identical types.
  6018. Semantics:
  6019. """"""""""
  6020. This instruction returns the unsigned integer *remainder* of a division.
  6021. This instruction always performs an unsigned division to get the
  6022. remainder.
  6023. Note that unsigned integer remainder and signed integer remainder are
  6024. distinct operations; for signed integer remainder, use '``srem``'.
  6025. Taking the remainder of a division by zero is undefined behavior.
  6026. For vectors, if any element of the divisor is zero, the operation has
  6027. undefined behavior.
  6028. Example:
  6029. """"""""
  6030. .. code-block:: text
  6031. <result> = urem i32 4, %var ; yields i32:result = 4 % %var
  6032. '``srem``' Instruction
  6033. ^^^^^^^^^^^^^^^^^^^^^^
  6034. Syntax:
  6035. """""""
  6036. ::
  6037. <result> = srem <ty> <op1>, <op2> ; yields ty:result
  6038. Overview:
  6039. """""""""
  6040. The '``srem``' instruction returns the remainder from the signed
  6041. division of its two operands. This instruction can also take
  6042. :ref:`vector <t_vector>` versions of the values in which case the elements
  6043. must be integers.
  6044. Arguments:
  6045. """"""""""
  6046. The two arguments to the '``srem``' instruction must be
  6047. :ref:`integer <t_integer>` or :ref:`vector <t_vector>` of integer values. Both
  6048. arguments must have identical types.
  6049. Semantics:
  6050. """"""""""
  6051. This instruction returns the *remainder* of a division (where the result
  6052. is either zero or has the same sign as the dividend, ``op1``), not the
  6053. *modulo* operator (where the result is either zero or has the same sign
  6054. as the divisor, ``op2``) of a value. For more information about the
  6055. difference, see `The Math
  6056. Forum <http://mathforum.org/dr.math/problems/anne.4.28.99.html>`_. For a
  6057. table of how this is implemented in various languages, please see
  6058. `Wikipedia: modulo
  6059. operation <http://en.wikipedia.org/wiki/Modulo_operation>`_.
  6060. Note that signed integer remainder and unsigned integer remainder are
  6061. distinct operations; for unsigned integer remainder, use '``urem``'.
  6062. Taking the remainder of a division by zero is undefined behavior.
  6063. For vectors, if any element of the divisor is zero, the operation has
  6064. undefined behavior.
  6065. Overflow also leads to undefined behavior; this is a rare case, but can
  6066. occur, for example, by taking the remainder of a 32-bit division of
  6067. -2147483648 by -1. (The remainder doesn't actually overflow, but this
  6068. rule lets srem be implemented using instructions that return both the
  6069. result of the division and the remainder.)
  6070. Example:
  6071. """"""""
  6072. .. code-block:: text
  6073. <result> = srem i32 4, %var ; yields i32:result = 4 % %var
  6074. .. _i_frem:
  6075. '``frem``' Instruction
  6076. ^^^^^^^^^^^^^^^^^^^^^^
  6077. Syntax:
  6078. """""""
  6079. ::
  6080. <result> = frem [fast-math flags]* <ty> <op1>, <op2> ; yields ty:result
  6081. Overview:
  6082. """""""""
  6083. The '``frem``' instruction returns the remainder from the division of
  6084. its two operands.
  6085. Arguments:
  6086. """"""""""
  6087. The two arguments to the '``frem``' instruction must be
  6088. :ref:`floating-point <t_floating>` or :ref:`vector <t_vector>` of
  6089. floating-point values. Both arguments must have identical types.
  6090. Semantics:
  6091. """"""""""
  6092. The value produced is the floating-point remainder of the two operands.
  6093. This is the same output as a libm '``fmod``' function, but without any
  6094. possibility of setting ``errno``. The remainder has the same sign as the
  6095. dividend.
  6096. This instruction is assumed to execute in the default :ref:`floating-point
  6097. environment <floatenv>`.
  6098. This instruction can also take any number of :ref:`fast-math
  6099. flags <fastmath>`, which are optimization hints to enable otherwise
  6100. unsafe floating-point optimizations:
  6101. Example:
  6102. """"""""
  6103. .. code-block:: text
  6104. <result> = frem float 4.0, %var ; yields float:result = 4.0 % %var
  6105. .. _bitwiseops:
  6106. Bitwise Binary Operations
  6107. -------------------------
  6108. Bitwise binary operators are used to do various forms of bit-twiddling
  6109. in a program. They are generally very efficient instructions and can
  6110. commonly be strength reduced from other instructions. They require two
  6111. operands of the same type, execute an operation on them, and produce a
  6112. single value. The resulting value is the same type as its operands.
  6113. '``shl``' Instruction
  6114. ^^^^^^^^^^^^^^^^^^^^^
  6115. Syntax:
  6116. """""""
  6117. ::
  6118. <result> = shl <ty> <op1>, <op2> ; yields ty:result
  6119. <result> = shl nuw <ty> <op1>, <op2> ; yields ty:result
  6120. <result> = shl nsw <ty> <op1>, <op2> ; yields ty:result
  6121. <result> = shl nuw nsw <ty> <op1>, <op2> ; yields ty:result
  6122. Overview:
  6123. """""""""
  6124. The '``shl``' instruction returns the first operand shifted to the left
  6125. a specified number of bits.
  6126. Arguments:
  6127. """"""""""
  6128. Both arguments to the '``shl``' instruction must be the same
  6129. :ref:`integer <t_integer>` or :ref:`vector <t_vector>` of integer type.
  6130. '``op2``' is treated as an unsigned value.
  6131. Semantics:
  6132. """"""""""
  6133. The value produced is ``op1`` \* 2\ :sup:`op2` mod 2\ :sup:`n`,
  6134. where ``n`` is the width of the result. If ``op2`` is (statically or
  6135. dynamically) equal to or larger than the number of bits in
  6136. ``op1``, this instruction returns a :ref:`poison value <poisonvalues>`.
  6137. If the arguments are vectors, each vector element of ``op1`` is shifted
  6138. by the corresponding shift amount in ``op2``.
  6139. If the ``nuw`` keyword is present, then the shift produces a poison
  6140. value if it shifts out any non-zero bits.
  6141. If the ``nsw`` keyword is present, then the shift produces a poison
  6142. value if it shifts out any bits that disagree with the resultant sign bit.
  6143. Example:
  6144. """"""""
  6145. .. code-block:: text
  6146. <result> = shl i32 4, %var ; yields i32: 4 << %var
  6147. <result> = shl i32 4, 2 ; yields i32: 16
  6148. <result> = shl i32 1, 10 ; yields i32: 1024
  6149. <result> = shl i32 1, 32 ; undefined
  6150. <result> = shl <2 x i32> < i32 1, i32 1>, < i32 1, i32 2> ; yields: result=<2 x i32> < i32 2, i32 4>
  6151. '``lshr``' Instruction
  6152. ^^^^^^^^^^^^^^^^^^^^^^
  6153. Syntax:
  6154. """""""
  6155. ::
  6156. <result> = lshr <ty> <op1>, <op2> ; yields ty:result
  6157. <result> = lshr exact <ty> <op1>, <op2> ; yields ty:result
  6158. Overview:
  6159. """""""""
  6160. The '``lshr``' instruction (logical shift right) returns the first
  6161. operand shifted to the right a specified number of bits with zero fill.
  6162. Arguments:
  6163. """"""""""
  6164. Both arguments to the '``lshr``' instruction must be the same
  6165. :ref:`integer <t_integer>` or :ref:`vector <t_vector>` of integer type.
  6166. '``op2``' is treated as an unsigned value.
  6167. Semantics:
  6168. """"""""""
  6169. This instruction always performs a logical shift right operation. The
  6170. most significant bits of the result will be filled with zero bits after
  6171. the shift. If ``op2`` is (statically or dynamically) equal to or larger
  6172. than the number of bits in ``op1``, this instruction returns a :ref:`poison
  6173. value <poisonvalues>`. If the arguments are vectors, each vector element
  6174. of ``op1`` is shifted by the corresponding shift amount in ``op2``.
  6175. If the ``exact`` keyword is present, the result value of the ``lshr`` is
  6176. a poison value if any of the bits shifted out are non-zero.
  6177. Example:
  6178. """"""""
  6179. .. code-block:: text
  6180. <result> = lshr i32 4, 1 ; yields i32:result = 2
  6181. <result> = lshr i32 4, 2 ; yields i32:result = 1
  6182. <result> = lshr i8 4, 3 ; yields i8:result = 0
  6183. <result> = lshr i8 -2, 1 ; yields i8:result = 0x7F
  6184. <result> = lshr i32 1, 32 ; undefined
  6185. <result> = lshr <2 x i32> < i32 -2, i32 4>, < i32 1, i32 2> ; yields: result=<2 x i32> < i32 0x7FFFFFFF, i32 1>
  6186. '``ashr``' Instruction
  6187. ^^^^^^^^^^^^^^^^^^^^^^
  6188. Syntax:
  6189. """""""
  6190. ::
  6191. <result> = ashr <ty> <op1>, <op2> ; yields ty:result
  6192. <result> = ashr exact <ty> <op1>, <op2> ; yields ty:result
  6193. Overview:
  6194. """""""""
  6195. The '``ashr``' instruction (arithmetic shift right) returns the first
  6196. operand shifted to the right a specified number of bits with sign
  6197. extension.
  6198. Arguments:
  6199. """"""""""
  6200. Both arguments to the '``ashr``' instruction must be the same
  6201. :ref:`integer <t_integer>` or :ref:`vector <t_vector>` of integer type.
  6202. '``op2``' is treated as an unsigned value.
  6203. Semantics:
  6204. """"""""""
  6205. This instruction always performs an arithmetic shift right operation,
  6206. The most significant bits of the result will be filled with the sign bit
  6207. of ``op1``. If ``op2`` is (statically or dynamically) equal to or larger
  6208. than the number of bits in ``op1``, this instruction returns a :ref:`poison
  6209. value <poisonvalues>`. If the arguments are vectors, each vector element
  6210. of ``op1`` is shifted by the corresponding shift amount in ``op2``.
  6211. If the ``exact`` keyword is present, the result value of the ``ashr`` is
  6212. a poison value if any of the bits shifted out are non-zero.
  6213. Example:
  6214. """"""""
  6215. .. code-block:: text
  6216. <result> = ashr i32 4, 1 ; yields i32:result = 2
  6217. <result> = ashr i32 4, 2 ; yields i32:result = 1
  6218. <result> = ashr i8 4, 3 ; yields i8:result = 0
  6219. <result> = ashr i8 -2, 1 ; yields i8:result = -1
  6220. <result> = ashr i32 1, 32 ; undefined
  6221. <result> = ashr <2 x i32> < i32 -2, i32 4>, < i32 1, i32 3> ; yields: result=<2 x i32> < i32 -1, i32 0>
  6222. '``and``' Instruction
  6223. ^^^^^^^^^^^^^^^^^^^^^
  6224. Syntax:
  6225. """""""
  6226. ::
  6227. <result> = and <ty> <op1>, <op2> ; yields ty:result
  6228. Overview:
  6229. """""""""
  6230. The '``and``' instruction returns the bitwise logical and of its two
  6231. operands.
  6232. Arguments:
  6233. """"""""""
  6234. The two arguments to the '``and``' instruction must be
  6235. :ref:`integer <t_integer>` or :ref:`vector <t_vector>` of integer values. Both
  6236. arguments must have identical types.
  6237. Semantics:
  6238. """"""""""
  6239. The truth table used for the '``and``' instruction is:
  6240. +-----+-----+-----+
  6241. | In0 | In1 | Out |
  6242. +-----+-----+-----+
  6243. | 0 | 0 | 0 |
  6244. +-----+-----+-----+
  6245. | 0 | 1 | 0 |
  6246. +-----+-----+-----+
  6247. | 1 | 0 | 0 |
  6248. +-----+-----+-----+
  6249. | 1 | 1 | 1 |
  6250. +-----+-----+-----+
  6251. Example:
  6252. """"""""
  6253. .. code-block:: text
  6254. <result> = and i32 4, %var ; yields i32:result = 4 & %var
  6255. <result> = and i32 15, 40 ; yields i32:result = 8
  6256. <result> = and i32 4, 8 ; yields i32:result = 0
  6257. '``or``' Instruction
  6258. ^^^^^^^^^^^^^^^^^^^^
  6259. Syntax:
  6260. """""""
  6261. ::
  6262. <result> = or <ty> <op1>, <op2> ; yields ty:result
  6263. Overview:
  6264. """""""""
  6265. The '``or``' instruction returns the bitwise logical inclusive or of its
  6266. two operands.
  6267. Arguments:
  6268. """"""""""
  6269. The two arguments to the '``or``' instruction must be
  6270. :ref:`integer <t_integer>` or :ref:`vector <t_vector>` of integer values. Both
  6271. arguments must have identical types.
  6272. Semantics:
  6273. """"""""""
  6274. The truth table used for the '``or``' instruction is:
  6275. +-----+-----+-----+
  6276. | In0 | In1 | Out |
  6277. +-----+-----+-----+
  6278. | 0 | 0 | 0 |
  6279. +-----+-----+-----+
  6280. | 0 | 1 | 1 |
  6281. +-----+-----+-----+
  6282. | 1 | 0 | 1 |
  6283. +-----+-----+-----+
  6284. | 1 | 1 | 1 |
  6285. +-----+-----+-----+
  6286. Example:
  6287. """"""""
  6288. ::
  6289. <result> = or i32 4, %var ; yields i32:result = 4 | %var
  6290. <result> = or i32 15, 40 ; yields i32:result = 47
  6291. <result> = or i32 4, 8 ; yields i32:result = 12
  6292. '``xor``' Instruction
  6293. ^^^^^^^^^^^^^^^^^^^^^
  6294. Syntax:
  6295. """""""
  6296. ::
  6297. <result> = xor <ty> <op1>, <op2> ; yields ty:result
  6298. Overview:
  6299. """""""""
  6300. The '``xor``' instruction returns the bitwise logical exclusive or of
  6301. its two operands. The ``xor`` is used to implement the "one's
  6302. complement" operation, which is the "~" operator in C.
  6303. Arguments:
  6304. """"""""""
  6305. The two arguments to the '``xor``' instruction must be
  6306. :ref:`integer <t_integer>` or :ref:`vector <t_vector>` of integer values. Both
  6307. arguments must have identical types.
  6308. Semantics:
  6309. """"""""""
  6310. The truth table used for the '``xor``' instruction is:
  6311. +-----+-----+-----+
  6312. | In0 | In1 | Out |
  6313. +-----+-----+-----+
  6314. | 0 | 0 | 0 |
  6315. +-----+-----+-----+
  6316. | 0 | 1 | 1 |
  6317. +-----+-----+-----+
  6318. | 1 | 0 | 1 |
  6319. +-----+-----+-----+
  6320. | 1 | 1 | 0 |
  6321. +-----+-----+-----+
  6322. Example:
  6323. """"""""
  6324. .. code-block:: text
  6325. <result> = xor i32 4, %var ; yields i32:result = 4 ^ %var
  6326. <result> = xor i32 15, 40 ; yields i32:result = 39
  6327. <result> = xor i32 4, 8 ; yields i32:result = 12
  6328. <result> = xor i32 %V, -1 ; yields i32:result = ~%V
  6329. Vector Operations
  6330. -----------------
  6331. LLVM supports several instructions to represent vector operations in a
  6332. target-independent manner. These instructions cover the element-access
  6333. and vector-specific operations needed to process vectors effectively.
  6334. While LLVM does directly support these vector operations, many
  6335. sophisticated algorithms will want to use target-specific intrinsics to
  6336. take full advantage of a specific target.
  6337. .. _i_extractelement:
  6338. '``extractelement``' Instruction
  6339. ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  6340. Syntax:
  6341. """""""
  6342. ::
  6343. <result> = extractelement <n x <ty>> <val>, <ty2> <idx> ; yields <ty>
  6344. <result> = extractelement <vscale x n x <ty>> <val>, <ty2> <idx> ; yields <ty>
  6345. Overview:
  6346. """""""""
  6347. The '``extractelement``' instruction extracts a single scalar element
  6348. from a vector at a specified index.
  6349. Arguments:
  6350. """"""""""
  6351. The first operand of an '``extractelement``' instruction is a value of
  6352. :ref:`vector <t_vector>` type. The second operand is an index indicating
  6353. the position from which to extract the element. The index may be a
  6354. variable of any integer type.
  6355. Semantics:
  6356. """"""""""
  6357. The result is a scalar of the same type as the element type of ``val``.
  6358. Its value is the value at position ``idx`` of ``val``. If ``idx``
  6359. exceeds the length of ``val`` for a fixed-length vector, the result is a
  6360. :ref:`poison value <poisonvalues>`. For a scalable vector, if the value
  6361. of ``idx`` exceeds the runtime length of the vector, the result is a
  6362. :ref:`poison value <poisonvalues>`.
  6363. Example:
  6364. """"""""
  6365. .. code-block:: text
  6366. <result> = extractelement <4 x i32> %vec, i32 0 ; yields i32
  6367. .. _i_insertelement:
  6368. '``insertelement``' Instruction
  6369. ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  6370. Syntax:
  6371. """""""
  6372. ::
  6373. <result> = insertelement <n x <ty>> <val>, <ty> <elt>, <ty2> <idx> ; yields <n x <ty>>
  6374. <result> = insertelement <vscale x n x <ty>> <val>, <ty> <elt>, <ty2> <idx> ; yields <vscale x n x <ty>>
  6375. Overview:
  6376. """""""""
  6377. The '``insertelement``' instruction inserts a scalar element into a
  6378. vector at a specified index.
  6379. Arguments:
  6380. """"""""""
  6381. The first operand of an '``insertelement``' instruction is a value of
  6382. :ref:`vector <t_vector>` type. The second operand is a scalar value whose
  6383. type must equal the element type of the first operand. The third operand
  6384. is an index indicating the position at which to insert the value. The
  6385. index may be a variable of any integer type.
  6386. Semantics:
  6387. """"""""""
  6388. The result is a vector of the same type as ``val``. Its element values
  6389. are those of ``val`` except at position ``idx``, where it gets the value
  6390. ``elt``. If ``idx`` exceeds the length of ``val`` for a fixed-length vector,
  6391. the result is a :ref:`poison value <poisonvalues>`. For a scalable vector,
  6392. if the value of ``idx`` exceeds the runtime length of the vector, the result
  6393. is a :ref:`poison value <poisonvalues>`.
  6394. Example:
  6395. """"""""
  6396. .. code-block:: text
  6397. <result> = insertelement <4 x i32> %vec, i32 1, i32 0 ; yields <4 x i32>
  6398. .. _i_shufflevector:
  6399. '``shufflevector``' Instruction
  6400. ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  6401. Syntax:
  6402. """""""
  6403. ::
  6404. <result> = shufflevector <n x <ty>> <v1>, <n x <ty>> <v2>, <m x i32> <mask> ; yields <m x <ty>>
  6405. <result> = shufflevector <vscale x n x <ty>> <v1>, <vscale x n x <ty>> v2, <vscale x m x i32> <mask> ; yields <vscale x m x <ty>>
  6406. Overview:
  6407. """""""""
  6408. The '``shufflevector``' instruction constructs a permutation of elements
  6409. from two input vectors, returning a vector with the same element type as
  6410. the input and length that is the same as the shuffle mask.
  6411. Arguments:
  6412. """"""""""
  6413. The first two operands of a '``shufflevector``' instruction are vectors
  6414. with the same type. The third argument is a shuffle mask whose element
  6415. type is always 'i32'. The result of the instruction is a vector whose
  6416. length is the same as the shuffle mask and whose element type is the
  6417. same as the element type of the first two operands.
  6418. The shuffle mask operand is required to be a constant vector with either
  6419. constant integer or undef values.
  6420. Semantics:
  6421. """"""""""
  6422. The elements of the two input vectors are numbered from left to right
  6423. across both of the vectors. The shuffle mask operand specifies, for each
  6424. element of the result vector, which element of the two input vectors the
  6425. result element gets. If the shuffle mask is undef, the result vector is
  6426. undef. If any element of the mask operand is undef, that element of the
  6427. result is undef. If the shuffle mask selects an undef element from one
  6428. of the input vectors, the resulting element is undef.
  6429. For scalable vectors, the only valid mask values at present are
  6430. ``zeroinitializer`` and ``undef``, since we cannot write all indices as
  6431. literals for a vector with a length unknown at compile time.
  6432. Example:
  6433. """"""""
  6434. .. code-block:: text
  6435. <result> = shufflevector <4 x i32> %v1, <4 x i32> %v2,
  6436. <4 x i32> <i32 0, i32 4, i32 1, i32 5> ; yields <4 x i32>
  6437. <result> = shufflevector <4 x i32> %v1, <4 x i32> undef,
  6438. <4 x i32> <i32 0, i32 1, i32 2, i32 3> ; yields <4 x i32> - Identity shuffle.
  6439. <result> = shufflevector <8 x i32> %v1, <8 x i32> undef,
  6440. <4 x i32> <i32 0, i32 1, i32 2, i32 3> ; yields <4 x i32>
  6441. <result> = shufflevector <4 x i32> %v1, <4 x i32> %v2,
  6442. <8 x i32> <i32 0, i32 1, i32 2, i32 3, i32 4, i32 5, i32 6, i32 7 > ; yields <8 x i32>
  6443. Aggregate Operations
  6444. --------------------
  6445. LLVM supports several instructions for working with
  6446. :ref:`aggregate <t_aggregate>` values.
  6447. .. _i_extractvalue:
  6448. '``extractvalue``' Instruction
  6449. ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  6450. Syntax:
  6451. """""""
  6452. ::
  6453. <result> = extractvalue <aggregate type> <val>, <idx>{, <idx>}*
  6454. Overview:
  6455. """""""""
  6456. The '``extractvalue``' instruction extracts the value of a member field
  6457. from an :ref:`aggregate <t_aggregate>` value.
  6458. Arguments:
  6459. """"""""""
  6460. The first operand of an '``extractvalue``' instruction is a value of
  6461. :ref:`struct <t_struct>` or :ref:`array <t_array>` type. The other operands are
  6462. constant indices to specify which value to extract in a similar manner
  6463. as indices in a '``getelementptr``' instruction.
  6464. The major differences to ``getelementptr`` indexing are:
  6465. - Since the value being indexed is not a pointer, the first index is
  6466. omitted and assumed to be zero.
  6467. - At least one index must be specified.
  6468. - Not only struct indices but also array indices must be in bounds.
  6469. Semantics:
  6470. """"""""""
  6471. The result is the value at the position in the aggregate specified by
  6472. the index operands.
  6473. Example:
  6474. """"""""
  6475. .. code-block:: text
  6476. <result> = extractvalue {i32, float} %agg, 0 ; yields i32
  6477. .. _i_insertvalue:
  6478. '``insertvalue``' Instruction
  6479. ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  6480. Syntax:
  6481. """""""
  6482. ::
  6483. <result> = insertvalue <aggregate type> <val>, <ty> <elt>, <idx>{, <idx>}* ; yields <aggregate type>
  6484. Overview:
  6485. """""""""
  6486. The '``insertvalue``' instruction inserts a value into a member field in
  6487. an :ref:`aggregate <t_aggregate>` value.
  6488. Arguments:
  6489. """"""""""
  6490. The first operand of an '``insertvalue``' instruction is a value of
  6491. :ref:`struct <t_struct>` or :ref:`array <t_array>` type. The second operand is
  6492. a first-class value to insert. The following operands are constant
  6493. indices indicating the position at which to insert the value in a
  6494. similar manner as indices in a '``extractvalue``' instruction. The value
  6495. to insert must have the same type as the value identified by the
  6496. indices.
  6497. Semantics:
  6498. """"""""""
  6499. The result is an aggregate of the same type as ``val``. Its value is
  6500. that of ``val`` except that the value at the position specified by the
  6501. indices is that of ``elt``.
  6502. Example:
  6503. """"""""
  6504. .. code-block:: llvm
  6505. %agg1 = insertvalue {i32, float} undef, i32 1, 0 ; yields {i32 1, float undef}
  6506. %agg2 = insertvalue {i32, float} %agg1, float %val, 1 ; yields {i32 1, float %val}
  6507. %agg3 = insertvalue {i32, {float}} undef, float %val, 1, 0 ; yields {i32 undef, {float %val}}
  6508. .. _memoryops:
  6509. Memory Access and Addressing Operations
  6510. ---------------------------------------
  6511. A key design point of an SSA-based representation is how it represents
  6512. memory. In LLVM, no memory locations are in SSA form, which makes things
  6513. very simple. This section describes how to read, write, and allocate
  6514. memory in LLVM.
  6515. .. _i_alloca:
  6516. '``alloca``' Instruction
  6517. ^^^^^^^^^^^^^^^^^^^^^^^^
  6518. Syntax:
  6519. """""""
  6520. ::
  6521. <result> = alloca [inalloca] <type> [, <ty> <NumElements>] [, align <alignment>] [, addrspace(<num>)] ; yields type addrspace(num)*:result
  6522. Overview:
  6523. """""""""
  6524. The '``alloca``' instruction allocates memory on the stack frame of the
  6525. currently executing function, to be automatically released when this
  6526. function returns to its caller. The object is always allocated in the
  6527. address space for allocas indicated in the datalayout.
  6528. Arguments:
  6529. """"""""""
  6530. The '``alloca``' instruction allocates ``sizeof(<type>)*NumElements``
  6531. bytes of memory on the runtime stack, returning a pointer of the
  6532. appropriate type to the program. If "NumElements" is specified, it is
  6533. the number of elements allocated, otherwise "NumElements" is defaulted
  6534. to be one. If a constant alignment is specified, the value result of the
  6535. allocation is guaranteed to be aligned to at least that boundary. The
  6536. alignment may not be greater than ``1 << 29``. If not specified, or if
  6537. zero, the target can choose to align the allocation on any convenient
  6538. boundary compatible with the type.
  6539. '``type``' may be any sized type.
  6540. Semantics:
  6541. """"""""""
  6542. Memory is allocated; a pointer is returned. The allocated memory is
  6543. uninitialized, and loading from uninitialized memory produces an undefined
  6544. value. The operation itself is undefined if there is insufficient stack
  6545. space for the allocation.'``alloca``'d memory is automatically released
  6546. when the function returns. The '``alloca``' instruction is commonly used
  6547. to represent automatic variables that must have an address available. When
  6548. the function returns (either with the ``ret`` or ``resume`` instructions),
  6549. the memory is reclaimed. Allocating zero bytes is legal, but the returned
  6550. pointer may not be unique. The order in which memory is allocated (ie.,
  6551. which way the stack grows) is not specified.
  6552. Example:
  6553. """"""""
  6554. .. code-block:: llvm
  6555. %ptr = alloca i32 ; yields i32*:ptr
  6556. %ptr = alloca i32, i32 4 ; yields i32*:ptr
  6557. %ptr = alloca i32, i32 4, align 1024 ; yields i32*:ptr
  6558. %ptr = alloca i32, align 1024 ; yields i32*:ptr
  6559. .. _i_load:
  6560. '``load``' Instruction
  6561. ^^^^^^^^^^^^^^^^^^^^^^
  6562. Syntax:
  6563. """""""
  6564. ::
  6565. <result> = load [volatile] <ty>, <ty>* <pointer>[, align <alignment>][, !nontemporal !<index>][, !invariant.load !<index>][, !invariant.group !<index>][, !nonnull !<index>][, !dereferenceable !<deref_bytes_node>][, !dereferenceable_or_null !<deref_bytes_node>][, !align !<align_node>]
  6566. <result> = load atomic [volatile] <ty>, <ty>* <pointer> [syncscope("<target-scope>")] <ordering>, align <alignment> [, !invariant.group !<index>]
  6567. !<index> = !{ i32 1 }
  6568. !<deref_bytes_node> = !{i64 <dereferenceable_bytes>}
  6569. !<align_node> = !{ i64 <value_alignment> }
  6570. Overview:
  6571. """""""""
  6572. The '``load``' instruction is used to read from memory.
  6573. Arguments:
  6574. """"""""""
  6575. The argument to the ``load`` instruction specifies the memory address from which
  6576. to load. The type specified must be a :ref:`first class <t_firstclass>` type of
  6577. known size (i.e. not containing an :ref:`opaque structural type <t_opaque>`). If
  6578. the ``load`` is marked as ``volatile``, then the optimizer is not allowed to
  6579. modify the number or order of execution of this ``load`` with other
  6580. :ref:`volatile operations <volatile>`.
  6581. If the ``load`` is marked as ``atomic``, it takes an extra :ref:`ordering
  6582. <ordering>` and optional ``syncscope("<target-scope>")`` argument. The
  6583. ``release`` and ``acq_rel`` orderings are not valid on ``load`` instructions.
  6584. Atomic loads produce :ref:`defined <memmodel>` results when they may see
  6585. multiple atomic stores. The type of the pointee must be an integer, pointer, or
  6586. floating-point type whose bit width is a power of two greater than or equal to
  6587. eight and less than or equal to a target-specific size limit. ``align`` must be
  6588. explicitly specified on atomic loads, and the load has undefined behavior if the
  6589. alignment is not set to a value which is at least the size in bytes of the
  6590. pointee. ``!nontemporal`` does not have any defined semantics for atomic loads.
  6591. The optional constant ``align`` argument specifies the alignment of the
  6592. operation (that is, the alignment of the memory address). A value of 0
  6593. or an omitted ``align`` argument means that the operation has the ABI
  6594. alignment for the target. It is the responsibility of the code emitter
  6595. to ensure that the alignment information is correct. Overestimating the
  6596. alignment results in undefined behavior. Underestimating the alignment
  6597. may produce less efficient code. An alignment of 1 is always safe. The
  6598. maximum possible alignment is ``1 << 29``. An alignment value higher
  6599. than the size of the loaded type implies memory up to the alignment
  6600. value bytes can be safely loaded without trapping in the default
  6601. address space. Access of the high bytes can interfere with debugging
  6602. tools, so should not be accessed if the function has the
  6603. ``sanitize_thread`` or ``sanitize_address`` attributes.
  6604. The optional ``!nontemporal`` metadata must reference a single
  6605. metadata name ``<index>`` corresponding to a metadata node with one
  6606. ``i32`` entry of value 1. The existence of the ``!nontemporal``
  6607. metadata on the instruction tells the optimizer and code generator
  6608. that this load is not expected to be reused in the cache. The code
  6609. generator may select special instructions to save cache bandwidth, such
  6610. as the ``MOVNT`` instruction on x86.
  6611. The optional ``!invariant.load`` metadata must reference a single
  6612. metadata name ``<index>`` corresponding to a metadata node with no
  6613. entries. If a load instruction tagged with the ``!invariant.load``
  6614. metadata is executed, the optimizer may assume the memory location
  6615. referenced by the load contains the same value at all points in the
  6616. program where the memory location is known to be dereferenceable;
  6617. otherwise, the behavior is undefined.
  6618. The optional ``!invariant.group`` metadata must reference a single metadata name
  6619. ``<index>`` corresponding to a metadata node with no entries.
  6620. See ``invariant.group`` metadata :ref:`invariant.group <md_invariant.group>`
  6621. The optional ``!nonnull`` metadata must reference a single
  6622. metadata name ``<index>`` corresponding to a metadata node with no
  6623. entries. The existence of the ``!nonnull`` metadata on the
  6624. instruction tells the optimizer that the value loaded is known to
  6625. never be null. If the value is null at runtime, the behavior is undefined.
  6626. This is analogous to the ``nonnull`` attribute on parameters and return
  6627. values. This metadata can only be applied to loads of a pointer type.
  6628. The optional ``!dereferenceable`` metadata must reference a single metadata
  6629. name ``<deref_bytes_node>`` corresponding to a metadata node with one ``i64``
  6630. entry.
  6631. See ``dereferenceable`` metadata :ref:`dereferenceable <md_dereferenceable>`
  6632. The optional ``!dereferenceable_or_null`` metadata must reference a single
  6633. metadata name ``<deref_bytes_node>`` corresponding to a metadata node with one
  6634. ``i64`` entry.
  6635. See ``dereferenceable_or_null`` metadata :ref:`dereferenceable_or_null
  6636. <md_dereferenceable_or_null>`
  6637. The optional ``!align`` metadata must reference a single metadata name
  6638. ``<align_node>`` corresponding to a metadata node with one ``i64`` entry.
  6639. The existence of the ``!align`` metadata on the instruction tells the
  6640. optimizer that the value loaded is known to be aligned to a boundary specified
  6641. by the integer value in the metadata node. The alignment must be a power of 2.
  6642. This is analogous to the ''align'' attribute on parameters and return values.
  6643. This metadata can only be applied to loads of a pointer type. If the returned
  6644. value is not appropriately aligned at runtime, the behavior is undefined.
  6645. Semantics:
  6646. """"""""""
  6647. The location of memory pointed to is loaded. If the value being loaded
  6648. is of scalar type then the number of bytes read does not exceed the
  6649. minimum number of bytes needed to hold all bits of the type. For
  6650. example, loading an ``i24`` reads at most three bytes. When loading a
  6651. value of a type like ``i20`` with a size that is not an integral number
  6652. of bytes, the result is undefined if the value was not originally
  6653. written using a store of the same type.
  6654. Examples:
  6655. """""""""
  6656. .. code-block:: llvm
  6657. %ptr = alloca i32 ; yields i32*:ptr
  6658. store i32 3, i32* %ptr ; yields void
  6659. %val = load i32, i32* %ptr ; yields i32:val = i32 3
  6660. .. _i_store:
  6661. '``store``' Instruction
  6662. ^^^^^^^^^^^^^^^^^^^^^^^
  6663. Syntax:
  6664. """""""
  6665. ::
  6666. store [volatile] <ty> <value>, <ty>* <pointer>[, align <alignment>][, !nontemporal !<index>][, !invariant.group !<index>] ; yields void
  6667. store atomic [volatile] <ty> <value>, <ty>* <pointer> [syncscope("<target-scope>")] <ordering>, align <alignment> [, !invariant.group !<index>] ; yields void
  6668. Overview:
  6669. """""""""
  6670. The '``store``' instruction is used to write to memory.
  6671. Arguments:
  6672. """"""""""
  6673. There are two arguments to the ``store`` instruction: a value to store and an
  6674. address at which to store it. The type of the ``<pointer>`` operand must be a
  6675. pointer to the :ref:`first class <t_firstclass>` type of the ``<value>``
  6676. operand. If the ``store`` is marked as ``volatile``, then the optimizer is not
  6677. allowed to modify the number or order of execution of this ``store`` with other
  6678. :ref:`volatile operations <volatile>`. Only values of :ref:`first class
  6679. <t_firstclass>` types of known size (i.e. not containing an :ref:`opaque
  6680. structural type <t_opaque>`) can be stored.
  6681. If the ``store`` is marked as ``atomic``, it takes an extra :ref:`ordering
  6682. <ordering>` and optional ``syncscope("<target-scope>")`` argument. The
  6683. ``acquire`` and ``acq_rel`` orderings aren't valid on ``store`` instructions.
  6684. Atomic loads produce :ref:`defined <memmodel>` results when they may see
  6685. multiple atomic stores. The type of the pointee must be an integer, pointer, or
  6686. floating-point type whose bit width is a power of two greater than or equal to
  6687. eight and less than or equal to a target-specific size limit. ``align`` must be
  6688. explicitly specified on atomic stores, and the store has undefined behavior if
  6689. the alignment is not set to a value which is at least the size in bytes of the
  6690. pointee. ``!nontemporal`` does not have any defined semantics for atomic stores.
  6691. The optional constant ``align`` argument specifies the alignment of the
  6692. operation (that is, the alignment of the memory address). A value of 0
  6693. or an omitted ``align`` argument means that the operation has the ABI
  6694. alignment for the target. It is the responsibility of the code emitter
  6695. to ensure that the alignment information is correct. Overestimating the
  6696. alignment results in undefined behavior. Underestimating the
  6697. alignment may produce less efficient code. An alignment of 1 is always
  6698. safe. The maximum possible alignment is ``1 << 29``. An alignment
  6699. value higher than the size of the stored type implies memory up to the
  6700. alignment value bytes can be stored to without trapping in the default
  6701. address space. Storing to the higher bytes however may result in data
  6702. races if another thread can access the same address. Introducing a
  6703. data race is not allowed. Storing to the extra bytes is not allowed
  6704. even in situations where a data race is known to not exist if the
  6705. function has the ``sanitize_address`` attribute.
  6706. The optional ``!nontemporal`` metadata must reference a single metadata
  6707. name ``<index>`` corresponding to a metadata node with one ``i32`` entry of
  6708. value 1. The existence of the ``!nontemporal`` metadata on the instruction
  6709. tells the optimizer and code generator that this load is not expected to
  6710. be reused in the cache. The code generator may select special
  6711. instructions to save cache bandwidth, such as the ``MOVNT`` instruction on
  6712. x86.
  6713. The optional ``!invariant.group`` metadata must reference a
  6714. single metadata name ``<index>``. See ``invariant.group`` metadata.
  6715. Semantics:
  6716. """"""""""
  6717. The contents of memory are updated to contain ``<value>`` at the
  6718. location specified by the ``<pointer>`` operand. If ``<value>`` is
  6719. of scalar type then the number of bytes written does not exceed the
  6720. minimum number of bytes needed to hold all bits of the type. For
  6721. example, storing an ``i24`` writes at most three bytes. When writing a
  6722. value of a type like ``i20`` with a size that is not an integral number
  6723. of bytes, it is unspecified what happens to the extra bits that do not
  6724. belong to the type, but they will typically be overwritten.
  6725. Example:
  6726. """"""""
  6727. .. code-block:: llvm
  6728. %ptr = alloca i32 ; yields i32*:ptr
  6729. store i32 3, i32* %ptr ; yields void
  6730. %val = load i32, i32* %ptr ; yields i32:val = i32 3
  6731. .. _i_fence:
  6732. '``fence``' Instruction
  6733. ^^^^^^^^^^^^^^^^^^^^^^^
  6734. Syntax:
  6735. """""""
  6736. ::
  6737. fence [syncscope("<target-scope>")] <ordering> ; yields void
  6738. Overview:
  6739. """""""""
  6740. The '``fence``' instruction is used to introduce happens-before edges
  6741. between operations.
  6742. Arguments:
  6743. """"""""""
  6744. '``fence``' instructions take an :ref:`ordering <ordering>` argument which
  6745. defines what *synchronizes-with* edges they add. They can only be given
  6746. ``acquire``, ``release``, ``acq_rel``, and ``seq_cst`` orderings.
  6747. Semantics:
  6748. """"""""""
  6749. A fence A which has (at least) ``release`` ordering semantics
  6750. *synchronizes with* a fence B with (at least) ``acquire`` ordering
  6751. semantics if and only if there exist atomic operations X and Y, both
  6752. operating on some atomic object M, such that A is sequenced before X, X
  6753. modifies M (either directly or through some side effect of a sequence
  6754. headed by X), Y is sequenced before B, and Y observes M. This provides a
  6755. *happens-before* dependency between A and B. Rather than an explicit
  6756. ``fence``, one (but not both) of the atomic operations X or Y might
  6757. provide a ``release`` or ``acquire`` (resp.) ordering constraint and
  6758. still *synchronize-with* the explicit ``fence`` and establish the
  6759. *happens-before* edge.
  6760. A ``fence`` which has ``seq_cst`` ordering, in addition to having both
  6761. ``acquire`` and ``release`` semantics specified above, participates in
  6762. the global program order of other ``seq_cst`` operations and/or fences.
  6763. A ``fence`` instruction can also take an optional
  6764. ":ref:`syncscope <syncscope>`" argument.
  6765. Example:
  6766. """"""""
  6767. .. code-block:: text
  6768. fence acquire ; yields void
  6769. fence syncscope("singlethread") seq_cst ; yields void
  6770. fence syncscope("agent") seq_cst ; yields void
  6771. .. _i_cmpxchg:
  6772. '``cmpxchg``' Instruction
  6773. ^^^^^^^^^^^^^^^^^^^^^^^^^
  6774. Syntax:
  6775. """""""
  6776. ::
  6777. cmpxchg [weak] [volatile] <ty>* <pointer>, <ty> <cmp>, <ty> <new> [syncscope("<target-scope>")] <success ordering> <failure ordering> ; yields { ty, i1 }
  6778. Overview:
  6779. """""""""
  6780. The '``cmpxchg``' instruction is used to atomically modify memory. It
  6781. loads a value in memory and compares it to a given value. If they are
  6782. equal, it tries to store a new value into the memory.
  6783. Arguments:
  6784. """"""""""
  6785. There are three arguments to the '``cmpxchg``' instruction: an address
  6786. to operate on, a value to compare to the value currently be at that
  6787. address, and a new value to place at that address if the compared values
  6788. are equal. The type of '<cmp>' must be an integer or pointer type whose
  6789. bit width is a power of two greater than or equal to eight and less
  6790. than or equal to a target-specific size limit. '<cmp>' and '<new>' must
  6791. have the same type, and the type of '<pointer>' must be a pointer to
  6792. that type. If the ``cmpxchg`` is marked as ``volatile``, then the
  6793. optimizer is not allowed to modify the number or order of execution of
  6794. this ``cmpxchg`` with other :ref:`volatile operations <volatile>`.
  6795. The success and failure :ref:`ordering <ordering>` arguments specify how this
  6796. ``cmpxchg`` synchronizes with other atomic operations. Both ordering parameters
  6797. must be at least ``monotonic``, the ordering constraint on failure must be no
  6798. stronger than that on success, and the failure ordering cannot be either
  6799. ``release`` or ``acq_rel``.
  6800. A ``cmpxchg`` instruction can also take an optional
  6801. ":ref:`syncscope <syncscope>`" argument.
  6802. The pointer passed into cmpxchg must have alignment greater than or
  6803. equal to the size in memory of the operand.
  6804. Semantics:
  6805. """"""""""
  6806. The contents of memory at the location specified by the '``<pointer>``' operand
  6807. is read and compared to '``<cmp>``'; if the values are equal, '``<new>``' is
  6808. written to the location. The original value at the location is returned,
  6809. together with a flag indicating success (true) or failure (false).
  6810. If the cmpxchg operation is marked as ``weak`` then a spurious failure is
  6811. permitted: the operation may not write ``<new>`` even if the comparison
  6812. matched.
  6813. If the cmpxchg operation is strong (the default), the i1 value is 1 if and only
  6814. if the value loaded equals ``cmp``.
  6815. A successful ``cmpxchg`` is a read-modify-write instruction for the purpose of
  6816. identifying release sequences. A failed ``cmpxchg`` is equivalent to an atomic
  6817. load with an ordering parameter determined the second ordering parameter.
  6818. Example:
  6819. """"""""
  6820. .. code-block:: llvm
  6821. entry:
  6822. %orig = load atomic i32, i32* %ptr unordered, align 4 ; yields i32
  6823. br label %loop
  6824. loop:
  6825. %cmp = phi i32 [ %orig, %entry ], [%value_loaded, %loop]
  6826. %squared = mul i32 %cmp, %cmp
  6827. %val_success = cmpxchg i32* %ptr, i32 %cmp, i32 %squared acq_rel monotonic ; yields { i32, i1 }
  6828. %value_loaded = extractvalue { i32, i1 } %val_success, 0
  6829. %success = extractvalue { i32, i1 } %val_success, 1
  6830. br i1 %success, label %done, label %loop
  6831. done:
  6832. ...
  6833. .. _i_atomicrmw:
  6834. '``atomicrmw``' Instruction
  6835. ^^^^^^^^^^^^^^^^^^^^^^^^^^^
  6836. Syntax:
  6837. """""""
  6838. ::
  6839. atomicrmw [volatile] <operation> <ty>* <pointer>, <ty> <value> [syncscope("<target-scope>")] <ordering> ; yields ty
  6840. Overview:
  6841. """""""""
  6842. The '``atomicrmw``' instruction is used to atomically modify memory.
  6843. Arguments:
  6844. """"""""""
  6845. There are three arguments to the '``atomicrmw``' instruction: an
  6846. operation to apply, an address whose value to modify, an argument to the
  6847. operation. The operation must be one of the following keywords:
  6848. - xchg
  6849. - add
  6850. - sub
  6851. - and
  6852. - nand
  6853. - or
  6854. - xor
  6855. - max
  6856. - min
  6857. - umax
  6858. - umin
  6859. - fadd
  6860. - fsub
  6861. For most of these operations, the type of '<value>' must be an integer
  6862. type whose bit width is a power of two greater than or equal to eight
  6863. and less than or equal to a target-specific size limit. For xchg, this
  6864. may also be a floating point type with the same size constraints as
  6865. integers. For fadd/fsub, this must be a floating point type. The
  6866. type of the '``<pointer>``' operand must be a pointer to that type. If
  6867. the ``atomicrmw`` is marked as ``volatile``, then the optimizer is not
  6868. allowed to modify the number or order of execution of this
  6869. ``atomicrmw`` with other :ref:`volatile operations <volatile>`.
  6870. A ``atomicrmw`` instruction can also take an optional
  6871. ":ref:`syncscope <syncscope>`" argument.
  6872. Semantics:
  6873. """"""""""
  6874. The contents of memory at the location specified by the '``<pointer>``'
  6875. operand are atomically read, modified, and written back. The original
  6876. value at the location is returned. The modification is specified by the
  6877. operation argument:
  6878. - xchg: ``*ptr = val``
  6879. - add: ``*ptr = *ptr + val``
  6880. - sub: ``*ptr = *ptr - val``
  6881. - and: ``*ptr = *ptr & val``
  6882. - nand: ``*ptr = ~(*ptr & val)``
  6883. - or: ``*ptr = *ptr | val``
  6884. - xor: ``*ptr = *ptr ^ val``
  6885. - max: ``*ptr = *ptr > val ? *ptr : val`` (using a signed comparison)
  6886. - min: ``*ptr = *ptr < val ? *ptr : val`` (using a signed comparison)
  6887. - umax: ``*ptr = *ptr > val ? *ptr : val`` (using an unsigned
  6888. comparison)
  6889. - umin: ``*ptr = *ptr < val ? *ptr : val`` (using an unsigned
  6890. comparison)
  6891. - fadd: ``*ptr = *ptr + val`` (using floating point arithmetic)
  6892. - fsub: ``*ptr = *ptr - val`` (using floating point arithmetic)
  6893. Example:
  6894. """"""""
  6895. .. code-block:: llvm
  6896. %old = atomicrmw add i32* %ptr, i32 1 acquire ; yields i32
  6897. .. _i_getelementptr:
  6898. '``getelementptr``' Instruction
  6899. ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  6900. Syntax:
  6901. """""""
  6902. ::
  6903. <result> = getelementptr <ty>, <ty>* <ptrval>{, [inrange] <ty> <idx>}*
  6904. <result> = getelementptr inbounds <ty>, <ty>* <ptrval>{, [inrange] <ty> <idx>}*
  6905. <result> = getelementptr <ty>, <ptr vector> <ptrval>, [inrange] <vector index type> <idx>
  6906. Overview:
  6907. """""""""
  6908. The '``getelementptr``' instruction is used to get the address of a
  6909. subelement of an :ref:`aggregate <t_aggregate>` data structure. It performs
  6910. address calculation only and does not access memory. The instruction can also
  6911. be used to calculate a vector of such addresses.
  6912. Arguments:
  6913. """"""""""
  6914. The first argument is always a type used as the basis for the calculations.
  6915. The second argument is always a pointer or a vector of pointers, and is the
  6916. base address to start from. The remaining arguments are indices
  6917. that indicate which of the elements of the aggregate object are indexed.
  6918. The interpretation of each index is dependent on the type being indexed
  6919. into. The first index always indexes the pointer value given as the
  6920. second argument, the second index indexes a value of the type pointed to
  6921. (not necessarily the value directly pointed to, since the first index
  6922. can be non-zero), etc. The first type indexed into must be a pointer
  6923. value, subsequent types can be arrays, vectors, and structs. Note that
  6924. subsequent types being indexed into can never be pointers, since that
  6925. would require loading the pointer before continuing calculation.
  6926. The type of each index argument depends on the type it is indexing into.
  6927. When indexing into a (optionally packed) structure, only ``i32`` integer
  6928. **constants** are allowed (when using a vector of indices they must all
  6929. be the **same** ``i32`` integer constant). When indexing into an array,
  6930. pointer or vector, integers of any width are allowed, and they are not
  6931. required to be constant. These integers are treated as signed values
  6932. where relevant.
  6933. For example, let's consider a C code fragment and how it gets compiled
  6934. to LLVM:
  6935. .. code-block:: c
  6936. struct RT {
  6937. char A;
  6938. int B[10][20];
  6939. char C;
  6940. };
  6941. struct ST {
  6942. int X;
  6943. double Y;
  6944. struct RT Z;
  6945. };
  6946. int *foo(struct ST *s) {
  6947. return &s[1].Z.B[5][13];
  6948. }
  6949. The LLVM code generated by Clang is:
  6950. .. code-block:: llvm
  6951. %struct.RT = type { i8, [10 x [20 x i32]], i8 }
  6952. %struct.ST = type { i32, double, %struct.RT }
  6953. define i32* @foo(%struct.ST* %s) nounwind uwtable readnone optsize ssp {
  6954. entry:
  6955. %arrayidx = getelementptr inbounds %struct.ST, %struct.ST* %s, i64 1, i32 2, i32 1, i64 5, i64 13
  6956. ret i32* %arrayidx
  6957. }
  6958. Semantics:
  6959. """"""""""
  6960. In the example above, the first index is indexing into the
  6961. '``%struct.ST*``' type, which is a pointer, yielding a '``%struct.ST``'
  6962. = '``{ i32, double, %struct.RT }``' type, a structure. The second index
  6963. indexes into the third element of the structure, yielding a
  6964. '``%struct.RT``' = '``{ i8 , [10 x [20 x i32]], i8 }``' type, another
  6965. structure. The third index indexes into the second element of the
  6966. structure, yielding a '``[10 x [20 x i32]]``' type, an array. The two
  6967. dimensions of the array are subscripted into, yielding an '``i32``'
  6968. type. The '``getelementptr``' instruction returns a pointer to this
  6969. element, thus computing a value of '``i32*``' type.
  6970. Note that it is perfectly legal to index partially through a structure,
  6971. returning a pointer to an inner element. Because of this, the LLVM code
  6972. for the given testcase is equivalent to:
  6973. .. code-block:: llvm
  6974. define i32* @foo(%struct.ST* %s) {
  6975. %t1 = getelementptr %struct.ST, %struct.ST* %s, i32 1 ; yields %struct.ST*:%t1
  6976. %t2 = getelementptr %struct.ST, %struct.ST* %t1, i32 0, i32 2 ; yields %struct.RT*:%t2
  6977. %t3 = getelementptr %struct.RT, %struct.RT* %t2, i32 0, i32 1 ; yields [10 x [20 x i32]]*:%t3
  6978. %t4 = getelementptr [10 x [20 x i32]], [10 x [20 x i32]]* %t3, i32 0, i32 5 ; yields [20 x i32]*:%t4
  6979. %t5 = getelementptr [20 x i32], [20 x i32]* %t4, i32 0, i32 13 ; yields i32*:%t5
  6980. ret i32* %t5
  6981. }
  6982. If the ``inbounds`` keyword is present, the result value of the
  6983. ``getelementptr`` is a :ref:`poison value <poisonvalues>` if the base
  6984. pointer is not an *in bounds* address of an allocated object, or if any
  6985. of the addresses that would be formed by successive addition of the
  6986. offsets implied by the indices to the base address with infinitely
  6987. precise signed arithmetic are not an *in bounds* address of that
  6988. allocated object. The *in bounds* addresses for an allocated object are
  6989. all the addresses that point into the object, plus the address one byte
  6990. past the end. The only *in bounds* address for a null pointer in the
  6991. default address-space is the null pointer itself. In cases where the
  6992. base is a vector of pointers the ``inbounds`` keyword applies to each
  6993. of the computations element-wise.
  6994. If the ``inbounds`` keyword is not present, the offsets are added to the
  6995. base address with silently-wrapping two's complement arithmetic. If the
  6996. offsets have a different width from the pointer, they are sign-extended
  6997. or truncated to the width of the pointer. The result value of the
  6998. ``getelementptr`` may be outside the object pointed to by the base
  6999. pointer. The result value may not necessarily be used to access memory
  7000. though, even if it happens to point into allocated storage. See the
  7001. :ref:`Pointer Aliasing Rules <pointeraliasing>` section for more
  7002. information.
  7003. If the ``inrange`` keyword is present before any index, loading from or
  7004. storing to any pointer derived from the ``getelementptr`` has undefined
  7005. behavior if the load or store would access memory outside of the bounds of
  7006. the element selected by the index marked as ``inrange``. The result of a
  7007. pointer comparison or ``ptrtoint`` (including ``ptrtoint``-like operations
  7008. involving memory) involving a pointer derived from a ``getelementptr`` with
  7009. the ``inrange`` keyword is undefined, with the exception of comparisons
  7010. in the case where both operands are in the range of the element selected
  7011. by the ``inrange`` keyword, inclusive of the address one past the end of
  7012. that element. Note that the ``inrange`` keyword is currently only allowed
  7013. in constant ``getelementptr`` expressions.
  7014. The getelementptr instruction is often confusing. For some more insight
  7015. into how it works, see :doc:`the getelementptr FAQ <GetElementPtr>`.
  7016. Example:
  7017. """"""""
  7018. .. code-block:: llvm
  7019. ; yields [12 x i8]*:aptr
  7020. %aptr = getelementptr {i32, [12 x i8]}, {i32, [12 x i8]}* %saptr, i64 0, i32 1
  7021. ; yields i8*:vptr
  7022. %vptr = getelementptr {i32, <2 x i8>}, {i32, <2 x i8>}* %svptr, i64 0, i32 1, i32 1
  7023. ; yields i8*:eptr
  7024. %eptr = getelementptr [12 x i8], [12 x i8]* %aptr, i64 0, i32 1
  7025. ; yields i32*:iptr
  7026. %iptr = getelementptr [10 x i32], [10 x i32]* @arr, i16 0, i16 0
  7027. Vector of pointers:
  7028. """""""""""""""""""
  7029. The ``getelementptr`` returns a vector of pointers, instead of a single address,
  7030. when one or more of its arguments is a vector. In such cases, all vector
  7031. arguments should have the same number of elements, and every scalar argument
  7032. will be effectively broadcast into a vector during address calculation.
  7033. .. code-block:: llvm
  7034. ; All arguments are vectors:
  7035. ; A[i] = ptrs[i] + offsets[i]*sizeof(i8)
  7036. %A = getelementptr i8, <4 x i8*> %ptrs, <4 x i64> %offsets
  7037. ; Add the same scalar offset to each pointer of a vector:
  7038. ; A[i] = ptrs[i] + offset*sizeof(i8)
  7039. %A = getelementptr i8, <4 x i8*> %ptrs, i64 %offset
  7040. ; Add distinct offsets to the same pointer:
  7041. ; A[i] = ptr + offsets[i]*sizeof(i8)
  7042. %A = getelementptr i8, i8* %ptr, <4 x i64> %offsets
  7043. ; In all cases described above the type of the result is <4 x i8*>
  7044. The two following instructions are equivalent:
  7045. .. code-block:: llvm
  7046. getelementptr %struct.ST, <4 x %struct.ST*> %s, <4 x i64> %ind1,
  7047. <4 x i32> <i32 2, i32 2, i32 2, i32 2>,
  7048. <4 x i32> <i32 1, i32 1, i32 1, i32 1>,
  7049. <4 x i32> %ind4,
  7050. <4 x i64> <i64 13, i64 13, i64 13, i64 13>
  7051. getelementptr %struct.ST, <4 x %struct.ST*> %s, <4 x i64> %ind1,
  7052. i32 2, i32 1, <4 x i32> %ind4, i64 13
  7053. Let's look at the C code, where the vector version of ``getelementptr``
  7054. makes sense:
  7055. .. code-block:: c
  7056. // Let's assume that we vectorize the following loop:
  7057. double *A, *B; int *C;
  7058. for (int i = 0; i < size; ++i) {
  7059. A[i] = B[C[i]];
  7060. }
  7061. .. code-block:: llvm
  7062. ; get pointers for 8 elements from array B
  7063. %ptrs = getelementptr double, double* %B, <8 x i32> %C
  7064. ; load 8 elements from array B into A
  7065. %A = call <8 x double> @llvm.masked.gather.v8f64.v8p0f64(<8 x double*> %ptrs,
  7066. i32 8, <8 x i1> %mask, <8 x double> %passthru)
  7067. Conversion Operations
  7068. ---------------------
  7069. The instructions in this category are the conversion instructions
  7070. (casting) which all take a single operand and a type. They perform
  7071. various bit conversions on the operand.
  7072. .. _i_trunc:
  7073. '``trunc .. to``' Instruction
  7074. ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  7075. Syntax:
  7076. """""""
  7077. ::
  7078. <result> = trunc <ty> <value> to <ty2> ; yields ty2
  7079. Overview:
  7080. """""""""
  7081. The '``trunc``' instruction truncates its operand to the type ``ty2``.
  7082. Arguments:
  7083. """"""""""
  7084. The '``trunc``' instruction takes a value to trunc, and a type to trunc
  7085. it to. Both types must be of :ref:`integer <t_integer>` types, or vectors
  7086. of the same number of integers. The bit size of the ``value`` must be
  7087. larger than the bit size of the destination type, ``ty2``. Equal sized
  7088. types are not allowed.
  7089. Semantics:
  7090. """"""""""
  7091. The '``trunc``' instruction truncates the high order bits in ``value``
  7092. and converts the remaining bits to ``ty2``. Since the source size must
  7093. be larger than the destination size, ``trunc`` cannot be a *no-op cast*.
  7094. It will always truncate bits.
  7095. Example:
  7096. """"""""
  7097. .. code-block:: llvm
  7098. %X = trunc i32 257 to i8 ; yields i8:1
  7099. %Y = trunc i32 123 to i1 ; yields i1:true
  7100. %Z = trunc i32 122 to i1 ; yields i1:false
  7101. %W = trunc <2 x i16> <i16 8, i16 7> to <2 x i8> ; yields <i8 8, i8 7>
  7102. .. _i_zext:
  7103. '``zext .. to``' Instruction
  7104. ^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  7105. Syntax:
  7106. """""""
  7107. ::
  7108. <result> = zext <ty> <value> to <ty2> ; yields ty2
  7109. Overview:
  7110. """""""""
  7111. The '``zext``' instruction zero extends its operand to type ``ty2``.
  7112. Arguments:
  7113. """"""""""
  7114. The '``zext``' instruction takes a value to cast, and a type to cast it
  7115. to. Both types must be of :ref:`integer <t_integer>` types, or vectors of
  7116. the same number of integers. The bit size of the ``value`` must be
  7117. smaller than the bit size of the destination type, ``ty2``.
  7118. Semantics:
  7119. """"""""""
  7120. The ``zext`` fills the high order bits of the ``value`` with zero bits
  7121. until it reaches the size of the destination type, ``ty2``.
  7122. When zero extending from i1, the result will always be either 0 or 1.
  7123. Example:
  7124. """"""""
  7125. .. code-block:: llvm
  7126. %X = zext i32 257 to i64 ; yields i64:257
  7127. %Y = zext i1 true to i32 ; yields i32:1
  7128. %Z = zext <2 x i16> <i16 8, i16 7> to <2 x i32> ; yields <i32 8, i32 7>
  7129. .. _i_sext:
  7130. '``sext .. to``' Instruction
  7131. ^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  7132. Syntax:
  7133. """""""
  7134. ::
  7135. <result> = sext <ty> <value> to <ty2> ; yields ty2
  7136. Overview:
  7137. """""""""
  7138. The '``sext``' sign extends ``value`` to the type ``ty2``.
  7139. Arguments:
  7140. """"""""""
  7141. The '``sext``' instruction takes a value to cast, and a type to cast it
  7142. to. Both types must be of :ref:`integer <t_integer>` types, or vectors of
  7143. the same number of integers. The bit size of the ``value`` must be
  7144. smaller than the bit size of the destination type, ``ty2``.
  7145. Semantics:
  7146. """"""""""
  7147. The '``sext``' instruction performs a sign extension by copying the sign
  7148. bit (highest order bit) of the ``value`` until it reaches the bit size
  7149. of the type ``ty2``.
  7150. When sign extending from i1, the extension always results in -1 or 0.
  7151. Example:
  7152. """"""""
  7153. .. code-block:: llvm
  7154. %X = sext i8 -1 to i16 ; yields i16 :65535
  7155. %Y = sext i1 true to i32 ; yields i32:-1
  7156. %Z = sext <2 x i16> <i16 8, i16 7> to <2 x i32> ; yields <i32 8, i32 7>
  7157. '``fptrunc .. to``' Instruction
  7158. ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  7159. Syntax:
  7160. """""""
  7161. ::
  7162. <result> = fptrunc <ty> <value> to <ty2> ; yields ty2
  7163. Overview:
  7164. """""""""
  7165. The '``fptrunc``' instruction truncates ``value`` to type ``ty2``.
  7166. Arguments:
  7167. """"""""""
  7168. The '``fptrunc``' instruction takes a :ref:`floating-point <t_floating>`
  7169. value to cast and a :ref:`floating-point <t_floating>` type to cast it to.
  7170. The size of ``value`` must be larger than the size of ``ty2``. This
  7171. implies that ``fptrunc`` cannot be used to make a *no-op cast*.
  7172. Semantics:
  7173. """"""""""
  7174. The '``fptrunc``' instruction casts a ``value`` from a larger
  7175. :ref:`floating-point <t_floating>` type to a smaller :ref:`floating-point
  7176. <t_floating>` type.
  7177. This instruction is assumed to execute in the default :ref:`floating-point
  7178. environment <floatenv>`.
  7179. Example:
  7180. """"""""
  7181. .. code-block:: llvm
  7182. %X = fptrunc double 16777217.0 to float ; yields float:16777216.0
  7183. %Y = fptrunc double 1.0E+300 to half ; yields half:+infinity
  7184. '``fpext .. to``' Instruction
  7185. ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  7186. Syntax:
  7187. """""""
  7188. ::
  7189. <result> = fpext <ty> <value> to <ty2> ; yields ty2
  7190. Overview:
  7191. """""""""
  7192. The '``fpext``' extends a floating-point ``value`` to a larger floating-point
  7193. value.
  7194. Arguments:
  7195. """"""""""
  7196. The '``fpext``' instruction takes a :ref:`floating-point <t_floating>`
  7197. ``value`` to cast, and a :ref:`floating-point <t_floating>` type to cast it
  7198. to. The source type must be smaller than the destination type.
  7199. Semantics:
  7200. """"""""""
  7201. The '``fpext``' instruction extends the ``value`` from a smaller
  7202. :ref:`floating-point <t_floating>` type to a larger :ref:`floating-point
  7203. <t_floating>` type. The ``fpext`` cannot be used to make a
  7204. *no-op cast* because it always changes bits. Use ``bitcast`` to make a
  7205. *no-op cast* for a floating-point cast.
  7206. Example:
  7207. """"""""
  7208. .. code-block:: llvm
  7209. %X = fpext float 3.125 to double ; yields double:3.125000e+00
  7210. %Y = fpext double %X to fp128 ; yields fp128:0xL00000000000000004000900000000000
  7211. '``fptoui .. to``' Instruction
  7212. ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  7213. Syntax:
  7214. """""""
  7215. ::
  7216. <result> = fptoui <ty> <value> to <ty2> ; yields ty2
  7217. Overview:
  7218. """""""""
  7219. The '``fptoui``' converts a floating-point ``value`` to its unsigned
  7220. integer equivalent of type ``ty2``.
  7221. Arguments:
  7222. """"""""""
  7223. The '``fptoui``' instruction takes a value to cast, which must be a
  7224. scalar or vector :ref:`floating-point <t_floating>` value, and a type to
  7225. cast it to ``ty2``, which must be an :ref:`integer <t_integer>` type. If
  7226. ``ty`` is a vector floating-point type, ``ty2`` must be a vector integer
  7227. type with the same number of elements as ``ty``
  7228. Semantics:
  7229. """"""""""
  7230. The '``fptoui``' instruction converts its :ref:`floating-point
  7231. <t_floating>` operand into the nearest (rounding towards zero)
  7232. unsigned integer value. If the value cannot fit in ``ty2``, the result
  7233. is a :ref:`poison value <poisonvalues>`.
  7234. Example:
  7235. """"""""
  7236. .. code-block:: llvm
  7237. %X = fptoui double 123.0 to i32 ; yields i32:123
  7238. %Y = fptoui float 1.0E+300 to i1 ; yields undefined:1
  7239. %Z = fptoui float 1.04E+17 to i8 ; yields undefined:1
  7240. '``fptosi .. to``' Instruction
  7241. ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  7242. Syntax:
  7243. """""""
  7244. ::
  7245. <result> = fptosi <ty> <value> to <ty2> ; yields ty2
  7246. Overview:
  7247. """""""""
  7248. The '``fptosi``' instruction converts :ref:`floating-point <t_floating>`
  7249. ``value`` to type ``ty2``.
  7250. Arguments:
  7251. """"""""""
  7252. The '``fptosi``' instruction takes a value to cast, which must be a
  7253. scalar or vector :ref:`floating-point <t_floating>` value, and a type to
  7254. cast it to ``ty2``, which must be an :ref:`integer <t_integer>` type. If
  7255. ``ty`` is a vector floating-point type, ``ty2`` must be a vector integer
  7256. type with the same number of elements as ``ty``
  7257. Semantics:
  7258. """"""""""
  7259. The '``fptosi``' instruction converts its :ref:`floating-point
  7260. <t_floating>` operand into the nearest (rounding towards zero)
  7261. signed integer value. If the value cannot fit in ``ty2``, the result
  7262. is a :ref:`poison value <poisonvalues>`.
  7263. Example:
  7264. """"""""
  7265. .. code-block:: llvm
  7266. %X = fptosi double -123.0 to i32 ; yields i32:-123
  7267. %Y = fptosi float 1.0E-247 to i1 ; yields undefined:1
  7268. %Z = fptosi float 1.04E+17 to i8 ; yields undefined:1
  7269. '``uitofp .. to``' Instruction
  7270. ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  7271. Syntax:
  7272. """""""
  7273. ::
  7274. <result> = uitofp <ty> <value> to <ty2> ; yields ty2
  7275. Overview:
  7276. """""""""
  7277. The '``uitofp``' instruction regards ``value`` as an unsigned integer
  7278. and converts that value to the ``ty2`` type.
  7279. Arguments:
  7280. """"""""""
  7281. The '``uitofp``' instruction takes a value to cast, which must be a
  7282. scalar or vector :ref:`integer <t_integer>` value, and a type to cast it to
  7283. ``ty2``, which must be an :ref:`floating-point <t_floating>` type. If
  7284. ``ty`` is a vector integer type, ``ty2`` must be a vector floating-point
  7285. type with the same number of elements as ``ty``
  7286. Semantics:
  7287. """"""""""
  7288. The '``uitofp``' instruction interprets its operand as an unsigned
  7289. integer quantity and converts it to the corresponding floating-point
  7290. value. If the value cannot be exactly represented, it is rounded using
  7291. the default rounding mode.
  7292. Example:
  7293. """"""""
  7294. .. code-block:: llvm
  7295. %X = uitofp i32 257 to float ; yields float:257.0
  7296. %Y = uitofp i8 -1 to double ; yields double:255.0
  7297. '``sitofp .. to``' Instruction
  7298. ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  7299. Syntax:
  7300. """""""
  7301. ::
  7302. <result> = sitofp <ty> <value> to <ty2> ; yields ty2
  7303. Overview:
  7304. """""""""
  7305. The '``sitofp``' instruction regards ``value`` as a signed integer and
  7306. converts that value to the ``ty2`` type.
  7307. Arguments:
  7308. """"""""""
  7309. The '``sitofp``' instruction takes a value to cast, which must be a
  7310. scalar or vector :ref:`integer <t_integer>` value, and a type to cast it to
  7311. ``ty2``, which must be an :ref:`floating-point <t_floating>` type. If
  7312. ``ty`` is a vector integer type, ``ty2`` must be a vector floating-point
  7313. type with the same number of elements as ``ty``
  7314. Semantics:
  7315. """"""""""
  7316. The '``sitofp``' instruction interprets its operand as a signed integer
  7317. quantity and converts it to the corresponding floating-point value. If the
  7318. value cannot be exactly represented, it is rounded using the default rounding
  7319. mode.
  7320. Example:
  7321. """"""""
  7322. .. code-block:: llvm
  7323. %X = sitofp i32 257 to float ; yields float:257.0
  7324. %Y = sitofp i8 -1 to double ; yields double:-1.0
  7325. .. _i_ptrtoint:
  7326. '``ptrtoint .. to``' Instruction
  7327. ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  7328. Syntax:
  7329. """""""
  7330. ::
  7331. <result> = ptrtoint <ty> <value> to <ty2> ; yields ty2
  7332. Overview:
  7333. """""""""
  7334. The '``ptrtoint``' instruction converts the pointer or a vector of
  7335. pointers ``value`` to the integer (or vector of integers) type ``ty2``.
  7336. Arguments:
  7337. """"""""""
  7338. The '``ptrtoint``' instruction takes a ``value`` to cast, which must be
  7339. a value of type :ref:`pointer <t_pointer>` or a vector of pointers, and a
  7340. type to cast it to ``ty2``, which must be an :ref:`integer <t_integer>` or
  7341. a vector of integers type.
  7342. Semantics:
  7343. """"""""""
  7344. The '``ptrtoint``' instruction converts ``value`` to integer type
  7345. ``ty2`` by interpreting the pointer value as an integer and either
  7346. truncating or zero extending that value to the size of the integer type.
  7347. If ``value`` is smaller than ``ty2`` then a zero extension is done. If
  7348. ``value`` is larger than ``ty2`` then a truncation is done. If they are
  7349. the same size, then nothing is done (*no-op cast*) other than a type
  7350. change.
  7351. Example:
  7352. """"""""
  7353. .. code-block:: llvm
  7354. %X = ptrtoint i32* %P to i8 ; yields truncation on 32-bit architecture
  7355. %Y = ptrtoint i32* %P to i64 ; yields zero extension on 32-bit architecture
  7356. %Z = ptrtoint <4 x i32*> %P to <4 x i64>; yields vector zero extension for a vector of addresses on 32-bit architecture
  7357. .. _i_inttoptr:
  7358. '``inttoptr .. to``' Instruction
  7359. ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  7360. Syntax:
  7361. """""""
  7362. ::
  7363. <result> = inttoptr <ty> <value> to <ty2>[, !dereferenceable !<deref_bytes_node>][, !dereferenceable_or_null !<deref_bytes_node] ; yields ty2
  7364. Overview:
  7365. """""""""
  7366. The '``inttoptr``' instruction converts an integer ``value`` to a
  7367. pointer type, ``ty2``.
  7368. Arguments:
  7369. """"""""""
  7370. The '``inttoptr``' instruction takes an :ref:`integer <t_integer>` value to
  7371. cast, and a type to cast it to, which must be a :ref:`pointer <t_pointer>`
  7372. type.
  7373. The optional ``!dereferenceable`` metadata must reference a single metadata
  7374. name ``<deref_bytes_node>`` corresponding to a metadata node with one ``i64``
  7375. entry.
  7376. See ``dereferenceable`` metadata.
  7377. The optional ``!dereferenceable_or_null`` metadata must reference a single
  7378. metadata name ``<deref_bytes_node>`` corresponding to a metadata node with one
  7379. ``i64`` entry.
  7380. See ``dereferenceable_or_null`` metadata.
  7381. Semantics:
  7382. """"""""""
  7383. The '``inttoptr``' instruction converts ``value`` to type ``ty2`` by
  7384. applying either a zero extension or a truncation depending on the size
  7385. of the integer ``value``. If ``value`` is larger than the size of a
  7386. pointer then a truncation is done. If ``value`` is smaller than the size
  7387. of a pointer then a zero extension is done. If they are the same size,
  7388. nothing is done (*no-op cast*).
  7389. Example:
  7390. """"""""
  7391. .. code-block:: llvm
  7392. %X = inttoptr i32 255 to i32* ; yields zero extension on 64-bit architecture
  7393. %Y = inttoptr i32 255 to i32* ; yields no-op on 32-bit architecture
  7394. %Z = inttoptr i64 0 to i32* ; yields truncation on 32-bit architecture
  7395. %Z = inttoptr <4 x i32> %G to <4 x i8*>; yields truncation of vector G to four pointers
  7396. .. _i_bitcast:
  7397. '``bitcast .. to``' Instruction
  7398. ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  7399. Syntax:
  7400. """""""
  7401. ::
  7402. <result> = bitcast <ty> <value> to <ty2> ; yields ty2
  7403. Overview:
  7404. """""""""
  7405. The '``bitcast``' instruction converts ``value`` to type ``ty2`` without
  7406. changing any bits.
  7407. Arguments:
  7408. """"""""""
  7409. The '``bitcast``' instruction takes a value to cast, which must be a
  7410. non-aggregate first class value, and a type to cast it to, which must
  7411. also be a non-aggregate :ref:`first class <t_firstclass>` type. The
  7412. bit sizes of ``value`` and the destination type, ``ty2``, must be
  7413. identical. If the source type is a pointer, the destination type must
  7414. also be a pointer of the same size. This instruction supports bitwise
  7415. conversion of vectors to integers and to vectors of other types (as
  7416. long as they have the same size).
  7417. Semantics:
  7418. """"""""""
  7419. The '``bitcast``' instruction converts ``value`` to type ``ty2``. It
  7420. is always a *no-op cast* because no bits change with this
  7421. conversion. The conversion is done as if the ``value`` had been stored
  7422. to memory and read back as type ``ty2``. Pointer (or vector of
  7423. pointers) types may only be converted to other pointer (or vector of
  7424. pointers) types with the same address space through this instruction.
  7425. To convert pointers to other types, use the :ref:`inttoptr <i_inttoptr>`
  7426. or :ref:`ptrtoint <i_ptrtoint>` instructions first.
  7427. Example:
  7428. """"""""
  7429. .. code-block:: text
  7430. %X = bitcast i8 255 to i8 ; yields i8 :-1
  7431. %Y = bitcast i32* %x to sint* ; yields sint*:%x
  7432. %Z = bitcast <2 x int> %V to i64; ; yields i64: %V
  7433. %Z = bitcast <2 x i32*> %V to <2 x i64*> ; yields <2 x i64*>
  7434. .. _i_addrspacecast:
  7435. '``addrspacecast .. to``' Instruction
  7436. ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  7437. Syntax:
  7438. """""""
  7439. ::
  7440. <result> = addrspacecast <pty> <ptrval> to <pty2> ; yields pty2
  7441. Overview:
  7442. """""""""
  7443. The '``addrspacecast``' instruction converts ``ptrval`` from ``pty`` in
  7444. address space ``n`` to type ``pty2`` in address space ``m``.
  7445. Arguments:
  7446. """"""""""
  7447. The '``addrspacecast``' instruction takes a pointer or vector of pointer value
  7448. to cast and a pointer type to cast it to, which must have a different
  7449. address space.
  7450. Semantics:
  7451. """"""""""
  7452. The '``addrspacecast``' instruction converts the pointer value
  7453. ``ptrval`` to type ``pty2``. It can be a *no-op cast* or a complex
  7454. value modification, depending on the target and the address space
  7455. pair. Pointer conversions within the same address space must be
  7456. performed with the ``bitcast`` instruction. Note that if the address space
  7457. conversion is legal then both result and operand refer to the same memory
  7458. location.
  7459. Example:
  7460. """"""""
  7461. .. code-block:: llvm
  7462. %X = addrspacecast i32* %x to i32 addrspace(1)* ; yields i32 addrspace(1)*:%x
  7463. %Y = addrspacecast i32 addrspace(1)* %y to i64 addrspace(2)* ; yields i64 addrspace(2)*:%y
  7464. %Z = addrspacecast <4 x i32*> %z to <4 x float addrspace(3)*> ; yields <4 x float addrspace(3)*>:%z
  7465. .. _otherops:
  7466. Other Operations
  7467. ----------------
  7468. The instructions in this category are the "miscellaneous" instructions,
  7469. which defy better classification.
  7470. .. _i_icmp:
  7471. '``icmp``' Instruction
  7472. ^^^^^^^^^^^^^^^^^^^^^^
  7473. Syntax:
  7474. """""""
  7475. ::
  7476. <result> = icmp <cond> <ty> <op1>, <op2> ; yields i1 or <N x i1>:result
  7477. Overview:
  7478. """""""""
  7479. The '``icmp``' instruction returns a boolean value or a vector of
  7480. boolean values based on comparison of its two integer, integer vector,
  7481. pointer, or pointer vector operands.
  7482. Arguments:
  7483. """"""""""
  7484. The '``icmp``' instruction takes three operands. The first operand is
  7485. the condition code indicating the kind of comparison to perform. It is
  7486. not a value, just a keyword. The possible condition codes are:
  7487. #. ``eq``: equal
  7488. #. ``ne``: not equal
  7489. #. ``ugt``: unsigned greater than
  7490. #. ``uge``: unsigned greater or equal
  7491. #. ``ult``: unsigned less than
  7492. #. ``ule``: unsigned less or equal
  7493. #. ``sgt``: signed greater than
  7494. #. ``sge``: signed greater or equal
  7495. #. ``slt``: signed less than
  7496. #. ``sle``: signed less or equal
  7497. The remaining two arguments must be :ref:`integer <t_integer>` or
  7498. :ref:`pointer <t_pointer>` or integer :ref:`vector <t_vector>` typed. They
  7499. must also be identical types.
  7500. Semantics:
  7501. """"""""""
  7502. The '``icmp``' compares ``op1`` and ``op2`` according to the condition
  7503. code given as ``cond``. The comparison performed always yields either an
  7504. :ref:`i1 <t_integer>` or vector of ``i1`` result, as follows:
  7505. #. ``eq``: yields ``true`` if the operands are equal, ``false``
  7506. otherwise. No sign interpretation is necessary or performed.
  7507. #. ``ne``: yields ``true`` if the operands are unequal, ``false``
  7508. otherwise. No sign interpretation is necessary or performed.
  7509. #. ``ugt``: interprets the operands as unsigned values and yields
  7510. ``true`` if ``op1`` is greater than ``op2``.
  7511. #. ``uge``: interprets the operands as unsigned values and yields
  7512. ``true`` if ``op1`` is greater than or equal to ``op2``.
  7513. #. ``ult``: interprets the operands as unsigned values and yields
  7514. ``true`` if ``op1`` is less than ``op2``.
  7515. #. ``ule``: interprets the operands as unsigned values and yields
  7516. ``true`` if ``op1`` is less than or equal to ``op2``.
  7517. #. ``sgt``: interprets the operands as signed values and yields ``true``
  7518. if ``op1`` is greater than ``op2``.
  7519. #. ``sge``: interprets the operands as signed values and yields ``true``
  7520. if ``op1`` is greater than or equal to ``op2``.
  7521. #. ``slt``: interprets the operands as signed values and yields ``true``
  7522. if ``op1`` is less than ``op2``.
  7523. #. ``sle``: interprets the operands as signed values and yields ``true``
  7524. if ``op1`` is less than or equal to ``op2``.
  7525. If the operands are :ref:`pointer <t_pointer>` typed, the pointer values
  7526. are compared as if they were integers.
  7527. If the operands are integer vectors, then they are compared element by
  7528. element. The result is an ``i1`` vector with the same number of elements
  7529. as the values being compared. Otherwise, the result is an ``i1``.
  7530. Example:
  7531. """"""""
  7532. .. code-block:: text
  7533. <result> = icmp eq i32 4, 5 ; yields: result=false
  7534. <result> = icmp ne float* %X, %X ; yields: result=false
  7535. <result> = icmp ult i16 4, 5 ; yields: result=true
  7536. <result> = icmp sgt i16 4, 5 ; yields: result=false
  7537. <result> = icmp ule i16 -4, 5 ; yields: result=false
  7538. <result> = icmp sge i16 4, 5 ; yields: result=false
  7539. .. _i_fcmp:
  7540. '``fcmp``' Instruction
  7541. ^^^^^^^^^^^^^^^^^^^^^^
  7542. Syntax:
  7543. """""""
  7544. ::
  7545. <result> = fcmp [fast-math flags]* <cond> <ty> <op1>, <op2> ; yields i1 or <N x i1>:result
  7546. Overview:
  7547. """""""""
  7548. The '``fcmp``' instruction returns a boolean value or vector of boolean
  7549. values based on comparison of its operands.
  7550. If the operands are floating-point scalars, then the result type is a
  7551. boolean (:ref:`i1 <t_integer>`).
  7552. If the operands are floating-point vectors, then the result type is a
  7553. vector of boolean with the same number of elements as the operands being
  7554. compared.
  7555. Arguments:
  7556. """"""""""
  7557. The '``fcmp``' instruction takes three operands. The first operand is
  7558. the condition code indicating the kind of comparison to perform. It is
  7559. not a value, just a keyword. The possible condition codes are:
  7560. #. ``false``: no comparison, always returns false
  7561. #. ``oeq``: ordered and equal
  7562. #. ``ogt``: ordered and greater than
  7563. #. ``oge``: ordered and greater than or equal
  7564. #. ``olt``: ordered and less than
  7565. #. ``ole``: ordered and less than or equal
  7566. #. ``one``: ordered and not equal
  7567. #. ``ord``: ordered (no nans)
  7568. #. ``ueq``: unordered or equal
  7569. #. ``ugt``: unordered or greater than
  7570. #. ``uge``: unordered or greater than or equal
  7571. #. ``ult``: unordered or less than
  7572. #. ``ule``: unordered or less than or equal
  7573. #. ``une``: unordered or not equal
  7574. #. ``uno``: unordered (either nans)
  7575. #. ``true``: no comparison, always returns true
  7576. *Ordered* means that neither operand is a QNAN while *unordered* means
  7577. that either operand may be a QNAN.
  7578. Each of ``val1`` and ``val2`` arguments must be either a :ref:`floating-point
  7579. <t_floating>` type or a :ref:`vector <t_vector>` of floating-point type.
  7580. They must have identical types.
  7581. Semantics:
  7582. """"""""""
  7583. The '``fcmp``' instruction compares ``op1`` and ``op2`` according to the
  7584. condition code given as ``cond``. If the operands are vectors, then the
  7585. vectors are compared element by element. Each comparison performed
  7586. always yields an :ref:`i1 <t_integer>` result, as follows:
  7587. #. ``false``: always yields ``false``, regardless of operands.
  7588. #. ``oeq``: yields ``true`` if both operands are not a QNAN and ``op1``
  7589. is equal to ``op2``.
  7590. #. ``ogt``: yields ``true`` if both operands are not a QNAN and ``op1``
  7591. is greater than ``op2``.
  7592. #. ``oge``: yields ``true`` if both operands are not a QNAN and ``op1``
  7593. is greater than or equal to ``op2``.
  7594. #. ``olt``: yields ``true`` if both operands are not a QNAN and ``op1``
  7595. is less than ``op2``.
  7596. #. ``ole``: yields ``true`` if both operands are not a QNAN and ``op1``
  7597. is less than or equal to ``op2``.
  7598. #. ``one``: yields ``true`` if both operands are not a QNAN and ``op1``
  7599. is not equal to ``op2``.
  7600. #. ``ord``: yields ``true`` if both operands are not a QNAN.
  7601. #. ``ueq``: yields ``true`` if either operand is a QNAN or ``op1`` is
  7602. equal to ``op2``.
  7603. #. ``ugt``: yields ``true`` if either operand is a QNAN or ``op1`` is
  7604. greater than ``op2``.
  7605. #. ``uge``: yields ``true`` if either operand is a QNAN or ``op1`` is
  7606. greater than or equal to ``op2``.
  7607. #. ``ult``: yields ``true`` if either operand is a QNAN or ``op1`` is
  7608. less than ``op2``.
  7609. #. ``ule``: yields ``true`` if either operand is a QNAN or ``op1`` is
  7610. less than or equal to ``op2``.
  7611. #. ``une``: yields ``true`` if either operand is a QNAN or ``op1`` is
  7612. not equal to ``op2``.
  7613. #. ``uno``: yields ``true`` if either operand is a QNAN.
  7614. #. ``true``: always yields ``true``, regardless of operands.
  7615. The ``fcmp`` instruction can also optionally take any number of
  7616. :ref:`fast-math flags <fastmath>`, which are optimization hints to enable
  7617. otherwise unsafe floating-point optimizations.
  7618. Any set of fast-math flags are legal on an ``fcmp`` instruction, but the
  7619. only flags that have any effect on its semantics are those that allow
  7620. assumptions to be made about the values of input arguments; namely
  7621. ``nnan``, ``ninf``, and ``reassoc``. See :ref:`fastmath` for more information.
  7622. Example:
  7623. """"""""
  7624. .. code-block:: text
  7625. <result> = fcmp oeq float 4.0, 5.0 ; yields: result=false
  7626. <result> = fcmp one float 4.0, 5.0 ; yields: result=true
  7627. <result> = fcmp olt float 4.0, 5.0 ; yields: result=true
  7628. <result> = fcmp ueq double 1.0, 2.0 ; yields: result=false
  7629. .. _i_phi:
  7630. '``phi``' Instruction
  7631. ^^^^^^^^^^^^^^^^^^^^^
  7632. Syntax:
  7633. """""""
  7634. ::
  7635. <result> = phi <ty> [ <val0>, <label0>], ...
  7636. Overview:
  7637. """""""""
  7638. The '``phi``' instruction is used to implement the φ node in the SSA
  7639. graph representing the function.
  7640. Arguments:
  7641. """"""""""
  7642. The type of the incoming values is specified with the first type field.
  7643. After this, the '``phi``' instruction takes a list of pairs as
  7644. arguments, with one pair for each predecessor basic block of the current
  7645. block. Only values of :ref:`first class <t_firstclass>` type may be used as
  7646. the value arguments to the PHI node. Only labels may be used as the
  7647. label arguments.
  7648. There must be no non-phi instructions between the start of a basic block
  7649. and the PHI instructions: i.e. PHI instructions must be first in a basic
  7650. block.
  7651. For the purposes of the SSA form, the use of each incoming value is
  7652. deemed to occur on the edge from the corresponding predecessor block to
  7653. the current block (but after any definition of an '``invoke``'
  7654. instruction's return value on the same edge).
  7655. Semantics:
  7656. """"""""""
  7657. At runtime, the '``phi``' instruction logically takes on the value
  7658. specified by the pair corresponding to the predecessor basic block that
  7659. executed just prior to the current block.
  7660. Example:
  7661. """"""""
  7662. .. code-block:: llvm
  7663. Loop: ; Infinite loop that counts from 0 on up...
  7664. %indvar = phi i32 [ 0, %LoopHeader ], [ %nextindvar, %Loop ]
  7665. %nextindvar = add i32 %indvar, 1
  7666. br label %Loop
  7667. .. _i_select:
  7668. '``select``' Instruction
  7669. ^^^^^^^^^^^^^^^^^^^^^^^^
  7670. Syntax:
  7671. """""""
  7672. ::
  7673. <result> = select [fast-math flags] selty <cond>, <ty> <val1>, <ty> <val2> ; yields ty
  7674. selty is either i1 or {<N x i1>}
  7675. Overview:
  7676. """""""""
  7677. The '``select``' instruction is used to choose one value based on a
  7678. condition, without IR-level branching.
  7679. Arguments:
  7680. """"""""""
  7681. The '``select``' instruction requires an 'i1' value or a vector of 'i1'
  7682. values indicating the condition, and two values of the same :ref:`first
  7683. class <t_firstclass>` type.
  7684. #. The optional ``fast-math flags`` marker indicates that the select has one or more
  7685. :ref:`fast-math flags <fastmath>`. These are optimization hints to enable
  7686. otherwise unsafe floating-point optimizations. Fast-math flags are only valid
  7687. for selects that return a floating-point scalar or vector type.
  7688. Semantics:
  7689. """"""""""
  7690. If the condition is an i1 and it evaluates to 1, the instruction returns
  7691. the first value argument; otherwise, it returns the second value
  7692. argument.
  7693. If the condition is a vector of i1, then the value arguments must be
  7694. vectors of the same size, and the selection is done element by element.
  7695. If the condition is an i1 and the value arguments are vectors of the
  7696. same size, then an entire vector is selected.
  7697. Example:
  7698. """"""""
  7699. .. code-block:: llvm
  7700. %X = select i1 true, i8 17, i8 42 ; yields i8:17
  7701. .. _i_call:
  7702. '``call``' Instruction
  7703. ^^^^^^^^^^^^^^^^^^^^^^
  7704. Syntax:
  7705. """""""
  7706. ::
  7707. <result> = [tail | musttail | notail ] call [fast-math flags] [cconv] [ret attrs] [addrspace(<num>)]
  7708. <ty>|<fnty> <fnptrval>(<function args>) [fn attrs] [ operand bundles ]
  7709. Overview:
  7710. """""""""
  7711. The '``call``' instruction represents a simple function call.
  7712. Arguments:
  7713. """"""""""
  7714. This instruction requires several arguments:
  7715. #. The optional ``tail`` and ``musttail`` markers indicate that the optimizers
  7716. should perform tail call optimization. The ``tail`` marker is a hint that
  7717. `can be ignored <CodeGenerator.html#sibcallopt>`_. The ``musttail`` marker
  7718. means that the call must be tail call optimized in order for the program to
  7719. be correct. The ``musttail`` marker provides these guarantees:
  7720. #. The call will not cause unbounded stack growth if it is part of a
  7721. recursive cycle in the call graph.
  7722. #. Arguments with the :ref:`inalloca <attr_inalloca>` attribute are
  7723. forwarded in place.
  7724. #. If the musttail call appears in a function with the ``"thunk"`` attribute
  7725. and the caller and callee both have varargs, than any unprototyped
  7726. arguments in register or memory are forwarded to the callee. Similarly,
  7727. the return value of the callee is returned the the caller's caller, even
  7728. if a void return type is in use.
  7729. Both markers imply that the callee does not access allocas from the caller.
  7730. The ``tail`` marker additionally implies that the callee does not access
  7731. varargs from the caller. Calls marked ``musttail`` must obey the following
  7732. additional rules:
  7733. - The call must immediately precede a :ref:`ret <i_ret>` instruction,
  7734. or a pointer bitcast followed by a ret instruction.
  7735. - The ret instruction must return the (possibly bitcasted) value
  7736. produced by the call or void.
  7737. - The caller and callee prototypes must match. Pointer types of
  7738. parameters or return types may differ in pointee type, but not
  7739. in address space.
  7740. - The calling conventions of the caller and callee must match.
  7741. - All ABI-impacting function attributes, such as sret, byval, inreg,
  7742. returned, and inalloca, must match.
  7743. - The callee must be varargs iff the caller is varargs. Bitcasting a
  7744. non-varargs function to the appropriate varargs type is legal so
  7745. long as the non-varargs prefixes obey the other rules.
  7746. Tail call optimization for calls marked ``tail`` is guaranteed to occur if
  7747. the following conditions are met:
  7748. - Caller and callee both have the calling convention ``fastcc``.
  7749. - The call is in tail position (ret immediately follows call and ret
  7750. uses value of call or is void).
  7751. - Option ``-tailcallopt`` is enabled, or
  7752. ``llvm::GuaranteedTailCallOpt`` is ``true``.
  7753. - `Platform-specific constraints are
  7754. met. <CodeGenerator.html#tailcallopt>`_
  7755. #. The optional ``notail`` marker indicates that the optimizers should not add
  7756. ``tail`` or ``musttail`` markers to the call. It is used to prevent tail
  7757. call optimization from being performed on the call.
  7758. #. The optional ``fast-math flags`` marker indicates that the call has one or more
  7759. :ref:`fast-math flags <fastmath>`, which are optimization hints to enable
  7760. otherwise unsafe floating-point optimizations. Fast-math flags are only valid
  7761. for calls that return a floating-point scalar or vector type.
  7762. #. The optional "cconv" marker indicates which :ref:`calling
  7763. convention <callingconv>` the call should use. If none is
  7764. specified, the call defaults to using C calling conventions. The
  7765. calling convention of the call must match the calling convention of
  7766. the target function, or else the behavior is undefined.
  7767. #. The optional :ref:`Parameter Attributes <paramattrs>` list for return
  7768. values. Only '``zeroext``', '``signext``', and '``inreg``' attributes
  7769. are valid here.
  7770. #. The optional addrspace attribute can be used to indicate the address space
  7771. of the called function. If it is not specified, the program address space
  7772. from the :ref:`datalayout string<langref_datalayout>` will be used.
  7773. #. '``ty``': the type of the call instruction itself which is also the
  7774. type of the return value. Functions that return no value are marked
  7775. ``void``.
  7776. #. '``fnty``': shall be the signature of the function being called. The
  7777. argument types must match the types implied by this signature. This
  7778. type can be omitted if the function is not varargs.
  7779. #. '``fnptrval``': An LLVM value containing a pointer to a function to
  7780. be called. In most cases, this is a direct function call, but
  7781. indirect ``call``'s are just as possible, calling an arbitrary pointer
  7782. to function value.
  7783. #. '``function args``': argument list whose types match the function
  7784. signature argument types and parameter attributes. All arguments must
  7785. be of :ref:`first class <t_firstclass>` type. If the function signature
  7786. indicates the function accepts a variable number of arguments, the
  7787. extra arguments can be specified.
  7788. #. The optional :ref:`function attributes <fnattrs>` list.
  7789. #. The optional :ref:`operand bundles <opbundles>` list.
  7790. Semantics:
  7791. """"""""""
  7792. The '``call``' instruction is used to cause control flow to transfer to
  7793. a specified function, with its incoming arguments bound to the specified
  7794. values. Upon a '``ret``' instruction in the called function, control
  7795. flow continues with the instruction after the function call, and the
  7796. return value of the function is bound to the result argument.
  7797. Example:
  7798. """"""""
  7799. .. code-block:: llvm
  7800. %retval = call i32 @test(i32 %argc)
  7801. call i32 (i8*, ...)* @printf(i8* %msg, i32 12, i8 42) ; yields i32
  7802. %X = tail call i32 @foo() ; yields i32
  7803. %Y = tail call fastcc i32 @foo() ; yields i32
  7804. call void %foo(i8 97 signext)
  7805. %struct.A = type { i32, i8 }
  7806. %r = call %struct.A @foo() ; yields { i32, i8 }
  7807. %gr = extractvalue %struct.A %r, 0 ; yields i32
  7808. %gr1 = extractvalue %struct.A %r, 1 ; yields i8
  7809. %Z = call void @foo() noreturn ; indicates that %foo never returns normally
  7810. %ZZ = call zeroext i32 @bar() ; Return value is %zero extended
  7811. llvm treats calls to some functions with names and arguments that match
  7812. the standard C99 library as being the C99 library functions, and may
  7813. perform optimizations or generate code for them under that assumption.
  7814. This is something we'd like to change in the future to provide better
  7815. support for freestanding environments and non-C-based languages.
  7816. .. _i_va_arg:
  7817. '``va_arg``' Instruction
  7818. ^^^^^^^^^^^^^^^^^^^^^^^^
  7819. Syntax:
  7820. """""""
  7821. ::
  7822. <resultval> = va_arg <va_list*> <arglist>, <argty>
  7823. Overview:
  7824. """""""""
  7825. The '``va_arg``' instruction is used to access arguments passed through
  7826. the "variable argument" area of a function call. It is used to implement
  7827. the ``va_arg`` macro in C.
  7828. Arguments:
  7829. """"""""""
  7830. This instruction takes a ``va_list*`` value and the type of the
  7831. argument. It returns a value of the specified argument type and
  7832. increments the ``va_list`` to point to the next argument. The actual
  7833. type of ``va_list`` is target specific.
  7834. Semantics:
  7835. """"""""""
  7836. The '``va_arg``' instruction loads an argument of the specified type
  7837. from the specified ``va_list`` and causes the ``va_list`` to point to
  7838. the next argument. For more information, see the variable argument
  7839. handling :ref:`Intrinsic Functions <int_varargs>`.
  7840. It is legal for this instruction to be called in a function which does
  7841. not take a variable number of arguments, for example, the ``vfprintf``
  7842. function.
  7843. ``va_arg`` is an LLVM instruction instead of an :ref:`intrinsic
  7844. function <intrinsics>` because it takes a type as an argument.
  7845. Example:
  7846. """"""""
  7847. See the :ref:`variable argument processing <int_varargs>` section.
  7848. Note that the code generator does not yet fully support va\_arg on many
  7849. targets. Also, it does not currently support va\_arg with aggregate
  7850. types on any target.
  7851. .. _i_landingpad:
  7852. '``landingpad``' Instruction
  7853. ^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  7854. Syntax:
  7855. """""""
  7856. ::
  7857. <resultval> = landingpad <resultty> <clause>+
  7858. <resultval> = landingpad <resultty> cleanup <clause>*
  7859. <clause> := catch <type> <value>
  7860. <clause> := filter <array constant type> <array constant>
  7861. Overview:
  7862. """""""""
  7863. The '``landingpad``' instruction is used by `LLVM's exception handling
  7864. system <ExceptionHandling.html#overview>`_ to specify that a basic block
  7865. is a landing pad --- one where the exception lands, and corresponds to the
  7866. code found in the ``catch`` portion of a ``try``/``catch`` sequence. It
  7867. defines values supplied by the :ref:`personality function <personalityfn>` upon
  7868. re-entry to the function. The ``resultval`` has the type ``resultty``.
  7869. Arguments:
  7870. """"""""""
  7871. The optional
  7872. ``cleanup`` flag indicates that the landing pad block is a cleanup.
  7873. A ``clause`` begins with the clause type --- ``catch`` or ``filter`` --- and
  7874. contains the global variable representing the "type" that may be caught
  7875. or filtered respectively. Unlike the ``catch`` clause, the ``filter``
  7876. clause takes an array constant as its argument. Use
  7877. "``[0 x i8**] undef``" for a filter which cannot throw. The
  7878. '``landingpad``' instruction must contain *at least* one ``clause`` or
  7879. the ``cleanup`` flag.
  7880. Semantics:
  7881. """"""""""
  7882. The '``landingpad``' instruction defines the values which are set by the
  7883. :ref:`personality function <personalityfn>` upon re-entry to the function, and
  7884. therefore the "result type" of the ``landingpad`` instruction. As with
  7885. calling conventions, how the personality function results are
  7886. represented in LLVM IR is target specific.
  7887. The clauses are applied in order from top to bottom. If two
  7888. ``landingpad`` instructions are merged together through inlining, the
  7889. clauses from the calling function are appended to the list of clauses.
  7890. When the call stack is being unwound due to an exception being thrown,
  7891. the exception is compared against each ``clause`` in turn. If it doesn't
  7892. match any of the clauses, and the ``cleanup`` flag is not set, then
  7893. unwinding continues further up the call stack.
  7894. The ``landingpad`` instruction has several restrictions:
  7895. - A landing pad block is a basic block which is the unwind destination
  7896. of an '``invoke``' instruction.
  7897. - A landing pad block must have a '``landingpad``' instruction as its
  7898. first non-PHI instruction.
  7899. - There can be only one '``landingpad``' instruction within the landing
  7900. pad block.
  7901. - A basic block that is not a landing pad block may not include a
  7902. '``landingpad``' instruction.
  7903. Example:
  7904. """"""""
  7905. .. code-block:: llvm
  7906. ;; A landing pad which can catch an integer.
  7907. %res = landingpad { i8*, i32 }
  7908. catch i8** @_ZTIi
  7909. ;; A landing pad that is a cleanup.
  7910. %res = landingpad { i8*, i32 }
  7911. cleanup
  7912. ;; A landing pad which can catch an integer and can only throw a double.
  7913. %res = landingpad { i8*, i32 }
  7914. catch i8** @_ZTIi
  7915. filter [1 x i8**] [@_ZTId]
  7916. .. _i_catchpad:
  7917. '``catchpad``' Instruction
  7918. ^^^^^^^^^^^^^^^^^^^^^^^^^^
  7919. Syntax:
  7920. """""""
  7921. ::
  7922. <resultval> = catchpad within <catchswitch> [<args>*]
  7923. Overview:
  7924. """""""""
  7925. The '``catchpad``' instruction is used by `LLVM's exception handling
  7926. system <ExceptionHandling.html#overview>`_ to specify that a basic block
  7927. begins a catch handler --- one where a personality routine attempts to transfer
  7928. control to catch an exception.
  7929. Arguments:
  7930. """"""""""
  7931. The ``catchswitch`` operand must always be a token produced by a
  7932. :ref:`catchswitch <i_catchswitch>` instruction in a predecessor block. This
  7933. ensures that each ``catchpad`` has exactly one predecessor block, and it always
  7934. terminates in a ``catchswitch``.
  7935. The ``args`` correspond to whatever information the personality routine
  7936. requires to know if this is an appropriate handler for the exception. Control
  7937. will transfer to the ``catchpad`` if this is the first appropriate handler for
  7938. the exception.
  7939. The ``resultval`` has the type :ref:`token <t_token>` and is used to match the
  7940. ``catchpad`` to corresponding :ref:`catchrets <i_catchret>` and other nested EH
  7941. pads.
  7942. Semantics:
  7943. """"""""""
  7944. When the call stack is being unwound due to an exception being thrown, the
  7945. exception is compared against the ``args``. If it doesn't match, control will
  7946. not reach the ``catchpad`` instruction. The representation of ``args`` is
  7947. entirely target and personality function-specific.
  7948. Like the :ref:`landingpad <i_landingpad>` instruction, the ``catchpad``
  7949. instruction must be the first non-phi of its parent basic block.
  7950. The meaning of the tokens produced and consumed by ``catchpad`` and other "pad"
  7951. instructions is described in the
  7952. `Windows exception handling documentation\ <ExceptionHandling.html#wineh>`_.
  7953. When a ``catchpad`` has been "entered" but not yet "exited" (as
  7954. described in the `EH documentation\ <ExceptionHandling.html#wineh-constraints>`_),
  7955. it is undefined behavior to execute a :ref:`call <i_call>` or :ref:`invoke <i_invoke>`
  7956. that does not carry an appropriate :ref:`"funclet" bundle <ob_funclet>`.
  7957. Example:
  7958. """"""""
  7959. .. code-block:: text
  7960. dispatch:
  7961. %cs = catchswitch within none [label %handler0] unwind to caller
  7962. ;; A catch block which can catch an integer.
  7963. handler0:
  7964. %tok = catchpad within %cs [i8** @_ZTIi]
  7965. .. _i_cleanuppad:
  7966. '``cleanuppad``' Instruction
  7967. ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  7968. Syntax:
  7969. """""""
  7970. ::
  7971. <resultval> = cleanuppad within <parent> [<args>*]
  7972. Overview:
  7973. """""""""
  7974. The '``cleanuppad``' instruction is used by `LLVM's exception handling
  7975. system <ExceptionHandling.html#overview>`_ to specify that a basic block
  7976. is a cleanup block --- one where a personality routine attempts to
  7977. transfer control to run cleanup actions.
  7978. The ``args`` correspond to whatever additional
  7979. information the :ref:`personality function <personalityfn>` requires to
  7980. execute the cleanup.
  7981. The ``resultval`` has the type :ref:`token <t_token>` and is used to
  7982. match the ``cleanuppad`` to corresponding :ref:`cleanuprets <i_cleanupret>`.
  7983. The ``parent`` argument is the token of the funclet that contains the
  7984. ``cleanuppad`` instruction. If the ``cleanuppad`` is not inside a funclet,
  7985. this operand may be the token ``none``.
  7986. Arguments:
  7987. """"""""""
  7988. The instruction takes a list of arbitrary values which are interpreted
  7989. by the :ref:`personality function <personalityfn>`.
  7990. Semantics:
  7991. """"""""""
  7992. When the call stack is being unwound due to an exception being thrown,
  7993. the :ref:`personality function <personalityfn>` transfers control to the
  7994. ``cleanuppad`` with the aid of the personality-specific arguments.
  7995. As with calling conventions, how the personality function results are
  7996. represented in LLVM IR is target specific.
  7997. The ``cleanuppad`` instruction has several restrictions:
  7998. - A cleanup block is a basic block which is the unwind destination of
  7999. an exceptional instruction.
  8000. - A cleanup block must have a '``cleanuppad``' instruction as its
  8001. first non-PHI instruction.
  8002. - There can be only one '``cleanuppad``' instruction within the
  8003. cleanup block.
  8004. - A basic block that is not a cleanup block may not include a
  8005. '``cleanuppad``' instruction.
  8006. When a ``cleanuppad`` has been "entered" but not yet "exited" (as
  8007. described in the `EH documentation\ <ExceptionHandling.html#wineh-constraints>`_),
  8008. it is undefined behavior to execute a :ref:`call <i_call>` or :ref:`invoke <i_invoke>`
  8009. that does not carry an appropriate :ref:`"funclet" bundle <ob_funclet>`.
  8010. Example:
  8011. """"""""
  8012. .. code-block:: text
  8013. %tok = cleanuppad within %cs []
  8014. .. _intrinsics:
  8015. Intrinsic Functions
  8016. ===================
  8017. LLVM supports the notion of an "intrinsic function". These functions
  8018. have well known names and semantics and are required to follow certain
  8019. restrictions. Overall, these intrinsics represent an extension mechanism
  8020. for the LLVM language that does not require changing all of the
  8021. transformations in LLVM when adding to the language (or the bitcode
  8022. reader/writer, the parser, etc...).
  8023. Intrinsic function names must all start with an "``llvm.``" prefix. This
  8024. prefix is reserved in LLVM for intrinsic names; thus, function names may
  8025. not begin with this prefix. Intrinsic functions must always be external
  8026. functions: you cannot define the body of intrinsic functions. Intrinsic
  8027. functions may only be used in call or invoke instructions: it is illegal
  8028. to take the address of an intrinsic function. Additionally, because
  8029. intrinsic functions are part of the LLVM language, it is required if any
  8030. are added that they be documented here.
  8031. Some intrinsic functions can be overloaded, i.e., the intrinsic
  8032. represents a family of functions that perform the same operation but on
  8033. different data types. Because LLVM can represent over 8 million
  8034. different integer types, overloading is used commonly to allow an
  8035. intrinsic function to operate on any integer type. One or more of the
  8036. argument types or the result type can be overloaded to accept any
  8037. integer type. Argument types may also be defined as exactly matching a
  8038. previous argument's type or the result type. This allows an intrinsic
  8039. function which accepts multiple arguments, but needs all of them to be
  8040. of the same type, to only be overloaded with respect to a single
  8041. argument or the result.
  8042. Overloaded intrinsics will have the names of its overloaded argument
  8043. types encoded into its function name, each preceded by a period. Only
  8044. those types which are overloaded result in a name suffix. Arguments
  8045. whose type is matched against another type do not. For example, the
  8046. ``llvm.ctpop`` function can take an integer of any width and returns an
  8047. integer of exactly the same integer width. This leads to a family of
  8048. functions such as ``i8 @llvm.ctpop.i8(i8 %val)`` and
  8049. ``i29 @llvm.ctpop.i29(i29 %val)``. Only one type, the return type, is
  8050. overloaded, and only one type suffix is required. Because the argument's
  8051. type is matched against the return type, it does not require its own
  8052. name suffix.
  8053. For target developers who are defining intrinsics for back-end code
  8054. generation, any intrinsic overloads based solely the distinction between
  8055. integer or floating point types should not be relied upon for correct
  8056. code generation. In such cases, the recommended approach for target
  8057. maintainers when defining intrinsics is to create separate integer and
  8058. FP intrinsics rather than rely on overloading. For example, if different
  8059. codegen is required for ``llvm.target.foo(<4 x i32>)`` and
  8060. ``llvm.target.foo(<4 x float>)`` then these should be split into
  8061. different intrinsics.
  8062. To learn how to add an intrinsic function, please see the `Extending
  8063. LLVM Guide <ExtendingLLVM.html>`_.
  8064. .. _int_varargs:
  8065. Variable Argument Handling Intrinsics
  8066. -------------------------------------
  8067. Variable argument support is defined in LLVM with the
  8068. :ref:`va_arg <i_va_arg>` instruction and these three intrinsic
  8069. functions. These functions are related to the similarly named macros
  8070. defined in the ``<stdarg.h>`` header file.
  8071. All of these functions operate on arguments that use a target-specific
  8072. value type "``va_list``". The LLVM assembly language reference manual
  8073. does not define what this type is, so all transformations should be
  8074. prepared to handle these functions regardless of the type used.
  8075. This example shows how the :ref:`va_arg <i_va_arg>` instruction and the
  8076. variable argument handling intrinsic functions are used.
  8077. .. code-block:: llvm
  8078. ; This struct is different for every platform. For most platforms,
  8079. ; it is merely an i8*.
  8080. %struct.va_list = type { i8* }
  8081. ; For Unix x86_64 platforms, va_list is the following struct:
  8082. ; %struct.va_list = type { i32, i32, i8*, i8* }
  8083. define i32 @test(i32 %X, ...) {
  8084. ; Initialize variable argument processing
  8085. %ap = alloca %struct.va_list
  8086. %ap2 = bitcast %struct.va_list* %ap to i8*
  8087. call void @llvm.va_start(i8* %ap2)
  8088. ; Read a single integer argument
  8089. %tmp = va_arg i8* %ap2, i32
  8090. ; Demonstrate usage of llvm.va_copy and llvm.va_end
  8091. %aq = alloca i8*
  8092. %aq2 = bitcast i8** %aq to i8*
  8093. call void @llvm.va_copy(i8* %aq2, i8* %ap2)
  8094. call void @llvm.va_end(i8* %aq2)
  8095. ; Stop processing of arguments.
  8096. call void @llvm.va_end(i8* %ap2)
  8097. ret i32 %tmp
  8098. }
  8099. declare void @llvm.va_start(i8*)
  8100. declare void @llvm.va_copy(i8*, i8*)
  8101. declare void @llvm.va_end(i8*)
  8102. .. _int_va_start:
  8103. '``llvm.va_start``' Intrinsic
  8104. ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  8105. Syntax:
  8106. """""""
  8107. ::
  8108. declare void @llvm.va_start(i8* <arglist>)
  8109. Overview:
  8110. """""""""
  8111. The '``llvm.va_start``' intrinsic initializes ``*<arglist>`` for
  8112. subsequent use by ``va_arg``.
  8113. Arguments:
  8114. """"""""""
  8115. The argument is a pointer to a ``va_list`` element to initialize.
  8116. Semantics:
  8117. """"""""""
  8118. The '``llvm.va_start``' intrinsic works just like the ``va_start`` macro
  8119. available in C. In a target-dependent way, it initializes the
  8120. ``va_list`` element to which the argument points, so that the next call
  8121. to ``va_arg`` will produce the first variable argument passed to the
  8122. function. Unlike the C ``va_start`` macro, this intrinsic does not need
  8123. to know the last argument of the function as the compiler can figure
  8124. that out.
  8125. '``llvm.va_end``' Intrinsic
  8126. ^^^^^^^^^^^^^^^^^^^^^^^^^^^
  8127. Syntax:
  8128. """""""
  8129. ::
  8130. declare void @llvm.va_end(i8* <arglist>)
  8131. Overview:
  8132. """""""""
  8133. The '``llvm.va_end``' intrinsic destroys ``*<arglist>``, which has been
  8134. initialized previously with ``llvm.va_start`` or ``llvm.va_copy``.
  8135. Arguments:
  8136. """"""""""
  8137. The argument is a pointer to a ``va_list`` to destroy.
  8138. Semantics:
  8139. """"""""""
  8140. The '``llvm.va_end``' intrinsic works just like the ``va_end`` macro
  8141. available in C. In a target-dependent way, it destroys the ``va_list``
  8142. element to which the argument points. Calls to
  8143. :ref:`llvm.va_start <int_va_start>` and
  8144. :ref:`llvm.va_copy <int_va_copy>` must be matched exactly with calls to
  8145. ``llvm.va_end``.
  8146. .. _int_va_copy:
  8147. '``llvm.va_copy``' Intrinsic
  8148. ^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  8149. Syntax:
  8150. """""""
  8151. ::
  8152. declare void @llvm.va_copy(i8* <destarglist>, i8* <srcarglist>)
  8153. Overview:
  8154. """""""""
  8155. The '``llvm.va_copy``' intrinsic copies the current argument position
  8156. from the source argument list to the destination argument list.
  8157. Arguments:
  8158. """"""""""
  8159. The first argument is a pointer to a ``va_list`` element to initialize.
  8160. The second argument is a pointer to a ``va_list`` element to copy from.
  8161. Semantics:
  8162. """"""""""
  8163. The '``llvm.va_copy``' intrinsic works just like the ``va_copy`` macro
  8164. available in C. In a target-dependent way, it copies the source
  8165. ``va_list`` element into the destination ``va_list`` element. This
  8166. intrinsic is necessary because the `` llvm.va_start`` intrinsic may be
  8167. arbitrarily complex and require, for example, memory allocation.
  8168. Accurate Garbage Collection Intrinsics
  8169. --------------------------------------
  8170. LLVM's support for `Accurate Garbage Collection <GarbageCollection.html>`_
  8171. (GC) requires the frontend to generate code containing appropriate intrinsic
  8172. calls and select an appropriate GC strategy which knows how to lower these
  8173. intrinsics in a manner which is appropriate for the target collector.
  8174. These intrinsics allow identification of :ref:`GC roots on the
  8175. stack <int_gcroot>`, as well as garbage collector implementations that
  8176. require :ref:`read <int_gcread>` and :ref:`write <int_gcwrite>` barriers.
  8177. Frontends for type-safe garbage collected languages should generate
  8178. these intrinsics to make use of the LLVM garbage collectors. For more
  8179. details, see `Garbage Collection with LLVM <GarbageCollection.html>`_.
  8180. Experimental Statepoint Intrinsics
  8181. ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  8182. LLVM provides an second experimental set of intrinsics for describing garbage
  8183. collection safepoints in compiled code. These intrinsics are an alternative
  8184. to the ``llvm.gcroot`` intrinsics, but are compatible with the ones for
  8185. :ref:`read <int_gcread>` and :ref:`write <int_gcwrite>` barriers. The
  8186. differences in approach are covered in the `Garbage Collection with LLVM
  8187. <GarbageCollection.html>`_ documentation. The intrinsics themselves are
  8188. described in :doc:`Statepoints`.
  8189. .. _int_gcroot:
  8190. '``llvm.gcroot``' Intrinsic
  8191. ^^^^^^^^^^^^^^^^^^^^^^^^^^^
  8192. Syntax:
  8193. """""""
  8194. ::
  8195. declare void @llvm.gcroot(i8** %ptrloc, i8* %metadata)
  8196. Overview:
  8197. """""""""
  8198. The '``llvm.gcroot``' intrinsic declares the existence of a GC root to
  8199. the code generator, and allows some metadata to be associated with it.
  8200. Arguments:
  8201. """"""""""
  8202. The first argument specifies the address of a stack object that contains
  8203. the root pointer. The second pointer (which must be either a constant or
  8204. a global value address) contains the meta-data to be associated with the
  8205. root.
  8206. Semantics:
  8207. """"""""""
  8208. At runtime, a call to this intrinsic stores a null pointer into the
  8209. "ptrloc" location. At compile-time, the code generator generates
  8210. information to allow the runtime to find the pointer at GC safe points.
  8211. The '``llvm.gcroot``' intrinsic may only be used in a function which
  8212. :ref:`specifies a GC algorithm <gc>`.
  8213. .. _int_gcread:
  8214. '``llvm.gcread``' Intrinsic
  8215. ^^^^^^^^^^^^^^^^^^^^^^^^^^^
  8216. Syntax:
  8217. """""""
  8218. ::
  8219. declare i8* @llvm.gcread(i8* %ObjPtr, i8** %Ptr)
  8220. Overview:
  8221. """""""""
  8222. The '``llvm.gcread``' intrinsic identifies reads of references from heap
  8223. locations, allowing garbage collector implementations that require read
  8224. barriers.
  8225. Arguments:
  8226. """"""""""
  8227. The second argument is the address to read from, which should be an
  8228. address allocated from the garbage collector. The first object is a
  8229. pointer to the start of the referenced object, if needed by the language
  8230. runtime (otherwise null).
  8231. Semantics:
  8232. """"""""""
  8233. The '``llvm.gcread``' intrinsic has the same semantics as a load
  8234. instruction, but may be replaced with substantially more complex code by
  8235. the garbage collector runtime, as needed. The '``llvm.gcread``'
  8236. intrinsic may only be used in a function which :ref:`specifies a GC
  8237. algorithm <gc>`.
  8238. .. _int_gcwrite:
  8239. '``llvm.gcwrite``' Intrinsic
  8240. ^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  8241. Syntax:
  8242. """""""
  8243. ::
  8244. declare void @llvm.gcwrite(i8* %P1, i8* %Obj, i8** %P2)
  8245. Overview:
  8246. """""""""
  8247. The '``llvm.gcwrite``' intrinsic identifies writes of references to heap
  8248. locations, allowing garbage collector implementations that require write
  8249. barriers (such as generational or reference counting collectors).
  8250. Arguments:
  8251. """"""""""
  8252. The first argument is the reference to store, the second is the start of
  8253. the object to store it to, and the third is the address of the field of
  8254. Obj to store to. If the runtime does not require a pointer to the
  8255. object, Obj may be null.
  8256. Semantics:
  8257. """"""""""
  8258. The '``llvm.gcwrite``' intrinsic has the same semantics as a store
  8259. instruction, but may be replaced with substantially more complex code by
  8260. the garbage collector runtime, as needed. The '``llvm.gcwrite``'
  8261. intrinsic may only be used in a function which :ref:`specifies a GC
  8262. algorithm <gc>`.
  8263. Code Generator Intrinsics
  8264. -------------------------
  8265. These intrinsics are provided by LLVM to expose special features that
  8266. may only be implemented with code generator support.
  8267. '``llvm.returnaddress``' Intrinsic
  8268. ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  8269. Syntax:
  8270. """""""
  8271. ::
  8272. declare i8* @llvm.returnaddress(i32 <level>)
  8273. Overview:
  8274. """""""""
  8275. The '``llvm.returnaddress``' intrinsic attempts to compute a
  8276. target-specific value indicating the return address of the current
  8277. function or one of its callers.
  8278. Arguments:
  8279. """"""""""
  8280. The argument to this intrinsic indicates which function to return the
  8281. address for. Zero indicates the calling function, one indicates its
  8282. caller, etc. The argument is **required** to be a constant integer
  8283. value.
  8284. Semantics:
  8285. """"""""""
  8286. The '``llvm.returnaddress``' intrinsic either returns a pointer
  8287. indicating the return address of the specified call frame, or zero if it
  8288. cannot be identified. The value returned by this intrinsic is likely to
  8289. be incorrect or 0 for arguments other than zero, so it should only be
  8290. used for debugging purposes.
  8291. Note that calling this intrinsic does not prevent function inlining or
  8292. other aggressive transformations, so the value returned may not be that
  8293. of the obvious source-language caller.
  8294. '``llvm.addressofreturnaddress``' Intrinsic
  8295. ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  8296. Syntax:
  8297. """""""
  8298. ::
  8299. declare i8* @llvm.addressofreturnaddress()
  8300. Overview:
  8301. """""""""
  8302. The '``llvm.addressofreturnaddress``' intrinsic returns a target-specific
  8303. pointer to the place in the stack frame where the return address of the
  8304. current function is stored.
  8305. Semantics:
  8306. """"""""""
  8307. Note that calling this intrinsic does not prevent function inlining or
  8308. other aggressive transformations, so the value returned may not be that
  8309. of the obvious source-language caller.
  8310. This intrinsic is only implemented for x86 and aarch64.
  8311. '``llvm.sponentry``' Intrinsic
  8312. ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  8313. Syntax:
  8314. """""""
  8315. ::
  8316. declare i8* @llvm.sponentry()
  8317. Overview:
  8318. """""""""
  8319. The '``llvm.sponentry``' intrinsic returns the stack pointer value at
  8320. the entry of the current function calling this intrinsic.
  8321. Semantics:
  8322. """"""""""
  8323. Note this intrinsic is only verified on AArch64.
  8324. '``llvm.frameaddress``' Intrinsic
  8325. ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  8326. Syntax:
  8327. """""""
  8328. ::
  8329. declare i8* @llvm.frameaddress(i32 <level>)
  8330. Overview:
  8331. """""""""
  8332. The '``llvm.frameaddress``' intrinsic attempts to return the
  8333. target-specific frame pointer value for the specified stack frame.
  8334. Arguments:
  8335. """"""""""
  8336. The argument to this intrinsic indicates which function to return the
  8337. frame pointer for. Zero indicates the calling function, one indicates
  8338. its caller, etc. The argument is **required** to be a constant integer
  8339. value.
  8340. Semantics:
  8341. """"""""""
  8342. The '``llvm.frameaddress``' intrinsic either returns a pointer
  8343. indicating the frame address of the specified call frame, or zero if it
  8344. cannot be identified. The value returned by this intrinsic is likely to
  8345. be incorrect or 0 for arguments other than zero, so it should only be
  8346. used for debugging purposes.
  8347. Note that calling this intrinsic does not prevent function inlining or
  8348. other aggressive transformations, so the value returned may not be that
  8349. of the obvious source-language caller.
  8350. '``llvm.localescape``' and '``llvm.localrecover``' Intrinsics
  8351. ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  8352. Syntax:
  8353. """""""
  8354. ::
  8355. declare void @llvm.localescape(...)
  8356. declare i8* @llvm.localrecover(i8* %func, i8* %fp, i32 %idx)
  8357. Overview:
  8358. """""""""
  8359. The '``llvm.localescape``' intrinsic escapes offsets of a collection of static
  8360. allocas, and the '``llvm.localrecover``' intrinsic applies those offsets to a
  8361. live frame pointer to recover the address of the allocation. The offset is
  8362. computed during frame layout of the caller of ``llvm.localescape``.
  8363. Arguments:
  8364. """"""""""
  8365. All arguments to '``llvm.localescape``' must be pointers to static allocas or
  8366. casts of static allocas. Each function can only call '``llvm.localescape``'
  8367. once, and it can only do so from the entry block.
  8368. The ``func`` argument to '``llvm.localrecover``' must be a constant
  8369. bitcasted pointer to a function defined in the current module. The code
  8370. generator cannot determine the frame allocation offset of functions defined in
  8371. other modules.
  8372. The ``fp`` argument to '``llvm.localrecover``' must be a frame pointer of a
  8373. call frame that is currently live. The return value of '``llvm.localaddress``'
  8374. is one way to produce such a value, but various runtimes also expose a suitable
  8375. pointer in platform-specific ways.
  8376. The ``idx`` argument to '``llvm.localrecover``' indicates which alloca passed to
  8377. '``llvm.localescape``' to recover. It is zero-indexed.
  8378. Semantics:
  8379. """"""""""
  8380. These intrinsics allow a group of functions to share access to a set of local
  8381. stack allocations of a one parent function. The parent function may call the
  8382. '``llvm.localescape``' intrinsic once from the function entry block, and the
  8383. child functions can use '``llvm.localrecover``' to access the escaped allocas.
  8384. The '``llvm.localescape``' intrinsic blocks inlining, as inlining changes where
  8385. the escaped allocas are allocated, which would break attempts to use
  8386. '``llvm.localrecover``'.
  8387. .. _int_read_register:
  8388. .. _int_write_register:
  8389. '``llvm.read_register``' and '``llvm.write_register``' Intrinsics
  8390. ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  8391. Syntax:
  8392. """""""
  8393. ::
  8394. declare i32 @llvm.read_register.i32(metadata)
  8395. declare i64 @llvm.read_register.i64(metadata)
  8396. declare void @llvm.write_register.i32(metadata, i32 @value)
  8397. declare void @llvm.write_register.i64(metadata, i64 @value)
  8398. !0 = !{!"sp\00"}
  8399. Overview:
  8400. """""""""
  8401. The '``llvm.read_register``' and '``llvm.write_register``' intrinsics
  8402. provides access to the named register. The register must be valid on
  8403. the architecture being compiled to. The type needs to be compatible
  8404. with the register being read.
  8405. Semantics:
  8406. """"""""""
  8407. The '``llvm.read_register``' intrinsic returns the current value of the
  8408. register, where possible. The '``llvm.write_register``' intrinsic sets
  8409. the current value of the register, where possible.
  8410. This is useful to implement named register global variables that need
  8411. to always be mapped to a specific register, as is common practice on
  8412. bare-metal programs including OS kernels.
  8413. The compiler doesn't check for register availability or use of the used
  8414. register in surrounding code, including inline assembly. Because of that,
  8415. allocatable registers are not supported.
  8416. Warning: So far it only works with the stack pointer on selected
  8417. architectures (ARM, AArch64, PowerPC and x86_64). Significant amount of
  8418. work is needed to support other registers and even more so, allocatable
  8419. registers.
  8420. .. _int_stacksave:
  8421. '``llvm.stacksave``' Intrinsic
  8422. ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  8423. Syntax:
  8424. """""""
  8425. ::
  8426. declare i8* @llvm.stacksave()
  8427. Overview:
  8428. """""""""
  8429. The '``llvm.stacksave``' intrinsic is used to remember the current state
  8430. of the function stack, for use with
  8431. :ref:`llvm.stackrestore <int_stackrestore>`. This is useful for
  8432. implementing language features like scoped automatic variable sized
  8433. arrays in C99.
  8434. Semantics:
  8435. """"""""""
  8436. This intrinsic returns a opaque pointer value that can be passed to
  8437. :ref:`llvm.stackrestore <int_stackrestore>`. When an
  8438. ``llvm.stackrestore`` intrinsic is executed with a value saved from
  8439. ``llvm.stacksave``, it effectively restores the state of the stack to
  8440. the state it was in when the ``llvm.stacksave`` intrinsic executed. In
  8441. practice, this pops any :ref:`alloca <i_alloca>` blocks from the stack that
  8442. were allocated after the ``llvm.stacksave`` was executed.
  8443. .. _int_stackrestore:
  8444. '``llvm.stackrestore``' Intrinsic
  8445. ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  8446. Syntax:
  8447. """""""
  8448. ::
  8449. declare void @llvm.stackrestore(i8* %ptr)
  8450. Overview:
  8451. """""""""
  8452. The '``llvm.stackrestore``' intrinsic is used to restore the state of
  8453. the function stack to the state it was in when the corresponding
  8454. :ref:`llvm.stacksave <int_stacksave>` intrinsic executed. This is
  8455. useful for implementing language features like scoped automatic variable
  8456. sized arrays in C99.
  8457. Semantics:
  8458. """"""""""
  8459. See the description for :ref:`llvm.stacksave <int_stacksave>`.
  8460. .. _int_get_dynamic_area_offset:
  8461. '``llvm.get.dynamic.area.offset``' Intrinsic
  8462. ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  8463. Syntax:
  8464. """""""
  8465. ::
  8466. declare i32 @llvm.get.dynamic.area.offset.i32()
  8467. declare i64 @llvm.get.dynamic.area.offset.i64()
  8468. Overview:
  8469. """""""""
  8470. The '``llvm.get.dynamic.area.offset.*``' intrinsic family is used to
  8471. get the offset from native stack pointer to the address of the most
  8472. recent dynamic alloca on the caller's stack. These intrinsics are
  8473. intendend for use in combination with
  8474. :ref:`llvm.stacksave <int_stacksave>` to get a
  8475. pointer to the most recent dynamic alloca. This is useful, for example,
  8476. for AddressSanitizer's stack unpoisoning routines.
  8477. Semantics:
  8478. """"""""""
  8479. These intrinsics return a non-negative integer value that can be used to
  8480. get the address of the most recent dynamic alloca, allocated by :ref:`alloca <i_alloca>`
  8481. on the caller's stack. In particular, for targets where stack grows downwards,
  8482. adding this offset to the native stack pointer would get the address of the most
  8483. recent dynamic alloca. For targets where stack grows upwards, the situation is a bit more
  8484. complicated, because subtracting this value from stack pointer would get the address
  8485. one past the end of the most recent dynamic alloca.
  8486. Although for most targets `llvm.get.dynamic.area.offset <int_get_dynamic_area_offset>`
  8487. returns just a zero, for others, such as PowerPC and PowerPC64, it returns a
  8488. compile-time-known constant value.
  8489. The return value type of :ref:`llvm.get.dynamic.area.offset <int_get_dynamic_area_offset>`
  8490. must match the target's default address space's (address space 0) pointer type.
  8491. '``llvm.prefetch``' Intrinsic
  8492. ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  8493. Syntax:
  8494. """""""
  8495. ::
  8496. declare void @llvm.prefetch(i8* <address>, i32 <rw>, i32 <locality>, i32 <cache type>)
  8497. Overview:
  8498. """""""""
  8499. The '``llvm.prefetch``' intrinsic is a hint to the code generator to
  8500. insert a prefetch instruction if supported; otherwise, it is a noop.
  8501. Prefetches have no effect on the behavior of the program but can change
  8502. its performance characteristics.
  8503. Arguments:
  8504. """"""""""
  8505. ``address`` is the address to be prefetched, ``rw`` is the specifier
  8506. determining if the fetch should be for a read (0) or write (1), and
  8507. ``locality`` is a temporal locality specifier ranging from (0) - no
  8508. locality, to (3) - extremely local keep in cache. The ``cache type``
  8509. specifies whether the prefetch is performed on the data (1) or
  8510. instruction (0) cache. The ``rw``, ``locality`` and ``cache type``
  8511. arguments must be constant integers.
  8512. Semantics:
  8513. """"""""""
  8514. This intrinsic does not modify the behavior of the program. In
  8515. particular, prefetches cannot trap and do not produce a value. On
  8516. targets that support this intrinsic, the prefetch can provide hints to
  8517. the processor cache for better performance.
  8518. '``llvm.pcmarker``' Intrinsic
  8519. ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  8520. Syntax:
  8521. """""""
  8522. ::
  8523. declare void @llvm.pcmarker(i32 <id>)
  8524. Overview:
  8525. """""""""
  8526. The '``llvm.pcmarker``' intrinsic is a method to export a Program
  8527. Counter (PC) in a region of code to simulators and other tools. The
  8528. method is target specific, but it is expected that the marker will use
  8529. exported symbols to transmit the PC of the marker. The marker makes no
  8530. guarantees that it will remain with any specific instruction after
  8531. optimizations. It is possible that the presence of a marker will inhibit
  8532. optimizations. The intended use is to be inserted after optimizations to
  8533. allow correlations of simulation runs.
  8534. Arguments:
  8535. """"""""""
  8536. ``id`` is a numerical id identifying the marker.
  8537. Semantics:
  8538. """"""""""
  8539. This intrinsic does not modify the behavior of the program. Backends
  8540. that do not support this intrinsic may ignore it.
  8541. '``llvm.readcyclecounter``' Intrinsic
  8542. ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  8543. Syntax:
  8544. """""""
  8545. ::
  8546. declare i64 @llvm.readcyclecounter()
  8547. Overview:
  8548. """""""""
  8549. The '``llvm.readcyclecounter``' intrinsic provides access to the cycle
  8550. counter register (or similar low latency, high accuracy clocks) on those
  8551. targets that support it. On X86, it should map to RDTSC. On Alpha, it
  8552. should map to RPCC. As the backing counters overflow quickly (on the
  8553. order of 9 seconds on alpha), this should only be used for small
  8554. timings.
  8555. Semantics:
  8556. """"""""""
  8557. When directly supported, reading the cycle counter should not modify any
  8558. memory. Implementations are allowed to either return a application
  8559. specific value or a system wide value. On backends without support, this
  8560. is lowered to a constant 0.
  8561. Note that runtime support may be conditional on the privilege-level code is
  8562. running at and the host platform.
  8563. '``llvm.clear_cache``' Intrinsic
  8564. ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  8565. Syntax:
  8566. """""""
  8567. ::
  8568. declare void @llvm.clear_cache(i8*, i8*)
  8569. Overview:
  8570. """""""""
  8571. The '``llvm.clear_cache``' intrinsic ensures visibility of modifications
  8572. in the specified range to the execution unit of the processor. On
  8573. targets with non-unified instruction and data cache, the implementation
  8574. flushes the instruction cache.
  8575. Semantics:
  8576. """"""""""
  8577. On platforms with coherent instruction and data caches (e.g. x86), this
  8578. intrinsic is a nop. On platforms with non-coherent instruction and data
  8579. cache (e.g. ARM, MIPS), the intrinsic is lowered either to appropriate
  8580. instructions or a system call, if cache flushing requires special
  8581. privileges.
  8582. The default behavior is to emit a call to ``__clear_cache`` from the run
  8583. time library.
  8584. This intrinsic does *not* empty the instruction pipeline. Modifications
  8585. of the current function are outside the scope of the intrinsic.
  8586. '``llvm.instrprof.increment``' Intrinsic
  8587. ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  8588. Syntax:
  8589. """""""
  8590. ::
  8591. declare void @llvm.instrprof.increment(i8* <name>, i64 <hash>,
  8592. i32 <num-counters>, i32 <index>)
  8593. Overview:
  8594. """""""""
  8595. The '``llvm.instrprof.increment``' intrinsic can be emitted by a
  8596. frontend for use with instrumentation based profiling. These will be
  8597. lowered by the ``-instrprof`` pass to generate execution counts of a
  8598. program at runtime.
  8599. Arguments:
  8600. """"""""""
  8601. The first argument is a pointer to a global variable containing the
  8602. name of the entity being instrumented. This should generally be the
  8603. (mangled) function name for a set of counters.
  8604. The second argument is a hash value that can be used by the consumer
  8605. of the profile data to detect changes to the instrumented source, and
  8606. the third is the number of counters associated with ``name``. It is an
  8607. error if ``hash`` or ``num-counters`` differ between two instances of
  8608. ``instrprof.increment`` that refer to the same name.
  8609. The last argument refers to which of the counters for ``name`` should
  8610. be incremented. It should be a value between 0 and ``num-counters``.
  8611. Semantics:
  8612. """"""""""
  8613. This intrinsic represents an increment of a profiling counter. It will
  8614. cause the ``-instrprof`` pass to generate the appropriate data
  8615. structures and the code to increment the appropriate value, in a
  8616. format that can be written out by a compiler runtime and consumed via
  8617. the ``llvm-profdata`` tool.
  8618. '``llvm.instrprof.increment.step``' Intrinsic
  8619. ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  8620. Syntax:
  8621. """""""
  8622. ::
  8623. declare void @llvm.instrprof.increment.step(i8* <name>, i64 <hash>,
  8624. i32 <num-counters>,
  8625. i32 <index>, i64 <step>)
  8626. Overview:
  8627. """""""""
  8628. The '``llvm.instrprof.increment.step``' intrinsic is an extension to
  8629. the '``llvm.instrprof.increment``' intrinsic with an additional fifth
  8630. argument to specify the step of the increment.
  8631. Arguments:
  8632. """"""""""
  8633. The first four arguments are the same as '``llvm.instrprof.increment``'
  8634. intrinsic.
  8635. The last argument specifies the value of the increment of the counter variable.
  8636. Semantics:
  8637. """"""""""
  8638. See description of '``llvm.instrprof.increment``' intrinsic.
  8639. '``llvm.instrprof.value.profile``' Intrinsic
  8640. ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  8641. Syntax:
  8642. """""""
  8643. ::
  8644. declare void @llvm.instrprof.value.profile(i8* <name>, i64 <hash>,
  8645. i64 <value>, i32 <value_kind>,
  8646. i32 <index>)
  8647. Overview:
  8648. """""""""
  8649. The '``llvm.instrprof.value.profile``' intrinsic can be emitted by a
  8650. frontend for use with instrumentation based profiling. This will be
  8651. lowered by the ``-instrprof`` pass to find out the target values,
  8652. instrumented expressions take in a program at runtime.
  8653. Arguments:
  8654. """"""""""
  8655. The first argument is a pointer to a global variable containing the
  8656. name of the entity being instrumented. ``name`` should generally be the
  8657. (mangled) function name for a set of counters.
  8658. The second argument is a hash value that can be used by the consumer
  8659. of the profile data to detect changes to the instrumented source. It
  8660. is an error if ``hash`` differs between two instances of
  8661. ``llvm.instrprof.*`` that refer to the same name.
  8662. The third argument is the value of the expression being profiled. The profiled
  8663. expression's value should be representable as an unsigned 64-bit value. The
  8664. fourth argument represents the kind of value profiling that is being done. The
  8665. supported value profiling kinds are enumerated through the
  8666. ``InstrProfValueKind`` type declared in the
  8667. ``<include/llvm/ProfileData/InstrProf.h>`` header file. The last argument is the
  8668. index of the instrumented expression within ``name``. It should be >= 0.
  8669. Semantics:
  8670. """"""""""
  8671. This intrinsic represents the point where a call to a runtime routine
  8672. should be inserted for value profiling of target expressions. ``-instrprof``
  8673. pass will generate the appropriate data structures and replace the
  8674. ``llvm.instrprof.value.profile`` intrinsic with the call to the profile
  8675. runtime library with proper arguments.
  8676. '``llvm.thread.pointer``' Intrinsic
  8677. ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  8678. Syntax:
  8679. """""""
  8680. ::
  8681. declare i8* @llvm.thread.pointer()
  8682. Overview:
  8683. """""""""
  8684. The '``llvm.thread.pointer``' intrinsic returns the value of the thread
  8685. pointer.
  8686. Semantics:
  8687. """"""""""
  8688. The '``llvm.thread.pointer``' intrinsic returns a pointer to the TLS area
  8689. for the current thread. The exact semantics of this value are target
  8690. specific: it may point to the start of TLS area, to the end, or somewhere
  8691. in the middle. Depending on the target, this intrinsic may read a register,
  8692. call a helper function, read from an alternate memory space, or perform
  8693. other operations necessary to locate the TLS area. Not all targets support
  8694. this intrinsic.
  8695. Standard C Library Intrinsics
  8696. -----------------------------
  8697. LLVM provides intrinsics for a few important standard C library
  8698. functions. These intrinsics allow source-language front-ends to pass
  8699. information about the alignment of the pointer arguments to the code
  8700. generator, providing opportunity for more efficient code generation.
  8701. .. _int_memcpy:
  8702. '``llvm.memcpy``' Intrinsic
  8703. ^^^^^^^^^^^^^^^^^^^^^^^^^^^
  8704. Syntax:
  8705. """""""
  8706. This is an overloaded intrinsic. You can use ``llvm.memcpy`` on any
  8707. integer bit width and for different address spaces. Not all targets
  8708. support all bit widths however.
  8709. ::
  8710. declare void @llvm.memcpy.p0i8.p0i8.i32(i8* <dest>, i8* <src>,
  8711. i32 <len>, i1 <isvolatile>)
  8712. declare void @llvm.memcpy.p0i8.p0i8.i64(i8* <dest>, i8* <src>,
  8713. i64 <len>, i1 <isvolatile>)
  8714. Overview:
  8715. """""""""
  8716. The '``llvm.memcpy.*``' intrinsics copy a block of memory from the
  8717. source location to the destination location.
  8718. Note that, unlike the standard libc function, the ``llvm.memcpy.*``
  8719. intrinsics do not return a value, takes extra isvolatile
  8720. arguments and the pointers can be in specified address spaces.
  8721. Arguments:
  8722. """"""""""
  8723. The first argument is a pointer to the destination, the second is a
  8724. pointer to the source. The third argument is an integer argument
  8725. specifying the number of bytes to copy, and the fourth is a
  8726. boolean indicating a volatile access.
  8727. The :ref:`align <attr_align>` parameter attribute can be provided
  8728. for the first and second arguments.
  8729. If the ``isvolatile`` parameter is ``true``, the ``llvm.memcpy`` call is
  8730. a :ref:`volatile operation <volatile>`. The detailed access behavior is not
  8731. very cleanly specified and it is unwise to depend on it.
  8732. Semantics:
  8733. """"""""""
  8734. The '``llvm.memcpy.*``' intrinsics copy a block of memory from the
  8735. source location to the destination location, which are not allowed to
  8736. overlap. It copies "len" bytes of memory over. If the argument is known
  8737. to be aligned to some boundary, this can be specified as an attribute on
  8738. the argument.
  8739. If "len" is 0, the pointers may be NULL or dangling. However, they must still
  8740. be appropriately aligned.
  8741. .. _int_memmove:
  8742. '``llvm.memmove``' Intrinsic
  8743. ^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  8744. Syntax:
  8745. """""""
  8746. This is an overloaded intrinsic. You can use llvm.memmove on any integer
  8747. bit width and for different address space. Not all targets support all
  8748. bit widths however.
  8749. ::
  8750. declare void @llvm.memmove.p0i8.p0i8.i32(i8* <dest>, i8* <src>,
  8751. i32 <len>, i1 <isvolatile>)
  8752. declare void @llvm.memmove.p0i8.p0i8.i64(i8* <dest>, i8* <src>,
  8753. i64 <len>, i1 <isvolatile>)
  8754. Overview:
  8755. """""""""
  8756. The '``llvm.memmove.*``' intrinsics move a block of memory from the
  8757. source location to the destination location. It is similar to the
  8758. '``llvm.memcpy``' intrinsic but allows the two memory locations to
  8759. overlap.
  8760. Note that, unlike the standard libc function, the ``llvm.memmove.*``
  8761. intrinsics do not return a value, takes an extra isvolatile
  8762. argument and the pointers can be in specified address spaces.
  8763. Arguments:
  8764. """"""""""
  8765. The first argument is a pointer to the destination, the second is a
  8766. pointer to the source. The third argument is an integer argument
  8767. specifying the number of bytes to copy, and the fourth is a
  8768. boolean indicating a volatile access.
  8769. The :ref:`align <attr_align>` parameter attribute can be provided
  8770. for the first and second arguments.
  8771. If the ``isvolatile`` parameter is ``true``, the ``llvm.memmove`` call
  8772. is a :ref:`volatile operation <volatile>`. The detailed access behavior is
  8773. not very cleanly specified and it is unwise to depend on it.
  8774. Semantics:
  8775. """"""""""
  8776. The '``llvm.memmove.*``' intrinsics copy a block of memory from the
  8777. source location to the destination location, which may overlap. It
  8778. copies "len" bytes of memory over. If the argument is known to be
  8779. aligned to some boundary, this can be specified as an attribute on
  8780. the argument.
  8781. If "len" is 0, the pointers may be NULL or dangling. However, they must still
  8782. be appropriately aligned.
  8783. .. _int_memset:
  8784. '``llvm.memset.*``' Intrinsics
  8785. ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  8786. Syntax:
  8787. """""""
  8788. This is an overloaded intrinsic. You can use llvm.memset on any integer
  8789. bit width and for different address spaces. However, not all targets
  8790. support all bit widths.
  8791. ::
  8792. declare void @llvm.memset.p0i8.i32(i8* <dest>, i8 <val>,
  8793. i32 <len>, i1 <isvolatile>)
  8794. declare void @llvm.memset.p0i8.i64(i8* <dest>, i8 <val>,
  8795. i64 <len>, i1 <isvolatile>)
  8796. Overview:
  8797. """""""""
  8798. The '``llvm.memset.*``' intrinsics fill a block of memory with a
  8799. particular byte value.
  8800. Note that, unlike the standard libc function, the ``llvm.memset``
  8801. intrinsic does not return a value and takes an extra volatile
  8802. argument. Also, the destination can be in an arbitrary address space.
  8803. Arguments:
  8804. """"""""""
  8805. The first argument is a pointer to the destination to fill, the second
  8806. is the byte value with which to fill it, the third argument is an
  8807. integer argument specifying the number of bytes to fill, and the fourth
  8808. is a boolean indicating a volatile access.
  8809. The :ref:`align <attr_align>` parameter attribute can be provided
  8810. for the first arguments.
  8811. If the ``isvolatile`` parameter is ``true``, the ``llvm.memset`` call is
  8812. a :ref:`volatile operation <volatile>`. The detailed access behavior is not
  8813. very cleanly specified and it is unwise to depend on it.
  8814. Semantics:
  8815. """"""""""
  8816. The '``llvm.memset.*``' intrinsics fill "len" bytes of memory starting
  8817. at the destination location. If the argument is known to be
  8818. aligned to some boundary, this can be specified as an attribute on
  8819. the argument.
  8820. If "len" is 0, the pointers may be NULL or dangling. However, they must still
  8821. be appropriately aligned.
  8822. '``llvm.sqrt.*``' Intrinsic
  8823. ^^^^^^^^^^^^^^^^^^^^^^^^^^^
  8824. Syntax:
  8825. """""""
  8826. This is an overloaded intrinsic. You can use ``llvm.sqrt`` on any
  8827. floating-point or vector of floating-point type. Not all targets support
  8828. all types however.
  8829. ::
  8830. declare float @llvm.sqrt.f32(float %Val)
  8831. declare double @llvm.sqrt.f64(double %Val)
  8832. declare x86_fp80 @llvm.sqrt.f80(x86_fp80 %Val)
  8833. declare fp128 @llvm.sqrt.f128(fp128 %Val)
  8834. declare ppc_fp128 @llvm.sqrt.ppcf128(ppc_fp128 %Val)
  8835. Overview:
  8836. """""""""
  8837. The '``llvm.sqrt``' intrinsics return the square root of the specified value.
  8838. Arguments:
  8839. """"""""""
  8840. The argument and return value are floating-point numbers of the same type.
  8841. Semantics:
  8842. """"""""""
  8843. Return the same value as a corresponding libm '``sqrt``' function but without
  8844. trapping or setting ``errno``. For types specified by IEEE-754, the result
  8845. matches a conforming libm implementation.
  8846. When specified with the fast-math-flag 'afn', the result may be approximated
  8847. using a less accurate calculation.
  8848. '``llvm.powi.*``' Intrinsic
  8849. ^^^^^^^^^^^^^^^^^^^^^^^^^^^
  8850. Syntax:
  8851. """""""
  8852. This is an overloaded intrinsic. You can use ``llvm.powi`` on any
  8853. floating-point or vector of floating-point type. Not all targets support
  8854. all types however.
  8855. ::
  8856. declare float @llvm.powi.f32(float %Val, i32 %power)
  8857. declare double @llvm.powi.f64(double %Val, i32 %power)
  8858. declare x86_fp80 @llvm.powi.f80(x86_fp80 %Val, i32 %power)
  8859. declare fp128 @llvm.powi.f128(fp128 %Val, i32 %power)
  8860. declare ppc_fp128 @llvm.powi.ppcf128(ppc_fp128 %Val, i32 %power)
  8861. Overview:
  8862. """""""""
  8863. The '``llvm.powi.*``' intrinsics return the first operand raised to the
  8864. specified (positive or negative) power. The order of evaluation of
  8865. multiplications is not defined. When a vector of floating-point type is
  8866. used, the second argument remains a scalar integer value.
  8867. Arguments:
  8868. """"""""""
  8869. The second argument is an integer power, and the first is a value to
  8870. raise to that power.
  8871. Semantics:
  8872. """"""""""
  8873. This function returns the first value raised to the second power with an
  8874. unspecified sequence of rounding operations.
  8875. '``llvm.sin.*``' Intrinsic
  8876. ^^^^^^^^^^^^^^^^^^^^^^^^^^
  8877. Syntax:
  8878. """""""
  8879. This is an overloaded intrinsic. You can use ``llvm.sin`` on any
  8880. floating-point or vector of floating-point type. Not all targets support
  8881. all types however.
  8882. ::
  8883. declare float @llvm.sin.f32(float %Val)
  8884. declare double @llvm.sin.f64(double %Val)
  8885. declare x86_fp80 @llvm.sin.f80(x86_fp80 %Val)
  8886. declare fp128 @llvm.sin.f128(fp128 %Val)
  8887. declare ppc_fp128 @llvm.sin.ppcf128(ppc_fp128 %Val)
  8888. Overview:
  8889. """""""""
  8890. The '``llvm.sin.*``' intrinsics return the sine of the operand.
  8891. Arguments:
  8892. """"""""""
  8893. The argument and return value are floating-point numbers of the same type.
  8894. Semantics:
  8895. """"""""""
  8896. Return the same value as a corresponding libm '``sin``' function but without
  8897. trapping or setting ``errno``.
  8898. When specified with the fast-math-flag 'afn', the result may be approximated
  8899. using a less accurate calculation.
  8900. '``llvm.cos.*``' Intrinsic
  8901. ^^^^^^^^^^^^^^^^^^^^^^^^^^
  8902. Syntax:
  8903. """""""
  8904. This is an overloaded intrinsic. You can use ``llvm.cos`` on any
  8905. floating-point or vector of floating-point type. Not all targets support
  8906. all types however.
  8907. ::
  8908. declare float @llvm.cos.f32(float %Val)
  8909. declare double @llvm.cos.f64(double %Val)
  8910. declare x86_fp80 @llvm.cos.f80(x86_fp80 %Val)
  8911. declare fp128 @llvm.cos.f128(fp128 %Val)
  8912. declare ppc_fp128 @llvm.cos.ppcf128(ppc_fp128 %Val)
  8913. Overview:
  8914. """""""""
  8915. The '``llvm.cos.*``' intrinsics return the cosine of the operand.
  8916. Arguments:
  8917. """"""""""
  8918. The argument and return value are floating-point numbers of the same type.
  8919. Semantics:
  8920. """"""""""
  8921. Return the same value as a corresponding libm '``cos``' function but without
  8922. trapping or setting ``errno``.
  8923. When specified with the fast-math-flag 'afn', the result may be approximated
  8924. using a less accurate calculation.
  8925. '``llvm.pow.*``' Intrinsic
  8926. ^^^^^^^^^^^^^^^^^^^^^^^^^^
  8927. Syntax:
  8928. """""""
  8929. This is an overloaded intrinsic. You can use ``llvm.pow`` on any
  8930. floating-point or vector of floating-point type. Not all targets support
  8931. all types however.
  8932. ::
  8933. declare float @llvm.pow.f32(float %Val, float %Power)
  8934. declare double @llvm.pow.f64(double %Val, double %Power)
  8935. declare x86_fp80 @llvm.pow.f80(x86_fp80 %Val, x86_fp80 %Power)
  8936. declare fp128 @llvm.pow.f128(fp128 %Val, fp128 %Power)
  8937. declare ppc_fp128 @llvm.pow.ppcf128(ppc_fp128 %Val, ppc_fp128 Power)
  8938. Overview:
  8939. """""""""
  8940. The '``llvm.pow.*``' intrinsics return the first operand raised to the
  8941. specified (positive or negative) power.
  8942. Arguments:
  8943. """"""""""
  8944. The arguments and return value are floating-point numbers of the same type.
  8945. Semantics:
  8946. """"""""""
  8947. Return the same value as a corresponding libm '``pow``' function but without
  8948. trapping or setting ``errno``.
  8949. When specified with the fast-math-flag 'afn', the result may be approximated
  8950. using a less accurate calculation.
  8951. '``llvm.exp.*``' Intrinsic
  8952. ^^^^^^^^^^^^^^^^^^^^^^^^^^
  8953. Syntax:
  8954. """""""
  8955. This is an overloaded intrinsic. You can use ``llvm.exp`` on any
  8956. floating-point or vector of floating-point type. Not all targets support
  8957. all types however.
  8958. ::
  8959. declare float @llvm.exp.f32(float %Val)
  8960. declare double @llvm.exp.f64(double %Val)
  8961. declare x86_fp80 @llvm.exp.f80(x86_fp80 %Val)
  8962. declare fp128 @llvm.exp.f128(fp128 %Val)
  8963. declare ppc_fp128 @llvm.exp.ppcf128(ppc_fp128 %Val)
  8964. Overview:
  8965. """""""""
  8966. The '``llvm.exp.*``' intrinsics compute the base-e exponential of the specified
  8967. value.
  8968. Arguments:
  8969. """"""""""
  8970. The argument and return value are floating-point numbers of the same type.
  8971. Semantics:
  8972. """"""""""
  8973. Return the same value as a corresponding libm '``exp``' function but without
  8974. trapping or setting ``errno``.
  8975. When specified with the fast-math-flag 'afn', the result may be approximated
  8976. using a less accurate calculation.
  8977. '``llvm.exp2.*``' Intrinsic
  8978. ^^^^^^^^^^^^^^^^^^^^^^^^^^^
  8979. Syntax:
  8980. """""""
  8981. This is an overloaded intrinsic. You can use ``llvm.exp2`` on any
  8982. floating-point or vector of floating-point type. Not all targets support
  8983. all types however.
  8984. ::
  8985. declare float @llvm.exp2.f32(float %Val)
  8986. declare double @llvm.exp2.f64(double %Val)
  8987. declare x86_fp80 @llvm.exp2.f80(x86_fp80 %Val)
  8988. declare fp128 @llvm.exp2.f128(fp128 %Val)
  8989. declare ppc_fp128 @llvm.exp2.ppcf128(ppc_fp128 %Val)
  8990. Overview:
  8991. """""""""
  8992. The '``llvm.exp2.*``' intrinsics compute the base-2 exponential of the
  8993. specified value.
  8994. Arguments:
  8995. """"""""""
  8996. The argument and return value are floating-point numbers of the same type.
  8997. Semantics:
  8998. """"""""""
  8999. Return the same value as a corresponding libm '``exp2``' function but without
  9000. trapping or setting ``errno``.
  9001. When specified with the fast-math-flag 'afn', the result may be approximated
  9002. using a less accurate calculation.
  9003. '``llvm.log.*``' Intrinsic
  9004. ^^^^^^^^^^^^^^^^^^^^^^^^^^
  9005. Syntax:
  9006. """""""
  9007. This is an overloaded intrinsic. You can use ``llvm.log`` on any
  9008. floating-point or vector of floating-point type. Not all targets support
  9009. all types however.
  9010. ::
  9011. declare float @llvm.log.f32(float %Val)
  9012. declare double @llvm.log.f64(double %Val)
  9013. declare x86_fp80 @llvm.log.f80(x86_fp80 %Val)
  9014. declare fp128 @llvm.log.f128(fp128 %Val)
  9015. declare ppc_fp128 @llvm.log.ppcf128(ppc_fp128 %Val)
  9016. Overview:
  9017. """""""""
  9018. The '``llvm.log.*``' intrinsics compute the base-e logarithm of the specified
  9019. value.
  9020. Arguments:
  9021. """"""""""
  9022. The argument and return value are floating-point numbers of the same type.
  9023. Semantics:
  9024. """"""""""
  9025. Return the same value as a corresponding libm '``log``' function but without
  9026. trapping or setting ``errno``.
  9027. When specified with the fast-math-flag 'afn', the result may be approximated
  9028. using a less accurate calculation.
  9029. '``llvm.log10.*``' Intrinsic
  9030. ^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  9031. Syntax:
  9032. """""""
  9033. This is an overloaded intrinsic. You can use ``llvm.log10`` on any
  9034. floating-point or vector of floating-point type. Not all targets support
  9035. all types however.
  9036. ::
  9037. declare float @llvm.log10.f32(float %Val)
  9038. declare double @llvm.log10.f64(double %Val)
  9039. declare x86_fp80 @llvm.log10.f80(x86_fp80 %Val)
  9040. declare fp128 @llvm.log10.f128(fp128 %Val)
  9041. declare ppc_fp128 @llvm.log10.ppcf128(ppc_fp128 %Val)
  9042. Overview:
  9043. """""""""
  9044. The '``llvm.log10.*``' intrinsics compute the base-10 logarithm of the
  9045. specified value.
  9046. Arguments:
  9047. """"""""""
  9048. The argument and return value are floating-point numbers of the same type.
  9049. Semantics:
  9050. """"""""""
  9051. Return the same value as a corresponding libm '``log10``' function but without
  9052. trapping or setting ``errno``.
  9053. When specified with the fast-math-flag 'afn', the result may be approximated
  9054. using a less accurate calculation.
  9055. '``llvm.log2.*``' Intrinsic
  9056. ^^^^^^^^^^^^^^^^^^^^^^^^^^^
  9057. Syntax:
  9058. """""""
  9059. This is an overloaded intrinsic. You can use ``llvm.log2`` on any
  9060. floating-point or vector of floating-point type. Not all targets support
  9061. all types however.
  9062. ::
  9063. declare float @llvm.log2.f32(float %Val)
  9064. declare double @llvm.log2.f64(double %Val)
  9065. declare x86_fp80 @llvm.log2.f80(x86_fp80 %Val)
  9066. declare fp128 @llvm.log2.f128(fp128 %Val)
  9067. declare ppc_fp128 @llvm.log2.ppcf128(ppc_fp128 %Val)
  9068. Overview:
  9069. """""""""
  9070. The '``llvm.log2.*``' intrinsics compute the base-2 logarithm of the specified
  9071. value.
  9072. Arguments:
  9073. """"""""""
  9074. The argument and return value are floating-point numbers of the same type.
  9075. Semantics:
  9076. """"""""""
  9077. Return the same value as a corresponding libm '``log2``' function but without
  9078. trapping or setting ``errno``.
  9079. When specified with the fast-math-flag 'afn', the result may be approximated
  9080. using a less accurate calculation.
  9081. .. _int_fma:
  9082. '``llvm.fma.*``' Intrinsic
  9083. ^^^^^^^^^^^^^^^^^^^^^^^^^^
  9084. Syntax:
  9085. """""""
  9086. This is an overloaded intrinsic. You can use ``llvm.fma`` on any
  9087. floating-point or vector of floating-point type. Not all targets support
  9088. all types however.
  9089. ::
  9090. declare float @llvm.fma.f32(float %a, float %b, float %c)
  9091. declare double @llvm.fma.f64(double %a, double %b, double %c)
  9092. declare x86_fp80 @llvm.fma.f80(x86_fp80 %a, x86_fp80 %b, x86_fp80 %c)
  9093. declare fp128 @llvm.fma.f128(fp128 %a, fp128 %b, fp128 %c)
  9094. declare ppc_fp128 @llvm.fma.ppcf128(ppc_fp128 %a, ppc_fp128 %b, ppc_fp128 %c)
  9095. Overview:
  9096. """""""""
  9097. The '``llvm.fma.*``' intrinsics perform the fused multiply-add operation.
  9098. Arguments:
  9099. """"""""""
  9100. The arguments and return value are floating-point numbers of the same type.
  9101. Semantics:
  9102. """"""""""
  9103. Return the same value as a corresponding libm '``fma``' function but without
  9104. trapping or setting ``errno``.
  9105. When specified with the fast-math-flag 'afn', the result may be approximated
  9106. using a less accurate calculation.
  9107. '``llvm.fabs.*``' Intrinsic
  9108. ^^^^^^^^^^^^^^^^^^^^^^^^^^^
  9109. Syntax:
  9110. """""""
  9111. This is an overloaded intrinsic. You can use ``llvm.fabs`` on any
  9112. floating-point or vector of floating-point type. Not all targets support
  9113. all types however.
  9114. ::
  9115. declare float @llvm.fabs.f32(float %Val)
  9116. declare double @llvm.fabs.f64(double %Val)
  9117. declare x86_fp80 @llvm.fabs.f80(x86_fp80 %Val)
  9118. declare fp128 @llvm.fabs.f128(fp128 %Val)
  9119. declare ppc_fp128 @llvm.fabs.ppcf128(ppc_fp128 %Val)
  9120. Overview:
  9121. """""""""
  9122. The '``llvm.fabs.*``' intrinsics return the absolute value of the
  9123. operand.
  9124. Arguments:
  9125. """"""""""
  9126. The argument and return value are floating-point numbers of the same
  9127. type.
  9128. Semantics:
  9129. """"""""""
  9130. This function returns the same values as the libm ``fabs`` functions
  9131. would, and handles error conditions in the same way.
  9132. '``llvm.minnum.*``' Intrinsic
  9133. ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  9134. Syntax:
  9135. """""""
  9136. This is an overloaded intrinsic. You can use ``llvm.minnum`` on any
  9137. floating-point or vector of floating-point type. Not all targets support
  9138. all types however.
  9139. ::
  9140. declare float @llvm.minnum.f32(float %Val0, float %Val1)
  9141. declare double @llvm.minnum.f64(double %Val0, double %Val1)
  9142. declare x86_fp80 @llvm.minnum.f80(x86_fp80 %Val0, x86_fp80 %Val1)
  9143. declare fp128 @llvm.minnum.f128(fp128 %Val0, fp128 %Val1)
  9144. declare ppc_fp128 @llvm.minnum.ppcf128(ppc_fp128 %Val0, ppc_fp128 %Val1)
  9145. Overview:
  9146. """""""""
  9147. The '``llvm.minnum.*``' intrinsics return the minimum of the two
  9148. arguments.
  9149. Arguments:
  9150. """"""""""
  9151. The arguments and return value are floating-point numbers of the same
  9152. type.
  9153. Semantics:
  9154. """"""""""
  9155. Follows the IEEE-754 semantics for minNum, except for handling of
  9156. signaling NaNs. This match's the behavior of libm's fmin.
  9157. If either operand is a NaN, returns the other non-NaN operand. Returns
  9158. NaN only if both operands are NaN. The returned NaN is always
  9159. quiet. If the operands compare equal, returns a value that compares
  9160. equal to both operands. This means that fmin(+/-0.0, +/-0.0) could
  9161. return either -0.0 or 0.0.
  9162. Unlike the IEEE-754 2008 behavior, this does not distinguish between
  9163. signaling and quiet NaN inputs. If a target's implementation follows
  9164. the standard and returns a quiet NaN if either input is a signaling
  9165. NaN, the intrinsic lowering is responsible for quieting the inputs to
  9166. correctly return the non-NaN input (e.g. by using the equivalent of
  9167. ``llvm.canonicalize``).
  9168. '``llvm.maxnum.*``' Intrinsic
  9169. ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  9170. Syntax:
  9171. """""""
  9172. This is an overloaded intrinsic. You can use ``llvm.maxnum`` on any
  9173. floating-point or vector of floating-point type. Not all targets support
  9174. all types however.
  9175. ::
  9176. declare float @llvm.maxnum.f32(float %Val0, float %Val1l)
  9177. declare double @llvm.maxnum.f64(double %Val0, double %Val1)
  9178. declare x86_fp80 @llvm.maxnum.f80(x86_fp80 %Val0, x86_fp80 %Val1)
  9179. declare fp128 @llvm.maxnum.f128(fp128 %Val0, fp128 %Val1)
  9180. declare ppc_fp128 @llvm.maxnum.ppcf128(ppc_fp128 %Val0, ppc_fp128 %Val1)
  9181. Overview:
  9182. """""""""
  9183. The '``llvm.maxnum.*``' intrinsics return the maximum of the two
  9184. arguments.
  9185. Arguments:
  9186. """"""""""
  9187. The arguments and return value are floating-point numbers of the same
  9188. type.
  9189. Semantics:
  9190. """"""""""
  9191. Follows the IEEE-754 semantics for maxNum except for the handling of
  9192. signaling NaNs. This matches the behavior of libm's fmax.
  9193. If either operand is a NaN, returns the other non-NaN operand. Returns
  9194. NaN only if both operands are NaN. The returned NaN is always
  9195. quiet. If the operands compare equal, returns a value that compares
  9196. equal to both operands. This means that fmax(+/-0.0, +/-0.0) could
  9197. return either -0.0 or 0.0.
  9198. Unlike the IEEE-754 2008 behavior, this does not distinguish between
  9199. signaling and quiet NaN inputs. If a target's implementation follows
  9200. the standard and returns a quiet NaN if either input is a signaling
  9201. NaN, the intrinsic lowering is responsible for quieting the inputs to
  9202. correctly return the non-NaN input (e.g. by using the equivalent of
  9203. ``llvm.canonicalize``).
  9204. '``llvm.minimum.*``' Intrinsic
  9205. ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  9206. Syntax:
  9207. """""""
  9208. This is an overloaded intrinsic. You can use ``llvm.minimum`` on any
  9209. floating-point or vector of floating-point type. Not all targets support
  9210. all types however.
  9211. ::
  9212. declare float @llvm.minimum.f32(float %Val0, float %Val1)
  9213. declare double @llvm.minimum.f64(double %Val0, double %Val1)
  9214. declare x86_fp80 @llvm.minimum.f80(x86_fp80 %Val0, x86_fp80 %Val1)
  9215. declare fp128 @llvm.minimum.f128(fp128 %Val0, fp128 %Val1)
  9216. declare ppc_fp128 @llvm.minimum.ppcf128(ppc_fp128 %Val0, ppc_fp128 %Val1)
  9217. Overview:
  9218. """""""""
  9219. The '``llvm.minimum.*``' intrinsics return the minimum of the two
  9220. arguments, propagating NaNs and treating -0.0 as less than +0.0.
  9221. Arguments:
  9222. """"""""""
  9223. The arguments and return value are floating-point numbers of the same
  9224. type.
  9225. Semantics:
  9226. """"""""""
  9227. If either operand is a NaN, returns NaN. Otherwise returns the lesser
  9228. of the two arguments. -0.0 is considered to be less than +0.0 for this
  9229. intrinsic. Note that these are the semantics specified in the draft of
  9230. IEEE 754-2018.
  9231. '``llvm.maximum.*``' Intrinsic
  9232. ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  9233. Syntax:
  9234. """""""
  9235. This is an overloaded intrinsic. You can use ``llvm.maximum`` on any
  9236. floating-point or vector of floating-point type. Not all targets support
  9237. all types however.
  9238. ::
  9239. declare float @llvm.maximum.f32(float %Val0, float %Val1)
  9240. declare double @llvm.maximum.f64(double %Val0, double %Val1)
  9241. declare x86_fp80 @llvm.maximum.f80(x86_fp80 %Val0, x86_fp80 %Val1)
  9242. declare fp128 @llvm.maximum.f128(fp128 %Val0, fp128 %Val1)
  9243. declare ppc_fp128 @llvm.maximum.ppcf128(ppc_fp128 %Val0, ppc_fp128 %Val1)
  9244. Overview:
  9245. """""""""
  9246. The '``llvm.maximum.*``' intrinsics return the maximum of the two
  9247. arguments, propagating NaNs and treating -0.0 as less than +0.0.
  9248. Arguments:
  9249. """"""""""
  9250. The arguments and return value are floating-point numbers of the same
  9251. type.
  9252. Semantics:
  9253. """"""""""
  9254. If either operand is a NaN, returns NaN. Otherwise returns the greater
  9255. of the two arguments. -0.0 is considered to be less than +0.0 for this
  9256. intrinsic. Note that these are the semantics specified in the draft of
  9257. IEEE 754-2018.
  9258. '``llvm.copysign.*``' Intrinsic
  9259. ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  9260. Syntax:
  9261. """""""
  9262. This is an overloaded intrinsic. You can use ``llvm.copysign`` on any
  9263. floating-point or vector of floating-point type. Not all targets support
  9264. all types however.
  9265. ::
  9266. declare float @llvm.copysign.f32(float %Mag, float %Sgn)
  9267. declare double @llvm.copysign.f64(double %Mag, double %Sgn)
  9268. declare x86_fp80 @llvm.copysign.f80(x86_fp80 %Mag, x86_fp80 %Sgn)
  9269. declare fp128 @llvm.copysign.f128(fp128 %Mag, fp128 %Sgn)
  9270. declare ppc_fp128 @llvm.copysign.ppcf128(ppc_fp128 %Mag, ppc_fp128 %Sgn)
  9271. Overview:
  9272. """""""""
  9273. The '``llvm.copysign.*``' intrinsics return a value with the magnitude of the
  9274. first operand and the sign of the second operand.
  9275. Arguments:
  9276. """"""""""
  9277. The arguments and return value are floating-point numbers of the same
  9278. type.
  9279. Semantics:
  9280. """"""""""
  9281. This function returns the same values as the libm ``copysign``
  9282. functions would, and handles error conditions in the same way.
  9283. '``llvm.floor.*``' Intrinsic
  9284. ^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  9285. Syntax:
  9286. """""""
  9287. This is an overloaded intrinsic. You can use ``llvm.floor`` on any
  9288. floating-point or vector of floating-point type. Not all targets support
  9289. all types however.
  9290. ::
  9291. declare float @llvm.floor.f32(float %Val)
  9292. declare double @llvm.floor.f64(double %Val)
  9293. declare x86_fp80 @llvm.floor.f80(x86_fp80 %Val)
  9294. declare fp128 @llvm.floor.f128(fp128 %Val)
  9295. declare ppc_fp128 @llvm.floor.ppcf128(ppc_fp128 %Val)
  9296. Overview:
  9297. """""""""
  9298. The '``llvm.floor.*``' intrinsics return the floor of the operand.
  9299. Arguments:
  9300. """"""""""
  9301. The argument and return value are floating-point numbers of the same
  9302. type.
  9303. Semantics:
  9304. """"""""""
  9305. This function returns the same values as the libm ``floor`` functions
  9306. would, and handles error conditions in the same way.
  9307. '``llvm.ceil.*``' Intrinsic
  9308. ^^^^^^^^^^^^^^^^^^^^^^^^^^^
  9309. Syntax:
  9310. """""""
  9311. This is an overloaded intrinsic. You can use ``llvm.ceil`` on any
  9312. floating-point or vector of floating-point type. Not all targets support
  9313. all types however.
  9314. ::
  9315. declare float @llvm.ceil.f32(float %Val)
  9316. declare double @llvm.ceil.f64(double %Val)
  9317. declare x86_fp80 @llvm.ceil.f80(x86_fp80 %Val)
  9318. declare fp128 @llvm.ceil.f128(fp128 %Val)
  9319. declare ppc_fp128 @llvm.ceil.ppcf128(ppc_fp128 %Val)
  9320. Overview:
  9321. """""""""
  9322. The '``llvm.ceil.*``' intrinsics return the ceiling of the operand.
  9323. Arguments:
  9324. """"""""""
  9325. The argument and return value are floating-point numbers of the same
  9326. type.
  9327. Semantics:
  9328. """"""""""
  9329. This function returns the same values as the libm ``ceil`` functions
  9330. would, and handles error conditions in the same way.
  9331. '``llvm.trunc.*``' Intrinsic
  9332. ^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  9333. Syntax:
  9334. """""""
  9335. This is an overloaded intrinsic. You can use ``llvm.trunc`` on any
  9336. floating-point or vector of floating-point type. Not all targets support
  9337. all types however.
  9338. ::
  9339. declare float @llvm.trunc.f32(float %Val)
  9340. declare double @llvm.trunc.f64(double %Val)
  9341. declare x86_fp80 @llvm.trunc.f80(x86_fp80 %Val)
  9342. declare fp128 @llvm.trunc.f128(fp128 %Val)
  9343. declare ppc_fp128 @llvm.trunc.ppcf128(ppc_fp128 %Val)
  9344. Overview:
  9345. """""""""
  9346. The '``llvm.trunc.*``' intrinsics returns the operand rounded to the
  9347. nearest integer not larger in magnitude than the operand.
  9348. Arguments:
  9349. """"""""""
  9350. The argument and return value are floating-point numbers of the same
  9351. type.
  9352. Semantics:
  9353. """"""""""
  9354. This function returns the same values as the libm ``trunc`` functions
  9355. would, and handles error conditions in the same way.
  9356. '``llvm.rint.*``' Intrinsic
  9357. ^^^^^^^^^^^^^^^^^^^^^^^^^^^
  9358. Syntax:
  9359. """""""
  9360. This is an overloaded intrinsic. You can use ``llvm.rint`` on any
  9361. floating-point or vector of floating-point type. Not all targets support
  9362. all types however.
  9363. ::
  9364. declare float @llvm.rint.f32(float %Val)
  9365. declare double @llvm.rint.f64(double %Val)
  9366. declare x86_fp80 @llvm.rint.f80(x86_fp80 %Val)
  9367. declare fp128 @llvm.rint.f128(fp128 %Val)
  9368. declare ppc_fp128 @llvm.rint.ppcf128(ppc_fp128 %Val)
  9369. Overview:
  9370. """""""""
  9371. The '``llvm.rint.*``' intrinsics returns the operand rounded to the
  9372. nearest integer. It may raise an inexact floating-point exception if the
  9373. operand isn't an integer.
  9374. Arguments:
  9375. """"""""""
  9376. The argument and return value are floating-point numbers of the same
  9377. type.
  9378. Semantics:
  9379. """"""""""
  9380. This function returns the same values as the libm ``rint`` functions
  9381. would, and handles error conditions in the same way.
  9382. '``llvm.nearbyint.*``' Intrinsic
  9383. ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  9384. Syntax:
  9385. """""""
  9386. This is an overloaded intrinsic. You can use ``llvm.nearbyint`` on any
  9387. floating-point or vector of floating-point type. Not all targets support
  9388. all types however.
  9389. ::
  9390. declare float @llvm.nearbyint.f32(float %Val)
  9391. declare double @llvm.nearbyint.f64(double %Val)
  9392. declare x86_fp80 @llvm.nearbyint.f80(x86_fp80 %Val)
  9393. declare fp128 @llvm.nearbyint.f128(fp128 %Val)
  9394. declare ppc_fp128 @llvm.nearbyint.ppcf128(ppc_fp128 %Val)
  9395. Overview:
  9396. """""""""
  9397. The '``llvm.nearbyint.*``' intrinsics returns the operand rounded to the
  9398. nearest integer.
  9399. Arguments:
  9400. """"""""""
  9401. The argument and return value are floating-point numbers of the same
  9402. type.
  9403. Semantics:
  9404. """"""""""
  9405. This function returns the same values as the libm ``nearbyint``
  9406. functions would, and handles error conditions in the same way.
  9407. '``llvm.round.*``' Intrinsic
  9408. ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  9409. Syntax:
  9410. """""""
  9411. This is an overloaded intrinsic. You can use ``llvm.round`` on any
  9412. floating-point or vector of floating-point type. Not all targets support
  9413. all types however.
  9414. ::
  9415. declare float @llvm.round.f32(float %Val)
  9416. declare double @llvm.round.f64(double %Val)
  9417. declare x86_fp80 @llvm.round.f80(x86_fp80 %Val)
  9418. declare fp128 @llvm.round.f128(fp128 %Val)
  9419. declare ppc_fp128 @llvm.round.ppcf128(ppc_fp128 %Val)
  9420. Overview:
  9421. """""""""
  9422. The '``llvm.round.*``' intrinsics returns the operand rounded to the
  9423. nearest integer.
  9424. Arguments:
  9425. """"""""""
  9426. The argument and return value are floating-point numbers of the same
  9427. type.
  9428. Semantics:
  9429. """"""""""
  9430. This function returns the same values as the libm ``round``
  9431. functions would, and handles error conditions in the same way.
  9432. '``llvm.lround.*``' Intrinsic
  9433. ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  9434. Syntax:
  9435. """""""
  9436. This is an overloaded intrinsic. You can use ``llvm.lround`` on any
  9437. floating-point type. Not all targets support all types however.
  9438. ::
  9439. declare i32 @llvm.lround.i32.f32(float %Val)
  9440. declare i32 @llvm.lround.i32.f64(double %Val)
  9441. declare i32 @llvm.lround.i32.f80(float %Val)
  9442. declare i32 @llvm.lround.i32.f128(double %Val)
  9443. declare i32 @llvm.lround.i32.ppcf128(double %Val)
  9444. declare i64 @llvm.lround.i64.f32(float %Val)
  9445. declare i64 @llvm.lround.i64.f64(double %Val)
  9446. declare i64 @llvm.lround.i64.f80(float %Val)
  9447. declare i64 @llvm.lround.i64.f128(double %Val)
  9448. declare i64 @llvm.lround.i64.ppcf128(double %Val)
  9449. Overview:
  9450. """""""""
  9451. The '``llvm.lround.*``' intrinsics returns the operand rounded to the
  9452. nearest integer.
  9453. Arguments:
  9454. """"""""""
  9455. The argument is a floating-point number and return is an integer type.
  9456. Semantics:
  9457. """"""""""
  9458. This function returns the same values as the libm ``lround``
  9459. functions would, but without setting errno.
  9460. '``llvm.llround.*``' Intrinsic
  9461. ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  9462. Syntax:
  9463. """""""
  9464. This is an overloaded intrinsic. You can use ``llvm.llround`` on any
  9465. floating-point type. Not all targets support all types however.
  9466. ::
  9467. declare i64 @llvm.lround.i64.f32(float %Val)
  9468. declare i64 @llvm.lround.i64.f64(double %Val)
  9469. declare i64 @llvm.lround.i64.f80(float %Val)
  9470. declare i64 @llvm.lround.i64.f128(double %Val)
  9471. declare i64 @llvm.lround.i64.ppcf128(double %Val)
  9472. Overview:
  9473. """""""""
  9474. The '``llvm.llround.*``' intrinsics returns the operand rounded to the
  9475. nearest integer.
  9476. Arguments:
  9477. """"""""""
  9478. The argument is a floating-point number and return is an integer type.
  9479. Semantics:
  9480. """"""""""
  9481. This function returns the same values as the libm ``llround``
  9482. functions would, but without setting errno.
  9483. '``llvm.lrint.*``' Intrinsic
  9484. ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  9485. Syntax:
  9486. """""""
  9487. This is an overloaded intrinsic. You can use ``llvm.lrint`` on any
  9488. floating-point type. Not all targets support all types however.
  9489. ::
  9490. declare i32 @llvm.lrint.i32.f32(float %Val)
  9491. declare i32 @llvm.lrint.i32.f64(double %Val)
  9492. declare i32 @llvm.lrint.i32.f80(float %Val)
  9493. declare i32 @llvm.lrint.i32.f128(double %Val)
  9494. declare i32 @llvm.lrint.i32.ppcf128(double %Val)
  9495. declare i64 @llvm.lrint.i64.f32(float %Val)
  9496. declare i64 @llvm.lrint.i64.f64(double %Val)
  9497. declare i64 @llvm.lrint.i64.f80(float %Val)
  9498. declare i64 @llvm.lrint.i64.f128(double %Val)
  9499. declare i64 @llvm.lrint.i64.ppcf128(double %Val)
  9500. Overview:
  9501. """""""""
  9502. The '``llvm.lrint.*``' intrinsics returns the operand rounded to the
  9503. nearest integer.
  9504. Arguments:
  9505. """"""""""
  9506. The argument is a floating-point number and return is an integer type.
  9507. Semantics:
  9508. """"""""""
  9509. This function returns the same values as the libm ``lrint``
  9510. functions would, but without setting errno.
  9511. '``llvm.llrint.*``' Intrinsic
  9512. ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  9513. Syntax:
  9514. """""""
  9515. This is an overloaded intrinsic. You can use ``llvm.llrint`` on any
  9516. floating-point type. Not all targets support all types however.
  9517. ::
  9518. declare i64 @llvm.llrint.i64.f32(float %Val)
  9519. declare i64 @llvm.llrint.i64.f64(double %Val)
  9520. declare i64 @llvm.llrint.i64.f80(float %Val)
  9521. declare i64 @llvm.llrint.i64.f128(double %Val)
  9522. declare i64 @llvm.llrint.i64.ppcf128(double %Val)
  9523. Overview:
  9524. """""""""
  9525. The '``llvm.llrint.*``' intrinsics returns the operand rounded to the
  9526. nearest integer.
  9527. Arguments:
  9528. """"""""""
  9529. The argument is a floating-point number and return is an integer type.
  9530. Semantics:
  9531. """"""""""
  9532. This function returns the same values as the libm ``llrint``
  9533. functions would, but without setting errno.
  9534. Bit Manipulation Intrinsics
  9535. ---------------------------
  9536. LLVM provides intrinsics for a few important bit manipulation
  9537. operations. These allow efficient code generation for some algorithms.
  9538. '``llvm.bitreverse.*``' Intrinsics
  9539. ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  9540. Syntax:
  9541. """""""
  9542. This is an overloaded intrinsic function. You can use bitreverse on any
  9543. integer type.
  9544. ::
  9545. declare i16 @llvm.bitreverse.i16(i16 <id>)
  9546. declare i32 @llvm.bitreverse.i32(i32 <id>)
  9547. declare i64 @llvm.bitreverse.i64(i64 <id>)
  9548. declare <4 x i32> @llvm.bitreverse.v4i32(<4 x i32> <id>)
  9549. Overview:
  9550. """""""""
  9551. The '``llvm.bitreverse``' family of intrinsics is used to reverse the
  9552. bitpattern of an integer value or vector of integer values; for example
  9553. ``0b10110110`` becomes ``0b01101101``.
  9554. Semantics:
  9555. """"""""""
  9556. The ``llvm.bitreverse.iN`` intrinsic returns an iN value that has bit
  9557. ``M`` in the input moved to bit ``N-M`` in the output. The vector
  9558. intrinsics, such as ``llvm.bitreverse.v4i32``, operate on a per-element
  9559. basis and the element order is not affected.
  9560. '``llvm.bswap.*``' Intrinsics
  9561. ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  9562. Syntax:
  9563. """""""
  9564. This is an overloaded intrinsic function. You can use bswap on any
  9565. integer type that is an even number of bytes (i.e. BitWidth % 16 == 0).
  9566. ::
  9567. declare i16 @llvm.bswap.i16(i16 <id>)
  9568. declare i32 @llvm.bswap.i32(i32 <id>)
  9569. declare i64 @llvm.bswap.i64(i64 <id>)
  9570. declare <4 x i32> @llvm.bswap.v4i32(<4 x i32> <id>)
  9571. Overview:
  9572. """""""""
  9573. The '``llvm.bswap``' family of intrinsics is used to byte swap an integer
  9574. value or vector of integer values with an even number of bytes (positive
  9575. multiple of 16 bits).
  9576. Semantics:
  9577. """"""""""
  9578. The ``llvm.bswap.i16`` intrinsic returns an i16 value that has the high
  9579. and low byte of the input i16 swapped. Similarly, the ``llvm.bswap.i32``
  9580. intrinsic returns an i32 value that has the four bytes of the input i32
  9581. swapped, so that if the input bytes are numbered 0, 1, 2, 3 then the
  9582. returned i32 will have its bytes in 3, 2, 1, 0 order. The
  9583. ``llvm.bswap.i48``, ``llvm.bswap.i64`` and other intrinsics extend this
  9584. concept to additional even-byte lengths (6 bytes, 8 bytes and more,
  9585. respectively). The vector intrinsics, such as ``llvm.bswap.v4i32``,
  9586. operate on a per-element basis and the element order is not affected.
  9587. '``llvm.ctpop.*``' Intrinsic
  9588. ^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  9589. Syntax:
  9590. """""""
  9591. This is an overloaded intrinsic. You can use llvm.ctpop on any integer
  9592. bit width, or on any vector with integer elements. Not all targets
  9593. support all bit widths or vector types, however.
  9594. ::
  9595. declare i8 @llvm.ctpop.i8(i8 <src>)
  9596. declare i16 @llvm.ctpop.i16(i16 <src>)
  9597. declare i32 @llvm.ctpop.i32(i32 <src>)
  9598. declare i64 @llvm.ctpop.i64(i64 <src>)
  9599. declare i256 @llvm.ctpop.i256(i256 <src>)
  9600. declare <2 x i32> @llvm.ctpop.v2i32(<2 x i32> <src>)
  9601. Overview:
  9602. """""""""
  9603. The '``llvm.ctpop``' family of intrinsics counts the number of bits set
  9604. in a value.
  9605. Arguments:
  9606. """"""""""
  9607. The only argument is the value to be counted. The argument may be of any
  9608. integer type, or a vector with integer elements. The return type must
  9609. match the argument type.
  9610. Semantics:
  9611. """"""""""
  9612. The '``llvm.ctpop``' intrinsic counts the 1's in a variable, or within
  9613. each element of a vector.
  9614. '``llvm.ctlz.*``' Intrinsic
  9615. ^^^^^^^^^^^^^^^^^^^^^^^^^^^
  9616. Syntax:
  9617. """""""
  9618. This is an overloaded intrinsic. You can use ``llvm.ctlz`` on any
  9619. integer bit width, or any vector whose elements are integers. Not all
  9620. targets support all bit widths or vector types, however.
  9621. ::
  9622. declare i8 @llvm.ctlz.i8 (i8 <src>, i1 <is_zero_undef>)
  9623. declare i16 @llvm.ctlz.i16 (i16 <src>, i1 <is_zero_undef>)
  9624. declare i32 @llvm.ctlz.i32 (i32 <src>, i1 <is_zero_undef>)
  9625. declare i64 @llvm.ctlz.i64 (i64 <src>, i1 <is_zero_undef>)
  9626. declare i256 @llvm.ctlz.i256(i256 <src>, i1 <is_zero_undef>)
  9627. declare <2 x i32> @llvm.ctlz.v2i32(<2 x i32> <src>, i1 <is_zero_undef>)
  9628. Overview:
  9629. """""""""
  9630. The '``llvm.ctlz``' family of intrinsic functions counts the number of
  9631. leading zeros in a variable.
  9632. Arguments:
  9633. """"""""""
  9634. The first argument is the value to be counted. This argument may be of
  9635. any integer type, or a vector with integer element type. The return
  9636. type must match the first argument type.
  9637. The second argument must be a constant and is a flag to indicate whether
  9638. the intrinsic should ensure that a zero as the first argument produces a
  9639. defined result. Historically some architectures did not provide a
  9640. defined result for zero values as efficiently, and many algorithms are
  9641. now predicated on avoiding zero-value inputs.
  9642. Semantics:
  9643. """"""""""
  9644. The '``llvm.ctlz``' intrinsic counts the leading (most significant)
  9645. zeros in a variable, or within each element of the vector. If
  9646. ``src == 0`` then the result is the size in bits of the type of ``src``
  9647. if ``is_zero_undef == 0`` and ``undef`` otherwise. For example,
  9648. ``llvm.ctlz(i32 2) = 30``.
  9649. '``llvm.cttz.*``' Intrinsic
  9650. ^^^^^^^^^^^^^^^^^^^^^^^^^^^
  9651. Syntax:
  9652. """""""
  9653. This is an overloaded intrinsic. You can use ``llvm.cttz`` on any
  9654. integer bit width, or any vector of integer elements. Not all targets
  9655. support all bit widths or vector types, however.
  9656. ::
  9657. declare i8 @llvm.cttz.i8 (i8 <src>, i1 <is_zero_undef>)
  9658. declare i16 @llvm.cttz.i16 (i16 <src>, i1 <is_zero_undef>)
  9659. declare i32 @llvm.cttz.i32 (i32 <src>, i1 <is_zero_undef>)
  9660. declare i64 @llvm.cttz.i64 (i64 <src>, i1 <is_zero_undef>)
  9661. declare i256 @llvm.cttz.i256(i256 <src>, i1 <is_zero_undef>)
  9662. declare <2 x i32> @llvm.cttz.v2i32(<2 x i32> <src>, i1 <is_zero_undef>)
  9663. Overview:
  9664. """""""""
  9665. The '``llvm.cttz``' family of intrinsic functions counts the number of
  9666. trailing zeros.
  9667. Arguments:
  9668. """"""""""
  9669. The first argument is the value to be counted. This argument may be of
  9670. any integer type, or a vector with integer element type. The return
  9671. type must match the first argument type.
  9672. The second argument must be a constant and is a flag to indicate whether
  9673. the intrinsic should ensure that a zero as the first argument produces a
  9674. defined result. Historically some architectures did not provide a
  9675. defined result for zero values as efficiently, and many algorithms are
  9676. now predicated on avoiding zero-value inputs.
  9677. Semantics:
  9678. """"""""""
  9679. The '``llvm.cttz``' intrinsic counts the trailing (least significant)
  9680. zeros in a variable, or within each element of a vector. If ``src == 0``
  9681. then the result is the size in bits of the type of ``src`` if
  9682. ``is_zero_undef == 0`` and ``undef`` otherwise. For example,
  9683. ``llvm.cttz(2) = 1``.
  9684. .. _int_overflow:
  9685. '``llvm.fshl.*``' Intrinsic
  9686. ^^^^^^^^^^^^^^^^^^^^^^^^^^^
  9687. Syntax:
  9688. """""""
  9689. This is an overloaded intrinsic. You can use ``llvm.fshl`` on any
  9690. integer bit width or any vector of integer elements. Not all targets
  9691. support all bit widths or vector types, however.
  9692. ::
  9693. declare i8 @llvm.fshl.i8 (i8 %a, i8 %b, i8 %c)
  9694. declare i67 @llvm.fshl.i67(i67 %a, i67 %b, i67 %c)
  9695. declare <2 x i32> @llvm.fshl.v2i32(<2 x i32> %a, <2 x i32> %b, <2 x i32> %c)
  9696. Overview:
  9697. """""""""
  9698. The '``llvm.fshl``' family of intrinsic functions performs a funnel shift left:
  9699. the first two values are concatenated as { %a : %b } (%a is the most significant
  9700. bits of the wide value), the combined value is shifted left, and the most
  9701. significant bits are extracted to produce a result that is the same size as the
  9702. original arguments. If the first 2 arguments are identical, this is equivalent
  9703. to a rotate left operation. For vector types, the operation occurs for each
  9704. element of the vector. The shift argument is treated as an unsigned amount
  9705. modulo the element size of the arguments.
  9706. Arguments:
  9707. """"""""""
  9708. The first two arguments are the values to be concatenated. The third
  9709. argument is the shift amount. The arguments may be any integer type or a
  9710. vector with integer element type. All arguments and the return value must
  9711. have the same type.
  9712. Example:
  9713. """"""""
  9714. .. code-block:: text
  9715. %r = call i8 @llvm.fshl.i8(i8 %x, i8 %y, i8 %z) ; %r = i8: msb_extract((concat(x, y) << (z % 8)), 8)
  9716. %r = call i8 @llvm.fshl.i8(i8 255, i8 0, i8 15) ; %r = i8: 128 (0b10000000)
  9717. %r = call i8 @llvm.fshl.i8(i8 15, i8 15, i8 11) ; %r = i8: 120 (0b01111000)
  9718. %r = call i8 @llvm.fshl.i8(i8 0, i8 255, i8 8) ; %r = i8: 0 (0b00000000)
  9719. '``llvm.fshr.*``' Intrinsic
  9720. ^^^^^^^^^^^^^^^^^^^^^^^^^^^
  9721. Syntax:
  9722. """""""
  9723. This is an overloaded intrinsic. You can use ``llvm.fshr`` on any
  9724. integer bit width or any vector of integer elements. Not all targets
  9725. support all bit widths or vector types, however.
  9726. ::
  9727. declare i8 @llvm.fshr.i8 (i8 %a, i8 %b, i8 %c)
  9728. declare i67 @llvm.fshr.i67(i67 %a, i67 %b, i67 %c)
  9729. declare <2 x i32> @llvm.fshr.v2i32(<2 x i32> %a, <2 x i32> %b, <2 x i32> %c)
  9730. Overview:
  9731. """""""""
  9732. The '``llvm.fshr``' family of intrinsic functions performs a funnel shift right:
  9733. the first two values are concatenated as { %a : %b } (%a is the most significant
  9734. bits of the wide value), the combined value is shifted right, and the least
  9735. significant bits are extracted to produce a result that is the same size as the
  9736. original arguments. If the first 2 arguments are identical, this is equivalent
  9737. to a rotate right operation. For vector types, the operation occurs for each
  9738. element of the vector. The shift argument is treated as an unsigned amount
  9739. modulo the element size of the arguments.
  9740. Arguments:
  9741. """"""""""
  9742. The first two arguments are the values to be concatenated. The third
  9743. argument is the shift amount. The arguments may be any integer type or a
  9744. vector with integer element type. All arguments and the return value must
  9745. have the same type.
  9746. Example:
  9747. """"""""
  9748. .. code-block:: text
  9749. %r = call i8 @llvm.fshr.i8(i8 %x, i8 %y, i8 %z) ; %r = i8: lsb_extract((concat(x, y) >> (z % 8)), 8)
  9750. %r = call i8 @llvm.fshr.i8(i8 255, i8 0, i8 15) ; %r = i8: 254 (0b11111110)
  9751. %r = call i8 @llvm.fshr.i8(i8 15, i8 15, i8 11) ; %r = i8: 225 (0b11100001)
  9752. %r = call i8 @llvm.fshr.i8(i8 0, i8 255, i8 8) ; %r = i8: 255 (0b11111111)
  9753. Arithmetic with Overflow Intrinsics
  9754. -----------------------------------
  9755. LLVM provides intrinsics for fast arithmetic overflow checking.
  9756. Each of these intrinsics returns a two-element struct. The first
  9757. element of this struct contains the result of the corresponding
  9758. arithmetic operation modulo 2\ :sup:`n`\ , where n is the bit width of
  9759. the result. Therefore, for example, the first element of the struct
  9760. returned by ``llvm.sadd.with.overflow.i32`` is always the same as the
  9761. result of a 32-bit ``add`` instruction with the same operands, where
  9762. the ``add`` is *not* modified by an ``nsw`` or ``nuw`` flag.
  9763. The second element of the result is an ``i1`` that is 1 if the
  9764. arithmetic operation overflowed and 0 otherwise. An operation
  9765. overflows if, for any values of its operands ``A`` and ``B`` and for
  9766. any ``N`` larger than the operands' width, ``ext(A op B) to iN`` is
  9767. not equal to ``(ext(A) to iN) op (ext(B) to iN)`` where ``ext`` is
  9768. ``sext`` for signed overflow and ``zext`` for unsigned overflow, and
  9769. ``op`` is the underlying arithmetic operation.
  9770. The behavior of these intrinsics is well-defined for all argument
  9771. values.
  9772. '``llvm.sadd.with.overflow.*``' Intrinsics
  9773. ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  9774. Syntax:
  9775. """""""
  9776. This is an overloaded intrinsic. You can use ``llvm.sadd.with.overflow``
  9777. on any integer bit width or vectors of integers.
  9778. ::
  9779. declare {i16, i1} @llvm.sadd.with.overflow.i16(i16 %a, i16 %b)
  9780. declare {i32, i1} @llvm.sadd.with.overflow.i32(i32 %a, i32 %b)
  9781. declare {i64, i1} @llvm.sadd.with.overflow.i64(i64 %a, i64 %b)
  9782. declare {<4 x i32>, <4 x i1>} @llvm.sadd.with.overflow.v4i32(<4 x i32> %a, <4 x i32> %b)
  9783. Overview:
  9784. """""""""
  9785. The '``llvm.sadd.with.overflow``' family of intrinsic functions perform
  9786. a signed addition of the two arguments, and indicate whether an overflow
  9787. occurred during the signed summation.
  9788. Arguments:
  9789. """"""""""
  9790. The arguments (%a and %b) and the first element of the result structure
  9791. may be of integer types of any bit width, but they must have the same
  9792. bit width. The second element of the result structure must be of type
  9793. ``i1``. ``%a`` and ``%b`` are the two values that will undergo signed
  9794. addition.
  9795. Semantics:
  9796. """"""""""
  9797. The '``llvm.sadd.with.overflow``' family of intrinsic functions perform
  9798. a signed addition of the two variables. They return a structure --- the
  9799. first element of which is the signed summation, and the second element
  9800. of which is a bit specifying if the signed summation resulted in an
  9801. overflow.
  9802. Examples:
  9803. """""""""
  9804. .. code-block:: llvm
  9805. %res = call {i32, i1} @llvm.sadd.with.overflow.i32(i32 %a, i32 %b)
  9806. %sum = extractvalue {i32, i1} %res, 0
  9807. %obit = extractvalue {i32, i1} %res, 1
  9808. br i1 %obit, label %overflow, label %normal
  9809. '``llvm.uadd.with.overflow.*``' Intrinsics
  9810. ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  9811. Syntax:
  9812. """""""
  9813. This is an overloaded intrinsic. You can use ``llvm.uadd.with.overflow``
  9814. on any integer bit width or vectors of integers.
  9815. ::
  9816. declare {i16, i1} @llvm.uadd.with.overflow.i16(i16 %a, i16 %b)
  9817. declare {i32, i1} @llvm.uadd.with.overflow.i32(i32 %a, i32 %b)
  9818. declare {i64, i1} @llvm.uadd.with.overflow.i64(i64 %a, i64 %b)
  9819. declare {<4 x i32>, <4 x i1>} @llvm.uadd.with.overflow.v4i32(<4 x i32> %a, <4 x i32> %b)
  9820. Overview:
  9821. """""""""
  9822. The '``llvm.uadd.with.overflow``' family of intrinsic functions perform
  9823. an unsigned addition of the two arguments, and indicate whether a carry
  9824. occurred during the unsigned summation.
  9825. Arguments:
  9826. """"""""""
  9827. The arguments (%a and %b) and the first element of the result structure
  9828. may be of integer types of any bit width, but they must have the same
  9829. bit width. The second element of the result structure must be of type
  9830. ``i1``. ``%a`` and ``%b`` are the two values that will undergo unsigned
  9831. addition.
  9832. Semantics:
  9833. """"""""""
  9834. The '``llvm.uadd.with.overflow``' family of intrinsic functions perform
  9835. an unsigned addition of the two arguments. They return a structure --- the
  9836. first element of which is the sum, and the second element of which is a
  9837. bit specifying if the unsigned summation resulted in a carry.
  9838. Examples:
  9839. """""""""
  9840. .. code-block:: llvm
  9841. %res = call {i32, i1} @llvm.uadd.with.overflow.i32(i32 %a, i32 %b)
  9842. %sum = extractvalue {i32, i1} %res, 0
  9843. %obit = extractvalue {i32, i1} %res, 1
  9844. br i1 %obit, label %carry, label %normal
  9845. '``llvm.ssub.with.overflow.*``' Intrinsics
  9846. ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  9847. Syntax:
  9848. """""""
  9849. This is an overloaded intrinsic. You can use ``llvm.ssub.with.overflow``
  9850. on any integer bit width or vectors of integers.
  9851. ::
  9852. declare {i16, i1} @llvm.ssub.with.overflow.i16(i16 %a, i16 %b)
  9853. declare {i32, i1} @llvm.ssub.with.overflow.i32(i32 %a, i32 %b)
  9854. declare {i64, i1} @llvm.ssub.with.overflow.i64(i64 %a, i64 %b)
  9855. declare {<4 x i32>, <4 x i1>} @llvm.ssub.with.overflow.v4i32(<4 x i32> %a, <4 x i32> %b)
  9856. Overview:
  9857. """""""""
  9858. The '``llvm.ssub.with.overflow``' family of intrinsic functions perform
  9859. a signed subtraction of the two arguments, and indicate whether an
  9860. overflow occurred during the signed subtraction.
  9861. Arguments:
  9862. """"""""""
  9863. The arguments (%a and %b) and the first element of the result structure
  9864. may be of integer types of any bit width, but they must have the same
  9865. bit width. The second element of the result structure must be of type
  9866. ``i1``. ``%a`` and ``%b`` are the two values that will undergo signed
  9867. subtraction.
  9868. Semantics:
  9869. """"""""""
  9870. The '``llvm.ssub.with.overflow``' family of intrinsic functions perform
  9871. a signed subtraction of the two arguments. They return a structure --- the
  9872. first element of which is the subtraction, and the second element of
  9873. which is a bit specifying if the signed subtraction resulted in an
  9874. overflow.
  9875. Examples:
  9876. """""""""
  9877. .. code-block:: llvm
  9878. %res = call {i32, i1} @llvm.ssub.with.overflow.i32(i32 %a, i32 %b)
  9879. %sum = extractvalue {i32, i1} %res, 0
  9880. %obit = extractvalue {i32, i1} %res, 1
  9881. br i1 %obit, label %overflow, label %normal
  9882. '``llvm.usub.with.overflow.*``' Intrinsics
  9883. ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  9884. Syntax:
  9885. """""""
  9886. This is an overloaded intrinsic. You can use ``llvm.usub.with.overflow``
  9887. on any integer bit width or vectors of integers.
  9888. ::
  9889. declare {i16, i1} @llvm.usub.with.overflow.i16(i16 %a, i16 %b)
  9890. declare {i32, i1} @llvm.usub.with.overflow.i32(i32 %a, i32 %b)
  9891. declare {i64, i1} @llvm.usub.with.overflow.i64(i64 %a, i64 %b)
  9892. declare {<4 x i32>, <4 x i1>} @llvm.usub.with.overflow.v4i32(<4 x i32> %a, <4 x i32> %b)
  9893. Overview:
  9894. """""""""
  9895. The '``llvm.usub.with.overflow``' family of intrinsic functions perform
  9896. an unsigned subtraction of the two arguments, and indicate whether an
  9897. overflow occurred during the unsigned subtraction.
  9898. Arguments:
  9899. """"""""""
  9900. The arguments (%a and %b) and the first element of the result structure
  9901. may be of integer types of any bit width, but they must have the same
  9902. bit width. The second element of the result structure must be of type
  9903. ``i1``. ``%a`` and ``%b`` are the two values that will undergo unsigned
  9904. subtraction.
  9905. Semantics:
  9906. """"""""""
  9907. The '``llvm.usub.with.overflow``' family of intrinsic functions perform
  9908. an unsigned subtraction of the two arguments. They return a structure ---
  9909. the first element of which is the subtraction, and the second element of
  9910. which is a bit specifying if the unsigned subtraction resulted in an
  9911. overflow.
  9912. Examples:
  9913. """""""""
  9914. .. code-block:: llvm
  9915. %res = call {i32, i1} @llvm.usub.with.overflow.i32(i32 %a, i32 %b)
  9916. %sum = extractvalue {i32, i1} %res, 0
  9917. %obit = extractvalue {i32, i1} %res, 1
  9918. br i1 %obit, label %overflow, label %normal
  9919. '``llvm.smul.with.overflow.*``' Intrinsics
  9920. ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  9921. Syntax:
  9922. """""""
  9923. This is an overloaded intrinsic. You can use ``llvm.smul.with.overflow``
  9924. on any integer bit width or vectors of integers.
  9925. ::
  9926. declare {i16, i1} @llvm.smul.with.overflow.i16(i16 %a, i16 %b)
  9927. declare {i32, i1} @llvm.smul.with.overflow.i32(i32 %a, i32 %b)
  9928. declare {i64, i1} @llvm.smul.with.overflow.i64(i64 %a, i64 %b)
  9929. declare {<4 x i32>, <4 x i1>} @llvm.smul.with.overflow.v4i32(<4 x i32> %a, <4 x i32> %b)
  9930. Overview:
  9931. """""""""
  9932. The '``llvm.smul.with.overflow``' family of intrinsic functions perform
  9933. a signed multiplication of the two arguments, and indicate whether an
  9934. overflow occurred during the signed multiplication.
  9935. Arguments:
  9936. """"""""""
  9937. The arguments (%a and %b) and the first element of the result structure
  9938. may be of integer types of any bit width, but they must have the same
  9939. bit width. The second element of the result structure must be of type
  9940. ``i1``. ``%a`` and ``%b`` are the two values that will undergo signed
  9941. multiplication.
  9942. Semantics:
  9943. """"""""""
  9944. The '``llvm.smul.with.overflow``' family of intrinsic functions perform
  9945. a signed multiplication of the two arguments. They return a structure ---
  9946. the first element of which is the multiplication, and the second element
  9947. of which is a bit specifying if the signed multiplication resulted in an
  9948. overflow.
  9949. Examples:
  9950. """""""""
  9951. .. code-block:: llvm
  9952. %res = call {i32, i1} @llvm.smul.with.overflow.i32(i32 %a, i32 %b)
  9953. %sum = extractvalue {i32, i1} %res, 0
  9954. %obit = extractvalue {i32, i1} %res, 1
  9955. br i1 %obit, label %overflow, label %normal
  9956. '``llvm.umul.with.overflow.*``' Intrinsics
  9957. ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  9958. Syntax:
  9959. """""""
  9960. This is an overloaded intrinsic. You can use ``llvm.umul.with.overflow``
  9961. on any integer bit width or vectors of integers.
  9962. ::
  9963. declare {i16, i1} @llvm.umul.with.overflow.i16(i16 %a, i16 %b)
  9964. declare {i32, i1} @llvm.umul.with.overflow.i32(i32 %a, i32 %b)
  9965. declare {i64, i1} @llvm.umul.with.overflow.i64(i64 %a, i64 %b)
  9966. declare {<4 x i32>, <4 x i1>} @llvm.umul.with.overflow.v4i32(<4 x i32> %a, <4 x i32> %b)
  9967. Overview:
  9968. """""""""
  9969. The '``llvm.umul.with.overflow``' family of intrinsic functions perform
  9970. a unsigned multiplication of the two arguments, and indicate whether an
  9971. overflow occurred during the unsigned multiplication.
  9972. Arguments:
  9973. """"""""""
  9974. The arguments (%a and %b) and the first element of the result structure
  9975. may be of integer types of any bit width, but they must have the same
  9976. bit width. The second element of the result structure must be of type
  9977. ``i1``. ``%a`` and ``%b`` are the two values that will undergo unsigned
  9978. multiplication.
  9979. Semantics:
  9980. """"""""""
  9981. The '``llvm.umul.with.overflow``' family of intrinsic functions perform
  9982. an unsigned multiplication of the two arguments. They return a structure ---
  9983. the first element of which is the multiplication, and the second
  9984. element of which is a bit specifying if the unsigned multiplication
  9985. resulted in an overflow.
  9986. Examples:
  9987. """""""""
  9988. .. code-block:: llvm
  9989. %res = call {i32, i1} @llvm.umul.with.overflow.i32(i32 %a, i32 %b)
  9990. %sum = extractvalue {i32, i1} %res, 0
  9991. %obit = extractvalue {i32, i1} %res, 1
  9992. br i1 %obit, label %overflow, label %normal
  9993. Saturation Arithmetic Intrinsics
  9994. ---------------------------------
  9995. Saturation arithmetic is a version of arithmetic in which operations are
  9996. limited to a fixed range between a minimum and maximum value. If the result of
  9997. an operation is greater than the maximum value, the result is set (or
  9998. "clamped") to this maximum. If it is below the minimum, it is clamped to this
  9999. minimum.
  10000. '``llvm.sadd.sat.*``' Intrinsics
  10001. ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  10002. Syntax
  10003. """""""
  10004. This is an overloaded intrinsic. You can use ``llvm.sadd.sat``
  10005. on any integer bit width or vectors of integers.
  10006. ::
  10007. declare i16 @llvm.sadd.sat.i16(i16 %a, i16 %b)
  10008. declare i32 @llvm.sadd.sat.i32(i32 %a, i32 %b)
  10009. declare i64 @llvm.sadd.sat.i64(i64 %a, i64 %b)
  10010. declare <4 x i32> @llvm.sadd.sat.v4i32(<4 x i32> %a, <4 x i32> %b)
  10011. Overview
  10012. """""""""
  10013. The '``llvm.sadd.sat``' family of intrinsic functions perform signed
  10014. saturation addition on the 2 arguments.
  10015. Arguments
  10016. """"""""""
  10017. The arguments (%a and %b) and the result may be of integer types of any bit
  10018. width, but they must have the same bit width. ``%a`` and ``%b`` are the two
  10019. values that will undergo signed addition.
  10020. Semantics:
  10021. """"""""""
  10022. The maximum value this operation can clamp to is the largest signed value
  10023. representable by the bit width of the arguments. The minimum value is the
  10024. smallest signed value representable by this bit width.
  10025. Examples
  10026. """""""""
  10027. .. code-block:: llvm
  10028. %res = call i4 @llvm.sadd.sat.i4(i4 1, i4 2) ; %res = 3
  10029. %res = call i4 @llvm.sadd.sat.i4(i4 5, i4 6) ; %res = 7
  10030. %res = call i4 @llvm.sadd.sat.i4(i4 -4, i4 2) ; %res = -2
  10031. %res = call i4 @llvm.sadd.sat.i4(i4 -4, i4 -5) ; %res = -8
  10032. '``llvm.uadd.sat.*``' Intrinsics
  10033. ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  10034. Syntax
  10035. """""""
  10036. This is an overloaded intrinsic. You can use ``llvm.uadd.sat``
  10037. on any integer bit width or vectors of integers.
  10038. ::
  10039. declare i16 @llvm.uadd.sat.i16(i16 %a, i16 %b)
  10040. declare i32 @llvm.uadd.sat.i32(i32 %a, i32 %b)
  10041. declare i64 @llvm.uadd.sat.i64(i64 %a, i64 %b)
  10042. declare <4 x i32> @llvm.uadd.sat.v4i32(<4 x i32> %a, <4 x i32> %b)
  10043. Overview
  10044. """""""""
  10045. The '``llvm.uadd.sat``' family of intrinsic functions perform unsigned
  10046. saturation addition on the 2 arguments.
  10047. Arguments
  10048. """"""""""
  10049. The arguments (%a and %b) and the result may be of integer types of any bit
  10050. width, but they must have the same bit width. ``%a`` and ``%b`` are the two
  10051. values that will undergo unsigned addition.
  10052. Semantics:
  10053. """"""""""
  10054. The maximum value this operation can clamp to is the largest unsigned value
  10055. representable by the bit width of the arguments. Because this is an unsigned
  10056. operation, the result will never saturate towards zero.
  10057. Examples
  10058. """""""""
  10059. .. code-block:: llvm
  10060. %res = call i4 @llvm.uadd.sat.i4(i4 1, i4 2) ; %res = 3
  10061. %res = call i4 @llvm.uadd.sat.i4(i4 5, i4 6) ; %res = 11
  10062. %res = call i4 @llvm.uadd.sat.i4(i4 8, i4 8) ; %res = 15
  10063. '``llvm.ssub.sat.*``' Intrinsics
  10064. ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  10065. Syntax
  10066. """""""
  10067. This is an overloaded intrinsic. You can use ``llvm.ssub.sat``
  10068. on any integer bit width or vectors of integers.
  10069. ::
  10070. declare i16 @llvm.ssub.sat.i16(i16 %a, i16 %b)
  10071. declare i32 @llvm.ssub.sat.i32(i32 %a, i32 %b)
  10072. declare i64 @llvm.ssub.sat.i64(i64 %a, i64 %b)
  10073. declare <4 x i32> @llvm.ssub.sat.v4i32(<4 x i32> %a, <4 x i32> %b)
  10074. Overview
  10075. """""""""
  10076. The '``llvm.ssub.sat``' family of intrinsic functions perform signed
  10077. saturation subtraction on the 2 arguments.
  10078. Arguments
  10079. """"""""""
  10080. The arguments (%a and %b) and the result may be of integer types of any bit
  10081. width, but they must have the same bit width. ``%a`` and ``%b`` are the two
  10082. values that will undergo signed subtraction.
  10083. Semantics:
  10084. """"""""""
  10085. The maximum value this operation can clamp to is the largest signed value
  10086. representable by the bit width of the arguments. The minimum value is the
  10087. smallest signed value representable by this bit width.
  10088. Examples
  10089. """""""""
  10090. .. code-block:: llvm
  10091. %res = call i4 @llvm.ssub.sat.i4(i4 2, i4 1) ; %res = 1
  10092. %res = call i4 @llvm.ssub.sat.i4(i4 2, i4 6) ; %res = -4
  10093. %res = call i4 @llvm.ssub.sat.i4(i4 -4, i4 5) ; %res = -8
  10094. %res = call i4 @llvm.ssub.sat.i4(i4 4, i4 -5) ; %res = 7
  10095. '``llvm.usub.sat.*``' Intrinsics
  10096. ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  10097. Syntax
  10098. """""""
  10099. This is an overloaded intrinsic. You can use ``llvm.usub.sat``
  10100. on any integer bit width or vectors of integers.
  10101. ::
  10102. declare i16 @llvm.usub.sat.i16(i16 %a, i16 %b)
  10103. declare i32 @llvm.usub.sat.i32(i32 %a, i32 %b)
  10104. declare i64 @llvm.usub.sat.i64(i64 %a, i64 %b)
  10105. declare <4 x i32> @llvm.usub.sat.v4i32(<4 x i32> %a, <4 x i32> %b)
  10106. Overview
  10107. """""""""
  10108. The '``llvm.usub.sat``' family of intrinsic functions perform unsigned
  10109. saturation subtraction on the 2 arguments.
  10110. Arguments
  10111. """"""""""
  10112. The arguments (%a and %b) and the result may be of integer types of any bit
  10113. width, but they must have the same bit width. ``%a`` and ``%b`` are the two
  10114. values that will undergo unsigned subtraction.
  10115. Semantics:
  10116. """"""""""
  10117. The minimum value this operation can clamp to is 0, which is the smallest
  10118. unsigned value representable by the bit width of the unsigned arguments.
  10119. Because this is an unsigned operation, the result will never saturate towards
  10120. the largest possible value representable by this bit width.
  10121. Examples
  10122. """""""""
  10123. .. code-block:: llvm
  10124. %res = call i4 @llvm.usub.sat.i4(i4 2, i4 1) ; %res = 1
  10125. %res = call i4 @llvm.usub.sat.i4(i4 2, i4 6) ; %res = 0
  10126. Fixed Point Arithmetic Intrinsics
  10127. ---------------------------------
  10128. A fixed point number represents a real data type for a number that has a fixed
  10129. number of digits after a radix point (equivalent to the decimal point '.').
  10130. The number of digits after the radix point is referred as the ``scale``. These
  10131. are useful for representing fractional values to a specific precision. The
  10132. following intrinsics perform fixed point arithmetic operations on 2 operands
  10133. of the same scale, specified as the third argument.
  10134. The `llvm.*mul.fix` family of intrinsic functions represents a multiplication
  10135. of fixed point numbers through scaled integers. Therefore, fixed point
  10136. multplication can be represented as
  10137. ::
  10138. %result = call i4 @llvm.smul.fix.i4(i4 %a, i4 %b, i32 %scale)
  10139. ; Expands to
  10140. %a2 = sext i4 %a to i8
  10141. %b2 = sext i4 %b to i8
  10142. %mul = mul nsw nuw i8 %a, %b
  10143. %scale2 = trunc i32 %scale to i8
  10144. %r = ashr i8 %mul, i8 %scale2 ; this is for a target rounding down towards negative infinity
  10145. %result = trunc i8 %r to i4
  10146. For each of these functions, if the result cannot be represented exactly with
  10147. the provided scale, the result is rounded. Rounding is unspecified since
  10148. preferred rounding may vary for different targets. Rounding is specified
  10149. through a target hook. Different pipelines should legalize or optimize this
  10150. using the rounding specified by this hook if it is provided. Operations like
  10151. constant folding, instruction combining, KnownBits, and ValueTracking should
  10152. also use this hook, if provided, and not assume the direction of rounding. A
  10153. rounded result must always be within one unit of precision from the true
  10154. result. That is, the error between the returned result and the true result must
  10155. be less than 1/2^(scale).
  10156. '``llvm.smul.fix.*``' Intrinsics
  10157. ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  10158. Syntax
  10159. """""""
  10160. This is an overloaded intrinsic. You can use ``llvm.smul.fix``
  10161. on any integer bit width or vectors of integers.
  10162. ::
  10163. declare i16 @llvm.smul.fix.i16(i16 %a, i16 %b, i32 %scale)
  10164. declare i32 @llvm.smul.fix.i32(i32 %a, i32 %b, i32 %scale)
  10165. declare i64 @llvm.smul.fix.i64(i64 %a, i64 %b, i32 %scale)
  10166. declare <4 x i32> @llvm.smul.fix.v4i32(<4 x i32> %a, <4 x i32> %b, i32 %scale)
  10167. Overview
  10168. """""""""
  10169. The '``llvm.smul.fix``' family of intrinsic functions perform signed
  10170. fixed point multiplication on 2 arguments of the same scale.
  10171. Arguments
  10172. """"""""""
  10173. The arguments (%a and %b) and the result may be of integer types of any bit
  10174. width, but they must have the same bit width. The arguments may also work with
  10175. int vectors of the same length and int size. ``%a`` and ``%b`` are the two
  10176. values that will undergo signed fixed point multiplication. The argument
  10177. ``%scale`` represents the scale of both operands, and must be a constant
  10178. integer.
  10179. Semantics:
  10180. """"""""""
  10181. This operation performs fixed point multiplication on the 2 arguments of a
  10182. specified scale. The result will also be returned in the same scale specified
  10183. in the third argument.
  10184. If the result value cannot be precisely represented in the given scale, the
  10185. value is rounded up or down to the closest representable value. The rounding
  10186. direction is unspecified.
  10187. It is undefined behavior if the result value does not fit within the range of
  10188. the fixed point type.
  10189. Examples
  10190. """""""""
  10191. .. code-block:: llvm
  10192. %res = call i4 @llvm.smul.fix.i4(i4 3, i4 2, i32 0) ; %res = 6 (2 x 3 = 6)
  10193. %res = call i4 @llvm.smul.fix.i4(i4 3, i4 2, i32 1) ; %res = 3 (1.5 x 1 = 1.5)
  10194. %res = call i4 @llvm.smul.fix.i4(i4 3, i4 -2, i32 1) ; %res = -3 (1.5 x -1 = -1.5)
  10195. ; The result in the following could be rounded up to -2 or down to -2.5
  10196. %res = call i4 @llvm.smul.fix.i4(i4 3, i4 -3, i32 1) ; %res = -5 (or -4) (1.5 x -1.5 = -2.25)
  10197. '``llvm.umul.fix.*``' Intrinsics
  10198. ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  10199. Syntax
  10200. """""""
  10201. This is an overloaded intrinsic. You can use ``llvm.umul.fix``
  10202. on any integer bit width or vectors of integers.
  10203. ::
  10204. declare i16 @llvm.umul.fix.i16(i16 %a, i16 %b, i32 %scale)
  10205. declare i32 @llvm.umul.fix.i32(i32 %a, i32 %b, i32 %scale)
  10206. declare i64 @llvm.umul.fix.i64(i64 %a, i64 %b, i32 %scale)
  10207. declare <4 x i32> @llvm.umul.fix.v4i32(<4 x i32> %a, <4 x i32> %b, i32 %scale)
  10208. Overview
  10209. """""""""
  10210. The '``llvm.umul.fix``' family of intrinsic functions perform unsigned
  10211. fixed point multiplication on 2 arguments of the same scale.
  10212. Arguments
  10213. """"""""""
  10214. The arguments (%a and %b) and the result may be of integer types of any bit
  10215. width, but they must have the same bit width. The arguments may also work with
  10216. int vectors of the same length and int size. ``%a`` and ``%b`` are the two
  10217. values that will undergo unsigned fixed point multiplication. The argument
  10218. ``%scale`` represents the scale of both operands, and must be a constant
  10219. integer.
  10220. Semantics:
  10221. """"""""""
  10222. This operation performs unsigned fixed point multiplication on the 2 arguments of a
  10223. specified scale. The result will also be returned in the same scale specified
  10224. in the third argument.
  10225. If the result value cannot be precisely represented in the given scale, the
  10226. value is rounded up or down to the closest representable value. The rounding
  10227. direction is unspecified.
  10228. It is undefined behavior if the result value does not fit within the range of
  10229. the fixed point type.
  10230. Examples
  10231. """""""""
  10232. .. code-block:: llvm
  10233. %res = call i4 @llvm.umul.fix.i4(i4 3, i4 2, i32 0) ; %res = 6 (2 x 3 = 6)
  10234. %res = call i4 @llvm.umul.fix.i4(i4 3, i4 2, i32 1) ; %res = 3 (1.5 x 1 = 1.5)
  10235. ; The result in the following could be rounded down to 3.5 or up to 4
  10236. %res = call i4 @llvm.umul.fix.i4(i4 15, i4 1, i32 1) ; %res = 7 (or 8) (7.5 x 0.5 = 3.75)
  10237. '``llvm.smul.fix.sat.*``' Intrinsics
  10238. ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  10239. Syntax
  10240. """""""
  10241. This is an overloaded intrinsic. You can use ``llvm.smul.fix.sat``
  10242. on any integer bit width or vectors of integers.
  10243. ::
  10244. declare i16 @llvm.smul.fix.sat.i16(i16 %a, i16 %b, i32 %scale)
  10245. declare i32 @llvm.smul.fix.sat.i32(i32 %a, i32 %b, i32 %scale)
  10246. declare i64 @llvm.smul.fix.sat.i64(i64 %a, i64 %b, i32 %scale)
  10247. declare <4 x i32> @llvm.smul.fix.sat.v4i32(<4 x i32> %a, <4 x i32> %b, i32 %scale)
  10248. Overview
  10249. """""""""
  10250. The '``llvm.smul.fix.sat``' family of intrinsic functions perform signed
  10251. fixed point saturation multiplication on 2 arguments of the same scale.
  10252. Arguments
  10253. """"""""""
  10254. The arguments (%a and %b) and the result may be of integer types of any bit
  10255. width, but they must have the same bit width. ``%a`` and ``%b`` are the two
  10256. values that will undergo signed fixed point multiplication. The argument
  10257. ``%scale`` represents the scale of both operands, and must be a constant
  10258. integer.
  10259. Semantics:
  10260. """"""""""
  10261. This operation performs fixed point multiplication on the 2 arguments of a
  10262. specified scale. The result will also be returned in the same scale specified
  10263. in the third argument.
  10264. If the result value cannot be precisely represented in the given scale, the
  10265. value is rounded up or down to the closest representable value. The rounding
  10266. direction is unspecified.
  10267. The maximum value this operation can clamp to is the largest signed value
  10268. representable by the bit width of the first 2 arguments. The minimum value is the
  10269. smallest signed value representable by this bit width.
  10270. Examples
  10271. """""""""
  10272. .. code-block:: llvm
  10273. %res = call i4 @llvm.smul.fix.sat.i4(i4 3, i4 2, i32 0) ; %res = 6 (2 x 3 = 6)
  10274. %res = call i4 @llvm.smul.fix.sat.i4(i4 3, i4 2, i32 1) ; %res = 3 (1.5 x 1 = 1.5)
  10275. %res = call i4 @llvm.smul.fix.sat.i4(i4 3, i4 -2, i32 1) ; %res = -3 (1.5 x -1 = -1.5)
  10276. ; The result in the following could be rounded up to -2 or down to -2.5
  10277. %res = call i4 @llvm.smul.fix.sat.i4(i4 3, i4 -3, i32 1) ; %res = -5 (or -4) (1.5 x -1.5 = -2.25)
  10278. ; Saturation
  10279. %res = call i4 @llvm.smul.fix.sat.i4(i4 7, i4 2, i32 0) ; %res = 7
  10280. %res = call i4 @llvm.smul.fix.sat.i4(i4 7, i4 4, i32 2) ; %res = 7
  10281. %res = call i4 @llvm.smul.fix.sat.i4(i4 -8, i4 5, i32 2) ; %res = -8
  10282. %res = call i4 @llvm.smul.fix.sat.i4(i4 -8, i4 -2, i32 1) ; %res = 7
  10283. ; Scale can affect the saturation result
  10284. %res = call i4 @llvm.smul.fix.sat.i4(i4 2, i4 4, i32 0) ; %res = 7 (2 x 4 -> clamped to 7)
  10285. %res = call i4 @llvm.smul.fix.sat.i4(i4 2, i4 4, i32 1) ; %res = 4 (1 x 2 = 2)
  10286. '``llvm.umul.fix.sat.*``' Intrinsics
  10287. ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  10288. Syntax
  10289. """""""
  10290. This is an overloaded intrinsic. You can use ``llvm.umul.fix.sat``
  10291. on any integer bit width or vectors of integers.
  10292. ::
  10293. declare i16 @llvm.umul.fix.sat.i16(i16 %a, i16 %b, i32 %scale)
  10294. declare i32 @llvm.umul.fix.sat.i32(i32 %a, i32 %b, i32 %scale)
  10295. declare i64 @llvm.umul.fix.sat.i64(i64 %a, i64 %b, i32 %scale)
  10296. declare <4 x i32> @llvm.umul.fix.sat.v4i32(<4 x i32> %a, <4 x i32> %b, i32 %scale)
  10297. Overview
  10298. """""""""
  10299. The '``llvm.umul.fix.sat``' family of intrinsic functions perform unsigned
  10300. fixed point saturation multiplication on 2 arguments of the same scale.
  10301. Arguments
  10302. """"""""""
  10303. The arguments (%a and %b) and the result may be of integer types of any bit
  10304. width, but they must have the same bit width. ``%a`` and ``%b`` are the two
  10305. values that will undergo unsigned fixed point multiplication. The argument
  10306. ``%scale`` represents the scale of both operands, and must be a constant
  10307. integer.
  10308. Semantics:
  10309. """"""""""
  10310. This operation performs fixed point multiplication on the 2 arguments of a
  10311. specified scale. The result will also be returned in the same scale specified
  10312. in the third argument.
  10313. If the result value cannot be precisely represented in the given scale, the
  10314. value is rounded up or down to the closest representable value. The rounding
  10315. direction is unspecified.
  10316. The maximum value this operation can clamp to is the largest unsigned value
  10317. representable by the bit width of the first 2 arguments. The minimum value is the
  10318. smallest unsigned value representable by this bit width (zero).
  10319. Examples
  10320. """""""""
  10321. .. code-block:: llvm
  10322. %res = call i4 @llvm.umul.fix.sat.i4(i4 3, i4 2, i32 0) ; %res = 6 (2 x 3 = 6)
  10323. %res = call i4 @llvm.umul.fix.sat.i4(i4 3, i4 2, i32 1) ; %res = 3 (1.5 x 1 = 1.5)
  10324. ; The result in the following could be rounded down to 2 or up to 2.5
  10325. %res = call i4 @llvm.umul.fix.sat.i4(i4 3, i4 3, i32 1) ; %res = 4 (or 5) (1.5 x 1.5 = 2.25)
  10326. ; Saturation
  10327. %res = call i4 @llvm.umul.fix.sat.i4(i4 8, i4 2, i32 0) ; %res = 15 (8 x 2 -> clamped to 15)
  10328. %res = call i4 @llvm.umul.fix.sat.i4(i4 8, i4 8, i32 2) ; %res = 15 (2 x 2 -> clamped to 3.75)
  10329. ; Scale can affect the saturation result
  10330. %res = call i4 @llvm.umul.fix.sat.i4(i4 2, i4 4, i32 0) ; %res = 7 (2 x 4 -> clamped to 7)
  10331. %res = call i4 @llvm.umul.fix.sat.i4(i4 2, i4 4, i32 1) ; %res = 4 (1 x 2 = 2)
  10332. Specialised Arithmetic Intrinsics
  10333. ---------------------------------
  10334. '``llvm.canonicalize.*``' Intrinsic
  10335. ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  10336. Syntax:
  10337. """""""
  10338. ::
  10339. declare float @llvm.canonicalize.f32(float %a)
  10340. declare double @llvm.canonicalize.f64(double %b)
  10341. Overview:
  10342. """""""""
  10343. The '``llvm.canonicalize.*``' intrinsic returns the platform specific canonical
  10344. encoding of a floating-point number. This canonicalization is useful for
  10345. implementing certain numeric primitives such as frexp. The canonical encoding is
  10346. defined by IEEE-754-2008 to be:
  10347. ::
  10348. 2.1.8 canonical encoding: The preferred encoding of a floating-point
  10349. representation in a format. Applied to declets, significands of finite
  10350. numbers, infinities, and NaNs, especially in decimal formats.
  10351. This operation can also be considered equivalent to the IEEE-754-2008
  10352. conversion of a floating-point value to the same format. NaNs are handled
  10353. according to section 6.2.
  10354. Examples of non-canonical encodings:
  10355. - x87 pseudo denormals, pseudo NaNs, pseudo Infinity, Unnormals. These are
  10356. converted to a canonical representation per hardware-specific protocol.
  10357. - Many normal decimal floating-point numbers have non-canonical alternative
  10358. encodings.
  10359. - Some machines, like GPUs or ARMv7 NEON, do not support subnormal values.
  10360. These are treated as non-canonical encodings of zero and will be flushed to
  10361. a zero of the same sign by this operation.
  10362. Note that per IEEE-754-2008 6.2, systems that support signaling NaNs with
  10363. default exception handling must signal an invalid exception, and produce a
  10364. quiet NaN result.
  10365. This function should always be implementable as multiplication by 1.0, provided
  10366. that the compiler does not constant fold the operation. Likewise, division by
  10367. 1.0 and ``llvm.minnum(x, x)`` are possible implementations. Addition with
  10368. -0.0 is also sufficient provided that the rounding mode is not -Infinity.
  10369. ``@llvm.canonicalize`` must preserve the equality relation. That is:
  10370. - ``(@llvm.canonicalize(x) == x)`` is equivalent to ``(x == x)``
  10371. - ``(@llvm.canonicalize(x) == @llvm.canonicalize(y))`` is equivalent to
  10372. to ``(x == y)``
  10373. Additionally, the sign of zero must be conserved:
  10374. ``@llvm.canonicalize(-0.0) = -0.0`` and ``@llvm.canonicalize(+0.0) = +0.0``
  10375. The payload bits of a NaN must be conserved, with two exceptions.
  10376. First, environments which use only a single canonical representation of NaN
  10377. must perform said canonicalization. Second, SNaNs must be quieted per the
  10378. usual methods.
  10379. The canonicalization operation may be optimized away if:
  10380. - The input is known to be canonical. For example, it was produced by a
  10381. floating-point operation that is required by the standard to be canonical.
  10382. - The result is consumed only by (or fused with) other floating-point
  10383. operations. That is, the bits of the floating-point value are not examined.
  10384. '``llvm.fmuladd.*``' Intrinsic
  10385. ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  10386. Syntax:
  10387. """""""
  10388. ::
  10389. declare float @llvm.fmuladd.f32(float %a, float %b, float %c)
  10390. declare double @llvm.fmuladd.f64(double %a, double %b, double %c)
  10391. Overview:
  10392. """""""""
  10393. The '``llvm.fmuladd.*``' intrinsic functions represent multiply-add
  10394. expressions that can be fused if the code generator determines that (a) the
  10395. target instruction set has support for a fused operation, and (b) that the
  10396. fused operation is more efficient than the equivalent, separate pair of mul
  10397. and add instructions.
  10398. Arguments:
  10399. """"""""""
  10400. The '``llvm.fmuladd.*``' intrinsics each take three arguments: two
  10401. multiplicands, a and b, and an addend c.
  10402. Semantics:
  10403. """"""""""
  10404. The expression:
  10405. ::
  10406. %0 = call float @llvm.fmuladd.f32(%a, %b, %c)
  10407. is equivalent to the expression a \* b + c, except that rounding will
  10408. not be performed between the multiplication and addition steps if the
  10409. code generator fuses the operations. Fusion is not guaranteed, even if
  10410. the target platform supports it. If a fused multiply-add is required, the
  10411. corresponding :ref:`llvm.fma <int_fma>` intrinsic function should be used
  10412. instead. This never sets errno, just as '``llvm.fma.*``'.
  10413. Examples:
  10414. """""""""
  10415. .. code-block:: llvm
  10416. %r2 = call float @llvm.fmuladd.f32(float %a, float %b, float %c) ; yields float:r2 = (a * b) + c
  10417. Experimental Vector Reduction Intrinsics
  10418. ----------------------------------------
  10419. Horizontal reductions of vectors can be expressed using the following
  10420. intrinsics. Each one takes a vector operand as an input and applies its
  10421. respective operation across all elements of the vector, returning a single
  10422. scalar result of the same element type.
  10423. '``llvm.experimental.vector.reduce.add.*``' Intrinsic
  10424. ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  10425. Syntax:
  10426. """""""
  10427. ::
  10428. declare i32 @llvm.experimental.vector.reduce.add.v4i32(<4 x i32> %a)
  10429. declare i64 @llvm.experimental.vector.reduce.add.v2i64(<2 x i64> %a)
  10430. Overview:
  10431. """""""""
  10432. The '``llvm.experimental.vector.reduce.add.*``' intrinsics do an integer ``ADD``
  10433. reduction of a vector, returning the result as a scalar. The return type matches
  10434. the element-type of the vector input.
  10435. Arguments:
  10436. """"""""""
  10437. The argument to this intrinsic must be a vector of integer values.
  10438. '``llvm.experimental.vector.reduce.v2.fadd.*``' Intrinsic
  10439. ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  10440. Syntax:
  10441. """""""
  10442. ::
  10443. declare float @llvm.experimental.vector.reduce.v2.fadd.f32.v4f32(float %start_value, <4 x float> %a)
  10444. declare double @llvm.experimental.vector.reduce.v2.fadd.f64.v2f64(double %start_value, <2 x double> %a)
  10445. Overview:
  10446. """""""""
  10447. The '``llvm.experimental.vector.reduce.v2.fadd.*``' intrinsics do a floating-point
  10448. ``ADD`` reduction of a vector, returning the result as a scalar. The return type
  10449. matches the element-type of the vector input.
  10450. If the intrinsic call has the 'reassoc' or 'fast' flags set, then the
  10451. reduction will not preserve the associativity of an equivalent scalarized
  10452. counterpart. Otherwise the reduction will be *ordered*, thus implying that
  10453. the operation respects the associativity of a scalarized reduction.
  10454. Arguments:
  10455. """"""""""
  10456. The first argument to this intrinsic is a scalar start value for the reduction.
  10457. The type of the start value matches the element-type of the vector input.
  10458. The second argument must be a vector of floating-point values.
  10459. Examples:
  10460. """""""""
  10461. ::
  10462. %unord = call reassoc float @llvm.experimental.vector.reduce.v2.fadd.f32.v4f32(float 0.0, <4 x float> %input) ; unordered reduction
  10463. %ord = call float @llvm.experimental.vector.reduce.v2.fadd.f32.v4f32(float %start_value, <4 x float> %input) ; ordered reduction
  10464. '``llvm.experimental.vector.reduce.mul.*``' Intrinsic
  10465. ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  10466. Syntax:
  10467. """""""
  10468. ::
  10469. declare i32 @llvm.experimental.vector.reduce.mul.v4i32(<4 x i32> %a)
  10470. declare i64 @llvm.experimental.vector.reduce.mul.v2i64(<2 x i64> %a)
  10471. Overview:
  10472. """""""""
  10473. The '``llvm.experimental.vector.reduce.mul.*``' intrinsics do an integer ``MUL``
  10474. reduction of a vector, returning the result as a scalar. The return type matches
  10475. the element-type of the vector input.
  10476. Arguments:
  10477. """"""""""
  10478. The argument to this intrinsic must be a vector of integer values.
  10479. '``llvm.experimental.vector.reduce.v2.fmul.*``' Intrinsic
  10480. ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  10481. Syntax:
  10482. """""""
  10483. ::
  10484. declare float @llvm.experimental.vector.reduce.v2.fmul.f32.v4f32(float %start_value, <4 x float> %a)
  10485. declare double @llvm.experimental.vector.reduce.v2.fmul.f64.v2f64(double %start_value, <2 x double> %a)
  10486. Overview:
  10487. """""""""
  10488. The '``llvm.experimental.vector.reduce.v2.fmul.*``' intrinsics do a floating-point
  10489. ``MUL`` reduction of a vector, returning the result as a scalar. The return type
  10490. matches the element-type of the vector input.
  10491. If the intrinsic call has the 'reassoc' or 'fast' flags set, then the
  10492. reduction will not preserve the associativity of an equivalent scalarized
  10493. counterpart. Otherwise the reduction will be *ordered*, thus implying that
  10494. the operation respects the associativity of a scalarized reduction.
  10495. Arguments:
  10496. """"""""""
  10497. The first argument to this intrinsic is a scalar start value for the reduction.
  10498. The type of the start value matches the element-type of the vector input.
  10499. The second argument must be a vector of floating-point values.
  10500. Examples:
  10501. """""""""
  10502. ::
  10503. %unord = call reassoc float @llvm.experimental.vector.reduce.v2.fmul.f32.v4f32(float 1.0, <4 x float> %input) ; unordered reduction
  10504. %ord = call float @llvm.experimental.vector.reduce.v2.fmul.f32.v4f32(float %start_value, <4 x float> %input) ; ordered reduction
  10505. '``llvm.experimental.vector.reduce.and.*``' Intrinsic
  10506. ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  10507. Syntax:
  10508. """""""
  10509. ::
  10510. declare i32 @llvm.experimental.vector.reduce.and.v4i32(<4 x i32> %a)
  10511. Overview:
  10512. """""""""
  10513. The '``llvm.experimental.vector.reduce.and.*``' intrinsics do a bitwise ``AND``
  10514. reduction of a vector, returning the result as a scalar. The return type matches
  10515. the element-type of the vector input.
  10516. Arguments:
  10517. """"""""""
  10518. The argument to this intrinsic must be a vector of integer values.
  10519. '``llvm.experimental.vector.reduce.or.*``' Intrinsic
  10520. ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  10521. Syntax:
  10522. """""""
  10523. ::
  10524. declare i32 @llvm.experimental.vector.reduce.or.v4i32(<4 x i32> %a)
  10525. Overview:
  10526. """""""""
  10527. The '``llvm.experimental.vector.reduce.or.*``' intrinsics do a bitwise ``OR`` reduction
  10528. of a vector, returning the result as a scalar. The return type matches the
  10529. element-type of the vector input.
  10530. Arguments:
  10531. """"""""""
  10532. The argument to this intrinsic must be a vector of integer values.
  10533. '``llvm.experimental.vector.reduce.xor.*``' Intrinsic
  10534. ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  10535. Syntax:
  10536. """""""
  10537. ::
  10538. declare i32 @llvm.experimental.vector.reduce.xor.v4i32(<4 x i32> %a)
  10539. Overview:
  10540. """""""""
  10541. The '``llvm.experimental.vector.reduce.xor.*``' intrinsics do a bitwise ``XOR``
  10542. reduction of a vector, returning the result as a scalar. The return type matches
  10543. the element-type of the vector input.
  10544. Arguments:
  10545. """"""""""
  10546. The argument to this intrinsic must be a vector of integer values.
  10547. '``llvm.experimental.vector.reduce.smax.*``' Intrinsic
  10548. ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  10549. Syntax:
  10550. """""""
  10551. ::
  10552. declare i32 @llvm.experimental.vector.reduce.smax.v4i32(<4 x i32> %a)
  10553. Overview:
  10554. """""""""
  10555. The '``llvm.experimental.vector.reduce.smax.*``' intrinsics do a signed integer
  10556. ``MAX`` reduction of a vector, returning the result as a scalar. The return type
  10557. matches the element-type of the vector input.
  10558. Arguments:
  10559. """"""""""
  10560. The argument to this intrinsic must be a vector of integer values.
  10561. '``llvm.experimental.vector.reduce.smin.*``' Intrinsic
  10562. ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  10563. Syntax:
  10564. """""""
  10565. ::
  10566. declare i32 @llvm.experimental.vector.reduce.smin.v4i32(<4 x i32> %a)
  10567. Overview:
  10568. """""""""
  10569. The '``llvm.experimental.vector.reduce.smin.*``' intrinsics do a signed integer
  10570. ``MIN`` reduction of a vector, returning the result as a scalar. The return type
  10571. matches the element-type of the vector input.
  10572. Arguments:
  10573. """"""""""
  10574. The argument to this intrinsic must be a vector of integer values.
  10575. '``llvm.experimental.vector.reduce.umax.*``' Intrinsic
  10576. ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  10577. Syntax:
  10578. """""""
  10579. ::
  10580. declare i32 @llvm.experimental.vector.reduce.umax.v4i32(<4 x i32> %a)
  10581. Overview:
  10582. """""""""
  10583. The '``llvm.experimental.vector.reduce.umax.*``' intrinsics do an unsigned
  10584. integer ``MAX`` reduction of a vector, returning the result as a scalar. The
  10585. return type matches the element-type of the vector input.
  10586. Arguments:
  10587. """"""""""
  10588. The argument to this intrinsic must be a vector of integer values.
  10589. '``llvm.experimental.vector.reduce.umin.*``' Intrinsic
  10590. ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  10591. Syntax:
  10592. """""""
  10593. ::
  10594. declare i32 @llvm.experimental.vector.reduce.umin.v4i32(<4 x i32> %a)
  10595. Overview:
  10596. """""""""
  10597. The '``llvm.experimental.vector.reduce.umin.*``' intrinsics do an unsigned
  10598. integer ``MIN`` reduction of a vector, returning the result as a scalar. The
  10599. return type matches the element-type of the vector input.
  10600. Arguments:
  10601. """"""""""
  10602. The argument to this intrinsic must be a vector of integer values.
  10603. '``llvm.experimental.vector.reduce.fmax.*``' Intrinsic
  10604. ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  10605. Syntax:
  10606. """""""
  10607. ::
  10608. declare float @llvm.experimental.vector.reduce.fmax.v4f32(<4 x float> %a)
  10609. declare double @llvm.experimental.vector.reduce.fmax.v2f64(<2 x double> %a)
  10610. Overview:
  10611. """""""""
  10612. The '``llvm.experimental.vector.reduce.fmax.*``' intrinsics do a floating-point
  10613. ``MAX`` reduction of a vector, returning the result as a scalar. The return type
  10614. matches the element-type of the vector input.
  10615. If the intrinsic call has the ``nnan`` fast-math flag then the operation can
  10616. assume that NaNs are not present in the input vector.
  10617. Arguments:
  10618. """"""""""
  10619. The argument to this intrinsic must be a vector of floating-point values.
  10620. '``llvm.experimental.vector.reduce.fmin.*``' Intrinsic
  10621. ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  10622. Syntax:
  10623. """""""
  10624. ::
  10625. declare float @llvm.experimental.vector.reduce.fmin.v4f32(<4 x float> %a)
  10626. declare double @llvm.experimental.vector.reduce.fmin.v2f64(<2 x double> %a)
  10627. Overview:
  10628. """""""""
  10629. The '``llvm.experimental.vector.reduce.fmin.*``' intrinsics do a floating-point
  10630. ``MIN`` reduction of a vector, returning the result as a scalar. The return type
  10631. matches the element-type of the vector input.
  10632. If the intrinsic call has the ``nnan`` fast-math flag then the operation can
  10633. assume that NaNs are not present in the input vector.
  10634. Arguments:
  10635. """"""""""
  10636. The argument to this intrinsic must be a vector of floating-point values.
  10637. Half Precision Floating-Point Intrinsics
  10638. ----------------------------------------
  10639. For most target platforms, half precision floating-point is a
  10640. storage-only format. This means that it is a dense encoding (in memory)
  10641. but does not support computation in the format.
  10642. This means that code must first load the half-precision floating-point
  10643. value as an i16, then convert it to float with
  10644. :ref:`llvm.convert.from.fp16 <int_convert_from_fp16>`. Computation can
  10645. then be performed on the float value (including extending to double
  10646. etc). To store the value back to memory, it is first converted to float
  10647. if needed, then converted to i16 with
  10648. :ref:`llvm.convert.to.fp16 <int_convert_to_fp16>`, then storing as an
  10649. i16 value.
  10650. .. _int_convert_to_fp16:
  10651. '``llvm.convert.to.fp16``' Intrinsic
  10652. ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  10653. Syntax:
  10654. """""""
  10655. ::
  10656. declare i16 @llvm.convert.to.fp16.f32(float %a)
  10657. declare i16 @llvm.convert.to.fp16.f64(double %a)
  10658. Overview:
  10659. """""""""
  10660. The '``llvm.convert.to.fp16``' intrinsic function performs a conversion from a
  10661. conventional floating-point type to half precision floating-point format.
  10662. Arguments:
  10663. """"""""""
  10664. The intrinsic function contains single argument - the value to be
  10665. converted.
  10666. Semantics:
  10667. """"""""""
  10668. The '``llvm.convert.to.fp16``' intrinsic function performs a conversion from a
  10669. conventional floating-point format to half precision floating-point format. The
  10670. return value is an ``i16`` which contains the converted number.
  10671. Examples:
  10672. """""""""
  10673. .. code-block:: llvm
  10674. %res = call i16 @llvm.convert.to.fp16.f32(float %a)
  10675. store i16 %res, i16* @x, align 2
  10676. .. _int_convert_from_fp16:
  10677. '``llvm.convert.from.fp16``' Intrinsic
  10678. ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  10679. Syntax:
  10680. """""""
  10681. ::
  10682. declare float @llvm.convert.from.fp16.f32(i16 %a)
  10683. declare double @llvm.convert.from.fp16.f64(i16 %a)
  10684. Overview:
  10685. """""""""
  10686. The '``llvm.convert.from.fp16``' intrinsic function performs a
  10687. conversion from half precision floating-point format to single precision
  10688. floating-point format.
  10689. Arguments:
  10690. """"""""""
  10691. The intrinsic function contains single argument - the value to be
  10692. converted.
  10693. Semantics:
  10694. """"""""""
  10695. The '``llvm.convert.from.fp16``' intrinsic function performs a
  10696. conversion from half single precision floating-point format to single
  10697. precision floating-point format. The input half-float value is
  10698. represented by an ``i16`` value.
  10699. Examples:
  10700. """""""""
  10701. .. code-block:: llvm
  10702. %a = load i16, i16* @x, align 2
  10703. %res = call float @llvm.convert.from.fp16(i16 %a)
  10704. .. _dbg_intrinsics:
  10705. Debugger Intrinsics
  10706. -------------------
  10707. The LLVM debugger intrinsics (which all start with ``llvm.dbg.``
  10708. prefix), are described in the `LLVM Source Level
  10709. Debugging <SourceLevelDebugging.html#format-common-intrinsics>`_
  10710. document.
  10711. Exception Handling Intrinsics
  10712. -----------------------------
  10713. The LLVM exception handling intrinsics (which all start with
  10714. ``llvm.eh.`` prefix), are described in the `LLVM Exception
  10715. Handling <ExceptionHandling.html#format-common-intrinsics>`_ document.
  10716. .. _int_trampoline:
  10717. Trampoline Intrinsics
  10718. ---------------------
  10719. These intrinsics make it possible to excise one parameter, marked with
  10720. the :ref:`nest <nest>` attribute, from a function. The result is a
  10721. callable function pointer lacking the nest parameter - the caller does
  10722. not need to provide a value for it. Instead, the value to use is stored
  10723. in advance in a "trampoline", a block of memory usually allocated on the
  10724. stack, which also contains code to splice the nest value into the
  10725. argument list. This is used to implement the GCC nested function address
  10726. extension.
  10727. For example, if the function is ``i32 f(i8* nest %c, i32 %x, i32 %y)``
  10728. then the resulting function pointer has signature ``i32 (i32, i32)*``.
  10729. It can be created as follows:
  10730. .. code-block:: llvm
  10731. %tramp = alloca [10 x i8], align 4 ; size and alignment only correct for X86
  10732. %tramp1 = getelementptr [10 x i8], [10 x i8]* %tramp, i32 0, i32 0
  10733. call i8* @llvm.init.trampoline(i8* %tramp1, i8* bitcast (i32 (i8*, i32, i32)* @f to i8*), i8* %nval)
  10734. %p = call i8* @llvm.adjust.trampoline(i8* %tramp1)
  10735. %fp = bitcast i8* %p to i32 (i32, i32)*
  10736. The call ``%val = call i32 %fp(i32 %x, i32 %y)`` is then equivalent to
  10737. ``%val = call i32 %f(i8* %nval, i32 %x, i32 %y)``.
  10738. .. _int_it:
  10739. '``llvm.init.trampoline``' Intrinsic
  10740. ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  10741. Syntax:
  10742. """""""
  10743. ::
  10744. declare void @llvm.init.trampoline(i8* <tramp>, i8* <func>, i8* <nval>)
  10745. Overview:
  10746. """""""""
  10747. This fills the memory pointed to by ``tramp`` with executable code,
  10748. turning it into a trampoline.
  10749. Arguments:
  10750. """"""""""
  10751. The ``llvm.init.trampoline`` intrinsic takes three arguments, all
  10752. pointers. The ``tramp`` argument must point to a sufficiently large and
  10753. sufficiently aligned block of memory; this memory is written to by the
  10754. intrinsic. Note that the size and the alignment are target-specific -
  10755. LLVM currently provides no portable way of determining them, so a
  10756. front-end that generates this intrinsic needs to have some
  10757. target-specific knowledge. The ``func`` argument must hold a function
  10758. bitcast to an ``i8*``.
  10759. Semantics:
  10760. """"""""""
  10761. The block of memory pointed to by ``tramp`` is filled with target
  10762. dependent code, turning it into a function. Then ``tramp`` needs to be
  10763. passed to :ref:`llvm.adjust.trampoline <int_at>` to get a pointer which can
  10764. be :ref:`bitcast (to a new function) and called <int_trampoline>`. The new
  10765. function's signature is the same as that of ``func`` with any arguments
  10766. marked with the ``nest`` attribute removed. At most one such ``nest``
  10767. argument is allowed, and it must be of pointer type. Calling the new
  10768. function is equivalent to calling ``func`` with the same argument list,
  10769. but with ``nval`` used for the missing ``nest`` argument. If, after
  10770. calling ``llvm.init.trampoline``, the memory pointed to by ``tramp`` is
  10771. modified, then the effect of any later call to the returned function
  10772. pointer is undefined.
  10773. .. _int_at:
  10774. '``llvm.adjust.trampoline``' Intrinsic
  10775. ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  10776. Syntax:
  10777. """""""
  10778. ::
  10779. declare i8* @llvm.adjust.trampoline(i8* <tramp>)
  10780. Overview:
  10781. """""""""
  10782. This performs any required machine-specific adjustment to the address of
  10783. a trampoline (passed as ``tramp``).
  10784. Arguments:
  10785. """"""""""
  10786. ``tramp`` must point to a block of memory which already has trampoline
  10787. code filled in by a previous call to
  10788. :ref:`llvm.init.trampoline <int_it>`.
  10789. Semantics:
  10790. """"""""""
  10791. On some architectures the address of the code to be executed needs to be
  10792. different than the address where the trampoline is actually stored. This
  10793. intrinsic returns the executable address corresponding to ``tramp``
  10794. after performing the required machine specific adjustments. The pointer
  10795. returned can then be :ref:`bitcast and executed <int_trampoline>`.
  10796. .. _int_mload_mstore:
  10797. Masked Vector Load and Store Intrinsics
  10798. ---------------------------------------
  10799. LLVM provides intrinsics for predicated vector load and store operations. The predicate is specified by a mask operand, which holds one bit per vector element, switching the associated vector lane on or off. The memory addresses corresponding to the "off" lanes are not accessed. When all bits of the mask are on, the intrinsic is identical to a regular vector load or store. When all bits are off, no memory is accessed.
  10800. .. _int_mload:
  10801. '``llvm.masked.load.*``' Intrinsics
  10802. ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  10803. Syntax:
  10804. """""""
  10805. This is an overloaded intrinsic. The loaded data is a vector of any integer, floating-point or pointer data type.
  10806. ::
  10807. declare <16 x float> @llvm.masked.load.v16f32.p0v16f32 (<16 x float>* <ptr>, i32 <alignment>, <16 x i1> <mask>, <16 x float> <passthru>)
  10808. declare <2 x double> @llvm.masked.load.v2f64.p0v2f64 (<2 x double>* <ptr>, i32 <alignment>, <2 x i1> <mask>, <2 x double> <passthru>)
  10809. ;; The data is a vector of pointers to double
  10810. declare <8 x double*> @llvm.masked.load.v8p0f64.p0v8p0f64 (<8 x double*>* <ptr>, i32 <alignment>, <8 x i1> <mask>, <8 x double*> <passthru>)
  10811. ;; The data is a vector of function pointers
  10812. declare <8 x i32 ()*> @llvm.masked.load.v8p0f_i32f.p0v8p0f_i32f (<8 x i32 ()*>* <ptr>, i32 <alignment>, <8 x i1> <mask>, <8 x i32 ()*> <passthru>)
  10813. Overview:
  10814. """""""""
  10815. Reads a vector from memory according to the provided mask. The mask holds a bit for each vector lane, and is used to prevent memory accesses to the masked-off lanes. The masked-off lanes in the result vector are taken from the corresponding lanes of the '``passthru``' operand.
  10816. Arguments:
  10817. """"""""""
  10818. The first operand is the base pointer for the load. The second operand is the alignment of the source location. It must be a constant integer value. The third operand, mask, is a vector of boolean values with the same number of elements as the return type. The fourth is a pass-through value that is used to fill the masked-off lanes of the result. The return type, underlying type of the base pointer and the type of the '``passthru``' operand are the same vector types.
  10819. Semantics:
  10820. """"""""""
  10821. The '``llvm.masked.load``' intrinsic is designed for conditional reading of selected vector elements in a single IR operation. It is useful for targets that support vector masked loads and allows vectorizing predicated basic blocks on these targets. Other targets may support this intrinsic differently, for example by lowering it into a sequence of branches that guard scalar load operations.
  10822. The result of this operation is equivalent to a regular vector load instruction followed by a 'select' between the loaded and the passthru values, predicated on the same mask. However, using this intrinsic prevents exceptions on memory access to masked-off lanes.
  10823. ::
  10824. %res = call <16 x float> @llvm.masked.load.v16f32.p0v16f32 (<16 x float>* %ptr, i32 4, <16 x i1>%mask, <16 x float> %passthru)
  10825. ;; The result of the two following instructions is identical aside from potential memory access exception
  10826. %loadlal = load <16 x float>, <16 x float>* %ptr, align 4
  10827. %res = select <16 x i1> %mask, <16 x float> %loadlal, <16 x float> %passthru
  10828. .. _int_mstore:
  10829. '``llvm.masked.store.*``' Intrinsics
  10830. ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  10831. Syntax:
  10832. """""""
  10833. This is an overloaded intrinsic. The data stored in memory is a vector of any integer, floating-point or pointer data type.
  10834. ::
  10835. declare void @llvm.masked.store.v8i32.p0v8i32 (<8 x i32> <value>, <8 x i32>* <ptr>, i32 <alignment>, <8 x i1> <mask>)
  10836. declare void @llvm.masked.store.v16f32.p0v16f32 (<16 x float> <value>, <16 x float>* <ptr>, i32 <alignment>, <16 x i1> <mask>)
  10837. ;; The data is a vector of pointers to double
  10838. declare void @llvm.masked.store.v8p0f64.p0v8p0f64 (<8 x double*> <value>, <8 x double*>* <ptr>, i32 <alignment>, <8 x i1> <mask>)
  10839. ;; The data is a vector of function pointers
  10840. declare void @llvm.masked.store.v4p0f_i32f.p0v4p0f_i32f (<4 x i32 ()*> <value>, <4 x i32 ()*>* <ptr>, i32 <alignment>, <4 x i1> <mask>)
  10841. Overview:
  10842. """""""""
  10843. Writes a vector to memory according to the provided mask. The mask holds a bit for each vector lane, and is used to prevent memory accesses to the masked-off lanes.
  10844. Arguments:
  10845. """"""""""
  10846. The first operand is the vector value to be written to memory. The second operand is the base pointer for the store, it has the same underlying type as the value operand. The third operand is the alignment of the destination location. The fourth operand, mask, is a vector of boolean values. The types of the mask and the value operand must have the same number of vector elements.
  10847. Semantics:
  10848. """"""""""
  10849. The '``llvm.masked.store``' intrinsics is designed for conditional writing of selected vector elements in a single IR operation. It is useful for targets that support vector masked store and allows vectorizing predicated basic blocks on these targets. Other targets may support this intrinsic differently, for example by lowering it into a sequence of branches that guard scalar store operations.
  10850. The result of this operation is equivalent to a load-modify-store sequence. However, using this intrinsic prevents exceptions and data races on memory access to masked-off lanes.
  10851. ::
  10852. call void @llvm.masked.store.v16f32.p0v16f32(<16 x float> %value, <16 x float>* %ptr, i32 4, <16 x i1> %mask)
  10853. ;; The result of the following instructions is identical aside from potential data races and memory access exceptions
  10854. %oldval = load <16 x float>, <16 x float>* %ptr, align 4
  10855. %res = select <16 x i1> %mask, <16 x float> %value, <16 x float> %oldval
  10856. store <16 x float> %res, <16 x float>* %ptr, align 4
  10857. Masked Vector Gather and Scatter Intrinsics
  10858. -------------------------------------------
  10859. LLVM provides intrinsics for vector gather and scatter operations. They are similar to :ref:`Masked Vector Load and Store <int_mload_mstore>`, except they are designed for arbitrary memory accesses, rather than sequential memory accesses. Gather and scatter also employ a mask operand, which holds one bit per vector element, switching the associated vector lane on or off. The memory addresses corresponding to the "off" lanes are not accessed. When all bits are off, no memory is accessed.
  10860. .. _int_mgather:
  10861. '``llvm.masked.gather.*``' Intrinsics
  10862. ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  10863. Syntax:
  10864. """""""
  10865. This is an overloaded intrinsic. The loaded data are multiple scalar values of any integer, floating-point or pointer data type gathered together into one vector.
  10866. ::
  10867. declare <16 x float> @llvm.masked.gather.v16f32.v16p0f32 (<16 x float*> <ptrs>, i32 <alignment>, <16 x i1> <mask>, <16 x float> <passthru>)
  10868. declare <2 x double> @llvm.masked.gather.v2f64.v2p1f64 (<2 x double addrspace(1)*> <ptrs>, i32 <alignment>, <2 x i1> <mask>, <2 x double> <passthru>)
  10869. declare <8 x float*> @llvm.masked.gather.v8p0f32.v8p0p0f32 (<8 x float**> <ptrs>, i32 <alignment>, <8 x i1> <mask>, <8 x float*> <passthru>)
  10870. Overview:
  10871. """""""""
  10872. Reads scalar values from arbitrary memory locations and gathers them into one vector. The memory locations are provided in the vector of pointers '``ptrs``'. The memory is accessed according to the provided mask. The mask holds a bit for each vector lane, and is used to prevent memory accesses to the masked-off lanes. The masked-off lanes in the result vector are taken from the corresponding lanes of the '``passthru``' operand.
  10873. Arguments:
  10874. """"""""""
  10875. The first operand is a vector of pointers which holds all memory addresses to read. The second operand is an alignment of the source addresses. It must be a constant integer value. The third operand, mask, is a vector of boolean values with the same number of elements as the return type. The fourth is a pass-through value that is used to fill the masked-off lanes of the result. The return type, underlying type of the vector of pointers and the type of the '``passthru``' operand are the same vector types.
  10876. Semantics:
  10877. """"""""""
  10878. The '``llvm.masked.gather``' intrinsic is designed for conditional reading of multiple scalar values from arbitrary memory locations in a single IR operation. It is useful for targets that support vector masked gathers and allows vectorizing basic blocks with data and control divergence. Other targets may support this intrinsic differently, for example by lowering it into a sequence of scalar load operations.
  10879. The semantics of this operation are equivalent to a sequence of conditional scalar loads with subsequent gathering all loaded values into a single vector. The mask restricts memory access to certain lanes and facilitates vectorization of predicated basic blocks.
  10880. ::
  10881. %res = call <4 x double> @llvm.masked.gather.v4f64.v4p0f64 (<4 x double*> %ptrs, i32 8, <4 x i1> <i1 true, i1 true, i1 true, i1 true>, <4 x double> undef)
  10882. ;; The gather with all-true mask is equivalent to the following instruction sequence
  10883. %ptr0 = extractelement <4 x double*> %ptrs, i32 0
  10884. %ptr1 = extractelement <4 x double*> %ptrs, i32 1
  10885. %ptr2 = extractelement <4 x double*> %ptrs, i32 2
  10886. %ptr3 = extractelement <4 x double*> %ptrs, i32 3
  10887. %val0 = load double, double* %ptr0, align 8
  10888. %val1 = load double, double* %ptr1, align 8
  10889. %val2 = load double, double* %ptr2, align 8
  10890. %val3 = load double, double* %ptr3, align 8
  10891. %vec0 = insertelement <4 x double>undef, %val0, 0
  10892. %vec01 = insertelement <4 x double>%vec0, %val1, 1
  10893. %vec012 = insertelement <4 x double>%vec01, %val2, 2
  10894. %vec0123 = insertelement <4 x double>%vec012, %val3, 3
  10895. .. _int_mscatter:
  10896. '``llvm.masked.scatter.*``' Intrinsics
  10897. ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  10898. Syntax:
  10899. """""""
  10900. This is an overloaded intrinsic. The data stored in memory is a vector of any integer, floating-point or pointer data type. Each vector element is stored in an arbitrary memory address. Scatter with overlapping addresses is guaranteed to be ordered from least-significant to most-significant element.
  10901. ::
  10902. declare void @llvm.masked.scatter.v8i32.v8p0i32 (<8 x i32> <value>, <8 x i32*> <ptrs>, i32 <alignment>, <8 x i1> <mask>)
  10903. declare void @llvm.masked.scatter.v16f32.v16p1f32 (<16 x float> <value>, <16 x float addrspace(1)*> <ptrs>, i32 <alignment>, <16 x i1> <mask>)
  10904. declare void @llvm.masked.scatter.v4p0f64.v4p0p0f64 (<4 x double*> <value>, <4 x double**> <ptrs>, i32 <alignment>, <4 x i1> <mask>)
  10905. Overview:
  10906. """""""""
  10907. Writes each element from the value vector to the corresponding memory address. The memory addresses are represented as a vector of pointers. Writing is done according to the provided mask. The mask holds a bit for each vector lane, and is used to prevent memory accesses to the masked-off lanes.
  10908. Arguments:
  10909. """"""""""
  10910. The first operand is a vector value to be written to memory. The second operand is a vector of pointers, pointing to where the value elements should be stored. It has the same underlying type as the value operand. The third operand is an alignment of the destination addresses. The fourth operand, mask, is a vector of boolean values. The types of the mask and the value operand must have the same number of vector elements.
  10911. Semantics:
  10912. """"""""""
  10913. The '``llvm.masked.scatter``' intrinsics is designed for writing selected vector elements to arbitrary memory addresses in a single IR operation. The operation may be conditional, when not all bits in the mask are switched on. It is useful for targets that support vector masked scatter and allows vectorizing basic blocks with data and control divergence. Other targets may support this intrinsic differently, for example by lowering it into a sequence of branches that guard scalar store operations.
  10914. ::
  10915. ;; This instruction unconditionally stores data vector in multiple addresses
  10916. call @llvm.masked.scatter.v8i32.v8p0i32 (<8 x i32> %value, <8 x i32*> %ptrs, i32 4, <8 x i1> <true, true, .. true>)
  10917. ;; It is equivalent to a list of scalar stores
  10918. %val0 = extractelement <8 x i32> %value, i32 0
  10919. %val1 = extractelement <8 x i32> %value, i32 1
  10920. ..
  10921. %val7 = extractelement <8 x i32> %value, i32 7
  10922. %ptr0 = extractelement <8 x i32*> %ptrs, i32 0
  10923. %ptr1 = extractelement <8 x i32*> %ptrs, i32 1
  10924. ..
  10925. %ptr7 = extractelement <8 x i32*> %ptrs, i32 7
  10926. ;; Note: the order of the following stores is important when they overlap:
  10927. store i32 %val0, i32* %ptr0, align 4
  10928. store i32 %val1, i32* %ptr1, align 4
  10929. ..
  10930. store i32 %val7, i32* %ptr7, align 4
  10931. Masked Vector Expanding Load and Compressing Store Intrinsics
  10932. -------------------------------------------------------------
  10933. LLVM provides intrinsics for expanding load and compressing store operations. Data selected from a vector according to a mask is stored in consecutive memory addresses (compressed store), and vice-versa (expanding load). These operations effective map to "if (cond.i) a[j++] = v.i" and "if (cond.i) v.i = a[j++]" patterns, respectively. Note that when the mask starts with '1' bits followed by '0' bits, these operations are identical to :ref:`llvm.masked.store <int_mstore>` and :ref:`llvm.masked.load <int_mload>`.
  10934. .. _int_expandload:
  10935. '``llvm.masked.expandload.*``' Intrinsics
  10936. ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  10937. Syntax:
  10938. """""""
  10939. This is an overloaded intrinsic. Several values of integer, floating point or pointer data type are loaded from consecutive memory addresses and stored into the elements of a vector according to the mask.
  10940. ::
  10941. declare <16 x float> @llvm.masked.expandload.v16f32 (float* <ptr>, <16 x i1> <mask>, <16 x float> <passthru>)
  10942. declare <2 x i64> @llvm.masked.expandload.v2i64 (i64* <ptr>, <2 x i1> <mask>, <2 x i64> <passthru>)
  10943. Overview:
  10944. """""""""
  10945. Reads a number of scalar values sequentially from memory location provided in '``ptr``' and spreads them in a vector. The '``mask``' holds a bit for each vector lane. The number of elements read from memory is equal to the number of '1' bits in the mask. The loaded elements are positioned in the destination vector according to the sequence of '1' and '0' bits in the mask. E.g., if the mask vector is '10010001', "explandload" reads 3 values from memory addresses ptr, ptr+1, ptr+2 and places them in lanes 0, 3 and 7 accordingly. The masked-off lanes are filled by elements from the corresponding lanes of the '``passthru``' operand.
  10946. Arguments:
  10947. """"""""""
  10948. The first operand is the base pointer for the load. It has the same underlying type as the element of the returned vector. The second operand, mask, is a vector of boolean values with the same number of elements as the return type. The third is a pass-through value that is used to fill the masked-off lanes of the result. The return type and the type of the '``passthru``' operand have the same vector type.
  10949. Semantics:
  10950. """"""""""
  10951. The '``llvm.masked.expandload``' intrinsic is designed for reading multiple scalar values from adjacent memory addresses into possibly non-adjacent vector lanes. It is useful for targets that support vector expanding loads and allows vectorizing loop with cross-iteration dependency like in the following example:
  10952. .. code-block:: c
  10953. // In this loop we load from B and spread the elements into array A.
  10954. double *A, B; int *C;
  10955. for (int i = 0; i < size; ++i) {
  10956. if (C[i] != 0)
  10957. A[i] = B[j++];
  10958. }
  10959. .. code-block:: llvm
  10960. ; Load several elements from array B and expand them in a vector.
  10961. ; The number of loaded elements is equal to the number of '1' elements in the Mask.
  10962. %Tmp = call <8 x double> @llvm.masked.expandload.v8f64(double* %Bptr, <8 x i1> %Mask, <8 x double> undef)
  10963. ; Store the result in A
  10964. call void @llvm.masked.store.v8f64.p0v8f64(<8 x double> %Tmp, <8 x double>* %Aptr, i32 8, <8 x i1> %Mask)
  10965. ; %Bptr should be increased on each iteration according to the number of '1' elements in the Mask.
  10966. %MaskI = bitcast <8 x i1> %Mask to i8
  10967. %MaskIPopcnt = call i8 @llvm.ctpop.i8(i8 %MaskI)
  10968. %MaskI64 = zext i8 %MaskIPopcnt to i64
  10969. %BNextInd = add i64 %BInd, %MaskI64
  10970. Other targets may support this intrinsic differently, for example, by lowering it into a sequence of conditional scalar load operations and shuffles.
  10971. If all mask elements are '1', the intrinsic behavior is equivalent to the regular unmasked vector load.
  10972. .. _int_compressstore:
  10973. '``llvm.masked.compressstore.*``' Intrinsics
  10974. ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  10975. Syntax:
  10976. """""""
  10977. This is an overloaded intrinsic. A number of scalar values of integer, floating point or pointer data type are collected from an input vector and stored into adjacent memory addresses. A mask defines which elements to collect from the vector.
  10978. ::
  10979. declare void @llvm.masked.compressstore.v8i32 (<8 x i32> <value>, i32* <ptr>, <8 x i1> <mask>)
  10980. declare void @llvm.masked.compressstore.v16f32 (<16 x float> <value>, float* <ptr>, <16 x i1> <mask>)
  10981. Overview:
  10982. """""""""
  10983. Selects elements from input vector '``value``' according to the '``mask``'. All selected elements are written into adjacent memory addresses starting at address '`ptr`', from lower to higher. The mask holds a bit for each vector lane, and is used to select elements to be stored. The number of elements to be stored is equal to the number of active bits in the mask.
  10984. Arguments:
  10985. """"""""""
  10986. The first operand is the input vector, from which elements are collected and written to memory. The second operand is the base pointer for the store, it has the same underlying type as the element of the input vector operand. The third operand is the mask, a vector of boolean values. The mask and the input vector must have the same number of vector elements.
  10987. Semantics:
  10988. """"""""""
  10989. The '``llvm.masked.compressstore``' intrinsic is designed for compressing data in memory. It allows to collect elements from possibly non-adjacent lanes of a vector and store them contiguously in memory in one IR operation. It is useful for targets that support compressing store operations and allows vectorizing loops with cross-iteration dependences like in the following example:
  10990. .. code-block:: c
  10991. // In this loop we load elements from A and store them consecutively in B
  10992. double *A, B; int *C;
  10993. for (int i = 0; i < size; ++i) {
  10994. if (C[i] != 0)
  10995. B[j++] = A[i]
  10996. }
  10997. .. code-block:: llvm
  10998. ; Load elements from A.
  10999. %Tmp = call <8 x double> @llvm.masked.load.v8f64.p0v8f64(<8 x double>* %Aptr, i32 8, <8 x i1> %Mask, <8 x double> undef)
  11000. ; Store all selected elements consecutively in array B
  11001. call <void> @llvm.masked.compressstore.v8f64(<8 x double> %Tmp, double* %Bptr, <8 x i1> %Mask)
  11002. ; %Bptr should be increased on each iteration according to the number of '1' elements in the Mask.
  11003. %MaskI = bitcast <8 x i1> %Mask to i8
  11004. %MaskIPopcnt = call i8 @llvm.ctpop.i8(i8 %MaskI)
  11005. %MaskI64 = zext i8 %MaskIPopcnt to i64
  11006. %BNextInd = add i64 %BInd, %MaskI64
  11007. Other targets may support this intrinsic differently, for example, by lowering it into a sequence of branches that guard scalar store operations.
  11008. Memory Use Markers
  11009. ------------------
  11010. This class of intrinsics provides information about the lifetime of
  11011. memory objects and ranges where variables are immutable.
  11012. .. _int_lifestart:
  11013. '``llvm.lifetime.start``' Intrinsic
  11014. ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  11015. Syntax:
  11016. """""""
  11017. ::
  11018. declare void @llvm.lifetime.start(i64 <size>, i8* nocapture <ptr>)
  11019. Overview:
  11020. """""""""
  11021. The '``llvm.lifetime.start``' intrinsic specifies the start of a memory
  11022. object's lifetime.
  11023. Arguments:
  11024. """"""""""
  11025. The first argument is a constant integer representing the size of the
  11026. object, or -1 if it is variable sized. The second argument is a pointer
  11027. to the object.
  11028. Semantics:
  11029. """"""""""
  11030. This intrinsic indicates that before this point in the code, the value
  11031. of the memory pointed to by ``ptr`` is dead. This means that it is known
  11032. to never be used and has an undefined value. A load from the pointer
  11033. that precedes this intrinsic can be replaced with ``'undef'``.
  11034. .. _int_lifeend:
  11035. '``llvm.lifetime.end``' Intrinsic
  11036. ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  11037. Syntax:
  11038. """""""
  11039. ::
  11040. declare void @llvm.lifetime.end(i64 <size>, i8* nocapture <ptr>)
  11041. Overview:
  11042. """""""""
  11043. The '``llvm.lifetime.end``' intrinsic specifies the end of a memory
  11044. object's lifetime.
  11045. Arguments:
  11046. """"""""""
  11047. The first argument is a constant integer representing the size of the
  11048. object, or -1 if it is variable sized. The second argument is a pointer
  11049. to the object.
  11050. Semantics:
  11051. """"""""""
  11052. This intrinsic indicates that after this point in the code, the value of
  11053. the memory pointed to by ``ptr`` is dead. This means that it is known to
  11054. never be used and has an undefined value. Any stores into the memory
  11055. object following this intrinsic may be removed as dead.
  11056. '``llvm.invariant.start``' Intrinsic
  11057. ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  11058. Syntax:
  11059. """""""
  11060. This is an overloaded intrinsic. The memory object can belong to any address space.
  11061. ::
  11062. declare {}* @llvm.invariant.start.p0i8(i64 <size>, i8* nocapture <ptr>)
  11063. Overview:
  11064. """""""""
  11065. The '``llvm.invariant.start``' intrinsic specifies that the contents of
  11066. a memory object will not change.
  11067. Arguments:
  11068. """"""""""
  11069. The first argument is a constant integer representing the size of the
  11070. object, or -1 if it is variable sized. The second argument is a pointer
  11071. to the object.
  11072. Semantics:
  11073. """"""""""
  11074. This intrinsic indicates that until an ``llvm.invariant.end`` that uses
  11075. the return value, the referenced memory location is constant and
  11076. unchanging.
  11077. '``llvm.invariant.end``' Intrinsic
  11078. ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  11079. Syntax:
  11080. """""""
  11081. This is an overloaded intrinsic. The memory object can belong to any address space.
  11082. ::
  11083. declare void @llvm.invariant.end.p0i8({}* <start>, i64 <size>, i8* nocapture <ptr>)
  11084. Overview:
  11085. """""""""
  11086. The '``llvm.invariant.end``' intrinsic specifies that the contents of a
  11087. memory object are mutable.
  11088. Arguments:
  11089. """"""""""
  11090. The first argument is the matching ``llvm.invariant.start`` intrinsic.
  11091. The second argument is a constant integer representing the size of the
  11092. object, or -1 if it is variable sized and the third argument is a
  11093. pointer to the object.
  11094. Semantics:
  11095. """"""""""
  11096. This intrinsic indicates that the memory is mutable again.
  11097. '``llvm.launder.invariant.group``' Intrinsic
  11098. ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  11099. Syntax:
  11100. """""""
  11101. This is an overloaded intrinsic. The memory object can belong to any address
  11102. space. The returned pointer must belong to the same address space as the
  11103. argument.
  11104. ::
  11105. declare i8* @llvm.launder.invariant.group.p0i8(i8* <ptr>)
  11106. Overview:
  11107. """""""""
  11108. The '``llvm.launder.invariant.group``' intrinsic can be used when an invariant
  11109. established by ``invariant.group`` metadata no longer holds, to obtain a new
  11110. pointer value that carries fresh invariant group information. It is an
  11111. experimental intrinsic, which means that its semantics might change in the
  11112. future.
  11113. Arguments:
  11114. """"""""""
  11115. The ``llvm.launder.invariant.group`` takes only one argument, which is a pointer
  11116. to the memory.
  11117. Semantics:
  11118. """"""""""
  11119. Returns another pointer that aliases its argument but which is considered different
  11120. for the purposes of ``load``/``store`` ``invariant.group`` metadata.
  11121. It does not read any accessible memory and the execution can be speculated.
  11122. '``llvm.strip.invariant.group``' Intrinsic
  11123. ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  11124. Syntax:
  11125. """""""
  11126. This is an overloaded intrinsic. The memory object can belong to any address
  11127. space. The returned pointer must belong to the same address space as the
  11128. argument.
  11129. ::
  11130. declare i8* @llvm.strip.invariant.group.p0i8(i8* <ptr>)
  11131. Overview:
  11132. """""""""
  11133. The '``llvm.strip.invariant.group``' intrinsic can be used when an invariant
  11134. established by ``invariant.group`` metadata no longer holds, to obtain a new pointer
  11135. value that does not carry the invariant information. It is an experimental
  11136. intrinsic, which means that its semantics might change in the future.
  11137. Arguments:
  11138. """"""""""
  11139. The ``llvm.strip.invariant.group`` takes only one argument, which is a pointer
  11140. to the memory.
  11141. Semantics:
  11142. """"""""""
  11143. Returns another pointer that aliases its argument but which has no associated
  11144. ``invariant.group`` metadata.
  11145. It does not read any memory and can be speculated.
  11146. .. _constrainedfp:
  11147. Constrained Floating-Point Intrinsics
  11148. -------------------------------------
  11149. These intrinsics are used to provide special handling of floating-point
  11150. operations when specific rounding mode or floating-point exception behavior is
  11151. required. By default, LLVM optimization passes assume that the rounding mode is
  11152. round-to-nearest and that floating-point exceptions will not be monitored.
  11153. Constrained FP intrinsics are used to support non-default rounding modes and
  11154. accurately preserve exception behavior without compromising LLVM's ability to
  11155. optimize FP code when the default behavior is used.
  11156. If any FP operation in a function is constrained then they all must be
  11157. constrained. This is required for correct LLVM IR. Optimizations that
  11158. move code around can create miscompiles if mixing of constrained and normal
  11159. operations is done. The correct way to mix constrained and less constrained
  11160. operations is to use the rounding mode and exception handling metadata to
  11161. mark constrained intrinsics as having LLVM's default behavior.
  11162. Each of these intrinsics corresponds to a normal floating-point operation. The
  11163. data arguments and the return value are the same as the corresponding FP
  11164. operation.
  11165. The rounding mode argument is a metadata string specifying what
  11166. assumptions, if any, the optimizer can make when transforming constant
  11167. values. Some constrained FP intrinsics omit this argument. If required
  11168. by the intrinsic, this argument must be one of the following strings:
  11169. ::
  11170. "round.dynamic"
  11171. "round.tonearest"
  11172. "round.downward"
  11173. "round.upward"
  11174. "round.towardzero"
  11175. If this argument is "round.dynamic" optimization passes must assume that the
  11176. rounding mode is unknown and may change at runtime. No transformations that
  11177. depend on rounding mode may be performed in this case.
  11178. The other possible values for the rounding mode argument correspond to the
  11179. similarly named IEEE rounding modes. If the argument is any of these values
  11180. optimization passes may perform transformations as long as they are consistent
  11181. with the specified rounding mode.
  11182. For example, 'x-0'->'x' is not a valid transformation if the rounding mode is
  11183. "round.downward" or "round.dynamic" because if the value of 'x' is +0 then
  11184. 'x-0' should evaluate to '-0' when rounding downward. However, this
  11185. transformation is legal for all other rounding modes.
  11186. For values other than "round.dynamic" optimization passes may assume that the
  11187. actual runtime rounding mode (as defined in a target-specific manner) matches
  11188. the specified rounding mode, but this is not guaranteed. Using a specific
  11189. non-dynamic rounding mode which does not match the actual rounding mode at
  11190. runtime results in undefined behavior.
  11191. The exception behavior argument is a metadata string describing the floating
  11192. point exception semantics that required for the intrinsic. This argument
  11193. must be one of the following strings:
  11194. ::
  11195. "fpexcept.ignore"
  11196. "fpexcept.maytrap"
  11197. "fpexcept.strict"
  11198. If this argument is "fpexcept.ignore" optimization passes may assume that the
  11199. exception status flags will not be read and that floating-point exceptions will
  11200. be masked. This allows transformations to be performed that may change the
  11201. exception semantics of the original code. For example, FP operations may be
  11202. speculatively executed in this case whereas they must not be for either of the
  11203. other possible values of this argument.
  11204. If the exception behavior argument is "fpexcept.maytrap" optimization passes
  11205. must avoid transformations that may raise exceptions that would not have been
  11206. raised by the original code (such as speculatively executing FP operations), but
  11207. passes are not required to preserve all exceptions that are implied by the
  11208. original code. For example, exceptions may be potentially hidden by constant
  11209. folding.
  11210. If the exception behavior argument is "fpexcept.strict" all transformations must
  11211. strictly preserve the floating-point exception semantics of the original code.
  11212. Any FP exception that would have been raised by the original code must be raised
  11213. by the transformed code, and the transformed code must not raise any FP
  11214. exceptions that would not have been raised by the original code. This is the
  11215. exception behavior argument that will be used if the code being compiled reads
  11216. the FP exception status flags, but this mode can also be used with code that
  11217. unmasks FP exceptions.
  11218. The number and order of floating-point exceptions is NOT guaranteed. For
  11219. example, a series of FP operations that each may raise exceptions may be
  11220. vectorized into a single instruction that raises each unique exception a single
  11221. time.
  11222. '``llvm.experimental.constrained.fadd``' Intrinsic
  11223. ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  11224. Syntax:
  11225. """""""
  11226. ::
  11227. declare <type>
  11228. @llvm.experimental.constrained.fadd(<type> <op1>, <type> <op2>,
  11229. metadata <rounding mode>,
  11230. metadata <exception behavior>)
  11231. Overview:
  11232. """""""""
  11233. The '``llvm.experimental.constrained.fadd``' intrinsic returns the sum of its
  11234. two operands.
  11235. Arguments:
  11236. """"""""""
  11237. The first two arguments to the '``llvm.experimental.constrained.fadd``'
  11238. intrinsic must be :ref:`floating-point <t_floating>` or :ref:`vector <t_vector>`
  11239. of floating-point values. Both arguments must have identical types.
  11240. The third and fourth arguments specify the rounding mode and exception
  11241. behavior as described above.
  11242. Semantics:
  11243. """"""""""
  11244. The value produced is the floating-point sum of the two value operands and has
  11245. the same type as the operands.
  11246. '``llvm.experimental.constrained.fsub``' Intrinsic
  11247. ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  11248. Syntax:
  11249. """""""
  11250. ::
  11251. declare <type>
  11252. @llvm.experimental.constrained.fsub(<type> <op1>, <type> <op2>,
  11253. metadata <rounding mode>,
  11254. metadata <exception behavior>)
  11255. Overview:
  11256. """""""""
  11257. The '``llvm.experimental.constrained.fsub``' intrinsic returns the difference
  11258. of its two operands.
  11259. Arguments:
  11260. """"""""""
  11261. The first two arguments to the '``llvm.experimental.constrained.fsub``'
  11262. intrinsic must be :ref:`floating-point <t_floating>` or :ref:`vector <t_vector>`
  11263. of floating-point values. Both arguments must have identical types.
  11264. The third and fourth arguments specify the rounding mode and exception
  11265. behavior as described above.
  11266. Semantics:
  11267. """"""""""
  11268. The value produced is the floating-point difference of the two value operands
  11269. and has the same type as the operands.
  11270. '``llvm.experimental.constrained.fmul``' Intrinsic
  11271. ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  11272. Syntax:
  11273. """""""
  11274. ::
  11275. declare <type>
  11276. @llvm.experimental.constrained.fmul(<type> <op1>, <type> <op2>,
  11277. metadata <rounding mode>,
  11278. metadata <exception behavior>)
  11279. Overview:
  11280. """""""""
  11281. The '``llvm.experimental.constrained.fmul``' intrinsic returns the product of
  11282. its two operands.
  11283. Arguments:
  11284. """"""""""
  11285. The first two arguments to the '``llvm.experimental.constrained.fmul``'
  11286. intrinsic must be :ref:`floating-point <t_floating>` or :ref:`vector <t_vector>`
  11287. of floating-point values. Both arguments must have identical types.
  11288. The third and fourth arguments specify the rounding mode and exception
  11289. behavior as described above.
  11290. Semantics:
  11291. """"""""""
  11292. The value produced is the floating-point product of the two value operands and
  11293. has the same type as the operands.
  11294. '``llvm.experimental.constrained.fdiv``' Intrinsic
  11295. ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  11296. Syntax:
  11297. """""""
  11298. ::
  11299. declare <type>
  11300. @llvm.experimental.constrained.fdiv(<type> <op1>, <type> <op2>,
  11301. metadata <rounding mode>,
  11302. metadata <exception behavior>)
  11303. Overview:
  11304. """""""""
  11305. The '``llvm.experimental.constrained.fdiv``' intrinsic returns the quotient of
  11306. its two operands.
  11307. Arguments:
  11308. """"""""""
  11309. The first two arguments to the '``llvm.experimental.constrained.fdiv``'
  11310. intrinsic must be :ref:`floating-point <t_floating>` or :ref:`vector <t_vector>`
  11311. of floating-point values. Both arguments must have identical types.
  11312. The third and fourth arguments specify the rounding mode and exception
  11313. behavior as described above.
  11314. Semantics:
  11315. """"""""""
  11316. The value produced is the floating-point quotient of the two value operands and
  11317. has the same type as the operands.
  11318. '``llvm.experimental.constrained.frem``' Intrinsic
  11319. ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  11320. Syntax:
  11321. """""""
  11322. ::
  11323. declare <type>
  11324. @llvm.experimental.constrained.frem(<type> <op1>, <type> <op2>,
  11325. metadata <rounding mode>,
  11326. metadata <exception behavior>)
  11327. Overview:
  11328. """""""""
  11329. The '``llvm.experimental.constrained.frem``' intrinsic returns the remainder
  11330. from the division of its two operands.
  11331. Arguments:
  11332. """"""""""
  11333. The first two arguments to the '``llvm.experimental.constrained.frem``'
  11334. intrinsic must be :ref:`floating-point <t_floating>` or :ref:`vector <t_vector>`
  11335. of floating-point values. Both arguments must have identical types.
  11336. The third and fourth arguments specify the rounding mode and exception
  11337. behavior as described above. The rounding mode argument has no effect, since
  11338. the result of frem is never rounded, but the argument is included for
  11339. consistency with the other constrained floating-point intrinsics.
  11340. Semantics:
  11341. """"""""""
  11342. The value produced is the floating-point remainder from the division of the two
  11343. value operands and has the same type as the operands. The remainder has the
  11344. same sign as the dividend.
  11345. '``llvm.experimental.constrained.fma``' Intrinsic
  11346. ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  11347. Syntax:
  11348. """""""
  11349. ::
  11350. declare <type>
  11351. @llvm.experimental.constrained.fma(<type> <op1>, <type> <op2>, <type> <op3>,
  11352. metadata <rounding mode>,
  11353. metadata <exception behavior>)
  11354. Overview:
  11355. """""""""
  11356. The '``llvm.experimental.constrained.fma``' intrinsic returns the result of a
  11357. fused-multiply-add operation on its operands.
  11358. Arguments:
  11359. """"""""""
  11360. The first three arguments to the '``llvm.experimental.constrained.fma``'
  11361. intrinsic must be :ref:`floating-point <t_floating>` or :ref:`vector
  11362. <t_vector>` of floating-point values. All arguments must have identical types.
  11363. The fourth and fifth arguments specify the rounding mode and exception behavior
  11364. as described above.
  11365. Semantics:
  11366. """"""""""
  11367. The result produced is the product of the first two operands added to the third
  11368. operand computed with infinite precision, and then rounded to the target
  11369. precision.
  11370. '``llvm.experimental.constrained.fptoui``' Intrinsic
  11371. ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  11372. Syntax:
  11373. """""""
  11374. ::
  11375. declare <ty2>
  11376. @llvm.experimental.constrained.fptoui(<type> <value>,
  11377. metadata <exception behavior>)
  11378. Overview:
  11379. """""""""
  11380. The '``llvm.experimental.constrained.fptoui``' intrinsic converts a
  11381. floating-point ``value`` to its unsigned integer equivalent of type ``ty2``.
  11382. Arguments:
  11383. """"""""""
  11384. The first argument to the '``llvm.experimental.constrained.fptoui``'
  11385. intrinsic must be :ref:`floating point <t_floating>` or :ref:`vector
  11386. <t_vector>` of floating point values.
  11387. The second argument specifies the exception behavior as described above.
  11388. Semantics:
  11389. """"""""""
  11390. The result produced is an unsigned integer converted from the floating
  11391. point operand. The value is truncated, so it is rounded towards zero.
  11392. '``llvm.experimental.constrained.fptosi``' Intrinsic
  11393. ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  11394. Syntax:
  11395. """""""
  11396. ::
  11397. declare <ty2>
  11398. @llvm.experimental.constrained.fptosi(<type> <value>,
  11399. metadata <exception behavior>)
  11400. Overview:
  11401. """""""""
  11402. The '``llvm.experimental.constrained.fptosi``' intrinsic converts
  11403. :ref:`floating-point <t_floating>` ``value`` to type ``ty2``.
  11404. Arguments:
  11405. """"""""""
  11406. The first argument to the '``llvm.experimental.constrained.fptosi``'
  11407. intrinsic must be :ref:`floating point <t_floating>` or :ref:`vector
  11408. <t_vector>` of floating point values.
  11409. The second argument specifies the exception behavior as described above.
  11410. Semantics:
  11411. """"""""""
  11412. The result produced is a signed integer converted from the floating
  11413. point operand. The value is truncated, so it is rounded towards zero.
  11414. '``llvm.experimental.constrained.fptrunc``' Intrinsic
  11415. ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  11416. Syntax:
  11417. """""""
  11418. ::
  11419. declare <ty2>
  11420. @llvm.experimental.constrained.fptrunc(<type> <value>,
  11421. metadata <rounding mode>,
  11422. metadata <exception behavior>)
  11423. Overview:
  11424. """""""""
  11425. The '``llvm.experimental.constrained.fptrunc``' intrinsic truncates ``value``
  11426. to type ``ty2``.
  11427. Arguments:
  11428. """"""""""
  11429. The first argument to the '``llvm.experimental.constrained.fptrunc``'
  11430. intrinsic must be :ref:`floating point <t_floating>` or :ref:`vector
  11431. <t_vector>` of floating point values. This argument must be larger in size
  11432. than the result.
  11433. The second and third arguments specify the rounding mode and exception
  11434. behavior as described above.
  11435. Semantics:
  11436. """"""""""
  11437. The result produced is a floating point value truncated to be smaller in size
  11438. than the operand.
  11439. '``llvm.experimental.constrained.fpext``' Intrinsic
  11440. ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  11441. Syntax:
  11442. """""""
  11443. ::
  11444. declare <ty2>
  11445. @llvm.experimental.constrained.fpext(<type> <value>,
  11446. metadata <exception behavior>)
  11447. Overview:
  11448. """""""""
  11449. The '``llvm.experimental.constrained.fpext``' intrinsic extends a
  11450. floating-point ``value`` to a larger floating-point value.
  11451. Arguments:
  11452. """"""""""
  11453. The first argument to the '``llvm.experimental.constrained.fpext``'
  11454. intrinsic must be :ref:`floating point <t_floating>` or :ref:`vector
  11455. <t_vector>` of floating point values. This argument must be smaller in size
  11456. than the result.
  11457. The second argument specifies the exception behavior as described above.
  11458. Semantics:
  11459. """"""""""
  11460. The result produced is a floating point value extended to be larger in size
  11461. than the operand. All restrictions that apply to the fpext instruction also
  11462. apply to this intrinsic.
  11463. Constrained libm-equivalent Intrinsics
  11464. --------------------------------------
  11465. In addition to the basic floating-point operations for which constrained
  11466. intrinsics are described above, there are constrained versions of various
  11467. operations which provide equivalent behavior to a corresponding libm function.
  11468. These intrinsics allow the precise behavior of these operations with respect to
  11469. rounding mode and exception behavior to be controlled.
  11470. As with the basic constrained floating-point intrinsics, the rounding mode
  11471. and exception behavior arguments only control the behavior of the optimizer.
  11472. They do not change the runtime floating-point environment.
  11473. '``llvm.experimental.constrained.sqrt``' Intrinsic
  11474. ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  11475. Syntax:
  11476. """""""
  11477. ::
  11478. declare <type>
  11479. @llvm.experimental.constrained.sqrt(<type> <op1>,
  11480. metadata <rounding mode>,
  11481. metadata <exception behavior>)
  11482. Overview:
  11483. """""""""
  11484. The '``llvm.experimental.constrained.sqrt``' intrinsic returns the square root
  11485. of the specified value, returning the same value as the libm '``sqrt``'
  11486. functions would, but without setting ``errno``.
  11487. Arguments:
  11488. """"""""""
  11489. The first argument and the return type are floating-point numbers of the same
  11490. type.
  11491. The second and third arguments specify the rounding mode and exception
  11492. behavior as described above.
  11493. Semantics:
  11494. """"""""""
  11495. This function returns the nonnegative square root of the specified value.
  11496. If the value is less than negative zero, a floating-point exception occurs
  11497. and the return value is architecture specific.
  11498. '``llvm.experimental.constrained.pow``' Intrinsic
  11499. ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  11500. Syntax:
  11501. """""""
  11502. ::
  11503. declare <type>
  11504. @llvm.experimental.constrained.pow(<type> <op1>, <type> <op2>,
  11505. metadata <rounding mode>,
  11506. metadata <exception behavior>)
  11507. Overview:
  11508. """""""""
  11509. The '``llvm.experimental.constrained.pow``' intrinsic returns the first operand
  11510. raised to the (positive or negative) power specified by the second operand.
  11511. Arguments:
  11512. """"""""""
  11513. The first two arguments and the return value are floating-point numbers of the
  11514. same type. The second argument specifies the power to which the first argument
  11515. should be raised.
  11516. The third and fourth arguments specify the rounding mode and exception
  11517. behavior as described above.
  11518. Semantics:
  11519. """"""""""
  11520. This function returns the first value raised to the second power,
  11521. returning the same values as the libm ``pow`` functions would, and
  11522. handles error conditions in the same way.
  11523. '``llvm.experimental.constrained.powi``' Intrinsic
  11524. ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  11525. Syntax:
  11526. """""""
  11527. ::
  11528. declare <type>
  11529. @llvm.experimental.constrained.powi(<type> <op1>, i32 <op2>,
  11530. metadata <rounding mode>,
  11531. metadata <exception behavior>)
  11532. Overview:
  11533. """""""""
  11534. The '``llvm.experimental.constrained.powi``' intrinsic returns the first operand
  11535. raised to the (positive or negative) power specified by the second operand. The
  11536. order of evaluation of multiplications is not defined. When a vector of
  11537. floating-point type is used, the second argument remains a scalar integer value.
  11538. Arguments:
  11539. """"""""""
  11540. The first argument and the return value are floating-point numbers of the same
  11541. type. The second argument is a 32-bit signed integer specifying the power to
  11542. which the first argument should be raised.
  11543. The third and fourth arguments specify the rounding mode and exception
  11544. behavior as described above.
  11545. Semantics:
  11546. """"""""""
  11547. This function returns the first value raised to the second power with an
  11548. unspecified sequence of rounding operations.
  11549. '``llvm.experimental.constrained.sin``' Intrinsic
  11550. ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  11551. Syntax:
  11552. """""""
  11553. ::
  11554. declare <type>
  11555. @llvm.experimental.constrained.sin(<type> <op1>,
  11556. metadata <rounding mode>,
  11557. metadata <exception behavior>)
  11558. Overview:
  11559. """""""""
  11560. The '``llvm.experimental.constrained.sin``' intrinsic returns the sine of the
  11561. first operand.
  11562. Arguments:
  11563. """"""""""
  11564. The first argument and the return type are floating-point numbers of the same
  11565. type.
  11566. The second and third arguments specify the rounding mode and exception
  11567. behavior as described above.
  11568. Semantics:
  11569. """"""""""
  11570. This function returns the sine of the specified operand, returning the
  11571. same values as the libm ``sin`` functions would, and handles error
  11572. conditions in the same way.
  11573. '``llvm.experimental.constrained.cos``' Intrinsic
  11574. ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  11575. Syntax:
  11576. """""""
  11577. ::
  11578. declare <type>
  11579. @llvm.experimental.constrained.cos(<type> <op1>,
  11580. metadata <rounding mode>,
  11581. metadata <exception behavior>)
  11582. Overview:
  11583. """""""""
  11584. The '``llvm.experimental.constrained.cos``' intrinsic returns the cosine of the
  11585. first operand.
  11586. Arguments:
  11587. """"""""""
  11588. The first argument and the return type are floating-point numbers of the same
  11589. type.
  11590. The second and third arguments specify the rounding mode and exception
  11591. behavior as described above.
  11592. Semantics:
  11593. """"""""""
  11594. This function returns the cosine of the specified operand, returning the
  11595. same values as the libm ``cos`` functions would, and handles error
  11596. conditions in the same way.
  11597. '``llvm.experimental.constrained.exp``' Intrinsic
  11598. ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  11599. Syntax:
  11600. """""""
  11601. ::
  11602. declare <type>
  11603. @llvm.experimental.constrained.exp(<type> <op1>,
  11604. metadata <rounding mode>,
  11605. metadata <exception behavior>)
  11606. Overview:
  11607. """""""""
  11608. The '``llvm.experimental.constrained.exp``' intrinsic computes the base-e
  11609. exponential of the specified value.
  11610. Arguments:
  11611. """"""""""
  11612. The first argument and the return value are floating-point numbers of the same
  11613. type.
  11614. The second and third arguments specify the rounding mode and exception
  11615. behavior as described above.
  11616. Semantics:
  11617. """"""""""
  11618. This function returns the same values as the libm ``exp`` functions
  11619. would, and handles error conditions in the same way.
  11620. '``llvm.experimental.constrained.exp2``' Intrinsic
  11621. ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  11622. Syntax:
  11623. """""""
  11624. ::
  11625. declare <type>
  11626. @llvm.experimental.constrained.exp2(<type> <op1>,
  11627. metadata <rounding mode>,
  11628. metadata <exception behavior>)
  11629. Overview:
  11630. """""""""
  11631. The '``llvm.experimental.constrained.exp2``' intrinsic computes the base-2
  11632. exponential of the specified value.
  11633. Arguments:
  11634. """"""""""
  11635. The first argument and the return value are floating-point numbers of the same
  11636. type.
  11637. The second and third arguments specify the rounding mode and exception
  11638. behavior as described above.
  11639. Semantics:
  11640. """"""""""
  11641. This function returns the same values as the libm ``exp2`` functions
  11642. would, and handles error conditions in the same way.
  11643. '``llvm.experimental.constrained.log``' Intrinsic
  11644. ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  11645. Syntax:
  11646. """""""
  11647. ::
  11648. declare <type>
  11649. @llvm.experimental.constrained.log(<type> <op1>,
  11650. metadata <rounding mode>,
  11651. metadata <exception behavior>)
  11652. Overview:
  11653. """""""""
  11654. The '``llvm.experimental.constrained.log``' intrinsic computes the base-e
  11655. logarithm of the specified value.
  11656. Arguments:
  11657. """"""""""
  11658. The first argument and the return value are floating-point numbers of the same
  11659. type.
  11660. The second and third arguments specify the rounding mode and exception
  11661. behavior as described above.
  11662. Semantics:
  11663. """"""""""
  11664. This function returns the same values as the libm ``log`` functions
  11665. would, and handles error conditions in the same way.
  11666. '``llvm.experimental.constrained.log10``' Intrinsic
  11667. ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  11668. Syntax:
  11669. """""""
  11670. ::
  11671. declare <type>
  11672. @llvm.experimental.constrained.log10(<type> <op1>,
  11673. metadata <rounding mode>,
  11674. metadata <exception behavior>)
  11675. Overview:
  11676. """""""""
  11677. The '``llvm.experimental.constrained.log10``' intrinsic computes the base-10
  11678. logarithm of the specified value.
  11679. Arguments:
  11680. """"""""""
  11681. The first argument and the return value are floating-point numbers of the same
  11682. type.
  11683. The second and third arguments specify the rounding mode and exception
  11684. behavior as described above.
  11685. Semantics:
  11686. """"""""""
  11687. This function returns the same values as the libm ``log10`` functions
  11688. would, and handles error conditions in the same way.
  11689. '``llvm.experimental.constrained.log2``' Intrinsic
  11690. ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  11691. Syntax:
  11692. """""""
  11693. ::
  11694. declare <type>
  11695. @llvm.experimental.constrained.log2(<type> <op1>,
  11696. metadata <rounding mode>,
  11697. metadata <exception behavior>)
  11698. Overview:
  11699. """""""""
  11700. The '``llvm.experimental.constrained.log2``' intrinsic computes the base-2
  11701. logarithm of the specified value.
  11702. Arguments:
  11703. """"""""""
  11704. The first argument and the return value are floating-point numbers of the same
  11705. type.
  11706. The second and third arguments specify the rounding mode and exception
  11707. behavior as described above.
  11708. Semantics:
  11709. """"""""""
  11710. This function returns the same values as the libm ``log2`` functions
  11711. would, and handles error conditions in the same way.
  11712. '``llvm.experimental.constrained.rint``' Intrinsic
  11713. ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  11714. Syntax:
  11715. """""""
  11716. ::
  11717. declare <type>
  11718. @llvm.experimental.constrained.rint(<type> <op1>,
  11719. metadata <rounding mode>,
  11720. metadata <exception behavior>)
  11721. Overview:
  11722. """""""""
  11723. The '``llvm.experimental.constrained.rint``' intrinsic returns the first
  11724. operand rounded to the nearest integer. It may raise an inexact floating-point
  11725. exception if the operand is not an integer.
  11726. Arguments:
  11727. """"""""""
  11728. The first argument and the return value are floating-point numbers of the same
  11729. type.
  11730. The second and third arguments specify the rounding mode and exception
  11731. behavior as described above.
  11732. Semantics:
  11733. """"""""""
  11734. This function returns the same values as the libm ``rint`` functions
  11735. would, and handles error conditions in the same way. The rounding mode is
  11736. described, not determined, by the rounding mode argument. The actual rounding
  11737. mode is determined by the runtime floating-point environment. The rounding
  11738. mode argument is only intended as information to the compiler.
  11739. '``llvm.experimental.constrained.nearbyint``' Intrinsic
  11740. ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  11741. Syntax:
  11742. """""""
  11743. ::
  11744. declare <type>
  11745. @llvm.experimental.constrained.nearbyint(<type> <op1>,
  11746. metadata <rounding mode>,
  11747. metadata <exception behavior>)
  11748. Overview:
  11749. """""""""
  11750. The '``llvm.experimental.constrained.nearbyint``' intrinsic returns the first
  11751. operand rounded to the nearest integer. It will not raise an inexact
  11752. floating-point exception if the operand is not an integer.
  11753. Arguments:
  11754. """"""""""
  11755. The first argument and the return value are floating-point numbers of the same
  11756. type.
  11757. The second and third arguments specify the rounding mode and exception
  11758. behavior as described above.
  11759. Semantics:
  11760. """"""""""
  11761. This function returns the same values as the libm ``nearbyint`` functions
  11762. would, and handles error conditions in the same way. The rounding mode is
  11763. described, not determined, by the rounding mode argument. The actual rounding
  11764. mode is determined by the runtime floating-point environment. The rounding
  11765. mode argument is only intended as information to the compiler.
  11766. '``llvm.experimental.constrained.maxnum``' Intrinsic
  11767. ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  11768. Syntax:
  11769. """""""
  11770. ::
  11771. declare <type>
  11772. @llvm.experimental.constrained.maxnum(<type> <op1>, <type> <op2>
  11773. metadata <rounding mode>,
  11774. metadata <exception behavior>)
  11775. Overview:
  11776. """""""""
  11777. The '``llvm.experimental.constrained.maxnum``' intrinsic returns the maximum
  11778. of the two arguments.
  11779. Arguments:
  11780. """"""""""
  11781. The first two arguments and the return value are floating-point numbers
  11782. of the same type.
  11783. The third and forth arguments specify the rounding mode and exception
  11784. behavior as described above.
  11785. Semantics:
  11786. """"""""""
  11787. This function follows the IEEE-754 semantics for maxNum. The rounding mode is
  11788. described, not determined, by the rounding mode argument. The actual rounding
  11789. mode is determined by the runtime floating-point environment. The rounding
  11790. mode argument is only intended as information to the compiler.
  11791. '``llvm.experimental.constrained.minnum``' Intrinsic
  11792. ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  11793. Syntax:
  11794. """""""
  11795. ::
  11796. declare <type>
  11797. @llvm.experimental.constrained.minnum(<type> <op1>, <type> <op2>
  11798. metadata <rounding mode>,
  11799. metadata <exception behavior>)
  11800. Overview:
  11801. """""""""
  11802. The '``llvm.experimental.constrained.minnum``' intrinsic returns the minimum
  11803. of the two arguments.
  11804. Arguments:
  11805. """"""""""
  11806. The first two arguments and the return value are floating-point numbers
  11807. of the same type.
  11808. The third and forth arguments specify the rounding mode and exception
  11809. behavior as described above.
  11810. Semantics:
  11811. """"""""""
  11812. This function follows the IEEE-754 semantics for minNum. The rounding mode is
  11813. described, not determined, by the rounding mode argument. The actual rounding
  11814. mode is determined by the runtime floating-point environment. The rounding
  11815. mode argument is only intended as information to the compiler.
  11816. '``llvm.experimental.constrained.ceil``' Intrinsic
  11817. ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  11818. Syntax:
  11819. """""""
  11820. ::
  11821. declare <type>
  11822. @llvm.experimental.constrained.ceil(<type> <op1>,
  11823. metadata <rounding mode>,
  11824. metadata <exception behavior>)
  11825. Overview:
  11826. """""""""
  11827. The '``llvm.experimental.constrained.ceil``' intrinsic returns the ceiling of the
  11828. first operand.
  11829. Arguments:
  11830. """"""""""
  11831. The first argument and the return value are floating-point numbers of the same
  11832. type.
  11833. The second and third arguments specify the rounding mode and exception
  11834. behavior as described above. The rounding mode is currently unused for this
  11835. intrinsic.
  11836. Semantics:
  11837. """"""""""
  11838. This function returns the same values as the libm ``ceil`` functions
  11839. would and handles error conditions in the same way.
  11840. '``llvm.experimental.constrained.floor``' Intrinsic
  11841. ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  11842. Syntax:
  11843. """""""
  11844. ::
  11845. declare <type>
  11846. @llvm.experimental.constrained.floor(<type> <op1>,
  11847. metadata <rounding mode>,
  11848. metadata <exception behavior>)
  11849. Overview:
  11850. """""""""
  11851. The '``llvm.experimental.constrained.floor``' intrinsic returns the floor of the
  11852. first operand.
  11853. Arguments:
  11854. """"""""""
  11855. The first argument and the return value are floating-point numbers of the same
  11856. type.
  11857. The second and third arguments specify the rounding mode and exception
  11858. behavior as described above. The rounding mode is currently unused for this
  11859. intrinsic.
  11860. Semantics:
  11861. """"""""""
  11862. This function returns the same values as the libm ``floor`` functions
  11863. would and handles error conditions in the same way.
  11864. '``llvm.experimental.constrained.round``' Intrinsic
  11865. ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  11866. Syntax:
  11867. """""""
  11868. ::
  11869. declare <type>
  11870. @llvm.experimental.constrained.round(<type> <op1>,
  11871. metadata <rounding mode>,
  11872. metadata <exception behavior>)
  11873. Overview:
  11874. """""""""
  11875. The '``llvm.experimental.constrained.round``' intrinsic returns the first
  11876. operand rounded to the nearest integer.
  11877. Arguments:
  11878. """"""""""
  11879. The first argument and the return value are floating-point numbers of the same
  11880. type.
  11881. The second and third arguments specify the rounding mode and exception
  11882. behavior as described above. The rounding mode is currently unused for this
  11883. intrinsic.
  11884. Semantics:
  11885. """"""""""
  11886. This function returns the same values as the libm ``round`` functions
  11887. would and handles error conditions in the same way.
  11888. '``llvm.experimental.constrained.trunc``' Intrinsic
  11889. ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  11890. Syntax:
  11891. """""""
  11892. ::
  11893. declare <type>
  11894. @llvm.experimental.constrained.trunc(<type> <op1>,
  11895. metadata <truncing mode>,
  11896. metadata <exception behavior>)
  11897. Overview:
  11898. """""""""
  11899. The '``llvm.experimental.constrained.trunc``' intrinsic returns the first
  11900. operand rounded to the nearest integer not larger in magnitude than the
  11901. operand.
  11902. Arguments:
  11903. """"""""""
  11904. The first argument and the return value are floating-point numbers of the same
  11905. type.
  11906. The second and third arguments specify the truncing mode and exception
  11907. behavior as described above. The truncing mode is currently unused for this
  11908. intrinsic.
  11909. Semantics:
  11910. """"""""""
  11911. This function returns the same values as the libm ``trunc`` functions
  11912. would and handles error conditions in the same way.
  11913. General Intrinsics
  11914. ------------------
  11915. This class of intrinsics is designed to be generic and has no specific
  11916. purpose.
  11917. '``llvm.var.annotation``' Intrinsic
  11918. ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  11919. Syntax:
  11920. """""""
  11921. ::
  11922. declare void @llvm.var.annotation(i8* <val>, i8* <str>, i8* <str>, i32 <int>)
  11923. Overview:
  11924. """""""""
  11925. The '``llvm.var.annotation``' intrinsic.
  11926. Arguments:
  11927. """"""""""
  11928. The first argument is a pointer to a value, the second is a pointer to a
  11929. global string, the third is a pointer to a global string which is the
  11930. source file name, and the last argument is the line number.
  11931. Semantics:
  11932. """"""""""
  11933. This intrinsic allows annotation of local variables with arbitrary
  11934. strings. This can be useful for special purpose optimizations that want
  11935. to look for these annotations. These have no other defined use; they are
  11936. ignored by code generation and optimization.
  11937. '``llvm.ptr.annotation.*``' Intrinsic
  11938. ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  11939. Syntax:
  11940. """""""
  11941. This is an overloaded intrinsic. You can use '``llvm.ptr.annotation``' on a
  11942. pointer to an integer of any width. *NOTE* you must specify an address space for
  11943. the pointer. The identifier for the default address space is the integer
  11944. '``0``'.
  11945. ::
  11946. declare i8* @llvm.ptr.annotation.p<address space>i8(i8* <val>, i8* <str>, i8* <str>, i32 <int>)
  11947. declare i16* @llvm.ptr.annotation.p<address space>i16(i16* <val>, i8* <str>, i8* <str>, i32 <int>)
  11948. declare i32* @llvm.ptr.annotation.p<address space>i32(i32* <val>, i8* <str>, i8* <str>, i32 <int>)
  11949. declare i64* @llvm.ptr.annotation.p<address space>i64(i64* <val>, i8* <str>, i8* <str>, i32 <int>)
  11950. declare i256* @llvm.ptr.annotation.p<address space>i256(i256* <val>, i8* <str>, i8* <str>, i32 <int>)
  11951. Overview:
  11952. """""""""
  11953. The '``llvm.ptr.annotation``' intrinsic.
  11954. Arguments:
  11955. """"""""""
  11956. The first argument is a pointer to an integer value of arbitrary bitwidth
  11957. (result of some expression), the second is a pointer to a global string, the
  11958. third is a pointer to a global string which is the source file name, and the
  11959. last argument is the line number. It returns the value of the first argument.
  11960. Semantics:
  11961. """"""""""
  11962. This intrinsic allows annotation of a pointer to an integer with arbitrary
  11963. strings. This can be useful for special purpose optimizations that want to look
  11964. for these annotations. These have no other defined use; they are ignored by code
  11965. generation and optimization.
  11966. '``llvm.annotation.*``' Intrinsic
  11967. ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  11968. Syntax:
  11969. """""""
  11970. This is an overloaded intrinsic. You can use '``llvm.annotation``' on
  11971. any integer bit width.
  11972. ::
  11973. declare i8 @llvm.annotation.i8(i8 <val>, i8* <str>, i8* <str>, i32 <int>)
  11974. declare i16 @llvm.annotation.i16(i16 <val>, i8* <str>, i8* <str>, i32 <int>)
  11975. declare i32 @llvm.annotation.i32(i32 <val>, i8* <str>, i8* <str>, i32 <int>)
  11976. declare i64 @llvm.annotation.i64(i64 <val>, i8* <str>, i8* <str>, i32 <int>)
  11977. declare i256 @llvm.annotation.i256(i256 <val>, i8* <str>, i8* <str>, i32 <int>)
  11978. Overview:
  11979. """""""""
  11980. The '``llvm.annotation``' intrinsic.
  11981. Arguments:
  11982. """"""""""
  11983. The first argument is an integer value (result of some expression), the
  11984. second is a pointer to a global string, the third is a pointer to a
  11985. global string which is the source file name, and the last argument is
  11986. the line number. It returns the value of the first argument.
  11987. Semantics:
  11988. """"""""""
  11989. This intrinsic allows annotations to be put on arbitrary expressions
  11990. with arbitrary strings. This can be useful for special purpose
  11991. optimizations that want to look for these annotations. These have no
  11992. other defined use; they are ignored by code generation and optimization.
  11993. '``llvm.codeview.annotation``' Intrinsic
  11994. ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  11995. Syntax:
  11996. """""""
  11997. This annotation emits a label at its program point and an associated
  11998. ``S_ANNOTATION`` codeview record with some additional string metadata. This is
  11999. used to implement MSVC's ``__annotation`` intrinsic. It is marked
  12000. ``noduplicate``, so calls to this intrinsic prevent inlining and should be
  12001. considered expensive.
  12002. ::
  12003. declare void @llvm.codeview.annotation(metadata)
  12004. Arguments:
  12005. """"""""""
  12006. The argument should be an MDTuple containing any number of MDStrings.
  12007. '``llvm.trap``' Intrinsic
  12008. ^^^^^^^^^^^^^^^^^^^^^^^^^
  12009. Syntax:
  12010. """""""
  12011. ::
  12012. declare void @llvm.trap() cold noreturn nounwind
  12013. Overview:
  12014. """""""""
  12015. The '``llvm.trap``' intrinsic.
  12016. Arguments:
  12017. """"""""""
  12018. None.
  12019. Semantics:
  12020. """"""""""
  12021. This intrinsic is lowered to the target dependent trap instruction. If
  12022. the target does not have a trap instruction, this intrinsic will be
  12023. lowered to a call of the ``abort()`` function.
  12024. '``llvm.debugtrap``' Intrinsic
  12025. ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  12026. Syntax:
  12027. """""""
  12028. ::
  12029. declare void @llvm.debugtrap() nounwind
  12030. Overview:
  12031. """""""""
  12032. The '``llvm.debugtrap``' intrinsic.
  12033. Arguments:
  12034. """"""""""
  12035. None.
  12036. Semantics:
  12037. """"""""""
  12038. This intrinsic is lowered to code which is intended to cause an
  12039. execution trap with the intention of requesting the attention of a
  12040. debugger.
  12041. '``llvm.stackprotector``' Intrinsic
  12042. ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  12043. Syntax:
  12044. """""""
  12045. ::
  12046. declare void @llvm.stackprotector(i8* <guard>, i8** <slot>)
  12047. Overview:
  12048. """""""""
  12049. The ``llvm.stackprotector`` intrinsic takes the ``guard`` and stores it
  12050. onto the stack at ``slot``. The stack slot is adjusted to ensure that it
  12051. is placed on the stack before local variables.
  12052. Arguments:
  12053. """"""""""
  12054. The ``llvm.stackprotector`` intrinsic requires two pointer arguments.
  12055. The first argument is the value loaded from the stack guard
  12056. ``@__stack_chk_guard``. The second variable is an ``alloca`` that has
  12057. enough space to hold the value of the guard.
  12058. Semantics:
  12059. """"""""""
  12060. This intrinsic causes the prologue/epilogue inserter to force the position of
  12061. the ``AllocaInst`` stack slot to be before local variables on the stack. This is
  12062. to ensure that if a local variable on the stack is overwritten, it will destroy
  12063. the value of the guard. When the function exits, the guard on the stack is
  12064. checked against the original guard by ``llvm.stackprotectorcheck``. If they are
  12065. different, then ``llvm.stackprotectorcheck`` causes the program to abort by
  12066. calling the ``__stack_chk_fail()`` function.
  12067. '``llvm.stackguard``' Intrinsic
  12068. ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  12069. Syntax:
  12070. """""""
  12071. ::
  12072. declare i8* @llvm.stackguard()
  12073. Overview:
  12074. """""""""
  12075. The ``llvm.stackguard`` intrinsic returns the system stack guard value.
  12076. It should not be generated by frontends, since it is only for internal usage.
  12077. The reason why we create this intrinsic is that we still support IR form Stack
  12078. Protector in FastISel.
  12079. Arguments:
  12080. """"""""""
  12081. None.
  12082. Semantics:
  12083. """"""""""
  12084. On some platforms, the value returned by this intrinsic remains unchanged
  12085. between loads in the same thread. On other platforms, it returns the same
  12086. global variable value, if any, e.g. ``@__stack_chk_guard``.
  12087. Currently some platforms have IR-level customized stack guard loading (e.g.
  12088. X86 Linux) that is not handled by ``llvm.stackguard()``, while they should be
  12089. in the future.
  12090. '``llvm.objectsize``' Intrinsic
  12091. ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  12092. Syntax:
  12093. """""""
  12094. ::
  12095. declare i32 @llvm.objectsize.i32(i8* <object>, i1 <min>, i1 <nullunknown>, i1 <dynamic>)
  12096. declare i64 @llvm.objectsize.i64(i8* <object>, i1 <min>, i1 <nullunknown>, i1 <dynamic>)
  12097. Overview:
  12098. """""""""
  12099. The ``llvm.objectsize`` intrinsic is designed to provide information to the
  12100. optimizer to determine whether a) an operation (like memcpy) will overflow a
  12101. buffer that corresponds to an object, or b) that a runtime check for overflow
  12102. isn't necessary. An object in this context means an allocation of a specific
  12103. class, structure, array, or other object.
  12104. Arguments:
  12105. """"""""""
  12106. The ``llvm.objectsize`` intrinsic takes four arguments. The first argument is a
  12107. pointer to or into the ``object``. The second argument determines whether
  12108. ``llvm.objectsize`` returns 0 (if true) or -1 (if false) when the object size is
  12109. unknown. The third argument controls how ``llvm.objectsize`` acts when ``null``
  12110. in address space 0 is used as its pointer argument. If it's ``false``,
  12111. ``llvm.objectsize`` reports 0 bytes available when given ``null``. Otherwise, if
  12112. the ``null`` is in a non-zero address space or if ``true`` is given for the
  12113. third argument of ``llvm.objectsize``, we assume its size is unknown. The fourth
  12114. argument to ``llvm.objectsize`` determines if the value should be evaluated at
  12115. runtime.
  12116. The second, third, and fourth arguments only accept constants.
  12117. Semantics:
  12118. """"""""""
  12119. The ``llvm.objectsize`` intrinsic is lowered to a value representing the size of
  12120. the object concerned. If the size cannot be determined, ``llvm.objectsize``
  12121. returns ``i32/i64 -1 or 0`` (depending on the ``min`` argument).
  12122. '``llvm.expect``' Intrinsic
  12123. ^^^^^^^^^^^^^^^^^^^^^^^^^^^
  12124. Syntax:
  12125. """""""
  12126. This is an overloaded intrinsic. You can use ``llvm.expect`` on any
  12127. integer bit width.
  12128. ::
  12129. declare i1 @llvm.expect.i1(i1 <val>, i1 <expected_val>)
  12130. declare i32 @llvm.expect.i32(i32 <val>, i32 <expected_val>)
  12131. declare i64 @llvm.expect.i64(i64 <val>, i64 <expected_val>)
  12132. Overview:
  12133. """""""""
  12134. The ``llvm.expect`` intrinsic provides information about expected (the
  12135. most probable) value of ``val``, which can be used by optimizers.
  12136. Arguments:
  12137. """"""""""
  12138. The ``llvm.expect`` intrinsic takes two arguments. The first argument is
  12139. a value. The second argument is an expected value.
  12140. Semantics:
  12141. """"""""""
  12142. This intrinsic is lowered to the ``val``.
  12143. .. _int_assume:
  12144. '``llvm.assume``' Intrinsic
  12145. ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  12146. Syntax:
  12147. """""""
  12148. ::
  12149. declare void @llvm.assume(i1 %cond)
  12150. Overview:
  12151. """""""""
  12152. The ``llvm.assume`` allows the optimizer to assume that the provided
  12153. condition is true. This information can then be used in simplifying other parts
  12154. of the code.
  12155. Arguments:
  12156. """"""""""
  12157. The condition which the optimizer may assume is always true.
  12158. Semantics:
  12159. """"""""""
  12160. The intrinsic allows the optimizer to assume that the provided condition is
  12161. always true whenever the control flow reaches the intrinsic call. No code is
  12162. generated for this intrinsic, and instructions that contribute only to the
  12163. provided condition are not used for code generation. If the condition is
  12164. violated during execution, the behavior is undefined.
  12165. Note that the optimizer might limit the transformations performed on values
  12166. used by the ``llvm.assume`` intrinsic in order to preserve the instructions
  12167. only used to form the intrinsic's input argument. This might prove undesirable
  12168. if the extra information provided by the ``llvm.assume`` intrinsic does not cause
  12169. sufficient overall improvement in code quality. For this reason,
  12170. ``llvm.assume`` should not be used to document basic mathematical invariants
  12171. that the optimizer can otherwise deduce or facts that are of little use to the
  12172. optimizer.
  12173. .. _int_ssa_copy:
  12174. '``llvm.ssa_copy``' Intrinsic
  12175. ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  12176. Syntax:
  12177. """""""
  12178. ::
  12179. declare type @llvm.ssa_copy(type %operand) returned(1) readnone
  12180. Arguments:
  12181. """"""""""
  12182. The first argument is an operand which is used as the returned value.
  12183. Overview:
  12184. """"""""""
  12185. The ``llvm.ssa_copy`` intrinsic can be used to attach information to
  12186. operations by copying them and giving them new names. For example,
  12187. the PredicateInfo utility uses it to build Extended SSA form, and
  12188. attach various forms of information to operands that dominate specific
  12189. uses. It is not meant for general use, only for building temporary
  12190. renaming forms that require value splits at certain points.
  12191. .. _type.test:
  12192. '``llvm.type.test``' Intrinsic
  12193. ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  12194. Syntax:
  12195. """""""
  12196. ::
  12197. declare i1 @llvm.type.test(i8* %ptr, metadata %type) nounwind readnone
  12198. Arguments:
  12199. """"""""""
  12200. The first argument is a pointer to be tested. The second argument is a
  12201. metadata object representing a :doc:`type identifier <TypeMetadata>`.
  12202. Overview:
  12203. """""""""
  12204. The ``llvm.type.test`` intrinsic tests whether the given pointer is associated
  12205. with the given type identifier.
  12206. '``llvm.type.checked.load``' Intrinsic
  12207. ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  12208. Syntax:
  12209. """""""
  12210. ::
  12211. declare {i8*, i1} @llvm.type.checked.load(i8* %ptr, i32 %offset, metadata %type) argmemonly nounwind readonly
  12212. Arguments:
  12213. """"""""""
  12214. The first argument is a pointer from which to load a function pointer. The
  12215. second argument is the byte offset from which to load the function pointer. The
  12216. third argument is a metadata object representing a :doc:`type identifier
  12217. <TypeMetadata>`.
  12218. Overview:
  12219. """""""""
  12220. The ``llvm.type.checked.load`` intrinsic safely loads a function pointer from a
  12221. virtual table pointer using type metadata. This intrinsic is used to implement
  12222. control flow integrity in conjunction with virtual call optimization. The
  12223. virtual call optimization pass will optimize away ``llvm.type.checked.load``
  12224. intrinsics associated with devirtualized calls, thereby removing the type
  12225. check in cases where it is not needed to enforce the control flow integrity
  12226. constraint.
  12227. If the given pointer is associated with a type metadata identifier, this
  12228. function returns true as the second element of its return value. (Note that
  12229. the function may also return true if the given pointer is not associated
  12230. with a type metadata identifier.) If the function's return value's second
  12231. element is true, the following rules apply to the first element:
  12232. - If the given pointer is associated with the given type metadata identifier,
  12233. it is the function pointer loaded from the given byte offset from the given
  12234. pointer.
  12235. - If the given pointer is not associated with the given type metadata
  12236. identifier, it is one of the following (the choice of which is unspecified):
  12237. 1. The function pointer that would have been loaded from an arbitrarily chosen
  12238. (through an unspecified mechanism) pointer associated with the type
  12239. metadata.
  12240. 2. If the function has a non-void return type, a pointer to a function that
  12241. returns an unspecified value without causing side effects.
  12242. If the function's return value's second element is false, the value of the
  12243. first element is undefined.
  12244. '``llvm.donothing``' Intrinsic
  12245. ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  12246. Syntax:
  12247. """""""
  12248. ::
  12249. declare void @llvm.donothing() nounwind readnone
  12250. Overview:
  12251. """""""""
  12252. The ``llvm.donothing`` intrinsic doesn't perform any operation. It's one of only
  12253. three intrinsics (besides ``llvm.experimental.patchpoint`` and
  12254. ``llvm.experimental.gc.statepoint``) that can be called with an invoke
  12255. instruction.
  12256. Arguments:
  12257. """"""""""
  12258. None.
  12259. Semantics:
  12260. """"""""""
  12261. This intrinsic does nothing, and it's removed by optimizers and ignored
  12262. by codegen.
  12263. '``llvm.experimental.deoptimize``' Intrinsic
  12264. ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  12265. Syntax:
  12266. """""""
  12267. ::
  12268. declare type @llvm.experimental.deoptimize(...) [ "deopt"(...) ]
  12269. Overview:
  12270. """""""""
  12271. This intrinsic, together with :ref:`deoptimization operand bundles
  12272. <deopt_opbundles>`, allow frontends to express transfer of control and
  12273. frame-local state from the currently executing (typically more specialized,
  12274. hence faster) version of a function into another (typically more generic, hence
  12275. slower) version.
  12276. In languages with a fully integrated managed runtime like Java and JavaScript
  12277. this intrinsic can be used to implement "uncommon trap" or "side exit" like
  12278. functionality. In unmanaged languages like C and C++, this intrinsic can be
  12279. used to represent the slow paths of specialized functions.
  12280. Arguments:
  12281. """"""""""
  12282. The intrinsic takes an arbitrary number of arguments, whose meaning is
  12283. decided by the :ref:`lowering strategy<deoptimize_lowering>`.
  12284. Semantics:
  12285. """"""""""
  12286. The ``@llvm.experimental.deoptimize`` intrinsic executes an attached
  12287. deoptimization continuation (denoted using a :ref:`deoptimization
  12288. operand bundle <deopt_opbundles>`) and returns the value returned by
  12289. the deoptimization continuation. Defining the semantic properties of
  12290. the continuation itself is out of scope of the language reference --
  12291. as far as LLVM is concerned, the deoptimization continuation can
  12292. invoke arbitrary side effects, including reading from and writing to
  12293. the entire heap.
  12294. Deoptimization continuations expressed using ``"deopt"`` operand bundles always
  12295. continue execution to the end of the physical frame containing them, so all
  12296. calls to ``@llvm.experimental.deoptimize`` must be in "tail position":
  12297. - ``@llvm.experimental.deoptimize`` cannot be invoked.
  12298. - The call must immediately precede a :ref:`ret <i_ret>` instruction.
  12299. - The ``ret`` instruction must return the value produced by the
  12300. ``@llvm.experimental.deoptimize`` call if there is one, or void.
  12301. Note that the above restrictions imply that the return type for a call to
  12302. ``@llvm.experimental.deoptimize`` will match the return type of its immediate
  12303. caller.
  12304. The inliner composes the ``"deopt"`` continuations of the caller into the
  12305. ``"deopt"`` continuations present in the inlinee, and also updates calls to this
  12306. intrinsic to return directly from the frame of the function it inlined into.
  12307. All declarations of ``@llvm.experimental.deoptimize`` must share the
  12308. same calling convention.
  12309. .. _deoptimize_lowering:
  12310. Lowering:
  12311. """""""""
  12312. Calls to ``@llvm.experimental.deoptimize`` are lowered to calls to the
  12313. symbol ``__llvm_deoptimize`` (it is the frontend's responsibility to
  12314. ensure that this symbol is defined). The call arguments to
  12315. ``@llvm.experimental.deoptimize`` are lowered as if they were formal
  12316. arguments of the specified types, and not as varargs.
  12317. '``llvm.experimental.guard``' Intrinsic
  12318. ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  12319. Syntax:
  12320. """""""
  12321. ::
  12322. declare void @llvm.experimental.guard(i1, ...) [ "deopt"(...) ]
  12323. Overview:
  12324. """""""""
  12325. This intrinsic, together with :ref:`deoptimization operand bundles
  12326. <deopt_opbundles>`, allows frontends to express guards or checks on
  12327. optimistic assumptions made during compilation. The semantics of
  12328. ``@llvm.experimental.guard`` is defined in terms of
  12329. ``@llvm.experimental.deoptimize`` -- its body is defined to be
  12330. equivalent to:
  12331. .. code-block:: text
  12332. define void @llvm.experimental.guard(i1 %pred, <args...>) {
  12333. %realPred = and i1 %pred, undef
  12334. br i1 %realPred, label %continue, label %leave [, !make.implicit !{}]
  12335. leave:
  12336. call void @llvm.experimental.deoptimize(<args...>) [ "deopt"() ]
  12337. ret void
  12338. continue:
  12339. ret void
  12340. }
  12341. with the optional ``[, !make.implicit !{}]`` present if and only if it
  12342. is present on the call site. For more details on ``!make.implicit``,
  12343. see :doc:`FaultMaps`.
  12344. In words, ``@llvm.experimental.guard`` executes the attached
  12345. ``"deopt"`` continuation if (but **not** only if) its first argument
  12346. is ``false``. Since the optimizer is allowed to replace the ``undef``
  12347. with an arbitrary value, it can optimize guard to fail "spuriously",
  12348. i.e. without the original condition being false (hence the "not only
  12349. if"); and this allows for "check widening" type optimizations.
  12350. ``@llvm.experimental.guard`` cannot be invoked.
  12351. '``llvm.experimental.widenable.condition``' Intrinsic
  12352. ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  12353. Syntax:
  12354. """""""
  12355. ::
  12356. declare i1 @llvm.experimental.widenable.condition()
  12357. Overview:
  12358. """""""""
  12359. This intrinsic represents a "widenable condition" which is
  12360. boolean expressions with the following property: whether this
  12361. expression is `true` or `false`, the program is correct and
  12362. well-defined.
  12363. Together with :ref:`deoptimization operand bundles <deopt_opbundles>`,
  12364. ``@llvm.experimental.widenable.condition`` allows frontends to
  12365. express guards or checks on optimistic assumptions made during
  12366. compilation and represent them as branch instructions on special
  12367. conditions.
  12368. While this may appear similar in semantics to `undef`, it is very
  12369. different in that an invocation produces a particular, singular
  12370. value. It is also intended to be lowered late, and remain available
  12371. for specific optimizations and transforms that can benefit from its
  12372. special properties.
  12373. Arguments:
  12374. """"""""""
  12375. None.
  12376. Semantics:
  12377. """"""""""
  12378. The intrinsic ``@llvm.experimental.widenable.condition()``
  12379. returns either `true` or `false`. For each evaluation of a call
  12380. to this intrinsic, the program must be valid and correct both if
  12381. it returns `true` and if it returns `false`. This allows
  12382. transformation passes to replace evaluations of this intrinsic
  12383. with either value whenever one is beneficial.
  12384. When used in a branch condition, it allows us to choose between
  12385. two alternative correct solutions for the same problem, like
  12386. in example below:
  12387. .. code-block:: text
  12388. %cond = call i1 @llvm.experimental.widenable.condition()
  12389. br i1 %cond, label %solution_1, label %solution_2
  12390. label %fast_path:
  12391. ; Apply memory-consuming but fast solution for a task.
  12392. label %slow_path:
  12393. ; Cheap in memory but slow solution.
  12394. Whether the result of intrinsic's call is `true` or `false`,
  12395. it should be correct to pick either solution. We can switch
  12396. between them by replacing the result of
  12397. ``@llvm.experimental.widenable.condition`` with different
  12398. `i1` expressions.
  12399. This is how it can be used to represent guards as widenable branches:
  12400. .. code-block:: text
  12401. block:
  12402. ; Unguarded instructions
  12403. call void @llvm.experimental.guard(i1 %cond, <args...>) ["deopt"(<deopt_args...>)]
  12404. ; Guarded instructions
  12405. Can be expressed in an alternative equivalent form of explicit branch using
  12406. ``@llvm.experimental.widenable.condition``:
  12407. .. code-block:: text
  12408. block:
  12409. ; Unguarded instructions
  12410. %widenable_condition = call i1 @llvm.experimental.widenable.condition()
  12411. %guard_condition = and i1 %cond, %widenable_condition
  12412. br i1 %guard_condition, label %guarded, label %deopt
  12413. guarded:
  12414. ; Guarded instructions
  12415. deopt:
  12416. call type @llvm.experimental.deoptimize(<args...>) [ "deopt"(<deopt_args...>) ]
  12417. So the block `guarded` is only reachable when `%cond` is `true`,
  12418. and it should be valid to go to the block `deopt` whenever `%cond`
  12419. is `true` or `false`.
  12420. ``@llvm.experimental.widenable.condition`` will never throw, thus
  12421. it cannot be invoked.
  12422. Guard widening:
  12423. """""""""""""""
  12424. When ``@llvm.experimental.widenable.condition()`` is used in
  12425. condition of a guard represented as explicit branch, it is
  12426. legal to widen the guard's condition with any additional
  12427. conditions.
  12428. Guard widening looks like replacement of
  12429. .. code-block:: text
  12430. %widenable_cond = call i1 @llvm.experimental.widenable.condition()
  12431. %guard_cond = and i1 %cond, %widenable_cond
  12432. br i1 %guard_cond, label %guarded, label %deopt
  12433. with
  12434. .. code-block:: text
  12435. %widenable_cond = call i1 @llvm.experimental.widenable.condition()
  12436. %new_cond = and i1 %any_other_cond, %widenable_cond
  12437. %new_guard_cond = and i1 %cond, %new_cond
  12438. br i1 %new_guard_cond, label %guarded, label %deopt
  12439. for this branch. Here `%any_other_cond` is an arbitrarily chosen
  12440. well-defined `i1` value. By making guard widening, we may
  12441. impose stricter conditions on `guarded` block and bail to the
  12442. deopt when the new condition is not met.
  12443. Lowering:
  12444. """""""""
  12445. Default lowering strategy is replacing the result of
  12446. call of ``@llvm.experimental.widenable.condition`` with
  12447. constant `true`. However it is always correct to replace
  12448. it with any other `i1` value. Any pass can
  12449. freely do it if it can benefit from non-default lowering.
  12450. '``llvm.load.relative``' Intrinsic
  12451. ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  12452. Syntax:
  12453. """""""
  12454. ::
  12455. declare i8* @llvm.load.relative.iN(i8* %ptr, iN %offset) argmemonly nounwind readonly
  12456. Overview:
  12457. """""""""
  12458. This intrinsic loads a 32-bit value from the address ``%ptr + %offset``,
  12459. adds ``%ptr`` to that value and returns it. The constant folder specifically
  12460. recognizes the form of this intrinsic and the constant initializers it may
  12461. load from; if a loaded constant initializer is known to have the form
  12462. ``i32 trunc(x - %ptr)``, the intrinsic call is folded to ``x``.
  12463. LLVM provides that the calculation of such a constant initializer will
  12464. not overflow at link time under the medium code model if ``x`` is an
  12465. ``unnamed_addr`` function. However, it does not provide this guarantee for
  12466. a constant initializer folded into a function body. This intrinsic can be
  12467. used to avoid the possibility of overflows when loading from such a constant.
  12468. '``llvm.sideeffect``' Intrinsic
  12469. ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  12470. Syntax:
  12471. """""""
  12472. ::
  12473. declare void @llvm.sideeffect() inaccessiblememonly nounwind
  12474. Overview:
  12475. """""""""
  12476. The ``llvm.sideeffect`` intrinsic doesn't perform any operation. Optimizers
  12477. treat it as having side effects, so it can be inserted into a loop to
  12478. indicate that the loop shouldn't be assumed to terminate (which could
  12479. potentially lead to the loop being optimized away entirely), even if it's
  12480. an infinite loop with no other side effects.
  12481. Arguments:
  12482. """"""""""
  12483. None.
  12484. Semantics:
  12485. """"""""""
  12486. This intrinsic actually does nothing, but optimizers must assume that it
  12487. has externally observable side effects.
  12488. '``llvm.is.constant.*``' Intrinsic
  12489. ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  12490. Syntax:
  12491. """""""
  12492. This is an overloaded intrinsic. You can use llvm.is.constant with any argument type.
  12493. ::
  12494. declare i1 @llvm.is.constant.i32(i32 %operand) nounwind readnone
  12495. declare i1 @llvm.is.constant.f32(float %operand) nounwind readnone
  12496. declare i1 @llvm.is.constant.TYPENAME(TYPE %operand) nounwind readnone
  12497. Overview:
  12498. """""""""
  12499. The '``llvm.is.constant``' intrinsic will return true if the argument
  12500. is known to be a manifest compile-time constant. It is guaranteed to
  12501. fold to either true or false before generating machine code.
  12502. Semantics:
  12503. """"""""""
  12504. This intrinsic generates no code. If its argument is known to be a
  12505. manifest compile-time constant value, then the intrinsic will be
  12506. converted to a constant true value. Otherwise, it will be converted to
  12507. a constant false value.
  12508. In particular, note that if the argument is a constant expression
  12509. which refers to a global (the address of which _is_ a constant, but
  12510. not manifest during the compile), then the intrinsic evaluates to
  12511. false.
  12512. The result also intentionally depends on the result of optimization
  12513. passes -- e.g., the result can change depending on whether a
  12514. function gets inlined or not. A function's parameters are
  12515. obviously not constant. However, a call like
  12516. ``llvm.is.constant.i32(i32 %param)`` *can* return true after the
  12517. function is inlined, if the value passed to the function parameter was
  12518. a constant.
  12519. On the other hand, if constant folding is not run, it will never
  12520. evaluate to true, even in simple cases.
  12521. .. _int_ptrmask:
  12522. '``llvm.ptrmask``' Intrinsic
  12523. ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  12524. Syntax:
  12525. """""""
  12526. ::
  12527. declare ptrty llvm.ptrmask(ptrty %ptr, intty %mask) readnone speculatable
  12528. Arguments:
  12529. """"""""""
  12530. The first argument is a pointer. The second argument is an integer.
  12531. Overview:
  12532. """"""""""
  12533. The ``llvm.ptrmask`` intrinsic masks out bits of the pointer according to a mask.
  12534. This allows stripping data from tagged pointers without converting them to an
  12535. integer (ptrtoint/inttoptr). As a consequence, we can preserve more information
  12536. to facilitate alias analysis and underlying-object detection.
  12537. Semantics:
  12538. """"""""""
  12539. The result of ``ptrmask(ptr, mask)`` is equivalent to
  12540. ``getelementptr ptr, (ptrtoint(ptr) & mask) - ptrtoint(ptr)``. Both the returned
  12541. pointer and the first argument are based on the same underlying object (for more
  12542. information on the *based on* terminology see
  12543. :ref:`the pointer aliasing rules <pointeraliasing>`). If the bitwidth of the
  12544. mask argument does not match the pointer size of the target, the mask is
  12545. zero-extended or truncated accordingly.
  12546. Stack Map Intrinsics
  12547. --------------------
  12548. LLVM provides experimental intrinsics to support runtime patching
  12549. mechanisms commonly desired in dynamic language JITs. These intrinsics
  12550. are described in :doc:`StackMaps`.
  12551. Element Wise Atomic Memory Intrinsics
  12552. -------------------------------------
  12553. These intrinsics are similar to the standard library memory intrinsics except
  12554. that they perform memory transfer as a sequence of atomic memory accesses.
  12555. .. _int_memcpy_element_unordered_atomic:
  12556. '``llvm.memcpy.element.unordered.atomic``' Intrinsic
  12557. ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  12558. Syntax:
  12559. """""""
  12560. This is an overloaded intrinsic. You can use ``llvm.memcpy.element.unordered.atomic`` on
  12561. any integer bit width and for different address spaces. Not all targets
  12562. support all bit widths however.
  12563. ::
  12564. declare void @llvm.memcpy.element.unordered.atomic.p0i8.p0i8.i32(i8* <dest>,
  12565. i8* <src>,
  12566. i32 <len>,
  12567. i32 <element_size>)
  12568. declare void @llvm.memcpy.element.unordered.atomic.p0i8.p0i8.i64(i8* <dest>,
  12569. i8* <src>,
  12570. i64 <len>,
  12571. i32 <element_size>)
  12572. Overview:
  12573. """""""""
  12574. The '``llvm.memcpy.element.unordered.atomic.*``' intrinsic is a specialization of the
  12575. '``llvm.memcpy.*``' intrinsic. It differs in that the ``dest`` and ``src`` are treated
  12576. as arrays with elements that are exactly ``element_size`` bytes, and the copy between
  12577. buffers uses a sequence of :ref:`unordered atomic <ordering>` load/store operations
  12578. that are a positive integer multiple of the ``element_size`` in size.
  12579. Arguments:
  12580. """"""""""
  12581. The first three arguments are the same as they are in the :ref:`@llvm.memcpy <int_memcpy>`
  12582. intrinsic, with the added constraint that ``len`` is required to be a positive integer
  12583. multiple of the ``element_size``. If ``len`` is not a positive integer multiple of
  12584. ``element_size``, then the behaviour of the intrinsic is undefined.
  12585. ``element_size`` must be a compile-time constant positive power of two no greater than
  12586. target-specific atomic access size limit.
  12587. For each of the input pointers ``align`` parameter attribute must be specified. It
  12588. must be a power of two no less than the ``element_size``. Caller guarantees that
  12589. both the source and destination pointers are aligned to that boundary.
  12590. Semantics:
  12591. """"""""""
  12592. The '``llvm.memcpy.element.unordered.atomic.*``' intrinsic copies ``len`` bytes of
  12593. memory from the source location to the destination location. These locations are not
  12594. allowed to overlap. The memory copy is performed as a sequence of load/store operations
  12595. where each access is guaranteed to be a multiple of ``element_size`` bytes wide and
  12596. aligned at an ``element_size`` boundary.
  12597. The order of the copy is unspecified. The same value may be read from the source
  12598. buffer many times, but only one write is issued to the destination buffer per
  12599. element. It is well defined to have concurrent reads and writes to both source and
  12600. destination provided those reads and writes are unordered atomic when specified.
  12601. This intrinsic does not provide any additional ordering guarantees over those
  12602. provided by a set of unordered loads from the source location and stores to the
  12603. destination.
  12604. Lowering:
  12605. """""""""
  12606. In the most general case call to the '``llvm.memcpy.element.unordered.atomic.*``' is
  12607. lowered to a call to the symbol ``__llvm_memcpy_element_unordered_atomic_*``. Where '*'
  12608. is replaced with an actual element size.
  12609. Optimizer is allowed to inline memory copy when it's profitable to do so.
  12610. '``llvm.memmove.element.unordered.atomic``' Intrinsic
  12611. ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  12612. Syntax:
  12613. """""""
  12614. This is an overloaded intrinsic. You can use
  12615. ``llvm.memmove.element.unordered.atomic`` on any integer bit width and for
  12616. different address spaces. Not all targets support all bit widths however.
  12617. ::
  12618. declare void @llvm.memmove.element.unordered.atomic.p0i8.p0i8.i32(i8* <dest>,
  12619. i8* <src>,
  12620. i32 <len>,
  12621. i32 <element_size>)
  12622. declare void @llvm.memmove.element.unordered.atomic.p0i8.p0i8.i64(i8* <dest>,
  12623. i8* <src>,
  12624. i64 <len>,
  12625. i32 <element_size>)
  12626. Overview:
  12627. """""""""
  12628. The '``llvm.memmove.element.unordered.atomic.*``' intrinsic is a specialization
  12629. of the '``llvm.memmove.*``' intrinsic. It differs in that the ``dest`` and
  12630. ``src`` are treated as arrays with elements that are exactly ``element_size``
  12631. bytes, and the copy between buffers uses a sequence of
  12632. :ref:`unordered atomic <ordering>` load/store operations that are a positive
  12633. integer multiple of the ``element_size`` in size.
  12634. Arguments:
  12635. """"""""""
  12636. The first three arguments are the same as they are in the
  12637. :ref:`@llvm.memmove <int_memmove>` intrinsic, with the added constraint that
  12638. ``len`` is required to be a positive integer multiple of the ``element_size``.
  12639. If ``len`` is not a positive integer multiple of ``element_size``, then the
  12640. behaviour of the intrinsic is undefined.
  12641. ``element_size`` must be a compile-time constant positive power of two no
  12642. greater than a target-specific atomic access size limit.
  12643. For each of the input pointers the ``align`` parameter attribute must be
  12644. specified. It must be a power of two no less than the ``element_size``. Caller
  12645. guarantees that both the source and destination pointers are aligned to that
  12646. boundary.
  12647. Semantics:
  12648. """"""""""
  12649. The '``llvm.memmove.element.unordered.atomic.*``' intrinsic copies ``len`` bytes
  12650. of memory from the source location to the destination location. These locations
  12651. are allowed to overlap. The memory copy is performed as a sequence of load/store
  12652. operations where each access is guaranteed to be a multiple of ``element_size``
  12653. bytes wide and aligned at an ``element_size`` boundary.
  12654. The order of the copy is unspecified. The same value may be read from the source
  12655. buffer many times, but only one write is issued to the destination buffer per
  12656. element. It is well defined to have concurrent reads and writes to both source
  12657. and destination provided those reads and writes are unordered atomic when
  12658. specified.
  12659. This intrinsic does not provide any additional ordering guarantees over those
  12660. provided by a set of unordered loads from the source location and stores to the
  12661. destination.
  12662. Lowering:
  12663. """""""""
  12664. In the most general case call to the
  12665. '``llvm.memmove.element.unordered.atomic.*``' is lowered to a call to the symbol
  12666. ``__llvm_memmove_element_unordered_atomic_*``. Where '*' is replaced with an
  12667. actual element size.
  12668. The optimizer is allowed to inline the memory copy when it's profitable to do so.
  12669. .. _int_memset_element_unordered_atomic:
  12670. '``llvm.memset.element.unordered.atomic``' Intrinsic
  12671. ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  12672. Syntax:
  12673. """""""
  12674. This is an overloaded intrinsic. You can use ``llvm.memset.element.unordered.atomic`` on
  12675. any integer bit width and for different address spaces. Not all targets
  12676. support all bit widths however.
  12677. ::
  12678. declare void @llvm.memset.element.unordered.atomic.p0i8.i32(i8* <dest>,
  12679. i8 <value>,
  12680. i32 <len>,
  12681. i32 <element_size>)
  12682. declare void @llvm.memset.element.unordered.atomic.p0i8.i64(i8* <dest>,
  12683. i8 <value>,
  12684. i64 <len>,
  12685. i32 <element_size>)
  12686. Overview:
  12687. """""""""
  12688. The '``llvm.memset.element.unordered.atomic.*``' intrinsic is a specialization of the
  12689. '``llvm.memset.*``' intrinsic. It differs in that the ``dest`` is treated as an array
  12690. with elements that are exactly ``element_size`` bytes, and the assignment to that array
  12691. uses uses a sequence of :ref:`unordered atomic <ordering>` store operations
  12692. that are a positive integer multiple of the ``element_size`` in size.
  12693. Arguments:
  12694. """"""""""
  12695. The first three arguments are the same as they are in the :ref:`@llvm.memset <int_memset>`
  12696. intrinsic, with the added constraint that ``len`` is required to be a positive integer
  12697. multiple of the ``element_size``. If ``len`` is not a positive integer multiple of
  12698. ``element_size``, then the behaviour of the intrinsic is undefined.
  12699. ``element_size`` must be a compile-time constant positive power of two no greater than
  12700. target-specific atomic access size limit.
  12701. The ``dest`` input pointer must have the ``align`` parameter attribute specified. It
  12702. must be a power of two no less than the ``element_size``. Caller guarantees that
  12703. the destination pointer is aligned to that boundary.
  12704. Semantics:
  12705. """"""""""
  12706. The '``llvm.memset.element.unordered.atomic.*``' intrinsic sets the ``len`` bytes of
  12707. memory starting at the destination location to the given ``value``. The memory is
  12708. set with a sequence of store operations where each access is guaranteed to be a
  12709. multiple of ``element_size`` bytes wide and aligned at an ``element_size`` boundary.
  12710. The order of the assignment is unspecified. Only one write is issued to the
  12711. destination buffer per element. It is well defined to have concurrent reads and
  12712. writes to the destination provided those reads and writes are unordered atomic
  12713. when specified.
  12714. This intrinsic does not provide any additional ordering guarantees over those
  12715. provided by a set of unordered stores to the destination.
  12716. Lowering:
  12717. """""""""
  12718. In the most general case call to the '``llvm.memset.element.unordered.atomic.*``' is
  12719. lowered to a call to the symbol ``__llvm_memset_element_unordered_atomic_*``. Where '*'
  12720. is replaced with an actual element size.
  12721. The optimizer is allowed to inline the memory assignment when it's profitable to do so.
  12722. Objective-C ARC Runtime Intrinsics
  12723. ----------------------------------
  12724. LLVM provides intrinsics that lower to Objective-C ARC runtime entry points.
  12725. LLVM is aware of the semantics of these functions, and optimizes based on that
  12726. knowledge. You can read more about the details of Objective-C ARC `here
  12727. <https://clang.llvm.org/docs/AutomaticReferenceCounting.html>`_.
  12728. '``llvm.objc.autorelease``' Intrinsic
  12729. ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  12730. Syntax:
  12731. """""""
  12732. ::
  12733. declare i8* @llvm.objc.autorelease(i8*)
  12734. Lowering:
  12735. """""""""
  12736. Lowers to a call to `objc_autorelease <https://clang.llvm.org/docs/AutomaticReferenceCounting.html#arc-runtime-objc-autorelease>`_.
  12737. '``llvm.objc.autoreleasePoolPop``' Intrinsic
  12738. ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  12739. Syntax:
  12740. """""""
  12741. ::
  12742. declare void @llvm.objc.autoreleasePoolPop(i8*)
  12743. Lowering:
  12744. """""""""
  12745. Lowers to a call to `objc_autoreleasePoolPop <https://clang.llvm.org/docs/AutomaticReferenceCounting.html#void-objc-autoreleasepoolpop-void-pool>`_.
  12746. '``llvm.objc.autoreleasePoolPush``' Intrinsic
  12747. ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  12748. Syntax:
  12749. """""""
  12750. ::
  12751. declare i8* @llvm.objc.autoreleasePoolPush()
  12752. Lowering:
  12753. """""""""
  12754. Lowers to a call to `objc_autoreleasePoolPush <https://clang.llvm.org/docs/AutomaticReferenceCounting.html#void-objc-autoreleasepoolpush-void>`_.
  12755. '``llvm.objc.autoreleaseReturnValue``' Intrinsic
  12756. ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  12757. Syntax:
  12758. """""""
  12759. ::
  12760. declare i8* @llvm.objc.autoreleaseReturnValue(i8*)
  12761. Lowering:
  12762. """""""""
  12763. Lowers to a call to `objc_autoreleaseReturnValue <https://clang.llvm.org/docs/AutomaticReferenceCounting.html#arc-runtime-objc-autoreleasereturnvalue>`_.
  12764. '``llvm.objc.copyWeak``' Intrinsic
  12765. ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  12766. Syntax:
  12767. """""""
  12768. ::
  12769. declare void @llvm.objc.copyWeak(i8**, i8**)
  12770. Lowering:
  12771. """""""""
  12772. Lowers to a call to `objc_copyWeak <https://clang.llvm.org/docs/AutomaticReferenceCounting.html#void-objc-copyweak-id-dest-id-src>`_.
  12773. '``llvm.objc.destroyWeak``' Intrinsic
  12774. ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  12775. Syntax:
  12776. """""""
  12777. ::
  12778. declare void @llvm.objc.destroyWeak(i8**)
  12779. Lowering:
  12780. """""""""
  12781. Lowers to a call to `objc_destroyWeak <https://clang.llvm.org/docs/AutomaticReferenceCounting.html#void-objc-destroyweak-id-object>`_.
  12782. '``llvm.objc.initWeak``' Intrinsic
  12783. ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  12784. Syntax:
  12785. """""""
  12786. ::
  12787. declare i8* @llvm.objc.initWeak(i8**, i8*)
  12788. Lowering:
  12789. """""""""
  12790. Lowers to a call to `objc_initWeak <https://clang.llvm.org/docs/AutomaticReferenceCounting.html#arc-runtime-objc-initweak>`_.
  12791. '``llvm.objc.loadWeak``' Intrinsic
  12792. ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  12793. Syntax:
  12794. """""""
  12795. ::
  12796. declare i8* @llvm.objc.loadWeak(i8**)
  12797. Lowering:
  12798. """""""""
  12799. Lowers to a call to `objc_loadWeak <https://clang.llvm.org/docs/AutomaticReferenceCounting.html#arc-runtime-objc-loadweak>`_.
  12800. '``llvm.objc.loadWeakRetained``' Intrinsic
  12801. ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  12802. Syntax:
  12803. """""""
  12804. ::
  12805. declare i8* @llvm.objc.loadWeakRetained(i8**)
  12806. Lowering:
  12807. """""""""
  12808. Lowers to a call to `objc_loadWeakRetained <https://clang.llvm.org/docs/AutomaticReferenceCounting.html#arc-runtime-objc-loadweakretained>`_.
  12809. '``llvm.objc.moveWeak``' Intrinsic
  12810. ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  12811. Syntax:
  12812. """""""
  12813. ::
  12814. declare void @llvm.objc.moveWeak(i8**, i8**)
  12815. Lowering:
  12816. """""""""
  12817. Lowers to a call to `objc_moveWeak <https://clang.llvm.org/docs/AutomaticReferenceCounting.html#void-objc-moveweak-id-dest-id-src>`_.
  12818. '``llvm.objc.release``' Intrinsic
  12819. ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  12820. Syntax:
  12821. """""""
  12822. ::
  12823. declare void @llvm.objc.release(i8*)
  12824. Lowering:
  12825. """""""""
  12826. Lowers to a call to `objc_release <https://clang.llvm.org/docs/AutomaticReferenceCounting.html#void-objc-release-id-value>`_.
  12827. '``llvm.objc.retain``' Intrinsic
  12828. ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  12829. Syntax:
  12830. """""""
  12831. ::
  12832. declare i8* @llvm.objc.retain(i8*)
  12833. Lowering:
  12834. """""""""
  12835. Lowers to a call to `objc_retain <https://clang.llvm.org/docs/AutomaticReferenceCounting.html#arc-runtime-objc-retain>`_.
  12836. '``llvm.objc.retainAutorelease``' Intrinsic
  12837. ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  12838. Syntax:
  12839. """""""
  12840. ::
  12841. declare i8* @llvm.objc.retainAutorelease(i8*)
  12842. Lowering:
  12843. """""""""
  12844. Lowers to a call to `objc_retainAutorelease <https://clang.llvm.org/docs/AutomaticReferenceCounting.html#arc-runtime-objc-retainautorelease>`_.
  12845. '``llvm.objc.retainAutoreleaseReturnValue``' Intrinsic
  12846. ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  12847. Syntax:
  12848. """""""
  12849. ::
  12850. declare i8* @llvm.objc.retainAutoreleaseReturnValue(i8*)
  12851. Lowering:
  12852. """""""""
  12853. Lowers to a call to `objc_retainAutoreleaseReturnValue <https://clang.llvm.org/docs/AutomaticReferenceCounting.html#arc-runtime-objc-retainautoreleasereturnvalue>`_.
  12854. '``llvm.objc.retainAutoreleasedReturnValue``' Intrinsic
  12855. ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  12856. Syntax:
  12857. """""""
  12858. ::
  12859. declare i8* @llvm.objc.retainAutoreleasedReturnValue(i8*)
  12860. Lowering:
  12861. """""""""
  12862. Lowers to a call to `objc_retainAutoreleasedReturnValue <https://clang.llvm.org/docs/AutomaticReferenceCounting.html#arc-runtime-objc-retainautoreleasedreturnvalue>`_.
  12863. '``llvm.objc.retainBlock``' Intrinsic
  12864. ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  12865. Syntax:
  12866. """""""
  12867. ::
  12868. declare i8* @llvm.objc.retainBlock(i8*)
  12869. Lowering:
  12870. """""""""
  12871. Lowers to a call to `objc_retainBlock <https://clang.llvm.org/docs/AutomaticReferenceCounting.html#arc-runtime-objc-retainblock>`_.
  12872. '``llvm.objc.storeStrong``' Intrinsic
  12873. ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  12874. Syntax:
  12875. """""""
  12876. ::
  12877. declare void @llvm.objc.storeStrong(i8**, i8*)
  12878. Lowering:
  12879. """""""""
  12880. Lowers to a call to `objc_storeStrong <https://clang.llvm.org/docs/AutomaticReferenceCounting.html#void-objc-storestrong-id-object-id-value>`_.
  12881. '``llvm.objc.storeWeak``' Intrinsic
  12882. ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  12883. Syntax:
  12884. """""""
  12885. ::
  12886. declare i8* @llvm.objc.storeWeak(i8**, i8*)
  12887. Lowering:
  12888. """""""""
  12889. Lowers to a call to `objc_storeWeak <https://clang.llvm.org/docs/AutomaticReferenceCounting.html#arc-runtime-objc-storeweak>`_.
  12890. Preserving Debug Information Intrinsics
  12891. ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  12892. These intrinsics are used to carry certain debuginfo together with
  12893. IR-level operations. For example, it may be desirable to
  12894. know the structure/union name and the original user-level field
  12895. indices. Such information got lost in IR GetElementPtr instruction
  12896. since the IR types are different from debugInfo types and unions
  12897. are converted to structs in IR.
  12898. '``llvm.preserve.array.access.index``' Intrinsic
  12899. ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  12900. Syntax:
  12901. """""""
  12902. ::
  12903. declare <ret_type>
  12904. @llvm.preserve.array.access.index.p0s_union.anons.p0a10s_union.anons(<type> base,
  12905. i32 dim,
  12906. i32 index)
  12907. Overview:
  12908. """""""""
  12909. The '``llvm.preserve.array.access.index``' intrinsic returns the getelementptr address
  12910. based on array base ``base``, array dimension ``dim`` and the last access index ``index``
  12911. into the array. The return type ``ret_type`` is a pointer type to the array element.
  12912. The array ``dim`` and ``index`` are preserved which is more robust than
  12913. getelementptr instruction which may be subject to compiler transformation.
  12914. The ``llvm.preserve.access.index`` type of metadata is attached to this call instruction
  12915. to provide array or pointer debuginfo type.
  12916. The metadata is a ``DICompositeType`` or ``DIDerivedType`` representing the
  12917. debuginfo version of ``type``.
  12918. Arguments:
  12919. """"""""""
  12920. The ``base`` is the array base address. The ``dim`` is the array dimension.
  12921. The ``base`` is a pointer if ``dim`` equals 0.
  12922. The ``index`` is the last access index into the array or pointer.
  12923. Semantics:
  12924. """"""""""
  12925. The '``llvm.preserve.array.access.index``' intrinsic produces the same result
  12926. as a getelementptr with base ``base`` and access operands ``{dim's 0's, index}``.
  12927. '``llvm.preserve.union.access.index``' Intrinsic
  12928. ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  12929. Syntax:
  12930. """""""
  12931. ::
  12932. declare <type>
  12933. @llvm.preserve.union.access.index.p0s_union.anons.p0s_union.anons(<type> base,
  12934. i32 di_index)
  12935. Overview:
  12936. """""""""
  12937. The '``llvm.preserve.union.access.index``' intrinsic carries the debuginfo field index
  12938. ``di_index`` and returns the ``base`` address.
  12939. The ``llvm.preserve.access.index`` type of metadata is attached to this call instruction
  12940. to provide union debuginfo type.
  12941. The metadata is a ``DICompositeType`` representing the debuginfo version of ``type``.
  12942. The return type ``type`` is the same as the ``base`` type.
  12943. Arguments:
  12944. """"""""""
  12945. The ``base`` is the union base address. The ``di_index`` is the field index in debuginfo.
  12946. Semantics:
  12947. """"""""""
  12948. The '``llvm.preserve.union.access.index``' intrinsic returns the ``base`` address.
  12949. '``llvm.preserve.struct.access.index``' Intrinsic
  12950. ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  12951. Syntax:
  12952. """""""
  12953. ::
  12954. declare <ret_type>
  12955. @llvm.preserve.struct.access.index.p0i8.p0s_struct.anon.0s(<type> base,
  12956. i32 gep_index,
  12957. i32 di_index)
  12958. Overview:
  12959. """""""""
  12960. The '``llvm.preserve.struct.access.index``' intrinsic returns the getelementptr address
  12961. based on struct base ``base`` and IR struct member index ``gep_index``.
  12962. The ``llvm.preserve.access.index`` type of metadata is attached to this call instruction
  12963. to provide struct debuginfo type.
  12964. The metadata is a ``DICompositeType`` representing the debuginfo version of ``type``.
  12965. The return type ``ret_type`` is a pointer type to the structure member.
  12966. Arguments:
  12967. """"""""""
  12968. The ``base`` is the structure base address. The ``gep_index`` is the struct member index
  12969. based on IR structures. The ``di_index`` is the struct member index based on debuginfo.
  12970. Semantics:
  12971. """"""""""
  12972. The '``llvm.preserve.struct.access.index``' intrinsic produces the same result
  12973. as a getelementptr with base ``base`` and access operands ``{0, gep_index}``.