Core.h 133 KB

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