blob: 3d5be5326097290e5142b4cbe637c4fcb1254fe9 [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);
Gordon Henriksenc23b66c2007-09-26 20:56:12 +0000507
Gordon Henriksen265f7802008-03-19 01:11:35 +0000508/* Operations on parameters */
509unsigned LLVMCountParams(LLVMValueRef Fn);
510void LLVMGetParams(LLVMValueRef Fn, LLVMValueRef *Params);
511LLVMValueRef LLVMGetParam(LLVMValueRef Fn, unsigned Index);
512LLVMValueRef LLVMGetParamParent(LLVMValueRef Inst);
Gordon Henriksen07a45f42008-03-23 22:21:29 +0000513LLVMValueRef LLVMGetFirstParam(LLVMValueRef Fn);
514LLVMValueRef LLVMGetLastParam(LLVMValueRef Fn);
515LLVMValueRef LLVMGetNextParam(LLVMValueRef Arg);
516LLVMValueRef LLVMGetPreviousParam(LLVMValueRef Arg);
Devang Patel4c758ea2008-09-25 21:00:45 +0000517void LLVMAddAttribute(LLVMValueRef Arg, LLVMAttribute PA);
518void LLVMRemoveAttribute(LLVMValueRef Arg, LLVMAttribute PA);
Gordon Henriksen2d9cc212008-04-28 17:37:06 +0000519void LLVMSetParamAlignment(LLVMValueRef Arg, unsigned align);
Gordon Henriksen265f7802008-03-19 01:11:35 +0000520
Gordon Henriksenc23b66c2007-09-26 20:56:12 +0000521/* Operations on basic blocks */
Gordon Henriksen07a45f42008-03-23 22:21:29 +0000522LLVMValueRef LLVMBasicBlockAsValue(LLVMBasicBlockRef BB);
Gordon Henriksenc23b66c2007-09-26 20:56:12 +0000523int LLVMValueIsBasicBlock(LLVMValueRef Val);
524LLVMBasicBlockRef LLVMValueAsBasicBlock(LLVMValueRef Val);
Gordon Henriksen07a45f42008-03-23 22:21:29 +0000525LLVMValueRef LLVMGetBasicBlockParent(LLVMBasicBlockRef BB);
Gordon Henriksenc23b66c2007-09-26 20:56:12 +0000526unsigned LLVMCountBasicBlocks(LLVMValueRef Fn);
527void LLVMGetBasicBlocks(LLVMValueRef Fn, LLVMBasicBlockRef *BasicBlocks);
Gordon Henriksen054817c2008-03-19 03:47:18 +0000528LLVMBasicBlockRef LLVMGetFirstBasicBlock(LLVMValueRef Fn);
529LLVMBasicBlockRef LLVMGetLastBasicBlock(LLVMValueRef Fn);
530LLVMBasicBlockRef LLVMGetNextBasicBlock(LLVMBasicBlockRef BB);
531LLVMBasicBlockRef LLVMGetPreviousBasicBlock(LLVMBasicBlockRef BB);
Gordon Henriksenc23b66c2007-09-26 20:56:12 +0000532LLVMBasicBlockRef LLVMGetEntryBasicBlock(LLVMValueRef Fn);
533LLVMBasicBlockRef LLVMAppendBasicBlock(LLVMValueRef Fn, const char *Name);
534LLVMBasicBlockRef LLVMInsertBasicBlock(LLVMBasicBlockRef InsertBeforeBB,
535 const char *Name);
536void LLVMDeleteBasicBlock(LLVMBasicBlockRef BB);
537
Gordon Henriksen265f7802008-03-19 01:11:35 +0000538/* Operations on instructions */
539LLVMBasicBlockRef LLVMGetInstructionParent(LLVMValueRef Inst);
Gordon Henriksen054817c2008-03-19 03:47:18 +0000540LLVMValueRef LLVMGetFirstInstruction(LLVMBasicBlockRef BB);
541LLVMValueRef LLVMGetLastInstruction(LLVMBasicBlockRef BB);
542LLVMValueRef LLVMGetNextInstruction(LLVMValueRef Inst);
543LLVMValueRef LLVMGetPreviousInstruction(LLVMValueRef Inst);
Gordon Henriksen265f7802008-03-19 01:11:35 +0000544
Gordon Henriksen1158c532007-12-29 20:45:00 +0000545/* Operations on call sites */
546void LLVMSetInstructionCallConv(LLVMValueRef Instr, unsigned CC);
547unsigned LLVMGetInstructionCallConv(LLVMValueRef Instr);
Devang Patel4c758ea2008-09-25 21:00:45 +0000548void LLVMAddInstrAttribute(LLVMValueRef Instr, unsigned index, LLVMAttribute);
549void LLVMRemoveInstrAttribute(LLVMValueRef Instr, unsigned index,
550 LLVMAttribute);
Gordon Henriksen2d9cc212008-04-28 17:37:06 +0000551void LLVMSetInstrParamAlignment(LLVMValueRef Instr, unsigned index,
552 unsigned align);
Gordon Henriksen1158c532007-12-29 20:45:00 +0000553
Gordon Henrikseneeb65372008-08-30 16:34:54 +0000554/* Operations on call instructions (only) */
555int LLVMIsTailCall(LLVMValueRef CallInst);
556void LLVMSetTailCall(LLVMValueRef CallInst, int IsTailCall);
557
Gordon Henriksen44dd8fb2007-10-08 18:14:39 +0000558/* Operations on phi nodes */
559void LLVMAddIncoming(LLVMValueRef PhiNode, LLVMValueRef *IncomingValues,
560 LLVMBasicBlockRef *IncomingBlocks, unsigned Count);
561unsigned LLVMCountIncoming(LLVMValueRef PhiNode);
562LLVMValueRef LLVMGetIncomingValue(LLVMValueRef PhiNode, unsigned Index);
563LLVMBasicBlockRef LLVMGetIncomingBlock(LLVMValueRef PhiNode, unsigned Index);
Gordon Henriksenc23b66c2007-09-26 20:56:12 +0000564
565/*===-- Instruction builders ----------------------------------------------===*/
566
567/* An instruction builder represents a point within a basic block, and is the
568 * exclusive means of building instructions using the C interface.
569 */
570
Gordon Henriksena735a9c2008-05-04 12:55:34 +0000571LLVMBuilderRef LLVMCreateBuilder(void);
Gordon Henriksen054817c2008-03-19 03:47:18 +0000572void LLVMPositionBuilder(LLVMBuilderRef Builder, LLVMBasicBlockRef Block,
573 LLVMValueRef Instr);
Gordon Henriksenc23b66c2007-09-26 20:56:12 +0000574void LLVMPositionBuilderBefore(LLVMBuilderRef Builder, LLVMValueRef Instr);
575void LLVMPositionBuilderAtEnd(LLVMBuilderRef Builder, LLVMBasicBlockRef Block);
Gordon Henriksen265f7802008-03-19 01:11:35 +0000576LLVMBasicBlockRef LLVMGetInsertBlock(LLVMBuilderRef Builder);
Chris Lattner3d1f5522008-12-17 21:39:50 +0000577void LLVMClearInsertionPosition(LLVMBuilderRef Builder);
578void LLVMInsertIntoBuilder(LLVMBuilderRef Builder, LLVMValueRef Instr);
Gordon Henriksenc23b66c2007-09-26 20:56:12 +0000579void LLVMDisposeBuilder(LLVMBuilderRef Builder);
580
581/* Terminators */
582LLVMValueRef LLVMBuildRetVoid(LLVMBuilderRef);
583LLVMValueRef LLVMBuildRet(LLVMBuilderRef, LLVMValueRef V);
584LLVMValueRef LLVMBuildBr(LLVMBuilderRef, LLVMBasicBlockRef Dest);
585LLVMValueRef LLVMBuildCondBr(LLVMBuilderRef, LLVMValueRef If,
586 LLVMBasicBlockRef Then, LLVMBasicBlockRef Else);
587LLVMValueRef LLVMBuildSwitch(LLVMBuilderRef, LLVMValueRef V,
588 LLVMBasicBlockRef Else, unsigned NumCases);
589LLVMValueRef LLVMBuildInvoke(LLVMBuilderRef, LLVMValueRef Fn,
590 LLVMValueRef *Args, unsigned NumArgs,
591 LLVMBasicBlockRef Then, LLVMBasicBlockRef Catch,
592 const char *Name);
593LLVMValueRef LLVMBuildUnwind(LLVMBuilderRef);
594LLVMValueRef LLVMBuildUnreachable(LLVMBuilderRef);
595
Gordon Henriksen097102c2008-01-01 05:50:53 +0000596/* Add a case to the switch instruction */
597void LLVMAddCase(LLVMValueRef Switch, LLVMValueRef OnVal,
598 LLVMBasicBlockRef Dest);
599
Gordon Henriksenc23b66c2007-09-26 20:56:12 +0000600/* Arithmetic */
601LLVMValueRef LLVMBuildAdd(LLVMBuilderRef, LLVMValueRef LHS, LLVMValueRef RHS,
602 const char *Name);
603LLVMValueRef LLVMBuildSub(LLVMBuilderRef, LLVMValueRef LHS, LLVMValueRef RHS,
604 const char *Name);
605LLVMValueRef LLVMBuildMul(LLVMBuilderRef, LLVMValueRef LHS, LLVMValueRef RHS,
606 const char *Name);
607LLVMValueRef LLVMBuildUDiv(LLVMBuilderRef, LLVMValueRef LHS, LLVMValueRef RHS,
608 const char *Name);
609LLVMValueRef LLVMBuildSDiv(LLVMBuilderRef, LLVMValueRef LHS, LLVMValueRef RHS,
610 const char *Name);
611LLVMValueRef LLVMBuildFDiv(LLVMBuilderRef, LLVMValueRef LHS, LLVMValueRef RHS,
612 const char *Name);
613LLVMValueRef LLVMBuildURem(LLVMBuilderRef, LLVMValueRef LHS, LLVMValueRef RHS,
614 const char *Name);
615LLVMValueRef LLVMBuildSRem(LLVMBuilderRef, LLVMValueRef LHS, LLVMValueRef RHS,
616 const char *Name);
617LLVMValueRef LLVMBuildFRem(LLVMBuilderRef, LLVMValueRef LHS, LLVMValueRef RHS,
618 const char *Name);
619LLVMValueRef LLVMBuildShl(LLVMBuilderRef, LLVMValueRef LHS, LLVMValueRef RHS,
620 const char *Name);
621LLVMValueRef LLVMBuildLShr(LLVMBuilderRef, LLVMValueRef LHS, LLVMValueRef RHS,
622 const char *Name);
623LLVMValueRef LLVMBuildAShr(LLVMBuilderRef, LLVMValueRef LHS, LLVMValueRef RHS,
624 const char *Name);
625LLVMValueRef LLVMBuildAnd(LLVMBuilderRef, LLVMValueRef LHS, LLVMValueRef RHS,
626 const char *Name);
627LLVMValueRef LLVMBuildOr(LLVMBuilderRef, LLVMValueRef LHS, LLVMValueRef RHS,
628 const char *Name);
629LLVMValueRef LLVMBuildXor(LLVMBuilderRef, LLVMValueRef LHS, LLVMValueRef RHS,
630 const char *Name);
631LLVMValueRef LLVMBuildNeg(LLVMBuilderRef, LLVMValueRef V, const char *Name);
632LLVMValueRef LLVMBuildNot(LLVMBuilderRef, LLVMValueRef V, const char *Name);
633
634/* Memory */
635LLVMValueRef LLVMBuildMalloc(LLVMBuilderRef, LLVMTypeRef Ty, const char *Name);
636LLVMValueRef LLVMBuildArrayMalloc(LLVMBuilderRef, LLVMTypeRef Ty,
637 LLVMValueRef Val, const char *Name);
638LLVMValueRef LLVMBuildAlloca(LLVMBuilderRef, LLVMTypeRef Ty, const char *Name);
639LLVMValueRef LLVMBuildArrayAlloca(LLVMBuilderRef, LLVMTypeRef Ty,
640 LLVMValueRef Val, const char *Name);
641LLVMValueRef LLVMBuildFree(LLVMBuilderRef, LLVMValueRef PointerVal);
642LLVMValueRef LLVMBuildLoad(LLVMBuilderRef, LLVMValueRef PointerVal,
643 const char *Name);
644LLVMValueRef LLVMBuildStore(LLVMBuilderRef, LLVMValueRef Val, LLVMValueRef Ptr);
645LLVMValueRef LLVMBuildGEP(LLVMBuilderRef B, LLVMValueRef Pointer,
646 LLVMValueRef *Indices, unsigned NumIndices,
647 const char *Name);
648
649/* Casts */
650LLVMValueRef LLVMBuildTrunc(LLVMBuilderRef, LLVMValueRef Val,
651 LLVMTypeRef DestTy, const char *Name);
652LLVMValueRef LLVMBuildZExt(LLVMBuilderRef, LLVMValueRef Val,
653 LLVMTypeRef DestTy, const char *Name);
654LLVMValueRef LLVMBuildSExt(LLVMBuilderRef, LLVMValueRef Val,
655 LLVMTypeRef DestTy, const char *Name);
656LLVMValueRef LLVMBuildFPToUI(LLVMBuilderRef, LLVMValueRef Val,
657 LLVMTypeRef DestTy, const char *Name);
658LLVMValueRef LLVMBuildFPToSI(LLVMBuilderRef, LLVMValueRef Val,
659 LLVMTypeRef DestTy, const char *Name);
660LLVMValueRef LLVMBuildUIToFP(LLVMBuilderRef, LLVMValueRef Val,
661 LLVMTypeRef DestTy, const char *Name);
662LLVMValueRef LLVMBuildSIToFP(LLVMBuilderRef, LLVMValueRef Val,
663 LLVMTypeRef DestTy, const char *Name);
664LLVMValueRef LLVMBuildFPTrunc(LLVMBuilderRef, LLVMValueRef Val,
665 LLVMTypeRef DestTy, const char *Name);
666LLVMValueRef LLVMBuildFPExt(LLVMBuilderRef, LLVMValueRef Val,
667 LLVMTypeRef DestTy, const char *Name);
668LLVMValueRef LLVMBuildPtrToInt(LLVMBuilderRef, LLVMValueRef Val,
669 LLVMTypeRef DestTy, const char *Name);
670LLVMValueRef LLVMBuildIntToPtr(LLVMBuilderRef, LLVMValueRef Val,
671 LLVMTypeRef DestTy, const char *Name);
672LLVMValueRef LLVMBuildBitCast(LLVMBuilderRef, LLVMValueRef Val,
673 LLVMTypeRef DestTy, const char *Name);
674
675/* Comparisons */
676LLVMValueRef LLVMBuildICmp(LLVMBuilderRef, LLVMIntPredicate Op,
677 LLVMValueRef LHS, LLVMValueRef RHS,
678 const char *Name);
679LLVMValueRef LLVMBuildFCmp(LLVMBuilderRef, LLVMRealPredicate Op,
680 LLVMValueRef LHS, LLVMValueRef RHS,
681 const char *Name);
682
683/* Miscellaneous instructions */
684LLVMValueRef LLVMBuildPhi(LLVMBuilderRef, LLVMTypeRef Ty, const char *Name);
685LLVMValueRef LLVMBuildCall(LLVMBuilderRef, LLVMValueRef Fn,
686 LLVMValueRef *Args, unsigned NumArgs,
687 const char *Name);
688LLVMValueRef LLVMBuildSelect(LLVMBuilderRef, LLVMValueRef If,
689 LLVMValueRef Then, LLVMValueRef Else,
690 const char *Name);
691LLVMValueRef LLVMBuildVAArg(LLVMBuilderRef, LLVMValueRef List, LLVMTypeRef Ty,
692 const char *Name);
693LLVMValueRef LLVMBuildExtractElement(LLVMBuilderRef, LLVMValueRef VecVal,
694 LLVMValueRef Index, const char *Name);
695LLVMValueRef LLVMBuildInsertElement(LLVMBuilderRef, LLVMValueRef VecVal,
696 LLVMValueRef EltVal, LLVMValueRef Index,
697 const char *Name);
698LLVMValueRef LLVMBuildShuffleVector(LLVMBuilderRef, LLVMValueRef V1,
699 LLVMValueRef V2, LLVMValueRef Mask,
700 const char *Name);
Dan Gohmand5104a52008-11-03 22:55:43 +0000701LLVMValueRef LLVMBuildExtractValue(LLVMBuilderRef, LLVMValueRef AggVal,
702 unsigned Index, const char *Name);
703LLVMValueRef LLVMBuildInsertValue(LLVMBuilderRef, LLVMValueRef AggVal,
704 LLVMValueRef EltVal, unsigned Index,
705 const char *Name);
Gordon Henriksen76a03742007-09-18 03:18:57 +0000706
Gordon Henriksen34eb6d82007-12-19 22:30:40 +0000707
Gordon Henriksen0a68fe22007-12-12 01:04:30 +0000708/*===-- Module providers --------------------------------------------------===*/
709
710/* Encapsulates the module M in a module provider, taking ownership of the
711 * module.
712 * See the constructor llvm::ExistingModuleProvider::ExistingModuleProvider.
713 */
714LLVMModuleProviderRef
715LLVMCreateModuleProviderForExistingModule(LLVMModuleRef M);
716
717/* Destroys the module provider MP as well as the contained module.
718 * See the destructor llvm::ModuleProvider::~ModuleProvider.
719 */
720void LLVMDisposeModuleProvider(LLVMModuleProviderRef MP);
721
Gordon Henriksen34eb6d82007-12-19 22:30:40 +0000722
723/*===-- Memory buffers ----------------------------------------------------===*/
724
725int LLVMCreateMemoryBufferWithContentsOfFile(const char *Path,
726 LLVMMemoryBufferRef *OutMemBuf,
727 char **OutMessage);
728int LLVMCreateMemoryBufferWithSTDIN(LLVMMemoryBufferRef *OutMemBuf,
729 char **OutMessage);
730void LLVMDisposeMemoryBuffer(LLVMMemoryBufferRef MemBuf);
731
Gordon Henriksen878114b2008-03-16 04:20:44 +0000732
733/*===-- Pass Managers -----------------------------------------------------===*/
734
735/** Constructs a new whole-module pass pipeline. This type of pipeline is
736 suitable for link-time optimization and whole-module transformations.
737 See llvm::PassManager::PassManager. */
Gordon Henriksena735a9c2008-05-04 12:55:34 +0000738LLVMPassManagerRef LLVMCreatePassManager(void);
Gordon Henriksen878114b2008-03-16 04:20:44 +0000739
740/** Constructs a new function-by-function pass pipeline over the module
741 provider. It does not take ownership of the module provider. This type of
742 pipeline is suitable for code generation and JIT compilation tasks.
743 See llvm::FunctionPassManager::FunctionPassManager. */
744LLVMPassManagerRef LLVMCreateFunctionPassManager(LLVMModuleProviderRef MP);
745
746/** Initializes, executes on the provided module, and finalizes all of the
747 passes scheduled in the pass manager. Returns 1 if any of the passes
748 modified the module, 0 otherwise. See llvm::PassManager::run(Module&). */
749int LLVMRunPassManager(LLVMPassManagerRef PM, LLVMModuleRef M);
750
751/** Initializes all of the function passes scheduled in the function pass
752 manager. Returns 1 if any of the passes modified the module, 0 otherwise.
753 See llvm::FunctionPassManager::doInitialization. */
754int LLVMInitializeFunctionPassManager(LLVMPassManagerRef FPM);
755
756/** Executes all of the function passes scheduled in the function pass manager
757 on the provided function. Returns 1 if any of the passes modified the
758 function, false otherwise.
759 See llvm::FunctionPassManager::run(Function&). */
760int LLVMRunFunctionPassManager(LLVMPassManagerRef FPM, LLVMValueRef F);
761
762/** Finalizes all of the function passes scheduled in in the function pass
763 manager. Returns 1 if any of the passes modified the module, 0 otherwise.
764 See llvm::FunctionPassManager::doFinalization. */
765int LLVMFinalizeFunctionPassManager(LLVMPassManagerRef FPM);
766
767/** Frees the memory of a pass pipeline. For function pipelines, does not free
768 the module provider.
769 See llvm::PassManagerBase::~PassManagerBase. */
770void LLVMDisposePassManager(LLVMPassManagerRef PM);
771
772
Gordon Henriksen76a03742007-09-18 03:18:57 +0000773#ifdef __cplusplus
774}
Gordon Henriksen76a03742007-09-18 03:18:57 +0000775
Gordon Henriksen7330acd2007-10-05 23:59:36 +0000776namespace llvm {
Gordon Henriksen0a68fe22007-12-12 01:04:30 +0000777 class ModuleProvider;
Gordon Henriksen34eb6d82007-12-19 22:30:40 +0000778 class MemoryBuffer;
Gordon Henriksen96571492008-03-16 15:55:43 +0000779 class PassManagerBase;
Gordon Henriksen0a68fe22007-12-12 01:04:30 +0000780
Gordon Henriksen34eb6d82007-12-19 22:30:40 +0000781 #define DEFINE_SIMPLE_CONVERSION_FUNCTIONS(ty, ref) \
782 inline ty *unwrap(ref P) { \
783 return reinterpret_cast<ty*>(P); \
784 } \
785 \
786 inline ref wrap(const ty *P) { \
787 return reinterpret_cast<ref>(const_cast<ty*>(P)); \
788 }
Gordon Henriksen7330acd2007-10-05 23:59:36 +0000789
Gordon Henriksen878114b2008-03-16 04:20:44 +0000790 #define DEFINE_ISA_CONVERSION_FUNCTIONS(ty, ref) \
791 DEFINE_SIMPLE_CONVERSION_FUNCTIONS(ty, ref) \
792 \
793 template<typename T> \
794 inline T *unwrap(ref P) { \
795 return cast<T>(unwrap(P)); \
796 }
797
798 #define DEFINE_STDCXX_CONVERSION_FUNCTIONS(ty, ref) \
799 DEFINE_SIMPLE_CONVERSION_FUNCTIONS(ty, ref) \
800 \
801 template<typename T> \
802 inline T *unwrap(ref P) { \
803 T *Q = dynamic_cast<T*>(unwrap(P)); \
804 assert(Q && "Invalid cast!"); \
805 return Q; \
806 }
807
808 DEFINE_ISA_CONVERSION_FUNCTIONS (Type, LLVMTypeRef )
809 DEFINE_ISA_CONVERSION_FUNCTIONS (Value, LLVMValueRef )
Gordon Henriksen823f9732007-12-27 18:25:59 +0000810 DEFINE_SIMPLE_CONVERSION_FUNCTIONS(Module, LLVMModuleRef )
811 DEFINE_SIMPLE_CONVERSION_FUNCTIONS(BasicBlock, LLVMBasicBlockRef )
Eric Christopher59278832008-08-08 19:39:37 +0000812 DEFINE_SIMPLE_CONVERSION_FUNCTIONS(IRBuilder<>, LLVMBuilderRef )
Gordon Henriksen823f9732007-12-27 18:25:59 +0000813 DEFINE_SIMPLE_CONVERSION_FUNCTIONS(PATypeHolder, LLVMTypeHandleRef )
814 DEFINE_SIMPLE_CONVERSION_FUNCTIONS(ModuleProvider, LLVMModuleProviderRef)
815 DEFINE_SIMPLE_CONVERSION_FUNCTIONS(MemoryBuffer, LLVMMemoryBufferRef )
Gordon Henriksen878114b2008-03-16 04:20:44 +0000816 DEFINE_STDCXX_CONVERSION_FUNCTIONS(PassManagerBase, LLVMPassManagerRef )
Gordon Henriksen7330acd2007-10-05 23:59:36 +0000817
Gordon Henriksen878114b2008-03-16 04:20:44 +0000818 #undef DEFINE_STDCXX_CONVERSION_FUNCTIONS
819 #undef DEFINE_ISA_CONVERSION_FUNCTIONS
Gordon Henriksen34eb6d82007-12-19 22:30:40 +0000820 #undef DEFINE_SIMPLE_CONVERSION_FUNCTIONS
Gordon Henriksen7330acd2007-10-05 23:59:36 +0000821
Gordon Henriksen34eb6d82007-12-19 22:30:40 +0000822 /* Specialized opaque type conversions.
823 */
Gordon Henriksen7330acd2007-10-05 23:59:36 +0000824 inline Type **unwrap(LLVMTypeRef* Tys) {
825 return reinterpret_cast<Type**>(Tys);
826 }
827
Gordon Henriksen7330acd2007-10-05 23:59:36 +0000828 inline LLVMTypeRef *wrap(const Type **Tys) {
829 return reinterpret_cast<LLVMTypeRef*>(const_cast<Type**>(Tys));
830 }
831
Gordon Henriksen34eb6d82007-12-19 22:30:40 +0000832 /* Specialized opaque value conversions.
Gordon Henriksen7330acd2007-10-05 23:59:36 +0000833 */
Gordon Henriksen7330acd2007-10-05 23:59:36 +0000834 inline Value **unwrap(LLVMValueRef *Vals) {
835 return reinterpret_cast<Value**>(Vals);
836 }
837
838 template<typename T>
839 inline T **unwrap(LLVMValueRef *Vals, unsigned Length) {
840 #if DEBUG
841 for (LLVMValueRef *I = Vals, E = Vals + Length; I != E; ++I)
842 cast<T>(*I);
843 #endif
844 return reinterpret_cast<T**>(Vals);
845 }
846
Gordon Henriksen7330acd2007-10-05 23:59:36 +0000847 inline LLVMValueRef *wrap(const Value **Vals) {
848 return reinterpret_cast<LLVMValueRef*>(const_cast<Value**>(Vals));
849 }
Gordon Henriksen7330acd2007-10-05 23:59:36 +0000850}
851
852#endif /* !defined(__cplusplus) */
853
854#endif /* !defined(LLVM_C_CORE_H) */