LangRef.rst 394 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602260326042605260626072608260926102611261226132614261526162617261826192620262126222623262426252626262726282629263026312632263326342635263626372638263926402641264226432644264526462647264826492650265126522653265426552656265726582659266026612662266326642665266626672668266926702671267226732674267526762677267826792680268126822683268426852686268726882689269026912692269326942695269626972698269927002701270227032704270527062707270827092710271127122713271427152716271727182719272027212722272327242725272627272728272927302731273227332734273527362737273827392740274127422743274427452746274727482749275027512752275327542755275627572758275927602761276227632764276527662767276827692770277127722773277427752776277727782779278027812782278327842785278627872788278927902791279227932794279527962797279827992800280128022803280428052806280728082809281028112812281328142815281628172818281928202821282228232824282528262827282828292830283128322833283428352836283728382839284028412842284328442845284628472848284928502851285228532854285528562857285828592860286128622863286428652866286728682869287028712872287328742875287628772878287928802881288228832884288528862887288828892890289128922893289428952896289728982899290029012902290329042905290629072908290929102911291229132914291529162917291829192920292129222923292429252926292729282929293029312932293329342935293629372938293929402941294229432944294529462947294829492950295129522953295429552956295729582959296029612962296329642965296629672968296929702971297229732974297529762977297829792980298129822983298429852986298729882989299029912992299329942995299629972998299930003001300230033004300530063007300830093010301130123013301430153016301730183019302030213022302330243025302630273028302930303031303230333034303530363037303830393040304130423043304430453046304730483049305030513052305330543055305630573058305930603061306230633064306530663067306830693070307130723073307430753076307730783079308030813082308330843085308630873088308930903091309230933094309530963097309830993100310131023103310431053106310731083109311031113112311331143115311631173118311931203121312231233124312531263127312831293130313131323133313431353136313731383139314031413142314331443145314631473148314931503151315231533154315531563157315831593160316131623163316431653166316731683169317031713172317331743175317631773178317931803181318231833184318531863187318831893190319131923193319431953196319731983199320032013202320332043205320632073208320932103211321232133214321532163217321832193220322132223223322432253226322732283229323032313232323332343235323632373238323932403241324232433244324532463247324832493250325132523253325432553256325732583259326032613262326332643265326632673268326932703271327232733274327532763277327832793280328132823283328432853286328732883289329032913292329332943295329632973298329933003301330233033304330533063307330833093310331133123313331433153316331733183319332033213322332333243325332633273328332933303331333233333334333533363337333833393340334133423343334433453346334733483349335033513352335333543355335633573358335933603361336233633364336533663367336833693370337133723373337433753376337733783379338033813382338333843385338633873388338933903391339233933394339533963397339833993400340134023403340434053406340734083409341034113412341334143415341634173418341934203421342234233424342534263427342834293430343134323433343434353436343734383439344034413442344334443445344634473448344934503451345234533454345534563457345834593460346134623463346434653466346734683469347034713472347334743475347634773478347934803481348234833484348534863487348834893490349134923493349434953496349734983499350035013502350335043505350635073508350935103511351235133514351535163517351835193520352135223523352435253526352735283529353035313532353335343535353635373538353935403541354235433544354535463547354835493550355135523553355435553556355735583559356035613562356335643565356635673568356935703571357235733574357535763577357835793580358135823583358435853586358735883589359035913592359335943595359635973598359936003601360236033604360536063607360836093610361136123613361436153616361736183619362036213622362336243625362636273628362936303631363236333634363536363637363836393640364136423643364436453646364736483649365036513652365336543655365636573658365936603661366236633664366536663667366836693670367136723673367436753676367736783679368036813682368336843685368636873688368936903691369236933694369536963697369836993700370137023703370437053706370737083709371037113712371337143715371637173718371937203721372237233724372537263727372837293730373137323733373437353736373737383739374037413742374337443745374637473748374937503751375237533754375537563757375837593760376137623763376437653766376737683769377037713772377337743775377637773778377937803781378237833784378537863787378837893790379137923793379437953796379737983799380038013802380338043805380638073808380938103811381238133814381538163817381838193820382138223823382438253826382738283829383038313832383338343835383638373838383938403841384238433844384538463847384838493850385138523853385438553856385738583859386038613862386338643865386638673868386938703871387238733874387538763877387838793880388138823883388438853886388738883889389038913892389338943895389638973898389939003901390239033904390539063907390839093910391139123913391439153916391739183919392039213922392339243925392639273928392939303931393239333934393539363937393839393940394139423943394439453946394739483949395039513952395339543955395639573958395939603961396239633964396539663967396839693970397139723973397439753976397739783979398039813982398339843985398639873988398939903991399239933994399539963997399839994000400140024003400440054006400740084009401040114012401340144015401640174018401940204021402240234024402540264027402840294030403140324033403440354036403740384039404040414042404340444045404640474048404940504051405240534054405540564057405840594060406140624063406440654066406740684069407040714072407340744075407640774078407940804081408240834084408540864087408840894090409140924093409440954096409740984099410041014102410341044105410641074108410941104111411241134114411541164117411841194120412141224123412441254126412741284129413041314132413341344135413641374138413941404141414241434144414541464147414841494150415141524153415441554156415741584159416041614162416341644165416641674168416941704171417241734174417541764177417841794180418141824183418441854186418741884189419041914192419341944195419641974198419942004201420242034204420542064207420842094210421142124213421442154216421742184219422042214222422342244225422642274228422942304231423242334234423542364237423842394240424142424243424442454246424742484249425042514252425342544255425642574258425942604261426242634264426542664267426842694270427142724273427442754276427742784279428042814282428342844285428642874288428942904291429242934294429542964297429842994300430143024303430443054306430743084309431043114312431343144315431643174318431943204321432243234324432543264327432843294330433143324333433443354336433743384339434043414342434343444345434643474348434943504351435243534354435543564357435843594360436143624363436443654366436743684369437043714372437343744375437643774378437943804381438243834384438543864387438843894390439143924393439443954396439743984399440044014402440344044405440644074408440944104411441244134414441544164417441844194420442144224423442444254426442744284429443044314432443344344435443644374438443944404441444244434444444544464447444844494450445144524453445444554456445744584459446044614462446344644465446644674468446944704471447244734474447544764477447844794480448144824483448444854486448744884489449044914492449344944495449644974498449945004501450245034504450545064507450845094510451145124513451445154516451745184519452045214522452345244525452645274528452945304531453245334534453545364537453845394540454145424543454445454546454745484549455045514552455345544555455645574558455945604561456245634564456545664567456845694570457145724573457445754576457745784579458045814582458345844585458645874588458945904591459245934594459545964597459845994600460146024603460446054606460746084609461046114612461346144615461646174618461946204621462246234624462546264627462846294630463146324633463446354636463746384639464046414642464346444645464646474648464946504651465246534654465546564657465846594660466146624663466446654666466746684669467046714672467346744675467646774678467946804681468246834684468546864687468846894690469146924693469446954696469746984699470047014702470347044705470647074708470947104711471247134714471547164717471847194720472147224723472447254726472747284729473047314732473347344735473647374738473947404741474247434744474547464747474847494750475147524753475447554756475747584759476047614762476347644765476647674768476947704771477247734774477547764777477847794780478147824783478447854786478747884789479047914792479347944795479647974798479948004801480248034804480548064807480848094810481148124813481448154816481748184819482048214822482348244825482648274828482948304831483248334834483548364837483848394840484148424843484448454846484748484849485048514852485348544855485648574858485948604861486248634864486548664867486848694870487148724873487448754876487748784879488048814882488348844885488648874888488948904891489248934894489548964897489848994900490149024903490449054906490749084909491049114912491349144915491649174918491949204921492249234924492549264927492849294930493149324933493449354936493749384939494049414942494349444945494649474948494949504951495249534954495549564957495849594960496149624963496449654966496749684969497049714972497349744975497649774978497949804981498249834984498549864987498849894990499149924993499449954996499749984999500050015002500350045005500650075008500950105011501250135014501550165017501850195020502150225023502450255026502750285029503050315032503350345035503650375038503950405041504250435044504550465047504850495050505150525053505450555056505750585059506050615062506350645065506650675068506950705071507250735074507550765077507850795080508150825083508450855086508750885089509050915092509350945095509650975098509951005101510251035104510551065107510851095110511151125113511451155116511751185119512051215122512351245125512651275128512951305131513251335134513551365137513851395140514151425143514451455146514751485149515051515152515351545155515651575158515951605161516251635164516551665167516851695170517151725173517451755176517751785179518051815182518351845185518651875188518951905191519251935194519551965197519851995200520152025203520452055206520752085209521052115212521352145215521652175218521952205221522252235224522552265227522852295230523152325233523452355236523752385239524052415242524352445245524652475248524952505251525252535254525552565257525852595260526152625263526452655266526752685269527052715272527352745275527652775278527952805281528252835284528552865287528852895290529152925293529452955296529752985299530053015302530353045305530653075308530953105311531253135314531553165317531853195320532153225323532453255326532753285329533053315332533353345335533653375338533953405341534253435344534553465347534853495350535153525353535453555356535753585359536053615362536353645365536653675368536953705371537253735374537553765377537853795380538153825383538453855386538753885389539053915392539353945395539653975398539954005401540254035404540554065407540854095410541154125413541454155416541754185419542054215422542354245425542654275428542954305431543254335434543554365437543854395440544154425443544454455446544754485449545054515452545354545455545654575458545954605461546254635464546554665467546854695470547154725473547454755476547754785479548054815482548354845485548654875488548954905491549254935494549554965497549854995500550155025503550455055506550755085509551055115512551355145515551655175518551955205521552255235524552555265527552855295530553155325533553455355536553755385539554055415542554355445545554655475548554955505551555255535554555555565557555855595560556155625563556455655566556755685569557055715572557355745575557655775578557955805581558255835584558555865587558855895590559155925593559455955596559755985599560056015602560356045605560656075608560956105611561256135614561556165617561856195620562156225623562456255626562756285629563056315632563356345635563656375638563956405641564256435644564556465647564856495650565156525653565456555656565756585659566056615662566356645665566656675668566956705671567256735674567556765677567856795680568156825683568456855686568756885689569056915692569356945695569656975698569957005701570257035704570557065707570857095710571157125713571457155716571757185719572057215722572357245725572657275728572957305731573257335734573557365737573857395740574157425743574457455746574757485749575057515752575357545755575657575758575957605761576257635764576557665767576857695770577157725773577457755776577757785779578057815782578357845785578657875788578957905791579257935794579557965797579857995800580158025803580458055806580758085809581058115812581358145815581658175818581958205821582258235824582558265827582858295830583158325833583458355836583758385839584058415842584358445845584658475848584958505851585258535854585558565857585858595860586158625863586458655866586758685869587058715872587358745875587658775878587958805881588258835884588558865887588858895890589158925893589458955896589758985899590059015902590359045905590659075908590959105911591259135914591559165917591859195920592159225923592459255926592759285929593059315932593359345935593659375938593959405941594259435944594559465947594859495950595159525953595459555956595759585959596059615962596359645965596659675968596959705971597259735974597559765977597859795980598159825983598459855986598759885989599059915992599359945995599659975998599960006001600260036004600560066007600860096010601160126013601460156016601760186019602060216022602360246025602660276028602960306031603260336034603560366037603860396040604160426043604460456046604760486049605060516052605360546055605660576058605960606061606260636064606560666067606860696070607160726073607460756076607760786079608060816082608360846085608660876088608960906091609260936094609560966097609860996100610161026103610461056106610761086109611061116112611361146115611661176118611961206121612261236124612561266127612861296130613161326133613461356136613761386139614061416142614361446145614661476148614961506151615261536154615561566157615861596160616161626163616461656166616761686169617061716172617361746175617661776178617961806181618261836184618561866187618861896190619161926193619461956196619761986199620062016202620362046205620662076208620962106211621262136214621562166217621862196220622162226223622462256226622762286229623062316232623362346235623662376238623962406241624262436244624562466247624862496250625162526253625462556256625762586259626062616262626362646265626662676268626962706271627262736274627562766277627862796280628162826283628462856286628762886289629062916292629362946295629662976298629963006301630263036304630563066307630863096310631163126313631463156316631763186319632063216322632363246325632663276328632963306331633263336334633563366337633863396340634163426343634463456346634763486349635063516352635363546355635663576358635963606361636263636364636563666367636863696370637163726373637463756376637763786379638063816382638363846385638663876388638963906391639263936394639563966397639863996400640164026403640464056406640764086409641064116412641364146415641664176418641964206421642264236424642564266427642864296430643164326433643464356436643764386439644064416442644364446445644664476448644964506451645264536454645564566457645864596460646164626463646464656466646764686469647064716472647364746475647664776478647964806481648264836484648564866487648864896490649164926493649464956496649764986499650065016502650365046505650665076508650965106511651265136514651565166517651865196520652165226523652465256526652765286529653065316532653365346535653665376538653965406541654265436544654565466547654865496550655165526553655465556556655765586559656065616562656365646565656665676568656965706571657265736574657565766577657865796580658165826583658465856586658765886589659065916592659365946595659665976598659966006601660266036604660566066607660866096610661166126613661466156616661766186619662066216622662366246625662666276628662966306631663266336634663566366637663866396640664166426643664466456646664766486649665066516652665366546655665666576658665966606661666266636664666566666667666866696670667166726673667466756676667766786679668066816682668366846685668666876688668966906691669266936694669566966697669866996700670167026703670467056706670767086709671067116712671367146715671667176718671967206721672267236724672567266727672867296730673167326733673467356736673767386739674067416742674367446745674667476748674967506751675267536754675567566757675867596760676167626763676467656766676767686769677067716772677367746775677667776778677967806781678267836784678567866787678867896790679167926793679467956796679767986799680068016802680368046805680668076808680968106811681268136814681568166817681868196820682168226823682468256826682768286829683068316832683368346835683668376838683968406841684268436844684568466847684868496850685168526853685468556856685768586859686068616862686368646865686668676868686968706871687268736874687568766877687868796880688168826883688468856886688768886889689068916892689368946895689668976898689969006901690269036904690569066907690869096910691169126913691469156916691769186919692069216922692369246925692669276928692969306931693269336934693569366937693869396940694169426943694469456946694769486949695069516952695369546955695669576958695969606961696269636964696569666967696869696970697169726973697469756976697769786979698069816982698369846985698669876988698969906991699269936994699569966997699869997000700170027003700470057006700770087009701070117012701370147015701670177018701970207021702270237024702570267027702870297030703170327033703470357036703770387039704070417042704370447045704670477048704970507051705270537054705570567057705870597060706170627063706470657066706770687069707070717072707370747075707670777078707970807081708270837084708570867087708870897090709170927093709470957096709770987099710071017102710371047105710671077108710971107111711271137114711571167117711871197120712171227123712471257126712771287129713071317132713371347135713671377138713971407141714271437144714571467147714871497150715171527153715471557156715771587159716071617162716371647165716671677168716971707171717271737174717571767177717871797180718171827183718471857186718771887189719071917192719371947195719671977198719972007201720272037204720572067207720872097210721172127213721472157216721772187219722072217222722372247225722672277228722972307231723272337234723572367237723872397240724172427243724472457246724772487249725072517252725372547255725672577258725972607261726272637264726572667267726872697270727172727273727472757276727772787279728072817282728372847285728672877288728972907291729272937294729572967297729872997300730173027303730473057306730773087309731073117312731373147315731673177318731973207321732273237324732573267327732873297330733173327333733473357336733773387339734073417342734373447345734673477348734973507351735273537354735573567357735873597360736173627363736473657366736773687369737073717372737373747375737673777378737973807381738273837384738573867387738873897390739173927393739473957396739773987399740074017402740374047405740674077408740974107411741274137414741574167417741874197420742174227423742474257426742774287429743074317432743374347435743674377438743974407441744274437444744574467447744874497450745174527453745474557456745774587459746074617462746374647465746674677468746974707471747274737474747574767477747874797480748174827483748474857486748774887489749074917492749374947495749674977498749975007501750275037504750575067507750875097510751175127513751475157516751775187519752075217522752375247525752675277528752975307531753275337534753575367537753875397540754175427543754475457546754775487549755075517552755375547555755675577558755975607561756275637564756575667567756875697570757175727573757475757576757775787579758075817582758375847585758675877588758975907591759275937594759575967597759875997600760176027603760476057606760776087609761076117612761376147615761676177618761976207621762276237624762576267627762876297630763176327633763476357636763776387639764076417642764376447645764676477648764976507651765276537654765576567657765876597660766176627663766476657666766776687669767076717672767376747675767676777678767976807681768276837684768576867687768876897690769176927693769476957696769776987699770077017702770377047705770677077708770977107711771277137714771577167717771877197720772177227723772477257726772777287729773077317732773377347735773677377738773977407741774277437744774577467747774877497750775177527753775477557756775777587759776077617762776377647765776677677768776977707771777277737774777577767777777877797780778177827783778477857786778777887789779077917792779377947795779677977798779978007801780278037804780578067807780878097810781178127813781478157816781778187819782078217822782378247825782678277828782978307831783278337834783578367837783878397840784178427843784478457846784778487849785078517852785378547855785678577858785978607861786278637864786578667867786878697870787178727873787478757876787778787879788078817882788378847885788678877888788978907891789278937894789578967897789878997900790179027903790479057906790779087909791079117912791379147915791679177918791979207921792279237924792579267927792879297930793179327933793479357936793779387939794079417942794379447945794679477948794979507951795279537954795579567957795879597960796179627963796479657966796779687969797079717972797379747975797679777978797979807981798279837984798579867987798879897990799179927993799479957996799779987999800080018002800380048005800680078008800980108011801280138014801580168017801880198020802180228023802480258026802780288029803080318032803380348035803680378038803980408041804280438044804580468047804880498050805180528053805480558056805780588059806080618062806380648065806680678068806980708071807280738074807580768077807880798080808180828083808480858086808780888089809080918092809380948095809680978098809981008101810281038104810581068107810881098110811181128113811481158116811781188119812081218122812381248125812681278128812981308131813281338134813581368137813881398140814181428143814481458146814781488149815081518152815381548155815681578158815981608161816281638164816581668167816881698170817181728173817481758176817781788179818081818182818381848185818681878188818981908191819281938194819581968197819881998200820182028203820482058206820782088209821082118212821382148215821682178218821982208221822282238224822582268227822882298230823182328233823482358236823782388239824082418242824382448245824682478248824982508251825282538254825582568257825882598260826182628263826482658266826782688269827082718272827382748275827682778278827982808281828282838284828582868287828882898290829182928293829482958296829782988299830083018302830383048305830683078308830983108311831283138314831583168317831883198320832183228323832483258326832783288329833083318332833383348335833683378338833983408341834283438344834583468347834883498350835183528353835483558356835783588359836083618362836383648365836683678368836983708371837283738374837583768377837883798380838183828383838483858386838783888389839083918392839383948395839683978398839984008401840284038404840584068407840884098410841184128413841484158416841784188419842084218422842384248425842684278428842984308431843284338434843584368437843884398440844184428443844484458446844784488449845084518452845384548455845684578458845984608461846284638464846584668467846884698470847184728473847484758476847784788479848084818482848384848485848684878488848984908491849284938494849584968497849884998500850185028503850485058506850785088509851085118512851385148515851685178518851985208521852285238524852585268527852885298530853185328533853485358536853785388539854085418542854385448545854685478548854985508551855285538554855585568557855885598560856185628563856485658566856785688569857085718572857385748575857685778578857985808581858285838584858585868587858885898590859185928593859485958596859785988599860086018602860386048605860686078608860986108611861286138614861586168617861886198620862186228623862486258626862786288629863086318632863386348635863686378638863986408641864286438644864586468647864886498650865186528653865486558656865786588659866086618662866386648665866686678668866986708671867286738674867586768677867886798680868186828683868486858686868786888689869086918692869386948695869686978698869987008701870287038704870587068707870887098710871187128713871487158716871787188719872087218722872387248725872687278728872987308731873287338734873587368737873887398740874187428743874487458746874787488749875087518752875387548755875687578758875987608761876287638764876587668767876887698770877187728773877487758776877787788779878087818782878387848785878687878788878987908791879287938794879587968797879887998800880188028803880488058806880788088809881088118812881388148815881688178818881988208821882288238824882588268827882888298830883188328833883488358836883788388839884088418842884388448845884688478848884988508851885288538854885588568857885888598860886188628863886488658866886788688869887088718872887388748875887688778878887988808881888288838884888588868887888888898890889188928893889488958896889788988899890089018902890389048905890689078908890989108911891289138914891589168917891889198920892189228923892489258926892789288929893089318932893389348935893689378938893989408941894289438944894589468947894889498950895189528953895489558956895789588959896089618962896389648965896689678968896989708971897289738974897589768977897889798980898189828983898489858986898789888989899089918992899389948995899689978998899990009001900290039004900590069007900890099010901190129013901490159016901790189019902090219022902390249025902690279028902990309031903290339034903590369037903890399040904190429043904490459046904790489049905090519052905390549055905690579058905990609061906290639064906590669067906890699070907190729073907490759076907790789079908090819082908390849085908690879088908990909091909290939094909590969097909890999100910191029103910491059106910791089109911091119112911391149115911691179118911991209121912291239124912591269127912891299130913191329133913491359136913791389139914091419142914391449145914691479148914991509151915291539154915591569157915891599160916191629163916491659166916791689169917091719172917391749175917691779178917991809181918291839184918591869187918891899190919191929193919491959196919791989199920092019202920392049205920692079208920992109211921292139214921592169217921892199220922192229223922492259226922792289229923092319232923392349235923692379238923992409241924292439244924592469247924892499250925192529253925492559256925792589259926092619262926392649265926692679268926992709271927292739274927592769277927892799280928192829283928492859286928792889289929092919292929392949295929692979298929993009301930293039304930593069307930893099310931193129313931493159316931793189319932093219322932393249325932693279328932993309331933293339334933593369337933893399340934193429343934493459346934793489349935093519352935393549355935693579358935993609361936293639364936593669367936893699370937193729373937493759376937793789379938093819382938393849385938693879388938993909391939293939394939593969397939893999400940194029403940494059406940794089409941094119412941394149415941694179418941994209421942294239424942594269427942894299430943194329433943494359436943794389439944094419442944394449445944694479448944994509451945294539454945594569457945894599460946194629463946494659466946794689469947094719472947394749475947694779478947994809481948294839484948594869487948894899490949194929493949494959496949794989499950095019502950395049505950695079508950995109511951295139514951595169517951895199520952195229523952495259526952795289529953095319532953395349535953695379538953995409541954295439544954595469547954895499550955195529553955495559556955795589559956095619562956395649565956695679568956995709571957295739574957595769577957895799580958195829583958495859586958795889589959095919592959395949595959695979598959996009601960296039604960596069607960896099610961196129613961496159616961796189619962096219622962396249625962696279628962996309631963296339634963596369637963896399640964196429643964496459646964796489649965096519652965396549655965696579658965996609661966296639664966596669667966896699670967196729673967496759676967796789679968096819682968396849685968696879688968996909691969296939694969596969697969896999700970197029703970497059706970797089709971097119712971397149715971697179718971997209721972297239724972597269727972897299730973197329733973497359736973797389739974097419742974397449745974697479748974997509751975297539754975597569757975897599760976197629763976497659766976797689769977097719772977397749775977697779778977997809781978297839784978597869787978897899790979197929793979497959796979797989799980098019802980398049805980698079808980998109811981298139814981598169817981898199820982198229823982498259826982798289829983098319832983398349835983698379838983998409841984298439844984598469847984898499850985198529853985498559856985798589859986098619862986398649865986698679868986998709871987298739874987598769877987898799880988198829883988498859886988798889889989098919892989398949895989698979898989999009901990299039904990599069907990899099910991199129913991499159916991799189919992099219922992399249925992699279928992999309931993299339934993599369937993899399940994199429943994499459946994799489949995099519952995399549955995699579958995999609961996299639964996599669967996899699970997199729973997499759976997799789979998099819982998399849985998699879988998999909991999299939994999599969997999899991000010001100021000310004100051000610007100081000910010100111001210013100141001510016100171001810019100201002110022100231002410025100261002710028100291003010031100321003310034100351003610037100381003910040100411004210043100441004510046100471004810049100501005110052100531005410055100561005710058100591006010061100621006310064100651006610067100681006910070100711007210073100741007510076100771007810079100801008110082100831008410085100861008710088100891009010091100921009310094100951009610097100981009910100101011010210103101041010510106101071010810109101101011110112101131011410115101161011710118101191012010121101221012310124101251012610127101281012910130101311013210133101341013510136101371013810139101401014110142101431014410145101461014710148101491015010151101521015310154101551015610157101581015910160101611016210163101641016510166101671016810169101701017110172101731017410175101761017710178101791018010181101821018310184101851018610187101881018910190101911019210193101941019510196101971019810199102001020110202102031020410205102061020710208102091021010211102121021310214102151021610217102181021910220102211022210223102241022510226102271022810229102301023110232102331023410235102361023710238102391024010241102421024310244102451024610247102481024910250102511025210253102541025510256102571025810259102601026110262102631026410265102661026710268102691027010271102721027310274102751027610277102781027910280102811028210283102841028510286102871028810289102901029110292102931029410295102961029710298102991030010301103021030310304103051030610307103081030910310103111031210313103141031510316103171031810319103201032110322103231032410325103261032710328103291033010331103321033310334103351033610337103381033910340103411034210343103441034510346103471034810349103501035110352103531035410355103561035710358103591036010361103621036310364103651036610367103681036910370103711037210373103741037510376103771037810379103801038110382103831038410385103861038710388103891039010391103921039310394103951039610397103981039910400104011040210403104041040510406104071040810409104101041110412104131041410415104161041710418104191042010421104221042310424104251042610427104281042910430104311043210433104341043510436104371043810439104401044110442104431044410445104461044710448104491045010451104521045310454104551045610457104581045910460104611046210463104641046510466104671046810469104701047110472104731047410475104761047710478104791048010481104821048310484104851048610487104881048910490104911049210493104941049510496104971049810499105001050110502105031050410505105061050710508105091051010511105121051310514105151051610517105181051910520105211052210523105241052510526105271052810529105301053110532105331053410535105361053710538105391054010541105421054310544105451054610547105481054910550105511055210553105541055510556105571055810559105601056110562105631056410565105661056710568105691057010571105721057310574105751057610577105781057910580105811058210583105841058510586105871058810589105901059110592105931059410595105961059710598105991060010601106021060310604106051060610607106081060910610106111061210613106141061510616106171061810619106201062110622106231062410625106261062710628106291063010631106321063310634106351063610637106381063910640106411064210643106441064510646106471064810649106501065110652106531065410655106561065710658106591066010661106621066310664106651066610667106681066910670106711067210673106741067510676106771067810679106801068110682106831068410685106861068710688106891069010691106921069310694106951069610697106981069910700107011070210703107041070510706107071070810709107101071110712107131071410715107161071710718107191072010721107221072310724107251072610727107281072910730107311073210733107341073510736107371073810739107401074110742107431074410745107461074710748107491075010751107521075310754107551075610757107581075910760107611076210763107641076510766107671076810769107701077110772107731077410775107761077710778107791078010781107821078310784107851078610787107881078910790107911079210793107941079510796107971079810799108001080110802108031080410805108061080710808108091081010811108121081310814108151081610817108181081910820108211082210823108241082510826108271082810829108301083110832108331083410835108361083710838108391084010841108421084310844108451084610847108481084910850108511085210853108541085510856108571085810859108601086110862108631086410865108661086710868108691087010871108721087310874108751087610877108781087910880108811088210883108841088510886108871088810889108901089110892108931089410895108961089710898108991090010901109021090310904109051090610907109081090910910109111091210913109141091510916109171091810919109201092110922109231092410925109261092710928109291093010931109321093310934109351093610937109381093910940109411094210943109441094510946109471094810949109501095110952109531095410955109561095710958109591096010961109621096310964109651096610967109681096910970109711097210973109741097510976109771097810979109801098110982109831098410985109861098710988109891099010991109921099310994109951099610997109981099911000110011100211003110041100511006110071100811009110101101111012110131101411015110161101711018110191102011021110221102311024110251102611027110281102911030110311103211033110341103511036110371103811039110401104111042110431104411045110461104711048110491105011051110521105311054110551105611057110581105911060110611106211063110641106511066110671106811069110701107111072110731107411075110761107711078110791108011081110821108311084110851108611087110881108911090110911109211093110941109511096110971109811099111001110111102111031110411105111061110711108111091111011111111121111311114111151111611117111181111911120111211112211123111241112511126111271112811129111301113111132111331113411135111361113711138111391114011141111421114311144111451114611147111481114911150111511115211153111541115511156111571115811159111601116111162111631116411165111661116711168111691117011171111721117311174111751117611177111781117911180111811118211183111841118511186111871118811189111901119111192111931119411195111961119711198111991120011201112021120311204112051120611207112081120911210112111121211213112141121511216112171121811219112201122111222112231122411225112261122711228112291123011231112321123311234112351123611237112381123911240112411124211243112441124511246112471124811249112501125111252112531125411255112561125711258112591126011261112621126311264112651126611267112681126911270112711127211273112741127511276112771127811279112801128111282112831128411285112861128711288112891129011291112921129311294112951129611297
  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 variables 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 an 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
  162. into the object file corresponding to the LLVM module. They exist to
  163. allow inlining and other optimizations to take place given knowledge
  164. of the definition of the global, which is known to be somewhere
  165. outside the module. Globals with ``available_externally`` linkage
  166. are allowed to be discarded at will, and are otherwise the same as
  167. ``linkonce_odr``. This linkage type is only allowed on definitions,
  168. not declarations.
  169. ``linkonce``
  170. Globals with "``linkonce``" linkage are merged with other globals of
  171. the same name when linkage occurs. This can be used to implement
  172. some forms of inline functions, templates, or other code which must
  173. be generated in each translation unit that uses it, but where the
  174. body may be overridden with a more definitive definition later.
  175. Unreferenced ``linkonce`` globals are allowed to be discarded. Note
  176. that ``linkonce`` linkage does not actually allow the optimizer to
  177. inline the body of this function into callers because it doesn't
  178. know if this definition of the function is the definitive definition
  179. within the program or whether it will be overridden by a stronger
  180. definition. To enable inlining and other optimizations, use
  181. "``linkonce_odr``" linkage.
  182. ``weak``
  183. "``weak``" linkage has the same merging semantics as ``linkonce``
  184. linkage, except that unreferenced globals with ``weak`` linkage may
  185. not be discarded. This is used for globals that are declared "weak"
  186. in C source code.
  187. ``common``
  188. "``common``" linkage is most similar to "``weak``" linkage, but they
  189. are used for tentative definitions in C, such as "``int X;``" at
  190. global scope. Symbols with "``common``" linkage are merged in the
  191. same way as ``weak symbols``, and they may not be deleted if
  192. unreferenced. ``common`` symbols may not have an explicit section,
  193. must have a zero initializer, and may not be marked
  194. ':ref:`constant <globalvars>`'. Functions and aliases may not have
  195. common linkage.
  196. .. _linkage_appending:
  197. ``appending``
  198. "``appending``" linkage may only be applied to global variables of
  199. pointer to array type. When two global variables with appending
  200. linkage are linked together, the two global arrays are appended
  201. together. This is the LLVM, typesafe, equivalent of having the
  202. system linker append together "sections" with identical names when
  203. .o files are linked.
  204. ``extern_weak``
  205. The semantics of this linkage follow the ELF object file model: the
  206. symbol is weak until linked, if not linked, the symbol becomes null
  207. instead of being an undefined reference.
  208. ``linkonce_odr``, ``weak_odr``
  209. Some languages allow differing globals to be merged, such as two
  210. functions with different semantics. Other languages, such as
  211. ``C++``, ensure that only equivalent globals are ever merged (the
  212. "one definition rule" --- "ODR"). Such languages can use the
  213. ``linkonce_odr`` and ``weak_odr`` linkage types to indicate that the
  214. global will only be merged with equivalent globals. These linkage
  215. types are otherwise the same as their non-``odr`` versions.
  216. ``external``
  217. If none of the above identifiers are used, the global is externally
  218. visible, meaning that it participates in linkage and can be used to
  219. resolve external symbol references.
  220. It is illegal for a function *declaration* to have any linkage type
  221. other than ``external`` or ``extern_weak``.
  222. .. _callingconv:
  223. Calling Conventions
  224. -------------------
  225. LLVM :ref:`functions <functionstructure>`, :ref:`calls <i_call>` and
  226. :ref:`invokes <i_invoke>` can all have an optional calling convention
  227. specified for the call. The calling convention of any pair of dynamic
  228. caller/callee must match, or the behavior of the program is undefined.
  229. The following calling conventions are supported by LLVM, and more may be
  230. added in the future:
  231. "``ccc``" - The C calling convention
  232. This calling convention (the default if no other calling convention
  233. is specified) matches the target C calling conventions. This calling
  234. convention supports varargs function calls and tolerates some
  235. mismatch in the declared prototype and implemented declaration of
  236. the function (as does normal C).
  237. "``fastcc``" - The fast calling convention
  238. This calling convention attempts to make calls as fast as possible
  239. (e.g. by passing things in registers). This calling convention
  240. allows the target to use whatever tricks it wants to produce fast
  241. code for the target, without having to conform to an externally
  242. specified ABI (Application Binary Interface). `Tail calls can only
  243. be optimized when this, the GHC or the HiPE convention is
  244. used. <CodeGenerator.html#id80>`_ This calling convention does not
  245. support varargs and requires the prototype of all callees to exactly
  246. match the prototype of the function definition.
  247. "``coldcc``" - The cold calling convention
  248. This calling convention attempts to make code in the caller as
  249. efficient as possible under the assumption that the call is not
  250. commonly executed. As such, these calls often preserve all registers
  251. so that the call does not break any live ranges in the caller side.
  252. This calling convention does not support varargs and requires the
  253. prototype of all callees to exactly match the prototype of the
  254. function definition. Furthermore the inliner doesn't consider such function
  255. calls for inlining.
  256. "``cc 10``" - GHC convention
  257. This calling convention has been implemented specifically for use by
  258. the `Glasgow Haskell Compiler (GHC) <http://www.haskell.org/ghc>`_.
  259. It passes everything in registers, going to extremes to achieve this
  260. by disabling callee save registers. This calling convention should
  261. not be used lightly but only for specific situations such as an
  262. alternative to the *register pinning* performance technique often
  263. used when implementing functional programming languages. At the
  264. moment only X86 supports this convention and it has the following
  265. limitations:
  266. - On *X86-32* only supports up to 4 bit type parameters. No
  267. floating point types are supported.
  268. - On *X86-64* only supports up to 10 bit type parameters and 6
  269. floating point parameters.
  270. This calling convention supports `tail call
  271. optimization <CodeGenerator.html#id80>`_ but requires both the
  272. caller and callee are using it.
  273. "``cc 11``" - The HiPE calling convention
  274. This calling convention has been implemented specifically for use by
  275. the `High-Performance Erlang
  276. (HiPE) <http://www.it.uu.se/research/group/hipe/>`_ compiler, *the*
  277. native code compiler of the `Ericsson's Open Source Erlang/OTP
  278. system <http://www.erlang.org/download.shtml>`_. It uses more
  279. registers for argument passing than the ordinary C calling
  280. convention and defines no callee-saved registers. The calling
  281. convention properly supports `tail call
  282. optimization <CodeGenerator.html#id80>`_ but requires that both the
  283. caller and the callee use it. It uses a *register pinning*
  284. mechanism, similar to GHC's convention, for keeping frequently
  285. accessed runtime components pinned to specific hardware registers.
  286. At the moment only X86 supports this convention (both 32 and 64
  287. bit).
  288. "``webkit_jscc``" - WebKit's JavaScript calling convention
  289. This calling convention has been implemented for `WebKit FTL JIT
  290. <https://trac.webkit.org/wiki/FTLJIT>`_. It passes arguments on the
  291. stack right to left (as cdecl does), and returns a value in the
  292. platform's customary return register.
  293. "``anyregcc``" - Dynamic calling convention for code patching
  294. This is a special convention that supports patching an arbitrary code
  295. sequence in place of a call site. This convention forces the call
  296. arguments into registers but allows them to be dynamically
  297. allocated. This can currently only be used with calls to
  298. llvm.experimental.patchpoint because only this intrinsic records
  299. the location of its arguments in a side table. See :doc:`StackMaps`.
  300. "``preserve_mostcc``" - The `PreserveMost` calling convention
  301. This calling convention attempts to make the code in the caller as
  302. unintrusive as possible. This convention behaves identically to the `C`
  303. calling convention on how arguments and return values are passed, but it
  304. uses a different set of caller/callee-saved registers. This alleviates the
  305. burden of saving and recovering a large register set before and after the
  306. call in the caller. If the arguments are passed in callee-saved registers,
  307. then they will be preserved by the callee across the call. This doesn't
  308. apply for values returned in callee-saved registers.
  309. - On X86-64 the callee preserves all general purpose registers, except for
  310. R11. R11 can be used as a scratch register. Floating-point registers
  311. (XMMs/YMMs) are not preserved and need to be saved by the caller.
  312. The idea behind this convention is to support calls to runtime functions
  313. that have a hot path and a cold path. The hot path is usually a small piece
  314. of code that doesn't use many registers. The cold path might need to call out to
  315. another function and therefore only needs to preserve the caller-saved
  316. registers, which haven't already been saved by the caller. The
  317. `PreserveMost` calling convention is very similar to the `cold` calling
  318. convention in terms of caller/callee-saved registers, but they are used for
  319. different types of function calls. `coldcc` is for function calls that are
  320. rarely executed, whereas `preserve_mostcc` function calls are intended to be
  321. on the hot path and definitely executed a lot. Furthermore `preserve_mostcc`
  322. doesn't prevent the inliner from inlining the function call.
  323. This calling convention will be used by a future version of the ObjectiveC
  324. runtime and should therefore still be considered experimental at this time.
  325. Although this convention was created to optimize certain runtime calls to
  326. the ObjectiveC runtime, it is not limited to this runtime and might be used
  327. by other runtimes in the future too. The current implementation only
  328. supports X86-64, but the intention is to support more architectures in the
  329. future.
  330. "``preserve_allcc``" - The `PreserveAll` calling convention
  331. This calling convention attempts to make the code in the caller even less
  332. intrusive than the `PreserveMost` calling convention. This calling
  333. convention also behaves identical to the `C` calling convention on how
  334. arguments and return values are passed, but it uses a different set of
  335. caller/callee-saved registers. This removes the burden of saving and
  336. recovering a large register set before and after the call in the caller. If
  337. the arguments are passed in callee-saved registers, then they will be
  338. preserved by the callee across the call. This doesn't apply for values
  339. returned in callee-saved registers.
  340. - On X86-64 the callee preserves all general purpose registers, except for
  341. R11. R11 can be used as a scratch register. Furthermore it also preserves
  342. all floating-point registers (XMMs/YMMs).
  343. The idea behind this convention is to support calls to runtime functions
  344. that don't need to call out to any other functions.
  345. This calling convention, like the `PreserveMost` calling convention, will be
  346. used by a future version of the ObjectiveC runtime and should be considered
  347. experimental at this time.
  348. "``cc <n>``" - Numbered convention
  349. Any calling convention may be specified by number, allowing
  350. target-specific calling conventions to be used. Target specific
  351. calling conventions start at 64.
  352. More calling conventions can be added/defined on an as-needed basis, to
  353. support Pascal conventions or any other well-known target-independent
  354. convention.
  355. .. _visibilitystyles:
  356. Visibility Styles
  357. -----------------
  358. All Global Variables and Functions have one of the following visibility
  359. styles:
  360. "``default``" - Default style
  361. On targets that use the ELF object file format, default visibility
  362. means that the declaration is visible to other modules and, in
  363. shared libraries, means that the declared entity may be overridden.
  364. On Darwin, default visibility means that the declaration is visible
  365. to other modules. Default visibility corresponds to "external
  366. linkage" in the language.
  367. "``hidden``" - Hidden style
  368. Two declarations of an object with hidden visibility refer to the
  369. same object if they are in the same shared object. Usually, hidden
  370. visibility indicates that the symbol will not be placed into the
  371. dynamic symbol table, so no other module (executable or shared
  372. library) can reference it directly.
  373. "``protected``" - Protected style
  374. On ELF, protected visibility indicates that the symbol will be
  375. placed in the dynamic symbol table, but that references within the
  376. defining module will bind to the local symbol. That is, the symbol
  377. cannot be overridden by another module.
  378. A symbol with ``internal`` or ``private`` linkage must have ``default``
  379. visibility.
  380. .. _dllstorageclass:
  381. DLL Storage Classes
  382. -------------------
  383. All Global Variables, Functions and Aliases can have one of the following
  384. DLL storage class:
  385. ``dllimport``
  386. "``dllimport``" causes the compiler to reference a function or variable via
  387. a global pointer to a pointer that is set up by the DLL exporting the
  388. symbol. On Microsoft Windows targets, the pointer name is formed by
  389. combining ``__imp_`` and the function or variable name.
  390. ``dllexport``
  391. "``dllexport``" causes the compiler to provide a global pointer to a pointer
  392. in a DLL, so that it can be referenced with the ``dllimport`` attribute. On
  393. Microsoft Windows targets, the pointer name is formed by combining
  394. ``__imp_`` and the function or variable name. Since this storage class
  395. exists for defining a dll interface, the compiler, assembler and linker know
  396. it is externally referenced and must refrain from deleting the symbol.
  397. .. _tls_model:
  398. Thread Local Storage Models
  399. ---------------------------
  400. A variable may be defined as ``thread_local``, which means that it will
  401. not be shared by threads (each thread will have a separated copy of the
  402. variable). Not all targets support thread-local variables. Optionally, a
  403. TLS model may be specified:
  404. ``localdynamic``
  405. For variables that are only used within the current shared library.
  406. ``initialexec``
  407. For variables in modules that will not be loaded dynamically.
  408. ``localexec``
  409. For variables defined in the executable and only used within it.
  410. If no explicit model is given, the "general dynamic" model is used.
  411. The models correspond to the ELF TLS models; see `ELF Handling For
  412. Thread-Local Storage <http://people.redhat.com/drepper/tls.pdf>`_ for
  413. more information on under which circumstances the different models may
  414. be used. The target may choose a different TLS model if the specified
  415. model is not supported, or if a better choice of model can be made.
  416. A model can also be specified in a alias, but then it only governs how
  417. the alias is accessed. It will not have any effect in the aliasee.
  418. .. _namedtypes:
  419. Structure Types
  420. ---------------
  421. LLVM IR allows you to specify both "identified" and "literal" :ref:`structure
  422. types <t_struct>`. Literal types are uniqued structurally, but identified types
  423. are never uniqued. An :ref:`opaque structural type <t_opaque>` can also be used
  424. to forward declare a type that is not yet available.
  425. An example of a identified structure specification is:
  426. .. code-block:: llvm
  427. %mytype = type { %mytype*, i32 }
  428. Prior to the LLVM 3.0 release, identified types were structurally uniqued. Only
  429. literal types are uniqued in recent versions of LLVM.
  430. .. _globalvars:
  431. Global Variables
  432. ----------------
  433. Global variables define regions of memory allocated at compilation time
  434. instead of run-time.
  435. Global variable definitions must be initialized.
  436. Global variables in other translation units can also be declared, in which
  437. case they don't have an initializer.
  438. Either global variable definitions or declarations may have an explicit section
  439. to be placed in and may have an optional explicit alignment specified.
  440. A variable may be defined as a global ``constant``, which indicates that
  441. the contents of the variable will **never** be modified (enabling better
  442. optimization, allowing the global data to be placed in the read-only
  443. section of an executable, etc). Note that variables that need runtime
  444. initialization cannot be marked ``constant`` as there is a store to the
  445. variable.
  446. LLVM explicitly allows *declarations* of global variables to be marked
  447. constant, even if the final definition of the global is not. This
  448. capability can be used to enable slightly better optimization of the
  449. program, but requires the language definition to guarantee that
  450. optimizations based on the 'constantness' are valid for the translation
  451. units that do not include the definition.
  452. As SSA values, global variables define pointer values that are in scope
  453. (i.e. they dominate) all basic blocks in the program. Global variables
  454. always define a pointer to their "content" type because they describe a
  455. region of memory, and all memory objects in LLVM are accessed through
  456. pointers.
  457. Global variables can be marked with ``unnamed_addr`` which indicates
  458. that the address is not significant, only the content. Constants marked
  459. like this can be merged with other constants if they have the same
  460. initializer. Note that a constant with significant address *can* be
  461. merged with a ``unnamed_addr`` constant, the result being a constant
  462. whose address is significant.
  463. A global variable may be declared to reside in a target-specific
  464. numbered address space. For targets that support them, address spaces
  465. may affect how optimizations are performed and/or what target
  466. instructions are used to access the variable. The default address space
  467. is zero. The address space qualifier must precede any other attributes.
  468. LLVM allows an explicit section to be specified for globals. If the
  469. target supports it, it will emit globals to the section specified.
  470. Additionally, the global can placed in a comdat if the target has the necessary
  471. support.
  472. By default, global initializers are optimized by assuming that global
  473. variables defined within the module are not modified from their
  474. initial values before the start of the global initializer. This is
  475. true even for variables potentially accessible from outside the
  476. module, including those with external linkage or appearing in
  477. ``@llvm.used`` or dllexported variables. This assumption may be suppressed
  478. by marking the variable with ``externally_initialized``.
  479. An explicit alignment may be specified for a global, which must be a
  480. power of 2. If not present, or if the alignment is set to zero, the
  481. alignment of the global is set by the target to whatever it feels
  482. convenient. If an explicit alignment is specified, the global is forced
  483. to have exactly that alignment. Targets and optimizers are not allowed
  484. to over-align the global if the global has an assigned section. In this
  485. case, the extra alignment could be observable: for example, code could
  486. assume that the globals are densely packed in their section and try to
  487. iterate over them as an array, alignment padding would break this
  488. iteration. The maximum alignment is ``1 << 29``.
  489. Globals can also have a :ref:`DLL storage class <dllstorageclass>`.
  490. Variables and aliases can have a
  491. :ref:`Thread Local Storage Model <tls_model>`.
  492. Syntax::
  493. [@<GlobalVarName> =] [Linkage] [Visibility] [DLLStorageClass] [ThreadLocal]
  494. [unnamed_addr] [AddrSpace] [ExternallyInitialized]
  495. <global | constant> <Type> [<InitializerConstant>]
  496. [, section "name"] [, comdat [($name)]]
  497. [, align <Alignment>]
  498. For example, the following defines a global in a numbered address space
  499. with an initializer, section, and alignment:
  500. .. code-block:: llvm
  501. @G = addrspace(5) constant float 1.0, section "foo", align 4
  502. The following example just declares a global variable
  503. .. code-block:: llvm
  504. @G = external global i32
  505. The following example defines a thread-local global with the
  506. ``initialexec`` TLS model:
  507. .. code-block:: llvm
  508. @G = thread_local(initialexec) global i32 0, align 4
  509. .. _functionstructure:
  510. Functions
  511. ---------
  512. LLVM function definitions consist of the "``define``" keyword, an
  513. optional :ref:`linkage type <linkage>`, an optional :ref:`visibility
  514. style <visibility>`, an optional :ref:`DLL storage class <dllstorageclass>`,
  515. an optional :ref:`calling convention <callingconv>`,
  516. an optional ``unnamed_addr`` attribute, a return type, an optional
  517. :ref:`parameter attribute <paramattrs>` for the return type, a function
  518. name, a (possibly empty) argument list (each with optional :ref:`parameter
  519. attributes <paramattrs>`), optional :ref:`function attributes <fnattrs>`,
  520. an optional section, an optional alignment,
  521. an optional :ref:`comdat <langref_comdats>`,
  522. an optional :ref:`garbage collector name <gc>`, an optional :ref:`prefix <prefixdata>`,
  523. an optional :ref:`prologue <prologuedata>`,
  524. an optional :ref:`personality <personalityfn>`,
  525. an opening curly brace, a list of basic blocks, and a closing curly brace.
  526. LLVM function declarations consist of the "``declare``" keyword, an
  527. optional :ref:`linkage type <linkage>`, an optional :ref:`visibility
  528. style <visibility>`, an optional :ref:`DLL storage class <dllstorageclass>`,
  529. an optional :ref:`calling convention <callingconv>`,
  530. an optional ``unnamed_addr`` attribute, a return type, an optional
  531. :ref:`parameter attribute <paramattrs>` for the return type, a function
  532. name, a possibly empty list of arguments, an optional alignment, an optional
  533. :ref:`garbage collector name <gc>`, an optional :ref:`prefix <prefixdata>`,
  534. and an optional :ref:`prologue <prologuedata>`.
  535. A function definition contains a list of basic blocks, forming the CFG (Control
  536. Flow Graph) for the function. Each basic block may optionally start with a label
  537. (giving the basic block a symbol table entry), contains a list of instructions,
  538. and ends with a :ref:`terminator <terminators>` instruction (such as a branch or
  539. function return). If an explicit label is not provided, a block is assigned an
  540. implicit numbered label, using the next value from the same counter as used for
  541. unnamed temporaries (:ref:`see above<identifiers>`). For example, if a function
  542. entry block does not have an explicit label, it will be assigned label "%0",
  543. then the first unnamed temporary in that block will be "%1", etc.
  544. The first basic block in a function is special in two ways: it is
  545. immediately executed on entrance to the function, and it is not allowed
  546. to have predecessor basic blocks (i.e. there can not be any branches to
  547. the entry block of a function). Because the block can have no
  548. predecessors, it also cannot have any :ref:`PHI nodes <i_phi>`.
  549. LLVM allows an explicit section to be specified for functions. If the
  550. target supports it, it will emit functions to the section specified.
  551. Additionally, the function can be placed in a COMDAT.
  552. An explicit alignment may be specified for a function. If not present,
  553. or if the alignment is set to zero, the alignment of the function is set
  554. by the target to whatever it feels convenient. If an explicit alignment
  555. is specified, the function is forced to have at least that much
  556. alignment. All alignments must be a power of 2.
  557. If the ``unnamed_addr`` attribute is given, the address is known to not
  558. be significant and two identical functions can be merged.
  559. Syntax::
  560. define [linkage] [visibility] [DLLStorageClass]
  561. [cconv] [ret attrs]
  562. <ResultType> @<FunctionName> ([argument list])
  563. [unnamed_addr] [fn Attrs] [section "name"] [comdat [($name)]]
  564. [align N] [gc] [prefix Constant] [prologue Constant]
  565. [personality Constant] { ... }
  566. The argument list is a comma seperated sequence of arguments where each
  567. argument is of the following form
  568. Syntax::
  569. <type> [parameter Attrs] [name]
  570. .. _langref_aliases:
  571. Aliases
  572. -------
  573. Aliases, unlike function or variables, don't create any new data. They
  574. are just a new symbol and metadata for an existing position.
  575. Aliases have a name and an aliasee that is either a global value or a
  576. constant expression.
  577. Aliases may have an optional :ref:`linkage type <linkage>`, an optional
  578. :ref:`visibility style <visibility>`, an optional :ref:`DLL storage class
  579. <dllstorageclass>` and an optional :ref:`tls model <tls_model>`.
  580. Syntax::
  581. @<Name> = [Linkage] [Visibility] [DLLStorageClass] [ThreadLocal] [unnamed_addr] alias <AliaseeTy> @<Aliasee>
  582. The linkage must be one of ``private``, ``internal``, ``linkonce``, ``weak``,
  583. ``linkonce_odr``, ``weak_odr``, ``external``. Note that some system linkers
  584. might not correctly handle dropping a weak symbol that is aliased.
  585. Aliases that are not ``unnamed_addr`` are guaranteed to have the same address as
  586. the aliasee expression. ``unnamed_addr`` ones are only guaranteed to point
  587. to the same content.
  588. Since aliases are only a second name, some restrictions apply, of which
  589. some can only be checked when producing an object file:
  590. * The expression defining the aliasee must be computable at assembly
  591. time. Since it is just a name, no relocations can be used.
  592. * No alias in the expression can be weak as the possibility of the
  593. intermediate alias being overridden cannot be represented in an
  594. object file.
  595. * No global value in the expression can be a declaration, since that
  596. would require a relocation, which is not possible.
  597. .. _langref_comdats:
  598. Comdats
  599. -------
  600. Comdat IR provides access to COFF and ELF object file COMDAT functionality.
  601. Comdats have a name which represents the COMDAT key. All global objects that
  602. specify this key will only end up in the final object file if the linker chooses
  603. that key over some other key. Aliases are placed in the same COMDAT that their
  604. aliasee computes to, if any.
  605. Comdats have a selection kind to provide input on how the linker should
  606. choose between keys in two different object files.
  607. Syntax::
  608. $<Name> = comdat SelectionKind
  609. The selection kind must be one of the following:
  610. ``any``
  611. The linker may choose any COMDAT key, the choice is arbitrary.
  612. ``exactmatch``
  613. The linker may choose any COMDAT key but the sections must contain the
  614. same data.
  615. ``largest``
  616. The linker will choose the section containing the largest COMDAT key.
  617. ``noduplicates``
  618. The linker requires that only section with this COMDAT key exist.
  619. ``samesize``
  620. The linker may choose any COMDAT key but the sections must contain the
  621. same amount of data.
  622. Note that the Mach-O platform doesn't support COMDATs and ELF only supports
  623. ``any`` as a selection kind.
  624. Here is an example of a COMDAT group where a function will only be selected if
  625. the COMDAT key's section is the largest:
  626. .. code-block:: llvm
  627. $foo = comdat largest
  628. @foo = global i32 2, comdat($foo)
  629. define void @bar() comdat($foo) {
  630. ret void
  631. }
  632. As a syntactic sugar the ``$name`` can be omitted if the name is the same as
  633. the global name:
  634. .. code-block:: llvm
  635. $foo = comdat any
  636. @foo = global i32 2, comdat
  637. In a COFF object file, this will create a COMDAT section with selection kind
  638. ``IMAGE_COMDAT_SELECT_LARGEST`` containing the contents of the ``@foo`` symbol
  639. and another COMDAT section with selection kind
  640. ``IMAGE_COMDAT_SELECT_ASSOCIATIVE`` which is associated with the first COMDAT
  641. section and contains the contents of the ``@bar`` symbol.
  642. There are some restrictions on the properties of the global object.
  643. It, or an alias to it, must have the same name as the COMDAT group when
  644. targeting COFF.
  645. The contents and size of this object may be used during link-time to determine
  646. which COMDAT groups get selected depending on the selection kind.
  647. Because the name of the object must match the name of the COMDAT group, the
  648. linkage of the global object must not be local; local symbols can get renamed
  649. if a collision occurs in the symbol table.
  650. The combined use of COMDATS and section attributes may yield surprising results.
  651. For example:
  652. .. code-block:: llvm
  653. $foo = comdat any
  654. $bar = comdat any
  655. @g1 = global i32 42, section "sec", comdat($foo)
  656. @g2 = global i32 42, section "sec", comdat($bar)
  657. From the object file perspective, this requires the creation of two sections
  658. with the same name. This is necessary because both globals belong to different
  659. COMDAT groups and COMDATs, at the object file level, are represented by
  660. sections.
  661. Note that certain IR constructs like global variables and functions may
  662. create COMDATs in the object file in addition to any which are specified using
  663. COMDAT IR. This arises when the code generator is configured to emit globals
  664. in individual sections (e.g. when `-data-sections` or `-function-sections`
  665. is supplied to `llc`).
  666. .. _namedmetadatastructure:
  667. Named Metadata
  668. --------------
  669. Named metadata is a collection of metadata. :ref:`Metadata
  670. nodes <metadata>` (but not metadata strings) are the only valid
  671. operands for a named metadata.
  672. #. Named metadata are represented as a string of characters with the
  673. metadata prefix. The rules for metadata names are the same as for
  674. identifiers, but quoted names are not allowed. ``"\xx"`` type escapes
  675. are still valid, which allows any character to be part of a name.
  676. Syntax::
  677. ; Some unnamed metadata nodes, which are referenced by the named metadata.
  678. !0 = !{!"zero"}
  679. !1 = !{!"one"}
  680. !2 = !{!"two"}
  681. ; A named metadata.
  682. !name = !{!0, !1, !2}
  683. .. _paramattrs:
  684. Parameter Attributes
  685. --------------------
  686. The return type and each parameter of a function type may have a set of
  687. *parameter attributes* associated with them. Parameter attributes are
  688. used to communicate additional information about the result or
  689. parameters of a function. Parameter attributes are considered to be part
  690. of the function, not of the function type, so functions with different
  691. parameter attributes can have the same function type.
  692. Parameter attributes are simple keywords that follow the type specified.
  693. If multiple parameter attributes are needed, they are space separated.
  694. For example:
  695. .. code-block:: llvm
  696. declare i32 @printf(i8* noalias nocapture, ...)
  697. declare i32 @atoi(i8 zeroext)
  698. declare signext i8 @returns_signed_char()
  699. Note that any attributes for the function result (``nounwind``,
  700. ``readonly``) come immediately after the argument list.
  701. Currently, only the following parameter attributes are defined:
  702. ``zeroext``
  703. This indicates to the code generator that the parameter or return
  704. value should be zero-extended to the extent required by the target's
  705. ABI (which is usually 32-bits, but is 8-bits for a i1 on x86-64) by
  706. the caller (for a parameter) or the callee (for a return value).
  707. ``signext``
  708. This indicates to the code generator that the parameter or return
  709. value should be sign-extended to the extent required by the target's
  710. ABI (which is usually 32-bits) by the caller (for a parameter) or
  711. the callee (for a return value).
  712. ``inreg``
  713. This indicates that this parameter or return value should be treated
  714. in a special target-dependent fashion during while emitting code for
  715. a function call or return (usually, by putting it in a register as
  716. opposed to memory, though some targets use it to distinguish between
  717. two different kinds of registers). Use of this attribute is
  718. target-specific.
  719. ``byval``
  720. This indicates that the pointer parameter should really be passed by
  721. value to the function. The attribute implies that a hidden copy of
  722. the pointee is made between the caller and the callee, so the callee
  723. is unable to modify the value in the caller. This attribute is only
  724. valid on LLVM pointer arguments. It is generally used to pass
  725. structs and arrays by value, but is also valid on pointers to
  726. scalars. The copy is considered to belong to the caller not the
  727. callee (for example, ``readonly`` functions should not write to
  728. ``byval`` parameters). This is not a valid attribute for return
  729. values.
  730. The byval attribute also supports specifying an alignment with the
  731. align attribute. It indicates the alignment of the stack slot to
  732. form and the known alignment of the pointer specified to the call
  733. site. If the alignment is not specified, then the code generator
  734. makes a target-specific assumption.
  735. .. _attr_inalloca:
  736. ``inalloca``
  737. The ``inalloca`` argument attribute allows the caller to take the
  738. address of outgoing stack arguments. An ``inalloca`` argument must
  739. be a pointer to stack memory produced by an ``alloca`` instruction.
  740. The alloca, or argument allocation, must also be tagged with the
  741. inalloca keyword. Only the last argument may have the ``inalloca``
  742. attribute, and that argument is guaranteed to be passed in memory.
  743. An argument allocation may be used by a call at most once because
  744. the call may deallocate it. The ``inalloca`` attribute cannot be
  745. used in conjunction with other attributes that affect argument
  746. storage, like ``inreg``, ``nest``, ``sret``, or ``byval``. The
  747. ``inalloca`` attribute also disables LLVM's implicit lowering of
  748. large aggregate return values, which means that frontend authors
  749. must lower them with ``sret`` pointers.
  750. When the call site is reached, the argument allocation must have
  751. been the most recent stack allocation that is still live, or the
  752. results are undefined. It is possible to allocate additional stack
  753. space after an argument allocation and before its call site, but it
  754. must be cleared off with :ref:`llvm.stackrestore
  755. <int_stackrestore>`.
  756. See :doc:`InAlloca` for more information on how to use this
  757. attribute.
  758. ``sret``
  759. This indicates that the pointer parameter specifies the address of a
  760. structure that is the return value of the function in the source
  761. program. This pointer must be guaranteed by the caller to be valid:
  762. loads and stores to the structure may be assumed by the callee
  763. not to trap and to be properly aligned. This may only be applied to
  764. the first parameter. This is not a valid attribute for return
  765. values.
  766. ``align <n>``
  767. This indicates that the pointer value may be assumed by the optimizer to
  768. have the specified alignment.
  769. Note that this attribute has additional semantics when combined with the
  770. ``byval`` attribute.
  771. .. _noalias:
  772. ``noalias``
  773. This indicates that objects accessed via pointer values
  774. :ref:`based <pointeraliasing>` on the argument or return value are not also
  775. accessed, during the execution of the function, via pointer values not
  776. *based* on the argument or return value. The attribute on a return value
  777. also has additional semantics described below. The caller shares the
  778. responsibility with the callee for ensuring that these requirements are met.
  779. For further details, please see the discussion of the NoAlias response in
  780. :ref:`alias analysis <Must, May, or No>`.
  781. Note that this definition of ``noalias`` is intentionally similar
  782. to the definition of ``restrict`` in C99 for function arguments.
  783. For function return values, C99's ``restrict`` is not meaningful,
  784. while LLVM's ``noalias`` is. Furthermore, the semantics of the ``noalias``
  785. attribute on return values are stronger than the semantics of the attribute
  786. when used on function arguments. On function return values, the ``noalias``
  787. attribute indicates that the function acts like a system memory allocation
  788. function, returning a pointer to allocated storage disjoint from the
  789. storage for any other object accessible to the caller.
  790. ``nocapture``
  791. This indicates that the callee does not make any copies of the
  792. pointer that outlive the callee itself. This is not a valid
  793. attribute for return values.
  794. .. _nest:
  795. ``nest``
  796. This indicates that the pointer parameter can be excised using the
  797. :ref:`trampoline intrinsics <int_trampoline>`. This is not a valid
  798. attribute for return values and can only be applied to one parameter.
  799. ``returned``
  800. This indicates that the function always returns the argument as its return
  801. value. This is an optimization hint to the code generator when generating
  802. the caller, allowing tail call optimization and omission of register saves
  803. and restores in some cases; it is not checked or enforced when generating
  804. the callee. The parameter and the function return type must be valid
  805. operands for the :ref:`bitcast instruction <i_bitcast>`. This is not a
  806. valid attribute for return values and can only be applied to one parameter.
  807. ``nonnull``
  808. This indicates that the parameter or return pointer is not null. This
  809. attribute may only be applied to pointer typed parameters. This is not
  810. checked or enforced by LLVM, the caller must ensure that the pointer
  811. passed in is non-null, or the callee must ensure that the returned pointer
  812. is non-null.
  813. ``dereferenceable(<n>)``
  814. This indicates that the parameter or return pointer is dereferenceable. This
  815. attribute may only be applied to pointer typed parameters. A pointer that
  816. is dereferenceable can be loaded from speculatively without a risk of
  817. trapping. The number of bytes known to be dereferenceable must be provided
  818. in parentheses. It is legal for the number of bytes to be less than the
  819. size of the pointee type. The ``nonnull`` attribute does not imply
  820. dereferenceability (consider a pointer to one element past the end of an
  821. array), however ``dereferenceable(<n>)`` does imply ``nonnull`` in
  822. ``addrspace(0)`` (which is the default address space).
  823. ``dereferenceable_or_null(<n>)``
  824. This indicates that the parameter or return value isn't both
  825. non-null and non-dereferenceable (up to ``<n>`` bytes) at the same
  826. time. All non-null pointers tagged with
  827. ``dereferenceable_or_null(<n>)`` are ``dereferenceable(<n>)``.
  828. For address space 0 ``dereferenceable_or_null(<n>)`` implies that
  829. a pointer is exactly one of ``dereferenceable(<n>)`` or ``null``,
  830. and in other address spaces ``dereferenceable_or_null(<n>)``
  831. implies that a pointer is at least one of ``dereferenceable(<n>)``
  832. or ``null`` (i.e. it may be both ``null`` and
  833. ``dereferenceable(<n>)``). This attribute may only be applied to
  834. pointer typed parameters.
  835. .. _gc:
  836. Garbage Collector Strategy Names
  837. --------------------------------
  838. Each function may specify a garbage collector strategy name, which is simply a
  839. string:
  840. .. code-block:: llvm
  841. define void @f() gc "name" { ... }
  842. The supported values of *name* includes those :ref:`built in to LLVM
  843. <builtin-gc-strategies>` and any provided by loaded plugins. Specifying a GC
  844. strategy will cause the compiler to alter its output in order to support the
  845. named garbage collection algorithm. Note that LLVM itself does not contain a
  846. garbage collector, this functionality is restricted to generating machine code
  847. which can interoperate with a collector provided externally.
  848. .. _prefixdata:
  849. Prefix Data
  850. -----------
  851. Prefix data is data associated with a function which the code
  852. generator will emit immediately before the function's entrypoint.
  853. The purpose of this feature is to allow frontends to associate
  854. language-specific runtime metadata with specific functions and make it
  855. available through the function pointer while still allowing the
  856. function pointer to be called.
  857. To access the data for a given function, a program may bitcast the
  858. function pointer to a pointer to the constant's type and dereference
  859. index -1. This implies that the IR symbol points just past the end of
  860. the prefix data. For instance, take the example of a function annotated
  861. with a single ``i32``,
  862. .. code-block:: llvm
  863. define void @f() prefix i32 123 { ... }
  864. The prefix data can be referenced as,
  865. .. code-block:: llvm
  866. %0 = bitcast void* () @f to i32*
  867. %a = getelementptr inbounds i32, i32* %0, i32 -1
  868. %b = load i32, i32* %a
  869. Prefix data is laid out as if it were an initializer for a global variable
  870. of the prefix data's type. The function will be placed such that the
  871. beginning of the prefix data is aligned. This means that if the size
  872. of the prefix data is not a multiple of the alignment size, the
  873. function's entrypoint will not be aligned. If alignment of the
  874. function's entrypoint is desired, padding must be added to the prefix
  875. data.
  876. A function may have prefix data but no body. This has similar semantics
  877. to the ``available_externally`` linkage in that the data may be used by the
  878. optimizers but will not be emitted in the object file.
  879. .. _prologuedata:
  880. Prologue Data
  881. -------------
  882. The ``prologue`` attribute allows arbitrary code (encoded as bytes) to
  883. be inserted prior to the function body. This can be used for enabling
  884. function hot-patching and instrumentation.
  885. To maintain the semantics of ordinary function calls, the prologue data must
  886. have a particular format. Specifically, it must begin with a sequence of
  887. bytes which decode to a sequence of machine instructions, valid for the
  888. module's target, which transfer control to the point immediately succeeding
  889. the prologue data, without performing any other visible action. This allows
  890. the inliner and other passes to reason about the semantics of the function
  891. definition without needing to reason about the prologue data. Obviously this
  892. makes the format of the prologue data highly target dependent.
  893. A trivial example of valid prologue data for the x86 architecture is ``i8 144``,
  894. which encodes the ``nop`` instruction:
  895. .. code-block:: llvm
  896. define void @f() prologue i8 144 { ... }
  897. Generally prologue data can be formed by encoding a relative branch instruction
  898. which skips the metadata, as in this example of valid prologue data for the
  899. x86_64 architecture, where the first two bytes encode ``jmp .+10``:
  900. .. code-block:: llvm
  901. %0 = type <{ i8, i8, i8* }>
  902. define void @f() prologue %0 <{ i8 235, i8 8, i8* @md}> { ... }
  903. A function may have prologue data but no body. This has similar semantics
  904. to the ``available_externally`` linkage in that the data may be used by the
  905. optimizers but will not be emitted in the object file.
  906. .. _personalityfn:
  907. Personality Function
  908. --------------------
  909. The ``personality`` attribute permits functions to specify what function
  910. to use for exception handling.
  911. .. _attrgrp:
  912. Attribute Groups
  913. ----------------
  914. Attribute groups are groups of attributes that are referenced by objects within
  915. the IR. They are important for keeping ``.ll`` files readable, because a lot of
  916. functions will use the same set of attributes. In the degenerative case of a
  917. ``.ll`` file that corresponds to a single ``.c`` file, the single attribute
  918. group will capture the important command line flags used to build that file.
  919. An attribute group is a module-level object. To use an attribute group, an
  920. object references the attribute group's ID (e.g. ``#37``). An object may refer
  921. to more than one attribute group. In that situation, the attributes from the
  922. different groups are merged.
  923. Here is an example of attribute groups for a function that should always be
  924. inlined, has a stack alignment of 4, and which shouldn't use SSE instructions:
  925. .. code-block:: llvm
  926. ; Target-independent attributes:
  927. attributes #0 = { alwaysinline alignstack=4 }
  928. ; Target-dependent attributes:
  929. attributes #1 = { "no-sse" }
  930. ; Function @f has attributes: alwaysinline, alignstack=4, and "no-sse".
  931. define void @f() #0 #1 { ... }
  932. .. _fnattrs:
  933. Function Attributes
  934. -------------------
  935. Function attributes are set to communicate additional information about
  936. a function. Function attributes are considered to be part of the
  937. function, not of the function type, so functions with different function
  938. attributes can have the same function type.
  939. Function attributes are simple keywords that follow the type specified.
  940. If multiple attributes are needed, they are space separated. For
  941. example:
  942. .. code-block:: llvm
  943. define void @f() noinline { ... }
  944. define void @f() alwaysinline { ... }
  945. define void @f() alwaysinline optsize { ... }
  946. define void @f() optsize { ... }
  947. ``alignstack(<n>)``
  948. This attribute indicates that, when emitting the prologue and
  949. epilogue, the backend should forcibly align the stack pointer.
  950. Specify the desired alignment, which must be a power of two, in
  951. parentheses.
  952. ``alwaysinline``
  953. This attribute indicates that the inliner should attempt to inline
  954. this function into callers whenever possible, ignoring any active
  955. inlining size threshold for this caller.
  956. ``builtin``
  957. This indicates that the callee function at a call site should be
  958. recognized as a built-in function, even though the function's declaration
  959. uses the ``nobuiltin`` attribute. This is only valid at call sites for
  960. direct calls to functions that are declared with the ``nobuiltin``
  961. attribute.
  962. ``cold``
  963. This attribute indicates that this function is rarely called. When
  964. computing edge weights, basic blocks post-dominated by a cold
  965. function call are also considered to be cold; and, thus, given low
  966. weight.
  967. ``convergent``
  968. This attribute indicates that the callee is dependent on a convergent
  969. thread execution pattern under certain parallel execution models.
  970. Transformations that are execution model agnostic may only move or
  971. tranform this call if the final location is control equivalent to its
  972. original position in the program, where control equivalence is defined as
  973. A dominates B and B post-dominates A, or vice versa.
  974. ``inlinehint``
  975. This attribute indicates that the source code contained a hint that
  976. inlining this function is desirable (such as the "inline" keyword in
  977. C/C++). It is just a hint; it imposes no requirements on the
  978. inliner.
  979. ``jumptable``
  980. This attribute indicates that the function should be added to a
  981. jump-instruction table at code-generation time, and that all address-taken
  982. references to this function should be replaced with a reference to the
  983. appropriate jump-instruction-table function pointer. Note that this creates
  984. a new pointer for the original function, which means that code that depends
  985. on function-pointer identity can break. So, any function annotated with
  986. ``jumptable`` must also be ``unnamed_addr``.
  987. ``minsize``
  988. This attribute suggests that optimization passes and code generator
  989. passes make choices that keep the code size of this function as small
  990. as possible and perform optimizations that may sacrifice runtime
  991. performance in order to minimize the size of the generated code.
  992. ``naked``
  993. This attribute disables prologue / epilogue emission for the
  994. function. This can have very system-specific consequences.
  995. ``nobuiltin``
  996. This indicates that the callee function at a call site is not recognized as
  997. a built-in function. LLVM will retain the original call and not replace it
  998. with equivalent code based on the semantics of the built-in function, unless
  999. the call site uses the ``builtin`` attribute. This is valid at call sites
  1000. and on function declarations and definitions.
  1001. ``noduplicate``
  1002. This attribute indicates that calls to the function cannot be
  1003. duplicated. A call to a ``noduplicate`` function may be moved
  1004. within its parent function, but may not be duplicated within
  1005. its parent function.
  1006. A function containing a ``noduplicate`` call may still
  1007. be an inlining candidate, provided that the call is not
  1008. duplicated by inlining. That implies that the function has
  1009. internal linkage and only has one call site, so the original
  1010. call is dead after inlining.
  1011. ``noimplicitfloat``
  1012. This attributes disables implicit floating point instructions.
  1013. ``noinline``
  1014. This attribute indicates that the inliner should never inline this
  1015. function in any situation. This attribute may not be used together
  1016. with the ``alwaysinline`` attribute.
  1017. ``nonlazybind``
  1018. This attribute suppresses lazy symbol binding for the function. This
  1019. may make calls to the function faster, at the cost of extra program
  1020. startup time if the function is not called during program startup.
  1021. ``noredzone``
  1022. This attribute indicates that the code generator should not use a
  1023. red zone, even if the target-specific ABI normally permits it.
  1024. ``noreturn``
  1025. This function attribute indicates that the function never returns
  1026. normally. This produces undefined behavior at runtime if the
  1027. function ever does dynamically return.
  1028. ``nounwind``
  1029. This function attribute indicates that the function never raises an
  1030. exception. If the function does raise an exception, its runtime
  1031. behavior is undefined. However, functions marked nounwind may still
  1032. trap or generate asynchronous exceptions. Exception handling schemes
  1033. that are recognized by LLVM to handle asynchronous exceptions, such
  1034. as SEH, will still provide their implementation defined semantics.
  1035. ``optnone``
  1036. This function attribute indicates that the function is not optimized
  1037. by any optimization or code generator passes with the
  1038. exception of interprocedural optimization passes.
  1039. This attribute cannot be used together with the ``alwaysinline``
  1040. attribute; this attribute is also incompatible
  1041. with the ``minsize`` attribute and the ``optsize`` attribute.
  1042. This attribute requires the ``noinline`` attribute to be specified on
  1043. the function as well, so the function is never inlined into any caller.
  1044. Only functions with the ``alwaysinline`` attribute are valid
  1045. candidates for inlining into the body of this function.
  1046. ``optsize``
  1047. This attribute suggests that optimization passes and code generator
  1048. passes make choices that keep the code size of this function low,
  1049. and otherwise do optimizations specifically to reduce code size as
  1050. long as they do not significantly impact runtime performance.
  1051. ``readnone``
  1052. On a function, this attribute indicates that the function computes its
  1053. result (or decides to unwind an exception) based strictly on its arguments,
  1054. without dereferencing any pointer arguments or otherwise accessing
  1055. any mutable state (e.g. memory, control registers, etc) visible to
  1056. caller functions. It does not write through any pointer arguments
  1057. (including ``byval`` arguments) and never changes any state visible
  1058. to callers. This means that it cannot unwind exceptions by calling
  1059. the ``C++`` exception throwing methods.
  1060. On an argument, this attribute indicates that the function does not
  1061. dereference that pointer argument, even though it may read or write the
  1062. memory that the pointer points to if accessed through other pointers.
  1063. ``readonly``
  1064. On a function, this attribute indicates that the function does not write
  1065. through any pointer arguments (including ``byval`` arguments) or otherwise
  1066. modify any state (e.g. memory, control registers, etc) visible to
  1067. caller functions. It may dereference pointer arguments and read
  1068. state that may be set in the caller. A readonly function always
  1069. returns the same value (or unwinds an exception identically) when
  1070. called with the same set of arguments and global state. It cannot
  1071. unwind an exception by calling the ``C++`` exception throwing
  1072. methods.
  1073. On an argument, this attribute indicates that the function does not write
  1074. through this pointer argument, even though it may write to the memory that
  1075. the pointer points to.
  1076. ``argmemonly``
  1077. This attribute indicates that the only memory accesses inside function are
  1078. loads and stores from objects pointed to by its pointer-typed arguments,
  1079. with arbitrary offsets. Or in other words, all memory operations in the
  1080. function can refer to memory only using pointers based on its function
  1081. arguments.
  1082. Note that ``argmemonly`` can be used together with ``readonly`` attribute
  1083. in order to specify that function reads only from its arguments.
  1084. ``returns_twice``
  1085. This attribute indicates that this function can return twice. The C
  1086. ``setjmp`` is an example of such a function. The compiler disables
  1087. some optimizations (like tail calls) in the caller of these
  1088. functions.
  1089. ``safestack``
  1090. This attribute indicates that
  1091. `SafeStack <http://clang.llvm.org/docs/SafeStack.html>`_
  1092. protection is enabled for this function.
  1093. If a function that has a ``safestack`` attribute is inlined into a
  1094. function that doesn't have a ``safestack`` attribute or which has an
  1095. ``ssp``, ``sspstrong`` or ``sspreq`` attribute, then the resulting
  1096. function will have a ``safestack`` attribute.
  1097. ``sanitize_address``
  1098. This attribute indicates that AddressSanitizer checks
  1099. (dynamic address safety analysis) are enabled for this function.
  1100. ``sanitize_memory``
  1101. This attribute indicates that MemorySanitizer checks (dynamic detection
  1102. of accesses to uninitialized memory) are enabled for this function.
  1103. ``sanitize_thread``
  1104. This attribute indicates that ThreadSanitizer checks
  1105. (dynamic thread safety analysis) are enabled for this function.
  1106. ``ssp``
  1107. This attribute indicates that the function should emit a stack
  1108. smashing protector. It is in the form of a "canary" --- a random value
  1109. placed on the stack before the local variables that's checked upon
  1110. return from the function to see if it has been overwritten. A
  1111. heuristic is used to determine if a function needs stack protectors
  1112. or not. The heuristic used will enable protectors for functions with:
  1113. - Character arrays larger than ``ssp-buffer-size`` (default 8).
  1114. - Aggregates containing character arrays larger than ``ssp-buffer-size``.
  1115. - Calls to alloca() with variable sizes or constant sizes greater than
  1116. ``ssp-buffer-size``.
  1117. Variables that are identified as requiring a protector will be arranged
  1118. on the stack such that they are adjacent to the stack protector guard.
  1119. If a function that has an ``ssp`` attribute is inlined into a
  1120. function that doesn't have an ``ssp`` attribute, then the resulting
  1121. function will have an ``ssp`` attribute.
  1122. ``sspreq``
  1123. This attribute indicates that the function should *always* emit a
  1124. stack smashing protector. This overrides the ``ssp`` function
  1125. attribute.
  1126. Variables that are identified as requiring a protector will be arranged
  1127. on the stack such that they are adjacent to the stack protector guard.
  1128. The specific layout rules are:
  1129. #. Large arrays and structures containing large arrays
  1130. (``>= ssp-buffer-size``) are closest to the stack protector.
  1131. #. Small arrays and structures containing small arrays
  1132. (``< ssp-buffer-size``) are 2nd closest to the protector.
  1133. #. Variables that have had their address taken are 3rd closest to the
  1134. protector.
  1135. If a function that has an ``sspreq`` attribute is inlined into a
  1136. function that doesn't have an ``sspreq`` attribute or which has an
  1137. ``ssp`` or ``sspstrong`` attribute, then the resulting function will have
  1138. an ``sspreq`` attribute.
  1139. ``sspstrong``
  1140. This attribute indicates that the function should emit a stack smashing
  1141. protector. This attribute causes a strong heuristic to be used when
  1142. determining if a function needs stack protectors. The strong heuristic
  1143. will enable protectors for functions with:
  1144. - Arrays of any size and type
  1145. - Aggregates containing an array of any size and type.
  1146. - Calls to alloca().
  1147. - Local variables that have had their address taken.
  1148. Variables that are identified as requiring a protector will be arranged
  1149. on the stack such that they are adjacent to the stack protector guard.
  1150. The specific layout rules are:
  1151. #. Large arrays and structures containing large arrays
  1152. (``>= ssp-buffer-size``) are closest to the stack protector.
  1153. #. Small arrays and structures containing small arrays
  1154. (``< ssp-buffer-size``) are 2nd closest to the protector.
  1155. #. Variables that have had their address taken are 3rd closest to the
  1156. protector.
  1157. This overrides the ``ssp`` function attribute.
  1158. If a function that has an ``sspstrong`` attribute is inlined into a
  1159. function that doesn't have an ``sspstrong`` attribute, then the
  1160. resulting function will have an ``sspstrong`` attribute.
  1161. ``"thunk"``
  1162. This attribute indicates that the function will delegate to some other
  1163. function with a tail call. The prototype of a thunk should not be used for
  1164. optimization purposes. The caller is expected to cast the thunk prototype to
  1165. match the thunk target prototype.
  1166. ``uwtable``
  1167. This attribute indicates that the ABI being targeted requires that
  1168. an unwind table entry be produce for this function even if we can
  1169. show that no exceptions passes by it. This is normally the case for
  1170. the ELF x86-64 abi, but it can be disabled for some compilation
  1171. units.
  1172. .. _moduleasm:
  1173. Module-Level Inline Assembly
  1174. ----------------------------
  1175. Modules may contain "module-level inline asm" blocks, which corresponds
  1176. to the GCC "file scope inline asm" blocks. These blocks are internally
  1177. concatenated by LLVM and treated as a single unit, but may be separated
  1178. in the ``.ll`` file if desired. The syntax is very simple:
  1179. .. code-block:: llvm
  1180. module asm "inline asm code goes here"
  1181. module asm "more can go here"
  1182. The strings can contain any character by escaping non-printable
  1183. characters. The escape sequence used is simply "\\xx" where "xx" is the
  1184. two digit hex code for the number.
  1185. Note that the assembly string *must* be parseable by LLVM's integrated assembler
  1186. (unless it is disabled), even when emitting a ``.s`` file.
  1187. .. _langref_datalayout:
  1188. Data Layout
  1189. -----------
  1190. A module may specify a target specific data layout string that specifies
  1191. how data is to be laid out in memory. The syntax for the data layout is
  1192. simply:
  1193. .. code-block:: llvm
  1194. target datalayout = "layout specification"
  1195. The *layout specification* consists of a list of specifications
  1196. separated by the minus sign character ('-'). Each specification starts
  1197. with a letter and may include other information after the letter to
  1198. define some aspect of the data layout. The specifications accepted are
  1199. as follows:
  1200. ``E``
  1201. Specifies that the target lays out data in big-endian form. That is,
  1202. the bits with the most significance have the lowest address
  1203. location.
  1204. ``e``
  1205. Specifies that the target lays out data in little-endian form. That
  1206. is, the bits with the least significance have the lowest address
  1207. location.
  1208. ``S<size>``
  1209. Specifies the natural alignment of the stack in bits. Alignment
  1210. promotion of stack variables is limited to the natural stack
  1211. alignment to avoid dynamic stack realignment. The stack alignment
  1212. must be a multiple of 8-bits. If omitted, the natural stack
  1213. alignment defaults to "unspecified", which does not prevent any
  1214. alignment promotions.
  1215. ``p[n]:<size>:<abi>:<pref>``
  1216. This specifies the *size* of a pointer and its ``<abi>`` and
  1217. ``<pref>``\erred alignments for address space ``n``. All sizes are in
  1218. bits. The address space, ``n`` is optional, and if not specified,
  1219. denotes the default address space 0. The value of ``n`` must be
  1220. in the range [1,2^23).
  1221. ``i<size>:<abi>:<pref>``
  1222. This specifies the alignment for an integer type of a given bit
  1223. ``<size>``. The value of ``<size>`` must be in the range [1,2^23).
  1224. ``v<size>:<abi>:<pref>``
  1225. This specifies the alignment for a vector type of a given bit
  1226. ``<size>``.
  1227. ``f<size>:<abi>:<pref>``
  1228. This specifies the alignment for a floating point type of a given bit
  1229. ``<size>``. Only values of ``<size>`` that are supported by the target
  1230. will work. 32 (float) and 64 (double) are supported on all targets; 80
  1231. or 128 (different flavors of long double) are also supported on some
  1232. targets.
  1233. ``a:<abi>:<pref>``
  1234. This specifies the alignment for an object of aggregate type.
  1235. ``m:<mangling>``
  1236. If present, specifies that llvm names are mangled in the output. The
  1237. options are
  1238. * ``e``: ELF mangling: Private symbols get a ``.L`` prefix.
  1239. * ``m``: Mips mangling: Private symbols get a ``$`` prefix.
  1240. * ``o``: Mach-O mangling: Private symbols get ``L`` prefix. Other
  1241. symbols get a ``_`` prefix.
  1242. * ``w``: Windows COFF prefix: Similar to Mach-O, but stdcall and fastcall
  1243. functions also get a suffix based on the frame size.
  1244. ``n<size1>:<size2>:<size3>...``
  1245. This specifies a set of native integer widths for the target CPU in
  1246. bits. For example, it might contain ``n32`` for 32-bit PowerPC,
  1247. ``n32:64`` for PowerPC 64, or ``n8:16:32:64`` for X86-64. Elements of
  1248. this set are considered to support most general arithmetic operations
  1249. efficiently.
  1250. On every specification that takes a ``<abi>:<pref>``, specifying the
  1251. ``<pref>`` alignment is optional. If omitted, the preceding ``:``
  1252. should be omitted too and ``<pref>`` will be equal to ``<abi>``.
  1253. When constructing the data layout for a given target, LLVM starts with a
  1254. default set of specifications which are then (possibly) overridden by
  1255. the specifications in the ``datalayout`` keyword. The default
  1256. specifications are given in this list:
  1257. - ``E`` - big endian
  1258. - ``p:64:64:64`` - 64-bit pointers with 64-bit alignment.
  1259. - ``p[n]:64:64:64`` - Other address spaces are assumed to be the
  1260. same as the default address space.
  1261. - ``S0`` - natural stack alignment is unspecified
  1262. - ``i1:8:8`` - i1 is 8-bit (byte) aligned
  1263. - ``i8:8:8`` - i8 is 8-bit (byte) aligned
  1264. - ``i16:16:16`` - i16 is 16-bit aligned
  1265. - ``i32:32:32`` - i32 is 32-bit aligned
  1266. - ``i64:32:64`` - i64 has ABI alignment of 32-bits but preferred
  1267. alignment of 64-bits
  1268. - ``f16:16:16`` - half is 16-bit aligned
  1269. - ``f32:32:32`` - float is 32-bit aligned
  1270. - ``f64:64:64`` - double is 64-bit aligned
  1271. - ``f128:128:128`` - quad is 128-bit aligned
  1272. - ``v64:64:64`` - 64-bit vector is 64-bit aligned
  1273. - ``v128:128:128`` - 128-bit vector is 128-bit aligned
  1274. - ``a:0:64`` - aggregates are 64-bit aligned
  1275. When LLVM is determining the alignment for a given type, it uses the
  1276. following rules:
  1277. #. If the type sought is an exact match for one of the specifications,
  1278. that specification is used.
  1279. #. If no match is found, and the type sought is an integer type, then
  1280. the smallest integer type that is larger than the bitwidth of the
  1281. sought type is used. If none of the specifications are larger than
  1282. the bitwidth then the largest integer type is used. For example,
  1283. given the default specifications above, the i7 type will use the
  1284. alignment of i8 (next largest) while both i65 and i256 will use the
  1285. alignment of i64 (largest specified).
  1286. #. If no match is found, and the type sought is a vector type, then the
  1287. largest vector type that is smaller than the sought vector type will
  1288. be used as a fall back. This happens because <128 x double> can be
  1289. implemented in terms of 64 <2 x double>, for example.
  1290. The function of the data layout string may not be what you expect.
  1291. Notably, this is not a specification from the frontend of what alignment
  1292. the code generator should use.
  1293. Instead, if specified, the target data layout is required to match what
  1294. the ultimate *code generator* expects. This string is used by the
  1295. mid-level optimizers to improve code, and this only works if it matches
  1296. what the ultimate code generator uses. There is no way to generate IR
  1297. that does not embed this target-specific detail into the IR. If you
  1298. don't specify the string, the default specifications will be used to
  1299. generate a Data Layout and the optimization phases will operate
  1300. accordingly and introduce target specificity into the IR with respect to
  1301. these default specifications.
  1302. .. _langref_triple:
  1303. Target Triple
  1304. -------------
  1305. A module may specify a target triple string that describes the target
  1306. host. The syntax for the target triple is simply:
  1307. .. code-block:: llvm
  1308. target triple = "x86_64-apple-macosx10.7.0"
  1309. The *target triple* string consists of a series of identifiers delimited
  1310. by the minus sign character ('-'). The canonical forms are:
  1311. ::
  1312. ARCHITECTURE-VENDOR-OPERATING_SYSTEM
  1313. ARCHITECTURE-VENDOR-OPERATING_SYSTEM-ENVIRONMENT
  1314. This information is passed along to the backend so that it generates
  1315. code for the proper architecture. It's possible to override this on the
  1316. command line with the ``-mtriple`` command line option.
  1317. .. _pointeraliasing:
  1318. Pointer Aliasing Rules
  1319. ----------------------
  1320. Any memory access must be done through a pointer value associated with
  1321. an address range of the memory access, otherwise the behavior is
  1322. undefined. Pointer values are associated with address ranges according
  1323. to the following rules:
  1324. - A pointer value is associated with the addresses associated with any
  1325. value it is *based* on.
  1326. - An address of a global variable is associated with the address range
  1327. of the variable's storage.
  1328. - The result value of an allocation instruction is associated with the
  1329. address range of the allocated storage.
  1330. - A null pointer in the default address-space is associated with no
  1331. address.
  1332. - An integer constant other than zero or a pointer value returned from
  1333. a function not defined within LLVM may be associated with address
  1334. ranges allocated through mechanisms other than those provided by
  1335. LLVM. Such ranges shall not overlap with any ranges of addresses
  1336. allocated by mechanisms provided by LLVM.
  1337. A pointer value is *based* on another pointer value according to the
  1338. following rules:
  1339. - A pointer value formed from a ``getelementptr`` operation is *based*
  1340. on the first value operand of the ``getelementptr``.
  1341. - The result value of a ``bitcast`` is *based* on the operand of the
  1342. ``bitcast``.
  1343. - A pointer value formed by an ``inttoptr`` is *based* on all pointer
  1344. values that contribute (directly or indirectly) to the computation of
  1345. the pointer's value.
  1346. - The "*based* on" relationship is transitive.
  1347. Note that this definition of *"based"* is intentionally similar to the
  1348. definition of *"based"* in C99, though it is slightly weaker.
  1349. LLVM IR does not associate types with memory. The result type of a
  1350. ``load`` merely indicates the size and alignment of the memory from
  1351. which to load, as well as the interpretation of the value. The first
  1352. operand type of a ``store`` similarly only indicates the size and
  1353. alignment of the store.
  1354. Consequently, type-based alias analysis, aka TBAA, aka
  1355. ``-fstrict-aliasing``, is not applicable to general unadorned LLVM IR.
  1356. :ref:`Metadata <metadata>` may be used to encode additional information
  1357. which specialized optimization passes may use to implement type-based
  1358. alias analysis.
  1359. .. _volatile:
  1360. Volatile Memory Accesses
  1361. ------------------------
  1362. Certain memory accesses, such as :ref:`load <i_load>`'s,
  1363. :ref:`store <i_store>`'s, and :ref:`llvm.memcpy <int_memcpy>`'s may be
  1364. marked ``volatile``. The optimizers must not change the number of
  1365. volatile operations or change their order of execution relative to other
  1366. volatile operations. The optimizers *may* change the order of volatile
  1367. operations relative to non-volatile operations. This is not Java's
  1368. "volatile" and has no cross-thread synchronization behavior.
  1369. IR-level volatile loads and stores cannot safely be optimized into
  1370. llvm.memcpy or llvm.memmove intrinsics even when those intrinsics are
  1371. flagged volatile. Likewise, the backend should never split or merge
  1372. target-legal volatile load/store instructions.
  1373. .. admonition:: Rationale
  1374. Platforms may rely on volatile loads and stores of natively supported
  1375. data width to be executed as single instruction. For example, in C
  1376. this holds for an l-value of volatile primitive type with native
  1377. hardware support, but not necessarily for aggregate types. The
  1378. frontend upholds these expectations, which are intentionally
  1379. unspecified in the IR. The rules above ensure that IR transformation
  1380. do not violate the frontend's contract with the language.
  1381. .. _memmodel:
  1382. Memory Model for Concurrent Operations
  1383. --------------------------------------
  1384. The LLVM IR does not define any way to start parallel threads of
  1385. execution or to register signal handlers. Nonetheless, there are
  1386. platform-specific ways to create them, and we define LLVM IR's behavior
  1387. in their presence. This model is inspired by the C++0x memory model.
  1388. For a more informal introduction to this model, see the :doc:`Atomics`.
  1389. We define a *happens-before* partial order as the least partial order
  1390. that
  1391. - Is a superset of single-thread program order, and
  1392. - When a *synchronizes-with* ``b``, includes an edge from ``a`` to
  1393. ``b``. *Synchronizes-with* pairs are introduced by platform-specific
  1394. techniques, like pthread locks, thread creation, thread joining,
  1395. etc., and by atomic instructions. (See also :ref:`Atomic Memory Ordering
  1396. Constraints <ordering>`).
  1397. Note that program order does not introduce *happens-before* edges
  1398. between a thread and signals executing inside that thread.
  1399. Every (defined) read operation (load instructions, memcpy, atomic
  1400. loads/read-modify-writes, etc.) R reads a series of bytes written by
  1401. (defined) write operations (store instructions, atomic
  1402. stores/read-modify-writes, memcpy, etc.). For the purposes of this
  1403. section, initialized globals are considered to have a write of the
  1404. initializer which is atomic and happens before any other read or write
  1405. of the memory in question. For each byte of a read R, R\ :sub:`byte`
  1406. may see any write to the same byte, except:
  1407. - If write\ :sub:`1` happens before write\ :sub:`2`, and
  1408. write\ :sub:`2` happens before R\ :sub:`byte`, then
  1409. R\ :sub:`byte` does not see write\ :sub:`1`.
  1410. - If R\ :sub:`byte` happens before write\ :sub:`3`, then
  1411. R\ :sub:`byte` does not see write\ :sub:`3`.
  1412. Given that definition, R\ :sub:`byte` is defined as follows:
  1413. - If R is volatile, the result is target-dependent. (Volatile is
  1414. supposed to give guarantees which can support ``sig_atomic_t`` in
  1415. C/C++, and may be used for accesses to addresses that do not behave
  1416. like normal memory. It does not generally provide cross-thread
  1417. synchronization.)
  1418. - Otherwise, if there is no write to the same byte that happens before
  1419. R\ :sub:`byte`, R\ :sub:`byte` returns ``undef`` for that byte.
  1420. - Otherwise, if R\ :sub:`byte` may see exactly one write,
  1421. R\ :sub:`byte` returns the value written by that write.
  1422. - Otherwise, if R is atomic, and all the writes R\ :sub:`byte` may
  1423. see are atomic, it chooses one of the values written. See the :ref:`Atomic
  1424. Memory Ordering Constraints <ordering>` section for additional
  1425. constraints on how the choice is made.
  1426. - Otherwise R\ :sub:`byte` returns ``undef``.
  1427. R returns the value composed of the series of bytes it read. This
  1428. implies that some bytes within the value may be ``undef`` **without**
  1429. the entire value being ``undef``. Note that this only defines the
  1430. semantics of the operation; it doesn't mean that targets will emit more
  1431. than one instruction to read the series of bytes.
  1432. Note that in cases where none of the atomic intrinsics are used, this
  1433. model places only one restriction on IR transformations on top of what
  1434. is required for single-threaded execution: introducing a store to a byte
  1435. which might not otherwise be stored is not allowed in general.
  1436. (Specifically, in the case where another thread might write to and read
  1437. from an address, introducing a store can change a load that may see
  1438. exactly one write into a load that may see multiple writes.)
  1439. .. _ordering:
  1440. Atomic Memory Ordering Constraints
  1441. ----------------------------------
  1442. Atomic instructions (:ref:`cmpxchg <i_cmpxchg>`,
  1443. :ref:`atomicrmw <i_atomicrmw>`, :ref:`fence <i_fence>`,
  1444. :ref:`atomic load <i_load>`, and :ref:`atomic store <i_store>`) take
  1445. ordering parameters that determine which other atomic instructions on
  1446. the same address they *synchronize with*. These semantics are borrowed
  1447. from Java and C++0x, but are somewhat more colloquial. If these
  1448. descriptions aren't precise enough, check those specs (see spec
  1449. references in the :doc:`atomics guide <Atomics>`).
  1450. :ref:`fence <i_fence>` instructions treat these orderings somewhat
  1451. differently since they don't take an address. See that instruction's
  1452. documentation for details.
  1453. For a simpler introduction to the ordering constraints, see the
  1454. :doc:`Atomics`.
  1455. ``unordered``
  1456. The set of values that can be read is governed by the happens-before
  1457. partial order. A value cannot be read unless some operation wrote
  1458. it. This is intended to provide a guarantee strong enough to model
  1459. Java's non-volatile shared variables. This ordering cannot be
  1460. specified for read-modify-write operations; it is not strong enough
  1461. to make them atomic in any interesting way.
  1462. ``monotonic``
  1463. In addition to the guarantees of ``unordered``, there is a single
  1464. total order for modifications by ``monotonic`` operations on each
  1465. address. All modification orders must be compatible with the
  1466. happens-before order. There is no guarantee that the modification
  1467. orders can be combined to a global total order for the whole program
  1468. (and this often will not be possible). The read in an atomic
  1469. read-modify-write operation (:ref:`cmpxchg <i_cmpxchg>` and
  1470. :ref:`atomicrmw <i_atomicrmw>`) reads the value in the modification
  1471. order immediately before the value it writes. If one atomic read
  1472. happens before another atomic read of the same address, the later
  1473. read must see the same value or a later value in the address's
  1474. modification order. This disallows reordering of ``monotonic`` (or
  1475. stronger) operations on the same address. If an address is written
  1476. ``monotonic``-ally by one thread, and other threads ``monotonic``-ally
  1477. read that address repeatedly, the other threads must eventually see
  1478. the write. This corresponds to the C++0x/C1x
  1479. ``memory_order_relaxed``.
  1480. ``acquire``
  1481. In addition to the guarantees of ``monotonic``, a
  1482. *synchronizes-with* edge may be formed with a ``release`` operation.
  1483. This is intended to model C++'s ``memory_order_acquire``.
  1484. ``release``
  1485. In addition to the guarantees of ``monotonic``, if this operation
  1486. writes a value which is subsequently read by an ``acquire``
  1487. operation, it *synchronizes-with* that operation. (This isn't a
  1488. complete description; see the C++0x definition of a release
  1489. sequence.) This corresponds to the C++0x/C1x
  1490. ``memory_order_release``.
  1491. ``acq_rel`` (acquire+release)
  1492. Acts as both an ``acquire`` and ``release`` operation on its
  1493. address. This corresponds to the C++0x/C1x ``memory_order_acq_rel``.
  1494. ``seq_cst`` (sequentially consistent)
  1495. In addition to the guarantees of ``acq_rel`` (``acquire`` for an
  1496. operation that only reads, ``release`` for an operation that only
  1497. writes), there is a global total order on all
  1498. sequentially-consistent operations on all addresses, which is
  1499. consistent with the *happens-before* partial order and with the
  1500. modification orders of all the affected addresses. Each
  1501. sequentially-consistent read sees the last preceding write to the
  1502. same address in this global order. This corresponds to the C++0x/C1x
  1503. ``memory_order_seq_cst`` and Java volatile.
  1504. .. _singlethread:
  1505. If an atomic operation is marked ``singlethread``, it only *synchronizes
  1506. with* or participates in modification and seq\_cst total orderings with
  1507. other operations running in the same thread (for example, in signal
  1508. handlers).
  1509. .. _fastmath:
  1510. Fast-Math Flags
  1511. ---------------
  1512. LLVM IR floating-point binary ops (:ref:`fadd <i_fadd>`,
  1513. :ref:`fsub <i_fsub>`, :ref:`fmul <i_fmul>`, :ref:`fdiv <i_fdiv>`,
  1514. :ref:`frem <i_frem>`, :ref:`fcmp <i_fcmp>`) have the following flags that can
  1515. be set to enable otherwise unsafe floating point operations
  1516. ``nnan``
  1517. No NaNs - Allow optimizations to assume the arguments and result are not
  1518. NaN. Such optimizations are required to retain defined behavior over
  1519. NaNs, but the value of the result is undefined.
  1520. ``ninf``
  1521. No Infs - Allow optimizations to assume the arguments and result are not
  1522. +/-Inf. Such optimizations are required to retain defined behavior over
  1523. +/-Inf, but the value of the result is undefined.
  1524. ``nsz``
  1525. No Signed Zeros - Allow optimizations to treat the sign of a zero
  1526. argument or result as insignificant.
  1527. ``arcp``
  1528. Allow Reciprocal - Allow optimizations to use the reciprocal of an
  1529. argument rather than perform division.
  1530. ``fast``
  1531. Fast - Allow algebraically equivalent transformations that may
  1532. dramatically change results in floating point (e.g. reassociate). This
  1533. flag implies all the others.
  1534. .. _uselistorder:
  1535. Use-list Order Directives
  1536. -------------------------
  1537. Use-list directives encode the in-memory order of each use-list, allowing the
  1538. order to be recreated. ``<order-indexes>`` is a comma-separated list of
  1539. indexes that are assigned to the referenced value's uses. The referenced
  1540. value's use-list is immediately sorted by these indexes.
  1541. Use-list directives may appear at function scope or global scope. They are not
  1542. instructions, and have no effect on the semantics of the IR. When they're at
  1543. function scope, they must appear after the terminator of the final basic block.
  1544. If basic blocks have their address taken via ``blockaddress()`` expressions,
  1545. ``uselistorder_bb`` can be used to reorder their use-lists from outside their
  1546. function's scope.
  1547. :Syntax:
  1548. ::
  1549. uselistorder <ty> <value>, { <order-indexes> }
  1550. uselistorder_bb @function, %block { <order-indexes> }
  1551. :Examples:
  1552. ::
  1553. define void @foo(i32 %arg1, i32 %arg2) {
  1554. entry:
  1555. ; ... instructions ...
  1556. bb:
  1557. ; ... instructions ...
  1558. ; At function scope.
  1559. uselistorder i32 %arg1, { 1, 0, 2 }
  1560. uselistorder label %bb, { 1, 0 }
  1561. }
  1562. ; At global scope.
  1563. uselistorder i32* @global, { 1, 2, 0 }
  1564. uselistorder i32 7, { 1, 0 }
  1565. uselistorder i32 (i32) @bar, { 1, 0 }
  1566. uselistorder_bb @foo, %bb, { 5, 1, 3, 2, 0, 4 }
  1567. .. _typesystem:
  1568. Type System
  1569. ===========
  1570. The LLVM type system is one of the most important features of the
  1571. intermediate representation. Being typed enables a number of
  1572. optimizations to be performed on the intermediate representation
  1573. directly, without having to do extra analyses on the side before the
  1574. transformation. A strong type system makes it easier to read the
  1575. generated code and enables novel analyses and transformations that are
  1576. not feasible to perform on normal three address code representations.
  1577. .. _t_void:
  1578. Void Type
  1579. ---------
  1580. :Overview:
  1581. The void type does not represent any value and has no size.
  1582. :Syntax:
  1583. ::
  1584. void
  1585. .. _t_function:
  1586. Function Type
  1587. -------------
  1588. :Overview:
  1589. The function type can be thought of as a function signature. It consists of a
  1590. return type and a list of formal parameter types. The return type of a function
  1591. type is a void type or first class type --- except for :ref:`label <t_label>`
  1592. and :ref:`metadata <t_metadata>` types.
  1593. :Syntax:
  1594. ::
  1595. <returntype> (<parameter list>)
  1596. ...where '``<parameter list>``' is a comma-separated list of type
  1597. specifiers. Optionally, the parameter list may include a type ``...``, which
  1598. indicates that the function takes a variable number of arguments. Variable
  1599. argument functions can access their arguments with the :ref:`variable argument
  1600. handling intrinsic <int_varargs>` functions. '``<returntype>``' is any type
  1601. except :ref:`label <t_label>` and :ref:`metadata <t_metadata>`.
  1602. :Examples:
  1603. +---------------------------------+---------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  1604. | ``i32 (i32)`` | function taking an ``i32``, returning an ``i32`` |
  1605. +---------------------------------+---------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  1606. | ``float (i16, i32 *) *`` | :ref:`Pointer <t_pointer>` to a function that takes an ``i16`` and a :ref:`pointer <t_pointer>` to ``i32``, returning ``float``. |
  1607. +---------------------------------+---------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  1608. | ``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. |
  1609. +---------------------------------+---------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  1610. | ``{i32, i32} (i32)`` | A function taking an ``i32``, returning a :ref:`structure <t_struct>` containing two ``i32`` values |
  1611. +---------------------------------+---------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  1612. .. _t_firstclass:
  1613. First Class Types
  1614. -----------------
  1615. The :ref:`first class <t_firstclass>` types are perhaps the most important.
  1616. Values of these types are the only ones which can be produced by
  1617. instructions.
  1618. .. _t_single_value:
  1619. Single Value Types
  1620. ^^^^^^^^^^^^^^^^^^
  1621. These are the types that are valid in registers from CodeGen's perspective.
  1622. .. _t_integer:
  1623. Integer Type
  1624. """"""""""""
  1625. :Overview:
  1626. The integer type is a very simple type that simply specifies an
  1627. arbitrary bit width for the integer type desired. Any bit width from 1
  1628. bit to 2\ :sup:`23`\ -1 (about 8 million) can be specified.
  1629. :Syntax:
  1630. ::
  1631. iN
  1632. The number of bits the integer will occupy is specified by the ``N``
  1633. value.
  1634. Examples:
  1635. *********
  1636. +----------------+------------------------------------------------+
  1637. | ``i1`` | a single-bit integer. |
  1638. +----------------+------------------------------------------------+
  1639. | ``i32`` | a 32-bit integer. |
  1640. +----------------+------------------------------------------------+
  1641. | ``i1942652`` | a really big integer of over 1 million bits. |
  1642. +----------------+------------------------------------------------+
  1643. .. _t_floating:
  1644. Floating Point Types
  1645. """"""""""""""""""""
  1646. .. list-table::
  1647. :header-rows: 1
  1648. * - Type
  1649. - Description
  1650. * - ``half``
  1651. - 16-bit floating point value
  1652. * - ``float``
  1653. - 32-bit floating point value
  1654. * - ``double``
  1655. - 64-bit floating point value
  1656. * - ``fp128``
  1657. - 128-bit floating point value (112-bit mantissa)
  1658. * - ``x86_fp80``
  1659. - 80-bit floating point value (X87)
  1660. * - ``ppc_fp128``
  1661. - 128-bit floating point value (two 64-bits)
  1662. X86_mmx Type
  1663. """"""""""""
  1664. :Overview:
  1665. The x86_mmx type represents a value held in an MMX register on an x86
  1666. machine. The operations allowed on it are quite limited: parameters and
  1667. return values, load and store, and bitcast. User-specified MMX
  1668. instructions are represented as intrinsic or asm calls with arguments
  1669. and/or results of this type. There are no arrays, vectors or constants
  1670. of this type.
  1671. :Syntax:
  1672. ::
  1673. x86_mmx
  1674. .. _t_pointer:
  1675. Pointer Type
  1676. """"""""""""
  1677. :Overview:
  1678. The pointer type is used to specify memory locations. Pointers are
  1679. commonly used to reference objects in memory.
  1680. Pointer types may have an optional address space attribute defining the
  1681. numbered address space where the pointed-to object resides. The default
  1682. address space is number zero. The semantics of non-zero address spaces
  1683. are target-specific.
  1684. Note that LLVM does not permit pointers to void (``void*``) nor does it
  1685. permit pointers to labels (``label*``). Use ``i8*`` instead.
  1686. :Syntax:
  1687. ::
  1688. <type> *
  1689. :Examples:
  1690. +-------------------------+--------------------------------------------------------------------------------------------------------------+
  1691. | ``[4 x i32]*`` | A :ref:`pointer <t_pointer>` to :ref:`array <t_array>` of four ``i32`` values. |
  1692. +-------------------------+--------------------------------------------------------------------------------------------------------------+
  1693. | ``i32 (i32*) *`` | A :ref:`pointer <t_pointer>` to a :ref:`function <t_function>` that takes an ``i32*``, returning an ``i32``. |
  1694. +-------------------------+--------------------------------------------------------------------------------------------------------------+
  1695. | ``i32 addrspace(5)*`` | A :ref:`pointer <t_pointer>` to an ``i32`` value that resides in address space #5. |
  1696. +-------------------------+--------------------------------------------------------------------------------------------------------------+
  1697. .. _t_vector:
  1698. Vector Type
  1699. """""""""""
  1700. :Overview:
  1701. A vector type is a simple derived type that represents a vector of
  1702. elements. Vector types are used when multiple primitive data are
  1703. operated in parallel using a single instruction (SIMD). A vector type
  1704. requires a size (number of elements) and an underlying primitive data
  1705. type. Vector types are considered :ref:`first class <t_firstclass>`.
  1706. :Syntax:
  1707. ::
  1708. < <# elements> x <elementtype> >
  1709. The number of elements is a constant integer value larger than 0;
  1710. elementtype may be any integer, floating point or pointer type. Vectors
  1711. of size zero are not allowed.
  1712. :Examples:
  1713. +-------------------+--------------------------------------------------+
  1714. | ``<4 x i32>`` | Vector of 4 32-bit integer values. |
  1715. +-------------------+--------------------------------------------------+
  1716. | ``<8 x float>`` | Vector of 8 32-bit floating-point values. |
  1717. +-------------------+--------------------------------------------------+
  1718. | ``<2 x i64>`` | Vector of 2 64-bit integer values. |
  1719. +-------------------+--------------------------------------------------+
  1720. | ``<4 x i64*>`` | Vector of 4 pointers to 64-bit integer values. |
  1721. +-------------------+--------------------------------------------------+
  1722. .. _t_label:
  1723. Label Type
  1724. ^^^^^^^^^^
  1725. :Overview:
  1726. The label type represents code labels.
  1727. :Syntax:
  1728. ::
  1729. label
  1730. .. _t_metadata:
  1731. Metadata Type
  1732. ^^^^^^^^^^^^^
  1733. :Overview:
  1734. The metadata type represents embedded metadata. No derived types may be
  1735. created from metadata except for :ref:`function <t_function>` arguments.
  1736. :Syntax:
  1737. ::
  1738. metadata
  1739. .. _t_aggregate:
  1740. Aggregate Types
  1741. ^^^^^^^^^^^^^^^
  1742. Aggregate Types are a subset of derived types that can contain multiple
  1743. member types. :ref:`Arrays <t_array>` and :ref:`structs <t_struct>` are
  1744. aggregate types. :ref:`Vectors <t_vector>` are not considered to be
  1745. aggregate types.
  1746. .. _t_array:
  1747. Array Type
  1748. """"""""""
  1749. :Overview:
  1750. The array type is a very simple derived type that arranges elements
  1751. sequentially in memory. The array type requires a size (number of
  1752. elements) and an underlying data type.
  1753. :Syntax:
  1754. ::
  1755. [<# elements> x <elementtype>]
  1756. The number of elements is a constant integer value; ``elementtype`` may
  1757. be any type with a size.
  1758. :Examples:
  1759. +------------------+--------------------------------------+
  1760. | ``[40 x i32]`` | Array of 40 32-bit integer values. |
  1761. +------------------+--------------------------------------+
  1762. | ``[41 x i32]`` | Array of 41 32-bit integer values. |
  1763. +------------------+--------------------------------------+
  1764. | ``[4 x i8]`` | Array of 4 8-bit integer values. |
  1765. +------------------+--------------------------------------+
  1766. Here are some examples of multidimensional arrays:
  1767. +-----------------------------+----------------------------------------------------------+
  1768. | ``[3 x [4 x i32]]`` | 3x4 array of 32-bit integer values. |
  1769. +-----------------------------+----------------------------------------------------------+
  1770. | ``[12 x [10 x float]]`` | 12x10 array of single precision floating point values. |
  1771. +-----------------------------+----------------------------------------------------------+
  1772. | ``[2 x [3 x [4 x i16]]]`` | 2x3x4 array of 16-bit integer values. |
  1773. +-----------------------------+----------------------------------------------------------+
  1774. There is no restriction on indexing beyond the end of the array implied
  1775. by a static type (though there are restrictions on indexing beyond the
  1776. bounds of an allocated object in some cases). This means that
  1777. single-dimension 'variable sized array' addressing can be implemented in
  1778. LLVM with a zero length array type. An implementation of 'pascal style
  1779. arrays' in LLVM could use the type "``{ i32, [0 x float]}``", for
  1780. example.
  1781. .. _t_struct:
  1782. Structure Type
  1783. """"""""""""""
  1784. :Overview:
  1785. The structure type is used to represent a collection of data members
  1786. together in memory. The elements of a structure may be any type that has
  1787. a size.
  1788. Structures in memory are accessed using '``load``' and '``store``' by
  1789. getting a pointer to a field with the '``getelementptr``' instruction.
  1790. Structures in registers are accessed using the '``extractvalue``' and
  1791. '``insertvalue``' instructions.
  1792. Structures may optionally be "packed" structures, which indicate that
  1793. the alignment of the struct is one byte, and that there is no padding
  1794. between the elements. In non-packed structs, padding between field types
  1795. is inserted as defined by the DataLayout string in the module, which is
  1796. required to match what the underlying code generator expects.
  1797. Structures can either be "literal" or "identified". A literal structure
  1798. is defined inline with other types (e.g. ``{i32, i32}*``) whereas
  1799. identified types are always defined at the top level with a name.
  1800. Literal types are uniqued by their contents and can never be recursive
  1801. or opaque since there is no way to write one. Identified types can be
  1802. recursive, can be opaqued, and are never uniqued.
  1803. :Syntax:
  1804. ::
  1805. %T1 = type { <type list> } ; Identified normal struct type
  1806. %T2 = type <{ <type list> }> ; Identified packed struct type
  1807. :Examples:
  1808. +------------------------------+---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  1809. | ``{ i32, i32, i32 }`` | A triple of three ``i32`` values |
  1810. +------------------------------+---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  1811. | ``{ 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``. |
  1812. +------------------------------+---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  1813. | ``<{ i8, i32 }>`` | A packed struct known to be 5 bytes in size. |
  1814. +------------------------------+---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  1815. .. _t_opaque:
  1816. Opaque Structure Types
  1817. """"""""""""""""""""""
  1818. :Overview:
  1819. Opaque structure types are used to represent named structure types that
  1820. do not have a body specified. This corresponds (for example) to the C
  1821. notion of a forward declared structure.
  1822. :Syntax:
  1823. ::
  1824. %X = type opaque
  1825. %52 = type opaque
  1826. :Examples:
  1827. +--------------+-------------------+
  1828. | ``opaque`` | An opaque type. |
  1829. +--------------+-------------------+
  1830. .. _constants:
  1831. Constants
  1832. =========
  1833. LLVM has several different basic types of constants. This section
  1834. describes them all and their syntax.
  1835. Simple Constants
  1836. ----------------
  1837. **Boolean constants**
  1838. The two strings '``true``' and '``false``' are both valid constants
  1839. of the ``i1`` type.
  1840. **Integer constants**
  1841. Standard integers (such as '4') are constants of the
  1842. :ref:`integer <t_integer>` type. Negative numbers may be used with
  1843. integer types.
  1844. **Floating point constants**
  1845. Floating point constants use standard decimal notation (e.g.
  1846. 123.421), exponential notation (e.g. 1.23421e+2), or a more precise
  1847. hexadecimal notation (see below). The assembler requires the exact
  1848. decimal value of a floating-point constant. For example, the
  1849. assembler accepts 1.25 but rejects 1.3 because 1.3 is a repeating
  1850. decimal in binary. Floating point constants must have a :ref:`floating
  1851. point <t_floating>` type.
  1852. **Null pointer constants**
  1853. The identifier '``null``' is recognized as a null pointer constant
  1854. and must be of :ref:`pointer type <t_pointer>`.
  1855. The one non-intuitive notation for constants is the hexadecimal form of
  1856. floating point constants. For example, the form
  1857. '``double 0x432ff973cafa8000``' is equivalent to (but harder to read
  1858. than) '``double 4.5e+15``'. The only time hexadecimal floating point
  1859. constants are required (and the only time that they are generated by the
  1860. disassembler) is when a floating point constant must be emitted but it
  1861. cannot be represented as a decimal floating point number in a reasonable
  1862. number of digits. For example, NaN's, infinities, and other special
  1863. values are represented in their IEEE hexadecimal format so that assembly
  1864. and disassembly do not cause any bits to change in the constants.
  1865. When using the hexadecimal form, constants of types half, float, and
  1866. double are represented using the 16-digit form shown above (which
  1867. matches the IEEE754 representation for double); half and float values
  1868. must, however, be exactly representable as IEEE 754 half and single
  1869. precision, respectively. Hexadecimal format is always used for long
  1870. double, and there are three forms of long double. The 80-bit format used
  1871. by x86 is represented as ``0xK`` followed by 20 hexadecimal digits. The
  1872. 128-bit format used by PowerPC (two adjacent doubles) is represented by
  1873. ``0xM`` followed by 32 hexadecimal digits. The IEEE 128-bit format is
  1874. represented by ``0xL`` followed by 32 hexadecimal digits. Long doubles
  1875. will only work if they match the long double format on your target.
  1876. The IEEE 16-bit format (half precision) is represented by ``0xH``
  1877. followed by 4 hexadecimal digits. All hexadecimal formats are big-endian
  1878. (sign bit at the left).
  1879. There are no constants of type x86_mmx.
  1880. .. _complexconstants:
  1881. Complex Constants
  1882. -----------------
  1883. Complex constants are a (potentially recursive) combination of simple
  1884. constants and smaller complex constants.
  1885. **Structure constants**
  1886. Structure constants are represented with notation similar to
  1887. structure type definitions (a comma separated list of elements,
  1888. surrounded by braces (``{}``)). For example:
  1889. "``{ i32 4, float 17.0, i32* @G }``", where "``@G``" is declared as
  1890. "``@G = external global i32``". Structure constants must have
  1891. :ref:`structure type <t_struct>`, and the number and types of elements
  1892. must match those specified by the type.
  1893. **Array constants**
  1894. Array constants are represented with notation similar to array type
  1895. definitions (a comma separated list of elements, surrounded by
  1896. square brackets (``[]``)). For example:
  1897. "``[ i32 42, i32 11, i32 74 ]``". Array constants must have
  1898. :ref:`array type <t_array>`, and the number and types of elements must
  1899. match those specified by the type. As a special case, character array
  1900. constants may also be represented as a double-quoted string using the ``c``
  1901. prefix. For example: "``c"Hello World\0A\00"``".
  1902. **Vector constants**
  1903. Vector constants are represented with notation similar to vector
  1904. type definitions (a comma separated list of elements, surrounded by
  1905. less-than/greater-than's (``<>``)). For example:
  1906. "``< i32 42, i32 11, i32 74, i32 100 >``". Vector constants
  1907. must have :ref:`vector type <t_vector>`, and the number and types of
  1908. elements must match those specified by the type.
  1909. **Zero initialization**
  1910. The string '``zeroinitializer``' can be used to zero initialize a
  1911. value to zero of *any* type, including scalar and
  1912. :ref:`aggregate <t_aggregate>` types. This is often used to avoid
  1913. having to print large zero initializers (e.g. for large arrays) and
  1914. is always exactly equivalent to using explicit zero initializers.
  1915. **Metadata node**
  1916. A metadata node is a constant tuple without types. For example:
  1917. "``!{!0, !{!2, !0}, !"test"}``". Metadata can reference constant values,
  1918. for example: "``!{!0, i32 0, i8* @global, i64 (i64)* @function, !"str"}``".
  1919. Unlike other typed constants that are meant to be interpreted as part of
  1920. the instruction stream, metadata is a place to attach additional
  1921. information such as debug info.
  1922. Global Variable and Function Addresses
  1923. --------------------------------------
  1924. The addresses of :ref:`global variables <globalvars>` and
  1925. :ref:`functions <functionstructure>` are always implicitly valid
  1926. (link-time) constants. These constants are explicitly referenced when
  1927. the :ref:`identifier for the global <identifiers>` is used and always have
  1928. :ref:`pointer <t_pointer>` type. For example, the following is a legal LLVM
  1929. file:
  1930. .. code-block:: llvm
  1931. @X = global i32 17
  1932. @Y = global i32 42
  1933. @Z = global [2 x i32*] [ i32* @X, i32* @Y ]
  1934. .. _undefvalues:
  1935. Undefined Values
  1936. ----------------
  1937. The string '``undef``' can be used anywhere a constant is expected, and
  1938. indicates that the user of the value may receive an unspecified
  1939. bit-pattern. Undefined values may be of any type (other than '``label``'
  1940. or '``void``') and be used anywhere a constant is permitted.
  1941. Undefined values are useful because they indicate to the compiler that
  1942. the program is well defined no matter what value is used. This gives the
  1943. compiler more freedom to optimize. Here are some examples of
  1944. (potentially surprising) transformations that are valid (in pseudo IR):
  1945. .. code-block:: llvm
  1946. %A = add %X, undef
  1947. %B = sub %X, undef
  1948. %C = xor %X, undef
  1949. Safe:
  1950. %A = undef
  1951. %B = undef
  1952. %C = undef
  1953. This is safe because all of the output bits are affected by the undef
  1954. bits. Any output bit can have a zero or one depending on the input bits.
  1955. .. code-block:: llvm
  1956. %A = or %X, undef
  1957. %B = and %X, undef
  1958. Safe:
  1959. %A = -1
  1960. %B = 0
  1961. Unsafe:
  1962. %A = undef
  1963. %B = undef
  1964. These logical operations have bits that are not always affected by the
  1965. input. For example, if ``%X`` has a zero bit, then the output of the
  1966. '``and``' operation will always be a zero for that bit, no matter what
  1967. the corresponding bit from the '``undef``' is. As such, it is unsafe to
  1968. optimize or assume that the result of the '``and``' is '``undef``'.
  1969. However, it is safe to assume that all bits of the '``undef``' could be
  1970. 0, and optimize the '``and``' to 0. Likewise, it is safe to assume that
  1971. all the bits of the '``undef``' operand to the '``or``' could be set,
  1972. allowing the '``or``' to be folded to -1.
  1973. .. code-block:: llvm
  1974. %A = select undef, %X, %Y
  1975. %B = select undef, 42, %Y
  1976. %C = select %X, %Y, undef
  1977. Safe:
  1978. %A = %X (or %Y)
  1979. %B = 42 (or %Y)
  1980. %C = %Y
  1981. Unsafe:
  1982. %A = undef
  1983. %B = undef
  1984. %C = undef
  1985. This set of examples shows that undefined '``select``' (and conditional
  1986. branch) conditions can go *either way*, but they have to come from one
  1987. of the two operands. In the ``%A`` example, if ``%X`` and ``%Y`` were
  1988. both known to have a clear low bit, then ``%A`` would have to have a
  1989. cleared low bit. However, in the ``%C`` example, the optimizer is
  1990. allowed to assume that the '``undef``' operand could be the same as
  1991. ``%Y``, allowing the whole '``select``' to be eliminated.
  1992. .. code-block:: llvm
  1993. %A = xor undef, undef
  1994. %B = undef
  1995. %C = xor %B, %B
  1996. %D = undef
  1997. %E = icmp slt %D, 4
  1998. %F = icmp gte %D, 4
  1999. Safe:
  2000. %A = undef
  2001. %B = undef
  2002. %C = undef
  2003. %D = undef
  2004. %E = undef
  2005. %F = undef
  2006. This example points out that two '``undef``' operands are not
  2007. necessarily the same. This can be surprising to people (and also matches
  2008. C semantics) where they assume that "``X^X``" is always zero, even if
  2009. ``X`` is undefined. This isn't true for a number of reasons, but the
  2010. short answer is that an '``undef``' "variable" can arbitrarily change
  2011. its value over its "live range". This is true because the variable
  2012. doesn't actually *have a live range*. Instead, the value is logically
  2013. read from arbitrary registers that happen to be around when needed, so
  2014. the value is not necessarily consistent over time. In fact, ``%A`` and
  2015. ``%C`` need to have the same semantics or the core LLVM "replace all
  2016. uses with" concept would not hold.
  2017. .. code-block:: llvm
  2018. %A = fdiv undef, %X
  2019. %B = fdiv %X, undef
  2020. Safe:
  2021. %A = undef
  2022. b: unreachable
  2023. These examples show the crucial difference between an *undefined value*
  2024. and *undefined behavior*. An undefined value (like '``undef``') is
  2025. allowed to have an arbitrary bit-pattern. This means that the ``%A``
  2026. operation can be constant folded to '``undef``', because the '``undef``'
  2027. could be an SNaN, and ``fdiv`` is not (currently) defined on SNaN's.
  2028. However, in the second example, we can make a more aggressive
  2029. assumption: because the ``undef`` is allowed to be an arbitrary value,
  2030. we are allowed to assume that it could be zero. Since a divide by zero
  2031. has *undefined behavior*, we are allowed to assume that the operation
  2032. does not execute at all. This allows us to delete the divide and all
  2033. code after it. Because the undefined operation "can't happen", the
  2034. optimizer can assume that it occurs in dead code.
  2035. .. code-block:: llvm
  2036. a: store undef -> %X
  2037. b: store %X -> undef
  2038. Safe:
  2039. a: <deleted>
  2040. b: unreachable
  2041. These examples reiterate the ``fdiv`` example: a store *of* an undefined
  2042. value can be assumed to not have any effect; we can assume that the
  2043. value is overwritten with bits that happen to match what was already
  2044. there. However, a store *to* an undefined location could clobber
  2045. arbitrary memory, therefore, it has undefined behavior.
  2046. .. _poisonvalues:
  2047. Poison Values
  2048. -------------
  2049. Poison values are similar to :ref:`undef values <undefvalues>`, however
  2050. they also represent the fact that an instruction or constant expression
  2051. that cannot evoke side effects has nevertheless detected a condition
  2052. that results in undefined behavior.
  2053. There is currently no way of representing a poison value in the IR; they
  2054. only exist when produced by operations such as :ref:`add <i_add>` with
  2055. the ``nsw`` flag.
  2056. Poison value behavior is defined in terms of value *dependence*:
  2057. - Values other than :ref:`phi <i_phi>` nodes depend on their operands.
  2058. - :ref:`Phi <i_phi>` nodes depend on the operand corresponding to
  2059. their dynamic predecessor basic block.
  2060. - Function arguments depend on the corresponding actual argument values
  2061. in the dynamic callers of their functions.
  2062. - :ref:`Call <i_call>` instructions depend on the :ref:`ret <i_ret>`
  2063. instructions that dynamically transfer control back to them.
  2064. - :ref:`Invoke <i_invoke>` instructions depend on the
  2065. :ref:`ret <i_ret>`, :ref:`resume <i_resume>`, or exception-throwing
  2066. call instructions that dynamically transfer control back to them.
  2067. - Non-volatile loads and stores depend on the most recent stores to all
  2068. of the referenced memory addresses, following the order in the IR
  2069. (including loads and stores implied by intrinsics such as
  2070. :ref:`@llvm.memcpy <int_memcpy>`.)
  2071. - An instruction with externally visible side effects depends on the
  2072. most recent preceding instruction with externally visible side
  2073. effects, following the order in the IR. (This includes :ref:`volatile
  2074. operations <volatile>`.)
  2075. - An instruction *control-depends* on a :ref:`terminator
  2076. instruction <terminators>` if the terminator instruction has
  2077. multiple successors and the instruction is always executed when
  2078. control transfers to one of the successors, and may not be executed
  2079. when control is transferred to another.
  2080. - Additionally, an instruction also *control-depends* on a terminator
  2081. instruction if the set of instructions it otherwise depends on would
  2082. be different if the terminator had transferred control to a different
  2083. successor.
  2084. - Dependence is transitive.
  2085. Poison values have the same behavior as :ref:`undef values <undefvalues>`,
  2086. with the additional effect that any instruction that has a *dependence*
  2087. on a poison value has undefined behavior.
  2088. Here are some examples:
  2089. .. code-block:: llvm
  2090. entry:
  2091. %poison = sub nuw i32 0, 1 ; Results in a poison value.
  2092. %still_poison = and i32 %poison, 0 ; 0, but also poison.
  2093. %poison_yet_again = getelementptr i32, i32* @h, i32 %still_poison
  2094. store i32 0, i32* %poison_yet_again ; memory at @h[0] is poisoned
  2095. store i32 %poison, i32* @g ; Poison value stored to memory.
  2096. %poison2 = load i32, i32* @g ; Poison value loaded back from memory.
  2097. store volatile i32 %poison, i32* @g ; External observation; undefined behavior.
  2098. %narrowaddr = bitcast i32* @g to i16*
  2099. %wideaddr = bitcast i32* @g to i64*
  2100. %poison3 = load i16, i16* %narrowaddr ; Returns a poison value.
  2101. %poison4 = load i64, i64* %wideaddr ; Returns a poison value.
  2102. %cmp = icmp slt i32 %poison, 0 ; Returns a poison value.
  2103. br i1 %cmp, label %true, label %end ; Branch to either destination.
  2104. true:
  2105. store volatile i32 0, i32* @g ; This is control-dependent on %cmp, so
  2106. ; it has undefined behavior.
  2107. br label %end
  2108. end:
  2109. %p = phi i32 [ 0, %entry ], [ 1, %true ]
  2110. ; Both edges into this PHI are
  2111. ; control-dependent on %cmp, so this
  2112. ; always results in a poison value.
  2113. store volatile i32 0, i32* @g ; This would depend on the store in %true
  2114. ; if %cmp is true, or the store in %entry
  2115. ; otherwise, so this is undefined behavior.
  2116. br i1 %cmp, label %second_true, label %second_end
  2117. ; The same branch again, but this time the
  2118. ; true block doesn't have side effects.
  2119. second_true:
  2120. ; No side effects!
  2121. ret void
  2122. second_end:
  2123. store volatile i32 0, i32* @g ; This time, the instruction always depends
  2124. ; on the store in %end. Also, it is
  2125. ; control-equivalent to %end, so this is
  2126. ; well-defined (ignoring earlier undefined
  2127. ; behavior in this example).
  2128. .. _blockaddress:
  2129. Addresses of Basic Blocks
  2130. -------------------------
  2131. ``blockaddress(@function, %block)``
  2132. The '``blockaddress``' constant computes the address of the specified
  2133. basic block in the specified function, and always has an ``i8*`` type.
  2134. Taking the address of the entry block is illegal.
  2135. This value only has defined behavior when used as an operand to the
  2136. ':ref:`indirectbr <i_indirectbr>`' instruction, or for comparisons
  2137. against null. Pointer equality tests between labels addresses results in
  2138. undefined behavior --- though, again, comparison against null is ok, and
  2139. no label is equal to the null pointer. This may be passed around as an
  2140. opaque pointer sized value as long as the bits are not inspected. This
  2141. allows ``ptrtoint`` and arithmetic to be performed on these values so
  2142. long as the original value is reconstituted before the ``indirectbr``
  2143. instruction.
  2144. Finally, some targets may provide defined semantics when using the value
  2145. as the operand to an inline assembly, but that is target specific.
  2146. .. _constantexprs:
  2147. Constant Expressions
  2148. --------------------
  2149. Constant expressions are used to allow expressions involving other
  2150. constants to be used as constants. Constant expressions may be of any
  2151. :ref:`first class <t_firstclass>` type and may involve any LLVM operation
  2152. that does not have side effects (e.g. load and call are not supported).
  2153. The following is the syntax for constant expressions:
  2154. ``trunc (CST to TYPE)``
  2155. Truncate a constant to another type. The bit size of CST must be
  2156. larger than the bit size of TYPE. Both types must be integers.
  2157. ``zext (CST to TYPE)``
  2158. Zero extend a constant to another type. The bit size of CST must be
  2159. smaller than the bit size of TYPE. Both types must be integers.
  2160. ``sext (CST to TYPE)``
  2161. Sign extend a constant to another type. The bit size of CST must be
  2162. smaller than the bit size of TYPE. Both types must be integers.
  2163. ``fptrunc (CST to TYPE)``
  2164. Truncate a floating point constant to another floating point type.
  2165. The size of CST must be larger than the size of TYPE. Both types
  2166. must be floating point.
  2167. ``fpext (CST to TYPE)``
  2168. Floating point extend a constant to another type. The size of CST
  2169. must be smaller or equal to the size of TYPE. Both types must be
  2170. floating point.
  2171. ``fptoui (CST to TYPE)``
  2172. Convert a floating point constant to the corresponding unsigned
  2173. integer constant. TYPE must be a scalar or vector integer type. CST
  2174. must be of scalar or vector floating point type. Both CST and TYPE
  2175. must be scalars, or vectors of the same number of elements. If the
  2176. value won't fit in the integer type, the results are undefined.
  2177. ``fptosi (CST to TYPE)``
  2178. Convert a floating point constant to the corresponding signed
  2179. integer constant. TYPE must be a scalar or vector integer type. CST
  2180. must be of scalar or vector floating point type. Both CST and TYPE
  2181. must be scalars, or vectors of the same number of elements. If the
  2182. value won't fit in the integer type, the results are undefined.
  2183. ``uitofp (CST to TYPE)``
  2184. Convert an unsigned integer constant to the corresponding floating
  2185. point constant. TYPE must be a scalar or vector floating point type.
  2186. CST must be of scalar or vector integer type. Both CST and TYPE must
  2187. be scalars, or vectors of the same number of elements. If the value
  2188. won't fit in the floating point type, the results are undefined.
  2189. ``sitofp (CST to TYPE)``
  2190. Convert a signed integer constant to the corresponding floating
  2191. point constant. TYPE must be a scalar or vector floating point type.
  2192. CST must be of scalar or vector integer type. Both CST and TYPE must
  2193. be scalars, or vectors of the same number of elements. If the value
  2194. won't fit in the floating point type, the results are undefined.
  2195. ``ptrtoint (CST to TYPE)``
  2196. Convert a pointer typed constant to the corresponding integer
  2197. constant. ``TYPE`` must be an integer type. ``CST`` must be of
  2198. pointer type. The ``CST`` value is zero extended, truncated, or
  2199. unchanged to make it fit in ``TYPE``.
  2200. ``inttoptr (CST to TYPE)``
  2201. Convert an integer constant to a pointer constant. TYPE must be a
  2202. pointer type. CST must be of integer type. The CST value is zero
  2203. extended, truncated, or unchanged to make it fit in a pointer size.
  2204. This one is *really* dangerous!
  2205. ``bitcast (CST to TYPE)``
  2206. Convert a constant, CST, to another TYPE. The constraints of the
  2207. operands are the same as those for the :ref:`bitcast
  2208. instruction <i_bitcast>`.
  2209. ``addrspacecast (CST to TYPE)``
  2210. Convert a constant pointer or constant vector of pointer, CST, to another
  2211. TYPE in a different address space. The constraints of the operands are the
  2212. same as those for the :ref:`addrspacecast instruction <i_addrspacecast>`.
  2213. ``getelementptr (TY, CSTPTR, IDX0, IDX1, ...)``, ``getelementptr inbounds (TY, CSTPTR, IDX0, IDX1, ...)``
  2214. Perform the :ref:`getelementptr operation <i_getelementptr>` on
  2215. constants. As with the :ref:`getelementptr <i_getelementptr>`
  2216. instruction, the index list may have zero or more indexes, which are
  2217. required to make sense for the type of "pointer to TY".
  2218. ``select (COND, VAL1, VAL2)``
  2219. Perform the :ref:`select operation <i_select>` on constants.
  2220. ``icmp COND (VAL1, VAL2)``
  2221. Performs the :ref:`icmp operation <i_icmp>` on constants.
  2222. ``fcmp COND (VAL1, VAL2)``
  2223. Performs the :ref:`fcmp operation <i_fcmp>` on constants.
  2224. ``extractelement (VAL, IDX)``
  2225. Perform the :ref:`extractelement operation <i_extractelement>` on
  2226. constants.
  2227. ``insertelement (VAL, ELT, IDX)``
  2228. Perform the :ref:`insertelement operation <i_insertelement>` on
  2229. constants.
  2230. ``shufflevector (VEC1, VEC2, IDXMASK)``
  2231. Perform the :ref:`shufflevector operation <i_shufflevector>` on
  2232. constants.
  2233. ``extractvalue (VAL, IDX0, IDX1, ...)``
  2234. Perform the :ref:`extractvalue operation <i_extractvalue>` on
  2235. constants. The index list is interpreted in a similar manner as
  2236. indices in a ':ref:`getelementptr <i_getelementptr>`' operation. At
  2237. least one index value must be specified.
  2238. ``insertvalue (VAL, ELT, IDX0, IDX1, ...)``
  2239. Perform the :ref:`insertvalue operation <i_insertvalue>` on constants.
  2240. The index list is interpreted in a similar manner as indices in a
  2241. ':ref:`getelementptr <i_getelementptr>`' operation. At least one index
  2242. value must be specified.
  2243. ``OPCODE (LHS, RHS)``
  2244. Perform the specified operation of the LHS and RHS constants. OPCODE
  2245. may be any of the :ref:`binary <binaryops>` or :ref:`bitwise
  2246. binary <bitwiseops>` operations. The constraints on operands are
  2247. the same as those for the corresponding instruction (e.g. no bitwise
  2248. operations on floating point values are allowed).
  2249. Other Values
  2250. ============
  2251. .. _inlineasmexprs:
  2252. Inline Assembler Expressions
  2253. ----------------------------
  2254. LLVM supports inline assembler expressions (as opposed to :ref:`Module-Level
  2255. Inline Assembly <moduleasm>`) through the use of a special value. This value
  2256. represents the inline assembler as a template string (containing the
  2257. instructions to emit), a list of operand constraints (stored as a string), a
  2258. flag that indicates whether or not the inline asm expression has side effects,
  2259. and a flag indicating whether the function containing the asm needs to align its
  2260. stack conservatively.
  2261. The template string supports argument substitution of the operands using "``$``"
  2262. followed by a number, to indicate substitution of the given register/memory
  2263. location, as specified by the constraint string. "``${NUM:MODIFIER}``" may also
  2264. be used, where ``MODIFIER`` is a target-specific annotation for how to print the
  2265. operand (See :ref:`inline-asm-modifiers`).
  2266. A literal "``$``" may be included by using "``$$``" in the template. To include
  2267. other special characters into the output, the usual "``\XX``" escapes may be
  2268. used, just as in other strings. Note that after template substitution, the
  2269. resulting assembly string is parsed by LLVM's integrated assembler unless it is
  2270. disabled -- even when emitting a ``.s`` file -- and thus must contain assembly
  2271. syntax known to LLVM.
  2272. LLVM's support for inline asm is modeled closely on the requirements of Clang's
  2273. GCC-compatible inline-asm support. Thus, the feature-set and the constraint and
  2274. modifier codes listed here are similar or identical to those in GCC's inline asm
  2275. support. However, to be clear, the syntax of the template and constraint strings
  2276. described here is *not* the same as the syntax accepted by GCC and Clang, and,
  2277. while most constraint letters are passed through as-is by Clang, some get
  2278. translated to other codes when converting from the C source to the LLVM
  2279. assembly.
  2280. An example inline assembler expression is:
  2281. .. code-block:: llvm
  2282. i32 (i32) asm "bswap $0", "=r,r"
  2283. Inline assembler expressions may **only** be used as the callee operand
  2284. of a :ref:`call <i_call>` or an :ref:`invoke <i_invoke>` instruction.
  2285. Thus, typically we have:
  2286. .. code-block:: llvm
  2287. %X = call i32 asm "bswap $0", "=r,r"(i32 %Y)
  2288. Inline asms with side effects not visible in the constraint list must be
  2289. marked as having side effects. This is done through the use of the
  2290. '``sideeffect``' keyword, like so:
  2291. .. code-block:: llvm
  2292. call void asm sideeffect "eieio", ""()
  2293. In some cases inline asms will contain code that will not work unless
  2294. the stack is aligned in some way, such as calls or SSE instructions on
  2295. x86, yet will not contain code that does that alignment within the asm.
  2296. The compiler should make conservative assumptions about what the asm
  2297. might contain and should generate its usual stack alignment code in the
  2298. prologue if the '``alignstack``' keyword is present:
  2299. .. code-block:: llvm
  2300. call void asm alignstack "eieio", ""()
  2301. Inline asms also support using non-standard assembly dialects. The
  2302. assumed dialect is ATT. When the '``inteldialect``' keyword is present,
  2303. the inline asm is using the Intel dialect. Currently, ATT and Intel are
  2304. the only supported dialects. An example is:
  2305. .. code-block:: llvm
  2306. call void asm inteldialect "eieio", ""()
  2307. If multiple keywords appear the '``sideeffect``' keyword must come
  2308. first, the '``alignstack``' keyword second and the '``inteldialect``'
  2309. keyword last.
  2310. Inline Asm Constraint String
  2311. ^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  2312. The constraint list is a comma-separated string, each element containing one or
  2313. more constraint codes.
  2314. For each element in the constraint list an appropriate register or memory
  2315. operand will be chosen, and it will be made available to assembly template
  2316. string expansion as ``$0`` for the first constraint in the list, ``$1`` for the
  2317. second, etc.
  2318. There are three different types of constraints, which are distinguished by a
  2319. prefix symbol in front of the constraint code: Output, Input, and Clobber. The
  2320. constraints must always be given in that order: outputs first, then inputs, then
  2321. clobbers. They cannot be intermingled.
  2322. There are also three different categories of constraint codes:
  2323. - Register constraint. This is either a register class, or a fixed physical
  2324. register. This kind of constraint will allocate a register, and if necessary,
  2325. bitcast the argument or result to the appropriate type.
  2326. - Memory constraint. This kind of constraint is for use with an instruction
  2327. taking a memory operand. Different constraints allow for different addressing
  2328. modes used by the target.
  2329. - Immediate value constraint. This kind of constraint is for an integer or other
  2330. immediate value which can be rendered directly into an instruction. The
  2331. various target-specific constraints allow the selection of a value in the
  2332. proper range for the instruction you wish to use it with.
  2333. Output constraints
  2334. """"""""""""""""""
  2335. Output constraints are specified by an "``=``" prefix (e.g. "``=r``"). This
  2336. indicates that the assembly will write to this operand, and the operand will
  2337. then be made available as a return value of the ``asm`` expression. Output
  2338. constraints do not consume an argument from the call instruction. (Except, see
  2339. below about indirect outputs).
  2340. Normally, it is expected that no output locations are written to by the assembly
  2341. expression until *all* of the inputs have been read. As such, LLVM may assign
  2342. the same register to an output and an input. If this is not safe (e.g. if the
  2343. assembly contains two instructions, where the first writes to one output, and
  2344. the second reads an input and writes to a second output), then the "``&``"
  2345. modifier must be used (e.g. "``=&r``") to specify that the output is an
  2346. "early-clobber" output. Marking an ouput as "early-clobber" ensures that LLVM
  2347. will not use the same register for any inputs (other than an input tied to this
  2348. output).
  2349. Input constraints
  2350. """""""""""""""""
  2351. Input constraints do not have a prefix -- just the constraint codes. Each input
  2352. constraint will consume one argument from the call instruction. It is not
  2353. permitted for the asm to write to any input register or memory location (unless
  2354. that input is tied to an output). Note also that multiple inputs may all be
  2355. assigned to the same register, if LLVM can determine that they necessarily all
  2356. contain the same value.
  2357. Instead of providing a Constraint Code, input constraints may also "tie"
  2358. themselves to an output constraint, by providing an integer as the constraint
  2359. string. Tied inputs still consume an argument from the call instruction, and
  2360. take up a position in the asm template numbering as is usual -- they will simply
  2361. be constrained to always use the same register as the output they've been tied
  2362. to. For example, a constraint string of "``=r,0``" says to assign a register for
  2363. output, and use that register as an input as well (it being the 0'th
  2364. constraint).
  2365. It is permitted to tie an input to an "early-clobber" output. In that case, no
  2366. *other* input may share the same register as the input tied to the early-clobber
  2367. (even when the other input has the same value).
  2368. You may only tie an input to an output which has a register constraint, not a
  2369. memory constraint. Only a single input may be tied to an output.
  2370. There is also an "interesting" feature which deserves a bit of explanation: if a
  2371. register class constraint allocates a register which is too small for the value
  2372. type operand provided as input, the input value will be split into multiple
  2373. registers, and all of them passed to the inline asm.
  2374. However, this feature is often not as useful as you might think.
  2375. Firstly, the registers are *not* guaranteed to be consecutive. So, on those
  2376. architectures that have instructions which operate on multiple consecutive
  2377. instructions, this is not an appropriate way to support them. (e.g. the 32-bit
  2378. SparcV8 has a 64-bit load, which instruction takes a single 32-bit register. The
  2379. hardware then loads into both the named register, and the next register. This
  2380. feature of inline asm would not be useful to support that.)
  2381. A few of the targets provide a template string modifier allowing explicit access
  2382. to the second register of a two-register operand (e.g. MIPS ``L``, ``M``, and
  2383. ``D``). On such an architecture, you can actually access the second allocated
  2384. register (yet, still, not any subsequent ones). But, in that case, you're still
  2385. probably better off simply splitting the value into two separate operands, for
  2386. clarity. (e.g. see the description of the ``A`` constraint on X86, which,
  2387. despite existing only for use with this feature, is not really a good idea to
  2388. use)
  2389. Indirect inputs and outputs
  2390. """""""""""""""""""""""""""
  2391. Indirect output or input constraints can be specified by the "``*``" modifier
  2392. (which goes after the "``=``" in case of an output). This indicates that the asm
  2393. will write to or read from the contents of an *address* provided as an input
  2394. argument. (Note that in this way, indirect outputs act more like an *input* than
  2395. an output: just like an input, they consume an argument of the call expression,
  2396. rather than producing a return value. An indirect output constraint is an
  2397. "output" only in that the asm is expected to write to the contents of the input
  2398. memory location, instead of just read from it).
  2399. This is most typically used for memory constraint, e.g. "``=*m``", to pass the
  2400. address of a variable as a value.
  2401. It is also possible to use an indirect *register* constraint, but only on output
  2402. (e.g. "``=*r``"). This will cause LLVM to allocate a register for an output
  2403. value normally, and then, separately emit a store to the address provided as
  2404. input, after the provided inline asm. (It's not clear what value this
  2405. functionality provides, compared to writing the store explicitly after the asm
  2406. statement, and it can only produce worse code, since it bypasses many
  2407. optimization passes. I would recommend not using it.)
  2408. Clobber constraints
  2409. """""""""""""""""""
  2410. A clobber constraint is indicated by a "``~``" prefix. A clobber does not
  2411. consume an input operand, nor generate an output. Clobbers cannot use any of the
  2412. general constraint code letters -- they may use only explicit register
  2413. constraints, e.g. "``~{eax}``". The one exception is that a clobber string of
  2414. "``~{memory}``" indicates that the assembly writes to arbitrary undeclared
  2415. memory locations -- not only the memory pointed to by a declared indirect
  2416. output.
  2417. Constraint Codes
  2418. """"""""""""""""
  2419. After a potential prefix comes constraint code, or codes.
  2420. A Constraint Code is either a single letter (e.g. "``r``"), a "``^``" character
  2421. followed by two letters (e.g. "``^wc``"), or "``{``" register-name "``}``"
  2422. (e.g. "``{eax}``").
  2423. The one and two letter constraint codes are typically chosen to be the same as
  2424. GCC's constraint codes.
  2425. A single constraint may include one or more than constraint code in it, leaving
  2426. it up to LLVM to choose which one to use. This is included mainly for
  2427. compatibility with the translation of GCC inline asm coming from clang.
  2428. There are two ways to specify alternatives, and either or both may be used in an
  2429. inline asm constraint list:
  2430. 1) Append the codes to each other, making a constraint code set. E.g. "``im``"
  2431. or "``{eax}m``". This means "choose any of the options in the set". The
  2432. choice of constraint is made independently for each constraint in the
  2433. constraint list.
  2434. 2) Use "``|``" between constraint code sets, creating alternatives. Every
  2435. constraint in the constraint list must have the same number of alternative
  2436. sets. With this syntax, the same alternative in *all* of the items in the
  2437. constraint list will be chosen together.
  2438. Putting those together, you might have a two operand constraint string like
  2439. ``"rm|r,ri|rm"``. This indicates that if operand 0 is ``r`` or ``m``, then
  2440. operand 1 may be one of ``r`` or ``i``. If operand 0 is ``r``, then operand 1
  2441. may be one of ``r`` or ``m``. But, operand 0 and 1 cannot both be of type m.
  2442. However, the use of either of the alternatives features is *NOT* recommended, as
  2443. LLVM is not able to make an intelligent choice about which one to use. (At the
  2444. point it currently needs to choose, not enough information is available to do so
  2445. in a smart way.) Thus, it simply tries to make a choice that's most likely to
  2446. compile, not one that will be optimal performance. (e.g., given "``rm``", it'll
  2447. always choose to use memory, not registers). And, if given multiple registers,
  2448. or multiple register classes, it will simply choose the first one. (In fact, it
  2449. doesn't currently even ensure explicitly specified physical registers are
  2450. unique, so specifying multiple physical registers as alternatives, like
  2451. ``{r11}{r12},{r11}{r12}``, will assign r11 to both operands, not at all what was
  2452. intended.)
  2453. Supported Constraint Code List
  2454. """"""""""""""""""""""""""""""
  2455. The constraint codes are, in general, expected to behave the same way they do in
  2456. GCC. LLVM's support is often implemented on an 'as-needed' basis, to support C
  2457. inline asm code which was supported by GCC. A mismatch in behavior between LLVM
  2458. and GCC likely indicates a bug in LLVM.
  2459. Some constraint codes are typically supported by all targets:
  2460. - ``r``: A register in the target's general purpose register class.
  2461. - ``m``: A memory address operand. It is target-specific what addressing modes
  2462. are supported, typical examples are register, or register + register offset,
  2463. or register + immediate offset (of some target-specific size).
  2464. - ``i``: An integer constant (of target-specific width). Allows either a simple
  2465. immediate, or a relocatable value.
  2466. - ``n``: An integer constant -- *not* including relocatable values.
  2467. - ``s``: An integer constant, but allowing *only* relocatable values.
  2468. - ``X``: Allows an operand of any kind, no constraint whatsoever. Typically
  2469. useful to pass a label for an asm branch or call.
  2470. .. FIXME: but that surely isn't actually okay to jump out of an asm
  2471. block without telling llvm about the control transfer???)
  2472. - ``{register-name}``: Requires exactly the named physical register.
  2473. Other constraints are target-specific:
  2474. AArch64:
  2475. - ``z``: An immediate integer 0. Outputs ``WZR`` or ``XZR``, as appropriate.
  2476. - ``I``: An immediate integer valid for an ``ADD`` or ``SUB`` instruction,
  2477. i.e. 0 to 4095 with optional shift by 12.
  2478. - ``J``: An immediate integer that, when negated, is valid for an ``ADD`` or
  2479. ``SUB`` instruction, i.e. -1 to -4095 with optional left shift by 12.
  2480. - ``K``: An immediate integer that is valid for the 'bitmask immediate 32' of a
  2481. logical instruction like ``AND``, ``EOR``, or ``ORR`` with a 32-bit register.
  2482. - ``L``: An immediate integer that is valid for the 'bitmask immediate 64' of a
  2483. logical instruction like ``AND``, ``EOR``, or ``ORR`` with a 64-bit register.
  2484. - ``M``: An immediate integer for use with the ``MOV`` assembly alias on a
  2485. 32-bit register. This is a superset of ``K``: in addition to the bitmask
  2486. immediate, also allows immediate integers which can be loaded with a single
  2487. ``MOVZ`` or ``MOVL`` instruction.
  2488. - ``N``: An immediate integer for use with the ``MOV`` assembly alias on a
  2489. 64-bit register. This is a superset of ``L``.
  2490. - ``Q``: Memory address operand must be in a single register (no
  2491. offsets). (However, LLVM currently does this for the ``m`` constraint as
  2492. well.)
  2493. - ``r``: A 32 or 64-bit integer register (W* or X*).
  2494. - ``w``: A 32, 64, or 128-bit floating-point/SIMD register.
  2495. - ``x``: A lower 128-bit floating-point/SIMD register (``V0`` to ``V15``).
  2496. AMDGPU:
  2497. - ``r``: A 32 or 64-bit integer register.
  2498. - ``[0-9]v``: The 32-bit VGPR register, number 0-9.
  2499. - ``[0-9]s``: The 32-bit SGPR register, number 0-9.
  2500. All ARM modes:
  2501. - ``Q``, ``Um``, ``Un``, ``Uq``, ``Us``, ``Ut``, ``Uv``, ``Uy``: Memory address
  2502. operand. Treated the same as operand ``m``, at the moment.
  2503. ARM and ARM's Thumb2 mode:
  2504. - ``j``: An immediate integer between 0 and 65535 (valid for ``MOVW``)
  2505. - ``I``: An immediate integer valid for a data-processing instruction.
  2506. - ``J``: An immediate integer between -4095 and 4095.
  2507. - ``K``: An immediate integer whose bitwise inverse is valid for a
  2508. data-processing instruction. (Can be used with template modifier "``B``" to
  2509. print the inverted value).
  2510. - ``L``: An immediate integer whose negation is valid for a data-processing
  2511. instruction. (Can be used with template modifier "``n``" to print the negated
  2512. value).
  2513. - ``M``: A power of two or a integer between 0 and 32.
  2514. - ``N``: Invalid immediate constraint.
  2515. - ``O``: Invalid immediate constraint.
  2516. - ``r``: A general-purpose 32-bit integer register (``r0-r15``).
  2517. - ``l``: In Thumb2 mode, low 32-bit GPR registers (``r0-r7``). In ARM mode, same
  2518. as ``r``.
  2519. - ``h``: In Thumb2 mode, a high 32-bit GPR register (``r8-r15``). In ARM mode,
  2520. invalid.
  2521. - ``w``: A 32, 64, or 128-bit floating-point/SIMD register: ``s0-s31``,
  2522. ``d0-d31``, or ``q0-q15``.
  2523. - ``x``: A 32, 64, or 128-bit floating-point/SIMD register: ``s0-s15``,
  2524. ``d0-d7``, or ``q0-q3``.
  2525. - ``t``: A floating-point/SIMD register, only supports 32-bit values:
  2526. ``s0-s31``.
  2527. ARM's Thumb1 mode:
  2528. - ``I``: An immediate integer between 0 and 255.
  2529. - ``J``: An immediate integer between -255 and -1.
  2530. - ``K``: An immediate integer between 0 and 255, with optional left-shift by
  2531. some amount.
  2532. - ``L``: An immediate integer between -7 and 7.
  2533. - ``M``: An immediate integer which is a multiple of 4 between 0 and 1020.
  2534. - ``N``: An immediate integer between 0 and 31.
  2535. - ``O``: An immediate integer which is a multiple of 4 between -508 and 508.
  2536. - ``r``: A low 32-bit GPR register (``r0-r7``).
  2537. - ``l``: A low 32-bit GPR register (``r0-r7``).
  2538. - ``h``: A high GPR register (``r0-r7``).
  2539. - ``w``: A 32, 64, or 128-bit floating-point/SIMD register: ``s0-s31``,
  2540. ``d0-d31``, or ``q0-q15``.
  2541. - ``x``: A 32, 64, or 128-bit floating-point/SIMD register: ``s0-s15``,
  2542. ``d0-d7``, or ``q0-q3``.
  2543. - ``t``: A floating-point/SIMD register, only supports 32-bit values:
  2544. ``s0-s31``.
  2545. Hexagon:
  2546. - ``o``, ``v``: A memory address operand, treated the same as constraint ``m``,
  2547. at the moment.
  2548. - ``r``: A 32 or 64-bit register.
  2549. MSP430:
  2550. - ``r``: An 8 or 16-bit register.
  2551. MIPS:
  2552. - ``I``: An immediate signed 16-bit integer.
  2553. - ``J``: An immediate integer zero.
  2554. - ``K``: An immediate unsigned 16-bit integer.
  2555. - ``L``: An immediate 32-bit integer, where the lower 16 bits are 0.
  2556. - ``N``: An immediate integer between -65535 and -1.
  2557. - ``O``: An immediate signed 15-bit integer.
  2558. - ``P``: An immediate integer between 1 and 65535.
  2559. - ``m``: A memory address operand. In MIPS-SE mode, allows a base address
  2560. register plus 16-bit immediate offset. In MIPS mode, just a base register.
  2561. - ``R``: A memory address operand. In MIPS-SE mode, allows a base address
  2562. register plus a 9-bit signed offset. In MIPS mode, the same as constraint
  2563. ``m``.
  2564. - ``ZC``: A memory address operand, suitable for use in a ``pref``, ``ll``, or
  2565. ``sc`` instruction on the given subtarget (details vary).
  2566. - ``r``, ``d``, ``y``: A 32 or 64-bit GPR register.
  2567. - ``f``: A 32 or 64-bit FPU register (``F0-F31``), or a 128-bit MSA register
  2568. (``W0-W31``). In the case of MSA registers, it is recommended to use the ``w``
  2569. argument modifier for compatibility with GCC.
  2570. - ``c``: A 32-bit or 64-bit GPR register suitable for indirect jump (always
  2571. ``25``).
  2572. - ``l``: The ``lo`` register, 32 or 64-bit.
  2573. - ``x``: Invalid.
  2574. NVPTX:
  2575. - ``b``: A 1-bit integer register.
  2576. - ``c`` or ``h``: A 16-bit integer register.
  2577. - ``r``: A 32-bit integer register.
  2578. - ``l`` or ``N``: A 64-bit integer register.
  2579. - ``f``: A 32-bit float register.
  2580. - ``d``: A 64-bit float register.
  2581. PowerPC:
  2582. - ``I``: An immediate signed 16-bit integer.
  2583. - ``J``: An immediate unsigned 16-bit integer, shifted left 16 bits.
  2584. - ``K``: An immediate unsigned 16-bit integer.
  2585. - ``L``: An immediate signed 16-bit integer, shifted left 16 bits.
  2586. - ``M``: An immediate integer greater than 31.
  2587. - ``N``: An immediate integer that is an exact power of 2.
  2588. - ``O``: The immediate integer constant 0.
  2589. - ``P``: An immediate integer constant whose negation is a signed 16-bit
  2590. constant.
  2591. - ``es``, ``o``, ``Q``, ``Z``, ``Zy``: A memory address operand, currently
  2592. treated the same as ``m``.
  2593. - ``r``: A 32 or 64-bit integer register.
  2594. - ``b``: A 32 or 64-bit integer register, excluding ``R0`` (that is:
  2595. ``R1-R31``).
  2596. - ``f``: A 32 or 64-bit float register (``F0-F31``), or when QPX is enabled, a
  2597. 128 or 256-bit QPX register (``Q0-Q31``; aliases the ``F`` registers).
  2598. - ``v``: For ``4 x f32`` or ``4 x f64`` types, when QPX is enabled, a
  2599. 128 or 256-bit QPX register (``Q0-Q31``), otherwise a 128-bit
  2600. altivec vector register (``V0-V31``).
  2601. .. FIXME: is this a bug that v accepts QPX registers? I think this
  2602. is supposed to only use the altivec vector registers?
  2603. - ``y``: Condition register (``CR0-CR7``).
  2604. - ``wc``: An individual CR bit in a CR register.
  2605. - ``wa``, ``wd``, ``wf``: Any 128-bit VSX vector register, from the full VSX
  2606. register set (overlapping both the floating-point and vector register files).
  2607. - ``ws``: A 32 or 64-bit floating point register, from the full VSX register
  2608. set.
  2609. Sparc:
  2610. - ``I``: An immediate 13-bit signed integer.
  2611. - ``r``: A 32-bit integer register.
  2612. SystemZ:
  2613. - ``I``: An immediate unsigned 8-bit integer.
  2614. - ``J``: An immediate unsigned 12-bit integer.
  2615. - ``K``: An immediate signed 16-bit integer.
  2616. - ``L``: An immediate signed 20-bit integer.
  2617. - ``M``: An immediate integer 0x7fffffff.
  2618. - ``Q``, ``R``, ``S``, ``T``: A memory address operand, treated the same as
  2619. ``m``, at the moment.
  2620. - ``r`` or ``d``: A 32, 64, or 128-bit integer register.
  2621. - ``a``: A 32, 64, or 128-bit integer address register (excludes R0, which in an
  2622. address context evaluates as zero).
  2623. - ``h``: A 32-bit value in the high part of a 64bit data register
  2624. (LLVM-specific)
  2625. - ``f``: A 32, 64, or 128-bit floating point register.
  2626. X86:
  2627. - ``I``: An immediate integer between 0 and 31.
  2628. - ``J``: An immediate integer between 0 and 64.
  2629. - ``K``: An immediate signed 8-bit integer.
  2630. - ``L``: An immediate integer, 0xff or 0xffff or (in 64-bit mode only)
  2631. 0xffffffff.
  2632. - ``M``: An immediate integer between 0 and 3.
  2633. - ``N``: An immediate unsigned 8-bit integer.
  2634. - ``O``: An immediate integer between 0 and 127.
  2635. - ``e``: An immediate 32-bit signed integer.
  2636. - ``Z``: An immediate 32-bit unsigned integer.
  2637. - ``o``, ``v``: Treated the same as ``m``, at the moment.
  2638. - ``q``: An 8, 16, 32, or 64-bit register which can be accessed as an 8-bit
  2639. ``l`` integer register. On X86-32, this is the ``a``, ``b``, ``c``, and ``d``
  2640. registers, and on X86-64, it is all of the integer registers.
  2641. - ``Q``: An 8, 16, 32, or 64-bit register which can be accessed as an 8-bit
  2642. ``h`` integer register. This is the ``a``, ``b``, ``c``, and ``d`` registers.
  2643. - ``r`` or ``l``: An 8, 16, 32, or 64-bit integer register.
  2644. - ``R``: An 8, 16, 32, or 64-bit "legacy" integer register -- one which has
  2645. existed since i386, and can be accessed without the REX prefix.
  2646. - ``f``: A 32, 64, or 80-bit '387 FPU stack pseudo-register.
  2647. - ``y``: A 64-bit MMX register, if MMX is enabled.
  2648. - ``x``: If SSE is enabled: a 32 or 64-bit scalar operand, or 128-bit vector
  2649. operand in a SSE register. If AVX is also enabled, can also be a 256-bit
  2650. vector operand in an AVX register. If AVX-512 is also enabled, can also be a
  2651. 512-bit vector operand in an AVX512 register, Otherwise, an error.
  2652. - ``Y``: The same as ``x``, if *SSE2* is enabled, otherwise an error.
  2653. - ``A``: Special case: allocates EAX first, then EDX, for a single operand (in
  2654. 32-bit mode, a 64-bit integer operand will get split into two registers). It
  2655. is not recommended to use this constraint, as in 64-bit mode, the 64-bit
  2656. operand will get allocated only to RAX -- if two 32-bit operands are needed,
  2657. you're better off splitting it yourself, before passing it to the asm
  2658. statement.
  2659. XCore:
  2660. - ``r``: A 32-bit integer register.
  2661. .. _inline-asm-modifiers:
  2662. Asm template argument modifiers
  2663. ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  2664. In the asm template string, modifiers can be used on the operand reference, like
  2665. "``${0:n}``".
  2666. The modifiers are, in general, expected to behave the same way they do in
  2667. GCC. LLVM's support is often implemented on an 'as-needed' basis, to support C
  2668. inline asm code which was supported by GCC. A mismatch in behavior between LLVM
  2669. and GCC likely indicates a bug in LLVM.
  2670. Target-independent:
  2671. - ``c``: Print an immediate integer constant unadorned, without
  2672. the target-specific immediate punctuation (e.g. no ``$`` prefix).
  2673. - ``n``: Negate and print immediate integer constant unadorned, without the
  2674. target-specific immediate punctuation (e.g. no ``$`` prefix).
  2675. - ``l``: Print as an unadorned label, without the target-specific label
  2676. punctuation (e.g. no ``$`` prefix).
  2677. AArch64:
  2678. - ``w``: Print a GPR register with a ``w*`` name instead of ``x*`` name. E.g.,
  2679. instead of ``x30``, print ``w30``.
  2680. - ``x``: Print a GPR register with a ``x*`` name. (this is the default, anyhow).
  2681. - ``b``, ``h``, ``s``, ``d``, ``q``: Print a floating-point/SIMD register with a
  2682. ``b*``, ``h*``, ``s*``, ``d*``, or ``q*`` name, rather than the default of
  2683. ``v*``.
  2684. AMDGPU:
  2685. - ``r``: No effect.
  2686. ARM:
  2687. - ``a``: Print an operand as an address (with ``[`` and ``]`` surrounding a
  2688. register).
  2689. - ``P``: No effect.
  2690. - ``q``: No effect.
  2691. - ``y``: Print a VFP single-precision register as an indexed double (e.g. print
  2692. as ``d4[1]`` instead of ``s9``)
  2693. - ``B``: Bitwise invert and print an immediate integer constant without ``#``
  2694. prefix.
  2695. - ``L``: Print the low 16-bits of an immediate integer constant.
  2696. - ``M``: Print as a register set suitable for ldm/stm. Also prints *all*
  2697. register operands subsequent to the specified one (!), so use carefully.
  2698. - ``Q``: Print the low-order register of a register-pair, or the low-order
  2699. register of a two-register operand.
  2700. - ``R``: Print the high-order register of a register-pair, or the high-order
  2701. register of a two-register operand.
  2702. - ``H``: Print the second register of a register-pair. (On a big-endian system,
  2703. ``H`` is equivalent to ``Q``, and on little-endian system, ``H`` is equivalent
  2704. to ``R``.)
  2705. .. FIXME: H doesn't currently support printing the second register
  2706. of a two-register operand.
  2707. - ``e``: Print the low doubleword register of a NEON quad register.
  2708. - ``f``: Print the high doubleword register of a NEON quad register.
  2709. - ``m``: Print the base register of a memory operand without the ``[`` and ``]``
  2710. adornment.
  2711. Hexagon:
  2712. - ``L``: Print the second register of a two-register operand. Requires that it
  2713. has been allocated consecutively to the first.
  2714. .. FIXME: why is it restricted to consecutive ones? And there's
  2715. nothing that ensures that happens, is there?
  2716. - ``I``: Print the letter 'i' if the operand is an integer constant, otherwise
  2717. nothing. Used to print 'addi' vs 'add' instructions.
  2718. MSP430:
  2719. No additional modifiers.
  2720. MIPS:
  2721. - ``X``: Print an immediate integer as hexadecimal
  2722. - ``x``: Print the low 16 bits of an immediate integer as hexadecimal.
  2723. - ``d``: Print an immediate integer as decimal.
  2724. - ``m``: Subtract one and print an immediate integer as decimal.
  2725. - ``z``: Print $0 if an immediate zero, otherwise print normally.
  2726. - ``L``: Print the low-order register of a two-register operand, or prints the
  2727. address of the low-order word of a double-word memory operand.
  2728. .. FIXME: L seems to be missing memory operand support.
  2729. - ``M``: Print the high-order register of a two-register operand, or prints the
  2730. address of the high-order word of a double-word memory operand.
  2731. .. FIXME: M seems to be missing memory operand support.
  2732. - ``D``: Print the second register of a two-register operand, or prints the
  2733. second word of a double-word memory operand. (On a big-endian system, ``D`` is
  2734. equivalent to ``L``, and on little-endian system, ``D`` is equivalent to
  2735. ``M``.)
  2736. - ``w``: No effect. Provided for compatibility with GCC which requires this
  2737. modifier in order to print MSA registers (``W0-W31``) with the ``f``
  2738. constraint.
  2739. NVPTX:
  2740. - ``r``: No effect.
  2741. PowerPC:
  2742. - ``L``: Print the second register of a two-register operand. Requires that it
  2743. has been allocated consecutively to the first.
  2744. .. FIXME: why is it restricted to consecutive ones? And there's
  2745. nothing that ensures that happens, is there?
  2746. - ``I``: Print the letter 'i' if the operand is an integer constant, otherwise
  2747. nothing. Used to print 'addi' vs 'add' instructions.
  2748. - ``y``: For a memory operand, prints formatter for a two-register X-form
  2749. instruction. (Currently always prints ``r0,OPERAND``).
  2750. - ``U``: Prints 'u' if the memory operand is an update form, and nothing
  2751. otherwise. (NOTE: LLVM does not support update form, so this will currently
  2752. always print nothing)
  2753. - ``X``: Prints 'x' if the memory operand is an indexed form. (NOTE: LLVM does
  2754. not support indexed form, so this will currently always print nothing)
  2755. Sparc:
  2756. - ``r``: No effect.
  2757. SystemZ:
  2758. SystemZ implements only ``n``, and does *not* support any of the other
  2759. target-independent modifiers.
  2760. X86:
  2761. - ``c``: Print an unadorned integer or symbol name. (The latter is
  2762. target-specific behavior for this typically target-independent modifier).
  2763. - ``A``: Print a register name with a '``*``' before it.
  2764. - ``b``: Print an 8-bit register name (e.g. ``al``); do nothing on a memory
  2765. operand.
  2766. - ``h``: Print the upper 8-bit register name (e.g. ``ah``); do nothing on a
  2767. memory operand.
  2768. - ``w``: Print the 16-bit register name (e.g. ``ax``); do nothing on a memory
  2769. operand.
  2770. - ``k``: Print the 32-bit register name (e.g. ``eax``); do nothing on a memory
  2771. operand.
  2772. - ``q``: Print the 64-bit register name (e.g. ``rax``), if 64-bit registers are
  2773. available, otherwise the 32-bit register name; do nothing on a memory operand.
  2774. - ``n``: Negate and print an unadorned integer, or, for operands other than an
  2775. immediate integer (e.g. a relocatable symbol expression), print a '-' before
  2776. the operand. (The behavior for relocatable symbol expressions is a
  2777. target-specific behavior for this typically target-independent modifier)
  2778. - ``H``: Print a memory reference with additional offset +8.
  2779. - ``P``: Print a memory reference or operand for use as the argument of a call
  2780. instruction. (E.g. omit ``(rip)``, even though it's PC-relative.)
  2781. XCore:
  2782. No additional modifiers.
  2783. Inline Asm Metadata
  2784. ^^^^^^^^^^^^^^^^^^^
  2785. The call instructions that wrap inline asm nodes may have a
  2786. "``!srcloc``" MDNode attached to it that contains a list of constant
  2787. integers. If present, the code generator will use the integer as the
  2788. location cookie value when report errors through the ``LLVMContext``
  2789. error reporting mechanisms. This allows a front-end to correlate backend
  2790. errors that occur with inline asm back to the source code that produced
  2791. it. For example:
  2792. .. code-block:: llvm
  2793. call void asm sideeffect "something bad", ""(), !srcloc !42
  2794. ...
  2795. !42 = !{ i32 1234567 }
  2796. It is up to the front-end to make sense of the magic numbers it places
  2797. in the IR. If the MDNode contains multiple constants, the code generator
  2798. will use the one that corresponds to the line of the asm that the error
  2799. occurs on.
  2800. .. _metadata:
  2801. Metadata
  2802. ========
  2803. LLVM IR allows metadata to be attached to instructions in the program
  2804. that can convey extra information about the code to the optimizers and
  2805. code generator. One example application of metadata is source-level
  2806. debug information. There are two metadata primitives: strings and nodes.
  2807. Metadata does not have a type, and is not a value. If referenced from a
  2808. ``call`` instruction, it uses the ``metadata`` type.
  2809. All metadata are identified in syntax by a exclamation point ('``!``').
  2810. .. _metadata-string:
  2811. Metadata Nodes and Metadata Strings
  2812. -----------------------------------
  2813. A metadata string is a string surrounded by double quotes. It can
  2814. contain any character by escaping non-printable characters with
  2815. "``\xx``" where "``xx``" is the two digit hex code. For example:
  2816. "``!"test\00"``".
  2817. Metadata nodes are represented with notation similar to structure
  2818. constants (a comma separated list of elements, surrounded by braces and
  2819. preceded by an exclamation point). Metadata nodes can have any values as
  2820. their operand. For example:
  2821. .. code-block:: llvm
  2822. !{ !"test\00", i32 10}
  2823. Metadata nodes that aren't uniqued use the ``distinct`` keyword. For example:
  2824. .. code-block:: llvm
  2825. !0 = distinct !{!"test\00", i32 10}
  2826. ``distinct`` nodes are useful when nodes shouldn't be merged based on their
  2827. content. They can also occur when transformations cause uniquing collisions
  2828. when metadata operands change.
  2829. A :ref:`named metadata <namedmetadatastructure>` is a collection of
  2830. metadata nodes, which can be looked up in the module symbol table. For
  2831. example:
  2832. .. code-block:: llvm
  2833. !foo = !{!4, !3}
  2834. Metadata can be used as function arguments. Here ``llvm.dbg.value``
  2835. function is using two metadata arguments:
  2836. .. code-block:: llvm
  2837. call void @llvm.dbg.value(metadata !24, i64 0, metadata !25)
  2838. Metadata can be attached with an instruction. Here metadata ``!21`` is
  2839. attached to the ``add`` instruction using the ``!dbg`` identifier:
  2840. .. code-block:: llvm
  2841. %indvar.next = add i64 %indvar, 1, !dbg !21
  2842. More information about specific metadata nodes recognized by the
  2843. optimizers and code generator is found below.
  2844. .. _specialized-metadata:
  2845. Specialized Metadata Nodes
  2846. ^^^^^^^^^^^^^^^^^^^^^^^^^^
  2847. Specialized metadata nodes are custom data structures in metadata (as opposed
  2848. to generic tuples). Their fields are labelled, and can be specified in any
  2849. order.
  2850. These aren't inherently debug info centric, but currently all the specialized
  2851. metadata nodes are related to debug info.
  2852. .. _DICompileUnit:
  2853. DICompileUnit
  2854. """""""""""""
  2855. ``DICompileUnit`` nodes represent a compile unit. The ``enums:``,
  2856. ``retainedTypes:``, ``subprograms:``, ``globals:`` and ``imports:`` fields are
  2857. tuples containing the debug info to be emitted along with the compile unit,
  2858. regardless of code optimizations (some nodes are only emitted if there are
  2859. references to them from instructions).
  2860. .. code-block:: llvm
  2861. !0 = !DICompileUnit(language: DW_LANG_C99, file: !1, producer: "clang",
  2862. isOptimized: true, flags: "-O2", runtimeVersion: 2,
  2863. splitDebugFilename: "abc.debug", emissionKind: 1,
  2864. enums: !2, retainedTypes: !3, subprograms: !4,
  2865. globals: !5, imports: !6)
  2866. Compile unit descriptors provide the root scope for objects declared in a
  2867. specific compilation unit. File descriptors are defined using this scope.
  2868. These descriptors are collected by a named metadata ``!llvm.dbg.cu``. They
  2869. keep track of subprograms, global variables, type information, and imported
  2870. entities (declarations and namespaces).
  2871. .. _DIFile:
  2872. DIFile
  2873. """"""
  2874. ``DIFile`` nodes represent files. The ``filename:`` can include slashes.
  2875. .. code-block:: llvm
  2876. !0 = !DIFile(filename: "path/to/file", directory: "/path/to/dir")
  2877. Files are sometimes used in ``scope:`` fields, and are the only valid target
  2878. for ``file:`` fields.
  2879. .. _DIBasicType:
  2880. DIBasicType
  2881. """""""""""
  2882. ``DIBasicType`` nodes represent primitive types, such as ``int``, ``bool`` and
  2883. ``float``. ``tag:`` defaults to ``DW_TAG_base_type``.
  2884. .. code-block:: llvm
  2885. !0 = !DIBasicType(name: "unsigned char", size: 8, align: 8,
  2886. encoding: DW_ATE_unsigned_char)
  2887. !1 = !DIBasicType(tag: DW_TAG_unspecified_type, name: "decltype(nullptr)")
  2888. The ``encoding:`` describes the details of the type. Usually it's one of the
  2889. following:
  2890. .. code-block:: llvm
  2891. DW_ATE_address = 1
  2892. DW_ATE_boolean = 2
  2893. DW_ATE_float = 4
  2894. DW_ATE_signed = 5
  2895. DW_ATE_signed_char = 6
  2896. DW_ATE_unsigned = 7
  2897. DW_ATE_unsigned_char = 8
  2898. .. _DISubroutineType:
  2899. DISubroutineType
  2900. """"""""""""""""
  2901. ``DISubroutineType`` nodes represent subroutine types. Their ``types:`` field
  2902. refers to a tuple; the first operand is the return type, while the rest are the
  2903. types of the formal arguments in order. If the first operand is ``null``, that
  2904. represents a function with no return value (such as ``void foo() {}`` in C++).
  2905. .. code-block:: llvm
  2906. !0 = !BasicType(name: "int", size: 32, align: 32, DW_ATE_signed)
  2907. !1 = !BasicType(name: "char", size: 8, align: 8, DW_ATE_signed_char)
  2908. !2 = !DISubroutineType(types: !{null, !0, !1}) ; void (int, char)
  2909. .. _DIDerivedType:
  2910. DIDerivedType
  2911. """""""""""""
  2912. ``DIDerivedType`` nodes represent types derived from other types, such as
  2913. qualified types.
  2914. .. code-block:: llvm
  2915. !0 = !DIBasicType(name: "unsigned char", size: 8, align: 8,
  2916. encoding: DW_ATE_unsigned_char)
  2917. !1 = !DIDerivedType(tag: DW_TAG_pointer_type, baseType: !0, size: 32,
  2918. align: 32)
  2919. The following ``tag:`` values are valid:
  2920. .. code-block:: llvm
  2921. DW_TAG_formal_parameter = 5
  2922. DW_TAG_member = 13
  2923. DW_TAG_pointer_type = 15
  2924. DW_TAG_reference_type = 16
  2925. DW_TAG_typedef = 22
  2926. DW_TAG_ptr_to_member_type = 31
  2927. DW_TAG_const_type = 38
  2928. DW_TAG_volatile_type = 53
  2929. DW_TAG_restrict_type = 55
  2930. ``DW_TAG_member`` is used to define a member of a :ref:`composite type
  2931. <DICompositeType>` or :ref:`subprogram <DISubprogram>`. The type of the member
  2932. is the ``baseType:``. The ``offset:`` is the member's bit offset.
  2933. ``DW_TAG_formal_parameter`` is used to define a member which is a formal
  2934. argument of a subprogram.
  2935. ``DW_TAG_typedef`` is used to provide a name for the ``baseType:``.
  2936. ``DW_TAG_pointer_type``, ``DW_TAG_reference_type``, ``DW_TAG_const_type``,
  2937. ``DW_TAG_volatile_type`` and ``DW_TAG_restrict_type`` are used to qualify the
  2938. ``baseType:``.
  2939. Note that the ``void *`` type is expressed as a type derived from NULL.
  2940. .. _DICompositeType:
  2941. DICompositeType
  2942. """""""""""""""
  2943. ``DICompositeType`` nodes represent types composed of other types, like
  2944. structures and unions. ``elements:`` points to a tuple of the composed types.
  2945. If the source language supports ODR, the ``identifier:`` field gives the unique
  2946. identifier used for type merging between modules. When specified, other types
  2947. can refer to composite types indirectly via a :ref:`metadata string
  2948. <metadata-string>` that matches their identifier.
  2949. .. code-block:: llvm
  2950. !0 = !DIEnumerator(name: "SixKind", value: 7)
  2951. !1 = !DIEnumerator(name: "SevenKind", value: 7)
  2952. !2 = !DIEnumerator(name: "NegEightKind", value: -8)
  2953. !3 = !DICompositeType(tag: DW_TAG_enumeration_type, name: "Enum", file: !12,
  2954. line: 2, size: 32, align: 32, identifier: "_M4Enum",
  2955. elements: !{!0, !1, !2})
  2956. The following ``tag:`` values are valid:
  2957. .. code-block:: llvm
  2958. DW_TAG_array_type = 1
  2959. DW_TAG_class_type = 2
  2960. DW_TAG_enumeration_type = 4
  2961. DW_TAG_structure_type = 19
  2962. DW_TAG_union_type = 23
  2963. DW_TAG_subroutine_type = 21
  2964. DW_TAG_inheritance = 28
  2965. For ``DW_TAG_array_type``, the ``elements:`` should be :ref:`subrange
  2966. descriptors <DISubrange>`, each representing the range of subscripts at that
  2967. level of indexing. The ``DIFlagVector`` flag to ``flags:`` indicates that an
  2968. array type is a native packed vector.
  2969. For ``DW_TAG_enumeration_type``, the ``elements:`` should be :ref:`enumerator
  2970. descriptors <DIEnumerator>`, each representing the definition of an enumeration
  2971. value for the set. All enumeration type descriptors are collected in the
  2972. ``enums:`` field of the :ref:`compile unit <DICompileUnit>`.
  2973. For ``DW_TAG_structure_type``, ``DW_TAG_class_type``, and
  2974. ``DW_TAG_union_type``, the ``elements:`` should be :ref:`derived types
  2975. <DIDerivedType>` with ``tag: DW_TAG_member`` or ``tag: DW_TAG_inheritance``.
  2976. .. _DISubrange:
  2977. DISubrange
  2978. """"""""""
  2979. ``DISubrange`` nodes are the elements for ``DW_TAG_array_type`` variants of
  2980. :ref:`DICompositeType`. ``count: -1`` indicates an empty array.
  2981. .. code-block:: llvm
  2982. !0 = !DISubrange(count: 5, lowerBound: 0) ; array counting from 0
  2983. !1 = !DISubrange(count: 5, lowerBound: 1) ; array counting from 1
  2984. !2 = !DISubrange(count: -1) ; empty array.
  2985. .. _DIEnumerator:
  2986. DIEnumerator
  2987. """"""""""""
  2988. ``DIEnumerator`` nodes are the elements for ``DW_TAG_enumeration_type``
  2989. variants of :ref:`DICompositeType`.
  2990. .. code-block:: llvm
  2991. !0 = !DIEnumerator(name: "SixKind", value: 7)
  2992. !1 = !DIEnumerator(name: "SevenKind", value: 7)
  2993. !2 = !DIEnumerator(name: "NegEightKind", value: -8)
  2994. DITemplateTypeParameter
  2995. """""""""""""""""""""""
  2996. ``DITemplateTypeParameter`` nodes represent type parameters to generic source
  2997. language constructs. They are used (optionally) in :ref:`DICompositeType` and
  2998. :ref:`DISubprogram` ``templateParams:`` fields.
  2999. .. code-block:: llvm
  3000. !0 = !DITemplateTypeParameter(name: "Ty", type: !1)
  3001. DITemplateValueParameter
  3002. """"""""""""""""""""""""
  3003. ``DITemplateValueParameter`` nodes represent value parameters to generic source
  3004. language constructs. ``tag:`` defaults to ``DW_TAG_template_value_parameter``,
  3005. but if specified can also be set to ``DW_TAG_GNU_template_template_param`` or
  3006. ``DW_TAG_GNU_template_param_pack``. They are used (optionally) in
  3007. :ref:`DICompositeType` and :ref:`DISubprogram` ``templateParams:`` fields.
  3008. .. code-block:: llvm
  3009. !0 = !DITemplateValueParameter(name: "Ty", type: !1, value: i32 7)
  3010. DINamespace
  3011. """""""""""
  3012. ``DINamespace`` nodes represent namespaces in the source language.
  3013. .. code-block:: llvm
  3014. !0 = !DINamespace(name: "myawesomeproject", scope: !1, file: !2, line: 7)
  3015. DIGlobalVariable
  3016. """"""""""""""""
  3017. ``DIGlobalVariable`` nodes represent global variables in the source language.
  3018. .. code-block:: llvm
  3019. !0 = !DIGlobalVariable(name: "foo", linkageName: "foo", scope: !1,
  3020. file: !2, line: 7, type: !3, isLocal: true,
  3021. isDefinition: false, variable: i32* @foo,
  3022. declaration: !4)
  3023. All global variables should be referenced by the `globals:` field of a
  3024. :ref:`compile unit <DICompileUnit>`.
  3025. .. _DISubprogram:
  3026. DISubprogram
  3027. """"""""""""
  3028. ``DISubprogram`` nodes represent functions from the source language. The
  3029. ``variables:`` field points at :ref:`variables <DILocalVariable>` that must be
  3030. retained, even if their IR counterparts are optimized out of the IR. The
  3031. ``type:`` field must point at an :ref:`DISubroutineType`.
  3032. .. code-block:: llvm
  3033. !0 = !DISubprogram(name: "foo", linkageName: "_Zfoov", scope: !1,
  3034. file: !2, line: 7, type: !3, isLocal: true,
  3035. isDefinition: false, scopeLine: 8, containingType: !4,
  3036. virtuality: DW_VIRTUALITY_pure_virtual, virtualIndex: 10,
  3037. flags: DIFlagPrototyped, isOptimized: true,
  3038. function: void ()* @_Z3foov,
  3039. templateParams: !5, declaration: !6, variables: !7)
  3040. .. _DILexicalBlock:
  3041. DILexicalBlock
  3042. """"""""""""""
  3043. ``DILexicalBlock`` nodes describe nested blocks within a :ref:`subprogram
  3044. <DISubprogram>`. The line number and column numbers are used to dinstinguish
  3045. two lexical blocks at same depth. They are valid targets for ``scope:``
  3046. fields.
  3047. .. code-block:: llvm
  3048. !0 = distinct !DILexicalBlock(scope: !1, file: !2, line: 7, column: 35)
  3049. Usually lexical blocks are ``distinct`` to prevent node merging based on
  3050. operands.
  3051. .. _DILexicalBlockFile:
  3052. DILexicalBlockFile
  3053. """"""""""""""""""
  3054. ``DILexicalBlockFile`` nodes are used to discriminate between sections of a
  3055. :ref:`lexical block <DILexicalBlock>`. The ``file:`` field can be changed to
  3056. indicate textual inclusion, or the ``discriminator:`` field can be used to
  3057. discriminate between control flow within a single block in the source language.
  3058. .. code-block:: llvm
  3059. !0 = !DILexicalBlock(scope: !3, file: !4, line: 7, column: 35)
  3060. !1 = !DILexicalBlockFile(scope: !0, file: !4, discriminator: 0)
  3061. !2 = !DILexicalBlockFile(scope: !0, file: !4, discriminator: 1)
  3062. .. _DILocation:
  3063. DILocation
  3064. """"""""""
  3065. ``DILocation`` nodes represent source debug locations. The ``scope:`` field is
  3066. mandatory, and points at an :ref:`DILexicalBlockFile`, an
  3067. :ref:`DILexicalBlock`, or an :ref:`DISubprogram`.
  3068. .. code-block:: llvm
  3069. !0 = !DILocation(line: 2900, column: 42, scope: !1, inlinedAt: !2)
  3070. .. _DILocalVariable:
  3071. DILocalVariable
  3072. """""""""""""""
  3073. ``DILocalVariable`` nodes represent local variables in the source language.
  3074. Instead of ``DW_TAG_variable``, they use LLVM-specific fake tags to
  3075. discriminate between local variables (``DW_TAG_auto_variable``) and subprogram
  3076. arguments (``DW_TAG_arg_variable``). In the latter case, the ``arg:`` field
  3077. specifies the argument position, and this variable will be included in the
  3078. ``variables:`` field of its :ref:`DISubprogram`.
  3079. .. code-block:: llvm
  3080. !0 = !DILocalVariable(tag: DW_TAG_arg_variable, name: "this", arg: 0,
  3081. scope: !3, file: !2, line: 7, type: !3,
  3082. flags: DIFlagArtificial)
  3083. !1 = !DILocalVariable(tag: DW_TAG_arg_variable, name: "x", arg: 1,
  3084. scope: !4, file: !2, line: 7, type: !3)
  3085. !1 = !DILocalVariable(tag: DW_TAG_auto_variable, name: "y",
  3086. scope: !5, file: !2, line: 7, type: !3)
  3087. DIExpression
  3088. """"""""""""
  3089. ``DIExpression`` nodes represent DWARF expression sequences. They are used in
  3090. :ref:`debug intrinsics<dbg_intrinsics>` (such as ``llvm.dbg.declare``) to
  3091. describe how the referenced LLVM variable relates to the source language
  3092. variable.
  3093. The current supported vocabulary is limited:
  3094. - ``DW_OP_deref`` dereferences the working expression.
  3095. - ``DW_OP_plus, 93`` adds ``93`` to the working expression.
  3096. - ``DW_OP_bit_piece, 16, 8`` specifies the offset and size (``16`` and ``8``
  3097. here, respectively) of the variable piece from the working expression.
  3098. .. code-block:: llvm
  3099. !0 = !DIExpression(DW_OP_deref)
  3100. !1 = !DIExpression(DW_OP_plus, 3)
  3101. !2 = !DIExpression(DW_OP_bit_piece, 3, 7)
  3102. !3 = !DIExpression(DW_OP_deref, DW_OP_plus, 3, DW_OP_bit_piece, 3, 7)
  3103. DIObjCProperty
  3104. """"""""""""""
  3105. ``DIObjCProperty`` nodes represent Objective-C property nodes.
  3106. .. code-block:: llvm
  3107. !3 = !DIObjCProperty(name: "foo", file: !1, line: 7, setter: "setFoo",
  3108. getter: "getFoo", attributes: 7, type: !2)
  3109. DIImportedEntity
  3110. """"""""""""""""
  3111. ``DIImportedEntity`` nodes represent entities (such as modules) imported into a
  3112. compile unit.
  3113. .. code-block:: llvm
  3114. !2 = !DIImportedEntity(tag: DW_TAG_imported_module, name: "foo", scope: !0,
  3115. entity: !1, line: 7)
  3116. '``tbaa``' Metadata
  3117. ^^^^^^^^^^^^^^^^^^^
  3118. In LLVM IR, memory does not have types, so LLVM's own type system is not
  3119. suitable for doing TBAA. Instead, metadata is added to the IR to
  3120. describe a type system of a higher level language. This can be used to
  3121. implement typical C/C++ TBAA, but it can also be used to implement
  3122. custom alias analysis behavior for other languages.
  3123. The current metadata format is very simple. TBAA metadata nodes have up
  3124. to three fields, e.g.:
  3125. .. code-block:: llvm
  3126. !0 = !{ !"an example type tree" }
  3127. !1 = !{ !"int", !0 }
  3128. !2 = !{ !"float", !0 }
  3129. !3 = !{ !"const float", !2, i64 1 }
  3130. The first field is an identity field. It can be any value, usually a
  3131. metadata string, which uniquely identifies the type. The most important
  3132. name in the tree is the name of the root node. Two trees with different
  3133. root node names are entirely disjoint, even if they have leaves with
  3134. common names.
  3135. The second field identifies the type's parent node in the tree, or is
  3136. null or omitted for a root node. A type is considered to alias all of
  3137. its descendants and all of its ancestors in the tree. Also, a type is
  3138. considered to alias all types in other trees, so that bitcode produced
  3139. from multiple front-ends is handled conservatively.
  3140. If the third field is present, it's an integer which if equal to 1
  3141. indicates that the type is "constant" (meaning
  3142. ``pointsToConstantMemory`` should return true; see `other useful
  3143. AliasAnalysis methods <AliasAnalysis.html#OtherItfs>`_).
  3144. '``tbaa.struct``' Metadata
  3145. ^^^^^^^^^^^^^^^^^^^^^^^^^^
  3146. The :ref:`llvm.memcpy <int_memcpy>` is often used to implement
  3147. aggregate assignment operations in C and similar languages, however it
  3148. is defined to copy a contiguous region of memory, which is more than
  3149. strictly necessary for aggregate types which contain holes due to
  3150. padding. Also, it doesn't contain any TBAA information about the fields
  3151. of the aggregate.
  3152. ``!tbaa.struct`` metadata can describe which memory subregions in a
  3153. memcpy are padding and what the TBAA tags of the struct are.
  3154. The current metadata format is very simple. ``!tbaa.struct`` metadata
  3155. nodes are a list of operands which are in conceptual groups of three.
  3156. For each group of three, the first operand gives the byte offset of a
  3157. field in bytes, the second gives its size in bytes, and the third gives
  3158. its tbaa tag. e.g.:
  3159. .. code-block:: llvm
  3160. !4 = !{ i64 0, i64 4, !1, i64 8, i64 4, !2 }
  3161. This describes a struct with two fields. The first is at offset 0 bytes
  3162. with size 4 bytes, and has tbaa tag !1. The second is at offset 8 bytes
  3163. and has size 4 bytes and has tbaa tag !2.
  3164. Note that the fields need not be contiguous. In this example, there is a
  3165. 4 byte gap between the two fields. This gap represents padding which
  3166. does not carry useful data and need not be preserved.
  3167. '``noalias``' and '``alias.scope``' Metadata
  3168. ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  3169. ``noalias`` and ``alias.scope`` metadata provide the ability to specify generic
  3170. noalias memory-access sets. This means that some collection of memory access
  3171. instructions (loads, stores, memory-accessing calls, etc.) that carry
  3172. ``noalias`` metadata can specifically be specified not to alias with some other
  3173. collection of memory access instructions that carry ``alias.scope`` metadata.
  3174. Each type of metadata specifies a list of scopes where each scope has an id and
  3175. a domain. When evaluating an aliasing query, if for some domain, the set
  3176. of scopes with that domain in one instruction's ``alias.scope`` list is a
  3177. subset of (or equal to) the set of scopes for that domain in another
  3178. instruction's ``noalias`` list, then the two memory accesses are assumed not to
  3179. alias.
  3180. The metadata identifying each domain is itself a list containing one or two
  3181. entries. The first entry is the name of the domain. Note that if the name is a
  3182. string then it can be combined accross functions and translation units. A
  3183. self-reference can be used to create globally unique domain names. A
  3184. descriptive string may optionally be provided as a second list entry.
  3185. The metadata identifying each scope is also itself a list containing two or
  3186. three entries. The first entry is the name of the scope. Note that if the name
  3187. is a string then it can be combined accross functions and translation units. A
  3188. self-reference can be used to create globally unique scope names. A metadata
  3189. reference to the scope's domain is the second entry. A descriptive string may
  3190. optionally be provided as a third list entry.
  3191. For example,
  3192. .. code-block:: llvm
  3193. ; Two scope domains:
  3194. !0 = !{!0}
  3195. !1 = !{!1}
  3196. ; Some scopes in these domains:
  3197. !2 = !{!2, !0}
  3198. !3 = !{!3, !0}
  3199. !4 = !{!4, !1}
  3200. ; Some scope lists:
  3201. !5 = !{!4} ; A list containing only scope !4
  3202. !6 = !{!4, !3, !2}
  3203. !7 = !{!3}
  3204. ; These two instructions don't alias:
  3205. %0 = load float, float* %c, align 4, !alias.scope !5
  3206. store float %0, float* %arrayidx.i, align 4, !noalias !5
  3207. ; These two instructions also don't alias (for domain !1, the set of scopes
  3208. ; in the !alias.scope equals that in the !noalias list):
  3209. %2 = load float, float* %c, align 4, !alias.scope !5
  3210. store float %2, float* %arrayidx.i2, align 4, !noalias !6
  3211. ; These two instructions may alias (for domain !0, the set of scopes in
  3212. ; the !noalias list is not a superset of, or equal to, the scopes in the
  3213. ; !alias.scope list):
  3214. %2 = load float, float* %c, align 4, !alias.scope !6
  3215. store float %0, float* %arrayidx.i, align 4, !noalias !7
  3216. '``fpmath``' Metadata
  3217. ^^^^^^^^^^^^^^^^^^^^^
  3218. ``fpmath`` metadata may be attached to any instruction of floating point
  3219. type. It can be used to express the maximum acceptable error in the
  3220. result of that instruction, in ULPs, thus potentially allowing the
  3221. compiler to use a more efficient but less accurate method of computing
  3222. it. ULP is defined as follows:
  3223. If ``x`` is a real number that lies between two finite consecutive
  3224. floating-point numbers ``a`` and ``b``, without being equal to one
  3225. of them, then ``ulp(x) = |b - a|``, otherwise ``ulp(x)`` is the
  3226. distance between the two non-equal finite floating-point numbers
  3227. nearest ``x``. Moreover, ``ulp(NaN)`` is ``NaN``.
  3228. The metadata node shall consist of a single positive floating point
  3229. number representing the maximum relative error, for example:
  3230. .. code-block:: llvm
  3231. !0 = !{ float 2.5 } ; maximum acceptable inaccuracy is 2.5 ULPs
  3232. .. _range-metadata:
  3233. '``range``' Metadata
  3234. ^^^^^^^^^^^^^^^^^^^^
  3235. ``range`` metadata may be attached only to ``load``, ``call`` and ``invoke`` of
  3236. integer types. It expresses the possible ranges the loaded value or the value
  3237. returned by the called function at this call site is in. The ranges are
  3238. represented with a flattened list of integers. The loaded value or the value
  3239. returned is known to be in the union of the ranges defined by each consecutive
  3240. pair. Each pair has the following properties:
  3241. - The type must match the type loaded by the instruction.
  3242. - The pair ``a,b`` represents the range ``[a,b)``.
  3243. - Both ``a`` and ``b`` are constants.
  3244. - The range is allowed to wrap.
  3245. - The range should not represent the full or empty set. That is,
  3246. ``a!=b``.
  3247. In addition, the pairs must be in signed order of the lower bound and
  3248. they must be non-contiguous.
  3249. Examples:
  3250. .. code-block:: llvm
  3251. %a = load i8, i8* %x, align 1, !range !0 ; Can only be 0 or 1
  3252. %b = load i8, i8* %y, align 1, !range !1 ; Can only be 255 (-1), 0 or 1
  3253. %c = call i8 @foo(), !range !2 ; Can only be 0, 1, 3, 4 or 5
  3254. %d = invoke i8 @bar() to label %cont
  3255. unwind label %lpad, !range !3 ; Can only be -2, -1, 3, 4 or 5
  3256. ...
  3257. !0 = !{ i8 0, i8 2 }
  3258. !1 = !{ i8 255, i8 2 }
  3259. !2 = !{ i8 0, i8 2, i8 3, i8 6 }
  3260. !3 = !{ i8 -2, i8 0, i8 3, i8 6 }
  3261. '``llvm.loop``'
  3262. ^^^^^^^^^^^^^^^
  3263. It is sometimes useful to attach information to loop constructs. Currently,
  3264. loop metadata is implemented as metadata attached to the branch instruction
  3265. in the loop latch block. This type of metadata refer to a metadata node that is
  3266. guaranteed to be separate for each loop. The loop identifier metadata is
  3267. specified with the name ``llvm.loop``.
  3268. The loop identifier metadata is implemented using a metadata that refers to
  3269. itself to avoid merging it with any other identifier metadata, e.g.,
  3270. during module linkage or function inlining. That is, each loop should refer
  3271. to their own identification metadata even if they reside in separate functions.
  3272. The following example contains loop identifier metadata for two separate loop
  3273. constructs:
  3274. .. code-block:: llvm
  3275. !0 = !{!0}
  3276. !1 = !{!1}
  3277. The loop identifier metadata can be used to specify additional
  3278. per-loop metadata. Any operands after the first operand can be treated
  3279. as user-defined metadata. For example the ``llvm.loop.unroll.count``
  3280. suggests an unroll factor to the loop unroller:
  3281. .. code-block:: llvm
  3282. br i1 %exitcond, label %._crit_edge, label %.lr.ph, !llvm.loop !0
  3283. ...
  3284. !0 = !{!0, !1}
  3285. !1 = !{!"llvm.loop.unroll.count", i32 4}
  3286. '``llvm.loop.vectorize``' and '``llvm.loop.interleave``'
  3287. ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  3288. Metadata prefixed with ``llvm.loop.vectorize`` or ``llvm.loop.interleave`` are
  3289. used to control per-loop vectorization and interleaving parameters such as
  3290. vectorization width and interleave count. These metadata should be used in
  3291. conjunction with ``llvm.loop`` loop identification metadata. The
  3292. ``llvm.loop.vectorize`` and ``llvm.loop.interleave`` metadata are only
  3293. optimization hints and the optimizer will only interleave and vectorize loops if
  3294. it believes it is safe to do so. The ``llvm.mem.parallel_loop_access`` metadata
  3295. which contains information about loop-carried memory dependencies can be helpful
  3296. in determining the safety of these transformations.
  3297. '``llvm.loop.interleave.count``' Metadata
  3298. ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  3299. This metadata suggests an interleave count to the loop interleaver.
  3300. The first operand is the string ``llvm.loop.interleave.count`` and the
  3301. second operand is an integer specifying the interleave count. For
  3302. example:
  3303. .. code-block:: llvm
  3304. !0 = !{!"llvm.loop.interleave.count", i32 4}
  3305. Note that setting ``llvm.loop.interleave.count`` to 1 disables interleaving
  3306. multiple iterations of the loop. If ``llvm.loop.interleave.count`` is set to 0
  3307. then the interleave count will be determined automatically.
  3308. '``llvm.loop.vectorize.enable``' Metadata
  3309. ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  3310. This metadata selectively enables or disables vectorization for the loop. The
  3311. first operand is the string ``llvm.loop.vectorize.enable`` and the second operand
  3312. is a bit. If the bit operand value is 1 vectorization is enabled. A value of
  3313. 0 disables vectorization:
  3314. .. code-block:: llvm
  3315. !0 = !{!"llvm.loop.vectorize.enable", i1 0}
  3316. !1 = !{!"llvm.loop.vectorize.enable", i1 1}
  3317. '``llvm.loop.vectorize.width``' Metadata
  3318. ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  3319. This metadata sets the target width of the vectorizer. The first
  3320. operand is the string ``llvm.loop.vectorize.width`` and the second
  3321. operand is an integer specifying the width. For example:
  3322. .. code-block:: llvm
  3323. !0 = !{!"llvm.loop.vectorize.width", i32 4}
  3324. Note that setting ``llvm.loop.vectorize.width`` to 1 disables
  3325. vectorization of the loop. If ``llvm.loop.vectorize.width`` is set to
  3326. 0 or if the loop does not have this metadata the width will be
  3327. determined automatically.
  3328. '``llvm.loop.unroll``'
  3329. ^^^^^^^^^^^^^^^^^^^^^^
  3330. Metadata prefixed with ``llvm.loop.unroll`` are loop unrolling
  3331. optimization hints such as the unroll factor. ``llvm.loop.unroll``
  3332. metadata should be used in conjunction with ``llvm.loop`` loop
  3333. identification metadata. The ``llvm.loop.unroll`` metadata are only
  3334. optimization hints and the unrolling will only be performed if the
  3335. optimizer believes it is safe to do so.
  3336. '``llvm.loop.unroll.count``' Metadata
  3337. ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  3338. This metadata suggests an unroll factor to the loop unroller. The
  3339. first operand is the string ``llvm.loop.unroll.count`` and the second
  3340. operand is a positive integer specifying the unroll factor. For
  3341. example:
  3342. .. code-block:: llvm
  3343. !0 = !{!"llvm.loop.unroll.count", i32 4}
  3344. If the trip count of the loop is less than the unroll count the loop
  3345. will be partially unrolled.
  3346. '``llvm.loop.unroll.disable``' Metadata
  3347. ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  3348. This metadata disables loop unrolling. The metadata has a single operand
  3349. which is the string ``llvm.loop.unroll.disable``. For example:
  3350. .. code-block:: llvm
  3351. !0 = !{!"llvm.loop.unroll.disable"}
  3352. '``llvm.loop.unroll.runtime.disable``' Metadata
  3353. ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  3354. This metadata disables runtime loop unrolling. The metadata has a single
  3355. operand which is the string ``llvm.loop.unroll.runtime.disable``. For example:
  3356. .. code-block:: llvm
  3357. !0 = !{!"llvm.loop.unroll.runtime.disable"}
  3358. '``llvm.loop.unroll.full``' Metadata
  3359. ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  3360. This metadata suggests that the loop should be unrolled fully. The
  3361. metadata has a single operand which is the string ``llvm.loop.unroll.full``.
  3362. For example:
  3363. .. code-block:: llvm
  3364. !0 = !{!"llvm.loop.unroll.full"}
  3365. '``llvm.mem``'
  3366. ^^^^^^^^^^^^^^^
  3367. Metadata types used to annotate memory accesses with information helpful
  3368. for optimizations are prefixed with ``llvm.mem``.
  3369. '``llvm.mem.parallel_loop_access``' Metadata
  3370. ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  3371. The ``llvm.mem.parallel_loop_access`` metadata refers to a loop identifier,
  3372. or metadata containing a list of loop identifiers for nested loops.
  3373. The metadata is attached to memory accessing instructions and denotes that
  3374. no loop carried memory dependence exist between it and other instructions denoted
  3375. with the same loop identifier.
  3376. Precisely, given two instructions ``m1`` and ``m2`` that both have the
  3377. ``llvm.mem.parallel_loop_access`` metadata, with ``L1`` and ``L2`` being the
  3378. set of loops associated with that metadata, respectively, then there is no loop
  3379. carried dependence between ``m1`` and ``m2`` for loops in both ``L1`` and
  3380. ``L2``.
  3381. As a special case, if all memory accessing instructions in a loop have
  3382. ``llvm.mem.parallel_loop_access`` metadata that refers to that loop, then the
  3383. loop has no loop carried memory dependences and is considered to be a parallel
  3384. loop.
  3385. Note that if not all memory access instructions have such metadata referring to
  3386. the loop, then the loop is considered not being trivially parallel. Additional
  3387. memory dependence analysis is required to make that determination. As a fail
  3388. safe mechanism, this causes loops that were originally parallel to be considered
  3389. sequential (if optimization passes that are unaware of the parallel semantics
  3390. insert new memory instructions into the loop body).
  3391. Example of a loop that is considered parallel due to its correct use of
  3392. both ``llvm.loop`` and ``llvm.mem.parallel_loop_access``
  3393. metadata types that refer to the same loop identifier metadata.
  3394. .. code-block:: llvm
  3395. for.body:
  3396. ...
  3397. %val0 = load i32, i32* %arrayidx, !llvm.mem.parallel_loop_access !0
  3398. ...
  3399. store i32 %val0, i32* %arrayidx1, !llvm.mem.parallel_loop_access !0
  3400. ...
  3401. br i1 %exitcond, label %for.end, label %for.body, !llvm.loop !0
  3402. for.end:
  3403. ...
  3404. !0 = !{!0}
  3405. It is also possible to have nested parallel loops. In that case the
  3406. memory accesses refer to a list of loop identifier metadata nodes instead of
  3407. the loop identifier metadata node directly:
  3408. .. code-block:: llvm
  3409. outer.for.body:
  3410. ...
  3411. %val1 = load i32, i32* %arrayidx3, !llvm.mem.parallel_loop_access !2
  3412. ...
  3413. br label %inner.for.body
  3414. inner.for.body:
  3415. ...
  3416. %val0 = load i32, i32* %arrayidx1, !llvm.mem.parallel_loop_access !0
  3417. ...
  3418. store i32 %val0, i32* %arrayidx2, !llvm.mem.parallel_loop_access !0
  3419. ...
  3420. br i1 %exitcond, label %inner.for.end, label %inner.for.body, !llvm.loop !1
  3421. inner.for.end:
  3422. ...
  3423. store i32 %val1, i32* %arrayidx4, !llvm.mem.parallel_loop_access !2
  3424. ...
  3425. br i1 %exitcond, label %outer.for.end, label %outer.for.body, !llvm.loop !2
  3426. outer.for.end: ; preds = %for.body
  3427. ...
  3428. !0 = !{!1, !2} ; a list of loop identifiers
  3429. !1 = !{!1} ; an identifier for the inner loop
  3430. !2 = !{!2} ; an identifier for the outer loop
  3431. '``llvm.bitsets``'
  3432. ^^^^^^^^^^^^^^^^^^
  3433. The ``llvm.bitsets`` global metadata is used to implement
  3434. :doc:`bitsets <BitSets>`.
  3435. Module Flags Metadata
  3436. =====================
  3437. Information about the module as a whole is difficult to convey to LLVM's
  3438. subsystems. The LLVM IR isn't sufficient to transmit this information.
  3439. The ``llvm.module.flags`` named metadata exists in order to facilitate
  3440. this. These flags are in the form of key / value pairs --- much like a
  3441. dictionary --- making it easy for any subsystem who cares about a flag to
  3442. look it up.
  3443. The ``llvm.module.flags`` metadata contains a list of metadata triplets.
  3444. Each triplet has the following form:
  3445. - The first element is a *behavior* flag, which specifies the behavior
  3446. when two (or more) modules are merged together, and it encounters two
  3447. (or more) metadata with the same ID. The supported behaviors are
  3448. described below.
  3449. - The second element is a metadata string that is a unique ID for the
  3450. metadata. Each module may only have one flag entry for each unique ID (not
  3451. including entries with the **Require** behavior).
  3452. - The third element is the value of the flag.
  3453. When two (or more) modules are merged together, the resulting
  3454. ``llvm.module.flags`` metadata is the union of the modules' flags. That is, for
  3455. each unique metadata ID string, there will be exactly one entry in the merged
  3456. modules ``llvm.module.flags`` metadata table, and the value for that entry will
  3457. be determined by the merge behavior flag, as described below. The only exception
  3458. is that entries with the *Require* behavior are always preserved.
  3459. The following behaviors are supported:
  3460. .. list-table::
  3461. :header-rows: 1
  3462. :widths: 10 90
  3463. * - Value
  3464. - Behavior
  3465. * - 1
  3466. - **Error**
  3467. Emits an error if two values disagree, otherwise the resulting value
  3468. is that of the operands.
  3469. * - 2
  3470. - **Warning**
  3471. Emits a warning if two values disagree. The result value will be the
  3472. operand for the flag from the first module being linked.
  3473. * - 3
  3474. - **Require**
  3475. Adds a requirement that another module flag be present and have a
  3476. specified value after linking is performed. The value must be a
  3477. metadata pair, where the first element of the pair is the ID of the
  3478. module flag to be restricted, and the second element of the pair is
  3479. the value the module flag should be restricted to. This behavior can
  3480. be used to restrict the allowable results (via triggering of an
  3481. error) of linking IDs with the **Override** behavior.
  3482. * - 4
  3483. - **Override**
  3484. Uses the specified value, regardless of the behavior or value of the
  3485. other module. If both modules specify **Override**, but the values
  3486. differ, an error will be emitted.
  3487. * - 5
  3488. - **Append**
  3489. Appends the two values, which are required to be metadata nodes.
  3490. * - 6
  3491. - **AppendUnique**
  3492. Appends the two values, which are required to be metadata
  3493. nodes. However, duplicate entries in the second list are dropped
  3494. during the append operation.
  3495. It is an error for a particular unique flag ID to have multiple behaviors,
  3496. except in the case of **Require** (which adds restrictions on another metadata
  3497. value) or **Override**.
  3498. An example of module flags:
  3499. .. code-block:: llvm
  3500. !0 = !{ i32 1, !"foo", i32 1 }
  3501. !1 = !{ i32 4, !"bar", i32 37 }
  3502. !2 = !{ i32 2, !"qux", i32 42 }
  3503. !3 = !{ i32 3, !"qux",
  3504. !{
  3505. !"foo", i32 1
  3506. }
  3507. }
  3508. !llvm.module.flags = !{ !0, !1, !2, !3 }
  3509. - Metadata ``!0`` has the ID ``!"foo"`` and the value '1'. The behavior
  3510. if two or more ``!"foo"`` flags are seen is to emit an error if their
  3511. values are not equal.
  3512. - Metadata ``!1`` has the ID ``!"bar"`` and the value '37'. The
  3513. behavior if two or more ``!"bar"`` flags are seen is to use the value
  3514. '37'.
  3515. - Metadata ``!2`` has the ID ``!"qux"`` and the value '42'. The
  3516. behavior if two or more ``!"qux"`` flags are seen is to emit a
  3517. warning if their values are not equal.
  3518. - Metadata ``!3`` has the ID ``!"qux"`` and the value:
  3519. ::
  3520. !{ !"foo", i32 1 }
  3521. The behavior is to emit an error if the ``llvm.module.flags`` does not
  3522. contain a flag with the ID ``!"foo"`` that has the value '1' after linking is
  3523. performed.
  3524. Objective-C Garbage Collection Module Flags Metadata
  3525. ----------------------------------------------------
  3526. On the Mach-O platform, Objective-C stores metadata about garbage
  3527. collection in a special section called "image info". The metadata
  3528. consists of a version number and a bitmask specifying what types of
  3529. garbage collection are supported (if any) by the file. If two or more
  3530. modules are linked together their garbage collection metadata needs to
  3531. be merged rather than appended together.
  3532. The Objective-C garbage collection module flags metadata consists of the
  3533. following key-value pairs:
  3534. .. list-table::
  3535. :header-rows: 1
  3536. :widths: 30 70
  3537. * - Key
  3538. - Value
  3539. * - ``Objective-C Version``
  3540. - **[Required]** --- The Objective-C ABI version. Valid values are 1 and 2.
  3541. * - ``Objective-C Image Info Version``
  3542. - **[Required]** --- The version of the image info section. Currently
  3543. always 0.
  3544. * - ``Objective-C Image Info Section``
  3545. - **[Required]** --- The section to place the metadata. Valid values are
  3546. ``"__OBJC, __image_info, regular"`` for Objective-C ABI version 1, and
  3547. ``"__DATA,__objc_imageinfo, regular, no_dead_strip"`` for
  3548. Objective-C ABI version 2.
  3549. * - ``Objective-C Garbage Collection``
  3550. - **[Required]** --- Specifies whether garbage collection is supported or
  3551. not. Valid values are 0, for no garbage collection, and 2, for garbage
  3552. collection supported.
  3553. * - ``Objective-C GC Only``
  3554. - **[Optional]** --- Specifies that only garbage collection is supported.
  3555. If present, its value must be 6. This flag requires that the
  3556. ``Objective-C Garbage Collection`` flag have the value 2.
  3557. Some important flag interactions:
  3558. - If a module with ``Objective-C Garbage Collection`` set to 0 is
  3559. merged with a module with ``Objective-C Garbage Collection`` set to
  3560. 2, then the resulting module has the
  3561. ``Objective-C Garbage Collection`` flag set to 0.
  3562. - A module with ``Objective-C Garbage Collection`` set to 0 cannot be
  3563. merged with a module with ``Objective-C GC Only`` set to 6.
  3564. Automatic Linker Flags Module Flags Metadata
  3565. --------------------------------------------
  3566. Some targets support embedding flags to the linker inside individual object
  3567. files. Typically this is used in conjunction with language extensions which
  3568. allow source files to explicitly declare the libraries they depend on, and have
  3569. these automatically be transmitted to the linker via object files.
  3570. These flags are encoded in the IR using metadata in the module flags section,
  3571. using the ``Linker Options`` key. The merge behavior for this flag is required
  3572. to be ``AppendUnique``, and the value for the key is expected to be a metadata
  3573. node which should be a list of other metadata nodes, each of which should be a
  3574. list of metadata strings defining linker options.
  3575. For example, the following metadata section specifies two separate sets of
  3576. linker options, presumably to link against ``libz`` and the ``Cocoa``
  3577. framework::
  3578. !0 = !{ i32 6, !"Linker Options",
  3579. !{
  3580. !{ !"-lz" },
  3581. !{ !"-framework", !"Cocoa" } } }
  3582. !llvm.module.flags = !{ !0 }
  3583. The metadata encoding as lists of lists of options, as opposed to a collapsed
  3584. list of options, is chosen so that the IR encoding can use multiple option
  3585. strings to specify e.g., a single library, while still having that specifier be
  3586. preserved as an atomic element that can be recognized by a target specific
  3587. assembly writer or object file emitter.
  3588. Each individual option is required to be either a valid option for the target's
  3589. linker, or an option that is reserved by the target specific assembly writer or
  3590. object file emitter. No other aspect of these options is defined by the IR.
  3591. C type width Module Flags Metadata
  3592. ----------------------------------
  3593. The ARM backend emits a section into each generated object file describing the
  3594. options that it was compiled with (in a compiler-independent way) to prevent
  3595. linking incompatible objects, and to allow automatic library selection. Some
  3596. of these options are not visible at the IR level, namely wchar_t width and enum
  3597. width.
  3598. To pass this information to the backend, these options are encoded in module
  3599. flags metadata, using the following key-value pairs:
  3600. .. list-table::
  3601. :header-rows: 1
  3602. :widths: 30 70
  3603. * - Key
  3604. - Value
  3605. * - short_wchar
  3606. - * 0 --- sizeof(wchar_t) == 4
  3607. * 1 --- sizeof(wchar_t) == 2
  3608. * - short_enum
  3609. - * 0 --- Enums are at least as large as an ``int``.
  3610. * 1 --- Enums are stored in the smallest integer type which can
  3611. represent all of its values.
  3612. For example, the following metadata section specifies that the module was
  3613. compiled with a ``wchar_t`` width of 4 bytes, and the underlying type of an
  3614. enum is the smallest type which can represent all of its values::
  3615. !llvm.module.flags = !{!0, !1}
  3616. !0 = !{i32 1, !"short_wchar", i32 1}
  3617. !1 = !{i32 1, !"short_enum", i32 0}
  3618. .. _intrinsicglobalvariables:
  3619. Intrinsic Global Variables
  3620. ==========================
  3621. LLVM has a number of "magic" global variables that contain data that
  3622. affect code generation or other IR semantics. These are documented here.
  3623. All globals of this sort should have a section specified as
  3624. "``llvm.metadata``". This section and all globals that start with
  3625. "``llvm.``" are reserved for use by LLVM.
  3626. .. _gv_llvmused:
  3627. The '``llvm.used``' Global Variable
  3628. -----------------------------------
  3629. The ``@llvm.used`` global is an array which has
  3630. :ref:`appending linkage <linkage_appending>`. This array contains a list of
  3631. pointers to named global variables, functions and aliases which may optionally
  3632. have a pointer cast formed of bitcast or getelementptr. For example, a legal
  3633. use of it is:
  3634. .. code-block:: llvm
  3635. @X = global i8 4
  3636. @Y = global i32 123
  3637. @llvm.used = appending global [2 x i8*] [
  3638. i8* @X,
  3639. i8* bitcast (i32* @Y to i8*)
  3640. ], section "llvm.metadata"
  3641. If a symbol appears in the ``@llvm.used`` list, then the compiler, assembler,
  3642. and linker are required to treat the symbol as if there is a reference to the
  3643. symbol that it cannot see (which is why they have to be named). For example, if
  3644. a variable has internal linkage and no references other than that from the
  3645. ``@llvm.used`` list, it cannot be deleted. This is commonly used to represent
  3646. references from inline asms and other things the compiler cannot "see", and
  3647. corresponds to "``attribute((used))``" in GNU C.
  3648. On some targets, the code generator must emit a directive to the
  3649. assembler or object file to prevent the assembler and linker from
  3650. molesting the symbol.
  3651. .. _gv_llvmcompilerused:
  3652. The '``llvm.compiler.used``' Global Variable
  3653. --------------------------------------------
  3654. The ``@llvm.compiler.used`` directive is the same as the ``@llvm.used``
  3655. directive, except that it only prevents the compiler from touching the
  3656. symbol. On targets that support it, this allows an intelligent linker to
  3657. optimize references to the symbol without being impeded as it would be
  3658. by ``@llvm.used``.
  3659. This is a rare construct that should only be used in rare circumstances,
  3660. and should not be exposed to source languages.
  3661. .. _gv_llvmglobalctors:
  3662. The '``llvm.global_ctors``' Global Variable
  3663. -------------------------------------------
  3664. .. code-block:: llvm
  3665. %0 = type { i32, void ()*, i8* }
  3666. @llvm.global_ctors = appending global [1 x %0] [%0 { i32 65535, void ()* @ctor, i8* @data }]
  3667. The ``@llvm.global_ctors`` array contains a list of constructor
  3668. functions, priorities, and an optional associated global or function.
  3669. The functions referenced by this array will be called in ascending order
  3670. of priority (i.e. lowest first) when the module is loaded. The order of
  3671. functions with the same priority is not defined.
  3672. If the third field is present, non-null, and points to a global variable
  3673. or function, the initializer function will only run if the associated
  3674. data from the current module is not discarded.
  3675. .. _llvmglobaldtors:
  3676. The '``llvm.global_dtors``' Global Variable
  3677. -------------------------------------------
  3678. .. code-block:: llvm
  3679. %0 = type { i32, void ()*, i8* }
  3680. @llvm.global_dtors = appending global [1 x %0] [%0 { i32 65535, void ()* @dtor, i8* @data }]
  3681. The ``@llvm.global_dtors`` array contains a list of destructor
  3682. functions, priorities, and an optional associated global or function.
  3683. The functions referenced by this array will be called in descending
  3684. order of priority (i.e. highest first) when the module is unloaded. The
  3685. order of functions with the same priority is not defined.
  3686. If the third field is present, non-null, and points to a global variable
  3687. or function, the destructor function will only run if the associated
  3688. data from the current module is not discarded.
  3689. Instruction Reference
  3690. =====================
  3691. The LLVM instruction set consists of several different classifications
  3692. of instructions: :ref:`terminator instructions <terminators>`, :ref:`binary
  3693. instructions <binaryops>`, :ref:`bitwise binary
  3694. instructions <bitwiseops>`, :ref:`memory instructions <memoryops>`, and
  3695. :ref:`other instructions <otherops>`.
  3696. .. _terminators:
  3697. Terminator Instructions
  3698. -----------------------
  3699. As mentioned :ref:`previously <functionstructure>`, every basic block in a
  3700. program ends with a "Terminator" instruction, which indicates which
  3701. block should be executed after the current block is finished. These
  3702. terminator instructions typically yield a '``void``' value: they produce
  3703. control flow, not values (the one exception being the
  3704. ':ref:`invoke <i_invoke>`' instruction).
  3705. The terminator instructions are: ':ref:`ret <i_ret>`',
  3706. ':ref:`br <i_br>`', ':ref:`switch <i_switch>`',
  3707. ':ref:`indirectbr <i_indirectbr>`', ':ref:`invoke <i_invoke>`',
  3708. ':ref:`resume <i_resume>`', and ':ref:`unreachable <i_unreachable>`'.
  3709. .. _i_ret:
  3710. '``ret``' Instruction
  3711. ^^^^^^^^^^^^^^^^^^^^^
  3712. Syntax:
  3713. """""""
  3714. ::
  3715. ret <type> <value> ; Return a value from a non-void function
  3716. ret void ; Return from void function
  3717. Overview:
  3718. """""""""
  3719. The '``ret``' instruction is used to return control flow (and optionally
  3720. a value) from a function back to the caller.
  3721. There are two forms of the '``ret``' instruction: one that returns a
  3722. value and then causes control flow, and one that just causes control
  3723. flow to occur.
  3724. Arguments:
  3725. """"""""""
  3726. The '``ret``' instruction optionally accepts a single argument, the
  3727. return value. The type of the return value must be a ':ref:`first
  3728. class <t_firstclass>`' type.
  3729. A function is not :ref:`well formed <wellformed>` if it it has a non-void
  3730. return type and contains a '``ret``' instruction with no return value or
  3731. a return value with a type that does not match its type, or if it has a
  3732. void return type and contains a '``ret``' instruction with a return
  3733. value.
  3734. Semantics:
  3735. """"""""""
  3736. When the '``ret``' instruction is executed, control flow returns back to
  3737. the calling function's context. If the caller is a
  3738. ":ref:`call <i_call>`" instruction, execution continues at the
  3739. instruction after the call. If the caller was an
  3740. ":ref:`invoke <i_invoke>`" instruction, execution continues at the
  3741. beginning of the "normal" destination block. If the instruction returns
  3742. a value, that value shall set the call or invoke instruction's return
  3743. value.
  3744. Example:
  3745. """"""""
  3746. .. code-block:: llvm
  3747. ret i32 5 ; Return an integer value of 5
  3748. ret void ; Return from a void function
  3749. ret { i32, i8 } { i32 4, i8 2 } ; Return a struct of values 4 and 2
  3750. .. _i_br:
  3751. '``br``' Instruction
  3752. ^^^^^^^^^^^^^^^^^^^^
  3753. Syntax:
  3754. """""""
  3755. ::
  3756. br i1 <cond>, label <iftrue>, label <iffalse>
  3757. br label <dest> ; Unconditional branch
  3758. Overview:
  3759. """""""""
  3760. The '``br``' instruction is used to cause control flow to transfer to a
  3761. different basic block in the current function. There are two forms of
  3762. this instruction, corresponding to a conditional branch and an
  3763. unconditional branch.
  3764. Arguments:
  3765. """"""""""
  3766. The conditional branch form of the '``br``' instruction takes a single
  3767. '``i1``' value and two '``label``' values. The unconditional form of the
  3768. '``br``' instruction takes a single '``label``' value as a target.
  3769. Semantics:
  3770. """"""""""
  3771. Upon execution of a conditional '``br``' instruction, the '``i1``'
  3772. argument is evaluated. If the value is ``true``, control flows to the
  3773. '``iftrue``' ``label`` argument. If "cond" is ``false``, control flows
  3774. to the '``iffalse``' ``label`` argument.
  3775. Example:
  3776. """"""""
  3777. .. code-block:: llvm
  3778. Test:
  3779. %cond = icmp eq i32 %a, %b
  3780. br i1 %cond, label %IfEqual, label %IfUnequal
  3781. IfEqual:
  3782. ret i32 1
  3783. IfUnequal:
  3784. ret i32 0
  3785. .. _i_switch:
  3786. '``switch``' Instruction
  3787. ^^^^^^^^^^^^^^^^^^^^^^^^
  3788. Syntax:
  3789. """""""
  3790. ::
  3791. switch <intty> <value>, label <defaultdest> [ <intty> <val>, label <dest> ... ]
  3792. Overview:
  3793. """""""""
  3794. The '``switch``' instruction is used to transfer control flow to one of
  3795. several different places. It is a generalization of the '``br``'
  3796. instruction, allowing a branch to occur to one of many possible
  3797. destinations.
  3798. Arguments:
  3799. """"""""""
  3800. The '``switch``' instruction uses three parameters: an integer
  3801. comparison value '``value``', a default '``label``' destination, and an
  3802. array of pairs of comparison value constants and '``label``'s. The table
  3803. is not allowed to contain duplicate constant entries.
  3804. Semantics:
  3805. """"""""""
  3806. The ``switch`` instruction specifies a table of values and destinations.
  3807. When the '``switch``' instruction is executed, this table is searched
  3808. for the given value. If the value is found, control flow is transferred
  3809. to the corresponding destination; otherwise, control flow is transferred
  3810. to the default destination.
  3811. Implementation:
  3812. """""""""""""""
  3813. Depending on properties of the target machine and the particular
  3814. ``switch`` instruction, this instruction may be code generated in
  3815. different ways. For example, it could be generated as a series of
  3816. chained conditional branches or with a lookup table.
  3817. Example:
  3818. """"""""
  3819. .. code-block:: llvm
  3820. ; Emulate a conditional br instruction
  3821. %Val = zext i1 %value to i32
  3822. switch i32 %Val, label %truedest [ i32 0, label %falsedest ]
  3823. ; Emulate an unconditional br instruction
  3824. switch i32 0, label %dest [ ]
  3825. ; Implement a jump table:
  3826. switch i32 %val, label %otherwise [ i32 0, label %onzero
  3827. i32 1, label %onone
  3828. i32 2, label %ontwo ]
  3829. .. _i_indirectbr:
  3830. '``indirectbr``' Instruction
  3831. ^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  3832. Syntax:
  3833. """""""
  3834. ::
  3835. indirectbr <somety>* <address>, [ label <dest1>, label <dest2>, ... ]
  3836. Overview:
  3837. """""""""
  3838. The '``indirectbr``' instruction implements an indirect branch to a
  3839. label within the current function, whose address is specified by
  3840. "``address``". Address must be derived from a
  3841. :ref:`blockaddress <blockaddress>` constant.
  3842. Arguments:
  3843. """"""""""
  3844. The '``address``' argument is the address of the label to jump to. The
  3845. rest of the arguments indicate the full set of possible destinations
  3846. that the address may point to. Blocks are allowed to occur multiple
  3847. times in the destination list, though this isn't particularly useful.
  3848. This destination list is required so that dataflow analysis has an
  3849. accurate understanding of the CFG.
  3850. Semantics:
  3851. """"""""""
  3852. Control transfers to the block specified in the address argument. All
  3853. possible destination blocks must be listed in the label list, otherwise
  3854. this instruction has undefined behavior. This implies that jumps to
  3855. labels defined in other functions have undefined behavior as well.
  3856. Implementation:
  3857. """""""""""""""
  3858. This is typically implemented with a jump through a register.
  3859. Example:
  3860. """"""""
  3861. .. code-block:: llvm
  3862. indirectbr i8* %Addr, [ label %bb1, label %bb2, label %bb3 ]
  3863. .. _i_invoke:
  3864. '``invoke``' Instruction
  3865. ^^^^^^^^^^^^^^^^^^^^^^^^
  3866. Syntax:
  3867. """""""
  3868. ::
  3869. <result> = invoke [cconv] [ret attrs] <ptr to function ty> <function ptr val>(<function args>) [fn attrs]
  3870. to label <normal label> unwind label <exception label>
  3871. Overview:
  3872. """""""""
  3873. The '``invoke``' instruction causes control to transfer to a specified
  3874. function, with the possibility of control flow transfer to either the
  3875. '``normal``' label or the '``exception``' label. If the callee function
  3876. returns with the "``ret``" instruction, control flow will return to the
  3877. "normal" label. If the callee (or any indirect callees) returns via the
  3878. ":ref:`resume <i_resume>`" instruction or other exception handling
  3879. mechanism, control is interrupted and continued at the dynamically
  3880. nearest "exception" label.
  3881. The '``exception``' label is a `landing
  3882. pad <ExceptionHandling.html#overview>`_ for the exception. As such,
  3883. '``exception``' label is required to have the
  3884. ":ref:`landingpad <i_landingpad>`" instruction, which contains the
  3885. information about the behavior of the program after unwinding happens,
  3886. as its first non-PHI instruction. The restrictions on the
  3887. "``landingpad``" instruction's tightly couples it to the "``invoke``"
  3888. instruction, so that the important information contained within the
  3889. "``landingpad``" instruction can't be lost through normal code motion.
  3890. Arguments:
  3891. """"""""""
  3892. This instruction requires several arguments:
  3893. #. The optional "cconv" marker indicates which :ref:`calling
  3894. convention <callingconv>` the call should use. If none is
  3895. specified, the call defaults to using C calling conventions.
  3896. #. The optional :ref:`Parameter Attributes <paramattrs>` list for return
  3897. values. Only '``zeroext``', '``signext``', and '``inreg``' attributes
  3898. are valid here.
  3899. #. '``ptr to function ty``': shall be the signature of the pointer to
  3900. function value being invoked. In most cases, this is a direct
  3901. function invocation, but indirect ``invoke``'s are just as possible,
  3902. branching off an arbitrary pointer to function value.
  3903. #. '``function ptr val``': An LLVM value containing a pointer to a
  3904. function to be invoked.
  3905. #. '``function args``': argument list whose types match the function
  3906. signature argument types and parameter attributes. All arguments must
  3907. be of :ref:`first class <t_firstclass>` type. If the function signature
  3908. indicates the function accepts a variable number of arguments, the
  3909. extra arguments can be specified.
  3910. #. '``normal label``': the label reached when the called function
  3911. executes a '``ret``' instruction.
  3912. #. '``exception label``': the label reached when a callee returns via
  3913. the :ref:`resume <i_resume>` instruction or other exception handling
  3914. mechanism.
  3915. #. The optional :ref:`function attributes <fnattrs>` list. Only
  3916. '``noreturn``', '``nounwind``', '``readonly``' and '``readnone``'
  3917. attributes are valid here.
  3918. Semantics:
  3919. """"""""""
  3920. This instruction is designed to operate as a standard '``call``'
  3921. instruction in most regards. The primary difference is that it
  3922. establishes an association with a label, which is used by the runtime
  3923. library to unwind the stack.
  3924. This instruction is used in languages with destructors to ensure that
  3925. proper cleanup is performed in the case of either a ``longjmp`` or a
  3926. thrown exception. Additionally, this is important for implementation of
  3927. '``catch``' clauses in high-level languages that support them.
  3928. For the purposes of the SSA form, the definition of the value returned
  3929. by the '``invoke``' instruction is deemed to occur on the edge from the
  3930. current block to the "normal" label. If the callee unwinds then no
  3931. return value is available.
  3932. Example:
  3933. """"""""
  3934. .. code-block:: llvm
  3935. %retval = invoke i32 @Test(i32 15) to label %Continue
  3936. unwind label %TestCleanup ; i32:retval set
  3937. %retval = invoke coldcc i32 %Testfnptr(i32 15) to label %Continue
  3938. unwind label %TestCleanup ; i32:retval set
  3939. .. _i_resume:
  3940. '``resume``' Instruction
  3941. ^^^^^^^^^^^^^^^^^^^^^^^^
  3942. Syntax:
  3943. """""""
  3944. ::
  3945. resume <type> <value>
  3946. Overview:
  3947. """""""""
  3948. The '``resume``' instruction is a terminator instruction that has no
  3949. successors.
  3950. Arguments:
  3951. """"""""""
  3952. The '``resume``' instruction requires one argument, which must have the
  3953. same type as the result of any '``landingpad``' instruction in the same
  3954. function.
  3955. Semantics:
  3956. """"""""""
  3957. The '``resume``' instruction resumes propagation of an existing
  3958. (in-flight) exception whose unwinding was interrupted with a
  3959. :ref:`landingpad <i_landingpad>` instruction.
  3960. Example:
  3961. """"""""
  3962. .. code-block:: llvm
  3963. resume { i8*, i32 } %exn
  3964. .. _i_unreachable:
  3965. '``unreachable``' Instruction
  3966. ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  3967. Syntax:
  3968. """""""
  3969. ::
  3970. unreachable
  3971. Overview:
  3972. """""""""
  3973. The '``unreachable``' instruction has no defined semantics. This
  3974. instruction is used to inform the optimizer that a particular portion of
  3975. the code is not reachable. This can be used to indicate that the code
  3976. after a no-return function cannot be reached, and other facts.
  3977. Semantics:
  3978. """"""""""
  3979. The '``unreachable``' instruction has no defined semantics.
  3980. .. _binaryops:
  3981. Binary Operations
  3982. -----------------
  3983. Binary operators are used to do most of the computation in a program.
  3984. They require two operands of the same type, execute an operation on
  3985. them, and produce a single value. The operands might represent multiple
  3986. data, as is the case with the :ref:`vector <t_vector>` data type. The
  3987. result value has the same type as its operands.
  3988. There are several different binary operators:
  3989. .. _i_add:
  3990. '``add``' Instruction
  3991. ^^^^^^^^^^^^^^^^^^^^^
  3992. Syntax:
  3993. """""""
  3994. ::
  3995. <result> = add <ty> <op1>, <op2> ; yields ty:result
  3996. <result> = add nuw <ty> <op1>, <op2> ; yields ty:result
  3997. <result> = add nsw <ty> <op1>, <op2> ; yields ty:result
  3998. <result> = add nuw nsw <ty> <op1>, <op2> ; yields ty:result
  3999. Overview:
  4000. """""""""
  4001. The '``add``' instruction returns the sum of its two operands.
  4002. Arguments:
  4003. """"""""""
  4004. The two arguments to the '``add``' instruction must be
  4005. :ref:`integer <t_integer>` or :ref:`vector <t_vector>` of integer values. Both
  4006. arguments must have identical types.
  4007. Semantics:
  4008. """"""""""
  4009. The value produced is the integer sum of the two operands.
  4010. If the sum has unsigned overflow, the result returned is the
  4011. mathematical result modulo 2\ :sup:`n`\ , where n is the bit width of
  4012. the result.
  4013. Because LLVM integers use a two's complement representation, this
  4014. instruction is appropriate for both signed and unsigned integers.
  4015. ``nuw`` and ``nsw`` stand for "No Unsigned Wrap" and "No Signed Wrap",
  4016. respectively. If the ``nuw`` and/or ``nsw`` keywords are present, the
  4017. result value of the ``add`` is a :ref:`poison value <poisonvalues>` if
  4018. unsigned and/or signed overflow, respectively, occurs.
  4019. Example:
  4020. """"""""
  4021. .. code-block:: llvm
  4022. <result> = add i32 4, %var ; yields i32:result = 4 + %var
  4023. .. _i_fadd:
  4024. '``fadd``' Instruction
  4025. ^^^^^^^^^^^^^^^^^^^^^^
  4026. Syntax:
  4027. """""""
  4028. ::
  4029. <result> = fadd [fast-math flags]* <ty> <op1>, <op2> ; yields ty:result
  4030. Overview:
  4031. """""""""
  4032. The '``fadd``' instruction returns the sum of its two operands.
  4033. Arguments:
  4034. """"""""""
  4035. The two arguments to the '``fadd``' instruction must be :ref:`floating
  4036. point <t_floating>` or :ref:`vector <t_vector>` of floating point values.
  4037. Both arguments must have identical types.
  4038. Semantics:
  4039. """"""""""
  4040. The value produced is the floating point sum of the two operands. This
  4041. instruction can also take any number of :ref:`fast-math flags <fastmath>`,
  4042. which are optimization hints to enable otherwise unsafe floating point
  4043. optimizations:
  4044. Example:
  4045. """"""""
  4046. .. code-block:: llvm
  4047. <result> = fadd float 4.0, %var ; yields float:result = 4.0 + %var
  4048. '``sub``' Instruction
  4049. ^^^^^^^^^^^^^^^^^^^^^
  4050. Syntax:
  4051. """""""
  4052. ::
  4053. <result> = sub <ty> <op1>, <op2> ; yields ty:result
  4054. <result> = sub nuw <ty> <op1>, <op2> ; yields ty:result
  4055. <result> = sub nsw <ty> <op1>, <op2> ; yields ty:result
  4056. <result> = sub nuw nsw <ty> <op1>, <op2> ; yields ty:result
  4057. Overview:
  4058. """""""""
  4059. The '``sub``' instruction returns the difference of its two operands.
  4060. Note that the '``sub``' instruction is used to represent the '``neg``'
  4061. instruction present in most other intermediate representations.
  4062. Arguments:
  4063. """"""""""
  4064. The two arguments to the '``sub``' instruction must be
  4065. :ref:`integer <t_integer>` or :ref:`vector <t_vector>` of integer values. Both
  4066. arguments must have identical types.
  4067. Semantics:
  4068. """"""""""
  4069. The value produced is the integer difference of the two operands.
  4070. If the difference has unsigned overflow, the result returned is the
  4071. mathematical result modulo 2\ :sup:`n`\ , where n is the bit width of
  4072. the result.
  4073. Because LLVM integers use a two's complement representation, this
  4074. instruction is appropriate for both signed and unsigned integers.
  4075. ``nuw`` and ``nsw`` stand for "No Unsigned Wrap" and "No Signed Wrap",
  4076. respectively. If the ``nuw`` and/or ``nsw`` keywords are present, the
  4077. result value of the ``sub`` is a :ref:`poison value <poisonvalues>` if
  4078. unsigned and/or signed overflow, respectively, occurs.
  4079. Example:
  4080. """"""""
  4081. .. code-block:: llvm
  4082. <result> = sub i32 4, %var ; yields i32:result = 4 - %var
  4083. <result> = sub i32 0, %val ; yields i32:result = -%var
  4084. .. _i_fsub:
  4085. '``fsub``' Instruction
  4086. ^^^^^^^^^^^^^^^^^^^^^^
  4087. Syntax:
  4088. """""""
  4089. ::
  4090. <result> = fsub [fast-math flags]* <ty> <op1>, <op2> ; yields ty:result
  4091. Overview:
  4092. """""""""
  4093. The '``fsub``' instruction returns the difference of its two operands.
  4094. Note that the '``fsub``' instruction is used to represent the '``fneg``'
  4095. instruction present in most other intermediate representations.
  4096. Arguments:
  4097. """"""""""
  4098. The two arguments to the '``fsub``' instruction must be :ref:`floating
  4099. point <t_floating>` or :ref:`vector <t_vector>` of floating point values.
  4100. Both arguments must have identical types.
  4101. Semantics:
  4102. """"""""""
  4103. The value produced is the floating point difference of the two operands.
  4104. This instruction can also take any number of :ref:`fast-math
  4105. flags <fastmath>`, which are optimization hints to enable otherwise
  4106. unsafe floating point optimizations:
  4107. Example:
  4108. """"""""
  4109. .. code-block:: llvm
  4110. <result> = fsub float 4.0, %var ; yields float:result = 4.0 - %var
  4111. <result> = fsub float -0.0, %val ; yields float:result = -%var
  4112. '``mul``' Instruction
  4113. ^^^^^^^^^^^^^^^^^^^^^
  4114. Syntax:
  4115. """""""
  4116. ::
  4117. <result> = mul <ty> <op1>, <op2> ; yields ty:result
  4118. <result> = mul nuw <ty> <op1>, <op2> ; yields ty:result
  4119. <result> = mul nsw <ty> <op1>, <op2> ; yields ty:result
  4120. <result> = mul nuw nsw <ty> <op1>, <op2> ; yields ty:result
  4121. Overview:
  4122. """""""""
  4123. The '``mul``' instruction returns the product of its two operands.
  4124. Arguments:
  4125. """"""""""
  4126. The two arguments to the '``mul``' instruction must be
  4127. :ref:`integer <t_integer>` or :ref:`vector <t_vector>` of integer values. Both
  4128. arguments must have identical types.
  4129. Semantics:
  4130. """"""""""
  4131. The value produced is the integer product of the two operands.
  4132. If the result of the multiplication has unsigned overflow, the result
  4133. returned is the mathematical result modulo 2\ :sup:`n`\ , where n is the
  4134. bit width of the result.
  4135. Because LLVM integers use a two's complement representation, and the
  4136. result is the same width as the operands, this instruction returns the
  4137. correct result for both signed and unsigned integers. If a full product
  4138. (e.g. ``i32`` * ``i32`` -> ``i64``) is needed, the operands should be
  4139. sign-extended or zero-extended as appropriate to the width of the full
  4140. product.
  4141. ``nuw`` and ``nsw`` stand for "No Unsigned Wrap" and "No Signed Wrap",
  4142. respectively. If the ``nuw`` and/or ``nsw`` keywords are present, the
  4143. result value of the ``mul`` is a :ref:`poison value <poisonvalues>` if
  4144. unsigned and/or signed overflow, respectively, occurs.
  4145. Example:
  4146. """"""""
  4147. .. code-block:: llvm
  4148. <result> = mul i32 4, %var ; yields i32:result = 4 * %var
  4149. .. _i_fmul:
  4150. '``fmul``' Instruction
  4151. ^^^^^^^^^^^^^^^^^^^^^^
  4152. Syntax:
  4153. """""""
  4154. ::
  4155. <result> = fmul [fast-math flags]* <ty> <op1>, <op2> ; yields ty:result
  4156. Overview:
  4157. """""""""
  4158. The '``fmul``' instruction returns the product of its two operands.
  4159. Arguments:
  4160. """"""""""
  4161. The two arguments to the '``fmul``' instruction must be :ref:`floating
  4162. point <t_floating>` or :ref:`vector <t_vector>` of floating point values.
  4163. Both arguments must have identical types.
  4164. Semantics:
  4165. """"""""""
  4166. The value produced is the floating point product of the two operands.
  4167. This instruction can also take any number of :ref:`fast-math
  4168. flags <fastmath>`, which are optimization hints to enable otherwise
  4169. unsafe floating point optimizations:
  4170. Example:
  4171. """"""""
  4172. .. code-block:: llvm
  4173. <result> = fmul float 4.0, %var ; yields float:result = 4.0 * %var
  4174. '``udiv``' Instruction
  4175. ^^^^^^^^^^^^^^^^^^^^^^
  4176. Syntax:
  4177. """""""
  4178. ::
  4179. <result> = udiv <ty> <op1>, <op2> ; yields ty:result
  4180. <result> = udiv exact <ty> <op1>, <op2> ; yields ty:result
  4181. Overview:
  4182. """""""""
  4183. The '``udiv``' instruction returns the quotient of its two operands.
  4184. Arguments:
  4185. """"""""""
  4186. The two arguments to the '``udiv``' instruction must be
  4187. :ref:`integer <t_integer>` or :ref:`vector <t_vector>` of integer values. Both
  4188. arguments must have identical types.
  4189. Semantics:
  4190. """"""""""
  4191. The value produced is the unsigned integer quotient of the two operands.
  4192. Note that unsigned integer division and signed integer division are
  4193. distinct operations; for signed integer division, use '``sdiv``'.
  4194. Division by zero leads to undefined behavior.
  4195. If the ``exact`` keyword is present, the result value of the ``udiv`` is
  4196. a :ref:`poison value <poisonvalues>` if %op1 is not a multiple of %op2 (as
  4197. such, "((a udiv exact b) mul b) == a").
  4198. Example:
  4199. """"""""
  4200. .. code-block:: llvm
  4201. <result> = udiv i32 4, %var ; yields i32:result = 4 / %var
  4202. '``sdiv``' Instruction
  4203. ^^^^^^^^^^^^^^^^^^^^^^
  4204. Syntax:
  4205. """""""
  4206. ::
  4207. <result> = sdiv <ty> <op1>, <op2> ; yields ty:result
  4208. <result> = sdiv exact <ty> <op1>, <op2> ; yields ty:result
  4209. Overview:
  4210. """""""""
  4211. The '``sdiv``' instruction returns the quotient of its two operands.
  4212. Arguments:
  4213. """"""""""
  4214. The two arguments to the '``sdiv``' instruction must be
  4215. :ref:`integer <t_integer>` or :ref:`vector <t_vector>` of integer values. Both
  4216. arguments must have identical types.
  4217. Semantics:
  4218. """"""""""
  4219. The value produced is the signed integer quotient of the two operands
  4220. rounded towards zero.
  4221. Note that signed integer division and unsigned integer division are
  4222. distinct operations; for unsigned integer division, use '``udiv``'.
  4223. Division by zero leads to undefined behavior. Overflow also leads to
  4224. undefined behavior; this is a rare case, but can occur, for example, by
  4225. doing a 32-bit division of -2147483648 by -1.
  4226. If the ``exact`` keyword is present, the result value of the ``sdiv`` is
  4227. a :ref:`poison value <poisonvalues>` if the result would be rounded.
  4228. Example:
  4229. """"""""
  4230. .. code-block:: llvm
  4231. <result> = sdiv i32 4, %var ; yields i32:result = 4 / %var
  4232. .. _i_fdiv:
  4233. '``fdiv``' Instruction
  4234. ^^^^^^^^^^^^^^^^^^^^^^
  4235. Syntax:
  4236. """""""
  4237. ::
  4238. <result> = fdiv [fast-math flags]* <ty> <op1>, <op2> ; yields ty:result
  4239. Overview:
  4240. """""""""
  4241. The '``fdiv``' instruction returns the quotient of its two operands.
  4242. Arguments:
  4243. """"""""""
  4244. The two arguments to the '``fdiv``' instruction must be :ref:`floating
  4245. point <t_floating>` or :ref:`vector <t_vector>` of floating point values.
  4246. Both arguments must have identical types.
  4247. Semantics:
  4248. """"""""""
  4249. The value produced is the floating point quotient of the two operands.
  4250. This instruction can also take any number of :ref:`fast-math
  4251. flags <fastmath>`, which are optimization hints to enable otherwise
  4252. unsafe floating point optimizations:
  4253. Example:
  4254. """"""""
  4255. .. code-block:: llvm
  4256. <result> = fdiv float 4.0, %var ; yields float:result = 4.0 / %var
  4257. '``urem``' Instruction
  4258. ^^^^^^^^^^^^^^^^^^^^^^
  4259. Syntax:
  4260. """""""
  4261. ::
  4262. <result> = urem <ty> <op1>, <op2> ; yields ty:result
  4263. Overview:
  4264. """""""""
  4265. The '``urem``' instruction returns the remainder from the unsigned
  4266. division of its two arguments.
  4267. Arguments:
  4268. """"""""""
  4269. The two arguments to the '``urem``' instruction must be
  4270. :ref:`integer <t_integer>` or :ref:`vector <t_vector>` of integer values. Both
  4271. arguments must have identical types.
  4272. Semantics:
  4273. """"""""""
  4274. This instruction returns the unsigned integer *remainder* of a division.
  4275. This instruction always performs an unsigned division to get the
  4276. remainder.
  4277. Note that unsigned integer remainder and signed integer remainder are
  4278. distinct operations; for signed integer remainder, use '``srem``'.
  4279. Taking the remainder of a division by zero leads to undefined behavior.
  4280. Example:
  4281. """"""""
  4282. .. code-block:: llvm
  4283. <result> = urem i32 4, %var ; yields i32:result = 4 % %var
  4284. '``srem``' Instruction
  4285. ^^^^^^^^^^^^^^^^^^^^^^
  4286. Syntax:
  4287. """""""
  4288. ::
  4289. <result> = srem <ty> <op1>, <op2> ; yields ty:result
  4290. Overview:
  4291. """""""""
  4292. The '``srem``' instruction returns the remainder from the signed
  4293. division of its two operands. This instruction can also take
  4294. :ref:`vector <t_vector>` versions of the values in which case the elements
  4295. must be integers.
  4296. Arguments:
  4297. """"""""""
  4298. The two arguments to the '``srem``' instruction must be
  4299. :ref:`integer <t_integer>` or :ref:`vector <t_vector>` of integer values. Both
  4300. arguments must have identical types.
  4301. Semantics:
  4302. """"""""""
  4303. This instruction returns the *remainder* of a division (where the result
  4304. is either zero or has the same sign as the dividend, ``op1``), not the
  4305. *modulo* operator (where the result is either zero or has the same sign
  4306. as the divisor, ``op2``) of a value. For more information about the
  4307. difference, see `The Math
  4308. Forum <http://mathforum.org/dr.math/problems/anne.4.28.99.html>`_. For a
  4309. table of how this is implemented in various languages, please see
  4310. `Wikipedia: modulo
  4311. operation <http://en.wikipedia.org/wiki/Modulo_operation>`_.
  4312. Note that signed integer remainder and unsigned integer remainder are
  4313. distinct operations; for unsigned integer remainder, use '``urem``'.
  4314. Taking the remainder of a division by zero leads to undefined behavior.
  4315. Overflow also leads to undefined behavior; this is a rare case, but can
  4316. occur, for example, by taking the remainder of a 32-bit division of
  4317. -2147483648 by -1. (The remainder doesn't actually overflow, but this
  4318. rule lets srem be implemented using instructions that return both the
  4319. result of the division and the remainder.)
  4320. Example:
  4321. """"""""
  4322. .. code-block:: llvm
  4323. <result> = srem i32 4, %var ; yields i32:result = 4 % %var
  4324. .. _i_frem:
  4325. '``frem``' Instruction
  4326. ^^^^^^^^^^^^^^^^^^^^^^
  4327. Syntax:
  4328. """""""
  4329. ::
  4330. <result> = frem [fast-math flags]* <ty> <op1>, <op2> ; yields ty:result
  4331. Overview:
  4332. """""""""
  4333. The '``frem``' instruction returns the remainder from the division of
  4334. its two operands.
  4335. Arguments:
  4336. """"""""""
  4337. The two arguments to the '``frem``' instruction must be :ref:`floating
  4338. point <t_floating>` or :ref:`vector <t_vector>` of floating point values.
  4339. Both arguments must have identical types.
  4340. Semantics:
  4341. """"""""""
  4342. This instruction returns the *remainder* of a division. The remainder
  4343. has the same sign as the dividend. This instruction can also take any
  4344. number of :ref:`fast-math flags <fastmath>`, which are optimization hints
  4345. to enable otherwise unsafe floating point optimizations:
  4346. Example:
  4347. """"""""
  4348. .. code-block:: llvm
  4349. <result> = frem float 4.0, %var ; yields float:result = 4.0 % %var
  4350. .. _bitwiseops:
  4351. Bitwise Binary Operations
  4352. -------------------------
  4353. Bitwise binary operators are used to do various forms of bit-twiddling
  4354. in a program. They are generally very efficient instructions and can
  4355. commonly be strength reduced from other instructions. They require two
  4356. operands of the same type, execute an operation on them, and produce a
  4357. single value. The resulting value is the same type as its operands.
  4358. '``shl``' Instruction
  4359. ^^^^^^^^^^^^^^^^^^^^^
  4360. Syntax:
  4361. """""""
  4362. ::
  4363. <result> = shl <ty> <op1>, <op2> ; yields ty:result
  4364. <result> = shl nuw <ty> <op1>, <op2> ; yields ty:result
  4365. <result> = shl nsw <ty> <op1>, <op2> ; yields ty:result
  4366. <result> = shl nuw nsw <ty> <op1>, <op2> ; yields ty:result
  4367. Overview:
  4368. """""""""
  4369. The '``shl``' instruction returns the first operand shifted to the left
  4370. a specified number of bits.
  4371. Arguments:
  4372. """"""""""
  4373. Both arguments to the '``shl``' instruction must be the same
  4374. :ref:`integer <t_integer>` or :ref:`vector <t_vector>` of integer type.
  4375. '``op2``' is treated as an unsigned value.
  4376. Semantics:
  4377. """"""""""
  4378. The value produced is ``op1`` \* 2\ :sup:`op2` mod 2\ :sup:`n`,
  4379. where ``n`` is the width of the result. If ``op2`` is (statically or
  4380. dynamically) equal to or larger than the number of bits in
  4381. ``op1``, the result is undefined. If the arguments are vectors, each
  4382. vector element of ``op1`` is shifted by the corresponding shift amount
  4383. in ``op2``.
  4384. If the ``nuw`` keyword is present, then the shift produces a :ref:`poison
  4385. value <poisonvalues>` if it shifts out any non-zero bits. If the
  4386. ``nsw`` keyword is present, then the shift produces a :ref:`poison
  4387. value <poisonvalues>` if it shifts out any bits that disagree with the
  4388. resultant sign bit. As such, NUW/NSW have the same semantics as they
  4389. would if the shift were expressed as a mul instruction with the same
  4390. nsw/nuw bits in (mul %op1, (shl 1, %op2)).
  4391. Example:
  4392. """"""""
  4393. .. code-block:: llvm
  4394. <result> = shl i32 4, %var ; yields i32: 4 << %var
  4395. <result> = shl i32 4, 2 ; yields i32: 16
  4396. <result> = shl i32 1, 10 ; yields i32: 1024
  4397. <result> = shl i32 1, 32 ; undefined
  4398. <result> = shl <2 x i32> < i32 1, i32 1>, < i32 1, i32 2> ; yields: result=<2 x i32> < i32 2, i32 4>
  4399. '``lshr``' Instruction
  4400. ^^^^^^^^^^^^^^^^^^^^^^
  4401. Syntax:
  4402. """""""
  4403. ::
  4404. <result> = lshr <ty> <op1>, <op2> ; yields ty:result
  4405. <result> = lshr exact <ty> <op1>, <op2> ; yields ty:result
  4406. Overview:
  4407. """""""""
  4408. The '``lshr``' instruction (logical shift right) returns the first
  4409. operand shifted to the right a specified number of bits with zero fill.
  4410. Arguments:
  4411. """"""""""
  4412. Both arguments to the '``lshr``' instruction must be the same
  4413. :ref:`integer <t_integer>` or :ref:`vector <t_vector>` of integer type.
  4414. '``op2``' is treated as an unsigned value.
  4415. Semantics:
  4416. """"""""""
  4417. This instruction always performs a logical shift right operation. The
  4418. most significant bits of the result will be filled with zero bits after
  4419. the shift. If ``op2`` is (statically or dynamically) equal to or larger
  4420. than the number of bits in ``op1``, the result is undefined. If the
  4421. arguments are vectors, each vector element of ``op1`` is shifted by the
  4422. corresponding shift amount in ``op2``.
  4423. If the ``exact`` keyword is present, the result value of the ``lshr`` is
  4424. a :ref:`poison value <poisonvalues>` if any of the bits shifted out are
  4425. non-zero.
  4426. Example:
  4427. """"""""
  4428. .. code-block:: llvm
  4429. <result> = lshr i32 4, 1 ; yields i32:result = 2
  4430. <result> = lshr i32 4, 2 ; yields i32:result = 1
  4431. <result> = lshr i8 4, 3 ; yields i8:result = 0
  4432. <result> = lshr i8 -2, 1 ; yields i8:result = 0x7F
  4433. <result> = lshr i32 1, 32 ; undefined
  4434. <result> = lshr <2 x i32> < i32 -2, i32 4>, < i32 1, i32 2> ; yields: result=<2 x i32> < i32 0x7FFFFFFF, i32 1>
  4435. '``ashr``' Instruction
  4436. ^^^^^^^^^^^^^^^^^^^^^^
  4437. Syntax:
  4438. """""""
  4439. ::
  4440. <result> = ashr <ty> <op1>, <op2> ; yields ty:result
  4441. <result> = ashr exact <ty> <op1>, <op2> ; yields ty:result
  4442. Overview:
  4443. """""""""
  4444. The '``ashr``' instruction (arithmetic shift right) returns the first
  4445. operand shifted to the right a specified number of bits with sign
  4446. extension.
  4447. Arguments:
  4448. """"""""""
  4449. Both arguments to the '``ashr``' instruction must be the same
  4450. :ref:`integer <t_integer>` or :ref:`vector <t_vector>` of integer type.
  4451. '``op2``' is treated as an unsigned value.
  4452. Semantics:
  4453. """"""""""
  4454. This instruction always performs an arithmetic shift right operation,
  4455. The most significant bits of the result will be filled with the sign bit
  4456. of ``op1``. If ``op2`` is (statically or dynamically) equal to or larger
  4457. than the number of bits in ``op1``, the result is undefined. If the
  4458. arguments are vectors, each vector element of ``op1`` is shifted by the
  4459. corresponding shift amount in ``op2``.
  4460. If the ``exact`` keyword is present, the result value of the ``ashr`` is
  4461. a :ref:`poison value <poisonvalues>` if any of the bits shifted out are
  4462. non-zero.
  4463. Example:
  4464. """"""""
  4465. .. code-block:: llvm
  4466. <result> = ashr i32 4, 1 ; yields i32:result = 2
  4467. <result> = ashr i32 4, 2 ; yields i32:result = 1
  4468. <result> = ashr i8 4, 3 ; yields i8:result = 0
  4469. <result> = ashr i8 -2, 1 ; yields i8:result = -1
  4470. <result> = ashr i32 1, 32 ; undefined
  4471. <result> = ashr <2 x i32> < i32 -2, i32 4>, < i32 1, i32 3> ; yields: result=<2 x i32> < i32 -1, i32 0>
  4472. '``and``' Instruction
  4473. ^^^^^^^^^^^^^^^^^^^^^
  4474. Syntax:
  4475. """""""
  4476. ::
  4477. <result> = and <ty> <op1>, <op2> ; yields ty:result
  4478. Overview:
  4479. """""""""
  4480. The '``and``' instruction returns the bitwise logical and of its two
  4481. operands.
  4482. Arguments:
  4483. """"""""""
  4484. The two arguments to the '``and``' instruction must be
  4485. :ref:`integer <t_integer>` or :ref:`vector <t_vector>` of integer values. Both
  4486. arguments must have identical types.
  4487. Semantics:
  4488. """"""""""
  4489. The truth table used for the '``and``' instruction is:
  4490. +-----+-----+-----+
  4491. | In0 | In1 | Out |
  4492. +-----+-----+-----+
  4493. | 0 | 0 | 0 |
  4494. +-----+-----+-----+
  4495. | 0 | 1 | 0 |
  4496. +-----+-----+-----+
  4497. | 1 | 0 | 0 |
  4498. +-----+-----+-----+
  4499. | 1 | 1 | 1 |
  4500. +-----+-----+-----+
  4501. Example:
  4502. """"""""
  4503. .. code-block:: llvm
  4504. <result> = and i32 4, %var ; yields i32:result = 4 & %var
  4505. <result> = and i32 15, 40 ; yields i32:result = 8
  4506. <result> = and i32 4, 8 ; yields i32:result = 0
  4507. '``or``' Instruction
  4508. ^^^^^^^^^^^^^^^^^^^^
  4509. Syntax:
  4510. """""""
  4511. ::
  4512. <result> = or <ty> <op1>, <op2> ; yields ty:result
  4513. Overview:
  4514. """""""""
  4515. The '``or``' instruction returns the bitwise logical inclusive or of its
  4516. two operands.
  4517. Arguments:
  4518. """"""""""
  4519. The two arguments to the '``or``' instruction must be
  4520. :ref:`integer <t_integer>` or :ref:`vector <t_vector>` of integer values. Both
  4521. arguments must have identical types.
  4522. Semantics:
  4523. """"""""""
  4524. The truth table used for the '``or``' instruction is:
  4525. +-----+-----+-----+
  4526. | In0 | In1 | Out |
  4527. +-----+-----+-----+
  4528. | 0 | 0 | 0 |
  4529. +-----+-----+-----+
  4530. | 0 | 1 | 1 |
  4531. +-----+-----+-----+
  4532. | 1 | 0 | 1 |
  4533. +-----+-----+-----+
  4534. | 1 | 1 | 1 |
  4535. +-----+-----+-----+
  4536. Example:
  4537. """"""""
  4538. ::
  4539. <result> = or i32 4, %var ; yields i32:result = 4 | %var
  4540. <result> = or i32 15, 40 ; yields i32:result = 47
  4541. <result> = or i32 4, 8 ; yields i32:result = 12
  4542. '``xor``' Instruction
  4543. ^^^^^^^^^^^^^^^^^^^^^
  4544. Syntax:
  4545. """""""
  4546. ::
  4547. <result> = xor <ty> <op1>, <op2> ; yields ty:result
  4548. Overview:
  4549. """""""""
  4550. The '``xor``' instruction returns the bitwise logical exclusive or of
  4551. its two operands. The ``xor`` is used to implement the "one's
  4552. complement" operation, which is the "~" operator in C.
  4553. Arguments:
  4554. """"""""""
  4555. The two arguments to the '``xor``' instruction must be
  4556. :ref:`integer <t_integer>` or :ref:`vector <t_vector>` of integer values. Both
  4557. arguments must have identical types.
  4558. Semantics:
  4559. """"""""""
  4560. The truth table used for the '``xor``' instruction is:
  4561. +-----+-----+-----+
  4562. | In0 | In1 | Out |
  4563. +-----+-----+-----+
  4564. | 0 | 0 | 0 |
  4565. +-----+-----+-----+
  4566. | 0 | 1 | 1 |
  4567. +-----+-----+-----+
  4568. | 1 | 0 | 1 |
  4569. +-----+-----+-----+
  4570. | 1 | 1 | 0 |
  4571. +-----+-----+-----+
  4572. Example:
  4573. """"""""
  4574. .. code-block:: llvm
  4575. <result> = xor i32 4, %var ; yields i32:result = 4 ^ %var
  4576. <result> = xor i32 15, 40 ; yields i32:result = 39
  4577. <result> = xor i32 4, 8 ; yields i32:result = 12
  4578. <result> = xor i32 %V, -1 ; yields i32:result = ~%V
  4579. Vector Operations
  4580. -----------------
  4581. LLVM supports several instructions to represent vector operations in a
  4582. target-independent manner. These instructions cover the element-access
  4583. and vector-specific operations needed to process vectors effectively.
  4584. While LLVM does directly support these vector operations, many
  4585. sophisticated algorithms will want to use target-specific intrinsics to
  4586. take full advantage of a specific target.
  4587. .. _i_extractelement:
  4588. '``extractelement``' Instruction
  4589. ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  4590. Syntax:
  4591. """""""
  4592. ::
  4593. <result> = extractelement <n x <ty>> <val>, <ty2> <idx> ; yields <ty>
  4594. Overview:
  4595. """""""""
  4596. The '``extractelement``' instruction extracts a single scalar element
  4597. from a vector at a specified index.
  4598. Arguments:
  4599. """"""""""
  4600. The first operand of an '``extractelement``' instruction is a value of
  4601. :ref:`vector <t_vector>` type. The second operand is an index indicating
  4602. the position from which to extract the element. The index may be a
  4603. variable of any integer type.
  4604. Semantics:
  4605. """"""""""
  4606. The result is a scalar of the same type as the element type of ``val``.
  4607. Its value is the value at position ``idx`` of ``val``. If ``idx``
  4608. exceeds the length of ``val``, the results are undefined.
  4609. Example:
  4610. """"""""
  4611. .. code-block:: llvm
  4612. <result> = extractelement <4 x i32> %vec, i32 0 ; yields i32
  4613. .. _i_insertelement:
  4614. '``insertelement``' Instruction
  4615. ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  4616. Syntax:
  4617. """""""
  4618. ::
  4619. <result> = insertelement <n x <ty>> <val>, <ty> <elt>, <ty2> <idx> ; yields <n x <ty>>
  4620. Overview:
  4621. """""""""
  4622. The '``insertelement``' instruction inserts a scalar element into a
  4623. vector at a specified index.
  4624. Arguments:
  4625. """"""""""
  4626. The first operand of an '``insertelement``' instruction is a value of
  4627. :ref:`vector <t_vector>` type. The second operand is a scalar value whose
  4628. type must equal the element type of the first operand. The third operand
  4629. is an index indicating the position at which to insert the value. The
  4630. index may be a variable of any integer type.
  4631. Semantics:
  4632. """"""""""
  4633. The result is a vector of the same type as ``val``. Its element values
  4634. are those of ``val`` except at position ``idx``, where it gets the value
  4635. ``elt``. If ``idx`` exceeds the length of ``val``, the results are
  4636. undefined.
  4637. Example:
  4638. """"""""
  4639. .. code-block:: llvm
  4640. <result> = insertelement <4 x i32> %vec, i32 1, i32 0 ; yields <4 x i32>
  4641. .. _i_shufflevector:
  4642. '``shufflevector``' Instruction
  4643. ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  4644. Syntax:
  4645. """""""
  4646. ::
  4647. <result> = shufflevector <n x <ty>> <v1>, <n x <ty>> <v2>, <m x i32> <mask> ; yields <m x <ty>>
  4648. Overview:
  4649. """""""""
  4650. The '``shufflevector``' instruction constructs a permutation of elements
  4651. from two input vectors, returning a vector with the same element type as
  4652. the input and length that is the same as the shuffle mask.
  4653. Arguments:
  4654. """"""""""
  4655. The first two operands of a '``shufflevector``' instruction are vectors
  4656. with the same type. The third argument is a shuffle mask whose element
  4657. type is always 'i32'. The result of the instruction is a vector whose
  4658. length is the same as the shuffle mask and whose element type is the
  4659. same as the element type of the first two operands.
  4660. The shuffle mask operand is required to be a constant vector with either
  4661. constant integer or undef values.
  4662. Semantics:
  4663. """"""""""
  4664. The elements of the two input vectors are numbered from left to right
  4665. across both of the vectors. The shuffle mask operand specifies, for each
  4666. element of the result vector, which element of the two input vectors the
  4667. result element gets. The element selector may be undef (meaning "don't
  4668. care") and the second operand may be undef if performing a shuffle from
  4669. only one vector.
  4670. Example:
  4671. """"""""
  4672. .. code-block:: llvm
  4673. <result> = shufflevector <4 x i32> %v1, <4 x i32> %v2,
  4674. <4 x i32> <i32 0, i32 4, i32 1, i32 5> ; yields <4 x i32>
  4675. <result> = shufflevector <4 x i32> %v1, <4 x i32> undef,
  4676. <4 x i32> <i32 0, i32 1, i32 2, i32 3> ; yields <4 x i32> - Identity shuffle.
  4677. <result> = shufflevector <8 x i32> %v1, <8 x i32> undef,
  4678. <4 x i32> <i32 0, i32 1, i32 2, i32 3> ; yields <4 x i32>
  4679. <result> = shufflevector <4 x i32> %v1, <4 x i32> %v2,
  4680. <8 x i32> <i32 0, i32 1, i32 2, i32 3, i32 4, i32 5, i32 6, i32 7 > ; yields <8 x i32>
  4681. Aggregate Operations
  4682. --------------------
  4683. LLVM supports several instructions for working with
  4684. :ref:`aggregate <t_aggregate>` values.
  4685. .. _i_extractvalue:
  4686. '``extractvalue``' Instruction
  4687. ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  4688. Syntax:
  4689. """""""
  4690. ::
  4691. <result> = extractvalue <aggregate type> <val>, <idx>{, <idx>}*
  4692. Overview:
  4693. """""""""
  4694. The '``extractvalue``' instruction extracts the value of a member field
  4695. from an :ref:`aggregate <t_aggregate>` value.
  4696. Arguments:
  4697. """"""""""
  4698. The first operand of an '``extractvalue``' instruction is a value of
  4699. :ref:`struct <t_struct>` or :ref:`array <t_array>` type. The operands are
  4700. constant indices to specify which value to extract in a similar manner
  4701. as indices in a '``getelementptr``' instruction.
  4702. The major differences to ``getelementptr`` indexing are:
  4703. - Since the value being indexed is not a pointer, the first index is
  4704. omitted and assumed to be zero.
  4705. - At least one index must be specified.
  4706. - Not only struct indices but also array indices must be in bounds.
  4707. Semantics:
  4708. """"""""""
  4709. The result is the value at the position in the aggregate specified by
  4710. the index operands.
  4711. Example:
  4712. """"""""
  4713. .. code-block:: llvm
  4714. <result> = extractvalue {i32, float} %agg, 0 ; yields i32
  4715. .. _i_insertvalue:
  4716. '``insertvalue``' Instruction
  4717. ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  4718. Syntax:
  4719. """""""
  4720. ::
  4721. <result> = insertvalue <aggregate type> <val>, <ty> <elt>, <idx>{, <idx>}* ; yields <aggregate type>
  4722. Overview:
  4723. """""""""
  4724. The '``insertvalue``' instruction inserts a value into a member field in
  4725. an :ref:`aggregate <t_aggregate>` value.
  4726. Arguments:
  4727. """"""""""
  4728. The first operand of an '``insertvalue``' instruction is a value of
  4729. :ref:`struct <t_struct>` or :ref:`array <t_array>` type. The second operand is
  4730. a first-class value to insert. The following operands are constant
  4731. indices indicating the position at which to insert the value in a
  4732. similar manner as indices in a '``extractvalue``' instruction. The value
  4733. to insert must have the same type as the value identified by the
  4734. indices.
  4735. Semantics:
  4736. """"""""""
  4737. The result is an aggregate of the same type as ``val``. Its value is
  4738. that of ``val`` except that the value at the position specified by the
  4739. indices is that of ``elt``.
  4740. Example:
  4741. """"""""
  4742. .. code-block:: llvm
  4743. %agg1 = insertvalue {i32, float} undef, i32 1, 0 ; yields {i32 1, float undef}
  4744. %agg2 = insertvalue {i32, float} %agg1, float %val, 1 ; yields {i32 1, float %val}
  4745. %agg3 = insertvalue {i32, {float}} undef, float %val, 1, 0 ; yields {i32 undef, {float %val}}
  4746. .. _memoryops:
  4747. Memory Access and Addressing Operations
  4748. ---------------------------------------
  4749. A key design point of an SSA-based representation is how it represents
  4750. memory. In LLVM, no memory locations are in SSA form, which makes things
  4751. very simple. This section describes how to read, write, and allocate
  4752. memory in LLVM.
  4753. .. _i_alloca:
  4754. '``alloca``' Instruction
  4755. ^^^^^^^^^^^^^^^^^^^^^^^^
  4756. Syntax:
  4757. """""""
  4758. ::
  4759. <result> = alloca [inalloca] <type> [, <ty> <NumElements>] [, align <alignment>] ; yields type*:result
  4760. Overview:
  4761. """""""""
  4762. The '``alloca``' instruction allocates memory on the stack frame of the
  4763. currently executing function, to be automatically released when this
  4764. function returns to its caller. The object is always allocated in the
  4765. generic address space (address space zero).
  4766. Arguments:
  4767. """"""""""
  4768. The '``alloca``' instruction allocates ``sizeof(<type>)*NumElements``
  4769. bytes of memory on the runtime stack, returning a pointer of the
  4770. appropriate type to the program. If "NumElements" is specified, it is
  4771. the number of elements allocated, otherwise "NumElements" is defaulted
  4772. to be one. If a constant alignment is specified, the value result of the
  4773. allocation is guaranteed to be aligned to at least that boundary. The
  4774. alignment may not be greater than ``1 << 29``. If not specified, or if
  4775. zero, the target can choose to align the allocation on any convenient
  4776. boundary compatible with the type.
  4777. '``type``' may be any sized type.
  4778. Semantics:
  4779. """"""""""
  4780. Memory is allocated; a pointer is returned. The operation is undefined
  4781. if there is insufficient stack space for the allocation. '``alloca``'d
  4782. memory is automatically released when the function returns. The
  4783. '``alloca``' instruction is commonly used to represent automatic
  4784. variables that must have an address available. When the function returns
  4785. (either with the ``ret`` or ``resume`` instructions), the memory is
  4786. reclaimed. Allocating zero bytes is legal, but the result is undefined.
  4787. The order in which memory is allocated (ie., which way the stack grows)
  4788. is not specified.
  4789. Example:
  4790. """"""""
  4791. .. code-block:: llvm
  4792. %ptr = alloca i32 ; yields i32*:ptr
  4793. %ptr = alloca i32, i32 4 ; yields i32*:ptr
  4794. %ptr = alloca i32, i32 4, align 1024 ; yields i32*:ptr
  4795. %ptr = alloca i32, align 1024 ; yields i32*:ptr
  4796. .. _i_load:
  4797. '``load``' Instruction
  4798. ^^^^^^^^^^^^^^^^^^^^^^
  4799. Syntax:
  4800. """""""
  4801. ::
  4802. <result> = load [volatile] <ty>, <ty>* <pointer>[, align <alignment>][, !nontemporal !<index>][, !invariant.load !<index>][, !nonnull !<index>][, !dereferenceable !<index>][, !dereferenceable_or_null !<index>]
  4803. <result> = load atomic [volatile] <ty>* <pointer> [singlethread] <ordering>, align <alignment>
  4804. !<index> = !{ i32 1 }
  4805. Overview:
  4806. """""""""
  4807. The '``load``' instruction is used to read from memory.
  4808. Arguments:
  4809. """"""""""
  4810. The argument to the ``load`` instruction specifies the memory address
  4811. from which to load. The type specified must be a :ref:`first
  4812. class <t_firstclass>` type. If the ``load`` is marked as ``volatile``,
  4813. then the optimizer is not allowed to modify the number or order of
  4814. execution of this ``load`` with other :ref:`volatile
  4815. operations <volatile>`.
  4816. If the ``load`` is marked as ``atomic``, it takes an extra
  4817. :ref:`ordering <ordering>` and optional ``singlethread`` argument. The
  4818. ``release`` and ``acq_rel`` orderings are not valid on ``load``
  4819. instructions. Atomic loads produce :ref:`defined <memmodel>` results
  4820. when they may see multiple atomic stores. The type of the pointee must
  4821. be an integer type whose bit width is a power of two greater than or
  4822. equal to eight and less than or equal to a target-specific size limit.
  4823. ``align`` must be explicitly specified on atomic loads, and the load has
  4824. undefined behavior if the alignment is not set to a value which is at
  4825. least the size in bytes of the pointee. ``!nontemporal`` does not have
  4826. any defined semantics for atomic loads.
  4827. The optional constant ``align`` argument specifies the alignment of the
  4828. operation (that is, the alignment of the memory address). A value of 0
  4829. or an omitted ``align`` argument means that the operation has the ABI
  4830. alignment for the target. It is the responsibility of the code emitter
  4831. to ensure that the alignment information is correct. Overestimating the
  4832. alignment results in undefined behavior. Underestimating the alignment
  4833. may produce less efficient code. An alignment of 1 is always safe. The
  4834. maximum possible alignment is ``1 << 29``.
  4835. The optional ``!nontemporal`` metadata must reference a single
  4836. metadata name ``<index>`` corresponding to a metadata node with one
  4837. ``i32`` entry of value 1. The existence of the ``!nontemporal``
  4838. metadata on the instruction tells the optimizer and code generator
  4839. that this load is not expected to be reused in the cache. The code
  4840. generator may select special instructions to save cache bandwidth, such
  4841. as the ``MOVNT`` instruction on x86.
  4842. The optional ``!invariant.load`` metadata must reference a single
  4843. metadata name ``<index>`` corresponding to a metadata node with no
  4844. entries. The existence of the ``!invariant.load`` metadata on the
  4845. instruction tells the optimizer and code generator that the address
  4846. operand to this load points to memory which can be assumed unchanged.
  4847. Being invariant does not imply that a location is dereferenceable,
  4848. but it does imply that once the location is known dereferenceable
  4849. its value is henceforth unchanging.
  4850. The optional ``!nonnull`` metadata must reference a single
  4851. metadata name ``<index>`` corresponding to a metadata node with no
  4852. entries. The existence of the ``!nonnull`` metadata on the
  4853. instruction tells the optimizer that the value loaded is known to
  4854. never be null. This is analogous to the ''nonnull'' attribute
  4855. on parameters and return values. This metadata can only be applied
  4856. to loads of a pointer type.
  4857. The optional ``!dereferenceable`` metadata must reference a single
  4858. metadata name ``<index>`` corresponding to a metadata node with one ``i64``
  4859. entry. The existence of the ``!dereferenceable`` metadata on the instruction
  4860. tells the optimizer that the value loaded is known to be dereferenceable.
  4861. The number of bytes known to be dereferenceable is specified by the integer
  4862. value in the metadata node. This is analogous to the ''dereferenceable''
  4863. attribute on parameters and return values. This metadata can only be applied
  4864. to loads of a pointer type.
  4865. The optional ``!dereferenceable_or_null`` metadata must reference a single
  4866. metadata name ``<index>`` corresponding to a metadata node with one ``i64``
  4867. entry. The existence of the ``!dereferenceable_or_null`` metadata on the
  4868. instruction tells the optimizer that the value loaded is known to be either
  4869. dereferenceable or null.
  4870. The number of bytes known to be dereferenceable is specified by the integer
  4871. value in the metadata node. This is analogous to the ''dereferenceable_or_null''
  4872. attribute on parameters and return values. This metadata can only be applied
  4873. to loads of a pointer type.
  4874. Semantics:
  4875. """"""""""
  4876. The location of memory pointed to is loaded. If the value being loaded
  4877. is of scalar type then the number of bytes read does not exceed the
  4878. minimum number of bytes needed to hold all bits of the type. For
  4879. example, loading an ``i24`` reads at most three bytes. When loading a
  4880. value of a type like ``i20`` with a size that is not an integral number
  4881. of bytes, the result is undefined if the value was not originally
  4882. written using a store of the same type.
  4883. Examples:
  4884. """""""""
  4885. .. code-block:: llvm
  4886. %ptr = alloca i32 ; yields i32*:ptr
  4887. store i32 3, i32* %ptr ; yields void
  4888. %val = load i32, i32* %ptr ; yields i32:val = i32 3
  4889. .. _i_store:
  4890. '``store``' Instruction
  4891. ^^^^^^^^^^^^^^^^^^^^^^^
  4892. Syntax:
  4893. """""""
  4894. ::
  4895. store [volatile] <ty> <value>, <ty>* <pointer>[, align <alignment>][, !nontemporal !<index>] ; yields void
  4896. store atomic [volatile] <ty> <value>, <ty>* <pointer> [singlethread] <ordering>, align <alignment> ; yields void
  4897. Overview:
  4898. """""""""
  4899. The '``store``' instruction is used to write to memory.
  4900. Arguments:
  4901. """"""""""
  4902. There are two arguments to the ``store`` instruction: a value to store
  4903. and an address at which to store it. The type of the ``<pointer>``
  4904. operand must be a pointer to the :ref:`first class <t_firstclass>` type of
  4905. the ``<value>`` operand. If the ``store`` is marked as ``volatile``,
  4906. then the optimizer is not allowed to modify the number or order of
  4907. execution of this ``store`` with other :ref:`volatile
  4908. operations <volatile>`.
  4909. If the ``store`` is marked as ``atomic``, it takes an extra
  4910. :ref:`ordering <ordering>` and optional ``singlethread`` argument. The
  4911. ``acquire`` and ``acq_rel`` orderings aren't valid on ``store``
  4912. instructions. Atomic loads produce :ref:`defined <memmodel>` results
  4913. when they may see multiple atomic stores. The type of the pointee must
  4914. be an integer type whose bit width is a power of two greater than or
  4915. equal to eight and less than or equal to a target-specific size limit.
  4916. ``align`` must be explicitly specified on atomic stores, and the store
  4917. has undefined behavior if the alignment is not set to a value which is
  4918. at least the size in bytes of the pointee. ``!nontemporal`` does not
  4919. have any defined semantics for atomic stores.
  4920. The optional constant ``align`` argument specifies the alignment of the
  4921. operation (that is, the alignment of the memory address). A value of 0
  4922. or an omitted ``align`` argument means that the operation has the ABI
  4923. alignment for the target. It is the responsibility of the code emitter
  4924. to ensure that the alignment information is correct. Overestimating the
  4925. alignment results in undefined behavior. Underestimating the
  4926. alignment may produce less efficient code. An alignment of 1 is always
  4927. safe. The maximum possible alignment is ``1 << 29``.
  4928. The optional ``!nontemporal`` metadata must reference a single metadata
  4929. name ``<index>`` corresponding to a metadata node with one ``i32`` entry of
  4930. value 1. The existence of the ``!nontemporal`` metadata on the instruction
  4931. tells the optimizer and code generator that this load is not expected to
  4932. be reused in the cache. The code generator may select special
  4933. instructions to save cache bandwidth, such as the MOVNT instruction on
  4934. x86.
  4935. Semantics:
  4936. """"""""""
  4937. The contents of memory are updated to contain ``<value>`` at the
  4938. location specified by the ``<pointer>`` operand. If ``<value>`` is
  4939. of scalar type then the number of bytes written does not exceed the
  4940. minimum number of bytes needed to hold all bits of the type. For
  4941. example, storing an ``i24`` writes at most three bytes. When writing a
  4942. value of a type like ``i20`` with a size that is not an integral number
  4943. of bytes, it is unspecified what happens to the extra bits that do not
  4944. belong to the type, but they will typically be overwritten.
  4945. Example:
  4946. """"""""
  4947. .. code-block:: llvm
  4948. %ptr = alloca i32 ; yields i32*:ptr
  4949. store i32 3, i32* %ptr ; yields void
  4950. %val = load i32, i32* %ptr ; yields i32:val = i32 3
  4951. .. _i_fence:
  4952. '``fence``' Instruction
  4953. ^^^^^^^^^^^^^^^^^^^^^^^
  4954. Syntax:
  4955. """""""
  4956. ::
  4957. fence [singlethread] <ordering> ; yields void
  4958. Overview:
  4959. """""""""
  4960. The '``fence``' instruction is used to introduce happens-before edges
  4961. between operations.
  4962. Arguments:
  4963. """"""""""
  4964. '``fence``' instructions take an :ref:`ordering <ordering>` argument which
  4965. defines what *synchronizes-with* edges they add. They can only be given
  4966. ``acquire``, ``release``, ``acq_rel``, and ``seq_cst`` orderings.
  4967. Semantics:
  4968. """"""""""
  4969. A fence A which has (at least) ``release`` ordering semantics
  4970. *synchronizes with* a fence B with (at least) ``acquire`` ordering
  4971. semantics if and only if there exist atomic operations X and Y, both
  4972. operating on some atomic object M, such that A is sequenced before X, X
  4973. modifies M (either directly or through some side effect of a sequence
  4974. headed by X), Y is sequenced before B, and Y observes M. This provides a
  4975. *happens-before* dependency between A and B. Rather than an explicit
  4976. ``fence``, one (but not both) of the atomic operations X or Y might
  4977. provide a ``release`` or ``acquire`` (resp.) ordering constraint and
  4978. still *synchronize-with* the explicit ``fence`` and establish the
  4979. *happens-before* edge.
  4980. A ``fence`` which has ``seq_cst`` ordering, in addition to having both
  4981. ``acquire`` and ``release`` semantics specified above, participates in
  4982. the global program order of other ``seq_cst`` operations and/or fences.
  4983. The optional ":ref:`singlethread <singlethread>`" argument specifies
  4984. that the fence only synchronizes with other fences in the same thread.
  4985. (This is useful for interacting with signal handlers.)
  4986. Example:
  4987. """"""""
  4988. .. code-block:: llvm
  4989. fence acquire ; yields void
  4990. fence singlethread seq_cst ; yields void
  4991. .. _i_cmpxchg:
  4992. '``cmpxchg``' Instruction
  4993. ^^^^^^^^^^^^^^^^^^^^^^^^^
  4994. Syntax:
  4995. """""""
  4996. ::
  4997. cmpxchg [weak] [volatile] <ty>* <pointer>, <ty> <cmp>, <ty> <new> [singlethread] <success ordering> <failure ordering> ; yields { ty, i1 }
  4998. Overview:
  4999. """""""""
  5000. The '``cmpxchg``' instruction is used to atomically modify memory. It
  5001. loads a value in memory and compares it to a given value. If they are
  5002. equal, it tries to store a new value into the memory.
  5003. Arguments:
  5004. """"""""""
  5005. There are three arguments to the '``cmpxchg``' instruction: an address
  5006. to operate on, a value to compare to the value currently be at that
  5007. address, and a new value to place at that address if the compared values
  5008. are equal. The type of '<cmp>' must be an integer type whose bit width
  5009. is a power of two greater than or equal to eight and less than or equal
  5010. to a target-specific size limit. '<cmp>' and '<new>' must have the same
  5011. type, and the type of '<pointer>' must be a pointer to that type. If the
  5012. ``cmpxchg`` is marked as ``volatile``, then the optimizer is not allowed
  5013. to modify the number or order of execution of this ``cmpxchg`` with
  5014. other :ref:`volatile operations <volatile>`.
  5015. The success and failure :ref:`ordering <ordering>` arguments specify how this
  5016. ``cmpxchg`` synchronizes with other atomic operations. Both ordering parameters
  5017. must be at least ``monotonic``, the ordering constraint on failure must be no
  5018. stronger than that on success, and the failure ordering cannot be either
  5019. ``release`` or ``acq_rel``.
  5020. The optional "``singlethread``" argument declares that the ``cmpxchg``
  5021. is only atomic with respect to code (usually signal handlers) running in
  5022. the same thread as the ``cmpxchg``. Otherwise the cmpxchg is atomic with
  5023. respect to all other code in the system.
  5024. The pointer passed into cmpxchg must have alignment greater than or
  5025. equal to the size in memory of the operand.
  5026. Semantics:
  5027. """"""""""
  5028. The contents of memory at the location specified by the '``<pointer>``' operand
  5029. is read and compared to '``<cmp>``'; if the read value is the equal, the
  5030. '``<new>``' is written. The original value at the location is returned, together
  5031. with a flag indicating success (true) or failure (false).
  5032. If the cmpxchg operation is marked as ``weak`` then a spurious failure is
  5033. permitted: the operation may not write ``<new>`` even if the comparison
  5034. matched.
  5035. If the cmpxchg operation is strong (the default), the i1 value is 1 if and only
  5036. if the value loaded equals ``cmp``.
  5037. A successful ``cmpxchg`` is a read-modify-write instruction for the purpose of
  5038. identifying release sequences. A failed ``cmpxchg`` is equivalent to an atomic
  5039. load with an ordering parameter determined the second ordering parameter.
  5040. Example:
  5041. """"""""
  5042. .. code-block:: llvm
  5043. entry:
  5044. %orig = atomic load i32, i32* %ptr unordered ; yields i32
  5045. br label %loop
  5046. loop:
  5047. %cmp = phi i32 [ %orig, %entry ], [%old, %loop]
  5048. %squared = mul i32 %cmp, %cmp
  5049. %val_success = cmpxchg i32* %ptr, i32 %cmp, i32 %squared acq_rel monotonic ; yields { i32, i1 }
  5050. %value_loaded = extractvalue { i32, i1 } %val_success, 0
  5051. %success = extractvalue { i32, i1 } %val_success, 1
  5052. br i1 %success, label %done, label %loop
  5053. done:
  5054. ...
  5055. .. _i_atomicrmw:
  5056. '``atomicrmw``' Instruction
  5057. ^^^^^^^^^^^^^^^^^^^^^^^^^^^
  5058. Syntax:
  5059. """""""
  5060. ::
  5061. atomicrmw [volatile] <operation> <ty>* <pointer>, <ty> <value> [singlethread] <ordering> ; yields ty
  5062. Overview:
  5063. """""""""
  5064. The '``atomicrmw``' instruction is used to atomically modify memory.
  5065. Arguments:
  5066. """"""""""
  5067. There are three arguments to the '``atomicrmw``' instruction: an
  5068. operation to apply, an address whose value to modify, an argument to the
  5069. operation. The operation must be one of the following keywords:
  5070. - xchg
  5071. - add
  5072. - sub
  5073. - and
  5074. - nand
  5075. - or
  5076. - xor
  5077. - max
  5078. - min
  5079. - umax
  5080. - umin
  5081. The type of '<value>' must be an integer type whose bit width is a power
  5082. of two greater than or equal to eight and less than or equal to a
  5083. target-specific size limit. The type of the '``<pointer>``' operand must
  5084. be a pointer to that type. If the ``atomicrmw`` is marked as
  5085. ``volatile``, then the optimizer is not allowed to modify the number or
  5086. order of execution of this ``atomicrmw`` with other :ref:`volatile
  5087. operations <volatile>`.
  5088. Semantics:
  5089. """"""""""
  5090. The contents of memory at the location specified by the '``<pointer>``'
  5091. operand are atomically read, modified, and written back. The original
  5092. value at the location is returned. The modification is specified by the
  5093. operation argument:
  5094. - xchg: ``*ptr = val``
  5095. - add: ``*ptr = *ptr + val``
  5096. - sub: ``*ptr = *ptr - val``
  5097. - and: ``*ptr = *ptr & val``
  5098. - nand: ``*ptr = ~(*ptr & val)``
  5099. - or: ``*ptr = *ptr | val``
  5100. - xor: ``*ptr = *ptr ^ val``
  5101. - max: ``*ptr = *ptr > val ? *ptr : val`` (using a signed comparison)
  5102. - min: ``*ptr = *ptr < val ? *ptr : val`` (using a signed comparison)
  5103. - umax: ``*ptr = *ptr > val ? *ptr : val`` (using an unsigned
  5104. comparison)
  5105. - umin: ``*ptr = *ptr < val ? *ptr : val`` (using an unsigned
  5106. comparison)
  5107. Example:
  5108. """"""""
  5109. .. code-block:: llvm
  5110. %old = atomicrmw add i32* %ptr, i32 1 acquire ; yields i32
  5111. .. _i_getelementptr:
  5112. '``getelementptr``' Instruction
  5113. ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  5114. Syntax:
  5115. """""""
  5116. ::
  5117. <result> = getelementptr <ty>, <ty>* <ptrval>{, <ty> <idx>}*
  5118. <result> = getelementptr inbounds <ty>, <ty>* <ptrval>{, <ty> <idx>}*
  5119. <result> = getelementptr <ty>, <ptr vector> <ptrval>, <vector index type> <idx>
  5120. Overview:
  5121. """""""""
  5122. The '``getelementptr``' instruction is used to get the address of a
  5123. subelement of an :ref:`aggregate <t_aggregate>` data structure. It performs
  5124. address calculation only and does not access memory. The instruction can also
  5125. be used to calculate a vector of such addresses.
  5126. Arguments:
  5127. """"""""""
  5128. The first argument is always a type used as the basis for the calculations.
  5129. The second argument is always a pointer or a vector of pointers, and is the
  5130. base address to start from. The remaining arguments are indices
  5131. that indicate which of the elements of the aggregate object are indexed.
  5132. The interpretation of each index is dependent on the type being indexed
  5133. into. The first index always indexes the pointer value given as the
  5134. first argument, the second index indexes a value of the type pointed to
  5135. (not necessarily the value directly pointed to, since the first index
  5136. can be non-zero), etc. The first type indexed into must be a pointer
  5137. value, subsequent types can be arrays, vectors, and structs. Note that
  5138. subsequent types being indexed into can never be pointers, since that
  5139. would require loading the pointer before continuing calculation.
  5140. The type of each index argument depends on the type it is indexing into.
  5141. When indexing into a (optionally packed) structure, only ``i32`` integer
  5142. **constants** are allowed (when using a vector of indices they must all
  5143. be the **same** ``i32`` integer constant). When indexing into an array,
  5144. pointer or vector, integers of any width are allowed, and they are not
  5145. required to be constant. These integers are treated as signed values
  5146. where relevant.
  5147. For example, let's consider a C code fragment and how it gets compiled
  5148. to LLVM:
  5149. .. code-block:: c
  5150. struct RT {
  5151. char A;
  5152. int B[10][20];
  5153. char C;
  5154. };
  5155. struct ST {
  5156. int X;
  5157. double Y;
  5158. struct RT Z;
  5159. };
  5160. int *foo(struct ST *s) {
  5161. return &s[1].Z.B[5][13];
  5162. }
  5163. The LLVM code generated by Clang is:
  5164. .. code-block:: llvm
  5165. %struct.RT = type { i8, [10 x [20 x i32]], i8 }
  5166. %struct.ST = type { i32, double, %struct.RT }
  5167. define i32* @foo(%struct.ST* %s) nounwind uwtable readnone optsize ssp {
  5168. entry:
  5169. %arrayidx = getelementptr inbounds %struct.ST, %struct.ST* %s, i64 1, i32 2, i32 1, i64 5, i64 13
  5170. ret i32* %arrayidx
  5171. }
  5172. Semantics:
  5173. """"""""""
  5174. In the example above, the first index is indexing into the
  5175. '``%struct.ST*``' type, which is a pointer, yielding a '``%struct.ST``'
  5176. = '``{ i32, double, %struct.RT }``' type, a structure. The second index
  5177. indexes into the third element of the structure, yielding a
  5178. '``%struct.RT``' = '``{ i8 , [10 x [20 x i32]], i8 }``' type, another
  5179. structure. The third index indexes into the second element of the
  5180. structure, yielding a '``[10 x [20 x i32]]``' type, an array. The two
  5181. dimensions of the array are subscripted into, yielding an '``i32``'
  5182. type. The '``getelementptr``' instruction returns a pointer to this
  5183. element, thus computing a value of '``i32*``' type.
  5184. Note that it is perfectly legal to index partially through a structure,
  5185. returning a pointer to an inner element. Because of this, the LLVM code
  5186. for the given testcase is equivalent to:
  5187. .. code-block:: llvm
  5188. define i32* @foo(%struct.ST* %s) {
  5189. %t1 = getelementptr %struct.ST, %struct.ST* %s, i32 1 ; yields %struct.ST*:%t1
  5190. %t2 = getelementptr %struct.ST, %struct.ST* %t1, i32 0, i32 2 ; yields %struct.RT*:%t2
  5191. %t3 = getelementptr %struct.RT, %struct.RT* %t2, i32 0, i32 1 ; yields [10 x [20 x i32]]*:%t3
  5192. %t4 = getelementptr [10 x [20 x i32]], [10 x [20 x i32]]* %t3, i32 0, i32 5 ; yields [20 x i32]*:%t4
  5193. %t5 = getelementptr [20 x i32], [20 x i32]* %t4, i32 0, i32 13 ; yields i32*:%t5
  5194. ret i32* %t5
  5195. }
  5196. If the ``inbounds`` keyword is present, the result value of the
  5197. ``getelementptr`` is a :ref:`poison value <poisonvalues>` if the base
  5198. pointer is not an *in bounds* address of an allocated object, or if any
  5199. of the addresses that would be formed by successive addition of the
  5200. offsets implied by the indices to the base address with infinitely
  5201. precise signed arithmetic are not an *in bounds* address of that
  5202. allocated object. The *in bounds* addresses for an allocated object are
  5203. all the addresses that point into the object, plus the address one byte
  5204. past the end. In cases where the base is a vector of pointers the
  5205. ``inbounds`` keyword applies to each of the computations element-wise.
  5206. If the ``inbounds`` keyword is not present, the offsets are added to the
  5207. base address with silently-wrapping two's complement arithmetic. If the
  5208. offsets have a different width from the pointer, they are sign-extended
  5209. or truncated to the width of the pointer. The result value of the
  5210. ``getelementptr`` may be outside the object pointed to by the base
  5211. pointer. The result value may not necessarily be used to access memory
  5212. though, even if it happens to point into allocated storage. See the
  5213. :ref:`Pointer Aliasing Rules <pointeraliasing>` section for more
  5214. information.
  5215. The getelementptr instruction is often confusing. For some more insight
  5216. into how it works, see :doc:`the getelementptr FAQ <GetElementPtr>`.
  5217. Example:
  5218. """"""""
  5219. .. code-block:: llvm
  5220. ; yields [12 x i8]*:aptr
  5221. %aptr = getelementptr {i32, [12 x i8]}, {i32, [12 x i8]}* %saptr, i64 0, i32 1
  5222. ; yields i8*:vptr
  5223. %vptr = getelementptr {i32, <2 x i8>}, {i32, <2 x i8>}* %svptr, i64 0, i32 1, i32 1
  5224. ; yields i8*:eptr
  5225. %eptr = getelementptr [12 x i8], [12 x i8]* %aptr, i64 0, i32 1
  5226. ; yields i32*:iptr
  5227. %iptr = getelementptr [10 x i32], [10 x i32]* @arr, i16 0, i16 0
  5228. Vector of pointers:
  5229. """""""""""""""""""
  5230. The ``getelementptr`` returns a vector of pointers, instead of a single address,
  5231. when one or more of its arguments is a vector. In such cases, all vector
  5232. arguments should have the same number of elements, and every scalar argument
  5233. will be effectively broadcast into a vector during address calculation.
  5234. .. code-block:: llvm
  5235. ; All arguments are vectors:
  5236. ; A[i] = ptrs[i] + offsets[i]*sizeof(i8)
  5237. %A = getelementptr i8, <4 x i8*> %ptrs, <4 x i64> %offsets
  5238. ; Add the same scalar offset to each pointer of a vector:
  5239. ; A[i] = ptrs[i] + offset*sizeof(i8)
  5240. %A = getelementptr i8, <4 x i8*> %ptrs, i64 %offset
  5241. ; Add distinct offsets to the same pointer:
  5242. ; A[i] = ptr + offsets[i]*sizeof(i8)
  5243. %A = getelementptr i8, i8* %ptr, <4 x i64> %offsets
  5244. ; In all cases described above the type of the result is <4 x i8*>
  5245. The two following instructions are equivalent:
  5246. .. code-block:: llvm
  5247. getelementptr %struct.ST, <4 x %struct.ST*> %s, <4 x i64> %ind1,
  5248. <4 x i32> <i32 2, i32 2, i32 2, i32 2>,
  5249. <4 x i32> <i32 1, i32 1, i32 1, i32 1>,
  5250. <4 x i32> %ind4,
  5251. <4 x i64> <i64 13, i64 13, i64 13, i64 13>
  5252. getelementptr %struct.ST, <4 x %struct.ST*> %s, <4 x i64> %ind1,
  5253. i32 2, i32 1, <4 x i32> %ind4, i64 13
  5254. Let's look at the C code, where the vector version of ``getelementptr``
  5255. makes sense:
  5256. .. code-block:: c
  5257. // Let's assume that we vectorize the following loop:
  5258. double *A, B; int *C;
  5259. for (int i = 0; i < size; ++i) {
  5260. A[i] = B[C[i]];
  5261. }
  5262. .. code-block:: llvm
  5263. ; get pointers for 8 elements from array B
  5264. %ptrs = getelementptr double, double* %B, <8 x i32> %C
  5265. ; load 8 elements from array B into A
  5266. %A = call <8 x double> @llvm.masked.gather.v8f64(<8 x double*> %ptrs,
  5267. i32 8, <8 x i1> %mask, <8 x double> %passthru)
  5268. Conversion Operations
  5269. ---------------------
  5270. The instructions in this category are the conversion instructions
  5271. (casting) which all take a single operand and a type. They perform
  5272. various bit conversions on the operand.
  5273. '``trunc .. to``' Instruction
  5274. ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  5275. Syntax:
  5276. """""""
  5277. ::
  5278. <result> = trunc <ty> <value> to <ty2> ; yields ty2
  5279. Overview:
  5280. """""""""
  5281. The '``trunc``' instruction truncates its operand to the type ``ty2``.
  5282. Arguments:
  5283. """"""""""
  5284. The '``trunc``' instruction takes a value to trunc, and a type to trunc
  5285. it to. Both types must be of :ref:`integer <t_integer>` types, or vectors
  5286. of the same number of integers. The bit size of the ``value`` must be
  5287. larger than the bit size of the destination type, ``ty2``. Equal sized
  5288. types are not allowed.
  5289. Semantics:
  5290. """"""""""
  5291. The '``trunc``' instruction truncates the high order bits in ``value``
  5292. and converts the remaining bits to ``ty2``. Since the source size must
  5293. be larger than the destination size, ``trunc`` cannot be a *no-op cast*.
  5294. It will always truncate bits.
  5295. Example:
  5296. """"""""
  5297. .. code-block:: llvm
  5298. %X = trunc i32 257 to i8 ; yields i8:1
  5299. %Y = trunc i32 123 to i1 ; yields i1:true
  5300. %Z = trunc i32 122 to i1 ; yields i1:false
  5301. %W = trunc <2 x i16> <i16 8, i16 7> to <2 x i8> ; yields <i8 8, i8 7>
  5302. '``zext .. to``' Instruction
  5303. ^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  5304. Syntax:
  5305. """""""
  5306. ::
  5307. <result> = zext <ty> <value> to <ty2> ; yields ty2
  5308. Overview:
  5309. """""""""
  5310. The '``zext``' instruction zero extends its operand to type ``ty2``.
  5311. Arguments:
  5312. """"""""""
  5313. The '``zext``' instruction takes a value to cast, and a type to cast it
  5314. to. Both types must be of :ref:`integer <t_integer>` types, or vectors of
  5315. the same number of integers. The bit size of the ``value`` must be
  5316. smaller than the bit size of the destination type, ``ty2``.
  5317. Semantics:
  5318. """"""""""
  5319. The ``zext`` fills the high order bits of the ``value`` with zero bits
  5320. until it reaches the size of the destination type, ``ty2``.
  5321. When zero extending from i1, the result will always be either 0 or 1.
  5322. Example:
  5323. """"""""
  5324. .. code-block:: llvm
  5325. %X = zext i32 257 to i64 ; yields i64:257
  5326. %Y = zext i1 true to i32 ; yields i32:1
  5327. %Z = zext <2 x i16> <i16 8, i16 7> to <2 x i32> ; yields <i32 8, i32 7>
  5328. '``sext .. to``' Instruction
  5329. ^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  5330. Syntax:
  5331. """""""
  5332. ::
  5333. <result> = sext <ty> <value> to <ty2> ; yields ty2
  5334. Overview:
  5335. """""""""
  5336. The '``sext``' sign extends ``value`` to the type ``ty2``.
  5337. Arguments:
  5338. """"""""""
  5339. The '``sext``' instruction takes a value to cast, and a type to cast it
  5340. to. Both types must be of :ref:`integer <t_integer>` types, or vectors of
  5341. the same number of integers. The bit size of the ``value`` must be
  5342. smaller than the bit size of the destination type, ``ty2``.
  5343. Semantics:
  5344. """"""""""
  5345. The '``sext``' instruction performs a sign extension by copying the sign
  5346. bit (highest order bit) of the ``value`` until it reaches the bit size
  5347. of the type ``ty2``.
  5348. When sign extending from i1, the extension always results in -1 or 0.
  5349. Example:
  5350. """"""""
  5351. .. code-block:: llvm
  5352. %X = sext i8 -1 to i16 ; yields i16 :65535
  5353. %Y = sext i1 true to i32 ; yields i32:-1
  5354. %Z = sext <2 x i16> <i16 8, i16 7> to <2 x i32> ; yields <i32 8, i32 7>
  5355. '``fptrunc .. to``' Instruction
  5356. ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  5357. Syntax:
  5358. """""""
  5359. ::
  5360. <result> = fptrunc <ty> <value> to <ty2> ; yields ty2
  5361. Overview:
  5362. """""""""
  5363. The '``fptrunc``' instruction truncates ``value`` to type ``ty2``.
  5364. Arguments:
  5365. """"""""""
  5366. The '``fptrunc``' instruction takes a :ref:`floating point <t_floating>`
  5367. value to cast and a :ref:`floating point <t_floating>` type to cast it to.
  5368. The size of ``value`` must be larger than the size of ``ty2``. This
  5369. implies that ``fptrunc`` cannot be used to make a *no-op cast*.
  5370. Semantics:
  5371. """"""""""
  5372. The '``fptrunc``' instruction truncates a ``value`` from a larger
  5373. :ref:`floating point <t_floating>` type to a smaller :ref:`floating
  5374. point <t_floating>` type. If the value cannot fit within the
  5375. destination type, ``ty2``, then the results are undefined.
  5376. Example:
  5377. """"""""
  5378. .. code-block:: llvm
  5379. %X = fptrunc double 123.0 to float ; yields float:123.0
  5380. %Y = fptrunc double 1.0E+300 to float ; yields undefined
  5381. '``fpext .. to``' Instruction
  5382. ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  5383. Syntax:
  5384. """""""
  5385. ::
  5386. <result> = fpext <ty> <value> to <ty2> ; yields ty2
  5387. Overview:
  5388. """""""""
  5389. The '``fpext``' extends a floating point ``value`` to a larger floating
  5390. point value.
  5391. Arguments:
  5392. """"""""""
  5393. The '``fpext``' instruction takes a :ref:`floating point <t_floating>`
  5394. ``value`` to cast, and a :ref:`floating point <t_floating>` type to cast it
  5395. to. The source type must be smaller than the destination type.
  5396. Semantics:
  5397. """"""""""
  5398. The '``fpext``' instruction extends the ``value`` from a smaller
  5399. :ref:`floating point <t_floating>` type to a larger :ref:`floating
  5400. point <t_floating>` type. The ``fpext`` cannot be used to make a
  5401. *no-op cast* because it always changes bits. Use ``bitcast`` to make a
  5402. *no-op cast* for a floating point cast.
  5403. Example:
  5404. """"""""
  5405. .. code-block:: llvm
  5406. %X = fpext float 3.125 to double ; yields double:3.125000e+00
  5407. %Y = fpext double %X to fp128 ; yields fp128:0xL00000000000000004000900000000000
  5408. '``fptoui .. to``' Instruction
  5409. ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  5410. Syntax:
  5411. """""""
  5412. ::
  5413. <result> = fptoui <ty> <value> to <ty2> ; yields ty2
  5414. Overview:
  5415. """""""""
  5416. The '``fptoui``' converts a floating point ``value`` to its unsigned
  5417. integer equivalent of type ``ty2``.
  5418. Arguments:
  5419. """"""""""
  5420. The '``fptoui``' instruction takes a value to cast, which must be a
  5421. scalar or vector :ref:`floating point <t_floating>` value, and a type to
  5422. cast it to ``ty2``, which must be an :ref:`integer <t_integer>` type. If
  5423. ``ty`` is a vector floating point type, ``ty2`` must be a vector integer
  5424. type with the same number of elements as ``ty``
  5425. Semantics:
  5426. """"""""""
  5427. The '``fptoui``' instruction converts its :ref:`floating
  5428. point <t_floating>` operand into the nearest (rounding towards zero)
  5429. unsigned integer value. If the value cannot fit in ``ty2``, the results
  5430. are undefined.
  5431. Example:
  5432. """"""""
  5433. .. code-block:: llvm
  5434. %X = fptoui double 123.0 to i32 ; yields i32:123
  5435. %Y = fptoui float 1.0E+300 to i1 ; yields undefined:1
  5436. %Z = fptoui float 1.04E+17 to i8 ; yields undefined:1
  5437. '``fptosi .. to``' Instruction
  5438. ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  5439. Syntax:
  5440. """""""
  5441. ::
  5442. <result> = fptosi <ty> <value> to <ty2> ; yields ty2
  5443. Overview:
  5444. """""""""
  5445. The '``fptosi``' instruction converts :ref:`floating point <t_floating>`
  5446. ``value`` to type ``ty2``.
  5447. Arguments:
  5448. """"""""""
  5449. The '``fptosi``' instruction takes a value to cast, which must be a
  5450. scalar or vector :ref:`floating point <t_floating>` value, and a type to
  5451. cast it to ``ty2``, which must be an :ref:`integer <t_integer>` type. If
  5452. ``ty`` is a vector floating point type, ``ty2`` must be a vector integer
  5453. type with the same number of elements as ``ty``
  5454. Semantics:
  5455. """"""""""
  5456. The '``fptosi``' instruction converts its :ref:`floating
  5457. point <t_floating>` operand into the nearest (rounding towards zero)
  5458. signed integer value. If the value cannot fit in ``ty2``, the results
  5459. are undefined.
  5460. Example:
  5461. """"""""
  5462. .. code-block:: llvm
  5463. %X = fptosi double -123.0 to i32 ; yields i32:-123
  5464. %Y = fptosi float 1.0E-247 to i1 ; yields undefined:1
  5465. %Z = fptosi float 1.04E+17 to i8 ; yields undefined:1
  5466. '``uitofp .. to``' Instruction
  5467. ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  5468. Syntax:
  5469. """""""
  5470. ::
  5471. <result> = uitofp <ty> <value> to <ty2> ; yields ty2
  5472. Overview:
  5473. """""""""
  5474. The '``uitofp``' instruction regards ``value`` as an unsigned integer
  5475. and converts that value to the ``ty2`` type.
  5476. Arguments:
  5477. """"""""""
  5478. The '``uitofp``' instruction takes a value to cast, which must be a
  5479. scalar or vector :ref:`integer <t_integer>` value, and a type to cast it to
  5480. ``ty2``, which must be an :ref:`floating point <t_floating>` type. If
  5481. ``ty`` is a vector integer type, ``ty2`` must be a vector floating point
  5482. type with the same number of elements as ``ty``
  5483. Semantics:
  5484. """"""""""
  5485. The '``uitofp``' instruction interprets its operand as an unsigned
  5486. integer quantity and converts it to the corresponding floating point
  5487. value. If the value cannot fit in the floating point value, the results
  5488. are undefined.
  5489. Example:
  5490. """"""""
  5491. .. code-block:: llvm
  5492. %X = uitofp i32 257 to float ; yields float:257.0
  5493. %Y = uitofp i8 -1 to double ; yields double:255.0
  5494. '``sitofp .. to``' Instruction
  5495. ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  5496. Syntax:
  5497. """""""
  5498. ::
  5499. <result> = sitofp <ty> <value> to <ty2> ; yields ty2
  5500. Overview:
  5501. """""""""
  5502. The '``sitofp``' instruction regards ``value`` as a signed integer and
  5503. converts that value to the ``ty2`` type.
  5504. Arguments:
  5505. """"""""""
  5506. The '``sitofp``' instruction takes a value to cast, which must be a
  5507. scalar or vector :ref:`integer <t_integer>` value, and a type to cast it to
  5508. ``ty2``, which must be an :ref:`floating point <t_floating>` type. If
  5509. ``ty`` is a vector integer type, ``ty2`` must be a vector floating point
  5510. type with the same number of elements as ``ty``
  5511. Semantics:
  5512. """"""""""
  5513. The '``sitofp``' instruction interprets its operand as a signed integer
  5514. quantity and converts it to the corresponding floating point value. If
  5515. the value cannot fit in the floating point value, the results are
  5516. undefined.
  5517. Example:
  5518. """"""""
  5519. .. code-block:: llvm
  5520. %X = sitofp i32 257 to float ; yields float:257.0
  5521. %Y = sitofp i8 -1 to double ; yields double:-1.0
  5522. .. _i_ptrtoint:
  5523. '``ptrtoint .. to``' Instruction
  5524. ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  5525. Syntax:
  5526. """""""
  5527. ::
  5528. <result> = ptrtoint <ty> <value> to <ty2> ; yields ty2
  5529. Overview:
  5530. """""""""
  5531. The '``ptrtoint``' instruction converts the pointer or a vector of
  5532. pointers ``value`` to the integer (or vector of integers) type ``ty2``.
  5533. Arguments:
  5534. """"""""""
  5535. The '``ptrtoint``' instruction takes a ``value`` to cast, which must be
  5536. a value of type :ref:`pointer <t_pointer>` or a vector of pointers, and a
  5537. type to cast it to ``ty2``, which must be an :ref:`integer <t_integer>` or
  5538. a vector of integers type.
  5539. Semantics:
  5540. """"""""""
  5541. The '``ptrtoint``' instruction converts ``value`` to integer type
  5542. ``ty2`` by interpreting the pointer value as an integer and either
  5543. truncating or zero extending that value to the size of the integer type.
  5544. If ``value`` is smaller than ``ty2`` then a zero extension is done. If
  5545. ``value`` is larger than ``ty2`` then a truncation is done. If they are
  5546. the same size, then nothing is done (*no-op cast*) other than a type
  5547. change.
  5548. Example:
  5549. """"""""
  5550. .. code-block:: llvm
  5551. %X = ptrtoint i32* %P to i8 ; yields truncation on 32-bit architecture
  5552. %Y = ptrtoint i32* %P to i64 ; yields zero extension on 32-bit architecture
  5553. %Z = ptrtoint <4 x i32*> %P to <4 x i64>; yields vector zero extension for a vector of addresses on 32-bit architecture
  5554. .. _i_inttoptr:
  5555. '``inttoptr .. to``' Instruction
  5556. ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  5557. Syntax:
  5558. """""""
  5559. ::
  5560. <result> = inttoptr <ty> <value> to <ty2> ; yields ty2
  5561. Overview:
  5562. """""""""
  5563. The '``inttoptr``' instruction converts an integer ``value`` to a
  5564. pointer type, ``ty2``.
  5565. Arguments:
  5566. """"""""""
  5567. The '``inttoptr``' instruction takes an :ref:`integer <t_integer>` value to
  5568. cast, and a type to cast it to, which must be a :ref:`pointer <t_pointer>`
  5569. type.
  5570. Semantics:
  5571. """"""""""
  5572. The '``inttoptr``' instruction converts ``value`` to type ``ty2`` by
  5573. applying either a zero extension or a truncation depending on the size
  5574. of the integer ``value``. If ``value`` is larger than the size of a
  5575. pointer then a truncation is done. If ``value`` is smaller than the size
  5576. of a pointer then a zero extension is done. If they are the same size,
  5577. nothing is done (*no-op cast*).
  5578. Example:
  5579. """"""""
  5580. .. code-block:: llvm
  5581. %X = inttoptr i32 255 to i32* ; yields zero extension on 64-bit architecture
  5582. %Y = inttoptr i32 255 to i32* ; yields no-op on 32-bit architecture
  5583. %Z = inttoptr i64 0 to i32* ; yields truncation on 32-bit architecture
  5584. %Z = inttoptr <4 x i32> %G to <4 x i8*>; yields truncation of vector G to four pointers
  5585. .. _i_bitcast:
  5586. '``bitcast .. to``' Instruction
  5587. ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  5588. Syntax:
  5589. """""""
  5590. ::
  5591. <result> = bitcast <ty> <value> to <ty2> ; yields ty2
  5592. Overview:
  5593. """""""""
  5594. The '``bitcast``' instruction converts ``value`` to type ``ty2`` without
  5595. changing any bits.
  5596. Arguments:
  5597. """"""""""
  5598. The '``bitcast``' instruction takes a value to cast, which must be a
  5599. non-aggregate first class value, and a type to cast it to, which must
  5600. also be a non-aggregate :ref:`first class <t_firstclass>` type. The
  5601. bit sizes of ``value`` and the destination type, ``ty2``, must be
  5602. identical. If the source type is a pointer, the destination type must
  5603. also be a pointer of the same size. This instruction supports bitwise
  5604. conversion of vectors to integers and to vectors of other types (as
  5605. long as they have the same size).
  5606. Semantics:
  5607. """"""""""
  5608. The '``bitcast``' instruction converts ``value`` to type ``ty2``. It
  5609. is always a *no-op cast* because no bits change with this
  5610. conversion. The conversion is done as if the ``value`` had been stored
  5611. to memory and read back as type ``ty2``. Pointer (or vector of
  5612. pointers) types may only be converted to other pointer (or vector of
  5613. pointers) types with the same address space through this instruction.
  5614. To convert pointers to other types, use the :ref:`inttoptr <i_inttoptr>`
  5615. or :ref:`ptrtoint <i_ptrtoint>` instructions first.
  5616. Example:
  5617. """"""""
  5618. .. code-block:: llvm
  5619. %X = bitcast i8 255 to i8 ; yields i8 :-1
  5620. %Y = bitcast i32* %x to sint* ; yields sint*:%x
  5621. %Z = bitcast <2 x int> %V to i64; ; yields i64: %V
  5622. %Z = bitcast <2 x i32*> %V to <2 x i64*> ; yields <2 x i64*>
  5623. .. _i_addrspacecast:
  5624. '``addrspacecast .. to``' Instruction
  5625. ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  5626. Syntax:
  5627. """""""
  5628. ::
  5629. <result> = addrspacecast <pty> <ptrval> to <pty2> ; yields pty2
  5630. Overview:
  5631. """""""""
  5632. The '``addrspacecast``' instruction converts ``ptrval`` from ``pty`` in
  5633. address space ``n`` to type ``pty2`` in address space ``m``.
  5634. Arguments:
  5635. """"""""""
  5636. The '``addrspacecast``' instruction takes a pointer or vector of pointer value
  5637. to cast and a pointer type to cast it to, which must have a different
  5638. address space.
  5639. Semantics:
  5640. """"""""""
  5641. The '``addrspacecast``' instruction converts the pointer value
  5642. ``ptrval`` to type ``pty2``. It can be a *no-op cast* or a complex
  5643. value modification, depending on the target and the address space
  5644. pair. Pointer conversions within the same address space must be
  5645. performed with the ``bitcast`` instruction. Note that if the address space
  5646. conversion is legal then both result and operand refer to the same memory
  5647. location.
  5648. Example:
  5649. """"""""
  5650. .. code-block:: llvm
  5651. %X = addrspacecast i32* %x to i32 addrspace(1)* ; yields i32 addrspace(1)*:%x
  5652. %Y = addrspacecast i32 addrspace(1)* %y to i64 addrspace(2)* ; yields i64 addrspace(2)*:%y
  5653. %Z = addrspacecast <4 x i32*> %z to <4 x float addrspace(3)*> ; yields <4 x float addrspace(3)*>:%z
  5654. .. _otherops:
  5655. Other Operations
  5656. ----------------
  5657. The instructions in this category are the "miscellaneous" instructions,
  5658. which defy better classification.
  5659. .. _i_icmp:
  5660. '``icmp``' Instruction
  5661. ^^^^^^^^^^^^^^^^^^^^^^
  5662. Syntax:
  5663. """""""
  5664. ::
  5665. <result> = icmp <cond> <ty> <op1>, <op2> ; yields i1 or <N x i1>:result
  5666. Overview:
  5667. """""""""
  5668. The '``icmp``' instruction returns a boolean value or a vector of
  5669. boolean values based on comparison of its two integer, integer vector,
  5670. pointer, or pointer vector operands.
  5671. Arguments:
  5672. """"""""""
  5673. The '``icmp``' instruction takes three operands. The first operand is
  5674. the condition code indicating the kind of comparison to perform. It is
  5675. not a value, just a keyword. The possible condition code are:
  5676. #. ``eq``: equal
  5677. #. ``ne``: not equal
  5678. #. ``ugt``: unsigned greater than
  5679. #. ``uge``: unsigned greater or equal
  5680. #. ``ult``: unsigned less than
  5681. #. ``ule``: unsigned less or equal
  5682. #. ``sgt``: signed greater than
  5683. #. ``sge``: signed greater or equal
  5684. #. ``slt``: signed less than
  5685. #. ``sle``: signed less or equal
  5686. The remaining two arguments must be :ref:`integer <t_integer>` or
  5687. :ref:`pointer <t_pointer>` or integer :ref:`vector <t_vector>` typed. They
  5688. must also be identical types.
  5689. Semantics:
  5690. """"""""""
  5691. The '``icmp``' compares ``op1`` and ``op2`` according to the condition
  5692. code given as ``cond``. The comparison performed always yields either an
  5693. :ref:`i1 <t_integer>` or vector of ``i1`` result, as follows:
  5694. #. ``eq``: yields ``true`` if the operands are equal, ``false``
  5695. otherwise. No sign interpretation is necessary or performed.
  5696. #. ``ne``: yields ``true`` if the operands are unequal, ``false``
  5697. otherwise. No sign interpretation is necessary or performed.
  5698. #. ``ugt``: interprets the operands as unsigned values and yields
  5699. ``true`` if ``op1`` is greater than ``op2``.
  5700. #. ``uge``: interprets the operands as unsigned values and yields
  5701. ``true`` if ``op1`` is greater than or equal to ``op2``.
  5702. #. ``ult``: interprets the operands as unsigned values and yields
  5703. ``true`` if ``op1`` is less than ``op2``.
  5704. #. ``ule``: interprets the operands as unsigned values and yields
  5705. ``true`` if ``op1`` is less than or equal to ``op2``.
  5706. #. ``sgt``: interprets the operands as signed values and yields ``true``
  5707. if ``op1`` is greater than ``op2``.
  5708. #. ``sge``: interprets the operands as signed values and yields ``true``
  5709. if ``op1`` is greater than or equal to ``op2``.
  5710. #. ``slt``: interprets the operands as signed values and yields ``true``
  5711. if ``op1`` is less than ``op2``.
  5712. #. ``sle``: interprets the operands as signed values and yields ``true``
  5713. if ``op1`` is less than or equal to ``op2``.
  5714. If the operands are :ref:`pointer <t_pointer>` typed, the pointer values
  5715. are compared as if they were integers.
  5716. If the operands are integer vectors, then they are compared element by
  5717. element. The result is an ``i1`` vector with the same number of elements
  5718. as the values being compared. Otherwise, the result is an ``i1``.
  5719. Example:
  5720. """"""""
  5721. .. code-block:: llvm
  5722. <result> = icmp eq i32 4, 5 ; yields: result=false
  5723. <result> = icmp ne float* %X, %X ; yields: result=false
  5724. <result> = icmp ult i16 4, 5 ; yields: result=true
  5725. <result> = icmp sgt i16 4, 5 ; yields: result=false
  5726. <result> = icmp ule i16 -4, 5 ; yields: result=false
  5727. <result> = icmp sge i16 4, 5 ; yields: result=false
  5728. Note that the code generator does not yet support vector types with the
  5729. ``icmp`` instruction.
  5730. .. _i_fcmp:
  5731. '``fcmp``' Instruction
  5732. ^^^^^^^^^^^^^^^^^^^^^^
  5733. Syntax:
  5734. """""""
  5735. ::
  5736. <result> = fcmp [fast-math flags]* <cond> <ty> <op1>, <op2> ; yields i1 or <N x i1>:result
  5737. Overview:
  5738. """""""""
  5739. The '``fcmp``' instruction returns a boolean value or vector of boolean
  5740. values based on comparison of its operands.
  5741. If the operands are floating point scalars, then the result type is a
  5742. boolean (:ref:`i1 <t_integer>`).
  5743. If the operands are floating point vectors, then the result type is a
  5744. vector of boolean with the same number of elements as the operands being
  5745. compared.
  5746. Arguments:
  5747. """"""""""
  5748. The '``fcmp``' instruction takes three operands. The first operand is
  5749. the condition code indicating the kind of comparison to perform. It is
  5750. not a value, just a keyword. The possible condition code are:
  5751. #. ``false``: no comparison, always returns false
  5752. #. ``oeq``: ordered and equal
  5753. #. ``ogt``: ordered and greater than
  5754. #. ``oge``: ordered and greater than or equal
  5755. #. ``olt``: ordered and less than
  5756. #. ``ole``: ordered and less than or equal
  5757. #. ``one``: ordered and not equal
  5758. #. ``ord``: ordered (no nans)
  5759. #. ``ueq``: unordered or equal
  5760. #. ``ugt``: unordered or greater than
  5761. #. ``uge``: unordered or greater than or equal
  5762. #. ``ult``: unordered or less than
  5763. #. ``ule``: unordered or less than or equal
  5764. #. ``une``: unordered or not equal
  5765. #. ``uno``: unordered (either nans)
  5766. #. ``true``: no comparison, always returns true
  5767. *Ordered* means that neither operand is a QNAN while *unordered* means
  5768. that either operand may be a QNAN.
  5769. Each of ``val1`` and ``val2`` arguments must be either a :ref:`floating
  5770. point <t_floating>` type or a :ref:`vector <t_vector>` of floating point
  5771. type. They must have identical types.
  5772. Semantics:
  5773. """"""""""
  5774. The '``fcmp``' instruction compares ``op1`` and ``op2`` according to the
  5775. condition code given as ``cond``. If the operands are vectors, then the
  5776. vectors are compared element by element. Each comparison performed
  5777. always yields an :ref:`i1 <t_integer>` result, as follows:
  5778. #. ``false``: always yields ``false``, regardless of operands.
  5779. #. ``oeq``: yields ``true`` if both operands are not a QNAN and ``op1``
  5780. is equal to ``op2``.
  5781. #. ``ogt``: yields ``true`` if both operands are not a QNAN and ``op1``
  5782. is greater than ``op2``.
  5783. #. ``oge``: yields ``true`` if both operands are not a QNAN and ``op1``
  5784. is greater than or equal to ``op2``.
  5785. #. ``olt``: yields ``true`` if both operands are not a QNAN and ``op1``
  5786. is less than ``op2``.
  5787. #. ``ole``: yields ``true`` if both operands are not a QNAN and ``op1``
  5788. is less than or equal to ``op2``.
  5789. #. ``one``: yields ``true`` if both operands are not a QNAN and ``op1``
  5790. is not equal to ``op2``.
  5791. #. ``ord``: yields ``true`` if both operands are not a QNAN.
  5792. #. ``ueq``: yields ``true`` if either operand is a QNAN or ``op1`` is
  5793. equal to ``op2``.
  5794. #. ``ugt``: yields ``true`` if either operand is a QNAN or ``op1`` is
  5795. greater than ``op2``.
  5796. #. ``uge``: yields ``true`` if either operand is a QNAN or ``op1`` is
  5797. greater than or equal to ``op2``.
  5798. #. ``ult``: yields ``true`` if either operand is a QNAN or ``op1`` is
  5799. less than ``op2``.
  5800. #. ``ule``: yields ``true`` if either operand is a QNAN or ``op1`` is
  5801. less than or equal to ``op2``.
  5802. #. ``une``: yields ``true`` if either operand is a QNAN or ``op1`` is
  5803. not equal to ``op2``.
  5804. #. ``uno``: yields ``true`` if either operand is a QNAN.
  5805. #. ``true``: always yields ``true``, regardless of operands.
  5806. The ``fcmp`` instruction can also optionally take any number of
  5807. :ref:`fast-math flags <fastmath>`, which are optimization hints to enable
  5808. otherwise unsafe floating point optimizations.
  5809. Any set of fast-math flags are legal on an ``fcmp`` instruction, but the
  5810. only flags that have any effect on its semantics are those that allow
  5811. assumptions to be made about the values of input arguments; namely
  5812. ``nnan``, ``ninf``, and ``nsz``. See :ref:`fastmath` for more information.
  5813. Example:
  5814. """"""""
  5815. .. code-block:: llvm
  5816. <result> = fcmp oeq float 4.0, 5.0 ; yields: result=false
  5817. <result> = fcmp one float 4.0, 5.0 ; yields: result=true
  5818. <result> = fcmp olt float 4.0, 5.0 ; yields: result=true
  5819. <result> = fcmp ueq double 1.0, 2.0 ; yields: result=false
  5820. Note that the code generator does not yet support vector types with the
  5821. ``fcmp`` instruction.
  5822. .. _i_phi:
  5823. '``phi``' Instruction
  5824. ^^^^^^^^^^^^^^^^^^^^^
  5825. Syntax:
  5826. """""""
  5827. ::
  5828. <result> = phi <ty> [ <val0>, <label0>], ...
  5829. Overview:
  5830. """""""""
  5831. The '``phi``' instruction is used to implement the φ node in the SSA
  5832. graph representing the function.
  5833. Arguments:
  5834. """"""""""
  5835. The type of the incoming values is specified with the first type field.
  5836. After this, the '``phi``' instruction takes a list of pairs as
  5837. arguments, with one pair for each predecessor basic block of the current
  5838. block. Only values of :ref:`first class <t_firstclass>` type may be used as
  5839. the value arguments to the PHI node. Only labels may be used as the
  5840. label arguments.
  5841. There must be no non-phi instructions between the start of a basic block
  5842. and the PHI instructions: i.e. PHI instructions must be first in a basic
  5843. block.
  5844. For the purposes of the SSA form, the use of each incoming value is
  5845. deemed to occur on the edge from the corresponding predecessor block to
  5846. the current block (but after any definition of an '``invoke``'
  5847. instruction's return value on the same edge).
  5848. Semantics:
  5849. """"""""""
  5850. At runtime, the '``phi``' instruction logically takes on the value
  5851. specified by the pair corresponding to the predecessor basic block that
  5852. executed just prior to the current block.
  5853. Example:
  5854. """"""""
  5855. .. code-block:: llvm
  5856. Loop: ; Infinite loop that counts from 0 on up...
  5857. %indvar = phi i32 [ 0, %LoopHeader ], [ %nextindvar, %Loop ]
  5858. %nextindvar = add i32 %indvar, 1
  5859. br label %Loop
  5860. .. _i_select:
  5861. '``select``' Instruction
  5862. ^^^^^^^^^^^^^^^^^^^^^^^^
  5863. Syntax:
  5864. """""""
  5865. ::
  5866. <result> = select selty <cond>, <ty> <val1>, <ty> <val2> ; yields ty
  5867. selty is either i1 or {<N x i1>}
  5868. Overview:
  5869. """""""""
  5870. The '``select``' instruction is used to choose one value based on a
  5871. condition, without IR-level branching.
  5872. Arguments:
  5873. """"""""""
  5874. The '``select``' instruction requires an 'i1' value or a vector of 'i1'
  5875. values indicating the condition, and two values of the same :ref:`first
  5876. class <t_firstclass>` type.
  5877. Semantics:
  5878. """"""""""
  5879. If the condition is an i1 and it evaluates to 1, the instruction returns
  5880. the first value argument; otherwise, it returns the second value
  5881. argument.
  5882. If the condition is a vector of i1, then the value arguments must be
  5883. vectors of the same size, and the selection is done element by element.
  5884. If the condition is an i1 and the value arguments are vectors of the
  5885. same size, then an entire vector is selected.
  5886. Example:
  5887. """"""""
  5888. .. code-block:: llvm
  5889. %X = select i1 true, i8 17, i8 42 ; yields i8:17
  5890. .. _i_call:
  5891. '``call``' Instruction
  5892. ^^^^^^^^^^^^^^^^^^^^^^
  5893. Syntax:
  5894. """""""
  5895. ::
  5896. <result> = [tail | musttail] call [cconv] [ret attrs] <ty> [<fnty>*] <fnptrval>(<function args>) [fn attrs]
  5897. Overview:
  5898. """""""""
  5899. The '``call``' instruction represents a simple function call.
  5900. Arguments:
  5901. """"""""""
  5902. This instruction requires several arguments:
  5903. #. The optional ``tail`` and ``musttail`` markers indicate that the optimizers
  5904. should perform tail call optimization. The ``tail`` marker is a hint that
  5905. `can be ignored <CodeGenerator.html#sibcallopt>`_. The ``musttail`` marker
  5906. means that the call must be tail call optimized in order for the program to
  5907. be correct. The ``musttail`` marker provides these guarantees:
  5908. #. The call will not cause unbounded stack growth if it is part of a
  5909. recursive cycle in the call graph.
  5910. #. Arguments with the :ref:`inalloca <attr_inalloca>` attribute are
  5911. forwarded in place.
  5912. Both markers imply that the callee does not access allocas or varargs from
  5913. the caller. Calls marked ``musttail`` must obey the following additional
  5914. rules:
  5915. - The call must immediately precede a :ref:`ret <i_ret>` instruction,
  5916. or a pointer bitcast followed by a ret instruction.
  5917. - The ret instruction must return the (possibly bitcasted) value
  5918. produced by the call or void.
  5919. - The caller and callee prototypes must match. Pointer types of
  5920. parameters or return types may differ in pointee type, but not
  5921. in address space.
  5922. - The calling conventions of the caller and callee must match.
  5923. - All ABI-impacting function attributes, such as sret, byval, inreg,
  5924. returned, and inalloca, must match.
  5925. - The callee must be varargs iff the caller is varargs. Bitcasting a
  5926. non-varargs function to the appropriate varargs type is legal so
  5927. long as the non-varargs prefixes obey the other rules.
  5928. Tail call optimization for calls marked ``tail`` is guaranteed to occur if
  5929. the following conditions are met:
  5930. - Caller and callee both have the calling convention ``fastcc``.
  5931. - The call is in tail position (ret immediately follows call and ret
  5932. uses value of call or is void).
  5933. - Option ``-tailcallopt`` is enabled, or
  5934. ``llvm::GuaranteedTailCallOpt`` is ``true``.
  5935. - `Platform-specific constraints are
  5936. met. <CodeGenerator.html#tailcallopt>`_
  5937. #. The optional "cconv" marker indicates which :ref:`calling
  5938. convention <callingconv>` the call should use. If none is
  5939. specified, the call defaults to using C calling conventions. The
  5940. calling convention of the call must match the calling convention of
  5941. the target function, or else the behavior is undefined.
  5942. #. The optional :ref:`Parameter Attributes <paramattrs>` list for return
  5943. values. Only '``zeroext``', '``signext``', and '``inreg``' attributes
  5944. are valid here.
  5945. #. '``ty``': the type of the call instruction itself which is also the
  5946. type of the return value. Functions that return no value are marked
  5947. ``void``.
  5948. #. '``fnty``': shall be the signature of the pointer to function value
  5949. being invoked. The argument types must match the types implied by
  5950. this signature. This type can be omitted if the function is not
  5951. varargs and if the function type does not return a pointer to a
  5952. function.
  5953. #. '``fnptrval``': An LLVM value containing a pointer to a function to
  5954. be invoked. In most cases, this is a direct function invocation, but
  5955. indirect ``call``'s are just as possible, calling an arbitrary pointer
  5956. to function value.
  5957. #. '``function args``': argument list whose types match the function
  5958. signature argument types and parameter attributes. All arguments must
  5959. be of :ref:`first class <t_firstclass>` type. If the function signature
  5960. indicates the function accepts a variable number of arguments, the
  5961. extra arguments can be specified.
  5962. #. The optional :ref:`function attributes <fnattrs>` list. Only
  5963. '``noreturn``', '``nounwind``', '``readonly``' and '``readnone``'
  5964. attributes are valid here.
  5965. Semantics:
  5966. """"""""""
  5967. The '``call``' instruction is used to cause control flow to transfer to
  5968. a specified function, with its incoming arguments bound to the specified
  5969. values. Upon a '``ret``' instruction in the called function, control
  5970. flow continues with the instruction after the function call, and the
  5971. return value of the function is bound to the result argument.
  5972. Example:
  5973. """"""""
  5974. .. code-block:: llvm
  5975. %retval = call i32 @test(i32 %argc)
  5976. call i32 (i8*, ...)* @printf(i8* %msg, i32 12, i8 42) ; yields i32
  5977. %X = tail call i32 @foo() ; yields i32
  5978. %Y = tail call fastcc i32 @foo() ; yields i32
  5979. call void %foo(i8 97 signext)
  5980. %struct.A = type { i32, i8 }
  5981. %r = call %struct.A @foo() ; yields { i32, i8 }
  5982. %gr = extractvalue %struct.A %r, 0 ; yields i32
  5983. %gr1 = extractvalue %struct.A %r, 1 ; yields i8
  5984. %Z = call void @foo() noreturn ; indicates that %foo never returns normally
  5985. %ZZ = call zeroext i32 @bar() ; Return value is %zero extended
  5986. llvm treats calls to some functions with names and arguments that match
  5987. the standard C99 library as being the C99 library functions, and may
  5988. perform optimizations or generate code for them under that assumption.
  5989. This is something we'd like to change in the future to provide better
  5990. support for freestanding environments and non-C-based languages.
  5991. .. _i_va_arg:
  5992. '``va_arg``' Instruction
  5993. ^^^^^^^^^^^^^^^^^^^^^^^^
  5994. Syntax:
  5995. """""""
  5996. ::
  5997. <resultval> = va_arg <va_list*> <arglist>, <argty>
  5998. Overview:
  5999. """""""""
  6000. The '``va_arg``' instruction is used to access arguments passed through
  6001. the "variable argument" area of a function call. It is used to implement
  6002. the ``va_arg`` macro in C.
  6003. Arguments:
  6004. """"""""""
  6005. This instruction takes a ``va_list*`` value and the type of the
  6006. argument. It returns a value of the specified argument type and
  6007. increments the ``va_list`` to point to the next argument. The actual
  6008. type of ``va_list`` is target specific.
  6009. Semantics:
  6010. """"""""""
  6011. The '``va_arg``' instruction loads an argument of the specified type
  6012. from the specified ``va_list`` and causes the ``va_list`` to point to
  6013. the next argument. For more information, see the variable argument
  6014. handling :ref:`Intrinsic Functions <int_varargs>`.
  6015. It is legal for this instruction to be called in a function which does
  6016. not take a variable number of arguments, for example, the ``vfprintf``
  6017. function.
  6018. ``va_arg`` is an LLVM instruction instead of an :ref:`intrinsic
  6019. function <intrinsics>` because it takes a type as an argument.
  6020. Example:
  6021. """"""""
  6022. See the :ref:`variable argument processing <int_varargs>` section.
  6023. Note that the code generator does not yet fully support va\_arg on many
  6024. targets. Also, it does not currently support va\_arg with aggregate
  6025. types on any target.
  6026. .. _i_landingpad:
  6027. '``landingpad``' Instruction
  6028. ^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  6029. Syntax:
  6030. """""""
  6031. ::
  6032. <resultval> = landingpad <resultty> <clause>+
  6033. <resultval> = landingpad <resultty> cleanup <clause>*
  6034. <clause> := catch <type> <value>
  6035. <clause> := filter <array constant type> <array constant>
  6036. Overview:
  6037. """""""""
  6038. The '``landingpad``' instruction is used by `LLVM's exception handling
  6039. system <ExceptionHandling.html#overview>`_ to specify that a basic block
  6040. is a landing pad --- one where the exception lands, and corresponds to the
  6041. code found in the ``catch`` portion of a ``try``/``catch`` sequence. It
  6042. defines values supplied by the :ref:`personality function <personalityfn>` upon
  6043. re-entry to the function. The ``resultval`` has the type ``resultty``.
  6044. Arguments:
  6045. """"""""""
  6046. The optional
  6047. ``cleanup`` flag indicates that the landing pad block is a cleanup.
  6048. A ``clause`` begins with the clause type --- ``catch`` or ``filter`` --- and
  6049. contains the global variable representing the "type" that may be caught
  6050. or filtered respectively. Unlike the ``catch`` clause, the ``filter``
  6051. clause takes an array constant as its argument. Use
  6052. "``[0 x i8**] undef``" for a filter which cannot throw. The
  6053. '``landingpad``' instruction must contain *at least* one ``clause`` or
  6054. the ``cleanup`` flag.
  6055. Semantics:
  6056. """"""""""
  6057. The '``landingpad``' instruction defines the values which are set by the
  6058. :ref:`personality function <personalityfn>` upon re-entry to the function, and
  6059. therefore the "result type" of the ``landingpad`` instruction. As with
  6060. calling conventions, how the personality function results are
  6061. represented in LLVM IR is target specific.
  6062. The clauses are applied in order from top to bottom. If two
  6063. ``landingpad`` instructions are merged together through inlining, the
  6064. clauses from the calling function are appended to the list of clauses.
  6065. When the call stack is being unwound due to an exception being thrown,
  6066. the exception is compared against each ``clause`` in turn. If it doesn't
  6067. match any of the clauses, and the ``cleanup`` flag is not set, then
  6068. unwinding continues further up the call stack.
  6069. The ``landingpad`` instruction has several restrictions:
  6070. - A landing pad block is a basic block which is the unwind destination
  6071. of an '``invoke``' instruction.
  6072. - A landing pad block must have a '``landingpad``' instruction as its
  6073. first non-PHI instruction.
  6074. - There can be only one '``landingpad``' instruction within the landing
  6075. pad block.
  6076. - A basic block that is not a landing pad block may not include a
  6077. '``landingpad``' instruction.
  6078. Example:
  6079. """"""""
  6080. .. code-block:: llvm
  6081. ;; A landing pad which can catch an integer.
  6082. %res = landingpad { i8*, i32 }
  6083. catch i8** @_ZTIi
  6084. ;; A landing pad that is a cleanup.
  6085. %res = landingpad { i8*, i32 }
  6086. cleanup
  6087. ;; A landing pad which can catch an integer and can only throw a double.
  6088. %res = landingpad { i8*, i32 }
  6089. catch i8** @_ZTIi
  6090. filter [1 x i8**] [@_ZTId]
  6091. .. _intrinsics:
  6092. Intrinsic Functions
  6093. ===================
  6094. LLVM supports the notion of an "intrinsic function". These functions
  6095. have well known names and semantics and are required to follow certain
  6096. restrictions. Overall, these intrinsics represent an extension mechanism
  6097. for the LLVM language that does not require changing all of the
  6098. transformations in LLVM when adding to the language (or the bitcode
  6099. reader/writer, the parser, etc...).
  6100. Intrinsic function names must all start with an "``llvm.``" prefix. This
  6101. prefix is reserved in LLVM for intrinsic names; thus, function names may
  6102. not begin with this prefix. Intrinsic functions must always be external
  6103. functions: you cannot define the body of intrinsic functions. Intrinsic
  6104. functions may only be used in call or invoke instructions: it is illegal
  6105. to take the address of an intrinsic function. Additionally, because
  6106. intrinsic functions are part of the LLVM language, it is required if any
  6107. are added that they be documented here.
  6108. Some intrinsic functions can be overloaded, i.e., the intrinsic
  6109. represents a family of functions that perform the same operation but on
  6110. different data types. Because LLVM can represent over 8 million
  6111. different integer types, overloading is used commonly to allow an
  6112. intrinsic function to operate on any integer type. One or more of the
  6113. argument types or the result type can be overloaded to accept any
  6114. integer type. Argument types may also be defined as exactly matching a
  6115. previous argument's type or the result type. This allows an intrinsic
  6116. function which accepts multiple arguments, but needs all of them to be
  6117. of the same type, to only be overloaded with respect to a single
  6118. argument or the result.
  6119. Overloaded intrinsics will have the names of its overloaded argument
  6120. types encoded into its function name, each preceded by a period. Only
  6121. those types which are overloaded result in a name suffix. Arguments
  6122. whose type is matched against another type do not. For example, the
  6123. ``llvm.ctpop`` function can take an integer of any width and returns an
  6124. integer of exactly the same integer width. This leads to a family of
  6125. functions such as ``i8 @llvm.ctpop.i8(i8 %val)`` and
  6126. ``i29 @llvm.ctpop.i29(i29 %val)``. Only one type, the return type, is
  6127. overloaded, and only one type suffix is required. Because the argument's
  6128. type is matched against the return type, it does not require its own
  6129. name suffix.
  6130. To learn how to add an intrinsic function, please see the `Extending
  6131. LLVM Guide <ExtendingLLVM.html>`_.
  6132. .. _int_varargs:
  6133. Variable Argument Handling Intrinsics
  6134. -------------------------------------
  6135. Variable argument support is defined in LLVM with the
  6136. :ref:`va_arg <i_va_arg>` instruction and these three intrinsic
  6137. functions. These functions are related to the similarly named macros
  6138. defined in the ``<stdarg.h>`` header file.
  6139. All of these functions operate on arguments that use a target-specific
  6140. value type "``va_list``". The LLVM assembly language reference manual
  6141. does not define what this type is, so all transformations should be
  6142. prepared to handle these functions regardless of the type used.
  6143. This example shows how the :ref:`va_arg <i_va_arg>` instruction and the
  6144. variable argument handling intrinsic functions are used.
  6145. .. code-block:: llvm
  6146. ; This struct is different for every platform. For most platforms,
  6147. ; it is merely an i8*.
  6148. %struct.va_list = type { i8* }
  6149. ; For Unix x86_64 platforms, va_list is the following struct:
  6150. ; %struct.va_list = type { i32, i32, i8*, i8* }
  6151. define i32 @test(i32 %X, ...) {
  6152. ; Initialize variable argument processing
  6153. %ap = alloca %struct.va_list
  6154. %ap2 = bitcast %struct.va_list* %ap to i8*
  6155. call void @llvm.va_start(i8* %ap2)
  6156. ; Read a single integer argument
  6157. %tmp = va_arg i8* %ap2, i32
  6158. ; Demonstrate usage of llvm.va_copy and llvm.va_end
  6159. %aq = alloca i8*
  6160. %aq2 = bitcast i8** %aq to i8*
  6161. call void @llvm.va_copy(i8* %aq2, i8* %ap2)
  6162. call void @llvm.va_end(i8* %aq2)
  6163. ; Stop processing of arguments.
  6164. call void @llvm.va_end(i8* %ap2)
  6165. ret i32 %tmp
  6166. }
  6167. declare void @llvm.va_start(i8*)
  6168. declare void @llvm.va_copy(i8*, i8*)
  6169. declare void @llvm.va_end(i8*)
  6170. .. _int_va_start:
  6171. '``llvm.va_start``' Intrinsic
  6172. ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  6173. Syntax:
  6174. """""""
  6175. ::
  6176. declare void @llvm.va_start(i8* <arglist>)
  6177. Overview:
  6178. """""""""
  6179. The '``llvm.va_start``' intrinsic initializes ``*<arglist>`` for
  6180. subsequent use by ``va_arg``.
  6181. Arguments:
  6182. """"""""""
  6183. The argument is a pointer to a ``va_list`` element to initialize.
  6184. Semantics:
  6185. """"""""""
  6186. The '``llvm.va_start``' intrinsic works just like the ``va_start`` macro
  6187. available in C. In a target-dependent way, it initializes the
  6188. ``va_list`` element to which the argument points, so that the next call
  6189. to ``va_arg`` will produce the first variable argument passed to the
  6190. function. Unlike the C ``va_start`` macro, this intrinsic does not need
  6191. to know the last argument of the function as the compiler can figure
  6192. that out.
  6193. '``llvm.va_end``' Intrinsic
  6194. ^^^^^^^^^^^^^^^^^^^^^^^^^^^
  6195. Syntax:
  6196. """""""
  6197. ::
  6198. declare void @llvm.va_end(i8* <arglist>)
  6199. Overview:
  6200. """""""""
  6201. The '``llvm.va_end``' intrinsic destroys ``*<arglist>``, which has been
  6202. initialized previously with ``llvm.va_start`` or ``llvm.va_copy``.
  6203. Arguments:
  6204. """"""""""
  6205. The argument is a pointer to a ``va_list`` to destroy.
  6206. Semantics:
  6207. """"""""""
  6208. The '``llvm.va_end``' intrinsic works just like the ``va_end`` macro
  6209. available in C. In a target-dependent way, it destroys the ``va_list``
  6210. element to which the argument points. Calls to
  6211. :ref:`llvm.va_start <int_va_start>` and
  6212. :ref:`llvm.va_copy <int_va_copy>` must be matched exactly with calls to
  6213. ``llvm.va_end``.
  6214. .. _int_va_copy:
  6215. '``llvm.va_copy``' Intrinsic
  6216. ^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  6217. Syntax:
  6218. """""""
  6219. ::
  6220. declare void @llvm.va_copy(i8* <destarglist>, i8* <srcarglist>)
  6221. Overview:
  6222. """""""""
  6223. The '``llvm.va_copy``' intrinsic copies the current argument position
  6224. from the source argument list to the destination argument list.
  6225. Arguments:
  6226. """"""""""
  6227. The first argument is a pointer to a ``va_list`` element to initialize.
  6228. The second argument is a pointer to a ``va_list`` element to copy from.
  6229. Semantics:
  6230. """"""""""
  6231. The '``llvm.va_copy``' intrinsic works just like the ``va_copy`` macro
  6232. available in C. In a target-dependent way, it copies the source
  6233. ``va_list`` element into the destination ``va_list`` element. This
  6234. intrinsic is necessary because the `` llvm.va_start`` intrinsic may be
  6235. arbitrarily complex and require, for example, memory allocation.
  6236. Accurate Garbage Collection Intrinsics
  6237. --------------------------------------
  6238. LLVM's support for `Accurate Garbage Collection <GarbageCollection.html>`_
  6239. (GC) requires the frontend to generate code containing appropriate intrinsic
  6240. calls and select an appropriate GC strategy which knows how to lower these
  6241. intrinsics in a manner which is appropriate for the target collector.
  6242. These intrinsics allow identification of :ref:`GC roots on the
  6243. stack <int_gcroot>`, as well as garbage collector implementations that
  6244. require :ref:`read <int_gcread>` and :ref:`write <int_gcwrite>` barriers.
  6245. Frontends for type-safe garbage collected languages should generate
  6246. these intrinsics to make use of the LLVM garbage collectors. For more
  6247. details, see `Garbage Collection with LLVM <GarbageCollection.html>`_.
  6248. Experimental Statepoint Intrinsics
  6249. ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  6250. LLVM provides an second experimental set of intrinsics for describing garbage
  6251. collection safepoints in compiled code. These intrinsics are an alternative
  6252. to the ``llvm.gcroot`` intrinsics, but are compatible with the ones for
  6253. :ref:`read <int_gcread>` and :ref:`write <int_gcwrite>` barriers. The
  6254. differences in approach are covered in the `Garbage Collection with LLVM
  6255. <GarbageCollection.html>`_ documentation. The intrinsics themselves are
  6256. described in :doc:`Statepoints`.
  6257. .. _int_gcroot:
  6258. '``llvm.gcroot``' Intrinsic
  6259. ^^^^^^^^^^^^^^^^^^^^^^^^^^^
  6260. Syntax:
  6261. """""""
  6262. ::
  6263. declare void @llvm.gcroot(i8** %ptrloc, i8* %metadata)
  6264. Overview:
  6265. """""""""
  6266. The '``llvm.gcroot``' intrinsic declares the existence of a GC root to
  6267. the code generator, and allows some metadata to be associated with it.
  6268. Arguments:
  6269. """"""""""
  6270. The first argument specifies the address of a stack object that contains
  6271. the root pointer. The second pointer (which must be either a constant or
  6272. a global value address) contains the meta-data to be associated with the
  6273. root.
  6274. Semantics:
  6275. """"""""""
  6276. At runtime, a call to this intrinsic stores a null pointer into the
  6277. "ptrloc" location. At compile-time, the code generator generates
  6278. information to allow the runtime to find the pointer at GC safe points.
  6279. The '``llvm.gcroot``' intrinsic may only be used in a function which
  6280. :ref:`specifies a GC algorithm <gc>`.
  6281. .. _int_gcread:
  6282. '``llvm.gcread``' Intrinsic
  6283. ^^^^^^^^^^^^^^^^^^^^^^^^^^^
  6284. Syntax:
  6285. """""""
  6286. ::
  6287. declare i8* @llvm.gcread(i8* %ObjPtr, i8** %Ptr)
  6288. Overview:
  6289. """""""""
  6290. The '``llvm.gcread``' intrinsic identifies reads of references from heap
  6291. locations, allowing garbage collector implementations that require read
  6292. barriers.
  6293. Arguments:
  6294. """"""""""
  6295. The second argument is the address to read from, which should be an
  6296. address allocated from the garbage collector. The first object is a
  6297. pointer to the start of the referenced object, if needed by the language
  6298. runtime (otherwise null).
  6299. Semantics:
  6300. """"""""""
  6301. The '``llvm.gcread``' intrinsic has the same semantics as a load
  6302. instruction, but may be replaced with substantially more complex code by
  6303. the garbage collector runtime, as needed. The '``llvm.gcread``'
  6304. intrinsic may only be used in a function which :ref:`specifies a GC
  6305. algorithm <gc>`.
  6306. .. _int_gcwrite:
  6307. '``llvm.gcwrite``' Intrinsic
  6308. ^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  6309. Syntax:
  6310. """""""
  6311. ::
  6312. declare void @llvm.gcwrite(i8* %P1, i8* %Obj, i8** %P2)
  6313. Overview:
  6314. """""""""
  6315. The '``llvm.gcwrite``' intrinsic identifies writes of references to heap
  6316. locations, allowing garbage collector implementations that require write
  6317. barriers (such as generational or reference counting collectors).
  6318. Arguments:
  6319. """"""""""
  6320. The first argument is the reference to store, the second is the start of
  6321. the object to store it to, and the third is the address of the field of
  6322. Obj to store to. If the runtime does not require a pointer to the
  6323. object, Obj may be null.
  6324. Semantics:
  6325. """"""""""
  6326. The '``llvm.gcwrite``' intrinsic has the same semantics as a store
  6327. instruction, but may be replaced with substantially more complex code by
  6328. the garbage collector runtime, as needed. The '``llvm.gcwrite``'
  6329. intrinsic may only be used in a function which :ref:`specifies a GC
  6330. algorithm <gc>`.
  6331. Code Generator Intrinsics
  6332. -------------------------
  6333. These intrinsics are provided by LLVM to expose special features that
  6334. may only be implemented with code generator support.
  6335. '``llvm.returnaddress``' Intrinsic
  6336. ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  6337. Syntax:
  6338. """""""
  6339. ::
  6340. declare i8 *@llvm.returnaddress(i32 <level>)
  6341. Overview:
  6342. """""""""
  6343. The '``llvm.returnaddress``' intrinsic attempts to compute a
  6344. target-specific value indicating the return address of the current
  6345. function or one of its callers.
  6346. Arguments:
  6347. """"""""""
  6348. The argument to this intrinsic indicates which function to return the
  6349. address for. Zero indicates the calling function, one indicates its
  6350. caller, etc. The argument is **required** to be a constant integer
  6351. value.
  6352. Semantics:
  6353. """"""""""
  6354. The '``llvm.returnaddress``' intrinsic either returns a pointer
  6355. indicating the return address of the specified call frame, or zero if it
  6356. cannot be identified. The value returned by this intrinsic is likely to
  6357. be incorrect or 0 for arguments other than zero, so it should only be
  6358. used for debugging purposes.
  6359. Note that calling this intrinsic does not prevent function inlining or
  6360. other aggressive transformations, so the value returned may not be that
  6361. of the obvious source-language caller.
  6362. '``llvm.frameaddress``' Intrinsic
  6363. ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  6364. Syntax:
  6365. """""""
  6366. ::
  6367. declare i8* @llvm.frameaddress(i32 <level>)
  6368. Overview:
  6369. """""""""
  6370. The '``llvm.frameaddress``' intrinsic attempts to return the
  6371. target-specific frame pointer value for the specified stack frame.
  6372. Arguments:
  6373. """"""""""
  6374. The argument to this intrinsic indicates which function to return the
  6375. frame pointer for. Zero indicates the calling function, one indicates
  6376. its caller, etc. The argument is **required** to be a constant integer
  6377. value.
  6378. Semantics:
  6379. """"""""""
  6380. The '``llvm.frameaddress``' intrinsic either returns a pointer
  6381. indicating the frame address of the specified call frame, or zero if it
  6382. cannot be identified. The value returned by this intrinsic is likely to
  6383. be incorrect or 0 for arguments other than zero, so it should only be
  6384. used for debugging purposes.
  6385. Note that calling this intrinsic does not prevent function inlining or
  6386. other aggressive transformations, so the value returned may not be that
  6387. of the obvious source-language caller.
  6388. '``llvm.localescape``' and '``llvm.localrecover``' Intrinsics
  6389. ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  6390. Syntax:
  6391. """""""
  6392. ::
  6393. declare void @llvm.localescape(...)
  6394. declare i8* @llvm.localrecover(i8* %func, i8* %fp, i32 %idx)
  6395. Overview:
  6396. """""""""
  6397. The '``llvm.localescape``' intrinsic escapes offsets of a collection of static
  6398. allocas, and the '``llvm.localrecover``' intrinsic applies those offsets to a
  6399. live frame pointer to recover the address of the allocation. The offset is
  6400. computed during frame layout of the caller of ``llvm.localescape``.
  6401. Arguments:
  6402. """"""""""
  6403. All arguments to '``llvm.localescape``' must be pointers to static allocas or
  6404. casts of static allocas. Each function can only call '``llvm.localescape``'
  6405. once, and it can only do so from the entry block.
  6406. The ``func`` argument to '``llvm.localrecover``' must be a constant
  6407. bitcasted pointer to a function defined in the current module. The code
  6408. generator cannot determine the frame allocation offset of functions defined in
  6409. other modules.
  6410. The ``fp`` argument to '``llvm.localrecover``' must be a frame pointer of a
  6411. call frame that is currently live. The return value of '``llvm.localaddress``'
  6412. is one way to produce such a value, but various runtimes also expose a suitable
  6413. pointer in platform-specific ways.
  6414. The ``idx`` argument to '``llvm.localrecover``' indicates which alloca passed to
  6415. '``llvm.localescape``' to recover. It is zero-indexed.
  6416. Semantics:
  6417. """"""""""
  6418. These intrinsics allow a group of functions to share access to a set of local
  6419. stack allocations of a one parent function. The parent function may call the
  6420. '``llvm.localescape``' intrinsic once from the function entry block, and the
  6421. child functions can use '``llvm.localrecover``' to access the escaped allocas.
  6422. The '``llvm.localescape``' intrinsic blocks inlining, as inlining changes where
  6423. the escaped allocas are allocated, which would break attempts to use
  6424. '``llvm.localrecover``'.
  6425. .. _int_read_register:
  6426. .. _int_write_register:
  6427. '``llvm.read_register``' and '``llvm.write_register``' Intrinsics
  6428. ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  6429. Syntax:
  6430. """""""
  6431. ::
  6432. declare i32 @llvm.read_register.i32(metadata)
  6433. declare i64 @llvm.read_register.i64(metadata)
  6434. declare void @llvm.write_register.i32(metadata, i32 @value)
  6435. declare void @llvm.write_register.i64(metadata, i64 @value)
  6436. !0 = !{!"sp\00"}
  6437. Overview:
  6438. """""""""
  6439. The '``llvm.read_register``' and '``llvm.write_register``' intrinsics
  6440. provides access to the named register. The register must be valid on
  6441. the architecture being compiled to. The type needs to be compatible
  6442. with the register being read.
  6443. Semantics:
  6444. """"""""""
  6445. The '``llvm.read_register``' intrinsic returns the current value of the
  6446. register, where possible. The '``llvm.write_register``' intrinsic sets
  6447. the current value of the register, where possible.
  6448. This is useful to implement named register global variables that need
  6449. to always be mapped to a specific register, as is common practice on
  6450. bare-metal programs including OS kernels.
  6451. The compiler doesn't check for register availability or use of the used
  6452. register in surrounding code, including inline assembly. Because of that,
  6453. allocatable registers are not supported.
  6454. Warning: So far it only works with the stack pointer on selected
  6455. architectures (ARM, AArch64, PowerPC and x86_64). Significant amount of
  6456. work is needed to support other registers and even more so, allocatable
  6457. registers.
  6458. .. _int_stacksave:
  6459. '``llvm.stacksave``' Intrinsic
  6460. ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  6461. Syntax:
  6462. """""""
  6463. ::
  6464. declare i8* @llvm.stacksave()
  6465. Overview:
  6466. """""""""
  6467. The '``llvm.stacksave``' intrinsic is used to remember the current state
  6468. of the function stack, for use with
  6469. :ref:`llvm.stackrestore <int_stackrestore>`. This is useful for
  6470. implementing language features like scoped automatic variable sized
  6471. arrays in C99.
  6472. Semantics:
  6473. """"""""""
  6474. This intrinsic returns a opaque pointer value that can be passed to
  6475. :ref:`llvm.stackrestore <int_stackrestore>`. When an
  6476. ``llvm.stackrestore`` intrinsic is executed with a value saved from
  6477. ``llvm.stacksave``, it effectively restores the state of the stack to
  6478. the state it was in when the ``llvm.stacksave`` intrinsic executed. In
  6479. practice, this pops any :ref:`alloca <i_alloca>` blocks from the stack that
  6480. were allocated after the ``llvm.stacksave`` was executed.
  6481. .. _int_stackrestore:
  6482. '``llvm.stackrestore``' Intrinsic
  6483. ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  6484. Syntax:
  6485. """""""
  6486. ::
  6487. declare void @llvm.stackrestore(i8* %ptr)
  6488. Overview:
  6489. """""""""
  6490. The '``llvm.stackrestore``' intrinsic is used to restore the state of
  6491. the function stack to the state it was in when the corresponding
  6492. :ref:`llvm.stacksave <int_stacksave>` intrinsic executed. This is
  6493. useful for implementing language features like scoped automatic variable
  6494. sized arrays in C99.
  6495. Semantics:
  6496. """"""""""
  6497. See the description for :ref:`llvm.stacksave <int_stacksave>`.
  6498. '``llvm.prefetch``' Intrinsic
  6499. ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  6500. Syntax:
  6501. """""""
  6502. ::
  6503. declare void @llvm.prefetch(i8* <address>, i32 <rw>, i32 <locality>, i32 <cache type>)
  6504. Overview:
  6505. """""""""
  6506. The '``llvm.prefetch``' intrinsic is a hint to the code generator to
  6507. insert a prefetch instruction if supported; otherwise, it is a noop.
  6508. Prefetches have no effect on the behavior of the program but can change
  6509. its performance characteristics.
  6510. Arguments:
  6511. """"""""""
  6512. ``address`` is the address to be prefetched, ``rw`` is the specifier
  6513. determining if the fetch should be for a read (0) or write (1), and
  6514. ``locality`` is a temporal locality specifier ranging from (0) - no
  6515. locality, to (3) - extremely local keep in cache. The ``cache type``
  6516. specifies whether the prefetch is performed on the data (1) or
  6517. instruction (0) cache. The ``rw``, ``locality`` and ``cache type``
  6518. arguments must be constant integers.
  6519. Semantics:
  6520. """"""""""
  6521. This intrinsic does not modify the behavior of the program. In
  6522. particular, prefetches cannot trap and do not produce a value. On
  6523. targets that support this intrinsic, the prefetch can provide hints to
  6524. the processor cache for better performance.
  6525. '``llvm.pcmarker``' Intrinsic
  6526. ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  6527. Syntax:
  6528. """""""
  6529. ::
  6530. declare void @llvm.pcmarker(i32 <id>)
  6531. Overview:
  6532. """""""""
  6533. The '``llvm.pcmarker``' intrinsic is a method to export a Program
  6534. Counter (PC) in a region of code to simulators and other tools. The
  6535. method is target specific, but it is expected that the marker will use
  6536. exported symbols to transmit the PC of the marker. The marker makes no
  6537. guarantees that it will remain with any specific instruction after
  6538. optimizations. It is possible that the presence of a marker will inhibit
  6539. optimizations. The intended use is to be inserted after optimizations to
  6540. allow correlations of simulation runs.
  6541. Arguments:
  6542. """"""""""
  6543. ``id`` is a numerical id identifying the marker.
  6544. Semantics:
  6545. """"""""""
  6546. This intrinsic does not modify the behavior of the program. Backends
  6547. that do not support this intrinsic may ignore it.
  6548. '``llvm.readcyclecounter``' Intrinsic
  6549. ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  6550. Syntax:
  6551. """""""
  6552. ::
  6553. declare i64 @llvm.readcyclecounter()
  6554. Overview:
  6555. """""""""
  6556. The '``llvm.readcyclecounter``' intrinsic provides access to the cycle
  6557. counter register (or similar low latency, high accuracy clocks) on those
  6558. targets that support it. On X86, it should map to RDTSC. On Alpha, it
  6559. should map to RPCC. As the backing counters overflow quickly (on the
  6560. order of 9 seconds on alpha), this should only be used for small
  6561. timings.
  6562. Semantics:
  6563. """"""""""
  6564. When directly supported, reading the cycle counter should not modify any
  6565. memory. Implementations are allowed to either return a application
  6566. specific value or a system wide value. On backends without support, this
  6567. is lowered to a constant 0.
  6568. Note that runtime support may be conditional on the privilege-level code is
  6569. running at and the host platform.
  6570. '``llvm.clear_cache``' Intrinsic
  6571. ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  6572. Syntax:
  6573. """""""
  6574. ::
  6575. declare void @llvm.clear_cache(i8*, i8*)
  6576. Overview:
  6577. """""""""
  6578. The '``llvm.clear_cache``' intrinsic ensures visibility of modifications
  6579. in the specified range to the execution unit of the processor. On
  6580. targets with non-unified instruction and data cache, the implementation
  6581. flushes the instruction cache.
  6582. Semantics:
  6583. """"""""""
  6584. On platforms with coherent instruction and data caches (e.g. x86), this
  6585. intrinsic is a nop. On platforms with non-coherent instruction and data
  6586. cache (e.g. ARM, MIPS), the intrinsic is lowered either to appropriate
  6587. instructions or a system call, if cache flushing requires special
  6588. privileges.
  6589. The default behavior is to emit a call to ``__clear_cache`` from the run
  6590. time library.
  6591. This instrinsic does *not* empty the instruction pipeline. Modifications
  6592. of the current function are outside the scope of the intrinsic.
  6593. '``llvm.instrprof_increment``' Intrinsic
  6594. ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  6595. Syntax:
  6596. """""""
  6597. ::
  6598. declare void @llvm.instrprof_increment(i8* <name>, i64 <hash>,
  6599. i32 <num-counters>, i32 <index>)
  6600. Overview:
  6601. """""""""
  6602. The '``llvm.instrprof_increment``' intrinsic can be emitted by a
  6603. frontend for use with instrumentation based profiling. These will be
  6604. lowered by the ``-instrprof`` pass to generate execution counts of a
  6605. program at runtime.
  6606. Arguments:
  6607. """"""""""
  6608. The first argument is a pointer to a global variable containing the
  6609. name of the entity being instrumented. This should generally be the
  6610. (mangled) function name for a set of counters.
  6611. The second argument is a hash value that can be used by the consumer
  6612. of the profile data to detect changes to the instrumented source, and
  6613. the third is the number of counters associated with ``name``. It is an
  6614. error if ``hash`` or ``num-counters`` differ between two instances of
  6615. ``instrprof_increment`` that refer to the same name.
  6616. The last argument refers to which of the counters for ``name`` should
  6617. be incremented. It should be a value between 0 and ``num-counters``.
  6618. Semantics:
  6619. """"""""""
  6620. This intrinsic represents an increment of a profiling counter. It will
  6621. cause the ``-instrprof`` pass to generate the appropriate data
  6622. structures and the code to increment the appropriate value, in a
  6623. format that can be written out by a compiler runtime and consumed via
  6624. the ``llvm-profdata`` tool.
  6625. Standard C Library Intrinsics
  6626. -----------------------------
  6627. LLVM provides intrinsics for a few important standard C library
  6628. functions. These intrinsics allow source-language front-ends to pass
  6629. information about the alignment of the pointer arguments to the code
  6630. generator, providing opportunity for more efficient code generation.
  6631. .. _int_memcpy:
  6632. '``llvm.memcpy``' Intrinsic
  6633. ^^^^^^^^^^^^^^^^^^^^^^^^^^^
  6634. Syntax:
  6635. """""""
  6636. This is an overloaded intrinsic. You can use ``llvm.memcpy`` on any
  6637. integer bit width and for different address spaces. Not all targets
  6638. support all bit widths however.
  6639. ::
  6640. declare void @llvm.memcpy.p0i8.p0i8.i32(i8* <dest>, i8* <src>,
  6641. i32 <len>, i32 <align>, i1 <isvolatile>)
  6642. declare void @llvm.memcpy.p0i8.p0i8.i64(i8* <dest>, i8* <src>,
  6643. i64 <len>, i32 <align>, i1 <isvolatile>)
  6644. Overview:
  6645. """""""""
  6646. The '``llvm.memcpy.*``' intrinsics copy a block of memory from the
  6647. source location to the destination location.
  6648. Note that, unlike the standard libc function, the ``llvm.memcpy.*``
  6649. intrinsics do not return a value, takes extra alignment/isvolatile
  6650. arguments and the pointers can be in specified address spaces.
  6651. Arguments:
  6652. """"""""""
  6653. The first argument is a pointer to the destination, the second is a
  6654. pointer to the source. The third argument is an integer argument
  6655. specifying the number of bytes to copy, the fourth argument is the
  6656. alignment of the source and destination locations, and the fifth is a
  6657. boolean indicating a volatile access.
  6658. If the call to this intrinsic has an alignment value that is not 0 or 1,
  6659. then the caller guarantees that both the source and destination pointers
  6660. are aligned to that boundary.
  6661. If the ``isvolatile`` parameter is ``true``, the ``llvm.memcpy`` call is
  6662. a :ref:`volatile operation <volatile>`. The detailed access behavior is not
  6663. very cleanly specified and it is unwise to depend on it.
  6664. Semantics:
  6665. """"""""""
  6666. The '``llvm.memcpy.*``' intrinsics copy a block of memory from the
  6667. source location to the destination location, which are not allowed to
  6668. overlap. It copies "len" bytes of memory over. If the argument is known
  6669. to be aligned to some boundary, this can be specified as the fourth
  6670. argument, otherwise it should be set to 0 or 1 (both meaning no alignment).
  6671. '``llvm.memmove``' Intrinsic
  6672. ^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  6673. Syntax:
  6674. """""""
  6675. This is an overloaded intrinsic. You can use llvm.memmove on any integer
  6676. bit width and for different address space. Not all targets support all
  6677. bit widths however.
  6678. ::
  6679. declare void @llvm.memmove.p0i8.p0i8.i32(i8* <dest>, i8* <src>,
  6680. i32 <len>, i32 <align>, i1 <isvolatile>)
  6681. declare void @llvm.memmove.p0i8.p0i8.i64(i8* <dest>, i8* <src>,
  6682. i64 <len>, i32 <align>, i1 <isvolatile>)
  6683. Overview:
  6684. """""""""
  6685. The '``llvm.memmove.*``' intrinsics move a block of memory from the
  6686. source location to the destination location. It is similar to the
  6687. '``llvm.memcpy``' intrinsic but allows the two memory locations to
  6688. overlap.
  6689. Note that, unlike the standard libc function, the ``llvm.memmove.*``
  6690. intrinsics do not return a value, takes extra alignment/isvolatile
  6691. arguments and the pointers can be in specified address spaces.
  6692. Arguments:
  6693. """"""""""
  6694. The first argument is a pointer to the destination, the second is a
  6695. pointer to the source. The third argument is an integer argument
  6696. specifying the number of bytes to copy, the fourth argument is the
  6697. alignment of the source and destination locations, and the fifth is a
  6698. boolean indicating a volatile access.
  6699. If the call to this intrinsic has an alignment value that is not 0 or 1,
  6700. then the caller guarantees that the source and destination pointers are
  6701. aligned to that boundary.
  6702. If the ``isvolatile`` parameter is ``true``, the ``llvm.memmove`` call
  6703. is a :ref:`volatile operation <volatile>`. The detailed access behavior is
  6704. not very cleanly specified and it is unwise to depend on it.
  6705. Semantics:
  6706. """"""""""
  6707. The '``llvm.memmove.*``' intrinsics copy a block of memory from the
  6708. source location to the destination location, which may overlap. It
  6709. copies "len" bytes of memory over. If the argument is known to be
  6710. aligned to some boundary, this can be specified as the fourth argument,
  6711. otherwise it should be set to 0 or 1 (both meaning no alignment).
  6712. '``llvm.memset.*``' Intrinsics
  6713. ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  6714. Syntax:
  6715. """""""
  6716. This is an overloaded intrinsic. You can use llvm.memset on any integer
  6717. bit width and for different address spaces. However, not all targets
  6718. support all bit widths.
  6719. ::
  6720. declare void @llvm.memset.p0i8.i32(i8* <dest>, i8 <val>,
  6721. i32 <len>, i32 <align>, i1 <isvolatile>)
  6722. declare void @llvm.memset.p0i8.i64(i8* <dest>, i8 <val>,
  6723. i64 <len>, i32 <align>, i1 <isvolatile>)
  6724. Overview:
  6725. """""""""
  6726. The '``llvm.memset.*``' intrinsics fill a block of memory with a
  6727. particular byte value.
  6728. Note that, unlike the standard libc function, the ``llvm.memset``
  6729. intrinsic does not return a value and takes extra alignment/volatile
  6730. arguments. Also, the destination can be in an arbitrary address space.
  6731. Arguments:
  6732. """"""""""
  6733. The first argument is a pointer to the destination to fill, the second
  6734. is the byte value with which to fill it, the third argument is an
  6735. integer argument specifying the number of bytes to fill, and the fourth
  6736. argument is the known alignment of the destination location.
  6737. If the call to this intrinsic has an alignment value that is not 0 or 1,
  6738. then the caller guarantees that the destination pointer is aligned to
  6739. that boundary.
  6740. If the ``isvolatile`` parameter is ``true``, the ``llvm.memset`` call is
  6741. a :ref:`volatile operation <volatile>`. The detailed access behavior is not
  6742. very cleanly specified and it is unwise to depend on it.
  6743. Semantics:
  6744. """"""""""
  6745. The '``llvm.memset.*``' intrinsics fill "len" bytes of memory starting
  6746. at the destination location. If the argument is known to be aligned to
  6747. some boundary, this can be specified as the fourth argument, otherwise
  6748. it should be set to 0 or 1 (both meaning no alignment).
  6749. '``llvm.sqrt.*``' Intrinsic
  6750. ^^^^^^^^^^^^^^^^^^^^^^^^^^^
  6751. Syntax:
  6752. """""""
  6753. This is an overloaded intrinsic. You can use ``llvm.sqrt`` on any
  6754. floating point or vector of floating point type. Not all targets support
  6755. all types however.
  6756. ::
  6757. declare float @llvm.sqrt.f32(float %Val)
  6758. declare double @llvm.sqrt.f64(double %Val)
  6759. declare x86_fp80 @llvm.sqrt.f80(x86_fp80 %Val)
  6760. declare fp128 @llvm.sqrt.f128(fp128 %Val)
  6761. declare ppc_fp128 @llvm.sqrt.ppcf128(ppc_fp128 %Val)
  6762. Overview:
  6763. """""""""
  6764. The '``llvm.sqrt``' intrinsics return the sqrt of the specified operand,
  6765. returning the same value as the libm '``sqrt``' functions would. Unlike
  6766. ``sqrt`` in libm, however, ``llvm.sqrt`` has undefined behavior for
  6767. negative numbers other than -0.0 (which allows for better optimization,
  6768. because there is no need to worry about errno being set).
  6769. ``llvm.sqrt(-0.0)`` is defined to return -0.0 like IEEE sqrt.
  6770. Arguments:
  6771. """"""""""
  6772. The argument and return value are floating point numbers of the same
  6773. type.
  6774. Semantics:
  6775. """"""""""
  6776. This function returns the sqrt of the specified operand if it is a
  6777. nonnegative floating point number.
  6778. '``llvm.powi.*``' Intrinsic
  6779. ^^^^^^^^^^^^^^^^^^^^^^^^^^^
  6780. Syntax:
  6781. """""""
  6782. This is an overloaded intrinsic. You can use ``llvm.powi`` on any
  6783. floating point or vector of floating point type. Not all targets support
  6784. all types however.
  6785. ::
  6786. declare float @llvm.powi.f32(float %Val, i32 %power)
  6787. declare double @llvm.powi.f64(double %Val, i32 %power)
  6788. declare x86_fp80 @llvm.powi.f80(x86_fp80 %Val, i32 %power)
  6789. declare fp128 @llvm.powi.f128(fp128 %Val, i32 %power)
  6790. declare ppc_fp128 @llvm.powi.ppcf128(ppc_fp128 %Val, i32 %power)
  6791. Overview:
  6792. """""""""
  6793. The '``llvm.powi.*``' intrinsics return the first operand raised to the
  6794. specified (positive or negative) power. The order of evaluation of
  6795. multiplications is not defined. When a vector of floating point type is
  6796. used, the second argument remains a scalar integer value.
  6797. Arguments:
  6798. """"""""""
  6799. The second argument is an integer power, and the first is a value to
  6800. raise to that power.
  6801. Semantics:
  6802. """"""""""
  6803. This function returns the first value raised to the second power with an
  6804. unspecified sequence of rounding operations.
  6805. '``llvm.sin.*``' Intrinsic
  6806. ^^^^^^^^^^^^^^^^^^^^^^^^^^
  6807. Syntax:
  6808. """""""
  6809. This is an overloaded intrinsic. You can use ``llvm.sin`` on any
  6810. floating point or vector of floating point type. Not all targets support
  6811. all types however.
  6812. ::
  6813. declare float @llvm.sin.f32(float %Val)
  6814. declare double @llvm.sin.f64(double %Val)
  6815. declare x86_fp80 @llvm.sin.f80(x86_fp80 %Val)
  6816. declare fp128 @llvm.sin.f128(fp128 %Val)
  6817. declare ppc_fp128 @llvm.sin.ppcf128(ppc_fp128 %Val)
  6818. Overview:
  6819. """""""""
  6820. The '``llvm.sin.*``' intrinsics return the sine of the operand.
  6821. Arguments:
  6822. """"""""""
  6823. The argument and return value are floating point numbers of the same
  6824. type.
  6825. Semantics:
  6826. """"""""""
  6827. This function returns the sine of the specified operand, returning the
  6828. same values as the libm ``sin`` functions would, and handles error
  6829. conditions in the same way.
  6830. '``llvm.cos.*``' Intrinsic
  6831. ^^^^^^^^^^^^^^^^^^^^^^^^^^
  6832. Syntax:
  6833. """""""
  6834. This is an overloaded intrinsic. You can use ``llvm.cos`` on any
  6835. floating point or vector of floating point type. Not all targets support
  6836. all types however.
  6837. ::
  6838. declare float @llvm.cos.f32(float %Val)
  6839. declare double @llvm.cos.f64(double %Val)
  6840. declare x86_fp80 @llvm.cos.f80(x86_fp80 %Val)
  6841. declare fp128 @llvm.cos.f128(fp128 %Val)
  6842. declare ppc_fp128 @llvm.cos.ppcf128(ppc_fp128 %Val)
  6843. Overview:
  6844. """""""""
  6845. The '``llvm.cos.*``' intrinsics return the cosine of the operand.
  6846. Arguments:
  6847. """"""""""
  6848. The argument and return value are floating point numbers of the same
  6849. type.
  6850. Semantics:
  6851. """"""""""
  6852. This function returns the cosine of the specified operand, returning the
  6853. same values as the libm ``cos`` functions would, and handles error
  6854. conditions in the same way.
  6855. '``llvm.pow.*``' Intrinsic
  6856. ^^^^^^^^^^^^^^^^^^^^^^^^^^
  6857. Syntax:
  6858. """""""
  6859. This is an overloaded intrinsic. You can use ``llvm.pow`` on any
  6860. floating point or vector of floating point type. Not all targets support
  6861. all types however.
  6862. ::
  6863. declare float @llvm.pow.f32(float %Val, float %Power)
  6864. declare double @llvm.pow.f64(double %Val, double %Power)
  6865. declare x86_fp80 @llvm.pow.f80(x86_fp80 %Val, x86_fp80 %Power)
  6866. declare fp128 @llvm.pow.f128(fp128 %Val, fp128 %Power)
  6867. declare ppc_fp128 @llvm.pow.ppcf128(ppc_fp128 %Val, ppc_fp128 Power)
  6868. Overview:
  6869. """""""""
  6870. The '``llvm.pow.*``' intrinsics return the first operand raised to the
  6871. specified (positive or negative) power.
  6872. Arguments:
  6873. """"""""""
  6874. The second argument is a floating point power, and the first is a value
  6875. to raise to that power.
  6876. Semantics:
  6877. """"""""""
  6878. This function returns the first value raised to the second power,
  6879. returning the same values as the libm ``pow`` functions would, and
  6880. handles error conditions in the same way.
  6881. '``llvm.exp.*``' Intrinsic
  6882. ^^^^^^^^^^^^^^^^^^^^^^^^^^
  6883. Syntax:
  6884. """""""
  6885. This is an overloaded intrinsic. You can use ``llvm.exp`` on any
  6886. floating point or vector of floating point type. Not all targets support
  6887. all types however.
  6888. ::
  6889. declare float @llvm.exp.f32(float %Val)
  6890. declare double @llvm.exp.f64(double %Val)
  6891. declare x86_fp80 @llvm.exp.f80(x86_fp80 %Val)
  6892. declare fp128 @llvm.exp.f128(fp128 %Val)
  6893. declare ppc_fp128 @llvm.exp.ppcf128(ppc_fp128 %Val)
  6894. Overview:
  6895. """""""""
  6896. The '``llvm.exp.*``' intrinsics perform the exp function.
  6897. Arguments:
  6898. """"""""""
  6899. The argument and return value are floating point numbers of the same
  6900. type.
  6901. Semantics:
  6902. """"""""""
  6903. This function returns the same values as the libm ``exp`` functions
  6904. would, and handles error conditions in the same way.
  6905. '``llvm.exp2.*``' Intrinsic
  6906. ^^^^^^^^^^^^^^^^^^^^^^^^^^^
  6907. Syntax:
  6908. """""""
  6909. This is an overloaded intrinsic. You can use ``llvm.exp2`` on any
  6910. floating point or vector of floating point type. Not all targets support
  6911. all types however.
  6912. ::
  6913. declare float @llvm.exp2.f32(float %Val)
  6914. declare double @llvm.exp2.f64(double %Val)
  6915. declare x86_fp80 @llvm.exp2.f80(x86_fp80 %Val)
  6916. declare fp128 @llvm.exp2.f128(fp128 %Val)
  6917. declare ppc_fp128 @llvm.exp2.ppcf128(ppc_fp128 %Val)
  6918. Overview:
  6919. """""""""
  6920. The '``llvm.exp2.*``' intrinsics perform the exp2 function.
  6921. Arguments:
  6922. """"""""""
  6923. The argument and return value are floating point numbers of the same
  6924. type.
  6925. Semantics:
  6926. """"""""""
  6927. This function returns the same values as the libm ``exp2`` functions
  6928. would, and handles error conditions in the same way.
  6929. '``llvm.log.*``' Intrinsic
  6930. ^^^^^^^^^^^^^^^^^^^^^^^^^^
  6931. Syntax:
  6932. """""""
  6933. This is an overloaded intrinsic. You can use ``llvm.log`` on any
  6934. floating point or vector of floating point type. Not all targets support
  6935. all types however.
  6936. ::
  6937. declare float @llvm.log.f32(float %Val)
  6938. declare double @llvm.log.f64(double %Val)
  6939. declare x86_fp80 @llvm.log.f80(x86_fp80 %Val)
  6940. declare fp128 @llvm.log.f128(fp128 %Val)
  6941. declare ppc_fp128 @llvm.log.ppcf128(ppc_fp128 %Val)
  6942. Overview:
  6943. """""""""
  6944. The '``llvm.log.*``' intrinsics perform the log function.
  6945. Arguments:
  6946. """"""""""
  6947. The argument and return value are floating point numbers of the same
  6948. type.
  6949. Semantics:
  6950. """"""""""
  6951. This function returns the same values as the libm ``log`` functions
  6952. would, and handles error conditions in the same way.
  6953. '``llvm.log10.*``' Intrinsic
  6954. ^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  6955. Syntax:
  6956. """""""
  6957. This is an overloaded intrinsic. You can use ``llvm.log10`` on any
  6958. floating point or vector of floating point type. Not all targets support
  6959. all types however.
  6960. ::
  6961. declare float @llvm.log10.f32(float %Val)
  6962. declare double @llvm.log10.f64(double %Val)
  6963. declare x86_fp80 @llvm.log10.f80(x86_fp80 %Val)
  6964. declare fp128 @llvm.log10.f128(fp128 %Val)
  6965. declare ppc_fp128 @llvm.log10.ppcf128(ppc_fp128 %Val)
  6966. Overview:
  6967. """""""""
  6968. The '``llvm.log10.*``' intrinsics perform the log10 function.
  6969. Arguments:
  6970. """"""""""
  6971. The argument and return value are floating point numbers of the same
  6972. type.
  6973. Semantics:
  6974. """"""""""
  6975. This function returns the same values as the libm ``log10`` functions
  6976. would, and handles error conditions in the same way.
  6977. '``llvm.log2.*``' Intrinsic
  6978. ^^^^^^^^^^^^^^^^^^^^^^^^^^^
  6979. Syntax:
  6980. """""""
  6981. This is an overloaded intrinsic. You can use ``llvm.log2`` on any
  6982. floating point or vector of floating point type. Not all targets support
  6983. all types however.
  6984. ::
  6985. declare float @llvm.log2.f32(float %Val)
  6986. declare double @llvm.log2.f64(double %Val)
  6987. declare x86_fp80 @llvm.log2.f80(x86_fp80 %Val)
  6988. declare fp128 @llvm.log2.f128(fp128 %Val)
  6989. declare ppc_fp128 @llvm.log2.ppcf128(ppc_fp128 %Val)
  6990. Overview:
  6991. """""""""
  6992. The '``llvm.log2.*``' intrinsics perform the log2 function.
  6993. Arguments:
  6994. """"""""""
  6995. The argument and return value are floating point numbers of the same
  6996. type.
  6997. Semantics:
  6998. """"""""""
  6999. This function returns the same values as the libm ``log2`` functions
  7000. would, and handles error conditions in the same way.
  7001. '``llvm.fma.*``' Intrinsic
  7002. ^^^^^^^^^^^^^^^^^^^^^^^^^^
  7003. Syntax:
  7004. """""""
  7005. This is an overloaded intrinsic. You can use ``llvm.fma`` on any
  7006. floating point or vector of floating point type. Not all targets support
  7007. all types however.
  7008. ::
  7009. declare float @llvm.fma.f32(float %a, float %b, float %c)
  7010. declare double @llvm.fma.f64(double %a, double %b, double %c)
  7011. declare x86_fp80 @llvm.fma.f80(x86_fp80 %a, x86_fp80 %b, x86_fp80 %c)
  7012. declare fp128 @llvm.fma.f128(fp128 %a, fp128 %b, fp128 %c)
  7013. declare ppc_fp128 @llvm.fma.ppcf128(ppc_fp128 %a, ppc_fp128 %b, ppc_fp128 %c)
  7014. Overview:
  7015. """""""""
  7016. The '``llvm.fma.*``' intrinsics perform the fused multiply-add
  7017. operation.
  7018. Arguments:
  7019. """"""""""
  7020. The argument and return value are floating point numbers of the same
  7021. type.
  7022. Semantics:
  7023. """"""""""
  7024. This function returns the same values as the libm ``fma`` functions
  7025. would, and does not set errno.
  7026. '``llvm.fabs.*``' Intrinsic
  7027. ^^^^^^^^^^^^^^^^^^^^^^^^^^^
  7028. Syntax:
  7029. """""""
  7030. This is an overloaded intrinsic. You can use ``llvm.fabs`` on any
  7031. floating point or vector of floating point type. Not all targets support
  7032. all types however.
  7033. ::
  7034. declare float @llvm.fabs.f32(float %Val)
  7035. declare double @llvm.fabs.f64(double %Val)
  7036. declare x86_fp80 @llvm.fabs.f80(x86_fp80 %Val)
  7037. declare fp128 @llvm.fabs.f128(fp128 %Val)
  7038. declare ppc_fp128 @llvm.fabs.ppcf128(ppc_fp128 %Val)
  7039. Overview:
  7040. """""""""
  7041. The '``llvm.fabs.*``' intrinsics return the absolute value of the
  7042. operand.
  7043. Arguments:
  7044. """"""""""
  7045. The argument and return value are floating point numbers of the same
  7046. type.
  7047. Semantics:
  7048. """"""""""
  7049. This function returns the same values as the libm ``fabs`` functions
  7050. would, and handles error conditions in the same way.
  7051. '``llvm.minnum.*``' Intrinsic
  7052. ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  7053. Syntax:
  7054. """""""
  7055. This is an overloaded intrinsic. You can use ``llvm.minnum`` on any
  7056. floating point or vector of floating point type. Not all targets support
  7057. all types however.
  7058. ::
  7059. declare float @llvm.minnum.f32(float %Val0, float %Val1)
  7060. declare double @llvm.minnum.f64(double %Val0, double %Val1)
  7061. declare x86_fp80 @llvm.minnum.f80(x86_fp80 %Val0, x86_fp80 %Val1)
  7062. declare fp128 @llvm.minnum.f128(fp128 %Val0, fp128 %Val1)
  7063. declare ppc_fp128 @llvm.minnum.ppcf128(ppc_fp128 %Val0, ppc_fp128 %Val1)
  7064. Overview:
  7065. """""""""
  7066. The '``llvm.minnum.*``' intrinsics return the minimum of the two
  7067. arguments.
  7068. Arguments:
  7069. """"""""""
  7070. The arguments and return value are floating point numbers of the same
  7071. type.
  7072. Semantics:
  7073. """"""""""
  7074. Follows the IEEE-754 semantics for minNum, which also match for libm's
  7075. fmin.
  7076. If either operand is a NaN, returns the other non-NaN operand. Returns
  7077. NaN only if both operands are NaN. If the operands compare equal,
  7078. returns a value that compares equal to both operands. This means that
  7079. fmin(+/-0.0, +/-0.0) could return either -0.0 or 0.0.
  7080. '``llvm.maxnum.*``' Intrinsic
  7081. ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  7082. Syntax:
  7083. """""""
  7084. This is an overloaded intrinsic. You can use ``llvm.maxnum`` on any
  7085. floating point or vector of floating point type. Not all targets support
  7086. all types however.
  7087. ::
  7088. declare float @llvm.maxnum.f32(float %Val0, float %Val1l)
  7089. declare double @llvm.maxnum.f64(double %Val0, double %Val1)
  7090. declare x86_fp80 @llvm.maxnum.f80(x86_fp80 %Val0, x86_fp80 %Val1)
  7091. declare fp128 @llvm.maxnum.f128(fp128 %Val0, fp128 %Val1)
  7092. declare ppc_fp128 @llvm.maxnum.ppcf128(ppc_fp128 %Val0, ppc_fp128 %Val1)
  7093. Overview:
  7094. """""""""
  7095. The '``llvm.maxnum.*``' intrinsics return the maximum of the two
  7096. arguments.
  7097. Arguments:
  7098. """"""""""
  7099. The arguments and return value are floating point numbers of the same
  7100. type.
  7101. Semantics:
  7102. """"""""""
  7103. Follows the IEEE-754 semantics for maxNum, which also match for libm's
  7104. fmax.
  7105. If either operand is a NaN, returns the other non-NaN operand. Returns
  7106. NaN only if both operands are NaN. If the operands compare equal,
  7107. returns a value that compares equal to both operands. This means that
  7108. fmax(+/-0.0, +/-0.0) could return either -0.0 or 0.0.
  7109. '``llvm.copysign.*``' Intrinsic
  7110. ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  7111. Syntax:
  7112. """""""
  7113. This is an overloaded intrinsic. You can use ``llvm.copysign`` on any
  7114. floating point or vector of floating point type. Not all targets support
  7115. all types however.
  7116. ::
  7117. declare float @llvm.copysign.f32(float %Mag, float %Sgn)
  7118. declare double @llvm.copysign.f64(double %Mag, double %Sgn)
  7119. declare x86_fp80 @llvm.copysign.f80(x86_fp80 %Mag, x86_fp80 %Sgn)
  7120. declare fp128 @llvm.copysign.f128(fp128 %Mag, fp128 %Sgn)
  7121. declare ppc_fp128 @llvm.copysign.ppcf128(ppc_fp128 %Mag, ppc_fp128 %Sgn)
  7122. Overview:
  7123. """""""""
  7124. The '``llvm.copysign.*``' intrinsics return a value with the magnitude of the
  7125. first operand and the sign of the second operand.
  7126. Arguments:
  7127. """"""""""
  7128. The arguments and return value are floating point numbers of the same
  7129. type.
  7130. Semantics:
  7131. """"""""""
  7132. This function returns the same values as the libm ``copysign``
  7133. functions would, and handles error conditions in the same way.
  7134. '``llvm.floor.*``' Intrinsic
  7135. ^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  7136. Syntax:
  7137. """""""
  7138. This is an overloaded intrinsic. You can use ``llvm.floor`` on any
  7139. floating point or vector of floating point type. Not all targets support
  7140. all types however.
  7141. ::
  7142. declare float @llvm.floor.f32(float %Val)
  7143. declare double @llvm.floor.f64(double %Val)
  7144. declare x86_fp80 @llvm.floor.f80(x86_fp80 %Val)
  7145. declare fp128 @llvm.floor.f128(fp128 %Val)
  7146. declare ppc_fp128 @llvm.floor.ppcf128(ppc_fp128 %Val)
  7147. Overview:
  7148. """""""""
  7149. The '``llvm.floor.*``' intrinsics return the floor of the operand.
  7150. Arguments:
  7151. """"""""""
  7152. The argument and return value are floating point numbers of the same
  7153. type.
  7154. Semantics:
  7155. """"""""""
  7156. This function returns the same values as the libm ``floor`` functions
  7157. would, and handles error conditions in the same way.
  7158. '``llvm.ceil.*``' Intrinsic
  7159. ^^^^^^^^^^^^^^^^^^^^^^^^^^^
  7160. Syntax:
  7161. """""""
  7162. This is an overloaded intrinsic. You can use ``llvm.ceil`` on any
  7163. floating point or vector of floating point type. Not all targets support
  7164. all types however.
  7165. ::
  7166. declare float @llvm.ceil.f32(float %Val)
  7167. declare double @llvm.ceil.f64(double %Val)
  7168. declare x86_fp80 @llvm.ceil.f80(x86_fp80 %Val)
  7169. declare fp128 @llvm.ceil.f128(fp128 %Val)
  7170. declare ppc_fp128 @llvm.ceil.ppcf128(ppc_fp128 %Val)
  7171. Overview:
  7172. """""""""
  7173. The '``llvm.ceil.*``' intrinsics return the ceiling of the operand.
  7174. Arguments:
  7175. """"""""""
  7176. The argument and return value are floating point numbers of the same
  7177. type.
  7178. Semantics:
  7179. """"""""""
  7180. This function returns the same values as the libm ``ceil`` functions
  7181. would, and handles error conditions in the same way.
  7182. '``llvm.trunc.*``' Intrinsic
  7183. ^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  7184. Syntax:
  7185. """""""
  7186. This is an overloaded intrinsic. You can use ``llvm.trunc`` on any
  7187. floating point or vector of floating point type. Not all targets support
  7188. all types however.
  7189. ::
  7190. declare float @llvm.trunc.f32(float %Val)
  7191. declare double @llvm.trunc.f64(double %Val)
  7192. declare x86_fp80 @llvm.trunc.f80(x86_fp80 %Val)
  7193. declare fp128 @llvm.trunc.f128(fp128 %Val)
  7194. declare ppc_fp128 @llvm.trunc.ppcf128(ppc_fp128 %Val)
  7195. Overview:
  7196. """""""""
  7197. The '``llvm.trunc.*``' intrinsics returns the operand rounded to the
  7198. nearest integer not larger in magnitude than the operand.
  7199. Arguments:
  7200. """"""""""
  7201. The argument and return value are floating point numbers of the same
  7202. type.
  7203. Semantics:
  7204. """"""""""
  7205. This function returns the same values as the libm ``trunc`` functions
  7206. would, and handles error conditions in the same way.
  7207. '``llvm.rint.*``' Intrinsic
  7208. ^^^^^^^^^^^^^^^^^^^^^^^^^^^
  7209. Syntax:
  7210. """""""
  7211. This is an overloaded intrinsic. You can use ``llvm.rint`` on any
  7212. floating point or vector of floating point type. Not all targets support
  7213. all types however.
  7214. ::
  7215. declare float @llvm.rint.f32(float %Val)
  7216. declare double @llvm.rint.f64(double %Val)
  7217. declare x86_fp80 @llvm.rint.f80(x86_fp80 %Val)
  7218. declare fp128 @llvm.rint.f128(fp128 %Val)
  7219. declare ppc_fp128 @llvm.rint.ppcf128(ppc_fp128 %Val)
  7220. Overview:
  7221. """""""""
  7222. The '``llvm.rint.*``' intrinsics returns the operand rounded to the
  7223. nearest integer. It may raise an inexact floating-point exception if the
  7224. operand isn't an integer.
  7225. Arguments:
  7226. """"""""""
  7227. The argument and return value are floating point numbers of the same
  7228. type.
  7229. Semantics:
  7230. """"""""""
  7231. This function returns the same values as the libm ``rint`` functions
  7232. would, and handles error conditions in the same way.
  7233. '``llvm.nearbyint.*``' Intrinsic
  7234. ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  7235. Syntax:
  7236. """""""
  7237. This is an overloaded intrinsic. You can use ``llvm.nearbyint`` on any
  7238. floating point or vector of floating point type. Not all targets support
  7239. all types however.
  7240. ::
  7241. declare float @llvm.nearbyint.f32(float %Val)
  7242. declare double @llvm.nearbyint.f64(double %Val)
  7243. declare x86_fp80 @llvm.nearbyint.f80(x86_fp80 %Val)
  7244. declare fp128 @llvm.nearbyint.f128(fp128 %Val)
  7245. declare ppc_fp128 @llvm.nearbyint.ppcf128(ppc_fp128 %Val)
  7246. Overview:
  7247. """""""""
  7248. The '``llvm.nearbyint.*``' intrinsics returns the operand rounded to the
  7249. nearest integer.
  7250. Arguments:
  7251. """"""""""
  7252. The argument and return value are floating point numbers of the same
  7253. type.
  7254. Semantics:
  7255. """"""""""
  7256. This function returns the same values as the libm ``nearbyint``
  7257. functions would, and handles error conditions in the same way.
  7258. '``llvm.round.*``' Intrinsic
  7259. ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  7260. Syntax:
  7261. """""""
  7262. This is an overloaded intrinsic. You can use ``llvm.round`` on any
  7263. floating point or vector of floating point type. Not all targets support
  7264. all types however.
  7265. ::
  7266. declare float @llvm.round.f32(float %Val)
  7267. declare double @llvm.round.f64(double %Val)
  7268. declare x86_fp80 @llvm.round.f80(x86_fp80 %Val)
  7269. declare fp128 @llvm.round.f128(fp128 %Val)
  7270. declare ppc_fp128 @llvm.round.ppcf128(ppc_fp128 %Val)
  7271. Overview:
  7272. """""""""
  7273. The '``llvm.round.*``' intrinsics returns the operand rounded to the
  7274. nearest integer.
  7275. Arguments:
  7276. """"""""""
  7277. The argument and return value are floating point numbers of the same
  7278. type.
  7279. Semantics:
  7280. """"""""""
  7281. This function returns the same values as the libm ``round``
  7282. functions would, and handles error conditions in the same way.
  7283. Bit Manipulation Intrinsics
  7284. ---------------------------
  7285. LLVM provides intrinsics for a few important bit manipulation
  7286. operations. These allow efficient code generation for some algorithms.
  7287. '``llvm.bswap.*``' Intrinsics
  7288. ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  7289. Syntax:
  7290. """""""
  7291. This is an overloaded intrinsic function. You can use bswap on any
  7292. integer type that is an even number of bytes (i.e. BitWidth % 16 == 0).
  7293. ::
  7294. declare i16 @llvm.bswap.i16(i16 <id>)
  7295. declare i32 @llvm.bswap.i32(i32 <id>)
  7296. declare i64 @llvm.bswap.i64(i64 <id>)
  7297. Overview:
  7298. """""""""
  7299. The '``llvm.bswap``' family of intrinsics is used to byte swap integer
  7300. values with an even number of bytes (positive multiple of 16 bits).
  7301. These are useful for performing operations on data that is not in the
  7302. target's native byte order.
  7303. Semantics:
  7304. """"""""""
  7305. The ``llvm.bswap.i16`` intrinsic returns an i16 value that has the high
  7306. and low byte of the input i16 swapped. Similarly, the ``llvm.bswap.i32``
  7307. intrinsic returns an i32 value that has the four bytes of the input i32
  7308. swapped, so that if the input bytes are numbered 0, 1, 2, 3 then the
  7309. returned i32 will have its bytes in 3, 2, 1, 0 order. The
  7310. ``llvm.bswap.i48``, ``llvm.bswap.i64`` and other intrinsics extend this
  7311. concept to additional even-byte lengths (6 bytes, 8 bytes and more,
  7312. respectively).
  7313. '``llvm.ctpop.*``' Intrinsic
  7314. ^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  7315. Syntax:
  7316. """""""
  7317. This is an overloaded intrinsic. You can use llvm.ctpop on any integer
  7318. bit width, or on any vector with integer elements. Not all targets
  7319. support all bit widths or vector types, however.
  7320. ::
  7321. declare i8 @llvm.ctpop.i8(i8 <src>)
  7322. declare i16 @llvm.ctpop.i16(i16 <src>)
  7323. declare i32 @llvm.ctpop.i32(i32 <src>)
  7324. declare i64 @llvm.ctpop.i64(i64 <src>)
  7325. declare i256 @llvm.ctpop.i256(i256 <src>)
  7326. declare <2 x i32> @llvm.ctpop.v2i32(<2 x i32> <src>)
  7327. Overview:
  7328. """""""""
  7329. The '``llvm.ctpop``' family of intrinsics counts the number of bits set
  7330. in a value.
  7331. Arguments:
  7332. """"""""""
  7333. The only argument is the value to be counted. The argument may be of any
  7334. integer type, or a vector with integer elements. The return type must
  7335. match the argument type.
  7336. Semantics:
  7337. """"""""""
  7338. The '``llvm.ctpop``' intrinsic counts the 1's in a variable, or within
  7339. each element of a vector.
  7340. '``llvm.ctlz.*``' Intrinsic
  7341. ^^^^^^^^^^^^^^^^^^^^^^^^^^^
  7342. Syntax:
  7343. """""""
  7344. This is an overloaded intrinsic. You can use ``llvm.ctlz`` on any
  7345. integer bit width, or any vector whose elements are integers. Not all
  7346. targets support all bit widths or vector types, however.
  7347. ::
  7348. declare i8 @llvm.ctlz.i8 (i8 <src>, i1 <is_zero_undef>)
  7349. declare i16 @llvm.ctlz.i16 (i16 <src>, i1 <is_zero_undef>)
  7350. declare i32 @llvm.ctlz.i32 (i32 <src>, i1 <is_zero_undef>)
  7351. declare i64 @llvm.ctlz.i64 (i64 <src>, i1 <is_zero_undef>)
  7352. declare i256 @llvm.ctlz.i256(i256 <src>, i1 <is_zero_undef>)
  7353. declase <2 x i32> @llvm.ctlz.v2i32(<2 x i32> <src>, i1 <is_zero_undef>)
  7354. Overview:
  7355. """""""""
  7356. The '``llvm.ctlz``' family of intrinsic functions counts the number of
  7357. leading zeros in a variable.
  7358. Arguments:
  7359. """"""""""
  7360. The first argument is the value to be counted. This argument may be of
  7361. any integer type, or a vector with integer element type. The return
  7362. type must match the first argument type.
  7363. The second argument must be a constant and is a flag to indicate whether
  7364. the intrinsic should ensure that a zero as the first argument produces a
  7365. defined result. Historically some architectures did not provide a
  7366. defined result for zero values as efficiently, and many algorithms are
  7367. now predicated on avoiding zero-value inputs.
  7368. Semantics:
  7369. """"""""""
  7370. The '``llvm.ctlz``' intrinsic counts the leading (most significant)
  7371. zeros in a variable, or within each element of the vector. If
  7372. ``src == 0`` then the result is the size in bits of the type of ``src``
  7373. if ``is_zero_undef == 0`` and ``undef`` otherwise. For example,
  7374. ``llvm.ctlz(i32 2) = 30``.
  7375. '``llvm.cttz.*``' Intrinsic
  7376. ^^^^^^^^^^^^^^^^^^^^^^^^^^^
  7377. Syntax:
  7378. """""""
  7379. This is an overloaded intrinsic. You can use ``llvm.cttz`` on any
  7380. integer bit width, or any vector of integer elements. Not all targets
  7381. support all bit widths or vector types, however.
  7382. ::
  7383. declare i8 @llvm.cttz.i8 (i8 <src>, i1 <is_zero_undef>)
  7384. declare i16 @llvm.cttz.i16 (i16 <src>, i1 <is_zero_undef>)
  7385. declare i32 @llvm.cttz.i32 (i32 <src>, i1 <is_zero_undef>)
  7386. declare i64 @llvm.cttz.i64 (i64 <src>, i1 <is_zero_undef>)
  7387. declare i256 @llvm.cttz.i256(i256 <src>, i1 <is_zero_undef>)
  7388. declase <2 x i32> @llvm.cttz.v2i32(<2 x i32> <src>, i1 <is_zero_undef>)
  7389. Overview:
  7390. """""""""
  7391. The '``llvm.cttz``' family of intrinsic functions counts the number of
  7392. trailing zeros.
  7393. Arguments:
  7394. """"""""""
  7395. The first argument is the value to be counted. This argument may be of
  7396. any integer type, or a vector with integer element type. The return
  7397. type must match the first argument type.
  7398. The second argument must be a constant and is a flag to indicate whether
  7399. the intrinsic should ensure that a zero as the first argument produces a
  7400. defined result. Historically some architectures did not provide a
  7401. defined result for zero values as efficiently, and many algorithms are
  7402. now predicated on avoiding zero-value inputs.
  7403. Semantics:
  7404. """"""""""
  7405. The '``llvm.cttz``' intrinsic counts the trailing (least significant)
  7406. zeros in a variable, or within each element of a vector. If ``src == 0``
  7407. then the result is the size in bits of the type of ``src`` if
  7408. ``is_zero_undef == 0`` and ``undef`` otherwise. For example,
  7409. ``llvm.cttz(2) = 1``.
  7410. .. _int_overflow:
  7411. Arithmetic with Overflow Intrinsics
  7412. -----------------------------------
  7413. LLVM provides intrinsics for some arithmetic with overflow operations.
  7414. '``llvm.sadd.with.overflow.*``' Intrinsics
  7415. ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  7416. Syntax:
  7417. """""""
  7418. This is an overloaded intrinsic. You can use ``llvm.sadd.with.overflow``
  7419. on any integer bit width.
  7420. ::
  7421. declare {i16, i1} @llvm.sadd.with.overflow.i16(i16 %a, i16 %b)
  7422. declare {i32, i1} @llvm.sadd.with.overflow.i32(i32 %a, i32 %b)
  7423. declare {i64, i1} @llvm.sadd.with.overflow.i64(i64 %a, i64 %b)
  7424. Overview:
  7425. """""""""
  7426. The '``llvm.sadd.with.overflow``' family of intrinsic functions perform
  7427. a signed addition of the two arguments, and indicate whether an overflow
  7428. occurred during the signed summation.
  7429. Arguments:
  7430. """"""""""
  7431. The arguments (%a and %b) and the first element of the result structure
  7432. may be of integer types of any bit width, but they must have the same
  7433. bit width. The second element of the result structure must be of type
  7434. ``i1``. ``%a`` and ``%b`` are the two values that will undergo signed
  7435. addition.
  7436. Semantics:
  7437. """"""""""
  7438. The '``llvm.sadd.with.overflow``' family of intrinsic functions perform
  7439. a signed addition of the two variables. They return a structure --- the
  7440. first element of which is the signed summation, and the second element
  7441. of which is a bit specifying if the signed summation resulted in an
  7442. overflow.
  7443. Examples:
  7444. """""""""
  7445. .. code-block:: llvm
  7446. %res = call {i32, i1} @llvm.sadd.with.overflow.i32(i32 %a, i32 %b)
  7447. %sum = extractvalue {i32, i1} %res, 0
  7448. %obit = extractvalue {i32, i1} %res, 1
  7449. br i1 %obit, label %overflow, label %normal
  7450. '``llvm.uadd.with.overflow.*``' Intrinsics
  7451. ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  7452. Syntax:
  7453. """""""
  7454. This is an overloaded intrinsic. You can use ``llvm.uadd.with.overflow``
  7455. on any integer bit width.
  7456. ::
  7457. declare {i16, i1} @llvm.uadd.with.overflow.i16(i16 %a, i16 %b)
  7458. declare {i32, i1} @llvm.uadd.with.overflow.i32(i32 %a, i32 %b)
  7459. declare {i64, i1} @llvm.uadd.with.overflow.i64(i64 %a, i64 %b)
  7460. Overview:
  7461. """""""""
  7462. The '``llvm.uadd.with.overflow``' family of intrinsic functions perform
  7463. an unsigned addition of the two arguments, and indicate whether a carry
  7464. occurred during the unsigned summation.
  7465. Arguments:
  7466. """"""""""
  7467. The arguments (%a and %b) and the first element of the result structure
  7468. may be of integer types of any bit width, but they must have the same
  7469. bit width. The second element of the result structure must be of type
  7470. ``i1``. ``%a`` and ``%b`` are the two values that will undergo unsigned
  7471. addition.
  7472. Semantics:
  7473. """"""""""
  7474. The '``llvm.uadd.with.overflow``' family of intrinsic functions perform
  7475. an unsigned addition of the two arguments. They return a structure --- the
  7476. first element of which is the sum, and the second element of which is a
  7477. bit specifying if the unsigned summation resulted in a carry.
  7478. Examples:
  7479. """""""""
  7480. .. code-block:: llvm
  7481. %res = call {i32, i1} @llvm.uadd.with.overflow.i32(i32 %a, i32 %b)
  7482. %sum = extractvalue {i32, i1} %res, 0
  7483. %obit = extractvalue {i32, i1} %res, 1
  7484. br i1 %obit, label %carry, label %normal
  7485. '``llvm.ssub.with.overflow.*``' Intrinsics
  7486. ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  7487. Syntax:
  7488. """""""
  7489. This is an overloaded intrinsic. You can use ``llvm.ssub.with.overflow``
  7490. on any integer bit width.
  7491. ::
  7492. declare {i16, i1} @llvm.ssub.with.overflow.i16(i16 %a, i16 %b)
  7493. declare {i32, i1} @llvm.ssub.with.overflow.i32(i32 %a, i32 %b)
  7494. declare {i64, i1} @llvm.ssub.with.overflow.i64(i64 %a, i64 %b)
  7495. Overview:
  7496. """""""""
  7497. The '``llvm.ssub.with.overflow``' family of intrinsic functions perform
  7498. a signed subtraction of the two arguments, and indicate whether an
  7499. overflow occurred during the signed subtraction.
  7500. Arguments:
  7501. """"""""""
  7502. The arguments (%a and %b) and the first element of the result structure
  7503. may be of integer types of any bit width, but they must have the same
  7504. bit width. The second element of the result structure must be of type
  7505. ``i1``. ``%a`` and ``%b`` are the two values that will undergo signed
  7506. subtraction.
  7507. Semantics:
  7508. """"""""""
  7509. The '``llvm.ssub.with.overflow``' family of intrinsic functions perform
  7510. a signed subtraction of the two arguments. They return a structure --- the
  7511. first element of which is the subtraction, and the second element of
  7512. which is a bit specifying if the signed subtraction resulted in an
  7513. overflow.
  7514. Examples:
  7515. """""""""
  7516. .. code-block:: llvm
  7517. %res = call {i32, i1} @llvm.ssub.with.overflow.i32(i32 %a, i32 %b)
  7518. %sum = extractvalue {i32, i1} %res, 0
  7519. %obit = extractvalue {i32, i1} %res, 1
  7520. br i1 %obit, label %overflow, label %normal
  7521. '``llvm.usub.with.overflow.*``' Intrinsics
  7522. ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  7523. Syntax:
  7524. """""""
  7525. This is an overloaded intrinsic. You can use ``llvm.usub.with.overflow``
  7526. on any integer bit width.
  7527. ::
  7528. declare {i16, i1} @llvm.usub.with.overflow.i16(i16 %a, i16 %b)
  7529. declare {i32, i1} @llvm.usub.with.overflow.i32(i32 %a, i32 %b)
  7530. declare {i64, i1} @llvm.usub.with.overflow.i64(i64 %a, i64 %b)
  7531. Overview:
  7532. """""""""
  7533. The '``llvm.usub.with.overflow``' family of intrinsic functions perform
  7534. an unsigned subtraction of the two arguments, and indicate whether an
  7535. overflow occurred during the unsigned subtraction.
  7536. Arguments:
  7537. """"""""""
  7538. The arguments (%a and %b) and the first element of the result structure
  7539. may be of integer types of any bit width, but they must have the same
  7540. bit width. The second element of the result structure must be of type
  7541. ``i1``. ``%a`` and ``%b`` are the two values that will undergo unsigned
  7542. subtraction.
  7543. Semantics:
  7544. """"""""""
  7545. The '``llvm.usub.with.overflow``' family of intrinsic functions perform
  7546. an unsigned subtraction of the two arguments. They return a structure ---
  7547. the first element of which is the subtraction, and the second element of
  7548. which is a bit specifying if the unsigned subtraction resulted in an
  7549. overflow.
  7550. Examples:
  7551. """""""""
  7552. .. code-block:: llvm
  7553. %res = call {i32, i1} @llvm.usub.with.overflow.i32(i32 %a, i32 %b)
  7554. %sum = extractvalue {i32, i1} %res, 0
  7555. %obit = extractvalue {i32, i1} %res, 1
  7556. br i1 %obit, label %overflow, label %normal
  7557. '``llvm.smul.with.overflow.*``' Intrinsics
  7558. ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  7559. Syntax:
  7560. """""""
  7561. This is an overloaded intrinsic. You can use ``llvm.smul.with.overflow``
  7562. on any integer bit width.
  7563. ::
  7564. declare {i16, i1} @llvm.smul.with.overflow.i16(i16 %a, i16 %b)
  7565. declare {i32, i1} @llvm.smul.with.overflow.i32(i32 %a, i32 %b)
  7566. declare {i64, i1} @llvm.smul.with.overflow.i64(i64 %a, i64 %b)
  7567. Overview:
  7568. """""""""
  7569. The '``llvm.smul.with.overflow``' family of intrinsic functions perform
  7570. a signed multiplication of the two arguments, and indicate whether an
  7571. overflow occurred during the signed multiplication.
  7572. Arguments:
  7573. """"""""""
  7574. The arguments (%a and %b) and the first element of the result structure
  7575. may be of integer types of any bit width, but they must have the same
  7576. bit width. The second element of the result structure must be of type
  7577. ``i1``. ``%a`` and ``%b`` are the two values that will undergo signed
  7578. multiplication.
  7579. Semantics:
  7580. """"""""""
  7581. The '``llvm.smul.with.overflow``' family of intrinsic functions perform
  7582. a signed multiplication of the two arguments. They return a structure ---
  7583. the first element of which is the multiplication, and the second element
  7584. of which is a bit specifying if the signed multiplication resulted in an
  7585. overflow.
  7586. Examples:
  7587. """""""""
  7588. .. code-block:: llvm
  7589. %res = call {i32, i1} @llvm.smul.with.overflow.i32(i32 %a, i32 %b)
  7590. %sum = extractvalue {i32, i1} %res, 0
  7591. %obit = extractvalue {i32, i1} %res, 1
  7592. br i1 %obit, label %overflow, label %normal
  7593. '``llvm.umul.with.overflow.*``' Intrinsics
  7594. ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  7595. Syntax:
  7596. """""""
  7597. This is an overloaded intrinsic. You can use ``llvm.umul.with.overflow``
  7598. on any integer bit width.
  7599. ::
  7600. declare {i16, i1} @llvm.umul.with.overflow.i16(i16 %a, i16 %b)
  7601. declare {i32, i1} @llvm.umul.with.overflow.i32(i32 %a, i32 %b)
  7602. declare {i64, i1} @llvm.umul.with.overflow.i64(i64 %a, i64 %b)
  7603. Overview:
  7604. """""""""
  7605. The '``llvm.umul.with.overflow``' family of intrinsic functions perform
  7606. a unsigned multiplication of the two arguments, and indicate whether an
  7607. overflow occurred during the unsigned multiplication.
  7608. Arguments:
  7609. """"""""""
  7610. The arguments (%a and %b) and the first element of the result structure
  7611. may be of integer types of any bit width, but they must have the same
  7612. bit width. The second element of the result structure must be of type
  7613. ``i1``. ``%a`` and ``%b`` are the two values that will undergo unsigned
  7614. multiplication.
  7615. Semantics:
  7616. """"""""""
  7617. The '``llvm.umul.with.overflow``' family of intrinsic functions perform
  7618. an unsigned multiplication of the two arguments. They return a structure ---
  7619. the first element of which is the multiplication, and the second
  7620. element of which is a bit specifying if the unsigned multiplication
  7621. resulted in an overflow.
  7622. Examples:
  7623. """""""""
  7624. .. code-block:: llvm
  7625. %res = call {i32, i1} @llvm.umul.with.overflow.i32(i32 %a, i32 %b)
  7626. %sum = extractvalue {i32, i1} %res, 0
  7627. %obit = extractvalue {i32, i1} %res, 1
  7628. br i1 %obit, label %overflow, label %normal
  7629. Specialised Arithmetic Intrinsics
  7630. ---------------------------------
  7631. '``llvm.canonicalize.*``' Intrinsic
  7632. ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  7633. Syntax:
  7634. """""""
  7635. ::
  7636. declare float @llvm.canonicalize.f32(float %a)
  7637. declare double @llvm.canonicalize.f64(double %b)
  7638. Overview:
  7639. """""""""
  7640. The '``llvm.canonicalize.*``' intrinsic returns the platform specific canonical
  7641. encoding of a floating point number. This canonicalization is useful for
  7642. implementing certain numeric primitives such as frexp. The canonical encoding is
  7643. defined by IEEE-754-2008 to be:
  7644. ::
  7645. 2.1.8 canonical encoding: The preferred encoding of a floating-point
  7646. representation in a format. Applied to declets, significands of finite
  7647. numbers, infinities, and NaNs, especially in decimal formats.
  7648. This operation can also be considered equivalent to the IEEE-754-2008
  7649. conversion of a floating-point value to the same format. NaNs are handled
  7650. according to section 6.2.
  7651. Examples of non-canonical encodings:
  7652. - x87 pseudo denormals, pseudo NaNs, pseudo Infinity, Unnormals. These are
  7653. converted to a canonical representation per hardware-specific protocol.
  7654. - Many normal decimal floating point numbers have non-canonical alternative
  7655. encodings.
  7656. - Some machines, like GPUs or ARMv7 NEON, do not support subnormal values.
  7657. These are treated as non-canonical encodings of zero and with be flushed to
  7658. a zero of the same sign by this operation.
  7659. Note that per IEEE-754-2008 6.2, systems that support signaling NaNs with
  7660. default exception handling must signal an invalid exception, and produce a
  7661. quiet NaN result.
  7662. This function should always be implementable as multiplication by 1.0, provided
  7663. that the compiler does not constant fold the operation. Likewise, division by
  7664. 1.0 and ``llvm.minnum(x, x)`` are possible implementations. Addition with
  7665. -0.0 is also sufficient provided that the rounding mode is not -Infinity.
  7666. ``@llvm.canonicalize`` must preserve the equality relation. That is:
  7667. - ``(@llvm.canonicalize(x) == x)`` is equivalent to ``(x == x)``
  7668. - ``(@llvm.canonicalize(x) == @llvm.canonicalize(y))`` is equivalent to
  7669. to ``(x == y)``
  7670. Additionally, the sign of zero must be conserved:
  7671. ``@llvm.canonicalize(-0.0) = -0.0`` and ``@llvm.canonicalize(+0.0) = +0.0``
  7672. The payload bits of a NaN must be conserved, with two exceptions.
  7673. First, environments which use only a single canonical representation of NaN
  7674. must perform said canonicalization. Second, SNaNs must be quieted per the
  7675. usual methods.
  7676. The canonicalization operation may be optimized away if:
  7677. - The input is known to be canonical. For example, it was produced by a
  7678. floating-point operation that is required by the standard to be canonical.
  7679. - The result is consumed only by (or fused with) other floating-point
  7680. operations. That is, the bits of the floating point value are not examined.
  7681. '``llvm.fmuladd.*``' Intrinsic
  7682. ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  7683. Syntax:
  7684. """""""
  7685. ::
  7686. declare float @llvm.fmuladd.f32(float %a, float %b, float %c)
  7687. declare double @llvm.fmuladd.f64(double %a, double %b, double %c)
  7688. Overview:
  7689. """""""""
  7690. The '``llvm.fmuladd.*``' intrinsic functions represent multiply-add
  7691. expressions that can be fused if the code generator determines that (a) the
  7692. target instruction set has support for a fused operation, and (b) that the
  7693. fused operation is more efficient than the equivalent, separate pair of mul
  7694. and add instructions.
  7695. Arguments:
  7696. """"""""""
  7697. The '``llvm.fmuladd.*``' intrinsics each take three arguments: two
  7698. multiplicands, a and b, and an addend c.
  7699. Semantics:
  7700. """"""""""
  7701. The expression:
  7702. ::
  7703. %0 = call float @llvm.fmuladd.f32(%a, %b, %c)
  7704. is equivalent to the expression a \* b + c, except that rounding will
  7705. not be performed between the multiplication and addition steps if the
  7706. code generator fuses the operations. Fusion is not guaranteed, even if
  7707. the target platform supports it. If a fused multiply-add is required the
  7708. corresponding llvm.fma.\* intrinsic function should be used
  7709. instead. This never sets errno, just as '``llvm.fma.*``'.
  7710. Examples:
  7711. """""""""
  7712. .. code-block:: llvm
  7713. %r2 = call float @llvm.fmuladd.f32(float %a, float %b, float %c) ; yields float:r2 = (a * b) + c
  7714. Half Precision Floating Point Intrinsics
  7715. ----------------------------------------
  7716. For most target platforms, half precision floating point is a
  7717. storage-only format. This means that it is a dense encoding (in memory)
  7718. but does not support computation in the format.
  7719. This means that code must first load the half-precision floating point
  7720. value as an i16, then convert it to float with
  7721. :ref:`llvm.convert.from.fp16 <int_convert_from_fp16>`. Computation can
  7722. then be performed on the float value (including extending to double
  7723. etc). To store the value back to memory, it is first converted to float
  7724. if needed, then converted to i16 with
  7725. :ref:`llvm.convert.to.fp16 <int_convert_to_fp16>`, then storing as an
  7726. i16 value.
  7727. .. _int_convert_to_fp16:
  7728. '``llvm.convert.to.fp16``' Intrinsic
  7729. ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  7730. Syntax:
  7731. """""""
  7732. ::
  7733. declare i16 @llvm.convert.to.fp16.f32(float %a)
  7734. declare i16 @llvm.convert.to.fp16.f64(double %a)
  7735. Overview:
  7736. """""""""
  7737. The '``llvm.convert.to.fp16``' intrinsic function performs a conversion from a
  7738. conventional floating point type to half precision floating point format.
  7739. Arguments:
  7740. """"""""""
  7741. The intrinsic function contains single argument - the value to be
  7742. converted.
  7743. Semantics:
  7744. """"""""""
  7745. The '``llvm.convert.to.fp16``' intrinsic function performs a conversion from a
  7746. conventional floating point format to half precision floating point format. The
  7747. return value is an ``i16`` which contains the converted number.
  7748. Examples:
  7749. """""""""
  7750. .. code-block:: llvm
  7751. %res = call i16 @llvm.convert.to.fp16.f32(float %a)
  7752. store i16 %res, i16* @x, align 2
  7753. .. _int_convert_from_fp16:
  7754. '``llvm.convert.from.fp16``' Intrinsic
  7755. ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  7756. Syntax:
  7757. """""""
  7758. ::
  7759. declare float @llvm.convert.from.fp16.f32(i16 %a)
  7760. declare double @llvm.convert.from.fp16.f64(i16 %a)
  7761. Overview:
  7762. """""""""
  7763. The '``llvm.convert.from.fp16``' intrinsic function performs a
  7764. conversion from half precision floating point format to single precision
  7765. floating point format.
  7766. Arguments:
  7767. """"""""""
  7768. The intrinsic function contains single argument - the value to be
  7769. converted.
  7770. Semantics:
  7771. """"""""""
  7772. The '``llvm.convert.from.fp16``' intrinsic function performs a
  7773. conversion from half single precision floating point format to single
  7774. precision floating point format. The input half-float value is
  7775. represented by an ``i16`` value.
  7776. Examples:
  7777. """""""""
  7778. .. code-block:: llvm
  7779. %a = load i16, i16* @x, align 2
  7780. %res = call float @llvm.convert.from.fp16(i16 %a)
  7781. .. _dbg_intrinsics:
  7782. Debugger Intrinsics
  7783. -------------------
  7784. The LLVM debugger intrinsics (which all start with ``llvm.dbg.``
  7785. prefix), are described in the `LLVM Source Level
  7786. Debugging <SourceLevelDebugging.html#format_common_intrinsics>`_
  7787. document.
  7788. Exception Handling Intrinsics
  7789. -----------------------------
  7790. The LLVM exception handling intrinsics (which all start with
  7791. ``llvm.eh.`` prefix), are described in the `LLVM Exception
  7792. Handling <ExceptionHandling.html#format_common_intrinsics>`_ document.
  7793. .. _int_trampoline:
  7794. Trampoline Intrinsics
  7795. ---------------------
  7796. These intrinsics make it possible to excise one parameter, marked with
  7797. the :ref:`nest <nest>` attribute, from a function. The result is a
  7798. callable function pointer lacking the nest parameter - the caller does
  7799. not need to provide a value for it. Instead, the value to use is stored
  7800. in advance in a "trampoline", a block of memory usually allocated on the
  7801. stack, which also contains code to splice the nest value into the
  7802. argument list. This is used to implement the GCC nested function address
  7803. extension.
  7804. For example, if the function is ``i32 f(i8* nest %c, i32 %x, i32 %y)``
  7805. then the resulting function pointer has signature ``i32 (i32, i32)*``.
  7806. It can be created as follows:
  7807. .. code-block:: llvm
  7808. %tramp = alloca [10 x i8], align 4 ; size and alignment only correct for X86
  7809. %tramp1 = getelementptr [10 x i8], [10 x i8]* %tramp, i32 0, i32 0
  7810. call i8* @llvm.init.trampoline(i8* %tramp1, i8* bitcast (i32 (i8*, i32, i32)* @f to i8*), i8* %nval)
  7811. %p = call i8* @llvm.adjust.trampoline(i8* %tramp1)
  7812. %fp = bitcast i8* %p to i32 (i32, i32)*
  7813. The call ``%val = call i32 %fp(i32 %x, i32 %y)`` is then equivalent to
  7814. ``%val = call i32 %f(i8* %nval, i32 %x, i32 %y)``.
  7815. .. _int_it:
  7816. '``llvm.init.trampoline``' Intrinsic
  7817. ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  7818. Syntax:
  7819. """""""
  7820. ::
  7821. declare void @llvm.init.trampoline(i8* <tramp>, i8* <func>, i8* <nval>)
  7822. Overview:
  7823. """""""""
  7824. This fills the memory pointed to by ``tramp`` with executable code,
  7825. turning it into a trampoline.
  7826. Arguments:
  7827. """"""""""
  7828. The ``llvm.init.trampoline`` intrinsic takes three arguments, all
  7829. pointers. The ``tramp`` argument must point to a sufficiently large and
  7830. sufficiently aligned block of memory; this memory is written to by the
  7831. intrinsic. Note that the size and the alignment are target-specific -
  7832. LLVM currently provides no portable way of determining them, so a
  7833. front-end that generates this intrinsic needs to have some
  7834. target-specific knowledge. The ``func`` argument must hold a function
  7835. bitcast to an ``i8*``.
  7836. Semantics:
  7837. """"""""""
  7838. The block of memory pointed to by ``tramp`` is filled with target
  7839. dependent code, turning it into a function. Then ``tramp`` needs to be
  7840. passed to :ref:`llvm.adjust.trampoline <int_at>` to get a pointer which can
  7841. be :ref:`bitcast (to a new function) and called <int_trampoline>`. The new
  7842. function's signature is the same as that of ``func`` with any arguments
  7843. marked with the ``nest`` attribute removed. At most one such ``nest``
  7844. argument is allowed, and it must be of pointer type. Calling the new
  7845. function is equivalent to calling ``func`` with the same argument list,
  7846. but with ``nval`` used for the missing ``nest`` argument. If, after
  7847. calling ``llvm.init.trampoline``, the memory pointed to by ``tramp`` is
  7848. modified, then the effect of any later call to the returned function
  7849. pointer is undefined.
  7850. .. _int_at:
  7851. '``llvm.adjust.trampoline``' Intrinsic
  7852. ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  7853. Syntax:
  7854. """""""
  7855. ::
  7856. declare i8* @llvm.adjust.trampoline(i8* <tramp>)
  7857. Overview:
  7858. """""""""
  7859. This performs any required machine-specific adjustment to the address of
  7860. a trampoline (passed as ``tramp``).
  7861. Arguments:
  7862. """"""""""
  7863. ``tramp`` must point to a block of memory which already has trampoline
  7864. code filled in by a previous call to
  7865. :ref:`llvm.init.trampoline <int_it>`.
  7866. Semantics:
  7867. """"""""""
  7868. On some architectures the address of the code to be executed needs to be
  7869. different than the address where the trampoline is actually stored. This
  7870. intrinsic returns the executable address corresponding to ``tramp``
  7871. after performing the required machine specific adjustments. The pointer
  7872. returned can then be :ref:`bitcast and executed <int_trampoline>`.
  7873. .. _int_mload_mstore:
  7874. Masked Vector Load and Store Intrinsics
  7875. ---------------------------------------
  7876. 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.
  7877. .. _int_mload:
  7878. '``llvm.masked.load.*``' Intrinsics
  7879. ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  7880. Syntax:
  7881. """""""
  7882. This is an overloaded intrinsic. The loaded data is a vector of any integer or floating point data type.
  7883. ::
  7884. declare <16 x float> @llvm.masked.load.v16f32 (<16 x float>* <ptr>, i32 <alignment>, <16 x i1> <mask>, <16 x float> <passthru>)
  7885. declare <2 x double> @llvm.masked.load.v2f64 (<2 x double>* <ptr>, i32 <alignment>, <2 x i1> <mask>, <2 x double> <passthru>)
  7886. Overview:
  7887. """""""""
  7888. 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.
  7889. Arguments:
  7890. """"""""""
  7891. 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.
  7892. Semantics:
  7893. """"""""""
  7894. 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.
  7895. 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.
  7896. ::
  7897. %res = call <16 x float> @llvm.masked.load.v16f32 (<16 x float>* %ptr, i32 4, <16 x i1>%mask, <16 x float> %passthru)
  7898. ;; The result of the two following instructions is identical aside from potential memory access exception
  7899. %loadlal = load <16 x float>, <16 x float>* %ptr, align 4
  7900. %res = select <16 x i1> %mask, <16 x float> %loadlal, <16 x float> %passthru
  7901. .. _int_mstore:
  7902. '``llvm.masked.store.*``' Intrinsics
  7903. ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  7904. Syntax:
  7905. """""""
  7906. This is an overloaded intrinsic. The data stored in memory is a vector of any integer or floating point data type.
  7907. ::
  7908. declare void @llvm.masked.store.v8i32 (<8 x i32> <value>, <8 x i32> * <ptr>, i32 <alignment>, <8 x i1> <mask>)
  7909. declare void @llvm.masked.store.v16f32(<16 x i32> <value>, <16 x i32>* <ptr>, i32 <alignment>, <16 x i1> <mask>)
  7910. Overview:
  7911. """""""""
  7912. 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.
  7913. Arguments:
  7914. """"""""""
  7915. 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.
  7916. Semantics:
  7917. """"""""""
  7918. 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.
  7919. 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.
  7920. ::
  7921. call void @llvm.masked.store.v16f32(<16 x float> %value, <16 x float>* %ptr, i32 4, <16 x i1> %mask)
  7922. ;; The result of the following instructions is identical aside from potential data races and memory access exceptions
  7923. %oldval = load <16 x float>, <16 x float>* %ptr, align 4
  7924. %res = select <16 x i1> %mask, <16 x float> %value, <16 x float> %oldval
  7925. store <16 x float> %res, <16 x float>* %ptr, align 4
  7926. Masked Vector Gather and Scatter Intrinsics
  7927. -------------------------------------------
  7928. 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.
  7929. .. _int_mgather:
  7930. '``llvm.masked.gather.*``' Intrinsics
  7931. ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  7932. Syntax:
  7933. """""""
  7934. This is an overloaded intrinsic. The loaded data are multiple scalar values of any integer or floating point data type gathered together into one vector.
  7935. ::
  7936. declare <16 x float> @llvm.masked.gather.v16f32 (<16 x float*> <ptrs>, i32 <alignment>, <16 x i1> <mask>, <16 x float> <passthru>)
  7937. declare <2 x double> @llvm.masked.gather.v2f64 (<2 x double*> <ptrs>, i32 <alignment>, <2 x i1> <mask>, <2 x double> <passthru>)
  7938. Overview:
  7939. """""""""
  7940. 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.
  7941. Arguments:
  7942. """"""""""
  7943. 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.
  7944. Semantics:
  7945. """"""""""
  7946. 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.
  7947. 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.
  7948. ::
  7949. %res = call <4 x double> @llvm.masked.gather.v4f64 (<4 x double*> %ptrs, i32 8, <4 x i1>%mask, <4 x double> <true, true, true, true>)
  7950. ;; The gather with all-true mask is equivalent to the following instruction sequence
  7951. %ptr0 = extractelement <4 x double*> %ptrs, i32 0
  7952. %ptr1 = extractelement <4 x double*> %ptrs, i32 1
  7953. %ptr2 = extractelement <4 x double*> %ptrs, i32 2
  7954. %ptr3 = extractelement <4 x double*> %ptrs, i32 3
  7955. %val0 = load double, double* %ptr0, align 8
  7956. %val1 = load double, double* %ptr1, align 8
  7957. %val2 = load double, double* %ptr2, align 8
  7958. %val3 = load double, double* %ptr3, align 8
  7959. %vec0 = insertelement <4 x double>undef, %val0, 0
  7960. %vec01 = insertelement <4 x double>%vec0, %val1, 1
  7961. %vec012 = insertelement <4 x double>%vec01, %val2, 2
  7962. %vec0123 = insertelement <4 x double>%vec012, %val3, 3
  7963. .. _int_mscatter:
  7964. '``llvm.masked.scatter.*``' Intrinsics
  7965. ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  7966. Syntax:
  7967. """""""
  7968. This is an overloaded intrinsic. The data stored in memory is a vector of any integer or floating point data type. Each vector element is stored in an arbitrary memory addresses. Scatter with overlapping addresses is guaranteed to be ordered from least-significant to most-significant element.
  7969. ::
  7970. declare void @llvm.masked.scatter.v8i32 (<8 x i32> <value>, <8 x i32*> <ptrs>, i32 <alignment>, <8 x i1> <mask>)
  7971. declare void @llvm.masked.scatter.v16f32(<16 x i32> <value>, <16 x i32*> <ptrs>, i32 <alignment>, <16 x i1> <mask>)
  7972. Overview:
  7973. """""""""
  7974. 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.
  7975. Arguments:
  7976. """"""""""
  7977. 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.
  7978. Semantics:
  7979. """"""""""
  7980. 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 divergency. Other targets may support this intrinsic differently, for example by lowering it into a sequence of branches that guard scalar store operations.
  7981. ::
  7982. ;; This instruction unconditionaly stores data vector in multiple addresses
  7983. call @llvm.masked.scatter.v8i32 (<8 x i32> %value, <8 x i32*> %ptrs, i32 4, <8 x i1> <true, true, .. true>)
  7984. ;; It is equivalent to a list of scalar stores
  7985. %val0 = extractelement <8 x i32> %value, i32 0
  7986. %val1 = extractelement <8 x i32> %value, i32 1
  7987. ..
  7988. %val7 = extractelement <8 x i32> %value, i32 7
  7989. %ptr0 = extractelement <8 x i32*> %ptrs, i32 0
  7990. %ptr1 = extractelement <8 x i32*> %ptrs, i32 1
  7991. ..
  7992. %ptr7 = extractelement <8 x i32*> %ptrs, i32 7
  7993. ;; Note: the order of the following stores is important when they overlap:
  7994. store i32 %val0, i32* %ptr0, align 4
  7995. store i32 %val1, i32* %ptr1, align 4
  7996. ..
  7997. store i32 %val7, i32* %ptr7, align 4
  7998. Memory Use Markers
  7999. ------------------
  8000. This class of intrinsics provides information about the lifetime of
  8001. memory objects and ranges where variables are immutable.
  8002. .. _int_lifestart:
  8003. '``llvm.lifetime.start``' Intrinsic
  8004. ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  8005. Syntax:
  8006. """""""
  8007. ::
  8008. declare void @llvm.lifetime.start(i64 <size>, i8* nocapture <ptr>)
  8009. Overview:
  8010. """""""""
  8011. The '``llvm.lifetime.start``' intrinsic specifies the start of a memory
  8012. object's lifetime.
  8013. Arguments:
  8014. """"""""""
  8015. The first argument is a constant integer representing the size of the
  8016. object, or -1 if it is variable sized. The second argument is a pointer
  8017. to the object.
  8018. Semantics:
  8019. """"""""""
  8020. This intrinsic indicates that before this point in the code, the value
  8021. of the memory pointed to by ``ptr`` is dead. This means that it is known
  8022. to never be used and has an undefined value. A load from the pointer
  8023. that precedes this intrinsic can be replaced with ``'undef'``.
  8024. .. _int_lifeend:
  8025. '``llvm.lifetime.end``' Intrinsic
  8026. ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  8027. Syntax:
  8028. """""""
  8029. ::
  8030. declare void @llvm.lifetime.end(i64 <size>, i8* nocapture <ptr>)
  8031. Overview:
  8032. """""""""
  8033. The '``llvm.lifetime.end``' intrinsic specifies the end of a memory
  8034. object's lifetime.
  8035. Arguments:
  8036. """"""""""
  8037. The first argument is a constant integer representing the size of the
  8038. object, or -1 if it is variable sized. The second argument is a pointer
  8039. to the object.
  8040. Semantics:
  8041. """"""""""
  8042. This intrinsic indicates that after this point in the code, the value of
  8043. the memory pointed to by ``ptr`` is dead. This means that it is known to
  8044. never be used and has an undefined value. Any stores into the memory
  8045. object following this intrinsic may be removed as dead.
  8046. '``llvm.invariant.start``' Intrinsic
  8047. ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  8048. Syntax:
  8049. """""""
  8050. ::
  8051. declare {}* @llvm.invariant.start(i64 <size>, i8* nocapture <ptr>)
  8052. Overview:
  8053. """""""""
  8054. The '``llvm.invariant.start``' intrinsic specifies that the contents of
  8055. a memory object will not change.
  8056. Arguments:
  8057. """"""""""
  8058. The first argument is a constant integer representing the size of the
  8059. object, or -1 if it is variable sized. The second argument is a pointer
  8060. to the object.
  8061. Semantics:
  8062. """"""""""
  8063. This intrinsic indicates that until an ``llvm.invariant.end`` that uses
  8064. the return value, the referenced memory location is constant and
  8065. unchanging.
  8066. '``llvm.invariant.end``' Intrinsic
  8067. ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  8068. Syntax:
  8069. """""""
  8070. ::
  8071. declare void @llvm.invariant.end({}* <start>, i64 <size>, i8* nocapture <ptr>)
  8072. Overview:
  8073. """""""""
  8074. The '``llvm.invariant.end``' intrinsic specifies that the contents of a
  8075. memory object are mutable.
  8076. Arguments:
  8077. """"""""""
  8078. The first argument is the matching ``llvm.invariant.start`` intrinsic.
  8079. The second argument is a constant integer representing the size of the
  8080. object, or -1 if it is variable sized and the third argument is a
  8081. pointer to the object.
  8082. Semantics:
  8083. """"""""""
  8084. This intrinsic indicates that the memory is mutable again.
  8085. General Intrinsics
  8086. ------------------
  8087. This class of intrinsics is designed to be generic and has no specific
  8088. purpose.
  8089. '``llvm.var.annotation``' Intrinsic
  8090. ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  8091. Syntax:
  8092. """""""
  8093. ::
  8094. declare void @llvm.var.annotation(i8* <val>, i8* <str>, i8* <str>, i32 <int>)
  8095. Overview:
  8096. """""""""
  8097. The '``llvm.var.annotation``' intrinsic.
  8098. Arguments:
  8099. """"""""""
  8100. The first argument is a pointer to a value, the second is a pointer to a
  8101. global string, the third is a pointer to a global string which is the
  8102. source file name, and the last argument is the line number.
  8103. Semantics:
  8104. """"""""""
  8105. This intrinsic allows annotation of local variables with arbitrary
  8106. strings. This can be useful for special purpose optimizations that want
  8107. to look for these annotations. These have no other defined use; they are
  8108. ignored by code generation and optimization.
  8109. '``llvm.ptr.annotation.*``' Intrinsic
  8110. ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  8111. Syntax:
  8112. """""""
  8113. This is an overloaded intrinsic. You can use '``llvm.ptr.annotation``' on a
  8114. pointer to an integer of any width. *NOTE* you must specify an address space for
  8115. the pointer. The identifier for the default address space is the integer
  8116. '``0``'.
  8117. ::
  8118. declare i8* @llvm.ptr.annotation.p<address space>i8(i8* <val>, i8* <str>, i8* <str>, i32 <int>)
  8119. declare i16* @llvm.ptr.annotation.p<address space>i16(i16* <val>, i8* <str>, i8* <str>, i32 <int>)
  8120. declare i32* @llvm.ptr.annotation.p<address space>i32(i32* <val>, i8* <str>, i8* <str>, i32 <int>)
  8121. declare i64* @llvm.ptr.annotation.p<address space>i64(i64* <val>, i8* <str>, i8* <str>, i32 <int>)
  8122. declare i256* @llvm.ptr.annotation.p<address space>i256(i256* <val>, i8* <str>, i8* <str>, i32 <int>)
  8123. Overview:
  8124. """""""""
  8125. The '``llvm.ptr.annotation``' intrinsic.
  8126. Arguments:
  8127. """"""""""
  8128. The first argument is a pointer to an integer value of arbitrary bitwidth
  8129. (result of some expression), the second is a pointer to a global string, the
  8130. third is a pointer to a global string which is the source file name, and the
  8131. last argument is the line number. It returns the value of the first argument.
  8132. Semantics:
  8133. """"""""""
  8134. This intrinsic allows annotation of a pointer to an integer with arbitrary
  8135. strings. This can be useful for special purpose optimizations that want to look
  8136. for these annotations. These have no other defined use; they are ignored by code
  8137. generation and optimization.
  8138. '``llvm.annotation.*``' Intrinsic
  8139. ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  8140. Syntax:
  8141. """""""
  8142. This is an overloaded intrinsic. You can use '``llvm.annotation``' on
  8143. any integer bit width.
  8144. ::
  8145. declare i8 @llvm.annotation.i8(i8 <val>, i8* <str>, i8* <str>, i32 <int>)
  8146. declare i16 @llvm.annotation.i16(i16 <val>, i8* <str>, i8* <str>, i32 <int>)
  8147. declare i32 @llvm.annotation.i32(i32 <val>, i8* <str>, i8* <str>, i32 <int>)
  8148. declare i64 @llvm.annotation.i64(i64 <val>, i8* <str>, i8* <str>, i32 <int>)
  8149. declare i256 @llvm.annotation.i256(i256 <val>, i8* <str>, i8* <str>, i32 <int>)
  8150. Overview:
  8151. """""""""
  8152. The '``llvm.annotation``' intrinsic.
  8153. Arguments:
  8154. """"""""""
  8155. The first argument is an integer value (result of some expression), the
  8156. second is a pointer to a global string, the third is a pointer to a
  8157. global string which is the source file name, and the last argument is
  8158. the line number. It returns the value of the first argument.
  8159. Semantics:
  8160. """"""""""
  8161. This intrinsic allows annotations to be put on arbitrary expressions
  8162. with arbitrary strings. This can be useful for special purpose
  8163. optimizations that want to look for these annotations. These have no
  8164. other defined use; they are ignored by code generation and optimization.
  8165. '``llvm.trap``' Intrinsic
  8166. ^^^^^^^^^^^^^^^^^^^^^^^^^
  8167. Syntax:
  8168. """""""
  8169. ::
  8170. declare void @llvm.trap() noreturn nounwind
  8171. Overview:
  8172. """""""""
  8173. The '``llvm.trap``' intrinsic.
  8174. Arguments:
  8175. """"""""""
  8176. None.
  8177. Semantics:
  8178. """"""""""
  8179. This intrinsic is lowered to the target dependent trap instruction. If
  8180. the target does not have a trap instruction, this intrinsic will be
  8181. lowered to a call of the ``abort()`` function.
  8182. '``llvm.debugtrap``' Intrinsic
  8183. ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  8184. Syntax:
  8185. """""""
  8186. ::
  8187. declare void @llvm.debugtrap() nounwind
  8188. Overview:
  8189. """""""""
  8190. The '``llvm.debugtrap``' intrinsic.
  8191. Arguments:
  8192. """"""""""
  8193. None.
  8194. Semantics:
  8195. """"""""""
  8196. This intrinsic is lowered to code which is intended to cause an
  8197. execution trap with the intention of requesting the attention of a
  8198. debugger.
  8199. '``llvm.stackprotector``' Intrinsic
  8200. ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  8201. Syntax:
  8202. """""""
  8203. ::
  8204. declare void @llvm.stackprotector(i8* <guard>, i8** <slot>)
  8205. Overview:
  8206. """""""""
  8207. The ``llvm.stackprotector`` intrinsic takes the ``guard`` and stores it
  8208. onto the stack at ``slot``. The stack slot is adjusted to ensure that it
  8209. is placed on the stack before local variables.
  8210. Arguments:
  8211. """"""""""
  8212. The ``llvm.stackprotector`` intrinsic requires two pointer arguments.
  8213. The first argument is the value loaded from the stack guard
  8214. ``@__stack_chk_guard``. The second variable is an ``alloca`` that has
  8215. enough space to hold the value of the guard.
  8216. Semantics:
  8217. """"""""""
  8218. This intrinsic causes the prologue/epilogue inserter to force the position of
  8219. the ``AllocaInst`` stack slot to be before local variables on the stack. This is
  8220. to ensure that if a local variable on the stack is overwritten, it will destroy
  8221. the value of the guard. When the function exits, the guard on the stack is
  8222. checked against the original guard by ``llvm.stackprotectorcheck``. If they are
  8223. different, then ``llvm.stackprotectorcheck`` causes the program to abort by
  8224. calling the ``__stack_chk_fail()`` function.
  8225. '``llvm.stackprotectorcheck``' Intrinsic
  8226. ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  8227. Syntax:
  8228. """""""
  8229. ::
  8230. declare void @llvm.stackprotectorcheck(i8** <guard>)
  8231. Overview:
  8232. """""""""
  8233. The ``llvm.stackprotectorcheck`` intrinsic compares ``guard`` against an already
  8234. created stack protector and if they are not equal calls the
  8235. ``__stack_chk_fail()`` function.
  8236. Arguments:
  8237. """"""""""
  8238. The ``llvm.stackprotectorcheck`` intrinsic requires one pointer argument, the
  8239. the variable ``@__stack_chk_guard``.
  8240. Semantics:
  8241. """"""""""
  8242. This intrinsic is provided to perform the stack protector check by comparing
  8243. ``guard`` with the stack slot created by ``llvm.stackprotector`` and if the
  8244. values do not match call the ``__stack_chk_fail()`` function.
  8245. The reason to provide this as an IR level intrinsic instead of implementing it
  8246. via other IR operations is that in order to perform this operation at the IR
  8247. level without an intrinsic, one would need to create additional basic blocks to
  8248. handle the success/failure cases. This makes it difficult to stop the stack
  8249. protector check from disrupting sibling tail calls in Codegen. With this
  8250. intrinsic, we are able to generate the stack protector basic blocks late in
  8251. codegen after the tail call decision has occurred.
  8252. '``llvm.objectsize``' Intrinsic
  8253. ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  8254. Syntax:
  8255. """""""
  8256. ::
  8257. declare i32 @llvm.objectsize.i32(i8* <object>, i1 <min>)
  8258. declare i64 @llvm.objectsize.i64(i8* <object>, i1 <min>)
  8259. Overview:
  8260. """""""""
  8261. The ``llvm.objectsize`` intrinsic is designed to provide information to
  8262. the optimizers to determine at compile time whether a) an operation
  8263. (like memcpy) will overflow a buffer that corresponds to an object, or
  8264. b) that a runtime check for overflow isn't necessary. An object in this
  8265. context means an allocation of a specific class, structure, array, or
  8266. other object.
  8267. Arguments:
  8268. """"""""""
  8269. The ``llvm.objectsize`` intrinsic takes two arguments. The first
  8270. argument is a pointer to or into the ``object``. The second argument is
  8271. a boolean and determines whether ``llvm.objectsize`` returns 0 (if true)
  8272. or -1 (if false) when the object size is unknown. The second argument
  8273. only accepts constants.
  8274. Semantics:
  8275. """"""""""
  8276. The ``llvm.objectsize`` intrinsic is lowered to a constant representing
  8277. the size of the object concerned. If the size cannot be determined at
  8278. compile time, ``llvm.objectsize`` returns ``i32/i64 -1 or 0`` (depending
  8279. on the ``min`` argument).
  8280. '``llvm.expect``' Intrinsic
  8281. ^^^^^^^^^^^^^^^^^^^^^^^^^^^
  8282. Syntax:
  8283. """""""
  8284. This is an overloaded intrinsic. You can use ``llvm.expect`` on any
  8285. integer bit width.
  8286. ::
  8287. declare i1 @llvm.expect.i1(i1 <val>, i1 <expected_val>)
  8288. declare i32 @llvm.expect.i32(i32 <val>, i32 <expected_val>)
  8289. declare i64 @llvm.expect.i64(i64 <val>, i64 <expected_val>)
  8290. Overview:
  8291. """""""""
  8292. The ``llvm.expect`` intrinsic provides information about expected (the
  8293. most probable) value of ``val``, which can be used by optimizers.
  8294. Arguments:
  8295. """"""""""
  8296. The ``llvm.expect`` intrinsic takes two arguments. The first argument is
  8297. a value. The second argument is an expected value, this needs to be a
  8298. constant value, variables are not allowed.
  8299. Semantics:
  8300. """"""""""
  8301. This intrinsic is lowered to the ``val``.
  8302. .. _int_assume:
  8303. '``llvm.assume``' Intrinsic
  8304. ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  8305. Syntax:
  8306. """""""
  8307. ::
  8308. declare void @llvm.assume(i1 %cond)
  8309. Overview:
  8310. """""""""
  8311. The ``llvm.assume`` allows the optimizer to assume that the provided
  8312. condition is true. This information can then be used in simplifying other parts
  8313. of the code.
  8314. Arguments:
  8315. """"""""""
  8316. The condition which the optimizer may assume is always true.
  8317. Semantics:
  8318. """"""""""
  8319. The intrinsic allows the optimizer to assume that the provided condition is
  8320. always true whenever the control flow reaches the intrinsic call. No code is
  8321. generated for this intrinsic, and instructions that contribute only to the
  8322. provided condition are not used for code generation. If the condition is
  8323. violated during execution, the behavior is undefined.
  8324. Note that the optimizer might limit the transformations performed on values
  8325. used by the ``llvm.assume`` intrinsic in order to preserve the instructions
  8326. only used to form the intrinsic's input argument. This might prove undesirable
  8327. if the extra information provided by the ``llvm.assume`` intrinsic does not cause
  8328. sufficient overall improvement in code quality. For this reason,
  8329. ``llvm.assume`` should not be used to document basic mathematical invariants
  8330. that the optimizer can otherwise deduce or facts that are of little use to the
  8331. optimizer.
  8332. .. _bitset.test:
  8333. '``llvm.bitset.test``' Intrinsic
  8334. ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  8335. Syntax:
  8336. """""""
  8337. ::
  8338. declare i1 @llvm.bitset.test(i8* %ptr, metadata %bitset) nounwind readnone
  8339. Arguments:
  8340. """"""""""
  8341. The first argument is a pointer to be tested. The second argument is a
  8342. metadata string containing the name of a :doc:`bitset <BitSets>`.
  8343. Overview:
  8344. """""""""
  8345. The ``llvm.bitset.test`` intrinsic tests whether the given pointer is a
  8346. member of the given bitset.
  8347. '``llvm.donothing``' Intrinsic
  8348. ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  8349. Syntax:
  8350. """""""
  8351. ::
  8352. declare void @llvm.donothing() nounwind readnone
  8353. Overview:
  8354. """""""""
  8355. The ``llvm.donothing`` intrinsic doesn't perform any operation. It's one of only
  8356. two intrinsics (besides ``llvm.experimental.patchpoint``) that can be called
  8357. with an invoke instruction.
  8358. Arguments:
  8359. """"""""""
  8360. None.
  8361. Semantics:
  8362. """"""""""
  8363. This intrinsic does nothing, and it's removed by optimizers and ignored
  8364. by codegen.
  8365. Stack Map Intrinsics
  8366. --------------------
  8367. LLVM provides experimental intrinsics to support runtime patching
  8368. mechanisms commonly desired in dynamic language JITs. These intrinsics
  8369. are described in :doc:`StackMaps`.