blob: 50985e906465f1705f85c2dc65000970b9c8fc6f [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|* *|
13|* LLVM uses a polymorphic type hierarchy which C cannot represent, therefore *|
14|* parameters must be passed as base types. Despite the declared types, most *|
15|* of the functions provided operate only on branches of the type hierarchy. *|
16|* The declared parameter names are descriptive and specify which type is *|
17|* required. Additionally, each type hierarchy is documented along with the *|
18|* functions that operate upon it. For more detail, refer to LLVM's C++ code. *|
19|* If in doubt, refer to Core.cpp, which performs paramter downcasts in the *|
20|* form unwrap<RequiredType>(Param). *|
21|* *|
22|* Many exotic languages can interoperate with C code but have a harder time *|
23|* with C++ due to name mangling. So in addition to C, this interface enables *|
24|* tools written in such languages. *|
25|* *|
Gordon Henriksen7330acd2007-10-05 23:59:36 +000026|* When included into a C++ source file, also declares 'wrap' and 'unwrap' *|
27|* helpers to perform opaque reference<-->pointer conversions. These helpers *|
28|* are shorter and more tightly typed than writing the casts by hand when *|
29|* authoring bindings. In assert builds, they will do runtime type checking. *|
30|* *|
Gordon Henriksen76a03742007-09-18 03:18:57 +000031\*===----------------------------------------------------------------------===*/
32
33#ifndef LLVM_C_CORE_H
34#define LLVM_C_CORE_H
35
36#ifdef __cplusplus
Gordon Henriksen7330acd2007-10-05 23:59:36 +000037
38/* Need these includes to support the LLVM 'cast' template for the C++ 'wrap'
39 and 'unwrap' conversion functions. */
40#include "llvm/Module.h"
Duncan Sandsa07136e2008-04-13 06:22:09 +000041#include "llvm/Support/IRBuilder.h"
Gordon Henriksen7330acd2007-10-05 23:59:36 +000042
Gordon Henriksen76a03742007-09-18 03:18:57 +000043extern "C" {
44#endif
45
46
47/* Opaque types. */
Gordon Henriksen4a4d7352007-12-30 17:46:33 +000048
49/**
Owen Anderson6773d382009-07-01 16:58:40 +000050 * The top-level container for all LLVM global data. See the LLVMContext class.
51 */
Erick Tryzelaar262332f2009-08-14 00:01:31 +000052typedef struct LLVMOpaqueContext *LLVMContextRef;
Owen Anderson6773d382009-07-01 16:58:40 +000053
54/**
Gordon Henriksen4a4d7352007-12-30 17:46:33 +000055 * The top-level container for all other LLVM Intermediate Representation (IR)
56 * objects. See the llvm::Module class.
57 */
Gordon Henriksen76a03742007-09-18 03:18:57 +000058typedef struct LLVMOpaqueModule *LLVMModuleRef;
Gordon Henriksen4a4d7352007-12-30 17:46:33 +000059
60/**
Gordon Henriksena49d4352008-03-07 19:13:06 +000061 * Each value in the LLVM IR has a type, an LLVMTypeRef. See the llvm::Type
62 * class.
Gordon Henriksen4a4d7352007-12-30 17:46:33 +000063 */
Gordon Henriksen76a03742007-09-18 03:18:57 +000064typedef struct LLVMOpaqueType *LLVMTypeRef;
Gordon Henriksen4a4d7352007-12-30 17:46:33 +000065
66/**
Gordon Henriksena49d4352008-03-07 19:13:06 +000067 * When building recursive types using LLVMRefineType, LLVMTypeRef values may
68 * become invalid; use LLVMTypeHandleRef to resolve this problem. See the
69 * llvm::AbstractTypeHolder class.
Gordon Henriksen4a4d7352007-12-30 17:46:33 +000070 */
Gordon Henriksenffb48762007-10-07 00:13:35 +000071typedef struct LLVMOpaqueTypeHandle *LLVMTypeHandleRef;
Gordon Henriksen4a4d7352007-12-30 17:46:33 +000072
Gordon Henriksen76a03742007-09-18 03:18:57 +000073typedef struct LLVMOpaqueValue *LLVMValueRef;
Gordon Henriksenc23b66c2007-09-26 20:56:12 +000074typedef struct LLVMOpaqueBasicBlock *LLVMBasicBlockRef;
75typedef struct LLVMOpaqueBuilder *LLVMBuilderRef;
Gordon Henriksen34eb6d82007-12-19 22:30:40 +000076
77/* Used to provide a module to JIT or interpreter.
78 * See the llvm::ModuleProvider class.
79 */
Gordon Henriksen0a68fe22007-12-12 01:04:30 +000080typedef struct LLVMOpaqueModuleProvider *LLVMModuleProviderRef;
Gordon Henriksen76a03742007-09-18 03:18:57 +000081
Gordon Henriksen34eb6d82007-12-19 22:30:40 +000082/* Used to provide a module to JIT or interpreter.
83 * See the llvm::MemoryBuffer class.
84 */
85typedef struct LLVMOpaqueMemoryBuffer *LLVMMemoryBufferRef;
86
Gordon Henriksen878114b2008-03-16 04:20:44 +000087/** See the llvm::PassManagerBase class. */
88typedef struct LLVMOpaquePassManager *LLVMPassManagerRef;
89
Gordon Henriksen76a03742007-09-18 03:18:57 +000090typedef enum {
Devang Patel4c758ea2008-09-25 21:00:45 +000091 LLVMZExtAttribute = 1<<0,
92 LLVMSExtAttribute = 1<<1,
93 LLVMNoReturnAttribute = 1<<2,
94 LLVMInRegAttribute = 1<<3,
95 LLVMStructRetAttribute = 1<<4,
96 LLVMNoUnwindAttribute = 1<<5,
97 LLVMNoAliasAttribute = 1<<6,
98 LLVMByValAttribute = 1<<7,
99 LLVMNestAttribute = 1<<8,
100 LLVMReadNoneAttribute = 1<<9,
Anton Korobeynikovc8ce7b082009-07-17 18:07:26 +0000101 LLVMReadOnlyAttribute = 1<<10,
Anton Korobeynikov9750be92009-07-17 18:57:16 +0000102 LLVMNoInlineAttribute = 1<<11,
103 LLVMAlwaysInlineAttribute = 1<<12,
104 LLVMOptimizeForSizeAttribute = 1<<13,
105 LLVMStackProtectAttribute = 1<<14,
106 LLVMStackProtectReqAttribute = 1<<15,
107 LLVMNoCaptureAttribute = 1<<21,
108 LLVMNoRedZoneAttribute = 1<<22,
109 LLVMNoImplicitFloatAttribute = 1<<23,
Anton Korobeynikovc8ce7b082009-07-17 18:07:26 +0000110 LLVMNakedAttribute = 1<<24
Devang Patel4c758ea2008-09-25 21:00:45 +0000111} LLVMAttribute;
Gordon Henriksen2d9cc212008-04-28 17:37:06 +0000112
113typedef enum {
Gordon Henriksen4a4d7352007-12-30 17:46:33 +0000114 LLVMVoidTypeKind, /**< type with no size */
115 LLVMFloatTypeKind, /**< 32 bit floating point type */
116 LLVMDoubleTypeKind, /**< 64 bit floating point type */
117 LLVMX86_FP80TypeKind, /**< 80 bit floating point type (X87) */
118 LLVMFP128TypeKind, /**< 128 bit floating point type (112-bit mantissa)*/
119 LLVMPPC_FP128TypeKind, /**< 128 bit floating point type (two 64-bits) */
120 LLVMLabelTypeKind, /**< Labels */
121 LLVMIntegerTypeKind, /**< Arbitrary bit width integers */
122 LLVMFunctionTypeKind, /**< Functions */
123 LLVMStructTypeKind, /**< Structures */
124 LLVMArrayTypeKind, /**< Arrays */
125 LLVMPointerTypeKind, /**< Pointers */
126 LLVMOpaqueTypeKind, /**< Opaque: type with unknown structure */
Chris Lattnerdac44ec2009-07-15 22:00:31 +0000127 LLVMVectorTypeKind, /**< SIMD 'packed' format, or other vector type */
128 LLVMMetadataTypeKind /**< Metadata */
Gordon Henriksen76a03742007-09-18 03:18:57 +0000129} LLVMTypeKind;
130
131typedef enum {
Gordon Henriksen4a4d7352007-12-30 17:46:33 +0000132 LLVMExternalLinkage, /**< Externally visible function */
Chris Lattner2dba0f02009-04-13 06:25:37 +0000133 LLVMAvailableExternallyLinkage,
Duncan Sands12da8ce2009-03-07 15:45:40 +0000134 LLVMLinkOnceAnyLinkage, /**< Keep one copy of function when linking (inline)*/
135 LLVMLinkOnceODRLinkage, /**< Same, but only replaced by something
136 equivalent. */
137 LLVMWeakAnyLinkage, /**< Keep one copy of function when linking (weak) */
138 LLVMWeakODRLinkage, /**< Same, but only replaced by something
139 equivalent. */
Gordon Henriksen4a4d7352007-12-30 17:46:33 +0000140 LLVMAppendingLinkage, /**< Special purpose, only applies to global arrays */
141 LLVMInternalLinkage, /**< Rename collisions when linking (static
142 functions) */
Duncan Sands12da8ce2009-03-07 15:45:40 +0000143 LLVMPrivateLinkage, /**< Like Internal, but omit from symbol table */
Gordon Henriksen4a4d7352007-12-30 17:46:33 +0000144 LLVMDLLImportLinkage, /**< Function to be imported from DLL */
145 LLVMDLLExportLinkage, /**< Function to be accessible from DLL */
Duncan Sandse2881052009-03-11 08:08:06 +0000146 LLVMExternalWeakLinkage,/**< ExternalWeak linkage description */
Duncan Sands12da8ce2009-03-07 15:45:40 +0000147 LLVMGhostLinkage, /**< Stand-in functions for streaming fns from
Gordon Henriksen4a4d7352007-12-30 17:46:33 +0000148 bitcode */
Bill Wendling002b1672009-07-20 18:22:52 +0000149 LLVMCommonLinkage, /**< Tentative definitions */
150 LLVMLinkerPrivateLinkage /**< Like Private, but linker removes. */
Gordon Henriksen76a03742007-09-18 03:18:57 +0000151} LLVMLinkage;
152
153typedef enum {
Gordon Henriksen4a4d7352007-12-30 17:46:33 +0000154 LLVMDefaultVisibility, /**< The GV is visible */
155 LLVMHiddenVisibility, /**< The GV is hidden */
156 LLVMProtectedVisibility /**< The GV is protected */
Gordon Henriksen76a03742007-09-18 03:18:57 +0000157} LLVMVisibility;
158
Gordon Henriksenc23b66c2007-09-26 20:56:12 +0000159typedef enum {
160 LLVMCCallConv = 0,
161 LLVMFastCallConv = 8,
162 LLVMColdCallConv = 9,
163 LLVMX86StdcallCallConv = 64,
164 LLVMX86FastcallCallConv = 65
165} LLVMCallConv;
166
167typedef enum {
Gordon Henriksen4a4d7352007-12-30 17:46:33 +0000168 LLVMIntEQ = 32, /**< equal */
169 LLVMIntNE, /**< not equal */
170 LLVMIntUGT, /**< unsigned greater than */
171 LLVMIntUGE, /**< unsigned greater or equal */
172 LLVMIntULT, /**< unsigned less than */
173 LLVMIntULE, /**< unsigned less or equal */
174 LLVMIntSGT, /**< signed greater than */
175 LLVMIntSGE, /**< signed greater or equal */
176 LLVMIntSLT, /**< signed less than */
177 LLVMIntSLE /**< signed less or equal */
Gordon Henriksenc23b66c2007-09-26 20:56:12 +0000178} LLVMIntPredicate;
179
180typedef enum {
Gordon Henriksen4a4d7352007-12-30 17:46:33 +0000181 LLVMRealPredicateFalse, /**< Always false (always folded) */
182 LLVMRealOEQ, /**< True if ordered and equal */
183 LLVMRealOGT, /**< True if ordered and greater than */
184 LLVMRealOGE, /**< True if ordered and greater than or equal */
185 LLVMRealOLT, /**< True if ordered and less than */
186 LLVMRealOLE, /**< True if ordered and less than or equal */
187 LLVMRealONE, /**< True if ordered and operands are unequal */
188 LLVMRealORD, /**< True if ordered (no nans) */
189 LLVMRealUNO, /**< True if unordered: isnan(X) | isnan(Y) */
190 LLVMRealUEQ, /**< True if unordered or equal */
191 LLVMRealUGT, /**< True if unordered or greater than */
192 LLVMRealUGE, /**< True if unordered, greater than, or equal */
193 LLVMRealULT, /**< True if unordered or less than */
194 LLVMRealULE, /**< True if unordered, less than, or equal */
195 LLVMRealUNE, /**< True if unordered or not equal */
196 LLVMRealPredicateTrue /**< Always true (always folded) */
Gordon Henriksenc23b66c2007-09-26 20:56:12 +0000197} LLVMRealPredicate;
198
Gordon Henriksen76a03742007-09-18 03:18:57 +0000199
Gordon Henriksen34eb6d82007-12-19 22:30:40 +0000200/*===-- Error handling ----------------------------------------------------===*/
201
202void LLVMDisposeMessage(char *Message);
203
204
Gordon Henriksen76a03742007-09-18 03:18:57 +0000205/*===-- Modules -----------------------------------------------------------===*/
206
Owen Anderson6773d382009-07-01 16:58:40 +0000207/* Create and destroy contexts. */
208LLVMContextRef LLVMContextCreate();
Owen Andersonf7691d32009-07-02 00:16:38 +0000209LLVMContextRef LLVMGetGlobalContext();
Owen Anderson6773d382009-07-01 16:58:40 +0000210void LLVMContextDispose(LLVMContextRef C);
211
Gordon Henriksen76a03742007-09-18 03:18:57 +0000212/* Create and destroy modules. */
Gordon Henriksena49d4352008-03-07 19:13:06 +0000213/** See llvm::Module::Module. */
Gordon Henriksen76a03742007-09-18 03:18:57 +0000214LLVMModuleRef LLVMModuleCreateWithName(const char *ModuleID);
Owen Anderson31d44e42009-07-02 07:17:57 +0000215LLVMModuleRef LLVMModuleCreateWithNameInContext(const char *ModuleID,
216 LLVMContextRef C);
Gordon Henriksena49d4352008-03-07 19:13:06 +0000217
218/** See llvm::Module::~Module. */
Gordon Henriksen76a03742007-09-18 03:18:57 +0000219void LLVMDisposeModule(LLVMModuleRef M);
220
Gordon Henriksena49d4352008-03-07 19:13:06 +0000221/** Data layout. See Module::getDataLayout. */
Gordon Henriksen05568bb2007-12-27 20:13:47 +0000222const char *LLVMGetDataLayout(LLVMModuleRef M);
223void LLVMSetDataLayout(LLVMModuleRef M, const char *Triple);
224
Gordon Henriksena49d4352008-03-07 19:13:06 +0000225/** Target triple. See Module::getTargetTriple. */
Gordon Henriksen05568bb2007-12-27 20:13:47 +0000226const char *LLVMGetTarget(LLVMModuleRef M);
227void LLVMSetTarget(LLVMModuleRef M, const char *Triple);
228
Gordon Henriksena49d4352008-03-07 19:13:06 +0000229/** See Module::addTypeName. */
Gordon Henriksen76a03742007-09-18 03:18:57 +0000230int LLVMAddTypeName(LLVMModuleRef M, const char *Name, LLVMTypeRef Ty);
Gordon Henriksenc23b66c2007-09-26 20:56:12 +0000231void LLVMDeleteTypeName(LLVMModuleRef M, const char *Name);
Chris Lattner7f318242009-07-06 17:29:59 +0000232LLVMTypeRef LLVMGetTypeByName(LLVMModuleRef M, const char *Name);
Gordon Henriksen76a03742007-09-18 03:18:57 +0000233
Gordon Henriksen6c6075e2008-03-14 23:58:56 +0000234/** See Module::dump. */
235void LLVMDumpModule(LLVMModuleRef M);
236
Gordon Henriksen76a03742007-09-18 03:18:57 +0000237
Gordon Henriksenc23b66c2007-09-26 20:56:12 +0000238/*===-- Types -------------------------------------------------------------===*/
Gordon Henriksen76a03742007-09-18 03:18:57 +0000239
240/* LLVM types conform to the following hierarchy:
241 *
242 * types:
243 * integer type
244 * real type
245 * function type
246 * sequence types:
247 * array type
248 * pointer type
249 * vector type
250 * void type
251 * label type
252 * opaque type
253 */
254
Gordon Henriksena49d4352008-03-07 19:13:06 +0000255/** See llvm::LLVMTypeKind::getTypeID. */
Gordon Henriksen76a03742007-09-18 03:18:57 +0000256LLVMTypeKind LLVMGetTypeKind(LLVMTypeRef Ty);
Gordon Henriksena49d4352008-03-07 19:13:06 +0000257
Erick Tryzelaar262332f2009-08-14 00:01:31 +0000258/** See llvm::LLVMType::getContext. */
259LLVMContextRef LLVMGetTypeContext(LLVMTypeRef Ty);
260
Gordon Henriksen76a03742007-09-18 03:18:57 +0000261/* Operations on integer types */
Erick Tryzelaar262332f2009-08-14 00:01:31 +0000262LLVMTypeRef LLVMInt1TypeInContext(LLVMContextRef C);
263LLVMTypeRef LLVMInt8TypeInContext(LLVMContextRef C);
264LLVMTypeRef LLVMInt16TypeInContext(LLVMContextRef C);
265LLVMTypeRef LLVMInt32TypeInContext(LLVMContextRef C);
266LLVMTypeRef LLVMInt64TypeInContext(LLVMContextRef C);
267LLVMTypeRef LLVMIntTypeInContext(LLVMContextRef C, unsigned NumBits);
268
Gordon Henriksena735a9c2008-05-04 12:55:34 +0000269LLVMTypeRef LLVMInt1Type(void);
270LLVMTypeRef LLVMInt8Type(void);
271LLVMTypeRef LLVMInt16Type(void);
272LLVMTypeRef LLVMInt32Type(void);
273LLVMTypeRef LLVMInt64Type(void);
Gordon Henriksened7beaa2007-10-06 16:05:20 +0000274LLVMTypeRef LLVMIntType(unsigned NumBits);
Gordon Henriksenc23b66c2007-09-26 20:56:12 +0000275unsigned LLVMGetIntTypeWidth(LLVMTypeRef IntegerTy);
Gordon Henriksen76a03742007-09-18 03:18:57 +0000276
277/* Operations on real types */
Erick Tryzelaar262332f2009-08-14 00:01:31 +0000278LLVMTypeRef LLVMFloatTypeInContext(LLVMContextRef C);
279LLVMTypeRef LLVMDoubleTypeInContext(LLVMContextRef C);
280LLVMTypeRef LLVMX86FP80TypeInContext(LLVMContextRef C);
281LLVMTypeRef LLVMFP128TypeInContext(LLVMContextRef C);
282LLVMTypeRef LLVMPPCFP128TypeInContext(LLVMContextRef C);
283
Gordon Henriksena735a9c2008-05-04 12:55:34 +0000284LLVMTypeRef LLVMFloatType(void);
285LLVMTypeRef LLVMDoubleType(void);
286LLVMTypeRef LLVMX86FP80Type(void);
287LLVMTypeRef LLVMFP128Type(void);
288LLVMTypeRef LLVMPPCFP128Type(void);
Gordon Henriksen76a03742007-09-18 03:18:57 +0000289
290/* Operations on function types */
Gordon Henriksened7beaa2007-10-06 16:05:20 +0000291LLVMTypeRef LLVMFunctionType(LLVMTypeRef ReturnType,
292 LLVMTypeRef *ParamTypes, unsigned ParamCount,
293 int IsVarArg);
Gordon Henriksen76a03742007-09-18 03:18:57 +0000294int LLVMIsFunctionVarArg(LLVMTypeRef FunctionTy);
Gordon Henriksenc23b66c2007-09-26 20:56:12 +0000295LLVMTypeRef LLVMGetReturnType(LLVMTypeRef FunctionTy);
296unsigned LLVMCountParamTypes(LLVMTypeRef FunctionTy);
297void LLVMGetParamTypes(LLVMTypeRef FunctionTy, LLVMTypeRef *Dest);
Gordon Henriksen76a03742007-09-18 03:18:57 +0000298
299/* Operations on struct types */
Erick Tryzelaar262332f2009-08-14 00:01:31 +0000300LLVMTypeRef LLVMStructTypeInContext(LLVMContextRef C, LLVMTypeRef *ElementTypes,
301 unsigned ElementCount, int Packed);
Gordon Henriksened7beaa2007-10-06 16:05:20 +0000302LLVMTypeRef LLVMStructType(LLVMTypeRef *ElementTypes, unsigned ElementCount,
303 int Packed);
Gordon Henriksenc23b66c2007-09-26 20:56:12 +0000304unsigned LLVMCountStructElementTypes(LLVMTypeRef StructTy);
Gordon Henriksen76a03742007-09-18 03:18:57 +0000305void LLVMGetStructElementTypes(LLVMTypeRef StructTy, LLVMTypeRef *Dest);
306int LLVMIsPackedStruct(LLVMTypeRef StructTy);
307
308/* Operations on array, pointer, and vector types (sequence types) */
Gordon Henriksened7beaa2007-10-06 16:05:20 +0000309LLVMTypeRef LLVMArrayType(LLVMTypeRef ElementType, unsigned ElementCount);
Gordon Henriksen5a3fe032007-12-17 16:08:32 +0000310LLVMTypeRef LLVMPointerType(LLVMTypeRef ElementType, unsigned AddressSpace);
Gordon Henriksened7beaa2007-10-06 16:05:20 +0000311LLVMTypeRef LLVMVectorType(LLVMTypeRef ElementType, unsigned ElementCount);
Gordon Henriksen76a03742007-09-18 03:18:57 +0000312
313LLVMTypeRef LLVMGetElementType(LLVMTypeRef Ty);
314unsigned LLVMGetArrayLength(LLVMTypeRef ArrayTy);
Gordon Henriksen5a3fe032007-12-17 16:08:32 +0000315unsigned LLVMGetPointerAddressSpace(LLVMTypeRef PointerTy);
Gordon Henriksen76a03742007-09-18 03:18:57 +0000316unsigned LLVMGetVectorSize(LLVMTypeRef VectorTy);
317
318/* Operations on other types */
Erick Tryzelaar262332f2009-08-14 00:01:31 +0000319LLVMTypeRef LLVMVoidTypeInContext(LLVMContextRef C);
320LLVMTypeRef LLVMLabelTypeInContext(LLVMContextRef C);
321LLVMTypeRef LLVMOpaqueTypeInContext(LLVMContextRef C);
322
Gordon Henriksena735a9c2008-05-04 12:55:34 +0000323LLVMTypeRef LLVMVoidType(void);
324LLVMTypeRef LLVMLabelType(void);
325LLVMTypeRef LLVMOpaqueType(void);
Gordon Henriksen76a03742007-09-18 03:18:57 +0000326
Gordon Henriksenffb48762007-10-07 00:13:35 +0000327/* Operations on type handles */
328LLVMTypeHandleRef LLVMCreateTypeHandle(LLVMTypeRef PotentiallyAbstractTy);
329void LLVMRefineType(LLVMTypeRef AbstractTy, LLVMTypeRef ConcreteTy);
330LLVMTypeRef LLVMResolveTypeHandle(LLVMTypeHandleRef TypeHandle);
331void LLVMDisposeTypeHandle(LLVMTypeHandleRef TypeHandle);
332
Gordon Henriksen76a03742007-09-18 03:18:57 +0000333
334/*===-- Values ------------------------------------------------------------===*/
335
336/* The bulk of LLVM's object model consists of values, which comprise a very
337 * rich type hierarchy.
Gordon Henriksen76a03742007-09-18 03:18:57 +0000338 */
339
Gordon Henriksen29e38942008-12-19 18:39:45 +0000340#define LLVM_FOR_EACH_VALUE_SUBCLASS(macro) \
341 macro(Argument) \
342 macro(BasicBlock) \
343 macro(InlineAsm) \
344 macro(User) \
345 macro(Constant) \
346 macro(ConstantAggregateZero) \
347 macro(ConstantArray) \
348 macro(ConstantExpr) \
349 macro(ConstantFP) \
350 macro(ConstantInt) \
351 macro(ConstantPointerNull) \
352 macro(ConstantStruct) \
353 macro(ConstantVector) \
354 macro(GlobalValue) \
355 macro(Function) \
356 macro(GlobalAlias) \
357 macro(GlobalVariable) \
358 macro(UndefValue) \
359 macro(Instruction) \
360 macro(BinaryOperator) \
361 macro(CallInst) \
362 macro(IntrinsicInst) \
363 macro(DbgInfoIntrinsic) \
364 macro(DbgDeclareInst) \
365 macro(DbgFuncStartInst) \
366 macro(DbgRegionEndInst) \
367 macro(DbgRegionStartInst) \
368 macro(DbgStopPointInst) \
369 macro(EHSelectorInst) \
370 macro(MemIntrinsic) \
371 macro(MemCpyInst) \
372 macro(MemMoveInst) \
373 macro(MemSetInst) \
374 macro(CmpInst) \
375 macro(FCmpInst) \
376 macro(ICmpInst) \
Gordon Henriksen29e38942008-12-19 18:39:45 +0000377 macro(ExtractElementInst) \
378 macro(GetElementPtrInst) \
379 macro(InsertElementInst) \
380 macro(InsertValueInst) \
381 macro(PHINode) \
382 macro(SelectInst) \
383 macro(ShuffleVectorInst) \
384 macro(StoreInst) \
385 macro(TerminatorInst) \
386 macro(BranchInst) \
387 macro(InvokeInst) \
388 macro(ReturnInst) \
389 macro(SwitchInst) \
390 macro(UnreachableInst) \
391 macro(UnwindInst) \
392 macro(UnaryInstruction) \
393 macro(AllocationInst) \
Gordon Henriksen05a868f2008-12-19 18:51:17 +0000394 macro(AllocaInst) \
395 macro(MallocInst) \
Gordon Henriksen29e38942008-12-19 18:39:45 +0000396 macro(CastInst) \
Gordon Henriksen05a868f2008-12-19 18:51:17 +0000397 macro(BitCastInst) \
398 macro(FPExtInst) \
399 macro(FPToSIInst) \
400 macro(FPToUIInst) \
401 macro(FPTruncInst) \
402 macro(IntToPtrInst) \
403 macro(PtrToIntInst) \
404 macro(SExtInst) \
405 macro(SIToFPInst) \
406 macro(TruncInst) \
407 macro(UIToFPInst) \
408 macro(ZExtInst) \
409 macro(ExtractValueInst) \
410 macro(FreeInst) \
411 macro(LoadInst) \
412 macro(VAArgInst)
Gordon Henriksen29e38942008-12-19 18:39:45 +0000413
Gordon Henriksen76a03742007-09-18 03:18:57 +0000414/* Operations on all values */
Gordon Henriksenc23b66c2007-09-26 20:56:12 +0000415LLVMTypeRef LLVMTypeOf(LLVMValueRef Val);
Gordon Henriksen76a03742007-09-18 03:18:57 +0000416const char *LLVMGetValueName(LLVMValueRef Val);
417void LLVMSetValueName(LLVMValueRef Val, const char *Name);
Gordon Henriksen1d0d24c2007-10-06 00:08:49 +0000418void LLVMDumpValue(LLVMValueRef Val);
Gordon Henriksen76a03742007-09-18 03:18:57 +0000419
Gordon Henriksen29e38942008-12-19 18:39:45 +0000420/* Conversion functions. Return the input value if it is an instance of the
421 specified class, otherwise NULL. See llvm::dyn_cast_or_null<>. */
422#define LLVM_DECLARE_VALUE_CAST(name) \
423 LLVMValueRef LLVMIsA##name(LLVMValueRef Val);
424LLVM_FOR_EACH_VALUE_SUBCLASS(LLVM_DECLARE_VALUE_CAST)
425
Gordon Henriksen76a03742007-09-18 03:18:57 +0000426/* Operations on constants of any type */
Gordon Henriksen1046c732007-10-06 15:11:06 +0000427LLVMValueRef LLVMConstNull(LLVMTypeRef Ty); /* all zeroes */
428LLVMValueRef LLVMConstAllOnes(LLVMTypeRef Ty); /* only for int/vector */
Gordon Henriksen76a03742007-09-18 03:18:57 +0000429LLVMValueRef LLVMGetUndef(LLVMTypeRef Ty);
Gordon Henriksendc88c062007-09-18 18:07:51 +0000430int LLVMIsConstant(LLVMValueRef Val);
Gordon Henriksen76a03742007-09-18 03:18:57 +0000431int LLVMIsNull(LLVMValueRef Val);
Gordon Henriksendc88c062007-09-18 18:07:51 +0000432int LLVMIsUndef(LLVMValueRef Val);
Chris Lattner7f318242009-07-06 17:29:59 +0000433LLVMValueRef LLVMConstPointerNull(LLVMTypeRef Ty);
Gordon Henriksen76a03742007-09-18 03:18:57 +0000434
435/* Operations on scalar constants */
Gordon Henriksen1046c732007-10-06 15:11:06 +0000436LLVMValueRef LLVMConstInt(LLVMTypeRef IntTy, unsigned long long N,
437 int SignExtend);
438LLVMValueRef LLVMConstReal(LLVMTypeRef RealTy, double N);
Gordon Henriksen931e1212008-02-02 01:07:50 +0000439LLVMValueRef LLVMConstRealOfString(LLVMTypeRef RealTy, const char *Text);
Gordon Henriksen76a03742007-09-18 03:18:57 +0000440
441/* Operations on composite constants */
Erick Tryzelaar262332f2009-08-14 00:01:31 +0000442LLVMValueRef LLVMConstStringInContext(LLVMContextRef C, const char *Str,
443 unsigned Length, int DontNullTerminate);
444LLVMValueRef LLVMConstStructInContext(LLVMContextRef C,
445 LLVMValueRef *ConstantVals,
446 unsigned Count, int Packed);
447
Gordon Henriksen1046c732007-10-06 15:11:06 +0000448LLVMValueRef LLVMConstString(const char *Str, unsigned Length,
449 int DontNullTerminate);
Gordon Henriksen2ad5aef2008-04-25 03:21:19 +0000450LLVMValueRef LLVMConstArray(LLVMTypeRef ElementTy,
Gordon Henriksen1046c732007-10-06 15:11:06 +0000451 LLVMValueRef *ConstantVals, unsigned Length);
452LLVMValueRef LLVMConstStruct(LLVMValueRef *ConstantVals, unsigned Count,
Erick Tryzelaar262332f2009-08-14 00:01:31 +0000453 int Packed);
Gordon Henriksen1046c732007-10-06 15:11:06 +0000454LLVMValueRef LLVMConstVector(LLVMValueRef *ScalarConstantVals, unsigned Size);
Gordon Henriksen76a03742007-09-18 03:18:57 +0000455
Gordon Henriksen7ce31762007-10-06 14:29:36 +0000456/* Constant expressions */
457LLVMValueRef LLVMSizeOf(LLVMTypeRef Ty);
458LLVMValueRef LLVMConstNeg(LLVMValueRef ConstantVal);
Erick Tryzelaar4cc690c2009-08-16 02:20:12 +0000459LLVMValueRef LLVMConstFNeg(LLVMValueRef ConstantVal);
Gordon Henriksen7ce31762007-10-06 14:29:36 +0000460LLVMValueRef LLVMConstNot(LLVMValueRef ConstantVal);
461LLVMValueRef LLVMConstAdd(LLVMValueRef LHSConstant, LLVMValueRef RHSConstant);
Erick Tryzelaar4cc690c2009-08-16 02:20:12 +0000462LLVMValueRef LLVMConstNSWAdd(LLVMValueRef LHSConstant, LLVMValueRef RHSConstant);
463LLVMValueRef LLVMConstFAdd(LLVMValueRef LHSConstant, LLVMValueRef RHSConstant);
Gordon Henriksen7ce31762007-10-06 14:29:36 +0000464LLVMValueRef LLVMConstSub(LLVMValueRef LHSConstant, LLVMValueRef RHSConstant);
Erick Tryzelaar4cc690c2009-08-16 02:20:12 +0000465LLVMValueRef LLVMConstFSub(LLVMValueRef LHSConstant, LLVMValueRef RHSConstant);
Gordon Henriksen7ce31762007-10-06 14:29:36 +0000466LLVMValueRef LLVMConstMul(LLVMValueRef LHSConstant, LLVMValueRef RHSConstant);
Erick Tryzelaar4cc690c2009-08-16 02:20:12 +0000467LLVMValueRef LLVMConstFMul(LLVMValueRef LHSConstant, LLVMValueRef RHSConstant);
Gordon Henriksen7ce31762007-10-06 14:29:36 +0000468LLVMValueRef LLVMConstUDiv(LLVMValueRef LHSConstant, LLVMValueRef RHSConstant);
469LLVMValueRef LLVMConstSDiv(LLVMValueRef LHSConstant, LLVMValueRef RHSConstant);
Erick Tryzelaar4cc690c2009-08-16 02:20:12 +0000470LLVMValueRef LLVMConstExactSDiv(LLVMValueRef LHSConstant, LLVMValueRef RHSConstant);
Gordon Henriksen7ce31762007-10-06 14:29:36 +0000471LLVMValueRef LLVMConstFDiv(LLVMValueRef LHSConstant, LLVMValueRef RHSConstant);
472LLVMValueRef LLVMConstURem(LLVMValueRef LHSConstant, LLVMValueRef RHSConstant);
473LLVMValueRef LLVMConstSRem(LLVMValueRef LHSConstant, LLVMValueRef RHSConstant);
474LLVMValueRef LLVMConstFRem(LLVMValueRef LHSConstant, LLVMValueRef RHSConstant);
475LLVMValueRef LLVMConstAnd(LLVMValueRef LHSConstant, LLVMValueRef RHSConstant);
476LLVMValueRef LLVMConstOr(LLVMValueRef LHSConstant, LLVMValueRef RHSConstant);
477LLVMValueRef LLVMConstXor(LLVMValueRef LHSConstant, LLVMValueRef RHSConstant);
478LLVMValueRef LLVMConstICmp(LLVMIntPredicate Predicate,
479 LLVMValueRef LHSConstant, LLVMValueRef RHSConstant);
480LLVMValueRef LLVMConstFCmp(LLVMRealPredicate Predicate,
481 LLVMValueRef LHSConstant, LLVMValueRef RHSConstant);
482LLVMValueRef LLVMConstShl(LLVMValueRef LHSConstant, LLVMValueRef RHSConstant);
483LLVMValueRef LLVMConstLShr(LLVMValueRef LHSConstant, LLVMValueRef RHSConstant);
484LLVMValueRef LLVMConstAShr(LLVMValueRef LHSConstant, LLVMValueRef RHSConstant);
485LLVMValueRef LLVMConstGEP(LLVMValueRef ConstantVal,
486 LLVMValueRef *ConstantIndices, unsigned NumIndices);
Erick Tryzelaar4cc690c2009-08-16 02:20:12 +0000487LLVMValueRef LLVMConstInBoundsGEP(LLVMValueRef ConstantVal,
488 LLVMValueRef *ConstantIndices,
489 unsigned NumIndices);
Gordon Henriksen7ce31762007-10-06 14:29:36 +0000490LLVMValueRef LLVMConstTrunc(LLVMValueRef ConstantVal, LLVMTypeRef ToType);
491LLVMValueRef LLVMConstSExt(LLVMValueRef ConstantVal, LLVMTypeRef ToType);
492LLVMValueRef LLVMConstZExt(LLVMValueRef ConstantVal, LLVMTypeRef ToType);
493LLVMValueRef LLVMConstFPTrunc(LLVMValueRef ConstantVal, LLVMTypeRef ToType);
494LLVMValueRef LLVMConstFPExt(LLVMValueRef ConstantVal, LLVMTypeRef ToType);
495LLVMValueRef LLVMConstUIToFP(LLVMValueRef ConstantVal, LLVMTypeRef ToType);
496LLVMValueRef LLVMConstSIToFP(LLVMValueRef ConstantVal, LLVMTypeRef ToType);
497LLVMValueRef LLVMConstFPToUI(LLVMValueRef ConstantVal, LLVMTypeRef ToType);
498LLVMValueRef LLVMConstFPToSI(LLVMValueRef ConstantVal, LLVMTypeRef ToType);
499LLVMValueRef LLVMConstPtrToInt(LLVMValueRef ConstantVal, LLVMTypeRef ToType);
500LLVMValueRef LLVMConstIntToPtr(LLVMValueRef ConstantVal, LLVMTypeRef ToType);
501LLVMValueRef LLVMConstBitCast(LLVMValueRef ConstantVal, LLVMTypeRef ToType);
Erick Tryzelaar4cc690c2009-08-16 02:20:12 +0000502LLVMValueRef LLVMConstZExtOrBitCast(LLVMValueRef ConstantVal,
503 LLVMTypeRef ToType);
504LLVMValueRef LLVMConstSExtOrBitCast(LLVMValueRef ConstantVal,
505 LLVMTypeRef ToType);
506LLVMValueRef LLVMConstTruncOrBitCast(LLVMValueRef ConstantVal,
507 LLVMTypeRef ToType);
508LLVMValueRef LLVMConstPointerCast(LLVMValueRef ConstantVal,
509 LLVMTypeRef ToType);
510LLVMValueRef LLVMConstIntCast(LLVMValueRef ConstantVal, LLVMTypeRef ToType,
511 unsigned isSigned);
512LLVMValueRef LLVMConstFPCast(LLVMValueRef ConstantVal, LLVMTypeRef ToType);
Gordon Henriksen7ce31762007-10-06 14:29:36 +0000513LLVMValueRef LLVMConstSelect(LLVMValueRef ConstantCondition,
514 LLVMValueRef ConstantIfTrue,
515 LLVMValueRef ConstantIfFalse);
516LLVMValueRef LLVMConstExtractElement(LLVMValueRef VectorConstant,
517 LLVMValueRef IndexConstant);
518LLVMValueRef LLVMConstInsertElement(LLVMValueRef VectorConstant,
519 LLVMValueRef ElementValueConstant,
520 LLVMValueRef IndexConstant);
521LLVMValueRef LLVMConstShuffleVector(LLVMValueRef VectorAConstant,
522 LLVMValueRef VectorBConstant,
523 LLVMValueRef MaskConstant);
Dan Gohmand5104a52008-11-03 22:55:43 +0000524LLVMValueRef LLVMConstExtractValue(LLVMValueRef AggConstant, unsigned *IdxList,
525 unsigned NumIdx);
526LLVMValueRef LLVMConstInsertValue(LLVMValueRef AggConstant,
527 LLVMValueRef ElementValueConstant,
528 unsigned *IdxList, unsigned NumIdx);
Chris Lattner3d1f5522008-12-17 21:39:50 +0000529LLVMValueRef LLVMConstInlineAsm(LLVMTypeRef Ty,
530 const char *AsmString, const char *Constraints,
531 int HasSideEffects);
Gordon Henriksen7ce31762007-10-06 14:29:36 +0000532
Gordon Henriksen76a03742007-09-18 03:18:57 +0000533/* Operations on global variables, functions, and aliases (globals) */
Gordon Henriksen265f7802008-03-19 01:11:35 +0000534LLVMModuleRef LLVMGetGlobalParent(LLVMValueRef Global);
Gordon Henriksen76a03742007-09-18 03:18:57 +0000535int LLVMIsDeclaration(LLVMValueRef Global);
536LLVMLinkage LLVMGetLinkage(LLVMValueRef Global);
537void LLVMSetLinkage(LLVMValueRef Global, LLVMLinkage Linkage);
538const char *LLVMGetSection(LLVMValueRef Global);
539void LLVMSetSection(LLVMValueRef Global, const char *Section);
540LLVMVisibility LLVMGetVisibility(LLVMValueRef Global);
541void LLVMSetVisibility(LLVMValueRef Global, LLVMVisibility Viz);
542unsigned LLVMGetAlignment(LLVMValueRef Global);
543void LLVMSetAlignment(LLVMValueRef Global, unsigned Bytes);
544
545/* Operations on global variables */
546LLVMValueRef LLVMAddGlobal(LLVMModuleRef M, LLVMTypeRef Ty, const char *Name);
Gordon Henriksen783f7bb2007-10-08 03:45:09 +0000547LLVMValueRef LLVMGetNamedGlobal(LLVMModuleRef M, const char *Name);
Gordon Henriksen07a45f42008-03-23 22:21:29 +0000548LLVMValueRef LLVMGetFirstGlobal(LLVMModuleRef M);
549LLVMValueRef LLVMGetLastGlobal(LLVMModuleRef M);
550LLVMValueRef LLVMGetNextGlobal(LLVMValueRef GlobalVar);
551LLVMValueRef LLVMGetPreviousGlobal(LLVMValueRef GlobalVar);
Gordon Henriksen76a03742007-09-18 03:18:57 +0000552void LLVMDeleteGlobal(LLVMValueRef GlobalVar);
Gordon Henriksen76a03742007-09-18 03:18:57 +0000553LLVMValueRef LLVMGetInitializer(LLVMValueRef GlobalVar);
554void LLVMSetInitializer(LLVMValueRef GlobalVar, LLVMValueRef ConstantVal);
555int LLVMIsThreadLocal(LLVMValueRef GlobalVar);
556void LLVMSetThreadLocal(LLVMValueRef GlobalVar, int IsThreadLocal);
Gordon Henriksen751ebf72007-10-07 17:31:42 +0000557int LLVMIsGlobalConstant(LLVMValueRef GlobalVar);
558void LLVMSetGlobalConstant(LLVMValueRef GlobalVar, int IsConstant);
Gordon Henriksen76a03742007-09-18 03:18:57 +0000559
Chris Lattner3d1f5522008-12-17 21:39:50 +0000560/* Operations on aliases */
561LLVMValueRef LLVMAddAlias(LLVMModuleRef M, LLVMTypeRef Ty, LLVMValueRef Aliasee,
562 const char *Name);
563
Gordon Henriksenc23b66c2007-09-26 20:56:12 +0000564/* Operations on functions */
565LLVMValueRef LLVMAddFunction(LLVMModuleRef M, const char *Name,
566 LLVMTypeRef FunctionTy);
Gordon Henriksen783f7bb2007-10-08 03:45:09 +0000567LLVMValueRef LLVMGetNamedFunction(LLVMModuleRef M, const char *Name);
Gordon Henriksen054817c2008-03-19 03:47:18 +0000568LLVMValueRef LLVMGetFirstFunction(LLVMModuleRef M);
569LLVMValueRef LLVMGetLastFunction(LLVMModuleRef M);
570LLVMValueRef LLVMGetNextFunction(LLVMValueRef Fn);
571LLVMValueRef LLVMGetPreviousFunction(LLVMValueRef Fn);
Gordon Henriksenc23b66c2007-09-26 20:56:12 +0000572void LLVMDeleteFunction(LLVMValueRef Fn);
Gordon Henriksenc23b66c2007-09-26 20:56:12 +0000573unsigned LLVMGetIntrinsicID(LLVMValueRef Fn);
574unsigned LLVMGetFunctionCallConv(LLVMValueRef Fn);
575void LLVMSetFunctionCallConv(LLVMValueRef Fn, unsigned CC);
Gordon Henriksend930f912008-08-17 18:44:35 +0000576const char *LLVMGetGC(LLVMValueRef Fn);
577void LLVMSetGC(LLVMValueRef Fn, const char *Name);
Duncan Sands7374a012009-05-06 12:21:17 +0000578void LLVMAddFunctionAttr(LLVMValueRef Fn, LLVMAttribute PA);
579void LLVMRemoveFunctionAttr(LLVMValueRef Fn, LLVMAttribute PA);
Gordon Henriksenc23b66c2007-09-26 20:56:12 +0000580
Gordon Henriksen265f7802008-03-19 01:11:35 +0000581/* Operations on parameters */
582unsigned LLVMCountParams(LLVMValueRef Fn);
583void LLVMGetParams(LLVMValueRef Fn, LLVMValueRef *Params);
584LLVMValueRef LLVMGetParam(LLVMValueRef Fn, unsigned Index);
585LLVMValueRef LLVMGetParamParent(LLVMValueRef Inst);
Gordon Henriksen07a45f42008-03-23 22:21:29 +0000586LLVMValueRef LLVMGetFirstParam(LLVMValueRef Fn);
587LLVMValueRef LLVMGetLastParam(LLVMValueRef Fn);
588LLVMValueRef LLVMGetNextParam(LLVMValueRef Arg);
589LLVMValueRef LLVMGetPreviousParam(LLVMValueRef Arg);
Devang Patel4c758ea2008-09-25 21:00:45 +0000590void LLVMAddAttribute(LLVMValueRef Arg, LLVMAttribute PA);
591void LLVMRemoveAttribute(LLVMValueRef Arg, LLVMAttribute PA);
Gordon Henriksen2d9cc212008-04-28 17:37:06 +0000592void LLVMSetParamAlignment(LLVMValueRef Arg, unsigned align);
Gordon Henriksen265f7802008-03-19 01:11:35 +0000593
Gordon Henriksenc23b66c2007-09-26 20:56:12 +0000594/* Operations on basic blocks */
Gordon Henriksen07a45f42008-03-23 22:21:29 +0000595LLVMValueRef LLVMBasicBlockAsValue(LLVMBasicBlockRef BB);
Gordon Henriksenc23b66c2007-09-26 20:56:12 +0000596int LLVMValueIsBasicBlock(LLVMValueRef Val);
597LLVMBasicBlockRef LLVMValueAsBasicBlock(LLVMValueRef Val);
Gordon Henriksen07a45f42008-03-23 22:21:29 +0000598LLVMValueRef LLVMGetBasicBlockParent(LLVMBasicBlockRef BB);
Gordon Henriksenc23b66c2007-09-26 20:56:12 +0000599unsigned LLVMCountBasicBlocks(LLVMValueRef Fn);
600void LLVMGetBasicBlocks(LLVMValueRef Fn, LLVMBasicBlockRef *BasicBlocks);
Gordon Henriksen054817c2008-03-19 03:47:18 +0000601LLVMBasicBlockRef LLVMGetFirstBasicBlock(LLVMValueRef Fn);
602LLVMBasicBlockRef LLVMGetLastBasicBlock(LLVMValueRef Fn);
603LLVMBasicBlockRef LLVMGetNextBasicBlock(LLVMBasicBlockRef BB);
604LLVMBasicBlockRef LLVMGetPreviousBasicBlock(LLVMBasicBlockRef BB);
Gordon Henriksenc23b66c2007-09-26 20:56:12 +0000605LLVMBasicBlockRef LLVMGetEntryBasicBlock(LLVMValueRef Fn);
Erick Tryzelaar262332f2009-08-14 00:01:31 +0000606
607LLVMBasicBlockRef LLVMAppendBasicBlockInContext(LLVMContextRef C,
608 LLVMValueRef Fn,
609 const char *Name);
610LLVMBasicBlockRef LLVMInsertBasicBlockInContext(LLVMContextRef C,
611 LLVMBasicBlockRef BB,
612 const char *Name);
613
Gordon Henriksenc23b66c2007-09-26 20:56:12 +0000614LLVMBasicBlockRef LLVMAppendBasicBlock(LLVMValueRef Fn, const char *Name);
615LLVMBasicBlockRef LLVMInsertBasicBlock(LLVMBasicBlockRef InsertBeforeBB,
616 const char *Name);
617void LLVMDeleteBasicBlock(LLVMBasicBlockRef BB);
618
Gordon Henriksen265f7802008-03-19 01:11:35 +0000619/* Operations on instructions */
620LLVMBasicBlockRef LLVMGetInstructionParent(LLVMValueRef Inst);
Gordon Henriksen054817c2008-03-19 03:47:18 +0000621LLVMValueRef LLVMGetFirstInstruction(LLVMBasicBlockRef BB);
622LLVMValueRef LLVMGetLastInstruction(LLVMBasicBlockRef BB);
623LLVMValueRef LLVMGetNextInstruction(LLVMValueRef Inst);
624LLVMValueRef LLVMGetPreviousInstruction(LLVMValueRef Inst);
Gordon Henriksen265f7802008-03-19 01:11:35 +0000625
Gordon Henriksen1158c532007-12-29 20:45:00 +0000626/* Operations on call sites */
627void LLVMSetInstructionCallConv(LLVMValueRef Instr, unsigned CC);
628unsigned LLVMGetInstructionCallConv(LLVMValueRef Instr);
Devang Patel4c758ea2008-09-25 21:00:45 +0000629void LLVMAddInstrAttribute(LLVMValueRef Instr, unsigned index, LLVMAttribute);
630void LLVMRemoveInstrAttribute(LLVMValueRef Instr, unsigned index,
631 LLVMAttribute);
Gordon Henriksen2d9cc212008-04-28 17:37:06 +0000632void LLVMSetInstrParamAlignment(LLVMValueRef Instr, unsigned index,
633 unsigned align);
Gordon Henriksen1158c532007-12-29 20:45:00 +0000634
Gordon Henrikseneeb65372008-08-30 16:34:54 +0000635/* Operations on call instructions (only) */
636int LLVMIsTailCall(LLVMValueRef CallInst);
637void LLVMSetTailCall(LLVMValueRef CallInst, int IsTailCall);
638
Gordon Henriksen44dd8fb2007-10-08 18:14:39 +0000639/* Operations on phi nodes */
640void LLVMAddIncoming(LLVMValueRef PhiNode, LLVMValueRef *IncomingValues,
641 LLVMBasicBlockRef *IncomingBlocks, unsigned Count);
642unsigned LLVMCountIncoming(LLVMValueRef PhiNode);
643LLVMValueRef LLVMGetIncomingValue(LLVMValueRef PhiNode, unsigned Index);
644LLVMBasicBlockRef LLVMGetIncomingBlock(LLVMValueRef PhiNode, unsigned Index);
Gordon Henriksenc23b66c2007-09-26 20:56:12 +0000645
646/*===-- Instruction builders ----------------------------------------------===*/
647
648/* An instruction builder represents a point within a basic block, and is the
649 * exclusive means of building instructions using the C interface.
650 */
651
Erick Tryzelaar262332f2009-08-14 00:01:31 +0000652LLVMBuilderRef LLVMCreateBuilderInContext(LLVMContextRef C);
Gordon Henriksena735a9c2008-05-04 12:55:34 +0000653LLVMBuilderRef LLVMCreateBuilder(void);
Gordon Henriksen054817c2008-03-19 03:47:18 +0000654void LLVMPositionBuilder(LLVMBuilderRef Builder, LLVMBasicBlockRef Block,
655 LLVMValueRef Instr);
Gordon Henriksenc23b66c2007-09-26 20:56:12 +0000656void LLVMPositionBuilderBefore(LLVMBuilderRef Builder, LLVMValueRef Instr);
657void LLVMPositionBuilderAtEnd(LLVMBuilderRef Builder, LLVMBasicBlockRef Block);
Gordon Henriksen265f7802008-03-19 01:11:35 +0000658LLVMBasicBlockRef LLVMGetInsertBlock(LLVMBuilderRef Builder);
Chris Lattner3d1f5522008-12-17 21:39:50 +0000659void LLVMClearInsertionPosition(LLVMBuilderRef Builder);
660void LLVMInsertIntoBuilder(LLVMBuilderRef Builder, LLVMValueRef Instr);
Erick Tryzelaar9813bea2009-08-16 02:20:57 +0000661void LLVMInsertIntoBuilderWithName(LLVMBuilderRef Builder, LLVMValueRef Instr,
662 const char *Name);
Gordon Henriksenc23b66c2007-09-26 20:56:12 +0000663void LLVMDisposeBuilder(LLVMBuilderRef Builder);
664
665/* Terminators */
666LLVMValueRef LLVMBuildRetVoid(LLVMBuilderRef);
667LLVMValueRef LLVMBuildRet(LLVMBuilderRef, LLVMValueRef V);
Erick Tryzelaar3045b8b2009-08-16 02:19:59 +0000668LLVMValueRef LLVMBuildAggregateRet(LLVMBuilderRef, LLVMValueRef RetVals,
669 unsigned N);
Gordon Henriksenc23b66c2007-09-26 20:56:12 +0000670LLVMValueRef LLVMBuildBr(LLVMBuilderRef, LLVMBasicBlockRef Dest);
671LLVMValueRef LLVMBuildCondBr(LLVMBuilderRef, LLVMValueRef If,
672 LLVMBasicBlockRef Then, LLVMBasicBlockRef Else);
673LLVMValueRef LLVMBuildSwitch(LLVMBuilderRef, LLVMValueRef V,
674 LLVMBasicBlockRef Else, unsigned NumCases);
675LLVMValueRef LLVMBuildInvoke(LLVMBuilderRef, LLVMValueRef Fn,
676 LLVMValueRef *Args, unsigned NumArgs,
677 LLVMBasicBlockRef Then, LLVMBasicBlockRef Catch,
678 const char *Name);
679LLVMValueRef LLVMBuildUnwind(LLVMBuilderRef);
680LLVMValueRef LLVMBuildUnreachable(LLVMBuilderRef);
681
Gordon Henriksen097102c2008-01-01 05:50:53 +0000682/* Add a case to the switch instruction */
683void LLVMAddCase(LLVMValueRef Switch, LLVMValueRef OnVal,
684 LLVMBasicBlockRef Dest);
685
Gordon Henriksenc23b66c2007-09-26 20:56:12 +0000686/* Arithmetic */
687LLVMValueRef LLVMBuildAdd(LLVMBuilderRef, LLVMValueRef LHS, LLVMValueRef RHS,
688 const char *Name);
Erick Tryzelaar3045b8b2009-08-16 02:19:59 +0000689LLVMValueRef LLVMBuildNSWAdd(LLVMBuilderRef, LLVMValueRef LHS, LLVMValueRef RHS,
690 const char *Name);
691LLVMValueRef LLVMBuildFAdd(LLVMBuilderRef, LLVMValueRef LHS, LLVMValueRef RHS,
692 const char *Name);
Gordon Henriksenc23b66c2007-09-26 20:56:12 +0000693LLVMValueRef LLVMBuildSub(LLVMBuilderRef, LLVMValueRef LHS, LLVMValueRef RHS,
694 const char *Name);
Erick Tryzelaar3045b8b2009-08-16 02:19:59 +0000695LLVMValueRef LLVMBuildFSub(LLVMBuilderRef, LLVMValueRef LHS, LLVMValueRef RHS,
696 const char *Name);
Gordon Henriksenc23b66c2007-09-26 20:56:12 +0000697LLVMValueRef LLVMBuildMul(LLVMBuilderRef, LLVMValueRef LHS, LLVMValueRef RHS,
698 const char *Name);
Erick Tryzelaar3045b8b2009-08-16 02:19:59 +0000699LLVMValueRef LLVMBuildFMul(LLVMBuilderRef, LLVMValueRef LHS, LLVMValueRef RHS,
700 const char *Name);
Gordon Henriksenc23b66c2007-09-26 20:56:12 +0000701LLVMValueRef LLVMBuildUDiv(LLVMBuilderRef, LLVMValueRef LHS, LLVMValueRef RHS,
702 const char *Name);
703LLVMValueRef LLVMBuildSDiv(LLVMBuilderRef, LLVMValueRef LHS, LLVMValueRef RHS,
704 const char *Name);
Erick Tryzelaar3045b8b2009-08-16 02:19:59 +0000705LLVMValueRef LLVMBuildExactSDiv(LLVMBuilderRef, LLVMValueRef LHS, LLVMValueRef RHS,
706 const char *Name);
Gordon Henriksenc23b66c2007-09-26 20:56:12 +0000707LLVMValueRef LLVMBuildFDiv(LLVMBuilderRef, LLVMValueRef LHS, LLVMValueRef RHS,
708 const char *Name);
709LLVMValueRef LLVMBuildURem(LLVMBuilderRef, LLVMValueRef LHS, LLVMValueRef RHS,
710 const char *Name);
711LLVMValueRef LLVMBuildSRem(LLVMBuilderRef, LLVMValueRef LHS, LLVMValueRef RHS,
712 const char *Name);
713LLVMValueRef LLVMBuildFRem(LLVMBuilderRef, LLVMValueRef LHS, LLVMValueRef RHS,
714 const char *Name);
715LLVMValueRef LLVMBuildShl(LLVMBuilderRef, LLVMValueRef LHS, LLVMValueRef RHS,
716 const char *Name);
717LLVMValueRef LLVMBuildLShr(LLVMBuilderRef, LLVMValueRef LHS, LLVMValueRef RHS,
718 const char *Name);
719LLVMValueRef LLVMBuildAShr(LLVMBuilderRef, LLVMValueRef LHS, LLVMValueRef RHS,
720 const char *Name);
721LLVMValueRef LLVMBuildAnd(LLVMBuilderRef, LLVMValueRef LHS, LLVMValueRef RHS,
722 const char *Name);
723LLVMValueRef LLVMBuildOr(LLVMBuilderRef, LLVMValueRef LHS, LLVMValueRef RHS,
724 const char *Name);
725LLVMValueRef LLVMBuildXor(LLVMBuilderRef, LLVMValueRef LHS, LLVMValueRef RHS,
726 const char *Name);
727LLVMValueRef LLVMBuildNeg(LLVMBuilderRef, LLVMValueRef V, const char *Name);
728LLVMValueRef LLVMBuildNot(LLVMBuilderRef, LLVMValueRef V, const char *Name);
729
730/* Memory */
731LLVMValueRef LLVMBuildMalloc(LLVMBuilderRef, LLVMTypeRef Ty, const char *Name);
732LLVMValueRef LLVMBuildArrayMalloc(LLVMBuilderRef, LLVMTypeRef Ty,
733 LLVMValueRef Val, const char *Name);
734LLVMValueRef LLVMBuildAlloca(LLVMBuilderRef, LLVMTypeRef Ty, const char *Name);
735LLVMValueRef LLVMBuildArrayAlloca(LLVMBuilderRef, LLVMTypeRef Ty,
736 LLVMValueRef Val, const char *Name);
737LLVMValueRef LLVMBuildFree(LLVMBuilderRef, LLVMValueRef PointerVal);
738LLVMValueRef LLVMBuildLoad(LLVMBuilderRef, LLVMValueRef PointerVal,
739 const char *Name);
740LLVMValueRef LLVMBuildStore(LLVMBuilderRef, LLVMValueRef Val, LLVMValueRef Ptr);
741LLVMValueRef LLVMBuildGEP(LLVMBuilderRef B, LLVMValueRef Pointer,
742 LLVMValueRef *Indices, unsigned NumIndices,
743 const char *Name);
Erick Tryzelaar3045b8b2009-08-16 02:19:59 +0000744LLVMValueRef LLVMBuildInBoundsGEP(LLVMBuilderRef B, LLVMValueRef Pointer,
745 LLVMValueRef *Indices, unsigned NumIndices,
746 const char *Name);
747LLVMValueRef LLVMBuildStructGEP(LLVMBuilderRef B, LLVMValueRef Pointer,
748 unsigned Idx, const char *Name);
749LLVMValueRef LLVMBuildGlobalString(LLVMBuilderRef B, const char *Str,
750 const char *Name);
751LLVMValueRef LLVMBuildGlobalStringPtr(LLVMBuilderRef B, const char *Str,
752 const char *Name);
Gordon Henriksenc23b66c2007-09-26 20:56:12 +0000753
754/* Casts */
755LLVMValueRef LLVMBuildTrunc(LLVMBuilderRef, LLVMValueRef Val,
756 LLVMTypeRef DestTy, const char *Name);
757LLVMValueRef LLVMBuildZExt(LLVMBuilderRef, LLVMValueRef Val,
758 LLVMTypeRef DestTy, const char *Name);
759LLVMValueRef LLVMBuildSExt(LLVMBuilderRef, LLVMValueRef Val,
760 LLVMTypeRef DestTy, const char *Name);
761LLVMValueRef LLVMBuildFPToUI(LLVMBuilderRef, LLVMValueRef Val,
762 LLVMTypeRef DestTy, const char *Name);
763LLVMValueRef LLVMBuildFPToSI(LLVMBuilderRef, LLVMValueRef Val,
764 LLVMTypeRef DestTy, const char *Name);
765LLVMValueRef LLVMBuildUIToFP(LLVMBuilderRef, LLVMValueRef Val,
766 LLVMTypeRef DestTy, const char *Name);
767LLVMValueRef LLVMBuildSIToFP(LLVMBuilderRef, LLVMValueRef Val,
768 LLVMTypeRef DestTy, const char *Name);
769LLVMValueRef LLVMBuildFPTrunc(LLVMBuilderRef, LLVMValueRef Val,
770 LLVMTypeRef DestTy, const char *Name);
771LLVMValueRef LLVMBuildFPExt(LLVMBuilderRef, LLVMValueRef Val,
772 LLVMTypeRef DestTy, const char *Name);
773LLVMValueRef LLVMBuildPtrToInt(LLVMBuilderRef, LLVMValueRef Val,
774 LLVMTypeRef DestTy, const char *Name);
775LLVMValueRef LLVMBuildIntToPtr(LLVMBuilderRef, LLVMValueRef Val,
776 LLVMTypeRef DestTy, const char *Name);
777LLVMValueRef LLVMBuildBitCast(LLVMBuilderRef, LLVMValueRef Val,
778 LLVMTypeRef DestTy, const char *Name);
Erick Tryzelaar3045b8b2009-08-16 02:19:59 +0000779LLVMValueRef LLVMBuildZExtOrBitCast(LLVMBuilderRef, LLVMValueRef Val,
780 LLVMTypeRef DestTy, const char *Name);
781LLVMValueRef LLVMBuildSExtOrBitCast(LLVMBuilderRef, LLVMValueRef Val,
782 LLVMTypeRef DestTy, const char *Name);
783LLVMValueRef LLVMBuildTruncOrBitCast(LLVMBuilderRef, LLVMValueRef Val,
784 LLVMTypeRef DestTy, const char *Name);
785LLVMValueRef LLVMBuildPointerCast(LLVMBuilderRef, LLVMValueRef Val,
786 LLVMTypeRef DestTy, const char *Name);
787LLVMValueRef LLVMBuildIntCast(LLVMBuilderRef, LLVMValueRef Val,
788 LLVMTypeRef DestTy, const char *Name);
789LLVMValueRef LLVMBuildFPCast(LLVMBuilderRef, LLVMValueRef Val,
790 LLVMTypeRef DestTy, const char *Name);
Gordon Henriksenc23b66c2007-09-26 20:56:12 +0000791
792/* Comparisons */
793LLVMValueRef LLVMBuildICmp(LLVMBuilderRef, LLVMIntPredicate Op,
794 LLVMValueRef LHS, LLVMValueRef RHS,
795 const char *Name);
796LLVMValueRef LLVMBuildFCmp(LLVMBuilderRef, LLVMRealPredicate Op,
797 LLVMValueRef LHS, LLVMValueRef RHS,
798 const char *Name);
799
800/* Miscellaneous instructions */
801LLVMValueRef LLVMBuildPhi(LLVMBuilderRef, LLVMTypeRef Ty, const char *Name);
802LLVMValueRef LLVMBuildCall(LLVMBuilderRef, LLVMValueRef Fn,
803 LLVMValueRef *Args, unsigned NumArgs,
804 const char *Name);
805LLVMValueRef LLVMBuildSelect(LLVMBuilderRef, LLVMValueRef If,
806 LLVMValueRef Then, LLVMValueRef Else,
807 const char *Name);
808LLVMValueRef LLVMBuildVAArg(LLVMBuilderRef, LLVMValueRef List, LLVMTypeRef Ty,
809 const char *Name);
810LLVMValueRef LLVMBuildExtractElement(LLVMBuilderRef, LLVMValueRef VecVal,
811 LLVMValueRef Index, const char *Name);
812LLVMValueRef LLVMBuildInsertElement(LLVMBuilderRef, LLVMValueRef VecVal,
813 LLVMValueRef EltVal, LLVMValueRef Index,
814 const char *Name);
815LLVMValueRef LLVMBuildShuffleVector(LLVMBuilderRef, LLVMValueRef V1,
816 LLVMValueRef V2, LLVMValueRef Mask,
817 const char *Name);
Dan Gohmand5104a52008-11-03 22:55:43 +0000818LLVMValueRef LLVMBuildExtractValue(LLVMBuilderRef, LLVMValueRef AggVal,
819 unsigned Index, const char *Name);
820LLVMValueRef LLVMBuildInsertValue(LLVMBuilderRef, LLVMValueRef AggVal,
821 LLVMValueRef EltVal, unsigned Index,
822 const char *Name);
Gordon Henriksen76a03742007-09-18 03:18:57 +0000823
Erick Tryzelaar3045b8b2009-08-16 02:19:59 +0000824LLVMValueRef LLVMBuildIsNull(LLVMBuilderRef, LLVMValueRef Val,
825 const char *Name);
826LLVMValueRef LLVMBuildIsNotNull(LLVMBuilderRef, LLVMValueRef Val,
827 const char *Name);
828LLVMValueRef LLVMBuildPtrDiff(LLVMBuilderRef, LLVMValueRef LHS,
829 LLVMValueRef RHS, const char *Name);
830
Gordon Henriksen34eb6d82007-12-19 22:30:40 +0000831
Gordon Henriksen0a68fe22007-12-12 01:04:30 +0000832/*===-- Module providers --------------------------------------------------===*/
833
834/* Encapsulates the module M in a module provider, taking ownership of the
835 * module.
836 * See the constructor llvm::ExistingModuleProvider::ExistingModuleProvider.
837 */
838LLVMModuleProviderRef
839LLVMCreateModuleProviderForExistingModule(LLVMModuleRef M);
840
841/* Destroys the module provider MP as well as the contained module.
842 * See the destructor llvm::ModuleProvider::~ModuleProvider.
843 */
844void LLVMDisposeModuleProvider(LLVMModuleProviderRef MP);
845
Gordon Henriksen34eb6d82007-12-19 22:30:40 +0000846
847/*===-- Memory buffers ----------------------------------------------------===*/
848
849int LLVMCreateMemoryBufferWithContentsOfFile(const char *Path,
850 LLVMMemoryBufferRef *OutMemBuf,
851 char **OutMessage);
852int LLVMCreateMemoryBufferWithSTDIN(LLVMMemoryBufferRef *OutMemBuf,
853 char **OutMessage);
854void LLVMDisposeMemoryBuffer(LLVMMemoryBufferRef MemBuf);
855
Gordon Henriksen878114b2008-03-16 04:20:44 +0000856
857/*===-- Pass Managers -----------------------------------------------------===*/
858
859/** Constructs a new whole-module pass pipeline. This type of pipeline is
860 suitable for link-time optimization and whole-module transformations.
861 See llvm::PassManager::PassManager. */
Gordon Henriksena735a9c2008-05-04 12:55:34 +0000862LLVMPassManagerRef LLVMCreatePassManager(void);
Gordon Henriksen878114b2008-03-16 04:20:44 +0000863
864/** Constructs a new function-by-function pass pipeline over the module
865 provider. It does not take ownership of the module provider. This type of
866 pipeline is suitable for code generation and JIT compilation tasks.
867 See llvm::FunctionPassManager::FunctionPassManager. */
868LLVMPassManagerRef LLVMCreateFunctionPassManager(LLVMModuleProviderRef MP);
869
870/** Initializes, executes on the provided module, and finalizes all of the
871 passes scheduled in the pass manager. Returns 1 if any of the passes
872 modified the module, 0 otherwise. See llvm::PassManager::run(Module&). */
873int LLVMRunPassManager(LLVMPassManagerRef PM, LLVMModuleRef M);
874
875/** Initializes all of the function passes scheduled in the function pass
876 manager. Returns 1 if any of the passes modified the module, 0 otherwise.
877 See llvm::FunctionPassManager::doInitialization. */
878int LLVMInitializeFunctionPassManager(LLVMPassManagerRef FPM);
879
880/** Executes all of the function passes scheduled in the function pass manager
881 on the provided function. Returns 1 if any of the passes modified the
882 function, false otherwise.
883 See llvm::FunctionPassManager::run(Function&). */
884int LLVMRunFunctionPassManager(LLVMPassManagerRef FPM, LLVMValueRef F);
885
886/** Finalizes all of the function passes scheduled in in the function pass
887 manager. Returns 1 if any of the passes modified the module, 0 otherwise.
888 See llvm::FunctionPassManager::doFinalization. */
889int LLVMFinalizeFunctionPassManager(LLVMPassManagerRef FPM);
890
891/** Frees the memory of a pass pipeline. For function pipelines, does not free
892 the module provider.
893 See llvm::PassManagerBase::~PassManagerBase. */
894void LLVMDisposePassManager(LLVMPassManagerRef PM);
895
896
Gordon Henriksen76a03742007-09-18 03:18:57 +0000897#ifdef __cplusplus
898}
Gordon Henriksen76a03742007-09-18 03:18:57 +0000899
Gordon Henriksen7330acd2007-10-05 23:59:36 +0000900namespace llvm {
Gordon Henriksen0a68fe22007-12-12 01:04:30 +0000901 class ModuleProvider;
Gordon Henriksen34eb6d82007-12-19 22:30:40 +0000902 class MemoryBuffer;
Gordon Henriksen96571492008-03-16 15:55:43 +0000903 class PassManagerBase;
Gordon Henriksen0a68fe22007-12-12 01:04:30 +0000904
Gordon Henriksen34eb6d82007-12-19 22:30:40 +0000905 #define DEFINE_SIMPLE_CONVERSION_FUNCTIONS(ty, ref) \
906 inline ty *unwrap(ref P) { \
907 return reinterpret_cast<ty*>(P); \
908 } \
909 \
910 inline ref wrap(const ty *P) { \
911 return reinterpret_cast<ref>(const_cast<ty*>(P)); \
912 }
Gordon Henriksen7330acd2007-10-05 23:59:36 +0000913
Gordon Henriksen878114b2008-03-16 04:20:44 +0000914 #define DEFINE_ISA_CONVERSION_FUNCTIONS(ty, ref) \
915 DEFINE_SIMPLE_CONVERSION_FUNCTIONS(ty, ref) \
916 \
917 template<typename T> \
918 inline T *unwrap(ref P) { \
919 return cast<T>(unwrap(P)); \
920 }
921
922 #define DEFINE_STDCXX_CONVERSION_FUNCTIONS(ty, ref) \
923 DEFINE_SIMPLE_CONVERSION_FUNCTIONS(ty, ref) \
924 \
925 template<typename T> \
926 inline T *unwrap(ref P) { \
927 T *Q = dynamic_cast<T*>(unwrap(P)); \
928 assert(Q && "Invalid cast!"); \
929 return Q; \
930 }
931
932 DEFINE_ISA_CONVERSION_FUNCTIONS (Type, LLVMTypeRef )
933 DEFINE_ISA_CONVERSION_FUNCTIONS (Value, LLVMValueRef )
Gordon Henriksen823f9732007-12-27 18:25:59 +0000934 DEFINE_SIMPLE_CONVERSION_FUNCTIONS(Module, LLVMModuleRef )
935 DEFINE_SIMPLE_CONVERSION_FUNCTIONS(BasicBlock, LLVMBasicBlockRef )
Eric Christopher59278832008-08-08 19:39:37 +0000936 DEFINE_SIMPLE_CONVERSION_FUNCTIONS(IRBuilder<>, LLVMBuilderRef )
Gordon Henriksen823f9732007-12-27 18:25:59 +0000937 DEFINE_SIMPLE_CONVERSION_FUNCTIONS(PATypeHolder, LLVMTypeHandleRef )
938 DEFINE_SIMPLE_CONVERSION_FUNCTIONS(ModuleProvider, LLVMModuleProviderRef)
939 DEFINE_SIMPLE_CONVERSION_FUNCTIONS(MemoryBuffer, LLVMMemoryBufferRef )
Owen Anderson6773d382009-07-01 16:58:40 +0000940 DEFINE_SIMPLE_CONVERSION_FUNCTIONS(LLVMContext, LLVMContextRef )
Gordon Henriksen878114b2008-03-16 04:20:44 +0000941 DEFINE_STDCXX_CONVERSION_FUNCTIONS(PassManagerBase, LLVMPassManagerRef )
Gordon Henriksen7330acd2007-10-05 23:59:36 +0000942
Gordon Henriksen878114b2008-03-16 04:20:44 +0000943 #undef DEFINE_STDCXX_CONVERSION_FUNCTIONS
944 #undef DEFINE_ISA_CONVERSION_FUNCTIONS
Gordon Henriksen34eb6d82007-12-19 22:30:40 +0000945 #undef DEFINE_SIMPLE_CONVERSION_FUNCTIONS
Erick Tryzelaar262332f2009-08-14 00:01:31 +0000946
947 /* Specialized opaque context conversions.
948 */
949 inline LLVMContext **unwrap(LLVMContextRef* Tys) {
950 return reinterpret_cast<LLVMContext**>(Tys);
951 }
952
953 inline LLVMContextRef *wrap(const LLVMContext **Tys) {
954 return reinterpret_cast<LLVMContextRef*>(const_cast<LLVMContext**>(Tys));
955 }
Gordon Henriksen7330acd2007-10-05 23:59:36 +0000956
Gordon Henriksen34eb6d82007-12-19 22:30:40 +0000957 /* Specialized opaque type conversions.
958 */
Gordon Henriksen7330acd2007-10-05 23:59:36 +0000959 inline Type **unwrap(LLVMTypeRef* Tys) {
960 return reinterpret_cast<Type**>(Tys);
961 }
962
Gordon Henriksen7330acd2007-10-05 23:59:36 +0000963 inline LLVMTypeRef *wrap(const Type **Tys) {
964 return reinterpret_cast<LLVMTypeRef*>(const_cast<Type**>(Tys));
965 }
966
Gordon Henriksen34eb6d82007-12-19 22:30:40 +0000967 /* Specialized opaque value conversions.
Gordon Henriksen7330acd2007-10-05 23:59:36 +0000968 */
Gordon Henriksen7330acd2007-10-05 23:59:36 +0000969 inline Value **unwrap(LLVMValueRef *Vals) {
970 return reinterpret_cast<Value**>(Vals);
971 }
972
973 template<typename T>
974 inline T **unwrap(LLVMValueRef *Vals, unsigned Length) {
975 #if DEBUG
Chris Lattnerb7971152009-07-10 18:28:19 +0000976 for (LLVMValueRef *I = Vals, *E = Vals + Length; I != E; ++I)
Gordon Henriksen7330acd2007-10-05 23:59:36 +0000977 cast<T>(*I);
978 #endif
979 return reinterpret_cast<T**>(Vals);
980 }
981
Gordon Henriksen7330acd2007-10-05 23:59:36 +0000982 inline LLVMValueRef *wrap(const Value **Vals) {
983 return reinterpret_cast<LLVMValueRef*>(const_cast<Value**>(Vals));
984 }
Gordon Henriksen7330acd2007-10-05 23:59:36 +0000985}
986
987#endif /* !defined(__cplusplus) */
988
989#endif /* !defined(LLVM_C_CORE_H) */