blob: 0d6e2488c5dc3f18030b3fe19499d1f3d67addfb [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,
Anton Korobeynikovc8ce7b082009-07-17 18:07:26 +0000101 LLVMReadOnlyAttribute = 1<<10,
Anton Korobeynikov9750be92009-07-17 18:57:16 +0000102 LLVMNoInlineAttribute = 1<<11,
103 LLVMAlwaysInlineAttribute = 1<<12,
104 LLVMOptimizeForSizeAttribute = 1<<13,
105 LLVMStackProtectAttribute = 1<<14,
106 LLVMStackProtectReqAttribute = 1<<15,
107 LLVMNoCaptureAttribute = 1<<21,
108 LLVMNoRedZoneAttribute = 1<<22,
109 LLVMNoImplicitFloatAttribute = 1<<23,
Anton Korobeynikovc8ce7b082009-07-17 18:07:26 +0000110 LLVMNakedAttribute = 1<<24
Devang Patel4c758ea2008-09-25 21:00:45 +0000111} LLVMAttribute;
Gordon Henriksen2d9cc212008-04-28 17:37:06 +0000112
113typedef enum {
Gordon Henriksen4a4d7352007-12-30 17:46:33 +0000114 LLVMVoidTypeKind, /**< type with no size */
115 LLVMFloatTypeKind, /**< 32 bit floating point type */
116 LLVMDoubleTypeKind, /**< 64 bit floating point type */
117 LLVMX86_FP80TypeKind, /**< 80 bit floating point type (X87) */
118 LLVMFP128TypeKind, /**< 128 bit floating point type (112-bit mantissa)*/
119 LLVMPPC_FP128TypeKind, /**< 128 bit floating point type (two 64-bits) */
120 LLVMLabelTypeKind, /**< Labels */
121 LLVMIntegerTypeKind, /**< Arbitrary bit width integers */
122 LLVMFunctionTypeKind, /**< Functions */
123 LLVMStructTypeKind, /**< Structures */
124 LLVMArrayTypeKind, /**< Arrays */
125 LLVMPointerTypeKind, /**< Pointers */
126 LLVMOpaqueTypeKind, /**< Opaque: type with unknown structure */
Chris Lattnerdac44ec2009-07-15 22:00:31 +0000127 LLVMVectorTypeKind, /**< SIMD 'packed' format, or other vector type */
128 LLVMMetadataTypeKind /**< Metadata */
Gordon Henriksen76a03742007-09-18 03:18:57 +0000129} LLVMTypeKind;
130
131typedef enum {
Gordon Henriksen4a4d7352007-12-30 17:46:33 +0000132 LLVMExternalLinkage, /**< Externally visible function */
Chris Lattner2dba0f02009-04-13 06:25:37 +0000133 LLVMAvailableExternallyLinkage,
Duncan Sands12da8ce2009-03-07 15:45:40 +0000134 LLVMLinkOnceAnyLinkage, /**< Keep one copy of function when linking (inline)*/
135 LLVMLinkOnceODRLinkage, /**< Same, but only replaced by something
136 equivalent. */
137 LLVMWeakAnyLinkage, /**< Keep one copy of function when linking (weak) */
138 LLVMWeakODRLinkage, /**< Same, but only replaced by something
139 equivalent. */
Gordon Henriksen4a4d7352007-12-30 17:46:33 +0000140 LLVMAppendingLinkage, /**< Special purpose, only applies to global arrays */
141 LLVMInternalLinkage, /**< Rename collisions when linking (static
142 functions) */
Duncan Sands12da8ce2009-03-07 15:45:40 +0000143 LLVMPrivateLinkage, /**< Like Internal, but omit from symbol table */
Gordon Henriksen4a4d7352007-12-30 17:46:33 +0000144 LLVMDLLImportLinkage, /**< Function to be imported from DLL */
145 LLVMDLLExportLinkage, /**< Function to be accessible from DLL */
Duncan Sandse2881052009-03-11 08:08:06 +0000146 LLVMExternalWeakLinkage,/**< ExternalWeak linkage description */
Duncan Sands12da8ce2009-03-07 15:45:40 +0000147 LLVMGhostLinkage, /**< Stand-in functions for streaming fns from
Gordon Henriksen4a4d7352007-12-30 17:46:33 +0000148 bitcode */
Bill Wendling002b1672009-07-20 18:22:52 +0000149 LLVMCommonLinkage, /**< Tentative definitions */
150 LLVMLinkerPrivateLinkage /**< Like Private, but linker removes. */
Gordon Henriksen76a03742007-09-18 03:18:57 +0000151} LLVMLinkage;
152
153typedef enum {
Gordon Henriksen4a4d7352007-12-30 17:46:33 +0000154 LLVMDefaultVisibility, /**< The GV is visible */
155 LLVMHiddenVisibility, /**< The GV is hidden */
156 LLVMProtectedVisibility /**< The GV is protected */
Gordon Henriksen76a03742007-09-18 03:18:57 +0000157} LLVMVisibility;
158
Gordon Henriksenc23b66c2007-09-26 20:56:12 +0000159typedef enum {
160 LLVMCCallConv = 0,
161 LLVMFastCallConv = 8,
162 LLVMColdCallConv = 9,
163 LLVMX86StdcallCallConv = 64,
164 LLVMX86FastcallCallConv = 65
165} LLVMCallConv;
166
167typedef enum {
Gordon Henriksen4a4d7352007-12-30 17:46:33 +0000168 LLVMIntEQ = 32, /**< equal */
169 LLVMIntNE, /**< not equal */
170 LLVMIntUGT, /**< unsigned greater than */
171 LLVMIntUGE, /**< unsigned greater or equal */
172 LLVMIntULT, /**< unsigned less than */
173 LLVMIntULE, /**< unsigned less or equal */
174 LLVMIntSGT, /**< signed greater than */
175 LLVMIntSGE, /**< signed greater or equal */
176 LLVMIntSLT, /**< signed less than */
177 LLVMIntSLE /**< signed less or equal */
Gordon Henriksenc23b66c2007-09-26 20:56:12 +0000178} LLVMIntPredicate;
179
180typedef enum {
Gordon Henriksen4a4d7352007-12-30 17:46:33 +0000181 LLVMRealPredicateFalse, /**< Always false (always folded) */
182 LLVMRealOEQ, /**< True if ordered and equal */
183 LLVMRealOGT, /**< True if ordered and greater than */
184 LLVMRealOGE, /**< True if ordered and greater than or equal */
185 LLVMRealOLT, /**< True if ordered and less than */
186 LLVMRealOLE, /**< True if ordered and less than or equal */
187 LLVMRealONE, /**< True if ordered and operands are unequal */
188 LLVMRealORD, /**< True if ordered (no nans) */
189 LLVMRealUNO, /**< True if unordered: isnan(X) | isnan(Y) */
190 LLVMRealUEQ, /**< True if unordered or equal */
191 LLVMRealUGT, /**< True if unordered or greater than */
192 LLVMRealUGE, /**< True if unordered, greater than, or equal */
193 LLVMRealULT, /**< True if unordered or less than */
194 LLVMRealULE, /**< True if unordered, less than, or equal */
195 LLVMRealUNE, /**< True if unordered or not equal */
196 LLVMRealPredicateTrue /**< Always true (always folded) */
Gordon Henriksenc23b66c2007-09-26 20:56:12 +0000197} LLVMRealPredicate;
198
Gordon Henriksen76a03742007-09-18 03:18:57 +0000199
Gordon Henriksen34eb6d82007-12-19 22:30:40 +0000200/*===-- Error handling ----------------------------------------------------===*/
201
202void LLVMDisposeMessage(char *Message);
203
204
Gordon Henriksen76a03742007-09-18 03:18:57 +0000205/*===-- Modules -----------------------------------------------------------===*/
206
Owen Anderson6773d382009-07-01 16:58:40 +0000207/* Create and destroy contexts. */
208LLVMContextRef LLVMContextCreate();
Owen Andersonf7691d32009-07-02 00:16:38 +0000209LLVMContextRef LLVMGetGlobalContext();
Owen Anderson6773d382009-07-01 16:58:40 +0000210void LLVMContextDispose(LLVMContextRef C);
211
Gordon Henriksen76a03742007-09-18 03:18:57 +0000212/* Create and destroy modules. */
Gordon Henriksena49d4352008-03-07 19:13:06 +0000213/** See llvm::Module::Module. */
Gordon Henriksen76a03742007-09-18 03:18:57 +0000214LLVMModuleRef LLVMModuleCreateWithName(const char *ModuleID);
Owen Anderson31d44e42009-07-02 07:17:57 +0000215LLVMModuleRef LLVMModuleCreateWithNameInContext(const char *ModuleID,
216 LLVMContextRef C);
Gordon Henriksena49d4352008-03-07 19:13:06 +0000217
218/** See llvm::Module::~Module. */
Gordon Henriksen76a03742007-09-18 03:18:57 +0000219void LLVMDisposeModule(LLVMModuleRef M);
220
Gordon Henriksena49d4352008-03-07 19:13:06 +0000221/** Data layout. See Module::getDataLayout. */
Gordon Henriksen05568bb2007-12-27 20:13:47 +0000222const char *LLVMGetDataLayout(LLVMModuleRef M);
223void LLVMSetDataLayout(LLVMModuleRef M, const char *Triple);
224
Gordon Henriksena49d4352008-03-07 19:13:06 +0000225/** Target triple. See Module::getTargetTriple. */
Gordon Henriksen05568bb2007-12-27 20:13:47 +0000226const char *LLVMGetTarget(LLVMModuleRef M);
227void LLVMSetTarget(LLVMModuleRef M, const char *Triple);
228
Gordon Henriksena49d4352008-03-07 19:13:06 +0000229/** See Module::addTypeName. */
Gordon Henriksen76a03742007-09-18 03:18:57 +0000230int LLVMAddTypeName(LLVMModuleRef M, const char *Name, LLVMTypeRef Ty);
Gordon Henriksenc23b66c2007-09-26 20:56:12 +0000231void LLVMDeleteTypeName(LLVMModuleRef M, const char *Name);
Chris Lattner7f318242009-07-06 17:29:59 +0000232LLVMTypeRef LLVMGetTypeByName(LLVMModuleRef M, const char *Name);
Gordon Henriksen76a03742007-09-18 03:18:57 +0000233
Gordon Henriksen6c6075e2008-03-14 23:58:56 +0000234/** See Module::dump. */
235void LLVMDumpModule(LLVMModuleRef M);
236
Gordon Henriksen76a03742007-09-18 03:18:57 +0000237
Gordon Henriksenc23b66c2007-09-26 20:56:12 +0000238/*===-- Types -------------------------------------------------------------===*/
Gordon Henriksen76a03742007-09-18 03:18:57 +0000239
240/* LLVM types conform to the following hierarchy:
241 *
242 * types:
243 * integer type
244 * real type
245 * function type
246 * sequence types:
247 * array type
248 * pointer type
249 * vector type
250 * void type
251 * label type
252 * opaque type
253 */
254
Gordon Henriksena49d4352008-03-07 19:13:06 +0000255/** See llvm::LLVMTypeKind::getTypeID. */
Gordon Henriksen76a03742007-09-18 03:18:57 +0000256LLVMTypeKind LLVMGetTypeKind(LLVMTypeRef Ty);
Gordon Henriksena49d4352008-03-07 19:13:06 +0000257
Gordon Henriksen76a03742007-09-18 03:18:57 +0000258/* Operations on integer types */
Gordon Henriksena735a9c2008-05-04 12:55:34 +0000259LLVMTypeRef LLVMInt1Type(void);
260LLVMTypeRef LLVMInt8Type(void);
261LLVMTypeRef LLVMInt16Type(void);
262LLVMTypeRef LLVMInt32Type(void);
263LLVMTypeRef LLVMInt64Type(void);
Gordon Henriksened7beaa2007-10-06 16:05:20 +0000264LLVMTypeRef LLVMIntType(unsigned NumBits);
Gordon Henriksenc23b66c2007-09-26 20:56:12 +0000265unsigned LLVMGetIntTypeWidth(LLVMTypeRef IntegerTy);
Gordon Henriksen76a03742007-09-18 03:18:57 +0000266
267/* Operations on real types */
Gordon Henriksena735a9c2008-05-04 12:55:34 +0000268LLVMTypeRef LLVMFloatType(void);
269LLVMTypeRef LLVMDoubleType(void);
270LLVMTypeRef LLVMX86FP80Type(void);
271LLVMTypeRef LLVMFP128Type(void);
272LLVMTypeRef LLVMPPCFP128Type(void);
Gordon Henriksen76a03742007-09-18 03:18:57 +0000273
274/* Operations on function types */
Gordon Henriksened7beaa2007-10-06 16:05:20 +0000275LLVMTypeRef LLVMFunctionType(LLVMTypeRef ReturnType,
276 LLVMTypeRef *ParamTypes, unsigned ParamCount,
277 int IsVarArg);
Gordon Henriksen76a03742007-09-18 03:18:57 +0000278int LLVMIsFunctionVarArg(LLVMTypeRef FunctionTy);
Gordon Henriksenc23b66c2007-09-26 20:56:12 +0000279LLVMTypeRef LLVMGetReturnType(LLVMTypeRef FunctionTy);
280unsigned LLVMCountParamTypes(LLVMTypeRef FunctionTy);
281void LLVMGetParamTypes(LLVMTypeRef FunctionTy, LLVMTypeRef *Dest);
Gordon Henriksen76a03742007-09-18 03:18:57 +0000282
283/* Operations on struct types */
Gordon Henriksened7beaa2007-10-06 16:05:20 +0000284LLVMTypeRef LLVMStructType(LLVMTypeRef *ElementTypes, unsigned ElementCount,
285 int Packed);
Gordon Henriksenc23b66c2007-09-26 20:56:12 +0000286unsigned LLVMCountStructElementTypes(LLVMTypeRef StructTy);
Gordon Henriksen76a03742007-09-18 03:18:57 +0000287void LLVMGetStructElementTypes(LLVMTypeRef StructTy, LLVMTypeRef *Dest);
288int LLVMIsPackedStruct(LLVMTypeRef StructTy);
289
290/* Operations on array, pointer, and vector types (sequence types) */
Gordon Henriksened7beaa2007-10-06 16:05:20 +0000291LLVMTypeRef LLVMArrayType(LLVMTypeRef ElementType, unsigned ElementCount);
Gordon Henriksen5a3fe032007-12-17 16:08:32 +0000292LLVMTypeRef LLVMPointerType(LLVMTypeRef ElementType, unsigned AddressSpace);
Gordon Henriksened7beaa2007-10-06 16:05:20 +0000293LLVMTypeRef LLVMVectorType(LLVMTypeRef ElementType, unsigned ElementCount);
Gordon Henriksen76a03742007-09-18 03:18:57 +0000294
295LLVMTypeRef LLVMGetElementType(LLVMTypeRef Ty);
296unsigned LLVMGetArrayLength(LLVMTypeRef ArrayTy);
Gordon Henriksen5a3fe032007-12-17 16:08:32 +0000297unsigned LLVMGetPointerAddressSpace(LLVMTypeRef PointerTy);
Gordon Henriksen76a03742007-09-18 03:18:57 +0000298unsigned LLVMGetVectorSize(LLVMTypeRef VectorTy);
299
300/* Operations on other types */
Gordon Henriksena735a9c2008-05-04 12:55:34 +0000301LLVMTypeRef LLVMVoidType(void);
302LLVMTypeRef LLVMLabelType(void);
303LLVMTypeRef LLVMOpaqueType(void);
Gordon Henriksen76a03742007-09-18 03:18:57 +0000304
Gordon Henriksenffb48762007-10-07 00:13:35 +0000305/* Operations on type handles */
306LLVMTypeHandleRef LLVMCreateTypeHandle(LLVMTypeRef PotentiallyAbstractTy);
307void LLVMRefineType(LLVMTypeRef AbstractTy, LLVMTypeRef ConcreteTy);
308LLVMTypeRef LLVMResolveTypeHandle(LLVMTypeHandleRef TypeHandle);
309void LLVMDisposeTypeHandle(LLVMTypeHandleRef TypeHandle);
310
Gordon Henriksen76a03742007-09-18 03:18:57 +0000311
312/*===-- Values ------------------------------------------------------------===*/
313
314/* The bulk of LLVM's object model consists of values, which comprise a very
315 * rich type hierarchy.
Gordon Henriksen76a03742007-09-18 03:18:57 +0000316 */
317
Gordon Henriksen29e38942008-12-19 18:39:45 +0000318#define LLVM_FOR_EACH_VALUE_SUBCLASS(macro) \
319 macro(Argument) \
320 macro(BasicBlock) \
321 macro(InlineAsm) \
322 macro(User) \
323 macro(Constant) \
324 macro(ConstantAggregateZero) \
325 macro(ConstantArray) \
326 macro(ConstantExpr) \
327 macro(ConstantFP) \
328 macro(ConstantInt) \
329 macro(ConstantPointerNull) \
330 macro(ConstantStruct) \
331 macro(ConstantVector) \
332 macro(GlobalValue) \
333 macro(Function) \
334 macro(GlobalAlias) \
335 macro(GlobalVariable) \
336 macro(UndefValue) \
337 macro(Instruction) \
338 macro(BinaryOperator) \
339 macro(CallInst) \
340 macro(IntrinsicInst) \
341 macro(DbgInfoIntrinsic) \
342 macro(DbgDeclareInst) \
343 macro(DbgFuncStartInst) \
344 macro(DbgRegionEndInst) \
345 macro(DbgRegionStartInst) \
346 macro(DbgStopPointInst) \
347 macro(EHSelectorInst) \
348 macro(MemIntrinsic) \
349 macro(MemCpyInst) \
350 macro(MemMoveInst) \
351 macro(MemSetInst) \
352 macro(CmpInst) \
353 macro(FCmpInst) \
354 macro(ICmpInst) \
Gordon Henriksen29e38942008-12-19 18:39:45 +0000355 macro(ExtractElementInst) \
356 macro(GetElementPtrInst) \
357 macro(InsertElementInst) \
358 macro(InsertValueInst) \
359 macro(PHINode) \
360 macro(SelectInst) \
361 macro(ShuffleVectorInst) \
362 macro(StoreInst) \
363 macro(TerminatorInst) \
364 macro(BranchInst) \
365 macro(InvokeInst) \
366 macro(ReturnInst) \
367 macro(SwitchInst) \
368 macro(UnreachableInst) \
369 macro(UnwindInst) \
370 macro(UnaryInstruction) \
371 macro(AllocationInst) \
Gordon Henriksen05a868f2008-12-19 18:51:17 +0000372 macro(AllocaInst) \
373 macro(MallocInst) \
Gordon Henriksen29e38942008-12-19 18:39:45 +0000374 macro(CastInst) \
Gordon Henriksen05a868f2008-12-19 18:51:17 +0000375 macro(BitCastInst) \
376 macro(FPExtInst) \
377 macro(FPToSIInst) \
378 macro(FPToUIInst) \
379 macro(FPTruncInst) \
380 macro(IntToPtrInst) \
381 macro(PtrToIntInst) \
382 macro(SExtInst) \
383 macro(SIToFPInst) \
384 macro(TruncInst) \
385 macro(UIToFPInst) \
386 macro(ZExtInst) \
387 macro(ExtractValueInst) \
388 macro(FreeInst) \
389 macro(LoadInst) \
390 macro(VAArgInst)
Gordon Henriksen29e38942008-12-19 18:39:45 +0000391
Gordon Henriksen76a03742007-09-18 03:18:57 +0000392/* Operations on all values */
Gordon Henriksenc23b66c2007-09-26 20:56:12 +0000393LLVMTypeRef LLVMTypeOf(LLVMValueRef Val);
Gordon Henriksen76a03742007-09-18 03:18:57 +0000394const char *LLVMGetValueName(LLVMValueRef Val);
395void LLVMSetValueName(LLVMValueRef Val, const char *Name);
Gordon Henriksen1d0d24c2007-10-06 00:08:49 +0000396void LLVMDumpValue(LLVMValueRef Val);
Gordon Henriksen76a03742007-09-18 03:18:57 +0000397
Gordon Henriksen29e38942008-12-19 18:39:45 +0000398/* Conversion functions. Return the input value if it is an instance of the
399 specified class, otherwise NULL. See llvm::dyn_cast_or_null<>. */
400#define LLVM_DECLARE_VALUE_CAST(name) \
401 LLVMValueRef LLVMIsA##name(LLVMValueRef Val);
402LLVM_FOR_EACH_VALUE_SUBCLASS(LLVM_DECLARE_VALUE_CAST)
403
Gordon Henriksen76a03742007-09-18 03:18:57 +0000404/* Operations on constants of any type */
Gordon Henriksen1046c732007-10-06 15:11:06 +0000405LLVMValueRef LLVMConstNull(LLVMTypeRef Ty); /* all zeroes */
406LLVMValueRef LLVMConstAllOnes(LLVMTypeRef Ty); /* only for int/vector */
Gordon Henriksen76a03742007-09-18 03:18:57 +0000407LLVMValueRef LLVMGetUndef(LLVMTypeRef Ty);
Gordon Henriksendc88c062007-09-18 18:07:51 +0000408int LLVMIsConstant(LLVMValueRef Val);
Gordon Henriksen76a03742007-09-18 03:18:57 +0000409int LLVMIsNull(LLVMValueRef Val);
Gordon Henriksendc88c062007-09-18 18:07:51 +0000410int LLVMIsUndef(LLVMValueRef Val);
Chris Lattner7f318242009-07-06 17:29:59 +0000411LLVMValueRef LLVMConstPointerNull(LLVMTypeRef Ty);
Gordon Henriksen76a03742007-09-18 03:18:57 +0000412
413/* Operations on scalar constants */
Gordon Henriksen1046c732007-10-06 15:11:06 +0000414LLVMValueRef LLVMConstInt(LLVMTypeRef IntTy, unsigned long long N,
415 int SignExtend);
416LLVMValueRef LLVMConstReal(LLVMTypeRef RealTy, double N);
Gordon Henriksen931e1212008-02-02 01:07:50 +0000417LLVMValueRef LLVMConstRealOfString(LLVMTypeRef RealTy, const char *Text);
Gordon Henriksen76a03742007-09-18 03:18:57 +0000418
419/* Operations on composite constants */
Gordon Henriksen1046c732007-10-06 15:11:06 +0000420LLVMValueRef LLVMConstString(const char *Str, unsigned Length,
421 int DontNullTerminate);
Gordon Henriksen2ad5aef2008-04-25 03:21:19 +0000422LLVMValueRef LLVMConstArray(LLVMTypeRef ElementTy,
Gordon Henriksen1046c732007-10-06 15:11:06 +0000423 LLVMValueRef *ConstantVals, unsigned Length);
424LLVMValueRef LLVMConstStruct(LLVMValueRef *ConstantVals, unsigned Count,
425 int packed);
426LLVMValueRef LLVMConstVector(LLVMValueRef *ScalarConstantVals, unsigned Size);
Gordon Henriksen76a03742007-09-18 03:18:57 +0000427
Gordon Henriksen7ce31762007-10-06 14:29:36 +0000428/* Constant expressions */
429LLVMValueRef LLVMSizeOf(LLVMTypeRef Ty);
430LLVMValueRef LLVMConstNeg(LLVMValueRef ConstantVal);
431LLVMValueRef LLVMConstNot(LLVMValueRef ConstantVal);
432LLVMValueRef LLVMConstAdd(LLVMValueRef LHSConstant, LLVMValueRef RHSConstant);
433LLVMValueRef LLVMConstSub(LLVMValueRef LHSConstant, LLVMValueRef RHSConstant);
434LLVMValueRef LLVMConstMul(LLVMValueRef LHSConstant, LLVMValueRef RHSConstant);
435LLVMValueRef LLVMConstUDiv(LLVMValueRef LHSConstant, LLVMValueRef RHSConstant);
436LLVMValueRef LLVMConstSDiv(LLVMValueRef LHSConstant, LLVMValueRef RHSConstant);
437LLVMValueRef LLVMConstFDiv(LLVMValueRef LHSConstant, LLVMValueRef RHSConstant);
438LLVMValueRef LLVMConstURem(LLVMValueRef LHSConstant, LLVMValueRef RHSConstant);
439LLVMValueRef LLVMConstSRem(LLVMValueRef LHSConstant, LLVMValueRef RHSConstant);
440LLVMValueRef LLVMConstFRem(LLVMValueRef LHSConstant, LLVMValueRef RHSConstant);
441LLVMValueRef LLVMConstAnd(LLVMValueRef LHSConstant, LLVMValueRef RHSConstant);
442LLVMValueRef LLVMConstOr(LLVMValueRef LHSConstant, LLVMValueRef RHSConstant);
443LLVMValueRef LLVMConstXor(LLVMValueRef LHSConstant, LLVMValueRef RHSConstant);
444LLVMValueRef LLVMConstICmp(LLVMIntPredicate Predicate,
445 LLVMValueRef LHSConstant, LLVMValueRef RHSConstant);
446LLVMValueRef LLVMConstFCmp(LLVMRealPredicate Predicate,
447 LLVMValueRef LHSConstant, LLVMValueRef RHSConstant);
448LLVMValueRef LLVMConstShl(LLVMValueRef LHSConstant, LLVMValueRef RHSConstant);
449LLVMValueRef LLVMConstLShr(LLVMValueRef LHSConstant, LLVMValueRef RHSConstant);
450LLVMValueRef LLVMConstAShr(LLVMValueRef LHSConstant, LLVMValueRef RHSConstant);
451LLVMValueRef LLVMConstGEP(LLVMValueRef ConstantVal,
452 LLVMValueRef *ConstantIndices, unsigned NumIndices);
453LLVMValueRef LLVMConstTrunc(LLVMValueRef ConstantVal, LLVMTypeRef ToType);
454LLVMValueRef LLVMConstSExt(LLVMValueRef ConstantVal, LLVMTypeRef ToType);
455LLVMValueRef LLVMConstZExt(LLVMValueRef ConstantVal, LLVMTypeRef ToType);
456LLVMValueRef LLVMConstFPTrunc(LLVMValueRef ConstantVal, LLVMTypeRef ToType);
457LLVMValueRef LLVMConstFPExt(LLVMValueRef ConstantVal, LLVMTypeRef ToType);
458LLVMValueRef LLVMConstUIToFP(LLVMValueRef ConstantVal, LLVMTypeRef ToType);
459LLVMValueRef LLVMConstSIToFP(LLVMValueRef ConstantVal, LLVMTypeRef ToType);
460LLVMValueRef LLVMConstFPToUI(LLVMValueRef ConstantVal, LLVMTypeRef ToType);
461LLVMValueRef LLVMConstFPToSI(LLVMValueRef ConstantVal, LLVMTypeRef ToType);
462LLVMValueRef LLVMConstPtrToInt(LLVMValueRef ConstantVal, LLVMTypeRef ToType);
463LLVMValueRef LLVMConstIntToPtr(LLVMValueRef ConstantVal, LLVMTypeRef ToType);
464LLVMValueRef LLVMConstBitCast(LLVMValueRef ConstantVal, LLVMTypeRef ToType);
465LLVMValueRef LLVMConstSelect(LLVMValueRef ConstantCondition,
466 LLVMValueRef ConstantIfTrue,
467 LLVMValueRef ConstantIfFalse);
468LLVMValueRef LLVMConstExtractElement(LLVMValueRef VectorConstant,
469 LLVMValueRef IndexConstant);
470LLVMValueRef LLVMConstInsertElement(LLVMValueRef VectorConstant,
471 LLVMValueRef ElementValueConstant,
472 LLVMValueRef IndexConstant);
473LLVMValueRef LLVMConstShuffleVector(LLVMValueRef VectorAConstant,
474 LLVMValueRef VectorBConstant,
475 LLVMValueRef MaskConstant);
Dan Gohmand5104a52008-11-03 22:55:43 +0000476LLVMValueRef LLVMConstExtractValue(LLVMValueRef AggConstant, unsigned *IdxList,
477 unsigned NumIdx);
478LLVMValueRef LLVMConstInsertValue(LLVMValueRef AggConstant,
479 LLVMValueRef ElementValueConstant,
480 unsigned *IdxList, unsigned NumIdx);
Chris Lattner3d1f5522008-12-17 21:39:50 +0000481LLVMValueRef LLVMConstInlineAsm(LLVMTypeRef Ty,
482 const char *AsmString, const char *Constraints,
483 int HasSideEffects);
Gordon Henriksen7ce31762007-10-06 14:29:36 +0000484
Gordon Henriksen76a03742007-09-18 03:18:57 +0000485/* Operations on global variables, functions, and aliases (globals) */
Gordon Henriksen265f7802008-03-19 01:11:35 +0000486LLVMModuleRef LLVMGetGlobalParent(LLVMValueRef Global);
Gordon Henriksen76a03742007-09-18 03:18:57 +0000487int LLVMIsDeclaration(LLVMValueRef Global);
488LLVMLinkage LLVMGetLinkage(LLVMValueRef Global);
489void LLVMSetLinkage(LLVMValueRef Global, LLVMLinkage Linkage);
490const char *LLVMGetSection(LLVMValueRef Global);
491void LLVMSetSection(LLVMValueRef Global, const char *Section);
492LLVMVisibility LLVMGetVisibility(LLVMValueRef Global);
493void LLVMSetVisibility(LLVMValueRef Global, LLVMVisibility Viz);
494unsigned LLVMGetAlignment(LLVMValueRef Global);
495void LLVMSetAlignment(LLVMValueRef Global, unsigned Bytes);
496
497/* Operations on global variables */
498LLVMValueRef LLVMAddGlobal(LLVMModuleRef M, LLVMTypeRef Ty, const char *Name);
Gordon Henriksen783f7bb2007-10-08 03:45:09 +0000499LLVMValueRef LLVMGetNamedGlobal(LLVMModuleRef M, const char *Name);
Gordon Henriksen07a45f42008-03-23 22:21:29 +0000500LLVMValueRef LLVMGetFirstGlobal(LLVMModuleRef M);
501LLVMValueRef LLVMGetLastGlobal(LLVMModuleRef M);
502LLVMValueRef LLVMGetNextGlobal(LLVMValueRef GlobalVar);
503LLVMValueRef LLVMGetPreviousGlobal(LLVMValueRef GlobalVar);
Gordon Henriksen76a03742007-09-18 03:18:57 +0000504void LLVMDeleteGlobal(LLVMValueRef GlobalVar);
Gordon Henriksen76a03742007-09-18 03:18:57 +0000505LLVMValueRef LLVMGetInitializer(LLVMValueRef GlobalVar);
506void LLVMSetInitializer(LLVMValueRef GlobalVar, LLVMValueRef ConstantVal);
507int LLVMIsThreadLocal(LLVMValueRef GlobalVar);
508void LLVMSetThreadLocal(LLVMValueRef GlobalVar, int IsThreadLocal);
Gordon Henriksen751ebf72007-10-07 17:31:42 +0000509int LLVMIsGlobalConstant(LLVMValueRef GlobalVar);
510void LLVMSetGlobalConstant(LLVMValueRef GlobalVar, int IsConstant);
Gordon Henriksen76a03742007-09-18 03:18:57 +0000511
Chris Lattner3d1f5522008-12-17 21:39:50 +0000512/* Operations on aliases */
513LLVMValueRef LLVMAddAlias(LLVMModuleRef M, LLVMTypeRef Ty, LLVMValueRef Aliasee,
514 const char *Name);
515
Gordon Henriksenc23b66c2007-09-26 20:56:12 +0000516/* Operations on functions */
517LLVMValueRef LLVMAddFunction(LLVMModuleRef M, const char *Name,
518 LLVMTypeRef FunctionTy);
Gordon Henriksen783f7bb2007-10-08 03:45:09 +0000519LLVMValueRef LLVMGetNamedFunction(LLVMModuleRef M, const char *Name);
Gordon Henriksen054817c2008-03-19 03:47:18 +0000520LLVMValueRef LLVMGetFirstFunction(LLVMModuleRef M);
521LLVMValueRef LLVMGetLastFunction(LLVMModuleRef M);
522LLVMValueRef LLVMGetNextFunction(LLVMValueRef Fn);
523LLVMValueRef LLVMGetPreviousFunction(LLVMValueRef Fn);
Gordon Henriksenc23b66c2007-09-26 20:56:12 +0000524void LLVMDeleteFunction(LLVMValueRef Fn);
Gordon Henriksenc23b66c2007-09-26 20:56:12 +0000525unsigned LLVMGetIntrinsicID(LLVMValueRef Fn);
526unsigned LLVMGetFunctionCallConv(LLVMValueRef Fn);
527void LLVMSetFunctionCallConv(LLVMValueRef Fn, unsigned CC);
Gordon Henriksend930f912008-08-17 18:44:35 +0000528const char *LLVMGetGC(LLVMValueRef Fn);
529void LLVMSetGC(LLVMValueRef Fn, const char *Name);
Duncan Sands7374a012009-05-06 12:21:17 +0000530void LLVMAddFunctionAttr(LLVMValueRef Fn, LLVMAttribute PA);
531void LLVMRemoveFunctionAttr(LLVMValueRef Fn, LLVMAttribute PA);
Gordon Henriksenc23b66c2007-09-26 20:56:12 +0000532
Gordon Henriksen265f7802008-03-19 01:11:35 +0000533/* Operations on parameters */
534unsigned LLVMCountParams(LLVMValueRef Fn);
535void LLVMGetParams(LLVMValueRef Fn, LLVMValueRef *Params);
536LLVMValueRef LLVMGetParam(LLVMValueRef Fn, unsigned Index);
537LLVMValueRef LLVMGetParamParent(LLVMValueRef Inst);
Gordon Henriksen07a45f42008-03-23 22:21:29 +0000538LLVMValueRef LLVMGetFirstParam(LLVMValueRef Fn);
539LLVMValueRef LLVMGetLastParam(LLVMValueRef Fn);
540LLVMValueRef LLVMGetNextParam(LLVMValueRef Arg);
541LLVMValueRef LLVMGetPreviousParam(LLVMValueRef Arg);
Devang Patel4c758ea2008-09-25 21:00:45 +0000542void LLVMAddAttribute(LLVMValueRef Arg, LLVMAttribute PA);
543void LLVMRemoveAttribute(LLVMValueRef Arg, LLVMAttribute PA);
Gordon Henriksen2d9cc212008-04-28 17:37:06 +0000544void LLVMSetParamAlignment(LLVMValueRef Arg, unsigned align);
Gordon Henriksen265f7802008-03-19 01:11:35 +0000545
Gordon Henriksenc23b66c2007-09-26 20:56:12 +0000546/* Operations on basic blocks */
Gordon Henriksen07a45f42008-03-23 22:21:29 +0000547LLVMValueRef LLVMBasicBlockAsValue(LLVMBasicBlockRef BB);
Gordon Henriksenc23b66c2007-09-26 20:56:12 +0000548int LLVMValueIsBasicBlock(LLVMValueRef Val);
549LLVMBasicBlockRef LLVMValueAsBasicBlock(LLVMValueRef Val);
Gordon Henriksen07a45f42008-03-23 22:21:29 +0000550LLVMValueRef LLVMGetBasicBlockParent(LLVMBasicBlockRef BB);
Gordon Henriksenc23b66c2007-09-26 20:56:12 +0000551unsigned LLVMCountBasicBlocks(LLVMValueRef Fn);
552void LLVMGetBasicBlocks(LLVMValueRef Fn, LLVMBasicBlockRef *BasicBlocks);
Gordon Henriksen054817c2008-03-19 03:47:18 +0000553LLVMBasicBlockRef LLVMGetFirstBasicBlock(LLVMValueRef Fn);
554LLVMBasicBlockRef LLVMGetLastBasicBlock(LLVMValueRef Fn);
555LLVMBasicBlockRef LLVMGetNextBasicBlock(LLVMBasicBlockRef BB);
556LLVMBasicBlockRef LLVMGetPreviousBasicBlock(LLVMBasicBlockRef BB);
Gordon Henriksenc23b66c2007-09-26 20:56:12 +0000557LLVMBasicBlockRef LLVMGetEntryBasicBlock(LLVMValueRef Fn);
558LLVMBasicBlockRef LLVMAppendBasicBlock(LLVMValueRef Fn, const char *Name);
559LLVMBasicBlockRef LLVMInsertBasicBlock(LLVMBasicBlockRef InsertBeforeBB,
560 const char *Name);
561void LLVMDeleteBasicBlock(LLVMBasicBlockRef BB);
562
Gordon Henriksen265f7802008-03-19 01:11:35 +0000563/* Operations on instructions */
564LLVMBasicBlockRef LLVMGetInstructionParent(LLVMValueRef Inst);
Gordon Henriksen054817c2008-03-19 03:47:18 +0000565LLVMValueRef LLVMGetFirstInstruction(LLVMBasicBlockRef BB);
566LLVMValueRef LLVMGetLastInstruction(LLVMBasicBlockRef BB);
567LLVMValueRef LLVMGetNextInstruction(LLVMValueRef Inst);
568LLVMValueRef LLVMGetPreviousInstruction(LLVMValueRef Inst);
Gordon Henriksen265f7802008-03-19 01:11:35 +0000569
Gordon Henriksen1158c532007-12-29 20:45:00 +0000570/* Operations on call sites */
571void LLVMSetInstructionCallConv(LLVMValueRef Instr, unsigned CC);
572unsigned LLVMGetInstructionCallConv(LLVMValueRef Instr);
Devang Patel4c758ea2008-09-25 21:00:45 +0000573void LLVMAddInstrAttribute(LLVMValueRef Instr, unsigned index, LLVMAttribute);
574void LLVMRemoveInstrAttribute(LLVMValueRef Instr, unsigned index,
575 LLVMAttribute);
Gordon Henriksen2d9cc212008-04-28 17:37:06 +0000576void LLVMSetInstrParamAlignment(LLVMValueRef Instr, unsigned index,
577 unsigned align);
Gordon Henriksen1158c532007-12-29 20:45:00 +0000578
Gordon Henrikseneeb65372008-08-30 16:34:54 +0000579/* Operations on call instructions (only) */
580int LLVMIsTailCall(LLVMValueRef CallInst);
581void LLVMSetTailCall(LLVMValueRef CallInst, int IsTailCall);
582
Gordon Henriksen44dd8fb2007-10-08 18:14:39 +0000583/* Operations on phi nodes */
584void LLVMAddIncoming(LLVMValueRef PhiNode, LLVMValueRef *IncomingValues,
585 LLVMBasicBlockRef *IncomingBlocks, unsigned Count);
586unsigned LLVMCountIncoming(LLVMValueRef PhiNode);
587LLVMValueRef LLVMGetIncomingValue(LLVMValueRef PhiNode, unsigned Index);
588LLVMBasicBlockRef LLVMGetIncomingBlock(LLVMValueRef PhiNode, unsigned Index);
Gordon Henriksenc23b66c2007-09-26 20:56:12 +0000589
590/*===-- Instruction builders ----------------------------------------------===*/
591
592/* An instruction builder represents a point within a basic block, and is the
593 * exclusive means of building instructions using the C interface.
594 */
595
Gordon Henriksena735a9c2008-05-04 12:55:34 +0000596LLVMBuilderRef LLVMCreateBuilder(void);
Gordon Henriksen054817c2008-03-19 03:47:18 +0000597void LLVMPositionBuilder(LLVMBuilderRef Builder, LLVMBasicBlockRef Block,
598 LLVMValueRef Instr);
Gordon Henriksenc23b66c2007-09-26 20:56:12 +0000599void LLVMPositionBuilderBefore(LLVMBuilderRef Builder, LLVMValueRef Instr);
600void LLVMPositionBuilderAtEnd(LLVMBuilderRef Builder, LLVMBasicBlockRef Block);
Gordon Henriksen265f7802008-03-19 01:11:35 +0000601LLVMBasicBlockRef LLVMGetInsertBlock(LLVMBuilderRef Builder);
Chris Lattner3d1f5522008-12-17 21:39:50 +0000602void LLVMClearInsertionPosition(LLVMBuilderRef Builder);
603void LLVMInsertIntoBuilder(LLVMBuilderRef Builder, LLVMValueRef Instr);
Gordon Henriksenc23b66c2007-09-26 20:56:12 +0000604void LLVMDisposeBuilder(LLVMBuilderRef Builder);
605
606/* Terminators */
607LLVMValueRef LLVMBuildRetVoid(LLVMBuilderRef);
608LLVMValueRef LLVMBuildRet(LLVMBuilderRef, LLVMValueRef V);
609LLVMValueRef LLVMBuildBr(LLVMBuilderRef, LLVMBasicBlockRef Dest);
610LLVMValueRef LLVMBuildCondBr(LLVMBuilderRef, LLVMValueRef If,
611 LLVMBasicBlockRef Then, LLVMBasicBlockRef Else);
612LLVMValueRef LLVMBuildSwitch(LLVMBuilderRef, LLVMValueRef V,
613 LLVMBasicBlockRef Else, unsigned NumCases);
614LLVMValueRef LLVMBuildInvoke(LLVMBuilderRef, LLVMValueRef Fn,
615 LLVMValueRef *Args, unsigned NumArgs,
616 LLVMBasicBlockRef Then, LLVMBasicBlockRef Catch,
617 const char *Name);
618LLVMValueRef LLVMBuildUnwind(LLVMBuilderRef);
619LLVMValueRef LLVMBuildUnreachable(LLVMBuilderRef);
620
Gordon Henriksen097102c2008-01-01 05:50:53 +0000621/* Add a case to the switch instruction */
622void LLVMAddCase(LLVMValueRef Switch, LLVMValueRef OnVal,
623 LLVMBasicBlockRef Dest);
624
Gordon Henriksenc23b66c2007-09-26 20:56:12 +0000625/* Arithmetic */
626LLVMValueRef LLVMBuildAdd(LLVMBuilderRef, LLVMValueRef LHS, LLVMValueRef RHS,
627 const char *Name);
628LLVMValueRef LLVMBuildSub(LLVMBuilderRef, LLVMValueRef LHS, LLVMValueRef RHS,
629 const char *Name);
630LLVMValueRef LLVMBuildMul(LLVMBuilderRef, LLVMValueRef LHS, LLVMValueRef RHS,
631 const char *Name);
632LLVMValueRef LLVMBuildUDiv(LLVMBuilderRef, LLVMValueRef LHS, LLVMValueRef RHS,
633 const char *Name);
634LLVMValueRef LLVMBuildSDiv(LLVMBuilderRef, LLVMValueRef LHS, LLVMValueRef RHS,
635 const char *Name);
636LLVMValueRef LLVMBuildFDiv(LLVMBuilderRef, LLVMValueRef LHS, LLVMValueRef RHS,
637 const char *Name);
638LLVMValueRef LLVMBuildURem(LLVMBuilderRef, LLVMValueRef LHS, LLVMValueRef RHS,
639 const char *Name);
640LLVMValueRef LLVMBuildSRem(LLVMBuilderRef, LLVMValueRef LHS, LLVMValueRef RHS,
641 const char *Name);
642LLVMValueRef LLVMBuildFRem(LLVMBuilderRef, LLVMValueRef LHS, LLVMValueRef RHS,
643 const char *Name);
644LLVMValueRef LLVMBuildShl(LLVMBuilderRef, LLVMValueRef LHS, LLVMValueRef RHS,
645 const char *Name);
646LLVMValueRef LLVMBuildLShr(LLVMBuilderRef, LLVMValueRef LHS, LLVMValueRef RHS,
647 const char *Name);
648LLVMValueRef LLVMBuildAShr(LLVMBuilderRef, LLVMValueRef LHS, LLVMValueRef RHS,
649 const char *Name);
650LLVMValueRef LLVMBuildAnd(LLVMBuilderRef, LLVMValueRef LHS, LLVMValueRef RHS,
651 const char *Name);
652LLVMValueRef LLVMBuildOr(LLVMBuilderRef, LLVMValueRef LHS, LLVMValueRef RHS,
653 const char *Name);
654LLVMValueRef LLVMBuildXor(LLVMBuilderRef, LLVMValueRef LHS, LLVMValueRef RHS,
655 const char *Name);
656LLVMValueRef LLVMBuildNeg(LLVMBuilderRef, LLVMValueRef V, const char *Name);
657LLVMValueRef LLVMBuildNot(LLVMBuilderRef, LLVMValueRef V, const char *Name);
658
659/* Memory */
660LLVMValueRef LLVMBuildMalloc(LLVMBuilderRef, LLVMTypeRef Ty, const char *Name);
661LLVMValueRef LLVMBuildArrayMalloc(LLVMBuilderRef, LLVMTypeRef Ty,
662 LLVMValueRef Val, const char *Name);
663LLVMValueRef LLVMBuildAlloca(LLVMBuilderRef, LLVMTypeRef Ty, const char *Name);
664LLVMValueRef LLVMBuildArrayAlloca(LLVMBuilderRef, LLVMTypeRef Ty,
665 LLVMValueRef Val, const char *Name);
666LLVMValueRef LLVMBuildFree(LLVMBuilderRef, LLVMValueRef PointerVal);
667LLVMValueRef LLVMBuildLoad(LLVMBuilderRef, LLVMValueRef PointerVal,
668 const char *Name);
669LLVMValueRef LLVMBuildStore(LLVMBuilderRef, LLVMValueRef Val, LLVMValueRef Ptr);
670LLVMValueRef LLVMBuildGEP(LLVMBuilderRef B, LLVMValueRef Pointer,
671 LLVMValueRef *Indices, unsigned NumIndices,
672 const char *Name);
673
674/* Casts */
675LLVMValueRef LLVMBuildTrunc(LLVMBuilderRef, LLVMValueRef Val,
676 LLVMTypeRef DestTy, const char *Name);
677LLVMValueRef LLVMBuildZExt(LLVMBuilderRef, LLVMValueRef Val,
678 LLVMTypeRef DestTy, const char *Name);
679LLVMValueRef LLVMBuildSExt(LLVMBuilderRef, LLVMValueRef Val,
680 LLVMTypeRef DestTy, const char *Name);
681LLVMValueRef LLVMBuildFPToUI(LLVMBuilderRef, LLVMValueRef Val,
682 LLVMTypeRef DestTy, const char *Name);
683LLVMValueRef LLVMBuildFPToSI(LLVMBuilderRef, LLVMValueRef Val,
684 LLVMTypeRef DestTy, const char *Name);
685LLVMValueRef LLVMBuildUIToFP(LLVMBuilderRef, LLVMValueRef Val,
686 LLVMTypeRef DestTy, const char *Name);
687LLVMValueRef LLVMBuildSIToFP(LLVMBuilderRef, LLVMValueRef Val,
688 LLVMTypeRef DestTy, const char *Name);
689LLVMValueRef LLVMBuildFPTrunc(LLVMBuilderRef, LLVMValueRef Val,
690 LLVMTypeRef DestTy, const char *Name);
691LLVMValueRef LLVMBuildFPExt(LLVMBuilderRef, LLVMValueRef Val,
692 LLVMTypeRef DestTy, const char *Name);
693LLVMValueRef LLVMBuildPtrToInt(LLVMBuilderRef, LLVMValueRef Val,
694 LLVMTypeRef DestTy, const char *Name);
695LLVMValueRef LLVMBuildIntToPtr(LLVMBuilderRef, LLVMValueRef Val,
696 LLVMTypeRef DestTy, const char *Name);
697LLVMValueRef LLVMBuildBitCast(LLVMBuilderRef, LLVMValueRef Val,
698 LLVMTypeRef DestTy, const char *Name);
699
700/* Comparisons */
701LLVMValueRef LLVMBuildICmp(LLVMBuilderRef, LLVMIntPredicate Op,
702 LLVMValueRef LHS, LLVMValueRef RHS,
703 const char *Name);
704LLVMValueRef LLVMBuildFCmp(LLVMBuilderRef, LLVMRealPredicate Op,
705 LLVMValueRef LHS, LLVMValueRef RHS,
706 const char *Name);
707
708/* Miscellaneous instructions */
709LLVMValueRef LLVMBuildPhi(LLVMBuilderRef, LLVMTypeRef Ty, const char *Name);
710LLVMValueRef LLVMBuildCall(LLVMBuilderRef, LLVMValueRef Fn,
711 LLVMValueRef *Args, unsigned NumArgs,
712 const char *Name);
713LLVMValueRef LLVMBuildSelect(LLVMBuilderRef, LLVMValueRef If,
714 LLVMValueRef Then, LLVMValueRef Else,
715 const char *Name);
716LLVMValueRef LLVMBuildVAArg(LLVMBuilderRef, LLVMValueRef List, LLVMTypeRef Ty,
717 const char *Name);
718LLVMValueRef LLVMBuildExtractElement(LLVMBuilderRef, LLVMValueRef VecVal,
719 LLVMValueRef Index, const char *Name);
720LLVMValueRef LLVMBuildInsertElement(LLVMBuilderRef, LLVMValueRef VecVal,
721 LLVMValueRef EltVal, LLVMValueRef Index,
722 const char *Name);
723LLVMValueRef LLVMBuildShuffleVector(LLVMBuilderRef, LLVMValueRef V1,
724 LLVMValueRef V2, LLVMValueRef Mask,
725 const char *Name);
Dan Gohmand5104a52008-11-03 22:55:43 +0000726LLVMValueRef LLVMBuildExtractValue(LLVMBuilderRef, LLVMValueRef AggVal,
727 unsigned Index, const char *Name);
728LLVMValueRef LLVMBuildInsertValue(LLVMBuilderRef, LLVMValueRef AggVal,
729 LLVMValueRef EltVal, unsigned Index,
730 const char *Name);
Gordon Henriksen76a03742007-09-18 03:18:57 +0000731
Gordon Henriksen34eb6d82007-12-19 22:30:40 +0000732
Gordon Henriksen0a68fe22007-12-12 01:04:30 +0000733/*===-- Module providers --------------------------------------------------===*/
734
735/* Encapsulates the module M in a module provider, taking ownership of the
736 * module.
737 * See the constructor llvm::ExistingModuleProvider::ExistingModuleProvider.
738 */
739LLVMModuleProviderRef
740LLVMCreateModuleProviderForExistingModule(LLVMModuleRef M);
741
742/* Destroys the module provider MP as well as the contained module.
743 * See the destructor llvm::ModuleProvider::~ModuleProvider.
744 */
745void LLVMDisposeModuleProvider(LLVMModuleProviderRef MP);
746
Gordon Henriksen34eb6d82007-12-19 22:30:40 +0000747
748/*===-- Memory buffers ----------------------------------------------------===*/
749
750int LLVMCreateMemoryBufferWithContentsOfFile(const char *Path,
751 LLVMMemoryBufferRef *OutMemBuf,
752 char **OutMessage);
753int LLVMCreateMemoryBufferWithSTDIN(LLVMMemoryBufferRef *OutMemBuf,
754 char **OutMessage);
755void LLVMDisposeMemoryBuffer(LLVMMemoryBufferRef MemBuf);
756
Gordon Henriksen878114b2008-03-16 04:20:44 +0000757
758/*===-- Pass Managers -----------------------------------------------------===*/
759
760/** Constructs a new whole-module pass pipeline. This type of pipeline is
761 suitable for link-time optimization and whole-module transformations.
762 See llvm::PassManager::PassManager. */
Gordon Henriksena735a9c2008-05-04 12:55:34 +0000763LLVMPassManagerRef LLVMCreatePassManager(void);
Gordon Henriksen878114b2008-03-16 04:20:44 +0000764
765/** Constructs a new function-by-function pass pipeline over the module
766 provider. It does not take ownership of the module provider. This type of
767 pipeline is suitable for code generation and JIT compilation tasks.
768 See llvm::FunctionPassManager::FunctionPassManager. */
769LLVMPassManagerRef LLVMCreateFunctionPassManager(LLVMModuleProviderRef MP);
770
771/** Initializes, executes on the provided module, and finalizes all of the
772 passes scheduled in the pass manager. Returns 1 if any of the passes
773 modified the module, 0 otherwise. See llvm::PassManager::run(Module&). */
774int LLVMRunPassManager(LLVMPassManagerRef PM, LLVMModuleRef M);
775
776/** Initializes all of the function passes scheduled in the function pass
777 manager. Returns 1 if any of the passes modified the module, 0 otherwise.
778 See llvm::FunctionPassManager::doInitialization. */
779int LLVMInitializeFunctionPassManager(LLVMPassManagerRef FPM);
780
781/** Executes all of the function passes scheduled in the function pass manager
782 on the provided function. Returns 1 if any of the passes modified the
783 function, false otherwise.
784 See llvm::FunctionPassManager::run(Function&). */
785int LLVMRunFunctionPassManager(LLVMPassManagerRef FPM, LLVMValueRef F);
786
787/** Finalizes all of the function passes scheduled in in the function pass
788 manager. Returns 1 if any of the passes modified the module, 0 otherwise.
789 See llvm::FunctionPassManager::doFinalization. */
790int LLVMFinalizeFunctionPassManager(LLVMPassManagerRef FPM);
791
792/** Frees the memory of a pass pipeline. For function pipelines, does not free
793 the module provider.
794 See llvm::PassManagerBase::~PassManagerBase. */
795void LLVMDisposePassManager(LLVMPassManagerRef PM);
796
797
Gordon Henriksen76a03742007-09-18 03:18:57 +0000798#ifdef __cplusplus
799}
Gordon Henriksen76a03742007-09-18 03:18:57 +0000800
Gordon Henriksen7330acd2007-10-05 23:59:36 +0000801namespace llvm {
Gordon Henriksen0a68fe22007-12-12 01:04:30 +0000802 class ModuleProvider;
Gordon Henriksen34eb6d82007-12-19 22:30:40 +0000803 class MemoryBuffer;
Gordon Henriksen96571492008-03-16 15:55:43 +0000804 class PassManagerBase;
Gordon Henriksen0a68fe22007-12-12 01:04:30 +0000805
Gordon Henriksen34eb6d82007-12-19 22:30:40 +0000806 #define DEFINE_SIMPLE_CONVERSION_FUNCTIONS(ty, ref) \
807 inline ty *unwrap(ref P) { \
808 return reinterpret_cast<ty*>(P); \
809 } \
810 \
811 inline ref wrap(const ty *P) { \
812 return reinterpret_cast<ref>(const_cast<ty*>(P)); \
813 }
Gordon Henriksen7330acd2007-10-05 23:59:36 +0000814
Gordon Henriksen878114b2008-03-16 04:20:44 +0000815 #define DEFINE_ISA_CONVERSION_FUNCTIONS(ty, ref) \
816 DEFINE_SIMPLE_CONVERSION_FUNCTIONS(ty, ref) \
817 \
818 template<typename T> \
819 inline T *unwrap(ref P) { \
820 return cast<T>(unwrap(P)); \
821 }
822
823 #define DEFINE_STDCXX_CONVERSION_FUNCTIONS(ty, ref) \
824 DEFINE_SIMPLE_CONVERSION_FUNCTIONS(ty, ref) \
825 \
826 template<typename T> \
827 inline T *unwrap(ref P) { \
828 T *Q = dynamic_cast<T*>(unwrap(P)); \
829 assert(Q && "Invalid cast!"); \
830 return Q; \
831 }
832
833 DEFINE_ISA_CONVERSION_FUNCTIONS (Type, LLVMTypeRef )
834 DEFINE_ISA_CONVERSION_FUNCTIONS (Value, LLVMValueRef )
Gordon Henriksen823f9732007-12-27 18:25:59 +0000835 DEFINE_SIMPLE_CONVERSION_FUNCTIONS(Module, LLVMModuleRef )
836 DEFINE_SIMPLE_CONVERSION_FUNCTIONS(BasicBlock, LLVMBasicBlockRef )
Eric Christopher59278832008-08-08 19:39:37 +0000837 DEFINE_SIMPLE_CONVERSION_FUNCTIONS(IRBuilder<>, LLVMBuilderRef )
Gordon Henriksen823f9732007-12-27 18:25:59 +0000838 DEFINE_SIMPLE_CONVERSION_FUNCTIONS(PATypeHolder, LLVMTypeHandleRef )
839 DEFINE_SIMPLE_CONVERSION_FUNCTIONS(ModuleProvider, LLVMModuleProviderRef)
840 DEFINE_SIMPLE_CONVERSION_FUNCTIONS(MemoryBuffer, LLVMMemoryBufferRef )
Owen Anderson6773d382009-07-01 16:58:40 +0000841 DEFINE_SIMPLE_CONVERSION_FUNCTIONS(LLVMContext, LLVMContextRef )
Gordon Henriksen878114b2008-03-16 04:20:44 +0000842 DEFINE_STDCXX_CONVERSION_FUNCTIONS(PassManagerBase, LLVMPassManagerRef )
Gordon Henriksen7330acd2007-10-05 23:59:36 +0000843
Gordon Henriksen878114b2008-03-16 04:20:44 +0000844 #undef DEFINE_STDCXX_CONVERSION_FUNCTIONS
845 #undef DEFINE_ISA_CONVERSION_FUNCTIONS
Gordon Henriksen34eb6d82007-12-19 22:30:40 +0000846 #undef DEFINE_SIMPLE_CONVERSION_FUNCTIONS
Gordon Henriksen7330acd2007-10-05 23:59:36 +0000847
Gordon Henriksen34eb6d82007-12-19 22:30:40 +0000848 /* Specialized opaque type conversions.
849 */
Gordon Henriksen7330acd2007-10-05 23:59:36 +0000850 inline Type **unwrap(LLVMTypeRef* Tys) {
851 return reinterpret_cast<Type**>(Tys);
852 }
853
Gordon Henriksen7330acd2007-10-05 23:59:36 +0000854 inline LLVMTypeRef *wrap(const Type **Tys) {
855 return reinterpret_cast<LLVMTypeRef*>(const_cast<Type**>(Tys));
856 }
857
Gordon Henriksen34eb6d82007-12-19 22:30:40 +0000858 /* Specialized opaque value conversions.
Gordon Henriksen7330acd2007-10-05 23:59:36 +0000859 */
Gordon Henriksen7330acd2007-10-05 23:59:36 +0000860 inline Value **unwrap(LLVMValueRef *Vals) {
861 return reinterpret_cast<Value**>(Vals);
862 }
863
864 template<typename T>
865 inline T **unwrap(LLVMValueRef *Vals, unsigned Length) {
866 #if DEBUG
Chris Lattnerb7971152009-07-10 18:28:19 +0000867 for (LLVMValueRef *I = Vals, *E = Vals + Length; I != E; ++I)
Gordon Henriksen7330acd2007-10-05 23:59:36 +0000868 cast<T>(*I);
869 #endif
870 return reinterpret_cast<T**>(Vals);
871 }
872
Gordon Henriksen7330acd2007-10-05 23:59:36 +0000873 inline LLVMValueRef *wrap(const Value **Vals) {
874 return reinterpret_cast<LLVMValueRef*>(const_cast<Value**>(Vals));
875 }
Gordon Henriksen7330acd2007-10-05 23:59:36 +0000876}
877
878#endif /* !defined(__cplusplus) */
879
880#endif /* !defined(LLVM_C_CORE_H) */