blob: d2d88454d711ee2d11f2750044970ddddda5726e [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 */
Chris Lattner2dba0f02009-04-13 06:25:37 +0000118 LLVMAvailableExternallyLinkage,
Duncan Sands12da8ce2009-03-07 15:45:40 +0000119 LLVMLinkOnceAnyLinkage, /**< Keep one copy of function when linking (inline)*/
120 LLVMLinkOnceODRLinkage, /**< Same, but only replaced by something
121 equivalent. */
122 LLVMWeakAnyLinkage, /**< Keep one copy of function when linking (weak) */
123 LLVMWeakODRLinkage, /**< Same, but only replaced by something
124 equivalent. */
Gordon Henriksen4a4d7352007-12-30 17:46:33 +0000125 LLVMAppendingLinkage, /**< Special purpose, only applies to global arrays */
126 LLVMInternalLinkage, /**< Rename collisions when linking (static
127 functions) */
Duncan Sands12da8ce2009-03-07 15:45:40 +0000128 LLVMPrivateLinkage, /**< Like Internal, but omit from symbol table */
Gordon Henriksen4a4d7352007-12-30 17:46:33 +0000129 LLVMDLLImportLinkage, /**< Function to be imported from DLL */
130 LLVMDLLExportLinkage, /**< Function to be accessible from DLL */
Duncan Sandse2881052009-03-11 08:08:06 +0000131 LLVMExternalWeakLinkage,/**< ExternalWeak linkage description */
Duncan Sands12da8ce2009-03-07 15:45:40 +0000132 LLVMGhostLinkage, /**< Stand-in functions for streaming fns from
Gordon Henriksen4a4d7352007-12-30 17:46:33 +0000133 bitcode */
Duncan Sands4581beb2009-03-11 20:14:15 +0000134 LLVMCommonLinkage /**< Tentative definitions */
Gordon Henriksen76a03742007-09-18 03:18:57 +0000135} LLVMLinkage;
136
137typedef enum {
Gordon Henriksen4a4d7352007-12-30 17:46:33 +0000138 LLVMDefaultVisibility, /**< The GV is visible */
139 LLVMHiddenVisibility, /**< The GV is hidden */
140 LLVMProtectedVisibility /**< The GV is protected */
Gordon Henriksen76a03742007-09-18 03:18:57 +0000141} LLVMVisibility;
142
Gordon Henriksenc23b66c2007-09-26 20:56:12 +0000143typedef enum {
144 LLVMCCallConv = 0,
145 LLVMFastCallConv = 8,
146 LLVMColdCallConv = 9,
147 LLVMX86StdcallCallConv = 64,
148 LLVMX86FastcallCallConv = 65
149} LLVMCallConv;
150
151typedef enum {
Gordon Henriksen4a4d7352007-12-30 17:46:33 +0000152 LLVMIntEQ = 32, /**< equal */
153 LLVMIntNE, /**< not equal */
154 LLVMIntUGT, /**< unsigned greater than */
155 LLVMIntUGE, /**< unsigned greater or equal */
156 LLVMIntULT, /**< unsigned less than */
157 LLVMIntULE, /**< unsigned less or equal */
158 LLVMIntSGT, /**< signed greater than */
159 LLVMIntSGE, /**< signed greater or equal */
160 LLVMIntSLT, /**< signed less than */
161 LLVMIntSLE /**< signed less or equal */
Gordon Henriksenc23b66c2007-09-26 20:56:12 +0000162} LLVMIntPredicate;
163
164typedef enum {
Gordon Henriksen4a4d7352007-12-30 17:46:33 +0000165 LLVMRealPredicateFalse, /**< Always false (always folded) */
166 LLVMRealOEQ, /**< True if ordered and equal */
167 LLVMRealOGT, /**< True if ordered and greater than */
168 LLVMRealOGE, /**< True if ordered and greater than or equal */
169 LLVMRealOLT, /**< True if ordered and less than */
170 LLVMRealOLE, /**< True if ordered and less than or equal */
171 LLVMRealONE, /**< True if ordered and operands are unequal */
172 LLVMRealORD, /**< True if ordered (no nans) */
173 LLVMRealUNO, /**< True if unordered: isnan(X) | isnan(Y) */
174 LLVMRealUEQ, /**< True if unordered or equal */
175 LLVMRealUGT, /**< True if unordered or greater than */
176 LLVMRealUGE, /**< True if unordered, greater than, or equal */
177 LLVMRealULT, /**< True if unordered or less than */
178 LLVMRealULE, /**< True if unordered, less than, or equal */
179 LLVMRealUNE, /**< True if unordered or not equal */
180 LLVMRealPredicateTrue /**< Always true (always folded) */
Gordon Henriksenc23b66c2007-09-26 20:56:12 +0000181} LLVMRealPredicate;
182
Gordon Henriksen76a03742007-09-18 03:18:57 +0000183
Gordon Henriksen34eb6d82007-12-19 22:30:40 +0000184/*===-- Error handling ----------------------------------------------------===*/
185
186void LLVMDisposeMessage(char *Message);
187
188
Gordon Henriksen76a03742007-09-18 03:18:57 +0000189/*===-- Modules -----------------------------------------------------------===*/
190
191/* Create and destroy modules. */
Gordon Henriksena49d4352008-03-07 19:13:06 +0000192/** See llvm::Module::Module. */
Gordon Henriksen76a03742007-09-18 03:18:57 +0000193LLVMModuleRef LLVMModuleCreateWithName(const char *ModuleID);
Gordon Henriksena49d4352008-03-07 19:13:06 +0000194
195/** See llvm::Module::~Module. */
Gordon Henriksen76a03742007-09-18 03:18:57 +0000196void LLVMDisposeModule(LLVMModuleRef M);
197
Gordon Henriksena49d4352008-03-07 19:13:06 +0000198/** Data layout. See Module::getDataLayout. */
Gordon Henriksen05568bb2007-12-27 20:13:47 +0000199const char *LLVMGetDataLayout(LLVMModuleRef M);
200void LLVMSetDataLayout(LLVMModuleRef M, const char *Triple);
201
Gordon Henriksena49d4352008-03-07 19:13:06 +0000202/** Target triple. See Module::getTargetTriple. */
Gordon Henriksen05568bb2007-12-27 20:13:47 +0000203const char *LLVMGetTarget(LLVMModuleRef M);
204void LLVMSetTarget(LLVMModuleRef M, const char *Triple);
205
Gordon Henriksena49d4352008-03-07 19:13:06 +0000206/** See Module::addTypeName. */
Gordon Henriksen76a03742007-09-18 03:18:57 +0000207int LLVMAddTypeName(LLVMModuleRef M, const char *Name, LLVMTypeRef Ty);
Gordon Henriksenc23b66c2007-09-26 20:56:12 +0000208void LLVMDeleteTypeName(LLVMModuleRef M, const char *Name);
Gordon Henriksen76a03742007-09-18 03:18:57 +0000209
Gordon Henriksen6c6075e2008-03-14 23:58:56 +0000210/** See Module::dump. */
211void LLVMDumpModule(LLVMModuleRef M);
212
Gordon Henriksen76a03742007-09-18 03:18:57 +0000213
Gordon Henriksenc23b66c2007-09-26 20:56:12 +0000214/*===-- Types -------------------------------------------------------------===*/
Gordon Henriksen76a03742007-09-18 03:18:57 +0000215
216/* LLVM types conform to the following hierarchy:
217 *
218 * types:
219 * integer type
220 * real type
221 * function type
222 * sequence types:
223 * array type
224 * pointer type
225 * vector type
226 * void type
227 * label type
228 * opaque type
229 */
230
Gordon Henriksena49d4352008-03-07 19:13:06 +0000231/** See llvm::LLVMTypeKind::getTypeID. */
Gordon Henriksen76a03742007-09-18 03:18:57 +0000232LLVMTypeKind LLVMGetTypeKind(LLVMTypeRef Ty);
Gordon Henriksena49d4352008-03-07 19:13:06 +0000233
Gordon Henriksen76a03742007-09-18 03:18:57 +0000234/* Operations on integer types */
Gordon Henriksena735a9c2008-05-04 12:55:34 +0000235LLVMTypeRef LLVMInt1Type(void);
236LLVMTypeRef LLVMInt8Type(void);
237LLVMTypeRef LLVMInt16Type(void);
238LLVMTypeRef LLVMInt32Type(void);
239LLVMTypeRef LLVMInt64Type(void);
Gordon Henriksened7beaa2007-10-06 16:05:20 +0000240LLVMTypeRef LLVMIntType(unsigned NumBits);
Gordon Henriksenc23b66c2007-09-26 20:56:12 +0000241unsigned LLVMGetIntTypeWidth(LLVMTypeRef IntegerTy);
Gordon Henriksen76a03742007-09-18 03:18:57 +0000242
243/* Operations on real types */
Gordon Henriksena735a9c2008-05-04 12:55:34 +0000244LLVMTypeRef LLVMFloatType(void);
245LLVMTypeRef LLVMDoubleType(void);
246LLVMTypeRef LLVMX86FP80Type(void);
247LLVMTypeRef LLVMFP128Type(void);
248LLVMTypeRef LLVMPPCFP128Type(void);
Gordon Henriksen76a03742007-09-18 03:18:57 +0000249
250/* Operations on function types */
Gordon Henriksened7beaa2007-10-06 16:05:20 +0000251LLVMTypeRef LLVMFunctionType(LLVMTypeRef ReturnType,
252 LLVMTypeRef *ParamTypes, unsigned ParamCount,
253 int IsVarArg);
Gordon Henriksen76a03742007-09-18 03:18:57 +0000254int LLVMIsFunctionVarArg(LLVMTypeRef FunctionTy);
Gordon Henriksenc23b66c2007-09-26 20:56:12 +0000255LLVMTypeRef LLVMGetReturnType(LLVMTypeRef FunctionTy);
256unsigned LLVMCountParamTypes(LLVMTypeRef FunctionTy);
257void LLVMGetParamTypes(LLVMTypeRef FunctionTy, LLVMTypeRef *Dest);
Gordon Henriksen76a03742007-09-18 03:18:57 +0000258
259/* Operations on struct types */
Gordon Henriksened7beaa2007-10-06 16:05:20 +0000260LLVMTypeRef LLVMStructType(LLVMTypeRef *ElementTypes, unsigned ElementCount,
261 int Packed);
Gordon Henriksenc23b66c2007-09-26 20:56:12 +0000262unsigned LLVMCountStructElementTypes(LLVMTypeRef StructTy);
Gordon Henriksen76a03742007-09-18 03:18:57 +0000263void LLVMGetStructElementTypes(LLVMTypeRef StructTy, LLVMTypeRef *Dest);
264int LLVMIsPackedStruct(LLVMTypeRef StructTy);
265
266/* Operations on array, pointer, and vector types (sequence types) */
Gordon Henriksened7beaa2007-10-06 16:05:20 +0000267LLVMTypeRef LLVMArrayType(LLVMTypeRef ElementType, unsigned ElementCount);
Gordon Henriksen5a3fe032007-12-17 16:08:32 +0000268LLVMTypeRef LLVMPointerType(LLVMTypeRef ElementType, unsigned AddressSpace);
Gordon Henriksened7beaa2007-10-06 16:05:20 +0000269LLVMTypeRef LLVMVectorType(LLVMTypeRef ElementType, unsigned ElementCount);
Gordon Henriksen76a03742007-09-18 03:18:57 +0000270
271LLVMTypeRef LLVMGetElementType(LLVMTypeRef Ty);
272unsigned LLVMGetArrayLength(LLVMTypeRef ArrayTy);
Gordon Henriksen5a3fe032007-12-17 16:08:32 +0000273unsigned LLVMGetPointerAddressSpace(LLVMTypeRef PointerTy);
Gordon Henriksen76a03742007-09-18 03:18:57 +0000274unsigned LLVMGetVectorSize(LLVMTypeRef VectorTy);
275
276/* Operations on other types */
Gordon Henriksena735a9c2008-05-04 12:55:34 +0000277LLVMTypeRef LLVMVoidType(void);
278LLVMTypeRef LLVMLabelType(void);
279LLVMTypeRef LLVMOpaqueType(void);
Gordon Henriksen76a03742007-09-18 03:18:57 +0000280
Gordon Henriksenffb48762007-10-07 00:13:35 +0000281/* Operations on type handles */
282LLVMTypeHandleRef LLVMCreateTypeHandle(LLVMTypeRef PotentiallyAbstractTy);
283void LLVMRefineType(LLVMTypeRef AbstractTy, LLVMTypeRef ConcreteTy);
284LLVMTypeRef LLVMResolveTypeHandle(LLVMTypeHandleRef TypeHandle);
285void LLVMDisposeTypeHandle(LLVMTypeHandleRef TypeHandle);
286
Gordon Henriksen76a03742007-09-18 03:18:57 +0000287
288/*===-- Values ------------------------------------------------------------===*/
289
290/* The bulk of LLVM's object model consists of values, which comprise a very
291 * rich type hierarchy.
Gordon Henriksen76a03742007-09-18 03:18:57 +0000292 */
293
Gordon Henriksen29e38942008-12-19 18:39:45 +0000294#define LLVM_FOR_EACH_VALUE_SUBCLASS(macro) \
295 macro(Argument) \
296 macro(BasicBlock) \
297 macro(InlineAsm) \
298 macro(User) \
299 macro(Constant) \
300 macro(ConstantAggregateZero) \
301 macro(ConstantArray) \
302 macro(ConstantExpr) \
303 macro(ConstantFP) \
304 macro(ConstantInt) \
305 macro(ConstantPointerNull) \
306 macro(ConstantStruct) \
307 macro(ConstantVector) \
308 macro(GlobalValue) \
309 macro(Function) \
310 macro(GlobalAlias) \
311 macro(GlobalVariable) \
312 macro(UndefValue) \
313 macro(Instruction) \
314 macro(BinaryOperator) \
315 macro(CallInst) \
316 macro(IntrinsicInst) \
317 macro(DbgInfoIntrinsic) \
318 macro(DbgDeclareInst) \
319 macro(DbgFuncStartInst) \
320 macro(DbgRegionEndInst) \
321 macro(DbgRegionStartInst) \
322 macro(DbgStopPointInst) \
323 macro(EHSelectorInst) \
324 macro(MemIntrinsic) \
325 macro(MemCpyInst) \
326 macro(MemMoveInst) \
327 macro(MemSetInst) \
328 macro(CmpInst) \
329 macro(FCmpInst) \
330 macro(ICmpInst) \
331 macro(VFCmpInst) \
332 macro(VICmpInst) \
333 macro(ExtractElementInst) \
334 macro(GetElementPtrInst) \
335 macro(InsertElementInst) \
336 macro(InsertValueInst) \
337 macro(PHINode) \
338 macro(SelectInst) \
339 macro(ShuffleVectorInst) \
340 macro(StoreInst) \
341 macro(TerminatorInst) \
342 macro(BranchInst) \
343 macro(InvokeInst) \
344 macro(ReturnInst) \
345 macro(SwitchInst) \
346 macro(UnreachableInst) \
347 macro(UnwindInst) \
348 macro(UnaryInstruction) \
349 macro(AllocationInst) \
Gordon Henriksen05a868f2008-12-19 18:51:17 +0000350 macro(AllocaInst) \
351 macro(MallocInst) \
Gordon Henriksen29e38942008-12-19 18:39:45 +0000352 macro(CastInst) \
Gordon Henriksen05a868f2008-12-19 18:51:17 +0000353 macro(BitCastInst) \
354 macro(FPExtInst) \
355 macro(FPToSIInst) \
356 macro(FPToUIInst) \
357 macro(FPTruncInst) \
358 macro(IntToPtrInst) \
359 macro(PtrToIntInst) \
360 macro(SExtInst) \
361 macro(SIToFPInst) \
362 macro(TruncInst) \
363 macro(UIToFPInst) \
364 macro(ZExtInst) \
365 macro(ExtractValueInst) \
366 macro(FreeInst) \
367 macro(LoadInst) \
368 macro(VAArgInst)
Gordon Henriksen29e38942008-12-19 18:39:45 +0000369
Gordon Henriksen76a03742007-09-18 03:18:57 +0000370/* Operations on all values */
Gordon Henriksenc23b66c2007-09-26 20:56:12 +0000371LLVMTypeRef LLVMTypeOf(LLVMValueRef Val);
Gordon Henriksen76a03742007-09-18 03:18:57 +0000372const char *LLVMGetValueName(LLVMValueRef Val);
373void LLVMSetValueName(LLVMValueRef Val, const char *Name);
Gordon Henriksen1d0d24c2007-10-06 00:08:49 +0000374void LLVMDumpValue(LLVMValueRef Val);
Gordon Henriksen76a03742007-09-18 03:18:57 +0000375
Gordon Henriksen29e38942008-12-19 18:39:45 +0000376/* Conversion functions. Return the input value if it is an instance of the
377 specified class, otherwise NULL. See llvm::dyn_cast_or_null<>. */
378#define LLVM_DECLARE_VALUE_CAST(name) \
379 LLVMValueRef LLVMIsA##name(LLVMValueRef Val);
380LLVM_FOR_EACH_VALUE_SUBCLASS(LLVM_DECLARE_VALUE_CAST)
381
Gordon Henriksen76a03742007-09-18 03:18:57 +0000382/* Operations on constants of any type */
Gordon Henriksen1046c732007-10-06 15:11:06 +0000383LLVMValueRef LLVMConstNull(LLVMTypeRef Ty); /* all zeroes */
384LLVMValueRef LLVMConstAllOnes(LLVMTypeRef Ty); /* only for int/vector */
Gordon Henriksen76a03742007-09-18 03:18:57 +0000385LLVMValueRef LLVMGetUndef(LLVMTypeRef Ty);
Gordon Henriksendc88c062007-09-18 18:07:51 +0000386int LLVMIsConstant(LLVMValueRef Val);
Gordon Henriksen76a03742007-09-18 03:18:57 +0000387int LLVMIsNull(LLVMValueRef Val);
Gordon Henriksendc88c062007-09-18 18:07:51 +0000388int LLVMIsUndef(LLVMValueRef Val);
Gordon Henriksen76a03742007-09-18 03:18:57 +0000389
390/* Operations on scalar constants */
Gordon Henriksen1046c732007-10-06 15:11:06 +0000391LLVMValueRef LLVMConstInt(LLVMTypeRef IntTy, unsigned long long N,
392 int SignExtend);
393LLVMValueRef LLVMConstReal(LLVMTypeRef RealTy, double N);
Gordon Henriksen931e1212008-02-02 01:07:50 +0000394LLVMValueRef LLVMConstRealOfString(LLVMTypeRef RealTy, const char *Text);
Gordon Henriksen76a03742007-09-18 03:18:57 +0000395
396/* Operations on composite constants */
Gordon Henriksen1046c732007-10-06 15:11:06 +0000397LLVMValueRef LLVMConstString(const char *Str, unsigned Length,
398 int DontNullTerminate);
Gordon Henriksen2ad5aef2008-04-25 03:21:19 +0000399LLVMValueRef LLVMConstArray(LLVMTypeRef ElementTy,
Gordon Henriksen1046c732007-10-06 15:11:06 +0000400 LLVMValueRef *ConstantVals, unsigned Length);
401LLVMValueRef LLVMConstStruct(LLVMValueRef *ConstantVals, unsigned Count,
402 int packed);
403LLVMValueRef LLVMConstVector(LLVMValueRef *ScalarConstantVals, unsigned Size);
Gordon Henriksen76a03742007-09-18 03:18:57 +0000404
Gordon Henriksen7ce31762007-10-06 14:29:36 +0000405/* Constant expressions */
406LLVMValueRef LLVMSizeOf(LLVMTypeRef Ty);
407LLVMValueRef LLVMConstNeg(LLVMValueRef ConstantVal);
408LLVMValueRef LLVMConstNot(LLVMValueRef ConstantVal);
409LLVMValueRef LLVMConstAdd(LLVMValueRef LHSConstant, LLVMValueRef RHSConstant);
410LLVMValueRef LLVMConstSub(LLVMValueRef LHSConstant, LLVMValueRef RHSConstant);
411LLVMValueRef LLVMConstMul(LLVMValueRef LHSConstant, LLVMValueRef RHSConstant);
412LLVMValueRef LLVMConstUDiv(LLVMValueRef LHSConstant, LLVMValueRef RHSConstant);
413LLVMValueRef LLVMConstSDiv(LLVMValueRef LHSConstant, LLVMValueRef RHSConstant);
414LLVMValueRef LLVMConstFDiv(LLVMValueRef LHSConstant, LLVMValueRef RHSConstant);
415LLVMValueRef LLVMConstURem(LLVMValueRef LHSConstant, LLVMValueRef RHSConstant);
416LLVMValueRef LLVMConstSRem(LLVMValueRef LHSConstant, LLVMValueRef RHSConstant);
417LLVMValueRef LLVMConstFRem(LLVMValueRef LHSConstant, LLVMValueRef RHSConstant);
418LLVMValueRef LLVMConstAnd(LLVMValueRef LHSConstant, LLVMValueRef RHSConstant);
419LLVMValueRef LLVMConstOr(LLVMValueRef LHSConstant, LLVMValueRef RHSConstant);
420LLVMValueRef LLVMConstXor(LLVMValueRef LHSConstant, LLVMValueRef RHSConstant);
421LLVMValueRef LLVMConstICmp(LLVMIntPredicate Predicate,
422 LLVMValueRef LHSConstant, LLVMValueRef RHSConstant);
423LLVMValueRef LLVMConstFCmp(LLVMRealPredicate Predicate,
424 LLVMValueRef LHSConstant, LLVMValueRef RHSConstant);
425LLVMValueRef LLVMConstShl(LLVMValueRef LHSConstant, LLVMValueRef RHSConstant);
426LLVMValueRef LLVMConstLShr(LLVMValueRef LHSConstant, LLVMValueRef RHSConstant);
427LLVMValueRef LLVMConstAShr(LLVMValueRef LHSConstant, LLVMValueRef RHSConstant);
428LLVMValueRef LLVMConstGEP(LLVMValueRef ConstantVal,
429 LLVMValueRef *ConstantIndices, unsigned NumIndices);
430LLVMValueRef LLVMConstTrunc(LLVMValueRef ConstantVal, LLVMTypeRef ToType);
431LLVMValueRef LLVMConstSExt(LLVMValueRef ConstantVal, LLVMTypeRef ToType);
432LLVMValueRef LLVMConstZExt(LLVMValueRef ConstantVal, LLVMTypeRef ToType);
433LLVMValueRef LLVMConstFPTrunc(LLVMValueRef ConstantVal, LLVMTypeRef ToType);
434LLVMValueRef LLVMConstFPExt(LLVMValueRef ConstantVal, LLVMTypeRef ToType);
435LLVMValueRef LLVMConstUIToFP(LLVMValueRef ConstantVal, LLVMTypeRef ToType);
436LLVMValueRef LLVMConstSIToFP(LLVMValueRef ConstantVal, LLVMTypeRef ToType);
437LLVMValueRef LLVMConstFPToUI(LLVMValueRef ConstantVal, LLVMTypeRef ToType);
438LLVMValueRef LLVMConstFPToSI(LLVMValueRef ConstantVal, LLVMTypeRef ToType);
439LLVMValueRef LLVMConstPtrToInt(LLVMValueRef ConstantVal, LLVMTypeRef ToType);
440LLVMValueRef LLVMConstIntToPtr(LLVMValueRef ConstantVal, LLVMTypeRef ToType);
441LLVMValueRef LLVMConstBitCast(LLVMValueRef ConstantVal, LLVMTypeRef ToType);
442LLVMValueRef LLVMConstSelect(LLVMValueRef ConstantCondition,
443 LLVMValueRef ConstantIfTrue,
444 LLVMValueRef ConstantIfFalse);
445LLVMValueRef LLVMConstExtractElement(LLVMValueRef VectorConstant,
446 LLVMValueRef IndexConstant);
447LLVMValueRef LLVMConstInsertElement(LLVMValueRef VectorConstant,
448 LLVMValueRef ElementValueConstant,
449 LLVMValueRef IndexConstant);
450LLVMValueRef LLVMConstShuffleVector(LLVMValueRef VectorAConstant,
451 LLVMValueRef VectorBConstant,
452 LLVMValueRef MaskConstant);
Dan Gohmand5104a52008-11-03 22:55:43 +0000453LLVMValueRef LLVMConstExtractValue(LLVMValueRef AggConstant, unsigned *IdxList,
454 unsigned NumIdx);
455LLVMValueRef LLVMConstInsertValue(LLVMValueRef AggConstant,
456 LLVMValueRef ElementValueConstant,
457 unsigned *IdxList, unsigned NumIdx);
Chris Lattner3d1f5522008-12-17 21:39:50 +0000458LLVMValueRef LLVMConstInlineAsm(LLVMTypeRef Ty,
459 const char *AsmString, const char *Constraints,
460 int HasSideEffects);
Gordon Henriksen7ce31762007-10-06 14:29:36 +0000461
Gordon Henriksen76a03742007-09-18 03:18:57 +0000462/* Operations on global variables, functions, and aliases (globals) */
Gordon Henriksen265f7802008-03-19 01:11:35 +0000463LLVMModuleRef LLVMGetGlobalParent(LLVMValueRef Global);
Gordon Henriksen76a03742007-09-18 03:18:57 +0000464int LLVMIsDeclaration(LLVMValueRef Global);
465LLVMLinkage LLVMGetLinkage(LLVMValueRef Global);
466void LLVMSetLinkage(LLVMValueRef Global, LLVMLinkage Linkage);
467const char *LLVMGetSection(LLVMValueRef Global);
468void LLVMSetSection(LLVMValueRef Global, const char *Section);
469LLVMVisibility LLVMGetVisibility(LLVMValueRef Global);
470void LLVMSetVisibility(LLVMValueRef Global, LLVMVisibility Viz);
471unsigned LLVMGetAlignment(LLVMValueRef Global);
472void LLVMSetAlignment(LLVMValueRef Global, unsigned Bytes);
473
474/* Operations on global variables */
475LLVMValueRef LLVMAddGlobal(LLVMModuleRef M, LLVMTypeRef Ty, const char *Name);
Gordon Henriksen783f7bb2007-10-08 03:45:09 +0000476LLVMValueRef LLVMGetNamedGlobal(LLVMModuleRef M, const char *Name);
Gordon Henriksen07a45f42008-03-23 22:21:29 +0000477LLVMValueRef LLVMGetFirstGlobal(LLVMModuleRef M);
478LLVMValueRef LLVMGetLastGlobal(LLVMModuleRef M);
479LLVMValueRef LLVMGetNextGlobal(LLVMValueRef GlobalVar);
480LLVMValueRef LLVMGetPreviousGlobal(LLVMValueRef GlobalVar);
Gordon Henriksen76a03742007-09-18 03:18:57 +0000481void LLVMDeleteGlobal(LLVMValueRef GlobalVar);
Gordon Henriksen76a03742007-09-18 03:18:57 +0000482LLVMValueRef LLVMGetInitializer(LLVMValueRef GlobalVar);
483void LLVMSetInitializer(LLVMValueRef GlobalVar, LLVMValueRef ConstantVal);
484int LLVMIsThreadLocal(LLVMValueRef GlobalVar);
485void LLVMSetThreadLocal(LLVMValueRef GlobalVar, int IsThreadLocal);
Gordon Henriksen751ebf72007-10-07 17:31:42 +0000486int LLVMIsGlobalConstant(LLVMValueRef GlobalVar);
487void LLVMSetGlobalConstant(LLVMValueRef GlobalVar, int IsConstant);
Gordon Henriksen76a03742007-09-18 03:18:57 +0000488
Chris Lattner3d1f5522008-12-17 21:39:50 +0000489/* Operations on aliases */
490LLVMValueRef LLVMAddAlias(LLVMModuleRef M, LLVMTypeRef Ty, LLVMValueRef Aliasee,
491 const char *Name);
492
Gordon Henriksenc23b66c2007-09-26 20:56:12 +0000493/* Operations on functions */
494LLVMValueRef LLVMAddFunction(LLVMModuleRef M, const char *Name,
495 LLVMTypeRef FunctionTy);
Gordon Henriksen783f7bb2007-10-08 03:45:09 +0000496LLVMValueRef LLVMGetNamedFunction(LLVMModuleRef M, const char *Name);
Gordon Henriksen054817c2008-03-19 03:47:18 +0000497LLVMValueRef LLVMGetFirstFunction(LLVMModuleRef M);
498LLVMValueRef LLVMGetLastFunction(LLVMModuleRef M);
499LLVMValueRef LLVMGetNextFunction(LLVMValueRef Fn);
500LLVMValueRef LLVMGetPreviousFunction(LLVMValueRef Fn);
Gordon Henriksenc23b66c2007-09-26 20:56:12 +0000501void LLVMDeleteFunction(LLVMValueRef Fn);
Gordon Henriksenc23b66c2007-09-26 20:56:12 +0000502unsigned LLVMGetIntrinsicID(LLVMValueRef Fn);
503unsigned LLVMGetFunctionCallConv(LLVMValueRef Fn);
504void LLVMSetFunctionCallConv(LLVMValueRef Fn, unsigned CC);
Gordon Henriksend930f912008-08-17 18:44:35 +0000505const char *LLVMGetGC(LLVMValueRef Fn);
506void LLVMSetGC(LLVMValueRef Fn, const char *Name);
Duncan Sands7374a012009-05-06 12:21:17 +0000507void LLVMAddFunctionAttr(LLVMValueRef Fn, LLVMAttribute PA);
508void LLVMRemoveFunctionAttr(LLVMValueRef Fn, LLVMAttribute PA);
Gordon Henriksenc23b66c2007-09-26 20:56:12 +0000509
Gordon Henriksen265f7802008-03-19 01:11:35 +0000510/* Operations on parameters */
511unsigned LLVMCountParams(LLVMValueRef Fn);
512void LLVMGetParams(LLVMValueRef Fn, LLVMValueRef *Params);
513LLVMValueRef LLVMGetParam(LLVMValueRef Fn, unsigned Index);
514LLVMValueRef LLVMGetParamParent(LLVMValueRef Inst);
Gordon Henriksen07a45f42008-03-23 22:21:29 +0000515LLVMValueRef LLVMGetFirstParam(LLVMValueRef Fn);
516LLVMValueRef LLVMGetLastParam(LLVMValueRef Fn);
517LLVMValueRef LLVMGetNextParam(LLVMValueRef Arg);
518LLVMValueRef LLVMGetPreviousParam(LLVMValueRef Arg);
Devang Patel4c758ea2008-09-25 21:00:45 +0000519void LLVMAddAttribute(LLVMValueRef Arg, LLVMAttribute PA);
520void LLVMRemoveAttribute(LLVMValueRef Arg, LLVMAttribute PA);
Gordon Henriksen2d9cc212008-04-28 17:37:06 +0000521void LLVMSetParamAlignment(LLVMValueRef Arg, unsigned align);
Gordon Henriksen265f7802008-03-19 01:11:35 +0000522
Gordon Henriksenc23b66c2007-09-26 20:56:12 +0000523/* Operations on basic blocks */
Gordon Henriksen07a45f42008-03-23 22:21:29 +0000524LLVMValueRef LLVMBasicBlockAsValue(LLVMBasicBlockRef BB);
Gordon Henriksenc23b66c2007-09-26 20:56:12 +0000525int LLVMValueIsBasicBlock(LLVMValueRef Val);
526LLVMBasicBlockRef LLVMValueAsBasicBlock(LLVMValueRef Val);
Gordon Henriksen07a45f42008-03-23 22:21:29 +0000527LLVMValueRef LLVMGetBasicBlockParent(LLVMBasicBlockRef BB);
Gordon Henriksenc23b66c2007-09-26 20:56:12 +0000528unsigned LLVMCountBasicBlocks(LLVMValueRef Fn);
529void LLVMGetBasicBlocks(LLVMValueRef Fn, LLVMBasicBlockRef *BasicBlocks);
Gordon Henriksen054817c2008-03-19 03:47:18 +0000530LLVMBasicBlockRef LLVMGetFirstBasicBlock(LLVMValueRef Fn);
531LLVMBasicBlockRef LLVMGetLastBasicBlock(LLVMValueRef Fn);
532LLVMBasicBlockRef LLVMGetNextBasicBlock(LLVMBasicBlockRef BB);
533LLVMBasicBlockRef LLVMGetPreviousBasicBlock(LLVMBasicBlockRef BB);
Gordon Henriksenc23b66c2007-09-26 20:56:12 +0000534LLVMBasicBlockRef LLVMGetEntryBasicBlock(LLVMValueRef Fn);
535LLVMBasicBlockRef LLVMAppendBasicBlock(LLVMValueRef Fn, const char *Name);
536LLVMBasicBlockRef LLVMInsertBasicBlock(LLVMBasicBlockRef InsertBeforeBB,
537 const char *Name);
538void LLVMDeleteBasicBlock(LLVMBasicBlockRef BB);
539
Gordon Henriksen265f7802008-03-19 01:11:35 +0000540/* Operations on instructions */
541LLVMBasicBlockRef LLVMGetInstructionParent(LLVMValueRef Inst);
Gordon Henriksen054817c2008-03-19 03:47:18 +0000542LLVMValueRef LLVMGetFirstInstruction(LLVMBasicBlockRef BB);
543LLVMValueRef LLVMGetLastInstruction(LLVMBasicBlockRef BB);
544LLVMValueRef LLVMGetNextInstruction(LLVMValueRef Inst);
545LLVMValueRef LLVMGetPreviousInstruction(LLVMValueRef Inst);
Gordon Henriksen265f7802008-03-19 01:11:35 +0000546
Gordon Henriksen1158c532007-12-29 20:45:00 +0000547/* Operations on call sites */
548void LLVMSetInstructionCallConv(LLVMValueRef Instr, unsigned CC);
549unsigned LLVMGetInstructionCallConv(LLVMValueRef Instr);
Devang Patel4c758ea2008-09-25 21:00:45 +0000550void LLVMAddInstrAttribute(LLVMValueRef Instr, unsigned index, LLVMAttribute);
551void LLVMRemoveInstrAttribute(LLVMValueRef Instr, unsigned index,
552 LLVMAttribute);
Gordon Henriksen2d9cc212008-04-28 17:37:06 +0000553void LLVMSetInstrParamAlignment(LLVMValueRef Instr, unsigned index,
554 unsigned align);
Gordon Henriksen1158c532007-12-29 20:45:00 +0000555
Gordon Henrikseneeb65372008-08-30 16:34:54 +0000556/* Operations on call instructions (only) */
557int LLVMIsTailCall(LLVMValueRef CallInst);
558void LLVMSetTailCall(LLVMValueRef CallInst, int IsTailCall);
559
Gordon Henriksen44dd8fb2007-10-08 18:14:39 +0000560/* Operations on phi nodes */
561void LLVMAddIncoming(LLVMValueRef PhiNode, LLVMValueRef *IncomingValues,
562 LLVMBasicBlockRef *IncomingBlocks, unsigned Count);
563unsigned LLVMCountIncoming(LLVMValueRef PhiNode);
564LLVMValueRef LLVMGetIncomingValue(LLVMValueRef PhiNode, unsigned Index);
565LLVMBasicBlockRef LLVMGetIncomingBlock(LLVMValueRef PhiNode, unsigned Index);
Gordon Henriksenc23b66c2007-09-26 20:56:12 +0000566
567/*===-- Instruction builders ----------------------------------------------===*/
568
569/* An instruction builder represents a point within a basic block, and is the
570 * exclusive means of building instructions using the C interface.
571 */
572
Gordon Henriksena735a9c2008-05-04 12:55:34 +0000573LLVMBuilderRef LLVMCreateBuilder(void);
Gordon Henriksen054817c2008-03-19 03:47:18 +0000574void LLVMPositionBuilder(LLVMBuilderRef Builder, LLVMBasicBlockRef Block,
575 LLVMValueRef Instr);
Gordon Henriksenc23b66c2007-09-26 20:56:12 +0000576void LLVMPositionBuilderBefore(LLVMBuilderRef Builder, LLVMValueRef Instr);
577void LLVMPositionBuilderAtEnd(LLVMBuilderRef Builder, LLVMBasicBlockRef Block);
Gordon Henriksen265f7802008-03-19 01:11:35 +0000578LLVMBasicBlockRef LLVMGetInsertBlock(LLVMBuilderRef Builder);
Chris Lattner3d1f5522008-12-17 21:39:50 +0000579void LLVMClearInsertionPosition(LLVMBuilderRef Builder);
580void LLVMInsertIntoBuilder(LLVMBuilderRef Builder, LLVMValueRef Instr);
Gordon Henriksenc23b66c2007-09-26 20:56:12 +0000581void LLVMDisposeBuilder(LLVMBuilderRef Builder);
582
583/* Terminators */
584LLVMValueRef LLVMBuildRetVoid(LLVMBuilderRef);
585LLVMValueRef LLVMBuildRet(LLVMBuilderRef, LLVMValueRef V);
586LLVMValueRef LLVMBuildBr(LLVMBuilderRef, LLVMBasicBlockRef Dest);
587LLVMValueRef LLVMBuildCondBr(LLVMBuilderRef, LLVMValueRef If,
588 LLVMBasicBlockRef Then, LLVMBasicBlockRef Else);
589LLVMValueRef LLVMBuildSwitch(LLVMBuilderRef, LLVMValueRef V,
590 LLVMBasicBlockRef Else, unsigned NumCases);
591LLVMValueRef LLVMBuildInvoke(LLVMBuilderRef, LLVMValueRef Fn,
592 LLVMValueRef *Args, unsigned NumArgs,
593 LLVMBasicBlockRef Then, LLVMBasicBlockRef Catch,
594 const char *Name);
595LLVMValueRef LLVMBuildUnwind(LLVMBuilderRef);
596LLVMValueRef LLVMBuildUnreachable(LLVMBuilderRef);
597
Gordon Henriksen097102c2008-01-01 05:50:53 +0000598/* Add a case to the switch instruction */
599void LLVMAddCase(LLVMValueRef Switch, LLVMValueRef OnVal,
600 LLVMBasicBlockRef Dest);
601
Gordon Henriksenc23b66c2007-09-26 20:56:12 +0000602/* Arithmetic */
603LLVMValueRef LLVMBuildAdd(LLVMBuilderRef, LLVMValueRef LHS, LLVMValueRef RHS,
604 const char *Name);
605LLVMValueRef LLVMBuildSub(LLVMBuilderRef, LLVMValueRef LHS, LLVMValueRef RHS,
606 const char *Name);
607LLVMValueRef LLVMBuildMul(LLVMBuilderRef, LLVMValueRef LHS, LLVMValueRef RHS,
608 const char *Name);
609LLVMValueRef LLVMBuildUDiv(LLVMBuilderRef, LLVMValueRef LHS, LLVMValueRef RHS,
610 const char *Name);
611LLVMValueRef LLVMBuildSDiv(LLVMBuilderRef, LLVMValueRef LHS, LLVMValueRef RHS,
612 const char *Name);
613LLVMValueRef LLVMBuildFDiv(LLVMBuilderRef, LLVMValueRef LHS, LLVMValueRef RHS,
614 const char *Name);
615LLVMValueRef LLVMBuildURem(LLVMBuilderRef, LLVMValueRef LHS, LLVMValueRef RHS,
616 const char *Name);
617LLVMValueRef LLVMBuildSRem(LLVMBuilderRef, LLVMValueRef LHS, LLVMValueRef RHS,
618 const char *Name);
619LLVMValueRef LLVMBuildFRem(LLVMBuilderRef, LLVMValueRef LHS, LLVMValueRef RHS,
620 const char *Name);
621LLVMValueRef LLVMBuildShl(LLVMBuilderRef, LLVMValueRef LHS, LLVMValueRef RHS,
622 const char *Name);
623LLVMValueRef LLVMBuildLShr(LLVMBuilderRef, LLVMValueRef LHS, LLVMValueRef RHS,
624 const char *Name);
625LLVMValueRef LLVMBuildAShr(LLVMBuilderRef, LLVMValueRef LHS, LLVMValueRef RHS,
626 const char *Name);
627LLVMValueRef LLVMBuildAnd(LLVMBuilderRef, LLVMValueRef LHS, LLVMValueRef RHS,
628 const char *Name);
629LLVMValueRef LLVMBuildOr(LLVMBuilderRef, LLVMValueRef LHS, LLVMValueRef RHS,
630 const char *Name);
631LLVMValueRef LLVMBuildXor(LLVMBuilderRef, LLVMValueRef LHS, LLVMValueRef RHS,
632 const char *Name);
633LLVMValueRef LLVMBuildNeg(LLVMBuilderRef, LLVMValueRef V, const char *Name);
634LLVMValueRef LLVMBuildNot(LLVMBuilderRef, LLVMValueRef V, const char *Name);
635
636/* Memory */
637LLVMValueRef LLVMBuildMalloc(LLVMBuilderRef, LLVMTypeRef Ty, const char *Name);
638LLVMValueRef LLVMBuildArrayMalloc(LLVMBuilderRef, LLVMTypeRef Ty,
639 LLVMValueRef Val, const char *Name);
640LLVMValueRef LLVMBuildAlloca(LLVMBuilderRef, LLVMTypeRef Ty, const char *Name);
641LLVMValueRef LLVMBuildArrayAlloca(LLVMBuilderRef, LLVMTypeRef Ty,
642 LLVMValueRef Val, const char *Name);
643LLVMValueRef LLVMBuildFree(LLVMBuilderRef, LLVMValueRef PointerVal);
644LLVMValueRef LLVMBuildLoad(LLVMBuilderRef, LLVMValueRef PointerVal,
645 const char *Name);
646LLVMValueRef LLVMBuildStore(LLVMBuilderRef, LLVMValueRef Val, LLVMValueRef Ptr);
647LLVMValueRef LLVMBuildGEP(LLVMBuilderRef B, LLVMValueRef Pointer,
648 LLVMValueRef *Indices, unsigned NumIndices,
649 const char *Name);
650
651/* Casts */
652LLVMValueRef LLVMBuildTrunc(LLVMBuilderRef, LLVMValueRef Val,
653 LLVMTypeRef DestTy, const char *Name);
654LLVMValueRef LLVMBuildZExt(LLVMBuilderRef, LLVMValueRef Val,
655 LLVMTypeRef DestTy, const char *Name);
656LLVMValueRef LLVMBuildSExt(LLVMBuilderRef, LLVMValueRef Val,
657 LLVMTypeRef DestTy, const char *Name);
658LLVMValueRef LLVMBuildFPToUI(LLVMBuilderRef, LLVMValueRef Val,
659 LLVMTypeRef DestTy, const char *Name);
660LLVMValueRef LLVMBuildFPToSI(LLVMBuilderRef, LLVMValueRef Val,
661 LLVMTypeRef DestTy, const char *Name);
662LLVMValueRef LLVMBuildUIToFP(LLVMBuilderRef, LLVMValueRef Val,
663 LLVMTypeRef DestTy, const char *Name);
664LLVMValueRef LLVMBuildSIToFP(LLVMBuilderRef, LLVMValueRef Val,
665 LLVMTypeRef DestTy, const char *Name);
666LLVMValueRef LLVMBuildFPTrunc(LLVMBuilderRef, LLVMValueRef Val,
667 LLVMTypeRef DestTy, const char *Name);
668LLVMValueRef LLVMBuildFPExt(LLVMBuilderRef, LLVMValueRef Val,
669 LLVMTypeRef DestTy, const char *Name);
670LLVMValueRef LLVMBuildPtrToInt(LLVMBuilderRef, LLVMValueRef Val,
671 LLVMTypeRef DestTy, const char *Name);
672LLVMValueRef LLVMBuildIntToPtr(LLVMBuilderRef, LLVMValueRef Val,
673 LLVMTypeRef DestTy, const char *Name);
674LLVMValueRef LLVMBuildBitCast(LLVMBuilderRef, LLVMValueRef Val,
675 LLVMTypeRef DestTy, const char *Name);
676
677/* Comparisons */
678LLVMValueRef LLVMBuildICmp(LLVMBuilderRef, LLVMIntPredicate Op,
679 LLVMValueRef LHS, LLVMValueRef RHS,
680 const char *Name);
681LLVMValueRef LLVMBuildFCmp(LLVMBuilderRef, LLVMRealPredicate Op,
682 LLVMValueRef LHS, LLVMValueRef RHS,
683 const char *Name);
684
685/* Miscellaneous instructions */
686LLVMValueRef LLVMBuildPhi(LLVMBuilderRef, LLVMTypeRef Ty, const char *Name);
687LLVMValueRef LLVMBuildCall(LLVMBuilderRef, LLVMValueRef Fn,
688 LLVMValueRef *Args, unsigned NumArgs,
689 const char *Name);
690LLVMValueRef LLVMBuildSelect(LLVMBuilderRef, LLVMValueRef If,
691 LLVMValueRef Then, LLVMValueRef Else,
692 const char *Name);
693LLVMValueRef LLVMBuildVAArg(LLVMBuilderRef, LLVMValueRef List, LLVMTypeRef Ty,
694 const char *Name);
695LLVMValueRef LLVMBuildExtractElement(LLVMBuilderRef, LLVMValueRef VecVal,
696 LLVMValueRef Index, const char *Name);
697LLVMValueRef LLVMBuildInsertElement(LLVMBuilderRef, LLVMValueRef VecVal,
698 LLVMValueRef EltVal, LLVMValueRef Index,
699 const char *Name);
700LLVMValueRef LLVMBuildShuffleVector(LLVMBuilderRef, LLVMValueRef V1,
701 LLVMValueRef V2, LLVMValueRef Mask,
702 const char *Name);
Dan Gohmand5104a52008-11-03 22:55:43 +0000703LLVMValueRef LLVMBuildExtractValue(LLVMBuilderRef, LLVMValueRef AggVal,
704 unsigned Index, const char *Name);
705LLVMValueRef LLVMBuildInsertValue(LLVMBuilderRef, LLVMValueRef AggVal,
706 LLVMValueRef EltVal, unsigned Index,
707 const char *Name);
Gordon Henriksen76a03742007-09-18 03:18:57 +0000708
Gordon Henriksen34eb6d82007-12-19 22:30:40 +0000709
Gordon Henriksen0a68fe22007-12-12 01:04:30 +0000710/*===-- Module providers --------------------------------------------------===*/
711
712/* Encapsulates the module M in a module provider, taking ownership of the
713 * module.
714 * See the constructor llvm::ExistingModuleProvider::ExistingModuleProvider.
715 */
716LLVMModuleProviderRef
717LLVMCreateModuleProviderForExistingModule(LLVMModuleRef M);
718
719/* Destroys the module provider MP as well as the contained module.
720 * See the destructor llvm::ModuleProvider::~ModuleProvider.
721 */
722void LLVMDisposeModuleProvider(LLVMModuleProviderRef MP);
723
Gordon Henriksen34eb6d82007-12-19 22:30:40 +0000724
725/*===-- Memory buffers ----------------------------------------------------===*/
726
727int LLVMCreateMemoryBufferWithContentsOfFile(const char *Path,
728 LLVMMemoryBufferRef *OutMemBuf,
729 char **OutMessage);
730int LLVMCreateMemoryBufferWithSTDIN(LLVMMemoryBufferRef *OutMemBuf,
731 char **OutMessage);
732void LLVMDisposeMemoryBuffer(LLVMMemoryBufferRef MemBuf);
733
Gordon Henriksen878114b2008-03-16 04:20:44 +0000734
735/*===-- Pass Managers -----------------------------------------------------===*/
736
737/** Constructs a new whole-module pass pipeline. This type of pipeline is
738 suitable for link-time optimization and whole-module transformations.
739 See llvm::PassManager::PassManager. */
Gordon Henriksena735a9c2008-05-04 12:55:34 +0000740LLVMPassManagerRef LLVMCreatePassManager(void);
Gordon Henriksen878114b2008-03-16 04:20:44 +0000741
742/** Constructs a new function-by-function pass pipeline over the module
743 provider. It does not take ownership of the module provider. This type of
744 pipeline is suitable for code generation and JIT compilation tasks.
745 See llvm::FunctionPassManager::FunctionPassManager. */
746LLVMPassManagerRef LLVMCreateFunctionPassManager(LLVMModuleProviderRef MP);
747
748/** Initializes, executes on the provided module, and finalizes all of the
749 passes scheduled in the pass manager. Returns 1 if any of the passes
750 modified the module, 0 otherwise. See llvm::PassManager::run(Module&). */
751int LLVMRunPassManager(LLVMPassManagerRef PM, LLVMModuleRef M);
752
753/** Initializes all of the function passes scheduled in the function pass
754 manager. Returns 1 if any of the passes modified the module, 0 otherwise.
755 See llvm::FunctionPassManager::doInitialization. */
756int LLVMInitializeFunctionPassManager(LLVMPassManagerRef FPM);
757
758/** Executes all of the function passes scheduled in the function pass manager
759 on the provided function. Returns 1 if any of the passes modified the
760 function, false otherwise.
761 See llvm::FunctionPassManager::run(Function&). */
762int LLVMRunFunctionPassManager(LLVMPassManagerRef FPM, LLVMValueRef F);
763
764/** Finalizes all of the function passes scheduled in in the function pass
765 manager. Returns 1 if any of the passes modified the module, 0 otherwise.
766 See llvm::FunctionPassManager::doFinalization. */
767int LLVMFinalizeFunctionPassManager(LLVMPassManagerRef FPM);
768
769/** Frees the memory of a pass pipeline. For function pipelines, does not free
770 the module provider.
771 See llvm::PassManagerBase::~PassManagerBase. */
772void LLVMDisposePassManager(LLVMPassManagerRef PM);
773
774
Gordon Henriksen76a03742007-09-18 03:18:57 +0000775#ifdef __cplusplus
776}
Gordon Henriksen76a03742007-09-18 03:18:57 +0000777
Gordon Henriksen7330acd2007-10-05 23:59:36 +0000778namespace llvm {
Gordon Henriksen0a68fe22007-12-12 01:04:30 +0000779 class ModuleProvider;
Gordon Henriksen34eb6d82007-12-19 22:30:40 +0000780 class MemoryBuffer;
Gordon Henriksen96571492008-03-16 15:55:43 +0000781 class PassManagerBase;
Gordon Henriksen0a68fe22007-12-12 01:04:30 +0000782
Gordon Henriksen34eb6d82007-12-19 22:30:40 +0000783 #define DEFINE_SIMPLE_CONVERSION_FUNCTIONS(ty, ref) \
784 inline ty *unwrap(ref P) { \
785 return reinterpret_cast<ty*>(P); \
786 } \
787 \
788 inline ref wrap(const ty *P) { \
789 return reinterpret_cast<ref>(const_cast<ty*>(P)); \
790 }
Gordon Henriksen7330acd2007-10-05 23:59:36 +0000791
Gordon Henriksen878114b2008-03-16 04:20:44 +0000792 #define DEFINE_ISA_CONVERSION_FUNCTIONS(ty, ref) \
793 DEFINE_SIMPLE_CONVERSION_FUNCTIONS(ty, ref) \
794 \
795 template<typename T> \
796 inline T *unwrap(ref P) { \
797 return cast<T>(unwrap(P)); \
798 }
799
800 #define DEFINE_STDCXX_CONVERSION_FUNCTIONS(ty, ref) \
801 DEFINE_SIMPLE_CONVERSION_FUNCTIONS(ty, ref) \
802 \
803 template<typename T> \
804 inline T *unwrap(ref P) { \
805 T *Q = dynamic_cast<T*>(unwrap(P)); \
806 assert(Q && "Invalid cast!"); \
807 return Q; \
808 }
809
810 DEFINE_ISA_CONVERSION_FUNCTIONS (Type, LLVMTypeRef )
811 DEFINE_ISA_CONVERSION_FUNCTIONS (Value, LLVMValueRef )
Gordon Henriksen823f9732007-12-27 18:25:59 +0000812 DEFINE_SIMPLE_CONVERSION_FUNCTIONS(Module, LLVMModuleRef )
813 DEFINE_SIMPLE_CONVERSION_FUNCTIONS(BasicBlock, LLVMBasicBlockRef )
Eric Christopher59278832008-08-08 19:39:37 +0000814 DEFINE_SIMPLE_CONVERSION_FUNCTIONS(IRBuilder<>, LLVMBuilderRef )
Gordon Henriksen823f9732007-12-27 18:25:59 +0000815 DEFINE_SIMPLE_CONVERSION_FUNCTIONS(PATypeHolder, LLVMTypeHandleRef )
816 DEFINE_SIMPLE_CONVERSION_FUNCTIONS(ModuleProvider, LLVMModuleProviderRef)
817 DEFINE_SIMPLE_CONVERSION_FUNCTIONS(MemoryBuffer, LLVMMemoryBufferRef )
Gordon Henriksen878114b2008-03-16 04:20:44 +0000818 DEFINE_STDCXX_CONVERSION_FUNCTIONS(PassManagerBase, LLVMPassManagerRef )
Gordon Henriksen7330acd2007-10-05 23:59:36 +0000819
Gordon Henriksen878114b2008-03-16 04:20:44 +0000820 #undef DEFINE_STDCXX_CONVERSION_FUNCTIONS
821 #undef DEFINE_ISA_CONVERSION_FUNCTIONS
Gordon Henriksen34eb6d82007-12-19 22:30:40 +0000822 #undef DEFINE_SIMPLE_CONVERSION_FUNCTIONS
Gordon Henriksen7330acd2007-10-05 23:59:36 +0000823
Gordon Henriksen34eb6d82007-12-19 22:30:40 +0000824 /* Specialized opaque type conversions.
825 */
Gordon Henriksen7330acd2007-10-05 23:59:36 +0000826 inline Type **unwrap(LLVMTypeRef* Tys) {
827 return reinterpret_cast<Type**>(Tys);
828 }
829
Gordon Henriksen7330acd2007-10-05 23:59:36 +0000830 inline LLVMTypeRef *wrap(const Type **Tys) {
831 return reinterpret_cast<LLVMTypeRef*>(const_cast<Type**>(Tys));
832 }
833
Gordon Henriksen34eb6d82007-12-19 22:30:40 +0000834 /* Specialized opaque value conversions.
Gordon Henriksen7330acd2007-10-05 23:59:36 +0000835 */
Gordon Henriksen7330acd2007-10-05 23:59:36 +0000836 inline Value **unwrap(LLVMValueRef *Vals) {
837 return reinterpret_cast<Value**>(Vals);
838 }
839
840 template<typename T>
841 inline T **unwrap(LLVMValueRef *Vals, unsigned Length) {
842 #if DEBUG
843 for (LLVMValueRef *I = Vals, E = Vals + Length; I != E; ++I)
844 cast<T>(*I);
845 #endif
846 return reinterpret_cast<T**>(Vals);
847 }
848
Gordon Henriksen7330acd2007-10-05 23:59:36 +0000849 inline LLVMValueRef *wrap(const Value **Vals) {
850 return reinterpret_cast<LLVMValueRef*>(const_cast<Value**>(Vals));
851 }
Gordon Henriksen7330acd2007-10-05 23:59:36 +0000852}
853
854#endif /* !defined(__cplusplus) */
855
856#endif /* !defined(LLVM_C_CORE_H) */