blob: d1251dc74fc1aa6183fb53dc94525b6f4e99bf0c [file] [log] [blame]
Gordon Henriksen76a03742007-09-18 03:18:57 +00001/*===-- llvm-c/Core.h - Core Library C Interface ------------------*- C -*-===*\
2|* *|
3|* The LLVM Compiler Infrastructure *|
4|* *|
Chris Lattnere9cc7422007-12-29 19:59:42 +00005|* This file is distributed under the University of Illinois Open Source *|
6|* License. See LICENSE.TXT for details. *|
Gordon Henriksen76a03742007-09-18 03:18:57 +00007|* *|
8|*===----------------------------------------------------------------------===*|
9|* *|
10|* This header declares the C interface to libLLVMCore.a, which implements *|
11|* the LLVM intermediate representation. *|
12|* *|
13|* LLVM uses a polymorphic type hierarchy which C cannot represent, therefore *|
14|* parameters must be passed as base types. Despite the declared types, most *|
15|* of the functions provided operate only on branches of the type hierarchy. *|
16|* The declared parameter names are descriptive and specify which type is *|
17|* required. Additionally, each type hierarchy is documented along with the *|
18|* functions that operate upon it. For more detail, refer to LLVM's C++ code. *|
19|* If in doubt, refer to Core.cpp, which performs paramter downcasts in the *|
20|* form unwrap<RequiredType>(Param). *|
21|* *|
22|* Many exotic languages can interoperate with C code but have a harder time *|
23|* with C++ due to name mangling. So in addition to C, this interface enables *|
24|* tools written in such languages. *|
25|* *|
Gordon Henriksen7330acd2007-10-05 23:59:36 +000026|* When included into a C++ source file, also declares 'wrap' and 'unwrap' *|
27|* helpers to perform opaque reference<-->pointer conversions. These helpers *|
28|* are shorter and more tightly typed than writing the casts by hand when *|
29|* authoring bindings. In assert builds, they will do runtime type checking. *|
30|* *|
Gordon Henriksen76a03742007-09-18 03:18:57 +000031\*===----------------------------------------------------------------------===*/
32
33#ifndef LLVM_C_CORE_H
34#define LLVM_C_CORE_H
35
36#ifdef __cplusplus
Gordon Henriksen7330acd2007-10-05 23:59:36 +000037
38/* Need these includes to support the LLVM 'cast' template for the C++ 'wrap'
39 and 'unwrap' conversion functions. */
40#include "llvm/Module.h"
Duncan Sandsa07136e2008-04-13 06:22:09 +000041#include "llvm/Support/IRBuilder.h"
Gordon Henriksen7330acd2007-10-05 23:59:36 +000042
Gordon Henriksen76a03742007-09-18 03:18:57 +000043extern "C" {
44#endif
45
46
47/* Opaque types. */
Gordon Henriksen4a4d7352007-12-30 17:46:33 +000048
49/**
50 * The top-level container for all other LLVM Intermediate Representation (IR)
51 * objects. See the llvm::Module class.
52 */
Gordon Henriksen76a03742007-09-18 03:18:57 +000053typedef struct LLVMOpaqueModule *LLVMModuleRef;
Gordon Henriksen4a4d7352007-12-30 17:46:33 +000054
55/**
Gordon Henriksena49d4352008-03-07 19:13:06 +000056 * Each value in the LLVM IR has a type, an LLVMTypeRef. See the llvm::Type
57 * class.
Gordon Henriksen4a4d7352007-12-30 17:46:33 +000058 */
Gordon Henriksen76a03742007-09-18 03:18:57 +000059typedef struct LLVMOpaqueType *LLVMTypeRef;
Gordon Henriksen4a4d7352007-12-30 17:46:33 +000060
61/**
Gordon Henriksena49d4352008-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 Henriksen4a4d7352007-12-30 17:46:33 +000065 */
Gordon Henriksenffb48762007-10-07 00:13:35 +000066typedef struct LLVMOpaqueTypeHandle *LLVMTypeHandleRef;
Gordon Henriksen4a4d7352007-12-30 17:46:33 +000067
Gordon Henriksen76a03742007-09-18 03:18:57 +000068typedef struct LLVMOpaqueValue *LLVMValueRef;
Gordon Henriksenc23b66c2007-09-26 20:56:12 +000069typedef struct LLVMOpaqueBasicBlock *LLVMBasicBlockRef;
70typedef struct LLVMOpaqueBuilder *LLVMBuilderRef;
Gordon Henriksen34eb6d82007-12-19 22:30:40 +000071
72/* Used to provide a module to JIT or interpreter.
73 * See the llvm::ModuleProvider class.
74 */
Gordon Henriksen0a68fe22007-12-12 01:04:30 +000075typedef struct LLVMOpaqueModuleProvider *LLVMModuleProviderRef;
Gordon Henriksen76a03742007-09-18 03:18:57 +000076
Gordon Henriksen34eb6d82007-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 Henriksen878114b2008-03-16 04:20:44 +000082/** See the llvm::PassManagerBase class. */
83typedef struct LLVMOpaquePassManager *LLVMPassManagerRef;
84
Gordon Henriksen76a03742007-09-18 03:18:57 +000085typedef enum {
Gordon Henriksen2d9cc212008-04-28 17:37:06 +000086 LLVMZExtParamAttr = 1<<0,
87 LLVMSExtParamAttr = 1<<1,
88 LLVMNoReturnParamAttr = 1<<2,
89 LLVMNoUnwindParamAttr = 1<<3,
90 LLVMInRegParamAttr = 1<<4,
91 LLVMNoAliasParamAttr = 1<<5,
92 LLVMStructRetParamAttr = 1<<6,
93 LLVMByValParamAttr = 1<<7,
94 LLVMNestParamAttr = 1<<8,
95 LLVMReadNoneParamAttr = 1<<9,
96 LLVMReadOnlyParamAttr = 1<<10
97} LLVMParamAttr;
98
99typedef enum {
Gordon Henriksen4a4d7352007-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 Henriksen76a03742007-09-18 03:18:57 +0000114} LLVMTypeKind;
115
116typedef enum {
Gordon Henriksen4a4d7352007-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 Henriksen76a03742007-09-18 03:18:57 +0000128} LLVMLinkage;
129
130typedef enum {
Gordon Henriksen4a4d7352007-12-30 17:46:33 +0000131 LLVMDefaultVisibility, /**< The GV is visible */
132 LLVMHiddenVisibility, /**< The GV is hidden */
133 LLVMProtectedVisibility /**< The GV is protected */
Gordon Henriksen76a03742007-09-18 03:18:57 +0000134} LLVMVisibility;
135
Gordon Henriksenc23b66c2007-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 Henriksen4a4d7352007-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 Henriksenc23b66c2007-09-26 20:56:12 +0000155} LLVMIntPredicate;
156
157typedef enum {
Gordon Henriksen4a4d7352007-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 Henriksenc23b66c2007-09-26 20:56:12 +0000174} LLVMRealPredicate;
175
Gordon Henriksen76a03742007-09-18 03:18:57 +0000176
Gordon Henriksen34eb6d82007-12-19 22:30:40 +0000177/*===-- Error handling ----------------------------------------------------===*/
178
179void LLVMDisposeMessage(char *Message);
180
181
Gordon Henriksen76a03742007-09-18 03:18:57 +0000182/*===-- Modules -----------------------------------------------------------===*/
183
184/* Create and destroy modules. */
Gordon Henriksena49d4352008-03-07 19:13:06 +0000185/** See llvm::Module::Module. */
Gordon Henriksen76a03742007-09-18 03:18:57 +0000186LLVMModuleRef LLVMModuleCreateWithName(const char *ModuleID);
Gordon Henriksena49d4352008-03-07 19:13:06 +0000187
188/** See llvm::Module::~Module. */
Gordon Henriksen76a03742007-09-18 03:18:57 +0000189void LLVMDisposeModule(LLVMModuleRef M);
190
Gordon Henriksena49d4352008-03-07 19:13:06 +0000191/** Data layout. See Module::getDataLayout. */
Gordon Henriksen05568bb2007-12-27 20:13:47 +0000192const char *LLVMGetDataLayout(LLVMModuleRef M);
193void LLVMSetDataLayout(LLVMModuleRef M, const char *Triple);
194
Gordon Henriksena49d4352008-03-07 19:13:06 +0000195/** Target triple. See Module::getTargetTriple. */
Gordon Henriksen05568bb2007-12-27 20:13:47 +0000196const char *LLVMGetTarget(LLVMModuleRef M);
197void LLVMSetTarget(LLVMModuleRef M, const char *Triple);
198
Gordon Henriksena49d4352008-03-07 19:13:06 +0000199/** See Module::addTypeName. */
Gordon Henriksen76a03742007-09-18 03:18:57 +0000200int LLVMAddTypeName(LLVMModuleRef M, const char *Name, LLVMTypeRef Ty);
Gordon Henriksenc23b66c2007-09-26 20:56:12 +0000201void LLVMDeleteTypeName(LLVMModuleRef M, const char *Name);
Gordon Henriksen76a03742007-09-18 03:18:57 +0000202
Gordon Henriksen6c6075e2008-03-14 23:58:56 +0000203/** See Module::dump. */
204void LLVMDumpModule(LLVMModuleRef M);
205
Gordon Henriksen76a03742007-09-18 03:18:57 +0000206
Gordon Henriksenc23b66c2007-09-26 20:56:12 +0000207/*===-- Types -------------------------------------------------------------===*/
Gordon Henriksen76a03742007-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 Henriksena49d4352008-03-07 19:13:06 +0000224/** See llvm::LLVMTypeKind::getTypeID. */
Gordon Henriksen76a03742007-09-18 03:18:57 +0000225LLVMTypeKind LLVMGetTypeKind(LLVMTypeRef Ty);
Gordon Henriksena49d4352008-03-07 19:13:06 +0000226
227/** See llvm::DerivedType::refineAbstractTypeTo. */
Gordon Henriksen76a03742007-09-18 03:18:57 +0000228void LLVMRefineAbstractType(LLVMTypeRef AbstractType, LLVMTypeRef ConcreteType);
229
230/* Operations on integer types */
231LLVMTypeRef LLVMInt1Type();
232LLVMTypeRef LLVMInt8Type();
233LLVMTypeRef LLVMInt16Type();
234LLVMTypeRef LLVMInt32Type();
235LLVMTypeRef LLVMInt64Type();
Gordon Henriksened7beaa2007-10-06 16:05:20 +0000236LLVMTypeRef LLVMIntType(unsigned NumBits);
Gordon Henriksenc23b66c2007-09-26 20:56:12 +0000237unsigned LLVMGetIntTypeWidth(LLVMTypeRef IntegerTy);
Gordon Henriksen76a03742007-09-18 03:18:57 +0000238
239/* Operations on real types */
240LLVMTypeRef LLVMFloatType();
241LLVMTypeRef LLVMDoubleType();
242LLVMTypeRef LLVMX86FP80Type();
243LLVMTypeRef LLVMFP128Type();
244LLVMTypeRef LLVMPPCFP128Type();
245
246/* Operations on function types */
Gordon Henriksened7beaa2007-10-06 16:05:20 +0000247LLVMTypeRef LLVMFunctionType(LLVMTypeRef ReturnType,
248 LLVMTypeRef *ParamTypes, unsigned ParamCount,
249 int IsVarArg);
Gordon Henriksen76a03742007-09-18 03:18:57 +0000250int LLVMIsFunctionVarArg(LLVMTypeRef FunctionTy);
Gordon Henriksenc23b66c2007-09-26 20:56:12 +0000251LLVMTypeRef LLVMGetReturnType(LLVMTypeRef FunctionTy);
252unsigned LLVMCountParamTypes(LLVMTypeRef FunctionTy);
253void LLVMGetParamTypes(LLVMTypeRef FunctionTy, LLVMTypeRef *Dest);
Gordon Henriksen76a03742007-09-18 03:18:57 +0000254
255/* Operations on struct types */
Gordon Henriksened7beaa2007-10-06 16:05:20 +0000256LLVMTypeRef LLVMStructType(LLVMTypeRef *ElementTypes, unsigned ElementCount,
257 int Packed);
Gordon Henriksenc23b66c2007-09-26 20:56:12 +0000258unsigned LLVMCountStructElementTypes(LLVMTypeRef StructTy);
Gordon Henriksen76a03742007-09-18 03:18:57 +0000259void LLVMGetStructElementTypes(LLVMTypeRef StructTy, LLVMTypeRef *Dest);
260int LLVMIsPackedStruct(LLVMTypeRef StructTy);
261
262/* Operations on array, pointer, and vector types (sequence types) */
Gordon Henriksened7beaa2007-10-06 16:05:20 +0000263LLVMTypeRef LLVMArrayType(LLVMTypeRef ElementType, unsigned ElementCount);
Gordon Henriksen5a3fe032007-12-17 16:08:32 +0000264LLVMTypeRef LLVMPointerType(LLVMTypeRef ElementType, unsigned AddressSpace);
Gordon Henriksened7beaa2007-10-06 16:05:20 +0000265LLVMTypeRef LLVMVectorType(LLVMTypeRef ElementType, unsigned ElementCount);
Gordon Henriksen76a03742007-09-18 03:18:57 +0000266
267LLVMTypeRef LLVMGetElementType(LLVMTypeRef Ty);
268unsigned LLVMGetArrayLength(LLVMTypeRef ArrayTy);
Gordon Henriksen5a3fe032007-12-17 16:08:32 +0000269unsigned LLVMGetPointerAddressSpace(LLVMTypeRef PointerTy);
Gordon Henriksen76a03742007-09-18 03:18:57 +0000270unsigned LLVMGetVectorSize(LLVMTypeRef VectorTy);
271
272/* Operations on other types */
273LLVMTypeRef LLVMVoidType();
274LLVMTypeRef LLVMLabelType();
Gordon Henriksened7beaa2007-10-06 16:05:20 +0000275LLVMTypeRef LLVMOpaqueType();
Gordon Henriksen76a03742007-09-18 03:18:57 +0000276
Gordon Henriksenffb48762007-10-07 00:13:35 +0000277/* Operations on type handles */
278LLVMTypeHandleRef LLVMCreateTypeHandle(LLVMTypeRef PotentiallyAbstractTy);
279void LLVMRefineType(LLVMTypeRef AbstractTy, LLVMTypeRef ConcreteTy);
280LLVMTypeRef LLVMResolveTypeHandle(LLVMTypeHandleRef TypeHandle);
281void LLVMDisposeTypeHandle(LLVMTypeHandleRef TypeHandle);
282
Gordon Henriksen76a03742007-09-18 03:18:57 +0000283
284/*===-- Values ------------------------------------------------------------===*/
285
286/* The bulk of LLVM's object model consists of values, which comprise a very
287 * rich type hierarchy.
288 *
289 * values:
290 * constants:
291 * scalar constants
292 * composite contants
293 * globals:
294 * global variable
295 * function
296 * alias
Gordon Henriksenc23b66c2007-09-26 20:56:12 +0000297 * basic blocks
Gordon Henriksen76a03742007-09-18 03:18:57 +0000298 */
299
300/* Operations on all values */
Gordon Henriksenc23b66c2007-09-26 20:56:12 +0000301LLVMTypeRef LLVMTypeOf(LLVMValueRef Val);
Gordon Henriksen76a03742007-09-18 03:18:57 +0000302const char *LLVMGetValueName(LLVMValueRef Val);
303void LLVMSetValueName(LLVMValueRef Val, const char *Name);
Gordon Henriksen1d0d24c2007-10-06 00:08:49 +0000304void LLVMDumpValue(LLVMValueRef Val);
Gordon Henriksen76a03742007-09-18 03:18:57 +0000305
306/* Operations on constants of any type */
Gordon Henriksen1046c732007-10-06 15:11:06 +0000307LLVMValueRef LLVMConstNull(LLVMTypeRef Ty); /* all zeroes */
308LLVMValueRef LLVMConstAllOnes(LLVMTypeRef Ty); /* only for int/vector */
Gordon Henriksen76a03742007-09-18 03:18:57 +0000309LLVMValueRef LLVMGetUndef(LLVMTypeRef Ty);
Gordon Henriksendc88c062007-09-18 18:07:51 +0000310int LLVMIsConstant(LLVMValueRef Val);
Gordon Henriksen76a03742007-09-18 03:18:57 +0000311int LLVMIsNull(LLVMValueRef Val);
Gordon Henriksendc88c062007-09-18 18:07:51 +0000312int LLVMIsUndef(LLVMValueRef Val);
Gordon Henriksen76a03742007-09-18 03:18:57 +0000313
314/* Operations on scalar constants */
Gordon Henriksen1046c732007-10-06 15:11:06 +0000315LLVMValueRef LLVMConstInt(LLVMTypeRef IntTy, unsigned long long N,
316 int SignExtend);
317LLVMValueRef LLVMConstReal(LLVMTypeRef RealTy, double N);
Gordon Henriksen931e1212008-02-02 01:07:50 +0000318LLVMValueRef LLVMConstRealOfString(LLVMTypeRef RealTy, const char *Text);
Gordon Henriksen76a03742007-09-18 03:18:57 +0000319
320/* Operations on composite constants */
Gordon Henriksen1046c732007-10-06 15:11:06 +0000321LLVMValueRef LLVMConstString(const char *Str, unsigned Length,
322 int DontNullTerminate);
Gordon Henriksen2ad5aef2008-04-25 03:21:19 +0000323LLVMValueRef LLVMConstArray(LLVMTypeRef ElementTy,
Gordon Henriksen1046c732007-10-06 15:11:06 +0000324 LLVMValueRef *ConstantVals, unsigned Length);
325LLVMValueRef LLVMConstStruct(LLVMValueRef *ConstantVals, unsigned Count,
326 int packed);
327LLVMValueRef LLVMConstVector(LLVMValueRef *ScalarConstantVals, unsigned Size);
Gordon Henriksen76a03742007-09-18 03:18:57 +0000328
Gordon Henriksen7ce31762007-10-06 14:29:36 +0000329/* Constant expressions */
330LLVMValueRef LLVMSizeOf(LLVMTypeRef Ty);
331LLVMValueRef LLVMConstNeg(LLVMValueRef ConstantVal);
332LLVMValueRef LLVMConstNot(LLVMValueRef ConstantVal);
333LLVMValueRef LLVMConstAdd(LLVMValueRef LHSConstant, LLVMValueRef RHSConstant);
334LLVMValueRef LLVMConstSub(LLVMValueRef LHSConstant, LLVMValueRef RHSConstant);
335LLVMValueRef LLVMConstMul(LLVMValueRef LHSConstant, LLVMValueRef RHSConstant);
336LLVMValueRef LLVMConstUDiv(LLVMValueRef LHSConstant, LLVMValueRef RHSConstant);
337LLVMValueRef LLVMConstSDiv(LLVMValueRef LHSConstant, LLVMValueRef RHSConstant);
338LLVMValueRef LLVMConstFDiv(LLVMValueRef LHSConstant, LLVMValueRef RHSConstant);
339LLVMValueRef LLVMConstURem(LLVMValueRef LHSConstant, LLVMValueRef RHSConstant);
340LLVMValueRef LLVMConstSRem(LLVMValueRef LHSConstant, LLVMValueRef RHSConstant);
341LLVMValueRef LLVMConstFRem(LLVMValueRef LHSConstant, LLVMValueRef RHSConstant);
342LLVMValueRef LLVMConstAnd(LLVMValueRef LHSConstant, LLVMValueRef RHSConstant);
343LLVMValueRef LLVMConstOr(LLVMValueRef LHSConstant, LLVMValueRef RHSConstant);
344LLVMValueRef LLVMConstXor(LLVMValueRef LHSConstant, LLVMValueRef RHSConstant);
345LLVMValueRef LLVMConstICmp(LLVMIntPredicate Predicate,
346 LLVMValueRef LHSConstant, LLVMValueRef RHSConstant);
347LLVMValueRef LLVMConstFCmp(LLVMRealPredicate Predicate,
348 LLVMValueRef LHSConstant, LLVMValueRef RHSConstant);
349LLVMValueRef LLVMConstShl(LLVMValueRef LHSConstant, LLVMValueRef RHSConstant);
350LLVMValueRef LLVMConstLShr(LLVMValueRef LHSConstant, LLVMValueRef RHSConstant);
351LLVMValueRef LLVMConstAShr(LLVMValueRef LHSConstant, LLVMValueRef RHSConstant);
352LLVMValueRef LLVMConstGEP(LLVMValueRef ConstantVal,
353 LLVMValueRef *ConstantIndices, unsigned NumIndices);
354LLVMValueRef LLVMConstTrunc(LLVMValueRef ConstantVal, LLVMTypeRef ToType);
355LLVMValueRef LLVMConstSExt(LLVMValueRef ConstantVal, LLVMTypeRef ToType);
356LLVMValueRef LLVMConstZExt(LLVMValueRef ConstantVal, LLVMTypeRef ToType);
357LLVMValueRef LLVMConstFPTrunc(LLVMValueRef ConstantVal, LLVMTypeRef ToType);
358LLVMValueRef LLVMConstFPExt(LLVMValueRef ConstantVal, LLVMTypeRef ToType);
359LLVMValueRef LLVMConstUIToFP(LLVMValueRef ConstantVal, LLVMTypeRef ToType);
360LLVMValueRef LLVMConstSIToFP(LLVMValueRef ConstantVal, LLVMTypeRef ToType);
361LLVMValueRef LLVMConstFPToUI(LLVMValueRef ConstantVal, LLVMTypeRef ToType);
362LLVMValueRef LLVMConstFPToSI(LLVMValueRef ConstantVal, LLVMTypeRef ToType);
363LLVMValueRef LLVMConstPtrToInt(LLVMValueRef ConstantVal, LLVMTypeRef ToType);
364LLVMValueRef LLVMConstIntToPtr(LLVMValueRef ConstantVal, LLVMTypeRef ToType);
365LLVMValueRef LLVMConstBitCast(LLVMValueRef ConstantVal, LLVMTypeRef ToType);
366LLVMValueRef LLVMConstSelect(LLVMValueRef ConstantCondition,
367 LLVMValueRef ConstantIfTrue,
368 LLVMValueRef ConstantIfFalse);
369LLVMValueRef LLVMConstExtractElement(LLVMValueRef VectorConstant,
370 LLVMValueRef IndexConstant);
371LLVMValueRef LLVMConstInsertElement(LLVMValueRef VectorConstant,
372 LLVMValueRef ElementValueConstant,
373 LLVMValueRef IndexConstant);
374LLVMValueRef LLVMConstShuffleVector(LLVMValueRef VectorAConstant,
375 LLVMValueRef VectorBConstant,
376 LLVMValueRef MaskConstant);
377
Gordon Henriksen76a03742007-09-18 03:18:57 +0000378/* Operations on global variables, functions, and aliases (globals) */
Gordon Henriksen265f7802008-03-19 01:11:35 +0000379LLVMModuleRef LLVMGetGlobalParent(LLVMValueRef Global);
Gordon Henriksen76a03742007-09-18 03:18:57 +0000380int LLVMIsDeclaration(LLVMValueRef Global);
381LLVMLinkage LLVMGetLinkage(LLVMValueRef Global);
382void LLVMSetLinkage(LLVMValueRef Global, LLVMLinkage Linkage);
383const char *LLVMGetSection(LLVMValueRef Global);
384void LLVMSetSection(LLVMValueRef Global, const char *Section);
385LLVMVisibility LLVMGetVisibility(LLVMValueRef Global);
386void LLVMSetVisibility(LLVMValueRef Global, LLVMVisibility Viz);
387unsigned LLVMGetAlignment(LLVMValueRef Global);
388void LLVMSetAlignment(LLVMValueRef Global, unsigned Bytes);
389
390/* Operations on global variables */
391LLVMValueRef LLVMAddGlobal(LLVMModuleRef M, LLVMTypeRef Ty, const char *Name);
Gordon Henriksen783f7bb2007-10-08 03:45:09 +0000392LLVMValueRef LLVMGetNamedGlobal(LLVMModuleRef M, const char *Name);
Gordon Henriksen07a45f42008-03-23 22:21:29 +0000393LLVMValueRef LLVMGetFirstGlobal(LLVMModuleRef M);
394LLVMValueRef LLVMGetLastGlobal(LLVMModuleRef M);
395LLVMValueRef LLVMGetNextGlobal(LLVMValueRef GlobalVar);
396LLVMValueRef LLVMGetPreviousGlobal(LLVMValueRef GlobalVar);
Gordon Henriksen76a03742007-09-18 03:18:57 +0000397void LLVMDeleteGlobal(LLVMValueRef GlobalVar);
398int LLVMHasInitializer(LLVMValueRef GlobalVar);
399LLVMValueRef LLVMGetInitializer(LLVMValueRef GlobalVar);
400void LLVMSetInitializer(LLVMValueRef GlobalVar, LLVMValueRef ConstantVal);
401int LLVMIsThreadLocal(LLVMValueRef GlobalVar);
402void LLVMSetThreadLocal(LLVMValueRef GlobalVar, int IsThreadLocal);
Gordon Henriksen751ebf72007-10-07 17:31:42 +0000403int LLVMIsGlobalConstant(LLVMValueRef GlobalVar);
404void LLVMSetGlobalConstant(LLVMValueRef GlobalVar, int IsConstant);
Gordon Henriksen76a03742007-09-18 03:18:57 +0000405
Gordon Henriksenc23b66c2007-09-26 20:56:12 +0000406/* Operations on functions */
407LLVMValueRef LLVMAddFunction(LLVMModuleRef M, const char *Name,
408 LLVMTypeRef FunctionTy);
Gordon Henriksen783f7bb2007-10-08 03:45:09 +0000409LLVMValueRef LLVMGetNamedFunction(LLVMModuleRef M, const char *Name);
Gordon Henriksen054817c2008-03-19 03:47:18 +0000410LLVMValueRef LLVMGetFirstFunction(LLVMModuleRef M);
411LLVMValueRef LLVMGetLastFunction(LLVMModuleRef M);
412LLVMValueRef LLVMGetNextFunction(LLVMValueRef Fn);
413LLVMValueRef LLVMGetPreviousFunction(LLVMValueRef Fn);
Gordon Henriksenc23b66c2007-09-26 20:56:12 +0000414void LLVMDeleteFunction(LLVMValueRef Fn);
Gordon Henriksenc23b66c2007-09-26 20:56:12 +0000415unsigned LLVMGetIntrinsicID(LLVMValueRef Fn);
416unsigned LLVMGetFunctionCallConv(LLVMValueRef Fn);
417void LLVMSetFunctionCallConv(LLVMValueRef Fn, unsigned CC);
Gordon Henriksen71183b62007-12-10 03:18:06 +0000418const char *LLVMGetCollector(LLVMValueRef Fn);
419void LLVMSetCollector(LLVMValueRef Fn, const char *Coll);
Gordon Henriksenc23b66c2007-09-26 20:56:12 +0000420
Gordon Henriksen265f7802008-03-19 01:11:35 +0000421/* Operations on parameters */
422unsigned LLVMCountParams(LLVMValueRef Fn);
423void LLVMGetParams(LLVMValueRef Fn, LLVMValueRef *Params);
424LLVMValueRef LLVMGetParam(LLVMValueRef Fn, unsigned Index);
425LLVMValueRef LLVMGetParamParent(LLVMValueRef Inst);
Gordon Henriksen07a45f42008-03-23 22:21:29 +0000426LLVMValueRef LLVMGetFirstParam(LLVMValueRef Fn);
427LLVMValueRef LLVMGetLastParam(LLVMValueRef Fn);
428LLVMValueRef LLVMGetNextParam(LLVMValueRef Arg);
429LLVMValueRef LLVMGetPreviousParam(LLVMValueRef Arg);
Gordon Henriksen2d9cc212008-04-28 17:37:06 +0000430void LLVMAddParamAttr(LLVMValueRef Arg, LLVMParamAttr PA);
431void LLVMRemoveParamAttr(LLVMValueRef Arg, LLVMParamAttr PA);
432void LLVMSetParamAlignment(LLVMValueRef Arg, unsigned align);
Gordon Henriksen265f7802008-03-19 01:11:35 +0000433
Gordon Henriksenc23b66c2007-09-26 20:56:12 +0000434/* Operations on basic blocks */
Gordon Henriksen07a45f42008-03-23 22:21:29 +0000435LLVMValueRef LLVMBasicBlockAsValue(LLVMBasicBlockRef BB);
Gordon Henriksenc23b66c2007-09-26 20:56:12 +0000436int LLVMValueIsBasicBlock(LLVMValueRef Val);
437LLVMBasicBlockRef LLVMValueAsBasicBlock(LLVMValueRef Val);
Gordon Henriksen07a45f42008-03-23 22:21:29 +0000438LLVMValueRef LLVMGetBasicBlockParent(LLVMBasicBlockRef BB);
Gordon Henriksenc23b66c2007-09-26 20:56:12 +0000439unsigned LLVMCountBasicBlocks(LLVMValueRef Fn);
440void LLVMGetBasicBlocks(LLVMValueRef Fn, LLVMBasicBlockRef *BasicBlocks);
Gordon Henriksen054817c2008-03-19 03:47:18 +0000441LLVMBasicBlockRef LLVMGetFirstBasicBlock(LLVMValueRef Fn);
442LLVMBasicBlockRef LLVMGetLastBasicBlock(LLVMValueRef Fn);
443LLVMBasicBlockRef LLVMGetNextBasicBlock(LLVMBasicBlockRef BB);
444LLVMBasicBlockRef LLVMGetPreviousBasicBlock(LLVMBasicBlockRef BB);
Gordon Henriksenc23b66c2007-09-26 20:56:12 +0000445LLVMBasicBlockRef LLVMGetEntryBasicBlock(LLVMValueRef Fn);
446LLVMBasicBlockRef LLVMAppendBasicBlock(LLVMValueRef Fn, const char *Name);
447LLVMBasicBlockRef LLVMInsertBasicBlock(LLVMBasicBlockRef InsertBeforeBB,
448 const char *Name);
449void LLVMDeleteBasicBlock(LLVMBasicBlockRef BB);
450
Gordon Henriksen265f7802008-03-19 01:11:35 +0000451/* Operations on instructions */
452LLVMBasicBlockRef LLVMGetInstructionParent(LLVMValueRef Inst);
Gordon Henriksen054817c2008-03-19 03:47:18 +0000453LLVMValueRef LLVMGetFirstInstruction(LLVMBasicBlockRef BB);
454LLVMValueRef LLVMGetLastInstruction(LLVMBasicBlockRef BB);
455LLVMValueRef LLVMGetNextInstruction(LLVMValueRef Inst);
456LLVMValueRef LLVMGetPreviousInstruction(LLVMValueRef Inst);
Gordon Henriksen265f7802008-03-19 01:11:35 +0000457
Gordon Henriksen1158c532007-12-29 20:45:00 +0000458/* Operations on call sites */
459void LLVMSetInstructionCallConv(LLVMValueRef Instr, unsigned CC);
460unsigned LLVMGetInstructionCallConv(LLVMValueRef Instr);
Gordon Henriksen2d9cc212008-04-28 17:37:06 +0000461void LLVMAddInstrParamAttr(LLVMValueRef Instr, unsigned index, LLVMParamAttr);
462void LLVMRemoveInstrParamAttr(LLVMValueRef Instr, unsigned index,
463 LLVMParamAttr);
464void LLVMSetInstrParamAlignment(LLVMValueRef Instr, unsigned index,
465 unsigned align);
Gordon Henriksen1158c532007-12-29 20:45:00 +0000466
Gordon Henriksen44dd8fb2007-10-08 18:14:39 +0000467/* Operations on phi nodes */
468void LLVMAddIncoming(LLVMValueRef PhiNode, LLVMValueRef *IncomingValues,
469 LLVMBasicBlockRef *IncomingBlocks, unsigned Count);
470unsigned LLVMCountIncoming(LLVMValueRef PhiNode);
471LLVMValueRef LLVMGetIncomingValue(LLVMValueRef PhiNode, unsigned Index);
472LLVMBasicBlockRef LLVMGetIncomingBlock(LLVMValueRef PhiNode, unsigned Index);
Gordon Henriksenc23b66c2007-09-26 20:56:12 +0000473
474/*===-- Instruction builders ----------------------------------------------===*/
475
476/* An instruction builder represents a point within a basic block, and is the
477 * exclusive means of building instructions using the C interface.
478 */
479
480LLVMBuilderRef LLVMCreateBuilder();
Gordon Henriksen054817c2008-03-19 03:47:18 +0000481void LLVMPositionBuilder(LLVMBuilderRef Builder, LLVMBasicBlockRef Block,
482 LLVMValueRef Instr);
Gordon Henriksenc23b66c2007-09-26 20:56:12 +0000483void LLVMPositionBuilderBefore(LLVMBuilderRef Builder, LLVMValueRef Instr);
484void LLVMPositionBuilderAtEnd(LLVMBuilderRef Builder, LLVMBasicBlockRef Block);
Gordon Henriksen265f7802008-03-19 01:11:35 +0000485LLVMBasicBlockRef LLVMGetInsertBlock(LLVMBuilderRef Builder);
Gordon Henriksenc23b66c2007-09-26 20:56:12 +0000486void LLVMDisposeBuilder(LLVMBuilderRef Builder);
487
488/* Terminators */
489LLVMValueRef LLVMBuildRetVoid(LLVMBuilderRef);
490LLVMValueRef LLVMBuildRet(LLVMBuilderRef, LLVMValueRef V);
491LLVMValueRef LLVMBuildBr(LLVMBuilderRef, LLVMBasicBlockRef Dest);
492LLVMValueRef LLVMBuildCondBr(LLVMBuilderRef, LLVMValueRef If,
493 LLVMBasicBlockRef Then, LLVMBasicBlockRef Else);
494LLVMValueRef LLVMBuildSwitch(LLVMBuilderRef, LLVMValueRef V,
495 LLVMBasicBlockRef Else, unsigned NumCases);
496LLVMValueRef LLVMBuildInvoke(LLVMBuilderRef, LLVMValueRef Fn,
497 LLVMValueRef *Args, unsigned NumArgs,
498 LLVMBasicBlockRef Then, LLVMBasicBlockRef Catch,
499 const char *Name);
500LLVMValueRef LLVMBuildUnwind(LLVMBuilderRef);
501LLVMValueRef LLVMBuildUnreachable(LLVMBuilderRef);
502
Gordon Henriksen097102c2008-01-01 05:50:53 +0000503/* Add a case to the switch instruction */
504void LLVMAddCase(LLVMValueRef Switch, LLVMValueRef OnVal,
505 LLVMBasicBlockRef Dest);
506
Gordon Henriksenc23b66c2007-09-26 20:56:12 +0000507/* Arithmetic */
508LLVMValueRef LLVMBuildAdd(LLVMBuilderRef, LLVMValueRef LHS, LLVMValueRef RHS,
509 const char *Name);
510LLVMValueRef LLVMBuildSub(LLVMBuilderRef, LLVMValueRef LHS, LLVMValueRef RHS,
511 const char *Name);
512LLVMValueRef LLVMBuildMul(LLVMBuilderRef, LLVMValueRef LHS, LLVMValueRef RHS,
513 const char *Name);
514LLVMValueRef LLVMBuildUDiv(LLVMBuilderRef, LLVMValueRef LHS, LLVMValueRef RHS,
515 const char *Name);
516LLVMValueRef LLVMBuildSDiv(LLVMBuilderRef, LLVMValueRef LHS, LLVMValueRef RHS,
517 const char *Name);
518LLVMValueRef LLVMBuildFDiv(LLVMBuilderRef, LLVMValueRef LHS, LLVMValueRef RHS,
519 const char *Name);
520LLVMValueRef LLVMBuildURem(LLVMBuilderRef, LLVMValueRef LHS, LLVMValueRef RHS,
521 const char *Name);
522LLVMValueRef LLVMBuildSRem(LLVMBuilderRef, LLVMValueRef LHS, LLVMValueRef RHS,
523 const char *Name);
524LLVMValueRef LLVMBuildFRem(LLVMBuilderRef, LLVMValueRef LHS, LLVMValueRef RHS,
525 const char *Name);
526LLVMValueRef LLVMBuildShl(LLVMBuilderRef, LLVMValueRef LHS, LLVMValueRef RHS,
527 const char *Name);
528LLVMValueRef LLVMBuildLShr(LLVMBuilderRef, LLVMValueRef LHS, LLVMValueRef RHS,
529 const char *Name);
530LLVMValueRef LLVMBuildAShr(LLVMBuilderRef, LLVMValueRef LHS, LLVMValueRef RHS,
531 const char *Name);
532LLVMValueRef LLVMBuildAnd(LLVMBuilderRef, LLVMValueRef LHS, LLVMValueRef RHS,
533 const char *Name);
534LLVMValueRef LLVMBuildOr(LLVMBuilderRef, LLVMValueRef LHS, LLVMValueRef RHS,
535 const char *Name);
536LLVMValueRef LLVMBuildXor(LLVMBuilderRef, LLVMValueRef LHS, LLVMValueRef RHS,
537 const char *Name);
538LLVMValueRef LLVMBuildNeg(LLVMBuilderRef, LLVMValueRef V, const char *Name);
539LLVMValueRef LLVMBuildNot(LLVMBuilderRef, LLVMValueRef V, const char *Name);
540
541/* Memory */
542LLVMValueRef LLVMBuildMalloc(LLVMBuilderRef, LLVMTypeRef Ty, const char *Name);
543LLVMValueRef LLVMBuildArrayMalloc(LLVMBuilderRef, LLVMTypeRef Ty,
544 LLVMValueRef Val, const char *Name);
545LLVMValueRef LLVMBuildAlloca(LLVMBuilderRef, LLVMTypeRef Ty, const char *Name);
546LLVMValueRef LLVMBuildArrayAlloca(LLVMBuilderRef, LLVMTypeRef Ty,
547 LLVMValueRef Val, const char *Name);
548LLVMValueRef LLVMBuildFree(LLVMBuilderRef, LLVMValueRef PointerVal);
549LLVMValueRef LLVMBuildLoad(LLVMBuilderRef, LLVMValueRef PointerVal,
550 const char *Name);
551LLVMValueRef LLVMBuildStore(LLVMBuilderRef, LLVMValueRef Val, LLVMValueRef Ptr);
552LLVMValueRef LLVMBuildGEP(LLVMBuilderRef B, LLVMValueRef Pointer,
553 LLVMValueRef *Indices, unsigned NumIndices,
554 const char *Name);
555
556/* Casts */
557LLVMValueRef LLVMBuildTrunc(LLVMBuilderRef, LLVMValueRef Val,
558 LLVMTypeRef DestTy, const char *Name);
559LLVMValueRef LLVMBuildZExt(LLVMBuilderRef, LLVMValueRef Val,
560 LLVMTypeRef DestTy, const char *Name);
561LLVMValueRef LLVMBuildSExt(LLVMBuilderRef, LLVMValueRef Val,
562 LLVMTypeRef DestTy, const char *Name);
563LLVMValueRef LLVMBuildFPToUI(LLVMBuilderRef, LLVMValueRef Val,
564 LLVMTypeRef DestTy, const char *Name);
565LLVMValueRef LLVMBuildFPToSI(LLVMBuilderRef, LLVMValueRef Val,
566 LLVMTypeRef DestTy, const char *Name);
567LLVMValueRef LLVMBuildUIToFP(LLVMBuilderRef, LLVMValueRef Val,
568 LLVMTypeRef DestTy, const char *Name);
569LLVMValueRef LLVMBuildSIToFP(LLVMBuilderRef, LLVMValueRef Val,
570 LLVMTypeRef DestTy, const char *Name);
571LLVMValueRef LLVMBuildFPTrunc(LLVMBuilderRef, LLVMValueRef Val,
572 LLVMTypeRef DestTy, const char *Name);
573LLVMValueRef LLVMBuildFPExt(LLVMBuilderRef, LLVMValueRef Val,
574 LLVMTypeRef DestTy, const char *Name);
575LLVMValueRef LLVMBuildPtrToInt(LLVMBuilderRef, LLVMValueRef Val,
576 LLVMTypeRef DestTy, const char *Name);
577LLVMValueRef LLVMBuildIntToPtr(LLVMBuilderRef, LLVMValueRef Val,
578 LLVMTypeRef DestTy, const char *Name);
579LLVMValueRef LLVMBuildBitCast(LLVMBuilderRef, LLVMValueRef Val,
580 LLVMTypeRef DestTy, const char *Name);
581
582/* Comparisons */
583LLVMValueRef LLVMBuildICmp(LLVMBuilderRef, LLVMIntPredicate Op,
584 LLVMValueRef LHS, LLVMValueRef RHS,
585 const char *Name);
586LLVMValueRef LLVMBuildFCmp(LLVMBuilderRef, LLVMRealPredicate Op,
587 LLVMValueRef LHS, LLVMValueRef RHS,
588 const char *Name);
589
590/* Miscellaneous instructions */
591LLVMValueRef LLVMBuildPhi(LLVMBuilderRef, LLVMTypeRef Ty, const char *Name);
592LLVMValueRef LLVMBuildCall(LLVMBuilderRef, LLVMValueRef Fn,
593 LLVMValueRef *Args, unsigned NumArgs,
594 const char *Name);
595LLVMValueRef LLVMBuildSelect(LLVMBuilderRef, LLVMValueRef If,
596 LLVMValueRef Then, LLVMValueRef Else,
597 const char *Name);
598LLVMValueRef LLVMBuildVAArg(LLVMBuilderRef, LLVMValueRef List, LLVMTypeRef Ty,
599 const char *Name);
600LLVMValueRef LLVMBuildExtractElement(LLVMBuilderRef, LLVMValueRef VecVal,
601 LLVMValueRef Index, const char *Name);
602LLVMValueRef LLVMBuildInsertElement(LLVMBuilderRef, LLVMValueRef VecVal,
603 LLVMValueRef EltVal, LLVMValueRef Index,
604 const char *Name);
605LLVMValueRef LLVMBuildShuffleVector(LLVMBuilderRef, LLVMValueRef V1,
606 LLVMValueRef V2, LLVMValueRef Mask,
607 const char *Name);
Gordon Henriksen76a03742007-09-18 03:18:57 +0000608
Gordon Henriksen34eb6d82007-12-19 22:30:40 +0000609
Gordon Henriksen0a68fe22007-12-12 01:04:30 +0000610/*===-- Module providers --------------------------------------------------===*/
611
612/* Encapsulates the module M in a module provider, taking ownership of the
613 * module.
614 * See the constructor llvm::ExistingModuleProvider::ExistingModuleProvider.
615 */
616LLVMModuleProviderRef
617LLVMCreateModuleProviderForExistingModule(LLVMModuleRef M);
618
619/* Destroys the module provider MP as well as the contained module.
620 * See the destructor llvm::ModuleProvider::~ModuleProvider.
621 */
622void LLVMDisposeModuleProvider(LLVMModuleProviderRef MP);
623
Gordon Henriksen34eb6d82007-12-19 22:30:40 +0000624
625/*===-- Memory buffers ----------------------------------------------------===*/
626
627int LLVMCreateMemoryBufferWithContentsOfFile(const char *Path,
628 LLVMMemoryBufferRef *OutMemBuf,
629 char **OutMessage);
630int LLVMCreateMemoryBufferWithSTDIN(LLVMMemoryBufferRef *OutMemBuf,
631 char **OutMessage);
632void LLVMDisposeMemoryBuffer(LLVMMemoryBufferRef MemBuf);
633
Gordon Henriksen878114b2008-03-16 04:20:44 +0000634
635/*===-- Pass Managers -----------------------------------------------------===*/
636
637/** Constructs a new whole-module pass pipeline. This type of pipeline is
638 suitable for link-time optimization and whole-module transformations.
639 See llvm::PassManager::PassManager. */
640LLVMPassManagerRef LLVMCreatePassManager();
641
642/** Constructs a new function-by-function pass pipeline over the module
643 provider. It does not take ownership of the module provider. This type of
644 pipeline is suitable for code generation and JIT compilation tasks.
645 See llvm::FunctionPassManager::FunctionPassManager. */
646LLVMPassManagerRef LLVMCreateFunctionPassManager(LLVMModuleProviderRef MP);
647
648/** Initializes, executes on the provided module, and finalizes all of the
649 passes scheduled in the pass manager. Returns 1 if any of the passes
650 modified the module, 0 otherwise. See llvm::PassManager::run(Module&). */
651int LLVMRunPassManager(LLVMPassManagerRef PM, LLVMModuleRef M);
652
653/** Initializes all of the function passes scheduled in the function pass
654 manager. Returns 1 if any of the passes modified the module, 0 otherwise.
655 See llvm::FunctionPassManager::doInitialization. */
656int LLVMInitializeFunctionPassManager(LLVMPassManagerRef FPM);
657
658/** Executes all of the function passes scheduled in the function pass manager
659 on the provided function. Returns 1 if any of the passes modified the
660 function, false otherwise.
661 See llvm::FunctionPassManager::run(Function&). */
662int LLVMRunFunctionPassManager(LLVMPassManagerRef FPM, LLVMValueRef F);
663
664/** Finalizes all of the function passes scheduled in in the function pass
665 manager. Returns 1 if any of the passes modified the module, 0 otherwise.
666 See llvm::FunctionPassManager::doFinalization. */
667int LLVMFinalizeFunctionPassManager(LLVMPassManagerRef FPM);
668
669/** Frees the memory of a pass pipeline. For function pipelines, does not free
670 the module provider.
671 See llvm::PassManagerBase::~PassManagerBase. */
672void LLVMDisposePassManager(LLVMPassManagerRef PM);
673
674
Gordon Henriksen76a03742007-09-18 03:18:57 +0000675#ifdef __cplusplus
676}
Gordon Henriksen76a03742007-09-18 03:18:57 +0000677
Gordon Henriksen7330acd2007-10-05 23:59:36 +0000678namespace llvm {
Gordon Henriksen0a68fe22007-12-12 01:04:30 +0000679 class ModuleProvider;
Gordon Henriksen34eb6d82007-12-19 22:30:40 +0000680 class MemoryBuffer;
Gordon Henriksen96571492008-03-16 15:55:43 +0000681 class PassManagerBase;
Gordon Henriksen0a68fe22007-12-12 01:04:30 +0000682
Gordon Henriksen34eb6d82007-12-19 22:30:40 +0000683 #define DEFINE_SIMPLE_CONVERSION_FUNCTIONS(ty, ref) \
684 inline ty *unwrap(ref P) { \
685 return reinterpret_cast<ty*>(P); \
686 } \
687 \
688 inline ref wrap(const ty *P) { \
689 return reinterpret_cast<ref>(const_cast<ty*>(P)); \
690 }
Gordon Henriksen7330acd2007-10-05 23:59:36 +0000691
Gordon Henriksen878114b2008-03-16 04:20:44 +0000692 #define DEFINE_ISA_CONVERSION_FUNCTIONS(ty, ref) \
693 DEFINE_SIMPLE_CONVERSION_FUNCTIONS(ty, ref) \
694 \
695 template<typename T> \
696 inline T *unwrap(ref P) { \
697 return cast<T>(unwrap(P)); \
698 }
699
700 #define DEFINE_STDCXX_CONVERSION_FUNCTIONS(ty, ref) \
701 DEFINE_SIMPLE_CONVERSION_FUNCTIONS(ty, ref) \
702 \
703 template<typename T> \
704 inline T *unwrap(ref P) { \
705 T *Q = dynamic_cast<T*>(unwrap(P)); \
706 assert(Q && "Invalid cast!"); \
707 return Q; \
708 }
709
710 DEFINE_ISA_CONVERSION_FUNCTIONS (Type, LLVMTypeRef )
711 DEFINE_ISA_CONVERSION_FUNCTIONS (Value, LLVMValueRef )
Gordon Henriksen823f9732007-12-27 18:25:59 +0000712 DEFINE_SIMPLE_CONVERSION_FUNCTIONS(Module, LLVMModuleRef )
713 DEFINE_SIMPLE_CONVERSION_FUNCTIONS(BasicBlock, LLVMBasicBlockRef )
Duncan Sandsa07136e2008-04-13 06:22:09 +0000714 DEFINE_SIMPLE_CONVERSION_FUNCTIONS(IRBuilder, LLVMBuilderRef )
Gordon Henriksen823f9732007-12-27 18:25:59 +0000715 DEFINE_SIMPLE_CONVERSION_FUNCTIONS(PATypeHolder, LLVMTypeHandleRef )
716 DEFINE_SIMPLE_CONVERSION_FUNCTIONS(ModuleProvider, LLVMModuleProviderRef)
717 DEFINE_SIMPLE_CONVERSION_FUNCTIONS(MemoryBuffer, LLVMMemoryBufferRef )
Gordon Henriksen878114b2008-03-16 04:20:44 +0000718 DEFINE_STDCXX_CONVERSION_FUNCTIONS(PassManagerBase, LLVMPassManagerRef )
Gordon Henriksen7330acd2007-10-05 23:59:36 +0000719
Gordon Henriksen878114b2008-03-16 04:20:44 +0000720 #undef DEFINE_STDCXX_CONVERSION_FUNCTIONS
721 #undef DEFINE_ISA_CONVERSION_FUNCTIONS
Gordon Henriksen34eb6d82007-12-19 22:30:40 +0000722 #undef DEFINE_SIMPLE_CONVERSION_FUNCTIONS
Gordon Henriksen7330acd2007-10-05 23:59:36 +0000723
Gordon Henriksen34eb6d82007-12-19 22:30:40 +0000724 /* Specialized opaque type conversions.
725 */
Gordon Henriksen7330acd2007-10-05 23:59:36 +0000726 inline Type **unwrap(LLVMTypeRef* Tys) {
727 return reinterpret_cast<Type**>(Tys);
728 }
729
Gordon Henriksen7330acd2007-10-05 23:59:36 +0000730 inline LLVMTypeRef *wrap(const Type **Tys) {
731 return reinterpret_cast<LLVMTypeRef*>(const_cast<Type**>(Tys));
732 }
733
Gordon Henriksen34eb6d82007-12-19 22:30:40 +0000734 /* Specialized opaque value conversions.
Gordon Henriksen7330acd2007-10-05 23:59:36 +0000735 */
Gordon Henriksen7330acd2007-10-05 23:59:36 +0000736 inline Value **unwrap(LLVMValueRef *Vals) {
737 return reinterpret_cast<Value**>(Vals);
738 }
739
740 template<typename T>
741 inline T **unwrap(LLVMValueRef *Vals, unsigned Length) {
742 #if DEBUG
743 for (LLVMValueRef *I = Vals, E = Vals + Length; I != E; ++I)
744 cast<T>(*I);
745 #endif
746 return reinterpret_cast<T**>(Vals);
747 }
748
Gordon Henriksen7330acd2007-10-05 23:59:36 +0000749 inline LLVMValueRef *wrap(const Value **Vals) {
750 return reinterpret_cast<LLVMValueRef*>(const_cast<Value**>(Vals));
751 }
Gordon Henriksen7330acd2007-10-05 23:59:36 +0000752}
753
754#endif /* !defined(__cplusplus) */
755
756#endif /* !defined(LLVM_C_CORE_H) */