blob: e1a99531b55773317359ad4104085f2dbdcdf153 [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,
Dale Johannesen2aaf5392009-08-26 01:08:21 +0000112 LLVMNakedAttribute = 1<<24,
113 LLVMInlineHintAttribute = 1<<25
Devang Patel4c758ea2008-09-25 21:00:45 +0000114} LLVMAttribute;
Gordon Henriksen2d9cc212008-04-28 17:37:06 +0000115
116typedef enum {
Gordon Henriksen4a4d7352007-12-30 17:46:33 +0000117 LLVMVoidTypeKind, /**< type with no size */
118 LLVMFloatTypeKind, /**< 32 bit floating point type */
119 LLVMDoubleTypeKind, /**< 64 bit floating point type */
120 LLVMX86_FP80TypeKind, /**< 80 bit floating point type (X87) */
121 LLVMFP128TypeKind, /**< 128 bit floating point type (112-bit mantissa)*/
122 LLVMPPC_FP128TypeKind, /**< 128 bit floating point type (two 64-bits) */
123 LLVMLabelTypeKind, /**< Labels */
124 LLVMIntegerTypeKind, /**< Arbitrary bit width integers */
125 LLVMFunctionTypeKind, /**< Functions */
126 LLVMStructTypeKind, /**< Structures */
127 LLVMArrayTypeKind, /**< Arrays */
128 LLVMPointerTypeKind, /**< Pointers */
129 LLVMOpaqueTypeKind, /**< Opaque: type with unknown structure */
Chris Lattnerdac44ec2009-07-15 22:00:31 +0000130 LLVMVectorTypeKind, /**< SIMD 'packed' format, or other vector type */
131 LLVMMetadataTypeKind /**< Metadata */
Gordon Henriksen76a03742007-09-18 03:18:57 +0000132} LLVMTypeKind;
133
134typedef enum {
Gordon Henriksen4a4d7352007-12-30 17:46:33 +0000135 LLVMExternalLinkage, /**< Externally visible function */
Chris Lattner2dba0f02009-04-13 06:25:37 +0000136 LLVMAvailableExternallyLinkage,
Duncan Sands12da8ce2009-03-07 15:45:40 +0000137 LLVMLinkOnceAnyLinkage, /**< Keep one copy of function when linking (inline)*/
138 LLVMLinkOnceODRLinkage, /**< Same, but only replaced by something
139 equivalent. */
140 LLVMWeakAnyLinkage, /**< Keep one copy of function when linking (weak) */
141 LLVMWeakODRLinkage, /**< Same, but only replaced by something
142 equivalent. */
Gordon Henriksen4a4d7352007-12-30 17:46:33 +0000143 LLVMAppendingLinkage, /**< Special purpose, only applies to global arrays */
144 LLVMInternalLinkage, /**< Rename collisions when linking (static
145 functions) */
Duncan Sands12da8ce2009-03-07 15:45:40 +0000146 LLVMPrivateLinkage, /**< Like Internal, but omit from symbol table */
Gordon Henriksen4a4d7352007-12-30 17:46:33 +0000147 LLVMDLLImportLinkage, /**< Function to be imported from DLL */
148 LLVMDLLExportLinkage, /**< Function to be accessible from DLL */
Duncan Sandse2881052009-03-11 08:08:06 +0000149 LLVMExternalWeakLinkage,/**< ExternalWeak linkage description */
Duncan Sands12da8ce2009-03-07 15:45:40 +0000150 LLVMGhostLinkage, /**< Stand-in functions for streaming fns from
Gordon Henriksen4a4d7352007-12-30 17:46:33 +0000151 bitcode */
Bill Wendling002b1672009-07-20 18:22:52 +0000152 LLVMCommonLinkage, /**< Tentative definitions */
153 LLVMLinkerPrivateLinkage /**< Like Private, but linker removes. */
Gordon Henriksen76a03742007-09-18 03:18:57 +0000154} LLVMLinkage;
155
156typedef enum {
Gordon Henriksen4a4d7352007-12-30 17:46:33 +0000157 LLVMDefaultVisibility, /**< The GV is visible */
158 LLVMHiddenVisibility, /**< The GV is hidden */
159 LLVMProtectedVisibility /**< The GV is protected */
Gordon Henriksen76a03742007-09-18 03:18:57 +0000160} LLVMVisibility;
161
Gordon Henriksenc23b66c2007-09-26 20:56:12 +0000162typedef enum {
163 LLVMCCallConv = 0,
164 LLVMFastCallConv = 8,
165 LLVMColdCallConv = 9,
166 LLVMX86StdcallCallConv = 64,
167 LLVMX86FastcallCallConv = 65
168} LLVMCallConv;
169
170typedef enum {
Gordon Henriksen4a4d7352007-12-30 17:46:33 +0000171 LLVMIntEQ = 32, /**< equal */
172 LLVMIntNE, /**< not equal */
173 LLVMIntUGT, /**< unsigned greater than */
174 LLVMIntUGE, /**< unsigned greater or equal */
175 LLVMIntULT, /**< unsigned less than */
176 LLVMIntULE, /**< unsigned less or equal */
177 LLVMIntSGT, /**< signed greater than */
178 LLVMIntSGE, /**< signed greater or equal */
179 LLVMIntSLT, /**< signed less than */
180 LLVMIntSLE /**< signed less or equal */
Gordon Henriksenc23b66c2007-09-26 20:56:12 +0000181} LLVMIntPredicate;
182
183typedef enum {
Gordon Henriksen4a4d7352007-12-30 17:46:33 +0000184 LLVMRealPredicateFalse, /**< Always false (always folded) */
185 LLVMRealOEQ, /**< True if ordered and equal */
186 LLVMRealOGT, /**< True if ordered and greater than */
187 LLVMRealOGE, /**< True if ordered and greater than or equal */
188 LLVMRealOLT, /**< True if ordered and less than */
189 LLVMRealOLE, /**< True if ordered and less than or equal */
190 LLVMRealONE, /**< True if ordered and operands are unequal */
191 LLVMRealORD, /**< True if ordered (no nans) */
192 LLVMRealUNO, /**< True if unordered: isnan(X) | isnan(Y) */
193 LLVMRealUEQ, /**< True if unordered or equal */
194 LLVMRealUGT, /**< True if unordered or greater than */
195 LLVMRealUGE, /**< True if unordered, greater than, or equal */
196 LLVMRealULT, /**< True if unordered or less than */
197 LLVMRealULE, /**< True if unordered, less than, or equal */
198 LLVMRealUNE, /**< True if unordered or not equal */
199 LLVMRealPredicateTrue /**< Always true (always folded) */
Gordon Henriksenc23b66c2007-09-26 20:56:12 +0000200} LLVMRealPredicate;
201
Gordon Henriksen76a03742007-09-18 03:18:57 +0000202
Gordon Henriksen34eb6d82007-12-19 22:30:40 +0000203/*===-- Error handling ----------------------------------------------------===*/
204
205void LLVMDisposeMessage(char *Message);
206
207
Gordon Henriksen76a03742007-09-18 03:18:57 +0000208/*===-- Modules -----------------------------------------------------------===*/
209
Owen Anderson6773d382009-07-01 16:58:40 +0000210/* Create and destroy contexts. */
211LLVMContextRef LLVMContextCreate();
Owen Andersonf7691d32009-07-02 00:16:38 +0000212LLVMContextRef LLVMGetGlobalContext();
Owen Anderson6773d382009-07-01 16:58:40 +0000213void LLVMContextDispose(LLVMContextRef C);
214
Gordon Henriksen76a03742007-09-18 03:18:57 +0000215/* Create and destroy modules. */
Gordon Henriksena49d4352008-03-07 19:13:06 +0000216/** See llvm::Module::Module. */
Gordon Henriksen76a03742007-09-18 03:18:57 +0000217LLVMModuleRef LLVMModuleCreateWithName(const char *ModuleID);
Owen Anderson31d44e42009-07-02 07:17:57 +0000218LLVMModuleRef LLVMModuleCreateWithNameInContext(const char *ModuleID,
219 LLVMContextRef C);
Gordon Henriksena49d4352008-03-07 19:13:06 +0000220
221/** See llvm::Module::~Module. */
Gordon Henriksen76a03742007-09-18 03:18:57 +0000222void LLVMDisposeModule(LLVMModuleRef M);
223
Gordon Henriksena49d4352008-03-07 19:13:06 +0000224/** Data layout. See Module::getDataLayout. */
Gordon Henriksen05568bb2007-12-27 20:13:47 +0000225const char *LLVMGetDataLayout(LLVMModuleRef M);
226void LLVMSetDataLayout(LLVMModuleRef M, const char *Triple);
227
Gordon Henriksena49d4352008-03-07 19:13:06 +0000228/** Target triple. See Module::getTargetTriple. */
Gordon Henriksen05568bb2007-12-27 20:13:47 +0000229const char *LLVMGetTarget(LLVMModuleRef M);
230void LLVMSetTarget(LLVMModuleRef M, const char *Triple);
231
Gordon Henriksena49d4352008-03-07 19:13:06 +0000232/** See Module::addTypeName. */
Gordon Henriksen76a03742007-09-18 03:18:57 +0000233int LLVMAddTypeName(LLVMModuleRef M, const char *Name, LLVMTypeRef Ty);
Gordon Henriksenc23b66c2007-09-26 20:56:12 +0000234void LLVMDeleteTypeName(LLVMModuleRef M, const char *Name);
Chris Lattner7f318242009-07-06 17:29:59 +0000235LLVMTypeRef LLVMGetTypeByName(LLVMModuleRef M, const char *Name);
Gordon Henriksen76a03742007-09-18 03:18:57 +0000236
Gordon Henriksen6c6075e2008-03-14 23:58:56 +0000237/** See Module::dump. */
238void LLVMDumpModule(LLVMModuleRef M);
239
Gordon Henriksen76a03742007-09-18 03:18:57 +0000240
Gordon Henriksenc23b66c2007-09-26 20:56:12 +0000241/*===-- Types -------------------------------------------------------------===*/
Gordon Henriksen76a03742007-09-18 03:18:57 +0000242
243/* LLVM types conform to the following hierarchy:
244 *
245 * types:
246 * integer type
247 * real type
248 * function type
249 * sequence types:
250 * array type
251 * pointer type
252 * vector type
253 * void type
254 * label type
255 * opaque type
256 */
257
Gordon Henriksena49d4352008-03-07 19:13:06 +0000258/** See llvm::LLVMTypeKind::getTypeID. */
Gordon Henriksen76a03742007-09-18 03:18:57 +0000259LLVMTypeKind LLVMGetTypeKind(LLVMTypeRef Ty);
Gordon Henriksena49d4352008-03-07 19:13:06 +0000260
Erick Tryzelaar262332f2009-08-14 00:01:31 +0000261/** See llvm::LLVMType::getContext. */
262LLVMContextRef LLVMGetTypeContext(LLVMTypeRef Ty);
263
Gordon Henriksen76a03742007-09-18 03:18:57 +0000264/* Operations on integer types */
Erick Tryzelaar262332f2009-08-14 00:01:31 +0000265LLVMTypeRef LLVMInt1TypeInContext(LLVMContextRef C);
266LLVMTypeRef LLVMInt8TypeInContext(LLVMContextRef C);
267LLVMTypeRef LLVMInt16TypeInContext(LLVMContextRef C);
268LLVMTypeRef LLVMInt32TypeInContext(LLVMContextRef C);
269LLVMTypeRef LLVMInt64TypeInContext(LLVMContextRef C);
270LLVMTypeRef LLVMIntTypeInContext(LLVMContextRef C, unsigned NumBits);
271
Gordon Henriksena735a9c2008-05-04 12:55:34 +0000272LLVMTypeRef LLVMInt1Type(void);
273LLVMTypeRef LLVMInt8Type(void);
274LLVMTypeRef LLVMInt16Type(void);
275LLVMTypeRef LLVMInt32Type(void);
276LLVMTypeRef LLVMInt64Type(void);
Gordon Henriksened7beaa2007-10-06 16:05:20 +0000277LLVMTypeRef LLVMIntType(unsigned NumBits);
Gordon Henriksenc23b66c2007-09-26 20:56:12 +0000278unsigned LLVMGetIntTypeWidth(LLVMTypeRef IntegerTy);
Gordon Henriksen76a03742007-09-18 03:18:57 +0000279
280/* Operations on real types */
Erick Tryzelaar262332f2009-08-14 00:01:31 +0000281LLVMTypeRef LLVMFloatTypeInContext(LLVMContextRef C);
282LLVMTypeRef LLVMDoubleTypeInContext(LLVMContextRef C);
283LLVMTypeRef LLVMX86FP80TypeInContext(LLVMContextRef C);
284LLVMTypeRef LLVMFP128TypeInContext(LLVMContextRef C);
285LLVMTypeRef LLVMPPCFP128TypeInContext(LLVMContextRef C);
286
Gordon Henriksena735a9c2008-05-04 12:55:34 +0000287LLVMTypeRef LLVMFloatType(void);
288LLVMTypeRef LLVMDoubleType(void);
289LLVMTypeRef LLVMX86FP80Type(void);
290LLVMTypeRef LLVMFP128Type(void);
291LLVMTypeRef LLVMPPCFP128Type(void);
Gordon Henriksen76a03742007-09-18 03:18:57 +0000292
293/* Operations on function types */
Gordon Henriksened7beaa2007-10-06 16:05:20 +0000294LLVMTypeRef LLVMFunctionType(LLVMTypeRef ReturnType,
295 LLVMTypeRef *ParamTypes, unsigned ParamCount,
296 int IsVarArg);
Gordon Henriksen76a03742007-09-18 03:18:57 +0000297int LLVMIsFunctionVarArg(LLVMTypeRef FunctionTy);
Gordon Henriksenc23b66c2007-09-26 20:56:12 +0000298LLVMTypeRef LLVMGetReturnType(LLVMTypeRef FunctionTy);
299unsigned LLVMCountParamTypes(LLVMTypeRef FunctionTy);
300void LLVMGetParamTypes(LLVMTypeRef FunctionTy, LLVMTypeRef *Dest);
Gordon Henriksen76a03742007-09-18 03:18:57 +0000301
302/* Operations on struct types */
Erick Tryzelaar262332f2009-08-14 00:01:31 +0000303LLVMTypeRef LLVMStructTypeInContext(LLVMContextRef C, LLVMTypeRef *ElementTypes,
304 unsigned ElementCount, int Packed);
Gordon Henriksened7beaa2007-10-06 16:05:20 +0000305LLVMTypeRef LLVMStructType(LLVMTypeRef *ElementTypes, unsigned ElementCount,
306 int Packed);
Gordon Henriksenc23b66c2007-09-26 20:56:12 +0000307unsigned LLVMCountStructElementTypes(LLVMTypeRef StructTy);
Gordon Henriksen76a03742007-09-18 03:18:57 +0000308void LLVMGetStructElementTypes(LLVMTypeRef StructTy, LLVMTypeRef *Dest);
309int LLVMIsPackedStruct(LLVMTypeRef StructTy);
310
311/* Operations on array, pointer, and vector types (sequence types) */
Gordon Henriksened7beaa2007-10-06 16:05:20 +0000312LLVMTypeRef LLVMArrayType(LLVMTypeRef ElementType, unsigned ElementCount);
Gordon Henriksen5a3fe032007-12-17 16:08:32 +0000313LLVMTypeRef LLVMPointerType(LLVMTypeRef ElementType, unsigned AddressSpace);
Gordon Henriksened7beaa2007-10-06 16:05:20 +0000314LLVMTypeRef LLVMVectorType(LLVMTypeRef ElementType, unsigned ElementCount);
Gordon Henriksen76a03742007-09-18 03:18:57 +0000315
316LLVMTypeRef LLVMGetElementType(LLVMTypeRef Ty);
317unsigned LLVMGetArrayLength(LLVMTypeRef ArrayTy);
Gordon Henriksen5a3fe032007-12-17 16:08:32 +0000318unsigned LLVMGetPointerAddressSpace(LLVMTypeRef PointerTy);
Gordon Henriksen76a03742007-09-18 03:18:57 +0000319unsigned LLVMGetVectorSize(LLVMTypeRef VectorTy);
320
321/* Operations on other types */
Erick Tryzelaar262332f2009-08-14 00:01:31 +0000322LLVMTypeRef LLVMVoidTypeInContext(LLVMContextRef C);
323LLVMTypeRef LLVMLabelTypeInContext(LLVMContextRef C);
324LLVMTypeRef LLVMOpaqueTypeInContext(LLVMContextRef C);
325
Gordon Henriksena735a9c2008-05-04 12:55:34 +0000326LLVMTypeRef LLVMVoidType(void);
327LLVMTypeRef LLVMLabelType(void);
328LLVMTypeRef LLVMOpaqueType(void);
Gordon Henriksen76a03742007-09-18 03:18:57 +0000329
Gordon Henriksenffb48762007-10-07 00:13:35 +0000330/* Operations on type handles */
331LLVMTypeHandleRef LLVMCreateTypeHandle(LLVMTypeRef PotentiallyAbstractTy);
332void LLVMRefineType(LLVMTypeRef AbstractTy, LLVMTypeRef ConcreteTy);
333LLVMTypeRef LLVMResolveTypeHandle(LLVMTypeHandleRef TypeHandle);
334void LLVMDisposeTypeHandle(LLVMTypeHandleRef TypeHandle);
335
Gordon Henriksen76a03742007-09-18 03:18:57 +0000336
337/*===-- Values ------------------------------------------------------------===*/
338
339/* The bulk of LLVM's object model consists of values, which comprise a very
340 * rich type hierarchy.
Gordon Henriksen76a03742007-09-18 03:18:57 +0000341 */
342
Gordon Henriksen29e38942008-12-19 18:39:45 +0000343#define LLVM_FOR_EACH_VALUE_SUBCLASS(macro) \
344 macro(Argument) \
345 macro(BasicBlock) \
346 macro(InlineAsm) \
347 macro(User) \
348 macro(Constant) \
349 macro(ConstantAggregateZero) \
350 macro(ConstantArray) \
351 macro(ConstantExpr) \
352 macro(ConstantFP) \
353 macro(ConstantInt) \
354 macro(ConstantPointerNull) \
355 macro(ConstantStruct) \
356 macro(ConstantVector) \
357 macro(GlobalValue) \
358 macro(Function) \
359 macro(GlobalAlias) \
360 macro(GlobalVariable) \
361 macro(UndefValue) \
362 macro(Instruction) \
363 macro(BinaryOperator) \
364 macro(CallInst) \
365 macro(IntrinsicInst) \
366 macro(DbgInfoIntrinsic) \
367 macro(DbgDeclareInst) \
368 macro(DbgFuncStartInst) \
369 macro(DbgRegionEndInst) \
370 macro(DbgRegionStartInst) \
371 macro(DbgStopPointInst) \
372 macro(EHSelectorInst) \
373 macro(MemIntrinsic) \
374 macro(MemCpyInst) \
375 macro(MemMoveInst) \
376 macro(MemSetInst) \
377 macro(CmpInst) \
378 macro(FCmpInst) \
379 macro(ICmpInst) \
Gordon Henriksen29e38942008-12-19 18:39:45 +0000380 macro(ExtractElementInst) \
381 macro(GetElementPtrInst) \
382 macro(InsertElementInst) \
383 macro(InsertValueInst) \
384 macro(PHINode) \
385 macro(SelectInst) \
386 macro(ShuffleVectorInst) \
387 macro(StoreInst) \
388 macro(TerminatorInst) \
389 macro(BranchInst) \
390 macro(InvokeInst) \
391 macro(ReturnInst) \
392 macro(SwitchInst) \
393 macro(UnreachableInst) \
394 macro(UnwindInst) \
395 macro(UnaryInstruction) \
396 macro(AllocationInst) \
Gordon Henriksen05a868f2008-12-19 18:51:17 +0000397 macro(AllocaInst) \
398 macro(MallocInst) \
Gordon Henriksen29e38942008-12-19 18:39:45 +0000399 macro(CastInst) \
Gordon Henriksen05a868f2008-12-19 18:51:17 +0000400 macro(BitCastInst) \
401 macro(FPExtInst) \
402 macro(FPToSIInst) \
403 macro(FPToUIInst) \
404 macro(FPTruncInst) \
405 macro(IntToPtrInst) \
406 macro(PtrToIntInst) \
407 macro(SExtInst) \
408 macro(SIToFPInst) \
409 macro(TruncInst) \
410 macro(UIToFPInst) \
411 macro(ZExtInst) \
412 macro(ExtractValueInst) \
413 macro(FreeInst) \
414 macro(LoadInst) \
415 macro(VAArgInst)
Gordon Henriksen29e38942008-12-19 18:39:45 +0000416
Gordon Henriksen76a03742007-09-18 03:18:57 +0000417/* Operations on all values */
Gordon Henriksenc23b66c2007-09-26 20:56:12 +0000418LLVMTypeRef LLVMTypeOf(LLVMValueRef Val);
Gordon Henriksen76a03742007-09-18 03:18:57 +0000419const char *LLVMGetValueName(LLVMValueRef Val);
420void LLVMSetValueName(LLVMValueRef Val, const char *Name);
Gordon Henriksen1d0d24c2007-10-06 00:08:49 +0000421void LLVMDumpValue(LLVMValueRef Val);
Gordon Henriksen76a03742007-09-18 03:18:57 +0000422
Gordon Henriksen29e38942008-12-19 18:39:45 +0000423/* Conversion functions. Return the input value if it is an instance of the
424 specified class, otherwise NULL. See llvm::dyn_cast_or_null<>. */
425#define LLVM_DECLARE_VALUE_CAST(name) \
426 LLVMValueRef LLVMIsA##name(LLVMValueRef Val);
427LLVM_FOR_EACH_VALUE_SUBCLASS(LLVM_DECLARE_VALUE_CAST)
428
Gordon Henriksen76a03742007-09-18 03:18:57 +0000429/* Operations on constants of any type */
Gordon Henriksen1046c732007-10-06 15:11:06 +0000430LLVMValueRef LLVMConstNull(LLVMTypeRef Ty); /* all zeroes */
431LLVMValueRef LLVMConstAllOnes(LLVMTypeRef Ty); /* only for int/vector */
Gordon Henriksen76a03742007-09-18 03:18:57 +0000432LLVMValueRef LLVMGetUndef(LLVMTypeRef Ty);
Gordon Henriksendc88c062007-09-18 18:07:51 +0000433int LLVMIsConstant(LLVMValueRef Val);
Gordon Henriksen76a03742007-09-18 03:18:57 +0000434int LLVMIsNull(LLVMValueRef Val);
Gordon Henriksendc88c062007-09-18 18:07:51 +0000435int LLVMIsUndef(LLVMValueRef Val);
Chris Lattner7f318242009-07-06 17:29:59 +0000436LLVMValueRef LLVMConstPointerNull(LLVMTypeRef Ty);
Gordon Henriksen76a03742007-09-18 03:18:57 +0000437
438/* Operations on scalar constants */
Gordon Henriksen1046c732007-10-06 15:11:06 +0000439LLVMValueRef LLVMConstInt(LLVMTypeRef IntTy, unsigned long long N,
440 int SignExtend);
Erick Tryzelaardd991352009-08-16 23:36:46 +0000441LLVMValueRef LLVMConstIntOfString(LLVMTypeRef IntTy, const char *Text,
442 uint8_t Radix);
443LLVMValueRef LLVMConstIntOfStringAndSize(LLVMTypeRef IntTy, const char *Text,
444 unsigned SLen, uint8_t Radix);
Gordon Henriksen1046c732007-10-06 15:11:06 +0000445LLVMValueRef LLVMConstReal(LLVMTypeRef RealTy, double N);
Gordon Henriksen931e1212008-02-02 01:07:50 +0000446LLVMValueRef LLVMConstRealOfString(LLVMTypeRef RealTy, const char *Text);
Erick Tryzelaardd991352009-08-16 23:36:46 +0000447LLVMValueRef LLVMConstRealOfStringAndSize(LLVMTypeRef RealTy, const char *Text,
448 unsigned SLen);
449
Gordon Henriksen76a03742007-09-18 03:18:57 +0000450
451/* Operations on composite constants */
Erick Tryzelaar262332f2009-08-14 00:01:31 +0000452LLVMValueRef LLVMConstStringInContext(LLVMContextRef C, const char *Str,
453 unsigned Length, int DontNullTerminate);
454LLVMValueRef LLVMConstStructInContext(LLVMContextRef C,
455 LLVMValueRef *ConstantVals,
456 unsigned Count, int Packed);
457
Gordon Henriksen1046c732007-10-06 15:11:06 +0000458LLVMValueRef LLVMConstString(const char *Str, unsigned Length,
459 int DontNullTerminate);
Gordon Henriksen2ad5aef2008-04-25 03:21:19 +0000460LLVMValueRef LLVMConstArray(LLVMTypeRef ElementTy,
Gordon Henriksen1046c732007-10-06 15:11:06 +0000461 LLVMValueRef *ConstantVals, unsigned Length);
462LLVMValueRef LLVMConstStruct(LLVMValueRef *ConstantVals, unsigned Count,
Erick Tryzelaar262332f2009-08-14 00:01:31 +0000463 int Packed);
Gordon Henriksen1046c732007-10-06 15:11:06 +0000464LLVMValueRef LLVMConstVector(LLVMValueRef *ScalarConstantVals, unsigned Size);
Gordon Henriksen76a03742007-09-18 03:18:57 +0000465
Gordon Henriksen7ce31762007-10-06 14:29:36 +0000466/* Constant expressions */
Erick Tryzelaarfd529d72009-08-19 08:36:49 +0000467LLVMValueRef LLVMAlignOf(LLVMTypeRef Ty);
Gordon Henriksen7ce31762007-10-06 14:29:36 +0000468LLVMValueRef LLVMSizeOf(LLVMTypeRef Ty);
469LLVMValueRef LLVMConstNeg(LLVMValueRef ConstantVal);
Erick Tryzelaar4cc690c2009-08-16 02:20:12 +0000470LLVMValueRef LLVMConstFNeg(LLVMValueRef ConstantVal);
Gordon Henriksen7ce31762007-10-06 14:29:36 +0000471LLVMValueRef LLVMConstNot(LLVMValueRef ConstantVal);
472LLVMValueRef LLVMConstAdd(LLVMValueRef LHSConstant, LLVMValueRef RHSConstant);
Erick Tryzelaar4cc690c2009-08-16 02:20:12 +0000473LLVMValueRef LLVMConstNSWAdd(LLVMValueRef LHSConstant, LLVMValueRef RHSConstant);
474LLVMValueRef LLVMConstFAdd(LLVMValueRef LHSConstant, LLVMValueRef RHSConstant);
Gordon Henriksen7ce31762007-10-06 14:29:36 +0000475LLVMValueRef LLVMConstSub(LLVMValueRef LHSConstant, LLVMValueRef RHSConstant);
Erick Tryzelaar4cc690c2009-08-16 02:20:12 +0000476LLVMValueRef LLVMConstFSub(LLVMValueRef LHSConstant, LLVMValueRef RHSConstant);
Gordon Henriksen7ce31762007-10-06 14:29:36 +0000477LLVMValueRef LLVMConstMul(LLVMValueRef LHSConstant, LLVMValueRef RHSConstant);
Erick Tryzelaar4cc690c2009-08-16 02:20:12 +0000478LLVMValueRef LLVMConstFMul(LLVMValueRef LHSConstant, LLVMValueRef RHSConstant);
Gordon Henriksen7ce31762007-10-06 14:29:36 +0000479LLVMValueRef LLVMConstUDiv(LLVMValueRef LHSConstant, LLVMValueRef RHSConstant);
480LLVMValueRef LLVMConstSDiv(LLVMValueRef LHSConstant, LLVMValueRef RHSConstant);
Erick Tryzelaar4cc690c2009-08-16 02:20:12 +0000481LLVMValueRef LLVMConstExactSDiv(LLVMValueRef LHSConstant, LLVMValueRef RHSConstant);
Gordon Henriksen7ce31762007-10-06 14:29:36 +0000482LLVMValueRef LLVMConstFDiv(LLVMValueRef LHSConstant, LLVMValueRef RHSConstant);
483LLVMValueRef LLVMConstURem(LLVMValueRef LHSConstant, LLVMValueRef RHSConstant);
484LLVMValueRef LLVMConstSRem(LLVMValueRef LHSConstant, LLVMValueRef RHSConstant);
485LLVMValueRef LLVMConstFRem(LLVMValueRef LHSConstant, LLVMValueRef RHSConstant);
486LLVMValueRef LLVMConstAnd(LLVMValueRef LHSConstant, LLVMValueRef RHSConstant);
487LLVMValueRef LLVMConstOr(LLVMValueRef LHSConstant, LLVMValueRef RHSConstant);
488LLVMValueRef LLVMConstXor(LLVMValueRef LHSConstant, LLVMValueRef RHSConstant);
489LLVMValueRef LLVMConstICmp(LLVMIntPredicate Predicate,
490 LLVMValueRef LHSConstant, LLVMValueRef RHSConstant);
491LLVMValueRef LLVMConstFCmp(LLVMRealPredicate Predicate,
492 LLVMValueRef LHSConstant, LLVMValueRef RHSConstant);
493LLVMValueRef LLVMConstShl(LLVMValueRef LHSConstant, LLVMValueRef RHSConstant);
494LLVMValueRef LLVMConstLShr(LLVMValueRef LHSConstant, LLVMValueRef RHSConstant);
495LLVMValueRef LLVMConstAShr(LLVMValueRef LHSConstant, LLVMValueRef RHSConstant);
496LLVMValueRef LLVMConstGEP(LLVMValueRef ConstantVal,
497 LLVMValueRef *ConstantIndices, unsigned NumIndices);
Erick Tryzelaar4cc690c2009-08-16 02:20:12 +0000498LLVMValueRef LLVMConstInBoundsGEP(LLVMValueRef ConstantVal,
499 LLVMValueRef *ConstantIndices,
500 unsigned NumIndices);
Gordon Henriksen7ce31762007-10-06 14:29:36 +0000501LLVMValueRef LLVMConstTrunc(LLVMValueRef ConstantVal, LLVMTypeRef ToType);
502LLVMValueRef LLVMConstSExt(LLVMValueRef ConstantVal, LLVMTypeRef ToType);
503LLVMValueRef LLVMConstZExt(LLVMValueRef ConstantVal, LLVMTypeRef ToType);
504LLVMValueRef LLVMConstFPTrunc(LLVMValueRef ConstantVal, LLVMTypeRef ToType);
505LLVMValueRef LLVMConstFPExt(LLVMValueRef ConstantVal, LLVMTypeRef ToType);
506LLVMValueRef LLVMConstUIToFP(LLVMValueRef ConstantVal, LLVMTypeRef ToType);
507LLVMValueRef LLVMConstSIToFP(LLVMValueRef ConstantVal, LLVMTypeRef ToType);
508LLVMValueRef LLVMConstFPToUI(LLVMValueRef ConstantVal, LLVMTypeRef ToType);
509LLVMValueRef LLVMConstFPToSI(LLVMValueRef ConstantVal, LLVMTypeRef ToType);
510LLVMValueRef LLVMConstPtrToInt(LLVMValueRef ConstantVal, LLVMTypeRef ToType);
511LLVMValueRef LLVMConstIntToPtr(LLVMValueRef ConstantVal, LLVMTypeRef ToType);
512LLVMValueRef LLVMConstBitCast(LLVMValueRef ConstantVal, LLVMTypeRef ToType);
Erick Tryzelaar4cc690c2009-08-16 02:20:12 +0000513LLVMValueRef LLVMConstZExtOrBitCast(LLVMValueRef ConstantVal,
514 LLVMTypeRef ToType);
515LLVMValueRef LLVMConstSExtOrBitCast(LLVMValueRef ConstantVal,
516 LLVMTypeRef ToType);
517LLVMValueRef LLVMConstTruncOrBitCast(LLVMValueRef ConstantVal,
518 LLVMTypeRef ToType);
519LLVMValueRef LLVMConstPointerCast(LLVMValueRef ConstantVal,
520 LLVMTypeRef ToType);
521LLVMValueRef LLVMConstIntCast(LLVMValueRef ConstantVal, LLVMTypeRef ToType,
522 unsigned isSigned);
523LLVMValueRef LLVMConstFPCast(LLVMValueRef ConstantVal, LLVMTypeRef ToType);
Gordon Henriksen7ce31762007-10-06 14:29:36 +0000524LLVMValueRef LLVMConstSelect(LLVMValueRef ConstantCondition,
525 LLVMValueRef ConstantIfTrue,
526 LLVMValueRef ConstantIfFalse);
527LLVMValueRef LLVMConstExtractElement(LLVMValueRef VectorConstant,
528 LLVMValueRef IndexConstant);
529LLVMValueRef LLVMConstInsertElement(LLVMValueRef VectorConstant,
530 LLVMValueRef ElementValueConstant,
531 LLVMValueRef IndexConstant);
532LLVMValueRef LLVMConstShuffleVector(LLVMValueRef VectorAConstant,
533 LLVMValueRef VectorBConstant,
534 LLVMValueRef MaskConstant);
Dan Gohmand5104a52008-11-03 22:55:43 +0000535LLVMValueRef LLVMConstExtractValue(LLVMValueRef AggConstant, unsigned *IdxList,
536 unsigned NumIdx);
537LLVMValueRef LLVMConstInsertValue(LLVMValueRef AggConstant,
538 LLVMValueRef ElementValueConstant,
539 unsigned *IdxList, unsigned NumIdx);
Chris Lattner3d1f5522008-12-17 21:39:50 +0000540LLVMValueRef LLVMConstInlineAsm(LLVMTypeRef Ty,
541 const char *AsmString, const char *Constraints,
542 int HasSideEffects);
Gordon Henriksen7ce31762007-10-06 14:29:36 +0000543
Gordon Henriksen76a03742007-09-18 03:18:57 +0000544/* Operations on global variables, functions, and aliases (globals) */
Gordon Henriksen265f7802008-03-19 01:11:35 +0000545LLVMModuleRef LLVMGetGlobalParent(LLVMValueRef Global);
Gordon Henriksen76a03742007-09-18 03:18:57 +0000546int LLVMIsDeclaration(LLVMValueRef Global);
547LLVMLinkage LLVMGetLinkage(LLVMValueRef Global);
548void LLVMSetLinkage(LLVMValueRef Global, LLVMLinkage Linkage);
549const char *LLVMGetSection(LLVMValueRef Global);
550void LLVMSetSection(LLVMValueRef Global, const char *Section);
551LLVMVisibility LLVMGetVisibility(LLVMValueRef Global);
552void LLVMSetVisibility(LLVMValueRef Global, LLVMVisibility Viz);
553unsigned LLVMGetAlignment(LLVMValueRef Global);
554void LLVMSetAlignment(LLVMValueRef Global, unsigned Bytes);
555
556/* Operations on global variables */
557LLVMValueRef LLVMAddGlobal(LLVMModuleRef M, LLVMTypeRef Ty, const char *Name);
Gordon Henriksen783f7bb2007-10-08 03:45:09 +0000558LLVMValueRef LLVMGetNamedGlobal(LLVMModuleRef M, const char *Name);
Gordon Henriksen07a45f42008-03-23 22:21:29 +0000559LLVMValueRef LLVMGetFirstGlobal(LLVMModuleRef M);
560LLVMValueRef LLVMGetLastGlobal(LLVMModuleRef M);
561LLVMValueRef LLVMGetNextGlobal(LLVMValueRef GlobalVar);
562LLVMValueRef LLVMGetPreviousGlobal(LLVMValueRef GlobalVar);
Gordon Henriksen76a03742007-09-18 03:18:57 +0000563void LLVMDeleteGlobal(LLVMValueRef GlobalVar);
Gordon Henriksen76a03742007-09-18 03:18:57 +0000564LLVMValueRef LLVMGetInitializer(LLVMValueRef GlobalVar);
565void LLVMSetInitializer(LLVMValueRef GlobalVar, LLVMValueRef ConstantVal);
566int LLVMIsThreadLocal(LLVMValueRef GlobalVar);
567void LLVMSetThreadLocal(LLVMValueRef GlobalVar, int IsThreadLocal);
Gordon Henriksen751ebf72007-10-07 17:31:42 +0000568int LLVMIsGlobalConstant(LLVMValueRef GlobalVar);
569void LLVMSetGlobalConstant(LLVMValueRef GlobalVar, int IsConstant);
Gordon Henriksen76a03742007-09-18 03:18:57 +0000570
Chris Lattner3d1f5522008-12-17 21:39:50 +0000571/* Operations on aliases */
572LLVMValueRef LLVMAddAlias(LLVMModuleRef M, LLVMTypeRef Ty, LLVMValueRef Aliasee,
573 const char *Name);
574
Gordon Henriksenc23b66c2007-09-26 20:56:12 +0000575/* Operations on functions */
576LLVMValueRef LLVMAddFunction(LLVMModuleRef M, const char *Name,
577 LLVMTypeRef FunctionTy);
Gordon Henriksen783f7bb2007-10-08 03:45:09 +0000578LLVMValueRef LLVMGetNamedFunction(LLVMModuleRef M, const char *Name);
Gordon Henriksen054817c2008-03-19 03:47:18 +0000579LLVMValueRef LLVMGetFirstFunction(LLVMModuleRef M);
580LLVMValueRef LLVMGetLastFunction(LLVMModuleRef M);
581LLVMValueRef LLVMGetNextFunction(LLVMValueRef Fn);
582LLVMValueRef LLVMGetPreviousFunction(LLVMValueRef Fn);
Gordon Henriksenc23b66c2007-09-26 20:56:12 +0000583void LLVMDeleteFunction(LLVMValueRef Fn);
Gordon Henriksenc23b66c2007-09-26 20:56:12 +0000584unsigned LLVMGetIntrinsicID(LLVMValueRef Fn);
585unsigned LLVMGetFunctionCallConv(LLVMValueRef Fn);
586void LLVMSetFunctionCallConv(LLVMValueRef Fn, unsigned CC);
Gordon Henriksend930f912008-08-17 18:44:35 +0000587const char *LLVMGetGC(LLVMValueRef Fn);
588void LLVMSetGC(LLVMValueRef Fn, const char *Name);
Duncan Sands7374a012009-05-06 12:21:17 +0000589void LLVMAddFunctionAttr(LLVMValueRef Fn, LLVMAttribute PA);
590void LLVMRemoveFunctionAttr(LLVMValueRef Fn, LLVMAttribute PA);
Gordon Henriksenc23b66c2007-09-26 20:56:12 +0000591
Gordon Henriksen265f7802008-03-19 01:11:35 +0000592/* Operations on parameters */
593unsigned LLVMCountParams(LLVMValueRef Fn);
594void LLVMGetParams(LLVMValueRef Fn, LLVMValueRef *Params);
595LLVMValueRef LLVMGetParam(LLVMValueRef Fn, unsigned Index);
596LLVMValueRef LLVMGetParamParent(LLVMValueRef Inst);
Gordon Henriksen07a45f42008-03-23 22:21:29 +0000597LLVMValueRef LLVMGetFirstParam(LLVMValueRef Fn);
598LLVMValueRef LLVMGetLastParam(LLVMValueRef Fn);
599LLVMValueRef LLVMGetNextParam(LLVMValueRef Arg);
600LLVMValueRef LLVMGetPreviousParam(LLVMValueRef Arg);
Devang Patel4c758ea2008-09-25 21:00:45 +0000601void LLVMAddAttribute(LLVMValueRef Arg, LLVMAttribute PA);
602void LLVMRemoveAttribute(LLVMValueRef Arg, LLVMAttribute PA);
Gordon Henriksen2d9cc212008-04-28 17:37:06 +0000603void LLVMSetParamAlignment(LLVMValueRef Arg, unsigned align);
Gordon Henriksen265f7802008-03-19 01:11:35 +0000604
Gordon Henriksenc23b66c2007-09-26 20:56:12 +0000605/* Operations on basic blocks */
Gordon Henriksen07a45f42008-03-23 22:21:29 +0000606LLVMValueRef LLVMBasicBlockAsValue(LLVMBasicBlockRef BB);
Gordon Henriksenc23b66c2007-09-26 20:56:12 +0000607int LLVMValueIsBasicBlock(LLVMValueRef Val);
608LLVMBasicBlockRef LLVMValueAsBasicBlock(LLVMValueRef Val);
Gordon Henriksen07a45f42008-03-23 22:21:29 +0000609LLVMValueRef LLVMGetBasicBlockParent(LLVMBasicBlockRef BB);
Gordon Henriksenc23b66c2007-09-26 20:56:12 +0000610unsigned LLVMCountBasicBlocks(LLVMValueRef Fn);
611void LLVMGetBasicBlocks(LLVMValueRef Fn, LLVMBasicBlockRef *BasicBlocks);
Gordon Henriksen054817c2008-03-19 03:47:18 +0000612LLVMBasicBlockRef LLVMGetFirstBasicBlock(LLVMValueRef Fn);
613LLVMBasicBlockRef LLVMGetLastBasicBlock(LLVMValueRef Fn);
614LLVMBasicBlockRef LLVMGetNextBasicBlock(LLVMBasicBlockRef BB);
615LLVMBasicBlockRef LLVMGetPreviousBasicBlock(LLVMBasicBlockRef BB);
Gordon Henriksenc23b66c2007-09-26 20:56:12 +0000616LLVMBasicBlockRef LLVMGetEntryBasicBlock(LLVMValueRef Fn);
Erick Tryzelaar262332f2009-08-14 00:01:31 +0000617
618LLVMBasicBlockRef LLVMAppendBasicBlockInContext(LLVMContextRef C,
619 LLVMValueRef Fn,
620 const char *Name);
621LLVMBasicBlockRef LLVMInsertBasicBlockInContext(LLVMContextRef C,
622 LLVMBasicBlockRef BB,
623 const char *Name);
624
Gordon Henriksenc23b66c2007-09-26 20:56:12 +0000625LLVMBasicBlockRef LLVMAppendBasicBlock(LLVMValueRef Fn, const char *Name);
626LLVMBasicBlockRef LLVMInsertBasicBlock(LLVMBasicBlockRef InsertBeforeBB,
627 const char *Name);
628void LLVMDeleteBasicBlock(LLVMBasicBlockRef BB);
629
Gordon Henriksen265f7802008-03-19 01:11:35 +0000630/* Operations on instructions */
631LLVMBasicBlockRef LLVMGetInstructionParent(LLVMValueRef Inst);
Gordon Henriksen054817c2008-03-19 03:47:18 +0000632LLVMValueRef LLVMGetFirstInstruction(LLVMBasicBlockRef BB);
633LLVMValueRef LLVMGetLastInstruction(LLVMBasicBlockRef BB);
634LLVMValueRef LLVMGetNextInstruction(LLVMValueRef Inst);
635LLVMValueRef LLVMGetPreviousInstruction(LLVMValueRef Inst);
Gordon Henriksen265f7802008-03-19 01:11:35 +0000636
Gordon Henriksen1158c532007-12-29 20:45:00 +0000637/* Operations on call sites */
638void LLVMSetInstructionCallConv(LLVMValueRef Instr, unsigned CC);
639unsigned LLVMGetInstructionCallConv(LLVMValueRef Instr);
Devang Patel4c758ea2008-09-25 21:00:45 +0000640void LLVMAddInstrAttribute(LLVMValueRef Instr, unsigned index, LLVMAttribute);
641void LLVMRemoveInstrAttribute(LLVMValueRef Instr, unsigned index,
642 LLVMAttribute);
Gordon Henriksen2d9cc212008-04-28 17:37:06 +0000643void LLVMSetInstrParamAlignment(LLVMValueRef Instr, unsigned index,
644 unsigned align);
Gordon Henriksen1158c532007-12-29 20:45:00 +0000645
Gordon Henrikseneeb65372008-08-30 16:34:54 +0000646/* Operations on call instructions (only) */
647int LLVMIsTailCall(LLVMValueRef CallInst);
648void LLVMSetTailCall(LLVMValueRef CallInst, int IsTailCall);
649
Gordon Henriksen44dd8fb2007-10-08 18:14:39 +0000650/* Operations on phi nodes */
651void LLVMAddIncoming(LLVMValueRef PhiNode, LLVMValueRef *IncomingValues,
652 LLVMBasicBlockRef *IncomingBlocks, unsigned Count);
653unsigned LLVMCountIncoming(LLVMValueRef PhiNode);
654LLVMValueRef LLVMGetIncomingValue(LLVMValueRef PhiNode, unsigned Index);
655LLVMBasicBlockRef LLVMGetIncomingBlock(LLVMValueRef PhiNode, unsigned Index);
Gordon Henriksenc23b66c2007-09-26 20:56:12 +0000656
657/*===-- Instruction builders ----------------------------------------------===*/
658
659/* An instruction builder represents a point within a basic block, and is the
660 * exclusive means of building instructions using the C interface.
661 */
662
Erick Tryzelaar262332f2009-08-14 00:01:31 +0000663LLVMBuilderRef LLVMCreateBuilderInContext(LLVMContextRef C);
Gordon Henriksena735a9c2008-05-04 12:55:34 +0000664LLVMBuilderRef LLVMCreateBuilder(void);
Gordon Henriksen054817c2008-03-19 03:47:18 +0000665void LLVMPositionBuilder(LLVMBuilderRef Builder, LLVMBasicBlockRef Block,
666 LLVMValueRef Instr);
Gordon Henriksenc23b66c2007-09-26 20:56:12 +0000667void LLVMPositionBuilderBefore(LLVMBuilderRef Builder, LLVMValueRef Instr);
668void LLVMPositionBuilderAtEnd(LLVMBuilderRef Builder, LLVMBasicBlockRef Block);
Gordon Henriksen265f7802008-03-19 01:11:35 +0000669LLVMBasicBlockRef LLVMGetInsertBlock(LLVMBuilderRef Builder);
Chris Lattner3d1f5522008-12-17 21:39:50 +0000670void LLVMClearInsertionPosition(LLVMBuilderRef Builder);
671void LLVMInsertIntoBuilder(LLVMBuilderRef Builder, LLVMValueRef Instr);
Erick Tryzelaar9813bea2009-08-16 02:20:57 +0000672void LLVMInsertIntoBuilderWithName(LLVMBuilderRef Builder, LLVMValueRef Instr,
673 const char *Name);
Gordon Henriksenc23b66c2007-09-26 20:56:12 +0000674void LLVMDisposeBuilder(LLVMBuilderRef Builder);
675
676/* Terminators */
677LLVMValueRef LLVMBuildRetVoid(LLVMBuilderRef);
678LLVMValueRef LLVMBuildRet(LLVMBuilderRef, LLVMValueRef V);
Erick Tryzelaarfd529d72009-08-19 08:36:49 +0000679LLVMValueRef LLVMBuildAggregateRet(LLVMBuilderRef, LLVMValueRef *RetVals,
Erick Tryzelaar3045b8b2009-08-16 02:19:59 +0000680 unsigned N);
Gordon Henriksenc23b66c2007-09-26 20:56:12 +0000681LLVMValueRef LLVMBuildBr(LLVMBuilderRef, LLVMBasicBlockRef Dest);
682LLVMValueRef LLVMBuildCondBr(LLVMBuilderRef, LLVMValueRef If,
683 LLVMBasicBlockRef Then, LLVMBasicBlockRef Else);
684LLVMValueRef LLVMBuildSwitch(LLVMBuilderRef, LLVMValueRef V,
685 LLVMBasicBlockRef Else, unsigned NumCases);
686LLVMValueRef LLVMBuildInvoke(LLVMBuilderRef, LLVMValueRef Fn,
687 LLVMValueRef *Args, unsigned NumArgs,
688 LLVMBasicBlockRef Then, LLVMBasicBlockRef Catch,
689 const char *Name);
690LLVMValueRef LLVMBuildUnwind(LLVMBuilderRef);
691LLVMValueRef LLVMBuildUnreachable(LLVMBuilderRef);
692
Gordon Henriksen097102c2008-01-01 05:50:53 +0000693/* Add a case to the switch instruction */
694void LLVMAddCase(LLVMValueRef Switch, LLVMValueRef OnVal,
695 LLVMBasicBlockRef Dest);
696
Gordon Henriksenc23b66c2007-09-26 20:56:12 +0000697/* Arithmetic */
698LLVMValueRef LLVMBuildAdd(LLVMBuilderRef, LLVMValueRef LHS, LLVMValueRef RHS,
699 const char *Name);
Erick Tryzelaar3045b8b2009-08-16 02:19:59 +0000700LLVMValueRef LLVMBuildNSWAdd(LLVMBuilderRef, LLVMValueRef LHS, LLVMValueRef RHS,
701 const char *Name);
702LLVMValueRef LLVMBuildFAdd(LLVMBuilderRef, LLVMValueRef LHS, LLVMValueRef RHS,
703 const char *Name);
Gordon Henriksenc23b66c2007-09-26 20:56:12 +0000704LLVMValueRef LLVMBuildSub(LLVMBuilderRef, LLVMValueRef LHS, LLVMValueRef RHS,
705 const char *Name);
Erick Tryzelaar3045b8b2009-08-16 02:19:59 +0000706LLVMValueRef LLVMBuildFSub(LLVMBuilderRef, LLVMValueRef LHS, LLVMValueRef RHS,
707 const char *Name);
Gordon Henriksenc23b66c2007-09-26 20:56:12 +0000708LLVMValueRef LLVMBuildMul(LLVMBuilderRef, LLVMValueRef LHS, LLVMValueRef RHS,
709 const char *Name);
Erick Tryzelaar3045b8b2009-08-16 02:19:59 +0000710LLVMValueRef LLVMBuildFMul(LLVMBuilderRef, LLVMValueRef LHS, LLVMValueRef RHS,
711 const char *Name);
Gordon Henriksenc23b66c2007-09-26 20:56:12 +0000712LLVMValueRef LLVMBuildUDiv(LLVMBuilderRef, LLVMValueRef LHS, LLVMValueRef RHS,
713 const char *Name);
714LLVMValueRef LLVMBuildSDiv(LLVMBuilderRef, LLVMValueRef LHS, LLVMValueRef RHS,
715 const char *Name);
Erick Tryzelaar3045b8b2009-08-16 02:19:59 +0000716LLVMValueRef LLVMBuildExactSDiv(LLVMBuilderRef, LLVMValueRef LHS, LLVMValueRef RHS,
717 const char *Name);
Gordon Henriksenc23b66c2007-09-26 20:56:12 +0000718LLVMValueRef LLVMBuildFDiv(LLVMBuilderRef, LLVMValueRef LHS, LLVMValueRef RHS,
719 const char *Name);
720LLVMValueRef LLVMBuildURem(LLVMBuilderRef, LLVMValueRef LHS, LLVMValueRef RHS,
721 const char *Name);
722LLVMValueRef LLVMBuildSRem(LLVMBuilderRef, LLVMValueRef LHS, LLVMValueRef RHS,
723 const char *Name);
724LLVMValueRef LLVMBuildFRem(LLVMBuilderRef, LLVMValueRef LHS, LLVMValueRef RHS,
725 const char *Name);
726LLVMValueRef LLVMBuildShl(LLVMBuilderRef, LLVMValueRef LHS, LLVMValueRef RHS,
727 const char *Name);
728LLVMValueRef LLVMBuildLShr(LLVMBuilderRef, LLVMValueRef LHS, LLVMValueRef RHS,
729 const char *Name);
730LLVMValueRef LLVMBuildAShr(LLVMBuilderRef, LLVMValueRef LHS, LLVMValueRef RHS,
731 const char *Name);
732LLVMValueRef LLVMBuildAnd(LLVMBuilderRef, LLVMValueRef LHS, LLVMValueRef RHS,
733 const char *Name);
734LLVMValueRef LLVMBuildOr(LLVMBuilderRef, LLVMValueRef LHS, LLVMValueRef RHS,
735 const char *Name);
736LLVMValueRef LLVMBuildXor(LLVMBuilderRef, LLVMValueRef LHS, LLVMValueRef RHS,
737 const char *Name);
738LLVMValueRef LLVMBuildNeg(LLVMBuilderRef, LLVMValueRef V, const char *Name);
739LLVMValueRef LLVMBuildNot(LLVMBuilderRef, LLVMValueRef V, const char *Name);
740
741/* Memory */
742LLVMValueRef LLVMBuildMalloc(LLVMBuilderRef, LLVMTypeRef Ty, const char *Name);
743LLVMValueRef LLVMBuildArrayMalloc(LLVMBuilderRef, LLVMTypeRef Ty,
744 LLVMValueRef Val, const char *Name);
745LLVMValueRef LLVMBuildAlloca(LLVMBuilderRef, LLVMTypeRef Ty, const char *Name);
746LLVMValueRef LLVMBuildArrayAlloca(LLVMBuilderRef, LLVMTypeRef Ty,
747 LLVMValueRef Val, const char *Name);
748LLVMValueRef LLVMBuildFree(LLVMBuilderRef, LLVMValueRef PointerVal);
749LLVMValueRef LLVMBuildLoad(LLVMBuilderRef, LLVMValueRef PointerVal,
750 const char *Name);
751LLVMValueRef LLVMBuildStore(LLVMBuilderRef, LLVMValueRef Val, LLVMValueRef Ptr);
752LLVMValueRef LLVMBuildGEP(LLVMBuilderRef B, LLVMValueRef Pointer,
753 LLVMValueRef *Indices, unsigned NumIndices,
754 const char *Name);
Erick Tryzelaar3045b8b2009-08-16 02:19:59 +0000755LLVMValueRef LLVMBuildInBoundsGEP(LLVMBuilderRef B, LLVMValueRef Pointer,
756 LLVMValueRef *Indices, unsigned NumIndices,
757 const char *Name);
758LLVMValueRef LLVMBuildStructGEP(LLVMBuilderRef B, LLVMValueRef Pointer,
759 unsigned Idx, const char *Name);
760LLVMValueRef LLVMBuildGlobalString(LLVMBuilderRef B, const char *Str,
761 const char *Name);
762LLVMValueRef LLVMBuildGlobalStringPtr(LLVMBuilderRef B, const char *Str,
763 const char *Name);
Gordon Henriksenc23b66c2007-09-26 20:56:12 +0000764
765/* Casts */
766LLVMValueRef LLVMBuildTrunc(LLVMBuilderRef, LLVMValueRef Val,
767 LLVMTypeRef DestTy, const char *Name);
768LLVMValueRef LLVMBuildZExt(LLVMBuilderRef, LLVMValueRef Val,
769 LLVMTypeRef DestTy, const char *Name);
770LLVMValueRef LLVMBuildSExt(LLVMBuilderRef, LLVMValueRef Val,
771 LLVMTypeRef DestTy, const char *Name);
772LLVMValueRef LLVMBuildFPToUI(LLVMBuilderRef, LLVMValueRef Val,
773 LLVMTypeRef DestTy, const char *Name);
774LLVMValueRef LLVMBuildFPToSI(LLVMBuilderRef, LLVMValueRef Val,
775 LLVMTypeRef DestTy, const char *Name);
776LLVMValueRef LLVMBuildUIToFP(LLVMBuilderRef, LLVMValueRef Val,
777 LLVMTypeRef DestTy, const char *Name);
778LLVMValueRef LLVMBuildSIToFP(LLVMBuilderRef, LLVMValueRef Val,
779 LLVMTypeRef DestTy, const char *Name);
780LLVMValueRef LLVMBuildFPTrunc(LLVMBuilderRef, LLVMValueRef Val,
781 LLVMTypeRef DestTy, const char *Name);
782LLVMValueRef LLVMBuildFPExt(LLVMBuilderRef, LLVMValueRef Val,
783 LLVMTypeRef DestTy, const char *Name);
784LLVMValueRef LLVMBuildPtrToInt(LLVMBuilderRef, LLVMValueRef Val,
785 LLVMTypeRef DestTy, const char *Name);
786LLVMValueRef LLVMBuildIntToPtr(LLVMBuilderRef, LLVMValueRef Val,
787 LLVMTypeRef DestTy, const char *Name);
788LLVMValueRef LLVMBuildBitCast(LLVMBuilderRef, LLVMValueRef Val,
789 LLVMTypeRef DestTy, const char *Name);
Erick Tryzelaar3045b8b2009-08-16 02:19:59 +0000790LLVMValueRef LLVMBuildZExtOrBitCast(LLVMBuilderRef, LLVMValueRef Val,
791 LLVMTypeRef DestTy, const char *Name);
792LLVMValueRef LLVMBuildSExtOrBitCast(LLVMBuilderRef, LLVMValueRef Val,
793 LLVMTypeRef DestTy, const char *Name);
794LLVMValueRef LLVMBuildTruncOrBitCast(LLVMBuilderRef, LLVMValueRef Val,
795 LLVMTypeRef DestTy, const char *Name);
796LLVMValueRef LLVMBuildPointerCast(LLVMBuilderRef, LLVMValueRef Val,
797 LLVMTypeRef DestTy, const char *Name);
798LLVMValueRef LLVMBuildIntCast(LLVMBuilderRef, LLVMValueRef Val,
799 LLVMTypeRef DestTy, const char *Name);
800LLVMValueRef LLVMBuildFPCast(LLVMBuilderRef, LLVMValueRef Val,
801 LLVMTypeRef DestTy, const char *Name);
Gordon Henriksenc23b66c2007-09-26 20:56:12 +0000802
803/* Comparisons */
804LLVMValueRef LLVMBuildICmp(LLVMBuilderRef, LLVMIntPredicate Op,
805 LLVMValueRef LHS, LLVMValueRef RHS,
806 const char *Name);
807LLVMValueRef LLVMBuildFCmp(LLVMBuilderRef, LLVMRealPredicate Op,
808 LLVMValueRef LHS, LLVMValueRef RHS,
809 const char *Name);
810
811/* Miscellaneous instructions */
812LLVMValueRef LLVMBuildPhi(LLVMBuilderRef, LLVMTypeRef Ty, const char *Name);
813LLVMValueRef LLVMBuildCall(LLVMBuilderRef, LLVMValueRef Fn,
814 LLVMValueRef *Args, unsigned NumArgs,
815 const char *Name);
816LLVMValueRef LLVMBuildSelect(LLVMBuilderRef, LLVMValueRef If,
817 LLVMValueRef Then, LLVMValueRef Else,
818 const char *Name);
819LLVMValueRef LLVMBuildVAArg(LLVMBuilderRef, LLVMValueRef List, LLVMTypeRef Ty,
820 const char *Name);
821LLVMValueRef LLVMBuildExtractElement(LLVMBuilderRef, LLVMValueRef VecVal,
822 LLVMValueRef Index, const char *Name);
823LLVMValueRef LLVMBuildInsertElement(LLVMBuilderRef, LLVMValueRef VecVal,
824 LLVMValueRef EltVal, LLVMValueRef Index,
825 const char *Name);
826LLVMValueRef LLVMBuildShuffleVector(LLVMBuilderRef, LLVMValueRef V1,
827 LLVMValueRef V2, LLVMValueRef Mask,
828 const char *Name);
Dan Gohmand5104a52008-11-03 22:55:43 +0000829LLVMValueRef LLVMBuildExtractValue(LLVMBuilderRef, LLVMValueRef AggVal,
830 unsigned Index, const char *Name);
831LLVMValueRef LLVMBuildInsertValue(LLVMBuilderRef, LLVMValueRef AggVal,
832 LLVMValueRef EltVal, unsigned Index,
833 const char *Name);
Gordon Henriksen76a03742007-09-18 03:18:57 +0000834
Erick Tryzelaar3045b8b2009-08-16 02:19:59 +0000835LLVMValueRef LLVMBuildIsNull(LLVMBuilderRef, LLVMValueRef Val,
836 const char *Name);
837LLVMValueRef LLVMBuildIsNotNull(LLVMBuilderRef, LLVMValueRef Val,
838 const char *Name);
839LLVMValueRef LLVMBuildPtrDiff(LLVMBuilderRef, LLVMValueRef LHS,
840 LLVMValueRef RHS, const char *Name);
841
Gordon Henriksen34eb6d82007-12-19 22:30:40 +0000842
Gordon Henriksen0a68fe22007-12-12 01:04:30 +0000843/*===-- Module providers --------------------------------------------------===*/
844
845/* Encapsulates the module M in a module provider, taking ownership of the
846 * module.
847 * See the constructor llvm::ExistingModuleProvider::ExistingModuleProvider.
848 */
849LLVMModuleProviderRef
850LLVMCreateModuleProviderForExistingModule(LLVMModuleRef M);
851
852/* Destroys the module provider MP as well as the contained module.
853 * See the destructor llvm::ModuleProvider::~ModuleProvider.
854 */
855void LLVMDisposeModuleProvider(LLVMModuleProviderRef MP);
856
Gordon Henriksen34eb6d82007-12-19 22:30:40 +0000857
858/*===-- Memory buffers ----------------------------------------------------===*/
859
860int LLVMCreateMemoryBufferWithContentsOfFile(const char *Path,
861 LLVMMemoryBufferRef *OutMemBuf,
862 char **OutMessage);
863int LLVMCreateMemoryBufferWithSTDIN(LLVMMemoryBufferRef *OutMemBuf,
864 char **OutMessage);
865void LLVMDisposeMemoryBuffer(LLVMMemoryBufferRef MemBuf);
866
Gordon Henriksen878114b2008-03-16 04:20:44 +0000867
868/*===-- Pass Managers -----------------------------------------------------===*/
869
870/** Constructs a new whole-module pass pipeline. This type of pipeline is
871 suitable for link-time optimization and whole-module transformations.
872 See llvm::PassManager::PassManager. */
Gordon Henriksena735a9c2008-05-04 12:55:34 +0000873LLVMPassManagerRef LLVMCreatePassManager(void);
Gordon Henriksen878114b2008-03-16 04:20:44 +0000874
875/** Constructs a new function-by-function pass pipeline over the module
876 provider. It does not take ownership of the module provider. This type of
877 pipeline is suitable for code generation and JIT compilation tasks.
878 See llvm::FunctionPassManager::FunctionPassManager. */
879LLVMPassManagerRef LLVMCreateFunctionPassManager(LLVMModuleProviderRef MP);
880
881/** Initializes, executes on the provided module, and finalizes all of the
882 passes scheduled in the pass manager. Returns 1 if any of the passes
883 modified the module, 0 otherwise. See llvm::PassManager::run(Module&). */
884int LLVMRunPassManager(LLVMPassManagerRef PM, LLVMModuleRef M);
885
886/** Initializes all of the function passes scheduled in the function pass
887 manager. Returns 1 if any of the passes modified the module, 0 otherwise.
888 See llvm::FunctionPassManager::doInitialization. */
889int LLVMInitializeFunctionPassManager(LLVMPassManagerRef FPM);
890
891/** Executes all of the function passes scheduled in the function pass manager
892 on the provided function. Returns 1 if any of the passes modified the
893 function, false otherwise.
894 See llvm::FunctionPassManager::run(Function&). */
895int LLVMRunFunctionPassManager(LLVMPassManagerRef FPM, LLVMValueRef F);
896
897/** Finalizes all of the function passes scheduled in in the function pass
898 manager. Returns 1 if any of the passes modified the module, 0 otherwise.
899 See llvm::FunctionPassManager::doFinalization. */
900int LLVMFinalizeFunctionPassManager(LLVMPassManagerRef FPM);
901
902/** Frees the memory of a pass pipeline. For function pipelines, does not free
903 the module provider.
904 See llvm::PassManagerBase::~PassManagerBase. */
905void LLVMDisposePassManager(LLVMPassManagerRef PM);
906
907
Gordon Henriksen76a03742007-09-18 03:18:57 +0000908#ifdef __cplusplus
909}
Gordon Henriksen76a03742007-09-18 03:18:57 +0000910
Gordon Henriksen7330acd2007-10-05 23:59:36 +0000911namespace llvm {
Gordon Henriksen0a68fe22007-12-12 01:04:30 +0000912 class ModuleProvider;
Gordon Henriksen34eb6d82007-12-19 22:30:40 +0000913 class MemoryBuffer;
Gordon Henriksen96571492008-03-16 15:55:43 +0000914 class PassManagerBase;
Gordon Henriksen0a68fe22007-12-12 01:04:30 +0000915
Gordon Henriksen34eb6d82007-12-19 22:30:40 +0000916 #define DEFINE_SIMPLE_CONVERSION_FUNCTIONS(ty, ref) \
917 inline ty *unwrap(ref P) { \
918 return reinterpret_cast<ty*>(P); \
919 } \
920 \
921 inline ref wrap(const ty *P) { \
922 return reinterpret_cast<ref>(const_cast<ty*>(P)); \
923 }
Gordon Henriksen7330acd2007-10-05 23:59:36 +0000924
Gordon Henriksen878114b2008-03-16 04:20:44 +0000925 #define DEFINE_ISA_CONVERSION_FUNCTIONS(ty, ref) \
926 DEFINE_SIMPLE_CONVERSION_FUNCTIONS(ty, ref) \
927 \
928 template<typename T> \
929 inline T *unwrap(ref P) { \
930 return cast<T>(unwrap(P)); \
931 }
932
933 #define DEFINE_STDCXX_CONVERSION_FUNCTIONS(ty, ref) \
934 DEFINE_SIMPLE_CONVERSION_FUNCTIONS(ty, ref) \
935 \
936 template<typename T> \
937 inline T *unwrap(ref P) { \
938 T *Q = dynamic_cast<T*>(unwrap(P)); \
939 assert(Q && "Invalid cast!"); \
940 return Q; \
941 }
942
943 DEFINE_ISA_CONVERSION_FUNCTIONS (Type, LLVMTypeRef )
944 DEFINE_ISA_CONVERSION_FUNCTIONS (Value, LLVMValueRef )
Gordon Henriksen823f9732007-12-27 18:25:59 +0000945 DEFINE_SIMPLE_CONVERSION_FUNCTIONS(Module, LLVMModuleRef )
946 DEFINE_SIMPLE_CONVERSION_FUNCTIONS(BasicBlock, LLVMBasicBlockRef )
Eric Christopher59278832008-08-08 19:39:37 +0000947 DEFINE_SIMPLE_CONVERSION_FUNCTIONS(IRBuilder<>, LLVMBuilderRef )
Gordon Henriksen823f9732007-12-27 18:25:59 +0000948 DEFINE_SIMPLE_CONVERSION_FUNCTIONS(PATypeHolder, LLVMTypeHandleRef )
949 DEFINE_SIMPLE_CONVERSION_FUNCTIONS(ModuleProvider, LLVMModuleProviderRef)
950 DEFINE_SIMPLE_CONVERSION_FUNCTIONS(MemoryBuffer, LLVMMemoryBufferRef )
Owen Anderson6773d382009-07-01 16:58:40 +0000951 DEFINE_SIMPLE_CONVERSION_FUNCTIONS(LLVMContext, LLVMContextRef )
Gordon Henriksen878114b2008-03-16 04:20:44 +0000952 DEFINE_STDCXX_CONVERSION_FUNCTIONS(PassManagerBase, LLVMPassManagerRef )
Gordon Henriksen7330acd2007-10-05 23:59:36 +0000953
Gordon Henriksen878114b2008-03-16 04:20:44 +0000954 #undef DEFINE_STDCXX_CONVERSION_FUNCTIONS
955 #undef DEFINE_ISA_CONVERSION_FUNCTIONS
Gordon Henriksen34eb6d82007-12-19 22:30:40 +0000956 #undef DEFINE_SIMPLE_CONVERSION_FUNCTIONS
Erick Tryzelaar262332f2009-08-14 00:01:31 +0000957
958 /* Specialized opaque context conversions.
959 */
960 inline LLVMContext **unwrap(LLVMContextRef* Tys) {
961 return reinterpret_cast<LLVMContext**>(Tys);
962 }
963
964 inline LLVMContextRef *wrap(const LLVMContext **Tys) {
965 return reinterpret_cast<LLVMContextRef*>(const_cast<LLVMContext**>(Tys));
966 }
Gordon Henriksen7330acd2007-10-05 23:59:36 +0000967
Gordon Henriksen34eb6d82007-12-19 22:30:40 +0000968 /* Specialized opaque type conversions.
969 */
Gordon Henriksen7330acd2007-10-05 23:59:36 +0000970 inline Type **unwrap(LLVMTypeRef* Tys) {
971 return reinterpret_cast<Type**>(Tys);
972 }
973
Gordon Henriksen7330acd2007-10-05 23:59:36 +0000974 inline LLVMTypeRef *wrap(const Type **Tys) {
975 return reinterpret_cast<LLVMTypeRef*>(const_cast<Type**>(Tys));
976 }
977
Gordon Henriksen34eb6d82007-12-19 22:30:40 +0000978 /* Specialized opaque value conversions.
Gordon Henriksen7330acd2007-10-05 23:59:36 +0000979 */
Gordon Henriksen7330acd2007-10-05 23:59:36 +0000980 inline Value **unwrap(LLVMValueRef *Vals) {
981 return reinterpret_cast<Value**>(Vals);
982 }
983
984 template<typename T>
985 inline T **unwrap(LLVMValueRef *Vals, unsigned Length) {
986 #if DEBUG
Chris Lattnerb7971152009-07-10 18:28:19 +0000987 for (LLVMValueRef *I = Vals, *E = Vals + Length; I != E; ++I)
Gordon Henriksen7330acd2007-10-05 23:59:36 +0000988 cast<T>(*I);
989 #endif
990 return reinterpret_cast<T**>(Vals);
991 }
992
Gordon Henriksen7330acd2007-10-05 23:59:36 +0000993 inline LLVMValueRef *wrap(const Value **Vals) {
994 return reinterpret_cast<LLVMValueRef*>(const_cast<Value**>(Vals));
995 }
Gordon Henriksen7330acd2007-10-05 23:59:36 +0000996}
997
998#endif /* !defined(__cplusplus) */
999
1000#endif /* !defined(LLVM_C_CORE_H) */