blob: a22d12ed86f4cdbce6365e38f4f1bb75164e094f [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 */
52typedef struct LLVMCtxt *LLVMContextRef;
53
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,
101 LLVMReadOnlyAttribute = 1<<10
102} LLVMAttribute;
Gordon Henriksen2d9cc212008-04-28 17:37:06 +0000103
104typedef enum {
Gordon Henriksen4a4d7352007-12-30 17:46:33 +0000105 LLVMVoidTypeKind, /**< type with no size */
106 LLVMFloatTypeKind, /**< 32 bit floating point type */
107 LLVMDoubleTypeKind, /**< 64 bit floating point type */
108 LLVMX86_FP80TypeKind, /**< 80 bit floating point type (X87) */
109 LLVMFP128TypeKind, /**< 128 bit floating point type (112-bit mantissa)*/
110 LLVMPPC_FP128TypeKind, /**< 128 bit floating point type (two 64-bits) */
111 LLVMLabelTypeKind, /**< Labels */
112 LLVMIntegerTypeKind, /**< Arbitrary bit width integers */
113 LLVMFunctionTypeKind, /**< Functions */
114 LLVMStructTypeKind, /**< Structures */
115 LLVMArrayTypeKind, /**< Arrays */
116 LLVMPointerTypeKind, /**< Pointers */
117 LLVMOpaqueTypeKind, /**< Opaque: type with unknown structure */
118 LLVMVectorTypeKind /**< SIMD 'packed' format, or other vector type */
Gordon Henriksen76a03742007-09-18 03:18:57 +0000119} LLVMTypeKind;
120
121typedef enum {
Gordon Henriksen4a4d7352007-12-30 17:46:33 +0000122 LLVMExternalLinkage, /**< Externally visible function */
Chris Lattner2dba0f02009-04-13 06:25:37 +0000123 LLVMAvailableExternallyLinkage,
Duncan Sands12da8ce2009-03-07 15:45:40 +0000124 LLVMLinkOnceAnyLinkage, /**< Keep one copy of function when linking (inline)*/
125 LLVMLinkOnceODRLinkage, /**< Same, but only replaced by something
126 equivalent. */
127 LLVMWeakAnyLinkage, /**< Keep one copy of function when linking (weak) */
128 LLVMWeakODRLinkage, /**< Same, but only replaced by something
129 equivalent. */
Gordon Henriksen4a4d7352007-12-30 17:46:33 +0000130 LLVMAppendingLinkage, /**< Special purpose, only applies to global arrays */
131 LLVMInternalLinkage, /**< Rename collisions when linking (static
132 functions) */
Duncan Sands12da8ce2009-03-07 15:45:40 +0000133 LLVMPrivateLinkage, /**< Like Internal, but omit from symbol table */
Gordon Henriksen4a4d7352007-12-30 17:46:33 +0000134 LLVMDLLImportLinkage, /**< Function to be imported from DLL */
135 LLVMDLLExportLinkage, /**< Function to be accessible from DLL */
Duncan Sandse2881052009-03-11 08:08:06 +0000136 LLVMExternalWeakLinkage,/**< ExternalWeak linkage description */
Duncan Sands12da8ce2009-03-07 15:45:40 +0000137 LLVMGhostLinkage, /**< Stand-in functions for streaming fns from
Gordon Henriksen4a4d7352007-12-30 17:46:33 +0000138 bitcode */
Duncan Sands4581beb2009-03-11 20:14:15 +0000139 LLVMCommonLinkage /**< Tentative definitions */
Gordon Henriksen76a03742007-09-18 03:18:57 +0000140} LLVMLinkage;
141
142typedef enum {
Gordon Henriksen4a4d7352007-12-30 17:46:33 +0000143 LLVMDefaultVisibility, /**< The GV is visible */
144 LLVMHiddenVisibility, /**< The GV is hidden */
145 LLVMProtectedVisibility /**< The GV is protected */
Gordon Henriksen76a03742007-09-18 03:18:57 +0000146} LLVMVisibility;
147
Gordon Henriksenc23b66c2007-09-26 20:56:12 +0000148typedef enum {
149 LLVMCCallConv = 0,
150 LLVMFastCallConv = 8,
151 LLVMColdCallConv = 9,
152 LLVMX86StdcallCallConv = 64,
153 LLVMX86FastcallCallConv = 65
154} LLVMCallConv;
155
156typedef enum {
Gordon Henriksen4a4d7352007-12-30 17:46:33 +0000157 LLVMIntEQ = 32, /**< equal */
158 LLVMIntNE, /**< not equal */
159 LLVMIntUGT, /**< unsigned greater than */
160 LLVMIntUGE, /**< unsigned greater or equal */
161 LLVMIntULT, /**< unsigned less than */
162 LLVMIntULE, /**< unsigned less or equal */
163 LLVMIntSGT, /**< signed greater than */
164 LLVMIntSGE, /**< signed greater or equal */
165 LLVMIntSLT, /**< signed less than */
166 LLVMIntSLE /**< signed less or equal */
Gordon Henriksenc23b66c2007-09-26 20:56:12 +0000167} LLVMIntPredicate;
168
169typedef enum {
Gordon Henriksen4a4d7352007-12-30 17:46:33 +0000170 LLVMRealPredicateFalse, /**< Always false (always folded) */
171 LLVMRealOEQ, /**< True if ordered and equal */
172 LLVMRealOGT, /**< True if ordered and greater than */
173 LLVMRealOGE, /**< True if ordered and greater than or equal */
174 LLVMRealOLT, /**< True if ordered and less than */
175 LLVMRealOLE, /**< True if ordered and less than or equal */
176 LLVMRealONE, /**< True if ordered and operands are unequal */
177 LLVMRealORD, /**< True if ordered (no nans) */
178 LLVMRealUNO, /**< True if unordered: isnan(X) | isnan(Y) */
179 LLVMRealUEQ, /**< True if unordered or equal */
180 LLVMRealUGT, /**< True if unordered or greater than */
181 LLVMRealUGE, /**< True if unordered, greater than, or equal */
182 LLVMRealULT, /**< True if unordered or less than */
183 LLVMRealULE, /**< True if unordered, less than, or equal */
184 LLVMRealUNE, /**< True if unordered or not equal */
185 LLVMRealPredicateTrue /**< Always true (always folded) */
Gordon Henriksenc23b66c2007-09-26 20:56:12 +0000186} LLVMRealPredicate;
187
Gordon Henriksen76a03742007-09-18 03:18:57 +0000188
Gordon Henriksen34eb6d82007-12-19 22:30:40 +0000189/*===-- Error handling ----------------------------------------------------===*/
190
191void LLVMDisposeMessage(char *Message);
192
193
Gordon Henriksen76a03742007-09-18 03:18:57 +0000194/*===-- Modules -----------------------------------------------------------===*/
195
Owen Anderson6773d382009-07-01 16:58:40 +0000196/* Create and destroy contexts. */
197LLVMContextRef LLVMContextCreate();
Owen Andersonf7691d32009-07-02 00:16:38 +0000198LLVMContextRef LLVMGetGlobalContext();
Owen Anderson6773d382009-07-01 16:58:40 +0000199void LLVMContextDispose(LLVMContextRef C);
200
Gordon Henriksen76a03742007-09-18 03:18:57 +0000201/* Create and destroy modules. */
Gordon Henriksena49d4352008-03-07 19:13:06 +0000202/** See llvm::Module::Module. */
Gordon Henriksen76a03742007-09-18 03:18:57 +0000203LLVMModuleRef LLVMModuleCreateWithName(const char *ModuleID);
Owen Anderson31d44e42009-07-02 07:17:57 +0000204LLVMModuleRef LLVMModuleCreateWithNameInContext(const char *ModuleID,
205 LLVMContextRef C);
Gordon Henriksena49d4352008-03-07 19:13:06 +0000206
207/** See llvm::Module::~Module. */
Gordon Henriksen76a03742007-09-18 03:18:57 +0000208void LLVMDisposeModule(LLVMModuleRef M);
209
Gordon Henriksena49d4352008-03-07 19:13:06 +0000210/** Data layout. See Module::getDataLayout. */
Gordon Henriksen05568bb2007-12-27 20:13:47 +0000211const char *LLVMGetDataLayout(LLVMModuleRef M);
212void LLVMSetDataLayout(LLVMModuleRef M, const char *Triple);
213
Gordon Henriksena49d4352008-03-07 19:13:06 +0000214/** Target triple. See Module::getTargetTriple. */
Gordon Henriksen05568bb2007-12-27 20:13:47 +0000215const char *LLVMGetTarget(LLVMModuleRef M);
216void LLVMSetTarget(LLVMModuleRef M, const char *Triple);
217
Gordon Henriksena49d4352008-03-07 19:13:06 +0000218/** See Module::addTypeName. */
Gordon Henriksen76a03742007-09-18 03:18:57 +0000219int LLVMAddTypeName(LLVMModuleRef M, const char *Name, LLVMTypeRef Ty);
Gordon Henriksenc23b66c2007-09-26 20:56:12 +0000220void LLVMDeleteTypeName(LLVMModuleRef M, const char *Name);
Chris Lattner7f318242009-07-06 17:29:59 +0000221LLVMTypeRef LLVMGetTypeByName(LLVMModuleRef M, const char *Name);
Gordon Henriksen76a03742007-09-18 03:18:57 +0000222
Gordon Henriksen6c6075e2008-03-14 23:58:56 +0000223/** See Module::dump. */
224void LLVMDumpModule(LLVMModuleRef M);
225
Gordon Henriksen76a03742007-09-18 03:18:57 +0000226
Gordon Henriksenc23b66c2007-09-26 20:56:12 +0000227/*===-- Types -------------------------------------------------------------===*/
Gordon Henriksen76a03742007-09-18 03:18:57 +0000228
229/* LLVM types conform to the following hierarchy:
230 *
231 * types:
232 * integer type
233 * real type
234 * function type
235 * sequence types:
236 * array type
237 * pointer type
238 * vector type
239 * void type
240 * label type
241 * opaque type
242 */
243
Gordon Henriksena49d4352008-03-07 19:13:06 +0000244/** See llvm::LLVMTypeKind::getTypeID. */
Gordon Henriksen76a03742007-09-18 03:18:57 +0000245LLVMTypeKind LLVMGetTypeKind(LLVMTypeRef Ty);
Gordon Henriksena49d4352008-03-07 19:13:06 +0000246
Gordon Henriksen76a03742007-09-18 03:18:57 +0000247/* Operations on integer types */
Gordon Henriksena735a9c2008-05-04 12:55:34 +0000248LLVMTypeRef LLVMInt1Type(void);
249LLVMTypeRef LLVMInt8Type(void);
250LLVMTypeRef LLVMInt16Type(void);
251LLVMTypeRef LLVMInt32Type(void);
252LLVMTypeRef LLVMInt64Type(void);
Gordon Henriksened7beaa2007-10-06 16:05:20 +0000253LLVMTypeRef LLVMIntType(unsigned NumBits);
Gordon Henriksenc23b66c2007-09-26 20:56:12 +0000254unsigned LLVMGetIntTypeWidth(LLVMTypeRef IntegerTy);
Gordon Henriksen76a03742007-09-18 03:18:57 +0000255
256/* Operations on real types */
Gordon Henriksena735a9c2008-05-04 12:55:34 +0000257LLVMTypeRef LLVMFloatType(void);
258LLVMTypeRef LLVMDoubleType(void);
259LLVMTypeRef LLVMX86FP80Type(void);
260LLVMTypeRef LLVMFP128Type(void);
261LLVMTypeRef LLVMPPCFP128Type(void);
Gordon Henriksen76a03742007-09-18 03:18:57 +0000262
263/* Operations on function types */
Gordon Henriksened7beaa2007-10-06 16:05:20 +0000264LLVMTypeRef LLVMFunctionType(LLVMTypeRef ReturnType,
265 LLVMTypeRef *ParamTypes, unsigned ParamCount,
266 int IsVarArg);
Gordon Henriksen76a03742007-09-18 03:18:57 +0000267int LLVMIsFunctionVarArg(LLVMTypeRef FunctionTy);
Gordon Henriksenc23b66c2007-09-26 20:56:12 +0000268LLVMTypeRef LLVMGetReturnType(LLVMTypeRef FunctionTy);
269unsigned LLVMCountParamTypes(LLVMTypeRef FunctionTy);
270void LLVMGetParamTypes(LLVMTypeRef FunctionTy, LLVMTypeRef *Dest);
Gordon Henriksen76a03742007-09-18 03:18:57 +0000271
272/* Operations on struct types */
Gordon Henriksened7beaa2007-10-06 16:05:20 +0000273LLVMTypeRef LLVMStructType(LLVMTypeRef *ElementTypes, unsigned ElementCount,
274 int Packed);
Gordon Henriksenc23b66c2007-09-26 20:56:12 +0000275unsigned LLVMCountStructElementTypes(LLVMTypeRef StructTy);
Gordon Henriksen76a03742007-09-18 03:18:57 +0000276void LLVMGetStructElementTypes(LLVMTypeRef StructTy, LLVMTypeRef *Dest);
277int LLVMIsPackedStruct(LLVMTypeRef StructTy);
278
279/* Operations on array, pointer, and vector types (sequence types) */
Gordon Henriksened7beaa2007-10-06 16:05:20 +0000280LLVMTypeRef LLVMArrayType(LLVMTypeRef ElementType, unsigned ElementCount);
Gordon Henriksen5a3fe032007-12-17 16:08:32 +0000281LLVMTypeRef LLVMPointerType(LLVMTypeRef ElementType, unsigned AddressSpace);
Gordon Henriksened7beaa2007-10-06 16:05:20 +0000282LLVMTypeRef LLVMVectorType(LLVMTypeRef ElementType, unsigned ElementCount);
Gordon Henriksen76a03742007-09-18 03:18:57 +0000283
284LLVMTypeRef LLVMGetElementType(LLVMTypeRef Ty);
285unsigned LLVMGetArrayLength(LLVMTypeRef ArrayTy);
Gordon Henriksen5a3fe032007-12-17 16:08:32 +0000286unsigned LLVMGetPointerAddressSpace(LLVMTypeRef PointerTy);
Gordon Henriksen76a03742007-09-18 03:18:57 +0000287unsigned LLVMGetVectorSize(LLVMTypeRef VectorTy);
288
289/* Operations on other types */
Gordon Henriksena735a9c2008-05-04 12:55:34 +0000290LLVMTypeRef LLVMVoidType(void);
291LLVMTypeRef LLVMLabelType(void);
292LLVMTypeRef LLVMOpaqueType(void);
Gordon Henriksen76a03742007-09-18 03:18:57 +0000293
Gordon Henriksenffb48762007-10-07 00:13:35 +0000294/* Operations on type handles */
295LLVMTypeHandleRef LLVMCreateTypeHandle(LLVMTypeRef PotentiallyAbstractTy);
296void LLVMRefineType(LLVMTypeRef AbstractTy, LLVMTypeRef ConcreteTy);
297LLVMTypeRef LLVMResolveTypeHandle(LLVMTypeHandleRef TypeHandle);
298void LLVMDisposeTypeHandle(LLVMTypeHandleRef TypeHandle);
299
Gordon Henriksen76a03742007-09-18 03:18:57 +0000300
301/*===-- Values ------------------------------------------------------------===*/
302
303/* The bulk of LLVM's object model consists of values, which comprise a very
304 * rich type hierarchy.
Gordon Henriksen76a03742007-09-18 03:18:57 +0000305 */
306
Gordon Henriksen29e38942008-12-19 18:39:45 +0000307#define LLVM_FOR_EACH_VALUE_SUBCLASS(macro) \
308 macro(Argument) \
309 macro(BasicBlock) \
310 macro(InlineAsm) \
311 macro(User) \
312 macro(Constant) \
313 macro(ConstantAggregateZero) \
314 macro(ConstantArray) \
315 macro(ConstantExpr) \
316 macro(ConstantFP) \
317 macro(ConstantInt) \
318 macro(ConstantPointerNull) \
319 macro(ConstantStruct) \
320 macro(ConstantVector) \
321 macro(GlobalValue) \
322 macro(Function) \
323 macro(GlobalAlias) \
324 macro(GlobalVariable) \
325 macro(UndefValue) \
326 macro(Instruction) \
327 macro(BinaryOperator) \
328 macro(CallInst) \
329 macro(IntrinsicInst) \
330 macro(DbgInfoIntrinsic) \
331 macro(DbgDeclareInst) \
332 macro(DbgFuncStartInst) \
333 macro(DbgRegionEndInst) \
334 macro(DbgRegionStartInst) \
335 macro(DbgStopPointInst) \
336 macro(EHSelectorInst) \
337 macro(MemIntrinsic) \
338 macro(MemCpyInst) \
339 macro(MemMoveInst) \
340 macro(MemSetInst) \
341 macro(CmpInst) \
342 macro(FCmpInst) \
343 macro(ICmpInst) \
Gordon Henriksen29e38942008-12-19 18:39:45 +0000344 macro(ExtractElementInst) \
345 macro(GetElementPtrInst) \
346 macro(InsertElementInst) \
347 macro(InsertValueInst) \
348 macro(PHINode) \
349 macro(SelectInst) \
350 macro(ShuffleVectorInst) \
351 macro(StoreInst) \
352 macro(TerminatorInst) \
353 macro(BranchInst) \
354 macro(InvokeInst) \
355 macro(ReturnInst) \
356 macro(SwitchInst) \
357 macro(UnreachableInst) \
358 macro(UnwindInst) \
359 macro(UnaryInstruction) \
360 macro(AllocationInst) \
Gordon Henriksen05a868f2008-12-19 18:51:17 +0000361 macro(AllocaInst) \
362 macro(MallocInst) \
Gordon Henriksen29e38942008-12-19 18:39:45 +0000363 macro(CastInst) \
Gordon Henriksen05a868f2008-12-19 18:51:17 +0000364 macro(BitCastInst) \
365 macro(FPExtInst) \
366 macro(FPToSIInst) \
367 macro(FPToUIInst) \
368 macro(FPTruncInst) \
369 macro(IntToPtrInst) \
370 macro(PtrToIntInst) \
371 macro(SExtInst) \
372 macro(SIToFPInst) \
373 macro(TruncInst) \
374 macro(UIToFPInst) \
375 macro(ZExtInst) \
376 macro(ExtractValueInst) \
377 macro(FreeInst) \
378 macro(LoadInst) \
379 macro(VAArgInst)
Gordon Henriksen29e38942008-12-19 18:39:45 +0000380
Gordon Henriksen76a03742007-09-18 03:18:57 +0000381/* Operations on all values */
Gordon Henriksenc23b66c2007-09-26 20:56:12 +0000382LLVMTypeRef LLVMTypeOf(LLVMValueRef Val);
Gordon Henriksen76a03742007-09-18 03:18:57 +0000383const char *LLVMGetValueName(LLVMValueRef Val);
384void LLVMSetValueName(LLVMValueRef Val, const char *Name);
Gordon Henriksen1d0d24c2007-10-06 00:08:49 +0000385void LLVMDumpValue(LLVMValueRef Val);
Gordon Henriksen76a03742007-09-18 03:18:57 +0000386
Gordon Henriksen29e38942008-12-19 18:39:45 +0000387/* Conversion functions. Return the input value if it is an instance of the
388 specified class, otherwise NULL. See llvm::dyn_cast_or_null<>. */
389#define LLVM_DECLARE_VALUE_CAST(name) \
390 LLVMValueRef LLVMIsA##name(LLVMValueRef Val);
391LLVM_FOR_EACH_VALUE_SUBCLASS(LLVM_DECLARE_VALUE_CAST)
392
Gordon Henriksen76a03742007-09-18 03:18:57 +0000393/* Operations on constants of any type */
Gordon Henriksen1046c732007-10-06 15:11:06 +0000394LLVMValueRef LLVMConstNull(LLVMTypeRef Ty); /* all zeroes */
395LLVMValueRef LLVMConstAllOnes(LLVMTypeRef Ty); /* only for int/vector */
Gordon Henriksen76a03742007-09-18 03:18:57 +0000396LLVMValueRef LLVMGetUndef(LLVMTypeRef Ty);
Gordon Henriksendc88c062007-09-18 18:07:51 +0000397int LLVMIsConstant(LLVMValueRef Val);
Gordon Henriksen76a03742007-09-18 03:18:57 +0000398int LLVMIsNull(LLVMValueRef Val);
Gordon Henriksendc88c062007-09-18 18:07:51 +0000399int LLVMIsUndef(LLVMValueRef Val);
Chris Lattner7f318242009-07-06 17:29:59 +0000400LLVMValueRef LLVMConstPointerNull(LLVMTypeRef Ty);
Gordon Henriksen76a03742007-09-18 03:18:57 +0000401
402/* Operations on scalar constants */
Gordon Henriksen1046c732007-10-06 15:11:06 +0000403LLVMValueRef LLVMConstInt(LLVMTypeRef IntTy, unsigned long long N,
404 int SignExtend);
405LLVMValueRef LLVMConstReal(LLVMTypeRef RealTy, double N);
Gordon Henriksen931e1212008-02-02 01:07:50 +0000406LLVMValueRef LLVMConstRealOfString(LLVMTypeRef RealTy, const char *Text);
Gordon Henriksen76a03742007-09-18 03:18:57 +0000407
408/* Operations on composite constants */
Gordon Henriksen1046c732007-10-06 15:11:06 +0000409LLVMValueRef LLVMConstString(const char *Str, unsigned Length,
410 int DontNullTerminate);
Gordon Henriksen2ad5aef2008-04-25 03:21:19 +0000411LLVMValueRef LLVMConstArray(LLVMTypeRef ElementTy,
Gordon Henriksen1046c732007-10-06 15:11:06 +0000412 LLVMValueRef *ConstantVals, unsigned Length);
413LLVMValueRef LLVMConstStruct(LLVMValueRef *ConstantVals, unsigned Count,
414 int packed);
415LLVMValueRef LLVMConstVector(LLVMValueRef *ScalarConstantVals, unsigned Size);
Gordon Henriksen76a03742007-09-18 03:18:57 +0000416
Gordon Henriksen7ce31762007-10-06 14:29:36 +0000417/* Constant expressions */
418LLVMValueRef LLVMSizeOf(LLVMTypeRef Ty);
419LLVMValueRef LLVMConstNeg(LLVMValueRef ConstantVal);
420LLVMValueRef LLVMConstNot(LLVMValueRef ConstantVal);
421LLVMValueRef LLVMConstAdd(LLVMValueRef LHSConstant, LLVMValueRef RHSConstant);
422LLVMValueRef LLVMConstSub(LLVMValueRef LHSConstant, LLVMValueRef RHSConstant);
423LLVMValueRef LLVMConstMul(LLVMValueRef LHSConstant, LLVMValueRef RHSConstant);
424LLVMValueRef LLVMConstUDiv(LLVMValueRef LHSConstant, LLVMValueRef RHSConstant);
425LLVMValueRef LLVMConstSDiv(LLVMValueRef LHSConstant, LLVMValueRef RHSConstant);
426LLVMValueRef LLVMConstFDiv(LLVMValueRef LHSConstant, LLVMValueRef RHSConstant);
427LLVMValueRef LLVMConstURem(LLVMValueRef LHSConstant, LLVMValueRef RHSConstant);
428LLVMValueRef LLVMConstSRem(LLVMValueRef LHSConstant, LLVMValueRef RHSConstant);
429LLVMValueRef LLVMConstFRem(LLVMValueRef LHSConstant, LLVMValueRef RHSConstant);
430LLVMValueRef LLVMConstAnd(LLVMValueRef LHSConstant, LLVMValueRef RHSConstant);
431LLVMValueRef LLVMConstOr(LLVMValueRef LHSConstant, LLVMValueRef RHSConstant);
432LLVMValueRef LLVMConstXor(LLVMValueRef LHSConstant, LLVMValueRef RHSConstant);
433LLVMValueRef LLVMConstICmp(LLVMIntPredicate Predicate,
434 LLVMValueRef LHSConstant, LLVMValueRef RHSConstant);
435LLVMValueRef LLVMConstFCmp(LLVMRealPredicate Predicate,
436 LLVMValueRef LHSConstant, LLVMValueRef RHSConstant);
437LLVMValueRef LLVMConstShl(LLVMValueRef LHSConstant, LLVMValueRef RHSConstant);
438LLVMValueRef LLVMConstLShr(LLVMValueRef LHSConstant, LLVMValueRef RHSConstant);
439LLVMValueRef LLVMConstAShr(LLVMValueRef LHSConstant, LLVMValueRef RHSConstant);
440LLVMValueRef LLVMConstGEP(LLVMValueRef ConstantVal,
441 LLVMValueRef *ConstantIndices, unsigned NumIndices);
442LLVMValueRef LLVMConstTrunc(LLVMValueRef ConstantVal, LLVMTypeRef ToType);
443LLVMValueRef LLVMConstSExt(LLVMValueRef ConstantVal, LLVMTypeRef ToType);
444LLVMValueRef LLVMConstZExt(LLVMValueRef ConstantVal, LLVMTypeRef ToType);
445LLVMValueRef LLVMConstFPTrunc(LLVMValueRef ConstantVal, LLVMTypeRef ToType);
446LLVMValueRef LLVMConstFPExt(LLVMValueRef ConstantVal, LLVMTypeRef ToType);
447LLVMValueRef LLVMConstUIToFP(LLVMValueRef ConstantVal, LLVMTypeRef ToType);
448LLVMValueRef LLVMConstSIToFP(LLVMValueRef ConstantVal, LLVMTypeRef ToType);
449LLVMValueRef LLVMConstFPToUI(LLVMValueRef ConstantVal, LLVMTypeRef ToType);
450LLVMValueRef LLVMConstFPToSI(LLVMValueRef ConstantVal, LLVMTypeRef ToType);
451LLVMValueRef LLVMConstPtrToInt(LLVMValueRef ConstantVal, LLVMTypeRef ToType);
452LLVMValueRef LLVMConstIntToPtr(LLVMValueRef ConstantVal, LLVMTypeRef ToType);
453LLVMValueRef LLVMConstBitCast(LLVMValueRef ConstantVal, LLVMTypeRef ToType);
454LLVMValueRef LLVMConstSelect(LLVMValueRef ConstantCondition,
455 LLVMValueRef ConstantIfTrue,
456 LLVMValueRef ConstantIfFalse);
457LLVMValueRef LLVMConstExtractElement(LLVMValueRef VectorConstant,
458 LLVMValueRef IndexConstant);
459LLVMValueRef LLVMConstInsertElement(LLVMValueRef VectorConstant,
460 LLVMValueRef ElementValueConstant,
461 LLVMValueRef IndexConstant);
462LLVMValueRef LLVMConstShuffleVector(LLVMValueRef VectorAConstant,
463 LLVMValueRef VectorBConstant,
464 LLVMValueRef MaskConstant);
Dan Gohmand5104a52008-11-03 22:55:43 +0000465LLVMValueRef LLVMConstExtractValue(LLVMValueRef AggConstant, unsigned *IdxList,
466 unsigned NumIdx);
467LLVMValueRef LLVMConstInsertValue(LLVMValueRef AggConstant,
468 LLVMValueRef ElementValueConstant,
469 unsigned *IdxList, unsigned NumIdx);
Chris Lattner3d1f5522008-12-17 21:39:50 +0000470LLVMValueRef LLVMConstInlineAsm(LLVMTypeRef Ty,
471 const char *AsmString, const char *Constraints,
472 int HasSideEffects);
Gordon Henriksen7ce31762007-10-06 14:29:36 +0000473
Gordon Henriksen76a03742007-09-18 03:18:57 +0000474/* Operations on global variables, functions, and aliases (globals) */
Gordon Henriksen265f7802008-03-19 01:11:35 +0000475LLVMModuleRef LLVMGetGlobalParent(LLVMValueRef Global);
Gordon Henriksen76a03742007-09-18 03:18:57 +0000476int LLVMIsDeclaration(LLVMValueRef Global);
477LLVMLinkage LLVMGetLinkage(LLVMValueRef Global);
478void LLVMSetLinkage(LLVMValueRef Global, LLVMLinkage Linkage);
479const char *LLVMGetSection(LLVMValueRef Global);
480void LLVMSetSection(LLVMValueRef Global, const char *Section);
481LLVMVisibility LLVMGetVisibility(LLVMValueRef Global);
482void LLVMSetVisibility(LLVMValueRef Global, LLVMVisibility Viz);
483unsigned LLVMGetAlignment(LLVMValueRef Global);
484void LLVMSetAlignment(LLVMValueRef Global, unsigned Bytes);
485
486/* Operations on global variables */
487LLVMValueRef LLVMAddGlobal(LLVMModuleRef M, LLVMTypeRef Ty, const char *Name);
Gordon Henriksen783f7bb2007-10-08 03:45:09 +0000488LLVMValueRef LLVMGetNamedGlobal(LLVMModuleRef M, const char *Name);
Gordon Henriksen07a45f42008-03-23 22:21:29 +0000489LLVMValueRef LLVMGetFirstGlobal(LLVMModuleRef M);
490LLVMValueRef LLVMGetLastGlobal(LLVMModuleRef M);
491LLVMValueRef LLVMGetNextGlobal(LLVMValueRef GlobalVar);
492LLVMValueRef LLVMGetPreviousGlobal(LLVMValueRef GlobalVar);
Gordon Henriksen76a03742007-09-18 03:18:57 +0000493void LLVMDeleteGlobal(LLVMValueRef GlobalVar);
Gordon Henriksen76a03742007-09-18 03:18:57 +0000494LLVMValueRef LLVMGetInitializer(LLVMValueRef GlobalVar);
495void LLVMSetInitializer(LLVMValueRef GlobalVar, LLVMValueRef ConstantVal);
496int LLVMIsThreadLocal(LLVMValueRef GlobalVar);
497void LLVMSetThreadLocal(LLVMValueRef GlobalVar, int IsThreadLocal);
Gordon Henriksen751ebf72007-10-07 17:31:42 +0000498int LLVMIsGlobalConstant(LLVMValueRef GlobalVar);
499void LLVMSetGlobalConstant(LLVMValueRef GlobalVar, int IsConstant);
Gordon Henriksen76a03742007-09-18 03:18:57 +0000500
Chris Lattner3d1f5522008-12-17 21:39:50 +0000501/* Operations on aliases */
502LLVMValueRef LLVMAddAlias(LLVMModuleRef M, LLVMTypeRef Ty, LLVMValueRef Aliasee,
503 const char *Name);
504
Gordon Henriksenc23b66c2007-09-26 20:56:12 +0000505/* Operations on functions */
506LLVMValueRef LLVMAddFunction(LLVMModuleRef M, const char *Name,
507 LLVMTypeRef FunctionTy);
Gordon Henriksen783f7bb2007-10-08 03:45:09 +0000508LLVMValueRef LLVMGetNamedFunction(LLVMModuleRef M, const char *Name);
Gordon Henriksen054817c2008-03-19 03:47:18 +0000509LLVMValueRef LLVMGetFirstFunction(LLVMModuleRef M);
510LLVMValueRef LLVMGetLastFunction(LLVMModuleRef M);
511LLVMValueRef LLVMGetNextFunction(LLVMValueRef Fn);
512LLVMValueRef LLVMGetPreviousFunction(LLVMValueRef Fn);
Gordon Henriksenc23b66c2007-09-26 20:56:12 +0000513void LLVMDeleteFunction(LLVMValueRef Fn);
Gordon Henriksenc23b66c2007-09-26 20:56:12 +0000514unsigned LLVMGetIntrinsicID(LLVMValueRef Fn);
515unsigned LLVMGetFunctionCallConv(LLVMValueRef Fn);
516void LLVMSetFunctionCallConv(LLVMValueRef Fn, unsigned CC);
Gordon Henriksend930f912008-08-17 18:44:35 +0000517const char *LLVMGetGC(LLVMValueRef Fn);
518void LLVMSetGC(LLVMValueRef Fn, const char *Name);
Duncan Sands7374a012009-05-06 12:21:17 +0000519void LLVMAddFunctionAttr(LLVMValueRef Fn, LLVMAttribute PA);
520void LLVMRemoveFunctionAttr(LLVMValueRef Fn, LLVMAttribute PA);
Gordon Henriksenc23b66c2007-09-26 20:56:12 +0000521
Gordon Henriksen265f7802008-03-19 01:11:35 +0000522/* Operations on parameters */
523unsigned LLVMCountParams(LLVMValueRef Fn);
524void LLVMGetParams(LLVMValueRef Fn, LLVMValueRef *Params);
525LLVMValueRef LLVMGetParam(LLVMValueRef Fn, unsigned Index);
526LLVMValueRef LLVMGetParamParent(LLVMValueRef Inst);
Gordon Henriksen07a45f42008-03-23 22:21:29 +0000527LLVMValueRef LLVMGetFirstParam(LLVMValueRef Fn);
528LLVMValueRef LLVMGetLastParam(LLVMValueRef Fn);
529LLVMValueRef LLVMGetNextParam(LLVMValueRef Arg);
530LLVMValueRef LLVMGetPreviousParam(LLVMValueRef Arg);
Devang Patel4c758ea2008-09-25 21:00:45 +0000531void LLVMAddAttribute(LLVMValueRef Arg, LLVMAttribute PA);
532void LLVMRemoveAttribute(LLVMValueRef Arg, LLVMAttribute PA);
Gordon Henriksen2d9cc212008-04-28 17:37:06 +0000533void LLVMSetParamAlignment(LLVMValueRef Arg, unsigned align);
Gordon Henriksen265f7802008-03-19 01:11:35 +0000534
Gordon Henriksenc23b66c2007-09-26 20:56:12 +0000535/* Operations on basic blocks */
Gordon Henriksen07a45f42008-03-23 22:21:29 +0000536LLVMValueRef LLVMBasicBlockAsValue(LLVMBasicBlockRef BB);
Gordon Henriksenc23b66c2007-09-26 20:56:12 +0000537int LLVMValueIsBasicBlock(LLVMValueRef Val);
538LLVMBasicBlockRef LLVMValueAsBasicBlock(LLVMValueRef Val);
Gordon Henriksen07a45f42008-03-23 22:21:29 +0000539LLVMValueRef LLVMGetBasicBlockParent(LLVMBasicBlockRef BB);
Gordon Henriksenc23b66c2007-09-26 20:56:12 +0000540unsigned LLVMCountBasicBlocks(LLVMValueRef Fn);
541void LLVMGetBasicBlocks(LLVMValueRef Fn, LLVMBasicBlockRef *BasicBlocks);
Gordon Henriksen054817c2008-03-19 03:47:18 +0000542LLVMBasicBlockRef LLVMGetFirstBasicBlock(LLVMValueRef Fn);
543LLVMBasicBlockRef LLVMGetLastBasicBlock(LLVMValueRef Fn);
544LLVMBasicBlockRef LLVMGetNextBasicBlock(LLVMBasicBlockRef BB);
545LLVMBasicBlockRef LLVMGetPreviousBasicBlock(LLVMBasicBlockRef BB);
Gordon Henriksenc23b66c2007-09-26 20:56:12 +0000546LLVMBasicBlockRef LLVMGetEntryBasicBlock(LLVMValueRef Fn);
547LLVMBasicBlockRef LLVMAppendBasicBlock(LLVMValueRef Fn, const char *Name);
548LLVMBasicBlockRef LLVMInsertBasicBlock(LLVMBasicBlockRef InsertBeforeBB,
549 const char *Name);
550void LLVMDeleteBasicBlock(LLVMBasicBlockRef BB);
551
Gordon Henriksen265f7802008-03-19 01:11:35 +0000552/* Operations on instructions */
553LLVMBasicBlockRef LLVMGetInstructionParent(LLVMValueRef Inst);
Gordon Henriksen054817c2008-03-19 03:47:18 +0000554LLVMValueRef LLVMGetFirstInstruction(LLVMBasicBlockRef BB);
555LLVMValueRef LLVMGetLastInstruction(LLVMBasicBlockRef BB);
556LLVMValueRef LLVMGetNextInstruction(LLVMValueRef Inst);
557LLVMValueRef LLVMGetPreviousInstruction(LLVMValueRef Inst);
Gordon Henriksen265f7802008-03-19 01:11:35 +0000558
Gordon Henriksen1158c532007-12-29 20:45:00 +0000559/* Operations on call sites */
560void LLVMSetInstructionCallConv(LLVMValueRef Instr, unsigned CC);
561unsigned LLVMGetInstructionCallConv(LLVMValueRef Instr);
Devang Patel4c758ea2008-09-25 21:00:45 +0000562void LLVMAddInstrAttribute(LLVMValueRef Instr, unsigned index, LLVMAttribute);
563void LLVMRemoveInstrAttribute(LLVMValueRef Instr, unsigned index,
564 LLVMAttribute);
Gordon Henriksen2d9cc212008-04-28 17:37:06 +0000565void LLVMSetInstrParamAlignment(LLVMValueRef Instr, unsigned index,
566 unsigned align);
Gordon Henriksen1158c532007-12-29 20:45:00 +0000567
Gordon Henrikseneeb65372008-08-30 16:34:54 +0000568/* Operations on call instructions (only) */
569int LLVMIsTailCall(LLVMValueRef CallInst);
570void LLVMSetTailCall(LLVMValueRef CallInst, int IsTailCall);
571
Gordon Henriksen44dd8fb2007-10-08 18:14:39 +0000572/* Operations on phi nodes */
573void LLVMAddIncoming(LLVMValueRef PhiNode, LLVMValueRef *IncomingValues,
574 LLVMBasicBlockRef *IncomingBlocks, unsigned Count);
575unsigned LLVMCountIncoming(LLVMValueRef PhiNode);
576LLVMValueRef LLVMGetIncomingValue(LLVMValueRef PhiNode, unsigned Index);
577LLVMBasicBlockRef LLVMGetIncomingBlock(LLVMValueRef PhiNode, unsigned Index);
Gordon Henriksenc23b66c2007-09-26 20:56:12 +0000578
579/*===-- Instruction builders ----------------------------------------------===*/
580
581/* An instruction builder represents a point within a basic block, and is the
582 * exclusive means of building instructions using the C interface.
583 */
584
Gordon Henriksena735a9c2008-05-04 12:55:34 +0000585LLVMBuilderRef LLVMCreateBuilder(void);
Gordon Henriksen054817c2008-03-19 03:47:18 +0000586void LLVMPositionBuilder(LLVMBuilderRef Builder, LLVMBasicBlockRef Block,
587 LLVMValueRef Instr);
Gordon Henriksenc23b66c2007-09-26 20:56:12 +0000588void LLVMPositionBuilderBefore(LLVMBuilderRef Builder, LLVMValueRef Instr);
589void LLVMPositionBuilderAtEnd(LLVMBuilderRef Builder, LLVMBasicBlockRef Block);
Gordon Henriksen265f7802008-03-19 01:11:35 +0000590LLVMBasicBlockRef LLVMGetInsertBlock(LLVMBuilderRef Builder);
Chris Lattner3d1f5522008-12-17 21:39:50 +0000591void LLVMClearInsertionPosition(LLVMBuilderRef Builder);
592void LLVMInsertIntoBuilder(LLVMBuilderRef Builder, LLVMValueRef Instr);
Gordon Henriksenc23b66c2007-09-26 20:56:12 +0000593void LLVMDisposeBuilder(LLVMBuilderRef Builder);
594
595/* Terminators */
596LLVMValueRef LLVMBuildRetVoid(LLVMBuilderRef);
597LLVMValueRef LLVMBuildRet(LLVMBuilderRef, LLVMValueRef V);
598LLVMValueRef LLVMBuildBr(LLVMBuilderRef, LLVMBasicBlockRef Dest);
599LLVMValueRef LLVMBuildCondBr(LLVMBuilderRef, LLVMValueRef If,
600 LLVMBasicBlockRef Then, LLVMBasicBlockRef Else);
601LLVMValueRef LLVMBuildSwitch(LLVMBuilderRef, LLVMValueRef V,
602 LLVMBasicBlockRef Else, unsigned NumCases);
603LLVMValueRef LLVMBuildInvoke(LLVMBuilderRef, LLVMValueRef Fn,
604 LLVMValueRef *Args, unsigned NumArgs,
605 LLVMBasicBlockRef Then, LLVMBasicBlockRef Catch,
606 const char *Name);
607LLVMValueRef LLVMBuildUnwind(LLVMBuilderRef);
608LLVMValueRef LLVMBuildUnreachable(LLVMBuilderRef);
609
Gordon Henriksen097102c2008-01-01 05:50:53 +0000610/* Add a case to the switch instruction */
611void LLVMAddCase(LLVMValueRef Switch, LLVMValueRef OnVal,
612 LLVMBasicBlockRef Dest);
613
Gordon Henriksenc23b66c2007-09-26 20:56:12 +0000614/* Arithmetic */
615LLVMValueRef LLVMBuildAdd(LLVMBuilderRef, LLVMValueRef LHS, LLVMValueRef RHS,
616 const char *Name);
617LLVMValueRef LLVMBuildSub(LLVMBuilderRef, LLVMValueRef LHS, LLVMValueRef RHS,
618 const char *Name);
619LLVMValueRef LLVMBuildMul(LLVMBuilderRef, LLVMValueRef LHS, LLVMValueRef RHS,
620 const char *Name);
621LLVMValueRef LLVMBuildUDiv(LLVMBuilderRef, LLVMValueRef LHS, LLVMValueRef RHS,
622 const char *Name);
623LLVMValueRef LLVMBuildSDiv(LLVMBuilderRef, LLVMValueRef LHS, LLVMValueRef RHS,
624 const char *Name);
625LLVMValueRef LLVMBuildFDiv(LLVMBuilderRef, LLVMValueRef LHS, LLVMValueRef RHS,
626 const char *Name);
627LLVMValueRef LLVMBuildURem(LLVMBuilderRef, LLVMValueRef LHS, LLVMValueRef RHS,
628 const char *Name);
629LLVMValueRef LLVMBuildSRem(LLVMBuilderRef, LLVMValueRef LHS, LLVMValueRef RHS,
630 const char *Name);
631LLVMValueRef LLVMBuildFRem(LLVMBuilderRef, LLVMValueRef LHS, LLVMValueRef RHS,
632 const char *Name);
633LLVMValueRef LLVMBuildShl(LLVMBuilderRef, LLVMValueRef LHS, LLVMValueRef RHS,
634 const char *Name);
635LLVMValueRef LLVMBuildLShr(LLVMBuilderRef, LLVMValueRef LHS, LLVMValueRef RHS,
636 const char *Name);
637LLVMValueRef LLVMBuildAShr(LLVMBuilderRef, LLVMValueRef LHS, LLVMValueRef RHS,
638 const char *Name);
639LLVMValueRef LLVMBuildAnd(LLVMBuilderRef, LLVMValueRef LHS, LLVMValueRef RHS,
640 const char *Name);
641LLVMValueRef LLVMBuildOr(LLVMBuilderRef, LLVMValueRef LHS, LLVMValueRef RHS,
642 const char *Name);
643LLVMValueRef LLVMBuildXor(LLVMBuilderRef, LLVMValueRef LHS, LLVMValueRef RHS,
644 const char *Name);
645LLVMValueRef LLVMBuildNeg(LLVMBuilderRef, LLVMValueRef V, const char *Name);
646LLVMValueRef LLVMBuildNot(LLVMBuilderRef, LLVMValueRef V, const char *Name);
647
648/* Memory */
649LLVMValueRef LLVMBuildMalloc(LLVMBuilderRef, LLVMTypeRef Ty, const char *Name);
650LLVMValueRef LLVMBuildArrayMalloc(LLVMBuilderRef, LLVMTypeRef Ty,
651 LLVMValueRef Val, const char *Name);
652LLVMValueRef LLVMBuildAlloca(LLVMBuilderRef, LLVMTypeRef Ty, const char *Name);
653LLVMValueRef LLVMBuildArrayAlloca(LLVMBuilderRef, LLVMTypeRef Ty,
654 LLVMValueRef Val, const char *Name);
655LLVMValueRef LLVMBuildFree(LLVMBuilderRef, LLVMValueRef PointerVal);
656LLVMValueRef LLVMBuildLoad(LLVMBuilderRef, LLVMValueRef PointerVal,
657 const char *Name);
658LLVMValueRef LLVMBuildStore(LLVMBuilderRef, LLVMValueRef Val, LLVMValueRef Ptr);
659LLVMValueRef LLVMBuildGEP(LLVMBuilderRef B, LLVMValueRef Pointer,
660 LLVMValueRef *Indices, unsigned NumIndices,
661 const char *Name);
662
663/* Casts */
664LLVMValueRef LLVMBuildTrunc(LLVMBuilderRef, LLVMValueRef Val,
665 LLVMTypeRef DestTy, const char *Name);
666LLVMValueRef LLVMBuildZExt(LLVMBuilderRef, LLVMValueRef Val,
667 LLVMTypeRef DestTy, const char *Name);
668LLVMValueRef LLVMBuildSExt(LLVMBuilderRef, LLVMValueRef Val,
669 LLVMTypeRef DestTy, const char *Name);
670LLVMValueRef LLVMBuildFPToUI(LLVMBuilderRef, LLVMValueRef Val,
671 LLVMTypeRef DestTy, const char *Name);
672LLVMValueRef LLVMBuildFPToSI(LLVMBuilderRef, LLVMValueRef Val,
673 LLVMTypeRef DestTy, const char *Name);
674LLVMValueRef LLVMBuildUIToFP(LLVMBuilderRef, LLVMValueRef Val,
675 LLVMTypeRef DestTy, const char *Name);
676LLVMValueRef LLVMBuildSIToFP(LLVMBuilderRef, LLVMValueRef Val,
677 LLVMTypeRef DestTy, const char *Name);
678LLVMValueRef LLVMBuildFPTrunc(LLVMBuilderRef, LLVMValueRef Val,
679 LLVMTypeRef DestTy, const char *Name);
680LLVMValueRef LLVMBuildFPExt(LLVMBuilderRef, LLVMValueRef Val,
681 LLVMTypeRef DestTy, const char *Name);
682LLVMValueRef LLVMBuildPtrToInt(LLVMBuilderRef, LLVMValueRef Val,
683 LLVMTypeRef DestTy, const char *Name);
684LLVMValueRef LLVMBuildIntToPtr(LLVMBuilderRef, LLVMValueRef Val,
685 LLVMTypeRef DestTy, const char *Name);
686LLVMValueRef LLVMBuildBitCast(LLVMBuilderRef, LLVMValueRef Val,
687 LLVMTypeRef DestTy, const char *Name);
688
689/* Comparisons */
690LLVMValueRef LLVMBuildICmp(LLVMBuilderRef, LLVMIntPredicate Op,
691 LLVMValueRef LHS, LLVMValueRef RHS,
692 const char *Name);
693LLVMValueRef LLVMBuildFCmp(LLVMBuilderRef, LLVMRealPredicate Op,
694 LLVMValueRef LHS, LLVMValueRef RHS,
695 const char *Name);
696
697/* Miscellaneous instructions */
698LLVMValueRef LLVMBuildPhi(LLVMBuilderRef, LLVMTypeRef Ty, const char *Name);
699LLVMValueRef LLVMBuildCall(LLVMBuilderRef, LLVMValueRef Fn,
700 LLVMValueRef *Args, unsigned NumArgs,
701 const char *Name);
702LLVMValueRef LLVMBuildSelect(LLVMBuilderRef, LLVMValueRef If,
703 LLVMValueRef Then, LLVMValueRef Else,
704 const char *Name);
705LLVMValueRef LLVMBuildVAArg(LLVMBuilderRef, LLVMValueRef List, LLVMTypeRef Ty,
706 const char *Name);
707LLVMValueRef LLVMBuildExtractElement(LLVMBuilderRef, LLVMValueRef VecVal,
708 LLVMValueRef Index, const char *Name);
709LLVMValueRef LLVMBuildInsertElement(LLVMBuilderRef, LLVMValueRef VecVal,
710 LLVMValueRef EltVal, LLVMValueRef Index,
711 const char *Name);
712LLVMValueRef LLVMBuildShuffleVector(LLVMBuilderRef, LLVMValueRef V1,
713 LLVMValueRef V2, LLVMValueRef Mask,
714 const char *Name);
Dan Gohmand5104a52008-11-03 22:55:43 +0000715LLVMValueRef LLVMBuildExtractValue(LLVMBuilderRef, LLVMValueRef AggVal,
716 unsigned Index, const char *Name);
717LLVMValueRef LLVMBuildInsertValue(LLVMBuilderRef, LLVMValueRef AggVal,
718 LLVMValueRef EltVal, unsigned Index,
719 const char *Name);
Gordon Henriksen76a03742007-09-18 03:18:57 +0000720
Gordon Henriksen34eb6d82007-12-19 22:30:40 +0000721
Gordon Henriksen0a68fe22007-12-12 01:04:30 +0000722/*===-- Module providers --------------------------------------------------===*/
723
724/* Encapsulates the module M in a module provider, taking ownership of the
725 * module.
726 * See the constructor llvm::ExistingModuleProvider::ExistingModuleProvider.
727 */
728LLVMModuleProviderRef
729LLVMCreateModuleProviderForExistingModule(LLVMModuleRef M);
730
731/* Destroys the module provider MP as well as the contained module.
732 * See the destructor llvm::ModuleProvider::~ModuleProvider.
733 */
734void LLVMDisposeModuleProvider(LLVMModuleProviderRef MP);
735
Gordon Henriksen34eb6d82007-12-19 22:30:40 +0000736
737/*===-- Memory buffers ----------------------------------------------------===*/
738
739int LLVMCreateMemoryBufferWithContentsOfFile(const char *Path,
740 LLVMMemoryBufferRef *OutMemBuf,
741 char **OutMessage);
742int LLVMCreateMemoryBufferWithSTDIN(LLVMMemoryBufferRef *OutMemBuf,
743 char **OutMessage);
744void LLVMDisposeMemoryBuffer(LLVMMemoryBufferRef MemBuf);
745
Gordon Henriksen878114b2008-03-16 04:20:44 +0000746
747/*===-- Pass Managers -----------------------------------------------------===*/
748
749/** Constructs a new whole-module pass pipeline. This type of pipeline is
750 suitable for link-time optimization and whole-module transformations.
751 See llvm::PassManager::PassManager. */
Gordon Henriksena735a9c2008-05-04 12:55:34 +0000752LLVMPassManagerRef LLVMCreatePassManager(void);
Gordon Henriksen878114b2008-03-16 04:20:44 +0000753
754/** Constructs a new function-by-function pass pipeline over the module
755 provider. It does not take ownership of the module provider. This type of
756 pipeline is suitable for code generation and JIT compilation tasks.
757 See llvm::FunctionPassManager::FunctionPassManager. */
758LLVMPassManagerRef LLVMCreateFunctionPassManager(LLVMModuleProviderRef MP);
759
760/** Initializes, executes on the provided module, and finalizes all of the
761 passes scheduled in the pass manager. Returns 1 if any of the passes
762 modified the module, 0 otherwise. See llvm::PassManager::run(Module&). */
763int LLVMRunPassManager(LLVMPassManagerRef PM, LLVMModuleRef M);
764
765/** Initializes all of the function passes scheduled in the function pass
766 manager. Returns 1 if any of the passes modified the module, 0 otherwise.
767 See llvm::FunctionPassManager::doInitialization. */
768int LLVMInitializeFunctionPassManager(LLVMPassManagerRef FPM);
769
770/** Executes all of the function passes scheduled in the function pass manager
771 on the provided function. Returns 1 if any of the passes modified the
772 function, false otherwise.
773 See llvm::FunctionPassManager::run(Function&). */
774int LLVMRunFunctionPassManager(LLVMPassManagerRef FPM, LLVMValueRef F);
775
776/** Finalizes all of the function passes scheduled in in the function pass
777 manager. Returns 1 if any of the passes modified the module, 0 otherwise.
778 See llvm::FunctionPassManager::doFinalization. */
779int LLVMFinalizeFunctionPassManager(LLVMPassManagerRef FPM);
780
781/** Frees the memory of a pass pipeline. For function pipelines, does not free
782 the module provider.
783 See llvm::PassManagerBase::~PassManagerBase. */
784void LLVMDisposePassManager(LLVMPassManagerRef PM);
785
786
Gordon Henriksen76a03742007-09-18 03:18:57 +0000787#ifdef __cplusplus
788}
Gordon Henriksen76a03742007-09-18 03:18:57 +0000789
Gordon Henriksen7330acd2007-10-05 23:59:36 +0000790namespace llvm {
Gordon Henriksen0a68fe22007-12-12 01:04:30 +0000791 class ModuleProvider;
Gordon Henriksen34eb6d82007-12-19 22:30:40 +0000792 class MemoryBuffer;
Gordon Henriksen96571492008-03-16 15:55:43 +0000793 class PassManagerBase;
Gordon Henriksen0a68fe22007-12-12 01:04:30 +0000794
Gordon Henriksen34eb6d82007-12-19 22:30:40 +0000795 #define DEFINE_SIMPLE_CONVERSION_FUNCTIONS(ty, ref) \
796 inline ty *unwrap(ref P) { \
797 return reinterpret_cast<ty*>(P); \
798 } \
799 \
800 inline ref wrap(const ty *P) { \
801 return reinterpret_cast<ref>(const_cast<ty*>(P)); \
802 }
Gordon Henriksen7330acd2007-10-05 23:59:36 +0000803
Gordon Henriksen878114b2008-03-16 04:20:44 +0000804 #define DEFINE_ISA_CONVERSION_FUNCTIONS(ty, ref) \
805 DEFINE_SIMPLE_CONVERSION_FUNCTIONS(ty, ref) \
806 \
807 template<typename T> \
808 inline T *unwrap(ref P) { \
809 return cast<T>(unwrap(P)); \
810 }
811
812 #define DEFINE_STDCXX_CONVERSION_FUNCTIONS(ty, ref) \
813 DEFINE_SIMPLE_CONVERSION_FUNCTIONS(ty, ref) \
814 \
815 template<typename T> \
816 inline T *unwrap(ref P) { \
817 T *Q = dynamic_cast<T*>(unwrap(P)); \
818 assert(Q && "Invalid cast!"); \
819 return Q; \
820 }
821
822 DEFINE_ISA_CONVERSION_FUNCTIONS (Type, LLVMTypeRef )
823 DEFINE_ISA_CONVERSION_FUNCTIONS (Value, LLVMValueRef )
Gordon Henriksen823f9732007-12-27 18:25:59 +0000824 DEFINE_SIMPLE_CONVERSION_FUNCTIONS(Module, LLVMModuleRef )
825 DEFINE_SIMPLE_CONVERSION_FUNCTIONS(BasicBlock, LLVMBasicBlockRef )
Eric Christopher59278832008-08-08 19:39:37 +0000826 DEFINE_SIMPLE_CONVERSION_FUNCTIONS(IRBuilder<>, LLVMBuilderRef )
Gordon Henriksen823f9732007-12-27 18:25:59 +0000827 DEFINE_SIMPLE_CONVERSION_FUNCTIONS(PATypeHolder, LLVMTypeHandleRef )
828 DEFINE_SIMPLE_CONVERSION_FUNCTIONS(ModuleProvider, LLVMModuleProviderRef)
829 DEFINE_SIMPLE_CONVERSION_FUNCTIONS(MemoryBuffer, LLVMMemoryBufferRef )
Owen Anderson6773d382009-07-01 16:58:40 +0000830 DEFINE_SIMPLE_CONVERSION_FUNCTIONS(LLVMContext, LLVMContextRef )
Gordon Henriksen878114b2008-03-16 04:20:44 +0000831 DEFINE_STDCXX_CONVERSION_FUNCTIONS(PassManagerBase, LLVMPassManagerRef )
Gordon Henriksen7330acd2007-10-05 23:59:36 +0000832
Gordon Henriksen878114b2008-03-16 04:20:44 +0000833 #undef DEFINE_STDCXX_CONVERSION_FUNCTIONS
834 #undef DEFINE_ISA_CONVERSION_FUNCTIONS
Gordon Henriksen34eb6d82007-12-19 22:30:40 +0000835 #undef DEFINE_SIMPLE_CONVERSION_FUNCTIONS
Gordon Henriksen7330acd2007-10-05 23:59:36 +0000836
Gordon Henriksen34eb6d82007-12-19 22:30:40 +0000837 /* Specialized opaque type conversions.
838 */
Gordon Henriksen7330acd2007-10-05 23:59:36 +0000839 inline Type **unwrap(LLVMTypeRef* Tys) {
840 return reinterpret_cast<Type**>(Tys);
841 }
842
Gordon Henriksen7330acd2007-10-05 23:59:36 +0000843 inline LLVMTypeRef *wrap(const Type **Tys) {
844 return reinterpret_cast<LLVMTypeRef*>(const_cast<Type**>(Tys));
845 }
846
Gordon Henriksen34eb6d82007-12-19 22:30:40 +0000847 /* Specialized opaque value conversions.
Gordon Henriksen7330acd2007-10-05 23:59:36 +0000848 */
Gordon Henriksen7330acd2007-10-05 23:59:36 +0000849 inline Value **unwrap(LLVMValueRef *Vals) {
850 return reinterpret_cast<Value**>(Vals);
851 }
852
853 template<typename T>
854 inline T **unwrap(LLVMValueRef *Vals, unsigned Length) {
855 #if DEBUG
Chris Lattnerb7971152009-07-10 18:28:19 +0000856 for (LLVMValueRef *I = Vals, *E = Vals + Length; I != E; ++I)
Gordon Henriksen7330acd2007-10-05 23:59:36 +0000857 cast<T>(*I);
858 #endif
859 return reinterpret_cast<T**>(Vals);
860 }
861
Gordon Henriksen7330acd2007-10-05 23:59:36 +0000862 inline LLVMValueRef *wrap(const Value **Vals) {
863 return reinterpret_cast<LLVMValueRef*>(const_cast<Value**>(Vals));
864 }
Gordon Henriksen7330acd2007-10-05 23:59:36 +0000865}
866
867#endif /* !defined(__cplusplus) */
868
869#endif /* !defined(LLVM_C_CORE_H) */