blob: c022c101775ae46349020b543a0483e6abc59ccf [file] [log] [blame]
Gordon Henriksen76a03742007-09-18 03:18:57 +00001/*===-- llvm-c/Core.h - Core Library C Interface ------------------*- C -*-===*\
2|* *|
3|* The LLVM Compiler Infrastructure *|
4|* *|
Chris Lattnere9cc7422007-12-29 19:59:42 +00005|* This file is distributed under the University of Illinois Open Source *|
6|* License. See LICENSE.TXT for details. *|
Gordon Henriksen76a03742007-09-18 03:18:57 +00007|* *|
8|*===----------------------------------------------------------------------===*|
9|* *|
10|* This header declares the C interface to libLLVMCore.a, which implements *|
11|* the LLVM intermediate representation. *|
12|* *|
13|* LLVM uses a polymorphic type hierarchy which C cannot represent, therefore *|
14|* parameters must be passed as base types. Despite the declared types, most *|
15|* of the functions provided operate only on branches of the type hierarchy. *|
16|* The declared parameter names are descriptive and specify which type is *|
17|* required. Additionally, each type hierarchy is documented along with the *|
18|* functions that operate upon it. For more detail, refer to LLVM's C++ code. *|
19|* If in doubt, refer to Core.cpp, which performs paramter downcasts in the *|
20|* form unwrap<RequiredType>(Param). *|
21|* *|
22|* Many exotic languages can interoperate with C code but have a harder time *|
23|* with C++ due to name mangling. So in addition to C, this interface enables *|
24|* tools written in such languages. *|
25|* *|
Gordon Henriksen7330acd2007-10-05 23:59:36 +000026|* When included into a C++ source file, also declares 'wrap' and 'unwrap' *|
27|* helpers to perform opaque reference<-->pointer conversions. These helpers *|
28|* are shorter and more tightly typed than writing the casts by hand when *|
29|* authoring bindings. In assert builds, they will do runtime type checking. *|
30|* *|
Gordon Henriksen76a03742007-09-18 03:18:57 +000031\*===----------------------------------------------------------------------===*/
32
33#ifndef LLVM_C_CORE_H
34#define LLVM_C_CORE_H
35
36#ifdef __cplusplus
Gordon Henriksen7330acd2007-10-05 23:59:36 +000037
38/* Need these includes to support the LLVM 'cast' template for the C++ 'wrap'
39 and 'unwrap' conversion functions. */
40#include "llvm/Module.h"
Duncan Sandsa07136e2008-04-13 06:22:09 +000041#include "llvm/Support/IRBuilder.h"
Gordon Henriksen7330acd2007-10-05 23:59:36 +000042
Gordon Henriksen76a03742007-09-18 03:18:57 +000043extern "C" {
44#endif
45
46
47/* Opaque types. */
Gordon Henriksen4a4d7352007-12-30 17:46:33 +000048
49/**
Owen Anderson6773d382009-07-01 16:58:40 +000050 * The top-level container for all LLVM global data. See the LLVMContext class.
51 */
52typedef struct LLVMCtxt *LLVMContextRef;
53
54/**
Gordon Henriksen4a4d7352007-12-30 17:46:33 +000055 * The top-level container for all other LLVM Intermediate Representation (IR)
56 * objects. See the llvm::Module class.
57 */
Gordon Henriksen76a03742007-09-18 03:18:57 +000058typedef struct LLVMOpaqueModule *LLVMModuleRef;
Gordon Henriksen4a4d7352007-12-30 17:46:33 +000059
60/**
Gordon Henriksena49d4352008-03-07 19:13:06 +000061 * Each value in the LLVM IR has a type, an LLVMTypeRef. See the llvm::Type
62 * class.
Gordon Henriksen4a4d7352007-12-30 17:46:33 +000063 */
Gordon Henriksen76a03742007-09-18 03:18:57 +000064typedef struct LLVMOpaqueType *LLVMTypeRef;
Gordon Henriksen4a4d7352007-12-30 17:46:33 +000065
66/**
Gordon Henriksena49d4352008-03-07 19:13:06 +000067 * When building recursive types using LLVMRefineType, LLVMTypeRef values may
68 * become invalid; use LLVMTypeHandleRef to resolve this problem. See the
69 * llvm::AbstractTypeHolder class.
Gordon Henriksen4a4d7352007-12-30 17:46:33 +000070 */
Gordon Henriksenffb48762007-10-07 00:13:35 +000071typedef struct LLVMOpaqueTypeHandle *LLVMTypeHandleRef;
Gordon Henriksen4a4d7352007-12-30 17:46:33 +000072
Gordon Henriksen76a03742007-09-18 03:18:57 +000073typedef struct LLVMOpaqueValue *LLVMValueRef;
Gordon Henriksenc23b66c2007-09-26 20:56:12 +000074typedef struct LLVMOpaqueBasicBlock *LLVMBasicBlockRef;
75typedef struct LLVMOpaqueBuilder *LLVMBuilderRef;
Gordon Henriksen34eb6d82007-12-19 22:30:40 +000076
77/* Used to provide a module to JIT or interpreter.
78 * See the llvm::ModuleProvider class.
79 */
Gordon Henriksen0a68fe22007-12-12 01:04:30 +000080typedef struct LLVMOpaqueModuleProvider *LLVMModuleProviderRef;
Gordon Henriksen76a03742007-09-18 03:18:57 +000081
Gordon Henriksen34eb6d82007-12-19 22:30:40 +000082/* Used to provide a module to JIT or interpreter.
83 * See the llvm::MemoryBuffer class.
84 */
85typedef struct LLVMOpaqueMemoryBuffer *LLVMMemoryBufferRef;
86
Gordon Henriksen878114b2008-03-16 04:20:44 +000087/** See the llvm::PassManagerBase class. */
88typedef struct LLVMOpaquePassManager *LLVMPassManagerRef;
89
Gordon Henriksen76a03742007-09-18 03:18:57 +000090typedef enum {
Devang Patel4c758ea2008-09-25 21:00:45 +000091 LLVMZExtAttribute = 1<<0,
92 LLVMSExtAttribute = 1<<1,
93 LLVMNoReturnAttribute = 1<<2,
94 LLVMInRegAttribute = 1<<3,
95 LLVMStructRetAttribute = 1<<4,
96 LLVMNoUnwindAttribute = 1<<5,
97 LLVMNoAliasAttribute = 1<<6,
98 LLVMByValAttribute = 1<<7,
99 LLVMNestAttribute = 1<<8,
100 LLVMReadNoneAttribute = 1<<9,
101 LLVMReadOnlyAttribute = 1<<10
102} LLVMAttribute;
Gordon Henriksen2d9cc212008-04-28 17:37:06 +0000103
104typedef enum {
Gordon Henriksen4a4d7352007-12-30 17:46:33 +0000105 LLVMVoidTypeKind, /**< type with no size */
106 LLVMFloatTypeKind, /**< 32 bit floating point type */
107 LLVMDoubleTypeKind, /**< 64 bit floating point type */
108 LLVMX86_FP80TypeKind, /**< 80 bit floating point type (X87) */
109 LLVMFP128TypeKind, /**< 128 bit floating point type (112-bit mantissa)*/
110 LLVMPPC_FP128TypeKind, /**< 128 bit floating point type (two 64-bits) */
111 LLVMLabelTypeKind, /**< Labels */
112 LLVMIntegerTypeKind, /**< Arbitrary bit width integers */
113 LLVMFunctionTypeKind, /**< Functions */
114 LLVMStructTypeKind, /**< Structures */
115 LLVMArrayTypeKind, /**< Arrays */
116 LLVMPointerTypeKind, /**< Pointers */
117 LLVMOpaqueTypeKind, /**< Opaque: type with unknown structure */
118 LLVMVectorTypeKind /**< SIMD 'packed' format, or other vector type */
Gordon Henriksen76a03742007-09-18 03:18:57 +0000119} LLVMTypeKind;
120
121typedef enum {
Gordon Henriksen4a4d7352007-12-30 17:46:33 +0000122 LLVMExternalLinkage, /**< Externally visible function */
Chris Lattner2dba0f02009-04-13 06:25:37 +0000123 LLVMAvailableExternallyLinkage,
Duncan Sands12da8ce2009-03-07 15:45:40 +0000124 LLVMLinkOnceAnyLinkage, /**< Keep one copy of function when linking (inline)*/
125 LLVMLinkOnceODRLinkage, /**< Same, but only replaced by something
126 equivalent. */
127 LLVMWeakAnyLinkage, /**< Keep one copy of function when linking (weak) */
128 LLVMWeakODRLinkage, /**< Same, but only replaced by something
129 equivalent. */
Gordon Henriksen4a4d7352007-12-30 17:46:33 +0000130 LLVMAppendingLinkage, /**< Special purpose, only applies to global arrays */
131 LLVMInternalLinkage, /**< Rename collisions when linking (static
132 functions) */
Duncan Sands12da8ce2009-03-07 15:45:40 +0000133 LLVMPrivateLinkage, /**< Like Internal, but omit from symbol table */
Gordon Henriksen4a4d7352007-12-30 17:46:33 +0000134 LLVMDLLImportLinkage, /**< Function to be imported from DLL */
135 LLVMDLLExportLinkage, /**< Function to be accessible from DLL */
Duncan Sandse2881052009-03-11 08:08:06 +0000136 LLVMExternalWeakLinkage,/**< ExternalWeak linkage description */
Duncan Sands12da8ce2009-03-07 15:45:40 +0000137 LLVMGhostLinkage, /**< Stand-in functions for streaming fns from
Gordon Henriksen4a4d7352007-12-30 17:46:33 +0000138 bitcode */
Duncan Sands4581beb2009-03-11 20:14:15 +0000139 LLVMCommonLinkage /**< Tentative definitions */
Gordon Henriksen76a03742007-09-18 03:18:57 +0000140} LLVMLinkage;
141
142typedef enum {
Gordon Henriksen4a4d7352007-12-30 17:46:33 +0000143 LLVMDefaultVisibility, /**< The GV is visible */
144 LLVMHiddenVisibility, /**< The GV is hidden */
145 LLVMProtectedVisibility /**< The GV is protected */
Gordon Henriksen76a03742007-09-18 03:18:57 +0000146} LLVMVisibility;
147
Gordon Henriksenc23b66c2007-09-26 20:56:12 +0000148typedef enum {
149 LLVMCCallConv = 0,
150 LLVMFastCallConv = 8,
151 LLVMColdCallConv = 9,
152 LLVMX86StdcallCallConv = 64,
153 LLVMX86FastcallCallConv = 65
154} LLVMCallConv;
155
156typedef enum {
Gordon Henriksen4a4d7352007-12-30 17:46:33 +0000157 LLVMIntEQ = 32, /**< equal */
158 LLVMIntNE, /**< not equal */
159 LLVMIntUGT, /**< unsigned greater than */
160 LLVMIntUGE, /**< unsigned greater or equal */
161 LLVMIntULT, /**< unsigned less than */
162 LLVMIntULE, /**< unsigned less or equal */
163 LLVMIntSGT, /**< signed greater than */
164 LLVMIntSGE, /**< signed greater or equal */
165 LLVMIntSLT, /**< signed less than */
166 LLVMIntSLE /**< signed less or equal */
Gordon Henriksenc23b66c2007-09-26 20:56:12 +0000167} LLVMIntPredicate;
168
169typedef enum {
Gordon Henriksen4a4d7352007-12-30 17:46:33 +0000170 LLVMRealPredicateFalse, /**< Always false (always folded) */
171 LLVMRealOEQ, /**< True if ordered and equal */
172 LLVMRealOGT, /**< True if ordered and greater than */
173 LLVMRealOGE, /**< True if ordered and greater than or equal */
174 LLVMRealOLT, /**< True if ordered and less than */
175 LLVMRealOLE, /**< True if ordered and less than or equal */
176 LLVMRealONE, /**< True if ordered and operands are unequal */
177 LLVMRealORD, /**< True if ordered (no nans) */
178 LLVMRealUNO, /**< True if unordered: isnan(X) | isnan(Y) */
179 LLVMRealUEQ, /**< True if unordered or equal */
180 LLVMRealUGT, /**< True if unordered or greater than */
181 LLVMRealUGE, /**< True if unordered, greater than, or equal */
182 LLVMRealULT, /**< True if unordered or less than */
183 LLVMRealULE, /**< True if unordered, less than, or equal */
184 LLVMRealUNE, /**< True if unordered or not equal */
185 LLVMRealPredicateTrue /**< Always true (always folded) */
Gordon Henriksenc23b66c2007-09-26 20:56:12 +0000186} LLVMRealPredicate;
187
Gordon Henriksen76a03742007-09-18 03:18:57 +0000188
Gordon Henriksen34eb6d82007-12-19 22:30:40 +0000189/*===-- Error handling ----------------------------------------------------===*/
190
191void LLVMDisposeMessage(char *Message);
192
193
Gordon Henriksen76a03742007-09-18 03:18:57 +0000194/*===-- Modules -----------------------------------------------------------===*/
195
Owen Anderson6773d382009-07-01 16:58:40 +0000196/* Create and destroy contexts. */
197LLVMContextRef LLVMContextCreate();
Owen Andersonf7691d32009-07-02 00:16:38 +0000198LLVMContextRef LLVMGetGlobalContext();
Owen Anderson6773d382009-07-01 16:58:40 +0000199void LLVMContextDispose(LLVMContextRef C);
200
Gordon Henriksen76a03742007-09-18 03:18:57 +0000201/* Create and destroy modules. */
Gordon Henriksena49d4352008-03-07 19:13:06 +0000202/** See llvm::Module::Module. */
Gordon Henriksen76a03742007-09-18 03:18:57 +0000203LLVMModuleRef LLVMModuleCreateWithName(const char *ModuleID);
Gordon Henriksena49d4352008-03-07 19:13:06 +0000204
205/** See llvm::Module::~Module. */
Gordon Henriksen76a03742007-09-18 03:18:57 +0000206void LLVMDisposeModule(LLVMModuleRef M);
207
Gordon Henriksena49d4352008-03-07 19:13:06 +0000208/** Data layout. See Module::getDataLayout. */
Gordon Henriksen05568bb2007-12-27 20:13:47 +0000209const char *LLVMGetDataLayout(LLVMModuleRef M);
210void LLVMSetDataLayout(LLVMModuleRef M, const char *Triple);
211
Gordon Henriksena49d4352008-03-07 19:13:06 +0000212/** Target triple. See Module::getTargetTriple. */
Gordon Henriksen05568bb2007-12-27 20:13:47 +0000213const char *LLVMGetTarget(LLVMModuleRef M);
214void LLVMSetTarget(LLVMModuleRef M, const char *Triple);
215
Gordon Henriksena49d4352008-03-07 19:13:06 +0000216/** See Module::addTypeName. */
Gordon Henriksen76a03742007-09-18 03:18:57 +0000217int LLVMAddTypeName(LLVMModuleRef M, const char *Name, LLVMTypeRef Ty);
Gordon Henriksenc23b66c2007-09-26 20:56:12 +0000218void LLVMDeleteTypeName(LLVMModuleRef M, const char *Name);
Gordon Henriksen76a03742007-09-18 03:18:57 +0000219
Gordon Henriksen6c6075e2008-03-14 23:58:56 +0000220/** See Module::dump. */
221void LLVMDumpModule(LLVMModuleRef M);
222
Gordon Henriksen76a03742007-09-18 03:18:57 +0000223
Gordon Henriksenc23b66c2007-09-26 20:56:12 +0000224/*===-- Types -------------------------------------------------------------===*/
Gordon Henriksen76a03742007-09-18 03:18:57 +0000225
226/* LLVM types conform to the following hierarchy:
227 *
228 * types:
229 * integer type
230 * real type
231 * function type
232 * sequence types:
233 * array type
234 * pointer type
235 * vector type
236 * void type
237 * label type
238 * opaque type
239 */
240
Gordon Henriksena49d4352008-03-07 19:13:06 +0000241/** See llvm::LLVMTypeKind::getTypeID. */
Gordon Henriksen76a03742007-09-18 03:18:57 +0000242LLVMTypeKind LLVMGetTypeKind(LLVMTypeRef Ty);
Gordon Henriksena49d4352008-03-07 19:13:06 +0000243
Gordon Henriksen76a03742007-09-18 03:18:57 +0000244/* Operations on integer types */
Gordon Henriksena735a9c2008-05-04 12:55:34 +0000245LLVMTypeRef LLVMInt1Type(void);
246LLVMTypeRef LLVMInt8Type(void);
247LLVMTypeRef LLVMInt16Type(void);
248LLVMTypeRef LLVMInt32Type(void);
249LLVMTypeRef LLVMInt64Type(void);
Gordon Henriksened7beaa2007-10-06 16:05:20 +0000250LLVMTypeRef LLVMIntType(unsigned NumBits);
Gordon Henriksenc23b66c2007-09-26 20:56:12 +0000251unsigned LLVMGetIntTypeWidth(LLVMTypeRef IntegerTy);
Gordon Henriksen76a03742007-09-18 03:18:57 +0000252
253/* Operations on real types */
Gordon Henriksena735a9c2008-05-04 12:55:34 +0000254LLVMTypeRef LLVMFloatType(void);
255LLVMTypeRef LLVMDoubleType(void);
256LLVMTypeRef LLVMX86FP80Type(void);
257LLVMTypeRef LLVMFP128Type(void);
258LLVMTypeRef LLVMPPCFP128Type(void);
Gordon Henriksen76a03742007-09-18 03:18:57 +0000259
260/* Operations on function types */
Gordon Henriksened7beaa2007-10-06 16:05:20 +0000261LLVMTypeRef LLVMFunctionType(LLVMTypeRef ReturnType,
262 LLVMTypeRef *ParamTypes, unsigned ParamCount,
263 int IsVarArg);
Gordon Henriksen76a03742007-09-18 03:18:57 +0000264int LLVMIsFunctionVarArg(LLVMTypeRef FunctionTy);
Gordon Henriksenc23b66c2007-09-26 20:56:12 +0000265LLVMTypeRef LLVMGetReturnType(LLVMTypeRef FunctionTy);
266unsigned LLVMCountParamTypes(LLVMTypeRef FunctionTy);
267void LLVMGetParamTypes(LLVMTypeRef FunctionTy, LLVMTypeRef *Dest);
Gordon Henriksen76a03742007-09-18 03:18:57 +0000268
269/* Operations on struct types */
Gordon Henriksened7beaa2007-10-06 16:05:20 +0000270LLVMTypeRef LLVMStructType(LLVMTypeRef *ElementTypes, unsigned ElementCount,
271 int Packed);
Gordon Henriksenc23b66c2007-09-26 20:56:12 +0000272unsigned LLVMCountStructElementTypes(LLVMTypeRef StructTy);
Gordon Henriksen76a03742007-09-18 03:18:57 +0000273void LLVMGetStructElementTypes(LLVMTypeRef StructTy, LLVMTypeRef *Dest);
274int LLVMIsPackedStruct(LLVMTypeRef StructTy);
275
276/* Operations on array, pointer, and vector types (sequence types) */
Gordon Henriksened7beaa2007-10-06 16:05:20 +0000277LLVMTypeRef LLVMArrayType(LLVMTypeRef ElementType, unsigned ElementCount);
Gordon Henriksen5a3fe032007-12-17 16:08:32 +0000278LLVMTypeRef LLVMPointerType(LLVMTypeRef ElementType, unsigned AddressSpace);
Gordon Henriksened7beaa2007-10-06 16:05:20 +0000279LLVMTypeRef LLVMVectorType(LLVMTypeRef ElementType, unsigned ElementCount);
Gordon Henriksen76a03742007-09-18 03:18:57 +0000280
281LLVMTypeRef LLVMGetElementType(LLVMTypeRef Ty);
282unsigned LLVMGetArrayLength(LLVMTypeRef ArrayTy);
Gordon Henriksen5a3fe032007-12-17 16:08:32 +0000283unsigned LLVMGetPointerAddressSpace(LLVMTypeRef PointerTy);
Gordon Henriksen76a03742007-09-18 03:18:57 +0000284unsigned LLVMGetVectorSize(LLVMTypeRef VectorTy);
285
286/* Operations on other types */
Gordon Henriksena735a9c2008-05-04 12:55:34 +0000287LLVMTypeRef LLVMVoidType(void);
288LLVMTypeRef LLVMLabelType(void);
289LLVMTypeRef LLVMOpaqueType(void);
Gordon Henriksen76a03742007-09-18 03:18:57 +0000290
Gordon Henriksenffb48762007-10-07 00:13:35 +0000291/* Operations on type handles */
292LLVMTypeHandleRef LLVMCreateTypeHandle(LLVMTypeRef PotentiallyAbstractTy);
293void LLVMRefineType(LLVMTypeRef AbstractTy, LLVMTypeRef ConcreteTy);
294LLVMTypeRef LLVMResolveTypeHandle(LLVMTypeHandleRef TypeHandle);
295void LLVMDisposeTypeHandle(LLVMTypeHandleRef TypeHandle);
296
Gordon Henriksen76a03742007-09-18 03:18:57 +0000297
298/*===-- Values ------------------------------------------------------------===*/
299
300/* The bulk of LLVM's object model consists of values, which comprise a very
301 * rich type hierarchy.
Gordon Henriksen76a03742007-09-18 03:18:57 +0000302 */
303
Gordon Henriksen29e38942008-12-19 18:39:45 +0000304#define LLVM_FOR_EACH_VALUE_SUBCLASS(macro) \
305 macro(Argument) \
306 macro(BasicBlock) \
307 macro(InlineAsm) \
308 macro(User) \
309 macro(Constant) \
310 macro(ConstantAggregateZero) \
311 macro(ConstantArray) \
312 macro(ConstantExpr) \
313 macro(ConstantFP) \
314 macro(ConstantInt) \
315 macro(ConstantPointerNull) \
316 macro(ConstantStruct) \
317 macro(ConstantVector) \
318 macro(GlobalValue) \
319 macro(Function) \
320 macro(GlobalAlias) \
321 macro(GlobalVariable) \
322 macro(UndefValue) \
323 macro(Instruction) \
324 macro(BinaryOperator) \
325 macro(CallInst) \
326 macro(IntrinsicInst) \
327 macro(DbgInfoIntrinsic) \
328 macro(DbgDeclareInst) \
329 macro(DbgFuncStartInst) \
330 macro(DbgRegionEndInst) \
331 macro(DbgRegionStartInst) \
332 macro(DbgStopPointInst) \
333 macro(EHSelectorInst) \
334 macro(MemIntrinsic) \
335 macro(MemCpyInst) \
336 macro(MemMoveInst) \
337 macro(MemSetInst) \
338 macro(CmpInst) \
339 macro(FCmpInst) \
340 macro(ICmpInst) \
341 macro(VFCmpInst) \
342 macro(VICmpInst) \
343 macro(ExtractElementInst) \
344 macro(GetElementPtrInst) \
345 macro(InsertElementInst) \
346 macro(InsertValueInst) \
347 macro(PHINode) \
348 macro(SelectInst) \
349 macro(ShuffleVectorInst) \
350 macro(StoreInst) \
351 macro(TerminatorInst) \
352 macro(BranchInst) \
353 macro(InvokeInst) \
354 macro(ReturnInst) \
355 macro(SwitchInst) \
356 macro(UnreachableInst) \
357 macro(UnwindInst) \
358 macro(UnaryInstruction) \
359 macro(AllocationInst) \
Gordon Henriksen05a868f2008-12-19 18:51:17 +0000360 macro(AllocaInst) \
361 macro(MallocInst) \
Gordon Henriksen29e38942008-12-19 18:39:45 +0000362 macro(CastInst) \
Gordon Henriksen05a868f2008-12-19 18:51:17 +0000363 macro(BitCastInst) \
364 macro(FPExtInst) \
365 macro(FPToSIInst) \
366 macro(FPToUIInst) \
367 macro(FPTruncInst) \
368 macro(IntToPtrInst) \
369 macro(PtrToIntInst) \
370 macro(SExtInst) \
371 macro(SIToFPInst) \
372 macro(TruncInst) \
373 macro(UIToFPInst) \
374 macro(ZExtInst) \
375 macro(ExtractValueInst) \
376 macro(FreeInst) \
377 macro(LoadInst) \
378 macro(VAArgInst)
Gordon Henriksen29e38942008-12-19 18:39:45 +0000379
Gordon Henriksen76a03742007-09-18 03:18:57 +0000380/* Operations on all values */
Gordon Henriksenc23b66c2007-09-26 20:56:12 +0000381LLVMTypeRef LLVMTypeOf(LLVMValueRef Val);
Gordon Henriksen76a03742007-09-18 03:18:57 +0000382const char *LLVMGetValueName(LLVMValueRef Val);
383void LLVMSetValueName(LLVMValueRef Val, const char *Name);
Gordon Henriksen1d0d24c2007-10-06 00:08:49 +0000384void LLVMDumpValue(LLVMValueRef Val);
Gordon Henriksen76a03742007-09-18 03:18:57 +0000385
Gordon Henriksen29e38942008-12-19 18:39:45 +0000386/* Conversion functions. Return the input value if it is an instance of the
387 specified class, otherwise NULL. See llvm::dyn_cast_or_null<>. */
388#define LLVM_DECLARE_VALUE_CAST(name) \
389 LLVMValueRef LLVMIsA##name(LLVMValueRef Val);
390LLVM_FOR_EACH_VALUE_SUBCLASS(LLVM_DECLARE_VALUE_CAST)
391
Gordon Henriksen76a03742007-09-18 03:18:57 +0000392/* Operations on constants of any type */
Gordon Henriksen1046c732007-10-06 15:11:06 +0000393LLVMValueRef LLVMConstNull(LLVMTypeRef Ty); /* all zeroes */
394LLVMValueRef LLVMConstAllOnes(LLVMTypeRef Ty); /* only for int/vector */
Gordon Henriksen76a03742007-09-18 03:18:57 +0000395LLVMValueRef LLVMGetUndef(LLVMTypeRef Ty);
Gordon Henriksendc88c062007-09-18 18:07:51 +0000396int LLVMIsConstant(LLVMValueRef Val);
Gordon Henriksen76a03742007-09-18 03:18:57 +0000397int LLVMIsNull(LLVMValueRef Val);
Gordon Henriksendc88c062007-09-18 18:07:51 +0000398int LLVMIsUndef(LLVMValueRef Val);
Gordon Henriksen76a03742007-09-18 03:18:57 +0000399
400/* Operations on scalar constants */
Gordon Henriksen1046c732007-10-06 15:11:06 +0000401LLVMValueRef LLVMConstInt(LLVMTypeRef IntTy, unsigned long long N,
402 int SignExtend);
403LLVMValueRef LLVMConstReal(LLVMTypeRef RealTy, double N);
Gordon Henriksen931e1212008-02-02 01:07:50 +0000404LLVMValueRef LLVMConstRealOfString(LLVMTypeRef RealTy, const char *Text);
Gordon Henriksen76a03742007-09-18 03:18:57 +0000405
406/* Operations on composite constants */
Gordon Henriksen1046c732007-10-06 15:11:06 +0000407LLVMValueRef LLVMConstString(const char *Str, unsigned Length,
408 int DontNullTerminate);
Gordon Henriksen2ad5aef2008-04-25 03:21:19 +0000409LLVMValueRef LLVMConstArray(LLVMTypeRef ElementTy,
Gordon Henriksen1046c732007-10-06 15:11:06 +0000410 LLVMValueRef *ConstantVals, unsigned Length);
411LLVMValueRef LLVMConstStruct(LLVMValueRef *ConstantVals, unsigned Count,
412 int packed);
413LLVMValueRef LLVMConstVector(LLVMValueRef *ScalarConstantVals, unsigned Size);
Gordon Henriksen76a03742007-09-18 03:18:57 +0000414
Gordon Henriksen7ce31762007-10-06 14:29:36 +0000415/* Constant expressions */
416LLVMValueRef LLVMSizeOf(LLVMTypeRef Ty);
417LLVMValueRef LLVMConstNeg(LLVMValueRef ConstantVal);
418LLVMValueRef LLVMConstNot(LLVMValueRef ConstantVal);
419LLVMValueRef LLVMConstAdd(LLVMValueRef LHSConstant, LLVMValueRef RHSConstant);
420LLVMValueRef LLVMConstSub(LLVMValueRef LHSConstant, LLVMValueRef RHSConstant);
421LLVMValueRef LLVMConstMul(LLVMValueRef LHSConstant, LLVMValueRef RHSConstant);
422LLVMValueRef LLVMConstUDiv(LLVMValueRef LHSConstant, LLVMValueRef RHSConstant);
423LLVMValueRef LLVMConstSDiv(LLVMValueRef LHSConstant, LLVMValueRef RHSConstant);
424LLVMValueRef LLVMConstFDiv(LLVMValueRef LHSConstant, LLVMValueRef RHSConstant);
425LLVMValueRef LLVMConstURem(LLVMValueRef LHSConstant, LLVMValueRef RHSConstant);
426LLVMValueRef LLVMConstSRem(LLVMValueRef LHSConstant, LLVMValueRef RHSConstant);
427LLVMValueRef LLVMConstFRem(LLVMValueRef LHSConstant, LLVMValueRef RHSConstant);
428LLVMValueRef LLVMConstAnd(LLVMValueRef LHSConstant, LLVMValueRef RHSConstant);
429LLVMValueRef LLVMConstOr(LLVMValueRef LHSConstant, LLVMValueRef RHSConstant);
430LLVMValueRef LLVMConstXor(LLVMValueRef LHSConstant, LLVMValueRef RHSConstant);
431LLVMValueRef LLVMConstICmp(LLVMIntPredicate Predicate,
432 LLVMValueRef LHSConstant, LLVMValueRef RHSConstant);
433LLVMValueRef LLVMConstFCmp(LLVMRealPredicate Predicate,
434 LLVMValueRef LHSConstant, LLVMValueRef RHSConstant);
435LLVMValueRef LLVMConstShl(LLVMValueRef LHSConstant, LLVMValueRef RHSConstant);
436LLVMValueRef LLVMConstLShr(LLVMValueRef LHSConstant, LLVMValueRef RHSConstant);
437LLVMValueRef LLVMConstAShr(LLVMValueRef LHSConstant, LLVMValueRef RHSConstant);
438LLVMValueRef LLVMConstGEP(LLVMValueRef ConstantVal,
439 LLVMValueRef *ConstantIndices, unsigned NumIndices);
440LLVMValueRef LLVMConstTrunc(LLVMValueRef ConstantVal, LLVMTypeRef ToType);
441LLVMValueRef LLVMConstSExt(LLVMValueRef ConstantVal, LLVMTypeRef ToType);
442LLVMValueRef LLVMConstZExt(LLVMValueRef ConstantVal, LLVMTypeRef ToType);
443LLVMValueRef LLVMConstFPTrunc(LLVMValueRef ConstantVal, LLVMTypeRef ToType);
444LLVMValueRef LLVMConstFPExt(LLVMValueRef ConstantVal, LLVMTypeRef ToType);
445LLVMValueRef LLVMConstUIToFP(LLVMValueRef ConstantVal, LLVMTypeRef ToType);
446LLVMValueRef LLVMConstSIToFP(LLVMValueRef ConstantVal, LLVMTypeRef ToType);
447LLVMValueRef LLVMConstFPToUI(LLVMValueRef ConstantVal, LLVMTypeRef ToType);
448LLVMValueRef LLVMConstFPToSI(LLVMValueRef ConstantVal, LLVMTypeRef ToType);
449LLVMValueRef LLVMConstPtrToInt(LLVMValueRef ConstantVal, LLVMTypeRef ToType);
450LLVMValueRef LLVMConstIntToPtr(LLVMValueRef ConstantVal, LLVMTypeRef ToType);
451LLVMValueRef LLVMConstBitCast(LLVMValueRef ConstantVal, LLVMTypeRef ToType);
452LLVMValueRef LLVMConstSelect(LLVMValueRef ConstantCondition,
453 LLVMValueRef ConstantIfTrue,
454 LLVMValueRef ConstantIfFalse);
455LLVMValueRef LLVMConstExtractElement(LLVMValueRef VectorConstant,
456 LLVMValueRef IndexConstant);
457LLVMValueRef LLVMConstInsertElement(LLVMValueRef VectorConstant,
458 LLVMValueRef ElementValueConstant,
459 LLVMValueRef IndexConstant);
460LLVMValueRef LLVMConstShuffleVector(LLVMValueRef VectorAConstant,
461 LLVMValueRef VectorBConstant,
462 LLVMValueRef MaskConstant);
Dan Gohmand5104a52008-11-03 22:55:43 +0000463LLVMValueRef LLVMConstExtractValue(LLVMValueRef AggConstant, unsigned *IdxList,
464 unsigned NumIdx);
465LLVMValueRef LLVMConstInsertValue(LLVMValueRef AggConstant,
466 LLVMValueRef ElementValueConstant,
467 unsigned *IdxList, unsigned NumIdx);
Chris Lattner3d1f5522008-12-17 21:39:50 +0000468LLVMValueRef LLVMConstInlineAsm(LLVMTypeRef Ty,
469 const char *AsmString, const char *Constraints,
470 int HasSideEffects);
Gordon Henriksen7ce31762007-10-06 14:29:36 +0000471
Gordon Henriksen76a03742007-09-18 03:18:57 +0000472/* Operations on global variables, functions, and aliases (globals) */
Gordon Henriksen265f7802008-03-19 01:11:35 +0000473LLVMModuleRef LLVMGetGlobalParent(LLVMValueRef Global);
Gordon Henriksen76a03742007-09-18 03:18:57 +0000474int LLVMIsDeclaration(LLVMValueRef Global);
475LLVMLinkage LLVMGetLinkage(LLVMValueRef Global);
476void LLVMSetLinkage(LLVMValueRef Global, LLVMLinkage Linkage);
477const char *LLVMGetSection(LLVMValueRef Global);
478void LLVMSetSection(LLVMValueRef Global, const char *Section);
479LLVMVisibility LLVMGetVisibility(LLVMValueRef Global);
480void LLVMSetVisibility(LLVMValueRef Global, LLVMVisibility Viz);
481unsigned LLVMGetAlignment(LLVMValueRef Global);
482void LLVMSetAlignment(LLVMValueRef Global, unsigned Bytes);
483
484/* Operations on global variables */
485LLVMValueRef LLVMAddGlobal(LLVMModuleRef M, LLVMTypeRef Ty, const char *Name);
Gordon Henriksen783f7bb2007-10-08 03:45:09 +0000486LLVMValueRef LLVMGetNamedGlobal(LLVMModuleRef M, const char *Name);
Gordon Henriksen07a45f42008-03-23 22:21:29 +0000487LLVMValueRef LLVMGetFirstGlobal(LLVMModuleRef M);
488LLVMValueRef LLVMGetLastGlobal(LLVMModuleRef M);
489LLVMValueRef LLVMGetNextGlobal(LLVMValueRef GlobalVar);
490LLVMValueRef LLVMGetPreviousGlobal(LLVMValueRef GlobalVar);
Gordon Henriksen76a03742007-09-18 03:18:57 +0000491void LLVMDeleteGlobal(LLVMValueRef GlobalVar);
Gordon Henriksen76a03742007-09-18 03:18:57 +0000492LLVMValueRef LLVMGetInitializer(LLVMValueRef GlobalVar);
493void LLVMSetInitializer(LLVMValueRef GlobalVar, LLVMValueRef ConstantVal);
494int LLVMIsThreadLocal(LLVMValueRef GlobalVar);
495void LLVMSetThreadLocal(LLVMValueRef GlobalVar, int IsThreadLocal);
Gordon Henriksen751ebf72007-10-07 17:31:42 +0000496int LLVMIsGlobalConstant(LLVMValueRef GlobalVar);
497void LLVMSetGlobalConstant(LLVMValueRef GlobalVar, int IsConstant);
Gordon Henriksen76a03742007-09-18 03:18:57 +0000498
Chris Lattner3d1f5522008-12-17 21:39:50 +0000499/* Operations on aliases */
500LLVMValueRef LLVMAddAlias(LLVMModuleRef M, LLVMTypeRef Ty, LLVMValueRef Aliasee,
501 const char *Name);
502
Gordon Henriksenc23b66c2007-09-26 20:56:12 +0000503/* Operations on functions */
504LLVMValueRef LLVMAddFunction(LLVMModuleRef M, const char *Name,
505 LLVMTypeRef FunctionTy);
Gordon Henriksen783f7bb2007-10-08 03:45:09 +0000506LLVMValueRef LLVMGetNamedFunction(LLVMModuleRef M, const char *Name);
Gordon Henriksen054817c2008-03-19 03:47:18 +0000507LLVMValueRef LLVMGetFirstFunction(LLVMModuleRef M);
508LLVMValueRef LLVMGetLastFunction(LLVMModuleRef M);
509LLVMValueRef LLVMGetNextFunction(LLVMValueRef Fn);
510LLVMValueRef LLVMGetPreviousFunction(LLVMValueRef Fn);
Gordon Henriksenc23b66c2007-09-26 20:56:12 +0000511void LLVMDeleteFunction(LLVMValueRef Fn);
Gordon Henriksenc23b66c2007-09-26 20:56:12 +0000512unsigned LLVMGetIntrinsicID(LLVMValueRef Fn);
513unsigned LLVMGetFunctionCallConv(LLVMValueRef Fn);
514void LLVMSetFunctionCallConv(LLVMValueRef Fn, unsigned CC);
Gordon Henriksend930f912008-08-17 18:44:35 +0000515const char *LLVMGetGC(LLVMValueRef Fn);
516void LLVMSetGC(LLVMValueRef Fn, const char *Name);
Duncan Sands7374a012009-05-06 12:21:17 +0000517void LLVMAddFunctionAttr(LLVMValueRef Fn, LLVMAttribute PA);
518void LLVMRemoveFunctionAttr(LLVMValueRef Fn, LLVMAttribute PA);
Gordon Henriksenc23b66c2007-09-26 20:56:12 +0000519
Gordon Henriksen265f7802008-03-19 01:11:35 +0000520/* Operations on parameters */
521unsigned LLVMCountParams(LLVMValueRef Fn);
522void LLVMGetParams(LLVMValueRef Fn, LLVMValueRef *Params);
523LLVMValueRef LLVMGetParam(LLVMValueRef Fn, unsigned Index);
524LLVMValueRef LLVMGetParamParent(LLVMValueRef Inst);
Gordon Henriksen07a45f42008-03-23 22:21:29 +0000525LLVMValueRef LLVMGetFirstParam(LLVMValueRef Fn);
526LLVMValueRef LLVMGetLastParam(LLVMValueRef Fn);
527LLVMValueRef LLVMGetNextParam(LLVMValueRef Arg);
528LLVMValueRef LLVMGetPreviousParam(LLVMValueRef Arg);
Devang Patel4c758ea2008-09-25 21:00:45 +0000529void LLVMAddAttribute(LLVMValueRef Arg, LLVMAttribute PA);
530void LLVMRemoveAttribute(LLVMValueRef Arg, LLVMAttribute PA);
Gordon Henriksen2d9cc212008-04-28 17:37:06 +0000531void LLVMSetParamAlignment(LLVMValueRef Arg, unsigned align);
Gordon Henriksen265f7802008-03-19 01:11:35 +0000532
Gordon Henriksenc23b66c2007-09-26 20:56:12 +0000533/* Operations on basic blocks */
Gordon Henriksen07a45f42008-03-23 22:21:29 +0000534LLVMValueRef LLVMBasicBlockAsValue(LLVMBasicBlockRef BB);
Gordon Henriksenc23b66c2007-09-26 20:56:12 +0000535int LLVMValueIsBasicBlock(LLVMValueRef Val);
536LLVMBasicBlockRef LLVMValueAsBasicBlock(LLVMValueRef Val);
Gordon Henriksen07a45f42008-03-23 22:21:29 +0000537LLVMValueRef LLVMGetBasicBlockParent(LLVMBasicBlockRef BB);
Gordon Henriksenc23b66c2007-09-26 20:56:12 +0000538unsigned LLVMCountBasicBlocks(LLVMValueRef Fn);
539void LLVMGetBasicBlocks(LLVMValueRef Fn, LLVMBasicBlockRef *BasicBlocks);
Gordon Henriksen054817c2008-03-19 03:47:18 +0000540LLVMBasicBlockRef LLVMGetFirstBasicBlock(LLVMValueRef Fn);
541LLVMBasicBlockRef LLVMGetLastBasicBlock(LLVMValueRef Fn);
542LLVMBasicBlockRef LLVMGetNextBasicBlock(LLVMBasicBlockRef BB);
543LLVMBasicBlockRef LLVMGetPreviousBasicBlock(LLVMBasicBlockRef BB);
Gordon Henriksenc23b66c2007-09-26 20:56:12 +0000544LLVMBasicBlockRef LLVMGetEntryBasicBlock(LLVMValueRef Fn);
545LLVMBasicBlockRef LLVMAppendBasicBlock(LLVMValueRef Fn, const char *Name);
546LLVMBasicBlockRef LLVMInsertBasicBlock(LLVMBasicBlockRef InsertBeforeBB,
547 const char *Name);
548void LLVMDeleteBasicBlock(LLVMBasicBlockRef BB);
549
Gordon Henriksen265f7802008-03-19 01:11:35 +0000550/* Operations on instructions */
551LLVMBasicBlockRef LLVMGetInstructionParent(LLVMValueRef Inst);
Gordon Henriksen054817c2008-03-19 03:47:18 +0000552LLVMValueRef LLVMGetFirstInstruction(LLVMBasicBlockRef BB);
553LLVMValueRef LLVMGetLastInstruction(LLVMBasicBlockRef BB);
554LLVMValueRef LLVMGetNextInstruction(LLVMValueRef Inst);
555LLVMValueRef LLVMGetPreviousInstruction(LLVMValueRef Inst);
Gordon Henriksen265f7802008-03-19 01:11:35 +0000556
Gordon Henriksen1158c532007-12-29 20:45:00 +0000557/* Operations on call sites */
558void LLVMSetInstructionCallConv(LLVMValueRef Instr, unsigned CC);
559unsigned LLVMGetInstructionCallConv(LLVMValueRef Instr);
Devang Patel4c758ea2008-09-25 21:00:45 +0000560void LLVMAddInstrAttribute(LLVMValueRef Instr, unsigned index, LLVMAttribute);
561void LLVMRemoveInstrAttribute(LLVMValueRef Instr, unsigned index,
562 LLVMAttribute);
Gordon Henriksen2d9cc212008-04-28 17:37:06 +0000563void LLVMSetInstrParamAlignment(LLVMValueRef Instr, unsigned index,
564 unsigned align);
Gordon Henriksen1158c532007-12-29 20:45:00 +0000565
Gordon Henrikseneeb65372008-08-30 16:34:54 +0000566/* Operations on call instructions (only) */
567int LLVMIsTailCall(LLVMValueRef CallInst);
568void LLVMSetTailCall(LLVMValueRef CallInst, int IsTailCall);
569
Gordon Henriksen44dd8fb2007-10-08 18:14:39 +0000570/* Operations on phi nodes */
571void LLVMAddIncoming(LLVMValueRef PhiNode, LLVMValueRef *IncomingValues,
572 LLVMBasicBlockRef *IncomingBlocks, unsigned Count);
573unsigned LLVMCountIncoming(LLVMValueRef PhiNode);
574LLVMValueRef LLVMGetIncomingValue(LLVMValueRef PhiNode, unsigned Index);
575LLVMBasicBlockRef LLVMGetIncomingBlock(LLVMValueRef PhiNode, unsigned Index);
Gordon Henriksenc23b66c2007-09-26 20:56:12 +0000576
577/*===-- Instruction builders ----------------------------------------------===*/
578
579/* An instruction builder represents a point within a basic block, and is the
580 * exclusive means of building instructions using the C interface.
581 */
582
Gordon Henriksena735a9c2008-05-04 12:55:34 +0000583LLVMBuilderRef LLVMCreateBuilder(void);
Gordon Henriksen054817c2008-03-19 03:47:18 +0000584void LLVMPositionBuilder(LLVMBuilderRef Builder, LLVMBasicBlockRef Block,
585 LLVMValueRef Instr);
Gordon Henriksenc23b66c2007-09-26 20:56:12 +0000586void LLVMPositionBuilderBefore(LLVMBuilderRef Builder, LLVMValueRef Instr);
587void LLVMPositionBuilderAtEnd(LLVMBuilderRef Builder, LLVMBasicBlockRef Block);
Gordon Henriksen265f7802008-03-19 01:11:35 +0000588LLVMBasicBlockRef LLVMGetInsertBlock(LLVMBuilderRef Builder);
Chris Lattner3d1f5522008-12-17 21:39:50 +0000589void LLVMClearInsertionPosition(LLVMBuilderRef Builder);
590void LLVMInsertIntoBuilder(LLVMBuilderRef Builder, LLVMValueRef Instr);
Gordon Henriksenc23b66c2007-09-26 20:56:12 +0000591void LLVMDisposeBuilder(LLVMBuilderRef Builder);
592
593/* Terminators */
594LLVMValueRef LLVMBuildRetVoid(LLVMBuilderRef);
595LLVMValueRef LLVMBuildRet(LLVMBuilderRef, LLVMValueRef V);
596LLVMValueRef LLVMBuildBr(LLVMBuilderRef, LLVMBasicBlockRef Dest);
597LLVMValueRef LLVMBuildCondBr(LLVMBuilderRef, LLVMValueRef If,
598 LLVMBasicBlockRef Then, LLVMBasicBlockRef Else);
599LLVMValueRef LLVMBuildSwitch(LLVMBuilderRef, LLVMValueRef V,
600 LLVMBasicBlockRef Else, unsigned NumCases);
601LLVMValueRef LLVMBuildInvoke(LLVMBuilderRef, LLVMValueRef Fn,
602 LLVMValueRef *Args, unsigned NumArgs,
603 LLVMBasicBlockRef Then, LLVMBasicBlockRef Catch,
604 const char *Name);
605LLVMValueRef LLVMBuildUnwind(LLVMBuilderRef);
606LLVMValueRef LLVMBuildUnreachable(LLVMBuilderRef);
607
Gordon Henriksen097102c2008-01-01 05:50:53 +0000608/* Add a case to the switch instruction */
609void LLVMAddCase(LLVMValueRef Switch, LLVMValueRef OnVal,
610 LLVMBasicBlockRef Dest);
611
Gordon Henriksenc23b66c2007-09-26 20:56:12 +0000612/* Arithmetic */
613LLVMValueRef LLVMBuildAdd(LLVMBuilderRef, LLVMValueRef LHS, LLVMValueRef RHS,
614 const char *Name);
615LLVMValueRef LLVMBuildSub(LLVMBuilderRef, LLVMValueRef LHS, LLVMValueRef RHS,
616 const char *Name);
617LLVMValueRef LLVMBuildMul(LLVMBuilderRef, LLVMValueRef LHS, LLVMValueRef RHS,
618 const char *Name);
619LLVMValueRef LLVMBuildUDiv(LLVMBuilderRef, LLVMValueRef LHS, LLVMValueRef RHS,
620 const char *Name);
621LLVMValueRef LLVMBuildSDiv(LLVMBuilderRef, LLVMValueRef LHS, LLVMValueRef RHS,
622 const char *Name);
623LLVMValueRef LLVMBuildFDiv(LLVMBuilderRef, LLVMValueRef LHS, LLVMValueRef RHS,
624 const char *Name);
625LLVMValueRef LLVMBuildURem(LLVMBuilderRef, LLVMValueRef LHS, LLVMValueRef RHS,
626 const char *Name);
627LLVMValueRef LLVMBuildSRem(LLVMBuilderRef, LLVMValueRef LHS, LLVMValueRef RHS,
628 const char *Name);
629LLVMValueRef LLVMBuildFRem(LLVMBuilderRef, LLVMValueRef LHS, LLVMValueRef RHS,
630 const char *Name);
631LLVMValueRef LLVMBuildShl(LLVMBuilderRef, LLVMValueRef LHS, LLVMValueRef RHS,
632 const char *Name);
633LLVMValueRef LLVMBuildLShr(LLVMBuilderRef, LLVMValueRef LHS, LLVMValueRef RHS,
634 const char *Name);
635LLVMValueRef LLVMBuildAShr(LLVMBuilderRef, LLVMValueRef LHS, LLVMValueRef RHS,
636 const char *Name);
637LLVMValueRef LLVMBuildAnd(LLVMBuilderRef, LLVMValueRef LHS, LLVMValueRef RHS,
638 const char *Name);
639LLVMValueRef LLVMBuildOr(LLVMBuilderRef, LLVMValueRef LHS, LLVMValueRef RHS,
640 const char *Name);
641LLVMValueRef LLVMBuildXor(LLVMBuilderRef, LLVMValueRef LHS, LLVMValueRef RHS,
642 const char *Name);
643LLVMValueRef LLVMBuildNeg(LLVMBuilderRef, LLVMValueRef V, const char *Name);
644LLVMValueRef LLVMBuildNot(LLVMBuilderRef, LLVMValueRef V, const char *Name);
645
646/* Memory */
647LLVMValueRef LLVMBuildMalloc(LLVMBuilderRef, LLVMTypeRef Ty, const char *Name);
648LLVMValueRef LLVMBuildArrayMalloc(LLVMBuilderRef, LLVMTypeRef Ty,
649 LLVMValueRef Val, const char *Name);
650LLVMValueRef LLVMBuildAlloca(LLVMBuilderRef, LLVMTypeRef Ty, const char *Name);
651LLVMValueRef LLVMBuildArrayAlloca(LLVMBuilderRef, LLVMTypeRef Ty,
652 LLVMValueRef Val, const char *Name);
653LLVMValueRef LLVMBuildFree(LLVMBuilderRef, LLVMValueRef PointerVal);
654LLVMValueRef LLVMBuildLoad(LLVMBuilderRef, LLVMValueRef PointerVal,
655 const char *Name);
656LLVMValueRef LLVMBuildStore(LLVMBuilderRef, LLVMValueRef Val, LLVMValueRef Ptr);
657LLVMValueRef LLVMBuildGEP(LLVMBuilderRef B, LLVMValueRef Pointer,
658 LLVMValueRef *Indices, unsigned NumIndices,
659 const char *Name);
660
661/* Casts */
662LLVMValueRef LLVMBuildTrunc(LLVMBuilderRef, LLVMValueRef Val,
663 LLVMTypeRef DestTy, const char *Name);
664LLVMValueRef LLVMBuildZExt(LLVMBuilderRef, LLVMValueRef Val,
665 LLVMTypeRef DestTy, const char *Name);
666LLVMValueRef LLVMBuildSExt(LLVMBuilderRef, LLVMValueRef Val,
667 LLVMTypeRef DestTy, const char *Name);
668LLVMValueRef LLVMBuildFPToUI(LLVMBuilderRef, LLVMValueRef Val,
669 LLVMTypeRef DestTy, const char *Name);
670LLVMValueRef LLVMBuildFPToSI(LLVMBuilderRef, LLVMValueRef Val,
671 LLVMTypeRef DestTy, const char *Name);
672LLVMValueRef LLVMBuildUIToFP(LLVMBuilderRef, LLVMValueRef Val,
673 LLVMTypeRef DestTy, const char *Name);
674LLVMValueRef LLVMBuildSIToFP(LLVMBuilderRef, LLVMValueRef Val,
675 LLVMTypeRef DestTy, const char *Name);
676LLVMValueRef LLVMBuildFPTrunc(LLVMBuilderRef, LLVMValueRef Val,
677 LLVMTypeRef DestTy, const char *Name);
678LLVMValueRef LLVMBuildFPExt(LLVMBuilderRef, LLVMValueRef Val,
679 LLVMTypeRef DestTy, const char *Name);
680LLVMValueRef LLVMBuildPtrToInt(LLVMBuilderRef, LLVMValueRef Val,
681 LLVMTypeRef DestTy, const char *Name);
682LLVMValueRef LLVMBuildIntToPtr(LLVMBuilderRef, LLVMValueRef Val,
683 LLVMTypeRef DestTy, const char *Name);
684LLVMValueRef LLVMBuildBitCast(LLVMBuilderRef, LLVMValueRef Val,
685 LLVMTypeRef DestTy, const char *Name);
686
687/* Comparisons */
688LLVMValueRef LLVMBuildICmp(LLVMBuilderRef, LLVMIntPredicate Op,
689 LLVMValueRef LHS, LLVMValueRef RHS,
690 const char *Name);
691LLVMValueRef LLVMBuildFCmp(LLVMBuilderRef, LLVMRealPredicate Op,
692 LLVMValueRef LHS, LLVMValueRef RHS,
693 const char *Name);
694
695/* Miscellaneous instructions */
696LLVMValueRef LLVMBuildPhi(LLVMBuilderRef, LLVMTypeRef Ty, const char *Name);
697LLVMValueRef LLVMBuildCall(LLVMBuilderRef, LLVMValueRef Fn,
698 LLVMValueRef *Args, unsigned NumArgs,
699 const char *Name);
700LLVMValueRef LLVMBuildSelect(LLVMBuilderRef, LLVMValueRef If,
701 LLVMValueRef Then, LLVMValueRef Else,
702 const char *Name);
703LLVMValueRef LLVMBuildVAArg(LLVMBuilderRef, LLVMValueRef List, LLVMTypeRef Ty,
704 const char *Name);
705LLVMValueRef LLVMBuildExtractElement(LLVMBuilderRef, LLVMValueRef VecVal,
706 LLVMValueRef Index, const char *Name);
707LLVMValueRef LLVMBuildInsertElement(LLVMBuilderRef, LLVMValueRef VecVal,
708 LLVMValueRef EltVal, LLVMValueRef Index,
709 const char *Name);
710LLVMValueRef LLVMBuildShuffleVector(LLVMBuilderRef, LLVMValueRef V1,
711 LLVMValueRef V2, LLVMValueRef Mask,
712 const char *Name);
Dan Gohmand5104a52008-11-03 22:55:43 +0000713LLVMValueRef LLVMBuildExtractValue(LLVMBuilderRef, LLVMValueRef AggVal,
714 unsigned Index, const char *Name);
715LLVMValueRef LLVMBuildInsertValue(LLVMBuilderRef, LLVMValueRef AggVal,
716 LLVMValueRef EltVal, unsigned Index,
717 const char *Name);
Gordon Henriksen76a03742007-09-18 03:18:57 +0000718
Gordon Henriksen34eb6d82007-12-19 22:30:40 +0000719
Gordon Henriksen0a68fe22007-12-12 01:04:30 +0000720/*===-- Module providers --------------------------------------------------===*/
721
722/* Encapsulates the module M in a module provider, taking ownership of the
723 * module.
724 * See the constructor llvm::ExistingModuleProvider::ExistingModuleProvider.
725 */
726LLVMModuleProviderRef
727LLVMCreateModuleProviderForExistingModule(LLVMModuleRef M);
728
729/* Destroys the module provider MP as well as the contained module.
730 * See the destructor llvm::ModuleProvider::~ModuleProvider.
731 */
732void LLVMDisposeModuleProvider(LLVMModuleProviderRef MP);
733
Gordon Henriksen34eb6d82007-12-19 22:30:40 +0000734
735/*===-- Memory buffers ----------------------------------------------------===*/
736
737int LLVMCreateMemoryBufferWithContentsOfFile(const char *Path,
738 LLVMMemoryBufferRef *OutMemBuf,
739 char **OutMessage);
740int LLVMCreateMemoryBufferWithSTDIN(LLVMMemoryBufferRef *OutMemBuf,
741 char **OutMessage);
742void LLVMDisposeMemoryBuffer(LLVMMemoryBufferRef MemBuf);
743
Gordon Henriksen878114b2008-03-16 04:20:44 +0000744
745/*===-- Pass Managers -----------------------------------------------------===*/
746
747/** Constructs a new whole-module pass pipeline. This type of pipeline is
748 suitable for link-time optimization and whole-module transformations.
749 See llvm::PassManager::PassManager. */
Gordon Henriksena735a9c2008-05-04 12:55:34 +0000750LLVMPassManagerRef LLVMCreatePassManager(void);
Gordon Henriksen878114b2008-03-16 04:20:44 +0000751
752/** Constructs a new function-by-function pass pipeline over the module
753 provider. It does not take ownership of the module provider. This type of
754 pipeline is suitable for code generation and JIT compilation tasks.
755 See llvm::FunctionPassManager::FunctionPassManager. */
756LLVMPassManagerRef LLVMCreateFunctionPassManager(LLVMModuleProviderRef MP);
757
758/** Initializes, executes on the provided module, and finalizes all of the
759 passes scheduled in the pass manager. Returns 1 if any of the passes
760 modified the module, 0 otherwise. See llvm::PassManager::run(Module&). */
761int LLVMRunPassManager(LLVMPassManagerRef PM, LLVMModuleRef M);
762
763/** Initializes all of the function passes scheduled in the function pass
764 manager. Returns 1 if any of the passes modified the module, 0 otherwise.
765 See llvm::FunctionPassManager::doInitialization. */
766int LLVMInitializeFunctionPassManager(LLVMPassManagerRef FPM);
767
768/** Executes all of the function passes scheduled in the function pass manager
769 on the provided function. Returns 1 if any of the passes modified the
770 function, false otherwise.
771 See llvm::FunctionPassManager::run(Function&). */
772int LLVMRunFunctionPassManager(LLVMPassManagerRef FPM, LLVMValueRef F);
773
774/** Finalizes all of the function passes scheduled in in the function pass
775 manager. Returns 1 if any of the passes modified the module, 0 otherwise.
776 See llvm::FunctionPassManager::doFinalization. */
777int LLVMFinalizeFunctionPassManager(LLVMPassManagerRef FPM);
778
779/** Frees the memory of a pass pipeline. For function pipelines, does not free
780 the module provider.
781 See llvm::PassManagerBase::~PassManagerBase. */
782void LLVMDisposePassManager(LLVMPassManagerRef PM);
783
784
Gordon Henriksen76a03742007-09-18 03:18:57 +0000785#ifdef __cplusplus
786}
Gordon Henriksen76a03742007-09-18 03:18:57 +0000787
Gordon Henriksen7330acd2007-10-05 23:59:36 +0000788namespace llvm {
Gordon Henriksen0a68fe22007-12-12 01:04:30 +0000789 class ModuleProvider;
Gordon Henriksen34eb6d82007-12-19 22:30:40 +0000790 class MemoryBuffer;
Gordon Henriksen96571492008-03-16 15:55:43 +0000791 class PassManagerBase;
Gordon Henriksen0a68fe22007-12-12 01:04:30 +0000792
Gordon Henriksen34eb6d82007-12-19 22:30:40 +0000793 #define DEFINE_SIMPLE_CONVERSION_FUNCTIONS(ty, ref) \
794 inline ty *unwrap(ref P) { \
795 return reinterpret_cast<ty*>(P); \
796 } \
797 \
798 inline ref wrap(const ty *P) { \
799 return reinterpret_cast<ref>(const_cast<ty*>(P)); \
800 }
Gordon Henriksen7330acd2007-10-05 23:59:36 +0000801
Gordon Henriksen878114b2008-03-16 04:20:44 +0000802 #define DEFINE_ISA_CONVERSION_FUNCTIONS(ty, ref) \
803 DEFINE_SIMPLE_CONVERSION_FUNCTIONS(ty, ref) \
804 \
805 template<typename T> \
806 inline T *unwrap(ref P) { \
807 return cast<T>(unwrap(P)); \
808 }
809
810 #define DEFINE_STDCXX_CONVERSION_FUNCTIONS(ty, ref) \
811 DEFINE_SIMPLE_CONVERSION_FUNCTIONS(ty, ref) \
812 \
813 template<typename T> \
814 inline T *unwrap(ref P) { \
815 T *Q = dynamic_cast<T*>(unwrap(P)); \
816 assert(Q && "Invalid cast!"); \
817 return Q; \
818 }
819
820 DEFINE_ISA_CONVERSION_FUNCTIONS (Type, LLVMTypeRef )
821 DEFINE_ISA_CONVERSION_FUNCTIONS (Value, LLVMValueRef )
Gordon Henriksen823f9732007-12-27 18:25:59 +0000822 DEFINE_SIMPLE_CONVERSION_FUNCTIONS(Module, LLVMModuleRef )
823 DEFINE_SIMPLE_CONVERSION_FUNCTIONS(BasicBlock, LLVMBasicBlockRef )
Eric Christopher59278832008-08-08 19:39:37 +0000824 DEFINE_SIMPLE_CONVERSION_FUNCTIONS(IRBuilder<>, LLVMBuilderRef )
Gordon Henriksen823f9732007-12-27 18:25:59 +0000825 DEFINE_SIMPLE_CONVERSION_FUNCTIONS(PATypeHolder, LLVMTypeHandleRef )
826 DEFINE_SIMPLE_CONVERSION_FUNCTIONS(ModuleProvider, LLVMModuleProviderRef)
827 DEFINE_SIMPLE_CONVERSION_FUNCTIONS(MemoryBuffer, LLVMMemoryBufferRef )
Owen Anderson6773d382009-07-01 16:58:40 +0000828 DEFINE_SIMPLE_CONVERSION_FUNCTIONS(LLVMContext, LLVMContextRef )
Gordon Henriksen878114b2008-03-16 04:20:44 +0000829 DEFINE_STDCXX_CONVERSION_FUNCTIONS(PassManagerBase, LLVMPassManagerRef )
Gordon Henriksen7330acd2007-10-05 23:59:36 +0000830
Gordon Henriksen878114b2008-03-16 04:20:44 +0000831 #undef DEFINE_STDCXX_CONVERSION_FUNCTIONS
832 #undef DEFINE_ISA_CONVERSION_FUNCTIONS
Gordon Henriksen34eb6d82007-12-19 22:30:40 +0000833 #undef DEFINE_SIMPLE_CONVERSION_FUNCTIONS
Gordon Henriksen7330acd2007-10-05 23:59:36 +0000834
Gordon Henriksen34eb6d82007-12-19 22:30:40 +0000835 /* Specialized opaque type conversions.
836 */
Gordon Henriksen7330acd2007-10-05 23:59:36 +0000837 inline Type **unwrap(LLVMTypeRef* Tys) {
838 return reinterpret_cast<Type**>(Tys);
839 }
840
Gordon Henriksen7330acd2007-10-05 23:59:36 +0000841 inline LLVMTypeRef *wrap(const Type **Tys) {
842 return reinterpret_cast<LLVMTypeRef*>(const_cast<Type**>(Tys));
843 }
844
Gordon Henriksen34eb6d82007-12-19 22:30:40 +0000845 /* Specialized opaque value conversions.
Gordon Henriksen7330acd2007-10-05 23:59:36 +0000846 */
Gordon Henriksen7330acd2007-10-05 23:59:36 +0000847 inline Value **unwrap(LLVMValueRef *Vals) {
848 return reinterpret_cast<Value**>(Vals);
849 }
850
851 template<typename T>
852 inline T **unwrap(LLVMValueRef *Vals, unsigned Length) {
853 #if DEBUG
854 for (LLVMValueRef *I = Vals, E = Vals + Length; I != E; ++I)
855 cast<T>(*I);
856 #endif
857 return reinterpret_cast<T**>(Vals);
858 }
859
Gordon Henriksen7330acd2007-10-05 23:59:36 +0000860 inline LLVMValueRef *wrap(const Value **Vals) {
861 return reinterpret_cast<LLVMValueRef*>(const_cast<Value**>(Vals));
862 }
Gordon Henriksen7330acd2007-10-05 23:59:36 +0000863}
864
865#endif /* !defined(__cplusplus) */
866
867#endif /* !defined(LLVM_C_CORE_H) */