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/IRBuilder.h"
50 * The top-level container for all LLVM global data. See the LLVMContext class.
52 typedef struct LLVMCtxt *LLVMContextRef;
55 * The top-level container for all other LLVM Intermediate Representation (IR)
56 * objects. See the llvm::Module class.
58 typedef struct LLVMOpaqueModule *LLVMModuleRef;
61 * Each value in the LLVM IR has a type, an LLVMTypeRef. See the llvm::Type
64 typedef struct LLVMOpaqueType *LLVMTypeRef;
67 * When building recursive types using LLVMRefineType, LLVMTypeRef values may
68 * become invalid; use LLVMTypeHandleRef to resolve this problem. See the
69 * llvm::AbstractTypeHolder class.
71 typedef struct LLVMOpaqueTypeHandle *LLVMTypeHandleRef;
73 typedef struct LLVMOpaqueValue *LLVMValueRef;
74 typedef struct LLVMOpaqueBasicBlock *LLVMBasicBlockRef;
75 typedef struct LLVMOpaqueBuilder *LLVMBuilderRef;
77 /* Used to provide a module to JIT or interpreter.
78 * See the llvm::ModuleProvider class.
80 typedef struct LLVMOpaqueModuleProvider *LLVMModuleProviderRef;
82 /* Used to provide a module to JIT or interpreter.
83 * See the llvm::MemoryBuffer class.
85 typedef struct LLVMOpaqueMemoryBuffer *LLVMMemoryBufferRef;
87 /** See the llvm::PassManagerBase class. */
88 typedef struct LLVMOpaquePassManager *LLVMPassManagerRef;
91 LLVMZExtAttribute = 1<<0,
92 LLVMSExtAttribute = 1<<1,
93 LLVMNoReturnAttribute = 1<<2,
94 LLVMInRegAttribute = 1<<3,
95 LLVMStructRetAttribute = 1<<4,
96 LLVMNoUnwindAttribute = 1<<5,
97 LLVMNoAliasAttribute = 1<<6,
98 LLVMByValAttribute = 1<<7,
99 LLVMNestAttribute = 1<<8,
100 LLVMReadNoneAttribute = 1<<9,
101 LLVMReadOnlyAttribute = 1<<10
105 LLVMVoidTypeKind, /**< type with no size */
106 LLVMFloatTypeKind, /**< 32 bit floating point type */
107 LLVMDoubleTypeKind, /**< 64 bit floating point type */
108 LLVMX86_FP80TypeKind, /**< 80 bit floating point type (X87) */
109 LLVMFP128TypeKind, /**< 128 bit floating point type (112-bit mantissa)*/
110 LLVMPPC_FP128TypeKind, /**< 128 bit floating point type (two 64-bits) */
111 LLVMLabelTypeKind, /**< Labels */
112 LLVMIntegerTypeKind, /**< Arbitrary bit width integers */
113 LLVMFunctionTypeKind, /**< Functions */
114 LLVMStructTypeKind, /**< Structures */
115 LLVMArrayTypeKind, /**< Arrays */
116 LLVMPointerTypeKind, /**< Pointers */
117 LLVMOpaqueTypeKind, /**< Opaque: type with unknown structure */
118 LLVMVectorTypeKind /**< SIMD 'packed' format, or other vector type */
122 LLVMExternalLinkage, /**< Externally visible function */
123 LLVMAvailableExternallyLinkage,
124 LLVMLinkOnceAnyLinkage, /**< Keep one copy of function when linking (inline)*/
125 LLVMLinkOnceODRLinkage, /**< Same, but only replaced by something
127 LLVMWeakAnyLinkage, /**< Keep one copy of function when linking (weak) */
128 LLVMWeakODRLinkage, /**< Same, but only replaced by something
130 LLVMAppendingLinkage, /**< Special purpose, only applies to global arrays */
131 LLVMInternalLinkage, /**< Rename collisions when linking (static
133 LLVMPrivateLinkage, /**< Like Internal, but omit from symbol table */
134 LLVMDLLImportLinkage, /**< Function to be imported from DLL */
135 LLVMDLLExportLinkage, /**< Function to be accessible from DLL */
136 LLVMExternalWeakLinkage,/**< ExternalWeak linkage description */
137 LLVMGhostLinkage, /**< Stand-in functions for streaming fns from
139 LLVMCommonLinkage /**< Tentative definitions */
143 LLVMDefaultVisibility, /**< The GV is visible */
144 LLVMHiddenVisibility, /**< The GV is hidden */
145 LLVMProtectedVisibility /**< The GV is protected */
150 LLVMFastCallConv = 8,
151 LLVMColdCallConv = 9,
152 LLVMX86StdcallCallConv = 64,
153 LLVMX86FastcallCallConv = 65
157 LLVMIntEQ = 32, /**< equal */
158 LLVMIntNE, /**< not equal */
159 LLVMIntUGT, /**< unsigned greater than */
160 LLVMIntUGE, /**< unsigned greater or equal */
161 LLVMIntULT, /**< unsigned less than */
162 LLVMIntULE, /**< unsigned less or equal */
163 LLVMIntSGT, /**< signed greater than */
164 LLVMIntSGE, /**< signed greater or equal */
165 LLVMIntSLT, /**< signed less than */
166 LLVMIntSLE /**< signed less or equal */
170 LLVMRealPredicateFalse, /**< Always false (always folded) */
171 LLVMRealOEQ, /**< True if ordered and equal */
172 LLVMRealOGT, /**< True if ordered and greater than */
173 LLVMRealOGE, /**< True if ordered and greater than or equal */
174 LLVMRealOLT, /**< True if ordered and less than */
175 LLVMRealOLE, /**< True if ordered and less than or equal */
176 LLVMRealONE, /**< True if ordered and operands are unequal */
177 LLVMRealORD, /**< True if ordered (no nans) */
178 LLVMRealUNO, /**< True if unordered: isnan(X) | isnan(Y) */
179 LLVMRealUEQ, /**< True if unordered or equal */
180 LLVMRealUGT, /**< True if unordered or greater than */
181 LLVMRealUGE, /**< True if unordered, greater than, or equal */
182 LLVMRealULT, /**< True if unordered or less than */
183 LLVMRealULE, /**< True if unordered, less than, or equal */
184 LLVMRealUNE, /**< True if unordered or not equal */
185 LLVMRealPredicateTrue /**< Always true (always folded) */
189 /*===-- Error handling ----------------------------------------------------===*/
191 void LLVMDisposeMessage(char *Message);
194 /*===-- Modules -----------------------------------------------------------===*/
196 /* Create and destroy contexts. */
197 LLVMContextRef LLVMContextCreate();
198 LLVMContextRef LLVMGetGlobalContext();
199 void LLVMContextDispose(LLVMContextRef C);
201 /* Create and destroy modules. */
202 /** See llvm::Module::Module. */
203 LLVMModuleRef LLVMModuleCreateWithName(const char *ModuleID);
204 LLVMModuleRef LLVMModuleCreateWithNameInContext(const char *ModuleID,
207 /** See llvm::Module::~Module. */
208 void LLVMDisposeModule(LLVMModuleRef M);
210 /** Data layout. See Module::getDataLayout. */
211 const char *LLVMGetDataLayout(LLVMModuleRef M);
212 void LLVMSetDataLayout(LLVMModuleRef M, const char *Triple);
214 /** Target triple. See Module::getTargetTriple. */
215 const char *LLVMGetTarget(LLVMModuleRef M);
216 void LLVMSetTarget(LLVMModuleRef M, const char *Triple);
218 /** See Module::addTypeName. */
219 int LLVMAddTypeName(LLVMModuleRef M, const char *Name, LLVMTypeRef Ty);
220 void LLVMDeleteTypeName(LLVMModuleRef M, const char *Name);
222 /** See Module::dump. */
223 void LLVMDumpModule(LLVMModuleRef M);
226 /*===-- Types -------------------------------------------------------------===*/
228 /* LLVM types conform to the following hierarchy:
243 /** See llvm::LLVMTypeKind::getTypeID. */
244 LLVMTypeKind LLVMGetTypeKind(LLVMTypeRef Ty);
246 /* Operations on integer types */
247 LLVMTypeRef LLVMInt1Type(void);
248 LLVMTypeRef LLVMInt8Type(void);
249 LLVMTypeRef LLVMInt16Type(void);
250 LLVMTypeRef LLVMInt32Type(void);
251 LLVMTypeRef LLVMInt64Type(void);
252 LLVMTypeRef LLVMIntType(unsigned NumBits);
253 unsigned LLVMGetIntTypeWidth(LLVMTypeRef IntegerTy);
255 /* Operations on real types */
256 LLVMTypeRef LLVMFloatType(void);
257 LLVMTypeRef LLVMDoubleType(void);
258 LLVMTypeRef LLVMX86FP80Type(void);
259 LLVMTypeRef LLVMFP128Type(void);
260 LLVMTypeRef LLVMPPCFP128Type(void);
262 /* Operations on function types */
263 LLVMTypeRef LLVMFunctionType(LLVMTypeRef ReturnType,
264 LLVMTypeRef *ParamTypes, unsigned ParamCount,
266 int LLVMIsFunctionVarArg(LLVMTypeRef FunctionTy);
267 LLVMTypeRef LLVMGetReturnType(LLVMTypeRef FunctionTy);
268 unsigned LLVMCountParamTypes(LLVMTypeRef FunctionTy);
269 void LLVMGetParamTypes(LLVMTypeRef FunctionTy, LLVMTypeRef *Dest);
271 /* Operations on struct types */
272 LLVMTypeRef LLVMStructType(LLVMTypeRef *ElementTypes, unsigned ElementCount,
274 unsigned LLVMCountStructElementTypes(LLVMTypeRef StructTy);
275 void LLVMGetStructElementTypes(LLVMTypeRef StructTy, LLVMTypeRef *Dest);
276 int LLVMIsPackedStruct(LLVMTypeRef StructTy);
278 /* Operations on array, pointer, and vector types (sequence types) */
279 LLVMTypeRef LLVMArrayType(LLVMTypeRef ElementType, unsigned ElementCount);
280 LLVMTypeRef LLVMPointerType(LLVMTypeRef ElementType, unsigned AddressSpace);
281 LLVMTypeRef LLVMVectorType(LLVMTypeRef ElementType, unsigned ElementCount);
283 LLVMTypeRef LLVMGetElementType(LLVMTypeRef Ty);
284 unsigned LLVMGetArrayLength(LLVMTypeRef ArrayTy);
285 unsigned LLVMGetPointerAddressSpace(LLVMTypeRef PointerTy);
286 unsigned LLVMGetVectorSize(LLVMTypeRef VectorTy);
288 /* Operations on other types */
289 LLVMTypeRef LLVMVoidType(void);
290 LLVMTypeRef LLVMLabelType(void);
291 LLVMTypeRef LLVMOpaqueType(void);
293 /* Operations on type handles */
294 LLVMTypeHandleRef LLVMCreateTypeHandle(LLVMTypeRef PotentiallyAbstractTy);
295 void LLVMRefineType(LLVMTypeRef AbstractTy, LLVMTypeRef ConcreteTy);
296 LLVMTypeRef LLVMResolveTypeHandle(LLVMTypeHandleRef TypeHandle);
297 void LLVMDisposeTypeHandle(LLVMTypeHandleRef TypeHandle);
300 /*===-- Values ------------------------------------------------------------===*/
302 /* The bulk of LLVM's object model consists of values, which comprise a very
303 * rich type hierarchy.
306 #define LLVM_FOR_EACH_VALUE_SUBCLASS(macro) \
312 macro(ConstantAggregateZero) \
313 macro(ConstantArray) \
314 macro(ConstantExpr) \
317 macro(ConstantPointerNull) \
318 macro(ConstantStruct) \
319 macro(ConstantVector) \
323 macro(GlobalVariable) \
326 macro(BinaryOperator) \
328 macro(IntrinsicInst) \
329 macro(DbgInfoIntrinsic) \
330 macro(DbgDeclareInst) \
331 macro(DbgFuncStartInst) \
332 macro(DbgRegionEndInst) \
333 macro(DbgRegionStartInst) \
334 macro(DbgStopPointInst) \
335 macro(EHSelectorInst) \
336 macro(MemIntrinsic) \
345 macro(ExtractElementInst) \
346 macro(GetElementPtrInst) \
347 macro(InsertElementInst) \
348 macro(InsertValueInst) \
351 macro(ShuffleVectorInst) \
353 macro(TerminatorInst) \
358 macro(UnreachableInst) \
360 macro(UnaryInstruction) \
361 macro(AllocationInst) \
370 macro(IntToPtrInst) \
371 macro(PtrToIntInst) \
377 macro(ExtractValueInst) \
382 /* Operations on all values */
383 LLVMTypeRef LLVMTypeOf(LLVMValueRef Val);
384 const char *LLVMGetValueName(LLVMValueRef Val);
385 void LLVMSetValueName(LLVMValueRef Val, const char *Name);
386 void LLVMDumpValue(LLVMValueRef Val);
388 /* Conversion functions. Return the input value if it is an instance of the
389 specified class, otherwise NULL. See llvm::dyn_cast_or_null<>. */
390 #define LLVM_DECLARE_VALUE_CAST(name) \
391 LLVMValueRef LLVMIsA##name(LLVMValueRef Val);
392 LLVM_FOR_EACH_VALUE_SUBCLASS(LLVM_DECLARE_VALUE_CAST)
394 /* Operations on constants of any type */
395 LLVMValueRef LLVMConstNull(LLVMTypeRef Ty); /* all zeroes */
396 LLVMValueRef LLVMConstAllOnes(LLVMTypeRef Ty); /* only for int/vector */
397 LLVMValueRef LLVMGetUndef(LLVMTypeRef Ty);
398 int LLVMIsConstant(LLVMValueRef Val);
399 int LLVMIsNull(LLVMValueRef Val);
400 int LLVMIsUndef(LLVMValueRef Val);
402 /* Operations on scalar constants */
403 LLVMValueRef LLVMConstInt(LLVMTypeRef IntTy, unsigned long long N,
405 LLVMValueRef LLVMConstReal(LLVMTypeRef RealTy, double N);
406 LLVMValueRef LLVMConstRealOfString(LLVMTypeRef RealTy, const char *Text);
408 /* Operations on composite constants */
409 LLVMValueRef LLVMConstString(const char *Str, unsigned Length,
410 int DontNullTerminate);
411 LLVMValueRef LLVMConstArray(LLVMTypeRef ElementTy,
412 LLVMValueRef *ConstantVals, unsigned Length);
413 LLVMValueRef LLVMConstStruct(LLVMValueRef *ConstantVals, unsigned Count,
415 LLVMValueRef LLVMConstVector(LLVMValueRef *ScalarConstantVals, unsigned Size);
417 /* Constant expressions */
418 LLVMValueRef LLVMSizeOf(LLVMTypeRef Ty);
419 LLVMValueRef LLVMConstNeg(LLVMValueRef ConstantVal);
420 LLVMValueRef LLVMConstNot(LLVMValueRef ConstantVal);
421 LLVMValueRef LLVMConstAdd(LLVMValueRef LHSConstant, LLVMValueRef RHSConstant);
422 LLVMValueRef LLVMConstSub(LLVMValueRef LHSConstant, LLVMValueRef RHSConstant);
423 LLVMValueRef LLVMConstMul(LLVMValueRef LHSConstant, LLVMValueRef RHSConstant);
424 LLVMValueRef LLVMConstUDiv(LLVMValueRef LHSConstant, LLVMValueRef RHSConstant);
425 LLVMValueRef LLVMConstSDiv(LLVMValueRef LHSConstant, LLVMValueRef RHSConstant);
426 LLVMValueRef LLVMConstFDiv(LLVMValueRef LHSConstant, LLVMValueRef RHSConstant);
427 LLVMValueRef LLVMConstURem(LLVMValueRef LHSConstant, LLVMValueRef RHSConstant);
428 LLVMValueRef LLVMConstSRem(LLVMValueRef LHSConstant, LLVMValueRef RHSConstant);
429 LLVMValueRef LLVMConstFRem(LLVMValueRef LHSConstant, LLVMValueRef RHSConstant);
430 LLVMValueRef LLVMConstAnd(LLVMValueRef LHSConstant, LLVMValueRef RHSConstant);
431 LLVMValueRef LLVMConstOr(LLVMValueRef LHSConstant, LLVMValueRef RHSConstant);
432 LLVMValueRef LLVMConstXor(LLVMValueRef LHSConstant, LLVMValueRef RHSConstant);
433 LLVMValueRef LLVMConstICmp(LLVMIntPredicate Predicate,
434 LLVMValueRef LHSConstant, LLVMValueRef RHSConstant);
435 LLVMValueRef LLVMConstFCmp(LLVMRealPredicate Predicate,
436 LLVMValueRef LHSConstant, LLVMValueRef RHSConstant);
437 LLVMValueRef LLVMConstShl(LLVMValueRef LHSConstant, LLVMValueRef RHSConstant);
438 LLVMValueRef LLVMConstLShr(LLVMValueRef LHSConstant, LLVMValueRef RHSConstant);
439 LLVMValueRef LLVMConstAShr(LLVMValueRef LHSConstant, LLVMValueRef RHSConstant);
440 LLVMValueRef LLVMConstGEP(LLVMValueRef ConstantVal,
441 LLVMValueRef *ConstantIndices, unsigned NumIndices);
442 LLVMValueRef LLVMConstTrunc(LLVMValueRef ConstantVal, LLVMTypeRef ToType);
443 LLVMValueRef LLVMConstSExt(LLVMValueRef ConstantVal, LLVMTypeRef ToType);
444 LLVMValueRef LLVMConstZExt(LLVMValueRef ConstantVal, LLVMTypeRef ToType);
445 LLVMValueRef LLVMConstFPTrunc(LLVMValueRef ConstantVal, LLVMTypeRef ToType);
446 LLVMValueRef LLVMConstFPExt(LLVMValueRef ConstantVal, LLVMTypeRef ToType);
447 LLVMValueRef LLVMConstUIToFP(LLVMValueRef ConstantVal, LLVMTypeRef ToType);
448 LLVMValueRef LLVMConstSIToFP(LLVMValueRef ConstantVal, LLVMTypeRef ToType);
449 LLVMValueRef LLVMConstFPToUI(LLVMValueRef ConstantVal, LLVMTypeRef ToType);
450 LLVMValueRef LLVMConstFPToSI(LLVMValueRef ConstantVal, LLVMTypeRef ToType);
451 LLVMValueRef LLVMConstPtrToInt(LLVMValueRef ConstantVal, LLVMTypeRef ToType);
452 LLVMValueRef LLVMConstIntToPtr(LLVMValueRef ConstantVal, LLVMTypeRef ToType);
453 LLVMValueRef LLVMConstBitCast(LLVMValueRef ConstantVal, LLVMTypeRef ToType);
454 LLVMValueRef LLVMConstSelect(LLVMValueRef ConstantCondition,
455 LLVMValueRef ConstantIfTrue,
456 LLVMValueRef ConstantIfFalse);
457 LLVMValueRef LLVMConstExtractElement(LLVMValueRef VectorConstant,
458 LLVMValueRef IndexConstant);
459 LLVMValueRef LLVMConstInsertElement(LLVMValueRef VectorConstant,
460 LLVMValueRef ElementValueConstant,
461 LLVMValueRef IndexConstant);
462 LLVMValueRef LLVMConstShuffleVector(LLVMValueRef VectorAConstant,
463 LLVMValueRef VectorBConstant,
464 LLVMValueRef MaskConstant);
465 LLVMValueRef LLVMConstExtractValue(LLVMValueRef AggConstant, unsigned *IdxList,
467 LLVMValueRef LLVMConstInsertValue(LLVMValueRef AggConstant,
468 LLVMValueRef ElementValueConstant,
469 unsigned *IdxList, unsigned NumIdx);
470 LLVMValueRef LLVMConstInlineAsm(LLVMTypeRef Ty,
471 const char *AsmString, const char *Constraints,
474 /* Operations on global variables, functions, and aliases (globals) */
475 LLVMModuleRef LLVMGetGlobalParent(LLVMValueRef Global);
476 int LLVMIsDeclaration(LLVMValueRef Global);
477 LLVMLinkage LLVMGetLinkage(LLVMValueRef Global);
478 void LLVMSetLinkage(LLVMValueRef Global, LLVMLinkage Linkage);
479 const char *LLVMGetSection(LLVMValueRef Global);
480 void LLVMSetSection(LLVMValueRef Global, const char *Section);
481 LLVMVisibility LLVMGetVisibility(LLVMValueRef Global);
482 void LLVMSetVisibility(LLVMValueRef Global, LLVMVisibility Viz);
483 unsigned LLVMGetAlignment(LLVMValueRef Global);
484 void LLVMSetAlignment(LLVMValueRef Global, unsigned Bytes);
486 /* Operations on global variables */
487 LLVMValueRef LLVMAddGlobal(LLVMModuleRef M, LLVMTypeRef Ty, const char *Name);
488 LLVMValueRef LLVMGetNamedGlobal(LLVMModuleRef M, const char *Name);
489 LLVMValueRef LLVMGetFirstGlobal(LLVMModuleRef M);
490 LLVMValueRef LLVMGetLastGlobal(LLVMModuleRef M);
491 LLVMValueRef LLVMGetNextGlobal(LLVMValueRef GlobalVar);
492 LLVMValueRef LLVMGetPreviousGlobal(LLVMValueRef GlobalVar);
493 void LLVMDeleteGlobal(LLVMValueRef GlobalVar);
494 LLVMValueRef LLVMGetInitializer(LLVMValueRef GlobalVar);
495 void LLVMSetInitializer(LLVMValueRef GlobalVar, LLVMValueRef ConstantVal);
496 int LLVMIsThreadLocal(LLVMValueRef GlobalVar);
497 void LLVMSetThreadLocal(LLVMValueRef GlobalVar, int IsThreadLocal);
498 int LLVMIsGlobalConstant(LLVMValueRef GlobalVar);
499 void LLVMSetGlobalConstant(LLVMValueRef GlobalVar, int IsConstant);
501 /* Operations on aliases */
502 LLVMValueRef LLVMAddAlias(LLVMModuleRef M, LLVMTypeRef Ty, LLVMValueRef Aliasee,
505 /* Operations on functions */
506 LLVMValueRef LLVMAddFunction(LLVMModuleRef M, const char *Name,
507 LLVMTypeRef FunctionTy);
508 LLVMValueRef LLVMGetNamedFunction(LLVMModuleRef M, const char *Name);
509 LLVMValueRef LLVMGetFirstFunction(LLVMModuleRef M);
510 LLVMValueRef LLVMGetLastFunction(LLVMModuleRef M);
511 LLVMValueRef LLVMGetNextFunction(LLVMValueRef Fn);
512 LLVMValueRef LLVMGetPreviousFunction(LLVMValueRef Fn);
513 void LLVMDeleteFunction(LLVMValueRef Fn);
514 unsigned LLVMGetIntrinsicID(LLVMValueRef Fn);
515 unsigned LLVMGetFunctionCallConv(LLVMValueRef Fn);
516 void LLVMSetFunctionCallConv(LLVMValueRef Fn, unsigned CC);
517 const char *LLVMGetGC(LLVMValueRef Fn);
518 void LLVMSetGC(LLVMValueRef Fn, const char *Name);
519 void LLVMAddFunctionAttr(LLVMValueRef Fn, LLVMAttribute PA);
520 void LLVMRemoveFunctionAttr(LLVMValueRef Fn, LLVMAttribute PA);
522 /* Operations on parameters */
523 unsigned LLVMCountParams(LLVMValueRef Fn);
524 void LLVMGetParams(LLVMValueRef Fn, LLVMValueRef *Params);
525 LLVMValueRef LLVMGetParam(LLVMValueRef Fn, unsigned Index);
526 LLVMValueRef LLVMGetParamParent(LLVMValueRef Inst);
527 LLVMValueRef LLVMGetFirstParam(LLVMValueRef Fn);
528 LLVMValueRef LLVMGetLastParam(LLVMValueRef Fn);
529 LLVMValueRef LLVMGetNextParam(LLVMValueRef Arg);
530 LLVMValueRef LLVMGetPreviousParam(LLVMValueRef Arg);
531 void LLVMAddAttribute(LLVMValueRef Arg, LLVMAttribute PA);
532 void LLVMRemoveAttribute(LLVMValueRef Arg, LLVMAttribute PA);
533 void LLVMSetParamAlignment(LLVMValueRef Arg, unsigned align);
535 /* Operations on basic blocks */
536 LLVMValueRef LLVMBasicBlockAsValue(LLVMBasicBlockRef BB);
537 int LLVMValueIsBasicBlock(LLVMValueRef Val);
538 LLVMBasicBlockRef LLVMValueAsBasicBlock(LLVMValueRef Val);
539 LLVMValueRef LLVMGetBasicBlockParent(LLVMBasicBlockRef BB);
540 unsigned LLVMCountBasicBlocks(LLVMValueRef Fn);
541 void LLVMGetBasicBlocks(LLVMValueRef Fn, LLVMBasicBlockRef *BasicBlocks);
542 LLVMBasicBlockRef LLVMGetFirstBasicBlock(LLVMValueRef Fn);
543 LLVMBasicBlockRef LLVMGetLastBasicBlock(LLVMValueRef Fn);
544 LLVMBasicBlockRef LLVMGetNextBasicBlock(LLVMBasicBlockRef BB);
545 LLVMBasicBlockRef LLVMGetPreviousBasicBlock(LLVMBasicBlockRef BB);
546 LLVMBasicBlockRef LLVMGetEntryBasicBlock(LLVMValueRef Fn);
547 LLVMBasicBlockRef LLVMAppendBasicBlock(LLVMValueRef Fn, const char *Name);
548 LLVMBasicBlockRef LLVMInsertBasicBlock(LLVMBasicBlockRef InsertBeforeBB,
550 void LLVMDeleteBasicBlock(LLVMBasicBlockRef BB);
552 /* Operations on instructions */
553 LLVMBasicBlockRef LLVMGetInstructionParent(LLVMValueRef Inst);
554 LLVMValueRef LLVMGetFirstInstruction(LLVMBasicBlockRef BB);
555 LLVMValueRef LLVMGetLastInstruction(LLVMBasicBlockRef BB);
556 LLVMValueRef LLVMGetNextInstruction(LLVMValueRef Inst);
557 LLVMValueRef LLVMGetPreviousInstruction(LLVMValueRef Inst);
559 /* Operations on call sites */
560 void LLVMSetInstructionCallConv(LLVMValueRef Instr, unsigned CC);
561 unsigned LLVMGetInstructionCallConv(LLVMValueRef Instr);
562 void LLVMAddInstrAttribute(LLVMValueRef Instr, unsigned index, LLVMAttribute);
563 void LLVMRemoveInstrAttribute(LLVMValueRef Instr, unsigned index,
565 void LLVMSetInstrParamAlignment(LLVMValueRef Instr, unsigned index,
568 /* Operations on call instructions (only) */
569 int LLVMIsTailCall(LLVMValueRef CallInst);
570 void LLVMSetTailCall(LLVMValueRef CallInst, int IsTailCall);
572 /* Operations on phi nodes */
573 void LLVMAddIncoming(LLVMValueRef PhiNode, LLVMValueRef *IncomingValues,
574 LLVMBasicBlockRef *IncomingBlocks, unsigned Count);
575 unsigned LLVMCountIncoming(LLVMValueRef PhiNode);
576 LLVMValueRef LLVMGetIncomingValue(LLVMValueRef PhiNode, unsigned Index);
577 LLVMBasicBlockRef LLVMGetIncomingBlock(LLVMValueRef PhiNode, unsigned Index);
579 /*===-- Instruction builders ----------------------------------------------===*/
581 /* An instruction builder represents a point within a basic block, and is the
582 * exclusive means of building instructions using the C interface.
585 LLVMBuilderRef LLVMCreateBuilder(void);
586 void LLVMPositionBuilder(LLVMBuilderRef Builder, LLVMBasicBlockRef Block,
588 void LLVMPositionBuilderBefore(LLVMBuilderRef Builder, LLVMValueRef Instr);
589 void LLVMPositionBuilderAtEnd(LLVMBuilderRef Builder, LLVMBasicBlockRef Block);
590 LLVMBasicBlockRef LLVMGetInsertBlock(LLVMBuilderRef Builder);
591 void LLVMClearInsertionPosition(LLVMBuilderRef Builder);
592 void LLVMInsertIntoBuilder(LLVMBuilderRef Builder, LLVMValueRef Instr);
593 void LLVMDisposeBuilder(LLVMBuilderRef Builder);
596 LLVMValueRef LLVMBuildRetVoid(LLVMBuilderRef);
597 LLVMValueRef LLVMBuildRet(LLVMBuilderRef, LLVMValueRef V);
598 LLVMValueRef LLVMBuildBr(LLVMBuilderRef, LLVMBasicBlockRef Dest);
599 LLVMValueRef LLVMBuildCondBr(LLVMBuilderRef, LLVMValueRef If,
600 LLVMBasicBlockRef Then, LLVMBasicBlockRef Else);
601 LLVMValueRef LLVMBuildSwitch(LLVMBuilderRef, LLVMValueRef V,
602 LLVMBasicBlockRef Else, unsigned NumCases);
603 LLVMValueRef LLVMBuildInvoke(LLVMBuilderRef, LLVMValueRef Fn,
604 LLVMValueRef *Args, unsigned NumArgs,
605 LLVMBasicBlockRef Then, LLVMBasicBlockRef Catch,
607 LLVMValueRef LLVMBuildUnwind(LLVMBuilderRef);
608 LLVMValueRef LLVMBuildUnreachable(LLVMBuilderRef);
610 /* Add a case to the switch instruction */
611 void LLVMAddCase(LLVMValueRef Switch, LLVMValueRef OnVal,
612 LLVMBasicBlockRef Dest);
615 LLVMValueRef LLVMBuildAdd(LLVMBuilderRef, LLVMValueRef LHS, LLVMValueRef RHS,
617 LLVMValueRef LLVMBuildSub(LLVMBuilderRef, LLVMValueRef LHS, LLVMValueRef RHS,
619 LLVMValueRef LLVMBuildMul(LLVMBuilderRef, LLVMValueRef LHS, LLVMValueRef RHS,
621 LLVMValueRef LLVMBuildUDiv(LLVMBuilderRef, LLVMValueRef LHS, LLVMValueRef RHS,
623 LLVMValueRef LLVMBuildSDiv(LLVMBuilderRef, LLVMValueRef LHS, LLVMValueRef RHS,
625 LLVMValueRef LLVMBuildFDiv(LLVMBuilderRef, LLVMValueRef LHS, LLVMValueRef RHS,
627 LLVMValueRef LLVMBuildURem(LLVMBuilderRef, LLVMValueRef LHS, LLVMValueRef RHS,
629 LLVMValueRef LLVMBuildSRem(LLVMBuilderRef, LLVMValueRef LHS, LLVMValueRef RHS,
631 LLVMValueRef LLVMBuildFRem(LLVMBuilderRef, LLVMValueRef LHS, LLVMValueRef RHS,
633 LLVMValueRef LLVMBuildShl(LLVMBuilderRef, LLVMValueRef LHS, LLVMValueRef RHS,
635 LLVMValueRef LLVMBuildLShr(LLVMBuilderRef, LLVMValueRef LHS, LLVMValueRef RHS,
637 LLVMValueRef LLVMBuildAShr(LLVMBuilderRef, LLVMValueRef LHS, LLVMValueRef RHS,
639 LLVMValueRef LLVMBuildAnd(LLVMBuilderRef, LLVMValueRef LHS, LLVMValueRef RHS,
641 LLVMValueRef LLVMBuildOr(LLVMBuilderRef, LLVMValueRef LHS, LLVMValueRef RHS,
643 LLVMValueRef LLVMBuildXor(LLVMBuilderRef, LLVMValueRef LHS, LLVMValueRef RHS,
645 LLVMValueRef LLVMBuildNeg(LLVMBuilderRef, LLVMValueRef V, const char *Name);
646 LLVMValueRef LLVMBuildNot(LLVMBuilderRef, LLVMValueRef V, const char *Name);
649 LLVMValueRef LLVMBuildMalloc(LLVMBuilderRef, LLVMTypeRef Ty, const char *Name);
650 LLVMValueRef LLVMBuildArrayMalloc(LLVMBuilderRef, LLVMTypeRef Ty,
651 LLVMValueRef Val, const char *Name);
652 LLVMValueRef LLVMBuildAlloca(LLVMBuilderRef, LLVMTypeRef Ty, const char *Name);
653 LLVMValueRef LLVMBuildArrayAlloca(LLVMBuilderRef, LLVMTypeRef Ty,
654 LLVMValueRef Val, const char *Name);
655 LLVMValueRef LLVMBuildFree(LLVMBuilderRef, LLVMValueRef PointerVal);
656 LLVMValueRef LLVMBuildLoad(LLVMBuilderRef, LLVMValueRef PointerVal,
658 LLVMValueRef LLVMBuildStore(LLVMBuilderRef, LLVMValueRef Val, LLVMValueRef Ptr);
659 LLVMValueRef LLVMBuildGEP(LLVMBuilderRef B, LLVMValueRef Pointer,
660 LLVMValueRef *Indices, unsigned NumIndices,
664 LLVMValueRef LLVMBuildTrunc(LLVMBuilderRef, LLVMValueRef Val,
665 LLVMTypeRef DestTy, const char *Name);
666 LLVMValueRef LLVMBuildZExt(LLVMBuilderRef, LLVMValueRef Val,
667 LLVMTypeRef DestTy, const char *Name);
668 LLVMValueRef LLVMBuildSExt(LLVMBuilderRef, LLVMValueRef Val,
669 LLVMTypeRef DestTy, const char *Name);
670 LLVMValueRef LLVMBuildFPToUI(LLVMBuilderRef, LLVMValueRef Val,
671 LLVMTypeRef DestTy, const char *Name);
672 LLVMValueRef LLVMBuildFPToSI(LLVMBuilderRef, LLVMValueRef Val,
673 LLVMTypeRef DestTy, const char *Name);
674 LLVMValueRef LLVMBuildUIToFP(LLVMBuilderRef, LLVMValueRef Val,
675 LLVMTypeRef DestTy, const char *Name);
676 LLVMValueRef LLVMBuildSIToFP(LLVMBuilderRef, LLVMValueRef Val,
677 LLVMTypeRef DestTy, const char *Name);
678 LLVMValueRef LLVMBuildFPTrunc(LLVMBuilderRef, LLVMValueRef Val,
679 LLVMTypeRef DestTy, const char *Name);
680 LLVMValueRef LLVMBuildFPExt(LLVMBuilderRef, LLVMValueRef Val,
681 LLVMTypeRef DestTy, const char *Name);
682 LLVMValueRef LLVMBuildPtrToInt(LLVMBuilderRef, LLVMValueRef Val,
683 LLVMTypeRef DestTy, const char *Name);
684 LLVMValueRef LLVMBuildIntToPtr(LLVMBuilderRef, LLVMValueRef Val,
685 LLVMTypeRef DestTy, const char *Name);
686 LLVMValueRef LLVMBuildBitCast(LLVMBuilderRef, LLVMValueRef Val,
687 LLVMTypeRef DestTy, const char *Name);
690 LLVMValueRef LLVMBuildICmp(LLVMBuilderRef, LLVMIntPredicate Op,
691 LLVMValueRef LHS, LLVMValueRef RHS,
693 LLVMValueRef LLVMBuildFCmp(LLVMBuilderRef, LLVMRealPredicate Op,
694 LLVMValueRef LHS, LLVMValueRef RHS,
697 /* Miscellaneous instructions */
698 LLVMValueRef LLVMBuildPhi(LLVMBuilderRef, LLVMTypeRef Ty, const char *Name);
699 LLVMValueRef LLVMBuildCall(LLVMBuilderRef, LLVMValueRef Fn,
700 LLVMValueRef *Args, unsigned NumArgs,
702 LLVMValueRef LLVMBuildSelect(LLVMBuilderRef, LLVMValueRef If,
703 LLVMValueRef Then, LLVMValueRef Else,
705 LLVMValueRef LLVMBuildVAArg(LLVMBuilderRef, LLVMValueRef List, LLVMTypeRef Ty,
707 LLVMValueRef LLVMBuildExtractElement(LLVMBuilderRef, LLVMValueRef VecVal,
708 LLVMValueRef Index, const char *Name);
709 LLVMValueRef LLVMBuildInsertElement(LLVMBuilderRef, LLVMValueRef VecVal,
710 LLVMValueRef EltVal, LLVMValueRef Index,
712 LLVMValueRef LLVMBuildShuffleVector(LLVMBuilderRef, LLVMValueRef V1,
713 LLVMValueRef V2, LLVMValueRef Mask,
715 LLVMValueRef LLVMBuildExtractValue(LLVMBuilderRef, LLVMValueRef AggVal,
716 unsigned Index, const char *Name);
717 LLVMValueRef LLVMBuildInsertValue(LLVMBuilderRef, LLVMValueRef AggVal,
718 LLVMValueRef EltVal, unsigned Index,
722 /*===-- Module providers --------------------------------------------------===*/
724 /* Encapsulates the module M in a module provider, taking ownership of the
726 * See the constructor llvm::ExistingModuleProvider::ExistingModuleProvider.
728 LLVMModuleProviderRef
729 LLVMCreateModuleProviderForExistingModule(LLVMModuleRef M);
731 /* Destroys the module provider MP as well as the contained module.
732 * See the destructor llvm::ModuleProvider::~ModuleProvider.
734 void LLVMDisposeModuleProvider(LLVMModuleProviderRef MP);
737 /*===-- Memory buffers ----------------------------------------------------===*/
739 int LLVMCreateMemoryBufferWithContentsOfFile(const char *Path,
740 LLVMMemoryBufferRef *OutMemBuf,
742 int LLVMCreateMemoryBufferWithSTDIN(LLVMMemoryBufferRef *OutMemBuf,
744 void LLVMDisposeMemoryBuffer(LLVMMemoryBufferRef MemBuf);
747 /*===-- Pass Managers -----------------------------------------------------===*/
749 /** Constructs a new whole-module pass pipeline. This type of pipeline is
750 suitable for link-time optimization and whole-module transformations.
751 See llvm::PassManager::PassManager. */
752 LLVMPassManagerRef LLVMCreatePassManager(void);
754 /** Constructs a new function-by-function pass pipeline over the module
755 provider. It does not take ownership of the module provider. This type of
756 pipeline is suitable for code generation and JIT compilation tasks.
757 See llvm::FunctionPassManager::FunctionPassManager. */
758 LLVMPassManagerRef LLVMCreateFunctionPassManager(LLVMModuleProviderRef MP);
760 /** Initializes, executes on the provided module, and finalizes all of the
761 passes scheduled in the pass manager. Returns 1 if any of the passes
762 modified the module, 0 otherwise. See llvm::PassManager::run(Module&). */
763 int LLVMRunPassManager(LLVMPassManagerRef PM, LLVMModuleRef M);
765 /** Initializes all of the function passes scheduled in the function pass
766 manager. Returns 1 if any of the passes modified the module, 0 otherwise.
767 See llvm::FunctionPassManager::doInitialization. */
768 int LLVMInitializeFunctionPassManager(LLVMPassManagerRef FPM);
770 /** Executes all of the function passes scheduled in the function pass manager
771 on the provided function. Returns 1 if any of the passes modified the
772 function, false otherwise.
773 See llvm::FunctionPassManager::run(Function&). */
774 int LLVMRunFunctionPassManager(LLVMPassManagerRef FPM, LLVMValueRef F);
776 /** Finalizes all of the function passes scheduled in in the function pass
777 manager. Returns 1 if any of the passes modified the module, 0 otherwise.
778 See llvm::FunctionPassManager::doFinalization. */
779 int LLVMFinalizeFunctionPassManager(LLVMPassManagerRef FPM);
781 /** Frees the memory of a pass pipeline. For function pipelines, does not free
783 See llvm::PassManagerBase::~PassManagerBase. */
784 void LLVMDisposePassManager(LLVMPassManagerRef PM);
791 class ModuleProvider;
793 class PassManagerBase;
795 #define DEFINE_SIMPLE_CONVERSION_FUNCTIONS(ty, ref) \
796 inline ty *unwrap(ref P) { \
797 return reinterpret_cast<ty*>(P); \
800 inline ref wrap(const ty *P) { \
801 return reinterpret_cast<ref>(const_cast<ty*>(P)); \
804 #define DEFINE_ISA_CONVERSION_FUNCTIONS(ty, ref) \
805 DEFINE_SIMPLE_CONVERSION_FUNCTIONS(ty, ref) \
807 template<typename T> \
808 inline T *unwrap(ref P) { \
809 return cast<T>(unwrap(P)); \
812 #define DEFINE_STDCXX_CONVERSION_FUNCTIONS(ty, ref) \
813 DEFINE_SIMPLE_CONVERSION_FUNCTIONS(ty, ref) \
815 template<typename T> \
816 inline T *unwrap(ref P) { \
817 T *Q = dynamic_cast<T*>(unwrap(P)); \
818 assert(Q && "Invalid cast!"); \
822 DEFINE_ISA_CONVERSION_FUNCTIONS (Type, LLVMTypeRef )
823 DEFINE_ISA_CONVERSION_FUNCTIONS (Value, LLVMValueRef )
824 DEFINE_SIMPLE_CONVERSION_FUNCTIONS(Module, LLVMModuleRef )
825 DEFINE_SIMPLE_CONVERSION_FUNCTIONS(BasicBlock, LLVMBasicBlockRef )
826 DEFINE_SIMPLE_CONVERSION_FUNCTIONS(IRBuilder<>, LLVMBuilderRef )
827 DEFINE_SIMPLE_CONVERSION_FUNCTIONS(PATypeHolder, LLVMTypeHandleRef )
828 DEFINE_SIMPLE_CONVERSION_FUNCTIONS(ModuleProvider, LLVMModuleProviderRef)
829 DEFINE_SIMPLE_CONVERSION_FUNCTIONS(MemoryBuffer, LLVMMemoryBufferRef )
830 DEFINE_SIMPLE_CONVERSION_FUNCTIONS(LLVMContext, LLVMContextRef )
831 DEFINE_STDCXX_CONVERSION_FUNCTIONS(PassManagerBase, LLVMPassManagerRef )
833 #undef DEFINE_STDCXX_CONVERSION_FUNCTIONS
834 #undef DEFINE_ISA_CONVERSION_FUNCTIONS
835 #undef DEFINE_SIMPLE_CONVERSION_FUNCTIONS
837 /* Specialized opaque type conversions.
839 inline Type **unwrap(LLVMTypeRef* Tys) {
840 return reinterpret_cast<Type**>(Tys);
843 inline LLVMTypeRef *wrap(const Type **Tys) {
844 return reinterpret_cast<LLVMTypeRef*>(const_cast<Type**>(Tys));
847 /* Specialized opaque value conversions.
849 inline Value **unwrap(LLVMValueRef *Vals) {
850 return reinterpret_cast<Value**>(Vals);
854 inline T **unwrap(LLVMValueRef *Vals, unsigned Length) {
856 for (LLVMValueRef *I = Vals, E = Vals + Length; I != E; ++I)
859 return reinterpret_cast<T**>(Vals);
862 inline LLVMValueRef *wrap(const Value **Vals) {
863 return reinterpret_cast<LLVMValueRef*>(const_cast<Value**>(Vals));
867 #endif /* !defined(__cplusplus) */
869 #endif /* !defined(LLVM_C_CORE_H) */