blob: bbef134a0b36e93ee7e118fe1dd78d70a3dde237 [file] [log] [blame]
Gordon Henriksen8b94a142007-09-18 03:18:57 +00001/*===-- llvm-c/Core.h - Core Library C Interface ------------------*- C -*-===*\
2|* *|
3|* The LLVM Compiler Infrastructure *|
4|* *|
Chris Lattner7ed47a12007-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 Henriksen8b94a142007-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 Henriksenacd96192007-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 Henriksen8b94a142007-09-18 03:18:57 +000031\*===----------------------------------------------------------------------===*/
32
33#ifndef LLVM_C_CORE_H
34#define LLVM_C_CORE_H
35
36#ifdef __cplusplus
Gordon Henriksenacd96192007-10-05 23:59:36 +000037
38/* Need these includes to support the LLVM 'cast' template for the C++ 'wrap'
39 and 'unwrap' conversion functions. */
40#include "llvm/Module.h"
Duncan Sands89f6d882008-04-13 06:22:09 +000041#include "llvm/Support/IRBuilder.h"
Gordon Henriksenacd96192007-10-05 23:59:36 +000042
Gordon Henriksen8b94a142007-09-18 03:18:57 +000043extern "C" {
44#endif
45
46
47/* Opaque types. */
Gordon Henriksendc2c07a2007-12-30 17:46:33 +000048
49/**
50 * The top-level container for all other LLVM Intermediate Representation (IR)
51 * objects. See the llvm::Module class.
52 */
Gordon Henriksen8b94a142007-09-18 03:18:57 +000053typedef struct LLVMOpaqueModule *LLVMModuleRef;
Gordon Henriksendc2c07a2007-12-30 17:46:33 +000054
55/**
Gordon Henriksenbbf1c512008-03-07 19:13:06 +000056 * Each value in the LLVM IR has a type, an LLVMTypeRef. See the llvm::Type
57 * class.
Gordon Henriksendc2c07a2007-12-30 17:46:33 +000058 */
Gordon Henriksen8b94a142007-09-18 03:18:57 +000059typedef struct LLVMOpaqueType *LLVMTypeRef;
Gordon Henriksendc2c07a2007-12-30 17:46:33 +000060
61/**
Gordon Henriksenbbf1c512008-03-07 19:13:06 +000062 * When building recursive types using LLVMRefineType, LLVMTypeRef values may
63 * become invalid; use LLVMTypeHandleRef to resolve this problem. See the
64 * llvm::AbstractTypeHolder class.
Gordon Henriksendc2c07a2007-12-30 17:46:33 +000065 */
Gordon Henriksen1cf08fd2007-10-07 00:13:35 +000066typedef struct LLVMOpaqueTypeHandle *LLVMTypeHandleRef;
Gordon Henriksendc2c07a2007-12-30 17:46:33 +000067
Gordon Henriksen8b94a142007-09-18 03:18:57 +000068typedef struct LLVMOpaqueValue *LLVMValueRef;
Gordon Henriksen46abf912007-09-26 20:56:12 +000069typedef struct LLVMOpaqueBasicBlock *LLVMBasicBlockRef;
70typedef struct LLVMOpaqueBuilder *LLVMBuilderRef;
Gordon Henriksenda1435f2007-12-19 22:30:40 +000071
72/* Used to provide a module to JIT or interpreter.
73 * See the llvm::ModuleProvider class.
74 */
Gordon Henriksen1ae61352007-12-12 01:04:30 +000075typedef struct LLVMOpaqueModuleProvider *LLVMModuleProviderRef;
Gordon Henriksen8b94a142007-09-18 03:18:57 +000076
Gordon Henriksenda1435f2007-12-19 22:30:40 +000077/* Used to provide a module to JIT or interpreter.
78 * See the llvm::MemoryBuffer class.
79 */
80typedef struct LLVMOpaqueMemoryBuffer *LLVMMemoryBufferRef;
81
Gordon Henriksend78c0f52008-03-16 04:20:44 +000082/** See the llvm::PassManagerBase class. */
83typedef struct LLVMOpaquePassManager *LLVMPassManagerRef;
84
Gordon Henriksen8b94a142007-09-18 03:18:57 +000085typedef enum {
Gordon Henriksene2435da2008-04-28 17:37:06 +000086 LLVMZExtParamAttr = 1<<0,
87 LLVMSExtParamAttr = 1<<1,
88 LLVMNoReturnParamAttr = 1<<2,
Anton Korobeynikov1fcfc3b2008-04-28 21:48:04 +000089 LLVMInRegParamAttr = 1<<3,
90 LLVMStructRetParamAttr = 1<<4,
91 LLVMNoUnwindParamAttr = 1<<5,
92 LLVMNoAliasParamAttr = 1<<6,
Gordon Henriksene2435da2008-04-28 17:37:06 +000093 LLVMByValParamAttr = 1<<7,
94 LLVMNestParamAttr = 1<<8,
95 LLVMReadNoneParamAttr = 1<<9,
96 LLVMReadOnlyParamAttr = 1<<10
97} LLVMParamAttr;
98
99typedef enum {
Gordon Henriksendc2c07a2007-12-30 17:46:33 +0000100 LLVMVoidTypeKind, /**< type with no size */
101 LLVMFloatTypeKind, /**< 32 bit floating point type */
102 LLVMDoubleTypeKind, /**< 64 bit floating point type */
103 LLVMX86_FP80TypeKind, /**< 80 bit floating point type (X87) */
104 LLVMFP128TypeKind, /**< 128 bit floating point type (112-bit mantissa)*/
105 LLVMPPC_FP128TypeKind, /**< 128 bit floating point type (two 64-bits) */
106 LLVMLabelTypeKind, /**< Labels */
107 LLVMIntegerTypeKind, /**< Arbitrary bit width integers */
108 LLVMFunctionTypeKind, /**< Functions */
109 LLVMStructTypeKind, /**< Structures */
110 LLVMArrayTypeKind, /**< Arrays */
111 LLVMPointerTypeKind, /**< Pointers */
112 LLVMOpaqueTypeKind, /**< Opaque: type with unknown structure */
113 LLVMVectorTypeKind /**< SIMD 'packed' format, or other vector type */
Gordon Henriksen8b94a142007-09-18 03:18:57 +0000114} LLVMTypeKind;
115
116typedef enum {
Gordon Henriksendc2c07a2007-12-30 17:46:33 +0000117 LLVMExternalLinkage, /**< Externally visible function */
118 LLVMLinkOnceLinkage, /**< Keep one copy of function when linking (inline)*/
119 LLVMWeakLinkage, /**< Keep one copy of function when linking (weak) */
120 LLVMAppendingLinkage, /**< Special purpose, only applies to global arrays */
121 LLVMInternalLinkage, /**< Rename collisions when linking (static
122 functions) */
123 LLVMDLLImportLinkage, /**< Function to be imported from DLL */
124 LLVMDLLExportLinkage, /**< Function to be accessible from DLL */
125 LLVMExternalWeakLinkage,/**< ExternalWeak linkage description */
126 LLVMGhostLinkage /**< Stand-in functions for streaming fns from
127 bitcode */
Gordon Henriksen8b94a142007-09-18 03:18:57 +0000128} LLVMLinkage;
129
130typedef enum {
Gordon Henriksendc2c07a2007-12-30 17:46:33 +0000131 LLVMDefaultVisibility, /**< The GV is visible */
132 LLVMHiddenVisibility, /**< The GV is hidden */
133 LLVMProtectedVisibility /**< The GV is protected */
Gordon Henriksen8b94a142007-09-18 03:18:57 +0000134} LLVMVisibility;
135
Gordon Henriksen46abf912007-09-26 20:56:12 +0000136typedef enum {
137 LLVMCCallConv = 0,
138 LLVMFastCallConv = 8,
139 LLVMColdCallConv = 9,
140 LLVMX86StdcallCallConv = 64,
141 LLVMX86FastcallCallConv = 65
142} LLVMCallConv;
143
144typedef enum {
Gordon Henriksendc2c07a2007-12-30 17:46:33 +0000145 LLVMIntEQ = 32, /**< equal */
146 LLVMIntNE, /**< not equal */
147 LLVMIntUGT, /**< unsigned greater than */
148 LLVMIntUGE, /**< unsigned greater or equal */
149 LLVMIntULT, /**< unsigned less than */
150 LLVMIntULE, /**< unsigned less or equal */
151 LLVMIntSGT, /**< signed greater than */
152 LLVMIntSGE, /**< signed greater or equal */
153 LLVMIntSLT, /**< signed less than */
154 LLVMIntSLE /**< signed less or equal */
Gordon Henriksen46abf912007-09-26 20:56:12 +0000155} LLVMIntPredicate;
156
157typedef enum {
Gordon Henriksendc2c07a2007-12-30 17:46:33 +0000158 LLVMRealPredicateFalse, /**< Always false (always folded) */
159 LLVMRealOEQ, /**< True if ordered and equal */
160 LLVMRealOGT, /**< True if ordered and greater than */
161 LLVMRealOGE, /**< True if ordered and greater than or equal */
162 LLVMRealOLT, /**< True if ordered and less than */
163 LLVMRealOLE, /**< True if ordered and less than or equal */
164 LLVMRealONE, /**< True if ordered and operands are unequal */
165 LLVMRealORD, /**< True if ordered (no nans) */
166 LLVMRealUNO, /**< True if unordered: isnan(X) | isnan(Y) */
167 LLVMRealUEQ, /**< True if unordered or equal */
168 LLVMRealUGT, /**< True if unordered or greater than */
169 LLVMRealUGE, /**< True if unordered, greater than, or equal */
170 LLVMRealULT, /**< True if unordered or less than */
171 LLVMRealULE, /**< True if unordered, less than, or equal */
172 LLVMRealUNE, /**< True if unordered or not equal */
173 LLVMRealPredicateTrue /**< Always true (always folded) */
Gordon Henriksen46abf912007-09-26 20:56:12 +0000174} LLVMRealPredicate;
175
Gordon Henriksen8b94a142007-09-18 03:18:57 +0000176
Gordon Henriksenda1435f2007-12-19 22:30:40 +0000177/*===-- Error handling ----------------------------------------------------===*/
178
179void LLVMDisposeMessage(char *Message);
180
181
Gordon Henriksen8b94a142007-09-18 03:18:57 +0000182/*===-- Modules -----------------------------------------------------------===*/
183
184/* Create and destroy modules. */
Gordon Henriksenbbf1c512008-03-07 19:13:06 +0000185/** See llvm::Module::Module. */
Gordon Henriksen8b94a142007-09-18 03:18:57 +0000186LLVMModuleRef LLVMModuleCreateWithName(const char *ModuleID);
Gordon Henriksenbbf1c512008-03-07 19:13:06 +0000187
188/** See llvm::Module::~Module. */
Gordon Henriksen8b94a142007-09-18 03:18:57 +0000189void LLVMDisposeModule(LLVMModuleRef M);
190
Gordon Henriksenbbf1c512008-03-07 19:13:06 +0000191/** Data layout. See Module::getDataLayout. */
Gordon Henriksena353ffa2007-12-27 20:13:47 +0000192const char *LLVMGetDataLayout(LLVMModuleRef M);
193void LLVMSetDataLayout(LLVMModuleRef M, const char *Triple);
194
Gordon Henriksenbbf1c512008-03-07 19:13:06 +0000195/** Target triple. See Module::getTargetTriple. */
Gordon Henriksena353ffa2007-12-27 20:13:47 +0000196const char *LLVMGetTarget(LLVMModuleRef M);
197void LLVMSetTarget(LLVMModuleRef M, const char *Triple);
198
Gordon Henriksenbbf1c512008-03-07 19:13:06 +0000199/** See Module::addTypeName. */
Gordon Henriksen8b94a142007-09-18 03:18:57 +0000200int LLVMAddTypeName(LLVMModuleRef M, const char *Name, LLVMTypeRef Ty);
Gordon Henriksen46abf912007-09-26 20:56:12 +0000201void LLVMDeleteTypeName(LLVMModuleRef M, const char *Name);
Gordon Henriksen8b94a142007-09-18 03:18:57 +0000202
Gordon Henriksenaf59b102008-03-14 23:58:56 +0000203/** See Module::dump. */
204void LLVMDumpModule(LLVMModuleRef M);
205
Gordon Henriksen8b94a142007-09-18 03:18:57 +0000206
Gordon Henriksen46abf912007-09-26 20:56:12 +0000207/*===-- Types -------------------------------------------------------------===*/
Gordon Henriksen8b94a142007-09-18 03:18:57 +0000208
209/* LLVM types conform to the following hierarchy:
210 *
211 * types:
212 * integer type
213 * real type
214 * function type
215 * sequence types:
216 * array type
217 * pointer type
218 * vector type
219 * void type
220 * label type
221 * opaque type
222 */
223
Gordon Henriksenbbf1c512008-03-07 19:13:06 +0000224/** See llvm::LLVMTypeKind::getTypeID. */
Gordon Henriksen8b94a142007-09-18 03:18:57 +0000225LLVMTypeKind LLVMGetTypeKind(LLVMTypeRef Ty);
Gordon Henriksenbbf1c512008-03-07 19:13:06 +0000226
Gordon Henriksen8b94a142007-09-18 03:18:57 +0000227/* Operations on integer types */
Gordon Henriksen16c1f442008-05-04 12:55:34 +0000228LLVMTypeRef LLVMInt1Type(void);
229LLVMTypeRef LLVMInt8Type(void);
230LLVMTypeRef LLVMInt16Type(void);
231LLVMTypeRef LLVMInt32Type(void);
232LLVMTypeRef LLVMInt64Type(void);
Gordon Henriksen81a78812007-10-06 16:05:20 +0000233LLVMTypeRef LLVMIntType(unsigned NumBits);
Gordon Henriksen46abf912007-09-26 20:56:12 +0000234unsigned LLVMGetIntTypeWidth(LLVMTypeRef IntegerTy);
Gordon Henriksen8b94a142007-09-18 03:18:57 +0000235
236/* Operations on real types */
Gordon Henriksen16c1f442008-05-04 12:55:34 +0000237LLVMTypeRef LLVMFloatType(void);
238LLVMTypeRef LLVMDoubleType(void);
239LLVMTypeRef LLVMX86FP80Type(void);
240LLVMTypeRef LLVMFP128Type(void);
241LLVMTypeRef LLVMPPCFP128Type(void);
Gordon Henriksen8b94a142007-09-18 03:18:57 +0000242
243/* Operations on function types */
Gordon Henriksen81a78812007-10-06 16:05:20 +0000244LLVMTypeRef LLVMFunctionType(LLVMTypeRef ReturnType,
245 LLVMTypeRef *ParamTypes, unsigned ParamCount,
246 int IsVarArg);
Gordon Henriksen8b94a142007-09-18 03:18:57 +0000247int LLVMIsFunctionVarArg(LLVMTypeRef FunctionTy);
Gordon Henriksen46abf912007-09-26 20:56:12 +0000248LLVMTypeRef LLVMGetReturnType(LLVMTypeRef FunctionTy);
249unsigned LLVMCountParamTypes(LLVMTypeRef FunctionTy);
250void LLVMGetParamTypes(LLVMTypeRef FunctionTy, LLVMTypeRef *Dest);
Gordon Henriksen8b94a142007-09-18 03:18:57 +0000251
252/* Operations on struct types */
Gordon Henriksen81a78812007-10-06 16:05:20 +0000253LLVMTypeRef LLVMStructType(LLVMTypeRef *ElementTypes, unsigned ElementCount,
254 int Packed);
Gordon Henriksen46abf912007-09-26 20:56:12 +0000255unsigned LLVMCountStructElementTypes(LLVMTypeRef StructTy);
Gordon Henriksen8b94a142007-09-18 03:18:57 +0000256void LLVMGetStructElementTypes(LLVMTypeRef StructTy, LLVMTypeRef *Dest);
257int LLVMIsPackedStruct(LLVMTypeRef StructTy);
258
259/* Operations on array, pointer, and vector types (sequence types) */
Gordon Henriksen81a78812007-10-06 16:05:20 +0000260LLVMTypeRef LLVMArrayType(LLVMTypeRef ElementType, unsigned ElementCount);
Gordon Henriksen57cebee2007-12-17 16:08:32 +0000261LLVMTypeRef LLVMPointerType(LLVMTypeRef ElementType, unsigned AddressSpace);
Gordon Henriksen81a78812007-10-06 16:05:20 +0000262LLVMTypeRef LLVMVectorType(LLVMTypeRef ElementType, unsigned ElementCount);
Gordon Henriksen8b94a142007-09-18 03:18:57 +0000263
264LLVMTypeRef LLVMGetElementType(LLVMTypeRef Ty);
265unsigned LLVMGetArrayLength(LLVMTypeRef ArrayTy);
Gordon Henriksen57cebee2007-12-17 16:08:32 +0000266unsigned LLVMGetPointerAddressSpace(LLVMTypeRef PointerTy);
Gordon Henriksen8b94a142007-09-18 03:18:57 +0000267unsigned LLVMGetVectorSize(LLVMTypeRef VectorTy);
268
269/* Operations on other types */
Gordon Henriksen16c1f442008-05-04 12:55:34 +0000270LLVMTypeRef LLVMVoidType(void);
271LLVMTypeRef LLVMLabelType(void);
272LLVMTypeRef LLVMOpaqueType(void);
Gordon Henriksen8b94a142007-09-18 03:18:57 +0000273
Gordon Henriksen1cf08fd2007-10-07 00:13:35 +0000274/* Operations on type handles */
275LLVMTypeHandleRef LLVMCreateTypeHandle(LLVMTypeRef PotentiallyAbstractTy);
276void LLVMRefineType(LLVMTypeRef AbstractTy, LLVMTypeRef ConcreteTy);
277LLVMTypeRef LLVMResolveTypeHandle(LLVMTypeHandleRef TypeHandle);
278void LLVMDisposeTypeHandle(LLVMTypeHandleRef TypeHandle);
279
Gordon Henriksen8b94a142007-09-18 03:18:57 +0000280
281/*===-- Values ------------------------------------------------------------===*/
282
283/* The bulk of LLVM's object model consists of values, which comprise a very
284 * rich type hierarchy.
285 *
286 * values:
287 * constants:
288 * scalar constants
289 * composite contants
290 * globals:
291 * global variable
292 * function
293 * alias
Gordon Henriksen46abf912007-09-26 20:56:12 +0000294 * basic blocks
Gordon Henriksen8b94a142007-09-18 03:18:57 +0000295 */
296
297/* Operations on all values */
Gordon Henriksen46abf912007-09-26 20:56:12 +0000298LLVMTypeRef LLVMTypeOf(LLVMValueRef Val);
Gordon Henriksen8b94a142007-09-18 03:18:57 +0000299const char *LLVMGetValueName(LLVMValueRef Val);
300void LLVMSetValueName(LLVMValueRef Val, const char *Name);
Gordon Henriksen88cc6992007-10-06 00:08:49 +0000301void LLVMDumpValue(LLVMValueRef Val);
Gordon Henriksen8b94a142007-09-18 03:18:57 +0000302
303/* Operations on constants of any type */
Gordon Henriksene3b989d2007-10-06 15:11:06 +0000304LLVMValueRef LLVMConstNull(LLVMTypeRef Ty); /* all zeroes */
305LLVMValueRef LLVMConstAllOnes(LLVMTypeRef Ty); /* only for int/vector */
Gordon Henriksen8b94a142007-09-18 03:18:57 +0000306LLVMValueRef LLVMGetUndef(LLVMTypeRef Ty);
Gordon Henriksen344be5f2007-09-18 18:07:51 +0000307int LLVMIsConstant(LLVMValueRef Val);
Gordon Henriksen8b94a142007-09-18 03:18:57 +0000308int LLVMIsNull(LLVMValueRef Val);
Gordon Henriksen344be5f2007-09-18 18:07:51 +0000309int LLVMIsUndef(LLVMValueRef Val);
Gordon Henriksen8b94a142007-09-18 03:18:57 +0000310
311/* Operations on scalar constants */
Gordon Henriksene3b989d2007-10-06 15:11:06 +0000312LLVMValueRef LLVMConstInt(LLVMTypeRef IntTy, unsigned long long N,
313 int SignExtend);
314LLVMValueRef LLVMConstReal(LLVMTypeRef RealTy, double N);
Gordon Henriksene62a8a32008-02-02 01:07:50 +0000315LLVMValueRef LLVMConstRealOfString(LLVMTypeRef RealTy, const char *Text);
Gordon Henriksen8b94a142007-09-18 03:18:57 +0000316
317/* Operations on composite constants */
Gordon Henriksene3b989d2007-10-06 15:11:06 +0000318LLVMValueRef LLVMConstString(const char *Str, unsigned Length,
319 int DontNullTerminate);
Gordon Henriksen877ee972008-04-25 03:21:19 +0000320LLVMValueRef LLVMConstArray(LLVMTypeRef ElementTy,
Gordon Henriksene3b989d2007-10-06 15:11:06 +0000321 LLVMValueRef *ConstantVals, unsigned Length);
322LLVMValueRef LLVMConstStruct(LLVMValueRef *ConstantVals, unsigned Count,
323 int packed);
324LLVMValueRef LLVMConstVector(LLVMValueRef *ScalarConstantVals, unsigned Size);
Gordon Henriksen8b94a142007-09-18 03:18:57 +0000325
Gordon Henriksen46475692007-10-06 14:29:36 +0000326/* Constant expressions */
327LLVMValueRef LLVMSizeOf(LLVMTypeRef Ty);
328LLVMValueRef LLVMConstNeg(LLVMValueRef ConstantVal);
329LLVMValueRef LLVMConstNot(LLVMValueRef ConstantVal);
330LLVMValueRef LLVMConstAdd(LLVMValueRef LHSConstant, LLVMValueRef RHSConstant);
331LLVMValueRef LLVMConstSub(LLVMValueRef LHSConstant, LLVMValueRef RHSConstant);
332LLVMValueRef LLVMConstMul(LLVMValueRef LHSConstant, LLVMValueRef RHSConstant);
333LLVMValueRef LLVMConstUDiv(LLVMValueRef LHSConstant, LLVMValueRef RHSConstant);
334LLVMValueRef LLVMConstSDiv(LLVMValueRef LHSConstant, LLVMValueRef RHSConstant);
335LLVMValueRef LLVMConstFDiv(LLVMValueRef LHSConstant, LLVMValueRef RHSConstant);
336LLVMValueRef LLVMConstURem(LLVMValueRef LHSConstant, LLVMValueRef RHSConstant);
337LLVMValueRef LLVMConstSRem(LLVMValueRef LHSConstant, LLVMValueRef RHSConstant);
338LLVMValueRef LLVMConstFRem(LLVMValueRef LHSConstant, LLVMValueRef RHSConstant);
339LLVMValueRef LLVMConstAnd(LLVMValueRef LHSConstant, LLVMValueRef RHSConstant);
340LLVMValueRef LLVMConstOr(LLVMValueRef LHSConstant, LLVMValueRef RHSConstant);
341LLVMValueRef LLVMConstXor(LLVMValueRef LHSConstant, LLVMValueRef RHSConstant);
342LLVMValueRef LLVMConstICmp(LLVMIntPredicate Predicate,
343 LLVMValueRef LHSConstant, LLVMValueRef RHSConstant);
344LLVMValueRef LLVMConstFCmp(LLVMRealPredicate Predicate,
345 LLVMValueRef LHSConstant, LLVMValueRef RHSConstant);
346LLVMValueRef LLVMConstShl(LLVMValueRef LHSConstant, LLVMValueRef RHSConstant);
347LLVMValueRef LLVMConstLShr(LLVMValueRef LHSConstant, LLVMValueRef RHSConstant);
348LLVMValueRef LLVMConstAShr(LLVMValueRef LHSConstant, LLVMValueRef RHSConstant);
349LLVMValueRef LLVMConstGEP(LLVMValueRef ConstantVal,
350 LLVMValueRef *ConstantIndices, unsigned NumIndices);
351LLVMValueRef LLVMConstTrunc(LLVMValueRef ConstantVal, LLVMTypeRef ToType);
352LLVMValueRef LLVMConstSExt(LLVMValueRef ConstantVal, LLVMTypeRef ToType);
353LLVMValueRef LLVMConstZExt(LLVMValueRef ConstantVal, LLVMTypeRef ToType);
354LLVMValueRef LLVMConstFPTrunc(LLVMValueRef ConstantVal, LLVMTypeRef ToType);
355LLVMValueRef LLVMConstFPExt(LLVMValueRef ConstantVal, LLVMTypeRef ToType);
356LLVMValueRef LLVMConstUIToFP(LLVMValueRef ConstantVal, LLVMTypeRef ToType);
357LLVMValueRef LLVMConstSIToFP(LLVMValueRef ConstantVal, LLVMTypeRef ToType);
358LLVMValueRef LLVMConstFPToUI(LLVMValueRef ConstantVal, LLVMTypeRef ToType);
359LLVMValueRef LLVMConstFPToSI(LLVMValueRef ConstantVal, LLVMTypeRef ToType);
360LLVMValueRef LLVMConstPtrToInt(LLVMValueRef ConstantVal, LLVMTypeRef ToType);
361LLVMValueRef LLVMConstIntToPtr(LLVMValueRef ConstantVal, LLVMTypeRef ToType);
362LLVMValueRef LLVMConstBitCast(LLVMValueRef ConstantVal, LLVMTypeRef ToType);
363LLVMValueRef LLVMConstSelect(LLVMValueRef ConstantCondition,
364 LLVMValueRef ConstantIfTrue,
365 LLVMValueRef ConstantIfFalse);
366LLVMValueRef LLVMConstExtractElement(LLVMValueRef VectorConstant,
367 LLVMValueRef IndexConstant);
368LLVMValueRef LLVMConstInsertElement(LLVMValueRef VectorConstant,
369 LLVMValueRef ElementValueConstant,
370 LLVMValueRef IndexConstant);
371LLVMValueRef LLVMConstShuffleVector(LLVMValueRef VectorAConstant,
372 LLVMValueRef VectorBConstant,
373 LLVMValueRef MaskConstant);
374
Gordon Henriksen8b94a142007-09-18 03:18:57 +0000375/* Operations on global variables, functions, and aliases (globals) */
Gordon Henriksendc1ce7b2008-03-19 01:11:35 +0000376LLVMModuleRef LLVMGetGlobalParent(LLVMValueRef Global);
Gordon Henriksen8b94a142007-09-18 03:18:57 +0000377int LLVMIsDeclaration(LLVMValueRef Global);
378LLVMLinkage LLVMGetLinkage(LLVMValueRef Global);
379void LLVMSetLinkage(LLVMValueRef Global, LLVMLinkage Linkage);
380const char *LLVMGetSection(LLVMValueRef Global);
381void LLVMSetSection(LLVMValueRef Global, const char *Section);
382LLVMVisibility LLVMGetVisibility(LLVMValueRef Global);
383void LLVMSetVisibility(LLVMValueRef Global, LLVMVisibility Viz);
384unsigned LLVMGetAlignment(LLVMValueRef Global);
385void LLVMSetAlignment(LLVMValueRef Global, unsigned Bytes);
386
387/* Operations on global variables */
388LLVMValueRef LLVMAddGlobal(LLVMModuleRef M, LLVMTypeRef Ty, const char *Name);
Gordon Henriksen6d6203d2007-10-08 03:45:09 +0000389LLVMValueRef LLVMGetNamedGlobal(LLVMModuleRef M, const char *Name);
Gordon Henriksen4733be32008-03-23 22:21:29 +0000390LLVMValueRef LLVMGetFirstGlobal(LLVMModuleRef M);
391LLVMValueRef LLVMGetLastGlobal(LLVMModuleRef M);
392LLVMValueRef LLVMGetNextGlobal(LLVMValueRef GlobalVar);
393LLVMValueRef LLVMGetPreviousGlobal(LLVMValueRef GlobalVar);
Gordon Henriksen8b94a142007-09-18 03:18:57 +0000394void LLVMDeleteGlobal(LLVMValueRef GlobalVar);
395int LLVMHasInitializer(LLVMValueRef GlobalVar);
396LLVMValueRef LLVMGetInitializer(LLVMValueRef GlobalVar);
397void LLVMSetInitializer(LLVMValueRef GlobalVar, LLVMValueRef ConstantVal);
398int LLVMIsThreadLocal(LLVMValueRef GlobalVar);
399void LLVMSetThreadLocal(LLVMValueRef GlobalVar, int IsThreadLocal);
Gordon Henriksenc84c16b2007-10-07 17:31:42 +0000400int LLVMIsGlobalConstant(LLVMValueRef GlobalVar);
401void LLVMSetGlobalConstant(LLVMValueRef GlobalVar, int IsConstant);
Gordon Henriksen8b94a142007-09-18 03:18:57 +0000402
Gordon Henriksen46abf912007-09-26 20:56:12 +0000403/* Operations on functions */
404LLVMValueRef LLVMAddFunction(LLVMModuleRef M, const char *Name,
405 LLVMTypeRef FunctionTy);
Gordon Henriksen6d6203d2007-10-08 03:45:09 +0000406LLVMValueRef LLVMGetNamedFunction(LLVMModuleRef M, const char *Name);
Gordon Henriksen34000972008-03-19 03:47:18 +0000407LLVMValueRef LLVMGetFirstFunction(LLVMModuleRef M);
408LLVMValueRef LLVMGetLastFunction(LLVMModuleRef M);
409LLVMValueRef LLVMGetNextFunction(LLVMValueRef Fn);
410LLVMValueRef LLVMGetPreviousFunction(LLVMValueRef Fn);
Gordon Henriksen46abf912007-09-26 20:56:12 +0000411void LLVMDeleteFunction(LLVMValueRef Fn);
Gordon Henriksen46abf912007-09-26 20:56:12 +0000412unsigned LLVMGetIntrinsicID(LLVMValueRef Fn);
413unsigned LLVMGetFunctionCallConv(LLVMValueRef Fn);
414void LLVMSetFunctionCallConv(LLVMValueRef Fn, unsigned CC);
Gordon Henriksen80a75bf2007-12-10 03:18:06 +0000415const char *LLVMGetCollector(LLVMValueRef Fn);
416void LLVMSetCollector(LLVMValueRef Fn, const char *Coll);
Gordon Henriksen46abf912007-09-26 20:56:12 +0000417
Gordon Henriksendc1ce7b2008-03-19 01:11:35 +0000418/* Operations on parameters */
419unsigned LLVMCountParams(LLVMValueRef Fn);
420void LLVMGetParams(LLVMValueRef Fn, LLVMValueRef *Params);
421LLVMValueRef LLVMGetParam(LLVMValueRef Fn, unsigned Index);
422LLVMValueRef LLVMGetParamParent(LLVMValueRef Inst);
Gordon Henriksen4733be32008-03-23 22:21:29 +0000423LLVMValueRef LLVMGetFirstParam(LLVMValueRef Fn);
424LLVMValueRef LLVMGetLastParam(LLVMValueRef Fn);
425LLVMValueRef LLVMGetNextParam(LLVMValueRef Arg);
426LLVMValueRef LLVMGetPreviousParam(LLVMValueRef Arg);
Gordon Henriksene2435da2008-04-28 17:37:06 +0000427void LLVMAddParamAttr(LLVMValueRef Arg, LLVMParamAttr PA);
428void LLVMRemoveParamAttr(LLVMValueRef Arg, LLVMParamAttr PA);
429void LLVMSetParamAlignment(LLVMValueRef Arg, unsigned align);
Gordon Henriksendc1ce7b2008-03-19 01:11:35 +0000430
Gordon Henriksen46abf912007-09-26 20:56:12 +0000431/* Operations on basic blocks */
Gordon Henriksen4733be32008-03-23 22:21:29 +0000432LLVMValueRef LLVMBasicBlockAsValue(LLVMBasicBlockRef BB);
Gordon Henriksen46abf912007-09-26 20:56:12 +0000433int LLVMValueIsBasicBlock(LLVMValueRef Val);
434LLVMBasicBlockRef LLVMValueAsBasicBlock(LLVMValueRef Val);
Gordon Henriksen4733be32008-03-23 22:21:29 +0000435LLVMValueRef LLVMGetBasicBlockParent(LLVMBasicBlockRef BB);
Gordon Henriksen46abf912007-09-26 20:56:12 +0000436unsigned LLVMCountBasicBlocks(LLVMValueRef Fn);
437void LLVMGetBasicBlocks(LLVMValueRef Fn, LLVMBasicBlockRef *BasicBlocks);
Gordon Henriksen34000972008-03-19 03:47:18 +0000438LLVMBasicBlockRef LLVMGetFirstBasicBlock(LLVMValueRef Fn);
439LLVMBasicBlockRef LLVMGetLastBasicBlock(LLVMValueRef Fn);
440LLVMBasicBlockRef LLVMGetNextBasicBlock(LLVMBasicBlockRef BB);
441LLVMBasicBlockRef LLVMGetPreviousBasicBlock(LLVMBasicBlockRef BB);
Gordon Henriksen46abf912007-09-26 20:56:12 +0000442LLVMBasicBlockRef LLVMGetEntryBasicBlock(LLVMValueRef Fn);
443LLVMBasicBlockRef LLVMAppendBasicBlock(LLVMValueRef Fn, const char *Name);
444LLVMBasicBlockRef LLVMInsertBasicBlock(LLVMBasicBlockRef InsertBeforeBB,
445 const char *Name);
446void LLVMDeleteBasicBlock(LLVMBasicBlockRef BB);
447
Gordon Henriksendc1ce7b2008-03-19 01:11:35 +0000448/* Operations on instructions */
449LLVMBasicBlockRef LLVMGetInstructionParent(LLVMValueRef Inst);
Gordon Henriksen34000972008-03-19 03:47:18 +0000450LLVMValueRef LLVMGetFirstInstruction(LLVMBasicBlockRef BB);
451LLVMValueRef LLVMGetLastInstruction(LLVMBasicBlockRef BB);
452LLVMValueRef LLVMGetNextInstruction(LLVMValueRef Inst);
453LLVMValueRef LLVMGetPreviousInstruction(LLVMValueRef Inst);
Gordon Henriksendc1ce7b2008-03-19 01:11:35 +0000454
Gordon Henriksencc0928f2007-12-29 20:45:00 +0000455/* Operations on call sites */
456void LLVMSetInstructionCallConv(LLVMValueRef Instr, unsigned CC);
457unsigned LLVMGetInstructionCallConv(LLVMValueRef Instr);
Gordon Henriksene2435da2008-04-28 17:37:06 +0000458void LLVMAddInstrParamAttr(LLVMValueRef Instr, unsigned index, LLVMParamAttr);
459void LLVMRemoveInstrParamAttr(LLVMValueRef Instr, unsigned index,
460 LLVMParamAttr);
461void LLVMSetInstrParamAlignment(LLVMValueRef Instr, unsigned index,
462 unsigned align);
Gordon Henriksencc0928f2007-12-29 20:45:00 +0000463
Gordon Henriksen2618a6c2007-10-08 18:14:39 +0000464/* Operations on phi nodes */
465void LLVMAddIncoming(LLVMValueRef PhiNode, LLVMValueRef *IncomingValues,
466 LLVMBasicBlockRef *IncomingBlocks, unsigned Count);
467unsigned LLVMCountIncoming(LLVMValueRef PhiNode);
468LLVMValueRef LLVMGetIncomingValue(LLVMValueRef PhiNode, unsigned Index);
469LLVMBasicBlockRef LLVMGetIncomingBlock(LLVMValueRef PhiNode, unsigned Index);
Gordon Henriksen46abf912007-09-26 20:56:12 +0000470
471/*===-- Instruction builders ----------------------------------------------===*/
472
473/* An instruction builder represents a point within a basic block, and is the
474 * exclusive means of building instructions using the C interface.
475 */
476
Gordon Henriksen16c1f442008-05-04 12:55:34 +0000477LLVMBuilderRef LLVMCreateBuilder(void);
Gordon Henriksen34000972008-03-19 03:47:18 +0000478void LLVMPositionBuilder(LLVMBuilderRef Builder, LLVMBasicBlockRef Block,
479 LLVMValueRef Instr);
Gordon Henriksen46abf912007-09-26 20:56:12 +0000480void LLVMPositionBuilderBefore(LLVMBuilderRef Builder, LLVMValueRef Instr);
481void LLVMPositionBuilderAtEnd(LLVMBuilderRef Builder, LLVMBasicBlockRef Block);
Gordon Henriksendc1ce7b2008-03-19 01:11:35 +0000482LLVMBasicBlockRef LLVMGetInsertBlock(LLVMBuilderRef Builder);
Gordon Henriksen46abf912007-09-26 20:56:12 +0000483void LLVMDisposeBuilder(LLVMBuilderRef Builder);
484
485/* Terminators */
486LLVMValueRef LLVMBuildRetVoid(LLVMBuilderRef);
487LLVMValueRef LLVMBuildRet(LLVMBuilderRef, LLVMValueRef V);
488LLVMValueRef LLVMBuildBr(LLVMBuilderRef, LLVMBasicBlockRef Dest);
489LLVMValueRef LLVMBuildCondBr(LLVMBuilderRef, LLVMValueRef If,
490 LLVMBasicBlockRef Then, LLVMBasicBlockRef Else);
491LLVMValueRef LLVMBuildSwitch(LLVMBuilderRef, LLVMValueRef V,
492 LLVMBasicBlockRef Else, unsigned NumCases);
493LLVMValueRef LLVMBuildInvoke(LLVMBuilderRef, LLVMValueRef Fn,
494 LLVMValueRef *Args, unsigned NumArgs,
495 LLVMBasicBlockRef Then, LLVMBasicBlockRef Catch,
496 const char *Name);
497LLVMValueRef LLVMBuildUnwind(LLVMBuilderRef);
498LLVMValueRef LLVMBuildUnreachable(LLVMBuilderRef);
499
Gordon Henriksenab477cc2008-01-01 05:50:53 +0000500/* Add a case to the switch instruction */
501void LLVMAddCase(LLVMValueRef Switch, LLVMValueRef OnVal,
502 LLVMBasicBlockRef Dest);
503
Gordon Henriksen46abf912007-09-26 20:56:12 +0000504/* Arithmetic */
505LLVMValueRef LLVMBuildAdd(LLVMBuilderRef, LLVMValueRef LHS, LLVMValueRef RHS,
506 const char *Name);
507LLVMValueRef LLVMBuildSub(LLVMBuilderRef, LLVMValueRef LHS, LLVMValueRef RHS,
508 const char *Name);
509LLVMValueRef LLVMBuildMul(LLVMBuilderRef, LLVMValueRef LHS, LLVMValueRef RHS,
510 const char *Name);
511LLVMValueRef LLVMBuildUDiv(LLVMBuilderRef, LLVMValueRef LHS, LLVMValueRef RHS,
512 const char *Name);
513LLVMValueRef LLVMBuildSDiv(LLVMBuilderRef, LLVMValueRef LHS, LLVMValueRef RHS,
514 const char *Name);
515LLVMValueRef LLVMBuildFDiv(LLVMBuilderRef, LLVMValueRef LHS, LLVMValueRef RHS,
516 const char *Name);
517LLVMValueRef LLVMBuildURem(LLVMBuilderRef, LLVMValueRef LHS, LLVMValueRef RHS,
518 const char *Name);
519LLVMValueRef LLVMBuildSRem(LLVMBuilderRef, LLVMValueRef LHS, LLVMValueRef RHS,
520 const char *Name);
521LLVMValueRef LLVMBuildFRem(LLVMBuilderRef, LLVMValueRef LHS, LLVMValueRef RHS,
522 const char *Name);
523LLVMValueRef LLVMBuildShl(LLVMBuilderRef, LLVMValueRef LHS, LLVMValueRef RHS,
524 const char *Name);
525LLVMValueRef LLVMBuildLShr(LLVMBuilderRef, LLVMValueRef LHS, LLVMValueRef RHS,
526 const char *Name);
527LLVMValueRef LLVMBuildAShr(LLVMBuilderRef, LLVMValueRef LHS, LLVMValueRef RHS,
528 const char *Name);
529LLVMValueRef LLVMBuildAnd(LLVMBuilderRef, LLVMValueRef LHS, LLVMValueRef RHS,
530 const char *Name);
531LLVMValueRef LLVMBuildOr(LLVMBuilderRef, LLVMValueRef LHS, LLVMValueRef RHS,
532 const char *Name);
533LLVMValueRef LLVMBuildXor(LLVMBuilderRef, LLVMValueRef LHS, LLVMValueRef RHS,
534 const char *Name);
535LLVMValueRef LLVMBuildNeg(LLVMBuilderRef, LLVMValueRef V, const char *Name);
536LLVMValueRef LLVMBuildNot(LLVMBuilderRef, LLVMValueRef V, const char *Name);
537
538/* Memory */
539LLVMValueRef LLVMBuildMalloc(LLVMBuilderRef, LLVMTypeRef Ty, const char *Name);
540LLVMValueRef LLVMBuildArrayMalloc(LLVMBuilderRef, LLVMTypeRef Ty,
541 LLVMValueRef Val, const char *Name);
542LLVMValueRef LLVMBuildAlloca(LLVMBuilderRef, LLVMTypeRef Ty, const char *Name);
543LLVMValueRef LLVMBuildArrayAlloca(LLVMBuilderRef, LLVMTypeRef Ty,
544 LLVMValueRef Val, const char *Name);
545LLVMValueRef LLVMBuildFree(LLVMBuilderRef, LLVMValueRef PointerVal);
546LLVMValueRef LLVMBuildLoad(LLVMBuilderRef, LLVMValueRef PointerVal,
547 const char *Name);
548LLVMValueRef LLVMBuildStore(LLVMBuilderRef, LLVMValueRef Val, LLVMValueRef Ptr);
549LLVMValueRef LLVMBuildGEP(LLVMBuilderRef B, LLVMValueRef Pointer,
550 LLVMValueRef *Indices, unsigned NumIndices,
551 const char *Name);
552
553/* Casts */
554LLVMValueRef LLVMBuildTrunc(LLVMBuilderRef, LLVMValueRef Val,
555 LLVMTypeRef DestTy, const char *Name);
556LLVMValueRef LLVMBuildZExt(LLVMBuilderRef, LLVMValueRef Val,
557 LLVMTypeRef DestTy, const char *Name);
558LLVMValueRef LLVMBuildSExt(LLVMBuilderRef, LLVMValueRef Val,
559 LLVMTypeRef DestTy, const char *Name);
560LLVMValueRef LLVMBuildFPToUI(LLVMBuilderRef, LLVMValueRef Val,
561 LLVMTypeRef DestTy, const char *Name);
562LLVMValueRef LLVMBuildFPToSI(LLVMBuilderRef, LLVMValueRef Val,
563 LLVMTypeRef DestTy, const char *Name);
564LLVMValueRef LLVMBuildUIToFP(LLVMBuilderRef, LLVMValueRef Val,
565 LLVMTypeRef DestTy, const char *Name);
566LLVMValueRef LLVMBuildSIToFP(LLVMBuilderRef, LLVMValueRef Val,
567 LLVMTypeRef DestTy, const char *Name);
568LLVMValueRef LLVMBuildFPTrunc(LLVMBuilderRef, LLVMValueRef Val,
569 LLVMTypeRef DestTy, const char *Name);
570LLVMValueRef LLVMBuildFPExt(LLVMBuilderRef, LLVMValueRef Val,
571 LLVMTypeRef DestTy, const char *Name);
572LLVMValueRef LLVMBuildPtrToInt(LLVMBuilderRef, LLVMValueRef Val,
573 LLVMTypeRef DestTy, const char *Name);
574LLVMValueRef LLVMBuildIntToPtr(LLVMBuilderRef, LLVMValueRef Val,
575 LLVMTypeRef DestTy, const char *Name);
576LLVMValueRef LLVMBuildBitCast(LLVMBuilderRef, LLVMValueRef Val,
577 LLVMTypeRef DestTy, const char *Name);
578
579/* Comparisons */
580LLVMValueRef LLVMBuildICmp(LLVMBuilderRef, LLVMIntPredicate Op,
581 LLVMValueRef LHS, LLVMValueRef RHS,
582 const char *Name);
583LLVMValueRef LLVMBuildFCmp(LLVMBuilderRef, LLVMRealPredicate Op,
584 LLVMValueRef LHS, LLVMValueRef RHS,
585 const char *Name);
586
587/* Miscellaneous instructions */
588LLVMValueRef LLVMBuildPhi(LLVMBuilderRef, LLVMTypeRef Ty, const char *Name);
589LLVMValueRef LLVMBuildCall(LLVMBuilderRef, LLVMValueRef Fn,
590 LLVMValueRef *Args, unsigned NumArgs,
591 const char *Name);
592LLVMValueRef LLVMBuildSelect(LLVMBuilderRef, LLVMValueRef If,
593 LLVMValueRef Then, LLVMValueRef Else,
594 const char *Name);
595LLVMValueRef LLVMBuildVAArg(LLVMBuilderRef, LLVMValueRef List, LLVMTypeRef Ty,
596 const char *Name);
597LLVMValueRef LLVMBuildExtractElement(LLVMBuilderRef, LLVMValueRef VecVal,
598 LLVMValueRef Index, const char *Name);
599LLVMValueRef LLVMBuildInsertElement(LLVMBuilderRef, LLVMValueRef VecVal,
600 LLVMValueRef EltVal, LLVMValueRef Index,
601 const char *Name);
602LLVMValueRef LLVMBuildShuffleVector(LLVMBuilderRef, LLVMValueRef V1,
603 LLVMValueRef V2, LLVMValueRef Mask,
604 const char *Name);
Gordon Henriksen8b94a142007-09-18 03:18:57 +0000605
Gordon Henriksenda1435f2007-12-19 22:30:40 +0000606
Gordon Henriksen1ae61352007-12-12 01:04:30 +0000607/*===-- Module providers --------------------------------------------------===*/
608
609/* Encapsulates the module M in a module provider, taking ownership of the
610 * module.
611 * See the constructor llvm::ExistingModuleProvider::ExistingModuleProvider.
612 */
613LLVMModuleProviderRef
614LLVMCreateModuleProviderForExistingModule(LLVMModuleRef M);
615
616/* Destroys the module provider MP as well as the contained module.
617 * See the destructor llvm::ModuleProvider::~ModuleProvider.
618 */
619void LLVMDisposeModuleProvider(LLVMModuleProviderRef MP);
620
Gordon Henriksenda1435f2007-12-19 22:30:40 +0000621
622/*===-- Memory buffers ----------------------------------------------------===*/
623
624int LLVMCreateMemoryBufferWithContentsOfFile(const char *Path,
625 LLVMMemoryBufferRef *OutMemBuf,
626 char **OutMessage);
627int LLVMCreateMemoryBufferWithSTDIN(LLVMMemoryBufferRef *OutMemBuf,
628 char **OutMessage);
629void LLVMDisposeMemoryBuffer(LLVMMemoryBufferRef MemBuf);
630
Gordon Henriksend78c0f52008-03-16 04:20:44 +0000631
632/*===-- Pass Managers -----------------------------------------------------===*/
633
634/** Constructs a new whole-module pass pipeline. This type of pipeline is
635 suitable for link-time optimization and whole-module transformations.
636 See llvm::PassManager::PassManager. */
Gordon Henriksen16c1f442008-05-04 12:55:34 +0000637LLVMPassManagerRef LLVMCreatePassManager(void);
Gordon Henriksend78c0f52008-03-16 04:20:44 +0000638
639/** Constructs a new function-by-function pass pipeline over the module
640 provider. It does not take ownership of the module provider. This type of
641 pipeline is suitable for code generation and JIT compilation tasks.
642 See llvm::FunctionPassManager::FunctionPassManager. */
643LLVMPassManagerRef LLVMCreateFunctionPassManager(LLVMModuleProviderRef MP);
644
645/** Initializes, executes on the provided module, and finalizes all of the
646 passes scheduled in the pass manager. Returns 1 if any of the passes
647 modified the module, 0 otherwise. See llvm::PassManager::run(Module&). */
648int LLVMRunPassManager(LLVMPassManagerRef PM, LLVMModuleRef M);
649
650/** Initializes all of the function passes scheduled in the function pass
651 manager. Returns 1 if any of the passes modified the module, 0 otherwise.
652 See llvm::FunctionPassManager::doInitialization. */
653int LLVMInitializeFunctionPassManager(LLVMPassManagerRef FPM);
654
655/** Executes all of the function passes scheduled in the function pass manager
656 on the provided function. Returns 1 if any of the passes modified the
657 function, false otherwise.
658 See llvm::FunctionPassManager::run(Function&). */
659int LLVMRunFunctionPassManager(LLVMPassManagerRef FPM, LLVMValueRef F);
660
661/** Finalizes all of the function passes scheduled in in the function pass
662 manager. Returns 1 if any of the passes modified the module, 0 otherwise.
663 See llvm::FunctionPassManager::doFinalization. */
664int LLVMFinalizeFunctionPassManager(LLVMPassManagerRef FPM);
665
666/** Frees the memory of a pass pipeline. For function pipelines, does not free
667 the module provider.
668 See llvm::PassManagerBase::~PassManagerBase. */
669void LLVMDisposePassManager(LLVMPassManagerRef PM);
670
671
Gordon Henriksen8b94a142007-09-18 03:18:57 +0000672#ifdef __cplusplus
673}
Gordon Henriksen8b94a142007-09-18 03:18:57 +0000674
Gordon Henriksenacd96192007-10-05 23:59:36 +0000675namespace llvm {
Gordon Henriksen1ae61352007-12-12 01:04:30 +0000676 class ModuleProvider;
Gordon Henriksenda1435f2007-12-19 22:30:40 +0000677 class MemoryBuffer;
Gordon Henriksen395b4142008-03-16 15:55:43 +0000678 class PassManagerBase;
Gordon Henriksen1ae61352007-12-12 01:04:30 +0000679
Gordon Henriksenda1435f2007-12-19 22:30:40 +0000680 #define DEFINE_SIMPLE_CONVERSION_FUNCTIONS(ty, ref) \
681 inline ty *unwrap(ref P) { \
682 return reinterpret_cast<ty*>(P); \
683 } \
684 \
685 inline ref wrap(const ty *P) { \
686 return reinterpret_cast<ref>(const_cast<ty*>(P)); \
687 }
Gordon Henriksenacd96192007-10-05 23:59:36 +0000688
Gordon Henriksend78c0f52008-03-16 04:20:44 +0000689 #define DEFINE_ISA_CONVERSION_FUNCTIONS(ty, ref) \
690 DEFINE_SIMPLE_CONVERSION_FUNCTIONS(ty, ref) \
691 \
692 template<typename T> \
693 inline T *unwrap(ref P) { \
694 return cast<T>(unwrap(P)); \
695 }
696
697 #define DEFINE_STDCXX_CONVERSION_FUNCTIONS(ty, ref) \
698 DEFINE_SIMPLE_CONVERSION_FUNCTIONS(ty, ref) \
699 \
700 template<typename T> \
701 inline T *unwrap(ref P) { \
702 T *Q = dynamic_cast<T*>(unwrap(P)); \
703 assert(Q && "Invalid cast!"); \
704 return Q; \
705 }
706
707 DEFINE_ISA_CONVERSION_FUNCTIONS (Type, LLVMTypeRef )
708 DEFINE_ISA_CONVERSION_FUNCTIONS (Value, LLVMValueRef )
Gordon Henriksen1d2e49c2007-12-27 18:25:59 +0000709 DEFINE_SIMPLE_CONVERSION_FUNCTIONS(Module, LLVMModuleRef )
710 DEFINE_SIMPLE_CONVERSION_FUNCTIONS(BasicBlock, LLVMBasicBlockRef )
Duncan Sands89f6d882008-04-13 06:22:09 +0000711 DEFINE_SIMPLE_CONVERSION_FUNCTIONS(IRBuilder, LLVMBuilderRef )
Gordon Henriksen1d2e49c2007-12-27 18:25:59 +0000712 DEFINE_SIMPLE_CONVERSION_FUNCTIONS(PATypeHolder, LLVMTypeHandleRef )
713 DEFINE_SIMPLE_CONVERSION_FUNCTIONS(ModuleProvider, LLVMModuleProviderRef)
714 DEFINE_SIMPLE_CONVERSION_FUNCTIONS(MemoryBuffer, LLVMMemoryBufferRef )
Gordon Henriksend78c0f52008-03-16 04:20:44 +0000715 DEFINE_STDCXX_CONVERSION_FUNCTIONS(PassManagerBase, LLVMPassManagerRef )
Gordon Henriksenacd96192007-10-05 23:59:36 +0000716
Gordon Henriksend78c0f52008-03-16 04:20:44 +0000717 #undef DEFINE_STDCXX_CONVERSION_FUNCTIONS
718 #undef DEFINE_ISA_CONVERSION_FUNCTIONS
Gordon Henriksenda1435f2007-12-19 22:30:40 +0000719 #undef DEFINE_SIMPLE_CONVERSION_FUNCTIONS
Gordon Henriksenacd96192007-10-05 23:59:36 +0000720
Gordon Henriksenda1435f2007-12-19 22:30:40 +0000721 /* Specialized opaque type conversions.
722 */
Gordon Henriksenacd96192007-10-05 23:59:36 +0000723 inline Type **unwrap(LLVMTypeRef* Tys) {
724 return reinterpret_cast<Type**>(Tys);
725 }
726
Gordon Henriksenacd96192007-10-05 23:59:36 +0000727 inline LLVMTypeRef *wrap(const Type **Tys) {
728 return reinterpret_cast<LLVMTypeRef*>(const_cast<Type**>(Tys));
729 }
730
Gordon Henriksenda1435f2007-12-19 22:30:40 +0000731 /* Specialized opaque value conversions.
Gordon Henriksenacd96192007-10-05 23:59:36 +0000732 */
Gordon Henriksenacd96192007-10-05 23:59:36 +0000733 inline Value **unwrap(LLVMValueRef *Vals) {
734 return reinterpret_cast<Value**>(Vals);
735 }
736
737 template<typename T>
738 inline T **unwrap(LLVMValueRef *Vals, unsigned Length) {
739 #if DEBUG
740 for (LLVMValueRef *I = Vals, E = Vals + Length; I != E; ++I)
741 cast<T>(*I);
742 #endif
743 return reinterpret_cast<T**>(Vals);
744 }
745
Gordon Henriksenacd96192007-10-05 23:59:36 +0000746 inline LLVMValueRef *wrap(const Value **Vals) {
747 return reinterpret_cast<LLVMValueRef*>(const_cast<Value**>(Vals));
748 }
Gordon Henriksenacd96192007-10-05 23:59:36 +0000749}
750
751#endif /* !defined(__cplusplus) */
752
753#endif /* !defined(LLVM_C_CORE_H) */