blob: 34a91fa10fb8a940ee76af92e0451ca5178fe0d1 [file] [log] [blame]
Gordon Henriksen76a03742007-09-18 03:18:57 +00001/*===-- llvm-c/Core.h - Core Library C Interface ------------------*- C -*-===*\
2|* *|
3|* The LLVM Compiler Infrastructure *|
4|* *|
Chris Lattnere9cc7422007-12-29 19:59:42 +00005|* This file is distributed under the University of Illinois Open Source *|
6|* License. See LICENSE.TXT for details. *|
Gordon Henriksen76a03742007-09-18 03:18:57 +00007|* *|
8|*===----------------------------------------------------------------------===*|
9|* *|
10|* This header declares the C interface to libLLVMCore.a, which implements *|
11|* the LLVM intermediate representation. *|
12|* *|
13|* LLVM uses a polymorphic type hierarchy which C cannot represent, therefore *|
14|* parameters must be passed as base types. Despite the declared types, most *|
15|* of the functions provided operate only on branches of the type hierarchy. *|
16|* The declared parameter names are descriptive and specify which type is *|
17|* required. Additionally, each type hierarchy is documented along with the *|
18|* functions that operate upon it. For more detail, refer to LLVM's C++ code. *|
19|* If in doubt, refer to Core.cpp, which performs paramter downcasts in the *|
20|* form unwrap<RequiredType>(Param). *|
21|* *|
22|* Many exotic languages can interoperate with C code but have a harder time *|
23|* with C++ due to name mangling. So in addition to C, this interface enables *|
24|* tools written in such languages. *|
25|* *|
Gordon Henriksen7330acd2007-10-05 23:59:36 +000026|* When included into a C++ source file, also declares 'wrap' and 'unwrap' *|
27|* helpers to perform opaque reference<-->pointer conversions. These helpers *|
28|* are shorter and more tightly typed than writing the casts by hand when *|
29|* authoring bindings. In assert builds, they will do runtime type checking. *|
30|* *|
Gordon Henriksen76a03742007-09-18 03:18:57 +000031\*===----------------------------------------------------------------------===*/
32
33#ifndef LLVM_C_CORE_H
34#define LLVM_C_CORE_H
35
36#ifdef __cplusplus
Gordon Henriksen7330acd2007-10-05 23:59:36 +000037
38/* Need these includes to support the LLVM 'cast' template for the C++ 'wrap'
39 and 'unwrap' conversion functions. */
40#include "llvm/Module.h"
Duncan Sandsa07136e2008-04-13 06:22:09 +000041#include "llvm/Support/IRBuilder.h"
Gordon Henriksen7330acd2007-10-05 23:59:36 +000042
Gordon Henriksen76a03742007-09-18 03:18:57 +000043extern "C" {
44#endif
45
46
47/* Opaque types. */
Gordon Henriksen4a4d7352007-12-30 17:46:33 +000048
49/**
50 * The top-level container for all other LLVM Intermediate Representation (IR)
51 * objects. See the llvm::Module class.
52 */
Gordon Henriksen76a03742007-09-18 03:18:57 +000053typedef struct LLVMOpaqueModule *LLVMModuleRef;
Gordon Henriksen4a4d7352007-12-30 17:46:33 +000054
55/**
Gordon Henriksena49d4352008-03-07 19:13:06 +000056 * Each value in the LLVM IR has a type, an LLVMTypeRef. See the llvm::Type
57 * class.
Gordon Henriksen4a4d7352007-12-30 17:46:33 +000058 */
Gordon Henriksen76a03742007-09-18 03:18:57 +000059typedef struct LLVMOpaqueType *LLVMTypeRef;
Gordon Henriksen4a4d7352007-12-30 17:46:33 +000060
61/**
Gordon Henriksena49d4352008-03-07 19:13:06 +000062 * When building recursive types using LLVMRefineType, LLVMTypeRef values may
63 * become invalid; use LLVMTypeHandleRef to resolve this problem. See the
64 * llvm::AbstractTypeHolder class.
Gordon Henriksen4a4d7352007-12-30 17:46:33 +000065 */
Gordon Henriksenffb48762007-10-07 00:13:35 +000066typedef struct LLVMOpaqueTypeHandle *LLVMTypeHandleRef;
Gordon Henriksen4a4d7352007-12-30 17:46:33 +000067
Gordon Henriksen76a03742007-09-18 03:18:57 +000068typedef struct LLVMOpaqueValue *LLVMValueRef;
Gordon Henriksenc23b66c2007-09-26 20:56:12 +000069typedef struct LLVMOpaqueBasicBlock *LLVMBasicBlockRef;
70typedef struct LLVMOpaqueBuilder *LLVMBuilderRef;
Gordon Henriksen34eb6d82007-12-19 22:30:40 +000071
72/* Used to provide a module to JIT or interpreter.
73 * See the llvm::ModuleProvider class.
74 */
Gordon Henriksen0a68fe22007-12-12 01:04:30 +000075typedef struct LLVMOpaqueModuleProvider *LLVMModuleProviderRef;
Gordon Henriksen76a03742007-09-18 03:18:57 +000076
Gordon Henriksen34eb6d82007-12-19 22:30:40 +000077/* Used to provide a module to JIT or interpreter.
78 * See the llvm::MemoryBuffer class.
79 */
80typedef struct LLVMOpaqueMemoryBuffer *LLVMMemoryBufferRef;
81
Gordon Henriksen878114b2008-03-16 04:20:44 +000082/** See the llvm::PassManagerBase class. */
83typedef struct LLVMOpaquePassManager *LLVMPassManagerRef;
84
Gordon Henriksen76a03742007-09-18 03:18:57 +000085typedef enum {
Devang Patel4c758ea2008-09-25 21:00:45 +000086 LLVMZExtAttribute = 1<<0,
87 LLVMSExtAttribute = 1<<1,
88 LLVMNoReturnAttribute = 1<<2,
89 LLVMInRegAttribute = 1<<3,
90 LLVMStructRetAttribute = 1<<4,
91 LLVMNoUnwindAttribute = 1<<5,
92 LLVMNoAliasAttribute = 1<<6,
93 LLVMByValAttribute = 1<<7,
94 LLVMNestAttribute = 1<<8,
95 LLVMReadNoneAttribute = 1<<9,
96 LLVMReadOnlyAttribute = 1<<10
97} LLVMAttribute;
Gordon Henriksen2d9cc212008-04-28 17:37:06 +000098
99typedef enum {
Gordon Henriksen4a4d7352007-12-30 17:46:33 +0000100 LLVMVoidTypeKind, /**< type with no size */
101 LLVMFloatTypeKind, /**< 32 bit floating point type */
102 LLVMDoubleTypeKind, /**< 64 bit floating point type */
103 LLVMX86_FP80TypeKind, /**< 80 bit floating point type (X87) */
104 LLVMFP128TypeKind, /**< 128 bit floating point type (112-bit mantissa)*/
105 LLVMPPC_FP128TypeKind, /**< 128 bit floating point type (two 64-bits) */
106 LLVMLabelTypeKind, /**< Labels */
107 LLVMIntegerTypeKind, /**< Arbitrary bit width integers */
108 LLVMFunctionTypeKind, /**< Functions */
109 LLVMStructTypeKind, /**< Structures */
110 LLVMArrayTypeKind, /**< Arrays */
111 LLVMPointerTypeKind, /**< Pointers */
112 LLVMOpaqueTypeKind, /**< Opaque: type with unknown structure */
113 LLVMVectorTypeKind /**< SIMD 'packed' format, or other vector type */
Gordon Henriksen76a03742007-09-18 03:18:57 +0000114} LLVMTypeKind;
115
116typedef enum {
Gordon Henriksen4a4d7352007-12-30 17:46:33 +0000117 LLVMExternalLinkage, /**< Externally visible function */
Duncan Sands12da8ce2009-03-07 15:45:40 +0000118 LLVMLinkOnceAnyLinkage, /**< Keep one copy of function when linking (inline)*/
119 LLVMLinkOnceODRLinkage, /**< Same, but only replaced by something
120 equivalent. */
121 LLVMWeakAnyLinkage, /**< Keep one copy of function when linking (weak) */
122 LLVMWeakODRLinkage, /**< Same, but only replaced by something
123 equivalent. */
Gordon Henriksen4a4d7352007-12-30 17:46:33 +0000124 LLVMAppendingLinkage, /**< Special purpose, only applies to global arrays */
125 LLVMInternalLinkage, /**< Rename collisions when linking (static
126 functions) */
Duncan Sands12da8ce2009-03-07 15:45:40 +0000127 LLVMPrivateLinkage, /**< Like Internal, but omit from symbol table */
Gordon Henriksen4a4d7352007-12-30 17:46:33 +0000128 LLVMDLLImportLinkage, /**< Function to be imported from DLL */
129 LLVMDLLExportLinkage, /**< Function to be accessible from DLL */
Duncan Sandse2881052009-03-11 08:08:06 +0000130 LLVMExternalWeakLinkage,/**< ExternalWeak linkage description */
Duncan Sands12da8ce2009-03-07 15:45:40 +0000131 LLVMGhostLinkage, /**< Stand-in functions for streaming fns from
Gordon Henriksen4a4d7352007-12-30 17:46:33 +0000132 bitcode */
Duncan Sands12da8ce2009-03-07 15:45:40 +0000133 LLVMCommonAnyLinkage, /**< Tentative definitions */
134 LLVMCommonODRLinkage /**< Same, but only replaced by something
135 equivalent. */
Gordon Henriksen76a03742007-09-18 03:18:57 +0000136} LLVMLinkage;
137
138typedef enum {
Gordon Henriksen4a4d7352007-12-30 17:46:33 +0000139 LLVMDefaultVisibility, /**< The GV is visible */
140 LLVMHiddenVisibility, /**< The GV is hidden */
141 LLVMProtectedVisibility /**< The GV is protected */
Gordon Henriksen76a03742007-09-18 03:18:57 +0000142} LLVMVisibility;
143
Gordon Henriksenc23b66c2007-09-26 20:56:12 +0000144typedef enum {
145 LLVMCCallConv = 0,
146 LLVMFastCallConv = 8,
147 LLVMColdCallConv = 9,
148 LLVMX86StdcallCallConv = 64,
149 LLVMX86FastcallCallConv = 65
150} LLVMCallConv;
151
152typedef enum {
Gordon Henriksen4a4d7352007-12-30 17:46:33 +0000153 LLVMIntEQ = 32, /**< equal */
154 LLVMIntNE, /**< not equal */
155 LLVMIntUGT, /**< unsigned greater than */
156 LLVMIntUGE, /**< unsigned greater or equal */
157 LLVMIntULT, /**< unsigned less than */
158 LLVMIntULE, /**< unsigned less or equal */
159 LLVMIntSGT, /**< signed greater than */
160 LLVMIntSGE, /**< signed greater or equal */
161 LLVMIntSLT, /**< signed less than */
162 LLVMIntSLE /**< signed less or equal */
Gordon Henriksenc23b66c2007-09-26 20:56:12 +0000163} LLVMIntPredicate;
164
165typedef enum {
Gordon Henriksen4a4d7352007-12-30 17:46:33 +0000166 LLVMRealPredicateFalse, /**< Always false (always folded) */
167 LLVMRealOEQ, /**< True if ordered and equal */
168 LLVMRealOGT, /**< True if ordered and greater than */
169 LLVMRealOGE, /**< True if ordered and greater than or equal */
170 LLVMRealOLT, /**< True if ordered and less than */
171 LLVMRealOLE, /**< True if ordered and less than or equal */
172 LLVMRealONE, /**< True if ordered and operands are unequal */
173 LLVMRealORD, /**< True if ordered (no nans) */
174 LLVMRealUNO, /**< True if unordered: isnan(X) | isnan(Y) */
175 LLVMRealUEQ, /**< True if unordered or equal */
176 LLVMRealUGT, /**< True if unordered or greater than */
177 LLVMRealUGE, /**< True if unordered, greater than, or equal */
178 LLVMRealULT, /**< True if unordered or less than */
179 LLVMRealULE, /**< True if unordered, less than, or equal */
180 LLVMRealUNE, /**< True if unordered or not equal */
181 LLVMRealPredicateTrue /**< Always true (always folded) */
Gordon Henriksenc23b66c2007-09-26 20:56:12 +0000182} LLVMRealPredicate;
183
Gordon Henriksen76a03742007-09-18 03:18:57 +0000184
Gordon Henriksen34eb6d82007-12-19 22:30:40 +0000185/*===-- Error handling ----------------------------------------------------===*/
186
187void LLVMDisposeMessage(char *Message);
188
189
Gordon Henriksen76a03742007-09-18 03:18:57 +0000190/*===-- Modules -----------------------------------------------------------===*/
191
192/* Create and destroy modules. */
Gordon Henriksena49d4352008-03-07 19:13:06 +0000193/** See llvm::Module::Module. */
Gordon Henriksen76a03742007-09-18 03:18:57 +0000194LLVMModuleRef LLVMModuleCreateWithName(const char *ModuleID);
Gordon Henriksena49d4352008-03-07 19:13:06 +0000195
196/** See llvm::Module::~Module. */
Gordon Henriksen76a03742007-09-18 03:18:57 +0000197void LLVMDisposeModule(LLVMModuleRef M);
198
Gordon Henriksena49d4352008-03-07 19:13:06 +0000199/** Data layout. See Module::getDataLayout. */
Gordon Henriksen05568bb2007-12-27 20:13:47 +0000200const char *LLVMGetDataLayout(LLVMModuleRef M);
201void LLVMSetDataLayout(LLVMModuleRef M, const char *Triple);
202
Gordon Henriksena49d4352008-03-07 19:13:06 +0000203/** Target triple. See Module::getTargetTriple. */
Gordon Henriksen05568bb2007-12-27 20:13:47 +0000204const char *LLVMGetTarget(LLVMModuleRef M);
205void LLVMSetTarget(LLVMModuleRef M, const char *Triple);
206
Gordon Henriksena49d4352008-03-07 19:13:06 +0000207/** See Module::addTypeName. */
Gordon Henriksen76a03742007-09-18 03:18:57 +0000208int LLVMAddTypeName(LLVMModuleRef M, const char *Name, LLVMTypeRef Ty);
Gordon Henriksenc23b66c2007-09-26 20:56:12 +0000209void LLVMDeleteTypeName(LLVMModuleRef M, const char *Name);
Gordon Henriksen76a03742007-09-18 03:18:57 +0000210
Gordon Henriksen6c6075e2008-03-14 23:58:56 +0000211/** See Module::dump. */
212void LLVMDumpModule(LLVMModuleRef M);
213
Gordon Henriksen76a03742007-09-18 03:18:57 +0000214
Gordon Henriksenc23b66c2007-09-26 20:56:12 +0000215/*===-- Types -------------------------------------------------------------===*/
Gordon Henriksen76a03742007-09-18 03:18:57 +0000216
217/* LLVM types conform to the following hierarchy:
218 *
219 * types:
220 * integer type
221 * real type
222 * function type
223 * sequence types:
224 * array type
225 * pointer type
226 * vector type
227 * void type
228 * label type
229 * opaque type
230 */
231
Gordon Henriksena49d4352008-03-07 19:13:06 +0000232/** See llvm::LLVMTypeKind::getTypeID. */
Gordon Henriksen76a03742007-09-18 03:18:57 +0000233LLVMTypeKind LLVMGetTypeKind(LLVMTypeRef Ty);
Gordon Henriksena49d4352008-03-07 19:13:06 +0000234
Gordon Henriksen76a03742007-09-18 03:18:57 +0000235/* Operations on integer types */
Gordon Henriksena735a9c2008-05-04 12:55:34 +0000236LLVMTypeRef LLVMInt1Type(void);
237LLVMTypeRef LLVMInt8Type(void);
238LLVMTypeRef LLVMInt16Type(void);
239LLVMTypeRef LLVMInt32Type(void);
240LLVMTypeRef LLVMInt64Type(void);
Gordon Henriksened7beaa2007-10-06 16:05:20 +0000241LLVMTypeRef LLVMIntType(unsigned NumBits);
Gordon Henriksenc23b66c2007-09-26 20:56:12 +0000242unsigned LLVMGetIntTypeWidth(LLVMTypeRef IntegerTy);
Gordon Henriksen76a03742007-09-18 03:18:57 +0000243
244/* Operations on real types */
Gordon Henriksena735a9c2008-05-04 12:55:34 +0000245LLVMTypeRef LLVMFloatType(void);
246LLVMTypeRef LLVMDoubleType(void);
247LLVMTypeRef LLVMX86FP80Type(void);
248LLVMTypeRef LLVMFP128Type(void);
249LLVMTypeRef LLVMPPCFP128Type(void);
Gordon Henriksen76a03742007-09-18 03:18:57 +0000250
251/* Operations on function types */
Gordon Henriksened7beaa2007-10-06 16:05:20 +0000252LLVMTypeRef LLVMFunctionType(LLVMTypeRef ReturnType,
253 LLVMTypeRef *ParamTypes, unsigned ParamCount,
254 int IsVarArg);
Gordon Henriksen76a03742007-09-18 03:18:57 +0000255int LLVMIsFunctionVarArg(LLVMTypeRef FunctionTy);
Gordon Henriksenc23b66c2007-09-26 20:56:12 +0000256LLVMTypeRef LLVMGetReturnType(LLVMTypeRef FunctionTy);
257unsigned LLVMCountParamTypes(LLVMTypeRef FunctionTy);
258void LLVMGetParamTypes(LLVMTypeRef FunctionTy, LLVMTypeRef *Dest);
Gordon Henriksen76a03742007-09-18 03:18:57 +0000259
260/* Operations on struct types */
Gordon Henriksened7beaa2007-10-06 16:05:20 +0000261LLVMTypeRef LLVMStructType(LLVMTypeRef *ElementTypes, unsigned ElementCount,
262 int Packed);
Gordon Henriksenc23b66c2007-09-26 20:56:12 +0000263unsigned LLVMCountStructElementTypes(LLVMTypeRef StructTy);
Gordon Henriksen76a03742007-09-18 03:18:57 +0000264void LLVMGetStructElementTypes(LLVMTypeRef StructTy, LLVMTypeRef *Dest);
265int LLVMIsPackedStruct(LLVMTypeRef StructTy);
266
267/* Operations on array, pointer, and vector types (sequence types) */
Gordon Henriksened7beaa2007-10-06 16:05:20 +0000268LLVMTypeRef LLVMArrayType(LLVMTypeRef ElementType, unsigned ElementCount);
Gordon Henriksen5a3fe032007-12-17 16:08:32 +0000269LLVMTypeRef LLVMPointerType(LLVMTypeRef ElementType, unsigned AddressSpace);
Gordon Henriksened7beaa2007-10-06 16:05:20 +0000270LLVMTypeRef LLVMVectorType(LLVMTypeRef ElementType, unsigned ElementCount);
Gordon Henriksen76a03742007-09-18 03:18:57 +0000271
272LLVMTypeRef LLVMGetElementType(LLVMTypeRef Ty);
273unsigned LLVMGetArrayLength(LLVMTypeRef ArrayTy);
Gordon Henriksen5a3fe032007-12-17 16:08:32 +0000274unsigned LLVMGetPointerAddressSpace(LLVMTypeRef PointerTy);
Gordon Henriksen76a03742007-09-18 03:18:57 +0000275unsigned LLVMGetVectorSize(LLVMTypeRef VectorTy);
276
277/* Operations on other types */
Gordon Henriksena735a9c2008-05-04 12:55:34 +0000278LLVMTypeRef LLVMVoidType(void);
279LLVMTypeRef LLVMLabelType(void);
280LLVMTypeRef LLVMOpaqueType(void);
Gordon Henriksen76a03742007-09-18 03:18:57 +0000281
Gordon Henriksenffb48762007-10-07 00:13:35 +0000282/* Operations on type handles */
283LLVMTypeHandleRef LLVMCreateTypeHandle(LLVMTypeRef PotentiallyAbstractTy);
284void LLVMRefineType(LLVMTypeRef AbstractTy, LLVMTypeRef ConcreteTy);
285LLVMTypeRef LLVMResolveTypeHandle(LLVMTypeHandleRef TypeHandle);
286void LLVMDisposeTypeHandle(LLVMTypeHandleRef TypeHandle);
287
Gordon Henriksen76a03742007-09-18 03:18:57 +0000288
289/*===-- Values ------------------------------------------------------------===*/
290
291/* The bulk of LLVM's object model consists of values, which comprise a very
292 * rich type hierarchy.
Gordon Henriksen76a03742007-09-18 03:18:57 +0000293 */
294
Gordon Henriksen29e38942008-12-19 18:39:45 +0000295#define LLVM_FOR_EACH_VALUE_SUBCLASS(macro) \
296 macro(Argument) \
297 macro(BasicBlock) \
298 macro(InlineAsm) \
299 macro(User) \
300 macro(Constant) \
301 macro(ConstantAggregateZero) \
302 macro(ConstantArray) \
303 macro(ConstantExpr) \
304 macro(ConstantFP) \
305 macro(ConstantInt) \
306 macro(ConstantPointerNull) \
307 macro(ConstantStruct) \
308 macro(ConstantVector) \
309 macro(GlobalValue) \
310 macro(Function) \
311 macro(GlobalAlias) \
312 macro(GlobalVariable) \
313 macro(UndefValue) \
314 macro(Instruction) \
315 macro(BinaryOperator) \
316 macro(CallInst) \
317 macro(IntrinsicInst) \
318 macro(DbgInfoIntrinsic) \
319 macro(DbgDeclareInst) \
320 macro(DbgFuncStartInst) \
321 macro(DbgRegionEndInst) \
322 macro(DbgRegionStartInst) \
323 macro(DbgStopPointInst) \
324 macro(EHSelectorInst) \
325 macro(MemIntrinsic) \
326 macro(MemCpyInst) \
327 macro(MemMoveInst) \
328 macro(MemSetInst) \
329 macro(CmpInst) \
330 macro(FCmpInst) \
331 macro(ICmpInst) \
332 macro(VFCmpInst) \
333 macro(VICmpInst) \
334 macro(ExtractElementInst) \
335 macro(GetElementPtrInst) \
336 macro(InsertElementInst) \
337 macro(InsertValueInst) \
338 macro(PHINode) \
339 macro(SelectInst) \
340 macro(ShuffleVectorInst) \
341 macro(StoreInst) \
342 macro(TerminatorInst) \
343 macro(BranchInst) \
344 macro(InvokeInst) \
345 macro(ReturnInst) \
346 macro(SwitchInst) \
347 macro(UnreachableInst) \
348 macro(UnwindInst) \
349 macro(UnaryInstruction) \
350 macro(AllocationInst) \
Gordon Henriksen05a868f2008-12-19 18:51:17 +0000351 macro(AllocaInst) \
352 macro(MallocInst) \
Gordon Henriksen29e38942008-12-19 18:39:45 +0000353 macro(CastInst) \
Gordon Henriksen05a868f2008-12-19 18:51:17 +0000354 macro(BitCastInst) \
355 macro(FPExtInst) \
356 macro(FPToSIInst) \
357 macro(FPToUIInst) \
358 macro(FPTruncInst) \
359 macro(IntToPtrInst) \
360 macro(PtrToIntInst) \
361 macro(SExtInst) \
362 macro(SIToFPInst) \
363 macro(TruncInst) \
364 macro(UIToFPInst) \
365 macro(ZExtInst) \
366 macro(ExtractValueInst) \
367 macro(FreeInst) \
368 macro(LoadInst) \
369 macro(VAArgInst)
Gordon Henriksen29e38942008-12-19 18:39:45 +0000370
Gordon Henriksen76a03742007-09-18 03:18:57 +0000371/* Operations on all values */
Gordon Henriksenc23b66c2007-09-26 20:56:12 +0000372LLVMTypeRef LLVMTypeOf(LLVMValueRef Val);
Gordon Henriksen76a03742007-09-18 03:18:57 +0000373const char *LLVMGetValueName(LLVMValueRef Val);
374void LLVMSetValueName(LLVMValueRef Val, const char *Name);
Gordon Henriksen1d0d24c2007-10-06 00:08:49 +0000375void LLVMDumpValue(LLVMValueRef Val);
Gordon Henriksen76a03742007-09-18 03:18:57 +0000376
Gordon Henriksen29e38942008-12-19 18:39:45 +0000377/* Conversion functions. Return the input value if it is an instance of the
378 specified class, otherwise NULL. See llvm::dyn_cast_or_null<>. */
379#define LLVM_DECLARE_VALUE_CAST(name) \
380 LLVMValueRef LLVMIsA##name(LLVMValueRef Val);
381LLVM_FOR_EACH_VALUE_SUBCLASS(LLVM_DECLARE_VALUE_CAST)
382
Gordon Henriksen76a03742007-09-18 03:18:57 +0000383/* Operations on constants of any type */
Gordon Henriksen1046c732007-10-06 15:11:06 +0000384LLVMValueRef LLVMConstNull(LLVMTypeRef Ty); /* all zeroes */
385LLVMValueRef LLVMConstAllOnes(LLVMTypeRef Ty); /* only for int/vector */
Gordon Henriksen76a03742007-09-18 03:18:57 +0000386LLVMValueRef LLVMGetUndef(LLVMTypeRef Ty);
Gordon Henriksendc88c062007-09-18 18:07:51 +0000387int LLVMIsConstant(LLVMValueRef Val);
Gordon Henriksen76a03742007-09-18 03:18:57 +0000388int LLVMIsNull(LLVMValueRef Val);
Gordon Henriksendc88c062007-09-18 18:07:51 +0000389int LLVMIsUndef(LLVMValueRef Val);
Gordon Henriksen76a03742007-09-18 03:18:57 +0000390
391/* Operations on scalar constants */
Gordon Henriksen1046c732007-10-06 15:11:06 +0000392LLVMValueRef LLVMConstInt(LLVMTypeRef IntTy, unsigned long long N,
393 int SignExtend);
394LLVMValueRef LLVMConstReal(LLVMTypeRef RealTy, double N);
Gordon Henriksen931e1212008-02-02 01:07:50 +0000395LLVMValueRef LLVMConstRealOfString(LLVMTypeRef RealTy, const char *Text);
Gordon Henriksen76a03742007-09-18 03:18:57 +0000396
397/* Operations on composite constants */
Gordon Henriksen1046c732007-10-06 15:11:06 +0000398LLVMValueRef LLVMConstString(const char *Str, unsigned Length,
399 int DontNullTerminate);
Gordon Henriksen2ad5aef2008-04-25 03:21:19 +0000400LLVMValueRef LLVMConstArray(LLVMTypeRef ElementTy,
Gordon Henriksen1046c732007-10-06 15:11:06 +0000401 LLVMValueRef *ConstantVals, unsigned Length);
402LLVMValueRef LLVMConstStruct(LLVMValueRef *ConstantVals, unsigned Count,
403 int packed);
404LLVMValueRef LLVMConstVector(LLVMValueRef *ScalarConstantVals, unsigned Size);
Gordon Henriksen76a03742007-09-18 03:18:57 +0000405
Gordon Henriksen7ce31762007-10-06 14:29:36 +0000406/* Constant expressions */
407LLVMValueRef LLVMSizeOf(LLVMTypeRef Ty);
408LLVMValueRef LLVMConstNeg(LLVMValueRef ConstantVal);
409LLVMValueRef LLVMConstNot(LLVMValueRef ConstantVal);
410LLVMValueRef LLVMConstAdd(LLVMValueRef LHSConstant, LLVMValueRef RHSConstant);
411LLVMValueRef LLVMConstSub(LLVMValueRef LHSConstant, LLVMValueRef RHSConstant);
412LLVMValueRef LLVMConstMul(LLVMValueRef LHSConstant, LLVMValueRef RHSConstant);
413LLVMValueRef LLVMConstUDiv(LLVMValueRef LHSConstant, LLVMValueRef RHSConstant);
414LLVMValueRef LLVMConstSDiv(LLVMValueRef LHSConstant, LLVMValueRef RHSConstant);
415LLVMValueRef LLVMConstFDiv(LLVMValueRef LHSConstant, LLVMValueRef RHSConstant);
416LLVMValueRef LLVMConstURem(LLVMValueRef LHSConstant, LLVMValueRef RHSConstant);
417LLVMValueRef LLVMConstSRem(LLVMValueRef LHSConstant, LLVMValueRef RHSConstant);
418LLVMValueRef LLVMConstFRem(LLVMValueRef LHSConstant, LLVMValueRef RHSConstant);
419LLVMValueRef LLVMConstAnd(LLVMValueRef LHSConstant, LLVMValueRef RHSConstant);
420LLVMValueRef LLVMConstOr(LLVMValueRef LHSConstant, LLVMValueRef RHSConstant);
421LLVMValueRef LLVMConstXor(LLVMValueRef LHSConstant, LLVMValueRef RHSConstant);
422LLVMValueRef LLVMConstICmp(LLVMIntPredicate Predicate,
423 LLVMValueRef LHSConstant, LLVMValueRef RHSConstant);
424LLVMValueRef LLVMConstFCmp(LLVMRealPredicate Predicate,
425 LLVMValueRef LHSConstant, LLVMValueRef RHSConstant);
426LLVMValueRef LLVMConstShl(LLVMValueRef LHSConstant, LLVMValueRef RHSConstant);
427LLVMValueRef LLVMConstLShr(LLVMValueRef LHSConstant, LLVMValueRef RHSConstant);
428LLVMValueRef LLVMConstAShr(LLVMValueRef LHSConstant, LLVMValueRef RHSConstant);
429LLVMValueRef LLVMConstGEP(LLVMValueRef ConstantVal,
430 LLVMValueRef *ConstantIndices, unsigned NumIndices);
431LLVMValueRef LLVMConstTrunc(LLVMValueRef ConstantVal, LLVMTypeRef ToType);
432LLVMValueRef LLVMConstSExt(LLVMValueRef ConstantVal, LLVMTypeRef ToType);
433LLVMValueRef LLVMConstZExt(LLVMValueRef ConstantVal, LLVMTypeRef ToType);
434LLVMValueRef LLVMConstFPTrunc(LLVMValueRef ConstantVal, LLVMTypeRef ToType);
435LLVMValueRef LLVMConstFPExt(LLVMValueRef ConstantVal, LLVMTypeRef ToType);
436LLVMValueRef LLVMConstUIToFP(LLVMValueRef ConstantVal, LLVMTypeRef ToType);
437LLVMValueRef LLVMConstSIToFP(LLVMValueRef ConstantVal, LLVMTypeRef ToType);
438LLVMValueRef LLVMConstFPToUI(LLVMValueRef ConstantVal, LLVMTypeRef ToType);
439LLVMValueRef LLVMConstFPToSI(LLVMValueRef ConstantVal, LLVMTypeRef ToType);
440LLVMValueRef LLVMConstPtrToInt(LLVMValueRef ConstantVal, LLVMTypeRef ToType);
441LLVMValueRef LLVMConstIntToPtr(LLVMValueRef ConstantVal, LLVMTypeRef ToType);
442LLVMValueRef LLVMConstBitCast(LLVMValueRef ConstantVal, LLVMTypeRef ToType);
443LLVMValueRef LLVMConstSelect(LLVMValueRef ConstantCondition,
444 LLVMValueRef ConstantIfTrue,
445 LLVMValueRef ConstantIfFalse);
446LLVMValueRef LLVMConstExtractElement(LLVMValueRef VectorConstant,
447 LLVMValueRef IndexConstant);
448LLVMValueRef LLVMConstInsertElement(LLVMValueRef VectorConstant,
449 LLVMValueRef ElementValueConstant,
450 LLVMValueRef IndexConstant);
451LLVMValueRef LLVMConstShuffleVector(LLVMValueRef VectorAConstant,
452 LLVMValueRef VectorBConstant,
453 LLVMValueRef MaskConstant);
Dan Gohmand5104a52008-11-03 22:55:43 +0000454LLVMValueRef LLVMConstExtractValue(LLVMValueRef AggConstant, unsigned *IdxList,
455 unsigned NumIdx);
456LLVMValueRef LLVMConstInsertValue(LLVMValueRef AggConstant,
457 LLVMValueRef ElementValueConstant,
458 unsigned *IdxList, unsigned NumIdx);
Chris Lattner3d1f5522008-12-17 21:39:50 +0000459LLVMValueRef LLVMConstInlineAsm(LLVMTypeRef Ty,
460 const char *AsmString, const char *Constraints,
461 int HasSideEffects);
Gordon Henriksen7ce31762007-10-06 14:29:36 +0000462
Gordon Henriksen76a03742007-09-18 03:18:57 +0000463/* Operations on global variables, functions, and aliases (globals) */
Gordon Henriksen265f7802008-03-19 01:11:35 +0000464LLVMModuleRef LLVMGetGlobalParent(LLVMValueRef Global);
Gordon Henriksen76a03742007-09-18 03:18:57 +0000465int LLVMIsDeclaration(LLVMValueRef Global);
466LLVMLinkage LLVMGetLinkage(LLVMValueRef Global);
467void LLVMSetLinkage(LLVMValueRef Global, LLVMLinkage Linkage);
468const char *LLVMGetSection(LLVMValueRef Global);
469void LLVMSetSection(LLVMValueRef Global, const char *Section);
470LLVMVisibility LLVMGetVisibility(LLVMValueRef Global);
471void LLVMSetVisibility(LLVMValueRef Global, LLVMVisibility Viz);
472unsigned LLVMGetAlignment(LLVMValueRef Global);
473void LLVMSetAlignment(LLVMValueRef Global, unsigned Bytes);
474
475/* Operations on global variables */
476LLVMValueRef LLVMAddGlobal(LLVMModuleRef M, LLVMTypeRef Ty, const char *Name);
Gordon Henriksen783f7bb2007-10-08 03:45:09 +0000477LLVMValueRef LLVMGetNamedGlobal(LLVMModuleRef M, const char *Name);
Gordon Henriksen07a45f42008-03-23 22:21:29 +0000478LLVMValueRef LLVMGetFirstGlobal(LLVMModuleRef M);
479LLVMValueRef LLVMGetLastGlobal(LLVMModuleRef M);
480LLVMValueRef LLVMGetNextGlobal(LLVMValueRef GlobalVar);
481LLVMValueRef LLVMGetPreviousGlobal(LLVMValueRef GlobalVar);
Gordon Henriksen76a03742007-09-18 03:18:57 +0000482void LLVMDeleteGlobal(LLVMValueRef GlobalVar);
Gordon Henriksen76a03742007-09-18 03:18:57 +0000483LLVMValueRef LLVMGetInitializer(LLVMValueRef GlobalVar);
484void LLVMSetInitializer(LLVMValueRef GlobalVar, LLVMValueRef ConstantVal);
485int LLVMIsThreadLocal(LLVMValueRef GlobalVar);
486void LLVMSetThreadLocal(LLVMValueRef GlobalVar, int IsThreadLocal);
Gordon Henriksen751ebf72007-10-07 17:31:42 +0000487int LLVMIsGlobalConstant(LLVMValueRef GlobalVar);
488void LLVMSetGlobalConstant(LLVMValueRef GlobalVar, int IsConstant);
Gordon Henriksen76a03742007-09-18 03:18:57 +0000489
Chris Lattner3d1f5522008-12-17 21:39:50 +0000490/* Operations on aliases */
491LLVMValueRef LLVMAddAlias(LLVMModuleRef M, LLVMTypeRef Ty, LLVMValueRef Aliasee,
492 const char *Name);
493
Gordon Henriksenc23b66c2007-09-26 20:56:12 +0000494/* Operations on functions */
495LLVMValueRef LLVMAddFunction(LLVMModuleRef M, const char *Name,
496 LLVMTypeRef FunctionTy);
Gordon Henriksen783f7bb2007-10-08 03:45:09 +0000497LLVMValueRef LLVMGetNamedFunction(LLVMModuleRef M, const char *Name);
Gordon Henriksen054817c2008-03-19 03:47:18 +0000498LLVMValueRef LLVMGetFirstFunction(LLVMModuleRef M);
499LLVMValueRef LLVMGetLastFunction(LLVMModuleRef M);
500LLVMValueRef LLVMGetNextFunction(LLVMValueRef Fn);
501LLVMValueRef LLVMGetPreviousFunction(LLVMValueRef Fn);
Gordon Henriksenc23b66c2007-09-26 20:56:12 +0000502void LLVMDeleteFunction(LLVMValueRef Fn);
Gordon Henriksenc23b66c2007-09-26 20:56:12 +0000503unsigned LLVMGetIntrinsicID(LLVMValueRef Fn);
504unsigned LLVMGetFunctionCallConv(LLVMValueRef Fn);
505void LLVMSetFunctionCallConv(LLVMValueRef Fn, unsigned CC);
Gordon Henriksend930f912008-08-17 18:44:35 +0000506const char *LLVMGetGC(LLVMValueRef Fn);
507void LLVMSetGC(LLVMValueRef Fn, const char *Name);
Gordon Henriksenc23b66c2007-09-26 20:56:12 +0000508
Gordon Henriksen265f7802008-03-19 01:11:35 +0000509/* Operations on parameters */
510unsigned LLVMCountParams(LLVMValueRef Fn);
511void LLVMGetParams(LLVMValueRef Fn, LLVMValueRef *Params);
512LLVMValueRef LLVMGetParam(LLVMValueRef Fn, unsigned Index);
513LLVMValueRef LLVMGetParamParent(LLVMValueRef Inst);
Gordon Henriksen07a45f42008-03-23 22:21:29 +0000514LLVMValueRef LLVMGetFirstParam(LLVMValueRef Fn);
515LLVMValueRef LLVMGetLastParam(LLVMValueRef Fn);
516LLVMValueRef LLVMGetNextParam(LLVMValueRef Arg);
517LLVMValueRef LLVMGetPreviousParam(LLVMValueRef Arg);
Devang Patel4c758ea2008-09-25 21:00:45 +0000518void LLVMAddAttribute(LLVMValueRef Arg, LLVMAttribute PA);
519void LLVMRemoveAttribute(LLVMValueRef Arg, LLVMAttribute PA);
Gordon Henriksen2d9cc212008-04-28 17:37:06 +0000520void LLVMSetParamAlignment(LLVMValueRef Arg, unsigned align);
Gordon Henriksen265f7802008-03-19 01:11:35 +0000521
Gordon Henriksenc23b66c2007-09-26 20:56:12 +0000522/* Operations on basic blocks */
Gordon Henriksen07a45f42008-03-23 22:21:29 +0000523LLVMValueRef LLVMBasicBlockAsValue(LLVMBasicBlockRef BB);
Gordon Henriksenc23b66c2007-09-26 20:56:12 +0000524int LLVMValueIsBasicBlock(LLVMValueRef Val);
525LLVMBasicBlockRef LLVMValueAsBasicBlock(LLVMValueRef Val);
Gordon Henriksen07a45f42008-03-23 22:21:29 +0000526LLVMValueRef LLVMGetBasicBlockParent(LLVMBasicBlockRef BB);
Gordon Henriksenc23b66c2007-09-26 20:56:12 +0000527unsigned LLVMCountBasicBlocks(LLVMValueRef Fn);
528void LLVMGetBasicBlocks(LLVMValueRef Fn, LLVMBasicBlockRef *BasicBlocks);
Gordon Henriksen054817c2008-03-19 03:47:18 +0000529LLVMBasicBlockRef LLVMGetFirstBasicBlock(LLVMValueRef Fn);
530LLVMBasicBlockRef LLVMGetLastBasicBlock(LLVMValueRef Fn);
531LLVMBasicBlockRef LLVMGetNextBasicBlock(LLVMBasicBlockRef BB);
532LLVMBasicBlockRef LLVMGetPreviousBasicBlock(LLVMBasicBlockRef BB);
Gordon Henriksenc23b66c2007-09-26 20:56:12 +0000533LLVMBasicBlockRef LLVMGetEntryBasicBlock(LLVMValueRef Fn);
534LLVMBasicBlockRef LLVMAppendBasicBlock(LLVMValueRef Fn, const char *Name);
535LLVMBasicBlockRef LLVMInsertBasicBlock(LLVMBasicBlockRef InsertBeforeBB,
536 const char *Name);
537void LLVMDeleteBasicBlock(LLVMBasicBlockRef BB);
538
Gordon Henriksen265f7802008-03-19 01:11:35 +0000539/* Operations on instructions */
540LLVMBasicBlockRef LLVMGetInstructionParent(LLVMValueRef Inst);
Gordon Henriksen054817c2008-03-19 03:47:18 +0000541LLVMValueRef LLVMGetFirstInstruction(LLVMBasicBlockRef BB);
542LLVMValueRef LLVMGetLastInstruction(LLVMBasicBlockRef BB);
543LLVMValueRef LLVMGetNextInstruction(LLVMValueRef Inst);
544LLVMValueRef LLVMGetPreviousInstruction(LLVMValueRef Inst);
Gordon Henriksen265f7802008-03-19 01:11:35 +0000545
Gordon Henriksen1158c532007-12-29 20:45:00 +0000546/* Operations on call sites */
547void LLVMSetInstructionCallConv(LLVMValueRef Instr, unsigned CC);
548unsigned LLVMGetInstructionCallConv(LLVMValueRef Instr);
Devang Patel4c758ea2008-09-25 21:00:45 +0000549void LLVMAddInstrAttribute(LLVMValueRef Instr, unsigned index, LLVMAttribute);
550void LLVMRemoveInstrAttribute(LLVMValueRef Instr, unsigned index,
551 LLVMAttribute);
Gordon Henriksen2d9cc212008-04-28 17:37:06 +0000552void LLVMSetInstrParamAlignment(LLVMValueRef Instr, unsigned index,
553 unsigned align);
Gordon Henriksen1158c532007-12-29 20:45:00 +0000554
Gordon Henrikseneeb65372008-08-30 16:34:54 +0000555/* Operations on call instructions (only) */
556int LLVMIsTailCall(LLVMValueRef CallInst);
557void LLVMSetTailCall(LLVMValueRef CallInst, int IsTailCall);
558
Gordon Henriksen44dd8fb2007-10-08 18:14:39 +0000559/* Operations on phi nodes */
560void LLVMAddIncoming(LLVMValueRef PhiNode, LLVMValueRef *IncomingValues,
561 LLVMBasicBlockRef *IncomingBlocks, unsigned Count);
562unsigned LLVMCountIncoming(LLVMValueRef PhiNode);
563LLVMValueRef LLVMGetIncomingValue(LLVMValueRef PhiNode, unsigned Index);
564LLVMBasicBlockRef LLVMGetIncomingBlock(LLVMValueRef PhiNode, unsigned Index);
Gordon Henriksenc23b66c2007-09-26 20:56:12 +0000565
566/*===-- Instruction builders ----------------------------------------------===*/
567
568/* An instruction builder represents a point within a basic block, and is the
569 * exclusive means of building instructions using the C interface.
570 */
571
Gordon Henriksena735a9c2008-05-04 12:55:34 +0000572LLVMBuilderRef LLVMCreateBuilder(void);
Gordon Henriksen054817c2008-03-19 03:47:18 +0000573void LLVMPositionBuilder(LLVMBuilderRef Builder, LLVMBasicBlockRef Block,
574 LLVMValueRef Instr);
Gordon Henriksenc23b66c2007-09-26 20:56:12 +0000575void LLVMPositionBuilderBefore(LLVMBuilderRef Builder, LLVMValueRef Instr);
576void LLVMPositionBuilderAtEnd(LLVMBuilderRef Builder, LLVMBasicBlockRef Block);
Gordon Henriksen265f7802008-03-19 01:11:35 +0000577LLVMBasicBlockRef LLVMGetInsertBlock(LLVMBuilderRef Builder);
Chris Lattner3d1f5522008-12-17 21:39:50 +0000578void LLVMClearInsertionPosition(LLVMBuilderRef Builder);
579void LLVMInsertIntoBuilder(LLVMBuilderRef Builder, LLVMValueRef Instr);
Gordon Henriksenc23b66c2007-09-26 20:56:12 +0000580void LLVMDisposeBuilder(LLVMBuilderRef Builder);
581
582/* Terminators */
583LLVMValueRef LLVMBuildRetVoid(LLVMBuilderRef);
584LLVMValueRef LLVMBuildRet(LLVMBuilderRef, LLVMValueRef V);
585LLVMValueRef LLVMBuildBr(LLVMBuilderRef, LLVMBasicBlockRef Dest);
586LLVMValueRef LLVMBuildCondBr(LLVMBuilderRef, LLVMValueRef If,
587 LLVMBasicBlockRef Then, LLVMBasicBlockRef Else);
588LLVMValueRef LLVMBuildSwitch(LLVMBuilderRef, LLVMValueRef V,
589 LLVMBasicBlockRef Else, unsigned NumCases);
590LLVMValueRef LLVMBuildInvoke(LLVMBuilderRef, LLVMValueRef Fn,
591 LLVMValueRef *Args, unsigned NumArgs,
592 LLVMBasicBlockRef Then, LLVMBasicBlockRef Catch,
593 const char *Name);
594LLVMValueRef LLVMBuildUnwind(LLVMBuilderRef);
595LLVMValueRef LLVMBuildUnreachable(LLVMBuilderRef);
596
Gordon Henriksen097102c2008-01-01 05:50:53 +0000597/* Add a case to the switch instruction */
598void LLVMAddCase(LLVMValueRef Switch, LLVMValueRef OnVal,
599 LLVMBasicBlockRef Dest);
600
Gordon Henriksenc23b66c2007-09-26 20:56:12 +0000601/* Arithmetic */
602LLVMValueRef LLVMBuildAdd(LLVMBuilderRef, LLVMValueRef LHS, LLVMValueRef RHS,
603 const char *Name);
604LLVMValueRef LLVMBuildSub(LLVMBuilderRef, LLVMValueRef LHS, LLVMValueRef RHS,
605 const char *Name);
606LLVMValueRef LLVMBuildMul(LLVMBuilderRef, LLVMValueRef LHS, LLVMValueRef RHS,
607 const char *Name);
608LLVMValueRef LLVMBuildUDiv(LLVMBuilderRef, LLVMValueRef LHS, LLVMValueRef RHS,
609 const char *Name);
610LLVMValueRef LLVMBuildSDiv(LLVMBuilderRef, LLVMValueRef LHS, LLVMValueRef RHS,
611 const char *Name);
612LLVMValueRef LLVMBuildFDiv(LLVMBuilderRef, LLVMValueRef LHS, LLVMValueRef RHS,
613 const char *Name);
614LLVMValueRef LLVMBuildURem(LLVMBuilderRef, LLVMValueRef LHS, LLVMValueRef RHS,
615 const char *Name);
616LLVMValueRef LLVMBuildSRem(LLVMBuilderRef, LLVMValueRef LHS, LLVMValueRef RHS,
617 const char *Name);
618LLVMValueRef LLVMBuildFRem(LLVMBuilderRef, LLVMValueRef LHS, LLVMValueRef RHS,
619 const char *Name);
620LLVMValueRef LLVMBuildShl(LLVMBuilderRef, LLVMValueRef LHS, LLVMValueRef RHS,
621 const char *Name);
622LLVMValueRef LLVMBuildLShr(LLVMBuilderRef, LLVMValueRef LHS, LLVMValueRef RHS,
623 const char *Name);
624LLVMValueRef LLVMBuildAShr(LLVMBuilderRef, LLVMValueRef LHS, LLVMValueRef RHS,
625 const char *Name);
626LLVMValueRef LLVMBuildAnd(LLVMBuilderRef, LLVMValueRef LHS, LLVMValueRef RHS,
627 const char *Name);
628LLVMValueRef LLVMBuildOr(LLVMBuilderRef, LLVMValueRef LHS, LLVMValueRef RHS,
629 const char *Name);
630LLVMValueRef LLVMBuildXor(LLVMBuilderRef, LLVMValueRef LHS, LLVMValueRef RHS,
631 const char *Name);
632LLVMValueRef LLVMBuildNeg(LLVMBuilderRef, LLVMValueRef V, const char *Name);
633LLVMValueRef LLVMBuildNot(LLVMBuilderRef, LLVMValueRef V, const char *Name);
634
635/* Memory */
636LLVMValueRef LLVMBuildMalloc(LLVMBuilderRef, LLVMTypeRef Ty, const char *Name);
637LLVMValueRef LLVMBuildArrayMalloc(LLVMBuilderRef, LLVMTypeRef Ty,
638 LLVMValueRef Val, const char *Name);
639LLVMValueRef LLVMBuildAlloca(LLVMBuilderRef, LLVMTypeRef Ty, const char *Name);
640LLVMValueRef LLVMBuildArrayAlloca(LLVMBuilderRef, LLVMTypeRef Ty,
641 LLVMValueRef Val, const char *Name);
642LLVMValueRef LLVMBuildFree(LLVMBuilderRef, LLVMValueRef PointerVal);
643LLVMValueRef LLVMBuildLoad(LLVMBuilderRef, LLVMValueRef PointerVal,
644 const char *Name);
645LLVMValueRef LLVMBuildStore(LLVMBuilderRef, LLVMValueRef Val, LLVMValueRef Ptr);
646LLVMValueRef LLVMBuildGEP(LLVMBuilderRef B, LLVMValueRef Pointer,
647 LLVMValueRef *Indices, unsigned NumIndices,
648 const char *Name);
649
650/* Casts */
651LLVMValueRef LLVMBuildTrunc(LLVMBuilderRef, LLVMValueRef Val,
652 LLVMTypeRef DestTy, const char *Name);
653LLVMValueRef LLVMBuildZExt(LLVMBuilderRef, LLVMValueRef Val,
654 LLVMTypeRef DestTy, const char *Name);
655LLVMValueRef LLVMBuildSExt(LLVMBuilderRef, LLVMValueRef Val,
656 LLVMTypeRef DestTy, const char *Name);
657LLVMValueRef LLVMBuildFPToUI(LLVMBuilderRef, LLVMValueRef Val,
658 LLVMTypeRef DestTy, const char *Name);
659LLVMValueRef LLVMBuildFPToSI(LLVMBuilderRef, LLVMValueRef Val,
660 LLVMTypeRef DestTy, const char *Name);
661LLVMValueRef LLVMBuildUIToFP(LLVMBuilderRef, LLVMValueRef Val,
662 LLVMTypeRef DestTy, const char *Name);
663LLVMValueRef LLVMBuildSIToFP(LLVMBuilderRef, LLVMValueRef Val,
664 LLVMTypeRef DestTy, const char *Name);
665LLVMValueRef LLVMBuildFPTrunc(LLVMBuilderRef, LLVMValueRef Val,
666 LLVMTypeRef DestTy, const char *Name);
667LLVMValueRef LLVMBuildFPExt(LLVMBuilderRef, LLVMValueRef Val,
668 LLVMTypeRef DestTy, const char *Name);
669LLVMValueRef LLVMBuildPtrToInt(LLVMBuilderRef, LLVMValueRef Val,
670 LLVMTypeRef DestTy, const char *Name);
671LLVMValueRef LLVMBuildIntToPtr(LLVMBuilderRef, LLVMValueRef Val,
672 LLVMTypeRef DestTy, const char *Name);
673LLVMValueRef LLVMBuildBitCast(LLVMBuilderRef, LLVMValueRef Val,
674 LLVMTypeRef DestTy, const char *Name);
675
676/* Comparisons */
677LLVMValueRef LLVMBuildICmp(LLVMBuilderRef, LLVMIntPredicate Op,
678 LLVMValueRef LHS, LLVMValueRef RHS,
679 const char *Name);
680LLVMValueRef LLVMBuildFCmp(LLVMBuilderRef, LLVMRealPredicate Op,
681 LLVMValueRef LHS, LLVMValueRef RHS,
682 const char *Name);
683
684/* Miscellaneous instructions */
685LLVMValueRef LLVMBuildPhi(LLVMBuilderRef, LLVMTypeRef Ty, const char *Name);
686LLVMValueRef LLVMBuildCall(LLVMBuilderRef, LLVMValueRef Fn,
687 LLVMValueRef *Args, unsigned NumArgs,
688 const char *Name);
689LLVMValueRef LLVMBuildSelect(LLVMBuilderRef, LLVMValueRef If,
690 LLVMValueRef Then, LLVMValueRef Else,
691 const char *Name);
692LLVMValueRef LLVMBuildVAArg(LLVMBuilderRef, LLVMValueRef List, LLVMTypeRef Ty,
693 const char *Name);
694LLVMValueRef LLVMBuildExtractElement(LLVMBuilderRef, LLVMValueRef VecVal,
695 LLVMValueRef Index, const char *Name);
696LLVMValueRef LLVMBuildInsertElement(LLVMBuilderRef, LLVMValueRef VecVal,
697 LLVMValueRef EltVal, LLVMValueRef Index,
698 const char *Name);
699LLVMValueRef LLVMBuildShuffleVector(LLVMBuilderRef, LLVMValueRef V1,
700 LLVMValueRef V2, LLVMValueRef Mask,
701 const char *Name);
Dan Gohmand5104a52008-11-03 22:55:43 +0000702LLVMValueRef LLVMBuildExtractValue(LLVMBuilderRef, LLVMValueRef AggVal,
703 unsigned Index, const char *Name);
704LLVMValueRef LLVMBuildInsertValue(LLVMBuilderRef, LLVMValueRef AggVal,
705 LLVMValueRef EltVal, unsigned Index,
706 const char *Name);
Gordon Henriksen76a03742007-09-18 03:18:57 +0000707
Gordon Henriksen34eb6d82007-12-19 22:30:40 +0000708
Gordon Henriksen0a68fe22007-12-12 01:04:30 +0000709/*===-- Module providers --------------------------------------------------===*/
710
711/* Encapsulates the module M in a module provider, taking ownership of the
712 * module.
713 * See the constructor llvm::ExistingModuleProvider::ExistingModuleProvider.
714 */
715LLVMModuleProviderRef
716LLVMCreateModuleProviderForExistingModule(LLVMModuleRef M);
717
718/* Destroys the module provider MP as well as the contained module.
719 * See the destructor llvm::ModuleProvider::~ModuleProvider.
720 */
721void LLVMDisposeModuleProvider(LLVMModuleProviderRef MP);
722
Gordon Henriksen34eb6d82007-12-19 22:30:40 +0000723
724/*===-- Memory buffers ----------------------------------------------------===*/
725
726int LLVMCreateMemoryBufferWithContentsOfFile(const char *Path,
727 LLVMMemoryBufferRef *OutMemBuf,
728 char **OutMessage);
729int LLVMCreateMemoryBufferWithSTDIN(LLVMMemoryBufferRef *OutMemBuf,
730 char **OutMessage);
731void LLVMDisposeMemoryBuffer(LLVMMemoryBufferRef MemBuf);
732
Gordon Henriksen878114b2008-03-16 04:20:44 +0000733
734/*===-- Pass Managers -----------------------------------------------------===*/
735
736/** Constructs a new whole-module pass pipeline. This type of pipeline is
737 suitable for link-time optimization and whole-module transformations.
738 See llvm::PassManager::PassManager. */
Gordon Henriksena735a9c2008-05-04 12:55:34 +0000739LLVMPassManagerRef LLVMCreatePassManager(void);
Gordon Henriksen878114b2008-03-16 04:20:44 +0000740
741/** Constructs a new function-by-function pass pipeline over the module
742 provider. It does not take ownership of the module provider. This type of
743 pipeline is suitable for code generation and JIT compilation tasks.
744 See llvm::FunctionPassManager::FunctionPassManager. */
745LLVMPassManagerRef LLVMCreateFunctionPassManager(LLVMModuleProviderRef MP);
746
747/** Initializes, executes on the provided module, and finalizes all of the
748 passes scheduled in the pass manager. Returns 1 if any of the passes
749 modified the module, 0 otherwise. See llvm::PassManager::run(Module&). */
750int LLVMRunPassManager(LLVMPassManagerRef PM, LLVMModuleRef M);
751
752/** Initializes all of the function passes scheduled in the function pass
753 manager. Returns 1 if any of the passes modified the module, 0 otherwise.
754 See llvm::FunctionPassManager::doInitialization. */
755int LLVMInitializeFunctionPassManager(LLVMPassManagerRef FPM);
756
757/** Executes all of the function passes scheduled in the function pass manager
758 on the provided function. Returns 1 if any of the passes modified the
759 function, false otherwise.
760 See llvm::FunctionPassManager::run(Function&). */
761int LLVMRunFunctionPassManager(LLVMPassManagerRef FPM, LLVMValueRef F);
762
763/** Finalizes all of the function passes scheduled in in the function pass
764 manager. Returns 1 if any of the passes modified the module, 0 otherwise.
765 See llvm::FunctionPassManager::doFinalization. */
766int LLVMFinalizeFunctionPassManager(LLVMPassManagerRef FPM);
767
768/** Frees the memory of a pass pipeline. For function pipelines, does not free
769 the module provider.
770 See llvm::PassManagerBase::~PassManagerBase. */
771void LLVMDisposePassManager(LLVMPassManagerRef PM);
772
773
Gordon Henriksen76a03742007-09-18 03:18:57 +0000774#ifdef __cplusplus
775}
Gordon Henriksen76a03742007-09-18 03:18:57 +0000776
Gordon Henriksen7330acd2007-10-05 23:59:36 +0000777namespace llvm {
Gordon Henriksen0a68fe22007-12-12 01:04:30 +0000778 class ModuleProvider;
Gordon Henriksen34eb6d82007-12-19 22:30:40 +0000779 class MemoryBuffer;
Gordon Henriksen96571492008-03-16 15:55:43 +0000780 class PassManagerBase;
Gordon Henriksen0a68fe22007-12-12 01:04:30 +0000781
Gordon Henriksen34eb6d82007-12-19 22:30:40 +0000782 #define DEFINE_SIMPLE_CONVERSION_FUNCTIONS(ty, ref) \
783 inline ty *unwrap(ref P) { \
784 return reinterpret_cast<ty*>(P); \
785 } \
786 \
787 inline ref wrap(const ty *P) { \
788 return reinterpret_cast<ref>(const_cast<ty*>(P)); \
789 }
Gordon Henriksen7330acd2007-10-05 23:59:36 +0000790
Gordon Henriksen878114b2008-03-16 04:20:44 +0000791 #define DEFINE_ISA_CONVERSION_FUNCTIONS(ty, ref) \
792 DEFINE_SIMPLE_CONVERSION_FUNCTIONS(ty, ref) \
793 \
794 template<typename T> \
795 inline T *unwrap(ref P) { \
796 return cast<T>(unwrap(P)); \
797 }
798
799 #define DEFINE_STDCXX_CONVERSION_FUNCTIONS(ty, ref) \
800 DEFINE_SIMPLE_CONVERSION_FUNCTIONS(ty, ref) \
801 \
802 template<typename T> \
803 inline T *unwrap(ref P) { \
804 T *Q = dynamic_cast<T*>(unwrap(P)); \
805 assert(Q && "Invalid cast!"); \
806 return Q; \
807 }
808
809 DEFINE_ISA_CONVERSION_FUNCTIONS (Type, LLVMTypeRef )
810 DEFINE_ISA_CONVERSION_FUNCTIONS (Value, LLVMValueRef )
Gordon Henriksen823f9732007-12-27 18:25:59 +0000811 DEFINE_SIMPLE_CONVERSION_FUNCTIONS(Module, LLVMModuleRef )
812 DEFINE_SIMPLE_CONVERSION_FUNCTIONS(BasicBlock, LLVMBasicBlockRef )
Eric Christopher59278832008-08-08 19:39:37 +0000813 DEFINE_SIMPLE_CONVERSION_FUNCTIONS(IRBuilder<>, LLVMBuilderRef )
Gordon Henriksen823f9732007-12-27 18:25:59 +0000814 DEFINE_SIMPLE_CONVERSION_FUNCTIONS(PATypeHolder, LLVMTypeHandleRef )
815 DEFINE_SIMPLE_CONVERSION_FUNCTIONS(ModuleProvider, LLVMModuleProviderRef)
816 DEFINE_SIMPLE_CONVERSION_FUNCTIONS(MemoryBuffer, LLVMMemoryBufferRef )
Gordon Henriksen878114b2008-03-16 04:20:44 +0000817 DEFINE_STDCXX_CONVERSION_FUNCTIONS(PassManagerBase, LLVMPassManagerRef )
Gordon Henriksen7330acd2007-10-05 23:59:36 +0000818
Gordon Henriksen878114b2008-03-16 04:20:44 +0000819 #undef DEFINE_STDCXX_CONVERSION_FUNCTIONS
820 #undef DEFINE_ISA_CONVERSION_FUNCTIONS
Gordon Henriksen34eb6d82007-12-19 22:30:40 +0000821 #undef DEFINE_SIMPLE_CONVERSION_FUNCTIONS
Gordon Henriksen7330acd2007-10-05 23:59:36 +0000822
Gordon Henriksen34eb6d82007-12-19 22:30:40 +0000823 /* Specialized opaque type conversions.
824 */
Gordon Henriksen7330acd2007-10-05 23:59:36 +0000825 inline Type **unwrap(LLVMTypeRef* Tys) {
826 return reinterpret_cast<Type**>(Tys);
827 }
828
Gordon Henriksen7330acd2007-10-05 23:59:36 +0000829 inline LLVMTypeRef *wrap(const Type **Tys) {
830 return reinterpret_cast<LLVMTypeRef*>(const_cast<Type**>(Tys));
831 }
832
Gordon Henriksen34eb6d82007-12-19 22:30:40 +0000833 /* Specialized opaque value conversions.
Gordon Henriksen7330acd2007-10-05 23:59:36 +0000834 */
Gordon Henriksen7330acd2007-10-05 23:59:36 +0000835 inline Value **unwrap(LLVMValueRef *Vals) {
836 return reinterpret_cast<Value**>(Vals);
837 }
838
839 template<typename T>
840 inline T **unwrap(LLVMValueRef *Vals, unsigned Length) {
841 #if DEBUG
842 for (LLVMValueRef *I = Vals, E = Vals + Length; I != E; ++I)
843 cast<T>(*I);
844 #endif
845 return reinterpret_cast<T**>(Vals);
846 }
847
Gordon Henriksen7330acd2007-10-05 23:59:36 +0000848 inline LLVMValueRef *wrap(const Value **Vals) {
849 return reinterpret_cast<LLVMValueRef*>(const_cast<Value**>(Vals));
850 }
Gordon Henriksen7330acd2007-10-05 23:59:36 +0000851}
852
853#endif /* !defined(__cplusplus) */
854
855#endif /* !defined(LLVM_C_CORE_H) */