blob: c1609b013eb1d10b14040bd8fa166a1999d97ce4 [file] [log] [blame]
Gordon Henriksen76a03742007-09-18 03:18:57 +00001/*===-- llvm-c/Core.h - Core Library C Interface ------------------*- C -*-===*\
2|* *|
3|* The LLVM Compiler Infrastructure *|
4|* *|
Chris Lattnere9cc7422007-12-29 19:59:42 +00005|* This file is distributed under the University of Illinois Open Source *|
6|* License. See LICENSE.TXT for details. *|
Gordon Henriksen76a03742007-09-18 03:18:57 +00007|* *|
8|*===----------------------------------------------------------------------===*|
9|* *|
10|* This header declares the C interface to libLLVMCore.a, which implements *|
11|* the LLVM intermediate representation. *|
12|* *|
13|* LLVM uses a polymorphic type hierarchy which C cannot represent, therefore *|
14|* parameters must be passed as base types. Despite the declared types, most *|
15|* of the functions provided operate only on branches of the type hierarchy. *|
16|* The declared parameter names are descriptive and specify which type is *|
17|* required. Additionally, each type hierarchy is documented along with the *|
18|* functions that operate upon it. For more detail, refer to LLVM's C++ code. *|
19|* If in doubt, refer to Core.cpp, which performs paramter downcasts in the *|
20|* form unwrap<RequiredType>(Param). *|
21|* *|
22|* Many exotic languages can interoperate with C code but have a harder time *|
23|* with C++ due to name mangling. So in addition to C, this interface enables *|
24|* tools written in such languages. *|
25|* *|
Gordon Henriksen7330acd2007-10-05 23:59:36 +000026|* When included into a C++ source file, also declares 'wrap' and 'unwrap' *|
27|* helpers to perform opaque reference<-->pointer conversions. These helpers *|
28|* are shorter and more tightly typed than writing the casts by hand when *|
29|* authoring bindings. In assert builds, they will do runtime type checking. *|
30|* *|
Gordon Henriksen76a03742007-09-18 03:18:57 +000031\*===----------------------------------------------------------------------===*/
32
33#ifndef LLVM_C_CORE_H
34#define LLVM_C_CORE_H
35
36#ifdef __cplusplus
Gordon Henriksen7330acd2007-10-05 23:59:36 +000037
38/* Need these includes to support the LLVM 'cast' template for the C++ 'wrap'
39 and 'unwrap' conversion functions. */
40#include "llvm/Module.h"
Duncan Sandsa07136e2008-04-13 06:22:09 +000041#include "llvm/Support/IRBuilder.h"
Gordon Henriksen7330acd2007-10-05 23:59:36 +000042
Gordon Henriksen76a03742007-09-18 03:18:57 +000043extern "C" {
44#endif
45
46
47/* Opaque types. */
Gordon Henriksen4a4d7352007-12-30 17:46:33 +000048
49/**
Owen Anderson6773d382009-07-01 16:58:40 +000050 * The top-level container for all LLVM global data. See the LLVMContext class.
51 */
Erick Tryzelaar262332f2009-08-14 00:01:31 +000052typedef struct LLVMOpaqueContext *LLVMContextRef;
Owen Anderson6773d382009-07-01 16:58:40 +000053
54/**
Gordon Henriksen4a4d7352007-12-30 17:46:33 +000055 * The top-level container for all other LLVM Intermediate Representation (IR)
56 * objects. See the llvm::Module class.
57 */
Gordon Henriksen76a03742007-09-18 03:18:57 +000058typedef struct LLVMOpaqueModule *LLVMModuleRef;
Gordon Henriksen4a4d7352007-12-30 17:46:33 +000059
60/**
Gordon Henriksena49d4352008-03-07 19:13:06 +000061 * Each value in the LLVM IR has a type, an LLVMTypeRef. See the llvm::Type
62 * class.
Gordon Henriksen4a4d7352007-12-30 17:46:33 +000063 */
Gordon Henriksen76a03742007-09-18 03:18:57 +000064typedef struct LLVMOpaqueType *LLVMTypeRef;
Gordon Henriksen4a4d7352007-12-30 17:46:33 +000065
66/**
Gordon Henriksena49d4352008-03-07 19:13:06 +000067 * When building recursive types using LLVMRefineType, LLVMTypeRef values may
68 * become invalid; use LLVMTypeHandleRef to resolve this problem. See the
69 * llvm::AbstractTypeHolder class.
Gordon Henriksen4a4d7352007-12-30 17:46:33 +000070 */
Gordon Henriksenffb48762007-10-07 00:13:35 +000071typedef struct LLVMOpaqueTypeHandle *LLVMTypeHandleRef;
Gordon Henriksen4a4d7352007-12-30 17:46:33 +000072
Gordon Henriksen76a03742007-09-18 03:18:57 +000073typedef struct LLVMOpaqueValue *LLVMValueRef;
Gordon Henriksenc23b66c2007-09-26 20:56:12 +000074typedef struct LLVMOpaqueBasicBlock *LLVMBasicBlockRef;
75typedef struct LLVMOpaqueBuilder *LLVMBuilderRef;
Gordon Henriksen34eb6d82007-12-19 22:30:40 +000076
77/* Used to provide a module to JIT or interpreter.
78 * See the llvm::ModuleProvider class.
79 */
Gordon Henriksen0a68fe22007-12-12 01:04:30 +000080typedef struct LLVMOpaqueModuleProvider *LLVMModuleProviderRef;
Gordon Henriksen76a03742007-09-18 03:18:57 +000081
Gordon Henriksen34eb6d82007-12-19 22:30:40 +000082/* Used to provide a module to JIT or interpreter.
83 * See the llvm::MemoryBuffer class.
84 */
85typedef struct LLVMOpaqueMemoryBuffer *LLVMMemoryBufferRef;
86
Gordon Henriksen878114b2008-03-16 04:20:44 +000087/** See the llvm::PassManagerBase class. */
88typedef struct LLVMOpaquePassManager *LLVMPassManagerRef;
89
Gordon Henriksen76a03742007-09-18 03:18:57 +000090typedef enum {
Devang Patel4c758ea2008-09-25 21:00:45 +000091 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,
Anton Korobeynikovc8ce7b082009-07-17 18:07:26 +0000101 LLVMReadOnlyAttribute = 1<<10,
Anton Korobeynikov9750be92009-07-17 18:57:16 +0000102 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,
Anton Korobeynikovc8ce7b082009-07-17 18:07:26 +0000110 LLVMNakedAttribute = 1<<24
Devang Patel4c758ea2008-09-25 21:00:45 +0000111} LLVMAttribute;
Gordon Henriksen2d9cc212008-04-28 17:37:06 +0000112
113typedef enum {
Gordon Henriksen4a4d7352007-12-30 17:46:33 +0000114 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 */
Chris Lattnerdac44ec2009-07-15 22:00:31 +0000127 LLVMVectorTypeKind, /**< SIMD 'packed' format, or other vector type */
128 LLVMMetadataTypeKind /**< Metadata */
Gordon Henriksen76a03742007-09-18 03:18:57 +0000129} LLVMTypeKind;
130
131typedef enum {
Gordon Henriksen4a4d7352007-12-30 17:46:33 +0000132 LLVMExternalLinkage, /**< Externally visible function */
Chris Lattner2dba0f02009-04-13 06:25:37 +0000133 LLVMAvailableExternallyLinkage,
Duncan Sands12da8ce2009-03-07 15:45:40 +0000134 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. */
Gordon Henriksen4a4d7352007-12-30 17:46:33 +0000140 LLVMAppendingLinkage, /**< Special purpose, only applies to global arrays */
141 LLVMInternalLinkage, /**< Rename collisions when linking (static
142 functions) */
Duncan Sands12da8ce2009-03-07 15:45:40 +0000143 LLVMPrivateLinkage, /**< Like Internal, but omit from symbol table */
Gordon Henriksen4a4d7352007-12-30 17:46:33 +0000144 LLVMDLLImportLinkage, /**< Function to be imported from DLL */
145 LLVMDLLExportLinkage, /**< Function to be accessible from DLL */
Duncan Sandse2881052009-03-11 08:08:06 +0000146 LLVMExternalWeakLinkage,/**< ExternalWeak linkage description */
Duncan Sands12da8ce2009-03-07 15:45:40 +0000147 LLVMGhostLinkage, /**< Stand-in functions for streaming fns from
Gordon Henriksen4a4d7352007-12-30 17:46:33 +0000148 bitcode */
Bill Wendling002b1672009-07-20 18:22:52 +0000149 LLVMCommonLinkage, /**< Tentative definitions */
150 LLVMLinkerPrivateLinkage /**< Like Private, but linker removes. */
Gordon Henriksen76a03742007-09-18 03:18:57 +0000151} LLVMLinkage;
152
153typedef enum {
Gordon Henriksen4a4d7352007-12-30 17:46:33 +0000154 LLVMDefaultVisibility, /**< The GV is visible */
155 LLVMHiddenVisibility, /**< The GV is hidden */
156 LLVMProtectedVisibility /**< The GV is protected */
Gordon Henriksen76a03742007-09-18 03:18:57 +0000157} LLVMVisibility;
158
Gordon Henriksenc23b66c2007-09-26 20:56:12 +0000159typedef enum {
160 LLVMCCallConv = 0,
161 LLVMFastCallConv = 8,
162 LLVMColdCallConv = 9,
163 LLVMX86StdcallCallConv = 64,
164 LLVMX86FastcallCallConv = 65
165} LLVMCallConv;
166
167typedef enum {
Gordon Henriksen4a4d7352007-12-30 17:46:33 +0000168 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 */
Gordon Henriksenc23b66c2007-09-26 20:56:12 +0000178} LLVMIntPredicate;
179
180typedef enum {
Gordon Henriksen4a4d7352007-12-30 17:46:33 +0000181 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) */
Gordon Henriksenc23b66c2007-09-26 20:56:12 +0000197} LLVMRealPredicate;
198
Gordon Henriksen76a03742007-09-18 03:18:57 +0000199
Gordon Henriksen34eb6d82007-12-19 22:30:40 +0000200/*===-- Error handling ----------------------------------------------------===*/
201
202void LLVMDisposeMessage(char *Message);
203
204
Gordon Henriksen76a03742007-09-18 03:18:57 +0000205/*===-- Modules -----------------------------------------------------------===*/
206
Owen Anderson6773d382009-07-01 16:58:40 +0000207/* Create and destroy contexts. */
208LLVMContextRef LLVMContextCreate();
Owen Andersonf7691d32009-07-02 00:16:38 +0000209LLVMContextRef LLVMGetGlobalContext();
Owen Anderson6773d382009-07-01 16:58:40 +0000210void LLVMContextDispose(LLVMContextRef C);
211
Gordon Henriksen76a03742007-09-18 03:18:57 +0000212/* Create and destroy modules. */
Gordon Henriksena49d4352008-03-07 19:13:06 +0000213/** See llvm::Module::Module. */
Gordon Henriksen76a03742007-09-18 03:18:57 +0000214LLVMModuleRef LLVMModuleCreateWithName(const char *ModuleID);
Owen Anderson31d44e42009-07-02 07:17:57 +0000215LLVMModuleRef LLVMModuleCreateWithNameInContext(const char *ModuleID,
216 LLVMContextRef C);
Gordon Henriksena49d4352008-03-07 19:13:06 +0000217
218/** See llvm::Module::~Module. */
Gordon Henriksen76a03742007-09-18 03:18:57 +0000219void LLVMDisposeModule(LLVMModuleRef M);
220
Gordon Henriksena49d4352008-03-07 19:13:06 +0000221/** Data layout. See Module::getDataLayout. */
Gordon Henriksen05568bb2007-12-27 20:13:47 +0000222const char *LLVMGetDataLayout(LLVMModuleRef M);
223void LLVMSetDataLayout(LLVMModuleRef M, const char *Triple);
224
Gordon Henriksena49d4352008-03-07 19:13:06 +0000225/** Target triple. See Module::getTargetTriple. */
Gordon Henriksen05568bb2007-12-27 20:13:47 +0000226const char *LLVMGetTarget(LLVMModuleRef M);
227void LLVMSetTarget(LLVMModuleRef M, const char *Triple);
228
Gordon Henriksena49d4352008-03-07 19:13:06 +0000229/** See Module::addTypeName. */
Gordon Henriksen76a03742007-09-18 03:18:57 +0000230int LLVMAddTypeName(LLVMModuleRef M, const char *Name, LLVMTypeRef Ty);
Gordon Henriksenc23b66c2007-09-26 20:56:12 +0000231void LLVMDeleteTypeName(LLVMModuleRef M, const char *Name);
Chris Lattner7f318242009-07-06 17:29:59 +0000232LLVMTypeRef LLVMGetTypeByName(LLVMModuleRef M, const char *Name);
Gordon Henriksen76a03742007-09-18 03:18:57 +0000233
Gordon Henriksen6c6075e2008-03-14 23:58:56 +0000234/** See Module::dump. */
235void LLVMDumpModule(LLVMModuleRef M);
236
Gordon Henriksen76a03742007-09-18 03:18:57 +0000237
Gordon Henriksenc23b66c2007-09-26 20:56:12 +0000238/*===-- Types -------------------------------------------------------------===*/
Gordon Henriksen76a03742007-09-18 03:18:57 +0000239
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
Gordon Henriksena49d4352008-03-07 19:13:06 +0000255/** See llvm::LLVMTypeKind::getTypeID. */
Gordon Henriksen76a03742007-09-18 03:18:57 +0000256LLVMTypeKind LLVMGetTypeKind(LLVMTypeRef Ty);
Gordon Henriksena49d4352008-03-07 19:13:06 +0000257
Erick Tryzelaar262332f2009-08-14 00:01:31 +0000258/** See llvm::LLVMType::getContext. */
259LLVMContextRef LLVMGetTypeContext(LLVMTypeRef Ty);
260
Gordon Henriksen76a03742007-09-18 03:18:57 +0000261/* Operations on integer types */
Erick Tryzelaar262332f2009-08-14 00:01:31 +0000262LLVMTypeRef LLVMInt1TypeInContext(LLVMContextRef C);
263LLVMTypeRef LLVMInt8TypeInContext(LLVMContextRef C);
264LLVMTypeRef LLVMInt16TypeInContext(LLVMContextRef C);
265LLVMTypeRef LLVMInt32TypeInContext(LLVMContextRef C);
266LLVMTypeRef LLVMInt64TypeInContext(LLVMContextRef C);
267LLVMTypeRef LLVMIntTypeInContext(LLVMContextRef C, unsigned NumBits);
268
Gordon Henriksena735a9c2008-05-04 12:55:34 +0000269LLVMTypeRef LLVMInt1Type(void);
270LLVMTypeRef LLVMInt8Type(void);
271LLVMTypeRef LLVMInt16Type(void);
272LLVMTypeRef LLVMInt32Type(void);
273LLVMTypeRef LLVMInt64Type(void);
Gordon Henriksened7beaa2007-10-06 16:05:20 +0000274LLVMTypeRef LLVMIntType(unsigned NumBits);
Gordon Henriksenc23b66c2007-09-26 20:56:12 +0000275unsigned LLVMGetIntTypeWidth(LLVMTypeRef IntegerTy);
Gordon Henriksen76a03742007-09-18 03:18:57 +0000276
277/* Operations on real types */
Erick Tryzelaar262332f2009-08-14 00:01:31 +0000278LLVMTypeRef LLVMFloatTypeInContext(LLVMContextRef C);
279LLVMTypeRef LLVMDoubleTypeInContext(LLVMContextRef C);
280LLVMTypeRef LLVMX86FP80TypeInContext(LLVMContextRef C);
281LLVMTypeRef LLVMFP128TypeInContext(LLVMContextRef C);
282LLVMTypeRef LLVMPPCFP128TypeInContext(LLVMContextRef C);
283
Gordon Henriksena735a9c2008-05-04 12:55:34 +0000284LLVMTypeRef LLVMFloatType(void);
285LLVMTypeRef LLVMDoubleType(void);
286LLVMTypeRef LLVMX86FP80Type(void);
287LLVMTypeRef LLVMFP128Type(void);
288LLVMTypeRef LLVMPPCFP128Type(void);
Gordon Henriksen76a03742007-09-18 03:18:57 +0000289
290/* Operations on function types */
Gordon Henriksened7beaa2007-10-06 16:05:20 +0000291LLVMTypeRef LLVMFunctionType(LLVMTypeRef ReturnType,
292 LLVMTypeRef *ParamTypes, unsigned ParamCount,
293 int IsVarArg);
Gordon Henriksen76a03742007-09-18 03:18:57 +0000294int LLVMIsFunctionVarArg(LLVMTypeRef FunctionTy);
Gordon Henriksenc23b66c2007-09-26 20:56:12 +0000295LLVMTypeRef LLVMGetReturnType(LLVMTypeRef FunctionTy);
296unsigned LLVMCountParamTypes(LLVMTypeRef FunctionTy);
297void LLVMGetParamTypes(LLVMTypeRef FunctionTy, LLVMTypeRef *Dest);
Gordon Henriksen76a03742007-09-18 03:18:57 +0000298
299/* Operations on struct types */
Erick Tryzelaar262332f2009-08-14 00:01:31 +0000300LLVMTypeRef LLVMStructTypeInContext(LLVMContextRef C, LLVMTypeRef *ElementTypes,
301 unsigned ElementCount, int Packed);
Gordon Henriksened7beaa2007-10-06 16:05:20 +0000302LLVMTypeRef LLVMStructType(LLVMTypeRef *ElementTypes, unsigned ElementCount,
303 int Packed);
Gordon Henriksenc23b66c2007-09-26 20:56:12 +0000304unsigned LLVMCountStructElementTypes(LLVMTypeRef StructTy);
Gordon Henriksen76a03742007-09-18 03:18:57 +0000305void LLVMGetStructElementTypes(LLVMTypeRef StructTy, LLVMTypeRef *Dest);
306int LLVMIsPackedStruct(LLVMTypeRef StructTy);
307
308/* Operations on array, pointer, and vector types (sequence types) */
Gordon Henriksened7beaa2007-10-06 16:05:20 +0000309LLVMTypeRef LLVMArrayType(LLVMTypeRef ElementType, unsigned ElementCount);
Gordon Henriksen5a3fe032007-12-17 16:08:32 +0000310LLVMTypeRef LLVMPointerType(LLVMTypeRef ElementType, unsigned AddressSpace);
Gordon Henriksened7beaa2007-10-06 16:05:20 +0000311LLVMTypeRef LLVMVectorType(LLVMTypeRef ElementType, unsigned ElementCount);
Gordon Henriksen76a03742007-09-18 03:18:57 +0000312
313LLVMTypeRef LLVMGetElementType(LLVMTypeRef Ty);
314unsigned LLVMGetArrayLength(LLVMTypeRef ArrayTy);
Gordon Henriksen5a3fe032007-12-17 16:08:32 +0000315unsigned LLVMGetPointerAddressSpace(LLVMTypeRef PointerTy);
Gordon Henriksen76a03742007-09-18 03:18:57 +0000316unsigned LLVMGetVectorSize(LLVMTypeRef VectorTy);
317
318/* Operations on other types */
Erick Tryzelaar262332f2009-08-14 00:01:31 +0000319LLVMTypeRef LLVMVoidTypeInContext(LLVMContextRef C);
320LLVMTypeRef LLVMLabelTypeInContext(LLVMContextRef C);
321LLVMTypeRef LLVMOpaqueTypeInContext(LLVMContextRef C);
322
Gordon Henriksena735a9c2008-05-04 12:55:34 +0000323LLVMTypeRef LLVMVoidType(void);
324LLVMTypeRef LLVMLabelType(void);
325LLVMTypeRef LLVMOpaqueType(void);
Gordon Henriksen76a03742007-09-18 03:18:57 +0000326
Gordon Henriksenffb48762007-10-07 00:13:35 +0000327/* Operations on type handles */
328LLVMTypeHandleRef LLVMCreateTypeHandle(LLVMTypeRef PotentiallyAbstractTy);
329void LLVMRefineType(LLVMTypeRef AbstractTy, LLVMTypeRef ConcreteTy);
330LLVMTypeRef LLVMResolveTypeHandle(LLVMTypeHandleRef TypeHandle);
331void LLVMDisposeTypeHandle(LLVMTypeHandleRef TypeHandle);
332
Gordon Henriksen76a03742007-09-18 03:18:57 +0000333
334/*===-- Values ------------------------------------------------------------===*/
335
336/* The bulk of LLVM's object model consists of values, which comprise a very
337 * rich type hierarchy.
Gordon Henriksen76a03742007-09-18 03:18:57 +0000338 */
339
Gordon Henriksen29e38942008-12-19 18:39:45 +0000340#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) \
Gordon Henriksen29e38942008-12-19 18:39:45 +0000377 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) \
Gordon Henriksen05a868f2008-12-19 18:51:17 +0000394 macro(AllocaInst) \
395 macro(MallocInst) \
Gordon Henriksen29e38942008-12-19 18:39:45 +0000396 macro(CastInst) \
Gordon Henriksen05a868f2008-12-19 18:51:17 +0000397 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)
Gordon Henriksen29e38942008-12-19 18:39:45 +0000413
Gordon Henriksen76a03742007-09-18 03:18:57 +0000414/* Operations on all values */
Gordon Henriksenc23b66c2007-09-26 20:56:12 +0000415LLVMTypeRef LLVMTypeOf(LLVMValueRef Val);
Gordon Henriksen76a03742007-09-18 03:18:57 +0000416const char *LLVMGetValueName(LLVMValueRef Val);
417void LLVMSetValueName(LLVMValueRef Val, const char *Name);
Gordon Henriksen1d0d24c2007-10-06 00:08:49 +0000418void LLVMDumpValue(LLVMValueRef Val);
Gordon Henriksen76a03742007-09-18 03:18:57 +0000419
Gordon Henriksen29e38942008-12-19 18:39:45 +0000420/* 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);
424LLVM_FOR_EACH_VALUE_SUBCLASS(LLVM_DECLARE_VALUE_CAST)
425
Gordon Henriksen76a03742007-09-18 03:18:57 +0000426/* Operations on constants of any type */
Gordon Henriksen1046c732007-10-06 15:11:06 +0000427LLVMValueRef LLVMConstNull(LLVMTypeRef Ty); /* all zeroes */
428LLVMValueRef LLVMConstAllOnes(LLVMTypeRef Ty); /* only for int/vector */
Gordon Henriksen76a03742007-09-18 03:18:57 +0000429LLVMValueRef LLVMGetUndef(LLVMTypeRef Ty);
Gordon Henriksendc88c062007-09-18 18:07:51 +0000430int LLVMIsConstant(LLVMValueRef Val);
Gordon Henriksen76a03742007-09-18 03:18:57 +0000431int LLVMIsNull(LLVMValueRef Val);
Gordon Henriksendc88c062007-09-18 18:07:51 +0000432int LLVMIsUndef(LLVMValueRef Val);
Chris Lattner7f318242009-07-06 17:29:59 +0000433LLVMValueRef LLVMConstPointerNull(LLVMTypeRef Ty);
Gordon Henriksen76a03742007-09-18 03:18:57 +0000434
435/* Operations on scalar constants */
Gordon Henriksen1046c732007-10-06 15:11:06 +0000436LLVMValueRef LLVMConstInt(LLVMTypeRef IntTy, unsigned long long N,
437 int SignExtend);
438LLVMValueRef LLVMConstReal(LLVMTypeRef RealTy, double N);
Gordon Henriksen931e1212008-02-02 01:07:50 +0000439LLVMValueRef LLVMConstRealOfString(LLVMTypeRef RealTy, const char *Text);
Gordon Henriksen76a03742007-09-18 03:18:57 +0000440
441/* Operations on composite constants */
Erick Tryzelaar262332f2009-08-14 00:01:31 +0000442LLVMValueRef LLVMConstStringInContext(LLVMContextRef C, const char *Str,
443 unsigned Length, int DontNullTerminate);
444LLVMValueRef LLVMConstStructInContext(LLVMContextRef C,
445 LLVMValueRef *ConstantVals,
446 unsigned Count, int Packed);
447
Gordon Henriksen1046c732007-10-06 15:11:06 +0000448LLVMValueRef LLVMConstString(const char *Str, unsigned Length,
449 int DontNullTerminate);
Gordon Henriksen2ad5aef2008-04-25 03:21:19 +0000450LLVMValueRef LLVMConstArray(LLVMTypeRef ElementTy,
Gordon Henriksen1046c732007-10-06 15:11:06 +0000451 LLVMValueRef *ConstantVals, unsigned Length);
452LLVMValueRef LLVMConstStruct(LLVMValueRef *ConstantVals, unsigned Count,
Erick Tryzelaar262332f2009-08-14 00:01:31 +0000453 int Packed);
Gordon Henriksen1046c732007-10-06 15:11:06 +0000454LLVMValueRef LLVMConstVector(LLVMValueRef *ScalarConstantVals, unsigned Size);
Gordon Henriksen76a03742007-09-18 03:18:57 +0000455
Gordon Henriksen7ce31762007-10-06 14:29:36 +0000456/* Constant expressions */
457LLVMValueRef LLVMSizeOf(LLVMTypeRef Ty);
458LLVMValueRef LLVMConstNeg(LLVMValueRef ConstantVal);
459LLVMValueRef LLVMConstNot(LLVMValueRef ConstantVal);
460LLVMValueRef LLVMConstAdd(LLVMValueRef LHSConstant, LLVMValueRef RHSConstant);
461LLVMValueRef LLVMConstSub(LLVMValueRef LHSConstant, LLVMValueRef RHSConstant);
462LLVMValueRef LLVMConstMul(LLVMValueRef LHSConstant, LLVMValueRef RHSConstant);
463LLVMValueRef LLVMConstUDiv(LLVMValueRef LHSConstant, LLVMValueRef RHSConstant);
464LLVMValueRef LLVMConstSDiv(LLVMValueRef LHSConstant, LLVMValueRef RHSConstant);
465LLVMValueRef LLVMConstFDiv(LLVMValueRef LHSConstant, LLVMValueRef RHSConstant);
466LLVMValueRef LLVMConstURem(LLVMValueRef LHSConstant, LLVMValueRef RHSConstant);
467LLVMValueRef LLVMConstSRem(LLVMValueRef LHSConstant, LLVMValueRef RHSConstant);
468LLVMValueRef LLVMConstFRem(LLVMValueRef LHSConstant, LLVMValueRef RHSConstant);
469LLVMValueRef LLVMConstAnd(LLVMValueRef LHSConstant, LLVMValueRef RHSConstant);
470LLVMValueRef LLVMConstOr(LLVMValueRef LHSConstant, LLVMValueRef RHSConstant);
471LLVMValueRef LLVMConstXor(LLVMValueRef LHSConstant, LLVMValueRef RHSConstant);
472LLVMValueRef LLVMConstICmp(LLVMIntPredicate Predicate,
473 LLVMValueRef LHSConstant, LLVMValueRef RHSConstant);
474LLVMValueRef LLVMConstFCmp(LLVMRealPredicate Predicate,
475 LLVMValueRef LHSConstant, LLVMValueRef RHSConstant);
476LLVMValueRef LLVMConstShl(LLVMValueRef LHSConstant, LLVMValueRef RHSConstant);
477LLVMValueRef LLVMConstLShr(LLVMValueRef LHSConstant, LLVMValueRef RHSConstant);
478LLVMValueRef LLVMConstAShr(LLVMValueRef LHSConstant, LLVMValueRef RHSConstant);
479LLVMValueRef LLVMConstGEP(LLVMValueRef ConstantVal,
480 LLVMValueRef *ConstantIndices, unsigned NumIndices);
481LLVMValueRef LLVMConstTrunc(LLVMValueRef ConstantVal, LLVMTypeRef ToType);
482LLVMValueRef LLVMConstSExt(LLVMValueRef ConstantVal, LLVMTypeRef ToType);
483LLVMValueRef LLVMConstZExt(LLVMValueRef ConstantVal, LLVMTypeRef ToType);
484LLVMValueRef LLVMConstFPTrunc(LLVMValueRef ConstantVal, LLVMTypeRef ToType);
485LLVMValueRef LLVMConstFPExt(LLVMValueRef ConstantVal, LLVMTypeRef ToType);
486LLVMValueRef LLVMConstUIToFP(LLVMValueRef ConstantVal, LLVMTypeRef ToType);
487LLVMValueRef LLVMConstSIToFP(LLVMValueRef ConstantVal, LLVMTypeRef ToType);
488LLVMValueRef LLVMConstFPToUI(LLVMValueRef ConstantVal, LLVMTypeRef ToType);
489LLVMValueRef LLVMConstFPToSI(LLVMValueRef ConstantVal, LLVMTypeRef ToType);
490LLVMValueRef LLVMConstPtrToInt(LLVMValueRef ConstantVal, LLVMTypeRef ToType);
491LLVMValueRef LLVMConstIntToPtr(LLVMValueRef ConstantVal, LLVMTypeRef ToType);
492LLVMValueRef LLVMConstBitCast(LLVMValueRef ConstantVal, LLVMTypeRef ToType);
493LLVMValueRef LLVMConstSelect(LLVMValueRef ConstantCondition,
494 LLVMValueRef ConstantIfTrue,
495 LLVMValueRef ConstantIfFalse);
496LLVMValueRef LLVMConstExtractElement(LLVMValueRef VectorConstant,
497 LLVMValueRef IndexConstant);
498LLVMValueRef LLVMConstInsertElement(LLVMValueRef VectorConstant,
499 LLVMValueRef ElementValueConstant,
500 LLVMValueRef IndexConstant);
501LLVMValueRef LLVMConstShuffleVector(LLVMValueRef VectorAConstant,
502 LLVMValueRef VectorBConstant,
503 LLVMValueRef MaskConstant);
Dan Gohmand5104a52008-11-03 22:55:43 +0000504LLVMValueRef LLVMConstExtractValue(LLVMValueRef AggConstant, unsigned *IdxList,
505 unsigned NumIdx);
506LLVMValueRef LLVMConstInsertValue(LLVMValueRef AggConstant,
507 LLVMValueRef ElementValueConstant,
508 unsigned *IdxList, unsigned NumIdx);
Chris Lattner3d1f5522008-12-17 21:39:50 +0000509LLVMValueRef LLVMConstInlineAsm(LLVMTypeRef Ty,
510 const char *AsmString, const char *Constraints,
511 int HasSideEffects);
Gordon Henriksen7ce31762007-10-06 14:29:36 +0000512
Gordon Henriksen76a03742007-09-18 03:18:57 +0000513/* Operations on global variables, functions, and aliases (globals) */
Gordon Henriksen265f7802008-03-19 01:11:35 +0000514LLVMModuleRef LLVMGetGlobalParent(LLVMValueRef Global);
Gordon Henriksen76a03742007-09-18 03:18:57 +0000515int LLVMIsDeclaration(LLVMValueRef Global);
516LLVMLinkage LLVMGetLinkage(LLVMValueRef Global);
517void LLVMSetLinkage(LLVMValueRef Global, LLVMLinkage Linkage);
518const char *LLVMGetSection(LLVMValueRef Global);
519void LLVMSetSection(LLVMValueRef Global, const char *Section);
520LLVMVisibility LLVMGetVisibility(LLVMValueRef Global);
521void LLVMSetVisibility(LLVMValueRef Global, LLVMVisibility Viz);
522unsigned LLVMGetAlignment(LLVMValueRef Global);
523void LLVMSetAlignment(LLVMValueRef Global, unsigned Bytes);
524
525/* Operations on global variables */
526LLVMValueRef LLVMAddGlobal(LLVMModuleRef M, LLVMTypeRef Ty, const char *Name);
Gordon Henriksen783f7bb2007-10-08 03:45:09 +0000527LLVMValueRef LLVMGetNamedGlobal(LLVMModuleRef M, const char *Name);
Gordon Henriksen07a45f42008-03-23 22:21:29 +0000528LLVMValueRef LLVMGetFirstGlobal(LLVMModuleRef M);
529LLVMValueRef LLVMGetLastGlobal(LLVMModuleRef M);
530LLVMValueRef LLVMGetNextGlobal(LLVMValueRef GlobalVar);
531LLVMValueRef LLVMGetPreviousGlobal(LLVMValueRef GlobalVar);
Gordon Henriksen76a03742007-09-18 03:18:57 +0000532void LLVMDeleteGlobal(LLVMValueRef GlobalVar);
Gordon Henriksen76a03742007-09-18 03:18:57 +0000533LLVMValueRef LLVMGetInitializer(LLVMValueRef GlobalVar);
534void LLVMSetInitializer(LLVMValueRef GlobalVar, LLVMValueRef ConstantVal);
535int LLVMIsThreadLocal(LLVMValueRef GlobalVar);
536void LLVMSetThreadLocal(LLVMValueRef GlobalVar, int IsThreadLocal);
Gordon Henriksen751ebf72007-10-07 17:31:42 +0000537int LLVMIsGlobalConstant(LLVMValueRef GlobalVar);
538void LLVMSetGlobalConstant(LLVMValueRef GlobalVar, int IsConstant);
Gordon Henriksen76a03742007-09-18 03:18:57 +0000539
Chris Lattner3d1f5522008-12-17 21:39:50 +0000540/* Operations on aliases */
541LLVMValueRef LLVMAddAlias(LLVMModuleRef M, LLVMTypeRef Ty, LLVMValueRef Aliasee,
542 const char *Name);
543
Gordon Henriksenc23b66c2007-09-26 20:56:12 +0000544/* Operations on functions */
545LLVMValueRef LLVMAddFunction(LLVMModuleRef M, const char *Name,
546 LLVMTypeRef FunctionTy);
Gordon Henriksen783f7bb2007-10-08 03:45:09 +0000547LLVMValueRef LLVMGetNamedFunction(LLVMModuleRef M, const char *Name);
Gordon Henriksen054817c2008-03-19 03:47:18 +0000548LLVMValueRef LLVMGetFirstFunction(LLVMModuleRef M);
549LLVMValueRef LLVMGetLastFunction(LLVMModuleRef M);
550LLVMValueRef LLVMGetNextFunction(LLVMValueRef Fn);
551LLVMValueRef LLVMGetPreviousFunction(LLVMValueRef Fn);
Gordon Henriksenc23b66c2007-09-26 20:56:12 +0000552void LLVMDeleteFunction(LLVMValueRef Fn);
Gordon Henriksenc23b66c2007-09-26 20:56:12 +0000553unsigned LLVMGetIntrinsicID(LLVMValueRef Fn);
554unsigned LLVMGetFunctionCallConv(LLVMValueRef Fn);
555void LLVMSetFunctionCallConv(LLVMValueRef Fn, unsigned CC);
Gordon Henriksend930f912008-08-17 18:44:35 +0000556const char *LLVMGetGC(LLVMValueRef Fn);
557void LLVMSetGC(LLVMValueRef Fn, const char *Name);
Duncan Sands7374a012009-05-06 12:21:17 +0000558void LLVMAddFunctionAttr(LLVMValueRef Fn, LLVMAttribute PA);
559void LLVMRemoveFunctionAttr(LLVMValueRef Fn, LLVMAttribute PA);
Gordon Henriksenc23b66c2007-09-26 20:56:12 +0000560
Gordon Henriksen265f7802008-03-19 01:11:35 +0000561/* Operations on parameters */
562unsigned LLVMCountParams(LLVMValueRef Fn);
563void LLVMGetParams(LLVMValueRef Fn, LLVMValueRef *Params);
564LLVMValueRef LLVMGetParam(LLVMValueRef Fn, unsigned Index);
565LLVMValueRef LLVMGetParamParent(LLVMValueRef Inst);
Gordon Henriksen07a45f42008-03-23 22:21:29 +0000566LLVMValueRef LLVMGetFirstParam(LLVMValueRef Fn);
567LLVMValueRef LLVMGetLastParam(LLVMValueRef Fn);
568LLVMValueRef LLVMGetNextParam(LLVMValueRef Arg);
569LLVMValueRef LLVMGetPreviousParam(LLVMValueRef Arg);
Devang Patel4c758ea2008-09-25 21:00:45 +0000570void LLVMAddAttribute(LLVMValueRef Arg, LLVMAttribute PA);
571void LLVMRemoveAttribute(LLVMValueRef Arg, LLVMAttribute PA);
Gordon Henriksen2d9cc212008-04-28 17:37:06 +0000572void LLVMSetParamAlignment(LLVMValueRef Arg, unsigned align);
Gordon Henriksen265f7802008-03-19 01:11:35 +0000573
Gordon Henriksenc23b66c2007-09-26 20:56:12 +0000574/* Operations on basic blocks */
Gordon Henriksen07a45f42008-03-23 22:21:29 +0000575LLVMValueRef LLVMBasicBlockAsValue(LLVMBasicBlockRef BB);
Gordon Henriksenc23b66c2007-09-26 20:56:12 +0000576int LLVMValueIsBasicBlock(LLVMValueRef Val);
577LLVMBasicBlockRef LLVMValueAsBasicBlock(LLVMValueRef Val);
Gordon Henriksen07a45f42008-03-23 22:21:29 +0000578LLVMValueRef LLVMGetBasicBlockParent(LLVMBasicBlockRef BB);
Gordon Henriksenc23b66c2007-09-26 20:56:12 +0000579unsigned LLVMCountBasicBlocks(LLVMValueRef Fn);
580void LLVMGetBasicBlocks(LLVMValueRef Fn, LLVMBasicBlockRef *BasicBlocks);
Gordon Henriksen054817c2008-03-19 03:47:18 +0000581LLVMBasicBlockRef LLVMGetFirstBasicBlock(LLVMValueRef Fn);
582LLVMBasicBlockRef LLVMGetLastBasicBlock(LLVMValueRef Fn);
583LLVMBasicBlockRef LLVMGetNextBasicBlock(LLVMBasicBlockRef BB);
584LLVMBasicBlockRef LLVMGetPreviousBasicBlock(LLVMBasicBlockRef BB);
Gordon Henriksenc23b66c2007-09-26 20:56:12 +0000585LLVMBasicBlockRef LLVMGetEntryBasicBlock(LLVMValueRef Fn);
Erick Tryzelaar262332f2009-08-14 00:01:31 +0000586
587LLVMBasicBlockRef LLVMAppendBasicBlockInContext(LLVMContextRef C,
588 LLVMValueRef Fn,
589 const char *Name);
590LLVMBasicBlockRef LLVMInsertBasicBlockInContext(LLVMContextRef C,
591 LLVMBasicBlockRef BB,
592 const char *Name);
593
Gordon Henriksenc23b66c2007-09-26 20:56:12 +0000594LLVMBasicBlockRef LLVMAppendBasicBlock(LLVMValueRef Fn, const char *Name);
595LLVMBasicBlockRef LLVMInsertBasicBlock(LLVMBasicBlockRef InsertBeforeBB,
596 const char *Name);
597void LLVMDeleteBasicBlock(LLVMBasicBlockRef BB);
598
Gordon Henriksen265f7802008-03-19 01:11:35 +0000599/* Operations on instructions */
600LLVMBasicBlockRef LLVMGetInstructionParent(LLVMValueRef Inst);
Gordon Henriksen054817c2008-03-19 03:47:18 +0000601LLVMValueRef LLVMGetFirstInstruction(LLVMBasicBlockRef BB);
602LLVMValueRef LLVMGetLastInstruction(LLVMBasicBlockRef BB);
603LLVMValueRef LLVMGetNextInstruction(LLVMValueRef Inst);
604LLVMValueRef LLVMGetPreviousInstruction(LLVMValueRef Inst);
Gordon Henriksen265f7802008-03-19 01:11:35 +0000605
Gordon Henriksen1158c532007-12-29 20:45:00 +0000606/* Operations on call sites */
607void LLVMSetInstructionCallConv(LLVMValueRef Instr, unsigned CC);
608unsigned LLVMGetInstructionCallConv(LLVMValueRef Instr);
Devang Patel4c758ea2008-09-25 21:00:45 +0000609void LLVMAddInstrAttribute(LLVMValueRef Instr, unsigned index, LLVMAttribute);
610void LLVMRemoveInstrAttribute(LLVMValueRef Instr, unsigned index,
611 LLVMAttribute);
Gordon Henriksen2d9cc212008-04-28 17:37:06 +0000612void LLVMSetInstrParamAlignment(LLVMValueRef Instr, unsigned index,
613 unsigned align);
Gordon Henriksen1158c532007-12-29 20:45:00 +0000614
Gordon Henrikseneeb65372008-08-30 16:34:54 +0000615/* Operations on call instructions (only) */
616int LLVMIsTailCall(LLVMValueRef CallInst);
617void LLVMSetTailCall(LLVMValueRef CallInst, int IsTailCall);
618
Gordon Henriksen44dd8fb2007-10-08 18:14:39 +0000619/* Operations on phi nodes */
620void LLVMAddIncoming(LLVMValueRef PhiNode, LLVMValueRef *IncomingValues,
621 LLVMBasicBlockRef *IncomingBlocks, unsigned Count);
622unsigned LLVMCountIncoming(LLVMValueRef PhiNode);
623LLVMValueRef LLVMGetIncomingValue(LLVMValueRef PhiNode, unsigned Index);
624LLVMBasicBlockRef LLVMGetIncomingBlock(LLVMValueRef PhiNode, unsigned Index);
Gordon Henriksenc23b66c2007-09-26 20:56:12 +0000625
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
Erick Tryzelaar262332f2009-08-14 00:01:31 +0000632LLVMBuilderRef LLVMCreateBuilderInContext(LLVMContextRef C);
Gordon Henriksena735a9c2008-05-04 12:55:34 +0000633LLVMBuilderRef LLVMCreateBuilder(void);
Gordon Henriksen054817c2008-03-19 03:47:18 +0000634void LLVMPositionBuilder(LLVMBuilderRef Builder, LLVMBasicBlockRef Block,
635 LLVMValueRef Instr);
Gordon Henriksenc23b66c2007-09-26 20:56:12 +0000636void LLVMPositionBuilderBefore(LLVMBuilderRef Builder, LLVMValueRef Instr);
637void LLVMPositionBuilderAtEnd(LLVMBuilderRef Builder, LLVMBasicBlockRef Block);
Gordon Henriksen265f7802008-03-19 01:11:35 +0000638LLVMBasicBlockRef LLVMGetInsertBlock(LLVMBuilderRef Builder);
Chris Lattner3d1f5522008-12-17 21:39:50 +0000639void LLVMClearInsertionPosition(LLVMBuilderRef Builder);
640void LLVMInsertIntoBuilder(LLVMBuilderRef Builder, LLVMValueRef Instr);
Gordon Henriksenc23b66c2007-09-26 20:56:12 +0000641void LLVMDisposeBuilder(LLVMBuilderRef Builder);
642
643/* Terminators */
644LLVMValueRef LLVMBuildRetVoid(LLVMBuilderRef);
645LLVMValueRef LLVMBuildRet(LLVMBuilderRef, LLVMValueRef V);
646LLVMValueRef LLVMBuildBr(LLVMBuilderRef, LLVMBasicBlockRef Dest);
647LLVMValueRef LLVMBuildCondBr(LLVMBuilderRef, LLVMValueRef If,
648 LLVMBasicBlockRef Then, LLVMBasicBlockRef Else);
649LLVMValueRef LLVMBuildSwitch(LLVMBuilderRef, LLVMValueRef V,
650 LLVMBasicBlockRef Else, unsigned NumCases);
651LLVMValueRef LLVMBuildInvoke(LLVMBuilderRef, LLVMValueRef Fn,
652 LLVMValueRef *Args, unsigned NumArgs,
653 LLVMBasicBlockRef Then, LLVMBasicBlockRef Catch,
654 const char *Name);
655LLVMValueRef LLVMBuildUnwind(LLVMBuilderRef);
656LLVMValueRef LLVMBuildUnreachable(LLVMBuilderRef);
657
Gordon Henriksen097102c2008-01-01 05:50:53 +0000658/* Add a case to the switch instruction */
659void LLVMAddCase(LLVMValueRef Switch, LLVMValueRef OnVal,
660 LLVMBasicBlockRef Dest);
661
Gordon Henriksenc23b66c2007-09-26 20:56:12 +0000662/* Arithmetic */
663LLVMValueRef LLVMBuildAdd(LLVMBuilderRef, LLVMValueRef LHS, LLVMValueRef RHS,
664 const char *Name);
665LLVMValueRef LLVMBuildSub(LLVMBuilderRef, LLVMValueRef LHS, LLVMValueRef RHS,
666 const char *Name);
667LLVMValueRef LLVMBuildMul(LLVMBuilderRef, LLVMValueRef LHS, LLVMValueRef RHS,
668 const char *Name);
669LLVMValueRef LLVMBuildUDiv(LLVMBuilderRef, LLVMValueRef LHS, LLVMValueRef RHS,
670 const char *Name);
671LLVMValueRef LLVMBuildSDiv(LLVMBuilderRef, LLVMValueRef LHS, LLVMValueRef RHS,
672 const char *Name);
673LLVMValueRef LLVMBuildFDiv(LLVMBuilderRef, LLVMValueRef LHS, LLVMValueRef RHS,
674 const char *Name);
675LLVMValueRef LLVMBuildURem(LLVMBuilderRef, LLVMValueRef LHS, LLVMValueRef RHS,
676 const char *Name);
677LLVMValueRef LLVMBuildSRem(LLVMBuilderRef, LLVMValueRef LHS, LLVMValueRef RHS,
678 const char *Name);
679LLVMValueRef LLVMBuildFRem(LLVMBuilderRef, LLVMValueRef LHS, LLVMValueRef RHS,
680 const char *Name);
681LLVMValueRef LLVMBuildShl(LLVMBuilderRef, LLVMValueRef LHS, LLVMValueRef RHS,
682 const char *Name);
683LLVMValueRef LLVMBuildLShr(LLVMBuilderRef, LLVMValueRef LHS, LLVMValueRef RHS,
684 const char *Name);
685LLVMValueRef LLVMBuildAShr(LLVMBuilderRef, LLVMValueRef LHS, LLVMValueRef RHS,
686 const char *Name);
687LLVMValueRef LLVMBuildAnd(LLVMBuilderRef, LLVMValueRef LHS, LLVMValueRef RHS,
688 const char *Name);
689LLVMValueRef LLVMBuildOr(LLVMBuilderRef, LLVMValueRef LHS, LLVMValueRef RHS,
690 const char *Name);
691LLVMValueRef LLVMBuildXor(LLVMBuilderRef, LLVMValueRef LHS, LLVMValueRef RHS,
692 const char *Name);
693LLVMValueRef LLVMBuildNeg(LLVMBuilderRef, LLVMValueRef V, const char *Name);
694LLVMValueRef LLVMBuildNot(LLVMBuilderRef, LLVMValueRef V, const char *Name);
695
696/* Memory */
697LLVMValueRef LLVMBuildMalloc(LLVMBuilderRef, LLVMTypeRef Ty, const char *Name);
698LLVMValueRef LLVMBuildArrayMalloc(LLVMBuilderRef, LLVMTypeRef Ty,
699 LLVMValueRef Val, const char *Name);
700LLVMValueRef LLVMBuildAlloca(LLVMBuilderRef, LLVMTypeRef Ty, const char *Name);
701LLVMValueRef LLVMBuildArrayAlloca(LLVMBuilderRef, LLVMTypeRef Ty,
702 LLVMValueRef Val, const char *Name);
703LLVMValueRef LLVMBuildFree(LLVMBuilderRef, LLVMValueRef PointerVal);
704LLVMValueRef LLVMBuildLoad(LLVMBuilderRef, LLVMValueRef PointerVal,
705 const char *Name);
706LLVMValueRef LLVMBuildStore(LLVMBuilderRef, LLVMValueRef Val, LLVMValueRef Ptr);
707LLVMValueRef LLVMBuildGEP(LLVMBuilderRef B, LLVMValueRef Pointer,
708 LLVMValueRef *Indices, unsigned NumIndices,
709 const char *Name);
710
711/* Casts */
712LLVMValueRef LLVMBuildTrunc(LLVMBuilderRef, LLVMValueRef Val,
713 LLVMTypeRef DestTy, const char *Name);
714LLVMValueRef LLVMBuildZExt(LLVMBuilderRef, LLVMValueRef Val,
715 LLVMTypeRef DestTy, const char *Name);
716LLVMValueRef LLVMBuildSExt(LLVMBuilderRef, LLVMValueRef Val,
717 LLVMTypeRef DestTy, const char *Name);
718LLVMValueRef LLVMBuildFPToUI(LLVMBuilderRef, LLVMValueRef Val,
719 LLVMTypeRef DestTy, const char *Name);
720LLVMValueRef LLVMBuildFPToSI(LLVMBuilderRef, LLVMValueRef Val,
721 LLVMTypeRef DestTy, const char *Name);
722LLVMValueRef LLVMBuildUIToFP(LLVMBuilderRef, LLVMValueRef Val,
723 LLVMTypeRef DestTy, const char *Name);
724LLVMValueRef LLVMBuildSIToFP(LLVMBuilderRef, LLVMValueRef Val,
725 LLVMTypeRef DestTy, const char *Name);
726LLVMValueRef LLVMBuildFPTrunc(LLVMBuilderRef, LLVMValueRef Val,
727 LLVMTypeRef DestTy, const char *Name);
728LLVMValueRef LLVMBuildFPExt(LLVMBuilderRef, LLVMValueRef Val,
729 LLVMTypeRef DestTy, const char *Name);
730LLVMValueRef LLVMBuildPtrToInt(LLVMBuilderRef, LLVMValueRef Val,
731 LLVMTypeRef DestTy, const char *Name);
732LLVMValueRef LLVMBuildIntToPtr(LLVMBuilderRef, LLVMValueRef Val,
733 LLVMTypeRef DestTy, const char *Name);
734LLVMValueRef LLVMBuildBitCast(LLVMBuilderRef, LLVMValueRef Val,
735 LLVMTypeRef DestTy, const char *Name);
736
737/* Comparisons */
738LLVMValueRef LLVMBuildICmp(LLVMBuilderRef, LLVMIntPredicate Op,
739 LLVMValueRef LHS, LLVMValueRef RHS,
740 const char *Name);
741LLVMValueRef LLVMBuildFCmp(LLVMBuilderRef, LLVMRealPredicate Op,
742 LLVMValueRef LHS, LLVMValueRef RHS,
743 const char *Name);
744
745/* Miscellaneous instructions */
746LLVMValueRef LLVMBuildPhi(LLVMBuilderRef, LLVMTypeRef Ty, const char *Name);
747LLVMValueRef LLVMBuildCall(LLVMBuilderRef, LLVMValueRef Fn,
748 LLVMValueRef *Args, unsigned NumArgs,
749 const char *Name);
750LLVMValueRef LLVMBuildSelect(LLVMBuilderRef, LLVMValueRef If,
751 LLVMValueRef Then, LLVMValueRef Else,
752 const char *Name);
753LLVMValueRef LLVMBuildVAArg(LLVMBuilderRef, LLVMValueRef List, LLVMTypeRef Ty,
754 const char *Name);
755LLVMValueRef LLVMBuildExtractElement(LLVMBuilderRef, LLVMValueRef VecVal,
756 LLVMValueRef Index, const char *Name);
757LLVMValueRef LLVMBuildInsertElement(LLVMBuilderRef, LLVMValueRef VecVal,
758 LLVMValueRef EltVal, LLVMValueRef Index,
759 const char *Name);
760LLVMValueRef LLVMBuildShuffleVector(LLVMBuilderRef, LLVMValueRef V1,
761 LLVMValueRef V2, LLVMValueRef Mask,
762 const char *Name);
Dan Gohmand5104a52008-11-03 22:55:43 +0000763LLVMValueRef LLVMBuildExtractValue(LLVMBuilderRef, LLVMValueRef AggVal,
764 unsigned Index, const char *Name);
765LLVMValueRef LLVMBuildInsertValue(LLVMBuilderRef, LLVMValueRef AggVal,
766 LLVMValueRef EltVal, unsigned Index,
767 const char *Name);
Gordon Henriksen76a03742007-09-18 03:18:57 +0000768
Gordon Henriksen34eb6d82007-12-19 22:30:40 +0000769
Gordon Henriksen0a68fe22007-12-12 01:04:30 +0000770/*===-- Module providers --------------------------------------------------===*/
771
772/* Encapsulates the module M in a module provider, taking ownership of the
773 * module.
774 * See the constructor llvm::ExistingModuleProvider::ExistingModuleProvider.
775 */
776LLVMModuleProviderRef
777LLVMCreateModuleProviderForExistingModule(LLVMModuleRef M);
778
779/* Destroys the module provider MP as well as the contained module.
780 * See the destructor llvm::ModuleProvider::~ModuleProvider.
781 */
782void LLVMDisposeModuleProvider(LLVMModuleProviderRef MP);
783
Gordon Henriksen34eb6d82007-12-19 22:30:40 +0000784
785/*===-- Memory buffers ----------------------------------------------------===*/
786
787int LLVMCreateMemoryBufferWithContentsOfFile(const char *Path,
788 LLVMMemoryBufferRef *OutMemBuf,
789 char **OutMessage);
790int LLVMCreateMemoryBufferWithSTDIN(LLVMMemoryBufferRef *OutMemBuf,
791 char **OutMessage);
792void LLVMDisposeMemoryBuffer(LLVMMemoryBufferRef MemBuf);
793
Gordon Henriksen878114b2008-03-16 04:20:44 +0000794
795/*===-- Pass Managers -----------------------------------------------------===*/
796
797/** Constructs a new whole-module pass pipeline. This type of pipeline is
798 suitable for link-time optimization and whole-module transformations.
799 See llvm::PassManager::PassManager. */
Gordon Henriksena735a9c2008-05-04 12:55:34 +0000800LLVMPassManagerRef LLVMCreatePassManager(void);
Gordon Henriksen878114b2008-03-16 04:20:44 +0000801
802/** Constructs a new function-by-function pass pipeline over the module
803 provider. It does not take ownership of the module provider. This type of
804 pipeline is suitable for code generation and JIT compilation tasks.
805 See llvm::FunctionPassManager::FunctionPassManager. */
806LLVMPassManagerRef LLVMCreateFunctionPassManager(LLVMModuleProviderRef MP);
807
808/** Initializes, executes on the provided module, and finalizes all of the
809 passes scheduled in the pass manager. Returns 1 if any of the passes
810 modified the module, 0 otherwise. See llvm::PassManager::run(Module&). */
811int LLVMRunPassManager(LLVMPassManagerRef PM, LLVMModuleRef M);
812
813/** Initializes all of the function passes scheduled in the function pass
814 manager. Returns 1 if any of the passes modified the module, 0 otherwise.
815 See llvm::FunctionPassManager::doInitialization. */
816int LLVMInitializeFunctionPassManager(LLVMPassManagerRef FPM);
817
818/** Executes all of the function passes scheduled in the function pass manager
819 on the provided function. Returns 1 if any of the passes modified the
820 function, false otherwise.
821 See llvm::FunctionPassManager::run(Function&). */
822int LLVMRunFunctionPassManager(LLVMPassManagerRef FPM, LLVMValueRef F);
823
824/** Finalizes all of the function passes scheduled in in the function pass
825 manager. Returns 1 if any of the passes modified the module, 0 otherwise.
826 See llvm::FunctionPassManager::doFinalization. */
827int LLVMFinalizeFunctionPassManager(LLVMPassManagerRef FPM);
828
829/** Frees the memory of a pass pipeline. For function pipelines, does not free
830 the module provider.
831 See llvm::PassManagerBase::~PassManagerBase. */
832void LLVMDisposePassManager(LLVMPassManagerRef PM);
833
834
Gordon Henriksen76a03742007-09-18 03:18:57 +0000835#ifdef __cplusplus
836}
Gordon Henriksen76a03742007-09-18 03:18:57 +0000837
Gordon Henriksen7330acd2007-10-05 23:59:36 +0000838namespace llvm {
Gordon Henriksen0a68fe22007-12-12 01:04:30 +0000839 class ModuleProvider;
Gordon Henriksen34eb6d82007-12-19 22:30:40 +0000840 class MemoryBuffer;
Gordon Henriksen96571492008-03-16 15:55:43 +0000841 class PassManagerBase;
Gordon Henriksen0a68fe22007-12-12 01:04:30 +0000842
Gordon Henriksen34eb6d82007-12-19 22:30:40 +0000843 #define DEFINE_SIMPLE_CONVERSION_FUNCTIONS(ty, ref) \
844 inline ty *unwrap(ref P) { \
845 return reinterpret_cast<ty*>(P); \
846 } \
847 \
848 inline ref wrap(const ty *P) { \
849 return reinterpret_cast<ref>(const_cast<ty*>(P)); \
850 }
Gordon Henriksen7330acd2007-10-05 23:59:36 +0000851
Gordon Henriksen878114b2008-03-16 04:20:44 +0000852 #define DEFINE_ISA_CONVERSION_FUNCTIONS(ty, ref) \
853 DEFINE_SIMPLE_CONVERSION_FUNCTIONS(ty, ref) \
854 \
855 template<typename T> \
856 inline T *unwrap(ref P) { \
857 return cast<T>(unwrap(P)); \
858 }
859
860 #define DEFINE_STDCXX_CONVERSION_FUNCTIONS(ty, ref) \
861 DEFINE_SIMPLE_CONVERSION_FUNCTIONS(ty, ref) \
862 \
863 template<typename T> \
864 inline T *unwrap(ref P) { \
865 T *Q = dynamic_cast<T*>(unwrap(P)); \
866 assert(Q && "Invalid cast!"); \
867 return Q; \
868 }
869
870 DEFINE_ISA_CONVERSION_FUNCTIONS (Type, LLVMTypeRef )
871 DEFINE_ISA_CONVERSION_FUNCTIONS (Value, LLVMValueRef )
Gordon Henriksen823f9732007-12-27 18:25:59 +0000872 DEFINE_SIMPLE_CONVERSION_FUNCTIONS(Module, LLVMModuleRef )
873 DEFINE_SIMPLE_CONVERSION_FUNCTIONS(BasicBlock, LLVMBasicBlockRef )
Eric Christopher59278832008-08-08 19:39:37 +0000874 DEFINE_SIMPLE_CONVERSION_FUNCTIONS(IRBuilder<>, LLVMBuilderRef )
Gordon Henriksen823f9732007-12-27 18:25:59 +0000875 DEFINE_SIMPLE_CONVERSION_FUNCTIONS(PATypeHolder, LLVMTypeHandleRef )
876 DEFINE_SIMPLE_CONVERSION_FUNCTIONS(ModuleProvider, LLVMModuleProviderRef)
877 DEFINE_SIMPLE_CONVERSION_FUNCTIONS(MemoryBuffer, LLVMMemoryBufferRef )
Owen Anderson6773d382009-07-01 16:58:40 +0000878 DEFINE_SIMPLE_CONVERSION_FUNCTIONS(LLVMContext, LLVMContextRef )
Gordon Henriksen878114b2008-03-16 04:20:44 +0000879 DEFINE_STDCXX_CONVERSION_FUNCTIONS(PassManagerBase, LLVMPassManagerRef )
Gordon Henriksen7330acd2007-10-05 23:59:36 +0000880
Gordon Henriksen878114b2008-03-16 04:20:44 +0000881 #undef DEFINE_STDCXX_CONVERSION_FUNCTIONS
882 #undef DEFINE_ISA_CONVERSION_FUNCTIONS
Gordon Henriksen34eb6d82007-12-19 22:30:40 +0000883 #undef DEFINE_SIMPLE_CONVERSION_FUNCTIONS
Erick Tryzelaar262332f2009-08-14 00:01:31 +0000884
885 /* Specialized opaque context conversions.
886 */
887 inline LLVMContext **unwrap(LLVMContextRef* Tys) {
888 return reinterpret_cast<LLVMContext**>(Tys);
889 }
890
891 inline LLVMContextRef *wrap(const LLVMContext **Tys) {
892 return reinterpret_cast<LLVMContextRef*>(const_cast<LLVMContext**>(Tys));
893 }
Gordon Henriksen7330acd2007-10-05 23:59:36 +0000894
Gordon Henriksen34eb6d82007-12-19 22:30:40 +0000895 /* Specialized opaque type conversions.
896 */
Gordon Henriksen7330acd2007-10-05 23:59:36 +0000897 inline Type **unwrap(LLVMTypeRef* Tys) {
898 return reinterpret_cast<Type**>(Tys);
899 }
900
Gordon Henriksen7330acd2007-10-05 23:59:36 +0000901 inline LLVMTypeRef *wrap(const Type **Tys) {
902 return reinterpret_cast<LLVMTypeRef*>(const_cast<Type**>(Tys));
903 }
904
Gordon Henriksen34eb6d82007-12-19 22:30:40 +0000905 /* Specialized opaque value conversions.
Gordon Henriksen7330acd2007-10-05 23:59:36 +0000906 */
Gordon Henriksen7330acd2007-10-05 23:59:36 +0000907 inline Value **unwrap(LLVMValueRef *Vals) {
908 return reinterpret_cast<Value**>(Vals);
909 }
910
911 template<typename T>
912 inline T **unwrap(LLVMValueRef *Vals, unsigned Length) {
913 #if DEBUG
Chris Lattnerb7971152009-07-10 18:28:19 +0000914 for (LLVMValueRef *I = Vals, *E = Vals + Length; I != E; ++I)
Gordon Henriksen7330acd2007-10-05 23:59:36 +0000915 cast<T>(*I);
916 #endif
917 return reinterpret_cast<T**>(Vals);
918 }
919
Gordon Henriksen7330acd2007-10-05 23:59:36 +0000920 inline LLVMValueRef *wrap(const Value **Vals) {
921 return reinterpret_cast<LLVMValueRef*>(const_cast<Value**>(Vals));
922 }
Gordon Henriksen7330acd2007-10-05 23:59:36 +0000923}
924
925#endif /* !defined(__cplusplus) */
926
927#endif /* !defined(LLVM_C_CORE_H) */