Core.h 131 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712271327142715271627172718271927202721272227232724272527262727272827292730273127322733273427352736273727382739274027412742274327442745274627472748274927502751275227532754275527562757275827592760276127622763276427652766276727682769277027712772277327742775277627772778277927802781278227832784278527862787278827892790279127922793279427952796279727982799280028012802280328042805280628072808280928102811281228132814281528162817281828192820282128222823282428252826282728282829283028312832283328342835283628372838283928402841284228432844284528462847284828492850285128522853285428552856285728582859286028612862286328642865286628672868286928702871287228732874287528762877287828792880288128822883288428852886288728882889289028912892289328942895289628972898289929002901290229032904290529062907290829092910291129122913291429152916291729182919292029212922292329242925292629272928292929302931293229332934293529362937293829392940294129422943294429452946294729482949295029512952295329542955295629572958295929602961296229632964296529662967296829692970297129722973297429752976297729782979298029812982298329842985298629872988298929902991299229932994299529962997299829993000300130023003300430053006300730083009301030113012301330143015301630173018301930203021302230233024302530263027302830293030303130323033303430353036303730383039304030413042304330443045304630473048304930503051305230533054305530563057305830593060306130623063306430653066306730683069307030713072307330743075307630773078307930803081308230833084308530863087308830893090309130923093309430953096309730983099310031013102310331043105310631073108310931103111311231133114311531163117311831193120312131223123312431253126312731283129313031313132313331343135313631373138313931403141314231433144314531463147314831493150315131523153315431553156315731583159316031613162316331643165316631673168316931703171317231733174317531763177317831793180318131823183318431853186318731883189319031913192319331943195319631973198319932003201320232033204320532063207320832093210321132123213321432153216321732183219322032213222322332243225322632273228322932303231323232333234323532363237323832393240324132423243324432453246324732483249325032513252325332543255325632573258325932603261326232633264326532663267326832693270327132723273327432753276327732783279328032813282328332843285328632873288328932903291329232933294329532963297329832993300330133023303330433053306330733083309331033113312331333143315331633173318331933203321332233233324332533263327332833293330333133323333333433353336333733383339334033413342334333443345334633473348334933503351335233533354335533563357335833593360336133623363336433653366336733683369337033713372337333743375337633773378337933803381338233833384338533863387338833893390339133923393339433953396339733983399340034013402340334043405340634073408340934103411341234133414341534163417341834193420342134223423342434253426342734283429343034313432343334343435343634373438343934403441344234433444344534463447344834493450345134523453345434553456345734583459346034613462346334643465346634673468346934703471347234733474347534763477347834793480348134823483348434853486348734883489349034913492349334943495349634973498349935003501350235033504350535063507350835093510351135123513351435153516351735183519352035213522352335243525352635273528352935303531353235333534353535363537353835393540354135423543354435453546354735483549355035513552355335543555355635573558355935603561356235633564356535663567356835693570357135723573357435753576357735783579358035813582358335843585358635873588358935903591359235933594359535963597359835993600360136023603360436053606360736083609361036113612361336143615361636173618361936203621362236233624362536263627362836293630363136323633363436353636363736383639364036413642364336443645364636473648364936503651365236533654365536563657365836593660366136623663366436653666366736683669367036713672367336743675367636773678367936803681368236833684368536863687368836893690369136923693369436953696369736983699370037013702370337043705370637073708370937103711371237133714371537163717371837193720372137223723372437253726372737283729373037313732373337343735373637373738373937403741374237433744374537463747374837493750375137523753375437553756375737583759376037613762376337643765376637673768376937703771377237733774377537763777377837793780378137823783378437853786378737883789379037913792379337943795379637973798379938003801380238033804380538063807380838093810381138123813381438153816381738183819382038213822382338243825382638273828382938303831383238333834383538363837383838393840384138423843384438453846384738483849385038513852385338543855385638573858385938603861386238633864386538663867386838693870387138723873387438753876387738783879388038813882388338843885388638873888388938903891389238933894389538963897389838993900390139023903390439053906390739083909391039113912391339143915391639173918391939203921392239233924392539263927392839293930393139323933393439353936393739383939394039413942394339443945394639473948394939503951395239533954395539563957395839593960396139623963396439653966396739683969397039713972397339743975397639773978397939803981398239833984398539863987398839893990399139923993399439953996399739983999400040014002400340044005400640074008400940104011401240134014401540164017401840194020402140224023402440254026402740284029403040314032403340344035403640374038403940404041404240434044404540464047404840494050405140524053405440554056405740584059406040614062406340644065406640674068406940704071407240734074407540764077407840794080408140824083408440854086408740884089409040914092409340944095409640974098409941004101410241034104410541064107410841094110411141124113411441154116411741184119412041214122412341244125412641274128412941304131413241334134413541364137413841394140414141424143414441454146414741484149415041514152415341544155415641574158415941604161416241634164416541664167416841694170417141724173417441754176417741784179418041814182418341844185418641874188418941904191419241934194419541964197419841994200420142024203420442054206420742084209421042114212421342144215421642174218421942204221422242234224422542264227422842294230423142324233423442354236423742384239424042414242424342444245424642474248
  1. #pragma once
  2. #ifdef __GNUC__
  3. #pragma GCC diagnostic push
  4. #pragma GCC diagnostic ignored "-Wunused-parameter"
  5. #endif
  6. /*===-- llvm-c/Core.h - Core Library C Interface ------------------*- C -*-===*\
  7. |* *|
  8. |* Part of the LLVM Project, under the Apache License v2.0 with LLVM *|
  9. |* Exceptions. *|
  10. |* See https://llvm.org/LICENSE.txt for license information. *|
  11. |* SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception *|
  12. |* *|
  13. |*===----------------------------------------------------------------------===*|
  14. |* *|
  15. |* This header declares the C interface to libLLVMCore.a, which implements *|
  16. |* the LLVM intermediate representation. *|
  17. |* *|
  18. \*===----------------------------------------------------------------------===*/
  19. #ifndef LLVM_C_CORE_H
  20. #define LLVM_C_CORE_H
  21. #include "llvm-c/Deprecated.h"
  22. #include "llvm-c/ErrorHandling.h"
  23. #include "llvm-c/ExternC.h"
  24. #include "llvm-c/Types.h"
  25. LLVM_C_EXTERN_C_BEGIN
  26. /**
  27. * @defgroup LLVMC LLVM-C: C interface to LLVM
  28. *
  29. * This module exposes parts of the LLVM library as a C API.
  30. *
  31. * @{
  32. */
  33. /**
  34. * @defgroup LLVMCTransforms Transforms
  35. */
  36. /**
  37. * @defgroup LLVMCCore Core
  38. *
  39. * This modules provide an interface to libLLVMCore, which implements
  40. * the LLVM intermediate representation as well as other related types
  41. * and utilities.
  42. *
  43. * Many exotic languages can interoperate with C code but have a harder time
  44. * with C++ due to name mangling. So in addition to C, this interface enables
  45. * tools written in such languages.
  46. *
  47. * @{
  48. */
  49. /**
  50. * @defgroup LLVMCCoreTypes Types and Enumerations
  51. *
  52. * @{
  53. */
  54. /// External users depend on the following values being stable. It is not safe
  55. /// to reorder them.
  56. typedef enum {
  57. /* Terminator Instructions */
  58. LLVMRet = 1,
  59. LLVMBr = 2,
  60. LLVMSwitch = 3,
  61. LLVMIndirectBr = 4,
  62. LLVMInvoke = 5,
  63. /* removed 6 due to API changes */
  64. LLVMUnreachable = 7,
  65. LLVMCallBr = 67,
  66. /* Standard Unary Operators */
  67. LLVMFNeg = 66,
  68. /* Standard Binary Operators */
  69. LLVMAdd = 8,
  70. LLVMFAdd = 9,
  71. LLVMSub = 10,
  72. LLVMFSub = 11,
  73. LLVMMul = 12,
  74. LLVMFMul = 13,
  75. LLVMUDiv = 14,
  76. LLVMSDiv = 15,
  77. LLVMFDiv = 16,
  78. LLVMURem = 17,
  79. LLVMSRem = 18,
  80. LLVMFRem = 19,
  81. /* Logical Operators */
  82. LLVMShl = 20,
  83. LLVMLShr = 21,
  84. LLVMAShr = 22,
  85. LLVMAnd = 23,
  86. LLVMOr = 24,
  87. LLVMXor = 25,
  88. /* Memory Operators */
  89. LLVMAlloca = 26,
  90. LLVMLoad = 27,
  91. LLVMStore = 28,
  92. LLVMGetElementPtr = 29,
  93. /* Cast Operators */
  94. LLVMTrunc = 30,
  95. LLVMZExt = 31,
  96. LLVMSExt = 32,
  97. LLVMFPToUI = 33,
  98. LLVMFPToSI = 34,
  99. LLVMUIToFP = 35,
  100. LLVMSIToFP = 36,
  101. LLVMFPTrunc = 37,
  102. LLVMFPExt = 38,
  103. LLVMPtrToInt = 39,
  104. LLVMIntToPtr = 40,
  105. LLVMBitCast = 41,
  106. LLVMAddrSpaceCast = 60,
  107. /* Other Operators */
  108. LLVMICmp = 42,
  109. LLVMFCmp = 43,
  110. LLVMPHI = 44,
  111. LLVMCall = 45,
  112. LLVMSelect = 46,
  113. LLVMUserOp1 = 47,
  114. LLVMUserOp2 = 48,
  115. LLVMVAArg = 49,
  116. LLVMExtractElement = 50,
  117. LLVMInsertElement = 51,
  118. LLVMShuffleVector = 52,
  119. LLVMExtractValue = 53,
  120. LLVMInsertValue = 54,
  121. LLVMFreeze = 68,
  122. /* Atomic operators */
  123. LLVMFence = 55,
  124. LLVMAtomicCmpXchg = 56,
  125. LLVMAtomicRMW = 57,
  126. /* Exception Handling Operators */
  127. LLVMResume = 58,
  128. LLVMLandingPad = 59,
  129. LLVMCleanupRet = 61,
  130. LLVMCatchRet = 62,
  131. LLVMCatchPad = 63,
  132. LLVMCleanupPad = 64,
  133. LLVMCatchSwitch = 65
  134. } LLVMOpcode;
  135. typedef enum {
  136. LLVMVoidTypeKind, /**< type with no size */
  137. LLVMHalfTypeKind, /**< 16 bit floating point type */
  138. LLVMFloatTypeKind, /**< 32 bit floating point type */
  139. LLVMDoubleTypeKind, /**< 64 bit floating point type */
  140. LLVMX86_FP80TypeKind, /**< 80 bit floating point type (X87) */
  141. LLVMFP128TypeKind, /**< 128 bit floating point type (112-bit mantissa)*/
  142. LLVMPPC_FP128TypeKind, /**< 128 bit floating point type (two 64-bits) */
  143. LLVMLabelTypeKind, /**< Labels */
  144. LLVMIntegerTypeKind, /**< Arbitrary bit width integers */
  145. LLVMFunctionTypeKind, /**< Functions */
  146. LLVMStructTypeKind, /**< Structures */
  147. LLVMArrayTypeKind, /**< Arrays */
  148. LLVMPointerTypeKind, /**< Pointers */
  149. LLVMVectorTypeKind, /**< Fixed width SIMD vector type */
  150. LLVMMetadataTypeKind, /**< Metadata */
  151. LLVMX86_MMXTypeKind, /**< X86 MMX */
  152. LLVMTokenTypeKind, /**< Tokens */
  153. LLVMScalableVectorTypeKind, /**< Scalable SIMD vector type */
  154. LLVMBFloatTypeKind, /**< 16 bit brain floating point type */
  155. LLVMX86_AMXTypeKind, /**< X86 AMX */
  156. LLVMTargetExtTypeKind, /**< Target extension type */
  157. } LLVMTypeKind;
  158. typedef enum {
  159. LLVMExternalLinkage, /**< Externally visible function */
  160. LLVMAvailableExternallyLinkage,
  161. LLVMLinkOnceAnyLinkage, /**< Keep one copy of function when linking (inline)*/
  162. LLVMLinkOnceODRLinkage, /**< Same, but only replaced by something
  163. equivalent. */
  164. LLVMLinkOnceODRAutoHideLinkage, /**< Obsolete */
  165. LLVMWeakAnyLinkage, /**< Keep one copy of function when linking (weak) */
  166. LLVMWeakODRLinkage, /**< Same, but only replaced by something
  167. equivalent. */
  168. LLVMAppendingLinkage, /**< Special purpose, only applies to global arrays */
  169. LLVMInternalLinkage, /**< Rename collisions when linking (static
  170. functions) */
  171. LLVMPrivateLinkage, /**< Like Internal, but omit from symbol table */
  172. LLVMDLLImportLinkage, /**< Obsolete */
  173. LLVMDLLExportLinkage, /**< Obsolete */
  174. LLVMExternalWeakLinkage,/**< ExternalWeak linkage description */
  175. LLVMGhostLinkage, /**< Obsolete */
  176. LLVMCommonLinkage, /**< Tentative definitions */
  177. LLVMLinkerPrivateLinkage, /**< Like Private, but linker removes. */
  178. LLVMLinkerPrivateWeakLinkage /**< Like LinkerPrivate, but is weak. */
  179. } LLVMLinkage;
  180. typedef enum {
  181. LLVMDefaultVisibility, /**< The GV is visible */
  182. LLVMHiddenVisibility, /**< The GV is hidden */
  183. LLVMProtectedVisibility /**< The GV is protected */
  184. } LLVMVisibility;
  185. typedef enum {
  186. LLVMNoUnnamedAddr, /**< Address of the GV is significant. */
  187. LLVMLocalUnnamedAddr, /**< Address of the GV is locally insignificant. */
  188. LLVMGlobalUnnamedAddr /**< Address of the GV is globally insignificant. */
  189. } LLVMUnnamedAddr;
  190. typedef enum {
  191. LLVMDefaultStorageClass = 0,
  192. LLVMDLLImportStorageClass = 1, /**< Function to be imported from DLL. */
  193. LLVMDLLExportStorageClass = 2 /**< Function to be accessible from DLL. */
  194. } LLVMDLLStorageClass;
  195. typedef enum {
  196. LLVMCCallConv = 0,
  197. LLVMFastCallConv = 8,
  198. LLVMColdCallConv = 9,
  199. LLVMGHCCallConv = 10,
  200. LLVMHiPECallConv = 11,
  201. LLVMWebKitJSCallConv = 12,
  202. LLVMAnyRegCallConv = 13,
  203. LLVMPreserveMostCallConv = 14,
  204. LLVMPreserveAllCallConv = 15,
  205. LLVMSwiftCallConv = 16,
  206. LLVMCXXFASTTLSCallConv = 17,
  207. LLVMX86StdcallCallConv = 64,
  208. LLVMX86FastcallCallConv = 65,
  209. LLVMARMAPCSCallConv = 66,
  210. LLVMARMAAPCSCallConv = 67,
  211. LLVMARMAAPCSVFPCallConv = 68,
  212. LLVMMSP430INTRCallConv = 69,
  213. LLVMX86ThisCallCallConv = 70,
  214. LLVMPTXKernelCallConv = 71,
  215. LLVMPTXDeviceCallConv = 72,
  216. LLVMSPIRFUNCCallConv = 75,
  217. LLVMSPIRKERNELCallConv = 76,
  218. LLVMIntelOCLBICallConv = 77,
  219. LLVMX8664SysVCallConv = 78,
  220. LLVMWin64CallConv = 79,
  221. LLVMX86VectorCallCallConv = 80,
  222. LLVMHHVMCallConv = 81,
  223. LLVMHHVMCCallConv = 82,
  224. LLVMX86INTRCallConv = 83,
  225. LLVMAVRINTRCallConv = 84,
  226. LLVMAVRSIGNALCallConv = 85,
  227. LLVMAVRBUILTINCallConv = 86,
  228. LLVMAMDGPUVSCallConv = 87,
  229. LLVMAMDGPUGSCallConv = 88,
  230. LLVMAMDGPUPSCallConv = 89,
  231. LLVMAMDGPUCSCallConv = 90,
  232. LLVMAMDGPUKERNELCallConv = 91,
  233. LLVMX86RegCallCallConv = 92,
  234. LLVMAMDGPUHSCallConv = 93,
  235. LLVMMSP430BUILTINCallConv = 94,
  236. LLVMAMDGPULSCallConv = 95,
  237. LLVMAMDGPUESCallConv = 96
  238. } LLVMCallConv;
  239. typedef enum {
  240. LLVMArgumentValueKind,
  241. LLVMBasicBlockValueKind,
  242. LLVMMemoryUseValueKind,
  243. LLVMMemoryDefValueKind,
  244. LLVMMemoryPhiValueKind,
  245. LLVMFunctionValueKind,
  246. LLVMGlobalAliasValueKind,
  247. LLVMGlobalIFuncValueKind,
  248. LLVMGlobalVariableValueKind,
  249. LLVMBlockAddressValueKind,
  250. LLVMConstantExprValueKind,
  251. LLVMConstantArrayValueKind,
  252. LLVMConstantStructValueKind,
  253. LLVMConstantVectorValueKind,
  254. LLVMUndefValueValueKind,
  255. LLVMConstantAggregateZeroValueKind,
  256. LLVMConstantDataArrayValueKind,
  257. LLVMConstantDataVectorValueKind,
  258. LLVMConstantIntValueKind,
  259. LLVMConstantFPValueKind,
  260. LLVMConstantPointerNullValueKind,
  261. LLVMConstantTokenNoneValueKind,
  262. LLVMMetadataAsValueValueKind,
  263. LLVMInlineAsmValueKind,
  264. LLVMInstructionValueKind,
  265. LLVMPoisonValueValueKind,
  266. LLVMConstantTargetNoneValueKind,
  267. } LLVMValueKind;
  268. typedef enum {
  269. LLVMIntEQ = 32, /**< equal */
  270. LLVMIntNE, /**< not equal */
  271. LLVMIntUGT, /**< unsigned greater than */
  272. LLVMIntUGE, /**< unsigned greater or equal */
  273. LLVMIntULT, /**< unsigned less than */
  274. LLVMIntULE, /**< unsigned less or equal */
  275. LLVMIntSGT, /**< signed greater than */
  276. LLVMIntSGE, /**< signed greater or equal */
  277. LLVMIntSLT, /**< signed less than */
  278. LLVMIntSLE /**< signed less or equal */
  279. } LLVMIntPredicate;
  280. typedef enum {
  281. LLVMRealPredicateFalse, /**< Always false (always folded) */
  282. LLVMRealOEQ, /**< True if ordered and equal */
  283. LLVMRealOGT, /**< True if ordered and greater than */
  284. LLVMRealOGE, /**< True if ordered and greater than or equal */
  285. LLVMRealOLT, /**< True if ordered and less than */
  286. LLVMRealOLE, /**< True if ordered and less than or equal */
  287. LLVMRealONE, /**< True if ordered and operands are unequal */
  288. LLVMRealORD, /**< True if ordered (no nans) */
  289. LLVMRealUNO, /**< True if unordered: isnan(X) | isnan(Y) */
  290. LLVMRealUEQ, /**< True if unordered or equal */
  291. LLVMRealUGT, /**< True if unordered or greater than */
  292. LLVMRealUGE, /**< True if unordered, greater than, or equal */
  293. LLVMRealULT, /**< True if unordered or less than */
  294. LLVMRealULE, /**< True if unordered, less than, or equal */
  295. LLVMRealUNE, /**< True if unordered or not equal */
  296. LLVMRealPredicateTrue /**< Always true (always folded) */
  297. } LLVMRealPredicate;
  298. typedef enum {
  299. LLVMLandingPadCatch, /**< A catch clause */
  300. LLVMLandingPadFilter /**< A filter clause */
  301. } LLVMLandingPadClauseTy;
  302. typedef enum {
  303. LLVMNotThreadLocal = 0,
  304. LLVMGeneralDynamicTLSModel,
  305. LLVMLocalDynamicTLSModel,
  306. LLVMInitialExecTLSModel,
  307. LLVMLocalExecTLSModel
  308. } LLVMThreadLocalMode;
  309. typedef enum {
  310. LLVMAtomicOrderingNotAtomic = 0, /**< A load or store which is not atomic */
  311. LLVMAtomicOrderingUnordered = 1, /**< Lowest level of atomicity, guarantees
  312. somewhat sane results, lock free. */
  313. LLVMAtomicOrderingMonotonic = 2, /**< guarantees that if you take all the
  314. operations affecting a specific address,
  315. a consistent ordering exists */
  316. LLVMAtomicOrderingAcquire = 4, /**< Acquire provides a barrier of the sort
  317. necessary to acquire a lock to access other
  318. memory with normal loads and stores. */
  319. LLVMAtomicOrderingRelease = 5, /**< Release is similar to Acquire, but with
  320. a barrier of the sort necessary to release
  321. a lock. */
  322. LLVMAtomicOrderingAcquireRelease = 6, /**< provides both an Acquire and a
  323. Release barrier (for fences and
  324. operations which both read and write
  325. memory). */
  326. LLVMAtomicOrderingSequentiallyConsistent = 7 /**< provides Acquire semantics
  327. for loads and Release
  328. semantics for stores.
  329. Additionally, it guarantees
  330. that a total ordering exists
  331. between all
  332. SequentiallyConsistent
  333. operations. */
  334. } LLVMAtomicOrdering;
  335. typedef enum {
  336. LLVMAtomicRMWBinOpXchg, /**< Set the new value and return the one old */
  337. LLVMAtomicRMWBinOpAdd, /**< Add a value and return the old one */
  338. LLVMAtomicRMWBinOpSub, /**< Subtract a value and return the old one */
  339. LLVMAtomicRMWBinOpAnd, /**< And a value and return the old one */
  340. LLVMAtomicRMWBinOpNand, /**< Not-And a value and return the old one */
  341. LLVMAtomicRMWBinOpOr, /**< OR a value and return the old one */
  342. LLVMAtomicRMWBinOpXor, /**< Xor a value and return the old one */
  343. LLVMAtomicRMWBinOpMax, /**< Sets the value if it's greater than the
  344. original using a signed comparison and return
  345. the old one */
  346. LLVMAtomicRMWBinOpMin, /**< Sets the value if it's Smaller than the
  347. original using a signed comparison and return
  348. the old one */
  349. LLVMAtomicRMWBinOpUMax, /**< Sets the value if it's greater than the
  350. original using an unsigned comparison and return
  351. the old one */
  352. LLVMAtomicRMWBinOpUMin, /**< Sets the value if it's greater than the
  353. original using an unsigned comparison and return
  354. the old one */
  355. LLVMAtomicRMWBinOpFAdd, /**< Add a floating point value and return the
  356. old one */
  357. LLVMAtomicRMWBinOpFSub, /**< Subtract a floating point value and return the
  358. old one */
  359. LLVMAtomicRMWBinOpFMax, /**< Sets the value if it's greater than the
  360. original using an floating point comparison and
  361. return the old one */
  362. LLVMAtomicRMWBinOpFMin, /**< Sets the value if it's smaller than the
  363. original using an floating point comparison and
  364. return the old one */
  365. } LLVMAtomicRMWBinOp;
  366. typedef enum {
  367. LLVMDSError,
  368. LLVMDSWarning,
  369. LLVMDSRemark,
  370. LLVMDSNote
  371. } LLVMDiagnosticSeverity;
  372. typedef enum {
  373. LLVMInlineAsmDialectATT,
  374. LLVMInlineAsmDialectIntel
  375. } LLVMInlineAsmDialect;
  376. typedef enum {
  377. /**
  378. * Emits an error if two values disagree, otherwise the resulting value is
  379. * that of the operands.
  380. *
  381. * @see Module::ModFlagBehavior::Error
  382. */
  383. LLVMModuleFlagBehaviorError,
  384. /**
  385. * Emits a warning if two values disagree. The result value will be the
  386. * operand for the flag from the first module being linked.
  387. *
  388. * @see Module::ModFlagBehavior::Warning
  389. */
  390. LLVMModuleFlagBehaviorWarning,
  391. /**
  392. * Adds a requirement that another module flag be present and have a
  393. * specified value after linking is performed. The value must be a metadata
  394. * pair, where the first element of the pair is the ID of the module flag
  395. * to be restricted, and the second element of the pair is the value the
  396. * module flag should be restricted to. This behavior can be used to
  397. * restrict the allowable results (via triggering of an error) of linking
  398. * IDs with the **Override** behavior.
  399. *
  400. * @see Module::ModFlagBehavior::Require
  401. */
  402. LLVMModuleFlagBehaviorRequire,
  403. /**
  404. * Uses the specified value, regardless of the behavior or value of the
  405. * other module. If both modules specify **Override**, but the values
  406. * differ, an error will be emitted.
  407. *
  408. * @see Module::ModFlagBehavior::Override
  409. */
  410. LLVMModuleFlagBehaviorOverride,
  411. /**
  412. * Appends the two values, which are required to be metadata nodes.
  413. *
  414. * @see Module::ModFlagBehavior::Append
  415. */
  416. LLVMModuleFlagBehaviorAppend,
  417. /**
  418. * Appends the two values, which are required to be metadata
  419. * nodes. However, duplicate entries in the second list are dropped
  420. * during the append operation.
  421. *
  422. * @see Module::ModFlagBehavior::AppendUnique
  423. */
  424. LLVMModuleFlagBehaviorAppendUnique,
  425. } LLVMModuleFlagBehavior;
  426. /**
  427. * Attribute index are either LLVMAttributeReturnIndex,
  428. * LLVMAttributeFunctionIndex or a parameter number from 1 to N.
  429. */
  430. enum {
  431. LLVMAttributeReturnIndex = 0U,
  432. // ISO C restricts enumerator values to range of 'int'
  433. // (4294967295 is too large)
  434. // LLVMAttributeFunctionIndex = ~0U,
  435. LLVMAttributeFunctionIndex = -1,
  436. };
  437. typedef unsigned LLVMAttributeIndex;
  438. /**
  439. * @}
  440. */
  441. void LLVMInitializeCore(LLVMPassRegistryRef R);
  442. /** Deallocate and destroy all ManagedStatic variables.
  443. @see llvm::llvm_shutdown
  444. @see ManagedStatic */
  445. void LLVMShutdown(void);
  446. /*===-- Version query -----------------------------------------------------===*/
  447. /**
  448. * Return the major, minor, and patch version of LLVM
  449. *
  450. * The version components are returned via the function's three output
  451. * parameters or skipped if a NULL pointer was supplied.
  452. */
  453. void LLVMGetVersion(unsigned *Major, unsigned *Minor, unsigned *Patch);
  454. /*===-- Error handling ----------------------------------------------------===*/
  455. char *LLVMCreateMessage(const char *Message);
  456. void LLVMDisposeMessage(char *Message);
  457. /**
  458. * @defgroup LLVMCCoreContext Contexts
  459. *
  460. * Contexts are execution states for the core LLVM IR system.
  461. *
  462. * Most types are tied to a context instance. Multiple contexts can
  463. * exist simultaneously. A single context is not thread safe. However,
  464. * different contexts can execute on different threads simultaneously.
  465. *
  466. * @{
  467. */
  468. typedef void (*LLVMDiagnosticHandler)(LLVMDiagnosticInfoRef, void *);
  469. typedef void (*LLVMYieldCallback)(LLVMContextRef, void *);
  470. /**
  471. * Create a new context.
  472. *
  473. * Every call to this function should be paired with a call to
  474. * LLVMContextDispose() or the context will leak memory.
  475. */
  476. LLVMContextRef LLVMContextCreate(void);
  477. /**
  478. * Obtain the global context instance.
  479. */
  480. LLVMContextRef LLVMGetGlobalContext(void);
  481. /**
  482. * Set the diagnostic handler for this context.
  483. */
  484. void LLVMContextSetDiagnosticHandler(LLVMContextRef C,
  485. LLVMDiagnosticHandler Handler,
  486. void *DiagnosticContext);
  487. /**
  488. * Get the diagnostic handler of this context.
  489. */
  490. LLVMDiagnosticHandler LLVMContextGetDiagnosticHandler(LLVMContextRef C);
  491. /**
  492. * Get the diagnostic context of this context.
  493. */
  494. void *LLVMContextGetDiagnosticContext(LLVMContextRef C);
  495. /**
  496. * Set the yield callback function for this context.
  497. *
  498. * @see LLVMContext::setYieldCallback()
  499. */
  500. void LLVMContextSetYieldCallback(LLVMContextRef C, LLVMYieldCallback Callback,
  501. void *OpaqueHandle);
  502. /**
  503. * Retrieve whether the given context is set to discard all value names.
  504. *
  505. * @see LLVMContext::shouldDiscardValueNames()
  506. */
  507. LLVMBool LLVMContextShouldDiscardValueNames(LLVMContextRef C);
  508. /**
  509. * Set whether the given context discards all value names.
  510. *
  511. * If true, only the names of GlobalValue objects will be available in the IR.
  512. * This can be used to save memory and runtime, especially in release mode.
  513. *
  514. * @see LLVMContext::setDiscardValueNames()
  515. */
  516. void LLVMContextSetDiscardValueNames(LLVMContextRef C, LLVMBool Discard);
  517. /**
  518. * Set whether the given context is in opaque pointer mode.
  519. *
  520. * @see LLVMContext::setOpaquePointers()
  521. */
  522. void LLVMContextSetOpaquePointers(LLVMContextRef C, LLVMBool OpaquePointers);
  523. /**
  524. * Destroy a context instance.
  525. *
  526. * This should be called for every call to LLVMContextCreate() or memory
  527. * will be leaked.
  528. */
  529. void LLVMContextDispose(LLVMContextRef C);
  530. /**
  531. * Return a string representation of the DiagnosticInfo. Use
  532. * LLVMDisposeMessage to free the string.
  533. *
  534. * @see DiagnosticInfo::print()
  535. */
  536. char *LLVMGetDiagInfoDescription(LLVMDiagnosticInfoRef DI);
  537. /**
  538. * Return an enum LLVMDiagnosticSeverity.
  539. *
  540. * @see DiagnosticInfo::getSeverity()
  541. */
  542. LLVMDiagnosticSeverity LLVMGetDiagInfoSeverity(LLVMDiagnosticInfoRef DI);
  543. unsigned LLVMGetMDKindIDInContext(LLVMContextRef C, const char *Name,
  544. unsigned SLen);
  545. unsigned LLVMGetMDKindID(const char *Name, unsigned SLen);
  546. /**
  547. * Return an unique id given the name of a enum attribute,
  548. * or 0 if no attribute by that name exists.
  549. *
  550. * See http://llvm.org/docs/LangRef.html#parameter-attributes
  551. * and http://llvm.org/docs/LangRef.html#function-attributes
  552. * for the list of available attributes.
  553. *
  554. * NB: Attribute names and/or id are subject to change without
  555. * going through the C API deprecation cycle.
  556. */
  557. unsigned LLVMGetEnumAttributeKindForName(const char *Name, size_t SLen);
  558. unsigned LLVMGetLastEnumAttributeKind(void);
  559. /**
  560. * Create an enum attribute.
  561. */
  562. LLVMAttributeRef LLVMCreateEnumAttribute(LLVMContextRef C, unsigned KindID,
  563. uint64_t Val);
  564. /**
  565. * Get the unique id corresponding to the enum attribute
  566. * passed as argument.
  567. */
  568. unsigned LLVMGetEnumAttributeKind(LLVMAttributeRef A);
  569. /**
  570. * Get the enum attribute's value. 0 is returned if none exists.
  571. */
  572. uint64_t LLVMGetEnumAttributeValue(LLVMAttributeRef A);
  573. /**
  574. * Create a type attribute
  575. */
  576. LLVMAttributeRef LLVMCreateTypeAttribute(LLVMContextRef C, unsigned KindID,
  577. LLVMTypeRef type_ref);
  578. /**
  579. * Get the type attribute's value.
  580. */
  581. LLVMTypeRef LLVMGetTypeAttributeValue(LLVMAttributeRef A);
  582. /**
  583. * Create a string attribute.
  584. */
  585. LLVMAttributeRef LLVMCreateStringAttribute(LLVMContextRef C,
  586. const char *K, unsigned KLength,
  587. const char *V, unsigned VLength);
  588. /**
  589. * Get the string attribute's kind.
  590. */
  591. const char *LLVMGetStringAttributeKind(LLVMAttributeRef A, unsigned *Length);
  592. /**
  593. * Get the string attribute's value.
  594. */
  595. const char *LLVMGetStringAttributeValue(LLVMAttributeRef A, unsigned *Length);
  596. /**
  597. * Check for the different types of attributes.
  598. */
  599. LLVMBool LLVMIsEnumAttribute(LLVMAttributeRef A);
  600. LLVMBool LLVMIsStringAttribute(LLVMAttributeRef A);
  601. LLVMBool LLVMIsTypeAttribute(LLVMAttributeRef A);
  602. /**
  603. * Obtain a Type from a context by its registered name.
  604. */
  605. LLVMTypeRef LLVMGetTypeByName2(LLVMContextRef C, const char *Name);
  606. /**
  607. * @}
  608. */
  609. /**
  610. * @defgroup LLVMCCoreModule Modules
  611. *
  612. * Modules represent the top-level structure in an LLVM program. An LLVM
  613. * module is effectively a translation unit or a collection of
  614. * translation units merged together.
  615. *
  616. * @{
  617. */
  618. /**
  619. * Create a new, empty module in the global context.
  620. *
  621. * This is equivalent to calling LLVMModuleCreateWithNameInContext with
  622. * LLVMGetGlobalContext() as the context parameter.
  623. *
  624. * Every invocation should be paired with LLVMDisposeModule() or memory
  625. * will be leaked.
  626. */
  627. LLVMModuleRef LLVMModuleCreateWithName(const char *ModuleID);
  628. /**
  629. * Create a new, empty module in a specific context.
  630. *
  631. * Every invocation should be paired with LLVMDisposeModule() or memory
  632. * will be leaked.
  633. */
  634. LLVMModuleRef LLVMModuleCreateWithNameInContext(const char *ModuleID,
  635. LLVMContextRef C);
  636. /**
  637. * Return an exact copy of the specified module.
  638. */
  639. LLVMModuleRef LLVMCloneModule(LLVMModuleRef M);
  640. /**
  641. * Destroy a module instance.
  642. *
  643. * This must be called for every created module or memory will be
  644. * leaked.
  645. */
  646. void LLVMDisposeModule(LLVMModuleRef M);
  647. /**
  648. * Obtain the identifier of a module.
  649. *
  650. * @param M Module to obtain identifier of
  651. * @param Len Out parameter which holds the length of the returned string.
  652. * @return The identifier of M.
  653. * @see Module::getModuleIdentifier()
  654. */
  655. const char *LLVMGetModuleIdentifier(LLVMModuleRef M, size_t *Len);
  656. /**
  657. * Set the identifier of a module to a string Ident with length Len.
  658. *
  659. * @param M The module to set identifier
  660. * @param Ident The string to set M's identifier to
  661. * @param Len Length of Ident
  662. * @see Module::setModuleIdentifier()
  663. */
  664. void LLVMSetModuleIdentifier(LLVMModuleRef M, const char *Ident, size_t Len);
  665. /**
  666. * Obtain the module's original source file name.
  667. *
  668. * @param M Module to obtain the name of
  669. * @param Len Out parameter which holds the length of the returned string
  670. * @return The original source file name of M
  671. * @see Module::getSourceFileName()
  672. */
  673. const char *LLVMGetSourceFileName(LLVMModuleRef M, size_t *Len);
  674. /**
  675. * Set the original source file name of a module to a string Name with length
  676. * Len.
  677. *
  678. * @param M The module to set the source file name of
  679. * @param Name The string to set M's source file name to
  680. * @param Len Length of Name
  681. * @see Module::setSourceFileName()
  682. */
  683. void LLVMSetSourceFileName(LLVMModuleRef M, const char *Name, size_t Len);
  684. /**
  685. * Obtain the data layout for a module.
  686. *
  687. * @see Module::getDataLayoutStr()
  688. *
  689. * LLVMGetDataLayout is DEPRECATED, as the name is not only incorrect,
  690. * but match the name of another method on the module. Prefer the use
  691. * of LLVMGetDataLayoutStr, which is not ambiguous.
  692. */
  693. const char *LLVMGetDataLayoutStr(LLVMModuleRef M);
  694. const char *LLVMGetDataLayout(LLVMModuleRef M);
  695. /**
  696. * Set the data layout for a module.
  697. *
  698. * @see Module::setDataLayout()
  699. */
  700. void LLVMSetDataLayout(LLVMModuleRef M, const char *DataLayoutStr);
  701. /**
  702. * Obtain the target triple for a module.
  703. *
  704. * @see Module::getTargetTriple()
  705. */
  706. const char *LLVMGetTarget(LLVMModuleRef M);
  707. /**
  708. * Set the target triple for a module.
  709. *
  710. * @see Module::setTargetTriple()
  711. */
  712. void LLVMSetTarget(LLVMModuleRef M, const char *Triple);
  713. /**
  714. * Returns the module flags as an array of flag-key-value triples. The caller
  715. * is responsible for freeing this array by calling
  716. * \c LLVMDisposeModuleFlagsMetadata.
  717. *
  718. * @see Module::getModuleFlagsMetadata()
  719. */
  720. LLVMModuleFlagEntry *LLVMCopyModuleFlagsMetadata(LLVMModuleRef M, size_t *Len);
  721. /**
  722. * Destroys module flags metadata entries.
  723. */
  724. void LLVMDisposeModuleFlagsMetadata(LLVMModuleFlagEntry *Entries);
  725. /**
  726. * Returns the flag behavior for a module flag entry at a specific index.
  727. *
  728. * @see Module::ModuleFlagEntry::Behavior
  729. */
  730. LLVMModuleFlagBehavior
  731. LLVMModuleFlagEntriesGetFlagBehavior(LLVMModuleFlagEntry *Entries,
  732. unsigned Index);
  733. /**
  734. * Returns the key for a module flag entry at a specific index.
  735. *
  736. * @see Module::ModuleFlagEntry::Key
  737. */
  738. const char *LLVMModuleFlagEntriesGetKey(LLVMModuleFlagEntry *Entries,
  739. unsigned Index, size_t *Len);
  740. /**
  741. * Returns the metadata for a module flag entry at a specific index.
  742. *
  743. * @see Module::ModuleFlagEntry::Val
  744. */
  745. LLVMMetadataRef LLVMModuleFlagEntriesGetMetadata(LLVMModuleFlagEntry *Entries,
  746. unsigned Index);
  747. /**
  748. * Add a module-level flag to the module-level flags metadata if it doesn't
  749. * already exist.
  750. *
  751. * @see Module::getModuleFlag()
  752. */
  753. LLVMMetadataRef LLVMGetModuleFlag(LLVMModuleRef M,
  754. const char *Key, size_t KeyLen);
  755. /**
  756. * Add a module-level flag to the module-level flags metadata if it doesn't
  757. * already exist.
  758. *
  759. * @see Module::addModuleFlag()
  760. */
  761. void LLVMAddModuleFlag(LLVMModuleRef M, LLVMModuleFlagBehavior Behavior,
  762. const char *Key, size_t KeyLen,
  763. LLVMMetadataRef Val);
  764. /**
  765. * Dump a representation of a module to stderr.
  766. *
  767. * @see Module::dump()
  768. */
  769. void LLVMDumpModule(LLVMModuleRef M);
  770. /**
  771. * Print a representation of a module to a file. The ErrorMessage needs to be
  772. * disposed with LLVMDisposeMessage. Returns 0 on success, 1 otherwise.
  773. *
  774. * @see Module::print()
  775. */
  776. LLVMBool LLVMPrintModuleToFile(LLVMModuleRef M, const char *Filename,
  777. char **ErrorMessage);
  778. /**
  779. * Return a string representation of the module. Use
  780. * LLVMDisposeMessage to free the string.
  781. *
  782. * @see Module::print()
  783. */
  784. char *LLVMPrintModuleToString(LLVMModuleRef M);
  785. /**
  786. * Get inline assembly for a module.
  787. *
  788. * @see Module::getModuleInlineAsm()
  789. */
  790. const char *LLVMGetModuleInlineAsm(LLVMModuleRef M, size_t *Len);
  791. /**
  792. * Set inline assembly for a module.
  793. *
  794. * @see Module::setModuleInlineAsm()
  795. */
  796. void LLVMSetModuleInlineAsm2(LLVMModuleRef M, const char *Asm, size_t Len);
  797. /**
  798. * Append inline assembly to a module.
  799. *
  800. * @see Module::appendModuleInlineAsm()
  801. */
  802. void LLVMAppendModuleInlineAsm(LLVMModuleRef M, const char *Asm, size_t Len);
  803. /**
  804. * Create the specified uniqued inline asm string.
  805. *
  806. * @see InlineAsm::get()
  807. */
  808. LLVMValueRef LLVMGetInlineAsm(LLVMTypeRef Ty, char *AsmString,
  809. size_t AsmStringSize, char *Constraints,
  810. size_t ConstraintsSize, LLVMBool HasSideEffects,
  811. LLVMBool IsAlignStack,
  812. LLVMInlineAsmDialect Dialect, LLVMBool CanThrow);
  813. /**
  814. * Obtain the context to which this module is associated.
  815. *
  816. * @see Module::getContext()
  817. */
  818. LLVMContextRef LLVMGetModuleContext(LLVMModuleRef M);
  819. /** Deprecated: Use LLVMGetTypeByName2 instead. */
  820. LLVMTypeRef LLVMGetTypeByName(LLVMModuleRef M, const char *Name);
  821. /**
  822. * Obtain an iterator to the first NamedMDNode in a Module.
  823. *
  824. * @see llvm::Module::named_metadata_begin()
  825. */
  826. LLVMNamedMDNodeRef LLVMGetFirstNamedMetadata(LLVMModuleRef M);
  827. /**
  828. * Obtain an iterator to the last NamedMDNode in a Module.
  829. *
  830. * @see llvm::Module::named_metadata_end()
  831. */
  832. LLVMNamedMDNodeRef LLVMGetLastNamedMetadata(LLVMModuleRef M);
  833. /**
  834. * Advance a NamedMDNode iterator to the next NamedMDNode.
  835. *
  836. * Returns NULL if the iterator was already at the end and there are no more
  837. * named metadata nodes.
  838. */
  839. LLVMNamedMDNodeRef LLVMGetNextNamedMetadata(LLVMNamedMDNodeRef NamedMDNode);
  840. /**
  841. * Decrement a NamedMDNode iterator to the previous NamedMDNode.
  842. *
  843. * Returns NULL if the iterator was already at the beginning and there are
  844. * no previous named metadata nodes.
  845. */
  846. LLVMNamedMDNodeRef LLVMGetPreviousNamedMetadata(LLVMNamedMDNodeRef NamedMDNode);
  847. /**
  848. * Retrieve a NamedMDNode with the given name, returning NULL if no such
  849. * node exists.
  850. *
  851. * @see llvm::Module::getNamedMetadata()
  852. */
  853. LLVMNamedMDNodeRef LLVMGetNamedMetadata(LLVMModuleRef M,
  854. const char *Name, size_t NameLen);
  855. /**
  856. * Retrieve a NamedMDNode with the given name, creating a new node if no such
  857. * node exists.
  858. *
  859. * @see llvm::Module::getOrInsertNamedMetadata()
  860. */
  861. LLVMNamedMDNodeRef LLVMGetOrInsertNamedMetadata(LLVMModuleRef M,
  862. const char *Name,
  863. size_t NameLen);
  864. /**
  865. * Retrieve the name of a NamedMDNode.
  866. *
  867. * @see llvm::NamedMDNode::getName()
  868. */
  869. const char *LLVMGetNamedMetadataName(LLVMNamedMDNodeRef NamedMD,
  870. size_t *NameLen);
  871. /**
  872. * Obtain the number of operands for named metadata in a module.
  873. *
  874. * @see llvm::Module::getNamedMetadata()
  875. */
  876. unsigned LLVMGetNamedMetadataNumOperands(LLVMModuleRef M, const char *Name);
  877. /**
  878. * Obtain the named metadata operands for a module.
  879. *
  880. * The passed LLVMValueRef pointer should refer to an array of
  881. * LLVMValueRef at least LLVMGetNamedMetadataNumOperands long. This
  882. * array will be populated with the LLVMValueRef instances. Each
  883. * instance corresponds to a llvm::MDNode.
  884. *
  885. * @see llvm::Module::getNamedMetadata()
  886. * @see llvm::MDNode::getOperand()
  887. */
  888. void LLVMGetNamedMetadataOperands(LLVMModuleRef M, const char *Name,
  889. LLVMValueRef *Dest);
  890. /**
  891. * Add an operand to named metadata.
  892. *
  893. * @see llvm::Module::getNamedMetadata()
  894. * @see llvm::MDNode::addOperand()
  895. */
  896. void LLVMAddNamedMetadataOperand(LLVMModuleRef M, const char *Name,
  897. LLVMValueRef Val);
  898. /**
  899. * Return the directory of the debug location for this value, which must be
  900. * an llvm::Instruction, llvm::GlobalVariable, or llvm::Function.
  901. *
  902. * @see llvm::Instruction::getDebugLoc()
  903. * @see llvm::GlobalVariable::getDebugInfo()
  904. * @see llvm::Function::getSubprogram()
  905. */
  906. const char *LLVMGetDebugLocDirectory(LLVMValueRef Val, unsigned *Length);
  907. /**
  908. * Return the filename of the debug location for this value, which must be
  909. * an llvm::Instruction, llvm::GlobalVariable, or llvm::Function.
  910. *
  911. * @see llvm::Instruction::getDebugLoc()
  912. * @see llvm::GlobalVariable::getDebugInfo()
  913. * @see llvm::Function::getSubprogram()
  914. */
  915. const char *LLVMGetDebugLocFilename(LLVMValueRef Val, unsigned *Length);
  916. /**
  917. * Return the line number of the debug location for this value, which must be
  918. * an llvm::Instruction, llvm::GlobalVariable, or llvm::Function.
  919. *
  920. * @see llvm::Instruction::getDebugLoc()
  921. * @see llvm::GlobalVariable::getDebugInfo()
  922. * @see llvm::Function::getSubprogram()
  923. */
  924. unsigned LLVMGetDebugLocLine(LLVMValueRef Val);
  925. /**
  926. * Return the column number of the debug location for this value, which must be
  927. * an llvm::Instruction.
  928. *
  929. * @see llvm::Instruction::getDebugLoc()
  930. */
  931. unsigned LLVMGetDebugLocColumn(LLVMValueRef Val);
  932. /**
  933. * Add a function to a module under a specified name.
  934. *
  935. * @see llvm::Function::Create()
  936. */
  937. LLVMValueRef LLVMAddFunction(LLVMModuleRef M, const char *Name,
  938. LLVMTypeRef FunctionTy);
  939. /**
  940. * Obtain a Function value from a Module by its name.
  941. *
  942. * The returned value corresponds to a llvm::Function value.
  943. *
  944. * @see llvm::Module::getFunction()
  945. */
  946. LLVMValueRef LLVMGetNamedFunction(LLVMModuleRef M, const char *Name);
  947. /**
  948. * Obtain an iterator to the first Function in a Module.
  949. *
  950. * @see llvm::Module::begin()
  951. */
  952. LLVMValueRef LLVMGetFirstFunction(LLVMModuleRef M);
  953. /**
  954. * Obtain an iterator to the last Function in a Module.
  955. *
  956. * @see llvm::Module::end()
  957. */
  958. LLVMValueRef LLVMGetLastFunction(LLVMModuleRef M);
  959. /**
  960. * Advance a Function iterator to the next Function.
  961. *
  962. * Returns NULL if the iterator was already at the end and there are no more
  963. * functions.
  964. */
  965. LLVMValueRef LLVMGetNextFunction(LLVMValueRef Fn);
  966. /**
  967. * Decrement a Function iterator to the previous Function.
  968. *
  969. * Returns NULL if the iterator was already at the beginning and there are
  970. * no previous functions.
  971. */
  972. LLVMValueRef LLVMGetPreviousFunction(LLVMValueRef Fn);
  973. /** Deprecated: Use LLVMSetModuleInlineAsm2 instead. */
  974. void LLVMSetModuleInlineAsm(LLVMModuleRef M, const char *Asm);
  975. /**
  976. * @}
  977. */
  978. /**
  979. * @defgroup LLVMCCoreType Types
  980. *
  981. * Types represent the type of a value.
  982. *
  983. * Types are associated with a context instance. The context internally
  984. * deduplicates types so there is only 1 instance of a specific type
  985. * alive at a time. In other words, a unique type is shared among all
  986. * consumers within a context.
  987. *
  988. * A Type in the C API corresponds to llvm::Type.
  989. *
  990. * Types have the following hierarchy:
  991. *
  992. * types:
  993. * integer type
  994. * real type
  995. * function type
  996. * sequence types:
  997. * array type
  998. * pointer type
  999. * vector type
  1000. * void type
  1001. * label type
  1002. * opaque type
  1003. *
  1004. * @{
  1005. */
  1006. /**
  1007. * Obtain the enumerated type of a Type instance.
  1008. *
  1009. * @see llvm::Type:getTypeID()
  1010. */
  1011. LLVMTypeKind LLVMGetTypeKind(LLVMTypeRef Ty);
  1012. /**
  1013. * Whether the type has a known size.
  1014. *
  1015. * Things that don't have a size are abstract types, labels, and void.a
  1016. *
  1017. * @see llvm::Type::isSized()
  1018. */
  1019. LLVMBool LLVMTypeIsSized(LLVMTypeRef Ty);
  1020. /**
  1021. * Obtain the context to which this type instance is associated.
  1022. *
  1023. * @see llvm::Type::getContext()
  1024. */
  1025. LLVMContextRef LLVMGetTypeContext(LLVMTypeRef Ty);
  1026. /**
  1027. * Dump a representation of a type to stderr.
  1028. *
  1029. * @see llvm::Type::dump()
  1030. */
  1031. void LLVMDumpType(LLVMTypeRef Val);
  1032. /**
  1033. * Return a string representation of the type. Use
  1034. * LLVMDisposeMessage to free the string.
  1035. *
  1036. * @see llvm::Type::print()
  1037. */
  1038. char *LLVMPrintTypeToString(LLVMTypeRef Val);
  1039. /**
  1040. * @defgroup LLVMCCoreTypeInt Integer Types
  1041. *
  1042. * Functions in this section operate on integer types.
  1043. *
  1044. * @{
  1045. */
  1046. /**
  1047. * Obtain an integer type from a context with specified bit width.
  1048. */
  1049. LLVMTypeRef LLVMInt1TypeInContext(LLVMContextRef C);
  1050. LLVMTypeRef LLVMInt8TypeInContext(LLVMContextRef C);
  1051. LLVMTypeRef LLVMInt16TypeInContext(LLVMContextRef C);
  1052. LLVMTypeRef LLVMInt32TypeInContext(LLVMContextRef C);
  1053. LLVMTypeRef LLVMInt64TypeInContext(LLVMContextRef C);
  1054. LLVMTypeRef LLVMInt128TypeInContext(LLVMContextRef C);
  1055. LLVMTypeRef LLVMIntTypeInContext(LLVMContextRef C, unsigned NumBits);
  1056. /**
  1057. * Obtain an integer type from the global context with a specified bit
  1058. * width.
  1059. */
  1060. LLVMTypeRef LLVMInt1Type(void);
  1061. LLVMTypeRef LLVMInt8Type(void);
  1062. LLVMTypeRef LLVMInt16Type(void);
  1063. LLVMTypeRef LLVMInt32Type(void);
  1064. LLVMTypeRef LLVMInt64Type(void);
  1065. LLVMTypeRef LLVMInt128Type(void);
  1066. LLVMTypeRef LLVMIntType(unsigned NumBits);
  1067. unsigned LLVMGetIntTypeWidth(LLVMTypeRef IntegerTy);
  1068. /**
  1069. * @}
  1070. */
  1071. /**
  1072. * @defgroup LLVMCCoreTypeFloat Floating Point Types
  1073. *
  1074. * @{
  1075. */
  1076. /**
  1077. * Obtain a 16-bit floating point type from a context.
  1078. */
  1079. LLVMTypeRef LLVMHalfTypeInContext(LLVMContextRef C);
  1080. /**
  1081. * Obtain a 16-bit brain floating point type from a context.
  1082. */
  1083. LLVMTypeRef LLVMBFloatTypeInContext(LLVMContextRef C);
  1084. /**
  1085. * Obtain a 32-bit floating point type from a context.
  1086. */
  1087. LLVMTypeRef LLVMFloatTypeInContext(LLVMContextRef C);
  1088. /**
  1089. * Obtain a 64-bit floating point type from a context.
  1090. */
  1091. LLVMTypeRef LLVMDoubleTypeInContext(LLVMContextRef C);
  1092. /**
  1093. * Obtain a 80-bit floating point type (X87) from a context.
  1094. */
  1095. LLVMTypeRef LLVMX86FP80TypeInContext(LLVMContextRef C);
  1096. /**
  1097. * Obtain a 128-bit floating point type (112-bit mantissa) from a
  1098. * context.
  1099. */
  1100. LLVMTypeRef LLVMFP128TypeInContext(LLVMContextRef C);
  1101. /**
  1102. * Obtain a 128-bit floating point type (two 64-bits) from a context.
  1103. */
  1104. LLVMTypeRef LLVMPPCFP128TypeInContext(LLVMContextRef C);
  1105. /**
  1106. * Obtain a floating point type from the global context.
  1107. *
  1108. * These map to the functions in this group of the same name.
  1109. */
  1110. LLVMTypeRef LLVMHalfType(void);
  1111. LLVMTypeRef LLVMBFloatType(void);
  1112. LLVMTypeRef LLVMFloatType(void);
  1113. LLVMTypeRef LLVMDoubleType(void);
  1114. LLVMTypeRef LLVMX86FP80Type(void);
  1115. LLVMTypeRef LLVMFP128Type(void);
  1116. LLVMTypeRef LLVMPPCFP128Type(void);
  1117. /**
  1118. * @}
  1119. */
  1120. /**
  1121. * @defgroup LLVMCCoreTypeFunction Function Types
  1122. *
  1123. * @{
  1124. */
  1125. /**
  1126. * Obtain a function type consisting of a specified signature.
  1127. *
  1128. * The function is defined as a tuple of a return Type, a list of
  1129. * parameter types, and whether the function is variadic.
  1130. */
  1131. LLVMTypeRef LLVMFunctionType(LLVMTypeRef ReturnType,
  1132. LLVMTypeRef *ParamTypes, unsigned ParamCount,
  1133. LLVMBool IsVarArg);
  1134. /**
  1135. * Returns whether a function type is variadic.
  1136. */
  1137. LLVMBool LLVMIsFunctionVarArg(LLVMTypeRef FunctionTy);
  1138. /**
  1139. * Obtain the Type this function Type returns.
  1140. */
  1141. LLVMTypeRef LLVMGetReturnType(LLVMTypeRef FunctionTy);
  1142. /**
  1143. * Obtain the number of parameters this function accepts.
  1144. */
  1145. unsigned LLVMCountParamTypes(LLVMTypeRef FunctionTy);
  1146. /**
  1147. * Obtain the types of a function's parameters.
  1148. *
  1149. * The Dest parameter should point to a pre-allocated array of
  1150. * LLVMTypeRef at least LLVMCountParamTypes() large. On return, the
  1151. * first LLVMCountParamTypes() entries in the array will be populated
  1152. * with LLVMTypeRef instances.
  1153. *
  1154. * @param FunctionTy The function type to operate on.
  1155. * @param Dest Memory address of an array to be filled with result.
  1156. */
  1157. void LLVMGetParamTypes(LLVMTypeRef FunctionTy, LLVMTypeRef *Dest);
  1158. /**
  1159. * @}
  1160. */
  1161. /**
  1162. * @defgroup LLVMCCoreTypeStruct Structure Types
  1163. *
  1164. * These functions relate to LLVMTypeRef instances.
  1165. *
  1166. * @see llvm::StructType
  1167. *
  1168. * @{
  1169. */
  1170. /**
  1171. * Create a new structure type in a context.
  1172. *
  1173. * A structure is specified by a list of inner elements/types and
  1174. * whether these can be packed together.
  1175. *
  1176. * @see llvm::StructType::create()
  1177. */
  1178. LLVMTypeRef LLVMStructTypeInContext(LLVMContextRef C, LLVMTypeRef *ElementTypes,
  1179. unsigned ElementCount, LLVMBool Packed);
  1180. /**
  1181. * Create a new structure type in the global context.
  1182. *
  1183. * @see llvm::StructType::create()
  1184. */
  1185. LLVMTypeRef LLVMStructType(LLVMTypeRef *ElementTypes, unsigned ElementCount,
  1186. LLVMBool Packed);
  1187. /**
  1188. * Create an empty structure in a context having a specified name.
  1189. *
  1190. * @see llvm::StructType::create()
  1191. */
  1192. LLVMTypeRef LLVMStructCreateNamed(LLVMContextRef C, const char *Name);
  1193. /**
  1194. * Obtain the name of a structure.
  1195. *
  1196. * @see llvm::StructType::getName()
  1197. */
  1198. const char *LLVMGetStructName(LLVMTypeRef Ty);
  1199. /**
  1200. * Set the contents of a structure type.
  1201. *
  1202. * @see llvm::StructType::setBody()
  1203. */
  1204. void LLVMStructSetBody(LLVMTypeRef StructTy, LLVMTypeRef *ElementTypes,
  1205. unsigned ElementCount, LLVMBool Packed);
  1206. /**
  1207. * Get the number of elements defined inside the structure.
  1208. *
  1209. * @see llvm::StructType::getNumElements()
  1210. */
  1211. unsigned LLVMCountStructElementTypes(LLVMTypeRef StructTy);
  1212. /**
  1213. * Get the elements within a structure.
  1214. *
  1215. * The function is passed the address of a pre-allocated array of
  1216. * LLVMTypeRef at least LLVMCountStructElementTypes() long. After
  1217. * invocation, this array will be populated with the structure's
  1218. * elements. The objects in the destination array will have a lifetime
  1219. * of the structure type itself, which is the lifetime of the context it
  1220. * is contained in.
  1221. */
  1222. void LLVMGetStructElementTypes(LLVMTypeRef StructTy, LLVMTypeRef *Dest);
  1223. /**
  1224. * Get the type of the element at a given index in the structure.
  1225. *
  1226. * @see llvm::StructType::getTypeAtIndex()
  1227. */
  1228. LLVMTypeRef LLVMStructGetTypeAtIndex(LLVMTypeRef StructTy, unsigned i);
  1229. /**
  1230. * Determine whether a structure is packed.
  1231. *
  1232. * @see llvm::StructType::isPacked()
  1233. */
  1234. LLVMBool LLVMIsPackedStruct(LLVMTypeRef StructTy);
  1235. /**
  1236. * Determine whether a structure is opaque.
  1237. *
  1238. * @see llvm::StructType::isOpaque()
  1239. */
  1240. LLVMBool LLVMIsOpaqueStruct(LLVMTypeRef StructTy);
  1241. /**
  1242. * Determine whether a structure is literal.
  1243. *
  1244. * @see llvm::StructType::isLiteral()
  1245. */
  1246. LLVMBool LLVMIsLiteralStruct(LLVMTypeRef StructTy);
  1247. /**
  1248. * @}
  1249. */
  1250. /**
  1251. * @defgroup LLVMCCoreTypeSequential Sequential Types
  1252. *
  1253. * Sequential types represents "arrays" of types. This is a super class
  1254. * for array, vector, and pointer types.
  1255. *
  1256. * @{
  1257. */
  1258. /**
  1259. * Obtain the element type of an array or vector type.
  1260. *
  1261. * This currently also works for pointer types, but this usage is deprecated.
  1262. *
  1263. * @see llvm::SequentialType::getElementType()
  1264. */
  1265. LLVMTypeRef LLVMGetElementType(LLVMTypeRef Ty);
  1266. /**
  1267. * Returns type's subtypes
  1268. *
  1269. * @see llvm::Type::subtypes()
  1270. */
  1271. void LLVMGetSubtypes(LLVMTypeRef Tp, LLVMTypeRef *Arr);
  1272. /**
  1273. * Return the number of types in the derived type.
  1274. *
  1275. * @see llvm::Type::getNumContainedTypes()
  1276. */
  1277. unsigned LLVMGetNumContainedTypes(LLVMTypeRef Tp);
  1278. /**
  1279. * Create a fixed size array type that refers to a specific type.
  1280. *
  1281. * The created type will exist in the context that its element type
  1282. * exists in.
  1283. *
  1284. * @see llvm::ArrayType::get()
  1285. */
  1286. LLVMTypeRef LLVMArrayType(LLVMTypeRef ElementType, unsigned ElementCount);
  1287. /**
  1288. * Obtain the length of an array type.
  1289. *
  1290. * This only works on types that represent arrays.
  1291. *
  1292. * @see llvm::ArrayType::getNumElements()
  1293. */
  1294. unsigned LLVMGetArrayLength(LLVMTypeRef ArrayTy);
  1295. /**
  1296. * Create a pointer type that points to a defined type.
  1297. *
  1298. * The created type will exist in the context that its pointee type
  1299. * exists in.
  1300. *
  1301. * @see llvm::PointerType::get()
  1302. */
  1303. LLVMTypeRef LLVMPointerType(LLVMTypeRef ElementType, unsigned AddressSpace);
  1304. /**
  1305. * Determine whether a pointer is opaque.
  1306. *
  1307. * True if this is an instance of an opaque PointerType.
  1308. *
  1309. * @see llvm::Type::isOpaquePointerTy()
  1310. */
  1311. LLVMBool LLVMPointerTypeIsOpaque(LLVMTypeRef Ty);
  1312. /**
  1313. * Create an opaque pointer type in a context.
  1314. *
  1315. * @see llvm::PointerType::get()
  1316. */
  1317. LLVMTypeRef LLVMPointerTypeInContext(LLVMContextRef C, unsigned AddressSpace);
  1318. /**
  1319. * Obtain the address space of a pointer type.
  1320. *
  1321. * This only works on types that represent pointers.
  1322. *
  1323. * @see llvm::PointerType::getAddressSpace()
  1324. */
  1325. unsigned LLVMGetPointerAddressSpace(LLVMTypeRef PointerTy);
  1326. /**
  1327. * Create a vector type that contains a defined type and has a specific
  1328. * number of elements.
  1329. *
  1330. * The created type will exist in the context thats its element type
  1331. * exists in.
  1332. *
  1333. * @see llvm::VectorType::get()
  1334. */
  1335. LLVMTypeRef LLVMVectorType(LLVMTypeRef ElementType, unsigned ElementCount);
  1336. /**
  1337. * Create a vector type that contains a defined type and has a scalable
  1338. * number of elements.
  1339. *
  1340. * The created type will exist in the context thats its element type
  1341. * exists in.
  1342. *
  1343. * @see llvm::ScalableVectorType::get()
  1344. */
  1345. LLVMTypeRef LLVMScalableVectorType(LLVMTypeRef ElementType,
  1346. unsigned ElementCount);
  1347. /**
  1348. * Obtain the (possibly scalable) number of elements in a vector type.
  1349. *
  1350. * This only works on types that represent vectors (fixed or scalable).
  1351. *
  1352. * @see llvm::VectorType::getNumElements()
  1353. */
  1354. unsigned LLVMGetVectorSize(LLVMTypeRef VectorTy);
  1355. /**
  1356. * @}
  1357. */
  1358. /**
  1359. * @defgroup LLVMCCoreTypeOther Other Types
  1360. *
  1361. * @{
  1362. */
  1363. /**
  1364. * Create a void type in a context.
  1365. */
  1366. LLVMTypeRef LLVMVoidTypeInContext(LLVMContextRef C);
  1367. /**
  1368. * Create a label type in a context.
  1369. */
  1370. LLVMTypeRef LLVMLabelTypeInContext(LLVMContextRef C);
  1371. /**
  1372. * Create a X86 MMX type in a context.
  1373. */
  1374. LLVMTypeRef LLVMX86MMXTypeInContext(LLVMContextRef C);
  1375. /**
  1376. * Create a X86 AMX type in a context.
  1377. */
  1378. LLVMTypeRef LLVMX86AMXTypeInContext(LLVMContextRef C);
  1379. /**
  1380. * Create a token type in a context.
  1381. */
  1382. LLVMTypeRef LLVMTokenTypeInContext(LLVMContextRef C);
  1383. /**
  1384. * Create a metadata type in a context.
  1385. */
  1386. LLVMTypeRef LLVMMetadataTypeInContext(LLVMContextRef C);
  1387. /**
  1388. * These are similar to the above functions except they operate on the
  1389. * global context.
  1390. */
  1391. LLVMTypeRef LLVMVoidType(void);
  1392. LLVMTypeRef LLVMLabelType(void);
  1393. LLVMTypeRef LLVMX86MMXType(void);
  1394. LLVMTypeRef LLVMX86AMXType(void);
  1395. /**
  1396. * Create a target extension type in LLVM context.
  1397. */
  1398. LLVMTypeRef LLVMTargetExtTypeInContext(LLVMContextRef C, const char *Name,
  1399. LLVMTypeRef *TypeParams,
  1400. unsigned TypeParamCount,
  1401. unsigned *IntParams,
  1402. unsigned IntParamCount);
  1403. /**
  1404. * @}
  1405. */
  1406. /**
  1407. * @}
  1408. */
  1409. /**
  1410. * @defgroup LLVMCCoreValues Values
  1411. *
  1412. * The bulk of LLVM's object model consists of values, which comprise a very
  1413. * rich type hierarchy.
  1414. *
  1415. * LLVMValueRef essentially represents llvm::Value. There is a rich
  1416. * hierarchy of classes within this type. Depending on the instance
  1417. * obtained, not all APIs are available.
  1418. *
  1419. * Callers can determine the type of an LLVMValueRef by calling the
  1420. * LLVMIsA* family of functions (e.g. LLVMIsAArgument()). These
  1421. * functions are defined by a macro, so it isn't obvious which are
  1422. * available by looking at the Doxygen source code. Instead, look at the
  1423. * source definition of LLVM_FOR_EACH_VALUE_SUBCLASS and note the list
  1424. * of value names given. These value names also correspond to classes in
  1425. * the llvm::Value hierarchy.
  1426. *
  1427. * @{
  1428. */
  1429. #define LLVM_FOR_EACH_VALUE_SUBCLASS(macro) \
  1430. macro(Argument) \
  1431. macro(BasicBlock) \
  1432. macro(InlineAsm) \
  1433. macro(User) \
  1434. macro(Constant) \
  1435. macro(BlockAddress) \
  1436. macro(ConstantAggregateZero) \
  1437. macro(ConstantArray) \
  1438. macro(ConstantDataSequential) \
  1439. macro(ConstantDataArray) \
  1440. macro(ConstantDataVector) \
  1441. macro(ConstantExpr) \
  1442. macro(ConstantFP) \
  1443. macro(ConstantInt) \
  1444. macro(ConstantPointerNull) \
  1445. macro(ConstantStruct) \
  1446. macro(ConstantTokenNone) \
  1447. macro(ConstantVector) \
  1448. macro(GlobalValue) \
  1449. macro(GlobalAlias) \
  1450. macro(GlobalObject) \
  1451. macro(Function) \
  1452. macro(GlobalVariable) \
  1453. macro(GlobalIFunc) \
  1454. macro(UndefValue) \
  1455. macro(PoisonValue) \
  1456. macro(Instruction) \
  1457. macro(UnaryOperator) \
  1458. macro(BinaryOperator) \
  1459. macro(CallInst) \
  1460. macro(IntrinsicInst) \
  1461. macro(DbgInfoIntrinsic) \
  1462. macro(DbgVariableIntrinsic) \
  1463. macro(DbgDeclareInst) \
  1464. macro(DbgLabelInst) \
  1465. macro(MemIntrinsic) \
  1466. macro(MemCpyInst) \
  1467. macro(MemMoveInst) \
  1468. macro(MemSetInst) \
  1469. macro(CmpInst) \
  1470. macro(FCmpInst) \
  1471. macro(ICmpInst) \
  1472. macro(ExtractElementInst) \
  1473. macro(GetElementPtrInst) \
  1474. macro(InsertElementInst) \
  1475. macro(InsertValueInst) \
  1476. macro(LandingPadInst) \
  1477. macro(PHINode) \
  1478. macro(SelectInst) \
  1479. macro(ShuffleVectorInst) \
  1480. macro(StoreInst) \
  1481. macro(BranchInst) \
  1482. macro(IndirectBrInst) \
  1483. macro(InvokeInst) \
  1484. macro(ReturnInst) \
  1485. macro(SwitchInst) \
  1486. macro(UnreachableInst) \
  1487. macro(ResumeInst) \
  1488. macro(CleanupReturnInst) \
  1489. macro(CatchReturnInst) \
  1490. macro(CatchSwitchInst) \
  1491. macro(CallBrInst) \
  1492. macro(FuncletPadInst) \
  1493. macro(CatchPadInst) \
  1494. macro(CleanupPadInst) \
  1495. macro(UnaryInstruction) \
  1496. macro(AllocaInst) \
  1497. macro(CastInst) \
  1498. macro(AddrSpaceCastInst) \
  1499. macro(BitCastInst) \
  1500. macro(FPExtInst) \
  1501. macro(FPToSIInst) \
  1502. macro(FPToUIInst) \
  1503. macro(FPTruncInst) \
  1504. macro(IntToPtrInst) \
  1505. macro(PtrToIntInst) \
  1506. macro(SExtInst) \
  1507. macro(SIToFPInst) \
  1508. macro(TruncInst) \
  1509. macro(UIToFPInst) \
  1510. macro(ZExtInst) \
  1511. macro(ExtractValueInst) \
  1512. macro(LoadInst) \
  1513. macro(VAArgInst) \
  1514. macro(FreezeInst) \
  1515. macro(AtomicCmpXchgInst) \
  1516. macro(AtomicRMWInst) \
  1517. macro(FenceInst)
  1518. /**
  1519. * @defgroup LLVMCCoreValueGeneral General APIs
  1520. *
  1521. * Functions in this section work on all LLVMValueRef instances,
  1522. * regardless of their sub-type. They correspond to functions available
  1523. * on llvm::Value.
  1524. *
  1525. * @{
  1526. */
  1527. /**
  1528. * Obtain the type of a value.
  1529. *
  1530. * @see llvm::Value::getType()
  1531. */
  1532. LLVMTypeRef LLVMTypeOf(LLVMValueRef Val);
  1533. /**
  1534. * Obtain the enumerated type of a Value instance.
  1535. *
  1536. * @see llvm::Value::getValueID()
  1537. */
  1538. LLVMValueKind LLVMGetValueKind(LLVMValueRef Val);
  1539. /**
  1540. * Obtain the string name of a value.
  1541. *
  1542. * @see llvm::Value::getName()
  1543. */
  1544. const char *LLVMGetValueName2(LLVMValueRef Val, size_t *Length);
  1545. /**
  1546. * Set the string name of a value.
  1547. *
  1548. * @see llvm::Value::setName()
  1549. */
  1550. void LLVMSetValueName2(LLVMValueRef Val, const char *Name, size_t NameLen);
  1551. /**
  1552. * Dump a representation of a value to stderr.
  1553. *
  1554. * @see llvm::Value::dump()
  1555. */
  1556. void LLVMDumpValue(LLVMValueRef Val);
  1557. /**
  1558. * Return a string representation of the value. Use
  1559. * LLVMDisposeMessage to free the string.
  1560. *
  1561. * @see llvm::Value::print()
  1562. */
  1563. char *LLVMPrintValueToString(LLVMValueRef Val);
  1564. /**
  1565. * Replace all uses of a value with another one.
  1566. *
  1567. * @see llvm::Value::replaceAllUsesWith()
  1568. */
  1569. void LLVMReplaceAllUsesWith(LLVMValueRef OldVal, LLVMValueRef NewVal);
  1570. /**
  1571. * Determine whether the specified value instance is constant.
  1572. */
  1573. LLVMBool LLVMIsConstant(LLVMValueRef Val);
  1574. /**
  1575. * Determine whether a value instance is undefined.
  1576. */
  1577. LLVMBool LLVMIsUndef(LLVMValueRef Val);
  1578. /**
  1579. * Determine whether a value instance is poisonous.
  1580. */
  1581. LLVMBool LLVMIsPoison(LLVMValueRef Val);
  1582. /**
  1583. * Convert value instances between types.
  1584. *
  1585. * Internally, an LLVMValueRef is "pinned" to a specific type. This
  1586. * series of functions allows you to cast an instance to a specific
  1587. * type.
  1588. *
  1589. * If the cast is not valid for the specified type, NULL is returned.
  1590. *
  1591. * @see llvm::dyn_cast_or_null<>
  1592. */
  1593. #define LLVM_DECLARE_VALUE_CAST(name) \
  1594. LLVMValueRef LLVMIsA##name(LLVMValueRef Val);
  1595. LLVM_FOR_EACH_VALUE_SUBCLASS(LLVM_DECLARE_VALUE_CAST)
  1596. LLVMValueRef LLVMIsAMDNode(LLVMValueRef Val);
  1597. LLVMValueRef LLVMIsAMDString(LLVMValueRef Val);
  1598. /** Deprecated: Use LLVMGetValueName2 instead. */
  1599. const char *LLVMGetValueName(LLVMValueRef Val);
  1600. /** Deprecated: Use LLVMSetValueName2 instead. */
  1601. void LLVMSetValueName(LLVMValueRef Val, const char *Name);
  1602. /**
  1603. * @}
  1604. */
  1605. /**
  1606. * @defgroup LLVMCCoreValueUses Usage
  1607. *
  1608. * This module defines functions that allow you to inspect the uses of a
  1609. * LLVMValueRef.
  1610. *
  1611. * It is possible to obtain an LLVMUseRef for any LLVMValueRef instance.
  1612. * Each LLVMUseRef (which corresponds to a llvm::Use instance) holds a
  1613. * llvm::User and llvm::Value.
  1614. *
  1615. * @{
  1616. */
  1617. /**
  1618. * Obtain the first use of a value.
  1619. *
  1620. * Uses are obtained in an iterator fashion. First, call this function
  1621. * to obtain a reference to the first use. Then, call LLVMGetNextUse()
  1622. * on that instance and all subsequently obtained instances until
  1623. * LLVMGetNextUse() returns NULL.
  1624. *
  1625. * @see llvm::Value::use_begin()
  1626. */
  1627. LLVMUseRef LLVMGetFirstUse(LLVMValueRef Val);
  1628. /**
  1629. * Obtain the next use of a value.
  1630. *
  1631. * This effectively advances the iterator. It returns NULL if you are on
  1632. * the final use and no more are available.
  1633. */
  1634. LLVMUseRef LLVMGetNextUse(LLVMUseRef U);
  1635. /**
  1636. * Obtain the user value for a user.
  1637. *
  1638. * The returned value corresponds to a llvm::User type.
  1639. *
  1640. * @see llvm::Use::getUser()
  1641. */
  1642. LLVMValueRef LLVMGetUser(LLVMUseRef U);
  1643. /**
  1644. * Obtain the value this use corresponds to.
  1645. *
  1646. * @see llvm::Use::get().
  1647. */
  1648. LLVMValueRef LLVMGetUsedValue(LLVMUseRef U);
  1649. /**
  1650. * @}
  1651. */
  1652. /**
  1653. * @defgroup LLVMCCoreValueUser User value
  1654. *
  1655. * Function in this group pertain to LLVMValueRef instances that descent
  1656. * from llvm::User. This includes constants, instructions, and
  1657. * operators.
  1658. *
  1659. * @{
  1660. */
  1661. /**
  1662. * Obtain an operand at a specific index in a llvm::User value.
  1663. *
  1664. * @see llvm::User::getOperand()
  1665. */
  1666. LLVMValueRef LLVMGetOperand(LLVMValueRef Val, unsigned Index);
  1667. /**
  1668. * Obtain the use of an operand at a specific index in a llvm::User value.
  1669. *
  1670. * @see llvm::User::getOperandUse()
  1671. */
  1672. LLVMUseRef LLVMGetOperandUse(LLVMValueRef Val, unsigned Index);
  1673. /**
  1674. * Set an operand at a specific index in a llvm::User value.
  1675. *
  1676. * @see llvm::User::setOperand()
  1677. */
  1678. void LLVMSetOperand(LLVMValueRef User, unsigned Index, LLVMValueRef Val);
  1679. /**
  1680. * Obtain the number of operands in a llvm::User value.
  1681. *
  1682. * @see llvm::User::getNumOperands()
  1683. */
  1684. int LLVMGetNumOperands(LLVMValueRef Val);
  1685. /**
  1686. * @}
  1687. */
  1688. /**
  1689. * @defgroup LLVMCCoreValueConstant Constants
  1690. *
  1691. * This section contains APIs for interacting with LLVMValueRef that
  1692. * correspond to llvm::Constant instances.
  1693. *
  1694. * These functions will work for any LLVMValueRef in the llvm::Constant
  1695. * class hierarchy.
  1696. *
  1697. * @{
  1698. */
  1699. /**
  1700. * Obtain a constant value referring to the null instance of a type.
  1701. *
  1702. * @see llvm::Constant::getNullValue()
  1703. */
  1704. LLVMValueRef LLVMConstNull(LLVMTypeRef Ty); /* all zeroes */
  1705. /**
  1706. * Obtain a constant value referring to the instance of a type
  1707. * consisting of all ones.
  1708. *
  1709. * This is only valid for integer types.
  1710. *
  1711. * @see llvm::Constant::getAllOnesValue()
  1712. */
  1713. LLVMValueRef LLVMConstAllOnes(LLVMTypeRef Ty);
  1714. /**
  1715. * Obtain a constant value referring to an undefined value of a type.
  1716. *
  1717. * @see llvm::UndefValue::get()
  1718. */
  1719. LLVMValueRef LLVMGetUndef(LLVMTypeRef Ty);
  1720. /**
  1721. * Obtain a constant value referring to a poison value of a type.
  1722. *
  1723. * @see llvm::PoisonValue::get()
  1724. */
  1725. LLVMValueRef LLVMGetPoison(LLVMTypeRef Ty);
  1726. /**
  1727. * Determine whether a value instance is null.
  1728. *
  1729. * @see llvm::Constant::isNullValue()
  1730. */
  1731. LLVMBool LLVMIsNull(LLVMValueRef Val);
  1732. /**
  1733. * Obtain a constant that is a constant pointer pointing to NULL for a
  1734. * specified type.
  1735. */
  1736. LLVMValueRef LLVMConstPointerNull(LLVMTypeRef Ty);
  1737. /**
  1738. * @defgroup LLVMCCoreValueConstantScalar Scalar constants
  1739. *
  1740. * Functions in this group model LLVMValueRef instances that correspond
  1741. * to constants referring to scalar types.
  1742. *
  1743. * For integer types, the LLVMTypeRef parameter should correspond to a
  1744. * llvm::IntegerType instance and the returned LLVMValueRef will
  1745. * correspond to a llvm::ConstantInt.
  1746. *
  1747. * For floating point types, the LLVMTypeRef returned corresponds to a
  1748. * llvm::ConstantFP.
  1749. *
  1750. * @{
  1751. */
  1752. /**
  1753. * Obtain a constant value for an integer type.
  1754. *
  1755. * The returned value corresponds to a llvm::ConstantInt.
  1756. *
  1757. * @see llvm::ConstantInt::get()
  1758. *
  1759. * @param IntTy Integer type to obtain value of.
  1760. * @param N The value the returned instance should refer to.
  1761. * @param SignExtend Whether to sign extend the produced value.
  1762. */
  1763. LLVMValueRef LLVMConstInt(LLVMTypeRef IntTy, unsigned long long N,
  1764. LLVMBool SignExtend);
  1765. /**
  1766. * Obtain a constant value for an integer of arbitrary precision.
  1767. *
  1768. * @see llvm::ConstantInt::get()
  1769. */
  1770. LLVMValueRef LLVMConstIntOfArbitraryPrecision(LLVMTypeRef IntTy,
  1771. unsigned NumWords,
  1772. const uint64_t Words[]);
  1773. /**
  1774. * Obtain a constant value for an integer parsed from a string.
  1775. *
  1776. * A similar API, LLVMConstIntOfStringAndSize is also available. If the
  1777. * string's length is available, it is preferred to call that function
  1778. * instead.
  1779. *
  1780. * @see llvm::ConstantInt::get()
  1781. */
  1782. LLVMValueRef LLVMConstIntOfString(LLVMTypeRef IntTy, const char *Text,
  1783. uint8_t Radix);
  1784. /**
  1785. * Obtain a constant value for an integer parsed from a string with
  1786. * specified length.
  1787. *
  1788. * @see llvm::ConstantInt::get()
  1789. */
  1790. LLVMValueRef LLVMConstIntOfStringAndSize(LLVMTypeRef IntTy, const char *Text,
  1791. unsigned SLen, uint8_t Radix);
  1792. /**
  1793. * Obtain a constant value referring to a double floating point value.
  1794. */
  1795. LLVMValueRef LLVMConstReal(LLVMTypeRef RealTy, double N);
  1796. /**
  1797. * Obtain a constant for a floating point value parsed from a string.
  1798. *
  1799. * A similar API, LLVMConstRealOfStringAndSize is also available. It
  1800. * should be used if the input string's length is known.
  1801. */
  1802. LLVMValueRef LLVMConstRealOfString(LLVMTypeRef RealTy, const char *Text);
  1803. /**
  1804. * Obtain a constant for a floating point value parsed from a string.
  1805. */
  1806. LLVMValueRef LLVMConstRealOfStringAndSize(LLVMTypeRef RealTy, const char *Text,
  1807. unsigned SLen);
  1808. /**
  1809. * Obtain the zero extended value for an integer constant value.
  1810. *
  1811. * @see llvm::ConstantInt::getZExtValue()
  1812. */
  1813. unsigned long long LLVMConstIntGetZExtValue(LLVMValueRef ConstantVal);
  1814. /**
  1815. * Obtain the sign extended value for an integer constant value.
  1816. *
  1817. * @see llvm::ConstantInt::getSExtValue()
  1818. */
  1819. long long LLVMConstIntGetSExtValue(LLVMValueRef ConstantVal);
  1820. /**
  1821. * Obtain the double value for an floating point constant value.
  1822. * losesInfo indicates if some precision was lost in the conversion.
  1823. *
  1824. * @see llvm::ConstantFP::getDoubleValue
  1825. */
  1826. double LLVMConstRealGetDouble(LLVMValueRef ConstantVal, LLVMBool *losesInfo);
  1827. /**
  1828. * @}
  1829. */
  1830. /**
  1831. * @defgroup LLVMCCoreValueConstantComposite Composite Constants
  1832. *
  1833. * Functions in this group operate on composite constants.
  1834. *
  1835. * @{
  1836. */
  1837. /**
  1838. * Create a ConstantDataSequential and initialize it with a string.
  1839. *
  1840. * @see llvm::ConstantDataArray::getString()
  1841. */
  1842. LLVMValueRef LLVMConstStringInContext(LLVMContextRef C, const char *Str,
  1843. unsigned Length, LLVMBool DontNullTerminate);
  1844. /**
  1845. * Create a ConstantDataSequential with string content in the global context.
  1846. *
  1847. * This is the same as LLVMConstStringInContext except it operates on the
  1848. * global context.
  1849. *
  1850. * @see LLVMConstStringInContext()
  1851. * @see llvm::ConstantDataArray::getString()
  1852. */
  1853. LLVMValueRef LLVMConstString(const char *Str, unsigned Length,
  1854. LLVMBool DontNullTerminate);
  1855. /**
  1856. * Returns true if the specified constant is an array of i8.
  1857. *
  1858. * @see ConstantDataSequential::getAsString()
  1859. */
  1860. LLVMBool LLVMIsConstantString(LLVMValueRef c);
  1861. /**
  1862. * Get the given constant data sequential as a string.
  1863. *
  1864. * @see ConstantDataSequential::getAsString()
  1865. */
  1866. const char *LLVMGetAsString(LLVMValueRef c, size_t *Length);
  1867. /**
  1868. * Create an anonymous ConstantStruct with the specified values.
  1869. *
  1870. * @see llvm::ConstantStruct::getAnon()
  1871. */
  1872. LLVMValueRef LLVMConstStructInContext(LLVMContextRef C,
  1873. LLVMValueRef *ConstantVals,
  1874. unsigned Count, LLVMBool Packed);
  1875. /**
  1876. * Create a ConstantStruct in the global Context.
  1877. *
  1878. * This is the same as LLVMConstStructInContext except it operates on the
  1879. * global Context.
  1880. *
  1881. * @see LLVMConstStructInContext()
  1882. */
  1883. LLVMValueRef LLVMConstStruct(LLVMValueRef *ConstantVals, unsigned Count,
  1884. LLVMBool Packed);
  1885. /**
  1886. * Create a ConstantArray from values.
  1887. *
  1888. * @see llvm::ConstantArray::get()
  1889. */
  1890. LLVMValueRef LLVMConstArray(LLVMTypeRef ElementTy,
  1891. LLVMValueRef *ConstantVals, unsigned Length);
  1892. /**
  1893. * Create a non-anonymous ConstantStruct from values.
  1894. *
  1895. * @see llvm::ConstantStruct::get()
  1896. */
  1897. LLVMValueRef LLVMConstNamedStruct(LLVMTypeRef StructTy,
  1898. LLVMValueRef *ConstantVals,
  1899. unsigned Count);
  1900. /**
  1901. * Get element of a constant aggregate (struct, array or vector) at the
  1902. * specified index. Returns null if the index is out of range, or it's not
  1903. * possible to determine the element (e.g., because the constant is a
  1904. * constant expression.)
  1905. *
  1906. * @see llvm::Constant::getAggregateElement()
  1907. */
  1908. LLVMValueRef LLVMGetAggregateElement(LLVMValueRef C, unsigned Idx);
  1909. /**
  1910. * Get an element at specified index as a constant.
  1911. *
  1912. * @see ConstantDataSequential::getElementAsConstant()
  1913. */
  1914. LLVM_ATTRIBUTE_C_DEPRECATED(
  1915. LLVMValueRef LLVMGetElementAsConstant(LLVMValueRef C, unsigned idx),
  1916. "Use LLVMGetAggregateElement instead");
  1917. /**
  1918. * Create a ConstantVector from values.
  1919. *
  1920. * @see llvm::ConstantVector::get()
  1921. */
  1922. LLVMValueRef LLVMConstVector(LLVMValueRef *ScalarConstantVals, unsigned Size);
  1923. /**
  1924. * @}
  1925. */
  1926. /**
  1927. * @defgroup LLVMCCoreValueConstantExpressions Constant Expressions
  1928. *
  1929. * Functions in this group correspond to APIs on llvm::ConstantExpr.
  1930. *
  1931. * @see llvm::ConstantExpr.
  1932. *
  1933. * @{
  1934. */
  1935. LLVMOpcode LLVMGetConstOpcode(LLVMValueRef ConstantVal);
  1936. LLVMValueRef LLVMAlignOf(LLVMTypeRef Ty);
  1937. LLVMValueRef LLVMSizeOf(LLVMTypeRef Ty);
  1938. LLVMValueRef LLVMConstNeg(LLVMValueRef ConstantVal);
  1939. LLVMValueRef LLVMConstNSWNeg(LLVMValueRef ConstantVal);
  1940. LLVMValueRef LLVMConstNUWNeg(LLVMValueRef ConstantVal);
  1941. LLVMValueRef LLVMConstNot(LLVMValueRef ConstantVal);
  1942. LLVMValueRef LLVMConstAdd(LLVMValueRef LHSConstant, LLVMValueRef RHSConstant);
  1943. LLVMValueRef LLVMConstNSWAdd(LLVMValueRef LHSConstant, LLVMValueRef RHSConstant);
  1944. LLVMValueRef LLVMConstNUWAdd(LLVMValueRef LHSConstant, LLVMValueRef RHSConstant);
  1945. LLVMValueRef LLVMConstSub(LLVMValueRef LHSConstant, LLVMValueRef RHSConstant);
  1946. LLVMValueRef LLVMConstNSWSub(LLVMValueRef LHSConstant, LLVMValueRef RHSConstant);
  1947. LLVMValueRef LLVMConstNUWSub(LLVMValueRef LHSConstant, LLVMValueRef RHSConstant);
  1948. LLVMValueRef LLVMConstMul(LLVMValueRef LHSConstant, LLVMValueRef RHSConstant);
  1949. LLVMValueRef LLVMConstNSWMul(LLVMValueRef LHSConstant, LLVMValueRef RHSConstant);
  1950. LLVMValueRef LLVMConstNUWMul(LLVMValueRef LHSConstant, LLVMValueRef RHSConstant);
  1951. LLVMValueRef LLVMConstAnd(LLVMValueRef LHSConstant, LLVMValueRef RHSConstant);
  1952. LLVMValueRef LLVMConstOr(LLVMValueRef LHSConstant, LLVMValueRef RHSConstant);
  1953. LLVMValueRef LLVMConstXor(LLVMValueRef LHSConstant, LLVMValueRef RHSConstant);
  1954. LLVMValueRef LLVMConstICmp(LLVMIntPredicate Predicate,
  1955. LLVMValueRef LHSConstant, LLVMValueRef RHSConstant);
  1956. LLVMValueRef LLVMConstFCmp(LLVMRealPredicate Predicate,
  1957. LLVMValueRef LHSConstant, LLVMValueRef RHSConstant);
  1958. LLVMValueRef LLVMConstShl(LLVMValueRef LHSConstant, LLVMValueRef RHSConstant);
  1959. LLVMValueRef LLVMConstLShr(LLVMValueRef LHSConstant, LLVMValueRef RHSConstant);
  1960. LLVMValueRef LLVMConstAShr(LLVMValueRef LHSConstant, LLVMValueRef RHSConstant);
  1961. LLVMValueRef LLVMConstGEP2(LLVMTypeRef Ty, LLVMValueRef ConstantVal,
  1962. LLVMValueRef *ConstantIndices, unsigned NumIndices);
  1963. LLVMValueRef LLVMConstInBoundsGEP2(LLVMTypeRef Ty, LLVMValueRef ConstantVal,
  1964. LLVMValueRef *ConstantIndices,
  1965. unsigned NumIndices);
  1966. LLVMValueRef LLVMConstTrunc(LLVMValueRef ConstantVal, LLVMTypeRef ToType);
  1967. LLVMValueRef LLVMConstSExt(LLVMValueRef ConstantVal, LLVMTypeRef ToType);
  1968. LLVMValueRef LLVMConstZExt(LLVMValueRef ConstantVal, LLVMTypeRef ToType);
  1969. LLVMValueRef LLVMConstFPTrunc(LLVMValueRef ConstantVal, LLVMTypeRef ToType);
  1970. LLVMValueRef LLVMConstFPExt(LLVMValueRef ConstantVal, LLVMTypeRef ToType);
  1971. LLVMValueRef LLVMConstUIToFP(LLVMValueRef ConstantVal, LLVMTypeRef ToType);
  1972. LLVMValueRef LLVMConstSIToFP(LLVMValueRef ConstantVal, LLVMTypeRef ToType);
  1973. LLVMValueRef LLVMConstFPToUI(LLVMValueRef ConstantVal, LLVMTypeRef ToType);
  1974. LLVMValueRef LLVMConstFPToSI(LLVMValueRef ConstantVal, LLVMTypeRef ToType);
  1975. LLVMValueRef LLVMConstPtrToInt(LLVMValueRef ConstantVal, LLVMTypeRef ToType);
  1976. LLVMValueRef LLVMConstIntToPtr(LLVMValueRef ConstantVal, LLVMTypeRef ToType);
  1977. LLVMValueRef LLVMConstBitCast(LLVMValueRef ConstantVal, LLVMTypeRef ToType);
  1978. LLVMValueRef LLVMConstAddrSpaceCast(LLVMValueRef ConstantVal, LLVMTypeRef ToType);
  1979. LLVMValueRef LLVMConstZExtOrBitCast(LLVMValueRef ConstantVal,
  1980. LLVMTypeRef ToType);
  1981. LLVMValueRef LLVMConstSExtOrBitCast(LLVMValueRef ConstantVal,
  1982. LLVMTypeRef ToType);
  1983. LLVMValueRef LLVMConstTruncOrBitCast(LLVMValueRef ConstantVal,
  1984. LLVMTypeRef ToType);
  1985. LLVMValueRef LLVMConstPointerCast(LLVMValueRef ConstantVal,
  1986. LLVMTypeRef ToType);
  1987. LLVMValueRef LLVMConstIntCast(LLVMValueRef ConstantVal, LLVMTypeRef ToType,
  1988. LLVMBool isSigned);
  1989. LLVMValueRef LLVMConstFPCast(LLVMValueRef ConstantVal, LLVMTypeRef ToType);
  1990. LLVMValueRef LLVMConstSelect(LLVMValueRef ConstantCondition,
  1991. LLVMValueRef ConstantIfTrue,
  1992. LLVMValueRef ConstantIfFalse);
  1993. LLVMValueRef LLVMConstExtractElement(LLVMValueRef VectorConstant,
  1994. LLVMValueRef IndexConstant);
  1995. LLVMValueRef LLVMConstInsertElement(LLVMValueRef VectorConstant,
  1996. LLVMValueRef ElementValueConstant,
  1997. LLVMValueRef IndexConstant);
  1998. LLVMValueRef LLVMConstShuffleVector(LLVMValueRef VectorAConstant,
  1999. LLVMValueRef VectorBConstant,
  2000. LLVMValueRef MaskConstant);
  2001. LLVMValueRef LLVMBlockAddress(LLVMValueRef F, LLVMBasicBlockRef BB);
  2002. /** Deprecated: Use LLVMGetInlineAsm instead. */
  2003. LLVMValueRef LLVMConstInlineAsm(LLVMTypeRef Ty,
  2004. const char *AsmString, const char *Constraints,
  2005. LLVMBool HasSideEffects, LLVMBool IsAlignStack);
  2006. /**
  2007. * @}
  2008. */
  2009. /**
  2010. * @defgroup LLVMCCoreValueConstantGlobals Global Values
  2011. *
  2012. * This group contains functions that operate on global values. Functions in
  2013. * this group relate to functions in the llvm::GlobalValue class tree.
  2014. *
  2015. * @see llvm::GlobalValue
  2016. *
  2017. * @{
  2018. */
  2019. LLVMModuleRef LLVMGetGlobalParent(LLVMValueRef Global);
  2020. LLVMBool LLVMIsDeclaration(LLVMValueRef Global);
  2021. LLVMLinkage LLVMGetLinkage(LLVMValueRef Global);
  2022. void LLVMSetLinkage(LLVMValueRef Global, LLVMLinkage Linkage);
  2023. const char *LLVMGetSection(LLVMValueRef Global);
  2024. void LLVMSetSection(LLVMValueRef Global, const char *Section);
  2025. LLVMVisibility LLVMGetVisibility(LLVMValueRef Global);
  2026. void LLVMSetVisibility(LLVMValueRef Global, LLVMVisibility Viz);
  2027. LLVMDLLStorageClass LLVMGetDLLStorageClass(LLVMValueRef Global);
  2028. void LLVMSetDLLStorageClass(LLVMValueRef Global, LLVMDLLStorageClass Class);
  2029. LLVMUnnamedAddr LLVMGetUnnamedAddress(LLVMValueRef Global);
  2030. void LLVMSetUnnamedAddress(LLVMValueRef Global, LLVMUnnamedAddr UnnamedAddr);
  2031. /**
  2032. * Returns the "value type" of a global value. This differs from the formal
  2033. * type of a global value which is always a pointer type.
  2034. *
  2035. * @see llvm::GlobalValue::getValueType()
  2036. */
  2037. LLVMTypeRef LLVMGlobalGetValueType(LLVMValueRef Global);
  2038. /** Deprecated: Use LLVMGetUnnamedAddress instead. */
  2039. LLVMBool LLVMHasUnnamedAddr(LLVMValueRef Global);
  2040. /** Deprecated: Use LLVMSetUnnamedAddress instead. */
  2041. void LLVMSetUnnamedAddr(LLVMValueRef Global, LLVMBool HasUnnamedAddr);
  2042. /**
  2043. * @defgroup LLVMCCoreValueWithAlignment Values with alignment
  2044. *
  2045. * Functions in this group only apply to values with alignment, i.e.
  2046. * global variables, load and store instructions.
  2047. */
  2048. /**
  2049. * Obtain the preferred alignment of the value.
  2050. * @see llvm::AllocaInst::getAlignment()
  2051. * @see llvm::LoadInst::getAlignment()
  2052. * @see llvm::StoreInst::getAlignment()
  2053. * @see llvm::AtomicRMWInst::setAlignment()
  2054. * @see llvm::AtomicCmpXchgInst::setAlignment()
  2055. * @see llvm::GlobalValue::getAlignment()
  2056. */
  2057. unsigned LLVMGetAlignment(LLVMValueRef V);
  2058. /**
  2059. * Set the preferred alignment of the value.
  2060. * @see llvm::AllocaInst::setAlignment()
  2061. * @see llvm::LoadInst::setAlignment()
  2062. * @see llvm::StoreInst::setAlignment()
  2063. * @see llvm::AtomicRMWInst::setAlignment()
  2064. * @see llvm::AtomicCmpXchgInst::setAlignment()
  2065. * @see llvm::GlobalValue::setAlignment()
  2066. */
  2067. void LLVMSetAlignment(LLVMValueRef V, unsigned Bytes);
  2068. /**
  2069. * Sets a metadata attachment, erasing the existing metadata attachment if
  2070. * it already exists for the given kind.
  2071. *
  2072. * @see llvm::GlobalObject::setMetadata()
  2073. */
  2074. void LLVMGlobalSetMetadata(LLVMValueRef Global, unsigned Kind,
  2075. LLVMMetadataRef MD);
  2076. /**
  2077. * Erases a metadata attachment of the given kind if it exists.
  2078. *
  2079. * @see llvm::GlobalObject::eraseMetadata()
  2080. */
  2081. void LLVMGlobalEraseMetadata(LLVMValueRef Global, unsigned Kind);
  2082. /**
  2083. * Removes all metadata attachments from this value.
  2084. *
  2085. * @see llvm::GlobalObject::clearMetadata()
  2086. */
  2087. void LLVMGlobalClearMetadata(LLVMValueRef Global);
  2088. /**
  2089. * Retrieves an array of metadata entries representing the metadata attached to
  2090. * this value. The caller is responsible for freeing this array by calling
  2091. * \c LLVMDisposeValueMetadataEntries.
  2092. *
  2093. * @see llvm::GlobalObject::getAllMetadata()
  2094. */
  2095. LLVMValueMetadataEntry *LLVMGlobalCopyAllMetadata(LLVMValueRef Value,
  2096. size_t *NumEntries);
  2097. /**
  2098. * Destroys value metadata entries.
  2099. */
  2100. void LLVMDisposeValueMetadataEntries(LLVMValueMetadataEntry *Entries);
  2101. /**
  2102. * Returns the kind of a value metadata entry at a specific index.
  2103. */
  2104. unsigned LLVMValueMetadataEntriesGetKind(LLVMValueMetadataEntry *Entries,
  2105. unsigned Index);
  2106. /**
  2107. * Returns the underlying metadata node of a value metadata entry at a
  2108. * specific index.
  2109. */
  2110. LLVMMetadataRef
  2111. LLVMValueMetadataEntriesGetMetadata(LLVMValueMetadataEntry *Entries,
  2112. unsigned Index);
  2113. /**
  2114. * @}
  2115. */
  2116. /**
  2117. * @defgroup LLVMCoreValueConstantGlobalVariable Global Variables
  2118. *
  2119. * This group contains functions that operate on global variable values.
  2120. *
  2121. * @see llvm::GlobalVariable
  2122. *
  2123. * @{
  2124. */
  2125. LLVMValueRef LLVMAddGlobal(LLVMModuleRef M, LLVMTypeRef Ty, const char *Name);
  2126. LLVMValueRef LLVMAddGlobalInAddressSpace(LLVMModuleRef M, LLVMTypeRef Ty,
  2127. const char *Name,
  2128. unsigned AddressSpace);
  2129. LLVMValueRef LLVMGetNamedGlobal(LLVMModuleRef M, const char *Name);
  2130. LLVMValueRef LLVMGetFirstGlobal(LLVMModuleRef M);
  2131. LLVMValueRef LLVMGetLastGlobal(LLVMModuleRef M);
  2132. LLVMValueRef LLVMGetNextGlobal(LLVMValueRef GlobalVar);
  2133. LLVMValueRef LLVMGetPreviousGlobal(LLVMValueRef GlobalVar);
  2134. void LLVMDeleteGlobal(LLVMValueRef GlobalVar);
  2135. LLVMValueRef LLVMGetInitializer(LLVMValueRef GlobalVar);
  2136. void LLVMSetInitializer(LLVMValueRef GlobalVar, LLVMValueRef ConstantVal);
  2137. LLVMBool LLVMIsThreadLocal(LLVMValueRef GlobalVar);
  2138. void LLVMSetThreadLocal(LLVMValueRef GlobalVar, LLVMBool IsThreadLocal);
  2139. LLVMBool LLVMIsGlobalConstant(LLVMValueRef GlobalVar);
  2140. void LLVMSetGlobalConstant(LLVMValueRef GlobalVar, LLVMBool IsConstant);
  2141. LLVMThreadLocalMode LLVMGetThreadLocalMode(LLVMValueRef GlobalVar);
  2142. void LLVMSetThreadLocalMode(LLVMValueRef GlobalVar, LLVMThreadLocalMode Mode);
  2143. LLVMBool LLVMIsExternallyInitialized(LLVMValueRef GlobalVar);
  2144. void LLVMSetExternallyInitialized(LLVMValueRef GlobalVar, LLVMBool IsExtInit);
  2145. /**
  2146. * @}
  2147. */
  2148. /**
  2149. * @defgroup LLVMCoreValueConstantGlobalAlias Global Aliases
  2150. *
  2151. * This group contains function that operate on global alias values.
  2152. *
  2153. * @see llvm::GlobalAlias
  2154. *
  2155. * @{
  2156. */
  2157. /**
  2158. * Add a GlobalAlias with the given value type, address space and aliasee.
  2159. *
  2160. * @see llvm::GlobalAlias::create()
  2161. */
  2162. LLVMValueRef LLVMAddAlias2(LLVMModuleRef M, LLVMTypeRef ValueTy,
  2163. unsigned AddrSpace, LLVMValueRef Aliasee,
  2164. const char *Name);
  2165. /**
  2166. * Obtain a GlobalAlias value from a Module by its name.
  2167. *
  2168. * The returned value corresponds to a llvm::GlobalAlias value.
  2169. *
  2170. * @see llvm::Module::getNamedAlias()
  2171. */
  2172. LLVMValueRef LLVMGetNamedGlobalAlias(LLVMModuleRef M,
  2173. const char *Name, size_t NameLen);
  2174. /**
  2175. * Obtain an iterator to the first GlobalAlias in a Module.
  2176. *
  2177. * @see llvm::Module::alias_begin()
  2178. */
  2179. LLVMValueRef LLVMGetFirstGlobalAlias(LLVMModuleRef M);
  2180. /**
  2181. * Obtain an iterator to the last GlobalAlias in a Module.
  2182. *
  2183. * @see llvm::Module::alias_end()
  2184. */
  2185. LLVMValueRef LLVMGetLastGlobalAlias(LLVMModuleRef M);
  2186. /**
  2187. * Advance a GlobalAlias iterator to the next GlobalAlias.
  2188. *
  2189. * Returns NULL if the iterator was already at the end and there are no more
  2190. * global aliases.
  2191. */
  2192. LLVMValueRef LLVMGetNextGlobalAlias(LLVMValueRef GA);
  2193. /**
  2194. * Decrement a GlobalAlias iterator to the previous GlobalAlias.
  2195. *
  2196. * Returns NULL if the iterator was already at the beginning and there are
  2197. * no previous global aliases.
  2198. */
  2199. LLVMValueRef LLVMGetPreviousGlobalAlias(LLVMValueRef GA);
  2200. /**
  2201. * Retrieve the target value of an alias.
  2202. */
  2203. LLVMValueRef LLVMAliasGetAliasee(LLVMValueRef Alias);
  2204. /**
  2205. * Set the target value of an alias.
  2206. */
  2207. void LLVMAliasSetAliasee(LLVMValueRef Alias, LLVMValueRef Aliasee);
  2208. /**
  2209. * @}
  2210. */
  2211. /**
  2212. * @defgroup LLVMCCoreValueFunction Function values
  2213. *
  2214. * Functions in this group operate on LLVMValueRef instances that
  2215. * correspond to llvm::Function instances.
  2216. *
  2217. * @see llvm::Function
  2218. *
  2219. * @{
  2220. */
  2221. /**
  2222. * Remove a function from its containing module and deletes it.
  2223. *
  2224. * @see llvm::Function::eraseFromParent()
  2225. */
  2226. void LLVMDeleteFunction(LLVMValueRef Fn);
  2227. /**
  2228. * Check whether the given function has a personality function.
  2229. *
  2230. * @see llvm::Function::hasPersonalityFn()
  2231. */
  2232. LLVMBool LLVMHasPersonalityFn(LLVMValueRef Fn);
  2233. /**
  2234. * Obtain the personality function attached to the function.
  2235. *
  2236. * @see llvm::Function::getPersonalityFn()
  2237. */
  2238. LLVMValueRef LLVMGetPersonalityFn(LLVMValueRef Fn);
  2239. /**
  2240. * Set the personality function attached to the function.
  2241. *
  2242. * @see llvm::Function::setPersonalityFn()
  2243. */
  2244. void LLVMSetPersonalityFn(LLVMValueRef Fn, LLVMValueRef PersonalityFn);
  2245. /**
  2246. * Obtain the intrinsic ID number which matches the given function name.
  2247. *
  2248. * @see llvm::Function::lookupIntrinsicID()
  2249. */
  2250. unsigned LLVMLookupIntrinsicID(const char *Name, size_t NameLen);
  2251. /**
  2252. * Obtain the ID number from a function instance.
  2253. *
  2254. * @see llvm::Function::getIntrinsicID()
  2255. */
  2256. unsigned LLVMGetIntrinsicID(LLVMValueRef Fn);
  2257. /**
  2258. * Create or insert the declaration of an intrinsic. For overloaded intrinsics,
  2259. * parameter types must be provided to uniquely identify an overload.
  2260. *
  2261. * @see llvm::Intrinsic::getDeclaration()
  2262. */
  2263. LLVMValueRef LLVMGetIntrinsicDeclaration(LLVMModuleRef Mod,
  2264. unsigned ID,
  2265. LLVMTypeRef *ParamTypes,
  2266. size_t ParamCount);
  2267. /**
  2268. * Retrieves the type of an intrinsic. For overloaded intrinsics, parameter
  2269. * types must be provided to uniquely identify an overload.
  2270. *
  2271. * @see llvm::Intrinsic::getType()
  2272. */
  2273. LLVMTypeRef LLVMIntrinsicGetType(LLVMContextRef Ctx, unsigned ID,
  2274. LLVMTypeRef *ParamTypes, size_t ParamCount);
  2275. /**
  2276. * Retrieves the name of an intrinsic.
  2277. *
  2278. * @see llvm::Intrinsic::getName()
  2279. */
  2280. const char *LLVMIntrinsicGetName(unsigned ID, size_t *NameLength);
  2281. /** Deprecated: Use LLVMIntrinsicCopyOverloadedName2 instead. */
  2282. const char *LLVMIntrinsicCopyOverloadedName(unsigned ID,
  2283. LLVMTypeRef *ParamTypes,
  2284. size_t ParamCount,
  2285. size_t *NameLength);
  2286. /**
  2287. * Copies the name of an overloaded intrinsic identified by a given list of
  2288. * parameter types.
  2289. *
  2290. * Unlike LLVMIntrinsicGetName, the caller is responsible for freeing the
  2291. * returned string.
  2292. *
  2293. * This version also supports unnamed types.
  2294. *
  2295. * @see llvm::Intrinsic::getName()
  2296. */
  2297. const char *LLVMIntrinsicCopyOverloadedName2(LLVMModuleRef Mod, unsigned ID,
  2298. LLVMTypeRef *ParamTypes,
  2299. size_t ParamCount,
  2300. size_t *NameLength);
  2301. /**
  2302. * Obtain if the intrinsic identified by the given ID is overloaded.
  2303. *
  2304. * @see llvm::Intrinsic::isOverloaded()
  2305. */
  2306. LLVMBool LLVMIntrinsicIsOverloaded(unsigned ID);
  2307. /**
  2308. * Obtain the calling function of a function.
  2309. *
  2310. * The returned value corresponds to the LLVMCallConv enumeration.
  2311. *
  2312. * @see llvm::Function::getCallingConv()
  2313. */
  2314. unsigned LLVMGetFunctionCallConv(LLVMValueRef Fn);
  2315. /**
  2316. * Set the calling convention of a function.
  2317. *
  2318. * @see llvm::Function::setCallingConv()
  2319. *
  2320. * @param Fn Function to operate on
  2321. * @param CC LLVMCallConv to set calling convention to
  2322. */
  2323. void LLVMSetFunctionCallConv(LLVMValueRef Fn, unsigned CC);
  2324. /**
  2325. * Obtain the name of the garbage collector to use during code
  2326. * generation.
  2327. *
  2328. * @see llvm::Function::getGC()
  2329. */
  2330. const char *LLVMGetGC(LLVMValueRef Fn);
  2331. /**
  2332. * Define the garbage collector to use during code generation.
  2333. *
  2334. * @see llvm::Function::setGC()
  2335. */
  2336. void LLVMSetGC(LLVMValueRef Fn, const char *Name);
  2337. /**
  2338. * Add an attribute to a function.
  2339. *
  2340. * @see llvm::Function::addAttribute()
  2341. */
  2342. void LLVMAddAttributeAtIndex(LLVMValueRef F, LLVMAttributeIndex Idx,
  2343. LLVMAttributeRef A);
  2344. unsigned LLVMGetAttributeCountAtIndex(LLVMValueRef F, LLVMAttributeIndex Idx);
  2345. void LLVMGetAttributesAtIndex(LLVMValueRef F, LLVMAttributeIndex Idx,
  2346. LLVMAttributeRef *Attrs);
  2347. LLVMAttributeRef LLVMGetEnumAttributeAtIndex(LLVMValueRef F,
  2348. LLVMAttributeIndex Idx,
  2349. unsigned KindID);
  2350. LLVMAttributeRef LLVMGetStringAttributeAtIndex(LLVMValueRef F,
  2351. LLVMAttributeIndex Idx,
  2352. const char *K, unsigned KLen);
  2353. void LLVMRemoveEnumAttributeAtIndex(LLVMValueRef F, LLVMAttributeIndex Idx,
  2354. unsigned KindID);
  2355. void LLVMRemoveStringAttributeAtIndex(LLVMValueRef F, LLVMAttributeIndex Idx,
  2356. const char *K, unsigned KLen);
  2357. /**
  2358. * Add a target-dependent attribute to a function
  2359. * @see llvm::AttrBuilder::addAttribute()
  2360. */
  2361. void LLVMAddTargetDependentFunctionAttr(LLVMValueRef Fn, const char *A,
  2362. const char *V);
  2363. /**
  2364. * @defgroup LLVMCCoreValueFunctionParameters Function Parameters
  2365. *
  2366. * Functions in this group relate to arguments/parameters on functions.
  2367. *
  2368. * Functions in this group expect LLVMValueRef instances that correspond
  2369. * to llvm::Function instances.
  2370. *
  2371. * @{
  2372. */
  2373. /**
  2374. * Obtain the number of parameters in a function.
  2375. *
  2376. * @see llvm::Function::arg_size()
  2377. */
  2378. unsigned LLVMCountParams(LLVMValueRef Fn);
  2379. /**
  2380. * Obtain the parameters in a function.
  2381. *
  2382. * The takes a pointer to a pre-allocated array of LLVMValueRef that is
  2383. * at least LLVMCountParams() long. This array will be filled with
  2384. * LLVMValueRef instances which correspond to the parameters the
  2385. * function receives. Each LLVMValueRef corresponds to a llvm::Argument
  2386. * instance.
  2387. *
  2388. * @see llvm::Function::arg_begin()
  2389. */
  2390. void LLVMGetParams(LLVMValueRef Fn, LLVMValueRef *Params);
  2391. /**
  2392. * Obtain the parameter at the specified index.
  2393. *
  2394. * Parameters are indexed from 0.
  2395. *
  2396. * @see llvm::Function::arg_begin()
  2397. */
  2398. LLVMValueRef LLVMGetParam(LLVMValueRef Fn, unsigned Index);
  2399. /**
  2400. * Obtain the function to which this argument belongs.
  2401. *
  2402. * Unlike other functions in this group, this one takes an LLVMValueRef
  2403. * that corresponds to a llvm::Attribute.
  2404. *
  2405. * The returned LLVMValueRef is the llvm::Function to which this
  2406. * argument belongs.
  2407. */
  2408. LLVMValueRef LLVMGetParamParent(LLVMValueRef Inst);
  2409. /**
  2410. * Obtain the first parameter to a function.
  2411. *
  2412. * @see llvm::Function::arg_begin()
  2413. */
  2414. LLVMValueRef LLVMGetFirstParam(LLVMValueRef Fn);
  2415. /**
  2416. * Obtain the last parameter to a function.
  2417. *
  2418. * @see llvm::Function::arg_end()
  2419. */
  2420. LLVMValueRef LLVMGetLastParam(LLVMValueRef Fn);
  2421. /**
  2422. * Obtain the next parameter to a function.
  2423. *
  2424. * This takes an LLVMValueRef obtained from LLVMGetFirstParam() (which is
  2425. * actually a wrapped iterator) and obtains the next parameter from the
  2426. * underlying iterator.
  2427. */
  2428. LLVMValueRef LLVMGetNextParam(LLVMValueRef Arg);
  2429. /**
  2430. * Obtain the previous parameter to a function.
  2431. *
  2432. * This is the opposite of LLVMGetNextParam().
  2433. */
  2434. LLVMValueRef LLVMGetPreviousParam(LLVMValueRef Arg);
  2435. /**
  2436. * Set the alignment for a function parameter.
  2437. *
  2438. * @see llvm::Argument::addAttr()
  2439. * @see llvm::AttrBuilder::addAlignmentAttr()
  2440. */
  2441. void LLVMSetParamAlignment(LLVMValueRef Arg, unsigned Align);
  2442. /**
  2443. * @}
  2444. */
  2445. /**
  2446. * @defgroup LLVMCCoreValueGlobalIFunc IFuncs
  2447. *
  2448. * Functions in this group relate to indirect functions.
  2449. *
  2450. * Functions in this group expect LLVMValueRef instances that correspond
  2451. * to llvm::GlobalIFunc instances.
  2452. *
  2453. * @{
  2454. */
  2455. /**
  2456. * Add a global indirect function to a module under a specified name.
  2457. *
  2458. * @see llvm::GlobalIFunc::create()
  2459. */
  2460. LLVMValueRef LLVMAddGlobalIFunc(LLVMModuleRef M,
  2461. const char *Name, size_t NameLen,
  2462. LLVMTypeRef Ty, unsigned AddrSpace,
  2463. LLVMValueRef Resolver);
  2464. /**
  2465. * Obtain a GlobalIFunc value from a Module by its name.
  2466. *
  2467. * The returned value corresponds to a llvm::GlobalIFunc value.
  2468. *
  2469. * @see llvm::Module::getNamedIFunc()
  2470. */
  2471. LLVMValueRef LLVMGetNamedGlobalIFunc(LLVMModuleRef M,
  2472. const char *Name, size_t NameLen);
  2473. /**
  2474. * Obtain an iterator to the first GlobalIFunc in a Module.
  2475. *
  2476. * @see llvm::Module::ifunc_begin()
  2477. */
  2478. LLVMValueRef LLVMGetFirstGlobalIFunc(LLVMModuleRef M);
  2479. /**
  2480. * Obtain an iterator to the last GlobalIFunc in a Module.
  2481. *
  2482. * @see llvm::Module::ifunc_end()
  2483. */
  2484. LLVMValueRef LLVMGetLastGlobalIFunc(LLVMModuleRef M);
  2485. /**
  2486. * Advance a GlobalIFunc iterator to the next GlobalIFunc.
  2487. *
  2488. * Returns NULL if the iterator was already at the end and there are no more
  2489. * global aliases.
  2490. */
  2491. LLVMValueRef LLVMGetNextGlobalIFunc(LLVMValueRef IFunc);
  2492. /**
  2493. * Decrement a GlobalIFunc iterator to the previous GlobalIFunc.
  2494. *
  2495. * Returns NULL if the iterator was already at the beginning and there are
  2496. * no previous global aliases.
  2497. */
  2498. LLVMValueRef LLVMGetPreviousGlobalIFunc(LLVMValueRef IFunc);
  2499. /**
  2500. * Retrieves the resolver function associated with this indirect function, or
  2501. * NULL if it doesn't not exist.
  2502. *
  2503. * @see llvm::GlobalIFunc::getResolver()
  2504. */
  2505. LLVMValueRef LLVMGetGlobalIFuncResolver(LLVMValueRef IFunc);
  2506. /**
  2507. * Sets the resolver function associated with this indirect function.
  2508. *
  2509. * @see llvm::GlobalIFunc::setResolver()
  2510. */
  2511. void LLVMSetGlobalIFuncResolver(LLVMValueRef IFunc, LLVMValueRef Resolver);
  2512. /**
  2513. * Remove a global indirect function from its parent module and delete it.
  2514. *
  2515. * @see llvm::GlobalIFunc::eraseFromParent()
  2516. */
  2517. void LLVMEraseGlobalIFunc(LLVMValueRef IFunc);
  2518. /**
  2519. * Remove a global indirect function from its parent module.
  2520. *
  2521. * This unlinks the global indirect function from its containing module but
  2522. * keeps it alive.
  2523. *
  2524. * @see llvm::GlobalIFunc::removeFromParent()
  2525. */
  2526. void LLVMRemoveGlobalIFunc(LLVMValueRef IFunc);
  2527. /**
  2528. * @}
  2529. */
  2530. /**
  2531. * @}
  2532. */
  2533. /**
  2534. * @}
  2535. */
  2536. /**
  2537. * @}
  2538. */
  2539. /**
  2540. * @defgroup LLVMCCoreValueMetadata Metadata
  2541. *
  2542. * @{
  2543. */
  2544. /**
  2545. * Create an MDString value from a given string value.
  2546. *
  2547. * The MDString value does not take ownership of the given string, it remains
  2548. * the responsibility of the caller to free it.
  2549. *
  2550. * @see llvm::MDString::get()
  2551. */
  2552. LLVMMetadataRef LLVMMDStringInContext2(LLVMContextRef C, const char *Str,
  2553. size_t SLen);
  2554. /**
  2555. * Create an MDNode value with the given array of operands.
  2556. *
  2557. * @see llvm::MDNode::get()
  2558. */
  2559. LLVMMetadataRef LLVMMDNodeInContext2(LLVMContextRef C, LLVMMetadataRef *MDs,
  2560. size_t Count);
  2561. /**
  2562. * Obtain a Metadata as a Value.
  2563. */
  2564. LLVMValueRef LLVMMetadataAsValue(LLVMContextRef C, LLVMMetadataRef MD);
  2565. /**
  2566. * Obtain a Value as a Metadata.
  2567. */
  2568. LLVMMetadataRef LLVMValueAsMetadata(LLVMValueRef Val);
  2569. /**
  2570. * Obtain the underlying string from a MDString value.
  2571. *
  2572. * @param V Instance to obtain string from.
  2573. * @param Length Memory address which will hold length of returned string.
  2574. * @return String data in MDString.
  2575. */
  2576. const char *LLVMGetMDString(LLVMValueRef V, unsigned *Length);
  2577. /**
  2578. * Obtain the number of operands from an MDNode value.
  2579. *
  2580. * @param V MDNode to get number of operands from.
  2581. * @return Number of operands of the MDNode.
  2582. */
  2583. unsigned LLVMGetMDNodeNumOperands(LLVMValueRef V);
  2584. /**
  2585. * Obtain the given MDNode's operands.
  2586. *
  2587. * The passed LLVMValueRef pointer should point to enough memory to hold all of
  2588. * the operands of the given MDNode (see LLVMGetMDNodeNumOperands) as
  2589. * LLVMValueRefs. This memory will be populated with the LLVMValueRefs of the
  2590. * MDNode's operands.
  2591. *
  2592. * @param V MDNode to get the operands from.
  2593. * @param Dest Destination array for operands.
  2594. */
  2595. void LLVMGetMDNodeOperands(LLVMValueRef V, LLVMValueRef *Dest);
  2596. /** Deprecated: Use LLVMMDStringInContext2 instead. */
  2597. LLVMValueRef LLVMMDStringInContext(LLVMContextRef C, const char *Str,
  2598. unsigned SLen);
  2599. /** Deprecated: Use LLVMMDStringInContext2 instead. */
  2600. LLVMValueRef LLVMMDString(const char *Str, unsigned SLen);
  2601. /** Deprecated: Use LLVMMDNodeInContext2 instead. */
  2602. LLVMValueRef LLVMMDNodeInContext(LLVMContextRef C, LLVMValueRef *Vals,
  2603. unsigned Count);
  2604. /** Deprecated: Use LLVMMDNodeInContext2 instead. */
  2605. LLVMValueRef LLVMMDNode(LLVMValueRef *Vals, unsigned Count);
  2606. /**
  2607. * @}
  2608. */
  2609. /**
  2610. * @defgroup LLVMCCoreValueBasicBlock Basic Block
  2611. *
  2612. * A basic block represents a single entry single exit section of code.
  2613. * Basic blocks contain a list of instructions which form the body of
  2614. * the block.
  2615. *
  2616. * Basic blocks belong to functions. They have the type of label.
  2617. *
  2618. * Basic blocks are themselves values. However, the C API models them as
  2619. * LLVMBasicBlockRef.
  2620. *
  2621. * @see llvm::BasicBlock
  2622. *
  2623. * @{
  2624. */
  2625. /**
  2626. * Convert a basic block instance to a value type.
  2627. */
  2628. LLVMValueRef LLVMBasicBlockAsValue(LLVMBasicBlockRef BB);
  2629. /**
  2630. * Determine whether an LLVMValueRef is itself a basic block.
  2631. */
  2632. LLVMBool LLVMValueIsBasicBlock(LLVMValueRef Val);
  2633. /**
  2634. * Convert an LLVMValueRef to an LLVMBasicBlockRef instance.
  2635. */
  2636. LLVMBasicBlockRef LLVMValueAsBasicBlock(LLVMValueRef Val);
  2637. /**
  2638. * Obtain the string name of a basic block.
  2639. */
  2640. const char *LLVMGetBasicBlockName(LLVMBasicBlockRef BB);
  2641. /**
  2642. * Obtain the function to which a basic block belongs.
  2643. *
  2644. * @see llvm::BasicBlock::getParent()
  2645. */
  2646. LLVMValueRef LLVMGetBasicBlockParent(LLVMBasicBlockRef BB);
  2647. /**
  2648. * Obtain the terminator instruction for a basic block.
  2649. *
  2650. * If the basic block does not have a terminator (it is not well-formed
  2651. * if it doesn't), then NULL is returned.
  2652. *
  2653. * The returned LLVMValueRef corresponds to an llvm::Instruction.
  2654. *
  2655. * @see llvm::BasicBlock::getTerminator()
  2656. */
  2657. LLVMValueRef LLVMGetBasicBlockTerminator(LLVMBasicBlockRef BB);
  2658. /**
  2659. * Obtain the number of basic blocks in a function.
  2660. *
  2661. * @param Fn Function value to operate on.
  2662. */
  2663. unsigned LLVMCountBasicBlocks(LLVMValueRef Fn);
  2664. /**
  2665. * Obtain all of the basic blocks in a function.
  2666. *
  2667. * This operates on a function value. The BasicBlocks parameter is a
  2668. * pointer to a pre-allocated array of LLVMBasicBlockRef of at least
  2669. * LLVMCountBasicBlocks() in length. This array is populated with
  2670. * LLVMBasicBlockRef instances.
  2671. */
  2672. void LLVMGetBasicBlocks(LLVMValueRef Fn, LLVMBasicBlockRef *BasicBlocks);
  2673. /**
  2674. * Obtain the first basic block in a function.
  2675. *
  2676. * The returned basic block can be used as an iterator. You will likely
  2677. * eventually call into LLVMGetNextBasicBlock() with it.
  2678. *
  2679. * @see llvm::Function::begin()
  2680. */
  2681. LLVMBasicBlockRef LLVMGetFirstBasicBlock(LLVMValueRef Fn);
  2682. /**
  2683. * Obtain the last basic block in a function.
  2684. *
  2685. * @see llvm::Function::end()
  2686. */
  2687. LLVMBasicBlockRef LLVMGetLastBasicBlock(LLVMValueRef Fn);
  2688. /**
  2689. * Advance a basic block iterator.
  2690. */
  2691. LLVMBasicBlockRef LLVMGetNextBasicBlock(LLVMBasicBlockRef BB);
  2692. /**
  2693. * Go backwards in a basic block iterator.
  2694. */
  2695. LLVMBasicBlockRef LLVMGetPreviousBasicBlock(LLVMBasicBlockRef BB);
  2696. /**
  2697. * Obtain the basic block that corresponds to the entry point of a
  2698. * function.
  2699. *
  2700. * @see llvm::Function::getEntryBlock()
  2701. */
  2702. LLVMBasicBlockRef LLVMGetEntryBasicBlock(LLVMValueRef Fn);
  2703. /**
  2704. * Insert the given basic block after the insertion point of the given builder.
  2705. *
  2706. * The insertion point must be valid.
  2707. *
  2708. * @see llvm::Function::BasicBlockListType::insertAfter()
  2709. */
  2710. void LLVMInsertExistingBasicBlockAfterInsertBlock(LLVMBuilderRef Builder,
  2711. LLVMBasicBlockRef BB);
  2712. /**
  2713. * Append the given basic block to the basic block list of the given function.
  2714. *
  2715. * @see llvm::Function::BasicBlockListType::push_back()
  2716. */
  2717. void LLVMAppendExistingBasicBlock(LLVMValueRef Fn,
  2718. LLVMBasicBlockRef BB);
  2719. /**
  2720. * Create a new basic block without inserting it into a function.
  2721. *
  2722. * @see llvm::BasicBlock::Create()
  2723. */
  2724. LLVMBasicBlockRef LLVMCreateBasicBlockInContext(LLVMContextRef C,
  2725. const char *Name);
  2726. /**
  2727. * Append a basic block to the end of a function.
  2728. *
  2729. * @see llvm::BasicBlock::Create()
  2730. */
  2731. LLVMBasicBlockRef LLVMAppendBasicBlockInContext(LLVMContextRef C,
  2732. LLVMValueRef Fn,
  2733. const char *Name);
  2734. /**
  2735. * Append a basic block to the end of a function using the global
  2736. * context.
  2737. *
  2738. * @see llvm::BasicBlock::Create()
  2739. */
  2740. LLVMBasicBlockRef LLVMAppendBasicBlock(LLVMValueRef Fn, const char *Name);
  2741. /**
  2742. * Insert a basic block in a function before another basic block.
  2743. *
  2744. * The function to add to is determined by the function of the
  2745. * passed basic block.
  2746. *
  2747. * @see llvm::BasicBlock::Create()
  2748. */
  2749. LLVMBasicBlockRef LLVMInsertBasicBlockInContext(LLVMContextRef C,
  2750. LLVMBasicBlockRef BB,
  2751. const char *Name);
  2752. /**
  2753. * Insert a basic block in a function using the global context.
  2754. *
  2755. * @see llvm::BasicBlock::Create()
  2756. */
  2757. LLVMBasicBlockRef LLVMInsertBasicBlock(LLVMBasicBlockRef InsertBeforeBB,
  2758. const char *Name);
  2759. /**
  2760. * Remove a basic block from a function and delete it.
  2761. *
  2762. * This deletes the basic block from its containing function and deletes
  2763. * the basic block itself.
  2764. *
  2765. * @see llvm::BasicBlock::eraseFromParent()
  2766. */
  2767. void LLVMDeleteBasicBlock(LLVMBasicBlockRef BB);
  2768. /**
  2769. * Remove a basic block from a function.
  2770. *
  2771. * This deletes the basic block from its containing function but keep
  2772. * the basic block alive.
  2773. *
  2774. * @see llvm::BasicBlock::removeFromParent()
  2775. */
  2776. void LLVMRemoveBasicBlockFromParent(LLVMBasicBlockRef BB);
  2777. /**
  2778. * Move a basic block to before another one.
  2779. *
  2780. * @see llvm::BasicBlock::moveBefore()
  2781. */
  2782. void LLVMMoveBasicBlockBefore(LLVMBasicBlockRef BB, LLVMBasicBlockRef MovePos);
  2783. /**
  2784. * Move a basic block to after another one.
  2785. *
  2786. * @see llvm::BasicBlock::moveAfter()
  2787. */
  2788. void LLVMMoveBasicBlockAfter(LLVMBasicBlockRef BB, LLVMBasicBlockRef MovePos);
  2789. /**
  2790. * Obtain the first instruction in a basic block.
  2791. *
  2792. * The returned LLVMValueRef corresponds to a llvm::Instruction
  2793. * instance.
  2794. */
  2795. LLVMValueRef LLVMGetFirstInstruction(LLVMBasicBlockRef BB);
  2796. /**
  2797. * Obtain the last instruction in a basic block.
  2798. *
  2799. * The returned LLVMValueRef corresponds to an LLVM:Instruction.
  2800. */
  2801. LLVMValueRef LLVMGetLastInstruction(LLVMBasicBlockRef BB);
  2802. /**
  2803. * @}
  2804. */
  2805. /**
  2806. * @defgroup LLVMCCoreValueInstruction Instructions
  2807. *
  2808. * Functions in this group relate to the inspection and manipulation of
  2809. * individual instructions.
  2810. *
  2811. * In the C++ API, an instruction is modeled by llvm::Instruction. This
  2812. * class has a large number of descendents. llvm::Instruction is a
  2813. * llvm::Value and in the C API, instructions are modeled by
  2814. * LLVMValueRef.
  2815. *
  2816. * This group also contains sub-groups which operate on specific
  2817. * llvm::Instruction types, e.g. llvm::CallInst.
  2818. *
  2819. * @{
  2820. */
  2821. /**
  2822. * Determine whether an instruction has any metadata attached.
  2823. */
  2824. int LLVMHasMetadata(LLVMValueRef Val);
  2825. /**
  2826. * Return metadata associated with an instruction value.
  2827. */
  2828. LLVMValueRef LLVMGetMetadata(LLVMValueRef Val, unsigned KindID);
  2829. /**
  2830. * Set metadata associated with an instruction value.
  2831. */
  2832. void LLVMSetMetadata(LLVMValueRef Val, unsigned KindID, LLVMValueRef Node);
  2833. /**
  2834. * Returns the metadata associated with an instruction value, but filters out
  2835. * all the debug locations.
  2836. *
  2837. * @see llvm::Instruction::getAllMetadataOtherThanDebugLoc()
  2838. */
  2839. LLVMValueMetadataEntry *
  2840. LLVMInstructionGetAllMetadataOtherThanDebugLoc(LLVMValueRef Instr,
  2841. size_t *NumEntries);
  2842. /**
  2843. * Obtain the basic block to which an instruction belongs.
  2844. *
  2845. * @see llvm::Instruction::getParent()
  2846. */
  2847. LLVMBasicBlockRef LLVMGetInstructionParent(LLVMValueRef Inst);
  2848. /**
  2849. * Obtain the instruction that occurs after the one specified.
  2850. *
  2851. * The next instruction will be from the same basic block.
  2852. *
  2853. * If this is the last instruction in a basic block, NULL will be
  2854. * returned.
  2855. */
  2856. LLVMValueRef LLVMGetNextInstruction(LLVMValueRef Inst);
  2857. /**
  2858. * Obtain the instruction that occurred before this one.
  2859. *
  2860. * If the instruction is the first instruction in a basic block, NULL
  2861. * will be returned.
  2862. */
  2863. LLVMValueRef LLVMGetPreviousInstruction(LLVMValueRef Inst);
  2864. /**
  2865. * Remove an instruction.
  2866. *
  2867. * The instruction specified is removed from its containing building
  2868. * block but is kept alive.
  2869. *
  2870. * @see llvm::Instruction::removeFromParent()
  2871. */
  2872. void LLVMInstructionRemoveFromParent(LLVMValueRef Inst);
  2873. /**
  2874. * Remove and delete an instruction.
  2875. *
  2876. * The instruction specified is removed from its containing building
  2877. * block and then deleted.
  2878. *
  2879. * @see llvm::Instruction::eraseFromParent()
  2880. */
  2881. void LLVMInstructionEraseFromParent(LLVMValueRef Inst);
  2882. /**
  2883. * Delete an instruction.
  2884. *
  2885. * The instruction specified is deleted. It must have previously been
  2886. * removed from its containing building block.
  2887. *
  2888. * @see llvm::Value::deleteValue()
  2889. */
  2890. void LLVMDeleteInstruction(LLVMValueRef Inst);
  2891. /**
  2892. * Obtain the code opcode for an individual instruction.
  2893. *
  2894. * @see llvm::Instruction::getOpCode()
  2895. */
  2896. LLVMOpcode LLVMGetInstructionOpcode(LLVMValueRef Inst);
  2897. /**
  2898. * Obtain the predicate of an instruction.
  2899. *
  2900. * This is only valid for instructions that correspond to llvm::ICmpInst
  2901. * or llvm::ConstantExpr whose opcode is llvm::Instruction::ICmp.
  2902. *
  2903. * @see llvm::ICmpInst::getPredicate()
  2904. */
  2905. LLVMIntPredicate LLVMGetICmpPredicate(LLVMValueRef Inst);
  2906. /**
  2907. * Obtain the float predicate of an instruction.
  2908. *
  2909. * This is only valid for instructions that correspond to llvm::FCmpInst
  2910. * or llvm::ConstantExpr whose opcode is llvm::Instruction::FCmp.
  2911. *
  2912. * @see llvm::FCmpInst::getPredicate()
  2913. */
  2914. LLVMRealPredicate LLVMGetFCmpPredicate(LLVMValueRef Inst);
  2915. /**
  2916. * Create a copy of 'this' instruction that is identical in all ways
  2917. * except the following:
  2918. * * The instruction has no parent
  2919. * * The instruction has no name
  2920. *
  2921. * @see llvm::Instruction::clone()
  2922. */
  2923. LLVMValueRef LLVMInstructionClone(LLVMValueRef Inst);
  2924. /**
  2925. * Determine whether an instruction is a terminator. This routine is named to
  2926. * be compatible with historical functions that did this by querying the
  2927. * underlying C++ type.
  2928. *
  2929. * @see llvm::Instruction::isTerminator()
  2930. */
  2931. LLVMValueRef LLVMIsATerminatorInst(LLVMValueRef Inst);
  2932. /**
  2933. * @defgroup LLVMCCoreValueInstructionCall Call Sites and Invocations
  2934. *
  2935. * Functions in this group apply to instructions that refer to call
  2936. * sites and invocations. These correspond to C++ types in the
  2937. * llvm::CallInst class tree.
  2938. *
  2939. * @{
  2940. */
  2941. /**
  2942. * Obtain the argument count for a call instruction.
  2943. *
  2944. * This expects an LLVMValueRef that corresponds to a llvm::CallInst,
  2945. * llvm::InvokeInst, or llvm:FuncletPadInst.
  2946. *
  2947. * @see llvm::CallInst::getNumArgOperands()
  2948. * @see llvm::InvokeInst::getNumArgOperands()
  2949. * @see llvm::FuncletPadInst::getNumArgOperands()
  2950. */
  2951. unsigned LLVMGetNumArgOperands(LLVMValueRef Instr);
  2952. /**
  2953. * Set the calling convention for a call instruction.
  2954. *
  2955. * This expects an LLVMValueRef that corresponds to a llvm::CallInst or
  2956. * llvm::InvokeInst.
  2957. *
  2958. * @see llvm::CallInst::setCallingConv()
  2959. * @see llvm::InvokeInst::setCallingConv()
  2960. */
  2961. void LLVMSetInstructionCallConv(LLVMValueRef Instr, unsigned CC);
  2962. /**
  2963. * Obtain the calling convention for a call instruction.
  2964. *
  2965. * This is the opposite of LLVMSetInstructionCallConv(). Reads its
  2966. * usage.
  2967. *
  2968. * @see LLVMSetInstructionCallConv()
  2969. */
  2970. unsigned LLVMGetInstructionCallConv(LLVMValueRef Instr);
  2971. void LLVMSetInstrParamAlignment(LLVMValueRef Instr, LLVMAttributeIndex Idx,
  2972. unsigned Align);
  2973. void LLVMAddCallSiteAttribute(LLVMValueRef C, LLVMAttributeIndex Idx,
  2974. LLVMAttributeRef A);
  2975. unsigned LLVMGetCallSiteAttributeCount(LLVMValueRef C, LLVMAttributeIndex Idx);
  2976. void LLVMGetCallSiteAttributes(LLVMValueRef C, LLVMAttributeIndex Idx,
  2977. LLVMAttributeRef *Attrs);
  2978. LLVMAttributeRef LLVMGetCallSiteEnumAttribute(LLVMValueRef C,
  2979. LLVMAttributeIndex Idx,
  2980. unsigned KindID);
  2981. LLVMAttributeRef LLVMGetCallSiteStringAttribute(LLVMValueRef C,
  2982. LLVMAttributeIndex Idx,
  2983. const char *K, unsigned KLen);
  2984. void LLVMRemoveCallSiteEnumAttribute(LLVMValueRef C, LLVMAttributeIndex Idx,
  2985. unsigned KindID);
  2986. void LLVMRemoveCallSiteStringAttribute(LLVMValueRef C, LLVMAttributeIndex Idx,
  2987. const char *K, unsigned KLen);
  2988. /**
  2989. * Obtain the function type called by this instruction.
  2990. *
  2991. * @see llvm::CallBase::getFunctionType()
  2992. */
  2993. LLVMTypeRef LLVMGetCalledFunctionType(LLVMValueRef C);
  2994. /**
  2995. * Obtain the pointer to the function invoked by this instruction.
  2996. *
  2997. * This expects an LLVMValueRef that corresponds to a llvm::CallInst or
  2998. * llvm::InvokeInst.
  2999. *
  3000. * @see llvm::CallInst::getCalledOperand()
  3001. * @see llvm::InvokeInst::getCalledOperand()
  3002. */
  3003. LLVMValueRef LLVMGetCalledValue(LLVMValueRef Instr);
  3004. /**
  3005. * Obtain whether a call instruction is a tail call.
  3006. *
  3007. * This only works on llvm::CallInst instructions.
  3008. *
  3009. * @see llvm::CallInst::isTailCall()
  3010. */
  3011. LLVMBool LLVMIsTailCall(LLVMValueRef CallInst);
  3012. /**
  3013. * Set whether a call instruction is a tail call.
  3014. *
  3015. * This only works on llvm::CallInst instructions.
  3016. *
  3017. * @see llvm::CallInst::setTailCall()
  3018. */
  3019. void LLVMSetTailCall(LLVMValueRef CallInst, LLVMBool IsTailCall);
  3020. /**
  3021. * Return the normal destination basic block.
  3022. *
  3023. * This only works on llvm::InvokeInst instructions.
  3024. *
  3025. * @see llvm::InvokeInst::getNormalDest()
  3026. */
  3027. LLVMBasicBlockRef LLVMGetNormalDest(LLVMValueRef InvokeInst);
  3028. /**
  3029. * Return the unwind destination basic block.
  3030. *
  3031. * Works on llvm::InvokeInst, llvm::CleanupReturnInst, and
  3032. * llvm::CatchSwitchInst instructions.
  3033. *
  3034. * @see llvm::InvokeInst::getUnwindDest()
  3035. * @see llvm::CleanupReturnInst::getUnwindDest()
  3036. * @see llvm::CatchSwitchInst::getUnwindDest()
  3037. */
  3038. LLVMBasicBlockRef LLVMGetUnwindDest(LLVMValueRef InvokeInst);
  3039. /**
  3040. * Set the normal destination basic block.
  3041. *
  3042. * This only works on llvm::InvokeInst instructions.
  3043. *
  3044. * @see llvm::InvokeInst::setNormalDest()
  3045. */
  3046. void LLVMSetNormalDest(LLVMValueRef InvokeInst, LLVMBasicBlockRef B);
  3047. /**
  3048. * Set the unwind destination basic block.
  3049. *
  3050. * Works on llvm::InvokeInst, llvm::CleanupReturnInst, and
  3051. * llvm::CatchSwitchInst instructions.
  3052. *
  3053. * @see llvm::InvokeInst::setUnwindDest()
  3054. * @see llvm::CleanupReturnInst::setUnwindDest()
  3055. * @see llvm::CatchSwitchInst::setUnwindDest()
  3056. */
  3057. void LLVMSetUnwindDest(LLVMValueRef InvokeInst, LLVMBasicBlockRef B);
  3058. /**
  3059. * @}
  3060. */
  3061. /**
  3062. * @defgroup LLVMCCoreValueInstructionTerminator Terminators
  3063. *
  3064. * Functions in this group only apply to instructions for which
  3065. * LLVMIsATerminatorInst returns true.
  3066. *
  3067. * @{
  3068. */
  3069. /**
  3070. * Return the number of successors that this terminator has.
  3071. *
  3072. * @see llvm::Instruction::getNumSuccessors
  3073. */
  3074. unsigned LLVMGetNumSuccessors(LLVMValueRef Term);
  3075. /**
  3076. * Return the specified successor.
  3077. *
  3078. * @see llvm::Instruction::getSuccessor
  3079. */
  3080. LLVMBasicBlockRef LLVMGetSuccessor(LLVMValueRef Term, unsigned i);
  3081. /**
  3082. * Update the specified successor to point at the provided block.
  3083. *
  3084. * @see llvm::Instruction::setSuccessor
  3085. */
  3086. void LLVMSetSuccessor(LLVMValueRef Term, unsigned i, LLVMBasicBlockRef block);
  3087. /**
  3088. * Return if a branch is conditional.
  3089. *
  3090. * This only works on llvm::BranchInst instructions.
  3091. *
  3092. * @see llvm::BranchInst::isConditional
  3093. */
  3094. LLVMBool LLVMIsConditional(LLVMValueRef Branch);
  3095. /**
  3096. * Return the condition of a branch instruction.
  3097. *
  3098. * This only works on llvm::BranchInst instructions.
  3099. *
  3100. * @see llvm::BranchInst::getCondition
  3101. */
  3102. LLVMValueRef LLVMGetCondition(LLVMValueRef Branch);
  3103. /**
  3104. * Set the condition of a branch instruction.
  3105. *
  3106. * This only works on llvm::BranchInst instructions.
  3107. *
  3108. * @see llvm::BranchInst::setCondition
  3109. */
  3110. void LLVMSetCondition(LLVMValueRef Branch, LLVMValueRef Cond);
  3111. /**
  3112. * Obtain the default destination basic block of a switch instruction.
  3113. *
  3114. * This only works on llvm::SwitchInst instructions.
  3115. *
  3116. * @see llvm::SwitchInst::getDefaultDest()
  3117. */
  3118. LLVMBasicBlockRef LLVMGetSwitchDefaultDest(LLVMValueRef SwitchInstr);
  3119. /**
  3120. * @}
  3121. */
  3122. /**
  3123. * @defgroup LLVMCCoreValueInstructionAlloca Allocas
  3124. *
  3125. * Functions in this group only apply to instructions that map to
  3126. * llvm::AllocaInst instances.
  3127. *
  3128. * @{
  3129. */
  3130. /**
  3131. * Obtain the type that is being allocated by the alloca instruction.
  3132. */
  3133. LLVMTypeRef LLVMGetAllocatedType(LLVMValueRef Alloca);
  3134. /**
  3135. * @}
  3136. */
  3137. /**
  3138. * @defgroup LLVMCCoreValueInstructionGetElementPointer GEPs
  3139. *
  3140. * Functions in this group only apply to instructions that map to
  3141. * llvm::GetElementPtrInst instances.
  3142. *
  3143. * @{
  3144. */
  3145. /**
  3146. * Check whether the given GEP operator is inbounds.
  3147. */
  3148. LLVMBool LLVMIsInBounds(LLVMValueRef GEP);
  3149. /**
  3150. * Set the given GEP instruction to be inbounds or not.
  3151. */
  3152. void LLVMSetIsInBounds(LLVMValueRef GEP, LLVMBool InBounds);
  3153. /**
  3154. * Get the source element type of the given GEP operator.
  3155. */
  3156. LLVMTypeRef LLVMGetGEPSourceElementType(LLVMValueRef GEP);
  3157. /**
  3158. * @}
  3159. */
  3160. /**
  3161. * @defgroup LLVMCCoreValueInstructionPHINode PHI Nodes
  3162. *
  3163. * Functions in this group only apply to instructions that map to
  3164. * llvm::PHINode instances.
  3165. *
  3166. * @{
  3167. */
  3168. /**
  3169. * Add an incoming value to the end of a PHI list.
  3170. */
  3171. void LLVMAddIncoming(LLVMValueRef PhiNode, LLVMValueRef *IncomingValues,
  3172. LLVMBasicBlockRef *IncomingBlocks, unsigned Count);
  3173. /**
  3174. * Obtain the number of incoming basic blocks to a PHI node.
  3175. */
  3176. unsigned LLVMCountIncoming(LLVMValueRef PhiNode);
  3177. /**
  3178. * Obtain an incoming value to a PHI node as an LLVMValueRef.
  3179. */
  3180. LLVMValueRef LLVMGetIncomingValue(LLVMValueRef PhiNode, unsigned Index);
  3181. /**
  3182. * Obtain an incoming value to a PHI node as an LLVMBasicBlockRef.
  3183. */
  3184. LLVMBasicBlockRef LLVMGetIncomingBlock(LLVMValueRef PhiNode, unsigned Index);
  3185. /**
  3186. * @}
  3187. */
  3188. /**
  3189. * @defgroup LLVMCCoreValueInstructionExtractValue ExtractValue
  3190. * @defgroup LLVMCCoreValueInstructionInsertValue InsertValue
  3191. *
  3192. * Functions in this group only apply to instructions that map to
  3193. * llvm::ExtractValue and llvm::InsertValue instances.
  3194. *
  3195. * @{
  3196. */
  3197. /**
  3198. * Obtain the number of indices.
  3199. * NB: This also works on GEP operators.
  3200. */
  3201. unsigned LLVMGetNumIndices(LLVMValueRef Inst);
  3202. /**
  3203. * Obtain the indices as an array.
  3204. */
  3205. const unsigned *LLVMGetIndices(LLVMValueRef Inst);
  3206. /**
  3207. * @}
  3208. */
  3209. /**
  3210. * @}
  3211. */
  3212. /**
  3213. * @}
  3214. */
  3215. /**
  3216. * @defgroup LLVMCCoreInstructionBuilder Instruction Builders
  3217. *
  3218. * An instruction builder represents a point within a basic block and is
  3219. * the exclusive means of building instructions using the C interface.
  3220. *
  3221. * @{
  3222. */
  3223. LLVMBuilderRef LLVMCreateBuilderInContext(LLVMContextRef C);
  3224. LLVMBuilderRef LLVMCreateBuilder(void);
  3225. void LLVMPositionBuilder(LLVMBuilderRef Builder, LLVMBasicBlockRef Block,
  3226. LLVMValueRef Instr);
  3227. void LLVMPositionBuilderBefore(LLVMBuilderRef Builder, LLVMValueRef Instr);
  3228. void LLVMPositionBuilderAtEnd(LLVMBuilderRef Builder, LLVMBasicBlockRef Block);
  3229. LLVMBasicBlockRef LLVMGetInsertBlock(LLVMBuilderRef Builder);
  3230. void LLVMClearInsertionPosition(LLVMBuilderRef Builder);
  3231. void LLVMInsertIntoBuilder(LLVMBuilderRef Builder, LLVMValueRef Instr);
  3232. void LLVMInsertIntoBuilderWithName(LLVMBuilderRef Builder, LLVMValueRef Instr,
  3233. const char *Name);
  3234. void LLVMDisposeBuilder(LLVMBuilderRef Builder);
  3235. /* Metadata */
  3236. /**
  3237. * Get location information used by debugging information.
  3238. *
  3239. * @see llvm::IRBuilder::getCurrentDebugLocation()
  3240. */
  3241. LLVMMetadataRef LLVMGetCurrentDebugLocation2(LLVMBuilderRef Builder);
  3242. /**
  3243. * Set location information used by debugging information.
  3244. *
  3245. * To clear the location metadata of the given instruction, pass NULL to \p Loc.
  3246. *
  3247. * @see llvm::IRBuilder::SetCurrentDebugLocation()
  3248. */
  3249. void LLVMSetCurrentDebugLocation2(LLVMBuilderRef Builder, LLVMMetadataRef Loc);
  3250. /**
  3251. * Attempts to set the debug location for the given instruction using the
  3252. * current debug location for the given builder. If the builder has no current
  3253. * debug location, this function is a no-op.
  3254. *
  3255. * @deprecated LLVMSetInstDebugLocation is deprecated in favor of the more general
  3256. * LLVMAddMetadataToInst.
  3257. *
  3258. * @see llvm::IRBuilder::SetInstDebugLocation()
  3259. */
  3260. void LLVMSetInstDebugLocation(LLVMBuilderRef Builder, LLVMValueRef Inst);
  3261. /**
  3262. * Adds the metadata registered with the given builder to the given instruction.
  3263. *
  3264. * @see llvm::IRBuilder::AddMetadataToInst()
  3265. */
  3266. void LLVMAddMetadataToInst(LLVMBuilderRef Builder, LLVMValueRef Inst);
  3267. /**
  3268. * Get the dafult floating-point math metadata for a given builder.
  3269. *
  3270. * @see llvm::IRBuilder::getDefaultFPMathTag()
  3271. */
  3272. LLVMMetadataRef LLVMBuilderGetDefaultFPMathTag(LLVMBuilderRef Builder);
  3273. /**
  3274. * Set the default floating-point math metadata for the given builder.
  3275. *
  3276. * To clear the metadata, pass NULL to \p FPMathTag.
  3277. *
  3278. * @see llvm::IRBuilder::setDefaultFPMathTag()
  3279. */
  3280. void LLVMBuilderSetDefaultFPMathTag(LLVMBuilderRef Builder,
  3281. LLVMMetadataRef FPMathTag);
  3282. /**
  3283. * Deprecated: Passing the NULL location will crash.
  3284. * Use LLVMGetCurrentDebugLocation2 instead.
  3285. */
  3286. void LLVMSetCurrentDebugLocation(LLVMBuilderRef Builder, LLVMValueRef L);
  3287. /**
  3288. * Deprecated: Returning the NULL location will crash.
  3289. * Use LLVMGetCurrentDebugLocation2 instead.
  3290. */
  3291. LLVMValueRef LLVMGetCurrentDebugLocation(LLVMBuilderRef Builder);
  3292. /* Terminators */
  3293. LLVMValueRef LLVMBuildRetVoid(LLVMBuilderRef);
  3294. LLVMValueRef LLVMBuildRet(LLVMBuilderRef, LLVMValueRef V);
  3295. LLVMValueRef LLVMBuildAggregateRet(LLVMBuilderRef, LLVMValueRef *RetVals,
  3296. unsigned N);
  3297. LLVMValueRef LLVMBuildBr(LLVMBuilderRef, LLVMBasicBlockRef Dest);
  3298. LLVMValueRef LLVMBuildCondBr(LLVMBuilderRef, LLVMValueRef If,
  3299. LLVMBasicBlockRef Then, LLVMBasicBlockRef Else);
  3300. LLVMValueRef LLVMBuildSwitch(LLVMBuilderRef, LLVMValueRef V,
  3301. LLVMBasicBlockRef Else, unsigned NumCases);
  3302. LLVMValueRef LLVMBuildIndirectBr(LLVMBuilderRef B, LLVMValueRef Addr,
  3303. unsigned NumDests);
  3304. LLVMValueRef LLVMBuildInvoke2(LLVMBuilderRef, LLVMTypeRef Ty, LLVMValueRef Fn,
  3305. LLVMValueRef *Args, unsigned NumArgs,
  3306. LLVMBasicBlockRef Then, LLVMBasicBlockRef Catch,
  3307. const char *Name);
  3308. LLVMValueRef LLVMBuildUnreachable(LLVMBuilderRef);
  3309. /* Exception Handling */
  3310. LLVMValueRef LLVMBuildResume(LLVMBuilderRef B, LLVMValueRef Exn);
  3311. LLVMValueRef LLVMBuildLandingPad(LLVMBuilderRef B, LLVMTypeRef Ty,
  3312. LLVMValueRef PersFn, unsigned NumClauses,
  3313. const char *Name);
  3314. LLVMValueRef LLVMBuildCleanupRet(LLVMBuilderRef B, LLVMValueRef CatchPad,
  3315. LLVMBasicBlockRef BB);
  3316. LLVMValueRef LLVMBuildCatchRet(LLVMBuilderRef B, LLVMValueRef CatchPad,
  3317. LLVMBasicBlockRef BB);
  3318. LLVMValueRef LLVMBuildCatchPad(LLVMBuilderRef B, LLVMValueRef ParentPad,
  3319. LLVMValueRef *Args, unsigned NumArgs,
  3320. const char *Name);
  3321. LLVMValueRef LLVMBuildCleanupPad(LLVMBuilderRef B, LLVMValueRef ParentPad,
  3322. LLVMValueRef *Args, unsigned NumArgs,
  3323. const char *Name);
  3324. LLVMValueRef LLVMBuildCatchSwitch(LLVMBuilderRef B, LLVMValueRef ParentPad,
  3325. LLVMBasicBlockRef UnwindBB,
  3326. unsigned NumHandlers, const char *Name);
  3327. /* Add a case to the switch instruction */
  3328. void LLVMAddCase(LLVMValueRef Switch, LLVMValueRef OnVal,
  3329. LLVMBasicBlockRef Dest);
  3330. /* Add a destination to the indirectbr instruction */
  3331. void LLVMAddDestination(LLVMValueRef IndirectBr, LLVMBasicBlockRef Dest);
  3332. /* Get the number of clauses on the landingpad instruction */
  3333. unsigned LLVMGetNumClauses(LLVMValueRef LandingPad);
  3334. /* Get the value of the clause at index Idx on the landingpad instruction */
  3335. LLVMValueRef LLVMGetClause(LLVMValueRef LandingPad, unsigned Idx);
  3336. /* Add a catch or filter clause to the landingpad instruction */
  3337. void LLVMAddClause(LLVMValueRef LandingPad, LLVMValueRef ClauseVal);
  3338. /* Get the 'cleanup' flag in the landingpad instruction */
  3339. LLVMBool LLVMIsCleanup(LLVMValueRef LandingPad);
  3340. /* Set the 'cleanup' flag in the landingpad instruction */
  3341. void LLVMSetCleanup(LLVMValueRef LandingPad, LLVMBool Val);
  3342. /* Add a destination to the catchswitch instruction */
  3343. void LLVMAddHandler(LLVMValueRef CatchSwitch, LLVMBasicBlockRef Dest);
  3344. /* Get the number of handlers on the catchswitch instruction */
  3345. unsigned LLVMGetNumHandlers(LLVMValueRef CatchSwitch);
  3346. /**
  3347. * Obtain the basic blocks acting as handlers for a catchswitch instruction.
  3348. *
  3349. * The Handlers parameter should point to a pre-allocated array of
  3350. * LLVMBasicBlockRefs at least LLVMGetNumHandlers() large. On return, the
  3351. * first LLVMGetNumHandlers() entries in the array will be populated
  3352. * with LLVMBasicBlockRef instances.
  3353. *
  3354. * @param CatchSwitch The catchswitch instruction to operate on.
  3355. * @param Handlers Memory address of an array to be filled with basic blocks.
  3356. */
  3357. void LLVMGetHandlers(LLVMValueRef CatchSwitch, LLVMBasicBlockRef *Handlers);
  3358. /* Funclets */
  3359. /* Get the number of funcletpad arguments. */
  3360. LLVMValueRef LLVMGetArgOperand(LLVMValueRef Funclet, unsigned i);
  3361. /* Set a funcletpad argument at the given index. */
  3362. void LLVMSetArgOperand(LLVMValueRef Funclet, unsigned i, LLVMValueRef value);
  3363. /**
  3364. * Get the parent catchswitch instruction of a catchpad instruction.
  3365. *
  3366. * This only works on llvm::CatchPadInst instructions.
  3367. *
  3368. * @see llvm::CatchPadInst::getCatchSwitch()
  3369. */
  3370. LLVMValueRef LLVMGetParentCatchSwitch(LLVMValueRef CatchPad);
  3371. /**
  3372. * Set the parent catchswitch instruction of a catchpad instruction.
  3373. *
  3374. * This only works on llvm::CatchPadInst instructions.
  3375. *
  3376. * @see llvm::CatchPadInst::setCatchSwitch()
  3377. */
  3378. void LLVMSetParentCatchSwitch(LLVMValueRef CatchPad, LLVMValueRef CatchSwitch);
  3379. /* Arithmetic */
  3380. LLVMValueRef LLVMBuildAdd(LLVMBuilderRef, LLVMValueRef LHS, LLVMValueRef RHS,
  3381. const char *Name);
  3382. LLVMValueRef LLVMBuildNSWAdd(LLVMBuilderRef, LLVMValueRef LHS, LLVMValueRef RHS,
  3383. const char *Name);
  3384. LLVMValueRef LLVMBuildNUWAdd(LLVMBuilderRef, LLVMValueRef LHS, LLVMValueRef RHS,
  3385. const char *Name);
  3386. LLVMValueRef LLVMBuildFAdd(LLVMBuilderRef, LLVMValueRef LHS, LLVMValueRef RHS,
  3387. const char *Name);
  3388. LLVMValueRef LLVMBuildSub(LLVMBuilderRef, LLVMValueRef LHS, LLVMValueRef RHS,
  3389. const char *Name);
  3390. LLVMValueRef LLVMBuildNSWSub(LLVMBuilderRef, LLVMValueRef LHS, LLVMValueRef RHS,
  3391. const char *Name);
  3392. LLVMValueRef LLVMBuildNUWSub(LLVMBuilderRef, LLVMValueRef LHS, LLVMValueRef RHS,
  3393. const char *Name);
  3394. LLVMValueRef LLVMBuildFSub(LLVMBuilderRef, LLVMValueRef LHS, LLVMValueRef RHS,
  3395. const char *Name);
  3396. LLVMValueRef LLVMBuildMul(LLVMBuilderRef, LLVMValueRef LHS, LLVMValueRef RHS,
  3397. const char *Name);
  3398. LLVMValueRef LLVMBuildNSWMul(LLVMBuilderRef, LLVMValueRef LHS, LLVMValueRef RHS,
  3399. const char *Name);
  3400. LLVMValueRef LLVMBuildNUWMul(LLVMBuilderRef, LLVMValueRef LHS, LLVMValueRef RHS,
  3401. const char *Name);
  3402. LLVMValueRef LLVMBuildFMul(LLVMBuilderRef, LLVMValueRef LHS, LLVMValueRef RHS,
  3403. const char *Name);
  3404. LLVMValueRef LLVMBuildUDiv(LLVMBuilderRef, LLVMValueRef LHS, LLVMValueRef RHS,
  3405. const char *Name);
  3406. LLVMValueRef LLVMBuildExactUDiv(LLVMBuilderRef, LLVMValueRef LHS, LLVMValueRef RHS,
  3407. const char *Name);
  3408. LLVMValueRef LLVMBuildSDiv(LLVMBuilderRef, LLVMValueRef LHS, LLVMValueRef RHS,
  3409. const char *Name);
  3410. LLVMValueRef LLVMBuildExactSDiv(LLVMBuilderRef, LLVMValueRef LHS, LLVMValueRef RHS,
  3411. const char *Name);
  3412. LLVMValueRef LLVMBuildFDiv(LLVMBuilderRef, LLVMValueRef LHS, LLVMValueRef RHS,
  3413. const char *Name);
  3414. LLVMValueRef LLVMBuildURem(LLVMBuilderRef, LLVMValueRef LHS, LLVMValueRef RHS,
  3415. const char *Name);
  3416. LLVMValueRef LLVMBuildSRem(LLVMBuilderRef, LLVMValueRef LHS, LLVMValueRef RHS,
  3417. const char *Name);
  3418. LLVMValueRef LLVMBuildFRem(LLVMBuilderRef, LLVMValueRef LHS, LLVMValueRef RHS,
  3419. const char *Name);
  3420. LLVMValueRef LLVMBuildShl(LLVMBuilderRef, LLVMValueRef LHS, LLVMValueRef RHS,
  3421. const char *Name);
  3422. LLVMValueRef LLVMBuildLShr(LLVMBuilderRef, LLVMValueRef LHS, LLVMValueRef RHS,
  3423. const char *Name);
  3424. LLVMValueRef LLVMBuildAShr(LLVMBuilderRef, LLVMValueRef LHS, LLVMValueRef RHS,
  3425. const char *Name);
  3426. LLVMValueRef LLVMBuildAnd(LLVMBuilderRef, LLVMValueRef LHS, LLVMValueRef RHS,
  3427. const char *Name);
  3428. LLVMValueRef LLVMBuildOr(LLVMBuilderRef, LLVMValueRef LHS, LLVMValueRef RHS,
  3429. const char *Name);
  3430. LLVMValueRef LLVMBuildXor(LLVMBuilderRef, LLVMValueRef LHS, LLVMValueRef RHS,
  3431. const char *Name);
  3432. LLVMValueRef LLVMBuildBinOp(LLVMBuilderRef B, LLVMOpcode Op,
  3433. LLVMValueRef LHS, LLVMValueRef RHS,
  3434. const char *Name);
  3435. LLVMValueRef LLVMBuildNeg(LLVMBuilderRef, LLVMValueRef V, const char *Name);
  3436. LLVMValueRef LLVMBuildNSWNeg(LLVMBuilderRef B, LLVMValueRef V,
  3437. const char *Name);
  3438. LLVMValueRef LLVMBuildNUWNeg(LLVMBuilderRef B, LLVMValueRef V,
  3439. const char *Name);
  3440. LLVMValueRef LLVMBuildFNeg(LLVMBuilderRef, LLVMValueRef V, const char *Name);
  3441. LLVMValueRef LLVMBuildNot(LLVMBuilderRef, LLVMValueRef V, const char *Name);
  3442. /* Memory */
  3443. LLVMValueRef LLVMBuildMalloc(LLVMBuilderRef, LLVMTypeRef Ty, const char *Name);
  3444. LLVMValueRef LLVMBuildArrayMalloc(LLVMBuilderRef, LLVMTypeRef Ty,
  3445. LLVMValueRef Val, const char *Name);
  3446. /**
  3447. * Creates and inserts a memset to the specified pointer and the
  3448. * specified value.
  3449. *
  3450. * @see llvm::IRRBuilder::CreateMemSet()
  3451. */
  3452. LLVMValueRef LLVMBuildMemSet(LLVMBuilderRef B, LLVMValueRef Ptr,
  3453. LLVMValueRef Val, LLVMValueRef Len,
  3454. unsigned Align);
  3455. /**
  3456. * Creates and inserts a memcpy between the specified pointers.
  3457. *
  3458. * @see llvm::IRRBuilder::CreateMemCpy()
  3459. */
  3460. LLVMValueRef LLVMBuildMemCpy(LLVMBuilderRef B,
  3461. LLVMValueRef Dst, unsigned DstAlign,
  3462. LLVMValueRef Src, unsigned SrcAlign,
  3463. LLVMValueRef Size);
  3464. /**
  3465. * Creates and inserts a memmove between the specified pointers.
  3466. *
  3467. * @see llvm::IRRBuilder::CreateMemMove()
  3468. */
  3469. LLVMValueRef LLVMBuildMemMove(LLVMBuilderRef B,
  3470. LLVMValueRef Dst, unsigned DstAlign,
  3471. LLVMValueRef Src, unsigned SrcAlign,
  3472. LLVMValueRef Size);
  3473. LLVMValueRef LLVMBuildAlloca(LLVMBuilderRef, LLVMTypeRef Ty, const char *Name);
  3474. LLVMValueRef LLVMBuildArrayAlloca(LLVMBuilderRef, LLVMTypeRef Ty,
  3475. LLVMValueRef Val, const char *Name);
  3476. LLVMValueRef LLVMBuildFree(LLVMBuilderRef, LLVMValueRef PointerVal);
  3477. LLVMValueRef LLVMBuildLoad2(LLVMBuilderRef, LLVMTypeRef Ty,
  3478. LLVMValueRef PointerVal, const char *Name);
  3479. LLVMValueRef LLVMBuildStore(LLVMBuilderRef, LLVMValueRef Val, LLVMValueRef Ptr);
  3480. LLVMValueRef LLVMBuildGEP2(LLVMBuilderRef B, LLVMTypeRef Ty,
  3481. LLVMValueRef Pointer, LLVMValueRef *Indices,
  3482. unsigned NumIndices, const char *Name);
  3483. LLVMValueRef LLVMBuildInBoundsGEP2(LLVMBuilderRef B, LLVMTypeRef Ty,
  3484. LLVMValueRef Pointer, LLVMValueRef *Indices,
  3485. unsigned NumIndices, const char *Name);
  3486. LLVMValueRef LLVMBuildStructGEP2(LLVMBuilderRef B, LLVMTypeRef Ty,
  3487. LLVMValueRef Pointer, unsigned Idx,
  3488. const char *Name);
  3489. LLVMValueRef LLVMBuildGlobalString(LLVMBuilderRef B, const char *Str,
  3490. const char *Name);
  3491. LLVMValueRef LLVMBuildGlobalStringPtr(LLVMBuilderRef B, const char *Str,
  3492. const char *Name);
  3493. LLVMBool LLVMGetVolatile(LLVMValueRef MemoryAccessInst);
  3494. void LLVMSetVolatile(LLVMValueRef MemoryAccessInst, LLVMBool IsVolatile);
  3495. LLVMBool LLVMGetWeak(LLVMValueRef CmpXchgInst);
  3496. void LLVMSetWeak(LLVMValueRef CmpXchgInst, LLVMBool IsWeak);
  3497. LLVMAtomicOrdering LLVMGetOrdering(LLVMValueRef MemoryAccessInst);
  3498. void LLVMSetOrdering(LLVMValueRef MemoryAccessInst, LLVMAtomicOrdering Ordering);
  3499. LLVMAtomicRMWBinOp LLVMGetAtomicRMWBinOp(LLVMValueRef AtomicRMWInst);
  3500. void LLVMSetAtomicRMWBinOp(LLVMValueRef AtomicRMWInst, LLVMAtomicRMWBinOp BinOp);
  3501. /* Casts */
  3502. LLVMValueRef LLVMBuildTrunc(LLVMBuilderRef, LLVMValueRef Val,
  3503. LLVMTypeRef DestTy, const char *Name);
  3504. LLVMValueRef LLVMBuildZExt(LLVMBuilderRef, LLVMValueRef Val,
  3505. LLVMTypeRef DestTy, const char *Name);
  3506. LLVMValueRef LLVMBuildSExt(LLVMBuilderRef, LLVMValueRef Val,
  3507. LLVMTypeRef DestTy, const char *Name);
  3508. LLVMValueRef LLVMBuildFPToUI(LLVMBuilderRef, LLVMValueRef Val,
  3509. LLVMTypeRef DestTy, const char *Name);
  3510. LLVMValueRef LLVMBuildFPToSI(LLVMBuilderRef, LLVMValueRef Val,
  3511. LLVMTypeRef DestTy, const char *Name);
  3512. LLVMValueRef LLVMBuildUIToFP(LLVMBuilderRef, LLVMValueRef Val,
  3513. LLVMTypeRef DestTy, const char *Name);
  3514. LLVMValueRef LLVMBuildSIToFP(LLVMBuilderRef, LLVMValueRef Val,
  3515. LLVMTypeRef DestTy, const char *Name);
  3516. LLVMValueRef LLVMBuildFPTrunc(LLVMBuilderRef, LLVMValueRef Val,
  3517. LLVMTypeRef DestTy, const char *Name);
  3518. LLVMValueRef LLVMBuildFPExt(LLVMBuilderRef, LLVMValueRef Val,
  3519. LLVMTypeRef DestTy, const char *Name);
  3520. LLVMValueRef LLVMBuildPtrToInt(LLVMBuilderRef, LLVMValueRef Val,
  3521. LLVMTypeRef DestTy, const char *Name);
  3522. LLVMValueRef LLVMBuildIntToPtr(LLVMBuilderRef, LLVMValueRef Val,
  3523. LLVMTypeRef DestTy, const char *Name);
  3524. LLVMValueRef LLVMBuildBitCast(LLVMBuilderRef, LLVMValueRef Val,
  3525. LLVMTypeRef DestTy, const char *Name);
  3526. LLVMValueRef LLVMBuildAddrSpaceCast(LLVMBuilderRef, LLVMValueRef Val,
  3527. LLVMTypeRef DestTy, const char *Name);
  3528. LLVMValueRef LLVMBuildZExtOrBitCast(LLVMBuilderRef, LLVMValueRef Val,
  3529. LLVMTypeRef DestTy, const char *Name);
  3530. LLVMValueRef LLVMBuildSExtOrBitCast(LLVMBuilderRef, LLVMValueRef Val,
  3531. LLVMTypeRef DestTy, const char *Name);
  3532. LLVMValueRef LLVMBuildTruncOrBitCast(LLVMBuilderRef, LLVMValueRef Val,
  3533. LLVMTypeRef DestTy, const char *Name);
  3534. LLVMValueRef LLVMBuildCast(LLVMBuilderRef B, LLVMOpcode Op, LLVMValueRef Val,
  3535. LLVMTypeRef DestTy, const char *Name);
  3536. LLVMValueRef LLVMBuildPointerCast(LLVMBuilderRef, LLVMValueRef Val,
  3537. LLVMTypeRef DestTy, const char *Name);
  3538. LLVMValueRef LLVMBuildIntCast2(LLVMBuilderRef, LLVMValueRef Val,
  3539. LLVMTypeRef DestTy, LLVMBool IsSigned,
  3540. const char *Name);
  3541. LLVMValueRef LLVMBuildFPCast(LLVMBuilderRef, LLVMValueRef Val,
  3542. LLVMTypeRef DestTy, const char *Name);
  3543. /** Deprecated: This cast is always signed. Use LLVMBuildIntCast2 instead. */
  3544. LLVMValueRef LLVMBuildIntCast(LLVMBuilderRef, LLVMValueRef Val, /*Signed cast!*/
  3545. LLVMTypeRef DestTy, const char *Name);
  3546. LLVMOpcode LLVMGetCastOpcode(LLVMValueRef Src, LLVMBool SrcIsSigned,
  3547. LLVMTypeRef DestTy, LLVMBool DestIsSigned);
  3548. /* Comparisons */
  3549. LLVMValueRef LLVMBuildICmp(LLVMBuilderRef, LLVMIntPredicate Op,
  3550. LLVMValueRef LHS, LLVMValueRef RHS,
  3551. const char *Name);
  3552. LLVMValueRef LLVMBuildFCmp(LLVMBuilderRef, LLVMRealPredicate Op,
  3553. LLVMValueRef LHS, LLVMValueRef RHS,
  3554. const char *Name);
  3555. /* Miscellaneous instructions */
  3556. LLVMValueRef LLVMBuildPhi(LLVMBuilderRef, LLVMTypeRef Ty, const char *Name);
  3557. LLVMValueRef LLVMBuildCall2(LLVMBuilderRef, LLVMTypeRef, LLVMValueRef Fn,
  3558. LLVMValueRef *Args, unsigned NumArgs,
  3559. const char *Name);
  3560. LLVMValueRef LLVMBuildSelect(LLVMBuilderRef, LLVMValueRef If,
  3561. LLVMValueRef Then, LLVMValueRef Else,
  3562. const char *Name);
  3563. LLVMValueRef LLVMBuildVAArg(LLVMBuilderRef, LLVMValueRef List, LLVMTypeRef Ty,
  3564. const char *Name);
  3565. LLVMValueRef LLVMBuildExtractElement(LLVMBuilderRef, LLVMValueRef VecVal,
  3566. LLVMValueRef Index, const char *Name);
  3567. LLVMValueRef LLVMBuildInsertElement(LLVMBuilderRef, LLVMValueRef VecVal,
  3568. LLVMValueRef EltVal, LLVMValueRef Index,
  3569. const char *Name);
  3570. LLVMValueRef LLVMBuildShuffleVector(LLVMBuilderRef, LLVMValueRef V1,
  3571. LLVMValueRef V2, LLVMValueRef Mask,
  3572. const char *Name);
  3573. LLVMValueRef LLVMBuildExtractValue(LLVMBuilderRef, LLVMValueRef AggVal,
  3574. unsigned Index, const char *Name);
  3575. LLVMValueRef LLVMBuildInsertValue(LLVMBuilderRef, LLVMValueRef AggVal,
  3576. LLVMValueRef EltVal, unsigned Index,
  3577. const char *Name);
  3578. LLVMValueRef LLVMBuildFreeze(LLVMBuilderRef, LLVMValueRef Val,
  3579. const char *Name);
  3580. LLVMValueRef LLVMBuildIsNull(LLVMBuilderRef, LLVMValueRef Val,
  3581. const char *Name);
  3582. LLVMValueRef LLVMBuildIsNotNull(LLVMBuilderRef, LLVMValueRef Val,
  3583. const char *Name);
  3584. LLVMValueRef LLVMBuildPtrDiff2(LLVMBuilderRef, LLVMTypeRef ElemTy,
  3585. LLVMValueRef LHS, LLVMValueRef RHS,
  3586. const char *Name);
  3587. LLVMValueRef LLVMBuildFence(LLVMBuilderRef B, LLVMAtomicOrdering ordering,
  3588. LLVMBool singleThread, const char *Name);
  3589. LLVMValueRef LLVMBuildAtomicRMW(LLVMBuilderRef B, LLVMAtomicRMWBinOp op,
  3590. LLVMValueRef PTR, LLVMValueRef Val,
  3591. LLVMAtomicOrdering ordering,
  3592. LLVMBool singleThread);
  3593. LLVMValueRef LLVMBuildAtomicCmpXchg(LLVMBuilderRef B, LLVMValueRef Ptr,
  3594. LLVMValueRef Cmp, LLVMValueRef New,
  3595. LLVMAtomicOrdering SuccessOrdering,
  3596. LLVMAtomicOrdering FailureOrdering,
  3597. LLVMBool SingleThread);
  3598. /**
  3599. * Get the number of elements in the mask of a ShuffleVector instruction.
  3600. */
  3601. unsigned LLVMGetNumMaskElements(LLVMValueRef ShuffleVectorInst);
  3602. /**
  3603. * \returns a constant that specifies that the result of a \c ShuffleVectorInst
  3604. * is undefined.
  3605. */
  3606. int LLVMGetUndefMaskElem(void);
  3607. /**
  3608. * Get the mask value at position Elt in the mask of a ShuffleVector
  3609. * instruction.
  3610. *
  3611. * \Returns the result of \c LLVMGetUndefMaskElem() if the mask value is undef
  3612. * at that position.
  3613. */
  3614. int LLVMGetMaskValue(LLVMValueRef ShuffleVectorInst, unsigned Elt);
  3615. LLVMBool LLVMIsAtomicSingleThread(LLVMValueRef AtomicInst);
  3616. void LLVMSetAtomicSingleThread(LLVMValueRef AtomicInst, LLVMBool SingleThread);
  3617. LLVMAtomicOrdering LLVMGetCmpXchgSuccessOrdering(LLVMValueRef CmpXchgInst);
  3618. void LLVMSetCmpXchgSuccessOrdering(LLVMValueRef CmpXchgInst,
  3619. LLVMAtomicOrdering Ordering);
  3620. LLVMAtomicOrdering LLVMGetCmpXchgFailureOrdering(LLVMValueRef CmpXchgInst);
  3621. void LLVMSetCmpXchgFailureOrdering(LLVMValueRef CmpXchgInst,
  3622. LLVMAtomicOrdering Ordering);
  3623. /**
  3624. * @}
  3625. */
  3626. /**
  3627. * @defgroup LLVMCCoreModuleProvider Module Providers
  3628. *
  3629. * @{
  3630. */
  3631. /**
  3632. * Changes the type of M so it can be passed to FunctionPassManagers and the
  3633. * JIT. They take ModuleProviders for historical reasons.
  3634. */
  3635. LLVMModuleProviderRef
  3636. LLVMCreateModuleProviderForExistingModule(LLVMModuleRef M);
  3637. /**
  3638. * Destroys the module M.
  3639. */
  3640. void LLVMDisposeModuleProvider(LLVMModuleProviderRef M);
  3641. /**
  3642. * @}
  3643. */
  3644. /**
  3645. * @defgroup LLVMCCoreMemoryBuffers Memory Buffers
  3646. *
  3647. * @{
  3648. */
  3649. LLVMBool LLVMCreateMemoryBufferWithContentsOfFile(const char *Path,
  3650. LLVMMemoryBufferRef *OutMemBuf,
  3651. char **OutMessage);
  3652. LLVMBool LLVMCreateMemoryBufferWithSTDIN(LLVMMemoryBufferRef *OutMemBuf,
  3653. char **OutMessage);
  3654. LLVMMemoryBufferRef LLVMCreateMemoryBufferWithMemoryRange(const char *InputData,
  3655. size_t InputDataLength,
  3656. const char *BufferName,
  3657. LLVMBool RequiresNullTerminator);
  3658. LLVMMemoryBufferRef LLVMCreateMemoryBufferWithMemoryRangeCopy(const char *InputData,
  3659. size_t InputDataLength,
  3660. const char *BufferName);
  3661. const char *LLVMGetBufferStart(LLVMMemoryBufferRef MemBuf);
  3662. size_t LLVMGetBufferSize(LLVMMemoryBufferRef MemBuf);
  3663. void LLVMDisposeMemoryBuffer(LLVMMemoryBufferRef MemBuf);
  3664. /**
  3665. * @}
  3666. */
  3667. /**
  3668. * @defgroup LLVMCCorePassRegistry Pass Registry
  3669. * @ingroup LLVMCCore
  3670. *
  3671. * @{
  3672. */
  3673. /** Return the global pass registry, for use with initialization functions.
  3674. @see llvm::PassRegistry::getPassRegistry */
  3675. LLVMPassRegistryRef LLVMGetGlobalPassRegistry(void);
  3676. /**
  3677. * @}
  3678. */
  3679. /**
  3680. * @defgroup LLVMCCorePassManagers Pass Managers
  3681. * @ingroup LLVMCCore
  3682. *
  3683. * @{
  3684. */
  3685. /** Constructs a new whole-module pass pipeline. This type of pipeline is
  3686. suitable for link-time optimization and whole-module transformations.
  3687. @see llvm::PassManager::PassManager */
  3688. LLVMPassManagerRef LLVMCreatePassManager(void);
  3689. /** Constructs a new function-by-function pass pipeline over the module
  3690. provider. It does not take ownership of the module provider. This type of
  3691. pipeline is suitable for code generation and JIT compilation tasks.
  3692. @see llvm::FunctionPassManager::FunctionPassManager */
  3693. LLVMPassManagerRef LLVMCreateFunctionPassManagerForModule(LLVMModuleRef M);
  3694. /** Deprecated: Use LLVMCreateFunctionPassManagerForModule instead. */
  3695. LLVMPassManagerRef LLVMCreateFunctionPassManager(LLVMModuleProviderRef MP);
  3696. /** Initializes, executes on the provided module, and finalizes all of the
  3697. passes scheduled in the pass manager. Returns 1 if any of the passes
  3698. modified the module, 0 otherwise.
  3699. @see llvm::PassManager::run(Module&) */
  3700. LLVMBool LLVMRunPassManager(LLVMPassManagerRef PM, LLVMModuleRef M);
  3701. /** Initializes all of the function passes scheduled in the function pass
  3702. manager. Returns 1 if any of the passes modified the module, 0 otherwise.
  3703. @see llvm::FunctionPassManager::doInitialization */
  3704. LLVMBool LLVMInitializeFunctionPassManager(LLVMPassManagerRef FPM);
  3705. /** Executes all of the function passes scheduled in the function pass manager
  3706. on the provided function. Returns 1 if any of the passes modified the
  3707. function, false otherwise.
  3708. @see llvm::FunctionPassManager::run(Function&) */
  3709. LLVMBool LLVMRunFunctionPassManager(LLVMPassManagerRef FPM, LLVMValueRef F);
  3710. /** Finalizes all of the function passes scheduled in the function pass
  3711. manager. Returns 1 if any of the passes modified the module, 0 otherwise.
  3712. @see llvm::FunctionPassManager::doFinalization */
  3713. LLVMBool LLVMFinalizeFunctionPassManager(LLVMPassManagerRef FPM);
  3714. /** Frees the memory of a pass pipeline. For function pipelines, does not free
  3715. the module provider.
  3716. @see llvm::PassManagerBase::~PassManagerBase. */
  3717. void LLVMDisposePassManager(LLVMPassManagerRef PM);
  3718. /**
  3719. * @}
  3720. */
  3721. /**
  3722. * @defgroup LLVMCCoreThreading Threading
  3723. *
  3724. * Handle the structures needed to make LLVM safe for multithreading.
  3725. *
  3726. * @{
  3727. */
  3728. /** Deprecated: Multi-threading can only be enabled/disabled with the compile
  3729. time define LLVM_ENABLE_THREADS. This function always returns
  3730. LLVMIsMultithreaded(). */
  3731. LLVMBool LLVMStartMultithreaded(void);
  3732. /** Deprecated: Multi-threading can only be enabled/disabled with the compile
  3733. time define LLVM_ENABLE_THREADS. */
  3734. void LLVMStopMultithreaded(void);
  3735. /** Check whether LLVM is executing in thread-safe mode or not.
  3736. @see llvm::llvm_is_multithreaded */
  3737. LLVMBool LLVMIsMultithreaded(void);
  3738. /**
  3739. * @}
  3740. */
  3741. /**
  3742. * @}
  3743. */
  3744. /**
  3745. * @}
  3746. */
  3747. LLVM_C_EXTERN_C_END
  3748. #endif /* LLVM_C_CORE_H */
  3749. #ifdef __GNUC__
  3750. #pragma GCC diagnostic pop
  3751. #endif