blob: 7ec8b8cffff4dae446ee352238409674dea8b04f [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 */
Amaury Sechetb130f432016-04-23 00:12:45 +0000639unsigned LLVMGetNamedMetadataNumOperands(LLVMModuleRef M, const char *Name);
Gregory Szorc34c863a2012-03-21 03:54:29 +0000640
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 */
Amaury Sechetb130f432016-04-23 00:12:45 +0000652void LLVMGetNamedMetadataOperands(LLVMModuleRef M, const char *Name,
653 LLVMValueRef *Dest);
Gregory Szorc34c863a2012-03-21 03:54:29 +0000654
655/**
656 * Add an operand to named metadata.
657 *
658 * @see llvm::Module::getNamedMetadata()
659 * @see llvm::MDNode::addOperand()
660 */
Amaury Sechetb130f432016-04-23 00:12:45 +0000661void LLVMAddNamedMetadataOperand(LLVMModuleRef M, const char *Name,
Gregory Szorc34c863a2012-03-21 03:54:29 +0000662 LLVMValueRef Val);
663
Gregory Szorc52d26602012-03-21 07:28:27 +0000664/**
665 * Add a function to a module under a specified name.
666 *
667 * @see llvm::Function::Create()
668 */
669LLVMValueRef LLVMAddFunction(LLVMModuleRef M, const char *Name,
670 LLVMTypeRef FunctionTy);
671
672/**
673 * Obtain a Function value from a Module by its name.
674 *
675 * The returned value corresponds to a llvm::Function value.
676 *
677 * @see llvm::Module::getFunction()
678 */
679LLVMValueRef LLVMGetNamedFunction(LLVMModuleRef M, const char *Name);
680
681/**
682 * Obtain an iterator to the first Function in a Module.
683 *
684 * @see llvm::Module::begin()
685 */
686LLVMValueRef LLVMGetFirstFunction(LLVMModuleRef M);
687
688/**
689 * Obtain an iterator to the last Function in a Module.
690 *
691 * @see llvm::Module::end()
692 */
693LLVMValueRef LLVMGetLastFunction(LLVMModuleRef M);
694
695/**
696 * Advance a Function iterator to the next Function.
697 *
698 * Returns NULL if the iterator was already at the end and there are no more
699 * functions.
700 */
701LLVMValueRef LLVMGetNextFunction(LLVMValueRef Fn);
702
703/**
704 * Decrement a Function iterator to the previous Function.
705 *
706 * Returns NULL if the iterator was already at the beginning and there are
707 * no previous functions.
708 */
709LLVMValueRef LLVMGetPreviousFunction(LLVMValueRef Fn);
Gregory Szorc34c863a2012-03-21 03:54:29 +0000710
711/**
712 * @}
713 */
714
715/**
716 * @defgroup LLVMCCoreType Types
717 *
718 * Types represent the type of a value.
719 *
720 * Types are associated with a context instance. The context internally
721 * deduplicates types so there is only 1 instance of a specific type
722 * alive at a time. In other words, a unique type is shared among all
723 * consumers within a context.
724 *
725 * A Type in the C API corresponds to llvm::Type.
726 *
727 * Types have the following hierarchy:
728 *
Gordon Henriksen76a03742007-09-18 03:18:57 +0000729 * types:
730 * integer type
731 * real type
732 * function type
733 * sequence types:
734 * array type
735 * pointer type
736 * vector type
737 * void type
738 * label type
739 * opaque type
Gregory Szorc34c863a2012-03-21 03:54:29 +0000740 *
741 * @{
Gordon Henriksen76a03742007-09-18 03:18:57 +0000742 */
743
Gregory Szorc34c863a2012-03-21 03:54:29 +0000744/**
745 * Obtain the enumerated type of a Type instance.
746 *
747 * @see llvm::Type:getTypeID()
748 */
Gordon Henriksen76a03742007-09-18 03:18:57 +0000749LLVMTypeKind LLVMGetTypeKind(LLVMTypeRef Ty);
Gregory Szorc34c863a2012-03-21 03:54:29 +0000750
751/**
752 * Whether the type has a known size.
753 *
754 * Things that don't have a size are abstract types, labels, and void.a
755 *
756 * @see llvm::Type::isSized()
757 */
Torok Edwin1cd9ade2011-10-06 12:13:28 +0000758LLVMBool LLVMTypeIsSized(LLVMTypeRef Ty);
Gordon Henriksena49d4352008-03-07 19:13:06 +0000759
Gregory Szorc34c863a2012-03-21 03:54:29 +0000760/**
761 * Obtain the context to which this type instance is associated.
762 *
763 * @see llvm::Type::getContext()
764 */
Erick Tryzelaar262332f2009-08-14 00:01:31 +0000765LLVMContextRef LLVMGetTypeContext(LLVMTypeRef Ty);
766
Gregory Szorc34c863a2012-03-21 03:54:29 +0000767/**
Anders Waldenborgb822cff2013-10-16 21:30:25 +0000768 * Dump a representation of a type to stderr.
769 *
770 * @see llvm::Type::dump()
771 */
772void LLVMDumpType(LLVMTypeRef Val);
773
774/**
Anders Waldenborg47b3bd32013-10-22 06:58:34 +0000775 * Return a string representation of the type. Use
776 * LLVMDisposeMessage to free the string.
777 *
778 * @see llvm::Type::print()
779 */
780char *LLVMPrintTypeToString(LLVMTypeRef Val);
781
782/**
Gregory Szorc34c863a2012-03-21 03:54:29 +0000783 * @defgroup LLVMCCoreTypeInt Integer Types
784 *
785 * Functions in this section operate on integer types.
786 *
787 * @{
788 */
789
790/**
791 * Obtain an integer type from a context with specified bit width.
792 */
Erick Tryzelaar262332f2009-08-14 00:01:31 +0000793LLVMTypeRef LLVMInt1TypeInContext(LLVMContextRef C);
794LLVMTypeRef LLVMInt8TypeInContext(LLVMContextRef C);
795LLVMTypeRef LLVMInt16TypeInContext(LLVMContextRef C);
796LLVMTypeRef LLVMInt32TypeInContext(LLVMContextRef C);
797LLVMTypeRef LLVMInt64TypeInContext(LLVMContextRef C);
Eugene Zelenkoffec81c2015-11-04 22:32:32 +0000798LLVMTypeRef LLVMInt128TypeInContext(LLVMContextRef C);
Erick Tryzelaar262332f2009-08-14 00:01:31 +0000799LLVMTypeRef LLVMIntTypeInContext(LLVMContextRef C, unsigned NumBits);
800
Gregory Szorc34c863a2012-03-21 03:54:29 +0000801/**
802 * Obtain an integer type from the global context with a specified bit
803 * width.
804 */
Gordon Henriksena735a9c2008-05-04 12:55:34 +0000805LLVMTypeRef LLVMInt1Type(void);
806LLVMTypeRef LLVMInt8Type(void);
807LLVMTypeRef LLVMInt16Type(void);
808LLVMTypeRef LLVMInt32Type(void);
809LLVMTypeRef LLVMInt64Type(void);
Eugene Zelenkoffec81c2015-11-04 22:32:32 +0000810LLVMTypeRef LLVMInt128Type(void);
Gordon Henriksened7beaa2007-10-06 16:05:20 +0000811LLVMTypeRef LLVMIntType(unsigned NumBits);
Gordon Henriksenc23b66c2007-09-26 20:56:12 +0000812unsigned LLVMGetIntTypeWidth(LLVMTypeRef IntegerTy);
Gordon Henriksen76a03742007-09-18 03:18:57 +0000813
Gregory Szorc34c863a2012-03-21 03:54:29 +0000814/**
815 * @}
816 */
817
818/**
819 * @defgroup LLVMCCoreTypeFloat Floating Point Types
820 *
821 * @{
822 */
823
824/**
825 * Obtain a 16-bit floating point type from a context.
826 */
Dan Gohman518cda42011-12-17 00:04:22 +0000827LLVMTypeRef LLVMHalfTypeInContext(LLVMContextRef C);
Gregory Szorc34c863a2012-03-21 03:54:29 +0000828
829/**
830 * Obtain a 32-bit floating point type from a context.
831 */
Erick Tryzelaar262332f2009-08-14 00:01:31 +0000832LLVMTypeRef LLVMFloatTypeInContext(LLVMContextRef C);
Gregory Szorc34c863a2012-03-21 03:54:29 +0000833
834/**
835 * Obtain a 64-bit floating point type from a context.
836 */
Erick Tryzelaar262332f2009-08-14 00:01:31 +0000837LLVMTypeRef LLVMDoubleTypeInContext(LLVMContextRef C);
Gregory Szorc34c863a2012-03-21 03:54:29 +0000838
839/**
840 * Obtain a 80-bit floating point type (X87) from a context.
841 */
Erick Tryzelaar262332f2009-08-14 00:01:31 +0000842LLVMTypeRef LLVMX86FP80TypeInContext(LLVMContextRef C);
Gregory Szorc34c863a2012-03-21 03:54:29 +0000843
844/**
845 * Obtain a 128-bit floating point type (112-bit mantissa) from a
846 * context.
847 */
Erick Tryzelaar262332f2009-08-14 00:01:31 +0000848LLVMTypeRef LLVMFP128TypeInContext(LLVMContextRef C);
Gregory Szorc34c863a2012-03-21 03:54:29 +0000849
850/**
851 * Obtain a 128-bit floating point type (two 64-bits) from a context.
852 */
Erick Tryzelaar262332f2009-08-14 00:01:31 +0000853LLVMTypeRef LLVMPPCFP128TypeInContext(LLVMContextRef C);
854
Gregory Szorc34c863a2012-03-21 03:54:29 +0000855/**
856 * Obtain a floating point type from the global context.
857 *
858 * These map to the functions in this group of the same name.
859 */
Dan Gohman518cda42011-12-17 00:04:22 +0000860LLVMTypeRef LLVMHalfType(void);
Gordon Henriksena735a9c2008-05-04 12:55:34 +0000861LLVMTypeRef LLVMFloatType(void);
862LLVMTypeRef LLVMDoubleType(void);
863LLVMTypeRef LLVMX86FP80Type(void);
864LLVMTypeRef LLVMFP128Type(void);
865LLVMTypeRef LLVMPPCFP128Type(void);
Gordon Henriksen76a03742007-09-18 03:18:57 +0000866
Gregory Szorc34c863a2012-03-21 03:54:29 +0000867/**
868 * @}
869 */
870
871/**
872 * @defgroup LLVMCCoreTypeFunction Function Types
873 *
874 * @{
875 */
876
877/**
878 * Obtain a function type consisting of a specified signature.
879 *
880 * The function is defined as a tuple of a return Type, a list of
881 * parameter types, and whether the function is variadic.
882 */
Gordon Henriksened7beaa2007-10-06 16:05:20 +0000883LLVMTypeRef LLVMFunctionType(LLVMTypeRef ReturnType,
884 LLVMTypeRef *ParamTypes, unsigned ParamCount,
Chris Lattner25963c62010-01-09 22:27:07 +0000885 LLVMBool IsVarArg);
Gregory Szorc34c863a2012-03-21 03:54:29 +0000886
887/**
888 * Returns whether a function type is variadic.
889 */
Chris Lattner25963c62010-01-09 22:27:07 +0000890LLVMBool LLVMIsFunctionVarArg(LLVMTypeRef FunctionTy);
Gregory Szorc34c863a2012-03-21 03:54:29 +0000891
892/**
893 * Obtain the Type this function Type returns.
894 */
Gordon Henriksenc23b66c2007-09-26 20:56:12 +0000895LLVMTypeRef LLVMGetReturnType(LLVMTypeRef FunctionTy);
Gregory Szorc34c863a2012-03-21 03:54:29 +0000896
897/**
898 * Obtain the number of parameters this function accepts.
899 */
Gordon Henriksenc23b66c2007-09-26 20:56:12 +0000900unsigned LLVMCountParamTypes(LLVMTypeRef FunctionTy);
Gregory Szorc34c863a2012-03-21 03:54:29 +0000901
902/**
903 * Obtain the types of a function's parameters.
904 *
905 * The Dest parameter should point to a pre-allocated array of
906 * LLVMTypeRef at least LLVMCountParamTypes() large. On return, the
907 * first LLVMCountParamTypes() entries in the array will be populated
908 * with LLVMTypeRef instances.
909 *
910 * @param FunctionTy The function type to operate on.
911 * @param Dest Memory address of an array to be filled with result.
912 */
Gordon Henriksenc23b66c2007-09-26 20:56:12 +0000913void LLVMGetParamTypes(LLVMTypeRef FunctionTy, LLVMTypeRef *Dest);
Gordon Henriksen76a03742007-09-18 03:18:57 +0000914
Gregory Szorc34c863a2012-03-21 03:54:29 +0000915/**
916 * @}
917 */
918
919/**
920 * @defgroup LLVMCCoreTypeStruct Structure Types
921 *
922 * These functions relate to LLVMTypeRef instances.
923 *
924 * @see llvm::StructType
925 *
926 * @{
927 */
928
929/**
930 * Create a new structure type in a context.
931 *
932 * A structure is specified by a list of inner elements/types and
933 * whether these can be packed together.
934 *
935 * @see llvm::StructType::create()
936 */
Erick Tryzelaar262332f2009-08-14 00:01:31 +0000937LLVMTypeRef LLVMStructTypeInContext(LLVMContextRef C, LLVMTypeRef *ElementTypes,
Chris Lattner25963c62010-01-09 22:27:07 +0000938 unsigned ElementCount, LLVMBool Packed);
Gregory Szorc34c863a2012-03-21 03:54:29 +0000939
940/**
941 * Create a new structure type in the global context.
942 *
943 * @see llvm::StructType::create()
944 */
Gordon Henriksened7beaa2007-10-06 16:05:20 +0000945LLVMTypeRef LLVMStructType(LLVMTypeRef *ElementTypes, unsigned ElementCount,
Chris Lattner25963c62010-01-09 22:27:07 +0000946 LLVMBool Packed);
Gregory Szorc34c863a2012-03-21 03:54:29 +0000947
948/**
949 * Create an empty structure in a context having a specified name.
950 *
951 * @see llvm::StructType::create()
952 */
Chris Lattnere71ccde2011-07-14 05:53:17 +0000953LLVMTypeRef LLVMStructCreateNamed(LLVMContextRef C, const char *Name);
Gregory Szorc34c863a2012-03-21 03:54:29 +0000954
955/**
956 * Obtain the name of a structure.
957 *
958 * @see llvm::StructType::getName()
959 */
Torok Edwin0d5f6ae2011-10-06 12:12:50 +0000960const char *LLVMGetStructName(LLVMTypeRef Ty);
Gregory Szorc34c863a2012-03-21 03:54:29 +0000961
962/**
963 * Set the contents of a structure type.
964 *
965 * @see llvm::StructType::setBody()
966 */
Chris Lattnere71ccde2011-07-14 05:53:17 +0000967void LLVMStructSetBody(LLVMTypeRef StructTy, LLVMTypeRef *ElementTypes,
968 unsigned ElementCount, LLVMBool Packed);
969
Gregory Szorc34c863a2012-03-21 03:54:29 +0000970/**
971 * Get the number of elements defined inside the structure.
972 *
973 * @see llvm::StructType::getNumElements()
974 */
Gordon Henriksenc23b66c2007-09-26 20:56:12 +0000975unsigned LLVMCountStructElementTypes(LLVMTypeRef StructTy);
Gregory Szorc34c863a2012-03-21 03:54:29 +0000976
977/**
978 * Get the elements within a structure.
979 *
980 * The function is passed the address of a pre-allocated array of
981 * LLVMTypeRef at least LLVMCountStructElementTypes() long. After
982 * invocation, this array will be populated with the structure's
983 * elements. The objects in the destination array will have a lifetime
984 * of the structure type itself, which is the lifetime of the context it
985 * is contained in.
986 */
Gordon Henriksen76a03742007-09-18 03:18:57 +0000987void LLVMGetStructElementTypes(LLVMTypeRef StructTy, LLVMTypeRef *Dest);
Gregory Szorc34c863a2012-03-21 03:54:29 +0000988
989/**
Peter Zotovc164a3f2015-06-04 09:09:53 +0000990 * Get the type of the element at a given index in the structure.
991 *
992 * @see llvm::StructType::getTypeAtIndex()
993 */
994LLVMTypeRef LLVMStructGetTypeAtIndex(LLVMTypeRef StructTy, unsigned i);
995
996/**
Gregory Szorc34c863a2012-03-21 03:54:29 +0000997 * Determine whether a structure is packed.
998 *
999 * @see llvm::StructType::isPacked()
1000 */
Chris Lattner25963c62010-01-09 22:27:07 +00001001LLVMBool LLVMIsPackedStruct(LLVMTypeRef StructTy);
Gregory Szorc34c863a2012-03-21 03:54:29 +00001002
1003/**
1004 * Determine whether a structure is opaque.
1005 *
1006 * @see llvm::StructType::isOpaque()
1007 */
Chris Lattner17cf05b2011-07-14 16:20:28 +00001008LLVMBool LLVMIsOpaqueStruct(LLVMTypeRef StructTy);
1009
Gregory Szorc34c863a2012-03-21 03:54:29 +00001010/**
1011 * @}
1012 */
Gordon Henriksen76a03742007-09-18 03:18:57 +00001013
Gregory Szorc34c863a2012-03-21 03:54:29 +00001014/**
1015 * @defgroup LLVMCCoreTypeSequential Sequential Types
1016 *
1017 * Sequential types represents "arrays" of types. This is a super class
1018 * for array, vector, and pointer types.
1019 *
1020 * @{
1021 */
1022
1023/**
1024 * Obtain the type of elements within a sequential type.
1025 *
1026 * This works on array, vector, and pointer types.
1027 *
1028 * @see llvm::SequentialType::getElementType()
1029 */
1030LLVMTypeRef LLVMGetElementType(LLVMTypeRef Ty);
1031
1032/**
1033 * Create a fixed size array type that refers to a specific type.
1034 *
1035 * The created type will exist in the context that its element type
1036 * exists in.
1037 *
1038 * @see llvm::ArrayType::get()
1039 */
Gordon Henriksened7beaa2007-10-06 16:05:20 +00001040LLVMTypeRef LLVMArrayType(LLVMTypeRef ElementType, unsigned ElementCount);
Gregory Szorc34c863a2012-03-21 03:54:29 +00001041
1042/**
1043 * Obtain the length of an array type.
1044 *
1045 * This only works on types that represent arrays.
1046 *
1047 * @see llvm::ArrayType::getNumElements()
1048 */
1049unsigned LLVMGetArrayLength(LLVMTypeRef ArrayTy);
1050
1051/**
1052 * Create a pointer type that points to a defined type.
1053 *
1054 * The created type will exist in the context that its pointee type
1055 * exists in.
1056 *
1057 * @see llvm::PointerType::get()
1058 */
Gordon Henriksen5a3fe032007-12-17 16:08:32 +00001059LLVMTypeRef LLVMPointerType(LLVMTypeRef ElementType, unsigned AddressSpace);
Gregory Szorc34c863a2012-03-21 03:54:29 +00001060
1061/**
1062 * Obtain the address space of a pointer type.
1063 *
1064 * This only works on types that represent pointers.
1065 *
1066 * @see llvm::PointerType::getAddressSpace()
1067 */
1068unsigned LLVMGetPointerAddressSpace(LLVMTypeRef PointerTy);
1069
1070/**
1071 * Create a vector type that contains a defined type and has a specific
1072 * number of elements.
1073 *
1074 * The created type will exist in the context thats its element type
1075 * exists in.
1076 *
1077 * @see llvm::VectorType::get()
1078 */
Gordon Henriksened7beaa2007-10-06 16:05:20 +00001079LLVMTypeRef LLVMVectorType(LLVMTypeRef ElementType, unsigned ElementCount);
Gordon Henriksen76a03742007-09-18 03:18:57 +00001080
Gregory Szorc34c863a2012-03-21 03:54:29 +00001081/**
1082 * Obtain the number of elements in a vector type.
1083 *
1084 * This only works on types that represent vectors.
1085 *
1086 * @see llvm::VectorType::getNumElements()
1087 */
Gordon Henriksen76a03742007-09-18 03:18:57 +00001088unsigned LLVMGetVectorSize(LLVMTypeRef VectorTy);
1089
Gregory Szorc34c863a2012-03-21 03:54:29 +00001090/**
1091 * @}
1092 */
1093
1094/**
1095 * @defgroup LLVMCCoreTypeOther Other Types
1096 *
1097 * @{
1098 */
1099
1100/**
1101 * Create a void type in a context.
1102 */
Erick Tryzelaar262332f2009-08-14 00:01:31 +00001103LLVMTypeRef LLVMVoidTypeInContext(LLVMContextRef C);
Gregory Szorc34c863a2012-03-21 03:54:29 +00001104
1105/**
1106 * Create a label type in a context.
1107 */
Erick Tryzelaar262332f2009-08-14 00:01:31 +00001108LLVMTypeRef LLVMLabelTypeInContext(LLVMContextRef C);
Gregory Szorc34c863a2012-03-21 03:54:29 +00001109
1110/**
1111 * Create a X86 MMX type in a context.
1112 */
Dale Johannesen95b67af2010-09-10 21:58:02 +00001113LLVMTypeRef LLVMX86MMXTypeInContext(LLVMContextRef C);
Erick Tryzelaar262332f2009-08-14 00:01:31 +00001114
Gregory Szorc34c863a2012-03-21 03:54:29 +00001115/**
1116 * These are similar to the above functions except they operate on the
1117 * global context.
1118 */
Gordon Henriksena735a9c2008-05-04 12:55:34 +00001119LLVMTypeRef LLVMVoidType(void);
1120LLVMTypeRef LLVMLabelType(void);
Dale Johannesen95b67af2010-09-10 21:58:02 +00001121LLVMTypeRef LLVMX86MMXType(void);
Gordon Henriksen76a03742007-09-18 03:18:57 +00001122
Gregory Szorc34c863a2012-03-21 03:54:29 +00001123/**
1124 * @}
1125 */
Gordon Henriksen76a03742007-09-18 03:18:57 +00001126
Gregory Szorc34c863a2012-03-21 03:54:29 +00001127/**
1128 * @}
1129 */
1130
1131/**
1132 * @defgroup LLVMCCoreValues Values
1133 *
1134 * The bulk of LLVM's object model consists of values, which comprise a very
Gordon Henriksen76a03742007-09-18 03:18:57 +00001135 * rich type hierarchy.
Gregory Szorc34c863a2012-03-21 03:54:29 +00001136 *
1137 * LLVMValueRef essentially represents llvm::Value. There is a rich
1138 * hierarchy of classes within this type. Depending on the instance
Eli Benderskyc52863c2012-08-10 18:30:44 +00001139 * obtained, not all APIs are available.
Gregory Szorc34c863a2012-03-21 03:54:29 +00001140 *
Daniel Dunbar06b9f9e2013-08-16 23:30:19 +00001141 * Callers can determine the type of an LLVMValueRef by calling the
Gregory Szorc34c863a2012-03-21 03:54:29 +00001142 * LLVMIsA* family of functions (e.g. LLVMIsAArgument()). These
1143 * functions are defined by a macro, so it isn't obvious which are
1144 * available by looking at the Doxygen source code. Instead, look at the
1145 * source definition of LLVM_FOR_EACH_VALUE_SUBCLASS and note the list
1146 * of value names given. These value names also correspond to classes in
1147 * the llvm::Value hierarchy.
1148 *
1149 * @{
Gordon Henriksen76a03742007-09-18 03:18:57 +00001150 */
1151
Gordon Henriksen29e38942008-12-19 18:39:45 +00001152#define LLVM_FOR_EACH_VALUE_SUBCLASS(macro) \
1153 macro(Argument) \
1154 macro(BasicBlock) \
1155 macro(InlineAsm) \
1156 macro(User) \
1157 macro(Constant) \
Torok Edwind09b7572011-10-14 20:37:56 +00001158 macro(BlockAddress) \
Gordon Henriksen29e38942008-12-19 18:39:45 +00001159 macro(ConstantAggregateZero) \
1160 macro(ConstantArray) \
Peter Zotovae0344b2013-11-05 12:55:37 +00001161 macro(ConstantDataSequential) \
1162 macro(ConstantDataArray) \
1163 macro(ConstantDataVector) \
Gordon Henriksen29e38942008-12-19 18:39:45 +00001164 macro(ConstantExpr) \
1165 macro(ConstantFP) \
1166 macro(ConstantInt) \
1167 macro(ConstantPointerNull) \
1168 macro(ConstantStruct) \
David Majnemerf0f224d2015-11-11 21:57:16 +00001169 macro(ConstantTokenNone) \
Gordon Henriksen29e38942008-12-19 18:39:45 +00001170 macro(ConstantVector) \
1171 macro(GlobalValue) \
Gordon Henriksen29e38942008-12-19 18:39:45 +00001172 macro(GlobalAlias) \
Rafael Espindola99e05cf2014-05-13 18:45:48 +00001173 macro(GlobalObject) \
1174 macro(Function) \
1175 macro(GlobalVariable) \
Gordon Henriksen29e38942008-12-19 18:39:45 +00001176 macro(UndefValue) \
1177 macro(Instruction) \
1178 macro(BinaryOperator) \
1179 macro(CallInst) \
1180 macro(IntrinsicInst) \
1181 macro(DbgInfoIntrinsic) \
1182 macro(DbgDeclareInst) \
Gordon Henriksen29e38942008-12-19 18:39:45 +00001183 macro(MemIntrinsic) \
1184 macro(MemCpyInst) \
1185 macro(MemMoveInst) \
1186 macro(MemSetInst) \
1187 macro(CmpInst) \
Torok Edwind09b7572011-10-14 20:37:56 +00001188 macro(FCmpInst) \
1189 macro(ICmpInst) \
Gordon Henriksen29e38942008-12-19 18:39:45 +00001190 macro(ExtractElementInst) \
1191 macro(GetElementPtrInst) \
1192 macro(InsertElementInst) \
1193 macro(InsertValueInst) \
Bill Wendlingfae14752011-08-12 20:24:12 +00001194 macro(LandingPadInst) \
Gordon Henriksen29e38942008-12-19 18:39:45 +00001195 macro(PHINode) \
1196 macro(SelectInst) \
1197 macro(ShuffleVectorInst) \
1198 macro(StoreInst) \
1199 macro(TerminatorInst) \
1200 macro(BranchInst) \
Torok Edwind09b7572011-10-14 20:37:56 +00001201 macro(IndirectBrInst) \
Gordon Henriksen29e38942008-12-19 18:39:45 +00001202 macro(InvokeInst) \
1203 macro(ReturnInst) \
1204 macro(SwitchInst) \
1205 macro(UnreachableInst) \
Bill Wendlingf891bf82011-07-31 06:30:59 +00001206 macro(ResumeInst) \
David Majnemer654e1302015-07-31 17:58:14 +00001207 macro(CleanupReturnInst) \
1208 macro(CatchReturnInst) \
David Majnemer8a1c45d2015-12-12 05:38:55 +00001209 macro(FuncletPadInst) \
1210 macro(CatchPadInst) \
1211 macro(CleanupPadInst) \
Duncan Sands5e37e992013-05-06 08:55:45 +00001212 macro(UnaryInstruction) \
1213 macro(AllocaInst) \
1214 macro(CastInst) \
Matt Arsenaultb03bd4d2013-11-15 01:34:59 +00001215 macro(AddrSpaceCastInst) \
Duncan Sands5e37e992013-05-06 08:55:45 +00001216 macro(BitCastInst) \
1217 macro(FPExtInst) \
1218 macro(FPToSIInst) \
1219 macro(FPToUIInst) \
1220 macro(FPTruncInst) \
1221 macro(IntToPtrInst) \
1222 macro(PtrToIntInst) \
1223 macro(SExtInst) \
1224 macro(SIToFPInst) \
1225 macro(TruncInst) \
1226 macro(UIToFPInst) \
1227 macro(ZExtInst) \
1228 macro(ExtractValueInst) \
1229 macro(LoadInst) \
1230 macro(VAArgInst)
Gordon Henriksen29e38942008-12-19 18:39:45 +00001231
Gregory Szorc34c863a2012-03-21 03:54:29 +00001232/**
1233 * @defgroup LLVMCCoreValueGeneral General APIs
1234 *
1235 * Functions in this section work on all LLVMValueRef instances,
1236 * regardless of their sub-type. They correspond to functions available
1237 * on llvm::Value.
1238 *
1239 * @{
1240 */
Gordon Henriksen76a03742007-09-18 03:18:57 +00001241
Gregory Szorc34c863a2012-03-21 03:54:29 +00001242/**
1243 * Obtain the type of a value.
1244 *
1245 * @see llvm::Value::getType()
1246 */
1247LLVMTypeRef LLVMTypeOf(LLVMValueRef Val);
1248
1249/**
Peter Zotov3e4561c2016-04-06 22:21:29 +00001250 * Obtain the enumerated type of a Value instance.
1251 *
1252 * @see llvm::Value::getValueID()
1253 */
1254LLVMValueKind LLVMGetValueKind(LLVMValueRef Val);
1255
1256/**
Gregory Szorc34c863a2012-03-21 03:54:29 +00001257 * Obtain the string name of a value.
1258 *
1259 * @see llvm::Value::getName()
1260 */
1261const char *LLVMGetValueName(LLVMValueRef Val);
1262
1263/**
1264 * Set the string name of a value.
1265 *
1266 * @see llvm::Value::setName()
1267 */
1268void LLVMSetValueName(LLVMValueRef Val, const char *Name);
1269
1270/**
1271 * Dump a representation of a value to stderr.
1272 *
1273 * @see llvm::Value::dump()
1274 */
1275void LLVMDumpValue(LLVMValueRef Val);
1276
1277/**
Peter Zotovcd93b372013-11-06 09:21:01 +00001278 * Return a string representation of the value. Use
1279 * LLVMDisposeMessage to free the string.
1280 *
1281 * @see llvm::Value::print()
1282 */
1283char *LLVMPrintValueToString(LLVMValueRef Val);
1284
1285/**
Gregory Szorc34c863a2012-03-21 03:54:29 +00001286 * Replace all uses of a value with another one.
1287 *
1288 * @see llvm::Value::replaceAllUsesWith()
1289 */
1290void LLVMReplaceAllUsesWith(LLVMValueRef OldVal, LLVMValueRef NewVal);
1291
1292/**
Amaury Sechet1c395072016-01-18 01:06:52 +00001293 * Determine whether the specified value instance is constant.
Gregory Szorc34c863a2012-03-21 03:54:29 +00001294 */
1295LLVMBool LLVMIsConstant(LLVMValueRef Val);
1296
1297/**
1298 * Determine whether a value instance is undefined.
1299 */
1300LLVMBool LLVMIsUndef(LLVMValueRef Val);
1301
1302/**
1303 * Convert value instances between types.
1304 *
Daniel Dunbar06b9f9e2013-08-16 23:30:19 +00001305 * Internally, an LLVMValueRef is "pinned" to a specific type. This
Gregory Szorc34c863a2012-03-21 03:54:29 +00001306 * series of functions allows you to cast an instance to a specific
1307 * type.
1308 *
1309 * If the cast is not valid for the specified type, NULL is returned.
1310 *
1311 * @see llvm::dyn_cast_or_null<>
1312 */
Gordon Henriksen29e38942008-12-19 18:39:45 +00001313#define LLVM_DECLARE_VALUE_CAST(name) \
1314 LLVMValueRef LLVMIsA##name(LLVMValueRef Val);
1315LLVM_FOR_EACH_VALUE_SUBCLASS(LLVM_DECLARE_VALUE_CAST)
1316
Duncan P. N. Exon Smith5bf8fef2014-12-09 18:38:53 +00001317LLVMValueRef LLVMIsAMDNode(LLVMValueRef Val);
1318LLVMValueRef LLVMIsAMDString(LLVMValueRef Val);
1319
Gregory Szorc34c863a2012-03-21 03:54:29 +00001320/**
1321 * @}
1322 */
1323
1324/**
1325 * @defgroup LLVMCCoreValueUses Usage
1326 *
1327 * This module defines functions that allow you to inspect the uses of a
1328 * LLVMValueRef.
1329 *
Daniel Dunbar06b9f9e2013-08-16 23:30:19 +00001330 * It is possible to obtain an LLVMUseRef for any LLVMValueRef instance.
Gregory Szorc34c863a2012-03-21 03:54:29 +00001331 * Each LLVMUseRef (which corresponds to a llvm::Use instance) holds a
1332 * llvm::User and llvm::Value.
1333 *
1334 * @{
1335 */
1336
1337/**
1338 * Obtain the first use of a value.
1339 *
1340 * Uses are obtained in an iterator fashion. First, call this function
1341 * to obtain a reference to the first use. Then, call LLVMGetNextUse()
Eli Benderskyc52863c2012-08-10 18:30:44 +00001342 * on that instance and all subsequently obtained instances until
Gregory Szorc34c863a2012-03-21 03:54:29 +00001343 * LLVMGetNextUse() returns NULL.
1344 *
1345 * @see llvm::Value::use_begin()
1346 */
Erick Tryzelaar9f9857e2010-03-02 20:32:28 +00001347LLVMUseRef LLVMGetFirstUse(LLVMValueRef Val);
Gregory Szorc34c863a2012-03-21 03:54:29 +00001348
1349/**
1350 * Obtain the next use of a value.
1351 *
1352 * This effectively advances the iterator. It returns NULL if you are on
1353 * the final use and no more are available.
1354 */
Erick Tryzelaar9f9857e2010-03-02 20:32:28 +00001355LLVMUseRef LLVMGetNextUse(LLVMUseRef U);
Gregory Szorc34c863a2012-03-21 03:54:29 +00001356
1357/**
1358 * Obtain the user value for a user.
1359 *
1360 * The returned value corresponds to a llvm::User type.
1361 *
1362 * @see llvm::Use::getUser()
1363 */
Erick Tryzelaar9f9857e2010-03-02 20:32:28 +00001364LLVMValueRef LLVMGetUser(LLVMUseRef U);
Gregory Szorc34c863a2012-03-21 03:54:29 +00001365
1366/**
1367 * Obtain the value this use corresponds to.
1368 *
1369 * @see llvm::Use::get().
1370 */
Erick Tryzelaar9f9857e2010-03-02 20:32:28 +00001371LLVMValueRef LLVMGetUsedValue(LLVMUseRef U);
Chris Lattner40cf28d2009-10-12 04:01:02 +00001372
Gregory Szorc34c863a2012-03-21 03:54:29 +00001373/**
1374 * @}
1375 */
1376
1377/**
Gregory Szorc52d26602012-03-21 07:28:27 +00001378 * @defgroup LLVMCCoreValueUser User value
Gregory Szorc34c863a2012-03-21 03:54:29 +00001379 *
1380 * Function in this group pertain to LLVMValueRef instances that descent
1381 * from llvm::User. This includes constants, instructions, and
1382 * operators.
1383 *
1384 * @{
1385 */
1386
1387/**
1388 * Obtain an operand at a specific index in a llvm::User value.
1389 *
1390 * @see llvm::User::getOperand()
1391 */
Chris Lattner40cf28d2009-10-12 04:01:02 +00001392LLVMValueRef LLVMGetOperand(LLVMValueRef Val, unsigned Index);
Gregory Szorc34c863a2012-03-21 03:54:29 +00001393
1394/**
Peter Zotovb19f78f2014-08-12 02:55:40 +00001395 * Obtain the use of an operand at a specific index in a llvm::User value.
1396 *
1397 * @see llvm::User::getOperandUse()
1398 */
1399LLVMUseRef LLVMGetOperandUse(LLVMValueRef Val, unsigned Index);
1400
1401/**
Gregory Szorc34c863a2012-03-21 03:54:29 +00001402 * Set an operand at a specific index in a llvm::User value.
1403 *
1404 * @see llvm::User::setOperand()
1405 */
Erick Tryzelaarb4d48702010-08-20 14:51:22 +00001406void LLVMSetOperand(LLVMValueRef User, unsigned Index, LLVMValueRef Val);
Gregory Szorc34c863a2012-03-21 03:54:29 +00001407
1408/**
1409 * Obtain the number of operands in a llvm::User value.
1410 *
1411 * @see llvm::User::getNumOperands()
1412 */
Erick Tryzelaarb4d48702010-08-20 14:51:22 +00001413int LLVMGetNumOperands(LLVMValueRef Val);
Chris Lattner40cf28d2009-10-12 04:01:02 +00001414
Gregory Szorc34c863a2012-03-21 03:54:29 +00001415/**
1416 * @}
1417 */
1418
1419/**
Gregory Szorc52d26602012-03-21 07:28:27 +00001420 * @defgroup LLVMCCoreValueConstant Constants
Gregory Szorc34c863a2012-03-21 03:54:29 +00001421 *
1422 * This section contains APIs for interacting with LLVMValueRef that
1423 * correspond to llvm::Constant instances.
1424 *
1425 * These functions will work for any LLVMValueRef in the llvm::Constant
1426 * class hierarchy.
1427 *
1428 * @{
1429 */
1430
1431/**
1432 * Obtain a constant value referring to the null instance of a type.
1433 *
1434 * @see llvm::Constant::getNullValue()
1435 */
Gordon Henriksen1046c732007-10-06 15:11:06 +00001436LLVMValueRef LLVMConstNull(LLVMTypeRef Ty); /* all zeroes */
Gregory Szorc34c863a2012-03-21 03:54:29 +00001437
1438/**
1439 * Obtain a constant value referring to the instance of a type
1440 * consisting of all ones.
1441 *
1442 * This is only valid for integer types.
1443 *
1444 * @see llvm::Constant::getAllOnesValue()
1445 */
1446LLVMValueRef LLVMConstAllOnes(LLVMTypeRef Ty);
1447
1448/**
1449 * Obtain a constant value referring to an undefined value of a type.
1450 *
1451 * @see llvm::UndefValue::get()
1452 */
Gordon Henriksen76a03742007-09-18 03:18:57 +00001453LLVMValueRef LLVMGetUndef(LLVMTypeRef Ty);
Gregory Szorc34c863a2012-03-21 03:54:29 +00001454
1455/**
1456 * Determine whether a value instance is null.
1457 *
1458 * @see llvm::Constant::isNullValue()
1459 */
Chris Lattner25963c62010-01-09 22:27:07 +00001460LLVMBool LLVMIsNull(LLVMValueRef Val);
Gregory Szorc34c863a2012-03-21 03:54:29 +00001461
1462/**
1463 * Obtain a constant that is a constant pointer pointing to NULL for a
1464 * specified type.
1465 */
Chris Lattner7f318242009-07-06 17:29:59 +00001466LLVMValueRef LLVMConstPointerNull(LLVMTypeRef Ty);
Gordon Henriksen76a03742007-09-18 03:18:57 +00001467
Gregory Szorc34c863a2012-03-21 03:54:29 +00001468/**
1469 * @defgroup LLVMCCoreValueConstantScalar Scalar constants
1470 *
1471 * Functions in this group model LLVMValueRef instances that correspond
1472 * to constants referring to scalar types.
1473 *
1474 * For integer types, the LLVMTypeRef parameter should correspond to a
1475 * llvm::IntegerType instance and the returned LLVMValueRef will
1476 * correspond to a llvm::ConstantInt.
1477 *
1478 * For floating point types, the LLVMTypeRef returned corresponds to a
1479 * llvm::ConstantFP.
1480 *
1481 * @{
1482 */
Erick Tryzelaard8531fa2010-02-28 09:45:59 +00001483
Gregory Szorc34c863a2012-03-21 03:54:29 +00001484/**
1485 * Obtain a constant value for an integer type.
1486 *
1487 * The returned value corresponds to a llvm::ConstantInt.
1488 *
1489 * @see llvm::ConstantInt::get()
1490 *
1491 * @param IntTy Integer type to obtain value of.
1492 * @param N The value the returned instance should refer to.
1493 * @param SignExtend Whether to sign extend the produced value.
1494 */
Gordon Henriksen1046c732007-10-06 15:11:06 +00001495LLVMValueRef LLVMConstInt(LLVMTypeRef IntTy, unsigned long long N,
Chris Lattner25963c62010-01-09 22:27:07 +00001496 LLVMBool SignExtend);
Gregory Szorc34c863a2012-03-21 03:54:29 +00001497
1498/**
1499 * Obtain a constant value for an integer of arbitrary precision.
1500 *
1501 * @see llvm::ConstantInt::get()
1502 */
Chris Lattner4329e072010-11-23 02:47:22 +00001503LLVMValueRef LLVMConstIntOfArbitraryPrecision(LLVMTypeRef IntTy,
1504 unsigned NumWords,
1505 const uint64_t Words[]);
Gregory Szorc34c863a2012-03-21 03:54:29 +00001506
1507/**
1508 * Obtain a constant value for an integer parsed from a string.
1509 *
1510 * A similar API, LLVMConstIntOfStringAndSize is also available. If the
1511 * string's length is available, it is preferred to call that function
1512 * instead.
1513 *
1514 * @see llvm::ConstantInt::get()
1515 */
Erick Tryzelaardd991352009-08-16 23:36:46 +00001516LLVMValueRef LLVMConstIntOfString(LLVMTypeRef IntTy, const char *Text,
1517 uint8_t Radix);
Gregory Szorc34c863a2012-03-21 03:54:29 +00001518
1519/**
1520 * Obtain a constant value for an integer parsed from a string with
1521 * specified length.
1522 *
1523 * @see llvm::ConstantInt::get()
1524 */
Erick Tryzelaardd991352009-08-16 23:36:46 +00001525LLVMValueRef LLVMConstIntOfStringAndSize(LLVMTypeRef IntTy, const char *Text,
1526 unsigned SLen, uint8_t Radix);
Gregory Szorc34c863a2012-03-21 03:54:29 +00001527
1528/**
1529 * Obtain a constant value referring to a double floating point value.
1530 */
Gordon Henriksen1046c732007-10-06 15:11:06 +00001531LLVMValueRef LLVMConstReal(LLVMTypeRef RealTy, double N);
Gregory Szorc34c863a2012-03-21 03:54:29 +00001532
1533/**
1534 * Obtain a constant for a floating point value parsed from a string.
1535 *
1536 * A similar API, LLVMConstRealOfStringAndSize is also available. It
1537 * should be used if the input string's length is known.
1538 */
Gordon Henriksen931e1212008-02-02 01:07:50 +00001539LLVMValueRef LLVMConstRealOfString(LLVMTypeRef RealTy, const char *Text);
Gregory Szorc34c863a2012-03-21 03:54:29 +00001540
1541/**
1542 * Obtain a constant for a floating point value parsed from a string.
1543 */
Erick Tryzelaardd991352009-08-16 23:36:46 +00001544LLVMValueRef LLVMConstRealOfStringAndSize(LLVMTypeRef RealTy, const char *Text,
1545 unsigned SLen);
Gregory Szorc34c863a2012-03-21 03:54:29 +00001546
1547/**
1548 * Obtain the zero extended value for an integer constant value.
1549 *
1550 * @see llvm::ConstantInt::getZExtValue()
1551 */
Chris Lattner40cf28d2009-10-12 04:01:02 +00001552unsigned long long LLVMConstIntGetZExtValue(LLVMValueRef ConstantVal);
Gregory Szorc34c863a2012-03-21 03:54:29 +00001553
1554/**
1555 * Obtain the sign extended value for an integer constant value.
1556 *
1557 * @see llvm::ConstantInt::getSExtValue()
1558 */
Chris Lattner40cf28d2009-10-12 04:01:02 +00001559long long LLVMConstIntGetSExtValue(LLVMValueRef ConstantVal);
Erick Tryzelaardd991352009-08-16 23:36:46 +00001560
Gregory Szorc34c863a2012-03-21 03:54:29 +00001561/**
Peter Zotov1d98e6d2014-10-28 19:46:44 +00001562 * Obtain the double value for an floating point constant value.
1563 * losesInfo indicates if some precision was lost in the conversion.
1564 *
1565 * @see llvm::ConstantFP::getDoubleValue
1566 */
1567double LLVMConstRealGetDouble(LLVMValueRef ConstantVal, LLVMBool *losesInfo);
1568
1569/**
Gregory Szorc34c863a2012-03-21 03:54:29 +00001570 * @}
1571 */
1572
1573/**
Gregory Szorc52d26602012-03-21 07:28:27 +00001574 * @defgroup LLVMCCoreValueConstantComposite Composite Constants
1575 *
1576 * Functions in this group operate on composite constants.
Gregory Szorc34c863a2012-03-21 03:54:29 +00001577 *
1578 * @{
1579 */
1580
1581/**
Gregory Szorc52d26602012-03-21 07:28:27 +00001582 * Create a ConstantDataSequential and initialize it with a string.
Gregory Szorc34c863a2012-03-21 03:54:29 +00001583 *
Gregory Szorc52d26602012-03-21 07:28:27 +00001584 * @see llvm::ConstantDataArray::getString()
Gregory Szorc34c863a2012-03-21 03:54:29 +00001585 */
Erick Tryzelaar262332f2009-08-14 00:01:31 +00001586LLVMValueRef LLVMConstStringInContext(LLVMContextRef C, const char *Str,
Chris Lattner25963c62010-01-09 22:27:07 +00001587 unsigned Length, LLVMBool DontNullTerminate);
Gregory Szorc52d26602012-03-21 07:28:27 +00001588
1589/**
1590 * Create a ConstantDataSequential with string content in the global context.
1591 *
1592 * This is the same as LLVMConstStringInContext except it operates on the
1593 * global context.
1594 *
1595 * @see LLVMConstStringInContext()
1596 * @see llvm::ConstantDataArray::getString()
1597 */
1598LLVMValueRef LLVMConstString(const char *Str, unsigned Length,
1599 LLVMBool DontNullTerminate);
1600
1601/**
Peter Zotovf9aa8822014-08-03 23:54:16 +00001602 * Returns true if the specified constant is an array of i8.
1603 *
1604 * @see ConstantDataSequential::getAsString()
1605 */
1606LLVMBool LLVMIsConstantString(LLVMValueRef c);
1607
1608/**
1609 * Get the given constant data sequential as a string.
1610 *
1611 * @see ConstantDataSequential::getAsString()
1612 */
Amaury Sechet7c2883c2016-04-03 21:06:04 +00001613const char *LLVMGetAsString(LLVMValueRef c, size_t *Length);
Peter Zotovf9aa8822014-08-03 23:54:16 +00001614
1615/**
Gregory Szorc52d26602012-03-21 07:28:27 +00001616 * Create an anonymous ConstantStruct with the specified values.
1617 *
1618 * @see llvm::ConstantStruct::getAnon()
1619 */
1620LLVMValueRef LLVMConstStructInContext(LLVMContextRef C,
Erick Tryzelaar262332f2009-08-14 00:01:31 +00001621 LLVMValueRef *ConstantVals,
Chris Lattner25963c62010-01-09 22:27:07 +00001622 unsigned Count, LLVMBool Packed);
Erick Tryzelaar262332f2009-08-14 00:01:31 +00001623
Gregory Szorc52d26602012-03-21 07:28:27 +00001624/**
1625 * Create a ConstantStruct in the global Context.
1626 *
1627 * This is the same as LLVMConstStructInContext except it operates on the
1628 * global Context.
1629 *
1630 * @see LLVMConstStructInContext()
1631 */
Gordon Henriksen1046c732007-10-06 15:11:06 +00001632LLVMValueRef LLVMConstStruct(LLVMValueRef *ConstantVals, unsigned Count,
Chris Lattner25963c62010-01-09 22:27:07 +00001633 LLVMBool Packed);
Gregory Szorc52d26602012-03-21 07:28:27 +00001634
1635/**
1636 * Create a ConstantArray from values.
1637 *
1638 * @see llvm::ConstantArray::get()
1639 */
1640LLVMValueRef LLVMConstArray(LLVMTypeRef ElementTy,
1641 LLVMValueRef *ConstantVals, unsigned Length);
1642
1643/**
1644 * Create a non-anonymous ConstantStruct from values.
1645 *
1646 * @see llvm::ConstantStruct::get()
1647 */
Rafael Espindola784ad242011-07-14 19:09:08 +00001648LLVMValueRef LLVMConstNamedStruct(LLVMTypeRef StructTy,
1649 LLVMValueRef *ConstantVals,
1650 unsigned Count);
Gregory Szorc52d26602012-03-21 07:28:27 +00001651
1652/**
Peter Zotovf9aa8822014-08-03 23:54:16 +00001653 * Get an element at specified index as a constant.
1654 *
1655 * @see ConstantDataSequential::getElementAsConstant()
1656 */
Amaury Sechet006ce632016-03-13 00:54:40 +00001657LLVMValueRef LLVMGetElementAsConstant(LLVMValueRef C, unsigned idx);
Peter Zotovf9aa8822014-08-03 23:54:16 +00001658
1659/**
Gregory Szorc52d26602012-03-21 07:28:27 +00001660 * Create a ConstantVector from values.
1661 *
1662 * @see llvm::ConstantVector::get()
1663 */
Gordon Henriksen1046c732007-10-06 15:11:06 +00001664LLVMValueRef LLVMConstVector(LLVMValueRef *ScalarConstantVals, unsigned Size);
Gordon Henriksen76a03742007-09-18 03:18:57 +00001665
Gregory Szorc52d26602012-03-21 07:28:27 +00001666/**
1667 * @}
1668 */
1669
1670/**
1671 * @defgroup LLVMCCoreValueConstantExpressions Constant Expressions
1672 *
1673 * Functions in this group correspond to APIs on llvm::ConstantExpr.
1674 *
1675 * @see llvm::ConstantExpr.
1676 *
1677 * @{
1678 */
Chris Lattner40cf28d2009-10-12 04:01:02 +00001679LLVMOpcode LLVMGetConstOpcode(LLVMValueRef ConstantVal);
Erick Tryzelaarfd529d72009-08-19 08:36:49 +00001680LLVMValueRef LLVMAlignOf(LLVMTypeRef Ty);
Gordon Henriksen7ce31762007-10-06 14:29:36 +00001681LLVMValueRef LLVMSizeOf(LLVMTypeRef Ty);
1682LLVMValueRef LLVMConstNeg(LLVMValueRef ConstantVal);
Erick Tryzelaar4c340c72010-02-28 05:51:43 +00001683LLVMValueRef LLVMConstNSWNeg(LLVMValueRef ConstantVal);
1684LLVMValueRef LLVMConstNUWNeg(LLVMValueRef ConstantVal);
Erick Tryzelaar4cc690c2009-08-16 02:20:12 +00001685LLVMValueRef LLVMConstFNeg(LLVMValueRef ConstantVal);
Gordon Henriksen7ce31762007-10-06 14:29:36 +00001686LLVMValueRef LLVMConstNot(LLVMValueRef ConstantVal);
1687LLVMValueRef LLVMConstAdd(LLVMValueRef LHSConstant, LLVMValueRef RHSConstant);
Dan Gohmane4ca02d2009-09-03 23:34:49 +00001688LLVMValueRef LLVMConstNSWAdd(LLVMValueRef LHSConstant, LLVMValueRef RHSConstant);
Erick Tryzelaar4c340c72010-02-28 05:51:43 +00001689LLVMValueRef LLVMConstNUWAdd(LLVMValueRef LHSConstant, LLVMValueRef RHSConstant);
Erick Tryzelaar4cc690c2009-08-16 02:20:12 +00001690LLVMValueRef LLVMConstFAdd(LLVMValueRef LHSConstant, LLVMValueRef RHSConstant);
Gordon Henriksen7ce31762007-10-06 14:29:36 +00001691LLVMValueRef LLVMConstSub(LLVMValueRef LHSConstant, LLVMValueRef RHSConstant);
Erick Tryzelaar4c340c72010-02-28 05:51:43 +00001692LLVMValueRef LLVMConstNSWSub(LLVMValueRef LHSConstant, LLVMValueRef RHSConstant);
1693LLVMValueRef LLVMConstNUWSub(LLVMValueRef LHSConstant, LLVMValueRef RHSConstant);
Erick Tryzelaar4cc690c2009-08-16 02:20:12 +00001694LLVMValueRef LLVMConstFSub(LLVMValueRef LHSConstant, LLVMValueRef RHSConstant);
Gordon Henriksen7ce31762007-10-06 14:29:36 +00001695LLVMValueRef LLVMConstMul(LLVMValueRef LHSConstant, LLVMValueRef RHSConstant);
Erick Tryzelaar4c340c72010-02-28 05:51:43 +00001696LLVMValueRef LLVMConstNSWMul(LLVMValueRef LHSConstant, LLVMValueRef RHSConstant);
1697LLVMValueRef LLVMConstNUWMul(LLVMValueRef LHSConstant, LLVMValueRef RHSConstant);
Erick Tryzelaar4cc690c2009-08-16 02:20:12 +00001698LLVMValueRef LLVMConstFMul(LLVMValueRef LHSConstant, LLVMValueRef RHSConstant);
Gordon Henriksen7ce31762007-10-06 14:29:36 +00001699LLVMValueRef LLVMConstUDiv(LLVMValueRef LHSConstant, LLVMValueRef RHSConstant);
1700LLVMValueRef LLVMConstSDiv(LLVMValueRef LHSConstant, LLVMValueRef RHSConstant);
Dan Gohmane4ca02d2009-09-03 23:34:49 +00001701LLVMValueRef LLVMConstExactSDiv(LLVMValueRef LHSConstant, LLVMValueRef RHSConstant);
Gordon Henriksen7ce31762007-10-06 14:29:36 +00001702LLVMValueRef LLVMConstFDiv(LLVMValueRef LHSConstant, LLVMValueRef RHSConstant);
1703LLVMValueRef LLVMConstURem(LLVMValueRef LHSConstant, LLVMValueRef RHSConstant);
1704LLVMValueRef LLVMConstSRem(LLVMValueRef LHSConstant, LLVMValueRef RHSConstant);
1705LLVMValueRef LLVMConstFRem(LLVMValueRef LHSConstant, LLVMValueRef RHSConstant);
1706LLVMValueRef LLVMConstAnd(LLVMValueRef LHSConstant, LLVMValueRef RHSConstant);
1707LLVMValueRef LLVMConstOr(LLVMValueRef LHSConstant, LLVMValueRef RHSConstant);
1708LLVMValueRef LLVMConstXor(LLVMValueRef LHSConstant, LLVMValueRef RHSConstant);
1709LLVMValueRef LLVMConstICmp(LLVMIntPredicate Predicate,
1710 LLVMValueRef LHSConstant, LLVMValueRef RHSConstant);
1711LLVMValueRef LLVMConstFCmp(LLVMRealPredicate Predicate,
1712 LLVMValueRef LHSConstant, LLVMValueRef RHSConstant);
1713LLVMValueRef LLVMConstShl(LLVMValueRef LHSConstant, LLVMValueRef RHSConstant);
1714LLVMValueRef LLVMConstLShr(LLVMValueRef LHSConstant, LLVMValueRef RHSConstant);
1715LLVMValueRef LLVMConstAShr(LLVMValueRef LHSConstant, LLVMValueRef RHSConstant);
1716LLVMValueRef LLVMConstGEP(LLVMValueRef ConstantVal,
1717 LLVMValueRef *ConstantIndices, unsigned NumIndices);
Dan Gohmane4ca02d2009-09-03 23:34:49 +00001718LLVMValueRef LLVMConstInBoundsGEP(LLVMValueRef ConstantVal,
1719 LLVMValueRef *ConstantIndices,
1720 unsigned NumIndices);
Gordon Henriksen7ce31762007-10-06 14:29:36 +00001721LLVMValueRef LLVMConstTrunc(LLVMValueRef ConstantVal, LLVMTypeRef ToType);
1722LLVMValueRef LLVMConstSExt(LLVMValueRef ConstantVal, LLVMTypeRef ToType);
1723LLVMValueRef LLVMConstZExt(LLVMValueRef ConstantVal, LLVMTypeRef ToType);
1724LLVMValueRef LLVMConstFPTrunc(LLVMValueRef ConstantVal, LLVMTypeRef ToType);
1725LLVMValueRef LLVMConstFPExt(LLVMValueRef ConstantVal, LLVMTypeRef ToType);
1726LLVMValueRef LLVMConstUIToFP(LLVMValueRef ConstantVal, LLVMTypeRef ToType);
1727LLVMValueRef LLVMConstSIToFP(LLVMValueRef ConstantVal, LLVMTypeRef ToType);
1728LLVMValueRef LLVMConstFPToUI(LLVMValueRef ConstantVal, LLVMTypeRef ToType);
1729LLVMValueRef LLVMConstFPToSI(LLVMValueRef ConstantVal, LLVMTypeRef ToType);
1730LLVMValueRef LLVMConstPtrToInt(LLVMValueRef ConstantVal, LLVMTypeRef ToType);
1731LLVMValueRef LLVMConstIntToPtr(LLVMValueRef ConstantVal, LLVMTypeRef ToType);
1732LLVMValueRef LLVMConstBitCast(LLVMValueRef ConstantVal, LLVMTypeRef ToType);
Matt Arsenaultb03bd4d2013-11-15 01:34:59 +00001733LLVMValueRef LLVMConstAddrSpaceCast(LLVMValueRef ConstantVal, LLVMTypeRef ToType);
Erick Tryzelaar4cc690c2009-08-16 02:20:12 +00001734LLVMValueRef LLVMConstZExtOrBitCast(LLVMValueRef ConstantVal,
1735 LLVMTypeRef ToType);
1736LLVMValueRef LLVMConstSExtOrBitCast(LLVMValueRef ConstantVal,
1737 LLVMTypeRef ToType);
1738LLVMValueRef LLVMConstTruncOrBitCast(LLVMValueRef ConstantVal,
1739 LLVMTypeRef ToType);
1740LLVMValueRef LLVMConstPointerCast(LLVMValueRef ConstantVal,
1741 LLVMTypeRef ToType);
1742LLVMValueRef LLVMConstIntCast(LLVMValueRef ConstantVal, LLVMTypeRef ToType,
Chris Lattner25963c62010-01-09 22:27:07 +00001743 LLVMBool isSigned);
Erick Tryzelaar4cc690c2009-08-16 02:20:12 +00001744LLVMValueRef LLVMConstFPCast(LLVMValueRef ConstantVal, LLVMTypeRef ToType);
Gordon Henriksen7ce31762007-10-06 14:29:36 +00001745LLVMValueRef LLVMConstSelect(LLVMValueRef ConstantCondition,
1746 LLVMValueRef ConstantIfTrue,
1747 LLVMValueRef ConstantIfFalse);
1748LLVMValueRef LLVMConstExtractElement(LLVMValueRef VectorConstant,
1749 LLVMValueRef IndexConstant);
1750LLVMValueRef LLVMConstInsertElement(LLVMValueRef VectorConstant,
1751 LLVMValueRef ElementValueConstant,
1752 LLVMValueRef IndexConstant);
1753LLVMValueRef LLVMConstShuffleVector(LLVMValueRef VectorAConstant,
1754 LLVMValueRef VectorBConstant,
1755 LLVMValueRef MaskConstant);
Dan Gohmand5104a52008-11-03 22:55:43 +00001756LLVMValueRef LLVMConstExtractValue(LLVMValueRef AggConstant, unsigned *IdxList,
1757 unsigned NumIdx);
1758LLVMValueRef LLVMConstInsertValue(LLVMValueRef AggConstant,
1759 LLVMValueRef ElementValueConstant,
1760 unsigned *IdxList, unsigned NumIdx);
Chris Lattner25963c62010-01-09 22:27:07 +00001761LLVMValueRef LLVMConstInlineAsm(LLVMTypeRef Ty,
Chris Lattner3d1f5522008-12-17 21:39:50 +00001762 const char *AsmString, const char *Constraints,
Chris Lattner25963c62010-01-09 22:27:07 +00001763 LLVMBool HasSideEffects, LLVMBool IsAlignStack);
Erick Tryzelaar0fb26ef2010-02-28 09:46:06 +00001764LLVMValueRef LLVMBlockAddress(LLVMValueRef F, LLVMBasicBlockRef BB);
Gordon Henriksen7ce31762007-10-06 14:29:36 +00001765
Gregory Szorc52d26602012-03-21 07:28:27 +00001766/**
1767 * @}
1768 */
1769
1770/**
1771 * @defgroup LLVMCCoreValueConstantGlobals Global Values
1772 *
1773 * This group contains functions that operate on global values. Functions in
1774 * this group relate to functions in the llvm::GlobalValue class tree.
1775 *
1776 * @see llvm::GlobalValue
1777 *
1778 * @{
1779 */
1780
Gordon Henriksen265f7802008-03-19 01:11:35 +00001781LLVMModuleRef LLVMGetGlobalParent(LLVMValueRef Global);
Chris Lattner25963c62010-01-09 22:27:07 +00001782LLVMBool LLVMIsDeclaration(LLVMValueRef Global);
Gordon Henriksen76a03742007-09-18 03:18:57 +00001783LLVMLinkage LLVMGetLinkage(LLVMValueRef Global);
1784void LLVMSetLinkage(LLVMValueRef Global, LLVMLinkage Linkage);
1785const char *LLVMGetSection(LLVMValueRef Global);
1786void LLVMSetSection(LLVMValueRef Global, const char *Section);
1787LLVMVisibility LLVMGetVisibility(LLVMValueRef Global);
1788void LLVMSetVisibility(LLVMValueRef Global, LLVMVisibility Viz);
Reid Kleckner2fae26f2014-03-05 02:34:23 +00001789LLVMDLLStorageClass LLVMGetDLLStorageClass(LLVMValueRef Global);
1790void LLVMSetDLLStorageClass(LLVMValueRef Global, LLVMDLLStorageClass Class);
Tim Northoverad96d012014-03-10 19:24:35 +00001791LLVMBool LLVMHasUnnamedAddr(LLVMValueRef Global);
1792void LLVMSetUnnamedAddr(LLVMValueRef Global, LLVMBool HasUnnamedAddr);
Anders Waldenborg213a63f2013-10-29 09:02:02 +00001793
1794/**
1795 * @defgroup LLVMCCoreValueWithAlignment Values with alignment
1796 *
1797 * Functions in this group only apply to values with alignment, i.e.
1798 * global variables, load and store instructions.
1799 */
1800
1801/**
1802 * Obtain the preferred alignment of the value.
Peter Zotov9f584e62014-03-05 05:05:34 +00001803 * @see llvm::AllocaInst::getAlignment()
Anders Waldenborg213a63f2013-10-29 09:02:02 +00001804 * @see llvm::LoadInst::getAlignment()
1805 * @see llvm::StoreInst::getAlignment()
1806 * @see llvm::GlobalValue::getAlignment()
1807 */
1808unsigned LLVMGetAlignment(LLVMValueRef V);
1809
1810/**
1811 * Set the preferred alignment of the value.
Peter Zotov9f584e62014-03-05 05:05:34 +00001812 * @see llvm::AllocaInst::setAlignment()
Anders Waldenborg213a63f2013-10-29 09:02:02 +00001813 * @see llvm::LoadInst::setAlignment()
1814 * @see llvm::StoreInst::setAlignment()
1815 * @see llvm::GlobalValue::setAlignment()
1816 */
1817void LLVMSetAlignment(LLVMValueRef V, unsigned Bytes);
1818
1819/**
Amaury Sechet83550102016-02-14 08:58:49 +00001820 * @}
1821 */
Gordon Henriksen76a03742007-09-18 03:18:57 +00001822
Gregory Szorc52d26602012-03-21 07:28:27 +00001823/**
1824 * @defgroup LLVMCoreValueConstantGlobalVariable Global Variables
1825 *
1826 * This group contains functions that operate on global variable values.
1827 *
1828 * @see llvm::GlobalVariable
1829 *
1830 * @{
1831 */
Gordon Henriksen76a03742007-09-18 03:18:57 +00001832LLVMValueRef LLVMAddGlobal(LLVMModuleRef M, LLVMTypeRef Ty, const char *Name);
Erick Tryzelaar06894b32010-02-28 09:46:13 +00001833LLVMValueRef LLVMAddGlobalInAddressSpace(LLVMModuleRef M, LLVMTypeRef Ty,
1834 const char *Name,
1835 unsigned AddressSpace);
Gordon Henriksen783f7bb2007-10-08 03:45:09 +00001836LLVMValueRef LLVMGetNamedGlobal(LLVMModuleRef M, const char *Name);
Gordon Henriksen07a45f42008-03-23 22:21:29 +00001837LLVMValueRef LLVMGetFirstGlobal(LLVMModuleRef M);
1838LLVMValueRef LLVMGetLastGlobal(LLVMModuleRef M);
1839LLVMValueRef LLVMGetNextGlobal(LLVMValueRef GlobalVar);
1840LLVMValueRef LLVMGetPreviousGlobal(LLVMValueRef GlobalVar);
Gordon Henriksen76a03742007-09-18 03:18:57 +00001841void LLVMDeleteGlobal(LLVMValueRef GlobalVar);
Gordon Henriksen76a03742007-09-18 03:18:57 +00001842LLVMValueRef LLVMGetInitializer(LLVMValueRef GlobalVar);
1843void LLVMSetInitializer(LLVMValueRef GlobalVar, LLVMValueRef ConstantVal);
Chris Lattner25963c62010-01-09 22:27:07 +00001844LLVMBool LLVMIsThreadLocal(LLVMValueRef GlobalVar);
1845void LLVMSetThreadLocal(LLVMValueRef GlobalVar, LLVMBool IsThreadLocal);
1846LLVMBool LLVMIsGlobalConstant(LLVMValueRef GlobalVar);
1847void LLVMSetGlobalConstant(LLVMValueRef GlobalVar, LLVMBool IsConstant);
Hans Wennborg5ff71202013-04-16 08:58:59 +00001848LLVMThreadLocalMode LLVMGetThreadLocalMode(LLVMValueRef GlobalVar);
1849void LLVMSetThreadLocalMode(LLVMValueRef GlobalVar, LLVMThreadLocalMode Mode);
1850LLVMBool LLVMIsExternallyInitialized(LLVMValueRef GlobalVar);
1851void LLVMSetExternallyInitialized(LLVMValueRef GlobalVar, LLVMBool IsExtInit);
Gordon Henriksen76a03742007-09-18 03:18:57 +00001852
Gregory Szorc52d26602012-03-21 07:28:27 +00001853/**
1854 * @}
1855 */
1856
1857/**
1858 * @defgroup LLVMCoreValueConstantGlobalAlias Global Aliases
1859 *
1860 * This group contains function that operate on global alias values.
1861 *
1862 * @see llvm::GlobalAlias
1863 *
1864 * @{
1865 */
Chris Lattner3d1f5522008-12-17 21:39:50 +00001866LLVMValueRef LLVMAddAlias(LLVMModuleRef M, LLVMTypeRef Ty, LLVMValueRef Aliasee,
1867 const char *Name);
1868
Gregory Szorc34c863a2012-03-21 03:54:29 +00001869/**
1870 * @}
1871 */
1872
1873/**
1874 * @defgroup LLVMCCoreValueFunction Function values
1875 *
1876 * Functions in this group operate on LLVMValueRef instances that
1877 * correspond to llvm::Function instances.
1878 *
1879 * @see llvm::Function
1880 *
1881 * @{
1882 */
1883
1884/**
1885 * Remove a function from its containing module and deletes it.
1886 *
1887 * @see llvm::Function::eraseFromParent()
1888 */
Gordon Henriksenc23b66c2007-09-26 20:56:12 +00001889void LLVMDeleteFunction(LLVMValueRef Fn);
Gregory Szorc34c863a2012-03-21 03:54:29 +00001890
1891/**
Amaury Sechete39e8532016-02-18 20:38:32 +00001892 * Check whether the given function has a personality function.
1893 *
1894 * @see llvm::Function::hasPersonalityFn()
1895 */
1896LLVMBool LLVMHasPersonalityFn(LLVMValueRef Fn);
1897
1898/**
Andrew Wilkins3bdfc1c2015-07-14 01:23:06 +00001899 * Obtain the personality function attached to the function.
1900 *
1901 * @see llvm::Function::getPersonalityFn()
1902 */
1903LLVMValueRef LLVMGetPersonalityFn(LLVMValueRef Fn);
1904
1905/**
1906 * Set the personality function attached to the function.
1907 *
1908 * @see llvm::Function::setPersonalityFn()
1909 */
1910void LLVMSetPersonalityFn(LLVMValueRef Fn, LLVMValueRef PersonalityFn);
1911
1912/**
Gregory Szorc34c863a2012-03-21 03:54:29 +00001913 * Obtain the ID number from a function instance.
1914 *
1915 * @see llvm::Function::getIntrinsicID()
1916 */
Gordon Henriksenc23b66c2007-09-26 20:56:12 +00001917unsigned LLVMGetIntrinsicID(LLVMValueRef Fn);
Gregory Szorc34c863a2012-03-21 03:54:29 +00001918
1919/**
1920 * Obtain the calling function of a function.
1921 *
1922 * The returned value corresponds to the LLVMCallConv enumeration.
1923 *
1924 * @see llvm::Function::getCallingConv()
1925 */
Gordon Henriksenc23b66c2007-09-26 20:56:12 +00001926unsigned LLVMGetFunctionCallConv(LLVMValueRef Fn);
Gregory Szorc34c863a2012-03-21 03:54:29 +00001927
1928/**
1929 * Set the calling convention of a function.
1930 *
1931 * @see llvm::Function::setCallingConv()
1932 *
1933 * @param Fn Function to operate on
1934 * @param CC LLVMCallConv to set calling convention to
1935 */
Gordon Henriksenc23b66c2007-09-26 20:56:12 +00001936void LLVMSetFunctionCallConv(LLVMValueRef Fn, unsigned CC);
Gregory Szorc34c863a2012-03-21 03:54:29 +00001937
1938/**
1939 * Obtain the name of the garbage collector to use during code
1940 * generation.
1941 *
1942 * @see llvm::Function::getGC()
1943 */
Gordon Henriksend930f912008-08-17 18:44:35 +00001944const char *LLVMGetGC(LLVMValueRef Fn);
Gregory Szorc34c863a2012-03-21 03:54:29 +00001945
1946/**
1947 * Define the garbage collector to use during code generation.
1948 *
1949 * @see llvm::Function::setGC()
1950 */
Gordon Henriksend930f912008-08-17 18:44:35 +00001951void LLVMSetGC(LLVMValueRef Fn, const char *Name);
Gregory Szorc34c863a2012-03-21 03:54:29 +00001952
1953/**
1954 * Add an attribute to a function.
1955 *
1956 * @see llvm::Function::addAttribute()
1957 */
Duncan Sands7374a012009-05-06 12:21:17 +00001958void LLVMAddFunctionAttr(LLVMValueRef Fn, LLVMAttribute PA);
Gregory Szorc34c863a2012-03-21 03:54:29 +00001959
1960/**
Nick Lewyckyc3890d22015-07-29 22:32:47 +00001961 * Add a target-dependent attribute to a function
Tom Stellarde8f35e12013-04-16 23:12:43 +00001962 * @see llvm::AttrBuilder::addAttribute()
1963 */
1964void LLVMAddTargetDependentFunctionAttr(LLVMValueRef Fn, const char *A,
1965 const char *V);
1966
1967/**
Gregory Szorc34c863a2012-03-21 03:54:29 +00001968 * Obtain an attribute from a function.
1969 *
1970 * @see llvm::Function::getAttributes()
1971 */
Chris Lattner40cf28d2009-10-12 04:01:02 +00001972LLVMAttribute LLVMGetFunctionAttr(LLVMValueRef Fn);
Gregory Szorc34c863a2012-03-21 03:54:29 +00001973
1974/**
1975 * Remove an attribute from a function.
1976 */
Duncan Sands7374a012009-05-06 12:21:17 +00001977void LLVMRemoveFunctionAttr(LLVMValueRef Fn, LLVMAttribute PA);
Gordon Henriksenc23b66c2007-09-26 20:56:12 +00001978
Gregory Szorc34c863a2012-03-21 03:54:29 +00001979/**
1980 * @defgroup LLVMCCoreValueFunctionParameters Function Parameters
1981 *
1982 * Functions in this group relate to arguments/parameters on functions.
1983 *
1984 * Functions in this group expect LLVMValueRef instances that correspond
1985 * to llvm::Function instances.
1986 *
1987 * @{
1988 */
1989
1990/**
1991 * Obtain the number of parameters in a function.
1992 *
1993 * @see llvm::Function::arg_size()
1994 */
Gordon Henriksen265f7802008-03-19 01:11:35 +00001995unsigned LLVMCountParams(LLVMValueRef Fn);
Gregory Szorc34c863a2012-03-21 03:54:29 +00001996
1997/**
1998 * Obtain the parameters in a function.
1999 *
2000 * The takes a pointer to a pre-allocated array of LLVMValueRef that is
2001 * at least LLVMCountParams() long. This array will be filled with
2002 * LLVMValueRef instances which correspond to the parameters the
2003 * function receives. Each LLVMValueRef corresponds to a llvm::Argument
2004 * instance.
2005 *
2006 * @see llvm::Function::arg_begin()
2007 */
Gordon Henriksen265f7802008-03-19 01:11:35 +00002008void LLVMGetParams(LLVMValueRef Fn, LLVMValueRef *Params);
Gregory Szorc34c863a2012-03-21 03:54:29 +00002009
2010/**
2011 * Obtain the parameter at the specified index.
2012 *
2013 * Parameters are indexed from 0.
2014 *
2015 * @see llvm::Function::arg_begin()
2016 */
Gordon Henriksen265f7802008-03-19 01:11:35 +00002017LLVMValueRef LLVMGetParam(LLVMValueRef Fn, unsigned Index);
Gregory Szorc34c863a2012-03-21 03:54:29 +00002018
2019/**
2020 * Obtain the function to which this argument belongs.
2021 *
Daniel Dunbar06b9f9e2013-08-16 23:30:19 +00002022 * Unlike other functions in this group, this one takes an LLVMValueRef
Gregory Szorc34c863a2012-03-21 03:54:29 +00002023 * that corresponds to a llvm::Attribute.
2024 *
2025 * The returned LLVMValueRef is the llvm::Function to which this
2026 * argument belongs.
2027 */
Gordon Henriksen265f7802008-03-19 01:11:35 +00002028LLVMValueRef LLVMGetParamParent(LLVMValueRef Inst);
Gregory Szorc34c863a2012-03-21 03:54:29 +00002029
2030/**
2031 * Obtain the first parameter to a function.
2032 *
2033 * @see llvm::Function::arg_begin()
2034 */
Gordon Henriksen07a45f42008-03-23 22:21:29 +00002035LLVMValueRef LLVMGetFirstParam(LLVMValueRef Fn);
Gregory Szorc34c863a2012-03-21 03:54:29 +00002036
2037/**
2038 * Obtain the last parameter to a function.
2039 *
2040 * @see llvm::Function::arg_end()
2041 */
Gordon Henriksen07a45f42008-03-23 22:21:29 +00002042LLVMValueRef LLVMGetLastParam(LLVMValueRef Fn);
Gregory Szorc34c863a2012-03-21 03:54:29 +00002043
2044/**
2045 * Obtain the next parameter to a function.
2046 *
Daniel Dunbar06b9f9e2013-08-16 23:30:19 +00002047 * This takes an LLVMValueRef obtained from LLVMGetFirstParam() (which is
Gregory Szorc34c863a2012-03-21 03:54:29 +00002048 * actually a wrapped iterator) and obtains the next parameter from the
2049 * underlying iterator.
2050 */
Gordon Henriksen07a45f42008-03-23 22:21:29 +00002051LLVMValueRef LLVMGetNextParam(LLVMValueRef Arg);
Gregory Szorc34c863a2012-03-21 03:54:29 +00002052
2053/**
2054 * Obtain the previous parameter to a function.
2055 *
2056 * This is the opposite of LLVMGetNextParam().
2057 */
Gordon Henriksen07a45f42008-03-23 22:21:29 +00002058LLVMValueRef LLVMGetPreviousParam(LLVMValueRef Arg);
Gregory Szorc34c863a2012-03-21 03:54:29 +00002059
2060/**
2061 * Add an attribute to a function argument.
2062 *
2063 * @see llvm::Argument::addAttr()
2064 */
Devang Patel4c758ea2008-09-25 21:00:45 +00002065void LLVMAddAttribute(LLVMValueRef Arg, LLVMAttribute PA);
Gregory Szorc34c863a2012-03-21 03:54:29 +00002066
2067/**
2068 * Remove an attribute from a function argument.
2069 *
2070 * @see llvm::Argument::removeAttr()
2071 */
Devang Patel4c758ea2008-09-25 21:00:45 +00002072void LLVMRemoveAttribute(LLVMValueRef Arg, LLVMAttribute PA);
Gregory Szorc34c863a2012-03-21 03:54:29 +00002073
2074/**
2075 * Get an attribute from a function argument.
2076 */
Chris Lattner40cf28d2009-10-12 04:01:02 +00002077LLVMAttribute LLVMGetAttribute(LLVMValueRef Arg);
Gregory Szorc34c863a2012-03-21 03:54:29 +00002078
2079/**
2080 * Set the alignment for a function parameter.
2081 *
2082 * @see llvm::Argument::addAttr()
Bill Wendling50d27842012-10-15 20:35:56 +00002083 * @see llvm::AttrBuilder::addAlignmentAttr()
Gregory Szorc34c863a2012-03-21 03:54:29 +00002084 */
Amaury Sechet81243a72016-05-01 01:42:34 +00002085void LLVMSetParamAlignment(LLVMValueRef Arg, unsigned Align);
Gordon Henriksen265f7802008-03-19 01:11:35 +00002086
Gregory Szorc34c863a2012-03-21 03:54:29 +00002087/**
2088 * @}
2089 */
2090
2091/**
2092 * @}
2093 */
2094
2095/**
Gregory Szorc52d26602012-03-21 07:28:27 +00002096 * @}
2097 */
2098
2099/**
2100 * @}
2101 */
2102
2103/**
2104 * @defgroup LLVMCCoreValueMetadata Metadata
2105 *
2106 * @{
2107 */
2108
2109/**
2110 * Obtain a MDString value from a context.
2111 *
2112 * The returned instance corresponds to the llvm::MDString class.
2113 *
2114 * The instance is specified by string data of a specified length. The
2115 * string content is copied, so the backing memory can be freed after
2116 * this function returns.
2117 */
2118LLVMValueRef LLVMMDStringInContext(LLVMContextRef C, const char *Str,
2119 unsigned SLen);
2120
2121/**
2122 * Obtain a MDString value from the global context.
2123 */
2124LLVMValueRef LLVMMDString(const char *Str, unsigned SLen);
2125
2126/**
2127 * Obtain a MDNode value from a context.
2128 *
2129 * The returned value corresponds to the llvm::MDNode class.
2130 */
2131LLVMValueRef LLVMMDNodeInContext(LLVMContextRef C, LLVMValueRef *Vals,
2132 unsigned Count);
2133
2134/**
2135 * Obtain a MDNode value from the global context.
2136 */
2137LLVMValueRef LLVMMDNode(LLVMValueRef *Vals, unsigned Count);
2138
2139/**
2140 * Obtain the underlying string from a MDString value.
2141 *
2142 * @param V Instance to obtain string from.
NAKAMURA Takumie4a77052016-04-04 11:54:48 +00002143 * @param Length Memory address which will hold length of returned string.
Gregory Szorc52d26602012-03-21 07:28:27 +00002144 * @return String data in MDString.
2145 */
Amaury Sechet7c2883c2016-04-03 21:06:04 +00002146const char *LLVMGetMDString(LLVMValueRef V, unsigned *Length);
Gregory Szorc52d26602012-03-21 07:28:27 +00002147
2148/**
Duncan Sands12ccbe72012-09-19 20:29:39 +00002149 * Obtain the number of operands from an MDNode value.
2150 *
2151 * @param V MDNode to get number of operands from.
2152 * @return Number of operands of the MDNode.
2153 */
2154unsigned LLVMGetMDNodeNumOperands(LLVMValueRef V);
2155
2156/**
2157 * Obtain the given MDNode's operands.
2158 *
2159 * The passed LLVMValueRef pointer should point to enough memory to hold all of
2160 * the operands of the given MDNode (see LLVMGetMDNodeNumOperands) as
2161 * LLVMValueRefs. This memory will be populated with the LLVMValueRefs of the
2162 * MDNode's operands.
2163 *
2164 * @param V MDNode to get the operands from.
2165 * @param Dest Destination array for operands.
2166 */
2167void LLVMGetMDNodeOperands(LLVMValueRef V, LLVMValueRef *Dest);
2168
2169/**
Gregory Szorc52d26602012-03-21 07:28:27 +00002170 * @}
2171 */
2172
2173/**
Gregory Szorc34c863a2012-03-21 03:54:29 +00002174 * @defgroup LLVMCCoreValueBasicBlock Basic Block
2175 *
2176 * A basic block represents a single entry single exit section of code.
2177 * Basic blocks contain a list of instructions which form the body of
2178 * the block.
2179 *
2180 * Basic blocks belong to functions. They have the type of label.
2181 *
2182 * Basic blocks are themselves values. However, the C API models them as
2183 * LLVMBasicBlockRef.
2184 *
2185 * @see llvm::BasicBlock
2186 *
2187 * @{
2188 */
2189
2190/**
2191 * Convert a basic block instance to a value type.
2192 */
Gordon Henriksen07a45f42008-03-23 22:21:29 +00002193LLVMValueRef LLVMBasicBlockAsValue(LLVMBasicBlockRef BB);
Gregory Szorc34c863a2012-03-21 03:54:29 +00002194
2195/**
Daniel Dunbar06b9f9e2013-08-16 23:30:19 +00002196 * Determine whether an LLVMValueRef is itself a basic block.
Gregory Szorc34c863a2012-03-21 03:54:29 +00002197 */
Chris Lattner25963c62010-01-09 22:27:07 +00002198LLVMBool LLVMValueIsBasicBlock(LLVMValueRef Val);
Gregory Szorc34c863a2012-03-21 03:54:29 +00002199
2200/**
Daniel Dunbar06b9f9e2013-08-16 23:30:19 +00002201 * Convert an LLVMValueRef to an LLVMBasicBlockRef instance.
Gregory Szorc34c863a2012-03-21 03:54:29 +00002202 */
Gordon Henriksenc23b66c2007-09-26 20:56:12 +00002203LLVMBasicBlockRef LLVMValueAsBasicBlock(LLVMValueRef Val);
Gregory Szorc34c863a2012-03-21 03:54:29 +00002204
2205/**
Amaury Secheta82042e2016-02-09 22:36:41 +00002206 * Obtain the string name of a basic block.
2207 */
2208const char *LLVMGetBasicBlockName(LLVMBasicBlockRef BB);
2209
2210/**
Gregory Szorc34c863a2012-03-21 03:54:29 +00002211 * Obtain the function to which a basic block belongs.
2212 *
2213 * @see llvm::BasicBlock::getParent()
2214 */
Gordon Henriksen07a45f42008-03-23 22:21:29 +00002215LLVMValueRef LLVMGetBasicBlockParent(LLVMBasicBlockRef BB);
Gregory Szorc34c863a2012-03-21 03:54:29 +00002216
2217/**
2218 * Obtain the terminator instruction for a basic block.
2219 *
2220 * If the basic block does not have a terminator (it is not well-formed
2221 * if it doesn't), then NULL is returned.
2222 *
2223 * The returned LLVMValueRef corresponds to a llvm::TerminatorInst.
2224 *
2225 * @see llvm::BasicBlock::getTerminator()
2226 */
Nate Begeman43c322b2011-08-23 20:27:46 +00002227LLVMValueRef LLVMGetBasicBlockTerminator(LLVMBasicBlockRef BB);
Gregory Szorc34c863a2012-03-21 03:54:29 +00002228
2229/**
2230 * Obtain the number of basic blocks in a function.
2231 *
2232 * @param Fn Function value to operate on.
2233 */
Gordon Henriksenc23b66c2007-09-26 20:56:12 +00002234unsigned LLVMCountBasicBlocks(LLVMValueRef Fn);
Gregory Szorc34c863a2012-03-21 03:54:29 +00002235
2236/**
2237 * Obtain all of the basic blocks in a function.
2238 *
2239 * This operates on a function value. The BasicBlocks parameter is a
2240 * pointer to a pre-allocated array of LLVMBasicBlockRef of at least
2241 * LLVMCountBasicBlocks() in length. This array is populated with
2242 * LLVMBasicBlockRef instances.
2243 */
Gordon Henriksenc23b66c2007-09-26 20:56:12 +00002244void LLVMGetBasicBlocks(LLVMValueRef Fn, LLVMBasicBlockRef *BasicBlocks);
Gregory Szorc34c863a2012-03-21 03:54:29 +00002245
2246/**
2247 * Obtain the first basic block in a function.
2248 *
2249 * The returned basic block can be used as an iterator. You will likely
2250 * eventually call into LLVMGetNextBasicBlock() with it.
2251 *
2252 * @see llvm::Function::begin()
2253 */
Gordon Henriksen054817c2008-03-19 03:47:18 +00002254LLVMBasicBlockRef LLVMGetFirstBasicBlock(LLVMValueRef Fn);
Gregory Szorc34c863a2012-03-21 03:54:29 +00002255
2256/**
2257 * Obtain the last basic block in a function.
2258 *
2259 * @see llvm::Function::end()
2260 */
Gordon Henriksen054817c2008-03-19 03:47:18 +00002261LLVMBasicBlockRef LLVMGetLastBasicBlock(LLVMValueRef Fn);
Gregory Szorc34c863a2012-03-21 03:54:29 +00002262
2263/**
2264 * Advance a basic block iterator.
2265 */
Gordon Henriksen054817c2008-03-19 03:47:18 +00002266LLVMBasicBlockRef LLVMGetNextBasicBlock(LLVMBasicBlockRef BB);
Gregory Szorc34c863a2012-03-21 03:54:29 +00002267
2268/**
2269 * Go backwards in a basic block iterator.
2270 */
Gordon Henriksen054817c2008-03-19 03:47:18 +00002271LLVMBasicBlockRef LLVMGetPreviousBasicBlock(LLVMBasicBlockRef BB);
Gregory Szorc34c863a2012-03-21 03:54:29 +00002272
2273/**
2274 * Obtain the basic block that corresponds to the entry point of a
2275 * function.
2276 *
2277 * @see llvm::Function::getEntryBlock()
2278 */
Gordon Henriksenc23b66c2007-09-26 20:56:12 +00002279LLVMBasicBlockRef LLVMGetEntryBasicBlock(LLVMValueRef Fn);
Erick Tryzelaar262332f2009-08-14 00:01:31 +00002280
Gregory Szorc34c863a2012-03-21 03:54:29 +00002281/**
2282 * Append a basic block to the end of a function.
2283 *
2284 * @see llvm::BasicBlock::Create()
2285 */
Erick Tryzelaar262332f2009-08-14 00:01:31 +00002286LLVMBasicBlockRef LLVMAppendBasicBlockInContext(LLVMContextRef C,
2287 LLVMValueRef Fn,
2288 const char *Name);
Gregory Szorc34c863a2012-03-21 03:54:29 +00002289
2290/**
2291 * Append a basic block to the end of a function using the global
2292 * context.
2293 *
2294 * @see llvm::BasicBlock::Create()
2295 */
2296LLVMBasicBlockRef LLVMAppendBasicBlock(LLVMValueRef Fn, const char *Name);
2297
2298/**
2299 * Insert a basic block in a function before another basic block.
2300 *
2301 * The function to add to is determined by the function of the
2302 * passed basic block.
2303 *
2304 * @see llvm::BasicBlock::Create()
2305 */
Erick Tryzelaar262332f2009-08-14 00:01:31 +00002306LLVMBasicBlockRef LLVMInsertBasicBlockInContext(LLVMContextRef C,
2307 LLVMBasicBlockRef BB,
2308 const char *Name);
2309
Gregory Szorc34c863a2012-03-21 03:54:29 +00002310/**
2311 * Insert a basic block in a function using the global context.
2312 *
2313 * @see llvm::BasicBlock::Create()
2314 */
Gordon Henriksenc23b66c2007-09-26 20:56:12 +00002315LLVMBasicBlockRef LLVMInsertBasicBlock(LLVMBasicBlockRef InsertBeforeBB,
2316 const char *Name);
Gregory Szorc34c863a2012-03-21 03:54:29 +00002317
2318/**
2319 * Remove a basic block from a function and delete it.
2320 *
2321 * This deletes the basic block from its containing function and deletes
2322 * the basic block itself.
2323 *
2324 * @see llvm::BasicBlock::eraseFromParent()
2325 */
Gordon Henriksenc23b66c2007-09-26 20:56:12 +00002326void LLVMDeleteBasicBlock(LLVMBasicBlockRef BB);
Gregory Szorc34c863a2012-03-21 03:54:29 +00002327
2328/**
2329 * Remove a basic block from a function.
2330 *
2331 * This deletes the basic block from its containing function but keep
2332 * the basic block alive.
2333 *
2334 * @see llvm::BasicBlock::removeFromParent()
2335 */
Nate Begeman43c322b2011-08-23 20:27:46 +00002336void LLVMRemoveBasicBlockFromParent(LLVMBasicBlockRef BB);
Gordon Henriksenc23b66c2007-09-26 20:56:12 +00002337
Gregory Szorc34c863a2012-03-21 03:54:29 +00002338/**
2339 * Move a basic block to before another one.
2340 *
2341 * @see llvm::BasicBlock::moveBefore()
2342 */
Duncan Sandsb1d61aa2010-07-19 15:31:07 +00002343void LLVMMoveBasicBlockBefore(LLVMBasicBlockRef BB, LLVMBasicBlockRef MovePos);
Gregory Szorc34c863a2012-03-21 03:54:29 +00002344
2345/**
2346 * Move a basic block to after another one.
2347 *
2348 * @see llvm::BasicBlock::moveAfter()
2349 */
Duncan Sandsb1d61aa2010-07-19 15:31:07 +00002350void LLVMMoveBasicBlockAfter(LLVMBasicBlockRef BB, LLVMBasicBlockRef MovePos);
2351
Gregory Szorc34c863a2012-03-21 03:54:29 +00002352/**
2353 * Obtain the first instruction in a basic block.
2354 *
2355 * The returned LLVMValueRef corresponds to a llvm::Instruction
2356 * instance.
2357 */
Gordon Henriksen054817c2008-03-19 03:47:18 +00002358LLVMValueRef LLVMGetFirstInstruction(LLVMBasicBlockRef BB);
Gregory Szorc34c863a2012-03-21 03:54:29 +00002359
2360/**
2361 * Obtain the last instruction in a basic block.
2362 *
Daniel Dunbar06b9f9e2013-08-16 23:30:19 +00002363 * The returned LLVMValueRef corresponds to an LLVM:Instruction.
Gregory Szorc34c863a2012-03-21 03:54:29 +00002364 */
Gordon Henriksen054817c2008-03-19 03:47:18 +00002365LLVMValueRef LLVMGetLastInstruction(LLVMBasicBlockRef BB);
Nate Begeman43c322b2011-08-23 20:27:46 +00002366
Gregory Szorc34c863a2012-03-21 03:54:29 +00002367/**
2368 * @}
2369 */
2370
2371/**
2372 * @defgroup LLVMCCoreValueInstruction Instructions
2373 *
2374 * Functions in this group relate to the inspection and manipulation of
2375 * individual instructions.
2376 *
2377 * In the C++ API, an instruction is modeled by llvm::Instruction. This
2378 * class has a large number of descendents. llvm::Instruction is a
2379 * llvm::Value and in the C API, instructions are modeled by
2380 * LLVMValueRef.
2381 *
2382 * This group also contains sub-groups which operate on specific
2383 * llvm::Instruction types, e.g. llvm::CallInst.
2384 *
2385 * @{
2386 */
2387
2388/**
2389 * Determine whether an instruction has any metadata attached.
2390 */
2391int LLVMHasMetadata(LLVMValueRef Val);
2392
2393/**
2394 * Return metadata associated with an instruction value.
2395 */
2396LLVMValueRef LLVMGetMetadata(LLVMValueRef Val, unsigned KindID);
2397
2398/**
2399 * Set metadata associated with an instruction value.
2400 */
2401void LLVMSetMetadata(LLVMValueRef Val, unsigned KindID, LLVMValueRef Node);
2402
2403/**
2404 * Obtain the basic block to which an instruction belongs.
2405 *
2406 * @see llvm::Instruction::getParent()
2407 */
Nate Begeman43c322b2011-08-23 20:27:46 +00002408LLVMBasicBlockRef LLVMGetInstructionParent(LLVMValueRef Inst);
Gregory Szorc34c863a2012-03-21 03:54:29 +00002409
2410/**
2411 * Obtain the instruction that occurs after the one specified.
2412 *
2413 * The next instruction will be from the same basic block.
2414 *
2415 * If this is the last instruction in a basic block, NULL will be
2416 * returned.
2417 */
Gordon Henriksen054817c2008-03-19 03:47:18 +00002418LLVMValueRef LLVMGetNextInstruction(LLVMValueRef Inst);
Gregory Szorc34c863a2012-03-21 03:54:29 +00002419
2420/**
Benjamin Kramerbde91762012-06-02 10:20:22 +00002421 * Obtain the instruction that occurred before this one.
Gregory Szorc34c863a2012-03-21 03:54:29 +00002422 *
2423 * If the instruction is the first instruction in a basic block, NULL
2424 * will be returned.
2425 */
Gordon Henriksen054817c2008-03-19 03:47:18 +00002426LLVMValueRef LLVMGetPreviousInstruction(LLVMValueRef Inst);
Gregory Szorc34c863a2012-03-21 03:54:29 +00002427
2428/**
2429 * Remove and delete an instruction.
2430 *
2431 * The instruction specified is removed from its containing building
Amaury Sechet2f432082016-02-11 21:37:54 +00002432 * block but is kept alive.
2433 *
2434 * @see llvm::Instruction::removeFromParent()
2435 */
2436void LLVMInstructionRemoveFromParent(LLVMValueRef Inst);
2437
2438/**
2439 * Remove and delete an instruction.
2440 *
2441 * The instruction specified is removed from its containing building
Gregory Szorc34c863a2012-03-21 03:54:29 +00002442 * block and then deleted.
2443 *
2444 * @see llvm::Instruction::eraseFromParent()
2445 */
Devang Pateldbebc6f2011-10-03 20:59:18 +00002446void LLVMInstructionEraseFromParent(LLVMValueRef Inst);
Gregory Szorc34c863a2012-03-21 03:54:29 +00002447
2448/**
2449 * Obtain the code opcode for an individual instruction.
2450 *
2451 * @see llvm::Instruction::getOpCode()
2452 */
Eric Christophera6b96002015-12-18 01:46:52 +00002453LLVMOpcode LLVMGetInstructionOpcode(LLVMValueRef Inst);
Gregory Szorc34c863a2012-03-21 03:54:29 +00002454
2455/**
2456 * Obtain the predicate of an instruction.
2457 *
2458 * This is only valid for instructions that correspond to llvm::ICmpInst
2459 * or llvm::ConstantExpr whose opcode is llvm::Instruction::ICmp.
2460 *
2461 * @see llvm::ICmpInst::getPredicate()
2462 */
Torok Edwin60c40de2011-10-06 12:13:20 +00002463LLVMIntPredicate LLVMGetICmpPredicate(LLVMValueRef Inst);
Gordon Henriksen265f7802008-03-19 01:11:35 +00002464
Gregory Szorc34c863a2012-03-21 03:54:29 +00002465/**
Peter Zotov1d98e6d2014-10-28 19:46:44 +00002466 * Obtain the float predicate of an instruction.
2467 *
2468 * This is only valid for instructions that correspond to llvm::FCmpInst
2469 * or llvm::ConstantExpr whose opcode is llvm::Instruction::FCmp.
2470 *
2471 * @see llvm::FCmpInst::getPredicate()
2472 */
2473LLVMRealPredicate LLVMGetFCmpPredicate(LLVMValueRef Inst);
2474
2475/**
Peter Zotovaff492c2014-10-17 01:02:34 +00002476 * Create a copy of 'this' instruction that is identical in all ways
2477 * except the following:
2478 * * The instruction has no parent
2479 * * The instruction has no name
2480 *
2481 * @see llvm::Instruction::clone()
2482 */
2483LLVMValueRef LLVMInstructionClone(LLVMValueRef Inst);
2484
2485/**
Gregory Szorc34c863a2012-03-21 03:54:29 +00002486 * @defgroup LLVMCCoreValueInstructionCall Call Sites and Invocations
2487 *
2488 * Functions in this group apply to instructions that refer to call
2489 * sites and invocations. These correspond to C++ types in the
2490 * llvm::CallInst class tree.
2491 *
2492 * @{
2493 */
2494
2495/**
Amaury Sechet5c7b3af2016-02-10 00:09:37 +00002496 * Obtain the argument count for a call instruction.
2497 *
2498 * This expects an LLVMValueRef that corresponds to a llvm::CallInst or
2499 * llvm::InvokeInst.
2500 *
2501 * @see llvm::CallInst::getNumArgOperands()
2502 * @see llvm::InvokeInst::getNumArgOperands()
2503 */
2504unsigned LLVMGetNumArgOperands(LLVMValueRef Instr);
2505
2506/**
Gregory Szorc34c863a2012-03-21 03:54:29 +00002507 * Set the calling convention for a call instruction.
2508 *
2509 * This expects an LLVMValueRef that corresponds to a llvm::CallInst or
2510 * llvm::InvokeInst.
2511 *
2512 * @see llvm::CallInst::setCallingConv()
2513 * @see llvm::InvokeInst::setCallingConv()
2514 */
Gordon Henriksen1158c532007-12-29 20:45:00 +00002515void LLVMSetInstructionCallConv(LLVMValueRef Instr, unsigned CC);
Gregory Szorc34c863a2012-03-21 03:54:29 +00002516
2517/**
2518 * Obtain the calling convention for a call instruction.
2519 *
2520 * This is the opposite of LLVMSetInstructionCallConv(). Reads its
2521 * usage.
2522 *
2523 * @see LLVMSetInstructionCallConv()
2524 */
Gordon Henriksen1158c532007-12-29 20:45:00 +00002525unsigned LLVMGetInstructionCallConv(LLVMValueRef Instr);
Gregory Szorc34c863a2012-03-21 03:54:29 +00002526
2527
Devang Patel4c758ea2008-09-25 21:00:45 +00002528void LLVMAddInstrAttribute(LLVMValueRef Instr, unsigned index, LLVMAttribute);
Gregory Szorc34c863a2012-03-21 03:54:29 +00002529void LLVMRemoveInstrAttribute(LLVMValueRef Instr, unsigned index,
Devang Patel4c758ea2008-09-25 21:00:45 +00002530 LLVMAttribute);
Gregory Szorc34c863a2012-03-21 03:54:29 +00002531void LLVMSetInstrParamAlignment(LLVMValueRef Instr, unsigned index,
Amaury Sechet81243a72016-05-01 01:42:34 +00002532 unsigned Align);
Gordon Henriksen1158c532007-12-29 20:45:00 +00002533
Gregory Szorc34c863a2012-03-21 03:54:29 +00002534/**
Amaury Sechet5c7b3af2016-02-10 00:09:37 +00002535 * Obtain the pointer to the function invoked by this instruction.
2536 *
2537 * This expects an LLVMValueRef that corresponds to a llvm::CallInst or
2538 * llvm::InvokeInst.
2539 *
2540 * @see llvm::CallInst::getCalledValue()
2541 * @see llvm::InvokeInst::getCalledValue()
2542 */
2543LLVMValueRef LLVMGetCalledValue(LLVMValueRef Instr);
2544
2545/**
Gregory Szorc34c863a2012-03-21 03:54:29 +00002546 * Obtain whether a call instruction is a tail call.
2547 *
2548 * This only works on llvm::CallInst instructions.
2549 *
2550 * @see llvm::CallInst::isTailCall()
2551 */
Chris Lattner25963c62010-01-09 22:27:07 +00002552LLVMBool LLVMIsTailCall(LLVMValueRef CallInst);
Gregory Szorc34c863a2012-03-21 03:54:29 +00002553
2554/**
2555 * Set whether a call instruction is a tail call.
2556 *
2557 * This only works on llvm::CallInst instructions.
2558 *
2559 * @see llvm::CallInst::setTailCall()
2560 */
Chris Lattner25963c62010-01-09 22:27:07 +00002561void LLVMSetTailCall(LLVMValueRef CallInst, LLVMBool IsTailCall);
Gordon Henrikseneeb65372008-08-30 16:34:54 +00002562
Gregory Szorc34c863a2012-03-21 03:54:29 +00002563/**
Amaury Sechete39e8532016-02-18 20:38:32 +00002564 * Return the normal destination basic block.
2565 *
2566 * This only works on llvm::InvokeInst instructions.
2567 *
2568 * @see llvm::InvokeInst::getNormalDest()
2569 */
2570LLVMBasicBlockRef LLVMGetNormalDest(LLVMValueRef InvokeInst);
2571
2572/**
2573 * Return the unwind destination basic block.
2574 *
2575 * This only works on llvm::InvokeInst instructions.
2576 *
2577 * @see llvm::InvokeInst::getUnwindDest()
2578 */
2579LLVMBasicBlockRef LLVMGetUnwindDest(LLVMValueRef InvokeInst);
2580
2581/**
2582 * Set the normal destination basic block.
2583 *
2584 * This only works on llvm::InvokeInst instructions.
2585 *
2586 * @see llvm::InvokeInst::setNormalDest()
2587 */
2588void LLVMSetNormalDest(LLVMValueRef InvokeInst, LLVMBasicBlockRef B);
2589
2590/**
2591 * Set the unwind destination basic block.
2592 *
2593 * This only works on llvm::InvokeInst instructions.
2594 *
2595 * @see llvm::InvokeInst::setUnwindDest()
2596 */
2597void LLVMSetUnwindDest(LLVMValueRef InvokeInst, LLVMBasicBlockRef B);
2598
2599/**
Gregory Szorc34c863a2012-03-21 03:54:29 +00002600 * @}
2601 */
2602
2603/**
Peter Zotov2481c752014-10-28 19:46:56 +00002604 * @defgroup LLVMCCoreValueInstructionTerminator Terminators
2605 *
2606 * Functions in this group only apply to instructions that map to
2607 * llvm::TerminatorInst instances.
2608 *
2609 * @{
2610 */
2611
2612/**
2613 * Return the number of successors that this terminator has.
2614 *
2615 * @see llvm::TerminatorInst::getNumSuccessors
2616 */
2617unsigned LLVMGetNumSuccessors(LLVMValueRef Term);
2618
2619/**
2620 * Return the specified successor.
2621 *
2622 * @see llvm::TerminatorInst::getSuccessor
2623 */
2624LLVMBasicBlockRef LLVMGetSuccessor(LLVMValueRef Term, unsigned i);
2625
2626/**
2627 * Update the specified successor to point at the provided block.
2628 *
2629 * @see llvm::TerminatorInst::setSuccessor
2630 */
2631void LLVMSetSuccessor(LLVMValueRef Term, unsigned i, LLVMBasicBlockRef block);
2632
2633/**
2634 * Return if a branch is conditional.
2635 *
2636 * This only works on llvm::BranchInst instructions.
2637 *
2638 * @see llvm::BranchInst::isConditional
2639 */
2640LLVMBool LLVMIsConditional(LLVMValueRef Branch);
2641
2642/**
2643 * Return the condition of a branch instruction.
2644 *
2645 * This only works on llvm::BranchInst instructions.
2646 *
2647 * @see llvm::BranchInst::getCondition
2648 */
2649LLVMValueRef LLVMGetCondition(LLVMValueRef Branch);
2650
2651/**
2652 * Set the condition of a branch instruction.
2653 *
2654 * This only works on llvm::BranchInst instructions.
2655 *
2656 * @see llvm::BranchInst::setCondition
2657 */
2658void LLVMSetCondition(LLVMValueRef Branch, LLVMValueRef Cond);
2659
2660/**
Gregory Szorc34c863a2012-03-21 03:54:29 +00002661 * Obtain the default destination basic block of a switch instruction.
2662 *
2663 * This only works on llvm::SwitchInst instructions.
2664 *
2665 * @see llvm::SwitchInst::getDefaultDest()
2666 */
Nate Begeman43c322b2011-08-23 20:27:46 +00002667LLVMBasicBlockRef LLVMGetSwitchDefaultDest(LLVMValueRef SwitchInstr);
2668
Gregory Szorc34c863a2012-03-21 03:54:29 +00002669/**
Peter Zotov2481c752014-10-28 19:46:56 +00002670 * @}
2671 */
2672
2673/**
Amaury Sechet1dcf5772016-02-09 22:50:53 +00002674 * @defgroup LLVMCCoreValueInstructionAlloca Allocas
2675 *
2676 * Functions in this group only apply to instructions that map to
2677 * llvm::AllocaInst instances.
2678 *
2679 * @{
2680 */
2681
2682/**
2683 * Obtain the type that is being allocated by the alloca instruction.
2684 */
2685LLVMTypeRef LLVMGetAllocatedType(LLVMValueRef Alloca);
2686
2687/**
2688 * @}
2689 */
2690
2691/**
Amaury Sechet053ac452016-02-17 22:51:03 +00002692 * @defgroup LLVMCCoreValueInstructionGetElementPointer GEPs
2693 *
2694 * Functions in this group only apply to instructions that map to
2695 * llvm::GetElementPtrInst instances.
2696 *
2697 * @{
2698 */
2699
2700/**
2701 * Check whether the given GEP instruction is inbounds.
2702 */
2703LLVMBool LLVMIsInBounds(LLVMValueRef GEP);
2704
2705/**
2706 * Set the given GEP instruction to be inbounds or not.
2707 */
Amaury Sechet8a367d42016-05-01 02:23:14 +00002708void LLVMSetIsInBounds(LLVMValueRef GEP, LLVMBool InBounds);
Amaury Sechet053ac452016-02-17 22:51:03 +00002709
2710/**
2711 * @}
2712 */
2713
2714/**
Gregory Szorc34c863a2012-03-21 03:54:29 +00002715 * @defgroup LLVMCCoreValueInstructionPHINode PHI Nodes
2716 *
2717 * Functions in this group only apply to instructions that map to
2718 * llvm::PHINode instances.
2719 *
2720 * @{
2721 */
2722
2723/**
2724 * Add an incoming value to the end of a PHI list.
2725 */
Gordon Henriksen44dd8fb2007-10-08 18:14:39 +00002726void LLVMAddIncoming(LLVMValueRef PhiNode, LLVMValueRef *IncomingValues,
2727 LLVMBasicBlockRef *IncomingBlocks, unsigned Count);
Gregory Szorc34c863a2012-03-21 03:54:29 +00002728
2729/**
2730 * Obtain the number of incoming basic blocks to a PHI node.
2731 */
Gordon Henriksen44dd8fb2007-10-08 18:14:39 +00002732unsigned LLVMCountIncoming(LLVMValueRef PhiNode);
Gregory Szorc34c863a2012-03-21 03:54:29 +00002733
2734/**
Daniel Dunbar06b9f9e2013-08-16 23:30:19 +00002735 * Obtain an incoming value to a PHI node as an LLVMValueRef.
Gregory Szorc34c863a2012-03-21 03:54:29 +00002736 */
Gordon Henriksen44dd8fb2007-10-08 18:14:39 +00002737LLVMValueRef LLVMGetIncomingValue(LLVMValueRef PhiNode, unsigned Index);
Gregory Szorc34c863a2012-03-21 03:54:29 +00002738
2739/**
Daniel Dunbar06b9f9e2013-08-16 23:30:19 +00002740 * Obtain an incoming value to a PHI node as an LLVMBasicBlockRef.
Gregory Szorc34c863a2012-03-21 03:54:29 +00002741 */
Gordon Henriksen44dd8fb2007-10-08 18:14:39 +00002742LLVMBasicBlockRef LLVMGetIncomingBlock(LLVMValueRef PhiNode, unsigned Index);
Gordon Henriksenc23b66c2007-09-26 20:56:12 +00002743
Gregory Szorc34c863a2012-03-21 03:54:29 +00002744/**
2745 * @}
2746 */
Gordon Henriksenc23b66c2007-09-26 20:56:12 +00002747
Gregory Szorc34c863a2012-03-21 03:54:29 +00002748/**
Amaury Sechetaad93532016-02-10 00:38:50 +00002749 * @defgroup LLVMCCoreValueInstructionExtractValue ExtractValue
2750 * @defgroup LLVMCCoreValueInstructionInsertValue InsertValue
2751 *
2752 * Functions in this group only apply to instructions that map to
2753 * llvm::ExtractValue and llvm::InsertValue instances.
2754 *
2755 * @{
2756 */
2757
2758/**
2759 * Obtain the number of indices.
Amaury Sechet053ac452016-02-17 22:51:03 +00002760 * NB: This also works on GEP.
Amaury Sechetaad93532016-02-10 00:38:50 +00002761 */
2762unsigned LLVMGetNumIndices(LLVMValueRef Inst);
2763
2764/**
2765 * Obtain the indices as an array.
2766 */
2767const unsigned *LLVMGetIndices(LLVMValueRef Inst);
2768
2769/**
2770 * @}
2771 */
2772
2773/**
Gregory Szorc34c863a2012-03-21 03:54:29 +00002774 * @}
2775 */
2776
2777/**
2778 * @}
2779 */
2780
2781/**
2782 * @defgroup LLVMCCoreInstructionBuilder Instruction Builders
2783 *
2784 * An instruction builder represents a point within a basic block and is
2785 * the exclusive means of building instructions using the C interface.
2786 *
2787 * @{
Gordon Henriksenc23b66c2007-09-26 20:56:12 +00002788 */
2789
Erick Tryzelaar262332f2009-08-14 00:01:31 +00002790LLVMBuilderRef LLVMCreateBuilderInContext(LLVMContextRef C);
Gordon Henriksena735a9c2008-05-04 12:55:34 +00002791LLVMBuilderRef LLVMCreateBuilder(void);
Gordon Henriksen054817c2008-03-19 03:47:18 +00002792void LLVMPositionBuilder(LLVMBuilderRef Builder, LLVMBasicBlockRef Block,
2793 LLVMValueRef Instr);
Gordon Henriksenc23b66c2007-09-26 20:56:12 +00002794void LLVMPositionBuilderBefore(LLVMBuilderRef Builder, LLVMValueRef Instr);
2795void LLVMPositionBuilderAtEnd(LLVMBuilderRef Builder, LLVMBasicBlockRef Block);
Gordon Henriksen265f7802008-03-19 01:11:35 +00002796LLVMBasicBlockRef LLVMGetInsertBlock(LLVMBuilderRef Builder);
Chris Lattner3d1f5522008-12-17 21:39:50 +00002797void LLVMClearInsertionPosition(LLVMBuilderRef Builder);
2798void LLVMInsertIntoBuilder(LLVMBuilderRef Builder, LLVMValueRef Instr);
Erick Tryzelaar9813bea2009-08-16 02:20:57 +00002799void LLVMInsertIntoBuilderWithName(LLVMBuilderRef Builder, LLVMValueRef Instr,
2800 const char *Name);
Gordon Henriksenc23b66c2007-09-26 20:56:12 +00002801void LLVMDisposeBuilder(LLVMBuilderRef Builder);
2802
Erick Tryzelaard8531fa2010-02-28 09:45:59 +00002803/* Metadata */
2804void LLVMSetCurrentDebugLocation(LLVMBuilderRef Builder, LLVMValueRef L);
2805LLVMValueRef LLVMGetCurrentDebugLocation(LLVMBuilderRef Builder);
2806void LLVMSetInstDebugLocation(LLVMBuilderRef Builder, LLVMValueRef Inst);
2807
Gordon Henriksenc23b66c2007-09-26 20:56:12 +00002808/* Terminators */
2809LLVMValueRef LLVMBuildRetVoid(LLVMBuilderRef);
2810LLVMValueRef LLVMBuildRet(LLVMBuilderRef, LLVMValueRef V);
Erick Tryzelaarfd529d72009-08-19 08:36:49 +00002811LLVMValueRef LLVMBuildAggregateRet(LLVMBuilderRef, LLVMValueRef *RetVals,
Erick Tryzelaar3045b8b2009-08-16 02:19:59 +00002812 unsigned N);
Gordon Henriksenc23b66c2007-09-26 20:56:12 +00002813LLVMValueRef LLVMBuildBr(LLVMBuilderRef, LLVMBasicBlockRef Dest);
2814LLVMValueRef LLVMBuildCondBr(LLVMBuilderRef, LLVMValueRef If,
2815 LLVMBasicBlockRef Then, LLVMBasicBlockRef Else);
2816LLVMValueRef LLVMBuildSwitch(LLVMBuilderRef, LLVMValueRef V,
2817 LLVMBasicBlockRef Else, unsigned NumCases);
Erick Tryzelaar0fb26ef2010-02-28 09:46:06 +00002818LLVMValueRef LLVMBuildIndirectBr(LLVMBuilderRef B, LLVMValueRef Addr,
2819 unsigned NumDests);
Gordon Henriksenc23b66c2007-09-26 20:56:12 +00002820LLVMValueRef LLVMBuildInvoke(LLVMBuilderRef, LLVMValueRef Fn,
2821 LLVMValueRef *Args, unsigned NumArgs,
2822 LLVMBasicBlockRef Then, LLVMBasicBlockRef Catch,
2823 const char *Name);
Benjamin Kramer5a6568832011-08-19 01:36:54 +00002824LLVMValueRef LLVMBuildLandingPad(LLVMBuilderRef B, LLVMTypeRef Ty,
Reid Kleckneref9828f2015-07-16 01:16:39 +00002825 LLVMValueRef PersFn, unsigned NumClauses,
2826 const char *Name);
Bill Wendlingf891bf82011-07-31 06:30:59 +00002827LLVMValueRef LLVMBuildResume(LLVMBuilderRef B, LLVMValueRef Exn);
Gordon Henriksenc23b66c2007-09-26 20:56:12 +00002828LLVMValueRef LLVMBuildUnreachable(LLVMBuilderRef);
2829
Gordon Henriksen097102c2008-01-01 05:50:53 +00002830/* Add a case to the switch instruction */
2831void LLVMAddCase(LLVMValueRef Switch, LLVMValueRef OnVal,
2832 LLVMBasicBlockRef Dest);
2833
Erick Tryzelaar0fb26ef2010-02-28 09:46:06 +00002834/* Add a destination to the indirectbr instruction */
2835void LLVMAddDestination(LLVMValueRef IndirectBr, LLVMBasicBlockRef Dest);
2836
Amaury Sechete39e8532016-02-18 20:38:32 +00002837/* Get the number of clauses on the landingpad instruction */
2838unsigned LLVMGetNumClauses(LLVMValueRef LandingPad);
2839
2840/* Get the value of the clause at idnex Idx on the landingpad instruction */
2841LLVMValueRef LLVMGetClause(LLVMValueRef LandingPad, unsigned Idx);
2842
Bill Wendlingfae14752011-08-12 20:24:12 +00002843/* Add a catch or filter clause to the landingpad instruction */
2844void LLVMAddClause(LLVMValueRef LandingPad, LLVMValueRef ClauseVal);
2845
Amaury Sechete39e8532016-02-18 20:38:32 +00002846/* Get the 'cleanup' flag in the landingpad instruction */
2847LLVMBool LLVMIsCleanup(LLVMValueRef LandingPad);
2848
Bill Wendlingfae14752011-08-12 20:24:12 +00002849/* Set the 'cleanup' flag in the landingpad instruction */
2850void LLVMSetCleanup(LLVMValueRef LandingPad, LLVMBool Val);
2851
Gordon Henriksenc23b66c2007-09-26 20:56:12 +00002852/* Arithmetic */
2853LLVMValueRef LLVMBuildAdd(LLVMBuilderRef, LLVMValueRef LHS, LLVMValueRef RHS,
2854 const char *Name);
Erick Tryzelaar3045b8b2009-08-16 02:19:59 +00002855LLVMValueRef LLVMBuildNSWAdd(LLVMBuilderRef, LLVMValueRef LHS, LLVMValueRef RHS,
2856 const char *Name);
Erick Tryzelaar4c340c72010-02-28 05:51:43 +00002857LLVMValueRef LLVMBuildNUWAdd(LLVMBuilderRef, LLVMValueRef LHS, LLVMValueRef RHS,
2858 const char *Name);
Erick Tryzelaar3045b8b2009-08-16 02:19:59 +00002859LLVMValueRef LLVMBuildFAdd(LLVMBuilderRef, LLVMValueRef LHS, LLVMValueRef RHS,
2860 const char *Name);
Gordon Henriksenc23b66c2007-09-26 20:56:12 +00002861LLVMValueRef LLVMBuildSub(LLVMBuilderRef, LLVMValueRef LHS, LLVMValueRef RHS,
2862 const char *Name);
Erick Tryzelaar4c340c72010-02-28 05:51:43 +00002863LLVMValueRef LLVMBuildNSWSub(LLVMBuilderRef, LLVMValueRef LHS, LLVMValueRef RHS,
2864 const char *Name);
2865LLVMValueRef LLVMBuildNUWSub(LLVMBuilderRef, LLVMValueRef LHS, LLVMValueRef RHS,
2866 const char *Name);
Erick Tryzelaar3045b8b2009-08-16 02:19:59 +00002867LLVMValueRef LLVMBuildFSub(LLVMBuilderRef, LLVMValueRef LHS, LLVMValueRef RHS,
2868 const char *Name);
Gordon Henriksenc23b66c2007-09-26 20:56:12 +00002869LLVMValueRef LLVMBuildMul(LLVMBuilderRef, LLVMValueRef LHS, LLVMValueRef RHS,
2870 const char *Name);
Erick Tryzelaar4c340c72010-02-28 05:51:43 +00002871LLVMValueRef LLVMBuildNSWMul(LLVMBuilderRef, LLVMValueRef LHS, LLVMValueRef RHS,
2872 const char *Name);
2873LLVMValueRef LLVMBuildNUWMul(LLVMBuilderRef, LLVMValueRef LHS, LLVMValueRef RHS,
2874 const char *Name);
Erick Tryzelaar3045b8b2009-08-16 02:19:59 +00002875LLVMValueRef LLVMBuildFMul(LLVMBuilderRef, LLVMValueRef LHS, LLVMValueRef RHS,
2876 const char *Name);
Gordon Henriksenc23b66c2007-09-26 20:56:12 +00002877LLVMValueRef LLVMBuildUDiv(LLVMBuilderRef, LLVMValueRef LHS, LLVMValueRef RHS,
2878 const char *Name);
2879LLVMValueRef LLVMBuildSDiv(LLVMBuilderRef, LLVMValueRef LHS, LLVMValueRef RHS,
2880 const char *Name);
Erick Tryzelaar3045b8b2009-08-16 02:19:59 +00002881LLVMValueRef LLVMBuildExactSDiv(LLVMBuilderRef, LLVMValueRef LHS, LLVMValueRef RHS,
2882 const char *Name);
Gordon Henriksenc23b66c2007-09-26 20:56:12 +00002883LLVMValueRef LLVMBuildFDiv(LLVMBuilderRef, LLVMValueRef LHS, LLVMValueRef RHS,
2884 const char *Name);
2885LLVMValueRef LLVMBuildURem(LLVMBuilderRef, LLVMValueRef LHS, LLVMValueRef RHS,
2886 const char *Name);
2887LLVMValueRef LLVMBuildSRem(LLVMBuilderRef, LLVMValueRef LHS, LLVMValueRef RHS,
2888 const char *Name);
2889LLVMValueRef LLVMBuildFRem(LLVMBuilderRef, LLVMValueRef LHS, LLVMValueRef RHS,
2890 const char *Name);
2891LLVMValueRef LLVMBuildShl(LLVMBuilderRef, LLVMValueRef LHS, LLVMValueRef RHS,
2892 const char *Name);
2893LLVMValueRef LLVMBuildLShr(LLVMBuilderRef, LLVMValueRef LHS, LLVMValueRef RHS,
2894 const char *Name);
2895LLVMValueRef LLVMBuildAShr(LLVMBuilderRef, LLVMValueRef LHS, LLVMValueRef RHS,
2896 const char *Name);
2897LLVMValueRef LLVMBuildAnd(LLVMBuilderRef, LLVMValueRef LHS, LLVMValueRef RHS,
2898 const char *Name);
2899LLVMValueRef LLVMBuildOr(LLVMBuilderRef, LLVMValueRef LHS, LLVMValueRef RHS,
2900 const char *Name);
2901LLVMValueRef LLVMBuildXor(LLVMBuilderRef, LLVMValueRef LHS, LLVMValueRef RHS,
2902 const char *Name);
Erick Tryzelaar31831792010-02-28 05:51:27 +00002903LLVMValueRef LLVMBuildBinOp(LLVMBuilderRef B, LLVMOpcode Op,
2904 LLVMValueRef LHS, LLVMValueRef RHS,
2905 const char *Name);
Gordon Henriksenc23b66c2007-09-26 20:56:12 +00002906LLVMValueRef LLVMBuildNeg(LLVMBuilderRef, LLVMValueRef V, const char *Name);
Erick Tryzelaar4c340c72010-02-28 05:51:43 +00002907LLVMValueRef LLVMBuildNSWNeg(LLVMBuilderRef B, LLVMValueRef V,
2908 const char *Name);
2909LLVMValueRef LLVMBuildNUWNeg(LLVMBuilderRef B, LLVMValueRef V,
2910 const char *Name);
Dan Gohmanf919bd62009-09-28 21:51:41 +00002911LLVMValueRef LLVMBuildFNeg(LLVMBuilderRef, LLVMValueRef V, const char *Name);
Gordon Henriksenc23b66c2007-09-26 20:56:12 +00002912LLVMValueRef LLVMBuildNot(LLVMBuilderRef, LLVMValueRef V, const char *Name);
2913
2914/* Memory */
2915LLVMValueRef LLVMBuildMalloc(LLVMBuilderRef, LLVMTypeRef Ty, const char *Name);
2916LLVMValueRef LLVMBuildArrayMalloc(LLVMBuilderRef, LLVMTypeRef Ty,
2917 LLVMValueRef Val, const char *Name);
2918LLVMValueRef LLVMBuildAlloca(LLVMBuilderRef, LLVMTypeRef Ty, const char *Name);
2919LLVMValueRef LLVMBuildArrayAlloca(LLVMBuilderRef, LLVMTypeRef Ty,
2920 LLVMValueRef Val, const char *Name);
2921LLVMValueRef LLVMBuildFree(LLVMBuilderRef, LLVMValueRef PointerVal);
2922LLVMValueRef LLVMBuildLoad(LLVMBuilderRef, LLVMValueRef PointerVal,
2923 const char *Name);
2924LLVMValueRef LLVMBuildStore(LLVMBuilderRef, LLVMValueRef Val, LLVMValueRef Ptr);
2925LLVMValueRef LLVMBuildGEP(LLVMBuilderRef B, LLVMValueRef Pointer,
2926 LLVMValueRef *Indices, unsigned NumIndices,
2927 const char *Name);
Erick Tryzelaar3045b8b2009-08-16 02:19:59 +00002928LLVMValueRef LLVMBuildInBoundsGEP(LLVMBuilderRef B, LLVMValueRef Pointer,
2929 LLVMValueRef *Indices, unsigned NumIndices,
2930 const char *Name);
2931LLVMValueRef LLVMBuildStructGEP(LLVMBuilderRef B, LLVMValueRef Pointer,
2932 unsigned Idx, const char *Name);
2933LLVMValueRef LLVMBuildGlobalString(LLVMBuilderRef B, const char *Str,
2934 const char *Name);
2935LLVMValueRef LLVMBuildGlobalStringPtr(LLVMBuilderRef B, const char *Str,
2936 const char *Name);
Chris Lattner2cc6f9d2012-03-22 03:54:15 +00002937LLVMBool LLVMGetVolatile(LLVMValueRef MemoryAccessInst);
2938void LLVMSetVolatile(LLVMValueRef MemoryAccessInst, LLVMBool IsVolatile);
Andrew Wilkinsb7362ce2015-08-02 12:16:57 +00002939LLVMAtomicOrdering LLVMGetOrdering(LLVMValueRef MemoryAccessInst);
2940void LLVMSetOrdering(LLVMValueRef MemoryAccessInst, LLVMAtomicOrdering Ordering);
Gordon Henriksenc23b66c2007-09-26 20:56:12 +00002941
2942/* Casts */
2943LLVMValueRef LLVMBuildTrunc(LLVMBuilderRef, LLVMValueRef Val,
2944 LLVMTypeRef DestTy, const char *Name);
2945LLVMValueRef LLVMBuildZExt(LLVMBuilderRef, LLVMValueRef Val,
2946 LLVMTypeRef DestTy, const char *Name);
2947LLVMValueRef LLVMBuildSExt(LLVMBuilderRef, LLVMValueRef Val,
2948 LLVMTypeRef DestTy, const char *Name);
2949LLVMValueRef LLVMBuildFPToUI(LLVMBuilderRef, LLVMValueRef Val,
2950 LLVMTypeRef DestTy, const char *Name);
2951LLVMValueRef LLVMBuildFPToSI(LLVMBuilderRef, LLVMValueRef Val,
2952 LLVMTypeRef DestTy, const char *Name);
2953LLVMValueRef LLVMBuildUIToFP(LLVMBuilderRef, LLVMValueRef Val,
2954 LLVMTypeRef DestTy, const char *Name);
2955LLVMValueRef LLVMBuildSIToFP(LLVMBuilderRef, LLVMValueRef Val,
2956 LLVMTypeRef DestTy, const char *Name);
2957LLVMValueRef LLVMBuildFPTrunc(LLVMBuilderRef, LLVMValueRef Val,
2958 LLVMTypeRef DestTy, const char *Name);
2959LLVMValueRef LLVMBuildFPExt(LLVMBuilderRef, LLVMValueRef Val,
2960 LLVMTypeRef DestTy, const char *Name);
2961LLVMValueRef LLVMBuildPtrToInt(LLVMBuilderRef, LLVMValueRef Val,
2962 LLVMTypeRef DestTy, const char *Name);
2963LLVMValueRef LLVMBuildIntToPtr(LLVMBuilderRef, LLVMValueRef Val,
2964 LLVMTypeRef DestTy, const char *Name);
2965LLVMValueRef LLVMBuildBitCast(LLVMBuilderRef, LLVMValueRef Val,
2966 LLVMTypeRef DestTy, const char *Name);
Matt Arsenaultb03bd4d2013-11-15 01:34:59 +00002967LLVMValueRef LLVMBuildAddrSpaceCast(LLVMBuilderRef, LLVMValueRef Val,
2968 LLVMTypeRef DestTy, const char *Name);
Erick Tryzelaar3045b8b2009-08-16 02:19:59 +00002969LLVMValueRef LLVMBuildZExtOrBitCast(LLVMBuilderRef, LLVMValueRef Val,
2970 LLVMTypeRef DestTy, const char *Name);
2971LLVMValueRef LLVMBuildSExtOrBitCast(LLVMBuilderRef, LLVMValueRef Val,
2972 LLVMTypeRef DestTy, const char *Name);
2973LLVMValueRef LLVMBuildTruncOrBitCast(LLVMBuilderRef, LLVMValueRef Val,
2974 LLVMTypeRef DestTy, const char *Name);
Erick Tryzelaar31831792010-02-28 05:51:27 +00002975LLVMValueRef LLVMBuildCast(LLVMBuilderRef B, LLVMOpcode Op, LLVMValueRef Val,
2976 LLVMTypeRef DestTy, const char *Name);
Erick Tryzelaar3045b8b2009-08-16 02:19:59 +00002977LLVMValueRef LLVMBuildPointerCast(LLVMBuilderRef, LLVMValueRef Val,
2978 LLVMTypeRef DestTy, const char *Name);
Duncan Sands9d786d72009-11-23 10:49:03 +00002979LLVMValueRef LLVMBuildIntCast(LLVMBuilderRef, LLVMValueRef Val, /*Signed cast!*/
Erick Tryzelaar3045b8b2009-08-16 02:19:59 +00002980 LLVMTypeRef DestTy, const char *Name);
2981LLVMValueRef LLVMBuildFPCast(LLVMBuilderRef, LLVMValueRef Val,
2982 LLVMTypeRef DestTy, const char *Name);
Gordon Henriksenc23b66c2007-09-26 20:56:12 +00002983
2984/* Comparisons */
2985LLVMValueRef LLVMBuildICmp(LLVMBuilderRef, LLVMIntPredicate Op,
2986 LLVMValueRef LHS, LLVMValueRef RHS,
2987 const char *Name);
2988LLVMValueRef LLVMBuildFCmp(LLVMBuilderRef, LLVMRealPredicate Op,
2989 LLVMValueRef LHS, LLVMValueRef RHS,
2990 const char *Name);
2991
2992/* Miscellaneous instructions */
2993LLVMValueRef LLVMBuildPhi(LLVMBuilderRef, LLVMTypeRef Ty, const char *Name);
2994LLVMValueRef LLVMBuildCall(LLVMBuilderRef, LLVMValueRef Fn,
2995 LLVMValueRef *Args, unsigned NumArgs,
2996 const char *Name);
2997LLVMValueRef LLVMBuildSelect(LLVMBuilderRef, LLVMValueRef If,
2998 LLVMValueRef Then, LLVMValueRef Else,
2999 const char *Name);
3000LLVMValueRef LLVMBuildVAArg(LLVMBuilderRef, LLVMValueRef List, LLVMTypeRef Ty,
3001 const char *Name);
3002LLVMValueRef LLVMBuildExtractElement(LLVMBuilderRef, LLVMValueRef VecVal,
3003 LLVMValueRef Index, const char *Name);
3004LLVMValueRef LLVMBuildInsertElement(LLVMBuilderRef, LLVMValueRef VecVal,
3005 LLVMValueRef EltVal, LLVMValueRef Index,
3006 const char *Name);
3007LLVMValueRef LLVMBuildShuffleVector(LLVMBuilderRef, LLVMValueRef V1,
3008 LLVMValueRef V2, LLVMValueRef Mask,
3009 const char *Name);
Dan Gohmand5104a52008-11-03 22:55:43 +00003010LLVMValueRef LLVMBuildExtractValue(LLVMBuilderRef, LLVMValueRef AggVal,
3011 unsigned Index, const char *Name);
3012LLVMValueRef LLVMBuildInsertValue(LLVMBuilderRef, LLVMValueRef AggVal,
3013 LLVMValueRef EltVal, unsigned Index,
3014 const char *Name);
Gordon Henriksen76a03742007-09-18 03:18:57 +00003015
Erick Tryzelaar3045b8b2009-08-16 02:19:59 +00003016LLVMValueRef LLVMBuildIsNull(LLVMBuilderRef, LLVMValueRef Val,
3017 const char *Name);
3018LLVMValueRef LLVMBuildIsNotNull(LLVMBuilderRef, LLVMValueRef Val,
3019 const char *Name);
3020LLVMValueRef LLVMBuildPtrDiff(LLVMBuilderRef, LLVMValueRef LHS,
3021 LLVMValueRef RHS, const char *Name);
Filip Pizlo0d3f7ec2013-11-20 00:07:49 +00003022LLVMValueRef LLVMBuildFence(LLVMBuilderRef B, LLVMAtomicOrdering ordering,
3023 LLVMBool singleThread, const char *Name);
3024LLVMValueRef LLVMBuildAtomicRMW(LLVMBuilderRef B, LLVMAtomicRMWBinOp op,
NAKAMURA Takumia3a81352013-10-23 17:56:29 +00003025 LLVMValueRef PTR, LLVMValueRef Val,
3026 LLVMAtomicOrdering ordering,
Carlo Kok8c6719b2013-04-23 13:21:19 +00003027 LLVMBool singleThread);
Mehdi Amini43165d92016-03-19 21:28:28 +00003028LLVMValueRef LLVMBuildAtomicCmpXchg(LLVMBuilderRef B, LLVMValueRef Ptr,
3029 LLVMValueRef Cmp, LLVMValueRef New,
3030 LLVMAtomicOrdering SuccessOrdering,
3031 LLVMAtomicOrdering FailureOrdering,
3032 LLVMBool SingleThread);
3033
3034LLVMBool LLVMIsAtomicSingleThread(LLVMValueRef AtomicInst);
3035void LLVMSetAtomicSingleThread(LLVMValueRef AtomicInst, LLVMBool SingleThread);
3036
3037LLVMAtomicOrdering LLVMGetCmpXchgSuccessOrdering(LLVMValueRef CmpXchgInst);
3038void LLVMSetCmpXchgSuccessOrdering(LLVMValueRef CmpXchgInst,
3039 LLVMAtomicOrdering Ordering);
3040LLVMAtomicOrdering LLVMGetCmpXchgFailureOrdering(LLVMValueRef CmpXchgInst);
3041void LLVMSetCmpXchgFailureOrdering(LLVMValueRef CmpXchgInst,
3042 LLVMAtomicOrdering Ordering);
Erick Tryzelaar3045b8b2009-08-16 02:19:59 +00003043
Gregory Szorc34c863a2012-03-21 03:54:29 +00003044/**
3045 * @}
3046 */
Gordon Henriksen34eb6d82007-12-19 22:30:40 +00003047
Gregory Szorc34c863a2012-03-21 03:54:29 +00003048/**
3049 * @defgroup LLVMCCoreModuleProvider Module Providers
3050 *
3051 * @{
3052 */
Gordon Henriksen0a68fe22007-12-12 01:04:30 +00003053
Gregory Szorc34c863a2012-03-21 03:54:29 +00003054/**
3055 * Changes the type of M so it can be passed to FunctionPassManagers and the
Jeffrey Yasskin091217b2010-01-27 20:34:15 +00003056 * JIT. They take ModuleProviders for historical reasons.
Gordon Henriksen0a68fe22007-12-12 01:04:30 +00003057 */
3058LLVMModuleProviderRef
3059LLVMCreateModuleProviderForExistingModule(LLVMModuleRef M);
3060
Gregory Szorc34c863a2012-03-21 03:54:29 +00003061/**
3062 * Destroys the module M.
Gordon Henriksen0a68fe22007-12-12 01:04:30 +00003063 */
Jeffrey Yasskin091217b2010-01-27 20:34:15 +00003064void LLVMDisposeModuleProvider(LLVMModuleProviderRef M);
Gordon Henriksen0a68fe22007-12-12 01:04:30 +00003065
Gregory Szorc34c863a2012-03-21 03:54:29 +00003066/**
3067 * @}
3068 */
Gordon Henriksen34eb6d82007-12-19 22:30:40 +00003069
Gregory Szorc34c863a2012-03-21 03:54:29 +00003070/**
3071 * @defgroup LLVMCCoreMemoryBuffers Memory Buffers
3072 *
3073 * @{
3074 */
Gordon Henriksen34eb6d82007-12-19 22:30:40 +00003075
Chris Lattner25963c62010-01-09 22:27:07 +00003076LLVMBool LLVMCreateMemoryBufferWithContentsOfFile(const char *Path,
3077 LLVMMemoryBufferRef *OutMemBuf,
3078 char **OutMessage);
3079LLVMBool LLVMCreateMemoryBufferWithSTDIN(LLVMMemoryBufferRef *OutMemBuf,
3080 char **OutMessage);
Bill Wendling526276a2013-02-14 19:11:28 +00003081LLVMMemoryBufferRef LLVMCreateMemoryBufferWithMemoryRange(const char *InputData,
3082 size_t InputDataLength,
3083 const char *BufferName,
Bill Wendlingc9baa962013-02-14 19:39:14 +00003084 LLVMBool RequiresNullTerminator);
Bill Wendling526276a2013-02-14 19:11:28 +00003085LLVMMemoryBufferRef LLVMCreateMemoryBufferWithMemoryRangeCopy(const char *InputData,
3086 size_t InputDataLength,
3087 const char *BufferName);
Tom Stellard62c03202013-04-18 19:50:53 +00003088const char *LLVMGetBufferStart(LLVMMemoryBufferRef MemBuf);
Tom Stellardb7fb7242013-04-16 23:12:51 +00003089size_t LLVMGetBufferSize(LLVMMemoryBufferRef MemBuf);
Gordon Henriksen34eb6d82007-12-19 22:30:40 +00003090void LLVMDisposeMemoryBuffer(LLVMMemoryBufferRef MemBuf);
3091
Gregory Szorc34c863a2012-03-21 03:54:29 +00003092/**
3093 * @}
3094 */
3095
3096/**
3097 * @defgroup LLVMCCorePassRegistry Pass Registry
3098 *
3099 * @{
3100 */
Owen Anderson4698c5d2010-10-07 17:55:47 +00003101
3102/** Return the global pass registry, for use with initialization functions.
Gregory Szorc34c863a2012-03-21 03:54:29 +00003103 @see llvm::PassRegistry::getPassRegistry */
Owen Anderson4698c5d2010-10-07 17:55:47 +00003104LLVMPassRegistryRef LLVMGetGlobalPassRegistry(void);
Gordon Henriksen878114b2008-03-16 04:20:44 +00003105
Gregory Szorc34c863a2012-03-21 03:54:29 +00003106/**
3107 * @}
3108 */
3109
3110/**
3111 * @defgroup LLVMCCorePassManagers Pass Managers
3112 *
3113 * @{
3114 */
Gordon Henriksen878114b2008-03-16 04:20:44 +00003115
3116/** Constructs a new whole-module pass pipeline. This type of pipeline is
3117 suitable for link-time optimization and whole-module transformations.
Gregory Szorc34c863a2012-03-21 03:54:29 +00003118 @see llvm::PassManager::PassManager */
Gordon Henriksena735a9c2008-05-04 12:55:34 +00003119LLVMPassManagerRef LLVMCreatePassManager(void);
Gordon Henriksen878114b2008-03-16 04:20:44 +00003120
3121/** Constructs a new function-by-function pass pipeline over the module
3122 provider. It does not take ownership of the module provider. This type of
3123 pipeline is suitable for code generation and JIT compilation tasks.
Gregory Szorc34c863a2012-03-21 03:54:29 +00003124 @see llvm::FunctionPassManager::FunctionPassManager */
Erick Tryzelaarad0e0cb2010-03-02 23:58:54 +00003125LLVMPassManagerRef LLVMCreateFunctionPassManagerForModule(LLVMModuleRef M);
3126
3127/** Deprecated: Use LLVMCreateFunctionPassManagerForModule instead. */
Gordon Henriksen878114b2008-03-16 04:20:44 +00003128LLVMPassManagerRef LLVMCreateFunctionPassManager(LLVMModuleProviderRef MP);
3129
3130/** Initializes, executes on the provided module, and finalizes all of the
3131 passes scheduled in the pass manager. Returns 1 if any of the passes
Gregory Szorc34c863a2012-03-21 03:54:29 +00003132 modified the module, 0 otherwise.
3133 @see llvm::PassManager::run(Module&) */
Chris Lattner25963c62010-01-09 22:27:07 +00003134LLVMBool LLVMRunPassManager(LLVMPassManagerRef PM, LLVMModuleRef M);
Gordon Henriksen878114b2008-03-16 04:20:44 +00003135
3136/** Initializes all of the function passes scheduled in the function pass
3137 manager. Returns 1 if any of the passes modified the module, 0 otherwise.
Gregory Szorc34c863a2012-03-21 03:54:29 +00003138 @see llvm::FunctionPassManager::doInitialization */
Chris Lattner25963c62010-01-09 22:27:07 +00003139LLVMBool LLVMInitializeFunctionPassManager(LLVMPassManagerRef FPM);
Gordon Henriksen878114b2008-03-16 04:20:44 +00003140
3141/** Executes all of the function passes scheduled in the function pass manager
3142 on the provided function. Returns 1 if any of the passes modified the
3143 function, false otherwise.
Gregory Szorc34c863a2012-03-21 03:54:29 +00003144 @see llvm::FunctionPassManager::run(Function&) */
Chris Lattner25963c62010-01-09 22:27:07 +00003145LLVMBool LLVMRunFunctionPassManager(LLVMPassManagerRef FPM, LLVMValueRef F);
Gordon Henriksen878114b2008-03-16 04:20:44 +00003146
3147/** Finalizes all of the function passes scheduled in in the function pass
3148 manager. Returns 1 if any of the passes modified the module, 0 otherwise.
Gregory Szorc34c863a2012-03-21 03:54:29 +00003149 @see llvm::FunctionPassManager::doFinalization */
Chris Lattner25963c62010-01-09 22:27:07 +00003150LLVMBool LLVMFinalizeFunctionPassManager(LLVMPassManagerRef FPM);
Gordon Henriksen878114b2008-03-16 04:20:44 +00003151
3152/** Frees the memory of a pass pipeline. For function pipelines, does not free
3153 the module provider.
Gregory Szorc34c863a2012-03-21 03:54:29 +00003154 @see llvm::PassManagerBase::~PassManagerBase. */
Gordon Henriksen878114b2008-03-16 04:20:44 +00003155void LLVMDisposePassManager(LLVMPassManagerRef PM);
3156
Gregory Szorc34c863a2012-03-21 03:54:29 +00003157/**
3158 * @}
3159 */
3160
3161/**
Duncan Sands1cba0a82013-02-17 16:35:51 +00003162 * @defgroup LLVMCCoreThreading Threading
3163 *
3164 * Handle the structures needed to make LLVM safe for multithreading.
3165 *
3166 * @{
3167 */
3168
Chandler Carruth39cd2162014-06-27 15:13:01 +00003169/** Deprecated: Multi-threading can only be enabled/disabled with the compile
3170 time define LLVM_ENABLE_THREADS. This function always returns
3171 LLVMIsMultithreaded(). */
Benjamin Kramer325ec892013-10-23 16:57:34 +00003172LLVMBool LLVMStartMultithreaded(void);
Duncan Sands1cba0a82013-02-17 16:35:51 +00003173
Chandler Carruth39cd2162014-06-27 15:13:01 +00003174/** Deprecated: Multi-threading can only be enabled/disabled with the compile
3175 time define LLVM_ENABLE_THREADS. */
Benjamin Kramer325ec892013-10-23 16:57:34 +00003176void LLVMStopMultithreaded(void);
Duncan Sands1cba0a82013-02-17 16:35:51 +00003177
3178/** Check whether LLVM is executing in thread-safe mode or not.
3179 @see llvm::llvm_is_multithreaded */
Benjamin Kramer325ec892013-10-23 16:57:34 +00003180LLVMBool LLVMIsMultithreaded(void);
Duncan Sands1cba0a82013-02-17 16:35:51 +00003181
3182/**
3183 * @}
3184 */
3185
3186/**
Gregory Szorc34c863a2012-03-21 03:54:29 +00003187 * @}
3188 */
3189
3190/**
3191 * @}
3192 */
Gordon Henriksen878114b2008-03-16 04:20:44 +00003193
Gordon Henriksen76a03742007-09-18 03:18:57 +00003194#ifdef __cplusplus
3195}
Eugene Zelenkoffec81c2015-11-04 22:32:32 +00003196#endif
Gordon Henriksen7330acd2007-10-05 23:59:36 +00003197
Eugene Zelenkoffec81c2015-11-04 22:32:32 +00003198#endif /* LLVM_C_CORE_H */