blob: 91b3bdfd74e82e8c914137a918a3116ad080862f [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/**
50 * The top-level container for all other LLVM Intermediate Representation (IR)
51 * objects. See the llvm::Module class.
52 */
Gordon Henriksen76a03742007-09-18 03:18:57 +000053typedef struct LLVMOpaqueModule *LLVMModuleRef;
Gordon Henriksen4a4d7352007-12-30 17:46:33 +000054
55/**
Gordon Henriksena49d4352008-03-07 19:13:06 +000056 * Each value in the LLVM IR has a type, an LLVMTypeRef. See the llvm::Type
57 * class.
Gordon Henriksen4a4d7352007-12-30 17:46:33 +000058 */
Gordon Henriksen76a03742007-09-18 03:18:57 +000059typedef struct LLVMOpaqueType *LLVMTypeRef;
Gordon Henriksen4a4d7352007-12-30 17:46:33 +000060
61/**
Gordon Henriksena49d4352008-03-07 19:13:06 +000062 * When building recursive types using LLVMRefineType, LLVMTypeRef values may
63 * become invalid; use LLVMTypeHandleRef to resolve this problem. See the
64 * llvm::AbstractTypeHolder class.
Gordon Henriksen4a4d7352007-12-30 17:46:33 +000065 */
Gordon Henriksenffb48762007-10-07 00:13:35 +000066typedef struct LLVMOpaqueTypeHandle *LLVMTypeHandleRef;
Gordon Henriksen4a4d7352007-12-30 17:46:33 +000067
Gordon Henriksen76a03742007-09-18 03:18:57 +000068typedef struct LLVMOpaqueValue *LLVMValueRef;
Gordon Henriksenc23b66c2007-09-26 20:56:12 +000069typedef struct LLVMOpaqueBasicBlock *LLVMBasicBlockRef;
70typedef struct LLVMOpaqueBuilder *LLVMBuilderRef;
Gordon Henriksen34eb6d82007-12-19 22:30:40 +000071
72/* Used to provide a module to JIT or interpreter.
73 * See the llvm::ModuleProvider class.
74 */
Gordon Henriksen0a68fe22007-12-12 01:04:30 +000075typedef struct LLVMOpaqueModuleProvider *LLVMModuleProviderRef;
Gordon Henriksen76a03742007-09-18 03:18:57 +000076
Gordon Henriksen34eb6d82007-12-19 22:30:40 +000077/* Used to provide a module to JIT or interpreter.
78 * See the llvm::MemoryBuffer class.
79 */
80typedef struct LLVMOpaqueMemoryBuffer *LLVMMemoryBufferRef;
81
Gordon Henriksen878114b2008-03-16 04:20:44 +000082/** See the llvm::PassManagerBase class. */
83typedef struct LLVMOpaquePassManager *LLVMPassManagerRef;
84
Gordon Henriksen76a03742007-09-18 03:18:57 +000085typedef enum {
Devang Patel4c758ea2008-09-25 21:00:45 +000086 LLVMZExtAttribute = 1<<0,
87 LLVMSExtAttribute = 1<<1,
88 LLVMNoReturnAttribute = 1<<2,
89 LLVMInRegAttribute = 1<<3,
90 LLVMStructRetAttribute = 1<<4,
91 LLVMNoUnwindAttribute = 1<<5,
92 LLVMNoAliasAttribute = 1<<6,
93 LLVMByValAttribute = 1<<7,
94 LLVMNestAttribute = 1<<8,
95 LLVMReadNoneAttribute = 1<<9,
96 LLVMReadOnlyAttribute = 1<<10
97} LLVMAttribute;
Gordon Henriksen2d9cc212008-04-28 17:37:06 +000098
99typedef enum {
Gordon Henriksen4a4d7352007-12-30 17:46:33 +0000100 LLVMVoidTypeKind, /**< type with no size */
101 LLVMFloatTypeKind, /**< 32 bit floating point type */
102 LLVMDoubleTypeKind, /**< 64 bit floating point type */
103 LLVMX86_FP80TypeKind, /**< 80 bit floating point type (X87) */
104 LLVMFP128TypeKind, /**< 128 bit floating point type (112-bit mantissa)*/
105 LLVMPPC_FP128TypeKind, /**< 128 bit floating point type (two 64-bits) */
106 LLVMLabelTypeKind, /**< Labels */
107 LLVMIntegerTypeKind, /**< Arbitrary bit width integers */
108 LLVMFunctionTypeKind, /**< Functions */
109 LLVMStructTypeKind, /**< Structures */
110 LLVMArrayTypeKind, /**< Arrays */
111 LLVMPointerTypeKind, /**< Pointers */
112 LLVMOpaqueTypeKind, /**< Opaque: type with unknown structure */
113 LLVMVectorTypeKind /**< SIMD 'packed' format, or other vector type */
Gordon Henriksen76a03742007-09-18 03:18:57 +0000114} LLVMTypeKind;
115
116typedef enum {
Gordon Henriksen4a4d7352007-12-30 17:46:33 +0000117 LLVMExternalLinkage, /**< Externally visible function */
Duncan Sands12da8ce2009-03-07 15:45:40 +0000118 LLVMLinkOnceAnyLinkage, /**< Keep one copy of function when linking (inline)*/
119 LLVMLinkOnceODRLinkage, /**< Same, but only replaced by something
120 equivalent. */
121 LLVMWeakAnyLinkage, /**< Keep one copy of function when linking (weak) */
122 LLVMWeakODRLinkage, /**< Same, but only replaced by something
123 equivalent. */
Gordon Henriksen4a4d7352007-12-30 17:46:33 +0000124 LLVMAppendingLinkage, /**< Special purpose, only applies to global arrays */
125 LLVMInternalLinkage, /**< Rename collisions when linking (static
126 functions) */
Duncan Sands12da8ce2009-03-07 15:45:40 +0000127 LLVMPrivateLinkage, /**< Like Internal, but omit from symbol table */
Gordon Henriksen4a4d7352007-12-30 17:46:33 +0000128 LLVMDLLImportLinkage, /**< Function to be imported from DLL */
129 LLVMDLLExportLinkage, /**< Function to be accessible from DLL */
Duncan Sandse2881052009-03-11 08:08:06 +0000130 LLVMExternalWeakLinkage,/**< ExternalWeak linkage description */
Duncan Sands12da8ce2009-03-07 15:45:40 +0000131 LLVMGhostLinkage, /**< Stand-in functions for streaming fns from
Gordon Henriksen4a4d7352007-12-30 17:46:33 +0000132 bitcode */
Duncan Sands4581beb2009-03-11 20:14:15 +0000133 LLVMCommonLinkage /**< Tentative definitions */
Gordon Henriksen76a03742007-09-18 03:18:57 +0000134} LLVMLinkage;
135
136typedef enum {
Gordon Henriksen4a4d7352007-12-30 17:46:33 +0000137 LLVMDefaultVisibility, /**< The GV is visible */
138 LLVMHiddenVisibility, /**< The GV is hidden */
139 LLVMProtectedVisibility /**< The GV is protected */
Gordon Henriksen76a03742007-09-18 03:18:57 +0000140} LLVMVisibility;
141
Gordon Henriksenc23b66c2007-09-26 20:56:12 +0000142typedef enum {
143 LLVMCCallConv = 0,
144 LLVMFastCallConv = 8,
145 LLVMColdCallConv = 9,
146 LLVMX86StdcallCallConv = 64,
147 LLVMX86FastcallCallConv = 65
148} LLVMCallConv;
149
150typedef enum {
Gordon Henriksen4a4d7352007-12-30 17:46:33 +0000151 LLVMIntEQ = 32, /**< equal */
152 LLVMIntNE, /**< not equal */
153 LLVMIntUGT, /**< unsigned greater than */
154 LLVMIntUGE, /**< unsigned greater or equal */
155 LLVMIntULT, /**< unsigned less than */
156 LLVMIntULE, /**< unsigned less or equal */
157 LLVMIntSGT, /**< signed greater than */
158 LLVMIntSGE, /**< signed greater or equal */
159 LLVMIntSLT, /**< signed less than */
160 LLVMIntSLE /**< signed less or equal */
Gordon Henriksenc23b66c2007-09-26 20:56:12 +0000161} LLVMIntPredicate;
162
163typedef enum {
Gordon Henriksen4a4d7352007-12-30 17:46:33 +0000164 LLVMRealPredicateFalse, /**< Always false (always folded) */
165 LLVMRealOEQ, /**< True if ordered and equal */
166 LLVMRealOGT, /**< True if ordered and greater than */
167 LLVMRealOGE, /**< True if ordered and greater than or equal */
168 LLVMRealOLT, /**< True if ordered and less than */
169 LLVMRealOLE, /**< True if ordered and less than or equal */
170 LLVMRealONE, /**< True if ordered and operands are unequal */
171 LLVMRealORD, /**< True if ordered (no nans) */
172 LLVMRealUNO, /**< True if unordered: isnan(X) | isnan(Y) */
173 LLVMRealUEQ, /**< True if unordered or equal */
174 LLVMRealUGT, /**< True if unordered or greater than */
175 LLVMRealUGE, /**< True if unordered, greater than, or equal */
176 LLVMRealULT, /**< True if unordered or less than */
177 LLVMRealULE, /**< True if unordered, less than, or equal */
178 LLVMRealUNE, /**< True if unordered or not equal */
179 LLVMRealPredicateTrue /**< Always true (always folded) */
Gordon Henriksenc23b66c2007-09-26 20:56:12 +0000180} LLVMRealPredicate;
181
Gordon Henriksen76a03742007-09-18 03:18:57 +0000182
Gordon Henriksen34eb6d82007-12-19 22:30:40 +0000183/*===-- Error handling ----------------------------------------------------===*/
184
185void LLVMDisposeMessage(char *Message);
186
187
Gordon Henriksen76a03742007-09-18 03:18:57 +0000188/*===-- Modules -----------------------------------------------------------===*/
189
190/* Create and destroy modules. */
Gordon Henriksena49d4352008-03-07 19:13:06 +0000191/** See llvm::Module::Module. */
Gordon Henriksen76a03742007-09-18 03:18:57 +0000192LLVMModuleRef LLVMModuleCreateWithName(const char *ModuleID);
Gordon Henriksena49d4352008-03-07 19:13:06 +0000193
194/** See llvm::Module::~Module. */
Gordon Henriksen76a03742007-09-18 03:18:57 +0000195void LLVMDisposeModule(LLVMModuleRef M);
196
Gordon Henriksena49d4352008-03-07 19:13:06 +0000197/** Data layout. See Module::getDataLayout. */
Gordon Henriksen05568bb2007-12-27 20:13:47 +0000198const char *LLVMGetDataLayout(LLVMModuleRef M);
199void LLVMSetDataLayout(LLVMModuleRef M, const char *Triple);
200
Gordon Henriksena49d4352008-03-07 19:13:06 +0000201/** Target triple. See Module::getTargetTriple. */
Gordon Henriksen05568bb2007-12-27 20:13:47 +0000202const char *LLVMGetTarget(LLVMModuleRef M);
203void LLVMSetTarget(LLVMModuleRef M, const char *Triple);
204
Gordon Henriksena49d4352008-03-07 19:13:06 +0000205/** See Module::addTypeName. */
Gordon Henriksen76a03742007-09-18 03:18:57 +0000206int LLVMAddTypeName(LLVMModuleRef M, const char *Name, LLVMTypeRef Ty);
Gordon Henriksenc23b66c2007-09-26 20:56:12 +0000207void LLVMDeleteTypeName(LLVMModuleRef M, const char *Name);
Gordon Henriksen76a03742007-09-18 03:18:57 +0000208
Gordon Henriksen6c6075e2008-03-14 23:58:56 +0000209/** See Module::dump. */
210void LLVMDumpModule(LLVMModuleRef M);
211
Gordon Henriksen76a03742007-09-18 03:18:57 +0000212
Gordon Henriksenc23b66c2007-09-26 20:56:12 +0000213/*===-- Types -------------------------------------------------------------===*/
Gordon Henriksen76a03742007-09-18 03:18:57 +0000214
215/* LLVM types conform to the following hierarchy:
216 *
217 * types:
218 * integer type
219 * real type
220 * function type
221 * sequence types:
222 * array type
223 * pointer type
224 * vector type
225 * void type
226 * label type
227 * opaque type
228 */
229
Gordon Henriksena49d4352008-03-07 19:13:06 +0000230/** See llvm::LLVMTypeKind::getTypeID. */
Gordon Henriksen76a03742007-09-18 03:18:57 +0000231LLVMTypeKind LLVMGetTypeKind(LLVMTypeRef Ty);
Gordon Henriksena49d4352008-03-07 19:13:06 +0000232
Gordon Henriksen76a03742007-09-18 03:18:57 +0000233/* Operations on integer types */
Gordon Henriksena735a9c2008-05-04 12:55:34 +0000234LLVMTypeRef LLVMInt1Type(void);
235LLVMTypeRef LLVMInt8Type(void);
236LLVMTypeRef LLVMInt16Type(void);
237LLVMTypeRef LLVMInt32Type(void);
238LLVMTypeRef LLVMInt64Type(void);
Gordon Henriksened7beaa2007-10-06 16:05:20 +0000239LLVMTypeRef LLVMIntType(unsigned NumBits);
Gordon Henriksenc23b66c2007-09-26 20:56:12 +0000240unsigned LLVMGetIntTypeWidth(LLVMTypeRef IntegerTy);
Gordon Henriksen76a03742007-09-18 03:18:57 +0000241
242/* Operations on real types */
Gordon Henriksena735a9c2008-05-04 12:55:34 +0000243LLVMTypeRef LLVMFloatType(void);
244LLVMTypeRef LLVMDoubleType(void);
245LLVMTypeRef LLVMX86FP80Type(void);
246LLVMTypeRef LLVMFP128Type(void);
247LLVMTypeRef LLVMPPCFP128Type(void);
Gordon Henriksen76a03742007-09-18 03:18:57 +0000248
249/* Operations on function types */
Gordon Henriksened7beaa2007-10-06 16:05:20 +0000250LLVMTypeRef LLVMFunctionType(LLVMTypeRef ReturnType,
251 LLVMTypeRef *ParamTypes, unsigned ParamCount,
252 int IsVarArg);
Gordon Henriksen76a03742007-09-18 03:18:57 +0000253int LLVMIsFunctionVarArg(LLVMTypeRef FunctionTy);
Gordon Henriksenc23b66c2007-09-26 20:56:12 +0000254LLVMTypeRef LLVMGetReturnType(LLVMTypeRef FunctionTy);
255unsigned LLVMCountParamTypes(LLVMTypeRef FunctionTy);
256void LLVMGetParamTypes(LLVMTypeRef FunctionTy, LLVMTypeRef *Dest);
Gordon Henriksen76a03742007-09-18 03:18:57 +0000257
258/* Operations on struct types */
Gordon Henriksened7beaa2007-10-06 16:05:20 +0000259LLVMTypeRef LLVMStructType(LLVMTypeRef *ElementTypes, unsigned ElementCount,
260 int Packed);
Gordon Henriksenc23b66c2007-09-26 20:56:12 +0000261unsigned LLVMCountStructElementTypes(LLVMTypeRef StructTy);
Gordon Henriksen76a03742007-09-18 03:18:57 +0000262void LLVMGetStructElementTypes(LLVMTypeRef StructTy, LLVMTypeRef *Dest);
263int LLVMIsPackedStruct(LLVMTypeRef StructTy);
264
265/* Operations on array, pointer, and vector types (sequence types) */
Gordon Henriksened7beaa2007-10-06 16:05:20 +0000266LLVMTypeRef LLVMArrayType(LLVMTypeRef ElementType, unsigned ElementCount);
Gordon Henriksen5a3fe032007-12-17 16:08:32 +0000267LLVMTypeRef LLVMPointerType(LLVMTypeRef ElementType, unsigned AddressSpace);
Gordon Henriksened7beaa2007-10-06 16:05:20 +0000268LLVMTypeRef LLVMVectorType(LLVMTypeRef ElementType, unsigned ElementCount);
Gordon Henriksen76a03742007-09-18 03:18:57 +0000269
270LLVMTypeRef LLVMGetElementType(LLVMTypeRef Ty);
271unsigned LLVMGetArrayLength(LLVMTypeRef ArrayTy);
Gordon Henriksen5a3fe032007-12-17 16:08:32 +0000272unsigned LLVMGetPointerAddressSpace(LLVMTypeRef PointerTy);
Gordon Henriksen76a03742007-09-18 03:18:57 +0000273unsigned LLVMGetVectorSize(LLVMTypeRef VectorTy);
274
275/* Operations on other types */
Gordon Henriksena735a9c2008-05-04 12:55:34 +0000276LLVMTypeRef LLVMVoidType(void);
277LLVMTypeRef LLVMLabelType(void);
278LLVMTypeRef LLVMOpaqueType(void);
Gordon Henriksen76a03742007-09-18 03:18:57 +0000279
Gordon Henriksenffb48762007-10-07 00:13:35 +0000280/* Operations on type handles */
281LLVMTypeHandleRef LLVMCreateTypeHandle(LLVMTypeRef PotentiallyAbstractTy);
282void LLVMRefineType(LLVMTypeRef AbstractTy, LLVMTypeRef ConcreteTy);
283LLVMTypeRef LLVMResolveTypeHandle(LLVMTypeHandleRef TypeHandle);
284void LLVMDisposeTypeHandle(LLVMTypeHandleRef TypeHandle);
285
Gordon Henriksen76a03742007-09-18 03:18:57 +0000286
287/*===-- Values ------------------------------------------------------------===*/
288
289/* The bulk of LLVM's object model consists of values, which comprise a very
290 * rich type hierarchy.
Gordon Henriksen76a03742007-09-18 03:18:57 +0000291 */
292
Gordon Henriksen29e38942008-12-19 18:39:45 +0000293#define LLVM_FOR_EACH_VALUE_SUBCLASS(macro) \
294 macro(Argument) \
295 macro(BasicBlock) \
296 macro(InlineAsm) \
297 macro(User) \
298 macro(Constant) \
299 macro(ConstantAggregateZero) \
300 macro(ConstantArray) \
301 macro(ConstantExpr) \
302 macro(ConstantFP) \
303 macro(ConstantInt) \
304 macro(ConstantPointerNull) \
305 macro(ConstantStruct) \
306 macro(ConstantVector) \
307 macro(GlobalValue) \
308 macro(Function) \
309 macro(GlobalAlias) \
310 macro(GlobalVariable) \
311 macro(UndefValue) \
312 macro(Instruction) \
313 macro(BinaryOperator) \
314 macro(CallInst) \
315 macro(IntrinsicInst) \
316 macro(DbgInfoIntrinsic) \
317 macro(DbgDeclareInst) \
318 macro(DbgFuncStartInst) \
319 macro(DbgRegionEndInst) \
320 macro(DbgRegionStartInst) \
321 macro(DbgStopPointInst) \
322 macro(EHSelectorInst) \
323 macro(MemIntrinsic) \
324 macro(MemCpyInst) \
325 macro(MemMoveInst) \
326 macro(MemSetInst) \
327 macro(CmpInst) \
328 macro(FCmpInst) \
329 macro(ICmpInst) \
330 macro(VFCmpInst) \
331 macro(VICmpInst) \
332 macro(ExtractElementInst) \
333 macro(GetElementPtrInst) \
334 macro(InsertElementInst) \
335 macro(InsertValueInst) \
336 macro(PHINode) \
337 macro(SelectInst) \
338 macro(ShuffleVectorInst) \
339 macro(StoreInst) \
340 macro(TerminatorInst) \
341 macro(BranchInst) \
342 macro(InvokeInst) \
343 macro(ReturnInst) \
344 macro(SwitchInst) \
345 macro(UnreachableInst) \
346 macro(UnwindInst) \
347 macro(UnaryInstruction) \
348 macro(AllocationInst) \
Gordon Henriksen05a868f2008-12-19 18:51:17 +0000349 macro(AllocaInst) \
350 macro(MallocInst) \
Gordon Henriksen29e38942008-12-19 18:39:45 +0000351 macro(CastInst) \
Gordon Henriksen05a868f2008-12-19 18:51:17 +0000352 macro(BitCastInst) \
353 macro(FPExtInst) \
354 macro(FPToSIInst) \
355 macro(FPToUIInst) \
356 macro(FPTruncInst) \
357 macro(IntToPtrInst) \
358 macro(PtrToIntInst) \
359 macro(SExtInst) \
360 macro(SIToFPInst) \
361 macro(TruncInst) \
362 macro(UIToFPInst) \
363 macro(ZExtInst) \
364 macro(ExtractValueInst) \
365 macro(FreeInst) \
366 macro(LoadInst) \
367 macro(VAArgInst)
Gordon Henriksen29e38942008-12-19 18:39:45 +0000368
Gordon Henriksen76a03742007-09-18 03:18:57 +0000369/* Operations on all values */
Gordon Henriksenc23b66c2007-09-26 20:56:12 +0000370LLVMTypeRef LLVMTypeOf(LLVMValueRef Val);
Gordon Henriksen76a03742007-09-18 03:18:57 +0000371const char *LLVMGetValueName(LLVMValueRef Val);
372void LLVMSetValueName(LLVMValueRef Val, const char *Name);
Gordon Henriksen1d0d24c2007-10-06 00:08:49 +0000373void LLVMDumpValue(LLVMValueRef Val);
Gordon Henriksen76a03742007-09-18 03:18:57 +0000374
Gordon Henriksen29e38942008-12-19 18:39:45 +0000375/* Conversion functions. Return the input value if it is an instance of the
376 specified class, otherwise NULL. See llvm::dyn_cast_or_null<>. */
377#define LLVM_DECLARE_VALUE_CAST(name) \
378 LLVMValueRef LLVMIsA##name(LLVMValueRef Val);
379LLVM_FOR_EACH_VALUE_SUBCLASS(LLVM_DECLARE_VALUE_CAST)
380
Gordon Henriksen76a03742007-09-18 03:18:57 +0000381/* Operations on constants of any type */
Gordon Henriksen1046c732007-10-06 15:11:06 +0000382LLVMValueRef LLVMConstNull(LLVMTypeRef Ty); /* all zeroes */
383LLVMValueRef LLVMConstAllOnes(LLVMTypeRef Ty); /* only for int/vector */
Gordon Henriksen76a03742007-09-18 03:18:57 +0000384LLVMValueRef LLVMGetUndef(LLVMTypeRef Ty);
Gordon Henriksendc88c062007-09-18 18:07:51 +0000385int LLVMIsConstant(LLVMValueRef Val);
Gordon Henriksen76a03742007-09-18 03:18:57 +0000386int LLVMIsNull(LLVMValueRef Val);
Gordon Henriksendc88c062007-09-18 18:07:51 +0000387int LLVMIsUndef(LLVMValueRef Val);
Gordon Henriksen76a03742007-09-18 03:18:57 +0000388
389/* Operations on scalar constants */
Gordon Henriksen1046c732007-10-06 15:11:06 +0000390LLVMValueRef LLVMConstInt(LLVMTypeRef IntTy, unsigned long long N,
391 int SignExtend);
392LLVMValueRef LLVMConstReal(LLVMTypeRef RealTy, double N);
Gordon Henriksen931e1212008-02-02 01:07:50 +0000393LLVMValueRef LLVMConstRealOfString(LLVMTypeRef RealTy, const char *Text);
Gordon Henriksen76a03742007-09-18 03:18:57 +0000394
395/* Operations on composite constants */
Gordon Henriksen1046c732007-10-06 15:11:06 +0000396LLVMValueRef LLVMConstString(const char *Str, unsigned Length,
397 int DontNullTerminate);
Gordon Henriksen2ad5aef2008-04-25 03:21:19 +0000398LLVMValueRef LLVMConstArray(LLVMTypeRef ElementTy,
Gordon Henriksen1046c732007-10-06 15:11:06 +0000399 LLVMValueRef *ConstantVals, unsigned Length);
400LLVMValueRef LLVMConstStruct(LLVMValueRef *ConstantVals, unsigned Count,
401 int packed);
402LLVMValueRef LLVMConstVector(LLVMValueRef *ScalarConstantVals, unsigned Size);
Gordon Henriksen76a03742007-09-18 03:18:57 +0000403
Gordon Henriksen7ce31762007-10-06 14:29:36 +0000404/* Constant expressions */
405LLVMValueRef LLVMSizeOf(LLVMTypeRef Ty);
406LLVMValueRef LLVMConstNeg(LLVMValueRef ConstantVal);
407LLVMValueRef LLVMConstNot(LLVMValueRef ConstantVal);
408LLVMValueRef LLVMConstAdd(LLVMValueRef LHSConstant, LLVMValueRef RHSConstant);
409LLVMValueRef LLVMConstSub(LLVMValueRef LHSConstant, LLVMValueRef RHSConstant);
410LLVMValueRef LLVMConstMul(LLVMValueRef LHSConstant, LLVMValueRef RHSConstant);
411LLVMValueRef LLVMConstUDiv(LLVMValueRef LHSConstant, LLVMValueRef RHSConstant);
412LLVMValueRef LLVMConstSDiv(LLVMValueRef LHSConstant, LLVMValueRef RHSConstant);
413LLVMValueRef LLVMConstFDiv(LLVMValueRef LHSConstant, LLVMValueRef RHSConstant);
414LLVMValueRef LLVMConstURem(LLVMValueRef LHSConstant, LLVMValueRef RHSConstant);
415LLVMValueRef LLVMConstSRem(LLVMValueRef LHSConstant, LLVMValueRef RHSConstant);
416LLVMValueRef LLVMConstFRem(LLVMValueRef LHSConstant, LLVMValueRef RHSConstant);
417LLVMValueRef LLVMConstAnd(LLVMValueRef LHSConstant, LLVMValueRef RHSConstant);
418LLVMValueRef LLVMConstOr(LLVMValueRef LHSConstant, LLVMValueRef RHSConstant);
419LLVMValueRef LLVMConstXor(LLVMValueRef LHSConstant, LLVMValueRef RHSConstant);
420LLVMValueRef LLVMConstICmp(LLVMIntPredicate Predicate,
421 LLVMValueRef LHSConstant, LLVMValueRef RHSConstant);
422LLVMValueRef LLVMConstFCmp(LLVMRealPredicate Predicate,
423 LLVMValueRef LHSConstant, LLVMValueRef RHSConstant);
424LLVMValueRef LLVMConstShl(LLVMValueRef LHSConstant, LLVMValueRef RHSConstant);
425LLVMValueRef LLVMConstLShr(LLVMValueRef LHSConstant, LLVMValueRef RHSConstant);
426LLVMValueRef LLVMConstAShr(LLVMValueRef LHSConstant, LLVMValueRef RHSConstant);
427LLVMValueRef LLVMConstGEP(LLVMValueRef ConstantVal,
428 LLVMValueRef *ConstantIndices, unsigned NumIndices);
429LLVMValueRef LLVMConstTrunc(LLVMValueRef ConstantVal, LLVMTypeRef ToType);
430LLVMValueRef LLVMConstSExt(LLVMValueRef ConstantVal, LLVMTypeRef ToType);
431LLVMValueRef LLVMConstZExt(LLVMValueRef ConstantVal, LLVMTypeRef ToType);
432LLVMValueRef LLVMConstFPTrunc(LLVMValueRef ConstantVal, LLVMTypeRef ToType);
433LLVMValueRef LLVMConstFPExt(LLVMValueRef ConstantVal, LLVMTypeRef ToType);
434LLVMValueRef LLVMConstUIToFP(LLVMValueRef ConstantVal, LLVMTypeRef ToType);
435LLVMValueRef LLVMConstSIToFP(LLVMValueRef ConstantVal, LLVMTypeRef ToType);
436LLVMValueRef LLVMConstFPToUI(LLVMValueRef ConstantVal, LLVMTypeRef ToType);
437LLVMValueRef LLVMConstFPToSI(LLVMValueRef ConstantVal, LLVMTypeRef ToType);
438LLVMValueRef LLVMConstPtrToInt(LLVMValueRef ConstantVal, LLVMTypeRef ToType);
439LLVMValueRef LLVMConstIntToPtr(LLVMValueRef ConstantVal, LLVMTypeRef ToType);
440LLVMValueRef LLVMConstBitCast(LLVMValueRef ConstantVal, LLVMTypeRef ToType);
441LLVMValueRef LLVMConstSelect(LLVMValueRef ConstantCondition,
442 LLVMValueRef ConstantIfTrue,
443 LLVMValueRef ConstantIfFalse);
444LLVMValueRef LLVMConstExtractElement(LLVMValueRef VectorConstant,
445 LLVMValueRef IndexConstant);
446LLVMValueRef LLVMConstInsertElement(LLVMValueRef VectorConstant,
447 LLVMValueRef ElementValueConstant,
448 LLVMValueRef IndexConstant);
449LLVMValueRef LLVMConstShuffleVector(LLVMValueRef VectorAConstant,
450 LLVMValueRef VectorBConstant,
451 LLVMValueRef MaskConstant);
Dan Gohmand5104a52008-11-03 22:55:43 +0000452LLVMValueRef LLVMConstExtractValue(LLVMValueRef AggConstant, unsigned *IdxList,
453 unsigned NumIdx);
454LLVMValueRef LLVMConstInsertValue(LLVMValueRef AggConstant,
455 LLVMValueRef ElementValueConstant,
456 unsigned *IdxList, unsigned NumIdx);
Chris Lattner3d1f5522008-12-17 21:39:50 +0000457LLVMValueRef LLVMConstInlineAsm(LLVMTypeRef Ty,
458 const char *AsmString, const char *Constraints,
459 int HasSideEffects);
Gordon Henriksen7ce31762007-10-06 14:29:36 +0000460
Gordon Henriksen76a03742007-09-18 03:18:57 +0000461/* Operations on global variables, functions, and aliases (globals) */
Gordon Henriksen265f7802008-03-19 01:11:35 +0000462LLVMModuleRef LLVMGetGlobalParent(LLVMValueRef Global);
Gordon Henriksen76a03742007-09-18 03:18:57 +0000463int LLVMIsDeclaration(LLVMValueRef Global);
464LLVMLinkage LLVMGetLinkage(LLVMValueRef Global);
465void LLVMSetLinkage(LLVMValueRef Global, LLVMLinkage Linkage);
466const char *LLVMGetSection(LLVMValueRef Global);
467void LLVMSetSection(LLVMValueRef Global, const char *Section);
468LLVMVisibility LLVMGetVisibility(LLVMValueRef Global);
469void LLVMSetVisibility(LLVMValueRef Global, LLVMVisibility Viz);
470unsigned LLVMGetAlignment(LLVMValueRef Global);
471void LLVMSetAlignment(LLVMValueRef Global, unsigned Bytes);
472
473/* Operations on global variables */
474LLVMValueRef LLVMAddGlobal(LLVMModuleRef M, LLVMTypeRef Ty, const char *Name);
Gordon Henriksen783f7bb2007-10-08 03:45:09 +0000475LLVMValueRef LLVMGetNamedGlobal(LLVMModuleRef M, const char *Name);
Gordon Henriksen07a45f42008-03-23 22:21:29 +0000476LLVMValueRef LLVMGetFirstGlobal(LLVMModuleRef M);
477LLVMValueRef LLVMGetLastGlobal(LLVMModuleRef M);
478LLVMValueRef LLVMGetNextGlobal(LLVMValueRef GlobalVar);
479LLVMValueRef LLVMGetPreviousGlobal(LLVMValueRef GlobalVar);
Gordon Henriksen76a03742007-09-18 03:18:57 +0000480void LLVMDeleteGlobal(LLVMValueRef GlobalVar);
Gordon Henriksen76a03742007-09-18 03:18:57 +0000481LLVMValueRef LLVMGetInitializer(LLVMValueRef GlobalVar);
482void LLVMSetInitializer(LLVMValueRef GlobalVar, LLVMValueRef ConstantVal);
483int LLVMIsThreadLocal(LLVMValueRef GlobalVar);
484void LLVMSetThreadLocal(LLVMValueRef GlobalVar, int IsThreadLocal);
Gordon Henriksen751ebf72007-10-07 17:31:42 +0000485int LLVMIsGlobalConstant(LLVMValueRef GlobalVar);
486void LLVMSetGlobalConstant(LLVMValueRef GlobalVar, int IsConstant);
Gordon Henriksen76a03742007-09-18 03:18:57 +0000487
Chris Lattner3d1f5522008-12-17 21:39:50 +0000488/* Operations on aliases */
489LLVMValueRef LLVMAddAlias(LLVMModuleRef M, LLVMTypeRef Ty, LLVMValueRef Aliasee,
490 const char *Name);
491
Gordon Henriksenc23b66c2007-09-26 20:56:12 +0000492/* Operations on functions */
493LLVMValueRef LLVMAddFunction(LLVMModuleRef M, const char *Name,
494 LLVMTypeRef FunctionTy);
Gordon Henriksen783f7bb2007-10-08 03:45:09 +0000495LLVMValueRef LLVMGetNamedFunction(LLVMModuleRef M, const char *Name);
Gordon Henriksen054817c2008-03-19 03:47:18 +0000496LLVMValueRef LLVMGetFirstFunction(LLVMModuleRef M);
497LLVMValueRef LLVMGetLastFunction(LLVMModuleRef M);
498LLVMValueRef LLVMGetNextFunction(LLVMValueRef Fn);
499LLVMValueRef LLVMGetPreviousFunction(LLVMValueRef Fn);
Gordon Henriksenc23b66c2007-09-26 20:56:12 +0000500void LLVMDeleteFunction(LLVMValueRef Fn);
Gordon Henriksenc23b66c2007-09-26 20:56:12 +0000501unsigned LLVMGetIntrinsicID(LLVMValueRef Fn);
502unsigned LLVMGetFunctionCallConv(LLVMValueRef Fn);
503void LLVMSetFunctionCallConv(LLVMValueRef Fn, unsigned CC);
Gordon Henriksend930f912008-08-17 18:44:35 +0000504const char *LLVMGetGC(LLVMValueRef Fn);
505void LLVMSetGC(LLVMValueRef Fn, const char *Name);
Gordon Henriksenc23b66c2007-09-26 20:56:12 +0000506
Gordon Henriksen265f7802008-03-19 01:11:35 +0000507/* Operations on parameters */
508unsigned LLVMCountParams(LLVMValueRef Fn);
509void LLVMGetParams(LLVMValueRef Fn, LLVMValueRef *Params);
510LLVMValueRef LLVMGetParam(LLVMValueRef Fn, unsigned Index);
511LLVMValueRef LLVMGetParamParent(LLVMValueRef Inst);
Gordon Henriksen07a45f42008-03-23 22:21:29 +0000512LLVMValueRef LLVMGetFirstParam(LLVMValueRef Fn);
513LLVMValueRef LLVMGetLastParam(LLVMValueRef Fn);
514LLVMValueRef LLVMGetNextParam(LLVMValueRef Arg);
515LLVMValueRef LLVMGetPreviousParam(LLVMValueRef Arg);
Devang Patel4c758ea2008-09-25 21:00:45 +0000516void LLVMAddAttribute(LLVMValueRef Arg, LLVMAttribute PA);
517void LLVMRemoveAttribute(LLVMValueRef Arg, LLVMAttribute PA);
Gordon Henriksen2d9cc212008-04-28 17:37:06 +0000518void LLVMSetParamAlignment(LLVMValueRef Arg, unsigned align);
Gordon Henriksen265f7802008-03-19 01:11:35 +0000519
Gordon Henriksenc23b66c2007-09-26 20:56:12 +0000520/* Operations on basic blocks */
Gordon Henriksen07a45f42008-03-23 22:21:29 +0000521LLVMValueRef LLVMBasicBlockAsValue(LLVMBasicBlockRef BB);
Gordon Henriksenc23b66c2007-09-26 20:56:12 +0000522int LLVMValueIsBasicBlock(LLVMValueRef Val);
523LLVMBasicBlockRef LLVMValueAsBasicBlock(LLVMValueRef Val);
Gordon Henriksen07a45f42008-03-23 22:21:29 +0000524LLVMValueRef LLVMGetBasicBlockParent(LLVMBasicBlockRef BB);
Gordon Henriksenc23b66c2007-09-26 20:56:12 +0000525unsigned LLVMCountBasicBlocks(LLVMValueRef Fn);
526void LLVMGetBasicBlocks(LLVMValueRef Fn, LLVMBasicBlockRef *BasicBlocks);
Gordon Henriksen054817c2008-03-19 03:47:18 +0000527LLVMBasicBlockRef LLVMGetFirstBasicBlock(LLVMValueRef Fn);
528LLVMBasicBlockRef LLVMGetLastBasicBlock(LLVMValueRef Fn);
529LLVMBasicBlockRef LLVMGetNextBasicBlock(LLVMBasicBlockRef BB);
530LLVMBasicBlockRef LLVMGetPreviousBasicBlock(LLVMBasicBlockRef BB);
Gordon Henriksenc23b66c2007-09-26 20:56:12 +0000531LLVMBasicBlockRef LLVMGetEntryBasicBlock(LLVMValueRef Fn);
532LLVMBasicBlockRef LLVMAppendBasicBlock(LLVMValueRef Fn, const char *Name);
533LLVMBasicBlockRef LLVMInsertBasicBlock(LLVMBasicBlockRef InsertBeforeBB,
534 const char *Name);
535void LLVMDeleteBasicBlock(LLVMBasicBlockRef BB);
536
Gordon Henriksen265f7802008-03-19 01:11:35 +0000537/* Operations on instructions */
538LLVMBasicBlockRef LLVMGetInstructionParent(LLVMValueRef Inst);
Gordon Henriksen054817c2008-03-19 03:47:18 +0000539LLVMValueRef LLVMGetFirstInstruction(LLVMBasicBlockRef BB);
540LLVMValueRef LLVMGetLastInstruction(LLVMBasicBlockRef BB);
541LLVMValueRef LLVMGetNextInstruction(LLVMValueRef Inst);
542LLVMValueRef LLVMGetPreviousInstruction(LLVMValueRef Inst);
Gordon Henriksen265f7802008-03-19 01:11:35 +0000543
Gordon Henriksen1158c532007-12-29 20:45:00 +0000544/* Operations on call sites */
545void LLVMSetInstructionCallConv(LLVMValueRef Instr, unsigned CC);
546unsigned LLVMGetInstructionCallConv(LLVMValueRef Instr);
Devang Patel4c758ea2008-09-25 21:00:45 +0000547void LLVMAddInstrAttribute(LLVMValueRef Instr, unsigned index, LLVMAttribute);
548void LLVMRemoveInstrAttribute(LLVMValueRef Instr, unsigned index,
549 LLVMAttribute);
Gordon Henriksen2d9cc212008-04-28 17:37:06 +0000550void LLVMSetInstrParamAlignment(LLVMValueRef Instr, unsigned index,
551 unsigned align);
Gordon Henriksen1158c532007-12-29 20:45:00 +0000552
Gordon Henrikseneeb65372008-08-30 16:34:54 +0000553/* Operations on call instructions (only) */
554int LLVMIsTailCall(LLVMValueRef CallInst);
555void LLVMSetTailCall(LLVMValueRef CallInst, int IsTailCall);
556
Gordon Henriksen44dd8fb2007-10-08 18:14:39 +0000557/* Operations on phi nodes */
558void LLVMAddIncoming(LLVMValueRef PhiNode, LLVMValueRef *IncomingValues,
559 LLVMBasicBlockRef *IncomingBlocks, unsigned Count);
560unsigned LLVMCountIncoming(LLVMValueRef PhiNode);
561LLVMValueRef LLVMGetIncomingValue(LLVMValueRef PhiNode, unsigned Index);
562LLVMBasicBlockRef LLVMGetIncomingBlock(LLVMValueRef PhiNode, unsigned Index);
Gordon Henriksenc23b66c2007-09-26 20:56:12 +0000563
564/*===-- Instruction builders ----------------------------------------------===*/
565
566/* An instruction builder represents a point within a basic block, and is the
567 * exclusive means of building instructions using the C interface.
568 */
569
Gordon Henriksena735a9c2008-05-04 12:55:34 +0000570LLVMBuilderRef LLVMCreateBuilder(void);
Gordon Henriksen054817c2008-03-19 03:47:18 +0000571void LLVMPositionBuilder(LLVMBuilderRef Builder, LLVMBasicBlockRef Block,
572 LLVMValueRef Instr);
Gordon Henriksenc23b66c2007-09-26 20:56:12 +0000573void LLVMPositionBuilderBefore(LLVMBuilderRef Builder, LLVMValueRef Instr);
574void LLVMPositionBuilderAtEnd(LLVMBuilderRef Builder, LLVMBasicBlockRef Block);
Gordon Henriksen265f7802008-03-19 01:11:35 +0000575LLVMBasicBlockRef LLVMGetInsertBlock(LLVMBuilderRef Builder);
Chris Lattner3d1f5522008-12-17 21:39:50 +0000576void LLVMClearInsertionPosition(LLVMBuilderRef Builder);
577void LLVMInsertIntoBuilder(LLVMBuilderRef Builder, LLVMValueRef Instr);
Gordon Henriksenc23b66c2007-09-26 20:56:12 +0000578void LLVMDisposeBuilder(LLVMBuilderRef Builder);
579
580/* Terminators */
581LLVMValueRef LLVMBuildRetVoid(LLVMBuilderRef);
582LLVMValueRef LLVMBuildRet(LLVMBuilderRef, LLVMValueRef V);
583LLVMValueRef LLVMBuildBr(LLVMBuilderRef, LLVMBasicBlockRef Dest);
584LLVMValueRef LLVMBuildCondBr(LLVMBuilderRef, LLVMValueRef If,
585 LLVMBasicBlockRef Then, LLVMBasicBlockRef Else);
586LLVMValueRef LLVMBuildSwitch(LLVMBuilderRef, LLVMValueRef V,
587 LLVMBasicBlockRef Else, unsigned NumCases);
588LLVMValueRef LLVMBuildInvoke(LLVMBuilderRef, LLVMValueRef Fn,
589 LLVMValueRef *Args, unsigned NumArgs,
590 LLVMBasicBlockRef Then, LLVMBasicBlockRef Catch,
591 const char *Name);
592LLVMValueRef LLVMBuildUnwind(LLVMBuilderRef);
593LLVMValueRef LLVMBuildUnreachable(LLVMBuilderRef);
594
Gordon Henriksen097102c2008-01-01 05:50:53 +0000595/* Add a case to the switch instruction */
596void LLVMAddCase(LLVMValueRef Switch, LLVMValueRef OnVal,
597 LLVMBasicBlockRef Dest);
598
Gordon Henriksenc23b66c2007-09-26 20:56:12 +0000599/* Arithmetic */
600LLVMValueRef LLVMBuildAdd(LLVMBuilderRef, LLVMValueRef LHS, LLVMValueRef RHS,
601 const char *Name);
602LLVMValueRef LLVMBuildSub(LLVMBuilderRef, LLVMValueRef LHS, LLVMValueRef RHS,
603 const char *Name);
604LLVMValueRef LLVMBuildMul(LLVMBuilderRef, LLVMValueRef LHS, LLVMValueRef RHS,
605 const char *Name);
606LLVMValueRef LLVMBuildUDiv(LLVMBuilderRef, LLVMValueRef LHS, LLVMValueRef RHS,
607 const char *Name);
608LLVMValueRef LLVMBuildSDiv(LLVMBuilderRef, LLVMValueRef LHS, LLVMValueRef RHS,
609 const char *Name);
610LLVMValueRef LLVMBuildFDiv(LLVMBuilderRef, LLVMValueRef LHS, LLVMValueRef RHS,
611 const char *Name);
612LLVMValueRef LLVMBuildURem(LLVMBuilderRef, LLVMValueRef LHS, LLVMValueRef RHS,
613 const char *Name);
614LLVMValueRef LLVMBuildSRem(LLVMBuilderRef, LLVMValueRef LHS, LLVMValueRef RHS,
615 const char *Name);
616LLVMValueRef LLVMBuildFRem(LLVMBuilderRef, LLVMValueRef LHS, LLVMValueRef RHS,
617 const char *Name);
618LLVMValueRef LLVMBuildShl(LLVMBuilderRef, LLVMValueRef LHS, LLVMValueRef RHS,
619 const char *Name);
620LLVMValueRef LLVMBuildLShr(LLVMBuilderRef, LLVMValueRef LHS, LLVMValueRef RHS,
621 const char *Name);
622LLVMValueRef LLVMBuildAShr(LLVMBuilderRef, LLVMValueRef LHS, LLVMValueRef RHS,
623 const char *Name);
624LLVMValueRef LLVMBuildAnd(LLVMBuilderRef, LLVMValueRef LHS, LLVMValueRef RHS,
625 const char *Name);
626LLVMValueRef LLVMBuildOr(LLVMBuilderRef, LLVMValueRef LHS, LLVMValueRef RHS,
627 const char *Name);
628LLVMValueRef LLVMBuildXor(LLVMBuilderRef, LLVMValueRef LHS, LLVMValueRef RHS,
629 const char *Name);
630LLVMValueRef LLVMBuildNeg(LLVMBuilderRef, LLVMValueRef V, const char *Name);
631LLVMValueRef LLVMBuildNot(LLVMBuilderRef, LLVMValueRef V, const char *Name);
632
633/* Memory */
634LLVMValueRef LLVMBuildMalloc(LLVMBuilderRef, LLVMTypeRef Ty, const char *Name);
635LLVMValueRef LLVMBuildArrayMalloc(LLVMBuilderRef, LLVMTypeRef Ty,
636 LLVMValueRef Val, const char *Name);
637LLVMValueRef LLVMBuildAlloca(LLVMBuilderRef, LLVMTypeRef Ty, const char *Name);
638LLVMValueRef LLVMBuildArrayAlloca(LLVMBuilderRef, LLVMTypeRef Ty,
639 LLVMValueRef Val, const char *Name);
640LLVMValueRef LLVMBuildFree(LLVMBuilderRef, LLVMValueRef PointerVal);
641LLVMValueRef LLVMBuildLoad(LLVMBuilderRef, LLVMValueRef PointerVal,
642 const char *Name);
643LLVMValueRef LLVMBuildStore(LLVMBuilderRef, LLVMValueRef Val, LLVMValueRef Ptr);
644LLVMValueRef LLVMBuildGEP(LLVMBuilderRef B, LLVMValueRef Pointer,
645 LLVMValueRef *Indices, unsigned NumIndices,
646 const char *Name);
647
648/* Casts */
649LLVMValueRef LLVMBuildTrunc(LLVMBuilderRef, LLVMValueRef Val,
650 LLVMTypeRef DestTy, const char *Name);
651LLVMValueRef LLVMBuildZExt(LLVMBuilderRef, LLVMValueRef Val,
652 LLVMTypeRef DestTy, const char *Name);
653LLVMValueRef LLVMBuildSExt(LLVMBuilderRef, LLVMValueRef Val,
654 LLVMTypeRef DestTy, const char *Name);
655LLVMValueRef LLVMBuildFPToUI(LLVMBuilderRef, LLVMValueRef Val,
656 LLVMTypeRef DestTy, const char *Name);
657LLVMValueRef LLVMBuildFPToSI(LLVMBuilderRef, LLVMValueRef Val,
658 LLVMTypeRef DestTy, const char *Name);
659LLVMValueRef LLVMBuildUIToFP(LLVMBuilderRef, LLVMValueRef Val,
660 LLVMTypeRef DestTy, const char *Name);
661LLVMValueRef LLVMBuildSIToFP(LLVMBuilderRef, LLVMValueRef Val,
662 LLVMTypeRef DestTy, const char *Name);
663LLVMValueRef LLVMBuildFPTrunc(LLVMBuilderRef, LLVMValueRef Val,
664 LLVMTypeRef DestTy, const char *Name);
665LLVMValueRef LLVMBuildFPExt(LLVMBuilderRef, LLVMValueRef Val,
666 LLVMTypeRef DestTy, const char *Name);
667LLVMValueRef LLVMBuildPtrToInt(LLVMBuilderRef, LLVMValueRef Val,
668 LLVMTypeRef DestTy, const char *Name);
669LLVMValueRef LLVMBuildIntToPtr(LLVMBuilderRef, LLVMValueRef Val,
670 LLVMTypeRef DestTy, const char *Name);
671LLVMValueRef LLVMBuildBitCast(LLVMBuilderRef, LLVMValueRef Val,
672 LLVMTypeRef DestTy, const char *Name);
673
674/* Comparisons */
675LLVMValueRef LLVMBuildICmp(LLVMBuilderRef, LLVMIntPredicate Op,
676 LLVMValueRef LHS, LLVMValueRef RHS,
677 const char *Name);
678LLVMValueRef LLVMBuildFCmp(LLVMBuilderRef, LLVMRealPredicate Op,
679 LLVMValueRef LHS, LLVMValueRef RHS,
680 const char *Name);
681
682/* Miscellaneous instructions */
683LLVMValueRef LLVMBuildPhi(LLVMBuilderRef, LLVMTypeRef Ty, const char *Name);
684LLVMValueRef LLVMBuildCall(LLVMBuilderRef, LLVMValueRef Fn,
685 LLVMValueRef *Args, unsigned NumArgs,
686 const char *Name);
687LLVMValueRef LLVMBuildSelect(LLVMBuilderRef, LLVMValueRef If,
688 LLVMValueRef Then, LLVMValueRef Else,
689 const char *Name);
690LLVMValueRef LLVMBuildVAArg(LLVMBuilderRef, LLVMValueRef List, LLVMTypeRef Ty,
691 const char *Name);
692LLVMValueRef LLVMBuildExtractElement(LLVMBuilderRef, LLVMValueRef VecVal,
693 LLVMValueRef Index, const char *Name);
694LLVMValueRef LLVMBuildInsertElement(LLVMBuilderRef, LLVMValueRef VecVal,
695 LLVMValueRef EltVal, LLVMValueRef Index,
696 const char *Name);
697LLVMValueRef LLVMBuildShuffleVector(LLVMBuilderRef, LLVMValueRef V1,
698 LLVMValueRef V2, LLVMValueRef Mask,
699 const char *Name);
Dan Gohmand5104a52008-11-03 22:55:43 +0000700LLVMValueRef LLVMBuildExtractValue(LLVMBuilderRef, LLVMValueRef AggVal,
701 unsigned Index, const char *Name);
702LLVMValueRef LLVMBuildInsertValue(LLVMBuilderRef, LLVMValueRef AggVal,
703 LLVMValueRef EltVal, unsigned Index,
704 const char *Name);
Gordon Henriksen76a03742007-09-18 03:18:57 +0000705
Gordon Henriksen34eb6d82007-12-19 22:30:40 +0000706
Gordon Henriksen0a68fe22007-12-12 01:04:30 +0000707/*===-- Module providers --------------------------------------------------===*/
708
709/* Encapsulates the module M in a module provider, taking ownership of the
710 * module.
711 * See the constructor llvm::ExistingModuleProvider::ExistingModuleProvider.
712 */
713LLVMModuleProviderRef
714LLVMCreateModuleProviderForExistingModule(LLVMModuleRef M);
715
716/* Destroys the module provider MP as well as the contained module.
717 * See the destructor llvm::ModuleProvider::~ModuleProvider.
718 */
719void LLVMDisposeModuleProvider(LLVMModuleProviderRef MP);
720
Gordon Henriksen34eb6d82007-12-19 22:30:40 +0000721
722/*===-- Memory buffers ----------------------------------------------------===*/
723
724int LLVMCreateMemoryBufferWithContentsOfFile(const char *Path,
725 LLVMMemoryBufferRef *OutMemBuf,
726 char **OutMessage);
727int LLVMCreateMemoryBufferWithSTDIN(LLVMMemoryBufferRef *OutMemBuf,
728 char **OutMessage);
729void LLVMDisposeMemoryBuffer(LLVMMemoryBufferRef MemBuf);
730
Gordon Henriksen878114b2008-03-16 04:20:44 +0000731
732/*===-- Pass Managers -----------------------------------------------------===*/
733
734/** Constructs a new whole-module pass pipeline. This type of pipeline is
735 suitable for link-time optimization and whole-module transformations.
736 See llvm::PassManager::PassManager. */
Gordon Henriksena735a9c2008-05-04 12:55:34 +0000737LLVMPassManagerRef LLVMCreatePassManager(void);
Gordon Henriksen878114b2008-03-16 04:20:44 +0000738
739/** Constructs a new function-by-function pass pipeline over the module
740 provider. It does not take ownership of the module provider. This type of
741 pipeline is suitable for code generation and JIT compilation tasks.
742 See llvm::FunctionPassManager::FunctionPassManager. */
743LLVMPassManagerRef LLVMCreateFunctionPassManager(LLVMModuleProviderRef MP);
744
745/** Initializes, executes on the provided module, and finalizes all of the
746 passes scheduled in the pass manager. Returns 1 if any of the passes
747 modified the module, 0 otherwise. See llvm::PassManager::run(Module&). */
748int LLVMRunPassManager(LLVMPassManagerRef PM, LLVMModuleRef M);
749
750/** Initializes all of the function passes scheduled in the function pass
751 manager. Returns 1 if any of the passes modified the module, 0 otherwise.
752 See llvm::FunctionPassManager::doInitialization. */
753int LLVMInitializeFunctionPassManager(LLVMPassManagerRef FPM);
754
755/** Executes all of the function passes scheduled in the function pass manager
756 on the provided function. Returns 1 if any of the passes modified the
757 function, false otherwise.
758 See llvm::FunctionPassManager::run(Function&). */
759int LLVMRunFunctionPassManager(LLVMPassManagerRef FPM, LLVMValueRef F);
760
761/** Finalizes all of the function passes scheduled in in the function pass
762 manager. Returns 1 if any of the passes modified the module, 0 otherwise.
763 See llvm::FunctionPassManager::doFinalization. */
764int LLVMFinalizeFunctionPassManager(LLVMPassManagerRef FPM);
765
766/** Frees the memory of a pass pipeline. For function pipelines, does not free
767 the module provider.
768 See llvm::PassManagerBase::~PassManagerBase. */
769void LLVMDisposePassManager(LLVMPassManagerRef PM);
770
771
Gordon Henriksen76a03742007-09-18 03:18:57 +0000772#ifdef __cplusplus
773}
Gordon Henriksen76a03742007-09-18 03:18:57 +0000774
Gordon Henriksen7330acd2007-10-05 23:59:36 +0000775namespace llvm {
Gordon Henriksen0a68fe22007-12-12 01:04:30 +0000776 class ModuleProvider;
Gordon Henriksen34eb6d82007-12-19 22:30:40 +0000777 class MemoryBuffer;
Gordon Henriksen96571492008-03-16 15:55:43 +0000778 class PassManagerBase;
Gordon Henriksen0a68fe22007-12-12 01:04:30 +0000779
Gordon Henriksen34eb6d82007-12-19 22:30:40 +0000780 #define DEFINE_SIMPLE_CONVERSION_FUNCTIONS(ty, ref) \
781 inline ty *unwrap(ref P) { \
782 return reinterpret_cast<ty*>(P); \
783 } \
784 \
785 inline ref wrap(const ty *P) { \
786 return reinterpret_cast<ref>(const_cast<ty*>(P)); \
787 }
Gordon Henriksen7330acd2007-10-05 23:59:36 +0000788
Gordon Henriksen878114b2008-03-16 04:20:44 +0000789 #define DEFINE_ISA_CONVERSION_FUNCTIONS(ty, ref) \
790 DEFINE_SIMPLE_CONVERSION_FUNCTIONS(ty, ref) \
791 \
792 template<typename T> \
793 inline T *unwrap(ref P) { \
794 return cast<T>(unwrap(P)); \
795 }
796
797 #define DEFINE_STDCXX_CONVERSION_FUNCTIONS(ty, ref) \
798 DEFINE_SIMPLE_CONVERSION_FUNCTIONS(ty, ref) \
799 \
800 template<typename T> \
801 inline T *unwrap(ref P) { \
802 T *Q = dynamic_cast<T*>(unwrap(P)); \
803 assert(Q && "Invalid cast!"); \
804 return Q; \
805 }
806
807 DEFINE_ISA_CONVERSION_FUNCTIONS (Type, LLVMTypeRef )
808 DEFINE_ISA_CONVERSION_FUNCTIONS (Value, LLVMValueRef )
Gordon Henriksen823f9732007-12-27 18:25:59 +0000809 DEFINE_SIMPLE_CONVERSION_FUNCTIONS(Module, LLVMModuleRef )
810 DEFINE_SIMPLE_CONVERSION_FUNCTIONS(BasicBlock, LLVMBasicBlockRef )
Eric Christopher59278832008-08-08 19:39:37 +0000811 DEFINE_SIMPLE_CONVERSION_FUNCTIONS(IRBuilder<>, LLVMBuilderRef )
Gordon Henriksen823f9732007-12-27 18:25:59 +0000812 DEFINE_SIMPLE_CONVERSION_FUNCTIONS(PATypeHolder, LLVMTypeHandleRef )
813 DEFINE_SIMPLE_CONVERSION_FUNCTIONS(ModuleProvider, LLVMModuleProviderRef)
814 DEFINE_SIMPLE_CONVERSION_FUNCTIONS(MemoryBuffer, LLVMMemoryBufferRef )
Gordon Henriksen878114b2008-03-16 04:20:44 +0000815 DEFINE_STDCXX_CONVERSION_FUNCTIONS(PassManagerBase, LLVMPassManagerRef )
Gordon Henriksen7330acd2007-10-05 23:59:36 +0000816
Gordon Henriksen878114b2008-03-16 04:20:44 +0000817 #undef DEFINE_STDCXX_CONVERSION_FUNCTIONS
818 #undef DEFINE_ISA_CONVERSION_FUNCTIONS
Gordon Henriksen34eb6d82007-12-19 22:30:40 +0000819 #undef DEFINE_SIMPLE_CONVERSION_FUNCTIONS
Gordon Henriksen7330acd2007-10-05 23:59:36 +0000820
Gordon Henriksen34eb6d82007-12-19 22:30:40 +0000821 /* Specialized opaque type conversions.
822 */
Gordon Henriksen7330acd2007-10-05 23:59:36 +0000823 inline Type **unwrap(LLVMTypeRef* Tys) {
824 return reinterpret_cast<Type**>(Tys);
825 }
826
Gordon Henriksen7330acd2007-10-05 23:59:36 +0000827 inline LLVMTypeRef *wrap(const Type **Tys) {
828 return reinterpret_cast<LLVMTypeRef*>(const_cast<Type**>(Tys));
829 }
830
Gordon Henriksen34eb6d82007-12-19 22:30:40 +0000831 /* Specialized opaque value conversions.
Gordon Henriksen7330acd2007-10-05 23:59:36 +0000832 */
Gordon Henriksen7330acd2007-10-05 23:59:36 +0000833 inline Value **unwrap(LLVMValueRef *Vals) {
834 return reinterpret_cast<Value**>(Vals);
835 }
836
837 template<typename T>
838 inline T **unwrap(LLVMValueRef *Vals, unsigned Length) {
839 #if DEBUG
840 for (LLVMValueRef *I = Vals, E = Vals + Length; I != E; ++I)
841 cast<T>(*I);
842 #endif
843 return reinterpret_cast<T**>(Vals);
844 }
845
Gordon Henriksen7330acd2007-10-05 23:59:36 +0000846 inline LLVMValueRef *wrap(const Value **Vals) {
847 return reinterpret_cast<LLVMValueRef*>(const_cast<Value**>(Vals));
848 }
Gordon Henriksen7330acd2007-10-05 23:59:36 +0000849}
850
851#endif /* !defined(__cplusplus) */
852
853#endif /* !defined(LLVM_C_CORE_H) */