blob: 5d8cff414fde99e56c90cfe351b85ff2cc29acd1 [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 Sands12da8ce2009-03-07 15:45:40 +0000130 LLVMExternalWeakAnyLinkage,/**< ExternalWeak linkage description */
131 LLVMExternalWeakODRLinkage,/**< Same, but only replaced by something
132 equivalent. */
133 LLVMGhostLinkage, /**< Stand-in functions for streaming fns from
Gordon Henriksen4a4d7352007-12-30 17:46:33 +0000134 bitcode */
Duncan Sands12da8ce2009-03-07 15:45:40 +0000135 LLVMCommonAnyLinkage, /**< Tentative definitions */
136 LLVMCommonODRLinkage /**< Same, but only replaced by something
137 equivalent. */
Gordon Henriksen76a03742007-09-18 03:18:57 +0000138} LLVMLinkage;
139
140typedef enum {
Gordon Henriksen4a4d7352007-12-30 17:46:33 +0000141 LLVMDefaultVisibility, /**< The GV is visible */
142 LLVMHiddenVisibility, /**< The GV is hidden */
143 LLVMProtectedVisibility /**< The GV is protected */
Gordon Henriksen76a03742007-09-18 03:18:57 +0000144} LLVMVisibility;
145
Gordon Henriksenc23b66c2007-09-26 20:56:12 +0000146typedef enum {
147 LLVMCCallConv = 0,
148 LLVMFastCallConv = 8,
149 LLVMColdCallConv = 9,
150 LLVMX86StdcallCallConv = 64,
151 LLVMX86FastcallCallConv = 65
152} LLVMCallConv;
153
154typedef enum {
Gordon Henriksen4a4d7352007-12-30 17:46:33 +0000155 LLVMIntEQ = 32, /**< equal */
156 LLVMIntNE, /**< not equal */
157 LLVMIntUGT, /**< unsigned greater than */
158 LLVMIntUGE, /**< unsigned greater or equal */
159 LLVMIntULT, /**< unsigned less than */
160 LLVMIntULE, /**< unsigned less or equal */
161 LLVMIntSGT, /**< signed greater than */
162 LLVMIntSGE, /**< signed greater or equal */
163 LLVMIntSLT, /**< signed less than */
164 LLVMIntSLE /**< signed less or equal */
Gordon Henriksenc23b66c2007-09-26 20:56:12 +0000165} LLVMIntPredicate;
166
167typedef enum {
Gordon Henriksen4a4d7352007-12-30 17:46:33 +0000168 LLVMRealPredicateFalse, /**< Always false (always folded) */
169 LLVMRealOEQ, /**< True if ordered and equal */
170 LLVMRealOGT, /**< True if ordered and greater than */
171 LLVMRealOGE, /**< True if ordered and greater than or equal */
172 LLVMRealOLT, /**< True if ordered and less than */
173 LLVMRealOLE, /**< True if ordered and less than or equal */
174 LLVMRealONE, /**< True if ordered and operands are unequal */
175 LLVMRealORD, /**< True if ordered (no nans) */
176 LLVMRealUNO, /**< True if unordered: isnan(X) | isnan(Y) */
177 LLVMRealUEQ, /**< True if unordered or equal */
178 LLVMRealUGT, /**< True if unordered or greater than */
179 LLVMRealUGE, /**< True if unordered, greater than, or equal */
180 LLVMRealULT, /**< True if unordered or less than */
181 LLVMRealULE, /**< True if unordered, less than, or equal */
182 LLVMRealUNE, /**< True if unordered or not equal */
183 LLVMRealPredicateTrue /**< Always true (always folded) */
Gordon Henriksenc23b66c2007-09-26 20:56:12 +0000184} LLVMRealPredicate;
185
Gordon Henriksen76a03742007-09-18 03:18:57 +0000186
Gordon Henriksen34eb6d82007-12-19 22:30:40 +0000187/*===-- Error handling ----------------------------------------------------===*/
188
189void LLVMDisposeMessage(char *Message);
190
191
Gordon Henriksen76a03742007-09-18 03:18:57 +0000192/*===-- Modules -----------------------------------------------------------===*/
193
194/* Create and destroy modules. */
Gordon Henriksena49d4352008-03-07 19:13:06 +0000195/** See llvm::Module::Module. */
Gordon Henriksen76a03742007-09-18 03:18:57 +0000196LLVMModuleRef LLVMModuleCreateWithName(const char *ModuleID);
Gordon Henriksena49d4352008-03-07 19:13:06 +0000197
198/** See llvm::Module::~Module. */
Gordon Henriksen76a03742007-09-18 03:18:57 +0000199void LLVMDisposeModule(LLVMModuleRef M);
200
Gordon Henriksena49d4352008-03-07 19:13:06 +0000201/** Data layout. See Module::getDataLayout. */
Gordon Henriksen05568bb2007-12-27 20:13:47 +0000202const char *LLVMGetDataLayout(LLVMModuleRef M);
203void LLVMSetDataLayout(LLVMModuleRef M, const char *Triple);
204
Gordon Henriksena49d4352008-03-07 19:13:06 +0000205/** Target triple. See Module::getTargetTriple. */
Gordon Henriksen05568bb2007-12-27 20:13:47 +0000206const char *LLVMGetTarget(LLVMModuleRef M);
207void LLVMSetTarget(LLVMModuleRef M, const char *Triple);
208
Gordon Henriksena49d4352008-03-07 19:13:06 +0000209/** See Module::addTypeName. */
Gordon Henriksen76a03742007-09-18 03:18:57 +0000210int LLVMAddTypeName(LLVMModuleRef M, const char *Name, LLVMTypeRef Ty);
Gordon Henriksenc23b66c2007-09-26 20:56:12 +0000211void LLVMDeleteTypeName(LLVMModuleRef M, const char *Name);
Gordon Henriksen76a03742007-09-18 03:18:57 +0000212
Gordon Henriksen6c6075e2008-03-14 23:58:56 +0000213/** See Module::dump. */
214void LLVMDumpModule(LLVMModuleRef M);
215
Gordon Henriksen76a03742007-09-18 03:18:57 +0000216
Gordon Henriksenc23b66c2007-09-26 20:56:12 +0000217/*===-- Types -------------------------------------------------------------===*/
Gordon Henriksen76a03742007-09-18 03:18:57 +0000218
219/* LLVM types conform to the following hierarchy:
220 *
221 * types:
222 * integer type
223 * real type
224 * function type
225 * sequence types:
226 * array type
227 * pointer type
228 * vector type
229 * void type
230 * label type
231 * opaque type
232 */
233
Gordon Henriksena49d4352008-03-07 19:13:06 +0000234/** See llvm::LLVMTypeKind::getTypeID. */
Gordon Henriksen76a03742007-09-18 03:18:57 +0000235LLVMTypeKind LLVMGetTypeKind(LLVMTypeRef Ty);
Gordon Henriksena49d4352008-03-07 19:13:06 +0000236
Gordon Henriksen76a03742007-09-18 03:18:57 +0000237/* Operations on integer types */
Gordon Henriksena735a9c2008-05-04 12:55:34 +0000238LLVMTypeRef LLVMInt1Type(void);
239LLVMTypeRef LLVMInt8Type(void);
240LLVMTypeRef LLVMInt16Type(void);
241LLVMTypeRef LLVMInt32Type(void);
242LLVMTypeRef LLVMInt64Type(void);
Gordon Henriksened7beaa2007-10-06 16:05:20 +0000243LLVMTypeRef LLVMIntType(unsigned NumBits);
Gordon Henriksenc23b66c2007-09-26 20:56:12 +0000244unsigned LLVMGetIntTypeWidth(LLVMTypeRef IntegerTy);
Gordon Henriksen76a03742007-09-18 03:18:57 +0000245
246/* Operations on real types */
Gordon Henriksena735a9c2008-05-04 12:55:34 +0000247LLVMTypeRef LLVMFloatType(void);
248LLVMTypeRef LLVMDoubleType(void);
249LLVMTypeRef LLVMX86FP80Type(void);
250LLVMTypeRef LLVMFP128Type(void);
251LLVMTypeRef LLVMPPCFP128Type(void);
Gordon Henriksen76a03742007-09-18 03:18:57 +0000252
253/* Operations on function types */
Gordon Henriksened7beaa2007-10-06 16:05:20 +0000254LLVMTypeRef LLVMFunctionType(LLVMTypeRef ReturnType,
255 LLVMTypeRef *ParamTypes, unsigned ParamCount,
256 int IsVarArg);
Gordon Henriksen76a03742007-09-18 03:18:57 +0000257int LLVMIsFunctionVarArg(LLVMTypeRef FunctionTy);
Gordon Henriksenc23b66c2007-09-26 20:56:12 +0000258LLVMTypeRef LLVMGetReturnType(LLVMTypeRef FunctionTy);
259unsigned LLVMCountParamTypes(LLVMTypeRef FunctionTy);
260void LLVMGetParamTypes(LLVMTypeRef FunctionTy, LLVMTypeRef *Dest);
Gordon Henriksen76a03742007-09-18 03:18:57 +0000261
262/* Operations on struct types */
Gordon Henriksened7beaa2007-10-06 16:05:20 +0000263LLVMTypeRef LLVMStructType(LLVMTypeRef *ElementTypes, unsigned ElementCount,
264 int Packed);
Gordon Henriksenc23b66c2007-09-26 20:56:12 +0000265unsigned LLVMCountStructElementTypes(LLVMTypeRef StructTy);
Gordon Henriksen76a03742007-09-18 03:18:57 +0000266void LLVMGetStructElementTypes(LLVMTypeRef StructTy, LLVMTypeRef *Dest);
267int LLVMIsPackedStruct(LLVMTypeRef StructTy);
268
269/* Operations on array, pointer, and vector types (sequence types) */
Gordon Henriksened7beaa2007-10-06 16:05:20 +0000270LLVMTypeRef LLVMArrayType(LLVMTypeRef ElementType, unsigned ElementCount);
Gordon Henriksen5a3fe032007-12-17 16:08:32 +0000271LLVMTypeRef LLVMPointerType(LLVMTypeRef ElementType, unsigned AddressSpace);
Gordon Henriksened7beaa2007-10-06 16:05:20 +0000272LLVMTypeRef LLVMVectorType(LLVMTypeRef ElementType, unsigned ElementCount);
Gordon Henriksen76a03742007-09-18 03:18:57 +0000273
274LLVMTypeRef LLVMGetElementType(LLVMTypeRef Ty);
275unsigned LLVMGetArrayLength(LLVMTypeRef ArrayTy);
Gordon Henriksen5a3fe032007-12-17 16:08:32 +0000276unsigned LLVMGetPointerAddressSpace(LLVMTypeRef PointerTy);
Gordon Henriksen76a03742007-09-18 03:18:57 +0000277unsigned LLVMGetVectorSize(LLVMTypeRef VectorTy);
278
279/* Operations on other types */
Gordon Henriksena735a9c2008-05-04 12:55:34 +0000280LLVMTypeRef LLVMVoidType(void);
281LLVMTypeRef LLVMLabelType(void);
282LLVMTypeRef LLVMOpaqueType(void);
Gordon Henriksen76a03742007-09-18 03:18:57 +0000283
Gordon Henriksenffb48762007-10-07 00:13:35 +0000284/* Operations on type handles */
285LLVMTypeHandleRef LLVMCreateTypeHandle(LLVMTypeRef PotentiallyAbstractTy);
286void LLVMRefineType(LLVMTypeRef AbstractTy, LLVMTypeRef ConcreteTy);
287LLVMTypeRef LLVMResolveTypeHandle(LLVMTypeHandleRef TypeHandle);
288void LLVMDisposeTypeHandle(LLVMTypeHandleRef TypeHandle);
289
Gordon Henriksen76a03742007-09-18 03:18:57 +0000290
291/*===-- Values ------------------------------------------------------------===*/
292
293/* The bulk of LLVM's object model consists of values, which comprise a very
294 * rich type hierarchy.
Gordon Henriksen76a03742007-09-18 03:18:57 +0000295 */
296
Gordon Henriksen29e38942008-12-19 18:39:45 +0000297#define LLVM_FOR_EACH_VALUE_SUBCLASS(macro) \
298 macro(Argument) \
299 macro(BasicBlock) \
300 macro(InlineAsm) \
301 macro(User) \
302 macro(Constant) \
303 macro(ConstantAggregateZero) \
304 macro(ConstantArray) \
305 macro(ConstantExpr) \
306 macro(ConstantFP) \
307 macro(ConstantInt) \
308 macro(ConstantPointerNull) \
309 macro(ConstantStruct) \
310 macro(ConstantVector) \
311 macro(GlobalValue) \
312 macro(Function) \
313 macro(GlobalAlias) \
314 macro(GlobalVariable) \
315 macro(UndefValue) \
316 macro(Instruction) \
317 macro(BinaryOperator) \
318 macro(CallInst) \
319 macro(IntrinsicInst) \
320 macro(DbgInfoIntrinsic) \
321 macro(DbgDeclareInst) \
322 macro(DbgFuncStartInst) \
323 macro(DbgRegionEndInst) \
324 macro(DbgRegionStartInst) \
325 macro(DbgStopPointInst) \
326 macro(EHSelectorInst) \
327 macro(MemIntrinsic) \
328 macro(MemCpyInst) \
329 macro(MemMoveInst) \
330 macro(MemSetInst) \
331 macro(CmpInst) \
332 macro(FCmpInst) \
333 macro(ICmpInst) \
334 macro(VFCmpInst) \
335 macro(VICmpInst) \
336 macro(ExtractElementInst) \
337 macro(GetElementPtrInst) \
338 macro(InsertElementInst) \
339 macro(InsertValueInst) \
340 macro(PHINode) \
341 macro(SelectInst) \
342 macro(ShuffleVectorInst) \
343 macro(StoreInst) \
344 macro(TerminatorInst) \
345 macro(BranchInst) \
346 macro(InvokeInst) \
347 macro(ReturnInst) \
348 macro(SwitchInst) \
349 macro(UnreachableInst) \
350 macro(UnwindInst) \
351 macro(UnaryInstruction) \
352 macro(AllocationInst) \
Gordon Henriksen05a868f2008-12-19 18:51:17 +0000353 macro(AllocaInst) \
354 macro(MallocInst) \
Gordon Henriksen29e38942008-12-19 18:39:45 +0000355 macro(CastInst) \
Gordon Henriksen05a868f2008-12-19 18:51:17 +0000356 macro(BitCastInst) \
357 macro(FPExtInst) \
358 macro(FPToSIInst) \
359 macro(FPToUIInst) \
360 macro(FPTruncInst) \
361 macro(IntToPtrInst) \
362 macro(PtrToIntInst) \
363 macro(SExtInst) \
364 macro(SIToFPInst) \
365 macro(TruncInst) \
366 macro(UIToFPInst) \
367 macro(ZExtInst) \
368 macro(ExtractValueInst) \
369 macro(FreeInst) \
370 macro(LoadInst) \
371 macro(VAArgInst)
Gordon Henriksen29e38942008-12-19 18:39:45 +0000372
Gordon Henriksen76a03742007-09-18 03:18:57 +0000373/* Operations on all values */
Gordon Henriksenc23b66c2007-09-26 20:56:12 +0000374LLVMTypeRef LLVMTypeOf(LLVMValueRef Val);
Gordon Henriksen76a03742007-09-18 03:18:57 +0000375const char *LLVMGetValueName(LLVMValueRef Val);
376void LLVMSetValueName(LLVMValueRef Val, const char *Name);
Gordon Henriksen1d0d24c2007-10-06 00:08:49 +0000377void LLVMDumpValue(LLVMValueRef Val);
Gordon Henriksen76a03742007-09-18 03:18:57 +0000378
Gordon Henriksen29e38942008-12-19 18:39:45 +0000379/* Conversion functions. Return the input value if it is an instance of the
380 specified class, otherwise NULL. See llvm::dyn_cast_or_null<>. */
381#define LLVM_DECLARE_VALUE_CAST(name) \
382 LLVMValueRef LLVMIsA##name(LLVMValueRef Val);
383LLVM_FOR_EACH_VALUE_SUBCLASS(LLVM_DECLARE_VALUE_CAST)
384
Gordon Henriksen76a03742007-09-18 03:18:57 +0000385/* Operations on constants of any type */
Gordon Henriksen1046c732007-10-06 15:11:06 +0000386LLVMValueRef LLVMConstNull(LLVMTypeRef Ty); /* all zeroes */
387LLVMValueRef LLVMConstAllOnes(LLVMTypeRef Ty); /* only for int/vector */
Gordon Henriksen76a03742007-09-18 03:18:57 +0000388LLVMValueRef LLVMGetUndef(LLVMTypeRef Ty);
Gordon Henriksendc88c062007-09-18 18:07:51 +0000389int LLVMIsConstant(LLVMValueRef Val);
Gordon Henriksen76a03742007-09-18 03:18:57 +0000390int LLVMIsNull(LLVMValueRef Val);
Gordon Henriksendc88c062007-09-18 18:07:51 +0000391int LLVMIsUndef(LLVMValueRef Val);
Gordon Henriksen76a03742007-09-18 03:18:57 +0000392
393/* Operations on scalar constants */
Gordon Henriksen1046c732007-10-06 15:11:06 +0000394LLVMValueRef LLVMConstInt(LLVMTypeRef IntTy, unsigned long long N,
395 int SignExtend);
396LLVMValueRef LLVMConstReal(LLVMTypeRef RealTy, double N);
Gordon Henriksen931e1212008-02-02 01:07:50 +0000397LLVMValueRef LLVMConstRealOfString(LLVMTypeRef RealTy, const char *Text);
Gordon Henriksen76a03742007-09-18 03:18:57 +0000398
399/* Operations on composite constants */
Gordon Henriksen1046c732007-10-06 15:11:06 +0000400LLVMValueRef LLVMConstString(const char *Str, unsigned Length,
401 int DontNullTerminate);
Gordon Henriksen2ad5aef2008-04-25 03:21:19 +0000402LLVMValueRef LLVMConstArray(LLVMTypeRef ElementTy,
Gordon Henriksen1046c732007-10-06 15:11:06 +0000403 LLVMValueRef *ConstantVals, unsigned Length);
404LLVMValueRef LLVMConstStruct(LLVMValueRef *ConstantVals, unsigned Count,
405 int packed);
406LLVMValueRef LLVMConstVector(LLVMValueRef *ScalarConstantVals, unsigned Size);
Gordon Henriksen76a03742007-09-18 03:18:57 +0000407
Gordon Henriksen7ce31762007-10-06 14:29:36 +0000408/* Constant expressions */
409LLVMValueRef LLVMSizeOf(LLVMTypeRef Ty);
410LLVMValueRef LLVMConstNeg(LLVMValueRef ConstantVal);
411LLVMValueRef LLVMConstNot(LLVMValueRef ConstantVal);
412LLVMValueRef LLVMConstAdd(LLVMValueRef LHSConstant, LLVMValueRef RHSConstant);
413LLVMValueRef LLVMConstSub(LLVMValueRef LHSConstant, LLVMValueRef RHSConstant);
414LLVMValueRef LLVMConstMul(LLVMValueRef LHSConstant, LLVMValueRef RHSConstant);
415LLVMValueRef LLVMConstUDiv(LLVMValueRef LHSConstant, LLVMValueRef RHSConstant);
416LLVMValueRef LLVMConstSDiv(LLVMValueRef LHSConstant, LLVMValueRef RHSConstant);
417LLVMValueRef LLVMConstFDiv(LLVMValueRef LHSConstant, LLVMValueRef RHSConstant);
418LLVMValueRef LLVMConstURem(LLVMValueRef LHSConstant, LLVMValueRef RHSConstant);
419LLVMValueRef LLVMConstSRem(LLVMValueRef LHSConstant, LLVMValueRef RHSConstant);
420LLVMValueRef LLVMConstFRem(LLVMValueRef LHSConstant, LLVMValueRef RHSConstant);
421LLVMValueRef LLVMConstAnd(LLVMValueRef LHSConstant, LLVMValueRef RHSConstant);
422LLVMValueRef LLVMConstOr(LLVMValueRef LHSConstant, LLVMValueRef RHSConstant);
423LLVMValueRef LLVMConstXor(LLVMValueRef LHSConstant, LLVMValueRef RHSConstant);
424LLVMValueRef LLVMConstICmp(LLVMIntPredicate Predicate,
425 LLVMValueRef LHSConstant, LLVMValueRef RHSConstant);
426LLVMValueRef LLVMConstFCmp(LLVMRealPredicate Predicate,
427 LLVMValueRef LHSConstant, LLVMValueRef RHSConstant);
428LLVMValueRef LLVMConstShl(LLVMValueRef LHSConstant, LLVMValueRef RHSConstant);
429LLVMValueRef LLVMConstLShr(LLVMValueRef LHSConstant, LLVMValueRef RHSConstant);
430LLVMValueRef LLVMConstAShr(LLVMValueRef LHSConstant, LLVMValueRef RHSConstant);
431LLVMValueRef LLVMConstGEP(LLVMValueRef ConstantVal,
432 LLVMValueRef *ConstantIndices, unsigned NumIndices);
433LLVMValueRef LLVMConstTrunc(LLVMValueRef ConstantVal, LLVMTypeRef ToType);
434LLVMValueRef LLVMConstSExt(LLVMValueRef ConstantVal, LLVMTypeRef ToType);
435LLVMValueRef LLVMConstZExt(LLVMValueRef ConstantVal, LLVMTypeRef ToType);
436LLVMValueRef LLVMConstFPTrunc(LLVMValueRef ConstantVal, LLVMTypeRef ToType);
437LLVMValueRef LLVMConstFPExt(LLVMValueRef ConstantVal, LLVMTypeRef ToType);
438LLVMValueRef LLVMConstUIToFP(LLVMValueRef ConstantVal, LLVMTypeRef ToType);
439LLVMValueRef LLVMConstSIToFP(LLVMValueRef ConstantVal, LLVMTypeRef ToType);
440LLVMValueRef LLVMConstFPToUI(LLVMValueRef ConstantVal, LLVMTypeRef ToType);
441LLVMValueRef LLVMConstFPToSI(LLVMValueRef ConstantVal, LLVMTypeRef ToType);
442LLVMValueRef LLVMConstPtrToInt(LLVMValueRef ConstantVal, LLVMTypeRef ToType);
443LLVMValueRef LLVMConstIntToPtr(LLVMValueRef ConstantVal, LLVMTypeRef ToType);
444LLVMValueRef LLVMConstBitCast(LLVMValueRef ConstantVal, LLVMTypeRef ToType);
445LLVMValueRef LLVMConstSelect(LLVMValueRef ConstantCondition,
446 LLVMValueRef ConstantIfTrue,
447 LLVMValueRef ConstantIfFalse);
448LLVMValueRef LLVMConstExtractElement(LLVMValueRef VectorConstant,
449 LLVMValueRef IndexConstant);
450LLVMValueRef LLVMConstInsertElement(LLVMValueRef VectorConstant,
451 LLVMValueRef ElementValueConstant,
452 LLVMValueRef IndexConstant);
453LLVMValueRef LLVMConstShuffleVector(LLVMValueRef VectorAConstant,
454 LLVMValueRef VectorBConstant,
455 LLVMValueRef MaskConstant);
Dan Gohmand5104a52008-11-03 22:55:43 +0000456LLVMValueRef LLVMConstExtractValue(LLVMValueRef AggConstant, unsigned *IdxList,
457 unsigned NumIdx);
458LLVMValueRef LLVMConstInsertValue(LLVMValueRef AggConstant,
459 LLVMValueRef ElementValueConstant,
460 unsigned *IdxList, unsigned NumIdx);
Chris Lattner3d1f5522008-12-17 21:39:50 +0000461LLVMValueRef LLVMConstInlineAsm(LLVMTypeRef Ty,
462 const char *AsmString, const char *Constraints,
463 int HasSideEffects);
Gordon Henriksen7ce31762007-10-06 14:29:36 +0000464
Gordon Henriksen76a03742007-09-18 03:18:57 +0000465/* Operations on global variables, functions, and aliases (globals) */
Gordon Henriksen265f7802008-03-19 01:11:35 +0000466LLVMModuleRef LLVMGetGlobalParent(LLVMValueRef Global);
Gordon Henriksen76a03742007-09-18 03:18:57 +0000467int LLVMIsDeclaration(LLVMValueRef Global);
468LLVMLinkage LLVMGetLinkage(LLVMValueRef Global);
469void LLVMSetLinkage(LLVMValueRef Global, LLVMLinkage Linkage);
470const char *LLVMGetSection(LLVMValueRef Global);
471void LLVMSetSection(LLVMValueRef Global, const char *Section);
472LLVMVisibility LLVMGetVisibility(LLVMValueRef Global);
473void LLVMSetVisibility(LLVMValueRef Global, LLVMVisibility Viz);
474unsigned LLVMGetAlignment(LLVMValueRef Global);
475void LLVMSetAlignment(LLVMValueRef Global, unsigned Bytes);
476
477/* Operations on global variables */
478LLVMValueRef LLVMAddGlobal(LLVMModuleRef M, LLVMTypeRef Ty, const char *Name);
Gordon Henriksen783f7bb2007-10-08 03:45:09 +0000479LLVMValueRef LLVMGetNamedGlobal(LLVMModuleRef M, const char *Name);
Gordon Henriksen07a45f42008-03-23 22:21:29 +0000480LLVMValueRef LLVMGetFirstGlobal(LLVMModuleRef M);
481LLVMValueRef LLVMGetLastGlobal(LLVMModuleRef M);
482LLVMValueRef LLVMGetNextGlobal(LLVMValueRef GlobalVar);
483LLVMValueRef LLVMGetPreviousGlobal(LLVMValueRef GlobalVar);
Gordon Henriksen76a03742007-09-18 03:18:57 +0000484void LLVMDeleteGlobal(LLVMValueRef GlobalVar);
Gordon Henriksen76a03742007-09-18 03:18:57 +0000485LLVMValueRef LLVMGetInitializer(LLVMValueRef GlobalVar);
486void LLVMSetInitializer(LLVMValueRef GlobalVar, LLVMValueRef ConstantVal);
487int LLVMIsThreadLocal(LLVMValueRef GlobalVar);
488void LLVMSetThreadLocal(LLVMValueRef GlobalVar, int IsThreadLocal);
Gordon Henriksen751ebf72007-10-07 17:31:42 +0000489int LLVMIsGlobalConstant(LLVMValueRef GlobalVar);
490void LLVMSetGlobalConstant(LLVMValueRef GlobalVar, int IsConstant);
Gordon Henriksen76a03742007-09-18 03:18:57 +0000491
Chris Lattner3d1f5522008-12-17 21:39:50 +0000492/* Operations on aliases */
493LLVMValueRef LLVMAddAlias(LLVMModuleRef M, LLVMTypeRef Ty, LLVMValueRef Aliasee,
494 const char *Name);
495
Gordon Henriksenc23b66c2007-09-26 20:56:12 +0000496/* Operations on functions */
497LLVMValueRef LLVMAddFunction(LLVMModuleRef M, const char *Name,
498 LLVMTypeRef FunctionTy);
Gordon Henriksen783f7bb2007-10-08 03:45:09 +0000499LLVMValueRef LLVMGetNamedFunction(LLVMModuleRef M, const char *Name);
Gordon Henriksen054817c2008-03-19 03:47:18 +0000500LLVMValueRef LLVMGetFirstFunction(LLVMModuleRef M);
501LLVMValueRef LLVMGetLastFunction(LLVMModuleRef M);
502LLVMValueRef LLVMGetNextFunction(LLVMValueRef Fn);
503LLVMValueRef LLVMGetPreviousFunction(LLVMValueRef Fn);
Gordon Henriksenc23b66c2007-09-26 20:56:12 +0000504void LLVMDeleteFunction(LLVMValueRef Fn);
Gordon Henriksenc23b66c2007-09-26 20:56:12 +0000505unsigned LLVMGetIntrinsicID(LLVMValueRef Fn);
506unsigned LLVMGetFunctionCallConv(LLVMValueRef Fn);
507void LLVMSetFunctionCallConv(LLVMValueRef Fn, unsigned CC);
Gordon Henriksend930f912008-08-17 18:44:35 +0000508const char *LLVMGetGC(LLVMValueRef Fn);
509void LLVMSetGC(LLVMValueRef Fn, const char *Name);
Gordon Henriksenc23b66c2007-09-26 20:56:12 +0000510
Gordon Henriksen265f7802008-03-19 01:11:35 +0000511/* Operations on parameters */
512unsigned LLVMCountParams(LLVMValueRef Fn);
513void LLVMGetParams(LLVMValueRef Fn, LLVMValueRef *Params);
514LLVMValueRef LLVMGetParam(LLVMValueRef Fn, unsigned Index);
515LLVMValueRef LLVMGetParamParent(LLVMValueRef Inst);
Gordon Henriksen07a45f42008-03-23 22:21:29 +0000516LLVMValueRef LLVMGetFirstParam(LLVMValueRef Fn);
517LLVMValueRef LLVMGetLastParam(LLVMValueRef Fn);
518LLVMValueRef LLVMGetNextParam(LLVMValueRef Arg);
519LLVMValueRef LLVMGetPreviousParam(LLVMValueRef Arg);
Devang Patel4c758ea2008-09-25 21:00:45 +0000520void LLVMAddAttribute(LLVMValueRef Arg, LLVMAttribute PA);
521void LLVMRemoveAttribute(LLVMValueRef Arg, LLVMAttribute PA);
Gordon Henriksen2d9cc212008-04-28 17:37:06 +0000522void LLVMSetParamAlignment(LLVMValueRef Arg, unsigned align);
Gordon Henriksen265f7802008-03-19 01:11:35 +0000523
Gordon Henriksenc23b66c2007-09-26 20:56:12 +0000524/* Operations on basic blocks */
Gordon Henriksen07a45f42008-03-23 22:21:29 +0000525LLVMValueRef LLVMBasicBlockAsValue(LLVMBasicBlockRef BB);
Gordon Henriksenc23b66c2007-09-26 20:56:12 +0000526int LLVMValueIsBasicBlock(LLVMValueRef Val);
527LLVMBasicBlockRef LLVMValueAsBasicBlock(LLVMValueRef Val);
Gordon Henriksen07a45f42008-03-23 22:21:29 +0000528LLVMValueRef LLVMGetBasicBlockParent(LLVMBasicBlockRef BB);
Gordon Henriksenc23b66c2007-09-26 20:56:12 +0000529unsigned LLVMCountBasicBlocks(LLVMValueRef Fn);
530void LLVMGetBasicBlocks(LLVMValueRef Fn, LLVMBasicBlockRef *BasicBlocks);
Gordon Henriksen054817c2008-03-19 03:47:18 +0000531LLVMBasicBlockRef LLVMGetFirstBasicBlock(LLVMValueRef Fn);
532LLVMBasicBlockRef LLVMGetLastBasicBlock(LLVMValueRef Fn);
533LLVMBasicBlockRef LLVMGetNextBasicBlock(LLVMBasicBlockRef BB);
534LLVMBasicBlockRef LLVMGetPreviousBasicBlock(LLVMBasicBlockRef BB);
Gordon Henriksenc23b66c2007-09-26 20:56:12 +0000535LLVMBasicBlockRef LLVMGetEntryBasicBlock(LLVMValueRef Fn);
536LLVMBasicBlockRef LLVMAppendBasicBlock(LLVMValueRef Fn, const char *Name);
537LLVMBasicBlockRef LLVMInsertBasicBlock(LLVMBasicBlockRef InsertBeforeBB,
538 const char *Name);
539void LLVMDeleteBasicBlock(LLVMBasicBlockRef BB);
540
Gordon Henriksen265f7802008-03-19 01:11:35 +0000541/* Operations on instructions */
542LLVMBasicBlockRef LLVMGetInstructionParent(LLVMValueRef Inst);
Gordon Henriksen054817c2008-03-19 03:47:18 +0000543LLVMValueRef LLVMGetFirstInstruction(LLVMBasicBlockRef BB);
544LLVMValueRef LLVMGetLastInstruction(LLVMBasicBlockRef BB);
545LLVMValueRef LLVMGetNextInstruction(LLVMValueRef Inst);
546LLVMValueRef LLVMGetPreviousInstruction(LLVMValueRef Inst);
Gordon Henriksen265f7802008-03-19 01:11:35 +0000547
Gordon Henriksen1158c532007-12-29 20:45:00 +0000548/* Operations on call sites */
549void LLVMSetInstructionCallConv(LLVMValueRef Instr, unsigned CC);
550unsigned LLVMGetInstructionCallConv(LLVMValueRef Instr);
Devang Patel4c758ea2008-09-25 21:00:45 +0000551void LLVMAddInstrAttribute(LLVMValueRef Instr, unsigned index, LLVMAttribute);
552void LLVMRemoveInstrAttribute(LLVMValueRef Instr, unsigned index,
553 LLVMAttribute);
Gordon Henriksen2d9cc212008-04-28 17:37:06 +0000554void LLVMSetInstrParamAlignment(LLVMValueRef Instr, unsigned index,
555 unsigned align);
Gordon Henriksen1158c532007-12-29 20:45:00 +0000556
Gordon Henrikseneeb65372008-08-30 16:34:54 +0000557/* Operations on call instructions (only) */
558int LLVMIsTailCall(LLVMValueRef CallInst);
559void LLVMSetTailCall(LLVMValueRef CallInst, int IsTailCall);
560
Gordon Henriksen44dd8fb2007-10-08 18:14:39 +0000561/* Operations on phi nodes */
562void LLVMAddIncoming(LLVMValueRef PhiNode, LLVMValueRef *IncomingValues,
563 LLVMBasicBlockRef *IncomingBlocks, unsigned Count);
564unsigned LLVMCountIncoming(LLVMValueRef PhiNode);
565LLVMValueRef LLVMGetIncomingValue(LLVMValueRef PhiNode, unsigned Index);
566LLVMBasicBlockRef LLVMGetIncomingBlock(LLVMValueRef PhiNode, unsigned Index);
Gordon Henriksenc23b66c2007-09-26 20:56:12 +0000567
568/*===-- Instruction builders ----------------------------------------------===*/
569
570/* An instruction builder represents a point within a basic block, and is the
571 * exclusive means of building instructions using the C interface.
572 */
573
Gordon Henriksena735a9c2008-05-04 12:55:34 +0000574LLVMBuilderRef LLVMCreateBuilder(void);
Gordon Henriksen054817c2008-03-19 03:47:18 +0000575void LLVMPositionBuilder(LLVMBuilderRef Builder, LLVMBasicBlockRef Block,
576 LLVMValueRef Instr);
Gordon Henriksenc23b66c2007-09-26 20:56:12 +0000577void LLVMPositionBuilderBefore(LLVMBuilderRef Builder, LLVMValueRef Instr);
578void LLVMPositionBuilderAtEnd(LLVMBuilderRef Builder, LLVMBasicBlockRef Block);
Gordon Henriksen265f7802008-03-19 01:11:35 +0000579LLVMBasicBlockRef LLVMGetInsertBlock(LLVMBuilderRef Builder);
Chris Lattner3d1f5522008-12-17 21:39:50 +0000580void LLVMClearInsertionPosition(LLVMBuilderRef Builder);
581void LLVMInsertIntoBuilder(LLVMBuilderRef Builder, LLVMValueRef Instr);
Gordon Henriksenc23b66c2007-09-26 20:56:12 +0000582void LLVMDisposeBuilder(LLVMBuilderRef Builder);
583
584/* Terminators */
585LLVMValueRef LLVMBuildRetVoid(LLVMBuilderRef);
586LLVMValueRef LLVMBuildRet(LLVMBuilderRef, LLVMValueRef V);
587LLVMValueRef LLVMBuildBr(LLVMBuilderRef, LLVMBasicBlockRef Dest);
588LLVMValueRef LLVMBuildCondBr(LLVMBuilderRef, LLVMValueRef If,
589 LLVMBasicBlockRef Then, LLVMBasicBlockRef Else);
590LLVMValueRef LLVMBuildSwitch(LLVMBuilderRef, LLVMValueRef V,
591 LLVMBasicBlockRef Else, unsigned NumCases);
592LLVMValueRef LLVMBuildInvoke(LLVMBuilderRef, LLVMValueRef Fn,
593 LLVMValueRef *Args, unsigned NumArgs,
594 LLVMBasicBlockRef Then, LLVMBasicBlockRef Catch,
595 const char *Name);
596LLVMValueRef LLVMBuildUnwind(LLVMBuilderRef);
597LLVMValueRef LLVMBuildUnreachable(LLVMBuilderRef);
598
Gordon Henriksen097102c2008-01-01 05:50:53 +0000599/* Add a case to the switch instruction */
600void LLVMAddCase(LLVMValueRef Switch, LLVMValueRef OnVal,
601 LLVMBasicBlockRef Dest);
602
Gordon Henriksenc23b66c2007-09-26 20:56:12 +0000603/* Arithmetic */
604LLVMValueRef LLVMBuildAdd(LLVMBuilderRef, LLVMValueRef LHS, LLVMValueRef RHS,
605 const char *Name);
606LLVMValueRef LLVMBuildSub(LLVMBuilderRef, LLVMValueRef LHS, LLVMValueRef RHS,
607 const char *Name);
608LLVMValueRef LLVMBuildMul(LLVMBuilderRef, LLVMValueRef LHS, LLVMValueRef RHS,
609 const char *Name);
610LLVMValueRef LLVMBuildUDiv(LLVMBuilderRef, LLVMValueRef LHS, LLVMValueRef RHS,
611 const char *Name);
612LLVMValueRef LLVMBuildSDiv(LLVMBuilderRef, LLVMValueRef LHS, LLVMValueRef RHS,
613 const char *Name);
614LLVMValueRef LLVMBuildFDiv(LLVMBuilderRef, LLVMValueRef LHS, LLVMValueRef RHS,
615 const char *Name);
616LLVMValueRef LLVMBuildURem(LLVMBuilderRef, LLVMValueRef LHS, LLVMValueRef RHS,
617 const char *Name);
618LLVMValueRef LLVMBuildSRem(LLVMBuilderRef, LLVMValueRef LHS, LLVMValueRef RHS,
619 const char *Name);
620LLVMValueRef LLVMBuildFRem(LLVMBuilderRef, LLVMValueRef LHS, LLVMValueRef RHS,
621 const char *Name);
622LLVMValueRef LLVMBuildShl(LLVMBuilderRef, LLVMValueRef LHS, LLVMValueRef RHS,
623 const char *Name);
624LLVMValueRef LLVMBuildLShr(LLVMBuilderRef, LLVMValueRef LHS, LLVMValueRef RHS,
625 const char *Name);
626LLVMValueRef LLVMBuildAShr(LLVMBuilderRef, LLVMValueRef LHS, LLVMValueRef RHS,
627 const char *Name);
628LLVMValueRef LLVMBuildAnd(LLVMBuilderRef, LLVMValueRef LHS, LLVMValueRef RHS,
629 const char *Name);
630LLVMValueRef LLVMBuildOr(LLVMBuilderRef, LLVMValueRef LHS, LLVMValueRef RHS,
631 const char *Name);
632LLVMValueRef LLVMBuildXor(LLVMBuilderRef, LLVMValueRef LHS, LLVMValueRef RHS,
633 const char *Name);
634LLVMValueRef LLVMBuildNeg(LLVMBuilderRef, LLVMValueRef V, const char *Name);
635LLVMValueRef LLVMBuildNot(LLVMBuilderRef, LLVMValueRef V, const char *Name);
636
637/* Memory */
638LLVMValueRef LLVMBuildMalloc(LLVMBuilderRef, LLVMTypeRef Ty, const char *Name);
639LLVMValueRef LLVMBuildArrayMalloc(LLVMBuilderRef, LLVMTypeRef Ty,
640 LLVMValueRef Val, const char *Name);
641LLVMValueRef LLVMBuildAlloca(LLVMBuilderRef, LLVMTypeRef Ty, const char *Name);
642LLVMValueRef LLVMBuildArrayAlloca(LLVMBuilderRef, LLVMTypeRef Ty,
643 LLVMValueRef Val, const char *Name);
644LLVMValueRef LLVMBuildFree(LLVMBuilderRef, LLVMValueRef PointerVal);
645LLVMValueRef LLVMBuildLoad(LLVMBuilderRef, LLVMValueRef PointerVal,
646 const char *Name);
647LLVMValueRef LLVMBuildStore(LLVMBuilderRef, LLVMValueRef Val, LLVMValueRef Ptr);
648LLVMValueRef LLVMBuildGEP(LLVMBuilderRef B, LLVMValueRef Pointer,
649 LLVMValueRef *Indices, unsigned NumIndices,
650 const char *Name);
651
652/* Casts */
653LLVMValueRef LLVMBuildTrunc(LLVMBuilderRef, LLVMValueRef Val,
654 LLVMTypeRef DestTy, const char *Name);
655LLVMValueRef LLVMBuildZExt(LLVMBuilderRef, LLVMValueRef Val,
656 LLVMTypeRef DestTy, const char *Name);
657LLVMValueRef LLVMBuildSExt(LLVMBuilderRef, LLVMValueRef Val,
658 LLVMTypeRef DestTy, const char *Name);
659LLVMValueRef LLVMBuildFPToUI(LLVMBuilderRef, LLVMValueRef Val,
660 LLVMTypeRef DestTy, const char *Name);
661LLVMValueRef LLVMBuildFPToSI(LLVMBuilderRef, LLVMValueRef Val,
662 LLVMTypeRef DestTy, const char *Name);
663LLVMValueRef LLVMBuildUIToFP(LLVMBuilderRef, LLVMValueRef Val,
664 LLVMTypeRef DestTy, const char *Name);
665LLVMValueRef LLVMBuildSIToFP(LLVMBuilderRef, LLVMValueRef Val,
666 LLVMTypeRef DestTy, const char *Name);
667LLVMValueRef LLVMBuildFPTrunc(LLVMBuilderRef, LLVMValueRef Val,
668 LLVMTypeRef DestTy, const char *Name);
669LLVMValueRef LLVMBuildFPExt(LLVMBuilderRef, LLVMValueRef Val,
670 LLVMTypeRef DestTy, const char *Name);
671LLVMValueRef LLVMBuildPtrToInt(LLVMBuilderRef, LLVMValueRef Val,
672 LLVMTypeRef DestTy, const char *Name);
673LLVMValueRef LLVMBuildIntToPtr(LLVMBuilderRef, LLVMValueRef Val,
674 LLVMTypeRef DestTy, const char *Name);
675LLVMValueRef LLVMBuildBitCast(LLVMBuilderRef, LLVMValueRef Val,
676 LLVMTypeRef DestTy, const char *Name);
677
678/* Comparisons */
679LLVMValueRef LLVMBuildICmp(LLVMBuilderRef, LLVMIntPredicate Op,
680 LLVMValueRef LHS, LLVMValueRef RHS,
681 const char *Name);
682LLVMValueRef LLVMBuildFCmp(LLVMBuilderRef, LLVMRealPredicate Op,
683 LLVMValueRef LHS, LLVMValueRef RHS,
684 const char *Name);
685
686/* Miscellaneous instructions */
687LLVMValueRef LLVMBuildPhi(LLVMBuilderRef, LLVMTypeRef Ty, const char *Name);
688LLVMValueRef LLVMBuildCall(LLVMBuilderRef, LLVMValueRef Fn,
689 LLVMValueRef *Args, unsigned NumArgs,
690 const char *Name);
691LLVMValueRef LLVMBuildSelect(LLVMBuilderRef, LLVMValueRef If,
692 LLVMValueRef Then, LLVMValueRef Else,
693 const char *Name);
694LLVMValueRef LLVMBuildVAArg(LLVMBuilderRef, LLVMValueRef List, LLVMTypeRef Ty,
695 const char *Name);
696LLVMValueRef LLVMBuildExtractElement(LLVMBuilderRef, LLVMValueRef VecVal,
697 LLVMValueRef Index, const char *Name);
698LLVMValueRef LLVMBuildInsertElement(LLVMBuilderRef, LLVMValueRef VecVal,
699 LLVMValueRef EltVal, LLVMValueRef Index,
700 const char *Name);
701LLVMValueRef LLVMBuildShuffleVector(LLVMBuilderRef, LLVMValueRef V1,
702 LLVMValueRef V2, LLVMValueRef Mask,
703 const char *Name);
Dan Gohmand5104a52008-11-03 22:55:43 +0000704LLVMValueRef LLVMBuildExtractValue(LLVMBuilderRef, LLVMValueRef AggVal,
705 unsigned Index, const char *Name);
706LLVMValueRef LLVMBuildInsertValue(LLVMBuilderRef, LLVMValueRef AggVal,
707 LLVMValueRef EltVal, unsigned Index,
708 const char *Name);
Gordon Henriksen76a03742007-09-18 03:18:57 +0000709
Gordon Henriksen34eb6d82007-12-19 22:30:40 +0000710
Gordon Henriksen0a68fe22007-12-12 01:04:30 +0000711/*===-- Module providers --------------------------------------------------===*/
712
713/* Encapsulates the module M in a module provider, taking ownership of the
714 * module.
715 * See the constructor llvm::ExistingModuleProvider::ExistingModuleProvider.
716 */
717LLVMModuleProviderRef
718LLVMCreateModuleProviderForExistingModule(LLVMModuleRef M);
719
720/* Destroys the module provider MP as well as the contained module.
721 * See the destructor llvm::ModuleProvider::~ModuleProvider.
722 */
723void LLVMDisposeModuleProvider(LLVMModuleProviderRef MP);
724
Gordon Henriksen34eb6d82007-12-19 22:30:40 +0000725
726/*===-- Memory buffers ----------------------------------------------------===*/
727
728int LLVMCreateMemoryBufferWithContentsOfFile(const char *Path,
729 LLVMMemoryBufferRef *OutMemBuf,
730 char **OutMessage);
731int LLVMCreateMemoryBufferWithSTDIN(LLVMMemoryBufferRef *OutMemBuf,
732 char **OutMessage);
733void LLVMDisposeMemoryBuffer(LLVMMemoryBufferRef MemBuf);
734
Gordon Henriksen878114b2008-03-16 04:20:44 +0000735
736/*===-- Pass Managers -----------------------------------------------------===*/
737
738/** Constructs a new whole-module pass pipeline. This type of pipeline is
739 suitable for link-time optimization and whole-module transformations.
740 See llvm::PassManager::PassManager. */
Gordon Henriksena735a9c2008-05-04 12:55:34 +0000741LLVMPassManagerRef LLVMCreatePassManager(void);
Gordon Henriksen878114b2008-03-16 04:20:44 +0000742
743/** Constructs a new function-by-function pass pipeline over the module
744 provider. It does not take ownership of the module provider. This type of
745 pipeline is suitable for code generation and JIT compilation tasks.
746 See llvm::FunctionPassManager::FunctionPassManager. */
747LLVMPassManagerRef LLVMCreateFunctionPassManager(LLVMModuleProviderRef MP);
748
749/** Initializes, executes on the provided module, and finalizes all of the
750 passes scheduled in the pass manager. Returns 1 if any of the passes
751 modified the module, 0 otherwise. See llvm::PassManager::run(Module&). */
752int LLVMRunPassManager(LLVMPassManagerRef PM, LLVMModuleRef M);
753
754/** Initializes all of the function passes scheduled in the function pass
755 manager. Returns 1 if any of the passes modified the module, 0 otherwise.
756 See llvm::FunctionPassManager::doInitialization. */
757int LLVMInitializeFunctionPassManager(LLVMPassManagerRef FPM);
758
759/** Executes all of the function passes scheduled in the function pass manager
760 on the provided function. Returns 1 if any of the passes modified the
761 function, false otherwise.
762 See llvm::FunctionPassManager::run(Function&). */
763int LLVMRunFunctionPassManager(LLVMPassManagerRef FPM, LLVMValueRef F);
764
765/** Finalizes all of the function passes scheduled in in the function pass
766 manager. Returns 1 if any of the passes modified the module, 0 otherwise.
767 See llvm::FunctionPassManager::doFinalization. */
768int LLVMFinalizeFunctionPassManager(LLVMPassManagerRef FPM);
769
770/** Frees the memory of a pass pipeline. For function pipelines, does not free
771 the module provider.
772 See llvm::PassManagerBase::~PassManagerBase. */
773void LLVMDisposePassManager(LLVMPassManagerRef PM);
774
775
Gordon Henriksen76a03742007-09-18 03:18:57 +0000776#ifdef __cplusplus
777}
Gordon Henriksen76a03742007-09-18 03:18:57 +0000778
Gordon Henriksen7330acd2007-10-05 23:59:36 +0000779namespace llvm {
Gordon Henriksen0a68fe22007-12-12 01:04:30 +0000780 class ModuleProvider;
Gordon Henriksen34eb6d82007-12-19 22:30:40 +0000781 class MemoryBuffer;
Gordon Henriksen96571492008-03-16 15:55:43 +0000782 class PassManagerBase;
Gordon Henriksen0a68fe22007-12-12 01:04:30 +0000783
Gordon Henriksen34eb6d82007-12-19 22:30:40 +0000784 #define DEFINE_SIMPLE_CONVERSION_FUNCTIONS(ty, ref) \
785 inline ty *unwrap(ref P) { \
786 return reinterpret_cast<ty*>(P); \
787 } \
788 \
789 inline ref wrap(const ty *P) { \
790 return reinterpret_cast<ref>(const_cast<ty*>(P)); \
791 }
Gordon Henriksen7330acd2007-10-05 23:59:36 +0000792
Gordon Henriksen878114b2008-03-16 04:20:44 +0000793 #define DEFINE_ISA_CONVERSION_FUNCTIONS(ty, ref) \
794 DEFINE_SIMPLE_CONVERSION_FUNCTIONS(ty, ref) \
795 \
796 template<typename T> \
797 inline T *unwrap(ref P) { \
798 return cast<T>(unwrap(P)); \
799 }
800
801 #define DEFINE_STDCXX_CONVERSION_FUNCTIONS(ty, ref) \
802 DEFINE_SIMPLE_CONVERSION_FUNCTIONS(ty, ref) \
803 \
804 template<typename T> \
805 inline T *unwrap(ref P) { \
806 T *Q = dynamic_cast<T*>(unwrap(P)); \
807 assert(Q && "Invalid cast!"); \
808 return Q; \
809 }
810
811 DEFINE_ISA_CONVERSION_FUNCTIONS (Type, LLVMTypeRef )
812 DEFINE_ISA_CONVERSION_FUNCTIONS (Value, LLVMValueRef )
Gordon Henriksen823f9732007-12-27 18:25:59 +0000813 DEFINE_SIMPLE_CONVERSION_FUNCTIONS(Module, LLVMModuleRef )
814 DEFINE_SIMPLE_CONVERSION_FUNCTIONS(BasicBlock, LLVMBasicBlockRef )
Eric Christopher59278832008-08-08 19:39:37 +0000815 DEFINE_SIMPLE_CONVERSION_FUNCTIONS(IRBuilder<>, LLVMBuilderRef )
Gordon Henriksen823f9732007-12-27 18:25:59 +0000816 DEFINE_SIMPLE_CONVERSION_FUNCTIONS(PATypeHolder, LLVMTypeHandleRef )
817 DEFINE_SIMPLE_CONVERSION_FUNCTIONS(ModuleProvider, LLVMModuleProviderRef)
818 DEFINE_SIMPLE_CONVERSION_FUNCTIONS(MemoryBuffer, LLVMMemoryBufferRef )
Gordon Henriksen878114b2008-03-16 04:20:44 +0000819 DEFINE_STDCXX_CONVERSION_FUNCTIONS(PassManagerBase, LLVMPassManagerRef )
Gordon Henriksen7330acd2007-10-05 23:59:36 +0000820
Gordon Henriksen878114b2008-03-16 04:20:44 +0000821 #undef DEFINE_STDCXX_CONVERSION_FUNCTIONS
822 #undef DEFINE_ISA_CONVERSION_FUNCTIONS
Gordon Henriksen34eb6d82007-12-19 22:30:40 +0000823 #undef DEFINE_SIMPLE_CONVERSION_FUNCTIONS
Gordon Henriksen7330acd2007-10-05 23:59:36 +0000824
Gordon Henriksen34eb6d82007-12-19 22:30:40 +0000825 /* Specialized opaque type conversions.
826 */
Gordon Henriksen7330acd2007-10-05 23:59:36 +0000827 inline Type **unwrap(LLVMTypeRef* Tys) {
828 return reinterpret_cast<Type**>(Tys);
829 }
830
Gordon Henriksen7330acd2007-10-05 23:59:36 +0000831 inline LLVMTypeRef *wrap(const Type **Tys) {
832 return reinterpret_cast<LLVMTypeRef*>(const_cast<Type**>(Tys));
833 }
834
Gordon Henriksen34eb6d82007-12-19 22:30:40 +0000835 /* Specialized opaque value conversions.
Gordon Henriksen7330acd2007-10-05 23:59:36 +0000836 */
Gordon Henriksen7330acd2007-10-05 23:59:36 +0000837 inline Value **unwrap(LLVMValueRef *Vals) {
838 return reinterpret_cast<Value**>(Vals);
839 }
840
841 template<typename T>
842 inline T **unwrap(LLVMValueRef *Vals, unsigned Length) {
843 #if DEBUG
844 for (LLVMValueRef *I = Vals, E = Vals + Length; I != E; ++I)
845 cast<T>(*I);
846 #endif
847 return reinterpret_cast<T**>(Vals);
848 }
849
Gordon Henriksen7330acd2007-10-05 23:59:36 +0000850 inline LLVMValueRef *wrap(const Value **Vals) {
851 return reinterpret_cast<LLVMValueRef*>(const_cast<Value**>(Vals));
852 }
Gordon Henriksen7330acd2007-10-05 23:59:36 +0000853}
854
855#endif /* !defined(__cplusplus) */
856
857#endif /* !defined(LLVM_C_CORE_H) */