Expose most of the rest of IRBuilder's functions to llvm-c.
[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 LLVMBuildAggregateRet(LLVMBuilderRef, LLVMValueRef RetVals,
647                                    unsigned N);
648 LLVMValueRef LLVMBuildBr(LLVMBuilderRef, LLVMBasicBlockRef Dest);
649 LLVMValueRef LLVMBuildCondBr(LLVMBuilderRef, LLVMValueRef If,
650                              LLVMBasicBlockRef Then, LLVMBasicBlockRef Else);
651 LLVMValueRef LLVMBuildSwitch(LLVMBuilderRef, LLVMValueRef V,
652                              LLVMBasicBlockRef Else, unsigned NumCases);
653 LLVMValueRef LLVMBuildInvoke(LLVMBuilderRef, LLVMValueRef Fn,
654                              LLVMValueRef *Args, unsigned NumArgs,
655                              LLVMBasicBlockRef Then, LLVMBasicBlockRef Catch,
656                              const char *Name);
657 LLVMValueRef LLVMBuildUnwind(LLVMBuilderRef);
658 LLVMValueRef LLVMBuildUnreachable(LLVMBuilderRef);
659
660 /* Add a case to the switch instruction */
661 void LLVMAddCase(LLVMValueRef Switch, LLVMValueRef OnVal,
662                  LLVMBasicBlockRef Dest);
663
664 /* Arithmetic */
665 LLVMValueRef LLVMBuildAdd(LLVMBuilderRef, LLVMValueRef LHS, LLVMValueRef RHS,
666                           const char *Name);
667 LLVMValueRef LLVMBuildNSWAdd(LLVMBuilderRef, LLVMValueRef LHS, LLVMValueRef RHS,
668                              const char *Name);
669 LLVMValueRef LLVMBuildFAdd(LLVMBuilderRef, LLVMValueRef LHS, LLVMValueRef RHS,
670                            const char *Name);
671 LLVMValueRef LLVMBuildSub(LLVMBuilderRef, LLVMValueRef LHS, LLVMValueRef RHS,
672                           const char *Name);
673 LLVMValueRef LLVMBuildFSub(LLVMBuilderRef, LLVMValueRef LHS, LLVMValueRef RHS,
674                            const char *Name);
675 LLVMValueRef LLVMBuildMul(LLVMBuilderRef, LLVMValueRef LHS, LLVMValueRef RHS,
676                           const char *Name);
677 LLVMValueRef LLVMBuildFMul(LLVMBuilderRef, LLVMValueRef LHS, LLVMValueRef RHS,
678                            const char *Name);
679 LLVMValueRef LLVMBuildUDiv(LLVMBuilderRef, LLVMValueRef LHS, LLVMValueRef RHS,
680                            const char *Name);
681 LLVMValueRef LLVMBuildSDiv(LLVMBuilderRef, LLVMValueRef LHS, LLVMValueRef RHS,
682                            const char *Name);
683 LLVMValueRef LLVMBuildExactSDiv(LLVMBuilderRef, LLVMValueRef LHS, LLVMValueRef RHS,
684                                 const char *Name);
685 LLVMValueRef LLVMBuildFDiv(LLVMBuilderRef, LLVMValueRef LHS, LLVMValueRef RHS,
686                            const char *Name);
687 LLVMValueRef LLVMBuildURem(LLVMBuilderRef, LLVMValueRef LHS, LLVMValueRef RHS,
688                            const char *Name);
689 LLVMValueRef LLVMBuildSRem(LLVMBuilderRef, LLVMValueRef LHS, LLVMValueRef RHS,
690                            const char *Name);
691 LLVMValueRef LLVMBuildFRem(LLVMBuilderRef, LLVMValueRef LHS, LLVMValueRef RHS,
692                            const char *Name);
693 LLVMValueRef LLVMBuildShl(LLVMBuilderRef, LLVMValueRef LHS, LLVMValueRef RHS,
694                            const char *Name);
695 LLVMValueRef LLVMBuildLShr(LLVMBuilderRef, LLVMValueRef LHS, LLVMValueRef RHS,
696                            const char *Name);
697 LLVMValueRef LLVMBuildAShr(LLVMBuilderRef, LLVMValueRef LHS, LLVMValueRef RHS,
698                            const char *Name);
699 LLVMValueRef LLVMBuildAnd(LLVMBuilderRef, LLVMValueRef LHS, LLVMValueRef RHS,
700                           const char *Name);
701 LLVMValueRef LLVMBuildOr(LLVMBuilderRef, LLVMValueRef LHS, LLVMValueRef RHS,
702                           const char *Name);
703 LLVMValueRef LLVMBuildXor(LLVMBuilderRef, LLVMValueRef LHS, LLVMValueRef RHS,
704                           const char *Name);
705 LLVMValueRef LLVMBuildNeg(LLVMBuilderRef, LLVMValueRef V, const char *Name);
706 LLVMValueRef LLVMBuildNot(LLVMBuilderRef, LLVMValueRef V, const char *Name);
707
708 /* Memory */
709 LLVMValueRef LLVMBuildMalloc(LLVMBuilderRef, LLVMTypeRef Ty, const char *Name);
710 LLVMValueRef LLVMBuildArrayMalloc(LLVMBuilderRef, LLVMTypeRef Ty,
711                                   LLVMValueRef Val, const char *Name);
712 LLVMValueRef LLVMBuildAlloca(LLVMBuilderRef, LLVMTypeRef Ty, const char *Name);
713 LLVMValueRef LLVMBuildArrayAlloca(LLVMBuilderRef, LLVMTypeRef Ty,
714                                   LLVMValueRef Val, const char *Name);
715 LLVMValueRef LLVMBuildFree(LLVMBuilderRef, LLVMValueRef PointerVal);
716 LLVMValueRef LLVMBuildLoad(LLVMBuilderRef, LLVMValueRef PointerVal,
717                            const char *Name);
718 LLVMValueRef LLVMBuildStore(LLVMBuilderRef, LLVMValueRef Val, LLVMValueRef Ptr);
719 LLVMValueRef LLVMBuildGEP(LLVMBuilderRef B, LLVMValueRef Pointer,
720                           LLVMValueRef *Indices, unsigned NumIndices,
721                           const char *Name);
722 LLVMValueRef LLVMBuildInBoundsGEP(LLVMBuilderRef B, LLVMValueRef Pointer,
723                                   LLVMValueRef *Indices, unsigned NumIndices,
724                                   const char *Name);
725 LLVMValueRef LLVMBuildStructGEP(LLVMBuilderRef B, LLVMValueRef Pointer,
726                                 unsigned Idx, const char *Name);
727 LLVMValueRef LLVMBuildGlobalString(LLVMBuilderRef B, const char *Str,
728                                    const char *Name);
729 LLVMValueRef LLVMBuildGlobalStringPtr(LLVMBuilderRef B, const char *Str,
730                                       const char *Name);
731
732 /* Casts */
733 LLVMValueRef LLVMBuildTrunc(LLVMBuilderRef, LLVMValueRef Val,
734                             LLVMTypeRef DestTy, const char *Name);
735 LLVMValueRef LLVMBuildZExt(LLVMBuilderRef, LLVMValueRef Val,
736                            LLVMTypeRef DestTy, const char *Name);
737 LLVMValueRef LLVMBuildSExt(LLVMBuilderRef, LLVMValueRef Val,
738                            LLVMTypeRef DestTy, const char *Name);
739 LLVMValueRef LLVMBuildFPToUI(LLVMBuilderRef, LLVMValueRef Val,
740                              LLVMTypeRef DestTy, const char *Name);
741 LLVMValueRef LLVMBuildFPToSI(LLVMBuilderRef, LLVMValueRef Val,
742                              LLVMTypeRef DestTy, const char *Name);
743 LLVMValueRef LLVMBuildUIToFP(LLVMBuilderRef, LLVMValueRef Val,
744                              LLVMTypeRef DestTy, const char *Name);
745 LLVMValueRef LLVMBuildSIToFP(LLVMBuilderRef, LLVMValueRef Val,
746                              LLVMTypeRef DestTy, const char *Name);
747 LLVMValueRef LLVMBuildFPTrunc(LLVMBuilderRef, LLVMValueRef Val,
748                               LLVMTypeRef DestTy, const char *Name);
749 LLVMValueRef LLVMBuildFPExt(LLVMBuilderRef, LLVMValueRef Val,
750                             LLVMTypeRef DestTy, const char *Name);
751 LLVMValueRef LLVMBuildPtrToInt(LLVMBuilderRef, LLVMValueRef Val,
752                                LLVMTypeRef DestTy, const char *Name);
753 LLVMValueRef LLVMBuildIntToPtr(LLVMBuilderRef, LLVMValueRef Val,
754                                LLVMTypeRef DestTy, const char *Name);
755 LLVMValueRef LLVMBuildBitCast(LLVMBuilderRef, LLVMValueRef Val,
756                               LLVMTypeRef DestTy, const char *Name);
757 LLVMValueRef LLVMBuildZExtOrBitCast(LLVMBuilderRef, LLVMValueRef Val,
758                                     LLVMTypeRef DestTy, const char *Name);
759 LLVMValueRef LLVMBuildSExtOrBitCast(LLVMBuilderRef, LLVMValueRef Val,
760                                     LLVMTypeRef DestTy, const char *Name);
761 LLVMValueRef LLVMBuildTruncOrBitCast(LLVMBuilderRef, LLVMValueRef Val,
762                                      LLVMTypeRef DestTy, const char *Name);
763 LLVMValueRef LLVMBuildPointerCast(LLVMBuilderRef, LLVMValueRef Val,
764                                   LLVMTypeRef DestTy, const char *Name);
765 LLVMValueRef LLVMBuildIntCast(LLVMBuilderRef, LLVMValueRef Val,
766                               LLVMTypeRef DestTy, const char *Name);
767 LLVMValueRef LLVMBuildFPCast(LLVMBuilderRef, LLVMValueRef Val,
768                              LLVMTypeRef DestTy, const char *Name);
769
770 /* Comparisons */
771 LLVMValueRef LLVMBuildICmp(LLVMBuilderRef, LLVMIntPredicate Op,
772                            LLVMValueRef LHS, LLVMValueRef RHS,
773                            const char *Name);
774 LLVMValueRef LLVMBuildFCmp(LLVMBuilderRef, LLVMRealPredicate Op,
775                            LLVMValueRef LHS, LLVMValueRef RHS,
776                            const char *Name);
777
778 /* Miscellaneous instructions */
779 LLVMValueRef LLVMBuildPhi(LLVMBuilderRef, LLVMTypeRef Ty, const char *Name);
780 LLVMValueRef LLVMBuildCall(LLVMBuilderRef, LLVMValueRef Fn,
781                            LLVMValueRef *Args, unsigned NumArgs,
782                            const char *Name);
783 LLVMValueRef LLVMBuildSelect(LLVMBuilderRef, LLVMValueRef If,
784                              LLVMValueRef Then, LLVMValueRef Else,
785                              const char *Name);
786 LLVMValueRef LLVMBuildVAArg(LLVMBuilderRef, LLVMValueRef List, LLVMTypeRef Ty,
787                             const char *Name);
788 LLVMValueRef LLVMBuildExtractElement(LLVMBuilderRef, LLVMValueRef VecVal,
789                                      LLVMValueRef Index, const char *Name);
790 LLVMValueRef LLVMBuildInsertElement(LLVMBuilderRef, LLVMValueRef VecVal,
791                                     LLVMValueRef EltVal, LLVMValueRef Index,
792                                     const char *Name);
793 LLVMValueRef LLVMBuildShuffleVector(LLVMBuilderRef, LLVMValueRef V1,
794                                     LLVMValueRef V2, LLVMValueRef Mask,
795                                     const char *Name);
796 LLVMValueRef LLVMBuildExtractValue(LLVMBuilderRef, LLVMValueRef AggVal,
797                                    unsigned Index, const char *Name);
798 LLVMValueRef LLVMBuildInsertValue(LLVMBuilderRef, LLVMValueRef AggVal,
799                                   LLVMValueRef EltVal, unsigned Index,
800                                   const char *Name);
801
802 LLVMValueRef LLVMBuildIsNull(LLVMBuilderRef, LLVMValueRef Val,
803                              const char *Name);
804 LLVMValueRef LLVMBuildIsNotNull(LLVMBuilderRef, LLVMValueRef Val,
805                                 const char *Name);
806 LLVMValueRef LLVMBuildPtrDiff(LLVMBuilderRef, LLVMValueRef LHS,
807                               LLVMValueRef RHS, const char *Name);
808
809
810 /*===-- Module providers --------------------------------------------------===*/
811
812 /* Encapsulates the module M in a module provider, taking ownership of the
813  * module.
814  * See the constructor llvm::ExistingModuleProvider::ExistingModuleProvider.
815  */
816 LLVMModuleProviderRef
817 LLVMCreateModuleProviderForExistingModule(LLVMModuleRef M);
818
819 /* Destroys the module provider MP as well as the contained module.
820  * See the destructor llvm::ModuleProvider::~ModuleProvider.
821  */
822 void LLVMDisposeModuleProvider(LLVMModuleProviderRef MP);
823
824
825 /*===-- Memory buffers ----------------------------------------------------===*/
826
827 int LLVMCreateMemoryBufferWithContentsOfFile(const char *Path,
828                                              LLVMMemoryBufferRef *OutMemBuf,
829                                              char **OutMessage);
830 int LLVMCreateMemoryBufferWithSTDIN(LLVMMemoryBufferRef *OutMemBuf,
831                                     char **OutMessage);
832 void LLVMDisposeMemoryBuffer(LLVMMemoryBufferRef MemBuf);
833
834
835 /*===-- Pass Managers -----------------------------------------------------===*/
836
837 /** Constructs a new whole-module pass pipeline. This type of pipeline is
838     suitable for link-time optimization and whole-module transformations.
839     See llvm::PassManager::PassManager. */
840 LLVMPassManagerRef LLVMCreatePassManager(void);
841
842 /** Constructs a new function-by-function pass pipeline over the module
843     provider. It does not take ownership of the module provider. This type of
844     pipeline is suitable for code generation and JIT compilation tasks.
845     See llvm::FunctionPassManager::FunctionPassManager. */
846 LLVMPassManagerRef LLVMCreateFunctionPassManager(LLVMModuleProviderRef MP);
847
848 /** Initializes, executes on the provided module, and finalizes all of the
849     passes scheduled in the pass manager. Returns 1 if any of the passes
850     modified the module, 0 otherwise. See llvm::PassManager::run(Module&). */
851 int LLVMRunPassManager(LLVMPassManagerRef PM, LLVMModuleRef M);
852
853 /** Initializes all of the function passes scheduled in the function pass
854     manager. Returns 1 if any of the passes modified the module, 0 otherwise.
855     See llvm::FunctionPassManager::doInitialization. */
856 int LLVMInitializeFunctionPassManager(LLVMPassManagerRef FPM);
857
858 /** Executes all of the function passes scheduled in the function pass manager
859     on the provided function. Returns 1 if any of the passes modified the
860     function, false otherwise.
861     See llvm::FunctionPassManager::run(Function&). */
862 int LLVMRunFunctionPassManager(LLVMPassManagerRef FPM, LLVMValueRef F);
863
864 /** Finalizes all of the function passes scheduled in in the function pass
865     manager. Returns 1 if any of the passes modified the module, 0 otherwise.
866     See llvm::FunctionPassManager::doFinalization. */
867 int LLVMFinalizeFunctionPassManager(LLVMPassManagerRef FPM);
868
869 /** Frees the memory of a pass pipeline. For function pipelines, does not free
870     the module provider.
871     See llvm::PassManagerBase::~PassManagerBase. */
872 void LLVMDisposePassManager(LLVMPassManagerRef PM);
873
874
875 #ifdef __cplusplus
876 }
877
878 namespace llvm {
879   class ModuleProvider;
880   class MemoryBuffer;
881   class PassManagerBase;
882   
883   #define DEFINE_SIMPLE_CONVERSION_FUNCTIONS(ty, ref)   \
884     inline ty *unwrap(ref P) {                          \
885       return reinterpret_cast<ty*>(P);                  \
886     }                                                   \
887                                                         \
888     inline ref wrap(const ty *P) {                      \
889       return reinterpret_cast<ref>(const_cast<ty*>(P)); \
890     }
891   
892   #define DEFINE_ISA_CONVERSION_FUNCTIONS(ty, ref)  \
893     DEFINE_SIMPLE_CONVERSION_FUNCTIONS(ty, ref)         \
894                                                         \
895     template<typename T>                                \
896     inline T *unwrap(ref P) {                           \
897       return cast<T>(unwrap(P));                        \
898     }
899   
900   #define DEFINE_STDCXX_CONVERSION_FUNCTIONS(ty, ref)   \
901     DEFINE_SIMPLE_CONVERSION_FUNCTIONS(ty, ref)         \
902                                                         \
903     template<typename T>                                \
904     inline T *unwrap(ref P) {                           \
905       T *Q = dynamic_cast<T*>(unwrap(P));               \
906       assert(Q && "Invalid cast!");                     \
907       return Q;                                         \
908     }
909   
910   DEFINE_ISA_CONVERSION_FUNCTIONS   (Type,               LLVMTypeRef          )
911   DEFINE_ISA_CONVERSION_FUNCTIONS   (Value,              LLVMValueRef         )
912   DEFINE_SIMPLE_CONVERSION_FUNCTIONS(Module,             LLVMModuleRef        )
913   DEFINE_SIMPLE_CONVERSION_FUNCTIONS(BasicBlock,         LLVMBasicBlockRef    )
914   DEFINE_SIMPLE_CONVERSION_FUNCTIONS(IRBuilder<>,        LLVMBuilderRef       )
915   DEFINE_SIMPLE_CONVERSION_FUNCTIONS(PATypeHolder,       LLVMTypeHandleRef    )
916   DEFINE_SIMPLE_CONVERSION_FUNCTIONS(ModuleProvider,     LLVMModuleProviderRef)
917   DEFINE_SIMPLE_CONVERSION_FUNCTIONS(MemoryBuffer,       LLVMMemoryBufferRef  )
918   DEFINE_SIMPLE_CONVERSION_FUNCTIONS(LLVMContext,        LLVMContextRef       )
919   DEFINE_STDCXX_CONVERSION_FUNCTIONS(PassManagerBase,    LLVMPassManagerRef   )
920   
921   #undef DEFINE_STDCXX_CONVERSION_FUNCTIONS
922   #undef DEFINE_ISA_CONVERSION_FUNCTIONS
923   #undef DEFINE_SIMPLE_CONVERSION_FUNCTIONS
924
925   /* Specialized opaque context conversions.
926    */
927   inline LLVMContext **unwrap(LLVMContextRef* Tys) {
928     return reinterpret_cast<LLVMContext**>(Tys);
929   }
930   
931   inline LLVMContextRef *wrap(const LLVMContext **Tys) {
932     return reinterpret_cast<LLVMContextRef*>(const_cast<LLVMContext**>(Tys));
933   }
934   
935   /* Specialized opaque type conversions.
936    */
937   inline Type **unwrap(LLVMTypeRef* Tys) {
938     return reinterpret_cast<Type**>(Tys);
939   }
940   
941   inline LLVMTypeRef *wrap(const Type **Tys) {
942     return reinterpret_cast<LLVMTypeRef*>(const_cast<Type**>(Tys));
943   }
944   
945   /* Specialized opaque value conversions.
946    */ 
947   inline Value **unwrap(LLVMValueRef *Vals) {
948     return reinterpret_cast<Value**>(Vals);
949   }
950   
951   template<typename T>
952   inline T **unwrap(LLVMValueRef *Vals, unsigned Length) {
953     #if DEBUG
954     for (LLVMValueRef *I = Vals, *E = Vals + Length; I != E; ++I)
955       cast<T>(*I);
956     #endif
957     return reinterpret_cast<T**>(Vals);
958   }
959   
960   inline LLVMValueRef *wrap(const Value **Vals) {
961     return reinterpret_cast<LLVMValueRef*>(const_cast<Value**>(Vals));
962   }
963 }
964
965 #endif /* !defined(__cplusplus) */
966
967 #endif /* !defined(LLVM_C_CORE_H) */