blob: b0a9800ce297560b83d8ce1e892f36d1169d1300 [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
Erick Tryzelaardd991352009-08-16 23:36:46 +000036#include "llvm/Support/DataTypes.h"
37
Gordon Henriksen76a03742007-09-18 03:18:57 +000038#ifdef __cplusplus
Gordon Henriksen7330acd2007-10-05 23:59:36 +000039
40/* Need these includes to support the LLVM 'cast' template for the C++ 'wrap'
41 and 'unwrap' conversion functions. */
42#include "llvm/Module.h"
Duncan Sandsa07136e2008-04-13 06:22:09 +000043#include "llvm/Support/IRBuilder.h"
Gordon Henriksen7330acd2007-10-05 23:59:36 +000044
Gordon Henriksen76a03742007-09-18 03:18:57 +000045extern "C" {
46#endif
47
48
49/* Opaque types. */
Gordon Henriksen4a4d7352007-12-30 17:46:33 +000050
51/**
Owen Anderson6773d382009-07-01 16:58:40 +000052 * The top-level container for all LLVM global data. See the LLVMContext class.
53 */
Erick Tryzelaar262332f2009-08-14 00:01:31 +000054typedef struct LLVMOpaqueContext *LLVMContextRef;
Owen Anderson6773d382009-07-01 16:58:40 +000055
56/**
Gordon Henriksen4a4d7352007-12-30 17:46:33 +000057 * The top-level container for all other LLVM Intermediate Representation (IR)
58 * objects. See the llvm::Module class.
59 */
Gordon Henriksen76a03742007-09-18 03:18:57 +000060typedef struct LLVMOpaqueModule *LLVMModuleRef;
Gordon Henriksen4a4d7352007-12-30 17:46:33 +000061
62/**
Gordon Henriksena49d4352008-03-07 19:13:06 +000063 * Each value in the LLVM IR has a type, an LLVMTypeRef. See the llvm::Type
64 * class.
Gordon Henriksen4a4d7352007-12-30 17:46:33 +000065 */
Gordon Henriksen76a03742007-09-18 03:18:57 +000066typedef struct LLVMOpaqueType *LLVMTypeRef;
Gordon Henriksen4a4d7352007-12-30 17:46:33 +000067
68/**
Gordon Henriksena49d4352008-03-07 19:13:06 +000069 * When building recursive types using LLVMRefineType, LLVMTypeRef values may
70 * become invalid; use LLVMTypeHandleRef to resolve this problem. See the
71 * llvm::AbstractTypeHolder class.
Gordon Henriksen4a4d7352007-12-30 17:46:33 +000072 */
Gordon Henriksenffb48762007-10-07 00:13:35 +000073typedef struct LLVMOpaqueTypeHandle *LLVMTypeHandleRef;
Gordon Henriksen4a4d7352007-12-30 17:46:33 +000074
Gordon Henriksen76a03742007-09-18 03:18:57 +000075typedef struct LLVMOpaqueValue *LLVMValueRef;
Gordon Henriksenc23b66c2007-09-26 20:56:12 +000076typedef struct LLVMOpaqueBasicBlock *LLVMBasicBlockRef;
77typedef struct LLVMOpaqueBuilder *LLVMBuilderRef;
Gordon Henriksen34eb6d82007-12-19 22:30:40 +000078
79/* Used to provide a module to JIT or interpreter.
80 * See the llvm::ModuleProvider class.
81 */
Gordon Henriksen0a68fe22007-12-12 01:04:30 +000082typedef struct LLVMOpaqueModuleProvider *LLVMModuleProviderRef;
Gordon Henriksen76a03742007-09-18 03:18:57 +000083
Gordon Henriksen34eb6d82007-12-19 22:30:40 +000084/* Used to provide a module to JIT or interpreter.
85 * See the llvm::MemoryBuffer class.
86 */
87typedef struct LLVMOpaqueMemoryBuffer *LLVMMemoryBufferRef;
88
Gordon Henriksen878114b2008-03-16 04:20:44 +000089/** See the llvm::PassManagerBase class. */
90typedef struct LLVMOpaquePassManager *LLVMPassManagerRef;
91
Gordon Henriksen76a03742007-09-18 03:18:57 +000092typedef enum {
Devang Patel4c758ea2008-09-25 21:00:45 +000093 LLVMZExtAttribute = 1<<0,
94 LLVMSExtAttribute = 1<<1,
95 LLVMNoReturnAttribute = 1<<2,
96 LLVMInRegAttribute = 1<<3,
97 LLVMStructRetAttribute = 1<<4,
98 LLVMNoUnwindAttribute = 1<<5,
99 LLVMNoAliasAttribute = 1<<6,
100 LLVMByValAttribute = 1<<7,
101 LLVMNestAttribute = 1<<8,
102 LLVMReadNoneAttribute = 1<<9,
Anton Korobeynikovc8ce7b082009-07-17 18:07:26 +0000103 LLVMReadOnlyAttribute = 1<<10,
Anton Korobeynikov9750be92009-07-17 18:57:16 +0000104 LLVMNoInlineAttribute = 1<<11,
105 LLVMAlwaysInlineAttribute = 1<<12,
106 LLVMOptimizeForSizeAttribute = 1<<13,
107 LLVMStackProtectAttribute = 1<<14,
108 LLVMStackProtectReqAttribute = 1<<15,
109 LLVMNoCaptureAttribute = 1<<21,
110 LLVMNoRedZoneAttribute = 1<<22,
111 LLVMNoImplicitFloatAttribute = 1<<23,
Anton Korobeynikovc8ce7b082009-07-17 18:07:26 +0000112 LLVMNakedAttribute = 1<<24
Devang Patel4c758ea2008-09-25 21:00:45 +0000113} LLVMAttribute;
Gordon Henriksen2d9cc212008-04-28 17:37:06 +0000114
115typedef enum {
Gordon Henriksen4a4d7352007-12-30 17:46:33 +0000116 LLVMVoidTypeKind, /**< type with no size */
117 LLVMFloatTypeKind, /**< 32 bit floating point type */
118 LLVMDoubleTypeKind, /**< 64 bit floating point type */
119 LLVMX86_FP80TypeKind, /**< 80 bit floating point type (X87) */
120 LLVMFP128TypeKind, /**< 128 bit floating point type (112-bit mantissa)*/
121 LLVMPPC_FP128TypeKind, /**< 128 bit floating point type (two 64-bits) */
122 LLVMLabelTypeKind, /**< Labels */
123 LLVMIntegerTypeKind, /**< Arbitrary bit width integers */
124 LLVMFunctionTypeKind, /**< Functions */
125 LLVMStructTypeKind, /**< Structures */
126 LLVMArrayTypeKind, /**< Arrays */
127 LLVMPointerTypeKind, /**< Pointers */
128 LLVMOpaqueTypeKind, /**< Opaque: type with unknown structure */
Chris Lattnerdac44ec2009-07-15 22:00:31 +0000129 LLVMVectorTypeKind, /**< SIMD 'packed' format, or other vector type */
130 LLVMMetadataTypeKind /**< Metadata */
Gordon Henriksen76a03742007-09-18 03:18:57 +0000131} LLVMTypeKind;
132
133typedef enum {
Gordon Henriksen4a4d7352007-12-30 17:46:33 +0000134 LLVMExternalLinkage, /**< Externally visible function */
Chris Lattner2dba0f02009-04-13 06:25:37 +0000135 LLVMAvailableExternallyLinkage,
Duncan Sands12da8ce2009-03-07 15:45:40 +0000136 LLVMLinkOnceAnyLinkage, /**< Keep one copy of function when linking (inline)*/
137 LLVMLinkOnceODRLinkage, /**< Same, but only replaced by something
138 equivalent. */
139 LLVMWeakAnyLinkage, /**< Keep one copy of function when linking (weak) */
140 LLVMWeakODRLinkage, /**< Same, but only replaced by something
141 equivalent. */
Gordon Henriksen4a4d7352007-12-30 17:46:33 +0000142 LLVMAppendingLinkage, /**< Special purpose, only applies to global arrays */
143 LLVMInternalLinkage, /**< Rename collisions when linking (static
144 functions) */
Duncan Sands12da8ce2009-03-07 15:45:40 +0000145 LLVMPrivateLinkage, /**< Like Internal, but omit from symbol table */
Gordon Henriksen4a4d7352007-12-30 17:46:33 +0000146 LLVMDLLImportLinkage, /**< Function to be imported from DLL */
147 LLVMDLLExportLinkage, /**< Function to be accessible from DLL */
Duncan Sandse2881052009-03-11 08:08:06 +0000148 LLVMExternalWeakLinkage,/**< ExternalWeak linkage description */
Duncan Sands12da8ce2009-03-07 15:45:40 +0000149 LLVMGhostLinkage, /**< Stand-in functions for streaming fns from
Gordon Henriksen4a4d7352007-12-30 17:46:33 +0000150 bitcode */
Bill Wendling002b1672009-07-20 18:22:52 +0000151 LLVMCommonLinkage, /**< Tentative definitions */
152 LLVMLinkerPrivateLinkage /**< Like Private, but linker removes. */
Gordon Henriksen76a03742007-09-18 03:18:57 +0000153} LLVMLinkage;
154
155typedef enum {
Gordon Henriksen4a4d7352007-12-30 17:46:33 +0000156 LLVMDefaultVisibility, /**< The GV is visible */
157 LLVMHiddenVisibility, /**< The GV is hidden */
158 LLVMProtectedVisibility /**< The GV is protected */
Gordon Henriksen76a03742007-09-18 03:18:57 +0000159} LLVMVisibility;
160
Gordon Henriksenc23b66c2007-09-26 20:56:12 +0000161typedef enum {
162 LLVMCCallConv = 0,
163 LLVMFastCallConv = 8,
164 LLVMColdCallConv = 9,
165 LLVMX86StdcallCallConv = 64,
166 LLVMX86FastcallCallConv = 65
167} LLVMCallConv;
168
169typedef enum {
Gordon Henriksen4a4d7352007-12-30 17:46:33 +0000170 LLVMIntEQ = 32, /**< equal */
171 LLVMIntNE, /**< not equal */
172 LLVMIntUGT, /**< unsigned greater than */
173 LLVMIntUGE, /**< unsigned greater or equal */
174 LLVMIntULT, /**< unsigned less than */
175 LLVMIntULE, /**< unsigned less or equal */
176 LLVMIntSGT, /**< signed greater than */
177 LLVMIntSGE, /**< signed greater or equal */
178 LLVMIntSLT, /**< signed less than */
179 LLVMIntSLE /**< signed less or equal */
Gordon Henriksenc23b66c2007-09-26 20:56:12 +0000180} LLVMIntPredicate;
181
182typedef enum {
Gordon Henriksen4a4d7352007-12-30 17:46:33 +0000183 LLVMRealPredicateFalse, /**< Always false (always folded) */
184 LLVMRealOEQ, /**< True if ordered and equal */
185 LLVMRealOGT, /**< True if ordered and greater than */
186 LLVMRealOGE, /**< True if ordered and greater than or equal */
187 LLVMRealOLT, /**< True if ordered and less than */
188 LLVMRealOLE, /**< True if ordered and less than or equal */
189 LLVMRealONE, /**< True if ordered and operands are unequal */
190 LLVMRealORD, /**< True if ordered (no nans) */
191 LLVMRealUNO, /**< True if unordered: isnan(X) | isnan(Y) */
192 LLVMRealUEQ, /**< True if unordered or equal */
193 LLVMRealUGT, /**< True if unordered or greater than */
194 LLVMRealUGE, /**< True if unordered, greater than, or equal */
195 LLVMRealULT, /**< True if unordered or less than */
196 LLVMRealULE, /**< True if unordered, less than, or equal */
197 LLVMRealUNE, /**< True if unordered or not equal */
198 LLVMRealPredicateTrue /**< Always true (always folded) */
Gordon Henriksenc23b66c2007-09-26 20:56:12 +0000199} LLVMRealPredicate;
200
Gordon Henriksen76a03742007-09-18 03:18:57 +0000201
Gordon Henriksen34eb6d82007-12-19 22:30:40 +0000202/*===-- Error handling ----------------------------------------------------===*/
203
204void LLVMDisposeMessage(char *Message);
205
206
Gordon Henriksen76a03742007-09-18 03:18:57 +0000207/*===-- Modules -----------------------------------------------------------===*/
208
Owen Anderson6773d382009-07-01 16:58:40 +0000209/* Create and destroy contexts. */
210LLVMContextRef LLVMContextCreate();
Owen Andersonf7691d32009-07-02 00:16:38 +0000211LLVMContextRef LLVMGetGlobalContext();
Owen Anderson6773d382009-07-01 16:58:40 +0000212void LLVMContextDispose(LLVMContextRef C);
213
Gordon Henriksen76a03742007-09-18 03:18:57 +0000214/* Create and destroy modules. */
Gordon Henriksena49d4352008-03-07 19:13:06 +0000215/** See llvm::Module::Module. */
Gordon Henriksen76a03742007-09-18 03:18:57 +0000216LLVMModuleRef LLVMModuleCreateWithName(const char *ModuleID);
Owen Anderson31d44e42009-07-02 07:17:57 +0000217LLVMModuleRef LLVMModuleCreateWithNameInContext(const char *ModuleID,
218 LLVMContextRef C);
Gordon Henriksena49d4352008-03-07 19:13:06 +0000219
220/** See llvm::Module::~Module. */
Gordon Henriksen76a03742007-09-18 03:18:57 +0000221void LLVMDisposeModule(LLVMModuleRef M);
222
Gordon Henriksena49d4352008-03-07 19:13:06 +0000223/** Data layout. See Module::getDataLayout. */
Gordon Henriksen05568bb2007-12-27 20:13:47 +0000224const char *LLVMGetDataLayout(LLVMModuleRef M);
225void LLVMSetDataLayout(LLVMModuleRef M, const char *Triple);
226
Gordon Henriksena49d4352008-03-07 19:13:06 +0000227/** Target triple. See Module::getTargetTriple. */
Gordon Henriksen05568bb2007-12-27 20:13:47 +0000228const char *LLVMGetTarget(LLVMModuleRef M);
229void LLVMSetTarget(LLVMModuleRef M, const char *Triple);
230
Gordon Henriksena49d4352008-03-07 19:13:06 +0000231/** See Module::addTypeName. */
Gordon Henriksen76a03742007-09-18 03:18:57 +0000232int LLVMAddTypeName(LLVMModuleRef M, const char *Name, LLVMTypeRef Ty);
Gordon Henriksenc23b66c2007-09-26 20:56:12 +0000233void LLVMDeleteTypeName(LLVMModuleRef M, const char *Name);
Chris Lattner7f318242009-07-06 17:29:59 +0000234LLVMTypeRef LLVMGetTypeByName(LLVMModuleRef M, const char *Name);
Gordon Henriksen76a03742007-09-18 03:18:57 +0000235
Gordon Henriksen6c6075e2008-03-14 23:58:56 +0000236/** See Module::dump. */
237void LLVMDumpModule(LLVMModuleRef M);
238
Gordon Henriksen76a03742007-09-18 03:18:57 +0000239
Gordon Henriksenc23b66c2007-09-26 20:56:12 +0000240/*===-- Types -------------------------------------------------------------===*/
Gordon Henriksen76a03742007-09-18 03:18:57 +0000241
242/* LLVM types conform to the following hierarchy:
243 *
244 * types:
245 * integer type
246 * real type
247 * function type
248 * sequence types:
249 * array type
250 * pointer type
251 * vector type
252 * void type
253 * label type
254 * opaque type
255 */
256
Gordon Henriksena49d4352008-03-07 19:13:06 +0000257/** See llvm::LLVMTypeKind::getTypeID. */
Gordon Henriksen76a03742007-09-18 03:18:57 +0000258LLVMTypeKind LLVMGetTypeKind(LLVMTypeRef Ty);
Gordon Henriksena49d4352008-03-07 19:13:06 +0000259
Erick Tryzelaar262332f2009-08-14 00:01:31 +0000260/** See llvm::LLVMType::getContext. */
261LLVMContextRef LLVMGetTypeContext(LLVMTypeRef Ty);
262
Gordon Henriksen76a03742007-09-18 03:18:57 +0000263/* Operations on integer types */
Erick Tryzelaar262332f2009-08-14 00:01:31 +0000264LLVMTypeRef LLVMInt1TypeInContext(LLVMContextRef C);
265LLVMTypeRef LLVMInt8TypeInContext(LLVMContextRef C);
266LLVMTypeRef LLVMInt16TypeInContext(LLVMContextRef C);
267LLVMTypeRef LLVMInt32TypeInContext(LLVMContextRef C);
268LLVMTypeRef LLVMInt64TypeInContext(LLVMContextRef C);
269LLVMTypeRef LLVMIntTypeInContext(LLVMContextRef C, unsigned NumBits);
270
Gordon Henriksena735a9c2008-05-04 12:55:34 +0000271LLVMTypeRef LLVMInt1Type(void);
272LLVMTypeRef LLVMInt8Type(void);
273LLVMTypeRef LLVMInt16Type(void);
274LLVMTypeRef LLVMInt32Type(void);
275LLVMTypeRef LLVMInt64Type(void);
Gordon Henriksened7beaa2007-10-06 16:05:20 +0000276LLVMTypeRef LLVMIntType(unsigned NumBits);
Gordon Henriksenc23b66c2007-09-26 20:56:12 +0000277unsigned LLVMGetIntTypeWidth(LLVMTypeRef IntegerTy);
Gordon Henriksen76a03742007-09-18 03:18:57 +0000278
279/* Operations on real types */
Erick Tryzelaar262332f2009-08-14 00:01:31 +0000280LLVMTypeRef LLVMFloatTypeInContext(LLVMContextRef C);
281LLVMTypeRef LLVMDoubleTypeInContext(LLVMContextRef C);
282LLVMTypeRef LLVMX86FP80TypeInContext(LLVMContextRef C);
283LLVMTypeRef LLVMFP128TypeInContext(LLVMContextRef C);
284LLVMTypeRef LLVMPPCFP128TypeInContext(LLVMContextRef C);
285
Gordon Henriksena735a9c2008-05-04 12:55:34 +0000286LLVMTypeRef LLVMFloatType(void);
287LLVMTypeRef LLVMDoubleType(void);
288LLVMTypeRef LLVMX86FP80Type(void);
289LLVMTypeRef LLVMFP128Type(void);
290LLVMTypeRef LLVMPPCFP128Type(void);
Gordon Henriksen76a03742007-09-18 03:18:57 +0000291
292/* Operations on function types */
Gordon Henriksened7beaa2007-10-06 16:05:20 +0000293LLVMTypeRef LLVMFunctionType(LLVMTypeRef ReturnType,
294 LLVMTypeRef *ParamTypes, unsigned ParamCount,
295 int IsVarArg);
Gordon Henriksen76a03742007-09-18 03:18:57 +0000296int LLVMIsFunctionVarArg(LLVMTypeRef FunctionTy);
Gordon Henriksenc23b66c2007-09-26 20:56:12 +0000297LLVMTypeRef LLVMGetReturnType(LLVMTypeRef FunctionTy);
298unsigned LLVMCountParamTypes(LLVMTypeRef FunctionTy);
299void LLVMGetParamTypes(LLVMTypeRef FunctionTy, LLVMTypeRef *Dest);
Gordon Henriksen76a03742007-09-18 03:18:57 +0000300
301/* Operations on struct types */
Erick Tryzelaar262332f2009-08-14 00:01:31 +0000302LLVMTypeRef LLVMStructTypeInContext(LLVMContextRef C, LLVMTypeRef *ElementTypes,
303 unsigned ElementCount, int Packed);
Gordon Henriksened7beaa2007-10-06 16:05:20 +0000304LLVMTypeRef LLVMStructType(LLVMTypeRef *ElementTypes, unsigned ElementCount,
305 int Packed);
Gordon Henriksenc23b66c2007-09-26 20:56:12 +0000306unsigned LLVMCountStructElementTypes(LLVMTypeRef StructTy);
Gordon Henriksen76a03742007-09-18 03:18:57 +0000307void LLVMGetStructElementTypes(LLVMTypeRef StructTy, LLVMTypeRef *Dest);
308int LLVMIsPackedStruct(LLVMTypeRef StructTy);
309
310/* Operations on array, pointer, and vector types (sequence types) */
Gordon Henriksened7beaa2007-10-06 16:05:20 +0000311LLVMTypeRef LLVMArrayType(LLVMTypeRef ElementType, unsigned ElementCount);
Gordon Henriksen5a3fe032007-12-17 16:08:32 +0000312LLVMTypeRef LLVMPointerType(LLVMTypeRef ElementType, unsigned AddressSpace);
Gordon Henriksened7beaa2007-10-06 16:05:20 +0000313LLVMTypeRef LLVMVectorType(LLVMTypeRef ElementType, unsigned ElementCount);
Gordon Henriksen76a03742007-09-18 03:18:57 +0000314
315LLVMTypeRef LLVMGetElementType(LLVMTypeRef Ty);
316unsigned LLVMGetArrayLength(LLVMTypeRef ArrayTy);
Gordon Henriksen5a3fe032007-12-17 16:08:32 +0000317unsigned LLVMGetPointerAddressSpace(LLVMTypeRef PointerTy);
Gordon Henriksen76a03742007-09-18 03:18:57 +0000318unsigned LLVMGetVectorSize(LLVMTypeRef VectorTy);
319
320/* Operations on other types */
Erick Tryzelaar262332f2009-08-14 00:01:31 +0000321LLVMTypeRef LLVMVoidTypeInContext(LLVMContextRef C);
322LLVMTypeRef LLVMLabelTypeInContext(LLVMContextRef C);
323LLVMTypeRef LLVMOpaqueTypeInContext(LLVMContextRef C);
324
Gordon Henriksena735a9c2008-05-04 12:55:34 +0000325LLVMTypeRef LLVMVoidType(void);
326LLVMTypeRef LLVMLabelType(void);
327LLVMTypeRef LLVMOpaqueType(void);
Gordon Henriksen76a03742007-09-18 03:18:57 +0000328
Gordon Henriksenffb48762007-10-07 00:13:35 +0000329/* Operations on type handles */
330LLVMTypeHandleRef LLVMCreateTypeHandle(LLVMTypeRef PotentiallyAbstractTy);
331void LLVMRefineType(LLVMTypeRef AbstractTy, LLVMTypeRef ConcreteTy);
332LLVMTypeRef LLVMResolveTypeHandle(LLVMTypeHandleRef TypeHandle);
333void LLVMDisposeTypeHandle(LLVMTypeHandleRef TypeHandle);
334
Gordon Henriksen76a03742007-09-18 03:18:57 +0000335
336/*===-- Values ------------------------------------------------------------===*/
337
338/* The bulk of LLVM's object model consists of values, which comprise a very
339 * rich type hierarchy.
Gordon Henriksen76a03742007-09-18 03:18:57 +0000340 */
341
Gordon Henriksen29e38942008-12-19 18:39:45 +0000342#define LLVM_FOR_EACH_VALUE_SUBCLASS(macro) \
343 macro(Argument) \
344 macro(BasicBlock) \
345 macro(InlineAsm) \
346 macro(User) \
347 macro(Constant) \
348 macro(ConstantAggregateZero) \
349 macro(ConstantArray) \
350 macro(ConstantExpr) \
351 macro(ConstantFP) \
352 macro(ConstantInt) \
353 macro(ConstantPointerNull) \
354 macro(ConstantStruct) \
355 macro(ConstantVector) \
356 macro(GlobalValue) \
357 macro(Function) \
358 macro(GlobalAlias) \
359 macro(GlobalVariable) \
360 macro(UndefValue) \
361 macro(Instruction) \
362 macro(BinaryOperator) \
363 macro(CallInst) \
364 macro(IntrinsicInst) \
365 macro(DbgInfoIntrinsic) \
366 macro(DbgDeclareInst) \
367 macro(DbgFuncStartInst) \
368 macro(DbgRegionEndInst) \
369 macro(DbgRegionStartInst) \
370 macro(DbgStopPointInst) \
371 macro(EHSelectorInst) \
372 macro(MemIntrinsic) \
373 macro(MemCpyInst) \
374 macro(MemMoveInst) \
375 macro(MemSetInst) \
376 macro(CmpInst) \
377 macro(FCmpInst) \
378 macro(ICmpInst) \
Gordon Henriksen29e38942008-12-19 18:39:45 +0000379 macro(ExtractElementInst) \
380 macro(GetElementPtrInst) \
381 macro(InsertElementInst) \
382 macro(InsertValueInst) \
383 macro(PHINode) \
384 macro(SelectInst) \
385 macro(ShuffleVectorInst) \
386 macro(StoreInst) \
387 macro(TerminatorInst) \
388 macro(BranchInst) \
389 macro(InvokeInst) \
390 macro(ReturnInst) \
391 macro(SwitchInst) \
392 macro(UnreachableInst) \
393 macro(UnwindInst) \
394 macro(UnaryInstruction) \
395 macro(AllocationInst) \
Gordon Henriksen05a868f2008-12-19 18:51:17 +0000396 macro(AllocaInst) \
397 macro(MallocInst) \
Gordon Henriksen29e38942008-12-19 18:39:45 +0000398 macro(CastInst) \
Gordon Henriksen05a868f2008-12-19 18:51:17 +0000399 macro(BitCastInst) \
400 macro(FPExtInst) \
401 macro(FPToSIInst) \
402 macro(FPToUIInst) \
403 macro(FPTruncInst) \
404 macro(IntToPtrInst) \
405 macro(PtrToIntInst) \
406 macro(SExtInst) \
407 macro(SIToFPInst) \
408 macro(TruncInst) \
409 macro(UIToFPInst) \
410 macro(ZExtInst) \
411 macro(ExtractValueInst) \
412 macro(FreeInst) \
413 macro(LoadInst) \
414 macro(VAArgInst)
Gordon Henriksen29e38942008-12-19 18:39:45 +0000415
Gordon Henriksen76a03742007-09-18 03:18:57 +0000416/* Operations on all values */
Gordon Henriksenc23b66c2007-09-26 20:56:12 +0000417LLVMTypeRef LLVMTypeOf(LLVMValueRef Val);
Gordon Henriksen76a03742007-09-18 03:18:57 +0000418const char *LLVMGetValueName(LLVMValueRef Val);
419void LLVMSetValueName(LLVMValueRef Val, const char *Name);
Gordon Henriksen1d0d24c2007-10-06 00:08:49 +0000420void LLVMDumpValue(LLVMValueRef Val);
Gordon Henriksen76a03742007-09-18 03:18:57 +0000421
Gordon Henriksen29e38942008-12-19 18:39:45 +0000422/* Conversion functions. Return the input value if it is an instance of the
423 specified class, otherwise NULL. See llvm::dyn_cast_or_null<>. */
424#define LLVM_DECLARE_VALUE_CAST(name) \
425 LLVMValueRef LLVMIsA##name(LLVMValueRef Val);
426LLVM_FOR_EACH_VALUE_SUBCLASS(LLVM_DECLARE_VALUE_CAST)
427
Gordon Henriksen76a03742007-09-18 03:18:57 +0000428/* Operations on constants of any type */
Gordon Henriksen1046c732007-10-06 15:11:06 +0000429LLVMValueRef LLVMConstNull(LLVMTypeRef Ty); /* all zeroes */
430LLVMValueRef LLVMConstAllOnes(LLVMTypeRef Ty); /* only for int/vector */
Gordon Henriksen76a03742007-09-18 03:18:57 +0000431LLVMValueRef LLVMGetUndef(LLVMTypeRef Ty);
Gordon Henriksendc88c062007-09-18 18:07:51 +0000432int LLVMIsConstant(LLVMValueRef Val);
Gordon Henriksen76a03742007-09-18 03:18:57 +0000433int LLVMIsNull(LLVMValueRef Val);
Gordon Henriksendc88c062007-09-18 18:07:51 +0000434int LLVMIsUndef(LLVMValueRef Val);
Chris Lattner7f318242009-07-06 17:29:59 +0000435LLVMValueRef LLVMConstPointerNull(LLVMTypeRef Ty);
Gordon Henriksen76a03742007-09-18 03:18:57 +0000436
437/* Operations on scalar constants */
Gordon Henriksen1046c732007-10-06 15:11:06 +0000438LLVMValueRef LLVMConstInt(LLVMTypeRef IntTy, unsigned long long N,
439 int SignExtend);
Erick Tryzelaardd991352009-08-16 23:36:46 +0000440LLVMValueRef LLVMConstIntOfString(LLVMTypeRef IntTy, const char *Text,
441 uint8_t Radix);
442LLVMValueRef LLVMConstIntOfStringAndSize(LLVMTypeRef IntTy, const char *Text,
443 unsigned SLen, uint8_t Radix);
Gordon Henriksen1046c732007-10-06 15:11:06 +0000444LLVMValueRef LLVMConstReal(LLVMTypeRef RealTy, double N);
Gordon Henriksen931e1212008-02-02 01:07:50 +0000445LLVMValueRef LLVMConstRealOfString(LLVMTypeRef RealTy, const char *Text);
Erick Tryzelaardd991352009-08-16 23:36:46 +0000446LLVMValueRef LLVMConstRealOfStringAndSize(LLVMTypeRef RealTy, const char *Text,
447 unsigned SLen);
448
Gordon Henriksen76a03742007-09-18 03:18:57 +0000449
450/* Operations on composite constants */
Erick Tryzelaar262332f2009-08-14 00:01:31 +0000451LLVMValueRef LLVMConstStringInContext(LLVMContextRef C, const char *Str,
452 unsigned Length, int DontNullTerminate);
453LLVMValueRef LLVMConstStructInContext(LLVMContextRef C,
454 LLVMValueRef *ConstantVals,
455 unsigned Count, int Packed);
456
Gordon Henriksen1046c732007-10-06 15:11:06 +0000457LLVMValueRef LLVMConstString(const char *Str, unsigned Length,
458 int DontNullTerminate);
Gordon Henriksen2ad5aef2008-04-25 03:21:19 +0000459LLVMValueRef LLVMConstArray(LLVMTypeRef ElementTy,
Gordon Henriksen1046c732007-10-06 15:11:06 +0000460 LLVMValueRef *ConstantVals, unsigned Length);
461LLVMValueRef LLVMConstStruct(LLVMValueRef *ConstantVals, unsigned Count,
Erick Tryzelaar262332f2009-08-14 00:01:31 +0000462 int Packed);
Gordon Henriksen1046c732007-10-06 15:11:06 +0000463LLVMValueRef LLVMConstVector(LLVMValueRef *ScalarConstantVals, unsigned Size);
Gordon Henriksen76a03742007-09-18 03:18:57 +0000464
Gordon Henriksen7ce31762007-10-06 14:29:36 +0000465/* Constant expressions */
Erick Tryzelaarfd529d72009-08-19 08:36:49 +0000466LLVMValueRef LLVMAlignOf(LLVMTypeRef Ty);
Gordon Henriksen7ce31762007-10-06 14:29:36 +0000467LLVMValueRef LLVMSizeOf(LLVMTypeRef Ty);
468LLVMValueRef LLVMConstNeg(LLVMValueRef ConstantVal);
Erick Tryzelaar4cc690c2009-08-16 02:20:12 +0000469LLVMValueRef LLVMConstFNeg(LLVMValueRef ConstantVal);
Gordon Henriksen7ce31762007-10-06 14:29:36 +0000470LLVMValueRef LLVMConstNot(LLVMValueRef ConstantVal);
471LLVMValueRef LLVMConstAdd(LLVMValueRef LHSConstant, LLVMValueRef RHSConstant);
Erick Tryzelaar4cc690c2009-08-16 02:20:12 +0000472LLVMValueRef LLVMConstNSWAdd(LLVMValueRef LHSConstant, LLVMValueRef RHSConstant);
473LLVMValueRef LLVMConstFAdd(LLVMValueRef LHSConstant, LLVMValueRef RHSConstant);
Gordon Henriksen7ce31762007-10-06 14:29:36 +0000474LLVMValueRef LLVMConstSub(LLVMValueRef LHSConstant, LLVMValueRef RHSConstant);
Erick Tryzelaar4cc690c2009-08-16 02:20:12 +0000475LLVMValueRef LLVMConstFSub(LLVMValueRef LHSConstant, LLVMValueRef RHSConstant);
Gordon Henriksen7ce31762007-10-06 14:29:36 +0000476LLVMValueRef LLVMConstMul(LLVMValueRef LHSConstant, LLVMValueRef RHSConstant);
Erick Tryzelaar4cc690c2009-08-16 02:20:12 +0000477LLVMValueRef LLVMConstFMul(LLVMValueRef LHSConstant, LLVMValueRef RHSConstant);
Gordon Henriksen7ce31762007-10-06 14:29:36 +0000478LLVMValueRef LLVMConstUDiv(LLVMValueRef LHSConstant, LLVMValueRef RHSConstant);
479LLVMValueRef LLVMConstSDiv(LLVMValueRef LHSConstant, LLVMValueRef RHSConstant);
Erick Tryzelaar4cc690c2009-08-16 02:20:12 +0000480LLVMValueRef LLVMConstExactSDiv(LLVMValueRef LHSConstant, LLVMValueRef RHSConstant);
Gordon Henriksen7ce31762007-10-06 14:29:36 +0000481LLVMValueRef LLVMConstFDiv(LLVMValueRef LHSConstant, LLVMValueRef RHSConstant);
482LLVMValueRef LLVMConstURem(LLVMValueRef LHSConstant, LLVMValueRef RHSConstant);
483LLVMValueRef LLVMConstSRem(LLVMValueRef LHSConstant, LLVMValueRef RHSConstant);
484LLVMValueRef LLVMConstFRem(LLVMValueRef LHSConstant, LLVMValueRef RHSConstant);
485LLVMValueRef LLVMConstAnd(LLVMValueRef LHSConstant, LLVMValueRef RHSConstant);
486LLVMValueRef LLVMConstOr(LLVMValueRef LHSConstant, LLVMValueRef RHSConstant);
487LLVMValueRef LLVMConstXor(LLVMValueRef LHSConstant, LLVMValueRef RHSConstant);
488LLVMValueRef LLVMConstICmp(LLVMIntPredicate Predicate,
489 LLVMValueRef LHSConstant, LLVMValueRef RHSConstant);
490LLVMValueRef LLVMConstFCmp(LLVMRealPredicate Predicate,
491 LLVMValueRef LHSConstant, LLVMValueRef RHSConstant);
492LLVMValueRef LLVMConstShl(LLVMValueRef LHSConstant, LLVMValueRef RHSConstant);
493LLVMValueRef LLVMConstLShr(LLVMValueRef LHSConstant, LLVMValueRef RHSConstant);
494LLVMValueRef LLVMConstAShr(LLVMValueRef LHSConstant, LLVMValueRef RHSConstant);
495LLVMValueRef LLVMConstGEP(LLVMValueRef ConstantVal,
496 LLVMValueRef *ConstantIndices, unsigned NumIndices);
Erick Tryzelaar4cc690c2009-08-16 02:20:12 +0000497LLVMValueRef LLVMConstInBoundsGEP(LLVMValueRef ConstantVal,
498 LLVMValueRef *ConstantIndices,
499 unsigned NumIndices);
Gordon Henriksen7ce31762007-10-06 14:29:36 +0000500LLVMValueRef LLVMConstTrunc(LLVMValueRef ConstantVal, LLVMTypeRef ToType);
501LLVMValueRef LLVMConstSExt(LLVMValueRef ConstantVal, LLVMTypeRef ToType);
502LLVMValueRef LLVMConstZExt(LLVMValueRef ConstantVal, LLVMTypeRef ToType);
503LLVMValueRef LLVMConstFPTrunc(LLVMValueRef ConstantVal, LLVMTypeRef ToType);
504LLVMValueRef LLVMConstFPExt(LLVMValueRef ConstantVal, LLVMTypeRef ToType);
505LLVMValueRef LLVMConstUIToFP(LLVMValueRef ConstantVal, LLVMTypeRef ToType);
506LLVMValueRef LLVMConstSIToFP(LLVMValueRef ConstantVal, LLVMTypeRef ToType);
507LLVMValueRef LLVMConstFPToUI(LLVMValueRef ConstantVal, LLVMTypeRef ToType);
508LLVMValueRef LLVMConstFPToSI(LLVMValueRef ConstantVal, LLVMTypeRef ToType);
509LLVMValueRef LLVMConstPtrToInt(LLVMValueRef ConstantVal, LLVMTypeRef ToType);
510LLVMValueRef LLVMConstIntToPtr(LLVMValueRef ConstantVal, LLVMTypeRef ToType);
511LLVMValueRef LLVMConstBitCast(LLVMValueRef ConstantVal, LLVMTypeRef ToType);
Erick Tryzelaar4cc690c2009-08-16 02:20:12 +0000512LLVMValueRef LLVMConstZExtOrBitCast(LLVMValueRef ConstantVal,
513 LLVMTypeRef ToType);
514LLVMValueRef LLVMConstSExtOrBitCast(LLVMValueRef ConstantVal,
515 LLVMTypeRef ToType);
516LLVMValueRef LLVMConstTruncOrBitCast(LLVMValueRef ConstantVal,
517 LLVMTypeRef ToType);
518LLVMValueRef LLVMConstPointerCast(LLVMValueRef ConstantVal,
519 LLVMTypeRef ToType);
520LLVMValueRef LLVMConstIntCast(LLVMValueRef ConstantVal, LLVMTypeRef ToType,
521 unsigned isSigned);
522LLVMValueRef LLVMConstFPCast(LLVMValueRef ConstantVal, LLVMTypeRef ToType);
Gordon Henriksen7ce31762007-10-06 14:29:36 +0000523LLVMValueRef LLVMConstSelect(LLVMValueRef ConstantCondition,
524 LLVMValueRef ConstantIfTrue,
525 LLVMValueRef ConstantIfFalse);
526LLVMValueRef LLVMConstExtractElement(LLVMValueRef VectorConstant,
527 LLVMValueRef IndexConstant);
528LLVMValueRef LLVMConstInsertElement(LLVMValueRef VectorConstant,
529 LLVMValueRef ElementValueConstant,
530 LLVMValueRef IndexConstant);
531LLVMValueRef LLVMConstShuffleVector(LLVMValueRef VectorAConstant,
532 LLVMValueRef VectorBConstant,
533 LLVMValueRef MaskConstant);
Dan Gohmand5104a52008-11-03 22:55:43 +0000534LLVMValueRef LLVMConstExtractValue(LLVMValueRef AggConstant, unsigned *IdxList,
535 unsigned NumIdx);
536LLVMValueRef LLVMConstInsertValue(LLVMValueRef AggConstant,
537 LLVMValueRef ElementValueConstant,
538 unsigned *IdxList, unsigned NumIdx);
Chris Lattner3d1f5522008-12-17 21:39:50 +0000539LLVMValueRef LLVMConstInlineAsm(LLVMTypeRef Ty,
540 const char *AsmString, const char *Constraints,
541 int HasSideEffects);
Gordon Henriksen7ce31762007-10-06 14:29:36 +0000542
Gordon Henriksen76a03742007-09-18 03:18:57 +0000543/* Operations on global variables, functions, and aliases (globals) */
Gordon Henriksen265f7802008-03-19 01:11:35 +0000544LLVMModuleRef LLVMGetGlobalParent(LLVMValueRef Global);
Gordon Henriksen76a03742007-09-18 03:18:57 +0000545int LLVMIsDeclaration(LLVMValueRef Global);
546LLVMLinkage LLVMGetLinkage(LLVMValueRef Global);
547void LLVMSetLinkage(LLVMValueRef Global, LLVMLinkage Linkage);
548const char *LLVMGetSection(LLVMValueRef Global);
549void LLVMSetSection(LLVMValueRef Global, const char *Section);
550LLVMVisibility LLVMGetVisibility(LLVMValueRef Global);
551void LLVMSetVisibility(LLVMValueRef Global, LLVMVisibility Viz);
552unsigned LLVMGetAlignment(LLVMValueRef Global);
553void LLVMSetAlignment(LLVMValueRef Global, unsigned Bytes);
554
555/* Operations on global variables */
556LLVMValueRef LLVMAddGlobal(LLVMModuleRef M, LLVMTypeRef Ty, const char *Name);
Gordon Henriksen783f7bb2007-10-08 03:45:09 +0000557LLVMValueRef LLVMGetNamedGlobal(LLVMModuleRef M, const char *Name);
Gordon Henriksen07a45f42008-03-23 22:21:29 +0000558LLVMValueRef LLVMGetFirstGlobal(LLVMModuleRef M);
559LLVMValueRef LLVMGetLastGlobal(LLVMModuleRef M);
560LLVMValueRef LLVMGetNextGlobal(LLVMValueRef GlobalVar);
561LLVMValueRef LLVMGetPreviousGlobal(LLVMValueRef GlobalVar);
Gordon Henriksen76a03742007-09-18 03:18:57 +0000562void LLVMDeleteGlobal(LLVMValueRef GlobalVar);
Gordon Henriksen76a03742007-09-18 03:18:57 +0000563LLVMValueRef LLVMGetInitializer(LLVMValueRef GlobalVar);
564void LLVMSetInitializer(LLVMValueRef GlobalVar, LLVMValueRef ConstantVal);
565int LLVMIsThreadLocal(LLVMValueRef GlobalVar);
566void LLVMSetThreadLocal(LLVMValueRef GlobalVar, int IsThreadLocal);
Gordon Henriksen751ebf72007-10-07 17:31:42 +0000567int LLVMIsGlobalConstant(LLVMValueRef GlobalVar);
568void LLVMSetGlobalConstant(LLVMValueRef GlobalVar, int IsConstant);
Gordon Henriksen76a03742007-09-18 03:18:57 +0000569
Chris Lattner3d1f5522008-12-17 21:39:50 +0000570/* Operations on aliases */
571LLVMValueRef LLVMAddAlias(LLVMModuleRef M, LLVMTypeRef Ty, LLVMValueRef Aliasee,
572 const char *Name);
573
Gordon Henriksenc23b66c2007-09-26 20:56:12 +0000574/* Operations on functions */
575LLVMValueRef LLVMAddFunction(LLVMModuleRef M, const char *Name,
576 LLVMTypeRef FunctionTy);
Gordon Henriksen783f7bb2007-10-08 03:45:09 +0000577LLVMValueRef LLVMGetNamedFunction(LLVMModuleRef M, const char *Name);
Gordon Henriksen054817c2008-03-19 03:47:18 +0000578LLVMValueRef LLVMGetFirstFunction(LLVMModuleRef M);
579LLVMValueRef LLVMGetLastFunction(LLVMModuleRef M);
580LLVMValueRef LLVMGetNextFunction(LLVMValueRef Fn);
581LLVMValueRef LLVMGetPreviousFunction(LLVMValueRef Fn);
Gordon Henriksenc23b66c2007-09-26 20:56:12 +0000582void LLVMDeleteFunction(LLVMValueRef Fn);
Gordon Henriksenc23b66c2007-09-26 20:56:12 +0000583unsigned LLVMGetIntrinsicID(LLVMValueRef Fn);
584unsigned LLVMGetFunctionCallConv(LLVMValueRef Fn);
585void LLVMSetFunctionCallConv(LLVMValueRef Fn, unsigned CC);
Gordon Henriksend930f912008-08-17 18:44:35 +0000586const char *LLVMGetGC(LLVMValueRef Fn);
587void LLVMSetGC(LLVMValueRef Fn, const char *Name);
Duncan Sands7374a012009-05-06 12:21:17 +0000588void LLVMAddFunctionAttr(LLVMValueRef Fn, LLVMAttribute PA);
589void LLVMRemoveFunctionAttr(LLVMValueRef Fn, LLVMAttribute PA);
Gordon Henriksenc23b66c2007-09-26 20:56:12 +0000590
Gordon Henriksen265f7802008-03-19 01:11:35 +0000591/* Operations on parameters */
592unsigned LLVMCountParams(LLVMValueRef Fn);
593void LLVMGetParams(LLVMValueRef Fn, LLVMValueRef *Params);
594LLVMValueRef LLVMGetParam(LLVMValueRef Fn, unsigned Index);
595LLVMValueRef LLVMGetParamParent(LLVMValueRef Inst);
Gordon Henriksen07a45f42008-03-23 22:21:29 +0000596LLVMValueRef LLVMGetFirstParam(LLVMValueRef Fn);
597LLVMValueRef LLVMGetLastParam(LLVMValueRef Fn);
598LLVMValueRef LLVMGetNextParam(LLVMValueRef Arg);
599LLVMValueRef LLVMGetPreviousParam(LLVMValueRef Arg);
Devang Patel4c758ea2008-09-25 21:00:45 +0000600void LLVMAddAttribute(LLVMValueRef Arg, LLVMAttribute PA);
601void LLVMRemoveAttribute(LLVMValueRef Arg, LLVMAttribute PA);
Gordon Henriksen2d9cc212008-04-28 17:37:06 +0000602void LLVMSetParamAlignment(LLVMValueRef Arg, unsigned align);
Gordon Henriksen265f7802008-03-19 01:11:35 +0000603
Gordon Henriksenc23b66c2007-09-26 20:56:12 +0000604/* Operations on basic blocks */
Gordon Henriksen07a45f42008-03-23 22:21:29 +0000605LLVMValueRef LLVMBasicBlockAsValue(LLVMBasicBlockRef BB);
Gordon Henriksenc23b66c2007-09-26 20:56:12 +0000606int LLVMValueIsBasicBlock(LLVMValueRef Val);
607LLVMBasicBlockRef LLVMValueAsBasicBlock(LLVMValueRef Val);
Gordon Henriksen07a45f42008-03-23 22:21:29 +0000608LLVMValueRef LLVMGetBasicBlockParent(LLVMBasicBlockRef BB);
Gordon Henriksenc23b66c2007-09-26 20:56:12 +0000609unsigned LLVMCountBasicBlocks(LLVMValueRef Fn);
610void LLVMGetBasicBlocks(LLVMValueRef Fn, LLVMBasicBlockRef *BasicBlocks);
Gordon Henriksen054817c2008-03-19 03:47:18 +0000611LLVMBasicBlockRef LLVMGetFirstBasicBlock(LLVMValueRef Fn);
612LLVMBasicBlockRef LLVMGetLastBasicBlock(LLVMValueRef Fn);
613LLVMBasicBlockRef LLVMGetNextBasicBlock(LLVMBasicBlockRef BB);
614LLVMBasicBlockRef LLVMGetPreviousBasicBlock(LLVMBasicBlockRef BB);
Gordon Henriksenc23b66c2007-09-26 20:56:12 +0000615LLVMBasicBlockRef LLVMGetEntryBasicBlock(LLVMValueRef Fn);
Erick Tryzelaar262332f2009-08-14 00:01:31 +0000616
617LLVMBasicBlockRef LLVMAppendBasicBlockInContext(LLVMContextRef C,
618 LLVMValueRef Fn,
619 const char *Name);
620LLVMBasicBlockRef LLVMInsertBasicBlockInContext(LLVMContextRef C,
621 LLVMBasicBlockRef BB,
622 const char *Name);
623
Gordon Henriksenc23b66c2007-09-26 20:56:12 +0000624LLVMBasicBlockRef LLVMAppendBasicBlock(LLVMValueRef Fn, const char *Name);
625LLVMBasicBlockRef LLVMInsertBasicBlock(LLVMBasicBlockRef InsertBeforeBB,
626 const char *Name);
627void LLVMDeleteBasicBlock(LLVMBasicBlockRef BB);
628
Gordon Henriksen265f7802008-03-19 01:11:35 +0000629/* Operations on instructions */
630LLVMBasicBlockRef LLVMGetInstructionParent(LLVMValueRef Inst);
Gordon Henriksen054817c2008-03-19 03:47:18 +0000631LLVMValueRef LLVMGetFirstInstruction(LLVMBasicBlockRef BB);
632LLVMValueRef LLVMGetLastInstruction(LLVMBasicBlockRef BB);
633LLVMValueRef LLVMGetNextInstruction(LLVMValueRef Inst);
634LLVMValueRef LLVMGetPreviousInstruction(LLVMValueRef Inst);
Gordon Henriksen265f7802008-03-19 01:11:35 +0000635
Gordon Henriksen1158c532007-12-29 20:45:00 +0000636/* Operations on call sites */
637void LLVMSetInstructionCallConv(LLVMValueRef Instr, unsigned CC);
638unsigned LLVMGetInstructionCallConv(LLVMValueRef Instr);
Devang Patel4c758ea2008-09-25 21:00:45 +0000639void LLVMAddInstrAttribute(LLVMValueRef Instr, unsigned index, LLVMAttribute);
640void LLVMRemoveInstrAttribute(LLVMValueRef Instr, unsigned index,
641 LLVMAttribute);
Gordon Henriksen2d9cc212008-04-28 17:37:06 +0000642void LLVMSetInstrParamAlignment(LLVMValueRef Instr, unsigned index,
643 unsigned align);
Gordon Henriksen1158c532007-12-29 20:45:00 +0000644
Gordon Henrikseneeb65372008-08-30 16:34:54 +0000645/* Operations on call instructions (only) */
646int LLVMIsTailCall(LLVMValueRef CallInst);
647void LLVMSetTailCall(LLVMValueRef CallInst, int IsTailCall);
648
Gordon Henriksen44dd8fb2007-10-08 18:14:39 +0000649/* Operations on phi nodes */
650void LLVMAddIncoming(LLVMValueRef PhiNode, LLVMValueRef *IncomingValues,
651 LLVMBasicBlockRef *IncomingBlocks, unsigned Count);
652unsigned LLVMCountIncoming(LLVMValueRef PhiNode);
653LLVMValueRef LLVMGetIncomingValue(LLVMValueRef PhiNode, unsigned Index);
654LLVMBasicBlockRef LLVMGetIncomingBlock(LLVMValueRef PhiNode, unsigned Index);
Gordon Henriksenc23b66c2007-09-26 20:56:12 +0000655
656/*===-- Instruction builders ----------------------------------------------===*/
657
658/* An instruction builder represents a point within a basic block, and is the
659 * exclusive means of building instructions using the C interface.
660 */
661
Erick Tryzelaar262332f2009-08-14 00:01:31 +0000662LLVMBuilderRef LLVMCreateBuilderInContext(LLVMContextRef C);
Gordon Henriksena735a9c2008-05-04 12:55:34 +0000663LLVMBuilderRef LLVMCreateBuilder(void);
Gordon Henriksen054817c2008-03-19 03:47:18 +0000664void LLVMPositionBuilder(LLVMBuilderRef Builder, LLVMBasicBlockRef Block,
665 LLVMValueRef Instr);
Gordon Henriksenc23b66c2007-09-26 20:56:12 +0000666void LLVMPositionBuilderBefore(LLVMBuilderRef Builder, LLVMValueRef Instr);
667void LLVMPositionBuilderAtEnd(LLVMBuilderRef Builder, LLVMBasicBlockRef Block);
Gordon Henriksen265f7802008-03-19 01:11:35 +0000668LLVMBasicBlockRef LLVMGetInsertBlock(LLVMBuilderRef Builder);
Chris Lattner3d1f5522008-12-17 21:39:50 +0000669void LLVMClearInsertionPosition(LLVMBuilderRef Builder);
670void LLVMInsertIntoBuilder(LLVMBuilderRef Builder, LLVMValueRef Instr);
Erick Tryzelaar9813bea2009-08-16 02:20:57 +0000671void LLVMInsertIntoBuilderWithName(LLVMBuilderRef Builder, LLVMValueRef Instr,
672 const char *Name);
Gordon Henriksenc23b66c2007-09-26 20:56:12 +0000673void LLVMDisposeBuilder(LLVMBuilderRef Builder);
674
675/* Terminators */
676LLVMValueRef LLVMBuildRetVoid(LLVMBuilderRef);
677LLVMValueRef LLVMBuildRet(LLVMBuilderRef, LLVMValueRef V);
Erick Tryzelaarfd529d72009-08-19 08:36:49 +0000678LLVMValueRef LLVMBuildAggregateRet(LLVMBuilderRef, LLVMValueRef *RetVals,
Erick Tryzelaar3045b8b2009-08-16 02:19:59 +0000679 unsigned N);
Gordon Henriksenc23b66c2007-09-26 20:56:12 +0000680LLVMValueRef LLVMBuildBr(LLVMBuilderRef, LLVMBasicBlockRef Dest);
681LLVMValueRef LLVMBuildCondBr(LLVMBuilderRef, LLVMValueRef If,
682 LLVMBasicBlockRef Then, LLVMBasicBlockRef Else);
683LLVMValueRef LLVMBuildSwitch(LLVMBuilderRef, LLVMValueRef V,
684 LLVMBasicBlockRef Else, unsigned NumCases);
685LLVMValueRef LLVMBuildInvoke(LLVMBuilderRef, LLVMValueRef Fn,
686 LLVMValueRef *Args, unsigned NumArgs,
687 LLVMBasicBlockRef Then, LLVMBasicBlockRef Catch,
688 const char *Name);
689LLVMValueRef LLVMBuildUnwind(LLVMBuilderRef);
690LLVMValueRef LLVMBuildUnreachable(LLVMBuilderRef);
691
Gordon Henriksen097102c2008-01-01 05:50:53 +0000692/* Add a case to the switch instruction */
693void LLVMAddCase(LLVMValueRef Switch, LLVMValueRef OnVal,
694 LLVMBasicBlockRef Dest);
695
Gordon Henriksenc23b66c2007-09-26 20:56:12 +0000696/* Arithmetic */
697LLVMValueRef LLVMBuildAdd(LLVMBuilderRef, LLVMValueRef LHS, LLVMValueRef RHS,
698 const char *Name);
Erick Tryzelaar3045b8b2009-08-16 02:19:59 +0000699LLVMValueRef LLVMBuildNSWAdd(LLVMBuilderRef, LLVMValueRef LHS, LLVMValueRef RHS,
700 const char *Name);
701LLVMValueRef LLVMBuildFAdd(LLVMBuilderRef, LLVMValueRef LHS, LLVMValueRef RHS,
702 const char *Name);
Gordon Henriksenc23b66c2007-09-26 20:56:12 +0000703LLVMValueRef LLVMBuildSub(LLVMBuilderRef, LLVMValueRef LHS, LLVMValueRef RHS,
704 const char *Name);
Erick Tryzelaar3045b8b2009-08-16 02:19:59 +0000705LLVMValueRef LLVMBuildFSub(LLVMBuilderRef, LLVMValueRef LHS, LLVMValueRef RHS,
706 const char *Name);
Gordon Henriksenc23b66c2007-09-26 20:56:12 +0000707LLVMValueRef LLVMBuildMul(LLVMBuilderRef, LLVMValueRef LHS, LLVMValueRef RHS,
708 const char *Name);
Erick Tryzelaar3045b8b2009-08-16 02:19:59 +0000709LLVMValueRef LLVMBuildFMul(LLVMBuilderRef, LLVMValueRef LHS, LLVMValueRef RHS,
710 const char *Name);
Gordon Henriksenc23b66c2007-09-26 20:56:12 +0000711LLVMValueRef LLVMBuildUDiv(LLVMBuilderRef, LLVMValueRef LHS, LLVMValueRef RHS,
712 const char *Name);
713LLVMValueRef LLVMBuildSDiv(LLVMBuilderRef, LLVMValueRef LHS, LLVMValueRef RHS,
714 const char *Name);
Erick Tryzelaar3045b8b2009-08-16 02:19:59 +0000715LLVMValueRef LLVMBuildExactSDiv(LLVMBuilderRef, LLVMValueRef LHS, LLVMValueRef RHS,
716 const char *Name);
Gordon Henriksenc23b66c2007-09-26 20:56:12 +0000717LLVMValueRef LLVMBuildFDiv(LLVMBuilderRef, LLVMValueRef LHS, LLVMValueRef RHS,
718 const char *Name);
719LLVMValueRef LLVMBuildURem(LLVMBuilderRef, LLVMValueRef LHS, LLVMValueRef RHS,
720 const char *Name);
721LLVMValueRef LLVMBuildSRem(LLVMBuilderRef, LLVMValueRef LHS, LLVMValueRef RHS,
722 const char *Name);
723LLVMValueRef LLVMBuildFRem(LLVMBuilderRef, LLVMValueRef LHS, LLVMValueRef RHS,
724 const char *Name);
725LLVMValueRef LLVMBuildShl(LLVMBuilderRef, LLVMValueRef LHS, LLVMValueRef RHS,
726 const char *Name);
727LLVMValueRef LLVMBuildLShr(LLVMBuilderRef, LLVMValueRef LHS, LLVMValueRef RHS,
728 const char *Name);
729LLVMValueRef LLVMBuildAShr(LLVMBuilderRef, LLVMValueRef LHS, LLVMValueRef RHS,
730 const char *Name);
731LLVMValueRef LLVMBuildAnd(LLVMBuilderRef, LLVMValueRef LHS, LLVMValueRef RHS,
732 const char *Name);
733LLVMValueRef LLVMBuildOr(LLVMBuilderRef, LLVMValueRef LHS, LLVMValueRef RHS,
734 const char *Name);
735LLVMValueRef LLVMBuildXor(LLVMBuilderRef, LLVMValueRef LHS, LLVMValueRef RHS,
736 const char *Name);
737LLVMValueRef LLVMBuildNeg(LLVMBuilderRef, LLVMValueRef V, const char *Name);
738LLVMValueRef LLVMBuildNot(LLVMBuilderRef, LLVMValueRef V, const char *Name);
739
740/* Memory */
741LLVMValueRef LLVMBuildMalloc(LLVMBuilderRef, LLVMTypeRef Ty, const char *Name);
742LLVMValueRef LLVMBuildArrayMalloc(LLVMBuilderRef, LLVMTypeRef Ty,
743 LLVMValueRef Val, const char *Name);
744LLVMValueRef LLVMBuildAlloca(LLVMBuilderRef, LLVMTypeRef Ty, const char *Name);
745LLVMValueRef LLVMBuildArrayAlloca(LLVMBuilderRef, LLVMTypeRef Ty,
746 LLVMValueRef Val, const char *Name);
747LLVMValueRef LLVMBuildFree(LLVMBuilderRef, LLVMValueRef PointerVal);
748LLVMValueRef LLVMBuildLoad(LLVMBuilderRef, LLVMValueRef PointerVal,
749 const char *Name);
750LLVMValueRef LLVMBuildStore(LLVMBuilderRef, LLVMValueRef Val, LLVMValueRef Ptr);
751LLVMValueRef LLVMBuildGEP(LLVMBuilderRef B, LLVMValueRef Pointer,
752 LLVMValueRef *Indices, unsigned NumIndices,
753 const char *Name);
Erick Tryzelaar3045b8b2009-08-16 02:19:59 +0000754LLVMValueRef LLVMBuildInBoundsGEP(LLVMBuilderRef B, LLVMValueRef Pointer,
755 LLVMValueRef *Indices, unsigned NumIndices,
756 const char *Name);
757LLVMValueRef LLVMBuildStructGEP(LLVMBuilderRef B, LLVMValueRef Pointer,
758 unsigned Idx, const char *Name);
759LLVMValueRef LLVMBuildGlobalString(LLVMBuilderRef B, const char *Str,
760 const char *Name);
761LLVMValueRef LLVMBuildGlobalStringPtr(LLVMBuilderRef B, const char *Str,
762 const char *Name);
Gordon Henriksenc23b66c2007-09-26 20:56:12 +0000763
764/* Casts */
765LLVMValueRef LLVMBuildTrunc(LLVMBuilderRef, LLVMValueRef Val,
766 LLVMTypeRef DestTy, const char *Name);
767LLVMValueRef LLVMBuildZExt(LLVMBuilderRef, LLVMValueRef Val,
768 LLVMTypeRef DestTy, const char *Name);
769LLVMValueRef LLVMBuildSExt(LLVMBuilderRef, LLVMValueRef Val,
770 LLVMTypeRef DestTy, const char *Name);
771LLVMValueRef LLVMBuildFPToUI(LLVMBuilderRef, LLVMValueRef Val,
772 LLVMTypeRef DestTy, const char *Name);
773LLVMValueRef LLVMBuildFPToSI(LLVMBuilderRef, LLVMValueRef Val,
774 LLVMTypeRef DestTy, const char *Name);
775LLVMValueRef LLVMBuildUIToFP(LLVMBuilderRef, LLVMValueRef Val,
776 LLVMTypeRef DestTy, const char *Name);
777LLVMValueRef LLVMBuildSIToFP(LLVMBuilderRef, LLVMValueRef Val,
778 LLVMTypeRef DestTy, const char *Name);
779LLVMValueRef LLVMBuildFPTrunc(LLVMBuilderRef, LLVMValueRef Val,
780 LLVMTypeRef DestTy, const char *Name);
781LLVMValueRef LLVMBuildFPExt(LLVMBuilderRef, LLVMValueRef Val,
782 LLVMTypeRef DestTy, const char *Name);
783LLVMValueRef LLVMBuildPtrToInt(LLVMBuilderRef, LLVMValueRef Val,
784 LLVMTypeRef DestTy, const char *Name);
785LLVMValueRef LLVMBuildIntToPtr(LLVMBuilderRef, LLVMValueRef Val,
786 LLVMTypeRef DestTy, const char *Name);
787LLVMValueRef LLVMBuildBitCast(LLVMBuilderRef, LLVMValueRef Val,
788 LLVMTypeRef DestTy, const char *Name);
Erick Tryzelaar3045b8b2009-08-16 02:19:59 +0000789LLVMValueRef LLVMBuildZExtOrBitCast(LLVMBuilderRef, LLVMValueRef Val,
790 LLVMTypeRef DestTy, const char *Name);
791LLVMValueRef LLVMBuildSExtOrBitCast(LLVMBuilderRef, LLVMValueRef Val,
792 LLVMTypeRef DestTy, const char *Name);
793LLVMValueRef LLVMBuildTruncOrBitCast(LLVMBuilderRef, LLVMValueRef Val,
794 LLVMTypeRef DestTy, const char *Name);
795LLVMValueRef LLVMBuildPointerCast(LLVMBuilderRef, LLVMValueRef Val,
796 LLVMTypeRef DestTy, const char *Name);
797LLVMValueRef LLVMBuildIntCast(LLVMBuilderRef, LLVMValueRef Val,
798 LLVMTypeRef DestTy, const char *Name);
799LLVMValueRef LLVMBuildFPCast(LLVMBuilderRef, LLVMValueRef Val,
800 LLVMTypeRef DestTy, const char *Name);
Gordon Henriksenc23b66c2007-09-26 20:56:12 +0000801
802/* Comparisons */
803LLVMValueRef LLVMBuildICmp(LLVMBuilderRef, LLVMIntPredicate Op,
804 LLVMValueRef LHS, LLVMValueRef RHS,
805 const char *Name);
806LLVMValueRef LLVMBuildFCmp(LLVMBuilderRef, LLVMRealPredicate Op,
807 LLVMValueRef LHS, LLVMValueRef RHS,
808 const char *Name);
809
810/* Miscellaneous instructions */
811LLVMValueRef LLVMBuildPhi(LLVMBuilderRef, LLVMTypeRef Ty, const char *Name);
812LLVMValueRef LLVMBuildCall(LLVMBuilderRef, LLVMValueRef Fn,
813 LLVMValueRef *Args, unsigned NumArgs,
814 const char *Name);
815LLVMValueRef LLVMBuildSelect(LLVMBuilderRef, LLVMValueRef If,
816 LLVMValueRef Then, LLVMValueRef Else,
817 const char *Name);
818LLVMValueRef LLVMBuildVAArg(LLVMBuilderRef, LLVMValueRef List, LLVMTypeRef Ty,
819 const char *Name);
820LLVMValueRef LLVMBuildExtractElement(LLVMBuilderRef, LLVMValueRef VecVal,
821 LLVMValueRef Index, const char *Name);
822LLVMValueRef LLVMBuildInsertElement(LLVMBuilderRef, LLVMValueRef VecVal,
823 LLVMValueRef EltVal, LLVMValueRef Index,
824 const char *Name);
825LLVMValueRef LLVMBuildShuffleVector(LLVMBuilderRef, LLVMValueRef V1,
826 LLVMValueRef V2, LLVMValueRef Mask,
827 const char *Name);
Dan Gohmand5104a52008-11-03 22:55:43 +0000828LLVMValueRef LLVMBuildExtractValue(LLVMBuilderRef, LLVMValueRef AggVal,
829 unsigned Index, const char *Name);
830LLVMValueRef LLVMBuildInsertValue(LLVMBuilderRef, LLVMValueRef AggVal,
831 LLVMValueRef EltVal, unsigned Index,
832 const char *Name);
Gordon Henriksen76a03742007-09-18 03:18:57 +0000833
Erick Tryzelaar3045b8b2009-08-16 02:19:59 +0000834LLVMValueRef LLVMBuildIsNull(LLVMBuilderRef, LLVMValueRef Val,
835 const char *Name);
836LLVMValueRef LLVMBuildIsNotNull(LLVMBuilderRef, LLVMValueRef Val,
837 const char *Name);
838LLVMValueRef LLVMBuildPtrDiff(LLVMBuilderRef, LLVMValueRef LHS,
839 LLVMValueRef RHS, const char *Name);
840
Gordon Henriksen34eb6d82007-12-19 22:30:40 +0000841
Gordon Henriksen0a68fe22007-12-12 01:04:30 +0000842/*===-- Module providers --------------------------------------------------===*/
843
844/* Encapsulates the module M in a module provider, taking ownership of the
845 * module.
846 * See the constructor llvm::ExistingModuleProvider::ExistingModuleProvider.
847 */
848LLVMModuleProviderRef
849LLVMCreateModuleProviderForExistingModule(LLVMModuleRef M);
850
851/* Destroys the module provider MP as well as the contained module.
852 * See the destructor llvm::ModuleProvider::~ModuleProvider.
853 */
854void LLVMDisposeModuleProvider(LLVMModuleProviderRef MP);
855
Gordon Henriksen34eb6d82007-12-19 22:30:40 +0000856
857/*===-- Memory buffers ----------------------------------------------------===*/
858
859int LLVMCreateMemoryBufferWithContentsOfFile(const char *Path,
860 LLVMMemoryBufferRef *OutMemBuf,
861 char **OutMessage);
862int LLVMCreateMemoryBufferWithSTDIN(LLVMMemoryBufferRef *OutMemBuf,
863 char **OutMessage);
864void LLVMDisposeMemoryBuffer(LLVMMemoryBufferRef MemBuf);
865
Gordon Henriksen878114b2008-03-16 04:20:44 +0000866
867/*===-- Pass Managers -----------------------------------------------------===*/
868
869/** Constructs a new whole-module pass pipeline. This type of pipeline is
870 suitable for link-time optimization and whole-module transformations.
871 See llvm::PassManager::PassManager. */
Gordon Henriksena735a9c2008-05-04 12:55:34 +0000872LLVMPassManagerRef LLVMCreatePassManager(void);
Gordon Henriksen878114b2008-03-16 04:20:44 +0000873
874/** Constructs a new function-by-function pass pipeline over the module
875 provider. It does not take ownership of the module provider. This type of
876 pipeline is suitable for code generation and JIT compilation tasks.
877 See llvm::FunctionPassManager::FunctionPassManager. */
878LLVMPassManagerRef LLVMCreateFunctionPassManager(LLVMModuleProviderRef MP);
879
880/** Initializes, executes on the provided module, and finalizes all of the
881 passes scheduled in the pass manager. Returns 1 if any of the passes
882 modified the module, 0 otherwise. See llvm::PassManager::run(Module&). */
883int LLVMRunPassManager(LLVMPassManagerRef PM, LLVMModuleRef M);
884
885/** Initializes all of the function passes scheduled in the function pass
886 manager. Returns 1 if any of the passes modified the module, 0 otherwise.
887 See llvm::FunctionPassManager::doInitialization. */
888int LLVMInitializeFunctionPassManager(LLVMPassManagerRef FPM);
889
890/** Executes all of the function passes scheduled in the function pass manager
891 on the provided function. Returns 1 if any of the passes modified the
892 function, false otherwise.
893 See llvm::FunctionPassManager::run(Function&). */
894int LLVMRunFunctionPassManager(LLVMPassManagerRef FPM, LLVMValueRef F);
895
896/** Finalizes all of the function passes scheduled in in the function pass
897 manager. Returns 1 if any of the passes modified the module, 0 otherwise.
898 See llvm::FunctionPassManager::doFinalization. */
899int LLVMFinalizeFunctionPassManager(LLVMPassManagerRef FPM);
900
901/** Frees the memory of a pass pipeline. For function pipelines, does not free
902 the module provider.
903 See llvm::PassManagerBase::~PassManagerBase. */
904void LLVMDisposePassManager(LLVMPassManagerRef PM);
905
906
Gordon Henriksen76a03742007-09-18 03:18:57 +0000907#ifdef __cplusplus
908}
Gordon Henriksen76a03742007-09-18 03:18:57 +0000909
Gordon Henriksen7330acd2007-10-05 23:59:36 +0000910namespace llvm {
Gordon Henriksen0a68fe22007-12-12 01:04:30 +0000911 class ModuleProvider;
Gordon Henriksen34eb6d82007-12-19 22:30:40 +0000912 class MemoryBuffer;
Gordon Henriksen96571492008-03-16 15:55:43 +0000913 class PassManagerBase;
Gordon Henriksen0a68fe22007-12-12 01:04:30 +0000914
Gordon Henriksen34eb6d82007-12-19 22:30:40 +0000915 #define DEFINE_SIMPLE_CONVERSION_FUNCTIONS(ty, ref) \
916 inline ty *unwrap(ref P) { \
917 return reinterpret_cast<ty*>(P); \
918 } \
919 \
920 inline ref wrap(const ty *P) { \
921 return reinterpret_cast<ref>(const_cast<ty*>(P)); \
922 }
Gordon Henriksen7330acd2007-10-05 23:59:36 +0000923
Gordon Henriksen878114b2008-03-16 04:20:44 +0000924 #define DEFINE_ISA_CONVERSION_FUNCTIONS(ty, ref) \
925 DEFINE_SIMPLE_CONVERSION_FUNCTIONS(ty, ref) \
926 \
927 template<typename T> \
928 inline T *unwrap(ref P) { \
929 return cast<T>(unwrap(P)); \
930 }
931
932 #define DEFINE_STDCXX_CONVERSION_FUNCTIONS(ty, ref) \
933 DEFINE_SIMPLE_CONVERSION_FUNCTIONS(ty, ref) \
934 \
935 template<typename T> \
936 inline T *unwrap(ref P) { \
937 T *Q = dynamic_cast<T*>(unwrap(P)); \
938 assert(Q && "Invalid cast!"); \
939 return Q; \
940 }
941
942 DEFINE_ISA_CONVERSION_FUNCTIONS (Type, LLVMTypeRef )
943 DEFINE_ISA_CONVERSION_FUNCTIONS (Value, LLVMValueRef )
Gordon Henriksen823f9732007-12-27 18:25:59 +0000944 DEFINE_SIMPLE_CONVERSION_FUNCTIONS(Module, LLVMModuleRef )
945 DEFINE_SIMPLE_CONVERSION_FUNCTIONS(BasicBlock, LLVMBasicBlockRef )
Eric Christopher59278832008-08-08 19:39:37 +0000946 DEFINE_SIMPLE_CONVERSION_FUNCTIONS(IRBuilder<>, LLVMBuilderRef )
Gordon Henriksen823f9732007-12-27 18:25:59 +0000947 DEFINE_SIMPLE_CONVERSION_FUNCTIONS(PATypeHolder, LLVMTypeHandleRef )
948 DEFINE_SIMPLE_CONVERSION_FUNCTIONS(ModuleProvider, LLVMModuleProviderRef)
949 DEFINE_SIMPLE_CONVERSION_FUNCTIONS(MemoryBuffer, LLVMMemoryBufferRef )
Owen Anderson6773d382009-07-01 16:58:40 +0000950 DEFINE_SIMPLE_CONVERSION_FUNCTIONS(LLVMContext, LLVMContextRef )
Gordon Henriksen878114b2008-03-16 04:20:44 +0000951 DEFINE_STDCXX_CONVERSION_FUNCTIONS(PassManagerBase, LLVMPassManagerRef )
Gordon Henriksen7330acd2007-10-05 23:59:36 +0000952
Gordon Henriksen878114b2008-03-16 04:20:44 +0000953 #undef DEFINE_STDCXX_CONVERSION_FUNCTIONS
954 #undef DEFINE_ISA_CONVERSION_FUNCTIONS
Gordon Henriksen34eb6d82007-12-19 22:30:40 +0000955 #undef DEFINE_SIMPLE_CONVERSION_FUNCTIONS
Erick Tryzelaar262332f2009-08-14 00:01:31 +0000956
957 /* Specialized opaque context conversions.
958 */
959 inline LLVMContext **unwrap(LLVMContextRef* Tys) {
960 return reinterpret_cast<LLVMContext**>(Tys);
961 }
962
963 inline LLVMContextRef *wrap(const LLVMContext **Tys) {
964 return reinterpret_cast<LLVMContextRef*>(const_cast<LLVMContext**>(Tys));
965 }
Gordon Henriksen7330acd2007-10-05 23:59:36 +0000966
Gordon Henriksen34eb6d82007-12-19 22:30:40 +0000967 /* Specialized opaque type conversions.
968 */
Gordon Henriksen7330acd2007-10-05 23:59:36 +0000969 inline Type **unwrap(LLVMTypeRef* Tys) {
970 return reinterpret_cast<Type**>(Tys);
971 }
972
Gordon Henriksen7330acd2007-10-05 23:59:36 +0000973 inline LLVMTypeRef *wrap(const Type **Tys) {
974 return reinterpret_cast<LLVMTypeRef*>(const_cast<Type**>(Tys));
975 }
976
Gordon Henriksen34eb6d82007-12-19 22:30:40 +0000977 /* Specialized opaque value conversions.
Gordon Henriksen7330acd2007-10-05 23:59:36 +0000978 */
Gordon Henriksen7330acd2007-10-05 23:59:36 +0000979 inline Value **unwrap(LLVMValueRef *Vals) {
980 return reinterpret_cast<Value**>(Vals);
981 }
982
983 template<typename T>
984 inline T **unwrap(LLVMValueRef *Vals, unsigned Length) {
985 #if DEBUG
Chris Lattnerb7971152009-07-10 18:28:19 +0000986 for (LLVMValueRef *I = Vals, *E = Vals + Length; I != E; ++I)
Gordon Henriksen7330acd2007-10-05 23:59:36 +0000987 cast<T>(*I);
988 #endif
989 return reinterpret_cast<T**>(Vals);
990 }
991
Gordon Henriksen7330acd2007-10-05 23:59:36 +0000992 inline LLVMValueRef *wrap(const Value **Vals) {
993 return reinterpret_cast<LLVMValueRef*>(const_cast<Value**>(Vals));
994 }
Gordon Henriksen7330acd2007-10-05 23:59:36 +0000995}
996
997#endif /* !defined(__cplusplus) */
998
999#endif /* !defined(LLVM_C_CORE_H) */