blob: d723d11111afb87e825bf866f64ec395e896ae49 [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 */
Chris Lattnerdac44ec2009-07-15 22:00:31 +0000118 LLVMVectorTypeKind, /**< SIMD 'packed' format, or other vector type */
119 LLVMMetadataTypeKind /**< Metadata */
Gordon Henriksen76a03742007-09-18 03:18:57 +0000120} LLVMTypeKind;
121
122typedef enum {
Gordon Henriksen4a4d7352007-12-30 17:46:33 +0000123 LLVMExternalLinkage, /**< Externally visible function */
Chris Lattner2dba0f02009-04-13 06:25:37 +0000124 LLVMAvailableExternallyLinkage,
Duncan Sands12da8ce2009-03-07 15:45:40 +0000125 LLVMLinkOnceAnyLinkage, /**< Keep one copy of function when linking (inline)*/
126 LLVMLinkOnceODRLinkage, /**< Same, but only replaced by something
127 equivalent. */
128 LLVMWeakAnyLinkage, /**< Keep one copy of function when linking (weak) */
129 LLVMWeakODRLinkage, /**< Same, but only replaced by something
130 equivalent. */
Gordon Henriksen4a4d7352007-12-30 17:46:33 +0000131 LLVMAppendingLinkage, /**< Special purpose, only applies to global arrays */
132 LLVMInternalLinkage, /**< Rename collisions when linking (static
133 functions) */
Duncan Sands12da8ce2009-03-07 15:45:40 +0000134 LLVMPrivateLinkage, /**< Like Internal, but omit from symbol table */
Gordon Henriksen4a4d7352007-12-30 17:46:33 +0000135 LLVMDLLImportLinkage, /**< Function to be imported from DLL */
136 LLVMDLLExportLinkage, /**< Function to be accessible from DLL */
Duncan Sandse2881052009-03-11 08:08:06 +0000137 LLVMExternalWeakLinkage,/**< ExternalWeak linkage description */
Duncan Sands12da8ce2009-03-07 15:45:40 +0000138 LLVMGhostLinkage, /**< Stand-in functions for streaming fns from
Gordon Henriksen4a4d7352007-12-30 17:46:33 +0000139 bitcode */
Duncan Sands4581beb2009-03-11 20:14:15 +0000140 LLVMCommonLinkage /**< Tentative definitions */
Gordon Henriksen76a03742007-09-18 03:18:57 +0000141} LLVMLinkage;
142
143typedef enum {
Gordon Henriksen4a4d7352007-12-30 17:46:33 +0000144 LLVMDefaultVisibility, /**< The GV is visible */
145 LLVMHiddenVisibility, /**< The GV is hidden */
146 LLVMProtectedVisibility /**< The GV is protected */
Gordon Henriksen76a03742007-09-18 03:18:57 +0000147} LLVMVisibility;
148
Gordon Henriksenc23b66c2007-09-26 20:56:12 +0000149typedef enum {
150 LLVMCCallConv = 0,
151 LLVMFastCallConv = 8,
152 LLVMColdCallConv = 9,
153 LLVMX86StdcallCallConv = 64,
154 LLVMX86FastcallCallConv = 65
155} LLVMCallConv;
156
157typedef enum {
Gordon Henriksen4a4d7352007-12-30 17:46:33 +0000158 LLVMIntEQ = 32, /**< equal */
159 LLVMIntNE, /**< not equal */
160 LLVMIntUGT, /**< unsigned greater than */
161 LLVMIntUGE, /**< unsigned greater or equal */
162 LLVMIntULT, /**< unsigned less than */
163 LLVMIntULE, /**< unsigned less or equal */
164 LLVMIntSGT, /**< signed greater than */
165 LLVMIntSGE, /**< signed greater or equal */
166 LLVMIntSLT, /**< signed less than */
167 LLVMIntSLE /**< signed less or equal */
Gordon Henriksenc23b66c2007-09-26 20:56:12 +0000168} LLVMIntPredicate;
169
170typedef enum {
Gordon Henriksen4a4d7352007-12-30 17:46:33 +0000171 LLVMRealPredicateFalse, /**< Always false (always folded) */
172 LLVMRealOEQ, /**< True if ordered and equal */
173 LLVMRealOGT, /**< True if ordered and greater than */
174 LLVMRealOGE, /**< True if ordered and greater than or equal */
175 LLVMRealOLT, /**< True if ordered and less than */
176 LLVMRealOLE, /**< True if ordered and less than or equal */
177 LLVMRealONE, /**< True if ordered and operands are unequal */
178 LLVMRealORD, /**< True if ordered (no nans) */
179 LLVMRealUNO, /**< True if unordered: isnan(X) | isnan(Y) */
180 LLVMRealUEQ, /**< True if unordered or equal */
181 LLVMRealUGT, /**< True if unordered or greater than */
182 LLVMRealUGE, /**< True if unordered, greater than, or equal */
183 LLVMRealULT, /**< True if unordered or less than */
184 LLVMRealULE, /**< True if unordered, less than, or equal */
185 LLVMRealUNE, /**< True if unordered or not equal */
186 LLVMRealPredicateTrue /**< Always true (always folded) */
Gordon Henriksenc23b66c2007-09-26 20:56:12 +0000187} LLVMRealPredicate;
188
Gordon Henriksen76a03742007-09-18 03:18:57 +0000189
Gordon Henriksen34eb6d82007-12-19 22:30:40 +0000190/*===-- Error handling ----------------------------------------------------===*/
191
192void LLVMDisposeMessage(char *Message);
193
194
Gordon Henriksen76a03742007-09-18 03:18:57 +0000195/*===-- Modules -----------------------------------------------------------===*/
196
Owen Anderson6773d382009-07-01 16:58:40 +0000197/* Create and destroy contexts. */
198LLVMContextRef LLVMContextCreate();
Owen Andersonf7691d32009-07-02 00:16:38 +0000199LLVMContextRef LLVMGetGlobalContext();
Owen Anderson6773d382009-07-01 16:58:40 +0000200void LLVMContextDispose(LLVMContextRef C);
201
Gordon Henriksen76a03742007-09-18 03:18:57 +0000202/* Create and destroy modules. */
Gordon Henriksena49d4352008-03-07 19:13:06 +0000203/** See llvm::Module::Module. */
Gordon Henriksen76a03742007-09-18 03:18:57 +0000204LLVMModuleRef LLVMModuleCreateWithName(const char *ModuleID);
Owen Anderson31d44e42009-07-02 07:17:57 +0000205LLVMModuleRef LLVMModuleCreateWithNameInContext(const char *ModuleID,
206 LLVMContextRef C);
Gordon Henriksena49d4352008-03-07 19:13:06 +0000207
208/** See llvm::Module::~Module. */
Gordon Henriksen76a03742007-09-18 03:18:57 +0000209void LLVMDisposeModule(LLVMModuleRef M);
210
Gordon Henriksena49d4352008-03-07 19:13:06 +0000211/** Data layout. See Module::getDataLayout. */
Gordon Henriksen05568bb2007-12-27 20:13:47 +0000212const char *LLVMGetDataLayout(LLVMModuleRef M);
213void LLVMSetDataLayout(LLVMModuleRef M, const char *Triple);
214
Gordon Henriksena49d4352008-03-07 19:13:06 +0000215/** Target triple. See Module::getTargetTriple. */
Gordon Henriksen05568bb2007-12-27 20:13:47 +0000216const char *LLVMGetTarget(LLVMModuleRef M);
217void LLVMSetTarget(LLVMModuleRef M, const char *Triple);
218
Gordon Henriksena49d4352008-03-07 19:13:06 +0000219/** See Module::addTypeName. */
Gordon Henriksen76a03742007-09-18 03:18:57 +0000220int LLVMAddTypeName(LLVMModuleRef M, const char *Name, LLVMTypeRef Ty);
Gordon Henriksenc23b66c2007-09-26 20:56:12 +0000221void LLVMDeleteTypeName(LLVMModuleRef M, const char *Name);
Chris Lattner7f318242009-07-06 17:29:59 +0000222LLVMTypeRef LLVMGetTypeByName(LLVMModuleRef M, const char *Name);
Gordon Henriksen76a03742007-09-18 03:18:57 +0000223
Gordon Henriksen6c6075e2008-03-14 23:58:56 +0000224/** See Module::dump. */
225void LLVMDumpModule(LLVMModuleRef M);
226
Gordon Henriksen76a03742007-09-18 03:18:57 +0000227
Gordon Henriksenc23b66c2007-09-26 20:56:12 +0000228/*===-- Types -------------------------------------------------------------===*/
Gordon Henriksen76a03742007-09-18 03:18:57 +0000229
230/* LLVM types conform to the following hierarchy:
231 *
232 * types:
233 * integer type
234 * real type
235 * function type
236 * sequence types:
237 * array type
238 * pointer type
239 * vector type
240 * void type
241 * label type
242 * opaque type
243 */
244
Gordon Henriksena49d4352008-03-07 19:13:06 +0000245/** See llvm::LLVMTypeKind::getTypeID. */
Gordon Henriksen76a03742007-09-18 03:18:57 +0000246LLVMTypeKind LLVMGetTypeKind(LLVMTypeRef Ty);
Gordon Henriksena49d4352008-03-07 19:13:06 +0000247
Gordon Henriksen76a03742007-09-18 03:18:57 +0000248/* Operations on integer types */
Gordon Henriksena735a9c2008-05-04 12:55:34 +0000249LLVMTypeRef LLVMInt1Type(void);
250LLVMTypeRef LLVMInt8Type(void);
251LLVMTypeRef LLVMInt16Type(void);
252LLVMTypeRef LLVMInt32Type(void);
253LLVMTypeRef LLVMInt64Type(void);
Gordon Henriksened7beaa2007-10-06 16:05:20 +0000254LLVMTypeRef LLVMIntType(unsigned NumBits);
Gordon Henriksenc23b66c2007-09-26 20:56:12 +0000255unsigned LLVMGetIntTypeWidth(LLVMTypeRef IntegerTy);
Gordon Henriksen76a03742007-09-18 03:18:57 +0000256
257/* Operations on real types */
Gordon Henriksena735a9c2008-05-04 12:55:34 +0000258LLVMTypeRef LLVMFloatType(void);
259LLVMTypeRef LLVMDoubleType(void);
260LLVMTypeRef LLVMX86FP80Type(void);
261LLVMTypeRef LLVMFP128Type(void);
262LLVMTypeRef LLVMPPCFP128Type(void);
Gordon Henriksen76a03742007-09-18 03:18:57 +0000263
264/* Operations on function types */
Gordon Henriksened7beaa2007-10-06 16:05:20 +0000265LLVMTypeRef LLVMFunctionType(LLVMTypeRef ReturnType,
266 LLVMTypeRef *ParamTypes, unsigned ParamCount,
267 int IsVarArg);
Gordon Henriksen76a03742007-09-18 03:18:57 +0000268int LLVMIsFunctionVarArg(LLVMTypeRef FunctionTy);
Gordon Henriksenc23b66c2007-09-26 20:56:12 +0000269LLVMTypeRef LLVMGetReturnType(LLVMTypeRef FunctionTy);
270unsigned LLVMCountParamTypes(LLVMTypeRef FunctionTy);
271void LLVMGetParamTypes(LLVMTypeRef FunctionTy, LLVMTypeRef *Dest);
Gordon Henriksen76a03742007-09-18 03:18:57 +0000272
273/* Operations on struct types */
Gordon Henriksened7beaa2007-10-06 16:05:20 +0000274LLVMTypeRef LLVMStructType(LLVMTypeRef *ElementTypes, unsigned ElementCount,
275 int Packed);
Gordon Henriksenc23b66c2007-09-26 20:56:12 +0000276unsigned LLVMCountStructElementTypes(LLVMTypeRef StructTy);
Gordon Henriksen76a03742007-09-18 03:18:57 +0000277void LLVMGetStructElementTypes(LLVMTypeRef StructTy, LLVMTypeRef *Dest);
278int LLVMIsPackedStruct(LLVMTypeRef StructTy);
279
280/* Operations on array, pointer, and vector types (sequence types) */
Gordon Henriksened7beaa2007-10-06 16:05:20 +0000281LLVMTypeRef LLVMArrayType(LLVMTypeRef ElementType, unsigned ElementCount);
Gordon Henriksen5a3fe032007-12-17 16:08:32 +0000282LLVMTypeRef LLVMPointerType(LLVMTypeRef ElementType, unsigned AddressSpace);
Gordon Henriksened7beaa2007-10-06 16:05:20 +0000283LLVMTypeRef LLVMVectorType(LLVMTypeRef ElementType, unsigned ElementCount);
Gordon Henriksen76a03742007-09-18 03:18:57 +0000284
285LLVMTypeRef LLVMGetElementType(LLVMTypeRef Ty);
286unsigned LLVMGetArrayLength(LLVMTypeRef ArrayTy);
Gordon Henriksen5a3fe032007-12-17 16:08:32 +0000287unsigned LLVMGetPointerAddressSpace(LLVMTypeRef PointerTy);
Gordon Henriksen76a03742007-09-18 03:18:57 +0000288unsigned LLVMGetVectorSize(LLVMTypeRef VectorTy);
289
290/* Operations on other types */
Gordon Henriksena735a9c2008-05-04 12:55:34 +0000291LLVMTypeRef LLVMVoidType(void);
292LLVMTypeRef LLVMLabelType(void);
293LLVMTypeRef LLVMOpaqueType(void);
Gordon Henriksen76a03742007-09-18 03:18:57 +0000294
Gordon Henriksenffb48762007-10-07 00:13:35 +0000295/* Operations on type handles */
296LLVMTypeHandleRef LLVMCreateTypeHandle(LLVMTypeRef PotentiallyAbstractTy);
297void LLVMRefineType(LLVMTypeRef AbstractTy, LLVMTypeRef ConcreteTy);
298LLVMTypeRef LLVMResolveTypeHandle(LLVMTypeHandleRef TypeHandle);
299void LLVMDisposeTypeHandle(LLVMTypeHandleRef TypeHandle);
300
Gordon Henriksen76a03742007-09-18 03:18:57 +0000301
302/*===-- Values ------------------------------------------------------------===*/
303
304/* The bulk of LLVM's object model consists of values, which comprise a very
305 * rich type hierarchy.
Gordon Henriksen76a03742007-09-18 03:18:57 +0000306 */
307
Gordon Henriksen29e38942008-12-19 18:39:45 +0000308#define LLVM_FOR_EACH_VALUE_SUBCLASS(macro) \
309 macro(Argument) \
310 macro(BasicBlock) \
311 macro(InlineAsm) \
312 macro(User) \
313 macro(Constant) \
314 macro(ConstantAggregateZero) \
315 macro(ConstantArray) \
316 macro(ConstantExpr) \
317 macro(ConstantFP) \
318 macro(ConstantInt) \
319 macro(ConstantPointerNull) \
320 macro(ConstantStruct) \
321 macro(ConstantVector) \
322 macro(GlobalValue) \
323 macro(Function) \
324 macro(GlobalAlias) \
325 macro(GlobalVariable) \
326 macro(UndefValue) \
327 macro(Instruction) \
328 macro(BinaryOperator) \
329 macro(CallInst) \
330 macro(IntrinsicInst) \
331 macro(DbgInfoIntrinsic) \
332 macro(DbgDeclareInst) \
333 macro(DbgFuncStartInst) \
334 macro(DbgRegionEndInst) \
335 macro(DbgRegionStartInst) \
336 macro(DbgStopPointInst) \
337 macro(EHSelectorInst) \
338 macro(MemIntrinsic) \
339 macro(MemCpyInst) \
340 macro(MemMoveInst) \
341 macro(MemSetInst) \
342 macro(CmpInst) \
343 macro(FCmpInst) \
344 macro(ICmpInst) \
Gordon Henriksen29e38942008-12-19 18:39:45 +0000345 macro(ExtractElementInst) \
346 macro(GetElementPtrInst) \
347 macro(InsertElementInst) \
348 macro(InsertValueInst) \
349 macro(PHINode) \
350 macro(SelectInst) \
351 macro(ShuffleVectorInst) \
352 macro(StoreInst) \
353 macro(TerminatorInst) \
354 macro(BranchInst) \
355 macro(InvokeInst) \
356 macro(ReturnInst) \
357 macro(SwitchInst) \
358 macro(UnreachableInst) \
359 macro(UnwindInst) \
360 macro(UnaryInstruction) \
361 macro(AllocationInst) \
Gordon Henriksen05a868f2008-12-19 18:51:17 +0000362 macro(AllocaInst) \
363 macro(MallocInst) \
Gordon Henriksen29e38942008-12-19 18:39:45 +0000364 macro(CastInst) \
Gordon Henriksen05a868f2008-12-19 18:51:17 +0000365 macro(BitCastInst) \
366 macro(FPExtInst) \
367 macro(FPToSIInst) \
368 macro(FPToUIInst) \
369 macro(FPTruncInst) \
370 macro(IntToPtrInst) \
371 macro(PtrToIntInst) \
372 macro(SExtInst) \
373 macro(SIToFPInst) \
374 macro(TruncInst) \
375 macro(UIToFPInst) \
376 macro(ZExtInst) \
377 macro(ExtractValueInst) \
378 macro(FreeInst) \
379 macro(LoadInst) \
380 macro(VAArgInst)
Gordon Henriksen29e38942008-12-19 18:39:45 +0000381
Gordon Henriksen76a03742007-09-18 03:18:57 +0000382/* Operations on all values */
Gordon Henriksenc23b66c2007-09-26 20:56:12 +0000383LLVMTypeRef LLVMTypeOf(LLVMValueRef Val);
Gordon Henriksen76a03742007-09-18 03:18:57 +0000384const char *LLVMGetValueName(LLVMValueRef Val);
385void LLVMSetValueName(LLVMValueRef Val, const char *Name);
Gordon Henriksen1d0d24c2007-10-06 00:08:49 +0000386void LLVMDumpValue(LLVMValueRef Val);
Gordon Henriksen76a03742007-09-18 03:18:57 +0000387
Gordon Henriksen29e38942008-12-19 18:39:45 +0000388/* Conversion functions. Return the input value if it is an instance of the
389 specified class, otherwise NULL. See llvm::dyn_cast_or_null<>. */
390#define LLVM_DECLARE_VALUE_CAST(name) \
391 LLVMValueRef LLVMIsA##name(LLVMValueRef Val);
392LLVM_FOR_EACH_VALUE_SUBCLASS(LLVM_DECLARE_VALUE_CAST)
393
Gordon Henriksen76a03742007-09-18 03:18:57 +0000394/* Operations on constants of any type */
Gordon Henriksen1046c732007-10-06 15:11:06 +0000395LLVMValueRef LLVMConstNull(LLVMTypeRef Ty); /* all zeroes */
396LLVMValueRef LLVMConstAllOnes(LLVMTypeRef Ty); /* only for int/vector */
Gordon Henriksen76a03742007-09-18 03:18:57 +0000397LLVMValueRef LLVMGetUndef(LLVMTypeRef Ty);
Gordon Henriksendc88c062007-09-18 18:07:51 +0000398int LLVMIsConstant(LLVMValueRef Val);
Gordon Henriksen76a03742007-09-18 03:18:57 +0000399int LLVMIsNull(LLVMValueRef Val);
Gordon Henriksendc88c062007-09-18 18:07:51 +0000400int LLVMIsUndef(LLVMValueRef Val);
Chris Lattner7f318242009-07-06 17:29:59 +0000401LLVMValueRef LLVMConstPointerNull(LLVMTypeRef Ty);
Gordon Henriksen76a03742007-09-18 03:18:57 +0000402
403/* Operations on scalar constants */
Gordon Henriksen1046c732007-10-06 15:11:06 +0000404LLVMValueRef LLVMConstInt(LLVMTypeRef IntTy, unsigned long long N,
405 int SignExtend);
406LLVMValueRef LLVMConstReal(LLVMTypeRef RealTy, double N);
Gordon Henriksen931e1212008-02-02 01:07:50 +0000407LLVMValueRef LLVMConstRealOfString(LLVMTypeRef RealTy, const char *Text);
Gordon Henriksen76a03742007-09-18 03:18:57 +0000408
409/* Operations on composite constants */
Gordon Henriksen1046c732007-10-06 15:11:06 +0000410LLVMValueRef LLVMConstString(const char *Str, unsigned Length,
411 int DontNullTerminate);
Gordon Henriksen2ad5aef2008-04-25 03:21:19 +0000412LLVMValueRef LLVMConstArray(LLVMTypeRef ElementTy,
Gordon Henriksen1046c732007-10-06 15:11:06 +0000413 LLVMValueRef *ConstantVals, unsigned Length);
414LLVMValueRef LLVMConstStruct(LLVMValueRef *ConstantVals, unsigned Count,
415 int packed);
416LLVMValueRef LLVMConstVector(LLVMValueRef *ScalarConstantVals, unsigned Size);
Gordon Henriksen76a03742007-09-18 03:18:57 +0000417
Gordon Henriksen7ce31762007-10-06 14:29:36 +0000418/* Constant expressions */
419LLVMValueRef LLVMSizeOf(LLVMTypeRef Ty);
420LLVMValueRef LLVMConstNeg(LLVMValueRef ConstantVal);
421LLVMValueRef LLVMConstNot(LLVMValueRef ConstantVal);
422LLVMValueRef LLVMConstAdd(LLVMValueRef LHSConstant, LLVMValueRef RHSConstant);
423LLVMValueRef LLVMConstSub(LLVMValueRef LHSConstant, LLVMValueRef RHSConstant);
424LLVMValueRef LLVMConstMul(LLVMValueRef LHSConstant, LLVMValueRef RHSConstant);
425LLVMValueRef LLVMConstUDiv(LLVMValueRef LHSConstant, LLVMValueRef RHSConstant);
426LLVMValueRef LLVMConstSDiv(LLVMValueRef LHSConstant, LLVMValueRef RHSConstant);
427LLVMValueRef LLVMConstFDiv(LLVMValueRef LHSConstant, LLVMValueRef RHSConstant);
428LLVMValueRef LLVMConstURem(LLVMValueRef LHSConstant, LLVMValueRef RHSConstant);
429LLVMValueRef LLVMConstSRem(LLVMValueRef LHSConstant, LLVMValueRef RHSConstant);
430LLVMValueRef LLVMConstFRem(LLVMValueRef LHSConstant, LLVMValueRef RHSConstant);
431LLVMValueRef LLVMConstAnd(LLVMValueRef LHSConstant, LLVMValueRef RHSConstant);
432LLVMValueRef LLVMConstOr(LLVMValueRef LHSConstant, LLVMValueRef RHSConstant);
433LLVMValueRef LLVMConstXor(LLVMValueRef LHSConstant, LLVMValueRef RHSConstant);
434LLVMValueRef LLVMConstICmp(LLVMIntPredicate Predicate,
435 LLVMValueRef LHSConstant, LLVMValueRef RHSConstant);
436LLVMValueRef LLVMConstFCmp(LLVMRealPredicate Predicate,
437 LLVMValueRef LHSConstant, LLVMValueRef RHSConstant);
438LLVMValueRef LLVMConstShl(LLVMValueRef LHSConstant, LLVMValueRef RHSConstant);
439LLVMValueRef LLVMConstLShr(LLVMValueRef LHSConstant, LLVMValueRef RHSConstant);
440LLVMValueRef LLVMConstAShr(LLVMValueRef LHSConstant, LLVMValueRef RHSConstant);
441LLVMValueRef LLVMConstGEP(LLVMValueRef ConstantVal,
442 LLVMValueRef *ConstantIndices, unsigned NumIndices);
443LLVMValueRef LLVMConstTrunc(LLVMValueRef ConstantVal, LLVMTypeRef ToType);
444LLVMValueRef LLVMConstSExt(LLVMValueRef ConstantVal, LLVMTypeRef ToType);
445LLVMValueRef LLVMConstZExt(LLVMValueRef ConstantVal, LLVMTypeRef ToType);
446LLVMValueRef LLVMConstFPTrunc(LLVMValueRef ConstantVal, LLVMTypeRef ToType);
447LLVMValueRef LLVMConstFPExt(LLVMValueRef ConstantVal, LLVMTypeRef ToType);
448LLVMValueRef LLVMConstUIToFP(LLVMValueRef ConstantVal, LLVMTypeRef ToType);
449LLVMValueRef LLVMConstSIToFP(LLVMValueRef ConstantVal, LLVMTypeRef ToType);
450LLVMValueRef LLVMConstFPToUI(LLVMValueRef ConstantVal, LLVMTypeRef ToType);
451LLVMValueRef LLVMConstFPToSI(LLVMValueRef ConstantVal, LLVMTypeRef ToType);
452LLVMValueRef LLVMConstPtrToInt(LLVMValueRef ConstantVal, LLVMTypeRef ToType);
453LLVMValueRef LLVMConstIntToPtr(LLVMValueRef ConstantVal, LLVMTypeRef ToType);
454LLVMValueRef LLVMConstBitCast(LLVMValueRef ConstantVal, LLVMTypeRef ToType);
455LLVMValueRef LLVMConstSelect(LLVMValueRef ConstantCondition,
456 LLVMValueRef ConstantIfTrue,
457 LLVMValueRef ConstantIfFalse);
458LLVMValueRef LLVMConstExtractElement(LLVMValueRef VectorConstant,
459 LLVMValueRef IndexConstant);
460LLVMValueRef LLVMConstInsertElement(LLVMValueRef VectorConstant,
461 LLVMValueRef ElementValueConstant,
462 LLVMValueRef IndexConstant);
463LLVMValueRef LLVMConstShuffleVector(LLVMValueRef VectorAConstant,
464 LLVMValueRef VectorBConstant,
465 LLVMValueRef MaskConstant);
Dan Gohmand5104a52008-11-03 22:55:43 +0000466LLVMValueRef LLVMConstExtractValue(LLVMValueRef AggConstant, unsigned *IdxList,
467 unsigned NumIdx);
468LLVMValueRef LLVMConstInsertValue(LLVMValueRef AggConstant,
469 LLVMValueRef ElementValueConstant,
470 unsigned *IdxList, unsigned NumIdx);
Chris Lattner3d1f5522008-12-17 21:39:50 +0000471LLVMValueRef LLVMConstInlineAsm(LLVMTypeRef Ty,
472 const char *AsmString, const char *Constraints,
473 int HasSideEffects);
Gordon Henriksen7ce31762007-10-06 14:29:36 +0000474
Gordon Henriksen76a03742007-09-18 03:18:57 +0000475/* Operations on global variables, functions, and aliases (globals) */
Gordon Henriksen265f7802008-03-19 01:11:35 +0000476LLVMModuleRef LLVMGetGlobalParent(LLVMValueRef Global);
Gordon Henriksen76a03742007-09-18 03:18:57 +0000477int LLVMIsDeclaration(LLVMValueRef Global);
478LLVMLinkage LLVMGetLinkage(LLVMValueRef Global);
479void LLVMSetLinkage(LLVMValueRef Global, LLVMLinkage Linkage);
480const char *LLVMGetSection(LLVMValueRef Global);
481void LLVMSetSection(LLVMValueRef Global, const char *Section);
482LLVMVisibility LLVMGetVisibility(LLVMValueRef Global);
483void LLVMSetVisibility(LLVMValueRef Global, LLVMVisibility Viz);
484unsigned LLVMGetAlignment(LLVMValueRef Global);
485void LLVMSetAlignment(LLVMValueRef Global, unsigned Bytes);
486
487/* Operations on global variables */
488LLVMValueRef LLVMAddGlobal(LLVMModuleRef M, LLVMTypeRef Ty, const char *Name);
Gordon Henriksen783f7bb2007-10-08 03:45:09 +0000489LLVMValueRef LLVMGetNamedGlobal(LLVMModuleRef M, const char *Name);
Gordon Henriksen07a45f42008-03-23 22:21:29 +0000490LLVMValueRef LLVMGetFirstGlobal(LLVMModuleRef M);
491LLVMValueRef LLVMGetLastGlobal(LLVMModuleRef M);
492LLVMValueRef LLVMGetNextGlobal(LLVMValueRef GlobalVar);
493LLVMValueRef LLVMGetPreviousGlobal(LLVMValueRef GlobalVar);
Gordon Henriksen76a03742007-09-18 03:18:57 +0000494void LLVMDeleteGlobal(LLVMValueRef GlobalVar);
Gordon Henriksen76a03742007-09-18 03:18:57 +0000495LLVMValueRef LLVMGetInitializer(LLVMValueRef GlobalVar);
496void LLVMSetInitializer(LLVMValueRef GlobalVar, LLVMValueRef ConstantVal);
497int LLVMIsThreadLocal(LLVMValueRef GlobalVar);
498void LLVMSetThreadLocal(LLVMValueRef GlobalVar, int IsThreadLocal);
Gordon Henriksen751ebf72007-10-07 17:31:42 +0000499int LLVMIsGlobalConstant(LLVMValueRef GlobalVar);
500void LLVMSetGlobalConstant(LLVMValueRef GlobalVar, int IsConstant);
Gordon Henriksen76a03742007-09-18 03:18:57 +0000501
Chris Lattner3d1f5522008-12-17 21:39:50 +0000502/* Operations on aliases */
503LLVMValueRef LLVMAddAlias(LLVMModuleRef M, LLVMTypeRef Ty, LLVMValueRef Aliasee,
504 const char *Name);
505
Gordon Henriksenc23b66c2007-09-26 20:56:12 +0000506/* Operations on functions */
507LLVMValueRef LLVMAddFunction(LLVMModuleRef M, const char *Name,
508 LLVMTypeRef FunctionTy);
Gordon Henriksen783f7bb2007-10-08 03:45:09 +0000509LLVMValueRef LLVMGetNamedFunction(LLVMModuleRef M, const char *Name);
Gordon Henriksen054817c2008-03-19 03:47:18 +0000510LLVMValueRef LLVMGetFirstFunction(LLVMModuleRef M);
511LLVMValueRef LLVMGetLastFunction(LLVMModuleRef M);
512LLVMValueRef LLVMGetNextFunction(LLVMValueRef Fn);
513LLVMValueRef LLVMGetPreviousFunction(LLVMValueRef Fn);
Gordon Henriksenc23b66c2007-09-26 20:56:12 +0000514void LLVMDeleteFunction(LLVMValueRef Fn);
Gordon Henriksenc23b66c2007-09-26 20:56:12 +0000515unsigned LLVMGetIntrinsicID(LLVMValueRef Fn);
516unsigned LLVMGetFunctionCallConv(LLVMValueRef Fn);
517void LLVMSetFunctionCallConv(LLVMValueRef Fn, unsigned CC);
Gordon Henriksend930f912008-08-17 18:44:35 +0000518const char *LLVMGetGC(LLVMValueRef Fn);
519void LLVMSetGC(LLVMValueRef Fn, const char *Name);
Duncan Sands7374a012009-05-06 12:21:17 +0000520void LLVMAddFunctionAttr(LLVMValueRef Fn, LLVMAttribute PA);
521void LLVMRemoveFunctionAttr(LLVMValueRef Fn, LLVMAttribute PA);
Gordon Henriksenc23b66c2007-09-26 20:56:12 +0000522
Gordon Henriksen265f7802008-03-19 01:11:35 +0000523/* Operations on parameters */
524unsigned LLVMCountParams(LLVMValueRef Fn);
525void LLVMGetParams(LLVMValueRef Fn, LLVMValueRef *Params);
526LLVMValueRef LLVMGetParam(LLVMValueRef Fn, unsigned Index);
527LLVMValueRef LLVMGetParamParent(LLVMValueRef Inst);
Gordon Henriksen07a45f42008-03-23 22:21:29 +0000528LLVMValueRef LLVMGetFirstParam(LLVMValueRef Fn);
529LLVMValueRef LLVMGetLastParam(LLVMValueRef Fn);
530LLVMValueRef LLVMGetNextParam(LLVMValueRef Arg);
531LLVMValueRef LLVMGetPreviousParam(LLVMValueRef Arg);
Devang Patel4c758ea2008-09-25 21:00:45 +0000532void LLVMAddAttribute(LLVMValueRef Arg, LLVMAttribute PA);
533void LLVMRemoveAttribute(LLVMValueRef Arg, LLVMAttribute PA);
Gordon Henriksen2d9cc212008-04-28 17:37:06 +0000534void LLVMSetParamAlignment(LLVMValueRef Arg, unsigned align);
Gordon Henriksen265f7802008-03-19 01:11:35 +0000535
Gordon Henriksenc23b66c2007-09-26 20:56:12 +0000536/* Operations on basic blocks */
Gordon Henriksen07a45f42008-03-23 22:21:29 +0000537LLVMValueRef LLVMBasicBlockAsValue(LLVMBasicBlockRef BB);
Gordon Henriksenc23b66c2007-09-26 20:56:12 +0000538int LLVMValueIsBasicBlock(LLVMValueRef Val);
539LLVMBasicBlockRef LLVMValueAsBasicBlock(LLVMValueRef Val);
Gordon Henriksen07a45f42008-03-23 22:21:29 +0000540LLVMValueRef LLVMGetBasicBlockParent(LLVMBasicBlockRef BB);
Gordon Henriksenc23b66c2007-09-26 20:56:12 +0000541unsigned LLVMCountBasicBlocks(LLVMValueRef Fn);
542void LLVMGetBasicBlocks(LLVMValueRef Fn, LLVMBasicBlockRef *BasicBlocks);
Gordon Henriksen054817c2008-03-19 03:47:18 +0000543LLVMBasicBlockRef LLVMGetFirstBasicBlock(LLVMValueRef Fn);
544LLVMBasicBlockRef LLVMGetLastBasicBlock(LLVMValueRef Fn);
545LLVMBasicBlockRef LLVMGetNextBasicBlock(LLVMBasicBlockRef BB);
546LLVMBasicBlockRef LLVMGetPreviousBasicBlock(LLVMBasicBlockRef BB);
Gordon Henriksenc23b66c2007-09-26 20:56:12 +0000547LLVMBasicBlockRef LLVMGetEntryBasicBlock(LLVMValueRef Fn);
548LLVMBasicBlockRef LLVMAppendBasicBlock(LLVMValueRef Fn, const char *Name);
549LLVMBasicBlockRef LLVMInsertBasicBlock(LLVMBasicBlockRef InsertBeforeBB,
550 const char *Name);
551void LLVMDeleteBasicBlock(LLVMBasicBlockRef BB);
552
Gordon Henriksen265f7802008-03-19 01:11:35 +0000553/* Operations on instructions */
554LLVMBasicBlockRef LLVMGetInstructionParent(LLVMValueRef Inst);
Gordon Henriksen054817c2008-03-19 03:47:18 +0000555LLVMValueRef LLVMGetFirstInstruction(LLVMBasicBlockRef BB);
556LLVMValueRef LLVMGetLastInstruction(LLVMBasicBlockRef BB);
557LLVMValueRef LLVMGetNextInstruction(LLVMValueRef Inst);
558LLVMValueRef LLVMGetPreviousInstruction(LLVMValueRef Inst);
Gordon Henriksen265f7802008-03-19 01:11:35 +0000559
Gordon Henriksen1158c532007-12-29 20:45:00 +0000560/* Operations on call sites */
561void LLVMSetInstructionCallConv(LLVMValueRef Instr, unsigned CC);
562unsigned LLVMGetInstructionCallConv(LLVMValueRef Instr);
Devang Patel4c758ea2008-09-25 21:00:45 +0000563void LLVMAddInstrAttribute(LLVMValueRef Instr, unsigned index, LLVMAttribute);
564void LLVMRemoveInstrAttribute(LLVMValueRef Instr, unsigned index,
565 LLVMAttribute);
Gordon Henriksen2d9cc212008-04-28 17:37:06 +0000566void LLVMSetInstrParamAlignment(LLVMValueRef Instr, unsigned index,
567 unsigned align);
Gordon Henriksen1158c532007-12-29 20:45:00 +0000568
Gordon Henrikseneeb65372008-08-30 16:34:54 +0000569/* Operations on call instructions (only) */
570int LLVMIsTailCall(LLVMValueRef CallInst);
571void LLVMSetTailCall(LLVMValueRef CallInst, int IsTailCall);
572
Gordon Henriksen44dd8fb2007-10-08 18:14:39 +0000573/* Operations on phi nodes */
574void LLVMAddIncoming(LLVMValueRef PhiNode, LLVMValueRef *IncomingValues,
575 LLVMBasicBlockRef *IncomingBlocks, unsigned Count);
576unsigned LLVMCountIncoming(LLVMValueRef PhiNode);
577LLVMValueRef LLVMGetIncomingValue(LLVMValueRef PhiNode, unsigned Index);
578LLVMBasicBlockRef LLVMGetIncomingBlock(LLVMValueRef PhiNode, unsigned Index);
Gordon Henriksenc23b66c2007-09-26 20:56:12 +0000579
580/*===-- Instruction builders ----------------------------------------------===*/
581
582/* An instruction builder represents a point within a basic block, and is the
583 * exclusive means of building instructions using the C interface.
584 */
585
Gordon Henriksena735a9c2008-05-04 12:55:34 +0000586LLVMBuilderRef LLVMCreateBuilder(void);
Gordon Henriksen054817c2008-03-19 03:47:18 +0000587void LLVMPositionBuilder(LLVMBuilderRef Builder, LLVMBasicBlockRef Block,
588 LLVMValueRef Instr);
Gordon Henriksenc23b66c2007-09-26 20:56:12 +0000589void LLVMPositionBuilderBefore(LLVMBuilderRef Builder, LLVMValueRef Instr);
590void LLVMPositionBuilderAtEnd(LLVMBuilderRef Builder, LLVMBasicBlockRef Block);
Gordon Henriksen265f7802008-03-19 01:11:35 +0000591LLVMBasicBlockRef LLVMGetInsertBlock(LLVMBuilderRef Builder);
Chris Lattner3d1f5522008-12-17 21:39:50 +0000592void LLVMClearInsertionPosition(LLVMBuilderRef Builder);
593void LLVMInsertIntoBuilder(LLVMBuilderRef Builder, LLVMValueRef Instr);
Gordon Henriksenc23b66c2007-09-26 20:56:12 +0000594void LLVMDisposeBuilder(LLVMBuilderRef Builder);
595
596/* Terminators */
597LLVMValueRef LLVMBuildRetVoid(LLVMBuilderRef);
598LLVMValueRef LLVMBuildRet(LLVMBuilderRef, LLVMValueRef V);
599LLVMValueRef LLVMBuildBr(LLVMBuilderRef, LLVMBasicBlockRef Dest);
600LLVMValueRef LLVMBuildCondBr(LLVMBuilderRef, LLVMValueRef If,
601 LLVMBasicBlockRef Then, LLVMBasicBlockRef Else);
602LLVMValueRef LLVMBuildSwitch(LLVMBuilderRef, LLVMValueRef V,
603 LLVMBasicBlockRef Else, unsigned NumCases);
604LLVMValueRef LLVMBuildInvoke(LLVMBuilderRef, LLVMValueRef Fn,
605 LLVMValueRef *Args, unsigned NumArgs,
606 LLVMBasicBlockRef Then, LLVMBasicBlockRef Catch,
607 const char *Name);
608LLVMValueRef LLVMBuildUnwind(LLVMBuilderRef);
609LLVMValueRef LLVMBuildUnreachable(LLVMBuilderRef);
610
Gordon Henriksen097102c2008-01-01 05:50:53 +0000611/* Add a case to the switch instruction */
612void LLVMAddCase(LLVMValueRef Switch, LLVMValueRef OnVal,
613 LLVMBasicBlockRef Dest);
614
Gordon Henriksenc23b66c2007-09-26 20:56:12 +0000615/* Arithmetic */
616LLVMValueRef LLVMBuildAdd(LLVMBuilderRef, LLVMValueRef LHS, LLVMValueRef RHS,
617 const char *Name);
618LLVMValueRef LLVMBuildSub(LLVMBuilderRef, LLVMValueRef LHS, LLVMValueRef RHS,
619 const char *Name);
620LLVMValueRef LLVMBuildMul(LLVMBuilderRef, LLVMValueRef LHS, LLVMValueRef RHS,
621 const char *Name);
622LLVMValueRef LLVMBuildUDiv(LLVMBuilderRef, LLVMValueRef LHS, LLVMValueRef RHS,
623 const char *Name);
624LLVMValueRef LLVMBuildSDiv(LLVMBuilderRef, LLVMValueRef LHS, LLVMValueRef RHS,
625 const char *Name);
626LLVMValueRef LLVMBuildFDiv(LLVMBuilderRef, LLVMValueRef LHS, LLVMValueRef RHS,
627 const char *Name);
628LLVMValueRef LLVMBuildURem(LLVMBuilderRef, LLVMValueRef LHS, LLVMValueRef RHS,
629 const char *Name);
630LLVMValueRef LLVMBuildSRem(LLVMBuilderRef, LLVMValueRef LHS, LLVMValueRef RHS,
631 const char *Name);
632LLVMValueRef LLVMBuildFRem(LLVMBuilderRef, LLVMValueRef LHS, LLVMValueRef RHS,
633 const char *Name);
634LLVMValueRef LLVMBuildShl(LLVMBuilderRef, LLVMValueRef LHS, LLVMValueRef RHS,
635 const char *Name);
636LLVMValueRef LLVMBuildLShr(LLVMBuilderRef, LLVMValueRef LHS, LLVMValueRef RHS,
637 const char *Name);
638LLVMValueRef LLVMBuildAShr(LLVMBuilderRef, LLVMValueRef LHS, LLVMValueRef RHS,
639 const char *Name);
640LLVMValueRef LLVMBuildAnd(LLVMBuilderRef, LLVMValueRef LHS, LLVMValueRef RHS,
641 const char *Name);
642LLVMValueRef LLVMBuildOr(LLVMBuilderRef, LLVMValueRef LHS, LLVMValueRef RHS,
643 const char *Name);
644LLVMValueRef LLVMBuildXor(LLVMBuilderRef, LLVMValueRef LHS, LLVMValueRef RHS,
645 const char *Name);
646LLVMValueRef LLVMBuildNeg(LLVMBuilderRef, LLVMValueRef V, const char *Name);
647LLVMValueRef LLVMBuildNot(LLVMBuilderRef, LLVMValueRef V, const char *Name);
648
649/* Memory */
650LLVMValueRef LLVMBuildMalloc(LLVMBuilderRef, LLVMTypeRef Ty, const char *Name);
651LLVMValueRef LLVMBuildArrayMalloc(LLVMBuilderRef, LLVMTypeRef Ty,
652 LLVMValueRef Val, const char *Name);
653LLVMValueRef LLVMBuildAlloca(LLVMBuilderRef, LLVMTypeRef Ty, const char *Name);
654LLVMValueRef LLVMBuildArrayAlloca(LLVMBuilderRef, LLVMTypeRef Ty,
655 LLVMValueRef Val, const char *Name);
656LLVMValueRef LLVMBuildFree(LLVMBuilderRef, LLVMValueRef PointerVal);
657LLVMValueRef LLVMBuildLoad(LLVMBuilderRef, LLVMValueRef PointerVal,
658 const char *Name);
659LLVMValueRef LLVMBuildStore(LLVMBuilderRef, LLVMValueRef Val, LLVMValueRef Ptr);
660LLVMValueRef LLVMBuildGEP(LLVMBuilderRef B, LLVMValueRef Pointer,
661 LLVMValueRef *Indices, unsigned NumIndices,
662 const char *Name);
663
664/* Casts */
665LLVMValueRef LLVMBuildTrunc(LLVMBuilderRef, LLVMValueRef Val,
666 LLVMTypeRef DestTy, const char *Name);
667LLVMValueRef LLVMBuildZExt(LLVMBuilderRef, LLVMValueRef Val,
668 LLVMTypeRef DestTy, const char *Name);
669LLVMValueRef LLVMBuildSExt(LLVMBuilderRef, LLVMValueRef Val,
670 LLVMTypeRef DestTy, const char *Name);
671LLVMValueRef LLVMBuildFPToUI(LLVMBuilderRef, LLVMValueRef Val,
672 LLVMTypeRef DestTy, const char *Name);
673LLVMValueRef LLVMBuildFPToSI(LLVMBuilderRef, LLVMValueRef Val,
674 LLVMTypeRef DestTy, const char *Name);
675LLVMValueRef LLVMBuildUIToFP(LLVMBuilderRef, LLVMValueRef Val,
676 LLVMTypeRef DestTy, const char *Name);
677LLVMValueRef LLVMBuildSIToFP(LLVMBuilderRef, LLVMValueRef Val,
678 LLVMTypeRef DestTy, const char *Name);
679LLVMValueRef LLVMBuildFPTrunc(LLVMBuilderRef, LLVMValueRef Val,
680 LLVMTypeRef DestTy, const char *Name);
681LLVMValueRef LLVMBuildFPExt(LLVMBuilderRef, LLVMValueRef Val,
682 LLVMTypeRef DestTy, const char *Name);
683LLVMValueRef LLVMBuildPtrToInt(LLVMBuilderRef, LLVMValueRef Val,
684 LLVMTypeRef DestTy, const char *Name);
685LLVMValueRef LLVMBuildIntToPtr(LLVMBuilderRef, LLVMValueRef Val,
686 LLVMTypeRef DestTy, const char *Name);
687LLVMValueRef LLVMBuildBitCast(LLVMBuilderRef, LLVMValueRef Val,
688 LLVMTypeRef DestTy, const char *Name);
689
690/* Comparisons */
691LLVMValueRef LLVMBuildICmp(LLVMBuilderRef, LLVMIntPredicate Op,
692 LLVMValueRef LHS, LLVMValueRef RHS,
693 const char *Name);
694LLVMValueRef LLVMBuildFCmp(LLVMBuilderRef, LLVMRealPredicate Op,
695 LLVMValueRef LHS, LLVMValueRef RHS,
696 const char *Name);
697
698/* Miscellaneous instructions */
699LLVMValueRef LLVMBuildPhi(LLVMBuilderRef, LLVMTypeRef Ty, const char *Name);
700LLVMValueRef LLVMBuildCall(LLVMBuilderRef, LLVMValueRef Fn,
701 LLVMValueRef *Args, unsigned NumArgs,
702 const char *Name);
703LLVMValueRef LLVMBuildSelect(LLVMBuilderRef, LLVMValueRef If,
704 LLVMValueRef Then, LLVMValueRef Else,
705 const char *Name);
706LLVMValueRef LLVMBuildVAArg(LLVMBuilderRef, LLVMValueRef List, LLVMTypeRef Ty,
707 const char *Name);
708LLVMValueRef LLVMBuildExtractElement(LLVMBuilderRef, LLVMValueRef VecVal,
709 LLVMValueRef Index, const char *Name);
710LLVMValueRef LLVMBuildInsertElement(LLVMBuilderRef, LLVMValueRef VecVal,
711 LLVMValueRef EltVal, LLVMValueRef Index,
712 const char *Name);
713LLVMValueRef LLVMBuildShuffleVector(LLVMBuilderRef, LLVMValueRef V1,
714 LLVMValueRef V2, LLVMValueRef Mask,
715 const char *Name);
Dan Gohmand5104a52008-11-03 22:55:43 +0000716LLVMValueRef LLVMBuildExtractValue(LLVMBuilderRef, LLVMValueRef AggVal,
717 unsigned Index, const char *Name);
718LLVMValueRef LLVMBuildInsertValue(LLVMBuilderRef, LLVMValueRef AggVal,
719 LLVMValueRef EltVal, unsigned Index,
720 const char *Name);
Gordon Henriksen76a03742007-09-18 03:18:57 +0000721
Gordon Henriksen34eb6d82007-12-19 22:30:40 +0000722
Gordon Henriksen0a68fe22007-12-12 01:04:30 +0000723/*===-- Module providers --------------------------------------------------===*/
724
725/* Encapsulates the module M in a module provider, taking ownership of the
726 * module.
727 * See the constructor llvm::ExistingModuleProvider::ExistingModuleProvider.
728 */
729LLVMModuleProviderRef
730LLVMCreateModuleProviderForExistingModule(LLVMModuleRef M);
731
732/* Destroys the module provider MP as well as the contained module.
733 * See the destructor llvm::ModuleProvider::~ModuleProvider.
734 */
735void LLVMDisposeModuleProvider(LLVMModuleProviderRef MP);
736
Gordon Henriksen34eb6d82007-12-19 22:30:40 +0000737
738/*===-- Memory buffers ----------------------------------------------------===*/
739
740int LLVMCreateMemoryBufferWithContentsOfFile(const char *Path,
741 LLVMMemoryBufferRef *OutMemBuf,
742 char **OutMessage);
743int LLVMCreateMemoryBufferWithSTDIN(LLVMMemoryBufferRef *OutMemBuf,
744 char **OutMessage);
745void LLVMDisposeMemoryBuffer(LLVMMemoryBufferRef MemBuf);
746
Gordon Henriksen878114b2008-03-16 04:20:44 +0000747
748/*===-- Pass Managers -----------------------------------------------------===*/
749
750/** Constructs a new whole-module pass pipeline. This type of pipeline is
751 suitable for link-time optimization and whole-module transformations.
752 See llvm::PassManager::PassManager. */
Gordon Henriksena735a9c2008-05-04 12:55:34 +0000753LLVMPassManagerRef LLVMCreatePassManager(void);
Gordon Henriksen878114b2008-03-16 04:20:44 +0000754
755/** Constructs a new function-by-function pass pipeline over the module
756 provider. It does not take ownership of the module provider. This type of
757 pipeline is suitable for code generation and JIT compilation tasks.
758 See llvm::FunctionPassManager::FunctionPassManager. */
759LLVMPassManagerRef LLVMCreateFunctionPassManager(LLVMModuleProviderRef MP);
760
761/** Initializes, executes on the provided module, and finalizes all of the
762 passes scheduled in the pass manager. Returns 1 if any of the passes
763 modified the module, 0 otherwise. See llvm::PassManager::run(Module&). */
764int LLVMRunPassManager(LLVMPassManagerRef PM, LLVMModuleRef M);
765
766/** Initializes all of the function passes scheduled in the function pass
767 manager. Returns 1 if any of the passes modified the module, 0 otherwise.
768 See llvm::FunctionPassManager::doInitialization. */
769int LLVMInitializeFunctionPassManager(LLVMPassManagerRef FPM);
770
771/** Executes all of the function passes scheduled in the function pass manager
772 on the provided function. Returns 1 if any of the passes modified the
773 function, false otherwise.
774 See llvm::FunctionPassManager::run(Function&). */
775int LLVMRunFunctionPassManager(LLVMPassManagerRef FPM, LLVMValueRef F);
776
777/** Finalizes all of the function passes scheduled in in the function pass
778 manager. Returns 1 if any of the passes modified the module, 0 otherwise.
779 See llvm::FunctionPassManager::doFinalization. */
780int LLVMFinalizeFunctionPassManager(LLVMPassManagerRef FPM);
781
782/** Frees the memory of a pass pipeline. For function pipelines, does not free
783 the module provider.
784 See llvm::PassManagerBase::~PassManagerBase. */
785void LLVMDisposePassManager(LLVMPassManagerRef PM);
786
787
Gordon Henriksen76a03742007-09-18 03:18:57 +0000788#ifdef __cplusplus
789}
Gordon Henriksen76a03742007-09-18 03:18:57 +0000790
Gordon Henriksen7330acd2007-10-05 23:59:36 +0000791namespace llvm {
Gordon Henriksen0a68fe22007-12-12 01:04:30 +0000792 class ModuleProvider;
Gordon Henriksen34eb6d82007-12-19 22:30:40 +0000793 class MemoryBuffer;
Gordon Henriksen96571492008-03-16 15:55:43 +0000794 class PassManagerBase;
Gordon Henriksen0a68fe22007-12-12 01:04:30 +0000795
Gordon Henriksen34eb6d82007-12-19 22:30:40 +0000796 #define DEFINE_SIMPLE_CONVERSION_FUNCTIONS(ty, ref) \
797 inline ty *unwrap(ref P) { \
798 return reinterpret_cast<ty*>(P); \
799 } \
800 \
801 inline ref wrap(const ty *P) { \
802 return reinterpret_cast<ref>(const_cast<ty*>(P)); \
803 }
Gordon Henriksen7330acd2007-10-05 23:59:36 +0000804
Gordon Henriksen878114b2008-03-16 04:20:44 +0000805 #define DEFINE_ISA_CONVERSION_FUNCTIONS(ty, ref) \
806 DEFINE_SIMPLE_CONVERSION_FUNCTIONS(ty, ref) \
807 \
808 template<typename T> \
809 inline T *unwrap(ref P) { \
810 return cast<T>(unwrap(P)); \
811 }
812
813 #define DEFINE_STDCXX_CONVERSION_FUNCTIONS(ty, ref) \
814 DEFINE_SIMPLE_CONVERSION_FUNCTIONS(ty, ref) \
815 \
816 template<typename T> \
817 inline T *unwrap(ref P) { \
818 T *Q = dynamic_cast<T*>(unwrap(P)); \
819 assert(Q && "Invalid cast!"); \
820 return Q; \
821 }
822
823 DEFINE_ISA_CONVERSION_FUNCTIONS (Type, LLVMTypeRef )
824 DEFINE_ISA_CONVERSION_FUNCTIONS (Value, LLVMValueRef )
Gordon Henriksen823f9732007-12-27 18:25:59 +0000825 DEFINE_SIMPLE_CONVERSION_FUNCTIONS(Module, LLVMModuleRef )
826 DEFINE_SIMPLE_CONVERSION_FUNCTIONS(BasicBlock, LLVMBasicBlockRef )
Eric Christopher59278832008-08-08 19:39:37 +0000827 DEFINE_SIMPLE_CONVERSION_FUNCTIONS(IRBuilder<>, LLVMBuilderRef )
Gordon Henriksen823f9732007-12-27 18:25:59 +0000828 DEFINE_SIMPLE_CONVERSION_FUNCTIONS(PATypeHolder, LLVMTypeHandleRef )
829 DEFINE_SIMPLE_CONVERSION_FUNCTIONS(ModuleProvider, LLVMModuleProviderRef)
830 DEFINE_SIMPLE_CONVERSION_FUNCTIONS(MemoryBuffer, LLVMMemoryBufferRef )
Owen Anderson6773d382009-07-01 16:58:40 +0000831 DEFINE_SIMPLE_CONVERSION_FUNCTIONS(LLVMContext, LLVMContextRef )
Gordon Henriksen878114b2008-03-16 04:20:44 +0000832 DEFINE_STDCXX_CONVERSION_FUNCTIONS(PassManagerBase, LLVMPassManagerRef )
Gordon Henriksen7330acd2007-10-05 23:59:36 +0000833
Gordon Henriksen878114b2008-03-16 04:20:44 +0000834 #undef DEFINE_STDCXX_CONVERSION_FUNCTIONS
835 #undef DEFINE_ISA_CONVERSION_FUNCTIONS
Gordon Henriksen34eb6d82007-12-19 22:30:40 +0000836 #undef DEFINE_SIMPLE_CONVERSION_FUNCTIONS
Gordon Henriksen7330acd2007-10-05 23:59:36 +0000837
Gordon Henriksen34eb6d82007-12-19 22:30:40 +0000838 /* Specialized opaque type conversions.
839 */
Gordon Henriksen7330acd2007-10-05 23:59:36 +0000840 inline Type **unwrap(LLVMTypeRef* Tys) {
841 return reinterpret_cast<Type**>(Tys);
842 }
843
Gordon Henriksen7330acd2007-10-05 23:59:36 +0000844 inline LLVMTypeRef *wrap(const Type **Tys) {
845 return reinterpret_cast<LLVMTypeRef*>(const_cast<Type**>(Tys));
846 }
847
Gordon Henriksen34eb6d82007-12-19 22:30:40 +0000848 /* Specialized opaque value conversions.
Gordon Henriksen7330acd2007-10-05 23:59:36 +0000849 */
Gordon Henriksen7330acd2007-10-05 23:59:36 +0000850 inline Value **unwrap(LLVMValueRef *Vals) {
851 return reinterpret_cast<Value**>(Vals);
852 }
853
854 template<typename T>
855 inline T **unwrap(LLVMValueRef *Vals, unsigned Length) {
856 #if DEBUG
Chris Lattnerb7971152009-07-10 18:28:19 +0000857 for (LLVMValueRef *I = Vals, *E = Vals + Length; I != E; ++I)
Gordon Henriksen7330acd2007-10-05 23:59:36 +0000858 cast<T>(*I);
859 #endif
860 return reinterpret_cast<T**>(Vals);
861 }
862
Gordon Henriksen7330acd2007-10-05 23:59:36 +0000863 inline LLVMValueRef *wrap(const Value **Vals) {
864 return reinterpret_cast<LLVMValueRef*>(const_cast<Value**>(Vals));
865 }
Gordon Henriksen7330acd2007-10-05 23:59:36 +0000866}
867
868#endif /* !defined(__cplusplus) */
869
870#endif /* !defined(LLVM_C_CORE_H) */