blob: 7019b4cc660e1d02d672931ec2fe0ab55e011223 [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();
198void LLVMContextDispose(LLVMContextRef C);
199
Gordon Henriksen76a03742007-09-18 03:18:57 +0000200/* Create and destroy modules. */
Gordon Henriksena49d4352008-03-07 19:13:06 +0000201/** See llvm::Module::Module. */
Gordon Henriksen76a03742007-09-18 03:18:57 +0000202LLVMModuleRef LLVMModuleCreateWithName(const char *ModuleID);
Gordon Henriksena49d4352008-03-07 19:13:06 +0000203
204/** See llvm::Module::~Module. */
Gordon Henriksen76a03742007-09-18 03:18:57 +0000205void LLVMDisposeModule(LLVMModuleRef M);
206
Gordon Henriksena49d4352008-03-07 19:13:06 +0000207/** Data layout. See Module::getDataLayout. */
Gordon Henriksen05568bb2007-12-27 20:13:47 +0000208const char *LLVMGetDataLayout(LLVMModuleRef M);
209void LLVMSetDataLayout(LLVMModuleRef M, const char *Triple);
210
Gordon Henriksena49d4352008-03-07 19:13:06 +0000211/** Target triple. See Module::getTargetTriple. */
Gordon Henriksen05568bb2007-12-27 20:13:47 +0000212const char *LLVMGetTarget(LLVMModuleRef M);
213void LLVMSetTarget(LLVMModuleRef M, const char *Triple);
214
Gordon Henriksena49d4352008-03-07 19:13:06 +0000215/** See Module::addTypeName. */
Gordon Henriksen76a03742007-09-18 03:18:57 +0000216int LLVMAddTypeName(LLVMModuleRef M, const char *Name, LLVMTypeRef Ty);
Gordon Henriksenc23b66c2007-09-26 20:56:12 +0000217void LLVMDeleteTypeName(LLVMModuleRef M, const char *Name);
Gordon Henriksen76a03742007-09-18 03:18:57 +0000218
Gordon Henriksen6c6075e2008-03-14 23:58:56 +0000219/** See Module::dump. */
220void LLVMDumpModule(LLVMModuleRef M);
221
Gordon Henriksen76a03742007-09-18 03:18:57 +0000222
Gordon Henriksenc23b66c2007-09-26 20:56:12 +0000223/*===-- Types -------------------------------------------------------------===*/
Gordon Henriksen76a03742007-09-18 03:18:57 +0000224
225/* LLVM types conform to the following hierarchy:
226 *
227 * types:
228 * integer type
229 * real type
230 * function type
231 * sequence types:
232 * array type
233 * pointer type
234 * vector type
235 * void type
236 * label type
237 * opaque type
238 */
239
Gordon Henriksena49d4352008-03-07 19:13:06 +0000240/** See llvm::LLVMTypeKind::getTypeID. */
Gordon Henriksen76a03742007-09-18 03:18:57 +0000241LLVMTypeKind LLVMGetTypeKind(LLVMTypeRef Ty);
Gordon Henriksena49d4352008-03-07 19:13:06 +0000242
Gordon Henriksen76a03742007-09-18 03:18:57 +0000243/* Operations on integer types */
Gordon Henriksena735a9c2008-05-04 12:55:34 +0000244LLVMTypeRef LLVMInt1Type(void);
245LLVMTypeRef LLVMInt8Type(void);
246LLVMTypeRef LLVMInt16Type(void);
247LLVMTypeRef LLVMInt32Type(void);
248LLVMTypeRef LLVMInt64Type(void);
Gordon Henriksened7beaa2007-10-06 16:05:20 +0000249LLVMTypeRef LLVMIntType(unsigned NumBits);
Gordon Henriksenc23b66c2007-09-26 20:56:12 +0000250unsigned LLVMGetIntTypeWidth(LLVMTypeRef IntegerTy);
Gordon Henriksen76a03742007-09-18 03:18:57 +0000251
252/* Operations on real types */
Gordon Henriksena735a9c2008-05-04 12:55:34 +0000253LLVMTypeRef LLVMFloatType(void);
254LLVMTypeRef LLVMDoubleType(void);
255LLVMTypeRef LLVMX86FP80Type(void);
256LLVMTypeRef LLVMFP128Type(void);
257LLVMTypeRef LLVMPPCFP128Type(void);
Gordon Henriksen76a03742007-09-18 03:18:57 +0000258
259/* Operations on function types */
Gordon Henriksened7beaa2007-10-06 16:05:20 +0000260LLVMTypeRef LLVMFunctionType(LLVMTypeRef ReturnType,
261 LLVMTypeRef *ParamTypes, unsigned ParamCount,
262 int IsVarArg);
Gordon Henriksen76a03742007-09-18 03:18:57 +0000263int LLVMIsFunctionVarArg(LLVMTypeRef FunctionTy);
Gordon Henriksenc23b66c2007-09-26 20:56:12 +0000264LLVMTypeRef LLVMGetReturnType(LLVMTypeRef FunctionTy);
265unsigned LLVMCountParamTypes(LLVMTypeRef FunctionTy);
266void LLVMGetParamTypes(LLVMTypeRef FunctionTy, LLVMTypeRef *Dest);
Gordon Henriksen76a03742007-09-18 03:18:57 +0000267
268/* Operations on struct types */
Gordon Henriksened7beaa2007-10-06 16:05:20 +0000269LLVMTypeRef LLVMStructType(LLVMTypeRef *ElementTypes, unsigned ElementCount,
270 int Packed);
Gordon Henriksenc23b66c2007-09-26 20:56:12 +0000271unsigned LLVMCountStructElementTypes(LLVMTypeRef StructTy);
Gordon Henriksen76a03742007-09-18 03:18:57 +0000272void LLVMGetStructElementTypes(LLVMTypeRef StructTy, LLVMTypeRef *Dest);
273int LLVMIsPackedStruct(LLVMTypeRef StructTy);
274
275/* Operations on array, pointer, and vector types (sequence types) */
Gordon Henriksened7beaa2007-10-06 16:05:20 +0000276LLVMTypeRef LLVMArrayType(LLVMTypeRef ElementType, unsigned ElementCount);
Gordon Henriksen5a3fe032007-12-17 16:08:32 +0000277LLVMTypeRef LLVMPointerType(LLVMTypeRef ElementType, unsigned AddressSpace);
Gordon Henriksened7beaa2007-10-06 16:05:20 +0000278LLVMTypeRef LLVMVectorType(LLVMTypeRef ElementType, unsigned ElementCount);
Gordon Henriksen76a03742007-09-18 03:18:57 +0000279
280LLVMTypeRef LLVMGetElementType(LLVMTypeRef Ty);
281unsigned LLVMGetArrayLength(LLVMTypeRef ArrayTy);
Gordon Henriksen5a3fe032007-12-17 16:08:32 +0000282unsigned LLVMGetPointerAddressSpace(LLVMTypeRef PointerTy);
Gordon Henriksen76a03742007-09-18 03:18:57 +0000283unsigned LLVMGetVectorSize(LLVMTypeRef VectorTy);
284
285/* Operations on other types */
Gordon Henriksena735a9c2008-05-04 12:55:34 +0000286LLVMTypeRef LLVMVoidType(void);
287LLVMTypeRef LLVMLabelType(void);
288LLVMTypeRef LLVMOpaqueType(void);
Gordon Henriksen76a03742007-09-18 03:18:57 +0000289
Gordon Henriksenffb48762007-10-07 00:13:35 +0000290/* Operations on type handles */
291LLVMTypeHandleRef LLVMCreateTypeHandle(LLVMTypeRef PotentiallyAbstractTy);
292void LLVMRefineType(LLVMTypeRef AbstractTy, LLVMTypeRef ConcreteTy);
293LLVMTypeRef LLVMResolveTypeHandle(LLVMTypeHandleRef TypeHandle);
294void LLVMDisposeTypeHandle(LLVMTypeHandleRef TypeHandle);
295
Gordon Henriksen76a03742007-09-18 03:18:57 +0000296
297/*===-- Values ------------------------------------------------------------===*/
298
299/* The bulk of LLVM's object model consists of values, which comprise a very
300 * rich type hierarchy.
Gordon Henriksen76a03742007-09-18 03:18:57 +0000301 */
302
Gordon Henriksen29e38942008-12-19 18:39:45 +0000303#define LLVM_FOR_EACH_VALUE_SUBCLASS(macro) \
304 macro(Argument) \
305 macro(BasicBlock) \
306 macro(InlineAsm) \
307 macro(User) \
308 macro(Constant) \
309 macro(ConstantAggregateZero) \
310 macro(ConstantArray) \
311 macro(ConstantExpr) \
312 macro(ConstantFP) \
313 macro(ConstantInt) \
314 macro(ConstantPointerNull) \
315 macro(ConstantStruct) \
316 macro(ConstantVector) \
317 macro(GlobalValue) \
318 macro(Function) \
319 macro(GlobalAlias) \
320 macro(GlobalVariable) \
321 macro(UndefValue) \
322 macro(Instruction) \
323 macro(BinaryOperator) \
324 macro(CallInst) \
325 macro(IntrinsicInst) \
326 macro(DbgInfoIntrinsic) \
327 macro(DbgDeclareInst) \
328 macro(DbgFuncStartInst) \
329 macro(DbgRegionEndInst) \
330 macro(DbgRegionStartInst) \
331 macro(DbgStopPointInst) \
332 macro(EHSelectorInst) \
333 macro(MemIntrinsic) \
334 macro(MemCpyInst) \
335 macro(MemMoveInst) \
336 macro(MemSetInst) \
337 macro(CmpInst) \
338 macro(FCmpInst) \
339 macro(ICmpInst) \
340 macro(VFCmpInst) \
341 macro(VICmpInst) \
342 macro(ExtractElementInst) \
343 macro(GetElementPtrInst) \
344 macro(InsertElementInst) \
345 macro(InsertValueInst) \
346 macro(PHINode) \
347 macro(SelectInst) \
348 macro(ShuffleVectorInst) \
349 macro(StoreInst) \
350 macro(TerminatorInst) \
351 macro(BranchInst) \
352 macro(InvokeInst) \
353 macro(ReturnInst) \
354 macro(SwitchInst) \
355 macro(UnreachableInst) \
356 macro(UnwindInst) \
357 macro(UnaryInstruction) \
358 macro(AllocationInst) \
Gordon Henriksen05a868f2008-12-19 18:51:17 +0000359 macro(AllocaInst) \
360 macro(MallocInst) \
Gordon Henriksen29e38942008-12-19 18:39:45 +0000361 macro(CastInst) \
Gordon Henriksen05a868f2008-12-19 18:51:17 +0000362 macro(BitCastInst) \
363 macro(FPExtInst) \
364 macro(FPToSIInst) \
365 macro(FPToUIInst) \
366 macro(FPTruncInst) \
367 macro(IntToPtrInst) \
368 macro(PtrToIntInst) \
369 macro(SExtInst) \
370 macro(SIToFPInst) \
371 macro(TruncInst) \
372 macro(UIToFPInst) \
373 macro(ZExtInst) \
374 macro(ExtractValueInst) \
375 macro(FreeInst) \
376 macro(LoadInst) \
377 macro(VAArgInst)
Gordon Henriksen29e38942008-12-19 18:39:45 +0000378
Gordon Henriksen76a03742007-09-18 03:18:57 +0000379/* Operations on all values */
Gordon Henriksenc23b66c2007-09-26 20:56:12 +0000380LLVMTypeRef LLVMTypeOf(LLVMValueRef Val);
Gordon Henriksen76a03742007-09-18 03:18:57 +0000381const char *LLVMGetValueName(LLVMValueRef Val);
382void LLVMSetValueName(LLVMValueRef Val, const char *Name);
Gordon Henriksen1d0d24c2007-10-06 00:08:49 +0000383void LLVMDumpValue(LLVMValueRef Val);
Gordon Henriksen76a03742007-09-18 03:18:57 +0000384
Gordon Henriksen29e38942008-12-19 18:39:45 +0000385/* Conversion functions. Return the input value if it is an instance of the
386 specified class, otherwise NULL. See llvm::dyn_cast_or_null<>. */
387#define LLVM_DECLARE_VALUE_CAST(name) \
388 LLVMValueRef LLVMIsA##name(LLVMValueRef Val);
389LLVM_FOR_EACH_VALUE_SUBCLASS(LLVM_DECLARE_VALUE_CAST)
390
Gordon Henriksen76a03742007-09-18 03:18:57 +0000391/* Operations on constants of any type */
Gordon Henriksen1046c732007-10-06 15:11:06 +0000392LLVMValueRef LLVMConstNull(LLVMTypeRef Ty); /* all zeroes */
393LLVMValueRef LLVMConstAllOnes(LLVMTypeRef Ty); /* only for int/vector */
Gordon Henriksen76a03742007-09-18 03:18:57 +0000394LLVMValueRef LLVMGetUndef(LLVMTypeRef Ty);
Gordon Henriksendc88c062007-09-18 18:07:51 +0000395int LLVMIsConstant(LLVMValueRef Val);
Gordon Henriksen76a03742007-09-18 03:18:57 +0000396int LLVMIsNull(LLVMValueRef Val);
Gordon Henriksendc88c062007-09-18 18:07:51 +0000397int LLVMIsUndef(LLVMValueRef Val);
Gordon Henriksen76a03742007-09-18 03:18:57 +0000398
399/* Operations on scalar constants */
Gordon Henriksen1046c732007-10-06 15:11:06 +0000400LLVMValueRef LLVMConstInt(LLVMTypeRef IntTy, unsigned long long N,
401 int SignExtend);
402LLVMValueRef LLVMConstReal(LLVMTypeRef RealTy, double N);
Gordon Henriksen931e1212008-02-02 01:07:50 +0000403LLVMValueRef LLVMConstRealOfString(LLVMTypeRef RealTy, const char *Text);
Gordon Henriksen76a03742007-09-18 03:18:57 +0000404
405/* Operations on composite constants */
Gordon Henriksen1046c732007-10-06 15:11:06 +0000406LLVMValueRef LLVMConstString(const char *Str, unsigned Length,
407 int DontNullTerminate);
Gordon Henriksen2ad5aef2008-04-25 03:21:19 +0000408LLVMValueRef LLVMConstArray(LLVMTypeRef ElementTy,
Gordon Henriksen1046c732007-10-06 15:11:06 +0000409 LLVMValueRef *ConstantVals, unsigned Length);
410LLVMValueRef LLVMConstStruct(LLVMValueRef *ConstantVals, unsigned Count,
411 int packed);
412LLVMValueRef LLVMConstVector(LLVMValueRef *ScalarConstantVals, unsigned Size);
Gordon Henriksen76a03742007-09-18 03:18:57 +0000413
Gordon Henriksen7ce31762007-10-06 14:29:36 +0000414/* Constant expressions */
415LLVMValueRef LLVMSizeOf(LLVMTypeRef Ty);
416LLVMValueRef LLVMConstNeg(LLVMValueRef ConstantVal);
417LLVMValueRef LLVMConstNot(LLVMValueRef ConstantVal);
418LLVMValueRef LLVMConstAdd(LLVMValueRef LHSConstant, LLVMValueRef RHSConstant);
419LLVMValueRef LLVMConstSub(LLVMValueRef LHSConstant, LLVMValueRef RHSConstant);
420LLVMValueRef LLVMConstMul(LLVMValueRef LHSConstant, LLVMValueRef RHSConstant);
421LLVMValueRef LLVMConstUDiv(LLVMValueRef LHSConstant, LLVMValueRef RHSConstant);
422LLVMValueRef LLVMConstSDiv(LLVMValueRef LHSConstant, LLVMValueRef RHSConstant);
423LLVMValueRef LLVMConstFDiv(LLVMValueRef LHSConstant, LLVMValueRef RHSConstant);
424LLVMValueRef LLVMConstURem(LLVMValueRef LHSConstant, LLVMValueRef RHSConstant);
425LLVMValueRef LLVMConstSRem(LLVMValueRef LHSConstant, LLVMValueRef RHSConstant);
426LLVMValueRef LLVMConstFRem(LLVMValueRef LHSConstant, LLVMValueRef RHSConstant);
427LLVMValueRef LLVMConstAnd(LLVMValueRef LHSConstant, LLVMValueRef RHSConstant);
428LLVMValueRef LLVMConstOr(LLVMValueRef LHSConstant, LLVMValueRef RHSConstant);
429LLVMValueRef LLVMConstXor(LLVMValueRef LHSConstant, LLVMValueRef RHSConstant);
430LLVMValueRef LLVMConstICmp(LLVMIntPredicate Predicate,
431 LLVMValueRef LHSConstant, LLVMValueRef RHSConstant);
432LLVMValueRef LLVMConstFCmp(LLVMRealPredicate Predicate,
433 LLVMValueRef LHSConstant, LLVMValueRef RHSConstant);
434LLVMValueRef LLVMConstShl(LLVMValueRef LHSConstant, LLVMValueRef RHSConstant);
435LLVMValueRef LLVMConstLShr(LLVMValueRef LHSConstant, LLVMValueRef RHSConstant);
436LLVMValueRef LLVMConstAShr(LLVMValueRef LHSConstant, LLVMValueRef RHSConstant);
437LLVMValueRef LLVMConstGEP(LLVMValueRef ConstantVal,
438 LLVMValueRef *ConstantIndices, unsigned NumIndices);
439LLVMValueRef LLVMConstTrunc(LLVMValueRef ConstantVal, LLVMTypeRef ToType);
440LLVMValueRef LLVMConstSExt(LLVMValueRef ConstantVal, LLVMTypeRef ToType);
441LLVMValueRef LLVMConstZExt(LLVMValueRef ConstantVal, LLVMTypeRef ToType);
442LLVMValueRef LLVMConstFPTrunc(LLVMValueRef ConstantVal, LLVMTypeRef ToType);
443LLVMValueRef LLVMConstFPExt(LLVMValueRef ConstantVal, LLVMTypeRef ToType);
444LLVMValueRef LLVMConstUIToFP(LLVMValueRef ConstantVal, LLVMTypeRef ToType);
445LLVMValueRef LLVMConstSIToFP(LLVMValueRef ConstantVal, LLVMTypeRef ToType);
446LLVMValueRef LLVMConstFPToUI(LLVMValueRef ConstantVal, LLVMTypeRef ToType);
447LLVMValueRef LLVMConstFPToSI(LLVMValueRef ConstantVal, LLVMTypeRef ToType);
448LLVMValueRef LLVMConstPtrToInt(LLVMValueRef ConstantVal, LLVMTypeRef ToType);
449LLVMValueRef LLVMConstIntToPtr(LLVMValueRef ConstantVal, LLVMTypeRef ToType);
450LLVMValueRef LLVMConstBitCast(LLVMValueRef ConstantVal, LLVMTypeRef ToType);
451LLVMValueRef LLVMConstSelect(LLVMValueRef ConstantCondition,
452 LLVMValueRef ConstantIfTrue,
453 LLVMValueRef ConstantIfFalse);
454LLVMValueRef LLVMConstExtractElement(LLVMValueRef VectorConstant,
455 LLVMValueRef IndexConstant);
456LLVMValueRef LLVMConstInsertElement(LLVMValueRef VectorConstant,
457 LLVMValueRef ElementValueConstant,
458 LLVMValueRef IndexConstant);
459LLVMValueRef LLVMConstShuffleVector(LLVMValueRef VectorAConstant,
460 LLVMValueRef VectorBConstant,
461 LLVMValueRef MaskConstant);
Dan Gohmand5104a52008-11-03 22:55:43 +0000462LLVMValueRef LLVMConstExtractValue(LLVMValueRef AggConstant, unsigned *IdxList,
463 unsigned NumIdx);
464LLVMValueRef LLVMConstInsertValue(LLVMValueRef AggConstant,
465 LLVMValueRef ElementValueConstant,
466 unsigned *IdxList, unsigned NumIdx);
Chris Lattner3d1f5522008-12-17 21:39:50 +0000467LLVMValueRef LLVMConstInlineAsm(LLVMTypeRef Ty,
468 const char *AsmString, const char *Constraints,
469 int HasSideEffects);
Gordon Henriksen7ce31762007-10-06 14:29:36 +0000470
Gordon Henriksen76a03742007-09-18 03:18:57 +0000471/* Operations on global variables, functions, and aliases (globals) */
Gordon Henriksen265f7802008-03-19 01:11:35 +0000472LLVMModuleRef LLVMGetGlobalParent(LLVMValueRef Global);
Gordon Henriksen76a03742007-09-18 03:18:57 +0000473int LLVMIsDeclaration(LLVMValueRef Global);
474LLVMLinkage LLVMGetLinkage(LLVMValueRef Global);
475void LLVMSetLinkage(LLVMValueRef Global, LLVMLinkage Linkage);
476const char *LLVMGetSection(LLVMValueRef Global);
477void LLVMSetSection(LLVMValueRef Global, const char *Section);
478LLVMVisibility LLVMGetVisibility(LLVMValueRef Global);
479void LLVMSetVisibility(LLVMValueRef Global, LLVMVisibility Viz);
480unsigned LLVMGetAlignment(LLVMValueRef Global);
481void LLVMSetAlignment(LLVMValueRef Global, unsigned Bytes);
482
483/* Operations on global variables */
484LLVMValueRef LLVMAddGlobal(LLVMModuleRef M, LLVMTypeRef Ty, const char *Name);
Gordon Henriksen783f7bb2007-10-08 03:45:09 +0000485LLVMValueRef LLVMGetNamedGlobal(LLVMModuleRef M, const char *Name);
Gordon Henriksen07a45f42008-03-23 22:21:29 +0000486LLVMValueRef LLVMGetFirstGlobal(LLVMModuleRef M);
487LLVMValueRef LLVMGetLastGlobal(LLVMModuleRef M);
488LLVMValueRef LLVMGetNextGlobal(LLVMValueRef GlobalVar);
489LLVMValueRef LLVMGetPreviousGlobal(LLVMValueRef GlobalVar);
Gordon Henriksen76a03742007-09-18 03:18:57 +0000490void LLVMDeleteGlobal(LLVMValueRef GlobalVar);
Gordon Henriksen76a03742007-09-18 03:18:57 +0000491LLVMValueRef LLVMGetInitializer(LLVMValueRef GlobalVar);
492void LLVMSetInitializer(LLVMValueRef GlobalVar, LLVMValueRef ConstantVal);
493int LLVMIsThreadLocal(LLVMValueRef GlobalVar);
494void LLVMSetThreadLocal(LLVMValueRef GlobalVar, int IsThreadLocal);
Gordon Henriksen751ebf72007-10-07 17:31:42 +0000495int LLVMIsGlobalConstant(LLVMValueRef GlobalVar);
496void LLVMSetGlobalConstant(LLVMValueRef GlobalVar, int IsConstant);
Gordon Henriksen76a03742007-09-18 03:18:57 +0000497
Chris Lattner3d1f5522008-12-17 21:39:50 +0000498/* Operations on aliases */
499LLVMValueRef LLVMAddAlias(LLVMModuleRef M, LLVMTypeRef Ty, LLVMValueRef Aliasee,
500 const char *Name);
501
Gordon Henriksenc23b66c2007-09-26 20:56:12 +0000502/* Operations on functions */
503LLVMValueRef LLVMAddFunction(LLVMModuleRef M, const char *Name,
504 LLVMTypeRef FunctionTy);
Gordon Henriksen783f7bb2007-10-08 03:45:09 +0000505LLVMValueRef LLVMGetNamedFunction(LLVMModuleRef M, const char *Name);
Gordon Henriksen054817c2008-03-19 03:47:18 +0000506LLVMValueRef LLVMGetFirstFunction(LLVMModuleRef M);
507LLVMValueRef LLVMGetLastFunction(LLVMModuleRef M);
508LLVMValueRef LLVMGetNextFunction(LLVMValueRef Fn);
509LLVMValueRef LLVMGetPreviousFunction(LLVMValueRef Fn);
Gordon Henriksenc23b66c2007-09-26 20:56:12 +0000510void LLVMDeleteFunction(LLVMValueRef Fn);
Gordon Henriksenc23b66c2007-09-26 20:56:12 +0000511unsigned LLVMGetIntrinsicID(LLVMValueRef Fn);
512unsigned LLVMGetFunctionCallConv(LLVMValueRef Fn);
513void LLVMSetFunctionCallConv(LLVMValueRef Fn, unsigned CC);
Gordon Henriksend930f912008-08-17 18:44:35 +0000514const char *LLVMGetGC(LLVMValueRef Fn);
515void LLVMSetGC(LLVMValueRef Fn, const char *Name);
Duncan Sands7374a012009-05-06 12:21:17 +0000516void LLVMAddFunctionAttr(LLVMValueRef Fn, LLVMAttribute PA);
517void LLVMRemoveFunctionAttr(LLVMValueRef Fn, LLVMAttribute PA);
Gordon Henriksenc23b66c2007-09-26 20:56:12 +0000518
Gordon Henriksen265f7802008-03-19 01:11:35 +0000519/* Operations on parameters */
520unsigned LLVMCountParams(LLVMValueRef Fn);
521void LLVMGetParams(LLVMValueRef Fn, LLVMValueRef *Params);
522LLVMValueRef LLVMGetParam(LLVMValueRef Fn, unsigned Index);
523LLVMValueRef LLVMGetParamParent(LLVMValueRef Inst);
Gordon Henriksen07a45f42008-03-23 22:21:29 +0000524LLVMValueRef LLVMGetFirstParam(LLVMValueRef Fn);
525LLVMValueRef LLVMGetLastParam(LLVMValueRef Fn);
526LLVMValueRef LLVMGetNextParam(LLVMValueRef Arg);
527LLVMValueRef LLVMGetPreviousParam(LLVMValueRef Arg);
Devang Patel4c758ea2008-09-25 21:00:45 +0000528void LLVMAddAttribute(LLVMValueRef Arg, LLVMAttribute PA);
529void LLVMRemoveAttribute(LLVMValueRef Arg, LLVMAttribute PA);
Gordon Henriksen2d9cc212008-04-28 17:37:06 +0000530void LLVMSetParamAlignment(LLVMValueRef Arg, unsigned align);
Gordon Henriksen265f7802008-03-19 01:11:35 +0000531
Gordon Henriksenc23b66c2007-09-26 20:56:12 +0000532/* Operations on basic blocks */
Gordon Henriksen07a45f42008-03-23 22:21:29 +0000533LLVMValueRef LLVMBasicBlockAsValue(LLVMBasicBlockRef BB);
Gordon Henriksenc23b66c2007-09-26 20:56:12 +0000534int LLVMValueIsBasicBlock(LLVMValueRef Val);
535LLVMBasicBlockRef LLVMValueAsBasicBlock(LLVMValueRef Val);
Gordon Henriksen07a45f42008-03-23 22:21:29 +0000536LLVMValueRef LLVMGetBasicBlockParent(LLVMBasicBlockRef BB);
Gordon Henriksenc23b66c2007-09-26 20:56:12 +0000537unsigned LLVMCountBasicBlocks(LLVMValueRef Fn);
538void LLVMGetBasicBlocks(LLVMValueRef Fn, LLVMBasicBlockRef *BasicBlocks);
Gordon Henriksen054817c2008-03-19 03:47:18 +0000539LLVMBasicBlockRef LLVMGetFirstBasicBlock(LLVMValueRef Fn);
540LLVMBasicBlockRef LLVMGetLastBasicBlock(LLVMValueRef Fn);
541LLVMBasicBlockRef LLVMGetNextBasicBlock(LLVMBasicBlockRef BB);
542LLVMBasicBlockRef LLVMGetPreviousBasicBlock(LLVMBasicBlockRef BB);
Gordon Henriksenc23b66c2007-09-26 20:56:12 +0000543LLVMBasicBlockRef LLVMGetEntryBasicBlock(LLVMValueRef Fn);
544LLVMBasicBlockRef LLVMAppendBasicBlock(LLVMValueRef Fn, const char *Name);
545LLVMBasicBlockRef LLVMInsertBasicBlock(LLVMBasicBlockRef InsertBeforeBB,
546 const char *Name);
547void LLVMDeleteBasicBlock(LLVMBasicBlockRef BB);
548
Gordon Henriksen265f7802008-03-19 01:11:35 +0000549/* Operations on instructions */
550LLVMBasicBlockRef LLVMGetInstructionParent(LLVMValueRef Inst);
Gordon Henriksen054817c2008-03-19 03:47:18 +0000551LLVMValueRef LLVMGetFirstInstruction(LLVMBasicBlockRef BB);
552LLVMValueRef LLVMGetLastInstruction(LLVMBasicBlockRef BB);
553LLVMValueRef LLVMGetNextInstruction(LLVMValueRef Inst);
554LLVMValueRef LLVMGetPreviousInstruction(LLVMValueRef Inst);
Gordon Henriksen265f7802008-03-19 01:11:35 +0000555
Gordon Henriksen1158c532007-12-29 20:45:00 +0000556/* Operations on call sites */
557void LLVMSetInstructionCallConv(LLVMValueRef Instr, unsigned CC);
558unsigned LLVMGetInstructionCallConv(LLVMValueRef Instr);
Devang Patel4c758ea2008-09-25 21:00:45 +0000559void LLVMAddInstrAttribute(LLVMValueRef Instr, unsigned index, LLVMAttribute);
560void LLVMRemoveInstrAttribute(LLVMValueRef Instr, unsigned index,
561 LLVMAttribute);
Gordon Henriksen2d9cc212008-04-28 17:37:06 +0000562void LLVMSetInstrParamAlignment(LLVMValueRef Instr, unsigned index,
563 unsigned align);
Gordon Henriksen1158c532007-12-29 20:45:00 +0000564
Gordon Henrikseneeb65372008-08-30 16:34:54 +0000565/* Operations on call instructions (only) */
566int LLVMIsTailCall(LLVMValueRef CallInst);
567void LLVMSetTailCall(LLVMValueRef CallInst, int IsTailCall);
568
Gordon Henriksen44dd8fb2007-10-08 18:14:39 +0000569/* Operations on phi nodes */
570void LLVMAddIncoming(LLVMValueRef PhiNode, LLVMValueRef *IncomingValues,
571 LLVMBasicBlockRef *IncomingBlocks, unsigned Count);
572unsigned LLVMCountIncoming(LLVMValueRef PhiNode);
573LLVMValueRef LLVMGetIncomingValue(LLVMValueRef PhiNode, unsigned Index);
574LLVMBasicBlockRef LLVMGetIncomingBlock(LLVMValueRef PhiNode, unsigned Index);
Gordon Henriksenc23b66c2007-09-26 20:56:12 +0000575
576/*===-- Instruction builders ----------------------------------------------===*/
577
578/* An instruction builder represents a point within a basic block, and is the
579 * exclusive means of building instructions using the C interface.
580 */
581
Gordon Henriksena735a9c2008-05-04 12:55:34 +0000582LLVMBuilderRef LLVMCreateBuilder(void);
Gordon Henriksen054817c2008-03-19 03:47:18 +0000583void LLVMPositionBuilder(LLVMBuilderRef Builder, LLVMBasicBlockRef Block,
584 LLVMValueRef Instr);
Gordon Henriksenc23b66c2007-09-26 20:56:12 +0000585void LLVMPositionBuilderBefore(LLVMBuilderRef Builder, LLVMValueRef Instr);
586void LLVMPositionBuilderAtEnd(LLVMBuilderRef Builder, LLVMBasicBlockRef Block);
Gordon Henriksen265f7802008-03-19 01:11:35 +0000587LLVMBasicBlockRef LLVMGetInsertBlock(LLVMBuilderRef Builder);
Chris Lattner3d1f5522008-12-17 21:39:50 +0000588void LLVMClearInsertionPosition(LLVMBuilderRef Builder);
589void LLVMInsertIntoBuilder(LLVMBuilderRef Builder, LLVMValueRef Instr);
Gordon Henriksenc23b66c2007-09-26 20:56:12 +0000590void LLVMDisposeBuilder(LLVMBuilderRef Builder);
591
592/* Terminators */
593LLVMValueRef LLVMBuildRetVoid(LLVMBuilderRef);
594LLVMValueRef LLVMBuildRet(LLVMBuilderRef, LLVMValueRef V);
595LLVMValueRef LLVMBuildBr(LLVMBuilderRef, LLVMBasicBlockRef Dest);
596LLVMValueRef LLVMBuildCondBr(LLVMBuilderRef, LLVMValueRef If,
597 LLVMBasicBlockRef Then, LLVMBasicBlockRef Else);
598LLVMValueRef LLVMBuildSwitch(LLVMBuilderRef, LLVMValueRef V,
599 LLVMBasicBlockRef Else, unsigned NumCases);
600LLVMValueRef LLVMBuildInvoke(LLVMBuilderRef, LLVMValueRef Fn,
601 LLVMValueRef *Args, unsigned NumArgs,
602 LLVMBasicBlockRef Then, LLVMBasicBlockRef Catch,
603 const char *Name);
604LLVMValueRef LLVMBuildUnwind(LLVMBuilderRef);
605LLVMValueRef LLVMBuildUnreachable(LLVMBuilderRef);
606
Gordon Henriksen097102c2008-01-01 05:50:53 +0000607/* Add a case to the switch instruction */
608void LLVMAddCase(LLVMValueRef Switch, LLVMValueRef OnVal,
609 LLVMBasicBlockRef Dest);
610
Gordon Henriksenc23b66c2007-09-26 20:56:12 +0000611/* Arithmetic */
612LLVMValueRef LLVMBuildAdd(LLVMBuilderRef, LLVMValueRef LHS, LLVMValueRef RHS,
613 const char *Name);
614LLVMValueRef LLVMBuildSub(LLVMBuilderRef, LLVMValueRef LHS, LLVMValueRef RHS,
615 const char *Name);
616LLVMValueRef LLVMBuildMul(LLVMBuilderRef, LLVMValueRef LHS, LLVMValueRef RHS,
617 const char *Name);
618LLVMValueRef LLVMBuildUDiv(LLVMBuilderRef, LLVMValueRef LHS, LLVMValueRef RHS,
619 const char *Name);
620LLVMValueRef LLVMBuildSDiv(LLVMBuilderRef, LLVMValueRef LHS, LLVMValueRef RHS,
621 const char *Name);
622LLVMValueRef LLVMBuildFDiv(LLVMBuilderRef, LLVMValueRef LHS, LLVMValueRef RHS,
623 const char *Name);
624LLVMValueRef LLVMBuildURem(LLVMBuilderRef, LLVMValueRef LHS, LLVMValueRef RHS,
625 const char *Name);
626LLVMValueRef LLVMBuildSRem(LLVMBuilderRef, LLVMValueRef LHS, LLVMValueRef RHS,
627 const char *Name);
628LLVMValueRef LLVMBuildFRem(LLVMBuilderRef, LLVMValueRef LHS, LLVMValueRef RHS,
629 const char *Name);
630LLVMValueRef LLVMBuildShl(LLVMBuilderRef, LLVMValueRef LHS, LLVMValueRef RHS,
631 const char *Name);
632LLVMValueRef LLVMBuildLShr(LLVMBuilderRef, LLVMValueRef LHS, LLVMValueRef RHS,
633 const char *Name);
634LLVMValueRef LLVMBuildAShr(LLVMBuilderRef, LLVMValueRef LHS, LLVMValueRef RHS,
635 const char *Name);
636LLVMValueRef LLVMBuildAnd(LLVMBuilderRef, LLVMValueRef LHS, LLVMValueRef RHS,
637 const char *Name);
638LLVMValueRef LLVMBuildOr(LLVMBuilderRef, LLVMValueRef LHS, LLVMValueRef RHS,
639 const char *Name);
640LLVMValueRef LLVMBuildXor(LLVMBuilderRef, LLVMValueRef LHS, LLVMValueRef RHS,
641 const char *Name);
642LLVMValueRef LLVMBuildNeg(LLVMBuilderRef, LLVMValueRef V, const char *Name);
643LLVMValueRef LLVMBuildNot(LLVMBuilderRef, LLVMValueRef V, const char *Name);
644
645/* Memory */
646LLVMValueRef LLVMBuildMalloc(LLVMBuilderRef, LLVMTypeRef Ty, const char *Name);
647LLVMValueRef LLVMBuildArrayMalloc(LLVMBuilderRef, LLVMTypeRef Ty,
648 LLVMValueRef Val, const char *Name);
649LLVMValueRef LLVMBuildAlloca(LLVMBuilderRef, LLVMTypeRef Ty, const char *Name);
650LLVMValueRef LLVMBuildArrayAlloca(LLVMBuilderRef, LLVMTypeRef Ty,
651 LLVMValueRef Val, const char *Name);
652LLVMValueRef LLVMBuildFree(LLVMBuilderRef, LLVMValueRef PointerVal);
653LLVMValueRef LLVMBuildLoad(LLVMBuilderRef, LLVMValueRef PointerVal,
654 const char *Name);
655LLVMValueRef LLVMBuildStore(LLVMBuilderRef, LLVMValueRef Val, LLVMValueRef Ptr);
656LLVMValueRef LLVMBuildGEP(LLVMBuilderRef B, LLVMValueRef Pointer,
657 LLVMValueRef *Indices, unsigned NumIndices,
658 const char *Name);
659
660/* Casts */
661LLVMValueRef LLVMBuildTrunc(LLVMBuilderRef, LLVMValueRef Val,
662 LLVMTypeRef DestTy, const char *Name);
663LLVMValueRef LLVMBuildZExt(LLVMBuilderRef, LLVMValueRef Val,
664 LLVMTypeRef DestTy, const char *Name);
665LLVMValueRef LLVMBuildSExt(LLVMBuilderRef, LLVMValueRef Val,
666 LLVMTypeRef DestTy, const char *Name);
667LLVMValueRef LLVMBuildFPToUI(LLVMBuilderRef, LLVMValueRef Val,
668 LLVMTypeRef DestTy, const char *Name);
669LLVMValueRef LLVMBuildFPToSI(LLVMBuilderRef, LLVMValueRef Val,
670 LLVMTypeRef DestTy, const char *Name);
671LLVMValueRef LLVMBuildUIToFP(LLVMBuilderRef, LLVMValueRef Val,
672 LLVMTypeRef DestTy, const char *Name);
673LLVMValueRef LLVMBuildSIToFP(LLVMBuilderRef, LLVMValueRef Val,
674 LLVMTypeRef DestTy, const char *Name);
675LLVMValueRef LLVMBuildFPTrunc(LLVMBuilderRef, LLVMValueRef Val,
676 LLVMTypeRef DestTy, const char *Name);
677LLVMValueRef LLVMBuildFPExt(LLVMBuilderRef, LLVMValueRef Val,
678 LLVMTypeRef DestTy, const char *Name);
679LLVMValueRef LLVMBuildPtrToInt(LLVMBuilderRef, LLVMValueRef Val,
680 LLVMTypeRef DestTy, const char *Name);
681LLVMValueRef LLVMBuildIntToPtr(LLVMBuilderRef, LLVMValueRef Val,
682 LLVMTypeRef DestTy, const char *Name);
683LLVMValueRef LLVMBuildBitCast(LLVMBuilderRef, LLVMValueRef Val,
684 LLVMTypeRef DestTy, const char *Name);
685
686/* Comparisons */
687LLVMValueRef LLVMBuildICmp(LLVMBuilderRef, LLVMIntPredicate Op,
688 LLVMValueRef LHS, LLVMValueRef RHS,
689 const char *Name);
690LLVMValueRef LLVMBuildFCmp(LLVMBuilderRef, LLVMRealPredicate Op,
691 LLVMValueRef LHS, LLVMValueRef RHS,
692 const char *Name);
693
694/* Miscellaneous instructions */
695LLVMValueRef LLVMBuildPhi(LLVMBuilderRef, LLVMTypeRef Ty, const char *Name);
696LLVMValueRef LLVMBuildCall(LLVMBuilderRef, LLVMValueRef Fn,
697 LLVMValueRef *Args, unsigned NumArgs,
698 const char *Name);
699LLVMValueRef LLVMBuildSelect(LLVMBuilderRef, LLVMValueRef If,
700 LLVMValueRef Then, LLVMValueRef Else,
701 const char *Name);
702LLVMValueRef LLVMBuildVAArg(LLVMBuilderRef, LLVMValueRef List, LLVMTypeRef Ty,
703 const char *Name);
704LLVMValueRef LLVMBuildExtractElement(LLVMBuilderRef, LLVMValueRef VecVal,
705 LLVMValueRef Index, const char *Name);
706LLVMValueRef LLVMBuildInsertElement(LLVMBuilderRef, LLVMValueRef VecVal,
707 LLVMValueRef EltVal, LLVMValueRef Index,
708 const char *Name);
709LLVMValueRef LLVMBuildShuffleVector(LLVMBuilderRef, LLVMValueRef V1,
710 LLVMValueRef V2, LLVMValueRef Mask,
711 const char *Name);
Dan Gohmand5104a52008-11-03 22:55:43 +0000712LLVMValueRef LLVMBuildExtractValue(LLVMBuilderRef, LLVMValueRef AggVal,
713 unsigned Index, const char *Name);
714LLVMValueRef LLVMBuildInsertValue(LLVMBuilderRef, LLVMValueRef AggVal,
715 LLVMValueRef EltVal, unsigned Index,
716 const char *Name);
Gordon Henriksen76a03742007-09-18 03:18:57 +0000717
Gordon Henriksen34eb6d82007-12-19 22:30:40 +0000718
Gordon Henriksen0a68fe22007-12-12 01:04:30 +0000719/*===-- Module providers --------------------------------------------------===*/
720
721/* Encapsulates the module M in a module provider, taking ownership of the
722 * module.
723 * See the constructor llvm::ExistingModuleProvider::ExistingModuleProvider.
724 */
725LLVMModuleProviderRef
726LLVMCreateModuleProviderForExistingModule(LLVMModuleRef M);
727
728/* Destroys the module provider MP as well as the contained module.
729 * See the destructor llvm::ModuleProvider::~ModuleProvider.
730 */
731void LLVMDisposeModuleProvider(LLVMModuleProviderRef MP);
732
Gordon Henriksen34eb6d82007-12-19 22:30:40 +0000733
734/*===-- Memory buffers ----------------------------------------------------===*/
735
736int LLVMCreateMemoryBufferWithContentsOfFile(const char *Path,
737 LLVMMemoryBufferRef *OutMemBuf,
738 char **OutMessage);
739int LLVMCreateMemoryBufferWithSTDIN(LLVMMemoryBufferRef *OutMemBuf,
740 char **OutMessage);
741void LLVMDisposeMemoryBuffer(LLVMMemoryBufferRef MemBuf);
742
Gordon Henriksen878114b2008-03-16 04:20:44 +0000743
744/*===-- Pass Managers -----------------------------------------------------===*/
745
746/** Constructs a new whole-module pass pipeline. This type of pipeline is
747 suitable for link-time optimization and whole-module transformations.
748 See llvm::PassManager::PassManager. */
Gordon Henriksena735a9c2008-05-04 12:55:34 +0000749LLVMPassManagerRef LLVMCreatePassManager(void);
Gordon Henriksen878114b2008-03-16 04:20:44 +0000750
751/** Constructs a new function-by-function pass pipeline over the module
752 provider. It does not take ownership of the module provider. This type of
753 pipeline is suitable for code generation and JIT compilation tasks.
754 See llvm::FunctionPassManager::FunctionPassManager. */
755LLVMPassManagerRef LLVMCreateFunctionPassManager(LLVMModuleProviderRef MP);
756
757/** Initializes, executes on the provided module, and finalizes all of the
758 passes scheduled in the pass manager. Returns 1 if any of the passes
759 modified the module, 0 otherwise. See llvm::PassManager::run(Module&). */
760int LLVMRunPassManager(LLVMPassManagerRef PM, LLVMModuleRef M);
761
762/** Initializes all of the function passes scheduled in the function pass
763 manager. Returns 1 if any of the passes modified the module, 0 otherwise.
764 See llvm::FunctionPassManager::doInitialization. */
765int LLVMInitializeFunctionPassManager(LLVMPassManagerRef FPM);
766
767/** Executes all of the function passes scheduled in the function pass manager
768 on the provided function. Returns 1 if any of the passes modified the
769 function, false otherwise.
770 See llvm::FunctionPassManager::run(Function&). */
771int LLVMRunFunctionPassManager(LLVMPassManagerRef FPM, LLVMValueRef F);
772
773/** Finalizes all of the function passes scheduled in in the function pass
774 manager. Returns 1 if any of the passes modified the module, 0 otherwise.
775 See llvm::FunctionPassManager::doFinalization. */
776int LLVMFinalizeFunctionPassManager(LLVMPassManagerRef FPM);
777
778/** Frees the memory of a pass pipeline. For function pipelines, does not free
779 the module provider.
780 See llvm::PassManagerBase::~PassManagerBase. */
781void LLVMDisposePassManager(LLVMPassManagerRef PM);
782
783
Gordon Henriksen76a03742007-09-18 03:18:57 +0000784#ifdef __cplusplus
785}
Gordon Henriksen76a03742007-09-18 03:18:57 +0000786
Gordon Henriksen7330acd2007-10-05 23:59:36 +0000787namespace llvm {
Gordon Henriksen0a68fe22007-12-12 01:04:30 +0000788 class ModuleProvider;
Gordon Henriksen34eb6d82007-12-19 22:30:40 +0000789 class MemoryBuffer;
Gordon Henriksen96571492008-03-16 15:55:43 +0000790 class PassManagerBase;
Gordon Henriksen0a68fe22007-12-12 01:04:30 +0000791
Gordon Henriksen34eb6d82007-12-19 22:30:40 +0000792 #define DEFINE_SIMPLE_CONVERSION_FUNCTIONS(ty, ref) \
793 inline ty *unwrap(ref P) { \
794 return reinterpret_cast<ty*>(P); \
795 } \
796 \
797 inline ref wrap(const ty *P) { \
798 return reinterpret_cast<ref>(const_cast<ty*>(P)); \
799 }
Gordon Henriksen7330acd2007-10-05 23:59:36 +0000800
Gordon Henriksen878114b2008-03-16 04:20:44 +0000801 #define DEFINE_ISA_CONVERSION_FUNCTIONS(ty, ref) \
802 DEFINE_SIMPLE_CONVERSION_FUNCTIONS(ty, ref) \
803 \
804 template<typename T> \
805 inline T *unwrap(ref P) { \
806 return cast<T>(unwrap(P)); \
807 }
808
809 #define DEFINE_STDCXX_CONVERSION_FUNCTIONS(ty, ref) \
810 DEFINE_SIMPLE_CONVERSION_FUNCTIONS(ty, ref) \
811 \
812 template<typename T> \
813 inline T *unwrap(ref P) { \
814 T *Q = dynamic_cast<T*>(unwrap(P)); \
815 assert(Q && "Invalid cast!"); \
816 return Q; \
817 }
818
819 DEFINE_ISA_CONVERSION_FUNCTIONS (Type, LLVMTypeRef )
820 DEFINE_ISA_CONVERSION_FUNCTIONS (Value, LLVMValueRef )
Gordon Henriksen823f9732007-12-27 18:25:59 +0000821 DEFINE_SIMPLE_CONVERSION_FUNCTIONS(Module, LLVMModuleRef )
822 DEFINE_SIMPLE_CONVERSION_FUNCTIONS(BasicBlock, LLVMBasicBlockRef )
Eric Christopher59278832008-08-08 19:39:37 +0000823 DEFINE_SIMPLE_CONVERSION_FUNCTIONS(IRBuilder<>, LLVMBuilderRef )
Gordon Henriksen823f9732007-12-27 18:25:59 +0000824 DEFINE_SIMPLE_CONVERSION_FUNCTIONS(PATypeHolder, LLVMTypeHandleRef )
825 DEFINE_SIMPLE_CONVERSION_FUNCTIONS(ModuleProvider, LLVMModuleProviderRef)
826 DEFINE_SIMPLE_CONVERSION_FUNCTIONS(MemoryBuffer, LLVMMemoryBufferRef )
Owen Anderson6773d382009-07-01 16:58:40 +0000827 DEFINE_SIMPLE_CONVERSION_FUNCTIONS(LLVMContext, LLVMContextRef )
Gordon Henriksen878114b2008-03-16 04:20:44 +0000828 DEFINE_STDCXX_CONVERSION_FUNCTIONS(PassManagerBase, LLVMPassManagerRef )
Gordon Henriksen7330acd2007-10-05 23:59:36 +0000829
Gordon Henriksen878114b2008-03-16 04:20:44 +0000830 #undef DEFINE_STDCXX_CONVERSION_FUNCTIONS
831 #undef DEFINE_ISA_CONVERSION_FUNCTIONS
Gordon Henriksen34eb6d82007-12-19 22:30:40 +0000832 #undef DEFINE_SIMPLE_CONVERSION_FUNCTIONS
Gordon Henriksen7330acd2007-10-05 23:59:36 +0000833
Gordon Henriksen34eb6d82007-12-19 22:30:40 +0000834 /* Specialized opaque type conversions.
835 */
Gordon Henriksen7330acd2007-10-05 23:59:36 +0000836 inline Type **unwrap(LLVMTypeRef* Tys) {
837 return reinterpret_cast<Type**>(Tys);
838 }
839
Gordon Henriksen7330acd2007-10-05 23:59:36 +0000840 inline LLVMTypeRef *wrap(const Type **Tys) {
841 return reinterpret_cast<LLVMTypeRef*>(const_cast<Type**>(Tys));
842 }
843
Gordon Henriksen34eb6d82007-12-19 22:30:40 +0000844 /* Specialized opaque value conversions.
Gordon Henriksen7330acd2007-10-05 23:59:36 +0000845 */
Gordon Henriksen7330acd2007-10-05 23:59:36 +0000846 inline Value **unwrap(LLVMValueRef *Vals) {
847 return reinterpret_cast<Value**>(Vals);
848 }
849
850 template<typename T>
851 inline T **unwrap(LLVMValueRef *Vals, unsigned Length) {
852 #if DEBUG
853 for (LLVMValueRef *I = Vals, E = Vals + Length; I != E; ++I)
854 cast<T>(*I);
855 #endif
856 return reinterpret_cast<T**>(Vals);
857 }
858
Gordon Henriksen7330acd2007-10-05 23:59:36 +0000859 inline LLVMValueRef *wrap(const Value **Vals) {
860 return reinterpret_cast<LLVMValueRef*>(const_cast<Value**>(Vals));
861 }
Gordon Henriksen7330acd2007-10-05 23:59:36 +0000862}
863
864#endif /* !defined(__cplusplus) */
865
866#endif /* !defined(LLVM_C_CORE_H) */