1 /*===-- llvm-c/Core.h - Core Library C Interface ------------------*- C -*-===*\
3 |* The LLVM Compiler Infrastructure *|
5 |* This file is distributed under the University of Illinois Open Source *|
6 |* License. See LICENSE.TXT for details. *|
8 |*===----------------------------------------------------------------------===*|
10 |* This header declares the C interface to libLLVMCore.a, which implements *|
11 |* the LLVM intermediate representation. *|
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). *|
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. *|
26 |* 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. *|
31 \*===----------------------------------------------------------------------===*/
38 /* Need these includes to support the LLVM 'cast' template for the C++ 'wrap'
39 and 'unwrap' conversion functions. */
40 #include "llvm/Module.h"
41 #include "llvm/Support/LLVMBuilder.h"
50 * The top-level container for all other LLVM Intermediate Representation (IR)
51 * objects. See the llvm::Module class.
53 typedef struct LLVMOpaqueModule *LLVMModuleRef;
56 * Each value in the LLVM IR has a type, an LLVMTypeRef. See the llvm::Type
59 typedef struct LLVMOpaqueType *LLVMTypeRef;
62 * When building recursive types using LLVMRefineType, LLVMTypeRef values may
63 * become invalid; use LLVMTypeHandleRef to resolve this problem. See the
64 * llvm::AbstractTypeHolder class.
66 typedef struct LLVMOpaqueTypeHandle *LLVMTypeHandleRef;
68 typedef struct LLVMOpaqueValue *LLVMValueRef;
69 typedef struct LLVMOpaqueBasicBlock *LLVMBasicBlockRef;
70 typedef struct LLVMOpaqueBuilder *LLVMBuilderRef;
72 /* Used to provide a module to JIT or interpreter.
73 * See the llvm::ModuleProvider class.
75 typedef struct LLVMOpaqueModuleProvider *LLVMModuleProviderRef;
77 /* Used to provide a module to JIT or interpreter.
78 * See the llvm::MemoryBuffer class.
80 typedef struct LLVMOpaqueMemoryBuffer *LLVMMemoryBufferRef;
82 /** See the llvm::PassManagerBase class. */
83 typedef struct LLVMOpaquePassManager *LLVMPassManagerRef;
86 LLVMVoidTypeKind, /**< type with no size */
87 LLVMFloatTypeKind, /**< 32 bit floating point type */
88 LLVMDoubleTypeKind, /**< 64 bit floating point type */
89 LLVMX86_FP80TypeKind, /**< 80 bit floating point type (X87) */
90 LLVMFP128TypeKind, /**< 128 bit floating point type (112-bit mantissa)*/
91 LLVMPPC_FP128TypeKind, /**< 128 bit floating point type (two 64-bits) */
92 LLVMLabelTypeKind, /**< Labels */
93 LLVMIntegerTypeKind, /**< Arbitrary bit width integers */
94 LLVMFunctionTypeKind, /**< Functions */
95 LLVMStructTypeKind, /**< Structures */
96 LLVMArrayTypeKind, /**< Arrays */
97 LLVMPointerTypeKind, /**< Pointers */
98 LLVMOpaqueTypeKind, /**< Opaque: type with unknown structure */
99 LLVMVectorTypeKind /**< SIMD 'packed' format, or other vector type */
103 LLVMExternalLinkage, /**< Externally visible function */
104 LLVMLinkOnceLinkage, /**< Keep one copy of function when linking (inline)*/
105 LLVMWeakLinkage, /**< Keep one copy of function when linking (weak) */
106 LLVMAppendingLinkage, /**< Special purpose, only applies to global arrays */
107 LLVMInternalLinkage, /**< Rename collisions when linking (static
109 LLVMDLLImportLinkage, /**< Function to be imported from DLL */
110 LLVMDLLExportLinkage, /**< Function to be accessible from DLL */
111 LLVMExternalWeakLinkage,/**< ExternalWeak linkage description */
112 LLVMGhostLinkage /**< Stand-in functions for streaming fns from
117 LLVMDefaultVisibility, /**< The GV is visible */
118 LLVMHiddenVisibility, /**< The GV is hidden */
119 LLVMProtectedVisibility /**< The GV is protected */
124 LLVMFastCallConv = 8,
125 LLVMColdCallConv = 9,
126 LLVMX86StdcallCallConv = 64,
127 LLVMX86FastcallCallConv = 65
131 LLVMIntEQ = 32, /**< equal */
132 LLVMIntNE, /**< not equal */
133 LLVMIntUGT, /**< unsigned greater than */
134 LLVMIntUGE, /**< unsigned greater or equal */
135 LLVMIntULT, /**< unsigned less than */
136 LLVMIntULE, /**< unsigned less or equal */
137 LLVMIntSGT, /**< signed greater than */
138 LLVMIntSGE, /**< signed greater or equal */
139 LLVMIntSLT, /**< signed less than */
140 LLVMIntSLE /**< signed less or equal */
144 LLVMRealPredicateFalse, /**< Always false (always folded) */
145 LLVMRealOEQ, /**< True if ordered and equal */
146 LLVMRealOGT, /**< True if ordered and greater than */
147 LLVMRealOGE, /**< True if ordered and greater than or equal */
148 LLVMRealOLT, /**< True if ordered and less than */
149 LLVMRealOLE, /**< True if ordered and less than or equal */
150 LLVMRealONE, /**< True if ordered and operands are unequal */
151 LLVMRealORD, /**< True if ordered (no nans) */
152 LLVMRealUNO, /**< True if unordered: isnan(X) | isnan(Y) */
153 LLVMRealUEQ, /**< True if unordered or equal */
154 LLVMRealUGT, /**< True if unordered or greater than */
155 LLVMRealUGE, /**< True if unordered, greater than, or equal */
156 LLVMRealULT, /**< True if unordered or less than */
157 LLVMRealULE, /**< True if unordered, less than, or equal */
158 LLVMRealUNE, /**< True if unordered or not equal */
159 LLVMRealPredicateTrue /**< Always true (always folded) */
163 /*===-- Error handling ----------------------------------------------------===*/
165 void LLVMDisposeMessage(char *Message);
168 /*===-- Modules -----------------------------------------------------------===*/
170 /* Create and destroy modules. */
171 /** See llvm::Module::Module. */
172 LLVMModuleRef LLVMModuleCreateWithName(const char *ModuleID);
174 /** See llvm::Module::~Module. */
175 void LLVMDisposeModule(LLVMModuleRef M);
177 /** Data layout. See Module::getDataLayout. */
178 const char *LLVMGetDataLayout(LLVMModuleRef M);
179 void LLVMSetDataLayout(LLVMModuleRef M, const char *Triple);
181 /** Target triple. See Module::getTargetTriple. */
182 const char *LLVMGetTarget(LLVMModuleRef M);
183 void LLVMSetTarget(LLVMModuleRef M, const char *Triple);
185 /** See Module::addTypeName. */
186 int LLVMAddTypeName(LLVMModuleRef M, const char *Name, LLVMTypeRef Ty);
187 void LLVMDeleteTypeName(LLVMModuleRef M, const char *Name);
189 /** See Module::dump. */
190 void LLVMDumpModule(LLVMModuleRef M);
193 /*===-- Types -------------------------------------------------------------===*/
195 /* LLVM types conform to the following hierarchy:
210 /** See llvm::LLVMTypeKind::getTypeID. */
211 LLVMTypeKind LLVMGetTypeKind(LLVMTypeRef Ty);
213 /** See llvm::DerivedType::refineAbstractTypeTo. */
214 void LLVMRefineAbstractType(LLVMTypeRef AbstractType, LLVMTypeRef ConcreteType);
216 /* Operations on integer types */
217 LLVMTypeRef LLVMInt1Type();
218 LLVMTypeRef LLVMInt8Type();
219 LLVMTypeRef LLVMInt16Type();
220 LLVMTypeRef LLVMInt32Type();
221 LLVMTypeRef LLVMInt64Type();
222 LLVMTypeRef LLVMIntType(unsigned NumBits);
223 unsigned LLVMGetIntTypeWidth(LLVMTypeRef IntegerTy);
225 /* Operations on real types */
226 LLVMTypeRef LLVMFloatType();
227 LLVMTypeRef LLVMDoubleType();
228 LLVMTypeRef LLVMX86FP80Type();
229 LLVMTypeRef LLVMFP128Type();
230 LLVMTypeRef LLVMPPCFP128Type();
232 /* Operations on function types */
233 LLVMTypeRef LLVMFunctionType(LLVMTypeRef ReturnType,
234 LLVMTypeRef *ParamTypes, unsigned ParamCount,
236 int LLVMIsFunctionVarArg(LLVMTypeRef FunctionTy);
237 LLVMTypeRef LLVMGetReturnType(LLVMTypeRef FunctionTy);
238 unsigned LLVMCountParamTypes(LLVMTypeRef FunctionTy);
239 void LLVMGetParamTypes(LLVMTypeRef FunctionTy, LLVMTypeRef *Dest);
241 /* Operations on struct types */
242 LLVMTypeRef LLVMStructType(LLVMTypeRef *ElementTypes, unsigned ElementCount,
244 unsigned LLVMCountStructElementTypes(LLVMTypeRef StructTy);
245 void LLVMGetStructElementTypes(LLVMTypeRef StructTy, LLVMTypeRef *Dest);
246 int LLVMIsPackedStruct(LLVMTypeRef StructTy);
248 /* Operations on array, pointer, and vector types (sequence types) */
249 LLVMTypeRef LLVMArrayType(LLVMTypeRef ElementType, unsigned ElementCount);
250 LLVMTypeRef LLVMPointerType(LLVMTypeRef ElementType, unsigned AddressSpace);
251 LLVMTypeRef LLVMVectorType(LLVMTypeRef ElementType, unsigned ElementCount);
253 LLVMTypeRef LLVMGetElementType(LLVMTypeRef Ty);
254 unsigned LLVMGetArrayLength(LLVMTypeRef ArrayTy);
255 unsigned LLVMGetPointerAddressSpace(LLVMTypeRef PointerTy);
256 unsigned LLVMGetVectorSize(LLVMTypeRef VectorTy);
258 /* Operations on other types */
259 LLVMTypeRef LLVMVoidType();
260 LLVMTypeRef LLVMLabelType();
261 LLVMTypeRef LLVMOpaqueType();
263 /* Operations on type handles */
264 LLVMTypeHandleRef LLVMCreateTypeHandle(LLVMTypeRef PotentiallyAbstractTy);
265 void LLVMRefineType(LLVMTypeRef AbstractTy, LLVMTypeRef ConcreteTy);
266 LLVMTypeRef LLVMResolveTypeHandle(LLVMTypeHandleRef TypeHandle);
267 void LLVMDisposeTypeHandle(LLVMTypeHandleRef TypeHandle);
270 /*===-- Values ------------------------------------------------------------===*/
272 /* The bulk of LLVM's object model consists of values, which comprise a very
273 * rich type hierarchy.
286 /* Operations on all values */
287 LLVMTypeRef LLVMTypeOf(LLVMValueRef Val);
288 const char *LLVMGetValueName(LLVMValueRef Val);
289 void LLVMSetValueName(LLVMValueRef Val, const char *Name);
290 void LLVMDumpValue(LLVMValueRef Val);
292 /* Operations on constants of any type */
293 LLVMValueRef LLVMConstNull(LLVMTypeRef Ty); /* all zeroes */
294 LLVMValueRef LLVMConstAllOnes(LLVMTypeRef Ty); /* only for int/vector */
295 LLVMValueRef LLVMGetUndef(LLVMTypeRef Ty);
296 int LLVMIsConstant(LLVMValueRef Val);
297 int LLVMIsNull(LLVMValueRef Val);
298 int LLVMIsUndef(LLVMValueRef Val);
300 /* Operations on scalar constants */
301 LLVMValueRef LLVMConstInt(LLVMTypeRef IntTy, unsigned long long N,
303 LLVMValueRef LLVMConstReal(LLVMTypeRef RealTy, double N);
304 LLVMValueRef LLVMConstRealOfString(LLVMTypeRef RealTy, const char *Text);
306 /* Operations on composite constants */
307 LLVMValueRef LLVMConstString(const char *Str, unsigned Length,
308 int DontNullTerminate);
309 LLVMValueRef LLVMConstArray(LLVMTypeRef ArrayTy,
310 LLVMValueRef *ConstantVals, unsigned Length);
311 LLVMValueRef LLVMConstStruct(LLVMValueRef *ConstantVals, unsigned Count,
313 LLVMValueRef LLVMConstVector(LLVMValueRef *ScalarConstantVals, unsigned Size);
315 /* Constant expressions */
316 LLVMValueRef LLVMSizeOf(LLVMTypeRef Ty);
317 LLVMValueRef LLVMConstNeg(LLVMValueRef ConstantVal);
318 LLVMValueRef LLVMConstNot(LLVMValueRef ConstantVal);
319 LLVMValueRef LLVMConstAdd(LLVMValueRef LHSConstant, LLVMValueRef RHSConstant);
320 LLVMValueRef LLVMConstSub(LLVMValueRef LHSConstant, LLVMValueRef RHSConstant);
321 LLVMValueRef LLVMConstMul(LLVMValueRef LHSConstant, LLVMValueRef RHSConstant);
322 LLVMValueRef LLVMConstUDiv(LLVMValueRef LHSConstant, LLVMValueRef RHSConstant);
323 LLVMValueRef LLVMConstSDiv(LLVMValueRef LHSConstant, LLVMValueRef RHSConstant);
324 LLVMValueRef LLVMConstFDiv(LLVMValueRef LHSConstant, LLVMValueRef RHSConstant);
325 LLVMValueRef LLVMConstURem(LLVMValueRef LHSConstant, LLVMValueRef RHSConstant);
326 LLVMValueRef LLVMConstSRem(LLVMValueRef LHSConstant, LLVMValueRef RHSConstant);
327 LLVMValueRef LLVMConstFRem(LLVMValueRef LHSConstant, LLVMValueRef RHSConstant);
328 LLVMValueRef LLVMConstAnd(LLVMValueRef LHSConstant, LLVMValueRef RHSConstant);
329 LLVMValueRef LLVMConstOr(LLVMValueRef LHSConstant, LLVMValueRef RHSConstant);
330 LLVMValueRef LLVMConstXor(LLVMValueRef LHSConstant, LLVMValueRef RHSConstant);
331 LLVMValueRef LLVMConstICmp(LLVMIntPredicate Predicate,
332 LLVMValueRef LHSConstant, LLVMValueRef RHSConstant);
333 LLVMValueRef LLVMConstFCmp(LLVMRealPredicate Predicate,
334 LLVMValueRef LHSConstant, LLVMValueRef RHSConstant);
335 LLVMValueRef LLVMConstShl(LLVMValueRef LHSConstant, LLVMValueRef RHSConstant);
336 LLVMValueRef LLVMConstLShr(LLVMValueRef LHSConstant, LLVMValueRef RHSConstant);
337 LLVMValueRef LLVMConstAShr(LLVMValueRef LHSConstant, LLVMValueRef RHSConstant);
338 LLVMValueRef LLVMConstGEP(LLVMValueRef ConstantVal,
339 LLVMValueRef *ConstantIndices, unsigned NumIndices);
340 LLVMValueRef LLVMConstTrunc(LLVMValueRef ConstantVal, LLVMTypeRef ToType);
341 LLVMValueRef LLVMConstSExt(LLVMValueRef ConstantVal, LLVMTypeRef ToType);
342 LLVMValueRef LLVMConstZExt(LLVMValueRef ConstantVal, LLVMTypeRef ToType);
343 LLVMValueRef LLVMConstFPTrunc(LLVMValueRef ConstantVal, LLVMTypeRef ToType);
344 LLVMValueRef LLVMConstFPExt(LLVMValueRef ConstantVal, LLVMTypeRef ToType);
345 LLVMValueRef LLVMConstUIToFP(LLVMValueRef ConstantVal, LLVMTypeRef ToType);
346 LLVMValueRef LLVMConstSIToFP(LLVMValueRef ConstantVal, LLVMTypeRef ToType);
347 LLVMValueRef LLVMConstFPToUI(LLVMValueRef ConstantVal, LLVMTypeRef ToType);
348 LLVMValueRef LLVMConstFPToSI(LLVMValueRef ConstantVal, LLVMTypeRef ToType);
349 LLVMValueRef LLVMConstPtrToInt(LLVMValueRef ConstantVal, LLVMTypeRef ToType);
350 LLVMValueRef LLVMConstIntToPtr(LLVMValueRef ConstantVal, LLVMTypeRef ToType);
351 LLVMValueRef LLVMConstBitCast(LLVMValueRef ConstantVal, LLVMTypeRef ToType);
352 LLVMValueRef LLVMConstSelect(LLVMValueRef ConstantCondition,
353 LLVMValueRef ConstantIfTrue,
354 LLVMValueRef ConstantIfFalse);
355 LLVMValueRef LLVMConstExtractElement(LLVMValueRef VectorConstant,
356 LLVMValueRef IndexConstant);
357 LLVMValueRef LLVMConstInsertElement(LLVMValueRef VectorConstant,
358 LLVMValueRef ElementValueConstant,
359 LLVMValueRef IndexConstant);
360 LLVMValueRef LLVMConstShuffleVector(LLVMValueRef VectorAConstant,
361 LLVMValueRef VectorBConstant,
362 LLVMValueRef MaskConstant);
364 /* Operations on global variables, functions, and aliases (globals) */
365 LLVMModuleRef LLVMGetGlobalParent(LLVMValueRef Global);
366 int LLVMIsDeclaration(LLVMValueRef Global);
367 LLVMLinkage LLVMGetLinkage(LLVMValueRef Global);
368 void LLVMSetLinkage(LLVMValueRef Global, LLVMLinkage Linkage);
369 const char *LLVMGetSection(LLVMValueRef Global);
370 void LLVMSetSection(LLVMValueRef Global, const char *Section);
371 LLVMVisibility LLVMGetVisibility(LLVMValueRef Global);
372 void LLVMSetVisibility(LLVMValueRef Global, LLVMVisibility Viz);
373 unsigned LLVMGetAlignment(LLVMValueRef Global);
374 void LLVMSetAlignment(LLVMValueRef Global, unsigned Bytes);
376 /* Operations on global variables */
377 LLVMValueRef LLVMAddGlobal(LLVMModuleRef M, LLVMTypeRef Ty, const char *Name);
378 LLVMValueRef LLVMGetNamedGlobal(LLVMModuleRef M, const char *Name);
379 void LLVMDeleteGlobal(LLVMValueRef GlobalVar);
380 int LLVMHasInitializer(LLVMValueRef GlobalVar);
381 LLVMValueRef LLVMGetInitializer(LLVMValueRef GlobalVar);
382 void LLVMSetInitializer(LLVMValueRef GlobalVar, LLVMValueRef ConstantVal);
383 int LLVMIsThreadLocal(LLVMValueRef GlobalVar);
384 void LLVMSetThreadLocal(LLVMValueRef GlobalVar, int IsThreadLocal);
385 int LLVMIsGlobalConstant(LLVMValueRef GlobalVar);
386 void LLVMSetGlobalConstant(LLVMValueRef GlobalVar, int IsConstant);
388 /* Operations on functions */
389 LLVMValueRef LLVMAddFunction(LLVMModuleRef M, const char *Name,
390 LLVMTypeRef FunctionTy);
391 LLVMValueRef LLVMGetNamedFunction(LLVMModuleRef M, const char *Name);
392 void LLVMDeleteFunction(LLVMValueRef Fn);
393 unsigned LLVMGetIntrinsicID(LLVMValueRef Fn);
394 unsigned LLVMGetFunctionCallConv(LLVMValueRef Fn);
395 void LLVMSetFunctionCallConv(LLVMValueRef Fn, unsigned CC);
396 const char *LLVMGetCollector(LLVMValueRef Fn);
397 void LLVMSetCollector(LLVMValueRef Fn, const char *Coll);
399 /* Operations on parameters */
400 unsigned LLVMCountParams(LLVMValueRef Fn);
401 void LLVMGetParams(LLVMValueRef Fn, LLVMValueRef *Params);
402 LLVMValueRef LLVMGetParam(LLVMValueRef Fn, unsigned Index);
403 LLVMValueRef LLVMGetParamParent(LLVMValueRef Inst);
405 /* Operations on basic blocks */
406 LLVMValueRef LLVMBasicBlockAsValue(LLVMBasicBlockRef Bb);
407 int LLVMValueIsBasicBlock(LLVMValueRef Val);
408 LLVMBasicBlockRef LLVMValueAsBasicBlock(LLVMValueRef Val);
409 LLVMValueRef LLVMGetBasicBlockParent(LLVMValueRef V);
410 unsigned LLVMCountBasicBlocks(LLVMValueRef Fn);
411 void LLVMGetBasicBlocks(LLVMValueRef Fn, LLVMBasicBlockRef *BasicBlocks);
412 LLVMBasicBlockRef LLVMGetEntryBasicBlock(LLVMValueRef Fn);
413 LLVMBasicBlockRef LLVMAppendBasicBlock(LLVMValueRef Fn, const char *Name);
414 LLVMBasicBlockRef LLVMInsertBasicBlock(LLVMBasicBlockRef InsertBeforeBB,
416 void LLVMDeleteBasicBlock(LLVMBasicBlockRef BB);
418 /* Operations on instructions */
419 LLVMBasicBlockRef LLVMGetInstructionParent(LLVMValueRef Inst);
421 /* Operations on call sites */
422 void LLVMSetInstructionCallConv(LLVMValueRef Instr, unsigned CC);
423 unsigned LLVMGetInstructionCallConv(LLVMValueRef Instr);
425 /* Operations on phi nodes */
426 void LLVMAddIncoming(LLVMValueRef PhiNode, LLVMValueRef *IncomingValues,
427 LLVMBasicBlockRef *IncomingBlocks, unsigned Count);
428 unsigned LLVMCountIncoming(LLVMValueRef PhiNode);
429 LLVMValueRef LLVMGetIncomingValue(LLVMValueRef PhiNode, unsigned Index);
430 LLVMBasicBlockRef LLVMGetIncomingBlock(LLVMValueRef PhiNode, unsigned Index);
432 /*===-- Instruction builders ----------------------------------------------===*/
434 /* An instruction builder represents a point within a basic block, and is the
435 * exclusive means of building instructions using the C interface.
438 LLVMBuilderRef LLVMCreateBuilder();
439 void LLVMPositionBuilderBefore(LLVMBuilderRef Builder, LLVMValueRef Instr);
440 void LLVMPositionBuilderAtEnd(LLVMBuilderRef Builder, LLVMBasicBlockRef Block);
441 LLVMBasicBlockRef LLVMGetInsertBlock(LLVMBuilderRef Builder);
442 void LLVMDisposeBuilder(LLVMBuilderRef Builder);
445 LLVMValueRef LLVMBuildRetVoid(LLVMBuilderRef);
446 LLVMValueRef LLVMBuildRet(LLVMBuilderRef, LLVMValueRef V);
447 LLVMValueRef LLVMBuildBr(LLVMBuilderRef, LLVMBasicBlockRef Dest);
448 LLVMValueRef LLVMBuildCondBr(LLVMBuilderRef, LLVMValueRef If,
449 LLVMBasicBlockRef Then, LLVMBasicBlockRef Else);
450 LLVMValueRef LLVMBuildSwitch(LLVMBuilderRef, LLVMValueRef V,
451 LLVMBasicBlockRef Else, unsigned NumCases);
452 LLVMValueRef LLVMBuildInvoke(LLVMBuilderRef, LLVMValueRef Fn,
453 LLVMValueRef *Args, unsigned NumArgs,
454 LLVMBasicBlockRef Then, LLVMBasicBlockRef Catch,
456 LLVMValueRef LLVMBuildUnwind(LLVMBuilderRef);
457 LLVMValueRef LLVMBuildUnreachable(LLVMBuilderRef);
459 /* Add a case to the switch instruction */
460 void LLVMAddCase(LLVMValueRef Switch, LLVMValueRef OnVal,
461 LLVMBasicBlockRef Dest);
464 LLVMValueRef LLVMBuildAdd(LLVMBuilderRef, LLVMValueRef LHS, LLVMValueRef RHS,
466 LLVMValueRef LLVMBuildSub(LLVMBuilderRef, LLVMValueRef LHS, LLVMValueRef RHS,
468 LLVMValueRef LLVMBuildMul(LLVMBuilderRef, LLVMValueRef LHS, LLVMValueRef RHS,
470 LLVMValueRef LLVMBuildUDiv(LLVMBuilderRef, LLVMValueRef LHS, LLVMValueRef RHS,
472 LLVMValueRef LLVMBuildSDiv(LLVMBuilderRef, LLVMValueRef LHS, LLVMValueRef RHS,
474 LLVMValueRef LLVMBuildFDiv(LLVMBuilderRef, LLVMValueRef LHS, LLVMValueRef RHS,
476 LLVMValueRef LLVMBuildURem(LLVMBuilderRef, LLVMValueRef LHS, LLVMValueRef RHS,
478 LLVMValueRef LLVMBuildSRem(LLVMBuilderRef, LLVMValueRef LHS, LLVMValueRef RHS,
480 LLVMValueRef LLVMBuildFRem(LLVMBuilderRef, LLVMValueRef LHS, LLVMValueRef RHS,
482 LLVMValueRef LLVMBuildShl(LLVMBuilderRef, LLVMValueRef LHS, LLVMValueRef RHS,
484 LLVMValueRef LLVMBuildLShr(LLVMBuilderRef, LLVMValueRef LHS, LLVMValueRef RHS,
486 LLVMValueRef LLVMBuildAShr(LLVMBuilderRef, LLVMValueRef LHS, LLVMValueRef RHS,
488 LLVMValueRef LLVMBuildAnd(LLVMBuilderRef, LLVMValueRef LHS, LLVMValueRef RHS,
490 LLVMValueRef LLVMBuildOr(LLVMBuilderRef, LLVMValueRef LHS, LLVMValueRef RHS,
492 LLVMValueRef LLVMBuildXor(LLVMBuilderRef, LLVMValueRef LHS, LLVMValueRef RHS,
494 LLVMValueRef LLVMBuildNeg(LLVMBuilderRef, LLVMValueRef V, const char *Name);
495 LLVMValueRef LLVMBuildNot(LLVMBuilderRef, LLVMValueRef V, const char *Name);
498 LLVMValueRef LLVMBuildMalloc(LLVMBuilderRef, LLVMTypeRef Ty, const char *Name);
499 LLVMValueRef LLVMBuildArrayMalloc(LLVMBuilderRef, LLVMTypeRef Ty,
500 LLVMValueRef Val, const char *Name);
501 LLVMValueRef LLVMBuildAlloca(LLVMBuilderRef, LLVMTypeRef Ty, const char *Name);
502 LLVMValueRef LLVMBuildArrayAlloca(LLVMBuilderRef, LLVMTypeRef Ty,
503 LLVMValueRef Val, const char *Name);
504 LLVMValueRef LLVMBuildFree(LLVMBuilderRef, LLVMValueRef PointerVal);
505 LLVMValueRef LLVMBuildLoad(LLVMBuilderRef, LLVMValueRef PointerVal,
507 LLVMValueRef LLVMBuildStore(LLVMBuilderRef, LLVMValueRef Val, LLVMValueRef Ptr);
508 LLVMValueRef LLVMBuildGEP(LLVMBuilderRef B, LLVMValueRef Pointer,
509 LLVMValueRef *Indices, unsigned NumIndices,
513 LLVMValueRef LLVMBuildTrunc(LLVMBuilderRef, LLVMValueRef Val,
514 LLVMTypeRef DestTy, const char *Name);
515 LLVMValueRef LLVMBuildZExt(LLVMBuilderRef, LLVMValueRef Val,
516 LLVMTypeRef DestTy, const char *Name);
517 LLVMValueRef LLVMBuildSExt(LLVMBuilderRef, LLVMValueRef Val,
518 LLVMTypeRef DestTy, const char *Name);
519 LLVMValueRef LLVMBuildFPToUI(LLVMBuilderRef, LLVMValueRef Val,
520 LLVMTypeRef DestTy, const char *Name);
521 LLVMValueRef LLVMBuildFPToSI(LLVMBuilderRef, LLVMValueRef Val,
522 LLVMTypeRef DestTy, const char *Name);
523 LLVMValueRef LLVMBuildUIToFP(LLVMBuilderRef, LLVMValueRef Val,
524 LLVMTypeRef DestTy, const char *Name);
525 LLVMValueRef LLVMBuildSIToFP(LLVMBuilderRef, LLVMValueRef Val,
526 LLVMTypeRef DestTy, const char *Name);
527 LLVMValueRef LLVMBuildFPTrunc(LLVMBuilderRef, LLVMValueRef Val,
528 LLVMTypeRef DestTy, const char *Name);
529 LLVMValueRef LLVMBuildFPExt(LLVMBuilderRef, LLVMValueRef Val,
530 LLVMTypeRef DestTy, const char *Name);
531 LLVMValueRef LLVMBuildPtrToInt(LLVMBuilderRef, LLVMValueRef Val,
532 LLVMTypeRef DestTy, const char *Name);
533 LLVMValueRef LLVMBuildIntToPtr(LLVMBuilderRef, LLVMValueRef Val,
534 LLVMTypeRef DestTy, const char *Name);
535 LLVMValueRef LLVMBuildBitCast(LLVMBuilderRef, LLVMValueRef Val,
536 LLVMTypeRef DestTy, const char *Name);
539 LLVMValueRef LLVMBuildICmp(LLVMBuilderRef, LLVMIntPredicate Op,
540 LLVMValueRef LHS, LLVMValueRef RHS,
542 LLVMValueRef LLVMBuildFCmp(LLVMBuilderRef, LLVMRealPredicate Op,
543 LLVMValueRef LHS, LLVMValueRef RHS,
546 /* Miscellaneous instructions */
547 LLVMValueRef LLVMBuildPhi(LLVMBuilderRef, LLVMTypeRef Ty, const char *Name);
548 LLVMValueRef LLVMBuildCall(LLVMBuilderRef, LLVMValueRef Fn,
549 LLVMValueRef *Args, unsigned NumArgs,
551 LLVMValueRef LLVMBuildSelect(LLVMBuilderRef, LLVMValueRef If,
552 LLVMValueRef Then, LLVMValueRef Else,
554 LLVMValueRef LLVMBuildVAArg(LLVMBuilderRef, LLVMValueRef List, LLVMTypeRef Ty,
556 LLVMValueRef LLVMBuildExtractElement(LLVMBuilderRef, LLVMValueRef VecVal,
557 LLVMValueRef Index, const char *Name);
558 LLVMValueRef LLVMBuildInsertElement(LLVMBuilderRef, LLVMValueRef VecVal,
559 LLVMValueRef EltVal, LLVMValueRef Index,
561 LLVMValueRef LLVMBuildShuffleVector(LLVMBuilderRef, LLVMValueRef V1,
562 LLVMValueRef V2, LLVMValueRef Mask,
566 /*===-- Module providers --------------------------------------------------===*/
568 /* Encapsulates the module M in a module provider, taking ownership of the
570 * See the constructor llvm::ExistingModuleProvider::ExistingModuleProvider.
572 LLVMModuleProviderRef
573 LLVMCreateModuleProviderForExistingModule(LLVMModuleRef M);
575 /* Destroys the module provider MP as well as the contained module.
576 * See the destructor llvm::ModuleProvider::~ModuleProvider.
578 void LLVMDisposeModuleProvider(LLVMModuleProviderRef MP);
581 /*===-- Memory buffers ----------------------------------------------------===*/
583 int LLVMCreateMemoryBufferWithContentsOfFile(const char *Path,
584 LLVMMemoryBufferRef *OutMemBuf,
586 int LLVMCreateMemoryBufferWithSTDIN(LLVMMemoryBufferRef *OutMemBuf,
588 void LLVMDisposeMemoryBuffer(LLVMMemoryBufferRef MemBuf);
591 /*===-- Pass Managers -----------------------------------------------------===*/
593 /** Constructs a new whole-module pass pipeline. This type of pipeline is
594 suitable for link-time optimization and whole-module transformations.
595 See llvm::PassManager::PassManager. */
596 LLVMPassManagerRef LLVMCreatePassManager();
598 /** Constructs a new function-by-function pass pipeline over the module
599 provider. It does not take ownership of the module provider. This type of
600 pipeline is suitable for code generation and JIT compilation tasks.
601 See llvm::FunctionPassManager::FunctionPassManager. */
602 LLVMPassManagerRef LLVMCreateFunctionPassManager(LLVMModuleProviderRef MP);
604 /** Initializes, executes on the provided module, and finalizes all of the
605 passes scheduled in the pass manager. Returns 1 if any of the passes
606 modified the module, 0 otherwise. See llvm::PassManager::run(Module&). */
607 int LLVMRunPassManager(LLVMPassManagerRef PM, LLVMModuleRef M);
609 /** Initializes all of the function passes scheduled in the function pass
610 manager. Returns 1 if any of the passes modified the module, 0 otherwise.
611 See llvm::FunctionPassManager::doInitialization. */
612 int LLVMInitializeFunctionPassManager(LLVMPassManagerRef FPM);
614 /** Executes all of the function passes scheduled in the function pass manager
615 on the provided function. Returns 1 if any of the passes modified the
616 function, false otherwise.
617 See llvm::FunctionPassManager::run(Function&). */
618 int LLVMRunFunctionPassManager(LLVMPassManagerRef FPM, LLVMValueRef F);
620 /** Finalizes all of the function passes scheduled in in the function pass
621 manager. Returns 1 if any of the passes modified the module, 0 otherwise.
622 See llvm::FunctionPassManager::doFinalization. */
623 int LLVMFinalizeFunctionPassManager(LLVMPassManagerRef FPM);
625 /** Frees the memory of a pass pipeline. For function pipelines, does not free
627 See llvm::PassManagerBase::~PassManagerBase. */
628 void LLVMDisposePassManager(LLVMPassManagerRef PM);
635 class ModuleProvider;
637 class PassManagerBase;
639 #define DEFINE_SIMPLE_CONVERSION_FUNCTIONS(ty, ref) \
640 inline ty *unwrap(ref P) { \
641 return reinterpret_cast<ty*>(P); \
644 inline ref wrap(const ty *P) { \
645 return reinterpret_cast<ref>(const_cast<ty*>(P)); \
648 #define DEFINE_ISA_CONVERSION_FUNCTIONS(ty, ref) \
649 DEFINE_SIMPLE_CONVERSION_FUNCTIONS(ty, ref) \
651 template<typename T> \
652 inline T *unwrap(ref P) { \
653 return cast<T>(unwrap(P)); \
656 #define DEFINE_STDCXX_CONVERSION_FUNCTIONS(ty, ref) \
657 DEFINE_SIMPLE_CONVERSION_FUNCTIONS(ty, ref) \
659 template<typename T> \
660 inline T *unwrap(ref P) { \
661 T *Q = dynamic_cast<T*>(unwrap(P)); \
662 assert(Q && "Invalid cast!"); \
666 DEFINE_ISA_CONVERSION_FUNCTIONS (Type, LLVMTypeRef )
667 DEFINE_ISA_CONVERSION_FUNCTIONS (Value, LLVMValueRef )
668 DEFINE_SIMPLE_CONVERSION_FUNCTIONS(Module, LLVMModuleRef )
669 DEFINE_SIMPLE_CONVERSION_FUNCTIONS(BasicBlock, LLVMBasicBlockRef )
670 DEFINE_SIMPLE_CONVERSION_FUNCTIONS(LLVMFoldingBuilder, LLVMBuilderRef )
671 DEFINE_SIMPLE_CONVERSION_FUNCTIONS(PATypeHolder, LLVMTypeHandleRef )
672 DEFINE_SIMPLE_CONVERSION_FUNCTIONS(ModuleProvider, LLVMModuleProviderRef)
673 DEFINE_SIMPLE_CONVERSION_FUNCTIONS(MemoryBuffer, LLVMMemoryBufferRef )
674 DEFINE_STDCXX_CONVERSION_FUNCTIONS(PassManagerBase, LLVMPassManagerRef )
676 #undef DEFINE_STDCXX_CONVERSION_FUNCTIONS
677 #undef DEFINE_ISA_CONVERSION_FUNCTIONS
678 #undef DEFINE_SIMPLE_CONVERSION_FUNCTIONS
680 /* Specialized opaque type conversions.
682 inline Type **unwrap(LLVMTypeRef* Tys) {
683 return reinterpret_cast<Type**>(Tys);
686 inline LLVMTypeRef *wrap(const Type **Tys) {
687 return reinterpret_cast<LLVMTypeRef*>(const_cast<Type**>(Tys));
690 /* Specialized opaque value conversions.
692 inline Value **unwrap(LLVMValueRef *Vals) {
693 return reinterpret_cast<Value**>(Vals);
697 inline T **unwrap(LLVMValueRef *Vals, unsigned Length) {
699 for (LLVMValueRef *I = Vals, E = Vals + Length; I != E; ++I)
702 return reinterpret_cast<T**>(Vals);
705 inline LLVMValueRef *wrap(const Value **Vals) {
706 return reinterpret_cast<LLVMValueRef*>(const_cast<Value**>(Vals));
710 #endif /* !defined(__cplusplus) */
712 #endif /* !defined(LLVM_C_CORE_H) */