blob: 0c3d76d6f9bfc7b9bba0f650f3d66fdf7cb8d722 [file] [log] [blame]
Gordon Henriksen76a03742007-09-18 03:18:57 +00001/*===-- llvm-c/Core.h - Core Library C Interface ------------------*- C -*-===*\
2|* *|
3|* The LLVM Compiler Infrastructure *|
4|* *|
Chris Lattnere9cc7422007-12-29 19:59:42 +00005|* This file is distributed under the University of Illinois Open Source *|
6|* License. See LICENSE.TXT for details. *|
Gordon Henriksen76a03742007-09-18 03:18:57 +00007|* *|
8|*===----------------------------------------------------------------------===*|
9|* *|
10|* This header declares the C interface to libLLVMCore.a, which implements *|
11|* the LLVM intermediate representation. *|
12|* *|
Gordon Henriksen76a03742007-09-18 03:18:57 +000013\*===----------------------------------------------------------------------===*/
14
15#ifndef LLVM_C_CORE_H
16#define LLVM_C_CORE_H
17
Eric Christophera6b96002015-12-18 01:46:52 +000018#include "llvm-c/ErrorHandling.h"
19#include "llvm-c/Types.h"
Erick Tryzelaardd991352009-08-16 23:36:46 +000020
Evan Cheng2e254d02013-04-04 17:40:53 +000021#ifdef __cplusplus
Gordon Henriksen76a03742007-09-18 03:18:57 +000022extern "C" {
23#endif
24
Gregory Szorc34c863a2012-03-21 03:54:29 +000025/**
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/**
34 * @defgroup LLVMCTransforms Transforms
35 */
36
37/**
38 * @defgroup LLVMCCore Core
39 *
40 * This modules provide an interface to libLLVMCore, which implements
41 * the LLVM intermediate representation as well as other related types
42 * and utilities.
43 *
Gregory Szorc34c863a2012-03-21 03:54:29 +000044 * Many exotic languages can interoperate with C code but have a harder time
45 * with C++ due to name mangling. So in addition to C, this interface enables
46 * tools written in such languages.
47 *
Gregory Szorc34c863a2012-03-21 03:54:29 +000048 * @{
49 */
50
51/**
52 * @defgroup LLVMCCoreTypes Types and Enumerations
53 *
54 * @{
55 */
Gordon Henriksen76a03742007-09-18 03:18:57 +000056
Gordon Henriksen76a03742007-09-18 03:18:57 +000057typedef enum {
Devang Patel4c758ea2008-09-25 21:00:45 +000058 LLVMZExtAttribute = 1<<0,
59 LLVMSExtAttribute = 1<<1,
60 LLVMNoReturnAttribute = 1<<2,
61 LLVMInRegAttribute = 1<<3,
62 LLVMStructRetAttribute = 1<<4,
63 LLVMNoUnwindAttribute = 1<<5,
64 LLVMNoAliasAttribute = 1<<6,
65 LLVMByValAttribute = 1<<7,
66 LLVMNestAttribute = 1<<8,
67 LLVMReadNoneAttribute = 1<<9,
Anton Korobeynikovc8ce7b082009-07-17 18:07:26 +000068 LLVMReadOnlyAttribute = 1<<10,
Anton Korobeynikov9750be92009-07-17 18:57:16 +000069 LLVMNoInlineAttribute = 1<<11,
70 LLVMAlwaysInlineAttribute = 1<<12,
71 LLVMOptimizeForSizeAttribute = 1<<13,
72 LLVMStackProtectAttribute = 1<<14,
73 LLVMStackProtectReqAttribute = 1<<15,
Erick Tryzelaar8f69fea2010-03-03 23:51:25 +000074 LLVMAlignment = 31<<16,
Anton Korobeynikov9750be92009-07-17 18:57:16 +000075 LLVMNoCaptureAttribute = 1<<21,
76 LLVMNoRedZoneAttribute = 1<<22,
77 LLVMNoImplicitFloatAttribute = 1<<23,
Jakob Stoklund Olesen74bb06c2010-02-06 01:16:28 +000078 LLVMNakedAttribute = 1<<24,
Erick Tryzelaar8f69fea2010-03-03 23:51:25 +000079 LLVMInlineHintAttribute = 1<<25,
Torok Edwin1db48c02011-10-06 12:13:32 +000080 LLVMStackAlignment = 7<<26,
81 LLVMReturnsTwice = 1 << 29,
82 LLVMUWTable = 1 << 30,
Chandler Carruth44d69d92012-01-25 07:40:15 +000083 LLVMNonLazyBind = 1 << 31
84
Bill Wendlingd154e2832013-01-23 06:41:41 +000085 /* FIXME: These attributes are currently not included in the C API as
Nuno Lopesdef4229972012-09-02 14:19:21 +000086 a temporary measure until the API/ABI impact to the C API is understood
87 and the path forward agreed upon.
Peter Collingbourne58af6d12015-06-15 22:16:51 +000088 LLVMSanitizeAddressAttribute = 1ULL << 32,
89 LLVMStackProtectStrongAttribute = 1ULL<<35,
90 LLVMColdAttribute = 1ULL << 40,
91 LLVMOptimizeNoneAttribute = 1ULL << 42,
92 LLVMInAllocaAttribute = 1ULL << 43,
93 LLVMNonNullAttribute = 1ULL << 44,
94 LLVMJumpTableAttribute = 1ULL << 45,
95 LLVMConvergentAttribute = 1ULL << 46,
96 LLVMSafeStackAttribute = 1ULL << 47,
Manman Renf46262e2016-03-29 17:37:21 +000097 LLVMSwiftSelfAttribute = 1ULL << 48,
Manman Ren9bfd0d02016-04-01 21:41:15 +000098 LLVMSwiftErrorAttribute = 1ULL << 49,
Nuno Lopesdef4229972012-09-02 14:19:21 +000099 */
Devang Patel4c758ea2008-09-25 21:00:45 +0000100} LLVMAttribute;
Gordon Henriksen2d9cc212008-04-28 17:37:06 +0000101
102typedef enum {
Bill Wendlingda52cec2010-02-15 20:53:17 +0000103 /* Terminator Instructions */
Chris Lattner40cf28d2009-10-12 04:01:02 +0000104 LLVMRet = 1,
105 LLVMBr = 2,
106 LLVMSwitch = 3,
Bill Wendling07d6d762010-02-15 20:50:51 +0000107 LLVMIndirectBr = 4,
108 LLVMInvoke = 5,
Bill Wendling46ffaa92011-08-02 06:20:17 +0000109 /* removed 6 due to API changes */
Bill Wendling2641d132011-07-27 21:00:28 +0000110 LLVMUnreachable = 7,
Bill Wendling07d6d762010-02-15 20:50:51 +0000111
Bill Wendlingda52cec2010-02-15 20:53:17 +0000112 /* Standard Binary Operators */
Bill Wendling2641d132011-07-27 21:00:28 +0000113 LLVMAdd = 8,
114 LLVMFAdd = 9,
115 LLVMSub = 10,
116 LLVMFSub = 11,
117 LLVMMul = 12,
118 LLVMFMul = 13,
119 LLVMUDiv = 14,
120 LLVMSDiv = 15,
121 LLVMFDiv = 16,
122 LLVMURem = 17,
123 LLVMSRem = 18,
124 LLVMFRem = 19,
Bill Wendling07d6d762010-02-15 20:50:51 +0000125
Bill Wendlingda52cec2010-02-15 20:53:17 +0000126 /* Logical Operators */
Bill Wendling2641d132011-07-27 21:00:28 +0000127 LLVMShl = 20,
128 LLVMLShr = 21,
129 LLVMAShr = 22,
130 LLVMAnd = 23,
131 LLVMOr = 24,
132 LLVMXor = 25,
Bill Wendling07d6d762010-02-15 20:50:51 +0000133
Bill Wendlingda52cec2010-02-15 20:53:17 +0000134 /* Memory Operators */
Bill Wendling2641d132011-07-27 21:00:28 +0000135 LLVMAlloca = 26,
136 LLVMLoad = 27,
137 LLVMStore = 28,
138 LLVMGetElementPtr = 29,
Bill Wendling07d6d762010-02-15 20:50:51 +0000139
Bill Wendlingda52cec2010-02-15 20:53:17 +0000140 /* Cast Operators */
Bill Wendling2641d132011-07-27 21:00:28 +0000141 LLVMTrunc = 30,
142 LLVMZExt = 31,
143 LLVMSExt = 32,
144 LLVMFPToUI = 33,
145 LLVMFPToSI = 34,
146 LLVMUIToFP = 35,
147 LLVMSIToFP = 36,
148 LLVMFPTrunc = 37,
149 LLVMFPExt = 38,
150 LLVMPtrToInt = 39,
151 LLVMIntToPtr = 40,
152 LLVMBitCast = 41,
Matt Arsenaultb03bd4d2013-11-15 01:34:59 +0000153 LLVMAddrSpaceCast = 60,
Bill Wendling07d6d762010-02-15 20:50:51 +0000154
Bill Wendlingda52cec2010-02-15 20:53:17 +0000155 /* Other Operators */
Bill Wendling2641d132011-07-27 21:00:28 +0000156 LLVMICmp = 42,
157 LLVMFCmp = 43,
158 LLVMPHI = 44,
159 LLVMCall = 45,
160 LLVMSelect = 46,
Torok Edwin05dc9d62011-10-06 12:39:34 +0000161 LLVMUserOp1 = 47,
162 LLVMUserOp2 = 48,
Bill Wendling2641d132011-07-27 21:00:28 +0000163 LLVMVAArg = 49,
164 LLVMExtractElement = 50,
165 LLVMInsertElement = 51,
166 LLVMShuffleVector = 52,
167 LLVMExtractValue = 53,
168 LLVMInsertValue = 54,
Eli Friedman4fc946c2011-07-27 18:59:19 +0000169
170 /* Atomic operators */
Bill Wendling2641d132011-07-27 21:00:28 +0000171 LLVMFence = 55,
Eli Friedmanc9a551e2011-07-28 21:48:00 +0000172 LLVMAtomicCmpXchg = 56,
Bill Wendlingf891bf82011-07-31 06:30:59 +0000173 LLVMAtomicRMW = 57,
174
175 /* Exception Handling Operators */
Bill Wendlingfae14752011-08-12 20:24:12 +0000176 LLVMResume = 58,
David Majnemer654e1302015-07-31 17:58:14 +0000177 LLVMLandingPad = 59,
178 LLVMCleanupRet = 61,
179 LLVMCatchRet = 62,
Joseph Tremoulet9ce71f72015-09-03 09:09:43 +0000180 LLVMCatchPad = 63,
David Majnemerbbfc7212015-12-14 18:34:23 +0000181 LLVMCleanupPad = 64,
182 LLVMCatchSwitch = 65
Chris Lattner40cf28d2009-10-12 04:01:02 +0000183} LLVMOpcode;
184
185typedef enum {
Gordon Henriksen4a4d7352007-12-30 17:46:33 +0000186 LLVMVoidTypeKind, /**< type with no size */
Dan Gohman518cda42011-12-17 00:04:22 +0000187 LLVMHalfTypeKind, /**< 16 bit floating point type */
Gordon Henriksen4a4d7352007-12-30 17:46:33 +0000188 LLVMFloatTypeKind, /**< 32 bit floating point type */
189 LLVMDoubleTypeKind, /**< 64 bit floating point type */
190 LLVMX86_FP80TypeKind, /**< 80 bit floating point type (X87) */
191 LLVMFP128TypeKind, /**< 128 bit floating point type (112-bit mantissa)*/
192 LLVMPPC_FP128TypeKind, /**< 128 bit floating point type (two 64-bits) */
193 LLVMLabelTypeKind, /**< Labels */
194 LLVMIntegerTypeKind, /**< Arbitrary bit width integers */
195 LLVMFunctionTypeKind, /**< Functions */
196 LLVMStructTypeKind, /**< Structures */
197 LLVMArrayTypeKind, /**< Arrays */
198 LLVMPointerTypeKind, /**< Pointers */
Chris Lattnerdac44ec2009-07-15 22:00:31 +0000199 LLVMVectorTypeKind, /**< SIMD 'packed' format, or other vector type */
Dale Johannesenbaa5d042010-09-10 20:55:01 +0000200 LLVMMetadataTypeKind, /**< Metadata */
David Majnemerb611e3f2015-08-14 05:09:07 +0000201 LLVMX86_MMXTypeKind, /**< X86 MMX */
202 LLVMTokenTypeKind /**< Tokens */
Gordon Henriksen76a03742007-09-18 03:18:57 +0000203} LLVMTypeKind;
204
205typedef enum {
Gordon Henriksen4a4d7352007-12-30 17:46:33 +0000206 LLVMExternalLinkage, /**< Externally visible function */
Chris Lattner2dba0f02009-04-13 06:25:37 +0000207 LLVMAvailableExternallyLinkage,
Duncan Sands12da8ce2009-03-07 15:45:40 +0000208 LLVMLinkOnceAnyLinkage, /**< Keep one copy of function when linking (inline)*/
209 LLVMLinkOnceODRLinkage, /**< Same, but only replaced by something
210 equivalent. */
Rafael Espindola716e7402013-11-01 17:09:14 +0000211 LLVMLinkOnceODRAutoHideLinkage, /**< Obsolete */
Duncan Sands12da8ce2009-03-07 15:45:40 +0000212 LLVMWeakAnyLinkage, /**< Keep one copy of function when linking (weak) */
213 LLVMWeakODRLinkage, /**< Same, but only replaced by something
214 equivalent. */
Gordon Henriksen4a4d7352007-12-30 17:46:33 +0000215 LLVMAppendingLinkage, /**< Special purpose, only applies to global arrays */
216 LLVMInternalLinkage, /**< Rename collisions when linking (static
217 functions) */
Duncan Sands12da8ce2009-03-07 15:45:40 +0000218 LLVMPrivateLinkage, /**< Like Internal, but omit from symbol table */
Nico Rieck7157bb72014-01-14 15:22:47 +0000219 LLVMDLLImportLinkage, /**< Obsolete */
220 LLVMDLLExportLinkage, /**< Obsolete */
Duncan Sandse2881052009-03-11 08:08:06 +0000221 LLVMExternalWeakLinkage,/**< ExternalWeak linkage description */
Jeffrey Yasskin091217b2010-01-27 20:34:15 +0000222 LLVMGhostLinkage, /**< Obsolete */
Bill Wendling002b1672009-07-20 18:22:52 +0000223 LLVMCommonLinkage, /**< Tentative definitions */
Bill Wendling03bcd6e2010-07-01 21:55:59 +0000224 LLVMLinkerPrivateLinkage, /**< Like Private, but linker removes. */
Bill Wendling34bc34e2012-08-17 18:33:14 +0000225 LLVMLinkerPrivateWeakLinkage /**< Like LinkerPrivate, but is weak. */
Gordon Henriksen76a03742007-09-18 03:18:57 +0000226} LLVMLinkage;
227
228typedef enum {
Gordon Henriksen4a4d7352007-12-30 17:46:33 +0000229 LLVMDefaultVisibility, /**< The GV is visible */
230 LLVMHiddenVisibility, /**< The GV is hidden */
231 LLVMProtectedVisibility /**< The GV is protected */
Gordon Henriksen76a03742007-09-18 03:18:57 +0000232} LLVMVisibility;
233
Gordon Henriksenc23b66c2007-09-26 20:56:12 +0000234typedef enum {
Reid Kleckner2fae26f2014-03-05 02:34:23 +0000235 LLVMDefaultStorageClass = 0,
236 LLVMDLLImportStorageClass = 1, /**< Function to be imported from DLL. */
237 LLVMDLLExportStorageClass = 2 /**< Function to be accessible from DLL. */
238} LLVMDLLStorageClass;
239
240typedef enum {
Gordon Henriksenc23b66c2007-09-26 20:56:12 +0000241 LLVMCCallConv = 0,
242 LLVMFastCallConv = 8,
243 LLVMColdCallConv = 9,
Filip Pizlodfc9b582013-11-09 06:00:03 +0000244 LLVMWebKitJSCallConv = 12,
245 LLVMAnyRegCallConv = 13,
Gordon Henriksenc23b66c2007-09-26 20:56:12 +0000246 LLVMX86StdcallCallConv = 64,
247 LLVMX86FastcallCallConv = 65
248} LLVMCallConv;
249
250typedef enum {
Peter Zotov3e4561c2016-04-06 22:21:29 +0000251 LLVMArgumentValueKind,
252 LLVMBasicBlockValueKind,
253 LLVMMemoryUseValueKind,
254 LLVMMemoryDefValueKind,
255 LLVMMemoryPhiValueKind,
256
257 LLVMFunctionValueKind,
258 LLVMGlobalAliasValueKind,
Dmitry Polukhina1feff72016-04-07 12:32:19 +0000259 LLVMGlobalIFuncValueKind,
Peter Zotov3e4561c2016-04-06 22:21:29 +0000260 LLVMGlobalVariableValueKind,
261 LLVMBlockAddressValueKind,
262 LLVMConstantExprValueKind,
263 LLVMConstantArrayValueKind,
264 LLVMConstantStructValueKind,
265 LLVMConstantVectorValueKind,
266
267 LLVMUndefValueValueKind,
268 LLVMConstantAggregateZeroValueKind,
269 LLVMConstantDataArrayValueKind,
270 LLVMConstantDataVectorValueKind,
271 LLVMConstantIntValueKind,
272 LLVMConstantFPValueKind,
273 LLVMConstantPointerNullValueKind,
274 LLVMConstantTokenNoneValueKind,
275
276 LLVMMetadataAsValueValueKind,
277 LLVMInlineAsmValueKind,
278
279 LLVMInstructionValueKind,
280} LLVMValueKind;
281
282typedef enum {
Gordon Henriksen4a4d7352007-12-30 17:46:33 +0000283 LLVMIntEQ = 32, /**< equal */
284 LLVMIntNE, /**< not equal */
285 LLVMIntUGT, /**< unsigned greater than */
286 LLVMIntUGE, /**< unsigned greater or equal */
287 LLVMIntULT, /**< unsigned less than */
288 LLVMIntULE, /**< unsigned less or equal */
289 LLVMIntSGT, /**< signed greater than */
290 LLVMIntSGE, /**< signed greater or equal */
291 LLVMIntSLT, /**< signed less than */
292 LLVMIntSLE /**< signed less or equal */
Gordon Henriksenc23b66c2007-09-26 20:56:12 +0000293} LLVMIntPredicate;
294
295typedef enum {
Gordon Henriksen4a4d7352007-12-30 17:46:33 +0000296 LLVMRealPredicateFalse, /**< Always false (always folded) */
297 LLVMRealOEQ, /**< True if ordered and equal */
298 LLVMRealOGT, /**< True if ordered and greater than */
299 LLVMRealOGE, /**< True if ordered and greater than or equal */
300 LLVMRealOLT, /**< True if ordered and less than */
301 LLVMRealOLE, /**< True if ordered and less than or equal */
302 LLVMRealONE, /**< True if ordered and operands are unequal */
303 LLVMRealORD, /**< True if ordered (no nans) */
304 LLVMRealUNO, /**< True if unordered: isnan(X) | isnan(Y) */
305 LLVMRealUEQ, /**< True if unordered or equal */
306 LLVMRealUGT, /**< True if unordered or greater than */
307 LLVMRealUGE, /**< True if unordered, greater than, or equal */
308 LLVMRealULT, /**< True if unordered or less than */
309 LLVMRealULE, /**< True if unordered, less than, or equal */
310 LLVMRealUNE, /**< True if unordered or not equal */
311 LLVMRealPredicateTrue /**< Always true (always folded) */
Gordon Henriksenc23b66c2007-09-26 20:56:12 +0000312} LLVMRealPredicate;
313
Bill Wendlingfae14752011-08-12 20:24:12 +0000314typedef enum {
315 LLVMLandingPadCatch, /**< A catch clause */
316 LLVMLandingPadFilter /**< A filter clause */
317} LLVMLandingPadClauseTy;
318
Hans Wennborg5ff71202013-04-16 08:58:59 +0000319typedef enum {
320 LLVMNotThreadLocal = 0,
321 LLVMGeneralDynamicTLSModel,
322 LLVMLocalDynamicTLSModel,
323 LLVMInitialExecTLSModel,
324 LLVMLocalExecTLSModel
325} LLVMThreadLocalMode;
326
Carlo Kokda0ac722013-04-23 13:45:37 +0000327typedef enum {
Carlo Kok8c6719b2013-04-23 13:21:19 +0000328 LLVMAtomicOrderingNotAtomic = 0, /**< A load or store which is not atomic */
329 LLVMAtomicOrderingUnordered = 1, /**< Lowest level of atomicity, guarantees
330 somewhat sane results, lock free. */
NAKAMURA Takumia3a81352013-10-23 17:56:29 +0000331 LLVMAtomicOrderingMonotonic = 2, /**< guarantees that if you take all the
332 operations affecting a specific address,
Carlo Kok8c6719b2013-04-23 13:21:19 +0000333 a consistent ordering exists */
NAKAMURA Takumia3a81352013-10-23 17:56:29 +0000334 LLVMAtomicOrderingAcquire = 4, /**< Acquire provides a barrier of the sort
335 necessary to acquire a lock to access other
Carlo Kok8c6719b2013-04-23 13:21:19 +0000336 memory with normal loads and stores. */
NAKAMURA Takumia3a81352013-10-23 17:56:29 +0000337 LLVMAtomicOrderingRelease = 5, /**< Release is similar to Acquire, but with
338 a barrier of the sort necessary to release
Carlo Kok8c6719b2013-04-23 13:21:19 +0000339 a lock. */
NAKAMURA Takumia3a81352013-10-23 17:56:29 +0000340 LLVMAtomicOrderingAcquireRelease = 6, /**< provides both an Acquire and a
341 Release barrier (for fences and
Carlo Kok8c6719b2013-04-23 13:21:19 +0000342 operations which both read and write
343 memory). */
NAKAMURA Takumia3a81352013-10-23 17:56:29 +0000344 LLVMAtomicOrderingSequentiallyConsistent = 7 /**< provides Acquire semantics
345 for loads and Release
346 semantics for stores.
347 Additionally, it guarantees
348 that a total ordering exists
349 between all
350 SequentiallyConsistent
Carlo Kok8c6719b2013-04-23 13:21:19 +0000351 operations. */
Carlo Kokda0ac722013-04-23 13:45:37 +0000352} LLVMAtomicOrdering;
Carlo Kok8c6719b2013-04-23 13:21:19 +0000353
Carlo Kokda0ac722013-04-23 13:45:37 +0000354typedef enum {
Carlo Kok8c6719b2013-04-23 13:21:19 +0000355 LLVMAtomicRMWBinOpXchg, /**< Set the new value and return the one old */
356 LLVMAtomicRMWBinOpAdd, /**< Add a value and return the old one */
357 LLVMAtomicRMWBinOpSub, /**< Subtract a value and return the old one */
358 LLVMAtomicRMWBinOpAnd, /**< And a value and return the old one */
359 LLVMAtomicRMWBinOpNand, /**< Not-And a value and return the old one */
360 LLVMAtomicRMWBinOpOr, /**< OR a value and return the old one */
361 LLVMAtomicRMWBinOpXor, /**< Xor a value and return the old one */
362 LLVMAtomicRMWBinOpMax, /**< Sets the value if it's greater than the
NAKAMURA Takumia3a81352013-10-23 17:56:29 +0000363 original using a signed comparison and return
Carlo Kok8c6719b2013-04-23 13:21:19 +0000364 the old one */
365 LLVMAtomicRMWBinOpMin, /**< Sets the value if it's Smaller than the
NAKAMURA Takumia3a81352013-10-23 17:56:29 +0000366 original using a signed comparison and return
Carlo Kok8c6719b2013-04-23 13:21:19 +0000367 the old one */
368 LLVMAtomicRMWBinOpUMax, /**< Sets the value if it's greater than the
NAKAMURA Takumia3a81352013-10-23 17:56:29 +0000369 original using an unsigned comparison and return
Carlo Kok8c6719b2013-04-23 13:21:19 +0000370 the old one */
371 LLVMAtomicRMWBinOpUMin /**< Sets the value if it's greater than the
NAKAMURA Takumia3a81352013-10-23 17:56:29 +0000372 original using an unsigned comparison and return
Carlo Kok8c6719b2013-04-23 13:21:19 +0000373 the old one */
Carlo Kokda0ac722013-04-23 13:45:37 +0000374} LLVMAtomicRMWBinOp;
Carlo Kok8c6719b2013-04-23 13:21:19 +0000375
Tom Stellard1580dc72014-04-16 17:45:04 +0000376typedef enum {
377 LLVMDSError,
378 LLVMDSWarning,
379 LLVMDSRemark,
380 LLVMDSNote
381} LLVMDiagnosticSeverity;
382
Gregory Szorc34c863a2012-03-21 03:54:29 +0000383/**
384 * @}
385 */
386
Nick Lewycky0db26542011-05-15 07:20:34 +0000387void LLVMInitializeCore(LLVMPassRegistryRef R);
388
Duncan Sands1cba0a82013-02-17 16:35:51 +0000389/** Deallocate and destroy all ManagedStatic variables.
390 @see llvm::llvm_shutdown
391 @see ManagedStatic */
Benjamin Kramer325ec892013-10-23 16:57:34 +0000392void LLVMShutdown(void);
Duncan Sands1cba0a82013-02-17 16:35:51 +0000393
Gordon Henriksen34eb6d82007-12-19 22:30:40 +0000394/*===-- Error handling ----------------------------------------------------===*/
395
Filip Pizlo3fdbaff2013-05-22 02:46:43 +0000396char *LLVMCreateMessage(const char *Message);
Gordon Henriksen34eb6d82007-12-19 22:30:40 +0000397void LLVMDisposeMessage(char *Message);
398
Filip Pizlo9f50ccd2013-11-03 00:29:47 +0000399/**
Gregory Szorc34c863a2012-03-21 03:54:29 +0000400 * @defgroup LLVMCCoreContext Contexts
401 *
402 * Contexts are execution states for the core LLVM IR system.
403 *
404 * Most types are tied to a context instance. Multiple contexts can
405 * exist simultaneously. A single context is not thread safe. However,
406 * different contexts can execute on different threads simultaneously.
407 *
408 * @{
409 */
Gordon Henriksen76a03742007-09-18 03:18:57 +0000410
Tom Stellard1580dc72014-04-16 17:45:04 +0000411typedef void (*LLVMDiagnosticHandler)(LLVMDiagnosticInfoRef, void *);
Juergen Ributzka34390c72014-05-16 02:33:15 +0000412typedef void (*LLVMYieldCallback)(LLVMContextRef, void *);
Tom Stellard1580dc72014-04-16 17:45:04 +0000413
Gregory Szorc34c863a2012-03-21 03:54:29 +0000414/**
415 * Create a new context.
416 *
417 * Every call to this function should be paired with a call to
418 * LLVMContextDispose() or the context will leak memory.
419 */
Erick Tryzelaarf34cb0c2009-08-30 23:38:06 +0000420LLVMContextRef LLVMContextCreate(void);
Gregory Szorc34c863a2012-03-21 03:54:29 +0000421
422/**
423 * Obtain the global context instance.
424 */
Erick Tryzelaarf34cb0c2009-08-30 23:38:06 +0000425LLVMContextRef LLVMGetGlobalContext(void);
Gregory Szorc34c863a2012-03-21 03:54:29 +0000426
427/**
Tom Stellard1580dc72014-04-16 17:45:04 +0000428 * Set the diagnostic handler for this context.
429 */
430void LLVMContextSetDiagnosticHandler(LLVMContextRef C,
431 LLVMDiagnosticHandler Handler,
432 void *DiagnosticContext);
433
434/**
Jeroen Ketemaad659c32016-04-08 09:19:02 +0000435 * Get the diagnostic handler of this context.
436 */
437LLVMDiagnosticHandler LLVMContextGetDiagnosticHandler(LLVMContextRef C);
438
439/**
440 * Get the diagnostic context of this context.
441 */
442void *LLVMContextGetDiagnosticContext(LLVMContextRef C);
443
444/**
Juergen Ributzka34390c72014-05-16 02:33:15 +0000445 * Set the yield callback function for this context.
446 *
447 * @see LLVMContext::setYieldCallback()
448 */
449void LLVMContextSetYieldCallback(LLVMContextRef C, LLVMYieldCallback Callback,
450 void *OpaqueHandle);
451
452/**
Gregory Szorc34c863a2012-03-21 03:54:29 +0000453 * Destroy a context instance.
454 *
455 * This should be called for every call to LLVMContextCreate() or memory
456 * will be leaked.
457 */
Owen Anderson6773d382009-07-01 16:58:40 +0000458void LLVMContextDispose(LLVMContextRef C);
459
Tom Stellard1580dc72014-04-16 17:45:04 +0000460/**
461 * Return a string representation of the DiagnosticInfo. Use
462 * LLVMDisposeMessage to free the string.
463 *
464 * @see DiagnosticInfo::print()
465 */
466char *LLVMGetDiagInfoDescription(LLVMDiagnosticInfoRef DI);
467
468/**
469 * Return an enum LLVMDiagnosticSeverity.
470 *
471 * @see DiagnosticInfo::getSeverity()
472 */
473LLVMDiagnosticSeverity LLVMGetDiagInfoSeverity(LLVMDiagnosticInfoRef DI);
474
Amaury Sechet56f056c2016-04-04 22:00:25 +0000475unsigned LLVMGetMDKindIDInContext(LLVMContextRef C, const char *Name,
Erick Tryzelaard8531fa2010-02-28 09:45:59 +0000476 unsigned SLen);
Amaury Sechet56f056c2016-04-04 22:00:25 +0000477unsigned LLVMGetMDKindID(const char *Name, unsigned SLen);
Erick Tryzelaard8531fa2010-02-28 09:45:59 +0000478
Gregory Szorc34c863a2012-03-21 03:54:29 +0000479/**
Amaury Sechet60b31452016-04-20 01:02:12 +0000480 * Return an unique id given the name of a target independent attribute,
481 * or 0 if no attribute by that name exists.
482 *
483 * See http://llvm.org/docs/LangRef.html#parameter-attributes
484 * and http://llvm.org/docs/LangRef.html#function-attributes
485 * for the list of available attributes.
486 *
487 * NB: Attribute names and/or id are subject to change without
488 * going through the C API deprecation cycle.
489 */
490unsigned LLVMGetAttrKindID(const char *Name, size_t SLen);
491
492/**
Gregory Szorc34c863a2012-03-21 03:54:29 +0000493 * @}
494 */
495
Gregory Szorc52d26602012-03-21 07:28:27 +0000496/**
497 * @defgroup LLVMCCoreModule Modules
Gregory Szorc34c863a2012-03-21 03:54:29 +0000498 *
Daniel Dunbar06b9f9e2013-08-16 23:30:19 +0000499 * Modules represent the top-level structure in an LLVM program. An LLVM
Gregory Szorc34c863a2012-03-21 03:54:29 +0000500 * module is effectively a translation unit or a collection of
501 * translation units merged together.
502 *
503 * @{
504 */
505
Gregory Szorc34c863a2012-03-21 03:54:29 +0000506/**
507 * Create a new, empty module in the global context.
508 *
509 * This is equivalent to calling LLVMModuleCreateWithNameInContext with
510 * LLVMGetGlobalContext() as the context parameter.
511 *
512 * Every invocation should be paired with LLVMDisposeModule() or memory
513 * will be leaked.
514 */
Gordon Henriksen76a03742007-09-18 03:18:57 +0000515LLVMModuleRef LLVMModuleCreateWithName(const char *ModuleID);
Gregory Szorc34c863a2012-03-21 03:54:29 +0000516
517/**
518 * Create a new, empty module in a specific context.
519 *
520 * Every invocation should be paired with LLVMDisposeModule() or memory
521 * will be leaked.
522 */
Owen Anderson31d44e42009-07-02 07:17:57 +0000523LLVMModuleRef LLVMModuleCreateWithNameInContext(const char *ModuleID,
524 LLVMContextRef C);
Tom Stellard0a4e9a32014-10-01 17:14:57 +0000525/**
526 * Return an exact copy of the specified module.
527 */
528LLVMModuleRef LLVMCloneModule(LLVMModuleRef M);
Gordon Henriksena49d4352008-03-07 19:13:06 +0000529
Gregory Szorc34c863a2012-03-21 03:54:29 +0000530/**
531 * Destroy a module instance.
532 *
533 * This must be called for every created module or memory will be
534 * leaked.
535 */
Gordon Henriksen76a03742007-09-18 03:18:57 +0000536void LLVMDisposeModule(LLVMModuleRef M);
537
Gregory Szorc34c863a2012-03-21 03:54:29 +0000538/**
Peter Zotov0a2fa0a2016-04-05 13:56:59 +0000539 * Obtain the identifier of a module.
540 *
541 * @param M Module to obtain identifier of
542 * @param Len Out parameter which holds the length of the returned string.
543 * @return The identifier of M.
544 * @see Module::getModuleIdentifier()
545 */
546const char *LLVMGetModuleIdentifier(LLVMModuleRef M, size_t *Len);
547
548/**
549 * Set the identifier of a module to a string Ident with length Len.
550 *
551 * @param M The module to set identifier
552 * @param Ident The string to set M's identifier to
553 * @param Len Length of Ident
554 * @see Module::setModuleIdentifier()
555 */
556void LLVMSetModuleIdentifier(LLVMModuleRef M, const char *Ident, size_t Len);
557
558/**
Gregory Szorc34c863a2012-03-21 03:54:29 +0000559 * Obtain the data layout for a module.
560 *
Amaury Sechetf3549c42016-02-16 00:23:52 +0000561 * @see Module::getDataLayoutStr()
562 *
563 * LLVMGetDataLayout is DEPRECATED, as the name is not only incorrect,
564 * but match the name of another method on the module. Prefer the use
565 * of LLVMGetDataLayoutStr, which is not ambiguous.
Gregory Szorc34c863a2012-03-21 03:54:29 +0000566 */
Amaury Sechetf3549c42016-02-16 00:23:52 +0000567const char *LLVMGetDataLayoutStr(LLVMModuleRef M);
Gordon Henriksen05568bb2007-12-27 20:13:47 +0000568const char *LLVMGetDataLayout(LLVMModuleRef M);
Gregory Szorc34c863a2012-03-21 03:54:29 +0000569
570/**
571 * Set the data layout for a module.
572 *
573 * @see Module::setDataLayout()
574 */
Amaury Sechet6ada31c2016-02-15 23:40:06 +0000575void LLVMSetDataLayout(LLVMModuleRef M, const char *DataLayoutStr);
Gordon Henriksen05568bb2007-12-27 20:13:47 +0000576
Gregory Szorc34c863a2012-03-21 03:54:29 +0000577/**
578 * Obtain the target triple for a module.
579 *
580 * @see Module::getTargetTriple()
581 */
Gordon Henriksen05568bb2007-12-27 20:13:47 +0000582const char *LLVMGetTarget(LLVMModuleRef M);
Gregory Szorc34c863a2012-03-21 03:54:29 +0000583
584/**
585 * Set the target triple for a module.
586 *
587 * @see Module::setTargetTriple()
588 */
Gordon Henriksen05568bb2007-12-27 20:13:47 +0000589void LLVMSetTarget(LLVMModuleRef M, const char *Triple);
590
Gregory Szorc34c863a2012-03-21 03:54:29 +0000591/**
592 * Dump a representation of a module to stderr.
593 *
594 * @see Module::dump()
595 */
Gordon Henriksen6c6075e2008-03-14 23:58:56 +0000596void LLVMDumpModule(LLVMModuleRef M);
597
Gregory Szorc34c863a2012-03-21 03:54:29 +0000598/**
Hans Wennborgb7ef2fe2012-05-09 16:54:17 +0000599 * Print a representation of a module to a file. The ErrorMessage needs to be
600 * disposed with LLVMDisposeMessage. Returns 0 on success, 1 otherwise.
601 *
602 * @see Module::print()
603 */
604LLVMBool LLVMPrintModuleToFile(LLVMModuleRef M, const char *Filename,
605 char **ErrorMessage);
606
607/**
Anders Waldenborg84355db2013-10-16 18:00:54 +0000608 * Return a string representation of the module. Use
609 * LLVMDisposeMessage to free the string.
610 *
611 * @see Module::print()
612 */
613char *LLVMPrintModuleToString(LLVMModuleRef M);
614
615/**
Gregory Szorc34c863a2012-03-21 03:54:29 +0000616 * Set inline assembly for a module.
617 *
618 * @see Module::setModuleInlineAsm()
619 */
Chris Lattner26941452010-04-10 17:52:58 +0000620void LLVMSetModuleInlineAsm(LLVMModuleRef M, const char *Asm);
Gordon Henriksen76a03742007-09-18 03:18:57 +0000621
Gregory Szorc34c863a2012-03-21 03:54:29 +0000622/**
623 * Obtain the context to which this module is associated.
624 *
625 * @see Module::getContext()
626 */
Chris Lattnera7e04b02010-11-28 20:03:44 +0000627LLVMContextRef LLVMGetModuleContext(LLVMModuleRef M);
628
Gregory Szorc34c863a2012-03-21 03:54:29 +0000629/**
630 * Obtain a Type from a module by its registered name.
631 */
632LLVMTypeRef LLVMGetTypeByName(LLVMModuleRef M, const char *Name);
Gordon Henriksen76a03742007-09-18 03:18:57 +0000633
Gregory Szorc34c863a2012-03-21 03:54:29 +0000634/**
635 * Obtain the number of operands for named metadata in a module.
636 *
637 * @see llvm::Module::getNamedMetadata()
638 */
639unsigned LLVMGetNamedMetadataNumOperands(LLVMModuleRef M, const char* name);
640
641/**
642 * Obtain the named metadata operands for a module.
643 *
644 * The passed LLVMValueRef pointer should refer to an array of
645 * LLVMValueRef at least LLVMGetNamedMetadataNumOperands long. This
646 * array will be populated with the LLVMValueRef instances. Each
647 * instance corresponds to a llvm::MDNode.
648 *
649 * @see llvm::Module::getNamedMetadata()
650 * @see llvm::MDNode::getOperand()
651 */
652void LLVMGetNamedMetadataOperands(LLVMModuleRef M, const char* name, LLVMValueRef *Dest);
653
654/**
655 * Add an operand to named metadata.
656 *
657 * @see llvm::Module::getNamedMetadata()
658 * @see llvm::MDNode::addOperand()
659 */
660void LLVMAddNamedMetadataOperand(LLVMModuleRef M, const char* name,
661 LLVMValueRef Val);
662
Gregory Szorc52d26602012-03-21 07:28:27 +0000663/**
664 * Add a function to a module under a specified name.
665 *
666 * @see llvm::Function::Create()
667 */
668LLVMValueRef LLVMAddFunction(LLVMModuleRef M, const char *Name,
669 LLVMTypeRef FunctionTy);
670
671/**
672 * Obtain a Function value from a Module by its name.
673 *
674 * The returned value corresponds to a llvm::Function value.
675 *
676 * @see llvm::Module::getFunction()
677 */
678LLVMValueRef LLVMGetNamedFunction(LLVMModuleRef M, const char *Name);
679
680/**
681 * Obtain an iterator to the first Function in a Module.
682 *
683 * @see llvm::Module::begin()
684 */
685LLVMValueRef LLVMGetFirstFunction(LLVMModuleRef M);
686
687/**
688 * Obtain an iterator to the last Function in a Module.
689 *
690 * @see llvm::Module::end()
691 */
692LLVMValueRef LLVMGetLastFunction(LLVMModuleRef M);
693
694/**
695 * Advance a Function iterator to the next Function.
696 *
697 * Returns NULL if the iterator was already at the end and there are no more
698 * functions.
699 */
700LLVMValueRef LLVMGetNextFunction(LLVMValueRef Fn);
701
702/**
703 * Decrement a Function iterator to the previous Function.
704 *
705 * Returns NULL if the iterator was already at the beginning and there are
706 * no previous functions.
707 */
708LLVMValueRef LLVMGetPreviousFunction(LLVMValueRef Fn);
Gregory Szorc34c863a2012-03-21 03:54:29 +0000709
710/**
711 * @}
712 */
713
714/**
715 * @defgroup LLVMCCoreType Types
716 *
717 * Types represent the type of a value.
718 *
719 * Types are associated with a context instance. The context internally
720 * deduplicates types so there is only 1 instance of a specific type
721 * alive at a time. In other words, a unique type is shared among all
722 * consumers within a context.
723 *
724 * A Type in the C API corresponds to llvm::Type.
725 *
726 * Types have the following hierarchy:
727 *
Gordon Henriksen76a03742007-09-18 03:18:57 +0000728 * types:
729 * integer type
730 * real type
731 * function type
732 * sequence types:
733 * array type
734 * pointer type
735 * vector type
736 * void type
737 * label type
738 * opaque type
Gregory Szorc34c863a2012-03-21 03:54:29 +0000739 *
740 * @{
Gordon Henriksen76a03742007-09-18 03:18:57 +0000741 */
742
Gregory Szorc34c863a2012-03-21 03:54:29 +0000743/**
744 * Obtain the enumerated type of a Type instance.
745 *
746 * @see llvm::Type:getTypeID()
747 */
Gordon Henriksen76a03742007-09-18 03:18:57 +0000748LLVMTypeKind LLVMGetTypeKind(LLVMTypeRef Ty);
Gregory Szorc34c863a2012-03-21 03:54:29 +0000749
750/**
751 * Whether the type has a known size.
752 *
753 * Things that don't have a size are abstract types, labels, and void.a
754 *
755 * @see llvm::Type::isSized()
756 */
Torok Edwin1cd9ade2011-10-06 12:13:28 +0000757LLVMBool LLVMTypeIsSized(LLVMTypeRef Ty);
Gordon Henriksena49d4352008-03-07 19:13:06 +0000758
Gregory Szorc34c863a2012-03-21 03:54:29 +0000759/**
760 * Obtain the context to which this type instance is associated.
761 *
762 * @see llvm::Type::getContext()
763 */
Erick Tryzelaar262332f2009-08-14 00:01:31 +0000764LLVMContextRef LLVMGetTypeContext(LLVMTypeRef Ty);
765
Gregory Szorc34c863a2012-03-21 03:54:29 +0000766/**
Anders Waldenborgb822cff2013-10-16 21:30:25 +0000767 * Dump a representation of a type to stderr.
768 *
769 * @see llvm::Type::dump()
770 */
771void LLVMDumpType(LLVMTypeRef Val);
772
773/**
Anders Waldenborg47b3bd32013-10-22 06:58:34 +0000774 * Return a string representation of the type. Use
775 * LLVMDisposeMessage to free the string.
776 *
777 * @see llvm::Type::print()
778 */
779char *LLVMPrintTypeToString(LLVMTypeRef Val);
780
781/**
Gregory Szorc34c863a2012-03-21 03:54:29 +0000782 * @defgroup LLVMCCoreTypeInt Integer Types
783 *
784 * Functions in this section operate on integer types.
785 *
786 * @{
787 */
788
789/**
790 * Obtain an integer type from a context with specified bit width.
791 */
Erick Tryzelaar262332f2009-08-14 00:01:31 +0000792LLVMTypeRef LLVMInt1TypeInContext(LLVMContextRef C);
793LLVMTypeRef LLVMInt8TypeInContext(LLVMContextRef C);
794LLVMTypeRef LLVMInt16TypeInContext(LLVMContextRef C);
795LLVMTypeRef LLVMInt32TypeInContext(LLVMContextRef C);
796LLVMTypeRef LLVMInt64TypeInContext(LLVMContextRef C);
Eugene Zelenkoffec81c2015-11-04 22:32:32 +0000797LLVMTypeRef LLVMInt128TypeInContext(LLVMContextRef C);
Erick Tryzelaar262332f2009-08-14 00:01:31 +0000798LLVMTypeRef LLVMIntTypeInContext(LLVMContextRef C, unsigned NumBits);
799
Gregory Szorc34c863a2012-03-21 03:54:29 +0000800/**
801 * Obtain an integer type from the global context with a specified bit
802 * width.
803 */
Gordon Henriksena735a9c2008-05-04 12:55:34 +0000804LLVMTypeRef LLVMInt1Type(void);
805LLVMTypeRef LLVMInt8Type(void);
806LLVMTypeRef LLVMInt16Type(void);
807LLVMTypeRef LLVMInt32Type(void);
808LLVMTypeRef LLVMInt64Type(void);
Eugene Zelenkoffec81c2015-11-04 22:32:32 +0000809LLVMTypeRef LLVMInt128Type(void);
Gordon Henriksened7beaa2007-10-06 16:05:20 +0000810LLVMTypeRef LLVMIntType(unsigned NumBits);
Gordon Henriksenc23b66c2007-09-26 20:56:12 +0000811unsigned LLVMGetIntTypeWidth(LLVMTypeRef IntegerTy);
Gordon Henriksen76a03742007-09-18 03:18:57 +0000812
Gregory Szorc34c863a2012-03-21 03:54:29 +0000813/**
814 * @}
815 */
816
817/**
818 * @defgroup LLVMCCoreTypeFloat Floating Point Types
819 *
820 * @{
821 */
822
823/**
824 * Obtain a 16-bit floating point type from a context.
825 */
Dan Gohman518cda42011-12-17 00:04:22 +0000826LLVMTypeRef LLVMHalfTypeInContext(LLVMContextRef C);
Gregory Szorc34c863a2012-03-21 03:54:29 +0000827
828/**
829 * Obtain a 32-bit floating point type from a context.
830 */
Erick Tryzelaar262332f2009-08-14 00:01:31 +0000831LLVMTypeRef LLVMFloatTypeInContext(LLVMContextRef C);
Gregory Szorc34c863a2012-03-21 03:54:29 +0000832
833/**
834 * Obtain a 64-bit floating point type from a context.
835 */
Erick Tryzelaar262332f2009-08-14 00:01:31 +0000836LLVMTypeRef LLVMDoubleTypeInContext(LLVMContextRef C);
Gregory Szorc34c863a2012-03-21 03:54:29 +0000837
838/**
839 * Obtain a 80-bit floating point type (X87) from a context.
840 */
Erick Tryzelaar262332f2009-08-14 00:01:31 +0000841LLVMTypeRef LLVMX86FP80TypeInContext(LLVMContextRef C);
Gregory Szorc34c863a2012-03-21 03:54:29 +0000842
843/**
844 * Obtain a 128-bit floating point type (112-bit mantissa) from a
845 * context.
846 */
Erick Tryzelaar262332f2009-08-14 00:01:31 +0000847LLVMTypeRef LLVMFP128TypeInContext(LLVMContextRef C);
Gregory Szorc34c863a2012-03-21 03:54:29 +0000848
849/**
850 * Obtain a 128-bit floating point type (two 64-bits) from a context.
851 */
Erick Tryzelaar262332f2009-08-14 00:01:31 +0000852LLVMTypeRef LLVMPPCFP128TypeInContext(LLVMContextRef C);
853
Gregory Szorc34c863a2012-03-21 03:54:29 +0000854/**
855 * Obtain a floating point type from the global context.
856 *
857 * These map to the functions in this group of the same name.
858 */
Dan Gohman518cda42011-12-17 00:04:22 +0000859LLVMTypeRef LLVMHalfType(void);
Gordon Henriksena735a9c2008-05-04 12:55:34 +0000860LLVMTypeRef LLVMFloatType(void);
861LLVMTypeRef LLVMDoubleType(void);
862LLVMTypeRef LLVMX86FP80Type(void);
863LLVMTypeRef LLVMFP128Type(void);
864LLVMTypeRef LLVMPPCFP128Type(void);
Gordon Henriksen76a03742007-09-18 03:18:57 +0000865
Gregory Szorc34c863a2012-03-21 03:54:29 +0000866/**
867 * @}
868 */
869
870/**
871 * @defgroup LLVMCCoreTypeFunction Function Types
872 *
873 * @{
874 */
875
876/**
877 * Obtain a function type consisting of a specified signature.
878 *
879 * The function is defined as a tuple of a return Type, a list of
880 * parameter types, and whether the function is variadic.
881 */
Gordon Henriksened7beaa2007-10-06 16:05:20 +0000882LLVMTypeRef LLVMFunctionType(LLVMTypeRef ReturnType,
883 LLVMTypeRef *ParamTypes, unsigned ParamCount,
Chris Lattner25963c62010-01-09 22:27:07 +0000884 LLVMBool IsVarArg);
Gregory Szorc34c863a2012-03-21 03:54:29 +0000885
886/**
887 * Returns whether a function type is variadic.
888 */
Chris Lattner25963c62010-01-09 22:27:07 +0000889LLVMBool LLVMIsFunctionVarArg(LLVMTypeRef FunctionTy);
Gregory Szorc34c863a2012-03-21 03:54:29 +0000890
891/**
892 * Obtain the Type this function Type returns.
893 */
Gordon Henriksenc23b66c2007-09-26 20:56:12 +0000894LLVMTypeRef LLVMGetReturnType(LLVMTypeRef FunctionTy);
Gregory Szorc34c863a2012-03-21 03:54:29 +0000895
896/**
897 * Obtain the number of parameters this function accepts.
898 */
Gordon Henriksenc23b66c2007-09-26 20:56:12 +0000899unsigned LLVMCountParamTypes(LLVMTypeRef FunctionTy);
Gregory Szorc34c863a2012-03-21 03:54:29 +0000900
901/**
902 * Obtain the types of a function's parameters.
903 *
904 * The Dest parameter should point to a pre-allocated array of
905 * LLVMTypeRef at least LLVMCountParamTypes() large. On return, the
906 * first LLVMCountParamTypes() entries in the array will be populated
907 * with LLVMTypeRef instances.
908 *
909 * @param FunctionTy The function type to operate on.
910 * @param Dest Memory address of an array to be filled with result.
911 */
Gordon Henriksenc23b66c2007-09-26 20:56:12 +0000912void LLVMGetParamTypes(LLVMTypeRef FunctionTy, LLVMTypeRef *Dest);
Gordon Henriksen76a03742007-09-18 03:18:57 +0000913
Gregory Szorc34c863a2012-03-21 03:54:29 +0000914/**
915 * @}
916 */
917
918/**
919 * @defgroup LLVMCCoreTypeStruct Structure Types
920 *
921 * These functions relate to LLVMTypeRef instances.
922 *
923 * @see llvm::StructType
924 *
925 * @{
926 */
927
928/**
929 * Create a new structure type in a context.
930 *
931 * A structure is specified by a list of inner elements/types and
932 * whether these can be packed together.
933 *
934 * @see llvm::StructType::create()
935 */
Erick Tryzelaar262332f2009-08-14 00:01:31 +0000936LLVMTypeRef LLVMStructTypeInContext(LLVMContextRef C, LLVMTypeRef *ElementTypes,
Chris Lattner25963c62010-01-09 22:27:07 +0000937 unsigned ElementCount, LLVMBool Packed);
Gregory Szorc34c863a2012-03-21 03:54:29 +0000938
939/**
940 * Create a new structure type in the global context.
941 *
942 * @see llvm::StructType::create()
943 */
Gordon Henriksened7beaa2007-10-06 16:05:20 +0000944LLVMTypeRef LLVMStructType(LLVMTypeRef *ElementTypes, unsigned ElementCount,
Chris Lattner25963c62010-01-09 22:27:07 +0000945 LLVMBool Packed);
Gregory Szorc34c863a2012-03-21 03:54:29 +0000946
947/**
948 * Create an empty structure in a context having a specified name.
949 *
950 * @see llvm::StructType::create()
951 */
Chris Lattnere71ccde2011-07-14 05:53:17 +0000952LLVMTypeRef LLVMStructCreateNamed(LLVMContextRef C, const char *Name);
Gregory Szorc34c863a2012-03-21 03:54:29 +0000953
954/**
955 * Obtain the name of a structure.
956 *
957 * @see llvm::StructType::getName()
958 */
Torok Edwin0d5f6ae2011-10-06 12:12:50 +0000959const char *LLVMGetStructName(LLVMTypeRef Ty);
Gregory Szorc34c863a2012-03-21 03:54:29 +0000960
961/**
962 * Set the contents of a structure type.
963 *
964 * @see llvm::StructType::setBody()
965 */
Chris Lattnere71ccde2011-07-14 05:53:17 +0000966void LLVMStructSetBody(LLVMTypeRef StructTy, LLVMTypeRef *ElementTypes,
967 unsigned ElementCount, LLVMBool Packed);
968
Gregory Szorc34c863a2012-03-21 03:54:29 +0000969/**
970 * Get the number of elements defined inside the structure.
971 *
972 * @see llvm::StructType::getNumElements()
973 */
Gordon Henriksenc23b66c2007-09-26 20:56:12 +0000974unsigned LLVMCountStructElementTypes(LLVMTypeRef StructTy);
Gregory Szorc34c863a2012-03-21 03:54:29 +0000975
976/**
977 * Get the elements within a structure.
978 *
979 * The function is passed the address of a pre-allocated array of
980 * LLVMTypeRef at least LLVMCountStructElementTypes() long. After
981 * invocation, this array will be populated with the structure's
982 * elements. The objects in the destination array will have a lifetime
983 * of the structure type itself, which is the lifetime of the context it
984 * is contained in.
985 */
Gordon Henriksen76a03742007-09-18 03:18:57 +0000986void LLVMGetStructElementTypes(LLVMTypeRef StructTy, LLVMTypeRef *Dest);
Gregory Szorc34c863a2012-03-21 03:54:29 +0000987
988/**
Peter Zotovc164a3f2015-06-04 09:09:53 +0000989 * Get the type of the element at a given index in the structure.
990 *
991 * @see llvm::StructType::getTypeAtIndex()
992 */
993LLVMTypeRef LLVMStructGetTypeAtIndex(LLVMTypeRef StructTy, unsigned i);
994
995/**
Gregory Szorc34c863a2012-03-21 03:54:29 +0000996 * Determine whether a structure is packed.
997 *
998 * @see llvm::StructType::isPacked()
999 */
Chris Lattner25963c62010-01-09 22:27:07 +00001000LLVMBool LLVMIsPackedStruct(LLVMTypeRef StructTy);
Gregory Szorc34c863a2012-03-21 03:54:29 +00001001
1002/**
1003 * Determine whether a structure is opaque.
1004 *
1005 * @see llvm::StructType::isOpaque()
1006 */
Chris Lattner17cf05b2011-07-14 16:20:28 +00001007LLVMBool LLVMIsOpaqueStruct(LLVMTypeRef StructTy);
1008
Gregory Szorc34c863a2012-03-21 03:54:29 +00001009/**
1010 * @}
1011 */
Gordon Henriksen76a03742007-09-18 03:18:57 +00001012
Gregory Szorc34c863a2012-03-21 03:54:29 +00001013/**
1014 * @defgroup LLVMCCoreTypeSequential Sequential Types
1015 *
1016 * Sequential types represents "arrays" of types. This is a super class
1017 * for array, vector, and pointer types.
1018 *
1019 * @{
1020 */
1021
1022/**
1023 * Obtain the type of elements within a sequential type.
1024 *
1025 * This works on array, vector, and pointer types.
1026 *
1027 * @see llvm::SequentialType::getElementType()
1028 */
1029LLVMTypeRef LLVMGetElementType(LLVMTypeRef Ty);
1030
1031/**
1032 * Create a fixed size array type that refers to a specific type.
1033 *
1034 * The created type will exist in the context that its element type
1035 * exists in.
1036 *
1037 * @see llvm::ArrayType::get()
1038 */
Gordon Henriksened7beaa2007-10-06 16:05:20 +00001039LLVMTypeRef LLVMArrayType(LLVMTypeRef ElementType, unsigned ElementCount);
Gregory Szorc34c863a2012-03-21 03:54:29 +00001040
1041/**
1042 * Obtain the length of an array type.
1043 *
1044 * This only works on types that represent arrays.
1045 *
1046 * @see llvm::ArrayType::getNumElements()
1047 */
1048unsigned LLVMGetArrayLength(LLVMTypeRef ArrayTy);
1049
1050/**
1051 * Create a pointer type that points to a defined type.
1052 *
1053 * The created type will exist in the context that its pointee type
1054 * exists in.
1055 *
1056 * @see llvm::PointerType::get()
1057 */
Gordon Henriksen5a3fe032007-12-17 16:08:32 +00001058LLVMTypeRef LLVMPointerType(LLVMTypeRef ElementType, unsigned AddressSpace);
Gregory Szorc34c863a2012-03-21 03:54:29 +00001059
1060/**
1061 * Obtain the address space of a pointer type.
1062 *
1063 * This only works on types that represent pointers.
1064 *
1065 * @see llvm::PointerType::getAddressSpace()
1066 */
1067unsigned LLVMGetPointerAddressSpace(LLVMTypeRef PointerTy);
1068
1069/**
1070 * Create a vector type that contains a defined type and has a specific
1071 * number of elements.
1072 *
1073 * The created type will exist in the context thats its element type
1074 * exists in.
1075 *
1076 * @see llvm::VectorType::get()
1077 */
Gordon Henriksened7beaa2007-10-06 16:05:20 +00001078LLVMTypeRef LLVMVectorType(LLVMTypeRef ElementType, unsigned ElementCount);
Gordon Henriksen76a03742007-09-18 03:18:57 +00001079
Gregory Szorc34c863a2012-03-21 03:54:29 +00001080/**
1081 * Obtain the number of elements in a vector type.
1082 *
1083 * This only works on types that represent vectors.
1084 *
1085 * @see llvm::VectorType::getNumElements()
1086 */
Gordon Henriksen76a03742007-09-18 03:18:57 +00001087unsigned LLVMGetVectorSize(LLVMTypeRef VectorTy);
1088
Gregory Szorc34c863a2012-03-21 03:54:29 +00001089/**
1090 * @}
1091 */
1092
1093/**
1094 * @defgroup LLVMCCoreTypeOther Other Types
1095 *
1096 * @{
1097 */
1098
1099/**
1100 * Create a void type in a context.
1101 */
Erick Tryzelaar262332f2009-08-14 00:01:31 +00001102LLVMTypeRef LLVMVoidTypeInContext(LLVMContextRef C);
Gregory Szorc34c863a2012-03-21 03:54:29 +00001103
1104/**
1105 * Create a label type in a context.
1106 */
Erick Tryzelaar262332f2009-08-14 00:01:31 +00001107LLVMTypeRef LLVMLabelTypeInContext(LLVMContextRef C);
Gregory Szorc34c863a2012-03-21 03:54:29 +00001108
1109/**
1110 * Create a X86 MMX type in a context.
1111 */
Dale Johannesen95b67af2010-09-10 21:58:02 +00001112LLVMTypeRef LLVMX86MMXTypeInContext(LLVMContextRef C);
Erick Tryzelaar262332f2009-08-14 00:01:31 +00001113
Gregory Szorc34c863a2012-03-21 03:54:29 +00001114/**
1115 * These are similar to the above functions except they operate on the
1116 * global context.
1117 */
Gordon Henriksena735a9c2008-05-04 12:55:34 +00001118LLVMTypeRef LLVMVoidType(void);
1119LLVMTypeRef LLVMLabelType(void);
Dale Johannesen95b67af2010-09-10 21:58:02 +00001120LLVMTypeRef LLVMX86MMXType(void);
Gordon Henriksen76a03742007-09-18 03:18:57 +00001121
Gregory Szorc34c863a2012-03-21 03:54:29 +00001122/**
1123 * @}
1124 */
Gordon Henriksen76a03742007-09-18 03:18:57 +00001125
Gregory Szorc34c863a2012-03-21 03:54:29 +00001126/**
1127 * @}
1128 */
1129
1130/**
1131 * @defgroup LLVMCCoreValues Values
1132 *
1133 * The bulk of LLVM's object model consists of values, which comprise a very
Gordon Henriksen76a03742007-09-18 03:18:57 +00001134 * rich type hierarchy.
Gregory Szorc34c863a2012-03-21 03:54:29 +00001135 *
1136 * LLVMValueRef essentially represents llvm::Value. There is a rich
1137 * hierarchy of classes within this type. Depending on the instance
Eli Benderskyc52863c2012-08-10 18:30:44 +00001138 * obtained, not all APIs are available.
Gregory Szorc34c863a2012-03-21 03:54:29 +00001139 *
Daniel Dunbar06b9f9e2013-08-16 23:30:19 +00001140 * Callers can determine the type of an LLVMValueRef by calling the
Gregory Szorc34c863a2012-03-21 03:54:29 +00001141 * LLVMIsA* family of functions (e.g. LLVMIsAArgument()). These
1142 * functions are defined by a macro, so it isn't obvious which are
1143 * available by looking at the Doxygen source code. Instead, look at the
1144 * source definition of LLVM_FOR_EACH_VALUE_SUBCLASS and note the list
1145 * of value names given. These value names also correspond to classes in
1146 * the llvm::Value hierarchy.
1147 *
1148 * @{
Gordon Henriksen76a03742007-09-18 03:18:57 +00001149 */
1150
Gordon Henriksen29e38942008-12-19 18:39:45 +00001151#define LLVM_FOR_EACH_VALUE_SUBCLASS(macro) \
1152 macro(Argument) \
1153 macro(BasicBlock) \
1154 macro(InlineAsm) \
1155 macro(User) \
1156 macro(Constant) \
Torok Edwind09b7572011-10-14 20:37:56 +00001157 macro(BlockAddress) \
Gordon Henriksen29e38942008-12-19 18:39:45 +00001158 macro(ConstantAggregateZero) \
1159 macro(ConstantArray) \
Peter Zotovae0344b2013-11-05 12:55:37 +00001160 macro(ConstantDataSequential) \
1161 macro(ConstantDataArray) \
1162 macro(ConstantDataVector) \
Gordon Henriksen29e38942008-12-19 18:39:45 +00001163 macro(ConstantExpr) \
1164 macro(ConstantFP) \
1165 macro(ConstantInt) \
1166 macro(ConstantPointerNull) \
1167 macro(ConstantStruct) \
David Majnemerf0f224d2015-11-11 21:57:16 +00001168 macro(ConstantTokenNone) \
Gordon Henriksen29e38942008-12-19 18:39:45 +00001169 macro(ConstantVector) \
1170 macro(GlobalValue) \
Gordon Henriksen29e38942008-12-19 18:39:45 +00001171 macro(GlobalAlias) \
Rafael Espindola99e05cf2014-05-13 18:45:48 +00001172 macro(GlobalObject) \
1173 macro(Function) \
1174 macro(GlobalVariable) \
Gordon Henriksen29e38942008-12-19 18:39:45 +00001175 macro(UndefValue) \
1176 macro(Instruction) \
1177 macro(BinaryOperator) \
1178 macro(CallInst) \
1179 macro(IntrinsicInst) \
1180 macro(DbgInfoIntrinsic) \
1181 macro(DbgDeclareInst) \
Gordon Henriksen29e38942008-12-19 18:39:45 +00001182 macro(MemIntrinsic) \
1183 macro(MemCpyInst) \
1184 macro(MemMoveInst) \
1185 macro(MemSetInst) \
1186 macro(CmpInst) \
Torok Edwind09b7572011-10-14 20:37:56 +00001187 macro(FCmpInst) \
1188 macro(ICmpInst) \
Gordon Henriksen29e38942008-12-19 18:39:45 +00001189 macro(ExtractElementInst) \
1190 macro(GetElementPtrInst) \
1191 macro(InsertElementInst) \
1192 macro(InsertValueInst) \
Bill Wendlingfae14752011-08-12 20:24:12 +00001193 macro(LandingPadInst) \
Gordon Henriksen29e38942008-12-19 18:39:45 +00001194 macro(PHINode) \
1195 macro(SelectInst) \
1196 macro(ShuffleVectorInst) \
1197 macro(StoreInst) \
1198 macro(TerminatorInst) \
1199 macro(BranchInst) \
Torok Edwind09b7572011-10-14 20:37:56 +00001200 macro(IndirectBrInst) \
Gordon Henriksen29e38942008-12-19 18:39:45 +00001201 macro(InvokeInst) \
1202 macro(ReturnInst) \
1203 macro(SwitchInst) \
1204 macro(UnreachableInst) \
Bill Wendlingf891bf82011-07-31 06:30:59 +00001205 macro(ResumeInst) \
David Majnemer654e1302015-07-31 17:58:14 +00001206 macro(CleanupReturnInst) \
1207 macro(CatchReturnInst) \
David Majnemer8a1c45d2015-12-12 05:38:55 +00001208 macro(FuncletPadInst) \
1209 macro(CatchPadInst) \
1210 macro(CleanupPadInst) \
Duncan Sands5e37e992013-05-06 08:55:45 +00001211 macro(UnaryInstruction) \
1212 macro(AllocaInst) \
1213 macro(CastInst) \
Matt Arsenaultb03bd4d2013-11-15 01:34:59 +00001214 macro(AddrSpaceCastInst) \
Duncan Sands5e37e992013-05-06 08:55:45 +00001215 macro(BitCastInst) \
1216 macro(FPExtInst) \
1217 macro(FPToSIInst) \
1218 macro(FPToUIInst) \
1219 macro(FPTruncInst) \
1220 macro(IntToPtrInst) \
1221 macro(PtrToIntInst) \
1222 macro(SExtInst) \
1223 macro(SIToFPInst) \
1224 macro(TruncInst) \
1225 macro(UIToFPInst) \
1226 macro(ZExtInst) \
1227 macro(ExtractValueInst) \
1228 macro(LoadInst) \
1229 macro(VAArgInst)
Gordon Henriksen29e38942008-12-19 18:39:45 +00001230
Gregory Szorc34c863a2012-03-21 03:54:29 +00001231/**
1232 * @defgroup LLVMCCoreValueGeneral General APIs
1233 *
1234 * Functions in this section work on all LLVMValueRef instances,
1235 * regardless of their sub-type. They correspond to functions available
1236 * on llvm::Value.
1237 *
1238 * @{
1239 */
Gordon Henriksen76a03742007-09-18 03:18:57 +00001240
Gregory Szorc34c863a2012-03-21 03:54:29 +00001241/**
1242 * Obtain the type of a value.
1243 *
1244 * @see llvm::Value::getType()
1245 */
1246LLVMTypeRef LLVMTypeOf(LLVMValueRef Val);
1247
1248/**
Peter Zotov3e4561c2016-04-06 22:21:29 +00001249 * Obtain the enumerated type of a Value instance.
1250 *
1251 * @see llvm::Value::getValueID()
1252 */
1253LLVMValueKind LLVMGetValueKind(LLVMValueRef Val);
1254
1255/**
Gregory Szorc34c863a2012-03-21 03:54:29 +00001256 * Obtain the string name of a value.
1257 *
1258 * @see llvm::Value::getName()
1259 */
1260const char *LLVMGetValueName(LLVMValueRef Val);
1261
1262/**
1263 * Set the string name of a value.
1264 *
1265 * @see llvm::Value::setName()
1266 */
1267void LLVMSetValueName(LLVMValueRef Val, const char *Name);
1268
1269/**
1270 * Dump a representation of a value to stderr.
1271 *
1272 * @see llvm::Value::dump()
1273 */
1274void LLVMDumpValue(LLVMValueRef Val);
1275
1276/**
Peter Zotovcd93b372013-11-06 09:21:01 +00001277 * Return a string representation of the value. Use
1278 * LLVMDisposeMessage to free the string.
1279 *
1280 * @see llvm::Value::print()
1281 */
1282char *LLVMPrintValueToString(LLVMValueRef Val);
1283
1284/**
Gregory Szorc34c863a2012-03-21 03:54:29 +00001285 * Replace all uses of a value with another one.
1286 *
1287 * @see llvm::Value::replaceAllUsesWith()
1288 */
1289void LLVMReplaceAllUsesWith(LLVMValueRef OldVal, LLVMValueRef NewVal);
1290
1291/**
Amaury Sechet1c395072016-01-18 01:06:52 +00001292 * Determine whether the specified value instance is constant.
Gregory Szorc34c863a2012-03-21 03:54:29 +00001293 */
1294LLVMBool LLVMIsConstant(LLVMValueRef Val);
1295
1296/**
1297 * Determine whether a value instance is undefined.
1298 */
1299LLVMBool LLVMIsUndef(LLVMValueRef Val);
1300
1301/**
1302 * Convert value instances between types.
1303 *
Daniel Dunbar06b9f9e2013-08-16 23:30:19 +00001304 * Internally, an LLVMValueRef is "pinned" to a specific type. This
Gregory Szorc34c863a2012-03-21 03:54:29 +00001305 * series of functions allows you to cast an instance to a specific
1306 * type.
1307 *
1308 * If the cast is not valid for the specified type, NULL is returned.
1309 *
1310 * @see llvm::dyn_cast_or_null<>
1311 */
Gordon Henriksen29e38942008-12-19 18:39:45 +00001312#define LLVM_DECLARE_VALUE_CAST(name) \
1313 LLVMValueRef LLVMIsA##name(LLVMValueRef Val);
1314LLVM_FOR_EACH_VALUE_SUBCLASS(LLVM_DECLARE_VALUE_CAST)
1315
Duncan P. N. Exon Smith5bf8fef2014-12-09 18:38:53 +00001316LLVMValueRef LLVMIsAMDNode(LLVMValueRef Val);
1317LLVMValueRef LLVMIsAMDString(LLVMValueRef Val);
1318
Gregory Szorc34c863a2012-03-21 03:54:29 +00001319/**
1320 * @}
1321 */
1322
1323/**
1324 * @defgroup LLVMCCoreValueUses Usage
1325 *
1326 * This module defines functions that allow you to inspect the uses of a
1327 * LLVMValueRef.
1328 *
Daniel Dunbar06b9f9e2013-08-16 23:30:19 +00001329 * It is possible to obtain an LLVMUseRef for any LLVMValueRef instance.
Gregory Szorc34c863a2012-03-21 03:54:29 +00001330 * Each LLVMUseRef (which corresponds to a llvm::Use instance) holds a
1331 * llvm::User and llvm::Value.
1332 *
1333 * @{
1334 */
1335
1336/**
1337 * Obtain the first use of a value.
1338 *
1339 * Uses are obtained in an iterator fashion. First, call this function
1340 * to obtain a reference to the first use. Then, call LLVMGetNextUse()
Eli Benderskyc52863c2012-08-10 18:30:44 +00001341 * on that instance and all subsequently obtained instances until
Gregory Szorc34c863a2012-03-21 03:54:29 +00001342 * LLVMGetNextUse() returns NULL.
1343 *
1344 * @see llvm::Value::use_begin()
1345 */
Erick Tryzelaar9f9857e2010-03-02 20:32:28 +00001346LLVMUseRef LLVMGetFirstUse(LLVMValueRef Val);
Gregory Szorc34c863a2012-03-21 03:54:29 +00001347
1348/**
1349 * Obtain the next use of a value.
1350 *
1351 * This effectively advances the iterator. It returns NULL if you are on
1352 * the final use and no more are available.
1353 */
Erick Tryzelaar9f9857e2010-03-02 20:32:28 +00001354LLVMUseRef LLVMGetNextUse(LLVMUseRef U);
Gregory Szorc34c863a2012-03-21 03:54:29 +00001355
1356/**
1357 * Obtain the user value for a user.
1358 *
1359 * The returned value corresponds to a llvm::User type.
1360 *
1361 * @see llvm::Use::getUser()
1362 */
Erick Tryzelaar9f9857e2010-03-02 20:32:28 +00001363LLVMValueRef LLVMGetUser(LLVMUseRef U);
Gregory Szorc34c863a2012-03-21 03:54:29 +00001364
1365/**
1366 * Obtain the value this use corresponds to.
1367 *
1368 * @see llvm::Use::get().
1369 */
Erick Tryzelaar9f9857e2010-03-02 20:32:28 +00001370LLVMValueRef LLVMGetUsedValue(LLVMUseRef U);
Chris Lattner40cf28d2009-10-12 04:01:02 +00001371
Gregory Szorc34c863a2012-03-21 03:54:29 +00001372/**
1373 * @}
1374 */
1375
1376/**
Gregory Szorc52d26602012-03-21 07:28:27 +00001377 * @defgroup LLVMCCoreValueUser User value
Gregory Szorc34c863a2012-03-21 03:54:29 +00001378 *
1379 * Function in this group pertain to LLVMValueRef instances that descent
1380 * from llvm::User. This includes constants, instructions, and
1381 * operators.
1382 *
1383 * @{
1384 */
1385
1386/**
1387 * Obtain an operand at a specific index in a llvm::User value.
1388 *
1389 * @see llvm::User::getOperand()
1390 */
Chris Lattner40cf28d2009-10-12 04:01:02 +00001391LLVMValueRef LLVMGetOperand(LLVMValueRef Val, unsigned Index);
Gregory Szorc34c863a2012-03-21 03:54:29 +00001392
1393/**
Peter Zotovb19f78f2014-08-12 02:55:40 +00001394 * Obtain the use of an operand at a specific index in a llvm::User value.
1395 *
1396 * @see llvm::User::getOperandUse()
1397 */
1398LLVMUseRef LLVMGetOperandUse(LLVMValueRef Val, unsigned Index);
1399
1400/**
Gregory Szorc34c863a2012-03-21 03:54:29 +00001401 * Set an operand at a specific index in a llvm::User value.
1402 *
1403 * @see llvm::User::setOperand()
1404 */
Erick Tryzelaarb4d48702010-08-20 14:51:22 +00001405void LLVMSetOperand(LLVMValueRef User, unsigned Index, LLVMValueRef Val);
Gregory Szorc34c863a2012-03-21 03:54:29 +00001406
1407/**
1408 * Obtain the number of operands in a llvm::User value.
1409 *
1410 * @see llvm::User::getNumOperands()
1411 */
Erick Tryzelaarb4d48702010-08-20 14:51:22 +00001412int LLVMGetNumOperands(LLVMValueRef Val);
Chris Lattner40cf28d2009-10-12 04:01:02 +00001413
Gregory Szorc34c863a2012-03-21 03:54:29 +00001414/**
1415 * @}
1416 */
1417
1418/**
Gregory Szorc52d26602012-03-21 07:28:27 +00001419 * @defgroup LLVMCCoreValueConstant Constants
Gregory Szorc34c863a2012-03-21 03:54:29 +00001420 *
1421 * This section contains APIs for interacting with LLVMValueRef that
1422 * correspond to llvm::Constant instances.
1423 *
1424 * These functions will work for any LLVMValueRef in the llvm::Constant
1425 * class hierarchy.
1426 *
1427 * @{
1428 */
1429
1430/**
1431 * Obtain a constant value referring to the null instance of a type.
1432 *
1433 * @see llvm::Constant::getNullValue()
1434 */
Gordon Henriksen1046c732007-10-06 15:11:06 +00001435LLVMValueRef LLVMConstNull(LLVMTypeRef Ty); /* all zeroes */
Gregory Szorc34c863a2012-03-21 03:54:29 +00001436
1437/**
1438 * Obtain a constant value referring to the instance of a type
1439 * consisting of all ones.
1440 *
1441 * This is only valid for integer types.
1442 *
1443 * @see llvm::Constant::getAllOnesValue()
1444 */
1445LLVMValueRef LLVMConstAllOnes(LLVMTypeRef Ty);
1446
1447/**
1448 * Obtain a constant value referring to an undefined value of a type.
1449 *
1450 * @see llvm::UndefValue::get()
1451 */
Gordon Henriksen76a03742007-09-18 03:18:57 +00001452LLVMValueRef LLVMGetUndef(LLVMTypeRef Ty);
Gregory Szorc34c863a2012-03-21 03:54:29 +00001453
1454/**
1455 * Determine whether a value instance is null.
1456 *
1457 * @see llvm::Constant::isNullValue()
1458 */
Chris Lattner25963c62010-01-09 22:27:07 +00001459LLVMBool LLVMIsNull(LLVMValueRef Val);
Gregory Szorc34c863a2012-03-21 03:54:29 +00001460
1461/**
1462 * Obtain a constant that is a constant pointer pointing to NULL for a
1463 * specified type.
1464 */
Chris Lattner7f318242009-07-06 17:29:59 +00001465LLVMValueRef LLVMConstPointerNull(LLVMTypeRef Ty);
Gordon Henriksen76a03742007-09-18 03:18:57 +00001466
Gregory Szorc34c863a2012-03-21 03:54:29 +00001467/**
1468 * @defgroup LLVMCCoreValueConstantScalar Scalar constants
1469 *
1470 * Functions in this group model LLVMValueRef instances that correspond
1471 * to constants referring to scalar types.
1472 *
1473 * For integer types, the LLVMTypeRef parameter should correspond to a
1474 * llvm::IntegerType instance and the returned LLVMValueRef will
1475 * correspond to a llvm::ConstantInt.
1476 *
1477 * For floating point types, the LLVMTypeRef returned corresponds to a
1478 * llvm::ConstantFP.
1479 *
1480 * @{
1481 */
Erick Tryzelaard8531fa2010-02-28 09:45:59 +00001482
Gregory Szorc34c863a2012-03-21 03:54:29 +00001483/**
1484 * Obtain a constant value for an integer type.
1485 *
1486 * The returned value corresponds to a llvm::ConstantInt.
1487 *
1488 * @see llvm::ConstantInt::get()
1489 *
1490 * @param IntTy Integer type to obtain value of.
1491 * @param N The value the returned instance should refer to.
1492 * @param SignExtend Whether to sign extend the produced value.
1493 */
Gordon Henriksen1046c732007-10-06 15:11:06 +00001494LLVMValueRef LLVMConstInt(LLVMTypeRef IntTy, unsigned long long N,
Chris Lattner25963c62010-01-09 22:27:07 +00001495 LLVMBool SignExtend);
Gregory Szorc34c863a2012-03-21 03:54:29 +00001496
1497/**
1498 * Obtain a constant value for an integer of arbitrary precision.
1499 *
1500 * @see llvm::ConstantInt::get()
1501 */
Chris Lattner4329e072010-11-23 02:47:22 +00001502LLVMValueRef LLVMConstIntOfArbitraryPrecision(LLVMTypeRef IntTy,
1503 unsigned NumWords,
1504 const uint64_t Words[]);
Gregory Szorc34c863a2012-03-21 03:54:29 +00001505
1506/**
1507 * Obtain a constant value for an integer parsed from a string.
1508 *
1509 * A similar API, LLVMConstIntOfStringAndSize is also available. If the
1510 * string's length is available, it is preferred to call that function
1511 * instead.
1512 *
1513 * @see llvm::ConstantInt::get()
1514 */
Erick Tryzelaardd991352009-08-16 23:36:46 +00001515LLVMValueRef LLVMConstIntOfString(LLVMTypeRef IntTy, const char *Text,
1516 uint8_t Radix);
Gregory Szorc34c863a2012-03-21 03:54:29 +00001517
1518/**
1519 * Obtain a constant value for an integer parsed from a string with
1520 * specified length.
1521 *
1522 * @see llvm::ConstantInt::get()
1523 */
Erick Tryzelaardd991352009-08-16 23:36:46 +00001524LLVMValueRef LLVMConstIntOfStringAndSize(LLVMTypeRef IntTy, const char *Text,
1525 unsigned SLen, uint8_t Radix);
Gregory Szorc34c863a2012-03-21 03:54:29 +00001526
1527/**
1528 * Obtain a constant value referring to a double floating point value.
1529 */
Gordon Henriksen1046c732007-10-06 15:11:06 +00001530LLVMValueRef LLVMConstReal(LLVMTypeRef RealTy, double N);
Gregory Szorc34c863a2012-03-21 03:54:29 +00001531
1532/**
1533 * Obtain a constant for a floating point value parsed from a string.
1534 *
1535 * A similar API, LLVMConstRealOfStringAndSize is also available. It
1536 * should be used if the input string's length is known.
1537 */
Gordon Henriksen931e1212008-02-02 01:07:50 +00001538LLVMValueRef LLVMConstRealOfString(LLVMTypeRef RealTy, const char *Text);
Gregory Szorc34c863a2012-03-21 03:54:29 +00001539
1540/**
1541 * Obtain a constant for a floating point value parsed from a string.
1542 */
Erick Tryzelaardd991352009-08-16 23:36:46 +00001543LLVMValueRef LLVMConstRealOfStringAndSize(LLVMTypeRef RealTy, const char *Text,
1544 unsigned SLen);
Gregory Szorc34c863a2012-03-21 03:54:29 +00001545
1546/**
1547 * Obtain the zero extended value for an integer constant value.
1548 *
1549 * @see llvm::ConstantInt::getZExtValue()
1550 */
Chris Lattner40cf28d2009-10-12 04:01:02 +00001551unsigned long long LLVMConstIntGetZExtValue(LLVMValueRef ConstantVal);
Gregory Szorc34c863a2012-03-21 03:54:29 +00001552
1553/**
1554 * Obtain the sign extended value for an integer constant value.
1555 *
1556 * @see llvm::ConstantInt::getSExtValue()
1557 */
Chris Lattner40cf28d2009-10-12 04:01:02 +00001558long long LLVMConstIntGetSExtValue(LLVMValueRef ConstantVal);
Erick Tryzelaardd991352009-08-16 23:36:46 +00001559
Gregory Szorc34c863a2012-03-21 03:54:29 +00001560/**
Peter Zotov1d98e6d2014-10-28 19:46:44 +00001561 * Obtain the double value for an floating point constant value.
1562 * losesInfo indicates if some precision was lost in the conversion.
1563 *
1564 * @see llvm::ConstantFP::getDoubleValue
1565 */
1566double LLVMConstRealGetDouble(LLVMValueRef ConstantVal, LLVMBool *losesInfo);
1567
1568/**
Gregory Szorc34c863a2012-03-21 03:54:29 +00001569 * @}
1570 */
1571
1572/**
Gregory Szorc52d26602012-03-21 07:28:27 +00001573 * @defgroup LLVMCCoreValueConstantComposite Composite Constants
1574 *
1575 * Functions in this group operate on composite constants.
Gregory Szorc34c863a2012-03-21 03:54:29 +00001576 *
1577 * @{
1578 */
1579
1580/**
Gregory Szorc52d26602012-03-21 07:28:27 +00001581 * Create a ConstantDataSequential and initialize it with a string.
Gregory Szorc34c863a2012-03-21 03:54:29 +00001582 *
Gregory Szorc52d26602012-03-21 07:28:27 +00001583 * @see llvm::ConstantDataArray::getString()
Gregory Szorc34c863a2012-03-21 03:54:29 +00001584 */
Erick Tryzelaar262332f2009-08-14 00:01:31 +00001585LLVMValueRef LLVMConstStringInContext(LLVMContextRef C, const char *Str,
Chris Lattner25963c62010-01-09 22:27:07 +00001586 unsigned Length, LLVMBool DontNullTerminate);
Gregory Szorc52d26602012-03-21 07:28:27 +00001587
1588/**
1589 * Create a ConstantDataSequential with string content in the global context.
1590 *
1591 * This is the same as LLVMConstStringInContext except it operates on the
1592 * global context.
1593 *
1594 * @see LLVMConstStringInContext()
1595 * @see llvm::ConstantDataArray::getString()
1596 */
1597LLVMValueRef LLVMConstString(const char *Str, unsigned Length,
1598 LLVMBool DontNullTerminate);
1599
1600/**
Peter Zotovf9aa8822014-08-03 23:54:16 +00001601 * Returns true if the specified constant is an array of i8.
1602 *
1603 * @see ConstantDataSequential::getAsString()
1604 */
1605LLVMBool LLVMIsConstantString(LLVMValueRef c);
1606
1607/**
1608 * Get the given constant data sequential as a string.
1609 *
1610 * @see ConstantDataSequential::getAsString()
1611 */
Amaury Sechet7c2883c2016-04-03 21:06:04 +00001612const char *LLVMGetAsString(LLVMValueRef c, size_t *Length);
Peter Zotovf9aa8822014-08-03 23:54:16 +00001613
1614/**
Gregory Szorc52d26602012-03-21 07:28:27 +00001615 * Create an anonymous ConstantStruct with the specified values.
1616 *
1617 * @see llvm::ConstantStruct::getAnon()
1618 */
1619LLVMValueRef LLVMConstStructInContext(LLVMContextRef C,
Erick Tryzelaar262332f2009-08-14 00:01:31 +00001620 LLVMValueRef *ConstantVals,
Chris Lattner25963c62010-01-09 22:27:07 +00001621 unsigned Count, LLVMBool Packed);
Erick Tryzelaar262332f2009-08-14 00:01:31 +00001622
Gregory Szorc52d26602012-03-21 07:28:27 +00001623/**
1624 * Create a ConstantStruct in the global Context.
1625 *
1626 * This is the same as LLVMConstStructInContext except it operates on the
1627 * global Context.
1628 *
1629 * @see LLVMConstStructInContext()
1630 */
Gordon Henriksen1046c732007-10-06 15:11:06 +00001631LLVMValueRef LLVMConstStruct(LLVMValueRef *ConstantVals, unsigned Count,
Chris Lattner25963c62010-01-09 22:27:07 +00001632 LLVMBool Packed);
Gregory Szorc52d26602012-03-21 07:28:27 +00001633
1634/**
1635 * Create a ConstantArray from values.
1636 *
1637 * @see llvm::ConstantArray::get()
1638 */
1639LLVMValueRef LLVMConstArray(LLVMTypeRef ElementTy,
1640 LLVMValueRef *ConstantVals, unsigned Length);
1641
1642/**
1643 * Create a non-anonymous ConstantStruct from values.
1644 *
1645 * @see llvm::ConstantStruct::get()
1646 */
Rafael Espindola784ad242011-07-14 19:09:08 +00001647LLVMValueRef LLVMConstNamedStruct(LLVMTypeRef StructTy,
1648 LLVMValueRef *ConstantVals,
1649 unsigned Count);
Gregory Szorc52d26602012-03-21 07:28:27 +00001650
1651/**
Peter Zotovf9aa8822014-08-03 23:54:16 +00001652 * Get an element at specified index as a constant.
1653 *
1654 * @see ConstantDataSequential::getElementAsConstant()
1655 */
Amaury Sechet006ce632016-03-13 00:54:40 +00001656LLVMValueRef LLVMGetElementAsConstant(LLVMValueRef C, unsigned idx);
Peter Zotovf9aa8822014-08-03 23:54:16 +00001657
1658/**
Gregory Szorc52d26602012-03-21 07:28:27 +00001659 * Create a ConstantVector from values.
1660 *
1661 * @see llvm::ConstantVector::get()
1662 */
Gordon Henriksen1046c732007-10-06 15:11:06 +00001663LLVMValueRef LLVMConstVector(LLVMValueRef *ScalarConstantVals, unsigned Size);
Gordon Henriksen76a03742007-09-18 03:18:57 +00001664
Gregory Szorc52d26602012-03-21 07:28:27 +00001665/**
1666 * @}
1667 */
1668
1669/**
1670 * @defgroup LLVMCCoreValueConstantExpressions Constant Expressions
1671 *
1672 * Functions in this group correspond to APIs on llvm::ConstantExpr.
1673 *
1674 * @see llvm::ConstantExpr.
1675 *
1676 * @{
1677 */
Chris Lattner40cf28d2009-10-12 04:01:02 +00001678LLVMOpcode LLVMGetConstOpcode(LLVMValueRef ConstantVal);
Erick Tryzelaarfd529d72009-08-19 08:36:49 +00001679LLVMValueRef LLVMAlignOf(LLVMTypeRef Ty);
Gordon Henriksen7ce31762007-10-06 14:29:36 +00001680LLVMValueRef LLVMSizeOf(LLVMTypeRef Ty);
1681LLVMValueRef LLVMConstNeg(LLVMValueRef ConstantVal);
Erick Tryzelaar4c340c72010-02-28 05:51:43 +00001682LLVMValueRef LLVMConstNSWNeg(LLVMValueRef ConstantVal);
1683LLVMValueRef LLVMConstNUWNeg(LLVMValueRef ConstantVal);
Erick Tryzelaar4cc690c2009-08-16 02:20:12 +00001684LLVMValueRef LLVMConstFNeg(LLVMValueRef ConstantVal);
Gordon Henriksen7ce31762007-10-06 14:29:36 +00001685LLVMValueRef LLVMConstNot(LLVMValueRef ConstantVal);
1686LLVMValueRef LLVMConstAdd(LLVMValueRef LHSConstant, LLVMValueRef RHSConstant);
Dan Gohmane4ca02d2009-09-03 23:34:49 +00001687LLVMValueRef LLVMConstNSWAdd(LLVMValueRef LHSConstant, LLVMValueRef RHSConstant);
Erick Tryzelaar4c340c72010-02-28 05:51:43 +00001688LLVMValueRef LLVMConstNUWAdd(LLVMValueRef LHSConstant, LLVMValueRef RHSConstant);
Erick Tryzelaar4cc690c2009-08-16 02:20:12 +00001689LLVMValueRef LLVMConstFAdd(LLVMValueRef LHSConstant, LLVMValueRef RHSConstant);
Gordon Henriksen7ce31762007-10-06 14:29:36 +00001690LLVMValueRef LLVMConstSub(LLVMValueRef LHSConstant, LLVMValueRef RHSConstant);
Erick Tryzelaar4c340c72010-02-28 05:51:43 +00001691LLVMValueRef LLVMConstNSWSub(LLVMValueRef LHSConstant, LLVMValueRef RHSConstant);
1692LLVMValueRef LLVMConstNUWSub(LLVMValueRef LHSConstant, LLVMValueRef RHSConstant);
Erick Tryzelaar4cc690c2009-08-16 02:20:12 +00001693LLVMValueRef LLVMConstFSub(LLVMValueRef LHSConstant, LLVMValueRef RHSConstant);
Gordon Henriksen7ce31762007-10-06 14:29:36 +00001694LLVMValueRef LLVMConstMul(LLVMValueRef LHSConstant, LLVMValueRef RHSConstant);
Erick Tryzelaar4c340c72010-02-28 05:51:43 +00001695LLVMValueRef LLVMConstNSWMul(LLVMValueRef LHSConstant, LLVMValueRef RHSConstant);
1696LLVMValueRef LLVMConstNUWMul(LLVMValueRef LHSConstant, LLVMValueRef RHSConstant);
Erick Tryzelaar4cc690c2009-08-16 02:20:12 +00001697LLVMValueRef LLVMConstFMul(LLVMValueRef LHSConstant, LLVMValueRef RHSConstant);
Gordon Henriksen7ce31762007-10-06 14:29:36 +00001698LLVMValueRef LLVMConstUDiv(LLVMValueRef LHSConstant, LLVMValueRef RHSConstant);
1699LLVMValueRef LLVMConstSDiv(LLVMValueRef LHSConstant, LLVMValueRef RHSConstant);
Dan Gohmane4ca02d2009-09-03 23:34:49 +00001700LLVMValueRef LLVMConstExactSDiv(LLVMValueRef LHSConstant, LLVMValueRef RHSConstant);
Gordon Henriksen7ce31762007-10-06 14:29:36 +00001701LLVMValueRef LLVMConstFDiv(LLVMValueRef LHSConstant, LLVMValueRef RHSConstant);
1702LLVMValueRef LLVMConstURem(LLVMValueRef LHSConstant, LLVMValueRef RHSConstant);
1703LLVMValueRef LLVMConstSRem(LLVMValueRef LHSConstant, LLVMValueRef RHSConstant);
1704LLVMValueRef LLVMConstFRem(LLVMValueRef LHSConstant, LLVMValueRef RHSConstant);
1705LLVMValueRef LLVMConstAnd(LLVMValueRef LHSConstant, LLVMValueRef RHSConstant);
1706LLVMValueRef LLVMConstOr(LLVMValueRef LHSConstant, LLVMValueRef RHSConstant);
1707LLVMValueRef LLVMConstXor(LLVMValueRef LHSConstant, LLVMValueRef RHSConstant);
1708LLVMValueRef LLVMConstICmp(LLVMIntPredicate Predicate,
1709 LLVMValueRef LHSConstant, LLVMValueRef RHSConstant);
1710LLVMValueRef LLVMConstFCmp(LLVMRealPredicate Predicate,
1711 LLVMValueRef LHSConstant, LLVMValueRef RHSConstant);
1712LLVMValueRef LLVMConstShl(LLVMValueRef LHSConstant, LLVMValueRef RHSConstant);
1713LLVMValueRef LLVMConstLShr(LLVMValueRef LHSConstant, LLVMValueRef RHSConstant);
1714LLVMValueRef LLVMConstAShr(LLVMValueRef LHSConstant, LLVMValueRef RHSConstant);
1715LLVMValueRef LLVMConstGEP(LLVMValueRef ConstantVal,
1716 LLVMValueRef *ConstantIndices, unsigned NumIndices);
Dan Gohmane4ca02d2009-09-03 23:34:49 +00001717LLVMValueRef LLVMConstInBoundsGEP(LLVMValueRef ConstantVal,
1718 LLVMValueRef *ConstantIndices,
1719 unsigned NumIndices);
Gordon Henriksen7ce31762007-10-06 14:29:36 +00001720LLVMValueRef LLVMConstTrunc(LLVMValueRef ConstantVal, LLVMTypeRef ToType);
1721LLVMValueRef LLVMConstSExt(LLVMValueRef ConstantVal, LLVMTypeRef ToType);
1722LLVMValueRef LLVMConstZExt(LLVMValueRef ConstantVal, LLVMTypeRef ToType);
1723LLVMValueRef LLVMConstFPTrunc(LLVMValueRef ConstantVal, LLVMTypeRef ToType);
1724LLVMValueRef LLVMConstFPExt(LLVMValueRef ConstantVal, LLVMTypeRef ToType);
1725LLVMValueRef LLVMConstUIToFP(LLVMValueRef ConstantVal, LLVMTypeRef ToType);
1726LLVMValueRef LLVMConstSIToFP(LLVMValueRef ConstantVal, LLVMTypeRef ToType);
1727LLVMValueRef LLVMConstFPToUI(LLVMValueRef ConstantVal, LLVMTypeRef ToType);
1728LLVMValueRef LLVMConstFPToSI(LLVMValueRef ConstantVal, LLVMTypeRef ToType);
1729LLVMValueRef LLVMConstPtrToInt(LLVMValueRef ConstantVal, LLVMTypeRef ToType);
1730LLVMValueRef LLVMConstIntToPtr(LLVMValueRef ConstantVal, LLVMTypeRef ToType);
1731LLVMValueRef LLVMConstBitCast(LLVMValueRef ConstantVal, LLVMTypeRef ToType);
Matt Arsenaultb03bd4d2013-11-15 01:34:59 +00001732LLVMValueRef LLVMConstAddrSpaceCast(LLVMValueRef ConstantVal, LLVMTypeRef ToType);
Erick Tryzelaar4cc690c2009-08-16 02:20:12 +00001733LLVMValueRef LLVMConstZExtOrBitCast(LLVMValueRef ConstantVal,
1734 LLVMTypeRef ToType);
1735LLVMValueRef LLVMConstSExtOrBitCast(LLVMValueRef ConstantVal,
1736 LLVMTypeRef ToType);
1737LLVMValueRef LLVMConstTruncOrBitCast(LLVMValueRef ConstantVal,
1738 LLVMTypeRef ToType);
1739LLVMValueRef LLVMConstPointerCast(LLVMValueRef ConstantVal,
1740 LLVMTypeRef ToType);
1741LLVMValueRef LLVMConstIntCast(LLVMValueRef ConstantVal, LLVMTypeRef ToType,
Chris Lattner25963c62010-01-09 22:27:07 +00001742 LLVMBool isSigned);
Erick Tryzelaar4cc690c2009-08-16 02:20:12 +00001743LLVMValueRef LLVMConstFPCast(LLVMValueRef ConstantVal, LLVMTypeRef ToType);
Gordon Henriksen7ce31762007-10-06 14:29:36 +00001744LLVMValueRef LLVMConstSelect(LLVMValueRef ConstantCondition,
1745 LLVMValueRef ConstantIfTrue,
1746 LLVMValueRef ConstantIfFalse);
1747LLVMValueRef LLVMConstExtractElement(LLVMValueRef VectorConstant,
1748 LLVMValueRef IndexConstant);
1749LLVMValueRef LLVMConstInsertElement(LLVMValueRef VectorConstant,
1750 LLVMValueRef ElementValueConstant,
1751 LLVMValueRef IndexConstant);
1752LLVMValueRef LLVMConstShuffleVector(LLVMValueRef VectorAConstant,
1753 LLVMValueRef VectorBConstant,
1754 LLVMValueRef MaskConstant);
Dan Gohmand5104a52008-11-03 22:55:43 +00001755LLVMValueRef LLVMConstExtractValue(LLVMValueRef AggConstant, unsigned *IdxList,
1756 unsigned NumIdx);
1757LLVMValueRef LLVMConstInsertValue(LLVMValueRef AggConstant,
1758 LLVMValueRef ElementValueConstant,
1759 unsigned *IdxList, unsigned NumIdx);
Chris Lattner25963c62010-01-09 22:27:07 +00001760LLVMValueRef LLVMConstInlineAsm(LLVMTypeRef Ty,
Chris Lattner3d1f5522008-12-17 21:39:50 +00001761 const char *AsmString, const char *Constraints,
Chris Lattner25963c62010-01-09 22:27:07 +00001762 LLVMBool HasSideEffects, LLVMBool IsAlignStack);
Erick Tryzelaar0fb26ef2010-02-28 09:46:06 +00001763LLVMValueRef LLVMBlockAddress(LLVMValueRef F, LLVMBasicBlockRef BB);
Gordon Henriksen7ce31762007-10-06 14:29:36 +00001764
Gregory Szorc52d26602012-03-21 07:28:27 +00001765/**
1766 * @}
1767 */
1768
1769/**
1770 * @defgroup LLVMCCoreValueConstantGlobals Global Values
1771 *
1772 * This group contains functions that operate on global values. Functions in
1773 * this group relate to functions in the llvm::GlobalValue class tree.
1774 *
1775 * @see llvm::GlobalValue
1776 *
1777 * @{
1778 */
1779
Gordon Henriksen265f7802008-03-19 01:11:35 +00001780LLVMModuleRef LLVMGetGlobalParent(LLVMValueRef Global);
Chris Lattner25963c62010-01-09 22:27:07 +00001781LLVMBool LLVMIsDeclaration(LLVMValueRef Global);
Gordon Henriksen76a03742007-09-18 03:18:57 +00001782LLVMLinkage LLVMGetLinkage(LLVMValueRef Global);
1783void LLVMSetLinkage(LLVMValueRef Global, LLVMLinkage Linkage);
1784const char *LLVMGetSection(LLVMValueRef Global);
1785void LLVMSetSection(LLVMValueRef Global, const char *Section);
1786LLVMVisibility LLVMGetVisibility(LLVMValueRef Global);
1787void LLVMSetVisibility(LLVMValueRef Global, LLVMVisibility Viz);
Reid Kleckner2fae26f2014-03-05 02:34:23 +00001788LLVMDLLStorageClass LLVMGetDLLStorageClass(LLVMValueRef Global);
1789void LLVMSetDLLStorageClass(LLVMValueRef Global, LLVMDLLStorageClass Class);
Tim Northoverad96d012014-03-10 19:24:35 +00001790LLVMBool LLVMHasUnnamedAddr(LLVMValueRef Global);
1791void LLVMSetUnnamedAddr(LLVMValueRef Global, LLVMBool HasUnnamedAddr);
Anders Waldenborg213a63f2013-10-29 09:02:02 +00001792
1793/**
1794 * @defgroup LLVMCCoreValueWithAlignment Values with alignment
1795 *
1796 * Functions in this group only apply to values with alignment, i.e.
1797 * global variables, load and store instructions.
1798 */
1799
1800/**
1801 * Obtain the preferred alignment of the value.
Peter Zotov9f584e62014-03-05 05:05:34 +00001802 * @see llvm::AllocaInst::getAlignment()
Anders Waldenborg213a63f2013-10-29 09:02:02 +00001803 * @see llvm::LoadInst::getAlignment()
1804 * @see llvm::StoreInst::getAlignment()
1805 * @see llvm::GlobalValue::getAlignment()
1806 */
1807unsigned LLVMGetAlignment(LLVMValueRef V);
1808
1809/**
1810 * Set the preferred alignment of the value.
Peter Zotov9f584e62014-03-05 05:05:34 +00001811 * @see llvm::AllocaInst::setAlignment()
Anders Waldenborg213a63f2013-10-29 09:02:02 +00001812 * @see llvm::LoadInst::setAlignment()
1813 * @see llvm::StoreInst::setAlignment()
1814 * @see llvm::GlobalValue::setAlignment()
1815 */
1816void LLVMSetAlignment(LLVMValueRef V, unsigned Bytes);
1817
1818/**
Amaury Sechet83550102016-02-14 08:58:49 +00001819 * @}
1820 */
Gordon Henriksen76a03742007-09-18 03:18:57 +00001821
Gregory Szorc52d26602012-03-21 07:28:27 +00001822/**
1823 * @defgroup LLVMCoreValueConstantGlobalVariable Global Variables
1824 *
1825 * This group contains functions that operate on global variable values.
1826 *
1827 * @see llvm::GlobalVariable
1828 *
1829 * @{
1830 */
Gordon Henriksen76a03742007-09-18 03:18:57 +00001831LLVMValueRef LLVMAddGlobal(LLVMModuleRef M, LLVMTypeRef Ty, const char *Name);
Erick Tryzelaar06894b32010-02-28 09:46:13 +00001832LLVMValueRef LLVMAddGlobalInAddressSpace(LLVMModuleRef M, LLVMTypeRef Ty,
1833 const char *Name,
1834 unsigned AddressSpace);
Gordon Henriksen783f7bb2007-10-08 03:45:09 +00001835LLVMValueRef LLVMGetNamedGlobal(LLVMModuleRef M, const char *Name);
Gordon Henriksen07a45f42008-03-23 22:21:29 +00001836LLVMValueRef LLVMGetFirstGlobal(LLVMModuleRef M);
1837LLVMValueRef LLVMGetLastGlobal(LLVMModuleRef M);
1838LLVMValueRef LLVMGetNextGlobal(LLVMValueRef GlobalVar);
1839LLVMValueRef LLVMGetPreviousGlobal(LLVMValueRef GlobalVar);
Gordon Henriksen76a03742007-09-18 03:18:57 +00001840void LLVMDeleteGlobal(LLVMValueRef GlobalVar);
Gordon Henriksen76a03742007-09-18 03:18:57 +00001841LLVMValueRef LLVMGetInitializer(LLVMValueRef GlobalVar);
1842void LLVMSetInitializer(LLVMValueRef GlobalVar, LLVMValueRef ConstantVal);
Chris Lattner25963c62010-01-09 22:27:07 +00001843LLVMBool LLVMIsThreadLocal(LLVMValueRef GlobalVar);
1844void LLVMSetThreadLocal(LLVMValueRef GlobalVar, LLVMBool IsThreadLocal);
1845LLVMBool LLVMIsGlobalConstant(LLVMValueRef GlobalVar);
1846void LLVMSetGlobalConstant(LLVMValueRef GlobalVar, LLVMBool IsConstant);
Hans Wennborg5ff71202013-04-16 08:58:59 +00001847LLVMThreadLocalMode LLVMGetThreadLocalMode(LLVMValueRef GlobalVar);
1848void LLVMSetThreadLocalMode(LLVMValueRef GlobalVar, LLVMThreadLocalMode Mode);
1849LLVMBool LLVMIsExternallyInitialized(LLVMValueRef GlobalVar);
1850void LLVMSetExternallyInitialized(LLVMValueRef GlobalVar, LLVMBool IsExtInit);
Gordon Henriksen76a03742007-09-18 03:18:57 +00001851
Gregory Szorc52d26602012-03-21 07:28:27 +00001852/**
1853 * @}
1854 */
1855
1856/**
1857 * @defgroup LLVMCoreValueConstantGlobalAlias Global Aliases
1858 *
1859 * This group contains function that operate on global alias values.
1860 *
1861 * @see llvm::GlobalAlias
1862 *
1863 * @{
1864 */
Chris Lattner3d1f5522008-12-17 21:39:50 +00001865LLVMValueRef LLVMAddAlias(LLVMModuleRef M, LLVMTypeRef Ty, LLVMValueRef Aliasee,
1866 const char *Name);
1867
Gregory Szorc34c863a2012-03-21 03:54:29 +00001868/**
1869 * @}
1870 */
1871
1872/**
1873 * @defgroup LLVMCCoreValueFunction Function values
1874 *
1875 * Functions in this group operate on LLVMValueRef instances that
1876 * correspond to llvm::Function instances.
1877 *
1878 * @see llvm::Function
1879 *
1880 * @{
1881 */
1882
1883/**
1884 * Remove a function from its containing module and deletes it.
1885 *
1886 * @see llvm::Function::eraseFromParent()
1887 */
Gordon Henriksenc23b66c2007-09-26 20:56:12 +00001888void LLVMDeleteFunction(LLVMValueRef Fn);
Gregory Szorc34c863a2012-03-21 03:54:29 +00001889
1890/**
Amaury Sechete39e8532016-02-18 20:38:32 +00001891 * Check whether the given function has a personality function.
1892 *
1893 * @see llvm::Function::hasPersonalityFn()
1894 */
1895LLVMBool LLVMHasPersonalityFn(LLVMValueRef Fn);
1896
1897/**
Andrew Wilkins3bdfc1c2015-07-14 01:23:06 +00001898 * Obtain the personality function attached to the function.
1899 *
1900 * @see llvm::Function::getPersonalityFn()
1901 */
1902LLVMValueRef LLVMGetPersonalityFn(LLVMValueRef Fn);
1903
1904/**
1905 * Set the personality function attached to the function.
1906 *
1907 * @see llvm::Function::setPersonalityFn()
1908 */
1909void LLVMSetPersonalityFn(LLVMValueRef Fn, LLVMValueRef PersonalityFn);
1910
1911/**
Gregory Szorc34c863a2012-03-21 03:54:29 +00001912 * Obtain the ID number from a function instance.
1913 *
1914 * @see llvm::Function::getIntrinsicID()
1915 */
Gordon Henriksenc23b66c2007-09-26 20:56:12 +00001916unsigned LLVMGetIntrinsicID(LLVMValueRef Fn);
Gregory Szorc34c863a2012-03-21 03:54:29 +00001917
1918/**
1919 * Obtain the calling function of a function.
1920 *
1921 * The returned value corresponds to the LLVMCallConv enumeration.
1922 *
1923 * @see llvm::Function::getCallingConv()
1924 */
Gordon Henriksenc23b66c2007-09-26 20:56:12 +00001925unsigned LLVMGetFunctionCallConv(LLVMValueRef Fn);
Gregory Szorc34c863a2012-03-21 03:54:29 +00001926
1927/**
1928 * Set the calling convention of a function.
1929 *
1930 * @see llvm::Function::setCallingConv()
1931 *
1932 * @param Fn Function to operate on
1933 * @param CC LLVMCallConv to set calling convention to
1934 */
Gordon Henriksenc23b66c2007-09-26 20:56:12 +00001935void LLVMSetFunctionCallConv(LLVMValueRef Fn, unsigned CC);
Gregory Szorc34c863a2012-03-21 03:54:29 +00001936
1937/**
1938 * Obtain the name of the garbage collector to use during code
1939 * generation.
1940 *
1941 * @see llvm::Function::getGC()
1942 */
Gordon Henriksend930f912008-08-17 18:44:35 +00001943const char *LLVMGetGC(LLVMValueRef Fn);
Gregory Szorc34c863a2012-03-21 03:54:29 +00001944
1945/**
1946 * Define the garbage collector to use during code generation.
1947 *
1948 * @see llvm::Function::setGC()
1949 */
Gordon Henriksend930f912008-08-17 18:44:35 +00001950void LLVMSetGC(LLVMValueRef Fn, const char *Name);
Gregory Szorc34c863a2012-03-21 03:54:29 +00001951
1952/**
1953 * Add an attribute to a function.
1954 *
1955 * @see llvm::Function::addAttribute()
1956 */
Duncan Sands7374a012009-05-06 12:21:17 +00001957void LLVMAddFunctionAttr(LLVMValueRef Fn, LLVMAttribute PA);
Gregory Szorc34c863a2012-03-21 03:54:29 +00001958
1959/**
Nick Lewyckyc3890d22015-07-29 22:32:47 +00001960 * Add a target-dependent attribute to a function
Tom Stellarde8f35e12013-04-16 23:12:43 +00001961 * @see llvm::AttrBuilder::addAttribute()
1962 */
1963void LLVMAddTargetDependentFunctionAttr(LLVMValueRef Fn, const char *A,
1964 const char *V);
1965
1966/**
Gregory Szorc34c863a2012-03-21 03:54:29 +00001967 * Obtain an attribute from a function.
1968 *
1969 * @see llvm::Function::getAttributes()
1970 */
Chris Lattner40cf28d2009-10-12 04:01:02 +00001971LLVMAttribute LLVMGetFunctionAttr(LLVMValueRef Fn);
Gregory Szorc34c863a2012-03-21 03:54:29 +00001972
1973/**
1974 * Remove an attribute from a function.
1975 */
Duncan Sands7374a012009-05-06 12:21:17 +00001976void LLVMRemoveFunctionAttr(LLVMValueRef Fn, LLVMAttribute PA);
Gordon Henriksenc23b66c2007-09-26 20:56:12 +00001977
Gregory Szorc34c863a2012-03-21 03:54:29 +00001978/**
1979 * @defgroup LLVMCCoreValueFunctionParameters Function Parameters
1980 *
1981 * Functions in this group relate to arguments/parameters on functions.
1982 *
1983 * Functions in this group expect LLVMValueRef instances that correspond
1984 * to llvm::Function instances.
1985 *
1986 * @{
1987 */
1988
1989/**
1990 * Obtain the number of parameters in a function.
1991 *
1992 * @see llvm::Function::arg_size()
1993 */
Gordon Henriksen265f7802008-03-19 01:11:35 +00001994unsigned LLVMCountParams(LLVMValueRef Fn);
Gregory Szorc34c863a2012-03-21 03:54:29 +00001995
1996/**
1997 * Obtain the parameters in a function.
1998 *
1999 * The takes a pointer to a pre-allocated array of LLVMValueRef that is
2000 * at least LLVMCountParams() long. This array will be filled with
2001 * LLVMValueRef instances which correspond to the parameters the
2002 * function receives. Each LLVMValueRef corresponds to a llvm::Argument
2003 * instance.
2004 *
2005 * @see llvm::Function::arg_begin()
2006 */
Gordon Henriksen265f7802008-03-19 01:11:35 +00002007void LLVMGetParams(LLVMValueRef Fn, LLVMValueRef *Params);
Gregory Szorc34c863a2012-03-21 03:54:29 +00002008
2009/**
2010 * Obtain the parameter at the specified index.
2011 *
2012 * Parameters are indexed from 0.
2013 *
2014 * @see llvm::Function::arg_begin()
2015 */
Gordon Henriksen265f7802008-03-19 01:11:35 +00002016LLVMValueRef LLVMGetParam(LLVMValueRef Fn, unsigned Index);
Gregory Szorc34c863a2012-03-21 03:54:29 +00002017
2018/**
2019 * Obtain the function to which this argument belongs.
2020 *
Daniel Dunbar06b9f9e2013-08-16 23:30:19 +00002021 * Unlike other functions in this group, this one takes an LLVMValueRef
Gregory Szorc34c863a2012-03-21 03:54:29 +00002022 * that corresponds to a llvm::Attribute.
2023 *
2024 * The returned LLVMValueRef is the llvm::Function to which this
2025 * argument belongs.
2026 */
Gordon Henriksen265f7802008-03-19 01:11:35 +00002027LLVMValueRef LLVMGetParamParent(LLVMValueRef Inst);
Gregory Szorc34c863a2012-03-21 03:54:29 +00002028
2029/**
2030 * Obtain the first parameter to a function.
2031 *
2032 * @see llvm::Function::arg_begin()
2033 */
Gordon Henriksen07a45f42008-03-23 22:21:29 +00002034LLVMValueRef LLVMGetFirstParam(LLVMValueRef Fn);
Gregory Szorc34c863a2012-03-21 03:54:29 +00002035
2036/**
2037 * Obtain the last parameter to a function.
2038 *
2039 * @see llvm::Function::arg_end()
2040 */
Gordon Henriksen07a45f42008-03-23 22:21:29 +00002041LLVMValueRef LLVMGetLastParam(LLVMValueRef Fn);
Gregory Szorc34c863a2012-03-21 03:54:29 +00002042
2043/**
2044 * Obtain the next parameter to a function.
2045 *
Daniel Dunbar06b9f9e2013-08-16 23:30:19 +00002046 * This takes an LLVMValueRef obtained from LLVMGetFirstParam() (which is
Gregory Szorc34c863a2012-03-21 03:54:29 +00002047 * actually a wrapped iterator) and obtains the next parameter from the
2048 * underlying iterator.
2049 */
Gordon Henriksen07a45f42008-03-23 22:21:29 +00002050LLVMValueRef LLVMGetNextParam(LLVMValueRef Arg);
Gregory Szorc34c863a2012-03-21 03:54:29 +00002051
2052/**
2053 * Obtain the previous parameter to a function.
2054 *
2055 * This is the opposite of LLVMGetNextParam().
2056 */
Gordon Henriksen07a45f42008-03-23 22:21:29 +00002057LLVMValueRef LLVMGetPreviousParam(LLVMValueRef Arg);
Gregory Szorc34c863a2012-03-21 03:54:29 +00002058
2059/**
2060 * Add an attribute to a function argument.
2061 *
2062 * @see llvm::Argument::addAttr()
2063 */
Devang Patel4c758ea2008-09-25 21:00:45 +00002064void LLVMAddAttribute(LLVMValueRef Arg, LLVMAttribute PA);
Gregory Szorc34c863a2012-03-21 03:54:29 +00002065
2066/**
2067 * Remove an attribute from a function argument.
2068 *
2069 * @see llvm::Argument::removeAttr()
2070 */
Devang Patel4c758ea2008-09-25 21:00:45 +00002071void LLVMRemoveAttribute(LLVMValueRef Arg, LLVMAttribute PA);
Gregory Szorc34c863a2012-03-21 03:54:29 +00002072
2073/**
2074 * Get an attribute from a function argument.
2075 */
Chris Lattner40cf28d2009-10-12 04:01:02 +00002076LLVMAttribute LLVMGetAttribute(LLVMValueRef Arg);
Gregory Szorc34c863a2012-03-21 03:54:29 +00002077
2078/**
2079 * Set the alignment for a function parameter.
2080 *
2081 * @see llvm::Argument::addAttr()
Bill Wendling50d27842012-10-15 20:35:56 +00002082 * @see llvm::AttrBuilder::addAlignmentAttr()
Gregory Szorc34c863a2012-03-21 03:54:29 +00002083 */
Gordon Henriksen2d9cc212008-04-28 17:37:06 +00002084void LLVMSetParamAlignment(LLVMValueRef Arg, unsigned align);
Gordon Henriksen265f7802008-03-19 01:11:35 +00002085
Gregory Szorc34c863a2012-03-21 03:54:29 +00002086/**
2087 * @}
2088 */
2089
2090/**
2091 * @}
2092 */
2093
2094/**
Gregory Szorc52d26602012-03-21 07:28:27 +00002095 * @}
2096 */
2097
2098/**
2099 * @}
2100 */
2101
2102/**
2103 * @defgroup LLVMCCoreValueMetadata Metadata
2104 *
2105 * @{
2106 */
2107
2108/**
2109 * Obtain a MDString value from a context.
2110 *
2111 * The returned instance corresponds to the llvm::MDString class.
2112 *
2113 * The instance is specified by string data of a specified length. The
2114 * string content is copied, so the backing memory can be freed after
2115 * this function returns.
2116 */
2117LLVMValueRef LLVMMDStringInContext(LLVMContextRef C, const char *Str,
2118 unsigned SLen);
2119
2120/**
2121 * Obtain a MDString value from the global context.
2122 */
2123LLVMValueRef LLVMMDString(const char *Str, unsigned SLen);
2124
2125/**
2126 * Obtain a MDNode value from a context.
2127 *
2128 * The returned value corresponds to the llvm::MDNode class.
2129 */
2130LLVMValueRef LLVMMDNodeInContext(LLVMContextRef C, LLVMValueRef *Vals,
2131 unsigned Count);
2132
2133/**
2134 * Obtain a MDNode value from the global context.
2135 */
2136LLVMValueRef LLVMMDNode(LLVMValueRef *Vals, unsigned Count);
2137
2138/**
2139 * Obtain the underlying string from a MDString value.
2140 *
2141 * @param V Instance to obtain string from.
NAKAMURA Takumie4a77052016-04-04 11:54:48 +00002142 * @param Length Memory address which will hold length of returned string.
Gregory Szorc52d26602012-03-21 07:28:27 +00002143 * @return String data in MDString.
2144 */
Amaury Sechet7c2883c2016-04-03 21:06:04 +00002145const char *LLVMGetMDString(LLVMValueRef V, unsigned *Length);
Gregory Szorc52d26602012-03-21 07:28:27 +00002146
2147/**
Duncan Sands12ccbe72012-09-19 20:29:39 +00002148 * Obtain the number of operands from an MDNode value.
2149 *
2150 * @param V MDNode to get number of operands from.
2151 * @return Number of operands of the MDNode.
2152 */
2153unsigned LLVMGetMDNodeNumOperands(LLVMValueRef V);
2154
2155/**
2156 * Obtain the given MDNode's operands.
2157 *
2158 * The passed LLVMValueRef pointer should point to enough memory to hold all of
2159 * the operands of the given MDNode (see LLVMGetMDNodeNumOperands) as
2160 * LLVMValueRefs. This memory will be populated with the LLVMValueRefs of the
2161 * MDNode's operands.
2162 *
2163 * @param V MDNode to get the operands from.
2164 * @param Dest Destination array for operands.
2165 */
2166void LLVMGetMDNodeOperands(LLVMValueRef V, LLVMValueRef *Dest);
2167
2168/**
Gregory Szorc52d26602012-03-21 07:28:27 +00002169 * @}
2170 */
2171
2172/**
Gregory Szorc34c863a2012-03-21 03:54:29 +00002173 * @defgroup LLVMCCoreValueBasicBlock Basic Block
2174 *
2175 * A basic block represents a single entry single exit section of code.
2176 * Basic blocks contain a list of instructions which form the body of
2177 * the block.
2178 *
2179 * Basic blocks belong to functions. They have the type of label.
2180 *
2181 * Basic blocks are themselves values. However, the C API models them as
2182 * LLVMBasicBlockRef.
2183 *
2184 * @see llvm::BasicBlock
2185 *
2186 * @{
2187 */
2188
2189/**
2190 * Convert a basic block instance to a value type.
2191 */
Gordon Henriksen07a45f42008-03-23 22:21:29 +00002192LLVMValueRef LLVMBasicBlockAsValue(LLVMBasicBlockRef BB);
Gregory Szorc34c863a2012-03-21 03:54:29 +00002193
2194/**
Daniel Dunbar06b9f9e2013-08-16 23:30:19 +00002195 * Determine whether an LLVMValueRef is itself a basic block.
Gregory Szorc34c863a2012-03-21 03:54:29 +00002196 */
Chris Lattner25963c62010-01-09 22:27:07 +00002197LLVMBool LLVMValueIsBasicBlock(LLVMValueRef Val);
Gregory Szorc34c863a2012-03-21 03:54:29 +00002198
2199/**
Daniel Dunbar06b9f9e2013-08-16 23:30:19 +00002200 * Convert an LLVMValueRef to an LLVMBasicBlockRef instance.
Gregory Szorc34c863a2012-03-21 03:54:29 +00002201 */
Gordon Henriksenc23b66c2007-09-26 20:56:12 +00002202LLVMBasicBlockRef LLVMValueAsBasicBlock(LLVMValueRef Val);
Gregory Szorc34c863a2012-03-21 03:54:29 +00002203
2204/**
Amaury Secheta82042e2016-02-09 22:36:41 +00002205 * Obtain the string name of a basic block.
2206 */
2207const char *LLVMGetBasicBlockName(LLVMBasicBlockRef BB);
2208
2209/**
Gregory Szorc34c863a2012-03-21 03:54:29 +00002210 * Obtain the function to which a basic block belongs.
2211 *
2212 * @see llvm::BasicBlock::getParent()
2213 */
Gordon Henriksen07a45f42008-03-23 22:21:29 +00002214LLVMValueRef LLVMGetBasicBlockParent(LLVMBasicBlockRef BB);
Gregory Szorc34c863a2012-03-21 03:54:29 +00002215
2216/**
2217 * Obtain the terminator instruction for a basic block.
2218 *
2219 * If the basic block does not have a terminator (it is not well-formed
2220 * if it doesn't), then NULL is returned.
2221 *
2222 * The returned LLVMValueRef corresponds to a llvm::TerminatorInst.
2223 *
2224 * @see llvm::BasicBlock::getTerminator()
2225 */
Nate Begeman43c322b2011-08-23 20:27:46 +00002226LLVMValueRef LLVMGetBasicBlockTerminator(LLVMBasicBlockRef BB);
Gregory Szorc34c863a2012-03-21 03:54:29 +00002227
2228/**
2229 * Obtain the number of basic blocks in a function.
2230 *
2231 * @param Fn Function value to operate on.
2232 */
Gordon Henriksenc23b66c2007-09-26 20:56:12 +00002233unsigned LLVMCountBasicBlocks(LLVMValueRef Fn);
Gregory Szorc34c863a2012-03-21 03:54:29 +00002234
2235/**
2236 * Obtain all of the basic blocks in a function.
2237 *
2238 * This operates on a function value. The BasicBlocks parameter is a
2239 * pointer to a pre-allocated array of LLVMBasicBlockRef of at least
2240 * LLVMCountBasicBlocks() in length. This array is populated with
2241 * LLVMBasicBlockRef instances.
2242 */
Gordon Henriksenc23b66c2007-09-26 20:56:12 +00002243void LLVMGetBasicBlocks(LLVMValueRef Fn, LLVMBasicBlockRef *BasicBlocks);
Gregory Szorc34c863a2012-03-21 03:54:29 +00002244
2245/**
2246 * Obtain the first basic block in a function.
2247 *
2248 * The returned basic block can be used as an iterator. You will likely
2249 * eventually call into LLVMGetNextBasicBlock() with it.
2250 *
2251 * @see llvm::Function::begin()
2252 */
Gordon Henriksen054817c2008-03-19 03:47:18 +00002253LLVMBasicBlockRef LLVMGetFirstBasicBlock(LLVMValueRef Fn);
Gregory Szorc34c863a2012-03-21 03:54:29 +00002254
2255/**
2256 * Obtain the last basic block in a function.
2257 *
2258 * @see llvm::Function::end()
2259 */
Gordon Henriksen054817c2008-03-19 03:47:18 +00002260LLVMBasicBlockRef LLVMGetLastBasicBlock(LLVMValueRef Fn);
Gregory Szorc34c863a2012-03-21 03:54:29 +00002261
2262/**
2263 * Advance a basic block iterator.
2264 */
Gordon Henriksen054817c2008-03-19 03:47:18 +00002265LLVMBasicBlockRef LLVMGetNextBasicBlock(LLVMBasicBlockRef BB);
Gregory Szorc34c863a2012-03-21 03:54:29 +00002266
2267/**
2268 * Go backwards in a basic block iterator.
2269 */
Gordon Henriksen054817c2008-03-19 03:47:18 +00002270LLVMBasicBlockRef LLVMGetPreviousBasicBlock(LLVMBasicBlockRef BB);
Gregory Szorc34c863a2012-03-21 03:54:29 +00002271
2272/**
2273 * Obtain the basic block that corresponds to the entry point of a
2274 * function.
2275 *
2276 * @see llvm::Function::getEntryBlock()
2277 */
Gordon Henriksenc23b66c2007-09-26 20:56:12 +00002278LLVMBasicBlockRef LLVMGetEntryBasicBlock(LLVMValueRef Fn);
Erick Tryzelaar262332f2009-08-14 00:01:31 +00002279
Gregory Szorc34c863a2012-03-21 03:54:29 +00002280/**
2281 * Append a basic block to the end of a function.
2282 *
2283 * @see llvm::BasicBlock::Create()
2284 */
Erick Tryzelaar262332f2009-08-14 00:01:31 +00002285LLVMBasicBlockRef LLVMAppendBasicBlockInContext(LLVMContextRef C,
2286 LLVMValueRef Fn,
2287 const char *Name);
Gregory Szorc34c863a2012-03-21 03:54:29 +00002288
2289/**
2290 * Append a basic block to the end of a function using the global
2291 * context.
2292 *
2293 * @see llvm::BasicBlock::Create()
2294 */
2295LLVMBasicBlockRef LLVMAppendBasicBlock(LLVMValueRef Fn, const char *Name);
2296
2297/**
2298 * Insert a basic block in a function before another basic block.
2299 *
2300 * The function to add to is determined by the function of the
2301 * passed basic block.
2302 *
2303 * @see llvm::BasicBlock::Create()
2304 */
Erick Tryzelaar262332f2009-08-14 00:01:31 +00002305LLVMBasicBlockRef LLVMInsertBasicBlockInContext(LLVMContextRef C,
2306 LLVMBasicBlockRef BB,
2307 const char *Name);
2308
Gregory Szorc34c863a2012-03-21 03:54:29 +00002309/**
2310 * Insert a basic block in a function using the global context.
2311 *
2312 * @see llvm::BasicBlock::Create()
2313 */
Gordon Henriksenc23b66c2007-09-26 20:56:12 +00002314LLVMBasicBlockRef LLVMInsertBasicBlock(LLVMBasicBlockRef InsertBeforeBB,
2315 const char *Name);
Gregory Szorc34c863a2012-03-21 03:54:29 +00002316
2317/**
2318 * Remove a basic block from a function and delete it.
2319 *
2320 * This deletes the basic block from its containing function and deletes
2321 * the basic block itself.
2322 *
2323 * @see llvm::BasicBlock::eraseFromParent()
2324 */
Gordon Henriksenc23b66c2007-09-26 20:56:12 +00002325void LLVMDeleteBasicBlock(LLVMBasicBlockRef BB);
Gregory Szorc34c863a2012-03-21 03:54:29 +00002326
2327/**
2328 * Remove a basic block from a function.
2329 *
2330 * This deletes the basic block from its containing function but keep
2331 * the basic block alive.
2332 *
2333 * @see llvm::BasicBlock::removeFromParent()
2334 */
Nate Begeman43c322b2011-08-23 20:27:46 +00002335void LLVMRemoveBasicBlockFromParent(LLVMBasicBlockRef BB);
Gordon Henriksenc23b66c2007-09-26 20:56:12 +00002336
Gregory Szorc34c863a2012-03-21 03:54:29 +00002337/**
2338 * Move a basic block to before another one.
2339 *
2340 * @see llvm::BasicBlock::moveBefore()
2341 */
Duncan Sandsb1d61aa2010-07-19 15:31:07 +00002342void LLVMMoveBasicBlockBefore(LLVMBasicBlockRef BB, LLVMBasicBlockRef MovePos);
Gregory Szorc34c863a2012-03-21 03:54:29 +00002343
2344/**
2345 * Move a basic block to after another one.
2346 *
2347 * @see llvm::BasicBlock::moveAfter()
2348 */
Duncan Sandsb1d61aa2010-07-19 15:31:07 +00002349void LLVMMoveBasicBlockAfter(LLVMBasicBlockRef BB, LLVMBasicBlockRef MovePos);
2350
Gregory Szorc34c863a2012-03-21 03:54:29 +00002351/**
2352 * Obtain the first instruction in a basic block.
2353 *
2354 * The returned LLVMValueRef corresponds to a llvm::Instruction
2355 * instance.
2356 */
Gordon Henriksen054817c2008-03-19 03:47:18 +00002357LLVMValueRef LLVMGetFirstInstruction(LLVMBasicBlockRef BB);
Gregory Szorc34c863a2012-03-21 03:54:29 +00002358
2359/**
2360 * Obtain the last instruction in a basic block.
2361 *
Daniel Dunbar06b9f9e2013-08-16 23:30:19 +00002362 * The returned LLVMValueRef corresponds to an LLVM:Instruction.
Gregory Szorc34c863a2012-03-21 03:54:29 +00002363 */
Gordon Henriksen054817c2008-03-19 03:47:18 +00002364LLVMValueRef LLVMGetLastInstruction(LLVMBasicBlockRef BB);
Nate Begeman43c322b2011-08-23 20:27:46 +00002365
Gregory Szorc34c863a2012-03-21 03:54:29 +00002366/**
2367 * @}
2368 */
2369
2370/**
2371 * @defgroup LLVMCCoreValueInstruction Instructions
2372 *
2373 * Functions in this group relate to the inspection and manipulation of
2374 * individual instructions.
2375 *
2376 * In the C++ API, an instruction is modeled by llvm::Instruction. This
2377 * class has a large number of descendents. llvm::Instruction is a
2378 * llvm::Value and in the C API, instructions are modeled by
2379 * LLVMValueRef.
2380 *
2381 * This group also contains sub-groups which operate on specific
2382 * llvm::Instruction types, e.g. llvm::CallInst.
2383 *
2384 * @{
2385 */
2386
2387/**
2388 * Determine whether an instruction has any metadata attached.
2389 */
2390int LLVMHasMetadata(LLVMValueRef Val);
2391
2392/**
2393 * Return metadata associated with an instruction value.
2394 */
2395LLVMValueRef LLVMGetMetadata(LLVMValueRef Val, unsigned KindID);
2396
2397/**
2398 * Set metadata associated with an instruction value.
2399 */
2400void LLVMSetMetadata(LLVMValueRef Val, unsigned KindID, LLVMValueRef Node);
2401
2402/**
2403 * Obtain the basic block to which an instruction belongs.
2404 *
2405 * @see llvm::Instruction::getParent()
2406 */
Nate Begeman43c322b2011-08-23 20:27:46 +00002407LLVMBasicBlockRef LLVMGetInstructionParent(LLVMValueRef Inst);
Gregory Szorc34c863a2012-03-21 03:54:29 +00002408
2409/**
2410 * Obtain the instruction that occurs after the one specified.
2411 *
2412 * The next instruction will be from the same basic block.
2413 *
2414 * If this is the last instruction in a basic block, NULL will be
2415 * returned.
2416 */
Gordon Henriksen054817c2008-03-19 03:47:18 +00002417LLVMValueRef LLVMGetNextInstruction(LLVMValueRef Inst);
Gregory Szorc34c863a2012-03-21 03:54:29 +00002418
2419/**
Benjamin Kramerbde91762012-06-02 10:20:22 +00002420 * Obtain the instruction that occurred before this one.
Gregory Szorc34c863a2012-03-21 03:54:29 +00002421 *
2422 * If the instruction is the first instruction in a basic block, NULL
2423 * will be returned.
2424 */
Gordon Henriksen054817c2008-03-19 03:47:18 +00002425LLVMValueRef LLVMGetPreviousInstruction(LLVMValueRef Inst);
Gregory Szorc34c863a2012-03-21 03:54:29 +00002426
2427/**
2428 * Remove and delete an instruction.
2429 *
2430 * The instruction specified is removed from its containing building
Amaury Sechet2f432082016-02-11 21:37:54 +00002431 * block but is kept alive.
2432 *
2433 * @see llvm::Instruction::removeFromParent()
2434 */
2435void LLVMInstructionRemoveFromParent(LLVMValueRef Inst);
2436
2437/**
2438 * Remove and delete an instruction.
2439 *
2440 * The instruction specified is removed from its containing building
Gregory Szorc34c863a2012-03-21 03:54:29 +00002441 * block and then deleted.
2442 *
2443 * @see llvm::Instruction::eraseFromParent()
2444 */
Devang Pateldbebc6f2011-10-03 20:59:18 +00002445void LLVMInstructionEraseFromParent(LLVMValueRef Inst);
Gregory Szorc34c863a2012-03-21 03:54:29 +00002446
2447/**
2448 * Obtain the code opcode for an individual instruction.
2449 *
2450 * @see llvm::Instruction::getOpCode()
2451 */
Eric Christophera6b96002015-12-18 01:46:52 +00002452LLVMOpcode LLVMGetInstructionOpcode(LLVMValueRef Inst);
Gregory Szorc34c863a2012-03-21 03:54:29 +00002453
2454/**
2455 * Obtain the predicate of an instruction.
2456 *
2457 * This is only valid for instructions that correspond to llvm::ICmpInst
2458 * or llvm::ConstantExpr whose opcode is llvm::Instruction::ICmp.
2459 *
2460 * @see llvm::ICmpInst::getPredicate()
2461 */
Torok Edwin60c40de2011-10-06 12:13:20 +00002462LLVMIntPredicate LLVMGetICmpPredicate(LLVMValueRef Inst);
Gordon Henriksen265f7802008-03-19 01:11:35 +00002463
Gregory Szorc34c863a2012-03-21 03:54:29 +00002464/**
Peter Zotov1d98e6d2014-10-28 19:46:44 +00002465 * Obtain the float predicate of an instruction.
2466 *
2467 * This is only valid for instructions that correspond to llvm::FCmpInst
2468 * or llvm::ConstantExpr whose opcode is llvm::Instruction::FCmp.
2469 *
2470 * @see llvm::FCmpInst::getPredicate()
2471 */
2472LLVMRealPredicate LLVMGetFCmpPredicate(LLVMValueRef Inst);
2473
2474/**
Peter Zotovaff492c2014-10-17 01:02:34 +00002475 * Create a copy of 'this' instruction that is identical in all ways
2476 * except the following:
2477 * * The instruction has no parent
2478 * * The instruction has no name
2479 *
2480 * @see llvm::Instruction::clone()
2481 */
2482LLVMValueRef LLVMInstructionClone(LLVMValueRef Inst);
2483
2484/**
Gregory Szorc34c863a2012-03-21 03:54:29 +00002485 * @defgroup LLVMCCoreValueInstructionCall Call Sites and Invocations
2486 *
2487 * Functions in this group apply to instructions that refer to call
2488 * sites and invocations. These correspond to C++ types in the
2489 * llvm::CallInst class tree.
2490 *
2491 * @{
2492 */
2493
2494/**
Amaury Sechet5c7b3af2016-02-10 00:09:37 +00002495 * Obtain the argument count for a call instruction.
2496 *
2497 * This expects an LLVMValueRef that corresponds to a llvm::CallInst or
2498 * llvm::InvokeInst.
2499 *
2500 * @see llvm::CallInst::getNumArgOperands()
2501 * @see llvm::InvokeInst::getNumArgOperands()
2502 */
2503unsigned LLVMGetNumArgOperands(LLVMValueRef Instr);
2504
2505/**
Gregory Szorc34c863a2012-03-21 03:54:29 +00002506 * Set the calling convention for a call instruction.
2507 *
2508 * This expects an LLVMValueRef that corresponds to a llvm::CallInst or
2509 * llvm::InvokeInst.
2510 *
2511 * @see llvm::CallInst::setCallingConv()
2512 * @see llvm::InvokeInst::setCallingConv()
2513 */
Gordon Henriksen1158c532007-12-29 20:45:00 +00002514void LLVMSetInstructionCallConv(LLVMValueRef Instr, unsigned CC);
Gregory Szorc34c863a2012-03-21 03:54:29 +00002515
2516/**
2517 * Obtain the calling convention for a call instruction.
2518 *
2519 * This is the opposite of LLVMSetInstructionCallConv(). Reads its
2520 * usage.
2521 *
2522 * @see LLVMSetInstructionCallConv()
2523 */
Gordon Henriksen1158c532007-12-29 20:45:00 +00002524unsigned LLVMGetInstructionCallConv(LLVMValueRef Instr);
Gregory Szorc34c863a2012-03-21 03:54:29 +00002525
2526
Devang Patel4c758ea2008-09-25 21:00:45 +00002527void LLVMAddInstrAttribute(LLVMValueRef Instr, unsigned index, LLVMAttribute);
Gregory Szorc34c863a2012-03-21 03:54:29 +00002528void LLVMRemoveInstrAttribute(LLVMValueRef Instr, unsigned index,
Devang Patel4c758ea2008-09-25 21:00:45 +00002529 LLVMAttribute);
Gregory Szorc34c863a2012-03-21 03:54:29 +00002530void LLVMSetInstrParamAlignment(LLVMValueRef Instr, unsigned index,
Gordon Henriksen2d9cc212008-04-28 17:37:06 +00002531 unsigned align);
Gordon Henriksen1158c532007-12-29 20:45:00 +00002532
Gregory Szorc34c863a2012-03-21 03:54:29 +00002533/**
Amaury Sechet5c7b3af2016-02-10 00:09:37 +00002534 * Obtain the pointer to the function invoked by this instruction.
2535 *
2536 * This expects an LLVMValueRef that corresponds to a llvm::CallInst or
2537 * llvm::InvokeInst.
2538 *
2539 * @see llvm::CallInst::getCalledValue()
2540 * @see llvm::InvokeInst::getCalledValue()
2541 */
2542LLVMValueRef LLVMGetCalledValue(LLVMValueRef Instr);
2543
2544/**
Gregory Szorc34c863a2012-03-21 03:54:29 +00002545 * Obtain whether a call instruction is a tail call.
2546 *
2547 * This only works on llvm::CallInst instructions.
2548 *
2549 * @see llvm::CallInst::isTailCall()
2550 */
Chris Lattner25963c62010-01-09 22:27:07 +00002551LLVMBool LLVMIsTailCall(LLVMValueRef CallInst);
Gregory Szorc34c863a2012-03-21 03:54:29 +00002552
2553/**
2554 * Set whether a call instruction is a tail call.
2555 *
2556 * This only works on llvm::CallInst instructions.
2557 *
2558 * @see llvm::CallInst::setTailCall()
2559 */
Chris Lattner25963c62010-01-09 22:27:07 +00002560void LLVMSetTailCall(LLVMValueRef CallInst, LLVMBool IsTailCall);
Gordon Henrikseneeb65372008-08-30 16:34:54 +00002561
Gregory Szorc34c863a2012-03-21 03:54:29 +00002562/**
Amaury Sechete39e8532016-02-18 20:38:32 +00002563 * Return the normal destination basic block.
2564 *
2565 * This only works on llvm::InvokeInst instructions.
2566 *
2567 * @see llvm::InvokeInst::getNormalDest()
2568 */
2569LLVMBasicBlockRef LLVMGetNormalDest(LLVMValueRef InvokeInst);
2570
2571/**
2572 * Return the unwind destination basic block.
2573 *
2574 * This only works on llvm::InvokeInst instructions.
2575 *
2576 * @see llvm::InvokeInst::getUnwindDest()
2577 */
2578LLVMBasicBlockRef LLVMGetUnwindDest(LLVMValueRef InvokeInst);
2579
2580/**
2581 * Set the normal destination basic block.
2582 *
2583 * This only works on llvm::InvokeInst instructions.
2584 *
2585 * @see llvm::InvokeInst::setNormalDest()
2586 */
2587void LLVMSetNormalDest(LLVMValueRef InvokeInst, LLVMBasicBlockRef B);
2588
2589/**
2590 * Set the unwind destination basic block.
2591 *
2592 * This only works on llvm::InvokeInst instructions.
2593 *
2594 * @see llvm::InvokeInst::setUnwindDest()
2595 */
2596void LLVMSetUnwindDest(LLVMValueRef InvokeInst, LLVMBasicBlockRef B);
2597
2598/**
Gregory Szorc34c863a2012-03-21 03:54:29 +00002599 * @}
2600 */
2601
2602/**
Peter Zotov2481c752014-10-28 19:46:56 +00002603 * @defgroup LLVMCCoreValueInstructionTerminator Terminators
2604 *
2605 * Functions in this group only apply to instructions that map to
2606 * llvm::TerminatorInst instances.
2607 *
2608 * @{
2609 */
2610
2611/**
2612 * Return the number of successors that this terminator has.
2613 *
2614 * @see llvm::TerminatorInst::getNumSuccessors
2615 */
2616unsigned LLVMGetNumSuccessors(LLVMValueRef Term);
2617
2618/**
2619 * Return the specified successor.
2620 *
2621 * @see llvm::TerminatorInst::getSuccessor
2622 */
2623LLVMBasicBlockRef LLVMGetSuccessor(LLVMValueRef Term, unsigned i);
2624
2625/**
2626 * Update the specified successor to point at the provided block.
2627 *
2628 * @see llvm::TerminatorInst::setSuccessor
2629 */
2630void LLVMSetSuccessor(LLVMValueRef Term, unsigned i, LLVMBasicBlockRef block);
2631
2632/**
2633 * Return if a branch is conditional.
2634 *
2635 * This only works on llvm::BranchInst instructions.
2636 *
2637 * @see llvm::BranchInst::isConditional
2638 */
2639LLVMBool LLVMIsConditional(LLVMValueRef Branch);
2640
2641/**
2642 * Return the condition of a branch instruction.
2643 *
2644 * This only works on llvm::BranchInst instructions.
2645 *
2646 * @see llvm::BranchInst::getCondition
2647 */
2648LLVMValueRef LLVMGetCondition(LLVMValueRef Branch);
2649
2650/**
2651 * Set the condition of a branch instruction.
2652 *
2653 * This only works on llvm::BranchInst instructions.
2654 *
2655 * @see llvm::BranchInst::setCondition
2656 */
2657void LLVMSetCondition(LLVMValueRef Branch, LLVMValueRef Cond);
2658
2659/**
Gregory Szorc34c863a2012-03-21 03:54:29 +00002660 * Obtain the default destination basic block of a switch instruction.
2661 *
2662 * This only works on llvm::SwitchInst instructions.
2663 *
2664 * @see llvm::SwitchInst::getDefaultDest()
2665 */
Nate Begeman43c322b2011-08-23 20:27:46 +00002666LLVMBasicBlockRef LLVMGetSwitchDefaultDest(LLVMValueRef SwitchInstr);
2667
Gregory Szorc34c863a2012-03-21 03:54:29 +00002668/**
Peter Zotov2481c752014-10-28 19:46:56 +00002669 * @}
2670 */
2671
2672/**
Amaury Sechet1dcf5772016-02-09 22:50:53 +00002673 * @defgroup LLVMCCoreValueInstructionAlloca Allocas
2674 *
2675 * Functions in this group only apply to instructions that map to
2676 * llvm::AllocaInst instances.
2677 *
2678 * @{
2679 */
2680
2681/**
2682 * Obtain the type that is being allocated by the alloca instruction.
2683 */
2684LLVMTypeRef LLVMGetAllocatedType(LLVMValueRef Alloca);
2685
2686/**
2687 * @}
2688 */
2689
2690/**
Amaury Sechet053ac452016-02-17 22:51:03 +00002691 * @defgroup LLVMCCoreValueInstructionGetElementPointer GEPs
2692 *
2693 * Functions in this group only apply to instructions that map to
2694 * llvm::GetElementPtrInst instances.
2695 *
2696 * @{
2697 */
2698
2699/**
2700 * Check whether the given GEP instruction is inbounds.
2701 */
2702LLVMBool LLVMIsInBounds(LLVMValueRef GEP);
2703
2704/**
2705 * Set the given GEP instruction to be inbounds or not.
2706 */
2707void LLVMSetIsInBounds(LLVMValueRef GEP, LLVMBool b);
2708
2709/**
2710 * @}
2711 */
2712
2713/**
Gregory Szorc34c863a2012-03-21 03:54:29 +00002714 * @defgroup LLVMCCoreValueInstructionPHINode PHI Nodes
2715 *
2716 * Functions in this group only apply to instructions that map to
2717 * llvm::PHINode instances.
2718 *
2719 * @{
2720 */
2721
2722/**
2723 * Add an incoming value to the end of a PHI list.
2724 */
Gordon Henriksen44dd8fb2007-10-08 18:14:39 +00002725void LLVMAddIncoming(LLVMValueRef PhiNode, LLVMValueRef *IncomingValues,
2726 LLVMBasicBlockRef *IncomingBlocks, unsigned Count);
Gregory Szorc34c863a2012-03-21 03:54:29 +00002727
2728/**
2729 * Obtain the number of incoming basic blocks to a PHI node.
2730 */
Gordon Henriksen44dd8fb2007-10-08 18:14:39 +00002731unsigned LLVMCountIncoming(LLVMValueRef PhiNode);
Gregory Szorc34c863a2012-03-21 03:54:29 +00002732
2733/**
Daniel Dunbar06b9f9e2013-08-16 23:30:19 +00002734 * Obtain an incoming value to a PHI node as an LLVMValueRef.
Gregory Szorc34c863a2012-03-21 03:54:29 +00002735 */
Gordon Henriksen44dd8fb2007-10-08 18:14:39 +00002736LLVMValueRef LLVMGetIncomingValue(LLVMValueRef PhiNode, unsigned Index);
Gregory Szorc34c863a2012-03-21 03:54:29 +00002737
2738/**
Daniel Dunbar06b9f9e2013-08-16 23:30:19 +00002739 * Obtain an incoming value to a PHI node as an LLVMBasicBlockRef.
Gregory Szorc34c863a2012-03-21 03:54:29 +00002740 */
Gordon Henriksen44dd8fb2007-10-08 18:14:39 +00002741LLVMBasicBlockRef LLVMGetIncomingBlock(LLVMValueRef PhiNode, unsigned Index);
Gordon Henriksenc23b66c2007-09-26 20:56:12 +00002742
Gregory Szorc34c863a2012-03-21 03:54:29 +00002743/**
2744 * @}
2745 */
Gordon Henriksenc23b66c2007-09-26 20:56:12 +00002746
Gregory Szorc34c863a2012-03-21 03:54:29 +00002747/**
Amaury Sechetaad93532016-02-10 00:38:50 +00002748 * @defgroup LLVMCCoreValueInstructionExtractValue ExtractValue
2749 * @defgroup LLVMCCoreValueInstructionInsertValue InsertValue
2750 *
2751 * Functions in this group only apply to instructions that map to
2752 * llvm::ExtractValue and llvm::InsertValue instances.
2753 *
2754 * @{
2755 */
2756
2757/**
2758 * Obtain the number of indices.
Amaury Sechet053ac452016-02-17 22:51:03 +00002759 * NB: This also works on GEP.
Amaury Sechetaad93532016-02-10 00:38:50 +00002760 */
2761unsigned LLVMGetNumIndices(LLVMValueRef Inst);
2762
2763/**
2764 * Obtain the indices as an array.
2765 */
2766const unsigned *LLVMGetIndices(LLVMValueRef Inst);
2767
2768/**
2769 * @}
2770 */
2771
2772/**
Gregory Szorc34c863a2012-03-21 03:54:29 +00002773 * @}
2774 */
2775
2776/**
2777 * @}
2778 */
2779
2780/**
2781 * @defgroup LLVMCCoreInstructionBuilder Instruction Builders
2782 *
2783 * An instruction builder represents a point within a basic block and is
2784 * the exclusive means of building instructions using the C interface.
2785 *
2786 * @{
Gordon Henriksenc23b66c2007-09-26 20:56:12 +00002787 */
2788
Erick Tryzelaar262332f2009-08-14 00:01:31 +00002789LLVMBuilderRef LLVMCreateBuilderInContext(LLVMContextRef C);
Gordon Henriksena735a9c2008-05-04 12:55:34 +00002790LLVMBuilderRef LLVMCreateBuilder(void);
Gordon Henriksen054817c2008-03-19 03:47:18 +00002791void LLVMPositionBuilder(LLVMBuilderRef Builder, LLVMBasicBlockRef Block,
2792 LLVMValueRef Instr);
Gordon Henriksenc23b66c2007-09-26 20:56:12 +00002793void LLVMPositionBuilderBefore(LLVMBuilderRef Builder, LLVMValueRef Instr);
2794void LLVMPositionBuilderAtEnd(LLVMBuilderRef Builder, LLVMBasicBlockRef Block);
Gordon Henriksen265f7802008-03-19 01:11:35 +00002795LLVMBasicBlockRef LLVMGetInsertBlock(LLVMBuilderRef Builder);
Chris Lattner3d1f5522008-12-17 21:39:50 +00002796void LLVMClearInsertionPosition(LLVMBuilderRef Builder);
2797void LLVMInsertIntoBuilder(LLVMBuilderRef Builder, LLVMValueRef Instr);
Erick Tryzelaar9813bea2009-08-16 02:20:57 +00002798void LLVMInsertIntoBuilderWithName(LLVMBuilderRef Builder, LLVMValueRef Instr,
2799 const char *Name);
Gordon Henriksenc23b66c2007-09-26 20:56:12 +00002800void LLVMDisposeBuilder(LLVMBuilderRef Builder);
2801
Erick Tryzelaard8531fa2010-02-28 09:45:59 +00002802/* Metadata */
2803void LLVMSetCurrentDebugLocation(LLVMBuilderRef Builder, LLVMValueRef L);
2804LLVMValueRef LLVMGetCurrentDebugLocation(LLVMBuilderRef Builder);
2805void LLVMSetInstDebugLocation(LLVMBuilderRef Builder, LLVMValueRef Inst);
2806
Gordon Henriksenc23b66c2007-09-26 20:56:12 +00002807/* Terminators */
2808LLVMValueRef LLVMBuildRetVoid(LLVMBuilderRef);
2809LLVMValueRef LLVMBuildRet(LLVMBuilderRef, LLVMValueRef V);
Erick Tryzelaarfd529d72009-08-19 08:36:49 +00002810LLVMValueRef LLVMBuildAggregateRet(LLVMBuilderRef, LLVMValueRef *RetVals,
Erick Tryzelaar3045b8b2009-08-16 02:19:59 +00002811 unsigned N);
Gordon Henriksenc23b66c2007-09-26 20:56:12 +00002812LLVMValueRef LLVMBuildBr(LLVMBuilderRef, LLVMBasicBlockRef Dest);
2813LLVMValueRef LLVMBuildCondBr(LLVMBuilderRef, LLVMValueRef If,
2814 LLVMBasicBlockRef Then, LLVMBasicBlockRef Else);
2815LLVMValueRef LLVMBuildSwitch(LLVMBuilderRef, LLVMValueRef V,
2816 LLVMBasicBlockRef Else, unsigned NumCases);
Erick Tryzelaar0fb26ef2010-02-28 09:46:06 +00002817LLVMValueRef LLVMBuildIndirectBr(LLVMBuilderRef B, LLVMValueRef Addr,
2818 unsigned NumDests);
Gordon Henriksenc23b66c2007-09-26 20:56:12 +00002819LLVMValueRef LLVMBuildInvoke(LLVMBuilderRef, LLVMValueRef Fn,
2820 LLVMValueRef *Args, unsigned NumArgs,
2821 LLVMBasicBlockRef Then, LLVMBasicBlockRef Catch,
2822 const char *Name);
Benjamin Kramer5a6568832011-08-19 01:36:54 +00002823LLVMValueRef LLVMBuildLandingPad(LLVMBuilderRef B, LLVMTypeRef Ty,
Reid Kleckneref9828f2015-07-16 01:16:39 +00002824 LLVMValueRef PersFn, unsigned NumClauses,
2825 const char *Name);
Bill Wendlingf891bf82011-07-31 06:30:59 +00002826LLVMValueRef LLVMBuildResume(LLVMBuilderRef B, LLVMValueRef Exn);
Gordon Henriksenc23b66c2007-09-26 20:56:12 +00002827LLVMValueRef LLVMBuildUnreachable(LLVMBuilderRef);
2828
Gordon Henriksen097102c2008-01-01 05:50:53 +00002829/* Add a case to the switch instruction */
2830void LLVMAddCase(LLVMValueRef Switch, LLVMValueRef OnVal,
2831 LLVMBasicBlockRef Dest);
2832
Erick Tryzelaar0fb26ef2010-02-28 09:46:06 +00002833/* Add a destination to the indirectbr instruction */
2834void LLVMAddDestination(LLVMValueRef IndirectBr, LLVMBasicBlockRef Dest);
2835
Amaury Sechete39e8532016-02-18 20:38:32 +00002836/* Get the number of clauses on the landingpad instruction */
2837unsigned LLVMGetNumClauses(LLVMValueRef LandingPad);
2838
2839/* Get the value of the clause at idnex Idx on the landingpad instruction */
2840LLVMValueRef LLVMGetClause(LLVMValueRef LandingPad, unsigned Idx);
2841
Bill Wendlingfae14752011-08-12 20:24:12 +00002842/* Add a catch or filter clause to the landingpad instruction */
2843void LLVMAddClause(LLVMValueRef LandingPad, LLVMValueRef ClauseVal);
2844
Amaury Sechete39e8532016-02-18 20:38:32 +00002845/* Get the 'cleanup' flag in the landingpad instruction */
2846LLVMBool LLVMIsCleanup(LLVMValueRef LandingPad);
2847
Bill Wendlingfae14752011-08-12 20:24:12 +00002848/* Set the 'cleanup' flag in the landingpad instruction */
2849void LLVMSetCleanup(LLVMValueRef LandingPad, LLVMBool Val);
2850
Gordon Henriksenc23b66c2007-09-26 20:56:12 +00002851/* Arithmetic */
2852LLVMValueRef LLVMBuildAdd(LLVMBuilderRef, LLVMValueRef LHS, LLVMValueRef RHS,
2853 const char *Name);
Erick Tryzelaar3045b8b2009-08-16 02:19:59 +00002854LLVMValueRef LLVMBuildNSWAdd(LLVMBuilderRef, LLVMValueRef LHS, LLVMValueRef RHS,
2855 const char *Name);
Erick Tryzelaar4c340c72010-02-28 05:51:43 +00002856LLVMValueRef LLVMBuildNUWAdd(LLVMBuilderRef, LLVMValueRef LHS, LLVMValueRef RHS,
2857 const char *Name);
Erick Tryzelaar3045b8b2009-08-16 02:19:59 +00002858LLVMValueRef LLVMBuildFAdd(LLVMBuilderRef, LLVMValueRef LHS, LLVMValueRef RHS,
2859 const char *Name);
Gordon Henriksenc23b66c2007-09-26 20:56:12 +00002860LLVMValueRef LLVMBuildSub(LLVMBuilderRef, LLVMValueRef LHS, LLVMValueRef RHS,
2861 const char *Name);
Erick Tryzelaar4c340c72010-02-28 05:51:43 +00002862LLVMValueRef LLVMBuildNSWSub(LLVMBuilderRef, LLVMValueRef LHS, LLVMValueRef RHS,
2863 const char *Name);
2864LLVMValueRef LLVMBuildNUWSub(LLVMBuilderRef, LLVMValueRef LHS, LLVMValueRef RHS,
2865 const char *Name);
Erick Tryzelaar3045b8b2009-08-16 02:19:59 +00002866LLVMValueRef LLVMBuildFSub(LLVMBuilderRef, LLVMValueRef LHS, LLVMValueRef RHS,
2867 const char *Name);
Gordon Henriksenc23b66c2007-09-26 20:56:12 +00002868LLVMValueRef LLVMBuildMul(LLVMBuilderRef, LLVMValueRef LHS, LLVMValueRef RHS,
2869 const char *Name);
Erick Tryzelaar4c340c72010-02-28 05:51:43 +00002870LLVMValueRef LLVMBuildNSWMul(LLVMBuilderRef, LLVMValueRef LHS, LLVMValueRef RHS,
2871 const char *Name);
2872LLVMValueRef LLVMBuildNUWMul(LLVMBuilderRef, LLVMValueRef LHS, LLVMValueRef RHS,
2873 const char *Name);
Erick Tryzelaar3045b8b2009-08-16 02:19:59 +00002874LLVMValueRef LLVMBuildFMul(LLVMBuilderRef, LLVMValueRef LHS, LLVMValueRef RHS,
2875 const char *Name);
Gordon Henriksenc23b66c2007-09-26 20:56:12 +00002876LLVMValueRef LLVMBuildUDiv(LLVMBuilderRef, LLVMValueRef LHS, LLVMValueRef RHS,
2877 const char *Name);
2878LLVMValueRef LLVMBuildSDiv(LLVMBuilderRef, LLVMValueRef LHS, LLVMValueRef RHS,
2879 const char *Name);
Erick Tryzelaar3045b8b2009-08-16 02:19:59 +00002880LLVMValueRef LLVMBuildExactSDiv(LLVMBuilderRef, LLVMValueRef LHS, LLVMValueRef RHS,
2881 const char *Name);
Gordon Henriksenc23b66c2007-09-26 20:56:12 +00002882LLVMValueRef LLVMBuildFDiv(LLVMBuilderRef, LLVMValueRef LHS, LLVMValueRef RHS,
2883 const char *Name);
2884LLVMValueRef LLVMBuildURem(LLVMBuilderRef, LLVMValueRef LHS, LLVMValueRef RHS,
2885 const char *Name);
2886LLVMValueRef LLVMBuildSRem(LLVMBuilderRef, LLVMValueRef LHS, LLVMValueRef RHS,
2887 const char *Name);
2888LLVMValueRef LLVMBuildFRem(LLVMBuilderRef, LLVMValueRef LHS, LLVMValueRef RHS,
2889 const char *Name);
2890LLVMValueRef LLVMBuildShl(LLVMBuilderRef, LLVMValueRef LHS, LLVMValueRef RHS,
2891 const char *Name);
2892LLVMValueRef LLVMBuildLShr(LLVMBuilderRef, LLVMValueRef LHS, LLVMValueRef RHS,
2893 const char *Name);
2894LLVMValueRef LLVMBuildAShr(LLVMBuilderRef, LLVMValueRef LHS, LLVMValueRef RHS,
2895 const char *Name);
2896LLVMValueRef LLVMBuildAnd(LLVMBuilderRef, LLVMValueRef LHS, LLVMValueRef RHS,
2897 const char *Name);
2898LLVMValueRef LLVMBuildOr(LLVMBuilderRef, LLVMValueRef LHS, LLVMValueRef RHS,
2899 const char *Name);
2900LLVMValueRef LLVMBuildXor(LLVMBuilderRef, LLVMValueRef LHS, LLVMValueRef RHS,
2901 const char *Name);
Erick Tryzelaar31831792010-02-28 05:51:27 +00002902LLVMValueRef LLVMBuildBinOp(LLVMBuilderRef B, LLVMOpcode Op,
2903 LLVMValueRef LHS, LLVMValueRef RHS,
2904 const char *Name);
Gordon Henriksenc23b66c2007-09-26 20:56:12 +00002905LLVMValueRef LLVMBuildNeg(LLVMBuilderRef, LLVMValueRef V, const char *Name);
Erick Tryzelaar4c340c72010-02-28 05:51:43 +00002906LLVMValueRef LLVMBuildNSWNeg(LLVMBuilderRef B, LLVMValueRef V,
2907 const char *Name);
2908LLVMValueRef LLVMBuildNUWNeg(LLVMBuilderRef B, LLVMValueRef V,
2909 const char *Name);
Dan Gohmanf919bd62009-09-28 21:51:41 +00002910LLVMValueRef LLVMBuildFNeg(LLVMBuilderRef, LLVMValueRef V, const char *Name);
Gordon Henriksenc23b66c2007-09-26 20:56:12 +00002911LLVMValueRef LLVMBuildNot(LLVMBuilderRef, LLVMValueRef V, const char *Name);
2912
2913/* Memory */
2914LLVMValueRef LLVMBuildMalloc(LLVMBuilderRef, LLVMTypeRef Ty, const char *Name);
2915LLVMValueRef LLVMBuildArrayMalloc(LLVMBuilderRef, LLVMTypeRef Ty,
2916 LLVMValueRef Val, const char *Name);
2917LLVMValueRef LLVMBuildAlloca(LLVMBuilderRef, LLVMTypeRef Ty, const char *Name);
2918LLVMValueRef LLVMBuildArrayAlloca(LLVMBuilderRef, LLVMTypeRef Ty,
2919 LLVMValueRef Val, const char *Name);
2920LLVMValueRef LLVMBuildFree(LLVMBuilderRef, LLVMValueRef PointerVal);
2921LLVMValueRef LLVMBuildLoad(LLVMBuilderRef, LLVMValueRef PointerVal,
2922 const char *Name);
2923LLVMValueRef LLVMBuildStore(LLVMBuilderRef, LLVMValueRef Val, LLVMValueRef Ptr);
2924LLVMValueRef LLVMBuildGEP(LLVMBuilderRef B, LLVMValueRef Pointer,
2925 LLVMValueRef *Indices, unsigned NumIndices,
2926 const char *Name);
Erick Tryzelaar3045b8b2009-08-16 02:19:59 +00002927LLVMValueRef LLVMBuildInBoundsGEP(LLVMBuilderRef B, LLVMValueRef Pointer,
2928 LLVMValueRef *Indices, unsigned NumIndices,
2929 const char *Name);
2930LLVMValueRef LLVMBuildStructGEP(LLVMBuilderRef B, LLVMValueRef Pointer,
2931 unsigned Idx, const char *Name);
2932LLVMValueRef LLVMBuildGlobalString(LLVMBuilderRef B, const char *Str,
2933 const char *Name);
2934LLVMValueRef LLVMBuildGlobalStringPtr(LLVMBuilderRef B, const char *Str,
2935 const char *Name);
Chris Lattner2cc6f9d2012-03-22 03:54:15 +00002936LLVMBool LLVMGetVolatile(LLVMValueRef MemoryAccessInst);
2937void LLVMSetVolatile(LLVMValueRef MemoryAccessInst, LLVMBool IsVolatile);
Andrew Wilkinsb7362ce2015-08-02 12:16:57 +00002938LLVMAtomicOrdering LLVMGetOrdering(LLVMValueRef MemoryAccessInst);
2939void LLVMSetOrdering(LLVMValueRef MemoryAccessInst, LLVMAtomicOrdering Ordering);
Gordon Henriksenc23b66c2007-09-26 20:56:12 +00002940
2941/* Casts */
2942LLVMValueRef LLVMBuildTrunc(LLVMBuilderRef, LLVMValueRef Val,
2943 LLVMTypeRef DestTy, const char *Name);
2944LLVMValueRef LLVMBuildZExt(LLVMBuilderRef, LLVMValueRef Val,
2945 LLVMTypeRef DestTy, const char *Name);
2946LLVMValueRef LLVMBuildSExt(LLVMBuilderRef, LLVMValueRef Val,
2947 LLVMTypeRef DestTy, const char *Name);
2948LLVMValueRef LLVMBuildFPToUI(LLVMBuilderRef, LLVMValueRef Val,
2949 LLVMTypeRef DestTy, const char *Name);
2950LLVMValueRef LLVMBuildFPToSI(LLVMBuilderRef, LLVMValueRef Val,
2951 LLVMTypeRef DestTy, const char *Name);
2952LLVMValueRef LLVMBuildUIToFP(LLVMBuilderRef, LLVMValueRef Val,
2953 LLVMTypeRef DestTy, const char *Name);
2954LLVMValueRef LLVMBuildSIToFP(LLVMBuilderRef, LLVMValueRef Val,
2955 LLVMTypeRef DestTy, const char *Name);
2956LLVMValueRef LLVMBuildFPTrunc(LLVMBuilderRef, LLVMValueRef Val,
2957 LLVMTypeRef DestTy, const char *Name);
2958LLVMValueRef LLVMBuildFPExt(LLVMBuilderRef, LLVMValueRef Val,
2959 LLVMTypeRef DestTy, const char *Name);
2960LLVMValueRef LLVMBuildPtrToInt(LLVMBuilderRef, LLVMValueRef Val,
2961 LLVMTypeRef DestTy, const char *Name);
2962LLVMValueRef LLVMBuildIntToPtr(LLVMBuilderRef, LLVMValueRef Val,
2963 LLVMTypeRef DestTy, const char *Name);
2964LLVMValueRef LLVMBuildBitCast(LLVMBuilderRef, LLVMValueRef Val,
2965 LLVMTypeRef DestTy, const char *Name);
Matt Arsenaultb03bd4d2013-11-15 01:34:59 +00002966LLVMValueRef LLVMBuildAddrSpaceCast(LLVMBuilderRef, LLVMValueRef Val,
2967 LLVMTypeRef DestTy, const char *Name);
Erick Tryzelaar3045b8b2009-08-16 02:19:59 +00002968LLVMValueRef LLVMBuildZExtOrBitCast(LLVMBuilderRef, LLVMValueRef Val,
2969 LLVMTypeRef DestTy, const char *Name);
2970LLVMValueRef LLVMBuildSExtOrBitCast(LLVMBuilderRef, LLVMValueRef Val,
2971 LLVMTypeRef DestTy, const char *Name);
2972LLVMValueRef LLVMBuildTruncOrBitCast(LLVMBuilderRef, LLVMValueRef Val,
2973 LLVMTypeRef DestTy, const char *Name);
Erick Tryzelaar31831792010-02-28 05:51:27 +00002974LLVMValueRef LLVMBuildCast(LLVMBuilderRef B, LLVMOpcode Op, LLVMValueRef Val,
2975 LLVMTypeRef DestTy, const char *Name);
Erick Tryzelaar3045b8b2009-08-16 02:19:59 +00002976LLVMValueRef LLVMBuildPointerCast(LLVMBuilderRef, LLVMValueRef Val,
2977 LLVMTypeRef DestTy, const char *Name);
Duncan Sands9d786d72009-11-23 10:49:03 +00002978LLVMValueRef LLVMBuildIntCast(LLVMBuilderRef, LLVMValueRef Val, /*Signed cast!*/
Erick Tryzelaar3045b8b2009-08-16 02:19:59 +00002979 LLVMTypeRef DestTy, const char *Name);
2980LLVMValueRef LLVMBuildFPCast(LLVMBuilderRef, LLVMValueRef Val,
2981 LLVMTypeRef DestTy, const char *Name);
Gordon Henriksenc23b66c2007-09-26 20:56:12 +00002982
2983/* Comparisons */
2984LLVMValueRef LLVMBuildICmp(LLVMBuilderRef, LLVMIntPredicate Op,
2985 LLVMValueRef LHS, LLVMValueRef RHS,
2986 const char *Name);
2987LLVMValueRef LLVMBuildFCmp(LLVMBuilderRef, LLVMRealPredicate Op,
2988 LLVMValueRef LHS, LLVMValueRef RHS,
2989 const char *Name);
2990
2991/* Miscellaneous instructions */
2992LLVMValueRef LLVMBuildPhi(LLVMBuilderRef, LLVMTypeRef Ty, const char *Name);
2993LLVMValueRef LLVMBuildCall(LLVMBuilderRef, LLVMValueRef Fn,
2994 LLVMValueRef *Args, unsigned NumArgs,
2995 const char *Name);
2996LLVMValueRef LLVMBuildSelect(LLVMBuilderRef, LLVMValueRef If,
2997 LLVMValueRef Then, LLVMValueRef Else,
2998 const char *Name);
2999LLVMValueRef LLVMBuildVAArg(LLVMBuilderRef, LLVMValueRef List, LLVMTypeRef Ty,
3000 const char *Name);
3001LLVMValueRef LLVMBuildExtractElement(LLVMBuilderRef, LLVMValueRef VecVal,
3002 LLVMValueRef Index, const char *Name);
3003LLVMValueRef LLVMBuildInsertElement(LLVMBuilderRef, LLVMValueRef VecVal,
3004 LLVMValueRef EltVal, LLVMValueRef Index,
3005 const char *Name);
3006LLVMValueRef LLVMBuildShuffleVector(LLVMBuilderRef, LLVMValueRef V1,
3007 LLVMValueRef V2, LLVMValueRef Mask,
3008 const char *Name);
Dan Gohmand5104a52008-11-03 22:55:43 +00003009LLVMValueRef LLVMBuildExtractValue(LLVMBuilderRef, LLVMValueRef AggVal,
3010 unsigned Index, const char *Name);
3011LLVMValueRef LLVMBuildInsertValue(LLVMBuilderRef, LLVMValueRef AggVal,
3012 LLVMValueRef EltVal, unsigned Index,
3013 const char *Name);
Gordon Henriksen76a03742007-09-18 03:18:57 +00003014
Erick Tryzelaar3045b8b2009-08-16 02:19:59 +00003015LLVMValueRef LLVMBuildIsNull(LLVMBuilderRef, LLVMValueRef Val,
3016 const char *Name);
3017LLVMValueRef LLVMBuildIsNotNull(LLVMBuilderRef, LLVMValueRef Val,
3018 const char *Name);
3019LLVMValueRef LLVMBuildPtrDiff(LLVMBuilderRef, LLVMValueRef LHS,
3020 LLVMValueRef RHS, const char *Name);
Filip Pizlo0d3f7ec2013-11-20 00:07:49 +00003021LLVMValueRef LLVMBuildFence(LLVMBuilderRef B, LLVMAtomicOrdering ordering,
3022 LLVMBool singleThread, const char *Name);
3023LLVMValueRef LLVMBuildAtomicRMW(LLVMBuilderRef B, LLVMAtomicRMWBinOp op,
NAKAMURA Takumia3a81352013-10-23 17:56:29 +00003024 LLVMValueRef PTR, LLVMValueRef Val,
3025 LLVMAtomicOrdering ordering,
Carlo Kok8c6719b2013-04-23 13:21:19 +00003026 LLVMBool singleThread);
Mehdi Amini43165d92016-03-19 21:28:28 +00003027LLVMValueRef LLVMBuildAtomicCmpXchg(LLVMBuilderRef B, LLVMValueRef Ptr,
3028 LLVMValueRef Cmp, LLVMValueRef New,
3029 LLVMAtomicOrdering SuccessOrdering,
3030 LLVMAtomicOrdering FailureOrdering,
3031 LLVMBool SingleThread);
3032
3033LLVMBool LLVMIsAtomicSingleThread(LLVMValueRef AtomicInst);
3034void LLVMSetAtomicSingleThread(LLVMValueRef AtomicInst, LLVMBool SingleThread);
3035
3036LLVMAtomicOrdering LLVMGetCmpXchgSuccessOrdering(LLVMValueRef CmpXchgInst);
3037void LLVMSetCmpXchgSuccessOrdering(LLVMValueRef CmpXchgInst,
3038 LLVMAtomicOrdering Ordering);
3039LLVMAtomicOrdering LLVMGetCmpXchgFailureOrdering(LLVMValueRef CmpXchgInst);
3040void LLVMSetCmpXchgFailureOrdering(LLVMValueRef CmpXchgInst,
3041 LLVMAtomicOrdering Ordering);
Erick Tryzelaar3045b8b2009-08-16 02:19:59 +00003042
Gregory Szorc34c863a2012-03-21 03:54:29 +00003043/**
3044 * @}
3045 */
Gordon Henriksen34eb6d82007-12-19 22:30:40 +00003046
Gregory Szorc34c863a2012-03-21 03:54:29 +00003047/**
3048 * @defgroup LLVMCCoreModuleProvider Module Providers
3049 *
3050 * @{
3051 */
Gordon Henriksen0a68fe22007-12-12 01:04:30 +00003052
Gregory Szorc34c863a2012-03-21 03:54:29 +00003053/**
3054 * Changes the type of M so it can be passed to FunctionPassManagers and the
Jeffrey Yasskin091217b2010-01-27 20:34:15 +00003055 * JIT. They take ModuleProviders for historical reasons.
Gordon Henriksen0a68fe22007-12-12 01:04:30 +00003056 */
3057LLVMModuleProviderRef
3058LLVMCreateModuleProviderForExistingModule(LLVMModuleRef M);
3059
Gregory Szorc34c863a2012-03-21 03:54:29 +00003060/**
3061 * Destroys the module M.
Gordon Henriksen0a68fe22007-12-12 01:04:30 +00003062 */
Jeffrey Yasskin091217b2010-01-27 20:34:15 +00003063void LLVMDisposeModuleProvider(LLVMModuleProviderRef M);
Gordon Henriksen0a68fe22007-12-12 01:04:30 +00003064
Gregory Szorc34c863a2012-03-21 03:54:29 +00003065/**
3066 * @}
3067 */
Gordon Henriksen34eb6d82007-12-19 22:30:40 +00003068
Gregory Szorc34c863a2012-03-21 03:54:29 +00003069/**
3070 * @defgroup LLVMCCoreMemoryBuffers Memory Buffers
3071 *
3072 * @{
3073 */
Gordon Henriksen34eb6d82007-12-19 22:30:40 +00003074
Chris Lattner25963c62010-01-09 22:27:07 +00003075LLVMBool LLVMCreateMemoryBufferWithContentsOfFile(const char *Path,
3076 LLVMMemoryBufferRef *OutMemBuf,
3077 char **OutMessage);
3078LLVMBool LLVMCreateMemoryBufferWithSTDIN(LLVMMemoryBufferRef *OutMemBuf,
3079 char **OutMessage);
Bill Wendling526276a2013-02-14 19:11:28 +00003080LLVMMemoryBufferRef LLVMCreateMemoryBufferWithMemoryRange(const char *InputData,
3081 size_t InputDataLength,
3082 const char *BufferName,
Bill Wendlingc9baa962013-02-14 19:39:14 +00003083 LLVMBool RequiresNullTerminator);
Bill Wendling526276a2013-02-14 19:11:28 +00003084LLVMMemoryBufferRef LLVMCreateMemoryBufferWithMemoryRangeCopy(const char *InputData,
3085 size_t InputDataLength,
3086 const char *BufferName);
Tom Stellard62c03202013-04-18 19:50:53 +00003087const char *LLVMGetBufferStart(LLVMMemoryBufferRef MemBuf);
Tom Stellardb7fb7242013-04-16 23:12:51 +00003088size_t LLVMGetBufferSize(LLVMMemoryBufferRef MemBuf);
Gordon Henriksen34eb6d82007-12-19 22:30:40 +00003089void LLVMDisposeMemoryBuffer(LLVMMemoryBufferRef MemBuf);
3090
Gregory Szorc34c863a2012-03-21 03:54:29 +00003091/**
3092 * @}
3093 */
3094
3095/**
3096 * @defgroup LLVMCCorePassRegistry Pass Registry
3097 *
3098 * @{
3099 */
Owen Anderson4698c5d2010-10-07 17:55:47 +00003100
3101/** Return the global pass registry, for use with initialization functions.
Gregory Szorc34c863a2012-03-21 03:54:29 +00003102 @see llvm::PassRegistry::getPassRegistry */
Owen Anderson4698c5d2010-10-07 17:55:47 +00003103LLVMPassRegistryRef LLVMGetGlobalPassRegistry(void);
Gordon Henriksen878114b2008-03-16 04:20:44 +00003104
Gregory Szorc34c863a2012-03-21 03:54:29 +00003105/**
3106 * @}
3107 */
3108
3109/**
3110 * @defgroup LLVMCCorePassManagers Pass Managers
3111 *
3112 * @{
3113 */
Gordon Henriksen878114b2008-03-16 04:20:44 +00003114
3115/** Constructs a new whole-module pass pipeline. This type of pipeline is
3116 suitable for link-time optimization and whole-module transformations.
Gregory Szorc34c863a2012-03-21 03:54:29 +00003117 @see llvm::PassManager::PassManager */
Gordon Henriksena735a9c2008-05-04 12:55:34 +00003118LLVMPassManagerRef LLVMCreatePassManager(void);
Gordon Henriksen878114b2008-03-16 04:20:44 +00003119
3120/** Constructs a new function-by-function pass pipeline over the module
3121 provider. It does not take ownership of the module provider. This type of
3122 pipeline is suitable for code generation and JIT compilation tasks.
Gregory Szorc34c863a2012-03-21 03:54:29 +00003123 @see llvm::FunctionPassManager::FunctionPassManager */
Erick Tryzelaarad0e0cb2010-03-02 23:58:54 +00003124LLVMPassManagerRef LLVMCreateFunctionPassManagerForModule(LLVMModuleRef M);
3125
3126/** Deprecated: Use LLVMCreateFunctionPassManagerForModule instead. */
Gordon Henriksen878114b2008-03-16 04:20:44 +00003127LLVMPassManagerRef LLVMCreateFunctionPassManager(LLVMModuleProviderRef MP);
3128
3129/** Initializes, executes on the provided module, and finalizes all of the
3130 passes scheduled in the pass manager. Returns 1 if any of the passes
Gregory Szorc34c863a2012-03-21 03:54:29 +00003131 modified the module, 0 otherwise.
3132 @see llvm::PassManager::run(Module&) */
Chris Lattner25963c62010-01-09 22:27:07 +00003133LLVMBool LLVMRunPassManager(LLVMPassManagerRef PM, LLVMModuleRef M);
Gordon Henriksen878114b2008-03-16 04:20:44 +00003134
3135/** Initializes all of the function passes scheduled in the function pass
3136 manager. Returns 1 if any of the passes modified the module, 0 otherwise.
Gregory Szorc34c863a2012-03-21 03:54:29 +00003137 @see llvm::FunctionPassManager::doInitialization */
Chris Lattner25963c62010-01-09 22:27:07 +00003138LLVMBool LLVMInitializeFunctionPassManager(LLVMPassManagerRef FPM);
Gordon Henriksen878114b2008-03-16 04:20:44 +00003139
3140/** Executes all of the function passes scheduled in the function pass manager
3141 on the provided function. Returns 1 if any of the passes modified the
3142 function, false otherwise.
Gregory Szorc34c863a2012-03-21 03:54:29 +00003143 @see llvm::FunctionPassManager::run(Function&) */
Chris Lattner25963c62010-01-09 22:27:07 +00003144LLVMBool LLVMRunFunctionPassManager(LLVMPassManagerRef FPM, LLVMValueRef F);
Gordon Henriksen878114b2008-03-16 04:20:44 +00003145
3146/** Finalizes all of the function passes scheduled in in the function pass
3147 manager. Returns 1 if any of the passes modified the module, 0 otherwise.
Gregory Szorc34c863a2012-03-21 03:54:29 +00003148 @see llvm::FunctionPassManager::doFinalization */
Chris Lattner25963c62010-01-09 22:27:07 +00003149LLVMBool LLVMFinalizeFunctionPassManager(LLVMPassManagerRef FPM);
Gordon Henriksen878114b2008-03-16 04:20:44 +00003150
3151/** Frees the memory of a pass pipeline. For function pipelines, does not free
3152 the module provider.
Gregory Szorc34c863a2012-03-21 03:54:29 +00003153 @see llvm::PassManagerBase::~PassManagerBase. */
Gordon Henriksen878114b2008-03-16 04:20:44 +00003154void LLVMDisposePassManager(LLVMPassManagerRef PM);
3155
Gregory Szorc34c863a2012-03-21 03:54:29 +00003156/**
3157 * @}
3158 */
3159
3160/**
Duncan Sands1cba0a82013-02-17 16:35:51 +00003161 * @defgroup LLVMCCoreThreading Threading
3162 *
3163 * Handle the structures needed to make LLVM safe for multithreading.
3164 *
3165 * @{
3166 */
3167
Chandler Carruth39cd2162014-06-27 15:13:01 +00003168/** Deprecated: Multi-threading can only be enabled/disabled with the compile
3169 time define LLVM_ENABLE_THREADS. This function always returns
3170 LLVMIsMultithreaded(). */
Benjamin Kramer325ec892013-10-23 16:57:34 +00003171LLVMBool LLVMStartMultithreaded(void);
Duncan Sands1cba0a82013-02-17 16:35:51 +00003172
Chandler Carruth39cd2162014-06-27 15:13:01 +00003173/** Deprecated: Multi-threading can only be enabled/disabled with the compile
3174 time define LLVM_ENABLE_THREADS. */
Benjamin Kramer325ec892013-10-23 16:57:34 +00003175void LLVMStopMultithreaded(void);
Duncan Sands1cba0a82013-02-17 16:35:51 +00003176
3177/** Check whether LLVM is executing in thread-safe mode or not.
3178 @see llvm::llvm_is_multithreaded */
Benjamin Kramer325ec892013-10-23 16:57:34 +00003179LLVMBool LLVMIsMultithreaded(void);
Duncan Sands1cba0a82013-02-17 16:35:51 +00003180
3181/**
3182 * @}
3183 */
3184
3185/**
Gregory Szorc34c863a2012-03-21 03:54:29 +00003186 * @}
3187 */
3188
3189/**
3190 * @}
3191 */
Gordon Henriksen878114b2008-03-16 04:20:44 +00003192
Gordon Henriksen76a03742007-09-18 03:18:57 +00003193#ifdef __cplusplus
3194}
Eugene Zelenkoffec81c2015-11-04 22:32:32 +00003195#endif
Gordon Henriksen7330acd2007-10-05 23:59:36 +00003196
Eugene Zelenkoffec81c2015-11-04 22:32:32 +00003197#endif /* LLVM_C_CORE_H */