blob: eceae5c7b68de35e32c3768cbb6bb6363d019368 [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 Carruthaafe0912012-06-29 12:38:19 +000024#include "llvm/IRBuilder.h"
Gordon Henriksen7330acd2007-10-05 23:59:36 +000025#include "llvm/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
176 // FIXME: This attribute is currently not included in the C API as
177 // a temporary measure until the API/ABI impact to the C API is understood
178 // and the path forward agreed upon.
179 //LLVMAddressSafety = 1ULL << 32
Devang Patel4c758ea2008-09-25 21:00:45 +0000180} LLVMAttribute;
Gordon Henriksen2d9cc212008-04-28 17:37:06 +0000181
182typedef enum {
Bill Wendlingda52cec2010-02-15 20:53:17 +0000183 /* Terminator Instructions */
Chris Lattner40cf28d2009-10-12 04:01:02 +0000184 LLVMRet = 1,
185 LLVMBr = 2,
186 LLVMSwitch = 3,
Bill Wendling07d6d762010-02-15 20:50:51 +0000187 LLVMIndirectBr = 4,
188 LLVMInvoke = 5,
Bill Wendling46ffaa92011-08-02 06:20:17 +0000189 /* removed 6 due to API changes */
Bill Wendling2641d132011-07-27 21:00:28 +0000190 LLVMUnreachable = 7,
Bill Wendling07d6d762010-02-15 20:50:51 +0000191
Bill Wendlingda52cec2010-02-15 20:53:17 +0000192 /* Standard Binary Operators */
Bill Wendling2641d132011-07-27 21:00:28 +0000193 LLVMAdd = 8,
194 LLVMFAdd = 9,
195 LLVMSub = 10,
196 LLVMFSub = 11,
197 LLVMMul = 12,
198 LLVMFMul = 13,
199 LLVMUDiv = 14,
200 LLVMSDiv = 15,
201 LLVMFDiv = 16,
202 LLVMURem = 17,
203 LLVMSRem = 18,
204 LLVMFRem = 19,
Bill Wendling07d6d762010-02-15 20:50:51 +0000205
Bill Wendlingda52cec2010-02-15 20:53:17 +0000206 /* Logical Operators */
Bill Wendling2641d132011-07-27 21:00:28 +0000207 LLVMShl = 20,
208 LLVMLShr = 21,
209 LLVMAShr = 22,
210 LLVMAnd = 23,
211 LLVMOr = 24,
212 LLVMXor = 25,
Bill Wendling07d6d762010-02-15 20:50:51 +0000213
Bill Wendlingda52cec2010-02-15 20:53:17 +0000214 /* Memory Operators */
Bill Wendling2641d132011-07-27 21:00:28 +0000215 LLVMAlloca = 26,
216 LLVMLoad = 27,
217 LLVMStore = 28,
218 LLVMGetElementPtr = 29,
Bill Wendling07d6d762010-02-15 20:50:51 +0000219
Bill Wendlingda52cec2010-02-15 20:53:17 +0000220 /* Cast Operators */
Bill Wendling2641d132011-07-27 21:00:28 +0000221 LLVMTrunc = 30,
222 LLVMZExt = 31,
223 LLVMSExt = 32,
224 LLVMFPToUI = 33,
225 LLVMFPToSI = 34,
226 LLVMUIToFP = 35,
227 LLVMSIToFP = 36,
228 LLVMFPTrunc = 37,
229 LLVMFPExt = 38,
230 LLVMPtrToInt = 39,
231 LLVMIntToPtr = 40,
232 LLVMBitCast = 41,
Bill Wendling07d6d762010-02-15 20:50:51 +0000233
Bill Wendlingda52cec2010-02-15 20:53:17 +0000234 /* Other Operators */
Bill Wendling2641d132011-07-27 21:00:28 +0000235 LLVMICmp = 42,
236 LLVMFCmp = 43,
237 LLVMPHI = 44,
238 LLVMCall = 45,
239 LLVMSelect = 46,
Torok Edwin05dc9d62011-10-06 12:39:34 +0000240 LLVMUserOp1 = 47,
241 LLVMUserOp2 = 48,
Bill Wendling2641d132011-07-27 21:00:28 +0000242 LLVMVAArg = 49,
243 LLVMExtractElement = 50,
244 LLVMInsertElement = 51,
245 LLVMShuffleVector = 52,
246 LLVMExtractValue = 53,
247 LLVMInsertValue = 54,
Eli Friedman4fc946c2011-07-27 18:59:19 +0000248
249 /* Atomic operators */
Bill Wendling2641d132011-07-27 21:00:28 +0000250 LLVMFence = 55,
Eli Friedmanc9a551e2011-07-28 21:48:00 +0000251 LLVMAtomicCmpXchg = 56,
Bill Wendlingf891bf82011-07-31 06:30:59 +0000252 LLVMAtomicRMW = 57,
253
254 /* Exception Handling Operators */
Bill Wendlingfae14752011-08-12 20:24:12 +0000255 LLVMResume = 58,
Bill Wendling0aef16a2012-02-06 21:44:22 +0000256 LLVMLandingPad = 59
Bill Wendling2641d132011-07-27 21:00:28 +0000257
Chris Lattner40cf28d2009-10-12 04:01:02 +0000258} LLVMOpcode;
259
260typedef enum {
Gordon Henriksen4a4d7352007-12-30 17:46:33 +0000261 LLVMVoidTypeKind, /**< type with no size */
Dan Gohman518cda42011-12-17 00:04:22 +0000262 LLVMHalfTypeKind, /**< 16 bit floating point type */
Gordon Henriksen4a4d7352007-12-30 17:46:33 +0000263 LLVMFloatTypeKind, /**< 32 bit floating point type */
264 LLVMDoubleTypeKind, /**< 64 bit floating point type */
265 LLVMX86_FP80TypeKind, /**< 80 bit floating point type (X87) */
266 LLVMFP128TypeKind, /**< 128 bit floating point type (112-bit mantissa)*/
267 LLVMPPC_FP128TypeKind, /**< 128 bit floating point type (two 64-bits) */
268 LLVMLabelTypeKind, /**< Labels */
269 LLVMIntegerTypeKind, /**< Arbitrary bit width integers */
270 LLVMFunctionTypeKind, /**< Functions */
271 LLVMStructTypeKind, /**< Structures */
272 LLVMArrayTypeKind, /**< Arrays */
273 LLVMPointerTypeKind, /**< Pointers */
Chris Lattnerdac44ec2009-07-15 22:00:31 +0000274 LLVMVectorTypeKind, /**< SIMD 'packed' format, or other vector type */
Dale Johannesenbaa5d042010-09-10 20:55:01 +0000275 LLVMMetadataTypeKind, /**< Metadata */
276 LLVMX86_MMXTypeKind /**< X86 MMX */
Gordon Henriksen76a03742007-09-18 03:18:57 +0000277} LLVMTypeKind;
278
279typedef enum {
Gordon Henriksen4a4d7352007-12-30 17:46:33 +0000280 LLVMExternalLinkage, /**< Externally visible function */
Chris Lattner2dba0f02009-04-13 06:25:37 +0000281 LLVMAvailableExternallyLinkage,
Duncan Sands12da8ce2009-03-07 15:45:40 +0000282 LLVMLinkOnceAnyLinkage, /**< Keep one copy of function when linking (inline)*/
283 LLVMLinkOnceODRLinkage, /**< Same, but only replaced by something
284 equivalent. */
Bill Wendling34bc34e2012-08-17 18:33:14 +0000285 LLVMLinkOnceODRAutoHideLinkage, /**< Like LinkOnceODR, but possibly hidden. */
Duncan Sands12da8ce2009-03-07 15:45:40 +0000286 LLVMWeakAnyLinkage, /**< Keep one copy of function when linking (weak) */
287 LLVMWeakODRLinkage, /**< Same, but only replaced by something
288 equivalent. */
Gordon Henriksen4a4d7352007-12-30 17:46:33 +0000289 LLVMAppendingLinkage, /**< Special purpose, only applies to global arrays */
290 LLVMInternalLinkage, /**< Rename collisions when linking (static
291 functions) */
Duncan Sands12da8ce2009-03-07 15:45:40 +0000292 LLVMPrivateLinkage, /**< Like Internal, but omit from symbol table */
Gordon Henriksen4a4d7352007-12-30 17:46:33 +0000293 LLVMDLLImportLinkage, /**< Function to be imported from DLL */
294 LLVMDLLExportLinkage, /**< Function to be accessible from DLL */
Duncan Sandse2881052009-03-11 08:08:06 +0000295 LLVMExternalWeakLinkage,/**< ExternalWeak linkage description */
Jeffrey Yasskin091217b2010-01-27 20:34:15 +0000296 LLVMGhostLinkage, /**< Obsolete */
Bill Wendling002b1672009-07-20 18:22:52 +0000297 LLVMCommonLinkage, /**< Tentative definitions */
Bill Wendling03bcd6e2010-07-01 21:55:59 +0000298 LLVMLinkerPrivateLinkage, /**< Like Private, but linker removes. */
Bill Wendling34bc34e2012-08-17 18:33:14 +0000299 LLVMLinkerPrivateWeakLinkage /**< Like LinkerPrivate, but is weak. */
Gordon Henriksen76a03742007-09-18 03:18:57 +0000300} LLVMLinkage;
301
302typedef enum {
Gordon Henriksen4a4d7352007-12-30 17:46:33 +0000303 LLVMDefaultVisibility, /**< The GV is visible */
304 LLVMHiddenVisibility, /**< The GV is hidden */
305 LLVMProtectedVisibility /**< The GV is protected */
Gordon Henriksen76a03742007-09-18 03:18:57 +0000306} LLVMVisibility;
307
Gordon Henriksenc23b66c2007-09-26 20:56:12 +0000308typedef enum {
309 LLVMCCallConv = 0,
310 LLVMFastCallConv = 8,
311 LLVMColdCallConv = 9,
312 LLVMX86StdcallCallConv = 64,
313 LLVMX86FastcallCallConv = 65
314} LLVMCallConv;
315
316typedef enum {
Gordon Henriksen4a4d7352007-12-30 17:46:33 +0000317 LLVMIntEQ = 32, /**< equal */
318 LLVMIntNE, /**< not equal */
319 LLVMIntUGT, /**< unsigned greater than */
320 LLVMIntUGE, /**< unsigned greater or equal */
321 LLVMIntULT, /**< unsigned less than */
322 LLVMIntULE, /**< unsigned less or equal */
323 LLVMIntSGT, /**< signed greater than */
324 LLVMIntSGE, /**< signed greater or equal */
325 LLVMIntSLT, /**< signed less than */
326 LLVMIntSLE /**< signed less or equal */
Gordon Henriksenc23b66c2007-09-26 20:56:12 +0000327} LLVMIntPredicate;
328
329typedef enum {
Gordon Henriksen4a4d7352007-12-30 17:46:33 +0000330 LLVMRealPredicateFalse, /**< Always false (always folded) */
331 LLVMRealOEQ, /**< True if ordered and equal */
332 LLVMRealOGT, /**< True if ordered and greater than */
333 LLVMRealOGE, /**< True if ordered and greater than or equal */
334 LLVMRealOLT, /**< True if ordered and less than */
335 LLVMRealOLE, /**< True if ordered and less than or equal */
336 LLVMRealONE, /**< True if ordered and operands are unequal */
337 LLVMRealORD, /**< True if ordered (no nans) */
338 LLVMRealUNO, /**< True if unordered: isnan(X) | isnan(Y) */
339 LLVMRealUEQ, /**< True if unordered or equal */
340 LLVMRealUGT, /**< True if unordered or greater than */
341 LLVMRealUGE, /**< True if unordered, greater than, or equal */
342 LLVMRealULT, /**< True if unordered or less than */
343 LLVMRealULE, /**< True if unordered, less than, or equal */
344 LLVMRealUNE, /**< True if unordered or not equal */
345 LLVMRealPredicateTrue /**< Always true (always folded) */
Gordon Henriksenc23b66c2007-09-26 20:56:12 +0000346} LLVMRealPredicate;
347
Bill Wendlingfae14752011-08-12 20:24:12 +0000348typedef enum {
349 LLVMLandingPadCatch, /**< A catch clause */
350 LLVMLandingPadFilter /**< A filter clause */
351} LLVMLandingPadClauseTy;
352
Gregory Szorc34c863a2012-03-21 03:54:29 +0000353/**
354 * @}
355 */
356
Nick Lewycky0db26542011-05-15 07:20:34 +0000357void LLVMInitializeCore(LLVMPassRegistryRef R);
358
Gordon Henriksen76a03742007-09-18 03:18:57 +0000359
Gordon Henriksen34eb6d82007-12-19 22:30:40 +0000360/*===-- Error handling ----------------------------------------------------===*/
361
362void LLVMDisposeMessage(char *Message);
363
364
Gregory Szorc34c863a2012-03-21 03:54:29 +0000365/**
366 * @defgroup LLVMCCoreContext Contexts
367 *
368 * Contexts are execution states for the core LLVM IR system.
369 *
370 * Most types are tied to a context instance. Multiple contexts can
371 * exist simultaneously. A single context is not thread safe. However,
372 * different contexts can execute on different threads simultaneously.
373 *
374 * @{
375 */
Gordon Henriksen76a03742007-09-18 03:18:57 +0000376
Gregory Szorc34c863a2012-03-21 03:54:29 +0000377/**
378 * Create a new context.
379 *
380 * Every call to this function should be paired with a call to
381 * LLVMContextDispose() or the context will leak memory.
382 */
Erick Tryzelaarf34cb0c2009-08-30 23:38:06 +0000383LLVMContextRef LLVMContextCreate(void);
Gregory Szorc34c863a2012-03-21 03:54:29 +0000384
385/**
386 * Obtain the global context instance.
387 */
Erick Tryzelaarf34cb0c2009-08-30 23:38:06 +0000388LLVMContextRef LLVMGetGlobalContext(void);
Gregory Szorc34c863a2012-03-21 03:54:29 +0000389
390/**
391 * Destroy a context instance.
392 *
393 * This should be called for every call to LLVMContextCreate() or memory
394 * will be leaked.
395 */
Owen Anderson6773d382009-07-01 16:58:40 +0000396void LLVMContextDispose(LLVMContextRef C);
397
Erick Tryzelaard8531fa2010-02-28 09:45:59 +0000398unsigned LLVMGetMDKindIDInContext(LLVMContextRef C, const char* Name,
399 unsigned SLen);
400unsigned LLVMGetMDKindID(const char* Name, unsigned SLen);
401
Gregory Szorc34c863a2012-03-21 03:54:29 +0000402/**
403 * @}
404 */
405
Gregory Szorc52d26602012-03-21 07:28:27 +0000406/**
407 * @defgroup LLVMCCoreModule Modules
Gregory Szorc34c863a2012-03-21 03:54:29 +0000408 *
409 * Modules represent the top-level structure in a LLVM program. An LLVM
410 * module is effectively a translation unit or a collection of
411 * translation units merged together.
412 *
413 * @{
414 */
415
Gregory Szorc34c863a2012-03-21 03:54:29 +0000416/**
417 * Create a new, empty module in the global context.
418 *
419 * This is equivalent to calling LLVMModuleCreateWithNameInContext with
420 * LLVMGetGlobalContext() as the context parameter.
421 *
422 * Every invocation should be paired with LLVMDisposeModule() or memory
423 * will be leaked.
424 */
Gordon Henriksen76a03742007-09-18 03:18:57 +0000425LLVMModuleRef LLVMModuleCreateWithName(const char *ModuleID);
Gregory Szorc34c863a2012-03-21 03:54:29 +0000426
427/**
428 * Create a new, empty module in a specific context.
429 *
430 * Every invocation should be paired with LLVMDisposeModule() or memory
431 * will be leaked.
432 */
Owen Anderson31d44e42009-07-02 07:17:57 +0000433LLVMModuleRef LLVMModuleCreateWithNameInContext(const char *ModuleID,
434 LLVMContextRef C);
Gordon Henriksena49d4352008-03-07 19:13:06 +0000435
Gregory Szorc34c863a2012-03-21 03:54:29 +0000436/**
437 * Destroy a module instance.
438 *
439 * This must be called for every created module or memory will be
440 * leaked.
441 */
Gordon Henriksen76a03742007-09-18 03:18:57 +0000442void LLVMDisposeModule(LLVMModuleRef M);
443
Gregory Szorc34c863a2012-03-21 03:54:29 +0000444/**
445 * Obtain the data layout for a module.
446 *
447 * @see Module::getDataLayout()
448 */
Gordon Henriksen05568bb2007-12-27 20:13:47 +0000449const char *LLVMGetDataLayout(LLVMModuleRef M);
Gregory Szorc34c863a2012-03-21 03:54:29 +0000450
451/**
452 * Set the data layout for a module.
453 *
454 * @see Module::setDataLayout()
455 */
Gordon Henriksen05568bb2007-12-27 20:13:47 +0000456void LLVMSetDataLayout(LLVMModuleRef M, const char *Triple);
457
Gregory Szorc34c863a2012-03-21 03:54:29 +0000458/**
459 * Obtain the target triple for a module.
460 *
461 * @see Module::getTargetTriple()
462 */
Gordon Henriksen05568bb2007-12-27 20:13:47 +0000463const char *LLVMGetTarget(LLVMModuleRef M);
Gregory Szorc34c863a2012-03-21 03:54:29 +0000464
465/**
466 * Set the target triple for a module.
467 *
468 * @see Module::setTargetTriple()
469 */
Gordon Henriksen05568bb2007-12-27 20:13:47 +0000470void LLVMSetTarget(LLVMModuleRef M, const char *Triple);
471
Gregory Szorc34c863a2012-03-21 03:54:29 +0000472/**
473 * Dump a representation of a module to stderr.
474 *
475 * @see Module::dump()
476 */
Gordon Henriksen6c6075e2008-03-14 23:58:56 +0000477void LLVMDumpModule(LLVMModuleRef M);
478
Gregory Szorc34c863a2012-03-21 03:54:29 +0000479/**
Hans Wennborgb7ef2fe2012-05-09 16:54:17 +0000480 * Print a representation of a module to a file. The ErrorMessage needs to be
481 * disposed with LLVMDisposeMessage. Returns 0 on success, 1 otherwise.
482 *
483 * @see Module::print()
484 */
485LLVMBool LLVMPrintModuleToFile(LLVMModuleRef M, const char *Filename,
486 char **ErrorMessage);
487
488/**
Gregory Szorc34c863a2012-03-21 03:54:29 +0000489 * Set inline assembly for a module.
490 *
491 * @see Module::setModuleInlineAsm()
492 */
Chris Lattner26941452010-04-10 17:52:58 +0000493void LLVMSetModuleInlineAsm(LLVMModuleRef M, const char *Asm);
Gordon Henriksen76a03742007-09-18 03:18:57 +0000494
Gregory Szorc34c863a2012-03-21 03:54:29 +0000495/**
496 * Obtain the context to which this module is associated.
497 *
498 * @see Module::getContext()
499 */
Chris Lattnera7e04b02010-11-28 20:03:44 +0000500LLVMContextRef LLVMGetModuleContext(LLVMModuleRef M);
501
Gregory Szorc34c863a2012-03-21 03:54:29 +0000502/**
503 * Obtain a Type from a module by its registered name.
504 */
505LLVMTypeRef LLVMGetTypeByName(LLVMModuleRef M, const char *Name);
Gordon Henriksen76a03742007-09-18 03:18:57 +0000506
Gregory Szorc34c863a2012-03-21 03:54:29 +0000507/**
508 * Obtain the number of operands for named metadata in a module.
509 *
510 * @see llvm::Module::getNamedMetadata()
511 */
512unsigned LLVMGetNamedMetadataNumOperands(LLVMModuleRef M, const char* name);
513
514/**
515 * Obtain the named metadata operands for a module.
516 *
517 * The passed LLVMValueRef pointer should refer to an array of
518 * LLVMValueRef at least LLVMGetNamedMetadataNumOperands long. This
519 * array will be populated with the LLVMValueRef instances. Each
520 * instance corresponds to a llvm::MDNode.
521 *
522 * @see llvm::Module::getNamedMetadata()
523 * @see llvm::MDNode::getOperand()
524 */
525void LLVMGetNamedMetadataOperands(LLVMModuleRef M, const char* name, LLVMValueRef *Dest);
526
527/**
528 * Add an operand to named metadata.
529 *
530 * @see llvm::Module::getNamedMetadata()
531 * @see llvm::MDNode::addOperand()
532 */
533void LLVMAddNamedMetadataOperand(LLVMModuleRef M, const char* name,
534 LLVMValueRef Val);
535
Gregory Szorc52d26602012-03-21 07:28:27 +0000536/**
537 * Add a function to a module under a specified name.
538 *
539 * @see llvm::Function::Create()
540 */
541LLVMValueRef LLVMAddFunction(LLVMModuleRef M, const char *Name,
542 LLVMTypeRef FunctionTy);
543
544/**
545 * Obtain a Function value from a Module by its name.
546 *
547 * The returned value corresponds to a llvm::Function value.
548 *
549 * @see llvm::Module::getFunction()
550 */
551LLVMValueRef LLVMGetNamedFunction(LLVMModuleRef M, const char *Name);
552
553/**
554 * Obtain an iterator to the first Function in a Module.
555 *
556 * @see llvm::Module::begin()
557 */
558LLVMValueRef LLVMGetFirstFunction(LLVMModuleRef M);
559
560/**
561 * Obtain an iterator to the last Function in a Module.
562 *
563 * @see llvm::Module::end()
564 */
565LLVMValueRef LLVMGetLastFunction(LLVMModuleRef M);
566
567/**
568 * Advance a Function iterator to the next Function.
569 *
570 * Returns NULL if the iterator was already at the end and there are no more
571 * functions.
572 */
573LLVMValueRef LLVMGetNextFunction(LLVMValueRef Fn);
574
575/**
576 * Decrement a Function iterator to the previous Function.
577 *
578 * Returns NULL if the iterator was already at the beginning and there are
579 * no previous functions.
580 */
581LLVMValueRef LLVMGetPreviousFunction(LLVMValueRef Fn);
Gregory Szorc34c863a2012-03-21 03:54:29 +0000582
583/**
584 * @}
585 */
586
587/**
588 * @defgroup LLVMCCoreType Types
589 *
590 * Types represent the type of a value.
591 *
592 * Types are associated with a context instance. The context internally
593 * deduplicates types so there is only 1 instance of a specific type
594 * alive at a time. In other words, a unique type is shared among all
595 * consumers within a context.
596 *
597 * A Type in the C API corresponds to llvm::Type.
598 *
599 * Types have the following hierarchy:
600 *
Gordon Henriksen76a03742007-09-18 03:18:57 +0000601 * types:
602 * integer type
603 * real type
604 * function type
605 * sequence types:
606 * array type
607 * pointer type
608 * vector type
609 * void type
610 * label type
611 * opaque type
Gregory Szorc34c863a2012-03-21 03:54:29 +0000612 *
613 * @{
Gordon Henriksen76a03742007-09-18 03:18:57 +0000614 */
615
Gregory Szorc34c863a2012-03-21 03:54:29 +0000616/**
617 * Obtain the enumerated type of a Type instance.
618 *
619 * @see llvm::Type:getTypeID()
620 */
Gordon Henriksen76a03742007-09-18 03:18:57 +0000621LLVMTypeKind LLVMGetTypeKind(LLVMTypeRef Ty);
Gregory Szorc34c863a2012-03-21 03:54:29 +0000622
623/**
624 * Whether the type has a known size.
625 *
626 * Things that don't have a size are abstract types, labels, and void.a
627 *
628 * @see llvm::Type::isSized()
629 */
Torok Edwin1cd9ade2011-10-06 12:13:28 +0000630LLVMBool LLVMTypeIsSized(LLVMTypeRef Ty);
Gordon Henriksena49d4352008-03-07 19:13:06 +0000631
Gregory Szorc34c863a2012-03-21 03:54:29 +0000632/**
633 * Obtain the context to which this type instance is associated.
634 *
635 * @see llvm::Type::getContext()
636 */
Erick Tryzelaar262332f2009-08-14 00:01:31 +0000637LLVMContextRef LLVMGetTypeContext(LLVMTypeRef Ty);
638
Gregory Szorc34c863a2012-03-21 03:54:29 +0000639/**
640 * @defgroup LLVMCCoreTypeInt Integer Types
641 *
642 * Functions in this section operate on integer types.
643 *
644 * @{
645 */
646
647/**
648 * Obtain an integer type from a context with specified bit width.
649 */
Erick Tryzelaar262332f2009-08-14 00:01:31 +0000650LLVMTypeRef LLVMInt1TypeInContext(LLVMContextRef C);
651LLVMTypeRef LLVMInt8TypeInContext(LLVMContextRef C);
652LLVMTypeRef LLVMInt16TypeInContext(LLVMContextRef C);
653LLVMTypeRef LLVMInt32TypeInContext(LLVMContextRef C);
654LLVMTypeRef LLVMInt64TypeInContext(LLVMContextRef C);
655LLVMTypeRef LLVMIntTypeInContext(LLVMContextRef C, unsigned NumBits);
656
Gregory Szorc34c863a2012-03-21 03:54:29 +0000657/**
658 * Obtain an integer type from the global context with a specified bit
659 * width.
660 */
Gordon Henriksena735a9c2008-05-04 12:55:34 +0000661LLVMTypeRef LLVMInt1Type(void);
662LLVMTypeRef LLVMInt8Type(void);
663LLVMTypeRef LLVMInt16Type(void);
664LLVMTypeRef LLVMInt32Type(void);
665LLVMTypeRef LLVMInt64Type(void);
Gordon Henriksened7beaa2007-10-06 16:05:20 +0000666LLVMTypeRef LLVMIntType(unsigned NumBits);
Gordon Henriksenc23b66c2007-09-26 20:56:12 +0000667unsigned LLVMGetIntTypeWidth(LLVMTypeRef IntegerTy);
Gordon Henriksen76a03742007-09-18 03:18:57 +0000668
Gregory Szorc34c863a2012-03-21 03:54:29 +0000669/**
670 * @}
671 */
672
673/**
674 * @defgroup LLVMCCoreTypeFloat Floating Point Types
675 *
676 * @{
677 */
678
679/**
680 * Obtain a 16-bit floating point type from a context.
681 */
Dan Gohman518cda42011-12-17 00:04:22 +0000682LLVMTypeRef LLVMHalfTypeInContext(LLVMContextRef C);
Gregory Szorc34c863a2012-03-21 03:54:29 +0000683
684/**
685 * Obtain a 32-bit floating point type from a context.
686 */
Erick Tryzelaar262332f2009-08-14 00:01:31 +0000687LLVMTypeRef LLVMFloatTypeInContext(LLVMContextRef C);
Gregory Szorc34c863a2012-03-21 03:54:29 +0000688
689/**
690 * Obtain a 64-bit floating point type from a context.
691 */
Erick Tryzelaar262332f2009-08-14 00:01:31 +0000692LLVMTypeRef LLVMDoubleTypeInContext(LLVMContextRef C);
Gregory Szorc34c863a2012-03-21 03:54:29 +0000693
694/**
695 * Obtain a 80-bit floating point type (X87) from a context.
696 */
Erick Tryzelaar262332f2009-08-14 00:01:31 +0000697LLVMTypeRef LLVMX86FP80TypeInContext(LLVMContextRef C);
Gregory Szorc34c863a2012-03-21 03:54:29 +0000698
699/**
700 * Obtain a 128-bit floating point type (112-bit mantissa) from a
701 * context.
702 */
Erick Tryzelaar262332f2009-08-14 00:01:31 +0000703LLVMTypeRef LLVMFP128TypeInContext(LLVMContextRef C);
Gregory Szorc34c863a2012-03-21 03:54:29 +0000704
705/**
706 * Obtain a 128-bit floating point type (two 64-bits) from a context.
707 */
Erick Tryzelaar262332f2009-08-14 00:01:31 +0000708LLVMTypeRef LLVMPPCFP128TypeInContext(LLVMContextRef C);
709
Gregory Szorc34c863a2012-03-21 03:54:29 +0000710/**
711 * Obtain a floating point type from the global context.
712 *
713 * These map to the functions in this group of the same name.
714 */
Dan Gohman518cda42011-12-17 00:04:22 +0000715LLVMTypeRef LLVMHalfType(void);
Gordon Henriksena735a9c2008-05-04 12:55:34 +0000716LLVMTypeRef LLVMFloatType(void);
717LLVMTypeRef LLVMDoubleType(void);
718LLVMTypeRef LLVMX86FP80Type(void);
719LLVMTypeRef LLVMFP128Type(void);
720LLVMTypeRef LLVMPPCFP128Type(void);
Gordon Henriksen76a03742007-09-18 03:18:57 +0000721
Gregory Szorc34c863a2012-03-21 03:54:29 +0000722/**
723 * @}
724 */
725
726/**
727 * @defgroup LLVMCCoreTypeFunction Function Types
728 *
729 * @{
730 */
731
732/**
733 * Obtain a function type consisting of a specified signature.
734 *
735 * The function is defined as a tuple of a return Type, a list of
736 * parameter types, and whether the function is variadic.
737 */
Gordon Henriksened7beaa2007-10-06 16:05:20 +0000738LLVMTypeRef LLVMFunctionType(LLVMTypeRef ReturnType,
739 LLVMTypeRef *ParamTypes, unsigned ParamCount,
Chris Lattner25963c62010-01-09 22:27:07 +0000740 LLVMBool IsVarArg);
Gregory Szorc34c863a2012-03-21 03:54:29 +0000741
742/**
743 * Returns whether a function type is variadic.
744 */
Chris Lattner25963c62010-01-09 22:27:07 +0000745LLVMBool LLVMIsFunctionVarArg(LLVMTypeRef FunctionTy);
Gregory Szorc34c863a2012-03-21 03:54:29 +0000746
747/**
748 * Obtain the Type this function Type returns.
749 */
Gordon Henriksenc23b66c2007-09-26 20:56:12 +0000750LLVMTypeRef LLVMGetReturnType(LLVMTypeRef FunctionTy);
Gregory Szorc34c863a2012-03-21 03:54:29 +0000751
752/**
753 * Obtain the number of parameters this function accepts.
754 */
Gordon Henriksenc23b66c2007-09-26 20:56:12 +0000755unsigned LLVMCountParamTypes(LLVMTypeRef FunctionTy);
Gregory Szorc34c863a2012-03-21 03:54:29 +0000756
757/**
758 * Obtain the types of a function's parameters.
759 *
760 * The Dest parameter should point to a pre-allocated array of
761 * LLVMTypeRef at least LLVMCountParamTypes() large. On return, the
762 * first LLVMCountParamTypes() entries in the array will be populated
763 * with LLVMTypeRef instances.
764 *
765 * @param FunctionTy The function type to operate on.
766 * @param Dest Memory address of an array to be filled with result.
767 */
Gordon Henriksenc23b66c2007-09-26 20:56:12 +0000768void LLVMGetParamTypes(LLVMTypeRef FunctionTy, LLVMTypeRef *Dest);
Gordon Henriksen76a03742007-09-18 03:18:57 +0000769
Gregory Szorc34c863a2012-03-21 03:54:29 +0000770/**
771 * @}
772 */
773
774/**
775 * @defgroup LLVMCCoreTypeStruct Structure Types
776 *
777 * These functions relate to LLVMTypeRef instances.
778 *
779 * @see llvm::StructType
780 *
781 * @{
782 */
783
784/**
785 * Create a new structure type in a context.
786 *
787 * A structure is specified by a list of inner elements/types and
788 * whether these can be packed together.
789 *
790 * @see llvm::StructType::create()
791 */
Erick Tryzelaar262332f2009-08-14 00:01:31 +0000792LLVMTypeRef LLVMStructTypeInContext(LLVMContextRef C, LLVMTypeRef *ElementTypes,
Chris Lattner25963c62010-01-09 22:27:07 +0000793 unsigned ElementCount, LLVMBool Packed);
Gregory Szorc34c863a2012-03-21 03:54:29 +0000794
795/**
796 * Create a new structure type in the global context.
797 *
798 * @see llvm::StructType::create()
799 */
Gordon Henriksened7beaa2007-10-06 16:05:20 +0000800LLVMTypeRef LLVMStructType(LLVMTypeRef *ElementTypes, unsigned ElementCount,
Chris Lattner25963c62010-01-09 22:27:07 +0000801 LLVMBool Packed);
Gregory Szorc34c863a2012-03-21 03:54:29 +0000802
803/**
804 * Create an empty structure in a context having a specified name.
805 *
806 * @see llvm::StructType::create()
807 */
Chris Lattnere71ccde2011-07-14 05:53:17 +0000808LLVMTypeRef LLVMStructCreateNamed(LLVMContextRef C, const char *Name);
Gregory Szorc34c863a2012-03-21 03:54:29 +0000809
810/**
811 * Obtain the name of a structure.
812 *
813 * @see llvm::StructType::getName()
814 */
Torok Edwin0d5f6ae2011-10-06 12:12:50 +0000815const char *LLVMGetStructName(LLVMTypeRef Ty);
Gregory Szorc34c863a2012-03-21 03:54:29 +0000816
817/**
818 * Set the contents of a structure type.
819 *
820 * @see llvm::StructType::setBody()
821 */
Chris Lattnere71ccde2011-07-14 05:53:17 +0000822void LLVMStructSetBody(LLVMTypeRef StructTy, LLVMTypeRef *ElementTypes,
823 unsigned ElementCount, LLVMBool Packed);
824
Gregory Szorc34c863a2012-03-21 03:54:29 +0000825/**
826 * Get the number of elements defined inside the structure.
827 *
828 * @see llvm::StructType::getNumElements()
829 */
Gordon Henriksenc23b66c2007-09-26 20:56:12 +0000830unsigned LLVMCountStructElementTypes(LLVMTypeRef StructTy);
Gregory Szorc34c863a2012-03-21 03:54:29 +0000831
832/**
833 * Get the elements within a structure.
834 *
835 * The function is passed the address of a pre-allocated array of
836 * LLVMTypeRef at least LLVMCountStructElementTypes() long. After
837 * invocation, this array will be populated with the structure's
838 * elements. The objects in the destination array will have a lifetime
839 * of the structure type itself, which is the lifetime of the context it
840 * is contained in.
841 */
Gordon Henriksen76a03742007-09-18 03:18:57 +0000842void LLVMGetStructElementTypes(LLVMTypeRef StructTy, LLVMTypeRef *Dest);
Gregory Szorc34c863a2012-03-21 03:54:29 +0000843
844/**
845 * Determine whether a structure is packed.
846 *
847 * @see llvm::StructType::isPacked()
848 */
Chris Lattner25963c62010-01-09 22:27:07 +0000849LLVMBool LLVMIsPackedStruct(LLVMTypeRef StructTy);
Gregory Szorc34c863a2012-03-21 03:54:29 +0000850
851/**
852 * Determine whether a structure is opaque.
853 *
854 * @see llvm::StructType::isOpaque()
855 */
Chris Lattner17cf05b2011-07-14 16:20:28 +0000856LLVMBool LLVMIsOpaqueStruct(LLVMTypeRef StructTy);
857
Gregory Szorc34c863a2012-03-21 03:54:29 +0000858/**
859 * @}
860 */
Gordon Henriksen76a03742007-09-18 03:18:57 +0000861
Gregory Szorc34c863a2012-03-21 03:54:29 +0000862
863/**
864 * @defgroup LLVMCCoreTypeSequential Sequential Types
865 *
866 * Sequential types represents "arrays" of types. This is a super class
867 * for array, vector, and pointer types.
868 *
869 * @{
870 */
871
872/**
873 * Obtain the type of elements within a sequential type.
874 *
875 * This works on array, vector, and pointer types.
876 *
877 * @see llvm::SequentialType::getElementType()
878 */
879LLVMTypeRef LLVMGetElementType(LLVMTypeRef Ty);
880
881/**
882 * Create a fixed size array type that refers to a specific type.
883 *
884 * The created type will exist in the context that its element type
885 * exists in.
886 *
887 * @see llvm::ArrayType::get()
888 */
Gordon Henriksened7beaa2007-10-06 16:05:20 +0000889LLVMTypeRef LLVMArrayType(LLVMTypeRef ElementType, unsigned ElementCount);
Gregory Szorc34c863a2012-03-21 03:54:29 +0000890
891/**
892 * Obtain the length of an array type.
893 *
894 * This only works on types that represent arrays.
895 *
896 * @see llvm::ArrayType::getNumElements()
897 */
898unsigned LLVMGetArrayLength(LLVMTypeRef ArrayTy);
899
900/**
901 * Create a pointer type that points to a defined type.
902 *
903 * The created type will exist in the context that its pointee type
904 * exists in.
905 *
906 * @see llvm::PointerType::get()
907 */
Gordon Henriksen5a3fe032007-12-17 16:08:32 +0000908LLVMTypeRef LLVMPointerType(LLVMTypeRef ElementType, unsigned AddressSpace);
Gregory Szorc34c863a2012-03-21 03:54:29 +0000909
910/**
911 * Obtain the address space of a pointer type.
912 *
913 * This only works on types that represent pointers.
914 *
915 * @see llvm::PointerType::getAddressSpace()
916 */
917unsigned LLVMGetPointerAddressSpace(LLVMTypeRef PointerTy);
918
919/**
920 * Create a vector type that contains a defined type and has a specific
921 * number of elements.
922 *
923 * The created type will exist in the context thats its element type
924 * exists in.
925 *
926 * @see llvm::VectorType::get()
927 */
Gordon Henriksened7beaa2007-10-06 16:05:20 +0000928LLVMTypeRef LLVMVectorType(LLVMTypeRef ElementType, unsigned ElementCount);
Gordon Henriksen76a03742007-09-18 03:18:57 +0000929
Gregory Szorc34c863a2012-03-21 03:54:29 +0000930/**
931 * Obtain the number of elements in a vector type.
932 *
933 * This only works on types that represent vectors.
934 *
935 * @see llvm::VectorType::getNumElements()
936 */
Gordon Henriksen76a03742007-09-18 03:18:57 +0000937unsigned LLVMGetVectorSize(LLVMTypeRef VectorTy);
938
Gregory Szorc34c863a2012-03-21 03:54:29 +0000939/**
940 * @}
941 */
942
943/**
944 * @defgroup LLVMCCoreTypeOther Other Types
945 *
946 * @{
947 */
948
949/**
950 * Create a void type in a context.
951 */
Erick Tryzelaar262332f2009-08-14 00:01:31 +0000952LLVMTypeRef LLVMVoidTypeInContext(LLVMContextRef C);
Gregory Szorc34c863a2012-03-21 03:54:29 +0000953
954/**
955 * Create a label type in a context.
956 */
Erick Tryzelaar262332f2009-08-14 00:01:31 +0000957LLVMTypeRef LLVMLabelTypeInContext(LLVMContextRef C);
Gregory Szorc34c863a2012-03-21 03:54:29 +0000958
959/**
960 * Create a X86 MMX type in a context.
961 */
Dale Johannesen95b67af2010-09-10 21:58:02 +0000962LLVMTypeRef LLVMX86MMXTypeInContext(LLVMContextRef C);
Erick Tryzelaar262332f2009-08-14 00:01:31 +0000963
Gregory Szorc34c863a2012-03-21 03:54:29 +0000964/**
965 * These are similar to the above functions except they operate on the
966 * global context.
967 */
Gordon Henriksena735a9c2008-05-04 12:55:34 +0000968LLVMTypeRef LLVMVoidType(void);
969LLVMTypeRef LLVMLabelType(void);
Dale Johannesen95b67af2010-09-10 21:58:02 +0000970LLVMTypeRef LLVMX86MMXType(void);
Gordon Henriksen76a03742007-09-18 03:18:57 +0000971
Gregory Szorc34c863a2012-03-21 03:54:29 +0000972/**
973 * @}
974 */
Gordon Henriksen76a03742007-09-18 03:18:57 +0000975
Gregory Szorc34c863a2012-03-21 03:54:29 +0000976/**
977 * @}
978 */
979
980/**
981 * @defgroup LLVMCCoreValues Values
982 *
983 * The bulk of LLVM's object model consists of values, which comprise a very
Gordon Henriksen76a03742007-09-18 03:18:57 +0000984 * rich type hierarchy.
Gregory Szorc34c863a2012-03-21 03:54:29 +0000985 *
986 * LLVMValueRef essentially represents llvm::Value. There is a rich
987 * hierarchy of classes within this type. Depending on the instance
Eli Benderskyc52863c2012-08-10 18:30:44 +0000988 * obtained, not all APIs are available.
Gregory Szorc34c863a2012-03-21 03:54:29 +0000989 *
990 * Callers can determine the type of a LLVMValueRef by calling the
991 * LLVMIsA* family of functions (e.g. LLVMIsAArgument()). These
992 * functions are defined by a macro, so it isn't obvious which are
993 * available by looking at the Doxygen source code. Instead, look at the
994 * source definition of LLVM_FOR_EACH_VALUE_SUBCLASS and note the list
995 * of value names given. These value names also correspond to classes in
996 * the llvm::Value hierarchy.
997 *
998 * @{
Gordon Henriksen76a03742007-09-18 03:18:57 +0000999 */
1000
Gordon Henriksen29e38942008-12-19 18:39:45 +00001001#define LLVM_FOR_EACH_VALUE_SUBCLASS(macro) \
1002 macro(Argument) \
1003 macro(BasicBlock) \
1004 macro(InlineAsm) \
Torok Edwind09b7572011-10-14 20:37:56 +00001005 macro(MDNode) \
1006 macro(MDString) \
Gordon Henriksen29e38942008-12-19 18:39:45 +00001007 macro(User) \
1008 macro(Constant) \
Torok Edwind09b7572011-10-14 20:37:56 +00001009 macro(BlockAddress) \
Gordon Henriksen29e38942008-12-19 18:39:45 +00001010 macro(ConstantAggregateZero) \
1011 macro(ConstantArray) \
1012 macro(ConstantExpr) \
1013 macro(ConstantFP) \
1014 macro(ConstantInt) \
1015 macro(ConstantPointerNull) \
1016 macro(ConstantStruct) \
1017 macro(ConstantVector) \
1018 macro(GlobalValue) \
1019 macro(Function) \
1020 macro(GlobalAlias) \
1021 macro(GlobalVariable) \
1022 macro(UndefValue) \
1023 macro(Instruction) \
1024 macro(BinaryOperator) \
1025 macro(CallInst) \
1026 macro(IntrinsicInst) \
1027 macro(DbgInfoIntrinsic) \
1028 macro(DbgDeclareInst) \
Gordon Henriksen29e38942008-12-19 18:39:45 +00001029 macro(MemIntrinsic) \
1030 macro(MemCpyInst) \
1031 macro(MemMoveInst) \
1032 macro(MemSetInst) \
1033 macro(CmpInst) \
Torok Edwind09b7572011-10-14 20:37:56 +00001034 macro(FCmpInst) \
1035 macro(ICmpInst) \
Gordon Henriksen29e38942008-12-19 18:39:45 +00001036 macro(ExtractElementInst) \
1037 macro(GetElementPtrInst) \
1038 macro(InsertElementInst) \
1039 macro(InsertValueInst) \
Bill Wendlingfae14752011-08-12 20:24:12 +00001040 macro(LandingPadInst) \
Gordon Henriksen29e38942008-12-19 18:39:45 +00001041 macro(PHINode) \
1042 macro(SelectInst) \
1043 macro(ShuffleVectorInst) \
1044 macro(StoreInst) \
1045 macro(TerminatorInst) \
1046 macro(BranchInst) \
Torok Edwind09b7572011-10-14 20:37:56 +00001047 macro(IndirectBrInst) \
Gordon Henriksen29e38942008-12-19 18:39:45 +00001048 macro(InvokeInst) \
1049 macro(ReturnInst) \
1050 macro(SwitchInst) \
1051 macro(UnreachableInst) \
Bill Wendlingf891bf82011-07-31 06:30:59 +00001052 macro(ResumeInst) \
Gordon Henriksen29e38942008-12-19 18:39:45 +00001053 macro(UnaryInstruction) \
Victor Hernandez8acf2952009-10-23 21:09:37 +00001054 macro(AllocaInst) \
Gordon Henriksen29e38942008-12-19 18:39:45 +00001055 macro(CastInst) \
Gordon Henriksen05a868f2008-12-19 18:51:17 +00001056 macro(BitCastInst) \
1057 macro(FPExtInst) \
1058 macro(FPToSIInst) \
1059 macro(FPToUIInst) \
1060 macro(FPTruncInst) \
1061 macro(IntToPtrInst) \
1062 macro(PtrToIntInst) \
1063 macro(SExtInst) \
1064 macro(SIToFPInst) \
1065 macro(TruncInst) \
1066 macro(UIToFPInst) \
1067 macro(ZExtInst) \
1068 macro(ExtractValueInst) \
Gordon Henriksen05a868f2008-12-19 18:51:17 +00001069 macro(LoadInst) \
1070 macro(VAArgInst)
Gordon Henriksen29e38942008-12-19 18:39:45 +00001071
Gregory Szorc34c863a2012-03-21 03:54:29 +00001072/**
1073 * @defgroup LLVMCCoreValueGeneral General APIs
1074 *
1075 * Functions in this section work on all LLVMValueRef instances,
1076 * regardless of their sub-type. They correspond to functions available
1077 * on llvm::Value.
1078 *
1079 * @{
1080 */
Gordon Henriksen76a03742007-09-18 03:18:57 +00001081
Gregory Szorc34c863a2012-03-21 03:54:29 +00001082/**
1083 * Obtain the type of a value.
1084 *
1085 * @see llvm::Value::getType()
1086 */
1087LLVMTypeRef LLVMTypeOf(LLVMValueRef Val);
1088
1089/**
1090 * Obtain the string name of a value.
1091 *
1092 * @see llvm::Value::getName()
1093 */
1094const char *LLVMGetValueName(LLVMValueRef Val);
1095
1096/**
1097 * Set the string name of a value.
1098 *
1099 * @see llvm::Value::setName()
1100 */
1101void LLVMSetValueName(LLVMValueRef Val, const char *Name);
1102
1103/**
1104 * Dump a representation of a value to stderr.
1105 *
1106 * @see llvm::Value::dump()
1107 */
1108void LLVMDumpValue(LLVMValueRef Val);
1109
1110/**
1111 * Replace all uses of a value with another one.
1112 *
1113 * @see llvm::Value::replaceAllUsesWith()
1114 */
1115void LLVMReplaceAllUsesWith(LLVMValueRef OldVal, LLVMValueRef NewVal);
1116
1117/**
1118 * Determine whether the specified constant instance is constant.
1119 */
1120LLVMBool LLVMIsConstant(LLVMValueRef Val);
1121
1122/**
1123 * Determine whether a value instance is undefined.
1124 */
1125LLVMBool LLVMIsUndef(LLVMValueRef Val);
1126
1127/**
1128 * Convert value instances between types.
1129 *
1130 * Internally, a LLVMValueRef is "pinned" to a specific type. This
1131 * series of functions allows you to cast an instance to a specific
1132 * type.
1133 *
1134 * If the cast is not valid for the specified type, NULL is returned.
1135 *
1136 * @see llvm::dyn_cast_or_null<>
1137 */
Gordon Henriksen29e38942008-12-19 18:39:45 +00001138#define LLVM_DECLARE_VALUE_CAST(name) \
1139 LLVMValueRef LLVMIsA##name(LLVMValueRef Val);
1140LLVM_FOR_EACH_VALUE_SUBCLASS(LLVM_DECLARE_VALUE_CAST)
1141
Gregory Szorc34c863a2012-03-21 03:54:29 +00001142/**
1143 * @}
1144 */
1145
1146/**
1147 * @defgroup LLVMCCoreValueUses Usage
1148 *
1149 * This module defines functions that allow you to inspect the uses of a
1150 * LLVMValueRef.
1151 *
1152 * It is possible to obtain a LLVMUseRef for any LLVMValueRef instance.
1153 * Each LLVMUseRef (which corresponds to a llvm::Use instance) holds a
1154 * llvm::User and llvm::Value.
1155 *
1156 * @{
1157 */
1158
1159/**
1160 * Obtain the first use of a value.
1161 *
1162 * Uses are obtained in an iterator fashion. First, call this function
1163 * to obtain a reference to the first use. Then, call LLVMGetNextUse()
Eli Benderskyc52863c2012-08-10 18:30:44 +00001164 * on that instance and all subsequently obtained instances until
Gregory Szorc34c863a2012-03-21 03:54:29 +00001165 * LLVMGetNextUse() returns NULL.
1166 *
1167 * @see llvm::Value::use_begin()
1168 */
Erick Tryzelaar9f9857e2010-03-02 20:32:28 +00001169LLVMUseRef LLVMGetFirstUse(LLVMValueRef Val);
Gregory Szorc34c863a2012-03-21 03:54:29 +00001170
1171/**
1172 * Obtain the next use of a value.
1173 *
1174 * This effectively advances the iterator. It returns NULL if you are on
1175 * the final use and no more are available.
1176 */
Erick Tryzelaar9f9857e2010-03-02 20:32:28 +00001177LLVMUseRef LLVMGetNextUse(LLVMUseRef U);
Gregory Szorc34c863a2012-03-21 03:54:29 +00001178
1179/**
1180 * Obtain the user value for a user.
1181 *
1182 * The returned value corresponds to a llvm::User type.
1183 *
1184 * @see llvm::Use::getUser()
1185 */
Erick Tryzelaar9f9857e2010-03-02 20:32:28 +00001186LLVMValueRef LLVMGetUser(LLVMUseRef U);
Gregory Szorc34c863a2012-03-21 03:54:29 +00001187
1188/**
1189 * Obtain the value this use corresponds to.
1190 *
1191 * @see llvm::Use::get().
1192 */
Erick Tryzelaar9f9857e2010-03-02 20:32:28 +00001193LLVMValueRef LLVMGetUsedValue(LLVMUseRef U);
Chris Lattner40cf28d2009-10-12 04:01:02 +00001194
Gregory Szorc34c863a2012-03-21 03:54:29 +00001195/**
1196 * @}
1197 */
1198
1199/**
Gregory Szorc52d26602012-03-21 07:28:27 +00001200 * @defgroup LLVMCCoreValueUser User value
Gregory Szorc34c863a2012-03-21 03:54:29 +00001201 *
1202 * Function in this group pertain to LLVMValueRef instances that descent
1203 * from llvm::User. This includes constants, instructions, and
1204 * operators.
1205 *
1206 * @{
1207 */
1208
1209/**
1210 * Obtain an operand at a specific index in a llvm::User value.
1211 *
1212 * @see llvm::User::getOperand()
1213 */
Chris Lattner40cf28d2009-10-12 04:01:02 +00001214LLVMValueRef LLVMGetOperand(LLVMValueRef Val, unsigned Index);
Gregory Szorc34c863a2012-03-21 03:54:29 +00001215
1216/**
1217 * Set an operand at a specific index in a llvm::User value.
1218 *
1219 * @see llvm::User::setOperand()
1220 */
Erick Tryzelaarb4d48702010-08-20 14:51:22 +00001221void LLVMSetOperand(LLVMValueRef User, unsigned Index, LLVMValueRef Val);
Gregory Szorc34c863a2012-03-21 03:54:29 +00001222
1223/**
1224 * Obtain the number of operands in a llvm::User value.
1225 *
1226 * @see llvm::User::getNumOperands()
1227 */
Erick Tryzelaarb4d48702010-08-20 14:51:22 +00001228int LLVMGetNumOperands(LLVMValueRef Val);
Chris Lattner40cf28d2009-10-12 04:01:02 +00001229
Gregory Szorc34c863a2012-03-21 03:54:29 +00001230/**
1231 * @}
1232 */
1233
1234/**
Gregory Szorc52d26602012-03-21 07:28:27 +00001235 * @defgroup LLVMCCoreValueConstant Constants
Gregory Szorc34c863a2012-03-21 03:54:29 +00001236 *
1237 * This section contains APIs for interacting with LLVMValueRef that
1238 * correspond to llvm::Constant instances.
1239 *
1240 * These functions will work for any LLVMValueRef in the llvm::Constant
1241 * class hierarchy.
1242 *
1243 * @{
1244 */
1245
1246/**
1247 * Obtain a constant value referring to the null instance of a type.
1248 *
1249 * @see llvm::Constant::getNullValue()
1250 */
Gordon Henriksen1046c732007-10-06 15:11:06 +00001251LLVMValueRef LLVMConstNull(LLVMTypeRef Ty); /* all zeroes */
Gregory Szorc34c863a2012-03-21 03:54:29 +00001252
1253/**
1254 * Obtain a constant value referring to the instance of a type
1255 * consisting of all ones.
1256 *
1257 * This is only valid for integer types.
1258 *
1259 * @see llvm::Constant::getAllOnesValue()
1260 */
1261LLVMValueRef LLVMConstAllOnes(LLVMTypeRef Ty);
1262
1263/**
1264 * Obtain a constant value referring to an undefined value of a type.
1265 *
1266 * @see llvm::UndefValue::get()
1267 */
Gordon Henriksen76a03742007-09-18 03:18:57 +00001268LLVMValueRef LLVMGetUndef(LLVMTypeRef Ty);
Gregory Szorc34c863a2012-03-21 03:54:29 +00001269
1270/**
1271 * Determine whether a value instance is null.
1272 *
1273 * @see llvm::Constant::isNullValue()
1274 */
Chris Lattner25963c62010-01-09 22:27:07 +00001275LLVMBool LLVMIsNull(LLVMValueRef Val);
Gregory Szorc34c863a2012-03-21 03:54:29 +00001276
1277/**
1278 * Obtain a constant that is a constant pointer pointing to NULL for a
1279 * specified type.
1280 */
Chris Lattner7f318242009-07-06 17:29:59 +00001281LLVMValueRef LLVMConstPointerNull(LLVMTypeRef Ty);
Gordon Henriksen76a03742007-09-18 03:18:57 +00001282
Gregory Szorc34c863a2012-03-21 03:54:29 +00001283/**
1284 * @defgroup LLVMCCoreValueConstantScalar Scalar constants
1285 *
1286 * Functions in this group model LLVMValueRef instances that correspond
1287 * to constants referring to scalar types.
1288 *
1289 * For integer types, the LLVMTypeRef parameter should correspond to a
1290 * llvm::IntegerType instance and the returned LLVMValueRef will
1291 * correspond to a llvm::ConstantInt.
1292 *
1293 * For floating point types, the LLVMTypeRef returned corresponds to a
1294 * llvm::ConstantFP.
1295 *
1296 * @{
1297 */
Erick Tryzelaard8531fa2010-02-28 09:45:59 +00001298
Gregory Szorc34c863a2012-03-21 03:54:29 +00001299/**
1300 * Obtain a constant value for an integer type.
1301 *
1302 * The returned value corresponds to a llvm::ConstantInt.
1303 *
1304 * @see llvm::ConstantInt::get()
1305 *
1306 * @param IntTy Integer type to obtain value of.
1307 * @param N The value the returned instance should refer to.
1308 * @param SignExtend Whether to sign extend the produced value.
1309 */
Gordon Henriksen1046c732007-10-06 15:11:06 +00001310LLVMValueRef LLVMConstInt(LLVMTypeRef IntTy, unsigned long long N,
Chris Lattner25963c62010-01-09 22:27:07 +00001311 LLVMBool SignExtend);
Gregory Szorc34c863a2012-03-21 03:54:29 +00001312
1313/**
1314 * Obtain a constant value for an integer of arbitrary precision.
1315 *
1316 * @see llvm::ConstantInt::get()
1317 */
Chris Lattner4329e072010-11-23 02:47:22 +00001318LLVMValueRef LLVMConstIntOfArbitraryPrecision(LLVMTypeRef IntTy,
1319 unsigned NumWords,
1320 const uint64_t Words[]);
Gregory Szorc34c863a2012-03-21 03:54:29 +00001321
1322/**
1323 * Obtain a constant value for an integer parsed from a string.
1324 *
1325 * A similar API, LLVMConstIntOfStringAndSize is also available. If the
1326 * string's length is available, it is preferred to call that function
1327 * instead.
1328 *
1329 * @see llvm::ConstantInt::get()
1330 */
Erick Tryzelaardd991352009-08-16 23:36:46 +00001331LLVMValueRef LLVMConstIntOfString(LLVMTypeRef IntTy, const char *Text,
1332 uint8_t Radix);
Gregory Szorc34c863a2012-03-21 03:54:29 +00001333
1334/**
1335 * Obtain a constant value for an integer parsed from a string with
1336 * specified length.
1337 *
1338 * @see llvm::ConstantInt::get()
1339 */
Erick Tryzelaardd991352009-08-16 23:36:46 +00001340LLVMValueRef LLVMConstIntOfStringAndSize(LLVMTypeRef IntTy, const char *Text,
1341 unsigned SLen, uint8_t Radix);
Gregory Szorc34c863a2012-03-21 03:54:29 +00001342
1343/**
1344 * Obtain a constant value referring to a double floating point value.
1345 */
Gordon Henriksen1046c732007-10-06 15:11:06 +00001346LLVMValueRef LLVMConstReal(LLVMTypeRef RealTy, double N);
Gregory Szorc34c863a2012-03-21 03:54:29 +00001347
1348/**
1349 * Obtain a constant for a floating point value parsed from a string.
1350 *
1351 * A similar API, LLVMConstRealOfStringAndSize is also available. It
1352 * should be used if the input string's length is known.
1353 */
Gordon Henriksen931e1212008-02-02 01:07:50 +00001354LLVMValueRef LLVMConstRealOfString(LLVMTypeRef RealTy, const char *Text);
Gregory Szorc34c863a2012-03-21 03:54:29 +00001355
1356/**
1357 * Obtain a constant for a floating point value parsed from a string.
1358 */
Erick Tryzelaardd991352009-08-16 23:36:46 +00001359LLVMValueRef LLVMConstRealOfStringAndSize(LLVMTypeRef RealTy, const char *Text,
1360 unsigned SLen);
Gregory Szorc34c863a2012-03-21 03:54:29 +00001361
1362/**
1363 * Obtain the zero extended value for an integer constant value.
1364 *
1365 * @see llvm::ConstantInt::getZExtValue()
1366 */
Chris Lattner40cf28d2009-10-12 04:01:02 +00001367unsigned long long LLVMConstIntGetZExtValue(LLVMValueRef ConstantVal);
Gregory Szorc34c863a2012-03-21 03:54:29 +00001368
1369/**
1370 * Obtain the sign extended value for an integer constant value.
1371 *
1372 * @see llvm::ConstantInt::getSExtValue()
1373 */
Chris Lattner40cf28d2009-10-12 04:01:02 +00001374long long LLVMConstIntGetSExtValue(LLVMValueRef ConstantVal);
Erick Tryzelaardd991352009-08-16 23:36:46 +00001375
Gregory Szorc34c863a2012-03-21 03:54:29 +00001376/**
1377 * @}
1378 */
1379
1380/**
Gregory Szorc52d26602012-03-21 07:28:27 +00001381 * @defgroup LLVMCCoreValueConstantComposite Composite Constants
1382 *
1383 * Functions in this group operate on composite constants.
Gregory Szorc34c863a2012-03-21 03:54:29 +00001384 *
1385 * @{
1386 */
1387
1388/**
Gregory Szorc52d26602012-03-21 07:28:27 +00001389 * Create a ConstantDataSequential and initialize it with a string.
Gregory Szorc34c863a2012-03-21 03:54:29 +00001390 *
Gregory Szorc52d26602012-03-21 07:28:27 +00001391 * @see llvm::ConstantDataArray::getString()
Gregory Szorc34c863a2012-03-21 03:54:29 +00001392 */
Erick Tryzelaar262332f2009-08-14 00:01:31 +00001393LLVMValueRef LLVMConstStringInContext(LLVMContextRef C, const char *Str,
Chris Lattner25963c62010-01-09 22:27:07 +00001394 unsigned Length, LLVMBool DontNullTerminate);
Gregory Szorc52d26602012-03-21 07:28:27 +00001395
1396/**
1397 * Create a ConstantDataSequential with string content in the global context.
1398 *
1399 * This is the same as LLVMConstStringInContext except it operates on the
1400 * global context.
1401 *
1402 * @see LLVMConstStringInContext()
1403 * @see llvm::ConstantDataArray::getString()
1404 */
1405LLVMValueRef LLVMConstString(const char *Str, unsigned Length,
1406 LLVMBool DontNullTerminate);
1407
1408/**
1409 * Create an anonymous ConstantStruct with the specified values.
1410 *
1411 * @see llvm::ConstantStruct::getAnon()
1412 */
1413LLVMValueRef LLVMConstStructInContext(LLVMContextRef C,
Erick Tryzelaar262332f2009-08-14 00:01:31 +00001414 LLVMValueRef *ConstantVals,
Chris Lattner25963c62010-01-09 22:27:07 +00001415 unsigned Count, LLVMBool Packed);
Erick Tryzelaar262332f2009-08-14 00:01:31 +00001416
Gregory Szorc52d26602012-03-21 07:28:27 +00001417/**
1418 * Create a ConstantStruct in the global Context.
1419 *
1420 * This is the same as LLVMConstStructInContext except it operates on the
1421 * global Context.
1422 *
1423 * @see LLVMConstStructInContext()
1424 */
Gordon Henriksen1046c732007-10-06 15:11:06 +00001425LLVMValueRef LLVMConstStruct(LLVMValueRef *ConstantVals, unsigned Count,
Chris Lattner25963c62010-01-09 22:27:07 +00001426 LLVMBool Packed);
Gregory Szorc52d26602012-03-21 07:28:27 +00001427
1428/**
1429 * Create a ConstantArray from values.
1430 *
1431 * @see llvm::ConstantArray::get()
1432 */
1433LLVMValueRef LLVMConstArray(LLVMTypeRef ElementTy,
1434 LLVMValueRef *ConstantVals, unsigned Length);
1435
1436/**
1437 * Create a non-anonymous ConstantStruct from values.
1438 *
1439 * @see llvm::ConstantStruct::get()
1440 */
Rafael Espindola784ad242011-07-14 19:09:08 +00001441LLVMValueRef LLVMConstNamedStruct(LLVMTypeRef StructTy,
1442 LLVMValueRef *ConstantVals,
1443 unsigned Count);
Gregory Szorc52d26602012-03-21 07:28:27 +00001444
1445/**
1446 * Create a ConstantVector from values.
1447 *
1448 * @see llvm::ConstantVector::get()
1449 */
Gordon Henriksen1046c732007-10-06 15:11:06 +00001450LLVMValueRef LLVMConstVector(LLVMValueRef *ScalarConstantVals, unsigned Size);
Gordon Henriksen76a03742007-09-18 03:18:57 +00001451
Gregory Szorc52d26602012-03-21 07:28:27 +00001452/**
1453 * @}
1454 */
1455
1456/**
1457 * @defgroup LLVMCCoreValueConstantExpressions Constant Expressions
1458 *
1459 * Functions in this group correspond to APIs on llvm::ConstantExpr.
1460 *
1461 * @see llvm::ConstantExpr.
1462 *
1463 * @{
1464 */
Chris Lattner40cf28d2009-10-12 04:01:02 +00001465LLVMOpcode LLVMGetConstOpcode(LLVMValueRef ConstantVal);
Erick Tryzelaarfd529d72009-08-19 08:36:49 +00001466LLVMValueRef LLVMAlignOf(LLVMTypeRef Ty);
Gordon Henriksen7ce31762007-10-06 14:29:36 +00001467LLVMValueRef LLVMSizeOf(LLVMTypeRef Ty);
1468LLVMValueRef LLVMConstNeg(LLVMValueRef ConstantVal);
Erick Tryzelaar4c340c72010-02-28 05:51:43 +00001469LLVMValueRef LLVMConstNSWNeg(LLVMValueRef ConstantVal);
1470LLVMValueRef LLVMConstNUWNeg(LLVMValueRef ConstantVal);
Erick Tryzelaar4cc690c2009-08-16 02:20:12 +00001471LLVMValueRef LLVMConstFNeg(LLVMValueRef ConstantVal);
Gordon Henriksen7ce31762007-10-06 14:29:36 +00001472LLVMValueRef LLVMConstNot(LLVMValueRef ConstantVal);
1473LLVMValueRef LLVMConstAdd(LLVMValueRef LHSConstant, LLVMValueRef RHSConstant);
Dan Gohmane4ca02d2009-09-03 23:34:49 +00001474LLVMValueRef LLVMConstNSWAdd(LLVMValueRef LHSConstant, LLVMValueRef RHSConstant);
Erick Tryzelaar4c340c72010-02-28 05:51:43 +00001475LLVMValueRef LLVMConstNUWAdd(LLVMValueRef LHSConstant, LLVMValueRef RHSConstant);
Erick Tryzelaar4cc690c2009-08-16 02:20:12 +00001476LLVMValueRef LLVMConstFAdd(LLVMValueRef LHSConstant, LLVMValueRef RHSConstant);
Gordon Henriksen7ce31762007-10-06 14:29:36 +00001477LLVMValueRef LLVMConstSub(LLVMValueRef LHSConstant, LLVMValueRef RHSConstant);
Erick Tryzelaar4c340c72010-02-28 05:51:43 +00001478LLVMValueRef LLVMConstNSWSub(LLVMValueRef LHSConstant, LLVMValueRef RHSConstant);
1479LLVMValueRef LLVMConstNUWSub(LLVMValueRef LHSConstant, LLVMValueRef RHSConstant);
Erick Tryzelaar4cc690c2009-08-16 02:20:12 +00001480LLVMValueRef LLVMConstFSub(LLVMValueRef LHSConstant, LLVMValueRef RHSConstant);
Gordon Henriksen7ce31762007-10-06 14:29:36 +00001481LLVMValueRef LLVMConstMul(LLVMValueRef LHSConstant, LLVMValueRef RHSConstant);
Erick Tryzelaar4c340c72010-02-28 05:51:43 +00001482LLVMValueRef LLVMConstNSWMul(LLVMValueRef LHSConstant, LLVMValueRef RHSConstant);
1483LLVMValueRef LLVMConstNUWMul(LLVMValueRef LHSConstant, LLVMValueRef RHSConstant);
Erick Tryzelaar4cc690c2009-08-16 02:20:12 +00001484LLVMValueRef LLVMConstFMul(LLVMValueRef LHSConstant, LLVMValueRef RHSConstant);
Gordon Henriksen7ce31762007-10-06 14:29:36 +00001485LLVMValueRef LLVMConstUDiv(LLVMValueRef LHSConstant, LLVMValueRef RHSConstant);
1486LLVMValueRef LLVMConstSDiv(LLVMValueRef LHSConstant, LLVMValueRef RHSConstant);
Dan Gohmane4ca02d2009-09-03 23:34:49 +00001487LLVMValueRef LLVMConstExactSDiv(LLVMValueRef LHSConstant, LLVMValueRef RHSConstant);
Gordon Henriksen7ce31762007-10-06 14:29:36 +00001488LLVMValueRef LLVMConstFDiv(LLVMValueRef LHSConstant, LLVMValueRef RHSConstant);
1489LLVMValueRef LLVMConstURem(LLVMValueRef LHSConstant, LLVMValueRef RHSConstant);
1490LLVMValueRef LLVMConstSRem(LLVMValueRef LHSConstant, LLVMValueRef RHSConstant);
1491LLVMValueRef LLVMConstFRem(LLVMValueRef LHSConstant, LLVMValueRef RHSConstant);
1492LLVMValueRef LLVMConstAnd(LLVMValueRef LHSConstant, LLVMValueRef RHSConstant);
1493LLVMValueRef LLVMConstOr(LLVMValueRef LHSConstant, LLVMValueRef RHSConstant);
1494LLVMValueRef LLVMConstXor(LLVMValueRef LHSConstant, LLVMValueRef RHSConstant);
1495LLVMValueRef LLVMConstICmp(LLVMIntPredicate Predicate,
1496 LLVMValueRef LHSConstant, LLVMValueRef RHSConstant);
1497LLVMValueRef LLVMConstFCmp(LLVMRealPredicate Predicate,
1498 LLVMValueRef LHSConstant, LLVMValueRef RHSConstant);
1499LLVMValueRef LLVMConstShl(LLVMValueRef LHSConstant, LLVMValueRef RHSConstant);
1500LLVMValueRef LLVMConstLShr(LLVMValueRef LHSConstant, LLVMValueRef RHSConstant);
1501LLVMValueRef LLVMConstAShr(LLVMValueRef LHSConstant, LLVMValueRef RHSConstant);
1502LLVMValueRef LLVMConstGEP(LLVMValueRef ConstantVal,
1503 LLVMValueRef *ConstantIndices, unsigned NumIndices);
Dan Gohmane4ca02d2009-09-03 23:34:49 +00001504LLVMValueRef LLVMConstInBoundsGEP(LLVMValueRef ConstantVal,
1505 LLVMValueRef *ConstantIndices,
1506 unsigned NumIndices);
Gordon Henriksen7ce31762007-10-06 14:29:36 +00001507LLVMValueRef LLVMConstTrunc(LLVMValueRef ConstantVal, LLVMTypeRef ToType);
1508LLVMValueRef LLVMConstSExt(LLVMValueRef ConstantVal, LLVMTypeRef ToType);
1509LLVMValueRef LLVMConstZExt(LLVMValueRef ConstantVal, LLVMTypeRef ToType);
1510LLVMValueRef LLVMConstFPTrunc(LLVMValueRef ConstantVal, LLVMTypeRef ToType);
1511LLVMValueRef LLVMConstFPExt(LLVMValueRef ConstantVal, LLVMTypeRef ToType);
1512LLVMValueRef LLVMConstUIToFP(LLVMValueRef ConstantVal, LLVMTypeRef ToType);
1513LLVMValueRef LLVMConstSIToFP(LLVMValueRef ConstantVal, LLVMTypeRef ToType);
1514LLVMValueRef LLVMConstFPToUI(LLVMValueRef ConstantVal, LLVMTypeRef ToType);
1515LLVMValueRef LLVMConstFPToSI(LLVMValueRef ConstantVal, LLVMTypeRef ToType);
1516LLVMValueRef LLVMConstPtrToInt(LLVMValueRef ConstantVal, LLVMTypeRef ToType);
1517LLVMValueRef LLVMConstIntToPtr(LLVMValueRef ConstantVal, LLVMTypeRef ToType);
1518LLVMValueRef LLVMConstBitCast(LLVMValueRef ConstantVal, LLVMTypeRef ToType);
Erick Tryzelaar4cc690c2009-08-16 02:20:12 +00001519LLVMValueRef LLVMConstZExtOrBitCast(LLVMValueRef ConstantVal,
1520 LLVMTypeRef ToType);
1521LLVMValueRef LLVMConstSExtOrBitCast(LLVMValueRef ConstantVal,
1522 LLVMTypeRef ToType);
1523LLVMValueRef LLVMConstTruncOrBitCast(LLVMValueRef ConstantVal,
1524 LLVMTypeRef ToType);
1525LLVMValueRef LLVMConstPointerCast(LLVMValueRef ConstantVal,
1526 LLVMTypeRef ToType);
1527LLVMValueRef LLVMConstIntCast(LLVMValueRef ConstantVal, LLVMTypeRef ToType,
Chris Lattner25963c62010-01-09 22:27:07 +00001528 LLVMBool isSigned);
Erick Tryzelaar4cc690c2009-08-16 02:20:12 +00001529LLVMValueRef LLVMConstFPCast(LLVMValueRef ConstantVal, LLVMTypeRef ToType);
Gordon Henriksen7ce31762007-10-06 14:29:36 +00001530LLVMValueRef LLVMConstSelect(LLVMValueRef ConstantCondition,
1531 LLVMValueRef ConstantIfTrue,
1532 LLVMValueRef ConstantIfFalse);
1533LLVMValueRef LLVMConstExtractElement(LLVMValueRef VectorConstant,
1534 LLVMValueRef IndexConstant);
1535LLVMValueRef LLVMConstInsertElement(LLVMValueRef VectorConstant,
1536 LLVMValueRef ElementValueConstant,
1537 LLVMValueRef IndexConstant);
1538LLVMValueRef LLVMConstShuffleVector(LLVMValueRef VectorAConstant,
1539 LLVMValueRef VectorBConstant,
1540 LLVMValueRef MaskConstant);
Dan Gohmand5104a52008-11-03 22:55:43 +00001541LLVMValueRef LLVMConstExtractValue(LLVMValueRef AggConstant, unsigned *IdxList,
1542 unsigned NumIdx);
1543LLVMValueRef LLVMConstInsertValue(LLVMValueRef AggConstant,
1544 LLVMValueRef ElementValueConstant,
1545 unsigned *IdxList, unsigned NumIdx);
Chris Lattner25963c62010-01-09 22:27:07 +00001546LLVMValueRef LLVMConstInlineAsm(LLVMTypeRef Ty,
Chris Lattner3d1f5522008-12-17 21:39:50 +00001547 const char *AsmString, const char *Constraints,
Chris Lattner25963c62010-01-09 22:27:07 +00001548 LLVMBool HasSideEffects, LLVMBool IsAlignStack);
Erick Tryzelaar0fb26ef2010-02-28 09:46:06 +00001549LLVMValueRef LLVMBlockAddress(LLVMValueRef F, LLVMBasicBlockRef BB);
Gordon Henriksen7ce31762007-10-06 14:29:36 +00001550
Gregory Szorc52d26602012-03-21 07:28:27 +00001551/**
1552 * @}
1553 */
1554
1555/**
1556 * @defgroup LLVMCCoreValueConstantGlobals Global Values
1557 *
1558 * This group contains functions that operate on global values. Functions in
1559 * this group relate to functions in the llvm::GlobalValue class tree.
1560 *
1561 * @see llvm::GlobalValue
1562 *
1563 * @{
1564 */
1565
Gordon Henriksen265f7802008-03-19 01:11:35 +00001566LLVMModuleRef LLVMGetGlobalParent(LLVMValueRef Global);
Chris Lattner25963c62010-01-09 22:27:07 +00001567LLVMBool LLVMIsDeclaration(LLVMValueRef Global);
Gordon Henriksen76a03742007-09-18 03:18:57 +00001568LLVMLinkage LLVMGetLinkage(LLVMValueRef Global);
1569void LLVMSetLinkage(LLVMValueRef Global, LLVMLinkage Linkage);
1570const char *LLVMGetSection(LLVMValueRef Global);
1571void LLVMSetSection(LLVMValueRef Global, const char *Section);
1572LLVMVisibility LLVMGetVisibility(LLVMValueRef Global);
1573void LLVMSetVisibility(LLVMValueRef Global, LLVMVisibility Viz);
1574unsigned LLVMGetAlignment(LLVMValueRef Global);
1575void LLVMSetAlignment(LLVMValueRef Global, unsigned Bytes);
1576
Gregory Szorc52d26602012-03-21 07:28:27 +00001577/**
1578 * @defgroup LLVMCoreValueConstantGlobalVariable Global Variables
1579 *
1580 * This group contains functions that operate on global variable values.
1581 *
1582 * @see llvm::GlobalVariable
1583 *
1584 * @{
1585 */
Gordon Henriksen76a03742007-09-18 03:18:57 +00001586LLVMValueRef LLVMAddGlobal(LLVMModuleRef M, LLVMTypeRef Ty, const char *Name);
Erick Tryzelaar06894b32010-02-28 09:46:13 +00001587LLVMValueRef LLVMAddGlobalInAddressSpace(LLVMModuleRef M, LLVMTypeRef Ty,
1588 const char *Name,
1589 unsigned AddressSpace);
Gordon Henriksen783f7bb2007-10-08 03:45:09 +00001590LLVMValueRef LLVMGetNamedGlobal(LLVMModuleRef M, const char *Name);
Gordon Henriksen07a45f42008-03-23 22:21:29 +00001591LLVMValueRef LLVMGetFirstGlobal(LLVMModuleRef M);
1592LLVMValueRef LLVMGetLastGlobal(LLVMModuleRef M);
1593LLVMValueRef LLVMGetNextGlobal(LLVMValueRef GlobalVar);
1594LLVMValueRef LLVMGetPreviousGlobal(LLVMValueRef GlobalVar);
Gordon Henriksen76a03742007-09-18 03:18:57 +00001595void LLVMDeleteGlobal(LLVMValueRef GlobalVar);
Gordon Henriksen76a03742007-09-18 03:18:57 +00001596LLVMValueRef LLVMGetInitializer(LLVMValueRef GlobalVar);
1597void LLVMSetInitializer(LLVMValueRef GlobalVar, LLVMValueRef ConstantVal);
Chris Lattner25963c62010-01-09 22:27:07 +00001598LLVMBool LLVMIsThreadLocal(LLVMValueRef GlobalVar);
1599void LLVMSetThreadLocal(LLVMValueRef GlobalVar, LLVMBool IsThreadLocal);
1600LLVMBool LLVMIsGlobalConstant(LLVMValueRef GlobalVar);
1601void LLVMSetGlobalConstant(LLVMValueRef GlobalVar, LLVMBool IsConstant);
Gordon Henriksen76a03742007-09-18 03:18:57 +00001602
Gregory Szorc52d26602012-03-21 07:28:27 +00001603/**
1604 * @}
1605 */
1606
1607/**
1608 * @defgroup LLVMCoreValueConstantGlobalAlias Global Aliases
1609 *
1610 * This group contains function that operate on global alias values.
1611 *
1612 * @see llvm::GlobalAlias
1613 *
1614 * @{
1615 */
Chris Lattner3d1f5522008-12-17 21:39:50 +00001616LLVMValueRef LLVMAddAlias(LLVMModuleRef M, LLVMTypeRef Ty, LLVMValueRef Aliasee,
1617 const char *Name);
1618
Gregory Szorc34c863a2012-03-21 03:54:29 +00001619/**
1620 * @}
1621 */
1622
1623/**
1624 * @defgroup LLVMCCoreValueFunction Function values
1625 *
1626 * Functions in this group operate on LLVMValueRef instances that
1627 * correspond to llvm::Function instances.
1628 *
1629 * @see llvm::Function
1630 *
1631 * @{
1632 */
1633
1634/**
1635 * Remove a function from its containing module and deletes it.
1636 *
1637 * @see llvm::Function::eraseFromParent()
1638 */
Gordon Henriksenc23b66c2007-09-26 20:56:12 +00001639void LLVMDeleteFunction(LLVMValueRef Fn);
Gregory Szorc34c863a2012-03-21 03:54:29 +00001640
1641/**
1642 * Obtain the ID number from a function instance.
1643 *
1644 * @see llvm::Function::getIntrinsicID()
1645 */
Gordon Henriksenc23b66c2007-09-26 20:56:12 +00001646unsigned LLVMGetIntrinsicID(LLVMValueRef Fn);
Gregory Szorc34c863a2012-03-21 03:54:29 +00001647
1648/**
1649 * Obtain the calling function of a function.
1650 *
1651 * The returned value corresponds to the LLVMCallConv enumeration.
1652 *
1653 * @see llvm::Function::getCallingConv()
1654 */
Gordon Henriksenc23b66c2007-09-26 20:56:12 +00001655unsigned LLVMGetFunctionCallConv(LLVMValueRef Fn);
Gregory Szorc34c863a2012-03-21 03:54:29 +00001656
1657/**
1658 * Set the calling convention of a function.
1659 *
1660 * @see llvm::Function::setCallingConv()
1661 *
1662 * @param Fn Function to operate on
1663 * @param CC LLVMCallConv to set calling convention to
1664 */
Gordon Henriksenc23b66c2007-09-26 20:56:12 +00001665void LLVMSetFunctionCallConv(LLVMValueRef Fn, unsigned CC);
Gregory Szorc34c863a2012-03-21 03:54:29 +00001666
1667/**
1668 * Obtain the name of the garbage collector to use during code
1669 * generation.
1670 *
1671 * @see llvm::Function::getGC()
1672 */
Gordon Henriksend930f912008-08-17 18:44:35 +00001673const char *LLVMGetGC(LLVMValueRef Fn);
Gregory Szorc34c863a2012-03-21 03:54:29 +00001674
1675/**
1676 * Define the garbage collector to use during code generation.
1677 *
1678 * @see llvm::Function::setGC()
1679 */
Gordon Henriksend930f912008-08-17 18:44:35 +00001680void LLVMSetGC(LLVMValueRef Fn, const char *Name);
Gregory Szorc34c863a2012-03-21 03:54:29 +00001681
1682/**
1683 * Add an attribute to a function.
1684 *
1685 * @see llvm::Function::addAttribute()
1686 */
Duncan Sands7374a012009-05-06 12:21:17 +00001687void LLVMAddFunctionAttr(LLVMValueRef Fn, LLVMAttribute PA);
Gregory Szorc34c863a2012-03-21 03:54:29 +00001688
1689/**
1690 * Obtain an attribute from a function.
1691 *
1692 * @see llvm::Function::getAttributes()
1693 */
Chris Lattner40cf28d2009-10-12 04:01:02 +00001694LLVMAttribute LLVMGetFunctionAttr(LLVMValueRef Fn);
Gregory Szorc34c863a2012-03-21 03:54:29 +00001695
1696/**
1697 * Remove an attribute from a function.
1698 */
Duncan Sands7374a012009-05-06 12:21:17 +00001699void LLVMRemoveFunctionAttr(LLVMValueRef Fn, LLVMAttribute PA);
Gordon Henriksenc23b66c2007-09-26 20:56:12 +00001700
Gregory Szorc34c863a2012-03-21 03:54:29 +00001701/**
1702 * @defgroup LLVMCCoreValueFunctionParameters Function Parameters
1703 *
1704 * Functions in this group relate to arguments/parameters on functions.
1705 *
1706 * Functions in this group expect LLVMValueRef instances that correspond
1707 * to llvm::Function instances.
1708 *
1709 * @{
1710 */
1711
1712/**
1713 * Obtain the number of parameters in a function.
1714 *
1715 * @see llvm::Function::arg_size()
1716 */
Gordon Henriksen265f7802008-03-19 01:11:35 +00001717unsigned LLVMCountParams(LLVMValueRef Fn);
Gregory Szorc34c863a2012-03-21 03:54:29 +00001718
1719/**
1720 * Obtain the parameters in a function.
1721 *
1722 * The takes a pointer to a pre-allocated array of LLVMValueRef that is
1723 * at least LLVMCountParams() long. This array will be filled with
1724 * LLVMValueRef instances which correspond to the parameters the
1725 * function receives. Each LLVMValueRef corresponds to a llvm::Argument
1726 * instance.
1727 *
1728 * @see llvm::Function::arg_begin()
1729 */
Gordon Henriksen265f7802008-03-19 01:11:35 +00001730void LLVMGetParams(LLVMValueRef Fn, LLVMValueRef *Params);
Gregory Szorc34c863a2012-03-21 03:54:29 +00001731
1732/**
1733 * Obtain the parameter at the specified index.
1734 *
1735 * Parameters are indexed from 0.
1736 *
1737 * @see llvm::Function::arg_begin()
1738 */
Gordon Henriksen265f7802008-03-19 01:11:35 +00001739LLVMValueRef LLVMGetParam(LLVMValueRef Fn, unsigned Index);
Gregory Szorc34c863a2012-03-21 03:54:29 +00001740
1741/**
1742 * Obtain the function to which this argument belongs.
1743 *
1744 * Unlike other functions in this group, this one takes a LLVMValueRef
1745 * that corresponds to a llvm::Attribute.
1746 *
1747 * The returned LLVMValueRef is the llvm::Function to which this
1748 * argument belongs.
1749 */
Gordon Henriksen265f7802008-03-19 01:11:35 +00001750LLVMValueRef LLVMGetParamParent(LLVMValueRef Inst);
Gregory Szorc34c863a2012-03-21 03:54:29 +00001751
1752/**
1753 * Obtain the first parameter to a function.
1754 *
1755 * @see llvm::Function::arg_begin()
1756 */
Gordon Henriksen07a45f42008-03-23 22:21:29 +00001757LLVMValueRef LLVMGetFirstParam(LLVMValueRef Fn);
Gregory Szorc34c863a2012-03-21 03:54:29 +00001758
1759/**
1760 * Obtain the last parameter to a function.
1761 *
1762 * @see llvm::Function::arg_end()
1763 */
Gordon Henriksen07a45f42008-03-23 22:21:29 +00001764LLVMValueRef LLVMGetLastParam(LLVMValueRef Fn);
Gregory Szorc34c863a2012-03-21 03:54:29 +00001765
1766/**
1767 * Obtain the next parameter to a function.
1768 *
1769 * This takes a LLVMValueRef obtained from LLVMGetFirstParam() (which is
1770 * actually a wrapped iterator) and obtains the next parameter from the
1771 * underlying iterator.
1772 */
Gordon Henriksen07a45f42008-03-23 22:21:29 +00001773LLVMValueRef LLVMGetNextParam(LLVMValueRef Arg);
Gregory Szorc34c863a2012-03-21 03:54:29 +00001774
1775/**
1776 * Obtain the previous parameter to a function.
1777 *
1778 * This is the opposite of LLVMGetNextParam().
1779 */
Gordon Henriksen07a45f42008-03-23 22:21:29 +00001780LLVMValueRef LLVMGetPreviousParam(LLVMValueRef Arg);
Gregory Szorc34c863a2012-03-21 03:54:29 +00001781
1782/**
1783 * Add an attribute to a function argument.
1784 *
1785 * @see llvm::Argument::addAttr()
1786 */
Devang Patel4c758ea2008-09-25 21:00:45 +00001787void LLVMAddAttribute(LLVMValueRef Arg, LLVMAttribute PA);
Gregory Szorc34c863a2012-03-21 03:54:29 +00001788
1789/**
1790 * Remove an attribute from a function argument.
1791 *
1792 * @see llvm::Argument::removeAttr()
1793 */
Devang Patel4c758ea2008-09-25 21:00:45 +00001794void LLVMRemoveAttribute(LLVMValueRef Arg, LLVMAttribute PA);
Gregory Szorc34c863a2012-03-21 03:54:29 +00001795
1796/**
1797 * Get an attribute from a function argument.
1798 */
Chris Lattner40cf28d2009-10-12 04:01:02 +00001799LLVMAttribute LLVMGetAttribute(LLVMValueRef Arg);
Gregory Szorc34c863a2012-03-21 03:54:29 +00001800
1801/**
1802 * Set the alignment for a function parameter.
1803 *
1804 * @see llvm::Argument::addAttr()
1805 * @see llvm::Attribute::constructAlignmentFromInt()
1806 */
Gordon Henriksen2d9cc212008-04-28 17:37:06 +00001807void LLVMSetParamAlignment(LLVMValueRef Arg, unsigned align);
Gordon Henriksen265f7802008-03-19 01:11:35 +00001808
Gregory Szorc34c863a2012-03-21 03:54:29 +00001809/**
1810 * @}
1811 */
1812
1813/**
1814 * @}
1815 */
1816
1817/**
Gregory Szorc52d26602012-03-21 07:28:27 +00001818 * @}
1819 */
1820
1821/**
1822 * @}
1823 */
1824
1825/**
1826 * @defgroup LLVMCCoreValueMetadata Metadata
1827 *
1828 * @{
1829 */
1830
1831/**
1832 * Obtain a MDString value from a context.
1833 *
1834 * The returned instance corresponds to the llvm::MDString class.
1835 *
1836 * The instance is specified by string data of a specified length. The
1837 * string content is copied, so the backing memory can be freed after
1838 * this function returns.
1839 */
1840LLVMValueRef LLVMMDStringInContext(LLVMContextRef C, const char *Str,
1841 unsigned SLen);
1842
1843/**
1844 * Obtain a MDString value from the global context.
1845 */
1846LLVMValueRef LLVMMDString(const char *Str, unsigned SLen);
1847
1848/**
1849 * Obtain a MDNode value from a context.
1850 *
1851 * The returned value corresponds to the llvm::MDNode class.
1852 */
1853LLVMValueRef LLVMMDNodeInContext(LLVMContextRef C, LLVMValueRef *Vals,
1854 unsigned Count);
1855
1856/**
1857 * Obtain a MDNode value from the global context.
1858 */
1859LLVMValueRef LLVMMDNode(LLVMValueRef *Vals, unsigned Count);
1860
1861/**
1862 * Obtain the underlying string from a MDString value.
1863 *
1864 * @param V Instance to obtain string from.
1865 * @param Len Memory address which will hold length of returned string.
1866 * @return String data in MDString.
1867 */
1868const char *LLVMGetMDString(LLVMValueRef V, unsigned* Len);
1869
1870/**
1871 * @}
1872 */
1873
1874/**
Gregory Szorc34c863a2012-03-21 03:54:29 +00001875 * @defgroup LLVMCCoreValueBasicBlock Basic Block
1876 *
1877 * A basic block represents a single entry single exit section of code.
1878 * Basic blocks contain a list of instructions which form the body of
1879 * the block.
1880 *
1881 * Basic blocks belong to functions. They have the type of label.
1882 *
1883 * Basic blocks are themselves values. However, the C API models them as
1884 * LLVMBasicBlockRef.
1885 *
1886 * @see llvm::BasicBlock
1887 *
1888 * @{
1889 */
1890
1891/**
1892 * Convert a basic block instance to a value type.
1893 */
Gordon Henriksen07a45f42008-03-23 22:21:29 +00001894LLVMValueRef LLVMBasicBlockAsValue(LLVMBasicBlockRef BB);
Gregory Szorc34c863a2012-03-21 03:54:29 +00001895
1896/**
1897 * Determine whether a LLVMValueRef is itself a basic block.
1898 */
Chris Lattner25963c62010-01-09 22:27:07 +00001899LLVMBool LLVMValueIsBasicBlock(LLVMValueRef Val);
Gregory Szorc34c863a2012-03-21 03:54:29 +00001900
1901/**
1902 * Convert a LLVMValueRef to a LLVMBasicBlockRef instance.
1903 */
Gordon Henriksenc23b66c2007-09-26 20:56:12 +00001904LLVMBasicBlockRef LLVMValueAsBasicBlock(LLVMValueRef Val);
Gregory Szorc34c863a2012-03-21 03:54:29 +00001905
1906/**
1907 * Obtain the function to which a basic block belongs.
1908 *
1909 * @see llvm::BasicBlock::getParent()
1910 */
Gordon Henriksen07a45f42008-03-23 22:21:29 +00001911LLVMValueRef LLVMGetBasicBlockParent(LLVMBasicBlockRef BB);
Gregory Szorc34c863a2012-03-21 03:54:29 +00001912
1913/**
1914 * Obtain the terminator instruction for a basic block.
1915 *
1916 * If the basic block does not have a terminator (it is not well-formed
1917 * if it doesn't), then NULL is returned.
1918 *
1919 * The returned LLVMValueRef corresponds to a llvm::TerminatorInst.
1920 *
1921 * @see llvm::BasicBlock::getTerminator()
1922 */
Nate Begeman43c322b2011-08-23 20:27:46 +00001923LLVMValueRef LLVMGetBasicBlockTerminator(LLVMBasicBlockRef BB);
Gregory Szorc34c863a2012-03-21 03:54:29 +00001924
1925/**
1926 * Obtain the number of basic blocks in a function.
1927 *
1928 * @param Fn Function value to operate on.
1929 */
Gordon Henriksenc23b66c2007-09-26 20:56:12 +00001930unsigned LLVMCountBasicBlocks(LLVMValueRef Fn);
Gregory Szorc34c863a2012-03-21 03:54:29 +00001931
1932/**
1933 * Obtain all of the basic blocks in a function.
1934 *
1935 * This operates on a function value. The BasicBlocks parameter is a
1936 * pointer to a pre-allocated array of LLVMBasicBlockRef of at least
1937 * LLVMCountBasicBlocks() in length. This array is populated with
1938 * LLVMBasicBlockRef instances.
1939 */
Gordon Henriksenc23b66c2007-09-26 20:56:12 +00001940void LLVMGetBasicBlocks(LLVMValueRef Fn, LLVMBasicBlockRef *BasicBlocks);
Gregory Szorc34c863a2012-03-21 03:54:29 +00001941
1942/**
1943 * Obtain the first basic block in a function.
1944 *
1945 * The returned basic block can be used as an iterator. You will likely
1946 * eventually call into LLVMGetNextBasicBlock() with it.
1947 *
1948 * @see llvm::Function::begin()
1949 */
Gordon Henriksen054817c2008-03-19 03:47:18 +00001950LLVMBasicBlockRef LLVMGetFirstBasicBlock(LLVMValueRef Fn);
Gregory Szorc34c863a2012-03-21 03:54:29 +00001951
1952/**
1953 * Obtain the last basic block in a function.
1954 *
1955 * @see llvm::Function::end()
1956 */
Gordon Henriksen054817c2008-03-19 03:47:18 +00001957LLVMBasicBlockRef LLVMGetLastBasicBlock(LLVMValueRef Fn);
Gregory Szorc34c863a2012-03-21 03:54:29 +00001958
1959/**
1960 * Advance a basic block iterator.
1961 */
Gordon Henriksen054817c2008-03-19 03:47:18 +00001962LLVMBasicBlockRef LLVMGetNextBasicBlock(LLVMBasicBlockRef BB);
Gregory Szorc34c863a2012-03-21 03:54:29 +00001963
1964/**
1965 * Go backwards in a basic block iterator.
1966 */
Gordon Henriksen054817c2008-03-19 03:47:18 +00001967LLVMBasicBlockRef LLVMGetPreviousBasicBlock(LLVMBasicBlockRef BB);
Gregory Szorc34c863a2012-03-21 03:54:29 +00001968
1969/**
1970 * Obtain the basic block that corresponds to the entry point of a
1971 * function.
1972 *
1973 * @see llvm::Function::getEntryBlock()
1974 */
Gordon Henriksenc23b66c2007-09-26 20:56:12 +00001975LLVMBasicBlockRef LLVMGetEntryBasicBlock(LLVMValueRef Fn);
Erick Tryzelaar262332f2009-08-14 00:01:31 +00001976
Gregory Szorc34c863a2012-03-21 03:54:29 +00001977/**
1978 * Append a basic block to the end of a function.
1979 *
1980 * @see llvm::BasicBlock::Create()
1981 */
Erick Tryzelaar262332f2009-08-14 00:01:31 +00001982LLVMBasicBlockRef LLVMAppendBasicBlockInContext(LLVMContextRef C,
1983 LLVMValueRef Fn,
1984 const char *Name);
Gregory Szorc34c863a2012-03-21 03:54:29 +00001985
1986/**
1987 * Append a basic block to the end of a function using the global
1988 * context.
1989 *
1990 * @see llvm::BasicBlock::Create()
1991 */
1992LLVMBasicBlockRef LLVMAppendBasicBlock(LLVMValueRef Fn, const char *Name);
1993
1994/**
1995 * Insert a basic block in a function before another basic block.
1996 *
1997 * The function to add to is determined by the function of the
1998 * passed basic block.
1999 *
2000 * @see llvm::BasicBlock::Create()
2001 */
Erick Tryzelaar262332f2009-08-14 00:01:31 +00002002LLVMBasicBlockRef LLVMInsertBasicBlockInContext(LLVMContextRef C,
2003 LLVMBasicBlockRef BB,
2004 const char *Name);
2005
Gregory Szorc34c863a2012-03-21 03:54:29 +00002006/**
2007 * Insert a basic block in a function using the global context.
2008 *
2009 * @see llvm::BasicBlock::Create()
2010 */
Gordon Henriksenc23b66c2007-09-26 20:56:12 +00002011LLVMBasicBlockRef LLVMInsertBasicBlock(LLVMBasicBlockRef InsertBeforeBB,
2012 const char *Name);
Gregory Szorc34c863a2012-03-21 03:54:29 +00002013
2014/**
2015 * Remove a basic block from a function and delete it.
2016 *
2017 * This deletes the basic block from its containing function and deletes
2018 * the basic block itself.
2019 *
2020 * @see llvm::BasicBlock::eraseFromParent()
2021 */
Gordon Henriksenc23b66c2007-09-26 20:56:12 +00002022void LLVMDeleteBasicBlock(LLVMBasicBlockRef BB);
Gregory Szorc34c863a2012-03-21 03:54:29 +00002023
2024/**
2025 * Remove a basic block from a function.
2026 *
2027 * This deletes the basic block from its containing function but keep
2028 * the basic block alive.
2029 *
2030 * @see llvm::BasicBlock::removeFromParent()
2031 */
Nate Begeman43c322b2011-08-23 20:27:46 +00002032void LLVMRemoveBasicBlockFromParent(LLVMBasicBlockRef BB);
Gordon Henriksenc23b66c2007-09-26 20:56:12 +00002033
Gregory Szorc34c863a2012-03-21 03:54:29 +00002034/**
2035 * Move a basic block to before another one.
2036 *
2037 * @see llvm::BasicBlock::moveBefore()
2038 */
Duncan Sandsb1d61aa2010-07-19 15:31:07 +00002039void LLVMMoveBasicBlockBefore(LLVMBasicBlockRef BB, LLVMBasicBlockRef MovePos);
Gregory Szorc34c863a2012-03-21 03:54:29 +00002040
2041/**
2042 * Move a basic block to after another one.
2043 *
2044 * @see llvm::BasicBlock::moveAfter()
2045 */
Duncan Sandsb1d61aa2010-07-19 15:31:07 +00002046void LLVMMoveBasicBlockAfter(LLVMBasicBlockRef BB, LLVMBasicBlockRef MovePos);
2047
Gregory Szorc34c863a2012-03-21 03:54:29 +00002048/**
2049 * Obtain the first instruction in a basic block.
2050 *
2051 * The returned LLVMValueRef corresponds to a llvm::Instruction
2052 * instance.
2053 */
Gordon Henriksen054817c2008-03-19 03:47:18 +00002054LLVMValueRef LLVMGetFirstInstruction(LLVMBasicBlockRef BB);
Gregory Szorc34c863a2012-03-21 03:54:29 +00002055
2056/**
2057 * Obtain the last instruction in a basic block.
2058 *
2059 * The returned LLVMValueRef corresponds to a LLVM:Instruction.
2060 */
Gordon Henriksen054817c2008-03-19 03:47:18 +00002061LLVMValueRef LLVMGetLastInstruction(LLVMBasicBlockRef BB);
Nate Begeman43c322b2011-08-23 20:27:46 +00002062
Gregory Szorc34c863a2012-03-21 03:54:29 +00002063/**
2064 * @}
2065 */
2066
2067/**
2068 * @defgroup LLVMCCoreValueInstruction Instructions
2069 *
2070 * Functions in this group relate to the inspection and manipulation of
2071 * individual instructions.
2072 *
2073 * In the C++ API, an instruction is modeled by llvm::Instruction. This
2074 * class has a large number of descendents. llvm::Instruction is a
2075 * llvm::Value and in the C API, instructions are modeled by
2076 * LLVMValueRef.
2077 *
2078 * This group also contains sub-groups which operate on specific
2079 * llvm::Instruction types, e.g. llvm::CallInst.
2080 *
2081 * @{
2082 */
2083
2084/**
2085 * Determine whether an instruction has any metadata attached.
2086 */
2087int LLVMHasMetadata(LLVMValueRef Val);
2088
2089/**
2090 * Return metadata associated with an instruction value.
2091 */
2092LLVMValueRef LLVMGetMetadata(LLVMValueRef Val, unsigned KindID);
2093
2094/**
2095 * Set metadata associated with an instruction value.
2096 */
2097void LLVMSetMetadata(LLVMValueRef Val, unsigned KindID, LLVMValueRef Node);
2098
2099/**
2100 * Obtain the basic block to which an instruction belongs.
2101 *
2102 * @see llvm::Instruction::getParent()
2103 */
Nate Begeman43c322b2011-08-23 20:27:46 +00002104LLVMBasicBlockRef LLVMGetInstructionParent(LLVMValueRef Inst);
Gregory Szorc34c863a2012-03-21 03:54:29 +00002105
2106/**
2107 * Obtain the instruction that occurs after the one specified.
2108 *
2109 * The next instruction will be from the same basic block.
2110 *
2111 * If this is the last instruction in a basic block, NULL will be
2112 * returned.
2113 */
Gordon Henriksen054817c2008-03-19 03:47:18 +00002114LLVMValueRef LLVMGetNextInstruction(LLVMValueRef Inst);
Gregory Szorc34c863a2012-03-21 03:54:29 +00002115
2116/**
Benjamin Kramerbde91762012-06-02 10:20:22 +00002117 * Obtain the instruction that occurred before this one.
Gregory Szorc34c863a2012-03-21 03:54:29 +00002118 *
2119 * If the instruction is the first instruction in a basic block, NULL
2120 * will be returned.
2121 */
Gordon Henriksen054817c2008-03-19 03:47:18 +00002122LLVMValueRef LLVMGetPreviousInstruction(LLVMValueRef Inst);
Gregory Szorc34c863a2012-03-21 03:54:29 +00002123
2124/**
2125 * Remove and delete an instruction.
2126 *
2127 * The instruction specified is removed from its containing building
2128 * block and then deleted.
2129 *
2130 * @see llvm::Instruction::eraseFromParent()
2131 */
Devang Pateldbebc6f2011-10-03 20:59:18 +00002132void LLVMInstructionEraseFromParent(LLVMValueRef Inst);
Gregory Szorc34c863a2012-03-21 03:54:29 +00002133
2134/**
2135 * Obtain the code opcode for an individual instruction.
2136 *
2137 * @see llvm::Instruction::getOpCode()
2138 */
Torok Edwinab6158e2011-10-14 20:37:49 +00002139LLVMOpcode LLVMGetInstructionOpcode(LLVMValueRef Inst);
Gregory Szorc34c863a2012-03-21 03:54:29 +00002140
2141/**
2142 * Obtain the predicate of an instruction.
2143 *
2144 * This is only valid for instructions that correspond to llvm::ICmpInst
2145 * or llvm::ConstantExpr whose opcode is llvm::Instruction::ICmp.
2146 *
2147 * @see llvm::ICmpInst::getPredicate()
2148 */
Torok Edwin60c40de2011-10-06 12:13:20 +00002149LLVMIntPredicate LLVMGetICmpPredicate(LLVMValueRef Inst);
Gordon Henriksen265f7802008-03-19 01:11:35 +00002150
Gregory Szorc34c863a2012-03-21 03:54:29 +00002151/**
2152 * @defgroup LLVMCCoreValueInstructionCall Call Sites and Invocations
2153 *
2154 * Functions in this group apply to instructions that refer to call
2155 * sites and invocations. These correspond to C++ types in the
2156 * llvm::CallInst class tree.
2157 *
2158 * @{
2159 */
2160
2161/**
2162 * Set the calling convention for a call instruction.
2163 *
2164 * This expects an LLVMValueRef that corresponds to a llvm::CallInst or
2165 * llvm::InvokeInst.
2166 *
2167 * @see llvm::CallInst::setCallingConv()
2168 * @see llvm::InvokeInst::setCallingConv()
2169 */
Gordon Henriksen1158c532007-12-29 20:45:00 +00002170void LLVMSetInstructionCallConv(LLVMValueRef Instr, unsigned CC);
Gregory Szorc34c863a2012-03-21 03:54:29 +00002171
2172/**
2173 * Obtain the calling convention for a call instruction.
2174 *
2175 * This is the opposite of LLVMSetInstructionCallConv(). Reads its
2176 * usage.
2177 *
2178 * @see LLVMSetInstructionCallConv()
2179 */
Gordon Henriksen1158c532007-12-29 20:45:00 +00002180unsigned LLVMGetInstructionCallConv(LLVMValueRef Instr);
Gregory Szorc34c863a2012-03-21 03:54:29 +00002181
2182
Devang Patel4c758ea2008-09-25 21:00:45 +00002183void LLVMAddInstrAttribute(LLVMValueRef Instr, unsigned index, LLVMAttribute);
Gregory Szorc34c863a2012-03-21 03:54:29 +00002184void LLVMRemoveInstrAttribute(LLVMValueRef Instr, unsigned index,
Devang Patel4c758ea2008-09-25 21:00:45 +00002185 LLVMAttribute);
Gregory Szorc34c863a2012-03-21 03:54:29 +00002186void LLVMSetInstrParamAlignment(LLVMValueRef Instr, unsigned index,
Gordon Henriksen2d9cc212008-04-28 17:37:06 +00002187 unsigned align);
Gordon Henriksen1158c532007-12-29 20:45:00 +00002188
Gregory Szorc34c863a2012-03-21 03:54:29 +00002189/**
2190 * Obtain whether a call instruction is a tail call.
2191 *
2192 * This only works on llvm::CallInst instructions.
2193 *
2194 * @see llvm::CallInst::isTailCall()
2195 */
Chris Lattner25963c62010-01-09 22:27:07 +00002196LLVMBool LLVMIsTailCall(LLVMValueRef CallInst);
Gregory Szorc34c863a2012-03-21 03:54:29 +00002197
2198/**
2199 * Set whether a call instruction is a tail call.
2200 *
2201 * This only works on llvm::CallInst instructions.
2202 *
2203 * @see llvm::CallInst::setTailCall()
2204 */
Chris Lattner25963c62010-01-09 22:27:07 +00002205void LLVMSetTailCall(LLVMValueRef CallInst, LLVMBool IsTailCall);
Gordon Henrikseneeb65372008-08-30 16:34:54 +00002206
Gregory Szorc34c863a2012-03-21 03:54:29 +00002207/**
2208 * @}
2209 */
2210
2211/**
2212 * Obtain the default destination basic block of a switch instruction.
2213 *
2214 * This only works on llvm::SwitchInst instructions.
2215 *
2216 * @see llvm::SwitchInst::getDefaultDest()
2217 */
Nate Begeman43c322b2011-08-23 20:27:46 +00002218LLVMBasicBlockRef LLVMGetSwitchDefaultDest(LLVMValueRef SwitchInstr);
2219
Gregory Szorc34c863a2012-03-21 03:54:29 +00002220/**
2221 * @defgroup LLVMCCoreValueInstructionPHINode PHI Nodes
2222 *
2223 * Functions in this group only apply to instructions that map to
2224 * llvm::PHINode instances.
2225 *
2226 * @{
2227 */
2228
2229/**
2230 * Add an incoming value to the end of a PHI list.
2231 */
Gordon Henriksen44dd8fb2007-10-08 18:14:39 +00002232void LLVMAddIncoming(LLVMValueRef PhiNode, LLVMValueRef *IncomingValues,
2233 LLVMBasicBlockRef *IncomingBlocks, unsigned Count);
Gregory Szorc34c863a2012-03-21 03:54:29 +00002234
2235/**
2236 * Obtain the number of incoming basic blocks to a PHI node.
2237 */
Gordon Henriksen44dd8fb2007-10-08 18:14:39 +00002238unsigned LLVMCountIncoming(LLVMValueRef PhiNode);
Gregory Szorc34c863a2012-03-21 03:54:29 +00002239
2240/**
2241 * Obtain an incoming value to a PHI node as a LLVMValueRef.
2242 */
Gordon Henriksen44dd8fb2007-10-08 18:14:39 +00002243LLVMValueRef LLVMGetIncomingValue(LLVMValueRef PhiNode, unsigned Index);
Gregory Szorc34c863a2012-03-21 03:54:29 +00002244
2245/**
2246 * Obtain an incoming value to a PHI node as a LLVMBasicBlockRef.
2247 */
Gordon Henriksen44dd8fb2007-10-08 18:14:39 +00002248LLVMBasicBlockRef LLVMGetIncomingBlock(LLVMValueRef PhiNode, unsigned Index);
Gordon Henriksenc23b66c2007-09-26 20:56:12 +00002249
Gregory Szorc34c863a2012-03-21 03:54:29 +00002250/**
2251 * @}
2252 */
Gordon Henriksenc23b66c2007-09-26 20:56:12 +00002253
Gregory Szorc34c863a2012-03-21 03:54:29 +00002254/**
2255 * @}
2256 */
2257
2258/**
2259 * @}
2260 */
2261
2262/**
2263 * @defgroup LLVMCCoreInstructionBuilder Instruction Builders
2264 *
2265 * An instruction builder represents a point within a basic block and is
2266 * the exclusive means of building instructions using the C interface.
2267 *
2268 * @{
Gordon Henriksenc23b66c2007-09-26 20:56:12 +00002269 */
2270
Erick Tryzelaar262332f2009-08-14 00:01:31 +00002271LLVMBuilderRef LLVMCreateBuilderInContext(LLVMContextRef C);
Gordon Henriksena735a9c2008-05-04 12:55:34 +00002272LLVMBuilderRef LLVMCreateBuilder(void);
Gordon Henriksen054817c2008-03-19 03:47:18 +00002273void LLVMPositionBuilder(LLVMBuilderRef Builder, LLVMBasicBlockRef Block,
2274 LLVMValueRef Instr);
Gordon Henriksenc23b66c2007-09-26 20:56:12 +00002275void LLVMPositionBuilderBefore(LLVMBuilderRef Builder, LLVMValueRef Instr);
2276void LLVMPositionBuilderAtEnd(LLVMBuilderRef Builder, LLVMBasicBlockRef Block);
Gordon Henriksen265f7802008-03-19 01:11:35 +00002277LLVMBasicBlockRef LLVMGetInsertBlock(LLVMBuilderRef Builder);
Chris Lattner3d1f5522008-12-17 21:39:50 +00002278void LLVMClearInsertionPosition(LLVMBuilderRef Builder);
2279void LLVMInsertIntoBuilder(LLVMBuilderRef Builder, LLVMValueRef Instr);
Erick Tryzelaar9813bea2009-08-16 02:20:57 +00002280void LLVMInsertIntoBuilderWithName(LLVMBuilderRef Builder, LLVMValueRef Instr,
2281 const char *Name);
Gordon Henriksenc23b66c2007-09-26 20:56:12 +00002282void LLVMDisposeBuilder(LLVMBuilderRef Builder);
2283
Erick Tryzelaard8531fa2010-02-28 09:45:59 +00002284/* Metadata */
2285void LLVMSetCurrentDebugLocation(LLVMBuilderRef Builder, LLVMValueRef L);
2286LLVMValueRef LLVMGetCurrentDebugLocation(LLVMBuilderRef Builder);
2287void LLVMSetInstDebugLocation(LLVMBuilderRef Builder, LLVMValueRef Inst);
2288
Gordon Henriksenc23b66c2007-09-26 20:56:12 +00002289/* Terminators */
2290LLVMValueRef LLVMBuildRetVoid(LLVMBuilderRef);
2291LLVMValueRef LLVMBuildRet(LLVMBuilderRef, LLVMValueRef V);
Erick Tryzelaarfd529d72009-08-19 08:36:49 +00002292LLVMValueRef LLVMBuildAggregateRet(LLVMBuilderRef, LLVMValueRef *RetVals,
Erick Tryzelaar3045b8b2009-08-16 02:19:59 +00002293 unsigned N);
Gordon Henriksenc23b66c2007-09-26 20:56:12 +00002294LLVMValueRef LLVMBuildBr(LLVMBuilderRef, LLVMBasicBlockRef Dest);
2295LLVMValueRef LLVMBuildCondBr(LLVMBuilderRef, LLVMValueRef If,
2296 LLVMBasicBlockRef Then, LLVMBasicBlockRef Else);
2297LLVMValueRef LLVMBuildSwitch(LLVMBuilderRef, LLVMValueRef V,
2298 LLVMBasicBlockRef Else, unsigned NumCases);
Erick Tryzelaar0fb26ef2010-02-28 09:46:06 +00002299LLVMValueRef LLVMBuildIndirectBr(LLVMBuilderRef B, LLVMValueRef Addr,
2300 unsigned NumDests);
Gordon Henriksenc23b66c2007-09-26 20:56:12 +00002301LLVMValueRef LLVMBuildInvoke(LLVMBuilderRef, LLVMValueRef Fn,
2302 LLVMValueRef *Args, unsigned NumArgs,
2303 LLVMBasicBlockRef Then, LLVMBasicBlockRef Catch,
2304 const char *Name);
Benjamin Kramer5a6568832011-08-19 01:36:54 +00002305LLVMValueRef LLVMBuildLandingPad(LLVMBuilderRef B, LLVMTypeRef Ty,
2306 LLVMValueRef PersFn, unsigned NumClauses,
2307 const char *Name);
Bill Wendlingf891bf82011-07-31 06:30:59 +00002308LLVMValueRef LLVMBuildResume(LLVMBuilderRef B, LLVMValueRef Exn);
Gordon Henriksenc23b66c2007-09-26 20:56:12 +00002309LLVMValueRef LLVMBuildUnreachable(LLVMBuilderRef);
2310
Gordon Henriksen097102c2008-01-01 05:50:53 +00002311/* Add a case to the switch instruction */
2312void LLVMAddCase(LLVMValueRef Switch, LLVMValueRef OnVal,
2313 LLVMBasicBlockRef Dest);
2314
Erick Tryzelaar0fb26ef2010-02-28 09:46:06 +00002315/* Add a destination to the indirectbr instruction */
2316void LLVMAddDestination(LLVMValueRef IndirectBr, LLVMBasicBlockRef Dest);
2317
Bill Wendlingfae14752011-08-12 20:24:12 +00002318/* Add a catch or filter clause to the landingpad instruction */
2319void LLVMAddClause(LLVMValueRef LandingPad, LLVMValueRef ClauseVal);
2320
2321/* Set the 'cleanup' flag in the landingpad instruction */
2322void LLVMSetCleanup(LLVMValueRef LandingPad, LLVMBool Val);
2323
Gordon Henriksenc23b66c2007-09-26 20:56:12 +00002324/* Arithmetic */
2325LLVMValueRef LLVMBuildAdd(LLVMBuilderRef, LLVMValueRef LHS, LLVMValueRef RHS,
2326 const char *Name);
Erick Tryzelaar3045b8b2009-08-16 02:19:59 +00002327LLVMValueRef LLVMBuildNSWAdd(LLVMBuilderRef, LLVMValueRef LHS, LLVMValueRef RHS,
2328 const char *Name);
Erick Tryzelaar4c340c72010-02-28 05:51:43 +00002329LLVMValueRef LLVMBuildNUWAdd(LLVMBuilderRef, LLVMValueRef LHS, LLVMValueRef RHS,
2330 const char *Name);
Erick Tryzelaar3045b8b2009-08-16 02:19:59 +00002331LLVMValueRef LLVMBuildFAdd(LLVMBuilderRef, LLVMValueRef LHS, LLVMValueRef RHS,
2332 const char *Name);
Gordon Henriksenc23b66c2007-09-26 20:56:12 +00002333LLVMValueRef LLVMBuildSub(LLVMBuilderRef, LLVMValueRef LHS, LLVMValueRef RHS,
2334 const char *Name);
Erick Tryzelaar4c340c72010-02-28 05:51:43 +00002335LLVMValueRef LLVMBuildNSWSub(LLVMBuilderRef, LLVMValueRef LHS, LLVMValueRef RHS,
2336 const char *Name);
2337LLVMValueRef LLVMBuildNUWSub(LLVMBuilderRef, LLVMValueRef LHS, LLVMValueRef RHS,
2338 const char *Name);
Erick Tryzelaar3045b8b2009-08-16 02:19:59 +00002339LLVMValueRef LLVMBuildFSub(LLVMBuilderRef, LLVMValueRef LHS, LLVMValueRef RHS,
2340 const char *Name);
Gordon Henriksenc23b66c2007-09-26 20:56:12 +00002341LLVMValueRef LLVMBuildMul(LLVMBuilderRef, LLVMValueRef LHS, LLVMValueRef RHS,
2342 const char *Name);
Erick Tryzelaar4c340c72010-02-28 05:51:43 +00002343LLVMValueRef LLVMBuildNSWMul(LLVMBuilderRef, LLVMValueRef LHS, LLVMValueRef RHS,
2344 const char *Name);
2345LLVMValueRef LLVMBuildNUWMul(LLVMBuilderRef, LLVMValueRef LHS, LLVMValueRef RHS,
2346 const char *Name);
Erick Tryzelaar3045b8b2009-08-16 02:19:59 +00002347LLVMValueRef LLVMBuildFMul(LLVMBuilderRef, LLVMValueRef LHS, LLVMValueRef RHS,
2348 const char *Name);
Gordon Henriksenc23b66c2007-09-26 20:56:12 +00002349LLVMValueRef LLVMBuildUDiv(LLVMBuilderRef, LLVMValueRef LHS, LLVMValueRef RHS,
2350 const char *Name);
2351LLVMValueRef LLVMBuildSDiv(LLVMBuilderRef, LLVMValueRef LHS, LLVMValueRef RHS,
2352 const char *Name);
Erick Tryzelaar3045b8b2009-08-16 02:19:59 +00002353LLVMValueRef LLVMBuildExactSDiv(LLVMBuilderRef, LLVMValueRef LHS, LLVMValueRef RHS,
2354 const char *Name);
Gordon Henriksenc23b66c2007-09-26 20:56:12 +00002355LLVMValueRef LLVMBuildFDiv(LLVMBuilderRef, LLVMValueRef LHS, LLVMValueRef RHS,
2356 const char *Name);
2357LLVMValueRef LLVMBuildURem(LLVMBuilderRef, LLVMValueRef LHS, LLVMValueRef RHS,
2358 const char *Name);
2359LLVMValueRef LLVMBuildSRem(LLVMBuilderRef, LLVMValueRef LHS, LLVMValueRef RHS,
2360 const char *Name);
2361LLVMValueRef LLVMBuildFRem(LLVMBuilderRef, LLVMValueRef LHS, LLVMValueRef RHS,
2362 const char *Name);
2363LLVMValueRef LLVMBuildShl(LLVMBuilderRef, LLVMValueRef LHS, LLVMValueRef RHS,
2364 const char *Name);
2365LLVMValueRef LLVMBuildLShr(LLVMBuilderRef, LLVMValueRef LHS, LLVMValueRef RHS,
2366 const char *Name);
2367LLVMValueRef LLVMBuildAShr(LLVMBuilderRef, LLVMValueRef LHS, LLVMValueRef RHS,
2368 const char *Name);
2369LLVMValueRef LLVMBuildAnd(LLVMBuilderRef, LLVMValueRef LHS, LLVMValueRef RHS,
2370 const char *Name);
2371LLVMValueRef LLVMBuildOr(LLVMBuilderRef, LLVMValueRef LHS, LLVMValueRef RHS,
2372 const char *Name);
2373LLVMValueRef LLVMBuildXor(LLVMBuilderRef, LLVMValueRef LHS, LLVMValueRef RHS,
2374 const char *Name);
Erick Tryzelaar31831792010-02-28 05:51:27 +00002375LLVMValueRef LLVMBuildBinOp(LLVMBuilderRef B, LLVMOpcode Op,
2376 LLVMValueRef LHS, LLVMValueRef RHS,
2377 const char *Name);
Gordon Henriksenc23b66c2007-09-26 20:56:12 +00002378LLVMValueRef LLVMBuildNeg(LLVMBuilderRef, LLVMValueRef V, const char *Name);
Erick Tryzelaar4c340c72010-02-28 05:51:43 +00002379LLVMValueRef LLVMBuildNSWNeg(LLVMBuilderRef B, LLVMValueRef V,
2380 const char *Name);
2381LLVMValueRef LLVMBuildNUWNeg(LLVMBuilderRef B, LLVMValueRef V,
2382 const char *Name);
Dan Gohmanf919bd62009-09-28 21:51:41 +00002383LLVMValueRef LLVMBuildFNeg(LLVMBuilderRef, LLVMValueRef V, const char *Name);
Gordon Henriksenc23b66c2007-09-26 20:56:12 +00002384LLVMValueRef LLVMBuildNot(LLVMBuilderRef, LLVMValueRef V, const char *Name);
2385
2386/* Memory */
2387LLVMValueRef LLVMBuildMalloc(LLVMBuilderRef, LLVMTypeRef Ty, const char *Name);
2388LLVMValueRef LLVMBuildArrayMalloc(LLVMBuilderRef, LLVMTypeRef Ty,
2389 LLVMValueRef Val, const char *Name);
2390LLVMValueRef LLVMBuildAlloca(LLVMBuilderRef, LLVMTypeRef Ty, const char *Name);
2391LLVMValueRef LLVMBuildArrayAlloca(LLVMBuilderRef, LLVMTypeRef Ty,
2392 LLVMValueRef Val, const char *Name);
2393LLVMValueRef LLVMBuildFree(LLVMBuilderRef, LLVMValueRef PointerVal);
2394LLVMValueRef LLVMBuildLoad(LLVMBuilderRef, LLVMValueRef PointerVal,
2395 const char *Name);
2396LLVMValueRef LLVMBuildStore(LLVMBuilderRef, LLVMValueRef Val, LLVMValueRef Ptr);
2397LLVMValueRef LLVMBuildGEP(LLVMBuilderRef B, LLVMValueRef Pointer,
2398 LLVMValueRef *Indices, unsigned NumIndices,
2399 const char *Name);
Erick Tryzelaar3045b8b2009-08-16 02:19:59 +00002400LLVMValueRef LLVMBuildInBoundsGEP(LLVMBuilderRef B, LLVMValueRef Pointer,
2401 LLVMValueRef *Indices, unsigned NumIndices,
2402 const char *Name);
2403LLVMValueRef LLVMBuildStructGEP(LLVMBuilderRef B, LLVMValueRef Pointer,
2404 unsigned Idx, const char *Name);
2405LLVMValueRef LLVMBuildGlobalString(LLVMBuilderRef B, const char *Str,
2406 const char *Name);
2407LLVMValueRef LLVMBuildGlobalStringPtr(LLVMBuilderRef B, const char *Str,
2408 const char *Name);
Chris Lattner2cc6f9d2012-03-22 03:54:15 +00002409LLVMBool LLVMGetVolatile(LLVMValueRef MemoryAccessInst);
2410void LLVMSetVolatile(LLVMValueRef MemoryAccessInst, LLVMBool IsVolatile);
Gordon Henriksenc23b66c2007-09-26 20:56:12 +00002411
2412/* Casts */
2413LLVMValueRef LLVMBuildTrunc(LLVMBuilderRef, LLVMValueRef Val,
2414 LLVMTypeRef DestTy, const char *Name);
2415LLVMValueRef LLVMBuildZExt(LLVMBuilderRef, LLVMValueRef Val,
2416 LLVMTypeRef DestTy, const char *Name);
2417LLVMValueRef LLVMBuildSExt(LLVMBuilderRef, LLVMValueRef Val,
2418 LLVMTypeRef DestTy, const char *Name);
2419LLVMValueRef LLVMBuildFPToUI(LLVMBuilderRef, LLVMValueRef Val,
2420 LLVMTypeRef DestTy, const char *Name);
2421LLVMValueRef LLVMBuildFPToSI(LLVMBuilderRef, LLVMValueRef Val,
2422 LLVMTypeRef DestTy, const char *Name);
2423LLVMValueRef LLVMBuildUIToFP(LLVMBuilderRef, LLVMValueRef Val,
2424 LLVMTypeRef DestTy, const char *Name);
2425LLVMValueRef LLVMBuildSIToFP(LLVMBuilderRef, LLVMValueRef Val,
2426 LLVMTypeRef DestTy, const char *Name);
2427LLVMValueRef LLVMBuildFPTrunc(LLVMBuilderRef, LLVMValueRef Val,
2428 LLVMTypeRef DestTy, const char *Name);
2429LLVMValueRef LLVMBuildFPExt(LLVMBuilderRef, LLVMValueRef Val,
2430 LLVMTypeRef DestTy, const char *Name);
2431LLVMValueRef LLVMBuildPtrToInt(LLVMBuilderRef, LLVMValueRef Val,
2432 LLVMTypeRef DestTy, const char *Name);
2433LLVMValueRef LLVMBuildIntToPtr(LLVMBuilderRef, LLVMValueRef Val,
2434 LLVMTypeRef DestTy, const char *Name);
2435LLVMValueRef LLVMBuildBitCast(LLVMBuilderRef, LLVMValueRef Val,
2436 LLVMTypeRef DestTy, const char *Name);
Erick Tryzelaar3045b8b2009-08-16 02:19:59 +00002437LLVMValueRef LLVMBuildZExtOrBitCast(LLVMBuilderRef, LLVMValueRef Val,
2438 LLVMTypeRef DestTy, const char *Name);
2439LLVMValueRef LLVMBuildSExtOrBitCast(LLVMBuilderRef, LLVMValueRef Val,
2440 LLVMTypeRef DestTy, const char *Name);
2441LLVMValueRef LLVMBuildTruncOrBitCast(LLVMBuilderRef, LLVMValueRef Val,
2442 LLVMTypeRef DestTy, const char *Name);
Erick Tryzelaar31831792010-02-28 05:51:27 +00002443LLVMValueRef LLVMBuildCast(LLVMBuilderRef B, LLVMOpcode Op, LLVMValueRef Val,
2444 LLVMTypeRef DestTy, const char *Name);
Erick Tryzelaar3045b8b2009-08-16 02:19:59 +00002445LLVMValueRef LLVMBuildPointerCast(LLVMBuilderRef, LLVMValueRef Val,
2446 LLVMTypeRef DestTy, const char *Name);
Duncan Sands9d786d72009-11-23 10:49:03 +00002447LLVMValueRef LLVMBuildIntCast(LLVMBuilderRef, LLVMValueRef Val, /*Signed cast!*/
Erick Tryzelaar3045b8b2009-08-16 02:19:59 +00002448 LLVMTypeRef DestTy, const char *Name);
2449LLVMValueRef LLVMBuildFPCast(LLVMBuilderRef, LLVMValueRef Val,
2450 LLVMTypeRef DestTy, const char *Name);
Gordon Henriksenc23b66c2007-09-26 20:56:12 +00002451
2452/* Comparisons */
2453LLVMValueRef LLVMBuildICmp(LLVMBuilderRef, LLVMIntPredicate Op,
2454 LLVMValueRef LHS, LLVMValueRef RHS,
2455 const char *Name);
2456LLVMValueRef LLVMBuildFCmp(LLVMBuilderRef, LLVMRealPredicate Op,
2457 LLVMValueRef LHS, LLVMValueRef RHS,
2458 const char *Name);
2459
2460/* Miscellaneous instructions */
2461LLVMValueRef LLVMBuildPhi(LLVMBuilderRef, LLVMTypeRef Ty, const char *Name);
2462LLVMValueRef LLVMBuildCall(LLVMBuilderRef, LLVMValueRef Fn,
2463 LLVMValueRef *Args, unsigned NumArgs,
2464 const char *Name);
2465LLVMValueRef LLVMBuildSelect(LLVMBuilderRef, LLVMValueRef If,
2466 LLVMValueRef Then, LLVMValueRef Else,
2467 const char *Name);
2468LLVMValueRef LLVMBuildVAArg(LLVMBuilderRef, LLVMValueRef List, LLVMTypeRef Ty,
2469 const char *Name);
2470LLVMValueRef LLVMBuildExtractElement(LLVMBuilderRef, LLVMValueRef VecVal,
2471 LLVMValueRef Index, const char *Name);
2472LLVMValueRef LLVMBuildInsertElement(LLVMBuilderRef, LLVMValueRef VecVal,
2473 LLVMValueRef EltVal, LLVMValueRef Index,
2474 const char *Name);
2475LLVMValueRef LLVMBuildShuffleVector(LLVMBuilderRef, LLVMValueRef V1,
2476 LLVMValueRef V2, LLVMValueRef Mask,
2477 const char *Name);
Dan Gohmand5104a52008-11-03 22:55:43 +00002478LLVMValueRef LLVMBuildExtractValue(LLVMBuilderRef, LLVMValueRef AggVal,
2479 unsigned Index, const char *Name);
2480LLVMValueRef LLVMBuildInsertValue(LLVMBuilderRef, LLVMValueRef AggVal,
2481 LLVMValueRef EltVal, unsigned Index,
2482 const char *Name);
Gordon Henriksen76a03742007-09-18 03:18:57 +00002483
Erick Tryzelaar3045b8b2009-08-16 02:19:59 +00002484LLVMValueRef LLVMBuildIsNull(LLVMBuilderRef, LLVMValueRef Val,
2485 const char *Name);
2486LLVMValueRef LLVMBuildIsNotNull(LLVMBuilderRef, LLVMValueRef Val,
2487 const char *Name);
2488LLVMValueRef LLVMBuildPtrDiff(LLVMBuilderRef, LLVMValueRef LHS,
2489 LLVMValueRef RHS, const char *Name);
2490
Gregory Szorc34c863a2012-03-21 03:54:29 +00002491/**
2492 * @}
2493 */
Gordon Henriksen34eb6d82007-12-19 22:30:40 +00002494
Gregory Szorc34c863a2012-03-21 03:54:29 +00002495/**
2496 * @defgroup LLVMCCoreModuleProvider Module Providers
2497 *
2498 * @{
2499 */
Gordon Henriksen0a68fe22007-12-12 01:04:30 +00002500
Gregory Szorc34c863a2012-03-21 03:54:29 +00002501/**
2502 * Changes the type of M so it can be passed to FunctionPassManagers and the
Jeffrey Yasskin091217b2010-01-27 20:34:15 +00002503 * JIT. They take ModuleProviders for historical reasons.
Gordon Henriksen0a68fe22007-12-12 01:04:30 +00002504 */
2505LLVMModuleProviderRef
2506LLVMCreateModuleProviderForExistingModule(LLVMModuleRef M);
2507
Gregory Szorc34c863a2012-03-21 03:54:29 +00002508/**
2509 * Destroys the module M.
Gordon Henriksen0a68fe22007-12-12 01:04:30 +00002510 */
Jeffrey Yasskin091217b2010-01-27 20:34:15 +00002511void LLVMDisposeModuleProvider(LLVMModuleProviderRef M);
Gordon Henriksen0a68fe22007-12-12 01:04:30 +00002512
Gregory Szorc34c863a2012-03-21 03:54:29 +00002513/**
2514 * @}
2515 */
Gordon Henriksen34eb6d82007-12-19 22:30:40 +00002516
Gregory Szorc34c863a2012-03-21 03:54:29 +00002517/**
2518 * @defgroup LLVMCCoreMemoryBuffers Memory Buffers
2519 *
2520 * @{
2521 */
Gordon Henriksen34eb6d82007-12-19 22:30:40 +00002522
Chris Lattner25963c62010-01-09 22:27:07 +00002523LLVMBool LLVMCreateMemoryBufferWithContentsOfFile(const char *Path,
2524 LLVMMemoryBufferRef *OutMemBuf,
2525 char **OutMessage);
2526LLVMBool LLVMCreateMemoryBufferWithSTDIN(LLVMMemoryBufferRef *OutMemBuf,
2527 char **OutMessage);
Gordon Henriksen34eb6d82007-12-19 22:30:40 +00002528void LLVMDisposeMemoryBuffer(LLVMMemoryBufferRef MemBuf);
2529
Gregory Szorc34c863a2012-03-21 03:54:29 +00002530/**
2531 * @}
2532 */
2533
2534/**
2535 * @defgroup LLVMCCorePassRegistry Pass Registry
2536 *
2537 * @{
2538 */
Owen Anderson4698c5d2010-10-07 17:55:47 +00002539
2540/** Return the global pass registry, for use with initialization functions.
Gregory Szorc34c863a2012-03-21 03:54:29 +00002541 @see llvm::PassRegistry::getPassRegistry */
Owen Anderson4698c5d2010-10-07 17:55:47 +00002542LLVMPassRegistryRef LLVMGetGlobalPassRegistry(void);
Gordon Henriksen878114b2008-03-16 04:20:44 +00002543
Gregory Szorc34c863a2012-03-21 03:54:29 +00002544/**
2545 * @}
2546 */
2547
2548/**
2549 * @defgroup LLVMCCorePassManagers Pass Managers
2550 *
2551 * @{
2552 */
Gordon Henriksen878114b2008-03-16 04:20:44 +00002553
2554/** Constructs a new whole-module pass pipeline. This type of pipeline is
2555 suitable for link-time optimization and whole-module transformations.
Gregory Szorc34c863a2012-03-21 03:54:29 +00002556 @see llvm::PassManager::PassManager */
Gordon Henriksena735a9c2008-05-04 12:55:34 +00002557LLVMPassManagerRef LLVMCreatePassManager(void);
Gordon Henriksen878114b2008-03-16 04:20:44 +00002558
2559/** Constructs a new function-by-function pass pipeline over the module
2560 provider. It does not take ownership of the module provider. This type of
2561 pipeline is suitable for code generation and JIT compilation tasks.
Gregory Szorc34c863a2012-03-21 03:54:29 +00002562 @see llvm::FunctionPassManager::FunctionPassManager */
Erick Tryzelaarad0e0cb2010-03-02 23:58:54 +00002563LLVMPassManagerRef LLVMCreateFunctionPassManagerForModule(LLVMModuleRef M);
2564
2565/** Deprecated: Use LLVMCreateFunctionPassManagerForModule instead. */
Gordon Henriksen878114b2008-03-16 04:20:44 +00002566LLVMPassManagerRef LLVMCreateFunctionPassManager(LLVMModuleProviderRef MP);
2567
2568/** Initializes, executes on the provided module, and finalizes all of the
2569 passes scheduled in the pass manager. Returns 1 if any of the passes
Gregory Szorc34c863a2012-03-21 03:54:29 +00002570 modified the module, 0 otherwise.
2571 @see llvm::PassManager::run(Module&) */
Chris Lattner25963c62010-01-09 22:27:07 +00002572LLVMBool LLVMRunPassManager(LLVMPassManagerRef PM, LLVMModuleRef M);
Gordon Henriksen878114b2008-03-16 04:20:44 +00002573
2574/** Initializes all of the function passes scheduled in the function pass
2575 manager. Returns 1 if any of the passes modified the module, 0 otherwise.
Gregory Szorc34c863a2012-03-21 03:54:29 +00002576 @see llvm::FunctionPassManager::doInitialization */
Chris Lattner25963c62010-01-09 22:27:07 +00002577LLVMBool LLVMInitializeFunctionPassManager(LLVMPassManagerRef FPM);
Gordon Henriksen878114b2008-03-16 04:20:44 +00002578
2579/** Executes all of the function passes scheduled in the function pass manager
2580 on the provided function. Returns 1 if any of the passes modified the
2581 function, false otherwise.
Gregory Szorc34c863a2012-03-21 03:54:29 +00002582 @see llvm::FunctionPassManager::run(Function&) */
Chris Lattner25963c62010-01-09 22:27:07 +00002583LLVMBool LLVMRunFunctionPassManager(LLVMPassManagerRef FPM, LLVMValueRef F);
Gordon Henriksen878114b2008-03-16 04:20:44 +00002584
2585/** Finalizes all of the function passes scheduled in in the function pass
2586 manager. Returns 1 if any of the passes modified the module, 0 otherwise.
Gregory Szorc34c863a2012-03-21 03:54:29 +00002587 @see llvm::FunctionPassManager::doFinalization */
Chris Lattner25963c62010-01-09 22:27:07 +00002588LLVMBool LLVMFinalizeFunctionPassManager(LLVMPassManagerRef FPM);
Gordon Henriksen878114b2008-03-16 04:20:44 +00002589
2590/** Frees the memory of a pass pipeline. For function pipelines, does not free
2591 the module provider.
Gregory Szorc34c863a2012-03-21 03:54:29 +00002592 @see llvm::PassManagerBase::~PassManagerBase. */
Gordon Henriksen878114b2008-03-16 04:20:44 +00002593void LLVMDisposePassManager(LLVMPassManagerRef PM);
2594
Gregory Szorc34c863a2012-03-21 03:54:29 +00002595/**
2596 * @}
2597 */
2598
2599/**
2600 * @}
2601 */
2602
2603/**
2604 * @}
2605 */
Gordon Henriksen878114b2008-03-16 04:20:44 +00002606
Gordon Henriksen76a03742007-09-18 03:18:57 +00002607#ifdef __cplusplus
2608}
Gordon Henriksen76a03742007-09-18 03:18:57 +00002609
Gordon Henriksen7330acd2007-10-05 23:59:36 +00002610namespace llvm {
Gordon Henriksen34eb6d82007-12-19 22:30:40 +00002611 class MemoryBuffer;
Gordon Henriksen96571492008-03-16 15:55:43 +00002612 class PassManagerBase;
Gordon Henriksen0a68fe22007-12-12 01:04:30 +00002613
Gordon Henriksen34eb6d82007-12-19 22:30:40 +00002614 #define DEFINE_SIMPLE_CONVERSION_FUNCTIONS(ty, ref) \
2615 inline ty *unwrap(ref P) { \
2616 return reinterpret_cast<ty*>(P); \
2617 } \
2618 \
2619 inline ref wrap(const ty *P) { \
2620 return reinterpret_cast<ref>(const_cast<ty*>(P)); \
2621 }
Gordon Henriksen7330acd2007-10-05 23:59:36 +00002622
Gordon Henriksen878114b2008-03-16 04:20:44 +00002623 #define DEFINE_ISA_CONVERSION_FUNCTIONS(ty, ref) \
2624 DEFINE_SIMPLE_CONVERSION_FUNCTIONS(ty, ref) \
2625 \
2626 template<typename T> \
2627 inline T *unwrap(ref P) { \
2628 return cast<T>(unwrap(P)); \
2629 }
2630
2631 #define DEFINE_STDCXX_CONVERSION_FUNCTIONS(ty, ref) \
2632 DEFINE_SIMPLE_CONVERSION_FUNCTIONS(ty, ref) \
2633 \
2634 template<typename T> \
2635 inline T *unwrap(ref P) { \
Chris Lattner7ba06612010-01-22 06:49:46 +00002636 T *Q = (T*)unwrap(P); \
Gordon Henriksen878114b2008-03-16 04:20:44 +00002637 assert(Q && "Invalid cast!"); \
2638 return Q; \
2639 }
2640
2641 DEFINE_ISA_CONVERSION_FUNCTIONS (Type, LLVMTypeRef )
2642 DEFINE_ISA_CONVERSION_FUNCTIONS (Value, LLVMValueRef )
Gordon Henriksen823f9732007-12-27 18:25:59 +00002643 DEFINE_SIMPLE_CONVERSION_FUNCTIONS(Module, LLVMModuleRef )
2644 DEFINE_SIMPLE_CONVERSION_FUNCTIONS(BasicBlock, LLVMBasicBlockRef )
Eric Christopher59278832008-08-08 19:39:37 +00002645 DEFINE_SIMPLE_CONVERSION_FUNCTIONS(IRBuilder<>, LLVMBuilderRef )
Gordon Henriksen823f9732007-12-27 18:25:59 +00002646 DEFINE_SIMPLE_CONVERSION_FUNCTIONS(MemoryBuffer, LLVMMemoryBufferRef )
Owen Anderson6773d382009-07-01 16:58:40 +00002647 DEFINE_SIMPLE_CONVERSION_FUNCTIONS(LLVMContext, LLVMContextRef )
Erick Tryzelaar9f9857e2010-03-02 20:32:28 +00002648 DEFINE_SIMPLE_CONVERSION_FUNCTIONS(Use, LLVMUseRef )
Gordon Henriksen878114b2008-03-16 04:20:44 +00002649 DEFINE_STDCXX_CONVERSION_FUNCTIONS(PassManagerBase, LLVMPassManagerRef )
Owen Anderson4698c5d2010-10-07 17:55:47 +00002650 DEFINE_STDCXX_CONVERSION_FUNCTIONS(PassRegistry, LLVMPassRegistryRef )
Jeffrey Yasskin091217b2010-01-27 20:34:15 +00002651 /* LLVMModuleProviderRef exists for historical reasons, but now just holds a
2652 * Module.
2653 */
2654 inline Module *unwrap(LLVMModuleProviderRef MP) {
2655 return reinterpret_cast<Module*>(MP);
2656 }
Gordon Henriksen7330acd2007-10-05 23:59:36 +00002657
Gordon Henriksen878114b2008-03-16 04:20:44 +00002658 #undef DEFINE_STDCXX_CONVERSION_FUNCTIONS
2659 #undef DEFINE_ISA_CONVERSION_FUNCTIONS
Gordon Henriksen34eb6d82007-12-19 22:30:40 +00002660 #undef DEFINE_SIMPLE_CONVERSION_FUNCTIONS
Erick Tryzelaar262332f2009-08-14 00:01:31 +00002661
2662 /* Specialized opaque context conversions.
2663 */
2664 inline LLVMContext **unwrap(LLVMContextRef* Tys) {
2665 return reinterpret_cast<LLVMContext**>(Tys);
2666 }
2667
2668 inline LLVMContextRef *wrap(const LLVMContext **Tys) {
2669 return reinterpret_cast<LLVMContextRef*>(const_cast<LLVMContext**>(Tys));
2670 }
Gordon Henriksen7330acd2007-10-05 23:59:36 +00002671
Gordon Henriksen34eb6d82007-12-19 22:30:40 +00002672 /* Specialized opaque type conversions.
2673 */
Gordon Henriksen7330acd2007-10-05 23:59:36 +00002674 inline Type **unwrap(LLVMTypeRef* Tys) {
2675 return reinterpret_cast<Type**>(Tys);
2676 }
2677
Chris Lattner229907c2011-07-18 04:54:35 +00002678 inline LLVMTypeRef *wrap(Type **Tys) {
Gordon Henriksen7330acd2007-10-05 23:59:36 +00002679 return reinterpret_cast<LLVMTypeRef*>(const_cast<Type**>(Tys));
2680 }
2681
Gordon Henriksen34eb6d82007-12-19 22:30:40 +00002682 /* Specialized opaque value conversions.
Gordon Henriksen7330acd2007-10-05 23:59:36 +00002683 */
Gordon Henriksen7330acd2007-10-05 23:59:36 +00002684 inline Value **unwrap(LLVMValueRef *Vals) {
2685 return reinterpret_cast<Value**>(Vals);
2686 }
2687
2688 template<typename T>
2689 inline T **unwrap(LLVMValueRef *Vals, unsigned Length) {
2690 #if DEBUG
Chris Lattnerb7971152009-07-10 18:28:19 +00002691 for (LLVMValueRef *I = Vals, *E = Vals + Length; I != E; ++I)
Gordon Henriksen7330acd2007-10-05 23:59:36 +00002692 cast<T>(*I);
2693 #endif
Hans Wennborg8f7edbf2011-06-04 16:00:19 +00002694 (void)Length;
Gordon Henriksen7330acd2007-10-05 23:59:36 +00002695 return reinterpret_cast<T**>(Vals);
2696 }
2697
Gordon Henriksen7330acd2007-10-05 23:59:36 +00002698 inline LLVMValueRef *wrap(const Value **Vals) {
2699 return reinterpret_cast<LLVMValueRef*>(const_cast<Value**>(Vals));
2700 }
Gordon Henriksen7330acd2007-10-05 23:59:36 +00002701}
2702
2703#endif /* !defined(__cplusplus) */
2704
2705#endif /* !defined(LLVM_C_CORE_H) */