blob: 6016ac61b52f01f8b2d7bac3bd79f81be4c5dcbb [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 */
118 LLVMLinkOnceLinkage, /**< Keep one copy of function when linking (inline)*/
119 LLVMWeakLinkage, /**< Keep one copy of function when linking (weak) */
120 LLVMAppendingLinkage, /**< Special purpose, only applies to global arrays */
121 LLVMInternalLinkage, /**< Rename collisions when linking (static
122 functions) */
123 LLVMDLLImportLinkage, /**< Function to be imported from DLL */
124 LLVMDLLExportLinkage, /**< Function to be accessible from DLL */
125 LLVMExternalWeakLinkage,/**< ExternalWeak linkage description */
126 LLVMGhostLinkage /**< Stand-in functions for streaming fns from
127 bitcode */
Gordon Henriksen76a03742007-09-18 03:18:57 +0000128} LLVMLinkage;
129
130typedef enum {
Gordon Henriksen4a4d7352007-12-30 17:46:33 +0000131 LLVMDefaultVisibility, /**< The GV is visible */
132 LLVMHiddenVisibility, /**< The GV is hidden */
133 LLVMProtectedVisibility /**< The GV is protected */
Gordon Henriksen76a03742007-09-18 03:18:57 +0000134} LLVMVisibility;
135
Gordon Henriksenc23b66c2007-09-26 20:56:12 +0000136typedef enum {
137 LLVMCCallConv = 0,
138 LLVMFastCallConv = 8,
139 LLVMColdCallConv = 9,
140 LLVMX86StdcallCallConv = 64,
141 LLVMX86FastcallCallConv = 65
142} LLVMCallConv;
143
144typedef enum {
Gordon Henriksen4a4d7352007-12-30 17:46:33 +0000145 LLVMIntEQ = 32, /**< equal */
146 LLVMIntNE, /**< not equal */
147 LLVMIntUGT, /**< unsigned greater than */
148 LLVMIntUGE, /**< unsigned greater or equal */
149 LLVMIntULT, /**< unsigned less than */
150 LLVMIntULE, /**< unsigned less or equal */
151 LLVMIntSGT, /**< signed greater than */
152 LLVMIntSGE, /**< signed greater or equal */
153 LLVMIntSLT, /**< signed less than */
154 LLVMIntSLE /**< signed less or equal */
Gordon Henriksenc23b66c2007-09-26 20:56:12 +0000155} LLVMIntPredicate;
156
157typedef enum {
Gordon Henriksen4a4d7352007-12-30 17:46:33 +0000158 LLVMRealPredicateFalse, /**< Always false (always folded) */
159 LLVMRealOEQ, /**< True if ordered and equal */
160 LLVMRealOGT, /**< True if ordered and greater than */
161 LLVMRealOGE, /**< True if ordered and greater than or equal */
162 LLVMRealOLT, /**< True if ordered and less than */
163 LLVMRealOLE, /**< True if ordered and less than or equal */
164 LLVMRealONE, /**< True if ordered and operands are unequal */
165 LLVMRealORD, /**< True if ordered (no nans) */
166 LLVMRealUNO, /**< True if unordered: isnan(X) | isnan(Y) */
167 LLVMRealUEQ, /**< True if unordered or equal */
168 LLVMRealUGT, /**< True if unordered or greater than */
169 LLVMRealUGE, /**< True if unordered, greater than, or equal */
170 LLVMRealULT, /**< True if unordered or less than */
171 LLVMRealULE, /**< True if unordered, less than, or equal */
172 LLVMRealUNE, /**< True if unordered or not equal */
173 LLVMRealPredicateTrue /**< Always true (always folded) */
Gordon Henriksenc23b66c2007-09-26 20:56:12 +0000174} LLVMRealPredicate;
175
Gordon Henriksen76a03742007-09-18 03:18:57 +0000176
Gordon Henriksen34eb6d82007-12-19 22:30:40 +0000177/*===-- Error handling ----------------------------------------------------===*/
178
179void LLVMDisposeMessage(char *Message);
180
181
Gordon Henriksen76a03742007-09-18 03:18:57 +0000182/*===-- Modules -----------------------------------------------------------===*/
183
184/* Create and destroy modules. */
Gordon Henriksena49d4352008-03-07 19:13:06 +0000185/** See llvm::Module::Module. */
Gordon Henriksen76a03742007-09-18 03:18:57 +0000186LLVMModuleRef LLVMModuleCreateWithName(const char *ModuleID);
Gordon Henriksena49d4352008-03-07 19:13:06 +0000187
188/** See llvm::Module::~Module. */
Gordon Henriksen76a03742007-09-18 03:18:57 +0000189void LLVMDisposeModule(LLVMModuleRef M);
190
Gordon Henriksena49d4352008-03-07 19:13:06 +0000191/** Data layout. See Module::getDataLayout. */
Gordon Henriksen05568bb2007-12-27 20:13:47 +0000192const char *LLVMGetDataLayout(LLVMModuleRef M);
193void LLVMSetDataLayout(LLVMModuleRef M, const char *Triple);
194
Gordon Henriksena49d4352008-03-07 19:13:06 +0000195/** Target triple. See Module::getTargetTriple. */
Gordon Henriksen05568bb2007-12-27 20:13:47 +0000196const char *LLVMGetTarget(LLVMModuleRef M);
197void LLVMSetTarget(LLVMModuleRef M, const char *Triple);
198
Gordon Henriksena49d4352008-03-07 19:13:06 +0000199/** See Module::addTypeName. */
Gordon Henriksen76a03742007-09-18 03:18:57 +0000200int LLVMAddTypeName(LLVMModuleRef M, const char *Name, LLVMTypeRef Ty);
Gordon Henriksenc23b66c2007-09-26 20:56:12 +0000201void LLVMDeleteTypeName(LLVMModuleRef M, const char *Name);
Gordon Henriksen76a03742007-09-18 03:18:57 +0000202
Gordon Henriksen6c6075e2008-03-14 23:58:56 +0000203/** See Module::dump. */
204void LLVMDumpModule(LLVMModuleRef M);
205
Gordon Henriksen76a03742007-09-18 03:18:57 +0000206
Gordon Henriksenc23b66c2007-09-26 20:56:12 +0000207/*===-- Types -------------------------------------------------------------===*/
Gordon Henriksen76a03742007-09-18 03:18:57 +0000208
209/* LLVM types conform to the following hierarchy:
210 *
211 * types:
212 * integer type
213 * real type
214 * function type
215 * sequence types:
216 * array type
217 * pointer type
218 * vector type
219 * void type
220 * label type
221 * opaque type
222 */
223
Gordon Henriksena49d4352008-03-07 19:13:06 +0000224/** See llvm::LLVMTypeKind::getTypeID. */
Gordon Henriksen76a03742007-09-18 03:18:57 +0000225LLVMTypeKind LLVMGetTypeKind(LLVMTypeRef Ty);
Gordon Henriksena49d4352008-03-07 19:13:06 +0000226
Gordon Henriksen76a03742007-09-18 03:18:57 +0000227/* Operations on integer types */
Gordon Henriksena735a9c2008-05-04 12:55:34 +0000228LLVMTypeRef LLVMInt1Type(void);
229LLVMTypeRef LLVMInt8Type(void);
230LLVMTypeRef LLVMInt16Type(void);
231LLVMTypeRef LLVMInt32Type(void);
232LLVMTypeRef LLVMInt64Type(void);
Gordon Henriksened7beaa2007-10-06 16:05:20 +0000233LLVMTypeRef LLVMIntType(unsigned NumBits);
Gordon Henriksenc23b66c2007-09-26 20:56:12 +0000234unsigned LLVMGetIntTypeWidth(LLVMTypeRef IntegerTy);
Gordon Henriksen76a03742007-09-18 03:18:57 +0000235
236/* Operations on real types */
Gordon Henriksena735a9c2008-05-04 12:55:34 +0000237LLVMTypeRef LLVMFloatType(void);
238LLVMTypeRef LLVMDoubleType(void);
239LLVMTypeRef LLVMX86FP80Type(void);
240LLVMTypeRef LLVMFP128Type(void);
241LLVMTypeRef LLVMPPCFP128Type(void);
Gordon Henriksen76a03742007-09-18 03:18:57 +0000242
243/* Operations on function types */
Gordon Henriksened7beaa2007-10-06 16:05:20 +0000244LLVMTypeRef LLVMFunctionType(LLVMTypeRef ReturnType,
245 LLVMTypeRef *ParamTypes, unsigned ParamCount,
246 int IsVarArg);
Gordon Henriksen76a03742007-09-18 03:18:57 +0000247int LLVMIsFunctionVarArg(LLVMTypeRef FunctionTy);
Gordon Henriksenc23b66c2007-09-26 20:56:12 +0000248LLVMTypeRef LLVMGetReturnType(LLVMTypeRef FunctionTy);
249unsigned LLVMCountParamTypes(LLVMTypeRef FunctionTy);
250void LLVMGetParamTypes(LLVMTypeRef FunctionTy, LLVMTypeRef *Dest);
Gordon Henriksen76a03742007-09-18 03:18:57 +0000251
252/* Operations on struct types */
Gordon Henriksened7beaa2007-10-06 16:05:20 +0000253LLVMTypeRef LLVMStructType(LLVMTypeRef *ElementTypes, unsigned ElementCount,
254 int Packed);
Gordon Henriksenc23b66c2007-09-26 20:56:12 +0000255unsigned LLVMCountStructElementTypes(LLVMTypeRef StructTy);
Gordon Henriksen76a03742007-09-18 03:18:57 +0000256void LLVMGetStructElementTypes(LLVMTypeRef StructTy, LLVMTypeRef *Dest);
257int LLVMIsPackedStruct(LLVMTypeRef StructTy);
258
259/* Operations on array, pointer, and vector types (sequence types) */
Gordon Henriksened7beaa2007-10-06 16:05:20 +0000260LLVMTypeRef LLVMArrayType(LLVMTypeRef ElementType, unsigned ElementCount);
Gordon Henriksen5a3fe032007-12-17 16:08:32 +0000261LLVMTypeRef LLVMPointerType(LLVMTypeRef ElementType, unsigned AddressSpace);
Gordon Henriksened7beaa2007-10-06 16:05:20 +0000262LLVMTypeRef LLVMVectorType(LLVMTypeRef ElementType, unsigned ElementCount);
Gordon Henriksen76a03742007-09-18 03:18:57 +0000263
264LLVMTypeRef LLVMGetElementType(LLVMTypeRef Ty);
265unsigned LLVMGetArrayLength(LLVMTypeRef ArrayTy);
Gordon Henriksen5a3fe032007-12-17 16:08:32 +0000266unsigned LLVMGetPointerAddressSpace(LLVMTypeRef PointerTy);
Gordon Henriksen76a03742007-09-18 03:18:57 +0000267unsigned LLVMGetVectorSize(LLVMTypeRef VectorTy);
268
269/* Operations on other types */
Gordon Henriksena735a9c2008-05-04 12:55:34 +0000270LLVMTypeRef LLVMVoidType(void);
271LLVMTypeRef LLVMLabelType(void);
272LLVMTypeRef LLVMOpaqueType(void);
Gordon Henriksen76a03742007-09-18 03:18:57 +0000273
Gordon Henriksenffb48762007-10-07 00:13:35 +0000274/* Operations on type handles */
275LLVMTypeHandleRef LLVMCreateTypeHandle(LLVMTypeRef PotentiallyAbstractTy);
276void LLVMRefineType(LLVMTypeRef AbstractTy, LLVMTypeRef ConcreteTy);
277LLVMTypeRef LLVMResolveTypeHandle(LLVMTypeHandleRef TypeHandle);
278void LLVMDisposeTypeHandle(LLVMTypeHandleRef TypeHandle);
279
Gordon Henriksen76a03742007-09-18 03:18:57 +0000280
281/*===-- Values ------------------------------------------------------------===*/
282
283/* The bulk of LLVM's object model consists of values, which comprise a very
284 * rich type hierarchy.
Gordon Henriksen76a03742007-09-18 03:18:57 +0000285 */
286
Gordon Henriksen29e38942008-12-19 18:39:45 +0000287#define LLVM_FOR_EACH_VALUE_SUBCLASS(macro) \
288 macro(Argument) \
289 macro(BasicBlock) \
290 macro(InlineAsm) \
291 macro(User) \
292 macro(Constant) \
293 macro(ConstantAggregateZero) \
294 macro(ConstantArray) \
295 macro(ConstantExpr) \
296 macro(ConstantFP) \
297 macro(ConstantInt) \
298 macro(ConstantPointerNull) \
299 macro(ConstantStruct) \
300 macro(ConstantVector) \
301 macro(GlobalValue) \
302 macro(Function) \
303 macro(GlobalAlias) \
304 macro(GlobalVariable) \
305 macro(UndefValue) \
306 macro(Instruction) \
307 macro(BinaryOperator) \
308 macro(CallInst) \
309 macro(IntrinsicInst) \
310 macro(DbgInfoIntrinsic) \
311 macro(DbgDeclareInst) \
312 macro(DbgFuncStartInst) \
313 macro(DbgRegionEndInst) \
314 macro(DbgRegionStartInst) \
315 macro(DbgStopPointInst) \
316 macro(EHSelectorInst) \
317 macro(MemIntrinsic) \
318 macro(MemCpyInst) \
319 macro(MemMoveInst) \
320 macro(MemSetInst) \
321 macro(CmpInst) \
322 macro(FCmpInst) \
323 macro(ICmpInst) \
324 macro(VFCmpInst) \
325 macro(VICmpInst) \
326 macro(ExtractElementInst) \
327 macro(GetElementPtrInst) \
328 macro(InsertElementInst) \
329 macro(InsertValueInst) \
330 macro(PHINode) \
331 macro(SelectInst) \
332 macro(ShuffleVectorInst) \
333 macro(StoreInst) \
334 macro(TerminatorInst) \
335 macro(BranchInst) \
336 macro(InvokeInst) \
337 macro(ReturnInst) \
338 macro(SwitchInst) \
339 macro(UnreachableInst) \
340 macro(UnwindInst) \
341 macro(UnaryInstruction) \
342 macro(AllocationInst) \
Gordon Henriksen05a868f2008-12-19 18:51:17 +0000343 macro(AllocaInst) \
344 macro(MallocInst) \
Gordon Henriksen29e38942008-12-19 18:39:45 +0000345 macro(CastInst) \
Gordon Henriksen05a868f2008-12-19 18:51:17 +0000346 macro(BitCastInst) \
347 macro(FPExtInst) \
348 macro(FPToSIInst) \
349 macro(FPToUIInst) \
350 macro(FPTruncInst) \
351 macro(IntToPtrInst) \
352 macro(PtrToIntInst) \
353 macro(SExtInst) \
354 macro(SIToFPInst) \
355 macro(TruncInst) \
356 macro(UIToFPInst) \
357 macro(ZExtInst) \
358 macro(ExtractValueInst) \
359 macro(FreeInst) \
360 macro(LoadInst) \
361 macro(VAArgInst)
Gordon Henriksen29e38942008-12-19 18:39:45 +0000362
Gordon Henriksen76a03742007-09-18 03:18:57 +0000363/* Operations on all values */
Gordon Henriksenc23b66c2007-09-26 20:56:12 +0000364LLVMTypeRef LLVMTypeOf(LLVMValueRef Val);
Gordon Henriksen76a03742007-09-18 03:18:57 +0000365const char *LLVMGetValueName(LLVMValueRef Val);
366void LLVMSetValueName(LLVMValueRef Val, const char *Name);
Gordon Henriksen1d0d24c2007-10-06 00:08:49 +0000367void LLVMDumpValue(LLVMValueRef Val);
Gordon Henriksen76a03742007-09-18 03:18:57 +0000368
Gordon Henriksen29e38942008-12-19 18:39:45 +0000369/* Conversion functions. Return the input value if it is an instance of the
370 specified class, otherwise NULL. See llvm::dyn_cast_or_null<>. */
371#define LLVM_DECLARE_VALUE_CAST(name) \
372 LLVMValueRef LLVMIsA##name(LLVMValueRef Val);
373LLVM_FOR_EACH_VALUE_SUBCLASS(LLVM_DECLARE_VALUE_CAST)
374
Gordon Henriksen76a03742007-09-18 03:18:57 +0000375/* Operations on constants of any type */
Gordon Henriksen1046c732007-10-06 15:11:06 +0000376LLVMValueRef LLVMConstNull(LLVMTypeRef Ty); /* all zeroes */
377LLVMValueRef LLVMConstAllOnes(LLVMTypeRef Ty); /* only for int/vector */
Gordon Henriksen76a03742007-09-18 03:18:57 +0000378LLVMValueRef LLVMGetUndef(LLVMTypeRef Ty);
Gordon Henriksendc88c062007-09-18 18:07:51 +0000379int LLVMIsConstant(LLVMValueRef Val);
Gordon Henriksen76a03742007-09-18 03:18:57 +0000380int LLVMIsNull(LLVMValueRef Val);
Gordon Henriksendc88c062007-09-18 18:07:51 +0000381int LLVMIsUndef(LLVMValueRef Val);
Gordon Henriksen76a03742007-09-18 03:18:57 +0000382
383/* Operations on scalar constants */
Gordon Henriksen1046c732007-10-06 15:11:06 +0000384LLVMValueRef LLVMConstInt(LLVMTypeRef IntTy, unsigned long long N,
385 int SignExtend);
386LLVMValueRef LLVMConstReal(LLVMTypeRef RealTy, double N);
Gordon Henriksen931e1212008-02-02 01:07:50 +0000387LLVMValueRef LLVMConstRealOfString(LLVMTypeRef RealTy, const char *Text);
Gordon Henriksen76a03742007-09-18 03:18:57 +0000388
389/* Operations on composite constants */
Gordon Henriksen1046c732007-10-06 15:11:06 +0000390LLVMValueRef LLVMConstString(const char *Str, unsigned Length,
391 int DontNullTerminate);
Gordon Henriksen2ad5aef2008-04-25 03:21:19 +0000392LLVMValueRef LLVMConstArray(LLVMTypeRef ElementTy,
Gordon Henriksen1046c732007-10-06 15:11:06 +0000393 LLVMValueRef *ConstantVals, unsigned Length);
394LLVMValueRef LLVMConstStruct(LLVMValueRef *ConstantVals, unsigned Count,
395 int packed);
396LLVMValueRef LLVMConstVector(LLVMValueRef *ScalarConstantVals, unsigned Size);
Gordon Henriksen76a03742007-09-18 03:18:57 +0000397
Gordon Henriksen7ce31762007-10-06 14:29:36 +0000398/* Constant expressions */
399LLVMValueRef LLVMSizeOf(LLVMTypeRef Ty);
400LLVMValueRef LLVMConstNeg(LLVMValueRef ConstantVal);
401LLVMValueRef LLVMConstNot(LLVMValueRef ConstantVal);
402LLVMValueRef LLVMConstAdd(LLVMValueRef LHSConstant, LLVMValueRef RHSConstant);
403LLVMValueRef LLVMConstSub(LLVMValueRef LHSConstant, LLVMValueRef RHSConstant);
404LLVMValueRef LLVMConstMul(LLVMValueRef LHSConstant, LLVMValueRef RHSConstant);
405LLVMValueRef LLVMConstUDiv(LLVMValueRef LHSConstant, LLVMValueRef RHSConstant);
406LLVMValueRef LLVMConstSDiv(LLVMValueRef LHSConstant, LLVMValueRef RHSConstant);
407LLVMValueRef LLVMConstFDiv(LLVMValueRef LHSConstant, LLVMValueRef RHSConstant);
408LLVMValueRef LLVMConstURem(LLVMValueRef LHSConstant, LLVMValueRef RHSConstant);
409LLVMValueRef LLVMConstSRem(LLVMValueRef LHSConstant, LLVMValueRef RHSConstant);
410LLVMValueRef LLVMConstFRem(LLVMValueRef LHSConstant, LLVMValueRef RHSConstant);
411LLVMValueRef LLVMConstAnd(LLVMValueRef LHSConstant, LLVMValueRef RHSConstant);
412LLVMValueRef LLVMConstOr(LLVMValueRef LHSConstant, LLVMValueRef RHSConstant);
413LLVMValueRef LLVMConstXor(LLVMValueRef LHSConstant, LLVMValueRef RHSConstant);
414LLVMValueRef LLVMConstICmp(LLVMIntPredicate Predicate,
415 LLVMValueRef LHSConstant, LLVMValueRef RHSConstant);
416LLVMValueRef LLVMConstFCmp(LLVMRealPredicate Predicate,
417 LLVMValueRef LHSConstant, LLVMValueRef RHSConstant);
418LLVMValueRef LLVMConstShl(LLVMValueRef LHSConstant, LLVMValueRef RHSConstant);
419LLVMValueRef LLVMConstLShr(LLVMValueRef LHSConstant, LLVMValueRef RHSConstant);
420LLVMValueRef LLVMConstAShr(LLVMValueRef LHSConstant, LLVMValueRef RHSConstant);
421LLVMValueRef LLVMConstGEP(LLVMValueRef ConstantVal,
422 LLVMValueRef *ConstantIndices, unsigned NumIndices);
423LLVMValueRef LLVMConstTrunc(LLVMValueRef ConstantVal, LLVMTypeRef ToType);
424LLVMValueRef LLVMConstSExt(LLVMValueRef ConstantVal, LLVMTypeRef ToType);
425LLVMValueRef LLVMConstZExt(LLVMValueRef ConstantVal, LLVMTypeRef ToType);
426LLVMValueRef LLVMConstFPTrunc(LLVMValueRef ConstantVal, LLVMTypeRef ToType);
427LLVMValueRef LLVMConstFPExt(LLVMValueRef ConstantVal, LLVMTypeRef ToType);
428LLVMValueRef LLVMConstUIToFP(LLVMValueRef ConstantVal, LLVMTypeRef ToType);
429LLVMValueRef LLVMConstSIToFP(LLVMValueRef ConstantVal, LLVMTypeRef ToType);
430LLVMValueRef LLVMConstFPToUI(LLVMValueRef ConstantVal, LLVMTypeRef ToType);
431LLVMValueRef LLVMConstFPToSI(LLVMValueRef ConstantVal, LLVMTypeRef ToType);
432LLVMValueRef LLVMConstPtrToInt(LLVMValueRef ConstantVal, LLVMTypeRef ToType);
433LLVMValueRef LLVMConstIntToPtr(LLVMValueRef ConstantVal, LLVMTypeRef ToType);
434LLVMValueRef LLVMConstBitCast(LLVMValueRef ConstantVal, LLVMTypeRef ToType);
435LLVMValueRef LLVMConstSelect(LLVMValueRef ConstantCondition,
436 LLVMValueRef ConstantIfTrue,
437 LLVMValueRef ConstantIfFalse);
438LLVMValueRef LLVMConstExtractElement(LLVMValueRef VectorConstant,
439 LLVMValueRef IndexConstant);
440LLVMValueRef LLVMConstInsertElement(LLVMValueRef VectorConstant,
441 LLVMValueRef ElementValueConstant,
442 LLVMValueRef IndexConstant);
443LLVMValueRef LLVMConstShuffleVector(LLVMValueRef VectorAConstant,
444 LLVMValueRef VectorBConstant,
445 LLVMValueRef MaskConstant);
Dan Gohmand5104a52008-11-03 22:55:43 +0000446LLVMValueRef LLVMConstExtractValue(LLVMValueRef AggConstant, unsigned *IdxList,
447 unsigned NumIdx);
448LLVMValueRef LLVMConstInsertValue(LLVMValueRef AggConstant,
449 LLVMValueRef ElementValueConstant,
450 unsigned *IdxList, unsigned NumIdx);
Chris Lattner3d1f5522008-12-17 21:39:50 +0000451LLVMValueRef LLVMConstInlineAsm(LLVMTypeRef Ty,
452 const char *AsmString, const char *Constraints,
453 int HasSideEffects);
Gordon Henriksen7ce31762007-10-06 14:29:36 +0000454
Gordon Henriksen76a03742007-09-18 03:18:57 +0000455/* Operations on global variables, functions, and aliases (globals) */
Gordon Henriksen265f7802008-03-19 01:11:35 +0000456LLVMModuleRef LLVMGetGlobalParent(LLVMValueRef Global);
Gordon Henriksen76a03742007-09-18 03:18:57 +0000457int LLVMIsDeclaration(LLVMValueRef Global);
458LLVMLinkage LLVMGetLinkage(LLVMValueRef Global);
459void LLVMSetLinkage(LLVMValueRef Global, LLVMLinkage Linkage);
460const char *LLVMGetSection(LLVMValueRef Global);
461void LLVMSetSection(LLVMValueRef Global, const char *Section);
462LLVMVisibility LLVMGetVisibility(LLVMValueRef Global);
463void LLVMSetVisibility(LLVMValueRef Global, LLVMVisibility Viz);
464unsigned LLVMGetAlignment(LLVMValueRef Global);
465void LLVMSetAlignment(LLVMValueRef Global, unsigned Bytes);
466
467/* Operations on global variables */
468LLVMValueRef LLVMAddGlobal(LLVMModuleRef M, LLVMTypeRef Ty, const char *Name);
Gordon Henriksen783f7bb2007-10-08 03:45:09 +0000469LLVMValueRef LLVMGetNamedGlobal(LLVMModuleRef M, const char *Name);
Gordon Henriksen07a45f42008-03-23 22:21:29 +0000470LLVMValueRef LLVMGetFirstGlobal(LLVMModuleRef M);
471LLVMValueRef LLVMGetLastGlobal(LLVMModuleRef M);
472LLVMValueRef LLVMGetNextGlobal(LLVMValueRef GlobalVar);
473LLVMValueRef LLVMGetPreviousGlobal(LLVMValueRef GlobalVar);
Gordon Henriksen76a03742007-09-18 03:18:57 +0000474void LLVMDeleteGlobal(LLVMValueRef GlobalVar);
Gordon Henriksen76a03742007-09-18 03:18:57 +0000475LLVMValueRef LLVMGetInitializer(LLVMValueRef GlobalVar);
476void LLVMSetInitializer(LLVMValueRef GlobalVar, LLVMValueRef ConstantVal);
477int LLVMIsThreadLocal(LLVMValueRef GlobalVar);
478void LLVMSetThreadLocal(LLVMValueRef GlobalVar, int IsThreadLocal);
Gordon Henriksen751ebf72007-10-07 17:31:42 +0000479int LLVMIsGlobalConstant(LLVMValueRef GlobalVar);
480void LLVMSetGlobalConstant(LLVMValueRef GlobalVar, int IsConstant);
Gordon Henriksen76a03742007-09-18 03:18:57 +0000481
Chris Lattner3d1f5522008-12-17 21:39:50 +0000482/* Operations on aliases */
483LLVMValueRef LLVMAddAlias(LLVMModuleRef M, LLVMTypeRef Ty, LLVMValueRef Aliasee,
484 const char *Name);
485
Gordon Henriksenc23b66c2007-09-26 20:56:12 +0000486/* Operations on functions */
487LLVMValueRef LLVMAddFunction(LLVMModuleRef M, const char *Name,
488 LLVMTypeRef FunctionTy);
Gordon Henriksen783f7bb2007-10-08 03:45:09 +0000489LLVMValueRef LLVMGetNamedFunction(LLVMModuleRef M, const char *Name);
Gordon Henriksen054817c2008-03-19 03:47:18 +0000490LLVMValueRef LLVMGetFirstFunction(LLVMModuleRef M);
491LLVMValueRef LLVMGetLastFunction(LLVMModuleRef M);
492LLVMValueRef LLVMGetNextFunction(LLVMValueRef Fn);
493LLVMValueRef LLVMGetPreviousFunction(LLVMValueRef Fn);
Gordon Henriksenc23b66c2007-09-26 20:56:12 +0000494void LLVMDeleteFunction(LLVMValueRef Fn);
Gordon Henriksenc23b66c2007-09-26 20:56:12 +0000495unsigned LLVMGetIntrinsicID(LLVMValueRef Fn);
496unsigned LLVMGetFunctionCallConv(LLVMValueRef Fn);
497void LLVMSetFunctionCallConv(LLVMValueRef Fn, unsigned CC);
Gordon Henriksend930f912008-08-17 18:44:35 +0000498const char *LLVMGetGC(LLVMValueRef Fn);
499void LLVMSetGC(LLVMValueRef Fn, const char *Name);
Gordon Henriksenc23b66c2007-09-26 20:56:12 +0000500
Gordon Henriksen265f7802008-03-19 01:11:35 +0000501/* Operations on parameters */
502unsigned LLVMCountParams(LLVMValueRef Fn);
503void LLVMGetParams(LLVMValueRef Fn, LLVMValueRef *Params);
504LLVMValueRef LLVMGetParam(LLVMValueRef Fn, unsigned Index);
505LLVMValueRef LLVMGetParamParent(LLVMValueRef Inst);
Gordon Henriksen07a45f42008-03-23 22:21:29 +0000506LLVMValueRef LLVMGetFirstParam(LLVMValueRef Fn);
507LLVMValueRef LLVMGetLastParam(LLVMValueRef Fn);
508LLVMValueRef LLVMGetNextParam(LLVMValueRef Arg);
509LLVMValueRef LLVMGetPreviousParam(LLVMValueRef Arg);
Devang Patel4c758ea2008-09-25 21:00:45 +0000510void LLVMAddAttribute(LLVMValueRef Arg, LLVMAttribute PA);
511void LLVMRemoveAttribute(LLVMValueRef Arg, LLVMAttribute PA);
Gordon Henriksen2d9cc212008-04-28 17:37:06 +0000512void LLVMSetParamAlignment(LLVMValueRef Arg, unsigned align);
Gordon Henriksen265f7802008-03-19 01:11:35 +0000513
Gordon Henriksenc23b66c2007-09-26 20:56:12 +0000514/* Operations on basic blocks */
Gordon Henriksen07a45f42008-03-23 22:21:29 +0000515LLVMValueRef LLVMBasicBlockAsValue(LLVMBasicBlockRef BB);
Gordon Henriksenc23b66c2007-09-26 20:56:12 +0000516int LLVMValueIsBasicBlock(LLVMValueRef Val);
517LLVMBasicBlockRef LLVMValueAsBasicBlock(LLVMValueRef Val);
Gordon Henriksen07a45f42008-03-23 22:21:29 +0000518LLVMValueRef LLVMGetBasicBlockParent(LLVMBasicBlockRef BB);
Gordon Henriksenc23b66c2007-09-26 20:56:12 +0000519unsigned LLVMCountBasicBlocks(LLVMValueRef Fn);
520void LLVMGetBasicBlocks(LLVMValueRef Fn, LLVMBasicBlockRef *BasicBlocks);
Gordon Henriksen054817c2008-03-19 03:47:18 +0000521LLVMBasicBlockRef LLVMGetFirstBasicBlock(LLVMValueRef Fn);
522LLVMBasicBlockRef LLVMGetLastBasicBlock(LLVMValueRef Fn);
523LLVMBasicBlockRef LLVMGetNextBasicBlock(LLVMBasicBlockRef BB);
524LLVMBasicBlockRef LLVMGetPreviousBasicBlock(LLVMBasicBlockRef BB);
Gordon Henriksenc23b66c2007-09-26 20:56:12 +0000525LLVMBasicBlockRef LLVMGetEntryBasicBlock(LLVMValueRef Fn);
526LLVMBasicBlockRef LLVMAppendBasicBlock(LLVMValueRef Fn, const char *Name);
527LLVMBasicBlockRef LLVMInsertBasicBlock(LLVMBasicBlockRef InsertBeforeBB,
528 const char *Name);
529void LLVMDeleteBasicBlock(LLVMBasicBlockRef BB);
530
Gordon Henriksen265f7802008-03-19 01:11:35 +0000531/* Operations on instructions */
532LLVMBasicBlockRef LLVMGetInstructionParent(LLVMValueRef Inst);
Gordon Henriksen054817c2008-03-19 03:47:18 +0000533LLVMValueRef LLVMGetFirstInstruction(LLVMBasicBlockRef BB);
534LLVMValueRef LLVMGetLastInstruction(LLVMBasicBlockRef BB);
535LLVMValueRef LLVMGetNextInstruction(LLVMValueRef Inst);
536LLVMValueRef LLVMGetPreviousInstruction(LLVMValueRef Inst);
Gordon Henriksen265f7802008-03-19 01:11:35 +0000537
Gordon Henriksen1158c532007-12-29 20:45:00 +0000538/* Operations on call sites */
539void LLVMSetInstructionCallConv(LLVMValueRef Instr, unsigned CC);
540unsigned LLVMGetInstructionCallConv(LLVMValueRef Instr);
Devang Patel4c758ea2008-09-25 21:00:45 +0000541void LLVMAddInstrAttribute(LLVMValueRef Instr, unsigned index, LLVMAttribute);
542void LLVMRemoveInstrAttribute(LLVMValueRef Instr, unsigned index,
543 LLVMAttribute);
Gordon Henriksen2d9cc212008-04-28 17:37:06 +0000544void LLVMSetInstrParamAlignment(LLVMValueRef Instr, unsigned index,
545 unsigned align);
Gordon Henriksen1158c532007-12-29 20:45:00 +0000546
Gordon Henrikseneeb65372008-08-30 16:34:54 +0000547/* Operations on call instructions (only) */
548int LLVMIsTailCall(LLVMValueRef CallInst);
549void LLVMSetTailCall(LLVMValueRef CallInst, int IsTailCall);
550
Gordon Henriksen44dd8fb2007-10-08 18:14:39 +0000551/* Operations on phi nodes */
552void LLVMAddIncoming(LLVMValueRef PhiNode, LLVMValueRef *IncomingValues,
553 LLVMBasicBlockRef *IncomingBlocks, unsigned Count);
554unsigned LLVMCountIncoming(LLVMValueRef PhiNode);
555LLVMValueRef LLVMGetIncomingValue(LLVMValueRef PhiNode, unsigned Index);
556LLVMBasicBlockRef LLVMGetIncomingBlock(LLVMValueRef PhiNode, unsigned Index);
Gordon Henriksenc23b66c2007-09-26 20:56:12 +0000557
558/*===-- Instruction builders ----------------------------------------------===*/
559
560/* An instruction builder represents a point within a basic block, and is the
561 * exclusive means of building instructions using the C interface.
562 */
563
Gordon Henriksena735a9c2008-05-04 12:55:34 +0000564LLVMBuilderRef LLVMCreateBuilder(void);
Gordon Henriksen054817c2008-03-19 03:47:18 +0000565void LLVMPositionBuilder(LLVMBuilderRef Builder, LLVMBasicBlockRef Block,
566 LLVMValueRef Instr);
Gordon Henriksenc23b66c2007-09-26 20:56:12 +0000567void LLVMPositionBuilderBefore(LLVMBuilderRef Builder, LLVMValueRef Instr);
568void LLVMPositionBuilderAtEnd(LLVMBuilderRef Builder, LLVMBasicBlockRef Block);
Gordon Henriksen265f7802008-03-19 01:11:35 +0000569LLVMBasicBlockRef LLVMGetInsertBlock(LLVMBuilderRef Builder);
Chris Lattner3d1f5522008-12-17 21:39:50 +0000570void LLVMClearInsertionPosition(LLVMBuilderRef Builder);
571void LLVMInsertIntoBuilder(LLVMBuilderRef Builder, LLVMValueRef Instr);
Gordon Henriksenc23b66c2007-09-26 20:56:12 +0000572void LLVMDisposeBuilder(LLVMBuilderRef Builder);
573
574/* Terminators */
575LLVMValueRef LLVMBuildRetVoid(LLVMBuilderRef);
576LLVMValueRef LLVMBuildRet(LLVMBuilderRef, LLVMValueRef V);
577LLVMValueRef LLVMBuildBr(LLVMBuilderRef, LLVMBasicBlockRef Dest);
578LLVMValueRef LLVMBuildCondBr(LLVMBuilderRef, LLVMValueRef If,
579 LLVMBasicBlockRef Then, LLVMBasicBlockRef Else);
580LLVMValueRef LLVMBuildSwitch(LLVMBuilderRef, LLVMValueRef V,
581 LLVMBasicBlockRef Else, unsigned NumCases);
582LLVMValueRef LLVMBuildInvoke(LLVMBuilderRef, LLVMValueRef Fn,
583 LLVMValueRef *Args, unsigned NumArgs,
584 LLVMBasicBlockRef Then, LLVMBasicBlockRef Catch,
585 const char *Name);
586LLVMValueRef LLVMBuildUnwind(LLVMBuilderRef);
587LLVMValueRef LLVMBuildUnreachable(LLVMBuilderRef);
588
Gordon Henriksen097102c2008-01-01 05:50:53 +0000589/* Add a case to the switch instruction */
590void LLVMAddCase(LLVMValueRef Switch, LLVMValueRef OnVal,
591 LLVMBasicBlockRef Dest);
592
Gordon Henriksenc23b66c2007-09-26 20:56:12 +0000593/* Arithmetic */
594LLVMValueRef LLVMBuildAdd(LLVMBuilderRef, LLVMValueRef LHS, LLVMValueRef RHS,
595 const char *Name);
596LLVMValueRef LLVMBuildSub(LLVMBuilderRef, LLVMValueRef LHS, LLVMValueRef RHS,
597 const char *Name);
598LLVMValueRef LLVMBuildMul(LLVMBuilderRef, LLVMValueRef LHS, LLVMValueRef RHS,
599 const char *Name);
600LLVMValueRef LLVMBuildUDiv(LLVMBuilderRef, LLVMValueRef LHS, LLVMValueRef RHS,
601 const char *Name);
602LLVMValueRef LLVMBuildSDiv(LLVMBuilderRef, LLVMValueRef LHS, LLVMValueRef RHS,
603 const char *Name);
604LLVMValueRef LLVMBuildFDiv(LLVMBuilderRef, LLVMValueRef LHS, LLVMValueRef RHS,
605 const char *Name);
606LLVMValueRef LLVMBuildURem(LLVMBuilderRef, LLVMValueRef LHS, LLVMValueRef RHS,
607 const char *Name);
608LLVMValueRef LLVMBuildSRem(LLVMBuilderRef, LLVMValueRef LHS, LLVMValueRef RHS,
609 const char *Name);
610LLVMValueRef LLVMBuildFRem(LLVMBuilderRef, LLVMValueRef LHS, LLVMValueRef RHS,
611 const char *Name);
612LLVMValueRef LLVMBuildShl(LLVMBuilderRef, LLVMValueRef LHS, LLVMValueRef RHS,
613 const char *Name);
614LLVMValueRef LLVMBuildLShr(LLVMBuilderRef, LLVMValueRef LHS, LLVMValueRef RHS,
615 const char *Name);
616LLVMValueRef LLVMBuildAShr(LLVMBuilderRef, LLVMValueRef LHS, LLVMValueRef RHS,
617 const char *Name);
618LLVMValueRef LLVMBuildAnd(LLVMBuilderRef, LLVMValueRef LHS, LLVMValueRef RHS,
619 const char *Name);
620LLVMValueRef LLVMBuildOr(LLVMBuilderRef, LLVMValueRef LHS, LLVMValueRef RHS,
621 const char *Name);
622LLVMValueRef LLVMBuildXor(LLVMBuilderRef, LLVMValueRef LHS, LLVMValueRef RHS,
623 const char *Name);
624LLVMValueRef LLVMBuildNeg(LLVMBuilderRef, LLVMValueRef V, const char *Name);
625LLVMValueRef LLVMBuildNot(LLVMBuilderRef, LLVMValueRef V, const char *Name);
626
627/* Memory */
628LLVMValueRef LLVMBuildMalloc(LLVMBuilderRef, LLVMTypeRef Ty, const char *Name);
629LLVMValueRef LLVMBuildArrayMalloc(LLVMBuilderRef, LLVMTypeRef Ty,
630 LLVMValueRef Val, const char *Name);
631LLVMValueRef LLVMBuildAlloca(LLVMBuilderRef, LLVMTypeRef Ty, const char *Name);
632LLVMValueRef LLVMBuildArrayAlloca(LLVMBuilderRef, LLVMTypeRef Ty,
633 LLVMValueRef Val, const char *Name);
634LLVMValueRef LLVMBuildFree(LLVMBuilderRef, LLVMValueRef PointerVal);
635LLVMValueRef LLVMBuildLoad(LLVMBuilderRef, LLVMValueRef PointerVal,
636 const char *Name);
637LLVMValueRef LLVMBuildStore(LLVMBuilderRef, LLVMValueRef Val, LLVMValueRef Ptr);
638LLVMValueRef LLVMBuildGEP(LLVMBuilderRef B, LLVMValueRef Pointer,
639 LLVMValueRef *Indices, unsigned NumIndices,
640 const char *Name);
641
642/* Casts */
643LLVMValueRef LLVMBuildTrunc(LLVMBuilderRef, LLVMValueRef Val,
644 LLVMTypeRef DestTy, const char *Name);
645LLVMValueRef LLVMBuildZExt(LLVMBuilderRef, LLVMValueRef Val,
646 LLVMTypeRef DestTy, const char *Name);
647LLVMValueRef LLVMBuildSExt(LLVMBuilderRef, LLVMValueRef Val,
648 LLVMTypeRef DestTy, const char *Name);
649LLVMValueRef LLVMBuildFPToUI(LLVMBuilderRef, LLVMValueRef Val,
650 LLVMTypeRef DestTy, const char *Name);
651LLVMValueRef LLVMBuildFPToSI(LLVMBuilderRef, LLVMValueRef Val,
652 LLVMTypeRef DestTy, const char *Name);
653LLVMValueRef LLVMBuildUIToFP(LLVMBuilderRef, LLVMValueRef Val,
654 LLVMTypeRef DestTy, const char *Name);
655LLVMValueRef LLVMBuildSIToFP(LLVMBuilderRef, LLVMValueRef Val,
656 LLVMTypeRef DestTy, const char *Name);
657LLVMValueRef LLVMBuildFPTrunc(LLVMBuilderRef, LLVMValueRef Val,
658 LLVMTypeRef DestTy, const char *Name);
659LLVMValueRef LLVMBuildFPExt(LLVMBuilderRef, LLVMValueRef Val,
660 LLVMTypeRef DestTy, const char *Name);
661LLVMValueRef LLVMBuildPtrToInt(LLVMBuilderRef, LLVMValueRef Val,
662 LLVMTypeRef DestTy, const char *Name);
663LLVMValueRef LLVMBuildIntToPtr(LLVMBuilderRef, LLVMValueRef Val,
664 LLVMTypeRef DestTy, const char *Name);
665LLVMValueRef LLVMBuildBitCast(LLVMBuilderRef, LLVMValueRef Val,
666 LLVMTypeRef DestTy, const char *Name);
667
668/* Comparisons */
669LLVMValueRef LLVMBuildICmp(LLVMBuilderRef, LLVMIntPredicate Op,
670 LLVMValueRef LHS, LLVMValueRef RHS,
671 const char *Name);
672LLVMValueRef LLVMBuildFCmp(LLVMBuilderRef, LLVMRealPredicate Op,
673 LLVMValueRef LHS, LLVMValueRef RHS,
674 const char *Name);
675
676/* Miscellaneous instructions */
677LLVMValueRef LLVMBuildPhi(LLVMBuilderRef, LLVMTypeRef Ty, const char *Name);
678LLVMValueRef LLVMBuildCall(LLVMBuilderRef, LLVMValueRef Fn,
679 LLVMValueRef *Args, unsigned NumArgs,
680 const char *Name);
681LLVMValueRef LLVMBuildSelect(LLVMBuilderRef, LLVMValueRef If,
682 LLVMValueRef Then, LLVMValueRef Else,
683 const char *Name);
684LLVMValueRef LLVMBuildVAArg(LLVMBuilderRef, LLVMValueRef List, LLVMTypeRef Ty,
685 const char *Name);
686LLVMValueRef LLVMBuildExtractElement(LLVMBuilderRef, LLVMValueRef VecVal,
687 LLVMValueRef Index, const char *Name);
688LLVMValueRef LLVMBuildInsertElement(LLVMBuilderRef, LLVMValueRef VecVal,
689 LLVMValueRef EltVal, LLVMValueRef Index,
690 const char *Name);
691LLVMValueRef LLVMBuildShuffleVector(LLVMBuilderRef, LLVMValueRef V1,
692 LLVMValueRef V2, LLVMValueRef Mask,
693 const char *Name);
Dan Gohmand5104a52008-11-03 22:55:43 +0000694LLVMValueRef LLVMBuildExtractValue(LLVMBuilderRef, LLVMValueRef AggVal,
695 unsigned Index, const char *Name);
696LLVMValueRef LLVMBuildInsertValue(LLVMBuilderRef, LLVMValueRef AggVal,
697 LLVMValueRef EltVal, unsigned Index,
698 const char *Name);
Gordon Henriksen76a03742007-09-18 03:18:57 +0000699
Gordon Henriksen34eb6d82007-12-19 22:30:40 +0000700
Gordon Henriksen0a68fe22007-12-12 01:04:30 +0000701/*===-- Module providers --------------------------------------------------===*/
702
703/* Encapsulates the module M in a module provider, taking ownership of the
704 * module.
705 * See the constructor llvm::ExistingModuleProvider::ExistingModuleProvider.
706 */
707LLVMModuleProviderRef
708LLVMCreateModuleProviderForExistingModule(LLVMModuleRef M);
709
710/* Destroys the module provider MP as well as the contained module.
711 * See the destructor llvm::ModuleProvider::~ModuleProvider.
712 */
713void LLVMDisposeModuleProvider(LLVMModuleProviderRef MP);
714
Gordon Henriksen34eb6d82007-12-19 22:30:40 +0000715
716/*===-- Memory buffers ----------------------------------------------------===*/
717
718int LLVMCreateMemoryBufferWithContentsOfFile(const char *Path,
719 LLVMMemoryBufferRef *OutMemBuf,
720 char **OutMessage);
721int LLVMCreateMemoryBufferWithSTDIN(LLVMMemoryBufferRef *OutMemBuf,
722 char **OutMessage);
723void LLVMDisposeMemoryBuffer(LLVMMemoryBufferRef MemBuf);
724
Gordon Henriksen878114b2008-03-16 04:20:44 +0000725
726/*===-- Pass Managers -----------------------------------------------------===*/
727
728/** Constructs a new whole-module pass pipeline. This type of pipeline is
729 suitable for link-time optimization and whole-module transformations.
730 See llvm::PassManager::PassManager. */
Gordon Henriksena735a9c2008-05-04 12:55:34 +0000731LLVMPassManagerRef LLVMCreatePassManager(void);
Gordon Henriksen878114b2008-03-16 04:20:44 +0000732
733/** Constructs a new function-by-function pass pipeline over the module
734 provider. It does not take ownership of the module provider. This type of
735 pipeline is suitable for code generation and JIT compilation tasks.
736 See llvm::FunctionPassManager::FunctionPassManager. */
737LLVMPassManagerRef LLVMCreateFunctionPassManager(LLVMModuleProviderRef MP);
738
739/** Initializes, executes on the provided module, and finalizes all of the
740 passes scheduled in the pass manager. Returns 1 if any of the passes
741 modified the module, 0 otherwise. See llvm::PassManager::run(Module&). */
742int LLVMRunPassManager(LLVMPassManagerRef PM, LLVMModuleRef M);
743
744/** Initializes all of the function passes scheduled in the function pass
745 manager. Returns 1 if any of the passes modified the module, 0 otherwise.
746 See llvm::FunctionPassManager::doInitialization. */
747int LLVMInitializeFunctionPassManager(LLVMPassManagerRef FPM);
748
749/** Executes all of the function passes scheduled in the function pass manager
750 on the provided function. Returns 1 if any of the passes modified the
751 function, false otherwise.
752 See llvm::FunctionPassManager::run(Function&). */
753int LLVMRunFunctionPassManager(LLVMPassManagerRef FPM, LLVMValueRef F);
754
755/** Finalizes all of the function passes scheduled in in the function pass
756 manager. Returns 1 if any of the passes modified the module, 0 otherwise.
757 See llvm::FunctionPassManager::doFinalization. */
758int LLVMFinalizeFunctionPassManager(LLVMPassManagerRef FPM);
759
760/** Frees the memory of a pass pipeline. For function pipelines, does not free
761 the module provider.
762 See llvm::PassManagerBase::~PassManagerBase. */
763void LLVMDisposePassManager(LLVMPassManagerRef PM);
764
765
Gordon Henriksen76a03742007-09-18 03:18:57 +0000766#ifdef __cplusplus
767}
Gordon Henriksen76a03742007-09-18 03:18:57 +0000768
Gordon Henriksen7330acd2007-10-05 23:59:36 +0000769namespace llvm {
Gordon Henriksen0a68fe22007-12-12 01:04:30 +0000770 class ModuleProvider;
Gordon Henriksen34eb6d82007-12-19 22:30:40 +0000771 class MemoryBuffer;
Gordon Henriksen96571492008-03-16 15:55:43 +0000772 class PassManagerBase;
Gordon Henriksen0a68fe22007-12-12 01:04:30 +0000773
Gordon Henriksen34eb6d82007-12-19 22:30:40 +0000774 #define DEFINE_SIMPLE_CONVERSION_FUNCTIONS(ty, ref) \
775 inline ty *unwrap(ref P) { \
776 return reinterpret_cast<ty*>(P); \
777 } \
778 \
779 inline ref wrap(const ty *P) { \
780 return reinterpret_cast<ref>(const_cast<ty*>(P)); \
781 }
Gordon Henriksen7330acd2007-10-05 23:59:36 +0000782
Gordon Henriksen878114b2008-03-16 04:20:44 +0000783 #define DEFINE_ISA_CONVERSION_FUNCTIONS(ty, ref) \
784 DEFINE_SIMPLE_CONVERSION_FUNCTIONS(ty, ref) \
785 \
786 template<typename T> \
787 inline T *unwrap(ref P) { \
788 return cast<T>(unwrap(P)); \
789 }
790
791 #define DEFINE_STDCXX_CONVERSION_FUNCTIONS(ty, ref) \
792 DEFINE_SIMPLE_CONVERSION_FUNCTIONS(ty, ref) \
793 \
794 template<typename T> \
795 inline T *unwrap(ref P) { \
796 T *Q = dynamic_cast<T*>(unwrap(P)); \
797 assert(Q && "Invalid cast!"); \
798 return Q; \
799 }
800
801 DEFINE_ISA_CONVERSION_FUNCTIONS (Type, LLVMTypeRef )
802 DEFINE_ISA_CONVERSION_FUNCTIONS (Value, LLVMValueRef )
Gordon Henriksen823f9732007-12-27 18:25:59 +0000803 DEFINE_SIMPLE_CONVERSION_FUNCTIONS(Module, LLVMModuleRef )
804 DEFINE_SIMPLE_CONVERSION_FUNCTIONS(BasicBlock, LLVMBasicBlockRef )
Eric Christopher59278832008-08-08 19:39:37 +0000805 DEFINE_SIMPLE_CONVERSION_FUNCTIONS(IRBuilder<>, LLVMBuilderRef )
Gordon Henriksen823f9732007-12-27 18:25:59 +0000806 DEFINE_SIMPLE_CONVERSION_FUNCTIONS(PATypeHolder, LLVMTypeHandleRef )
807 DEFINE_SIMPLE_CONVERSION_FUNCTIONS(ModuleProvider, LLVMModuleProviderRef)
808 DEFINE_SIMPLE_CONVERSION_FUNCTIONS(MemoryBuffer, LLVMMemoryBufferRef )
Gordon Henriksen878114b2008-03-16 04:20:44 +0000809 DEFINE_STDCXX_CONVERSION_FUNCTIONS(PassManagerBase, LLVMPassManagerRef )
Gordon Henriksen7330acd2007-10-05 23:59:36 +0000810
Gordon Henriksen878114b2008-03-16 04:20:44 +0000811 #undef DEFINE_STDCXX_CONVERSION_FUNCTIONS
812 #undef DEFINE_ISA_CONVERSION_FUNCTIONS
Gordon Henriksen34eb6d82007-12-19 22:30:40 +0000813 #undef DEFINE_SIMPLE_CONVERSION_FUNCTIONS
Gordon Henriksen7330acd2007-10-05 23:59:36 +0000814
Gordon Henriksen34eb6d82007-12-19 22:30:40 +0000815 /* Specialized opaque type conversions.
816 */
Gordon Henriksen7330acd2007-10-05 23:59:36 +0000817 inline Type **unwrap(LLVMTypeRef* Tys) {
818 return reinterpret_cast<Type**>(Tys);
819 }
820
Gordon Henriksen7330acd2007-10-05 23:59:36 +0000821 inline LLVMTypeRef *wrap(const Type **Tys) {
822 return reinterpret_cast<LLVMTypeRef*>(const_cast<Type**>(Tys));
823 }
824
Gordon Henriksen34eb6d82007-12-19 22:30:40 +0000825 /* Specialized opaque value conversions.
Gordon Henriksen7330acd2007-10-05 23:59:36 +0000826 */
Gordon Henriksen7330acd2007-10-05 23:59:36 +0000827 inline Value **unwrap(LLVMValueRef *Vals) {
828 return reinterpret_cast<Value**>(Vals);
829 }
830
831 template<typename T>
832 inline T **unwrap(LLVMValueRef *Vals, unsigned Length) {
833 #if DEBUG
834 for (LLVMValueRef *I = Vals, E = Vals + Length; I != E; ++I)
835 cast<T>(*I);
836 #endif
837 return reinterpret_cast<T**>(Vals);
838 }
839
Gordon Henriksen7330acd2007-10-05 23:59:36 +0000840 inline LLVMValueRef *wrap(const Value **Vals) {
841 return reinterpret_cast<LLVMValueRef*>(const_cast<Value**>(Vals));
842 }
Gordon Henriksen7330acd2007-10-05 23:59:36 +0000843}
844
845#endif /* !defined(__cplusplus) */
846
847#endif /* !defined(LLVM_C_CORE_H) */