blob: 17229b4a6f5955a0b6f45e433f7df686617571ec [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);
Erick Tryzelaar3045b8b2009-08-16 02:19:59 +0000646LLVMValueRef LLVMBuildAggregateRet(LLVMBuilderRef, LLVMValueRef RetVals,
647 unsigned N);
Gordon Henriksenc23b66c2007-09-26 20:56:12 +0000648LLVMValueRef LLVMBuildBr(LLVMBuilderRef, LLVMBasicBlockRef Dest);
649LLVMValueRef LLVMBuildCondBr(LLVMBuilderRef, LLVMValueRef If,
650 LLVMBasicBlockRef Then, LLVMBasicBlockRef Else);
651LLVMValueRef LLVMBuildSwitch(LLVMBuilderRef, LLVMValueRef V,
652 LLVMBasicBlockRef Else, unsigned NumCases);
653LLVMValueRef LLVMBuildInvoke(LLVMBuilderRef, LLVMValueRef Fn,
654 LLVMValueRef *Args, unsigned NumArgs,
655 LLVMBasicBlockRef Then, LLVMBasicBlockRef Catch,
656 const char *Name);
657LLVMValueRef LLVMBuildUnwind(LLVMBuilderRef);
658LLVMValueRef LLVMBuildUnreachable(LLVMBuilderRef);
659
Gordon Henriksen097102c2008-01-01 05:50:53 +0000660/* Add a case to the switch instruction */
661void LLVMAddCase(LLVMValueRef Switch, LLVMValueRef OnVal,
662 LLVMBasicBlockRef Dest);
663
Gordon Henriksenc23b66c2007-09-26 20:56:12 +0000664/* Arithmetic */
665LLVMValueRef LLVMBuildAdd(LLVMBuilderRef, LLVMValueRef LHS, LLVMValueRef RHS,
666 const char *Name);
Erick Tryzelaar3045b8b2009-08-16 02:19:59 +0000667LLVMValueRef LLVMBuildNSWAdd(LLVMBuilderRef, LLVMValueRef LHS, LLVMValueRef RHS,
668 const char *Name);
669LLVMValueRef LLVMBuildFAdd(LLVMBuilderRef, LLVMValueRef LHS, LLVMValueRef RHS,
670 const char *Name);
Gordon Henriksenc23b66c2007-09-26 20:56:12 +0000671LLVMValueRef LLVMBuildSub(LLVMBuilderRef, LLVMValueRef LHS, LLVMValueRef RHS,
672 const char *Name);
Erick Tryzelaar3045b8b2009-08-16 02:19:59 +0000673LLVMValueRef LLVMBuildFSub(LLVMBuilderRef, LLVMValueRef LHS, LLVMValueRef RHS,
674 const char *Name);
Gordon Henriksenc23b66c2007-09-26 20:56:12 +0000675LLVMValueRef LLVMBuildMul(LLVMBuilderRef, LLVMValueRef LHS, LLVMValueRef RHS,
676 const char *Name);
Erick Tryzelaar3045b8b2009-08-16 02:19:59 +0000677LLVMValueRef LLVMBuildFMul(LLVMBuilderRef, LLVMValueRef LHS, LLVMValueRef RHS,
678 const char *Name);
Gordon Henriksenc23b66c2007-09-26 20:56:12 +0000679LLVMValueRef LLVMBuildUDiv(LLVMBuilderRef, LLVMValueRef LHS, LLVMValueRef RHS,
680 const char *Name);
681LLVMValueRef LLVMBuildSDiv(LLVMBuilderRef, LLVMValueRef LHS, LLVMValueRef RHS,
682 const char *Name);
Erick Tryzelaar3045b8b2009-08-16 02:19:59 +0000683LLVMValueRef LLVMBuildExactSDiv(LLVMBuilderRef, LLVMValueRef LHS, LLVMValueRef RHS,
684 const char *Name);
Gordon Henriksenc23b66c2007-09-26 20:56:12 +0000685LLVMValueRef LLVMBuildFDiv(LLVMBuilderRef, LLVMValueRef LHS, LLVMValueRef RHS,
686 const char *Name);
687LLVMValueRef LLVMBuildURem(LLVMBuilderRef, LLVMValueRef LHS, LLVMValueRef RHS,
688 const char *Name);
689LLVMValueRef LLVMBuildSRem(LLVMBuilderRef, LLVMValueRef LHS, LLVMValueRef RHS,
690 const char *Name);
691LLVMValueRef LLVMBuildFRem(LLVMBuilderRef, LLVMValueRef LHS, LLVMValueRef RHS,
692 const char *Name);
693LLVMValueRef LLVMBuildShl(LLVMBuilderRef, LLVMValueRef LHS, LLVMValueRef RHS,
694 const char *Name);
695LLVMValueRef LLVMBuildLShr(LLVMBuilderRef, LLVMValueRef LHS, LLVMValueRef RHS,
696 const char *Name);
697LLVMValueRef LLVMBuildAShr(LLVMBuilderRef, LLVMValueRef LHS, LLVMValueRef RHS,
698 const char *Name);
699LLVMValueRef LLVMBuildAnd(LLVMBuilderRef, LLVMValueRef LHS, LLVMValueRef RHS,
700 const char *Name);
701LLVMValueRef LLVMBuildOr(LLVMBuilderRef, LLVMValueRef LHS, LLVMValueRef RHS,
702 const char *Name);
703LLVMValueRef LLVMBuildXor(LLVMBuilderRef, LLVMValueRef LHS, LLVMValueRef RHS,
704 const char *Name);
705LLVMValueRef LLVMBuildNeg(LLVMBuilderRef, LLVMValueRef V, const char *Name);
706LLVMValueRef LLVMBuildNot(LLVMBuilderRef, LLVMValueRef V, const char *Name);
707
708/* Memory */
709LLVMValueRef LLVMBuildMalloc(LLVMBuilderRef, LLVMTypeRef Ty, const char *Name);
710LLVMValueRef LLVMBuildArrayMalloc(LLVMBuilderRef, LLVMTypeRef Ty,
711 LLVMValueRef Val, const char *Name);
712LLVMValueRef LLVMBuildAlloca(LLVMBuilderRef, LLVMTypeRef Ty, const char *Name);
713LLVMValueRef LLVMBuildArrayAlloca(LLVMBuilderRef, LLVMTypeRef Ty,
714 LLVMValueRef Val, const char *Name);
715LLVMValueRef LLVMBuildFree(LLVMBuilderRef, LLVMValueRef PointerVal);
716LLVMValueRef LLVMBuildLoad(LLVMBuilderRef, LLVMValueRef PointerVal,
717 const char *Name);
718LLVMValueRef LLVMBuildStore(LLVMBuilderRef, LLVMValueRef Val, LLVMValueRef Ptr);
719LLVMValueRef LLVMBuildGEP(LLVMBuilderRef B, LLVMValueRef Pointer,
720 LLVMValueRef *Indices, unsigned NumIndices,
721 const char *Name);
Erick Tryzelaar3045b8b2009-08-16 02:19:59 +0000722LLVMValueRef LLVMBuildInBoundsGEP(LLVMBuilderRef B, LLVMValueRef Pointer,
723 LLVMValueRef *Indices, unsigned NumIndices,
724 const char *Name);
725LLVMValueRef LLVMBuildStructGEP(LLVMBuilderRef B, LLVMValueRef Pointer,
726 unsigned Idx, const char *Name);
727LLVMValueRef LLVMBuildGlobalString(LLVMBuilderRef B, const char *Str,
728 const char *Name);
729LLVMValueRef LLVMBuildGlobalStringPtr(LLVMBuilderRef B, const char *Str,
730 const char *Name);
Gordon Henriksenc23b66c2007-09-26 20:56:12 +0000731
732/* Casts */
733LLVMValueRef LLVMBuildTrunc(LLVMBuilderRef, LLVMValueRef Val,
734 LLVMTypeRef DestTy, const char *Name);
735LLVMValueRef LLVMBuildZExt(LLVMBuilderRef, LLVMValueRef Val,
736 LLVMTypeRef DestTy, const char *Name);
737LLVMValueRef LLVMBuildSExt(LLVMBuilderRef, LLVMValueRef Val,
738 LLVMTypeRef DestTy, const char *Name);
739LLVMValueRef LLVMBuildFPToUI(LLVMBuilderRef, LLVMValueRef Val,
740 LLVMTypeRef DestTy, const char *Name);
741LLVMValueRef LLVMBuildFPToSI(LLVMBuilderRef, LLVMValueRef Val,
742 LLVMTypeRef DestTy, const char *Name);
743LLVMValueRef LLVMBuildUIToFP(LLVMBuilderRef, LLVMValueRef Val,
744 LLVMTypeRef DestTy, const char *Name);
745LLVMValueRef LLVMBuildSIToFP(LLVMBuilderRef, LLVMValueRef Val,
746 LLVMTypeRef DestTy, const char *Name);
747LLVMValueRef LLVMBuildFPTrunc(LLVMBuilderRef, LLVMValueRef Val,
748 LLVMTypeRef DestTy, const char *Name);
749LLVMValueRef LLVMBuildFPExt(LLVMBuilderRef, LLVMValueRef Val,
750 LLVMTypeRef DestTy, const char *Name);
751LLVMValueRef LLVMBuildPtrToInt(LLVMBuilderRef, LLVMValueRef Val,
752 LLVMTypeRef DestTy, const char *Name);
753LLVMValueRef LLVMBuildIntToPtr(LLVMBuilderRef, LLVMValueRef Val,
754 LLVMTypeRef DestTy, const char *Name);
755LLVMValueRef LLVMBuildBitCast(LLVMBuilderRef, LLVMValueRef Val,
756 LLVMTypeRef DestTy, const char *Name);
Erick Tryzelaar3045b8b2009-08-16 02:19:59 +0000757LLVMValueRef LLVMBuildZExtOrBitCast(LLVMBuilderRef, LLVMValueRef Val,
758 LLVMTypeRef DestTy, const char *Name);
759LLVMValueRef LLVMBuildSExtOrBitCast(LLVMBuilderRef, LLVMValueRef Val,
760 LLVMTypeRef DestTy, const char *Name);
761LLVMValueRef LLVMBuildTruncOrBitCast(LLVMBuilderRef, LLVMValueRef Val,
762 LLVMTypeRef DestTy, const char *Name);
763LLVMValueRef LLVMBuildPointerCast(LLVMBuilderRef, LLVMValueRef Val,
764 LLVMTypeRef DestTy, const char *Name);
765LLVMValueRef LLVMBuildIntCast(LLVMBuilderRef, LLVMValueRef Val,
766 LLVMTypeRef DestTy, const char *Name);
767LLVMValueRef LLVMBuildFPCast(LLVMBuilderRef, LLVMValueRef Val,
768 LLVMTypeRef DestTy, const char *Name);
Gordon Henriksenc23b66c2007-09-26 20:56:12 +0000769
770/* Comparisons */
771LLVMValueRef LLVMBuildICmp(LLVMBuilderRef, LLVMIntPredicate Op,
772 LLVMValueRef LHS, LLVMValueRef RHS,
773 const char *Name);
774LLVMValueRef LLVMBuildFCmp(LLVMBuilderRef, LLVMRealPredicate Op,
775 LLVMValueRef LHS, LLVMValueRef RHS,
776 const char *Name);
777
778/* Miscellaneous instructions */
779LLVMValueRef LLVMBuildPhi(LLVMBuilderRef, LLVMTypeRef Ty, const char *Name);
780LLVMValueRef LLVMBuildCall(LLVMBuilderRef, LLVMValueRef Fn,
781 LLVMValueRef *Args, unsigned NumArgs,
782 const char *Name);
783LLVMValueRef LLVMBuildSelect(LLVMBuilderRef, LLVMValueRef If,
784 LLVMValueRef Then, LLVMValueRef Else,
785 const char *Name);
786LLVMValueRef LLVMBuildVAArg(LLVMBuilderRef, LLVMValueRef List, LLVMTypeRef Ty,
787 const char *Name);
788LLVMValueRef LLVMBuildExtractElement(LLVMBuilderRef, LLVMValueRef VecVal,
789 LLVMValueRef Index, const char *Name);
790LLVMValueRef LLVMBuildInsertElement(LLVMBuilderRef, LLVMValueRef VecVal,
791 LLVMValueRef EltVal, LLVMValueRef Index,
792 const char *Name);
793LLVMValueRef LLVMBuildShuffleVector(LLVMBuilderRef, LLVMValueRef V1,
794 LLVMValueRef V2, LLVMValueRef Mask,
795 const char *Name);
Dan Gohmand5104a52008-11-03 22:55:43 +0000796LLVMValueRef LLVMBuildExtractValue(LLVMBuilderRef, LLVMValueRef AggVal,
797 unsigned Index, const char *Name);
798LLVMValueRef LLVMBuildInsertValue(LLVMBuilderRef, LLVMValueRef AggVal,
799 LLVMValueRef EltVal, unsigned Index,
800 const char *Name);
Gordon Henriksen76a03742007-09-18 03:18:57 +0000801
Erick Tryzelaar3045b8b2009-08-16 02:19:59 +0000802LLVMValueRef LLVMBuildIsNull(LLVMBuilderRef, LLVMValueRef Val,
803 const char *Name);
804LLVMValueRef LLVMBuildIsNotNull(LLVMBuilderRef, LLVMValueRef Val,
805 const char *Name);
806LLVMValueRef LLVMBuildPtrDiff(LLVMBuilderRef, LLVMValueRef LHS,
807 LLVMValueRef RHS, const char *Name);
808
Gordon Henriksen34eb6d82007-12-19 22:30:40 +0000809
Gordon Henriksen0a68fe22007-12-12 01:04:30 +0000810/*===-- Module providers --------------------------------------------------===*/
811
812/* Encapsulates the module M in a module provider, taking ownership of the
813 * module.
814 * See the constructor llvm::ExistingModuleProvider::ExistingModuleProvider.
815 */
816LLVMModuleProviderRef
817LLVMCreateModuleProviderForExistingModule(LLVMModuleRef M);
818
819/* Destroys the module provider MP as well as the contained module.
820 * See the destructor llvm::ModuleProvider::~ModuleProvider.
821 */
822void LLVMDisposeModuleProvider(LLVMModuleProviderRef MP);
823
Gordon Henriksen34eb6d82007-12-19 22:30:40 +0000824
825/*===-- Memory buffers ----------------------------------------------------===*/
826
827int LLVMCreateMemoryBufferWithContentsOfFile(const char *Path,
828 LLVMMemoryBufferRef *OutMemBuf,
829 char **OutMessage);
830int LLVMCreateMemoryBufferWithSTDIN(LLVMMemoryBufferRef *OutMemBuf,
831 char **OutMessage);
832void LLVMDisposeMemoryBuffer(LLVMMemoryBufferRef MemBuf);
833
Gordon Henriksen878114b2008-03-16 04:20:44 +0000834
835/*===-- Pass Managers -----------------------------------------------------===*/
836
837/** Constructs a new whole-module pass pipeline. This type of pipeline is
838 suitable for link-time optimization and whole-module transformations.
839 See llvm::PassManager::PassManager. */
Gordon Henriksena735a9c2008-05-04 12:55:34 +0000840LLVMPassManagerRef LLVMCreatePassManager(void);
Gordon Henriksen878114b2008-03-16 04:20:44 +0000841
842/** Constructs a new function-by-function pass pipeline over the module
843 provider. It does not take ownership of the module provider. This type of
844 pipeline is suitable for code generation and JIT compilation tasks.
845 See llvm::FunctionPassManager::FunctionPassManager. */
846LLVMPassManagerRef LLVMCreateFunctionPassManager(LLVMModuleProviderRef MP);
847
848/** Initializes, executes on the provided module, and finalizes all of the
849 passes scheduled in the pass manager. Returns 1 if any of the passes
850 modified the module, 0 otherwise. See llvm::PassManager::run(Module&). */
851int LLVMRunPassManager(LLVMPassManagerRef PM, LLVMModuleRef M);
852
853/** Initializes all of the function passes scheduled in the function pass
854 manager. Returns 1 if any of the passes modified the module, 0 otherwise.
855 See llvm::FunctionPassManager::doInitialization. */
856int LLVMInitializeFunctionPassManager(LLVMPassManagerRef FPM);
857
858/** Executes all of the function passes scheduled in the function pass manager
859 on the provided function. Returns 1 if any of the passes modified the
860 function, false otherwise.
861 See llvm::FunctionPassManager::run(Function&). */
862int LLVMRunFunctionPassManager(LLVMPassManagerRef FPM, LLVMValueRef F);
863
864/** Finalizes all of the function passes scheduled in in the function pass
865 manager. Returns 1 if any of the passes modified the module, 0 otherwise.
866 See llvm::FunctionPassManager::doFinalization. */
867int LLVMFinalizeFunctionPassManager(LLVMPassManagerRef FPM);
868
869/** Frees the memory of a pass pipeline. For function pipelines, does not free
870 the module provider.
871 See llvm::PassManagerBase::~PassManagerBase. */
872void LLVMDisposePassManager(LLVMPassManagerRef PM);
873
874
Gordon Henriksen76a03742007-09-18 03:18:57 +0000875#ifdef __cplusplus
876}
Gordon Henriksen76a03742007-09-18 03:18:57 +0000877
Gordon Henriksen7330acd2007-10-05 23:59:36 +0000878namespace llvm {
Gordon Henriksen0a68fe22007-12-12 01:04:30 +0000879 class ModuleProvider;
Gordon Henriksen34eb6d82007-12-19 22:30:40 +0000880 class MemoryBuffer;
Gordon Henriksen96571492008-03-16 15:55:43 +0000881 class PassManagerBase;
Gordon Henriksen0a68fe22007-12-12 01:04:30 +0000882
Gordon Henriksen34eb6d82007-12-19 22:30:40 +0000883 #define DEFINE_SIMPLE_CONVERSION_FUNCTIONS(ty, ref) \
884 inline ty *unwrap(ref P) { \
885 return reinterpret_cast<ty*>(P); \
886 } \
887 \
888 inline ref wrap(const ty *P) { \
889 return reinterpret_cast<ref>(const_cast<ty*>(P)); \
890 }
Gordon Henriksen7330acd2007-10-05 23:59:36 +0000891
Gordon Henriksen878114b2008-03-16 04:20:44 +0000892 #define DEFINE_ISA_CONVERSION_FUNCTIONS(ty, ref) \
893 DEFINE_SIMPLE_CONVERSION_FUNCTIONS(ty, ref) \
894 \
895 template<typename T> \
896 inline T *unwrap(ref P) { \
897 return cast<T>(unwrap(P)); \
898 }
899
900 #define DEFINE_STDCXX_CONVERSION_FUNCTIONS(ty, ref) \
901 DEFINE_SIMPLE_CONVERSION_FUNCTIONS(ty, ref) \
902 \
903 template<typename T> \
904 inline T *unwrap(ref P) { \
905 T *Q = dynamic_cast<T*>(unwrap(P)); \
906 assert(Q && "Invalid cast!"); \
907 return Q; \
908 }
909
910 DEFINE_ISA_CONVERSION_FUNCTIONS (Type, LLVMTypeRef )
911 DEFINE_ISA_CONVERSION_FUNCTIONS (Value, LLVMValueRef )
Gordon Henriksen823f9732007-12-27 18:25:59 +0000912 DEFINE_SIMPLE_CONVERSION_FUNCTIONS(Module, LLVMModuleRef )
913 DEFINE_SIMPLE_CONVERSION_FUNCTIONS(BasicBlock, LLVMBasicBlockRef )
Eric Christopher59278832008-08-08 19:39:37 +0000914 DEFINE_SIMPLE_CONVERSION_FUNCTIONS(IRBuilder<>, LLVMBuilderRef )
Gordon Henriksen823f9732007-12-27 18:25:59 +0000915 DEFINE_SIMPLE_CONVERSION_FUNCTIONS(PATypeHolder, LLVMTypeHandleRef )
916 DEFINE_SIMPLE_CONVERSION_FUNCTIONS(ModuleProvider, LLVMModuleProviderRef)
917 DEFINE_SIMPLE_CONVERSION_FUNCTIONS(MemoryBuffer, LLVMMemoryBufferRef )
Owen Anderson6773d382009-07-01 16:58:40 +0000918 DEFINE_SIMPLE_CONVERSION_FUNCTIONS(LLVMContext, LLVMContextRef )
Gordon Henriksen878114b2008-03-16 04:20:44 +0000919 DEFINE_STDCXX_CONVERSION_FUNCTIONS(PassManagerBase, LLVMPassManagerRef )
Gordon Henriksen7330acd2007-10-05 23:59:36 +0000920
Gordon Henriksen878114b2008-03-16 04:20:44 +0000921 #undef DEFINE_STDCXX_CONVERSION_FUNCTIONS
922 #undef DEFINE_ISA_CONVERSION_FUNCTIONS
Gordon Henriksen34eb6d82007-12-19 22:30:40 +0000923 #undef DEFINE_SIMPLE_CONVERSION_FUNCTIONS
Erick Tryzelaar262332f2009-08-14 00:01:31 +0000924
925 /* Specialized opaque context conversions.
926 */
927 inline LLVMContext **unwrap(LLVMContextRef* Tys) {
928 return reinterpret_cast<LLVMContext**>(Tys);
929 }
930
931 inline LLVMContextRef *wrap(const LLVMContext **Tys) {
932 return reinterpret_cast<LLVMContextRef*>(const_cast<LLVMContext**>(Tys));
933 }
Gordon Henriksen7330acd2007-10-05 23:59:36 +0000934
Gordon Henriksen34eb6d82007-12-19 22:30:40 +0000935 /* Specialized opaque type conversions.
936 */
Gordon Henriksen7330acd2007-10-05 23:59:36 +0000937 inline Type **unwrap(LLVMTypeRef* Tys) {
938 return reinterpret_cast<Type**>(Tys);
939 }
940
Gordon Henriksen7330acd2007-10-05 23:59:36 +0000941 inline LLVMTypeRef *wrap(const Type **Tys) {
942 return reinterpret_cast<LLVMTypeRef*>(const_cast<Type**>(Tys));
943 }
944
Gordon Henriksen34eb6d82007-12-19 22:30:40 +0000945 /* Specialized opaque value conversions.
Gordon Henriksen7330acd2007-10-05 23:59:36 +0000946 */
Gordon Henriksen7330acd2007-10-05 23:59:36 +0000947 inline Value **unwrap(LLVMValueRef *Vals) {
948 return reinterpret_cast<Value**>(Vals);
949 }
950
951 template<typename T>
952 inline T **unwrap(LLVMValueRef *Vals, unsigned Length) {
953 #if DEBUG
Chris Lattnerb7971152009-07-10 18:28:19 +0000954 for (LLVMValueRef *I = Vals, *E = Vals + Length; I != E; ++I)
Gordon Henriksen7330acd2007-10-05 23:59:36 +0000955 cast<T>(*I);
956 #endif
957 return reinterpret_cast<T**>(Vals);
958 }
959
Gordon Henriksen7330acd2007-10-05 23:59:36 +0000960 inline LLVMValueRef *wrap(const Value **Vals) {
961 return reinterpret_cast<LLVMValueRef*>(const_cast<Value**>(Vals));
962 }
Gordon Henriksen7330acd2007-10-05 23:59:36 +0000963}
964
965#endif /* !defined(__cplusplus) */
966
967#endif /* !defined(LLVM_C_CORE_H) */