c1609b013eb1d10b14040bd8fa166a1999d97ce4
[oota-llvm.git] / include / llvm-c / Core.h
1 /*===-- llvm-c/Core.h - Core Library C Interface ------------------*- C -*-===*\
2 |*                                                                            *|
3 |*                     The LLVM Compiler Infrastructure                       *|
4 |*                                                                            *|
5 |* This file is distributed under the University of Illinois Open Source      *|
6 |* License. See LICENSE.TXT for details.                                      *|
7 |*                                                                            *|
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 |*                                                                            *|
26 |* 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 |*                                                                            *|
31 \*===----------------------------------------------------------------------===*/
32
33 #ifndef LLVM_C_CORE_H
34 #define LLVM_C_CORE_H
35
36 #ifdef __cplusplus
37
38 /* Need these includes to support the LLVM 'cast' template for the C++ 'wrap' 
39    and 'unwrap' conversion functions. */
40 #include "llvm/Module.h"
41 #include "llvm/Support/IRBuilder.h"
42
43 extern "C" {
44 #endif
45
46
47 /* Opaque types. */
48
49 /**
50  * The top-level container for all LLVM global data.  See the LLVMContext class.
51  */
52 typedef struct LLVMOpaqueContext *LLVMContextRef;
53
54 /**
55  * The top-level container for all other LLVM Intermediate Representation (IR)
56  * objects. See the llvm::Module class.
57  */
58 typedef struct LLVMOpaqueModule *LLVMModuleRef;
59
60 /**
61  * Each value in the LLVM IR has a type, an LLVMTypeRef. See the llvm::Type
62  * class.
63  */
64 typedef struct LLVMOpaqueType *LLVMTypeRef;
65
66 /**
67  * When building recursive types using LLVMRefineType, LLVMTypeRef values may
68  * become invalid; use LLVMTypeHandleRef to resolve this problem. See the
69  * llvm::AbstractTypeHolder class.
70  */
71 typedef struct LLVMOpaqueTypeHandle *LLVMTypeHandleRef;
72
73 typedef struct LLVMOpaqueValue *LLVMValueRef;
74 typedef struct LLVMOpaqueBasicBlock *LLVMBasicBlockRef;
75 typedef struct LLVMOpaqueBuilder *LLVMBuilderRef;
76
77 /* Used to provide a module to JIT or interpreter.
78  * See the llvm::ModuleProvider class.
79  */
80 typedef struct LLVMOpaqueModuleProvider *LLVMModuleProviderRef;
81
82 /* Used to provide a module to JIT or interpreter.
83  * See the llvm::MemoryBuffer class.
84  */
85 typedef struct LLVMOpaqueMemoryBuffer *LLVMMemoryBufferRef;
86
87 /** See the llvm::PassManagerBase class. */
88 typedef struct LLVMOpaquePassManager *LLVMPassManagerRef;
89
90 typedef enum {
91     LLVMZExtAttribute       = 1<<0,
92     LLVMSExtAttribute       = 1<<1,
93     LLVMNoReturnAttribute   = 1<<2,
94     LLVMInRegAttribute      = 1<<3,
95     LLVMStructRetAttribute  = 1<<4,
96     LLVMNoUnwindAttribute   = 1<<5,
97     LLVMNoAliasAttribute    = 1<<6,
98     LLVMByValAttribute      = 1<<7,
99     LLVMNestAttribute       = 1<<8,
100     LLVMReadNoneAttribute   = 1<<9,
101     LLVMReadOnlyAttribute   = 1<<10,
102     LLVMNoInlineAttribute   = 1<<11,
103     LLVMAlwaysInlineAttribute    = 1<<12,
104     LLVMOptimizeForSizeAttribute = 1<<13,
105     LLVMStackProtectAttribute    = 1<<14,
106     LLVMStackProtectReqAttribute = 1<<15,
107     LLVMNoCaptureAttribute  = 1<<21,
108     LLVMNoRedZoneAttribute  = 1<<22,
109     LLVMNoImplicitFloatAttribute = 1<<23,
110     LLVMNakedAttribute      = 1<<24
111 } LLVMAttribute;
112
113 typedef enum {
114   LLVMVoidTypeKind,        /**< type with no size */
115   LLVMFloatTypeKind,       /**< 32 bit floating point type */
116   LLVMDoubleTypeKind,      /**< 64 bit floating point type */
117   LLVMX86_FP80TypeKind,    /**< 80 bit floating point type (X87) */
118   LLVMFP128TypeKind,       /**< 128 bit floating point type (112-bit mantissa)*/
119   LLVMPPC_FP128TypeKind,   /**< 128 bit floating point type (two 64-bits) */
120   LLVMLabelTypeKind,       /**< Labels */
121   LLVMIntegerTypeKind,     /**< Arbitrary bit width integers */
122   LLVMFunctionTypeKind,    /**< Functions */
123   LLVMStructTypeKind,      /**< Structures */
124   LLVMArrayTypeKind,       /**< Arrays */
125   LLVMPointerTypeKind,     /**< Pointers */
126   LLVMOpaqueTypeKind,      /**< Opaque: type with unknown structure */
127   LLVMVectorTypeKind,      /**< SIMD 'packed' format, or other vector type */
128   LLVMMetadataTypeKind     /**< Metadata */
129 } LLVMTypeKind;
130
131 typedef enum {
132   LLVMExternalLinkage,    /**< Externally visible function */
133   LLVMAvailableExternallyLinkage,
134   LLVMLinkOnceAnyLinkage, /**< Keep one copy of function when linking (inline)*/
135   LLVMLinkOnceODRLinkage, /**< Same, but only replaced by something
136                             equivalent. */
137   LLVMWeakAnyLinkage,     /**< Keep one copy of function when linking (weak) */
138   LLVMWeakODRLinkage,     /**< Same, but only replaced by something
139                             equivalent. */
140   LLVMAppendingLinkage,   /**< Special purpose, only applies to global arrays */
141   LLVMInternalLinkage,    /**< Rename collisions when linking (static
142                                functions) */
143   LLVMPrivateLinkage,     /**< Like Internal, but omit from symbol table */
144   LLVMDLLImportLinkage,   /**< Function to be imported from DLL */
145   LLVMDLLExportLinkage,   /**< Function to be accessible from DLL */
146   LLVMExternalWeakLinkage,/**< ExternalWeak linkage description */
147   LLVMGhostLinkage,       /**< Stand-in functions for streaming fns from
148                                bitcode */
149   LLVMCommonLinkage,      /**< Tentative definitions */
150   LLVMLinkerPrivateLinkage /**< Like Private, but linker removes. */
151 } LLVMLinkage;
152
153 typedef enum {
154   LLVMDefaultVisibility,  /**< The GV is visible */
155   LLVMHiddenVisibility,   /**< The GV is hidden */
156   LLVMProtectedVisibility /**< The GV is protected */
157 } LLVMVisibility;
158
159 typedef enum {
160   LLVMCCallConv           = 0,
161   LLVMFastCallConv        = 8,
162   LLVMColdCallConv        = 9,
163   LLVMX86StdcallCallConv  = 64,
164   LLVMX86FastcallCallConv = 65
165 } LLVMCallConv;
166
167 typedef enum {
168   LLVMIntEQ = 32, /**< equal */
169   LLVMIntNE,      /**< not equal */
170   LLVMIntUGT,     /**< unsigned greater than */
171   LLVMIntUGE,     /**< unsigned greater or equal */
172   LLVMIntULT,     /**< unsigned less than */
173   LLVMIntULE,     /**< unsigned less or equal */
174   LLVMIntSGT,     /**< signed greater than */
175   LLVMIntSGE,     /**< signed greater or equal */
176   LLVMIntSLT,     /**< signed less than */
177   LLVMIntSLE      /**< signed less or equal */
178 } LLVMIntPredicate;
179
180 typedef enum {
181   LLVMRealPredicateFalse, /**< Always false (always folded) */
182   LLVMRealOEQ,            /**< True if ordered and equal */
183   LLVMRealOGT,            /**< True if ordered and greater than */
184   LLVMRealOGE,            /**< True if ordered and greater than or equal */
185   LLVMRealOLT,            /**< True if ordered and less than */
186   LLVMRealOLE,            /**< True if ordered and less than or equal */
187   LLVMRealONE,            /**< True if ordered and operands are unequal */
188   LLVMRealORD,            /**< True if ordered (no nans) */
189   LLVMRealUNO,            /**< True if unordered: isnan(X) | isnan(Y) */
190   LLVMRealUEQ,            /**< True if unordered or equal */
191   LLVMRealUGT,            /**< True if unordered or greater than */
192   LLVMRealUGE,            /**< True if unordered, greater than, or equal */
193   LLVMRealULT,            /**< True if unordered or less than */
194   LLVMRealULE,            /**< True if unordered, less than, or equal */
195   LLVMRealUNE,            /**< True if unordered or not equal */
196   LLVMRealPredicateTrue   /**< Always true (always folded) */
197 } LLVMRealPredicate;
198
199
200 /*===-- Error handling ----------------------------------------------------===*/
201
202 void LLVMDisposeMessage(char *Message);
203
204
205 /*===-- Modules -----------------------------------------------------------===*/
206
207 /* Create and destroy contexts. */
208 LLVMContextRef LLVMContextCreate();
209 LLVMContextRef LLVMGetGlobalContext();
210 void LLVMContextDispose(LLVMContextRef C);
211
212 /* Create and destroy modules. */ 
213 /** See llvm::Module::Module. */
214 LLVMModuleRef LLVMModuleCreateWithName(const char *ModuleID);
215 LLVMModuleRef LLVMModuleCreateWithNameInContext(const char *ModuleID,
216                                                 LLVMContextRef C);
217
218 /** See llvm::Module::~Module. */
219 void LLVMDisposeModule(LLVMModuleRef M);
220
221 /** Data layout. See Module::getDataLayout. */
222 const char *LLVMGetDataLayout(LLVMModuleRef M);
223 void LLVMSetDataLayout(LLVMModuleRef M, const char *Triple);
224
225 /** Target triple. See Module::getTargetTriple. */
226 const char *LLVMGetTarget(LLVMModuleRef M);
227 void LLVMSetTarget(LLVMModuleRef M, const char *Triple);
228
229 /** See Module::addTypeName. */
230 int LLVMAddTypeName(LLVMModuleRef M, const char *Name, LLVMTypeRef Ty);
231 void LLVMDeleteTypeName(LLVMModuleRef M, const char *Name);
232 LLVMTypeRef LLVMGetTypeByName(LLVMModuleRef M, const char *Name);
233
234 /** See Module::dump. */
235 void LLVMDumpModule(LLVMModuleRef M);
236
237
238 /*===-- Types -------------------------------------------------------------===*/
239
240 /* LLVM types conform to the following hierarchy:
241  * 
242  *   types:
243  *     integer type
244  *     real type
245  *     function type
246  *     sequence types:
247  *       array type
248  *       pointer type
249  *       vector type
250  *     void type
251  *     label type
252  *     opaque type
253  */
254
255 /** See llvm::LLVMTypeKind::getTypeID. */
256 LLVMTypeKind LLVMGetTypeKind(LLVMTypeRef Ty);
257
258 /** See llvm::LLVMType::getContext. */
259 LLVMContextRef LLVMGetTypeContext(LLVMTypeRef Ty);
260
261 /* Operations on integer types */
262 LLVMTypeRef LLVMInt1TypeInContext(LLVMContextRef C);
263 LLVMTypeRef LLVMInt8TypeInContext(LLVMContextRef C);
264 LLVMTypeRef LLVMInt16TypeInContext(LLVMContextRef C);
265 LLVMTypeRef LLVMInt32TypeInContext(LLVMContextRef C);
266 LLVMTypeRef LLVMInt64TypeInContext(LLVMContextRef C);
267 LLVMTypeRef LLVMIntTypeInContext(LLVMContextRef C, unsigned NumBits);
268
269 LLVMTypeRef LLVMInt1Type(void);
270 LLVMTypeRef LLVMInt8Type(void);
271 LLVMTypeRef LLVMInt16Type(void);
272 LLVMTypeRef LLVMInt32Type(void);
273 LLVMTypeRef LLVMInt64Type(void);
274 LLVMTypeRef LLVMIntType(unsigned NumBits);
275 unsigned LLVMGetIntTypeWidth(LLVMTypeRef IntegerTy);
276
277 /* Operations on real types */
278 LLVMTypeRef LLVMFloatTypeInContext(LLVMContextRef C);
279 LLVMTypeRef LLVMDoubleTypeInContext(LLVMContextRef C);
280 LLVMTypeRef LLVMX86FP80TypeInContext(LLVMContextRef C);
281 LLVMTypeRef LLVMFP128TypeInContext(LLVMContextRef C);
282 LLVMTypeRef LLVMPPCFP128TypeInContext(LLVMContextRef C);
283
284 LLVMTypeRef LLVMFloatType(void);
285 LLVMTypeRef LLVMDoubleType(void);
286 LLVMTypeRef LLVMX86FP80Type(void);
287 LLVMTypeRef LLVMFP128Type(void);
288 LLVMTypeRef LLVMPPCFP128Type(void);
289
290 /* Operations on function types */
291 LLVMTypeRef LLVMFunctionType(LLVMTypeRef ReturnType,
292                              LLVMTypeRef *ParamTypes, unsigned ParamCount,
293                              int IsVarArg);
294 int LLVMIsFunctionVarArg(LLVMTypeRef FunctionTy);
295 LLVMTypeRef LLVMGetReturnType(LLVMTypeRef FunctionTy);
296 unsigned LLVMCountParamTypes(LLVMTypeRef FunctionTy);
297 void LLVMGetParamTypes(LLVMTypeRef FunctionTy, LLVMTypeRef *Dest);
298
299 /* Operations on struct types */
300 LLVMTypeRef LLVMStructTypeInContext(LLVMContextRef C, LLVMTypeRef *ElementTypes,
301                                     unsigned ElementCount, int Packed);
302 LLVMTypeRef LLVMStructType(LLVMTypeRef *ElementTypes, unsigned ElementCount,
303                            int Packed);
304 unsigned LLVMCountStructElementTypes(LLVMTypeRef StructTy);
305 void LLVMGetStructElementTypes(LLVMTypeRef StructTy, LLVMTypeRef *Dest);
306 int LLVMIsPackedStruct(LLVMTypeRef StructTy);
307
308 /* Operations on array, pointer, and vector types (sequence types) */
309 LLVMTypeRef LLVMArrayType(LLVMTypeRef ElementType, unsigned ElementCount);
310 LLVMTypeRef LLVMPointerType(LLVMTypeRef ElementType, unsigned AddressSpace);
311 LLVMTypeRef LLVMVectorType(LLVMTypeRef ElementType, unsigned ElementCount);
312
313 LLVMTypeRef LLVMGetElementType(LLVMTypeRef Ty);
314 unsigned LLVMGetArrayLength(LLVMTypeRef ArrayTy);
315 unsigned LLVMGetPointerAddressSpace(LLVMTypeRef PointerTy);
316 unsigned LLVMGetVectorSize(LLVMTypeRef VectorTy);
317
318 /* Operations on other types */
319 LLVMTypeRef LLVMVoidTypeInContext(LLVMContextRef C);
320 LLVMTypeRef LLVMLabelTypeInContext(LLVMContextRef C);
321 LLVMTypeRef LLVMOpaqueTypeInContext(LLVMContextRef C);
322
323 LLVMTypeRef LLVMVoidType(void);
324 LLVMTypeRef LLVMLabelType(void);
325 LLVMTypeRef LLVMOpaqueType(void);
326
327 /* Operations on type handles */
328 LLVMTypeHandleRef LLVMCreateTypeHandle(LLVMTypeRef PotentiallyAbstractTy);
329 void LLVMRefineType(LLVMTypeRef AbstractTy, LLVMTypeRef ConcreteTy);
330 LLVMTypeRef LLVMResolveTypeHandle(LLVMTypeHandleRef TypeHandle);
331 void LLVMDisposeTypeHandle(LLVMTypeHandleRef TypeHandle);
332
333
334 /*===-- Values ------------------------------------------------------------===*/
335
336 /* The bulk of LLVM's object model consists of values, which comprise a very
337  * rich type hierarchy.
338  */
339
340 #define LLVM_FOR_EACH_VALUE_SUBCLASS(macro) \
341   macro(Argument)                           \
342   macro(BasicBlock)                         \
343   macro(InlineAsm)                          \
344   macro(User)                               \
345     macro(Constant)                         \
346       macro(ConstantAggregateZero)          \
347       macro(ConstantArray)                  \
348       macro(ConstantExpr)                   \
349       macro(ConstantFP)                     \
350       macro(ConstantInt)                    \
351       macro(ConstantPointerNull)            \
352       macro(ConstantStruct)                 \
353       macro(ConstantVector)                 \
354       macro(GlobalValue)                    \
355         macro(Function)                     \
356         macro(GlobalAlias)                  \
357         macro(GlobalVariable)               \
358       macro(UndefValue)                     \
359     macro(Instruction)                      \
360       macro(BinaryOperator)                 \
361       macro(CallInst)                       \
362         macro(IntrinsicInst)                \
363           macro(DbgInfoIntrinsic)           \
364             macro(DbgDeclareInst)           \
365             macro(DbgFuncStartInst)         \
366             macro(DbgRegionEndInst)         \
367             macro(DbgRegionStartInst)       \
368             macro(DbgStopPointInst)         \
369           macro(EHSelectorInst)             \
370           macro(MemIntrinsic)               \
371             macro(MemCpyInst)               \
372             macro(MemMoveInst)              \
373             macro(MemSetInst)               \
374       macro(CmpInst)                        \
375       macro(FCmpInst)                       \
376       macro(ICmpInst)                       \
377       macro(ExtractElementInst)             \
378       macro(GetElementPtrInst)              \
379       macro(InsertElementInst)              \
380       macro(InsertValueInst)                \
381       macro(PHINode)                        \
382       macro(SelectInst)                     \
383       macro(ShuffleVectorInst)              \
384       macro(StoreInst)                      \
385       macro(TerminatorInst)                 \
386         macro(BranchInst)                   \
387         macro(InvokeInst)                   \
388         macro(ReturnInst)                   \
389         macro(SwitchInst)                   \
390         macro(UnreachableInst)              \
391         macro(UnwindInst)                   \
392     macro(UnaryInstruction)                 \
393       macro(AllocationInst)                 \
394         macro(AllocaInst)                   \
395         macro(MallocInst)                   \
396       macro(CastInst)                       \
397         macro(BitCastInst)                  \
398         macro(FPExtInst)                    \
399         macro(FPToSIInst)                   \
400         macro(FPToUIInst)                   \
401         macro(FPTruncInst)                  \
402         macro(IntToPtrInst)                 \
403         macro(PtrToIntInst)                 \
404         macro(SExtInst)                     \
405         macro(SIToFPInst)                   \
406         macro(TruncInst)                    \
407         macro(UIToFPInst)                   \
408         macro(ZExtInst)                     \
409       macro(ExtractValueInst)               \
410       macro(FreeInst)                       \
411       macro(LoadInst)                       \
412       macro(VAArgInst)
413
414 /* Operations on all values */
415 LLVMTypeRef LLVMTypeOf(LLVMValueRef Val);
416 const char *LLVMGetValueName(LLVMValueRef Val);
417 void LLVMSetValueName(LLVMValueRef Val, const char *Name);
418 void LLVMDumpValue(LLVMValueRef Val);
419
420 /* Conversion functions. Return the input value if it is an instance of the
421    specified class, otherwise NULL. See llvm::dyn_cast_or_null<>. */
422 #define LLVM_DECLARE_VALUE_CAST(name) \
423   LLVMValueRef LLVMIsA##name(LLVMValueRef Val);
424 LLVM_FOR_EACH_VALUE_SUBCLASS(LLVM_DECLARE_VALUE_CAST)
425
426 /* Operations on constants of any type */
427 LLVMValueRef LLVMConstNull(LLVMTypeRef Ty); /* all zeroes */
428 LLVMValueRef LLVMConstAllOnes(LLVMTypeRef Ty); /* only for int/vector */
429 LLVMValueRef LLVMGetUndef(LLVMTypeRef Ty);
430 int LLVMIsConstant(LLVMValueRef Val);
431 int LLVMIsNull(LLVMValueRef Val);
432 int LLVMIsUndef(LLVMValueRef Val);
433 LLVMValueRef LLVMConstPointerNull(LLVMTypeRef Ty);
434
435 /* Operations on scalar constants */
436 LLVMValueRef LLVMConstInt(LLVMTypeRef IntTy, unsigned long long N,
437                           int SignExtend);
438 LLVMValueRef LLVMConstReal(LLVMTypeRef RealTy, double N);
439 LLVMValueRef LLVMConstRealOfString(LLVMTypeRef RealTy, const char *Text);
440
441 /* Operations on composite constants */
442 LLVMValueRef LLVMConstStringInContext(LLVMContextRef C, const char *Str,
443                                       unsigned Length, int DontNullTerminate);
444 LLVMValueRef LLVMConstStructInContext(LLVMContextRef C, 
445                                       LLVMValueRef *ConstantVals,
446                                       unsigned Count, int Packed);
447
448 LLVMValueRef LLVMConstString(const char *Str, unsigned Length,
449                              int DontNullTerminate);
450 LLVMValueRef LLVMConstArray(LLVMTypeRef ElementTy,
451                             LLVMValueRef *ConstantVals, unsigned Length);
452 LLVMValueRef LLVMConstStruct(LLVMValueRef *ConstantVals, unsigned Count,
453                              int Packed);
454 LLVMValueRef LLVMConstVector(LLVMValueRef *ScalarConstantVals, unsigned Size);
455
456 /* Constant expressions */
457 LLVMValueRef LLVMSizeOf(LLVMTypeRef Ty);
458 LLVMValueRef LLVMConstNeg(LLVMValueRef ConstantVal);
459 LLVMValueRef LLVMConstNot(LLVMValueRef ConstantVal);
460 LLVMValueRef LLVMConstAdd(LLVMValueRef LHSConstant, LLVMValueRef RHSConstant);
461 LLVMValueRef LLVMConstSub(LLVMValueRef LHSConstant, LLVMValueRef RHSConstant);
462 LLVMValueRef LLVMConstMul(LLVMValueRef LHSConstant, LLVMValueRef RHSConstant);
463 LLVMValueRef LLVMConstUDiv(LLVMValueRef LHSConstant, LLVMValueRef RHSConstant);
464 LLVMValueRef LLVMConstSDiv(LLVMValueRef LHSConstant, LLVMValueRef RHSConstant);
465 LLVMValueRef LLVMConstFDiv(LLVMValueRef LHSConstant, LLVMValueRef RHSConstant);
466 LLVMValueRef LLVMConstURem(LLVMValueRef LHSConstant, LLVMValueRef RHSConstant);
467 LLVMValueRef LLVMConstSRem(LLVMValueRef LHSConstant, LLVMValueRef RHSConstant);
468 LLVMValueRef LLVMConstFRem(LLVMValueRef LHSConstant, LLVMValueRef RHSConstant);
469 LLVMValueRef LLVMConstAnd(LLVMValueRef LHSConstant, LLVMValueRef RHSConstant);
470 LLVMValueRef LLVMConstOr(LLVMValueRef LHSConstant, LLVMValueRef RHSConstant);
471 LLVMValueRef LLVMConstXor(LLVMValueRef LHSConstant, LLVMValueRef RHSConstant);
472 LLVMValueRef LLVMConstICmp(LLVMIntPredicate Predicate,
473                            LLVMValueRef LHSConstant, LLVMValueRef RHSConstant);
474 LLVMValueRef LLVMConstFCmp(LLVMRealPredicate Predicate,
475                            LLVMValueRef LHSConstant, LLVMValueRef RHSConstant);
476 LLVMValueRef LLVMConstShl(LLVMValueRef LHSConstant, LLVMValueRef RHSConstant);
477 LLVMValueRef LLVMConstLShr(LLVMValueRef LHSConstant, LLVMValueRef RHSConstant);
478 LLVMValueRef LLVMConstAShr(LLVMValueRef LHSConstant, LLVMValueRef RHSConstant);
479 LLVMValueRef LLVMConstGEP(LLVMValueRef ConstantVal,
480                           LLVMValueRef *ConstantIndices, unsigned NumIndices);
481 LLVMValueRef LLVMConstTrunc(LLVMValueRef ConstantVal, LLVMTypeRef ToType);
482 LLVMValueRef LLVMConstSExt(LLVMValueRef ConstantVal, LLVMTypeRef ToType);
483 LLVMValueRef LLVMConstZExt(LLVMValueRef ConstantVal, LLVMTypeRef ToType);
484 LLVMValueRef LLVMConstFPTrunc(LLVMValueRef ConstantVal, LLVMTypeRef ToType);
485 LLVMValueRef LLVMConstFPExt(LLVMValueRef ConstantVal, LLVMTypeRef ToType);
486 LLVMValueRef LLVMConstUIToFP(LLVMValueRef ConstantVal, LLVMTypeRef ToType);
487 LLVMValueRef LLVMConstSIToFP(LLVMValueRef ConstantVal, LLVMTypeRef ToType);
488 LLVMValueRef LLVMConstFPToUI(LLVMValueRef ConstantVal, LLVMTypeRef ToType);
489 LLVMValueRef LLVMConstFPToSI(LLVMValueRef ConstantVal, LLVMTypeRef ToType);
490 LLVMValueRef LLVMConstPtrToInt(LLVMValueRef ConstantVal, LLVMTypeRef ToType);
491 LLVMValueRef LLVMConstIntToPtr(LLVMValueRef ConstantVal, LLVMTypeRef ToType);
492 LLVMValueRef LLVMConstBitCast(LLVMValueRef ConstantVal, LLVMTypeRef ToType);
493 LLVMValueRef LLVMConstSelect(LLVMValueRef ConstantCondition,
494                              LLVMValueRef ConstantIfTrue,
495                              LLVMValueRef ConstantIfFalse);
496 LLVMValueRef LLVMConstExtractElement(LLVMValueRef VectorConstant,
497                                      LLVMValueRef IndexConstant);
498 LLVMValueRef LLVMConstInsertElement(LLVMValueRef VectorConstant,
499                                     LLVMValueRef ElementValueConstant,
500                                     LLVMValueRef IndexConstant);
501 LLVMValueRef LLVMConstShuffleVector(LLVMValueRef VectorAConstant,
502                                     LLVMValueRef VectorBConstant,
503                                     LLVMValueRef MaskConstant);
504 LLVMValueRef LLVMConstExtractValue(LLVMValueRef AggConstant, unsigned *IdxList,
505                                    unsigned NumIdx);
506 LLVMValueRef LLVMConstInsertValue(LLVMValueRef AggConstant,
507                                   LLVMValueRef ElementValueConstant,
508                                   unsigned *IdxList, unsigned NumIdx);
509 LLVMValueRef LLVMConstInlineAsm(LLVMTypeRef Ty, 
510                                 const char *AsmString, const char *Constraints,
511                                 int HasSideEffects);
512
513 /* Operations on global variables, functions, and aliases (globals) */
514 LLVMModuleRef LLVMGetGlobalParent(LLVMValueRef Global);
515 int LLVMIsDeclaration(LLVMValueRef Global);
516 LLVMLinkage LLVMGetLinkage(LLVMValueRef Global);
517 void LLVMSetLinkage(LLVMValueRef Global, LLVMLinkage Linkage);
518 const char *LLVMGetSection(LLVMValueRef Global);
519 void LLVMSetSection(LLVMValueRef Global, const char *Section);
520 LLVMVisibility LLVMGetVisibility(LLVMValueRef Global);
521 void LLVMSetVisibility(LLVMValueRef Global, LLVMVisibility Viz);
522 unsigned LLVMGetAlignment(LLVMValueRef Global);
523 void LLVMSetAlignment(LLVMValueRef Global, unsigned Bytes);
524
525 /* Operations on global variables */
526 LLVMValueRef LLVMAddGlobal(LLVMModuleRef M, LLVMTypeRef Ty, const char *Name);
527 LLVMValueRef LLVMGetNamedGlobal(LLVMModuleRef M, const char *Name);
528 LLVMValueRef LLVMGetFirstGlobal(LLVMModuleRef M);
529 LLVMValueRef LLVMGetLastGlobal(LLVMModuleRef M);
530 LLVMValueRef LLVMGetNextGlobal(LLVMValueRef GlobalVar);
531 LLVMValueRef LLVMGetPreviousGlobal(LLVMValueRef GlobalVar);
532 void LLVMDeleteGlobal(LLVMValueRef GlobalVar);
533 LLVMValueRef LLVMGetInitializer(LLVMValueRef GlobalVar);
534 void LLVMSetInitializer(LLVMValueRef GlobalVar, LLVMValueRef ConstantVal);
535 int LLVMIsThreadLocal(LLVMValueRef GlobalVar);
536 void LLVMSetThreadLocal(LLVMValueRef GlobalVar, int IsThreadLocal);
537 int LLVMIsGlobalConstant(LLVMValueRef GlobalVar);
538 void LLVMSetGlobalConstant(LLVMValueRef GlobalVar, int IsConstant);
539
540 /* Operations on aliases */
541 LLVMValueRef LLVMAddAlias(LLVMModuleRef M, LLVMTypeRef Ty, LLVMValueRef Aliasee,
542                           const char *Name);
543
544 /* Operations on functions */
545 LLVMValueRef LLVMAddFunction(LLVMModuleRef M, const char *Name,
546                              LLVMTypeRef FunctionTy);
547 LLVMValueRef LLVMGetNamedFunction(LLVMModuleRef M, const char *Name);
548 LLVMValueRef LLVMGetFirstFunction(LLVMModuleRef M);
549 LLVMValueRef LLVMGetLastFunction(LLVMModuleRef M);
550 LLVMValueRef LLVMGetNextFunction(LLVMValueRef Fn);
551 LLVMValueRef LLVMGetPreviousFunction(LLVMValueRef Fn);
552 void LLVMDeleteFunction(LLVMValueRef Fn);
553 unsigned LLVMGetIntrinsicID(LLVMValueRef Fn);
554 unsigned LLVMGetFunctionCallConv(LLVMValueRef Fn);
555 void LLVMSetFunctionCallConv(LLVMValueRef Fn, unsigned CC);
556 const char *LLVMGetGC(LLVMValueRef Fn);
557 void LLVMSetGC(LLVMValueRef Fn, const char *Name);
558 void LLVMAddFunctionAttr(LLVMValueRef Fn, LLVMAttribute PA);
559 void LLVMRemoveFunctionAttr(LLVMValueRef Fn, LLVMAttribute PA);
560
561 /* Operations on parameters */
562 unsigned LLVMCountParams(LLVMValueRef Fn);
563 void LLVMGetParams(LLVMValueRef Fn, LLVMValueRef *Params);
564 LLVMValueRef LLVMGetParam(LLVMValueRef Fn, unsigned Index);
565 LLVMValueRef LLVMGetParamParent(LLVMValueRef Inst);
566 LLVMValueRef LLVMGetFirstParam(LLVMValueRef Fn);
567 LLVMValueRef LLVMGetLastParam(LLVMValueRef Fn);
568 LLVMValueRef LLVMGetNextParam(LLVMValueRef Arg);
569 LLVMValueRef LLVMGetPreviousParam(LLVMValueRef Arg);
570 void LLVMAddAttribute(LLVMValueRef Arg, LLVMAttribute PA);
571 void LLVMRemoveAttribute(LLVMValueRef Arg, LLVMAttribute PA);
572 void LLVMSetParamAlignment(LLVMValueRef Arg, unsigned align);
573
574 /* Operations on basic blocks */
575 LLVMValueRef LLVMBasicBlockAsValue(LLVMBasicBlockRef BB);
576 int LLVMValueIsBasicBlock(LLVMValueRef Val);
577 LLVMBasicBlockRef LLVMValueAsBasicBlock(LLVMValueRef Val);
578 LLVMValueRef LLVMGetBasicBlockParent(LLVMBasicBlockRef BB);
579 unsigned LLVMCountBasicBlocks(LLVMValueRef Fn);
580 void LLVMGetBasicBlocks(LLVMValueRef Fn, LLVMBasicBlockRef *BasicBlocks);
581 LLVMBasicBlockRef LLVMGetFirstBasicBlock(LLVMValueRef Fn);
582 LLVMBasicBlockRef LLVMGetLastBasicBlock(LLVMValueRef Fn);
583 LLVMBasicBlockRef LLVMGetNextBasicBlock(LLVMBasicBlockRef BB);
584 LLVMBasicBlockRef LLVMGetPreviousBasicBlock(LLVMBasicBlockRef BB);
585 LLVMBasicBlockRef LLVMGetEntryBasicBlock(LLVMValueRef Fn);
586
587 LLVMBasicBlockRef LLVMAppendBasicBlockInContext(LLVMContextRef C,
588                                                 LLVMValueRef Fn,
589                                                 const char *Name);
590 LLVMBasicBlockRef LLVMInsertBasicBlockInContext(LLVMContextRef C,
591                                                 LLVMBasicBlockRef BB,
592                                                 const char *Name);
593
594 LLVMBasicBlockRef LLVMAppendBasicBlock(LLVMValueRef Fn, const char *Name);
595 LLVMBasicBlockRef LLVMInsertBasicBlock(LLVMBasicBlockRef InsertBeforeBB,
596                                        const char *Name);
597 void LLVMDeleteBasicBlock(LLVMBasicBlockRef BB);
598
599 /* Operations on instructions */
600 LLVMBasicBlockRef LLVMGetInstructionParent(LLVMValueRef Inst);
601 LLVMValueRef LLVMGetFirstInstruction(LLVMBasicBlockRef BB);
602 LLVMValueRef LLVMGetLastInstruction(LLVMBasicBlockRef BB);
603 LLVMValueRef LLVMGetNextInstruction(LLVMValueRef Inst);
604 LLVMValueRef LLVMGetPreviousInstruction(LLVMValueRef Inst);
605
606 /* Operations on call sites */
607 void LLVMSetInstructionCallConv(LLVMValueRef Instr, unsigned CC);
608 unsigned LLVMGetInstructionCallConv(LLVMValueRef Instr);
609 void LLVMAddInstrAttribute(LLVMValueRef Instr, unsigned index, LLVMAttribute);
610 void LLVMRemoveInstrAttribute(LLVMValueRef Instr, unsigned index, 
611                               LLVMAttribute);
612 void LLVMSetInstrParamAlignment(LLVMValueRef Instr, unsigned index, 
613                                 unsigned align);
614
615 /* Operations on call instructions (only) */
616 int LLVMIsTailCall(LLVMValueRef CallInst);
617 void LLVMSetTailCall(LLVMValueRef CallInst, int IsTailCall);
618
619 /* Operations on phi nodes */
620 void LLVMAddIncoming(LLVMValueRef PhiNode, LLVMValueRef *IncomingValues,
621                      LLVMBasicBlockRef *IncomingBlocks, unsigned Count);
622 unsigned LLVMCountIncoming(LLVMValueRef PhiNode);
623 LLVMValueRef LLVMGetIncomingValue(LLVMValueRef PhiNode, unsigned Index);
624 LLVMBasicBlockRef LLVMGetIncomingBlock(LLVMValueRef PhiNode, unsigned Index);
625
626 /*===-- Instruction builders ----------------------------------------------===*/
627
628 /* An instruction builder represents a point within a basic block, and is the
629  * exclusive means of building instructions using the C interface.
630  */
631
632 LLVMBuilderRef LLVMCreateBuilderInContext(LLVMContextRef C);
633 LLVMBuilderRef LLVMCreateBuilder(void);
634 void LLVMPositionBuilder(LLVMBuilderRef Builder, LLVMBasicBlockRef Block,
635                          LLVMValueRef Instr);
636 void LLVMPositionBuilderBefore(LLVMBuilderRef Builder, LLVMValueRef Instr);
637 void LLVMPositionBuilderAtEnd(LLVMBuilderRef Builder, LLVMBasicBlockRef Block);
638 LLVMBasicBlockRef LLVMGetInsertBlock(LLVMBuilderRef Builder);
639 void LLVMClearInsertionPosition(LLVMBuilderRef Builder);
640 void LLVMInsertIntoBuilder(LLVMBuilderRef Builder, LLVMValueRef Instr);
641 void LLVMDisposeBuilder(LLVMBuilderRef Builder);
642
643 /* Terminators */
644 LLVMValueRef LLVMBuildRetVoid(LLVMBuilderRef);
645 LLVMValueRef LLVMBuildRet(LLVMBuilderRef, LLVMValueRef V);
646 LLVMValueRef LLVMBuildBr(LLVMBuilderRef, LLVMBasicBlockRef Dest);
647 LLVMValueRef LLVMBuildCondBr(LLVMBuilderRef, LLVMValueRef If,
648                              LLVMBasicBlockRef Then, LLVMBasicBlockRef Else);
649 LLVMValueRef LLVMBuildSwitch(LLVMBuilderRef, LLVMValueRef V,
650                              LLVMBasicBlockRef Else, unsigned NumCases);
651 LLVMValueRef LLVMBuildInvoke(LLVMBuilderRef, LLVMValueRef Fn,
652                              LLVMValueRef *Args, unsigned NumArgs,
653                              LLVMBasicBlockRef Then, LLVMBasicBlockRef Catch,
654                              const char *Name);
655 LLVMValueRef LLVMBuildUnwind(LLVMBuilderRef);
656 LLVMValueRef LLVMBuildUnreachable(LLVMBuilderRef);
657
658 /* Add a case to the switch instruction */
659 void LLVMAddCase(LLVMValueRef Switch, LLVMValueRef OnVal,
660                  LLVMBasicBlockRef Dest);
661
662 /* Arithmetic */
663 LLVMValueRef LLVMBuildAdd(LLVMBuilderRef, LLVMValueRef LHS, LLVMValueRef RHS,
664                           const char *Name);
665 LLVMValueRef LLVMBuildSub(LLVMBuilderRef, LLVMValueRef LHS, LLVMValueRef RHS,
666                           const char *Name);
667 LLVMValueRef LLVMBuildMul(LLVMBuilderRef, LLVMValueRef LHS, LLVMValueRef RHS,
668                           const char *Name);
669 LLVMValueRef LLVMBuildUDiv(LLVMBuilderRef, LLVMValueRef LHS, LLVMValueRef RHS,
670                            const char *Name);
671 LLVMValueRef LLVMBuildSDiv(LLVMBuilderRef, LLVMValueRef LHS, LLVMValueRef RHS,
672                            const char *Name);
673 LLVMValueRef LLVMBuildFDiv(LLVMBuilderRef, LLVMValueRef LHS, LLVMValueRef RHS,
674                            const char *Name);
675 LLVMValueRef LLVMBuildURem(LLVMBuilderRef, LLVMValueRef LHS, LLVMValueRef RHS,
676                            const char *Name);
677 LLVMValueRef LLVMBuildSRem(LLVMBuilderRef, LLVMValueRef LHS, LLVMValueRef RHS,
678                            const char *Name);
679 LLVMValueRef LLVMBuildFRem(LLVMBuilderRef, LLVMValueRef LHS, LLVMValueRef RHS,
680                            const char *Name);
681 LLVMValueRef LLVMBuildShl(LLVMBuilderRef, LLVMValueRef LHS, LLVMValueRef RHS,
682                            const char *Name);
683 LLVMValueRef LLVMBuildLShr(LLVMBuilderRef, LLVMValueRef LHS, LLVMValueRef RHS,
684                            const char *Name);
685 LLVMValueRef LLVMBuildAShr(LLVMBuilderRef, LLVMValueRef LHS, LLVMValueRef RHS,
686                            const char *Name);
687 LLVMValueRef LLVMBuildAnd(LLVMBuilderRef, LLVMValueRef LHS, LLVMValueRef RHS,
688                           const char *Name);
689 LLVMValueRef LLVMBuildOr(LLVMBuilderRef, LLVMValueRef LHS, LLVMValueRef RHS,
690                           const char *Name);
691 LLVMValueRef LLVMBuildXor(LLVMBuilderRef, LLVMValueRef LHS, LLVMValueRef RHS,
692                           const char *Name);
693 LLVMValueRef LLVMBuildNeg(LLVMBuilderRef, LLVMValueRef V, const char *Name);
694 LLVMValueRef LLVMBuildNot(LLVMBuilderRef, LLVMValueRef V, const char *Name);
695
696 /* Memory */
697 LLVMValueRef LLVMBuildMalloc(LLVMBuilderRef, LLVMTypeRef Ty, const char *Name);
698 LLVMValueRef LLVMBuildArrayMalloc(LLVMBuilderRef, LLVMTypeRef Ty,
699                                   LLVMValueRef Val, const char *Name);
700 LLVMValueRef LLVMBuildAlloca(LLVMBuilderRef, LLVMTypeRef Ty, const char *Name);
701 LLVMValueRef LLVMBuildArrayAlloca(LLVMBuilderRef, LLVMTypeRef Ty,
702                                   LLVMValueRef Val, const char *Name);
703 LLVMValueRef LLVMBuildFree(LLVMBuilderRef, LLVMValueRef PointerVal);
704 LLVMValueRef LLVMBuildLoad(LLVMBuilderRef, LLVMValueRef PointerVal,
705                            const char *Name);
706 LLVMValueRef LLVMBuildStore(LLVMBuilderRef, LLVMValueRef Val, LLVMValueRef Ptr);
707 LLVMValueRef LLVMBuildGEP(LLVMBuilderRef B, LLVMValueRef Pointer,
708                           LLVMValueRef *Indices, unsigned NumIndices,
709                           const char *Name);
710
711 /* Casts */
712 LLVMValueRef LLVMBuildTrunc(LLVMBuilderRef, LLVMValueRef Val,
713                             LLVMTypeRef DestTy, const char *Name);
714 LLVMValueRef LLVMBuildZExt(LLVMBuilderRef, LLVMValueRef Val,
715                            LLVMTypeRef DestTy, const char *Name);
716 LLVMValueRef LLVMBuildSExt(LLVMBuilderRef, LLVMValueRef Val,
717                            LLVMTypeRef DestTy, const char *Name);
718 LLVMValueRef LLVMBuildFPToUI(LLVMBuilderRef, LLVMValueRef Val,
719                              LLVMTypeRef DestTy, const char *Name);
720 LLVMValueRef LLVMBuildFPToSI(LLVMBuilderRef, LLVMValueRef Val,
721                              LLVMTypeRef DestTy, const char *Name);
722 LLVMValueRef LLVMBuildUIToFP(LLVMBuilderRef, LLVMValueRef Val,
723                              LLVMTypeRef DestTy, const char *Name);
724 LLVMValueRef LLVMBuildSIToFP(LLVMBuilderRef, LLVMValueRef Val,
725                              LLVMTypeRef DestTy, const char *Name);
726 LLVMValueRef LLVMBuildFPTrunc(LLVMBuilderRef, LLVMValueRef Val,
727                               LLVMTypeRef DestTy, const char *Name);
728 LLVMValueRef LLVMBuildFPExt(LLVMBuilderRef, LLVMValueRef Val,
729                             LLVMTypeRef DestTy, const char *Name);
730 LLVMValueRef LLVMBuildPtrToInt(LLVMBuilderRef, LLVMValueRef Val,
731                                LLVMTypeRef DestTy, const char *Name);
732 LLVMValueRef LLVMBuildIntToPtr(LLVMBuilderRef, LLVMValueRef Val,
733                                LLVMTypeRef DestTy, const char *Name);
734 LLVMValueRef LLVMBuildBitCast(LLVMBuilderRef, LLVMValueRef Val,
735                               LLVMTypeRef DestTy, const char *Name);
736
737 /* Comparisons */
738 LLVMValueRef LLVMBuildICmp(LLVMBuilderRef, LLVMIntPredicate Op,
739                            LLVMValueRef LHS, LLVMValueRef RHS,
740                            const char *Name);
741 LLVMValueRef LLVMBuildFCmp(LLVMBuilderRef, LLVMRealPredicate Op,
742                            LLVMValueRef LHS, LLVMValueRef RHS,
743                            const char *Name);
744
745 /* Miscellaneous instructions */
746 LLVMValueRef LLVMBuildPhi(LLVMBuilderRef, LLVMTypeRef Ty, const char *Name);
747 LLVMValueRef LLVMBuildCall(LLVMBuilderRef, LLVMValueRef Fn,
748                            LLVMValueRef *Args, unsigned NumArgs,
749                            const char *Name);
750 LLVMValueRef LLVMBuildSelect(LLVMBuilderRef, LLVMValueRef If,
751                              LLVMValueRef Then, LLVMValueRef Else,
752                              const char *Name);
753 LLVMValueRef LLVMBuildVAArg(LLVMBuilderRef, LLVMValueRef List, LLVMTypeRef Ty,
754                             const char *Name);
755 LLVMValueRef LLVMBuildExtractElement(LLVMBuilderRef, LLVMValueRef VecVal,
756                                      LLVMValueRef Index, const char *Name);
757 LLVMValueRef LLVMBuildInsertElement(LLVMBuilderRef, LLVMValueRef VecVal,
758                                     LLVMValueRef EltVal, LLVMValueRef Index,
759                                     const char *Name);
760 LLVMValueRef LLVMBuildShuffleVector(LLVMBuilderRef, LLVMValueRef V1,
761                                     LLVMValueRef V2, LLVMValueRef Mask,
762                                     const char *Name);
763 LLVMValueRef LLVMBuildExtractValue(LLVMBuilderRef, LLVMValueRef AggVal,
764                                    unsigned Index, const char *Name);
765 LLVMValueRef LLVMBuildInsertValue(LLVMBuilderRef, LLVMValueRef AggVal,
766                                   LLVMValueRef EltVal, unsigned Index,
767                                   const char *Name);
768
769
770 /*===-- Module providers --------------------------------------------------===*/
771
772 /* Encapsulates the module M in a module provider, taking ownership of the
773  * module.
774  * See the constructor llvm::ExistingModuleProvider::ExistingModuleProvider.
775  */
776 LLVMModuleProviderRef
777 LLVMCreateModuleProviderForExistingModule(LLVMModuleRef M);
778
779 /* Destroys the module provider MP as well as the contained module.
780  * See the destructor llvm::ModuleProvider::~ModuleProvider.
781  */
782 void LLVMDisposeModuleProvider(LLVMModuleProviderRef MP);
783
784
785 /*===-- Memory buffers ----------------------------------------------------===*/
786
787 int LLVMCreateMemoryBufferWithContentsOfFile(const char *Path,
788                                              LLVMMemoryBufferRef *OutMemBuf,
789                                              char **OutMessage);
790 int LLVMCreateMemoryBufferWithSTDIN(LLVMMemoryBufferRef *OutMemBuf,
791                                     char **OutMessage);
792 void LLVMDisposeMemoryBuffer(LLVMMemoryBufferRef MemBuf);
793
794
795 /*===-- Pass Managers -----------------------------------------------------===*/
796
797 /** Constructs a new whole-module pass pipeline. This type of pipeline is
798     suitable for link-time optimization and whole-module transformations.
799     See llvm::PassManager::PassManager. */
800 LLVMPassManagerRef LLVMCreatePassManager(void);
801
802 /** Constructs a new function-by-function pass pipeline over the module
803     provider. It does not take ownership of the module provider. This type of
804     pipeline is suitable for code generation and JIT compilation tasks.
805     See llvm::FunctionPassManager::FunctionPassManager. */
806 LLVMPassManagerRef LLVMCreateFunctionPassManager(LLVMModuleProviderRef MP);
807
808 /** Initializes, executes on the provided module, and finalizes all of the
809     passes scheduled in the pass manager. Returns 1 if any of the passes
810     modified the module, 0 otherwise. See llvm::PassManager::run(Module&). */
811 int LLVMRunPassManager(LLVMPassManagerRef PM, LLVMModuleRef M);
812
813 /** Initializes all of the function passes scheduled in the function pass
814     manager. Returns 1 if any of the passes modified the module, 0 otherwise.
815     See llvm::FunctionPassManager::doInitialization. */
816 int LLVMInitializeFunctionPassManager(LLVMPassManagerRef FPM);
817
818 /** Executes all of the function passes scheduled in the function pass manager
819     on the provided function. Returns 1 if any of the passes modified the
820     function, false otherwise.
821     See llvm::FunctionPassManager::run(Function&). */
822 int LLVMRunFunctionPassManager(LLVMPassManagerRef FPM, LLVMValueRef F);
823
824 /** Finalizes all of the function passes scheduled in in the function pass
825     manager. Returns 1 if any of the passes modified the module, 0 otherwise.
826     See llvm::FunctionPassManager::doFinalization. */
827 int LLVMFinalizeFunctionPassManager(LLVMPassManagerRef FPM);
828
829 /** Frees the memory of a pass pipeline. For function pipelines, does not free
830     the module provider.
831     See llvm::PassManagerBase::~PassManagerBase. */
832 void LLVMDisposePassManager(LLVMPassManagerRef PM);
833
834
835 #ifdef __cplusplus
836 }
837
838 namespace llvm {
839   class ModuleProvider;
840   class MemoryBuffer;
841   class PassManagerBase;
842   
843   #define DEFINE_SIMPLE_CONVERSION_FUNCTIONS(ty, ref)   \
844     inline ty *unwrap(ref P) {                          \
845       return reinterpret_cast<ty*>(P);                  \
846     }                                                   \
847                                                         \
848     inline ref wrap(const ty *P) {                      \
849       return reinterpret_cast<ref>(const_cast<ty*>(P)); \
850     }
851   
852   #define DEFINE_ISA_CONVERSION_FUNCTIONS(ty, ref)  \
853     DEFINE_SIMPLE_CONVERSION_FUNCTIONS(ty, ref)         \
854                                                         \
855     template<typename T>                                \
856     inline T *unwrap(ref P) {                           \
857       return cast<T>(unwrap(P));                        \
858     }
859   
860   #define DEFINE_STDCXX_CONVERSION_FUNCTIONS(ty, ref)   \
861     DEFINE_SIMPLE_CONVERSION_FUNCTIONS(ty, ref)         \
862                                                         \
863     template<typename T>                                \
864     inline T *unwrap(ref P) {                           \
865       T *Q = dynamic_cast<T*>(unwrap(P));               \
866       assert(Q && "Invalid cast!");                     \
867       return Q;                                         \
868     }
869   
870   DEFINE_ISA_CONVERSION_FUNCTIONS   (Type,               LLVMTypeRef          )
871   DEFINE_ISA_CONVERSION_FUNCTIONS   (Value,              LLVMValueRef         )
872   DEFINE_SIMPLE_CONVERSION_FUNCTIONS(Module,             LLVMModuleRef        )
873   DEFINE_SIMPLE_CONVERSION_FUNCTIONS(BasicBlock,         LLVMBasicBlockRef    )
874   DEFINE_SIMPLE_CONVERSION_FUNCTIONS(IRBuilder<>,        LLVMBuilderRef       )
875   DEFINE_SIMPLE_CONVERSION_FUNCTIONS(PATypeHolder,       LLVMTypeHandleRef    )
876   DEFINE_SIMPLE_CONVERSION_FUNCTIONS(ModuleProvider,     LLVMModuleProviderRef)
877   DEFINE_SIMPLE_CONVERSION_FUNCTIONS(MemoryBuffer,       LLVMMemoryBufferRef  )
878   DEFINE_SIMPLE_CONVERSION_FUNCTIONS(LLVMContext,        LLVMContextRef       )
879   DEFINE_STDCXX_CONVERSION_FUNCTIONS(PassManagerBase,    LLVMPassManagerRef   )
880   
881   #undef DEFINE_STDCXX_CONVERSION_FUNCTIONS
882   #undef DEFINE_ISA_CONVERSION_FUNCTIONS
883   #undef DEFINE_SIMPLE_CONVERSION_FUNCTIONS
884
885   /* Specialized opaque context conversions.
886    */
887   inline LLVMContext **unwrap(LLVMContextRef* Tys) {
888     return reinterpret_cast<LLVMContext**>(Tys);
889   }
890   
891   inline LLVMContextRef *wrap(const LLVMContext **Tys) {
892     return reinterpret_cast<LLVMContextRef*>(const_cast<LLVMContext**>(Tys));
893   }
894   
895   /* Specialized opaque type conversions.
896    */
897   inline Type **unwrap(LLVMTypeRef* Tys) {
898     return reinterpret_cast<Type**>(Tys);
899   }
900   
901   inline LLVMTypeRef *wrap(const Type **Tys) {
902     return reinterpret_cast<LLVMTypeRef*>(const_cast<Type**>(Tys));
903   }
904   
905   /* Specialized opaque value conversions.
906    */ 
907   inline Value **unwrap(LLVMValueRef *Vals) {
908     return reinterpret_cast<Value**>(Vals);
909   }
910   
911   template<typename T>
912   inline T **unwrap(LLVMValueRef *Vals, unsigned Length) {
913     #if DEBUG
914     for (LLVMValueRef *I = Vals, *E = Vals + Length; I != E; ++I)
915       cast<T>(*I);
916     #endif
917     return reinterpret_cast<T**>(Vals);
918   }
919   
920   inline LLVMValueRef *wrap(const Value **Vals) {
921     return reinterpret_cast<LLVMValueRef*>(const_cast<Value**>(Vals));
922   }
923 }
924
925 #endif /* !defined(__cplusplus) */
926
927 #endif /* !defined(LLVM_C_CORE_H) */