Core.h revision 204792
168349Sobrien/*===-- llvm-c/Core.h - Core Library C Interface ------------------*- C -*-===*\
2133359Sobrien|*                                                                            *|
3133359Sobrien|*                     The LLVM Compiler Infrastructure                       *|
4133359Sobrien|*                                                                            *|
5133359Sobrien|* This file is distributed under the University of Illinois Open Source      *|
6133359Sobrien|* License. See LICENSE.TXT for details.                                      *|
7133359Sobrien|*                                                                            *|
8133359Sobrien|*===----------------------------------------------------------------------===*|
9133359Sobrien|*                                                                            *|
10133359Sobrien|* This header declares the C interface to libLLVMCore.a, which implements    *|
11133359Sobrien|* the LLVM intermediate representation.                                      *|
12133359Sobrien|*                                                                            *|
13133359Sobrien|* LLVM uses a polymorphic type hierarchy which C cannot represent, therefore *|
14133359Sobrien|* parameters must be passed as base types. Despite the declared types, most  *|
15133359Sobrien|* of the functions provided operate only on branches of the type hierarchy.  *|
16133359Sobrien|* The declared parameter names are descriptive and specify which type is     *|
17133359Sobrien|* required. Additionally, each type hierarchy is documented along with the   *|
18133359Sobrien|* functions that operate upon it. For more detail, refer to LLVM's C++ code. *|
19133359Sobrien|* If in doubt, refer to Core.cpp, which performs paramter downcasts in the   *|
20133359Sobrien|* form unwrap<RequiredType>(Param).                                          *|
21133359Sobrien|*                                                                            *|
22133359Sobrien|* Many exotic languages can interoperate with C code but have a harder time  *|
23133359Sobrien|* with C++ due to name mangling. So in addition to C, this interface enables *|
24133359Sobrien|* tools written in such languages.                                           *|
25133359Sobrien|*                                                                            *|
26133359Sobrien|* When included into a C++ source file, also declares 'wrap' and 'unwrap'    *|
27133359Sobrien|* helpers to perform opaque reference<-->pointer conversions. These helpers  *|
28133359Sobrien|* are shorter and more tightly typed than writing the casts by hand when     *|
2968349Sobrien|* authoring bindings. In assert builds, they will do runtime type checking.  *|
30139368Sobrien|*                                                                            *|
3168349Sobrien\*===----------------------------------------------------------------------===*/
3268349Sobrien
3368349Sobrien#ifndef LLVM_C_CORE_H
3468349Sobrien#define LLVM_C_CORE_H
3568349Sobrien
3668349Sobrien#include "llvm/System/DataTypes.h"
3768349Sobrien
3868349Sobrien#ifdef __cplusplus
3968349Sobrien
40133359Sobrien/* Need these includes to support the LLVM 'cast' template for the C++ 'wrap'
41103373Sobrien   and 'unwrap' conversion functions. */
42103373Sobrien#include "llvm/Module.h"
43103373Sobrien#include "llvm/Support/IRBuilder.h"
44133359Sobrien
45133359Sobrienextern "C" {
46110949Sobrien#endif
47103373Sobrien
48103373Sobrien
49103373Sobrientypedef int LLVMBool;
5068349Sobrien
51133359Sobrien/* Opaque types. */
52133359Sobrien
53133359Sobrien/**
54133359Sobrien * The top-level container for all LLVM global data.  See the LLVMContext class.
55133359Sobrien */
56133359Sobrientypedef struct LLVMOpaqueContext *LLVMContextRef;
57133359Sobrien
58133359Sobrien/**
59133359Sobrien * The top-level container for all other LLVM Intermediate Representation (IR)
60133359Sobrien * objects. See the llvm::Module class.
61133359Sobrien */
62133359Sobrientypedef struct LLVMOpaqueModule *LLVMModuleRef;
63133359Sobrien
64133359Sobrien/**
65133359Sobrien * Each value in the LLVM IR has a type, an LLVMTypeRef. See the llvm::Type
66133359Sobrien * class.
6768349Sobrien */
68103373Sobrientypedef struct LLVMOpaqueType *LLVMTypeRef;
6968349Sobrien
70103373Sobrien/**
71133359Sobrien * When building recursive types using LLVMRefineType, LLVMTypeRef values may
7268349Sobrien * become invalid; use LLVMTypeHandleRef to resolve this problem. See the
7368349Sobrien * llvm::AbstractTypeHolder class.
7474784Sobrien */
75133359Sobrientypedef struct LLVMOpaqueTypeHandle *LLVMTypeHandleRef;
76133359Sobrien
7774784Sobrientypedef struct LLVMOpaqueValue *LLVMValueRef;
78133359Sobrientypedef struct LLVMOpaqueBasicBlock *LLVMBasicBlockRef;
79133359Sobrientypedef struct LLVMOpaqueBuilder *LLVMBuilderRef;
80133359Sobrien
8174784Sobrien/* Interface used to provide a module to JIT or interpreter.  This is now just a
8268349Sobrien * synonym for llvm::Module, but we have to keep using the different type to
83133359Sobrien * keep binary compatibility.
84103373Sobrien */
85103373Sobrientypedef struct LLVMOpaqueModuleProvider *LLVMModuleProviderRef;
86103373Sobrien
8768349Sobrien/* Used to provide a module to JIT or interpreter.
8868349Sobrien * See the llvm::MemoryBuffer class.
8980588Sobrien */
90133359Sobrientypedef struct LLVMOpaqueMemoryBuffer *LLVMMemoryBufferRef;
91103373Sobrien
92103373Sobrien/** See the llvm::PassManagerBase class. */
93103373Sobrientypedef struct LLVMOpaquePassManager *LLVMPassManagerRef;
94103373Sobrien
95133359Sobrien/** Used to get the users and usees of a Value. See the llvm::Use class. */
96133359Sobrientypedef struct LLVMOpaqueUse *LLVMUseRef;
97133359Sobrien
98133359Sobrientypedef enum {
99133359Sobrien    LLVMZExtAttribute       = 1<<0,
100133359Sobrien    LLVMSExtAttribute       = 1<<1,
101133359Sobrien    LLVMNoReturnAttribute   = 1<<2,
102133359Sobrien    LLVMInRegAttribute      = 1<<3,
103133359Sobrien    LLVMStructRetAttribute  = 1<<4,
104133359Sobrien    LLVMNoUnwindAttribute   = 1<<5,
105133359Sobrien    LLVMNoAliasAttribute    = 1<<6,
106133359Sobrien    LLVMByValAttribute      = 1<<7,
107133359Sobrien    LLVMNestAttribute       = 1<<8,
108133359Sobrien    LLVMReadNoneAttribute   = 1<<9,
109133359Sobrien    LLVMReadOnlyAttribute   = 1<<10,
110133359Sobrien    LLVMNoInlineAttribute   = 1<<11,
111139368Sobrien    LLVMAlwaysInlineAttribute    = 1<<12,
112139368Sobrien    LLVMOptimizeForSizeAttribute = 1<<13,
113133359Sobrien    LLVMStackProtectAttribute    = 1<<14,
114133359Sobrien    LLVMStackProtectReqAttribute = 1<<15,
115133359Sobrien    LLVMAlignment = 31<<16,
116133359Sobrien    LLVMNoCaptureAttribute  = 1<<21,
117133359Sobrien    LLVMNoRedZoneAttribute  = 1<<22,
118133359Sobrien    LLVMNoImplicitFloatAttribute = 1<<23,
119133359Sobrien    LLVMNakedAttribute      = 1<<24,
120133359Sobrien    LLVMInlineHintAttribute = 1<<25,
121133359Sobrien    LLVMStackAlignment = 7<<26
122133359Sobrien} LLVMAttribute;
123133359Sobrien
124133359Sobrientypedef enum {
125133359Sobrien  /* Terminator Instructions */
126133359Sobrien  LLVMRet            = 1,
127133359Sobrien  LLVMBr             = 2,
128133359Sobrien  LLVMSwitch         = 3,
129133359Sobrien  LLVMIndirectBr     = 4,
130133359Sobrien  LLVMInvoke         = 5,
131133359Sobrien  LLVMUnwind         = 6,
132139368Sobrien  LLVMUnreachable    = 7,
133139368Sobrien
134139368Sobrien  /* Standard Binary Operators */
135133359Sobrien  LLVMAdd            = 8,
136133359Sobrien  LLVMFAdd           = 9,
137133359Sobrien  LLVMSub            = 10,
138133359Sobrien  LLVMFSub           = 11,
139133359Sobrien  LLVMMul            = 12,
140133359Sobrien  LLVMFMul           = 13,
141133359Sobrien  LLVMUDiv           = 14,
142133359Sobrien  LLVMSDiv           = 15,
143133359Sobrien  LLVMFDiv           = 16,
144133359Sobrien  LLVMURem           = 17,
145133359Sobrien  LLVMSRem           = 18,
146133359Sobrien  LLVMFRem           = 19,
147133359Sobrien
148133359Sobrien  /* Logical Operators */
149133359Sobrien  LLVMShl            = 20,
150133359Sobrien  LLVMLShr           = 21,
151133359Sobrien  LLVMAShr           = 22,
152133359Sobrien  LLVMAnd            = 23,
153133359Sobrien  LLVMOr             = 24,
154133359Sobrien  LLVMXor            = 25,
155133359Sobrien
156133359Sobrien  /* Memory Operators */
157139368Sobrien  LLVMAlloca         = 26,
158139368Sobrien  LLVMLoad           = 27,
159139368Sobrien  LLVMStore          = 28,
160133359Sobrien  LLVMGetElementPtr  = 29,
161133359Sobrien
162103373Sobrien  /* Cast Operators */
163103373Sobrien  LLVMTrunc          = 30,
164133359Sobrien  LLVMZExt           = 31,
165133359Sobrien  LLVMSExt           = 32,
166133359Sobrien  LLVMFPToUI         = 33,
167133359Sobrien  LLVMFPToSI         = 34,
168133359Sobrien  LLVMUIToFP         = 35,
169133359Sobrien  LLVMSIToFP         = 36,
170133359Sobrien  LLVMFPTrunc        = 37,
171133359Sobrien  LLVMFPExt          = 38,
172133359Sobrien  LLVMPtrToInt       = 39,
173133359Sobrien  LLVMIntToPtr       = 40,
174133359Sobrien  LLVMBitCast        = 41,
175133359Sobrien
176133359Sobrien  /* Other Operators */
177133359Sobrien  LLVMICmp           = 42,
178133359Sobrien  LLVMFCmp           = 43,
179133359Sobrien  LLVMPHI            = 44,
180133359Sobrien  LLVMCall           = 45,
181133359Sobrien  LLVMSelect         = 46,
182133359Sobrien  /* UserOp1 */
183133359Sobrien  /* UserOp2 */
184133359Sobrien  LLVMVAArg          = 49,
185133359Sobrien  LLVMExtractElement = 50,
186133359Sobrien  LLVMInsertElement  = 51,
18768349Sobrien  LLVMShuffleVector  = 52,
188103373Sobrien  LLVMExtractValue   = 53,
189103373Sobrien  LLVMInsertValue    = 54
190103373Sobrien} LLVMOpcode;
19168349Sobrien
192103373Sobrientypedef enum {
193103373Sobrien  LLVMVoidTypeKind,        /**< type with no size */
194103373Sobrien  LLVMFloatTypeKind,       /**< 32 bit floating point type */
19568349Sobrien  LLVMDoubleTypeKind,      /**< 64 bit floating point type */
196133359Sobrien  LLVMX86_FP80TypeKind,    /**< 80 bit floating point type (X87) */
19768349Sobrien  LLVMFP128TypeKind,       /**< 128 bit floating point type (112-bit mantissa)*/
198133359Sobrien  LLVMPPC_FP128TypeKind,   /**< 128 bit floating point type (two 64-bits) */
19968349Sobrien  LLVMLabelTypeKind,       /**< Labels */
20068349Sobrien  LLVMIntegerTypeKind,     /**< Arbitrary bit width integers */
20168349Sobrien  LLVMFunctionTypeKind,    /**< Functions */
20268349Sobrien  LLVMStructTypeKind,      /**< Structures */
20368349Sobrien  LLVMArrayTypeKind,       /**< Arrays */
20468349Sobrien  LLVMPointerTypeKind,     /**< Pointers */
20568349Sobrien  LLVMOpaqueTypeKind,      /**< Opaque: type with unknown structure */
20668349Sobrien  LLVMVectorTypeKind,      /**< SIMD 'packed' format, or other vector type */
20768349Sobrien  LLVMMetadataTypeKind,    /**< Metadata */
20868349Sobrien  LLVMUnionTypeKind        /**< Unions */
20974784Sobrien} LLVMTypeKind;
21074784Sobrien
21174784Sobrientypedef enum {
212133359Sobrien  LLVMExternalLinkage,    /**< Externally visible function */
213133359Sobrien  LLVMAvailableExternallyLinkage,
214133359Sobrien  LLVMLinkOnceAnyLinkage, /**< Keep one copy of function when linking (inline)*/
215133359Sobrien  LLVMLinkOnceODRLinkage, /**< Same, but only replaced by something
21674784Sobrien                            equivalent. */
21774784Sobrien  LLVMWeakAnyLinkage,     /**< Keep one copy of function when linking (weak) */
21874784Sobrien  LLVMWeakODRLinkage,     /**< Same, but only replaced by something
219133359Sobrien                            equivalent. */
220133359Sobrien  LLVMAppendingLinkage,   /**< Special purpose, only applies to global arrays */
221133359Sobrien  LLVMInternalLinkage,    /**< Rename collisions when linking (static
222133359Sobrien                               functions) */
223133359Sobrien  LLVMPrivateLinkage,     /**< Like Internal, but omit from symbol table */
224133359Sobrien  LLVMDLLImportLinkage,   /**< Function to be imported from DLL */
225133359Sobrien  LLVMDLLExportLinkage,   /**< Function to be accessible from DLL */
226133359Sobrien  LLVMExternalWeakLinkage,/**< ExternalWeak linkage description */
227133359Sobrien  LLVMGhostLinkage,       /**< Obsolete */
228133359Sobrien  LLVMCommonLinkage,      /**< Tentative definitions */
229133359Sobrien  LLVMLinkerPrivateLinkage /**< Like Private, but linker removes. */
230133359Sobrien} LLVMLinkage;
231133359Sobrien
232133359Sobrientypedef enum {
233133359Sobrien  LLVMDefaultVisibility,  /**< The GV is visible */
234133359Sobrien  LLVMHiddenVisibility,   /**< The GV is hidden */
235133359Sobrien  LLVMProtectedVisibility /**< The GV is protected */
236133359Sobrien} LLVMVisibility;
237133359Sobrien
238139368Sobrientypedef enum {
239139368Sobrien  LLVMCCallConv           = 0,
240133359Sobrien  LLVMFastCallConv        = 8,
241133359Sobrien  LLVMColdCallConv        = 9,
242103373Sobrien  LLVMX86StdcallCallConv  = 64,
243133359Sobrien  LLVMX86FastcallCallConv = 65
244133359Sobrien} LLVMCallConv;
245133359Sobrien
246133359Sobrientypedef enum {
247133359Sobrien  LLVMIntEQ = 32, /**< equal */
248133359Sobrien  LLVMIntNE,      /**< not equal */
249133359Sobrien  LLVMIntUGT,     /**< unsigned greater than */
250133359Sobrien  LLVMIntUGE,     /**< unsigned greater or equal */
251133359Sobrien  LLVMIntULT,     /**< unsigned less than */
252133359Sobrien  LLVMIntULE,     /**< unsigned less or equal */
253133359Sobrien  LLVMIntSGT,     /**< signed greater than */
254133359Sobrien  LLVMIntSGE,     /**< signed greater or equal */
255133359Sobrien  LLVMIntSLT,     /**< signed less than */
256133359Sobrien  LLVMIntSLE      /**< signed less or equal */
257133359Sobrien} LLVMIntPredicate;
258133359Sobrien
259133359Sobrientypedef enum {
260133359Sobrien  LLVMRealPredicateFalse, /**< Always false (always folded) */
261139368Sobrien  LLVMRealOEQ,            /**< True if ordered and equal */
262133359Sobrien  LLVMRealOGT,            /**< True if ordered and greater than */
263133359Sobrien  LLVMRealOGE,            /**< True if ordered and greater than or equal */
264133359Sobrien  LLVMRealOLT,            /**< True if ordered and less than */
265133359Sobrien  LLVMRealOLE,            /**< True if ordered and less than or equal */
26668349Sobrien  LLVMRealONE,            /**< True if ordered and operands are unequal */
26768349Sobrien  LLVMRealORD,            /**< True if ordered (no nans) */
26868349Sobrien  LLVMRealUNO,            /**< True if unordered: isnan(X) | isnan(Y) */
26968349Sobrien  LLVMRealUEQ,            /**< True if unordered or equal */
27068349Sobrien  LLVMRealUGT,            /**< True if unordered or greater than */
27168349Sobrien  LLVMRealUGE,            /**< True if unordered, greater than, or equal */
27268349Sobrien  LLVMRealULT,            /**< True if unordered or less than */
27368349Sobrien  LLVMRealULE,            /**< True if unordered, less than, or equal */
27468349Sobrien  LLVMRealUNE,            /**< True if unordered or not equal */
27568349Sobrien  LLVMRealPredicateTrue   /**< Always true (always folded) */
27668349Sobrien} LLVMRealPredicate;
27768349Sobrien
27880588Sobrien
27980588Sobrien/*===-- Error handling ----------------------------------------------------===*/
28080588Sobrien
28180588Sobrienvoid LLVMDisposeMessage(char *Message);
28268349Sobrien
28368349Sobrien
28468349Sobrien/*===-- Contexts ----------------------------------------------------------===*/
28568349Sobrien
286133359Sobrien/* Create and destroy contexts. */
28768349SobrienLLVMContextRef LLVMContextCreate(void);
28868349SobrienLLVMContextRef LLVMGetGlobalContext(void);
289void LLVMContextDispose(LLVMContextRef C);
290
291unsigned LLVMGetMDKindIDInContext(LLVMContextRef C, const char* Name,
292                                  unsigned SLen);
293unsigned LLVMGetMDKindID(const char* Name, unsigned SLen);
294
295/*===-- Modules -----------------------------------------------------------===*/
296
297/* Create and destroy modules. */
298/** See llvm::Module::Module. */
299LLVMModuleRef LLVMModuleCreateWithName(const char *ModuleID);
300LLVMModuleRef LLVMModuleCreateWithNameInContext(const char *ModuleID,
301                                                LLVMContextRef C);
302
303/** See llvm::Module::~Module. */
304void LLVMDisposeModule(LLVMModuleRef M);
305
306/** Data layout. See Module::getDataLayout. */
307const char *LLVMGetDataLayout(LLVMModuleRef M);
308void LLVMSetDataLayout(LLVMModuleRef M, const char *Triple);
309
310/** Target triple. See Module::getTargetTriple. */
311const char *LLVMGetTarget(LLVMModuleRef M);
312void LLVMSetTarget(LLVMModuleRef M, const char *Triple);
313
314/** See Module::addTypeName. */
315LLVMBool LLVMAddTypeName(LLVMModuleRef M, const char *Name, LLVMTypeRef Ty);
316void LLVMDeleteTypeName(LLVMModuleRef M, const char *Name);
317LLVMTypeRef LLVMGetTypeByName(LLVMModuleRef M, const char *Name);
318
319/** See Module::dump. */
320void LLVMDumpModule(LLVMModuleRef M);
321
322
323/*===-- Types -------------------------------------------------------------===*/
324
325/* LLVM types conform to the following hierarchy:
326 *
327 *   types:
328 *     integer type
329 *     real type
330 *     function type
331 *     sequence types:
332 *       array type
333 *       pointer type
334 *       vector type
335 *     void type
336 *     label type
337 *     opaque type
338 */
339
340/** See llvm::LLVMTypeKind::getTypeID. */
341LLVMTypeKind LLVMGetTypeKind(LLVMTypeRef Ty);
342
343/** See llvm::LLVMType::getContext. */
344LLVMContextRef LLVMGetTypeContext(LLVMTypeRef Ty);
345
346/* Operations on integer types */
347LLVMTypeRef LLVMInt1TypeInContext(LLVMContextRef C);
348LLVMTypeRef LLVMInt8TypeInContext(LLVMContextRef C);
349LLVMTypeRef LLVMInt16TypeInContext(LLVMContextRef C);
350LLVMTypeRef LLVMInt32TypeInContext(LLVMContextRef C);
351LLVMTypeRef LLVMInt64TypeInContext(LLVMContextRef C);
352LLVMTypeRef LLVMIntTypeInContext(LLVMContextRef C, unsigned NumBits);
353
354LLVMTypeRef LLVMInt1Type(void);
355LLVMTypeRef LLVMInt8Type(void);
356LLVMTypeRef LLVMInt16Type(void);
357LLVMTypeRef LLVMInt32Type(void);
358LLVMTypeRef LLVMInt64Type(void);
359LLVMTypeRef LLVMIntType(unsigned NumBits);
360unsigned LLVMGetIntTypeWidth(LLVMTypeRef IntegerTy);
361
362/* Operations on real types */
363LLVMTypeRef LLVMFloatTypeInContext(LLVMContextRef C);
364LLVMTypeRef LLVMDoubleTypeInContext(LLVMContextRef C);
365LLVMTypeRef LLVMX86FP80TypeInContext(LLVMContextRef C);
366LLVMTypeRef LLVMFP128TypeInContext(LLVMContextRef C);
367LLVMTypeRef LLVMPPCFP128TypeInContext(LLVMContextRef C);
368
369LLVMTypeRef LLVMFloatType(void);
370LLVMTypeRef LLVMDoubleType(void);
371LLVMTypeRef LLVMX86FP80Type(void);
372LLVMTypeRef LLVMFP128Type(void);
373LLVMTypeRef LLVMPPCFP128Type(void);
374
375/* Operations on function types */
376LLVMTypeRef LLVMFunctionType(LLVMTypeRef ReturnType,
377                             LLVMTypeRef *ParamTypes, unsigned ParamCount,
378                             LLVMBool IsVarArg);
379LLVMBool LLVMIsFunctionVarArg(LLVMTypeRef FunctionTy);
380LLVMTypeRef LLVMGetReturnType(LLVMTypeRef FunctionTy);
381unsigned LLVMCountParamTypes(LLVMTypeRef FunctionTy);
382void LLVMGetParamTypes(LLVMTypeRef FunctionTy, LLVMTypeRef *Dest);
383
384/* Operations on struct types */
385LLVMTypeRef LLVMStructTypeInContext(LLVMContextRef C, LLVMTypeRef *ElementTypes,
386                                    unsigned ElementCount, LLVMBool Packed);
387LLVMTypeRef LLVMStructType(LLVMTypeRef *ElementTypes, unsigned ElementCount,
388                           LLVMBool Packed);
389unsigned LLVMCountStructElementTypes(LLVMTypeRef StructTy);
390void LLVMGetStructElementTypes(LLVMTypeRef StructTy, LLVMTypeRef *Dest);
391LLVMBool LLVMIsPackedStruct(LLVMTypeRef StructTy);
392
393/* Operations on union types */
394LLVMTypeRef LLVMUnionTypeInContext(LLVMContextRef C, LLVMTypeRef *ElementTypes,
395                                   unsigned ElementCount);
396LLVMTypeRef LLVMUnionType(LLVMTypeRef *ElementTypes, unsigned ElementCount);
397unsigned LLVMCountUnionElementTypes(LLVMTypeRef UnionTy);
398void LLVMGetUnionElementTypes(LLVMTypeRef UnionTy, LLVMTypeRef *Dest);
399
400/* Operations on array, pointer, and vector types (sequence types) */
401LLVMTypeRef LLVMArrayType(LLVMTypeRef ElementType, unsigned ElementCount);
402LLVMTypeRef LLVMPointerType(LLVMTypeRef ElementType, unsigned AddressSpace);
403LLVMTypeRef LLVMVectorType(LLVMTypeRef ElementType, unsigned ElementCount);
404
405LLVMTypeRef LLVMGetElementType(LLVMTypeRef Ty);
406unsigned LLVMGetArrayLength(LLVMTypeRef ArrayTy);
407unsigned LLVMGetPointerAddressSpace(LLVMTypeRef PointerTy);
408unsigned LLVMGetVectorSize(LLVMTypeRef VectorTy);
409
410/* Operations on other types */
411LLVMTypeRef LLVMVoidTypeInContext(LLVMContextRef C);
412LLVMTypeRef LLVMLabelTypeInContext(LLVMContextRef C);
413LLVMTypeRef LLVMOpaqueTypeInContext(LLVMContextRef C);
414
415LLVMTypeRef LLVMVoidType(void);
416LLVMTypeRef LLVMLabelType(void);
417LLVMTypeRef LLVMOpaqueType(void);
418
419/* Operations on type handles */
420LLVMTypeHandleRef LLVMCreateTypeHandle(LLVMTypeRef PotentiallyAbstractTy);
421void LLVMRefineType(LLVMTypeRef AbstractTy, LLVMTypeRef ConcreteTy);
422LLVMTypeRef LLVMResolveTypeHandle(LLVMTypeHandleRef TypeHandle);
423void LLVMDisposeTypeHandle(LLVMTypeHandleRef TypeHandle);
424
425
426/*===-- Values ------------------------------------------------------------===*/
427
428/* The bulk of LLVM's object model consists of values, which comprise a very
429 * rich type hierarchy.
430 */
431
432#define LLVM_FOR_EACH_VALUE_SUBCLASS(macro) \
433  macro(Argument)                           \
434  macro(BasicBlock)                         \
435  macro(InlineAsm)                          \
436  macro(User)                               \
437    macro(Constant)                         \
438      macro(ConstantAggregateZero)          \
439      macro(ConstantArray)                  \
440      macro(ConstantExpr)                   \
441      macro(ConstantFP)                     \
442      macro(ConstantInt)                    \
443      macro(ConstantPointerNull)            \
444      macro(ConstantStruct)                 \
445      macro(ConstantVector)                 \
446      macro(GlobalValue)                    \
447        macro(Function)                     \
448        macro(GlobalAlias)                  \
449        macro(GlobalVariable)               \
450      macro(UndefValue)                     \
451    macro(Instruction)                      \
452      macro(BinaryOperator)                 \
453      macro(CallInst)                       \
454        macro(IntrinsicInst)                \
455          macro(DbgInfoIntrinsic)           \
456            macro(DbgDeclareInst)           \
457          macro(EHSelectorInst)             \
458          macro(MemIntrinsic)               \
459            macro(MemCpyInst)               \
460            macro(MemMoveInst)              \
461            macro(MemSetInst)               \
462      macro(CmpInst)                        \
463      macro(FCmpInst)                       \
464      macro(ICmpInst)                       \
465      macro(ExtractElementInst)             \
466      macro(GetElementPtrInst)              \
467      macro(InsertElementInst)              \
468      macro(InsertValueInst)                \
469      macro(PHINode)                        \
470      macro(SelectInst)                     \
471      macro(ShuffleVectorInst)              \
472      macro(StoreInst)                      \
473      macro(TerminatorInst)                 \
474        macro(BranchInst)                   \
475        macro(InvokeInst)                   \
476        macro(ReturnInst)                   \
477        macro(SwitchInst)                   \
478        macro(UnreachableInst)              \
479        macro(UnwindInst)                   \
480    macro(UnaryInstruction)                 \
481      macro(AllocaInst)                     \
482      macro(CastInst)                       \
483        macro(BitCastInst)                  \
484        macro(FPExtInst)                    \
485        macro(FPToSIInst)                   \
486        macro(FPToUIInst)                   \
487        macro(FPTruncInst)                  \
488        macro(IntToPtrInst)                 \
489        macro(PtrToIntInst)                 \
490        macro(SExtInst)                     \
491        macro(SIToFPInst)                   \
492        macro(TruncInst)                    \
493        macro(UIToFPInst)                   \
494        macro(ZExtInst)                     \
495      macro(ExtractValueInst)               \
496      macro(LoadInst)                       \
497      macro(VAArgInst)
498
499/* Operations on all values */
500LLVMTypeRef LLVMTypeOf(LLVMValueRef Val);
501const char *LLVMGetValueName(LLVMValueRef Val);
502void LLVMSetValueName(LLVMValueRef Val, const char *Name);
503void LLVMDumpValue(LLVMValueRef Val);
504void LLVMReplaceAllUsesWith(LLVMValueRef OldVal, LLVMValueRef NewVal);
505int LLVMHasMetadata(LLVMValueRef Val);
506LLVMValueRef LLVMGetMetadata(LLVMValueRef Val, unsigned KindID);
507void LLVMSetMetadata(LLVMValueRef Val, unsigned KindID, LLVMValueRef Node);
508
509/* Conversion functions. Return the input value if it is an instance of the
510   specified class, otherwise NULL. See llvm::dyn_cast_or_null<>. */
511#define LLVM_DECLARE_VALUE_CAST(name) \
512  LLVMValueRef LLVMIsA##name(LLVMValueRef Val);
513LLVM_FOR_EACH_VALUE_SUBCLASS(LLVM_DECLARE_VALUE_CAST)
514
515/* Operations on Uses */
516LLVMUseRef LLVMGetFirstUse(LLVMValueRef Val);
517LLVMUseRef LLVMGetNextUse(LLVMUseRef U);
518LLVMValueRef LLVMGetUser(LLVMUseRef U);
519LLVMValueRef LLVMGetUsedValue(LLVMUseRef U);
520
521/* Operations on Users */
522LLVMValueRef LLVMGetOperand(LLVMValueRef Val, unsigned Index);
523
524/* Operations on constants of any type */
525LLVMValueRef LLVMConstNull(LLVMTypeRef Ty); /* all zeroes */
526LLVMValueRef LLVMConstAllOnes(LLVMTypeRef Ty); /* only for int/vector */
527LLVMValueRef LLVMGetUndef(LLVMTypeRef Ty);
528LLVMBool LLVMIsConstant(LLVMValueRef Val);
529LLVMBool LLVMIsNull(LLVMValueRef Val);
530LLVMBool LLVMIsUndef(LLVMValueRef Val);
531LLVMValueRef LLVMConstPointerNull(LLVMTypeRef Ty);
532
533/* Operations on metadata */
534LLVMValueRef LLVMMDStringInContext(LLVMContextRef C, const char *Str,
535                                   unsigned SLen);
536LLVMValueRef LLVMMDString(const char *Str, unsigned SLen);
537LLVMValueRef LLVMMDNodeInContext(LLVMContextRef C, LLVMValueRef *Vals,
538                                 unsigned Count);
539LLVMValueRef LLVMMDNode(LLVMValueRef *Vals, unsigned Count);
540
541/* Operations on scalar constants */
542LLVMValueRef LLVMConstInt(LLVMTypeRef IntTy, unsigned long long N,
543                          LLVMBool SignExtend);
544LLVMValueRef LLVMConstIntOfString(LLVMTypeRef IntTy, const char *Text,
545                                  uint8_t Radix);
546LLVMValueRef LLVMConstIntOfStringAndSize(LLVMTypeRef IntTy, const char *Text,
547                                         unsigned SLen, uint8_t Radix);
548LLVMValueRef LLVMConstReal(LLVMTypeRef RealTy, double N);
549LLVMValueRef LLVMConstRealOfString(LLVMTypeRef RealTy, const char *Text);
550LLVMValueRef LLVMConstRealOfStringAndSize(LLVMTypeRef RealTy, const char *Text,
551                                          unsigned SLen);
552unsigned long long LLVMConstIntGetZExtValue(LLVMValueRef ConstantVal);
553long long LLVMConstIntGetSExtValue(LLVMValueRef ConstantVal);
554
555
556/* Operations on composite constants */
557LLVMValueRef LLVMConstStringInContext(LLVMContextRef C, const char *Str,
558                                      unsigned Length, LLVMBool DontNullTerminate);
559LLVMValueRef LLVMConstStructInContext(LLVMContextRef C,
560                                      LLVMValueRef *ConstantVals,
561                                      unsigned Count, LLVMBool Packed);
562
563LLVMValueRef LLVMConstString(const char *Str, unsigned Length,
564                             LLVMBool DontNullTerminate);
565LLVMValueRef LLVMConstArray(LLVMTypeRef ElementTy,
566                            LLVMValueRef *ConstantVals, unsigned Length);
567LLVMValueRef LLVMConstStruct(LLVMValueRef *ConstantVals, unsigned Count,
568                             LLVMBool Packed);
569LLVMValueRef LLVMConstVector(LLVMValueRef *ScalarConstantVals, unsigned Size);
570LLVMValueRef LLVMConstUnion(LLVMTypeRef Ty, LLVMValueRef Val);
571
572/* Constant expressions */
573LLVMOpcode LLVMGetConstOpcode(LLVMValueRef ConstantVal);
574LLVMValueRef LLVMAlignOf(LLVMTypeRef Ty);
575LLVMValueRef LLVMSizeOf(LLVMTypeRef Ty);
576LLVMValueRef LLVMConstNeg(LLVMValueRef ConstantVal);
577LLVMValueRef LLVMConstNSWNeg(LLVMValueRef ConstantVal);
578LLVMValueRef LLVMConstNUWNeg(LLVMValueRef ConstantVal);
579LLVMValueRef LLVMConstFNeg(LLVMValueRef ConstantVal);
580LLVMValueRef LLVMConstNot(LLVMValueRef ConstantVal);
581LLVMValueRef LLVMConstAdd(LLVMValueRef LHSConstant, LLVMValueRef RHSConstant);
582LLVMValueRef LLVMConstNSWAdd(LLVMValueRef LHSConstant, LLVMValueRef RHSConstant);
583LLVMValueRef LLVMConstNUWAdd(LLVMValueRef LHSConstant, LLVMValueRef RHSConstant);
584LLVMValueRef LLVMConstFAdd(LLVMValueRef LHSConstant, LLVMValueRef RHSConstant);
585LLVMValueRef LLVMConstSub(LLVMValueRef LHSConstant, LLVMValueRef RHSConstant);
586LLVMValueRef LLVMConstNSWSub(LLVMValueRef LHSConstant, LLVMValueRef RHSConstant);
587LLVMValueRef LLVMConstNUWSub(LLVMValueRef LHSConstant, LLVMValueRef RHSConstant);
588LLVMValueRef LLVMConstFSub(LLVMValueRef LHSConstant, LLVMValueRef RHSConstant);
589LLVMValueRef LLVMConstMul(LLVMValueRef LHSConstant, LLVMValueRef RHSConstant);
590LLVMValueRef LLVMConstNSWMul(LLVMValueRef LHSConstant, LLVMValueRef RHSConstant);
591LLVMValueRef LLVMConstNUWMul(LLVMValueRef LHSConstant, LLVMValueRef RHSConstant);
592LLVMValueRef LLVMConstFMul(LLVMValueRef LHSConstant, LLVMValueRef RHSConstant);
593LLVMValueRef LLVMConstUDiv(LLVMValueRef LHSConstant, LLVMValueRef RHSConstant);
594LLVMValueRef LLVMConstSDiv(LLVMValueRef LHSConstant, LLVMValueRef RHSConstant);
595LLVMValueRef LLVMConstExactSDiv(LLVMValueRef LHSConstant, LLVMValueRef RHSConstant);
596LLVMValueRef LLVMConstFDiv(LLVMValueRef LHSConstant, LLVMValueRef RHSConstant);
597LLVMValueRef LLVMConstURem(LLVMValueRef LHSConstant, LLVMValueRef RHSConstant);
598LLVMValueRef LLVMConstSRem(LLVMValueRef LHSConstant, LLVMValueRef RHSConstant);
599LLVMValueRef LLVMConstFRem(LLVMValueRef LHSConstant, LLVMValueRef RHSConstant);
600LLVMValueRef LLVMConstAnd(LLVMValueRef LHSConstant, LLVMValueRef RHSConstant);
601LLVMValueRef LLVMConstOr(LLVMValueRef LHSConstant, LLVMValueRef RHSConstant);
602LLVMValueRef LLVMConstXor(LLVMValueRef LHSConstant, LLVMValueRef RHSConstant);
603LLVMValueRef LLVMConstICmp(LLVMIntPredicate Predicate,
604                           LLVMValueRef LHSConstant, LLVMValueRef RHSConstant);
605LLVMValueRef LLVMConstFCmp(LLVMRealPredicate Predicate,
606                           LLVMValueRef LHSConstant, LLVMValueRef RHSConstant);
607LLVMValueRef LLVMConstShl(LLVMValueRef LHSConstant, LLVMValueRef RHSConstant);
608LLVMValueRef LLVMConstLShr(LLVMValueRef LHSConstant, LLVMValueRef RHSConstant);
609LLVMValueRef LLVMConstAShr(LLVMValueRef LHSConstant, LLVMValueRef RHSConstant);
610LLVMValueRef LLVMConstGEP(LLVMValueRef ConstantVal,
611                          LLVMValueRef *ConstantIndices, unsigned NumIndices);
612LLVMValueRef LLVMConstInBoundsGEP(LLVMValueRef ConstantVal,
613                                  LLVMValueRef *ConstantIndices,
614                                  unsigned NumIndices);
615LLVMValueRef LLVMConstTrunc(LLVMValueRef ConstantVal, LLVMTypeRef ToType);
616LLVMValueRef LLVMConstSExt(LLVMValueRef ConstantVal, LLVMTypeRef ToType);
617LLVMValueRef LLVMConstZExt(LLVMValueRef ConstantVal, LLVMTypeRef ToType);
618LLVMValueRef LLVMConstFPTrunc(LLVMValueRef ConstantVal, LLVMTypeRef ToType);
619LLVMValueRef LLVMConstFPExt(LLVMValueRef ConstantVal, LLVMTypeRef ToType);
620LLVMValueRef LLVMConstUIToFP(LLVMValueRef ConstantVal, LLVMTypeRef ToType);
621LLVMValueRef LLVMConstSIToFP(LLVMValueRef ConstantVal, LLVMTypeRef ToType);
622LLVMValueRef LLVMConstFPToUI(LLVMValueRef ConstantVal, LLVMTypeRef ToType);
623LLVMValueRef LLVMConstFPToSI(LLVMValueRef ConstantVal, LLVMTypeRef ToType);
624LLVMValueRef LLVMConstPtrToInt(LLVMValueRef ConstantVal, LLVMTypeRef ToType);
625LLVMValueRef LLVMConstIntToPtr(LLVMValueRef ConstantVal, LLVMTypeRef ToType);
626LLVMValueRef LLVMConstBitCast(LLVMValueRef ConstantVal, LLVMTypeRef ToType);
627LLVMValueRef LLVMConstZExtOrBitCast(LLVMValueRef ConstantVal,
628                                    LLVMTypeRef ToType);
629LLVMValueRef LLVMConstSExtOrBitCast(LLVMValueRef ConstantVal,
630                                    LLVMTypeRef ToType);
631LLVMValueRef LLVMConstTruncOrBitCast(LLVMValueRef ConstantVal,
632                                     LLVMTypeRef ToType);
633LLVMValueRef LLVMConstPointerCast(LLVMValueRef ConstantVal,
634                                  LLVMTypeRef ToType);
635LLVMValueRef LLVMConstIntCast(LLVMValueRef ConstantVal, LLVMTypeRef ToType,
636                              LLVMBool isSigned);
637LLVMValueRef LLVMConstFPCast(LLVMValueRef ConstantVal, LLVMTypeRef ToType);
638LLVMValueRef LLVMConstSelect(LLVMValueRef ConstantCondition,
639                             LLVMValueRef ConstantIfTrue,
640                             LLVMValueRef ConstantIfFalse);
641LLVMValueRef LLVMConstExtractElement(LLVMValueRef VectorConstant,
642                                     LLVMValueRef IndexConstant);
643LLVMValueRef LLVMConstInsertElement(LLVMValueRef VectorConstant,
644                                    LLVMValueRef ElementValueConstant,
645                                    LLVMValueRef IndexConstant);
646LLVMValueRef LLVMConstShuffleVector(LLVMValueRef VectorAConstant,
647                                    LLVMValueRef VectorBConstant,
648                                    LLVMValueRef MaskConstant);
649LLVMValueRef LLVMConstExtractValue(LLVMValueRef AggConstant, unsigned *IdxList,
650                                   unsigned NumIdx);
651LLVMValueRef LLVMConstInsertValue(LLVMValueRef AggConstant,
652                                  LLVMValueRef ElementValueConstant,
653                                  unsigned *IdxList, unsigned NumIdx);
654LLVMValueRef LLVMConstInlineAsm(LLVMTypeRef Ty,
655                                const char *AsmString, const char *Constraints,
656                                LLVMBool HasSideEffects, LLVMBool IsAlignStack);
657LLVMValueRef LLVMBlockAddress(LLVMValueRef F, LLVMBasicBlockRef BB);
658
659/* Operations on global variables, functions, and aliases (globals) */
660LLVMModuleRef LLVMGetGlobalParent(LLVMValueRef Global);
661LLVMBool LLVMIsDeclaration(LLVMValueRef Global);
662LLVMLinkage LLVMGetLinkage(LLVMValueRef Global);
663void LLVMSetLinkage(LLVMValueRef Global, LLVMLinkage Linkage);
664const char *LLVMGetSection(LLVMValueRef Global);
665void LLVMSetSection(LLVMValueRef Global, const char *Section);
666LLVMVisibility LLVMGetVisibility(LLVMValueRef Global);
667void LLVMSetVisibility(LLVMValueRef Global, LLVMVisibility Viz);
668unsigned LLVMGetAlignment(LLVMValueRef Global);
669void LLVMSetAlignment(LLVMValueRef Global, unsigned Bytes);
670
671/* Operations on global variables */
672LLVMValueRef LLVMAddGlobal(LLVMModuleRef M, LLVMTypeRef Ty, const char *Name);
673LLVMValueRef LLVMAddGlobalInAddressSpace(LLVMModuleRef M, LLVMTypeRef Ty,
674                                         const char *Name,
675                                         unsigned AddressSpace);
676LLVMValueRef LLVMGetNamedGlobal(LLVMModuleRef M, const char *Name);
677LLVMValueRef LLVMGetFirstGlobal(LLVMModuleRef M);
678LLVMValueRef LLVMGetLastGlobal(LLVMModuleRef M);
679LLVMValueRef LLVMGetNextGlobal(LLVMValueRef GlobalVar);
680LLVMValueRef LLVMGetPreviousGlobal(LLVMValueRef GlobalVar);
681void LLVMDeleteGlobal(LLVMValueRef GlobalVar);
682LLVMValueRef LLVMGetInitializer(LLVMValueRef GlobalVar);
683void LLVMSetInitializer(LLVMValueRef GlobalVar, LLVMValueRef ConstantVal);
684LLVMBool LLVMIsThreadLocal(LLVMValueRef GlobalVar);
685void LLVMSetThreadLocal(LLVMValueRef GlobalVar, LLVMBool IsThreadLocal);
686LLVMBool LLVMIsGlobalConstant(LLVMValueRef GlobalVar);
687void LLVMSetGlobalConstant(LLVMValueRef GlobalVar, LLVMBool IsConstant);
688
689/* Operations on aliases */
690LLVMValueRef LLVMAddAlias(LLVMModuleRef M, LLVMTypeRef Ty, LLVMValueRef Aliasee,
691                          const char *Name);
692
693/* Operations on functions */
694LLVMValueRef LLVMAddFunction(LLVMModuleRef M, const char *Name,
695                             LLVMTypeRef FunctionTy);
696LLVMValueRef LLVMGetNamedFunction(LLVMModuleRef M, const char *Name);
697LLVMValueRef LLVMGetFirstFunction(LLVMModuleRef M);
698LLVMValueRef LLVMGetLastFunction(LLVMModuleRef M);
699LLVMValueRef LLVMGetNextFunction(LLVMValueRef Fn);
700LLVMValueRef LLVMGetPreviousFunction(LLVMValueRef Fn);
701void LLVMDeleteFunction(LLVMValueRef Fn);
702unsigned LLVMGetIntrinsicID(LLVMValueRef Fn);
703unsigned LLVMGetFunctionCallConv(LLVMValueRef Fn);
704void LLVMSetFunctionCallConv(LLVMValueRef Fn, unsigned CC);
705const char *LLVMGetGC(LLVMValueRef Fn);
706void LLVMSetGC(LLVMValueRef Fn, const char *Name);
707void LLVMAddFunctionAttr(LLVMValueRef Fn, LLVMAttribute PA);
708LLVMAttribute LLVMGetFunctionAttr(LLVMValueRef Fn);
709void LLVMRemoveFunctionAttr(LLVMValueRef Fn, LLVMAttribute PA);
710
711/* Operations on parameters */
712unsigned LLVMCountParams(LLVMValueRef Fn);
713void LLVMGetParams(LLVMValueRef Fn, LLVMValueRef *Params);
714LLVMValueRef LLVMGetParam(LLVMValueRef Fn, unsigned Index);
715LLVMValueRef LLVMGetParamParent(LLVMValueRef Inst);
716LLVMValueRef LLVMGetFirstParam(LLVMValueRef Fn);
717LLVMValueRef LLVMGetLastParam(LLVMValueRef Fn);
718LLVMValueRef LLVMGetNextParam(LLVMValueRef Arg);
719LLVMValueRef LLVMGetPreviousParam(LLVMValueRef Arg);
720void LLVMAddAttribute(LLVMValueRef Arg, LLVMAttribute PA);
721void LLVMRemoveAttribute(LLVMValueRef Arg, LLVMAttribute PA);
722LLVMAttribute LLVMGetAttribute(LLVMValueRef Arg);
723void LLVMSetParamAlignment(LLVMValueRef Arg, unsigned align);
724
725/* Operations on basic blocks */
726LLVMValueRef LLVMBasicBlockAsValue(LLVMBasicBlockRef BB);
727LLVMBool LLVMValueIsBasicBlock(LLVMValueRef Val);
728LLVMBasicBlockRef LLVMValueAsBasicBlock(LLVMValueRef Val);
729LLVMValueRef LLVMGetBasicBlockParent(LLVMBasicBlockRef BB);
730unsigned LLVMCountBasicBlocks(LLVMValueRef Fn);
731void LLVMGetBasicBlocks(LLVMValueRef Fn, LLVMBasicBlockRef *BasicBlocks);
732LLVMBasicBlockRef LLVMGetFirstBasicBlock(LLVMValueRef Fn);
733LLVMBasicBlockRef LLVMGetLastBasicBlock(LLVMValueRef Fn);
734LLVMBasicBlockRef LLVMGetNextBasicBlock(LLVMBasicBlockRef BB);
735LLVMBasicBlockRef LLVMGetPreviousBasicBlock(LLVMBasicBlockRef BB);
736LLVMBasicBlockRef LLVMGetEntryBasicBlock(LLVMValueRef Fn);
737
738LLVMBasicBlockRef LLVMAppendBasicBlockInContext(LLVMContextRef C,
739                                                LLVMValueRef Fn,
740                                                const char *Name);
741LLVMBasicBlockRef LLVMInsertBasicBlockInContext(LLVMContextRef C,
742                                                LLVMBasicBlockRef BB,
743                                                const char *Name);
744
745LLVMBasicBlockRef LLVMAppendBasicBlock(LLVMValueRef Fn, const char *Name);
746LLVMBasicBlockRef LLVMInsertBasicBlock(LLVMBasicBlockRef InsertBeforeBB,
747                                       const char *Name);
748void LLVMDeleteBasicBlock(LLVMBasicBlockRef BB);
749
750/* Operations on instructions */
751LLVMBasicBlockRef LLVMGetInstructionParent(LLVMValueRef Inst);
752LLVMValueRef LLVMGetFirstInstruction(LLVMBasicBlockRef BB);
753LLVMValueRef LLVMGetLastInstruction(LLVMBasicBlockRef BB);
754LLVMValueRef LLVMGetNextInstruction(LLVMValueRef Inst);
755LLVMValueRef LLVMGetPreviousInstruction(LLVMValueRef Inst);
756
757/* Operations on call sites */
758void LLVMSetInstructionCallConv(LLVMValueRef Instr, unsigned CC);
759unsigned LLVMGetInstructionCallConv(LLVMValueRef Instr);
760void LLVMAddInstrAttribute(LLVMValueRef Instr, unsigned index, LLVMAttribute);
761void LLVMRemoveInstrAttribute(LLVMValueRef Instr, unsigned index,
762                              LLVMAttribute);
763void LLVMSetInstrParamAlignment(LLVMValueRef Instr, unsigned index,
764                                unsigned align);
765
766/* Operations on call instructions (only) */
767LLVMBool LLVMIsTailCall(LLVMValueRef CallInst);
768void LLVMSetTailCall(LLVMValueRef CallInst, LLVMBool IsTailCall);
769
770/* Operations on phi nodes */
771void LLVMAddIncoming(LLVMValueRef PhiNode, LLVMValueRef *IncomingValues,
772                     LLVMBasicBlockRef *IncomingBlocks, unsigned Count);
773unsigned LLVMCountIncoming(LLVMValueRef PhiNode);
774LLVMValueRef LLVMGetIncomingValue(LLVMValueRef PhiNode, unsigned Index);
775LLVMBasicBlockRef LLVMGetIncomingBlock(LLVMValueRef PhiNode, unsigned Index);
776
777/*===-- Instruction builders ----------------------------------------------===*/
778
779/* An instruction builder represents a point within a basic block, and is the
780 * exclusive means of building instructions using the C interface.
781 */
782
783LLVMBuilderRef LLVMCreateBuilderInContext(LLVMContextRef C);
784LLVMBuilderRef LLVMCreateBuilder(void);
785void LLVMPositionBuilder(LLVMBuilderRef Builder, LLVMBasicBlockRef Block,
786                         LLVMValueRef Instr);
787void LLVMPositionBuilderBefore(LLVMBuilderRef Builder, LLVMValueRef Instr);
788void LLVMPositionBuilderAtEnd(LLVMBuilderRef Builder, LLVMBasicBlockRef Block);
789LLVMBasicBlockRef LLVMGetInsertBlock(LLVMBuilderRef Builder);
790void LLVMClearInsertionPosition(LLVMBuilderRef Builder);
791void LLVMInsertIntoBuilder(LLVMBuilderRef Builder, LLVMValueRef Instr);
792void LLVMInsertIntoBuilderWithName(LLVMBuilderRef Builder, LLVMValueRef Instr,
793                                   const char *Name);
794void LLVMDisposeBuilder(LLVMBuilderRef Builder);
795
796/* Metadata */
797void LLVMSetCurrentDebugLocation(LLVMBuilderRef Builder, LLVMValueRef L);
798LLVMValueRef LLVMGetCurrentDebugLocation(LLVMBuilderRef Builder);
799void LLVMSetInstDebugLocation(LLVMBuilderRef Builder, LLVMValueRef Inst);
800
801/* Terminators */
802LLVMValueRef LLVMBuildRetVoid(LLVMBuilderRef);
803LLVMValueRef LLVMBuildRet(LLVMBuilderRef, LLVMValueRef V);
804LLVMValueRef LLVMBuildAggregateRet(LLVMBuilderRef, LLVMValueRef *RetVals,
805                                   unsigned N);
806LLVMValueRef LLVMBuildBr(LLVMBuilderRef, LLVMBasicBlockRef Dest);
807LLVMValueRef LLVMBuildCondBr(LLVMBuilderRef, LLVMValueRef If,
808                             LLVMBasicBlockRef Then, LLVMBasicBlockRef Else);
809LLVMValueRef LLVMBuildSwitch(LLVMBuilderRef, LLVMValueRef V,
810                             LLVMBasicBlockRef Else, unsigned NumCases);
811LLVMValueRef LLVMBuildIndirectBr(LLVMBuilderRef B, LLVMValueRef Addr,
812                                 unsigned NumDests);
813LLVMValueRef LLVMBuildInvoke(LLVMBuilderRef, LLVMValueRef Fn,
814                             LLVMValueRef *Args, unsigned NumArgs,
815                             LLVMBasicBlockRef Then, LLVMBasicBlockRef Catch,
816                             const char *Name);
817LLVMValueRef LLVMBuildUnwind(LLVMBuilderRef);
818LLVMValueRef LLVMBuildUnreachable(LLVMBuilderRef);
819
820/* Add a case to the switch instruction */
821void LLVMAddCase(LLVMValueRef Switch, LLVMValueRef OnVal,
822                 LLVMBasicBlockRef Dest);
823
824/* Add a destination to the indirectbr instruction */
825void LLVMAddDestination(LLVMValueRef IndirectBr, LLVMBasicBlockRef Dest);
826
827/* Arithmetic */
828LLVMValueRef LLVMBuildAdd(LLVMBuilderRef, LLVMValueRef LHS, LLVMValueRef RHS,
829                          const char *Name);
830LLVMValueRef LLVMBuildNSWAdd(LLVMBuilderRef, LLVMValueRef LHS, LLVMValueRef RHS,
831                             const char *Name);
832LLVMValueRef LLVMBuildNUWAdd(LLVMBuilderRef, LLVMValueRef LHS, LLVMValueRef RHS,
833                             const char *Name);
834LLVMValueRef LLVMBuildFAdd(LLVMBuilderRef, LLVMValueRef LHS, LLVMValueRef RHS,
835                           const char *Name);
836LLVMValueRef LLVMBuildSub(LLVMBuilderRef, LLVMValueRef LHS, LLVMValueRef RHS,
837                          const char *Name);
838LLVMValueRef LLVMBuildNSWSub(LLVMBuilderRef, LLVMValueRef LHS, LLVMValueRef RHS,
839                             const char *Name);
840LLVMValueRef LLVMBuildNUWSub(LLVMBuilderRef, LLVMValueRef LHS, LLVMValueRef RHS,
841                             const char *Name);
842LLVMValueRef LLVMBuildFSub(LLVMBuilderRef, LLVMValueRef LHS, LLVMValueRef RHS,
843                           const char *Name);
844LLVMValueRef LLVMBuildMul(LLVMBuilderRef, LLVMValueRef LHS, LLVMValueRef RHS,
845                          const char *Name);
846LLVMValueRef LLVMBuildNSWMul(LLVMBuilderRef, LLVMValueRef LHS, LLVMValueRef RHS,
847                             const char *Name);
848LLVMValueRef LLVMBuildNUWMul(LLVMBuilderRef, LLVMValueRef LHS, LLVMValueRef RHS,
849                             const char *Name);
850LLVMValueRef LLVMBuildFMul(LLVMBuilderRef, LLVMValueRef LHS, LLVMValueRef RHS,
851                           const char *Name);
852LLVMValueRef LLVMBuildUDiv(LLVMBuilderRef, LLVMValueRef LHS, LLVMValueRef RHS,
853                           const char *Name);
854LLVMValueRef LLVMBuildSDiv(LLVMBuilderRef, LLVMValueRef LHS, LLVMValueRef RHS,
855                           const char *Name);
856LLVMValueRef LLVMBuildExactSDiv(LLVMBuilderRef, LLVMValueRef LHS, LLVMValueRef RHS,
857                                const char *Name);
858LLVMValueRef LLVMBuildFDiv(LLVMBuilderRef, LLVMValueRef LHS, LLVMValueRef RHS,
859                           const char *Name);
860LLVMValueRef LLVMBuildURem(LLVMBuilderRef, LLVMValueRef LHS, LLVMValueRef RHS,
861                           const char *Name);
862LLVMValueRef LLVMBuildSRem(LLVMBuilderRef, LLVMValueRef LHS, LLVMValueRef RHS,
863                           const char *Name);
864LLVMValueRef LLVMBuildFRem(LLVMBuilderRef, LLVMValueRef LHS, LLVMValueRef RHS,
865                           const char *Name);
866LLVMValueRef LLVMBuildShl(LLVMBuilderRef, LLVMValueRef LHS, LLVMValueRef RHS,
867                           const char *Name);
868LLVMValueRef LLVMBuildLShr(LLVMBuilderRef, LLVMValueRef LHS, LLVMValueRef RHS,
869                           const char *Name);
870LLVMValueRef LLVMBuildAShr(LLVMBuilderRef, LLVMValueRef LHS, LLVMValueRef RHS,
871                           const char *Name);
872LLVMValueRef LLVMBuildAnd(LLVMBuilderRef, LLVMValueRef LHS, LLVMValueRef RHS,
873                          const char *Name);
874LLVMValueRef LLVMBuildOr(LLVMBuilderRef, LLVMValueRef LHS, LLVMValueRef RHS,
875                          const char *Name);
876LLVMValueRef LLVMBuildXor(LLVMBuilderRef, LLVMValueRef LHS, LLVMValueRef RHS,
877                          const char *Name);
878LLVMValueRef LLVMBuildBinOp(LLVMBuilderRef B, LLVMOpcode Op,
879                            LLVMValueRef LHS, LLVMValueRef RHS,
880                            const char *Name);
881LLVMValueRef LLVMBuildNeg(LLVMBuilderRef, LLVMValueRef V, const char *Name);
882LLVMValueRef LLVMBuildNSWNeg(LLVMBuilderRef B, LLVMValueRef V,
883                             const char *Name);
884LLVMValueRef LLVMBuildNUWNeg(LLVMBuilderRef B, LLVMValueRef V,
885                             const char *Name);
886LLVMValueRef LLVMBuildFNeg(LLVMBuilderRef, LLVMValueRef V, const char *Name);
887LLVMValueRef LLVMBuildNot(LLVMBuilderRef, LLVMValueRef V, const char *Name);
888
889/* Memory */
890LLVMValueRef LLVMBuildMalloc(LLVMBuilderRef, LLVMTypeRef Ty, const char *Name);
891LLVMValueRef LLVMBuildArrayMalloc(LLVMBuilderRef, LLVMTypeRef Ty,
892                                  LLVMValueRef Val, const char *Name);
893LLVMValueRef LLVMBuildAlloca(LLVMBuilderRef, LLVMTypeRef Ty, const char *Name);
894LLVMValueRef LLVMBuildArrayAlloca(LLVMBuilderRef, LLVMTypeRef Ty,
895                                  LLVMValueRef Val, const char *Name);
896LLVMValueRef LLVMBuildFree(LLVMBuilderRef, LLVMValueRef PointerVal);
897LLVMValueRef LLVMBuildLoad(LLVMBuilderRef, LLVMValueRef PointerVal,
898                           const char *Name);
899LLVMValueRef LLVMBuildStore(LLVMBuilderRef, LLVMValueRef Val, LLVMValueRef Ptr);
900LLVMValueRef LLVMBuildGEP(LLVMBuilderRef B, LLVMValueRef Pointer,
901                          LLVMValueRef *Indices, unsigned NumIndices,
902                          const char *Name);
903LLVMValueRef LLVMBuildInBoundsGEP(LLVMBuilderRef B, LLVMValueRef Pointer,
904                                  LLVMValueRef *Indices, unsigned NumIndices,
905                                  const char *Name);
906LLVMValueRef LLVMBuildStructGEP(LLVMBuilderRef B, LLVMValueRef Pointer,
907                                unsigned Idx, const char *Name);
908LLVMValueRef LLVMBuildGlobalString(LLVMBuilderRef B, const char *Str,
909                                   const char *Name);
910LLVMValueRef LLVMBuildGlobalStringPtr(LLVMBuilderRef B, const char *Str,
911                                      const char *Name);
912
913/* Casts */
914LLVMValueRef LLVMBuildTrunc(LLVMBuilderRef, LLVMValueRef Val,
915                            LLVMTypeRef DestTy, const char *Name);
916LLVMValueRef LLVMBuildZExt(LLVMBuilderRef, LLVMValueRef Val,
917                           LLVMTypeRef DestTy, const char *Name);
918LLVMValueRef LLVMBuildSExt(LLVMBuilderRef, LLVMValueRef Val,
919                           LLVMTypeRef DestTy, const char *Name);
920LLVMValueRef LLVMBuildFPToUI(LLVMBuilderRef, LLVMValueRef Val,
921                             LLVMTypeRef DestTy, const char *Name);
922LLVMValueRef LLVMBuildFPToSI(LLVMBuilderRef, LLVMValueRef Val,
923                             LLVMTypeRef DestTy, const char *Name);
924LLVMValueRef LLVMBuildUIToFP(LLVMBuilderRef, LLVMValueRef Val,
925                             LLVMTypeRef DestTy, const char *Name);
926LLVMValueRef LLVMBuildSIToFP(LLVMBuilderRef, LLVMValueRef Val,
927                             LLVMTypeRef DestTy, const char *Name);
928LLVMValueRef LLVMBuildFPTrunc(LLVMBuilderRef, LLVMValueRef Val,
929                              LLVMTypeRef DestTy, const char *Name);
930LLVMValueRef LLVMBuildFPExt(LLVMBuilderRef, LLVMValueRef Val,
931                            LLVMTypeRef DestTy, const char *Name);
932LLVMValueRef LLVMBuildPtrToInt(LLVMBuilderRef, LLVMValueRef Val,
933                               LLVMTypeRef DestTy, const char *Name);
934LLVMValueRef LLVMBuildIntToPtr(LLVMBuilderRef, LLVMValueRef Val,
935                               LLVMTypeRef DestTy, const char *Name);
936LLVMValueRef LLVMBuildBitCast(LLVMBuilderRef, LLVMValueRef Val,
937                              LLVMTypeRef DestTy, const char *Name);
938LLVMValueRef LLVMBuildZExtOrBitCast(LLVMBuilderRef, LLVMValueRef Val,
939                                    LLVMTypeRef DestTy, const char *Name);
940LLVMValueRef LLVMBuildSExtOrBitCast(LLVMBuilderRef, LLVMValueRef Val,
941                                    LLVMTypeRef DestTy, const char *Name);
942LLVMValueRef LLVMBuildTruncOrBitCast(LLVMBuilderRef, LLVMValueRef Val,
943                                     LLVMTypeRef DestTy, const char *Name);
944LLVMValueRef LLVMBuildCast(LLVMBuilderRef B, LLVMOpcode Op, LLVMValueRef Val,
945                           LLVMTypeRef DestTy, const char *Name);
946LLVMValueRef LLVMBuildPointerCast(LLVMBuilderRef, LLVMValueRef Val,
947                                  LLVMTypeRef DestTy, const char *Name);
948LLVMValueRef LLVMBuildIntCast(LLVMBuilderRef, LLVMValueRef Val, /*Signed cast!*/
949                              LLVMTypeRef DestTy, const char *Name);
950LLVMValueRef LLVMBuildFPCast(LLVMBuilderRef, LLVMValueRef Val,
951                             LLVMTypeRef DestTy, const char *Name);
952
953/* Comparisons */
954LLVMValueRef LLVMBuildICmp(LLVMBuilderRef, LLVMIntPredicate Op,
955                           LLVMValueRef LHS, LLVMValueRef RHS,
956                           const char *Name);
957LLVMValueRef LLVMBuildFCmp(LLVMBuilderRef, LLVMRealPredicate Op,
958                           LLVMValueRef LHS, LLVMValueRef RHS,
959                           const char *Name);
960
961/* Miscellaneous instructions */
962LLVMValueRef LLVMBuildPhi(LLVMBuilderRef, LLVMTypeRef Ty, const char *Name);
963LLVMValueRef LLVMBuildCall(LLVMBuilderRef, LLVMValueRef Fn,
964                           LLVMValueRef *Args, unsigned NumArgs,
965                           const char *Name);
966LLVMValueRef LLVMBuildSelect(LLVMBuilderRef, LLVMValueRef If,
967                             LLVMValueRef Then, LLVMValueRef Else,
968                             const char *Name);
969LLVMValueRef LLVMBuildVAArg(LLVMBuilderRef, LLVMValueRef List, LLVMTypeRef Ty,
970                            const char *Name);
971LLVMValueRef LLVMBuildExtractElement(LLVMBuilderRef, LLVMValueRef VecVal,
972                                     LLVMValueRef Index, const char *Name);
973LLVMValueRef LLVMBuildInsertElement(LLVMBuilderRef, LLVMValueRef VecVal,
974                                    LLVMValueRef EltVal, LLVMValueRef Index,
975                                    const char *Name);
976LLVMValueRef LLVMBuildShuffleVector(LLVMBuilderRef, LLVMValueRef V1,
977                                    LLVMValueRef V2, LLVMValueRef Mask,
978                                    const char *Name);
979LLVMValueRef LLVMBuildExtractValue(LLVMBuilderRef, LLVMValueRef AggVal,
980                                   unsigned Index, const char *Name);
981LLVMValueRef LLVMBuildInsertValue(LLVMBuilderRef, LLVMValueRef AggVal,
982                                  LLVMValueRef EltVal, unsigned Index,
983                                  const char *Name);
984
985LLVMValueRef LLVMBuildIsNull(LLVMBuilderRef, LLVMValueRef Val,
986                             const char *Name);
987LLVMValueRef LLVMBuildIsNotNull(LLVMBuilderRef, LLVMValueRef Val,
988                                const char *Name);
989LLVMValueRef LLVMBuildPtrDiff(LLVMBuilderRef, LLVMValueRef LHS,
990                              LLVMValueRef RHS, const char *Name);
991
992
993/*===-- Module providers --------------------------------------------------===*/
994
995/* Changes the type of M so it can be passed to FunctionPassManagers and the
996 * JIT.  They take ModuleProviders for historical reasons.
997 */
998LLVMModuleProviderRef
999LLVMCreateModuleProviderForExistingModule(LLVMModuleRef M);
1000
1001/* Destroys the module M.
1002 */
1003void LLVMDisposeModuleProvider(LLVMModuleProviderRef M);
1004
1005
1006/*===-- Memory buffers ----------------------------------------------------===*/
1007
1008LLVMBool LLVMCreateMemoryBufferWithContentsOfFile(const char *Path,
1009                                                  LLVMMemoryBufferRef *OutMemBuf,
1010                                                  char **OutMessage);
1011LLVMBool LLVMCreateMemoryBufferWithSTDIN(LLVMMemoryBufferRef *OutMemBuf,
1012                                         char **OutMessage);
1013void LLVMDisposeMemoryBuffer(LLVMMemoryBufferRef MemBuf);
1014
1015
1016/*===-- Pass Managers -----------------------------------------------------===*/
1017
1018/** Constructs a new whole-module pass pipeline. This type of pipeline is
1019    suitable for link-time optimization and whole-module transformations.
1020    See llvm::PassManager::PassManager. */
1021LLVMPassManagerRef LLVMCreatePassManager(void);
1022
1023/** Constructs a new function-by-function pass pipeline over the module
1024    provider. It does not take ownership of the module provider. This type of
1025    pipeline is suitable for code generation and JIT compilation tasks.
1026    See llvm::FunctionPassManager::FunctionPassManager. */
1027LLVMPassManagerRef LLVMCreateFunctionPassManagerForModule(LLVMModuleRef M);
1028
1029/** Deprecated: Use LLVMCreateFunctionPassManagerForModule instead. */
1030LLVMPassManagerRef LLVMCreateFunctionPassManager(LLVMModuleProviderRef MP);
1031
1032/** Initializes, executes on the provided module, and finalizes all of the
1033    passes scheduled in the pass manager. Returns 1 if any of the passes
1034    modified the module, 0 otherwise. See llvm::PassManager::run(Module&). */
1035LLVMBool LLVMRunPassManager(LLVMPassManagerRef PM, LLVMModuleRef M);
1036
1037/** Initializes all of the function passes scheduled in the function pass
1038    manager. Returns 1 if any of the passes modified the module, 0 otherwise.
1039    See llvm::FunctionPassManager::doInitialization. */
1040LLVMBool LLVMInitializeFunctionPassManager(LLVMPassManagerRef FPM);
1041
1042/** Executes all of the function passes scheduled in the function pass manager
1043    on the provided function. Returns 1 if any of the passes modified the
1044    function, false otherwise.
1045    See llvm::FunctionPassManager::run(Function&). */
1046LLVMBool LLVMRunFunctionPassManager(LLVMPassManagerRef FPM, LLVMValueRef F);
1047
1048/** Finalizes all of the function passes scheduled in in the function pass
1049    manager. Returns 1 if any of the passes modified the module, 0 otherwise.
1050    See llvm::FunctionPassManager::doFinalization. */
1051LLVMBool LLVMFinalizeFunctionPassManager(LLVMPassManagerRef FPM);
1052
1053/** Frees the memory of a pass pipeline. For function pipelines, does not free
1054    the module provider.
1055    See llvm::PassManagerBase::~PassManagerBase. */
1056void LLVMDisposePassManager(LLVMPassManagerRef PM);
1057
1058
1059#ifdef __cplusplus
1060}
1061
1062namespace llvm {
1063  class MemoryBuffer;
1064  class PassManagerBase;
1065
1066  #define DEFINE_SIMPLE_CONVERSION_FUNCTIONS(ty, ref)   \
1067    inline ty *unwrap(ref P) {                          \
1068      return reinterpret_cast<ty*>(P);                  \
1069    }                                                   \
1070                                                        \
1071    inline ref wrap(const ty *P) {                      \
1072      return reinterpret_cast<ref>(const_cast<ty*>(P)); \
1073    }
1074
1075  #define DEFINE_ISA_CONVERSION_FUNCTIONS(ty, ref)  \
1076    DEFINE_SIMPLE_CONVERSION_FUNCTIONS(ty, ref)         \
1077                                                        \
1078    template<typename T>                                \
1079    inline T *unwrap(ref P) {                           \
1080      return cast<T>(unwrap(P));                        \
1081    }
1082
1083  #define DEFINE_STDCXX_CONVERSION_FUNCTIONS(ty, ref)   \
1084    DEFINE_SIMPLE_CONVERSION_FUNCTIONS(ty, ref)         \
1085                                                        \
1086    template<typename T>                                \
1087    inline T *unwrap(ref P) {                           \
1088      T *Q = (T*)unwrap(P);                             \
1089      assert(Q && "Invalid cast!");                     \
1090      return Q;                                         \
1091    }
1092
1093  DEFINE_ISA_CONVERSION_FUNCTIONS   (Type,               LLVMTypeRef          )
1094  DEFINE_ISA_CONVERSION_FUNCTIONS   (Value,              LLVMValueRef         )
1095  DEFINE_SIMPLE_CONVERSION_FUNCTIONS(Module,             LLVMModuleRef        )
1096  DEFINE_SIMPLE_CONVERSION_FUNCTIONS(BasicBlock,         LLVMBasicBlockRef    )
1097  DEFINE_SIMPLE_CONVERSION_FUNCTIONS(IRBuilder<>,        LLVMBuilderRef       )
1098  DEFINE_SIMPLE_CONVERSION_FUNCTIONS(PATypeHolder,       LLVMTypeHandleRef    )
1099  DEFINE_SIMPLE_CONVERSION_FUNCTIONS(MemoryBuffer,       LLVMMemoryBufferRef  )
1100  DEFINE_SIMPLE_CONVERSION_FUNCTIONS(LLVMContext,        LLVMContextRef       )
1101  DEFINE_SIMPLE_CONVERSION_FUNCTIONS(Use,                LLVMUseRef           )
1102  DEFINE_STDCXX_CONVERSION_FUNCTIONS(PassManagerBase,    LLVMPassManagerRef   )
1103  /* LLVMModuleProviderRef exists for historical reasons, but now just holds a
1104   * Module.
1105   */
1106  inline Module *unwrap(LLVMModuleProviderRef MP) {
1107    return reinterpret_cast<Module*>(MP);
1108  }
1109
1110  #undef DEFINE_STDCXX_CONVERSION_FUNCTIONS
1111  #undef DEFINE_ISA_CONVERSION_FUNCTIONS
1112  #undef DEFINE_SIMPLE_CONVERSION_FUNCTIONS
1113
1114  /* Specialized opaque context conversions.
1115   */
1116  inline LLVMContext **unwrap(LLVMContextRef* Tys) {
1117    return reinterpret_cast<LLVMContext**>(Tys);
1118  }
1119
1120  inline LLVMContextRef *wrap(const LLVMContext **Tys) {
1121    return reinterpret_cast<LLVMContextRef*>(const_cast<LLVMContext**>(Tys));
1122  }
1123
1124  /* Specialized opaque type conversions.
1125   */
1126  inline Type **unwrap(LLVMTypeRef* Tys) {
1127    return reinterpret_cast<Type**>(Tys);
1128  }
1129
1130  inline LLVMTypeRef *wrap(const Type **Tys) {
1131    return reinterpret_cast<LLVMTypeRef*>(const_cast<Type**>(Tys));
1132  }
1133
1134  /* Specialized opaque value conversions.
1135   */
1136  inline Value **unwrap(LLVMValueRef *Vals) {
1137    return reinterpret_cast<Value**>(Vals);
1138  }
1139
1140  template<typename T>
1141  inline T **unwrap(LLVMValueRef *Vals, unsigned Length) {
1142    #if DEBUG
1143    for (LLVMValueRef *I = Vals, *E = Vals + Length; I != E; ++I)
1144      cast<T>(*I);
1145    #endif
1146    return reinterpret_cast<T**>(Vals);
1147  }
1148
1149  inline LLVMValueRef *wrap(const Value **Vals) {
1150    return reinterpret_cast<LLVMValueRef*>(const_cast<Value**>(Vals));
1151  }
1152}
1153
1154#endif /* !defined(__cplusplus) */
1155
1156#endif /* !defined(LLVM_C_CORE_H) */
1157