blob: 71e71a9c9980c5997e19dc4be84c13625f13a279 [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 */
Duncan Sands4581beb2009-03-11 20:14:15 +0000149 LLVMCommonLinkage /**< Tentative definitions */
Gordon Henriksen76a03742007-09-18 03:18:57 +0000150} LLVMLinkage;
151
152typedef enum {
Gordon Henriksen4a4d7352007-12-30 17:46:33 +0000153 LLVMDefaultVisibility, /**< The GV is visible */
154 LLVMHiddenVisibility, /**< The GV is hidden */
155 LLVMProtectedVisibility /**< The GV is protected */
Gordon Henriksen76a03742007-09-18 03:18:57 +0000156} LLVMVisibility;
157
Gordon Henriksenc23b66c2007-09-26 20:56:12 +0000158typedef enum {
159 LLVMCCallConv = 0,
160 LLVMFastCallConv = 8,
161 LLVMColdCallConv = 9,
162 LLVMX86StdcallCallConv = 64,
163 LLVMX86FastcallCallConv = 65
164} LLVMCallConv;
165
166typedef enum {
Gordon Henriksen4a4d7352007-12-30 17:46:33 +0000167 LLVMIntEQ = 32, /**< equal */
168 LLVMIntNE, /**< not equal */
169 LLVMIntUGT, /**< unsigned greater than */
170 LLVMIntUGE, /**< unsigned greater or equal */
171 LLVMIntULT, /**< unsigned less than */
172 LLVMIntULE, /**< unsigned less or equal */
173 LLVMIntSGT, /**< signed greater than */
174 LLVMIntSGE, /**< signed greater or equal */
175 LLVMIntSLT, /**< signed less than */
176 LLVMIntSLE /**< signed less or equal */
Gordon Henriksenc23b66c2007-09-26 20:56:12 +0000177} LLVMIntPredicate;
178
179typedef enum {
Gordon Henriksen4a4d7352007-12-30 17:46:33 +0000180 LLVMRealPredicateFalse, /**< Always false (always folded) */
181 LLVMRealOEQ, /**< True if ordered and equal */
182 LLVMRealOGT, /**< True if ordered and greater than */
183 LLVMRealOGE, /**< True if ordered and greater than or equal */
184 LLVMRealOLT, /**< True if ordered and less than */
185 LLVMRealOLE, /**< True if ordered and less than or equal */
186 LLVMRealONE, /**< True if ordered and operands are unequal */
187 LLVMRealORD, /**< True if ordered (no nans) */
188 LLVMRealUNO, /**< True if unordered: isnan(X) | isnan(Y) */
189 LLVMRealUEQ, /**< True if unordered or equal */
190 LLVMRealUGT, /**< True if unordered or greater than */
191 LLVMRealUGE, /**< True if unordered, greater than, or equal */
192 LLVMRealULT, /**< True if unordered or less than */
193 LLVMRealULE, /**< True if unordered, less than, or equal */
194 LLVMRealUNE, /**< True if unordered or not equal */
195 LLVMRealPredicateTrue /**< Always true (always folded) */
Gordon Henriksenc23b66c2007-09-26 20:56:12 +0000196} LLVMRealPredicate;
197
Gordon Henriksen76a03742007-09-18 03:18:57 +0000198
Gordon Henriksen34eb6d82007-12-19 22:30:40 +0000199/*===-- Error handling ----------------------------------------------------===*/
200
201void LLVMDisposeMessage(char *Message);
202
203
Gordon Henriksen76a03742007-09-18 03:18:57 +0000204/*===-- Modules -----------------------------------------------------------===*/
205
Owen Anderson6773d382009-07-01 16:58:40 +0000206/* Create and destroy contexts. */
207LLVMContextRef LLVMContextCreate();
Owen Andersonf7691d32009-07-02 00:16:38 +0000208LLVMContextRef LLVMGetGlobalContext();
Owen Anderson6773d382009-07-01 16:58:40 +0000209void LLVMContextDispose(LLVMContextRef C);
210
Gordon Henriksen76a03742007-09-18 03:18:57 +0000211/* Create and destroy modules. */
Gordon Henriksena49d4352008-03-07 19:13:06 +0000212/** See llvm::Module::Module. */
Gordon Henriksen76a03742007-09-18 03:18:57 +0000213LLVMModuleRef LLVMModuleCreateWithName(const char *ModuleID);
Owen Anderson31d44e42009-07-02 07:17:57 +0000214LLVMModuleRef LLVMModuleCreateWithNameInContext(const char *ModuleID,
215 LLVMContextRef C);
Gordon Henriksena49d4352008-03-07 19:13:06 +0000216
217/** See llvm::Module::~Module. */
Gordon Henriksen76a03742007-09-18 03:18:57 +0000218void LLVMDisposeModule(LLVMModuleRef M);
219
Gordon Henriksena49d4352008-03-07 19:13:06 +0000220/** Data layout. See Module::getDataLayout. */
Gordon Henriksen05568bb2007-12-27 20:13:47 +0000221const char *LLVMGetDataLayout(LLVMModuleRef M);
222void LLVMSetDataLayout(LLVMModuleRef M, const char *Triple);
223
Gordon Henriksena49d4352008-03-07 19:13:06 +0000224/** Target triple. See Module::getTargetTriple. */
Gordon Henriksen05568bb2007-12-27 20:13:47 +0000225const char *LLVMGetTarget(LLVMModuleRef M);
226void LLVMSetTarget(LLVMModuleRef M, const char *Triple);
227
Gordon Henriksena49d4352008-03-07 19:13:06 +0000228/** See Module::addTypeName. */
Gordon Henriksen76a03742007-09-18 03:18:57 +0000229int LLVMAddTypeName(LLVMModuleRef M, const char *Name, LLVMTypeRef Ty);
Gordon Henriksenc23b66c2007-09-26 20:56:12 +0000230void LLVMDeleteTypeName(LLVMModuleRef M, const char *Name);
Chris Lattner7f318242009-07-06 17:29:59 +0000231LLVMTypeRef LLVMGetTypeByName(LLVMModuleRef M, const char *Name);
Gordon Henriksen76a03742007-09-18 03:18:57 +0000232
Gordon Henriksen6c6075e2008-03-14 23:58:56 +0000233/** See Module::dump. */
234void LLVMDumpModule(LLVMModuleRef M);
235
Gordon Henriksen76a03742007-09-18 03:18:57 +0000236
Gordon Henriksenc23b66c2007-09-26 20:56:12 +0000237/*===-- Types -------------------------------------------------------------===*/
Gordon Henriksen76a03742007-09-18 03:18:57 +0000238
239/* LLVM types conform to the following hierarchy:
240 *
241 * types:
242 * integer type
243 * real type
244 * function type
245 * sequence types:
246 * array type
247 * pointer type
248 * vector type
249 * void type
250 * label type
251 * opaque type
252 */
253
Gordon Henriksena49d4352008-03-07 19:13:06 +0000254/** See llvm::LLVMTypeKind::getTypeID. */
Gordon Henriksen76a03742007-09-18 03:18:57 +0000255LLVMTypeKind LLVMGetTypeKind(LLVMTypeRef Ty);
Gordon Henriksena49d4352008-03-07 19:13:06 +0000256
Gordon Henriksen76a03742007-09-18 03:18:57 +0000257/* Operations on integer types */
Gordon Henriksena735a9c2008-05-04 12:55:34 +0000258LLVMTypeRef LLVMInt1Type(void);
259LLVMTypeRef LLVMInt8Type(void);
260LLVMTypeRef LLVMInt16Type(void);
261LLVMTypeRef LLVMInt32Type(void);
262LLVMTypeRef LLVMInt64Type(void);
Gordon Henriksened7beaa2007-10-06 16:05:20 +0000263LLVMTypeRef LLVMIntType(unsigned NumBits);
Gordon Henriksenc23b66c2007-09-26 20:56:12 +0000264unsigned LLVMGetIntTypeWidth(LLVMTypeRef IntegerTy);
Gordon Henriksen76a03742007-09-18 03:18:57 +0000265
266/* Operations on real types */
Gordon Henriksena735a9c2008-05-04 12:55:34 +0000267LLVMTypeRef LLVMFloatType(void);
268LLVMTypeRef LLVMDoubleType(void);
269LLVMTypeRef LLVMX86FP80Type(void);
270LLVMTypeRef LLVMFP128Type(void);
271LLVMTypeRef LLVMPPCFP128Type(void);
Gordon Henriksen76a03742007-09-18 03:18:57 +0000272
273/* Operations on function types */
Gordon Henriksened7beaa2007-10-06 16:05:20 +0000274LLVMTypeRef LLVMFunctionType(LLVMTypeRef ReturnType,
275 LLVMTypeRef *ParamTypes, unsigned ParamCount,
276 int IsVarArg);
Gordon Henriksen76a03742007-09-18 03:18:57 +0000277int LLVMIsFunctionVarArg(LLVMTypeRef FunctionTy);
Gordon Henriksenc23b66c2007-09-26 20:56:12 +0000278LLVMTypeRef LLVMGetReturnType(LLVMTypeRef FunctionTy);
279unsigned LLVMCountParamTypes(LLVMTypeRef FunctionTy);
280void LLVMGetParamTypes(LLVMTypeRef FunctionTy, LLVMTypeRef *Dest);
Gordon Henriksen76a03742007-09-18 03:18:57 +0000281
282/* Operations on struct types */
Gordon Henriksened7beaa2007-10-06 16:05:20 +0000283LLVMTypeRef LLVMStructType(LLVMTypeRef *ElementTypes, unsigned ElementCount,
284 int Packed);
Gordon Henriksenc23b66c2007-09-26 20:56:12 +0000285unsigned LLVMCountStructElementTypes(LLVMTypeRef StructTy);
Gordon Henriksen76a03742007-09-18 03:18:57 +0000286void LLVMGetStructElementTypes(LLVMTypeRef StructTy, LLVMTypeRef *Dest);
287int LLVMIsPackedStruct(LLVMTypeRef StructTy);
288
289/* Operations on array, pointer, and vector types (sequence types) */
Gordon Henriksened7beaa2007-10-06 16:05:20 +0000290LLVMTypeRef LLVMArrayType(LLVMTypeRef ElementType, unsigned ElementCount);
Gordon Henriksen5a3fe032007-12-17 16:08:32 +0000291LLVMTypeRef LLVMPointerType(LLVMTypeRef ElementType, unsigned AddressSpace);
Gordon Henriksened7beaa2007-10-06 16:05:20 +0000292LLVMTypeRef LLVMVectorType(LLVMTypeRef ElementType, unsigned ElementCount);
Gordon Henriksen76a03742007-09-18 03:18:57 +0000293
294LLVMTypeRef LLVMGetElementType(LLVMTypeRef Ty);
295unsigned LLVMGetArrayLength(LLVMTypeRef ArrayTy);
Gordon Henriksen5a3fe032007-12-17 16:08:32 +0000296unsigned LLVMGetPointerAddressSpace(LLVMTypeRef PointerTy);
Gordon Henriksen76a03742007-09-18 03:18:57 +0000297unsigned LLVMGetVectorSize(LLVMTypeRef VectorTy);
298
299/* Operations on other types */
Gordon Henriksena735a9c2008-05-04 12:55:34 +0000300LLVMTypeRef LLVMVoidType(void);
301LLVMTypeRef LLVMLabelType(void);
302LLVMTypeRef LLVMOpaqueType(void);
Gordon Henriksen76a03742007-09-18 03:18:57 +0000303
Gordon Henriksenffb48762007-10-07 00:13:35 +0000304/* Operations on type handles */
305LLVMTypeHandleRef LLVMCreateTypeHandle(LLVMTypeRef PotentiallyAbstractTy);
306void LLVMRefineType(LLVMTypeRef AbstractTy, LLVMTypeRef ConcreteTy);
307LLVMTypeRef LLVMResolveTypeHandle(LLVMTypeHandleRef TypeHandle);
308void LLVMDisposeTypeHandle(LLVMTypeHandleRef TypeHandle);
309
Gordon Henriksen76a03742007-09-18 03:18:57 +0000310
311/*===-- Values ------------------------------------------------------------===*/
312
313/* The bulk of LLVM's object model consists of values, which comprise a very
314 * rich type hierarchy.
Gordon Henriksen76a03742007-09-18 03:18:57 +0000315 */
316
Gordon Henriksen29e38942008-12-19 18:39:45 +0000317#define LLVM_FOR_EACH_VALUE_SUBCLASS(macro) \
318 macro(Argument) \
319 macro(BasicBlock) \
320 macro(InlineAsm) \
321 macro(User) \
322 macro(Constant) \
323 macro(ConstantAggregateZero) \
324 macro(ConstantArray) \
325 macro(ConstantExpr) \
326 macro(ConstantFP) \
327 macro(ConstantInt) \
328 macro(ConstantPointerNull) \
329 macro(ConstantStruct) \
330 macro(ConstantVector) \
331 macro(GlobalValue) \
332 macro(Function) \
333 macro(GlobalAlias) \
334 macro(GlobalVariable) \
335 macro(UndefValue) \
336 macro(Instruction) \
337 macro(BinaryOperator) \
338 macro(CallInst) \
339 macro(IntrinsicInst) \
340 macro(DbgInfoIntrinsic) \
341 macro(DbgDeclareInst) \
342 macro(DbgFuncStartInst) \
343 macro(DbgRegionEndInst) \
344 macro(DbgRegionStartInst) \
345 macro(DbgStopPointInst) \
346 macro(EHSelectorInst) \
347 macro(MemIntrinsic) \
348 macro(MemCpyInst) \
349 macro(MemMoveInst) \
350 macro(MemSetInst) \
351 macro(CmpInst) \
352 macro(FCmpInst) \
353 macro(ICmpInst) \
Gordon Henriksen29e38942008-12-19 18:39:45 +0000354 macro(ExtractElementInst) \
355 macro(GetElementPtrInst) \
356 macro(InsertElementInst) \
357 macro(InsertValueInst) \
358 macro(PHINode) \
359 macro(SelectInst) \
360 macro(ShuffleVectorInst) \
361 macro(StoreInst) \
362 macro(TerminatorInst) \
363 macro(BranchInst) \
364 macro(InvokeInst) \
365 macro(ReturnInst) \
366 macro(SwitchInst) \
367 macro(UnreachableInst) \
368 macro(UnwindInst) \
369 macro(UnaryInstruction) \
370 macro(AllocationInst) \
Gordon Henriksen05a868f2008-12-19 18:51:17 +0000371 macro(AllocaInst) \
372 macro(MallocInst) \
Gordon Henriksen29e38942008-12-19 18:39:45 +0000373 macro(CastInst) \
Gordon Henriksen05a868f2008-12-19 18:51:17 +0000374 macro(BitCastInst) \
375 macro(FPExtInst) \
376 macro(FPToSIInst) \
377 macro(FPToUIInst) \
378 macro(FPTruncInst) \
379 macro(IntToPtrInst) \
380 macro(PtrToIntInst) \
381 macro(SExtInst) \
382 macro(SIToFPInst) \
383 macro(TruncInst) \
384 macro(UIToFPInst) \
385 macro(ZExtInst) \
386 macro(ExtractValueInst) \
387 macro(FreeInst) \
388 macro(LoadInst) \
389 macro(VAArgInst)
Gordon Henriksen29e38942008-12-19 18:39:45 +0000390
Gordon Henriksen76a03742007-09-18 03:18:57 +0000391/* Operations on all values */
Gordon Henriksenc23b66c2007-09-26 20:56:12 +0000392LLVMTypeRef LLVMTypeOf(LLVMValueRef Val);
Gordon Henriksen76a03742007-09-18 03:18:57 +0000393const char *LLVMGetValueName(LLVMValueRef Val);
394void LLVMSetValueName(LLVMValueRef Val, const char *Name);
Gordon Henriksen1d0d24c2007-10-06 00:08:49 +0000395void LLVMDumpValue(LLVMValueRef Val);
Gordon Henriksen76a03742007-09-18 03:18:57 +0000396
Gordon Henriksen29e38942008-12-19 18:39:45 +0000397/* Conversion functions. Return the input value if it is an instance of the
398 specified class, otherwise NULL. See llvm::dyn_cast_or_null<>. */
399#define LLVM_DECLARE_VALUE_CAST(name) \
400 LLVMValueRef LLVMIsA##name(LLVMValueRef Val);
401LLVM_FOR_EACH_VALUE_SUBCLASS(LLVM_DECLARE_VALUE_CAST)
402
Gordon Henriksen76a03742007-09-18 03:18:57 +0000403/* Operations on constants of any type */
Gordon Henriksen1046c732007-10-06 15:11:06 +0000404LLVMValueRef LLVMConstNull(LLVMTypeRef Ty); /* all zeroes */
405LLVMValueRef LLVMConstAllOnes(LLVMTypeRef Ty); /* only for int/vector */
Gordon Henriksen76a03742007-09-18 03:18:57 +0000406LLVMValueRef LLVMGetUndef(LLVMTypeRef Ty);
Gordon Henriksendc88c062007-09-18 18:07:51 +0000407int LLVMIsConstant(LLVMValueRef Val);
Gordon Henriksen76a03742007-09-18 03:18:57 +0000408int LLVMIsNull(LLVMValueRef Val);
Gordon Henriksendc88c062007-09-18 18:07:51 +0000409int LLVMIsUndef(LLVMValueRef Val);
Chris Lattner7f318242009-07-06 17:29:59 +0000410LLVMValueRef LLVMConstPointerNull(LLVMTypeRef Ty);
Gordon Henriksen76a03742007-09-18 03:18:57 +0000411
412/* Operations on scalar constants */
Gordon Henriksen1046c732007-10-06 15:11:06 +0000413LLVMValueRef LLVMConstInt(LLVMTypeRef IntTy, unsigned long long N,
414 int SignExtend);
415LLVMValueRef LLVMConstReal(LLVMTypeRef RealTy, double N);
Gordon Henriksen931e1212008-02-02 01:07:50 +0000416LLVMValueRef LLVMConstRealOfString(LLVMTypeRef RealTy, const char *Text);
Gordon Henriksen76a03742007-09-18 03:18:57 +0000417
418/* Operations on composite constants */
Gordon Henriksen1046c732007-10-06 15:11:06 +0000419LLVMValueRef LLVMConstString(const char *Str, unsigned Length,
420 int DontNullTerminate);
Gordon Henriksen2ad5aef2008-04-25 03:21:19 +0000421LLVMValueRef LLVMConstArray(LLVMTypeRef ElementTy,
Gordon Henriksen1046c732007-10-06 15:11:06 +0000422 LLVMValueRef *ConstantVals, unsigned Length);
423LLVMValueRef LLVMConstStruct(LLVMValueRef *ConstantVals, unsigned Count,
424 int packed);
425LLVMValueRef LLVMConstVector(LLVMValueRef *ScalarConstantVals, unsigned Size);
Gordon Henriksen76a03742007-09-18 03:18:57 +0000426
Gordon Henriksen7ce31762007-10-06 14:29:36 +0000427/* Constant expressions */
428LLVMValueRef LLVMSizeOf(LLVMTypeRef Ty);
429LLVMValueRef LLVMConstNeg(LLVMValueRef ConstantVal);
430LLVMValueRef LLVMConstNot(LLVMValueRef ConstantVal);
431LLVMValueRef LLVMConstAdd(LLVMValueRef LHSConstant, LLVMValueRef RHSConstant);
432LLVMValueRef LLVMConstSub(LLVMValueRef LHSConstant, LLVMValueRef RHSConstant);
433LLVMValueRef LLVMConstMul(LLVMValueRef LHSConstant, LLVMValueRef RHSConstant);
434LLVMValueRef LLVMConstUDiv(LLVMValueRef LHSConstant, LLVMValueRef RHSConstant);
435LLVMValueRef LLVMConstSDiv(LLVMValueRef LHSConstant, LLVMValueRef RHSConstant);
436LLVMValueRef LLVMConstFDiv(LLVMValueRef LHSConstant, LLVMValueRef RHSConstant);
437LLVMValueRef LLVMConstURem(LLVMValueRef LHSConstant, LLVMValueRef RHSConstant);
438LLVMValueRef LLVMConstSRem(LLVMValueRef LHSConstant, LLVMValueRef RHSConstant);
439LLVMValueRef LLVMConstFRem(LLVMValueRef LHSConstant, LLVMValueRef RHSConstant);
440LLVMValueRef LLVMConstAnd(LLVMValueRef LHSConstant, LLVMValueRef RHSConstant);
441LLVMValueRef LLVMConstOr(LLVMValueRef LHSConstant, LLVMValueRef RHSConstant);
442LLVMValueRef LLVMConstXor(LLVMValueRef LHSConstant, LLVMValueRef RHSConstant);
443LLVMValueRef LLVMConstICmp(LLVMIntPredicate Predicate,
444 LLVMValueRef LHSConstant, LLVMValueRef RHSConstant);
445LLVMValueRef LLVMConstFCmp(LLVMRealPredicate Predicate,
446 LLVMValueRef LHSConstant, LLVMValueRef RHSConstant);
447LLVMValueRef LLVMConstShl(LLVMValueRef LHSConstant, LLVMValueRef RHSConstant);
448LLVMValueRef LLVMConstLShr(LLVMValueRef LHSConstant, LLVMValueRef RHSConstant);
449LLVMValueRef LLVMConstAShr(LLVMValueRef LHSConstant, LLVMValueRef RHSConstant);
450LLVMValueRef LLVMConstGEP(LLVMValueRef ConstantVal,
451 LLVMValueRef *ConstantIndices, unsigned NumIndices);
452LLVMValueRef LLVMConstTrunc(LLVMValueRef ConstantVal, LLVMTypeRef ToType);
453LLVMValueRef LLVMConstSExt(LLVMValueRef ConstantVal, LLVMTypeRef ToType);
454LLVMValueRef LLVMConstZExt(LLVMValueRef ConstantVal, LLVMTypeRef ToType);
455LLVMValueRef LLVMConstFPTrunc(LLVMValueRef ConstantVal, LLVMTypeRef ToType);
456LLVMValueRef LLVMConstFPExt(LLVMValueRef ConstantVal, LLVMTypeRef ToType);
457LLVMValueRef LLVMConstUIToFP(LLVMValueRef ConstantVal, LLVMTypeRef ToType);
458LLVMValueRef LLVMConstSIToFP(LLVMValueRef ConstantVal, LLVMTypeRef ToType);
459LLVMValueRef LLVMConstFPToUI(LLVMValueRef ConstantVal, LLVMTypeRef ToType);
460LLVMValueRef LLVMConstFPToSI(LLVMValueRef ConstantVal, LLVMTypeRef ToType);
461LLVMValueRef LLVMConstPtrToInt(LLVMValueRef ConstantVal, LLVMTypeRef ToType);
462LLVMValueRef LLVMConstIntToPtr(LLVMValueRef ConstantVal, LLVMTypeRef ToType);
463LLVMValueRef LLVMConstBitCast(LLVMValueRef ConstantVal, LLVMTypeRef ToType);
464LLVMValueRef LLVMConstSelect(LLVMValueRef ConstantCondition,
465 LLVMValueRef ConstantIfTrue,
466 LLVMValueRef ConstantIfFalse);
467LLVMValueRef LLVMConstExtractElement(LLVMValueRef VectorConstant,
468 LLVMValueRef IndexConstant);
469LLVMValueRef LLVMConstInsertElement(LLVMValueRef VectorConstant,
470 LLVMValueRef ElementValueConstant,
471 LLVMValueRef IndexConstant);
472LLVMValueRef LLVMConstShuffleVector(LLVMValueRef VectorAConstant,
473 LLVMValueRef VectorBConstant,
474 LLVMValueRef MaskConstant);
Dan Gohmand5104a52008-11-03 22:55:43 +0000475LLVMValueRef LLVMConstExtractValue(LLVMValueRef AggConstant, unsigned *IdxList,
476 unsigned NumIdx);
477LLVMValueRef LLVMConstInsertValue(LLVMValueRef AggConstant,
478 LLVMValueRef ElementValueConstant,
479 unsigned *IdxList, unsigned NumIdx);
Chris Lattner3d1f5522008-12-17 21:39:50 +0000480LLVMValueRef LLVMConstInlineAsm(LLVMTypeRef Ty,
481 const char *AsmString, const char *Constraints,
482 int HasSideEffects);
Gordon Henriksen7ce31762007-10-06 14:29:36 +0000483
Gordon Henriksen76a03742007-09-18 03:18:57 +0000484/* Operations on global variables, functions, and aliases (globals) */
Gordon Henriksen265f7802008-03-19 01:11:35 +0000485LLVMModuleRef LLVMGetGlobalParent(LLVMValueRef Global);
Gordon Henriksen76a03742007-09-18 03:18:57 +0000486int LLVMIsDeclaration(LLVMValueRef Global);
487LLVMLinkage LLVMGetLinkage(LLVMValueRef Global);
488void LLVMSetLinkage(LLVMValueRef Global, LLVMLinkage Linkage);
489const char *LLVMGetSection(LLVMValueRef Global);
490void LLVMSetSection(LLVMValueRef Global, const char *Section);
491LLVMVisibility LLVMGetVisibility(LLVMValueRef Global);
492void LLVMSetVisibility(LLVMValueRef Global, LLVMVisibility Viz);
493unsigned LLVMGetAlignment(LLVMValueRef Global);
494void LLVMSetAlignment(LLVMValueRef Global, unsigned Bytes);
495
496/* Operations on global variables */
497LLVMValueRef LLVMAddGlobal(LLVMModuleRef M, LLVMTypeRef Ty, const char *Name);
Gordon Henriksen783f7bb2007-10-08 03:45:09 +0000498LLVMValueRef LLVMGetNamedGlobal(LLVMModuleRef M, const char *Name);
Gordon Henriksen07a45f42008-03-23 22:21:29 +0000499LLVMValueRef LLVMGetFirstGlobal(LLVMModuleRef M);
500LLVMValueRef LLVMGetLastGlobal(LLVMModuleRef M);
501LLVMValueRef LLVMGetNextGlobal(LLVMValueRef GlobalVar);
502LLVMValueRef LLVMGetPreviousGlobal(LLVMValueRef GlobalVar);
Gordon Henriksen76a03742007-09-18 03:18:57 +0000503void LLVMDeleteGlobal(LLVMValueRef GlobalVar);
Gordon Henriksen76a03742007-09-18 03:18:57 +0000504LLVMValueRef LLVMGetInitializer(LLVMValueRef GlobalVar);
505void LLVMSetInitializer(LLVMValueRef GlobalVar, LLVMValueRef ConstantVal);
506int LLVMIsThreadLocal(LLVMValueRef GlobalVar);
507void LLVMSetThreadLocal(LLVMValueRef GlobalVar, int IsThreadLocal);
Gordon Henriksen751ebf72007-10-07 17:31:42 +0000508int LLVMIsGlobalConstant(LLVMValueRef GlobalVar);
509void LLVMSetGlobalConstant(LLVMValueRef GlobalVar, int IsConstant);
Gordon Henriksen76a03742007-09-18 03:18:57 +0000510
Chris Lattner3d1f5522008-12-17 21:39:50 +0000511/* Operations on aliases */
512LLVMValueRef LLVMAddAlias(LLVMModuleRef M, LLVMTypeRef Ty, LLVMValueRef Aliasee,
513 const char *Name);
514
Gordon Henriksenc23b66c2007-09-26 20:56:12 +0000515/* Operations on functions */
516LLVMValueRef LLVMAddFunction(LLVMModuleRef M, const char *Name,
517 LLVMTypeRef FunctionTy);
Gordon Henriksen783f7bb2007-10-08 03:45:09 +0000518LLVMValueRef LLVMGetNamedFunction(LLVMModuleRef M, const char *Name);
Gordon Henriksen054817c2008-03-19 03:47:18 +0000519LLVMValueRef LLVMGetFirstFunction(LLVMModuleRef M);
520LLVMValueRef LLVMGetLastFunction(LLVMModuleRef M);
521LLVMValueRef LLVMGetNextFunction(LLVMValueRef Fn);
522LLVMValueRef LLVMGetPreviousFunction(LLVMValueRef Fn);
Gordon Henriksenc23b66c2007-09-26 20:56:12 +0000523void LLVMDeleteFunction(LLVMValueRef Fn);
Gordon Henriksenc23b66c2007-09-26 20:56:12 +0000524unsigned LLVMGetIntrinsicID(LLVMValueRef Fn);
525unsigned LLVMGetFunctionCallConv(LLVMValueRef Fn);
526void LLVMSetFunctionCallConv(LLVMValueRef Fn, unsigned CC);
Gordon Henriksend930f912008-08-17 18:44:35 +0000527const char *LLVMGetGC(LLVMValueRef Fn);
528void LLVMSetGC(LLVMValueRef Fn, const char *Name);
Duncan Sands7374a012009-05-06 12:21:17 +0000529void LLVMAddFunctionAttr(LLVMValueRef Fn, LLVMAttribute PA);
530void LLVMRemoveFunctionAttr(LLVMValueRef Fn, LLVMAttribute PA);
Gordon Henriksenc23b66c2007-09-26 20:56:12 +0000531
Gordon Henriksen265f7802008-03-19 01:11:35 +0000532/* Operations on parameters */
533unsigned LLVMCountParams(LLVMValueRef Fn);
534void LLVMGetParams(LLVMValueRef Fn, LLVMValueRef *Params);
535LLVMValueRef LLVMGetParam(LLVMValueRef Fn, unsigned Index);
536LLVMValueRef LLVMGetParamParent(LLVMValueRef Inst);
Gordon Henriksen07a45f42008-03-23 22:21:29 +0000537LLVMValueRef LLVMGetFirstParam(LLVMValueRef Fn);
538LLVMValueRef LLVMGetLastParam(LLVMValueRef Fn);
539LLVMValueRef LLVMGetNextParam(LLVMValueRef Arg);
540LLVMValueRef LLVMGetPreviousParam(LLVMValueRef Arg);
Devang Patel4c758ea2008-09-25 21:00:45 +0000541void LLVMAddAttribute(LLVMValueRef Arg, LLVMAttribute PA);
542void LLVMRemoveAttribute(LLVMValueRef Arg, LLVMAttribute PA);
Gordon Henriksen2d9cc212008-04-28 17:37:06 +0000543void LLVMSetParamAlignment(LLVMValueRef Arg, unsigned align);
Gordon Henriksen265f7802008-03-19 01:11:35 +0000544
Gordon Henriksenc23b66c2007-09-26 20:56:12 +0000545/* Operations on basic blocks */
Gordon Henriksen07a45f42008-03-23 22:21:29 +0000546LLVMValueRef LLVMBasicBlockAsValue(LLVMBasicBlockRef BB);
Gordon Henriksenc23b66c2007-09-26 20:56:12 +0000547int LLVMValueIsBasicBlock(LLVMValueRef Val);
548LLVMBasicBlockRef LLVMValueAsBasicBlock(LLVMValueRef Val);
Gordon Henriksen07a45f42008-03-23 22:21:29 +0000549LLVMValueRef LLVMGetBasicBlockParent(LLVMBasicBlockRef BB);
Gordon Henriksenc23b66c2007-09-26 20:56:12 +0000550unsigned LLVMCountBasicBlocks(LLVMValueRef Fn);
551void LLVMGetBasicBlocks(LLVMValueRef Fn, LLVMBasicBlockRef *BasicBlocks);
Gordon Henriksen054817c2008-03-19 03:47:18 +0000552LLVMBasicBlockRef LLVMGetFirstBasicBlock(LLVMValueRef Fn);
553LLVMBasicBlockRef LLVMGetLastBasicBlock(LLVMValueRef Fn);
554LLVMBasicBlockRef LLVMGetNextBasicBlock(LLVMBasicBlockRef BB);
555LLVMBasicBlockRef LLVMGetPreviousBasicBlock(LLVMBasicBlockRef BB);
Gordon Henriksenc23b66c2007-09-26 20:56:12 +0000556LLVMBasicBlockRef LLVMGetEntryBasicBlock(LLVMValueRef Fn);
557LLVMBasicBlockRef LLVMAppendBasicBlock(LLVMValueRef Fn, const char *Name);
558LLVMBasicBlockRef LLVMInsertBasicBlock(LLVMBasicBlockRef InsertBeforeBB,
559 const char *Name);
560void LLVMDeleteBasicBlock(LLVMBasicBlockRef BB);
561
Gordon Henriksen265f7802008-03-19 01:11:35 +0000562/* Operations on instructions */
563LLVMBasicBlockRef LLVMGetInstructionParent(LLVMValueRef Inst);
Gordon Henriksen054817c2008-03-19 03:47:18 +0000564LLVMValueRef LLVMGetFirstInstruction(LLVMBasicBlockRef BB);
565LLVMValueRef LLVMGetLastInstruction(LLVMBasicBlockRef BB);
566LLVMValueRef LLVMGetNextInstruction(LLVMValueRef Inst);
567LLVMValueRef LLVMGetPreviousInstruction(LLVMValueRef Inst);
Gordon Henriksen265f7802008-03-19 01:11:35 +0000568
Gordon Henriksen1158c532007-12-29 20:45:00 +0000569/* Operations on call sites */
570void LLVMSetInstructionCallConv(LLVMValueRef Instr, unsigned CC);
571unsigned LLVMGetInstructionCallConv(LLVMValueRef Instr);
Devang Patel4c758ea2008-09-25 21:00:45 +0000572void LLVMAddInstrAttribute(LLVMValueRef Instr, unsigned index, LLVMAttribute);
573void LLVMRemoveInstrAttribute(LLVMValueRef Instr, unsigned index,
574 LLVMAttribute);
Gordon Henriksen2d9cc212008-04-28 17:37:06 +0000575void LLVMSetInstrParamAlignment(LLVMValueRef Instr, unsigned index,
576 unsigned align);
Gordon Henriksen1158c532007-12-29 20:45:00 +0000577
Gordon Henrikseneeb65372008-08-30 16:34:54 +0000578/* Operations on call instructions (only) */
579int LLVMIsTailCall(LLVMValueRef CallInst);
580void LLVMSetTailCall(LLVMValueRef CallInst, int IsTailCall);
581
Gordon Henriksen44dd8fb2007-10-08 18:14:39 +0000582/* Operations on phi nodes */
583void LLVMAddIncoming(LLVMValueRef PhiNode, LLVMValueRef *IncomingValues,
584 LLVMBasicBlockRef *IncomingBlocks, unsigned Count);
585unsigned LLVMCountIncoming(LLVMValueRef PhiNode);
586LLVMValueRef LLVMGetIncomingValue(LLVMValueRef PhiNode, unsigned Index);
587LLVMBasicBlockRef LLVMGetIncomingBlock(LLVMValueRef PhiNode, unsigned Index);
Gordon Henriksenc23b66c2007-09-26 20:56:12 +0000588
589/*===-- Instruction builders ----------------------------------------------===*/
590
591/* An instruction builder represents a point within a basic block, and is the
592 * exclusive means of building instructions using the C interface.
593 */
594
Gordon Henriksena735a9c2008-05-04 12:55:34 +0000595LLVMBuilderRef LLVMCreateBuilder(void);
Gordon Henriksen054817c2008-03-19 03:47:18 +0000596void LLVMPositionBuilder(LLVMBuilderRef Builder, LLVMBasicBlockRef Block,
597 LLVMValueRef Instr);
Gordon Henriksenc23b66c2007-09-26 20:56:12 +0000598void LLVMPositionBuilderBefore(LLVMBuilderRef Builder, LLVMValueRef Instr);
599void LLVMPositionBuilderAtEnd(LLVMBuilderRef Builder, LLVMBasicBlockRef Block);
Gordon Henriksen265f7802008-03-19 01:11:35 +0000600LLVMBasicBlockRef LLVMGetInsertBlock(LLVMBuilderRef Builder);
Chris Lattner3d1f5522008-12-17 21:39:50 +0000601void LLVMClearInsertionPosition(LLVMBuilderRef Builder);
602void LLVMInsertIntoBuilder(LLVMBuilderRef Builder, LLVMValueRef Instr);
Gordon Henriksenc23b66c2007-09-26 20:56:12 +0000603void LLVMDisposeBuilder(LLVMBuilderRef Builder);
604
605/* Terminators */
606LLVMValueRef LLVMBuildRetVoid(LLVMBuilderRef);
607LLVMValueRef LLVMBuildRet(LLVMBuilderRef, LLVMValueRef V);
608LLVMValueRef LLVMBuildBr(LLVMBuilderRef, LLVMBasicBlockRef Dest);
609LLVMValueRef LLVMBuildCondBr(LLVMBuilderRef, LLVMValueRef If,
610 LLVMBasicBlockRef Then, LLVMBasicBlockRef Else);
611LLVMValueRef LLVMBuildSwitch(LLVMBuilderRef, LLVMValueRef V,
612 LLVMBasicBlockRef Else, unsigned NumCases);
613LLVMValueRef LLVMBuildInvoke(LLVMBuilderRef, LLVMValueRef Fn,
614 LLVMValueRef *Args, unsigned NumArgs,
615 LLVMBasicBlockRef Then, LLVMBasicBlockRef Catch,
616 const char *Name);
617LLVMValueRef LLVMBuildUnwind(LLVMBuilderRef);
618LLVMValueRef LLVMBuildUnreachable(LLVMBuilderRef);
619
Gordon Henriksen097102c2008-01-01 05:50:53 +0000620/* Add a case to the switch instruction */
621void LLVMAddCase(LLVMValueRef Switch, LLVMValueRef OnVal,
622 LLVMBasicBlockRef Dest);
623
Gordon Henriksenc23b66c2007-09-26 20:56:12 +0000624/* Arithmetic */
625LLVMValueRef LLVMBuildAdd(LLVMBuilderRef, LLVMValueRef LHS, LLVMValueRef RHS,
626 const char *Name);
627LLVMValueRef LLVMBuildSub(LLVMBuilderRef, LLVMValueRef LHS, LLVMValueRef RHS,
628 const char *Name);
629LLVMValueRef LLVMBuildMul(LLVMBuilderRef, LLVMValueRef LHS, LLVMValueRef RHS,
630 const char *Name);
631LLVMValueRef LLVMBuildUDiv(LLVMBuilderRef, LLVMValueRef LHS, LLVMValueRef RHS,
632 const char *Name);
633LLVMValueRef LLVMBuildSDiv(LLVMBuilderRef, LLVMValueRef LHS, LLVMValueRef RHS,
634 const char *Name);
635LLVMValueRef LLVMBuildFDiv(LLVMBuilderRef, LLVMValueRef LHS, LLVMValueRef RHS,
636 const char *Name);
637LLVMValueRef LLVMBuildURem(LLVMBuilderRef, LLVMValueRef LHS, LLVMValueRef RHS,
638 const char *Name);
639LLVMValueRef LLVMBuildSRem(LLVMBuilderRef, LLVMValueRef LHS, LLVMValueRef RHS,
640 const char *Name);
641LLVMValueRef LLVMBuildFRem(LLVMBuilderRef, LLVMValueRef LHS, LLVMValueRef RHS,
642 const char *Name);
643LLVMValueRef LLVMBuildShl(LLVMBuilderRef, LLVMValueRef LHS, LLVMValueRef RHS,
644 const char *Name);
645LLVMValueRef LLVMBuildLShr(LLVMBuilderRef, LLVMValueRef LHS, LLVMValueRef RHS,
646 const char *Name);
647LLVMValueRef LLVMBuildAShr(LLVMBuilderRef, LLVMValueRef LHS, LLVMValueRef RHS,
648 const char *Name);
649LLVMValueRef LLVMBuildAnd(LLVMBuilderRef, LLVMValueRef LHS, LLVMValueRef RHS,
650 const char *Name);
651LLVMValueRef LLVMBuildOr(LLVMBuilderRef, LLVMValueRef LHS, LLVMValueRef RHS,
652 const char *Name);
653LLVMValueRef LLVMBuildXor(LLVMBuilderRef, LLVMValueRef LHS, LLVMValueRef RHS,
654 const char *Name);
655LLVMValueRef LLVMBuildNeg(LLVMBuilderRef, LLVMValueRef V, const char *Name);
656LLVMValueRef LLVMBuildNot(LLVMBuilderRef, LLVMValueRef V, const char *Name);
657
658/* Memory */
659LLVMValueRef LLVMBuildMalloc(LLVMBuilderRef, LLVMTypeRef Ty, const char *Name);
660LLVMValueRef LLVMBuildArrayMalloc(LLVMBuilderRef, LLVMTypeRef Ty,
661 LLVMValueRef Val, const char *Name);
662LLVMValueRef LLVMBuildAlloca(LLVMBuilderRef, LLVMTypeRef Ty, const char *Name);
663LLVMValueRef LLVMBuildArrayAlloca(LLVMBuilderRef, LLVMTypeRef Ty,
664 LLVMValueRef Val, const char *Name);
665LLVMValueRef LLVMBuildFree(LLVMBuilderRef, LLVMValueRef PointerVal);
666LLVMValueRef LLVMBuildLoad(LLVMBuilderRef, LLVMValueRef PointerVal,
667 const char *Name);
668LLVMValueRef LLVMBuildStore(LLVMBuilderRef, LLVMValueRef Val, LLVMValueRef Ptr);
669LLVMValueRef LLVMBuildGEP(LLVMBuilderRef B, LLVMValueRef Pointer,
670 LLVMValueRef *Indices, unsigned NumIndices,
671 const char *Name);
672
673/* Casts */
674LLVMValueRef LLVMBuildTrunc(LLVMBuilderRef, LLVMValueRef Val,
675 LLVMTypeRef DestTy, const char *Name);
676LLVMValueRef LLVMBuildZExt(LLVMBuilderRef, LLVMValueRef Val,
677 LLVMTypeRef DestTy, const char *Name);
678LLVMValueRef LLVMBuildSExt(LLVMBuilderRef, LLVMValueRef Val,
679 LLVMTypeRef DestTy, const char *Name);
680LLVMValueRef LLVMBuildFPToUI(LLVMBuilderRef, LLVMValueRef Val,
681 LLVMTypeRef DestTy, const char *Name);
682LLVMValueRef LLVMBuildFPToSI(LLVMBuilderRef, LLVMValueRef Val,
683 LLVMTypeRef DestTy, const char *Name);
684LLVMValueRef LLVMBuildUIToFP(LLVMBuilderRef, LLVMValueRef Val,
685 LLVMTypeRef DestTy, const char *Name);
686LLVMValueRef LLVMBuildSIToFP(LLVMBuilderRef, LLVMValueRef Val,
687 LLVMTypeRef DestTy, const char *Name);
688LLVMValueRef LLVMBuildFPTrunc(LLVMBuilderRef, LLVMValueRef Val,
689 LLVMTypeRef DestTy, const char *Name);
690LLVMValueRef LLVMBuildFPExt(LLVMBuilderRef, LLVMValueRef Val,
691 LLVMTypeRef DestTy, const char *Name);
692LLVMValueRef LLVMBuildPtrToInt(LLVMBuilderRef, LLVMValueRef Val,
693 LLVMTypeRef DestTy, const char *Name);
694LLVMValueRef LLVMBuildIntToPtr(LLVMBuilderRef, LLVMValueRef Val,
695 LLVMTypeRef DestTy, const char *Name);
696LLVMValueRef LLVMBuildBitCast(LLVMBuilderRef, LLVMValueRef Val,
697 LLVMTypeRef DestTy, const char *Name);
698
699/* Comparisons */
700LLVMValueRef LLVMBuildICmp(LLVMBuilderRef, LLVMIntPredicate Op,
701 LLVMValueRef LHS, LLVMValueRef RHS,
702 const char *Name);
703LLVMValueRef LLVMBuildFCmp(LLVMBuilderRef, LLVMRealPredicate Op,
704 LLVMValueRef LHS, LLVMValueRef RHS,
705 const char *Name);
706
707/* Miscellaneous instructions */
708LLVMValueRef LLVMBuildPhi(LLVMBuilderRef, LLVMTypeRef Ty, const char *Name);
709LLVMValueRef LLVMBuildCall(LLVMBuilderRef, LLVMValueRef Fn,
710 LLVMValueRef *Args, unsigned NumArgs,
711 const char *Name);
712LLVMValueRef LLVMBuildSelect(LLVMBuilderRef, LLVMValueRef If,
713 LLVMValueRef Then, LLVMValueRef Else,
714 const char *Name);
715LLVMValueRef LLVMBuildVAArg(LLVMBuilderRef, LLVMValueRef List, LLVMTypeRef Ty,
716 const char *Name);
717LLVMValueRef LLVMBuildExtractElement(LLVMBuilderRef, LLVMValueRef VecVal,
718 LLVMValueRef Index, const char *Name);
719LLVMValueRef LLVMBuildInsertElement(LLVMBuilderRef, LLVMValueRef VecVal,
720 LLVMValueRef EltVal, LLVMValueRef Index,
721 const char *Name);
722LLVMValueRef LLVMBuildShuffleVector(LLVMBuilderRef, LLVMValueRef V1,
723 LLVMValueRef V2, LLVMValueRef Mask,
724 const char *Name);
Dan Gohmand5104a52008-11-03 22:55:43 +0000725LLVMValueRef LLVMBuildExtractValue(LLVMBuilderRef, LLVMValueRef AggVal,
726 unsigned Index, const char *Name);
727LLVMValueRef LLVMBuildInsertValue(LLVMBuilderRef, LLVMValueRef AggVal,
728 LLVMValueRef EltVal, unsigned Index,
729 const char *Name);
Gordon Henriksen76a03742007-09-18 03:18:57 +0000730
Gordon Henriksen34eb6d82007-12-19 22:30:40 +0000731
Gordon Henriksen0a68fe22007-12-12 01:04:30 +0000732/*===-- Module providers --------------------------------------------------===*/
733
734/* Encapsulates the module M in a module provider, taking ownership of the
735 * module.
736 * See the constructor llvm::ExistingModuleProvider::ExistingModuleProvider.
737 */
738LLVMModuleProviderRef
739LLVMCreateModuleProviderForExistingModule(LLVMModuleRef M);
740
741/* Destroys the module provider MP as well as the contained module.
742 * See the destructor llvm::ModuleProvider::~ModuleProvider.
743 */
744void LLVMDisposeModuleProvider(LLVMModuleProviderRef MP);
745
Gordon Henriksen34eb6d82007-12-19 22:30:40 +0000746
747/*===-- Memory buffers ----------------------------------------------------===*/
748
749int LLVMCreateMemoryBufferWithContentsOfFile(const char *Path,
750 LLVMMemoryBufferRef *OutMemBuf,
751 char **OutMessage);
752int LLVMCreateMemoryBufferWithSTDIN(LLVMMemoryBufferRef *OutMemBuf,
753 char **OutMessage);
754void LLVMDisposeMemoryBuffer(LLVMMemoryBufferRef MemBuf);
755
Gordon Henriksen878114b2008-03-16 04:20:44 +0000756
757/*===-- Pass Managers -----------------------------------------------------===*/
758
759/** Constructs a new whole-module pass pipeline. This type of pipeline is
760 suitable for link-time optimization and whole-module transformations.
761 See llvm::PassManager::PassManager. */
Gordon Henriksena735a9c2008-05-04 12:55:34 +0000762LLVMPassManagerRef LLVMCreatePassManager(void);
Gordon Henriksen878114b2008-03-16 04:20:44 +0000763
764/** Constructs a new function-by-function pass pipeline over the module
765 provider. It does not take ownership of the module provider. This type of
766 pipeline is suitable for code generation and JIT compilation tasks.
767 See llvm::FunctionPassManager::FunctionPassManager. */
768LLVMPassManagerRef LLVMCreateFunctionPassManager(LLVMModuleProviderRef MP);
769
770/** Initializes, executes on the provided module, and finalizes all of the
771 passes scheduled in the pass manager. Returns 1 if any of the passes
772 modified the module, 0 otherwise. See llvm::PassManager::run(Module&). */
773int LLVMRunPassManager(LLVMPassManagerRef PM, LLVMModuleRef M);
774
775/** Initializes all of the function passes scheduled in the function pass
776 manager. Returns 1 if any of the passes modified the module, 0 otherwise.
777 See llvm::FunctionPassManager::doInitialization. */
778int LLVMInitializeFunctionPassManager(LLVMPassManagerRef FPM);
779
780/** Executes all of the function passes scheduled in the function pass manager
781 on the provided function. Returns 1 if any of the passes modified the
782 function, false otherwise.
783 See llvm::FunctionPassManager::run(Function&). */
784int LLVMRunFunctionPassManager(LLVMPassManagerRef FPM, LLVMValueRef F);
785
786/** Finalizes all of the function passes scheduled in in the function pass
787 manager. Returns 1 if any of the passes modified the module, 0 otherwise.
788 See llvm::FunctionPassManager::doFinalization. */
789int LLVMFinalizeFunctionPassManager(LLVMPassManagerRef FPM);
790
791/** Frees the memory of a pass pipeline. For function pipelines, does not free
792 the module provider.
793 See llvm::PassManagerBase::~PassManagerBase. */
794void LLVMDisposePassManager(LLVMPassManagerRef PM);
795
796
Gordon Henriksen76a03742007-09-18 03:18:57 +0000797#ifdef __cplusplus
798}
Gordon Henriksen76a03742007-09-18 03:18:57 +0000799
Gordon Henriksen7330acd2007-10-05 23:59:36 +0000800namespace llvm {
Gordon Henriksen0a68fe22007-12-12 01:04:30 +0000801 class ModuleProvider;
Gordon Henriksen34eb6d82007-12-19 22:30:40 +0000802 class MemoryBuffer;
Gordon Henriksen96571492008-03-16 15:55:43 +0000803 class PassManagerBase;
Gordon Henriksen0a68fe22007-12-12 01:04:30 +0000804
Gordon Henriksen34eb6d82007-12-19 22:30:40 +0000805 #define DEFINE_SIMPLE_CONVERSION_FUNCTIONS(ty, ref) \
806 inline ty *unwrap(ref P) { \
807 return reinterpret_cast<ty*>(P); \
808 } \
809 \
810 inline ref wrap(const ty *P) { \
811 return reinterpret_cast<ref>(const_cast<ty*>(P)); \
812 }
Gordon Henriksen7330acd2007-10-05 23:59:36 +0000813
Gordon Henriksen878114b2008-03-16 04:20:44 +0000814 #define DEFINE_ISA_CONVERSION_FUNCTIONS(ty, ref) \
815 DEFINE_SIMPLE_CONVERSION_FUNCTIONS(ty, ref) \
816 \
817 template<typename T> \
818 inline T *unwrap(ref P) { \
819 return cast<T>(unwrap(P)); \
820 }
821
822 #define DEFINE_STDCXX_CONVERSION_FUNCTIONS(ty, ref) \
823 DEFINE_SIMPLE_CONVERSION_FUNCTIONS(ty, ref) \
824 \
825 template<typename T> \
826 inline T *unwrap(ref P) { \
827 T *Q = dynamic_cast<T*>(unwrap(P)); \
828 assert(Q && "Invalid cast!"); \
829 return Q; \
830 }
831
832 DEFINE_ISA_CONVERSION_FUNCTIONS (Type, LLVMTypeRef )
833 DEFINE_ISA_CONVERSION_FUNCTIONS (Value, LLVMValueRef )
Gordon Henriksen823f9732007-12-27 18:25:59 +0000834 DEFINE_SIMPLE_CONVERSION_FUNCTIONS(Module, LLVMModuleRef )
835 DEFINE_SIMPLE_CONVERSION_FUNCTIONS(BasicBlock, LLVMBasicBlockRef )
Eric Christopher59278832008-08-08 19:39:37 +0000836 DEFINE_SIMPLE_CONVERSION_FUNCTIONS(IRBuilder<>, LLVMBuilderRef )
Gordon Henriksen823f9732007-12-27 18:25:59 +0000837 DEFINE_SIMPLE_CONVERSION_FUNCTIONS(PATypeHolder, LLVMTypeHandleRef )
838 DEFINE_SIMPLE_CONVERSION_FUNCTIONS(ModuleProvider, LLVMModuleProviderRef)
839 DEFINE_SIMPLE_CONVERSION_FUNCTIONS(MemoryBuffer, LLVMMemoryBufferRef )
Owen Anderson6773d382009-07-01 16:58:40 +0000840 DEFINE_SIMPLE_CONVERSION_FUNCTIONS(LLVMContext, LLVMContextRef )
Gordon Henriksen878114b2008-03-16 04:20:44 +0000841 DEFINE_STDCXX_CONVERSION_FUNCTIONS(PassManagerBase, LLVMPassManagerRef )
Gordon Henriksen7330acd2007-10-05 23:59:36 +0000842
Gordon Henriksen878114b2008-03-16 04:20:44 +0000843 #undef DEFINE_STDCXX_CONVERSION_FUNCTIONS
844 #undef DEFINE_ISA_CONVERSION_FUNCTIONS
Gordon Henriksen34eb6d82007-12-19 22:30:40 +0000845 #undef DEFINE_SIMPLE_CONVERSION_FUNCTIONS
Gordon Henriksen7330acd2007-10-05 23:59:36 +0000846
Gordon Henriksen34eb6d82007-12-19 22:30:40 +0000847 /* Specialized opaque type conversions.
848 */
Gordon Henriksen7330acd2007-10-05 23:59:36 +0000849 inline Type **unwrap(LLVMTypeRef* Tys) {
850 return reinterpret_cast<Type**>(Tys);
851 }
852
Gordon Henriksen7330acd2007-10-05 23:59:36 +0000853 inline LLVMTypeRef *wrap(const Type **Tys) {
854 return reinterpret_cast<LLVMTypeRef*>(const_cast<Type**>(Tys));
855 }
856
Gordon Henriksen34eb6d82007-12-19 22:30:40 +0000857 /* Specialized opaque value conversions.
Gordon Henriksen7330acd2007-10-05 23:59:36 +0000858 */
Gordon Henriksen7330acd2007-10-05 23:59:36 +0000859 inline Value **unwrap(LLVMValueRef *Vals) {
860 return reinterpret_cast<Value**>(Vals);
861 }
862
863 template<typename T>
864 inline T **unwrap(LLVMValueRef *Vals, unsigned Length) {
865 #if DEBUG
Chris Lattnerb7971152009-07-10 18:28:19 +0000866 for (LLVMValueRef *I = Vals, *E = Vals + Length; I != E; ++I)
Gordon Henriksen7330acd2007-10-05 23:59:36 +0000867 cast<T>(*I);
868 #endif
869 return reinterpret_cast<T**>(Vals);
870 }
871
Gordon Henriksen7330acd2007-10-05 23:59:36 +0000872 inline LLVMValueRef *wrap(const Value **Vals) {
873 return reinterpret_cast<LLVMValueRef*>(const_cast<Value**>(Vals));
874 }
Gordon Henriksen7330acd2007-10-05 23:59:36 +0000875}
876
877#endif /* !defined(__cplusplus) */
878
879#endif /* !defined(LLVM_C_CORE_H) */