blob: f3aaab64e818ab15ae68d5cfa2ac142b73599a8b [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. */
285 LLVMWeakAnyLinkage, /**< Keep one copy of function when linking (weak) */
286 LLVMWeakODRLinkage, /**< Same, but only replaced by something
287 equivalent. */
Gordon Henriksen4a4d7352007-12-30 17:46:33 +0000288 LLVMAppendingLinkage, /**< Special purpose, only applies to global arrays */
289 LLVMInternalLinkage, /**< Rename collisions when linking (static
290 functions) */
Duncan Sands12da8ce2009-03-07 15:45:40 +0000291 LLVMPrivateLinkage, /**< Like Internal, but omit from symbol table */
Gordon Henriksen4a4d7352007-12-30 17:46:33 +0000292 LLVMDLLImportLinkage, /**< Function to be imported from DLL */
293 LLVMDLLExportLinkage, /**< Function to be accessible from DLL */
Duncan Sandse2881052009-03-11 08:08:06 +0000294 LLVMExternalWeakLinkage,/**< ExternalWeak linkage description */
Jeffrey Yasskin091217b2010-01-27 20:34:15 +0000295 LLVMGhostLinkage, /**< Obsolete */
Bill Wendling002b1672009-07-20 18:22:52 +0000296 LLVMCommonLinkage, /**< Tentative definitions */
Bill Wendling03bcd6e2010-07-01 21:55:59 +0000297 LLVMLinkerPrivateLinkage, /**< Like Private, but linker removes. */
Bill Wendling578ee402010-08-20 22:05:50 +0000298 LLVMLinkerPrivateWeakLinkage, /**< Like LinkerPrivate, but is weak. */
299 LLVMLinkerPrivateWeakDefAutoLinkage /**< Like LinkerPrivateWeak, but possibly
300 hidden. */
Gordon Henriksen76a03742007-09-18 03:18:57 +0000301} LLVMLinkage;
302
303typedef enum {
Gordon Henriksen4a4d7352007-12-30 17:46:33 +0000304 LLVMDefaultVisibility, /**< The GV is visible */
305 LLVMHiddenVisibility, /**< The GV is hidden */
306 LLVMProtectedVisibility /**< The GV is protected */
Gordon Henriksen76a03742007-09-18 03:18:57 +0000307} LLVMVisibility;
308
Gordon Henriksenc23b66c2007-09-26 20:56:12 +0000309typedef enum {
310 LLVMCCallConv = 0,
311 LLVMFastCallConv = 8,
312 LLVMColdCallConv = 9,
313 LLVMX86StdcallCallConv = 64,
314 LLVMX86FastcallCallConv = 65
315} LLVMCallConv;
316
317typedef enum {
Gordon Henriksen4a4d7352007-12-30 17:46:33 +0000318 LLVMIntEQ = 32, /**< equal */
319 LLVMIntNE, /**< not equal */
320 LLVMIntUGT, /**< unsigned greater than */
321 LLVMIntUGE, /**< unsigned greater or equal */
322 LLVMIntULT, /**< unsigned less than */
323 LLVMIntULE, /**< unsigned less or equal */
324 LLVMIntSGT, /**< signed greater than */
325 LLVMIntSGE, /**< signed greater or equal */
326 LLVMIntSLT, /**< signed less than */
327 LLVMIntSLE /**< signed less or equal */
Gordon Henriksenc23b66c2007-09-26 20:56:12 +0000328} LLVMIntPredicate;
329
330typedef enum {
Gordon Henriksen4a4d7352007-12-30 17:46:33 +0000331 LLVMRealPredicateFalse, /**< Always false (always folded) */
332 LLVMRealOEQ, /**< True if ordered and equal */
333 LLVMRealOGT, /**< True if ordered and greater than */
334 LLVMRealOGE, /**< True if ordered and greater than or equal */
335 LLVMRealOLT, /**< True if ordered and less than */
336 LLVMRealOLE, /**< True if ordered and less than or equal */
337 LLVMRealONE, /**< True if ordered and operands are unequal */
338 LLVMRealORD, /**< True if ordered (no nans) */
339 LLVMRealUNO, /**< True if unordered: isnan(X) | isnan(Y) */
340 LLVMRealUEQ, /**< True if unordered or equal */
341 LLVMRealUGT, /**< True if unordered or greater than */
342 LLVMRealUGE, /**< True if unordered, greater than, or equal */
343 LLVMRealULT, /**< True if unordered or less than */
344 LLVMRealULE, /**< True if unordered, less than, or equal */
345 LLVMRealUNE, /**< True if unordered or not equal */
346 LLVMRealPredicateTrue /**< Always true (always folded) */
Gordon Henriksenc23b66c2007-09-26 20:56:12 +0000347} LLVMRealPredicate;
348
Bill Wendlingfae14752011-08-12 20:24:12 +0000349typedef enum {
350 LLVMLandingPadCatch, /**< A catch clause */
351 LLVMLandingPadFilter /**< A filter clause */
352} LLVMLandingPadClauseTy;
353
Gregory Szorc34c863a2012-03-21 03:54:29 +0000354/**
355 * @}
356 */
357
Nick Lewycky0db26542011-05-15 07:20:34 +0000358void LLVMInitializeCore(LLVMPassRegistryRef R);
359
Gordon Henriksen76a03742007-09-18 03:18:57 +0000360
Gordon Henriksen34eb6d82007-12-19 22:30:40 +0000361/*===-- Error handling ----------------------------------------------------===*/
362
363void LLVMDisposeMessage(char *Message);
364
365
Gregory Szorc34c863a2012-03-21 03:54:29 +0000366/**
367 * @defgroup LLVMCCoreContext Contexts
368 *
369 * Contexts are execution states for the core LLVM IR system.
370 *
371 * Most types are tied to a context instance. Multiple contexts can
372 * exist simultaneously. A single context is not thread safe. However,
373 * different contexts can execute on different threads simultaneously.
374 *
375 * @{
376 */
Gordon Henriksen76a03742007-09-18 03:18:57 +0000377
Gregory Szorc34c863a2012-03-21 03:54:29 +0000378/**
379 * Create a new context.
380 *
381 * Every call to this function should be paired with a call to
382 * LLVMContextDispose() or the context will leak memory.
383 */
Erick Tryzelaarf34cb0c2009-08-30 23:38:06 +0000384LLVMContextRef LLVMContextCreate(void);
Gregory Szorc34c863a2012-03-21 03:54:29 +0000385
386/**
387 * Obtain the global context instance.
388 */
Erick Tryzelaarf34cb0c2009-08-30 23:38:06 +0000389LLVMContextRef LLVMGetGlobalContext(void);
Gregory Szorc34c863a2012-03-21 03:54:29 +0000390
391/**
392 * Destroy a context instance.
393 *
394 * This should be called for every call to LLVMContextCreate() or memory
395 * will be leaked.
396 */
Owen Anderson6773d382009-07-01 16:58:40 +0000397void LLVMContextDispose(LLVMContextRef C);
398
Erick Tryzelaard8531fa2010-02-28 09:45:59 +0000399unsigned LLVMGetMDKindIDInContext(LLVMContextRef C, const char* Name,
400 unsigned SLen);
401unsigned LLVMGetMDKindID(const char* Name, unsigned SLen);
402
Gregory Szorc34c863a2012-03-21 03:54:29 +0000403/**
404 * @}
405 */
406
Gregory Szorc52d26602012-03-21 07:28:27 +0000407/**
408 * @defgroup LLVMCCoreModule Modules
Gregory Szorc34c863a2012-03-21 03:54:29 +0000409 *
410 * Modules represent the top-level structure in a LLVM program. An LLVM
411 * module is effectively a translation unit or a collection of
412 * translation units merged together.
413 *
414 * @{
415 */
416
Gregory Szorc34c863a2012-03-21 03:54:29 +0000417/**
418 * Create a new, empty module in the global context.
419 *
420 * This is equivalent to calling LLVMModuleCreateWithNameInContext with
421 * LLVMGetGlobalContext() as the context parameter.
422 *
423 * Every invocation should be paired with LLVMDisposeModule() or memory
424 * will be leaked.
425 */
Gordon Henriksen76a03742007-09-18 03:18:57 +0000426LLVMModuleRef LLVMModuleCreateWithName(const char *ModuleID);
Gregory Szorc34c863a2012-03-21 03:54:29 +0000427
428/**
429 * Create a new, empty module in a specific context.
430 *
431 * Every invocation should be paired with LLVMDisposeModule() or memory
432 * will be leaked.
433 */
Owen Anderson31d44e42009-07-02 07:17:57 +0000434LLVMModuleRef LLVMModuleCreateWithNameInContext(const char *ModuleID,
435 LLVMContextRef C);
Gordon Henriksena49d4352008-03-07 19:13:06 +0000436
Gregory Szorc34c863a2012-03-21 03:54:29 +0000437/**
438 * Destroy a module instance.
439 *
440 * This must be called for every created module or memory will be
441 * leaked.
442 */
Gordon Henriksen76a03742007-09-18 03:18:57 +0000443void LLVMDisposeModule(LLVMModuleRef M);
444
Gregory Szorc34c863a2012-03-21 03:54:29 +0000445/**
446 * Obtain the data layout for a module.
447 *
448 * @see Module::getDataLayout()
449 */
Gordon Henriksen05568bb2007-12-27 20:13:47 +0000450const char *LLVMGetDataLayout(LLVMModuleRef M);
Gregory Szorc34c863a2012-03-21 03:54:29 +0000451
452/**
453 * Set the data layout for a module.
454 *
455 * @see Module::setDataLayout()
456 */
Gordon Henriksen05568bb2007-12-27 20:13:47 +0000457void LLVMSetDataLayout(LLVMModuleRef M, const char *Triple);
458
Gregory Szorc34c863a2012-03-21 03:54:29 +0000459/**
460 * Obtain the target triple for a module.
461 *
462 * @see Module::getTargetTriple()
463 */
Gordon Henriksen05568bb2007-12-27 20:13:47 +0000464const char *LLVMGetTarget(LLVMModuleRef M);
Gregory Szorc34c863a2012-03-21 03:54:29 +0000465
466/**
467 * Set the target triple for a module.
468 *
469 * @see Module::setTargetTriple()
470 */
Gordon Henriksen05568bb2007-12-27 20:13:47 +0000471void LLVMSetTarget(LLVMModuleRef M, const char *Triple);
472
Gregory Szorc34c863a2012-03-21 03:54:29 +0000473/**
474 * Dump a representation of a module to stderr.
475 *
476 * @see Module::dump()
477 */
Gordon Henriksen6c6075e2008-03-14 23:58:56 +0000478void LLVMDumpModule(LLVMModuleRef M);
479
Gregory Szorc34c863a2012-03-21 03:54:29 +0000480/**
Hans Wennborgb7ef2fe2012-05-09 16:54:17 +0000481 * Print a representation of a module to a file. The ErrorMessage needs to be
482 * disposed with LLVMDisposeMessage. Returns 0 on success, 1 otherwise.
483 *
484 * @see Module::print()
485 */
486LLVMBool LLVMPrintModuleToFile(LLVMModuleRef M, const char *Filename,
487 char **ErrorMessage);
488
489/**
Gregory Szorc34c863a2012-03-21 03:54:29 +0000490 * Set inline assembly for a module.
491 *
492 * @see Module::setModuleInlineAsm()
493 */
Chris Lattner26941452010-04-10 17:52:58 +0000494void LLVMSetModuleInlineAsm(LLVMModuleRef M, const char *Asm);
Gordon Henriksen76a03742007-09-18 03:18:57 +0000495
Gregory Szorc34c863a2012-03-21 03:54:29 +0000496/**
497 * Obtain the context to which this module is associated.
498 *
499 * @see Module::getContext()
500 */
Chris Lattnera7e04b02010-11-28 20:03:44 +0000501LLVMContextRef LLVMGetModuleContext(LLVMModuleRef M);
502
Gregory Szorc34c863a2012-03-21 03:54:29 +0000503/**
504 * Obtain a Type from a module by its registered name.
505 */
506LLVMTypeRef LLVMGetTypeByName(LLVMModuleRef M, const char *Name);
Gordon Henriksen76a03742007-09-18 03:18:57 +0000507
Gregory Szorc34c863a2012-03-21 03:54:29 +0000508/**
509 * Obtain the number of operands for named metadata in a module.
510 *
511 * @see llvm::Module::getNamedMetadata()
512 */
513unsigned LLVMGetNamedMetadataNumOperands(LLVMModuleRef M, const char* name);
514
515/**
516 * Obtain the named metadata operands for a module.
517 *
518 * The passed LLVMValueRef pointer should refer to an array of
519 * LLVMValueRef at least LLVMGetNamedMetadataNumOperands long. This
520 * array will be populated with the LLVMValueRef instances. Each
521 * instance corresponds to a llvm::MDNode.
522 *
523 * @see llvm::Module::getNamedMetadata()
524 * @see llvm::MDNode::getOperand()
525 */
526void LLVMGetNamedMetadataOperands(LLVMModuleRef M, const char* name, LLVMValueRef *Dest);
527
528/**
529 * Add an operand to named metadata.
530 *
531 * @see llvm::Module::getNamedMetadata()
532 * @see llvm::MDNode::addOperand()
533 */
534void LLVMAddNamedMetadataOperand(LLVMModuleRef M, const char* name,
535 LLVMValueRef Val);
536
Gregory Szorc52d26602012-03-21 07:28:27 +0000537/**
538 * Add a function to a module under a specified name.
539 *
540 * @see llvm::Function::Create()
541 */
542LLVMValueRef LLVMAddFunction(LLVMModuleRef M, const char *Name,
543 LLVMTypeRef FunctionTy);
544
545/**
546 * Obtain a Function value from a Module by its name.
547 *
548 * The returned value corresponds to a llvm::Function value.
549 *
550 * @see llvm::Module::getFunction()
551 */
552LLVMValueRef LLVMGetNamedFunction(LLVMModuleRef M, const char *Name);
553
554/**
555 * Obtain an iterator to the first Function in a Module.
556 *
557 * @see llvm::Module::begin()
558 */
559LLVMValueRef LLVMGetFirstFunction(LLVMModuleRef M);
560
561/**
562 * Obtain an iterator to the last Function in a Module.
563 *
564 * @see llvm::Module::end()
565 */
566LLVMValueRef LLVMGetLastFunction(LLVMModuleRef M);
567
568/**
569 * Advance a Function iterator to the next Function.
570 *
571 * Returns NULL if the iterator was already at the end and there are no more
572 * functions.
573 */
574LLVMValueRef LLVMGetNextFunction(LLVMValueRef Fn);
575
576/**
577 * Decrement a Function iterator to the previous Function.
578 *
579 * Returns NULL if the iterator was already at the beginning and there are
580 * no previous functions.
581 */
582LLVMValueRef LLVMGetPreviousFunction(LLVMValueRef Fn);
Gregory Szorc34c863a2012-03-21 03:54:29 +0000583
584/**
585 * @}
586 */
587
588/**
589 * @defgroup LLVMCCoreType Types
590 *
591 * Types represent the type of a value.
592 *
593 * Types are associated with a context instance. The context internally
594 * deduplicates types so there is only 1 instance of a specific type
595 * alive at a time. In other words, a unique type is shared among all
596 * consumers within a context.
597 *
598 * A Type in the C API corresponds to llvm::Type.
599 *
600 * Types have the following hierarchy:
601 *
Gordon Henriksen76a03742007-09-18 03:18:57 +0000602 * types:
603 * integer type
604 * real type
605 * function type
606 * sequence types:
607 * array type
608 * pointer type
609 * vector type
610 * void type
611 * label type
612 * opaque type
Gregory Szorc34c863a2012-03-21 03:54:29 +0000613 *
614 * @{
Gordon Henriksen76a03742007-09-18 03:18:57 +0000615 */
616
Gregory Szorc34c863a2012-03-21 03:54:29 +0000617/**
618 * Obtain the enumerated type of a Type instance.
619 *
620 * @see llvm::Type:getTypeID()
621 */
Gordon Henriksen76a03742007-09-18 03:18:57 +0000622LLVMTypeKind LLVMGetTypeKind(LLVMTypeRef Ty);
Gregory Szorc34c863a2012-03-21 03:54:29 +0000623
624/**
625 * Whether the type has a known size.
626 *
627 * Things that don't have a size are abstract types, labels, and void.a
628 *
629 * @see llvm::Type::isSized()
630 */
Torok Edwin1cd9ade2011-10-06 12:13:28 +0000631LLVMBool LLVMTypeIsSized(LLVMTypeRef Ty);
Gordon Henriksena49d4352008-03-07 19:13:06 +0000632
Gregory Szorc34c863a2012-03-21 03:54:29 +0000633/**
634 * Obtain the context to which this type instance is associated.
635 *
636 * @see llvm::Type::getContext()
637 */
Erick Tryzelaar262332f2009-08-14 00:01:31 +0000638LLVMContextRef LLVMGetTypeContext(LLVMTypeRef Ty);
639
Gregory Szorc34c863a2012-03-21 03:54:29 +0000640/**
641 * @defgroup LLVMCCoreTypeInt Integer Types
642 *
643 * Functions in this section operate on integer types.
644 *
645 * @{
646 */
647
648/**
649 * Obtain an integer type from a context with specified bit width.
650 */
Erick Tryzelaar262332f2009-08-14 00:01:31 +0000651LLVMTypeRef LLVMInt1TypeInContext(LLVMContextRef C);
652LLVMTypeRef LLVMInt8TypeInContext(LLVMContextRef C);
653LLVMTypeRef LLVMInt16TypeInContext(LLVMContextRef C);
654LLVMTypeRef LLVMInt32TypeInContext(LLVMContextRef C);
655LLVMTypeRef LLVMInt64TypeInContext(LLVMContextRef C);
656LLVMTypeRef LLVMIntTypeInContext(LLVMContextRef C, unsigned NumBits);
657
Gregory Szorc34c863a2012-03-21 03:54:29 +0000658/**
659 * Obtain an integer type from the global context with a specified bit
660 * width.
661 */
Gordon Henriksena735a9c2008-05-04 12:55:34 +0000662LLVMTypeRef LLVMInt1Type(void);
663LLVMTypeRef LLVMInt8Type(void);
664LLVMTypeRef LLVMInt16Type(void);
665LLVMTypeRef LLVMInt32Type(void);
666LLVMTypeRef LLVMInt64Type(void);
Gordon Henriksened7beaa2007-10-06 16:05:20 +0000667LLVMTypeRef LLVMIntType(unsigned NumBits);
Gordon Henriksenc23b66c2007-09-26 20:56:12 +0000668unsigned LLVMGetIntTypeWidth(LLVMTypeRef IntegerTy);
Gordon Henriksen76a03742007-09-18 03:18:57 +0000669
Gregory Szorc34c863a2012-03-21 03:54:29 +0000670/**
671 * @}
672 */
673
674/**
675 * @defgroup LLVMCCoreTypeFloat Floating Point Types
676 *
677 * @{
678 */
679
680/**
681 * Obtain a 16-bit floating point type from a context.
682 */
Dan Gohman518cda42011-12-17 00:04:22 +0000683LLVMTypeRef LLVMHalfTypeInContext(LLVMContextRef C);
Gregory Szorc34c863a2012-03-21 03:54:29 +0000684
685/**
686 * Obtain a 32-bit floating point type from a context.
687 */
Erick Tryzelaar262332f2009-08-14 00:01:31 +0000688LLVMTypeRef LLVMFloatTypeInContext(LLVMContextRef C);
Gregory Szorc34c863a2012-03-21 03:54:29 +0000689
690/**
691 * Obtain a 64-bit floating point type from a context.
692 */
Erick Tryzelaar262332f2009-08-14 00:01:31 +0000693LLVMTypeRef LLVMDoubleTypeInContext(LLVMContextRef C);
Gregory Szorc34c863a2012-03-21 03:54:29 +0000694
695/**
696 * Obtain a 80-bit floating point type (X87) from a context.
697 */
Erick Tryzelaar262332f2009-08-14 00:01:31 +0000698LLVMTypeRef LLVMX86FP80TypeInContext(LLVMContextRef C);
Gregory Szorc34c863a2012-03-21 03:54:29 +0000699
700/**
701 * Obtain a 128-bit floating point type (112-bit mantissa) from a
702 * context.
703 */
Erick Tryzelaar262332f2009-08-14 00:01:31 +0000704LLVMTypeRef LLVMFP128TypeInContext(LLVMContextRef C);
Gregory Szorc34c863a2012-03-21 03:54:29 +0000705
706/**
707 * Obtain a 128-bit floating point type (two 64-bits) from a context.
708 */
Erick Tryzelaar262332f2009-08-14 00:01:31 +0000709LLVMTypeRef LLVMPPCFP128TypeInContext(LLVMContextRef C);
710
Gregory Szorc34c863a2012-03-21 03:54:29 +0000711/**
712 * Obtain a floating point type from the global context.
713 *
714 * These map to the functions in this group of the same name.
715 */
Dan Gohman518cda42011-12-17 00:04:22 +0000716LLVMTypeRef LLVMHalfType(void);
Gordon Henriksena735a9c2008-05-04 12:55:34 +0000717LLVMTypeRef LLVMFloatType(void);
718LLVMTypeRef LLVMDoubleType(void);
719LLVMTypeRef LLVMX86FP80Type(void);
720LLVMTypeRef LLVMFP128Type(void);
721LLVMTypeRef LLVMPPCFP128Type(void);
Gordon Henriksen76a03742007-09-18 03:18:57 +0000722
Gregory Szorc34c863a2012-03-21 03:54:29 +0000723/**
724 * @}
725 */
726
727/**
728 * @defgroup LLVMCCoreTypeFunction Function Types
729 *
730 * @{
731 */
732
733/**
734 * Obtain a function type consisting of a specified signature.
735 *
736 * The function is defined as a tuple of a return Type, a list of
737 * parameter types, and whether the function is variadic.
738 */
Gordon Henriksened7beaa2007-10-06 16:05:20 +0000739LLVMTypeRef LLVMFunctionType(LLVMTypeRef ReturnType,
740 LLVMTypeRef *ParamTypes, unsigned ParamCount,
Chris Lattner25963c62010-01-09 22:27:07 +0000741 LLVMBool IsVarArg);
Gregory Szorc34c863a2012-03-21 03:54:29 +0000742
743/**
744 * Returns whether a function type is variadic.
745 */
Chris Lattner25963c62010-01-09 22:27:07 +0000746LLVMBool LLVMIsFunctionVarArg(LLVMTypeRef FunctionTy);
Gregory Szorc34c863a2012-03-21 03:54:29 +0000747
748/**
749 * Obtain the Type this function Type returns.
750 */
Gordon Henriksenc23b66c2007-09-26 20:56:12 +0000751LLVMTypeRef LLVMGetReturnType(LLVMTypeRef FunctionTy);
Gregory Szorc34c863a2012-03-21 03:54:29 +0000752
753/**
754 * Obtain the number of parameters this function accepts.
755 */
Gordon Henriksenc23b66c2007-09-26 20:56:12 +0000756unsigned LLVMCountParamTypes(LLVMTypeRef FunctionTy);
Gregory Szorc34c863a2012-03-21 03:54:29 +0000757
758/**
759 * Obtain the types of a function's parameters.
760 *
761 * The Dest parameter should point to a pre-allocated array of
762 * LLVMTypeRef at least LLVMCountParamTypes() large. On return, the
763 * first LLVMCountParamTypes() entries in the array will be populated
764 * with LLVMTypeRef instances.
765 *
766 * @param FunctionTy The function type to operate on.
767 * @param Dest Memory address of an array to be filled with result.
768 */
Gordon Henriksenc23b66c2007-09-26 20:56:12 +0000769void LLVMGetParamTypes(LLVMTypeRef FunctionTy, LLVMTypeRef *Dest);
Gordon Henriksen76a03742007-09-18 03:18:57 +0000770
Gregory Szorc34c863a2012-03-21 03:54:29 +0000771/**
772 * @}
773 */
774
775/**
776 * @defgroup LLVMCCoreTypeStruct Structure Types
777 *
778 * These functions relate to LLVMTypeRef instances.
779 *
780 * @see llvm::StructType
781 *
782 * @{
783 */
784
785/**
786 * Create a new structure type in a context.
787 *
788 * A structure is specified by a list of inner elements/types and
789 * whether these can be packed together.
790 *
791 * @see llvm::StructType::create()
792 */
Erick Tryzelaar262332f2009-08-14 00:01:31 +0000793LLVMTypeRef LLVMStructTypeInContext(LLVMContextRef C, LLVMTypeRef *ElementTypes,
Chris Lattner25963c62010-01-09 22:27:07 +0000794 unsigned ElementCount, LLVMBool Packed);
Gregory Szorc34c863a2012-03-21 03:54:29 +0000795
796/**
797 * Create a new structure type in the global context.
798 *
799 * @see llvm::StructType::create()
800 */
Gordon Henriksened7beaa2007-10-06 16:05:20 +0000801LLVMTypeRef LLVMStructType(LLVMTypeRef *ElementTypes, unsigned ElementCount,
Chris Lattner25963c62010-01-09 22:27:07 +0000802 LLVMBool Packed);
Gregory Szorc34c863a2012-03-21 03:54:29 +0000803
804/**
805 * Create an empty structure in a context having a specified name.
806 *
807 * @see llvm::StructType::create()
808 */
Chris Lattnere71ccde2011-07-14 05:53:17 +0000809LLVMTypeRef LLVMStructCreateNamed(LLVMContextRef C, const char *Name);
Gregory Szorc34c863a2012-03-21 03:54:29 +0000810
811/**
812 * Obtain the name of a structure.
813 *
814 * @see llvm::StructType::getName()
815 */
Torok Edwin0d5f6ae2011-10-06 12:12:50 +0000816const char *LLVMGetStructName(LLVMTypeRef Ty);
Gregory Szorc34c863a2012-03-21 03:54:29 +0000817
818/**
819 * Set the contents of a structure type.
820 *
821 * @see llvm::StructType::setBody()
822 */
Chris Lattnere71ccde2011-07-14 05:53:17 +0000823void LLVMStructSetBody(LLVMTypeRef StructTy, LLVMTypeRef *ElementTypes,
824 unsigned ElementCount, LLVMBool Packed);
825
Gregory Szorc34c863a2012-03-21 03:54:29 +0000826/**
827 * Get the number of elements defined inside the structure.
828 *
829 * @see llvm::StructType::getNumElements()
830 */
Gordon Henriksenc23b66c2007-09-26 20:56:12 +0000831unsigned LLVMCountStructElementTypes(LLVMTypeRef StructTy);
Gregory Szorc34c863a2012-03-21 03:54:29 +0000832
833/**
834 * Get the elements within a structure.
835 *
836 * The function is passed the address of a pre-allocated array of
837 * LLVMTypeRef at least LLVMCountStructElementTypes() long. After
838 * invocation, this array will be populated with the structure's
839 * elements. The objects in the destination array will have a lifetime
840 * of the structure type itself, which is the lifetime of the context it
841 * is contained in.
842 */
Gordon Henriksen76a03742007-09-18 03:18:57 +0000843void LLVMGetStructElementTypes(LLVMTypeRef StructTy, LLVMTypeRef *Dest);
Gregory Szorc34c863a2012-03-21 03:54:29 +0000844
845/**
846 * Determine whether a structure is packed.
847 *
848 * @see llvm::StructType::isPacked()
849 */
Chris Lattner25963c62010-01-09 22:27:07 +0000850LLVMBool LLVMIsPackedStruct(LLVMTypeRef StructTy);
Gregory Szorc34c863a2012-03-21 03:54:29 +0000851
852/**
853 * Determine whether a structure is opaque.
854 *
855 * @see llvm::StructType::isOpaque()
856 */
Chris Lattner17cf05b2011-07-14 16:20:28 +0000857LLVMBool LLVMIsOpaqueStruct(LLVMTypeRef StructTy);
858
Gregory Szorc34c863a2012-03-21 03:54:29 +0000859/**
860 * @}
861 */
Gordon Henriksen76a03742007-09-18 03:18:57 +0000862
Gregory Szorc34c863a2012-03-21 03:54:29 +0000863
864/**
865 * @defgroup LLVMCCoreTypeSequential Sequential Types
866 *
867 * Sequential types represents "arrays" of types. This is a super class
868 * for array, vector, and pointer types.
869 *
870 * @{
871 */
872
873/**
874 * Obtain the type of elements within a sequential type.
875 *
876 * This works on array, vector, and pointer types.
877 *
878 * @see llvm::SequentialType::getElementType()
879 */
880LLVMTypeRef LLVMGetElementType(LLVMTypeRef Ty);
881
882/**
883 * Create a fixed size array type that refers to a specific type.
884 *
885 * The created type will exist in the context that its element type
886 * exists in.
887 *
888 * @see llvm::ArrayType::get()
889 */
Gordon Henriksened7beaa2007-10-06 16:05:20 +0000890LLVMTypeRef LLVMArrayType(LLVMTypeRef ElementType, unsigned ElementCount);
Gregory Szorc34c863a2012-03-21 03:54:29 +0000891
892/**
893 * Obtain the length of an array type.
894 *
895 * This only works on types that represent arrays.
896 *
897 * @see llvm::ArrayType::getNumElements()
898 */
899unsigned LLVMGetArrayLength(LLVMTypeRef ArrayTy);
900
901/**
902 * Create a pointer type that points to a defined type.
903 *
904 * The created type will exist in the context that its pointee type
905 * exists in.
906 *
907 * @see llvm::PointerType::get()
908 */
Gordon Henriksen5a3fe032007-12-17 16:08:32 +0000909LLVMTypeRef LLVMPointerType(LLVMTypeRef ElementType, unsigned AddressSpace);
Gregory Szorc34c863a2012-03-21 03:54:29 +0000910
911/**
912 * Obtain the address space of a pointer type.
913 *
914 * This only works on types that represent pointers.
915 *
916 * @see llvm::PointerType::getAddressSpace()
917 */
918unsigned LLVMGetPointerAddressSpace(LLVMTypeRef PointerTy);
919
920/**
921 * Create a vector type that contains a defined type and has a specific
922 * number of elements.
923 *
924 * The created type will exist in the context thats its element type
925 * exists in.
926 *
927 * @see llvm::VectorType::get()
928 */
Gordon Henriksened7beaa2007-10-06 16:05:20 +0000929LLVMTypeRef LLVMVectorType(LLVMTypeRef ElementType, unsigned ElementCount);
Gordon Henriksen76a03742007-09-18 03:18:57 +0000930
Gregory Szorc34c863a2012-03-21 03:54:29 +0000931/**
932 * Obtain the number of elements in a vector type.
933 *
934 * This only works on types that represent vectors.
935 *
936 * @see llvm::VectorType::getNumElements()
937 */
Gordon Henriksen76a03742007-09-18 03:18:57 +0000938unsigned LLVMGetVectorSize(LLVMTypeRef VectorTy);
939
Gregory Szorc34c863a2012-03-21 03:54:29 +0000940/**
941 * @}
942 */
943
944/**
945 * @defgroup LLVMCCoreTypeOther Other Types
946 *
947 * @{
948 */
949
950/**
951 * Create a void type in a context.
952 */
Erick Tryzelaar262332f2009-08-14 00:01:31 +0000953LLVMTypeRef LLVMVoidTypeInContext(LLVMContextRef C);
Gregory Szorc34c863a2012-03-21 03:54:29 +0000954
955/**
956 * Create a label type in a context.
957 */
Erick Tryzelaar262332f2009-08-14 00:01:31 +0000958LLVMTypeRef LLVMLabelTypeInContext(LLVMContextRef C);
Gregory Szorc34c863a2012-03-21 03:54:29 +0000959
960/**
961 * Create a X86 MMX type in a context.
962 */
Dale Johannesen95b67af2010-09-10 21:58:02 +0000963LLVMTypeRef LLVMX86MMXTypeInContext(LLVMContextRef C);
Erick Tryzelaar262332f2009-08-14 00:01:31 +0000964
Gregory Szorc34c863a2012-03-21 03:54:29 +0000965/**
966 * These are similar to the above functions except they operate on the
967 * global context.
968 */
Gordon Henriksena735a9c2008-05-04 12:55:34 +0000969LLVMTypeRef LLVMVoidType(void);
970LLVMTypeRef LLVMLabelType(void);
Dale Johannesen95b67af2010-09-10 21:58:02 +0000971LLVMTypeRef LLVMX86MMXType(void);
Gordon Henriksen76a03742007-09-18 03:18:57 +0000972
Gregory Szorc34c863a2012-03-21 03:54:29 +0000973/**
974 * @}
975 */
Gordon Henriksen76a03742007-09-18 03:18:57 +0000976
Gregory Szorc34c863a2012-03-21 03:54:29 +0000977/**
978 * @}
979 */
980
981/**
982 * @defgroup LLVMCCoreValues Values
983 *
984 * The bulk of LLVM's object model consists of values, which comprise a very
Gordon Henriksen76a03742007-09-18 03:18:57 +0000985 * rich type hierarchy.
Gregory Szorc34c863a2012-03-21 03:54:29 +0000986 *
987 * LLVMValueRef essentially represents llvm::Value. There is a rich
988 * hierarchy of classes within this type. Depending on the instance
989 * obtain, not all APIs are available.
990 *
991 * Callers can determine the type of a LLVMValueRef by calling the
992 * LLVMIsA* family of functions (e.g. LLVMIsAArgument()). These
993 * functions are defined by a macro, so it isn't obvious which are
994 * available by looking at the Doxygen source code. Instead, look at the
995 * source definition of LLVM_FOR_EACH_VALUE_SUBCLASS and note the list
996 * of value names given. These value names also correspond to classes in
997 * the llvm::Value hierarchy.
998 *
999 * @{
Gordon Henriksen76a03742007-09-18 03:18:57 +00001000 */
1001
Gordon Henriksen29e38942008-12-19 18:39:45 +00001002#define LLVM_FOR_EACH_VALUE_SUBCLASS(macro) \
1003 macro(Argument) \
1004 macro(BasicBlock) \
1005 macro(InlineAsm) \
Torok Edwind09b7572011-10-14 20:37:56 +00001006 macro(MDNode) \
1007 macro(MDString) \
Gordon Henriksen29e38942008-12-19 18:39:45 +00001008 macro(User) \
1009 macro(Constant) \
Torok Edwind09b7572011-10-14 20:37:56 +00001010 macro(BlockAddress) \
Gordon Henriksen29e38942008-12-19 18:39:45 +00001011 macro(ConstantAggregateZero) \
1012 macro(ConstantArray) \
1013 macro(ConstantExpr) \
1014 macro(ConstantFP) \
1015 macro(ConstantInt) \
1016 macro(ConstantPointerNull) \
1017 macro(ConstantStruct) \
1018 macro(ConstantVector) \
1019 macro(GlobalValue) \
1020 macro(Function) \
1021 macro(GlobalAlias) \
1022 macro(GlobalVariable) \
1023 macro(UndefValue) \
1024 macro(Instruction) \
1025 macro(BinaryOperator) \
1026 macro(CallInst) \
1027 macro(IntrinsicInst) \
1028 macro(DbgInfoIntrinsic) \
1029 macro(DbgDeclareInst) \
Gordon Henriksen29e38942008-12-19 18:39:45 +00001030 macro(MemIntrinsic) \
1031 macro(MemCpyInst) \
1032 macro(MemMoveInst) \
1033 macro(MemSetInst) \
1034 macro(CmpInst) \
Torok Edwind09b7572011-10-14 20:37:56 +00001035 macro(FCmpInst) \
1036 macro(ICmpInst) \
Gordon Henriksen29e38942008-12-19 18:39:45 +00001037 macro(ExtractElementInst) \
1038 macro(GetElementPtrInst) \
1039 macro(InsertElementInst) \
1040 macro(InsertValueInst) \
Bill Wendlingfae14752011-08-12 20:24:12 +00001041 macro(LandingPadInst) \
Gordon Henriksen29e38942008-12-19 18:39:45 +00001042 macro(PHINode) \
1043 macro(SelectInst) \
1044 macro(ShuffleVectorInst) \
1045 macro(StoreInst) \
1046 macro(TerminatorInst) \
1047 macro(BranchInst) \
Torok Edwind09b7572011-10-14 20:37:56 +00001048 macro(IndirectBrInst) \
Gordon Henriksen29e38942008-12-19 18:39:45 +00001049 macro(InvokeInst) \
1050 macro(ReturnInst) \
1051 macro(SwitchInst) \
1052 macro(UnreachableInst) \
Bill Wendlingf891bf82011-07-31 06:30:59 +00001053 macro(ResumeInst) \
Gordon Henriksen29e38942008-12-19 18:39:45 +00001054 macro(UnaryInstruction) \
Victor Hernandez8acf2952009-10-23 21:09:37 +00001055 macro(AllocaInst) \
Gordon Henriksen29e38942008-12-19 18:39:45 +00001056 macro(CastInst) \
Gordon Henriksen05a868f2008-12-19 18:51:17 +00001057 macro(BitCastInst) \
1058 macro(FPExtInst) \
1059 macro(FPToSIInst) \
1060 macro(FPToUIInst) \
1061 macro(FPTruncInst) \
1062 macro(IntToPtrInst) \
1063 macro(PtrToIntInst) \
1064 macro(SExtInst) \
1065 macro(SIToFPInst) \
1066 macro(TruncInst) \
1067 macro(UIToFPInst) \
1068 macro(ZExtInst) \
1069 macro(ExtractValueInst) \
Gordon Henriksen05a868f2008-12-19 18:51:17 +00001070 macro(LoadInst) \
1071 macro(VAArgInst)
Gordon Henriksen29e38942008-12-19 18:39:45 +00001072
Gregory Szorc34c863a2012-03-21 03:54:29 +00001073/**
1074 * @defgroup LLVMCCoreValueGeneral General APIs
1075 *
1076 * Functions in this section work on all LLVMValueRef instances,
1077 * regardless of their sub-type. They correspond to functions available
1078 * on llvm::Value.
1079 *
1080 * @{
1081 */
Gordon Henriksen76a03742007-09-18 03:18:57 +00001082
Gregory Szorc34c863a2012-03-21 03:54:29 +00001083/**
1084 * Obtain the type of a value.
1085 *
1086 * @see llvm::Value::getType()
1087 */
1088LLVMTypeRef LLVMTypeOf(LLVMValueRef Val);
1089
1090/**
1091 * Obtain the string name of a value.
1092 *
1093 * @see llvm::Value::getName()
1094 */
1095const char *LLVMGetValueName(LLVMValueRef Val);
1096
1097/**
1098 * Set the string name of a value.
1099 *
1100 * @see llvm::Value::setName()
1101 */
1102void LLVMSetValueName(LLVMValueRef Val, const char *Name);
1103
1104/**
1105 * Dump a representation of a value to stderr.
1106 *
1107 * @see llvm::Value::dump()
1108 */
1109void LLVMDumpValue(LLVMValueRef Val);
1110
1111/**
1112 * Replace all uses of a value with another one.
1113 *
1114 * @see llvm::Value::replaceAllUsesWith()
1115 */
1116void LLVMReplaceAllUsesWith(LLVMValueRef OldVal, LLVMValueRef NewVal);
1117
1118/**
1119 * Determine whether the specified constant instance is constant.
1120 */
1121LLVMBool LLVMIsConstant(LLVMValueRef Val);
1122
1123/**
1124 * Determine whether a value instance is undefined.
1125 */
1126LLVMBool LLVMIsUndef(LLVMValueRef Val);
1127
1128/**
1129 * Convert value instances between types.
1130 *
1131 * Internally, a LLVMValueRef is "pinned" to a specific type. This
1132 * series of functions allows you to cast an instance to a specific
1133 * type.
1134 *
1135 * If the cast is not valid for the specified type, NULL is returned.
1136 *
1137 * @see llvm::dyn_cast_or_null<>
1138 */
Gordon Henriksen29e38942008-12-19 18:39:45 +00001139#define LLVM_DECLARE_VALUE_CAST(name) \
1140 LLVMValueRef LLVMIsA##name(LLVMValueRef Val);
1141LLVM_FOR_EACH_VALUE_SUBCLASS(LLVM_DECLARE_VALUE_CAST)
1142
Gregory Szorc34c863a2012-03-21 03:54:29 +00001143/**
1144 * @}
1145 */
1146
1147/**
1148 * @defgroup LLVMCCoreValueUses Usage
1149 *
1150 * This module defines functions that allow you to inspect the uses of a
1151 * LLVMValueRef.
1152 *
1153 * It is possible to obtain a LLVMUseRef for any LLVMValueRef instance.
1154 * Each LLVMUseRef (which corresponds to a llvm::Use instance) holds a
1155 * llvm::User and llvm::Value.
1156 *
1157 * @{
1158 */
1159
1160/**
1161 * Obtain the first use of a value.
1162 *
1163 * Uses are obtained in an iterator fashion. First, call this function
1164 * to obtain a reference to the first use. Then, call LLVMGetNextUse()
1165 * on that instance and all subsequently obtained instances untl
1166 * LLVMGetNextUse() returns NULL.
1167 *
1168 * @see llvm::Value::use_begin()
1169 */
Erick Tryzelaar9f9857e2010-03-02 20:32:28 +00001170LLVMUseRef LLVMGetFirstUse(LLVMValueRef Val);
Gregory Szorc34c863a2012-03-21 03:54:29 +00001171
1172/**
1173 * Obtain the next use of a value.
1174 *
1175 * This effectively advances the iterator. It returns NULL if you are on
1176 * the final use and no more are available.
1177 */
Erick Tryzelaar9f9857e2010-03-02 20:32:28 +00001178LLVMUseRef LLVMGetNextUse(LLVMUseRef U);
Gregory Szorc34c863a2012-03-21 03:54:29 +00001179
1180/**
1181 * Obtain the user value for a user.
1182 *
1183 * The returned value corresponds to a llvm::User type.
1184 *
1185 * @see llvm::Use::getUser()
1186 */
Erick Tryzelaar9f9857e2010-03-02 20:32:28 +00001187LLVMValueRef LLVMGetUser(LLVMUseRef U);
Gregory Szorc34c863a2012-03-21 03:54:29 +00001188
1189/**
1190 * Obtain the value this use corresponds to.
1191 *
1192 * @see llvm::Use::get().
1193 */
Erick Tryzelaar9f9857e2010-03-02 20:32:28 +00001194LLVMValueRef LLVMGetUsedValue(LLVMUseRef U);
Chris Lattner40cf28d2009-10-12 04:01:02 +00001195
Gregory Szorc34c863a2012-03-21 03:54:29 +00001196/**
1197 * @}
1198 */
1199
1200/**
Gregory Szorc52d26602012-03-21 07:28:27 +00001201 * @defgroup LLVMCCoreValueUser User value
Gregory Szorc34c863a2012-03-21 03:54:29 +00001202 *
1203 * Function in this group pertain to LLVMValueRef instances that descent
1204 * from llvm::User. This includes constants, instructions, and
1205 * operators.
1206 *
1207 * @{
1208 */
1209
1210/**
1211 * Obtain an operand at a specific index in a llvm::User value.
1212 *
1213 * @see llvm::User::getOperand()
1214 */
Chris Lattner40cf28d2009-10-12 04:01:02 +00001215LLVMValueRef LLVMGetOperand(LLVMValueRef Val, unsigned Index);
Gregory Szorc34c863a2012-03-21 03:54:29 +00001216
1217/**
1218 * Set an operand at a specific index in a llvm::User value.
1219 *
1220 * @see llvm::User::setOperand()
1221 */
Erick Tryzelaarb4d48702010-08-20 14:51:22 +00001222void LLVMSetOperand(LLVMValueRef User, unsigned Index, LLVMValueRef Val);
Gregory Szorc34c863a2012-03-21 03:54:29 +00001223
1224/**
1225 * Obtain the number of operands in a llvm::User value.
1226 *
1227 * @see llvm::User::getNumOperands()
1228 */
Erick Tryzelaarb4d48702010-08-20 14:51:22 +00001229int LLVMGetNumOperands(LLVMValueRef Val);
Chris Lattner40cf28d2009-10-12 04:01:02 +00001230
Gregory Szorc34c863a2012-03-21 03:54:29 +00001231/**
1232 * @}
1233 */
1234
1235/**
Gregory Szorc52d26602012-03-21 07:28:27 +00001236 * @defgroup LLVMCCoreValueConstant Constants
Gregory Szorc34c863a2012-03-21 03:54:29 +00001237 *
1238 * This section contains APIs for interacting with LLVMValueRef that
1239 * correspond to llvm::Constant instances.
1240 *
1241 * These functions will work for any LLVMValueRef in the llvm::Constant
1242 * class hierarchy.
1243 *
1244 * @{
1245 */
1246
1247/**
1248 * Obtain a constant value referring to the null instance of a type.
1249 *
1250 * @see llvm::Constant::getNullValue()
1251 */
Gordon Henriksen1046c732007-10-06 15:11:06 +00001252LLVMValueRef LLVMConstNull(LLVMTypeRef Ty); /* all zeroes */
Gregory Szorc34c863a2012-03-21 03:54:29 +00001253
1254/**
1255 * Obtain a constant value referring to the instance of a type
1256 * consisting of all ones.
1257 *
1258 * This is only valid for integer types.
1259 *
1260 * @see llvm::Constant::getAllOnesValue()
1261 */
1262LLVMValueRef LLVMConstAllOnes(LLVMTypeRef Ty);
1263
1264/**
1265 * Obtain a constant value referring to an undefined value of a type.
1266 *
1267 * @see llvm::UndefValue::get()
1268 */
Gordon Henriksen76a03742007-09-18 03:18:57 +00001269LLVMValueRef LLVMGetUndef(LLVMTypeRef Ty);
Gregory Szorc34c863a2012-03-21 03:54:29 +00001270
1271/**
1272 * Determine whether a value instance is null.
1273 *
1274 * @see llvm::Constant::isNullValue()
1275 */
Chris Lattner25963c62010-01-09 22:27:07 +00001276LLVMBool LLVMIsNull(LLVMValueRef Val);
Gregory Szorc34c863a2012-03-21 03:54:29 +00001277
1278/**
1279 * Obtain a constant that is a constant pointer pointing to NULL for a
1280 * specified type.
1281 */
Chris Lattner7f318242009-07-06 17:29:59 +00001282LLVMValueRef LLVMConstPointerNull(LLVMTypeRef Ty);
Gordon Henriksen76a03742007-09-18 03:18:57 +00001283
Gregory Szorc34c863a2012-03-21 03:54:29 +00001284/**
1285 * @defgroup LLVMCCoreValueConstantScalar Scalar constants
1286 *
1287 * Functions in this group model LLVMValueRef instances that correspond
1288 * to constants referring to scalar types.
1289 *
1290 * For integer types, the LLVMTypeRef parameter should correspond to a
1291 * llvm::IntegerType instance and the returned LLVMValueRef will
1292 * correspond to a llvm::ConstantInt.
1293 *
1294 * For floating point types, the LLVMTypeRef returned corresponds to a
1295 * llvm::ConstantFP.
1296 *
1297 * @{
1298 */
Erick Tryzelaard8531fa2010-02-28 09:45:59 +00001299
Gregory Szorc34c863a2012-03-21 03:54:29 +00001300/**
1301 * Obtain a constant value for an integer type.
1302 *
1303 * The returned value corresponds to a llvm::ConstantInt.
1304 *
1305 * @see llvm::ConstantInt::get()
1306 *
1307 * @param IntTy Integer type to obtain value of.
1308 * @param N The value the returned instance should refer to.
1309 * @param SignExtend Whether to sign extend the produced value.
1310 */
Gordon Henriksen1046c732007-10-06 15:11:06 +00001311LLVMValueRef LLVMConstInt(LLVMTypeRef IntTy, unsigned long long N,
Chris Lattner25963c62010-01-09 22:27:07 +00001312 LLVMBool SignExtend);
Gregory Szorc34c863a2012-03-21 03:54:29 +00001313
1314/**
1315 * Obtain a constant value for an integer of arbitrary precision.
1316 *
1317 * @see llvm::ConstantInt::get()
1318 */
Chris Lattner4329e072010-11-23 02:47:22 +00001319LLVMValueRef LLVMConstIntOfArbitraryPrecision(LLVMTypeRef IntTy,
1320 unsigned NumWords,
1321 const uint64_t Words[]);
Gregory Szorc34c863a2012-03-21 03:54:29 +00001322
1323/**
1324 * Obtain a constant value for an integer parsed from a string.
1325 *
1326 * A similar API, LLVMConstIntOfStringAndSize is also available. If the
1327 * string's length is available, it is preferred to call that function
1328 * instead.
1329 *
1330 * @see llvm::ConstantInt::get()
1331 */
Erick Tryzelaardd991352009-08-16 23:36:46 +00001332LLVMValueRef LLVMConstIntOfString(LLVMTypeRef IntTy, const char *Text,
1333 uint8_t Radix);
Gregory Szorc34c863a2012-03-21 03:54:29 +00001334
1335/**
1336 * Obtain a constant value for an integer parsed from a string with
1337 * specified length.
1338 *
1339 * @see llvm::ConstantInt::get()
1340 */
Erick Tryzelaardd991352009-08-16 23:36:46 +00001341LLVMValueRef LLVMConstIntOfStringAndSize(LLVMTypeRef IntTy, const char *Text,
1342 unsigned SLen, uint8_t Radix);
Gregory Szorc34c863a2012-03-21 03:54:29 +00001343
1344/**
1345 * Obtain a constant value referring to a double floating point value.
1346 */
Gordon Henriksen1046c732007-10-06 15:11:06 +00001347LLVMValueRef LLVMConstReal(LLVMTypeRef RealTy, double N);
Gregory Szorc34c863a2012-03-21 03:54:29 +00001348
1349/**
1350 * Obtain a constant for a floating point value parsed from a string.
1351 *
1352 * A similar API, LLVMConstRealOfStringAndSize is also available. It
1353 * should be used if the input string's length is known.
1354 */
Gordon Henriksen931e1212008-02-02 01:07:50 +00001355LLVMValueRef LLVMConstRealOfString(LLVMTypeRef RealTy, const char *Text);
Gregory Szorc34c863a2012-03-21 03:54:29 +00001356
1357/**
1358 * Obtain a constant for a floating point value parsed from a string.
1359 */
Erick Tryzelaardd991352009-08-16 23:36:46 +00001360LLVMValueRef LLVMConstRealOfStringAndSize(LLVMTypeRef RealTy, const char *Text,
1361 unsigned SLen);
Gregory Szorc34c863a2012-03-21 03:54:29 +00001362
1363/**
1364 * Obtain the zero extended value for an integer constant value.
1365 *
1366 * @see llvm::ConstantInt::getZExtValue()
1367 */
Chris Lattner40cf28d2009-10-12 04:01:02 +00001368unsigned long long LLVMConstIntGetZExtValue(LLVMValueRef ConstantVal);
Gregory Szorc34c863a2012-03-21 03:54:29 +00001369
1370/**
1371 * Obtain the sign extended value for an integer constant value.
1372 *
1373 * @see llvm::ConstantInt::getSExtValue()
1374 */
Chris Lattner40cf28d2009-10-12 04:01:02 +00001375long long LLVMConstIntGetSExtValue(LLVMValueRef ConstantVal);
Erick Tryzelaardd991352009-08-16 23:36:46 +00001376
Gregory Szorc34c863a2012-03-21 03:54:29 +00001377/**
1378 * @}
1379 */
1380
1381/**
Gregory Szorc52d26602012-03-21 07:28:27 +00001382 * @defgroup LLVMCCoreValueConstantComposite Composite Constants
1383 *
1384 * Functions in this group operate on composite constants.
Gregory Szorc34c863a2012-03-21 03:54:29 +00001385 *
1386 * @{
1387 */
1388
1389/**
Gregory Szorc52d26602012-03-21 07:28:27 +00001390 * Create a ConstantDataSequential and initialize it with a string.
Gregory Szorc34c863a2012-03-21 03:54:29 +00001391 *
Gregory Szorc52d26602012-03-21 07:28:27 +00001392 * @see llvm::ConstantDataArray::getString()
Gregory Szorc34c863a2012-03-21 03:54:29 +00001393 */
Erick Tryzelaar262332f2009-08-14 00:01:31 +00001394LLVMValueRef LLVMConstStringInContext(LLVMContextRef C, const char *Str,
Chris Lattner25963c62010-01-09 22:27:07 +00001395 unsigned Length, LLVMBool DontNullTerminate);
Gregory Szorc52d26602012-03-21 07:28:27 +00001396
1397/**
1398 * Create a ConstantDataSequential with string content in the global context.
1399 *
1400 * This is the same as LLVMConstStringInContext except it operates on the
1401 * global context.
1402 *
1403 * @see LLVMConstStringInContext()
1404 * @see llvm::ConstantDataArray::getString()
1405 */
1406LLVMValueRef LLVMConstString(const char *Str, unsigned Length,
1407 LLVMBool DontNullTerminate);
1408
1409/**
1410 * Create an anonymous ConstantStruct with the specified values.
1411 *
1412 * @see llvm::ConstantStruct::getAnon()
1413 */
1414LLVMValueRef LLVMConstStructInContext(LLVMContextRef C,
Erick Tryzelaar262332f2009-08-14 00:01:31 +00001415 LLVMValueRef *ConstantVals,
Chris Lattner25963c62010-01-09 22:27:07 +00001416 unsigned Count, LLVMBool Packed);
Erick Tryzelaar262332f2009-08-14 00:01:31 +00001417
Gregory Szorc52d26602012-03-21 07:28:27 +00001418/**
1419 * Create a ConstantStruct in the global Context.
1420 *
1421 * This is the same as LLVMConstStructInContext except it operates on the
1422 * global Context.
1423 *
1424 * @see LLVMConstStructInContext()
1425 */
Gordon Henriksen1046c732007-10-06 15:11:06 +00001426LLVMValueRef LLVMConstStruct(LLVMValueRef *ConstantVals, unsigned Count,
Chris Lattner25963c62010-01-09 22:27:07 +00001427 LLVMBool Packed);
Gregory Szorc52d26602012-03-21 07:28:27 +00001428
1429/**
1430 * Create a ConstantArray from values.
1431 *
1432 * @see llvm::ConstantArray::get()
1433 */
1434LLVMValueRef LLVMConstArray(LLVMTypeRef ElementTy,
1435 LLVMValueRef *ConstantVals, unsigned Length);
1436
1437/**
1438 * Create a non-anonymous ConstantStruct from values.
1439 *
1440 * @see llvm::ConstantStruct::get()
1441 */
Rafael Espindola784ad242011-07-14 19:09:08 +00001442LLVMValueRef LLVMConstNamedStruct(LLVMTypeRef StructTy,
1443 LLVMValueRef *ConstantVals,
1444 unsigned Count);
Gregory Szorc52d26602012-03-21 07:28:27 +00001445
1446/**
1447 * Create a ConstantVector from values.
1448 *
1449 * @see llvm::ConstantVector::get()
1450 */
Gordon Henriksen1046c732007-10-06 15:11:06 +00001451LLVMValueRef LLVMConstVector(LLVMValueRef *ScalarConstantVals, unsigned Size);
Gordon Henriksen76a03742007-09-18 03:18:57 +00001452
Gregory Szorc52d26602012-03-21 07:28:27 +00001453/**
1454 * @}
1455 */
1456
1457/**
1458 * @defgroup LLVMCCoreValueConstantExpressions Constant Expressions
1459 *
1460 * Functions in this group correspond to APIs on llvm::ConstantExpr.
1461 *
1462 * @see llvm::ConstantExpr.
1463 *
1464 * @{
1465 */
Chris Lattner40cf28d2009-10-12 04:01:02 +00001466LLVMOpcode LLVMGetConstOpcode(LLVMValueRef ConstantVal);
Erick Tryzelaarfd529d72009-08-19 08:36:49 +00001467LLVMValueRef LLVMAlignOf(LLVMTypeRef Ty);
Gordon Henriksen7ce31762007-10-06 14:29:36 +00001468LLVMValueRef LLVMSizeOf(LLVMTypeRef Ty);
1469LLVMValueRef LLVMConstNeg(LLVMValueRef ConstantVal);
Erick Tryzelaar4c340c72010-02-28 05:51:43 +00001470LLVMValueRef LLVMConstNSWNeg(LLVMValueRef ConstantVal);
1471LLVMValueRef LLVMConstNUWNeg(LLVMValueRef ConstantVal);
Erick Tryzelaar4cc690c2009-08-16 02:20:12 +00001472LLVMValueRef LLVMConstFNeg(LLVMValueRef ConstantVal);
Gordon Henriksen7ce31762007-10-06 14:29:36 +00001473LLVMValueRef LLVMConstNot(LLVMValueRef ConstantVal);
1474LLVMValueRef LLVMConstAdd(LLVMValueRef LHSConstant, LLVMValueRef RHSConstant);
Dan Gohmane4ca02d2009-09-03 23:34:49 +00001475LLVMValueRef LLVMConstNSWAdd(LLVMValueRef LHSConstant, LLVMValueRef RHSConstant);
Erick Tryzelaar4c340c72010-02-28 05:51:43 +00001476LLVMValueRef LLVMConstNUWAdd(LLVMValueRef LHSConstant, LLVMValueRef RHSConstant);
Erick Tryzelaar4cc690c2009-08-16 02:20:12 +00001477LLVMValueRef LLVMConstFAdd(LLVMValueRef LHSConstant, LLVMValueRef RHSConstant);
Gordon Henriksen7ce31762007-10-06 14:29:36 +00001478LLVMValueRef LLVMConstSub(LLVMValueRef LHSConstant, LLVMValueRef RHSConstant);
Erick Tryzelaar4c340c72010-02-28 05:51:43 +00001479LLVMValueRef LLVMConstNSWSub(LLVMValueRef LHSConstant, LLVMValueRef RHSConstant);
1480LLVMValueRef LLVMConstNUWSub(LLVMValueRef LHSConstant, LLVMValueRef RHSConstant);
Erick Tryzelaar4cc690c2009-08-16 02:20:12 +00001481LLVMValueRef LLVMConstFSub(LLVMValueRef LHSConstant, LLVMValueRef RHSConstant);
Gordon Henriksen7ce31762007-10-06 14:29:36 +00001482LLVMValueRef LLVMConstMul(LLVMValueRef LHSConstant, LLVMValueRef RHSConstant);
Erick Tryzelaar4c340c72010-02-28 05:51:43 +00001483LLVMValueRef LLVMConstNSWMul(LLVMValueRef LHSConstant, LLVMValueRef RHSConstant);
1484LLVMValueRef LLVMConstNUWMul(LLVMValueRef LHSConstant, LLVMValueRef RHSConstant);
Erick Tryzelaar4cc690c2009-08-16 02:20:12 +00001485LLVMValueRef LLVMConstFMul(LLVMValueRef LHSConstant, LLVMValueRef RHSConstant);
Gordon Henriksen7ce31762007-10-06 14:29:36 +00001486LLVMValueRef LLVMConstUDiv(LLVMValueRef LHSConstant, LLVMValueRef RHSConstant);
1487LLVMValueRef LLVMConstSDiv(LLVMValueRef LHSConstant, LLVMValueRef RHSConstant);
Dan Gohmane4ca02d2009-09-03 23:34:49 +00001488LLVMValueRef LLVMConstExactSDiv(LLVMValueRef LHSConstant, LLVMValueRef RHSConstant);
Gordon Henriksen7ce31762007-10-06 14:29:36 +00001489LLVMValueRef LLVMConstFDiv(LLVMValueRef LHSConstant, LLVMValueRef RHSConstant);
1490LLVMValueRef LLVMConstURem(LLVMValueRef LHSConstant, LLVMValueRef RHSConstant);
1491LLVMValueRef LLVMConstSRem(LLVMValueRef LHSConstant, LLVMValueRef RHSConstant);
1492LLVMValueRef LLVMConstFRem(LLVMValueRef LHSConstant, LLVMValueRef RHSConstant);
1493LLVMValueRef LLVMConstAnd(LLVMValueRef LHSConstant, LLVMValueRef RHSConstant);
1494LLVMValueRef LLVMConstOr(LLVMValueRef LHSConstant, LLVMValueRef RHSConstant);
1495LLVMValueRef LLVMConstXor(LLVMValueRef LHSConstant, LLVMValueRef RHSConstant);
1496LLVMValueRef LLVMConstICmp(LLVMIntPredicate Predicate,
1497 LLVMValueRef LHSConstant, LLVMValueRef RHSConstant);
1498LLVMValueRef LLVMConstFCmp(LLVMRealPredicate Predicate,
1499 LLVMValueRef LHSConstant, LLVMValueRef RHSConstant);
1500LLVMValueRef LLVMConstShl(LLVMValueRef LHSConstant, LLVMValueRef RHSConstant);
1501LLVMValueRef LLVMConstLShr(LLVMValueRef LHSConstant, LLVMValueRef RHSConstant);
1502LLVMValueRef LLVMConstAShr(LLVMValueRef LHSConstant, LLVMValueRef RHSConstant);
1503LLVMValueRef LLVMConstGEP(LLVMValueRef ConstantVal,
1504 LLVMValueRef *ConstantIndices, unsigned NumIndices);
Dan Gohmane4ca02d2009-09-03 23:34:49 +00001505LLVMValueRef LLVMConstInBoundsGEP(LLVMValueRef ConstantVal,
1506 LLVMValueRef *ConstantIndices,
1507 unsigned NumIndices);
Gordon Henriksen7ce31762007-10-06 14:29:36 +00001508LLVMValueRef LLVMConstTrunc(LLVMValueRef ConstantVal, LLVMTypeRef ToType);
1509LLVMValueRef LLVMConstSExt(LLVMValueRef ConstantVal, LLVMTypeRef ToType);
1510LLVMValueRef LLVMConstZExt(LLVMValueRef ConstantVal, LLVMTypeRef ToType);
1511LLVMValueRef LLVMConstFPTrunc(LLVMValueRef ConstantVal, LLVMTypeRef ToType);
1512LLVMValueRef LLVMConstFPExt(LLVMValueRef ConstantVal, LLVMTypeRef ToType);
1513LLVMValueRef LLVMConstUIToFP(LLVMValueRef ConstantVal, LLVMTypeRef ToType);
1514LLVMValueRef LLVMConstSIToFP(LLVMValueRef ConstantVal, LLVMTypeRef ToType);
1515LLVMValueRef LLVMConstFPToUI(LLVMValueRef ConstantVal, LLVMTypeRef ToType);
1516LLVMValueRef LLVMConstFPToSI(LLVMValueRef ConstantVal, LLVMTypeRef ToType);
1517LLVMValueRef LLVMConstPtrToInt(LLVMValueRef ConstantVal, LLVMTypeRef ToType);
1518LLVMValueRef LLVMConstIntToPtr(LLVMValueRef ConstantVal, LLVMTypeRef ToType);
1519LLVMValueRef LLVMConstBitCast(LLVMValueRef ConstantVal, LLVMTypeRef ToType);
Erick Tryzelaar4cc690c2009-08-16 02:20:12 +00001520LLVMValueRef LLVMConstZExtOrBitCast(LLVMValueRef ConstantVal,
1521 LLVMTypeRef ToType);
1522LLVMValueRef LLVMConstSExtOrBitCast(LLVMValueRef ConstantVal,
1523 LLVMTypeRef ToType);
1524LLVMValueRef LLVMConstTruncOrBitCast(LLVMValueRef ConstantVal,
1525 LLVMTypeRef ToType);
1526LLVMValueRef LLVMConstPointerCast(LLVMValueRef ConstantVal,
1527 LLVMTypeRef ToType);
1528LLVMValueRef LLVMConstIntCast(LLVMValueRef ConstantVal, LLVMTypeRef ToType,
Chris Lattner25963c62010-01-09 22:27:07 +00001529 LLVMBool isSigned);
Erick Tryzelaar4cc690c2009-08-16 02:20:12 +00001530LLVMValueRef LLVMConstFPCast(LLVMValueRef ConstantVal, LLVMTypeRef ToType);
Gordon Henriksen7ce31762007-10-06 14:29:36 +00001531LLVMValueRef LLVMConstSelect(LLVMValueRef ConstantCondition,
1532 LLVMValueRef ConstantIfTrue,
1533 LLVMValueRef ConstantIfFalse);
1534LLVMValueRef LLVMConstExtractElement(LLVMValueRef VectorConstant,
1535 LLVMValueRef IndexConstant);
1536LLVMValueRef LLVMConstInsertElement(LLVMValueRef VectorConstant,
1537 LLVMValueRef ElementValueConstant,
1538 LLVMValueRef IndexConstant);
1539LLVMValueRef LLVMConstShuffleVector(LLVMValueRef VectorAConstant,
1540 LLVMValueRef VectorBConstant,
1541 LLVMValueRef MaskConstant);
Dan Gohmand5104a52008-11-03 22:55:43 +00001542LLVMValueRef LLVMConstExtractValue(LLVMValueRef AggConstant, unsigned *IdxList,
1543 unsigned NumIdx);
1544LLVMValueRef LLVMConstInsertValue(LLVMValueRef AggConstant,
1545 LLVMValueRef ElementValueConstant,
1546 unsigned *IdxList, unsigned NumIdx);
Chris Lattner25963c62010-01-09 22:27:07 +00001547LLVMValueRef LLVMConstInlineAsm(LLVMTypeRef Ty,
Chris Lattner3d1f5522008-12-17 21:39:50 +00001548 const char *AsmString, const char *Constraints,
Chris Lattner25963c62010-01-09 22:27:07 +00001549 LLVMBool HasSideEffects, LLVMBool IsAlignStack);
Erick Tryzelaar0fb26ef2010-02-28 09:46:06 +00001550LLVMValueRef LLVMBlockAddress(LLVMValueRef F, LLVMBasicBlockRef BB);
Gordon Henriksen7ce31762007-10-06 14:29:36 +00001551
Gregory Szorc52d26602012-03-21 07:28:27 +00001552/**
1553 * @}
1554 */
1555
1556/**
1557 * @defgroup LLVMCCoreValueConstantGlobals Global Values
1558 *
1559 * This group contains functions that operate on global values. Functions in
1560 * this group relate to functions in the llvm::GlobalValue class tree.
1561 *
1562 * @see llvm::GlobalValue
1563 *
1564 * @{
1565 */
1566
Gordon Henriksen265f7802008-03-19 01:11:35 +00001567LLVMModuleRef LLVMGetGlobalParent(LLVMValueRef Global);
Chris Lattner25963c62010-01-09 22:27:07 +00001568LLVMBool LLVMIsDeclaration(LLVMValueRef Global);
Gordon Henriksen76a03742007-09-18 03:18:57 +00001569LLVMLinkage LLVMGetLinkage(LLVMValueRef Global);
1570void LLVMSetLinkage(LLVMValueRef Global, LLVMLinkage Linkage);
1571const char *LLVMGetSection(LLVMValueRef Global);
1572void LLVMSetSection(LLVMValueRef Global, const char *Section);
1573LLVMVisibility LLVMGetVisibility(LLVMValueRef Global);
1574void LLVMSetVisibility(LLVMValueRef Global, LLVMVisibility Viz);
1575unsigned LLVMGetAlignment(LLVMValueRef Global);
1576void LLVMSetAlignment(LLVMValueRef Global, unsigned Bytes);
1577
Gregory Szorc52d26602012-03-21 07:28:27 +00001578/**
1579 * @defgroup LLVMCoreValueConstantGlobalVariable Global Variables
1580 *
1581 * This group contains functions that operate on global variable values.
1582 *
1583 * @see llvm::GlobalVariable
1584 *
1585 * @{
1586 */
Gordon Henriksen76a03742007-09-18 03:18:57 +00001587LLVMValueRef LLVMAddGlobal(LLVMModuleRef M, LLVMTypeRef Ty, const char *Name);
Erick Tryzelaar06894b32010-02-28 09:46:13 +00001588LLVMValueRef LLVMAddGlobalInAddressSpace(LLVMModuleRef M, LLVMTypeRef Ty,
1589 const char *Name,
1590 unsigned AddressSpace);
Gordon Henriksen783f7bb2007-10-08 03:45:09 +00001591LLVMValueRef LLVMGetNamedGlobal(LLVMModuleRef M, const char *Name);
Gordon Henriksen07a45f42008-03-23 22:21:29 +00001592LLVMValueRef LLVMGetFirstGlobal(LLVMModuleRef M);
1593LLVMValueRef LLVMGetLastGlobal(LLVMModuleRef M);
1594LLVMValueRef LLVMGetNextGlobal(LLVMValueRef GlobalVar);
1595LLVMValueRef LLVMGetPreviousGlobal(LLVMValueRef GlobalVar);
Gordon Henriksen76a03742007-09-18 03:18:57 +00001596void LLVMDeleteGlobal(LLVMValueRef GlobalVar);
Gordon Henriksen76a03742007-09-18 03:18:57 +00001597LLVMValueRef LLVMGetInitializer(LLVMValueRef GlobalVar);
1598void LLVMSetInitializer(LLVMValueRef GlobalVar, LLVMValueRef ConstantVal);
Chris Lattner25963c62010-01-09 22:27:07 +00001599LLVMBool LLVMIsThreadLocal(LLVMValueRef GlobalVar);
1600void LLVMSetThreadLocal(LLVMValueRef GlobalVar, LLVMBool IsThreadLocal);
1601LLVMBool LLVMIsGlobalConstant(LLVMValueRef GlobalVar);
1602void LLVMSetGlobalConstant(LLVMValueRef GlobalVar, LLVMBool IsConstant);
Gordon Henriksen76a03742007-09-18 03:18:57 +00001603
Gregory Szorc52d26602012-03-21 07:28:27 +00001604/**
1605 * @}
1606 */
1607
1608/**
1609 * @defgroup LLVMCoreValueConstantGlobalAlias Global Aliases
1610 *
1611 * This group contains function that operate on global alias values.
1612 *
1613 * @see llvm::GlobalAlias
1614 *
1615 * @{
1616 */
Chris Lattner3d1f5522008-12-17 21:39:50 +00001617LLVMValueRef LLVMAddAlias(LLVMModuleRef M, LLVMTypeRef Ty, LLVMValueRef Aliasee,
1618 const char *Name);
1619
Gregory Szorc34c863a2012-03-21 03:54:29 +00001620/**
1621 * @}
1622 */
1623
1624/**
1625 * @defgroup LLVMCCoreValueFunction Function values
1626 *
1627 * Functions in this group operate on LLVMValueRef instances that
1628 * correspond to llvm::Function instances.
1629 *
1630 * @see llvm::Function
1631 *
1632 * @{
1633 */
1634
1635/**
1636 * Remove a function from its containing module and deletes it.
1637 *
1638 * @see llvm::Function::eraseFromParent()
1639 */
Gordon Henriksenc23b66c2007-09-26 20:56:12 +00001640void LLVMDeleteFunction(LLVMValueRef Fn);
Gregory Szorc34c863a2012-03-21 03:54:29 +00001641
1642/**
1643 * Obtain the ID number from a function instance.
1644 *
1645 * @see llvm::Function::getIntrinsicID()
1646 */
Gordon Henriksenc23b66c2007-09-26 20:56:12 +00001647unsigned LLVMGetIntrinsicID(LLVMValueRef Fn);
Gregory Szorc34c863a2012-03-21 03:54:29 +00001648
1649/**
1650 * Obtain the calling function of a function.
1651 *
1652 * The returned value corresponds to the LLVMCallConv enumeration.
1653 *
1654 * @see llvm::Function::getCallingConv()
1655 */
Gordon Henriksenc23b66c2007-09-26 20:56:12 +00001656unsigned LLVMGetFunctionCallConv(LLVMValueRef Fn);
Gregory Szorc34c863a2012-03-21 03:54:29 +00001657
1658/**
1659 * Set the calling convention of a function.
1660 *
1661 * @see llvm::Function::setCallingConv()
1662 *
1663 * @param Fn Function to operate on
1664 * @param CC LLVMCallConv to set calling convention to
1665 */
Gordon Henriksenc23b66c2007-09-26 20:56:12 +00001666void LLVMSetFunctionCallConv(LLVMValueRef Fn, unsigned CC);
Gregory Szorc34c863a2012-03-21 03:54:29 +00001667
1668/**
1669 * Obtain the name of the garbage collector to use during code
1670 * generation.
1671 *
1672 * @see llvm::Function::getGC()
1673 */
Gordon Henriksend930f912008-08-17 18:44:35 +00001674const char *LLVMGetGC(LLVMValueRef Fn);
Gregory Szorc34c863a2012-03-21 03:54:29 +00001675
1676/**
1677 * Define the garbage collector to use during code generation.
1678 *
1679 * @see llvm::Function::setGC()
1680 */
Gordon Henriksend930f912008-08-17 18:44:35 +00001681void LLVMSetGC(LLVMValueRef Fn, const char *Name);
Gregory Szorc34c863a2012-03-21 03:54:29 +00001682
1683/**
1684 * Add an attribute to a function.
1685 *
1686 * @see llvm::Function::addAttribute()
1687 */
Duncan Sands7374a012009-05-06 12:21:17 +00001688void LLVMAddFunctionAttr(LLVMValueRef Fn, LLVMAttribute PA);
Gregory Szorc34c863a2012-03-21 03:54:29 +00001689
1690/**
1691 * Obtain an attribute from a function.
1692 *
1693 * @see llvm::Function::getAttributes()
1694 */
Chris Lattner40cf28d2009-10-12 04:01:02 +00001695LLVMAttribute LLVMGetFunctionAttr(LLVMValueRef Fn);
Gregory Szorc34c863a2012-03-21 03:54:29 +00001696
1697/**
1698 * Remove an attribute from a function.
1699 */
Duncan Sands7374a012009-05-06 12:21:17 +00001700void LLVMRemoveFunctionAttr(LLVMValueRef Fn, LLVMAttribute PA);
Gordon Henriksenc23b66c2007-09-26 20:56:12 +00001701
Gregory Szorc34c863a2012-03-21 03:54:29 +00001702/**
1703 * @defgroup LLVMCCoreValueFunctionParameters Function Parameters
1704 *
1705 * Functions in this group relate to arguments/parameters on functions.
1706 *
1707 * Functions in this group expect LLVMValueRef instances that correspond
1708 * to llvm::Function instances.
1709 *
1710 * @{
1711 */
1712
1713/**
1714 * Obtain the number of parameters in a function.
1715 *
1716 * @see llvm::Function::arg_size()
1717 */
Gordon Henriksen265f7802008-03-19 01:11:35 +00001718unsigned LLVMCountParams(LLVMValueRef Fn);
Gregory Szorc34c863a2012-03-21 03:54:29 +00001719
1720/**
1721 * Obtain the parameters in a function.
1722 *
1723 * The takes a pointer to a pre-allocated array of LLVMValueRef that is
1724 * at least LLVMCountParams() long. This array will be filled with
1725 * LLVMValueRef instances which correspond to the parameters the
1726 * function receives. Each LLVMValueRef corresponds to a llvm::Argument
1727 * instance.
1728 *
1729 * @see llvm::Function::arg_begin()
1730 */
Gordon Henriksen265f7802008-03-19 01:11:35 +00001731void LLVMGetParams(LLVMValueRef Fn, LLVMValueRef *Params);
Gregory Szorc34c863a2012-03-21 03:54:29 +00001732
1733/**
1734 * Obtain the parameter at the specified index.
1735 *
1736 * Parameters are indexed from 0.
1737 *
1738 * @see llvm::Function::arg_begin()
1739 */
Gordon Henriksen265f7802008-03-19 01:11:35 +00001740LLVMValueRef LLVMGetParam(LLVMValueRef Fn, unsigned Index);
Gregory Szorc34c863a2012-03-21 03:54:29 +00001741
1742/**
1743 * Obtain the function to which this argument belongs.
1744 *
1745 * Unlike other functions in this group, this one takes a LLVMValueRef
1746 * that corresponds to a llvm::Attribute.
1747 *
1748 * The returned LLVMValueRef is the llvm::Function to which this
1749 * argument belongs.
1750 */
Gordon Henriksen265f7802008-03-19 01:11:35 +00001751LLVMValueRef LLVMGetParamParent(LLVMValueRef Inst);
Gregory Szorc34c863a2012-03-21 03:54:29 +00001752
1753/**
1754 * Obtain the first parameter to a function.
1755 *
1756 * @see llvm::Function::arg_begin()
1757 */
Gordon Henriksen07a45f42008-03-23 22:21:29 +00001758LLVMValueRef LLVMGetFirstParam(LLVMValueRef Fn);
Gregory Szorc34c863a2012-03-21 03:54:29 +00001759
1760/**
1761 * Obtain the last parameter to a function.
1762 *
1763 * @see llvm::Function::arg_end()
1764 */
Gordon Henriksen07a45f42008-03-23 22:21:29 +00001765LLVMValueRef LLVMGetLastParam(LLVMValueRef Fn);
Gregory Szorc34c863a2012-03-21 03:54:29 +00001766
1767/**
1768 * Obtain the next parameter to a function.
1769 *
1770 * This takes a LLVMValueRef obtained from LLVMGetFirstParam() (which is
1771 * actually a wrapped iterator) and obtains the next parameter from the
1772 * underlying iterator.
1773 */
Gordon Henriksen07a45f42008-03-23 22:21:29 +00001774LLVMValueRef LLVMGetNextParam(LLVMValueRef Arg);
Gregory Szorc34c863a2012-03-21 03:54:29 +00001775
1776/**
1777 * Obtain the previous parameter to a function.
1778 *
1779 * This is the opposite of LLVMGetNextParam().
1780 */
Gordon Henriksen07a45f42008-03-23 22:21:29 +00001781LLVMValueRef LLVMGetPreviousParam(LLVMValueRef Arg);
Gregory Szorc34c863a2012-03-21 03:54:29 +00001782
1783/**
1784 * Add an attribute to a function argument.
1785 *
1786 * @see llvm::Argument::addAttr()
1787 */
Devang Patel4c758ea2008-09-25 21:00:45 +00001788void LLVMAddAttribute(LLVMValueRef Arg, LLVMAttribute PA);
Gregory Szorc34c863a2012-03-21 03:54:29 +00001789
1790/**
1791 * Remove an attribute from a function argument.
1792 *
1793 * @see llvm::Argument::removeAttr()
1794 */
Devang Patel4c758ea2008-09-25 21:00:45 +00001795void LLVMRemoveAttribute(LLVMValueRef Arg, LLVMAttribute PA);
Gregory Szorc34c863a2012-03-21 03:54:29 +00001796
1797/**
1798 * Get an attribute from a function argument.
1799 */
Chris Lattner40cf28d2009-10-12 04:01:02 +00001800LLVMAttribute LLVMGetAttribute(LLVMValueRef Arg);
Gregory Szorc34c863a2012-03-21 03:54:29 +00001801
1802/**
1803 * Set the alignment for a function parameter.
1804 *
1805 * @see llvm::Argument::addAttr()
1806 * @see llvm::Attribute::constructAlignmentFromInt()
1807 */
Gordon Henriksen2d9cc212008-04-28 17:37:06 +00001808void LLVMSetParamAlignment(LLVMValueRef Arg, unsigned align);
Gordon Henriksen265f7802008-03-19 01:11:35 +00001809
Gregory Szorc34c863a2012-03-21 03:54:29 +00001810/**
1811 * @}
1812 */
1813
1814/**
1815 * @}
1816 */
1817
1818/**
Gregory Szorc52d26602012-03-21 07:28:27 +00001819 * @}
1820 */
1821
1822/**
1823 * @}
1824 */
1825
1826/**
1827 * @defgroup LLVMCCoreValueMetadata Metadata
1828 *
1829 * @{
1830 */
1831
1832/**
1833 * Obtain a MDString value from a context.
1834 *
1835 * The returned instance corresponds to the llvm::MDString class.
1836 *
1837 * The instance is specified by string data of a specified length. The
1838 * string content is copied, so the backing memory can be freed after
1839 * this function returns.
1840 */
1841LLVMValueRef LLVMMDStringInContext(LLVMContextRef C, const char *Str,
1842 unsigned SLen);
1843
1844/**
1845 * Obtain a MDString value from the global context.
1846 */
1847LLVMValueRef LLVMMDString(const char *Str, unsigned SLen);
1848
1849/**
1850 * Obtain a MDNode value from a context.
1851 *
1852 * The returned value corresponds to the llvm::MDNode class.
1853 */
1854LLVMValueRef LLVMMDNodeInContext(LLVMContextRef C, LLVMValueRef *Vals,
1855 unsigned Count);
1856
1857/**
1858 * Obtain a MDNode value from the global context.
1859 */
1860LLVMValueRef LLVMMDNode(LLVMValueRef *Vals, unsigned Count);
1861
1862/**
1863 * Obtain the underlying string from a MDString value.
1864 *
1865 * @param V Instance to obtain string from.
1866 * @param Len Memory address which will hold length of returned string.
1867 * @return String data in MDString.
1868 */
1869const char *LLVMGetMDString(LLVMValueRef V, unsigned* Len);
1870
1871/**
1872 * @}
1873 */
1874
1875/**
Gregory Szorc34c863a2012-03-21 03:54:29 +00001876 * @defgroup LLVMCCoreValueBasicBlock Basic Block
1877 *
1878 * A basic block represents a single entry single exit section of code.
1879 * Basic blocks contain a list of instructions which form the body of
1880 * the block.
1881 *
1882 * Basic blocks belong to functions. They have the type of label.
1883 *
1884 * Basic blocks are themselves values. However, the C API models them as
1885 * LLVMBasicBlockRef.
1886 *
1887 * @see llvm::BasicBlock
1888 *
1889 * @{
1890 */
1891
1892/**
1893 * Convert a basic block instance to a value type.
1894 */
Gordon Henriksen07a45f42008-03-23 22:21:29 +00001895LLVMValueRef LLVMBasicBlockAsValue(LLVMBasicBlockRef BB);
Gregory Szorc34c863a2012-03-21 03:54:29 +00001896
1897/**
1898 * Determine whether a LLVMValueRef is itself a basic block.
1899 */
Chris Lattner25963c62010-01-09 22:27:07 +00001900LLVMBool LLVMValueIsBasicBlock(LLVMValueRef Val);
Gregory Szorc34c863a2012-03-21 03:54:29 +00001901
1902/**
1903 * Convert a LLVMValueRef to a LLVMBasicBlockRef instance.
1904 */
Gordon Henriksenc23b66c2007-09-26 20:56:12 +00001905LLVMBasicBlockRef LLVMValueAsBasicBlock(LLVMValueRef Val);
Gregory Szorc34c863a2012-03-21 03:54:29 +00001906
1907/**
1908 * Obtain the function to which a basic block belongs.
1909 *
1910 * @see llvm::BasicBlock::getParent()
1911 */
Gordon Henriksen07a45f42008-03-23 22:21:29 +00001912LLVMValueRef LLVMGetBasicBlockParent(LLVMBasicBlockRef BB);
Gregory Szorc34c863a2012-03-21 03:54:29 +00001913
1914/**
1915 * Obtain the terminator instruction for a basic block.
1916 *
1917 * If the basic block does not have a terminator (it is not well-formed
1918 * if it doesn't), then NULL is returned.
1919 *
1920 * The returned LLVMValueRef corresponds to a llvm::TerminatorInst.
1921 *
1922 * @see llvm::BasicBlock::getTerminator()
1923 */
Nate Begeman43c322b2011-08-23 20:27:46 +00001924LLVMValueRef LLVMGetBasicBlockTerminator(LLVMBasicBlockRef BB);
Gregory Szorc34c863a2012-03-21 03:54:29 +00001925
1926/**
1927 * Obtain the number of basic blocks in a function.
1928 *
1929 * @param Fn Function value to operate on.
1930 */
Gordon Henriksenc23b66c2007-09-26 20:56:12 +00001931unsigned LLVMCountBasicBlocks(LLVMValueRef Fn);
Gregory Szorc34c863a2012-03-21 03:54:29 +00001932
1933/**
1934 * Obtain all of the basic blocks in a function.
1935 *
1936 * This operates on a function value. The BasicBlocks parameter is a
1937 * pointer to a pre-allocated array of LLVMBasicBlockRef of at least
1938 * LLVMCountBasicBlocks() in length. This array is populated with
1939 * LLVMBasicBlockRef instances.
1940 */
Gordon Henriksenc23b66c2007-09-26 20:56:12 +00001941void LLVMGetBasicBlocks(LLVMValueRef Fn, LLVMBasicBlockRef *BasicBlocks);
Gregory Szorc34c863a2012-03-21 03:54:29 +00001942
1943/**
1944 * Obtain the first basic block in a function.
1945 *
1946 * The returned basic block can be used as an iterator. You will likely
1947 * eventually call into LLVMGetNextBasicBlock() with it.
1948 *
1949 * @see llvm::Function::begin()
1950 */
Gordon Henriksen054817c2008-03-19 03:47:18 +00001951LLVMBasicBlockRef LLVMGetFirstBasicBlock(LLVMValueRef Fn);
Gregory Szorc34c863a2012-03-21 03:54:29 +00001952
1953/**
1954 * Obtain the last basic block in a function.
1955 *
1956 * @see llvm::Function::end()
1957 */
Gordon Henriksen054817c2008-03-19 03:47:18 +00001958LLVMBasicBlockRef LLVMGetLastBasicBlock(LLVMValueRef Fn);
Gregory Szorc34c863a2012-03-21 03:54:29 +00001959
1960/**
1961 * Advance a basic block iterator.
1962 */
Gordon Henriksen054817c2008-03-19 03:47:18 +00001963LLVMBasicBlockRef LLVMGetNextBasicBlock(LLVMBasicBlockRef BB);
Gregory Szorc34c863a2012-03-21 03:54:29 +00001964
1965/**
1966 * Go backwards in a basic block iterator.
1967 */
Gordon Henriksen054817c2008-03-19 03:47:18 +00001968LLVMBasicBlockRef LLVMGetPreviousBasicBlock(LLVMBasicBlockRef BB);
Gregory Szorc34c863a2012-03-21 03:54:29 +00001969
1970/**
1971 * Obtain the basic block that corresponds to the entry point of a
1972 * function.
1973 *
1974 * @see llvm::Function::getEntryBlock()
1975 */
Gordon Henriksenc23b66c2007-09-26 20:56:12 +00001976LLVMBasicBlockRef LLVMGetEntryBasicBlock(LLVMValueRef Fn);
Erick Tryzelaar262332f2009-08-14 00:01:31 +00001977
Gregory Szorc34c863a2012-03-21 03:54:29 +00001978/**
1979 * Append a basic block to the end of a function.
1980 *
1981 * @see llvm::BasicBlock::Create()
1982 */
Erick Tryzelaar262332f2009-08-14 00:01:31 +00001983LLVMBasicBlockRef LLVMAppendBasicBlockInContext(LLVMContextRef C,
1984 LLVMValueRef Fn,
1985 const char *Name);
Gregory Szorc34c863a2012-03-21 03:54:29 +00001986
1987/**
1988 * Append a basic block to the end of a function using the global
1989 * context.
1990 *
1991 * @see llvm::BasicBlock::Create()
1992 */
1993LLVMBasicBlockRef LLVMAppendBasicBlock(LLVMValueRef Fn, const char *Name);
1994
1995/**
1996 * Insert a basic block in a function before another basic block.
1997 *
1998 * The function to add to is determined by the function of the
1999 * passed basic block.
2000 *
2001 * @see llvm::BasicBlock::Create()
2002 */
Erick Tryzelaar262332f2009-08-14 00:01:31 +00002003LLVMBasicBlockRef LLVMInsertBasicBlockInContext(LLVMContextRef C,
2004 LLVMBasicBlockRef BB,
2005 const char *Name);
2006
Gregory Szorc34c863a2012-03-21 03:54:29 +00002007/**
2008 * Insert a basic block in a function using the global context.
2009 *
2010 * @see llvm::BasicBlock::Create()
2011 */
Gordon Henriksenc23b66c2007-09-26 20:56:12 +00002012LLVMBasicBlockRef LLVMInsertBasicBlock(LLVMBasicBlockRef InsertBeforeBB,
2013 const char *Name);
Gregory Szorc34c863a2012-03-21 03:54:29 +00002014
2015/**
2016 * Remove a basic block from a function and delete it.
2017 *
2018 * This deletes the basic block from its containing function and deletes
2019 * the basic block itself.
2020 *
2021 * @see llvm::BasicBlock::eraseFromParent()
2022 */
Gordon Henriksenc23b66c2007-09-26 20:56:12 +00002023void LLVMDeleteBasicBlock(LLVMBasicBlockRef BB);
Gregory Szorc34c863a2012-03-21 03:54:29 +00002024
2025/**
2026 * Remove a basic block from a function.
2027 *
2028 * This deletes the basic block from its containing function but keep
2029 * the basic block alive.
2030 *
2031 * @see llvm::BasicBlock::removeFromParent()
2032 */
Nate Begeman43c322b2011-08-23 20:27:46 +00002033void LLVMRemoveBasicBlockFromParent(LLVMBasicBlockRef BB);
Gordon Henriksenc23b66c2007-09-26 20:56:12 +00002034
Gregory Szorc34c863a2012-03-21 03:54:29 +00002035/**
2036 * Move a basic block to before another one.
2037 *
2038 * @see llvm::BasicBlock::moveBefore()
2039 */
Duncan Sandsb1d61aa2010-07-19 15:31:07 +00002040void LLVMMoveBasicBlockBefore(LLVMBasicBlockRef BB, LLVMBasicBlockRef MovePos);
Gregory Szorc34c863a2012-03-21 03:54:29 +00002041
2042/**
2043 * Move a basic block to after another one.
2044 *
2045 * @see llvm::BasicBlock::moveAfter()
2046 */
Duncan Sandsb1d61aa2010-07-19 15:31:07 +00002047void LLVMMoveBasicBlockAfter(LLVMBasicBlockRef BB, LLVMBasicBlockRef MovePos);
2048
Gregory Szorc34c863a2012-03-21 03:54:29 +00002049/**
2050 * Obtain the first instruction in a basic block.
2051 *
2052 * The returned LLVMValueRef corresponds to a llvm::Instruction
2053 * instance.
2054 */
Gordon Henriksen054817c2008-03-19 03:47:18 +00002055LLVMValueRef LLVMGetFirstInstruction(LLVMBasicBlockRef BB);
Gregory Szorc34c863a2012-03-21 03:54:29 +00002056
2057/**
2058 * Obtain the last instruction in a basic block.
2059 *
2060 * The returned LLVMValueRef corresponds to a LLVM:Instruction.
2061 */
Gordon Henriksen054817c2008-03-19 03:47:18 +00002062LLVMValueRef LLVMGetLastInstruction(LLVMBasicBlockRef BB);
Nate Begeman43c322b2011-08-23 20:27:46 +00002063
Gregory Szorc34c863a2012-03-21 03:54:29 +00002064/**
2065 * @}
2066 */
2067
2068/**
2069 * @defgroup LLVMCCoreValueInstruction Instructions
2070 *
2071 * Functions in this group relate to the inspection and manipulation of
2072 * individual instructions.
2073 *
2074 * In the C++ API, an instruction is modeled by llvm::Instruction. This
2075 * class has a large number of descendents. llvm::Instruction is a
2076 * llvm::Value and in the C API, instructions are modeled by
2077 * LLVMValueRef.
2078 *
2079 * This group also contains sub-groups which operate on specific
2080 * llvm::Instruction types, e.g. llvm::CallInst.
2081 *
2082 * @{
2083 */
2084
2085/**
2086 * Determine whether an instruction has any metadata attached.
2087 */
2088int LLVMHasMetadata(LLVMValueRef Val);
2089
2090/**
2091 * Return metadata associated with an instruction value.
2092 */
2093LLVMValueRef LLVMGetMetadata(LLVMValueRef Val, unsigned KindID);
2094
2095/**
2096 * Set metadata associated with an instruction value.
2097 */
2098void LLVMSetMetadata(LLVMValueRef Val, unsigned KindID, LLVMValueRef Node);
2099
2100/**
2101 * Obtain the basic block to which an instruction belongs.
2102 *
2103 * @see llvm::Instruction::getParent()
2104 */
Nate Begeman43c322b2011-08-23 20:27:46 +00002105LLVMBasicBlockRef LLVMGetInstructionParent(LLVMValueRef Inst);
Gregory Szorc34c863a2012-03-21 03:54:29 +00002106
2107/**
2108 * Obtain the instruction that occurs after the one specified.
2109 *
2110 * The next instruction will be from the same basic block.
2111 *
2112 * If this is the last instruction in a basic block, NULL will be
2113 * returned.
2114 */
Gordon Henriksen054817c2008-03-19 03:47:18 +00002115LLVMValueRef LLVMGetNextInstruction(LLVMValueRef Inst);
Gregory Szorc34c863a2012-03-21 03:54:29 +00002116
2117/**
Benjamin Kramerbde91762012-06-02 10:20:22 +00002118 * Obtain the instruction that occurred before this one.
Gregory Szorc34c863a2012-03-21 03:54:29 +00002119 *
2120 * If the instruction is the first instruction in a basic block, NULL
2121 * will be returned.
2122 */
Gordon Henriksen054817c2008-03-19 03:47:18 +00002123LLVMValueRef LLVMGetPreviousInstruction(LLVMValueRef Inst);
Gregory Szorc34c863a2012-03-21 03:54:29 +00002124
2125/**
2126 * Remove and delete an instruction.
2127 *
2128 * The instruction specified is removed from its containing building
2129 * block and then deleted.
2130 *
2131 * @see llvm::Instruction::eraseFromParent()
2132 */
Devang Pateldbebc6f2011-10-03 20:59:18 +00002133void LLVMInstructionEraseFromParent(LLVMValueRef Inst);
Gregory Szorc34c863a2012-03-21 03:54:29 +00002134
2135/**
2136 * Obtain the code opcode for an individual instruction.
2137 *
2138 * @see llvm::Instruction::getOpCode()
2139 */
Torok Edwinab6158e2011-10-14 20:37:49 +00002140LLVMOpcode LLVMGetInstructionOpcode(LLVMValueRef Inst);
Gregory Szorc34c863a2012-03-21 03:54:29 +00002141
2142/**
2143 * Obtain the predicate of an instruction.
2144 *
2145 * This is only valid for instructions that correspond to llvm::ICmpInst
2146 * or llvm::ConstantExpr whose opcode is llvm::Instruction::ICmp.
2147 *
2148 * @see llvm::ICmpInst::getPredicate()
2149 */
Torok Edwin60c40de2011-10-06 12:13:20 +00002150LLVMIntPredicate LLVMGetICmpPredicate(LLVMValueRef Inst);
Gordon Henriksen265f7802008-03-19 01:11:35 +00002151
Gregory Szorc34c863a2012-03-21 03:54:29 +00002152/**
2153 * @defgroup LLVMCCoreValueInstructionCall Call Sites and Invocations
2154 *
2155 * Functions in this group apply to instructions that refer to call
2156 * sites and invocations. These correspond to C++ types in the
2157 * llvm::CallInst class tree.
2158 *
2159 * @{
2160 */
2161
2162/**
2163 * Set the calling convention for a call instruction.
2164 *
2165 * This expects an LLVMValueRef that corresponds to a llvm::CallInst or
2166 * llvm::InvokeInst.
2167 *
2168 * @see llvm::CallInst::setCallingConv()
2169 * @see llvm::InvokeInst::setCallingConv()
2170 */
Gordon Henriksen1158c532007-12-29 20:45:00 +00002171void LLVMSetInstructionCallConv(LLVMValueRef Instr, unsigned CC);
Gregory Szorc34c863a2012-03-21 03:54:29 +00002172
2173/**
2174 * Obtain the calling convention for a call instruction.
2175 *
2176 * This is the opposite of LLVMSetInstructionCallConv(). Reads its
2177 * usage.
2178 *
2179 * @see LLVMSetInstructionCallConv()
2180 */
Gordon Henriksen1158c532007-12-29 20:45:00 +00002181unsigned LLVMGetInstructionCallConv(LLVMValueRef Instr);
Gregory Szorc34c863a2012-03-21 03:54:29 +00002182
2183
Devang Patel4c758ea2008-09-25 21:00:45 +00002184void LLVMAddInstrAttribute(LLVMValueRef Instr, unsigned index, LLVMAttribute);
Gregory Szorc34c863a2012-03-21 03:54:29 +00002185void LLVMRemoveInstrAttribute(LLVMValueRef Instr, unsigned index,
Devang Patel4c758ea2008-09-25 21:00:45 +00002186 LLVMAttribute);
Gregory Szorc34c863a2012-03-21 03:54:29 +00002187void LLVMSetInstrParamAlignment(LLVMValueRef Instr, unsigned index,
Gordon Henriksen2d9cc212008-04-28 17:37:06 +00002188 unsigned align);
Gordon Henriksen1158c532007-12-29 20:45:00 +00002189
Gregory Szorc34c863a2012-03-21 03:54:29 +00002190/**
2191 * Obtain whether a call instruction is a tail call.
2192 *
2193 * This only works on llvm::CallInst instructions.
2194 *
2195 * @see llvm::CallInst::isTailCall()
2196 */
Chris Lattner25963c62010-01-09 22:27:07 +00002197LLVMBool LLVMIsTailCall(LLVMValueRef CallInst);
Gregory Szorc34c863a2012-03-21 03:54:29 +00002198
2199/**
2200 * Set whether a call instruction is a tail call.
2201 *
2202 * This only works on llvm::CallInst instructions.
2203 *
2204 * @see llvm::CallInst::setTailCall()
2205 */
Chris Lattner25963c62010-01-09 22:27:07 +00002206void LLVMSetTailCall(LLVMValueRef CallInst, LLVMBool IsTailCall);
Gordon Henrikseneeb65372008-08-30 16:34:54 +00002207
Gregory Szorc34c863a2012-03-21 03:54:29 +00002208/**
2209 * @}
2210 */
2211
2212/**
2213 * Obtain the default destination basic block of a switch instruction.
2214 *
2215 * This only works on llvm::SwitchInst instructions.
2216 *
2217 * @see llvm::SwitchInst::getDefaultDest()
2218 */
Nate Begeman43c322b2011-08-23 20:27:46 +00002219LLVMBasicBlockRef LLVMGetSwitchDefaultDest(LLVMValueRef SwitchInstr);
2220
Gregory Szorc34c863a2012-03-21 03:54:29 +00002221/**
2222 * @defgroup LLVMCCoreValueInstructionPHINode PHI Nodes
2223 *
2224 * Functions in this group only apply to instructions that map to
2225 * llvm::PHINode instances.
2226 *
2227 * @{
2228 */
2229
2230/**
2231 * Add an incoming value to the end of a PHI list.
2232 */
Gordon Henriksen44dd8fb2007-10-08 18:14:39 +00002233void LLVMAddIncoming(LLVMValueRef PhiNode, LLVMValueRef *IncomingValues,
2234 LLVMBasicBlockRef *IncomingBlocks, unsigned Count);
Gregory Szorc34c863a2012-03-21 03:54:29 +00002235
2236/**
2237 * Obtain the number of incoming basic blocks to a PHI node.
2238 */
Gordon Henriksen44dd8fb2007-10-08 18:14:39 +00002239unsigned LLVMCountIncoming(LLVMValueRef PhiNode);
Gregory Szorc34c863a2012-03-21 03:54:29 +00002240
2241/**
2242 * Obtain an incoming value to a PHI node as a LLVMValueRef.
2243 */
Gordon Henriksen44dd8fb2007-10-08 18:14:39 +00002244LLVMValueRef LLVMGetIncomingValue(LLVMValueRef PhiNode, unsigned Index);
Gregory Szorc34c863a2012-03-21 03:54:29 +00002245
2246/**
2247 * Obtain an incoming value to a PHI node as a LLVMBasicBlockRef.
2248 */
Gordon Henriksen44dd8fb2007-10-08 18:14:39 +00002249LLVMBasicBlockRef LLVMGetIncomingBlock(LLVMValueRef PhiNode, unsigned Index);
Gordon Henriksenc23b66c2007-09-26 20:56:12 +00002250
Gregory Szorc34c863a2012-03-21 03:54:29 +00002251/**
2252 * @}
2253 */
Gordon Henriksenc23b66c2007-09-26 20:56:12 +00002254
Gregory Szorc34c863a2012-03-21 03:54:29 +00002255/**
2256 * @}
2257 */
2258
2259/**
2260 * @}
2261 */
2262
2263/**
2264 * @defgroup LLVMCCoreInstructionBuilder Instruction Builders
2265 *
2266 * An instruction builder represents a point within a basic block and is
2267 * the exclusive means of building instructions using the C interface.
2268 *
2269 * @{
Gordon Henriksenc23b66c2007-09-26 20:56:12 +00002270 */
2271
Erick Tryzelaar262332f2009-08-14 00:01:31 +00002272LLVMBuilderRef LLVMCreateBuilderInContext(LLVMContextRef C);
Gordon Henriksena735a9c2008-05-04 12:55:34 +00002273LLVMBuilderRef LLVMCreateBuilder(void);
Gordon Henriksen054817c2008-03-19 03:47:18 +00002274void LLVMPositionBuilder(LLVMBuilderRef Builder, LLVMBasicBlockRef Block,
2275 LLVMValueRef Instr);
Gordon Henriksenc23b66c2007-09-26 20:56:12 +00002276void LLVMPositionBuilderBefore(LLVMBuilderRef Builder, LLVMValueRef Instr);
2277void LLVMPositionBuilderAtEnd(LLVMBuilderRef Builder, LLVMBasicBlockRef Block);
Gordon Henriksen265f7802008-03-19 01:11:35 +00002278LLVMBasicBlockRef LLVMGetInsertBlock(LLVMBuilderRef Builder);
Chris Lattner3d1f5522008-12-17 21:39:50 +00002279void LLVMClearInsertionPosition(LLVMBuilderRef Builder);
2280void LLVMInsertIntoBuilder(LLVMBuilderRef Builder, LLVMValueRef Instr);
Erick Tryzelaar9813bea2009-08-16 02:20:57 +00002281void LLVMInsertIntoBuilderWithName(LLVMBuilderRef Builder, LLVMValueRef Instr,
2282 const char *Name);
Gordon Henriksenc23b66c2007-09-26 20:56:12 +00002283void LLVMDisposeBuilder(LLVMBuilderRef Builder);
2284
Erick Tryzelaard8531fa2010-02-28 09:45:59 +00002285/* Metadata */
2286void LLVMSetCurrentDebugLocation(LLVMBuilderRef Builder, LLVMValueRef L);
2287LLVMValueRef LLVMGetCurrentDebugLocation(LLVMBuilderRef Builder);
2288void LLVMSetInstDebugLocation(LLVMBuilderRef Builder, LLVMValueRef Inst);
2289
Gordon Henriksenc23b66c2007-09-26 20:56:12 +00002290/* Terminators */
2291LLVMValueRef LLVMBuildRetVoid(LLVMBuilderRef);
2292LLVMValueRef LLVMBuildRet(LLVMBuilderRef, LLVMValueRef V);
Erick Tryzelaarfd529d72009-08-19 08:36:49 +00002293LLVMValueRef LLVMBuildAggregateRet(LLVMBuilderRef, LLVMValueRef *RetVals,
Erick Tryzelaar3045b8b2009-08-16 02:19:59 +00002294 unsigned N);
Gordon Henriksenc23b66c2007-09-26 20:56:12 +00002295LLVMValueRef LLVMBuildBr(LLVMBuilderRef, LLVMBasicBlockRef Dest);
2296LLVMValueRef LLVMBuildCondBr(LLVMBuilderRef, LLVMValueRef If,
2297 LLVMBasicBlockRef Then, LLVMBasicBlockRef Else);
2298LLVMValueRef LLVMBuildSwitch(LLVMBuilderRef, LLVMValueRef V,
2299 LLVMBasicBlockRef Else, unsigned NumCases);
Erick Tryzelaar0fb26ef2010-02-28 09:46:06 +00002300LLVMValueRef LLVMBuildIndirectBr(LLVMBuilderRef B, LLVMValueRef Addr,
2301 unsigned NumDests);
Gordon Henriksenc23b66c2007-09-26 20:56:12 +00002302LLVMValueRef LLVMBuildInvoke(LLVMBuilderRef, LLVMValueRef Fn,
2303 LLVMValueRef *Args, unsigned NumArgs,
2304 LLVMBasicBlockRef Then, LLVMBasicBlockRef Catch,
2305 const char *Name);
Benjamin Kramer5a6568832011-08-19 01:36:54 +00002306LLVMValueRef LLVMBuildLandingPad(LLVMBuilderRef B, LLVMTypeRef Ty,
2307 LLVMValueRef PersFn, unsigned NumClauses,
2308 const char *Name);
Bill Wendlingf891bf82011-07-31 06:30:59 +00002309LLVMValueRef LLVMBuildResume(LLVMBuilderRef B, LLVMValueRef Exn);
Gordon Henriksenc23b66c2007-09-26 20:56:12 +00002310LLVMValueRef LLVMBuildUnreachable(LLVMBuilderRef);
2311
Gordon Henriksen097102c2008-01-01 05:50:53 +00002312/* Add a case to the switch instruction */
2313void LLVMAddCase(LLVMValueRef Switch, LLVMValueRef OnVal,
2314 LLVMBasicBlockRef Dest);
2315
Erick Tryzelaar0fb26ef2010-02-28 09:46:06 +00002316/* Add a destination to the indirectbr instruction */
2317void LLVMAddDestination(LLVMValueRef IndirectBr, LLVMBasicBlockRef Dest);
2318
Bill Wendlingfae14752011-08-12 20:24:12 +00002319/* Add a catch or filter clause to the landingpad instruction */
2320void LLVMAddClause(LLVMValueRef LandingPad, LLVMValueRef ClauseVal);
2321
2322/* Set the 'cleanup' flag in the landingpad instruction */
2323void LLVMSetCleanup(LLVMValueRef LandingPad, LLVMBool Val);
2324
Gordon Henriksenc23b66c2007-09-26 20:56:12 +00002325/* Arithmetic */
2326LLVMValueRef LLVMBuildAdd(LLVMBuilderRef, LLVMValueRef LHS, LLVMValueRef RHS,
2327 const char *Name);
Erick Tryzelaar3045b8b2009-08-16 02:19:59 +00002328LLVMValueRef LLVMBuildNSWAdd(LLVMBuilderRef, LLVMValueRef LHS, LLVMValueRef RHS,
2329 const char *Name);
Erick Tryzelaar4c340c72010-02-28 05:51:43 +00002330LLVMValueRef LLVMBuildNUWAdd(LLVMBuilderRef, LLVMValueRef LHS, LLVMValueRef RHS,
2331 const char *Name);
Erick Tryzelaar3045b8b2009-08-16 02:19:59 +00002332LLVMValueRef LLVMBuildFAdd(LLVMBuilderRef, LLVMValueRef LHS, LLVMValueRef RHS,
2333 const char *Name);
Gordon Henriksenc23b66c2007-09-26 20:56:12 +00002334LLVMValueRef LLVMBuildSub(LLVMBuilderRef, LLVMValueRef LHS, LLVMValueRef RHS,
2335 const char *Name);
Erick Tryzelaar4c340c72010-02-28 05:51:43 +00002336LLVMValueRef LLVMBuildNSWSub(LLVMBuilderRef, LLVMValueRef LHS, LLVMValueRef RHS,
2337 const char *Name);
2338LLVMValueRef LLVMBuildNUWSub(LLVMBuilderRef, LLVMValueRef LHS, LLVMValueRef RHS,
2339 const char *Name);
Erick Tryzelaar3045b8b2009-08-16 02:19:59 +00002340LLVMValueRef LLVMBuildFSub(LLVMBuilderRef, LLVMValueRef LHS, LLVMValueRef RHS,
2341 const char *Name);
Gordon Henriksenc23b66c2007-09-26 20:56:12 +00002342LLVMValueRef LLVMBuildMul(LLVMBuilderRef, LLVMValueRef LHS, LLVMValueRef RHS,
2343 const char *Name);
Erick Tryzelaar4c340c72010-02-28 05:51:43 +00002344LLVMValueRef LLVMBuildNSWMul(LLVMBuilderRef, LLVMValueRef LHS, LLVMValueRef RHS,
2345 const char *Name);
2346LLVMValueRef LLVMBuildNUWMul(LLVMBuilderRef, LLVMValueRef LHS, LLVMValueRef RHS,
2347 const char *Name);
Erick Tryzelaar3045b8b2009-08-16 02:19:59 +00002348LLVMValueRef LLVMBuildFMul(LLVMBuilderRef, LLVMValueRef LHS, LLVMValueRef RHS,
2349 const char *Name);
Gordon Henriksenc23b66c2007-09-26 20:56:12 +00002350LLVMValueRef LLVMBuildUDiv(LLVMBuilderRef, LLVMValueRef LHS, LLVMValueRef RHS,
2351 const char *Name);
2352LLVMValueRef LLVMBuildSDiv(LLVMBuilderRef, LLVMValueRef LHS, LLVMValueRef RHS,
2353 const char *Name);
Erick Tryzelaar3045b8b2009-08-16 02:19:59 +00002354LLVMValueRef LLVMBuildExactSDiv(LLVMBuilderRef, LLVMValueRef LHS, LLVMValueRef RHS,
2355 const char *Name);
Gordon Henriksenc23b66c2007-09-26 20:56:12 +00002356LLVMValueRef LLVMBuildFDiv(LLVMBuilderRef, LLVMValueRef LHS, LLVMValueRef RHS,
2357 const char *Name);
2358LLVMValueRef LLVMBuildURem(LLVMBuilderRef, LLVMValueRef LHS, LLVMValueRef RHS,
2359 const char *Name);
2360LLVMValueRef LLVMBuildSRem(LLVMBuilderRef, LLVMValueRef LHS, LLVMValueRef RHS,
2361 const char *Name);
2362LLVMValueRef LLVMBuildFRem(LLVMBuilderRef, LLVMValueRef LHS, LLVMValueRef RHS,
2363 const char *Name);
2364LLVMValueRef LLVMBuildShl(LLVMBuilderRef, LLVMValueRef LHS, LLVMValueRef RHS,
2365 const char *Name);
2366LLVMValueRef LLVMBuildLShr(LLVMBuilderRef, LLVMValueRef LHS, LLVMValueRef RHS,
2367 const char *Name);
2368LLVMValueRef LLVMBuildAShr(LLVMBuilderRef, LLVMValueRef LHS, LLVMValueRef RHS,
2369 const char *Name);
2370LLVMValueRef LLVMBuildAnd(LLVMBuilderRef, LLVMValueRef LHS, LLVMValueRef RHS,
2371 const char *Name);
2372LLVMValueRef LLVMBuildOr(LLVMBuilderRef, LLVMValueRef LHS, LLVMValueRef RHS,
2373 const char *Name);
2374LLVMValueRef LLVMBuildXor(LLVMBuilderRef, LLVMValueRef LHS, LLVMValueRef RHS,
2375 const char *Name);
Erick Tryzelaar31831792010-02-28 05:51:27 +00002376LLVMValueRef LLVMBuildBinOp(LLVMBuilderRef B, LLVMOpcode Op,
2377 LLVMValueRef LHS, LLVMValueRef RHS,
2378 const char *Name);
Gordon Henriksenc23b66c2007-09-26 20:56:12 +00002379LLVMValueRef LLVMBuildNeg(LLVMBuilderRef, LLVMValueRef V, const char *Name);
Erick Tryzelaar4c340c72010-02-28 05:51:43 +00002380LLVMValueRef LLVMBuildNSWNeg(LLVMBuilderRef B, LLVMValueRef V,
2381 const char *Name);
2382LLVMValueRef LLVMBuildNUWNeg(LLVMBuilderRef B, LLVMValueRef V,
2383 const char *Name);
Dan Gohmanf919bd62009-09-28 21:51:41 +00002384LLVMValueRef LLVMBuildFNeg(LLVMBuilderRef, LLVMValueRef V, const char *Name);
Gordon Henriksenc23b66c2007-09-26 20:56:12 +00002385LLVMValueRef LLVMBuildNot(LLVMBuilderRef, LLVMValueRef V, const char *Name);
2386
2387/* Memory */
2388LLVMValueRef LLVMBuildMalloc(LLVMBuilderRef, LLVMTypeRef Ty, const char *Name);
2389LLVMValueRef LLVMBuildArrayMalloc(LLVMBuilderRef, LLVMTypeRef Ty,
2390 LLVMValueRef Val, const char *Name);
2391LLVMValueRef LLVMBuildAlloca(LLVMBuilderRef, LLVMTypeRef Ty, const char *Name);
2392LLVMValueRef LLVMBuildArrayAlloca(LLVMBuilderRef, LLVMTypeRef Ty,
2393 LLVMValueRef Val, const char *Name);
2394LLVMValueRef LLVMBuildFree(LLVMBuilderRef, LLVMValueRef PointerVal);
2395LLVMValueRef LLVMBuildLoad(LLVMBuilderRef, LLVMValueRef PointerVal,
2396 const char *Name);
2397LLVMValueRef LLVMBuildStore(LLVMBuilderRef, LLVMValueRef Val, LLVMValueRef Ptr);
2398LLVMValueRef LLVMBuildGEP(LLVMBuilderRef B, LLVMValueRef Pointer,
2399 LLVMValueRef *Indices, unsigned NumIndices,
2400 const char *Name);
Erick Tryzelaar3045b8b2009-08-16 02:19:59 +00002401LLVMValueRef LLVMBuildInBoundsGEP(LLVMBuilderRef B, LLVMValueRef Pointer,
2402 LLVMValueRef *Indices, unsigned NumIndices,
2403 const char *Name);
2404LLVMValueRef LLVMBuildStructGEP(LLVMBuilderRef B, LLVMValueRef Pointer,
2405 unsigned Idx, const char *Name);
2406LLVMValueRef LLVMBuildGlobalString(LLVMBuilderRef B, const char *Str,
2407 const char *Name);
2408LLVMValueRef LLVMBuildGlobalStringPtr(LLVMBuilderRef B, const char *Str,
2409 const char *Name);
Chris Lattner2cc6f9d2012-03-22 03:54:15 +00002410LLVMBool LLVMGetVolatile(LLVMValueRef MemoryAccessInst);
2411void LLVMSetVolatile(LLVMValueRef MemoryAccessInst, LLVMBool IsVolatile);
Gordon Henriksenc23b66c2007-09-26 20:56:12 +00002412
2413/* Casts */
2414LLVMValueRef LLVMBuildTrunc(LLVMBuilderRef, LLVMValueRef Val,
2415 LLVMTypeRef DestTy, const char *Name);
2416LLVMValueRef LLVMBuildZExt(LLVMBuilderRef, LLVMValueRef Val,
2417 LLVMTypeRef DestTy, const char *Name);
2418LLVMValueRef LLVMBuildSExt(LLVMBuilderRef, LLVMValueRef Val,
2419 LLVMTypeRef DestTy, const char *Name);
2420LLVMValueRef LLVMBuildFPToUI(LLVMBuilderRef, LLVMValueRef Val,
2421 LLVMTypeRef DestTy, const char *Name);
2422LLVMValueRef LLVMBuildFPToSI(LLVMBuilderRef, LLVMValueRef Val,
2423 LLVMTypeRef DestTy, const char *Name);
2424LLVMValueRef LLVMBuildUIToFP(LLVMBuilderRef, LLVMValueRef Val,
2425 LLVMTypeRef DestTy, const char *Name);
2426LLVMValueRef LLVMBuildSIToFP(LLVMBuilderRef, LLVMValueRef Val,
2427 LLVMTypeRef DestTy, const char *Name);
2428LLVMValueRef LLVMBuildFPTrunc(LLVMBuilderRef, LLVMValueRef Val,
2429 LLVMTypeRef DestTy, const char *Name);
2430LLVMValueRef LLVMBuildFPExt(LLVMBuilderRef, LLVMValueRef Val,
2431 LLVMTypeRef DestTy, const char *Name);
2432LLVMValueRef LLVMBuildPtrToInt(LLVMBuilderRef, LLVMValueRef Val,
2433 LLVMTypeRef DestTy, const char *Name);
2434LLVMValueRef LLVMBuildIntToPtr(LLVMBuilderRef, LLVMValueRef Val,
2435 LLVMTypeRef DestTy, const char *Name);
2436LLVMValueRef LLVMBuildBitCast(LLVMBuilderRef, LLVMValueRef Val,
2437 LLVMTypeRef DestTy, const char *Name);
Erick Tryzelaar3045b8b2009-08-16 02:19:59 +00002438LLVMValueRef LLVMBuildZExtOrBitCast(LLVMBuilderRef, LLVMValueRef Val,
2439 LLVMTypeRef DestTy, const char *Name);
2440LLVMValueRef LLVMBuildSExtOrBitCast(LLVMBuilderRef, LLVMValueRef Val,
2441 LLVMTypeRef DestTy, const char *Name);
2442LLVMValueRef LLVMBuildTruncOrBitCast(LLVMBuilderRef, LLVMValueRef Val,
2443 LLVMTypeRef DestTy, const char *Name);
Erick Tryzelaar31831792010-02-28 05:51:27 +00002444LLVMValueRef LLVMBuildCast(LLVMBuilderRef B, LLVMOpcode Op, LLVMValueRef Val,
2445 LLVMTypeRef DestTy, const char *Name);
Erick Tryzelaar3045b8b2009-08-16 02:19:59 +00002446LLVMValueRef LLVMBuildPointerCast(LLVMBuilderRef, LLVMValueRef Val,
2447 LLVMTypeRef DestTy, const char *Name);
Duncan Sands9d786d72009-11-23 10:49:03 +00002448LLVMValueRef LLVMBuildIntCast(LLVMBuilderRef, LLVMValueRef Val, /*Signed cast!*/
Erick Tryzelaar3045b8b2009-08-16 02:19:59 +00002449 LLVMTypeRef DestTy, const char *Name);
2450LLVMValueRef LLVMBuildFPCast(LLVMBuilderRef, LLVMValueRef Val,
2451 LLVMTypeRef DestTy, const char *Name);
Gordon Henriksenc23b66c2007-09-26 20:56:12 +00002452
2453/* Comparisons */
2454LLVMValueRef LLVMBuildICmp(LLVMBuilderRef, LLVMIntPredicate Op,
2455 LLVMValueRef LHS, LLVMValueRef RHS,
2456 const char *Name);
2457LLVMValueRef LLVMBuildFCmp(LLVMBuilderRef, LLVMRealPredicate Op,
2458 LLVMValueRef LHS, LLVMValueRef RHS,
2459 const char *Name);
2460
2461/* Miscellaneous instructions */
2462LLVMValueRef LLVMBuildPhi(LLVMBuilderRef, LLVMTypeRef Ty, const char *Name);
2463LLVMValueRef LLVMBuildCall(LLVMBuilderRef, LLVMValueRef Fn,
2464 LLVMValueRef *Args, unsigned NumArgs,
2465 const char *Name);
2466LLVMValueRef LLVMBuildSelect(LLVMBuilderRef, LLVMValueRef If,
2467 LLVMValueRef Then, LLVMValueRef Else,
2468 const char *Name);
2469LLVMValueRef LLVMBuildVAArg(LLVMBuilderRef, LLVMValueRef List, LLVMTypeRef Ty,
2470 const char *Name);
2471LLVMValueRef LLVMBuildExtractElement(LLVMBuilderRef, LLVMValueRef VecVal,
2472 LLVMValueRef Index, const char *Name);
2473LLVMValueRef LLVMBuildInsertElement(LLVMBuilderRef, LLVMValueRef VecVal,
2474 LLVMValueRef EltVal, LLVMValueRef Index,
2475 const char *Name);
2476LLVMValueRef LLVMBuildShuffleVector(LLVMBuilderRef, LLVMValueRef V1,
2477 LLVMValueRef V2, LLVMValueRef Mask,
2478 const char *Name);
Dan Gohmand5104a52008-11-03 22:55:43 +00002479LLVMValueRef LLVMBuildExtractValue(LLVMBuilderRef, LLVMValueRef AggVal,
2480 unsigned Index, const char *Name);
2481LLVMValueRef LLVMBuildInsertValue(LLVMBuilderRef, LLVMValueRef AggVal,
2482 LLVMValueRef EltVal, unsigned Index,
2483 const char *Name);
Gordon Henriksen76a03742007-09-18 03:18:57 +00002484
Erick Tryzelaar3045b8b2009-08-16 02:19:59 +00002485LLVMValueRef LLVMBuildIsNull(LLVMBuilderRef, LLVMValueRef Val,
2486 const char *Name);
2487LLVMValueRef LLVMBuildIsNotNull(LLVMBuilderRef, LLVMValueRef Val,
2488 const char *Name);
2489LLVMValueRef LLVMBuildPtrDiff(LLVMBuilderRef, LLVMValueRef LHS,
2490 LLVMValueRef RHS, const char *Name);
2491
Gregory Szorc34c863a2012-03-21 03:54:29 +00002492/**
2493 * @}
2494 */
Gordon Henriksen34eb6d82007-12-19 22:30:40 +00002495
Gregory Szorc34c863a2012-03-21 03:54:29 +00002496/**
2497 * @defgroup LLVMCCoreModuleProvider Module Providers
2498 *
2499 * @{
2500 */
Gordon Henriksen0a68fe22007-12-12 01:04:30 +00002501
Gregory Szorc34c863a2012-03-21 03:54:29 +00002502/**
2503 * Changes the type of M so it can be passed to FunctionPassManagers and the
Jeffrey Yasskin091217b2010-01-27 20:34:15 +00002504 * JIT. They take ModuleProviders for historical reasons.
Gordon Henriksen0a68fe22007-12-12 01:04:30 +00002505 */
2506LLVMModuleProviderRef
2507LLVMCreateModuleProviderForExistingModule(LLVMModuleRef M);
2508
Gregory Szorc34c863a2012-03-21 03:54:29 +00002509/**
2510 * Destroys the module M.
Gordon Henriksen0a68fe22007-12-12 01:04:30 +00002511 */
Jeffrey Yasskin091217b2010-01-27 20:34:15 +00002512void LLVMDisposeModuleProvider(LLVMModuleProviderRef M);
Gordon Henriksen0a68fe22007-12-12 01:04:30 +00002513
Gregory Szorc34c863a2012-03-21 03:54:29 +00002514/**
2515 * @}
2516 */
Gordon Henriksen34eb6d82007-12-19 22:30:40 +00002517
Gregory Szorc34c863a2012-03-21 03:54:29 +00002518/**
2519 * @defgroup LLVMCCoreMemoryBuffers Memory Buffers
2520 *
2521 * @{
2522 */
Gordon Henriksen34eb6d82007-12-19 22:30:40 +00002523
Chris Lattner25963c62010-01-09 22:27:07 +00002524LLVMBool LLVMCreateMemoryBufferWithContentsOfFile(const char *Path,
2525 LLVMMemoryBufferRef *OutMemBuf,
2526 char **OutMessage);
2527LLVMBool LLVMCreateMemoryBufferWithSTDIN(LLVMMemoryBufferRef *OutMemBuf,
2528 char **OutMessage);
Gordon Henriksen34eb6d82007-12-19 22:30:40 +00002529void LLVMDisposeMemoryBuffer(LLVMMemoryBufferRef MemBuf);
2530
Gregory Szorc34c863a2012-03-21 03:54:29 +00002531/**
2532 * @}
2533 */
2534
2535/**
2536 * @defgroup LLVMCCorePassRegistry Pass Registry
2537 *
2538 * @{
2539 */
Owen Anderson4698c5d2010-10-07 17:55:47 +00002540
2541/** Return the global pass registry, for use with initialization functions.
Gregory Szorc34c863a2012-03-21 03:54:29 +00002542 @see llvm::PassRegistry::getPassRegistry */
Owen Anderson4698c5d2010-10-07 17:55:47 +00002543LLVMPassRegistryRef LLVMGetGlobalPassRegistry(void);
Gordon Henriksen878114b2008-03-16 04:20:44 +00002544
Gregory Szorc34c863a2012-03-21 03:54:29 +00002545/**
2546 * @}
2547 */
2548
2549/**
2550 * @defgroup LLVMCCorePassManagers Pass Managers
2551 *
2552 * @{
2553 */
Gordon Henriksen878114b2008-03-16 04:20:44 +00002554
2555/** Constructs a new whole-module pass pipeline. This type of pipeline is
2556 suitable for link-time optimization and whole-module transformations.
Gregory Szorc34c863a2012-03-21 03:54:29 +00002557 @see llvm::PassManager::PassManager */
Gordon Henriksena735a9c2008-05-04 12:55:34 +00002558LLVMPassManagerRef LLVMCreatePassManager(void);
Gordon Henriksen878114b2008-03-16 04:20:44 +00002559
2560/** Constructs a new function-by-function pass pipeline over the module
2561 provider. It does not take ownership of the module provider. This type of
2562 pipeline is suitable for code generation and JIT compilation tasks.
Gregory Szorc34c863a2012-03-21 03:54:29 +00002563 @see llvm::FunctionPassManager::FunctionPassManager */
Erick Tryzelaarad0e0cb2010-03-02 23:58:54 +00002564LLVMPassManagerRef LLVMCreateFunctionPassManagerForModule(LLVMModuleRef M);
2565
2566/** Deprecated: Use LLVMCreateFunctionPassManagerForModule instead. */
Gordon Henriksen878114b2008-03-16 04:20:44 +00002567LLVMPassManagerRef LLVMCreateFunctionPassManager(LLVMModuleProviderRef MP);
2568
2569/** Initializes, executes on the provided module, and finalizes all of the
2570 passes scheduled in the pass manager. Returns 1 if any of the passes
Gregory Szorc34c863a2012-03-21 03:54:29 +00002571 modified the module, 0 otherwise.
2572 @see llvm::PassManager::run(Module&) */
Chris Lattner25963c62010-01-09 22:27:07 +00002573LLVMBool LLVMRunPassManager(LLVMPassManagerRef PM, LLVMModuleRef M);
Gordon Henriksen878114b2008-03-16 04:20:44 +00002574
2575/** Initializes all of the function passes scheduled in the function pass
2576 manager. Returns 1 if any of the passes modified the module, 0 otherwise.
Gregory Szorc34c863a2012-03-21 03:54:29 +00002577 @see llvm::FunctionPassManager::doInitialization */
Chris Lattner25963c62010-01-09 22:27:07 +00002578LLVMBool LLVMInitializeFunctionPassManager(LLVMPassManagerRef FPM);
Gordon Henriksen878114b2008-03-16 04:20:44 +00002579
2580/** Executes all of the function passes scheduled in the function pass manager
2581 on the provided function. Returns 1 if any of the passes modified the
2582 function, false otherwise.
Gregory Szorc34c863a2012-03-21 03:54:29 +00002583 @see llvm::FunctionPassManager::run(Function&) */
Chris Lattner25963c62010-01-09 22:27:07 +00002584LLVMBool LLVMRunFunctionPassManager(LLVMPassManagerRef FPM, LLVMValueRef F);
Gordon Henriksen878114b2008-03-16 04:20:44 +00002585
2586/** Finalizes all of the function passes scheduled in in the function pass
2587 manager. Returns 1 if any of the passes modified the module, 0 otherwise.
Gregory Szorc34c863a2012-03-21 03:54:29 +00002588 @see llvm::FunctionPassManager::doFinalization */
Chris Lattner25963c62010-01-09 22:27:07 +00002589LLVMBool LLVMFinalizeFunctionPassManager(LLVMPassManagerRef FPM);
Gordon Henriksen878114b2008-03-16 04:20:44 +00002590
2591/** Frees the memory of a pass pipeline. For function pipelines, does not free
2592 the module provider.
Gregory Szorc34c863a2012-03-21 03:54:29 +00002593 @see llvm::PassManagerBase::~PassManagerBase. */
Gordon Henriksen878114b2008-03-16 04:20:44 +00002594void LLVMDisposePassManager(LLVMPassManagerRef PM);
2595
Gregory Szorc34c863a2012-03-21 03:54:29 +00002596/**
2597 * @}
2598 */
2599
2600/**
2601 * @}
2602 */
2603
2604/**
2605 * @}
2606 */
Gordon Henriksen878114b2008-03-16 04:20:44 +00002607
Gordon Henriksen76a03742007-09-18 03:18:57 +00002608#ifdef __cplusplus
2609}
Gordon Henriksen76a03742007-09-18 03:18:57 +00002610
Gordon Henriksen7330acd2007-10-05 23:59:36 +00002611namespace llvm {
Gordon Henriksen34eb6d82007-12-19 22:30:40 +00002612 class MemoryBuffer;
Gordon Henriksen96571492008-03-16 15:55:43 +00002613 class PassManagerBase;
Gordon Henriksen0a68fe22007-12-12 01:04:30 +00002614
Gordon Henriksen34eb6d82007-12-19 22:30:40 +00002615 #define DEFINE_SIMPLE_CONVERSION_FUNCTIONS(ty, ref) \
2616 inline ty *unwrap(ref P) { \
2617 return reinterpret_cast<ty*>(P); \
2618 } \
2619 \
2620 inline ref wrap(const ty *P) { \
2621 return reinterpret_cast<ref>(const_cast<ty*>(P)); \
2622 }
Gordon Henriksen7330acd2007-10-05 23:59:36 +00002623
Gordon Henriksen878114b2008-03-16 04:20:44 +00002624 #define DEFINE_ISA_CONVERSION_FUNCTIONS(ty, ref) \
2625 DEFINE_SIMPLE_CONVERSION_FUNCTIONS(ty, ref) \
2626 \
2627 template<typename T> \
2628 inline T *unwrap(ref P) { \
2629 return cast<T>(unwrap(P)); \
2630 }
2631
2632 #define DEFINE_STDCXX_CONVERSION_FUNCTIONS(ty, ref) \
2633 DEFINE_SIMPLE_CONVERSION_FUNCTIONS(ty, ref) \
2634 \
2635 template<typename T> \
2636 inline T *unwrap(ref P) { \
Chris Lattner7ba06612010-01-22 06:49:46 +00002637 T *Q = (T*)unwrap(P); \
Gordon Henriksen878114b2008-03-16 04:20:44 +00002638 assert(Q && "Invalid cast!"); \
2639 return Q; \
2640 }
2641
2642 DEFINE_ISA_CONVERSION_FUNCTIONS (Type, LLVMTypeRef )
2643 DEFINE_ISA_CONVERSION_FUNCTIONS (Value, LLVMValueRef )
Gordon Henriksen823f9732007-12-27 18:25:59 +00002644 DEFINE_SIMPLE_CONVERSION_FUNCTIONS(Module, LLVMModuleRef )
2645 DEFINE_SIMPLE_CONVERSION_FUNCTIONS(BasicBlock, LLVMBasicBlockRef )
Eric Christopher59278832008-08-08 19:39:37 +00002646 DEFINE_SIMPLE_CONVERSION_FUNCTIONS(IRBuilder<>, LLVMBuilderRef )
Gordon Henriksen823f9732007-12-27 18:25:59 +00002647 DEFINE_SIMPLE_CONVERSION_FUNCTIONS(MemoryBuffer, LLVMMemoryBufferRef )
Owen Anderson6773d382009-07-01 16:58:40 +00002648 DEFINE_SIMPLE_CONVERSION_FUNCTIONS(LLVMContext, LLVMContextRef )
Erick Tryzelaar9f9857e2010-03-02 20:32:28 +00002649 DEFINE_SIMPLE_CONVERSION_FUNCTIONS(Use, LLVMUseRef )
Gordon Henriksen878114b2008-03-16 04:20:44 +00002650 DEFINE_STDCXX_CONVERSION_FUNCTIONS(PassManagerBase, LLVMPassManagerRef )
Owen Anderson4698c5d2010-10-07 17:55:47 +00002651 DEFINE_STDCXX_CONVERSION_FUNCTIONS(PassRegistry, LLVMPassRegistryRef )
Jeffrey Yasskin091217b2010-01-27 20:34:15 +00002652 /* LLVMModuleProviderRef exists for historical reasons, but now just holds a
2653 * Module.
2654 */
2655 inline Module *unwrap(LLVMModuleProviderRef MP) {
2656 return reinterpret_cast<Module*>(MP);
2657 }
Gordon Henriksen7330acd2007-10-05 23:59:36 +00002658
Gordon Henriksen878114b2008-03-16 04:20:44 +00002659 #undef DEFINE_STDCXX_CONVERSION_FUNCTIONS
2660 #undef DEFINE_ISA_CONVERSION_FUNCTIONS
Gordon Henriksen34eb6d82007-12-19 22:30:40 +00002661 #undef DEFINE_SIMPLE_CONVERSION_FUNCTIONS
Erick Tryzelaar262332f2009-08-14 00:01:31 +00002662
2663 /* Specialized opaque context conversions.
2664 */
2665 inline LLVMContext **unwrap(LLVMContextRef* Tys) {
2666 return reinterpret_cast<LLVMContext**>(Tys);
2667 }
2668
2669 inline LLVMContextRef *wrap(const LLVMContext **Tys) {
2670 return reinterpret_cast<LLVMContextRef*>(const_cast<LLVMContext**>(Tys));
2671 }
Gordon Henriksen7330acd2007-10-05 23:59:36 +00002672
Gordon Henriksen34eb6d82007-12-19 22:30:40 +00002673 /* Specialized opaque type conversions.
2674 */
Gordon Henriksen7330acd2007-10-05 23:59:36 +00002675 inline Type **unwrap(LLVMTypeRef* Tys) {
2676 return reinterpret_cast<Type**>(Tys);
2677 }
2678
Chris Lattner229907c2011-07-18 04:54:35 +00002679 inline LLVMTypeRef *wrap(Type **Tys) {
Gordon Henriksen7330acd2007-10-05 23:59:36 +00002680 return reinterpret_cast<LLVMTypeRef*>(const_cast<Type**>(Tys));
2681 }
2682
Gordon Henriksen34eb6d82007-12-19 22:30:40 +00002683 /* Specialized opaque value conversions.
Gordon Henriksen7330acd2007-10-05 23:59:36 +00002684 */
Gordon Henriksen7330acd2007-10-05 23:59:36 +00002685 inline Value **unwrap(LLVMValueRef *Vals) {
2686 return reinterpret_cast<Value**>(Vals);
2687 }
2688
2689 template<typename T>
2690 inline T **unwrap(LLVMValueRef *Vals, unsigned Length) {
2691 #if DEBUG
Chris Lattnerb7971152009-07-10 18:28:19 +00002692 for (LLVMValueRef *I = Vals, *E = Vals + Length; I != E; ++I)
Gordon Henriksen7330acd2007-10-05 23:59:36 +00002693 cast<T>(*I);
2694 #endif
Hans Wennborg8f7edbf2011-06-04 16:00:19 +00002695 (void)Length;
Gordon Henriksen7330acd2007-10-05 23:59:36 +00002696 return reinterpret_cast<T**>(Vals);
2697 }
2698
Gordon Henriksen7330acd2007-10-05 23:59:36 +00002699 inline LLVMValueRef *wrap(const Value **Vals) {
2700 return reinterpret_cast<LLVMValueRef*>(const_cast<Value**>(Vals));
2701 }
Gordon Henriksen7330acd2007-10-05 23:59:36 +00002702}
2703
2704#endif /* !defined(__cplusplus) */
2705
2706#endif /* !defined(LLVM_C_CORE_H) */