LangRef.rst 628 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602260326042605260626072608260926102611261226132614261526162617261826192620262126222623262426252626262726282629263026312632263326342635263626372638263926402641264226432644264526462647264826492650265126522653265426552656265726582659266026612662266326642665266626672668266926702671267226732674267526762677267826792680268126822683268426852686268726882689269026912692269326942695269626972698269927002701270227032704270527062707270827092710271127122713271427152716271727182719272027212722272327242725272627272728272927302731273227332734273527362737273827392740274127422743274427452746274727482749275027512752275327542755275627572758275927602761276227632764276527662767276827692770277127722773277427752776277727782779278027812782278327842785278627872788278927902791279227932794279527962797279827992800280128022803280428052806280728082809281028112812281328142815281628172818281928202821282228232824282528262827282828292830283128322833283428352836283728382839284028412842284328442845284628472848284928502851285228532854285528562857285828592860286128622863286428652866286728682869287028712872287328742875287628772878287928802881288228832884288528862887288828892890289128922893289428952896289728982899290029012902290329042905290629072908290929102911291229132914291529162917291829192920292129222923292429252926292729282929293029312932293329342935293629372938293929402941294229432944294529462947294829492950295129522953295429552956295729582959296029612962296329642965296629672968296929702971297229732974297529762977297829792980298129822983298429852986298729882989299029912992299329942995299629972998299930003001300230033004300530063007300830093010301130123013301430153016301730183019302030213022302330243025302630273028302930303031303230333034303530363037303830393040304130423043304430453046304730483049305030513052305330543055305630573058305930603061306230633064306530663067306830693070307130723073307430753076307730783079308030813082308330843085308630873088308930903091309230933094309530963097309830993100310131023103310431053106310731083109311031113112311331143115311631173118311931203121312231233124312531263127312831293130313131323133313431353136313731383139314031413142314331443145314631473148314931503151315231533154315531563157315831593160316131623163316431653166316731683169317031713172317331743175317631773178317931803181318231833184318531863187318831893190319131923193319431953196319731983199320032013202320332043205320632073208320932103211321232133214321532163217321832193220322132223223322432253226322732283229323032313232323332343235323632373238323932403241324232433244324532463247324832493250325132523253325432553256325732583259326032613262326332643265326632673268326932703271327232733274327532763277327832793280328132823283328432853286328732883289329032913292329332943295329632973298329933003301330233033304330533063307330833093310331133123313331433153316331733183319332033213322332333243325332633273328332933303331333233333334333533363337333833393340334133423343334433453346334733483349335033513352335333543355335633573358335933603361336233633364336533663367336833693370337133723373337433753376337733783379338033813382338333843385338633873388338933903391339233933394339533963397339833993400340134023403340434053406340734083409341034113412341334143415341634173418341934203421342234233424342534263427342834293430343134323433343434353436343734383439344034413442344334443445344634473448344934503451345234533454345534563457345834593460346134623463346434653466346734683469347034713472347334743475347634773478347934803481348234833484348534863487348834893490349134923493349434953496349734983499350035013502350335043505350635073508350935103511351235133514351535163517351835193520352135223523352435253526352735283529353035313532353335343535353635373538353935403541354235433544354535463547354835493550355135523553355435553556355735583559356035613562356335643565356635673568356935703571357235733574357535763577357835793580358135823583358435853586358735883589359035913592359335943595359635973598359936003601360236033604360536063607360836093610361136123613361436153616361736183619362036213622362336243625362636273628362936303631363236333634363536363637363836393640364136423643364436453646364736483649365036513652365336543655365636573658365936603661366236633664366536663667366836693670367136723673367436753676367736783679368036813682368336843685368636873688368936903691369236933694369536963697369836993700370137023703370437053706370737083709371037113712371337143715371637173718371937203721372237233724372537263727372837293730373137323733373437353736373737383739374037413742374337443745374637473748374937503751375237533754375537563757375837593760376137623763376437653766376737683769377037713772377337743775377637773778377937803781378237833784378537863787378837893790379137923793379437953796379737983799380038013802380338043805380638073808380938103811381238133814381538163817381838193820382138223823382438253826382738283829383038313832383338343835383638373838383938403841384238433844384538463847384838493850385138523853385438553856385738583859386038613862386338643865386638673868386938703871387238733874387538763877387838793880388138823883388438853886388738883889389038913892389338943895389638973898389939003901390239033904390539063907390839093910391139123913391439153916391739183919392039213922392339243925392639273928392939303931393239333934393539363937393839393940394139423943394439453946394739483949395039513952395339543955395639573958395939603961396239633964396539663967396839693970397139723973397439753976397739783979398039813982398339843985398639873988398939903991399239933994399539963997399839994000400140024003400440054006400740084009401040114012401340144015401640174018401940204021402240234024402540264027402840294030403140324033403440354036403740384039404040414042404340444045404640474048404940504051405240534054405540564057405840594060406140624063406440654066406740684069407040714072407340744075407640774078407940804081408240834084408540864087408840894090409140924093409440954096409740984099410041014102410341044105410641074108410941104111411241134114411541164117411841194120412141224123412441254126412741284129413041314132413341344135413641374138413941404141414241434144414541464147414841494150415141524153415441554156415741584159416041614162416341644165416641674168416941704171417241734174417541764177417841794180418141824183418441854186418741884189419041914192419341944195419641974198419942004201420242034204420542064207420842094210421142124213421442154216421742184219422042214222422342244225422642274228422942304231423242334234423542364237423842394240424142424243424442454246424742484249425042514252425342544255425642574258425942604261426242634264426542664267426842694270427142724273427442754276427742784279428042814282428342844285428642874288428942904291429242934294429542964297429842994300430143024303430443054306430743084309431043114312431343144315431643174318431943204321432243234324432543264327432843294330433143324333433443354336433743384339434043414342434343444345434643474348434943504351435243534354435543564357435843594360436143624363436443654366436743684369437043714372437343744375437643774378437943804381438243834384438543864387438843894390439143924393439443954396439743984399440044014402440344044405440644074408440944104411441244134414441544164417441844194420442144224423442444254426442744284429443044314432443344344435443644374438443944404441444244434444444544464447444844494450445144524453445444554456445744584459446044614462446344644465446644674468446944704471447244734474447544764477447844794480448144824483448444854486448744884489449044914492449344944495449644974498449945004501450245034504450545064507450845094510451145124513451445154516451745184519452045214522452345244525452645274528452945304531453245334534453545364537453845394540454145424543454445454546454745484549455045514552455345544555455645574558455945604561456245634564456545664567456845694570457145724573457445754576457745784579458045814582458345844585458645874588458945904591459245934594459545964597459845994600460146024603460446054606460746084609461046114612461346144615461646174618461946204621462246234624462546264627462846294630463146324633463446354636463746384639464046414642464346444645464646474648464946504651465246534654465546564657465846594660466146624663466446654666466746684669467046714672467346744675467646774678467946804681468246834684468546864687468846894690469146924693469446954696469746984699470047014702470347044705470647074708470947104711471247134714471547164717471847194720472147224723472447254726472747284729473047314732473347344735473647374738473947404741474247434744474547464747474847494750475147524753475447554756475747584759476047614762476347644765476647674768476947704771477247734774477547764777477847794780478147824783478447854786478747884789479047914792479347944795479647974798479948004801480248034804480548064807480848094810481148124813481448154816481748184819482048214822482348244825482648274828482948304831483248334834483548364837483848394840484148424843484448454846484748484849485048514852485348544855485648574858485948604861486248634864486548664867486848694870487148724873487448754876487748784879488048814882488348844885488648874888488948904891489248934894489548964897489848994900490149024903490449054906490749084909491049114912491349144915491649174918491949204921492249234924492549264927492849294930493149324933493449354936493749384939494049414942494349444945494649474948494949504951495249534954495549564957495849594960496149624963496449654966496749684969497049714972497349744975497649774978497949804981498249834984498549864987498849894990499149924993499449954996499749984999500050015002500350045005500650075008500950105011501250135014501550165017501850195020502150225023502450255026502750285029503050315032503350345035503650375038503950405041504250435044504550465047504850495050505150525053505450555056505750585059506050615062506350645065506650675068506950705071507250735074507550765077507850795080508150825083508450855086508750885089509050915092509350945095509650975098509951005101510251035104510551065107510851095110511151125113511451155116511751185119512051215122512351245125512651275128512951305131513251335134513551365137513851395140514151425143514451455146514751485149515051515152515351545155515651575158515951605161516251635164516551665167516851695170517151725173517451755176517751785179518051815182518351845185518651875188518951905191519251935194519551965197519851995200520152025203520452055206520752085209521052115212521352145215521652175218521952205221522252235224522552265227522852295230523152325233523452355236523752385239524052415242524352445245524652475248524952505251525252535254525552565257525852595260526152625263526452655266526752685269527052715272527352745275527652775278527952805281528252835284528552865287528852895290529152925293529452955296529752985299530053015302530353045305530653075308530953105311531253135314531553165317531853195320532153225323532453255326532753285329533053315332533353345335533653375338533953405341534253435344534553465347534853495350535153525353535453555356535753585359536053615362536353645365536653675368536953705371537253735374537553765377537853795380538153825383538453855386538753885389539053915392539353945395539653975398539954005401540254035404540554065407540854095410541154125413541454155416541754185419542054215422542354245425542654275428542954305431543254335434543554365437543854395440544154425443544454455446544754485449545054515452545354545455545654575458545954605461546254635464546554665467546854695470547154725473547454755476547754785479548054815482548354845485548654875488548954905491549254935494549554965497549854995500550155025503550455055506550755085509551055115512551355145515551655175518551955205521552255235524552555265527552855295530553155325533553455355536553755385539554055415542554355445545554655475548554955505551555255535554555555565557555855595560556155625563556455655566556755685569557055715572557355745575557655775578557955805581558255835584558555865587558855895590559155925593559455955596559755985599560056015602560356045605560656075608560956105611561256135614561556165617561856195620562156225623562456255626562756285629563056315632563356345635563656375638563956405641564256435644564556465647564856495650565156525653565456555656565756585659566056615662566356645665566656675668566956705671567256735674567556765677567856795680568156825683568456855686568756885689569056915692569356945695569656975698569957005701570257035704570557065707570857095710571157125713571457155716571757185719572057215722572357245725572657275728572957305731573257335734573557365737573857395740574157425743574457455746574757485749575057515752575357545755575657575758575957605761576257635764576557665767576857695770577157725773577457755776577757785779578057815782578357845785578657875788578957905791579257935794579557965797579857995800580158025803580458055806580758085809581058115812581358145815581658175818581958205821582258235824582558265827582858295830583158325833583458355836583758385839584058415842584358445845584658475848584958505851585258535854585558565857585858595860586158625863586458655866586758685869587058715872587358745875587658775878587958805881588258835884588558865887588858895890589158925893589458955896589758985899590059015902590359045905590659075908590959105911591259135914591559165917591859195920592159225923592459255926592759285929593059315932593359345935593659375938593959405941594259435944594559465947594859495950595159525953595459555956595759585959596059615962596359645965596659675968596959705971597259735974597559765977597859795980598159825983598459855986598759885989599059915992599359945995599659975998599960006001600260036004600560066007600860096010601160126013601460156016601760186019602060216022602360246025602660276028602960306031603260336034603560366037603860396040604160426043604460456046604760486049605060516052605360546055605660576058605960606061606260636064606560666067606860696070607160726073607460756076607760786079608060816082608360846085608660876088608960906091609260936094609560966097609860996100610161026103610461056106610761086109611061116112611361146115611661176118611961206121612261236124612561266127612861296130613161326133613461356136613761386139614061416142614361446145614661476148614961506151615261536154615561566157615861596160616161626163616461656166616761686169617061716172617361746175617661776178617961806181618261836184618561866187618861896190619161926193619461956196619761986199620062016202620362046205620662076208620962106211621262136214621562166217621862196220622162226223622462256226622762286229623062316232623362346235623662376238623962406241624262436244624562466247624862496250625162526253625462556256625762586259626062616262626362646265626662676268626962706271627262736274627562766277627862796280628162826283628462856286628762886289629062916292629362946295629662976298629963006301630263036304630563066307630863096310631163126313631463156316631763186319632063216322632363246325632663276328632963306331633263336334633563366337633863396340634163426343634463456346634763486349635063516352635363546355635663576358635963606361636263636364636563666367636863696370637163726373637463756376637763786379638063816382638363846385638663876388638963906391639263936394639563966397639863996400640164026403640464056406640764086409641064116412641364146415641664176418641964206421642264236424642564266427642864296430643164326433643464356436643764386439644064416442644364446445644664476448644964506451645264536454645564566457645864596460646164626463646464656466646764686469647064716472647364746475647664776478647964806481648264836484648564866487648864896490649164926493649464956496649764986499650065016502650365046505650665076508650965106511651265136514651565166517651865196520652165226523652465256526652765286529653065316532653365346535653665376538653965406541654265436544654565466547654865496550655165526553655465556556655765586559656065616562656365646565656665676568656965706571657265736574657565766577657865796580658165826583658465856586658765886589659065916592659365946595659665976598659966006601660266036604660566066607660866096610661166126613661466156616661766186619662066216622662366246625662666276628662966306631663266336634663566366637663866396640664166426643664466456646664766486649665066516652665366546655665666576658665966606661666266636664666566666667666866696670667166726673667466756676667766786679668066816682668366846685668666876688668966906691669266936694669566966697669866996700670167026703670467056706670767086709671067116712671367146715671667176718671967206721672267236724672567266727672867296730673167326733673467356736673767386739674067416742674367446745674667476748674967506751675267536754675567566757675867596760676167626763676467656766676767686769677067716772677367746775677667776778677967806781678267836784678567866787678867896790679167926793679467956796679767986799680068016802680368046805680668076808680968106811681268136814681568166817681868196820682168226823682468256826682768286829683068316832683368346835683668376838683968406841684268436844684568466847684868496850685168526853685468556856685768586859686068616862686368646865686668676868686968706871687268736874687568766877687868796880688168826883688468856886688768886889689068916892689368946895689668976898689969006901690269036904690569066907690869096910691169126913691469156916691769186919692069216922692369246925692669276928692969306931693269336934693569366937693869396940694169426943694469456946694769486949695069516952695369546955695669576958695969606961696269636964696569666967696869696970697169726973697469756976697769786979698069816982698369846985698669876988698969906991699269936994699569966997699869997000700170027003700470057006700770087009701070117012701370147015701670177018701970207021702270237024702570267027702870297030703170327033703470357036703770387039704070417042704370447045704670477048704970507051705270537054705570567057705870597060706170627063706470657066706770687069707070717072707370747075707670777078707970807081708270837084708570867087708870897090709170927093709470957096709770987099710071017102710371047105710671077108710971107111711271137114711571167117711871197120712171227123712471257126712771287129713071317132713371347135713671377138713971407141714271437144714571467147714871497150715171527153715471557156715771587159716071617162716371647165716671677168716971707171717271737174717571767177717871797180718171827183718471857186718771887189719071917192719371947195719671977198719972007201720272037204720572067207720872097210721172127213721472157216721772187219722072217222722372247225722672277228722972307231723272337234723572367237723872397240724172427243724472457246724772487249725072517252725372547255725672577258725972607261726272637264726572667267726872697270727172727273727472757276727772787279728072817282728372847285728672877288728972907291729272937294729572967297729872997300730173027303730473057306730773087309731073117312731373147315731673177318731973207321732273237324732573267327732873297330733173327333733473357336733773387339734073417342734373447345734673477348734973507351735273537354735573567357735873597360736173627363736473657366736773687369737073717372737373747375737673777378737973807381738273837384738573867387738873897390739173927393739473957396739773987399740074017402740374047405740674077408740974107411741274137414741574167417741874197420742174227423742474257426742774287429743074317432743374347435743674377438743974407441744274437444744574467447744874497450745174527453745474557456745774587459746074617462746374647465746674677468746974707471747274737474747574767477747874797480748174827483748474857486748774887489749074917492749374947495749674977498749975007501750275037504750575067507750875097510751175127513751475157516751775187519752075217522752375247525752675277528752975307531753275337534753575367537753875397540754175427543754475457546754775487549755075517552755375547555755675577558755975607561756275637564756575667567756875697570757175727573757475757576757775787579758075817582758375847585758675877588758975907591759275937594759575967597759875997600760176027603760476057606760776087609761076117612761376147615761676177618761976207621762276237624762576267627762876297630763176327633763476357636763776387639764076417642764376447645764676477648764976507651765276537654765576567657765876597660766176627663766476657666766776687669767076717672767376747675767676777678767976807681768276837684768576867687768876897690769176927693769476957696769776987699770077017702770377047705770677077708770977107711771277137714771577167717771877197720772177227723772477257726772777287729773077317732773377347735773677377738773977407741774277437744774577467747774877497750775177527753775477557756775777587759776077617762776377647765776677677768776977707771777277737774777577767777777877797780778177827783778477857786778777887789779077917792779377947795779677977798779978007801780278037804780578067807780878097810781178127813781478157816781778187819782078217822782378247825782678277828782978307831783278337834783578367837783878397840784178427843784478457846784778487849785078517852785378547855785678577858785978607861786278637864786578667867786878697870787178727873787478757876787778787879788078817882788378847885788678877888788978907891789278937894789578967897789878997900790179027903790479057906790779087909791079117912791379147915791679177918791979207921792279237924792579267927792879297930793179327933793479357936793779387939794079417942794379447945794679477948794979507951795279537954795579567957795879597960796179627963796479657966796779687969797079717972797379747975797679777978797979807981798279837984798579867987798879897990799179927993799479957996799779987999800080018002800380048005800680078008800980108011801280138014801580168017801880198020802180228023802480258026802780288029803080318032803380348035803680378038803980408041804280438044804580468047804880498050805180528053805480558056805780588059806080618062806380648065806680678068806980708071807280738074807580768077807880798080808180828083808480858086808780888089809080918092809380948095809680978098809981008101810281038104810581068107810881098110811181128113811481158116811781188119812081218122812381248125812681278128812981308131813281338134813581368137813881398140814181428143814481458146814781488149815081518152815381548155815681578158815981608161816281638164816581668167816881698170817181728173817481758176817781788179818081818182818381848185818681878188818981908191819281938194819581968197819881998200820182028203820482058206820782088209821082118212821382148215821682178218821982208221822282238224822582268227822882298230823182328233823482358236823782388239824082418242824382448245824682478248824982508251825282538254825582568257825882598260826182628263826482658266826782688269827082718272827382748275827682778278827982808281828282838284828582868287828882898290829182928293829482958296829782988299830083018302830383048305830683078308830983108311831283138314831583168317831883198320832183228323832483258326832783288329833083318332833383348335833683378338833983408341834283438344834583468347834883498350835183528353835483558356835783588359836083618362836383648365836683678368836983708371837283738374837583768377837883798380838183828383838483858386838783888389839083918392839383948395839683978398839984008401840284038404840584068407840884098410841184128413841484158416841784188419842084218422842384248425842684278428842984308431843284338434843584368437843884398440844184428443844484458446844784488449845084518452845384548455845684578458845984608461846284638464846584668467846884698470847184728473847484758476847784788479848084818482848384848485848684878488848984908491849284938494849584968497849884998500850185028503850485058506850785088509851085118512851385148515851685178518851985208521852285238524852585268527852885298530853185328533853485358536853785388539854085418542854385448545854685478548854985508551855285538554855585568557855885598560856185628563856485658566856785688569857085718572857385748575857685778578857985808581858285838584858585868587858885898590859185928593859485958596859785988599860086018602860386048605860686078608860986108611861286138614861586168617861886198620862186228623862486258626862786288629863086318632863386348635863686378638863986408641864286438644864586468647864886498650865186528653865486558656865786588659866086618662866386648665866686678668866986708671867286738674867586768677867886798680868186828683868486858686868786888689869086918692869386948695869686978698869987008701870287038704870587068707870887098710871187128713871487158716871787188719872087218722872387248725872687278728872987308731873287338734873587368737873887398740874187428743874487458746874787488749875087518752875387548755875687578758875987608761876287638764876587668767876887698770877187728773877487758776877787788779878087818782878387848785878687878788878987908791879287938794879587968797879887998800880188028803880488058806880788088809881088118812881388148815881688178818881988208821882288238824882588268827882888298830883188328833883488358836883788388839884088418842884388448845884688478848884988508851885288538854885588568857885888598860886188628863886488658866886788688869887088718872887388748875887688778878887988808881888288838884888588868887888888898890889188928893889488958896889788988899890089018902890389048905890689078908890989108911891289138914891589168917891889198920892189228923892489258926892789288929893089318932893389348935893689378938893989408941894289438944894589468947894889498950895189528953895489558956895789588959896089618962896389648965896689678968896989708971897289738974897589768977897889798980898189828983898489858986898789888989899089918992899389948995899689978998899990009001900290039004900590069007900890099010901190129013901490159016901790189019902090219022902390249025902690279028902990309031903290339034903590369037903890399040904190429043904490459046904790489049905090519052905390549055905690579058905990609061906290639064906590669067906890699070907190729073907490759076907790789079908090819082908390849085908690879088908990909091909290939094909590969097909890999100910191029103910491059106910791089109911091119112911391149115911691179118911991209121912291239124912591269127912891299130913191329133913491359136913791389139914091419142914391449145914691479148914991509151915291539154915591569157915891599160916191629163916491659166916791689169917091719172917391749175917691779178917991809181918291839184918591869187918891899190919191929193919491959196919791989199920092019202920392049205920692079208920992109211921292139214921592169217921892199220922192229223922492259226922792289229923092319232923392349235923692379238923992409241924292439244924592469247924892499250925192529253925492559256925792589259926092619262926392649265926692679268926992709271927292739274927592769277927892799280928192829283928492859286928792889289929092919292929392949295929692979298929993009301930293039304930593069307930893099310931193129313931493159316931793189319932093219322932393249325932693279328932993309331933293339334933593369337933893399340934193429343934493459346934793489349935093519352935393549355935693579358935993609361936293639364936593669367936893699370937193729373937493759376937793789379938093819382938393849385938693879388938993909391939293939394939593969397939893999400940194029403940494059406940794089409941094119412941394149415941694179418941994209421942294239424942594269427942894299430943194329433943494359436943794389439944094419442944394449445944694479448944994509451945294539454945594569457945894599460946194629463946494659466946794689469947094719472947394749475947694779478947994809481948294839484948594869487948894899490949194929493949494959496949794989499950095019502950395049505950695079508950995109511951295139514951595169517951895199520952195229523952495259526952795289529953095319532953395349535953695379538953995409541954295439544954595469547954895499550955195529553955495559556955795589559956095619562956395649565956695679568956995709571957295739574957595769577957895799580958195829583958495859586958795889589959095919592959395949595959695979598959996009601960296039604960596069607960896099610961196129613961496159616961796189619962096219622962396249625962696279628962996309631963296339634963596369637963896399640964196429643964496459646964796489649965096519652965396549655965696579658965996609661966296639664966596669667966896699670967196729673967496759676967796789679968096819682968396849685968696879688968996909691969296939694969596969697969896999700970197029703970497059706970797089709971097119712971397149715971697179718971997209721972297239724972597269727972897299730973197329733973497359736973797389739974097419742974397449745974697479748974997509751975297539754975597569757975897599760976197629763976497659766976797689769977097719772977397749775977697779778977997809781978297839784978597869787978897899790979197929793979497959796979797989799980098019802980398049805980698079808980998109811981298139814981598169817981898199820982198229823982498259826982798289829983098319832983398349835983698379838983998409841984298439844984598469847984898499850985198529853985498559856985798589859986098619862986398649865986698679868986998709871987298739874987598769877987898799880988198829883988498859886988798889889989098919892989398949895989698979898989999009901990299039904990599069907990899099910991199129913991499159916991799189919992099219922992399249925992699279928992999309931993299339934993599369937993899399940994199429943994499459946994799489949995099519952995399549955995699579958995999609961996299639964996599669967996899699970997199729973997499759976997799789979998099819982998399849985998699879988998999909991999299939994999599969997999899991000010001100021000310004100051000610007100081000910010100111001210013100141001510016100171001810019100201002110022100231002410025100261002710028100291003010031100321003310034100351003610037100381003910040100411004210043100441004510046100471004810049100501005110052100531005410055100561005710058100591006010061100621006310064100651006610067100681006910070100711007210073100741007510076100771007810079100801008110082100831008410085100861008710088100891009010091100921009310094100951009610097100981009910100101011010210103101041010510106101071010810109101101011110112101131011410115101161011710118101191012010121101221012310124101251012610127101281012910130101311013210133101341013510136101371013810139101401014110142101431014410145101461014710148101491015010151101521015310154101551015610157101581015910160101611016210163101641016510166101671016810169101701017110172101731017410175101761017710178101791018010181101821018310184101851018610187101881018910190101911019210193101941019510196101971019810199102001020110202102031020410205102061020710208102091021010211102121021310214102151021610217102181021910220102211022210223102241022510226102271022810229102301023110232102331023410235102361023710238102391024010241102421024310244102451024610247102481024910250102511025210253102541025510256102571025810259102601026110262102631026410265102661026710268102691027010271102721027310274102751027610277102781027910280102811028210283102841028510286102871028810289102901029110292102931029410295102961029710298102991030010301103021030310304103051030610307103081030910310103111031210313103141031510316103171031810319103201032110322103231032410325103261032710328103291033010331103321033310334103351033610337103381033910340103411034210343103441034510346103471034810349103501035110352103531035410355103561035710358103591036010361103621036310364103651036610367103681036910370103711037210373103741037510376103771037810379103801038110382103831038410385103861038710388103891039010391103921039310394103951039610397103981039910400104011040210403104041040510406104071040810409104101041110412104131041410415104161041710418104191042010421104221042310424104251042610427104281042910430104311043210433104341043510436104371043810439104401044110442104431044410445104461044710448104491045010451104521045310454104551045610457104581045910460104611046210463104641046510466104671046810469104701047110472104731047410475104761047710478104791048010481104821048310484104851048610487104881048910490104911049210493104941049510496104971049810499105001050110502105031050410505105061050710508105091051010511105121051310514105151051610517105181051910520105211052210523105241052510526105271052810529105301053110532105331053410535105361053710538105391054010541105421054310544105451054610547105481054910550105511055210553105541055510556105571055810559105601056110562105631056410565105661056710568105691057010571105721057310574105751057610577105781057910580105811058210583105841058510586105871058810589105901059110592105931059410595105961059710598105991060010601106021060310604106051060610607106081060910610106111061210613106141061510616106171061810619106201062110622106231062410625106261062710628106291063010631106321063310634106351063610637106381063910640106411064210643106441064510646106471064810649106501065110652106531065410655106561065710658106591066010661106621066310664106651066610667106681066910670106711067210673106741067510676106771067810679106801068110682106831068410685106861068710688106891069010691106921069310694106951069610697106981069910700107011070210703107041070510706107071070810709107101071110712107131071410715107161071710718107191072010721107221072310724107251072610727107281072910730107311073210733107341073510736107371073810739107401074110742107431074410745107461074710748107491075010751107521075310754107551075610757107581075910760107611076210763107641076510766107671076810769107701077110772107731077410775107761077710778107791078010781107821078310784107851078610787107881078910790107911079210793107941079510796107971079810799108001080110802108031080410805108061080710808108091081010811108121081310814108151081610817108181081910820108211082210823108241082510826108271082810829108301083110832108331083410835108361083710838108391084010841108421084310844108451084610847108481084910850108511085210853108541085510856108571085810859108601086110862108631086410865108661086710868108691087010871108721087310874108751087610877108781087910880108811088210883108841088510886108871088810889108901089110892108931089410895108961089710898108991090010901109021090310904109051090610907109081090910910109111091210913109141091510916109171091810919109201092110922109231092410925109261092710928109291093010931109321093310934109351093610937109381093910940109411094210943109441094510946109471094810949109501095110952109531095410955109561095710958109591096010961109621096310964109651096610967109681096910970109711097210973109741097510976109771097810979109801098110982109831098410985109861098710988109891099010991109921099310994109951099610997109981099911000110011100211003110041100511006110071100811009110101101111012110131101411015110161101711018110191102011021110221102311024110251102611027110281102911030110311103211033110341103511036110371103811039110401104111042110431104411045110461104711048110491105011051110521105311054110551105611057110581105911060110611106211063110641106511066110671106811069110701107111072110731107411075110761107711078110791108011081110821108311084110851108611087110881108911090110911109211093110941109511096110971109811099111001110111102111031110411105111061110711108111091111011111111121111311114111151111611117111181111911120111211112211123111241112511126111271112811129111301113111132111331113411135111361113711138111391114011141111421114311144111451114611147111481114911150111511115211153111541115511156111571115811159111601116111162111631116411165111661116711168111691117011171111721117311174111751117611177111781117911180111811118211183111841118511186111871118811189111901119111192111931119411195111961119711198111991120011201112021120311204112051120611207112081120911210112111121211213112141121511216112171121811219112201122111222112231122411225112261122711228112291123011231112321123311234112351123611237112381123911240112411124211243112441124511246112471124811249112501125111252112531125411255112561125711258112591126011261112621126311264112651126611267112681126911270112711127211273112741127511276112771127811279112801128111282112831128411285112861128711288112891129011291112921129311294112951129611297112981129911300113011130211303113041130511306113071130811309113101131111312113131131411315113161131711318113191132011321113221132311324113251132611327113281132911330113311133211333113341133511336113371133811339113401134111342113431134411345113461134711348113491135011351113521135311354113551135611357113581135911360113611136211363113641136511366113671136811369113701137111372113731137411375113761137711378113791138011381113821138311384113851138611387113881138911390113911139211393113941139511396113971139811399114001140111402114031140411405114061140711408114091141011411114121141311414114151141611417114181141911420114211142211423114241142511426114271142811429114301143111432114331143411435114361143711438114391144011441114421144311444114451144611447114481144911450114511145211453114541145511456114571145811459114601146111462114631146411465114661146711468114691147011471114721147311474114751147611477114781147911480114811148211483114841148511486114871148811489114901149111492114931149411495114961149711498114991150011501115021150311504115051150611507115081150911510115111151211513115141151511516115171151811519115201152111522115231152411525115261152711528115291153011531115321153311534115351153611537115381153911540115411154211543115441154511546115471154811549115501155111552115531155411555115561155711558115591156011561115621156311564115651156611567115681156911570115711157211573115741157511576115771157811579115801158111582115831158411585115861158711588115891159011591115921159311594115951159611597115981159911600116011160211603116041160511606116071160811609116101161111612116131161411615116161161711618116191162011621116221162311624116251162611627116281162911630116311163211633116341163511636116371163811639116401164111642116431164411645116461164711648116491165011651116521165311654116551165611657116581165911660116611166211663116641166511666116671166811669116701167111672116731167411675116761167711678116791168011681116821168311684116851168611687116881168911690116911169211693116941169511696116971169811699117001170111702117031170411705117061170711708117091171011711117121171311714117151171611717117181171911720117211172211723117241172511726117271172811729117301173111732117331173411735117361173711738117391174011741117421174311744117451174611747117481174911750117511175211753117541175511756117571175811759117601176111762117631176411765117661176711768117691177011771117721177311774117751177611777117781177911780117811178211783117841178511786117871178811789117901179111792117931179411795117961179711798117991180011801118021180311804118051180611807118081180911810118111181211813118141181511816118171181811819118201182111822118231182411825118261182711828118291183011831118321183311834118351183611837118381183911840118411184211843118441184511846118471184811849118501185111852118531185411855118561185711858118591186011861118621186311864118651186611867118681186911870118711187211873118741187511876118771187811879118801188111882118831188411885118861188711888118891189011891118921189311894118951189611897118981189911900119011190211903119041190511906119071190811909119101191111912119131191411915119161191711918119191192011921119221192311924119251192611927119281192911930119311193211933119341193511936119371193811939119401194111942119431194411945119461194711948119491195011951119521195311954119551195611957119581195911960119611196211963119641196511966119671196811969119701197111972119731197411975119761197711978119791198011981119821198311984119851198611987119881198911990119911199211993119941199511996119971199811999120001200112002120031200412005120061200712008120091201012011120121201312014120151201612017120181201912020120211202212023120241202512026120271202812029120301203112032120331203412035120361203712038120391204012041120421204312044120451204612047120481204912050120511205212053120541205512056120571205812059120601206112062120631206412065120661206712068120691207012071120721207312074120751207612077120781207912080120811208212083120841208512086120871208812089120901209112092120931209412095120961209712098120991210012101121021210312104121051210612107121081210912110121111211212113121141211512116121171211812119121201212112122121231212412125121261212712128121291213012131121321213312134121351213612137121381213912140121411214212143121441214512146121471214812149121501215112152121531215412155121561215712158121591216012161121621216312164121651216612167121681216912170121711217212173121741217512176121771217812179121801218112182121831218412185121861218712188121891219012191121921219312194121951219612197121981219912200122011220212203122041220512206122071220812209122101221112212122131221412215122161221712218122191222012221122221222312224122251222612227122281222912230122311223212233122341223512236122371223812239122401224112242122431224412245122461224712248122491225012251122521225312254122551225612257122581225912260122611226212263122641226512266122671226812269122701227112272122731227412275122761227712278122791228012281122821228312284122851228612287122881228912290122911229212293122941229512296122971229812299123001230112302123031230412305123061230712308123091231012311123121231312314123151231612317123181231912320123211232212323123241232512326123271232812329123301233112332123331233412335123361233712338123391234012341123421234312344123451234612347123481234912350123511235212353123541235512356123571235812359123601236112362123631236412365123661236712368123691237012371123721237312374123751237612377123781237912380123811238212383123841238512386123871238812389123901239112392123931239412395123961239712398123991240012401124021240312404124051240612407124081240912410124111241212413124141241512416124171241812419124201242112422124231242412425124261242712428124291243012431124321243312434124351243612437124381243912440124411244212443124441244512446124471244812449124501245112452124531245412455124561245712458124591246012461124621246312464124651246612467124681246912470124711247212473124741247512476124771247812479124801248112482124831248412485124861248712488124891249012491124921249312494124951249612497124981249912500125011250212503125041250512506125071250812509125101251112512125131251412515125161251712518125191252012521125221252312524125251252612527125281252912530125311253212533125341253512536125371253812539125401254112542125431254412545125461254712548125491255012551125521255312554125551255612557125581255912560125611256212563125641256512566125671256812569125701257112572125731257412575125761257712578125791258012581125821258312584125851258612587125881258912590125911259212593125941259512596125971259812599126001260112602126031260412605126061260712608126091261012611126121261312614126151261612617126181261912620126211262212623126241262512626126271262812629126301263112632126331263412635126361263712638126391264012641126421264312644126451264612647126481264912650126511265212653126541265512656126571265812659126601266112662126631266412665126661266712668126691267012671126721267312674126751267612677126781267912680126811268212683126841268512686126871268812689126901269112692126931269412695126961269712698126991270012701127021270312704127051270612707127081270912710127111271212713127141271512716127171271812719127201272112722127231272412725127261272712728127291273012731127321273312734127351273612737127381273912740127411274212743127441274512746127471274812749127501275112752127531275412755127561275712758127591276012761127621276312764127651276612767127681276912770127711277212773127741277512776127771277812779127801278112782127831278412785127861278712788127891279012791127921279312794127951279612797127981279912800128011280212803128041280512806128071280812809128101281112812128131281412815128161281712818128191282012821128221282312824128251282612827128281282912830128311283212833128341283512836128371283812839128401284112842128431284412845128461284712848128491285012851128521285312854128551285612857128581285912860128611286212863128641286512866128671286812869128701287112872128731287412875128761287712878128791288012881128821288312884128851288612887128881288912890128911289212893128941289512896128971289812899129001290112902129031290412905129061290712908129091291012911129121291312914129151291612917129181291912920129211292212923129241292512926129271292812929129301293112932129331293412935129361293712938129391294012941129421294312944129451294612947129481294912950129511295212953129541295512956129571295812959129601296112962129631296412965129661296712968129691297012971129721297312974129751297612977129781297912980129811298212983129841298512986129871298812989129901299112992129931299412995129961299712998129991300013001130021300313004130051300613007130081300913010130111301213013130141301513016130171301813019130201302113022130231302413025130261302713028130291303013031130321303313034130351303613037130381303913040130411304213043130441304513046130471304813049130501305113052130531305413055130561305713058130591306013061130621306313064130651306613067130681306913070130711307213073130741307513076130771307813079130801308113082130831308413085130861308713088130891309013091130921309313094130951309613097130981309913100131011310213103131041310513106131071310813109131101311113112131131311413115131161311713118131191312013121131221312313124131251312613127131281312913130131311313213133131341313513136131371313813139131401314113142131431314413145131461314713148131491315013151131521315313154131551315613157131581315913160131611316213163131641316513166131671316813169131701317113172131731317413175131761317713178131791318013181131821318313184131851318613187131881318913190131911319213193131941319513196131971319813199132001320113202132031320413205132061320713208132091321013211132121321313214132151321613217132181321913220132211322213223132241322513226132271322813229132301323113232132331323413235132361323713238132391324013241132421324313244132451324613247132481324913250132511325213253132541325513256132571325813259132601326113262132631326413265132661326713268132691327013271132721327313274132751327613277132781327913280132811328213283132841328513286132871328813289132901329113292132931329413295132961329713298132991330013301133021330313304133051330613307133081330913310133111331213313133141331513316133171331813319133201332113322133231332413325133261332713328133291333013331133321333313334133351333613337133381333913340133411334213343133441334513346133471334813349133501335113352133531335413355133561335713358133591336013361133621336313364133651336613367133681336913370133711337213373133741337513376133771337813379133801338113382133831338413385133861338713388133891339013391133921339313394133951339613397133981339913400134011340213403134041340513406134071340813409134101341113412134131341413415134161341713418134191342013421134221342313424134251342613427134281342913430134311343213433134341343513436134371343813439134401344113442134431344413445134461344713448134491345013451134521345313454134551345613457134581345913460134611346213463134641346513466134671346813469134701347113472134731347413475134761347713478134791348013481134821348313484134851348613487134881348913490134911349213493134941349513496134971349813499135001350113502135031350413505135061350713508135091351013511135121351313514135151351613517135181351913520135211352213523135241352513526135271352813529135301353113532135331353413535135361353713538135391354013541135421354313544135451354613547135481354913550135511355213553135541355513556135571355813559135601356113562135631356413565135661356713568135691357013571135721357313574135751357613577135781357913580135811358213583135841358513586135871358813589135901359113592135931359413595135961359713598135991360013601136021360313604136051360613607136081360913610136111361213613136141361513616136171361813619136201362113622136231362413625136261362713628136291363013631136321363313634136351363613637136381363913640136411364213643136441364513646136471364813649136501365113652136531365413655136561365713658136591366013661136621366313664136651366613667136681366913670136711367213673136741367513676136771367813679136801368113682136831368413685136861368713688136891369013691136921369313694136951369613697136981369913700137011370213703137041370513706137071370813709137101371113712137131371413715137161371713718137191372013721137221372313724137251372613727137281372913730137311373213733137341373513736137371373813739137401374113742137431374413745137461374713748137491375013751137521375313754137551375613757137581375913760137611376213763137641376513766137671376813769137701377113772137731377413775137761377713778137791378013781137821378313784137851378613787137881378913790137911379213793137941379513796137971379813799138001380113802138031380413805138061380713808138091381013811138121381313814138151381613817138181381913820138211382213823138241382513826138271382813829138301383113832138331383413835138361383713838138391384013841138421384313844138451384613847138481384913850138511385213853138541385513856138571385813859138601386113862138631386413865138661386713868138691387013871138721387313874138751387613877138781387913880138811388213883138841388513886138871388813889138901389113892138931389413895138961389713898138991390013901139021390313904139051390613907139081390913910139111391213913139141391513916139171391813919139201392113922139231392413925139261392713928139291393013931139321393313934139351393613937139381393913940139411394213943139441394513946139471394813949139501395113952139531395413955139561395713958139591396013961139621396313964139651396613967139681396913970139711397213973139741397513976139771397813979139801398113982139831398413985139861398713988139891399013991139921399313994139951399613997139981399914000140011400214003140041400514006140071400814009140101401114012140131401414015140161401714018140191402014021140221402314024140251402614027140281402914030140311403214033140341403514036140371403814039140401404114042140431404414045140461404714048140491405014051140521405314054140551405614057140581405914060140611406214063140641406514066140671406814069140701407114072140731407414075140761407714078140791408014081140821408314084140851408614087140881408914090140911409214093140941409514096140971409814099141001410114102141031410414105141061410714108141091411014111141121411314114141151411614117141181411914120141211412214123141241412514126141271412814129141301413114132141331413414135141361413714138141391414014141141421414314144141451414614147141481414914150141511415214153141541415514156141571415814159141601416114162141631416414165141661416714168141691417014171141721417314174141751417614177141781417914180141811418214183141841418514186141871418814189141901419114192141931419414195141961419714198141991420014201142021420314204142051420614207142081420914210142111421214213142141421514216142171421814219142201422114222142231422414225142261422714228142291423014231142321423314234142351423614237142381423914240142411424214243142441424514246142471424814249142501425114252142531425414255142561425714258142591426014261142621426314264142651426614267142681426914270142711427214273142741427514276142771427814279142801428114282142831428414285142861428714288142891429014291142921429314294142951429614297142981429914300143011430214303143041430514306143071430814309143101431114312143131431414315143161431714318143191432014321143221432314324143251432614327143281432914330143311433214333143341433514336143371433814339143401434114342143431434414345143461434714348143491435014351143521435314354143551435614357143581435914360143611436214363143641436514366143671436814369143701437114372143731437414375143761437714378143791438014381143821438314384143851438614387143881438914390143911439214393143941439514396143971439814399144001440114402144031440414405144061440714408144091441014411144121441314414144151441614417144181441914420144211442214423144241442514426144271442814429144301443114432144331443414435144361443714438144391444014441144421444314444144451444614447144481444914450144511445214453144541445514456144571445814459144601446114462144631446414465144661446714468144691447014471144721447314474144751447614477144781447914480144811448214483144841448514486144871448814489144901449114492144931449414495144961449714498144991450014501145021450314504145051450614507145081450914510145111451214513145141451514516145171451814519145201452114522145231452414525145261452714528145291453014531145321453314534145351453614537145381453914540145411454214543145441454514546145471454814549145501455114552145531455414555145561455714558145591456014561145621456314564145651456614567145681456914570145711457214573145741457514576145771457814579145801458114582145831458414585145861458714588145891459014591145921459314594145951459614597145981459914600146011460214603146041460514606146071460814609146101461114612146131461414615146161461714618146191462014621146221462314624146251462614627146281462914630146311463214633146341463514636146371463814639146401464114642146431464414645146461464714648146491465014651146521465314654146551465614657146581465914660146611466214663146641466514666146671466814669146701467114672146731467414675146761467714678146791468014681146821468314684146851468614687146881468914690146911469214693146941469514696146971469814699147001470114702147031470414705147061470714708147091471014711147121471314714147151471614717147181471914720147211472214723147241472514726147271472814729147301473114732147331473414735147361473714738147391474014741147421474314744147451474614747147481474914750147511475214753147541475514756147571475814759147601476114762147631476414765147661476714768147691477014771147721477314774147751477614777147781477914780147811478214783147841478514786147871478814789147901479114792147931479414795147961479714798147991480014801148021480314804148051480614807148081480914810148111481214813148141481514816148171481814819148201482114822148231482414825148261482714828148291483014831148321483314834148351483614837148381483914840148411484214843148441484514846148471484814849148501485114852148531485414855148561485714858148591486014861148621486314864148651486614867148681486914870148711487214873148741487514876148771487814879148801488114882148831488414885148861488714888148891489014891148921489314894148951489614897148981489914900149011490214903149041490514906149071490814909149101491114912149131491414915149161491714918149191492014921149221492314924149251492614927149281492914930149311493214933149341493514936149371493814939149401494114942149431494414945149461494714948149491495014951149521495314954149551495614957149581495914960149611496214963149641496514966149671496814969149701497114972149731497414975149761497714978149791498014981149821498314984149851498614987149881498914990149911499214993149941499514996149971499814999150001500115002150031500415005150061500715008150091501015011150121501315014150151501615017150181501915020150211502215023150241502515026150271502815029150301503115032150331503415035150361503715038150391504015041150421504315044150451504615047150481504915050150511505215053150541505515056150571505815059150601506115062150631506415065150661506715068150691507015071150721507315074150751507615077150781507915080150811508215083150841508515086150871508815089150901509115092150931509415095150961509715098150991510015101151021510315104151051510615107151081510915110151111511215113151141511515116151171511815119151201512115122151231512415125151261512715128151291513015131151321513315134151351513615137151381513915140151411514215143151441514515146151471514815149151501515115152151531515415155151561515715158151591516015161151621516315164151651516615167151681516915170151711517215173151741517515176151771517815179151801518115182151831518415185151861518715188151891519015191151921519315194151951519615197151981519915200152011520215203152041520515206152071520815209152101521115212152131521415215152161521715218152191522015221152221522315224152251522615227152281522915230152311523215233152341523515236152371523815239152401524115242152431524415245152461524715248152491525015251152521525315254152551525615257152581525915260152611526215263152641526515266152671526815269152701527115272152731527415275152761527715278152791528015281152821528315284152851528615287152881528915290152911529215293152941529515296152971529815299153001530115302153031530415305153061530715308153091531015311153121531315314153151531615317153181531915320153211532215323153241532515326153271532815329153301533115332153331533415335153361533715338153391534015341153421534315344153451534615347153481534915350153511535215353153541535515356153571535815359153601536115362153631536415365153661536715368153691537015371153721537315374153751537615377153781537915380153811538215383153841538515386153871538815389153901539115392153931539415395153961539715398153991540015401154021540315404154051540615407154081540915410154111541215413154141541515416154171541815419154201542115422154231542415425154261542715428154291543015431154321543315434154351543615437154381543915440154411544215443154441544515446154471544815449154501545115452154531545415455154561545715458154591546015461154621546315464154651546615467154681546915470154711547215473154741547515476154771547815479154801548115482154831548415485154861548715488154891549015491154921549315494154951549615497154981549915500155011550215503155041550515506155071550815509155101551115512155131551415515155161551715518155191552015521155221552315524155251552615527155281552915530155311553215533155341553515536155371553815539155401554115542155431554415545155461554715548155491555015551155521555315554155551555615557155581555915560155611556215563155641556515566155671556815569155701557115572155731557415575155761557715578155791558015581155821558315584155851558615587155881558915590155911559215593155941559515596155971559815599156001560115602156031560415605156061560715608156091561015611156121561315614156151561615617156181561915620156211562215623156241562515626156271562815629156301563115632156331563415635156361563715638156391564015641156421564315644156451564615647156481564915650156511565215653156541565515656156571565815659156601566115662156631566415665156661566715668156691567015671156721567315674156751567615677156781567915680156811568215683156841568515686156871568815689156901569115692156931569415695156961569715698156991570015701157021570315704157051570615707157081570915710157111571215713157141571515716157171571815719157201572115722157231572415725157261572715728157291573015731157321573315734157351573615737157381573915740157411574215743157441574515746157471574815749157501575115752157531575415755157561575715758157591576015761157621576315764157651576615767157681576915770157711577215773157741577515776157771577815779157801578115782157831578415785157861578715788157891579015791157921579315794157951579615797157981579915800158011580215803158041580515806158071580815809158101581115812158131581415815158161581715818158191582015821158221582315824158251582615827158281582915830158311583215833158341583515836158371583815839158401584115842158431584415845158461584715848158491585015851158521585315854158551585615857158581585915860158611586215863158641586515866158671586815869158701587115872158731587415875158761587715878158791588015881158821588315884158851588615887158881588915890158911589215893158941589515896158971589815899159001590115902159031590415905159061590715908159091591015911159121591315914159151591615917159181591915920159211592215923159241592515926159271592815929159301593115932159331593415935159361593715938159391594015941159421594315944159451594615947159481594915950159511595215953159541595515956159571595815959159601596115962159631596415965159661596715968159691597015971159721597315974159751597615977159781597915980159811598215983159841598515986159871598815989159901599115992159931599415995159961599715998159991600016001160021600316004160051600616007160081600916010160111601216013160141601516016160171601816019160201602116022160231602416025160261602716028160291603016031160321603316034160351603616037160381603916040160411604216043160441604516046160471604816049160501605116052160531605416055160561605716058160591606016061160621606316064160651606616067160681606916070160711607216073160741607516076160771607816079160801608116082160831608416085160861608716088160891609016091160921609316094160951609616097160981609916100161011610216103161041610516106161071610816109161101611116112161131611416115161161611716118161191612016121161221612316124161251612616127161281612916130161311613216133161341613516136161371613816139161401614116142161431614416145161461614716148161491615016151161521615316154161551615616157161581615916160161611616216163161641616516166161671616816169161701617116172161731617416175161761617716178161791618016181161821618316184161851618616187161881618916190161911619216193161941619516196161971619816199162001620116202162031620416205162061620716208162091621016211162121621316214162151621616217162181621916220162211622216223162241622516226162271622816229162301623116232162331623416235162361623716238162391624016241162421624316244162451624616247162481624916250162511625216253162541625516256162571625816259162601626116262162631626416265162661626716268162691627016271162721627316274162751627616277162781627916280162811628216283162841628516286162871628816289162901629116292162931629416295162961629716298162991630016301163021630316304163051630616307163081630916310163111631216313163141631516316163171631816319163201632116322163231632416325163261632716328163291633016331163321633316334163351633616337163381633916340163411634216343163441634516346163471634816349163501635116352163531635416355163561635716358163591636016361163621636316364163651636616367163681636916370163711637216373163741637516376163771637816379163801638116382163831638416385163861638716388163891639016391163921639316394163951639616397163981639916400164011640216403164041640516406164071640816409164101641116412164131641416415164161641716418164191642016421164221642316424164251642616427164281642916430164311643216433164341643516436164371643816439164401644116442164431644416445164461644716448164491645016451164521645316454164551645616457164581645916460164611646216463164641646516466164671646816469164701647116472164731647416475164761647716478164791648016481164821648316484164851648616487164881648916490164911649216493164941649516496164971649816499165001650116502165031650416505165061650716508165091651016511165121651316514165151651616517165181651916520165211652216523165241652516526165271652816529165301653116532165331653416535165361653716538165391654016541165421654316544165451654616547165481654916550165511655216553165541655516556165571655816559165601656116562165631656416565165661656716568165691657016571165721657316574165751657616577165781657916580165811658216583165841658516586165871658816589165901659116592165931659416595165961659716598165991660016601166021660316604166051660616607166081660916610166111661216613166141661516616166171661816619166201662116622166231662416625166261662716628166291663016631166321663316634166351663616637166381663916640166411664216643166441664516646166471664816649166501665116652166531665416655166561665716658166591666016661166621666316664166651666616667166681666916670166711667216673166741667516676166771667816679166801668116682166831668416685166861668716688166891669016691166921669316694166951669616697166981669916700167011670216703167041670516706167071670816709167101671116712167131671416715167161671716718167191672016721167221672316724167251672616727167281672916730167311673216733167341673516736167371673816739167401674116742167431674416745167461674716748167491675016751167521675316754167551675616757167581675916760167611676216763167641676516766167671676816769167701677116772167731677416775167761677716778167791678016781167821678316784167851678616787167881678916790167911679216793167941679516796167971679816799168001680116802168031680416805168061680716808168091681016811168121681316814168151681616817168181681916820168211682216823168241682516826168271682816829168301683116832168331683416835168361683716838168391684016841168421684316844168451684616847168481684916850168511685216853168541685516856168571685816859168601686116862168631686416865168661686716868168691687016871168721687316874168751687616877168781687916880168811688216883168841688516886168871688816889168901689116892168931689416895168961689716898168991690016901169021690316904169051690616907169081690916910169111691216913169141691516916169171691816919169201692116922169231692416925169261692716928169291693016931169321693316934169351693616937169381693916940169411694216943169441694516946169471694816949169501695116952169531695416955169561695716958169591696016961169621696316964169651696616967169681696916970169711697216973169741697516976169771697816979169801698116982169831698416985169861698716988169891699016991169921699316994169951699616997169981699917000170011700217003170041700517006170071700817009170101701117012170131701417015170161701717018170191702017021170221702317024170251702617027170281702917030170311703217033170341703517036170371703817039170401704117042170431704417045170461704717048170491705017051170521705317054170551705617057170581705917060170611706217063170641706517066170671706817069170701707117072170731707417075170761707717078170791708017081170821708317084170851708617087170881708917090170911709217093170941709517096170971709817099171001710117102171031710417105171061710717108171091711017111171121711317114171151711617117171181711917120171211712217123171241712517126171271712817129171301713117132171331713417135171361713717138171391714017141171421714317144171451714617147171481714917150171511715217153171541715517156171571715817159171601716117162171631716417165171661716717168171691717017171171721717317174171751717617177171781717917180171811718217183171841718517186171871718817189171901719117192171931719417195171961719717198171991720017201172021720317204172051720617207172081720917210172111721217213172141721517216172171721817219172201722117222172231722417225172261722717228172291723017231172321723317234172351723617237172381723917240172411724217243172441724517246172471724817249172501725117252172531725417255172561725717258172591726017261172621726317264172651726617267172681726917270172711727217273172741727517276172771727817279172801728117282172831728417285172861728717288172891729017291172921729317294172951729617297172981729917300173011730217303173041730517306173071730817309173101731117312173131731417315173161731717318173191732017321173221732317324173251732617327173281732917330173311733217333173341733517336173371733817339173401734117342173431734417345173461734717348173491735017351173521735317354173551735617357173581735917360173611736217363173641736517366173671736817369173701737117372173731737417375173761737717378173791738017381173821738317384173851738617387173881738917390173911739217393173941739517396173971739817399174001740117402174031740417405174061740717408174091741017411174121741317414174151741617417174181741917420174211742217423174241742517426174271742817429174301743117432174331743417435174361743717438174391744017441174421744317444174451744617447174481744917450174511745217453174541745517456174571745817459174601746117462174631746417465174661746717468174691747017471174721747317474174751747617477174781747917480174811748217483174841748517486174871748817489174901749117492174931749417495174961749717498174991750017501175021750317504175051750617507175081750917510175111751217513175141751517516175171751817519175201752117522175231752417525175261752717528175291753017531175321753317534175351753617537175381753917540175411754217543175441754517546175471754817549175501755117552175531755417555175561755717558175591756017561175621756317564175651756617567175681756917570175711757217573175741757517576175771757817579175801758117582175831758417585175861758717588175891759017591175921759317594175951759617597175981759917600176011760217603176041760517606176071760817609176101761117612176131761417615176161761717618176191762017621176221762317624176251762617627176281762917630176311763217633176341763517636176371763817639176401764117642176431764417645176461764717648176491765017651176521765317654176551765617657176581765917660176611766217663176641766517666176671766817669176701767117672176731767417675176761767717678176791768017681176821768317684176851768617687176881768917690176911769217693176941769517696176971769817699177001770117702177031770417705177061770717708177091771017711177121771317714177151771617717177181771917720177211772217723177241772517726177271772817729177301773117732177331773417735177361773717738177391774017741177421774317744177451774617747177481774917750177511775217753177541775517756177571775817759177601776117762177631776417765177661776717768177691777017771177721777317774177751777617777177781777917780177811778217783177841778517786177871778817789177901779117792177931779417795177961779717798177991780017801178021780317804178051780617807178081780917810178111781217813178141781517816178171781817819178201782117822178231782417825178261782717828178291783017831178321783317834178351783617837178381783917840178411784217843178441784517846178471784817849178501785117852178531785417855178561785717858178591786017861178621786317864178651786617867178681786917870178711787217873178741787517876178771787817879178801788117882178831788417885178861788717888178891789017891178921789317894178951789617897178981789917900179011790217903179041790517906179071790817909179101791117912179131791417915179161791717918
  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 tailcc, 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. "``tailcc``" - Tail callable calling convention
  373. This calling convention ensures that calls in tail position will always be
  374. tail call optimized. This calling convention is equivalent to fastcc,
  375. except for an additional guarantee that tail calls will be produced
  376. whenever possible. `Tail calls can only be optimized when this, the fastcc,
  377. the GHC or the HiPE convention is used. <CodeGenerator.html#id80>`_ This
  378. calling convention does not support varargs and requires the prototype of
  379. all callees to exactly match the prototype of the function definition.
  380. "``cc <n>``" - Numbered convention
  381. Any calling convention may be specified by number, allowing
  382. target-specific calling conventions to be used. Target specific
  383. calling conventions start at 64.
  384. More calling conventions can be added/defined on an as-needed basis, to
  385. support Pascal conventions or any other well-known target-independent
  386. convention.
  387. .. _visibilitystyles:
  388. Visibility Styles
  389. -----------------
  390. All Global Variables and Functions have one of the following visibility
  391. styles:
  392. "``default``" - Default style
  393. On targets that use the ELF object file format, default visibility
  394. means that the declaration is visible to other modules and, in
  395. shared libraries, means that the declared entity may be overridden.
  396. On Darwin, default visibility means that the declaration is visible
  397. to other modules. Default visibility corresponds to "external
  398. linkage" in the language.
  399. "``hidden``" - Hidden style
  400. Two declarations of an object with hidden visibility refer to the
  401. same object if they are in the same shared object. Usually, hidden
  402. visibility indicates that the symbol will not be placed into the
  403. dynamic symbol table, so no other module (executable or shared
  404. library) can reference it directly.
  405. "``protected``" - Protected style
  406. On ELF, protected visibility indicates that the symbol will be
  407. placed in the dynamic symbol table, but that references within the
  408. defining module will bind to the local symbol. That is, the symbol
  409. cannot be overridden by another module.
  410. A symbol with ``internal`` or ``private`` linkage must have ``default``
  411. visibility.
  412. .. _dllstorageclass:
  413. DLL Storage Classes
  414. -------------------
  415. All Global Variables, Functions and Aliases can have one of the following
  416. DLL storage class:
  417. ``dllimport``
  418. "``dllimport``" causes the compiler to reference a function or variable via
  419. a global pointer to a pointer that is set up by the DLL exporting the
  420. symbol. On Microsoft Windows targets, the pointer name is formed by
  421. combining ``__imp_`` and the function or variable name.
  422. ``dllexport``
  423. "``dllexport``" causes the compiler to provide a global pointer to a pointer
  424. in a DLL, so that it can be referenced with the ``dllimport`` attribute. On
  425. Microsoft Windows targets, the pointer name is formed by combining
  426. ``__imp_`` and the function or variable name. Since this storage class
  427. exists for defining a dll interface, the compiler, assembler and linker know
  428. it is externally referenced and must refrain from deleting the symbol.
  429. .. _tls_model:
  430. Thread Local Storage Models
  431. ---------------------------
  432. A variable may be defined as ``thread_local``, which means that it will
  433. not be shared by threads (each thread will have a separated copy of the
  434. variable). Not all targets support thread-local variables. Optionally, a
  435. TLS model may be specified:
  436. ``localdynamic``
  437. For variables that are only used within the current shared library.
  438. ``initialexec``
  439. For variables in modules that will not be loaded dynamically.
  440. ``localexec``
  441. For variables defined in the executable and only used within it.
  442. If no explicit model is given, the "general dynamic" model is used.
  443. The models correspond to the ELF TLS models; see `ELF Handling For
  444. Thread-Local Storage <http://people.redhat.com/drepper/tls.pdf>`_ for
  445. more information on under which circumstances the different models may
  446. be used. The target may choose a different TLS model if the specified
  447. model is not supported, or if a better choice of model can be made.
  448. A model can also be specified in an alias, but then it only governs how
  449. the alias is accessed. It will not have any effect in the aliasee.
  450. For platforms without linker support of ELF TLS model, the -femulated-tls
  451. flag can be used to generate GCC compatible emulated TLS code.
  452. .. _runtime_preemption_model:
  453. Runtime Preemption Specifiers
  454. -----------------------------
  455. Global variables, functions and aliases may have an optional runtime preemption
  456. specifier. If a preemption specifier isn't given explicitly, then a
  457. symbol is assumed to be ``dso_preemptable``.
  458. ``dso_preemptable``
  459. Indicates that the function or variable may be replaced by a symbol from
  460. outside the linkage unit at runtime.
  461. ``dso_local``
  462. The compiler may assume that a function or variable marked as ``dso_local``
  463. will resolve to a symbol within the same linkage unit. Direct access will
  464. be generated even if the definition is not within this compilation unit.
  465. .. _namedtypes:
  466. Structure Types
  467. ---------------
  468. LLVM IR allows you to specify both "identified" and "literal" :ref:`structure
  469. types <t_struct>`. Literal types are uniqued structurally, but identified types
  470. are never uniqued. An :ref:`opaque structural type <t_opaque>` can also be used
  471. to forward declare a type that is not yet available.
  472. An example of an identified structure specification is:
  473. .. code-block:: llvm
  474. %mytype = type { %mytype*, i32 }
  475. Prior to the LLVM 3.0 release, identified types were structurally uniqued. Only
  476. literal types are uniqued in recent versions of LLVM.
  477. .. _nointptrtype:
  478. Non-Integral Pointer Type
  479. -------------------------
  480. Note: non-integral pointer types are a work in progress, and they should be
  481. considered experimental at this time.
  482. LLVM IR optionally allows the frontend to denote pointers in certain address
  483. spaces as "non-integral" via the :ref:`datalayout string<langref_datalayout>`.
  484. Non-integral pointer types represent pointers that have an *unspecified* bitwise
  485. representation; that is, the integral representation may be target dependent or
  486. unstable (not backed by a fixed integer).
  487. ``inttoptr`` instructions converting integers to non-integral pointer types are
  488. ill-typed, and so are ``ptrtoint`` instructions converting values of
  489. non-integral pointer types to integers. Vector versions of said instructions
  490. are ill-typed as well.
  491. .. _globalvars:
  492. Global Variables
  493. ----------------
  494. Global variables define regions of memory allocated at compilation time
  495. instead of run-time.
  496. Global variable definitions must be initialized.
  497. Global variables in other translation units can also be declared, in which
  498. case they don't have an initializer.
  499. Either global variable definitions or declarations may have an explicit section
  500. to be placed in and may have an optional explicit alignment specified. If there
  501. is a mismatch between the explicit or inferred section information for the
  502. variable declaration and its definition the resulting behavior is undefined.
  503. A variable may be defined as a global ``constant``, which indicates that
  504. the contents of the variable will **never** be modified (enabling better
  505. optimization, allowing the global data to be placed in the read-only
  506. section of an executable, etc). Note that variables that need runtime
  507. initialization cannot be marked ``constant`` as there is a store to the
  508. variable.
  509. LLVM explicitly allows *declarations* of global variables to be marked
  510. constant, even if the final definition of the global is not. This
  511. capability can be used to enable slightly better optimization of the
  512. program, but requires the language definition to guarantee that
  513. optimizations based on the 'constantness' are valid for the translation
  514. units that do not include the definition.
  515. As SSA values, global variables define pointer values that are in scope
  516. (i.e. they dominate) all basic blocks in the program. Global variables
  517. always define a pointer to their "content" type because they describe a
  518. region of memory, and all memory objects in LLVM are accessed through
  519. pointers.
  520. Global variables can be marked with ``unnamed_addr`` which indicates
  521. that the address is not significant, only the content. Constants marked
  522. like this can be merged with other constants if they have the same
  523. initializer. Note that a constant with significant address *can* be
  524. merged with a ``unnamed_addr`` constant, the result being a constant
  525. whose address is significant.
  526. If the ``local_unnamed_addr`` attribute is given, the address is known to
  527. not be significant within the module.
  528. A global variable may be declared to reside in a target-specific
  529. numbered address space. For targets that support them, address spaces
  530. may affect how optimizations are performed and/or what target
  531. instructions are used to access the variable. The default address space
  532. is zero. The address space qualifier must precede any other attributes.
  533. LLVM allows an explicit section to be specified for globals. If the
  534. target supports it, it will emit globals to the section specified.
  535. Additionally, the global can placed in a comdat if the target has the necessary
  536. support.
  537. External declarations may have an explicit section specified. Section
  538. information is retained in LLVM IR for targets that make use of this
  539. information. Attaching section information to an external declaration is an
  540. assertion that its definition is located in the specified section. If the
  541. definition is located in a different section, the behavior is undefined.
  542. By default, global initializers are optimized by assuming that global
  543. variables defined within the module are not modified from their
  544. initial values before the start of the global initializer. This is
  545. true even for variables potentially accessible from outside the
  546. module, including those with external linkage or appearing in
  547. ``@llvm.used`` or dllexported variables. This assumption may be suppressed
  548. by marking the variable with ``externally_initialized``.
  549. An explicit alignment may be specified for a global, which must be a
  550. power of 2. If not present, or if the alignment is set to zero, the
  551. alignment of the global is set by the target to whatever it feels
  552. convenient. If an explicit alignment is specified, the global is forced
  553. to have exactly that alignment. Targets and optimizers are not allowed
  554. to over-align the global if the global has an assigned section. In this
  555. case, the extra alignment could be observable: for example, code could
  556. assume that the globals are densely packed in their section and try to
  557. iterate over them as an array, alignment padding would break this
  558. iteration. The maximum alignment is ``1 << 29``.
  559. Globals can also have a :ref:`DLL storage class <dllstorageclass>`,
  560. an optional :ref:`runtime preemption specifier <runtime_preemption_model>`,
  561. an optional :ref:`global attributes <glattrs>` and
  562. an optional list of attached :ref:`metadata <metadata>`.
  563. Variables and aliases can have a
  564. :ref:`Thread Local Storage Model <tls_model>`.
  565. :ref:`Scalable vectors <t_vector>` cannot be global variables or members of
  566. structs or arrays because their size is unknown at compile time.
  567. Syntax::
  568. @<GlobalVarName> = [Linkage] [PreemptionSpecifier] [Visibility]
  569. [DLLStorageClass] [ThreadLocal]
  570. [(unnamed_addr|local_unnamed_addr)] [AddrSpace]
  571. [ExternallyInitialized]
  572. <global | constant> <Type> [<InitializerConstant>]
  573. [, section "name"] [, comdat [($name)]]
  574. [, align <Alignment>] (, !name !N)*
  575. For example, the following defines a global in a numbered address space
  576. with an initializer, section, and alignment:
  577. .. code-block:: llvm
  578. @G = addrspace(5) constant float 1.0, section "foo", align 4
  579. The following example just declares a global variable
  580. .. code-block:: llvm
  581. @G = external global i32
  582. The following example defines a thread-local global with the
  583. ``initialexec`` TLS model:
  584. .. code-block:: llvm
  585. @G = thread_local(initialexec) global i32 0, align 4
  586. .. _functionstructure:
  587. Functions
  588. ---------
  589. LLVM function definitions consist of the "``define``" keyword, an
  590. optional :ref:`linkage type <linkage>`, an optional :ref:`runtime preemption
  591. specifier <runtime_preemption_model>`, an optional :ref:`visibility
  592. style <visibility>`, an optional :ref:`DLL storage class <dllstorageclass>`,
  593. an optional :ref:`calling convention <callingconv>`,
  594. an optional ``unnamed_addr`` attribute, a return type, an optional
  595. :ref:`parameter attribute <paramattrs>` for the return type, a function
  596. name, a (possibly empty) argument list (each with optional :ref:`parameter
  597. attributes <paramattrs>`), optional :ref:`function attributes <fnattrs>`,
  598. an optional address space, an optional section, an optional alignment,
  599. an optional :ref:`comdat <langref_comdats>`,
  600. an optional :ref:`garbage collector name <gc>`, an optional :ref:`prefix <prefixdata>`,
  601. an optional :ref:`prologue <prologuedata>`,
  602. an optional :ref:`personality <personalityfn>`,
  603. an optional list of attached :ref:`metadata <metadata>`,
  604. an opening curly brace, a list of basic blocks, and a closing curly brace.
  605. LLVM function declarations consist of the "``declare``" keyword, an
  606. optional :ref:`linkage type <linkage>`, an optional :ref:`visibility style
  607. <visibility>`, an optional :ref:`DLL storage class <dllstorageclass>`, an
  608. optional :ref:`calling convention <callingconv>`, an optional ``unnamed_addr``
  609. or ``local_unnamed_addr`` attribute, an optional address space, a return type,
  610. an optional :ref:`parameter attribute <paramattrs>` for the return type, a function name, a possibly
  611. empty list of arguments, an optional alignment, an optional :ref:`garbage
  612. collector name <gc>`, an optional :ref:`prefix <prefixdata>`, and an optional
  613. :ref:`prologue <prologuedata>`.
  614. A function definition contains a list of basic blocks, forming the CFG (Control
  615. Flow Graph) for the function. Each basic block may optionally start with a label
  616. (giving the basic block a symbol table entry), contains a list of instructions,
  617. and ends with a :ref:`terminator <terminators>` instruction (such as a branch or
  618. function return). If an explicit label name is not provided, a block is assigned
  619. an implicit numbered label, using the next value from the same counter as used
  620. for unnamed temporaries (:ref:`see above<identifiers>`). For example, if a
  621. function entry block does not have an explicit label, it will be assigned label
  622. "%0", then the first unnamed temporary in that block will be "%1", etc. If a
  623. numeric label is explicitly specified, it must match the numeric label that
  624. would be used implicitly.
  625. The first basic block in a function is special in two ways: it is
  626. immediately executed on entrance to the function, and it is not allowed
  627. to have predecessor basic blocks (i.e. there can not be any branches to
  628. the entry block of a function). Because the block can have no
  629. predecessors, it also cannot have any :ref:`PHI nodes <i_phi>`.
  630. LLVM allows an explicit section to be specified for functions. If the
  631. target supports it, it will emit functions to the section specified.
  632. Additionally, the function can be placed in a COMDAT.
  633. An explicit alignment may be specified for a function. If not present,
  634. or if the alignment is set to zero, the alignment of the function is set
  635. by the target to whatever it feels convenient. If an explicit alignment
  636. is specified, the function is forced to have at least that much
  637. alignment. All alignments must be a power of 2.
  638. If the ``unnamed_addr`` attribute is given, the address is known to not
  639. be significant and two identical functions can be merged.
  640. If the ``local_unnamed_addr`` attribute is given, the address is known to
  641. not be significant within the module.
  642. If an explicit address space is not given, it will default to the program
  643. address space from the :ref:`datalayout string<langref_datalayout>`.
  644. Syntax::
  645. define [linkage] [PreemptionSpecifier] [visibility] [DLLStorageClass]
  646. [cconv] [ret attrs]
  647. <ResultType> @<FunctionName> ([argument list])
  648. [(unnamed_addr|local_unnamed_addr)] [AddrSpace] [fn Attrs]
  649. [section "name"] [comdat [($name)]] [align N] [gc] [prefix Constant]
  650. [prologue Constant] [personality Constant] (!name !N)* { ... }
  651. The argument list is a comma separated sequence of arguments where each
  652. argument is of the following form:
  653. Syntax::
  654. <type> [parameter Attrs] [name]
  655. .. _langref_aliases:
  656. Aliases
  657. -------
  658. Aliases, unlike function or variables, don't create any new data. They
  659. are just a new symbol and metadata for an existing position.
  660. Aliases have a name and an aliasee that is either a global value or a
  661. constant expression.
  662. Aliases may have an optional :ref:`linkage type <linkage>`, an optional
  663. :ref:`runtime preemption specifier <runtime_preemption_model>`, an optional
  664. :ref:`visibility style <visibility>`, an optional :ref:`DLL storage class
  665. <dllstorageclass>` and an optional :ref:`tls model <tls_model>`.
  666. Syntax::
  667. @<Name> = [Linkage] [PreemptionSpecifier] [Visibility] [DLLStorageClass] [ThreadLocal] [(unnamed_addr|local_unnamed_addr)] alias <AliaseeTy>, <AliaseeTy>* @<Aliasee>
  668. The linkage must be one of ``private``, ``internal``, ``linkonce``, ``weak``,
  669. ``linkonce_odr``, ``weak_odr``, ``external``. Note that some system linkers
  670. might not correctly handle dropping a weak symbol that is aliased.
  671. Aliases that are not ``unnamed_addr`` are guaranteed to have the same address as
  672. the aliasee expression. ``unnamed_addr`` ones are only guaranteed to point
  673. to the same content.
  674. If the ``local_unnamed_addr`` attribute is given, the address is known to
  675. not be significant within the module.
  676. Since aliases are only a second name, some restrictions apply, of which
  677. some can only be checked when producing an object file:
  678. * The expression defining the aliasee must be computable at assembly
  679. time. Since it is just a name, no relocations can be used.
  680. * No alias in the expression can be weak as the possibility of the
  681. intermediate alias being overridden cannot be represented in an
  682. object file.
  683. * No global value in the expression can be a declaration, since that
  684. would require a relocation, which is not possible.
  685. .. _langref_ifunc:
  686. IFuncs
  687. -------
  688. IFuncs, like as aliases, don't create any new data or func. They are just a new
  689. symbol that dynamic linker resolves at runtime by calling a resolver function.
  690. IFuncs have a name and a resolver that is a function called by dynamic linker
  691. that returns address of another function associated with the name.
  692. IFunc may have an optional :ref:`linkage type <linkage>` and an optional
  693. :ref:`visibility style <visibility>`.
  694. Syntax::
  695. @<Name> = [Linkage] [Visibility] ifunc <IFuncTy>, <ResolverTy>* @<Resolver>
  696. .. _langref_comdats:
  697. Comdats
  698. -------
  699. Comdat IR provides access to COFF and ELF object file COMDAT functionality.
  700. Comdats have a name which represents the COMDAT key. All global objects that
  701. specify this key will only end up in the final object file if the linker chooses
  702. that key over some other key. Aliases are placed in the same COMDAT that their
  703. aliasee computes to, if any.
  704. Comdats have a selection kind to provide input on how the linker should
  705. choose between keys in two different object files.
  706. Syntax::
  707. $<Name> = comdat SelectionKind
  708. The selection kind must be one of the following:
  709. ``any``
  710. The linker may choose any COMDAT key, the choice is arbitrary.
  711. ``exactmatch``
  712. The linker may choose any COMDAT key but the sections must contain the
  713. same data.
  714. ``largest``
  715. The linker will choose the section containing the largest COMDAT key.
  716. ``noduplicates``
  717. The linker requires that only section with this COMDAT key exist.
  718. ``samesize``
  719. The linker may choose any COMDAT key but the sections must contain the
  720. same amount of data.
  721. Note that the Mach-O platform doesn't support COMDATs, and ELF and WebAssembly
  722. only support ``any`` as a selection kind.
  723. Here is an example of a COMDAT group where a function will only be selected if
  724. the COMDAT key's section is the largest:
  725. .. code-block:: text
  726. $foo = comdat largest
  727. @foo = global i32 2, comdat($foo)
  728. define void @bar() comdat($foo) {
  729. ret void
  730. }
  731. As a syntactic sugar the ``$name`` can be omitted if the name is the same as
  732. the global name:
  733. .. code-block:: text
  734. $foo = comdat any
  735. @foo = global i32 2, comdat
  736. In a COFF object file, this will create a COMDAT section with selection kind
  737. ``IMAGE_COMDAT_SELECT_LARGEST`` containing the contents of the ``@foo`` symbol
  738. and another COMDAT section with selection kind
  739. ``IMAGE_COMDAT_SELECT_ASSOCIATIVE`` which is associated with the first COMDAT
  740. section and contains the contents of the ``@bar`` symbol.
  741. There are some restrictions on the properties of the global object.
  742. It, or an alias to it, must have the same name as the COMDAT group when
  743. targeting COFF.
  744. The contents and size of this object may be used during link-time to determine
  745. which COMDAT groups get selected depending on the selection kind.
  746. Because the name of the object must match the name of the COMDAT group, the
  747. linkage of the global object must not be local; local symbols can get renamed
  748. if a collision occurs in the symbol table.
  749. The combined use of COMDATS and section attributes may yield surprising results.
  750. For example:
  751. .. code-block:: text
  752. $foo = comdat any
  753. $bar = comdat any
  754. @g1 = global i32 42, section "sec", comdat($foo)
  755. @g2 = global i32 42, section "sec", comdat($bar)
  756. From the object file perspective, this requires the creation of two sections
  757. with the same name. This is necessary because both globals belong to different
  758. COMDAT groups and COMDATs, at the object file level, are represented by
  759. sections.
  760. Note that certain IR constructs like global variables and functions may
  761. create COMDATs in the object file in addition to any which are specified using
  762. COMDAT IR. This arises when the code generator is configured to emit globals
  763. in individual sections (e.g. when `-data-sections` or `-function-sections`
  764. is supplied to `llc`).
  765. .. _namedmetadatastructure:
  766. Named Metadata
  767. --------------
  768. Named metadata is a collection of metadata. :ref:`Metadata
  769. nodes <metadata>` (but not metadata strings) are the only valid
  770. operands for a named metadata.
  771. #. Named metadata are represented as a string of characters with the
  772. metadata prefix. The rules for metadata names are the same as for
  773. identifiers, but quoted names are not allowed. ``"\xx"`` type escapes
  774. are still valid, which allows any character to be part of a name.
  775. Syntax::
  776. ; Some unnamed metadata nodes, which are referenced by the named metadata.
  777. !0 = !{!"zero"}
  778. !1 = !{!"one"}
  779. !2 = !{!"two"}
  780. ; A named metadata.
  781. !name = !{!0, !1, !2}
  782. .. _paramattrs:
  783. Parameter Attributes
  784. --------------------
  785. The return type and each parameter of a function type may have a set of
  786. *parameter attributes* associated with them. Parameter attributes are
  787. used to communicate additional information about the result or
  788. parameters of a function. Parameter attributes are considered to be part
  789. of the function, not of the function type, so functions with different
  790. parameter attributes can have the same function type.
  791. Parameter attributes are simple keywords that follow the type specified.
  792. If multiple parameter attributes are needed, they are space separated.
  793. For example:
  794. .. code-block:: llvm
  795. declare i32 @printf(i8* noalias nocapture, ...)
  796. declare i32 @atoi(i8 zeroext)
  797. declare signext i8 @returns_signed_char()
  798. Note that any attributes for the function result (``nounwind``,
  799. ``readonly``) come immediately after the argument list.
  800. Currently, only the following parameter attributes are defined:
  801. ``zeroext``
  802. This indicates to the code generator that the parameter or return
  803. value should be zero-extended to the extent required by the target's
  804. ABI by the caller (for a parameter) or the callee (for a return value).
  805. ``signext``
  806. This indicates to the code generator that the parameter or return
  807. value should be sign-extended to the extent required by the target's
  808. ABI (which is usually 32-bits) by the caller (for a parameter) or
  809. the callee (for a return value).
  810. ``inreg``
  811. This indicates that this parameter or return value should be treated
  812. in a special target-dependent fashion while emitting code for
  813. a function call or return (usually, by putting it in a register as
  814. opposed to memory, though some targets use it to distinguish between
  815. two different kinds of registers). Use of this attribute is
  816. target-specific.
  817. ``byval`` or ``byval(<ty>)``
  818. This indicates that the pointer parameter should really be passed by
  819. value to the function. The attribute implies that a hidden copy of
  820. the pointee is made between the caller and the callee, so the callee
  821. is unable to modify the value in the caller. This attribute is only
  822. valid on LLVM pointer arguments. It is generally used to pass
  823. structs and arrays by value, but is also valid on pointers to
  824. scalars. The copy is considered to belong to the caller not the
  825. callee (for example, ``readonly`` functions should not write to
  826. ``byval`` parameters). This is not a valid attribute for return
  827. values.
  828. The byval attribute also supports an optional type argument, which must be
  829. the same as the pointee type of the argument.
  830. The byval attribute also supports specifying an alignment with the
  831. align attribute. It indicates the alignment of the stack slot to
  832. form and the known alignment of the pointer specified to the call
  833. site. If the alignment is not specified, then the code generator
  834. makes a target-specific assumption.
  835. .. _attr_inalloca:
  836. ``inalloca``
  837. The ``inalloca`` argument attribute allows the caller to take the
  838. address of outgoing stack arguments. An ``inalloca`` argument must
  839. be a pointer to stack memory produced by an ``alloca`` instruction.
  840. The alloca, or argument allocation, must also be tagged with the
  841. inalloca keyword. Only the last argument may have the ``inalloca``
  842. attribute, and that argument is guaranteed to be passed in memory.
  843. An argument allocation may be used by a call at most once because
  844. the call may deallocate it. The ``inalloca`` attribute cannot be
  845. used in conjunction with other attributes that affect argument
  846. storage, like ``inreg``, ``nest``, ``sret``, or ``byval``. The
  847. ``inalloca`` attribute also disables LLVM's implicit lowering of
  848. large aggregate return values, which means that frontend authors
  849. must lower them with ``sret`` pointers.
  850. When the call site is reached, the argument allocation must have
  851. been the most recent stack allocation that is still live, or the
  852. behavior is undefined. It is possible to allocate additional stack
  853. space after an argument allocation and before its call site, but it
  854. must be cleared off with :ref:`llvm.stackrestore
  855. <int_stackrestore>`.
  856. See :doc:`InAlloca` for more information on how to use this
  857. attribute.
  858. ``sret``
  859. This indicates that the pointer parameter specifies the address of a
  860. structure that is the return value of the function in the source
  861. program. This pointer must be guaranteed by the caller to be valid:
  862. loads and stores to the structure may be assumed by the callee not
  863. to trap and to be properly aligned. This is not a valid attribute
  864. for return values.
  865. .. _attr_align:
  866. ``align <n>``
  867. This indicates that the pointer value may be assumed by the optimizer to
  868. have the specified alignment. If the pointer value does not have the
  869. specified alignment, behavior is undefined.
  870. Note that this attribute has additional semantics when combined with the
  871. ``byval`` attribute, which are documented there.
  872. .. _noalias:
  873. ``noalias``
  874. This indicates that objects accessed via pointer values
  875. :ref:`based <pointeraliasing>` on the argument or return value are not also
  876. accessed, during the execution of the function, via pointer values not
  877. *based* on the argument or return value. The attribute on a return value
  878. also has additional semantics described below. The caller shares the
  879. responsibility with the callee for ensuring that these requirements are met.
  880. For further details, please see the discussion of the NoAlias response in
  881. :ref:`alias analysis <Must, May, or No>`.
  882. Note that this definition of ``noalias`` is intentionally similar
  883. to the definition of ``restrict`` in C99 for function arguments.
  884. For function return values, C99's ``restrict`` is not meaningful,
  885. while LLVM's ``noalias`` is. Furthermore, the semantics of the ``noalias``
  886. attribute on return values are stronger than the semantics of the attribute
  887. when used on function arguments. On function return values, the ``noalias``
  888. attribute indicates that the function acts like a system memory allocation
  889. function, returning a pointer to allocated storage disjoint from the
  890. storage for any other object accessible to the caller.
  891. ``nocapture``
  892. This indicates that the callee does not make any copies of the
  893. pointer that outlive the callee itself. This is not a valid
  894. attribute for return values. Addresses used in volatile operations
  895. are considered to be captured.
  896. .. _nest:
  897. ``nest``
  898. This indicates that the pointer parameter can be excised using the
  899. :ref:`trampoline intrinsics <int_trampoline>`. This is not a valid
  900. attribute for return values and can only be applied to one parameter.
  901. ``returned``
  902. This indicates that the function always returns the argument as its return
  903. value. This is a hint to the optimizer and code generator used when
  904. generating the caller, allowing value propagation, tail call optimization,
  905. and omission of register saves and restores in some cases; it is not
  906. checked or enforced when generating the callee. The parameter and the
  907. function return type must be valid operands for the
  908. :ref:`bitcast instruction <i_bitcast>`. This is not a valid attribute for
  909. return values and can only be applied to one parameter.
  910. ``nonnull``
  911. This indicates that the parameter or return pointer is not null. This
  912. attribute may only be applied to pointer typed parameters. This is not
  913. checked or enforced by LLVM; if the parameter or return pointer is null,
  914. the behavior is undefined.
  915. ``dereferenceable(<n>)``
  916. This indicates that the parameter or return pointer is dereferenceable. This
  917. attribute may only be applied to pointer typed parameters. A pointer that
  918. is dereferenceable can be loaded from speculatively without a risk of
  919. trapping. The number of bytes known to be dereferenceable must be provided
  920. in parentheses. It is legal for the number of bytes to be less than the
  921. size of the pointee type. The ``nonnull`` attribute does not imply
  922. dereferenceability (consider a pointer to one element past the end of an
  923. array), however ``dereferenceable(<n>)`` does imply ``nonnull`` in
  924. ``addrspace(0)`` (which is the default address space).
  925. ``dereferenceable_or_null(<n>)``
  926. This indicates that the parameter or return value isn't both
  927. non-null and non-dereferenceable (up to ``<n>`` bytes) at the same
  928. time. All non-null pointers tagged with
  929. ``dereferenceable_or_null(<n>)`` are ``dereferenceable(<n>)``.
  930. For address space 0 ``dereferenceable_or_null(<n>)`` implies that
  931. a pointer is exactly one of ``dereferenceable(<n>)`` or ``null``,
  932. and in other address spaces ``dereferenceable_or_null(<n>)``
  933. implies that a pointer is at least one of ``dereferenceable(<n>)``
  934. or ``null`` (i.e. it may be both ``null`` and
  935. ``dereferenceable(<n>)``). This attribute may only be applied to
  936. pointer typed parameters.
  937. ``swiftself``
  938. This indicates that the parameter is the self/context parameter. This is not
  939. a valid attribute for return values and can only be applied to one
  940. parameter.
  941. ``swifterror``
  942. This attribute is motivated to model and optimize Swift error handling. It
  943. can be applied to a parameter with pointer to pointer type or a
  944. pointer-sized alloca. At the call site, the actual argument that corresponds
  945. to a ``swifterror`` parameter has to come from a ``swifterror`` alloca or
  946. the ``swifterror`` parameter of the caller. A ``swifterror`` value (either
  947. the parameter or the alloca) can only be loaded and stored from, or used as
  948. a ``swifterror`` argument. This is not a valid attribute for return values
  949. and can only be applied to one parameter.
  950. These constraints allow the calling convention to optimize access to
  951. ``swifterror`` variables by associating them with a specific register at
  952. call boundaries rather than placing them in memory. Since this does change
  953. the calling convention, a function which uses the ``swifterror`` attribute
  954. on a parameter is not ABI-compatible with one which does not.
  955. These constraints also allow LLVM to assume that a ``swifterror`` argument
  956. does not alias any other memory visible within a function and that a
  957. ``swifterror`` alloca passed as an argument does not escape.
  958. ``immarg``
  959. This indicates the parameter is required to be an immediate
  960. value. This must be a trivial immediate integer or floating-point
  961. constant. Undef or constant expressions are not valid. This is
  962. only valid on intrinsic declarations and cannot be applied to a
  963. call site or arbitrary function.
  964. .. _gc:
  965. Garbage Collector Strategy Names
  966. --------------------------------
  967. Each function may specify a garbage collector strategy name, which is simply a
  968. string:
  969. .. code-block:: llvm
  970. define void @f() gc "name" { ... }
  971. The supported values of *name* includes those :ref:`built in to LLVM
  972. <builtin-gc-strategies>` and any provided by loaded plugins. Specifying a GC
  973. strategy will cause the compiler to alter its output in order to support the
  974. named garbage collection algorithm. Note that LLVM itself does not contain a
  975. garbage collector, this functionality is restricted to generating machine code
  976. which can interoperate with a collector provided externally.
  977. .. _prefixdata:
  978. Prefix Data
  979. -----------
  980. Prefix data is data associated with a function which the code
  981. generator will emit immediately before the function's entrypoint.
  982. The purpose of this feature is to allow frontends to associate
  983. language-specific runtime metadata with specific functions and make it
  984. available through the function pointer while still allowing the
  985. function pointer to be called.
  986. To access the data for a given function, a program may bitcast the
  987. function pointer to a pointer to the constant's type and dereference
  988. index -1. This implies that the IR symbol points just past the end of
  989. the prefix data. For instance, take the example of a function annotated
  990. with a single ``i32``,
  991. .. code-block:: llvm
  992. define void @f() prefix i32 123 { ... }
  993. The prefix data can be referenced as,
  994. .. code-block:: llvm
  995. %0 = bitcast void* () @f to i32*
  996. %a = getelementptr inbounds i32, i32* %0, i32 -1
  997. %b = load i32, i32* %a
  998. Prefix data is laid out as if it were an initializer for a global variable
  999. of the prefix data's type. The function will be placed such that the
  1000. beginning of the prefix data is aligned. This means that if the size
  1001. of the prefix data is not a multiple of the alignment size, the
  1002. function's entrypoint will not be aligned. If alignment of the
  1003. function's entrypoint is desired, padding must be added to the prefix
  1004. data.
  1005. A function may have prefix data but no body. This has similar semantics
  1006. to the ``available_externally`` linkage in that the data may be used by the
  1007. optimizers but will not be emitted in the object file.
  1008. .. _prologuedata:
  1009. Prologue Data
  1010. -------------
  1011. The ``prologue`` attribute allows arbitrary code (encoded as bytes) to
  1012. be inserted prior to the function body. This can be used for enabling
  1013. function hot-patching and instrumentation.
  1014. To maintain the semantics of ordinary function calls, the prologue data must
  1015. have a particular format. Specifically, it must begin with a sequence of
  1016. bytes which decode to a sequence of machine instructions, valid for the
  1017. module's target, which transfer control to the point immediately succeeding
  1018. the prologue data, without performing any other visible action. This allows
  1019. the inliner and other passes to reason about the semantics of the function
  1020. definition without needing to reason about the prologue data. Obviously this
  1021. makes the format of the prologue data highly target dependent.
  1022. A trivial example of valid prologue data for the x86 architecture is ``i8 144``,
  1023. which encodes the ``nop`` instruction:
  1024. .. code-block:: text
  1025. define void @f() prologue i8 144 { ... }
  1026. Generally prologue data can be formed by encoding a relative branch instruction
  1027. which skips the metadata, as in this example of valid prologue data for the
  1028. x86_64 architecture, where the first two bytes encode ``jmp .+10``:
  1029. .. code-block:: text
  1030. %0 = type <{ i8, i8, i8* }>
  1031. define void @f() prologue %0 <{ i8 235, i8 8, i8* @md}> { ... }
  1032. A function may have prologue data but no body. This has similar semantics
  1033. to the ``available_externally`` linkage in that the data may be used by the
  1034. optimizers but will not be emitted in the object file.
  1035. .. _personalityfn:
  1036. Personality Function
  1037. --------------------
  1038. The ``personality`` attribute permits functions to specify what function
  1039. to use for exception handling.
  1040. .. _attrgrp:
  1041. Attribute Groups
  1042. ----------------
  1043. Attribute groups are groups of attributes that are referenced by objects within
  1044. the IR. They are important for keeping ``.ll`` files readable, because a lot of
  1045. functions will use the same set of attributes. In the degenerative case of a
  1046. ``.ll`` file that corresponds to a single ``.c`` file, the single attribute
  1047. group will capture the important command line flags used to build that file.
  1048. An attribute group is a module-level object. To use an attribute group, an
  1049. object references the attribute group's ID (e.g. ``#37``). An object may refer
  1050. to more than one attribute group. In that situation, the attributes from the
  1051. different groups are merged.
  1052. Here is an example of attribute groups for a function that should always be
  1053. inlined, has a stack alignment of 4, and which shouldn't use SSE instructions:
  1054. .. code-block:: llvm
  1055. ; Target-independent attributes:
  1056. attributes #0 = { alwaysinline alignstack=4 }
  1057. ; Target-dependent attributes:
  1058. attributes #1 = { "no-sse" }
  1059. ; Function @f has attributes: alwaysinline, alignstack=4, and "no-sse".
  1060. define void @f() #0 #1 { ... }
  1061. .. _fnattrs:
  1062. Function Attributes
  1063. -------------------
  1064. Function attributes are set to communicate additional information about
  1065. a function. Function attributes are considered to be part of the
  1066. function, not of the function type, so functions with different function
  1067. attributes can have the same function type.
  1068. Function attributes are simple keywords that follow the type specified.
  1069. If multiple attributes are needed, they are space separated. For
  1070. example:
  1071. .. code-block:: llvm
  1072. define void @f() noinline { ... }
  1073. define void @f() alwaysinline { ... }
  1074. define void @f() alwaysinline optsize { ... }
  1075. define void @f() optsize { ... }
  1076. ``alignstack(<n>)``
  1077. This attribute indicates that, when emitting the prologue and
  1078. epilogue, the backend should forcibly align the stack pointer.
  1079. Specify the desired alignment, which must be a power of two, in
  1080. parentheses.
  1081. ``allocsize(<EltSizeParam>[, <NumEltsParam>])``
  1082. This attribute indicates that the annotated function will always return at
  1083. least a given number of bytes (or null). Its arguments are zero-indexed
  1084. parameter numbers; if one argument is provided, then it's assumed that at
  1085. least ``CallSite.Args[EltSizeParam]`` bytes will be available at the
  1086. returned pointer. If two are provided, then it's assumed that
  1087. ``CallSite.Args[EltSizeParam] * CallSite.Args[NumEltsParam]`` bytes are
  1088. available. The referenced parameters must be integer types. No assumptions
  1089. are made about the contents of the returned block of memory.
  1090. ``alwaysinline``
  1091. This attribute indicates that the inliner should attempt to inline
  1092. this function into callers whenever possible, ignoring any active
  1093. inlining size threshold for this caller.
  1094. ``builtin``
  1095. This indicates that the callee function at a call site should be
  1096. recognized as a built-in function, even though the function's declaration
  1097. uses the ``nobuiltin`` attribute. This is only valid at call sites for
  1098. direct calls to functions that are declared with the ``nobuiltin``
  1099. attribute.
  1100. ``cold``
  1101. This attribute indicates that this function is rarely called. When
  1102. computing edge weights, basic blocks post-dominated by a cold
  1103. function call are also considered to be cold; and, thus, given low
  1104. weight.
  1105. ``convergent``
  1106. In some parallel execution models, there exist operations that cannot be
  1107. made control-dependent on any additional values. We call such operations
  1108. ``convergent``, and mark them with this attribute.
  1109. The ``convergent`` attribute may appear on functions or call/invoke
  1110. instructions. When it appears on a function, it indicates that calls to
  1111. this function should not be made control-dependent on additional values.
  1112. For example, the intrinsic ``llvm.nvvm.barrier0`` is ``convergent``, so
  1113. calls to this intrinsic cannot be made control-dependent on additional
  1114. values.
  1115. When it appears on a call/invoke, the ``convergent`` attribute indicates
  1116. that we should treat the call as though we're calling a convergent
  1117. function. This is particularly useful on indirect calls; without this we
  1118. may treat such calls as though the target is non-convergent.
  1119. The optimizer may remove the ``convergent`` attribute on functions when it
  1120. can prove that the function does not execute any convergent operations.
  1121. Similarly, the optimizer may remove ``convergent`` on calls/invokes when it
  1122. can prove that the call/invoke cannot call a convergent function.
  1123. ``inaccessiblememonly``
  1124. This attribute indicates that the function may only access memory that
  1125. is not accessible by the module being compiled. This is a weaker form
  1126. of ``readnone``. If the function reads or writes other memory, the
  1127. behavior is undefined.
  1128. ``inaccessiblemem_or_argmemonly``
  1129. This attribute indicates that the function may only access memory that is
  1130. either not accessible by the module being compiled, or is pointed to
  1131. by its pointer arguments. This is a weaker form of ``argmemonly``. If the
  1132. function reads or writes other memory, the behavior is undefined.
  1133. ``inlinehint``
  1134. This attribute indicates that the source code contained a hint that
  1135. inlining this function is desirable (such as the "inline" keyword in
  1136. C/C++). It is just a hint; it imposes no requirements on the
  1137. inliner.
  1138. ``jumptable``
  1139. This attribute indicates that the function should be added to a
  1140. jump-instruction table at code-generation time, and that all address-taken
  1141. references to this function should be replaced with a reference to the
  1142. appropriate jump-instruction-table function pointer. Note that this creates
  1143. a new pointer for the original function, which means that code that depends
  1144. on function-pointer identity can break. So, any function annotated with
  1145. ``jumptable`` must also be ``unnamed_addr``.
  1146. ``minsize``
  1147. This attribute suggests that optimization passes and code generator
  1148. passes make choices that keep the code size of this function as small
  1149. as possible and perform optimizations that may sacrifice runtime
  1150. performance in order to minimize the size of the generated code.
  1151. ``naked``
  1152. This attribute disables prologue / epilogue emission for the
  1153. function. This can have very system-specific consequences.
  1154. ``no-jump-tables``
  1155. When this attribute is set to true, the jump tables and lookup tables that
  1156. can be generated from a switch case lowering are disabled.
  1157. ``nobuiltin``
  1158. This indicates that the callee function at a call site is not recognized as
  1159. a built-in function. LLVM will retain the original call and not replace it
  1160. with equivalent code based on the semantics of the built-in function, unless
  1161. the call site uses the ``builtin`` attribute. This is valid at call sites
  1162. and on function declarations and definitions.
  1163. ``noduplicate``
  1164. This attribute indicates that calls to the function cannot be
  1165. duplicated. A call to a ``noduplicate`` function may be moved
  1166. within its parent function, but may not be duplicated within
  1167. its parent function.
  1168. A function containing a ``noduplicate`` call may still
  1169. be an inlining candidate, provided that the call is not
  1170. duplicated by inlining. That implies that the function has
  1171. internal linkage and only has one call site, so the original
  1172. call is dead after inlining.
  1173. ``nofree``
  1174. This function attribute indicates that the function does not, directly or
  1175. indirectly, call a memory-deallocation function (free, for example). As a
  1176. result, uncaptured pointers that are known to be dereferenceable prior to a
  1177. call to a function with the ``nofree`` attribute are still known to be
  1178. dereferenceable after the call (the capturing condition is necessary in
  1179. environments where the function might communicate the pointer to another thread
  1180. which then deallocates the memory).
  1181. ``noimplicitfloat``
  1182. This attributes disables implicit floating-point instructions.
  1183. ``noinline``
  1184. This attribute indicates that the inliner should never inline this
  1185. function in any situation. This attribute may not be used together
  1186. with the ``alwaysinline`` attribute.
  1187. ``nonlazybind``
  1188. This attribute suppresses lazy symbol binding for the function. This
  1189. may make calls to the function faster, at the cost of extra program
  1190. startup time if the function is not called during program startup.
  1191. ``noredzone``
  1192. This attribute indicates that the code generator should not use a
  1193. red zone, even if the target-specific ABI normally permits it.
  1194. ``indirect-tls-seg-refs``
  1195. This attribute indicates that the code generator should not use
  1196. direct TLS access through segment registers, even if the
  1197. target-specific ABI normally permits it.
  1198. ``noreturn``
  1199. This function attribute indicates that the function never returns
  1200. normally, hence through a return instruction. This produces undefined
  1201. behavior at runtime if the function ever does dynamically return. Annotated
  1202. functions may still raise an exception, i.a., ``nounwind`` is not implied.
  1203. ``norecurse``
  1204. This function attribute indicates that the function does not call itself
  1205. either directly or indirectly down any possible call path. This produces
  1206. undefined behavior at runtime if the function ever does recurse.
  1207. ``willreturn``
  1208. This function attribute indicates that a call of this function will
  1209. either exhibit undefined behavior or comes back and continues execution
  1210. at a point in the existing call stack that includes the current invocation.
  1211. Annotated functions may still raise an exception, i.a., ``nounwind`` is not implied.
  1212. If an invocation of an annotated function does not return control back
  1213. to a point in the call stack, the behavior is undefined.
  1214. ``nosync``
  1215. This function attribute indicates that the function does not communicate
  1216. (synchronize) with another thread through memory or other well-defined means.
  1217. Synchronization is considered possible in the presence of `atomic` accesses
  1218. that enforce an order, thus not "unordered" and "monotonic", `volatile` accesses,
  1219. as well as `convergent` function calls. Note that through `convergent` function calls
  1220. non-memory communication, e.g., cross-lane operations, are possible and are also
  1221. considered synchronization. However `convergent` does not contradict `nosync`.
  1222. If an annotated function does ever synchronize with another thread,
  1223. the behavior is undefined.
  1224. ``nounwind``
  1225. This function attribute indicates that the function never raises an
  1226. exception. If the function does raise an exception, its runtime
  1227. behavior is undefined. However, functions marked nounwind may still
  1228. trap or generate asynchronous exceptions. Exception handling schemes
  1229. that are recognized by LLVM to handle asynchronous exceptions, such
  1230. as SEH, will still provide their implementation defined semantics.
  1231. ``"null-pointer-is-valid"``
  1232. If ``"null-pointer-is-valid"`` is set to ``"true"``, then ``null`` address
  1233. in address-space 0 is considered to be a valid address for memory loads and
  1234. stores. Any analysis or optimization should not treat dereferencing a
  1235. pointer to ``null`` as undefined behavior in this function.
  1236. Note: Comparing address of a global variable to ``null`` may still
  1237. evaluate to false because of a limitation in querying this attribute inside
  1238. constant expressions.
  1239. ``optforfuzzing``
  1240. This attribute indicates that this function should be optimized
  1241. for maximum fuzzing signal.
  1242. ``optnone``
  1243. This function attribute indicates that most optimization passes will skip
  1244. this function, with the exception of interprocedural optimization passes.
  1245. Code generation defaults to the "fast" instruction selector.
  1246. This attribute cannot be used together with the ``alwaysinline``
  1247. attribute; this attribute is also incompatible
  1248. with the ``minsize`` attribute and the ``optsize`` attribute.
  1249. This attribute requires the ``noinline`` attribute to be specified on
  1250. the function as well, so the function is never inlined into any caller.
  1251. Only functions with the ``alwaysinline`` attribute are valid
  1252. candidates for inlining into the body of this function.
  1253. ``optsize``
  1254. This attribute suggests that optimization passes and code generator
  1255. passes make choices that keep the code size of this function low,
  1256. and otherwise do optimizations specifically to reduce code size as
  1257. long as they do not significantly impact runtime performance.
  1258. ``"patchable-function"``
  1259. This attribute tells the code generator that the code
  1260. generated for this function needs to follow certain conventions that
  1261. make it possible for a runtime function to patch over it later.
  1262. The exact effect of this attribute depends on its string value,
  1263. for which there currently is one legal possibility:
  1264. * ``"prologue-short-redirect"`` - This style of patchable
  1265. function is intended to support patching a function prologue to
  1266. redirect control away from the function in a thread safe
  1267. manner. It guarantees that the first instruction of the
  1268. function will be large enough to accommodate a short jump
  1269. instruction, and will be sufficiently aligned to allow being
  1270. fully changed via an atomic compare-and-swap instruction.
  1271. While the first requirement can be satisfied by inserting large
  1272. enough NOP, LLVM can and will try to re-purpose an existing
  1273. instruction (i.e. one that would have to be emitted anyway) as
  1274. the patchable instruction larger than a short jump.
  1275. ``"prologue-short-redirect"`` is currently only supported on
  1276. x86-64.
  1277. This attribute by itself does not imply restrictions on
  1278. inter-procedural optimizations. All of the semantic effects the
  1279. patching may have to be separately conveyed via the linkage type.
  1280. ``"probe-stack"``
  1281. This attribute indicates that the function will trigger a guard region
  1282. in the end of the stack. It ensures that accesses to the stack must be
  1283. no further apart than the size of the guard region to a previous
  1284. access of the stack. It takes one required string value, the name of
  1285. the stack probing function that will be called.
  1286. If a function that has a ``"probe-stack"`` attribute is inlined into
  1287. a function with another ``"probe-stack"`` attribute, the resulting
  1288. function has the ``"probe-stack"`` attribute of the caller. If a
  1289. function that has a ``"probe-stack"`` attribute is inlined into a
  1290. function that has no ``"probe-stack"`` attribute at all, the resulting
  1291. function has the ``"probe-stack"`` attribute of the callee.
  1292. ``readnone``
  1293. On a function, this attribute indicates that the function computes its
  1294. result (or decides to unwind an exception) based strictly on its arguments,
  1295. without dereferencing any pointer arguments or otherwise accessing
  1296. any mutable state (e.g. memory, control registers, etc) visible to
  1297. caller functions. It does not write through any pointer arguments
  1298. (including ``byval`` arguments) and never changes any state visible
  1299. to callers. This means while it cannot unwind exceptions by calling
  1300. the ``C++`` exception throwing methods (since they write to memory), there may
  1301. be non-``C++`` mechanisms that throw exceptions without writing to LLVM
  1302. visible memory.
  1303. On an argument, this attribute indicates that the function does not
  1304. dereference that pointer argument, even though it may read or write the
  1305. memory that the pointer points to if accessed through other pointers.
  1306. If a readnone function reads or writes memory visible to the program, or
  1307. has other side-effects, the behavior is undefined. If a function reads from
  1308. or writes to a readnone pointer argument, the behavior is undefined.
  1309. ``readonly``
  1310. On a function, this attribute indicates that the function does not write
  1311. through any pointer arguments (including ``byval`` arguments) or otherwise
  1312. modify any state (e.g. memory, control registers, etc) visible to
  1313. caller functions. It may dereference pointer arguments and read
  1314. state that may be set in the caller. A readonly function always
  1315. returns the same value (or unwinds an exception identically) when
  1316. called with the same set of arguments and global state. This means while it
  1317. cannot unwind exceptions by calling the ``C++`` exception throwing methods
  1318. (since they write to memory), there may be non-``C++`` mechanisms that throw
  1319. exceptions without writing to LLVM visible memory.
  1320. On an argument, this attribute indicates that the function does not write
  1321. through this pointer argument, even though it may write to the memory that
  1322. the pointer points to.
  1323. If a readonly function writes memory visible to the program, or
  1324. has other side-effects, the behavior is undefined. If a function writes to
  1325. a readonly pointer argument, the behavior is undefined.
  1326. ``"stack-probe-size"``
  1327. This attribute controls the behavior of stack probes: either
  1328. the ``"probe-stack"`` attribute, or ABI-required stack probes, if any.
  1329. It defines the size of the guard region. It ensures that if the function
  1330. may use more stack space than the size of the guard region, stack probing
  1331. sequence will be emitted. It takes one required integer value, which
  1332. is 4096 by default.
  1333. If a function that has a ``"stack-probe-size"`` attribute is inlined into
  1334. a function with another ``"stack-probe-size"`` attribute, the resulting
  1335. function has the ``"stack-probe-size"`` attribute that has the lower
  1336. numeric value. If a function that has a ``"stack-probe-size"`` attribute is
  1337. inlined into a function that has no ``"stack-probe-size"`` attribute
  1338. at all, the resulting function has the ``"stack-probe-size"`` attribute
  1339. of the callee.
  1340. ``"no-stack-arg-probe"``
  1341. This attribute disables ABI-required stack probes, if any.
  1342. ``writeonly``
  1343. On a function, this attribute indicates that the function may write to but
  1344. does not read from memory.
  1345. On an argument, this attribute indicates that the function may write to but
  1346. does not read through this pointer argument (even though it may read from
  1347. the memory that the pointer points to).
  1348. If a writeonly function reads memory visible to the program, or
  1349. has other side-effects, the behavior is undefined. If a function reads
  1350. from a writeonly pointer argument, the behavior is undefined.
  1351. ``argmemonly``
  1352. This attribute indicates that the only memory accesses inside function are
  1353. loads and stores from objects pointed to by its pointer-typed arguments,
  1354. with arbitrary offsets. Or in other words, all memory operations in the
  1355. function can refer to memory only using pointers based on its function
  1356. arguments.
  1357. Note that ``argmemonly`` can be used together with ``readonly`` attribute
  1358. in order to specify that function reads only from its arguments.
  1359. If an argmemonly function reads or writes memory other than the pointer
  1360. arguments, or has other side-effects, the behavior is undefined.
  1361. ``returns_twice``
  1362. This attribute indicates that this function can return twice. The C
  1363. ``setjmp`` is an example of such a function. The compiler disables
  1364. some optimizations (like tail calls) in the caller of these
  1365. functions.
  1366. ``safestack``
  1367. This attribute indicates that
  1368. `SafeStack <http://clang.llvm.org/docs/SafeStack.html>`_
  1369. protection is enabled for this function.
  1370. If a function that has a ``safestack`` attribute is inlined into a
  1371. function that doesn't have a ``safestack`` attribute or which has an
  1372. ``ssp``, ``sspstrong`` or ``sspreq`` attribute, then the resulting
  1373. function will have a ``safestack`` attribute.
  1374. ``sanitize_address``
  1375. This attribute indicates that AddressSanitizer checks
  1376. (dynamic address safety analysis) are enabled for this function.
  1377. ``sanitize_memory``
  1378. This attribute indicates that MemorySanitizer checks (dynamic detection
  1379. of accesses to uninitialized memory) are enabled for this function.
  1380. ``sanitize_thread``
  1381. This attribute indicates that ThreadSanitizer checks
  1382. (dynamic thread safety analysis) are enabled for this function.
  1383. ``sanitize_hwaddress``
  1384. This attribute indicates that HWAddressSanitizer checks
  1385. (dynamic address safety analysis based on tagged pointers) are enabled for
  1386. this function.
  1387. ``sanitize_memtag``
  1388. This attribute indicates that MemTagSanitizer checks
  1389. (dynamic address safety analysis based on Armv8 MTE) are enabled for
  1390. this function.
  1391. ``speculative_load_hardening``
  1392. This attribute indicates that
  1393. `Speculative Load Hardening <https://llvm.org/docs/SpeculativeLoadHardening.html>`_
  1394. should be enabled for the function body.
  1395. Speculative Load Hardening is a best-effort mitigation against
  1396. information leak attacks that make use of control flow
  1397. miss-speculation - specifically miss-speculation of whether a branch
  1398. is taken or not. Typically vulnerabilities enabling such attacks are
  1399. classified as "Spectre variant #1". Notably, this does not attempt to
  1400. mitigate against miss-speculation of branch target, classified as
  1401. "Spectre variant #2" vulnerabilities.
  1402. When inlining, the attribute is sticky. Inlining a function that carries
  1403. this attribute will cause the caller to gain the attribute. This is intended
  1404. to provide a maximally conservative model where the code in a function
  1405. annotated with this attribute will always (even after inlining) end up
  1406. hardened.
  1407. ``speculatable``
  1408. This function attribute indicates that the function does not have any
  1409. effects besides calculating its result and does not have undefined behavior.
  1410. Note that ``speculatable`` is not enough to conclude that along any
  1411. particular execution path the number of calls to this function will not be
  1412. externally observable. This attribute is only valid on functions
  1413. and declarations, not on individual call sites. If a function is
  1414. incorrectly marked as speculatable and really does exhibit
  1415. undefined behavior, the undefined behavior may be observed even
  1416. if the call site is dead code.
  1417. ``ssp``
  1418. This attribute indicates that the function should emit a stack
  1419. smashing protector. It is in the form of a "canary" --- a random value
  1420. placed on the stack before the local variables that's checked upon
  1421. return from the function to see if it has been overwritten. A
  1422. heuristic is used to determine if a function needs stack protectors
  1423. or not. The heuristic used will enable protectors for functions with:
  1424. - Character arrays larger than ``ssp-buffer-size`` (default 8).
  1425. - Aggregates containing character arrays larger than ``ssp-buffer-size``.
  1426. - Calls to alloca() with variable sizes or constant sizes greater than
  1427. ``ssp-buffer-size``.
  1428. Variables that are identified as requiring a protector will be arranged
  1429. on the stack such that they are adjacent to the stack protector guard.
  1430. If a function that has an ``ssp`` attribute is inlined into a
  1431. function that doesn't have an ``ssp`` attribute, then the resulting
  1432. function will have an ``ssp`` attribute.
  1433. ``sspreq``
  1434. This attribute indicates that the function should *always* emit a
  1435. stack smashing protector. This overrides the ``ssp`` function
  1436. attribute.
  1437. Variables that are identified as requiring a protector will be arranged
  1438. on the stack such that they are adjacent to the stack protector guard.
  1439. The specific layout rules are:
  1440. #. Large arrays and structures containing large arrays
  1441. (``>= ssp-buffer-size``) are closest to the stack protector.
  1442. #. Small arrays and structures containing small arrays
  1443. (``< ssp-buffer-size``) are 2nd closest to the protector.
  1444. #. Variables that have had their address taken are 3rd closest to the
  1445. protector.
  1446. If a function that has an ``sspreq`` attribute is inlined into a
  1447. function that doesn't have an ``sspreq`` attribute or which has an
  1448. ``ssp`` or ``sspstrong`` attribute, then the resulting function will have
  1449. an ``sspreq`` attribute.
  1450. ``sspstrong``
  1451. This attribute indicates that the function should emit a stack smashing
  1452. protector. This attribute causes a strong heuristic to be used when
  1453. determining if a function needs stack protectors. The strong heuristic
  1454. will enable protectors for functions with:
  1455. - Arrays of any size and type
  1456. - Aggregates containing an array of any size and type.
  1457. - Calls to alloca().
  1458. - Local variables that have had their address taken.
  1459. Variables that are identified as requiring a protector will be arranged
  1460. on the stack such that they are adjacent to the stack protector guard.
  1461. The specific layout rules are:
  1462. #. Large arrays and structures containing large arrays
  1463. (``>= ssp-buffer-size``) are closest to the stack protector.
  1464. #. Small arrays and structures containing small arrays
  1465. (``< ssp-buffer-size``) are 2nd closest to the protector.
  1466. #. Variables that have had their address taken are 3rd closest to the
  1467. protector.
  1468. This overrides the ``ssp`` function attribute.
  1469. If a function that has an ``sspstrong`` attribute is inlined into a
  1470. function that doesn't have an ``sspstrong`` attribute, then the
  1471. resulting function will have an ``sspstrong`` attribute.
  1472. ``strictfp``
  1473. This attribute indicates that the function was called from a scope that
  1474. requires strict floating-point semantics. LLVM will not attempt any
  1475. optimizations that require assumptions about the floating-point rounding
  1476. mode or that might alter the state of floating-point status flags that
  1477. might otherwise be set or cleared by calling this function. LLVM will
  1478. not introduce any new floating-point instructions that may trap.
  1479. ``"thunk"``
  1480. This attribute indicates that the function will delegate to some other
  1481. function with a tail call. The prototype of a thunk should not be used for
  1482. optimization purposes. The caller is expected to cast the thunk prototype to
  1483. match the thunk target prototype.
  1484. ``uwtable``
  1485. This attribute indicates that the ABI being targeted requires that
  1486. an unwind table entry be produced for this function even if we can
  1487. show that no exceptions passes by it. This is normally the case for
  1488. the ELF x86-64 abi, but it can be disabled for some compilation
  1489. units.
  1490. ``nocf_check``
  1491. This attribute indicates that no control-flow check will be performed on
  1492. the attributed entity. It disables -fcf-protection=<> for a specific
  1493. entity to fine grain the HW control flow protection mechanism. The flag
  1494. is target independent and currently appertains to a function or function
  1495. pointer.
  1496. ``shadowcallstack``
  1497. This attribute indicates that the ShadowCallStack checks are enabled for
  1498. the function. The instrumentation checks that the return address for the
  1499. function has not changed between the function prolog and eiplog. It is
  1500. currently x86_64-specific.
  1501. .. _glattrs:
  1502. Global Attributes
  1503. -----------------
  1504. Attributes may be set to communicate additional information about a global variable.
  1505. Unlike :ref:`function attributes <fnattrs>`, attributes on a global variable
  1506. are grouped into a single :ref:`attribute group <attrgrp>`.
  1507. .. _opbundles:
  1508. Operand Bundles
  1509. ---------------
  1510. Operand bundles are tagged sets of SSA values that can be associated
  1511. with certain LLVM instructions (currently only ``call`` s and
  1512. ``invoke`` s). In a way they are like metadata, but dropping them is
  1513. incorrect and will change program semantics.
  1514. Syntax::
  1515. operand bundle set ::= '[' operand bundle (, operand bundle )* ']'
  1516. operand bundle ::= tag '(' [ bundle operand ] (, bundle operand )* ')'
  1517. bundle operand ::= SSA value
  1518. tag ::= string constant
  1519. Operand bundles are **not** part of a function's signature, and a
  1520. given function may be called from multiple places with different kinds
  1521. of operand bundles. This reflects the fact that the operand bundles
  1522. are conceptually a part of the ``call`` (or ``invoke``), not the
  1523. callee being dispatched to.
  1524. Operand bundles are a generic mechanism intended to support
  1525. runtime-introspection-like functionality for managed languages. While
  1526. the exact semantics of an operand bundle depend on the bundle tag,
  1527. there are certain limitations to how much the presence of an operand
  1528. bundle can influence the semantics of a program. These restrictions
  1529. are described as the semantics of an "unknown" operand bundle. As
  1530. long as the behavior of an operand bundle is describable within these
  1531. restrictions, LLVM does not need to have special knowledge of the
  1532. operand bundle to not miscompile programs containing it.
  1533. - The bundle operands for an unknown operand bundle escape in unknown
  1534. ways before control is transferred to the callee or invokee.
  1535. - Calls and invokes with operand bundles have unknown read / write
  1536. effect on the heap on entry and exit (even if the call target is
  1537. ``readnone`` or ``readonly``), unless they're overridden with
  1538. callsite specific attributes.
  1539. - An operand bundle at a call site cannot change the implementation
  1540. of the called function. Inter-procedural optimizations work as
  1541. usual as long as they take into account the first two properties.
  1542. More specific types of operand bundles are described below.
  1543. .. _deopt_opbundles:
  1544. Deoptimization Operand Bundles
  1545. ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  1546. Deoptimization operand bundles are characterized by the ``"deopt"``
  1547. operand bundle tag. These operand bundles represent an alternate
  1548. "safe" continuation for the call site they're attached to, and can be
  1549. used by a suitable runtime to deoptimize the compiled frame at the
  1550. specified call site. There can be at most one ``"deopt"`` operand
  1551. bundle attached to a call site. Exact details of deoptimization is
  1552. out of scope for the language reference, but it usually involves
  1553. rewriting a compiled frame into a set of interpreted frames.
  1554. From the compiler's perspective, deoptimization operand bundles make
  1555. the call sites they're attached to at least ``readonly``. They read
  1556. through all of their pointer typed operands (even if they're not
  1557. otherwise escaped) and the entire visible heap. Deoptimization
  1558. operand bundles do not capture their operands except during
  1559. deoptimization, in which case control will not be returned to the
  1560. compiled frame.
  1561. The inliner knows how to inline through calls that have deoptimization
  1562. operand bundles. Just like inlining through a normal call site
  1563. involves composing the normal and exceptional continuations, inlining
  1564. through a call site with a deoptimization operand bundle needs to
  1565. appropriately compose the "safe" deoptimization continuation. The
  1566. inliner does this by prepending the parent's deoptimization
  1567. continuation to every deoptimization continuation in the inlined body.
  1568. E.g. inlining ``@f`` into ``@g`` in the following example
  1569. .. code-block:: llvm
  1570. define void @f() {
  1571. call void @x() ;; no deopt state
  1572. call void @y() [ "deopt"(i32 10) ]
  1573. call void @y() [ "deopt"(i32 10), "unknown"(i8* null) ]
  1574. ret void
  1575. }
  1576. define void @g() {
  1577. call void @f() [ "deopt"(i32 20) ]
  1578. ret void
  1579. }
  1580. will result in
  1581. .. code-block:: llvm
  1582. define void @g() {
  1583. call void @x() ;; still no deopt state
  1584. call void @y() [ "deopt"(i32 20, i32 10) ]
  1585. call void @y() [ "deopt"(i32 20, i32 10), "unknown"(i8* null) ]
  1586. ret void
  1587. }
  1588. It is the frontend's responsibility to structure or encode the
  1589. deoptimization state in a way that syntactically prepending the
  1590. caller's deoptimization state to the callee's deoptimization state is
  1591. semantically equivalent to composing the caller's deoptimization
  1592. continuation after the callee's deoptimization continuation.
  1593. .. _ob_funclet:
  1594. Funclet Operand Bundles
  1595. ^^^^^^^^^^^^^^^^^^^^^^^
  1596. Funclet operand bundles are characterized by the ``"funclet"``
  1597. operand bundle tag. These operand bundles indicate that a call site
  1598. is within a particular funclet. There can be at most one
  1599. ``"funclet"`` operand bundle attached to a call site and it must have
  1600. exactly one bundle operand.
  1601. If any funclet EH pads have been "entered" but not "exited" (per the
  1602. `description in the EH doc\ <ExceptionHandling.html#wineh-constraints>`_),
  1603. it is undefined behavior to execute a ``call`` or ``invoke`` which:
  1604. * does not have a ``"funclet"`` bundle and is not a ``call`` to a nounwind
  1605. intrinsic, or
  1606. * has a ``"funclet"`` bundle whose operand is not the most-recently-entered
  1607. not-yet-exited funclet EH pad.
  1608. Similarly, if no funclet EH pads have been entered-but-not-yet-exited,
  1609. executing a ``call`` or ``invoke`` with a ``"funclet"`` bundle is undefined behavior.
  1610. GC Transition Operand Bundles
  1611. ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  1612. GC transition operand bundles are characterized by the
  1613. ``"gc-transition"`` operand bundle tag. These operand bundles mark a
  1614. call as a transition between a function with one GC strategy to a
  1615. function with a different GC strategy. If coordinating the transition
  1616. between GC strategies requires additional code generation at the call
  1617. site, these bundles may contain any values that are needed by the
  1618. generated code. For more details, see :ref:`GC Transitions
  1619. <gc_transition_args>`.
  1620. .. _moduleasm:
  1621. Module-Level Inline Assembly
  1622. ----------------------------
  1623. Modules may contain "module-level inline asm" blocks, which corresponds
  1624. to the GCC "file scope inline asm" blocks. These blocks are internally
  1625. concatenated by LLVM and treated as a single unit, but may be separated
  1626. in the ``.ll`` file if desired. The syntax is very simple:
  1627. .. code-block:: llvm
  1628. module asm "inline asm code goes here"
  1629. module asm "more can go here"
  1630. The strings can contain any character by escaping non-printable
  1631. characters. The escape sequence used is simply "\\xx" where "xx" is the
  1632. two digit hex code for the number.
  1633. Note that the assembly string *must* be parseable by LLVM's integrated assembler
  1634. (unless it is disabled), even when emitting a ``.s`` file.
  1635. .. _langref_datalayout:
  1636. Data Layout
  1637. -----------
  1638. A module may specify a target specific data layout string that specifies
  1639. how data is to be laid out in memory. The syntax for the data layout is
  1640. simply:
  1641. .. code-block:: llvm
  1642. target datalayout = "layout specification"
  1643. The *layout specification* consists of a list of specifications
  1644. separated by the minus sign character ('-'). Each specification starts
  1645. with a letter and may include other information after the letter to
  1646. define some aspect of the data layout. The specifications accepted are
  1647. as follows:
  1648. ``E``
  1649. Specifies that the target lays out data in big-endian form. That is,
  1650. the bits with the most significance have the lowest address
  1651. location.
  1652. ``e``
  1653. Specifies that the target lays out data in little-endian form. That
  1654. is, the bits with the least significance have the lowest address
  1655. location.
  1656. ``S<size>``
  1657. Specifies the natural alignment of the stack in bits. Alignment
  1658. promotion of stack variables is limited to the natural stack
  1659. alignment to avoid dynamic stack realignment. The stack alignment
  1660. must be a multiple of 8-bits. If omitted, the natural stack
  1661. alignment defaults to "unspecified", which does not prevent any
  1662. alignment promotions.
  1663. ``P<address space>``
  1664. Specifies the address space that corresponds to program memory.
  1665. Harvard architectures can use this to specify what space LLVM
  1666. should place things such as functions into. If omitted, the
  1667. program memory space defaults to the default address space of 0,
  1668. which corresponds to a Von Neumann architecture that has code
  1669. and data in the same space.
  1670. ``A<address space>``
  1671. Specifies the address space of objects created by '``alloca``'.
  1672. Defaults to the default address space of 0.
  1673. ``p[n]:<size>:<abi>:<pref>:<idx>``
  1674. This specifies the *size* of a pointer and its ``<abi>`` and
  1675. ``<pref>``\erred alignments for address space ``n``. The fourth parameter
  1676. ``<idx>`` is a size of index that used for address calculation. If not
  1677. specified, the default index size is equal to the pointer size. All sizes
  1678. are in bits. The address space, ``n``, is optional, and if not specified,
  1679. denotes the default address space 0. The value of ``n`` must be
  1680. in the range [1,2^23).
  1681. ``i<size>:<abi>:<pref>``
  1682. This specifies the alignment for an integer type of a given bit
  1683. ``<size>``. The value of ``<size>`` must be in the range [1,2^23).
  1684. ``v<size>:<abi>:<pref>``
  1685. This specifies the alignment for a vector type of a given bit
  1686. ``<size>``.
  1687. ``f<size>:<abi>:<pref>``
  1688. This specifies the alignment for a floating-point type of a given bit
  1689. ``<size>``. Only values of ``<size>`` that are supported by the target
  1690. will work. 32 (float) and 64 (double) are supported on all targets; 80
  1691. or 128 (different flavors of long double) are also supported on some
  1692. targets.
  1693. ``a:<abi>:<pref>``
  1694. This specifies the alignment for an object of aggregate type.
  1695. ``F<type><abi>``
  1696. This specifies the alignment for function pointers.
  1697. The options for ``<type>`` are:
  1698. * ``i``: The alignment of function pointers is independent of the alignment
  1699. of functions, and is a multiple of ``<abi>``.
  1700. * ``n``: The alignment of function pointers is a multiple of the explicit
  1701. alignment specified on the function, and is a multiple of ``<abi>``.
  1702. ``m:<mangling>``
  1703. If present, specifies that llvm names are mangled in the output. Symbols
  1704. prefixed with the mangling escape character ``\01`` are passed through
  1705. directly to the assembler without the escape character. The mangling style
  1706. options are
  1707. * ``e``: ELF mangling: Private symbols get a ``.L`` prefix.
  1708. * ``m``: Mips mangling: Private symbols get a ``$`` prefix.
  1709. * ``o``: Mach-O mangling: Private symbols get ``L`` prefix. Other
  1710. symbols get a ``_`` prefix.
  1711. * ``x``: Windows x86 COFF mangling: Private symbols get the usual prefix.
  1712. Regular C symbols get a ``_`` prefix. Functions with ``__stdcall``,
  1713. ``__fastcall``, and ``__vectorcall`` have custom mangling that appends
  1714. ``@N`` where N is the number of bytes used to pass parameters. C++ symbols
  1715. starting with ``?`` are not mangled in any way.
  1716. * ``w``: Windows COFF mangling: Similar to ``x``, except that normal C
  1717. symbols do not receive a ``_`` prefix.
  1718. ``n<size1>:<size2>:<size3>...``
  1719. This specifies a set of native integer widths for the target CPU in
  1720. bits. For example, it might contain ``n32`` for 32-bit PowerPC,
  1721. ``n32:64`` for PowerPC 64, or ``n8:16:32:64`` for X86-64. Elements of
  1722. this set are considered to support most general arithmetic operations
  1723. efficiently.
  1724. ``ni:<address space0>:<address space1>:<address space2>...``
  1725. This specifies pointer types with the specified address spaces
  1726. as :ref:`Non-Integral Pointer Type <nointptrtype>` s. The ``0``
  1727. address space cannot be specified as non-integral.
  1728. On every specification that takes a ``<abi>:<pref>``, specifying the
  1729. ``<pref>`` alignment is optional. If omitted, the preceding ``:``
  1730. should be omitted too and ``<pref>`` will be equal to ``<abi>``.
  1731. When constructing the data layout for a given target, LLVM starts with a
  1732. default set of specifications which are then (possibly) overridden by
  1733. the specifications in the ``datalayout`` keyword. The default
  1734. specifications are given in this list:
  1735. - ``E`` - big endian
  1736. - ``p:64:64:64`` - 64-bit pointers with 64-bit alignment.
  1737. - ``p[n]:64:64:64`` - Other address spaces are assumed to be the
  1738. same as the default address space.
  1739. - ``S0`` - natural stack alignment is unspecified
  1740. - ``i1:8:8`` - i1 is 8-bit (byte) aligned
  1741. - ``i8:8:8`` - i8 is 8-bit (byte) aligned
  1742. - ``i16:16:16`` - i16 is 16-bit aligned
  1743. - ``i32:32:32`` - i32 is 32-bit aligned
  1744. - ``i64:32:64`` - i64 has ABI alignment of 32-bits but preferred
  1745. alignment of 64-bits
  1746. - ``f16:16:16`` - half is 16-bit aligned
  1747. - ``f32:32:32`` - float is 32-bit aligned
  1748. - ``f64:64:64`` - double is 64-bit aligned
  1749. - ``f128:128:128`` - quad is 128-bit aligned
  1750. - ``v64:64:64`` - 64-bit vector is 64-bit aligned
  1751. - ``v128:128:128`` - 128-bit vector is 128-bit aligned
  1752. - ``a:0:64`` - aggregates are 64-bit aligned
  1753. When LLVM is determining the alignment for a given type, it uses the
  1754. following rules:
  1755. #. If the type sought is an exact match for one of the specifications,
  1756. that specification is used.
  1757. #. If no match is found, and the type sought is an integer type, then
  1758. the smallest integer type that is larger than the bitwidth of the
  1759. sought type is used. If none of the specifications are larger than
  1760. the bitwidth then the largest integer type is used. For example,
  1761. given the default specifications above, the i7 type will use the
  1762. alignment of i8 (next largest) while both i65 and i256 will use the
  1763. alignment of i64 (largest specified).
  1764. #. If no match is found, and the type sought is a vector type, then the
  1765. largest vector type that is smaller than the sought vector type will
  1766. be used as a fall back. This happens because <128 x double> can be
  1767. implemented in terms of 64 <2 x double>, for example.
  1768. The function of the data layout string may not be what you expect.
  1769. Notably, this is not a specification from the frontend of what alignment
  1770. the code generator should use.
  1771. Instead, if specified, the target data layout is required to match what
  1772. the ultimate *code generator* expects. This string is used by the
  1773. mid-level optimizers to improve code, and this only works if it matches
  1774. what the ultimate code generator uses. There is no way to generate IR
  1775. that does not embed this target-specific detail into the IR. If you
  1776. don't specify the string, the default specifications will be used to
  1777. generate a Data Layout and the optimization phases will operate
  1778. accordingly and introduce target specificity into the IR with respect to
  1779. these default specifications.
  1780. .. _langref_triple:
  1781. Target Triple
  1782. -------------
  1783. A module may specify a target triple string that describes the target
  1784. host. The syntax for the target triple is simply:
  1785. .. code-block:: llvm
  1786. target triple = "x86_64-apple-macosx10.7.0"
  1787. The *target triple* string consists of a series of identifiers delimited
  1788. by the minus sign character ('-'). The canonical forms are:
  1789. ::
  1790. ARCHITECTURE-VENDOR-OPERATING_SYSTEM
  1791. ARCHITECTURE-VENDOR-OPERATING_SYSTEM-ENVIRONMENT
  1792. This information is passed along to the backend so that it generates
  1793. code for the proper architecture. It's possible to override this on the
  1794. command line with the ``-mtriple`` command line option.
  1795. .. _pointeraliasing:
  1796. Pointer Aliasing Rules
  1797. ----------------------
  1798. Any memory access must be done through a pointer value associated with
  1799. an address range of the memory access, otherwise the behavior is
  1800. undefined. Pointer values are associated with address ranges according
  1801. to the following rules:
  1802. - A pointer value is associated with the addresses associated with any
  1803. value it is *based* on.
  1804. - An address of a global variable is associated with the address range
  1805. of the variable's storage.
  1806. - The result value of an allocation instruction is associated with the
  1807. address range of the allocated storage.
  1808. - A null pointer in the default address-space is associated with no
  1809. address.
  1810. - An :ref:`undef value <undefvalues>` in *any* address-space is
  1811. associated with no address.
  1812. - An integer constant other than zero or a pointer value returned from
  1813. a function not defined within LLVM may be associated with address
  1814. ranges allocated through mechanisms other than those provided by
  1815. LLVM. Such ranges shall not overlap with any ranges of addresses
  1816. allocated by mechanisms provided by LLVM.
  1817. A pointer value is *based* on another pointer value according to the
  1818. following rules:
  1819. - A pointer value formed from a scalar ``getelementptr`` operation is *based* on
  1820. the pointer-typed operand of the ``getelementptr``.
  1821. - The pointer in lane *l* of the result of a vector ``getelementptr`` operation
  1822. is *based* on the pointer in lane *l* of the vector-of-pointers-typed operand
  1823. of the ``getelementptr``.
  1824. - The result value of a ``bitcast`` is *based* on the operand of the
  1825. ``bitcast``.
  1826. - A pointer value formed by an ``inttoptr`` is *based* on all pointer
  1827. values that contribute (directly or indirectly) to the computation of
  1828. the pointer's value.
  1829. - The "*based* on" relationship is transitive.
  1830. Note that this definition of *"based"* is intentionally similar to the
  1831. definition of *"based"* in C99, though it is slightly weaker.
  1832. LLVM IR does not associate types with memory. The result type of a
  1833. ``load`` merely indicates the size and alignment of the memory from
  1834. which to load, as well as the interpretation of the value. The first
  1835. operand type of a ``store`` similarly only indicates the size and
  1836. alignment of the store.
  1837. Consequently, type-based alias analysis, aka TBAA, aka
  1838. ``-fstrict-aliasing``, is not applicable to general unadorned LLVM IR.
  1839. :ref:`Metadata <metadata>` may be used to encode additional information
  1840. which specialized optimization passes may use to implement type-based
  1841. alias analysis.
  1842. .. _volatile:
  1843. Volatile Memory Accesses
  1844. ------------------------
  1845. Certain memory accesses, such as :ref:`load <i_load>`'s,
  1846. :ref:`store <i_store>`'s, and :ref:`llvm.memcpy <int_memcpy>`'s may be
  1847. marked ``volatile``. The optimizers must not change the number of
  1848. volatile operations or change their order of execution relative to other
  1849. volatile operations. The optimizers *may* change the order of volatile
  1850. operations relative to non-volatile operations. This is not Java's
  1851. "volatile" and has no cross-thread synchronization behavior.
  1852. A volatile load or store may have additional target-specific semantics.
  1853. Any volatile operation can have side effects, and any volatile operation
  1854. can read and/or modify state which is not accessible via a regular load
  1855. or store in this module. Volatile operations may use addresses which do
  1856. not point to memory (like MMIO registers). This means the compiler may
  1857. not use a volatile operation to prove a non-volatile access to that
  1858. address has defined behavior.
  1859. The allowed side-effects for volatile accesses are limited. If a
  1860. non-volatile store to a given address would be legal, a volatile
  1861. operation may modify the memory at that address. A volatile operation
  1862. may not modify any other memory accessible by the module being compiled.
  1863. A volatile operation may not call any code in the current module.
  1864. The compiler may assume execution will continue after a volatile operation,
  1865. so operations which modify memory or may have undefined behavior can be
  1866. hoisted past a volatile operation.
  1867. IR-level volatile loads and stores cannot safely be optimized into
  1868. llvm.memcpy or llvm.memmove intrinsics even when those intrinsics are
  1869. flagged volatile. Likewise, the backend should never split or merge
  1870. target-legal volatile load/store instructions.
  1871. .. admonition:: Rationale
  1872. Platforms may rely on volatile loads and stores of natively supported
  1873. data width to be executed as single instruction. For example, in C
  1874. this holds for an l-value of volatile primitive type with native
  1875. hardware support, but not necessarily for aggregate types. The
  1876. frontend upholds these expectations, which are intentionally
  1877. unspecified in the IR. The rules above ensure that IR transformations
  1878. do not violate the frontend's contract with the language.
  1879. .. _memmodel:
  1880. Memory Model for Concurrent Operations
  1881. --------------------------------------
  1882. The LLVM IR does not define any way to start parallel threads of
  1883. execution or to register signal handlers. Nonetheless, there are
  1884. platform-specific ways to create them, and we define LLVM IR's behavior
  1885. in their presence. This model is inspired by the C++0x memory model.
  1886. For a more informal introduction to this model, see the :doc:`Atomics`.
  1887. We define a *happens-before* partial order as the least partial order
  1888. that
  1889. - Is a superset of single-thread program order, and
  1890. - When a *synchronizes-with* ``b``, includes an edge from ``a`` to
  1891. ``b``. *Synchronizes-with* pairs are introduced by platform-specific
  1892. techniques, like pthread locks, thread creation, thread joining,
  1893. etc., and by atomic instructions. (See also :ref:`Atomic Memory Ordering
  1894. Constraints <ordering>`).
  1895. Note that program order does not introduce *happens-before* edges
  1896. between a thread and signals executing inside that thread.
  1897. Every (defined) read operation (load instructions, memcpy, atomic
  1898. loads/read-modify-writes, etc.) R reads a series of bytes written by
  1899. (defined) write operations (store instructions, atomic
  1900. stores/read-modify-writes, memcpy, etc.). For the purposes of this
  1901. section, initialized globals are considered to have a write of the
  1902. initializer which is atomic and happens before any other read or write
  1903. of the memory in question. For each byte of a read R, R\ :sub:`byte`
  1904. may see any write to the same byte, except:
  1905. - If write\ :sub:`1` happens before write\ :sub:`2`, and
  1906. write\ :sub:`2` happens before R\ :sub:`byte`, then
  1907. R\ :sub:`byte` does not see write\ :sub:`1`.
  1908. - If R\ :sub:`byte` happens before write\ :sub:`3`, then
  1909. R\ :sub:`byte` does not see write\ :sub:`3`.
  1910. Given that definition, R\ :sub:`byte` is defined as follows:
  1911. - If R is volatile, the result is target-dependent. (Volatile is
  1912. supposed to give guarantees which can support ``sig_atomic_t`` in
  1913. C/C++, and may be used for accesses to addresses that do not behave
  1914. like normal memory. It does not generally provide cross-thread
  1915. synchronization.)
  1916. - Otherwise, if there is no write to the same byte that happens before
  1917. R\ :sub:`byte`, R\ :sub:`byte` returns ``undef`` for that byte.
  1918. - Otherwise, if R\ :sub:`byte` may see exactly one write,
  1919. R\ :sub:`byte` returns the value written by that write.
  1920. - Otherwise, if R is atomic, and all the writes R\ :sub:`byte` may
  1921. see are atomic, it chooses one of the values written. See the :ref:`Atomic
  1922. Memory Ordering Constraints <ordering>` section for additional
  1923. constraints on how the choice is made.
  1924. - Otherwise R\ :sub:`byte` returns ``undef``.
  1925. R returns the value composed of the series of bytes it read. This
  1926. implies that some bytes within the value may be ``undef`` **without**
  1927. the entire value being ``undef``. Note that this only defines the
  1928. semantics of the operation; it doesn't mean that targets will emit more
  1929. than one instruction to read the series of bytes.
  1930. Note that in cases where none of the atomic intrinsics are used, this
  1931. model places only one restriction on IR transformations on top of what
  1932. is required for single-threaded execution: introducing a store to a byte
  1933. which might not otherwise be stored is not allowed in general.
  1934. (Specifically, in the case where another thread might write to and read
  1935. from an address, introducing a store can change a load that may see
  1936. exactly one write into a load that may see multiple writes.)
  1937. .. _ordering:
  1938. Atomic Memory Ordering Constraints
  1939. ----------------------------------
  1940. Atomic instructions (:ref:`cmpxchg <i_cmpxchg>`,
  1941. :ref:`atomicrmw <i_atomicrmw>`, :ref:`fence <i_fence>`,
  1942. :ref:`atomic load <i_load>`, and :ref:`atomic store <i_store>`) take
  1943. ordering parameters that determine which other atomic instructions on
  1944. the same address they *synchronize with*. These semantics are borrowed
  1945. from Java and C++0x, but are somewhat more colloquial. If these
  1946. descriptions aren't precise enough, check those specs (see spec
  1947. references in the :doc:`atomics guide <Atomics>`).
  1948. :ref:`fence <i_fence>` instructions treat these orderings somewhat
  1949. differently since they don't take an address. See that instruction's
  1950. documentation for details.
  1951. For a simpler introduction to the ordering constraints, see the
  1952. :doc:`Atomics`.
  1953. ``unordered``
  1954. The set of values that can be read is governed by the happens-before
  1955. partial order. A value cannot be read unless some operation wrote
  1956. it. This is intended to provide a guarantee strong enough to model
  1957. Java's non-volatile shared variables. This ordering cannot be
  1958. specified for read-modify-write operations; it is not strong enough
  1959. to make them atomic in any interesting way.
  1960. ``monotonic``
  1961. In addition to the guarantees of ``unordered``, there is a single
  1962. total order for modifications by ``monotonic`` operations on each
  1963. address. All modification orders must be compatible with the
  1964. happens-before order. There is no guarantee that the modification
  1965. orders can be combined to a global total order for the whole program
  1966. (and this often will not be possible). The read in an atomic
  1967. read-modify-write operation (:ref:`cmpxchg <i_cmpxchg>` and
  1968. :ref:`atomicrmw <i_atomicrmw>`) reads the value in the modification
  1969. order immediately before the value it writes. If one atomic read
  1970. happens before another atomic read of the same address, the later
  1971. read must see the same value or a later value in the address's
  1972. modification order. This disallows reordering of ``monotonic`` (or
  1973. stronger) operations on the same address. If an address is written
  1974. ``monotonic``-ally by one thread, and other threads ``monotonic``-ally
  1975. read that address repeatedly, the other threads must eventually see
  1976. the write. This corresponds to the C++0x/C1x
  1977. ``memory_order_relaxed``.
  1978. ``acquire``
  1979. In addition to the guarantees of ``monotonic``, a
  1980. *synchronizes-with* edge may be formed with a ``release`` operation.
  1981. This is intended to model C++'s ``memory_order_acquire``.
  1982. ``release``
  1983. In addition to the guarantees of ``monotonic``, if this operation
  1984. writes a value which is subsequently read by an ``acquire``
  1985. operation, it *synchronizes-with* that operation. (This isn't a
  1986. complete description; see the C++0x definition of a release
  1987. sequence.) This corresponds to the C++0x/C1x
  1988. ``memory_order_release``.
  1989. ``acq_rel`` (acquire+release)
  1990. Acts as both an ``acquire`` and ``release`` operation on its
  1991. address. This corresponds to the C++0x/C1x ``memory_order_acq_rel``.
  1992. ``seq_cst`` (sequentially consistent)
  1993. In addition to the guarantees of ``acq_rel`` (``acquire`` for an
  1994. operation that only reads, ``release`` for an operation that only
  1995. writes), there is a global total order on all
  1996. sequentially-consistent operations on all addresses, which is
  1997. consistent with the *happens-before* partial order and with the
  1998. modification orders of all the affected addresses. Each
  1999. sequentially-consistent read sees the last preceding write to the
  2000. same address in this global order. This corresponds to the C++0x/C1x
  2001. ``memory_order_seq_cst`` and Java volatile.
  2002. .. _syncscope:
  2003. If an atomic operation is marked ``syncscope("singlethread")``, it only
  2004. *synchronizes with* and only participates in the seq\_cst total orderings of
  2005. other operations running in the same thread (for example, in signal handlers).
  2006. If an atomic operation is marked ``syncscope("<target-scope>")``, where
  2007. ``<target-scope>`` is a target specific synchronization scope, then it is target
  2008. dependent if it *synchronizes with* and participates in the seq\_cst total
  2009. orderings of other operations.
  2010. Otherwise, an atomic operation that is not marked ``syncscope("singlethread")``
  2011. or ``syncscope("<target-scope>")`` *synchronizes with* and participates in the
  2012. seq\_cst total orderings of other operations that are not marked
  2013. ``syncscope("singlethread")`` or ``syncscope("<target-scope>")``.
  2014. .. _floatenv:
  2015. Floating-Point Environment
  2016. --------------------------
  2017. The default LLVM floating-point environment assumes that floating-point
  2018. instructions do not have side effects. Results assume the round-to-nearest
  2019. rounding mode. No floating-point exception state is maintained in this
  2020. environment. Therefore, there is no attempt to create or preserve invalid
  2021. operation (SNaN) or division-by-zero exceptions.
  2022. The benefit of this exception-free assumption is that floating-point
  2023. operations may be speculated freely without any other fast-math relaxations
  2024. to the floating-point model.
  2025. Code that requires different behavior than this should use the
  2026. :ref:`Constrained Floating-Point Intrinsics <constrainedfp>`.
  2027. .. _fastmath:
  2028. Fast-Math Flags
  2029. ---------------
  2030. LLVM IR floating-point operations (:ref:`fneg <i_fneg>`, :ref:`fadd <i_fadd>`,
  2031. :ref:`fsub <i_fsub>`, :ref:`fmul <i_fmul>`, :ref:`fdiv <i_fdiv>`,
  2032. :ref:`frem <i_frem>`, :ref:`fcmp <i_fcmp>`), :ref:`phi <i_phi>`,
  2033. :ref:`select <i_select>` and :ref:`call <i_call>`
  2034. may use the following flags to enable otherwise unsafe
  2035. floating-point transformations.
  2036. ``nnan``
  2037. No NaNs - Allow optimizations to assume the arguments and result are not
  2038. NaN. If an argument is a nan, or the result would be a nan, it produces
  2039. a :ref:`poison value <poisonvalues>` instead.
  2040. ``ninf``
  2041. No Infs - Allow optimizations to assume the arguments and result are not
  2042. +/-Inf. If an argument is +/-Inf, or the result would be +/-Inf, it
  2043. produces a :ref:`poison value <poisonvalues>` instead.
  2044. ``nsz``
  2045. No Signed Zeros - Allow optimizations to treat the sign of a zero
  2046. argument or result as insignificant.
  2047. ``arcp``
  2048. Allow Reciprocal - Allow optimizations to use the reciprocal of an
  2049. argument rather than perform division.
  2050. ``contract``
  2051. Allow floating-point contraction (e.g. fusing a multiply followed by an
  2052. addition into a fused multiply-and-add).
  2053. ``afn``
  2054. Approximate functions - Allow substitution of approximate calculations for
  2055. functions (sin, log, sqrt, etc). See floating-point intrinsic definitions
  2056. for places where this can apply to LLVM's intrinsic math functions.
  2057. ``reassoc``
  2058. Allow reassociation transformations for floating-point instructions.
  2059. This may dramatically change results in floating-point.
  2060. ``fast``
  2061. This flag implies all of the others.
  2062. .. _uselistorder:
  2063. Use-list Order Directives
  2064. -------------------------
  2065. Use-list directives encode the in-memory order of each use-list, allowing the
  2066. order to be recreated. ``<order-indexes>`` is a comma-separated list of
  2067. indexes that are assigned to the referenced value's uses. The referenced
  2068. value's use-list is immediately sorted by these indexes.
  2069. Use-list directives may appear at function scope or global scope. They are not
  2070. instructions, and have no effect on the semantics of the IR. When they're at
  2071. function scope, they must appear after the terminator of the final basic block.
  2072. If basic blocks have their address taken via ``blockaddress()`` expressions,
  2073. ``uselistorder_bb`` can be used to reorder their use-lists from outside their
  2074. function's scope.
  2075. :Syntax:
  2076. ::
  2077. uselistorder <ty> <value>, { <order-indexes> }
  2078. uselistorder_bb @function, %block { <order-indexes> }
  2079. :Examples:
  2080. ::
  2081. define void @foo(i32 %arg1, i32 %arg2) {
  2082. entry:
  2083. ; ... instructions ...
  2084. bb:
  2085. ; ... instructions ...
  2086. ; At function scope.
  2087. uselistorder i32 %arg1, { 1, 0, 2 }
  2088. uselistorder label %bb, { 1, 0 }
  2089. }
  2090. ; At global scope.
  2091. uselistorder i32* @global, { 1, 2, 0 }
  2092. uselistorder i32 7, { 1, 0 }
  2093. uselistorder i32 (i32) @bar, { 1, 0 }
  2094. uselistorder_bb @foo, %bb, { 5, 1, 3, 2, 0, 4 }
  2095. .. _source_filename:
  2096. Source Filename
  2097. ---------------
  2098. The *source filename* string is set to the original module identifier,
  2099. which will be the name of the compiled source file when compiling from
  2100. source through the clang front end, for example. It is then preserved through
  2101. the IR and bitcode.
  2102. This is currently necessary to generate a consistent unique global
  2103. identifier for local functions used in profile data, which prepends the
  2104. source file name to the local function name.
  2105. The syntax for the source file name is simply:
  2106. .. code-block:: text
  2107. source_filename = "/path/to/source.c"
  2108. .. _typesystem:
  2109. Type System
  2110. ===========
  2111. The LLVM type system is one of the most important features of the
  2112. intermediate representation. Being typed enables a number of
  2113. optimizations to be performed on the intermediate representation
  2114. directly, without having to do extra analyses on the side before the
  2115. transformation. A strong type system makes it easier to read the
  2116. generated code and enables novel analyses and transformations that are
  2117. not feasible to perform on normal three address code representations.
  2118. .. _t_void:
  2119. Void Type
  2120. ---------
  2121. :Overview:
  2122. The void type does not represent any value and has no size.
  2123. :Syntax:
  2124. ::
  2125. void
  2126. .. _t_function:
  2127. Function Type
  2128. -------------
  2129. :Overview:
  2130. The function type can be thought of as a function signature. It consists of a
  2131. return type and a list of formal parameter types. The return type of a function
  2132. type is a void type or first class type --- except for :ref:`label <t_label>`
  2133. and :ref:`metadata <t_metadata>` types.
  2134. :Syntax:
  2135. ::
  2136. <returntype> (<parameter list>)
  2137. ...where '``<parameter list>``' is a comma-separated list of type
  2138. specifiers. Optionally, the parameter list may include a type ``...``, which
  2139. indicates that the function takes a variable number of arguments. Variable
  2140. argument functions can access their arguments with the :ref:`variable argument
  2141. handling intrinsic <int_varargs>` functions. '``<returntype>``' is any type
  2142. except :ref:`label <t_label>` and :ref:`metadata <t_metadata>`.
  2143. :Examples:
  2144. +---------------------------------+---------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  2145. | ``i32 (i32)`` | function taking an ``i32``, returning an ``i32`` |
  2146. +---------------------------------+---------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  2147. | ``float (i16, i32 *) *`` | :ref:`Pointer <t_pointer>` to a function that takes an ``i16`` and a :ref:`pointer <t_pointer>` to ``i32``, returning ``float``. |
  2148. +---------------------------------+---------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  2149. | ``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. |
  2150. +---------------------------------+---------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  2151. | ``{i32, i32} (i32)`` | A function taking an ``i32``, returning a :ref:`structure <t_struct>` containing two ``i32`` values |
  2152. +---------------------------------+---------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  2153. .. _t_firstclass:
  2154. First Class Types
  2155. -----------------
  2156. The :ref:`first class <t_firstclass>` types are perhaps the most important.
  2157. Values of these types are the only ones which can be produced by
  2158. instructions.
  2159. .. _t_single_value:
  2160. Single Value Types
  2161. ^^^^^^^^^^^^^^^^^^
  2162. These are the types that are valid in registers from CodeGen's perspective.
  2163. .. _t_integer:
  2164. Integer Type
  2165. """"""""""""
  2166. :Overview:
  2167. The integer type is a very simple type that simply specifies an
  2168. arbitrary bit width for the integer type desired. Any bit width from 1
  2169. bit to 2\ :sup:`23`\ -1 (about 8 million) can be specified.
  2170. :Syntax:
  2171. ::
  2172. iN
  2173. The number of bits the integer will occupy is specified by the ``N``
  2174. value.
  2175. Examples:
  2176. *********
  2177. +----------------+------------------------------------------------+
  2178. | ``i1`` | a single-bit integer. |
  2179. +----------------+------------------------------------------------+
  2180. | ``i32`` | a 32-bit integer. |
  2181. +----------------+------------------------------------------------+
  2182. | ``i1942652`` | a really big integer of over 1 million bits. |
  2183. +----------------+------------------------------------------------+
  2184. .. _t_floating:
  2185. Floating-Point Types
  2186. """"""""""""""""""""
  2187. .. list-table::
  2188. :header-rows: 1
  2189. * - Type
  2190. - Description
  2191. * - ``half``
  2192. - 16-bit floating-point value
  2193. * - ``float``
  2194. - 32-bit floating-point value
  2195. * - ``double``
  2196. - 64-bit floating-point value
  2197. * - ``fp128``
  2198. - 128-bit floating-point value (112-bit mantissa)
  2199. * - ``x86_fp80``
  2200. - 80-bit floating-point value (X87)
  2201. * - ``ppc_fp128``
  2202. - 128-bit floating-point value (two 64-bits)
  2203. The binary format of half, float, double, and fp128 correspond to the
  2204. IEEE-754-2008 specifications for binary16, binary32, binary64, and binary128
  2205. respectively.
  2206. X86_mmx Type
  2207. """"""""""""
  2208. :Overview:
  2209. The x86_mmx type represents a value held in an MMX register on an x86
  2210. machine. The operations allowed on it are quite limited: parameters and
  2211. return values, load and store, and bitcast. User-specified MMX
  2212. instructions are represented as intrinsic or asm calls with arguments
  2213. and/or results of this type. There are no arrays, vectors or constants
  2214. of this type.
  2215. :Syntax:
  2216. ::
  2217. x86_mmx
  2218. .. _t_pointer:
  2219. Pointer Type
  2220. """"""""""""
  2221. :Overview:
  2222. The pointer type is used to specify memory locations. Pointers are
  2223. commonly used to reference objects in memory.
  2224. Pointer types may have an optional address space attribute defining the
  2225. numbered address space where the pointed-to object resides. The default
  2226. address space is number zero. The semantics of non-zero address spaces
  2227. are target-specific.
  2228. Note that LLVM does not permit pointers to void (``void*``) nor does it
  2229. permit pointers to labels (``label*``). Use ``i8*`` instead.
  2230. :Syntax:
  2231. ::
  2232. <type> *
  2233. :Examples:
  2234. +-------------------------+--------------------------------------------------------------------------------------------------------------+
  2235. | ``[4 x i32]*`` | A :ref:`pointer <t_pointer>` to :ref:`array <t_array>` of four ``i32`` values. |
  2236. +-------------------------+--------------------------------------------------------------------------------------------------------------+
  2237. | ``i32 (i32*) *`` | A :ref:`pointer <t_pointer>` to a :ref:`function <t_function>` that takes an ``i32*``, returning an ``i32``. |
  2238. +-------------------------+--------------------------------------------------------------------------------------------------------------+
  2239. | ``i32 addrspace(5)*`` | A :ref:`pointer <t_pointer>` to an ``i32`` value that resides in address space #5. |
  2240. +-------------------------+--------------------------------------------------------------------------------------------------------------+
  2241. .. _t_vector:
  2242. Vector Type
  2243. """""""""""
  2244. :Overview:
  2245. A vector type is a simple derived type that represents a vector of
  2246. elements. Vector types are used when multiple primitive data are
  2247. operated in parallel using a single instruction (SIMD). A vector type
  2248. requires a size (number of elements), an underlying primitive data type,
  2249. and a scalable property to represent vectors where the exact hardware
  2250. vector length is unknown at compile time. Vector types are considered
  2251. :ref:`first class <t_firstclass>`.
  2252. :Syntax:
  2253. ::
  2254. < <# elements> x <elementtype> > ; Fixed-length vector
  2255. < vscale x <# elements> x <elementtype> > ; Scalable vector
  2256. The number of elements is a constant integer value larger than 0;
  2257. elementtype may be any integer, floating-point or pointer type. Vectors
  2258. of size zero are not allowed. For scalable vectors, the total number of
  2259. elements is a constant multiple (called vscale) of the specified number
  2260. of elements; vscale is a positive integer that is unknown at compile time
  2261. and the same hardware-dependent constant for all scalable vectors at run
  2262. time. The size of a specific scalable vector type is thus constant within
  2263. IR, even if the exact size in bytes cannot be determined until run time.
  2264. :Examples:
  2265. +------------------------+----------------------------------------------------+
  2266. | ``<4 x i32>`` | Vector of 4 32-bit integer values. |
  2267. +------------------------+----------------------------------------------------+
  2268. | ``<8 x float>`` | Vector of 8 32-bit floating-point values. |
  2269. +------------------------+----------------------------------------------------+
  2270. | ``<2 x i64>`` | Vector of 2 64-bit integer values. |
  2271. +------------------------+----------------------------------------------------+
  2272. | ``<4 x i64*>`` | Vector of 4 pointers to 64-bit integer values. |
  2273. +------------------------+----------------------------------------------------+
  2274. | ``<vscale x 4 x i32>`` | Vector with a multiple of 4 32-bit integer values. |
  2275. +------------------------+----------------------------------------------------+
  2276. .. _t_label:
  2277. Label Type
  2278. ^^^^^^^^^^
  2279. :Overview:
  2280. The label type represents code labels.
  2281. :Syntax:
  2282. ::
  2283. label
  2284. .. _t_token:
  2285. Token Type
  2286. ^^^^^^^^^^
  2287. :Overview:
  2288. The token type is used when a value is associated with an instruction
  2289. but all uses of the value must not attempt to introspect or obscure it.
  2290. As such, it is not appropriate to have a :ref:`phi <i_phi>` or
  2291. :ref:`select <i_select>` of type token.
  2292. :Syntax:
  2293. ::
  2294. token
  2295. .. _t_metadata:
  2296. Metadata Type
  2297. ^^^^^^^^^^^^^
  2298. :Overview:
  2299. The metadata type represents embedded metadata. No derived types may be
  2300. created from metadata except for :ref:`function <t_function>` arguments.
  2301. :Syntax:
  2302. ::
  2303. metadata
  2304. .. _t_aggregate:
  2305. Aggregate Types
  2306. ^^^^^^^^^^^^^^^
  2307. Aggregate Types are a subset of derived types that can contain multiple
  2308. member types. :ref:`Arrays <t_array>` and :ref:`structs <t_struct>` are
  2309. aggregate types. :ref:`Vectors <t_vector>` are not considered to be
  2310. aggregate types.
  2311. .. _t_array:
  2312. Array Type
  2313. """"""""""
  2314. :Overview:
  2315. The array type is a very simple derived type that arranges elements
  2316. sequentially in memory. The array type requires a size (number of
  2317. elements) and an underlying data type.
  2318. :Syntax:
  2319. ::
  2320. [<# elements> x <elementtype>]
  2321. The number of elements is a constant integer value; ``elementtype`` may
  2322. be any type with a size.
  2323. :Examples:
  2324. +------------------+--------------------------------------+
  2325. | ``[40 x i32]`` | Array of 40 32-bit integer values. |
  2326. +------------------+--------------------------------------+
  2327. | ``[41 x i32]`` | Array of 41 32-bit integer values. |
  2328. +------------------+--------------------------------------+
  2329. | ``[4 x i8]`` | Array of 4 8-bit integer values. |
  2330. +------------------+--------------------------------------+
  2331. Here are some examples of multidimensional arrays:
  2332. +-----------------------------+----------------------------------------------------------+
  2333. | ``[3 x [4 x i32]]`` | 3x4 array of 32-bit integer values. |
  2334. +-----------------------------+----------------------------------------------------------+
  2335. | ``[12 x [10 x float]]`` | 12x10 array of single precision floating-point values. |
  2336. +-----------------------------+----------------------------------------------------------+
  2337. | ``[2 x [3 x [4 x i16]]]`` | 2x3x4 array of 16-bit integer values. |
  2338. +-----------------------------+----------------------------------------------------------+
  2339. There is no restriction on indexing beyond the end of the array implied
  2340. by a static type (though there are restrictions on indexing beyond the
  2341. bounds of an allocated object in some cases). This means that
  2342. single-dimension 'variable sized array' addressing can be implemented in
  2343. LLVM with a zero length array type. An implementation of 'pascal style
  2344. arrays' in LLVM could use the type "``{ i32, [0 x float]}``", for
  2345. example.
  2346. .. _t_struct:
  2347. Structure Type
  2348. """"""""""""""
  2349. :Overview:
  2350. The structure type is used to represent a collection of data members
  2351. together in memory. The elements of a structure may be any type that has
  2352. a size.
  2353. Structures in memory are accessed using '``load``' and '``store``' by
  2354. getting a pointer to a field with the '``getelementptr``' instruction.
  2355. Structures in registers are accessed using the '``extractvalue``' and
  2356. '``insertvalue``' instructions.
  2357. Structures may optionally be "packed" structures, which indicate that
  2358. the alignment of the struct is one byte, and that there is no padding
  2359. between the elements. In non-packed structs, padding between field types
  2360. is inserted as defined by the DataLayout string in the module, which is
  2361. required to match what the underlying code generator expects.
  2362. Structures can either be "literal" or "identified". A literal structure
  2363. is defined inline with other types (e.g. ``{i32, i32}*``) whereas
  2364. identified types are always defined at the top level with a name.
  2365. Literal types are uniqued by their contents and can never be recursive
  2366. or opaque since there is no way to write one. Identified types can be
  2367. recursive, can be opaqued, and are never uniqued.
  2368. :Syntax:
  2369. ::
  2370. %T1 = type { <type list> } ; Identified normal struct type
  2371. %T2 = type <{ <type list> }> ; Identified packed struct type
  2372. :Examples:
  2373. +------------------------------+---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  2374. | ``{ i32, i32, i32 }`` | A triple of three ``i32`` values |
  2375. +------------------------------+---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  2376. | ``{ 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``. |
  2377. +------------------------------+---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  2378. | ``<{ i8, i32 }>`` | A packed struct known to be 5 bytes in size. |
  2379. +------------------------------+---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  2380. .. _t_opaque:
  2381. Opaque Structure Types
  2382. """"""""""""""""""""""
  2383. :Overview:
  2384. Opaque structure types are used to represent named structure types that
  2385. do not have a body specified. This corresponds (for example) to the C
  2386. notion of a forward declared structure.
  2387. :Syntax:
  2388. ::
  2389. %X = type opaque
  2390. %52 = type opaque
  2391. :Examples:
  2392. +--------------+-------------------+
  2393. | ``opaque`` | An opaque type. |
  2394. +--------------+-------------------+
  2395. .. _constants:
  2396. Constants
  2397. =========
  2398. LLVM has several different basic types of constants. This section
  2399. describes them all and their syntax.
  2400. Simple Constants
  2401. ----------------
  2402. **Boolean constants**
  2403. The two strings '``true``' and '``false``' are both valid constants
  2404. of the ``i1`` type.
  2405. **Integer constants**
  2406. Standard integers (such as '4') are constants of the
  2407. :ref:`integer <t_integer>` type. Negative numbers may be used with
  2408. integer types.
  2409. **Floating-point constants**
  2410. Floating-point constants use standard decimal notation (e.g.
  2411. 123.421), exponential notation (e.g. 1.23421e+2), or a more precise
  2412. hexadecimal notation (see below). The assembler requires the exact
  2413. decimal value of a floating-point constant. For example, the
  2414. assembler accepts 1.25 but rejects 1.3 because 1.3 is a repeating
  2415. decimal in binary. Floating-point constants must have a
  2416. :ref:`floating-point <t_floating>` type.
  2417. **Null pointer constants**
  2418. The identifier '``null``' is recognized as a null pointer constant
  2419. and must be of :ref:`pointer type <t_pointer>`.
  2420. **Token constants**
  2421. The identifier '``none``' is recognized as an empty token constant
  2422. and must be of :ref:`token type <t_token>`.
  2423. The one non-intuitive notation for constants is the hexadecimal form of
  2424. floating-point constants. For example, the form
  2425. '``double 0x432ff973cafa8000``' is equivalent to (but harder to read
  2426. than) '``double 4.5e+15``'. The only time hexadecimal floating-point
  2427. constants are required (and the only time that they are generated by the
  2428. disassembler) is when a floating-point constant must be emitted but it
  2429. cannot be represented as a decimal floating-point number in a reasonable
  2430. number of digits. For example, NaN's, infinities, and other special
  2431. values are represented in their IEEE hexadecimal format so that assembly
  2432. and disassembly do not cause any bits to change in the constants.
  2433. When using the hexadecimal form, constants of types half, float, and
  2434. double are represented using the 16-digit form shown above (which
  2435. matches the IEEE754 representation for double); half and float values
  2436. must, however, be exactly representable as IEEE 754 half and single
  2437. precision, respectively. Hexadecimal format is always used for long
  2438. double, and there are three forms of long double. The 80-bit format used
  2439. by x86 is represented as ``0xK`` followed by 20 hexadecimal digits. The
  2440. 128-bit format used by PowerPC (two adjacent doubles) is represented by
  2441. ``0xM`` followed by 32 hexadecimal digits. The IEEE 128-bit format is
  2442. represented by ``0xL`` followed by 32 hexadecimal digits. Long doubles
  2443. will only work if they match the long double format on your target.
  2444. The IEEE 16-bit format (half precision) is represented by ``0xH``
  2445. followed by 4 hexadecimal digits. All hexadecimal formats are big-endian
  2446. (sign bit at the left).
  2447. There are no constants of type x86_mmx.
  2448. .. _complexconstants:
  2449. Complex Constants
  2450. -----------------
  2451. Complex constants are a (potentially recursive) combination of simple
  2452. constants and smaller complex constants.
  2453. **Structure constants**
  2454. Structure constants are represented with notation similar to
  2455. structure type definitions (a comma separated list of elements,
  2456. surrounded by braces (``{}``)). For example:
  2457. "``{ i32 4, float 17.0, i32* @G }``", where "``@G``" is declared as
  2458. "``@G = external global i32``". Structure constants must have
  2459. :ref:`structure type <t_struct>`, and the number and types of elements
  2460. must match those specified by the type.
  2461. **Array constants**
  2462. Array constants are represented with notation similar to array type
  2463. definitions (a comma separated list of elements, surrounded by
  2464. square brackets (``[]``)). For example:
  2465. "``[ i32 42, i32 11, i32 74 ]``". Array constants must have
  2466. :ref:`array type <t_array>`, and the number and types of elements must
  2467. match those specified by the type. As a special case, character array
  2468. constants may also be represented as a double-quoted string using the ``c``
  2469. prefix. For example: "``c"Hello World\0A\00"``".
  2470. **Vector constants**
  2471. Vector constants are represented with notation similar to vector
  2472. type definitions (a comma separated list of elements, surrounded by
  2473. less-than/greater-than's (``<>``)). For example:
  2474. "``< i32 42, i32 11, i32 74, i32 100 >``". Vector constants
  2475. must have :ref:`vector type <t_vector>`, and the number and types of
  2476. elements must match those specified by the type.
  2477. **Zero initialization**
  2478. The string '``zeroinitializer``' can be used to zero initialize a
  2479. value to zero of *any* type, including scalar and
  2480. :ref:`aggregate <t_aggregate>` types. This is often used to avoid
  2481. having to print large zero initializers (e.g. for large arrays) and
  2482. is always exactly equivalent to using explicit zero initializers.
  2483. **Metadata node**
  2484. A metadata node is a constant tuple without types. For example:
  2485. "``!{!0, !{!2, !0}, !"test"}``". Metadata can reference constant values,
  2486. for example: "``!{!0, i32 0, i8* @global, i64 (i64)* @function, !"str"}``".
  2487. Unlike other typed constants that are meant to be interpreted as part of
  2488. the instruction stream, metadata is a place to attach additional
  2489. information such as debug info.
  2490. Global Variable and Function Addresses
  2491. --------------------------------------
  2492. The addresses of :ref:`global variables <globalvars>` and
  2493. :ref:`functions <functionstructure>` are always implicitly valid
  2494. (link-time) constants. These constants are explicitly referenced when
  2495. the :ref:`identifier for the global <identifiers>` is used and always have
  2496. :ref:`pointer <t_pointer>` type. For example, the following is a legal LLVM
  2497. file:
  2498. .. code-block:: llvm
  2499. @X = global i32 17
  2500. @Y = global i32 42
  2501. @Z = global [2 x i32*] [ i32* @X, i32* @Y ]
  2502. .. _undefvalues:
  2503. Undefined Values
  2504. ----------------
  2505. The string '``undef``' can be used anywhere a constant is expected, and
  2506. indicates that the user of the value may receive an unspecified
  2507. bit-pattern. Undefined values may be of any type (other than '``label``'
  2508. or '``void``') and be used anywhere a constant is permitted.
  2509. Undefined values are useful because they indicate to the compiler that
  2510. the program is well defined no matter what value is used. This gives the
  2511. compiler more freedom to optimize. Here are some examples of
  2512. (potentially surprising) transformations that are valid (in pseudo IR):
  2513. .. code-block:: llvm
  2514. %A = add %X, undef
  2515. %B = sub %X, undef
  2516. %C = xor %X, undef
  2517. Safe:
  2518. %A = undef
  2519. %B = undef
  2520. %C = undef
  2521. This is safe because all of the output bits are affected by the undef
  2522. bits. Any output bit can have a zero or one depending on the input bits.
  2523. .. code-block:: llvm
  2524. %A = or %X, undef
  2525. %B = and %X, undef
  2526. Safe:
  2527. %A = -1
  2528. %B = 0
  2529. Safe:
  2530. %A = %X ;; By choosing undef as 0
  2531. %B = %X ;; By choosing undef as -1
  2532. Unsafe:
  2533. %A = undef
  2534. %B = undef
  2535. These logical operations have bits that are not always affected by the
  2536. input. For example, if ``%X`` has a zero bit, then the output of the
  2537. '``and``' operation will always be a zero for that bit, no matter what
  2538. the corresponding bit from the '``undef``' is. As such, it is unsafe to
  2539. optimize or assume that the result of the '``and``' is '``undef``'.
  2540. However, it is safe to assume that all bits of the '``undef``' could be
  2541. 0, and optimize the '``and``' to 0. Likewise, it is safe to assume that
  2542. all the bits of the '``undef``' operand to the '``or``' could be set,
  2543. allowing the '``or``' to be folded to -1.
  2544. .. code-block:: llvm
  2545. %A = select undef, %X, %Y
  2546. %B = select undef, 42, %Y
  2547. %C = select %X, %Y, undef
  2548. Safe:
  2549. %A = %X (or %Y)
  2550. %B = 42 (or %Y)
  2551. %C = %Y
  2552. Unsafe:
  2553. %A = undef
  2554. %B = undef
  2555. %C = undef
  2556. This set of examples shows that undefined '``select``' (and conditional
  2557. branch) conditions can go *either way*, but they have to come from one
  2558. of the two operands. In the ``%A`` example, if ``%X`` and ``%Y`` were
  2559. both known to have a clear low bit, then ``%A`` would have to have a
  2560. cleared low bit. However, in the ``%C`` example, the optimizer is
  2561. allowed to assume that the '``undef``' operand could be the same as
  2562. ``%Y``, allowing the whole '``select``' to be eliminated.
  2563. .. code-block:: text
  2564. %A = xor undef, undef
  2565. %B = undef
  2566. %C = xor %B, %B
  2567. %D = undef
  2568. %E = icmp slt %D, 4
  2569. %F = icmp gte %D, 4
  2570. Safe:
  2571. %A = undef
  2572. %B = undef
  2573. %C = undef
  2574. %D = undef
  2575. %E = undef
  2576. %F = undef
  2577. This example points out that two '``undef``' operands are not
  2578. necessarily the same. This can be surprising to people (and also matches
  2579. C semantics) where they assume that "``X^X``" is always zero, even if
  2580. ``X`` is undefined. This isn't true for a number of reasons, but the
  2581. short answer is that an '``undef``' "variable" can arbitrarily change
  2582. its value over its "live range". This is true because the variable
  2583. doesn't actually *have a live range*. Instead, the value is logically
  2584. read from arbitrary registers that happen to be around when needed, so
  2585. the value is not necessarily consistent over time. In fact, ``%A`` and
  2586. ``%C`` need to have the same semantics or the core LLVM "replace all
  2587. uses with" concept would not hold.
  2588. .. code-block:: llvm
  2589. %A = sdiv undef, %X
  2590. %B = sdiv %X, undef
  2591. Safe:
  2592. %A = 0
  2593. b: unreachable
  2594. These examples show the crucial difference between an *undefined value*
  2595. and *undefined behavior*. An undefined value (like '``undef``') is
  2596. allowed to have an arbitrary bit-pattern. This means that the ``%A``
  2597. operation can be constant folded to '``0``', because the '``undef``'
  2598. could be zero, and zero divided by any value is zero.
  2599. However, in the second example, we can make a more aggressive
  2600. assumption: because the ``undef`` is allowed to be an arbitrary value,
  2601. we are allowed to assume that it could be zero. Since a divide by zero
  2602. has *undefined behavior*, we are allowed to assume that the operation
  2603. does not execute at all. This allows us to delete the divide and all
  2604. code after it. Because the undefined operation "can't happen", the
  2605. optimizer can assume that it occurs in dead code.
  2606. .. code-block:: text
  2607. a: store undef -> %X
  2608. b: store %X -> undef
  2609. Safe:
  2610. a: <deleted>
  2611. b: unreachable
  2612. A store *of* an undefined value can be assumed to not have any effect;
  2613. we can assume that the value is overwritten with bits that happen to
  2614. match what was already there. However, a store *to* an undefined
  2615. location could clobber arbitrary memory, therefore, it has undefined
  2616. behavior.
  2617. **MemorySanitizer**, a detector of uses of uninitialized memory,
  2618. defines a branch with condition that depends on an undef value (or
  2619. certain other values, like e.g. a result of a load from heap-allocated
  2620. memory that has never been stored to) to have an externally visible
  2621. side effect. For this reason functions with *sanitize_memory*
  2622. attribute are not allowed to produce such branches "out of thin
  2623. air". More strictly, an optimization that inserts a conditional branch
  2624. is only valid if in all executions where the branch condition has at
  2625. least one undefined bit, the same branch condition is evaluated in the
  2626. input IR as well.
  2627. .. _poisonvalues:
  2628. Poison Values
  2629. -------------
  2630. In order to facilitate speculative execution, many instructions do not
  2631. invoke immediate undefined behavior when provided with illegal operands,
  2632. and return a poison value instead.
  2633. There is currently no way of representing a poison value in the IR; they
  2634. only exist when produced by operations such as :ref:`add <i_add>` with
  2635. the ``nsw`` flag.
  2636. Poison value behavior is defined in terms of value *dependence*:
  2637. - Values other than :ref:`phi <i_phi>` nodes depend on their operands.
  2638. - :ref:`Phi <i_phi>` nodes depend on the operand corresponding to
  2639. their dynamic predecessor basic block.
  2640. - Function arguments depend on the corresponding actual argument values
  2641. in the dynamic callers of their functions.
  2642. - :ref:`Call <i_call>` instructions depend on the :ref:`ret <i_ret>`
  2643. instructions that dynamically transfer control back to them.
  2644. - :ref:`Invoke <i_invoke>` instructions depend on the
  2645. :ref:`ret <i_ret>`, :ref:`resume <i_resume>`, or exception-throwing
  2646. call instructions that dynamically transfer control back to them.
  2647. - Non-volatile loads and stores depend on the most recent stores to all
  2648. of the referenced memory addresses, following the order in the IR
  2649. (including loads and stores implied by intrinsics such as
  2650. :ref:`@llvm.memcpy <int_memcpy>`.)
  2651. - An instruction with externally visible side effects depends on the
  2652. most recent preceding instruction with externally visible side
  2653. effects, following the order in the IR. (This includes :ref:`volatile
  2654. operations <volatile>`.)
  2655. - An instruction *control-depends* on a :ref:`terminator
  2656. instruction <terminators>` if the terminator instruction has
  2657. multiple successors and the instruction is always executed when
  2658. control transfers to one of the successors, and may not be executed
  2659. when control is transferred to another.
  2660. - Additionally, an instruction also *control-depends* on a terminator
  2661. instruction if the set of instructions it otherwise depends on would
  2662. be different if the terminator had transferred control to a different
  2663. successor.
  2664. - Dependence is transitive.
  2665. An instruction that *depends* on a poison value, produces a poison value
  2666. itself. A poison value may be relaxed into an
  2667. :ref:`undef value <undefvalues>`, which takes an arbitrary bit-pattern.
  2668. This means that immediate undefined behavior occurs if a poison value is
  2669. used as an instruction operand that has any values that trigger undefined
  2670. behavior. Notably this includes (but is not limited to):
  2671. - The pointer operand of a :ref:`load <i_load>`, :ref:`store <i_store>` or
  2672. any other pointer dereferencing instruction (independent of address
  2673. space).
  2674. - The divisor operand of a ``udiv``, ``sdiv``, ``urem`` or ``srem``
  2675. instruction.
  2676. Additionally, undefined behavior occurs if a side effect *depends* on poison.
  2677. This includes side effects that are control dependent on a poisoned branch.
  2678. Here are some examples:
  2679. .. code-block:: llvm
  2680. entry:
  2681. %poison = sub nuw i32 0, 1 ; Results in a poison value.
  2682. %still_poison = and i32 %poison, 0 ; 0, but also poison.
  2683. %poison_yet_again = getelementptr i32, i32* @h, i32 %still_poison
  2684. store i32 0, i32* %poison_yet_again ; Undefined behavior due to
  2685. ; store to poison.
  2686. store i32 %poison, i32* @g ; Poison value stored to memory.
  2687. %poison2 = load i32, i32* @g ; Poison value loaded back from memory.
  2688. %narrowaddr = bitcast i32* @g to i16*
  2689. %wideaddr = bitcast i32* @g to i64*
  2690. %poison3 = load i16, i16* %narrowaddr ; Returns a poison value.
  2691. %poison4 = load i64, i64* %wideaddr ; Returns a poison value.
  2692. %cmp = icmp slt i32 %poison, 0 ; Returns a poison value.
  2693. br i1 %cmp, label %true, label %end ; Branch to either destination.
  2694. true:
  2695. store volatile i32 0, i32* @g ; This is control-dependent on %cmp, so
  2696. ; it has undefined behavior.
  2697. br label %end
  2698. end:
  2699. %p = phi i32 [ 0, %entry ], [ 1, %true ]
  2700. ; Both edges into this PHI are
  2701. ; control-dependent on %cmp, so this
  2702. ; always results in a poison value.
  2703. store volatile i32 0, i32* @g ; This would depend on the store in %true
  2704. ; if %cmp is true, or the store in %entry
  2705. ; otherwise, so this is undefined behavior.
  2706. br i1 %cmp, label %second_true, label %second_end
  2707. ; The same branch again, but this time the
  2708. ; true block doesn't have side effects.
  2709. second_true:
  2710. ; No side effects!
  2711. ret void
  2712. second_end:
  2713. store volatile i32 0, i32* @g ; This time, the instruction always depends
  2714. ; on the store in %end. Also, it is
  2715. ; control-equivalent to %end, so this is
  2716. ; well-defined (ignoring earlier undefined
  2717. ; behavior in this example).
  2718. .. _blockaddress:
  2719. Addresses of Basic Blocks
  2720. -------------------------
  2721. ``blockaddress(@function, %block)``
  2722. The '``blockaddress``' constant computes the address of the specified
  2723. basic block in the specified function, and always has an ``i8*`` type.
  2724. Taking the address of the entry block is illegal.
  2725. This value only has defined behavior when used as an operand to the
  2726. ':ref:`indirectbr <i_indirectbr>`' or ':ref:`callbr <i_callbr>`'instruction, or
  2727. for comparisons against null. Pointer equality tests between labels addresses
  2728. results in undefined behavior --- though, again, comparison against null is ok,
  2729. and no label is equal to the null pointer. This may be passed around as an
  2730. opaque pointer sized value as long as the bits are not inspected. This
  2731. allows ``ptrtoint`` and arithmetic to be performed on these values so
  2732. long as the original value is reconstituted before the ``indirectbr`` or
  2733. ``callbr`` instruction.
  2734. Finally, some targets may provide defined semantics when using the value
  2735. as the operand to an inline assembly, but that is target specific.
  2736. .. _constantexprs:
  2737. Constant Expressions
  2738. --------------------
  2739. Constant expressions are used to allow expressions involving other
  2740. constants to be used as constants. Constant expressions may be of any
  2741. :ref:`first class <t_firstclass>` type and may involve any LLVM operation
  2742. that does not have side effects (e.g. load and call are not supported).
  2743. The following is the syntax for constant expressions:
  2744. ``trunc (CST to TYPE)``
  2745. Perform the :ref:`trunc operation <i_trunc>` on constants.
  2746. ``zext (CST to TYPE)``
  2747. Perform the :ref:`zext operation <i_zext>` on constants.
  2748. ``sext (CST to TYPE)``
  2749. Perform the :ref:`sext operation <i_sext>` on constants.
  2750. ``fptrunc (CST to TYPE)``
  2751. Truncate a floating-point constant to another floating-point type.
  2752. The size of CST must be larger than the size of TYPE. Both types
  2753. must be floating-point.
  2754. ``fpext (CST to TYPE)``
  2755. Floating-point extend a constant to another type. The size of CST
  2756. must be smaller or equal to the size of TYPE. Both types must be
  2757. floating-point.
  2758. ``fptoui (CST to TYPE)``
  2759. Convert a floating-point constant to the corresponding unsigned
  2760. integer constant. TYPE must be a scalar or vector integer type. CST
  2761. must be of scalar or vector floating-point type. Both CST and TYPE
  2762. must be scalars, or vectors of the same number of elements. If the
  2763. value won't fit in the integer type, the result is a
  2764. :ref:`poison value <poisonvalues>`.
  2765. ``fptosi (CST to TYPE)``
  2766. Convert a floating-point constant to the corresponding signed
  2767. integer constant. TYPE must be a scalar or vector integer type. CST
  2768. must be of scalar or vector floating-point type. Both CST and TYPE
  2769. must be scalars, or vectors of the same number of elements. If the
  2770. value won't fit in the integer type, the result is a
  2771. :ref:`poison value <poisonvalues>`.
  2772. ``uitofp (CST to TYPE)``
  2773. Convert an unsigned integer constant to the corresponding
  2774. floating-point constant. TYPE must be a scalar or vector floating-point
  2775. type. CST must be of scalar or vector integer type. Both CST and TYPE must
  2776. be scalars, or vectors of the same number of elements.
  2777. ``sitofp (CST to TYPE)``
  2778. Convert a signed integer constant to the corresponding floating-point
  2779. constant. TYPE must be a scalar or vector floating-point type.
  2780. CST must be of scalar or vector integer type. Both CST and TYPE must
  2781. be scalars, or vectors of the same number of elements.
  2782. ``ptrtoint (CST to TYPE)``
  2783. Perform the :ref:`ptrtoint operation <i_ptrtoint>` on constants.
  2784. ``inttoptr (CST to TYPE)``
  2785. Perform the :ref:`inttoptr operation <i_inttoptr>` on constants.
  2786. This one is *really* dangerous!
  2787. ``bitcast (CST to TYPE)``
  2788. Convert a constant, CST, to another TYPE.
  2789. The constraints of the operands are the same as those for the
  2790. :ref:`bitcast instruction <i_bitcast>`.
  2791. ``addrspacecast (CST to TYPE)``
  2792. Convert a constant pointer or constant vector of pointer, CST, to another
  2793. TYPE in a different address space. The constraints of the operands are the
  2794. same as those for the :ref:`addrspacecast instruction <i_addrspacecast>`.
  2795. ``getelementptr (TY, CSTPTR, IDX0, IDX1, ...)``, ``getelementptr inbounds (TY, CSTPTR, IDX0, IDX1, ...)``
  2796. Perform the :ref:`getelementptr operation <i_getelementptr>` on
  2797. constants. As with the :ref:`getelementptr <i_getelementptr>`
  2798. instruction, the index list may have one or more indexes, which are
  2799. required to make sense for the type of "pointer to TY".
  2800. ``select (COND, VAL1, VAL2)``
  2801. Perform the :ref:`select operation <i_select>` on constants.
  2802. ``icmp COND (VAL1, VAL2)``
  2803. Perform the :ref:`icmp operation <i_icmp>` on constants.
  2804. ``fcmp COND (VAL1, VAL2)``
  2805. Perform the :ref:`fcmp operation <i_fcmp>` on constants.
  2806. ``extractelement (VAL, IDX)``
  2807. Perform the :ref:`extractelement operation <i_extractelement>` on
  2808. constants.
  2809. ``insertelement (VAL, ELT, IDX)``
  2810. Perform the :ref:`insertelement operation <i_insertelement>` on
  2811. constants.
  2812. ``shufflevector (VEC1, VEC2, IDXMASK)``
  2813. Perform the :ref:`shufflevector operation <i_shufflevector>` on
  2814. constants.
  2815. ``extractvalue (VAL, IDX0, IDX1, ...)``
  2816. Perform the :ref:`extractvalue operation <i_extractvalue>` on
  2817. constants. The index list is interpreted in a similar manner as
  2818. indices in a ':ref:`getelementptr <i_getelementptr>`' operation. At
  2819. least one index value must be specified.
  2820. ``insertvalue (VAL, ELT, IDX0, IDX1, ...)``
  2821. Perform the :ref:`insertvalue operation <i_insertvalue>` on constants.
  2822. The index list is interpreted in a similar manner as indices in a
  2823. ':ref:`getelementptr <i_getelementptr>`' operation. At least one index
  2824. value must be specified.
  2825. ``OPCODE (LHS, RHS)``
  2826. Perform the specified operation of the LHS and RHS constants. OPCODE
  2827. may be any of the :ref:`binary <binaryops>` or :ref:`bitwise
  2828. binary <bitwiseops>` operations. The constraints on operands are
  2829. the same as those for the corresponding instruction (e.g. no bitwise
  2830. operations on floating-point values are allowed).
  2831. Other Values
  2832. ============
  2833. .. _inlineasmexprs:
  2834. Inline Assembler Expressions
  2835. ----------------------------
  2836. LLVM supports inline assembler expressions (as opposed to :ref:`Module-Level
  2837. Inline Assembly <moduleasm>`) through the use of a special value. This value
  2838. represents the inline assembler as a template string (containing the
  2839. instructions to emit), a list of operand constraints (stored as a string), a
  2840. flag that indicates whether or not the inline asm expression has side effects,
  2841. and a flag indicating whether the function containing the asm needs to align its
  2842. stack conservatively.
  2843. The template string supports argument substitution of the operands using "``$``"
  2844. followed by a number, to indicate substitution of the given register/memory
  2845. location, as specified by the constraint string. "``${NUM:MODIFIER}``" may also
  2846. be used, where ``MODIFIER`` is a target-specific annotation for how to print the
  2847. operand (See :ref:`inline-asm-modifiers`).
  2848. A literal "``$``" may be included by using "``$$``" in the template. To include
  2849. other special characters into the output, the usual "``\XX``" escapes may be
  2850. used, just as in other strings. Note that after template substitution, the
  2851. resulting assembly string is parsed by LLVM's integrated assembler unless it is
  2852. disabled -- even when emitting a ``.s`` file -- and thus must contain assembly
  2853. syntax known to LLVM.
  2854. LLVM also supports a few more substitutions useful for writing inline assembly:
  2855. - ``${:uid}``: Expands to a decimal integer unique to this inline assembly blob.
  2856. This substitution is useful when declaring a local label. Many standard
  2857. compiler optimizations, such as inlining, may duplicate an inline asm blob.
  2858. Adding a blob-unique identifier ensures that the two labels will not conflict
  2859. during assembly. This is used to implement `GCC's %= special format
  2860. string <https://gcc.gnu.org/onlinedocs/gcc/Extended-Asm.html>`_.
  2861. - ``${:comment}``: Expands to the comment character of the current target's
  2862. assembly dialect. This is usually ``#``, but many targets use other strings,
  2863. such as ``;``, ``//``, or ``!``.
  2864. - ``${:private}``: Expands to the assembler private label prefix. Labels with
  2865. this prefix will not appear in the symbol table of the assembled object.
  2866. Typically the prefix is ``L``, but targets may use other strings. ``.L`` is
  2867. relatively popular.
  2868. LLVM's support for inline asm is modeled closely on the requirements of Clang's
  2869. GCC-compatible inline-asm support. Thus, the feature-set and the constraint and
  2870. modifier codes listed here are similar or identical to those in GCC's inline asm
  2871. support. However, to be clear, the syntax of the template and constraint strings
  2872. described here is *not* the same as the syntax accepted by GCC and Clang, and,
  2873. while most constraint letters are passed through as-is by Clang, some get
  2874. translated to other codes when converting from the C source to the LLVM
  2875. assembly.
  2876. An example inline assembler expression is:
  2877. .. code-block:: llvm
  2878. i32 (i32) asm "bswap $0", "=r,r"
  2879. Inline assembler expressions may **only** be used as the callee operand
  2880. of a :ref:`call <i_call>` or an :ref:`invoke <i_invoke>` instruction.
  2881. Thus, typically we have:
  2882. .. code-block:: llvm
  2883. %X = call i32 asm "bswap $0", "=r,r"(i32 %Y)
  2884. Inline asms with side effects not visible in the constraint list must be
  2885. marked as having side effects. This is done through the use of the
  2886. '``sideeffect``' keyword, like so:
  2887. .. code-block:: llvm
  2888. call void asm sideeffect "eieio", ""()
  2889. In some cases inline asms will contain code that will not work unless
  2890. the stack is aligned in some way, such as calls or SSE instructions on
  2891. x86, yet will not contain code that does that alignment within the asm.
  2892. The compiler should make conservative assumptions about what the asm
  2893. might contain and should generate its usual stack alignment code in the
  2894. prologue if the '``alignstack``' keyword is present:
  2895. .. code-block:: llvm
  2896. call void asm alignstack "eieio", ""()
  2897. Inline asms also support using non-standard assembly dialects. The
  2898. assumed dialect is ATT. When the '``inteldialect``' keyword is present,
  2899. the inline asm is using the Intel dialect. Currently, ATT and Intel are
  2900. the only supported dialects. An example is:
  2901. .. code-block:: llvm
  2902. call void asm inteldialect "eieio", ""()
  2903. If multiple keywords appear the '``sideeffect``' keyword must come
  2904. first, the '``alignstack``' keyword second and the '``inteldialect``'
  2905. keyword last.
  2906. Inline Asm Constraint String
  2907. ^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  2908. The constraint list is a comma-separated string, each element containing one or
  2909. more constraint codes.
  2910. For each element in the constraint list an appropriate register or memory
  2911. operand will be chosen, and it will be made available to assembly template
  2912. string expansion as ``$0`` for the first constraint in the list, ``$1`` for the
  2913. second, etc.
  2914. There are three different types of constraints, which are distinguished by a
  2915. prefix symbol in front of the constraint code: Output, Input, and Clobber. The
  2916. constraints must always be given in that order: outputs first, then inputs, then
  2917. clobbers. They cannot be intermingled.
  2918. There are also three different categories of constraint codes:
  2919. - Register constraint. This is either a register class, or a fixed physical
  2920. register. This kind of constraint will allocate a register, and if necessary,
  2921. bitcast the argument or result to the appropriate type.
  2922. - Memory constraint. This kind of constraint is for use with an instruction
  2923. taking a memory operand. Different constraints allow for different addressing
  2924. modes used by the target.
  2925. - Immediate value constraint. This kind of constraint is for an integer or other
  2926. immediate value which can be rendered directly into an instruction. The
  2927. various target-specific constraints allow the selection of a value in the
  2928. proper range for the instruction you wish to use it with.
  2929. Output constraints
  2930. """"""""""""""""""
  2931. Output constraints are specified by an "``=``" prefix (e.g. "``=r``"). This
  2932. indicates that the assembly will write to this operand, and the operand will
  2933. then be made available as a return value of the ``asm`` expression. Output
  2934. constraints do not consume an argument from the call instruction. (Except, see
  2935. below about indirect outputs).
  2936. Normally, it is expected that no output locations are written to by the assembly
  2937. expression until *all* of the inputs have been read. As such, LLVM may assign
  2938. the same register to an output and an input. If this is not safe (e.g. if the
  2939. assembly contains two instructions, where the first writes to one output, and
  2940. the second reads an input and writes to a second output), then the "``&``"
  2941. modifier must be used (e.g. "``=&r``") to specify that the output is an
  2942. "early-clobber" output. Marking an output as "early-clobber" ensures that LLVM
  2943. will not use the same register for any inputs (other than an input tied to this
  2944. output).
  2945. Input constraints
  2946. """""""""""""""""
  2947. Input constraints do not have a prefix -- just the constraint codes. Each input
  2948. constraint will consume one argument from the call instruction. It is not
  2949. permitted for the asm to write to any input register or memory location (unless
  2950. that input is tied to an output). Note also that multiple inputs may all be
  2951. assigned to the same register, if LLVM can determine that they necessarily all
  2952. contain the same value.
  2953. Instead of providing a Constraint Code, input constraints may also "tie"
  2954. themselves to an output constraint, by providing an integer as the constraint
  2955. string. Tied inputs still consume an argument from the call instruction, and
  2956. take up a position in the asm template numbering as is usual -- they will simply
  2957. be constrained to always use the same register as the output they've been tied
  2958. to. For example, a constraint string of "``=r,0``" says to assign a register for
  2959. output, and use that register as an input as well (it being the 0'th
  2960. constraint).
  2961. It is permitted to tie an input to an "early-clobber" output. In that case, no
  2962. *other* input may share the same register as the input tied to the early-clobber
  2963. (even when the other input has the same value).
  2964. You may only tie an input to an output which has a register constraint, not a
  2965. memory constraint. Only a single input may be tied to an output.
  2966. There is also an "interesting" feature which deserves a bit of explanation: if a
  2967. register class constraint allocates a register which is too small for the value
  2968. type operand provided as input, the input value will be split into multiple
  2969. registers, and all of them passed to the inline asm.
  2970. However, this feature is often not as useful as you might think.
  2971. Firstly, the registers are *not* guaranteed to be consecutive. So, on those
  2972. architectures that have instructions which operate on multiple consecutive
  2973. instructions, this is not an appropriate way to support them. (e.g. the 32-bit
  2974. SparcV8 has a 64-bit load, which instruction takes a single 32-bit register. The
  2975. hardware then loads into both the named register, and the next register. This
  2976. feature of inline asm would not be useful to support that.)
  2977. A few of the targets provide a template string modifier allowing explicit access
  2978. to the second register of a two-register operand (e.g. MIPS ``L``, ``M``, and
  2979. ``D``). On such an architecture, you can actually access the second allocated
  2980. register (yet, still, not any subsequent ones). But, in that case, you're still
  2981. probably better off simply splitting the value into two separate operands, for
  2982. clarity. (e.g. see the description of the ``A`` constraint on X86, which,
  2983. despite existing only for use with this feature, is not really a good idea to
  2984. use)
  2985. Indirect inputs and outputs
  2986. """""""""""""""""""""""""""
  2987. Indirect output or input constraints can be specified by the "``*``" modifier
  2988. (which goes after the "``=``" in case of an output). This indicates that the asm
  2989. will write to or read from the contents of an *address* provided as an input
  2990. argument. (Note that in this way, indirect outputs act more like an *input* than
  2991. an output: just like an input, they consume an argument of the call expression,
  2992. rather than producing a return value. An indirect output constraint is an
  2993. "output" only in that the asm is expected to write to the contents of the input
  2994. memory location, instead of just read from it).
  2995. This is most typically used for memory constraint, e.g. "``=*m``", to pass the
  2996. address of a variable as a value.
  2997. It is also possible to use an indirect *register* constraint, but only on output
  2998. (e.g. "``=*r``"). This will cause LLVM to allocate a register for an output
  2999. value normally, and then, separately emit a store to the address provided as
  3000. input, after the provided inline asm. (It's not clear what value this
  3001. functionality provides, compared to writing the store explicitly after the asm
  3002. statement, and it can only produce worse code, since it bypasses many
  3003. optimization passes. I would recommend not using it.)
  3004. Clobber constraints
  3005. """""""""""""""""""
  3006. A clobber constraint is indicated by a "``~``" prefix. A clobber does not
  3007. consume an input operand, nor generate an output. Clobbers cannot use any of the
  3008. general constraint code letters -- they may use only explicit register
  3009. constraints, e.g. "``~{eax}``". The one exception is that a clobber string of
  3010. "``~{memory}``" indicates that the assembly writes to arbitrary undeclared
  3011. memory locations -- not only the memory pointed to by a declared indirect
  3012. output.
  3013. Note that clobbering named registers that are also present in output
  3014. constraints is not legal.
  3015. Constraint Codes
  3016. """"""""""""""""
  3017. After a potential prefix comes constraint code, or codes.
  3018. A Constraint Code is either a single letter (e.g. "``r``"), a "``^``" character
  3019. followed by two letters (e.g. "``^wc``"), or "``{``" register-name "``}``"
  3020. (e.g. "``{eax}``").
  3021. The one and two letter constraint codes are typically chosen to be the same as
  3022. GCC's constraint codes.
  3023. A single constraint may include one or more than constraint code in it, leaving
  3024. it up to LLVM to choose which one to use. This is included mainly for
  3025. compatibility with the translation of GCC inline asm coming from clang.
  3026. There are two ways to specify alternatives, and either or both may be used in an
  3027. inline asm constraint list:
  3028. 1) Append the codes to each other, making a constraint code set. E.g. "``im``"
  3029. or "``{eax}m``". This means "choose any of the options in the set". The
  3030. choice of constraint is made independently for each constraint in the
  3031. constraint list.
  3032. 2) Use "``|``" between constraint code sets, creating alternatives. Every
  3033. constraint in the constraint list must have the same number of alternative
  3034. sets. With this syntax, the same alternative in *all* of the items in the
  3035. constraint list will be chosen together.
  3036. Putting those together, you might have a two operand constraint string like
  3037. ``"rm|r,ri|rm"``. This indicates that if operand 0 is ``r`` or ``m``, then
  3038. operand 1 may be one of ``r`` or ``i``. If operand 0 is ``r``, then operand 1
  3039. may be one of ``r`` or ``m``. But, operand 0 and 1 cannot both be of type m.
  3040. However, the use of either of the alternatives features is *NOT* recommended, as
  3041. LLVM is not able to make an intelligent choice about which one to use. (At the
  3042. point it currently needs to choose, not enough information is available to do so
  3043. in a smart way.) Thus, it simply tries to make a choice that's most likely to
  3044. compile, not one that will be optimal performance. (e.g., given "``rm``", it'll
  3045. always choose to use memory, not registers). And, if given multiple registers,
  3046. or multiple register classes, it will simply choose the first one. (In fact, it
  3047. doesn't currently even ensure explicitly specified physical registers are
  3048. unique, so specifying multiple physical registers as alternatives, like
  3049. ``{r11}{r12},{r11}{r12}``, will assign r11 to both operands, not at all what was
  3050. intended.)
  3051. Supported Constraint Code List
  3052. """"""""""""""""""""""""""""""
  3053. The constraint codes are, in general, expected to behave the same way they do in
  3054. GCC. LLVM's support is often implemented on an 'as-needed' basis, to support C
  3055. inline asm code which was supported by GCC. A mismatch in behavior between LLVM
  3056. and GCC likely indicates a bug in LLVM.
  3057. Some constraint codes are typically supported by all targets:
  3058. - ``r``: A register in the target's general purpose register class.
  3059. - ``m``: A memory address operand. It is target-specific what addressing modes
  3060. are supported, typical examples are register, or register + register offset,
  3061. or register + immediate offset (of some target-specific size).
  3062. - ``i``: An integer constant (of target-specific width). Allows either a simple
  3063. immediate, or a relocatable value.
  3064. - ``n``: An integer constant -- *not* including relocatable values.
  3065. - ``s``: An integer constant, but allowing *only* relocatable values.
  3066. - ``X``: Allows an operand of any kind, no constraint whatsoever. Typically
  3067. useful to pass a label for an asm branch or call.
  3068. .. FIXME: but that surely isn't actually okay to jump out of an asm
  3069. block without telling llvm about the control transfer???)
  3070. - ``{register-name}``: Requires exactly the named physical register.
  3071. Other constraints are target-specific:
  3072. AArch64:
  3073. - ``z``: An immediate integer 0. Outputs ``WZR`` or ``XZR``, as appropriate.
  3074. - ``I``: An immediate integer valid for an ``ADD`` or ``SUB`` instruction,
  3075. i.e. 0 to 4095 with optional shift by 12.
  3076. - ``J``: An immediate integer that, when negated, is valid for an ``ADD`` or
  3077. ``SUB`` instruction, i.e. -1 to -4095 with optional left shift by 12.
  3078. - ``K``: An immediate integer that is valid for the 'bitmask immediate 32' of a
  3079. logical instruction like ``AND``, ``EOR``, or ``ORR`` with a 32-bit register.
  3080. - ``L``: An immediate integer that is valid for the 'bitmask immediate 64' of a
  3081. logical instruction like ``AND``, ``EOR``, or ``ORR`` with a 64-bit register.
  3082. - ``M``: An immediate integer for use with the ``MOV`` assembly alias on a
  3083. 32-bit register. This is a superset of ``K``: in addition to the bitmask
  3084. immediate, also allows immediate integers which can be loaded with a single
  3085. ``MOVZ`` or ``MOVL`` instruction.
  3086. - ``N``: An immediate integer for use with the ``MOV`` assembly alias on a
  3087. 64-bit register. This is a superset of ``L``.
  3088. - ``Q``: Memory address operand must be in a single register (no
  3089. offsets). (However, LLVM currently does this for the ``m`` constraint as
  3090. well.)
  3091. - ``r``: A 32 or 64-bit integer register (W* or X*).
  3092. - ``w``: A 32, 64, or 128-bit floating-point, SIMD or SVE vector register.
  3093. - ``x``: Like w, but restricted to registers 0 to 15 inclusive.
  3094. - ``y``: Like w, but restricted to SVE vector registers Z0 to Z7 inclusive.
  3095. - ``Upl``: One of the low eight SVE predicate registers (P0 to P7)
  3096. - ``Upa``: Any of the SVE predicate registers (P0 to P15)
  3097. AMDGPU:
  3098. - ``r``: A 32 or 64-bit integer register.
  3099. - ``[0-9]v``: The 32-bit VGPR register, number 0-9.
  3100. - ``[0-9]s``: The 32-bit SGPR register, number 0-9.
  3101. All ARM modes:
  3102. - ``Q``, ``Um``, ``Un``, ``Uq``, ``Us``, ``Ut``, ``Uv``, ``Uy``: Memory address
  3103. operand. Treated the same as operand ``m``, at the moment.
  3104. - ``Te``: An even general-purpose 32-bit integer register: ``r0,r2,...,r12,r14``
  3105. - ``To``: An odd general-purpose 32-bit integer register: ``r1,r3,...,r11``
  3106. ARM and ARM's Thumb2 mode:
  3107. - ``j``: An immediate integer between 0 and 65535 (valid for ``MOVW``)
  3108. - ``I``: An immediate integer valid for a data-processing instruction.
  3109. - ``J``: An immediate integer between -4095 and 4095.
  3110. - ``K``: An immediate integer whose bitwise inverse is valid for a
  3111. data-processing instruction. (Can be used with template modifier "``B``" to
  3112. print the inverted value).
  3113. - ``L``: An immediate integer whose negation is valid for a data-processing
  3114. instruction. (Can be used with template modifier "``n``" to print the negated
  3115. value).
  3116. - ``M``: A power of two or a integer between 0 and 32.
  3117. - ``N``: Invalid immediate constraint.
  3118. - ``O``: Invalid immediate constraint.
  3119. - ``r``: A general-purpose 32-bit integer register (``r0-r15``).
  3120. - ``l``: In Thumb2 mode, low 32-bit GPR registers (``r0-r7``). In ARM mode, same
  3121. as ``r``.
  3122. - ``h``: In Thumb2 mode, a high 32-bit GPR register (``r8-r15``). In ARM mode,
  3123. invalid.
  3124. - ``w``: A 32, 64, or 128-bit floating-point/SIMD register in the ranges
  3125. ``s0-s31``, ``d0-d31``, or ``q0-q15``, respectively.
  3126. - ``t``: A 32, 64, or 128-bit floating-point/SIMD register in the ranges
  3127. ``s0-s31``, ``d0-d15``, or ``q0-q7``, respectively.
  3128. - ``x``: A 32, 64, or 128-bit floating-point/SIMD register in the ranges
  3129. ``s0-s15``, ``d0-d7``, or ``q0-q3``, respectively.
  3130. ARM's Thumb1 mode:
  3131. - ``I``: An immediate integer between 0 and 255.
  3132. - ``J``: An immediate integer between -255 and -1.
  3133. - ``K``: An immediate integer between 0 and 255, with optional left-shift by
  3134. some amount.
  3135. - ``L``: An immediate integer between -7 and 7.
  3136. - ``M``: An immediate integer which is a multiple of 4 between 0 and 1020.
  3137. - ``N``: An immediate integer between 0 and 31.
  3138. - ``O``: An immediate integer which is a multiple of 4 between -508 and 508.
  3139. - ``r``: A low 32-bit GPR register (``r0-r7``).
  3140. - ``l``: A low 32-bit GPR register (``r0-r7``).
  3141. - ``h``: A high GPR register (``r0-r7``).
  3142. - ``w``: A 32, 64, or 128-bit floating-point/SIMD register in the ranges
  3143. ``s0-s31``, ``d0-d31``, or ``q0-q15``, respectively.
  3144. - ``t``: A 32, 64, or 128-bit floating-point/SIMD register in the ranges
  3145. ``s0-s31``, ``d0-d15``, or ``q0-q7``, respectively.
  3146. - ``x``: A 32, 64, or 128-bit floating-point/SIMD register in the ranges
  3147. ``s0-s15``, ``d0-d7``, or ``q0-q3``, respectively.
  3148. Hexagon:
  3149. - ``o``, ``v``: A memory address operand, treated the same as constraint ``m``,
  3150. at the moment.
  3151. - ``r``: A 32 or 64-bit register.
  3152. MSP430:
  3153. - ``r``: An 8 or 16-bit register.
  3154. MIPS:
  3155. - ``I``: An immediate signed 16-bit integer.
  3156. - ``J``: An immediate integer zero.
  3157. - ``K``: An immediate unsigned 16-bit integer.
  3158. - ``L``: An immediate 32-bit integer, where the lower 16 bits are 0.
  3159. - ``N``: An immediate integer between -65535 and -1.
  3160. - ``O``: An immediate signed 15-bit integer.
  3161. - ``P``: An immediate integer between 1 and 65535.
  3162. - ``m``: A memory address operand. In MIPS-SE mode, allows a base address
  3163. register plus 16-bit immediate offset. In MIPS mode, just a base register.
  3164. - ``R``: A memory address operand. In MIPS-SE mode, allows a base address
  3165. register plus a 9-bit signed offset. In MIPS mode, the same as constraint
  3166. ``m``.
  3167. - ``ZC``: A memory address operand, suitable for use in a ``pref``, ``ll``, or
  3168. ``sc`` instruction on the given subtarget (details vary).
  3169. - ``r``, ``d``, ``y``: A 32 or 64-bit GPR register.
  3170. - ``f``: A 32 or 64-bit FPU register (``F0-F31``), or a 128-bit MSA register
  3171. (``W0-W31``). In the case of MSA registers, it is recommended to use the ``w``
  3172. argument modifier for compatibility with GCC.
  3173. - ``c``: A 32-bit or 64-bit GPR register suitable for indirect jump (always
  3174. ``25``).
  3175. - ``l``: The ``lo`` register, 32 or 64-bit.
  3176. - ``x``: Invalid.
  3177. NVPTX:
  3178. - ``b``: A 1-bit integer register.
  3179. - ``c`` or ``h``: A 16-bit integer register.
  3180. - ``r``: A 32-bit integer register.
  3181. - ``l`` or ``N``: A 64-bit integer register.
  3182. - ``f``: A 32-bit float register.
  3183. - ``d``: A 64-bit float register.
  3184. PowerPC:
  3185. - ``I``: An immediate signed 16-bit integer.
  3186. - ``J``: An immediate unsigned 16-bit integer, shifted left 16 bits.
  3187. - ``K``: An immediate unsigned 16-bit integer.
  3188. - ``L``: An immediate signed 16-bit integer, shifted left 16 bits.
  3189. - ``M``: An immediate integer greater than 31.
  3190. - ``N``: An immediate integer that is an exact power of 2.
  3191. - ``O``: The immediate integer constant 0.
  3192. - ``P``: An immediate integer constant whose negation is a signed 16-bit
  3193. constant.
  3194. - ``es``, ``o``, ``Q``, ``Z``, ``Zy``: A memory address operand, currently
  3195. treated the same as ``m``.
  3196. - ``r``: A 32 or 64-bit integer register.
  3197. - ``b``: A 32 or 64-bit integer register, excluding ``R0`` (that is:
  3198. ``R1-R31``).
  3199. - ``f``: A 32 or 64-bit float register (``F0-F31``), or when QPX is enabled, a
  3200. 128 or 256-bit QPX register (``Q0-Q31``; aliases the ``F`` registers).
  3201. - ``v``: For ``4 x f32`` or ``4 x f64`` types, when QPX is enabled, a
  3202. 128 or 256-bit QPX register (``Q0-Q31``), otherwise a 128-bit
  3203. altivec vector register (``V0-V31``).
  3204. .. FIXME: is this a bug that v accepts QPX registers? I think this
  3205. is supposed to only use the altivec vector registers?
  3206. - ``y``: Condition register (``CR0-CR7``).
  3207. - ``wc``: An individual CR bit in a CR register.
  3208. - ``wa``, ``wd``, ``wf``: Any 128-bit VSX vector register, from the full VSX
  3209. register set (overlapping both the floating-point and vector register files).
  3210. - ``ws``: A 32 or 64-bit floating-point register, from the full VSX register
  3211. set.
  3212. RISC-V:
  3213. - ``A``: An address operand (using a general-purpose register, without an
  3214. offset).
  3215. - ``I``: A 12-bit signed integer immediate operand.
  3216. - ``J``: A zero integer immediate operand.
  3217. - ``K``: A 5-bit unsigned integer immediate operand.
  3218. - ``f``: A 32- or 64-bit floating-point register (requires F or D extension).
  3219. - ``r``: A 32- or 64-bit general-purpose register (depending on the platform
  3220. ``XLEN``).
  3221. Sparc:
  3222. - ``I``: An immediate 13-bit signed integer.
  3223. - ``r``: A 32-bit integer register.
  3224. - ``f``: Any floating-point register on SparcV8, or a floating-point
  3225. register in the "low" half of the registers on SparcV9.
  3226. - ``e``: Any floating-point register. (Same as ``f`` on SparcV8.)
  3227. SystemZ:
  3228. - ``I``: An immediate unsigned 8-bit integer.
  3229. - ``J``: An immediate unsigned 12-bit integer.
  3230. - ``K``: An immediate signed 16-bit integer.
  3231. - ``L``: An immediate signed 20-bit integer.
  3232. - ``M``: An immediate integer 0x7fffffff.
  3233. - ``Q``: A memory address operand with a base address and a 12-bit immediate
  3234. unsigned displacement.
  3235. - ``R``: A memory address operand with a base address, a 12-bit immediate
  3236. unsigned displacement, and an index register.
  3237. - ``S``: A memory address operand with a base address and a 20-bit immediate
  3238. signed displacement.
  3239. - ``T``: A memory address operand with a base address, a 20-bit immediate
  3240. signed displacement, and an index register.
  3241. - ``r`` or ``d``: A 32, 64, or 128-bit integer register.
  3242. - ``a``: A 32, 64, or 128-bit integer address register (excludes R0, which in an
  3243. address context evaluates as zero).
  3244. - ``h``: A 32-bit value in the high part of a 64bit data register
  3245. (LLVM-specific)
  3246. - ``f``: A 32, 64, or 128-bit floating-point register.
  3247. X86:
  3248. - ``I``: An immediate integer between 0 and 31.
  3249. - ``J``: An immediate integer between 0 and 64.
  3250. - ``K``: An immediate signed 8-bit integer.
  3251. - ``L``: An immediate integer, 0xff or 0xffff or (in 64-bit mode only)
  3252. 0xffffffff.
  3253. - ``M``: An immediate integer between 0 and 3.
  3254. - ``N``: An immediate unsigned 8-bit integer.
  3255. - ``O``: An immediate integer between 0 and 127.
  3256. - ``e``: An immediate 32-bit signed integer.
  3257. - ``Z``: An immediate 32-bit unsigned integer.
  3258. - ``o``, ``v``: Treated the same as ``m``, at the moment.
  3259. - ``q``: An 8, 16, 32, or 64-bit register which can be accessed as an 8-bit
  3260. ``l`` integer register. On X86-32, this is the ``a``, ``b``, ``c``, and ``d``
  3261. registers, and on X86-64, it is all of the integer registers.
  3262. - ``Q``: An 8, 16, 32, or 64-bit register which can be accessed as an 8-bit
  3263. ``h`` integer register. This is the ``a``, ``b``, ``c``, and ``d`` registers.
  3264. - ``r`` or ``l``: An 8, 16, 32, or 64-bit integer register.
  3265. - ``R``: An 8, 16, 32, or 64-bit "legacy" integer register -- one which has
  3266. existed since i386, and can be accessed without the REX prefix.
  3267. - ``f``: A 32, 64, or 80-bit '387 FPU stack pseudo-register.
  3268. - ``y``: A 64-bit MMX register, if MMX is enabled.
  3269. - ``x``: If SSE is enabled: a 32 or 64-bit scalar operand, or 128-bit vector
  3270. operand in a SSE register. If AVX is also enabled, can also be a 256-bit
  3271. vector operand in an AVX register. If AVX-512 is also enabled, can also be a
  3272. 512-bit vector operand in an AVX512 register, Otherwise, an error.
  3273. - ``Y``: The same as ``x``, if *SSE2* is enabled, otherwise an error.
  3274. - ``A``: Special case: allocates EAX first, then EDX, for a single operand (in
  3275. 32-bit mode, a 64-bit integer operand will get split into two registers). It
  3276. is not recommended to use this constraint, as in 64-bit mode, the 64-bit
  3277. operand will get allocated only to RAX -- if two 32-bit operands are needed,
  3278. you're better off splitting it yourself, before passing it to the asm
  3279. statement.
  3280. XCore:
  3281. - ``r``: A 32-bit integer register.
  3282. .. _inline-asm-modifiers:
  3283. Asm template argument modifiers
  3284. ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  3285. In the asm template string, modifiers can be used on the operand reference, like
  3286. "``${0:n}``".
  3287. The modifiers are, in general, expected to behave the same way they do in
  3288. GCC. LLVM's support is often implemented on an 'as-needed' basis, to support C
  3289. inline asm code which was supported by GCC. A mismatch in behavior between LLVM
  3290. and GCC likely indicates a bug in LLVM.
  3291. Target-independent:
  3292. - ``c``: Print an immediate integer constant unadorned, without
  3293. the target-specific immediate punctuation (e.g. no ``$`` prefix).
  3294. - ``n``: Negate and print immediate integer constant unadorned, without the
  3295. target-specific immediate punctuation (e.g. no ``$`` prefix).
  3296. - ``l``: Print as an unadorned label, without the target-specific label
  3297. punctuation (e.g. no ``$`` prefix).
  3298. AArch64:
  3299. - ``w``: Print a GPR register with a ``w*`` name instead of ``x*`` name. E.g.,
  3300. instead of ``x30``, print ``w30``.
  3301. - ``x``: Print a GPR register with a ``x*`` name. (this is the default, anyhow).
  3302. - ``b``, ``h``, ``s``, ``d``, ``q``: Print a floating-point/SIMD register with a
  3303. ``b*``, ``h*``, ``s*``, ``d*``, or ``q*`` name, rather than the default of
  3304. ``v*``.
  3305. AMDGPU:
  3306. - ``r``: No effect.
  3307. ARM:
  3308. - ``a``: Print an operand as an address (with ``[`` and ``]`` surrounding a
  3309. register).
  3310. - ``P``: No effect.
  3311. - ``q``: No effect.
  3312. - ``y``: Print a VFP single-precision register as an indexed double (e.g. print
  3313. as ``d4[1]`` instead of ``s9``)
  3314. - ``B``: Bitwise invert and print an immediate integer constant without ``#``
  3315. prefix.
  3316. - ``L``: Print the low 16-bits of an immediate integer constant.
  3317. - ``M``: Print as a register set suitable for ldm/stm. Also prints *all*
  3318. register operands subsequent to the specified one (!), so use carefully.
  3319. - ``Q``: Print the low-order register of a register-pair, or the low-order
  3320. register of a two-register operand.
  3321. - ``R``: Print the high-order register of a register-pair, or the high-order
  3322. register of a two-register operand.
  3323. - ``H``: Print the second register of a register-pair. (On a big-endian system,
  3324. ``H`` is equivalent to ``Q``, and on little-endian system, ``H`` is equivalent
  3325. to ``R``.)
  3326. .. FIXME: H doesn't currently support printing the second register
  3327. of a two-register operand.
  3328. - ``e``: Print the low doubleword register of a NEON quad register.
  3329. - ``f``: Print the high doubleword register of a NEON quad register.
  3330. - ``m``: Print the base register of a memory operand without the ``[`` and ``]``
  3331. adornment.
  3332. Hexagon:
  3333. - ``L``: Print the second register of a two-register operand. Requires that it
  3334. has been allocated consecutively to the first.
  3335. .. FIXME: why is it restricted to consecutive ones? And there's
  3336. nothing that ensures that happens, is there?
  3337. - ``I``: Print the letter 'i' if the operand is an integer constant, otherwise
  3338. nothing. Used to print 'addi' vs 'add' instructions.
  3339. MSP430:
  3340. No additional modifiers.
  3341. MIPS:
  3342. - ``X``: Print an immediate integer as hexadecimal
  3343. - ``x``: Print the low 16 bits of an immediate integer as hexadecimal.
  3344. - ``d``: Print an immediate integer as decimal.
  3345. - ``m``: Subtract one and print an immediate integer as decimal.
  3346. - ``z``: Print $0 if an immediate zero, otherwise print normally.
  3347. - ``L``: Print the low-order register of a two-register operand, or prints the
  3348. address of the low-order word of a double-word memory operand.
  3349. .. FIXME: L seems to be missing memory operand support.
  3350. - ``M``: Print the high-order register of a two-register operand, or prints the
  3351. address of the high-order word of a double-word memory operand.
  3352. .. FIXME: M seems to be missing memory operand support.
  3353. - ``D``: Print the second register of a two-register operand, or prints the
  3354. second word of a double-word memory operand. (On a big-endian system, ``D`` is
  3355. equivalent to ``L``, and on little-endian system, ``D`` is equivalent to
  3356. ``M``.)
  3357. - ``w``: No effect. Provided for compatibility with GCC which requires this
  3358. modifier in order to print MSA registers (``W0-W31``) with the ``f``
  3359. constraint.
  3360. NVPTX:
  3361. - ``r``: No effect.
  3362. PowerPC:
  3363. - ``L``: Print the second register of a two-register operand. Requires that it
  3364. has been allocated consecutively to the first.
  3365. .. FIXME: why is it restricted to consecutive ones? And there's
  3366. nothing that ensures that happens, is there?
  3367. - ``I``: Print the letter 'i' if the operand is an integer constant, otherwise
  3368. nothing. Used to print 'addi' vs 'add' instructions.
  3369. - ``y``: For a memory operand, prints formatter for a two-register X-form
  3370. instruction. (Currently always prints ``r0,OPERAND``).
  3371. - ``U``: Prints 'u' if the memory operand is an update form, and nothing
  3372. otherwise. (NOTE: LLVM does not support update form, so this will currently
  3373. always print nothing)
  3374. - ``X``: Prints 'x' if the memory operand is an indexed form. (NOTE: LLVM does
  3375. not support indexed form, so this will currently always print nothing)
  3376. Sparc:
  3377. - ``r``: No effect.
  3378. SystemZ:
  3379. SystemZ implements only ``n``, and does *not* support any of the other
  3380. target-independent modifiers.
  3381. X86:
  3382. - ``c``: Print an unadorned integer or symbol name. (The latter is
  3383. target-specific behavior for this typically target-independent modifier).
  3384. - ``A``: Print a register name with a '``*``' before it.
  3385. - ``b``: Print an 8-bit register name (e.g. ``al``); do nothing on a memory
  3386. operand.
  3387. - ``h``: Print the upper 8-bit register name (e.g. ``ah``); do nothing on a
  3388. memory operand.
  3389. - ``w``: Print the 16-bit register name (e.g. ``ax``); do nothing on a memory
  3390. operand.
  3391. - ``k``: Print the 32-bit register name (e.g. ``eax``); do nothing on a memory
  3392. operand.
  3393. - ``q``: Print the 64-bit register name (e.g. ``rax``), if 64-bit registers are
  3394. available, otherwise the 32-bit register name; do nothing on a memory operand.
  3395. - ``n``: Negate and print an unadorned integer, or, for operands other than an
  3396. immediate integer (e.g. a relocatable symbol expression), print a '-' before
  3397. the operand. (The behavior for relocatable symbol expressions is a
  3398. target-specific behavior for this typically target-independent modifier)
  3399. - ``H``: Print a memory reference with additional offset +8.
  3400. - ``P``: Print a memory reference or operand for use as the argument of a call
  3401. instruction. (E.g. omit ``(rip)``, even though it's PC-relative.)
  3402. XCore:
  3403. No additional modifiers.
  3404. Inline Asm Metadata
  3405. ^^^^^^^^^^^^^^^^^^^
  3406. The call instructions that wrap inline asm nodes may have a
  3407. "``!srcloc``" MDNode attached to it that contains a list of constant
  3408. integers. If present, the code generator will use the integer as the
  3409. location cookie value when report errors through the ``LLVMContext``
  3410. error reporting mechanisms. This allows a front-end to correlate backend
  3411. errors that occur with inline asm back to the source code that produced
  3412. it. For example:
  3413. .. code-block:: llvm
  3414. call void asm sideeffect "something bad", ""(), !srcloc !42
  3415. ...
  3416. !42 = !{ i32 1234567 }
  3417. It is up to the front-end to make sense of the magic numbers it places
  3418. in the IR. If the MDNode contains multiple constants, the code generator
  3419. will use the one that corresponds to the line of the asm that the error
  3420. occurs on.
  3421. .. _metadata:
  3422. Metadata
  3423. ========
  3424. LLVM IR allows metadata to be attached to instructions in the program
  3425. that can convey extra information about the code to the optimizers and
  3426. code generator. One example application of metadata is source-level
  3427. debug information. There are two metadata primitives: strings and nodes.
  3428. Metadata does not have a type, and is not a value. If referenced from a
  3429. ``call`` instruction, it uses the ``metadata`` type.
  3430. All metadata are identified in syntax by a exclamation point ('``!``').
  3431. .. _metadata-string:
  3432. Metadata Nodes and Metadata Strings
  3433. -----------------------------------
  3434. A metadata string is a string surrounded by double quotes. It can
  3435. contain any character by escaping non-printable characters with
  3436. "``\xx``" where "``xx``" is the two digit hex code. For example:
  3437. "``!"test\00"``".
  3438. Metadata nodes are represented with notation similar to structure
  3439. constants (a comma separated list of elements, surrounded by braces and
  3440. preceded by an exclamation point). Metadata nodes can have any values as
  3441. their operand. For example:
  3442. .. code-block:: llvm
  3443. !{ !"test\00", i32 10}
  3444. Metadata nodes that aren't uniqued use the ``distinct`` keyword. For example:
  3445. .. code-block:: text
  3446. !0 = distinct !{!"test\00", i32 10}
  3447. ``distinct`` nodes are useful when nodes shouldn't be merged based on their
  3448. content. They can also occur when transformations cause uniquing collisions
  3449. when metadata operands change.
  3450. A :ref:`named metadata <namedmetadatastructure>` is a collection of
  3451. metadata nodes, which can be looked up in the module symbol table. For
  3452. example:
  3453. .. code-block:: llvm
  3454. !foo = !{!4, !3}
  3455. Metadata can be used as function arguments. Here the ``llvm.dbg.value``
  3456. intrinsic is using three metadata arguments:
  3457. .. code-block:: llvm
  3458. call void @llvm.dbg.value(metadata !24, metadata !25, metadata !26)
  3459. Metadata can be attached to an instruction. Here metadata ``!21`` is attached
  3460. to the ``add`` instruction using the ``!dbg`` identifier:
  3461. .. code-block:: llvm
  3462. %indvar.next = add i64 %indvar, 1, !dbg !21
  3463. Metadata can also be attached to a function or a global variable. Here metadata
  3464. ``!22`` is attached to the ``f1`` and ``f2 functions, and the globals ``g1``
  3465. and ``g2`` using the ``!dbg`` identifier:
  3466. .. code-block:: llvm
  3467. declare !dbg !22 void @f1()
  3468. define void @f2() !dbg !22 {
  3469. ret void
  3470. }
  3471. @g1 = global i32 0, !dbg !22
  3472. @g2 = external global i32, !dbg !22
  3473. A transformation is required to drop any metadata attachment that it does not
  3474. know or know it can't preserve. Currently there is an exception for metadata
  3475. attachment to globals for ``!type`` and ``!absolute_symbol`` which can't be
  3476. unconditionally dropped unless the global is itself deleted.
  3477. Metadata attached to a module using named metadata may not be dropped, with
  3478. the exception of debug metadata (named metadata with the name ``!llvm.dbg.*``).
  3479. More information about specific metadata nodes recognized by the
  3480. optimizers and code generator is found below.
  3481. .. _specialized-metadata:
  3482. Specialized Metadata Nodes
  3483. ^^^^^^^^^^^^^^^^^^^^^^^^^^
  3484. Specialized metadata nodes are custom data structures in metadata (as opposed
  3485. to generic tuples). Their fields are labelled, and can be specified in any
  3486. order.
  3487. These aren't inherently debug info centric, but currently all the specialized
  3488. metadata nodes are related to debug info.
  3489. .. _DICompileUnit:
  3490. DICompileUnit
  3491. """""""""""""
  3492. ``DICompileUnit`` nodes represent a compile unit. The ``enums:``,
  3493. ``retainedTypes:``, ``globals:``, ``imports:`` and ``macros:`` fields are tuples
  3494. containing the debug info to be emitted along with the compile unit, regardless
  3495. of code optimizations (some nodes are only emitted if there are references to
  3496. them from instructions). The ``debugInfoForProfiling:`` field is a boolean
  3497. indicating whether or not line-table discriminators are updated to provide
  3498. more-accurate debug info for profiling results.
  3499. .. code-block:: text
  3500. !0 = !DICompileUnit(language: DW_LANG_C99, file: !1, producer: "clang",
  3501. isOptimized: true, flags: "-O2", runtimeVersion: 2,
  3502. splitDebugFilename: "abc.debug", emissionKind: FullDebug,
  3503. enums: !2, retainedTypes: !3, globals: !4, imports: !5,
  3504. macros: !6, dwoId: 0x0abcd)
  3505. Compile unit descriptors provide the root scope for objects declared in a
  3506. specific compilation unit. File descriptors are defined using this scope. These
  3507. descriptors are collected by a named metadata node ``!llvm.dbg.cu``. They keep
  3508. track of global variables, type information, and imported entities (declarations
  3509. and namespaces).
  3510. .. _DIFile:
  3511. DIFile
  3512. """"""
  3513. ``DIFile`` nodes represent files. The ``filename:`` can include slashes.
  3514. .. code-block:: none
  3515. !0 = !DIFile(filename: "path/to/file", directory: "/path/to/dir",
  3516. checksumkind: CSK_MD5,
  3517. checksum: "000102030405060708090a0b0c0d0e0f")
  3518. Files are sometimes used in ``scope:`` fields, and are the only valid target
  3519. for ``file:`` fields.
  3520. Valid values for ``checksumkind:`` field are: {CSK_None, CSK_MD5, CSK_SHA1}
  3521. .. _DIBasicType:
  3522. DIBasicType
  3523. """""""""""
  3524. ``DIBasicType`` nodes represent primitive types, such as ``int``, ``bool`` and
  3525. ``float``. ``tag:`` defaults to ``DW_TAG_base_type``.
  3526. .. code-block:: text
  3527. !0 = !DIBasicType(name: "unsigned char", size: 8, align: 8,
  3528. encoding: DW_ATE_unsigned_char)
  3529. !1 = !DIBasicType(tag: DW_TAG_unspecified_type, name: "decltype(nullptr)")
  3530. The ``encoding:`` describes the details of the type. Usually it's one of the
  3531. following:
  3532. .. code-block:: text
  3533. DW_ATE_address = 1
  3534. DW_ATE_boolean = 2
  3535. DW_ATE_float = 4
  3536. DW_ATE_signed = 5
  3537. DW_ATE_signed_char = 6
  3538. DW_ATE_unsigned = 7
  3539. DW_ATE_unsigned_char = 8
  3540. .. _DISubroutineType:
  3541. DISubroutineType
  3542. """"""""""""""""
  3543. ``DISubroutineType`` nodes represent subroutine types. Their ``types:`` field
  3544. refers to a tuple; the first operand is the return type, while the rest are the
  3545. types of the formal arguments in order. If the first operand is ``null``, that
  3546. represents a function with no return value (such as ``void foo() {}`` in C++).
  3547. .. code-block:: text
  3548. !0 = !BasicType(name: "int", size: 32, align: 32, DW_ATE_signed)
  3549. !1 = !BasicType(name: "char", size: 8, align: 8, DW_ATE_signed_char)
  3550. !2 = !DISubroutineType(types: !{null, !0, !1}) ; void (int, char)
  3551. .. _DIDerivedType:
  3552. DIDerivedType
  3553. """""""""""""
  3554. ``DIDerivedType`` nodes represent types derived from other types, such as
  3555. qualified types.
  3556. .. code-block:: text
  3557. !0 = !DIBasicType(name: "unsigned char", size: 8, align: 8,
  3558. encoding: DW_ATE_unsigned_char)
  3559. !1 = !DIDerivedType(tag: DW_TAG_pointer_type, baseType: !0, size: 32,
  3560. align: 32)
  3561. The following ``tag:`` values are valid:
  3562. .. code-block:: text
  3563. DW_TAG_member = 13
  3564. DW_TAG_pointer_type = 15
  3565. DW_TAG_reference_type = 16
  3566. DW_TAG_typedef = 22
  3567. DW_TAG_inheritance = 28
  3568. DW_TAG_ptr_to_member_type = 31
  3569. DW_TAG_const_type = 38
  3570. DW_TAG_friend = 42
  3571. DW_TAG_volatile_type = 53
  3572. DW_TAG_restrict_type = 55
  3573. DW_TAG_atomic_type = 71
  3574. .. _DIDerivedTypeMember:
  3575. ``DW_TAG_member`` is used to define a member of a :ref:`composite type
  3576. <DICompositeType>`. The type of the member is the ``baseType:``. The
  3577. ``offset:`` is the member's bit offset. If the composite type has an ODR
  3578. ``identifier:`` and does not set ``flags: DIFwdDecl``, then the member is
  3579. uniqued based only on its ``name:`` and ``scope:``.
  3580. ``DW_TAG_inheritance`` and ``DW_TAG_friend`` are used in the ``elements:``
  3581. field of :ref:`composite types <DICompositeType>` to describe parents and
  3582. friends.
  3583. ``DW_TAG_typedef`` is used to provide a name for the ``baseType:``.
  3584. ``DW_TAG_pointer_type``, ``DW_TAG_reference_type``, ``DW_TAG_const_type``,
  3585. ``DW_TAG_volatile_type``, ``DW_TAG_restrict_type`` and ``DW_TAG_atomic_type``
  3586. are used to qualify the ``baseType:``.
  3587. Note that the ``void *`` type is expressed as a type derived from NULL.
  3588. .. _DICompositeType:
  3589. DICompositeType
  3590. """""""""""""""
  3591. ``DICompositeType`` nodes represent types composed of other types, like
  3592. structures and unions. ``elements:`` points to a tuple of the composed types.
  3593. If the source language supports ODR, the ``identifier:`` field gives the unique
  3594. identifier used for type merging between modules. When specified,
  3595. :ref:`subprogram declarations <DISubprogramDeclaration>` and :ref:`member
  3596. derived types <DIDerivedTypeMember>` that reference the ODR-type in their
  3597. ``scope:`` change uniquing rules.
  3598. For a given ``identifier:``, there should only be a single composite type that
  3599. does not have ``flags: DIFlagFwdDecl`` set. LLVM tools that link modules
  3600. together will unique such definitions at parse time via the ``identifier:``
  3601. field, even if the nodes are ``distinct``.
  3602. .. code-block:: text
  3603. !0 = !DIEnumerator(name: "SixKind", value: 7)
  3604. !1 = !DIEnumerator(name: "SevenKind", value: 7)
  3605. !2 = !DIEnumerator(name: "NegEightKind", value: -8)
  3606. !3 = !DICompositeType(tag: DW_TAG_enumeration_type, name: "Enum", file: !12,
  3607. line: 2, size: 32, align: 32, identifier: "_M4Enum",
  3608. elements: !{!0, !1, !2})
  3609. The following ``tag:`` values are valid:
  3610. .. code-block:: text
  3611. DW_TAG_array_type = 1
  3612. DW_TAG_class_type = 2
  3613. DW_TAG_enumeration_type = 4
  3614. DW_TAG_structure_type = 19
  3615. DW_TAG_union_type = 23
  3616. For ``DW_TAG_array_type``, the ``elements:`` should be :ref:`subrange
  3617. descriptors <DISubrange>`, each representing the range of subscripts at that
  3618. level of indexing. The ``DIFlagVector`` flag to ``flags:`` indicates that an
  3619. array type is a native packed vector.
  3620. For ``DW_TAG_enumeration_type``, the ``elements:`` should be :ref:`enumerator
  3621. descriptors <DIEnumerator>`, each representing the definition of an enumeration
  3622. value for the set. All enumeration type descriptors are collected in the
  3623. ``enums:`` field of the :ref:`compile unit <DICompileUnit>`.
  3624. For ``DW_TAG_structure_type``, ``DW_TAG_class_type``, and
  3625. ``DW_TAG_union_type``, the ``elements:`` should be :ref:`derived types
  3626. <DIDerivedType>` with ``tag: DW_TAG_member``, ``tag: DW_TAG_inheritance``, or
  3627. ``tag: DW_TAG_friend``; or :ref:`subprograms <DISubprogram>` with
  3628. ``isDefinition: false``.
  3629. .. _DISubrange:
  3630. DISubrange
  3631. """"""""""
  3632. ``DISubrange`` nodes are the elements for ``DW_TAG_array_type`` variants of
  3633. :ref:`DICompositeType`.
  3634. - ``count: -1`` indicates an empty array.
  3635. - ``count: !9`` describes the count with a :ref:`DILocalVariable`.
  3636. - ``count: !11`` describes the count with a :ref:`DIGlobalVariable`.
  3637. .. code-block:: text
  3638. !0 = !DISubrange(count: 5, lowerBound: 0) ; array counting from 0
  3639. !1 = !DISubrange(count: 5, lowerBound: 1) ; array counting from 1
  3640. !2 = !DISubrange(count: -1) ; empty array.
  3641. ; Scopes used in rest of example
  3642. !6 = !DIFile(filename: "vla.c", directory: "/path/to/file")
  3643. !7 = distinct !DICompileUnit(language: DW_LANG_C99, file: !6)
  3644. !8 = distinct !DISubprogram(name: "foo", scope: !7, file: !6, line: 5)
  3645. ; Use of local variable as count value
  3646. !9 = !DIBasicType(name: "int", size: 32, encoding: DW_ATE_signed)
  3647. !10 = !DILocalVariable(name: "count", scope: !8, file: !6, line: 42, type: !9)
  3648. !11 = !DISubrange(count: !10, lowerBound: 0)
  3649. ; Use of global variable as count value
  3650. !12 = !DIGlobalVariable(name: "count", scope: !8, file: !6, line: 22, type: !9)
  3651. !13 = !DISubrange(count: !12, lowerBound: 0)
  3652. .. _DIEnumerator:
  3653. DIEnumerator
  3654. """"""""""""
  3655. ``DIEnumerator`` nodes are the elements for ``DW_TAG_enumeration_type``
  3656. variants of :ref:`DICompositeType`.
  3657. .. code-block:: text
  3658. !0 = !DIEnumerator(name: "SixKind", value: 7)
  3659. !1 = !DIEnumerator(name: "SevenKind", value: 7)
  3660. !2 = !DIEnumerator(name: "NegEightKind", value: -8)
  3661. DITemplateTypeParameter
  3662. """""""""""""""""""""""
  3663. ``DITemplateTypeParameter`` nodes represent type parameters to generic source
  3664. language constructs. They are used (optionally) in :ref:`DICompositeType` and
  3665. :ref:`DISubprogram` ``templateParams:`` fields.
  3666. .. code-block:: text
  3667. !0 = !DITemplateTypeParameter(name: "Ty", type: !1)
  3668. DITemplateValueParameter
  3669. """"""""""""""""""""""""
  3670. ``DITemplateValueParameter`` nodes represent value parameters to generic source
  3671. language constructs. ``tag:`` defaults to ``DW_TAG_template_value_parameter``,
  3672. but if specified can also be set to ``DW_TAG_GNU_template_template_param`` or
  3673. ``DW_TAG_GNU_template_param_pack``. They are used (optionally) in
  3674. :ref:`DICompositeType` and :ref:`DISubprogram` ``templateParams:`` fields.
  3675. .. code-block:: text
  3676. !0 = !DITemplateValueParameter(name: "Ty", type: !1, value: i32 7)
  3677. DINamespace
  3678. """""""""""
  3679. ``DINamespace`` nodes represent namespaces in the source language.
  3680. .. code-block:: text
  3681. !0 = !DINamespace(name: "myawesomeproject", scope: !1, file: !2, line: 7)
  3682. .. _DIGlobalVariable:
  3683. DIGlobalVariable
  3684. """"""""""""""""
  3685. ``DIGlobalVariable`` nodes represent global variables in the source language.
  3686. .. code-block:: text
  3687. @foo = global i32, !dbg !0
  3688. !0 = !DIGlobalVariableExpression(var: !1, expr: !DIExpression())
  3689. !1 = !DIGlobalVariable(name: "foo", linkageName: "foo", scope: !2,
  3690. file: !3, line: 7, type: !4, isLocal: true,
  3691. isDefinition: false, declaration: !5)
  3692. DIGlobalVariableExpression
  3693. """"""""""""""""""""""""""
  3694. ``DIGlobalVariableExpression`` nodes tie a :ref:`DIGlobalVariable` together
  3695. with a :ref:`DIExpression`.
  3696. .. code-block:: text
  3697. @lower = global i32, !dbg !0
  3698. @upper = global i32, !dbg !1
  3699. !0 = !DIGlobalVariableExpression(
  3700. var: !2,
  3701. expr: !DIExpression(DW_OP_LLVM_fragment, 0, 32)
  3702. )
  3703. !1 = !DIGlobalVariableExpression(
  3704. var: !2,
  3705. expr: !DIExpression(DW_OP_LLVM_fragment, 32, 32)
  3706. )
  3707. !2 = !DIGlobalVariable(name: "split64", linkageName: "split64", scope: !3,
  3708. file: !4, line: 8, type: !5, declaration: !6)
  3709. All global variable expressions should be referenced by the `globals:` field of
  3710. a :ref:`compile unit <DICompileUnit>`.
  3711. .. _DISubprogram:
  3712. DISubprogram
  3713. """"""""""""
  3714. ``DISubprogram`` nodes represent functions from the source language. A
  3715. distinct ``DISubprogram`` may be attached to a function definition using
  3716. ``!dbg`` metadata. A unique ``DISubprogram`` may be attached to a function
  3717. declaration used for call site debug info. The ``variables:`` field points at
  3718. :ref:`variables <DILocalVariable>` that must be retained, even if their IR
  3719. counterparts are optimized out of the IR. The ``type:`` field must point at an
  3720. :ref:`DISubroutineType`.
  3721. .. _DISubprogramDeclaration:
  3722. When ``isDefinition: false``, subprograms describe a declaration in the type
  3723. tree as opposed to a definition of a function. If the scope is a composite
  3724. type with an ODR ``identifier:`` and that does not set ``flags: DIFwdDecl``,
  3725. then the subprogram declaration is uniqued based only on its ``linkageName:``
  3726. and ``scope:``.
  3727. .. code-block:: text
  3728. define void @_Z3foov() !dbg !0 {
  3729. ...
  3730. }
  3731. !0 = distinct !DISubprogram(name: "foo", linkageName: "_Zfoov", scope: !1,
  3732. file: !2, line: 7, type: !3, isLocal: true,
  3733. isDefinition: true, scopeLine: 8,
  3734. containingType: !4,
  3735. virtuality: DW_VIRTUALITY_pure_virtual,
  3736. virtualIndex: 10, flags: DIFlagPrototyped,
  3737. isOptimized: true, unit: !5, templateParams: !6,
  3738. declaration: !7, variables: !8, thrownTypes: !9)
  3739. .. _DILexicalBlock:
  3740. DILexicalBlock
  3741. """"""""""""""
  3742. ``DILexicalBlock`` nodes describe nested blocks within a :ref:`subprogram
  3743. <DISubprogram>`. The line number and column numbers are used to distinguish
  3744. two lexical blocks at same depth. They are valid targets for ``scope:``
  3745. fields.
  3746. .. code-block:: text
  3747. !0 = distinct !DILexicalBlock(scope: !1, file: !2, line: 7, column: 35)
  3748. Usually lexical blocks are ``distinct`` to prevent node merging based on
  3749. operands.
  3750. .. _DILexicalBlockFile:
  3751. DILexicalBlockFile
  3752. """"""""""""""""""
  3753. ``DILexicalBlockFile`` nodes are used to discriminate between sections of a
  3754. :ref:`lexical block <DILexicalBlock>`. The ``file:`` field can be changed to
  3755. indicate textual inclusion, or the ``discriminator:`` field can be used to
  3756. discriminate between control flow within a single block in the source language.
  3757. .. code-block:: text
  3758. !0 = !DILexicalBlock(scope: !3, file: !4, line: 7, column: 35)
  3759. !1 = !DILexicalBlockFile(scope: !0, file: !4, discriminator: 0)
  3760. !2 = !DILexicalBlockFile(scope: !0, file: !4, discriminator: 1)
  3761. .. _DILocation:
  3762. DILocation
  3763. """"""""""
  3764. ``DILocation`` nodes represent source debug locations. The ``scope:`` field is
  3765. mandatory, and points at an :ref:`DILexicalBlockFile`, an
  3766. :ref:`DILexicalBlock`, or an :ref:`DISubprogram`.
  3767. .. code-block:: text
  3768. !0 = !DILocation(line: 2900, column: 42, scope: !1, inlinedAt: !2)
  3769. .. _DILocalVariable:
  3770. DILocalVariable
  3771. """""""""""""""
  3772. ``DILocalVariable`` nodes represent local variables in the source language. If
  3773. the ``arg:`` field is set to non-zero, then this variable is a subprogram
  3774. parameter, and it will be included in the ``variables:`` field of its
  3775. :ref:`DISubprogram`.
  3776. .. code-block:: text
  3777. !0 = !DILocalVariable(name: "this", arg: 1, scope: !3, file: !2, line: 7,
  3778. type: !3, flags: DIFlagArtificial)
  3779. !1 = !DILocalVariable(name: "x", arg: 2, scope: !4, file: !2, line: 7,
  3780. type: !3)
  3781. !2 = !DILocalVariable(name: "y", scope: !5, file: !2, line: 7, type: !3)
  3782. .. _DIExpression:
  3783. DIExpression
  3784. """"""""""""
  3785. ``DIExpression`` nodes represent expressions that are inspired by the DWARF
  3786. expression language. They are used in :ref:`debug intrinsics<dbg_intrinsics>`
  3787. (such as ``llvm.dbg.declare`` and ``llvm.dbg.value``) to describe how the
  3788. referenced LLVM variable relates to the source language variable. Debug
  3789. intrinsics are interpreted left-to-right: start by pushing the value/address
  3790. operand of the intrinsic onto a stack, then repeatedly push and evaluate
  3791. opcodes from the DIExpression until the final variable description is produced.
  3792. The current supported opcode vocabulary is limited:
  3793. - ``DW_OP_deref`` dereferences the top of the expression stack.
  3794. - ``DW_OP_plus`` pops the last two entries from the expression stack, adds
  3795. them together and appends the result to the expression stack.
  3796. - ``DW_OP_minus`` pops the last two entries from the expression stack, subtracts
  3797. the last entry from the second last entry and appends the result to the
  3798. expression stack.
  3799. - ``DW_OP_plus_uconst, 93`` adds ``93`` to the working expression.
  3800. - ``DW_OP_LLVM_fragment, 16, 8`` specifies the offset and size (``16`` and ``8``
  3801. here, respectively) of the variable fragment from the working expression. Note
  3802. that contrary to DW_OP_bit_piece, the offset is describing the location
  3803. within the described source variable.
  3804. - ``DW_OP_LLVM_convert, 16, DW_ATE_signed`` specifies a bit size and encoding
  3805. (``16`` and ``DW_ATE_signed`` here, respectively) to which the top of the
  3806. expression stack is to be converted. Maps into a ``DW_OP_convert`` operation
  3807. that references a base type constructed from the supplied values.
  3808. - ``DW_OP_LLVM_tag_offset, tag_offset`` specifies that a memory tag should be
  3809. optionally applied to the pointer. The memory tag is derived from the
  3810. given tag offset in an implementation-defined manner.
  3811. - ``DW_OP_swap`` swaps top two stack entries.
  3812. - ``DW_OP_xderef`` provides extended dereference mechanism. The entry at the top
  3813. of the stack is treated as an address. The second stack entry is treated as an
  3814. address space identifier.
  3815. - ``DW_OP_stack_value`` marks a constant value.
  3816. - ``DW_OP_LLVM_entry_value, N`` can only appear at the beginning of a
  3817. ``DIExpression``, and it specifies that all register and memory read
  3818. operations for the debug value instruction's value/address operand and for
  3819. the ``(N - 1)`` operations immediately following the
  3820. ``DW_OP_LLVM_entry_value`` refer to their respective values at function
  3821. entry. For example, ``!DIExpression(DW_OP_LLVM_entry_value, 1,
  3822. DW_OP_plus_uconst, 123, DW_OP_stack_value)`` specifies an expression where
  3823. the entry value of the debug value instruction's value/address operand is
  3824. pushed to the stack, and is added with 123. Due to framework limitations
  3825. ``N`` can currently only be 1.
  3826. ``DW_OP_LLVM_entry_value`` is only legal in MIR. The operation is introduced
  3827. by the ``LiveDebugValues`` pass; currently only for function parameters that
  3828. are unmodified throughout a function and that are described as simple
  3829. register location descriptions. The operation is also introduced by the
  3830. ``AsmPrinter`` pass when a call site parameter value
  3831. (``DW_AT_call_site_parameter_value``) is represented as entry value of the
  3832. parameter.
  3833. - ``DW_OP_breg`` (or ``DW_OP_bregx``) represents a content on the provided
  3834. signed offset of the specified register. The opcode is only generated by the
  3835. ``AsmPrinter`` pass to describe call site parameter value which requires an
  3836. expression over two registers.
  3837. DWARF specifies three kinds of simple location descriptions: Register, memory,
  3838. and implicit location descriptions. Note that a location description is
  3839. defined over certain ranges of a program, i.e the location of a variable may
  3840. change over the course of the program. Register and memory location
  3841. descriptions describe the *concrete location* of a source variable (in the
  3842. sense that a debugger might modify its value), whereas *implicit locations*
  3843. describe merely the actual *value* of a source variable which might not exist
  3844. in registers or in memory (see ``DW_OP_stack_value``).
  3845. A ``llvm.dbg.addr`` or ``llvm.dbg.declare`` intrinsic describes an indirect
  3846. value (the address) of a source variable. The first operand of the intrinsic
  3847. must be an address of some kind. A DIExpression attached to the intrinsic
  3848. refines this address to produce a concrete location for the source variable.
  3849. A ``llvm.dbg.value`` intrinsic describes the direct value of a source variable.
  3850. The first operand of the intrinsic may be a direct or indirect value. A
  3851. DIExpresion attached to the intrinsic refines the first operand to produce a
  3852. direct value. For example, if the first operand is an indirect value, it may be
  3853. necessary to insert ``DW_OP_deref`` into the DIExpresion in order to produce a
  3854. valid debug intrinsic.
  3855. .. note::
  3856. A DIExpression is interpreted in the same way regardless of which kind of
  3857. debug intrinsic it's attached to.
  3858. .. code-block:: text
  3859. !0 = !DIExpression(DW_OP_deref)
  3860. !1 = !DIExpression(DW_OP_plus_uconst, 3)
  3861. !1 = !DIExpression(DW_OP_constu, 3, DW_OP_plus)
  3862. !2 = !DIExpression(DW_OP_bit_piece, 3, 7)
  3863. !3 = !DIExpression(DW_OP_deref, DW_OP_constu, 3, DW_OP_plus, DW_OP_LLVM_fragment, 3, 7)
  3864. !4 = !DIExpression(DW_OP_constu, 2, DW_OP_swap, DW_OP_xderef)
  3865. !5 = !DIExpression(DW_OP_constu, 42, DW_OP_stack_value)
  3866. DIFlags
  3867. """""""""""""""
  3868. These flags encode various properties of DINodes.
  3869. The `ArgumentNotModified` flag marks a function argument whose value
  3870. is not modified throughout of a function. This flag is used to decide
  3871. whether a DW_OP_LLVM_entry_value can be used in a location description
  3872. after the function prologue. The language frontend is expected to compute
  3873. this property for each DILocalVariable. The flag should be used
  3874. only in optimized code.
  3875. The `ExportSymbols` flag marks a class, struct or union whose members
  3876. may be referenced as if they were defined in the containing class or
  3877. union. This flag is used to decide whether the DW_AT_export_symbols can
  3878. be used for the structure type.
  3879. DIObjCProperty
  3880. """"""""""""""
  3881. ``DIObjCProperty`` nodes represent Objective-C property nodes.
  3882. .. code-block:: text
  3883. !3 = !DIObjCProperty(name: "foo", file: !1, line: 7, setter: "setFoo",
  3884. getter: "getFoo", attributes: 7, type: !2)
  3885. DIImportedEntity
  3886. """"""""""""""""
  3887. ``DIImportedEntity`` nodes represent entities (such as modules) imported into a
  3888. compile unit.
  3889. .. code-block:: text
  3890. !2 = !DIImportedEntity(tag: DW_TAG_imported_module, name: "foo", scope: !0,
  3891. entity: !1, line: 7)
  3892. DIMacro
  3893. """""""
  3894. ``DIMacro`` nodes represent definition or undefinition of a macro identifiers.
  3895. The ``name:`` field is the macro identifier, followed by macro parameters when
  3896. defining a function-like macro, and the ``value`` field is the token-string
  3897. used to expand the macro identifier.
  3898. .. code-block:: text
  3899. !2 = !DIMacro(macinfo: DW_MACINFO_define, line: 7, name: "foo(x)",
  3900. value: "((x) + 1)")
  3901. !3 = !DIMacro(macinfo: DW_MACINFO_undef, line: 30, name: "foo")
  3902. DIMacroFile
  3903. """""""""""
  3904. ``DIMacroFile`` nodes represent inclusion of source files.
  3905. The ``nodes:`` field is a list of ``DIMacro`` and ``DIMacroFile`` nodes that
  3906. appear in the included source file.
  3907. .. code-block:: text
  3908. !2 = !DIMacroFile(macinfo: DW_MACINFO_start_file, line: 7, file: !2,
  3909. nodes: !3)
  3910. '``tbaa``' Metadata
  3911. ^^^^^^^^^^^^^^^^^^^
  3912. In LLVM IR, memory does not have types, so LLVM's own type system is not
  3913. suitable for doing type based alias analysis (TBAA). Instead, metadata is
  3914. added to the IR to describe a type system of a higher level language. This
  3915. can be used to implement C/C++ strict type aliasing rules, but it can also
  3916. be used to implement custom alias analysis behavior for other languages.
  3917. This description of LLVM's TBAA system is broken into two parts:
  3918. :ref:`Semantics<tbaa_node_semantics>` talks about high level issues, and
  3919. :ref:`Representation<tbaa_node_representation>` talks about the metadata
  3920. encoding of various entities.
  3921. It is always possible to trace any TBAA node to a "root" TBAA node (details
  3922. in the :ref:`Representation<tbaa_node_representation>` section). TBAA
  3923. nodes with different roots have an unknown aliasing relationship, and LLVM
  3924. conservatively infers ``MayAlias`` between them. The rules mentioned in
  3925. this section only pertain to TBAA nodes living under the same root.
  3926. .. _tbaa_node_semantics:
  3927. Semantics
  3928. """""""""
  3929. The TBAA metadata system, referred to as "struct path TBAA" (not to be
  3930. confused with ``tbaa.struct``), consists of the following high level
  3931. concepts: *Type Descriptors*, further subdivided into scalar type
  3932. descriptors and struct type descriptors; and *Access Tags*.
  3933. **Type descriptors** describe the type system of the higher level language
  3934. being compiled. **Scalar type descriptors** describe types that do not
  3935. contain other types. Each scalar type has a parent type, which must also
  3936. be a scalar type or the TBAA root. Via this parent relation, scalar types
  3937. within a TBAA root form a tree. **Struct type descriptors** denote types
  3938. that contain a sequence of other type descriptors, at known offsets. These
  3939. contained type descriptors can either be struct type descriptors themselves
  3940. or scalar type descriptors.
  3941. **Access tags** are metadata nodes attached to load and store instructions.
  3942. Access tags use type descriptors to describe the *location* being accessed
  3943. in terms of the type system of the higher level language. Access tags are
  3944. tuples consisting of a base type, an access type and an offset. The base
  3945. type is a scalar type descriptor or a struct type descriptor, the access
  3946. type is a scalar type descriptor, and the offset is a constant integer.
  3947. The access tag ``(BaseTy, AccessTy, Offset)`` can describe one of two
  3948. things:
  3949. * If ``BaseTy`` is a struct type, the tag describes a memory access (load
  3950. or store) of a value of type ``AccessTy`` contained in the struct type
  3951. ``BaseTy`` at offset ``Offset``.
  3952. * If ``BaseTy`` is a scalar type, ``Offset`` must be 0 and ``BaseTy`` and
  3953. ``AccessTy`` must be the same; and the access tag describes a scalar
  3954. access with scalar type ``AccessTy``.
  3955. We first define an ``ImmediateParent`` relation on ``(BaseTy, Offset)``
  3956. tuples this way:
  3957. * If ``BaseTy`` is a scalar type then ``ImmediateParent(BaseTy, 0)`` is
  3958. ``(ParentTy, 0)`` where ``ParentTy`` is the parent of the scalar type as
  3959. described in the TBAA metadata. ``ImmediateParent(BaseTy, Offset)`` is
  3960. undefined if ``Offset`` is non-zero.
  3961. * If ``BaseTy`` is a struct type then ``ImmediateParent(BaseTy, Offset)``
  3962. is ``(NewTy, NewOffset)`` where ``NewTy`` is the type contained in
  3963. ``BaseTy`` at offset ``Offset`` and ``NewOffset`` is ``Offset`` adjusted
  3964. to be relative within that inner type.
  3965. A memory access with an access tag ``(BaseTy1, AccessTy1, Offset1)``
  3966. aliases a memory access with an access tag ``(BaseTy2, AccessTy2,
  3967. Offset2)`` if either ``(BaseTy1, Offset1)`` is reachable from ``(Base2,
  3968. Offset2)`` via the ``Parent`` relation or vice versa.
  3969. As a concrete example, the type descriptor graph for the following program
  3970. .. code-block:: c
  3971. struct Inner {
  3972. int i; // offset 0
  3973. float f; // offset 4
  3974. };
  3975. struct Outer {
  3976. float f; // offset 0
  3977. double d; // offset 4
  3978. struct Inner inner_a; // offset 12
  3979. };
  3980. void f(struct Outer* outer, struct Inner* inner, float* f, int* i, char* c) {
  3981. outer->f = 0; // tag0: (OuterStructTy, FloatScalarTy, 0)
  3982. outer->inner_a.i = 0; // tag1: (OuterStructTy, IntScalarTy, 12)
  3983. outer->inner_a.f = 0.0; // tag2: (OuterStructTy, FloatScalarTy, 16)
  3984. *f = 0.0; // tag3: (FloatScalarTy, FloatScalarTy, 0)
  3985. }
  3986. is (note that in C and C++, ``char`` can be used to access any arbitrary
  3987. type):
  3988. .. code-block:: text
  3989. Root = "TBAA Root"
  3990. CharScalarTy = ("char", Root, 0)
  3991. FloatScalarTy = ("float", CharScalarTy, 0)
  3992. DoubleScalarTy = ("double", CharScalarTy, 0)
  3993. IntScalarTy = ("int", CharScalarTy, 0)
  3994. InnerStructTy = {"Inner" (IntScalarTy, 0), (FloatScalarTy, 4)}
  3995. OuterStructTy = {"Outer", (FloatScalarTy, 0), (DoubleScalarTy, 4),
  3996. (InnerStructTy, 12)}
  3997. with (e.g.) ``ImmediateParent(OuterStructTy, 12)`` = ``(InnerStructTy,
  3998. 0)``, ``ImmediateParent(InnerStructTy, 0)`` = ``(IntScalarTy, 0)``, and
  3999. ``ImmediateParent(IntScalarTy, 0)`` = ``(CharScalarTy, 0)``.
  4000. .. _tbaa_node_representation:
  4001. Representation
  4002. """"""""""""""
  4003. The root node of a TBAA type hierarchy is an ``MDNode`` with 0 operands or
  4004. with exactly one ``MDString`` operand.
  4005. Scalar type descriptors are represented as an ``MDNode`` s with two
  4006. operands. The first operand is an ``MDString`` denoting the name of the
  4007. struct type. LLVM does not assign meaning to the value of this operand, it
  4008. only cares about it being an ``MDString``. The second operand is an
  4009. ``MDNode`` which points to the parent for said scalar type descriptor,
  4010. which is either another scalar type descriptor or the TBAA root. Scalar
  4011. type descriptors can have an optional third argument, but that must be the
  4012. constant integer zero.
  4013. Struct type descriptors are represented as ``MDNode`` s with an odd number
  4014. of operands greater than 1. The first operand is an ``MDString`` denoting
  4015. the name of the struct type. Like in scalar type descriptors the actual
  4016. value of this name operand is irrelevant to LLVM. After the name operand,
  4017. the struct type descriptors have a sequence of alternating ``MDNode`` and
  4018. ``ConstantInt`` operands. With N starting from 1, the 2N - 1 th operand,
  4019. an ``MDNode``, denotes a contained field, and the 2N th operand, a
  4020. ``ConstantInt``, is the offset of the said contained field. The offsets
  4021. must be in non-decreasing order.
  4022. Access tags are represented as ``MDNode`` s with either 3 or 4 operands.
  4023. The first operand is an ``MDNode`` pointing to the node representing the
  4024. base type. The second operand is an ``MDNode`` pointing to the node
  4025. representing the access type. The third operand is a ``ConstantInt`` that
  4026. states the offset of the access. If a fourth field is present, it must be
  4027. a ``ConstantInt`` valued at 0 or 1. If it is 1 then the access tag states
  4028. that the location being accessed is "constant" (meaning
  4029. ``pointsToConstantMemory`` should return true; see `other useful
  4030. AliasAnalysis methods <AliasAnalysis.html#OtherItfs>`_). The TBAA root of
  4031. the access type and the base type of an access tag must be the same, and
  4032. that is the TBAA root of the access tag.
  4033. '``tbaa.struct``' Metadata
  4034. ^^^^^^^^^^^^^^^^^^^^^^^^^^
  4035. The :ref:`llvm.memcpy <int_memcpy>` is often used to implement
  4036. aggregate assignment operations in C and similar languages, however it
  4037. is defined to copy a contiguous region of memory, which is more than
  4038. strictly necessary for aggregate types which contain holes due to
  4039. padding. Also, it doesn't contain any TBAA information about the fields
  4040. of the aggregate.
  4041. ``!tbaa.struct`` metadata can describe which memory subregions in a
  4042. memcpy are padding and what the TBAA tags of the struct are.
  4043. The current metadata format is very simple. ``!tbaa.struct`` metadata
  4044. nodes are a list of operands which are in conceptual groups of three.
  4045. For each group of three, the first operand gives the byte offset of a
  4046. field in bytes, the second gives its size in bytes, and the third gives
  4047. its tbaa tag. e.g.:
  4048. .. code-block:: llvm
  4049. !4 = !{ i64 0, i64 4, !1, i64 8, i64 4, !2 }
  4050. This describes a struct with two fields. The first is at offset 0 bytes
  4051. with size 4 bytes, and has tbaa tag !1. The second is at offset 8 bytes
  4052. and has size 4 bytes and has tbaa tag !2.
  4053. Note that the fields need not be contiguous. In this example, there is a
  4054. 4 byte gap between the two fields. This gap represents padding which
  4055. does not carry useful data and need not be preserved.
  4056. '``noalias``' and '``alias.scope``' Metadata
  4057. ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  4058. ``noalias`` and ``alias.scope`` metadata provide the ability to specify generic
  4059. noalias memory-access sets. This means that some collection of memory access
  4060. instructions (loads, stores, memory-accessing calls, etc.) that carry
  4061. ``noalias`` metadata can specifically be specified not to alias with some other
  4062. collection of memory access instructions that carry ``alias.scope`` metadata.
  4063. Each type of metadata specifies a list of scopes where each scope has an id and
  4064. a domain.
  4065. When evaluating an aliasing query, if for some domain, the set
  4066. of scopes with that domain in one instruction's ``alias.scope`` list is a
  4067. subset of (or equal to) the set of scopes for that domain in another
  4068. instruction's ``noalias`` list, then the two memory accesses are assumed not to
  4069. alias.
  4070. Because scopes in one domain don't affect scopes in other domains, separate
  4071. domains can be used to compose multiple independent noalias sets. This is
  4072. used for example during inlining. As the noalias function parameters are
  4073. turned into noalias scope metadata, a new domain is used every time the
  4074. function is inlined.
  4075. The metadata identifying each domain is itself a list containing one or two
  4076. entries. The first entry is the name of the domain. Note that if the name is a
  4077. string then it can be combined across functions and translation units. A
  4078. self-reference can be used to create globally unique domain names. A
  4079. descriptive string may optionally be provided as a second list entry.
  4080. The metadata identifying each scope is also itself a list containing two or
  4081. three entries. The first entry is the name of the scope. Note that if the name
  4082. is a string then it can be combined across functions and translation units. A
  4083. self-reference can be used to create globally unique scope names. A metadata
  4084. reference to the scope's domain is the second entry. A descriptive string may
  4085. optionally be provided as a third list entry.
  4086. For example,
  4087. .. code-block:: llvm
  4088. ; Two scope domains:
  4089. !0 = !{!0}
  4090. !1 = !{!1}
  4091. ; Some scopes in these domains:
  4092. !2 = !{!2, !0}
  4093. !3 = !{!3, !0}
  4094. !4 = !{!4, !1}
  4095. ; Some scope lists:
  4096. !5 = !{!4} ; A list containing only scope !4
  4097. !6 = !{!4, !3, !2}
  4098. !7 = !{!3}
  4099. ; These two instructions don't alias:
  4100. %0 = load float, float* %c, align 4, !alias.scope !5
  4101. store float %0, float* %arrayidx.i, align 4, !noalias !5
  4102. ; These two instructions also don't alias (for domain !1, the set of scopes
  4103. ; in the !alias.scope equals that in the !noalias list):
  4104. %2 = load float, float* %c, align 4, !alias.scope !5
  4105. store float %2, float* %arrayidx.i2, align 4, !noalias !6
  4106. ; These two instructions may alias (for domain !0, the set of scopes in
  4107. ; the !noalias list is not a superset of, or equal to, the scopes in the
  4108. ; !alias.scope list):
  4109. %2 = load float, float* %c, align 4, !alias.scope !6
  4110. store float %0, float* %arrayidx.i, align 4, !noalias !7
  4111. '``fpmath``' Metadata
  4112. ^^^^^^^^^^^^^^^^^^^^^
  4113. ``fpmath`` metadata may be attached to any instruction of floating-point
  4114. type. It can be used to express the maximum acceptable error in the
  4115. result of that instruction, in ULPs, thus potentially allowing the
  4116. compiler to use a more efficient but less accurate method of computing
  4117. it. ULP is defined as follows:
  4118. If ``x`` is a real number that lies between two finite consecutive
  4119. floating-point numbers ``a`` and ``b``, without being equal to one
  4120. of them, then ``ulp(x) = |b - a|``, otherwise ``ulp(x)`` is the
  4121. distance between the two non-equal finite floating-point numbers
  4122. nearest ``x``. Moreover, ``ulp(NaN)`` is ``NaN``.
  4123. The metadata node shall consist of a single positive float type number
  4124. representing the maximum relative error, for example:
  4125. .. code-block:: llvm
  4126. !0 = !{ float 2.5 } ; maximum acceptable inaccuracy is 2.5 ULPs
  4127. .. _range-metadata:
  4128. '``range``' Metadata
  4129. ^^^^^^^^^^^^^^^^^^^^
  4130. ``range`` metadata may be attached only to ``load``, ``call`` and ``invoke`` of
  4131. integer types. It expresses the possible ranges the loaded value or the value
  4132. returned by the called function at this call site is in. If the loaded or
  4133. returned value is not in the specified range, the behavior is undefined. The
  4134. ranges are represented with a flattened list of integers. The loaded value or
  4135. the value returned is known to be in the union of the ranges defined by each
  4136. consecutive pair. Each pair has the following properties:
  4137. - The type must match the type loaded by the instruction.
  4138. - The pair ``a,b`` represents the range ``[a,b)``.
  4139. - Both ``a`` and ``b`` are constants.
  4140. - The range is allowed to wrap.
  4141. - The range should not represent the full or empty set. That is,
  4142. ``a!=b``.
  4143. In addition, the pairs must be in signed order of the lower bound and
  4144. they must be non-contiguous.
  4145. Examples:
  4146. .. code-block:: llvm
  4147. %a = load i8, i8* %x, align 1, !range !0 ; Can only be 0 or 1
  4148. %b = load i8, i8* %y, align 1, !range !1 ; Can only be 255 (-1), 0 or 1
  4149. %c = call i8 @foo(), !range !2 ; Can only be 0, 1, 3, 4 or 5
  4150. %d = invoke i8 @bar() to label %cont
  4151. unwind label %lpad, !range !3 ; Can only be -2, -1, 3, 4 or 5
  4152. ...
  4153. !0 = !{ i8 0, i8 2 }
  4154. !1 = !{ i8 255, i8 2 }
  4155. !2 = !{ i8 0, i8 2, i8 3, i8 6 }
  4156. !3 = !{ i8 -2, i8 0, i8 3, i8 6 }
  4157. '``absolute_symbol``' Metadata
  4158. ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  4159. ``absolute_symbol`` metadata may be attached to a global variable
  4160. declaration. It marks the declaration as a reference to an absolute symbol,
  4161. which causes the backend to use absolute relocations for the symbol even
  4162. in position independent code, and expresses the possible ranges that the
  4163. global variable's *address* (not its value) is in, in the same format as
  4164. ``range`` metadata, with the extension that the pair ``all-ones,all-ones``
  4165. may be used to represent the full set.
  4166. Example (assuming 64-bit pointers):
  4167. .. code-block:: llvm
  4168. @a = external global i8, !absolute_symbol !0 ; Absolute symbol in range [0,256)
  4169. @b = external global i8, !absolute_symbol !1 ; Absolute symbol in range [0,2^64)
  4170. ...
  4171. !0 = !{ i64 0, i64 256 }
  4172. !1 = !{ i64 -1, i64 -1 }
  4173. '``callees``' Metadata
  4174. ^^^^^^^^^^^^^^^^^^^^^^
  4175. ``callees`` metadata may be attached to indirect call sites. If ``callees``
  4176. metadata is attached to a call site, and any callee is not among the set of
  4177. functions provided by the metadata, the behavior is undefined. The intent of
  4178. this metadata is to facilitate optimizations such as indirect-call promotion.
  4179. For example, in the code below, the call instruction may only target the
  4180. ``add`` or ``sub`` functions:
  4181. .. code-block:: llvm
  4182. %result = call i64 %binop(i64 %x, i64 %y), !callees !0
  4183. ...
  4184. !0 = !{i64 (i64, i64)* @add, i64 (i64, i64)* @sub}
  4185. '``callback``' Metadata
  4186. ^^^^^^^^^^^^^^^^^^^^^^^
  4187. ``callback`` metadata may be attached to a function declaration, or definition.
  4188. (Call sites are excluded only due to the lack of a use case.) For ease of
  4189. exposition, we'll refer to the function annotated w/ metadata as a broker
  4190. function. The metadata describes how the arguments of a call to the broker are
  4191. in turn passed to the callback function specified by the metadata. Thus, the
  4192. ``callback`` metadata provides a partial description of a call site inside the
  4193. broker function with regards to the arguments of a call to the broker. The only
  4194. semantic restriction on the broker function itself is that it is not allowed to
  4195. inspect or modify arguments referenced in the ``callback`` metadata as
  4196. pass-through to the callback function.
  4197. The broker is not required to actually invoke the callback function at runtime.
  4198. However, the assumptions about not inspecting or modifying arguments that would
  4199. be passed to the specified callback function still hold, even if the callback
  4200. function is not dynamically invoked. The broker is allowed to invoke the
  4201. callback function more than once per invocation of the broker. The broker is
  4202. also allowed to invoke (directly or indirectly) the function passed as a
  4203. callback through another use. Finally, the broker is also allowed to relay the
  4204. callback callee invocation to a different thread.
  4205. The metadata is structured as follows: At the outer level, ``callback``
  4206. metadata is a list of ``callback`` encodings. Each encoding starts with a
  4207. constant ``i64`` which describes the argument position of the callback function
  4208. in the call to the broker. The following elements, except the last, describe
  4209. what arguments are passed to the callback function. Each element is again an
  4210. ``i64`` constant identifying the argument of the broker that is passed through,
  4211. or ``i64 -1`` to indicate an unknown or inspected argument. The order in which
  4212. they are listed has to be the same in which they are passed to the callback
  4213. callee. The last element of the encoding is a boolean which specifies how
  4214. variadic arguments of the broker are handled. If it is true, all variadic
  4215. arguments of the broker are passed through to the callback function *after* the
  4216. arguments encoded explicitly before.
  4217. In the code below, the ``pthread_create`` function is marked as a broker
  4218. through the ``!callback !1`` metadata. In the example, there is only one
  4219. callback encoding, namely ``!2``, associated with the broker. This encoding
  4220. identifies the callback function as the second argument of the broker (``i64
  4221. 2``) and the sole argument of the callback function as the third one of the
  4222. broker function (``i64 3``).
  4223. .. FIXME why does the llvm-sphinx-docs builder give a highlighting
  4224. error if the below is set to highlight as 'llvm', despite that we
  4225. have misc.highlighting_failure set?
  4226. .. code-block:: text
  4227. declare !callback !1 dso_local i32 @pthread_create(i64*, %union.pthread_attr_t*, i8* (i8*)*, i8*)
  4228. ...
  4229. !2 = !{i64 2, i64 3, i1 false}
  4230. !1 = !{!2}
  4231. Another example is shown below. The callback callee is the second argument of
  4232. the ``__kmpc_fork_call`` function (``i64 2``). The callee is given two unknown
  4233. values (each identified by a ``i64 -1``) and afterwards all
  4234. variadic arguments that are passed to the ``__kmpc_fork_call`` call (due to the
  4235. final ``i1 true``).
  4236. .. FIXME why does the llvm-sphinx-docs builder give a highlighting
  4237. error if the below is set to highlight as 'llvm', despite that we
  4238. have misc.highlighting_failure set?
  4239. .. code-block:: text
  4240. declare !callback !0 dso_local void @__kmpc_fork_call(%struct.ident_t*, i32, void (i32*, i32*, ...)*, ...)
  4241. ...
  4242. !1 = !{i64 2, i64 -1, i64 -1, i1 true}
  4243. !0 = !{!1}
  4244. '``unpredictable``' Metadata
  4245. ^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  4246. ``unpredictable`` metadata may be attached to any branch or switch
  4247. instruction. It can be used to express the unpredictability of control
  4248. flow. Similar to the llvm.expect intrinsic, it may be used to alter
  4249. optimizations related to compare and branch instructions. The metadata
  4250. is treated as a boolean value; if it exists, it signals that the branch
  4251. or switch that it is attached to is completely unpredictable.
  4252. .. _md_dereferenceable:
  4253. '``dereferenceable``' Metadata
  4254. ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  4255. The existence of the ``!dereferenceable`` metadata on the instruction
  4256. tells the optimizer that the value loaded is known to be dereferenceable.
  4257. The number of bytes known to be dereferenceable is specified by the integer
  4258. value in the metadata node. This is analogous to the ''dereferenceable''
  4259. attribute on parameters and return values.
  4260. .. _md_dereferenceable_or_null:
  4261. '``dereferenceable_or_null``' Metadata
  4262. ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  4263. The existence of the ``!dereferenceable_or_null`` metadata on the
  4264. instruction tells the optimizer that the value loaded is known to be either
  4265. dereferenceable or null.
  4266. The number of bytes known to be dereferenceable is specified by the integer
  4267. value in the metadata node. This is analogous to the ''dereferenceable_or_null''
  4268. attribute on parameters and return values.
  4269. .. _llvm.loop:
  4270. '``llvm.loop``'
  4271. ^^^^^^^^^^^^^^^
  4272. It is sometimes useful to attach information to loop constructs. Currently,
  4273. loop metadata is implemented as metadata attached to the branch instruction
  4274. in the loop latch block. This type of metadata refer to a metadata node that is
  4275. guaranteed to be separate for each loop. The loop identifier metadata is
  4276. specified with the name ``llvm.loop``.
  4277. The loop identifier metadata is implemented using a metadata that refers to
  4278. itself to avoid merging it with any other identifier metadata, e.g.,
  4279. during module linkage or function inlining. That is, each loop should refer
  4280. to their own identification metadata even if they reside in separate functions.
  4281. The following example contains loop identifier metadata for two separate loop
  4282. constructs:
  4283. .. code-block:: llvm
  4284. !0 = !{!0}
  4285. !1 = !{!1}
  4286. The loop identifier metadata can be used to specify additional
  4287. per-loop metadata. Any operands after the first operand can be treated
  4288. as user-defined metadata. For example the ``llvm.loop.unroll.count``
  4289. suggests an unroll factor to the loop unroller:
  4290. .. code-block:: llvm
  4291. br i1 %exitcond, label %._crit_edge, label %.lr.ph, !llvm.loop !0
  4292. ...
  4293. !0 = !{!0, !1}
  4294. !1 = !{!"llvm.loop.unroll.count", i32 4}
  4295. '``llvm.loop.disable_nonforced``'
  4296. ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  4297. This metadata disables all optional loop transformations unless
  4298. explicitly instructed using other transformation metadata such as
  4299. ``llvm.loop.unroll.enable``. That is, no heuristic will try to determine
  4300. whether a transformation is profitable. The purpose is to avoid that the
  4301. loop is transformed to a different loop before an explicitly requested
  4302. (forced) transformation is applied. For instance, loop fusion can make
  4303. other transformations impossible. Mandatory loop canonicalizations such
  4304. as loop rotation are still applied.
  4305. It is recommended to use this metadata in addition to any llvm.loop.*
  4306. transformation directive. Also, any loop should have at most one
  4307. directive applied to it (and a sequence of transformations built using
  4308. followup-attributes). Otherwise, which transformation will be applied
  4309. depends on implementation details such as the pass pipeline order.
  4310. See :ref:`transformation-metadata` for details.
  4311. '``llvm.loop.vectorize``' and '``llvm.loop.interleave``'
  4312. ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  4313. Metadata prefixed with ``llvm.loop.vectorize`` or ``llvm.loop.interleave`` are
  4314. used to control per-loop vectorization and interleaving parameters such as
  4315. vectorization width and interleave count. These metadata should be used in
  4316. conjunction with ``llvm.loop`` loop identification metadata. The
  4317. ``llvm.loop.vectorize`` and ``llvm.loop.interleave`` metadata are only
  4318. optimization hints and the optimizer will only interleave and vectorize loops if
  4319. it believes it is safe to do so. The ``llvm.loop.parallel_accesses`` metadata
  4320. which contains information about loop-carried memory dependencies can be helpful
  4321. in determining the safety of these transformations.
  4322. '``llvm.loop.interleave.count``' Metadata
  4323. ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  4324. This metadata suggests an interleave count to the loop interleaver.
  4325. The first operand is the string ``llvm.loop.interleave.count`` and the
  4326. second operand is an integer specifying the interleave count. For
  4327. example:
  4328. .. code-block:: llvm
  4329. !0 = !{!"llvm.loop.interleave.count", i32 4}
  4330. Note that setting ``llvm.loop.interleave.count`` to 1 disables interleaving
  4331. multiple iterations of the loop. If ``llvm.loop.interleave.count`` is set to 0
  4332. then the interleave count will be determined automatically.
  4333. '``llvm.loop.vectorize.enable``' Metadata
  4334. ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  4335. This metadata selectively enables or disables vectorization for the loop. The
  4336. first operand is the string ``llvm.loop.vectorize.enable`` and the second operand
  4337. is a bit. If the bit operand value is 1 vectorization is enabled. A value of
  4338. 0 disables vectorization:
  4339. .. code-block:: llvm
  4340. !0 = !{!"llvm.loop.vectorize.enable", i1 0}
  4341. !1 = !{!"llvm.loop.vectorize.enable", i1 1}
  4342. '``llvm.loop.vectorize.predicate.enable``' Metadata
  4343. ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  4344. This metadata selectively enables or disables creating predicated instructions
  4345. for the loop, which can enable folding of the scalar epilogue loop into the
  4346. main loop. The first operand is the string
  4347. ``llvm.loop.vectorize.predicate.enable`` and the second operand is a bit. If
  4348. the bit operand value is 1 vectorization is enabled. A value of 0 disables
  4349. vectorization:
  4350. .. code-block:: llvm
  4351. !0 = !{!"llvm.loop.vectorize.predicate.enable", i1 0}
  4352. !1 = !{!"llvm.loop.vectorize.predicate.enable", i1 1}
  4353. '``llvm.loop.vectorize.width``' Metadata
  4354. ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  4355. This metadata sets the target width of the vectorizer. The first
  4356. operand is the string ``llvm.loop.vectorize.width`` and the second
  4357. operand is an integer specifying the width. For example:
  4358. .. code-block:: llvm
  4359. !0 = !{!"llvm.loop.vectorize.width", i32 4}
  4360. Note that setting ``llvm.loop.vectorize.width`` to 1 disables
  4361. vectorization of the loop. If ``llvm.loop.vectorize.width`` is set to
  4362. 0 or if the loop does not have this metadata the width will be
  4363. determined automatically.
  4364. '``llvm.loop.vectorize.followup_vectorized``' Metadata
  4365. ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  4366. This metadata defines which loop attributes the vectorized loop will
  4367. have. See :ref:`transformation-metadata` for details.
  4368. '``llvm.loop.vectorize.followup_epilogue``' Metadata
  4369. ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  4370. This metadata defines which loop attributes the epilogue will have. The
  4371. epilogue is not vectorized and is executed when either the vectorized
  4372. loop is not known to preserve semantics (because e.g., it processes two
  4373. arrays that are found to alias by a runtime check) or for the last
  4374. iterations that do not fill a complete set of vector lanes. See
  4375. :ref:`Transformation Metadata <transformation-metadata>` for details.
  4376. '``llvm.loop.vectorize.followup_all``' Metadata
  4377. ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  4378. Attributes in the metadata will be added to both the vectorized and
  4379. epilogue loop.
  4380. See :ref:`Transformation Metadata <transformation-metadata>` for details.
  4381. '``llvm.loop.unroll``'
  4382. ^^^^^^^^^^^^^^^^^^^^^^
  4383. Metadata prefixed with ``llvm.loop.unroll`` are loop unrolling
  4384. optimization hints such as the unroll factor. ``llvm.loop.unroll``
  4385. metadata should be used in conjunction with ``llvm.loop`` loop
  4386. identification metadata. The ``llvm.loop.unroll`` metadata are only
  4387. optimization hints and the unrolling will only be performed if the
  4388. optimizer believes it is safe to do so.
  4389. '``llvm.loop.unroll.count``' Metadata
  4390. ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  4391. This metadata suggests an unroll factor to the loop unroller. The
  4392. first operand is the string ``llvm.loop.unroll.count`` and the second
  4393. operand is a positive integer specifying the unroll factor. For
  4394. example:
  4395. .. code-block:: llvm
  4396. !0 = !{!"llvm.loop.unroll.count", i32 4}
  4397. If the trip count of the loop is less than the unroll count the loop
  4398. will be partially unrolled.
  4399. '``llvm.loop.unroll.disable``' Metadata
  4400. ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  4401. This metadata disables loop unrolling. The metadata has a single operand
  4402. which is the string ``llvm.loop.unroll.disable``. For example:
  4403. .. code-block:: llvm
  4404. !0 = !{!"llvm.loop.unroll.disable"}
  4405. '``llvm.loop.unroll.runtime.disable``' Metadata
  4406. ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  4407. This metadata disables runtime loop unrolling. The metadata has a single
  4408. operand which is the string ``llvm.loop.unroll.runtime.disable``. For example:
  4409. .. code-block:: llvm
  4410. !0 = !{!"llvm.loop.unroll.runtime.disable"}
  4411. '``llvm.loop.unroll.enable``' Metadata
  4412. ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  4413. This metadata suggests that the loop should be fully unrolled if the trip count
  4414. is known at compile time and partially unrolled if the trip count is not known
  4415. at compile time. The metadata has a single operand which is the string
  4416. ``llvm.loop.unroll.enable``. For example:
  4417. .. code-block:: llvm
  4418. !0 = !{!"llvm.loop.unroll.enable"}
  4419. '``llvm.loop.unroll.full``' Metadata
  4420. ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  4421. This metadata suggests that the loop should be unrolled fully. The
  4422. metadata has a single operand which is the string ``llvm.loop.unroll.full``.
  4423. For example:
  4424. .. code-block:: llvm
  4425. !0 = !{!"llvm.loop.unroll.full"}
  4426. '``llvm.loop.unroll.followup``' Metadata
  4427. ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  4428. This metadata defines which loop attributes the unrolled loop will have.
  4429. See :ref:`Transformation Metadata <transformation-metadata>` for details.
  4430. '``llvm.loop.unroll.followup_remainder``' Metadata
  4431. ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  4432. This metadata defines which loop attributes the remainder loop after
  4433. partial/runtime unrolling will have. See
  4434. :ref:`Transformation Metadata <transformation-metadata>` for details.
  4435. '``llvm.loop.unroll_and_jam``'
  4436. ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  4437. This metadata is treated very similarly to the ``llvm.loop.unroll`` metadata
  4438. above, but affect the unroll and jam pass. In addition any loop with
  4439. ``llvm.loop.unroll`` metadata but no ``llvm.loop.unroll_and_jam`` metadata will
  4440. disable unroll and jam (so ``llvm.loop.unroll`` metadata will be left to the
  4441. unroller, plus ``llvm.loop.unroll.disable`` metadata will disable unroll and jam
  4442. too.)
  4443. The metadata for unroll and jam otherwise is the same as for ``unroll``.
  4444. ``llvm.loop.unroll_and_jam.enable``, ``llvm.loop.unroll_and_jam.disable`` and
  4445. ``llvm.loop.unroll_and_jam.count`` do the same as for unroll.
  4446. ``llvm.loop.unroll_and_jam.full`` is not supported. Again these are only hints
  4447. and the normal safety checks will still be performed.
  4448. '``llvm.loop.unroll_and_jam.count``' Metadata
  4449. ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  4450. This metadata suggests an unroll and jam factor to use, similarly to
  4451. ``llvm.loop.unroll.count``. The first operand is the string
  4452. ``llvm.loop.unroll_and_jam.count`` and the second operand is a positive integer
  4453. specifying the unroll factor. For example:
  4454. .. code-block:: llvm
  4455. !0 = !{!"llvm.loop.unroll_and_jam.count", i32 4}
  4456. If the trip count of the loop is less than the unroll count the loop
  4457. will be partially unroll and jammed.
  4458. '``llvm.loop.unroll_and_jam.disable``' Metadata
  4459. ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  4460. This metadata disables loop unroll and jamming. The metadata has a single
  4461. operand which is the string ``llvm.loop.unroll_and_jam.disable``. For example:
  4462. .. code-block:: llvm
  4463. !0 = !{!"llvm.loop.unroll_and_jam.disable"}
  4464. '``llvm.loop.unroll_and_jam.enable``' Metadata
  4465. ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  4466. This metadata suggests that the loop should be fully unroll and jammed if the
  4467. trip count is known at compile time and partially unrolled if the trip count is
  4468. not known at compile time. The metadata has a single operand which is the
  4469. string ``llvm.loop.unroll_and_jam.enable``. For example:
  4470. .. code-block:: llvm
  4471. !0 = !{!"llvm.loop.unroll_and_jam.enable"}
  4472. '``llvm.loop.unroll_and_jam.followup_outer``' Metadata
  4473. ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  4474. This metadata defines which loop attributes the outer unrolled loop will
  4475. have. See :ref:`Transformation Metadata <transformation-metadata>` for
  4476. details.
  4477. '``llvm.loop.unroll_and_jam.followup_inner``' Metadata
  4478. ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  4479. This metadata defines which loop attributes the inner jammed loop will
  4480. have. See :ref:`Transformation Metadata <transformation-metadata>` for
  4481. details.
  4482. '``llvm.loop.unroll_and_jam.followup_remainder_outer``' Metadata
  4483. ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  4484. This metadata defines which attributes the epilogue of the outer loop
  4485. will have. This loop is usually unrolled, meaning there is no such
  4486. loop. This attribute will be ignored in this case. See
  4487. :ref:`Transformation Metadata <transformation-metadata>` for details.
  4488. '``llvm.loop.unroll_and_jam.followup_remainder_inner``' Metadata
  4489. ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  4490. This metadata defines which attributes the inner loop of the epilogue
  4491. will have. The outer epilogue will usually be unrolled, meaning there
  4492. can be multiple inner remainder loops. See
  4493. :ref:`Transformation Metadata <transformation-metadata>` for details.
  4494. '``llvm.loop.unroll_and_jam.followup_all``' Metadata
  4495. ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  4496. Attributes specified in the metadata is added to all
  4497. ``llvm.loop.unroll_and_jam.*`` loops. See
  4498. :ref:`Transformation Metadata <transformation-metadata>` for details.
  4499. '``llvm.loop.licm_versioning.disable``' Metadata
  4500. ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  4501. This metadata indicates that the loop should not be versioned for the purpose
  4502. of enabling loop-invariant code motion (LICM). The metadata has a single operand
  4503. which is the string ``llvm.loop.licm_versioning.disable``. For example:
  4504. .. code-block:: llvm
  4505. !0 = !{!"llvm.loop.licm_versioning.disable"}
  4506. '``llvm.loop.distribute.enable``' Metadata
  4507. ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  4508. Loop distribution allows splitting a loop into multiple loops. Currently,
  4509. this is only performed if the entire loop cannot be vectorized due to unsafe
  4510. memory dependencies. The transformation will attempt to isolate the unsafe
  4511. dependencies into their own loop.
  4512. This metadata can be used to selectively enable or disable distribution of the
  4513. loop. The first operand is the string ``llvm.loop.distribute.enable`` and the
  4514. second operand is a bit. If the bit operand value is 1 distribution is
  4515. enabled. A value of 0 disables distribution:
  4516. .. code-block:: llvm
  4517. !0 = !{!"llvm.loop.distribute.enable", i1 0}
  4518. !1 = !{!"llvm.loop.distribute.enable", i1 1}
  4519. This metadata should be used in conjunction with ``llvm.loop`` loop
  4520. identification metadata.
  4521. '``llvm.loop.distribute.followup_coincident``' Metadata
  4522. ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  4523. This metadata defines which attributes extracted loops with no cyclic
  4524. dependencies will have (i.e. can be vectorized). See
  4525. :ref:`Transformation Metadata <transformation-metadata>` for details.
  4526. '``llvm.loop.distribute.followup_sequential``' Metadata
  4527. ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  4528. This metadata defines which attributes the isolated loops with unsafe
  4529. memory dependencies will have. See
  4530. :ref:`Transformation Metadata <transformation-metadata>` for details.
  4531. '``llvm.loop.distribute.followup_fallback``' Metadata
  4532. ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  4533. If loop versioning is necessary, this metadata defined the attributes
  4534. the non-distributed fallback version will have. See
  4535. :ref:`Transformation Metadata <transformation-metadata>` for details.
  4536. '``llvm.loop.distribute.followup_all``' Metadata
  4537. ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  4538. The attributes in this metadata is added to all followup loops of the
  4539. loop distribution pass. See
  4540. :ref:`Transformation Metadata <transformation-metadata>` for details.
  4541. '``llvm.licm.disable``' Metadata
  4542. ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  4543. This metadata indicates that loop-invariant code motion (LICM) should not be
  4544. performed on this loop. The metadata has a single operand which is the string
  4545. ``llvm.licm.disable``. For example:
  4546. .. code-block:: llvm
  4547. !0 = !{!"llvm.licm.disable"}
  4548. Note that although it operates per loop it isn't given the llvm.loop prefix
  4549. as it is not affected by the ``llvm.loop.disable_nonforced`` metadata.
  4550. '``llvm.access.group``' Metadata
  4551. ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  4552. ``llvm.access.group`` metadata can be attached to any instruction that
  4553. potentially accesses memory. It can point to a single distinct metadata
  4554. node, which we call access group. This node represents all memory access
  4555. instructions referring to it via ``llvm.access.group``. When an
  4556. instruction belongs to multiple access groups, it can also point to a
  4557. list of accesses groups, illustrated by the following example.
  4558. .. code-block:: llvm
  4559. %val = load i32, i32* %arrayidx, !llvm.access.group !0
  4560. ...
  4561. !0 = !{!1, !2}
  4562. !1 = distinct !{}
  4563. !2 = distinct !{}
  4564. It is illegal for the list node to be empty since it might be confused
  4565. with an access group.
  4566. The access group metadata node must be 'distinct' to avoid collapsing
  4567. multiple access groups by content. A access group metadata node must
  4568. always be empty which can be used to distinguish an access group
  4569. metadata node from a list of access groups. Being empty avoids the
  4570. situation that the content must be updated which, because metadata is
  4571. immutable by design, would required finding and updating all references
  4572. to the access group node.
  4573. The access group can be used to refer to a memory access instruction
  4574. without pointing to it directly (which is not possible in global
  4575. metadata). Currently, the only metadata making use of it is
  4576. ``llvm.loop.parallel_accesses``.
  4577. '``llvm.loop.parallel_accesses``' Metadata
  4578. ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  4579. The ``llvm.loop.parallel_accesses`` metadata refers to one or more
  4580. access group metadata nodes (see ``llvm.access.group``). It denotes that
  4581. no loop-carried memory dependence exist between it and other instructions
  4582. in the loop with this metadata.
  4583. Let ``m1`` and ``m2`` be two instructions that both have the
  4584. ``llvm.access.group`` metadata to the access group ``g1``, respectively
  4585. ``g2`` (which might be identical). If a loop contains both access groups
  4586. in its ``llvm.loop.parallel_accesses`` metadata, then the compiler can
  4587. assume that there is no dependency between ``m1`` and ``m2`` carried by
  4588. this loop. Instructions that belong to multiple access groups are
  4589. considered having this property if at least one of the access groups
  4590. matches the ``llvm.loop.parallel_accesses`` list.
  4591. If all memory-accessing instructions in a loop have
  4592. ``llvm.loop.parallel_accesses`` metadata that refers to that loop, then the
  4593. loop has no loop carried memory dependences and is considered to be a
  4594. parallel loop.
  4595. Note that if not all memory access instructions belong to an access
  4596. group referred to by ``llvm.loop.parallel_accesses``, then the loop must
  4597. not be considered trivially parallel. Additional
  4598. memory dependence analysis is required to make that determination. As a fail
  4599. safe mechanism, this causes loops that were originally parallel to be considered
  4600. sequential (if optimization passes that are unaware of the parallel semantics
  4601. insert new memory instructions into the loop body).
  4602. Example of a loop that is considered parallel due to its correct use of
  4603. both ``llvm.access.group`` and ``llvm.loop.parallel_accesses``
  4604. metadata types.
  4605. .. code-block:: llvm
  4606. for.body:
  4607. ...
  4608. %val0 = load i32, i32* %arrayidx, !llvm.access.group !1
  4609. ...
  4610. store i32 %val0, i32* %arrayidx1, !llvm.access.group !1
  4611. ...
  4612. br i1 %exitcond, label %for.end, label %for.body, !llvm.loop !0
  4613. for.end:
  4614. ...
  4615. !0 = distinct !{!0, !{!"llvm.loop.parallel_accesses", !1}}
  4616. !1 = distinct !{}
  4617. It is also possible to have nested parallel loops:
  4618. .. code-block:: llvm
  4619. outer.for.body:
  4620. ...
  4621. %val1 = load i32, i32* %arrayidx3, !llvm.access.group !4
  4622. ...
  4623. br label %inner.for.body
  4624. inner.for.body:
  4625. ...
  4626. %val0 = load i32, i32* %arrayidx1, !llvm.access.group !3
  4627. ...
  4628. store i32 %val0, i32* %arrayidx2, !llvm.access.group !3
  4629. ...
  4630. br i1 %exitcond, label %inner.for.end, label %inner.for.body, !llvm.loop !1
  4631. inner.for.end:
  4632. ...
  4633. store i32 %val1, i32* %arrayidx4, !llvm.access.group !4
  4634. ...
  4635. br i1 %exitcond, label %outer.for.end, label %outer.for.body, !llvm.loop !2
  4636. outer.for.end: ; preds = %for.body
  4637. ...
  4638. !1 = distinct !{!1, !{!"llvm.loop.parallel_accesses", !3}} ; metadata for the inner loop
  4639. !2 = distinct !{!2, !{!"llvm.loop.parallel_accesses", !3, !4}} ; metadata for the outer loop
  4640. !3 = distinct !{} ; access group for instructions in the inner loop (which are implicitly contained in outer loop as well)
  4641. !4 = distinct !{} ; access group for instructions in the outer, but not the inner loop
  4642. '``irr_loop``' Metadata
  4643. ^^^^^^^^^^^^^^^^^^^^^^^
  4644. ``irr_loop`` metadata may be attached to the terminator instruction of a basic
  4645. block that's an irreducible loop header (note that an irreducible loop has more
  4646. than once header basic blocks.) If ``irr_loop`` metadata is attached to the
  4647. terminator instruction of a basic block that is not really an irreducible loop
  4648. header, the behavior is undefined. The intent of this metadata is to improve the
  4649. accuracy of the block frequency propagation. For example, in the code below, the
  4650. block ``header0`` may have a loop header weight (relative to the other headers of
  4651. the irreducible loop) of 100:
  4652. .. code-block:: llvm
  4653. header0:
  4654. ...
  4655. br i1 %cmp, label %t1, label %t2, !irr_loop !0
  4656. ...
  4657. !0 = !{"loop_header_weight", i64 100}
  4658. Irreducible loop header weights are typically based on profile data.
  4659. .. _md_invariant.group:
  4660. '``invariant.group``' Metadata
  4661. ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  4662. The experimental ``invariant.group`` metadata may be attached to
  4663. ``load``/``store`` instructions referencing a single metadata with no entries.
  4664. The existence of the ``invariant.group`` metadata on the instruction tells
  4665. the optimizer that every ``load`` and ``store`` to the same pointer operand
  4666. can be assumed to load or store the same
  4667. value (but see the ``llvm.launder.invariant.group`` intrinsic which affects
  4668. when two pointers are considered the same). Pointers returned by bitcast or
  4669. getelementptr with only zero indices are considered the same.
  4670. Examples:
  4671. .. code-block:: llvm
  4672. @unknownPtr = external global i8
  4673. ...
  4674. %ptr = alloca i8
  4675. store i8 42, i8* %ptr, !invariant.group !0
  4676. call void @foo(i8* %ptr)
  4677. %a = load i8, i8* %ptr, !invariant.group !0 ; Can assume that value under %ptr didn't change
  4678. call void @foo(i8* %ptr)
  4679. %newPtr = call i8* @getPointer(i8* %ptr)
  4680. %c = load i8, i8* %newPtr, !invariant.group !0 ; Can't assume anything, because we only have information about %ptr
  4681. %unknownValue = load i8, i8* @unknownPtr
  4682. store i8 %unknownValue, i8* %ptr, !invariant.group !0 ; Can assume that %unknownValue == 42
  4683. call void @foo(i8* %ptr)
  4684. %newPtr2 = call i8* @llvm.launder.invariant.group(i8* %ptr)
  4685. %d = load i8, i8* %newPtr2, !invariant.group !0 ; Can't step through launder.invariant.group to get value of %ptr
  4686. ...
  4687. declare void @foo(i8*)
  4688. declare i8* @getPointer(i8*)
  4689. declare i8* @llvm.launder.invariant.group(i8*)
  4690. !0 = !{}
  4691. The invariant.group metadata must be dropped when replacing one pointer by
  4692. another based on aliasing information. This is because invariant.group is tied
  4693. to the SSA value of the pointer operand.
  4694. .. code-block:: llvm
  4695. %v = load i8, i8* %x, !invariant.group !0
  4696. ; if %x mustalias %y then we can replace the above instruction with
  4697. %v = load i8, i8* %y
  4698. Note that this is an experimental feature, which means that its semantics might
  4699. change in the future.
  4700. '``type``' Metadata
  4701. ^^^^^^^^^^^^^^^^^^^
  4702. See :doc:`TypeMetadata`.
  4703. '``associated``' Metadata
  4704. ^^^^^^^^^^^^^^^^^^^^^^^^^
  4705. The ``associated`` metadata may be attached to a global object
  4706. declaration with a single argument that references another global object.
  4707. This metadata prevents discarding of the global object in linker GC
  4708. unless the referenced object is also discarded. The linker support for
  4709. this feature is spotty. For best compatibility, globals carrying this
  4710. metadata may also:
  4711. - Be in a comdat with the referenced global.
  4712. - Be in @llvm.compiler.used.
  4713. - Have an explicit section with a name which is a valid C identifier.
  4714. It does not have any effect on non-ELF targets.
  4715. Example:
  4716. .. code-block:: text
  4717. $a = comdat any
  4718. @a = global i32 1, comdat $a
  4719. @b = internal global i32 2, comdat $a, section "abc", !associated !0
  4720. !0 = !{i32* @a}
  4721. '``prof``' Metadata
  4722. ^^^^^^^^^^^^^^^^^^^
  4723. The ``prof`` metadata is used to record profile data in the IR.
  4724. The first operand of the metadata node indicates the profile metadata
  4725. type. There are currently 3 types:
  4726. :ref:`branch_weights<prof_node_branch_weights>`,
  4727. :ref:`function_entry_count<prof_node_function_entry_count>`, and
  4728. :ref:`VP<prof_node_VP>`.
  4729. .. _prof_node_branch_weights:
  4730. branch_weights
  4731. """"""""""""""
  4732. Branch weight metadata attached to a branch, select, switch or call instruction
  4733. represents the likeliness of the associated branch being taken.
  4734. For more information, see :doc:`BranchWeightMetadata`.
  4735. .. _prof_node_function_entry_count:
  4736. function_entry_count
  4737. """"""""""""""""""""
  4738. Function entry count metadata can be attached to function definitions
  4739. to record the number of times the function is called. Used with BFI
  4740. information, it is also used to derive the basic block profile count.
  4741. For more information, see :doc:`BranchWeightMetadata`.
  4742. .. _prof_node_VP:
  4743. VP
  4744. ""
  4745. VP (value profile) metadata can be attached to instructions that have
  4746. value profile information. Currently this is indirect calls (where it
  4747. records the hottest callees) and calls to memory intrinsics such as memcpy,
  4748. memmove, and memset (where it records the hottest byte lengths).
  4749. Each VP metadata node contains "VP" string, then a uint32_t value for the value
  4750. profiling kind, a uint64_t value for the total number of times the instruction
  4751. is executed, followed by uint64_t value and execution count pairs.
  4752. The value profiling kind is 0 for indirect call targets and 1 for memory
  4753. operations. For indirect call targets, each profile value is a hash
  4754. of the callee function name, and for memory operations each value is the
  4755. byte length.
  4756. Note that the value counts do not need to add up to the total count
  4757. listed in the third operand (in practice only the top hottest values
  4758. are tracked and reported).
  4759. Indirect call example:
  4760. .. code-block:: llvm
  4761. call void %f(), !prof !1
  4762. !1 = !{!"VP", i32 0, i64 1600, i64 7651369219802541373, i64 1030, i64 -4377547752858689819, i64 410}
  4763. Note that the VP type is 0 (the second operand), which indicates this is
  4764. an indirect call value profile data. The third operand indicates that the
  4765. indirect call executed 1600 times. The 4th and 6th operands give the
  4766. hashes of the 2 hottest target functions' names (this is the same hash used
  4767. to represent function names in the profile database), and the 5th and 7th
  4768. operands give the execution count that each of the respective prior target
  4769. functions was called.
  4770. Module Flags Metadata
  4771. =====================
  4772. Information about the module as a whole is difficult to convey to LLVM's
  4773. subsystems. The LLVM IR isn't sufficient to transmit this information.
  4774. The ``llvm.module.flags`` named metadata exists in order to facilitate
  4775. this. These flags are in the form of key / value pairs --- much like a
  4776. dictionary --- making it easy for any subsystem who cares about a flag to
  4777. look it up.
  4778. The ``llvm.module.flags`` metadata contains a list of metadata triplets.
  4779. Each triplet has the following form:
  4780. - The first element is a *behavior* flag, which specifies the behavior
  4781. when two (or more) modules are merged together, and it encounters two
  4782. (or more) metadata with the same ID. The supported behaviors are
  4783. described below.
  4784. - The second element is a metadata string that is a unique ID for the
  4785. metadata. Each module may only have one flag entry for each unique ID (not
  4786. including entries with the **Require** behavior).
  4787. - The third element is the value of the flag.
  4788. When two (or more) modules are merged together, the resulting
  4789. ``llvm.module.flags`` metadata is the union of the modules' flags. That is, for
  4790. each unique metadata ID string, there will be exactly one entry in the merged
  4791. modules ``llvm.module.flags`` metadata table, and the value for that entry will
  4792. be determined by the merge behavior flag, as described below. The only exception
  4793. is that entries with the *Require* behavior are always preserved.
  4794. The following behaviors are supported:
  4795. .. list-table::
  4796. :header-rows: 1
  4797. :widths: 10 90
  4798. * - Value
  4799. - Behavior
  4800. * - 1
  4801. - **Error**
  4802. Emits an error if two values disagree, otherwise the resulting value
  4803. is that of the operands.
  4804. * - 2
  4805. - **Warning**
  4806. Emits a warning if two values disagree. The result value will be the
  4807. operand for the flag from the first module being linked.
  4808. * - 3
  4809. - **Require**
  4810. Adds a requirement that another module flag be present and have a
  4811. specified value after linking is performed. The value must be a
  4812. metadata pair, where the first element of the pair is the ID of the
  4813. module flag to be restricted, and the second element of the pair is
  4814. the value the module flag should be restricted to. This behavior can
  4815. be used to restrict the allowable results (via triggering of an
  4816. error) of linking IDs with the **Override** behavior.
  4817. * - 4
  4818. - **Override**
  4819. Uses the specified value, regardless of the behavior or value of the
  4820. other module. If both modules specify **Override**, but the values
  4821. differ, an error will be emitted.
  4822. * - 5
  4823. - **Append**
  4824. Appends the two values, which are required to be metadata nodes.
  4825. * - 6
  4826. - **AppendUnique**
  4827. Appends the two values, which are required to be metadata
  4828. nodes. However, duplicate entries in the second list are dropped
  4829. during the append operation.
  4830. * - 7
  4831. - **Max**
  4832. Takes the max of the two values, which are required to be integers.
  4833. It is an error for a particular unique flag ID to have multiple behaviors,
  4834. except in the case of **Require** (which adds restrictions on another metadata
  4835. value) or **Override**.
  4836. An example of module flags:
  4837. .. code-block:: llvm
  4838. !0 = !{ i32 1, !"foo", i32 1 }
  4839. !1 = !{ i32 4, !"bar", i32 37 }
  4840. !2 = !{ i32 2, !"qux", i32 42 }
  4841. !3 = !{ i32 3, !"qux",
  4842. !{
  4843. !"foo", i32 1
  4844. }
  4845. }
  4846. !llvm.module.flags = !{ !0, !1, !2, !3 }
  4847. - Metadata ``!0`` has the ID ``!"foo"`` and the value '1'. The behavior
  4848. if two or more ``!"foo"`` flags are seen is to emit an error if their
  4849. values are not equal.
  4850. - Metadata ``!1`` has the ID ``!"bar"`` and the value '37'. The
  4851. behavior if two or more ``!"bar"`` flags are seen is to use the value
  4852. '37'.
  4853. - Metadata ``!2`` has the ID ``!"qux"`` and the value '42'. The
  4854. behavior if two or more ``!"qux"`` flags are seen is to emit a
  4855. warning if their values are not equal.
  4856. - Metadata ``!3`` has the ID ``!"qux"`` and the value:
  4857. ::
  4858. !{ !"foo", i32 1 }
  4859. The behavior is to emit an error if the ``llvm.module.flags`` does not
  4860. contain a flag with the ID ``!"foo"`` that has the value '1' after linking is
  4861. performed.
  4862. Objective-C Garbage Collection Module Flags Metadata
  4863. ----------------------------------------------------
  4864. On the Mach-O platform, Objective-C stores metadata about garbage
  4865. collection in a special section called "image info". The metadata
  4866. consists of a version number and a bitmask specifying what types of
  4867. garbage collection are supported (if any) by the file. If two or more
  4868. modules are linked together their garbage collection metadata needs to
  4869. be merged rather than appended together.
  4870. The Objective-C garbage collection module flags metadata consists of the
  4871. following key-value pairs:
  4872. .. list-table::
  4873. :header-rows: 1
  4874. :widths: 30 70
  4875. * - Key
  4876. - Value
  4877. * - ``Objective-C Version``
  4878. - **[Required]** --- The Objective-C ABI version. Valid values are 1 and 2.
  4879. * - ``Objective-C Image Info Version``
  4880. - **[Required]** --- The version of the image info section. Currently
  4881. always 0.
  4882. * - ``Objective-C Image Info Section``
  4883. - **[Required]** --- The section to place the metadata. Valid values are
  4884. ``"__OBJC, __image_info, regular"`` for Objective-C ABI version 1, and
  4885. ``"__DATA,__objc_imageinfo, regular, no_dead_strip"`` for
  4886. Objective-C ABI version 2.
  4887. * - ``Objective-C Garbage Collection``
  4888. - **[Required]** --- Specifies whether garbage collection is supported or
  4889. not. Valid values are 0, for no garbage collection, and 2, for garbage
  4890. collection supported.
  4891. * - ``Objective-C GC Only``
  4892. - **[Optional]** --- Specifies that only garbage collection is supported.
  4893. If present, its value must be 6. This flag requires that the
  4894. ``Objective-C Garbage Collection`` flag have the value 2.
  4895. Some important flag interactions:
  4896. - If a module with ``Objective-C Garbage Collection`` set to 0 is
  4897. merged with a module with ``Objective-C Garbage Collection`` set to
  4898. 2, then the resulting module has the
  4899. ``Objective-C Garbage Collection`` flag set to 0.
  4900. - A module with ``Objective-C Garbage Collection`` set to 0 cannot be
  4901. merged with a module with ``Objective-C GC Only`` set to 6.
  4902. C type width Module Flags Metadata
  4903. ----------------------------------
  4904. The ARM backend emits a section into each generated object file describing the
  4905. options that it was compiled with (in a compiler-independent way) to prevent
  4906. linking incompatible objects, and to allow automatic library selection. Some
  4907. of these options are not visible at the IR level, namely wchar_t width and enum
  4908. width.
  4909. To pass this information to the backend, these options are encoded in module
  4910. flags metadata, using the following key-value pairs:
  4911. .. list-table::
  4912. :header-rows: 1
  4913. :widths: 30 70
  4914. * - Key
  4915. - Value
  4916. * - short_wchar
  4917. - * 0 --- sizeof(wchar_t) == 4
  4918. * 1 --- sizeof(wchar_t) == 2
  4919. * - short_enum
  4920. - * 0 --- Enums are at least as large as an ``int``.
  4921. * 1 --- Enums are stored in the smallest integer type which can
  4922. represent all of its values.
  4923. For example, the following metadata section specifies that the module was
  4924. compiled with a ``wchar_t`` width of 4 bytes, and the underlying type of an
  4925. enum is the smallest type which can represent all of its values::
  4926. !llvm.module.flags = !{!0, !1}
  4927. !0 = !{i32 1, !"short_wchar", i32 1}
  4928. !1 = !{i32 1, !"short_enum", i32 0}
  4929. LTO Post-Link Module Flags Metadata
  4930. -----------------------------------
  4931. Some optimisations are only when the entire LTO unit is present in the current
  4932. module. This is represented by the ``LTOPostLink`` module flags metadata, which
  4933. will be created with a value of ``1`` when LTO linking occurs.
  4934. Automatic Linker Flags Named Metadata
  4935. =====================================
  4936. Some targets support embedding of flags to the linker inside individual object
  4937. files. Typically this is used in conjunction with language extensions which
  4938. allow source files to contain linker command line options, and have these
  4939. automatically be transmitted to the linker via object files.
  4940. These flags are encoded in the IR using named metadata with the name
  4941. ``!llvm.linker.options``. Each operand is expected to be a metadata node
  4942. which should be a list of other metadata nodes, each of which should be a
  4943. list of metadata strings defining linker options.
  4944. For example, the following metadata section specifies two separate sets of
  4945. linker options, presumably to link against ``libz`` and the ``Cocoa``
  4946. framework::
  4947. !0 = !{ !"-lz" }
  4948. !1 = !{ !"-framework", !"Cocoa" }
  4949. !llvm.linker.options = !{ !0, !1 }
  4950. The metadata encoding as lists of lists of options, as opposed to a collapsed
  4951. list of options, is chosen so that the IR encoding can use multiple option
  4952. strings to specify e.g., a single library, while still having that specifier be
  4953. preserved as an atomic element that can be recognized by a target specific
  4954. assembly writer or object file emitter.
  4955. Each individual option is required to be either a valid option for the target's
  4956. linker, or an option that is reserved by the target specific assembly writer or
  4957. object file emitter. No other aspect of these options is defined by the IR.
  4958. Dependent Libs Named Metadata
  4959. =============================
  4960. Some targets support embedding of strings into object files to indicate
  4961. a set of libraries to add to the link. Typically this is used in conjunction
  4962. with language extensions which allow source files to explicitly declare the
  4963. libraries they depend on, and have these automatically be transmitted to the
  4964. linker via object files.
  4965. The list is encoded in the IR using named metadata with the name
  4966. ``!llvm.dependent-libraries``. Each operand is expected to be a metadata node
  4967. which should contain a single string operand.
  4968. For example, the following metadata section contains two library specfiers::
  4969. !0 = !{!"a library specifier"}
  4970. !1 = !{!"another library specifier"}
  4971. !llvm.dependent-libraries = !{ !0, !1 }
  4972. Each library specifier will be handled independently by the consuming linker.
  4973. The effect of the library specifiers are defined by the consuming linker.
  4974. .. _summary:
  4975. ThinLTO Summary
  4976. ===============
  4977. Compiling with `ThinLTO <https://clang.llvm.org/docs/ThinLTO.html>`_
  4978. causes the building of a compact summary of the module that is emitted into
  4979. the bitcode. The summary is emitted into the LLVM assembly and identified
  4980. in syntax by a caret ('``^``').
  4981. The summary is parsed into a bitcode output, along with the Module
  4982. IR, via the "``llvm-as``" tool. Tools that parse the Module IR for the purposes
  4983. of optimization (e.g. "``clang -x ir``" and "``opt``"), will ignore the
  4984. summary entries (just as they currently ignore summary entries in a bitcode
  4985. input file).
  4986. Eventually, the summary will be parsed into a ModuleSummaryIndex object under
  4987. the same conditions where summary index is currently built from bitcode.
  4988. Specifically, tools that test the Thin Link portion of a ThinLTO compile
  4989. (i.e. llvm-lto and llvm-lto2), or when parsing a combined index
  4990. for a distributed ThinLTO backend via clang's "``-fthinlto-index=<>``" flag
  4991. (this part is not yet implemented, use llvm-as to create a bitcode object
  4992. before feeding into thin link tools for now).
  4993. There are currently 3 types of summary entries in the LLVM assembly:
  4994. :ref:`module paths<module_path_summary>`,
  4995. :ref:`global values<gv_summary>`, and
  4996. :ref:`type identifiers<typeid_summary>`.
  4997. .. _module_path_summary:
  4998. Module Path Summary Entry
  4999. -------------------------
  5000. Each module path summary entry lists a module containing global values included
  5001. in the summary. For a single IR module there will be one such entry, but
  5002. in a combined summary index produced during the thin link, there will be
  5003. one module path entry per linked module with summary.
  5004. Example:
  5005. .. code-block:: text
  5006. ^0 = module: (path: "/path/to/file.o", hash: (2468601609, 1329373163, 1565878005, 638838075, 3148790418))
  5007. The ``path`` field is a string path to the bitcode file, and the ``hash``
  5008. field is the 160-bit SHA-1 hash of the IR bitcode contents, used for
  5009. incremental builds and caching.
  5010. .. _gv_summary:
  5011. Global Value Summary Entry
  5012. --------------------------
  5013. Each global value summary entry corresponds to a global value defined or
  5014. referenced by a summarized module.
  5015. Example:
  5016. .. code-block:: text
  5017. ^4 = gv: (name: "f"[, summaries: (Summary)[, (Summary)]*]?) ; guid = 14740650423002898831
  5018. For declarations, there will not be a summary list. For definitions, a
  5019. global value will contain a list of summaries, one per module containing
  5020. a definition. There can be multiple entries in a combined summary index
  5021. for symbols with weak linkage.
  5022. Each ``Summary`` format will depend on whether the global value is a
  5023. :ref:`function<function_summary>`, :ref:`variable<variable_summary>`, or
  5024. :ref:`alias<alias_summary>`.
  5025. .. _function_summary:
  5026. Function Summary
  5027. ^^^^^^^^^^^^^^^^
  5028. If the global value is a function, the ``Summary`` entry will look like:
  5029. .. code-block:: text
  5030. function: (module: ^0, flags: (linkage: external, notEligibleToImport: 0, live: 0, dsoLocal: 0), insts: 2[, FuncFlags]?[, Calls]?[, TypeIdInfo]?[, Refs]?
  5031. The ``module`` field includes the summary entry id for the module containing
  5032. this definition, and the ``flags`` field contains information such as
  5033. the linkage type, a flag indicating whether it is legal to import the
  5034. definition, whether it is globally live and whether the linker resolved it
  5035. to a local definition (the latter two are populated during the thin link).
  5036. The ``insts`` field contains the number of IR instructions in the function.
  5037. Finally, there are several optional fields: :ref:`FuncFlags<funcflags_summary>`,
  5038. :ref:`Calls<calls_summary>`, :ref:`TypeIdInfo<typeidinfo_summary>`,
  5039. :ref:`Refs<refs_summary>`.
  5040. .. _variable_summary:
  5041. Global Variable Summary
  5042. ^^^^^^^^^^^^^^^^^^^^^^^
  5043. If the global value is a variable, the ``Summary`` entry will look like:
  5044. .. code-block:: text
  5045. variable: (module: ^0, flags: (linkage: external, notEligibleToImport: 0, live: 0, dsoLocal: 0)[, Refs]?
  5046. The variable entry contains a subset of the fields in a
  5047. :ref:`function summary <function_summary>`, see the descriptions there.
  5048. .. _alias_summary:
  5049. Alias Summary
  5050. ^^^^^^^^^^^^^
  5051. If the global value is an alias, the ``Summary`` entry will look like:
  5052. .. code-block:: text
  5053. alias: (module: ^0, flags: (linkage: external, notEligibleToImport: 0, live: 0, dsoLocal: 0), aliasee: ^2)
  5054. The ``module`` and ``flags`` fields are as described for a
  5055. :ref:`function summary <function_summary>`. The ``aliasee`` field
  5056. contains a reference to the global value summary entry of the aliasee.
  5057. .. _funcflags_summary:
  5058. Function Flags
  5059. ^^^^^^^^^^^^^^
  5060. The optional ``FuncFlags`` field looks like:
  5061. .. code-block:: text
  5062. funcFlags: (readNone: 0, readOnly: 0, noRecurse: 0, returnDoesNotAlias: 0)
  5063. If unspecified, flags are assumed to hold the conservative ``false`` value of
  5064. ``0``.
  5065. .. _calls_summary:
  5066. Calls
  5067. ^^^^^
  5068. The optional ``Calls`` field looks like:
  5069. .. code-block:: text
  5070. calls: ((Callee)[, (Callee)]*)
  5071. where each ``Callee`` looks like:
  5072. .. code-block:: text
  5073. callee: ^1[, hotness: None]?[, relbf: 0]?
  5074. The ``callee`` refers to the summary entry id of the callee. At most one
  5075. of ``hotness`` (which can take the values ``Unknown``, ``Cold``, ``None``,
  5076. ``Hot``, and ``Critical``), and ``relbf`` (which holds the integer
  5077. branch frequency relative to the entry frequency, scaled down by 2^8)
  5078. may be specified. The defaults are ``Unknown`` and ``0``, respectively.
  5079. .. _refs_summary:
  5080. Refs
  5081. ^^^^
  5082. The optional ``Refs`` field looks like:
  5083. .. code-block:: text
  5084. refs: ((Ref)[, (Ref)]*)
  5085. where each ``Ref`` contains a reference to the summary id of the referenced
  5086. value (e.g. ``^1``).
  5087. .. _typeidinfo_summary:
  5088. TypeIdInfo
  5089. ^^^^^^^^^^
  5090. The optional ``TypeIdInfo`` field, used for
  5091. `Control Flow Integrity <http://clang.llvm.org/docs/ControlFlowIntegrity.html>`_,
  5092. looks like:
  5093. .. code-block:: text
  5094. typeIdInfo: [(TypeTests)]?[, (TypeTestAssumeVCalls)]?[, (TypeCheckedLoadVCalls)]?[, (TypeTestAssumeConstVCalls)]?[, (TypeCheckedLoadConstVCalls)]?
  5095. These optional fields have the following forms:
  5096. TypeTests
  5097. """""""""
  5098. .. code-block:: text
  5099. typeTests: (TypeIdRef[, TypeIdRef]*)
  5100. Where each ``TypeIdRef`` refers to a :ref:`type id<typeid_summary>`
  5101. by summary id or ``GUID``.
  5102. TypeTestAssumeVCalls
  5103. """"""""""""""""""""
  5104. .. code-block:: text
  5105. typeTestAssumeVCalls: (VFuncId[, VFuncId]*)
  5106. Where each VFuncId has the format:
  5107. .. code-block:: text
  5108. vFuncId: (TypeIdRef, offset: 16)
  5109. Where each ``TypeIdRef`` refers to a :ref:`type id<typeid_summary>`
  5110. by summary id or ``GUID`` preceded by a ``guid:`` tag.
  5111. TypeCheckedLoadVCalls
  5112. """""""""""""""""""""
  5113. .. code-block:: text
  5114. typeCheckedLoadVCalls: (VFuncId[, VFuncId]*)
  5115. Where each VFuncId has the format described for ``TypeTestAssumeVCalls``.
  5116. TypeTestAssumeConstVCalls
  5117. """""""""""""""""""""""""
  5118. .. code-block:: text
  5119. typeTestAssumeConstVCalls: (ConstVCall[, ConstVCall]*)
  5120. Where each ConstVCall has the format:
  5121. .. code-block:: text
  5122. (VFuncId, args: (Arg[, Arg]*))
  5123. and where each VFuncId has the format described for ``TypeTestAssumeVCalls``,
  5124. and each Arg is an integer argument number.
  5125. TypeCheckedLoadConstVCalls
  5126. """"""""""""""""""""""""""
  5127. .. code-block:: text
  5128. typeCheckedLoadConstVCalls: (ConstVCall[, ConstVCall]*)
  5129. Where each ConstVCall has the format described for
  5130. ``TypeTestAssumeConstVCalls``.
  5131. .. _typeid_summary:
  5132. Type ID Summary Entry
  5133. ---------------------
  5134. Each type id summary entry corresponds to a type identifier resolution
  5135. which is generated during the LTO link portion of the compile when building
  5136. with `Control Flow Integrity <http://clang.llvm.org/docs/ControlFlowIntegrity.html>`_,
  5137. so these are only present in a combined summary index.
  5138. Example:
  5139. .. code-block:: text
  5140. ^4 = typeid: (name: "_ZTS1A", summary: (typeTestRes: (kind: allOnes, sizeM1BitWidth: 7[, alignLog2: 0]?[, sizeM1: 0]?[, bitMask: 0]?[, inlineBits: 0]?)[, WpdResolutions]?)) ; guid = 7004155349499253778
  5141. The ``typeTestRes`` gives the type test resolution ``kind`` (which may
  5142. be ``unsat``, ``byteArray``, ``inline``, ``single``, or ``allOnes``), and
  5143. the ``size-1`` bit width. It is followed by optional flags, which default to 0,
  5144. and an optional WpdResolutions (whole program devirtualization resolution)
  5145. field that looks like:
  5146. .. code-block:: text
  5147. wpdResolutions: ((offset: 0, WpdRes)[, (offset: 1, WpdRes)]*
  5148. where each entry is a mapping from the given byte offset to the whole-program
  5149. devirtualization resolution WpdRes, that has one of the following formats:
  5150. .. code-block:: text
  5151. wpdRes: (kind: branchFunnel)
  5152. wpdRes: (kind: singleImpl, singleImplName: "_ZN1A1nEi")
  5153. wpdRes: (kind: indir)
  5154. Additionally, each wpdRes has an optional ``resByArg`` field, which
  5155. describes the resolutions for calls with all constant integer arguments:
  5156. .. code-block:: text
  5157. resByArg: (ResByArg[, ResByArg]*)
  5158. where ResByArg is:
  5159. .. code-block:: text
  5160. args: (Arg[, Arg]*), byArg: (kind: UniformRetVal[, info: 0][, byte: 0][, bit: 0])
  5161. Where the ``kind`` can be ``Indir``, ``UniformRetVal``, ``UniqueRetVal``
  5162. or ``VirtualConstProp``. The ``info`` field is only used if the kind
  5163. is ``UniformRetVal`` (indicates the uniform return value), or
  5164. ``UniqueRetVal`` (holds the return value associated with the unique vtable
  5165. (0 or 1)). The ``byte`` and ``bit`` fields are only used if the target does
  5166. not support the use of absolute symbols to store constants.
  5167. .. _intrinsicglobalvariables:
  5168. Intrinsic Global Variables
  5169. ==========================
  5170. LLVM has a number of "magic" global variables that contain data that
  5171. affect code generation or other IR semantics. These are documented here.
  5172. All globals of this sort should have a section specified as
  5173. "``llvm.metadata``". This section and all globals that start with
  5174. "``llvm.``" are reserved for use by LLVM.
  5175. .. _gv_llvmused:
  5176. The '``llvm.used``' Global Variable
  5177. -----------------------------------
  5178. The ``@llvm.used`` global is an array which has
  5179. :ref:`appending linkage <linkage_appending>`. This array contains a list of
  5180. pointers to named global variables, functions and aliases which may optionally
  5181. have a pointer cast formed of bitcast or getelementptr. For example, a legal
  5182. use of it is:
  5183. .. code-block:: llvm
  5184. @X = global i8 4
  5185. @Y = global i32 123
  5186. @llvm.used = appending global [2 x i8*] [
  5187. i8* @X,
  5188. i8* bitcast (i32* @Y to i8*)
  5189. ], section "llvm.metadata"
  5190. If a symbol appears in the ``@llvm.used`` list, then the compiler, assembler,
  5191. and linker are required to treat the symbol as if there is a reference to the
  5192. symbol that it cannot see (which is why they have to be named). For example, if
  5193. a variable has internal linkage and no references other than that from the
  5194. ``@llvm.used`` list, it cannot be deleted. This is commonly used to represent
  5195. references from inline asms and other things the compiler cannot "see", and
  5196. corresponds to "``attribute((used))``" in GNU C.
  5197. On some targets, the code generator must emit a directive to the
  5198. assembler or object file to prevent the assembler and linker from
  5199. molesting the symbol.
  5200. .. _gv_llvmcompilerused:
  5201. The '``llvm.compiler.used``' Global Variable
  5202. --------------------------------------------
  5203. The ``@llvm.compiler.used`` directive is the same as the ``@llvm.used``
  5204. directive, except that it only prevents the compiler from touching the
  5205. symbol. On targets that support it, this allows an intelligent linker to
  5206. optimize references to the symbol without being impeded as it would be
  5207. by ``@llvm.used``.
  5208. This is a rare construct that should only be used in rare circumstances,
  5209. and should not be exposed to source languages.
  5210. .. _gv_llvmglobalctors:
  5211. The '``llvm.global_ctors``' Global Variable
  5212. -------------------------------------------
  5213. .. code-block:: llvm
  5214. %0 = type { i32, void ()*, i8* }
  5215. @llvm.global_ctors = appending global [1 x %0] [%0 { i32 65535, void ()* @ctor, i8* @data }]
  5216. The ``@llvm.global_ctors`` array contains a list of constructor
  5217. functions, priorities, and an associated global or function.
  5218. The functions referenced by this array will be called in ascending order
  5219. of priority (i.e. lowest first) when the module is loaded. The order of
  5220. functions with the same priority is not defined.
  5221. If the third field is non-null, and points to a global variable
  5222. or function, the initializer function will only run if the associated
  5223. data from the current module is not discarded.
  5224. .. _llvmglobaldtors:
  5225. The '``llvm.global_dtors``' Global Variable
  5226. -------------------------------------------
  5227. .. code-block:: llvm
  5228. %0 = type { i32, void ()*, i8* }
  5229. @llvm.global_dtors = appending global [1 x %0] [%0 { i32 65535, void ()* @dtor, i8* @data }]
  5230. The ``@llvm.global_dtors`` array contains a list of destructor
  5231. functions, priorities, and an associated global or function.
  5232. The functions referenced by this array will be called in descending
  5233. order of priority (i.e. highest first) when the module is unloaded. The
  5234. order of functions with the same priority is not defined.
  5235. If the third field is non-null, and points to a global variable
  5236. or function, the destructor function will only run if the associated
  5237. data from the current module is not discarded.
  5238. Instruction Reference
  5239. =====================
  5240. The LLVM instruction set consists of several different classifications
  5241. of instructions: :ref:`terminator instructions <terminators>`, :ref:`binary
  5242. instructions <binaryops>`, :ref:`bitwise binary
  5243. instructions <bitwiseops>`, :ref:`memory instructions <memoryops>`, and
  5244. :ref:`other instructions <otherops>`.
  5245. .. _terminators:
  5246. Terminator Instructions
  5247. -----------------------
  5248. As mentioned :ref:`previously <functionstructure>`, every basic block in a
  5249. program ends with a "Terminator" instruction, which indicates which
  5250. block should be executed after the current block is finished. These
  5251. terminator instructions typically yield a '``void``' value: they produce
  5252. control flow, not values (the one exception being the
  5253. ':ref:`invoke <i_invoke>`' instruction).
  5254. The terminator instructions are: ':ref:`ret <i_ret>`',
  5255. ':ref:`br <i_br>`', ':ref:`switch <i_switch>`',
  5256. ':ref:`indirectbr <i_indirectbr>`', ':ref:`invoke <i_invoke>`',
  5257. ':ref:`callbr <i_callbr>`'
  5258. ':ref:`resume <i_resume>`', ':ref:`catchswitch <i_catchswitch>`',
  5259. ':ref:`catchret <i_catchret>`',
  5260. ':ref:`cleanupret <i_cleanupret>`',
  5261. and ':ref:`unreachable <i_unreachable>`'.
  5262. .. _i_ret:
  5263. '``ret``' Instruction
  5264. ^^^^^^^^^^^^^^^^^^^^^
  5265. Syntax:
  5266. """""""
  5267. ::
  5268. ret <type> <value> ; Return a value from a non-void function
  5269. ret void ; Return from void function
  5270. Overview:
  5271. """""""""
  5272. The '``ret``' instruction is used to return control flow (and optionally
  5273. a value) from a function back to the caller.
  5274. There are two forms of the '``ret``' instruction: one that returns a
  5275. value and then causes control flow, and one that just causes control
  5276. flow to occur.
  5277. Arguments:
  5278. """"""""""
  5279. The '``ret``' instruction optionally accepts a single argument, the
  5280. return value. The type of the return value must be a ':ref:`first
  5281. class <t_firstclass>`' type.
  5282. A function is not :ref:`well formed <wellformed>` if it has a non-void
  5283. return type and contains a '``ret``' instruction with no return value or
  5284. a return value with a type that does not match its type, or if it has a
  5285. void return type and contains a '``ret``' instruction with a return
  5286. value.
  5287. Semantics:
  5288. """"""""""
  5289. When the '``ret``' instruction is executed, control flow returns back to
  5290. the calling function's context. If the caller is a
  5291. ":ref:`call <i_call>`" instruction, execution continues at the
  5292. instruction after the call. If the caller was an
  5293. ":ref:`invoke <i_invoke>`" instruction, execution continues at the
  5294. beginning of the "normal" destination block. If the instruction returns
  5295. a value, that value shall set the call or invoke instruction's return
  5296. value.
  5297. Example:
  5298. """"""""
  5299. .. code-block:: llvm
  5300. ret i32 5 ; Return an integer value of 5
  5301. ret void ; Return from a void function
  5302. ret { i32, i8 } { i32 4, i8 2 } ; Return a struct of values 4 and 2
  5303. .. _i_br:
  5304. '``br``' Instruction
  5305. ^^^^^^^^^^^^^^^^^^^^
  5306. Syntax:
  5307. """""""
  5308. ::
  5309. br i1 <cond>, label <iftrue>, label <iffalse>
  5310. br label <dest> ; Unconditional branch
  5311. Overview:
  5312. """""""""
  5313. The '``br``' instruction is used to cause control flow to transfer to a
  5314. different basic block in the current function. There are two forms of
  5315. this instruction, corresponding to a conditional branch and an
  5316. unconditional branch.
  5317. Arguments:
  5318. """"""""""
  5319. The conditional branch form of the '``br``' instruction takes a single
  5320. '``i1``' value and two '``label``' values. The unconditional form of the
  5321. '``br``' instruction takes a single '``label``' value as a target.
  5322. Semantics:
  5323. """"""""""
  5324. Upon execution of a conditional '``br``' instruction, the '``i1``'
  5325. argument is evaluated. If the value is ``true``, control flows to the
  5326. '``iftrue``' ``label`` argument. If "cond" is ``false``, control flows
  5327. to the '``iffalse``' ``label`` argument.
  5328. Example:
  5329. """"""""
  5330. .. code-block:: llvm
  5331. Test:
  5332. %cond = icmp eq i32 %a, %b
  5333. br i1 %cond, label %IfEqual, label %IfUnequal
  5334. IfEqual:
  5335. ret i32 1
  5336. IfUnequal:
  5337. ret i32 0
  5338. .. _i_switch:
  5339. '``switch``' Instruction
  5340. ^^^^^^^^^^^^^^^^^^^^^^^^
  5341. Syntax:
  5342. """""""
  5343. ::
  5344. switch <intty> <value>, label <defaultdest> [ <intty> <val>, label <dest> ... ]
  5345. Overview:
  5346. """""""""
  5347. The '``switch``' instruction is used to transfer control flow to one of
  5348. several different places. It is a generalization of the '``br``'
  5349. instruction, allowing a branch to occur to one of many possible
  5350. destinations.
  5351. Arguments:
  5352. """"""""""
  5353. The '``switch``' instruction uses three parameters: an integer
  5354. comparison value '``value``', a default '``label``' destination, and an
  5355. array of pairs of comparison value constants and '``label``'s. The table
  5356. is not allowed to contain duplicate constant entries.
  5357. Semantics:
  5358. """"""""""
  5359. The ``switch`` instruction specifies a table of values and destinations.
  5360. When the '``switch``' instruction is executed, this table is searched
  5361. for the given value. If the value is found, control flow is transferred
  5362. to the corresponding destination; otherwise, control flow is transferred
  5363. to the default destination.
  5364. Implementation:
  5365. """""""""""""""
  5366. Depending on properties of the target machine and the particular
  5367. ``switch`` instruction, this instruction may be code generated in
  5368. different ways. For example, it could be generated as a series of
  5369. chained conditional branches or with a lookup table.
  5370. Example:
  5371. """"""""
  5372. .. code-block:: llvm
  5373. ; Emulate a conditional br instruction
  5374. %Val = zext i1 %value to i32
  5375. switch i32 %Val, label %truedest [ i32 0, label %falsedest ]
  5376. ; Emulate an unconditional br instruction
  5377. switch i32 0, label %dest [ ]
  5378. ; Implement a jump table:
  5379. switch i32 %val, label %otherwise [ i32 0, label %onzero
  5380. i32 1, label %onone
  5381. i32 2, label %ontwo ]
  5382. .. _i_indirectbr:
  5383. '``indirectbr``' Instruction
  5384. ^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  5385. Syntax:
  5386. """""""
  5387. ::
  5388. indirectbr <somety>* <address>, [ label <dest1>, label <dest2>, ... ]
  5389. Overview:
  5390. """""""""
  5391. The '``indirectbr``' instruction implements an indirect branch to a
  5392. label within the current function, whose address is specified by
  5393. "``address``". Address must be derived from a
  5394. :ref:`blockaddress <blockaddress>` constant.
  5395. Arguments:
  5396. """"""""""
  5397. The '``address``' argument is the address of the label to jump to. The
  5398. rest of the arguments indicate the full set of possible destinations
  5399. that the address may point to. Blocks are allowed to occur multiple
  5400. times in the destination list, though this isn't particularly useful.
  5401. This destination list is required so that dataflow analysis has an
  5402. accurate understanding of the CFG.
  5403. Semantics:
  5404. """"""""""
  5405. Control transfers to the block specified in the address argument. All
  5406. possible destination blocks must be listed in the label list, otherwise
  5407. this instruction has undefined behavior. This implies that jumps to
  5408. labels defined in other functions have undefined behavior as well.
  5409. Implementation:
  5410. """""""""""""""
  5411. This is typically implemented with a jump through a register.
  5412. Example:
  5413. """"""""
  5414. .. code-block:: llvm
  5415. indirectbr i8* %Addr, [ label %bb1, label %bb2, label %bb3 ]
  5416. .. _i_invoke:
  5417. '``invoke``' Instruction
  5418. ^^^^^^^^^^^^^^^^^^^^^^^^
  5419. Syntax:
  5420. """""""
  5421. ::
  5422. <result> = invoke [cconv] [ret attrs] [addrspace(<num>)] <ty>|<fnty> <fnptrval>(<function args>) [fn attrs]
  5423. [operand bundles] to label <normal label> unwind label <exception label>
  5424. Overview:
  5425. """""""""
  5426. The '``invoke``' instruction causes control to transfer to a specified
  5427. function, with the possibility of control flow transfer to either the
  5428. '``normal``' label or the '``exception``' label. If the callee function
  5429. returns with the "``ret``" instruction, control flow will return to the
  5430. "normal" label. If the callee (or any indirect callees) returns via the
  5431. ":ref:`resume <i_resume>`" instruction or other exception handling
  5432. mechanism, control is interrupted and continued at the dynamically
  5433. nearest "exception" label.
  5434. The '``exception``' label is a `landing
  5435. pad <ExceptionHandling.html#overview>`_ for the exception. As such,
  5436. '``exception``' label is required to have the
  5437. ":ref:`landingpad <i_landingpad>`" instruction, which contains the
  5438. information about the behavior of the program after unwinding happens,
  5439. as its first non-PHI instruction. The restrictions on the
  5440. "``landingpad``" instruction's tightly couples it to the "``invoke``"
  5441. instruction, so that the important information contained within the
  5442. "``landingpad``" instruction can't be lost through normal code motion.
  5443. Arguments:
  5444. """"""""""
  5445. This instruction requires several arguments:
  5446. #. The optional "cconv" marker indicates which :ref:`calling
  5447. convention <callingconv>` the call should use. If none is
  5448. specified, the call defaults to using C calling conventions.
  5449. #. The optional :ref:`Parameter Attributes <paramattrs>` list for return
  5450. values. Only '``zeroext``', '``signext``', and '``inreg``' attributes
  5451. are valid here.
  5452. #. The optional addrspace attribute can be used to indicate the address space
  5453. of the called function. If it is not specified, the program address space
  5454. from the :ref:`datalayout string<langref_datalayout>` will be used.
  5455. #. '``ty``': the type of the call instruction itself which is also the
  5456. type of the return value. Functions that return no value are marked
  5457. ``void``.
  5458. #. '``fnty``': shall be the signature of the function being invoked. The
  5459. argument types must match the types implied by this signature. This
  5460. type can be omitted if the function is not varargs.
  5461. #. '``fnptrval``': An LLVM value containing a pointer to a function to
  5462. be invoked. In most cases, this is a direct function invocation, but
  5463. indirect ``invoke``'s are just as possible, calling an arbitrary pointer
  5464. to function value.
  5465. #. '``function args``': argument list whose types match the function
  5466. signature argument types and parameter attributes. All arguments must
  5467. be of :ref:`first class <t_firstclass>` type. If the function signature
  5468. indicates the function accepts a variable number of arguments, the
  5469. extra arguments can be specified.
  5470. #. '``normal label``': the label reached when the called function
  5471. executes a '``ret``' instruction.
  5472. #. '``exception label``': the label reached when a callee returns via
  5473. the :ref:`resume <i_resume>` instruction or other exception handling
  5474. mechanism.
  5475. #. The optional :ref:`function attributes <fnattrs>` list.
  5476. #. The optional :ref:`operand bundles <opbundles>` list.
  5477. Semantics:
  5478. """"""""""
  5479. This instruction is designed to operate as a standard '``call``'
  5480. instruction in most regards. The primary difference is that it
  5481. establishes an association with a label, which is used by the runtime
  5482. library to unwind the stack.
  5483. This instruction is used in languages with destructors to ensure that
  5484. proper cleanup is performed in the case of either a ``longjmp`` or a
  5485. thrown exception. Additionally, this is important for implementation of
  5486. '``catch``' clauses in high-level languages that support them.
  5487. For the purposes of the SSA form, the definition of the value returned
  5488. by the '``invoke``' instruction is deemed to occur on the edge from the
  5489. current block to the "normal" label. If the callee unwinds then no
  5490. return value is available.
  5491. Example:
  5492. """"""""
  5493. .. code-block:: llvm
  5494. %retval = invoke i32 @Test(i32 15) to label %Continue
  5495. unwind label %TestCleanup ; i32:retval set
  5496. %retval = invoke coldcc i32 %Testfnptr(i32 15) to label %Continue
  5497. unwind label %TestCleanup ; i32:retval set
  5498. .. _i_callbr:
  5499. '``callbr``' Instruction
  5500. ^^^^^^^^^^^^^^^^^^^^^^^^
  5501. Syntax:
  5502. """""""
  5503. ::
  5504. <result> = callbr [cconv] [ret attrs] [addrspace(<num>)] <ty>|<fnty> <fnptrval>(<function args>) [fn attrs]
  5505. [operand bundles] to label <normal label> [other labels]
  5506. Overview:
  5507. """""""""
  5508. The '``callbr``' instruction causes control to transfer to a specified
  5509. function, with the possibility of control flow transfer to either the
  5510. '``normal``' label or one of the '``other``' labels.
  5511. This instruction should only be used to implement the "goto" feature of gcc
  5512. style inline assembly. Any other usage is an error in the IR verifier.
  5513. Arguments:
  5514. """"""""""
  5515. This instruction requires several arguments:
  5516. #. The optional "cconv" marker indicates which :ref:`calling
  5517. convention <callingconv>` the call should use. If none is
  5518. specified, the call defaults to using C calling conventions.
  5519. #. The optional :ref:`Parameter Attributes <paramattrs>` list for return
  5520. values. Only '``zeroext``', '``signext``', and '``inreg``' attributes
  5521. are valid here.
  5522. #. The optional addrspace attribute can be used to indicate the address space
  5523. of the called function. If it is not specified, the program address space
  5524. from the :ref:`datalayout string<langref_datalayout>` will be used.
  5525. #. '``ty``': the type of the call instruction itself which is also the
  5526. type of the return value. Functions that return no value are marked
  5527. ``void``.
  5528. #. '``fnty``': shall be the signature of the function being called. The
  5529. argument types must match the types implied by this signature. This
  5530. type can be omitted if the function is not varargs.
  5531. #. '``fnptrval``': An LLVM value containing a pointer to a function to
  5532. be called. In most cases, this is a direct function call, but
  5533. indirect ``callbr``'s are just as possible, calling an arbitrary pointer
  5534. to function value.
  5535. #. '``function args``': argument list whose types match the function
  5536. signature argument types and parameter attributes. All arguments must
  5537. be of :ref:`first class <t_firstclass>` type. If the function signature
  5538. indicates the function accepts a variable number of arguments, the
  5539. extra arguments can be specified.
  5540. #. '``normal label``': the label reached when the called function
  5541. executes a '``ret``' instruction.
  5542. #. '``other labels``': the labels reached when a callee transfers control
  5543. to a location other than the normal '``normal label``'. The blockaddress
  5544. constant for these should also be in the list of '``function args``'.
  5545. #. The optional :ref:`function attributes <fnattrs>` list.
  5546. #. The optional :ref:`operand bundles <opbundles>` list.
  5547. Semantics:
  5548. """"""""""
  5549. This instruction is designed to operate as a standard '``call``'
  5550. instruction in most regards. The primary difference is that it
  5551. establishes an association with additional labels to define where control
  5552. flow goes after the call.
  5553. The only use of this today is to implement the "goto" feature of gcc inline
  5554. assembly where additional labels can be provided as locations for the inline
  5555. assembly to jump to.
  5556. Example:
  5557. """"""""
  5558. .. code-block:: text
  5559. callbr void asm "", "r,x"(i32 %x, i8 *blockaddress(@foo, %fail))
  5560. to label %normal [label %fail]
  5561. .. _i_resume:
  5562. '``resume``' Instruction
  5563. ^^^^^^^^^^^^^^^^^^^^^^^^
  5564. Syntax:
  5565. """""""
  5566. ::
  5567. resume <type> <value>
  5568. Overview:
  5569. """""""""
  5570. The '``resume``' instruction is a terminator instruction that has no
  5571. successors.
  5572. Arguments:
  5573. """"""""""
  5574. The '``resume``' instruction requires one argument, which must have the
  5575. same type as the result of any '``landingpad``' instruction in the same
  5576. function.
  5577. Semantics:
  5578. """"""""""
  5579. The '``resume``' instruction resumes propagation of an existing
  5580. (in-flight) exception whose unwinding was interrupted with a
  5581. :ref:`landingpad <i_landingpad>` instruction.
  5582. Example:
  5583. """"""""
  5584. .. code-block:: llvm
  5585. resume { i8*, i32 } %exn
  5586. .. _i_catchswitch:
  5587. '``catchswitch``' Instruction
  5588. ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  5589. Syntax:
  5590. """""""
  5591. ::
  5592. <resultval> = catchswitch within <parent> [ label <handler1>, label <handler2>, ... ] unwind to caller
  5593. <resultval> = catchswitch within <parent> [ label <handler1>, label <handler2>, ... ] unwind label <default>
  5594. Overview:
  5595. """""""""
  5596. The '``catchswitch``' instruction is used by `LLVM's exception handling system
  5597. <ExceptionHandling.html#overview>`_ to describe the set of possible catch handlers
  5598. that may be executed by the :ref:`EH personality routine <personalityfn>`.
  5599. Arguments:
  5600. """"""""""
  5601. The ``parent`` argument is the token of the funclet that contains the
  5602. ``catchswitch`` instruction. If the ``catchswitch`` is not inside a funclet,
  5603. this operand may be the token ``none``.
  5604. The ``default`` argument is the label of another basic block beginning with
  5605. either a ``cleanuppad`` or ``catchswitch`` instruction. This unwind destination
  5606. must be a legal target with respect to the ``parent`` links, as described in
  5607. the `exception handling documentation\ <ExceptionHandling.html#wineh-constraints>`_.
  5608. The ``handlers`` are a nonempty list of successor blocks that each begin with a
  5609. :ref:`catchpad <i_catchpad>` instruction.
  5610. Semantics:
  5611. """"""""""
  5612. Executing this instruction transfers control to one of the successors in
  5613. ``handlers``, if appropriate, or continues to unwind via the unwind label if
  5614. present.
  5615. The ``catchswitch`` is both a terminator and a "pad" instruction, meaning that
  5616. it must be both the first non-phi instruction and last instruction in the basic
  5617. block. Therefore, it must be the only non-phi instruction in the block.
  5618. Example:
  5619. """"""""
  5620. .. code-block:: text
  5621. dispatch1:
  5622. %cs1 = catchswitch within none [label %handler0, label %handler1] unwind to caller
  5623. dispatch2:
  5624. %cs2 = catchswitch within %parenthandler [label %handler0] unwind label %cleanup
  5625. .. _i_catchret:
  5626. '``catchret``' Instruction
  5627. ^^^^^^^^^^^^^^^^^^^^^^^^^^
  5628. Syntax:
  5629. """""""
  5630. ::
  5631. catchret from <token> to label <normal>
  5632. Overview:
  5633. """""""""
  5634. The '``catchret``' instruction is a terminator instruction that has a
  5635. single successor.
  5636. Arguments:
  5637. """"""""""
  5638. The first argument to a '``catchret``' indicates which ``catchpad`` it
  5639. exits. It must be a :ref:`catchpad <i_catchpad>`.
  5640. The second argument to a '``catchret``' specifies where control will
  5641. transfer to next.
  5642. Semantics:
  5643. """"""""""
  5644. The '``catchret``' instruction ends an existing (in-flight) exception whose
  5645. unwinding was interrupted with a :ref:`catchpad <i_catchpad>` instruction. The
  5646. :ref:`personality function <personalityfn>` gets a chance to execute arbitrary
  5647. code to, for example, destroy the active exception. Control then transfers to
  5648. ``normal``.
  5649. The ``token`` argument must be a token produced by a ``catchpad`` instruction.
  5650. If the specified ``catchpad`` is not the most-recently-entered not-yet-exited
  5651. funclet pad (as described in the `EH documentation\ <ExceptionHandling.html#wineh-constraints>`_),
  5652. the ``catchret``'s behavior is undefined.
  5653. Example:
  5654. """"""""
  5655. .. code-block:: text
  5656. catchret from %catch label %continue
  5657. .. _i_cleanupret:
  5658. '``cleanupret``' Instruction
  5659. ^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  5660. Syntax:
  5661. """""""
  5662. ::
  5663. cleanupret from <value> unwind label <continue>
  5664. cleanupret from <value> unwind to caller
  5665. Overview:
  5666. """""""""
  5667. The '``cleanupret``' instruction is a terminator instruction that has
  5668. an optional successor.
  5669. Arguments:
  5670. """"""""""
  5671. The '``cleanupret``' instruction requires one argument, which indicates
  5672. which ``cleanuppad`` it exits, and must be a :ref:`cleanuppad <i_cleanuppad>`.
  5673. If the specified ``cleanuppad`` is not the most-recently-entered not-yet-exited
  5674. funclet pad (as described in the `EH documentation\ <ExceptionHandling.html#wineh-constraints>`_),
  5675. the ``cleanupret``'s behavior is undefined.
  5676. The '``cleanupret``' instruction also has an optional successor, ``continue``,
  5677. which must be the label of another basic block beginning with either a
  5678. ``cleanuppad`` or ``catchswitch`` instruction. This unwind destination must
  5679. be a legal target with respect to the ``parent`` links, as described in the
  5680. `exception handling documentation\ <ExceptionHandling.html#wineh-constraints>`_.
  5681. Semantics:
  5682. """"""""""
  5683. The '``cleanupret``' instruction indicates to the
  5684. :ref:`personality function <personalityfn>` that one
  5685. :ref:`cleanuppad <i_cleanuppad>` it transferred control to has ended.
  5686. It transfers control to ``continue`` or unwinds out of the function.
  5687. Example:
  5688. """"""""
  5689. .. code-block:: text
  5690. cleanupret from %cleanup unwind to caller
  5691. cleanupret from %cleanup unwind label %continue
  5692. .. _i_unreachable:
  5693. '``unreachable``' Instruction
  5694. ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  5695. Syntax:
  5696. """""""
  5697. ::
  5698. unreachable
  5699. Overview:
  5700. """""""""
  5701. The '``unreachable``' instruction has no defined semantics. This
  5702. instruction is used to inform the optimizer that a particular portion of
  5703. the code is not reachable. This can be used to indicate that the code
  5704. after a no-return function cannot be reached, and other facts.
  5705. Semantics:
  5706. """"""""""
  5707. The '``unreachable``' instruction has no defined semantics.
  5708. .. _unaryops:
  5709. Unary Operations
  5710. -----------------
  5711. Unary operators require a single operand, execute an operation on
  5712. it, and produce a single value. The operand might represent multiple
  5713. data, as is the case with the :ref:`vector <t_vector>` data type. The
  5714. result value has the same type as its operand.
  5715. .. _i_fneg:
  5716. '``fneg``' Instruction
  5717. ^^^^^^^^^^^^^^^^^^^^^^
  5718. Syntax:
  5719. """""""
  5720. ::
  5721. <result> = fneg [fast-math flags]* <ty> <op1> ; yields ty:result
  5722. Overview:
  5723. """""""""
  5724. The '``fneg``' instruction returns the negation of its operand.
  5725. Arguments:
  5726. """"""""""
  5727. The argument to the '``fneg``' instruction must be a
  5728. :ref:`floating-point <t_floating>` or :ref:`vector <t_vector>` of
  5729. floating-point values.
  5730. Semantics:
  5731. """"""""""
  5732. The value produced is a copy of the operand with its sign bit flipped.
  5733. This instruction can also take any number of :ref:`fast-math
  5734. flags <fastmath>`, which are optimization hints to enable otherwise
  5735. unsafe floating-point optimizations:
  5736. Example:
  5737. """"""""
  5738. .. code-block:: text
  5739. <result> = fneg float %val ; yields float:result = -%var
  5740. .. _binaryops:
  5741. Binary Operations
  5742. -----------------
  5743. Binary operators are used to do most of the computation in a program.
  5744. They require two operands of the same type, execute an operation on
  5745. them, and produce a single value. The operands might represent multiple
  5746. data, as is the case with the :ref:`vector <t_vector>` data type. The
  5747. result value has the same type as its operands.
  5748. There are several different binary operators:
  5749. .. _i_add:
  5750. '``add``' Instruction
  5751. ^^^^^^^^^^^^^^^^^^^^^
  5752. Syntax:
  5753. """""""
  5754. ::
  5755. <result> = add <ty> <op1>, <op2> ; yields ty:result
  5756. <result> = add nuw <ty> <op1>, <op2> ; yields ty:result
  5757. <result> = add nsw <ty> <op1>, <op2> ; yields ty:result
  5758. <result> = add nuw nsw <ty> <op1>, <op2> ; yields ty:result
  5759. Overview:
  5760. """""""""
  5761. The '``add``' instruction returns the sum of its two operands.
  5762. Arguments:
  5763. """"""""""
  5764. The two arguments to the '``add``' instruction must be
  5765. :ref:`integer <t_integer>` or :ref:`vector <t_vector>` of integer values. Both
  5766. arguments must have identical types.
  5767. Semantics:
  5768. """"""""""
  5769. The value produced is the integer sum of the two operands.
  5770. If the sum has unsigned overflow, the result returned is the
  5771. mathematical result modulo 2\ :sup:`n`\ , where n is the bit width of
  5772. the result.
  5773. Because LLVM integers use a two's complement representation, this
  5774. instruction is appropriate for both signed and unsigned integers.
  5775. ``nuw`` and ``nsw`` stand for "No Unsigned Wrap" and "No Signed Wrap",
  5776. respectively. If the ``nuw`` and/or ``nsw`` keywords are present, the
  5777. result value of the ``add`` is a :ref:`poison value <poisonvalues>` if
  5778. unsigned and/or signed overflow, respectively, occurs.
  5779. Example:
  5780. """"""""
  5781. .. code-block:: text
  5782. <result> = add i32 4, %var ; yields i32:result = 4 + %var
  5783. .. _i_fadd:
  5784. '``fadd``' Instruction
  5785. ^^^^^^^^^^^^^^^^^^^^^^
  5786. Syntax:
  5787. """""""
  5788. ::
  5789. <result> = fadd [fast-math flags]* <ty> <op1>, <op2> ; yields ty:result
  5790. Overview:
  5791. """""""""
  5792. The '``fadd``' instruction returns the sum of its two operands.
  5793. Arguments:
  5794. """"""""""
  5795. The two arguments to the '``fadd``' instruction must be
  5796. :ref:`floating-point <t_floating>` or :ref:`vector <t_vector>` of
  5797. floating-point values. Both arguments must have identical types.
  5798. Semantics:
  5799. """"""""""
  5800. The value produced is the floating-point sum of the two operands.
  5801. This instruction is assumed to execute in the default :ref:`floating-point
  5802. environment <floatenv>`.
  5803. This instruction can also take any number of :ref:`fast-math
  5804. flags <fastmath>`, which are optimization hints to enable otherwise
  5805. unsafe floating-point optimizations:
  5806. Example:
  5807. """"""""
  5808. .. code-block:: text
  5809. <result> = fadd float 4.0, %var ; yields float:result = 4.0 + %var
  5810. '``sub``' Instruction
  5811. ^^^^^^^^^^^^^^^^^^^^^
  5812. Syntax:
  5813. """""""
  5814. ::
  5815. <result> = sub <ty> <op1>, <op2> ; yields ty:result
  5816. <result> = sub nuw <ty> <op1>, <op2> ; yields ty:result
  5817. <result> = sub nsw <ty> <op1>, <op2> ; yields ty:result
  5818. <result> = sub nuw nsw <ty> <op1>, <op2> ; yields ty:result
  5819. Overview:
  5820. """""""""
  5821. The '``sub``' instruction returns the difference of its two operands.
  5822. Note that the '``sub``' instruction is used to represent the '``neg``'
  5823. instruction present in most other intermediate representations.
  5824. Arguments:
  5825. """"""""""
  5826. The two arguments to the '``sub``' instruction must be
  5827. :ref:`integer <t_integer>` or :ref:`vector <t_vector>` of integer values. Both
  5828. arguments must have identical types.
  5829. Semantics:
  5830. """"""""""
  5831. The value produced is the integer difference of the two operands.
  5832. If the difference has unsigned overflow, the result returned is the
  5833. mathematical result modulo 2\ :sup:`n`\ , where n is the bit width of
  5834. the result.
  5835. Because LLVM integers use a two's complement representation, this
  5836. instruction is appropriate for both signed and unsigned integers.
  5837. ``nuw`` and ``nsw`` stand for "No Unsigned Wrap" and "No Signed Wrap",
  5838. respectively. If the ``nuw`` and/or ``nsw`` keywords are present, the
  5839. result value of the ``sub`` is a :ref:`poison value <poisonvalues>` if
  5840. unsigned and/or signed overflow, respectively, occurs.
  5841. Example:
  5842. """"""""
  5843. .. code-block:: text
  5844. <result> = sub i32 4, %var ; yields i32:result = 4 - %var
  5845. <result> = sub i32 0, %val ; yields i32:result = -%var
  5846. .. _i_fsub:
  5847. '``fsub``' Instruction
  5848. ^^^^^^^^^^^^^^^^^^^^^^
  5849. Syntax:
  5850. """""""
  5851. ::
  5852. <result> = fsub [fast-math flags]* <ty> <op1>, <op2> ; yields ty:result
  5853. Overview:
  5854. """""""""
  5855. The '``fsub``' instruction returns the difference of its two operands.
  5856. Arguments:
  5857. """"""""""
  5858. The two arguments to the '``fsub``' instruction must be
  5859. :ref:`floating-point <t_floating>` or :ref:`vector <t_vector>` of
  5860. floating-point values. Both arguments must have identical types.
  5861. Semantics:
  5862. """"""""""
  5863. The value produced is the floating-point difference of the two operands.
  5864. This instruction is assumed to execute in the default :ref:`floating-point
  5865. environment <floatenv>`.
  5866. This instruction can also take any number of :ref:`fast-math
  5867. flags <fastmath>`, which are optimization hints to enable otherwise
  5868. unsafe floating-point optimizations:
  5869. Example:
  5870. """"""""
  5871. .. code-block:: text
  5872. <result> = fsub float 4.0, %var ; yields float:result = 4.0 - %var
  5873. <result> = fsub float -0.0, %val ; yields float:result = -%var
  5874. '``mul``' Instruction
  5875. ^^^^^^^^^^^^^^^^^^^^^
  5876. Syntax:
  5877. """""""
  5878. ::
  5879. <result> = mul <ty> <op1>, <op2> ; yields ty:result
  5880. <result> = mul nuw <ty> <op1>, <op2> ; yields ty:result
  5881. <result> = mul nsw <ty> <op1>, <op2> ; yields ty:result
  5882. <result> = mul nuw nsw <ty> <op1>, <op2> ; yields ty:result
  5883. Overview:
  5884. """""""""
  5885. The '``mul``' instruction returns the product of its two operands.
  5886. Arguments:
  5887. """"""""""
  5888. The two arguments to the '``mul``' instruction must be
  5889. :ref:`integer <t_integer>` or :ref:`vector <t_vector>` of integer values. Both
  5890. arguments must have identical types.
  5891. Semantics:
  5892. """"""""""
  5893. The value produced is the integer product of the two operands.
  5894. If the result of the multiplication has unsigned overflow, the result
  5895. returned is the mathematical result modulo 2\ :sup:`n`\ , where n is the
  5896. bit width of the result.
  5897. Because LLVM integers use a two's complement representation, and the
  5898. result is the same width as the operands, this instruction returns the
  5899. correct result for both signed and unsigned integers. If a full product
  5900. (e.g. ``i32`` * ``i32`` -> ``i64``) is needed, the operands should be
  5901. sign-extended or zero-extended as appropriate to the width of the full
  5902. product.
  5903. ``nuw`` and ``nsw`` stand for "No Unsigned Wrap" and "No Signed Wrap",
  5904. respectively. If the ``nuw`` and/or ``nsw`` keywords are present, the
  5905. result value of the ``mul`` is a :ref:`poison value <poisonvalues>` if
  5906. unsigned and/or signed overflow, respectively, occurs.
  5907. Example:
  5908. """"""""
  5909. .. code-block:: text
  5910. <result> = mul i32 4, %var ; yields i32:result = 4 * %var
  5911. .. _i_fmul:
  5912. '``fmul``' Instruction
  5913. ^^^^^^^^^^^^^^^^^^^^^^
  5914. Syntax:
  5915. """""""
  5916. ::
  5917. <result> = fmul [fast-math flags]* <ty> <op1>, <op2> ; yields ty:result
  5918. Overview:
  5919. """""""""
  5920. The '``fmul``' instruction returns the product of its two operands.
  5921. Arguments:
  5922. """"""""""
  5923. The two arguments to the '``fmul``' instruction must be
  5924. :ref:`floating-point <t_floating>` or :ref:`vector <t_vector>` of
  5925. floating-point values. Both arguments must have identical types.
  5926. Semantics:
  5927. """"""""""
  5928. The value produced is the floating-point product of the two operands.
  5929. This instruction is assumed to execute in the default :ref:`floating-point
  5930. environment <floatenv>`.
  5931. This instruction can also take any number of :ref:`fast-math
  5932. flags <fastmath>`, which are optimization hints to enable otherwise
  5933. unsafe floating-point optimizations:
  5934. Example:
  5935. """"""""
  5936. .. code-block:: text
  5937. <result> = fmul float 4.0, %var ; yields float:result = 4.0 * %var
  5938. '``udiv``' Instruction
  5939. ^^^^^^^^^^^^^^^^^^^^^^
  5940. Syntax:
  5941. """""""
  5942. ::
  5943. <result> = udiv <ty> <op1>, <op2> ; yields ty:result
  5944. <result> = udiv exact <ty> <op1>, <op2> ; yields ty:result
  5945. Overview:
  5946. """""""""
  5947. The '``udiv``' instruction returns the quotient of its two operands.
  5948. Arguments:
  5949. """"""""""
  5950. The two arguments to the '``udiv``' instruction must be
  5951. :ref:`integer <t_integer>` or :ref:`vector <t_vector>` of integer values. Both
  5952. arguments must have identical types.
  5953. Semantics:
  5954. """"""""""
  5955. The value produced is the unsigned integer quotient of the two operands.
  5956. Note that unsigned integer division and signed integer division are
  5957. distinct operations; for signed integer division, use '``sdiv``'.
  5958. Division by zero is undefined behavior. For vectors, if any element
  5959. of the divisor is zero, the operation has undefined behavior.
  5960. If the ``exact`` keyword is present, the result value of the ``udiv`` is
  5961. a :ref:`poison value <poisonvalues>` if %op1 is not a multiple of %op2 (as
  5962. such, "((a udiv exact b) mul b) == a").
  5963. Example:
  5964. """"""""
  5965. .. code-block:: text
  5966. <result> = udiv i32 4, %var ; yields i32:result = 4 / %var
  5967. '``sdiv``' Instruction
  5968. ^^^^^^^^^^^^^^^^^^^^^^
  5969. Syntax:
  5970. """""""
  5971. ::
  5972. <result> = sdiv <ty> <op1>, <op2> ; yields ty:result
  5973. <result> = sdiv exact <ty> <op1>, <op2> ; yields ty:result
  5974. Overview:
  5975. """""""""
  5976. The '``sdiv``' instruction returns the quotient of its two operands.
  5977. Arguments:
  5978. """"""""""
  5979. The two arguments to the '``sdiv``' instruction must be
  5980. :ref:`integer <t_integer>` or :ref:`vector <t_vector>` of integer values. Both
  5981. arguments must have identical types.
  5982. Semantics:
  5983. """"""""""
  5984. The value produced is the signed integer quotient of the two operands
  5985. rounded towards zero.
  5986. Note that signed integer division and unsigned integer division are
  5987. distinct operations; for unsigned integer division, use '``udiv``'.
  5988. Division by zero is undefined behavior. For vectors, if any element
  5989. of the divisor is zero, the operation has undefined behavior.
  5990. Overflow also leads to undefined behavior; this is a rare case, but can
  5991. occur, for example, by doing a 32-bit division of -2147483648 by -1.
  5992. If the ``exact`` keyword is present, the result value of the ``sdiv`` is
  5993. a :ref:`poison value <poisonvalues>` if the result would be rounded.
  5994. Example:
  5995. """"""""
  5996. .. code-block:: text
  5997. <result> = sdiv i32 4, %var ; yields i32:result = 4 / %var
  5998. .. _i_fdiv:
  5999. '``fdiv``' Instruction
  6000. ^^^^^^^^^^^^^^^^^^^^^^
  6001. Syntax:
  6002. """""""
  6003. ::
  6004. <result> = fdiv [fast-math flags]* <ty> <op1>, <op2> ; yields ty:result
  6005. Overview:
  6006. """""""""
  6007. The '``fdiv``' instruction returns the quotient of its two operands.
  6008. Arguments:
  6009. """"""""""
  6010. The two arguments to the '``fdiv``' instruction must be
  6011. :ref:`floating-point <t_floating>` or :ref:`vector <t_vector>` of
  6012. floating-point values. Both arguments must have identical types.
  6013. Semantics:
  6014. """"""""""
  6015. The value produced is the floating-point quotient of the two operands.
  6016. This instruction is assumed to execute in the default :ref:`floating-point
  6017. environment <floatenv>`.
  6018. This instruction can also take any number of :ref:`fast-math
  6019. flags <fastmath>`, which are optimization hints to enable otherwise
  6020. unsafe floating-point optimizations:
  6021. Example:
  6022. """"""""
  6023. .. code-block:: text
  6024. <result> = fdiv float 4.0, %var ; yields float:result = 4.0 / %var
  6025. '``urem``' Instruction
  6026. ^^^^^^^^^^^^^^^^^^^^^^
  6027. Syntax:
  6028. """""""
  6029. ::
  6030. <result> = urem <ty> <op1>, <op2> ; yields ty:result
  6031. Overview:
  6032. """""""""
  6033. The '``urem``' instruction returns the remainder from the unsigned
  6034. division of its two arguments.
  6035. Arguments:
  6036. """"""""""
  6037. The two arguments to the '``urem``' instruction must be
  6038. :ref:`integer <t_integer>` or :ref:`vector <t_vector>` of integer values. Both
  6039. arguments must have identical types.
  6040. Semantics:
  6041. """"""""""
  6042. This instruction returns the unsigned integer *remainder* of a division.
  6043. This instruction always performs an unsigned division to get the
  6044. remainder.
  6045. Note that unsigned integer remainder and signed integer remainder are
  6046. distinct operations; for signed integer remainder, use '``srem``'.
  6047. Taking the remainder of a division by zero is undefined behavior.
  6048. For vectors, if any element of the divisor is zero, the operation has
  6049. undefined behavior.
  6050. Example:
  6051. """"""""
  6052. .. code-block:: text
  6053. <result> = urem i32 4, %var ; yields i32:result = 4 % %var
  6054. '``srem``' Instruction
  6055. ^^^^^^^^^^^^^^^^^^^^^^
  6056. Syntax:
  6057. """""""
  6058. ::
  6059. <result> = srem <ty> <op1>, <op2> ; yields ty:result
  6060. Overview:
  6061. """""""""
  6062. The '``srem``' instruction returns the remainder from the signed
  6063. division of its two operands. This instruction can also take
  6064. :ref:`vector <t_vector>` versions of the values in which case the elements
  6065. must be integers.
  6066. Arguments:
  6067. """"""""""
  6068. The two arguments to the '``srem``' instruction must be
  6069. :ref:`integer <t_integer>` or :ref:`vector <t_vector>` of integer values. Both
  6070. arguments must have identical types.
  6071. Semantics:
  6072. """"""""""
  6073. This instruction returns the *remainder* of a division (where the result
  6074. is either zero or has the same sign as the dividend, ``op1``), not the
  6075. *modulo* operator (where the result is either zero or has the same sign
  6076. as the divisor, ``op2``) of a value. For more information about the
  6077. difference, see `The Math
  6078. Forum <http://mathforum.org/dr.math/problems/anne.4.28.99.html>`_. For a
  6079. table of how this is implemented in various languages, please see
  6080. `Wikipedia: modulo
  6081. operation <http://en.wikipedia.org/wiki/Modulo_operation>`_.
  6082. Note that signed integer remainder and unsigned integer remainder are
  6083. distinct operations; for unsigned integer remainder, use '``urem``'.
  6084. Taking the remainder of a division by zero is undefined behavior.
  6085. For vectors, if any element of the divisor is zero, the operation has
  6086. undefined behavior.
  6087. Overflow also leads to undefined behavior; this is a rare case, but can
  6088. occur, for example, by taking the remainder of a 32-bit division of
  6089. -2147483648 by -1. (The remainder doesn't actually overflow, but this
  6090. rule lets srem be implemented using instructions that return both the
  6091. result of the division and the remainder.)
  6092. Example:
  6093. """"""""
  6094. .. code-block:: text
  6095. <result> = srem i32 4, %var ; yields i32:result = 4 % %var
  6096. .. _i_frem:
  6097. '``frem``' Instruction
  6098. ^^^^^^^^^^^^^^^^^^^^^^
  6099. Syntax:
  6100. """""""
  6101. ::
  6102. <result> = frem [fast-math flags]* <ty> <op1>, <op2> ; yields ty:result
  6103. Overview:
  6104. """""""""
  6105. The '``frem``' instruction returns the remainder from the division of
  6106. its two operands.
  6107. Arguments:
  6108. """"""""""
  6109. The two arguments to the '``frem``' instruction must be
  6110. :ref:`floating-point <t_floating>` or :ref:`vector <t_vector>` of
  6111. floating-point values. Both arguments must have identical types.
  6112. Semantics:
  6113. """"""""""
  6114. The value produced is the floating-point remainder of the two operands.
  6115. This is the same output as a libm '``fmod``' function, but without any
  6116. possibility of setting ``errno``. The remainder has the same sign as the
  6117. dividend.
  6118. This instruction is assumed to execute in the default :ref:`floating-point
  6119. environment <floatenv>`.
  6120. This instruction can also take any number of :ref:`fast-math
  6121. flags <fastmath>`, which are optimization hints to enable otherwise
  6122. unsafe floating-point optimizations:
  6123. Example:
  6124. """"""""
  6125. .. code-block:: text
  6126. <result> = frem float 4.0, %var ; yields float:result = 4.0 % %var
  6127. .. _bitwiseops:
  6128. Bitwise Binary Operations
  6129. -------------------------
  6130. Bitwise binary operators are used to do various forms of bit-twiddling
  6131. in a program. They are generally very efficient instructions and can
  6132. commonly be strength reduced from other instructions. They require two
  6133. operands of the same type, execute an operation on them, and produce a
  6134. single value. The resulting value is the same type as its operands.
  6135. '``shl``' Instruction
  6136. ^^^^^^^^^^^^^^^^^^^^^
  6137. Syntax:
  6138. """""""
  6139. ::
  6140. <result> = shl <ty> <op1>, <op2> ; yields ty:result
  6141. <result> = shl nuw <ty> <op1>, <op2> ; yields ty:result
  6142. <result> = shl nsw <ty> <op1>, <op2> ; yields ty:result
  6143. <result> = shl nuw nsw <ty> <op1>, <op2> ; yields ty:result
  6144. Overview:
  6145. """""""""
  6146. The '``shl``' instruction returns the first operand shifted to the left
  6147. a specified number of bits.
  6148. Arguments:
  6149. """"""""""
  6150. Both arguments to the '``shl``' instruction must be the same
  6151. :ref:`integer <t_integer>` or :ref:`vector <t_vector>` of integer type.
  6152. '``op2``' is treated as an unsigned value.
  6153. Semantics:
  6154. """"""""""
  6155. The value produced is ``op1`` \* 2\ :sup:`op2` mod 2\ :sup:`n`,
  6156. where ``n`` is the width of the result. If ``op2`` is (statically or
  6157. dynamically) equal to or larger than the number of bits in
  6158. ``op1``, this instruction returns a :ref:`poison value <poisonvalues>`.
  6159. If the arguments are vectors, each vector element of ``op1`` is shifted
  6160. by the corresponding shift amount in ``op2``.
  6161. If the ``nuw`` keyword is present, then the shift produces a poison
  6162. value if it shifts out any non-zero bits.
  6163. If the ``nsw`` keyword is present, then the shift produces a poison
  6164. value if it shifts out any bits that disagree with the resultant sign bit.
  6165. Example:
  6166. """"""""
  6167. .. code-block:: text
  6168. <result> = shl i32 4, %var ; yields i32: 4 << %var
  6169. <result> = shl i32 4, 2 ; yields i32: 16
  6170. <result> = shl i32 1, 10 ; yields i32: 1024
  6171. <result> = shl i32 1, 32 ; undefined
  6172. <result> = shl <2 x i32> < i32 1, i32 1>, < i32 1, i32 2> ; yields: result=<2 x i32> < i32 2, i32 4>
  6173. '``lshr``' Instruction
  6174. ^^^^^^^^^^^^^^^^^^^^^^
  6175. Syntax:
  6176. """""""
  6177. ::
  6178. <result> = lshr <ty> <op1>, <op2> ; yields ty:result
  6179. <result> = lshr exact <ty> <op1>, <op2> ; yields ty:result
  6180. Overview:
  6181. """""""""
  6182. The '``lshr``' instruction (logical shift right) returns the first
  6183. operand shifted to the right a specified number of bits with zero fill.
  6184. Arguments:
  6185. """"""""""
  6186. Both arguments to the '``lshr``' instruction must be the same
  6187. :ref:`integer <t_integer>` or :ref:`vector <t_vector>` of integer type.
  6188. '``op2``' is treated as an unsigned value.
  6189. Semantics:
  6190. """"""""""
  6191. This instruction always performs a logical shift right operation. The
  6192. most significant bits of the result will be filled with zero bits after
  6193. the shift. If ``op2`` is (statically or dynamically) equal to or larger
  6194. than the number of bits in ``op1``, this instruction returns a :ref:`poison
  6195. value <poisonvalues>`. If the arguments are vectors, each vector element
  6196. of ``op1`` is shifted by the corresponding shift amount in ``op2``.
  6197. If the ``exact`` keyword is present, the result value of the ``lshr`` is
  6198. a poison value if any of the bits shifted out are non-zero.
  6199. Example:
  6200. """"""""
  6201. .. code-block:: text
  6202. <result> = lshr i32 4, 1 ; yields i32:result = 2
  6203. <result> = lshr i32 4, 2 ; yields i32:result = 1
  6204. <result> = lshr i8 4, 3 ; yields i8:result = 0
  6205. <result> = lshr i8 -2, 1 ; yields i8:result = 0x7F
  6206. <result> = lshr i32 1, 32 ; undefined
  6207. <result> = lshr <2 x i32> < i32 -2, i32 4>, < i32 1, i32 2> ; yields: result=<2 x i32> < i32 0x7FFFFFFF, i32 1>
  6208. '``ashr``' Instruction
  6209. ^^^^^^^^^^^^^^^^^^^^^^
  6210. Syntax:
  6211. """""""
  6212. ::
  6213. <result> = ashr <ty> <op1>, <op2> ; yields ty:result
  6214. <result> = ashr exact <ty> <op1>, <op2> ; yields ty:result
  6215. Overview:
  6216. """""""""
  6217. The '``ashr``' instruction (arithmetic shift right) returns the first
  6218. operand shifted to the right a specified number of bits with sign
  6219. extension.
  6220. Arguments:
  6221. """"""""""
  6222. Both arguments to the '``ashr``' instruction must be the same
  6223. :ref:`integer <t_integer>` or :ref:`vector <t_vector>` of integer type.
  6224. '``op2``' is treated as an unsigned value.
  6225. Semantics:
  6226. """"""""""
  6227. This instruction always performs an arithmetic shift right operation,
  6228. The most significant bits of the result will be filled with the sign bit
  6229. of ``op1``. If ``op2`` is (statically or dynamically) equal to or larger
  6230. than the number of bits in ``op1``, this instruction returns a :ref:`poison
  6231. value <poisonvalues>`. If the arguments are vectors, each vector element
  6232. of ``op1`` is shifted by the corresponding shift amount in ``op2``.
  6233. If the ``exact`` keyword is present, the result value of the ``ashr`` is
  6234. a poison value if any of the bits shifted out are non-zero.
  6235. Example:
  6236. """"""""
  6237. .. code-block:: text
  6238. <result> = ashr i32 4, 1 ; yields i32:result = 2
  6239. <result> = ashr i32 4, 2 ; yields i32:result = 1
  6240. <result> = ashr i8 4, 3 ; yields i8:result = 0
  6241. <result> = ashr i8 -2, 1 ; yields i8:result = -1
  6242. <result> = ashr i32 1, 32 ; undefined
  6243. <result> = ashr <2 x i32> < i32 -2, i32 4>, < i32 1, i32 3> ; yields: result=<2 x i32> < i32 -1, i32 0>
  6244. '``and``' Instruction
  6245. ^^^^^^^^^^^^^^^^^^^^^
  6246. Syntax:
  6247. """""""
  6248. ::
  6249. <result> = and <ty> <op1>, <op2> ; yields ty:result
  6250. Overview:
  6251. """""""""
  6252. The '``and``' instruction returns the bitwise logical and of its two
  6253. operands.
  6254. Arguments:
  6255. """"""""""
  6256. The two arguments to the '``and``' instruction must be
  6257. :ref:`integer <t_integer>` or :ref:`vector <t_vector>` of integer values. Both
  6258. arguments must have identical types.
  6259. Semantics:
  6260. """"""""""
  6261. The truth table used for the '``and``' instruction is:
  6262. +-----+-----+-----+
  6263. | In0 | In1 | Out |
  6264. +-----+-----+-----+
  6265. | 0 | 0 | 0 |
  6266. +-----+-----+-----+
  6267. | 0 | 1 | 0 |
  6268. +-----+-----+-----+
  6269. | 1 | 0 | 0 |
  6270. +-----+-----+-----+
  6271. | 1 | 1 | 1 |
  6272. +-----+-----+-----+
  6273. Example:
  6274. """"""""
  6275. .. code-block:: text
  6276. <result> = and i32 4, %var ; yields i32:result = 4 & %var
  6277. <result> = and i32 15, 40 ; yields i32:result = 8
  6278. <result> = and i32 4, 8 ; yields i32:result = 0
  6279. '``or``' Instruction
  6280. ^^^^^^^^^^^^^^^^^^^^
  6281. Syntax:
  6282. """""""
  6283. ::
  6284. <result> = or <ty> <op1>, <op2> ; yields ty:result
  6285. Overview:
  6286. """""""""
  6287. The '``or``' instruction returns the bitwise logical inclusive or of its
  6288. two operands.
  6289. Arguments:
  6290. """"""""""
  6291. The two arguments to the '``or``' instruction must be
  6292. :ref:`integer <t_integer>` or :ref:`vector <t_vector>` of integer values. Both
  6293. arguments must have identical types.
  6294. Semantics:
  6295. """"""""""
  6296. The truth table used for the '``or``' instruction is:
  6297. +-----+-----+-----+
  6298. | In0 | In1 | Out |
  6299. +-----+-----+-----+
  6300. | 0 | 0 | 0 |
  6301. +-----+-----+-----+
  6302. | 0 | 1 | 1 |
  6303. +-----+-----+-----+
  6304. | 1 | 0 | 1 |
  6305. +-----+-----+-----+
  6306. | 1 | 1 | 1 |
  6307. +-----+-----+-----+
  6308. Example:
  6309. """"""""
  6310. ::
  6311. <result> = or i32 4, %var ; yields i32:result = 4 | %var
  6312. <result> = or i32 15, 40 ; yields i32:result = 47
  6313. <result> = or i32 4, 8 ; yields i32:result = 12
  6314. '``xor``' Instruction
  6315. ^^^^^^^^^^^^^^^^^^^^^
  6316. Syntax:
  6317. """""""
  6318. ::
  6319. <result> = xor <ty> <op1>, <op2> ; yields ty:result
  6320. Overview:
  6321. """""""""
  6322. The '``xor``' instruction returns the bitwise logical exclusive or of
  6323. its two operands. The ``xor`` is used to implement the "one's
  6324. complement" operation, which is the "~" operator in C.
  6325. Arguments:
  6326. """"""""""
  6327. The two arguments to the '``xor``' instruction must be
  6328. :ref:`integer <t_integer>` or :ref:`vector <t_vector>` of integer values. Both
  6329. arguments must have identical types.
  6330. Semantics:
  6331. """"""""""
  6332. The truth table used for the '``xor``' instruction is:
  6333. +-----+-----+-----+
  6334. | In0 | In1 | Out |
  6335. +-----+-----+-----+
  6336. | 0 | 0 | 0 |
  6337. +-----+-----+-----+
  6338. | 0 | 1 | 1 |
  6339. +-----+-----+-----+
  6340. | 1 | 0 | 1 |
  6341. +-----+-----+-----+
  6342. | 1 | 1 | 0 |
  6343. +-----+-----+-----+
  6344. Example:
  6345. """"""""
  6346. .. code-block:: text
  6347. <result> = xor i32 4, %var ; yields i32:result = 4 ^ %var
  6348. <result> = xor i32 15, 40 ; yields i32:result = 39
  6349. <result> = xor i32 4, 8 ; yields i32:result = 12
  6350. <result> = xor i32 %V, -1 ; yields i32:result = ~%V
  6351. Vector Operations
  6352. -----------------
  6353. LLVM supports several instructions to represent vector operations in a
  6354. target-independent manner. These instructions cover the element-access
  6355. and vector-specific operations needed to process vectors effectively.
  6356. While LLVM does directly support these vector operations, many
  6357. sophisticated algorithms will want to use target-specific intrinsics to
  6358. take full advantage of a specific target.
  6359. .. _i_extractelement:
  6360. '``extractelement``' Instruction
  6361. ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  6362. Syntax:
  6363. """""""
  6364. ::
  6365. <result> = extractelement <n x <ty>> <val>, <ty2> <idx> ; yields <ty>
  6366. <result> = extractelement <vscale x n x <ty>> <val>, <ty2> <idx> ; yields <ty>
  6367. Overview:
  6368. """""""""
  6369. The '``extractelement``' instruction extracts a single scalar element
  6370. from a vector at a specified index.
  6371. Arguments:
  6372. """"""""""
  6373. The first operand of an '``extractelement``' instruction is a value of
  6374. :ref:`vector <t_vector>` type. The second operand is an index indicating
  6375. the position from which to extract the element. The index may be a
  6376. variable of any integer type.
  6377. Semantics:
  6378. """"""""""
  6379. The result is a scalar of the same type as the element type of ``val``.
  6380. Its value is the value at position ``idx`` of ``val``. If ``idx``
  6381. exceeds the length of ``val`` for a fixed-length vector, the result is a
  6382. :ref:`poison value <poisonvalues>`. For a scalable vector, if the value
  6383. of ``idx`` exceeds the runtime length of the vector, the result is a
  6384. :ref:`poison value <poisonvalues>`.
  6385. Example:
  6386. """"""""
  6387. .. code-block:: text
  6388. <result> = extractelement <4 x i32> %vec, i32 0 ; yields i32
  6389. .. _i_insertelement:
  6390. '``insertelement``' Instruction
  6391. ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  6392. Syntax:
  6393. """""""
  6394. ::
  6395. <result> = insertelement <n x <ty>> <val>, <ty> <elt>, <ty2> <idx> ; yields <n x <ty>>
  6396. <result> = insertelement <vscale x n x <ty>> <val>, <ty> <elt>, <ty2> <idx> ; yields <vscale x n x <ty>>
  6397. Overview:
  6398. """""""""
  6399. The '``insertelement``' instruction inserts a scalar element into a
  6400. vector at a specified index.
  6401. Arguments:
  6402. """"""""""
  6403. The first operand of an '``insertelement``' instruction is a value of
  6404. :ref:`vector <t_vector>` type. The second operand is a scalar value whose
  6405. type must equal the element type of the first operand. The third operand
  6406. is an index indicating the position at which to insert the value. The
  6407. index may be a variable of any integer type.
  6408. Semantics:
  6409. """"""""""
  6410. The result is a vector of the same type as ``val``. Its element values
  6411. are those of ``val`` except at position ``idx``, where it gets the value
  6412. ``elt``. If ``idx`` exceeds the length of ``val`` for a fixed-length vector,
  6413. the result is a :ref:`poison value <poisonvalues>`. For a scalable vector,
  6414. if the value of ``idx`` exceeds the runtime length of the vector, the result
  6415. is a :ref:`poison value <poisonvalues>`.
  6416. Example:
  6417. """"""""
  6418. .. code-block:: text
  6419. <result> = insertelement <4 x i32> %vec, i32 1, i32 0 ; yields <4 x i32>
  6420. .. _i_shufflevector:
  6421. '``shufflevector``' Instruction
  6422. ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  6423. Syntax:
  6424. """""""
  6425. ::
  6426. <result> = shufflevector <n x <ty>> <v1>, <n x <ty>> <v2>, <m x i32> <mask> ; yields <m x <ty>>
  6427. <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>>
  6428. Overview:
  6429. """""""""
  6430. The '``shufflevector``' instruction constructs a permutation of elements
  6431. from two input vectors, returning a vector with the same element type as
  6432. the input and length that is the same as the shuffle mask.
  6433. Arguments:
  6434. """"""""""
  6435. The first two operands of a '``shufflevector``' instruction are vectors
  6436. with the same type. The third argument is a shuffle mask whose element
  6437. type is always 'i32'. The result of the instruction is a vector whose
  6438. length is the same as the shuffle mask and whose element type is the
  6439. same as the element type of the first two operands.
  6440. The shuffle mask operand is required to be a constant vector with either
  6441. constant integer or undef values.
  6442. Semantics:
  6443. """"""""""
  6444. The elements of the two input vectors are numbered from left to right
  6445. across both of the vectors. The shuffle mask operand specifies, for each
  6446. element of the result vector, which element of the two input vectors the
  6447. result element gets. If the shuffle mask is undef, the result vector is
  6448. undef. If any element of the mask operand is undef, that element of the
  6449. result is undef. If the shuffle mask selects an undef element from one
  6450. of the input vectors, the resulting element is undef.
  6451. For scalable vectors, the only valid mask values at present are
  6452. ``zeroinitializer`` and ``undef``, since we cannot write all indices as
  6453. literals for a vector with a length unknown at compile time.
  6454. Example:
  6455. """"""""
  6456. .. code-block:: text
  6457. <result> = shufflevector <4 x i32> %v1, <4 x i32> %v2,
  6458. <4 x i32> <i32 0, i32 4, i32 1, i32 5> ; yields <4 x i32>
  6459. <result> = shufflevector <4 x i32> %v1, <4 x i32> undef,
  6460. <4 x i32> <i32 0, i32 1, i32 2, i32 3> ; yields <4 x i32> - Identity shuffle.
  6461. <result> = shufflevector <8 x i32> %v1, <8 x i32> undef,
  6462. <4 x i32> <i32 0, i32 1, i32 2, i32 3> ; yields <4 x i32>
  6463. <result> = shufflevector <4 x i32> %v1, <4 x i32> %v2,
  6464. <8 x i32> <i32 0, i32 1, i32 2, i32 3, i32 4, i32 5, i32 6, i32 7 > ; yields <8 x i32>
  6465. Aggregate Operations
  6466. --------------------
  6467. LLVM supports several instructions for working with
  6468. :ref:`aggregate <t_aggregate>` values.
  6469. .. _i_extractvalue:
  6470. '``extractvalue``' Instruction
  6471. ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  6472. Syntax:
  6473. """""""
  6474. ::
  6475. <result> = extractvalue <aggregate type> <val>, <idx>{, <idx>}*
  6476. Overview:
  6477. """""""""
  6478. The '``extractvalue``' instruction extracts the value of a member field
  6479. from an :ref:`aggregate <t_aggregate>` value.
  6480. Arguments:
  6481. """"""""""
  6482. The first operand of an '``extractvalue``' instruction is a value of
  6483. :ref:`struct <t_struct>` or :ref:`array <t_array>` type. The other operands are
  6484. constant indices to specify which value to extract in a similar manner
  6485. as indices in a '``getelementptr``' instruction.
  6486. The major differences to ``getelementptr`` indexing are:
  6487. - Since the value being indexed is not a pointer, the first index is
  6488. omitted and assumed to be zero.
  6489. - At least one index must be specified.
  6490. - Not only struct indices but also array indices must be in bounds.
  6491. Semantics:
  6492. """"""""""
  6493. The result is the value at the position in the aggregate specified by
  6494. the index operands.
  6495. Example:
  6496. """"""""
  6497. .. code-block:: text
  6498. <result> = extractvalue {i32, float} %agg, 0 ; yields i32
  6499. .. _i_insertvalue:
  6500. '``insertvalue``' Instruction
  6501. ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  6502. Syntax:
  6503. """""""
  6504. ::
  6505. <result> = insertvalue <aggregate type> <val>, <ty> <elt>, <idx>{, <idx>}* ; yields <aggregate type>
  6506. Overview:
  6507. """""""""
  6508. The '``insertvalue``' instruction inserts a value into a member field in
  6509. an :ref:`aggregate <t_aggregate>` value.
  6510. Arguments:
  6511. """"""""""
  6512. The first operand of an '``insertvalue``' instruction is a value of
  6513. :ref:`struct <t_struct>` or :ref:`array <t_array>` type. The second operand is
  6514. a first-class value to insert. The following operands are constant
  6515. indices indicating the position at which to insert the value in a
  6516. similar manner as indices in a '``extractvalue``' instruction. The value
  6517. to insert must have the same type as the value identified by the
  6518. indices.
  6519. Semantics:
  6520. """"""""""
  6521. The result is an aggregate of the same type as ``val``. Its value is
  6522. that of ``val`` except that the value at the position specified by the
  6523. indices is that of ``elt``.
  6524. Example:
  6525. """"""""
  6526. .. code-block:: llvm
  6527. %agg1 = insertvalue {i32, float} undef, i32 1, 0 ; yields {i32 1, float undef}
  6528. %agg2 = insertvalue {i32, float} %agg1, float %val, 1 ; yields {i32 1, float %val}
  6529. %agg3 = insertvalue {i32, {float}} undef, float %val, 1, 0 ; yields {i32 undef, {float %val}}
  6530. .. _memoryops:
  6531. Memory Access and Addressing Operations
  6532. ---------------------------------------
  6533. A key design point of an SSA-based representation is how it represents
  6534. memory. In LLVM, no memory locations are in SSA form, which makes things
  6535. very simple. This section describes how to read, write, and allocate
  6536. memory in LLVM.
  6537. .. _i_alloca:
  6538. '``alloca``' Instruction
  6539. ^^^^^^^^^^^^^^^^^^^^^^^^
  6540. Syntax:
  6541. """""""
  6542. ::
  6543. <result> = alloca [inalloca] <type> [, <ty> <NumElements>] [, align <alignment>] [, addrspace(<num>)] ; yields type addrspace(num)*:result
  6544. Overview:
  6545. """""""""
  6546. The '``alloca``' instruction allocates memory on the stack frame of the
  6547. currently executing function, to be automatically released when this
  6548. function returns to its caller. The object is always allocated in the
  6549. address space for allocas indicated in the datalayout.
  6550. Arguments:
  6551. """"""""""
  6552. The '``alloca``' instruction allocates ``sizeof(<type>)*NumElements``
  6553. bytes of memory on the runtime stack, returning a pointer of the
  6554. appropriate type to the program. If "NumElements" is specified, it is
  6555. the number of elements allocated, otherwise "NumElements" is defaulted
  6556. to be one. If a constant alignment is specified, the value result of the
  6557. allocation is guaranteed to be aligned to at least that boundary. The
  6558. alignment may not be greater than ``1 << 29``. If not specified, or if
  6559. zero, the target can choose to align the allocation on any convenient
  6560. boundary compatible with the type.
  6561. '``type``' may be any sized type.
  6562. Semantics:
  6563. """"""""""
  6564. Memory is allocated; a pointer is returned. The allocated memory is
  6565. uninitialized, and loading from uninitialized memory produces an undefined
  6566. value. The operation itself is undefined if there is insufficient stack
  6567. space for the allocation.'``alloca``'d memory is automatically released
  6568. when the function returns. The '``alloca``' instruction is commonly used
  6569. to represent automatic variables that must have an address available. When
  6570. the function returns (either with the ``ret`` or ``resume`` instructions),
  6571. the memory is reclaimed. Allocating zero bytes is legal, but the returned
  6572. pointer may not be unique. The order in which memory is allocated (ie.,
  6573. which way the stack grows) is not specified.
  6574. Example:
  6575. """"""""
  6576. .. code-block:: llvm
  6577. %ptr = alloca i32 ; yields i32*:ptr
  6578. %ptr = alloca i32, i32 4 ; yields i32*:ptr
  6579. %ptr = alloca i32, i32 4, align 1024 ; yields i32*:ptr
  6580. %ptr = alloca i32, align 1024 ; yields i32*:ptr
  6581. .. _i_load:
  6582. '``load``' Instruction
  6583. ^^^^^^^^^^^^^^^^^^^^^^
  6584. Syntax:
  6585. """""""
  6586. ::
  6587. <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>]
  6588. <result> = load atomic [volatile] <ty>, <ty>* <pointer> [syncscope("<target-scope>")] <ordering>, align <alignment> [, !invariant.group !<index>]
  6589. !<index> = !{ i32 1 }
  6590. !<deref_bytes_node> = !{i64 <dereferenceable_bytes>}
  6591. !<align_node> = !{ i64 <value_alignment> }
  6592. Overview:
  6593. """""""""
  6594. The '``load``' instruction is used to read from memory.
  6595. Arguments:
  6596. """"""""""
  6597. The argument to the ``load`` instruction specifies the memory address from which
  6598. to load. The type specified must be a :ref:`first class <t_firstclass>` type of
  6599. known size (i.e. not containing an :ref:`opaque structural type <t_opaque>`). If
  6600. the ``load`` is marked as ``volatile``, then the optimizer is not allowed to
  6601. modify the number or order of execution of this ``load`` with other
  6602. :ref:`volatile operations <volatile>`.
  6603. If the ``load`` is marked as ``atomic``, it takes an extra :ref:`ordering
  6604. <ordering>` and optional ``syncscope("<target-scope>")`` argument. The
  6605. ``release`` and ``acq_rel`` orderings are not valid on ``load`` instructions.
  6606. Atomic loads produce :ref:`defined <memmodel>` results when they may see
  6607. multiple atomic stores. The type of the pointee must be an integer, pointer, or
  6608. floating-point type whose bit width is a power of two greater than or equal to
  6609. eight and less than or equal to a target-specific size limit. ``align`` must be
  6610. explicitly specified on atomic loads, and the load has undefined behavior if the
  6611. alignment is not set to a value which is at least the size in bytes of the
  6612. pointee. ``!nontemporal`` does not have any defined semantics for atomic loads.
  6613. The optional constant ``align`` argument specifies the alignment of the
  6614. operation (that is, the alignment of the memory address). A value of 0
  6615. or an omitted ``align`` argument means that the operation has the ABI
  6616. alignment for the target. It is the responsibility of the code emitter
  6617. to ensure that the alignment information is correct. Overestimating the
  6618. alignment results in undefined behavior. Underestimating the alignment
  6619. may produce less efficient code. An alignment of 1 is always safe. The
  6620. maximum possible alignment is ``1 << 29``. An alignment value higher
  6621. than the size of the loaded type implies memory up to the alignment
  6622. value bytes can be safely loaded without trapping in the default
  6623. address space. Access of the high bytes can interfere with debugging
  6624. tools, so should not be accessed if the function has the
  6625. ``sanitize_thread`` or ``sanitize_address`` attributes.
  6626. The optional ``!nontemporal`` metadata must reference a single
  6627. metadata name ``<index>`` corresponding to a metadata node with one
  6628. ``i32`` entry of value 1. The existence of the ``!nontemporal``
  6629. metadata on the instruction tells the optimizer and code generator
  6630. that this load is not expected to be reused in the cache. The code
  6631. generator may select special instructions to save cache bandwidth, such
  6632. as the ``MOVNT`` instruction on x86.
  6633. The optional ``!invariant.load`` metadata must reference a single
  6634. metadata name ``<index>`` corresponding to a metadata node with no
  6635. entries. If a load instruction tagged with the ``!invariant.load``
  6636. metadata is executed, the optimizer may assume the memory location
  6637. referenced by the load contains the same value at all points in the
  6638. program where the memory location is known to be dereferenceable;
  6639. otherwise, the behavior is undefined.
  6640. The optional ``!invariant.group`` metadata must reference a single metadata name
  6641. ``<index>`` corresponding to a metadata node with no entries.
  6642. See ``invariant.group`` metadata :ref:`invariant.group <md_invariant.group>`
  6643. The optional ``!nonnull`` metadata must reference a single
  6644. metadata name ``<index>`` corresponding to a metadata node with no
  6645. entries. The existence of the ``!nonnull`` metadata on the
  6646. instruction tells the optimizer that the value loaded is known to
  6647. never be null. If the value is null at runtime, the behavior is undefined.
  6648. This is analogous to the ``nonnull`` attribute on parameters and return
  6649. values. This metadata can only be applied to loads of a pointer type.
  6650. The optional ``!dereferenceable`` metadata must reference a single metadata
  6651. name ``<deref_bytes_node>`` corresponding to a metadata node with one ``i64``
  6652. entry.
  6653. See ``dereferenceable`` metadata :ref:`dereferenceable <md_dereferenceable>`
  6654. The optional ``!dereferenceable_or_null`` metadata must reference a single
  6655. metadata name ``<deref_bytes_node>`` corresponding to a metadata node with one
  6656. ``i64`` entry.
  6657. See ``dereferenceable_or_null`` metadata :ref:`dereferenceable_or_null
  6658. <md_dereferenceable_or_null>`
  6659. The optional ``!align`` metadata must reference a single metadata name
  6660. ``<align_node>`` corresponding to a metadata node with one ``i64`` entry.
  6661. The existence of the ``!align`` metadata on the instruction tells the
  6662. optimizer that the value loaded is known to be aligned to a boundary specified
  6663. by the integer value in the metadata node. The alignment must be a power of 2.
  6664. This is analogous to the ''align'' attribute on parameters and return values.
  6665. This metadata can only be applied to loads of a pointer type. If the returned
  6666. value is not appropriately aligned at runtime, the behavior is undefined.
  6667. Semantics:
  6668. """"""""""
  6669. The location of memory pointed to is loaded. If the value being loaded
  6670. is of scalar type then the number of bytes read does not exceed the
  6671. minimum number of bytes needed to hold all bits of the type. For
  6672. example, loading an ``i24`` reads at most three bytes. When loading a
  6673. value of a type like ``i20`` with a size that is not an integral number
  6674. of bytes, the result is undefined if the value was not originally
  6675. written using a store of the same type.
  6676. Examples:
  6677. """""""""
  6678. .. code-block:: llvm
  6679. %ptr = alloca i32 ; yields i32*:ptr
  6680. store i32 3, i32* %ptr ; yields void
  6681. %val = load i32, i32* %ptr ; yields i32:val = i32 3
  6682. .. _i_store:
  6683. '``store``' Instruction
  6684. ^^^^^^^^^^^^^^^^^^^^^^^
  6685. Syntax:
  6686. """""""
  6687. ::
  6688. store [volatile] <ty> <value>, <ty>* <pointer>[, align <alignment>][, !nontemporal !<index>][, !invariant.group !<index>] ; yields void
  6689. store atomic [volatile] <ty> <value>, <ty>* <pointer> [syncscope("<target-scope>")] <ordering>, align <alignment> [, !invariant.group !<index>] ; yields void
  6690. Overview:
  6691. """""""""
  6692. The '``store``' instruction is used to write to memory.
  6693. Arguments:
  6694. """"""""""
  6695. There are two arguments to the ``store`` instruction: a value to store and an
  6696. address at which to store it. The type of the ``<pointer>`` operand must be a
  6697. pointer to the :ref:`first class <t_firstclass>` type of the ``<value>``
  6698. operand. If the ``store`` is marked as ``volatile``, then the optimizer is not
  6699. allowed to modify the number or order of execution of this ``store`` with other
  6700. :ref:`volatile operations <volatile>`. Only values of :ref:`first class
  6701. <t_firstclass>` types of known size (i.e. not containing an :ref:`opaque
  6702. structural type <t_opaque>`) can be stored.
  6703. If the ``store`` is marked as ``atomic``, it takes an extra :ref:`ordering
  6704. <ordering>` and optional ``syncscope("<target-scope>")`` argument. The
  6705. ``acquire`` and ``acq_rel`` orderings aren't valid on ``store`` instructions.
  6706. Atomic loads produce :ref:`defined <memmodel>` results when they may see
  6707. multiple atomic stores. The type of the pointee must be an integer, pointer, or
  6708. floating-point type whose bit width is a power of two greater than or equal to
  6709. eight and less than or equal to a target-specific size limit. ``align`` must be
  6710. explicitly specified on atomic stores, and the store has undefined behavior if
  6711. the alignment is not set to a value which is at least the size in bytes of the
  6712. pointee. ``!nontemporal`` does not have any defined semantics for atomic stores.
  6713. The optional constant ``align`` argument specifies the alignment of the
  6714. operation (that is, the alignment of the memory address). A value of 0
  6715. or an omitted ``align`` argument means that the operation has the ABI
  6716. alignment for the target. It is the responsibility of the code emitter
  6717. to ensure that the alignment information is correct. Overestimating the
  6718. alignment results in undefined behavior. Underestimating the
  6719. alignment may produce less efficient code. An alignment of 1 is always
  6720. safe. The maximum possible alignment is ``1 << 29``. An alignment
  6721. value higher than the size of the stored type implies memory up to the
  6722. alignment value bytes can be stored to without trapping in the default
  6723. address space. Storing to the higher bytes however may result in data
  6724. races if another thread can access the same address. Introducing a
  6725. data race is not allowed. Storing to the extra bytes is not allowed
  6726. even in situations where a data race is known to not exist if the
  6727. function has the ``sanitize_address`` attribute.
  6728. The optional ``!nontemporal`` metadata must reference a single metadata
  6729. name ``<index>`` corresponding to a metadata node with one ``i32`` entry of
  6730. value 1. The existence of the ``!nontemporal`` metadata on the instruction
  6731. tells the optimizer and code generator that this load is not expected to
  6732. be reused in the cache. The code generator may select special
  6733. instructions to save cache bandwidth, such as the ``MOVNT`` instruction on
  6734. x86.
  6735. The optional ``!invariant.group`` metadata must reference a
  6736. single metadata name ``<index>``. See ``invariant.group`` metadata.
  6737. Semantics:
  6738. """"""""""
  6739. The contents of memory are updated to contain ``<value>`` at the
  6740. location specified by the ``<pointer>`` operand. If ``<value>`` is
  6741. of scalar type then the number of bytes written does not exceed the
  6742. minimum number of bytes needed to hold all bits of the type. For
  6743. example, storing an ``i24`` writes at most three bytes. When writing a
  6744. value of a type like ``i20`` with a size that is not an integral number
  6745. of bytes, it is unspecified what happens to the extra bits that do not
  6746. belong to the type, but they will typically be overwritten.
  6747. Example:
  6748. """"""""
  6749. .. code-block:: llvm
  6750. %ptr = alloca i32 ; yields i32*:ptr
  6751. store i32 3, i32* %ptr ; yields void
  6752. %val = load i32, i32* %ptr ; yields i32:val = i32 3
  6753. .. _i_fence:
  6754. '``fence``' Instruction
  6755. ^^^^^^^^^^^^^^^^^^^^^^^
  6756. Syntax:
  6757. """""""
  6758. ::
  6759. fence [syncscope("<target-scope>")] <ordering> ; yields void
  6760. Overview:
  6761. """""""""
  6762. The '``fence``' instruction is used to introduce happens-before edges
  6763. between operations.
  6764. Arguments:
  6765. """"""""""
  6766. '``fence``' instructions take an :ref:`ordering <ordering>` argument which
  6767. defines what *synchronizes-with* edges they add. They can only be given
  6768. ``acquire``, ``release``, ``acq_rel``, and ``seq_cst`` orderings.
  6769. Semantics:
  6770. """"""""""
  6771. A fence A which has (at least) ``release`` ordering semantics
  6772. *synchronizes with* a fence B with (at least) ``acquire`` ordering
  6773. semantics if and only if there exist atomic operations X and Y, both
  6774. operating on some atomic object M, such that A is sequenced before X, X
  6775. modifies M (either directly or through some side effect of a sequence
  6776. headed by X), Y is sequenced before B, and Y observes M. This provides a
  6777. *happens-before* dependency between A and B. Rather than an explicit
  6778. ``fence``, one (but not both) of the atomic operations X or Y might
  6779. provide a ``release`` or ``acquire`` (resp.) ordering constraint and
  6780. still *synchronize-with* the explicit ``fence`` and establish the
  6781. *happens-before* edge.
  6782. A ``fence`` which has ``seq_cst`` ordering, in addition to having both
  6783. ``acquire`` and ``release`` semantics specified above, participates in
  6784. the global program order of other ``seq_cst`` operations and/or fences.
  6785. A ``fence`` instruction can also take an optional
  6786. ":ref:`syncscope <syncscope>`" argument.
  6787. Example:
  6788. """"""""
  6789. .. code-block:: text
  6790. fence acquire ; yields void
  6791. fence syncscope("singlethread") seq_cst ; yields void
  6792. fence syncscope("agent") seq_cst ; yields void
  6793. .. _i_cmpxchg:
  6794. '``cmpxchg``' Instruction
  6795. ^^^^^^^^^^^^^^^^^^^^^^^^^
  6796. Syntax:
  6797. """""""
  6798. ::
  6799. cmpxchg [weak] [volatile] <ty>* <pointer>, <ty> <cmp>, <ty> <new> [syncscope("<target-scope>")] <success ordering> <failure ordering> ; yields { ty, i1 }
  6800. Overview:
  6801. """""""""
  6802. The '``cmpxchg``' instruction is used to atomically modify memory. It
  6803. loads a value in memory and compares it to a given value. If they are
  6804. equal, it tries to store a new value into the memory.
  6805. Arguments:
  6806. """"""""""
  6807. There are three arguments to the '``cmpxchg``' instruction: an address
  6808. to operate on, a value to compare to the value currently be at that
  6809. address, and a new value to place at that address if the compared values
  6810. are equal. The type of '<cmp>' must be an integer or pointer type whose
  6811. bit width is a power of two greater than or equal to eight and less
  6812. than or equal to a target-specific size limit. '<cmp>' and '<new>' must
  6813. have the same type, and the type of '<pointer>' must be a pointer to
  6814. that type. If the ``cmpxchg`` is marked as ``volatile``, then the
  6815. optimizer is not allowed to modify the number or order of execution of
  6816. this ``cmpxchg`` with other :ref:`volatile operations <volatile>`.
  6817. The success and failure :ref:`ordering <ordering>` arguments specify how this
  6818. ``cmpxchg`` synchronizes with other atomic operations. Both ordering parameters
  6819. must be at least ``monotonic``, the ordering constraint on failure must be no
  6820. stronger than that on success, and the failure ordering cannot be either
  6821. ``release`` or ``acq_rel``.
  6822. A ``cmpxchg`` instruction can also take an optional
  6823. ":ref:`syncscope <syncscope>`" argument.
  6824. The pointer passed into cmpxchg must have alignment greater than or
  6825. equal to the size in memory of the operand.
  6826. Semantics:
  6827. """"""""""
  6828. The contents of memory at the location specified by the '``<pointer>``' operand
  6829. is read and compared to '``<cmp>``'; if the values are equal, '``<new>``' is
  6830. written to the location. The original value at the location is returned,
  6831. together with a flag indicating success (true) or failure (false).
  6832. If the cmpxchg operation is marked as ``weak`` then a spurious failure is
  6833. permitted: the operation may not write ``<new>`` even if the comparison
  6834. matched.
  6835. If the cmpxchg operation is strong (the default), the i1 value is 1 if and only
  6836. if the value loaded equals ``cmp``.
  6837. A successful ``cmpxchg`` is a read-modify-write instruction for the purpose of
  6838. identifying release sequences. A failed ``cmpxchg`` is equivalent to an atomic
  6839. load with an ordering parameter determined the second ordering parameter.
  6840. Example:
  6841. """"""""
  6842. .. code-block:: llvm
  6843. entry:
  6844. %orig = load atomic i32, i32* %ptr unordered, align 4 ; yields i32
  6845. br label %loop
  6846. loop:
  6847. %cmp = phi i32 [ %orig, %entry ], [%value_loaded, %loop]
  6848. %squared = mul i32 %cmp, %cmp
  6849. %val_success = cmpxchg i32* %ptr, i32 %cmp, i32 %squared acq_rel monotonic ; yields { i32, i1 }
  6850. %value_loaded = extractvalue { i32, i1 } %val_success, 0
  6851. %success = extractvalue { i32, i1 } %val_success, 1
  6852. br i1 %success, label %done, label %loop
  6853. done:
  6854. ...
  6855. .. _i_atomicrmw:
  6856. '``atomicrmw``' Instruction
  6857. ^^^^^^^^^^^^^^^^^^^^^^^^^^^
  6858. Syntax:
  6859. """""""
  6860. ::
  6861. atomicrmw [volatile] <operation> <ty>* <pointer>, <ty> <value> [syncscope("<target-scope>")] <ordering> ; yields ty
  6862. Overview:
  6863. """""""""
  6864. The '``atomicrmw``' instruction is used to atomically modify memory.
  6865. Arguments:
  6866. """"""""""
  6867. There are three arguments to the '``atomicrmw``' instruction: an
  6868. operation to apply, an address whose value to modify, an argument to the
  6869. operation. The operation must be one of the following keywords:
  6870. - xchg
  6871. - add
  6872. - sub
  6873. - and
  6874. - nand
  6875. - or
  6876. - xor
  6877. - max
  6878. - min
  6879. - umax
  6880. - umin
  6881. - fadd
  6882. - fsub
  6883. For most of these operations, the type of '<value>' must be an integer
  6884. type whose bit width is a power of two greater than or equal to eight
  6885. and less than or equal to a target-specific size limit. For xchg, this
  6886. may also be a floating point type with the same size constraints as
  6887. integers. For fadd/fsub, this must be a floating point type. The
  6888. type of the '``<pointer>``' operand must be a pointer to that type. If
  6889. the ``atomicrmw`` is marked as ``volatile``, then the optimizer is not
  6890. allowed to modify the number or order of execution of this
  6891. ``atomicrmw`` with other :ref:`volatile operations <volatile>`.
  6892. A ``atomicrmw`` instruction can also take an optional
  6893. ":ref:`syncscope <syncscope>`" argument.
  6894. Semantics:
  6895. """"""""""
  6896. The contents of memory at the location specified by the '``<pointer>``'
  6897. operand are atomically read, modified, and written back. The original
  6898. value at the location is returned. The modification is specified by the
  6899. operation argument:
  6900. - xchg: ``*ptr = val``
  6901. - add: ``*ptr = *ptr + val``
  6902. - sub: ``*ptr = *ptr - val``
  6903. - and: ``*ptr = *ptr & val``
  6904. - nand: ``*ptr = ~(*ptr & val)``
  6905. - or: ``*ptr = *ptr | val``
  6906. - xor: ``*ptr = *ptr ^ val``
  6907. - max: ``*ptr = *ptr > val ? *ptr : val`` (using a signed comparison)
  6908. - min: ``*ptr = *ptr < val ? *ptr : val`` (using a signed comparison)
  6909. - umax: ``*ptr = *ptr > val ? *ptr : val`` (using an unsigned
  6910. comparison)
  6911. - umin: ``*ptr = *ptr < val ? *ptr : val`` (using an unsigned
  6912. comparison)
  6913. - fadd: ``*ptr = *ptr + val`` (using floating point arithmetic)
  6914. - fsub: ``*ptr = *ptr - val`` (using floating point arithmetic)
  6915. Example:
  6916. """"""""
  6917. .. code-block:: llvm
  6918. %old = atomicrmw add i32* %ptr, i32 1 acquire ; yields i32
  6919. .. _i_getelementptr:
  6920. '``getelementptr``' Instruction
  6921. ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  6922. Syntax:
  6923. """""""
  6924. ::
  6925. <result> = getelementptr <ty>, <ty>* <ptrval>{, [inrange] <ty> <idx>}*
  6926. <result> = getelementptr inbounds <ty>, <ty>* <ptrval>{, [inrange] <ty> <idx>}*
  6927. <result> = getelementptr <ty>, <ptr vector> <ptrval>, [inrange] <vector index type> <idx>
  6928. Overview:
  6929. """""""""
  6930. The '``getelementptr``' instruction is used to get the address of a
  6931. subelement of an :ref:`aggregate <t_aggregate>` data structure. It performs
  6932. address calculation only and does not access memory. The instruction can also
  6933. be used to calculate a vector of such addresses.
  6934. Arguments:
  6935. """"""""""
  6936. The first argument is always a type used as the basis for the calculations.
  6937. The second argument is always a pointer or a vector of pointers, and is the
  6938. base address to start from. The remaining arguments are indices
  6939. that indicate which of the elements of the aggregate object are indexed.
  6940. The interpretation of each index is dependent on the type being indexed
  6941. into. The first index always indexes the pointer value given as the
  6942. second argument, the second index indexes a value of the type pointed to
  6943. (not necessarily the value directly pointed to, since the first index
  6944. can be non-zero), etc. The first type indexed into must be a pointer
  6945. value, subsequent types can be arrays, vectors, and structs. Note that
  6946. subsequent types being indexed into can never be pointers, since that
  6947. would require loading the pointer before continuing calculation.
  6948. The type of each index argument depends on the type it is indexing into.
  6949. When indexing into a (optionally packed) structure, only ``i32`` integer
  6950. **constants** are allowed (when using a vector of indices they must all
  6951. be the **same** ``i32`` integer constant). When indexing into an array,
  6952. pointer or vector, integers of any width are allowed, and they are not
  6953. required to be constant. These integers are treated as signed values
  6954. where relevant.
  6955. For example, let's consider a C code fragment and how it gets compiled
  6956. to LLVM:
  6957. .. code-block:: c
  6958. struct RT {
  6959. char A;
  6960. int B[10][20];
  6961. char C;
  6962. };
  6963. struct ST {
  6964. int X;
  6965. double Y;
  6966. struct RT Z;
  6967. };
  6968. int *foo(struct ST *s) {
  6969. return &s[1].Z.B[5][13];
  6970. }
  6971. The LLVM code generated by Clang is:
  6972. .. code-block:: llvm
  6973. %struct.RT = type { i8, [10 x [20 x i32]], i8 }
  6974. %struct.ST = type { i32, double, %struct.RT }
  6975. define i32* @foo(%struct.ST* %s) nounwind uwtable readnone optsize ssp {
  6976. entry:
  6977. %arrayidx = getelementptr inbounds %struct.ST, %struct.ST* %s, i64 1, i32 2, i32 1, i64 5, i64 13
  6978. ret i32* %arrayidx
  6979. }
  6980. Semantics:
  6981. """"""""""
  6982. In the example above, the first index is indexing into the
  6983. '``%struct.ST*``' type, which is a pointer, yielding a '``%struct.ST``'
  6984. = '``{ i32, double, %struct.RT }``' type, a structure. The second index
  6985. indexes into the third element of the structure, yielding a
  6986. '``%struct.RT``' = '``{ i8 , [10 x [20 x i32]], i8 }``' type, another
  6987. structure. The third index indexes into the second element of the
  6988. structure, yielding a '``[10 x [20 x i32]]``' type, an array. The two
  6989. dimensions of the array are subscripted into, yielding an '``i32``'
  6990. type. The '``getelementptr``' instruction returns a pointer to this
  6991. element, thus computing a value of '``i32*``' type.
  6992. Note that it is perfectly legal to index partially through a structure,
  6993. returning a pointer to an inner element. Because of this, the LLVM code
  6994. for the given testcase is equivalent to:
  6995. .. code-block:: llvm
  6996. define i32* @foo(%struct.ST* %s) {
  6997. %t1 = getelementptr %struct.ST, %struct.ST* %s, i32 1 ; yields %struct.ST*:%t1
  6998. %t2 = getelementptr %struct.ST, %struct.ST* %t1, i32 0, i32 2 ; yields %struct.RT*:%t2
  6999. %t3 = getelementptr %struct.RT, %struct.RT* %t2, i32 0, i32 1 ; yields [10 x [20 x i32]]*:%t3
  7000. %t4 = getelementptr [10 x [20 x i32]], [10 x [20 x i32]]* %t3, i32 0, i32 5 ; yields [20 x i32]*:%t4
  7001. %t5 = getelementptr [20 x i32], [20 x i32]* %t4, i32 0, i32 13 ; yields i32*:%t5
  7002. ret i32* %t5
  7003. }
  7004. If the ``inbounds`` keyword is present, the result value of the
  7005. ``getelementptr`` is a :ref:`poison value <poisonvalues>` if the base
  7006. pointer is not an *in bounds* address of an allocated object, or if any
  7007. of the addresses that would be formed by successive addition of the
  7008. offsets implied by the indices to the base address with infinitely
  7009. precise signed arithmetic are not an *in bounds* address of that
  7010. allocated object. The *in bounds* addresses for an allocated object are
  7011. all the addresses that point into the object, plus the address one byte
  7012. past the end. The only *in bounds* address for a null pointer in the
  7013. default address-space is the null pointer itself. In cases where the
  7014. base is a vector of pointers the ``inbounds`` keyword applies to each
  7015. of the computations element-wise.
  7016. If the ``inbounds`` keyword is not present, the offsets are added to the
  7017. base address with silently-wrapping two's complement arithmetic. If the
  7018. offsets have a different width from the pointer, they are sign-extended
  7019. or truncated to the width of the pointer. The result value of the
  7020. ``getelementptr`` may be outside the object pointed to by the base
  7021. pointer. The result value may not necessarily be used to access memory
  7022. though, even if it happens to point into allocated storage. See the
  7023. :ref:`Pointer Aliasing Rules <pointeraliasing>` section for more
  7024. information.
  7025. If the ``inrange`` keyword is present before any index, loading from or
  7026. storing to any pointer derived from the ``getelementptr`` has undefined
  7027. behavior if the load or store would access memory outside of the bounds of
  7028. the element selected by the index marked as ``inrange``. The result of a
  7029. pointer comparison or ``ptrtoint`` (including ``ptrtoint``-like operations
  7030. involving memory) involving a pointer derived from a ``getelementptr`` with
  7031. the ``inrange`` keyword is undefined, with the exception of comparisons
  7032. in the case where both operands are in the range of the element selected
  7033. by the ``inrange`` keyword, inclusive of the address one past the end of
  7034. that element. Note that the ``inrange`` keyword is currently only allowed
  7035. in constant ``getelementptr`` expressions.
  7036. The getelementptr instruction is often confusing. For some more insight
  7037. into how it works, see :doc:`the getelementptr FAQ <GetElementPtr>`.
  7038. Example:
  7039. """"""""
  7040. .. code-block:: llvm
  7041. ; yields [12 x i8]*:aptr
  7042. %aptr = getelementptr {i32, [12 x i8]}, {i32, [12 x i8]}* %saptr, i64 0, i32 1
  7043. ; yields i8*:vptr
  7044. %vptr = getelementptr {i32, <2 x i8>}, {i32, <2 x i8>}* %svptr, i64 0, i32 1, i32 1
  7045. ; yields i8*:eptr
  7046. %eptr = getelementptr [12 x i8], [12 x i8]* %aptr, i64 0, i32 1
  7047. ; yields i32*:iptr
  7048. %iptr = getelementptr [10 x i32], [10 x i32]* @arr, i16 0, i16 0
  7049. Vector of pointers:
  7050. """""""""""""""""""
  7051. The ``getelementptr`` returns a vector of pointers, instead of a single address,
  7052. when one or more of its arguments is a vector. In such cases, all vector
  7053. arguments should have the same number of elements, and every scalar argument
  7054. will be effectively broadcast into a vector during address calculation.
  7055. .. code-block:: llvm
  7056. ; All arguments are vectors:
  7057. ; A[i] = ptrs[i] + offsets[i]*sizeof(i8)
  7058. %A = getelementptr i8, <4 x i8*> %ptrs, <4 x i64> %offsets
  7059. ; Add the same scalar offset to each pointer of a vector:
  7060. ; A[i] = ptrs[i] + offset*sizeof(i8)
  7061. %A = getelementptr i8, <4 x i8*> %ptrs, i64 %offset
  7062. ; Add distinct offsets to the same pointer:
  7063. ; A[i] = ptr + offsets[i]*sizeof(i8)
  7064. %A = getelementptr i8, i8* %ptr, <4 x i64> %offsets
  7065. ; In all cases described above the type of the result is <4 x i8*>
  7066. The two following instructions are equivalent:
  7067. .. code-block:: llvm
  7068. getelementptr %struct.ST, <4 x %struct.ST*> %s, <4 x i64> %ind1,
  7069. <4 x i32> <i32 2, i32 2, i32 2, i32 2>,
  7070. <4 x i32> <i32 1, i32 1, i32 1, i32 1>,
  7071. <4 x i32> %ind4,
  7072. <4 x i64> <i64 13, i64 13, i64 13, i64 13>
  7073. getelementptr %struct.ST, <4 x %struct.ST*> %s, <4 x i64> %ind1,
  7074. i32 2, i32 1, <4 x i32> %ind4, i64 13
  7075. Let's look at the C code, where the vector version of ``getelementptr``
  7076. makes sense:
  7077. .. code-block:: c
  7078. // Let's assume that we vectorize the following loop:
  7079. double *A, *B; int *C;
  7080. for (int i = 0; i < size; ++i) {
  7081. A[i] = B[C[i]];
  7082. }
  7083. .. code-block:: llvm
  7084. ; get pointers for 8 elements from array B
  7085. %ptrs = getelementptr double, double* %B, <8 x i32> %C
  7086. ; load 8 elements from array B into A
  7087. %A = call <8 x double> @llvm.masked.gather.v8f64.v8p0f64(<8 x double*> %ptrs,
  7088. i32 8, <8 x i1> %mask, <8 x double> %passthru)
  7089. Conversion Operations
  7090. ---------------------
  7091. The instructions in this category are the conversion instructions
  7092. (casting) which all take a single operand and a type. They perform
  7093. various bit conversions on the operand.
  7094. .. _i_trunc:
  7095. '``trunc .. to``' Instruction
  7096. ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  7097. Syntax:
  7098. """""""
  7099. ::
  7100. <result> = trunc <ty> <value> to <ty2> ; yields ty2
  7101. Overview:
  7102. """""""""
  7103. The '``trunc``' instruction truncates its operand to the type ``ty2``.
  7104. Arguments:
  7105. """"""""""
  7106. The '``trunc``' instruction takes a value to trunc, and a type to trunc
  7107. it to. Both types must be of :ref:`integer <t_integer>` types, or vectors
  7108. of the same number of integers. The bit size of the ``value`` must be
  7109. larger than the bit size of the destination type, ``ty2``. Equal sized
  7110. types are not allowed.
  7111. Semantics:
  7112. """"""""""
  7113. The '``trunc``' instruction truncates the high order bits in ``value``
  7114. and converts the remaining bits to ``ty2``. Since the source size must
  7115. be larger than the destination size, ``trunc`` cannot be a *no-op cast*.
  7116. It will always truncate bits.
  7117. Example:
  7118. """"""""
  7119. .. code-block:: llvm
  7120. %X = trunc i32 257 to i8 ; yields i8:1
  7121. %Y = trunc i32 123 to i1 ; yields i1:true
  7122. %Z = trunc i32 122 to i1 ; yields i1:false
  7123. %W = trunc <2 x i16> <i16 8, i16 7> to <2 x i8> ; yields <i8 8, i8 7>
  7124. .. _i_zext:
  7125. '``zext .. to``' Instruction
  7126. ^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  7127. Syntax:
  7128. """""""
  7129. ::
  7130. <result> = zext <ty> <value> to <ty2> ; yields ty2
  7131. Overview:
  7132. """""""""
  7133. The '``zext``' instruction zero extends its operand to type ``ty2``.
  7134. Arguments:
  7135. """"""""""
  7136. The '``zext``' instruction takes a value to cast, and a type to cast it
  7137. to. Both types must be of :ref:`integer <t_integer>` types, or vectors of
  7138. the same number of integers. The bit size of the ``value`` must be
  7139. smaller than the bit size of the destination type, ``ty2``.
  7140. Semantics:
  7141. """"""""""
  7142. The ``zext`` fills the high order bits of the ``value`` with zero bits
  7143. until it reaches the size of the destination type, ``ty2``.
  7144. When zero extending from i1, the result will always be either 0 or 1.
  7145. Example:
  7146. """"""""
  7147. .. code-block:: llvm
  7148. %X = zext i32 257 to i64 ; yields i64:257
  7149. %Y = zext i1 true to i32 ; yields i32:1
  7150. %Z = zext <2 x i16> <i16 8, i16 7> to <2 x i32> ; yields <i32 8, i32 7>
  7151. .. _i_sext:
  7152. '``sext .. to``' Instruction
  7153. ^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  7154. Syntax:
  7155. """""""
  7156. ::
  7157. <result> = sext <ty> <value> to <ty2> ; yields ty2
  7158. Overview:
  7159. """""""""
  7160. The '``sext``' sign extends ``value`` to the type ``ty2``.
  7161. Arguments:
  7162. """"""""""
  7163. The '``sext``' instruction takes a value to cast, and a type to cast it
  7164. to. Both types must be of :ref:`integer <t_integer>` types, or vectors of
  7165. the same number of integers. The bit size of the ``value`` must be
  7166. smaller than the bit size of the destination type, ``ty2``.
  7167. Semantics:
  7168. """"""""""
  7169. The '``sext``' instruction performs a sign extension by copying the sign
  7170. bit (highest order bit) of the ``value`` until it reaches the bit size
  7171. of the type ``ty2``.
  7172. When sign extending from i1, the extension always results in -1 or 0.
  7173. Example:
  7174. """"""""
  7175. .. code-block:: llvm
  7176. %X = sext i8 -1 to i16 ; yields i16 :65535
  7177. %Y = sext i1 true to i32 ; yields i32:-1
  7178. %Z = sext <2 x i16> <i16 8, i16 7> to <2 x i32> ; yields <i32 8, i32 7>
  7179. '``fptrunc .. to``' Instruction
  7180. ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  7181. Syntax:
  7182. """""""
  7183. ::
  7184. <result> = fptrunc <ty> <value> to <ty2> ; yields ty2
  7185. Overview:
  7186. """""""""
  7187. The '``fptrunc``' instruction truncates ``value`` to type ``ty2``.
  7188. Arguments:
  7189. """"""""""
  7190. The '``fptrunc``' instruction takes a :ref:`floating-point <t_floating>`
  7191. value to cast and a :ref:`floating-point <t_floating>` type to cast it to.
  7192. The size of ``value`` must be larger than the size of ``ty2``. This
  7193. implies that ``fptrunc`` cannot be used to make a *no-op cast*.
  7194. Semantics:
  7195. """"""""""
  7196. The '``fptrunc``' instruction casts a ``value`` from a larger
  7197. :ref:`floating-point <t_floating>` type to a smaller :ref:`floating-point
  7198. <t_floating>` type.
  7199. This instruction is assumed to execute in the default :ref:`floating-point
  7200. environment <floatenv>`.
  7201. Example:
  7202. """"""""
  7203. .. code-block:: llvm
  7204. %X = fptrunc double 16777217.0 to float ; yields float:16777216.0
  7205. %Y = fptrunc double 1.0E+300 to half ; yields half:+infinity
  7206. '``fpext .. to``' Instruction
  7207. ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  7208. Syntax:
  7209. """""""
  7210. ::
  7211. <result> = fpext <ty> <value> to <ty2> ; yields ty2
  7212. Overview:
  7213. """""""""
  7214. The '``fpext``' extends a floating-point ``value`` to a larger floating-point
  7215. value.
  7216. Arguments:
  7217. """"""""""
  7218. The '``fpext``' instruction takes a :ref:`floating-point <t_floating>`
  7219. ``value`` to cast, and a :ref:`floating-point <t_floating>` type to cast it
  7220. to. The source type must be smaller than the destination type.
  7221. Semantics:
  7222. """"""""""
  7223. The '``fpext``' instruction extends the ``value`` from a smaller
  7224. :ref:`floating-point <t_floating>` type to a larger :ref:`floating-point
  7225. <t_floating>` type. The ``fpext`` cannot be used to make a
  7226. *no-op cast* because it always changes bits. Use ``bitcast`` to make a
  7227. *no-op cast* for a floating-point cast.
  7228. Example:
  7229. """"""""
  7230. .. code-block:: llvm
  7231. %X = fpext float 3.125 to double ; yields double:3.125000e+00
  7232. %Y = fpext double %X to fp128 ; yields fp128:0xL00000000000000004000900000000000
  7233. '``fptoui .. to``' Instruction
  7234. ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  7235. Syntax:
  7236. """""""
  7237. ::
  7238. <result> = fptoui <ty> <value> to <ty2> ; yields ty2
  7239. Overview:
  7240. """""""""
  7241. The '``fptoui``' converts a floating-point ``value`` to its unsigned
  7242. integer equivalent of type ``ty2``.
  7243. Arguments:
  7244. """"""""""
  7245. The '``fptoui``' instruction takes a value to cast, which must be a
  7246. scalar or vector :ref:`floating-point <t_floating>` value, and a type to
  7247. cast it to ``ty2``, which must be an :ref:`integer <t_integer>` type. If
  7248. ``ty`` is a vector floating-point type, ``ty2`` must be a vector integer
  7249. type with the same number of elements as ``ty``
  7250. Semantics:
  7251. """"""""""
  7252. The '``fptoui``' instruction converts its :ref:`floating-point
  7253. <t_floating>` operand into the nearest (rounding towards zero)
  7254. unsigned integer value. If the value cannot fit in ``ty2``, the result
  7255. is a :ref:`poison value <poisonvalues>`.
  7256. Example:
  7257. """"""""
  7258. .. code-block:: llvm
  7259. %X = fptoui double 123.0 to i32 ; yields i32:123
  7260. %Y = fptoui float 1.0E+300 to i1 ; yields undefined:1
  7261. %Z = fptoui float 1.04E+17 to i8 ; yields undefined:1
  7262. '``fptosi .. to``' Instruction
  7263. ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  7264. Syntax:
  7265. """""""
  7266. ::
  7267. <result> = fptosi <ty> <value> to <ty2> ; yields ty2
  7268. Overview:
  7269. """""""""
  7270. The '``fptosi``' instruction converts :ref:`floating-point <t_floating>`
  7271. ``value`` to type ``ty2``.
  7272. Arguments:
  7273. """"""""""
  7274. The '``fptosi``' instruction takes a value to cast, which must be a
  7275. scalar or vector :ref:`floating-point <t_floating>` value, and a type to
  7276. cast it to ``ty2``, which must be an :ref:`integer <t_integer>` type. If
  7277. ``ty`` is a vector floating-point type, ``ty2`` must be a vector integer
  7278. type with the same number of elements as ``ty``
  7279. Semantics:
  7280. """"""""""
  7281. The '``fptosi``' instruction converts its :ref:`floating-point
  7282. <t_floating>` operand into the nearest (rounding towards zero)
  7283. signed integer value. If the value cannot fit in ``ty2``, the result
  7284. is a :ref:`poison value <poisonvalues>`.
  7285. Example:
  7286. """"""""
  7287. .. code-block:: llvm
  7288. %X = fptosi double -123.0 to i32 ; yields i32:-123
  7289. %Y = fptosi float 1.0E-247 to i1 ; yields undefined:1
  7290. %Z = fptosi float 1.04E+17 to i8 ; yields undefined:1
  7291. '``uitofp .. to``' Instruction
  7292. ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  7293. Syntax:
  7294. """""""
  7295. ::
  7296. <result> = uitofp <ty> <value> to <ty2> ; yields ty2
  7297. Overview:
  7298. """""""""
  7299. The '``uitofp``' instruction regards ``value`` as an unsigned integer
  7300. and converts that value to the ``ty2`` type.
  7301. Arguments:
  7302. """"""""""
  7303. The '``uitofp``' instruction takes a value to cast, which must be a
  7304. scalar or vector :ref:`integer <t_integer>` value, and a type to cast it to
  7305. ``ty2``, which must be an :ref:`floating-point <t_floating>` type. If
  7306. ``ty`` is a vector integer type, ``ty2`` must be a vector floating-point
  7307. type with the same number of elements as ``ty``
  7308. Semantics:
  7309. """"""""""
  7310. The '``uitofp``' instruction interprets its operand as an unsigned
  7311. integer quantity and converts it to the corresponding floating-point
  7312. value. If the value cannot be exactly represented, it is rounded using
  7313. the default rounding mode.
  7314. Example:
  7315. """"""""
  7316. .. code-block:: llvm
  7317. %X = uitofp i32 257 to float ; yields float:257.0
  7318. %Y = uitofp i8 -1 to double ; yields double:255.0
  7319. '``sitofp .. to``' Instruction
  7320. ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  7321. Syntax:
  7322. """""""
  7323. ::
  7324. <result> = sitofp <ty> <value> to <ty2> ; yields ty2
  7325. Overview:
  7326. """""""""
  7327. The '``sitofp``' instruction regards ``value`` as a signed integer and
  7328. converts that value to the ``ty2`` type.
  7329. Arguments:
  7330. """"""""""
  7331. The '``sitofp``' instruction takes a value to cast, which must be a
  7332. scalar or vector :ref:`integer <t_integer>` value, and a type to cast it to
  7333. ``ty2``, which must be an :ref:`floating-point <t_floating>` type. If
  7334. ``ty`` is a vector integer type, ``ty2`` must be a vector floating-point
  7335. type with the same number of elements as ``ty``
  7336. Semantics:
  7337. """"""""""
  7338. The '``sitofp``' instruction interprets its operand as a signed integer
  7339. quantity and converts it to the corresponding floating-point value. If the
  7340. value cannot be exactly represented, it is rounded using the default rounding
  7341. mode.
  7342. Example:
  7343. """"""""
  7344. .. code-block:: llvm
  7345. %X = sitofp i32 257 to float ; yields float:257.0
  7346. %Y = sitofp i8 -1 to double ; yields double:-1.0
  7347. .. _i_ptrtoint:
  7348. '``ptrtoint .. to``' Instruction
  7349. ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  7350. Syntax:
  7351. """""""
  7352. ::
  7353. <result> = ptrtoint <ty> <value> to <ty2> ; yields ty2
  7354. Overview:
  7355. """""""""
  7356. The '``ptrtoint``' instruction converts the pointer or a vector of
  7357. pointers ``value`` to the integer (or vector of integers) type ``ty2``.
  7358. Arguments:
  7359. """"""""""
  7360. The '``ptrtoint``' instruction takes a ``value`` to cast, which must be
  7361. a value of type :ref:`pointer <t_pointer>` or a vector of pointers, and a
  7362. type to cast it to ``ty2``, which must be an :ref:`integer <t_integer>` or
  7363. a vector of integers type.
  7364. Semantics:
  7365. """"""""""
  7366. The '``ptrtoint``' instruction converts ``value`` to integer type
  7367. ``ty2`` by interpreting the pointer value as an integer and either
  7368. truncating or zero extending that value to the size of the integer type.
  7369. If ``value`` is smaller than ``ty2`` then a zero extension is done. If
  7370. ``value`` is larger than ``ty2`` then a truncation is done. If they are
  7371. the same size, then nothing is done (*no-op cast*) other than a type
  7372. change.
  7373. Example:
  7374. """"""""
  7375. .. code-block:: llvm
  7376. %X = ptrtoint i32* %P to i8 ; yields truncation on 32-bit architecture
  7377. %Y = ptrtoint i32* %P to i64 ; yields zero extension on 32-bit architecture
  7378. %Z = ptrtoint <4 x i32*> %P to <4 x i64>; yields vector zero extension for a vector of addresses on 32-bit architecture
  7379. .. _i_inttoptr:
  7380. '``inttoptr .. to``' Instruction
  7381. ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  7382. Syntax:
  7383. """""""
  7384. ::
  7385. <result> = inttoptr <ty> <value> to <ty2>[, !dereferenceable !<deref_bytes_node>][, !dereferenceable_or_null !<deref_bytes_node] ; yields ty2
  7386. Overview:
  7387. """""""""
  7388. The '``inttoptr``' instruction converts an integer ``value`` to a
  7389. pointer type, ``ty2``.
  7390. Arguments:
  7391. """"""""""
  7392. The '``inttoptr``' instruction takes an :ref:`integer <t_integer>` value to
  7393. cast, and a type to cast it to, which must be a :ref:`pointer <t_pointer>`
  7394. type.
  7395. The optional ``!dereferenceable`` metadata must reference a single metadata
  7396. name ``<deref_bytes_node>`` corresponding to a metadata node with one ``i64``
  7397. entry.
  7398. See ``dereferenceable`` metadata.
  7399. The optional ``!dereferenceable_or_null`` metadata must reference a single
  7400. metadata name ``<deref_bytes_node>`` corresponding to a metadata node with one
  7401. ``i64`` entry.
  7402. See ``dereferenceable_or_null`` metadata.
  7403. Semantics:
  7404. """"""""""
  7405. The '``inttoptr``' instruction converts ``value`` to type ``ty2`` by
  7406. applying either a zero extension or a truncation depending on the size
  7407. of the integer ``value``. If ``value`` is larger than the size of a
  7408. pointer then a truncation is done. If ``value`` is smaller than the size
  7409. of a pointer then a zero extension is done. If they are the same size,
  7410. nothing is done (*no-op cast*).
  7411. Example:
  7412. """"""""
  7413. .. code-block:: llvm
  7414. %X = inttoptr i32 255 to i32* ; yields zero extension on 64-bit architecture
  7415. %Y = inttoptr i32 255 to i32* ; yields no-op on 32-bit architecture
  7416. %Z = inttoptr i64 0 to i32* ; yields truncation on 32-bit architecture
  7417. %Z = inttoptr <4 x i32> %G to <4 x i8*>; yields truncation of vector G to four pointers
  7418. .. _i_bitcast:
  7419. '``bitcast .. to``' Instruction
  7420. ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  7421. Syntax:
  7422. """""""
  7423. ::
  7424. <result> = bitcast <ty> <value> to <ty2> ; yields ty2
  7425. Overview:
  7426. """""""""
  7427. The '``bitcast``' instruction converts ``value`` to type ``ty2`` without
  7428. changing any bits.
  7429. Arguments:
  7430. """"""""""
  7431. The '``bitcast``' instruction takes a value to cast, which must be a
  7432. non-aggregate first class value, and a type to cast it to, which must
  7433. also be a non-aggregate :ref:`first class <t_firstclass>` type. The
  7434. bit sizes of ``value`` and the destination type, ``ty2``, must be
  7435. identical. If the source type is a pointer, the destination type must
  7436. also be a pointer of the same size. This instruction supports bitwise
  7437. conversion of vectors to integers and to vectors of other types (as
  7438. long as they have the same size).
  7439. Semantics:
  7440. """"""""""
  7441. The '``bitcast``' instruction converts ``value`` to type ``ty2``. It
  7442. is always a *no-op cast* because no bits change with this
  7443. conversion. The conversion is done as if the ``value`` had been stored
  7444. to memory and read back as type ``ty2``. Pointer (or vector of
  7445. pointers) types may only be converted to other pointer (or vector of
  7446. pointers) types with the same address space through this instruction.
  7447. To convert pointers to other types, use the :ref:`inttoptr <i_inttoptr>`
  7448. or :ref:`ptrtoint <i_ptrtoint>` instructions first.
  7449. Example:
  7450. """"""""
  7451. .. code-block:: text
  7452. %X = bitcast i8 255 to i8 ; yields i8 :-1
  7453. %Y = bitcast i32* %x to sint* ; yields sint*:%x
  7454. %Z = bitcast <2 x int> %V to i64; ; yields i64: %V
  7455. %Z = bitcast <2 x i32*> %V to <2 x i64*> ; yields <2 x i64*>
  7456. .. _i_addrspacecast:
  7457. '``addrspacecast .. to``' Instruction
  7458. ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  7459. Syntax:
  7460. """""""
  7461. ::
  7462. <result> = addrspacecast <pty> <ptrval> to <pty2> ; yields pty2
  7463. Overview:
  7464. """""""""
  7465. The '``addrspacecast``' instruction converts ``ptrval`` from ``pty`` in
  7466. address space ``n`` to type ``pty2`` in address space ``m``.
  7467. Arguments:
  7468. """"""""""
  7469. The '``addrspacecast``' instruction takes a pointer or vector of pointer value
  7470. to cast and a pointer type to cast it to, which must have a different
  7471. address space.
  7472. Semantics:
  7473. """"""""""
  7474. The '``addrspacecast``' instruction converts the pointer value
  7475. ``ptrval`` to type ``pty2``. It can be a *no-op cast* or a complex
  7476. value modification, depending on the target and the address space
  7477. pair. Pointer conversions within the same address space must be
  7478. performed with the ``bitcast`` instruction. Note that if the address space
  7479. conversion is legal then both result and operand refer to the same memory
  7480. location.
  7481. Example:
  7482. """"""""
  7483. .. code-block:: llvm
  7484. %X = addrspacecast i32* %x to i32 addrspace(1)* ; yields i32 addrspace(1)*:%x
  7485. %Y = addrspacecast i32 addrspace(1)* %y to i64 addrspace(2)* ; yields i64 addrspace(2)*:%y
  7486. %Z = addrspacecast <4 x i32*> %z to <4 x float addrspace(3)*> ; yields <4 x float addrspace(3)*>:%z
  7487. .. _otherops:
  7488. Other Operations
  7489. ----------------
  7490. The instructions in this category are the "miscellaneous" instructions,
  7491. which defy better classification.
  7492. .. _i_icmp:
  7493. '``icmp``' Instruction
  7494. ^^^^^^^^^^^^^^^^^^^^^^
  7495. Syntax:
  7496. """""""
  7497. ::
  7498. <result> = icmp <cond> <ty> <op1>, <op2> ; yields i1 or <N x i1>:result
  7499. Overview:
  7500. """""""""
  7501. The '``icmp``' instruction returns a boolean value or a vector of
  7502. boolean values based on comparison of its two integer, integer vector,
  7503. pointer, or pointer vector operands.
  7504. Arguments:
  7505. """"""""""
  7506. The '``icmp``' instruction takes three operands. The first operand is
  7507. the condition code indicating the kind of comparison to perform. It is
  7508. not a value, just a keyword. The possible condition codes are:
  7509. #. ``eq``: equal
  7510. #. ``ne``: not equal
  7511. #. ``ugt``: unsigned greater than
  7512. #. ``uge``: unsigned greater or equal
  7513. #. ``ult``: unsigned less than
  7514. #. ``ule``: unsigned less or equal
  7515. #. ``sgt``: signed greater than
  7516. #. ``sge``: signed greater or equal
  7517. #. ``slt``: signed less than
  7518. #. ``sle``: signed less or equal
  7519. The remaining two arguments must be :ref:`integer <t_integer>` or
  7520. :ref:`pointer <t_pointer>` or integer :ref:`vector <t_vector>` typed. They
  7521. must also be identical types.
  7522. Semantics:
  7523. """"""""""
  7524. The '``icmp``' compares ``op1`` and ``op2`` according to the condition
  7525. code given as ``cond``. The comparison performed always yields either an
  7526. :ref:`i1 <t_integer>` or vector of ``i1`` result, as follows:
  7527. #. ``eq``: yields ``true`` if the operands are equal, ``false``
  7528. otherwise. No sign interpretation is necessary or performed.
  7529. #. ``ne``: yields ``true`` if the operands are unequal, ``false``
  7530. otherwise. No sign interpretation is necessary or performed.
  7531. #. ``ugt``: interprets the operands as unsigned values and yields
  7532. ``true`` if ``op1`` is greater than ``op2``.
  7533. #. ``uge``: interprets the operands as unsigned values and yields
  7534. ``true`` if ``op1`` is greater than or equal to ``op2``.
  7535. #. ``ult``: interprets the operands as unsigned values and yields
  7536. ``true`` if ``op1`` is less than ``op2``.
  7537. #. ``ule``: interprets the operands as unsigned values and yields
  7538. ``true`` if ``op1`` is less than or equal to ``op2``.
  7539. #. ``sgt``: interprets the operands as signed values and yields ``true``
  7540. if ``op1`` is greater than ``op2``.
  7541. #. ``sge``: interprets the operands as signed values and yields ``true``
  7542. if ``op1`` is greater than or equal to ``op2``.
  7543. #. ``slt``: interprets the operands as signed values and yields ``true``
  7544. if ``op1`` is less than ``op2``.
  7545. #. ``sle``: interprets the operands as signed values and yields ``true``
  7546. if ``op1`` is less than or equal to ``op2``.
  7547. If the operands are :ref:`pointer <t_pointer>` typed, the pointer values
  7548. are compared as if they were integers.
  7549. If the operands are integer vectors, then they are compared element by
  7550. element. The result is an ``i1`` vector with the same number of elements
  7551. as the values being compared. Otherwise, the result is an ``i1``.
  7552. Example:
  7553. """"""""
  7554. .. code-block:: text
  7555. <result> = icmp eq i32 4, 5 ; yields: result=false
  7556. <result> = icmp ne float* %X, %X ; yields: result=false
  7557. <result> = icmp ult i16 4, 5 ; yields: result=true
  7558. <result> = icmp sgt i16 4, 5 ; yields: result=false
  7559. <result> = icmp ule i16 -4, 5 ; yields: result=false
  7560. <result> = icmp sge i16 4, 5 ; yields: result=false
  7561. .. _i_fcmp:
  7562. '``fcmp``' Instruction
  7563. ^^^^^^^^^^^^^^^^^^^^^^
  7564. Syntax:
  7565. """""""
  7566. ::
  7567. <result> = fcmp [fast-math flags]* <cond> <ty> <op1>, <op2> ; yields i1 or <N x i1>:result
  7568. Overview:
  7569. """""""""
  7570. The '``fcmp``' instruction returns a boolean value or vector of boolean
  7571. values based on comparison of its operands.
  7572. If the operands are floating-point scalars, then the result type is a
  7573. boolean (:ref:`i1 <t_integer>`).
  7574. If the operands are floating-point vectors, then the result type is a
  7575. vector of boolean with the same number of elements as the operands being
  7576. compared.
  7577. Arguments:
  7578. """"""""""
  7579. The '``fcmp``' instruction takes three operands. The first operand is
  7580. the condition code indicating the kind of comparison to perform. It is
  7581. not a value, just a keyword. The possible condition codes are:
  7582. #. ``false``: no comparison, always returns false
  7583. #. ``oeq``: ordered and equal
  7584. #. ``ogt``: ordered and greater than
  7585. #. ``oge``: ordered and greater than or equal
  7586. #. ``olt``: ordered and less than
  7587. #. ``ole``: ordered and less than or equal
  7588. #. ``one``: ordered and not equal
  7589. #. ``ord``: ordered (no nans)
  7590. #. ``ueq``: unordered or equal
  7591. #. ``ugt``: unordered or greater than
  7592. #. ``uge``: unordered or greater than or equal
  7593. #. ``ult``: unordered or less than
  7594. #. ``ule``: unordered or less than or equal
  7595. #. ``une``: unordered or not equal
  7596. #. ``uno``: unordered (either nans)
  7597. #. ``true``: no comparison, always returns true
  7598. *Ordered* means that neither operand is a QNAN while *unordered* means
  7599. that either operand may be a QNAN.
  7600. Each of ``val1`` and ``val2`` arguments must be either a :ref:`floating-point
  7601. <t_floating>` type or a :ref:`vector <t_vector>` of floating-point type.
  7602. They must have identical types.
  7603. Semantics:
  7604. """"""""""
  7605. The '``fcmp``' instruction compares ``op1`` and ``op2`` according to the
  7606. condition code given as ``cond``. If the operands are vectors, then the
  7607. vectors are compared element by element. Each comparison performed
  7608. always yields an :ref:`i1 <t_integer>` result, as follows:
  7609. #. ``false``: always yields ``false``, regardless of operands.
  7610. #. ``oeq``: yields ``true`` if both operands are not a QNAN and ``op1``
  7611. is equal to ``op2``.
  7612. #. ``ogt``: yields ``true`` if both operands are not a QNAN and ``op1``
  7613. is greater than ``op2``.
  7614. #. ``oge``: yields ``true`` if both operands are not a QNAN and ``op1``
  7615. is greater than or equal to ``op2``.
  7616. #. ``olt``: yields ``true`` if both operands are not a QNAN and ``op1``
  7617. is less than ``op2``.
  7618. #. ``ole``: yields ``true`` if both operands are not a QNAN and ``op1``
  7619. is less than or equal to ``op2``.
  7620. #. ``one``: yields ``true`` if both operands are not a QNAN and ``op1``
  7621. is not equal to ``op2``.
  7622. #. ``ord``: yields ``true`` if both operands are not a QNAN.
  7623. #. ``ueq``: yields ``true`` if either operand is a QNAN or ``op1`` is
  7624. equal to ``op2``.
  7625. #. ``ugt``: yields ``true`` if either operand is a QNAN or ``op1`` is
  7626. greater than ``op2``.
  7627. #. ``uge``: yields ``true`` if either operand is a QNAN or ``op1`` is
  7628. greater than or equal to ``op2``.
  7629. #. ``ult``: yields ``true`` if either operand is a QNAN or ``op1`` is
  7630. less than ``op2``.
  7631. #. ``ule``: yields ``true`` if either operand is a QNAN or ``op1`` is
  7632. less than or equal to ``op2``.
  7633. #. ``une``: yields ``true`` if either operand is a QNAN or ``op1`` is
  7634. not equal to ``op2``.
  7635. #. ``uno``: yields ``true`` if either operand is a QNAN.
  7636. #. ``true``: always yields ``true``, regardless of operands.
  7637. The ``fcmp`` instruction can also optionally take any number of
  7638. :ref:`fast-math flags <fastmath>`, which are optimization hints to enable
  7639. otherwise unsafe floating-point optimizations.
  7640. Any set of fast-math flags are legal on an ``fcmp`` instruction, but the
  7641. only flags that have any effect on its semantics are those that allow
  7642. assumptions to be made about the values of input arguments; namely
  7643. ``nnan``, ``ninf``, and ``reassoc``. See :ref:`fastmath` for more information.
  7644. Example:
  7645. """"""""
  7646. .. code-block:: text
  7647. <result> = fcmp oeq float 4.0, 5.0 ; yields: result=false
  7648. <result> = fcmp one float 4.0, 5.0 ; yields: result=true
  7649. <result> = fcmp olt float 4.0, 5.0 ; yields: result=true
  7650. <result> = fcmp ueq double 1.0, 2.0 ; yields: result=false
  7651. .. _i_phi:
  7652. '``phi``' Instruction
  7653. ^^^^^^^^^^^^^^^^^^^^^
  7654. Syntax:
  7655. """""""
  7656. ::
  7657. <result> = phi [fast-math-flags] <ty> [ <val0>, <label0>], ...
  7658. Overview:
  7659. """""""""
  7660. The '``phi``' instruction is used to implement the φ node in the SSA
  7661. graph representing the function.
  7662. Arguments:
  7663. """"""""""
  7664. The type of the incoming values is specified with the first type field.
  7665. After this, the '``phi``' instruction takes a list of pairs as
  7666. arguments, with one pair for each predecessor basic block of the current
  7667. block. Only values of :ref:`first class <t_firstclass>` type may be used as
  7668. the value arguments to the PHI node. Only labels may be used as the
  7669. label arguments.
  7670. There must be no non-phi instructions between the start of a basic block
  7671. and the PHI instructions: i.e. PHI instructions must be first in a basic
  7672. block.
  7673. For the purposes of the SSA form, the use of each incoming value is
  7674. deemed to occur on the edge from the corresponding predecessor block to
  7675. the current block (but after any definition of an '``invoke``'
  7676. instruction's return value on the same edge).
  7677. The optional ``fast-math-flags`` marker indicates that the phi has one
  7678. or more :ref:`fast-math-flags <fastmath>`. These are optimization hints
  7679. to enable otherwise unsafe floating-point optimizations. Fast-math-flags
  7680. are only valid for phis that return a floating-point scalar or vector
  7681. type.
  7682. Semantics:
  7683. """"""""""
  7684. At runtime, the '``phi``' instruction logically takes on the value
  7685. specified by the pair corresponding to the predecessor basic block that
  7686. executed just prior to the current block.
  7687. Example:
  7688. """"""""
  7689. .. code-block:: llvm
  7690. Loop: ; Infinite loop that counts from 0 on up...
  7691. %indvar = phi i32 [ 0, %LoopHeader ], [ %nextindvar, %Loop ]
  7692. %nextindvar = add i32 %indvar, 1
  7693. br label %Loop
  7694. .. _i_select:
  7695. '``select``' Instruction
  7696. ^^^^^^^^^^^^^^^^^^^^^^^^
  7697. Syntax:
  7698. """""""
  7699. ::
  7700. <result> = select [fast-math flags] selty <cond>, <ty> <val1>, <ty> <val2> ; yields ty
  7701. selty is either i1 or {<N x i1>}
  7702. Overview:
  7703. """""""""
  7704. The '``select``' instruction is used to choose one value based on a
  7705. condition, without IR-level branching.
  7706. Arguments:
  7707. """"""""""
  7708. The '``select``' instruction requires an 'i1' value or a vector of 'i1'
  7709. values indicating the condition, and two values of the same :ref:`first
  7710. class <t_firstclass>` type.
  7711. #. The optional ``fast-math flags`` marker indicates that the select has one or more
  7712. :ref:`fast-math flags <fastmath>`. These are optimization hints to enable
  7713. otherwise unsafe floating-point optimizations. Fast-math flags are only valid
  7714. for selects that return a floating-point scalar or vector type.
  7715. Semantics:
  7716. """"""""""
  7717. If the condition is an i1 and it evaluates to 1, the instruction returns
  7718. the first value argument; otherwise, it returns the second value
  7719. argument.
  7720. If the condition is a vector of i1, then the value arguments must be
  7721. vectors of the same size, and the selection is done element by element.
  7722. If the condition is an i1 and the value arguments are vectors of the
  7723. same size, then an entire vector is selected.
  7724. Example:
  7725. """"""""
  7726. .. code-block:: llvm
  7727. %X = select i1 true, i8 17, i8 42 ; yields i8:17
  7728. .. _i_call:
  7729. '``call``' Instruction
  7730. ^^^^^^^^^^^^^^^^^^^^^^
  7731. Syntax:
  7732. """""""
  7733. ::
  7734. <result> = [tail | musttail | notail ] call [fast-math flags] [cconv] [ret attrs] [addrspace(<num>)]
  7735. <ty>|<fnty> <fnptrval>(<function args>) [fn attrs] [ operand bundles ]
  7736. Overview:
  7737. """""""""
  7738. The '``call``' instruction represents a simple function call.
  7739. Arguments:
  7740. """"""""""
  7741. This instruction requires several arguments:
  7742. #. The optional ``tail`` and ``musttail`` markers indicate that the optimizers
  7743. should perform tail call optimization. The ``tail`` marker is a hint that
  7744. `can be ignored <CodeGenerator.html#sibcallopt>`_. The ``musttail`` marker
  7745. means that the call must be tail call optimized in order for the program to
  7746. be correct. The ``musttail`` marker provides these guarantees:
  7747. #. The call will not cause unbounded stack growth if it is part of a
  7748. recursive cycle in the call graph.
  7749. #. Arguments with the :ref:`inalloca <attr_inalloca>` attribute are
  7750. forwarded in place.
  7751. #. If the musttail call appears in a function with the ``"thunk"`` attribute
  7752. and the caller and callee both have varargs, than any unprototyped
  7753. arguments in register or memory are forwarded to the callee. Similarly,
  7754. the return value of the callee is returned the the caller's caller, even
  7755. if a void return type is in use.
  7756. Both markers imply that the callee does not access allocas from the caller.
  7757. The ``tail`` marker additionally implies that the callee does not access
  7758. varargs from the caller. Calls marked ``musttail`` must obey the following
  7759. additional rules:
  7760. - The call must immediately precede a :ref:`ret <i_ret>` instruction,
  7761. or a pointer bitcast followed by a ret instruction.
  7762. - The ret instruction must return the (possibly bitcasted) value
  7763. produced by the call or void.
  7764. - The caller and callee prototypes must match. Pointer types of
  7765. parameters or return types may differ in pointee type, but not
  7766. in address space.
  7767. - The calling conventions of the caller and callee must match.
  7768. - All ABI-impacting function attributes, such as sret, byval, inreg,
  7769. returned, and inalloca, must match.
  7770. - The callee must be varargs iff the caller is varargs. Bitcasting a
  7771. non-varargs function to the appropriate varargs type is legal so
  7772. long as the non-varargs prefixes obey the other rules.
  7773. Tail call optimization for calls marked ``tail`` is guaranteed to occur if
  7774. the following conditions are met:
  7775. - Caller and callee both have the calling convention ``fastcc`` or ``tailcc``.
  7776. - The call is in tail position (ret immediately follows call and ret
  7777. uses value of call or is void).
  7778. - Option ``-tailcallopt`` is enabled,
  7779. ``llvm::GuaranteedTailCallOpt`` is ``true``, or the calling convention
  7780. is ``tailcc``
  7781. - `Platform-specific constraints are
  7782. met. <CodeGenerator.html#tailcallopt>`_
  7783. #. The optional ``notail`` marker indicates that the optimizers should not add
  7784. ``tail`` or ``musttail`` markers to the call. It is used to prevent tail
  7785. call optimization from being performed on the call.
  7786. #. The optional ``fast-math flags`` marker indicates that the call has one or more
  7787. :ref:`fast-math flags <fastmath>`, which are optimization hints to enable
  7788. otherwise unsafe floating-point optimizations. Fast-math flags are only valid
  7789. for calls that return a floating-point scalar or vector type.
  7790. #. The optional "cconv" marker indicates which :ref:`calling
  7791. convention <callingconv>` the call should use. If none is
  7792. specified, the call defaults to using C calling conventions. The
  7793. calling convention of the call must match the calling convention of
  7794. the target function, or else the behavior is undefined.
  7795. #. The optional :ref:`Parameter Attributes <paramattrs>` list for return
  7796. values. Only '``zeroext``', '``signext``', and '``inreg``' attributes
  7797. are valid here.
  7798. #. The optional addrspace attribute can be used to indicate the address space
  7799. of the called function. If it is not specified, the program address space
  7800. from the :ref:`datalayout string<langref_datalayout>` will be used.
  7801. #. '``ty``': the type of the call instruction itself which is also the
  7802. type of the return value. Functions that return no value are marked
  7803. ``void``.
  7804. #. '``fnty``': shall be the signature of the function being called. The
  7805. argument types must match the types implied by this signature. This
  7806. type can be omitted if the function is not varargs.
  7807. #. '``fnptrval``': An LLVM value containing a pointer to a function to
  7808. be called. In most cases, this is a direct function call, but
  7809. indirect ``call``'s are just as possible, calling an arbitrary pointer
  7810. to function value.
  7811. #. '``function args``': argument list whose types match the function
  7812. signature argument types and parameter attributes. All arguments must
  7813. be of :ref:`first class <t_firstclass>` type. If the function signature
  7814. indicates the function accepts a variable number of arguments, the
  7815. extra arguments can be specified.
  7816. #. The optional :ref:`function attributes <fnattrs>` list.
  7817. #. The optional :ref:`operand bundles <opbundles>` list.
  7818. Semantics:
  7819. """"""""""
  7820. The '``call``' instruction is used to cause control flow to transfer to
  7821. a specified function, with its incoming arguments bound to the specified
  7822. values. Upon a '``ret``' instruction in the called function, control
  7823. flow continues with the instruction after the function call, and the
  7824. return value of the function is bound to the result argument.
  7825. Example:
  7826. """"""""
  7827. .. code-block:: llvm
  7828. %retval = call i32 @test(i32 %argc)
  7829. call i32 (i8*, ...)* @printf(i8* %msg, i32 12, i8 42) ; yields i32
  7830. %X = tail call i32 @foo() ; yields i32
  7831. %Y = tail call fastcc i32 @foo() ; yields i32
  7832. call void %foo(i8 97 signext)
  7833. %struct.A = type { i32, i8 }
  7834. %r = call %struct.A @foo() ; yields { i32, i8 }
  7835. %gr = extractvalue %struct.A %r, 0 ; yields i32
  7836. %gr1 = extractvalue %struct.A %r, 1 ; yields i8
  7837. %Z = call void @foo() noreturn ; indicates that %foo never returns normally
  7838. %ZZ = call zeroext i32 @bar() ; Return value is %zero extended
  7839. llvm treats calls to some functions with names and arguments that match
  7840. the standard C99 library as being the C99 library functions, and may
  7841. perform optimizations or generate code for them under that assumption.
  7842. This is something we'd like to change in the future to provide better
  7843. support for freestanding environments and non-C-based languages.
  7844. .. _i_va_arg:
  7845. '``va_arg``' Instruction
  7846. ^^^^^^^^^^^^^^^^^^^^^^^^
  7847. Syntax:
  7848. """""""
  7849. ::
  7850. <resultval> = va_arg <va_list*> <arglist>, <argty>
  7851. Overview:
  7852. """""""""
  7853. The '``va_arg``' instruction is used to access arguments passed through
  7854. the "variable argument" area of a function call. It is used to implement
  7855. the ``va_arg`` macro in C.
  7856. Arguments:
  7857. """"""""""
  7858. This instruction takes a ``va_list*`` value and the type of the
  7859. argument. It returns a value of the specified argument type and
  7860. increments the ``va_list`` to point to the next argument. The actual
  7861. type of ``va_list`` is target specific.
  7862. Semantics:
  7863. """"""""""
  7864. The '``va_arg``' instruction loads an argument of the specified type
  7865. from the specified ``va_list`` and causes the ``va_list`` to point to
  7866. the next argument. For more information, see the variable argument
  7867. handling :ref:`Intrinsic Functions <int_varargs>`.
  7868. It is legal for this instruction to be called in a function which does
  7869. not take a variable number of arguments, for example, the ``vfprintf``
  7870. function.
  7871. ``va_arg`` is an LLVM instruction instead of an :ref:`intrinsic
  7872. function <intrinsics>` because it takes a type as an argument.
  7873. Example:
  7874. """"""""
  7875. See the :ref:`variable argument processing <int_varargs>` section.
  7876. Note that the code generator does not yet fully support va\_arg on many
  7877. targets. Also, it does not currently support va\_arg with aggregate
  7878. types on any target.
  7879. .. _i_landingpad:
  7880. '``landingpad``' Instruction
  7881. ^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  7882. Syntax:
  7883. """""""
  7884. ::
  7885. <resultval> = landingpad <resultty> <clause>+
  7886. <resultval> = landingpad <resultty> cleanup <clause>*
  7887. <clause> := catch <type> <value>
  7888. <clause> := filter <array constant type> <array constant>
  7889. Overview:
  7890. """""""""
  7891. The '``landingpad``' instruction is used by `LLVM's exception handling
  7892. system <ExceptionHandling.html#overview>`_ to specify that a basic block
  7893. is a landing pad --- one where the exception lands, and corresponds to the
  7894. code found in the ``catch`` portion of a ``try``/``catch`` sequence. It
  7895. defines values supplied by the :ref:`personality function <personalityfn>` upon
  7896. re-entry to the function. The ``resultval`` has the type ``resultty``.
  7897. Arguments:
  7898. """"""""""
  7899. The optional
  7900. ``cleanup`` flag indicates that the landing pad block is a cleanup.
  7901. A ``clause`` begins with the clause type --- ``catch`` or ``filter`` --- and
  7902. contains the global variable representing the "type" that may be caught
  7903. or filtered respectively. Unlike the ``catch`` clause, the ``filter``
  7904. clause takes an array constant as its argument. Use
  7905. "``[0 x i8**] undef``" for a filter which cannot throw. The
  7906. '``landingpad``' instruction must contain *at least* one ``clause`` or
  7907. the ``cleanup`` flag.
  7908. Semantics:
  7909. """"""""""
  7910. The '``landingpad``' instruction defines the values which are set by the
  7911. :ref:`personality function <personalityfn>` upon re-entry to the function, and
  7912. therefore the "result type" of the ``landingpad`` instruction. As with
  7913. calling conventions, how the personality function results are
  7914. represented in LLVM IR is target specific.
  7915. The clauses are applied in order from top to bottom. If two
  7916. ``landingpad`` instructions are merged together through inlining, the
  7917. clauses from the calling function are appended to the list of clauses.
  7918. When the call stack is being unwound due to an exception being thrown,
  7919. the exception is compared against each ``clause`` in turn. If it doesn't
  7920. match any of the clauses, and the ``cleanup`` flag is not set, then
  7921. unwinding continues further up the call stack.
  7922. The ``landingpad`` instruction has several restrictions:
  7923. - A landing pad block is a basic block which is the unwind destination
  7924. of an '``invoke``' instruction.
  7925. - A landing pad block must have a '``landingpad``' instruction as its
  7926. first non-PHI instruction.
  7927. - There can be only one '``landingpad``' instruction within the landing
  7928. pad block.
  7929. - A basic block that is not a landing pad block may not include a
  7930. '``landingpad``' instruction.
  7931. Example:
  7932. """"""""
  7933. .. code-block:: llvm
  7934. ;; A landing pad which can catch an integer.
  7935. %res = landingpad { i8*, i32 }
  7936. catch i8** @_ZTIi
  7937. ;; A landing pad that is a cleanup.
  7938. %res = landingpad { i8*, i32 }
  7939. cleanup
  7940. ;; A landing pad which can catch an integer and can only throw a double.
  7941. %res = landingpad { i8*, i32 }
  7942. catch i8** @_ZTIi
  7943. filter [1 x i8**] [@_ZTId]
  7944. .. _i_catchpad:
  7945. '``catchpad``' Instruction
  7946. ^^^^^^^^^^^^^^^^^^^^^^^^^^
  7947. Syntax:
  7948. """""""
  7949. ::
  7950. <resultval> = catchpad within <catchswitch> [<args>*]
  7951. Overview:
  7952. """""""""
  7953. The '``catchpad``' instruction is used by `LLVM's exception handling
  7954. system <ExceptionHandling.html#overview>`_ to specify that a basic block
  7955. begins a catch handler --- one where a personality routine attempts to transfer
  7956. control to catch an exception.
  7957. Arguments:
  7958. """"""""""
  7959. The ``catchswitch`` operand must always be a token produced by a
  7960. :ref:`catchswitch <i_catchswitch>` instruction in a predecessor block. This
  7961. ensures that each ``catchpad`` has exactly one predecessor block, and it always
  7962. terminates in a ``catchswitch``.
  7963. The ``args`` correspond to whatever information the personality routine
  7964. requires to know if this is an appropriate handler for the exception. Control
  7965. will transfer to the ``catchpad`` if this is the first appropriate handler for
  7966. the exception.
  7967. The ``resultval`` has the type :ref:`token <t_token>` and is used to match the
  7968. ``catchpad`` to corresponding :ref:`catchrets <i_catchret>` and other nested EH
  7969. pads.
  7970. Semantics:
  7971. """"""""""
  7972. When the call stack is being unwound due to an exception being thrown, the
  7973. exception is compared against the ``args``. If it doesn't match, control will
  7974. not reach the ``catchpad`` instruction. The representation of ``args`` is
  7975. entirely target and personality function-specific.
  7976. Like the :ref:`landingpad <i_landingpad>` instruction, the ``catchpad``
  7977. instruction must be the first non-phi of its parent basic block.
  7978. The meaning of the tokens produced and consumed by ``catchpad`` and other "pad"
  7979. instructions is described in the
  7980. `Windows exception handling documentation\ <ExceptionHandling.html#wineh>`_.
  7981. When a ``catchpad`` has been "entered" but not yet "exited" (as
  7982. described in the `EH documentation\ <ExceptionHandling.html#wineh-constraints>`_),
  7983. it is undefined behavior to execute a :ref:`call <i_call>` or :ref:`invoke <i_invoke>`
  7984. that does not carry an appropriate :ref:`"funclet" bundle <ob_funclet>`.
  7985. Example:
  7986. """"""""
  7987. .. code-block:: text
  7988. dispatch:
  7989. %cs = catchswitch within none [label %handler0] unwind to caller
  7990. ;; A catch block which can catch an integer.
  7991. handler0:
  7992. %tok = catchpad within %cs [i8** @_ZTIi]
  7993. .. _i_cleanuppad:
  7994. '``cleanuppad``' Instruction
  7995. ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  7996. Syntax:
  7997. """""""
  7998. ::
  7999. <resultval> = cleanuppad within <parent> [<args>*]
  8000. Overview:
  8001. """""""""
  8002. The '``cleanuppad``' instruction is used by `LLVM's exception handling
  8003. system <ExceptionHandling.html#overview>`_ to specify that a basic block
  8004. is a cleanup block --- one where a personality routine attempts to
  8005. transfer control to run cleanup actions.
  8006. The ``args`` correspond to whatever additional
  8007. information the :ref:`personality function <personalityfn>` requires to
  8008. execute the cleanup.
  8009. The ``resultval`` has the type :ref:`token <t_token>` and is used to
  8010. match the ``cleanuppad`` to corresponding :ref:`cleanuprets <i_cleanupret>`.
  8011. The ``parent`` argument is the token of the funclet that contains the
  8012. ``cleanuppad`` instruction. If the ``cleanuppad`` is not inside a funclet,
  8013. this operand may be the token ``none``.
  8014. Arguments:
  8015. """"""""""
  8016. The instruction takes a list of arbitrary values which are interpreted
  8017. by the :ref:`personality function <personalityfn>`.
  8018. Semantics:
  8019. """"""""""
  8020. When the call stack is being unwound due to an exception being thrown,
  8021. the :ref:`personality function <personalityfn>` transfers control to the
  8022. ``cleanuppad`` with the aid of the personality-specific arguments.
  8023. As with calling conventions, how the personality function results are
  8024. represented in LLVM IR is target specific.
  8025. The ``cleanuppad`` instruction has several restrictions:
  8026. - A cleanup block is a basic block which is the unwind destination of
  8027. an exceptional instruction.
  8028. - A cleanup block must have a '``cleanuppad``' instruction as its
  8029. first non-PHI instruction.
  8030. - There can be only one '``cleanuppad``' instruction within the
  8031. cleanup block.
  8032. - A basic block that is not a cleanup block may not include a
  8033. '``cleanuppad``' instruction.
  8034. When a ``cleanuppad`` has been "entered" but not yet "exited" (as
  8035. described in the `EH documentation\ <ExceptionHandling.html#wineh-constraints>`_),
  8036. it is undefined behavior to execute a :ref:`call <i_call>` or :ref:`invoke <i_invoke>`
  8037. that does not carry an appropriate :ref:`"funclet" bundle <ob_funclet>`.
  8038. Example:
  8039. """"""""
  8040. .. code-block:: text
  8041. %tok = cleanuppad within %cs []
  8042. .. _intrinsics:
  8043. Intrinsic Functions
  8044. ===================
  8045. LLVM supports the notion of an "intrinsic function". These functions
  8046. have well known names and semantics and are required to follow certain
  8047. restrictions. Overall, these intrinsics represent an extension mechanism
  8048. for the LLVM language that does not require changing all of the
  8049. transformations in LLVM when adding to the language (or the bitcode
  8050. reader/writer, the parser, etc...).
  8051. Intrinsic function names must all start with an "``llvm.``" prefix. This
  8052. prefix is reserved in LLVM for intrinsic names; thus, function names may
  8053. not begin with this prefix. Intrinsic functions must always be external
  8054. functions: you cannot define the body of intrinsic functions. Intrinsic
  8055. functions may only be used in call or invoke instructions: it is illegal
  8056. to take the address of an intrinsic function. Additionally, because
  8057. intrinsic functions are part of the LLVM language, it is required if any
  8058. are added that they be documented here.
  8059. Some intrinsic functions can be overloaded, i.e., the intrinsic
  8060. represents a family of functions that perform the same operation but on
  8061. different data types. Because LLVM can represent over 8 million
  8062. different integer types, overloading is used commonly to allow an
  8063. intrinsic function to operate on any integer type. One or more of the
  8064. argument types or the result type can be overloaded to accept any
  8065. integer type. Argument types may also be defined as exactly matching a
  8066. previous argument's type or the result type. This allows an intrinsic
  8067. function which accepts multiple arguments, but needs all of them to be
  8068. of the same type, to only be overloaded with respect to a single
  8069. argument or the result.
  8070. Overloaded intrinsics will have the names of its overloaded argument
  8071. types encoded into its function name, each preceded by a period. Only
  8072. those types which are overloaded result in a name suffix. Arguments
  8073. whose type is matched against another type do not. For example, the
  8074. ``llvm.ctpop`` function can take an integer of any width and returns an
  8075. integer of exactly the same integer width. This leads to a family of
  8076. functions such as ``i8 @llvm.ctpop.i8(i8 %val)`` and
  8077. ``i29 @llvm.ctpop.i29(i29 %val)``. Only one type, the return type, is
  8078. overloaded, and only one type suffix is required. Because the argument's
  8079. type is matched against the return type, it does not require its own
  8080. name suffix.
  8081. For target developers who are defining intrinsics for back-end code
  8082. generation, any intrinsic overloads based solely the distinction between
  8083. integer or floating point types should not be relied upon for correct
  8084. code generation. In such cases, the recommended approach for target
  8085. maintainers when defining intrinsics is to create separate integer and
  8086. FP intrinsics rather than rely on overloading. For example, if different
  8087. codegen is required for ``llvm.target.foo(<4 x i32>)`` and
  8088. ``llvm.target.foo(<4 x float>)`` then these should be split into
  8089. different intrinsics.
  8090. To learn how to add an intrinsic function, please see the `Extending
  8091. LLVM Guide <ExtendingLLVM.html>`_.
  8092. .. _int_varargs:
  8093. Variable Argument Handling Intrinsics
  8094. -------------------------------------
  8095. Variable argument support is defined in LLVM with the
  8096. :ref:`va_arg <i_va_arg>` instruction and these three intrinsic
  8097. functions. These functions are related to the similarly named macros
  8098. defined in the ``<stdarg.h>`` header file.
  8099. All of these functions operate on arguments that use a target-specific
  8100. value type "``va_list``". The LLVM assembly language reference manual
  8101. does not define what this type is, so all transformations should be
  8102. prepared to handle these functions regardless of the type used.
  8103. This example shows how the :ref:`va_arg <i_va_arg>` instruction and the
  8104. variable argument handling intrinsic functions are used.
  8105. .. code-block:: llvm
  8106. ; This struct is different for every platform. For most platforms,
  8107. ; it is merely an i8*.
  8108. %struct.va_list = type { i8* }
  8109. ; For Unix x86_64 platforms, va_list is the following struct:
  8110. ; %struct.va_list = type { i32, i32, i8*, i8* }
  8111. define i32 @test(i32 %X, ...) {
  8112. ; Initialize variable argument processing
  8113. %ap = alloca %struct.va_list
  8114. %ap2 = bitcast %struct.va_list* %ap to i8*
  8115. call void @llvm.va_start(i8* %ap2)
  8116. ; Read a single integer argument
  8117. %tmp = va_arg i8* %ap2, i32
  8118. ; Demonstrate usage of llvm.va_copy and llvm.va_end
  8119. %aq = alloca i8*
  8120. %aq2 = bitcast i8** %aq to i8*
  8121. call void @llvm.va_copy(i8* %aq2, i8* %ap2)
  8122. call void @llvm.va_end(i8* %aq2)
  8123. ; Stop processing of arguments.
  8124. call void @llvm.va_end(i8* %ap2)
  8125. ret i32 %tmp
  8126. }
  8127. declare void @llvm.va_start(i8*)
  8128. declare void @llvm.va_copy(i8*, i8*)
  8129. declare void @llvm.va_end(i8*)
  8130. .. _int_va_start:
  8131. '``llvm.va_start``' Intrinsic
  8132. ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  8133. Syntax:
  8134. """""""
  8135. ::
  8136. declare void @llvm.va_start(i8* <arglist>)
  8137. Overview:
  8138. """""""""
  8139. The '``llvm.va_start``' intrinsic initializes ``*<arglist>`` for
  8140. subsequent use by ``va_arg``.
  8141. Arguments:
  8142. """"""""""
  8143. The argument is a pointer to a ``va_list`` element to initialize.
  8144. Semantics:
  8145. """"""""""
  8146. The '``llvm.va_start``' intrinsic works just like the ``va_start`` macro
  8147. available in C. In a target-dependent way, it initializes the
  8148. ``va_list`` element to which the argument points, so that the next call
  8149. to ``va_arg`` will produce the first variable argument passed to the
  8150. function. Unlike the C ``va_start`` macro, this intrinsic does not need
  8151. to know the last argument of the function as the compiler can figure
  8152. that out.
  8153. '``llvm.va_end``' Intrinsic
  8154. ^^^^^^^^^^^^^^^^^^^^^^^^^^^
  8155. Syntax:
  8156. """""""
  8157. ::
  8158. declare void @llvm.va_end(i8* <arglist>)
  8159. Overview:
  8160. """""""""
  8161. The '``llvm.va_end``' intrinsic destroys ``*<arglist>``, which has been
  8162. initialized previously with ``llvm.va_start`` or ``llvm.va_copy``.
  8163. Arguments:
  8164. """"""""""
  8165. The argument is a pointer to a ``va_list`` to destroy.
  8166. Semantics:
  8167. """"""""""
  8168. The '``llvm.va_end``' intrinsic works just like the ``va_end`` macro
  8169. available in C. In a target-dependent way, it destroys the ``va_list``
  8170. element to which the argument points. Calls to
  8171. :ref:`llvm.va_start <int_va_start>` and
  8172. :ref:`llvm.va_copy <int_va_copy>` must be matched exactly with calls to
  8173. ``llvm.va_end``.
  8174. .. _int_va_copy:
  8175. '``llvm.va_copy``' Intrinsic
  8176. ^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  8177. Syntax:
  8178. """""""
  8179. ::
  8180. declare void @llvm.va_copy(i8* <destarglist>, i8* <srcarglist>)
  8181. Overview:
  8182. """""""""
  8183. The '``llvm.va_copy``' intrinsic copies the current argument position
  8184. from the source argument list to the destination argument list.
  8185. Arguments:
  8186. """"""""""
  8187. The first argument is a pointer to a ``va_list`` element to initialize.
  8188. The second argument is a pointer to a ``va_list`` element to copy from.
  8189. Semantics:
  8190. """"""""""
  8191. The '``llvm.va_copy``' intrinsic works just like the ``va_copy`` macro
  8192. available in C. In a target-dependent way, it copies the source
  8193. ``va_list`` element into the destination ``va_list`` element. This
  8194. intrinsic is necessary because the `` llvm.va_start`` intrinsic may be
  8195. arbitrarily complex and require, for example, memory allocation.
  8196. Accurate Garbage Collection Intrinsics
  8197. --------------------------------------
  8198. LLVM's support for `Accurate Garbage Collection <GarbageCollection.html>`_
  8199. (GC) requires the frontend to generate code containing appropriate intrinsic
  8200. calls and select an appropriate GC strategy which knows how to lower these
  8201. intrinsics in a manner which is appropriate for the target collector.
  8202. These intrinsics allow identification of :ref:`GC roots on the
  8203. stack <int_gcroot>`, as well as garbage collector implementations that
  8204. require :ref:`read <int_gcread>` and :ref:`write <int_gcwrite>` barriers.
  8205. Frontends for type-safe garbage collected languages should generate
  8206. these intrinsics to make use of the LLVM garbage collectors. For more
  8207. details, see `Garbage Collection with LLVM <GarbageCollection.html>`_.
  8208. Experimental Statepoint Intrinsics
  8209. ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  8210. LLVM provides an second experimental set of intrinsics for describing garbage
  8211. collection safepoints in compiled code. These intrinsics are an alternative
  8212. to the ``llvm.gcroot`` intrinsics, but are compatible with the ones for
  8213. :ref:`read <int_gcread>` and :ref:`write <int_gcwrite>` barriers. The
  8214. differences in approach are covered in the `Garbage Collection with LLVM
  8215. <GarbageCollection.html>`_ documentation. The intrinsics themselves are
  8216. described in :doc:`Statepoints`.
  8217. .. _int_gcroot:
  8218. '``llvm.gcroot``' Intrinsic
  8219. ^^^^^^^^^^^^^^^^^^^^^^^^^^^
  8220. Syntax:
  8221. """""""
  8222. ::
  8223. declare void @llvm.gcroot(i8** %ptrloc, i8* %metadata)
  8224. Overview:
  8225. """""""""
  8226. The '``llvm.gcroot``' intrinsic declares the existence of a GC root to
  8227. the code generator, and allows some metadata to be associated with it.
  8228. Arguments:
  8229. """"""""""
  8230. The first argument specifies the address of a stack object that contains
  8231. the root pointer. The second pointer (which must be either a constant or
  8232. a global value address) contains the meta-data to be associated with the
  8233. root.
  8234. Semantics:
  8235. """"""""""
  8236. At runtime, a call to this intrinsic stores a null pointer into the
  8237. "ptrloc" location. At compile-time, the code generator generates
  8238. information to allow the runtime to find the pointer at GC safe points.
  8239. The '``llvm.gcroot``' intrinsic may only be used in a function which
  8240. :ref:`specifies a GC algorithm <gc>`.
  8241. .. _int_gcread:
  8242. '``llvm.gcread``' Intrinsic
  8243. ^^^^^^^^^^^^^^^^^^^^^^^^^^^
  8244. Syntax:
  8245. """""""
  8246. ::
  8247. declare i8* @llvm.gcread(i8* %ObjPtr, i8** %Ptr)
  8248. Overview:
  8249. """""""""
  8250. The '``llvm.gcread``' intrinsic identifies reads of references from heap
  8251. locations, allowing garbage collector implementations that require read
  8252. barriers.
  8253. Arguments:
  8254. """"""""""
  8255. The second argument is the address to read from, which should be an
  8256. address allocated from the garbage collector. The first object is a
  8257. pointer to the start of the referenced object, if needed by the language
  8258. runtime (otherwise null).
  8259. Semantics:
  8260. """"""""""
  8261. The '``llvm.gcread``' intrinsic has the same semantics as a load
  8262. instruction, but may be replaced with substantially more complex code by
  8263. the garbage collector runtime, as needed. The '``llvm.gcread``'
  8264. intrinsic may only be used in a function which :ref:`specifies a GC
  8265. algorithm <gc>`.
  8266. .. _int_gcwrite:
  8267. '``llvm.gcwrite``' Intrinsic
  8268. ^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  8269. Syntax:
  8270. """""""
  8271. ::
  8272. declare void @llvm.gcwrite(i8* %P1, i8* %Obj, i8** %P2)
  8273. Overview:
  8274. """""""""
  8275. The '``llvm.gcwrite``' intrinsic identifies writes of references to heap
  8276. locations, allowing garbage collector implementations that require write
  8277. barriers (such as generational or reference counting collectors).
  8278. Arguments:
  8279. """"""""""
  8280. The first argument is the reference to store, the second is the start of
  8281. the object to store it to, and the third is the address of the field of
  8282. Obj to store to. If the runtime does not require a pointer to the
  8283. object, Obj may be null.
  8284. Semantics:
  8285. """"""""""
  8286. The '``llvm.gcwrite``' intrinsic has the same semantics as a store
  8287. instruction, but may be replaced with substantially more complex code by
  8288. the garbage collector runtime, as needed. The '``llvm.gcwrite``'
  8289. intrinsic may only be used in a function which :ref:`specifies a GC
  8290. algorithm <gc>`.
  8291. Code Generator Intrinsics
  8292. -------------------------
  8293. These intrinsics are provided by LLVM to expose special features that
  8294. may only be implemented with code generator support.
  8295. '``llvm.returnaddress``' Intrinsic
  8296. ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  8297. Syntax:
  8298. """""""
  8299. ::
  8300. declare i8* @llvm.returnaddress(i32 <level>)
  8301. Overview:
  8302. """""""""
  8303. The '``llvm.returnaddress``' intrinsic attempts to compute a
  8304. target-specific value indicating the return address of the current
  8305. function or one of its callers.
  8306. Arguments:
  8307. """"""""""
  8308. The argument to this intrinsic indicates which function to return the
  8309. address for. Zero indicates the calling function, one indicates its
  8310. caller, etc. The argument is **required** to be a constant integer
  8311. value.
  8312. Semantics:
  8313. """"""""""
  8314. The '``llvm.returnaddress``' intrinsic either returns a pointer
  8315. indicating the return address of the specified call frame, or zero if it
  8316. cannot be identified. The value returned by this intrinsic is likely to
  8317. be incorrect or 0 for arguments other than zero, so it should only be
  8318. used for debugging purposes.
  8319. Note that calling this intrinsic does not prevent function inlining or
  8320. other aggressive transformations, so the value returned may not be that
  8321. of the obvious source-language caller.
  8322. '``llvm.addressofreturnaddress``' Intrinsic
  8323. ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  8324. Syntax:
  8325. """""""
  8326. ::
  8327. declare i8* @llvm.addressofreturnaddress()
  8328. Overview:
  8329. """""""""
  8330. The '``llvm.addressofreturnaddress``' intrinsic returns a target-specific
  8331. pointer to the place in the stack frame where the return address of the
  8332. current function is stored.
  8333. Semantics:
  8334. """"""""""
  8335. Note that calling this intrinsic does not prevent function inlining or
  8336. other aggressive transformations, so the value returned may not be that
  8337. of the obvious source-language caller.
  8338. This intrinsic is only implemented for x86 and aarch64.
  8339. '``llvm.sponentry``' Intrinsic
  8340. ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  8341. Syntax:
  8342. """""""
  8343. ::
  8344. declare i8* @llvm.sponentry()
  8345. Overview:
  8346. """""""""
  8347. The '``llvm.sponentry``' intrinsic returns the stack pointer value at
  8348. the entry of the current function calling this intrinsic.
  8349. Semantics:
  8350. """"""""""
  8351. Note this intrinsic is only verified on AArch64.
  8352. '``llvm.frameaddress``' Intrinsic
  8353. ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  8354. Syntax:
  8355. """""""
  8356. ::
  8357. declare i8* @llvm.frameaddress(i32 <level>)
  8358. Overview:
  8359. """""""""
  8360. The '``llvm.frameaddress``' intrinsic attempts to return the
  8361. target-specific frame pointer value for the specified stack frame.
  8362. Arguments:
  8363. """"""""""
  8364. The argument to this intrinsic indicates which function to return the
  8365. frame pointer for. Zero indicates the calling function, one indicates
  8366. its caller, etc. The argument is **required** to be a constant integer
  8367. value.
  8368. Semantics:
  8369. """"""""""
  8370. The '``llvm.frameaddress``' intrinsic either returns a pointer
  8371. indicating the frame address of the specified call frame, or zero if it
  8372. cannot be identified. The value returned by this intrinsic is likely to
  8373. be incorrect or 0 for arguments other than zero, so it should only be
  8374. used for debugging purposes.
  8375. Note that calling this intrinsic does not prevent function inlining or
  8376. other aggressive transformations, so the value returned may not be that
  8377. of the obvious source-language caller.
  8378. '``llvm.localescape``' and '``llvm.localrecover``' Intrinsics
  8379. ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  8380. Syntax:
  8381. """""""
  8382. ::
  8383. declare void @llvm.localescape(...)
  8384. declare i8* @llvm.localrecover(i8* %func, i8* %fp, i32 %idx)
  8385. Overview:
  8386. """""""""
  8387. The '``llvm.localescape``' intrinsic escapes offsets of a collection of static
  8388. allocas, and the '``llvm.localrecover``' intrinsic applies those offsets to a
  8389. live frame pointer to recover the address of the allocation. The offset is
  8390. computed during frame layout of the caller of ``llvm.localescape``.
  8391. Arguments:
  8392. """"""""""
  8393. All arguments to '``llvm.localescape``' must be pointers to static allocas or
  8394. casts of static allocas. Each function can only call '``llvm.localescape``'
  8395. once, and it can only do so from the entry block.
  8396. The ``func`` argument to '``llvm.localrecover``' must be a constant
  8397. bitcasted pointer to a function defined in the current module. The code
  8398. generator cannot determine the frame allocation offset of functions defined in
  8399. other modules.
  8400. The ``fp`` argument to '``llvm.localrecover``' must be a frame pointer of a
  8401. call frame that is currently live. The return value of '``llvm.localaddress``'
  8402. is one way to produce such a value, but various runtimes also expose a suitable
  8403. pointer in platform-specific ways.
  8404. The ``idx`` argument to '``llvm.localrecover``' indicates which alloca passed to
  8405. '``llvm.localescape``' to recover. It is zero-indexed.
  8406. Semantics:
  8407. """"""""""
  8408. These intrinsics allow a group of functions to share access to a set of local
  8409. stack allocations of a one parent function. The parent function may call the
  8410. '``llvm.localescape``' intrinsic once from the function entry block, and the
  8411. child functions can use '``llvm.localrecover``' to access the escaped allocas.
  8412. The '``llvm.localescape``' intrinsic blocks inlining, as inlining changes where
  8413. the escaped allocas are allocated, which would break attempts to use
  8414. '``llvm.localrecover``'.
  8415. .. _int_read_register:
  8416. .. _int_write_register:
  8417. '``llvm.read_register``' and '``llvm.write_register``' Intrinsics
  8418. ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  8419. Syntax:
  8420. """""""
  8421. ::
  8422. declare i32 @llvm.read_register.i32(metadata)
  8423. declare i64 @llvm.read_register.i64(metadata)
  8424. declare void @llvm.write_register.i32(metadata, i32 @value)
  8425. declare void @llvm.write_register.i64(metadata, i64 @value)
  8426. !0 = !{!"sp\00"}
  8427. Overview:
  8428. """""""""
  8429. The '``llvm.read_register``' and '``llvm.write_register``' intrinsics
  8430. provides access to the named register. The register must be valid on
  8431. the architecture being compiled to. The type needs to be compatible
  8432. with the register being read.
  8433. Semantics:
  8434. """"""""""
  8435. The '``llvm.read_register``' intrinsic returns the current value of the
  8436. register, where possible. The '``llvm.write_register``' intrinsic sets
  8437. the current value of the register, where possible.
  8438. This is useful to implement named register global variables that need
  8439. to always be mapped to a specific register, as is common practice on
  8440. bare-metal programs including OS kernels.
  8441. The compiler doesn't check for register availability or use of the used
  8442. register in surrounding code, including inline assembly. Because of that,
  8443. allocatable registers are not supported.
  8444. Warning: So far it only works with the stack pointer on selected
  8445. architectures (ARM, AArch64, PowerPC and x86_64). Significant amount of
  8446. work is needed to support other registers and even more so, allocatable
  8447. registers.
  8448. .. _int_stacksave:
  8449. '``llvm.stacksave``' Intrinsic
  8450. ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  8451. Syntax:
  8452. """""""
  8453. ::
  8454. declare i8* @llvm.stacksave()
  8455. Overview:
  8456. """""""""
  8457. The '``llvm.stacksave``' intrinsic is used to remember the current state
  8458. of the function stack, for use with
  8459. :ref:`llvm.stackrestore <int_stackrestore>`. This is useful for
  8460. implementing language features like scoped automatic variable sized
  8461. arrays in C99.
  8462. Semantics:
  8463. """"""""""
  8464. This intrinsic returns a opaque pointer value that can be passed to
  8465. :ref:`llvm.stackrestore <int_stackrestore>`. When an
  8466. ``llvm.stackrestore`` intrinsic is executed with a value saved from
  8467. ``llvm.stacksave``, it effectively restores the state of the stack to
  8468. the state it was in when the ``llvm.stacksave`` intrinsic executed. In
  8469. practice, this pops any :ref:`alloca <i_alloca>` blocks from the stack that
  8470. were allocated after the ``llvm.stacksave`` was executed.
  8471. .. _int_stackrestore:
  8472. '``llvm.stackrestore``' Intrinsic
  8473. ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  8474. Syntax:
  8475. """""""
  8476. ::
  8477. declare void @llvm.stackrestore(i8* %ptr)
  8478. Overview:
  8479. """""""""
  8480. The '``llvm.stackrestore``' intrinsic is used to restore the state of
  8481. the function stack to the state it was in when the corresponding
  8482. :ref:`llvm.stacksave <int_stacksave>` intrinsic executed. This is
  8483. useful for implementing language features like scoped automatic variable
  8484. sized arrays in C99.
  8485. Semantics:
  8486. """"""""""
  8487. See the description for :ref:`llvm.stacksave <int_stacksave>`.
  8488. .. _int_get_dynamic_area_offset:
  8489. '``llvm.get.dynamic.area.offset``' Intrinsic
  8490. ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  8491. Syntax:
  8492. """""""
  8493. ::
  8494. declare i32 @llvm.get.dynamic.area.offset.i32()
  8495. declare i64 @llvm.get.dynamic.area.offset.i64()
  8496. Overview:
  8497. """""""""
  8498. The '``llvm.get.dynamic.area.offset.*``' intrinsic family is used to
  8499. get the offset from native stack pointer to the address of the most
  8500. recent dynamic alloca on the caller's stack. These intrinsics are
  8501. intendend for use in combination with
  8502. :ref:`llvm.stacksave <int_stacksave>` to get a
  8503. pointer to the most recent dynamic alloca. This is useful, for example,
  8504. for AddressSanitizer's stack unpoisoning routines.
  8505. Semantics:
  8506. """"""""""
  8507. These intrinsics return a non-negative integer value that can be used to
  8508. get the address of the most recent dynamic alloca, allocated by :ref:`alloca <i_alloca>`
  8509. on the caller's stack. In particular, for targets where stack grows downwards,
  8510. adding this offset to the native stack pointer would get the address of the most
  8511. recent dynamic alloca. For targets where stack grows upwards, the situation is a bit more
  8512. complicated, because subtracting this value from stack pointer would get the address
  8513. one past the end of the most recent dynamic alloca.
  8514. Although for most targets `llvm.get.dynamic.area.offset <int_get_dynamic_area_offset>`
  8515. returns just a zero, for others, such as PowerPC and PowerPC64, it returns a
  8516. compile-time-known constant value.
  8517. The return value type of :ref:`llvm.get.dynamic.area.offset <int_get_dynamic_area_offset>`
  8518. must match the target's default address space's (address space 0) pointer type.
  8519. '``llvm.prefetch``' Intrinsic
  8520. ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  8521. Syntax:
  8522. """""""
  8523. ::
  8524. declare void @llvm.prefetch(i8* <address>, i32 <rw>, i32 <locality>, i32 <cache type>)
  8525. Overview:
  8526. """""""""
  8527. The '``llvm.prefetch``' intrinsic is a hint to the code generator to
  8528. insert a prefetch instruction if supported; otherwise, it is a noop.
  8529. Prefetches have no effect on the behavior of the program but can change
  8530. its performance characteristics.
  8531. Arguments:
  8532. """"""""""
  8533. ``address`` is the address to be prefetched, ``rw`` is the specifier
  8534. determining if the fetch should be for a read (0) or write (1), and
  8535. ``locality`` is a temporal locality specifier ranging from (0) - no
  8536. locality, to (3) - extremely local keep in cache. The ``cache type``
  8537. specifies whether the prefetch is performed on the data (1) or
  8538. instruction (0) cache. The ``rw``, ``locality`` and ``cache type``
  8539. arguments must be constant integers.
  8540. Semantics:
  8541. """"""""""
  8542. This intrinsic does not modify the behavior of the program. In
  8543. particular, prefetches cannot trap and do not produce a value. On
  8544. targets that support this intrinsic, the prefetch can provide hints to
  8545. the processor cache for better performance.
  8546. '``llvm.pcmarker``' Intrinsic
  8547. ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  8548. Syntax:
  8549. """""""
  8550. ::
  8551. declare void @llvm.pcmarker(i32 <id>)
  8552. Overview:
  8553. """""""""
  8554. The '``llvm.pcmarker``' intrinsic is a method to export a Program
  8555. Counter (PC) in a region of code to simulators and other tools. The
  8556. method is target specific, but it is expected that the marker will use
  8557. exported symbols to transmit the PC of the marker. The marker makes no
  8558. guarantees that it will remain with any specific instruction after
  8559. optimizations. It is possible that the presence of a marker will inhibit
  8560. optimizations. The intended use is to be inserted after optimizations to
  8561. allow correlations of simulation runs.
  8562. Arguments:
  8563. """"""""""
  8564. ``id`` is a numerical id identifying the marker.
  8565. Semantics:
  8566. """"""""""
  8567. This intrinsic does not modify the behavior of the program. Backends
  8568. that do not support this intrinsic may ignore it.
  8569. '``llvm.readcyclecounter``' Intrinsic
  8570. ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  8571. Syntax:
  8572. """""""
  8573. ::
  8574. declare i64 @llvm.readcyclecounter()
  8575. Overview:
  8576. """""""""
  8577. The '``llvm.readcyclecounter``' intrinsic provides access to the cycle
  8578. counter register (or similar low latency, high accuracy clocks) on those
  8579. targets that support it. On X86, it should map to RDTSC. On Alpha, it
  8580. should map to RPCC. As the backing counters overflow quickly (on the
  8581. order of 9 seconds on alpha), this should only be used for small
  8582. timings.
  8583. Semantics:
  8584. """"""""""
  8585. When directly supported, reading the cycle counter should not modify any
  8586. memory. Implementations are allowed to either return a application
  8587. specific value or a system wide value. On backends without support, this
  8588. is lowered to a constant 0.
  8589. Note that runtime support may be conditional on the privilege-level code is
  8590. running at and the host platform.
  8591. '``llvm.clear_cache``' Intrinsic
  8592. ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  8593. Syntax:
  8594. """""""
  8595. ::
  8596. declare void @llvm.clear_cache(i8*, i8*)
  8597. Overview:
  8598. """""""""
  8599. The '``llvm.clear_cache``' intrinsic ensures visibility of modifications
  8600. in the specified range to the execution unit of the processor. On
  8601. targets with non-unified instruction and data cache, the implementation
  8602. flushes the instruction cache.
  8603. Semantics:
  8604. """"""""""
  8605. On platforms with coherent instruction and data caches (e.g. x86), this
  8606. intrinsic is a nop. On platforms with non-coherent instruction and data
  8607. cache (e.g. ARM, MIPS), the intrinsic is lowered either to appropriate
  8608. instructions or a system call, if cache flushing requires special
  8609. privileges.
  8610. The default behavior is to emit a call to ``__clear_cache`` from the run
  8611. time library.
  8612. This intrinsic does *not* empty the instruction pipeline. Modifications
  8613. of the current function are outside the scope of the intrinsic.
  8614. '``llvm.instrprof.increment``' Intrinsic
  8615. ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  8616. Syntax:
  8617. """""""
  8618. ::
  8619. declare void @llvm.instrprof.increment(i8* <name>, i64 <hash>,
  8620. i32 <num-counters>, i32 <index>)
  8621. Overview:
  8622. """""""""
  8623. The '``llvm.instrprof.increment``' intrinsic can be emitted by a
  8624. frontend for use with instrumentation based profiling. These will be
  8625. lowered by the ``-instrprof`` pass to generate execution counts of a
  8626. program at runtime.
  8627. Arguments:
  8628. """"""""""
  8629. The first argument is a pointer to a global variable containing the
  8630. name of the entity being instrumented. This should generally be the
  8631. (mangled) function name for a set of counters.
  8632. The second argument is a hash value that can be used by the consumer
  8633. of the profile data to detect changes to the instrumented source, and
  8634. the third is the number of counters associated with ``name``. It is an
  8635. error if ``hash`` or ``num-counters`` differ between two instances of
  8636. ``instrprof.increment`` that refer to the same name.
  8637. The last argument refers to which of the counters for ``name`` should
  8638. be incremented. It should be a value between 0 and ``num-counters``.
  8639. Semantics:
  8640. """"""""""
  8641. This intrinsic represents an increment of a profiling counter. It will
  8642. cause the ``-instrprof`` pass to generate the appropriate data
  8643. structures and the code to increment the appropriate value, in a
  8644. format that can be written out by a compiler runtime and consumed via
  8645. the ``llvm-profdata`` tool.
  8646. '``llvm.instrprof.increment.step``' Intrinsic
  8647. ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  8648. Syntax:
  8649. """""""
  8650. ::
  8651. declare void @llvm.instrprof.increment.step(i8* <name>, i64 <hash>,
  8652. i32 <num-counters>,
  8653. i32 <index>, i64 <step>)
  8654. Overview:
  8655. """""""""
  8656. The '``llvm.instrprof.increment.step``' intrinsic is an extension to
  8657. the '``llvm.instrprof.increment``' intrinsic with an additional fifth
  8658. argument to specify the step of the increment.
  8659. Arguments:
  8660. """"""""""
  8661. The first four arguments are the same as '``llvm.instrprof.increment``'
  8662. intrinsic.
  8663. The last argument specifies the value of the increment of the counter variable.
  8664. Semantics:
  8665. """"""""""
  8666. See description of '``llvm.instrprof.increment``' intrinsic.
  8667. '``llvm.instrprof.value.profile``' Intrinsic
  8668. ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  8669. Syntax:
  8670. """""""
  8671. ::
  8672. declare void @llvm.instrprof.value.profile(i8* <name>, i64 <hash>,
  8673. i64 <value>, i32 <value_kind>,
  8674. i32 <index>)
  8675. Overview:
  8676. """""""""
  8677. The '``llvm.instrprof.value.profile``' intrinsic can be emitted by a
  8678. frontend for use with instrumentation based profiling. This will be
  8679. lowered by the ``-instrprof`` pass to find out the target values,
  8680. instrumented expressions take in a program at runtime.
  8681. Arguments:
  8682. """"""""""
  8683. The first argument is a pointer to a global variable containing the
  8684. name of the entity being instrumented. ``name`` should generally be the
  8685. (mangled) function name for a set of counters.
  8686. The second argument is a hash value that can be used by the consumer
  8687. of the profile data to detect changes to the instrumented source. It
  8688. is an error if ``hash`` differs between two instances of
  8689. ``llvm.instrprof.*`` that refer to the same name.
  8690. The third argument is the value of the expression being profiled. The profiled
  8691. expression's value should be representable as an unsigned 64-bit value. The
  8692. fourth argument represents the kind of value profiling that is being done. The
  8693. supported value profiling kinds are enumerated through the
  8694. ``InstrProfValueKind`` type declared in the
  8695. ``<include/llvm/ProfileData/InstrProf.h>`` header file. The last argument is the
  8696. index of the instrumented expression within ``name``. It should be >= 0.
  8697. Semantics:
  8698. """"""""""
  8699. This intrinsic represents the point where a call to a runtime routine
  8700. should be inserted for value profiling of target expressions. ``-instrprof``
  8701. pass will generate the appropriate data structures and replace the
  8702. ``llvm.instrprof.value.profile`` intrinsic with the call to the profile
  8703. runtime library with proper arguments.
  8704. '``llvm.thread.pointer``' Intrinsic
  8705. ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  8706. Syntax:
  8707. """""""
  8708. ::
  8709. declare i8* @llvm.thread.pointer()
  8710. Overview:
  8711. """""""""
  8712. The '``llvm.thread.pointer``' intrinsic returns the value of the thread
  8713. pointer.
  8714. Semantics:
  8715. """"""""""
  8716. The '``llvm.thread.pointer``' intrinsic returns a pointer to the TLS area
  8717. for the current thread. The exact semantics of this value are target
  8718. specific: it may point to the start of TLS area, to the end, or somewhere
  8719. in the middle. Depending on the target, this intrinsic may read a register,
  8720. call a helper function, read from an alternate memory space, or perform
  8721. other operations necessary to locate the TLS area. Not all targets support
  8722. this intrinsic.
  8723. Standard C Library Intrinsics
  8724. -----------------------------
  8725. LLVM provides intrinsics for a few important standard C library
  8726. functions. These intrinsics allow source-language front-ends to pass
  8727. information about the alignment of the pointer arguments to the code
  8728. generator, providing opportunity for more efficient code generation.
  8729. .. _int_memcpy:
  8730. '``llvm.memcpy``' Intrinsic
  8731. ^^^^^^^^^^^^^^^^^^^^^^^^^^^
  8732. Syntax:
  8733. """""""
  8734. This is an overloaded intrinsic. You can use ``llvm.memcpy`` on any
  8735. integer bit width and for different address spaces. Not all targets
  8736. support all bit widths however.
  8737. ::
  8738. declare void @llvm.memcpy.p0i8.p0i8.i32(i8* <dest>, i8* <src>,
  8739. i32 <len>, i1 <isvolatile>)
  8740. declare void @llvm.memcpy.p0i8.p0i8.i64(i8* <dest>, i8* <src>,
  8741. i64 <len>, i1 <isvolatile>)
  8742. Overview:
  8743. """""""""
  8744. The '``llvm.memcpy.*``' intrinsics copy a block of memory from the
  8745. source location to the destination location.
  8746. Note that, unlike the standard libc function, the ``llvm.memcpy.*``
  8747. intrinsics do not return a value, takes extra isvolatile
  8748. arguments and the pointers can be in specified address spaces.
  8749. Arguments:
  8750. """"""""""
  8751. The first argument is a pointer to the destination, the second is a
  8752. pointer to the source. The third argument is an integer argument
  8753. specifying the number of bytes to copy, and the fourth is a
  8754. boolean indicating a volatile access.
  8755. The :ref:`align <attr_align>` parameter attribute can be provided
  8756. for the first and second arguments.
  8757. If the ``isvolatile`` parameter is ``true``, the ``llvm.memcpy`` call is
  8758. a :ref:`volatile operation <volatile>`. The detailed access behavior is not
  8759. very cleanly specified and it is unwise to depend on it.
  8760. Semantics:
  8761. """"""""""
  8762. The '``llvm.memcpy.*``' intrinsics copy a block of memory from the
  8763. source location to the destination location, which are not allowed to
  8764. overlap. It copies "len" bytes of memory over. If the argument is known
  8765. to be aligned to some boundary, this can be specified as an attribute on
  8766. the argument.
  8767. If "len" is 0, the pointers may be NULL or dangling. However, they must still
  8768. be appropriately aligned.
  8769. .. _int_memmove:
  8770. '``llvm.memmove``' Intrinsic
  8771. ^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  8772. Syntax:
  8773. """""""
  8774. This is an overloaded intrinsic. You can use llvm.memmove on any integer
  8775. bit width and for different address space. Not all targets support all
  8776. bit widths however.
  8777. ::
  8778. declare void @llvm.memmove.p0i8.p0i8.i32(i8* <dest>, i8* <src>,
  8779. i32 <len>, i1 <isvolatile>)
  8780. declare void @llvm.memmove.p0i8.p0i8.i64(i8* <dest>, i8* <src>,
  8781. i64 <len>, i1 <isvolatile>)
  8782. Overview:
  8783. """""""""
  8784. The '``llvm.memmove.*``' intrinsics move a block of memory from the
  8785. source location to the destination location. It is similar to the
  8786. '``llvm.memcpy``' intrinsic but allows the two memory locations to
  8787. overlap.
  8788. Note that, unlike the standard libc function, the ``llvm.memmove.*``
  8789. intrinsics do not return a value, takes an extra isvolatile
  8790. argument and the pointers can be in specified address spaces.
  8791. Arguments:
  8792. """"""""""
  8793. The first argument is a pointer to the destination, the second is a
  8794. pointer to the source. The third argument is an integer argument
  8795. specifying the number of bytes to copy, and the fourth is a
  8796. boolean indicating a volatile access.
  8797. The :ref:`align <attr_align>` parameter attribute can be provided
  8798. for the first and second arguments.
  8799. If the ``isvolatile`` parameter is ``true``, the ``llvm.memmove`` call
  8800. is a :ref:`volatile operation <volatile>`. The detailed access behavior is
  8801. not very cleanly specified and it is unwise to depend on it.
  8802. Semantics:
  8803. """"""""""
  8804. The '``llvm.memmove.*``' intrinsics copy a block of memory from the
  8805. source location to the destination location, which may overlap. It
  8806. copies "len" bytes of memory over. If the argument is known to be
  8807. aligned to some boundary, this can be specified as an attribute on
  8808. the argument.
  8809. If "len" is 0, the pointers may be NULL or dangling. However, they must still
  8810. be appropriately aligned.
  8811. .. _int_memset:
  8812. '``llvm.memset.*``' Intrinsics
  8813. ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  8814. Syntax:
  8815. """""""
  8816. This is an overloaded intrinsic. You can use llvm.memset on any integer
  8817. bit width and for different address spaces. However, not all targets
  8818. support all bit widths.
  8819. ::
  8820. declare void @llvm.memset.p0i8.i32(i8* <dest>, i8 <val>,
  8821. i32 <len>, i1 <isvolatile>)
  8822. declare void @llvm.memset.p0i8.i64(i8* <dest>, i8 <val>,
  8823. i64 <len>, i1 <isvolatile>)
  8824. Overview:
  8825. """""""""
  8826. The '``llvm.memset.*``' intrinsics fill a block of memory with a
  8827. particular byte value.
  8828. Note that, unlike the standard libc function, the ``llvm.memset``
  8829. intrinsic does not return a value and takes an extra volatile
  8830. argument. Also, the destination can be in an arbitrary address space.
  8831. Arguments:
  8832. """"""""""
  8833. The first argument is a pointer to the destination to fill, the second
  8834. is the byte value with which to fill it, the third argument is an
  8835. integer argument specifying the number of bytes to fill, and the fourth
  8836. is a boolean indicating a volatile access.
  8837. The :ref:`align <attr_align>` parameter attribute can be provided
  8838. for the first arguments.
  8839. If the ``isvolatile`` parameter is ``true``, the ``llvm.memset`` call is
  8840. a :ref:`volatile operation <volatile>`. The detailed access behavior is not
  8841. very cleanly specified and it is unwise to depend on it.
  8842. Semantics:
  8843. """"""""""
  8844. The '``llvm.memset.*``' intrinsics fill "len" bytes of memory starting
  8845. at the destination location. If the argument is known to be
  8846. aligned to some boundary, this can be specified as an attribute on
  8847. the argument.
  8848. If "len" is 0, the pointers may be NULL or dangling. However, they must still
  8849. be appropriately aligned.
  8850. '``llvm.sqrt.*``' Intrinsic
  8851. ^^^^^^^^^^^^^^^^^^^^^^^^^^^
  8852. Syntax:
  8853. """""""
  8854. This is an overloaded intrinsic. You can use ``llvm.sqrt`` on any
  8855. floating-point or vector of floating-point type. Not all targets support
  8856. all types however.
  8857. ::
  8858. declare float @llvm.sqrt.f32(float %Val)
  8859. declare double @llvm.sqrt.f64(double %Val)
  8860. declare x86_fp80 @llvm.sqrt.f80(x86_fp80 %Val)
  8861. declare fp128 @llvm.sqrt.f128(fp128 %Val)
  8862. declare ppc_fp128 @llvm.sqrt.ppcf128(ppc_fp128 %Val)
  8863. Overview:
  8864. """""""""
  8865. The '``llvm.sqrt``' intrinsics return the square root of the specified value.
  8866. Arguments:
  8867. """"""""""
  8868. The argument and return value are floating-point numbers of the same type.
  8869. Semantics:
  8870. """"""""""
  8871. Return the same value as a corresponding libm '``sqrt``' function but without
  8872. trapping or setting ``errno``. For types specified by IEEE-754, the result
  8873. matches a conforming libm implementation.
  8874. When specified with the fast-math-flag 'afn', the result may be approximated
  8875. using a less accurate calculation.
  8876. '``llvm.powi.*``' Intrinsic
  8877. ^^^^^^^^^^^^^^^^^^^^^^^^^^^
  8878. Syntax:
  8879. """""""
  8880. This is an overloaded intrinsic. You can use ``llvm.powi`` on any
  8881. floating-point or vector of floating-point type. Not all targets support
  8882. all types however.
  8883. ::
  8884. declare float @llvm.powi.f32(float %Val, i32 %power)
  8885. declare double @llvm.powi.f64(double %Val, i32 %power)
  8886. declare x86_fp80 @llvm.powi.f80(x86_fp80 %Val, i32 %power)
  8887. declare fp128 @llvm.powi.f128(fp128 %Val, i32 %power)
  8888. declare ppc_fp128 @llvm.powi.ppcf128(ppc_fp128 %Val, i32 %power)
  8889. Overview:
  8890. """""""""
  8891. The '``llvm.powi.*``' intrinsics return the first operand raised to the
  8892. specified (positive or negative) power. The order of evaluation of
  8893. multiplications is not defined. When a vector of floating-point type is
  8894. used, the second argument remains a scalar integer value.
  8895. Arguments:
  8896. """"""""""
  8897. The second argument is an integer power, and the first is a value to
  8898. raise to that power.
  8899. Semantics:
  8900. """"""""""
  8901. This function returns the first value raised to the second power with an
  8902. unspecified sequence of rounding operations.
  8903. '``llvm.sin.*``' Intrinsic
  8904. ^^^^^^^^^^^^^^^^^^^^^^^^^^
  8905. Syntax:
  8906. """""""
  8907. This is an overloaded intrinsic. You can use ``llvm.sin`` on any
  8908. floating-point or vector of floating-point type. Not all targets support
  8909. all types however.
  8910. ::
  8911. declare float @llvm.sin.f32(float %Val)
  8912. declare double @llvm.sin.f64(double %Val)
  8913. declare x86_fp80 @llvm.sin.f80(x86_fp80 %Val)
  8914. declare fp128 @llvm.sin.f128(fp128 %Val)
  8915. declare ppc_fp128 @llvm.sin.ppcf128(ppc_fp128 %Val)
  8916. Overview:
  8917. """""""""
  8918. The '``llvm.sin.*``' intrinsics return the sine of the operand.
  8919. Arguments:
  8920. """"""""""
  8921. The argument and return value are floating-point numbers of the same type.
  8922. Semantics:
  8923. """"""""""
  8924. Return the same value as a corresponding libm '``sin``' function but without
  8925. trapping or setting ``errno``.
  8926. When specified with the fast-math-flag 'afn', the result may be approximated
  8927. using a less accurate calculation.
  8928. '``llvm.cos.*``' Intrinsic
  8929. ^^^^^^^^^^^^^^^^^^^^^^^^^^
  8930. Syntax:
  8931. """""""
  8932. This is an overloaded intrinsic. You can use ``llvm.cos`` on any
  8933. floating-point or vector of floating-point type. Not all targets support
  8934. all types however.
  8935. ::
  8936. declare float @llvm.cos.f32(float %Val)
  8937. declare double @llvm.cos.f64(double %Val)
  8938. declare x86_fp80 @llvm.cos.f80(x86_fp80 %Val)
  8939. declare fp128 @llvm.cos.f128(fp128 %Val)
  8940. declare ppc_fp128 @llvm.cos.ppcf128(ppc_fp128 %Val)
  8941. Overview:
  8942. """""""""
  8943. The '``llvm.cos.*``' intrinsics return the cosine of the operand.
  8944. Arguments:
  8945. """"""""""
  8946. The argument and return value are floating-point numbers of the same type.
  8947. Semantics:
  8948. """"""""""
  8949. Return the same value as a corresponding libm '``cos``' function but without
  8950. trapping or setting ``errno``.
  8951. When specified with the fast-math-flag 'afn', the result may be approximated
  8952. using a less accurate calculation.
  8953. '``llvm.pow.*``' Intrinsic
  8954. ^^^^^^^^^^^^^^^^^^^^^^^^^^
  8955. Syntax:
  8956. """""""
  8957. This is an overloaded intrinsic. You can use ``llvm.pow`` on any
  8958. floating-point or vector of floating-point type. Not all targets support
  8959. all types however.
  8960. ::
  8961. declare float @llvm.pow.f32(float %Val, float %Power)
  8962. declare double @llvm.pow.f64(double %Val, double %Power)
  8963. declare x86_fp80 @llvm.pow.f80(x86_fp80 %Val, x86_fp80 %Power)
  8964. declare fp128 @llvm.pow.f128(fp128 %Val, fp128 %Power)
  8965. declare ppc_fp128 @llvm.pow.ppcf128(ppc_fp128 %Val, ppc_fp128 Power)
  8966. Overview:
  8967. """""""""
  8968. The '``llvm.pow.*``' intrinsics return the first operand raised to the
  8969. specified (positive or negative) power.
  8970. Arguments:
  8971. """"""""""
  8972. The arguments and return value are floating-point numbers of the same type.
  8973. Semantics:
  8974. """"""""""
  8975. Return the same value as a corresponding libm '``pow``' function but without
  8976. trapping or setting ``errno``.
  8977. When specified with the fast-math-flag 'afn', the result may be approximated
  8978. using a less accurate calculation.
  8979. '``llvm.exp.*``' Intrinsic
  8980. ^^^^^^^^^^^^^^^^^^^^^^^^^^
  8981. Syntax:
  8982. """""""
  8983. This is an overloaded intrinsic. You can use ``llvm.exp`` on any
  8984. floating-point or vector of floating-point type. Not all targets support
  8985. all types however.
  8986. ::
  8987. declare float @llvm.exp.f32(float %Val)
  8988. declare double @llvm.exp.f64(double %Val)
  8989. declare x86_fp80 @llvm.exp.f80(x86_fp80 %Val)
  8990. declare fp128 @llvm.exp.f128(fp128 %Val)
  8991. declare ppc_fp128 @llvm.exp.ppcf128(ppc_fp128 %Val)
  8992. Overview:
  8993. """""""""
  8994. The '``llvm.exp.*``' intrinsics compute the base-e exponential of the specified
  8995. value.
  8996. Arguments:
  8997. """"""""""
  8998. The argument and return value are floating-point numbers of the same type.
  8999. Semantics:
  9000. """"""""""
  9001. Return the same value as a corresponding libm '``exp``' function but without
  9002. trapping or setting ``errno``.
  9003. When specified with the fast-math-flag 'afn', the result may be approximated
  9004. using a less accurate calculation.
  9005. '``llvm.exp2.*``' Intrinsic
  9006. ^^^^^^^^^^^^^^^^^^^^^^^^^^^
  9007. Syntax:
  9008. """""""
  9009. This is an overloaded intrinsic. You can use ``llvm.exp2`` on any
  9010. floating-point or vector of floating-point type. Not all targets support
  9011. all types however.
  9012. ::
  9013. declare float @llvm.exp2.f32(float %Val)
  9014. declare double @llvm.exp2.f64(double %Val)
  9015. declare x86_fp80 @llvm.exp2.f80(x86_fp80 %Val)
  9016. declare fp128 @llvm.exp2.f128(fp128 %Val)
  9017. declare ppc_fp128 @llvm.exp2.ppcf128(ppc_fp128 %Val)
  9018. Overview:
  9019. """""""""
  9020. The '``llvm.exp2.*``' intrinsics compute the base-2 exponential of the
  9021. specified value.
  9022. Arguments:
  9023. """"""""""
  9024. The argument and return value are floating-point numbers of the same type.
  9025. Semantics:
  9026. """"""""""
  9027. Return the same value as a corresponding libm '``exp2``' function but without
  9028. trapping or setting ``errno``.
  9029. When specified with the fast-math-flag 'afn', the result may be approximated
  9030. using a less accurate calculation.
  9031. '``llvm.log.*``' Intrinsic
  9032. ^^^^^^^^^^^^^^^^^^^^^^^^^^
  9033. Syntax:
  9034. """""""
  9035. This is an overloaded intrinsic. You can use ``llvm.log`` on any
  9036. floating-point or vector of floating-point type. Not all targets support
  9037. all types however.
  9038. ::
  9039. declare float @llvm.log.f32(float %Val)
  9040. declare double @llvm.log.f64(double %Val)
  9041. declare x86_fp80 @llvm.log.f80(x86_fp80 %Val)
  9042. declare fp128 @llvm.log.f128(fp128 %Val)
  9043. declare ppc_fp128 @llvm.log.ppcf128(ppc_fp128 %Val)
  9044. Overview:
  9045. """""""""
  9046. The '``llvm.log.*``' intrinsics compute the base-e logarithm of the specified
  9047. value.
  9048. Arguments:
  9049. """"""""""
  9050. The argument and return value are floating-point numbers of the same type.
  9051. Semantics:
  9052. """"""""""
  9053. Return the same value as a corresponding libm '``log``' function but without
  9054. trapping or setting ``errno``.
  9055. When specified with the fast-math-flag 'afn', the result may be approximated
  9056. using a less accurate calculation.
  9057. '``llvm.log10.*``' Intrinsic
  9058. ^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  9059. Syntax:
  9060. """""""
  9061. This is an overloaded intrinsic. You can use ``llvm.log10`` on any
  9062. floating-point or vector of floating-point type. Not all targets support
  9063. all types however.
  9064. ::
  9065. declare float @llvm.log10.f32(float %Val)
  9066. declare double @llvm.log10.f64(double %Val)
  9067. declare x86_fp80 @llvm.log10.f80(x86_fp80 %Val)
  9068. declare fp128 @llvm.log10.f128(fp128 %Val)
  9069. declare ppc_fp128 @llvm.log10.ppcf128(ppc_fp128 %Val)
  9070. Overview:
  9071. """""""""
  9072. The '``llvm.log10.*``' intrinsics compute the base-10 logarithm of the
  9073. specified value.
  9074. Arguments:
  9075. """"""""""
  9076. The argument and return value are floating-point numbers of the same type.
  9077. Semantics:
  9078. """"""""""
  9079. Return the same value as a corresponding libm '``log10``' function but without
  9080. trapping or setting ``errno``.
  9081. When specified with the fast-math-flag 'afn', the result may be approximated
  9082. using a less accurate calculation.
  9083. '``llvm.log2.*``' Intrinsic
  9084. ^^^^^^^^^^^^^^^^^^^^^^^^^^^
  9085. Syntax:
  9086. """""""
  9087. This is an overloaded intrinsic. You can use ``llvm.log2`` on any
  9088. floating-point or vector of floating-point type. Not all targets support
  9089. all types however.
  9090. ::
  9091. declare float @llvm.log2.f32(float %Val)
  9092. declare double @llvm.log2.f64(double %Val)
  9093. declare x86_fp80 @llvm.log2.f80(x86_fp80 %Val)
  9094. declare fp128 @llvm.log2.f128(fp128 %Val)
  9095. declare ppc_fp128 @llvm.log2.ppcf128(ppc_fp128 %Val)
  9096. Overview:
  9097. """""""""
  9098. The '``llvm.log2.*``' intrinsics compute the base-2 logarithm of the specified
  9099. value.
  9100. Arguments:
  9101. """"""""""
  9102. The argument and return value are floating-point numbers of the same type.
  9103. Semantics:
  9104. """"""""""
  9105. Return the same value as a corresponding libm '``log2``' function but without
  9106. trapping or setting ``errno``.
  9107. When specified with the fast-math-flag 'afn', the result may be approximated
  9108. using a less accurate calculation.
  9109. .. _int_fma:
  9110. '``llvm.fma.*``' Intrinsic
  9111. ^^^^^^^^^^^^^^^^^^^^^^^^^^
  9112. Syntax:
  9113. """""""
  9114. This is an overloaded intrinsic. You can use ``llvm.fma`` on any
  9115. floating-point or vector of floating-point type. Not all targets support
  9116. all types however.
  9117. ::
  9118. declare float @llvm.fma.f32(float %a, float %b, float %c)
  9119. declare double @llvm.fma.f64(double %a, double %b, double %c)
  9120. declare x86_fp80 @llvm.fma.f80(x86_fp80 %a, x86_fp80 %b, x86_fp80 %c)
  9121. declare fp128 @llvm.fma.f128(fp128 %a, fp128 %b, fp128 %c)
  9122. declare ppc_fp128 @llvm.fma.ppcf128(ppc_fp128 %a, ppc_fp128 %b, ppc_fp128 %c)
  9123. Overview:
  9124. """""""""
  9125. The '``llvm.fma.*``' intrinsics perform the fused multiply-add operation.
  9126. Arguments:
  9127. """"""""""
  9128. The arguments and return value are floating-point numbers of the same type.
  9129. Semantics:
  9130. """"""""""
  9131. Return the same value as a corresponding libm '``fma``' function but without
  9132. trapping or setting ``errno``.
  9133. When specified with the fast-math-flag 'afn', the result may be approximated
  9134. using a less accurate calculation.
  9135. '``llvm.fabs.*``' Intrinsic
  9136. ^^^^^^^^^^^^^^^^^^^^^^^^^^^
  9137. Syntax:
  9138. """""""
  9139. This is an overloaded intrinsic. You can use ``llvm.fabs`` on any
  9140. floating-point or vector of floating-point type. Not all targets support
  9141. all types however.
  9142. ::
  9143. declare float @llvm.fabs.f32(float %Val)
  9144. declare double @llvm.fabs.f64(double %Val)
  9145. declare x86_fp80 @llvm.fabs.f80(x86_fp80 %Val)
  9146. declare fp128 @llvm.fabs.f128(fp128 %Val)
  9147. declare ppc_fp128 @llvm.fabs.ppcf128(ppc_fp128 %Val)
  9148. Overview:
  9149. """""""""
  9150. The '``llvm.fabs.*``' intrinsics return the absolute value of the
  9151. operand.
  9152. Arguments:
  9153. """"""""""
  9154. The argument and return value are floating-point numbers of the same
  9155. type.
  9156. Semantics:
  9157. """"""""""
  9158. This function returns the same values as the libm ``fabs`` functions
  9159. would, and handles error conditions in the same way.
  9160. '``llvm.minnum.*``' Intrinsic
  9161. ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  9162. Syntax:
  9163. """""""
  9164. This is an overloaded intrinsic. You can use ``llvm.minnum`` on any
  9165. floating-point or vector of floating-point type. Not all targets support
  9166. all types however.
  9167. ::
  9168. declare float @llvm.minnum.f32(float %Val0, float %Val1)
  9169. declare double @llvm.minnum.f64(double %Val0, double %Val1)
  9170. declare x86_fp80 @llvm.minnum.f80(x86_fp80 %Val0, x86_fp80 %Val1)
  9171. declare fp128 @llvm.minnum.f128(fp128 %Val0, fp128 %Val1)
  9172. declare ppc_fp128 @llvm.minnum.ppcf128(ppc_fp128 %Val0, ppc_fp128 %Val1)
  9173. Overview:
  9174. """""""""
  9175. The '``llvm.minnum.*``' intrinsics return the minimum of the two
  9176. arguments.
  9177. Arguments:
  9178. """"""""""
  9179. The arguments and return value are floating-point numbers of the same
  9180. type.
  9181. Semantics:
  9182. """"""""""
  9183. Follows the IEEE-754 semantics for minNum, except for handling of
  9184. signaling NaNs. This match's the behavior of libm's fmin.
  9185. If either operand is a NaN, returns the other non-NaN operand. Returns
  9186. NaN only if both operands are NaN. The returned NaN is always
  9187. quiet. If the operands compare equal, returns a value that compares
  9188. equal to both operands. This means that fmin(+/-0.0, +/-0.0) could
  9189. return either -0.0 or 0.0.
  9190. Unlike the IEEE-754 2008 behavior, this does not distinguish between
  9191. signaling and quiet NaN inputs. If a target's implementation follows
  9192. the standard and returns a quiet NaN if either input is a signaling
  9193. NaN, the intrinsic lowering is responsible for quieting the inputs to
  9194. correctly return the non-NaN input (e.g. by using the equivalent of
  9195. ``llvm.canonicalize``).
  9196. '``llvm.maxnum.*``' Intrinsic
  9197. ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  9198. Syntax:
  9199. """""""
  9200. This is an overloaded intrinsic. You can use ``llvm.maxnum`` on any
  9201. floating-point or vector of floating-point type. Not all targets support
  9202. all types however.
  9203. ::
  9204. declare float @llvm.maxnum.f32(float %Val0, float %Val1l)
  9205. declare double @llvm.maxnum.f64(double %Val0, double %Val1)
  9206. declare x86_fp80 @llvm.maxnum.f80(x86_fp80 %Val0, x86_fp80 %Val1)
  9207. declare fp128 @llvm.maxnum.f128(fp128 %Val0, fp128 %Val1)
  9208. declare ppc_fp128 @llvm.maxnum.ppcf128(ppc_fp128 %Val0, ppc_fp128 %Val1)
  9209. Overview:
  9210. """""""""
  9211. The '``llvm.maxnum.*``' intrinsics return the maximum of the two
  9212. arguments.
  9213. Arguments:
  9214. """"""""""
  9215. The arguments and return value are floating-point numbers of the same
  9216. type.
  9217. Semantics:
  9218. """"""""""
  9219. Follows the IEEE-754 semantics for maxNum except for the handling of
  9220. signaling NaNs. This matches the behavior of libm's fmax.
  9221. If either operand is a NaN, returns the other non-NaN operand. Returns
  9222. NaN only if both operands are NaN. The returned NaN is always
  9223. quiet. If the operands compare equal, returns a value that compares
  9224. equal to both operands. This means that fmax(+/-0.0, +/-0.0) could
  9225. return either -0.0 or 0.0.
  9226. Unlike the IEEE-754 2008 behavior, this does not distinguish between
  9227. signaling and quiet NaN inputs. If a target's implementation follows
  9228. the standard and returns a quiet NaN if either input is a signaling
  9229. NaN, the intrinsic lowering is responsible for quieting the inputs to
  9230. correctly return the non-NaN input (e.g. by using the equivalent of
  9231. ``llvm.canonicalize``).
  9232. '``llvm.minimum.*``' Intrinsic
  9233. ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  9234. Syntax:
  9235. """""""
  9236. This is an overloaded intrinsic. You can use ``llvm.minimum`` on any
  9237. floating-point or vector of floating-point type. Not all targets support
  9238. all types however.
  9239. ::
  9240. declare float @llvm.minimum.f32(float %Val0, float %Val1)
  9241. declare double @llvm.minimum.f64(double %Val0, double %Val1)
  9242. declare x86_fp80 @llvm.minimum.f80(x86_fp80 %Val0, x86_fp80 %Val1)
  9243. declare fp128 @llvm.minimum.f128(fp128 %Val0, fp128 %Val1)
  9244. declare ppc_fp128 @llvm.minimum.ppcf128(ppc_fp128 %Val0, ppc_fp128 %Val1)
  9245. Overview:
  9246. """""""""
  9247. The '``llvm.minimum.*``' intrinsics return the minimum of the two
  9248. arguments, propagating NaNs and treating -0.0 as less than +0.0.
  9249. Arguments:
  9250. """"""""""
  9251. The arguments and return value are floating-point numbers of the same
  9252. type.
  9253. Semantics:
  9254. """"""""""
  9255. If either operand is a NaN, returns NaN. Otherwise returns the lesser
  9256. of the two arguments. -0.0 is considered to be less than +0.0 for this
  9257. intrinsic. Note that these are the semantics specified in the draft of
  9258. IEEE 754-2018.
  9259. '``llvm.maximum.*``' Intrinsic
  9260. ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  9261. Syntax:
  9262. """""""
  9263. This is an overloaded intrinsic. You can use ``llvm.maximum`` on any
  9264. floating-point or vector of floating-point type. Not all targets support
  9265. all types however.
  9266. ::
  9267. declare float @llvm.maximum.f32(float %Val0, float %Val1)
  9268. declare double @llvm.maximum.f64(double %Val0, double %Val1)
  9269. declare x86_fp80 @llvm.maximum.f80(x86_fp80 %Val0, x86_fp80 %Val1)
  9270. declare fp128 @llvm.maximum.f128(fp128 %Val0, fp128 %Val1)
  9271. declare ppc_fp128 @llvm.maximum.ppcf128(ppc_fp128 %Val0, ppc_fp128 %Val1)
  9272. Overview:
  9273. """""""""
  9274. The '``llvm.maximum.*``' intrinsics return the maximum of the two
  9275. arguments, propagating NaNs and treating -0.0 as less than +0.0.
  9276. Arguments:
  9277. """"""""""
  9278. The arguments and return value are floating-point numbers of the same
  9279. type.
  9280. Semantics:
  9281. """"""""""
  9282. If either operand is a NaN, returns NaN. Otherwise returns the greater
  9283. of the two arguments. -0.0 is considered to be less than +0.0 for this
  9284. intrinsic. Note that these are the semantics specified in the draft of
  9285. IEEE 754-2018.
  9286. '``llvm.copysign.*``' Intrinsic
  9287. ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  9288. Syntax:
  9289. """""""
  9290. This is an overloaded intrinsic. You can use ``llvm.copysign`` on any
  9291. floating-point or vector of floating-point type. Not all targets support
  9292. all types however.
  9293. ::
  9294. declare float @llvm.copysign.f32(float %Mag, float %Sgn)
  9295. declare double @llvm.copysign.f64(double %Mag, double %Sgn)
  9296. declare x86_fp80 @llvm.copysign.f80(x86_fp80 %Mag, x86_fp80 %Sgn)
  9297. declare fp128 @llvm.copysign.f128(fp128 %Mag, fp128 %Sgn)
  9298. declare ppc_fp128 @llvm.copysign.ppcf128(ppc_fp128 %Mag, ppc_fp128 %Sgn)
  9299. Overview:
  9300. """""""""
  9301. The '``llvm.copysign.*``' intrinsics return a value with the magnitude of the
  9302. first operand and the sign of the second operand.
  9303. Arguments:
  9304. """"""""""
  9305. The arguments and return value are floating-point numbers of the same
  9306. type.
  9307. Semantics:
  9308. """"""""""
  9309. This function returns the same values as the libm ``copysign``
  9310. functions would, and handles error conditions in the same way.
  9311. '``llvm.floor.*``' Intrinsic
  9312. ^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  9313. Syntax:
  9314. """""""
  9315. This is an overloaded intrinsic. You can use ``llvm.floor`` on any
  9316. floating-point or vector of floating-point type. Not all targets support
  9317. all types however.
  9318. ::
  9319. declare float @llvm.floor.f32(float %Val)
  9320. declare double @llvm.floor.f64(double %Val)
  9321. declare x86_fp80 @llvm.floor.f80(x86_fp80 %Val)
  9322. declare fp128 @llvm.floor.f128(fp128 %Val)
  9323. declare ppc_fp128 @llvm.floor.ppcf128(ppc_fp128 %Val)
  9324. Overview:
  9325. """""""""
  9326. The '``llvm.floor.*``' intrinsics return the floor of the operand.
  9327. Arguments:
  9328. """"""""""
  9329. The argument and return value are floating-point numbers of the same
  9330. type.
  9331. Semantics:
  9332. """"""""""
  9333. This function returns the same values as the libm ``floor`` functions
  9334. would, and handles error conditions in the same way.
  9335. '``llvm.ceil.*``' Intrinsic
  9336. ^^^^^^^^^^^^^^^^^^^^^^^^^^^
  9337. Syntax:
  9338. """""""
  9339. This is an overloaded intrinsic. You can use ``llvm.ceil`` on any
  9340. floating-point or vector of floating-point type. Not all targets support
  9341. all types however.
  9342. ::
  9343. declare float @llvm.ceil.f32(float %Val)
  9344. declare double @llvm.ceil.f64(double %Val)
  9345. declare x86_fp80 @llvm.ceil.f80(x86_fp80 %Val)
  9346. declare fp128 @llvm.ceil.f128(fp128 %Val)
  9347. declare ppc_fp128 @llvm.ceil.ppcf128(ppc_fp128 %Val)
  9348. Overview:
  9349. """""""""
  9350. The '``llvm.ceil.*``' intrinsics return the ceiling of the operand.
  9351. Arguments:
  9352. """"""""""
  9353. The argument and return value are floating-point numbers of the same
  9354. type.
  9355. Semantics:
  9356. """"""""""
  9357. This function returns the same values as the libm ``ceil`` functions
  9358. would, and handles error conditions in the same way.
  9359. '``llvm.trunc.*``' Intrinsic
  9360. ^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  9361. Syntax:
  9362. """""""
  9363. This is an overloaded intrinsic. You can use ``llvm.trunc`` on any
  9364. floating-point or vector of floating-point type. Not all targets support
  9365. all types however.
  9366. ::
  9367. declare float @llvm.trunc.f32(float %Val)
  9368. declare double @llvm.trunc.f64(double %Val)
  9369. declare x86_fp80 @llvm.trunc.f80(x86_fp80 %Val)
  9370. declare fp128 @llvm.trunc.f128(fp128 %Val)
  9371. declare ppc_fp128 @llvm.trunc.ppcf128(ppc_fp128 %Val)
  9372. Overview:
  9373. """""""""
  9374. The '``llvm.trunc.*``' intrinsics returns the operand rounded to the
  9375. nearest integer not larger in magnitude than the operand.
  9376. Arguments:
  9377. """"""""""
  9378. The argument and return value are floating-point numbers of the same
  9379. type.
  9380. Semantics:
  9381. """"""""""
  9382. This function returns the same values as the libm ``trunc`` functions
  9383. would, and handles error conditions in the same way.
  9384. '``llvm.rint.*``' Intrinsic
  9385. ^^^^^^^^^^^^^^^^^^^^^^^^^^^
  9386. Syntax:
  9387. """""""
  9388. This is an overloaded intrinsic. You can use ``llvm.rint`` on any
  9389. floating-point or vector of floating-point type. Not all targets support
  9390. all types however.
  9391. ::
  9392. declare float @llvm.rint.f32(float %Val)
  9393. declare double @llvm.rint.f64(double %Val)
  9394. declare x86_fp80 @llvm.rint.f80(x86_fp80 %Val)
  9395. declare fp128 @llvm.rint.f128(fp128 %Val)
  9396. declare ppc_fp128 @llvm.rint.ppcf128(ppc_fp128 %Val)
  9397. Overview:
  9398. """""""""
  9399. The '``llvm.rint.*``' intrinsics returns the operand rounded to the
  9400. nearest integer. It may raise an inexact floating-point exception if the
  9401. operand isn't an integer.
  9402. Arguments:
  9403. """"""""""
  9404. The argument and return value are floating-point numbers of the same
  9405. type.
  9406. Semantics:
  9407. """"""""""
  9408. This function returns the same values as the libm ``rint`` functions
  9409. would, and handles error conditions in the same way.
  9410. '``llvm.nearbyint.*``' Intrinsic
  9411. ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  9412. Syntax:
  9413. """""""
  9414. This is an overloaded intrinsic. You can use ``llvm.nearbyint`` on any
  9415. floating-point or vector of floating-point type. Not all targets support
  9416. all types however.
  9417. ::
  9418. declare float @llvm.nearbyint.f32(float %Val)
  9419. declare double @llvm.nearbyint.f64(double %Val)
  9420. declare x86_fp80 @llvm.nearbyint.f80(x86_fp80 %Val)
  9421. declare fp128 @llvm.nearbyint.f128(fp128 %Val)
  9422. declare ppc_fp128 @llvm.nearbyint.ppcf128(ppc_fp128 %Val)
  9423. Overview:
  9424. """""""""
  9425. The '``llvm.nearbyint.*``' intrinsics returns the operand rounded to the
  9426. nearest integer.
  9427. Arguments:
  9428. """"""""""
  9429. The argument and return value are floating-point numbers of the same
  9430. type.
  9431. Semantics:
  9432. """"""""""
  9433. This function returns the same values as the libm ``nearbyint``
  9434. functions would, and handles error conditions in the same way.
  9435. '``llvm.round.*``' Intrinsic
  9436. ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  9437. Syntax:
  9438. """""""
  9439. This is an overloaded intrinsic. You can use ``llvm.round`` on any
  9440. floating-point or vector of floating-point type. Not all targets support
  9441. all types however.
  9442. ::
  9443. declare float @llvm.round.f32(float %Val)
  9444. declare double @llvm.round.f64(double %Val)
  9445. declare x86_fp80 @llvm.round.f80(x86_fp80 %Val)
  9446. declare fp128 @llvm.round.f128(fp128 %Val)
  9447. declare ppc_fp128 @llvm.round.ppcf128(ppc_fp128 %Val)
  9448. Overview:
  9449. """""""""
  9450. The '``llvm.round.*``' intrinsics returns the operand rounded to the
  9451. nearest integer.
  9452. Arguments:
  9453. """"""""""
  9454. The argument and return value are floating-point numbers of the same
  9455. type.
  9456. Semantics:
  9457. """"""""""
  9458. This function returns the same values as the libm ``round``
  9459. functions would, and handles error conditions in the same way.
  9460. '``llvm.lround.*``' Intrinsic
  9461. ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  9462. Syntax:
  9463. """""""
  9464. This is an overloaded intrinsic. You can use ``llvm.lround`` on any
  9465. floating-point type. Not all targets support all types however.
  9466. ::
  9467. declare i32 @llvm.lround.i32.f32(float %Val)
  9468. declare i32 @llvm.lround.i32.f64(double %Val)
  9469. declare i32 @llvm.lround.i32.f80(float %Val)
  9470. declare i32 @llvm.lround.i32.f128(double %Val)
  9471. declare i32 @llvm.lround.i32.ppcf128(double %Val)
  9472. declare i64 @llvm.lround.i64.f32(float %Val)
  9473. declare i64 @llvm.lround.i64.f64(double %Val)
  9474. declare i64 @llvm.lround.i64.f80(float %Val)
  9475. declare i64 @llvm.lround.i64.f128(double %Val)
  9476. declare i64 @llvm.lround.i64.ppcf128(double %Val)
  9477. Overview:
  9478. """""""""
  9479. The '``llvm.lround.*``' intrinsics returns the operand rounded to the
  9480. nearest integer.
  9481. Arguments:
  9482. """"""""""
  9483. The argument is a floating-point number and return is an integer type.
  9484. Semantics:
  9485. """"""""""
  9486. This function returns the same values as the libm ``lround``
  9487. functions would, but without setting errno.
  9488. '``llvm.llround.*``' Intrinsic
  9489. ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  9490. Syntax:
  9491. """""""
  9492. This is an overloaded intrinsic. You can use ``llvm.llround`` on any
  9493. floating-point type. Not all targets support all types however.
  9494. ::
  9495. declare i64 @llvm.lround.i64.f32(float %Val)
  9496. declare i64 @llvm.lround.i64.f64(double %Val)
  9497. declare i64 @llvm.lround.i64.f80(float %Val)
  9498. declare i64 @llvm.lround.i64.f128(double %Val)
  9499. declare i64 @llvm.lround.i64.ppcf128(double %Val)
  9500. Overview:
  9501. """""""""
  9502. The '``llvm.llround.*``' 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 ``llround``
  9510. functions would, but without setting errno.
  9511. '``llvm.lrint.*``' Intrinsic
  9512. ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  9513. Syntax:
  9514. """""""
  9515. This is an overloaded intrinsic. You can use ``llvm.lrint`` on any
  9516. floating-point type. Not all targets support all types however.
  9517. ::
  9518. declare i32 @llvm.lrint.i32.f32(float %Val)
  9519. declare i32 @llvm.lrint.i32.f64(double %Val)
  9520. declare i32 @llvm.lrint.i32.f80(float %Val)
  9521. declare i32 @llvm.lrint.i32.f128(double %Val)
  9522. declare i32 @llvm.lrint.i32.ppcf128(double %Val)
  9523. declare i64 @llvm.lrint.i64.f32(float %Val)
  9524. declare i64 @llvm.lrint.i64.f64(double %Val)
  9525. declare i64 @llvm.lrint.i64.f80(float %Val)
  9526. declare i64 @llvm.lrint.i64.f128(double %Val)
  9527. declare i64 @llvm.lrint.i64.ppcf128(double %Val)
  9528. Overview:
  9529. """""""""
  9530. The '``llvm.lrint.*``' intrinsics returns the operand rounded to the
  9531. nearest integer.
  9532. Arguments:
  9533. """"""""""
  9534. The argument is a floating-point number and return is an integer type.
  9535. Semantics:
  9536. """"""""""
  9537. This function returns the same values as the libm ``lrint``
  9538. functions would, but without setting errno.
  9539. '``llvm.llrint.*``' Intrinsic
  9540. ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  9541. Syntax:
  9542. """""""
  9543. This is an overloaded intrinsic. You can use ``llvm.llrint`` on any
  9544. floating-point type. Not all targets support all types however.
  9545. ::
  9546. declare i64 @llvm.llrint.i64.f32(float %Val)
  9547. declare i64 @llvm.llrint.i64.f64(double %Val)
  9548. declare i64 @llvm.llrint.i64.f80(float %Val)
  9549. declare i64 @llvm.llrint.i64.f128(double %Val)
  9550. declare i64 @llvm.llrint.i64.ppcf128(double %Val)
  9551. Overview:
  9552. """""""""
  9553. The '``llvm.llrint.*``' intrinsics returns the operand rounded to the
  9554. nearest integer.
  9555. Arguments:
  9556. """"""""""
  9557. The argument is a floating-point number and return is an integer type.
  9558. Semantics:
  9559. """"""""""
  9560. This function returns the same values as the libm ``llrint``
  9561. functions would, but without setting errno.
  9562. Bit Manipulation Intrinsics
  9563. ---------------------------
  9564. LLVM provides intrinsics for a few important bit manipulation
  9565. operations. These allow efficient code generation for some algorithms.
  9566. '``llvm.bitreverse.*``' Intrinsics
  9567. ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  9568. Syntax:
  9569. """""""
  9570. This is an overloaded intrinsic function. You can use bitreverse on any
  9571. integer type.
  9572. ::
  9573. declare i16 @llvm.bitreverse.i16(i16 <id>)
  9574. declare i32 @llvm.bitreverse.i32(i32 <id>)
  9575. declare i64 @llvm.bitreverse.i64(i64 <id>)
  9576. declare <4 x i32> @llvm.bitreverse.v4i32(<4 x i32> <id>)
  9577. Overview:
  9578. """""""""
  9579. The '``llvm.bitreverse``' family of intrinsics is used to reverse the
  9580. bitpattern of an integer value or vector of integer values; for example
  9581. ``0b10110110`` becomes ``0b01101101``.
  9582. Semantics:
  9583. """"""""""
  9584. The ``llvm.bitreverse.iN`` intrinsic returns an iN value that has bit
  9585. ``M`` in the input moved to bit ``N-M`` in the output. The vector
  9586. intrinsics, such as ``llvm.bitreverse.v4i32``, operate on a per-element
  9587. basis and the element order is not affected.
  9588. '``llvm.bswap.*``' Intrinsics
  9589. ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  9590. Syntax:
  9591. """""""
  9592. This is an overloaded intrinsic function. You can use bswap on any
  9593. integer type that is an even number of bytes (i.e. BitWidth % 16 == 0).
  9594. ::
  9595. declare i16 @llvm.bswap.i16(i16 <id>)
  9596. declare i32 @llvm.bswap.i32(i32 <id>)
  9597. declare i64 @llvm.bswap.i64(i64 <id>)
  9598. declare <4 x i32> @llvm.bswap.v4i32(<4 x i32> <id>)
  9599. Overview:
  9600. """""""""
  9601. The '``llvm.bswap``' family of intrinsics is used to byte swap an integer
  9602. value or vector of integer values with an even number of bytes (positive
  9603. multiple of 16 bits).
  9604. Semantics:
  9605. """"""""""
  9606. The ``llvm.bswap.i16`` intrinsic returns an i16 value that has the high
  9607. and low byte of the input i16 swapped. Similarly, the ``llvm.bswap.i32``
  9608. intrinsic returns an i32 value that has the four bytes of the input i32
  9609. swapped, so that if the input bytes are numbered 0, 1, 2, 3 then the
  9610. returned i32 will have its bytes in 3, 2, 1, 0 order. The
  9611. ``llvm.bswap.i48``, ``llvm.bswap.i64`` and other intrinsics extend this
  9612. concept to additional even-byte lengths (6 bytes, 8 bytes and more,
  9613. respectively). The vector intrinsics, such as ``llvm.bswap.v4i32``,
  9614. operate on a per-element basis and the element order is not affected.
  9615. '``llvm.ctpop.*``' Intrinsic
  9616. ^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  9617. Syntax:
  9618. """""""
  9619. This is an overloaded intrinsic. You can use llvm.ctpop on any integer
  9620. bit width, or on any vector with integer elements. Not all targets
  9621. support all bit widths or vector types, however.
  9622. ::
  9623. declare i8 @llvm.ctpop.i8(i8 <src>)
  9624. declare i16 @llvm.ctpop.i16(i16 <src>)
  9625. declare i32 @llvm.ctpop.i32(i32 <src>)
  9626. declare i64 @llvm.ctpop.i64(i64 <src>)
  9627. declare i256 @llvm.ctpop.i256(i256 <src>)
  9628. declare <2 x i32> @llvm.ctpop.v2i32(<2 x i32> <src>)
  9629. Overview:
  9630. """""""""
  9631. The '``llvm.ctpop``' family of intrinsics counts the number of bits set
  9632. in a value.
  9633. Arguments:
  9634. """"""""""
  9635. The only argument is the value to be counted. The argument may be of any
  9636. integer type, or a vector with integer elements. The return type must
  9637. match the argument type.
  9638. Semantics:
  9639. """"""""""
  9640. The '``llvm.ctpop``' intrinsic counts the 1's in a variable, or within
  9641. each element of a vector.
  9642. '``llvm.ctlz.*``' Intrinsic
  9643. ^^^^^^^^^^^^^^^^^^^^^^^^^^^
  9644. Syntax:
  9645. """""""
  9646. This is an overloaded intrinsic. You can use ``llvm.ctlz`` on any
  9647. integer bit width, or any vector whose elements are integers. Not all
  9648. targets support all bit widths or vector types, however.
  9649. ::
  9650. declare i8 @llvm.ctlz.i8 (i8 <src>, i1 <is_zero_undef>)
  9651. declare i16 @llvm.ctlz.i16 (i16 <src>, i1 <is_zero_undef>)
  9652. declare i32 @llvm.ctlz.i32 (i32 <src>, i1 <is_zero_undef>)
  9653. declare i64 @llvm.ctlz.i64 (i64 <src>, i1 <is_zero_undef>)
  9654. declare i256 @llvm.ctlz.i256(i256 <src>, i1 <is_zero_undef>)
  9655. declare <2 x i32> @llvm.ctlz.v2i32(<2 x i32> <src>, i1 <is_zero_undef>)
  9656. Overview:
  9657. """""""""
  9658. The '``llvm.ctlz``' family of intrinsic functions counts the number of
  9659. leading zeros in a variable.
  9660. Arguments:
  9661. """"""""""
  9662. The first argument is the value to be counted. This argument may be of
  9663. any integer type, or a vector with integer element type. The return
  9664. type must match the first argument type.
  9665. The second argument must be a constant and is a flag to indicate whether
  9666. the intrinsic should ensure that a zero as the first argument produces a
  9667. defined result. Historically some architectures did not provide a
  9668. defined result for zero values as efficiently, and many algorithms are
  9669. now predicated on avoiding zero-value inputs.
  9670. Semantics:
  9671. """"""""""
  9672. The '``llvm.ctlz``' intrinsic counts the leading (most significant)
  9673. zeros in a variable, or within each element of the vector. If
  9674. ``src == 0`` then the result is the size in bits of the type of ``src``
  9675. if ``is_zero_undef == 0`` and ``undef`` otherwise. For example,
  9676. ``llvm.ctlz(i32 2) = 30``.
  9677. '``llvm.cttz.*``' Intrinsic
  9678. ^^^^^^^^^^^^^^^^^^^^^^^^^^^
  9679. Syntax:
  9680. """""""
  9681. This is an overloaded intrinsic. You can use ``llvm.cttz`` on any
  9682. integer bit width, or any vector of integer elements. Not all targets
  9683. support all bit widths or vector types, however.
  9684. ::
  9685. declare i8 @llvm.cttz.i8 (i8 <src>, i1 <is_zero_undef>)
  9686. declare i16 @llvm.cttz.i16 (i16 <src>, i1 <is_zero_undef>)
  9687. declare i32 @llvm.cttz.i32 (i32 <src>, i1 <is_zero_undef>)
  9688. declare i64 @llvm.cttz.i64 (i64 <src>, i1 <is_zero_undef>)
  9689. declare i256 @llvm.cttz.i256(i256 <src>, i1 <is_zero_undef>)
  9690. declare <2 x i32> @llvm.cttz.v2i32(<2 x i32> <src>, i1 <is_zero_undef>)
  9691. Overview:
  9692. """""""""
  9693. The '``llvm.cttz``' family of intrinsic functions counts the number of
  9694. trailing zeros.
  9695. Arguments:
  9696. """"""""""
  9697. The first argument is the value to be counted. This argument may be of
  9698. any integer type, or a vector with integer element type. The return
  9699. type must match the first argument type.
  9700. The second argument must be a constant and is a flag to indicate whether
  9701. the intrinsic should ensure that a zero as the first argument produces a
  9702. defined result. Historically some architectures did not provide a
  9703. defined result for zero values as efficiently, and many algorithms are
  9704. now predicated on avoiding zero-value inputs.
  9705. Semantics:
  9706. """"""""""
  9707. The '``llvm.cttz``' intrinsic counts the trailing (least significant)
  9708. zeros in a variable, or within each element of a vector. If ``src == 0``
  9709. then the result is the size in bits of the type of ``src`` if
  9710. ``is_zero_undef == 0`` and ``undef`` otherwise. For example,
  9711. ``llvm.cttz(2) = 1``.
  9712. .. _int_overflow:
  9713. '``llvm.fshl.*``' Intrinsic
  9714. ^^^^^^^^^^^^^^^^^^^^^^^^^^^
  9715. Syntax:
  9716. """""""
  9717. This is an overloaded intrinsic. You can use ``llvm.fshl`` on any
  9718. integer bit width or any vector of integer elements. Not all targets
  9719. support all bit widths or vector types, however.
  9720. ::
  9721. declare i8 @llvm.fshl.i8 (i8 %a, i8 %b, i8 %c)
  9722. declare i67 @llvm.fshl.i67(i67 %a, i67 %b, i67 %c)
  9723. declare <2 x i32> @llvm.fshl.v2i32(<2 x i32> %a, <2 x i32> %b, <2 x i32> %c)
  9724. Overview:
  9725. """""""""
  9726. The '``llvm.fshl``' family of intrinsic functions performs a funnel shift left:
  9727. the first two values are concatenated as { %a : %b } (%a is the most significant
  9728. bits of the wide value), the combined value is shifted left, and the most
  9729. significant bits are extracted to produce a result that is the same size as the
  9730. original arguments. If the first 2 arguments are identical, this is equivalent
  9731. to a rotate left operation. For vector types, the operation occurs for each
  9732. element of the vector. The shift argument is treated as an unsigned amount
  9733. modulo the element size of the arguments.
  9734. Arguments:
  9735. """"""""""
  9736. The first two arguments are the values to be concatenated. The third
  9737. argument is the shift amount. The arguments may be any integer type or a
  9738. vector with integer element type. All arguments and the return value must
  9739. have the same type.
  9740. Example:
  9741. """"""""
  9742. .. code-block:: text
  9743. %r = call i8 @llvm.fshl.i8(i8 %x, i8 %y, i8 %z) ; %r = i8: msb_extract((concat(x, y) << (z % 8)), 8)
  9744. %r = call i8 @llvm.fshl.i8(i8 255, i8 0, i8 15) ; %r = i8: 128 (0b10000000)
  9745. %r = call i8 @llvm.fshl.i8(i8 15, i8 15, i8 11) ; %r = i8: 120 (0b01111000)
  9746. %r = call i8 @llvm.fshl.i8(i8 0, i8 255, i8 8) ; %r = i8: 0 (0b00000000)
  9747. '``llvm.fshr.*``' Intrinsic
  9748. ^^^^^^^^^^^^^^^^^^^^^^^^^^^
  9749. Syntax:
  9750. """""""
  9751. This is an overloaded intrinsic. You can use ``llvm.fshr`` on any
  9752. integer bit width or any vector of integer elements. Not all targets
  9753. support all bit widths or vector types, however.
  9754. ::
  9755. declare i8 @llvm.fshr.i8 (i8 %a, i8 %b, i8 %c)
  9756. declare i67 @llvm.fshr.i67(i67 %a, i67 %b, i67 %c)
  9757. declare <2 x i32> @llvm.fshr.v2i32(<2 x i32> %a, <2 x i32> %b, <2 x i32> %c)
  9758. Overview:
  9759. """""""""
  9760. The '``llvm.fshr``' family of intrinsic functions performs a funnel shift right:
  9761. the first two values are concatenated as { %a : %b } (%a is the most significant
  9762. bits of the wide value), the combined value is shifted right, and the least
  9763. significant bits are extracted to produce a result that is the same size as the
  9764. original arguments. If the first 2 arguments are identical, this is equivalent
  9765. to a rotate right operation. For vector types, the operation occurs for each
  9766. element of the vector. The shift argument is treated as an unsigned amount
  9767. modulo the element size of the arguments.
  9768. Arguments:
  9769. """"""""""
  9770. The first two arguments are the values to be concatenated. The third
  9771. argument is the shift amount. The arguments may be any integer type or a
  9772. vector with integer element type. All arguments and the return value must
  9773. have the same type.
  9774. Example:
  9775. """"""""
  9776. .. code-block:: text
  9777. %r = call i8 @llvm.fshr.i8(i8 %x, i8 %y, i8 %z) ; %r = i8: lsb_extract((concat(x, y) >> (z % 8)), 8)
  9778. %r = call i8 @llvm.fshr.i8(i8 255, i8 0, i8 15) ; %r = i8: 254 (0b11111110)
  9779. %r = call i8 @llvm.fshr.i8(i8 15, i8 15, i8 11) ; %r = i8: 225 (0b11100001)
  9780. %r = call i8 @llvm.fshr.i8(i8 0, i8 255, i8 8) ; %r = i8: 255 (0b11111111)
  9781. Arithmetic with Overflow Intrinsics
  9782. -----------------------------------
  9783. LLVM provides intrinsics for fast arithmetic overflow checking.
  9784. Each of these intrinsics returns a two-element struct. The first
  9785. element of this struct contains the result of the corresponding
  9786. arithmetic operation modulo 2\ :sup:`n`\ , where n is the bit width of
  9787. the result. Therefore, for example, the first element of the struct
  9788. returned by ``llvm.sadd.with.overflow.i32`` is always the same as the
  9789. result of a 32-bit ``add`` instruction with the same operands, where
  9790. the ``add`` is *not* modified by an ``nsw`` or ``nuw`` flag.
  9791. The second element of the result is an ``i1`` that is 1 if the
  9792. arithmetic operation overflowed and 0 otherwise. An operation
  9793. overflows if, for any values of its operands ``A`` and ``B`` and for
  9794. any ``N`` larger than the operands' width, ``ext(A op B) to iN`` is
  9795. not equal to ``(ext(A) to iN) op (ext(B) to iN)`` where ``ext`` is
  9796. ``sext`` for signed overflow and ``zext`` for unsigned overflow, and
  9797. ``op`` is the underlying arithmetic operation.
  9798. The behavior of these intrinsics is well-defined for all argument
  9799. values.
  9800. '``llvm.sadd.with.overflow.*``' Intrinsics
  9801. ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  9802. Syntax:
  9803. """""""
  9804. This is an overloaded intrinsic. You can use ``llvm.sadd.with.overflow``
  9805. on any integer bit width or vectors of integers.
  9806. ::
  9807. declare {i16, i1} @llvm.sadd.with.overflow.i16(i16 %a, i16 %b)
  9808. declare {i32, i1} @llvm.sadd.with.overflow.i32(i32 %a, i32 %b)
  9809. declare {i64, i1} @llvm.sadd.with.overflow.i64(i64 %a, i64 %b)
  9810. declare {<4 x i32>, <4 x i1>} @llvm.sadd.with.overflow.v4i32(<4 x i32> %a, <4 x i32> %b)
  9811. Overview:
  9812. """""""""
  9813. The '``llvm.sadd.with.overflow``' family of intrinsic functions perform
  9814. a signed addition of the two arguments, and indicate whether an overflow
  9815. occurred during the signed summation.
  9816. Arguments:
  9817. """"""""""
  9818. The arguments (%a and %b) and the first element of the result structure
  9819. may be of integer types of any bit width, but they must have the same
  9820. bit width. The second element of the result structure must be of type
  9821. ``i1``. ``%a`` and ``%b`` are the two values that will undergo signed
  9822. addition.
  9823. Semantics:
  9824. """"""""""
  9825. The '``llvm.sadd.with.overflow``' family of intrinsic functions perform
  9826. a signed addition of the two variables. They return a structure --- the
  9827. first element of which is the signed summation, and the second element
  9828. of which is a bit specifying if the signed summation resulted in an
  9829. overflow.
  9830. Examples:
  9831. """""""""
  9832. .. code-block:: llvm
  9833. %res = call {i32, i1} @llvm.sadd.with.overflow.i32(i32 %a, i32 %b)
  9834. %sum = extractvalue {i32, i1} %res, 0
  9835. %obit = extractvalue {i32, i1} %res, 1
  9836. br i1 %obit, label %overflow, label %normal
  9837. '``llvm.uadd.with.overflow.*``' Intrinsics
  9838. ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  9839. Syntax:
  9840. """""""
  9841. This is an overloaded intrinsic. You can use ``llvm.uadd.with.overflow``
  9842. on any integer bit width or vectors of integers.
  9843. ::
  9844. declare {i16, i1} @llvm.uadd.with.overflow.i16(i16 %a, i16 %b)
  9845. declare {i32, i1} @llvm.uadd.with.overflow.i32(i32 %a, i32 %b)
  9846. declare {i64, i1} @llvm.uadd.with.overflow.i64(i64 %a, i64 %b)
  9847. declare {<4 x i32>, <4 x i1>} @llvm.uadd.with.overflow.v4i32(<4 x i32> %a, <4 x i32> %b)
  9848. Overview:
  9849. """""""""
  9850. The '``llvm.uadd.with.overflow``' family of intrinsic functions perform
  9851. an unsigned addition of the two arguments, and indicate whether a carry
  9852. occurred during the unsigned summation.
  9853. Arguments:
  9854. """"""""""
  9855. The arguments (%a and %b) and the first element of the result structure
  9856. may be of integer types of any bit width, but they must have the same
  9857. bit width. The second element of the result structure must be of type
  9858. ``i1``. ``%a`` and ``%b`` are the two values that will undergo unsigned
  9859. addition.
  9860. Semantics:
  9861. """"""""""
  9862. The '``llvm.uadd.with.overflow``' family of intrinsic functions perform
  9863. an unsigned addition of the two arguments. They return a structure --- the
  9864. first element of which is the sum, and the second element of which is a
  9865. bit specifying if the unsigned summation resulted in a carry.
  9866. Examples:
  9867. """""""""
  9868. .. code-block:: llvm
  9869. %res = call {i32, i1} @llvm.uadd.with.overflow.i32(i32 %a, i32 %b)
  9870. %sum = extractvalue {i32, i1} %res, 0
  9871. %obit = extractvalue {i32, i1} %res, 1
  9872. br i1 %obit, label %carry, label %normal
  9873. '``llvm.ssub.with.overflow.*``' Intrinsics
  9874. ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  9875. Syntax:
  9876. """""""
  9877. This is an overloaded intrinsic. You can use ``llvm.ssub.with.overflow``
  9878. on any integer bit width or vectors of integers.
  9879. ::
  9880. declare {i16, i1} @llvm.ssub.with.overflow.i16(i16 %a, i16 %b)
  9881. declare {i32, i1} @llvm.ssub.with.overflow.i32(i32 %a, i32 %b)
  9882. declare {i64, i1} @llvm.ssub.with.overflow.i64(i64 %a, i64 %b)
  9883. declare {<4 x i32>, <4 x i1>} @llvm.ssub.with.overflow.v4i32(<4 x i32> %a, <4 x i32> %b)
  9884. Overview:
  9885. """""""""
  9886. The '``llvm.ssub.with.overflow``' family of intrinsic functions perform
  9887. a signed subtraction of the two arguments, and indicate whether an
  9888. overflow occurred during the signed subtraction.
  9889. Arguments:
  9890. """"""""""
  9891. The arguments (%a and %b) and the first element of the result structure
  9892. may be of integer types of any bit width, but they must have the same
  9893. bit width. The second element of the result structure must be of type
  9894. ``i1``. ``%a`` and ``%b`` are the two values that will undergo signed
  9895. subtraction.
  9896. Semantics:
  9897. """"""""""
  9898. The '``llvm.ssub.with.overflow``' family of intrinsic functions perform
  9899. a signed subtraction of the two arguments. They return a structure --- the
  9900. first element of which is the subtraction, and the second element of
  9901. which is a bit specifying if the signed subtraction resulted in an
  9902. overflow.
  9903. Examples:
  9904. """""""""
  9905. .. code-block:: llvm
  9906. %res = call {i32, i1} @llvm.ssub.with.overflow.i32(i32 %a, i32 %b)
  9907. %sum = extractvalue {i32, i1} %res, 0
  9908. %obit = extractvalue {i32, i1} %res, 1
  9909. br i1 %obit, label %overflow, label %normal
  9910. '``llvm.usub.with.overflow.*``' Intrinsics
  9911. ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  9912. Syntax:
  9913. """""""
  9914. This is an overloaded intrinsic. You can use ``llvm.usub.with.overflow``
  9915. on any integer bit width or vectors of integers.
  9916. ::
  9917. declare {i16, i1} @llvm.usub.with.overflow.i16(i16 %a, i16 %b)
  9918. declare {i32, i1} @llvm.usub.with.overflow.i32(i32 %a, i32 %b)
  9919. declare {i64, i1} @llvm.usub.with.overflow.i64(i64 %a, i64 %b)
  9920. declare {<4 x i32>, <4 x i1>} @llvm.usub.with.overflow.v4i32(<4 x i32> %a, <4 x i32> %b)
  9921. Overview:
  9922. """""""""
  9923. The '``llvm.usub.with.overflow``' family of intrinsic functions perform
  9924. an unsigned subtraction of the two arguments, and indicate whether an
  9925. overflow occurred during the unsigned subtraction.
  9926. Arguments:
  9927. """"""""""
  9928. The arguments (%a and %b) and the first element of the result structure
  9929. may be of integer types of any bit width, but they must have the same
  9930. bit width. The second element of the result structure must be of type
  9931. ``i1``. ``%a`` and ``%b`` are the two values that will undergo unsigned
  9932. subtraction.
  9933. Semantics:
  9934. """"""""""
  9935. The '``llvm.usub.with.overflow``' family of intrinsic functions perform
  9936. an unsigned subtraction of the two arguments. They return a structure ---
  9937. the first element of which is the subtraction, and the second element of
  9938. which is a bit specifying if the unsigned subtraction resulted in an
  9939. overflow.
  9940. Examples:
  9941. """""""""
  9942. .. code-block:: llvm
  9943. %res = call {i32, i1} @llvm.usub.with.overflow.i32(i32 %a, i32 %b)
  9944. %sum = extractvalue {i32, i1} %res, 0
  9945. %obit = extractvalue {i32, i1} %res, 1
  9946. br i1 %obit, label %overflow, label %normal
  9947. '``llvm.smul.with.overflow.*``' Intrinsics
  9948. ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  9949. Syntax:
  9950. """""""
  9951. This is an overloaded intrinsic. You can use ``llvm.smul.with.overflow``
  9952. on any integer bit width or vectors of integers.
  9953. ::
  9954. declare {i16, i1} @llvm.smul.with.overflow.i16(i16 %a, i16 %b)
  9955. declare {i32, i1} @llvm.smul.with.overflow.i32(i32 %a, i32 %b)
  9956. declare {i64, i1} @llvm.smul.with.overflow.i64(i64 %a, i64 %b)
  9957. declare {<4 x i32>, <4 x i1>} @llvm.smul.with.overflow.v4i32(<4 x i32> %a, <4 x i32> %b)
  9958. Overview:
  9959. """""""""
  9960. The '``llvm.smul.with.overflow``' family of intrinsic functions perform
  9961. a signed multiplication of the two arguments, and indicate whether an
  9962. overflow occurred during the signed multiplication.
  9963. Arguments:
  9964. """"""""""
  9965. The arguments (%a and %b) and the first element of the result structure
  9966. may be of integer types of any bit width, but they must have the same
  9967. bit width. The second element of the result structure must be of type
  9968. ``i1``. ``%a`` and ``%b`` are the two values that will undergo signed
  9969. multiplication.
  9970. Semantics:
  9971. """"""""""
  9972. The '``llvm.smul.with.overflow``' family of intrinsic functions perform
  9973. a signed multiplication of the two arguments. They return a structure ---
  9974. the first element of which is the multiplication, and the second element
  9975. of which is a bit specifying if the signed multiplication resulted in an
  9976. overflow.
  9977. Examples:
  9978. """""""""
  9979. .. code-block:: llvm
  9980. %res = call {i32, i1} @llvm.smul.with.overflow.i32(i32 %a, i32 %b)
  9981. %sum = extractvalue {i32, i1} %res, 0
  9982. %obit = extractvalue {i32, i1} %res, 1
  9983. br i1 %obit, label %overflow, label %normal
  9984. '``llvm.umul.with.overflow.*``' Intrinsics
  9985. ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  9986. Syntax:
  9987. """""""
  9988. This is an overloaded intrinsic. You can use ``llvm.umul.with.overflow``
  9989. on any integer bit width or vectors of integers.
  9990. ::
  9991. declare {i16, i1} @llvm.umul.with.overflow.i16(i16 %a, i16 %b)
  9992. declare {i32, i1} @llvm.umul.with.overflow.i32(i32 %a, i32 %b)
  9993. declare {i64, i1} @llvm.umul.with.overflow.i64(i64 %a, i64 %b)
  9994. declare {<4 x i32>, <4 x i1>} @llvm.umul.with.overflow.v4i32(<4 x i32> %a, <4 x i32> %b)
  9995. Overview:
  9996. """""""""
  9997. The '``llvm.umul.with.overflow``' family of intrinsic functions perform
  9998. a unsigned multiplication of the two arguments, and indicate whether an
  9999. overflow occurred during the unsigned multiplication.
  10000. Arguments:
  10001. """"""""""
  10002. The arguments (%a and %b) and the first element of the result structure
  10003. may be of integer types of any bit width, but they must have the same
  10004. bit width. The second element of the result structure must be of type
  10005. ``i1``. ``%a`` and ``%b`` are the two values that will undergo unsigned
  10006. multiplication.
  10007. Semantics:
  10008. """"""""""
  10009. The '``llvm.umul.with.overflow``' family of intrinsic functions perform
  10010. an unsigned multiplication of the two arguments. They return a structure ---
  10011. the first element of which is the multiplication, and the second
  10012. element of which is a bit specifying if the unsigned multiplication
  10013. resulted in an overflow.
  10014. Examples:
  10015. """""""""
  10016. .. code-block:: llvm
  10017. %res = call {i32, i1} @llvm.umul.with.overflow.i32(i32 %a, i32 %b)
  10018. %sum = extractvalue {i32, i1} %res, 0
  10019. %obit = extractvalue {i32, i1} %res, 1
  10020. br i1 %obit, label %overflow, label %normal
  10021. Saturation Arithmetic Intrinsics
  10022. ---------------------------------
  10023. Saturation arithmetic is a version of arithmetic in which operations are
  10024. limited to a fixed range between a minimum and maximum value. If the result of
  10025. an operation is greater than the maximum value, the result is set (or
  10026. "clamped") to this maximum. If it is below the minimum, it is clamped to this
  10027. minimum.
  10028. '``llvm.sadd.sat.*``' Intrinsics
  10029. ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  10030. Syntax
  10031. """""""
  10032. This is an overloaded intrinsic. You can use ``llvm.sadd.sat``
  10033. on any integer bit width or vectors of integers.
  10034. ::
  10035. declare i16 @llvm.sadd.sat.i16(i16 %a, i16 %b)
  10036. declare i32 @llvm.sadd.sat.i32(i32 %a, i32 %b)
  10037. declare i64 @llvm.sadd.sat.i64(i64 %a, i64 %b)
  10038. declare <4 x i32> @llvm.sadd.sat.v4i32(<4 x i32> %a, <4 x i32> %b)
  10039. Overview
  10040. """""""""
  10041. The '``llvm.sadd.sat``' family of intrinsic functions perform signed
  10042. saturation addition on the 2 arguments.
  10043. Arguments
  10044. """"""""""
  10045. The arguments (%a and %b) and the result may be of integer types of any bit
  10046. width, but they must have the same bit width. ``%a`` and ``%b`` are the two
  10047. values that will undergo signed addition.
  10048. Semantics:
  10049. """"""""""
  10050. The maximum value this operation can clamp to is the largest signed value
  10051. representable by the bit width of the arguments. The minimum value is the
  10052. smallest signed value representable by this bit width.
  10053. Examples
  10054. """""""""
  10055. .. code-block:: llvm
  10056. %res = call i4 @llvm.sadd.sat.i4(i4 1, i4 2) ; %res = 3
  10057. %res = call i4 @llvm.sadd.sat.i4(i4 5, i4 6) ; %res = 7
  10058. %res = call i4 @llvm.sadd.sat.i4(i4 -4, i4 2) ; %res = -2
  10059. %res = call i4 @llvm.sadd.sat.i4(i4 -4, i4 -5) ; %res = -8
  10060. '``llvm.uadd.sat.*``' Intrinsics
  10061. ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  10062. Syntax
  10063. """""""
  10064. This is an overloaded intrinsic. You can use ``llvm.uadd.sat``
  10065. on any integer bit width or vectors of integers.
  10066. ::
  10067. declare i16 @llvm.uadd.sat.i16(i16 %a, i16 %b)
  10068. declare i32 @llvm.uadd.sat.i32(i32 %a, i32 %b)
  10069. declare i64 @llvm.uadd.sat.i64(i64 %a, i64 %b)
  10070. declare <4 x i32> @llvm.uadd.sat.v4i32(<4 x i32> %a, <4 x i32> %b)
  10071. Overview
  10072. """""""""
  10073. The '``llvm.uadd.sat``' family of intrinsic functions perform unsigned
  10074. saturation addition on the 2 arguments.
  10075. Arguments
  10076. """"""""""
  10077. The arguments (%a and %b) and the result may be of integer types of any bit
  10078. width, but they must have the same bit width. ``%a`` and ``%b`` are the two
  10079. values that will undergo unsigned addition.
  10080. Semantics:
  10081. """"""""""
  10082. The maximum value this operation can clamp to is the largest unsigned value
  10083. representable by the bit width of the arguments. Because this is an unsigned
  10084. operation, the result will never saturate towards zero.
  10085. Examples
  10086. """""""""
  10087. .. code-block:: llvm
  10088. %res = call i4 @llvm.uadd.sat.i4(i4 1, i4 2) ; %res = 3
  10089. %res = call i4 @llvm.uadd.sat.i4(i4 5, i4 6) ; %res = 11
  10090. %res = call i4 @llvm.uadd.sat.i4(i4 8, i4 8) ; %res = 15
  10091. '``llvm.ssub.sat.*``' Intrinsics
  10092. ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  10093. Syntax
  10094. """""""
  10095. This is an overloaded intrinsic. You can use ``llvm.ssub.sat``
  10096. on any integer bit width or vectors of integers.
  10097. ::
  10098. declare i16 @llvm.ssub.sat.i16(i16 %a, i16 %b)
  10099. declare i32 @llvm.ssub.sat.i32(i32 %a, i32 %b)
  10100. declare i64 @llvm.ssub.sat.i64(i64 %a, i64 %b)
  10101. declare <4 x i32> @llvm.ssub.sat.v4i32(<4 x i32> %a, <4 x i32> %b)
  10102. Overview
  10103. """""""""
  10104. The '``llvm.ssub.sat``' family of intrinsic functions perform signed
  10105. saturation subtraction on the 2 arguments.
  10106. Arguments
  10107. """"""""""
  10108. The arguments (%a and %b) and the result may be of integer types of any bit
  10109. width, but they must have the same bit width. ``%a`` and ``%b`` are the two
  10110. values that will undergo signed subtraction.
  10111. Semantics:
  10112. """"""""""
  10113. The maximum value this operation can clamp to is the largest signed value
  10114. representable by the bit width of the arguments. The minimum value is the
  10115. smallest signed value representable by this bit width.
  10116. Examples
  10117. """""""""
  10118. .. code-block:: llvm
  10119. %res = call i4 @llvm.ssub.sat.i4(i4 2, i4 1) ; %res = 1
  10120. %res = call i4 @llvm.ssub.sat.i4(i4 2, i4 6) ; %res = -4
  10121. %res = call i4 @llvm.ssub.sat.i4(i4 -4, i4 5) ; %res = -8
  10122. %res = call i4 @llvm.ssub.sat.i4(i4 4, i4 -5) ; %res = 7
  10123. '``llvm.usub.sat.*``' Intrinsics
  10124. ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  10125. Syntax
  10126. """""""
  10127. This is an overloaded intrinsic. You can use ``llvm.usub.sat``
  10128. on any integer bit width or vectors of integers.
  10129. ::
  10130. declare i16 @llvm.usub.sat.i16(i16 %a, i16 %b)
  10131. declare i32 @llvm.usub.sat.i32(i32 %a, i32 %b)
  10132. declare i64 @llvm.usub.sat.i64(i64 %a, i64 %b)
  10133. declare <4 x i32> @llvm.usub.sat.v4i32(<4 x i32> %a, <4 x i32> %b)
  10134. Overview
  10135. """""""""
  10136. The '``llvm.usub.sat``' family of intrinsic functions perform unsigned
  10137. saturation subtraction on the 2 arguments.
  10138. Arguments
  10139. """"""""""
  10140. The arguments (%a and %b) and the result may be of integer types of any bit
  10141. width, but they must have the same bit width. ``%a`` and ``%b`` are the two
  10142. values that will undergo unsigned subtraction.
  10143. Semantics:
  10144. """"""""""
  10145. The minimum value this operation can clamp to is 0, which is the smallest
  10146. unsigned value representable by the bit width of the unsigned arguments.
  10147. Because this is an unsigned operation, the result will never saturate towards
  10148. the largest possible value representable by this bit width.
  10149. Examples
  10150. """""""""
  10151. .. code-block:: llvm
  10152. %res = call i4 @llvm.usub.sat.i4(i4 2, i4 1) ; %res = 1
  10153. %res = call i4 @llvm.usub.sat.i4(i4 2, i4 6) ; %res = 0
  10154. Fixed Point Arithmetic Intrinsics
  10155. ---------------------------------
  10156. A fixed point number represents a real data type for a number that has a fixed
  10157. number of digits after a radix point (equivalent to the decimal point '.').
  10158. The number of digits after the radix point is referred as the ``scale``. These
  10159. are useful for representing fractional values to a specific precision. The
  10160. following intrinsics perform fixed point arithmetic operations on 2 operands
  10161. of the same scale, specified as the third argument.
  10162. The `llvm.*mul.fix` family of intrinsic functions represents a multiplication
  10163. of fixed point numbers through scaled integers. Therefore, fixed point
  10164. multplication can be represented as
  10165. ::
  10166. %result = call i4 @llvm.smul.fix.i4(i4 %a, i4 %b, i32 %scale)
  10167. ; Expands to
  10168. %a2 = sext i4 %a to i8
  10169. %b2 = sext i4 %b to i8
  10170. %mul = mul nsw nuw i8 %a, %b
  10171. %scale2 = trunc i32 %scale to i8
  10172. %r = ashr i8 %mul, i8 %scale2 ; this is for a target rounding down towards negative infinity
  10173. %result = trunc i8 %r to i4
  10174. For each of these functions, if the result cannot be represented exactly with
  10175. the provided scale, the result is rounded. Rounding is unspecified since
  10176. preferred rounding may vary for different targets. Rounding is specified
  10177. through a target hook. Different pipelines should legalize or optimize this
  10178. using the rounding specified by this hook if it is provided. Operations like
  10179. constant folding, instruction combining, KnownBits, and ValueTracking should
  10180. also use this hook, if provided, and not assume the direction of rounding. A
  10181. rounded result must always be within one unit of precision from the true
  10182. result. That is, the error between the returned result and the true result must
  10183. be less than 1/2^(scale).
  10184. '``llvm.smul.fix.*``' Intrinsics
  10185. ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  10186. Syntax
  10187. """""""
  10188. This is an overloaded intrinsic. You can use ``llvm.smul.fix``
  10189. on any integer bit width or vectors of integers.
  10190. ::
  10191. declare i16 @llvm.smul.fix.i16(i16 %a, i16 %b, i32 %scale)
  10192. declare i32 @llvm.smul.fix.i32(i32 %a, i32 %b, i32 %scale)
  10193. declare i64 @llvm.smul.fix.i64(i64 %a, i64 %b, i32 %scale)
  10194. declare <4 x i32> @llvm.smul.fix.v4i32(<4 x i32> %a, <4 x i32> %b, i32 %scale)
  10195. Overview
  10196. """""""""
  10197. The '``llvm.smul.fix``' family of intrinsic functions perform signed
  10198. fixed point multiplication on 2 arguments of the same scale.
  10199. Arguments
  10200. """"""""""
  10201. The arguments (%a and %b) and the result may be of integer types of any bit
  10202. width, but they must have the same bit width. The arguments may also work with
  10203. int vectors of the same length and int size. ``%a`` and ``%b`` are the two
  10204. values that will undergo signed fixed point multiplication. The argument
  10205. ``%scale`` represents the scale of both operands, and must be a constant
  10206. integer.
  10207. Semantics:
  10208. """"""""""
  10209. This operation performs fixed point multiplication on the 2 arguments of a
  10210. specified scale. The result will also be returned in the same scale specified
  10211. in the third argument.
  10212. If the result value cannot be precisely represented in the given scale, the
  10213. value is rounded up or down to the closest representable value. The rounding
  10214. direction is unspecified.
  10215. It is undefined behavior if the result value does not fit within the range of
  10216. the fixed point type.
  10217. Examples
  10218. """""""""
  10219. .. code-block:: llvm
  10220. %res = call i4 @llvm.smul.fix.i4(i4 3, i4 2, i32 0) ; %res = 6 (2 x 3 = 6)
  10221. %res = call i4 @llvm.smul.fix.i4(i4 3, i4 2, i32 1) ; %res = 3 (1.5 x 1 = 1.5)
  10222. %res = call i4 @llvm.smul.fix.i4(i4 3, i4 -2, i32 1) ; %res = -3 (1.5 x -1 = -1.5)
  10223. ; The result in the following could be rounded up to -2 or down to -2.5
  10224. %res = call i4 @llvm.smul.fix.i4(i4 3, i4 -3, i32 1) ; %res = -5 (or -4) (1.5 x -1.5 = -2.25)
  10225. '``llvm.umul.fix.*``' Intrinsics
  10226. ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  10227. Syntax
  10228. """""""
  10229. This is an overloaded intrinsic. You can use ``llvm.umul.fix``
  10230. on any integer bit width or vectors of integers.
  10231. ::
  10232. declare i16 @llvm.umul.fix.i16(i16 %a, i16 %b, i32 %scale)
  10233. declare i32 @llvm.umul.fix.i32(i32 %a, i32 %b, i32 %scale)
  10234. declare i64 @llvm.umul.fix.i64(i64 %a, i64 %b, i32 %scale)
  10235. declare <4 x i32> @llvm.umul.fix.v4i32(<4 x i32> %a, <4 x i32> %b, i32 %scale)
  10236. Overview
  10237. """""""""
  10238. The '``llvm.umul.fix``' family of intrinsic functions perform unsigned
  10239. fixed point multiplication on 2 arguments of the same scale.
  10240. Arguments
  10241. """"""""""
  10242. The arguments (%a and %b) and the result may be of integer types of any bit
  10243. width, but they must have the same bit width. The arguments may also work with
  10244. int vectors of the same length and int size. ``%a`` and ``%b`` are the two
  10245. values that will undergo unsigned fixed point multiplication. The argument
  10246. ``%scale`` represents the scale of both operands, and must be a constant
  10247. integer.
  10248. Semantics:
  10249. """"""""""
  10250. This operation performs unsigned fixed point multiplication on the 2 arguments of a
  10251. specified scale. The result will also be returned in the same scale specified
  10252. in the third argument.
  10253. If the result value cannot be precisely represented in the given scale, the
  10254. value is rounded up or down to the closest representable value. The rounding
  10255. direction is unspecified.
  10256. It is undefined behavior if the result value does not fit within the range of
  10257. the fixed point type.
  10258. Examples
  10259. """""""""
  10260. .. code-block:: llvm
  10261. %res = call i4 @llvm.umul.fix.i4(i4 3, i4 2, i32 0) ; %res = 6 (2 x 3 = 6)
  10262. %res = call i4 @llvm.umul.fix.i4(i4 3, i4 2, i32 1) ; %res = 3 (1.5 x 1 = 1.5)
  10263. ; The result in the following could be rounded down to 3.5 or up to 4
  10264. %res = call i4 @llvm.umul.fix.i4(i4 15, i4 1, i32 1) ; %res = 7 (or 8) (7.5 x 0.5 = 3.75)
  10265. '``llvm.smul.fix.sat.*``' Intrinsics
  10266. ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  10267. Syntax
  10268. """""""
  10269. This is an overloaded intrinsic. You can use ``llvm.smul.fix.sat``
  10270. on any integer bit width or vectors of integers.
  10271. ::
  10272. declare i16 @llvm.smul.fix.sat.i16(i16 %a, i16 %b, i32 %scale)
  10273. declare i32 @llvm.smul.fix.sat.i32(i32 %a, i32 %b, i32 %scale)
  10274. declare i64 @llvm.smul.fix.sat.i64(i64 %a, i64 %b, i32 %scale)
  10275. declare <4 x i32> @llvm.smul.fix.sat.v4i32(<4 x i32> %a, <4 x i32> %b, i32 %scale)
  10276. Overview
  10277. """""""""
  10278. The '``llvm.smul.fix.sat``' family of intrinsic functions perform signed
  10279. fixed point saturation multiplication on 2 arguments of the same scale.
  10280. Arguments
  10281. """"""""""
  10282. The arguments (%a and %b) and the result may be of integer types of any bit
  10283. width, but they must have the same bit width. ``%a`` and ``%b`` are the two
  10284. values that will undergo signed fixed point multiplication. The argument
  10285. ``%scale`` represents the scale of both operands, and must be a constant
  10286. integer.
  10287. Semantics:
  10288. """"""""""
  10289. This operation performs fixed point multiplication on the 2 arguments of a
  10290. specified scale. The result will also be returned in the same scale specified
  10291. in the third argument.
  10292. If the result value cannot be precisely represented in the given scale, the
  10293. value is rounded up or down to the closest representable value. The rounding
  10294. direction is unspecified.
  10295. The maximum value this operation can clamp to is the largest signed value
  10296. representable by the bit width of the first 2 arguments. The minimum value is the
  10297. smallest signed value representable by this bit width.
  10298. Examples
  10299. """""""""
  10300. .. code-block:: llvm
  10301. %res = call i4 @llvm.smul.fix.sat.i4(i4 3, i4 2, i32 0) ; %res = 6 (2 x 3 = 6)
  10302. %res = call i4 @llvm.smul.fix.sat.i4(i4 3, i4 2, i32 1) ; %res = 3 (1.5 x 1 = 1.5)
  10303. %res = call i4 @llvm.smul.fix.sat.i4(i4 3, i4 -2, i32 1) ; %res = -3 (1.5 x -1 = -1.5)
  10304. ; The result in the following could be rounded up to -2 or down to -2.5
  10305. %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)
  10306. ; Saturation
  10307. %res = call i4 @llvm.smul.fix.sat.i4(i4 7, i4 2, i32 0) ; %res = 7
  10308. %res = call i4 @llvm.smul.fix.sat.i4(i4 7, i4 4, i32 2) ; %res = 7
  10309. %res = call i4 @llvm.smul.fix.sat.i4(i4 -8, i4 5, i32 2) ; %res = -8
  10310. %res = call i4 @llvm.smul.fix.sat.i4(i4 -8, i4 -2, i32 1) ; %res = 7
  10311. ; Scale can affect the saturation result
  10312. %res = call i4 @llvm.smul.fix.sat.i4(i4 2, i4 4, i32 0) ; %res = 7 (2 x 4 -> clamped to 7)
  10313. %res = call i4 @llvm.smul.fix.sat.i4(i4 2, i4 4, i32 1) ; %res = 4 (1 x 2 = 2)
  10314. '``llvm.umul.fix.sat.*``' Intrinsics
  10315. ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  10316. Syntax
  10317. """""""
  10318. This is an overloaded intrinsic. You can use ``llvm.umul.fix.sat``
  10319. on any integer bit width or vectors of integers.
  10320. ::
  10321. declare i16 @llvm.umul.fix.sat.i16(i16 %a, i16 %b, i32 %scale)
  10322. declare i32 @llvm.umul.fix.sat.i32(i32 %a, i32 %b, i32 %scale)
  10323. declare i64 @llvm.umul.fix.sat.i64(i64 %a, i64 %b, i32 %scale)
  10324. declare <4 x i32> @llvm.umul.fix.sat.v4i32(<4 x i32> %a, <4 x i32> %b, i32 %scale)
  10325. Overview
  10326. """""""""
  10327. The '``llvm.umul.fix.sat``' family of intrinsic functions perform unsigned
  10328. fixed point saturation multiplication on 2 arguments of the same scale.
  10329. Arguments
  10330. """"""""""
  10331. The arguments (%a and %b) and the result may be of integer types of any bit
  10332. width, but they must have the same bit width. ``%a`` and ``%b`` are the two
  10333. values that will undergo unsigned fixed point multiplication. The argument
  10334. ``%scale`` represents the scale of both operands, and must be a constant
  10335. integer.
  10336. Semantics:
  10337. """"""""""
  10338. This operation performs fixed point multiplication on the 2 arguments of a
  10339. specified scale. The result will also be returned in the same scale specified
  10340. in the third argument.
  10341. If the result value cannot be precisely represented in the given scale, the
  10342. value is rounded up or down to the closest representable value. The rounding
  10343. direction is unspecified.
  10344. The maximum value this operation can clamp to is the largest unsigned value
  10345. representable by the bit width of the first 2 arguments. The minimum value is the
  10346. smallest unsigned value representable by this bit width (zero).
  10347. Examples
  10348. """""""""
  10349. .. code-block:: llvm
  10350. %res = call i4 @llvm.umul.fix.sat.i4(i4 3, i4 2, i32 0) ; %res = 6 (2 x 3 = 6)
  10351. %res = call i4 @llvm.umul.fix.sat.i4(i4 3, i4 2, i32 1) ; %res = 3 (1.5 x 1 = 1.5)
  10352. ; The result in the following could be rounded down to 2 or up to 2.5
  10353. %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)
  10354. ; Saturation
  10355. %res = call i4 @llvm.umul.fix.sat.i4(i4 8, i4 2, i32 0) ; %res = 15 (8 x 2 -> clamped to 15)
  10356. %res = call i4 @llvm.umul.fix.sat.i4(i4 8, i4 8, i32 2) ; %res = 15 (2 x 2 -> clamped to 3.75)
  10357. ; Scale can affect the saturation result
  10358. %res = call i4 @llvm.umul.fix.sat.i4(i4 2, i4 4, i32 0) ; %res = 7 (2 x 4 -> clamped to 7)
  10359. %res = call i4 @llvm.umul.fix.sat.i4(i4 2, i4 4, i32 1) ; %res = 4 (1 x 2 = 2)
  10360. Specialised Arithmetic Intrinsics
  10361. ---------------------------------
  10362. '``llvm.canonicalize.*``' Intrinsic
  10363. ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  10364. Syntax:
  10365. """""""
  10366. ::
  10367. declare float @llvm.canonicalize.f32(float %a)
  10368. declare double @llvm.canonicalize.f64(double %b)
  10369. Overview:
  10370. """""""""
  10371. The '``llvm.canonicalize.*``' intrinsic returns the platform specific canonical
  10372. encoding of a floating-point number. This canonicalization is useful for
  10373. implementing certain numeric primitives such as frexp. The canonical encoding is
  10374. defined by IEEE-754-2008 to be:
  10375. ::
  10376. 2.1.8 canonical encoding: The preferred encoding of a floating-point
  10377. representation in a format. Applied to declets, significands of finite
  10378. numbers, infinities, and NaNs, especially in decimal formats.
  10379. This operation can also be considered equivalent to the IEEE-754-2008
  10380. conversion of a floating-point value to the same format. NaNs are handled
  10381. according to section 6.2.
  10382. Examples of non-canonical encodings:
  10383. - x87 pseudo denormals, pseudo NaNs, pseudo Infinity, Unnormals. These are
  10384. converted to a canonical representation per hardware-specific protocol.
  10385. - Many normal decimal floating-point numbers have non-canonical alternative
  10386. encodings.
  10387. - Some machines, like GPUs or ARMv7 NEON, do not support subnormal values.
  10388. These are treated as non-canonical encodings of zero and will be flushed to
  10389. a zero of the same sign by this operation.
  10390. Note that per IEEE-754-2008 6.2, systems that support signaling NaNs with
  10391. default exception handling must signal an invalid exception, and produce a
  10392. quiet NaN result.
  10393. This function should always be implementable as multiplication by 1.0, provided
  10394. that the compiler does not constant fold the operation. Likewise, division by
  10395. 1.0 and ``llvm.minnum(x, x)`` are possible implementations. Addition with
  10396. -0.0 is also sufficient provided that the rounding mode is not -Infinity.
  10397. ``@llvm.canonicalize`` must preserve the equality relation. That is:
  10398. - ``(@llvm.canonicalize(x) == x)`` is equivalent to ``(x == x)``
  10399. - ``(@llvm.canonicalize(x) == @llvm.canonicalize(y))`` is equivalent to
  10400. to ``(x == y)``
  10401. Additionally, the sign of zero must be conserved:
  10402. ``@llvm.canonicalize(-0.0) = -0.0`` and ``@llvm.canonicalize(+0.0) = +0.0``
  10403. The payload bits of a NaN must be conserved, with two exceptions.
  10404. First, environments which use only a single canonical representation of NaN
  10405. must perform said canonicalization. Second, SNaNs must be quieted per the
  10406. usual methods.
  10407. The canonicalization operation may be optimized away if:
  10408. - The input is known to be canonical. For example, it was produced by a
  10409. floating-point operation that is required by the standard to be canonical.
  10410. - The result is consumed only by (or fused with) other floating-point
  10411. operations. That is, the bits of the floating-point value are not examined.
  10412. '``llvm.fmuladd.*``' Intrinsic
  10413. ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  10414. Syntax:
  10415. """""""
  10416. ::
  10417. declare float @llvm.fmuladd.f32(float %a, float %b, float %c)
  10418. declare double @llvm.fmuladd.f64(double %a, double %b, double %c)
  10419. Overview:
  10420. """""""""
  10421. The '``llvm.fmuladd.*``' intrinsic functions represent multiply-add
  10422. expressions that can be fused if the code generator determines that (a) the
  10423. target instruction set has support for a fused operation, and (b) that the
  10424. fused operation is more efficient than the equivalent, separate pair of mul
  10425. and add instructions.
  10426. Arguments:
  10427. """"""""""
  10428. The '``llvm.fmuladd.*``' intrinsics each take three arguments: two
  10429. multiplicands, a and b, and an addend c.
  10430. Semantics:
  10431. """"""""""
  10432. The expression:
  10433. ::
  10434. %0 = call float @llvm.fmuladd.f32(%a, %b, %c)
  10435. is equivalent to the expression a \* b + c, except that it is unspecified
  10436. whether rounding will be performed between the multiplication and addition
  10437. steps. Fusion is not guaranteed, even if the target platform supports it.
  10438. If a fused multiply-add is required, the corresponding
  10439. :ref:`llvm.fma <int_fma>` intrinsic function should be used instead.
  10440. This never sets errno, just as '``llvm.fma.*``'.
  10441. Examples:
  10442. """""""""
  10443. .. code-block:: llvm
  10444. %r2 = call float @llvm.fmuladd.f32(float %a, float %b, float %c) ; yields float:r2 = (a * b) + c
  10445. Experimental Vector Reduction Intrinsics
  10446. ----------------------------------------
  10447. Horizontal reductions of vectors can be expressed using the following
  10448. intrinsics. Each one takes a vector operand as an input and applies its
  10449. respective operation across all elements of the vector, returning a single
  10450. scalar result of the same element type.
  10451. '``llvm.experimental.vector.reduce.add.*``' Intrinsic
  10452. ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  10453. Syntax:
  10454. """""""
  10455. ::
  10456. declare i32 @llvm.experimental.vector.reduce.add.v4i32(<4 x i32> %a)
  10457. declare i64 @llvm.experimental.vector.reduce.add.v2i64(<2 x i64> %a)
  10458. Overview:
  10459. """""""""
  10460. The '``llvm.experimental.vector.reduce.add.*``' intrinsics do an integer ``ADD``
  10461. reduction of a vector, returning the result as a scalar. The return type matches
  10462. the element-type of the vector input.
  10463. Arguments:
  10464. """"""""""
  10465. The argument to this intrinsic must be a vector of integer values.
  10466. '``llvm.experimental.vector.reduce.v2.fadd.*``' Intrinsic
  10467. ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  10468. Syntax:
  10469. """""""
  10470. ::
  10471. declare float @llvm.experimental.vector.reduce.v2.fadd.f32.v4f32(float %start_value, <4 x float> %a)
  10472. declare double @llvm.experimental.vector.reduce.v2.fadd.f64.v2f64(double %start_value, <2 x double> %a)
  10473. Overview:
  10474. """""""""
  10475. The '``llvm.experimental.vector.reduce.v2.fadd.*``' intrinsics do a floating-point
  10476. ``ADD`` reduction of a vector, returning the result as a scalar. The return type
  10477. matches the element-type of the vector input.
  10478. If the intrinsic call has the 'reassoc' or 'fast' flags set, then the
  10479. reduction will not preserve the associativity of an equivalent scalarized
  10480. counterpart. Otherwise the reduction will be *ordered*, thus implying that
  10481. the operation respects the associativity of a scalarized reduction.
  10482. Arguments:
  10483. """"""""""
  10484. The first argument to this intrinsic is a scalar start value for the reduction.
  10485. The type of the start value matches the element-type of the vector input.
  10486. The second argument must be a vector of floating-point values.
  10487. Examples:
  10488. """""""""
  10489. ::
  10490. %unord = call reassoc float @llvm.experimental.vector.reduce.v2.fadd.f32.v4f32(float 0.0, <4 x float> %input) ; unordered reduction
  10491. %ord = call float @llvm.experimental.vector.reduce.v2.fadd.f32.v4f32(float %start_value, <4 x float> %input) ; ordered reduction
  10492. '``llvm.experimental.vector.reduce.mul.*``' Intrinsic
  10493. ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  10494. Syntax:
  10495. """""""
  10496. ::
  10497. declare i32 @llvm.experimental.vector.reduce.mul.v4i32(<4 x i32> %a)
  10498. declare i64 @llvm.experimental.vector.reduce.mul.v2i64(<2 x i64> %a)
  10499. Overview:
  10500. """""""""
  10501. The '``llvm.experimental.vector.reduce.mul.*``' intrinsics do an integer ``MUL``
  10502. reduction of a vector, returning the result as a scalar. The return type matches
  10503. the element-type of the vector input.
  10504. Arguments:
  10505. """"""""""
  10506. The argument to this intrinsic must be a vector of integer values.
  10507. '``llvm.experimental.vector.reduce.v2.fmul.*``' Intrinsic
  10508. ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  10509. Syntax:
  10510. """""""
  10511. ::
  10512. declare float @llvm.experimental.vector.reduce.v2.fmul.f32.v4f32(float %start_value, <4 x float> %a)
  10513. declare double @llvm.experimental.vector.reduce.v2.fmul.f64.v2f64(double %start_value, <2 x double> %a)
  10514. Overview:
  10515. """""""""
  10516. The '``llvm.experimental.vector.reduce.v2.fmul.*``' intrinsics do a floating-point
  10517. ``MUL`` reduction of a vector, returning the result as a scalar. The return type
  10518. matches the element-type of the vector input.
  10519. If the intrinsic call has the 'reassoc' or 'fast' flags set, then the
  10520. reduction will not preserve the associativity of an equivalent scalarized
  10521. counterpart. Otherwise the reduction will be *ordered*, thus implying that
  10522. the operation respects the associativity of a scalarized reduction.
  10523. Arguments:
  10524. """"""""""
  10525. The first argument to this intrinsic is a scalar start value for the reduction.
  10526. The type of the start value matches the element-type of the vector input.
  10527. The second argument must be a vector of floating-point values.
  10528. Examples:
  10529. """""""""
  10530. ::
  10531. %unord = call reassoc float @llvm.experimental.vector.reduce.v2.fmul.f32.v4f32(float 1.0, <4 x float> %input) ; unordered reduction
  10532. %ord = call float @llvm.experimental.vector.reduce.v2.fmul.f32.v4f32(float %start_value, <4 x float> %input) ; ordered reduction
  10533. '``llvm.experimental.vector.reduce.and.*``' Intrinsic
  10534. ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  10535. Syntax:
  10536. """""""
  10537. ::
  10538. declare i32 @llvm.experimental.vector.reduce.and.v4i32(<4 x i32> %a)
  10539. Overview:
  10540. """""""""
  10541. The '``llvm.experimental.vector.reduce.and.*``' intrinsics do a bitwise ``AND``
  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.or.*``' Intrinsic
  10548. ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  10549. Syntax:
  10550. """""""
  10551. ::
  10552. declare i32 @llvm.experimental.vector.reduce.or.v4i32(<4 x i32> %a)
  10553. Overview:
  10554. """""""""
  10555. The '``llvm.experimental.vector.reduce.or.*``' intrinsics do a bitwise ``OR`` reduction
  10556. of a vector, returning the result as a scalar. The return type matches the
  10557. 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.xor.*``' Intrinsic
  10562. ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  10563. Syntax:
  10564. """""""
  10565. ::
  10566. declare i32 @llvm.experimental.vector.reduce.xor.v4i32(<4 x i32> %a)
  10567. Overview:
  10568. """""""""
  10569. The '``llvm.experimental.vector.reduce.xor.*``' intrinsics do a bitwise ``XOR``
  10570. reduction of a vector, returning the result as a scalar. The return type matches
  10571. 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.smax.*``' Intrinsic
  10576. ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  10577. Syntax:
  10578. """""""
  10579. ::
  10580. declare i32 @llvm.experimental.vector.reduce.smax.v4i32(<4 x i32> %a)
  10581. Overview:
  10582. """""""""
  10583. The '``llvm.experimental.vector.reduce.smax.*``' intrinsics do a signed integer
  10584. ``MAX`` reduction of a vector, returning the result as a scalar. The return type
  10585. 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.smin.*``' Intrinsic
  10590. ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  10591. Syntax:
  10592. """""""
  10593. ::
  10594. declare i32 @llvm.experimental.vector.reduce.smin.v4i32(<4 x i32> %a)
  10595. Overview:
  10596. """""""""
  10597. The '``llvm.experimental.vector.reduce.smin.*``' intrinsics do a signed integer
  10598. ``MIN`` reduction of a vector, returning the result as a scalar. The return type
  10599. 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.umax.*``' Intrinsic
  10604. ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  10605. Syntax:
  10606. """""""
  10607. ::
  10608. declare i32 @llvm.experimental.vector.reduce.umax.v4i32(<4 x i32> %a)
  10609. Overview:
  10610. """""""""
  10611. The '``llvm.experimental.vector.reduce.umax.*``' intrinsics do an unsigned
  10612. integer ``MAX`` reduction of a vector, returning the result as a scalar. The
  10613. return type matches the element-type of the vector input.
  10614. Arguments:
  10615. """"""""""
  10616. The argument to this intrinsic must be a vector of integer values.
  10617. '``llvm.experimental.vector.reduce.umin.*``' Intrinsic
  10618. ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  10619. Syntax:
  10620. """""""
  10621. ::
  10622. declare i32 @llvm.experimental.vector.reduce.umin.v4i32(<4 x i32> %a)
  10623. Overview:
  10624. """""""""
  10625. The '``llvm.experimental.vector.reduce.umin.*``' intrinsics do an unsigned
  10626. integer ``MIN`` reduction of a vector, returning the result as a scalar. The
  10627. return type matches the element-type of the vector input.
  10628. Arguments:
  10629. """"""""""
  10630. The argument to this intrinsic must be a vector of integer values.
  10631. '``llvm.experimental.vector.reduce.fmax.*``' Intrinsic
  10632. ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  10633. Syntax:
  10634. """""""
  10635. ::
  10636. declare float @llvm.experimental.vector.reduce.fmax.v4f32(<4 x float> %a)
  10637. declare double @llvm.experimental.vector.reduce.fmax.v2f64(<2 x double> %a)
  10638. Overview:
  10639. """""""""
  10640. The '``llvm.experimental.vector.reduce.fmax.*``' intrinsics do a floating-point
  10641. ``MAX`` reduction of a vector, returning the result as a scalar. The return type
  10642. matches the element-type of the vector input.
  10643. If the intrinsic call has the ``nnan`` fast-math flag then the operation can
  10644. assume that NaNs are not present in the input vector.
  10645. Arguments:
  10646. """"""""""
  10647. The argument to this intrinsic must be a vector of floating-point values.
  10648. '``llvm.experimental.vector.reduce.fmin.*``' Intrinsic
  10649. ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  10650. Syntax:
  10651. """""""
  10652. ::
  10653. declare float @llvm.experimental.vector.reduce.fmin.v4f32(<4 x float> %a)
  10654. declare double @llvm.experimental.vector.reduce.fmin.v2f64(<2 x double> %a)
  10655. Overview:
  10656. """""""""
  10657. The '``llvm.experimental.vector.reduce.fmin.*``' intrinsics do a floating-point
  10658. ``MIN`` reduction of a vector, returning the result as a scalar. The return type
  10659. matches the element-type of the vector input.
  10660. If the intrinsic call has the ``nnan`` fast-math flag then the operation can
  10661. assume that NaNs are not present in the input vector.
  10662. Arguments:
  10663. """"""""""
  10664. The argument to this intrinsic must be a vector of floating-point values.
  10665. Half Precision Floating-Point Intrinsics
  10666. ----------------------------------------
  10667. For most target platforms, half precision floating-point is a
  10668. storage-only format. This means that it is a dense encoding (in memory)
  10669. but does not support computation in the format.
  10670. This means that code must first load the half-precision floating-point
  10671. value as an i16, then convert it to float with
  10672. :ref:`llvm.convert.from.fp16 <int_convert_from_fp16>`. Computation can
  10673. then be performed on the float value (including extending to double
  10674. etc). To store the value back to memory, it is first converted to float
  10675. if needed, then converted to i16 with
  10676. :ref:`llvm.convert.to.fp16 <int_convert_to_fp16>`, then storing as an
  10677. i16 value.
  10678. .. _int_convert_to_fp16:
  10679. '``llvm.convert.to.fp16``' Intrinsic
  10680. ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  10681. Syntax:
  10682. """""""
  10683. ::
  10684. declare i16 @llvm.convert.to.fp16.f32(float %a)
  10685. declare i16 @llvm.convert.to.fp16.f64(double %a)
  10686. Overview:
  10687. """""""""
  10688. The '``llvm.convert.to.fp16``' intrinsic function performs a conversion from a
  10689. conventional floating-point type to half precision floating-point format.
  10690. Arguments:
  10691. """"""""""
  10692. The intrinsic function contains single argument - the value to be
  10693. converted.
  10694. Semantics:
  10695. """"""""""
  10696. The '``llvm.convert.to.fp16``' intrinsic function performs a conversion from a
  10697. conventional floating-point format to half precision floating-point format. The
  10698. return value is an ``i16`` which contains the converted number.
  10699. Examples:
  10700. """""""""
  10701. .. code-block:: llvm
  10702. %res = call i16 @llvm.convert.to.fp16.f32(float %a)
  10703. store i16 %res, i16* @x, align 2
  10704. .. _int_convert_from_fp16:
  10705. '``llvm.convert.from.fp16``' Intrinsic
  10706. ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  10707. Syntax:
  10708. """""""
  10709. ::
  10710. declare float @llvm.convert.from.fp16.f32(i16 %a)
  10711. declare double @llvm.convert.from.fp16.f64(i16 %a)
  10712. Overview:
  10713. """""""""
  10714. The '``llvm.convert.from.fp16``' intrinsic function performs a
  10715. conversion from half precision floating-point format to single precision
  10716. floating-point format.
  10717. Arguments:
  10718. """"""""""
  10719. The intrinsic function contains single argument - the value to be
  10720. converted.
  10721. Semantics:
  10722. """"""""""
  10723. The '``llvm.convert.from.fp16``' intrinsic function performs a
  10724. conversion from half single precision floating-point format to single
  10725. precision floating-point format. The input half-float value is
  10726. represented by an ``i16`` value.
  10727. Examples:
  10728. """""""""
  10729. .. code-block:: llvm
  10730. %a = load i16, i16* @x, align 2
  10731. %res = call float @llvm.convert.from.fp16(i16 %a)
  10732. .. _dbg_intrinsics:
  10733. Debugger Intrinsics
  10734. -------------------
  10735. The LLVM debugger intrinsics (which all start with ``llvm.dbg.``
  10736. prefix), are described in the `LLVM Source Level
  10737. Debugging <SourceLevelDebugging.html#format-common-intrinsics>`_
  10738. document.
  10739. Exception Handling Intrinsics
  10740. -----------------------------
  10741. The LLVM exception handling intrinsics (which all start with
  10742. ``llvm.eh.`` prefix), are described in the `LLVM Exception
  10743. Handling <ExceptionHandling.html#format-common-intrinsics>`_ document.
  10744. .. _int_trampoline:
  10745. Trampoline Intrinsics
  10746. ---------------------
  10747. These intrinsics make it possible to excise one parameter, marked with
  10748. the :ref:`nest <nest>` attribute, from a function. The result is a
  10749. callable function pointer lacking the nest parameter - the caller does
  10750. not need to provide a value for it. Instead, the value to use is stored
  10751. in advance in a "trampoline", a block of memory usually allocated on the
  10752. stack, which also contains code to splice the nest value into the
  10753. argument list. This is used to implement the GCC nested function address
  10754. extension.
  10755. For example, if the function is ``i32 f(i8* nest %c, i32 %x, i32 %y)``
  10756. then the resulting function pointer has signature ``i32 (i32, i32)*``.
  10757. It can be created as follows:
  10758. .. code-block:: llvm
  10759. %tramp = alloca [10 x i8], align 4 ; size and alignment only correct for X86
  10760. %tramp1 = getelementptr [10 x i8], [10 x i8]* %tramp, i32 0, i32 0
  10761. call i8* @llvm.init.trampoline(i8* %tramp1, i8* bitcast (i32 (i8*, i32, i32)* @f to i8*), i8* %nval)
  10762. %p = call i8* @llvm.adjust.trampoline(i8* %tramp1)
  10763. %fp = bitcast i8* %p to i32 (i32, i32)*
  10764. The call ``%val = call i32 %fp(i32 %x, i32 %y)`` is then equivalent to
  10765. ``%val = call i32 %f(i8* %nval, i32 %x, i32 %y)``.
  10766. .. _int_it:
  10767. '``llvm.init.trampoline``' Intrinsic
  10768. ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  10769. Syntax:
  10770. """""""
  10771. ::
  10772. declare void @llvm.init.trampoline(i8* <tramp>, i8* <func>, i8* <nval>)
  10773. Overview:
  10774. """""""""
  10775. This fills the memory pointed to by ``tramp`` with executable code,
  10776. turning it into a trampoline.
  10777. Arguments:
  10778. """"""""""
  10779. The ``llvm.init.trampoline`` intrinsic takes three arguments, all
  10780. pointers. The ``tramp`` argument must point to a sufficiently large and
  10781. sufficiently aligned block of memory; this memory is written to by the
  10782. intrinsic. Note that the size and the alignment are target-specific -
  10783. LLVM currently provides no portable way of determining them, so a
  10784. front-end that generates this intrinsic needs to have some
  10785. target-specific knowledge. The ``func`` argument must hold a function
  10786. bitcast to an ``i8*``.
  10787. Semantics:
  10788. """"""""""
  10789. The block of memory pointed to by ``tramp`` is filled with target
  10790. dependent code, turning it into a function. Then ``tramp`` needs to be
  10791. passed to :ref:`llvm.adjust.trampoline <int_at>` to get a pointer which can
  10792. be :ref:`bitcast (to a new function) and called <int_trampoline>`. The new
  10793. function's signature is the same as that of ``func`` with any arguments
  10794. marked with the ``nest`` attribute removed. At most one such ``nest``
  10795. argument is allowed, and it must be of pointer type. Calling the new
  10796. function is equivalent to calling ``func`` with the same argument list,
  10797. but with ``nval`` used for the missing ``nest`` argument. If, after
  10798. calling ``llvm.init.trampoline``, the memory pointed to by ``tramp`` is
  10799. modified, then the effect of any later call to the returned function
  10800. pointer is undefined.
  10801. .. _int_at:
  10802. '``llvm.adjust.trampoline``' Intrinsic
  10803. ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  10804. Syntax:
  10805. """""""
  10806. ::
  10807. declare i8* @llvm.adjust.trampoline(i8* <tramp>)
  10808. Overview:
  10809. """""""""
  10810. This performs any required machine-specific adjustment to the address of
  10811. a trampoline (passed as ``tramp``).
  10812. Arguments:
  10813. """"""""""
  10814. ``tramp`` must point to a block of memory which already has trampoline
  10815. code filled in by a previous call to
  10816. :ref:`llvm.init.trampoline <int_it>`.
  10817. Semantics:
  10818. """"""""""
  10819. On some architectures the address of the code to be executed needs to be
  10820. different than the address where the trampoline is actually stored. This
  10821. intrinsic returns the executable address corresponding to ``tramp``
  10822. after performing the required machine specific adjustments. The pointer
  10823. returned can then be :ref:`bitcast and executed <int_trampoline>`.
  10824. .. _int_mload_mstore:
  10825. Masked Vector Load and Store Intrinsics
  10826. ---------------------------------------
  10827. 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.
  10828. .. _int_mload:
  10829. '``llvm.masked.load.*``' Intrinsics
  10830. ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  10831. Syntax:
  10832. """""""
  10833. This is an overloaded intrinsic. The loaded data is a vector of any integer, floating-point or pointer data type.
  10834. ::
  10835. declare <16 x float> @llvm.masked.load.v16f32.p0v16f32 (<16 x float>* <ptr>, i32 <alignment>, <16 x i1> <mask>, <16 x float> <passthru>)
  10836. declare <2 x double> @llvm.masked.load.v2f64.p0v2f64 (<2 x double>* <ptr>, i32 <alignment>, <2 x i1> <mask>, <2 x double> <passthru>)
  10837. ;; The data is a vector of pointers to double
  10838. declare <8 x double*> @llvm.masked.load.v8p0f64.p0v8p0f64 (<8 x double*>* <ptr>, i32 <alignment>, <8 x i1> <mask>, <8 x double*> <passthru>)
  10839. ;; The data is a vector of function pointers
  10840. 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>)
  10841. Overview:
  10842. """""""""
  10843. 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.
  10844. Arguments:
  10845. """"""""""
  10846. 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.
  10847. Semantics:
  10848. """"""""""
  10849. 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.
  10850. 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.
  10851. ::
  10852. %res = call <16 x float> @llvm.masked.load.v16f32.p0v16f32 (<16 x float>* %ptr, i32 4, <16 x i1>%mask, <16 x float> %passthru)
  10853. ;; The result of the two following instructions is identical aside from potential memory access exception
  10854. %loadlal = load <16 x float>, <16 x float>* %ptr, align 4
  10855. %res = select <16 x i1> %mask, <16 x float> %loadlal, <16 x float> %passthru
  10856. .. _int_mstore:
  10857. '``llvm.masked.store.*``' Intrinsics
  10858. ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  10859. Syntax:
  10860. """""""
  10861. This is an overloaded intrinsic. The data stored in memory is a vector of any integer, floating-point or pointer data type.
  10862. ::
  10863. declare void @llvm.masked.store.v8i32.p0v8i32 (<8 x i32> <value>, <8 x i32>* <ptr>, i32 <alignment>, <8 x i1> <mask>)
  10864. declare void @llvm.masked.store.v16f32.p0v16f32 (<16 x float> <value>, <16 x float>* <ptr>, i32 <alignment>, <16 x i1> <mask>)
  10865. ;; The data is a vector of pointers to double
  10866. declare void @llvm.masked.store.v8p0f64.p0v8p0f64 (<8 x double*> <value>, <8 x double*>* <ptr>, i32 <alignment>, <8 x i1> <mask>)
  10867. ;; The data is a vector of function pointers
  10868. declare void @llvm.masked.store.v4p0f_i32f.p0v4p0f_i32f (<4 x i32 ()*> <value>, <4 x i32 ()*>* <ptr>, i32 <alignment>, <4 x i1> <mask>)
  10869. Overview:
  10870. """""""""
  10871. 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.
  10872. Arguments:
  10873. """"""""""
  10874. 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.
  10875. Semantics:
  10876. """"""""""
  10877. 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.
  10878. 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.
  10879. ::
  10880. call void @llvm.masked.store.v16f32.p0v16f32(<16 x float> %value, <16 x float>* %ptr, i32 4, <16 x i1> %mask)
  10881. ;; The result of the following instructions is identical aside from potential data races and memory access exceptions
  10882. %oldval = load <16 x float>, <16 x float>* %ptr, align 4
  10883. %res = select <16 x i1> %mask, <16 x float> %value, <16 x float> %oldval
  10884. store <16 x float> %res, <16 x float>* %ptr, align 4
  10885. Masked Vector Gather and Scatter Intrinsics
  10886. -------------------------------------------
  10887. 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.
  10888. .. _int_mgather:
  10889. '``llvm.masked.gather.*``' Intrinsics
  10890. ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  10891. Syntax:
  10892. """""""
  10893. 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.
  10894. ::
  10895. declare <16 x float> @llvm.masked.gather.v16f32.v16p0f32 (<16 x float*> <ptrs>, i32 <alignment>, <16 x i1> <mask>, <16 x float> <passthru>)
  10896. 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>)
  10897. declare <8 x float*> @llvm.masked.gather.v8p0f32.v8p0p0f32 (<8 x float**> <ptrs>, i32 <alignment>, <8 x i1> <mask>, <8 x float*> <passthru>)
  10898. Overview:
  10899. """""""""
  10900. 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.
  10901. Arguments:
  10902. """"""""""
  10903. 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.
  10904. Semantics:
  10905. """"""""""
  10906. 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.
  10907. 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.
  10908. ::
  10909. %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)
  10910. ;; The gather with all-true mask is equivalent to the following instruction sequence
  10911. %ptr0 = extractelement <4 x double*> %ptrs, i32 0
  10912. %ptr1 = extractelement <4 x double*> %ptrs, i32 1
  10913. %ptr2 = extractelement <4 x double*> %ptrs, i32 2
  10914. %ptr3 = extractelement <4 x double*> %ptrs, i32 3
  10915. %val0 = load double, double* %ptr0, align 8
  10916. %val1 = load double, double* %ptr1, align 8
  10917. %val2 = load double, double* %ptr2, align 8
  10918. %val3 = load double, double* %ptr3, align 8
  10919. %vec0 = insertelement <4 x double>undef, %val0, 0
  10920. %vec01 = insertelement <4 x double>%vec0, %val1, 1
  10921. %vec012 = insertelement <4 x double>%vec01, %val2, 2
  10922. %vec0123 = insertelement <4 x double>%vec012, %val3, 3
  10923. .. _int_mscatter:
  10924. '``llvm.masked.scatter.*``' Intrinsics
  10925. ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  10926. Syntax:
  10927. """""""
  10928. 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.
  10929. ::
  10930. declare void @llvm.masked.scatter.v8i32.v8p0i32 (<8 x i32> <value>, <8 x i32*> <ptrs>, i32 <alignment>, <8 x i1> <mask>)
  10931. declare void @llvm.masked.scatter.v16f32.v16p1f32 (<16 x float> <value>, <16 x float addrspace(1)*> <ptrs>, i32 <alignment>, <16 x i1> <mask>)
  10932. declare void @llvm.masked.scatter.v4p0f64.v4p0p0f64 (<4 x double*> <value>, <4 x double**> <ptrs>, i32 <alignment>, <4 x i1> <mask>)
  10933. Overview:
  10934. """""""""
  10935. 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.
  10936. Arguments:
  10937. """"""""""
  10938. 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.
  10939. Semantics:
  10940. """"""""""
  10941. 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.
  10942. ::
  10943. ;; This instruction unconditionally stores data vector in multiple addresses
  10944. call @llvm.masked.scatter.v8i32.v8p0i32 (<8 x i32> %value, <8 x i32*> %ptrs, i32 4, <8 x i1> <true, true, .. true>)
  10945. ;; It is equivalent to a list of scalar stores
  10946. %val0 = extractelement <8 x i32> %value, i32 0
  10947. %val1 = extractelement <8 x i32> %value, i32 1
  10948. ..
  10949. %val7 = extractelement <8 x i32> %value, i32 7
  10950. %ptr0 = extractelement <8 x i32*> %ptrs, i32 0
  10951. %ptr1 = extractelement <8 x i32*> %ptrs, i32 1
  10952. ..
  10953. %ptr7 = extractelement <8 x i32*> %ptrs, i32 7
  10954. ;; Note: the order of the following stores is important when they overlap:
  10955. store i32 %val0, i32* %ptr0, align 4
  10956. store i32 %val1, i32* %ptr1, align 4
  10957. ..
  10958. store i32 %val7, i32* %ptr7, align 4
  10959. Masked Vector Expanding Load and Compressing Store Intrinsics
  10960. -------------------------------------------------------------
  10961. 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>`.
  10962. .. _int_expandload:
  10963. '``llvm.masked.expandload.*``' Intrinsics
  10964. ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  10965. Syntax:
  10966. """""""
  10967. 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.
  10968. ::
  10969. declare <16 x float> @llvm.masked.expandload.v16f32 (float* <ptr>, <16 x i1> <mask>, <16 x float> <passthru>)
  10970. declare <2 x i64> @llvm.masked.expandload.v2i64 (i64* <ptr>, <2 x i1> <mask>, <2 x i64> <passthru>)
  10971. Overview:
  10972. """""""""
  10973. 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.
  10974. Arguments:
  10975. """"""""""
  10976. 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.
  10977. Semantics:
  10978. """"""""""
  10979. 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:
  10980. .. code-block:: c
  10981. // In this loop we load from B and spread the elements into array A.
  10982. double *A, B; int *C;
  10983. for (int i = 0; i < size; ++i) {
  10984. if (C[i] != 0)
  10985. A[i] = B[j++];
  10986. }
  10987. .. code-block:: llvm
  10988. ; Load several elements from array B and expand them in a vector.
  10989. ; The number of loaded elements is equal to the number of '1' elements in the Mask.
  10990. %Tmp = call <8 x double> @llvm.masked.expandload.v8f64(double* %Bptr, <8 x i1> %Mask, <8 x double> undef)
  10991. ; Store the result in A
  10992. call void @llvm.masked.store.v8f64.p0v8f64(<8 x double> %Tmp, <8 x double>* %Aptr, i32 8, <8 x i1> %Mask)
  10993. ; %Bptr should be increased on each iteration according to the number of '1' elements in the Mask.
  10994. %MaskI = bitcast <8 x i1> %Mask to i8
  10995. %MaskIPopcnt = call i8 @llvm.ctpop.i8(i8 %MaskI)
  10996. %MaskI64 = zext i8 %MaskIPopcnt to i64
  10997. %BNextInd = add i64 %BInd, %MaskI64
  10998. Other targets may support this intrinsic differently, for example, by lowering it into a sequence of conditional scalar load operations and shuffles.
  10999. If all mask elements are '1', the intrinsic behavior is equivalent to the regular unmasked vector load.
  11000. .. _int_compressstore:
  11001. '``llvm.masked.compressstore.*``' Intrinsics
  11002. ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  11003. Syntax:
  11004. """""""
  11005. 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.
  11006. ::
  11007. declare void @llvm.masked.compressstore.v8i32 (<8 x i32> <value>, i32* <ptr>, <8 x i1> <mask>)
  11008. declare void @llvm.masked.compressstore.v16f32 (<16 x float> <value>, float* <ptr>, <16 x i1> <mask>)
  11009. Overview:
  11010. """""""""
  11011. 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.
  11012. Arguments:
  11013. """"""""""
  11014. 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.
  11015. Semantics:
  11016. """"""""""
  11017. 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:
  11018. .. code-block:: c
  11019. // In this loop we load elements from A and store them consecutively in B
  11020. double *A, B; int *C;
  11021. for (int i = 0; i < size; ++i) {
  11022. if (C[i] != 0)
  11023. B[j++] = A[i]
  11024. }
  11025. .. code-block:: llvm
  11026. ; Load elements from A.
  11027. %Tmp = call <8 x double> @llvm.masked.load.v8f64.p0v8f64(<8 x double>* %Aptr, i32 8, <8 x i1> %Mask, <8 x double> undef)
  11028. ; Store all selected elements consecutively in array B
  11029. call <void> @llvm.masked.compressstore.v8f64(<8 x double> %Tmp, double* %Bptr, <8 x i1> %Mask)
  11030. ; %Bptr should be increased on each iteration according to the number of '1' elements in the Mask.
  11031. %MaskI = bitcast <8 x i1> %Mask to i8
  11032. %MaskIPopcnt = call i8 @llvm.ctpop.i8(i8 %MaskI)
  11033. %MaskI64 = zext i8 %MaskIPopcnt to i64
  11034. %BNextInd = add i64 %BInd, %MaskI64
  11035. Other targets may support this intrinsic differently, for example, by lowering it into a sequence of branches that guard scalar store operations.
  11036. Memory Use Markers
  11037. ------------------
  11038. This class of intrinsics provides information about the lifetime of
  11039. memory objects and ranges where variables are immutable.
  11040. .. _int_lifestart:
  11041. '``llvm.lifetime.start``' Intrinsic
  11042. ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  11043. Syntax:
  11044. """""""
  11045. ::
  11046. declare void @llvm.lifetime.start(i64 <size>, i8* nocapture <ptr>)
  11047. Overview:
  11048. """""""""
  11049. The '``llvm.lifetime.start``' intrinsic specifies the start of a memory
  11050. object's lifetime.
  11051. Arguments:
  11052. """"""""""
  11053. The first argument is a constant integer representing the size of the
  11054. object, or -1 if it is variable sized. The second argument is a pointer
  11055. to the object.
  11056. Semantics:
  11057. """"""""""
  11058. This intrinsic indicates that before this point in the code, the value
  11059. of the memory pointed to by ``ptr`` is dead. This means that it is known
  11060. to never be used and has an undefined value. A load from the pointer
  11061. that precedes this intrinsic can be replaced with ``'undef'``.
  11062. .. _int_lifeend:
  11063. '``llvm.lifetime.end``' Intrinsic
  11064. ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  11065. Syntax:
  11066. """""""
  11067. ::
  11068. declare void @llvm.lifetime.end(i64 <size>, i8* nocapture <ptr>)
  11069. Overview:
  11070. """""""""
  11071. The '``llvm.lifetime.end``' intrinsic specifies the end of a memory
  11072. object's lifetime.
  11073. Arguments:
  11074. """"""""""
  11075. The first argument is a constant integer representing the size of the
  11076. object, or -1 if it is variable sized. The second argument is a pointer
  11077. to the object.
  11078. Semantics:
  11079. """"""""""
  11080. This intrinsic indicates that after this point in the code, the value of
  11081. the memory pointed to by ``ptr`` is dead. This means that it is known to
  11082. never be used and has an undefined value. Any stores into the memory
  11083. object following this intrinsic may be removed as dead.
  11084. '``llvm.invariant.start``' Intrinsic
  11085. ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  11086. Syntax:
  11087. """""""
  11088. This is an overloaded intrinsic. The memory object can belong to any address space.
  11089. ::
  11090. declare {}* @llvm.invariant.start.p0i8(i64 <size>, i8* nocapture <ptr>)
  11091. Overview:
  11092. """""""""
  11093. The '``llvm.invariant.start``' intrinsic specifies that the contents of
  11094. a memory object will not change.
  11095. Arguments:
  11096. """"""""""
  11097. The first argument is a constant integer representing the size of the
  11098. object, or -1 if it is variable sized. The second argument is a pointer
  11099. to the object.
  11100. Semantics:
  11101. """"""""""
  11102. This intrinsic indicates that until an ``llvm.invariant.end`` that uses
  11103. the return value, the referenced memory location is constant and
  11104. unchanging.
  11105. '``llvm.invariant.end``' Intrinsic
  11106. ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  11107. Syntax:
  11108. """""""
  11109. This is an overloaded intrinsic. The memory object can belong to any address space.
  11110. ::
  11111. declare void @llvm.invariant.end.p0i8({}* <start>, i64 <size>, i8* nocapture <ptr>)
  11112. Overview:
  11113. """""""""
  11114. The '``llvm.invariant.end``' intrinsic specifies that the contents of a
  11115. memory object are mutable.
  11116. Arguments:
  11117. """"""""""
  11118. The first argument is the matching ``llvm.invariant.start`` intrinsic.
  11119. The second argument is a constant integer representing the size of the
  11120. object, or -1 if it is variable sized and the third argument is a
  11121. pointer to the object.
  11122. Semantics:
  11123. """"""""""
  11124. This intrinsic indicates that the memory is mutable again.
  11125. '``llvm.launder.invariant.group``' Intrinsic
  11126. ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  11127. Syntax:
  11128. """""""
  11129. This is an overloaded intrinsic. The memory object can belong to any address
  11130. space. The returned pointer must belong to the same address space as the
  11131. argument.
  11132. ::
  11133. declare i8* @llvm.launder.invariant.group.p0i8(i8* <ptr>)
  11134. Overview:
  11135. """""""""
  11136. The '``llvm.launder.invariant.group``' intrinsic can be used when an invariant
  11137. established by ``invariant.group`` metadata no longer holds, to obtain a new
  11138. pointer value that carries fresh invariant group information. It is an
  11139. experimental intrinsic, which means that its semantics might change in the
  11140. future.
  11141. Arguments:
  11142. """"""""""
  11143. The ``llvm.launder.invariant.group`` takes only one argument, which is a pointer
  11144. to the memory.
  11145. Semantics:
  11146. """"""""""
  11147. Returns another pointer that aliases its argument but which is considered different
  11148. for the purposes of ``load``/``store`` ``invariant.group`` metadata.
  11149. It does not read any accessible memory and the execution can be speculated.
  11150. '``llvm.strip.invariant.group``' Intrinsic
  11151. ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  11152. Syntax:
  11153. """""""
  11154. This is an overloaded intrinsic. The memory object can belong to any address
  11155. space. The returned pointer must belong to the same address space as the
  11156. argument.
  11157. ::
  11158. declare i8* @llvm.strip.invariant.group.p0i8(i8* <ptr>)
  11159. Overview:
  11160. """""""""
  11161. The '``llvm.strip.invariant.group``' intrinsic can be used when an invariant
  11162. established by ``invariant.group`` metadata no longer holds, to obtain a new pointer
  11163. value that does not carry the invariant information. It is an experimental
  11164. intrinsic, which means that its semantics might change in the future.
  11165. Arguments:
  11166. """"""""""
  11167. The ``llvm.strip.invariant.group`` takes only one argument, which is a pointer
  11168. to the memory.
  11169. Semantics:
  11170. """"""""""
  11171. Returns another pointer that aliases its argument but which has no associated
  11172. ``invariant.group`` metadata.
  11173. It does not read any memory and can be speculated.
  11174. .. _constrainedfp:
  11175. Constrained Floating-Point Intrinsics
  11176. -------------------------------------
  11177. These intrinsics are used to provide special handling of floating-point
  11178. operations when specific rounding mode or floating-point exception behavior is
  11179. required. By default, LLVM optimization passes assume that the rounding mode is
  11180. round-to-nearest and that floating-point exceptions will not be monitored.
  11181. Constrained FP intrinsics are used to support non-default rounding modes and
  11182. accurately preserve exception behavior without compromising LLVM's ability to
  11183. optimize FP code when the default behavior is used.
  11184. If any FP operation in a function is constrained then they all must be
  11185. constrained. This is required for correct LLVM IR. Optimizations that
  11186. move code around can create miscompiles if mixing of constrained and normal
  11187. operations is done. The correct way to mix constrained and less constrained
  11188. operations is to use the rounding mode and exception handling metadata to
  11189. mark constrained intrinsics as having LLVM's default behavior.
  11190. Each of these intrinsics corresponds to a normal floating-point operation. The
  11191. data arguments and the return value are the same as the corresponding FP
  11192. operation.
  11193. The rounding mode argument is a metadata string specifying what
  11194. assumptions, if any, the optimizer can make when transforming constant
  11195. values. Some constrained FP intrinsics omit this argument. If required
  11196. by the intrinsic, this argument must be one of the following strings:
  11197. ::
  11198. "round.dynamic"
  11199. "round.tonearest"
  11200. "round.downward"
  11201. "round.upward"
  11202. "round.towardzero"
  11203. If this argument is "round.dynamic" optimization passes must assume that the
  11204. rounding mode is unknown and may change at runtime. No transformations that
  11205. depend on rounding mode may be performed in this case.
  11206. The other possible values for the rounding mode argument correspond to the
  11207. similarly named IEEE rounding modes. If the argument is any of these values
  11208. optimization passes may perform transformations as long as they are consistent
  11209. with the specified rounding mode.
  11210. For example, 'x-0'->'x' is not a valid transformation if the rounding mode is
  11211. "round.downward" or "round.dynamic" because if the value of 'x' is +0 then
  11212. 'x-0' should evaluate to '-0' when rounding downward. However, this
  11213. transformation is legal for all other rounding modes.
  11214. For values other than "round.dynamic" optimization passes may assume that the
  11215. actual runtime rounding mode (as defined in a target-specific manner) matches
  11216. the specified rounding mode, but this is not guaranteed. Using a specific
  11217. non-dynamic rounding mode which does not match the actual rounding mode at
  11218. runtime results in undefined behavior.
  11219. The exception behavior argument is a metadata string describing the floating
  11220. point exception semantics that required for the intrinsic. This argument
  11221. must be one of the following strings:
  11222. ::
  11223. "fpexcept.ignore"
  11224. "fpexcept.maytrap"
  11225. "fpexcept.strict"
  11226. If this argument is "fpexcept.ignore" optimization passes may assume that the
  11227. exception status flags will not be read and that floating-point exceptions will
  11228. be masked. This allows transformations to be performed that may change the
  11229. exception semantics of the original code. For example, FP operations may be
  11230. speculatively executed in this case whereas they must not be for either of the
  11231. other possible values of this argument.
  11232. If the exception behavior argument is "fpexcept.maytrap" optimization passes
  11233. must avoid transformations that may raise exceptions that would not have been
  11234. raised by the original code (such as speculatively executing FP operations), but
  11235. passes are not required to preserve all exceptions that are implied by the
  11236. original code. For example, exceptions may be potentially hidden by constant
  11237. folding.
  11238. If the exception behavior argument is "fpexcept.strict" all transformations must
  11239. strictly preserve the floating-point exception semantics of the original code.
  11240. Any FP exception that would have been raised by the original code must be raised
  11241. by the transformed code, and the transformed code must not raise any FP
  11242. exceptions that would not have been raised by the original code. This is the
  11243. exception behavior argument that will be used if the code being compiled reads
  11244. the FP exception status flags, but this mode can also be used with code that
  11245. unmasks FP exceptions.
  11246. The number and order of floating-point exceptions is NOT guaranteed. For
  11247. example, a series of FP operations that each may raise exceptions may be
  11248. vectorized into a single instruction that raises each unique exception a single
  11249. time.
  11250. Proper :ref:`function attributes <fnattrs>` usage is required for the
  11251. constrained intrinsics to function correctly.
  11252. All function *calls* done in a function that uses constrained floating
  11253. point intrinsics must have the ``strictfp`` attribute.
  11254. All function *definitions* that use constrained floating point intrinsics
  11255. must have the ``strictfp`` attribute.
  11256. '``llvm.experimental.constrained.fadd``' Intrinsic
  11257. ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  11258. Syntax:
  11259. """""""
  11260. ::
  11261. declare <type>
  11262. @llvm.experimental.constrained.fadd(<type> <op1>, <type> <op2>,
  11263. metadata <rounding mode>,
  11264. metadata <exception behavior>)
  11265. Overview:
  11266. """""""""
  11267. The '``llvm.experimental.constrained.fadd``' intrinsic returns the sum of its
  11268. two operands.
  11269. Arguments:
  11270. """"""""""
  11271. The first two arguments to the '``llvm.experimental.constrained.fadd``'
  11272. intrinsic must be :ref:`floating-point <t_floating>` or :ref:`vector <t_vector>`
  11273. of floating-point values. Both arguments must have identical types.
  11274. The third and fourth arguments specify the rounding mode and exception
  11275. behavior as described above.
  11276. Semantics:
  11277. """"""""""
  11278. The value produced is the floating-point sum of the two value operands and has
  11279. the same type as the operands.
  11280. '``llvm.experimental.constrained.fsub``' Intrinsic
  11281. ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  11282. Syntax:
  11283. """""""
  11284. ::
  11285. declare <type>
  11286. @llvm.experimental.constrained.fsub(<type> <op1>, <type> <op2>,
  11287. metadata <rounding mode>,
  11288. metadata <exception behavior>)
  11289. Overview:
  11290. """""""""
  11291. The '``llvm.experimental.constrained.fsub``' intrinsic returns the difference
  11292. of its two operands.
  11293. Arguments:
  11294. """"""""""
  11295. The first two arguments to the '``llvm.experimental.constrained.fsub``'
  11296. intrinsic must be :ref:`floating-point <t_floating>` or :ref:`vector <t_vector>`
  11297. of floating-point values. Both arguments must have identical types.
  11298. The third and fourth arguments specify the rounding mode and exception
  11299. behavior as described above.
  11300. Semantics:
  11301. """"""""""
  11302. The value produced is the floating-point difference of the two value operands
  11303. and has the same type as the operands.
  11304. '``llvm.experimental.constrained.fmul``' Intrinsic
  11305. ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  11306. Syntax:
  11307. """""""
  11308. ::
  11309. declare <type>
  11310. @llvm.experimental.constrained.fmul(<type> <op1>, <type> <op2>,
  11311. metadata <rounding mode>,
  11312. metadata <exception behavior>)
  11313. Overview:
  11314. """""""""
  11315. The '``llvm.experimental.constrained.fmul``' intrinsic returns the product of
  11316. its two operands.
  11317. Arguments:
  11318. """"""""""
  11319. The first two arguments to the '``llvm.experimental.constrained.fmul``'
  11320. intrinsic must be :ref:`floating-point <t_floating>` or :ref:`vector <t_vector>`
  11321. of floating-point values. Both arguments must have identical types.
  11322. The third and fourth arguments specify the rounding mode and exception
  11323. behavior as described above.
  11324. Semantics:
  11325. """"""""""
  11326. The value produced is the floating-point product of the two value operands and
  11327. has the same type as the operands.
  11328. '``llvm.experimental.constrained.fdiv``' Intrinsic
  11329. ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  11330. Syntax:
  11331. """""""
  11332. ::
  11333. declare <type>
  11334. @llvm.experimental.constrained.fdiv(<type> <op1>, <type> <op2>,
  11335. metadata <rounding mode>,
  11336. metadata <exception behavior>)
  11337. Overview:
  11338. """""""""
  11339. The '``llvm.experimental.constrained.fdiv``' intrinsic returns the quotient of
  11340. its two operands.
  11341. Arguments:
  11342. """"""""""
  11343. The first two arguments to the '``llvm.experimental.constrained.fdiv``'
  11344. intrinsic must be :ref:`floating-point <t_floating>` or :ref:`vector <t_vector>`
  11345. of floating-point values. Both arguments must have identical types.
  11346. The third and fourth arguments specify the rounding mode and exception
  11347. behavior as described above.
  11348. Semantics:
  11349. """"""""""
  11350. The value produced is the floating-point quotient of the two value operands and
  11351. has the same type as the operands.
  11352. '``llvm.experimental.constrained.frem``' Intrinsic
  11353. ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  11354. Syntax:
  11355. """""""
  11356. ::
  11357. declare <type>
  11358. @llvm.experimental.constrained.frem(<type> <op1>, <type> <op2>,
  11359. metadata <rounding mode>,
  11360. metadata <exception behavior>)
  11361. Overview:
  11362. """""""""
  11363. The '``llvm.experimental.constrained.frem``' intrinsic returns the remainder
  11364. from the division of its two operands.
  11365. Arguments:
  11366. """"""""""
  11367. The first two arguments to the '``llvm.experimental.constrained.frem``'
  11368. intrinsic must be :ref:`floating-point <t_floating>` or :ref:`vector <t_vector>`
  11369. of floating-point values. Both arguments must have identical types.
  11370. The third and fourth arguments specify the rounding mode and exception
  11371. behavior as described above. The rounding mode argument has no effect, since
  11372. the result of frem is never rounded, but the argument is included for
  11373. consistency with the other constrained floating-point intrinsics.
  11374. Semantics:
  11375. """"""""""
  11376. The value produced is the floating-point remainder from the division of the two
  11377. value operands and has the same type as the operands. The remainder has the
  11378. same sign as the dividend.
  11379. '``llvm.experimental.constrained.fma``' Intrinsic
  11380. ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  11381. Syntax:
  11382. """""""
  11383. ::
  11384. declare <type>
  11385. @llvm.experimental.constrained.fma(<type> <op1>, <type> <op2>, <type> <op3>,
  11386. metadata <rounding mode>,
  11387. metadata <exception behavior>)
  11388. Overview:
  11389. """""""""
  11390. The '``llvm.experimental.constrained.fma``' intrinsic returns the result of a
  11391. fused-multiply-add operation on its operands.
  11392. Arguments:
  11393. """"""""""
  11394. The first three arguments to the '``llvm.experimental.constrained.fma``'
  11395. intrinsic must be :ref:`floating-point <t_floating>` or :ref:`vector
  11396. <t_vector>` of floating-point values. All arguments must have identical types.
  11397. The fourth and fifth arguments specify the rounding mode and exception behavior
  11398. as described above.
  11399. Semantics:
  11400. """"""""""
  11401. The result produced is the product of the first two operands added to the third
  11402. operand computed with infinite precision, and then rounded to the target
  11403. precision.
  11404. '``llvm.experimental.constrained.fptoui``' Intrinsic
  11405. ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  11406. Syntax:
  11407. """""""
  11408. ::
  11409. declare <ty2>
  11410. @llvm.experimental.constrained.fptoui(<type> <value>,
  11411. metadata <exception behavior>)
  11412. Overview:
  11413. """""""""
  11414. The '``llvm.experimental.constrained.fptoui``' intrinsic converts a
  11415. floating-point ``value`` to its unsigned integer equivalent of type ``ty2``.
  11416. Arguments:
  11417. """"""""""
  11418. The first argument to the '``llvm.experimental.constrained.fptoui``'
  11419. intrinsic must be :ref:`floating point <t_floating>` or :ref:`vector
  11420. <t_vector>` of floating point values.
  11421. The second argument specifies the exception behavior as described above.
  11422. Semantics:
  11423. """"""""""
  11424. The result produced is an unsigned integer converted from the floating
  11425. point operand. The value is truncated, so it is rounded towards zero.
  11426. '``llvm.experimental.constrained.fptosi``' Intrinsic
  11427. ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  11428. Syntax:
  11429. """""""
  11430. ::
  11431. declare <ty2>
  11432. @llvm.experimental.constrained.fptosi(<type> <value>,
  11433. metadata <exception behavior>)
  11434. Overview:
  11435. """""""""
  11436. The '``llvm.experimental.constrained.fptosi``' intrinsic converts
  11437. :ref:`floating-point <t_floating>` ``value`` to type ``ty2``.
  11438. Arguments:
  11439. """"""""""
  11440. The first argument to the '``llvm.experimental.constrained.fptosi``'
  11441. intrinsic must be :ref:`floating point <t_floating>` or :ref:`vector
  11442. <t_vector>` of floating point values.
  11443. The second argument specifies the exception behavior as described above.
  11444. Semantics:
  11445. """"""""""
  11446. The result produced is a signed integer converted from the floating
  11447. point operand. The value is truncated, so it is rounded towards zero.
  11448. '``llvm.experimental.constrained.fptrunc``' Intrinsic
  11449. ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  11450. Syntax:
  11451. """""""
  11452. ::
  11453. declare <ty2>
  11454. @llvm.experimental.constrained.fptrunc(<type> <value>,
  11455. metadata <rounding mode>,
  11456. metadata <exception behavior>)
  11457. Overview:
  11458. """""""""
  11459. The '``llvm.experimental.constrained.fptrunc``' intrinsic truncates ``value``
  11460. to type ``ty2``.
  11461. Arguments:
  11462. """"""""""
  11463. The first argument to the '``llvm.experimental.constrained.fptrunc``'
  11464. intrinsic must be :ref:`floating point <t_floating>` or :ref:`vector
  11465. <t_vector>` of floating point values. This argument must be larger in size
  11466. than the result.
  11467. The second and third arguments specify the rounding mode and exception
  11468. behavior as described above.
  11469. Semantics:
  11470. """"""""""
  11471. The result produced is a floating point value truncated to be smaller in size
  11472. than the operand.
  11473. '``llvm.experimental.constrained.fpext``' Intrinsic
  11474. ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  11475. Syntax:
  11476. """""""
  11477. ::
  11478. declare <ty2>
  11479. @llvm.experimental.constrained.fpext(<type> <value>,
  11480. metadata <exception behavior>)
  11481. Overview:
  11482. """""""""
  11483. The '``llvm.experimental.constrained.fpext``' intrinsic extends a
  11484. floating-point ``value`` to a larger floating-point value.
  11485. Arguments:
  11486. """"""""""
  11487. The first argument to the '``llvm.experimental.constrained.fpext``'
  11488. intrinsic must be :ref:`floating point <t_floating>` or :ref:`vector
  11489. <t_vector>` of floating point values. This argument must be smaller in size
  11490. than the result.
  11491. The second argument specifies the exception behavior as described above.
  11492. Semantics:
  11493. """"""""""
  11494. The result produced is a floating point value extended to be larger in size
  11495. than the operand. All restrictions that apply to the fpext instruction also
  11496. apply to this intrinsic.
  11497. Constrained libm-equivalent Intrinsics
  11498. --------------------------------------
  11499. In addition to the basic floating-point operations for which constrained
  11500. intrinsics are described above, there are constrained versions of various
  11501. operations which provide equivalent behavior to a corresponding libm function.
  11502. These intrinsics allow the precise behavior of these operations with respect to
  11503. rounding mode and exception behavior to be controlled.
  11504. As with the basic constrained floating-point intrinsics, the rounding mode
  11505. and exception behavior arguments only control the behavior of the optimizer.
  11506. They do not change the runtime floating-point environment.
  11507. '``llvm.experimental.constrained.sqrt``' Intrinsic
  11508. ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  11509. Syntax:
  11510. """""""
  11511. ::
  11512. declare <type>
  11513. @llvm.experimental.constrained.sqrt(<type> <op1>,
  11514. metadata <rounding mode>,
  11515. metadata <exception behavior>)
  11516. Overview:
  11517. """""""""
  11518. The '``llvm.experimental.constrained.sqrt``' intrinsic returns the square root
  11519. of the specified value, returning the same value as the libm '``sqrt``'
  11520. functions would, but without setting ``errno``.
  11521. Arguments:
  11522. """"""""""
  11523. The first argument and the return type are floating-point numbers of the same
  11524. type.
  11525. The second and third arguments specify the rounding mode and exception
  11526. behavior as described above.
  11527. Semantics:
  11528. """"""""""
  11529. This function returns the nonnegative square root of the specified value.
  11530. If the value is less than negative zero, a floating-point exception occurs
  11531. and the return value is architecture specific.
  11532. '``llvm.experimental.constrained.pow``' Intrinsic
  11533. ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  11534. Syntax:
  11535. """""""
  11536. ::
  11537. declare <type>
  11538. @llvm.experimental.constrained.pow(<type> <op1>, <type> <op2>,
  11539. metadata <rounding mode>,
  11540. metadata <exception behavior>)
  11541. Overview:
  11542. """""""""
  11543. The '``llvm.experimental.constrained.pow``' intrinsic returns the first operand
  11544. raised to the (positive or negative) power specified by the second operand.
  11545. Arguments:
  11546. """"""""""
  11547. The first two arguments and the return value are floating-point numbers of the
  11548. same type. The second argument specifies the power to which the first argument
  11549. should be raised.
  11550. The third and fourth arguments specify the rounding mode and exception
  11551. behavior as described above.
  11552. Semantics:
  11553. """"""""""
  11554. This function returns the first value raised to the second power,
  11555. returning the same values as the libm ``pow`` functions would, and
  11556. handles error conditions in the same way.
  11557. '``llvm.experimental.constrained.powi``' Intrinsic
  11558. ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  11559. Syntax:
  11560. """""""
  11561. ::
  11562. declare <type>
  11563. @llvm.experimental.constrained.powi(<type> <op1>, i32 <op2>,
  11564. metadata <rounding mode>,
  11565. metadata <exception behavior>)
  11566. Overview:
  11567. """""""""
  11568. The '``llvm.experimental.constrained.powi``' intrinsic returns the first operand
  11569. raised to the (positive or negative) power specified by the second operand. The
  11570. order of evaluation of multiplications is not defined. When a vector of
  11571. floating-point type is used, the second argument remains a scalar integer value.
  11572. Arguments:
  11573. """"""""""
  11574. The first argument and the return value are floating-point numbers of the same
  11575. type. The second argument is a 32-bit signed integer specifying the power to
  11576. which the first argument should be raised.
  11577. The third and fourth arguments specify the rounding mode and exception
  11578. behavior as described above.
  11579. Semantics:
  11580. """"""""""
  11581. This function returns the first value raised to the second power with an
  11582. unspecified sequence of rounding operations.
  11583. '``llvm.experimental.constrained.sin``' Intrinsic
  11584. ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  11585. Syntax:
  11586. """""""
  11587. ::
  11588. declare <type>
  11589. @llvm.experimental.constrained.sin(<type> <op1>,
  11590. metadata <rounding mode>,
  11591. metadata <exception behavior>)
  11592. Overview:
  11593. """""""""
  11594. The '``llvm.experimental.constrained.sin``' intrinsic returns the sine of the
  11595. first operand.
  11596. Arguments:
  11597. """"""""""
  11598. The first argument and the return type are floating-point numbers of the same
  11599. type.
  11600. The second and third arguments specify the rounding mode and exception
  11601. behavior as described above.
  11602. Semantics:
  11603. """"""""""
  11604. This function returns the sine of the specified operand, returning the
  11605. same values as the libm ``sin`` functions would, and handles error
  11606. conditions in the same way.
  11607. '``llvm.experimental.constrained.cos``' Intrinsic
  11608. ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  11609. Syntax:
  11610. """""""
  11611. ::
  11612. declare <type>
  11613. @llvm.experimental.constrained.cos(<type> <op1>,
  11614. metadata <rounding mode>,
  11615. metadata <exception behavior>)
  11616. Overview:
  11617. """""""""
  11618. The '``llvm.experimental.constrained.cos``' intrinsic returns the cosine of the
  11619. first operand.
  11620. Arguments:
  11621. """"""""""
  11622. The first argument and the return type are floating-point numbers of the same
  11623. type.
  11624. The second and third arguments specify the rounding mode and exception
  11625. behavior as described above.
  11626. Semantics:
  11627. """"""""""
  11628. This function returns the cosine of the specified operand, returning the
  11629. same values as the libm ``cos`` functions would, and handles error
  11630. conditions in the same way.
  11631. '``llvm.experimental.constrained.exp``' Intrinsic
  11632. ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  11633. Syntax:
  11634. """""""
  11635. ::
  11636. declare <type>
  11637. @llvm.experimental.constrained.exp(<type> <op1>,
  11638. metadata <rounding mode>,
  11639. metadata <exception behavior>)
  11640. Overview:
  11641. """""""""
  11642. The '``llvm.experimental.constrained.exp``' intrinsic computes the base-e
  11643. exponential of the specified value.
  11644. Arguments:
  11645. """"""""""
  11646. The first argument and the return value are floating-point numbers of the same
  11647. type.
  11648. The second and third arguments specify the rounding mode and exception
  11649. behavior as described above.
  11650. Semantics:
  11651. """"""""""
  11652. This function returns the same values as the libm ``exp`` functions
  11653. would, and handles error conditions in the same way.
  11654. '``llvm.experimental.constrained.exp2``' Intrinsic
  11655. ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  11656. Syntax:
  11657. """""""
  11658. ::
  11659. declare <type>
  11660. @llvm.experimental.constrained.exp2(<type> <op1>,
  11661. metadata <rounding mode>,
  11662. metadata <exception behavior>)
  11663. Overview:
  11664. """""""""
  11665. The '``llvm.experimental.constrained.exp2``' intrinsic computes the base-2
  11666. exponential of the specified value.
  11667. Arguments:
  11668. """"""""""
  11669. The first argument and the return value are floating-point numbers of the same
  11670. type.
  11671. The second and third arguments specify the rounding mode and exception
  11672. behavior as described above.
  11673. Semantics:
  11674. """"""""""
  11675. This function returns the same values as the libm ``exp2`` functions
  11676. would, and handles error conditions in the same way.
  11677. '``llvm.experimental.constrained.log``' Intrinsic
  11678. ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  11679. Syntax:
  11680. """""""
  11681. ::
  11682. declare <type>
  11683. @llvm.experimental.constrained.log(<type> <op1>,
  11684. metadata <rounding mode>,
  11685. metadata <exception behavior>)
  11686. Overview:
  11687. """""""""
  11688. The '``llvm.experimental.constrained.log``' intrinsic computes the base-e
  11689. logarithm of the specified value.
  11690. Arguments:
  11691. """"""""""
  11692. The first argument and the return value are floating-point numbers of the same
  11693. type.
  11694. The second and third arguments specify the rounding mode and exception
  11695. behavior as described above.
  11696. Semantics:
  11697. """"""""""
  11698. This function returns the same values as the libm ``log`` functions
  11699. would, and handles error conditions in the same way.
  11700. '``llvm.experimental.constrained.log10``' Intrinsic
  11701. ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  11702. Syntax:
  11703. """""""
  11704. ::
  11705. declare <type>
  11706. @llvm.experimental.constrained.log10(<type> <op1>,
  11707. metadata <rounding mode>,
  11708. metadata <exception behavior>)
  11709. Overview:
  11710. """""""""
  11711. The '``llvm.experimental.constrained.log10``' intrinsic computes the base-10
  11712. logarithm of the specified value.
  11713. Arguments:
  11714. """"""""""
  11715. The first argument and the return value are floating-point numbers of the same
  11716. type.
  11717. The second and third arguments specify the rounding mode and exception
  11718. behavior as described above.
  11719. Semantics:
  11720. """"""""""
  11721. This function returns the same values as the libm ``log10`` functions
  11722. would, and handles error conditions in the same way.
  11723. '``llvm.experimental.constrained.log2``' Intrinsic
  11724. ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  11725. Syntax:
  11726. """""""
  11727. ::
  11728. declare <type>
  11729. @llvm.experimental.constrained.log2(<type> <op1>,
  11730. metadata <rounding mode>,
  11731. metadata <exception behavior>)
  11732. Overview:
  11733. """""""""
  11734. The '``llvm.experimental.constrained.log2``' intrinsic computes the base-2
  11735. logarithm of the specified value.
  11736. Arguments:
  11737. """"""""""
  11738. The first argument and the return value are floating-point numbers of the same
  11739. type.
  11740. The second and third arguments specify the rounding mode and exception
  11741. behavior as described above.
  11742. Semantics:
  11743. """"""""""
  11744. This function returns the same values as the libm ``log2`` functions
  11745. would, and handles error conditions in the same way.
  11746. '``llvm.experimental.constrained.rint``' Intrinsic
  11747. ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  11748. Syntax:
  11749. """""""
  11750. ::
  11751. declare <type>
  11752. @llvm.experimental.constrained.rint(<type> <op1>,
  11753. metadata <rounding mode>,
  11754. metadata <exception behavior>)
  11755. Overview:
  11756. """""""""
  11757. The '``llvm.experimental.constrained.rint``' intrinsic returns the first
  11758. operand rounded to the nearest integer. It may raise an inexact floating-point
  11759. exception if the operand is not an integer.
  11760. Arguments:
  11761. """"""""""
  11762. The first argument and the return value are floating-point numbers of the same
  11763. type.
  11764. The second and third arguments specify the rounding mode and exception
  11765. behavior as described above.
  11766. Semantics:
  11767. """"""""""
  11768. This function returns the same values as the libm ``rint`` functions
  11769. would, and handles error conditions in the same way. The rounding mode is
  11770. described, not determined, by the rounding mode argument. The actual rounding
  11771. mode is determined by the runtime floating-point environment. The rounding
  11772. mode argument is only intended as information to the compiler.
  11773. '``llvm.experimental.constrained.lrint``' Intrinsic
  11774. ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  11775. Syntax:
  11776. """""""
  11777. ::
  11778. declare <inttype>
  11779. @llvm.experimental.constrained.lrint(<fptype> <op1>,
  11780. metadata <rounding mode>,
  11781. metadata <exception behavior>)
  11782. Overview:
  11783. """""""""
  11784. The '``llvm.experimental.constrained.lrint``' intrinsic returns the first
  11785. operand rounded to the nearest integer. An inexact floating-point exception
  11786. will be raised if the operand is not an integer. An invalid exception is
  11787. raised if the result is too large to fit into a supported integer type,
  11788. and in this case the result is undefined.
  11789. Arguments:
  11790. """"""""""
  11791. The first argument is a floating-point number. The return value is an
  11792. integer type. Not all types are supported on all targets. The supported
  11793. types are the same as the ``llvm.lrint`` intrinsic and the ``lrint``
  11794. libm functions.
  11795. The second and third arguments specify the rounding mode and exception
  11796. behavior as described above.
  11797. Semantics:
  11798. """"""""""
  11799. This function returns the same values as the libm ``lrint`` functions
  11800. would, and handles error conditions in the same way.
  11801. The rounding mode is described, not determined, by the rounding mode
  11802. argument. The actual rounding mode is determined by the runtime floating-point
  11803. environment. The rounding mode argument is only intended as information
  11804. to the compiler.
  11805. If the runtime floating-point environment is using the default rounding mode
  11806. then the results will be the same as the llvm.lrint intrinsic.
  11807. '``llvm.experimental.constrained.llrint``' Intrinsic
  11808. ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  11809. Syntax:
  11810. """""""
  11811. ::
  11812. declare <inttype>
  11813. @llvm.experimental.constrained.llrint(<fptype> <op1>,
  11814. metadata <rounding mode>,
  11815. metadata <exception behavior>)
  11816. Overview:
  11817. """""""""
  11818. The '``llvm.experimental.constrained.llrint``' intrinsic returns the first
  11819. operand rounded to the nearest integer. An inexact floating-point exception
  11820. will be raised if the operand is not an integer. An invalid exception is
  11821. raised if the result is too large to fit into a supported integer type,
  11822. and in this case the result is undefined.
  11823. Arguments:
  11824. """"""""""
  11825. The first argument is a floating-point number. The return value is an
  11826. integer type. Not all types are supported on all targets. The supported
  11827. types are the same as the ``llvm.llrint`` intrinsic and the ``llrint``
  11828. libm functions.
  11829. The second and third arguments specify the rounding mode and exception
  11830. behavior as described above.
  11831. Semantics:
  11832. """"""""""
  11833. This function returns the same values as the libm ``llrint`` functions
  11834. would, and handles error conditions in the same way.
  11835. The rounding mode is described, not determined, by the rounding mode
  11836. argument. The actual rounding mode is determined by the runtime floating-point
  11837. environment. The rounding mode argument is only intended as information
  11838. to the compiler.
  11839. If the runtime floating-point environment is using the default rounding mode
  11840. then the results will be the same as the llvm.llrint intrinsic.
  11841. '``llvm.experimental.constrained.nearbyint``' Intrinsic
  11842. ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  11843. Syntax:
  11844. """""""
  11845. ::
  11846. declare <type>
  11847. @llvm.experimental.constrained.nearbyint(<type> <op1>,
  11848. metadata <rounding mode>,
  11849. metadata <exception behavior>)
  11850. Overview:
  11851. """""""""
  11852. The '``llvm.experimental.constrained.nearbyint``' intrinsic returns the first
  11853. operand rounded to the nearest integer. It will not raise an inexact
  11854. floating-point exception if the operand is not an integer.
  11855. Arguments:
  11856. """"""""""
  11857. The first argument and the return value are floating-point numbers of the same
  11858. type.
  11859. The second and third arguments specify the rounding mode and exception
  11860. behavior as described above.
  11861. Semantics:
  11862. """"""""""
  11863. This function returns the same values as the libm ``nearbyint`` functions
  11864. would, and handles error conditions in the same way. The rounding mode is
  11865. described, not determined, by the rounding mode argument. The actual rounding
  11866. mode is determined by the runtime floating-point environment. The rounding
  11867. mode argument is only intended as information to the compiler.
  11868. '``llvm.experimental.constrained.maxnum``' Intrinsic
  11869. ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  11870. Syntax:
  11871. """""""
  11872. ::
  11873. declare <type>
  11874. @llvm.experimental.constrained.maxnum(<type> <op1>, <type> <op2>
  11875. metadata <rounding mode>,
  11876. metadata <exception behavior>)
  11877. Overview:
  11878. """""""""
  11879. The '``llvm.experimental.constrained.maxnum``' intrinsic returns the maximum
  11880. of the two arguments.
  11881. Arguments:
  11882. """"""""""
  11883. The first two arguments and the return value are floating-point numbers
  11884. of the same type.
  11885. The third and forth arguments specify the rounding mode and exception
  11886. behavior as described above.
  11887. Semantics:
  11888. """"""""""
  11889. This function follows the IEEE-754 semantics for maxNum. The rounding mode is
  11890. described, not determined, by the rounding mode argument. The actual rounding
  11891. mode is determined by the runtime floating-point environment. The rounding
  11892. mode argument is only intended as information to the compiler.
  11893. '``llvm.experimental.constrained.minnum``' Intrinsic
  11894. ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  11895. Syntax:
  11896. """""""
  11897. ::
  11898. declare <type>
  11899. @llvm.experimental.constrained.minnum(<type> <op1>, <type> <op2>
  11900. metadata <rounding mode>,
  11901. metadata <exception behavior>)
  11902. Overview:
  11903. """""""""
  11904. The '``llvm.experimental.constrained.minnum``' intrinsic returns the minimum
  11905. of the two arguments.
  11906. Arguments:
  11907. """"""""""
  11908. The first two arguments and the return value are floating-point numbers
  11909. of the same type.
  11910. The third and forth arguments specify the rounding mode and exception
  11911. behavior as described above.
  11912. Semantics:
  11913. """"""""""
  11914. This function follows the IEEE-754 semantics for minNum. The rounding mode is
  11915. described, not determined, by the rounding mode argument. The actual rounding
  11916. mode is determined by the runtime floating-point environment. The rounding
  11917. mode argument is only intended as information to the compiler.
  11918. '``llvm.experimental.constrained.ceil``' Intrinsic
  11919. ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  11920. Syntax:
  11921. """""""
  11922. ::
  11923. declare <type>
  11924. @llvm.experimental.constrained.ceil(<type> <op1>,
  11925. metadata <rounding mode>,
  11926. metadata <exception behavior>)
  11927. Overview:
  11928. """""""""
  11929. The '``llvm.experimental.constrained.ceil``' intrinsic returns the ceiling of the
  11930. first operand.
  11931. Arguments:
  11932. """"""""""
  11933. The first argument and the return value are floating-point numbers of the same
  11934. type.
  11935. The second and third arguments specify the rounding mode and exception
  11936. behavior as described above. The rounding mode is currently unused for this
  11937. intrinsic.
  11938. Semantics:
  11939. """"""""""
  11940. This function returns the same values as the libm ``ceil`` functions
  11941. would and handles error conditions in the same way.
  11942. '``llvm.experimental.constrained.floor``' Intrinsic
  11943. ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  11944. Syntax:
  11945. """""""
  11946. ::
  11947. declare <type>
  11948. @llvm.experimental.constrained.floor(<type> <op1>,
  11949. metadata <rounding mode>,
  11950. metadata <exception behavior>)
  11951. Overview:
  11952. """""""""
  11953. The '``llvm.experimental.constrained.floor``' intrinsic returns the floor of the
  11954. first operand.
  11955. Arguments:
  11956. """"""""""
  11957. The first argument and the return value are floating-point numbers of the same
  11958. type.
  11959. The second and third arguments specify the rounding mode and exception
  11960. behavior as described above. The rounding mode is currently unused for this
  11961. intrinsic.
  11962. Semantics:
  11963. """"""""""
  11964. This function returns the same values as the libm ``floor`` functions
  11965. would and handles error conditions in the same way.
  11966. '``llvm.experimental.constrained.round``' Intrinsic
  11967. ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  11968. Syntax:
  11969. """""""
  11970. ::
  11971. declare <type>
  11972. @llvm.experimental.constrained.round(<type> <op1>,
  11973. metadata <rounding mode>,
  11974. metadata <exception behavior>)
  11975. Overview:
  11976. """""""""
  11977. The '``llvm.experimental.constrained.round``' intrinsic returns the first
  11978. operand rounded to the nearest integer.
  11979. Arguments:
  11980. """"""""""
  11981. The first argument and the return value are floating-point numbers of the same
  11982. type.
  11983. The second and third arguments specify the rounding mode and exception
  11984. behavior as described above. The rounding mode is currently unused for this
  11985. intrinsic.
  11986. Semantics:
  11987. """"""""""
  11988. This function returns the same values as the libm ``round`` functions
  11989. would and handles error conditions in the same way.
  11990. '``llvm.experimental.constrained.lround``' Intrinsic
  11991. ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  11992. Syntax:
  11993. """""""
  11994. ::
  11995. declare <inttype>
  11996. @llvm.experimental.constrained.lround(<fptype> <op1>,
  11997. metadata <exception behavior>)
  11998. Overview:
  11999. """""""""
  12000. The '``llvm.experimental.constrained.lround``' intrinsic returns the first
  12001. operand rounded to the nearest integer with ties away from zero. It will
  12002. raise an inexact floating-point exception if the operand is not an integer.
  12003. An invalid exception is raised if the result is too large to fit into a
  12004. supported integer type, and in this case the result is undefined.
  12005. Arguments:
  12006. """"""""""
  12007. The first argument is a floating-point number. The return value is an
  12008. integer type. Not all types are supported on all targets. The supported
  12009. types are the same as the ``llvm.lround`` intrinsic and the ``lround``
  12010. libm functions.
  12011. The second argument specifies the exception behavior as described above.
  12012. Semantics:
  12013. """"""""""
  12014. This function returns the same values as the libm ``lround`` functions
  12015. would and handles error conditions in the same way.
  12016. '``llvm.experimental.constrained.llround``' Intrinsic
  12017. ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  12018. Syntax:
  12019. """""""
  12020. ::
  12021. declare <inttype>
  12022. @llvm.experimental.constrained.llround(<fptype> <op1>,
  12023. metadata <exception behavior>)
  12024. Overview:
  12025. """""""""
  12026. The '``llvm.experimental.constrained.llround``' intrinsic returns the first
  12027. operand rounded to the nearest integer with ties away from zero. It will
  12028. raise an inexact floating-point exception if the operand is not an integer.
  12029. An invalid exception is raised if the result is too large to fit into a
  12030. supported integer type, and in this case the result is undefined.
  12031. Arguments:
  12032. """"""""""
  12033. The first argument is a floating-point number. The return value is an
  12034. integer type. Not all types are supported on all targets. The supported
  12035. types are the same as the ``llvm.llround`` intrinsic and the ``llround``
  12036. libm functions.
  12037. The second argument specifies the exception behavior as described above.
  12038. Semantics:
  12039. """"""""""
  12040. This function returns the same values as the libm ``llround`` functions
  12041. would and handles error conditions in the same way.
  12042. '``llvm.experimental.constrained.trunc``' Intrinsic
  12043. ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  12044. Syntax:
  12045. """""""
  12046. ::
  12047. declare <type>
  12048. @llvm.experimental.constrained.trunc(<type> <op1>,
  12049. metadata <truncing mode>,
  12050. metadata <exception behavior>)
  12051. Overview:
  12052. """""""""
  12053. The '``llvm.experimental.constrained.trunc``' intrinsic returns the first
  12054. operand rounded to the nearest integer not larger in magnitude than the
  12055. operand.
  12056. Arguments:
  12057. """"""""""
  12058. The first argument and the return value are floating-point numbers of the same
  12059. type.
  12060. The second and third arguments specify the truncing mode and exception
  12061. behavior as described above. The truncing mode is currently unused for this
  12062. intrinsic.
  12063. Semantics:
  12064. """"""""""
  12065. This function returns the same values as the libm ``trunc`` functions
  12066. would and handles error conditions in the same way.
  12067. General Intrinsics
  12068. ------------------
  12069. This class of intrinsics is designed to be generic and has no specific
  12070. purpose.
  12071. '``llvm.var.annotation``' Intrinsic
  12072. ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  12073. Syntax:
  12074. """""""
  12075. ::
  12076. declare void @llvm.var.annotation(i8* <val>, i8* <str>, i8* <str>, i32 <int>)
  12077. Overview:
  12078. """""""""
  12079. The '``llvm.var.annotation``' intrinsic.
  12080. Arguments:
  12081. """"""""""
  12082. The first argument is a pointer to a value, the second is a pointer to a
  12083. global string, the third is a pointer to a global string which is the
  12084. source file name, and the last argument is the line number.
  12085. Semantics:
  12086. """"""""""
  12087. This intrinsic allows annotation of local variables with arbitrary
  12088. strings. This can be useful for special purpose optimizations that want
  12089. to look for these annotations. These have no other defined use; they are
  12090. ignored by code generation and optimization.
  12091. '``llvm.ptr.annotation.*``' Intrinsic
  12092. ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  12093. Syntax:
  12094. """""""
  12095. This is an overloaded intrinsic. You can use '``llvm.ptr.annotation``' on a
  12096. pointer to an integer of any width. *NOTE* you must specify an address space for
  12097. the pointer. The identifier for the default address space is the integer
  12098. '``0``'.
  12099. ::
  12100. declare i8* @llvm.ptr.annotation.p<address space>i8(i8* <val>, i8* <str>, i8* <str>, i32 <int>)
  12101. declare i16* @llvm.ptr.annotation.p<address space>i16(i16* <val>, i8* <str>, i8* <str>, i32 <int>)
  12102. declare i32* @llvm.ptr.annotation.p<address space>i32(i32* <val>, i8* <str>, i8* <str>, i32 <int>)
  12103. declare i64* @llvm.ptr.annotation.p<address space>i64(i64* <val>, i8* <str>, i8* <str>, i32 <int>)
  12104. declare i256* @llvm.ptr.annotation.p<address space>i256(i256* <val>, i8* <str>, i8* <str>, i32 <int>)
  12105. Overview:
  12106. """""""""
  12107. The '``llvm.ptr.annotation``' intrinsic.
  12108. Arguments:
  12109. """"""""""
  12110. The first argument is a pointer to an integer value of arbitrary bitwidth
  12111. (result of some expression), the second is a pointer to a global string, the
  12112. third is a pointer to a global string which is the source file name, and the
  12113. last argument is the line number. It returns the value of the first argument.
  12114. Semantics:
  12115. """"""""""
  12116. This intrinsic allows annotation of a pointer to an integer with arbitrary
  12117. strings. This can be useful for special purpose optimizations that want to look
  12118. for these annotations. These have no other defined use; they are ignored by code
  12119. generation and optimization.
  12120. '``llvm.annotation.*``' Intrinsic
  12121. ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  12122. Syntax:
  12123. """""""
  12124. This is an overloaded intrinsic. You can use '``llvm.annotation``' on
  12125. any integer bit width.
  12126. ::
  12127. declare i8 @llvm.annotation.i8(i8 <val>, i8* <str>, i8* <str>, i32 <int>)
  12128. declare i16 @llvm.annotation.i16(i16 <val>, i8* <str>, i8* <str>, i32 <int>)
  12129. declare i32 @llvm.annotation.i32(i32 <val>, i8* <str>, i8* <str>, i32 <int>)
  12130. declare i64 @llvm.annotation.i64(i64 <val>, i8* <str>, i8* <str>, i32 <int>)
  12131. declare i256 @llvm.annotation.i256(i256 <val>, i8* <str>, i8* <str>, i32 <int>)
  12132. Overview:
  12133. """""""""
  12134. The '``llvm.annotation``' intrinsic.
  12135. Arguments:
  12136. """"""""""
  12137. The first argument is an integer value (result of some expression), the
  12138. second is a pointer to a global string, the third is a pointer to a
  12139. global string which is the source file name, and the last argument is
  12140. the line number. It returns the value of the first argument.
  12141. Semantics:
  12142. """"""""""
  12143. This intrinsic allows annotations to be put on arbitrary expressions
  12144. with arbitrary strings. This can be useful for special purpose
  12145. optimizations that want to look for these annotations. These have no
  12146. other defined use; they are ignored by code generation and optimization.
  12147. '``llvm.codeview.annotation``' Intrinsic
  12148. ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  12149. Syntax:
  12150. """""""
  12151. This annotation emits a label at its program point and an associated
  12152. ``S_ANNOTATION`` codeview record with some additional string metadata. This is
  12153. used to implement MSVC's ``__annotation`` intrinsic. It is marked
  12154. ``noduplicate``, so calls to this intrinsic prevent inlining and should be
  12155. considered expensive.
  12156. ::
  12157. declare void @llvm.codeview.annotation(metadata)
  12158. Arguments:
  12159. """"""""""
  12160. The argument should be an MDTuple containing any number of MDStrings.
  12161. '``llvm.trap``' Intrinsic
  12162. ^^^^^^^^^^^^^^^^^^^^^^^^^
  12163. Syntax:
  12164. """""""
  12165. ::
  12166. declare void @llvm.trap() cold noreturn nounwind
  12167. Overview:
  12168. """""""""
  12169. The '``llvm.trap``' intrinsic.
  12170. Arguments:
  12171. """"""""""
  12172. None.
  12173. Semantics:
  12174. """"""""""
  12175. This intrinsic is lowered to the target dependent trap instruction. If
  12176. the target does not have a trap instruction, this intrinsic will be
  12177. lowered to a call of the ``abort()`` function.
  12178. '``llvm.debugtrap``' Intrinsic
  12179. ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  12180. Syntax:
  12181. """""""
  12182. ::
  12183. declare void @llvm.debugtrap() nounwind
  12184. Overview:
  12185. """""""""
  12186. The '``llvm.debugtrap``' intrinsic.
  12187. Arguments:
  12188. """"""""""
  12189. None.
  12190. Semantics:
  12191. """"""""""
  12192. This intrinsic is lowered to code which is intended to cause an
  12193. execution trap with the intention of requesting the attention of a
  12194. debugger.
  12195. '``llvm.stackprotector``' Intrinsic
  12196. ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  12197. Syntax:
  12198. """""""
  12199. ::
  12200. declare void @llvm.stackprotector(i8* <guard>, i8** <slot>)
  12201. Overview:
  12202. """""""""
  12203. The ``llvm.stackprotector`` intrinsic takes the ``guard`` and stores it
  12204. onto the stack at ``slot``. The stack slot is adjusted to ensure that it
  12205. is placed on the stack before local variables.
  12206. Arguments:
  12207. """"""""""
  12208. The ``llvm.stackprotector`` intrinsic requires two pointer arguments.
  12209. The first argument is the value loaded from the stack guard
  12210. ``@__stack_chk_guard``. The second variable is an ``alloca`` that has
  12211. enough space to hold the value of the guard.
  12212. Semantics:
  12213. """"""""""
  12214. This intrinsic causes the prologue/epilogue inserter to force the position of
  12215. the ``AllocaInst`` stack slot to be before local variables on the stack. This is
  12216. to ensure that if a local variable on the stack is overwritten, it will destroy
  12217. the value of the guard. When the function exits, the guard on the stack is
  12218. checked against the original guard by ``llvm.stackprotectorcheck``. If they are
  12219. different, then ``llvm.stackprotectorcheck`` causes the program to abort by
  12220. calling the ``__stack_chk_fail()`` function.
  12221. '``llvm.stackguard``' Intrinsic
  12222. ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  12223. Syntax:
  12224. """""""
  12225. ::
  12226. declare i8* @llvm.stackguard()
  12227. Overview:
  12228. """""""""
  12229. The ``llvm.stackguard`` intrinsic returns the system stack guard value.
  12230. It should not be generated by frontends, since it is only for internal usage.
  12231. The reason why we create this intrinsic is that we still support IR form Stack
  12232. Protector in FastISel.
  12233. Arguments:
  12234. """"""""""
  12235. None.
  12236. Semantics:
  12237. """"""""""
  12238. On some platforms, the value returned by this intrinsic remains unchanged
  12239. between loads in the same thread. On other platforms, it returns the same
  12240. global variable value, if any, e.g. ``@__stack_chk_guard``.
  12241. Currently some platforms have IR-level customized stack guard loading (e.g.
  12242. X86 Linux) that is not handled by ``llvm.stackguard()``, while they should be
  12243. in the future.
  12244. '``llvm.objectsize``' Intrinsic
  12245. ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  12246. Syntax:
  12247. """""""
  12248. ::
  12249. declare i32 @llvm.objectsize.i32(i8* <object>, i1 <min>, i1 <nullunknown>, i1 <dynamic>)
  12250. declare i64 @llvm.objectsize.i64(i8* <object>, i1 <min>, i1 <nullunknown>, i1 <dynamic>)
  12251. Overview:
  12252. """""""""
  12253. The ``llvm.objectsize`` intrinsic is designed to provide information to the
  12254. optimizer to determine whether a) an operation (like memcpy) will overflow a
  12255. buffer that corresponds to an object, or b) that a runtime check for overflow
  12256. isn't necessary. An object in this context means an allocation of a specific
  12257. class, structure, array, or other object.
  12258. Arguments:
  12259. """"""""""
  12260. The ``llvm.objectsize`` intrinsic takes four arguments. The first argument is a
  12261. pointer to or into the ``object``. The second argument determines whether
  12262. ``llvm.objectsize`` returns 0 (if true) or -1 (if false) when the object size is
  12263. unknown. The third argument controls how ``llvm.objectsize`` acts when ``null``
  12264. in address space 0 is used as its pointer argument. If it's ``false``,
  12265. ``llvm.objectsize`` reports 0 bytes available when given ``null``. Otherwise, if
  12266. the ``null`` is in a non-zero address space or if ``true`` is given for the
  12267. third argument of ``llvm.objectsize``, we assume its size is unknown. The fourth
  12268. argument to ``llvm.objectsize`` determines if the value should be evaluated at
  12269. runtime.
  12270. The second, third, and fourth arguments only accept constants.
  12271. Semantics:
  12272. """"""""""
  12273. The ``llvm.objectsize`` intrinsic is lowered to a value representing the size of
  12274. the object concerned. If the size cannot be determined, ``llvm.objectsize``
  12275. returns ``i32/i64 -1 or 0`` (depending on the ``min`` argument).
  12276. '``llvm.expect``' Intrinsic
  12277. ^^^^^^^^^^^^^^^^^^^^^^^^^^^
  12278. Syntax:
  12279. """""""
  12280. This is an overloaded intrinsic. You can use ``llvm.expect`` on any
  12281. integer bit width.
  12282. ::
  12283. declare i1 @llvm.expect.i1(i1 <val>, i1 <expected_val>)
  12284. declare i32 @llvm.expect.i32(i32 <val>, i32 <expected_val>)
  12285. declare i64 @llvm.expect.i64(i64 <val>, i64 <expected_val>)
  12286. Overview:
  12287. """""""""
  12288. The ``llvm.expect`` intrinsic provides information about expected (the
  12289. most probable) value of ``val``, which can be used by optimizers.
  12290. Arguments:
  12291. """"""""""
  12292. The ``llvm.expect`` intrinsic takes two arguments. The first argument is
  12293. a value. The second argument is an expected value.
  12294. Semantics:
  12295. """"""""""
  12296. This intrinsic is lowered to the ``val``.
  12297. .. _int_assume:
  12298. '``llvm.assume``' Intrinsic
  12299. ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  12300. Syntax:
  12301. """""""
  12302. ::
  12303. declare void @llvm.assume(i1 %cond)
  12304. Overview:
  12305. """""""""
  12306. The ``llvm.assume`` allows the optimizer to assume that the provided
  12307. condition is true. This information can then be used in simplifying other parts
  12308. of the code.
  12309. Arguments:
  12310. """"""""""
  12311. The condition which the optimizer may assume is always true.
  12312. Semantics:
  12313. """"""""""
  12314. The intrinsic allows the optimizer to assume that the provided condition is
  12315. always true whenever the control flow reaches the intrinsic call. No code is
  12316. generated for this intrinsic, and instructions that contribute only to the
  12317. provided condition are not used for code generation. If the condition is
  12318. violated during execution, the behavior is undefined.
  12319. Note that the optimizer might limit the transformations performed on values
  12320. used by the ``llvm.assume`` intrinsic in order to preserve the instructions
  12321. only used to form the intrinsic's input argument. This might prove undesirable
  12322. if the extra information provided by the ``llvm.assume`` intrinsic does not cause
  12323. sufficient overall improvement in code quality. For this reason,
  12324. ``llvm.assume`` should not be used to document basic mathematical invariants
  12325. that the optimizer can otherwise deduce or facts that are of little use to the
  12326. optimizer.
  12327. .. _int_ssa_copy:
  12328. '``llvm.ssa_copy``' Intrinsic
  12329. ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  12330. Syntax:
  12331. """""""
  12332. ::
  12333. declare type @llvm.ssa_copy(type %operand) returned(1) readnone
  12334. Arguments:
  12335. """"""""""
  12336. The first argument is an operand which is used as the returned value.
  12337. Overview:
  12338. """"""""""
  12339. The ``llvm.ssa_copy`` intrinsic can be used to attach information to
  12340. operations by copying them and giving them new names. For example,
  12341. the PredicateInfo utility uses it to build Extended SSA form, and
  12342. attach various forms of information to operands that dominate specific
  12343. uses. It is not meant for general use, only for building temporary
  12344. renaming forms that require value splits at certain points.
  12345. .. _type.test:
  12346. '``llvm.type.test``' Intrinsic
  12347. ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  12348. Syntax:
  12349. """""""
  12350. ::
  12351. declare i1 @llvm.type.test(i8* %ptr, metadata %type) nounwind readnone
  12352. Arguments:
  12353. """"""""""
  12354. The first argument is a pointer to be tested. The second argument is a
  12355. metadata object representing a :doc:`type identifier <TypeMetadata>`.
  12356. Overview:
  12357. """""""""
  12358. The ``llvm.type.test`` intrinsic tests whether the given pointer is associated
  12359. with the given type identifier.
  12360. .. _type.checked.load:
  12361. '``llvm.type.checked.load``' Intrinsic
  12362. ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  12363. Syntax:
  12364. """""""
  12365. ::
  12366. declare {i8*, i1} @llvm.type.checked.load(i8* %ptr, i32 %offset, metadata %type) argmemonly nounwind readonly
  12367. Arguments:
  12368. """"""""""
  12369. The first argument is a pointer from which to load a function pointer. The
  12370. second argument is the byte offset from which to load the function pointer. The
  12371. third argument is a metadata object representing a :doc:`type identifier
  12372. <TypeMetadata>`.
  12373. Overview:
  12374. """""""""
  12375. The ``llvm.type.checked.load`` intrinsic safely loads a function pointer from a
  12376. virtual table pointer using type metadata. This intrinsic is used to implement
  12377. control flow integrity in conjunction with virtual call optimization. The
  12378. virtual call optimization pass will optimize away ``llvm.type.checked.load``
  12379. intrinsics associated with devirtualized calls, thereby removing the type
  12380. check in cases where it is not needed to enforce the control flow integrity
  12381. constraint.
  12382. If the given pointer is associated with a type metadata identifier, this
  12383. function returns true as the second element of its return value. (Note that
  12384. the function may also return true if the given pointer is not associated
  12385. with a type metadata identifier.) If the function's return value's second
  12386. element is true, the following rules apply to the first element:
  12387. - If the given pointer is associated with the given type metadata identifier,
  12388. it is the function pointer loaded from the given byte offset from the given
  12389. pointer.
  12390. - If the given pointer is not associated with the given type metadata
  12391. identifier, it is one of the following (the choice of which is unspecified):
  12392. 1. The function pointer that would have been loaded from an arbitrarily chosen
  12393. (through an unspecified mechanism) pointer associated with the type
  12394. metadata.
  12395. 2. If the function has a non-void return type, a pointer to a function that
  12396. returns an unspecified value without causing side effects.
  12397. If the function's return value's second element is false, the value of the
  12398. first element is undefined.
  12399. '``llvm.donothing``' Intrinsic
  12400. ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  12401. Syntax:
  12402. """""""
  12403. ::
  12404. declare void @llvm.donothing() nounwind readnone
  12405. Overview:
  12406. """""""""
  12407. The ``llvm.donothing`` intrinsic doesn't perform any operation. It's one of only
  12408. three intrinsics (besides ``llvm.experimental.patchpoint`` and
  12409. ``llvm.experimental.gc.statepoint``) that can be called with an invoke
  12410. instruction.
  12411. Arguments:
  12412. """"""""""
  12413. None.
  12414. Semantics:
  12415. """"""""""
  12416. This intrinsic does nothing, and it's removed by optimizers and ignored
  12417. by codegen.
  12418. '``llvm.experimental.deoptimize``' Intrinsic
  12419. ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  12420. Syntax:
  12421. """""""
  12422. ::
  12423. declare type @llvm.experimental.deoptimize(...) [ "deopt"(...) ]
  12424. Overview:
  12425. """""""""
  12426. This intrinsic, together with :ref:`deoptimization operand bundles
  12427. <deopt_opbundles>`, allow frontends to express transfer of control and
  12428. frame-local state from the currently executing (typically more specialized,
  12429. hence faster) version of a function into another (typically more generic, hence
  12430. slower) version.
  12431. In languages with a fully integrated managed runtime like Java and JavaScript
  12432. this intrinsic can be used to implement "uncommon trap" or "side exit" like
  12433. functionality. In unmanaged languages like C and C++, this intrinsic can be
  12434. used to represent the slow paths of specialized functions.
  12435. Arguments:
  12436. """"""""""
  12437. The intrinsic takes an arbitrary number of arguments, whose meaning is
  12438. decided by the :ref:`lowering strategy<deoptimize_lowering>`.
  12439. Semantics:
  12440. """"""""""
  12441. The ``@llvm.experimental.deoptimize`` intrinsic executes an attached
  12442. deoptimization continuation (denoted using a :ref:`deoptimization
  12443. operand bundle <deopt_opbundles>`) and returns the value returned by
  12444. the deoptimization continuation. Defining the semantic properties of
  12445. the continuation itself is out of scope of the language reference --
  12446. as far as LLVM is concerned, the deoptimization continuation can
  12447. invoke arbitrary side effects, including reading from and writing to
  12448. the entire heap.
  12449. Deoptimization continuations expressed using ``"deopt"`` operand bundles always
  12450. continue execution to the end of the physical frame containing them, so all
  12451. calls to ``@llvm.experimental.deoptimize`` must be in "tail position":
  12452. - ``@llvm.experimental.deoptimize`` cannot be invoked.
  12453. - The call must immediately precede a :ref:`ret <i_ret>` instruction.
  12454. - The ``ret`` instruction must return the value produced by the
  12455. ``@llvm.experimental.deoptimize`` call if there is one, or void.
  12456. Note that the above restrictions imply that the return type for a call to
  12457. ``@llvm.experimental.deoptimize`` will match the return type of its immediate
  12458. caller.
  12459. The inliner composes the ``"deopt"`` continuations of the caller into the
  12460. ``"deopt"`` continuations present in the inlinee, and also updates calls to this
  12461. intrinsic to return directly from the frame of the function it inlined into.
  12462. All declarations of ``@llvm.experimental.deoptimize`` must share the
  12463. same calling convention.
  12464. .. _deoptimize_lowering:
  12465. Lowering:
  12466. """""""""
  12467. Calls to ``@llvm.experimental.deoptimize`` are lowered to calls to the
  12468. symbol ``__llvm_deoptimize`` (it is the frontend's responsibility to
  12469. ensure that this symbol is defined). The call arguments to
  12470. ``@llvm.experimental.deoptimize`` are lowered as if they were formal
  12471. arguments of the specified types, and not as varargs.
  12472. '``llvm.experimental.guard``' Intrinsic
  12473. ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  12474. Syntax:
  12475. """""""
  12476. ::
  12477. declare void @llvm.experimental.guard(i1, ...) [ "deopt"(...) ]
  12478. Overview:
  12479. """""""""
  12480. This intrinsic, together with :ref:`deoptimization operand bundles
  12481. <deopt_opbundles>`, allows frontends to express guards or checks on
  12482. optimistic assumptions made during compilation. The semantics of
  12483. ``@llvm.experimental.guard`` is defined in terms of
  12484. ``@llvm.experimental.deoptimize`` -- its body is defined to be
  12485. equivalent to:
  12486. .. code-block:: text
  12487. define void @llvm.experimental.guard(i1 %pred, <args...>) {
  12488. %realPred = and i1 %pred, undef
  12489. br i1 %realPred, label %continue, label %leave [, !make.implicit !{}]
  12490. leave:
  12491. call void @llvm.experimental.deoptimize(<args...>) [ "deopt"() ]
  12492. ret void
  12493. continue:
  12494. ret void
  12495. }
  12496. with the optional ``[, !make.implicit !{}]`` present if and only if it
  12497. is present on the call site. For more details on ``!make.implicit``,
  12498. see :doc:`FaultMaps`.
  12499. In words, ``@llvm.experimental.guard`` executes the attached
  12500. ``"deopt"`` continuation if (but **not** only if) its first argument
  12501. is ``false``. Since the optimizer is allowed to replace the ``undef``
  12502. with an arbitrary value, it can optimize guard to fail "spuriously",
  12503. i.e. without the original condition being false (hence the "not only
  12504. if"); and this allows for "check widening" type optimizations.
  12505. ``@llvm.experimental.guard`` cannot be invoked.
  12506. '``llvm.experimental.widenable.condition``' Intrinsic
  12507. ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  12508. Syntax:
  12509. """""""
  12510. ::
  12511. declare i1 @llvm.experimental.widenable.condition()
  12512. Overview:
  12513. """""""""
  12514. This intrinsic represents a "widenable condition" which is
  12515. boolean expressions with the following property: whether this
  12516. expression is `true` or `false`, the program is correct and
  12517. well-defined.
  12518. Together with :ref:`deoptimization operand bundles <deopt_opbundles>`,
  12519. ``@llvm.experimental.widenable.condition`` allows frontends to
  12520. express guards or checks on optimistic assumptions made during
  12521. compilation and represent them as branch instructions on special
  12522. conditions.
  12523. While this may appear similar in semantics to `undef`, it is very
  12524. different in that an invocation produces a particular, singular
  12525. value. It is also intended to be lowered late, and remain available
  12526. for specific optimizations and transforms that can benefit from its
  12527. special properties.
  12528. Arguments:
  12529. """"""""""
  12530. None.
  12531. Semantics:
  12532. """"""""""
  12533. The intrinsic ``@llvm.experimental.widenable.condition()``
  12534. returns either `true` or `false`. For each evaluation of a call
  12535. to this intrinsic, the program must be valid and correct both if
  12536. it returns `true` and if it returns `false`. This allows
  12537. transformation passes to replace evaluations of this intrinsic
  12538. with either value whenever one is beneficial.
  12539. When used in a branch condition, it allows us to choose between
  12540. two alternative correct solutions for the same problem, like
  12541. in example below:
  12542. .. code-block:: text
  12543. %cond = call i1 @llvm.experimental.widenable.condition()
  12544. br i1 %cond, label %solution_1, label %solution_2
  12545. label %fast_path:
  12546. ; Apply memory-consuming but fast solution for a task.
  12547. label %slow_path:
  12548. ; Cheap in memory but slow solution.
  12549. Whether the result of intrinsic's call is `true` or `false`,
  12550. it should be correct to pick either solution. We can switch
  12551. between them by replacing the result of
  12552. ``@llvm.experimental.widenable.condition`` with different
  12553. `i1` expressions.
  12554. This is how it can be used to represent guards as widenable branches:
  12555. .. code-block:: text
  12556. block:
  12557. ; Unguarded instructions
  12558. call void @llvm.experimental.guard(i1 %cond, <args...>) ["deopt"(<deopt_args...>)]
  12559. ; Guarded instructions
  12560. Can be expressed in an alternative equivalent form of explicit branch using
  12561. ``@llvm.experimental.widenable.condition``:
  12562. .. code-block:: text
  12563. block:
  12564. ; Unguarded instructions
  12565. %widenable_condition = call i1 @llvm.experimental.widenable.condition()
  12566. %guard_condition = and i1 %cond, %widenable_condition
  12567. br i1 %guard_condition, label %guarded, label %deopt
  12568. guarded:
  12569. ; Guarded instructions
  12570. deopt:
  12571. call type @llvm.experimental.deoptimize(<args...>) [ "deopt"(<deopt_args...>) ]
  12572. So the block `guarded` is only reachable when `%cond` is `true`,
  12573. and it should be valid to go to the block `deopt` whenever `%cond`
  12574. is `true` or `false`.
  12575. ``@llvm.experimental.widenable.condition`` will never throw, thus
  12576. it cannot be invoked.
  12577. Guard widening:
  12578. """""""""""""""
  12579. When ``@llvm.experimental.widenable.condition()`` is used in
  12580. condition of a guard represented as explicit branch, it is
  12581. legal to widen the guard's condition with any additional
  12582. conditions.
  12583. Guard widening looks like replacement of
  12584. .. code-block:: text
  12585. %widenable_cond = call i1 @llvm.experimental.widenable.condition()
  12586. %guard_cond = and i1 %cond, %widenable_cond
  12587. br i1 %guard_cond, label %guarded, label %deopt
  12588. with
  12589. .. code-block:: text
  12590. %widenable_cond = call i1 @llvm.experimental.widenable.condition()
  12591. %new_cond = and i1 %any_other_cond, %widenable_cond
  12592. %new_guard_cond = and i1 %cond, %new_cond
  12593. br i1 %new_guard_cond, label %guarded, label %deopt
  12594. for this branch. Here `%any_other_cond` is an arbitrarily chosen
  12595. well-defined `i1` value. By making guard widening, we may
  12596. impose stricter conditions on `guarded` block and bail to the
  12597. deopt when the new condition is not met.
  12598. Lowering:
  12599. """""""""
  12600. Default lowering strategy is replacing the result of
  12601. call of ``@llvm.experimental.widenable.condition`` with
  12602. constant `true`. However it is always correct to replace
  12603. it with any other `i1` value. Any pass can
  12604. freely do it if it can benefit from non-default lowering.
  12605. '``llvm.load.relative``' Intrinsic
  12606. ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  12607. Syntax:
  12608. """""""
  12609. ::
  12610. declare i8* @llvm.load.relative.iN(i8* %ptr, iN %offset) argmemonly nounwind readonly
  12611. Overview:
  12612. """""""""
  12613. This intrinsic loads a 32-bit value from the address ``%ptr + %offset``,
  12614. adds ``%ptr`` to that value and returns it. The constant folder specifically
  12615. recognizes the form of this intrinsic and the constant initializers it may
  12616. load from; if a loaded constant initializer is known to have the form
  12617. ``i32 trunc(x - %ptr)``, the intrinsic call is folded to ``x``.
  12618. LLVM provides that the calculation of such a constant initializer will
  12619. not overflow at link time under the medium code model if ``x`` is an
  12620. ``unnamed_addr`` function. However, it does not provide this guarantee for
  12621. a constant initializer folded into a function body. This intrinsic can be
  12622. used to avoid the possibility of overflows when loading from such a constant.
  12623. '``llvm.sideeffect``' Intrinsic
  12624. ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  12625. Syntax:
  12626. """""""
  12627. ::
  12628. declare void @llvm.sideeffect() inaccessiblememonly nounwind
  12629. Overview:
  12630. """""""""
  12631. The ``llvm.sideeffect`` intrinsic doesn't perform any operation. Optimizers
  12632. treat it as having side effects, so it can be inserted into a loop to
  12633. indicate that the loop shouldn't be assumed to terminate (which could
  12634. potentially lead to the loop being optimized away entirely), even if it's
  12635. an infinite loop with no other side effects.
  12636. Arguments:
  12637. """"""""""
  12638. None.
  12639. Semantics:
  12640. """"""""""
  12641. This intrinsic actually does nothing, but optimizers must assume that it
  12642. has externally observable side effects.
  12643. '``llvm.is.constant.*``' Intrinsic
  12644. ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  12645. Syntax:
  12646. """""""
  12647. This is an overloaded intrinsic. You can use llvm.is.constant with any argument type.
  12648. ::
  12649. declare i1 @llvm.is.constant.i32(i32 %operand) nounwind readnone
  12650. declare i1 @llvm.is.constant.f32(float %operand) nounwind readnone
  12651. declare i1 @llvm.is.constant.TYPENAME(TYPE %operand) nounwind readnone
  12652. Overview:
  12653. """""""""
  12654. The '``llvm.is.constant``' intrinsic will return true if the argument
  12655. is known to be a manifest compile-time constant. It is guaranteed to
  12656. fold to either true or false before generating machine code.
  12657. Semantics:
  12658. """"""""""
  12659. This intrinsic generates no code. If its argument is known to be a
  12660. manifest compile-time constant value, then the intrinsic will be
  12661. converted to a constant true value. Otherwise, it will be converted to
  12662. a constant false value.
  12663. In particular, note that if the argument is a constant expression
  12664. which refers to a global (the address of which _is_ a constant, but
  12665. not manifest during the compile), then the intrinsic evaluates to
  12666. false.
  12667. The result also intentionally depends on the result of optimization
  12668. passes -- e.g., the result can change depending on whether a
  12669. function gets inlined or not. A function's parameters are
  12670. obviously not constant. However, a call like
  12671. ``llvm.is.constant.i32(i32 %param)`` *can* return true after the
  12672. function is inlined, if the value passed to the function parameter was
  12673. a constant.
  12674. On the other hand, if constant folding is not run, it will never
  12675. evaluate to true, even in simple cases.
  12676. .. _int_ptrmask:
  12677. '``llvm.ptrmask``' Intrinsic
  12678. ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  12679. Syntax:
  12680. """""""
  12681. ::
  12682. declare ptrty llvm.ptrmask(ptrty %ptr, intty %mask) readnone speculatable
  12683. Arguments:
  12684. """"""""""
  12685. The first argument is a pointer. The second argument is an integer.
  12686. Overview:
  12687. """"""""""
  12688. The ``llvm.ptrmask`` intrinsic masks out bits of the pointer according to a mask.
  12689. This allows stripping data from tagged pointers without converting them to an
  12690. integer (ptrtoint/inttoptr). As a consequence, we can preserve more information
  12691. to facilitate alias analysis and underlying-object detection.
  12692. Semantics:
  12693. """"""""""
  12694. The result of ``ptrmask(ptr, mask)`` is equivalent to
  12695. ``getelementptr ptr, (ptrtoint(ptr) & mask) - ptrtoint(ptr)``. Both the returned
  12696. pointer and the first argument are based on the same underlying object (for more
  12697. information on the *based on* terminology see
  12698. :ref:`the pointer aliasing rules <pointeraliasing>`). If the bitwidth of the
  12699. mask argument does not match the pointer size of the target, the mask is
  12700. zero-extended or truncated accordingly.
  12701. Stack Map Intrinsics
  12702. --------------------
  12703. LLVM provides experimental intrinsics to support runtime patching
  12704. mechanisms commonly desired in dynamic language JITs. These intrinsics
  12705. are described in :doc:`StackMaps`.
  12706. Element Wise Atomic Memory Intrinsics
  12707. -------------------------------------
  12708. These intrinsics are similar to the standard library memory intrinsics except
  12709. that they perform memory transfer as a sequence of atomic memory accesses.
  12710. .. _int_memcpy_element_unordered_atomic:
  12711. '``llvm.memcpy.element.unordered.atomic``' Intrinsic
  12712. ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  12713. Syntax:
  12714. """""""
  12715. This is an overloaded intrinsic. You can use ``llvm.memcpy.element.unordered.atomic`` on
  12716. any integer bit width and for different address spaces. Not all targets
  12717. support all bit widths however.
  12718. ::
  12719. declare void @llvm.memcpy.element.unordered.atomic.p0i8.p0i8.i32(i8* <dest>,
  12720. i8* <src>,
  12721. i32 <len>,
  12722. i32 <element_size>)
  12723. declare void @llvm.memcpy.element.unordered.atomic.p0i8.p0i8.i64(i8* <dest>,
  12724. i8* <src>,
  12725. i64 <len>,
  12726. i32 <element_size>)
  12727. Overview:
  12728. """""""""
  12729. The '``llvm.memcpy.element.unordered.atomic.*``' intrinsic is a specialization of the
  12730. '``llvm.memcpy.*``' intrinsic. It differs in that the ``dest`` and ``src`` are treated
  12731. as arrays with elements that are exactly ``element_size`` bytes, and the copy between
  12732. buffers uses a sequence of :ref:`unordered atomic <ordering>` load/store operations
  12733. that are a positive integer multiple of the ``element_size`` in size.
  12734. Arguments:
  12735. """"""""""
  12736. The first three arguments are the same as they are in the :ref:`@llvm.memcpy <int_memcpy>`
  12737. intrinsic, with the added constraint that ``len`` is required to be a positive integer
  12738. multiple of the ``element_size``. If ``len`` is not a positive integer multiple of
  12739. ``element_size``, then the behaviour of the intrinsic is undefined.
  12740. ``element_size`` must be a compile-time constant positive power of two no greater than
  12741. target-specific atomic access size limit.
  12742. For each of the input pointers ``align`` parameter attribute must be specified. It
  12743. must be a power of two no less than the ``element_size``. Caller guarantees that
  12744. both the source and destination pointers are aligned to that boundary.
  12745. Semantics:
  12746. """"""""""
  12747. The '``llvm.memcpy.element.unordered.atomic.*``' intrinsic copies ``len`` bytes of
  12748. memory from the source location to the destination location. These locations are not
  12749. allowed to overlap. The memory copy is performed as a sequence of load/store operations
  12750. where each access is guaranteed to be a multiple of ``element_size`` bytes wide and
  12751. aligned at an ``element_size`` boundary.
  12752. The order of the copy is unspecified. The same value may be read from the source
  12753. buffer many times, but only one write is issued to the destination buffer per
  12754. element. It is well defined to have concurrent reads and writes to both source and
  12755. destination provided those reads and writes are unordered atomic when specified.
  12756. This intrinsic does not provide any additional ordering guarantees over those
  12757. provided by a set of unordered loads from the source location and stores to the
  12758. destination.
  12759. Lowering:
  12760. """""""""
  12761. In the most general case call to the '``llvm.memcpy.element.unordered.atomic.*``' is
  12762. lowered to a call to the symbol ``__llvm_memcpy_element_unordered_atomic_*``. Where '*'
  12763. is replaced with an actual element size.
  12764. Optimizer is allowed to inline memory copy when it's profitable to do so.
  12765. '``llvm.memmove.element.unordered.atomic``' Intrinsic
  12766. ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  12767. Syntax:
  12768. """""""
  12769. This is an overloaded intrinsic. You can use
  12770. ``llvm.memmove.element.unordered.atomic`` on any integer bit width and for
  12771. different address spaces. Not all targets support all bit widths however.
  12772. ::
  12773. declare void @llvm.memmove.element.unordered.atomic.p0i8.p0i8.i32(i8* <dest>,
  12774. i8* <src>,
  12775. i32 <len>,
  12776. i32 <element_size>)
  12777. declare void @llvm.memmove.element.unordered.atomic.p0i8.p0i8.i64(i8* <dest>,
  12778. i8* <src>,
  12779. i64 <len>,
  12780. i32 <element_size>)
  12781. Overview:
  12782. """""""""
  12783. The '``llvm.memmove.element.unordered.atomic.*``' intrinsic is a specialization
  12784. of the '``llvm.memmove.*``' intrinsic. It differs in that the ``dest`` and
  12785. ``src`` are treated as arrays with elements that are exactly ``element_size``
  12786. bytes, and the copy between buffers uses a sequence of
  12787. :ref:`unordered atomic <ordering>` load/store operations that are a positive
  12788. integer multiple of the ``element_size`` in size.
  12789. Arguments:
  12790. """"""""""
  12791. The first three arguments are the same as they are in the
  12792. :ref:`@llvm.memmove <int_memmove>` intrinsic, with the added constraint that
  12793. ``len`` is required to be a positive integer multiple of the ``element_size``.
  12794. If ``len`` is not a positive integer multiple of ``element_size``, then the
  12795. behaviour of the intrinsic is undefined.
  12796. ``element_size`` must be a compile-time constant positive power of two no
  12797. greater than a target-specific atomic access size limit.
  12798. For each of the input pointers the ``align`` parameter attribute must be
  12799. specified. It must be a power of two no less than the ``element_size``. Caller
  12800. guarantees that both the source and destination pointers are aligned to that
  12801. boundary.
  12802. Semantics:
  12803. """"""""""
  12804. The '``llvm.memmove.element.unordered.atomic.*``' intrinsic copies ``len`` bytes
  12805. of memory from the source location to the destination location. These locations
  12806. are allowed to overlap. The memory copy is performed as a sequence of load/store
  12807. operations where each access is guaranteed to be a multiple of ``element_size``
  12808. bytes wide and aligned at an ``element_size`` boundary.
  12809. The order of the copy is unspecified. The same value may be read from the source
  12810. buffer many times, but only one write is issued to the destination buffer per
  12811. element. It is well defined to have concurrent reads and writes to both source
  12812. and destination provided those reads and writes are unordered atomic when
  12813. specified.
  12814. This intrinsic does not provide any additional ordering guarantees over those
  12815. provided by a set of unordered loads from the source location and stores to the
  12816. destination.
  12817. Lowering:
  12818. """""""""
  12819. In the most general case call to the
  12820. '``llvm.memmove.element.unordered.atomic.*``' is lowered to a call to the symbol
  12821. ``__llvm_memmove_element_unordered_atomic_*``. Where '*' is replaced with an
  12822. actual element size.
  12823. The optimizer is allowed to inline the memory copy when it's profitable to do so.
  12824. .. _int_memset_element_unordered_atomic:
  12825. '``llvm.memset.element.unordered.atomic``' Intrinsic
  12826. ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  12827. Syntax:
  12828. """""""
  12829. This is an overloaded intrinsic. You can use ``llvm.memset.element.unordered.atomic`` on
  12830. any integer bit width and for different address spaces. Not all targets
  12831. support all bit widths however.
  12832. ::
  12833. declare void @llvm.memset.element.unordered.atomic.p0i8.i32(i8* <dest>,
  12834. i8 <value>,
  12835. i32 <len>,
  12836. i32 <element_size>)
  12837. declare void @llvm.memset.element.unordered.atomic.p0i8.i64(i8* <dest>,
  12838. i8 <value>,
  12839. i64 <len>,
  12840. i32 <element_size>)
  12841. Overview:
  12842. """""""""
  12843. The '``llvm.memset.element.unordered.atomic.*``' intrinsic is a specialization of the
  12844. '``llvm.memset.*``' intrinsic. It differs in that the ``dest`` is treated as an array
  12845. with elements that are exactly ``element_size`` bytes, and the assignment to that array
  12846. uses uses a sequence of :ref:`unordered atomic <ordering>` store operations
  12847. that are a positive integer multiple of the ``element_size`` in size.
  12848. Arguments:
  12849. """"""""""
  12850. The first three arguments are the same as they are in the :ref:`@llvm.memset <int_memset>`
  12851. intrinsic, with the added constraint that ``len`` is required to be a positive integer
  12852. multiple of the ``element_size``. If ``len`` is not a positive integer multiple of
  12853. ``element_size``, then the behaviour of the intrinsic is undefined.
  12854. ``element_size`` must be a compile-time constant positive power of two no greater than
  12855. target-specific atomic access size limit.
  12856. The ``dest`` input pointer must have the ``align`` parameter attribute specified. It
  12857. must be a power of two no less than the ``element_size``. Caller guarantees that
  12858. the destination pointer is aligned to that boundary.
  12859. Semantics:
  12860. """"""""""
  12861. The '``llvm.memset.element.unordered.atomic.*``' intrinsic sets the ``len`` bytes of
  12862. memory starting at the destination location to the given ``value``. The memory is
  12863. set with a sequence of store operations where each access is guaranteed to be a
  12864. multiple of ``element_size`` bytes wide and aligned at an ``element_size`` boundary.
  12865. The order of the assignment is unspecified. Only one write is issued to the
  12866. destination buffer per element. It is well defined to have concurrent reads and
  12867. writes to the destination provided those reads and writes are unordered atomic
  12868. when specified.
  12869. This intrinsic does not provide any additional ordering guarantees over those
  12870. provided by a set of unordered stores to the destination.
  12871. Lowering:
  12872. """""""""
  12873. In the most general case call to the '``llvm.memset.element.unordered.atomic.*``' is
  12874. lowered to a call to the symbol ``__llvm_memset_element_unordered_atomic_*``. Where '*'
  12875. is replaced with an actual element size.
  12876. The optimizer is allowed to inline the memory assignment when it's profitable to do so.
  12877. Objective-C ARC Runtime Intrinsics
  12878. ----------------------------------
  12879. LLVM provides intrinsics that lower to Objective-C ARC runtime entry points.
  12880. LLVM is aware of the semantics of these functions, and optimizes based on that
  12881. knowledge. You can read more about the details of Objective-C ARC `here
  12882. <https://clang.llvm.org/docs/AutomaticReferenceCounting.html>`_.
  12883. '``llvm.objc.autorelease``' Intrinsic
  12884. ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  12885. Syntax:
  12886. """""""
  12887. ::
  12888. declare i8* @llvm.objc.autorelease(i8*)
  12889. Lowering:
  12890. """""""""
  12891. Lowers to a call to `objc_autorelease <https://clang.llvm.org/docs/AutomaticReferenceCounting.html#arc-runtime-objc-autorelease>`_.
  12892. '``llvm.objc.autoreleasePoolPop``' Intrinsic
  12893. ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  12894. Syntax:
  12895. """""""
  12896. ::
  12897. declare void @llvm.objc.autoreleasePoolPop(i8*)
  12898. Lowering:
  12899. """""""""
  12900. Lowers to a call to `objc_autoreleasePoolPop <https://clang.llvm.org/docs/AutomaticReferenceCounting.html#void-objc-autoreleasepoolpop-void-pool>`_.
  12901. '``llvm.objc.autoreleasePoolPush``' Intrinsic
  12902. ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  12903. Syntax:
  12904. """""""
  12905. ::
  12906. declare i8* @llvm.objc.autoreleasePoolPush()
  12907. Lowering:
  12908. """""""""
  12909. Lowers to a call to `objc_autoreleasePoolPush <https://clang.llvm.org/docs/AutomaticReferenceCounting.html#void-objc-autoreleasepoolpush-void>`_.
  12910. '``llvm.objc.autoreleaseReturnValue``' Intrinsic
  12911. ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  12912. Syntax:
  12913. """""""
  12914. ::
  12915. declare i8* @llvm.objc.autoreleaseReturnValue(i8*)
  12916. Lowering:
  12917. """""""""
  12918. Lowers to a call to `objc_autoreleaseReturnValue <https://clang.llvm.org/docs/AutomaticReferenceCounting.html#arc-runtime-objc-autoreleasereturnvalue>`_.
  12919. '``llvm.objc.copyWeak``' Intrinsic
  12920. ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  12921. Syntax:
  12922. """""""
  12923. ::
  12924. declare void @llvm.objc.copyWeak(i8**, i8**)
  12925. Lowering:
  12926. """""""""
  12927. Lowers to a call to `objc_copyWeak <https://clang.llvm.org/docs/AutomaticReferenceCounting.html#void-objc-copyweak-id-dest-id-src>`_.
  12928. '``llvm.objc.destroyWeak``' Intrinsic
  12929. ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  12930. Syntax:
  12931. """""""
  12932. ::
  12933. declare void @llvm.objc.destroyWeak(i8**)
  12934. Lowering:
  12935. """""""""
  12936. Lowers to a call to `objc_destroyWeak <https://clang.llvm.org/docs/AutomaticReferenceCounting.html#void-objc-destroyweak-id-object>`_.
  12937. '``llvm.objc.initWeak``' Intrinsic
  12938. ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  12939. Syntax:
  12940. """""""
  12941. ::
  12942. declare i8* @llvm.objc.initWeak(i8**, i8*)
  12943. Lowering:
  12944. """""""""
  12945. Lowers to a call to `objc_initWeak <https://clang.llvm.org/docs/AutomaticReferenceCounting.html#arc-runtime-objc-initweak>`_.
  12946. '``llvm.objc.loadWeak``' Intrinsic
  12947. ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  12948. Syntax:
  12949. """""""
  12950. ::
  12951. declare i8* @llvm.objc.loadWeak(i8**)
  12952. Lowering:
  12953. """""""""
  12954. Lowers to a call to `objc_loadWeak <https://clang.llvm.org/docs/AutomaticReferenceCounting.html#arc-runtime-objc-loadweak>`_.
  12955. '``llvm.objc.loadWeakRetained``' Intrinsic
  12956. ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  12957. Syntax:
  12958. """""""
  12959. ::
  12960. declare i8* @llvm.objc.loadWeakRetained(i8**)
  12961. Lowering:
  12962. """""""""
  12963. Lowers to a call to `objc_loadWeakRetained <https://clang.llvm.org/docs/AutomaticReferenceCounting.html#arc-runtime-objc-loadweakretained>`_.
  12964. '``llvm.objc.moveWeak``' Intrinsic
  12965. ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  12966. Syntax:
  12967. """""""
  12968. ::
  12969. declare void @llvm.objc.moveWeak(i8**, i8**)
  12970. Lowering:
  12971. """""""""
  12972. Lowers to a call to `objc_moveWeak <https://clang.llvm.org/docs/AutomaticReferenceCounting.html#void-objc-moveweak-id-dest-id-src>`_.
  12973. '``llvm.objc.release``' Intrinsic
  12974. ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  12975. Syntax:
  12976. """""""
  12977. ::
  12978. declare void @llvm.objc.release(i8*)
  12979. Lowering:
  12980. """""""""
  12981. Lowers to a call to `objc_release <https://clang.llvm.org/docs/AutomaticReferenceCounting.html#void-objc-release-id-value>`_.
  12982. '``llvm.objc.retain``' Intrinsic
  12983. ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  12984. Syntax:
  12985. """""""
  12986. ::
  12987. declare i8* @llvm.objc.retain(i8*)
  12988. Lowering:
  12989. """""""""
  12990. Lowers to a call to `objc_retain <https://clang.llvm.org/docs/AutomaticReferenceCounting.html#arc-runtime-objc-retain>`_.
  12991. '``llvm.objc.retainAutorelease``' Intrinsic
  12992. ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  12993. Syntax:
  12994. """""""
  12995. ::
  12996. declare i8* @llvm.objc.retainAutorelease(i8*)
  12997. Lowering:
  12998. """""""""
  12999. Lowers to a call to `objc_retainAutorelease <https://clang.llvm.org/docs/AutomaticReferenceCounting.html#arc-runtime-objc-retainautorelease>`_.
  13000. '``llvm.objc.retainAutoreleaseReturnValue``' Intrinsic
  13001. ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  13002. Syntax:
  13003. """""""
  13004. ::
  13005. declare i8* @llvm.objc.retainAutoreleaseReturnValue(i8*)
  13006. Lowering:
  13007. """""""""
  13008. Lowers to a call to `objc_retainAutoreleaseReturnValue <https://clang.llvm.org/docs/AutomaticReferenceCounting.html#arc-runtime-objc-retainautoreleasereturnvalue>`_.
  13009. '``llvm.objc.retainAutoreleasedReturnValue``' Intrinsic
  13010. ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  13011. Syntax:
  13012. """""""
  13013. ::
  13014. declare i8* @llvm.objc.retainAutoreleasedReturnValue(i8*)
  13015. Lowering:
  13016. """""""""
  13017. Lowers to a call to `objc_retainAutoreleasedReturnValue <https://clang.llvm.org/docs/AutomaticReferenceCounting.html#arc-runtime-objc-retainautoreleasedreturnvalue>`_.
  13018. '``llvm.objc.retainBlock``' Intrinsic
  13019. ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  13020. Syntax:
  13021. """""""
  13022. ::
  13023. declare i8* @llvm.objc.retainBlock(i8*)
  13024. Lowering:
  13025. """""""""
  13026. Lowers to a call to `objc_retainBlock <https://clang.llvm.org/docs/AutomaticReferenceCounting.html#arc-runtime-objc-retainblock>`_.
  13027. '``llvm.objc.storeStrong``' Intrinsic
  13028. ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  13029. Syntax:
  13030. """""""
  13031. ::
  13032. declare void @llvm.objc.storeStrong(i8**, i8*)
  13033. Lowering:
  13034. """""""""
  13035. Lowers to a call to `objc_storeStrong <https://clang.llvm.org/docs/AutomaticReferenceCounting.html#void-objc-storestrong-id-object-id-value>`_.
  13036. '``llvm.objc.storeWeak``' Intrinsic
  13037. ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  13038. Syntax:
  13039. """""""
  13040. ::
  13041. declare i8* @llvm.objc.storeWeak(i8**, i8*)
  13042. Lowering:
  13043. """""""""
  13044. Lowers to a call to `objc_storeWeak <https://clang.llvm.org/docs/AutomaticReferenceCounting.html#arc-runtime-objc-storeweak>`_.
  13045. Preserving Debug Information Intrinsics
  13046. ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  13047. These intrinsics are used to carry certain debuginfo together with
  13048. IR-level operations. For example, it may be desirable to
  13049. know the structure/union name and the original user-level field
  13050. indices. Such information got lost in IR GetElementPtr instruction
  13051. since the IR types are different from debugInfo types and unions
  13052. are converted to structs in IR.
  13053. '``llvm.preserve.array.access.index``' Intrinsic
  13054. ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  13055. Syntax:
  13056. """""""
  13057. ::
  13058. declare <ret_type>
  13059. @llvm.preserve.array.access.index.p0s_union.anons.p0a10s_union.anons(<type> base,
  13060. i32 dim,
  13061. i32 index)
  13062. Overview:
  13063. """""""""
  13064. The '``llvm.preserve.array.access.index``' intrinsic returns the getelementptr address
  13065. based on array base ``base``, array dimension ``dim`` and the last access index ``index``
  13066. into the array. The return type ``ret_type`` is a pointer type to the array element.
  13067. The array ``dim`` and ``index`` are preserved which is more robust than
  13068. getelementptr instruction which may be subject to compiler transformation.
  13069. The ``llvm.preserve.access.index`` type of metadata is attached to this call instruction
  13070. to provide array or pointer debuginfo type.
  13071. The metadata is a ``DICompositeType`` or ``DIDerivedType`` representing the
  13072. debuginfo version of ``type``.
  13073. Arguments:
  13074. """"""""""
  13075. The ``base`` is the array base address. The ``dim`` is the array dimension.
  13076. The ``base`` is a pointer if ``dim`` equals 0.
  13077. The ``index`` is the last access index into the array or pointer.
  13078. Semantics:
  13079. """"""""""
  13080. The '``llvm.preserve.array.access.index``' intrinsic produces the same result
  13081. as a getelementptr with base ``base`` and access operands ``{dim's 0's, index}``.
  13082. '``llvm.preserve.union.access.index``' Intrinsic
  13083. ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  13084. Syntax:
  13085. """""""
  13086. ::
  13087. declare <type>
  13088. @llvm.preserve.union.access.index.p0s_union.anons.p0s_union.anons(<type> base,
  13089. i32 di_index)
  13090. Overview:
  13091. """""""""
  13092. The '``llvm.preserve.union.access.index``' intrinsic carries the debuginfo field index
  13093. ``di_index`` and returns the ``base`` address.
  13094. The ``llvm.preserve.access.index`` type of metadata is attached to this call instruction
  13095. to provide union debuginfo type.
  13096. The metadata is a ``DICompositeType`` representing the debuginfo version of ``type``.
  13097. The return type ``type`` is the same as the ``base`` type.
  13098. Arguments:
  13099. """"""""""
  13100. The ``base`` is the union base address. The ``di_index`` is the field index in debuginfo.
  13101. Semantics:
  13102. """"""""""
  13103. The '``llvm.preserve.union.access.index``' intrinsic returns the ``base`` address.
  13104. '``llvm.preserve.struct.access.index``' Intrinsic
  13105. ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  13106. Syntax:
  13107. """""""
  13108. ::
  13109. declare <ret_type>
  13110. @llvm.preserve.struct.access.index.p0i8.p0s_struct.anon.0s(<type> base,
  13111. i32 gep_index,
  13112. i32 di_index)
  13113. Overview:
  13114. """""""""
  13115. The '``llvm.preserve.struct.access.index``' intrinsic returns the getelementptr address
  13116. based on struct base ``base`` and IR struct member index ``gep_index``.
  13117. The ``llvm.preserve.access.index`` type of metadata is attached to this call instruction
  13118. to provide struct debuginfo type.
  13119. The metadata is a ``DICompositeType`` representing the debuginfo version of ``type``.
  13120. The return type ``ret_type`` is a pointer type to the structure member.
  13121. Arguments:
  13122. """"""""""
  13123. The ``base`` is the structure base address. The ``gep_index`` is the struct member index
  13124. based on IR structures. The ``di_index`` is the struct member index based on debuginfo.
  13125. Semantics:
  13126. """"""""""
  13127. The '``llvm.preserve.struct.access.index``' intrinsic produces the same result
  13128. as a getelementptr with base ``base`` and access operands ``{0, gep_index}``.