blob: e85fb9750503472c84f882581dd8c3ef8b908103 [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
Michael J. Spencerab425d82010-11-29 18:47:54 +000018#include "llvm/Support/DataTypes.h"
Erick Tryzelaardd991352009-08-16 23:36:46 +000019
Gordon Henriksen76a03742007-09-18 03:18:57 +000020#ifdef __cplusplus
Gordon Henriksen7330acd2007-10-05 23:59:36 +000021
22/* Need these includes to support the LLVM 'cast' template for the C++ 'wrap'
23 and 'unwrap' conversion functions. */
Chandler Carruth9fb823b2013-01-02 11:36:10 +000024#include "llvm/IR/IRBuilder.h"
25#include "llvm/IR/Module.h"
Owen Anderson4698c5d2010-10-07 17:55:47 +000026#include "llvm/PassRegistry.h"
Gordon Henriksen7330acd2007-10-05 23:59:36 +000027
Gordon Henriksen76a03742007-09-18 03:18:57 +000028extern "C" {
29#endif
30
Gregory Szorc34c863a2012-03-21 03:54:29 +000031/**
32 * @defgroup LLVMC LLVM-C: C interface to LLVM
33 *
34 * This module exposes parts of the LLVM library as a C API.
35 *
36 * @{
37 */
38
39/**
40 * @defgroup LLVMCTransforms Transforms
41 */
42
43/**
44 * @defgroup LLVMCCore Core
45 *
46 * This modules provide an interface to libLLVMCore, which implements
47 * the LLVM intermediate representation as well as other related types
48 * and utilities.
49 *
50 * LLVM uses a polymorphic type hierarchy which C cannot represent, therefore
51 * parameters must be passed as base types. Despite the declared types, most
52 * of the functions provided operate only on branches of the type hierarchy.
53 * The declared parameter names are descriptive and specify which type is
54 * required. Additionally, each type hierarchy is documented along with the
55 * functions that operate upon it. For more detail, refer to LLVM's C++ code.
Eli Bendersky870d0572012-08-10 18:26:20 +000056 * If in doubt, refer to Core.cpp, which performs parameter downcasts in the
Gregory Szorc34c863a2012-03-21 03:54:29 +000057 * form unwrap<RequiredType>(Param).
58 *
59 * Many exotic languages can interoperate with C code but have a harder time
60 * with C++ due to name mangling. So in addition to C, this interface enables
61 * tools written in such languages.
62 *
63 * When included into a C++ source file, also declares 'wrap' and 'unwrap'
64 * helpers to perform opaque reference<-->pointer conversions. These helpers
65 * are shorter and more tightly typed than writing the casts by hand when
66 * authoring bindings. In assert builds, they will do runtime type checking.
67 *
68 * @{
69 */
70
71/**
72 * @defgroup LLVMCCoreTypes Types and Enumerations
73 *
74 * @{
75 */
Gordon Henriksen76a03742007-09-18 03:18:57 +000076
Chris Lattner25963c62010-01-09 22:27:07 +000077typedef int LLVMBool;
78
Gordon Henriksen76a03742007-09-18 03:18:57 +000079/* Opaque types. */
Gordon Henriksen4a4d7352007-12-30 17:46:33 +000080
81/**
Gregory Szorc34c863a2012-03-21 03:54:29 +000082 * The top-level container for all LLVM global data. See the LLVMContext class.
Owen Anderson6773d382009-07-01 16:58:40 +000083 */
Erick Tryzelaar262332f2009-08-14 00:01:31 +000084typedef struct LLVMOpaqueContext *LLVMContextRef;
Owen Anderson6773d382009-07-01 16:58:40 +000085
86/**
Gordon Henriksen4a4d7352007-12-30 17:46:33 +000087 * The top-level container for all other LLVM Intermediate Representation (IR)
Gregory Szorc34c863a2012-03-21 03:54:29 +000088 * objects.
89 *
90 * @see llvm::Module
Gordon Henriksen4a4d7352007-12-30 17:46:33 +000091 */
Gordon Henriksen76a03742007-09-18 03:18:57 +000092typedef struct LLVMOpaqueModule *LLVMModuleRef;
Gordon Henriksen4a4d7352007-12-30 17:46:33 +000093
94/**
Gregory Szorc34c863a2012-03-21 03:54:29 +000095 * Each value in the LLVM IR has a type, an LLVMTypeRef.
96 *
97 * @see llvm::Type
Gordon Henriksen4a4d7352007-12-30 17:46:33 +000098 */
Gordon Henriksen76a03742007-09-18 03:18:57 +000099typedef struct LLVMOpaqueType *LLVMTypeRef;
Gordon Henriksen4a4d7352007-12-30 17:46:33 +0000100
Gregory Szorc34c863a2012-03-21 03:54:29 +0000101/**
102 * Represents an individual value in LLVM IR.
103 *
104 * This models llvm::Value.
105 */
Gordon Henriksen76a03742007-09-18 03:18:57 +0000106typedef struct LLVMOpaqueValue *LLVMValueRef;
Gregory Szorc34c863a2012-03-21 03:54:29 +0000107
108/**
Eli Bendersky870d0572012-08-10 18:26:20 +0000109 * Represents a basic block of instructions in LLVM IR.
Gregory Szorc34c863a2012-03-21 03:54:29 +0000110 *
111 * This models llvm::BasicBlock.
112 */
Gordon Henriksenc23b66c2007-09-26 20:56:12 +0000113typedef struct LLVMOpaqueBasicBlock *LLVMBasicBlockRef;
Gregory Szorc34c863a2012-03-21 03:54:29 +0000114
115/**
116 * Represents an LLVM basic block builder.
117 *
118 * This models llvm::IRBuilder.
119 */
Gordon Henriksenc23b66c2007-09-26 20:56:12 +0000120typedef struct LLVMOpaqueBuilder *LLVMBuilderRef;
Gordon Henriksen34eb6d82007-12-19 22:30:40 +0000121
Gregory Szorc34c863a2012-03-21 03:54:29 +0000122/**
123 * Interface used to provide a module to JIT or interpreter.
124 * This is now just a synonym for llvm::Module, but we have to keep using the
125 * different type to keep binary compatibility.
Gordon Henriksen34eb6d82007-12-19 22:30:40 +0000126 */
Gordon Henriksen0a68fe22007-12-12 01:04:30 +0000127typedef struct LLVMOpaqueModuleProvider *LLVMModuleProviderRef;
Gordon Henriksen76a03742007-09-18 03:18:57 +0000128
Gregory Szorc34c863a2012-03-21 03:54:29 +0000129/**
130 * Used to provide a module to JIT or interpreter.
131 *
132 * @see llvm::MemoryBuffer
Gordon Henriksen34eb6d82007-12-19 22:30:40 +0000133 */
134typedef struct LLVMOpaqueMemoryBuffer *LLVMMemoryBufferRef;
135
Gregory Szorc34c863a2012-03-21 03:54:29 +0000136/** @see llvm::PassManagerBase */
Gordon Henriksen878114b2008-03-16 04:20:44 +0000137typedef struct LLVMOpaquePassManager *LLVMPassManagerRef;
138
Gregory Szorc34c863a2012-03-21 03:54:29 +0000139/** @see llvm::PassRegistry */
Owen Anderson4698c5d2010-10-07 17:55:47 +0000140typedef struct LLVMOpaquePassRegistry *LLVMPassRegistryRef;
141
Gregory Szorc34c863a2012-03-21 03:54:29 +0000142/**
143 * Used to get the users and usees of a Value.
144 *
145 * @see llvm::Use */
Erick Tryzelaar9f9857e2010-03-02 20:32:28 +0000146typedef struct LLVMOpaqueUse *LLVMUseRef;
Chris Lattner40cf28d2009-10-12 04:01:02 +0000147
Gordon Henriksen76a03742007-09-18 03:18:57 +0000148typedef enum {
Devang Patel4c758ea2008-09-25 21:00:45 +0000149 LLVMZExtAttribute = 1<<0,
150 LLVMSExtAttribute = 1<<1,
151 LLVMNoReturnAttribute = 1<<2,
152 LLVMInRegAttribute = 1<<3,
153 LLVMStructRetAttribute = 1<<4,
154 LLVMNoUnwindAttribute = 1<<5,
155 LLVMNoAliasAttribute = 1<<6,
156 LLVMByValAttribute = 1<<7,
157 LLVMNestAttribute = 1<<8,
158 LLVMReadNoneAttribute = 1<<9,
Anton Korobeynikovc8ce7b082009-07-17 18:07:26 +0000159 LLVMReadOnlyAttribute = 1<<10,
Anton Korobeynikov9750be92009-07-17 18:57:16 +0000160 LLVMNoInlineAttribute = 1<<11,
161 LLVMAlwaysInlineAttribute = 1<<12,
162 LLVMOptimizeForSizeAttribute = 1<<13,
163 LLVMStackProtectAttribute = 1<<14,
164 LLVMStackProtectReqAttribute = 1<<15,
Erick Tryzelaar8f69fea2010-03-03 23:51:25 +0000165 LLVMAlignment = 31<<16,
Anton Korobeynikov9750be92009-07-17 18:57:16 +0000166 LLVMNoCaptureAttribute = 1<<21,
167 LLVMNoRedZoneAttribute = 1<<22,
168 LLVMNoImplicitFloatAttribute = 1<<23,
Jakob Stoklund Olesen74bb06c2010-02-06 01:16:28 +0000169 LLVMNakedAttribute = 1<<24,
Erick Tryzelaar8f69fea2010-03-03 23:51:25 +0000170 LLVMInlineHintAttribute = 1<<25,
Torok Edwin1db48c02011-10-06 12:13:32 +0000171 LLVMStackAlignment = 7<<26,
172 LLVMReturnsTwice = 1 << 29,
173 LLVMUWTable = 1 << 30,
Chandler Carruth44d69d92012-01-25 07:40:15 +0000174 LLVMNonLazyBind = 1 << 31
175
Bill Wendlingd154e2832013-01-23 06:41:41 +0000176 /* FIXME: These attributes are currently not included in the C API as
Nuno Lopesdef4229972012-09-02 14:19:21 +0000177 a temporary measure until the API/ABI impact to the C API is understood
178 and the path forward agreed upon.
Bill Wendlingd154e2832013-01-23 06:41:41 +0000179 LLVMAddressSafety = 1ULL << 32,
180 LLVMStackProtectStrongAttribute = 1ULL<<33
Nuno Lopesdef4229972012-09-02 14:19:21 +0000181 */
Devang Patel4c758ea2008-09-25 21:00:45 +0000182} LLVMAttribute;
Gordon Henriksen2d9cc212008-04-28 17:37:06 +0000183
184typedef enum {
Bill Wendlingda52cec2010-02-15 20:53:17 +0000185 /* Terminator Instructions */
Chris Lattner40cf28d2009-10-12 04:01:02 +0000186 LLVMRet = 1,
187 LLVMBr = 2,
188 LLVMSwitch = 3,
Bill Wendling07d6d762010-02-15 20:50:51 +0000189 LLVMIndirectBr = 4,
190 LLVMInvoke = 5,
Bill Wendling46ffaa92011-08-02 06:20:17 +0000191 /* removed 6 due to API changes */
Bill Wendling2641d132011-07-27 21:00:28 +0000192 LLVMUnreachable = 7,
Bill Wendling07d6d762010-02-15 20:50:51 +0000193
Bill Wendlingda52cec2010-02-15 20:53:17 +0000194 /* Standard Binary Operators */
Bill Wendling2641d132011-07-27 21:00:28 +0000195 LLVMAdd = 8,
196 LLVMFAdd = 9,
197 LLVMSub = 10,
198 LLVMFSub = 11,
199 LLVMMul = 12,
200 LLVMFMul = 13,
201 LLVMUDiv = 14,
202 LLVMSDiv = 15,
203 LLVMFDiv = 16,
204 LLVMURem = 17,
205 LLVMSRem = 18,
206 LLVMFRem = 19,
Bill Wendling07d6d762010-02-15 20:50:51 +0000207
Bill Wendlingda52cec2010-02-15 20:53:17 +0000208 /* Logical Operators */
Bill Wendling2641d132011-07-27 21:00:28 +0000209 LLVMShl = 20,
210 LLVMLShr = 21,
211 LLVMAShr = 22,
212 LLVMAnd = 23,
213 LLVMOr = 24,
214 LLVMXor = 25,
Bill Wendling07d6d762010-02-15 20:50:51 +0000215
Bill Wendlingda52cec2010-02-15 20:53:17 +0000216 /* Memory Operators */
Bill Wendling2641d132011-07-27 21:00:28 +0000217 LLVMAlloca = 26,
218 LLVMLoad = 27,
219 LLVMStore = 28,
220 LLVMGetElementPtr = 29,
Bill Wendling07d6d762010-02-15 20:50:51 +0000221
Bill Wendlingda52cec2010-02-15 20:53:17 +0000222 /* Cast Operators */
Bill Wendling2641d132011-07-27 21:00:28 +0000223 LLVMTrunc = 30,
224 LLVMZExt = 31,
225 LLVMSExt = 32,
226 LLVMFPToUI = 33,
227 LLVMFPToSI = 34,
228 LLVMUIToFP = 35,
229 LLVMSIToFP = 36,
230 LLVMFPTrunc = 37,
231 LLVMFPExt = 38,
232 LLVMPtrToInt = 39,
233 LLVMIntToPtr = 40,
234 LLVMBitCast = 41,
Bill Wendling07d6d762010-02-15 20:50:51 +0000235
Bill Wendlingda52cec2010-02-15 20:53:17 +0000236 /* Other Operators */
Bill Wendling2641d132011-07-27 21:00:28 +0000237 LLVMICmp = 42,
238 LLVMFCmp = 43,
239 LLVMPHI = 44,
240 LLVMCall = 45,
241 LLVMSelect = 46,
Torok Edwin05dc9d62011-10-06 12:39:34 +0000242 LLVMUserOp1 = 47,
243 LLVMUserOp2 = 48,
Bill Wendling2641d132011-07-27 21:00:28 +0000244 LLVMVAArg = 49,
245 LLVMExtractElement = 50,
246 LLVMInsertElement = 51,
247 LLVMShuffleVector = 52,
248 LLVMExtractValue = 53,
249 LLVMInsertValue = 54,
Eli Friedman4fc946c2011-07-27 18:59:19 +0000250
251 /* Atomic operators */
Bill Wendling2641d132011-07-27 21:00:28 +0000252 LLVMFence = 55,
Eli Friedmanc9a551e2011-07-28 21:48:00 +0000253 LLVMAtomicCmpXchg = 56,
Bill Wendlingf891bf82011-07-31 06:30:59 +0000254 LLVMAtomicRMW = 57,
255
256 /* Exception Handling Operators */
Bill Wendlingfae14752011-08-12 20:24:12 +0000257 LLVMResume = 58,
Bill Wendling0aef16a2012-02-06 21:44:22 +0000258 LLVMLandingPad = 59
Bill Wendling2641d132011-07-27 21:00:28 +0000259
Chris Lattner40cf28d2009-10-12 04:01:02 +0000260} LLVMOpcode;
261
262typedef enum {
Gordon Henriksen4a4d7352007-12-30 17:46:33 +0000263 LLVMVoidTypeKind, /**< type with no size */
Dan Gohman518cda42011-12-17 00:04:22 +0000264 LLVMHalfTypeKind, /**< 16 bit floating point type */
Gordon Henriksen4a4d7352007-12-30 17:46:33 +0000265 LLVMFloatTypeKind, /**< 32 bit floating point type */
266 LLVMDoubleTypeKind, /**< 64 bit floating point type */
267 LLVMX86_FP80TypeKind, /**< 80 bit floating point type (X87) */
268 LLVMFP128TypeKind, /**< 128 bit floating point type (112-bit mantissa)*/
269 LLVMPPC_FP128TypeKind, /**< 128 bit floating point type (two 64-bits) */
270 LLVMLabelTypeKind, /**< Labels */
271 LLVMIntegerTypeKind, /**< Arbitrary bit width integers */
272 LLVMFunctionTypeKind, /**< Functions */
273 LLVMStructTypeKind, /**< Structures */
274 LLVMArrayTypeKind, /**< Arrays */
275 LLVMPointerTypeKind, /**< Pointers */
Chris Lattnerdac44ec2009-07-15 22:00:31 +0000276 LLVMVectorTypeKind, /**< SIMD 'packed' format, or other vector type */
Dale Johannesenbaa5d042010-09-10 20:55:01 +0000277 LLVMMetadataTypeKind, /**< Metadata */
278 LLVMX86_MMXTypeKind /**< X86 MMX */
Gordon Henriksen76a03742007-09-18 03:18:57 +0000279} LLVMTypeKind;
280
281typedef enum {
Gordon Henriksen4a4d7352007-12-30 17:46:33 +0000282 LLVMExternalLinkage, /**< Externally visible function */
Chris Lattner2dba0f02009-04-13 06:25:37 +0000283 LLVMAvailableExternallyLinkage,
Duncan Sands12da8ce2009-03-07 15:45:40 +0000284 LLVMLinkOnceAnyLinkage, /**< Keep one copy of function when linking (inline)*/
285 LLVMLinkOnceODRLinkage, /**< Same, but only replaced by something
286 equivalent. */
Bill Wendling34bc34e2012-08-17 18:33:14 +0000287 LLVMLinkOnceODRAutoHideLinkage, /**< Like LinkOnceODR, but possibly hidden. */
Duncan Sands12da8ce2009-03-07 15:45:40 +0000288 LLVMWeakAnyLinkage, /**< Keep one copy of function when linking (weak) */
289 LLVMWeakODRLinkage, /**< Same, but only replaced by something
290 equivalent. */
Gordon Henriksen4a4d7352007-12-30 17:46:33 +0000291 LLVMAppendingLinkage, /**< Special purpose, only applies to global arrays */
292 LLVMInternalLinkage, /**< Rename collisions when linking (static
293 functions) */
Duncan Sands12da8ce2009-03-07 15:45:40 +0000294 LLVMPrivateLinkage, /**< Like Internal, but omit from symbol table */
Gordon Henriksen4a4d7352007-12-30 17:46:33 +0000295 LLVMDLLImportLinkage, /**< Function to be imported from DLL */
296 LLVMDLLExportLinkage, /**< Function to be accessible from DLL */
Duncan Sandse2881052009-03-11 08:08:06 +0000297 LLVMExternalWeakLinkage,/**< ExternalWeak linkage description */
Jeffrey Yasskin091217b2010-01-27 20:34:15 +0000298 LLVMGhostLinkage, /**< Obsolete */
Bill Wendling002b1672009-07-20 18:22:52 +0000299 LLVMCommonLinkage, /**< Tentative definitions */
Bill Wendling03bcd6e2010-07-01 21:55:59 +0000300 LLVMLinkerPrivateLinkage, /**< Like Private, but linker removes. */
Bill Wendling34bc34e2012-08-17 18:33:14 +0000301 LLVMLinkerPrivateWeakLinkage /**< Like LinkerPrivate, but is weak. */
Gordon Henriksen76a03742007-09-18 03:18:57 +0000302} LLVMLinkage;
303
304typedef enum {
Gordon Henriksen4a4d7352007-12-30 17:46:33 +0000305 LLVMDefaultVisibility, /**< The GV is visible */
306 LLVMHiddenVisibility, /**< The GV is hidden */
307 LLVMProtectedVisibility /**< The GV is protected */
Gordon Henriksen76a03742007-09-18 03:18:57 +0000308} LLVMVisibility;
309
Gordon Henriksenc23b66c2007-09-26 20:56:12 +0000310typedef enum {
311 LLVMCCallConv = 0,
312 LLVMFastCallConv = 8,
313 LLVMColdCallConv = 9,
314 LLVMX86StdcallCallConv = 64,
315 LLVMX86FastcallCallConv = 65
316} LLVMCallConv;
317
318typedef enum {
Gordon Henriksen4a4d7352007-12-30 17:46:33 +0000319 LLVMIntEQ = 32, /**< equal */
320 LLVMIntNE, /**< not equal */
321 LLVMIntUGT, /**< unsigned greater than */
322 LLVMIntUGE, /**< unsigned greater or equal */
323 LLVMIntULT, /**< unsigned less than */
324 LLVMIntULE, /**< unsigned less or equal */
325 LLVMIntSGT, /**< signed greater than */
326 LLVMIntSGE, /**< signed greater or equal */
327 LLVMIntSLT, /**< signed less than */
328 LLVMIntSLE /**< signed less or equal */
Gordon Henriksenc23b66c2007-09-26 20:56:12 +0000329} LLVMIntPredicate;
330
331typedef enum {
Gordon Henriksen4a4d7352007-12-30 17:46:33 +0000332 LLVMRealPredicateFalse, /**< Always false (always folded) */
333 LLVMRealOEQ, /**< True if ordered and equal */
334 LLVMRealOGT, /**< True if ordered and greater than */
335 LLVMRealOGE, /**< True if ordered and greater than or equal */
336 LLVMRealOLT, /**< True if ordered and less than */
337 LLVMRealOLE, /**< True if ordered and less than or equal */
338 LLVMRealONE, /**< True if ordered and operands are unequal */
339 LLVMRealORD, /**< True if ordered (no nans) */
340 LLVMRealUNO, /**< True if unordered: isnan(X) | isnan(Y) */
341 LLVMRealUEQ, /**< True if unordered or equal */
342 LLVMRealUGT, /**< True if unordered or greater than */
343 LLVMRealUGE, /**< True if unordered, greater than, or equal */
344 LLVMRealULT, /**< True if unordered or less than */
345 LLVMRealULE, /**< True if unordered, less than, or equal */
346 LLVMRealUNE, /**< True if unordered or not equal */
347 LLVMRealPredicateTrue /**< Always true (always folded) */
Gordon Henriksenc23b66c2007-09-26 20:56:12 +0000348} LLVMRealPredicate;
349
Bill Wendlingfae14752011-08-12 20:24:12 +0000350typedef enum {
351 LLVMLandingPadCatch, /**< A catch clause */
352 LLVMLandingPadFilter /**< A filter clause */
353} LLVMLandingPadClauseTy;
354
Gregory Szorc34c863a2012-03-21 03:54:29 +0000355/**
356 * @}
357 */
358
Nick Lewycky0db26542011-05-15 07:20:34 +0000359void LLVMInitializeCore(LLVMPassRegistryRef R);
360
Duncan Sands1cba0a82013-02-17 16:35:51 +0000361/** Deallocate and destroy all ManagedStatic variables.
362 @see llvm::llvm_shutdown
363 @see ManagedStatic */
364void LLVMShutdown();
365
Gordon Henriksen76a03742007-09-18 03:18:57 +0000366
Gordon Henriksen34eb6d82007-12-19 22:30:40 +0000367/*===-- Error handling ----------------------------------------------------===*/
368
369void LLVMDisposeMessage(char *Message);
370
371
Gregory Szorc34c863a2012-03-21 03:54:29 +0000372/**
373 * @defgroup LLVMCCoreContext Contexts
374 *
375 * Contexts are execution states for the core LLVM IR system.
376 *
377 * Most types are tied to a context instance. Multiple contexts can
378 * exist simultaneously. A single context is not thread safe. However,
379 * different contexts can execute on different threads simultaneously.
380 *
381 * @{
382 */
Gordon Henriksen76a03742007-09-18 03:18:57 +0000383
Gregory Szorc34c863a2012-03-21 03:54:29 +0000384/**
385 * Create a new context.
386 *
387 * Every call to this function should be paired with a call to
388 * LLVMContextDispose() or the context will leak memory.
389 */
Erick Tryzelaarf34cb0c2009-08-30 23:38:06 +0000390LLVMContextRef LLVMContextCreate(void);
Gregory Szorc34c863a2012-03-21 03:54:29 +0000391
392/**
393 * Obtain the global context instance.
394 */
Erick Tryzelaarf34cb0c2009-08-30 23:38:06 +0000395LLVMContextRef LLVMGetGlobalContext(void);
Gregory Szorc34c863a2012-03-21 03:54:29 +0000396
397/**
398 * Destroy a context instance.
399 *
400 * This should be called for every call to LLVMContextCreate() or memory
401 * will be leaked.
402 */
Owen Anderson6773d382009-07-01 16:58:40 +0000403void LLVMContextDispose(LLVMContextRef C);
404
Erick Tryzelaard8531fa2010-02-28 09:45:59 +0000405unsigned LLVMGetMDKindIDInContext(LLVMContextRef C, const char* Name,
406 unsigned SLen);
407unsigned LLVMGetMDKindID(const char* Name, unsigned SLen);
408
Gregory Szorc34c863a2012-03-21 03:54:29 +0000409/**
410 * @}
411 */
412
Gregory Szorc52d26602012-03-21 07:28:27 +0000413/**
414 * @defgroup LLVMCCoreModule Modules
Gregory Szorc34c863a2012-03-21 03:54:29 +0000415 *
416 * Modules represent the top-level structure in a LLVM program. An LLVM
417 * module is effectively a translation unit or a collection of
418 * translation units merged together.
419 *
420 * @{
421 */
422
Gregory Szorc34c863a2012-03-21 03:54:29 +0000423/**
424 * Create a new, empty module in the global context.
425 *
426 * This is equivalent to calling LLVMModuleCreateWithNameInContext with
427 * LLVMGetGlobalContext() as the context parameter.
428 *
429 * Every invocation should be paired with LLVMDisposeModule() or memory
430 * will be leaked.
431 */
Gordon Henriksen76a03742007-09-18 03:18:57 +0000432LLVMModuleRef LLVMModuleCreateWithName(const char *ModuleID);
Gregory Szorc34c863a2012-03-21 03:54:29 +0000433
434/**
435 * Create a new, empty module in a specific context.
436 *
437 * Every invocation should be paired with LLVMDisposeModule() or memory
438 * will be leaked.
439 */
Owen Anderson31d44e42009-07-02 07:17:57 +0000440LLVMModuleRef LLVMModuleCreateWithNameInContext(const char *ModuleID,
441 LLVMContextRef C);
Gordon Henriksena49d4352008-03-07 19:13:06 +0000442
Gregory Szorc34c863a2012-03-21 03:54:29 +0000443/**
444 * Destroy a module instance.
445 *
446 * This must be called for every created module or memory will be
447 * leaked.
448 */
Gordon Henriksen76a03742007-09-18 03:18:57 +0000449void LLVMDisposeModule(LLVMModuleRef M);
450
Gregory Szorc34c863a2012-03-21 03:54:29 +0000451/**
452 * Obtain the data layout for a module.
453 *
454 * @see Module::getDataLayout()
455 */
Gordon Henriksen05568bb2007-12-27 20:13:47 +0000456const char *LLVMGetDataLayout(LLVMModuleRef M);
Gregory Szorc34c863a2012-03-21 03:54:29 +0000457
458/**
459 * Set the data layout for a module.
460 *
461 * @see Module::setDataLayout()
462 */
Gordon Henriksen05568bb2007-12-27 20:13:47 +0000463void LLVMSetDataLayout(LLVMModuleRef M, const char *Triple);
464
Gregory Szorc34c863a2012-03-21 03:54:29 +0000465/**
466 * Obtain the target triple for a module.
467 *
468 * @see Module::getTargetTriple()
469 */
Gordon Henriksen05568bb2007-12-27 20:13:47 +0000470const char *LLVMGetTarget(LLVMModuleRef M);
Gregory Szorc34c863a2012-03-21 03:54:29 +0000471
472/**
473 * Set the target triple for a module.
474 *
475 * @see Module::setTargetTriple()
476 */
Gordon Henriksen05568bb2007-12-27 20:13:47 +0000477void LLVMSetTarget(LLVMModuleRef M, const char *Triple);
478
Gregory Szorc34c863a2012-03-21 03:54:29 +0000479/**
480 * Dump a representation of a module to stderr.
481 *
482 * @see Module::dump()
483 */
Gordon Henriksen6c6075e2008-03-14 23:58:56 +0000484void LLVMDumpModule(LLVMModuleRef M);
485
Gregory Szorc34c863a2012-03-21 03:54:29 +0000486/**
Hans Wennborgb7ef2fe2012-05-09 16:54:17 +0000487 * Print a representation of a module to a file. The ErrorMessage needs to be
488 * disposed with LLVMDisposeMessage. Returns 0 on success, 1 otherwise.
489 *
490 * @see Module::print()
491 */
492LLVMBool LLVMPrintModuleToFile(LLVMModuleRef M, const char *Filename,
493 char **ErrorMessage);
494
495/**
Gregory Szorc34c863a2012-03-21 03:54:29 +0000496 * Set inline assembly for a module.
497 *
498 * @see Module::setModuleInlineAsm()
499 */
Chris Lattner26941452010-04-10 17:52:58 +0000500void LLVMSetModuleInlineAsm(LLVMModuleRef M, const char *Asm);
Gordon Henriksen76a03742007-09-18 03:18:57 +0000501
Gregory Szorc34c863a2012-03-21 03:54:29 +0000502/**
503 * Obtain the context to which this module is associated.
504 *
505 * @see Module::getContext()
506 */
Chris Lattnera7e04b02010-11-28 20:03:44 +0000507LLVMContextRef LLVMGetModuleContext(LLVMModuleRef M);
508
Gregory Szorc34c863a2012-03-21 03:54:29 +0000509/**
510 * Obtain a Type from a module by its registered name.
511 */
512LLVMTypeRef LLVMGetTypeByName(LLVMModuleRef M, const char *Name);
Gordon Henriksen76a03742007-09-18 03:18:57 +0000513
Gregory Szorc34c863a2012-03-21 03:54:29 +0000514/**
515 * Obtain the number of operands for named metadata in a module.
516 *
517 * @see llvm::Module::getNamedMetadata()
518 */
519unsigned LLVMGetNamedMetadataNumOperands(LLVMModuleRef M, const char* name);
520
521/**
522 * Obtain the named metadata operands for a module.
523 *
524 * The passed LLVMValueRef pointer should refer to an array of
525 * LLVMValueRef at least LLVMGetNamedMetadataNumOperands long. This
526 * array will be populated with the LLVMValueRef instances. Each
527 * instance corresponds to a llvm::MDNode.
528 *
529 * @see llvm::Module::getNamedMetadata()
530 * @see llvm::MDNode::getOperand()
531 */
532void LLVMGetNamedMetadataOperands(LLVMModuleRef M, const char* name, LLVMValueRef *Dest);
533
534/**
535 * Add an operand to named metadata.
536 *
537 * @see llvm::Module::getNamedMetadata()
538 * @see llvm::MDNode::addOperand()
539 */
540void LLVMAddNamedMetadataOperand(LLVMModuleRef M, const char* name,
541 LLVMValueRef Val);
542
Gregory Szorc52d26602012-03-21 07:28:27 +0000543/**
544 * Add a function to a module under a specified name.
545 *
546 * @see llvm::Function::Create()
547 */
548LLVMValueRef LLVMAddFunction(LLVMModuleRef M, const char *Name,
549 LLVMTypeRef FunctionTy);
550
551/**
552 * Obtain a Function value from a Module by its name.
553 *
554 * The returned value corresponds to a llvm::Function value.
555 *
556 * @see llvm::Module::getFunction()
557 */
558LLVMValueRef LLVMGetNamedFunction(LLVMModuleRef M, const char *Name);
559
560/**
561 * Obtain an iterator to the first Function in a Module.
562 *
563 * @see llvm::Module::begin()
564 */
565LLVMValueRef LLVMGetFirstFunction(LLVMModuleRef M);
566
567/**
568 * Obtain an iterator to the last Function in a Module.
569 *
570 * @see llvm::Module::end()
571 */
572LLVMValueRef LLVMGetLastFunction(LLVMModuleRef M);
573
574/**
575 * Advance a Function iterator to the next Function.
576 *
577 * Returns NULL if the iterator was already at the end and there are no more
578 * functions.
579 */
580LLVMValueRef LLVMGetNextFunction(LLVMValueRef Fn);
581
582/**
583 * Decrement a Function iterator to the previous Function.
584 *
585 * Returns NULL if the iterator was already at the beginning and there are
586 * no previous functions.
587 */
588LLVMValueRef LLVMGetPreviousFunction(LLVMValueRef Fn);
Gregory Szorc34c863a2012-03-21 03:54:29 +0000589
590/**
591 * @}
592 */
593
594/**
595 * @defgroup LLVMCCoreType Types
596 *
597 * Types represent the type of a value.
598 *
599 * Types are associated with a context instance. The context internally
600 * deduplicates types so there is only 1 instance of a specific type
601 * alive at a time. In other words, a unique type is shared among all
602 * consumers within a context.
603 *
604 * A Type in the C API corresponds to llvm::Type.
605 *
606 * Types have the following hierarchy:
607 *
Gordon Henriksen76a03742007-09-18 03:18:57 +0000608 * types:
609 * integer type
610 * real type
611 * function type
612 * sequence types:
613 * array type
614 * pointer type
615 * vector type
616 * void type
617 * label type
618 * opaque type
Gregory Szorc34c863a2012-03-21 03:54:29 +0000619 *
620 * @{
Gordon Henriksen76a03742007-09-18 03:18:57 +0000621 */
622
Gregory Szorc34c863a2012-03-21 03:54:29 +0000623/**
624 * Obtain the enumerated type of a Type instance.
625 *
626 * @see llvm::Type:getTypeID()
627 */
Gordon Henriksen76a03742007-09-18 03:18:57 +0000628LLVMTypeKind LLVMGetTypeKind(LLVMTypeRef Ty);
Gregory Szorc34c863a2012-03-21 03:54:29 +0000629
630/**
631 * Whether the type has a known size.
632 *
633 * Things that don't have a size are abstract types, labels, and void.a
634 *
635 * @see llvm::Type::isSized()
636 */
Torok Edwin1cd9ade2011-10-06 12:13:28 +0000637LLVMBool LLVMTypeIsSized(LLVMTypeRef Ty);
Gordon Henriksena49d4352008-03-07 19:13:06 +0000638
Gregory Szorc34c863a2012-03-21 03:54:29 +0000639/**
640 * Obtain the context to which this type instance is associated.
641 *
642 * @see llvm::Type::getContext()
643 */
Erick Tryzelaar262332f2009-08-14 00:01:31 +0000644LLVMContextRef LLVMGetTypeContext(LLVMTypeRef Ty);
645
Gregory Szorc34c863a2012-03-21 03:54:29 +0000646/**
647 * @defgroup LLVMCCoreTypeInt Integer Types
648 *
649 * Functions in this section operate on integer types.
650 *
651 * @{
652 */
653
654/**
655 * Obtain an integer type from a context with specified bit width.
656 */
Erick Tryzelaar262332f2009-08-14 00:01:31 +0000657LLVMTypeRef LLVMInt1TypeInContext(LLVMContextRef C);
658LLVMTypeRef LLVMInt8TypeInContext(LLVMContextRef C);
659LLVMTypeRef LLVMInt16TypeInContext(LLVMContextRef C);
660LLVMTypeRef LLVMInt32TypeInContext(LLVMContextRef C);
661LLVMTypeRef LLVMInt64TypeInContext(LLVMContextRef C);
662LLVMTypeRef LLVMIntTypeInContext(LLVMContextRef C, unsigned NumBits);
663
Gregory Szorc34c863a2012-03-21 03:54:29 +0000664/**
665 * Obtain an integer type from the global context with a specified bit
666 * width.
667 */
Gordon Henriksena735a9c2008-05-04 12:55:34 +0000668LLVMTypeRef LLVMInt1Type(void);
669LLVMTypeRef LLVMInt8Type(void);
670LLVMTypeRef LLVMInt16Type(void);
671LLVMTypeRef LLVMInt32Type(void);
672LLVMTypeRef LLVMInt64Type(void);
Gordon Henriksened7beaa2007-10-06 16:05:20 +0000673LLVMTypeRef LLVMIntType(unsigned NumBits);
Gordon Henriksenc23b66c2007-09-26 20:56:12 +0000674unsigned LLVMGetIntTypeWidth(LLVMTypeRef IntegerTy);
Gordon Henriksen76a03742007-09-18 03:18:57 +0000675
Gregory Szorc34c863a2012-03-21 03:54:29 +0000676/**
677 * @}
678 */
679
680/**
681 * @defgroup LLVMCCoreTypeFloat Floating Point Types
682 *
683 * @{
684 */
685
686/**
687 * Obtain a 16-bit floating point type from a context.
688 */
Dan Gohman518cda42011-12-17 00:04:22 +0000689LLVMTypeRef LLVMHalfTypeInContext(LLVMContextRef C);
Gregory Szorc34c863a2012-03-21 03:54:29 +0000690
691/**
692 * Obtain a 32-bit floating point type from a context.
693 */
Erick Tryzelaar262332f2009-08-14 00:01:31 +0000694LLVMTypeRef LLVMFloatTypeInContext(LLVMContextRef C);
Gregory Szorc34c863a2012-03-21 03:54:29 +0000695
696/**
697 * Obtain a 64-bit floating point type from a context.
698 */
Erick Tryzelaar262332f2009-08-14 00:01:31 +0000699LLVMTypeRef LLVMDoubleTypeInContext(LLVMContextRef C);
Gregory Szorc34c863a2012-03-21 03:54:29 +0000700
701/**
702 * Obtain a 80-bit floating point type (X87) from a context.
703 */
Erick Tryzelaar262332f2009-08-14 00:01:31 +0000704LLVMTypeRef LLVMX86FP80TypeInContext(LLVMContextRef C);
Gregory Szorc34c863a2012-03-21 03:54:29 +0000705
706/**
707 * Obtain a 128-bit floating point type (112-bit mantissa) from a
708 * context.
709 */
Erick Tryzelaar262332f2009-08-14 00:01:31 +0000710LLVMTypeRef LLVMFP128TypeInContext(LLVMContextRef C);
Gregory Szorc34c863a2012-03-21 03:54:29 +0000711
712/**
713 * Obtain a 128-bit floating point type (two 64-bits) from a context.
714 */
Erick Tryzelaar262332f2009-08-14 00:01:31 +0000715LLVMTypeRef LLVMPPCFP128TypeInContext(LLVMContextRef C);
716
Gregory Szorc34c863a2012-03-21 03:54:29 +0000717/**
718 * Obtain a floating point type from the global context.
719 *
720 * These map to the functions in this group of the same name.
721 */
Dan Gohman518cda42011-12-17 00:04:22 +0000722LLVMTypeRef LLVMHalfType(void);
Gordon Henriksena735a9c2008-05-04 12:55:34 +0000723LLVMTypeRef LLVMFloatType(void);
724LLVMTypeRef LLVMDoubleType(void);
725LLVMTypeRef LLVMX86FP80Type(void);
726LLVMTypeRef LLVMFP128Type(void);
727LLVMTypeRef LLVMPPCFP128Type(void);
Gordon Henriksen76a03742007-09-18 03:18:57 +0000728
Gregory Szorc34c863a2012-03-21 03:54:29 +0000729/**
730 * @}
731 */
732
733/**
734 * @defgroup LLVMCCoreTypeFunction Function Types
735 *
736 * @{
737 */
738
739/**
740 * Obtain a function type consisting of a specified signature.
741 *
742 * The function is defined as a tuple of a return Type, a list of
743 * parameter types, and whether the function is variadic.
744 */
Gordon Henriksened7beaa2007-10-06 16:05:20 +0000745LLVMTypeRef LLVMFunctionType(LLVMTypeRef ReturnType,
746 LLVMTypeRef *ParamTypes, unsigned ParamCount,
Chris Lattner25963c62010-01-09 22:27:07 +0000747 LLVMBool IsVarArg);
Gregory Szorc34c863a2012-03-21 03:54:29 +0000748
749/**
750 * Returns whether a function type is variadic.
751 */
Chris Lattner25963c62010-01-09 22:27:07 +0000752LLVMBool LLVMIsFunctionVarArg(LLVMTypeRef FunctionTy);
Gregory Szorc34c863a2012-03-21 03:54:29 +0000753
754/**
755 * Obtain the Type this function Type returns.
756 */
Gordon Henriksenc23b66c2007-09-26 20:56:12 +0000757LLVMTypeRef LLVMGetReturnType(LLVMTypeRef FunctionTy);
Gregory Szorc34c863a2012-03-21 03:54:29 +0000758
759/**
760 * Obtain the number of parameters this function accepts.
761 */
Gordon Henriksenc23b66c2007-09-26 20:56:12 +0000762unsigned LLVMCountParamTypes(LLVMTypeRef FunctionTy);
Gregory Szorc34c863a2012-03-21 03:54:29 +0000763
764/**
765 * Obtain the types of a function's parameters.
766 *
767 * The Dest parameter should point to a pre-allocated array of
768 * LLVMTypeRef at least LLVMCountParamTypes() large. On return, the
769 * first LLVMCountParamTypes() entries in the array will be populated
770 * with LLVMTypeRef instances.
771 *
772 * @param FunctionTy The function type to operate on.
773 * @param Dest Memory address of an array to be filled with result.
774 */
Gordon Henriksenc23b66c2007-09-26 20:56:12 +0000775void LLVMGetParamTypes(LLVMTypeRef FunctionTy, LLVMTypeRef *Dest);
Gordon Henriksen76a03742007-09-18 03:18:57 +0000776
Gregory Szorc34c863a2012-03-21 03:54:29 +0000777/**
778 * @}
779 */
780
781/**
782 * @defgroup LLVMCCoreTypeStruct Structure Types
783 *
784 * These functions relate to LLVMTypeRef instances.
785 *
786 * @see llvm::StructType
787 *
788 * @{
789 */
790
791/**
792 * Create a new structure type in a context.
793 *
794 * A structure is specified by a list of inner elements/types and
795 * whether these can be packed together.
796 *
797 * @see llvm::StructType::create()
798 */
Erick Tryzelaar262332f2009-08-14 00:01:31 +0000799LLVMTypeRef LLVMStructTypeInContext(LLVMContextRef C, LLVMTypeRef *ElementTypes,
Chris Lattner25963c62010-01-09 22:27:07 +0000800 unsigned ElementCount, LLVMBool Packed);
Gregory Szorc34c863a2012-03-21 03:54:29 +0000801
802/**
803 * Create a new structure type in the global context.
804 *
805 * @see llvm::StructType::create()
806 */
Gordon Henriksened7beaa2007-10-06 16:05:20 +0000807LLVMTypeRef LLVMStructType(LLVMTypeRef *ElementTypes, unsigned ElementCount,
Chris Lattner25963c62010-01-09 22:27:07 +0000808 LLVMBool Packed);
Gregory Szorc34c863a2012-03-21 03:54:29 +0000809
810/**
811 * Create an empty structure in a context having a specified name.
812 *
813 * @see llvm::StructType::create()
814 */
Chris Lattnere71ccde2011-07-14 05:53:17 +0000815LLVMTypeRef LLVMStructCreateNamed(LLVMContextRef C, const char *Name);
Gregory Szorc34c863a2012-03-21 03:54:29 +0000816
817/**
818 * Obtain the name of a structure.
819 *
820 * @see llvm::StructType::getName()
821 */
Torok Edwin0d5f6ae2011-10-06 12:12:50 +0000822const char *LLVMGetStructName(LLVMTypeRef Ty);
Gregory Szorc34c863a2012-03-21 03:54:29 +0000823
824/**
825 * Set the contents of a structure type.
826 *
827 * @see llvm::StructType::setBody()
828 */
Chris Lattnere71ccde2011-07-14 05:53:17 +0000829void LLVMStructSetBody(LLVMTypeRef StructTy, LLVMTypeRef *ElementTypes,
830 unsigned ElementCount, LLVMBool Packed);
831
Gregory Szorc34c863a2012-03-21 03:54:29 +0000832/**
833 * Get the number of elements defined inside the structure.
834 *
835 * @see llvm::StructType::getNumElements()
836 */
Gordon Henriksenc23b66c2007-09-26 20:56:12 +0000837unsigned LLVMCountStructElementTypes(LLVMTypeRef StructTy);
Gregory Szorc34c863a2012-03-21 03:54:29 +0000838
839/**
840 * Get the elements within a structure.
841 *
842 * The function is passed the address of a pre-allocated array of
843 * LLVMTypeRef at least LLVMCountStructElementTypes() long. After
844 * invocation, this array will be populated with the structure's
845 * elements. The objects in the destination array will have a lifetime
846 * of the structure type itself, which is the lifetime of the context it
847 * is contained in.
848 */
Gordon Henriksen76a03742007-09-18 03:18:57 +0000849void LLVMGetStructElementTypes(LLVMTypeRef StructTy, LLVMTypeRef *Dest);
Gregory Szorc34c863a2012-03-21 03:54:29 +0000850
851/**
852 * Determine whether a structure is packed.
853 *
854 * @see llvm::StructType::isPacked()
855 */
Chris Lattner25963c62010-01-09 22:27:07 +0000856LLVMBool LLVMIsPackedStruct(LLVMTypeRef StructTy);
Gregory Szorc34c863a2012-03-21 03:54:29 +0000857
858/**
859 * Determine whether a structure is opaque.
860 *
861 * @see llvm::StructType::isOpaque()
862 */
Chris Lattner17cf05b2011-07-14 16:20:28 +0000863LLVMBool LLVMIsOpaqueStruct(LLVMTypeRef StructTy);
864
Gregory Szorc34c863a2012-03-21 03:54:29 +0000865/**
866 * @}
867 */
Gordon Henriksen76a03742007-09-18 03:18:57 +0000868
Gregory Szorc34c863a2012-03-21 03:54:29 +0000869
870/**
871 * @defgroup LLVMCCoreTypeSequential Sequential Types
872 *
873 * Sequential types represents "arrays" of types. This is a super class
874 * for array, vector, and pointer types.
875 *
876 * @{
877 */
878
879/**
880 * Obtain the type of elements within a sequential type.
881 *
882 * This works on array, vector, and pointer types.
883 *
884 * @see llvm::SequentialType::getElementType()
885 */
886LLVMTypeRef LLVMGetElementType(LLVMTypeRef Ty);
887
888/**
889 * Create a fixed size array type that refers to a specific type.
890 *
891 * The created type will exist in the context that its element type
892 * exists in.
893 *
894 * @see llvm::ArrayType::get()
895 */
Gordon Henriksened7beaa2007-10-06 16:05:20 +0000896LLVMTypeRef LLVMArrayType(LLVMTypeRef ElementType, unsigned ElementCount);
Gregory Szorc34c863a2012-03-21 03:54:29 +0000897
898/**
899 * Obtain the length of an array type.
900 *
901 * This only works on types that represent arrays.
902 *
903 * @see llvm::ArrayType::getNumElements()
904 */
905unsigned LLVMGetArrayLength(LLVMTypeRef ArrayTy);
906
907/**
908 * Create a pointer type that points to a defined type.
909 *
910 * The created type will exist in the context that its pointee type
911 * exists in.
912 *
913 * @see llvm::PointerType::get()
914 */
Gordon Henriksen5a3fe032007-12-17 16:08:32 +0000915LLVMTypeRef LLVMPointerType(LLVMTypeRef ElementType, unsigned AddressSpace);
Gregory Szorc34c863a2012-03-21 03:54:29 +0000916
917/**
918 * Obtain the address space of a pointer type.
919 *
920 * This only works on types that represent pointers.
921 *
922 * @see llvm::PointerType::getAddressSpace()
923 */
924unsigned LLVMGetPointerAddressSpace(LLVMTypeRef PointerTy);
925
926/**
927 * Create a vector type that contains a defined type and has a specific
928 * number of elements.
929 *
930 * The created type will exist in the context thats its element type
931 * exists in.
932 *
933 * @see llvm::VectorType::get()
934 */
Gordon Henriksened7beaa2007-10-06 16:05:20 +0000935LLVMTypeRef LLVMVectorType(LLVMTypeRef ElementType, unsigned ElementCount);
Gordon Henriksen76a03742007-09-18 03:18:57 +0000936
Gregory Szorc34c863a2012-03-21 03:54:29 +0000937/**
938 * Obtain the number of elements in a vector type.
939 *
940 * This only works on types that represent vectors.
941 *
942 * @see llvm::VectorType::getNumElements()
943 */
Gordon Henriksen76a03742007-09-18 03:18:57 +0000944unsigned LLVMGetVectorSize(LLVMTypeRef VectorTy);
945
Gregory Szorc34c863a2012-03-21 03:54:29 +0000946/**
947 * @}
948 */
949
950/**
951 * @defgroup LLVMCCoreTypeOther Other Types
952 *
953 * @{
954 */
955
956/**
957 * Create a void type in a context.
958 */
Erick Tryzelaar262332f2009-08-14 00:01:31 +0000959LLVMTypeRef LLVMVoidTypeInContext(LLVMContextRef C);
Gregory Szorc34c863a2012-03-21 03:54:29 +0000960
961/**
962 * Create a label type in a context.
963 */
Erick Tryzelaar262332f2009-08-14 00:01:31 +0000964LLVMTypeRef LLVMLabelTypeInContext(LLVMContextRef C);
Gregory Szorc34c863a2012-03-21 03:54:29 +0000965
966/**
967 * Create a X86 MMX type in a context.
968 */
Dale Johannesen95b67af2010-09-10 21:58:02 +0000969LLVMTypeRef LLVMX86MMXTypeInContext(LLVMContextRef C);
Erick Tryzelaar262332f2009-08-14 00:01:31 +0000970
Gregory Szorc34c863a2012-03-21 03:54:29 +0000971/**
972 * These are similar to the above functions except they operate on the
973 * global context.
974 */
Gordon Henriksena735a9c2008-05-04 12:55:34 +0000975LLVMTypeRef LLVMVoidType(void);
976LLVMTypeRef LLVMLabelType(void);
Dale Johannesen95b67af2010-09-10 21:58:02 +0000977LLVMTypeRef LLVMX86MMXType(void);
Gordon Henriksen76a03742007-09-18 03:18:57 +0000978
Gregory Szorc34c863a2012-03-21 03:54:29 +0000979/**
980 * @}
981 */
Gordon Henriksen76a03742007-09-18 03:18:57 +0000982
Gregory Szorc34c863a2012-03-21 03:54:29 +0000983/**
984 * @}
985 */
986
987/**
988 * @defgroup LLVMCCoreValues Values
989 *
990 * The bulk of LLVM's object model consists of values, which comprise a very
Gordon Henriksen76a03742007-09-18 03:18:57 +0000991 * rich type hierarchy.
Gregory Szorc34c863a2012-03-21 03:54:29 +0000992 *
993 * LLVMValueRef essentially represents llvm::Value. There is a rich
994 * hierarchy of classes within this type. Depending on the instance
Eli Benderskyc52863c2012-08-10 18:30:44 +0000995 * obtained, not all APIs are available.
Gregory Szorc34c863a2012-03-21 03:54:29 +0000996 *
997 * Callers can determine the type of a LLVMValueRef by calling the
998 * LLVMIsA* family of functions (e.g. LLVMIsAArgument()). These
999 * functions are defined by a macro, so it isn't obvious which are
1000 * available by looking at the Doxygen source code. Instead, look at the
1001 * source definition of LLVM_FOR_EACH_VALUE_SUBCLASS and note the list
1002 * of value names given. These value names also correspond to classes in
1003 * the llvm::Value hierarchy.
1004 *
1005 * @{
Gordon Henriksen76a03742007-09-18 03:18:57 +00001006 */
1007
Gordon Henriksen29e38942008-12-19 18:39:45 +00001008#define LLVM_FOR_EACH_VALUE_SUBCLASS(macro) \
1009 macro(Argument) \
1010 macro(BasicBlock) \
1011 macro(InlineAsm) \
Torok Edwind09b7572011-10-14 20:37:56 +00001012 macro(MDNode) \
1013 macro(MDString) \
Gordon Henriksen29e38942008-12-19 18:39:45 +00001014 macro(User) \
1015 macro(Constant) \
Torok Edwind09b7572011-10-14 20:37:56 +00001016 macro(BlockAddress) \
Gordon Henriksen29e38942008-12-19 18:39:45 +00001017 macro(ConstantAggregateZero) \
1018 macro(ConstantArray) \
1019 macro(ConstantExpr) \
1020 macro(ConstantFP) \
1021 macro(ConstantInt) \
1022 macro(ConstantPointerNull) \
1023 macro(ConstantStruct) \
1024 macro(ConstantVector) \
1025 macro(GlobalValue) \
1026 macro(Function) \
1027 macro(GlobalAlias) \
1028 macro(GlobalVariable) \
1029 macro(UndefValue) \
1030 macro(Instruction) \
1031 macro(BinaryOperator) \
1032 macro(CallInst) \
1033 macro(IntrinsicInst) \
1034 macro(DbgInfoIntrinsic) \
1035 macro(DbgDeclareInst) \
Gordon Henriksen29e38942008-12-19 18:39:45 +00001036 macro(MemIntrinsic) \
1037 macro(MemCpyInst) \
1038 macro(MemMoveInst) \
1039 macro(MemSetInst) \
1040 macro(CmpInst) \
Torok Edwind09b7572011-10-14 20:37:56 +00001041 macro(FCmpInst) \
1042 macro(ICmpInst) \
Gordon Henriksen29e38942008-12-19 18:39:45 +00001043 macro(ExtractElementInst) \
1044 macro(GetElementPtrInst) \
1045 macro(InsertElementInst) \
1046 macro(InsertValueInst) \
Bill Wendlingfae14752011-08-12 20:24:12 +00001047 macro(LandingPadInst) \
Gordon Henriksen29e38942008-12-19 18:39:45 +00001048 macro(PHINode) \
1049 macro(SelectInst) \
1050 macro(ShuffleVectorInst) \
1051 macro(StoreInst) \
1052 macro(TerminatorInst) \
1053 macro(BranchInst) \
Torok Edwind09b7572011-10-14 20:37:56 +00001054 macro(IndirectBrInst) \
Gordon Henriksen29e38942008-12-19 18:39:45 +00001055 macro(InvokeInst) \
1056 macro(ReturnInst) \
1057 macro(SwitchInst) \
1058 macro(UnreachableInst) \
Bill Wendlingf891bf82011-07-31 06:30:59 +00001059 macro(ResumeInst) \
Gordon Henriksen29e38942008-12-19 18:39:45 +00001060 macro(UnaryInstruction) \
Victor Hernandez8acf2952009-10-23 21:09:37 +00001061 macro(AllocaInst) \
Gordon Henriksen29e38942008-12-19 18:39:45 +00001062 macro(CastInst) \
Gordon Henriksen05a868f2008-12-19 18:51:17 +00001063 macro(BitCastInst) \
1064 macro(FPExtInst) \
1065 macro(FPToSIInst) \
1066 macro(FPToUIInst) \
1067 macro(FPTruncInst) \
1068 macro(IntToPtrInst) \
1069 macro(PtrToIntInst) \
1070 macro(SExtInst) \
1071 macro(SIToFPInst) \
1072 macro(TruncInst) \
1073 macro(UIToFPInst) \
1074 macro(ZExtInst) \
1075 macro(ExtractValueInst) \
Gordon Henriksen05a868f2008-12-19 18:51:17 +00001076 macro(LoadInst) \
1077 macro(VAArgInst)
Gordon Henriksen29e38942008-12-19 18:39:45 +00001078
Gregory Szorc34c863a2012-03-21 03:54:29 +00001079/**
1080 * @defgroup LLVMCCoreValueGeneral General APIs
1081 *
1082 * Functions in this section work on all LLVMValueRef instances,
1083 * regardless of their sub-type. They correspond to functions available
1084 * on llvm::Value.
1085 *
1086 * @{
1087 */
Gordon Henriksen76a03742007-09-18 03:18:57 +00001088
Gregory Szorc34c863a2012-03-21 03:54:29 +00001089/**
1090 * Obtain the type of a value.
1091 *
1092 * @see llvm::Value::getType()
1093 */
1094LLVMTypeRef LLVMTypeOf(LLVMValueRef Val);
1095
1096/**
1097 * Obtain the string name of a value.
1098 *
1099 * @see llvm::Value::getName()
1100 */
1101const char *LLVMGetValueName(LLVMValueRef Val);
1102
1103/**
1104 * Set the string name of a value.
1105 *
1106 * @see llvm::Value::setName()
1107 */
1108void LLVMSetValueName(LLVMValueRef Val, const char *Name);
1109
1110/**
1111 * Dump a representation of a value to stderr.
1112 *
1113 * @see llvm::Value::dump()
1114 */
1115void LLVMDumpValue(LLVMValueRef Val);
1116
1117/**
1118 * Replace all uses of a value with another one.
1119 *
1120 * @see llvm::Value::replaceAllUsesWith()
1121 */
1122void LLVMReplaceAllUsesWith(LLVMValueRef OldVal, LLVMValueRef NewVal);
1123
1124/**
1125 * Determine whether the specified constant instance is constant.
1126 */
1127LLVMBool LLVMIsConstant(LLVMValueRef Val);
1128
1129/**
1130 * Determine whether a value instance is undefined.
1131 */
1132LLVMBool LLVMIsUndef(LLVMValueRef Val);
1133
1134/**
1135 * Convert value instances between types.
1136 *
1137 * Internally, a LLVMValueRef is "pinned" to a specific type. This
1138 * series of functions allows you to cast an instance to a specific
1139 * type.
1140 *
1141 * If the cast is not valid for the specified type, NULL is returned.
1142 *
1143 * @see llvm::dyn_cast_or_null<>
1144 */
Gordon Henriksen29e38942008-12-19 18:39:45 +00001145#define LLVM_DECLARE_VALUE_CAST(name) \
1146 LLVMValueRef LLVMIsA##name(LLVMValueRef Val);
1147LLVM_FOR_EACH_VALUE_SUBCLASS(LLVM_DECLARE_VALUE_CAST)
1148
Gregory Szorc34c863a2012-03-21 03:54:29 +00001149/**
1150 * @}
1151 */
1152
1153/**
1154 * @defgroup LLVMCCoreValueUses Usage
1155 *
1156 * This module defines functions that allow you to inspect the uses of a
1157 * LLVMValueRef.
1158 *
1159 * It is possible to obtain a LLVMUseRef for any LLVMValueRef instance.
1160 * Each LLVMUseRef (which corresponds to a llvm::Use instance) holds a
1161 * llvm::User and llvm::Value.
1162 *
1163 * @{
1164 */
1165
1166/**
1167 * Obtain the first use of a value.
1168 *
1169 * Uses are obtained in an iterator fashion. First, call this function
1170 * to obtain a reference to the first use. Then, call LLVMGetNextUse()
Eli Benderskyc52863c2012-08-10 18:30:44 +00001171 * on that instance and all subsequently obtained instances until
Gregory Szorc34c863a2012-03-21 03:54:29 +00001172 * LLVMGetNextUse() returns NULL.
1173 *
1174 * @see llvm::Value::use_begin()
1175 */
Erick Tryzelaar9f9857e2010-03-02 20:32:28 +00001176LLVMUseRef LLVMGetFirstUse(LLVMValueRef Val);
Gregory Szorc34c863a2012-03-21 03:54:29 +00001177
1178/**
1179 * Obtain the next use of a value.
1180 *
1181 * This effectively advances the iterator. It returns NULL if you are on
1182 * the final use and no more are available.
1183 */
Erick Tryzelaar9f9857e2010-03-02 20:32:28 +00001184LLVMUseRef LLVMGetNextUse(LLVMUseRef U);
Gregory Szorc34c863a2012-03-21 03:54:29 +00001185
1186/**
1187 * Obtain the user value for a user.
1188 *
1189 * The returned value corresponds to a llvm::User type.
1190 *
1191 * @see llvm::Use::getUser()
1192 */
Erick Tryzelaar9f9857e2010-03-02 20:32:28 +00001193LLVMValueRef LLVMGetUser(LLVMUseRef U);
Gregory Szorc34c863a2012-03-21 03:54:29 +00001194
1195/**
1196 * Obtain the value this use corresponds to.
1197 *
1198 * @see llvm::Use::get().
1199 */
Erick Tryzelaar9f9857e2010-03-02 20:32:28 +00001200LLVMValueRef LLVMGetUsedValue(LLVMUseRef U);
Chris Lattner40cf28d2009-10-12 04:01:02 +00001201
Gregory Szorc34c863a2012-03-21 03:54:29 +00001202/**
1203 * @}
1204 */
1205
1206/**
Gregory Szorc52d26602012-03-21 07:28:27 +00001207 * @defgroup LLVMCCoreValueUser User value
Gregory Szorc34c863a2012-03-21 03:54:29 +00001208 *
1209 * Function in this group pertain to LLVMValueRef instances that descent
1210 * from llvm::User. This includes constants, instructions, and
1211 * operators.
1212 *
1213 * @{
1214 */
1215
1216/**
1217 * Obtain an operand at a specific index in a llvm::User value.
1218 *
1219 * @see llvm::User::getOperand()
1220 */
Chris Lattner40cf28d2009-10-12 04:01:02 +00001221LLVMValueRef LLVMGetOperand(LLVMValueRef Val, unsigned Index);
Gregory Szorc34c863a2012-03-21 03:54:29 +00001222
1223/**
1224 * Set an operand at a specific index in a llvm::User value.
1225 *
1226 * @see llvm::User::setOperand()
1227 */
Erick Tryzelaarb4d48702010-08-20 14:51:22 +00001228void LLVMSetOperand(LLVMValueRef User, unsigned Index, LLVMValueRef Val);
Gregory Szorc34c863a2012-03-21 03:54:29 +00001229
1230/**
1231 * Obtain the number of operands in a llvm::User value.
1232 *
1233 * @see llvm::User::getNumOperands()
1234 */
Erick Tryzelaarb4d48702010-08-20 14:51:22 +00001235int LLVMGetNumOperands(LLVMValueRef Val);
Chris Lattner40cf28d2009-10-12 04:01:02 +00001236
Gregory Szorc34c863a2012-03-21 03:54:29 +00001237/**
1238 * @}
1239 */
1240
1241/**
Gregory Szorc52d26602012-03-21 07:28:27 +00001242 * @defgroup LLVMCCoreValueConstant Constants
Gregory Szorc34c863a2012-03-21 03:54:29 +00001243 *
1244 * This section contains APIs for interacting with LLVMValueRef that
1245 * correspond to llvm::Constant instances.
1246 *
1247 * These functions will work for any LLVMValueRef in the llvm::Constant
1248 * class hierarchy.
1249 *
1250 * @{
1251 */
1252
1253/**
1254 * Obtain a constant value referring to the null instance of a type.
1255 *
1256 * @see llvm::Constant::getNullValue()
1257 */
Gordon Henriksen1046c732007-10-06 15:11:06 +00001258LLVMValueRef LLVMConstNull(LLVMTypeRef Ty); /* all zeroes */
Gregory Szorc34c863a2012-03-21 03:54:29 +00001259
1260/**
1261 * Obtain a constant value referring to the instance of a type
1262 * consisting of all ones.
1263 *
1264 * This is only valid for integer types.
1265 *
1266 * @see llvm::Constant::getAllOnesValue()
1267 */
1268LLVMValueRef LLVMConstAllOnes(LLVMTypeRef Ty);
1269
1270/**
1271 * Obtain a constant value referring to an undefined value of a type.
1272 *
1273 * @see llvm::UndefValue::get()
1274 */
Gordon Henriksen76a03742007-09-18 03:18:57 +00001275LLVMValueRef LLVMGetUndef(LLVMTypeRef Ty);
Gregory Szorc34c863a2012-03-21 03:54:29 +00001276
1277/**
1278 * Determine whether a value instance is null.
1279 *
1280 * @see llvm::Constant::isNullValue()
1281 */
Chris Lattner25963c62010-01-09 22:27:07 +00001282LLVMBool LLVMIsNull(LLVMValueRef Val);
Gregory Szorc34c863a2012-03-21 03:54:29 +00001283
1284/**
1285 * Obtain a constant that is a constant pointer pointing to NULL for a
1286 * specified type.
1287 */
Chris Lattner7f318242009-07-06 17:29:59 +00001288LLVMValueRef LLVMConstPointerNull(LLVMTypeRef Ty);
Gordon Henriksen76a03742007-09-18 03:18:57 +00001289
Gregory Szorc34c863a2012-03-21 03:54:29 +00001290/**
1291 * @defgroup LLVMCCoreValueConstantScalar Scalar constants
1292 *
1293 * Functions in this group model LLVMValueRef instances that correspond
1294 * to constants referring to scalar types.
1295 *
1296 * For integer types, the LLVMTypeRef parameter should correspond to a
1297 * llvm::IntegerType instance and the returned LLVMValueRef will
1298 * correspond to a llvm::ConstantInt.
1299 *
1300 * For floating point types, the LLVMTypeRef returned corresponds to a
1301 * llvm::ConstantFP.
1302 *
1303 * @{
1304 */
Erick Tryzelaard8531fa2010-02-28 09:45:59 +00001305
Gregory Szorc34c863a2012-03-21 03:54:29 +00001306/**
1307 * Obtain a constant value for an integer type.
1308 *
1309 * The returned value corresponds to a llvm::ConstantInt.
1310 *
1311 * @see llvm::ConstantInt::get()
1312 *
1313 * @param IntTy Integer type to obtain value of.
1314 * @param N The value the returned instance should refer to.
1315 * @param SignExtend Whether to sign extend the produced value.
1316 */
Gordon Henriksen1046c732007-10-06 15:11:06 +00001317LLVMValueRef LLVMConstInt(LLVMTypeRef IntTy, unsigned long long N,
Chris Lattner25963c62010-01-09 22:27:07 +00001318 LLVMBool SignExtend);
Gregory Szorc34c863a2012-03-21 03:54:29 +00001319
1320/**
1321 * Obtain a constant value for an integer of arbitrary precision.
1322 *
1323 * @see llvm::ConstantInt::get()
1324 */
Chris Lattner4329e072010-11-23 02:47:22 +00001325LLVMValueRef LLVMConstIntOfArbitraryPrecision(LLVMTypeRef IntTy,
1326 unsigned NumWords,
1327 const uint64_t Words[]);
Gregory Szorc34c863a2012-03-21 03:54:29 +00001328
1329/**
1330 * Obtain a constant value for an integer parsed from a string.
1331 *
1332 * A similar API, LLVMConstIntOfStringAndSize is also available. If the
1333 * string's length is available, it is preferred to call that function
1334 * instead.
1335 *
1336 * @see llvm::ConstantInt::get()
1337 */
Erick Tryzelaardd991352009-08-16 23:36:46 +00001338LLVMValueRef LLVMConstIntOfString(LLVMTypeRef IntTy, const char *Text,
1339 uint8_t Radix);
Gregory Szorc34c863a2012-03-21 03:54:29 +00001340
1341/**
1342 * Obtain a constant value for an integer parsed from a string with
1343 * specified length.
1344 *
1345 * @see llvm::ConstantInt::get()
1346 */
Erick Tryzelaardd991352009-08-16 23:36:46 +00001347LLVMValueRef LLVMConstIntOfStringAndSize(LLVMTypeRef IntTy, const char *Text,
1348 unsigned SLen, uint8_t Radix);
Gregory Szorc34c863a2012-03-21 03:54:29 +00001349
1350/**
1351 * Obtain a constant value referring to a double floating point value.
1352 */
Gordon Henriksen1046c732007-10-06 15:11:06 +00001353LLVMValueRef LLVMConstReal(LLVMTypeRef RealTy, double N);
Gregory Szorc34c863a2012-03-21 03:54:29 +00001354
1355/**
1356 * Obtain a constant for a floating point value parsed from a string.
1357 *
1358 * A similar API, LLVMConstRealOfStringAndSize is also available. It
1359 * should be used if the input string's length is known.
1360 */
Gordon Henriksen931e1212008-02-02 01:07:50 +00001361LLVMValueRef LLVMConstRealOfString(LLVMTypeRef RealTy, const char *Text);
Gregory Szorc34c863a2012-03-21 03:54:29 +00001362
1363/**
1364 * Obtain a constant for a floating point value parsed from a string.
1365 */
Erick Tryzelaardd991352009-08-16 23:36:46 +00001366LLVMValueRef LLVMConstRealOfStringAndSize(LLVMTypeRef RealTy, const char *Text,
1367 unsigned SLen);
Gregory Szorc34c863a2012-03-21 03:54:29 +00001368
1369/**
1370 * Obtain the zero extended value for an integer constant value.
1371 *
1372 * @see llvm::ConstantInt::getZExtValue()
1373 */
Chris Lattner40cf28d2009-10-12 04:01:02 +00001374unsigned long long LLVMConstIntGetZExtValue(LLVMValueRef ConstantVal);
Gregory Szorc34c863a2012-03-21 03:54:29 +00001375
1376/**
1377 * Obtain the sign extended value for an integer constant value.
1378 *
1379 * @see llvm::ConstantInt::getSExtValue()
1380 */
Chris Lattner40cf28d2009-10-12 04:01:02 +00001381long long LLVMConstIntGetSExtValue(LLVMValueRef ConstantVal);
Erick Tryzelaardd991352009-08-16 23:36:46 +00001382
Gregory Szorc34c863a2012-03-21 03:54:29 +00001383/**
1384 * @}
1385 */
1386
1387/**
Gregory Szorc52d26602012-03-21 07:28:27 +00001388 * @defgroup LLVMCCoreValueConstantComposite Composite Constants
1389 *
1390 * Functions in this group operate on composite constants.
Gregory Szorc34c863a2012-03-21 03:54:29 +00001391 *
1392 * @{
1393 */
1394
1395/**
Gregory Szorc52d26602012-03-21 07:28:27 +00001396 * Create a ConstantDataSequential and initialize it with a string.
Gregory Szorc34c863a2012-03-21 03:54:29 +00001397 *
Gregory Szorc52d26602012-03-21 07:28:27 +00001398 * @see llvm::ConstantDataArray::getString()
Gregory Szorc34c863a2012-03-21 03:54:29 +00001399 */
Erick Tryzelaar262332f2009-08-14 00:01:31 +00001400LLVMValueRef LLVMConstStringInContext(LLVMContextRef C, const char *Str,
Chris Lattner25963c62010-01-09 22:27:07 +00001401 unsigned Length, LLVMBool DontNullTerminate);
Gregory Szorc52d26602012-03-21 07:28:27 +00001402
1403/**
1404 * Create a ConstantDataSequential with string content in the global context.
1405 *
1406 * This is the same as LLVMConstStringInContext except it operates on the
1407 * global context.
1408 *
1409 * @see LLVMConstStringInContext()
1410 * @see llvm::ConstantDataArray::getString()
1411 */
1412LLVMValueRef LLVMConstString(const char *Str, unsigned Length,
1413 LLVMBool DontNullTerminate);
1414
1415/**
1416 * Create an anonymous ConstantStruct with the specified values.
1417 *
1418 * @see llvm::ConstantStruct::getAnon()
1419 */
1420LLVMValueRef LLVMConstStructInContext(LLVMContextRef C,
Erick Tryzelaar262332f2009-08-14 00:01:31 +00001421 LLVMValueRef *ConstantVals,
Chris Lattner25963c62010-01-09 22:27:07 +00001422 unsigned Count, LLVMBool Packed);
Erick Tryzelaar262332f2009-08-14 00:01:31 +00001423
Gregory Szorc52d26602012-03-21 07:28:27 +00001424/**
1425 * Create a ConstantStruct in the global Context.
1426 *
1427 * This is the same as LLVMConstStructInContext except it operates on the
1428 * global Context.
1429 *
1430 * @see LLVMConstStructInContext()
1431 */
Gordon Henriksen1046c732007-10-06 15:11:06 +00001432LLVMValueRef LLVMConstStruct(LLVMValueRef *ConstantVals, unsigned Count,
Chris Lattner25963c62010-01-09 22:27:07 +00001433 LLVMBool Packed);
Gregory Szorc52d26602012-03-21 07:28:27 +00001434
1435/**
1436 * Create a ConstantArray from values.
1437 *
1438 * @see llvm::ConstantArray::get()
1439 */
1440LLVMValueRef LLVMConstArray(LLVMTypeRef ElementTy,
1441 LLVMValueRef *ConstantVals, unsigned Length);
1442
1443/**
1444 * Create a non-anonymous ConstantStruct from values.
1445 *
1446 * @see llvm::ConstantStruct::get()
1447 */
Rafael Espindola784ad242011-07-14 19:09:08 +00001448LLVMValueRef LLVMConstNamedStruct(LLVMTypeRef StructTy,
1449 LLVMValueRef *ConstantVals,
1450 unsigned Count);
Gregory Szorc52d26602012-03-21 07:28:27 +00001451
1452/**
1453 * Create a ConstantVector from values.
1454 *
1455 * @see llvm::ConstantVector::get()
1456 */
Gordon Henriksen1046c732007-10-06 15:11:06 +00001457LLVMValueRef LLVMConstVector(LLVMValueRef *ScalarConstantVals, unsigned Size);
Gordon Henriksen76a03742007-09-18 03:18:57 +00001458
Gregory Szorc52d26602012-03-21 07:28:27 +00001459/**
1460 * @}
1461 */
1462
1463/**
1464 * @defgroup LLVMCCoreValueConstantExpressions Constant Expressions
1465 *
1466 * Functions in this group correspond to APIs on llvm::ConstantExpr.
1467 *
1468 * @see llvm::ConstantExpr.
1469 *
1470 * @{
1471 */
Chris Lattner40cf28d2009-10-12 04:01:02 +00001472LLVMOpcode LLVMGetConstOpcode(LLVMValueRef ConstantVal);
Erick Tryzelaarfd529d72009-08-19 08:36:49 +00001473LLVMValueRef LLVMAlignOf(LLVMTypeRef Ty);
Gordon Henriksen7ce31762007-10-06 14:29:36 +00001474LLVMValueRef LLVMSizeOf(LLVMTypeRef Ty);
1475LLVMValueRef LLVMConstNeg(LLVMValueRef ConstantVal);
Erick Tryzelaar4c340c72010-02-28 05:51:43 +00001476LLVMValueRef LLVMConstNSWNeg(LLVMValueRef ConstantVal);
1477LLVMValueRef LLVMConstNUWNeg(LLVMValueRef ConstantVal);
Erick Tryzelaar4cc690c2009-08-16 02:20:12 +00001478LLVMValueRef LLVMConstFNeg(LLVMValueRef ConstantVal);
Gordon Henriksen7ce31762007-10-06 14:29:36 +00001479LLVMValueRef LLVMConstNot(LLVMValueRef ConstantVal);
1480LLVMValueRef LLVMConstAdd(LLVMValueRef LHSConstant, LLVMValueRef RHSConstant);
Dan Gohmane4ca02d2009-09-03 23:34:49 +00001481LLVMValueRef LLVMConstNSWAdd(LLVMValueRef LHSConstant, LLVMValueRef RHSConstant);
Erick Tryzelaar4c340c72010-02-28 05:51:43 +00001482LLVMValueRef LLVMConstNUWAdd(LLVMValueRef LHSConstant, LLVMValueRef RHSConstant);
Erick Tryzelaar4cc690c2009-08-16 02:20:12 +00001483LLVMValueRef LLVMConstFAdd(LLVMValueRef LHSConstant, LLVMValueRef RHSConstant);
Gordon Henriksen7ce31762007-10-06 14:29:36 +00001484LLVMValueRef LLVMConstSub(LLVMValueRef LHSConstant, LLVMValueRef RHSConstant);
Erick Tryzelaar4c340c72010-02-28 05:51:43 +00001485LLVMValueRef LLVMConstNSWSub(LLVMValueRef LHSConstant, LLVMValueRef RHSConstant);
1486LLVMValueRef LLVMConstNUWSub(LLVMValueRef LHSConstant, LLVMValueRef RHSConstant);
Erick Tryzelaar4cc690c2009-08-16 02:20:12 +00001487LLVMValueRef LLVMConstFSub(LLVMValueRef LHSConstant, LLVMValueRef RHSConstant);
Gordon Henriksen7ce31762007-10-06 14:29:36 +00001488LLVMValueRef LLVMConstMul(LLVMValueRef LHSConstant, LLVMValueRef RHSConstant);
Erick Tryzelaar4c340c72010-02-28 05:51:43 +00001489LLVMValueRef LLVMConstNSWMul(LLVMValueRef LHSConstant, LLVMValueRef RHSConstant);
1490LLVMValueRef LLVMConstNUWMul(LLVMValueRef LHSConstant, LLVMValueRef RHSConstant);
Erick Tryzelaar4cc690c2009-08-16 02:20:12 +00001491LLVMValueRef LLVMConstFMul(LLVMValueRef LHSConstant, LLVMValueRef RHSConstant);
Gordon Henriksen7ce31762007-10-06 14:29:36 +00001492LLVMValueRef LLVMConstUDiv(LLVMValueRef LHSConstant, LLVMValueRef RHSConstant);
1493LLVMValueRef LLVMConstSDiv(LLVMValueRef LHSConstant, LLVMValueRef RHSConstant);
Dan Gohmane4ca02d2009-09-03 23:34:49 +00001494LLVMValueRef LLVMConstExactSDiv(LLVMValueRef LHSConstant, LLVMValueRef RHSConstant);
Gordon Henriksen7ce31762007-10-06 14:29:36 +00001495LLVMValueRef LLVMConstFDiv(LLVMValueRef LHSConstant, LLVMValueRef RHSConstant);
1496LLVMValueRef LLVMConstURem(LLVMValueRef LHSConstant, LLVMValueRef RHSConstant);
1497LLVMValueRef LLVMConstSRem(LLVMValueRef LHSConstant, LLVMValueRef RHSConstant);
1498LLVMValueRef LLVMConstFRem(LLVMValueRef LHSConstant, LLVMValueRef RHSConstant);
1499LLVMValueRef LLVMConstAnd(LLVMValueRef LHSConstant, LLVMValueRef RHSConstant);
1500LLVMValueRef LLVMConstOr(LLVMValueRef LHSConstant, LLVMValueRef RHSConstant);
1501LLVMValueRef LLVMConstXor(LLVMValueRef LHSConstant, LLVMValueRef RHSConstant);
1502LLVMValueRef LLVMConstICmp(LLVMIntPredicate Predicate,
1503 LLVMValueRef LHSConstant, LLVMValueRef RHSConstant);
1504LLVMValueRef LLVMConstFCmp(LLVMRealPredicate Predicate,
1505 LLVMValueRef LHSConstant, LLVMValueRef RHSConstant);
1506LLVMValueRef LLVMConstShl(LLVMValueRef LHSConstant, LLVMValueRef RHSConstant);
1507LLVMValueRef LLVMConstLShr(LLVMValueRef LHSConstant, LLVMValueRef RHSConstant);
1508LLVMValueRef LLVMConstAShr(LLVMValueRef LHSConstant, LLVMValueRef RHSConstant);
1509LLVMValueRef LLVMConstGEP(LLVMValueRef ConstantVal,
1510 LLVMValueRef *ConstantIndices, unsigned NumIndices);
Dan Gohmane4ca02d2009-09-03 23:34:49 +00001511LLVMValueRef LLVMConstInBoundsGEP(LLVMValueRef ConstantVal,
1512 LLVMValueRef *ConstantIndices,
1513 unsigned NumIndices);
Gordon Henriksen7ce31762007-10-06 14:29:36 +00001514LLVMValueRef LLVMConstTrunc(LLVMValueRef ConstantVal, LLVMTypeRef ToType);
1515LLVMValueRef LLVMConstSExt(LLVMValueRef ConstantVal, LLVMTypeRef ToType);
1516LLVMValueRef LLVMConstZExt(LLVMValueRef ConstantVal, LLVMTypeRef ToType);
1517LLVMValueRef LLVMConstFPTrunc(LLVMValueRef ConstantVal, LLVMTypeRef ToType);
1518LLVMValueRef LLVMConstFPExt(LLVMValueRef ConstantVal, LLVMTypeRef ToType);
1519LLVMValueRef LLVMConstUIToFP(LLVMValueRef ConstantVal, LLVMTypeRef ToType);
1520LLVMValueRef LLVMConstSIToFP(LLVMValueRef ConstantVal, LLVMTypeRef ToType);
1521LLVMValueRef LLVMConstFPToUI(LLVMValueRef ConstantVal, LLVMTypeRef ToType);
1522LLVMValueRef LLVMConstFPToSI(LLVMValueRef ConstantVal, LLVMTypeRef ToType);
1523LLVMValueRef LLVMConstPtrToInt(LLVMValueRef ConstantVal, LLVMTypeRef ToType);
1524LLVMValueRef LLVMConstIntToPtr(LLVMValueRef ConstantVal, LLVMTypeRef ToType);
1525LLVMValueRef LLVMConstBitCast(LLVMValueRef ConstantVal, LLVMTypeRef ToType);
Erick Tryzelaar4cc690c2009-08-16 02:20:12 +00001526LLVMValueRef LLVMConstZExtOrBitCast(LLVMValueRef ConstantVal,
1527 LLVMTypeRef ToType);
1528LLVMValueRef LLVMConstSExtOrBitCast(LLVMValueRef ConstantVal,
1529 LLVMTypeRef ToType);
1530LLVMValueRef LLVMConstTruncOrBitCast(LLVMValueRef ConstantVal,
1531 LLVMTypeRef ToType);
1532LLVMValueRef LLVMConstPointerCast(LLVMValueRef ConstantVal,
1533 LLVMTypeRef ToType);
1534LLVMValueRef LLVMConstIntCast(LLVMValueRef ConstantVal, LLVMTypeRef ToType,
Chris Lattner25963c62010-01-09 22:27:07 +00001535 LLVMBool isSigned);
Erick Tryzelaar4cc690c2009-08-16 02:20:12 +00001536LLVMValueRef LLVMConstFPCast(LLVMValueRef ConstantVal, LLVMTypeRef ToType);
Gordon Henriksen7ce31762007-10-06 14:29:36 +00001537LLVMValueRef LLVMConstSelect(LLVMValueRef ConstantCondition,
1538 LLVMValueRef ConstantIfTrue,
1539 LLVMValueRef ConstantIfFalse);
1540LLVMValueRef LLVMConstExtractElement(LLVMValueRef VectorConstant,
1541 LLVMValueRef IndexConstant);
1542LLVMValueRef LLVMConstInsertElement(LLVMValueRef VectorConstant,
1543 LLVMValueRef ElementValueConstant,
1544 LLVMValueRef IndexConstant);
1545LLVMValueRef LLVMConstShuffleVector(LLVMValueRef VectorAConstant,
1546 LLVMValueRef VectorBConstant,
1547 LLVMValueRef MaskConstant);
Dan Gohmand5104a52008-11-03 22:55:43 +00001548LLVMValueRef LLVMConstExtractValue(LLVMValueRef AggConstant, unsigned *IdxList,
1549 unsigned NumIdx);
1550LLVMValueRef LLVMConstInsertValue(LLVMValueRef AggConstant,
1551 LLVMValueRef ElementValueConstant,
1552 unsigned *IdxList, unsigned NumIdx);
Chris Lattner25963c62010-01-09 22:27:07 +00001553LLVMValueRef LLVMConstInlineAsm(LLVMTypeRef Ty,
Chris Lattner3d1f5522008-12-17 21:39:50 +00001554 const char *AsmString, const char *Constraints,
Chris Lattner25963c62010-01-09 22:27:07 +00001555 LLVMBool HasSideEffects, LLVMBool IsAlignStack);
Erick Tryzelaar0fb26ef2010-02-28 09:46:06 +00001556LLVMValueRef LLVMBlockAddress(LLVMValueRef F, LLVMBasicBlockRef BB);
Gordon Henriksen7ce31762007-10-06 14:29:36 +00001557
Gregory Szorc52d26602012-03-21 07:28:27 +00001558/**
1559 * @}
1560 */
1561
1562/**
1563 * @defgroup LLVMCCoreValueConstantGlobals Global Values
1564 *
1565 * This group contains functions that operate on global values. Functions in
1566 * this group relate to functions in the llvm::GlobalValue class tree.
1567 *
1568 * @see llvm::GlobalValue
1569 *
1570 * @{
1571 */
1572
Gordon Henriksen265f7802008-03-19 01:11:35 +00001573LLVMModuleRef LLVMGetGlobalParent(LLVMValueRef Global);
Chris Lattner25963c62010-01-09 22:27:07 +00001574LLVMBool LLVMIsDeclaration(LLVMValueRef Global);
Gordon Henriksen76a03742007-09-18 03:18:57 +00001575LLVMLinkage LLVMGetLinkage(LLVMValueRef Global);
1576void LLVMSetLinkage(LLVMValueRef Global, LLVMLinkage Linkage);
1577const char *LLVMGetSection(LLVMValueRef Global);
1578void LLVMSetSection(LLVMValueRef Global, const char *Section);
1579LLVMVisibility LLVMGetVisibility(LLVMValueRef Global);
1580void LLVMSetVisibility(LLVMValueRef Global, LLVMVisibility Viz);
1581unsigned LLVMGetAlignment(LLVMValueRef Global);
1582void LLVMSetAlignment(LLVMValueRef Global, unsigned Bytes);
1583
Gregory Szorc52d26602012-03-21 07:28:27 +00001584/**
1585 * @defgroup LLVMCoreValueConstantGlobalVariable Global Variables
1586 *
1587 * This group contains functions that operate on global variable values.
1588 *
1589 * @see llvm::GlobalVariable
1590 *
1591 * @{
1592 */
Gordon Henriksen76a03742007-09-18 03:18:57 +00001593LLVMValueRef LLVMAddGlobal(LLVMModuleRef M, LLVMTypeRef Ty, const char *Name);
Erick Tryzelaar06894b32010-02-28 09:46:13 +00001594LLVMValueRef LLVMAddGlobalInAddressSpace(LLVMModuleRef M, LLVMTypeRef Ty,
1595 const char *Name,
1596 unsigned AddressSpace);
Gordon Henriksen783f7bb2007-10-08 03:45:09 +00001597LLVMValueRef LLVMGetNamedGlobal(LLVMModuleRef M, const char *Name);
Gordon Henriksen07a45f42008-03-23 22:21:29 +00001598LLVMValueRef LLVMGetFirstGlobal(LLVMModuleRef M);
1599LLVMValueRef LLVMGetLastGlobal(LLVMModuleRef M);
1600LLVMValueRef LLVMGetNextGlobal(LLVMValueRef GlobalVar);
1601LLVMValueRef LLVMGetPreviousGlobal(LLVMValueRef GlobalVar);
Gordon Henriksen76a03742007-09-18 03:18:57 +00001602void LLVMDeleteGlobal(LLVMValueRef GlobalVar);
Gordon Henriksen76a03742007-09-18 03:18:57 +00001603LLVMValueRef LLVMGetInitializer(LLVMValueRef GlobalVar);
1604void LLVMSetInitializer(LLVMValueRef GlobalVar, LLVMValueRef ConstantVal);
Chris Lattner25963c62010-01-09 22:27:07 +00001605LLVMBool LLVMIsThreadLocal(LLVMValueRef GlobalVar);
1606void LLVMSetThreadLocal(LLVMValueRef GlobalVar, LLVMBool IsThreadLocal);
1607LLVMBool LLVMIsGlobalConstant(LLVMValueRef GlobalVar);
1608void LLVMSetGlobalConstant(LLVMValueRef GlobalVar, LLVMBool IsConstant);
Gordon Henriksen76a03742007-09-18 03:18:57 +00001609
Gregory Szorc52d26602012-03-21 07:28:27 +00001610/**
1611 * @}
1612 */
1613
1614/**
1615 * @defgroup LLVMCoreValueConstantGlobalAlias Global Aliases
1616 *
1617 * This group contains function that operate on global alias values.
1618 *
1619 * @see llvm::GlobalAlias
1620 *
1621 * @{
1622 */
Chris Lattner3d1f5522008-12-17 21:39:50 +00001623LLVMValueRef LLVMAddAlias(LLVMModuleRef M, LLVMTypeRef Ty, LLVMValueRef Aliasee,
1624 const char *Name);
1625
Gregory Szorc34c863a2012-03-21 03:54:29 +00001626/**
1627 * @}
1628 */
1629
1630/**
1631 * @defgroup LLVMCCoreValueFunction Function values
1632 *
1633 * Functions in this group operate on LLVMValueRef instances that
1634 * correspond to llvm::Function instances.
1635 *
1636 * @see llvm::Function
1637 *
1638 * @{
1639 */
1640
1641/**
1642 * Remove a function from its containing module and deletes it.
1643 *
1644 * @see llvm::Function::eraseFromParent()
1645 */
Gordon Henriksenc23b66c2007-09-26 20:56:12 +00001646void LLVMDeleteFunction(LLVMValueRef Fn);
Gregory Szorc34c863a2012-03-21 03:54:29 +00001647
1648/**
1649 * Obtain the ID number from a function instance.
1650 *
1651 * @see llvm::Function::getIntrinsicID()
1652 */
Gordon Henriksenc23b66c2007-09-26 20:56:12 +00001653unsigned LLVMGetIntrinsicID(LLVMValueRef Fn);
Gregory Szorc34c863a2012-03-21 03:54:29 +00001654
1655/**
1656 * Obtain the calling function of a function.
1657 *
1658 * The returned value corresponds to the LLVMCallConv enumeration.
1659 *
1660 * @see llvm::Function::getCallingConv()
1661 */
Gordon Henriksenc23b66c2007-09-26 20:56:12 +00001662unsigned LLVMGetFunctionCallConv(LLVMValueRef Fn);
Gregory Szorc34c863a2012-03-21 03:54:29 +00001663
1664/**
1665 * Set the calling convention of a function.
1666 *
1667 * @see llvm::Function::setCallingConv()
1668 *
1669 * @param Fn Function to operate on
1670 * @param CC LLVMCallConv to set calling convention to
1671 */
Gordon Henriksenc23b66c2007-09-26 20:56:12 +00001672void LLVMSetFunctionCallConv(LLVMValueRef Fn, unsigned CC);
Gregory Szorc34c863a2012-03-21 03:54:29 +00001673
1674/**
1675 * Obtain the name of the garbage collector to use during code
1676 * generation.
1677 *
1678 * @see llvm::Function::getGC()
1679 */
Gordon Henriksend930f912008-08-17 18:44:35 +00001680const char *LLVMGetGC(LLVMValueRef Fn);
Gregory Szorc34c863a2012-03-21 03:54:29 +00001681
1682/**
1683 * Define the garbage collector to use during code generation.
1684 *
1685 * @see llvm::Function::setGC()
1686 */
Gordon Henriksend930f912008-08-17 18:44:35 +00001687void LLVMSetGC(LLVMValueRef Fn, const char *Name);
Gregory Szorc34c863a2012-03-21 03:54:29 +00001688
1689/**
1690 * Add an attribute to a function.
1691 *
1692 * @see llvm::Function::addAttribute()
1693 */
Duncan Sands7374a012009-05-06 12:21:17 +00001694void LLVMAddFunctionAttr(LLVMValueRef Fn, LLVMAttribute PA);
Gregory Szorc34c863a2012-03-21 03:54:29 +00001695
1696/**
1697 * Obtain an attribute from a function.
1698 *
1699 * @see llvm::Function::getAttributes()
1700 */
Chris Lattner40cf28d2009-10-12 04:01:02 +00001701LLVMAttribute LLVMGetFunctionAttr(LLVMValueRef Fn);
Gregory Szorc34c863a2012-03-21 03:54:29 +00001702
1703/**
1704 * Remove an attribute from a function.
1705 */
Duncan Sands7374a012009-05-06 12:21:17 +00001706void LLVMRemoveFunctionAttr(LLVMValueRef Fn, LLVMAttribute PA);
Gordon Henriksenc23b66c2007-09-26 20:56:12 +00001707
Gregory Szorc34c863a2012-03-21 03:54:29 +00001708/**
1709 * @defgroup LLVMCCoreValueFunctionParameters Function Parameters
1710 *
1711 * Functions in this group relate to arguments/parameters on functions.
1712 *
1713 * Functions in this group expect LLVMValueRef instances that correspond
1714 * to llvm::Function instances.
1715 *
1716 * @{
1717 */
1718
1719/**
1720 * Obtain the number of parameters in a function.
1721 *
1722 * @see llvm::Function::arg_size()
1723 */
Gordon Henriksen265f7802008-03-19 01:11:35 +00001724unsigned LLVMCountParams(LLVMValueRef Fn);
Gregory Szorc34c863a2012-03-21 03:54:29 +00001725
1726/**
1727 * Obtain the parameters in a function.
1728 *
1729 * The takes a pointer to a pre-allocated array of LLVMValueRef that is
1730 * at least LLVMCountParams() long. This array will be filled with
1731 * LLVMValueRef instances which correspond to the parameters the
1732 * function receives. Each LLVMValueRef corresponds to a llvm::Argument
1733 * instance.
1734 *
1735 * @see llvm::Function::arg_begin()
1736 */
Gordon Henriksen265f7802008-03-19 01:11:35 +00001737void LLVMGetParams(LLVMValueRef Fn, LLVMValueRef *Params);
Gregory Szorc34c863a2012-03-21 03:54:29 +00001738
1739/**
1740 * Obtain the parameter at the specified index.
1741 *
1742 * Parameters are indexed from 0.
1743 *
1744 * @see llvm::Function::arg_begin()
1745 */
Gordon Henriksen265f7802008-03-19 01:11:35 +00001746LLVMValueRef LLVMGetParam(LLVMValueRef Fn, unsigned Index);
Gregory Szorc34c863a2012-03-21 03:54:29 +00001747
1748/**
1749 * Obtain the function to which this argument belongs.
1750 *
1751 * Unlike other functions in this group, this one takes a LLVMValueRef
1752 * that corresponds to a llvm::Attribute.
1753 *
1754 * The returned LLVMValueRef is the llvm::Function to which this
1755 * argument belongs.
1756 */
Gordon Henriksen265f7802008-03-19 01:11:35 +00001757LLVMValueRef LLVMGetParamParent(LLVMValueRef Inst);
Gregory Szorc34c863a2012-03-21 03:54:29 +00001758
1759/**
1760 * Obtain the first parameter to a function.
1761 *
1762 * @see llvm::Function::arg_begin()
1763 */
Gordon Henriksen07a45f42008-03-23 22:21:29 +00001764LLVMValueRef LLVMGetFirstParam(LLVMValueRef Fn);
Gregory Szorc34c863a2012-03-21 03:54:29 +00001765
1766/**
1767 * Obtain the last parameter to a function.
1768 *
1769 * @see llvm::Function::arg_end()
1770 */
Gordon Henriksen07a45f42008-03-23 22:21:29 +00001771LLVMValueRef LLVMGetLastParam(LLVMValueRef Fn);
Gregory Szorc34c863a2012-03-21 03:54:29 +00001772
1773/**
1774 * Obtain the next parameter to a function.
1775 *
1776 * This takes a LLVMValueRef obtained from LLVMGetFirstParam() (which is
1777 * actually a wrapped iterator) and obtains the next parameter from the
1778 * underlying iterator.
1779 */
Gordon Henriksen07a45f42008-03-23 22:21:29 +00001780LLVMValueRef LLVMGetNextParam(LLVMValueRef Arg);
Gregory Szorc34c863a2012-03-21 03:54:29 +00001781
1782/**
1783 * Obtain the previous parameter to a function.
1784 *
1785 * This is the opposite of LLVMGetNextParam().
1786 */
Gordon Henriksen07a45f42008-03-23 22:21:29 +00001787LLVMValueRef LLVMGetPreviousParam(LLVMValueRef Arg);
Gregory Szorc34c863a2012-03-21 03:54:29 +00001788
1789/**
1790 * Add an attribute to a function argument.
1791 *
1792 * @see llvm::Argument::addAttr()
1793 */
Devang Patel4c758ea2008-09-25 21:00:45 +00001794void LLVMAddAttribute(LLVMValueRef Arg, LLVMAttribute PA);
Gregory Szorc34c863a2012-03-21 03:54:29 +00001795
1796/**
1797 * Remove an attribute from a function argument.
1798 *
1799 * @see llvm::Argument::removeAttr()
1800 */
Devang Patel4c758ea2008-09-25 21:00:45 +00001801void LLVMRemoveAttribute(LLVMValueRef Arg, LLVMAttribute PA);
Gregory Szorc34c863a2012-03-21 03:54:29 +00001802
1803/**
1804 * Get an attribute from a function argument.
1805 */
Chris Lattner40cf28d2009-10-12 04:01:02 +00001806LLVMAttribute LLVMGetAttribute(LLVMValueRef Arg);
Gregory Szorc34c863a2012-03-21 03:54:29 +00001807
1808/**
1809 * Set the alignment for a function parameter.
1810 *
1811 * @see llvm::Argument::addAttr()
Bill Wendling50d27842012-10-15 20:35:56 +00001812 * @see llvm::AttrBuilder::addAlignmentAttr()
Gregory Szorc34c863a2012-03-21 03:54:29 +00001813 */
Gordon Henriksen2d9cc212008-04-28 17:37:06 +00001814void LLVMSetParamAlignment(LLVMValueRef Arg, unsigned align);
Gordon Henriksen265f7802008-03-19 01:11:35 +00001815
Gregory Szorc34c863a2012-03-21 03:54:29 +00001816/**
1817 * @}
1818 */
1819
1820/**
1821 * @}
1822 */
1823
1824/**
Gregory Szorc52d26602012-03-21 07:28:27 +00001825 * @}
1826 */
1827
1828/**
1829 * @}
1830 */
1831
1832/**
1833 * @defgroup LLVMCCoreValueMetadata Metadata
1834 *
1835 * @{
1836 */
1837
1838/**
1839 * Obtain a MDString value from a context.
1840 *
1841 * The returned instance corresponds to the llvm::MDString class.
1842 *
1843 * The instance is specified by string data of a specified length. The
1844 * string content is copied, so the backing memory can be freed after
1845 * this function returns.
1846 */
1847LLVMValueRef LLVMMDStringInContext(LLVMContextRef C, const char *Str,
1848 unsigned SLen);
1849
1850/**
1851 * Obtain a MDString value from the global context.
1852 */
1853LLVMValueRef LLVMMDString(const char *Str, unsigned SLen);
1854
1855/**
1856 * Obtain a MDNode value from a context.
1857 *
1858 * The returned value corresponds to the llvm::MDNode class.
1859 */
1860LLVMValueRef LLVMMDNodeInContext(LLVMContextRef C, LLVMValueRef *Vals,
1861 unsigned Count);
1862
1863/**
1864 * Obtain a MDNode value from the global context.
1865 */
1866LLVMValueRef LLVMMDNode(LLVMValueRef *Vals, unsigned Count);
1867
1868/**
1869 * Obtain the underlying string from a MDString value.
1870 *
1871 * @param V Instance to obtain string from.
1872 * @param Len Memory address which will hold length of returned string.
1873 * @return String data in MDString.
1874 */
1875const char *LLVMGetMDString(LLVMValueRef V, unsigned* Len);
1876
1877/**
Duncan Sands12ccbe72012-09-19 20:29:39 +00001878 * Obtain the number of operands from an MDNode value.
1879 *
1880 * @param V MDNode to get number of operands from.
1881 * @return Number of operands of the MDNode.
1882 */
1883unsigned LLVMGetMDNodeNumOperands(LLVMValueRef V);
1884
1885/**
1886 * Obtain the given MDNode's operands.
1887 *
1888 * The passed LLVMValueRef pointer should point to enough memory to hold all of
1889 * the operands of the given MDNode (see LLVMGetMDNodeNumOperands) as
1890 * LLVMValueRefs. This memory will be populated with the LLVMValueRefs of the
1891 * MDNode's operands.
1892 *
1893 * @param V MDNode to get the operands from.
1894 * @param Dest Destination array for operands.
1895 */
1896void LLVMGetMDNodeOperands(LLVMValueRef V, LLVMValueRef *Dest);
1897
1898/**
Gregory Szorc52d26602012-03-21 07:28:27 +00001899 * @}
1900 */
1901
1902/**
Gregory Szorc34c863a2012-03-21 03:54:29 +00001903 * @defgroup LLVMCCoreValueBasicBlock Basic Block
1904 *
1905 * A basic block represents a single entry single exit section of code.
1906 * Basic blocks contain a list of instructions which form the body of
1907 * the block.
1908 *
1909 * Basic blocks belong to functions. They have the type of label.
1910 *
1911 * Basic blocks are themselves values. However, the C API models them as
1912 * LLVMBasicBlockRef.
1913 *
1914 * @see llvm::BasicBlock
1915 *
1916 * @{
1917 */
1918
1919/**
1920 * Convert a basic block instance to a value type.
1921 */
Gordon Henriksen07a45f42008-03-23 22:21:29 +00001922LLVMValueRef LLVMBasicBlockAsValue(LLVMBasicBlockRef BB);
Gregory Szorc34c863a2012-03-21 03:54:29 +00001923
1924/**
1925 * Determine whether a LLVMValueRef is itself a basic block.
1926 */
Chris Lattner25963c62010-01-09 22:27:07 +00001927LLVMBool LLVMValueIsBasicBlock(LLVMValueRef Val);
Gregory Szorc34c863a2012-03-21 03:54:29 +00001928
1929/**
1930 * Convert a LLVMValueRef to a LLVMBasicBlockRef instance.
1931 */
Gordon Henriksenc23b66c2007-09-26 20:56:12 +00001932LLVMBasicBlockRef LLVMValueAsBasicBlock(LLVMValueRef Val);
Gregory Szorc34c863a2012-03-21 03:54:29 +00001933
1934/**
1935 * Obtain the function to which a basic block belongs.
1936 *
1937 * @see llvm::BasicBlock::getParent()
1938 */
Gordon Henriksen07a45f42008-03-23 22:21:29 +00001939LLVMValueRef LLVMGetBasicBlockParent(LLVMBasicBlockRef BB);
Gregory Szorc34c863a2012-03-21 03:54:29 +00001940
1941/**
1942 * Obtain the terminator instruction for a basic block.
1943 *
1944 * If the basic block does not have a terminator (it is not well-formed
1945 * if it doesn't), then NULL is returned.
1946 *
1947 * The returned LLVMValueRef corresponds to a llvm::TerminatorInst.
1948 *
1949 * @see llvm::BasicBlock::getTerminator()
1950 */
Nate Begeman43c322b2011-08-23 20:27:46 +00001951LLVMValueRef LLVMGetBasicBlockTerminator(LLVMBasicBlockRef BB);
Gregory Szorc34c863a2012-03-21 03:54:29 +00001952
1953/**
1954 * Obtain the number of basic blocks in a function.
1955 *
1956 * @param Fn Function value to operate on.
1957 */
Gordon Henriksenc23b66c2007-09-26 20:56:12 +00001958unsigned LLVMCountBasicBlocks(LLVMValueRef Fn);
Gregory Szorc34c863a2012-03-21 03:54:29 +00001959
1960/**
1961 * Obtain all of the basic blocks in a function.
1962 *
1963 * This operates on a function value. The BasicBlocks parameter is a
1964 * pointer to a pre-allocated array of LLVMBasicBlockRef of at least
1965 * LLVMCountBasicBlocks() in length. This array is populated with
1966 * LLVMBasicBlockRef instances.
1967 */
Gordon Henriksenc23b66c2007-09-26 20:56:12 +00001968void LLVMGetBasicBlocks(LLVMValueRef Fn, LLVMBasicBlockRef *BasicBlocks);
Gregory Szorc34c863a2012-03-21 03:54:29 +00001969
1970/**
1971 * Obtain the first basic block in a function.
1972 *
1973 * The returned basic block can be used as an iterator. You will likely
1974 * eventually call into LLVMGetNextBasicBlock() with it.
1975 *
1976 * @see llvm::Function::begin()
1977 */
Gordon Henriksen054817c2008-03-19 03:47:18 +00001978LLVMBasicBlockRef LLVMGetFirstBasicBlock(LLVMValueRef Fn);
Gregory Szorc34c863a2012-03-21 03:54:29 +00001979
1980/**
1981 * Obtain the last basic block in a function.
1982 *
1983 * @see llvm::Function::end()
1984 */
Gordon Henriksen054817c2008-03-19 03:47:18 +00001985LLVMBasicBlockRef LLVMGetLastBasicBlock(LLVMValueRef Fn);
Gregory Szorc34c863a2012-03-21 03:54:29 +00001986
1987/**
1988 * Advance a basic block iterator.
1989 */
Gordon Henriksen054817c2008-03-19 03:47:18 +00001990LLVMBasicBlockRef LLVMGetNextBasicBlock(LLVMBasicBlockRef BB);
Gregory Szorc34c863a2012-03-21 03:54:29 +00001991
1992/**
1993 * Go backwards in a basic block iterator.
1994 */
Gordon Henriksen054817c2008-03-19 03:47:18 +00001995LLVMBasicBlockRef LLVMGetPreviousBasicBlock(LLVMBasicBlockRef BB);
Gregory Szorc34c863a2012-03-21 03:54:29 +00001996
1997/**
1998 * Obtain the basic block that corresponds to the entry point of a
1999 * function.
2000 *
2001 * @see llvm::Function::getEntryBlock()
2002 */
Gordon Henriksenc23b66c2007-09-26 20:56:12 +00002003LLVMBasicBlockRef LLVMGetEntryBasicBlock(LLVMValueRef Fn);
Erick Tryzelaar262332f2009-08-14 00:01:31 +00002004
Gregory Szorc34c863a2012-03-21 03:54:29 +00002005/**
2006 * Append a basic block to the end of a function.
2007 *
2008 * @see llvm::BasicBlock::Create()
2009 */
Erick Tryzelaar262332f2009-08-14 00:01:31 +00002010LLVMBasicBlockRef LLVMAppendBasicBlockInContext(LLVMContextRef C,
2011 LLVMValueRef Fn,
2012 const char *Name);
Gregory Szorc34c863a2012-03-21 03:54:29 +00002013
2014/**
2015 * Append a basic block to the end of a function using the global
2016 * context.
2017 *
2018 * @see llvm::BasicBlock::Create()
2019 */
2020LLVMBasicBlockRef LLVMAppendBasicBlock(LLVMValueRef Fn, const char *Name);
2021
2022/**
2023 * Insert a basic block in a function before another basic block.
2024 *
2025 * The function to add to is determined by the function of the
2026 * passed basic block.
2027 *
2028 * @see llvm::BasicBlock::Create()
2029 */
Erick Tryzelaar262332f2009-08-14 00:01:31 +00002030LLVMBasicBlockRef LLVMInsertBasicBlockInContext(LLVMContextRef C,
2031 LLVMBasicBlockRef BB,
2032 const char *Name);
2033
Gregory Szorc34c863a2012-03-21 03:54:29 +00002034/**
2035 * Insert a basic block in a function using the global context.
2036 *
2037 * @see llvm::BasicBlock::Create()
2038 */
Gordon Henriksenc23b66c2007-09-26 20:56:12 +00002039LLVMBasicBlockRef LLVMInsertBasicBlock(LLVMBasicBlockRef InsertBeforeBB,
2040 const char *Name);
Gregory Szorc34c863a2012-03-21 03:54:29 +00002041
2042/**
2043 * Remove a basic block from a function and delete it.
2044 *
2045 * This deletes the basic block from its containing function and deletes
2046 * the basic block itself.
2047 *
2048 * @see llvm::BasicBlock::eraseFromParent()
2049 */
Gordon Henriksenc23b66c2007-09-26 20:56:12 +00002050void LLVMDeleteBasicBlock(LLVMBasicBlockRef BB);
Gregory Szorc34c863a2012-03-21 03:54:29 +00002051
2052/**
2053 * Remove a basic block from a function.
2054 *
2055 * This deletes the basic block from its containing function but keep
2056 * the basic block alive.
2057 *
2058 * @see llvm::BasicBlock::removeFromParent()
2059 */
Nate Begeman43c322b2011-08-23 20:27:46 +00002060void LLVMRemoveBasicBlockFromParent(LLVMBasicBlockRef BB);
Gordon Henriksenc23b66c2007-09-26 20:56:12 +00002061
Gregory Szorc34c863a2012-03-21 03:54:29 +00002062/**
2063 * Move a basic block to before another one.
2064 *
2065 * @see llvm::BasicBlock::moveBefore()
2066 */
Duncan Sandsb1d61aa2010-07-19 15:31:07 +00002067void LLVMMoveBasicBlockBefore(LLVMBasicBlockRef BB, LLVMBasicBlockRef MovePos);
Gregory Szorc34c863a2012-03-21 03:54:29 +00002068
2069/**
2070 * Move a basic block to after another one.
2071 *
2072 * @see llvm::BasicBlock::moveAfter()
2073 */
Duncan Sandsb1d61aa2010-07-19 15:31:07 +00002074void LLVMMoveBasicBlockAfter(LLVMBasicBlockRef BB, LLVMBasicBlockRef MovePos);
2075
Gregory Szorc34c863a2012-03-21 03:54:29 +00002076/**
2077 * Obtain the first instruction in a basic block.
2078 *
2079 * The returned LLVMValueRef corresponds to a llvm::Instruction
2080 * instance.
2081 */
Gordon Henriksen054817c2008-03-19 03:47:18 +00002082LLVMValueRef LLVMGetFirstInstruction(LLVMBasicBlockRef BB);
Gregory Szorc34c863a2012-03-21 03:54:29 +00002083
2084/**
2085 * Obtain the last instruction in a basic block.
2086 *
2087 * The returned LLVMValueRef corresponds to a LLVM:Instruction.
2088 */
Gordon Henriksen054817c2008-03-19 03:47:18 +00002089LLVMValueRef LLVMGetLastInstruction(LLVMBasicBlockRef BB);
Nate Begeman43c322b2011-08-23 20:27:46 +00002090
Gregory Szorc34c863a2012-03-21 03:54:29 +00002091/**
2092 * @}
2093 */
2094
2095/**
2096 * @defgroup LLVMCCoreValueInstruction Instructions
2097 *
2098 * Functions in this group relate to the inspection and manipulation of
2099 * individual instructions.
2100 *
2101 * In the C++ API, an instruction is modeled by llvm::Instruction. This
2102 * class has a large number of descendents. llvm::Instruction is a
2103 * llvm::Value and in the C API, instructions are modeled by
2104 * LLVMValueRef.
2105 *
2106 * This group also contains sub-groups which operate on specific
2107 * llvm::Instruction types, e.g. llvm::CallInst.
2108 *
2109 * @{
2110 */
2111
2112/**
2113 * Determine whether an instruction has any metadata attached.
2114 */
2115int LLVMHasMetadata(LLVMValueRef Val);
2116
2117/**
2118 * Return metadata associated with an instruction value.
2119 */
2120LLVMValueRef LLVMGetMetadata(LLVMValueRef Val, unsigned KindID);
2121
2122/**
2123 * Set metadata associated with an instruction value.
2124 */
2125void LLVMSetMetadata(LLVMValueRef Val, unsigned KindID, LLVMValueRef Node);
2126
2127/**
2128 * Obtain the basic block to which an instruction belongs.
2129 *
2130 * @see llvm::Instruction::getParent()
2131 */
Nate Begeman43c322b2011-08-23 20:27:46 +00002132LLVMBasicBlockRef LLVMGetInstructionParent(LLVMValueRef Inst);
Gregory Szorc34c863a2012-03-21 03:54:29 +00002133
2134/**
2135 * Obtain the instruction that occurs after the one specified.
2136 *
2137 * The next instruction will be from the same basic block.
2138 *
2139 * If this is the last instruction in a basic block, NULL will be
2140 * returned.
2141 */
Gordon Henriksen054817c2008-03-19 03:47:18 +00002142LLVMValueRef LLVMGetNextInstruction(LLVMValueRef Inst);
Gregory Szorc34c863a2012-03-21 03:54:29 +00002143
2144/**
Benjamin Kramerbde91762012-06-02 10:20:22 +00002145 * Obtain the instruction that occurred before this one.
Gregory Szorc34c863a2012-03-21 03:54:29 +00002146 *
2147 * If the instruction is the first instruction in a basic block, NULL
2148 * will be returned.
2149 */
Gordon Henriksen054817c2008-03-19 03:47:18 +00002150LLVMValueRef LLVMGetPreviousInstruction(LLVMValueRef Inst);
Gregory Szorc34c863a2012-03-21 03:54:29 +00002151
2152/**
2153 * Remove and delete an instruction.
2154 *
2155 * The instruction specified is removed from its containing building
2156 * block and then deleted.
2157 *
2158 * @see llvm::Instruction::eraseFromParent()
2159 */
Devang Pateldbebc6f2011-10-03 20:59:18 +00002160void LLVMInstructionEraseFromParent(LLVMValueRef Inst);
Gregory Szorc34c863a2012-03-21 03:54:29 +00002161
2162/**
2163 * Obtain the code opcode for an individual instruction.
2164 *
2165 * @see llvm::Instruction::getOpCode()
2166 */
Torok Edwinab6158e2011-10-14 20:37:49 +00002167LLVMOpcode LLVMGetInstructionOpcode(LLVMValueRef Inst);
Gregory Szorc34c863a2012-03-21 03:54:29 +00002168
2169/**
2170 * Obtain the predicate of an instruction.
2171 *
2172 * This is only valid for instructions that correspond to llvm::ICmpInst
2173 * or llvm::ConstantExpr whose opcode is llvm::Instruction::ICmp.
2174 *
2175 * @see llvm::ICmpInst::getPredicate()
2176 */
Torok Edwin60c40de2011-10-06 12:13:20 +00002177LLVMIntPredicate LLVMGetICmpPredicate(LLVMValueRef Inst);
Gordon Henriksen265f7802008-03-19 01:11:35 +00002178
Gregory Szorc34c863a2012-03-21 03:54:29 +00002179/**
2180 * @defgroup LLVMCCoreValueInstructionCall Call Sites and Invocations
2181 *
2182 * Functions in this group apply to instructions that refer to call
2183 * sites and invocations. These correspond to C++ types in the
2184 * llvm::CallInst class tree.
2185 *
2186 * @{
2187 */
2188
2189/**
2190 * Set the calling convention for a call instruction.
2191 *
2192 * This expects an LLVMValueRef that corresponds to a llvm::CallInst or
2193 * llvm::InvokeInst.
2194 *
2195 * @see llvm::CallInst::setCallingConv()
2196 * @see llvm::InvokeInst::setCallingConv()
2197 */
Gordon Henriksen1158c532007-12-29 20:45:00 +00002198void LLVMSetInstructionCallConv(LLVMValueRef Instr, unsigned CC);
Gregory Szorc34c863a2012-03-21 03:54:29 +00002199
2200/**
2201 * Obtain the calling convention for a call instruction.
2202 *
2203 * This is the opposite of LLVMSetInstructionCallConv(). Reads its
2204 * usage.
2205 *
2206 * @see LLVMSetInstructionCallConv()
2207 */
Gordon Henriksen1158c532007-12-29 20:45:00 +00002208unsigned LLVMGetInstructionCallConv(LLVMValueRef Instr);
Gregory Szorc34c863a2012-03-21 03:54:29 +00002209
2210
Devang Patel4c758ea2008-09-25 21:00:45 +00002211void LLVMAddInstrAttribute(LLVMValueRef Instr, unsigned index, LLVMAttribute);
Gregory Szorc34c863a2012-03-21 03:54:29 +00002212void LLVMRemoveInstrAttribute(LLVMValueRef Instr, unsigned index,
Devang Patel4c758ea2008-09-25 21:00:45 +00002213 LLVMAttribute);
Gregory Szorc34c863a2012-03-21 03:54:29 +00002214void LLVMSetInstrParamAlignment(LLVMValueRef Instr, unsigned index,
Gordon Henriksen2d9cc212008-04-28 17:37:06 +00002215 unsigned align);
Gordon Henriksen1158c532007-12-29 20:45:00 +00002216
Gregory Szorc34c863a2012-03-21 03:54:29 +00002217/**
2218 * Obtain whether a call instruction is a tail call.
2219 *
2220 * This only works on llvm::CallInst instructions.
2221 *
2222 * @see llvm::CallInst::isTailCall()
2223 */
Chris Lattner25963c62010-01-09 22:27:07 +00002224LLVMBool LLVMIsTailCall(LLVMValueRef CallInst);
Gregory Szorc34c863a2012-03-21 03:54:29 +00002225
2226/**
2227 * Set whether a call instruction is a tail call.
2228 *
2229 * This only works on llvm::CallInst instructions.
2230 *
2231 * @see llvm::CallInst::setTailCall()
2232 */
Chris Lattner25963c62010-01-09 22:27:07 +00002233void LLVMSetTailCall(LLVMValueRef CallInst, LLVMBool IsTailCall);
Gordon Henrikseneeb65372008-08-30 16:34:54 +00002234
Gregory Szorc34c863a2012-03-21 03:54:29 +00002235/**
2236 * @}
2237 */
2238
2239/**
2240 * Obtain the default destination basic block of a switch instruction.
2241 *
2242 * This only works on llvm::SwitchInst instructions.
2243 *
2244 * @see llvm::SwitchInst::getDefaultDest()
2245 */
Nate Begeman43c322b2011-08-23 20:27:46 +00002246LLVMBasicBlockRef LLVMGetSwitchDefaultDest(LLVMValueRef SwitchInstr);
2247
Gregory Szorc34c863a2012-03-21 03:54:29 +00002248/**
2249 * @defgroup LLVMCCoreValueInstructionPHINode PHI Nodes
2250 *
2251 * Functions in this group only apply to instructions that map to
2252 * llvm::PHINode instances.
2253 *
2254 * @{
2255 */
2256
2257/**
2258 * Add an incoming value to the end of a PHI list.
2259 */
Gordon Henriksen44dd8fb2007-10-08 18:14:39 +00002260void LLVMAddIncoming(LLVMValueRef PhiNode, LLVMValueRef *IncomingValues,
2261 LLVMBasicBlockRef *IncomingBlocks, unsigned Count);
Gregory Szorc34c863a2012-03-21 03:54:29 +00002262
2263/**
2264 * Obtain the number of incoming basic blocks to a PHI node.
2265 */
Gordon Henriksen44dd8fb2007-10-08 18:14:39 +00002266unsigned LLVMCountIncoming(LLVMValueRef PhiNode);
Gregory Szorc34c863a2012-03-21 03:54:29 +00002267
2268/**
2269 * Obtain an incoming value to a PHI node as a LLVMValueRef.
2270 */
Gordon Henriksen44dd8fb2007-10-08 18:14:39 +00002271LLVMValueRef LLVMGetIncomingValue(LLVMValueRef PhiNode, unsigned Index);
Gregory Szorc34c863a2012-03-21 03:54:29 +00002272
2273/**
2274 * Obtain an incoming value to a PHI node as a LLVMBasicBlockRef.
2275 */
Gordon Henriksen44dd8fb2007-10-08 18:14:39 +00002276LLVMBasicBlockRef LLVMGetIncomingBlock(LLVMValueRef PhiNode, unsigned Index);
Gordon Henriksenc23b66c2007-09-26 20:56:12 +00002277
Gregory Szorc34c863a2012-03-21 03:54:29 +00002278/**
2279 * @}
2280 */
Gordon Henriksenc23b66c2007-09-26 20:56:12 +00002281
Gregory Szorc34c863a2012-03-21 03:54:29 +00002282/**
2283 * @}
2284 */
2285
2286/**
2287 * @}
2288 */
2289
2290/**
2291 * @defgroup LLVMCCoreInstructionBuilder Instruction Builders
2292 *
2293 * An instruction builder represents a point within a basic block and is
2294 * the exclusive means of building instructions using the C interface.
2295 *
2296 * @{
Gordon Henriksenc23b66c2007-09-26 20:56:12 +00002297 */
2298
Erick Tryzelaar262332f2009-08-14 00:01:31 +00002299LLVMBuilderRef LLVMCreateBuilderInContext(LLVMContextRef C);
Gordon Henriksena735a9c2008-05-04 12:55:34 +00002300LLVMBuilderRef LLVMCreateBuilder(void);
Gordon Henriksen054817c2008-03-19 03:47:18 +00002301void LLVMPositionBuilder(LLVMBuilderRef Builder, LLVMBasicBlockRef Block,
2302 LLVMValueRef Instr);
Gordon Henriksenc23b66c2007-09-26 20:56:12 +00002303void LLVMPositionBuilderBefore(LLVMBuilderRef Builder, LLVMValueRef Instr);
2304void LLVMPositionBuilderAtEnd(LLVMBuilderRef Builder, LLVMBasicBlockRef Block);
Gordon Henriksen265f7802008-03-19 01:11:35 +00002305LLVMBasicBlockRef LLVMGetInsertBlock(LLVMBuilderRef Builder);
Chris Lattner3d1f5522008-12-17 21:39:50 +00002306void LLVMClearInsertionPosition(LLVMBuilderRef Builder);
2307void LLVMInsertIntoBuilder(LLVMBuilderRef Builder, LLVMValueRef Instr);
Erick Tryzelaar9813bea2009-08-16 02:20:57 +00002308void LLVMInsertIntoBuilderWithName(LLVMBuilderRef Builder, LLVMValueRef Instr,
2309 const char *Name);
Gordon Henriksenc23b66c2007-09-26 20:56:12 +00002310void LLVMDisposeBuilder(LLVMBuilderRef Builder);
2311
Erick Tryzelaard8531fa2010-02-28 09:45:59 +00002312/* Metadata */
2313void LLVMSetCurrentDebugLocation(LLVMBuilderRef Builder, LLVMValueRef L);
2314LLVMValueRef LLVMGetCurrentDebugLocation(LLVMBuilderRef Builder);
2315void LLVMSetInstDebugLocation(LLVMBuilderRef Builder, LLVMValueRef Inst);
2316
Gordon Henriksenc23b66c2007-09-26 20:56:12 +00002317/* Terminators */
2318LLVMValueRef LLVMBuildRetVoid(LLVMBuilderRef);
2319LLVMValueRef LLVMBuildRet(LLVMBuilderRef, LLVMValueRef V);
Erick Tryzelaarfd529d72009-08-19 08:36:49 +00002320LLVMValueRef LLVMBuildAggregateRet(LLVMBuilderRef, LLVMValueRef *RetVals,
Erick Tryzelaar3045b8b2009-08-16 02:19:59 +00002321 unsigned N);
Gordon Henriksenc23b66c2007-09-26 20:56:12 +00002322LLVMValueRef LLVMBuildBr(LLVMBuilderRef, LLVMBasicBlockRef Dest);
2323LLVMValueRef LLVMBuildCondBr(LLVMBuilderRef, LLVMValueRef If,
2324 LLVMBasicBlockRef Then, LLVMBasicBlockRef Else);
2325LLVMValueRef LLVMBuildSwitch(LLVMBuilderRef, LLVMValueRef V,
2326 LLVMBasicBlockRef Else, unsigned NumCases);
Erick Tryzelaar0fb26ef2010-02-28 09:46:06 +00002327LLVMValueRef LLVMBuildIndirectBr(LLVMBuilderRef B, LLVMValueRef Addr,
2328 unsigned NumDests);
Gordon Henriksenc23b66c2007-09-26 20:56:12 +00002329LLVMValueRef LLVMBuildInvoke(LLVMBuilderRef, LLVMValueRef Fn,
2330 LLVMValueRef *Args, unsigned NumArgs,
2331 LLVMBasicBlockRef Then, LLVMBasicBlockRef Catch,
2332 const char *Name);
Benjamin Kramer5a6568832011-08-19 01:36:54 +00002333LLVMValueRef LLVMBuildLandingPad(LLVMBuilderRef B, LLVMTypeRef Ty,
2334 LLVMValueRef PersFn, unsigned NumClauses,
2335 const char *Name);
Bill Wendlingf891bf82011-07-31 06:30:59 +00002336LLVMValueRef LLVMBuildResume(LLVMBuilderRef B, LLVMValueRef Exn);
Gordon Henriksenc23b66c2007-09-26 20:56:12 +00002337LLVMValueRef LLVMBuildUnreachable(LLVMBuilderRef);
2338
Gordon Henriksen097102c2008-01-01 05:50:53 +00002339/* Add a case to the switch instruction */
2340void LLVMAddCase(LLVMValueRef Switch, LLVMValueRef OnVal,
2341 LLVMBasicBlockRef Dest);
2342
Erick Tryzelaar0fb26ef2010-02-28 09:46:06 +00002343/* Add a destination to the indirectbr instruction */
2344void LLVMAddDestination(LLVMValueRef IndirectBr, LLVMBasicBlockRef Dest);
2345
Bill Wendlingfae14752011-08-12 20:24:12 +00002346/* Add a catch or filter clause to the landingpad instruction */
2347void LLVMAddClause(LLVMValueRef LandingPad, LLVMValueRef ClauseVal);
2348
2349/* Set the 'cleanup' flag in the landingpad instruction */
2350void LLVMSetCleanup(LLVMValueRef LandingPad, LLVMBool Val);
2351
Gordon Henriksenc23b66c2007-09-26 20:56:12 +00002352/* Arithmetic */
2353LLVMValueRef LLVMBuildAdd(LLVMBuilderRef, LLVMValueRef LHS, LLVMValueRef RHS,
2354 const char *Name);
Erick Tryzelaar3045b8b2009-08-16 02:19:59 +00002355LLVMValueRef LLVMBuildNSWAdd(LLVMBuilderRef, LLVMValueRef LHS, LLVMValueRef RHS,
2356 const char *Name);
Erick Tryzelaar4c340c72010-02-28 05:51:43 +00002357LLVMValueRef LLVMBuildNUWAdd(LLVMBuilderRef, LLVMValueRef LHS, LLVMValueRef RHS,
2358 const char *Name);
Erick Tryzelaar3045b8b2009-08-16 02:19:59 +00002359LLVMValueRef LLVMBuildFAdd(LLVMBuilderRef, LLVMValueRef LHS, LLVMValueRef RHS,
2360 const char *Name);
Gordon Henriksenc23b66c2007-09-26 20:56:12 +00002361LLVMValueRef LLVMBuildSub(LLVMBuilderRef, LLVMValueRef LHS, LLVMValueRef RHS,
2362 const char *Name);
Erick Tryzelaar4c340c72010-02-28 05:51:43 +00002363LLVMValueRef LLVMBuildNSWSub(LLVMBuilderRef, LLVMValueRef LHS, LLVMValueRef RHS,
2364 const char *Name);
2365LLVMValueRef LLVMBuildNUWSub(LLVMBuilderRef, LLVMValueRef LHS, LLVMValueRef RHS,
2366 const char *Name);
Erick Tryzelaar3045b8b2009-08-16 02:19:59 +00002367LLVMValueRef LLVMBuildFSub(LLVMBuilderRef, LLVMValueRef LHS, LLVMValueRef RHS,
2368 const char *Name);
Gordon Henriksenc23b66c2007-09-26 20:56:12 +00002369LLVMValueRef LLVMBuildMul(LLVMBuilderRef, LLVMValueRef LHS, LLVMValueRef RHS,
2370 const char *Name);
Erick Tryzelaar4c340c72010-02-28 05:51:43 +00002371LLVMValueRef LLVMBuildNSWMul(LLVMBuilderRef, LLVMValueRef LHS, LLVMValueRef RHS,
2372 const char *Name);
2373LLVMValueRef LLVMBuildNUWMul(LLVMBuilderRef, LLVMValueRef LHS, LLVMValueRef RHS,
2374 const char *Name);
Erick Tryzelaar3045b8b2009-08-16 02:19:59 +00002375LLVMValueRef LLVMBuildFMul(LLVMBuilderRef, LLVMValueRef LHS, LLVMValueRef RHS,
2376 const char *Name);
Gordon Henriksenc23b66c2007-09-26 20:56:12 +00002377LLVMValueRef LLVMBuildUDiv(LLVMBuilderRef, LLVMValueRef LHS, LLVMValueRef RHS,
2378 const char *Name);
2379LLVMValueRef LLVMBuildSDiv(LLVMBuilderRef, LLVMValueRef LHS, LLVMValueRef RHS,
2380 const char *Name);
Erick Tryzelaar3045b8b2009-08-16 02:19:59 +00002381LLVMValueRef LLVMBuildExactSDiv(LLVMBuilderRef, LLVMValueRef LHS, LLVMValueRef RHS,
2382 const char *Name);
Gordon Henriksenc23b66c2007-09-26 20:56:12 +00002383LLVMValueRef LLVMBuildFDiv(LLVMBuilderRef, LLVMValueRef LHS, LLVMValueRef RHS,
2384 const char *Name);
2385LLVMValueRef LLVMBuildURem(LLVMBuilderRef, LLVMValueRef LHS, LLVMValueRef RHS,
2386 const char *Name);
2387LLVMValueRef LLVMBuildSRem(LLVMBuilderRef, LLVMValueRef LHS, LLVMValueRef RHS,
2388 const char *Name);
2389LLVMValueRef LLVMBuildFRem(LLVMBuilderRef, LLVMValueRef LHS, LLVMValueRef RHS,
2390 const char *Name);
2391LLVMValueRef LLVMBuildShl(LLVMBuilderRef, LLVMValueRef LHS, LLVMValueRef RHS,
2392 const char *Name);
2393LLVMValueRef LLVMBuildLShr(LLVMBuilderRef, LLVMValueRef LHS, LLVMValueRef RHS,
2394 const char *Name);
2395LLVMValueRef LLVMBuildAShr(LLVMBuilderRef, LLVMValueRef LHS, LLVMValueRef RHS,
2396 const char *Name);
2397LLVMValueRef LLVMBuildAnd(LLVMBuilderRef, LLVMValueRef LHS, LLVMValueRef RHS,
2398 const char *Name);
2399LLVMValueRef LLVMBuildOr(LLVMBuilderRef, LLVMValueRef LHS, LLVMValueRef RHS,
2400 const char *Name);
2401LLVMValueRef LLVMBuildXor(LLVMBuilderRef, LLVMValueRef LHS, LLVMValueRef RHS,
2402 const char *Name);
Erick Tryzelaar31831792010-02-28 05:51:27 +00002403LLVMValueRef LLVMBuildBinOp(LLVMBuilderRef B, LLVMOpcode Op,
2404 LLVMValueRef LHS, LLVMValueRef RHS,
2405 const char *Name);
Gordon Henriksenc23b66c2007-09-26 20:56:12 +00002406LLVMValueRef LLVMBuildNeg(LLVMBuilderRef, LLVMValueRef V, const char *Name);
Erick Tryzelaar4c340c72010-02-28 05:51:43 +00002407LLVMValueRef LLVMBuildNSWNeg(LLVMBuilderRef B, LLVMValueRef V,
2408 const char *Name);
2409LLVMValueRef LLVMBuildNUWNeg(LLVMBuilderRef B, LLVMValueRef V,
2410 const char *Name);
Dan Gohmanf919bd62009-09-28 21:51:41 +00002411LLVMValueRef LLVMBuildFNeg(LLVMBuilderRef, LLVMValueRef V, const char *Name);
Gordon Henriksenc23b66c2007-09-26 20:56:12 +00002412LLVMValueRef LLVMBuildNot(LLVMBuilderRef, LLVMValueRef V, const char *Name);
2413
2414/* Memory */
2415LLVMValueRef LLVMBuildMalloc(LLVMBuilderRef, LLVMTypeRef Ty, const char *Name);
2416LLVMValueRef LLVMBuildArrayMalloc(LLVMBuilderRef, LLVMTypeRef Ty,
2417 LLVMValueRef Val, const char *Name);
2418LLVMValueRef LLVMBuildAlloca(LLVMBuilderRef, LLVMTypeRef Ty, const char *Name);
2419LLVMValueRef LLVMBuildArrayAlloca(LLVMBuilderRef, LLVMTypeRef Ty,
2420 LLVMValueRef Val, const char *Name);
2421LLVMValueRef LLVMBuildFree(LLVMBuilderRef, LLVMValueRef PointerVal);
2422LLVMValueRef LLVMBuildLoad(LLVMBuilderRef, LLVMValueRef PointerVal,
2423 const char *Name);
2424LLVMValueRef LLVMBuildStore(LLVMBuilderRef, LLVMValueRef Val, LLVMValueRef Ptr);
2425LLVMValueRef LLVMBuildGEP(LLVMBuilderRef B, LLVMValueRef Pointer,
2426 LLVMValueRef *Indices, unsigned NumIndices,
2427 const char *Name);
Erick Tryzelaar3045b8b2009-08-16 02:19:59 +00002428LLVMValueRef LLVMBuildInBoundsGEP(LLVMBuilderRef B, LLVMValueRef Pointer,
2429 LLVMValueRef *Indices, unsigned NumIndices,
2430 const char *Name);
2431LLVMValueRef LLVMBuildStructGEP(LLVMBuilderRef B, LLVMValueRef Pointer,
2432 unsigned Idx, const char *Name);
2433LLVMValueRef LLVMBuildGlobalString(LLVMBuilderRef B, const char *Str,
2434 const char *Name);
2435LLVMValueRef LLVMBuildGlobalStringPtr(LLVMBuilderRef B, const char *Str,
2436 const char *Name);
Chris Lattner2cc6f9d2012-03-22 03:54:15 +00002437LLVMBool LLVMGetVolatile(LLVMValueRef MemoryAccessInst);
2438void LLVMSetVolatile(LLVMValueRef MemoryAccessInst, LLVMBool IsVolatile);
Gordon Henriksenc23b66c2007-09-26 20:56:12 +00002439
2440/* Casts */
2441LLVMValueRef LLVMBuildTrunc(LLVMBuilderRef, LLVMValueRef Val,
2442 LLVMTypeRef DestTy, const char *Name);
2443LLVMValueRef LLVMBuildZExt(LLVMBuilderRef, LLVMValueRef Val,
2444 LLVMTypeRef DestTy, const char *Name);
2445LLVMValueRef LLVMBuildSExt(LLVMBuilderRef, LLVMValueRef Val,
2446 LLVMTypeRef DestTy, const char *Name);
2447LLVMValueRef LLVMBuildFPToUI(LLVMBuilderRef, LLVMValueRef Val,
2448 LLVMTypeRef DestTy, const char *Name);
2449LLVMValueRef LLVMBuildFPToSI(LLVMBuilderRef, LLVMValueRef Val,
2450 LLVMTypeRef DestTy, const char *Name);
2451LLVMValueRef LLVMBuildUIToFP(LLVMBuilderRef, LLVMValueRef Val,
2452 LLVMTypeRef DestTy, const char *Name);
2453LLVMValueRef LLVMBuildSIToFP(LLVMBuilderRef, LLVMValueRef Val,
2454 LLVMTypeRef DestTy, const char *Name);
2455LLVMValueRef LLVMBuildFPTrunc(LLVMBuilderRef, LLVMValueRef Val,
2456 LLVMTypeRef DestTy, const char *Name);
2457LLVMValueRef LLVMBuildFPExt(LLVMBuilderRef, LLVMValueRef Val,
2458 LLVMTypeRef DestTy, const char *Name);
2459LLVMValueRef LLVMBuildPtrToInt(LLVMBuilderRef, LLVMValueRef Val,
2460 LLVMTypeRef DestTy, const char *Name);
2461LLVMValueRef LLVMBuildIntToPtr(LLVMBuilderRef, LLVMValueRef Val,
2462 LLVMTypeRef DestTy, const char *Name);
2463LLVMValueRef LLVMBuildBitCast(LLVMBuilderRef, LLVMValueRef Val,
2464 LLVMTypeRef DestTy, const char *Name);
Erick Tryzelaar3045b8b2009-08-16 02:19:59 +00002465LLVMValueRef LLVMBuildZExtOrBitCast(LLVMBuilderRef, LLVMValueRef Val,
2466 LLVMTypeRef DestTy, const char *Name);
2467LLVMValueRef LLVMBuildSExtOrBitCast(LLVMBuilderRef, LLVMValueRef Val,
2468 LLVMTypeRef DestTy, const char *Name);
2469LLVMValueRef LLVMBuildTruncOrBitCast(LLVMBuilderRef, LLVMValueRef Val,
2470 LLVMTypeRef DestTy, const char *Name);
Erick Tryzelaar31831792010-02-28 05:51:27 +00002471LLVMValueRef LLVMBuildCast(LLVMBuilderRef B, LLVMOpcode Op, LLVMValueRef Val,
2472 LLVMTypeRef DestTy, const char *Name);
Erick Tryzelaar3045b8b2009-08-16 02:19:59 +00002473LLVMValueRef LLVMBuildPointerCast(LLVMBuilderRef, LLVMValueRef Val,
2474 LLVMTypeRef DestTy, const char *Name);
Duncan Sands9d786d72009-11-23 10:49:03 +00002475LLVMValueRef LLVMBuildIntCast(LLVMBuilderRef, LLVMValueRef Val, /*Signed cast!*/
Erick Tryzelaar3045b8b2009-08-16 02:19:59 +00002476 LLVMTypeRef DestTy, const char *Name);
2477LLVMValueRef LLVMBuildFPCast(LLVMBuilderRef, LLVMValueRef Val,
2478 LLVMTypeRef DestTy, const char *Name);
Gordon Henriksenc23b66c2007-09-26 20:56:12 +00002479
2480/* Comparisons */
2481LLVMValueRef LLVMBuildICmp(LLVMBuilderRef, LLVMIntPredicate Op,
2482 LLVMValueRef LHS, LLVMValueRef RHS,
2483 const char *Name);
2484LLVMValueRef LLVMBuildFCmp(LLVMBuilderRef, LLVMRealPredicate Op,
2485 LLVMValueRef LHS, LLVMValueRef RHS,
2486 const char *Name);
2487
2488/* Miscellaneous instructions */
2489LLVMValueRef LLVMBuildPhi(LLVMBuilderRef, LLVMTypeRef Ty, const char *Name);
2490LLVMValueRef LLVMBuildCall(LLVMBuilderRef, LLVMValueRef Fn,
2491 LLVMValueRef *Args, unsigned NumArgs,
2492 const char *Name);
2493LLVMValueRef LLVMBuildSelect(LLVMBuilderRef, LLVMValueRef If,
2494 LLVMValueRef Then, LLVMValueRef Else,
2495 const char *Name);
2496LLVMValueRef LLVMBuildVAArg(LLVMBuilderRef, LLVMValueRef List, LLVMTypeRef Ty,
2497 const char *Name);
2498LLVMValueRef LLVMBuildExtractElement(LLVMBuilderRef, LLVMValueRef VecVal,
2499 LLVMValueRef Index, const char *Name);
2500LLVMValueRef LLVMBuildInsertElement(LLVMBuilderRef, LLVMValueRef VecVal,
2501 LLVMValueRef EltVal, LLVMValueRef Index,
2502 const char *Name);
2503LLVMValueRef LLVMBuildShuffleVector(LLVMBuilderRef, LLVMValueRef V1,
2504 LLVMValueRef V2, LLVMValueRef Mask,
2505 const char *Name);
Dan Gohmand5104a52008-11-03 22:55:43 +00002506LLVMValueRef LLVMBuildExtractValue(LLVMBuilderRef, LLVMValueRef AggVal,
2507 unsigned Index, const char *Name);
2508LLVMValueRef LLVMBuildInsertValue(LLVMBuilderRef, LLVMValueRef AggVal,
2509 LLVMValueRef EltVal, unsigned Index,
2510 const char *Name);
Gordon Henriksen76a03742007-09-18 03:18:57 +00002511
Erick Tryzelaar3045b8b2009-08-16 02:19:59 +00002512LLVMValueRef LLVMBuildIsNull(LLVMBuilderRef, LLVMValueRef Val,
2513 const char *Name);
2514LLVMValueRef LLVMBuildIsNotNull(LLVMBuilderRef, LLVMValueRef Val,
2515 const char *Name);
2516LLVMValueRef LLVMBuildPtrDiff(LLVMBuilderRef, LLVMValueRef LHS,
2517 LLVMValueRef RHS, const char *Name);
2518
Gregory Szorc34c863a2012-03-21 03:54:29 +00002519/**
2520 * @}
2521 */
Gordon Henriksen34eb6d82007-12-19 22:30:40 +00002522
Gregory Szorc34c863a2012-03-21 03:54:29 +00002523/**
2524 * @defgroup LLVMCCoreModuleProvider Module Providers
2525 *
2526 * @{
2527 */
Gordon Henriksen0a68fe22007-12-12 01:04:30 +00002528
Gregory Szorc34c863a2012-03-21 03:54:29 +00002529/**
2530 * Changes the type of M so it can be passed to FunctionPassManagers and the
Jeffrey Yasskin091217b2010-01-27 20:34:15 +00002531 * JIT. They take ModuleProviders for historical reasons.
Gordon Henriksen0a68fe22007-12-12 01:04:30 +00002532 */
2533LLVMModuleProviderRef
2534LLVMCreateModuleProviderForExistingModule(LLVMModuleRef M);
2535
Gregory Szorc34c863a2012-03-21 03:54:29 +00002536/**
2537 * Destroys the module M.
Gordon Henriksen0a68fe22007-12-12 01:04:30 +00002538 */
Jeffrey Yasskin091217b2010-01-27 20:34:15 +00002539void LLVMDisposeModuleProvider(LLVMModuleProviderRef M);
Gordon Henriksen0a68fe22007-12-12 01:04:30 +00002540
Gregory Szorc34c863a2012-03-21 03:54:29 +00002541/**
2542 * @}
2543 */
Gordon Henriksen34eb6d82007-12-19 22:30:40 +00002544
Gregory Szorc34c863a2012-03-21 03:54:29 +00002545/**
2546 * @defgroup LLVMCCoreMemoryBuffers Memory Buffers
2547 *
2548 * @{
2549 */
Gordon Henriksen34eb6d82007-12-19 22:30:40 +00002550
Chris Lattner25963c62010-01-09 22:27:07 +00002551LLVMBool LLVMCreateMemoryBufferWithContentsOfFile(const char *Path,
2552 LLVMMemoryBufferRef *OutMemBuf,
2553 char **OutMessage);
2554LLVMBool LLVMCreateMemoryBufferWithSTDIN(LLVMMemoryBufferRef *OutMemBuf,
2555 char **OutMessage);
Bill Wendling526276a2013-02-14 19:11:28 +00002556LLVMMemoryBufferRef LLVMCreateMemoryBufferWithMemoryRange(const char *InputData,
2557 size_t InputDataLength,
2558 const char *BufferName,
Bill Wendlingc9baa962013-02-14 19:39:14 +00002559 LLVMBool RequiresNullTerminator);
Bill Wendling526276a2013-02-14 19:11:28 +00002560LLVMMemoryBufferRef LLVMCreateMemoryBufferWithMemoryRangeCopy(const char *InputData,
2561 size_t InputDataLength,
2562 const char *BufferName);
Gordon Henriksen34eb6d82007-12-19 22:30:40 +00002563void LLVMDisposeMemoryBuffer(LLVMMemoryBufferRef MemBuf);
2564
Gregory Szorc34c863a2012-03-21 03:54:29 +00002565/**
2566 * @}
2567 */
2568
2569/**
2570 * @defgroup LLVMCCorePassRegistry Pass Registry
2571 *
2572 * @{
2573 */
Owen Anderson4698c5d2010-10-07 17:55:47 +00002574
2575/** Return the global pass registry, for use with initialization functions.
Gregory Szorc34c863a2012-03-21 03:54:29 +00002576 @see llvm::PassRegistry::getPassRegistry */
Owen Anderson4698c5d2010-10-07 17:55:47 +00002577LLVMPassRegistryRef LLVMGetGlobalPassRegistry(void);
Gordon Henriksen878114b2008-03-16 04:20:44 +00002578
Gregory Szorc34c863a2012-03-21 03:54:29 +00002579/**
2580 * @}
2581 */
2582
2583/**
2584 * @defgroup LLVMCCorePassManagers Pass Managers
2585 *
2586 * @{
2587 */
Gordon Henriksen878114b2008-03-16 04:20:44 +00002588
2589/** Constructs a new whole-module pass pipeline. This type of pipeline is
2590 suitable for link-time optimization and whole-module transformations.
Gregory Szorc34c863a2012-03-21 03:54:29 +00002591 @see llvm::PassManager::PassManager */
Gordon Henriksena735a9c2008-05-04 12:55:34 +00002592LLVMPassManagerRef LLVMCreatePassManager(void);
Gordon Henriksen878114b2008-03-16 04:20:44 +00002593
2594/** Constructs a new function-by-function pass pipeline over the module
2595 provider. It does not take ownership of the module provider. This type of
2596 pipeline is suitable for code generation and JIT compilation tasks.
Gregory Szorc34c863a2012-03-21 03:54:29 +00002597 @see llvm::FunctionPassManager::FunctionPassManager */
Erick Tryzelaarad0e0cb2010-03-02 23:58:54 +00002598LLVMPassManagerRef LLVMCreateFunctionPassManagerForModule(LLVMModuleRef M);
2599
2600/** Deprecated: Use LLVMCreateFunctionPassManagerForModule instead. */
Gordon Henriksen878114b2008-03-16 04:20:44 +00002601LLVMPassManagerRef LLVMCreateFunctionPassManager(LLVMModuleProviderRef MP);
2602
2603/** Initializes, executes on the provided module, and finalizes all of the
2604 passes scheduled in the pass manager. Returns 1 if any of the passes
Gregory Szorc34c863a2012-03-21 03:54:29 +00002605 modified the module, 0 otherwise.
2606 @see llvm::PassManager::run(Module&) */
Chris Lattner25963c62010-01-09 22:27:07 +00002607LLVMBool LLVMRunPassManager(LLVMPassManagerRef PM, LLVMModuleRef M);
Gordon Henriksen878114b2008-03-16 04:20:44 +00002608
2609/** Initializes all of the function passes scheduled in the function pass
2610 manager. Returns 1 if any of the passes modified the module, 0 otherwise.
Gregory Szorc34c863a2012-03-21 03:54:29 +00002611 @see llvm::FunctionPassManager::doInitialization */
Chris Lattner25963c62010-01-09 22:27:07 +00002612LLVMBool LLVMInitializeFunctionPassManager(LLVMPassManagerRef FPM);
Gordon Henriksen878114b2008-03-16 04:20:44 +00002613
2614/** Executes all of the function passes scheduled in the function pass manager
2615 on the provided function. Returns 1 if any of the passes modified the
2616 function, false otherwise.
Gregory Szorc34c863a2012-03-21 03:54:29 +00002617 @see llvm::FunctionPassManager::run(Function&) */
Chris Lattner25963c62010-01-09 22:27:07 +00002618LLVMBool LLVMRunFunctionPassManager(LLVMPassManagerRef FPM, LLVMValueRef F);
Gordon Henriksen878114b2008-03-16 04:20:44 +00002619
2620/** Finalizes all of the function passes scheduled in in the function pass
2621 manager. Returns 1 if any of the passes modified the module, 0 otherwise.
Gregory Szorc34c863a2012-03-21 03:54:29 +00002622 @see llvm::FunctionPassManager::doFinalization */
Chris Lattner25963c62010-01-09 22:27:07 +00002623LLVMBool LLVMFinalizeFunctionPassManager(LLVMPassManagerRef FPM);
Gordon Henriksen878114b2008-03-16 04:20:44 +00002624
2625/** Frees the memory of a pass pipeline. For function pipelines, does not free
2626 the module provider.
Gregory Szorc34c863a2012-03-21 03:54:29 +00002627 @see llvm::PassManagerBase::~PassManagerBase. */
Gordon Henriksen878114b2008-03-16 04:20:44 +00002628void LLVMDisposePassManager(LLVMPassManagerRef PM);
2629
Gregory Szorc34c863a2012-03-21 03:54:29 +00002630/**
2631 * @}
2632 */
2633
2634/**
Duncan Sands1cba0a82013-02-17 16:35:51 +00002635 * @defgroup LLVMCCoreThreading Threading
2636 *
2637 * Handle the structures needed to make LLVM safe for multithreading.
2638 *
2639 * @{
2640 */
2641
2642/** Allocate and initialize structures needed to make LLVM safe for
2643 multithreading. The return value indicates whether multithreaded
2644 initialization succeeded. Must be executed in isolation from all
2645 other LLVM api calls.
2646 @see llvm::llvm_start_multithreaded */
2647LLVMBool LLVMStartMultithreaded();
2648
2649/** Deallocate structures necessary to make LLVM safe for multithreading.
2650 Must be executed in isolation from all other LLVM api calls.
2651 @see llvm::llvm_stop_multithreaded */
2652void LLVMStopMultithreaded();
2653
2654/** Check whether LLVM is executing in thread-safe mode or not.
2655 @see llvm::llvm_is_multithreaded */
2656LLVMBool LLVMIsMultithreaded();
2657
2658/**
2659 * @}
2660 */
2661
2662/**
Gregory Szorc34c863a2012-03-21 03:54:29 +00002663 * @}
2664 */
2665
2666/**
2667 * @}
2668 */
Gordon Henriksen878114b2008-03-16 04:20:44 +00002669
Gordon Henriksen76a03742007-09-18 03:18:57 +00002670#ifdef __cplusplus
2671}
Gordon Henriksen76a03742007-09-18 03:18:57 +00002672
Gordon Henriksen7330acd2007-10-05 23:59:36 +00002673namespace llvm {
Gordon Henriksen34eb6d82007-12-19 22:30:40 +00002674 class MemoryBuffer;
Gordon Henriksen96571492008-03-16 15:55:43 +00002675 class PassManagerBase;
Gordon Henriksen0a68fe22007-12-12 01:04:30 +00002676
Gordon Henriksen34eb6d82007-12-19 22:30:40 +00002677 #define DEFINE_SIMPLE_CONVERSION_FUNCTIONS(ty, ref) \
2678 inline ty *unwrap(ref P) { \
2679 return reinterpret_cast<ty*>(P); \
2680 } \
2681 \
2682 inline ref wrap(const ty *P) { \
2683 return reinterpret_cast<ref>(const_cast<ty*>(P)); \
2684 }
Gordon Henriksen7330acd2007-10-05 23:59:36 +00002685
Gordon Henriksen878114b2008-03-16 04:20:44 +00002686 #define DEFINE_ISA_CONVERSION_FUNCTIONS(ty, ref) \
2687 DEFINE_SIMPLE_CONVERSION_FUNCTIONS(ty, ref) \
2688 \
2689 template<typename T> \
2690 inline T *unwrap(ref P) { \
2691 return cast<T>(unwrap(P)); \
2692 }
2693
2694 #define DEFINE_STDCXX_CONVERSION_FUNCTIONS(ty, ref) \
2695 DEFINE_SIMPLE_CONVERSION_FUNCTIONS(ty, ref) \
2696 \
2697 template<typename T> \
2698 inline T *unwrap(ref P) { \
Chris Lattner7ba06612010-01-22 06:49:46 +00002699 T *Q = (T*)unwrap(P); \
Gordon Henriksen878114b2008-03-16 04:20:44 +00002700 assert(Q && "Invalid cast!"); \
2701 return Q; \
2702 }
2703
2704 DEFINE_ISA_CONVERSION_FUNCTIONS (Type, LLVMTypeRef )
2705 DEFINE_ISA_CONVERSION_FUNCTIONS (Value, LLVMValueRef )
Gordon Henriksen823f9732007-12-27 18:25:59 +00002706 DEFINE_SIMPLE_CONVERSION_FUNCTIONS(Module, LLVMModuleRef )
2707 DEFINE_SIMPLE_CONVERSION_FUNCTIONS(BasicBlock, LLVMBasicBlockRef )
Eric Christopher59278832008-08-08 19:39:37 +00002708 DEFINE_SIMPLE_CONVERSION_FUNCTIONS(IRBuilder<>, LLVMBuilderRef )
Gordon Henriksen823f9732007-12-27 18:25:59 +00002709 DEFINE_SIMPLE_CONVERSION_FUNCTIONS(MemoryBuffer, LLVMMemoryBufferRef )
Owen Anderson6773d382009-07-01 16:58:40 +00002710 DEFINE_SIMPLE_CONVERSION_FUNCTIONS(LLVMContext, LLVMContextRef )
Erick Tryzelaar9f9857e2010-03-02 20:32:28 +00002711 DEFINE_SIMPLE_CONVERSION_FUNCTIONS(Use, LLVMUseRef )
Gordon Henriksen878114b2008-03-16 04:20:44 +00002712 DEFINE_STDCXX_CONVERSION_FUNCTIONS(PassManagerBase, LLVMPassManagerRef )
Owen Anderson4698c5d2010-10-07 17:55:47 +00002713 DEFINE_STDCXX_CONVERSION_FUNCTIONS(PassRegistry, LLVMPassRegistryRef )
Jeffrey Yasskin091217b2010-01-27 20:34:15 +00002714 /* LLVMModuleProviderRef exists for historical reasons, but now just holds a
2715 * Module.
2716 */
2717 inline Module *unwrap(LLVMModuleProviderRef MP) {
2718 return reinterpret_cast<Module*>(MP);
2719 }
Gordon Henriksen7330acd2007-10-05 23:59:36 +00002720
Gordon Henriksen878114b2008-03-16 04:20:44 +00002721 #undef DEFINE_STDCXX_CONVERSION_FUNCTIONS
2722 #undef DEFINE_ISA_CONVERSION_FUNCTIONS
Gordon Henriksen34eb6d82007-12-19 22:30:40 +00002723 #undef DEFINE_SIMPLE_CONVERSION_FUNCTIONS
Erick Tryzelaar262332f2009-08-14 00:01:31 +00002724
2725 /* Specialized opaque context conversions.
2726 */
2727 inline LLVMContext **unwrap(LLVMContextRef* Tys) {
2728 return reinterpret_cast<LLVMContext**>(Tys);
2729 }
2730
2731 inline LLVMContextRef *wrap(const LLVMContext **Tys) {
2732 return reinterpret_cast<LLVMContextRef*>(const_cast<LLVMContext**>(Tys));
2733 }
Gordon Henriksen7330acd2007-10-05 23:59:36 +00002734
Gordon Henriksen34eb6d82007-12-19 22:30:40 +00002735 /* Specialized opaque type conversions.
2736 */
Gordon Henriksen7330acd2007-10-05 23:59:36 +00002737 inline Type **unwrap(LLVMTypeRef* Tys) {
2738 return reinterpret_cast<Type**>(Tys);
2739 }
2740
Chris Lattner229907c2011-07-18 04:54:35 +00002741 inline LLVMTypeRef *wrap(Type **Tys) {
Gordon Henriksen7330acd2007-10-05 23:59:36 +00002742 return reinterpret_cast<LLVMTypeRef*>(const_cast<Type**>(Tys));
2743 }
2744
Gordon Henriksen34eb6d82007-12-19 22:30:40 +00002745 /* Specialized opaque value conversions.
Gordon Henriksen7330acd2007-10-05 23:59:36 +00002746 */
Gordon Henriksen7330acd2007-10-05 23:59:36 +00002747 inline Value **unwrap(LLVMValueRef *Vals) {
2748 return reinterpret_cast<Value**>(Vals);
2749 }
2750
2751 template<typename T>
2752 inline T **unwrap(LLVMValueRef *Vals, unsigned Length) {
Bob Wilsond43a50d2012-09-04 17:42:53 +00002753 #ifdef DEBUG
Chris Lattnerb7971152009-07-10 18:28:19 +00002754 for (LLVMValueRef *I = Vals, *E = Vals + Length; I != E; ++I)
Gordon Henriksen7330acd2007-10-05 23:59:36 +00002755 cast<T>(*I);
2756 #endif
Hans Wennborg8f7edbf2011-06-04 16:00:19 +00002757 (void)Length;
Gordon Henriksen7330acd2007-10-05 23:59:36 +00002758 return reinterpret_cast<T**>(Vals);
2759 }
2760
Gordon Henriksen7330acd2007-10-05 23:59:36 +00002761 inline LLVMValueRef *wrap(const Value **Vals) {
2762 return reinterpret_cast<LLVMValueRef*>(const_cast<Value**>(Vals));
2763 }
Gordon Henriksen7330acd2007-10-05 23:59:36 +00002764}
2765
2766#endif /* !defined(__cplusplus) */
2767
2768#endif /* !defined(LLVM_C_CORE_H) */