Core.h 130 KB

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