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,
102 LLVMNoInlineAttribute = 1<<11,
103 LLVMAlwaysInlineAttribute = 1<<12,
104 LLVMOptimizeForSizeAttribute = 1<<13,
105 LLVMStackProtectAttribute = 1<<14,
106 LLVMStackProtectReqAttribute = 1<<15,
107 LLVMNoCaptureAttribute = 1<<21,
108 LLVMNoRedZoneAttribute = 1<<22,
109 LLVMNoImplicitFloatAttribute = 1<<23,
110 LLVMNakedAttribute = 1<<24
114 LLVMVoidTypeKind, /**< type with no size */
115 LLVMFloatTypeKind, /**< 32 bit floating point type */
116 LLVMDoubleTypeKind, /**< 64 bit floating point type */
117 LLVMX86_FP80TypeKind, /**< 80 bit floating point type (X87) */
118 LLVMFP128TypeKind, /**< 128 bit floating point type (112-bit mantissa)*/
119 LLVMPPC_FP128TypeKind, /**< 128 bit floating point type (two 64-bits) */
120 LLVMLabelTypeKind, /**< Labels */
121 LLVMIntegerTypeKind, /**< Arbitrary bit width integers */
122 LLVMFunctionTypeKind, /**< Functions */
123 LLVMStructTypeKind, /**< Structures */
124 LLVMArrayTypeKind, /**< Arrays */
125 LLVMPointerTypeKind, /**< Pointers */
126 LLVMOpaqueTypeKind, /**< Opaque: type with unknown structure */
127 LLVMVectorTypeKind, /**< SIMD 'packed' format, or other vector type */
128 LLVMMetadataTypeKind /**< Metadata */
132 LLVMExternalLinkage, /**< Externally visible function */
133 LLVMAvailableExternallyLinkage,
134 LLVMLinkOnceAnyLinkage, /**< Keep one copy of function when linking (inline)*/
135 LLVMLinkOnceODRLinkage, /**< Same, but only replaced by something
137 LLVMWeakAnyLinkage, /**< Keep one copy of function when linking (weak) */
138 LLVMWeakODRLinkage, /**< Same, but only replaced by something
140 LLVMAppendingLinkage, /**< Special purpose, only applies to global arrays */
141 LLVMInternalLinkage, /**< Rename collisions when linking (static
143 LLVMPrivateLinkage, /**< Like Internal, but omit from symbol table */
144 LLVMDLLImportLinkage, /**< Function to be imported from DLL */
145 LLVMDLLExportLinkage, /**< Function to be accessible from DLL */
146 LLVMExternalWeakLinkage,/**< ExternalWeak linkage description */
147 LLVMGhostLinkage, /**< Stand-in functions for streaming fns from
149 LLVMCommonLinkage /**< Tentative definitions */
153 LLVMDefaultVisibility, /**< The GV is visible */
154 LLVMHiddenVisibility, /**< The GV is hidden */
155 LLVMProtectedVisibility /**< The GV is protected */
160 LLVMFastCallConv = 8,
161 LLVMColdCallConv = 9,
162 LLVMX86StdcallCallConv = 64,
163 LLVMX86FastcallCallConv = 65
167 LLVMIntEQ = 32, /**< equal */
168 LLVMIntNE, /**< not equal */
169 LLVMIntUGT, /**< unsigned greater than */
170 LLVMIntUGE, /**< unsigned greater or equal */
171 LLVMIntULT, /**< unsigned less than */
172 LLVMIntULE, /**< unsigned less or equal */
173 LLVMIntSGT, /**< signed greater than */
174 LLVMIntSGE, /**< signed greater or equal */
175 LLVMIntSLT, /**< signed less than */
176 LLVMIntSLE /**< signed less or equal */
180 LLVMRealPredicateFalse, /**< Always false (always folded) */
181 LLVMRealOEQ, /**< True if ordered and equal */
182 LLVMRealOGT, /**< True if ordered and greater than */
183 LLVMRealOGE, /**< True if ordered and greater than or equal */
184 LLVMRealOLT, /**< True if ordered and less than */
185 LLVMRealOLE, /**< True if ordered and less than or equal */
186 LLVMRealONE, /**< True if ordered and operands are unequal */
187 LLVMRealORD, /**< True if ordered (no nans) */
188 LLVMRealUNO, /**< True if unordered: isnan(X) | isnan(Y) */
189 LLVMRealUEQ, /**< True if unordered or equal */
190 LLVMRealUGT, /**< True if unordered or greater than */
191 LLVMRealUGE, /**< True if unordered, greater than, or equal */
192 LLVMRealULT, /**< True if unordered or less than */
193 LLVMRealULE, /**< True if unordered, less than, or equal */
194 LLVMRealUNE, /**< True if unordered or not equal */
195 LLVMRealPredicateTrue /**< Always true (always folded) */
199 /*===-- Error handling ----------------------------------------------------===*/
201 void LLVMDisposeMessage(char *Message);
204 /*===-- Modules -----------------------------------------------------------===*/
206 /* Create and destroy contexts. */
207 LLVMContextRef LLVMContextCreate();
208 LLVMContextRef LLVMGetGlobalContext();
209 void LLVMContextDispose(LLVMContextRef C);
211 /* Create and destroy modules. */
212 /** See llvm::Module::Module. */
213 LLVMModuleRef LLVMModuleCreateWithName(const char *ModuleID);
214 LLVMModuleRef LLVMModuleCreateWithNameInContext(const char *ModuleID,
217 /** See llvm::Module::~Module. */
218 void LLVMDisposeModule(LLVMModuleRef M);
220 /** Data layout. See Module::getDataLayout. */
221 const char *LLVMGetDataLayout(LLVMModuleRef M);
222 void LLVMSetDataLayout(LLVMModuleRef M, const char *Triple);
224 /** Target triple. See Module::getTargetTriple. */
225 const char *LLVMGetTarget(LLVMModuleRef M);
226 void LLVMSetTarget(LLVMModuleRef M, const char *Triple);
228 /** See Module::addTypeName. */
229 int LLVMAddTypeName(LLVMModuleRef M, const char *Name, LLVMTypeRef Ty);
230 void LLVMDeleteTypeName(LLVMModuleRef M, const char *Name);
231 LLVMTypeRef LLVMGetTypeByName(LLVMModuleRef M, const char *Name);
233 /** See Module::dump. */
234 void LLVMDumpModule(LLVMModuleRef M);
237 /*===-- Types -------------------------------------------------------------===*/
239 /* LLVM types conform to the following hierarchy:
254 /** See llvm::LLVMTypeKind::getTypeID. */
255 LLVMTypeKind LLVMGetTypeKind(LLVMTypeRef Ty);
257 /* Operations on integer types */
258 LLVMTypeRef LLVMInt1Type(void);
259 LLVMTypeRef LLVMInt8Type(void);
260 LLVMTypeRef LLVMInt16Type(void);
261 LLVMTypeRef LLVMInt32Type(void);
262 LLVMTypeRef LLVMInt64Type(void);
263 LLVMTypeRef LLVMIntType(unsigned NumBits);
264 unsigned LLVMGetIntTypeWidth(LLVMTypeRef IntegerTy);
266 /* Operations on real types */
267 LLVMTypeRef LLVMFloatType(void);
268 LLVMTypeRef LLVMDoubleType(void);
269 LLVMTypeRef LLVMX86FP80Type(void);
270 LLVMTypeRef LLVMFP128Type(void);
271 LLVMTypeRef LLVMPPCFP128Type(void);
273 /* Operations on function types */
274 LLVMTypeRef LLVMFunctionType(LLVMTypeRef ReturnType,
275 LLVMTypeRef *ParamTypes, unsigned ParamCount,
277 int LLVMIsFunctionVarArg(LLVMTypeRef FunctionTy);
278 LLVMTypeRef LLVMGetReturnType(LLVMTypeRef FunctionTy);
279 unsigned LLVMCountParamTypes(LLVMTypeRef FunctionTy);
280 void LLVMGetParamTypes(LLVMTypeRef FunctionTy, LLVMTypeRef *Dest);
282 /* Operations on struct types */
283 LLVMTypeRef LLVMStructType(LLVMTypeRef *ElementTypes, unsigned ElementCount,
285 unsigned LLVMCountStructElementTypes(LLVMTypeRef StructTy);
286 void LLVMGetStructElementTypes(LLVMTypeRef StructTy, LLVMTypeRef *Dest);
287 int LLVMIsPackedStruct(LLVMTypeRef StructTy);
289 /* Operations on array, pointer, and vector types (sequence types) */
290 LLVMTypeRef LLVMArrayType(LLVMTypeRef ElementType, unsigned ElementCount);
291 LLVMTypeRef LLVMPointerType(LLVMTypeRef ElementType, unsigned AddressSpace);
292 LLVMTypeRef LLVMVectorType(LLVMTypeRef ElementType, unsigned ElementCount);
294 LLVMTypeRef LLVMGetElementType(LLVMTypeRef Ty);
295 unsigned LLVMGetArrayLength(LLVMTypeRef ArrayTy);
296 unsigned LLVMGetPointerAddressSpace(LLVMTypeRef PointerTy);
297 unsigned LLVMGetVectorSize(LLVMTypeRef VectorTy);
299 /* Operations on other types */
300 LLVMTypeRef LLVMVoidType(void);
301 LLVMTypeRef LLVMLabelType(void);
302 LLVMTypeRef LLVMOpaqueType(void);
304 /* Operations on type handles */
305 LLVMTypeHandleRef LLVMCreateTypeHandle(LLVMTypeRef PotentiallyAbstractTy);
306 void LLVMRefineType(LLVMTypeRef AbstractTy, LLVMTypeRef ConcreteTy);
307 LLVMTypeRef LLVMResolveTypeHandle(LLVMTypeHandleRef TypeHandle);
308 void LLVMDisposeTypeHandle(LLVMTypeHandleRef TypeHandle);
311 /*===-- Values ------------------------------------------------------------===*/
313 /* The bulk of LLVM's object model consists of values, which comprise a very
314 * rich type hierarchy.
317 #define LLVM_FOR_EACH_VALUE_SUBCLASS(macro) \
323 macro(ConstantAggregateZero) \
324 macro(ConstantArray) \
325 macro(ConstantExpr) \
328 macro(ConstantPointerNull) \
329 macro(ConstantStruct) \
330 macro(ConstantVector) \
334 macro(GlobalVariable) \
337 macro(BinaryOperator) \
339 macro(IntrinsicInst) \
340 macro(DbgInfoIntrinsic) \
341 macro(DbgDeclareInst) \
342 macro(DbgFuncStartInst) \
343 macro(DbgRegionEndInst) \
344 macro(DbgRegionStartInst) \
345 macro(DbgStopPointInst) \
346 macro(EHSelectorInst) \
347 macro(MemIntrinsic) \
354 macro(ExtractElementInst) \
355 macro(GetElementPtrInst) \
356 macro(InsertElementInst) \
357 macro(InsertValueInst) \
360 macro(ShuffleVectorInst) \
362 macro(TerminatorInst) \
367 macro(UnreachableInst) \
369 macro(UnaryInstruction) \
370 macro(AllocationInst) \
379 macro(IntToPtrInst) \
380 macro(PtrToIntInst) \
386 macro(ExtractValueInst) \
391 /* Operations on all values */
392 LLVMTypeRef LLVMTypeOf(LLVMValueRef Val);
393 const char *LLVMGetValueName(LLVMValueRef Val);
394 void LLVMSetValueName(LLVMValueRef Val, const char *Name);
395 void LLVMDumpValue(LLVMValueRef Val);
397 /* Conversion functions. Return the input value if it is an instance of the
398 specified class, otherwise NULL. See llvm::dyn_cast_or_null<>. */
399 #define LLVM_DECLARE_VALUE_CAST(name) \
400 LLVMValueRef LLVMIsA##name(LLVMValueRef Val);
401 LLVM_FOR_EACH_VALUE_SUBCLASS(LLVM_DECLARE_VALUE_CAST)
403 /* Operations on constants of any type */
404 LLVMValueRef LLVMConstNull(LLVMTypeRef Ty); /* all zeroes */
405 LLVMValueRef LLVMConstAllOnes(LLVMTypeRef Ty); /* only for int/vector */
406 LLVMValueRef LLVMGetUndef(LLVMTypeRef Ty);
407 int LLVMIsConstant(LLVMValueRef Val);
408 int LLVMIsNull(LLVMValueRef Val);
409 int LLVMIsUndef(LLVMValueRef Val);
410 LLVMValueRef LLVMConstPointerNull(LLVMTypeRef Ty);
412 /* Operations on scalar constants */
413 LLVMValueRef LLVMConstInt(LLVMTypeRef IntTy, unsigned long long N,
415 LLVMValueRef LLVMConstReal(LLVMTypeRef RealTy, double N);
416 LLVMValueRef LLVMConstRealOfString(LLVMTypeRef RealTy, const char *Text);
418 /* Operations on composite constants */
419 LLVMValueRef LLVMConstString(const char *Str, unsigned Length,
420 int DontNullTerminate);
421 LLVMValueRef LLVMConstArray(LLVMTypeRef ElementTy,
422 LLVMValueRef *ConstantVals, unsigned Length);
423 LLVMValueRef LLVMConstStruct(LLVMValueRef *ConstantVals, unsigned Count,
425 LLVMValueRef LLVMConstVector(LLVMValueRef *ScalarConstantVals, unsigned Size);
427 /* Constant expressions */
428 LLVMValueRef LLVMSizeOf(LLVMTypeRef Ty);
429 LLVMValueRef LLVMConstNeg(LLVMValueRef ConstantVal);
430 LLVMValueRef LLVMConstNot(LLVMValueRef ConstantVal);
431 LLVMValueRef LLVMConstAdd(LLVMValueRef LHSConstant, LLVMValueRef RHSConstant);
432 LLVMValueRef LLVMConstSub(LLVMValueRef LHSConstant, LLVMValueRef RHSConstant);
433 LLVMValueRef LLVMConstMul(LLVMValueRef LHSConstant, LLVMValueRef RHSConstant);
434 LLVMValueRef LLVMConstUDiv(LLVMValueRef LHSConstant, LLVMValueRef RHSConstant);
435 LLVMValueRef LLVMConstSDiv(LLVMValueRef LHSConstant, LLVMValueRef RHSConstant);
436 LLVMValueRef LLVMConstFDiv(LLVMValueRef LHSConstant, LLVMValueRef RHSConstant);
437 LLVMValueRef LLVMConstURem(LLVMValueRef LHSConstant, LLVMValueRef RHSConstant);
438 LLVMValueRef LLVMConstSRem(LLVMValueRef LHSConstant, LLVMValueRef RHSConstant);
439 LLVMValueRef LLVMConstFRem(LLVMValueRef LHSConstant, LLVMValueRef RHSConstant);
440 LLVMValueRef LLVMConstAnd(LLVMValueRef LHSConstant, LLVMValueRef RHSConstant);
441 LLVMValueRef LLVMConstOr(LLVMValueRef LHSConstant, LLVMValueRef RHSConstant);
442 LLVMValueRef LLVMConstXor(LLVMValueRef LHSConstant, LLVMValueRef RHSConstant);
443 LLVMValueRef LLVMConstICmp(LLVMIntPredicate Predicate,
444 LLVMValueRef LHSConstant, LLVMValueRef RHSConstant);
445 LLVMValueRef LLVMConstFCmp(LLVMRealPredicate Predicate,
446 LLVMValueRef LHSConstant, LLVMValueRef RHSConstant);
447 LLVMValueRef LLVMConstShl(LLVMValueRef LHSConstant, LLVMValueRef RHSConstant);
448 LLVMValueRef LLVMConstLShr(LLVMValueRef LHSConstant, LLVMValueRef RHSConstant);
449 LLVMValueRef LLVMConstAShr(LLVMValueRef LHSConstant, LLVMValueRef RHSConstant);
450 LLVMValueRef LLVMConstGEP(LLVMValueRef ConstantVal,
451 LLVMValueRef *ConstantIndices, unsigned NumIndices);
452 LLVMValueRef LLVMConstTrunc(LLVMValueRef ConstantVal, LLVMTypeRef ToType);
453 LLVMValueRef LLVMConstSExt(LLVMValueRef ConstantVal, LLVMTypeRef ToType);
454 LLVMValueRef LLVMConstZExt(LLVMValueRef ConstantVal, LLVMTypeRef ToType);
455 LLVMValueRef LLVMConstFPTrunc(LLVMValueRef ConstantVal, LLVMTypeRef ToType);
456 LLVMValueRef LLVMConstFPExt(LLVMValueRef ConstantVal, LLVMTypeRef ToType);
457 LLVMValueRef LLVMConstUIToFP(LLVMValueRef ConstantVal, LLVMTypeRef ToType);
458 LLVMValueRef LLVMConstSIToFP(LLVMValueRef ConstantVal, LLVMTypeRef ToType);
459 LLVMValueRef LLVMConstFPToUI(LLVMValueRef ConstantVal, LLVMTypeRef ToType);
460 LLVMValueRef LLVMConstFPToSI(LLVMValueRef ConstantVal, LLVMTypeRef ToType);
461 LLVMValueRef LLVMConstPtrToInt(LLVMValueRef ConstantVal, LLVMTypeRef ToType);
462 LLVMValueRef LLVMConstIntToPtr(LLVMValueRef ConstantVal, LLVMTypeRef ToType);
463 LLVMValueRef LLVMConstBitCast(LLVMValueRef ConstantVal, LLVMTypeRef ToType);
464 LLVMValueRef LLVMConstSelect(LLVMValueRef ConstantCondition,
465 LLVMValueRef ConstantIfTrue,
466 LLVMValueRef ConstantIfFalse);
467 LLVMValueRef LLVMConstExtractElement(LLVMValueRef VectorConstant,
468 LLVMValueRef IndexConstant);
469 LLVMValueRef LLVMConstInsertElement(LLVMValueRef VectorConstant,
470 LLVMValueRef ElementValueConstant,
471 LLVMValueRef IndexConstant);
472 LLVMValueRef LLVMConstShuffleVector(LLVMValueRef VectorAConstant,
473 LLVMValueRef VectorBConstant,
474 LLVMValueRef MaskConstant);
475 LLVMValueRef LLVMConstExtractValue(LLVMValueRef AggConstant, unsigned *IdxList,
477 LLVMValueRef LLVMConstInsertValue(LLVMValueRef AggConstant,
478 LLVMValueRef ElementValueConstant,
479 unsigned *IdxList, unsigned NumIdx);
480 LLVMValueRef LLVMConstInlineAsm(LLVMTypeRef Ty,
481 const char *AsmString, const char *Constraints,
484 /* Operations on global variables, functions, and aliases (globals) */
485 LLVMModuleRef LLVMGetGlobalParent(LLVMValueRef Global);
486 int LLVMIsDeclaration(LLVMValueRef Global);
487 LLVMLinkage LLVMGetLinkage(LLVMValueRef Global);
488 void LLVMSetLinkage(LLVMValueRef Global, LLVMLinkage Linkage);
489 const char *LLVMGetSection(LLVMValueRef Global);
490 void LLVMSetSection(LLVMValueRef Global, const char *Section);
491 LLVMVisibility LLVMGetVisibility(LLVMValueRef Global);
492 void LLVMSetVisibility(LLVMValueRef Global, LLVMVisibility Viz);
493 unsigned LLVMGetAlignment(LLVMValueRef Global);
494 void LLVMSetAlignment(LLVMValueRef Global, unsigned Bytes);
496 /* Operations on global variables */
497 LLVMValueRef LLVMAddGlobal(LLVMModuleRef M, LLVMTypeRef Ty, const char *Name);
498 LLVMValueRef LLVMGetNamedGlobal(LLVMModuleRef M, const char *Name);
499 LLVMValueRef LLVMGetFirstGlobal(LLVMModuleRef M);
500 LLVMValueRef LLVMGetLastGlobal(LLVMModuleRef M);
501 LLVMValueRef LLVMGetNextGlobal(LLVMValueRef GlobalVar);
502 LLVMValueRef LLVMGetPreviousGlobal(LLVMValueRef GlobalVar);
503 void LLVMDeleteGlobal(LLVMValueRef GlobalVar);
504 LLVMValueRef LLVMGetInitializer(LLVMValueRef GlobalVar);
505 void LLVMSetInitializer(LLVMValueRef GlobalVar, LLVMValueRef ConstantVal);
506 int LLVMIsThreadLocal(LLVMValueRef GlobalVar);
507 void LLVMSetThreadLocal(LLVMValueRef GlobalVar, int IsThreadLocal);
508 int LLVMIsGlobalConstant(LLVMValueRef GlobalVar);
509 void LLVMSetGlobalConstant(LLVMValueRef GlobalVar, int IsConstant);
511 /* Operations on aliases */
512 LLVMValueRef LLVMAddAlias(LLVMModuleRef M, LLVMTypeRef Ty, LLVMValueRef Aliasee,
515 /* Operations on functions */
516 LLVMValueRef LLVMAddFunction(LLVMModuleRef M, const char *Name,
517 LLVMTypeRef FunctionTy);
518 LLVMValueRef LLVMGetNamedFunction(LLVMModuleRef M, const char *Name);
519 LLVMValueRef LLVMGetFirstFunction(LLVMModuleRef M);
520 LLVMValueRef LLVMGetLastFunction(LLVMModuleRef M);
521 LLVMValueRef LLVMGetNextFunction(LLVMValueRef Fn);
522 LLVMValueRef LLVMGetPreviousFunction(LLVMValueRef Fn);
523 void LLVMDeleteFunction(LLVMValueRef Fn);
524 unsigned LLVMGetIntrinsicID(LLVMValueRef Fn);
525 unsigned LLVMGetFunctionCallConv(LLVMValueRef Fn);
526 void LLVMSetFunctionCallConv(LLVMValueRef Fn, unsigned CC);
527 const char *LLVMGetGC(LLVMValueRef Fn);
528 void LLVMSetGC(LLVMValueRef Fn, const char *Name);
529 void LLVMAddFunctionAttr(LLVMValueRef Fn, LLVMAttribute PA);
530 void LLVMRemoveFunctionAttr(LLVMValueRef Fn, LLVMAttribute PA);
532 /* Operations on parameters */
533 unsigned LLVMCountParams(LLVMValueRef Fn);
534 void LLVMGetParams(LLVMValueRef Fn, LLVMValueRef *Params);
535 LLVMValueRef LLVMGetParam(LLVMValueRef Fn, unsigned Index);
536 LLVMValueRef LLVMGetParamParent(LLVMValueRef Inst);
537 LLVMValueRef LLVMGetFirstParam(LLVMValueRef Fn);
538 LLVMValueRef LLVMGetLastParam(LLVMValueRef Fn);
539 LLVMValueRef LLVMGetNextParam(LLVMValueRef Arg);
540 LLVMValueRef LLVMGetPreviousParam(LLVMValueRef Arg);
541 void LLVMAddAttribute(LLVMValueRef Arg, LLVMAttribute PA);
542 void LLVMRemoveAttribute(LLVMValueRef Arg, LLVMAttribute PA);
543 void LLVMSetParamAlignment(LLVMValueRef Arg, unsigned align);
545 /* Operations on basic blocks */
546 LLVMValueRef LLVMBasicBlockAsValue(LLVMBasicBlockRef BB);
547 int LLVMValueIsBasicBlock(LLVMValueRef Val);
548 LLVMBasicBlockRef LLVMValueAsBasicBlock(LLVMValueRef Val);
549 LLVMValueRef LLVMGetBasicBlockParent(LLVMBasicBlockRef BB);
550 unsigned LLVMCountBasicBlocks(LLVMValueRef Fn);
551 void LLVMGetBasicBlocks(LLVMValueRef Fn, LLVMBasicBlockRef *BasicBlocks);
552 LLVMBasicBlockRef LLVMGetFirstBasicBlock(LLVMValueRef Fn);
553 LLVMBasicBlockRef LLVMGetLastBasicBlock(LLVMValueRef Fn);
554 LLVMBasicBlockRef LLVMGetNextBasicBlock(LLVMBasicBlockRef BB);
555 LLVMBasicBlockRef LLVMGetPreviousBasicBlock(LLVMBasicBlockRef BB);
556 LLVMBasicBlockRef LLVMGetEntryBasicBlock(LLVMValueRef Fn);
557 LLVMBasicBlockRef LLVMAppendBasicBlock(LLVMValueRef Fn, const char *Name);
558 LLVMBasicBlockRef LLVMInsertBasicBlock(LLVMBasicBlockRef InsertBeforeBB,
560 void LLVMDeleteBasicBlock(LLVMBasicBlockRef BB);
562 /* Operations on instructions */
563 LLVMBasicBlockRef LLVMGetInstructionParent(LLVMValueRef Inst);
564 LLVMValueRef LLVMGetFirstInstruction(LLVMBasicBlockRef BB);
565 LLVMValueRef LLVMGetLastInstruction(LLVMBasicBlockRef BB);
566 LLVMValueRef LLVMGetNextInstruction(LLVMValueRef Inst);
567 LLVMValueRef LLVMGetPreviousInstruction(LLVMValueRef Inst);
569 /* Operations on call sites */
570 void LLVMSetInstructionCallConv(LLVMValueRef Instr, unsigned CC);
571 unsigned LLVMGetInstructionCallConv(LLVMValueRef Instr);
572 void LLVMAddInstrAttribute(LLVMValueRef Instr, unsigned index, LLVMAttribute);
573 void LLVMRemoveInstrAttribute(LLVMValueRef Instr, unsigned index,
575 void LLVMSetInstrParamAlignment(LLVMValueRef Instr, unsigned index,
578 /* Operations on call instructions (only) */
579 int LLVMIsTailCall(LLVMValueRef CallInst);
580 void LLVMSetTailCall(LLVMValueRef CallInst, int IsTailCall);
582 /* Operations on phi nodes */
583 void LLVMAddIncoming(LLVMValueRef PhiNode, LLVMValueRef *IncomingValues,
584 LLVMBasicBlockRef *IncomingBlocks, unsigned Count);
585 unsigned LLVMCountIncoming(LLVMValueRef PhiNode);
586 LLVMValueRef LLVMGetIncomingValue(LLVMValueRef PhiNode, unsigned Index);
587 LLVMBasicBlockRef LLVMGetIncomingBlock(LLVMValueRef PhiNode, unsigned Index);
589 /*===-- Instruction builders ----------------------------------------------===*/
591 /* An instruction builder represents a point within a basic block, and is the
592 * exclusive means of building instructions using the C interface.
595 LLVMBuilderRef LLVMCreateBuilder(void);
596 void LLVMPositionBuilder(LLVMBuilderRef Builder, LLVMBasicBlockRef Block,
598 void LLVMPositionBuilderBefore(LLVMBuilderRef Builder, LLVMValueRef Instr);
599 void LLVMPositionBuilderAtEnd(LLVMBuilderRef Builder, LLVMBasicBlockRef Block);
600 LLVMBasicBlockRef LLVMGetInsertBlock(LLVMBuilderRef Builder);
601 void LLVMClearInsertionPosition(LLVMBuilderRef Builder);
602 void LLVMInsertIntoBuilder(LLVMBuilderRef Builder, LLVMValueRef Instr);
603 void LLVMDisposeBuilder(LLVMBuilderRef Builder);
606 LLVMValueRef LLVMBuildRetVoid(LLVMBuilderRef);
607 LLVMValueRef LLVMBuildRet(LLVMBuilderRef, LLVMValueRef V);
608 LLVMValueRef LLVMBuildBr(LLVMBuilderRef, LLVMBasicBlockRef Dest);
609 LLVMValueRef LLVMBuildCondBr(LLVMBuilderRef, LLVMValueRef If,
610 LLVMBasicBlockRef Then, LLVMBasicBlockRef Else);
611 LLVMValueRef LLVMBuildSwitch(LLVMBuilderRef, LLVMValueRef V,
612 LLVMBasicBlockRef Else, unsigned NumCases);
613 LLVMValueRef LLVMBuildInvoke(LLVMBuilderRef, LLVMValueRef Fn,
614 LLVMValueRef *Args, unsigned NumArgs,
615 LLVMBasicBlockRef Then, LLVMBasicBlockRef Catch,
617 LLVMValueRef LLVMBuildUnwind(LLVMBuilderRef);
618 LLVMValueRef LLVMBuildUnreachable(LLVMBuilderRef);
620 /* Add a case to the switch instruction */
621 void LLVMAddCase(LLVMValueRef Switch, LLVMValueRef OnVal,
622 LLVMBasicBlockRef Dest);
625 LLVMValueRef LLVMBuildAdd(LLVMBuilderRef, LLVMValueRef LHS, LLVMValueRef RHS,
627 LLVMValueRef LLVMBuildSub(LLVMBuilderRef, LLVMValueRef LHS, LLVMValueRef RHS,
629 LLVMValueRef LLVMBuildMul(LLVMBuilderRef, LLVMValueRef LHS, LLVMValueRef RHS,
631 LLVMValueRef LLVMBuildUDiv(LLVMBuilderRef, LLVMValueRef LHS, LLVMValueRef RHS,
633 LLVMValueRef LLVMBuildSDiv(LLVMBuilderRef, LLVMValueRef LHS, LLVMValueRef RHS,
635 LLVMValueRef LLVMBuildFDiv(LLVMBuilderRef, LLVMValueRef LHS, LLVMValueRef RHS,
637 LLVMValueRef LLVMBuildURem(LLVMBuilderRef, LLVMValueRef LHS, LLVMValueRef RHS,
639 LLVMValueRef LLVMBuildSRem(LLVMBuilderRef, LLVMValueRef LHS, LLVMValueRef RHS,
641 LLVMValueRef LLVMBuildFRem(LLVMBuilderRef, LLVMValueRef LHS, LLVMValueRef RHS,
643 LLVMValueRef LLVMBuildShl(LLVMBuilderRef, LLVMValueRef LHS, LLVMValueRef RHS,
645 LLVMValueRef LLVMBuildLShr(LLVMBuilderRef, LLVMValueRef LHS, LLVMValueRef RHS,
647 LLVMValueRef LLVMBuildAShr(LLVMBuilderRef, LLVMValueRef LHS, LLVMValueRef RHS,
649 LLVMValueRef LLVMBuildAnd(LLVMBuilderRef, LLVMValueRef LHS, LLVMValueRef RHS,
651 LLVMValueRef LLVMBuildOr(LLVMBuilderRef, LLVMValueRef LHS, LLVMValueRef RHS,
653 LLVMValueRef LLVMBuildXor(LLVMBuilderRef, LLVMValueRef LHS, LLVMValueRef RHS,
655 LLVMValueRef LLVMBuildNeg(LLVMBuilderRef, LLVMValueRef V, const char *Name);
656 LLVMValueRef LLVMBuildNot(LLVMBuilderRef, LLVMValueRef V, const char *Name);
659 LLVMValueRef LLVMBuildMalloc(LLVMBuilderRef, LLVMTypeRef Ty, const char *Name);
660 LLVMValueRef LLVMBuildArrayMalloc(LLVMBuilderRef, LLVMTypeRef Ty,
661 LLVMValueRef Val, const char *Name);
662 LLVMValueRef LLVMBuildAlloca(LLVMBuilderRef, LLVMTypeRef Ty, const char *Name);
663 LLVMValueRef LLVMBuildArrayAlloca(LLVMBuilderRef, LLVMTypeRef Ty,
664 LLVMValueRef Val, const char *Name);
665 LLVMValueRef LLVMBuildFree(LLVMBuilderRef, LLVMValueRef PointerVal);
666 LLVMValueRef LLVMBuildLoad(LLVMBuilderRef, LLVMValueRef PointerVal,
668 LLVMValueRef LLVMBuildStore(LLVMBuilderRef, LLVMValueRef Val, LLVMValueRef Ptr);
669 LLVMValueRef LLVMBuildGEP(LLVMBuilderRef B, LLVMValueRef Pointer,
670 LLVMValueRef *Indices, unsigned NumIndices,
674 LLVMValueRef LLVMBuildTrunc(LLVMBuilderRef, LLVMValueRef Val,
675 LLVMTypeRef DestTy, const char *Name);
676 LLVMValueRef LLVMBuildZExt(LLVMBuilderRef, LLVMValueRef Val,
677 LLVMTypeRef DestTy, const char *Name);
678 LLVMValueRef LLVMBuildSExt(LLVMBuilderRef, LLVMValueRef Val,
679 LLVMTypeRef DestTy, const char *Name);
680 LLVMValueRef LLVMBuildFPToUI(LLVMBuilderRef, LLVMValueRef Val,
681 LLVMTypeRef DestTy, const char *Name);
682 LLVMValueRef LLVMBuildFPToSI(LLVMBuilderRef, LLVMValueRef Val,
683 LLVMTypeRef DestTy, const char *Name);
684 LLVMValueRef LLVMBuildUIToFP(LLVMBuilderRef, LLVMValueRef Val,
685 LLVMTypeRef DestTy, const char *Name);
686 LLVMValueRef LLVMBuildSIToFP(LLVMBuilderRef, LLVMValueRef Val,
687 LLVMTypeRef DestTy, const char *Name);
688 LLVMValueRef LLVMBuildFPTrunc(LLVMBuilderRef, LLVMValueRef Val,
689 LLVMTypeRef DestTy, const char *Name);
690 LLVMValueRef LLVMBuildFPExt(LLVMBuilderRef, LLVMValueRef Val,
691 LLVMTypeRef DestTy, const char *Name);
692 LLVMValueRef LLVMBuildPtrToInt(LLVMBuilderRef, LLVMValueRef Val,
693 LLVMTypeRef DestTy, const char *Name);
694 LLVMValueRef LLVMBuildIntToPtr(LLVMBuilderRef, LLVMValueRef Val,
695 LLVMTypeRef DestTy, const char *Name);
696 LLVMValueRef LLVMBuildBitCast(LLVMBuilderRef, LLVMValueRef Val,
697 LLVMTypeRef DestTy, const char *Name);
700 LLVMValueRef LLVMBuildICmp(LLVMBuilderRef, LLVMIntPredicate Op,
701 LLVMValueRef LHS, LLVMValueRef RHS,
703 LLVMValueRef LLVMBuildFCmp(LLVMBuilderRef, LLVMRealPredicate Op,
704 LLVMValueRef LHS, LLVMValueRef RHS,
707 /* Miscellaneous instructions */
708 LLVMValueRef LLVMBuildPhi(LLVMBuilderRef, LLVMTypeRef Ty, const char *Name);
709 LLVMValueRef LLVMBuildCall(LLVMBuilderRef, LLVMValueRef Fn,
710 LLVMValueRef *Args, unsigned NumArgs,
712 LLVMValueRef LLVMBuildSelect(LLVMBuilderRef, LLVMValueRef If,
713 LLVMValueRef Then, LLVMValueRef Else,
715 LLVMValueRef LLVMBuildVAArg(LLVMBuilderRef, LLVMValueRef List, LLVMTypeRef Ty,
717 LLVMValueRef LLVMBuildExtractElement(LLVMBuilderRef, LLVMValueRef VecVal,
718 LLVMValueRef Index, const char *Name);
719 LLVMValueRef LLVMBuildInsertElement(LLVMBuilderRef, LLVMValueRef VecVal,
720 LLVMValueRef EltVal, LLVMValueRef Index,
722 LLVMValueRef LLVMBuildShuffleVector(LLVMBuilderRef, LLVMValueRef V1,
723 LLVMValueRef V2, LLVMValueRef Mask,
725 LLVMValueRef LLVMBuildExtractValue(LLVMBuilderRef, LLVMValueRef AggVal,
726 unsigned Index, const char *Name);
727 LLVMValueRef LLVMBuildInsertValue(LLVMBuilderRef, LLVMValueRef AggVal,
728 LLVMValueRef EltVal, unsigned Index,
732 /*===-- Module providers --------------------------------------------------===*/
734 /* Encapsulates the module M in a module provider, taking ownership of the
736 * See the constructor llvm::ExistingModuleProvider::ExistingModuleProvider.
738 LLVMModuleProviderRef
739 LLVMCreateModuleProviderForExistingModule(LLVMModuleRef M);
741 /* Destroys the module provider MP as well as the contained module.
742 * See the destructor llvm::ModuleProvider::~ModuleProvider.
744 void LLVMDisposeModuleProvider(LLVMModuleProviderRef MP);
747 /*===-- Memory buffers ----------------------------------------------------===*/
749 int LLVMCreateMemoryBufferWithContentsOfFile(const char *Path,
750 LLVMMemoryBufferRef *OutMemBuf,
752 int LLVMCreateMemoryBufferWithSTDIN(LLVMMemoryBufferRef *OutMemBuf,
754 void LLVMDisposeMemoryBuffer(LLVMMemoryBufferRef MemBuf);
757 /*===-- Pass Managers -----------------------------------------------------===*/
759 /** Constructs a new whole-module pass pipeline. This type of pipeline is
760 suitable for link-time optimization and whole-module transformations.
761 See llvm::PassManager::PassManager. */
762 LLVMPassManagerRef LLVMCreatePassManager(void);
764 /** Constructs a new function-by-function pass pipeline over the module
765 provider. It does not take ownership of the module provider. This type of
766 pipeline is suitable for code generation and JIT compilation tasks.
767 See llvm::FunctionPassManager::FunctionPassManager. */
768 LLVMPassManagerRef LLVMCreateFunctionPassManager(LLVMModuleProviderRef MP);
770 /** Initializes, executes on the provided module, and finalizes all of the
771 passes scheduled in the pass manager. Returns 1 if any of the passes
772 modified the module, 0 otherwise. See llvm::PassManager::run(Module&). */
773 int LLVMRunPassManager(LLVMPassManagerRef PM, LLVMModuleRef M);
775 /** Initializes all of the function passes scheduled in the function pass
776 manager. Returns 1 if any of the passes modified the module, 0 otherwise.
777 See llvm::FunctionPassManager::doInitialization. */
778 int LLVMInitializeFunctionPassManager(LLVMPassManagerRef FPM);
780 /** Executes all of the function passes scheduled in the function pass manager
781 on the provided function. Returns 1 if any of the passes modified the
782 function, false otherwise.
783 See llvm::FunctionPassManager::run(Function&). */
784 int LLVMRunFunctionPassManager(LLVMPassManagerRef FPM, LLVMValueRef F);
786 /** Finalizes all of the function passes scheduled in in the function pass
787 manager. Returns 1 if any of the passes modified the module, 0 otherwise.
788 See llvm::FunctionPassManager::doFinalization. */
789 int LLVMFinalizeFunctionPassManager(LLVMPassManagerRef FPM);
791 /** Frees the memory of a pass pipeline. For function pipelines, does not free
793 See llvm::PassManagerBase::~PassManagerBase. */
794 void LLVMDisposePassManager(LLVMPassManagerRef PM);
801 class ModuleProvider;
803 class PassManagerBase;
805 #define DEFINE_SIMPLE_CONVERSION_FUNCTIONS(ty, ref) \
806 inline ty *unwrap(ref P) { \
807 return reinterpret_cast<ty*>(P); \
810 inline ref wrap(const ty *P) { \
811 return reinterpret_cast<ref>(const_cast<ty*>(P)); \
814 #define DEFINE_ISA_CONVERSION_FUNCTIONS(ty, ref) \
815 DEFINE_SIMPLE_CONVERSION_FUNCTIONS(ty, ref) \
817 template<typename T> \
818 inline T *unwrap(ref P) { \
819 return cast<T>(unwrap(P)); \
822 #define DEFINE_STDCXX_CONVERSION_FUNCTIONS(ty, ref) \
823 DEFINE_SIMPLE_CONVERSION_FUNCTIONS(ty, ref) \
825 template<typename T> \
826 inline T *unwrap(ref P) { \
827 T *Q = dynamic_cast<T*>(unwrap(P)); \
828 assert(Q && "Invalid cast!"); \
832 DEFINE_ISA_CONVERSION_FUNCTIONS (Type, LLVMTypeRef )
833 DEFINE_ISA_CONVERSION_FUNCTIONS (Value, LLVMValueRef )
834 DEFINE_SIMPLE_CONVERSION_FUNCTIONS(Module, LLVMModuleRef )
835 DEFINE_SIMPLE_CONVERSION_FUNCTIONS(BasicBlock, LLVMBasicBlockRef )
836 DEFINE_SIMPLE_CONVERSION_FUNCTIONS(IRBuilder<>, LLVMBuilderRef )
837 DEFINE_SIMPLE_CONVERSION_FUNCTIONS(PATypeHolder, LLVMTypeHandleRef )
838 DEFINE_SIMPLE_CONVERSION_FUNCTIONS(ModuleProvider, LLVMModuleProviderRef)
839 DEFINE_SIMPLE_CONVERSION_FUNCTIONS(MemoryBuffer, LLVMMemoryBufferRef )
840 DEFINE_SIMPLE_CONVERSION_FUNCTIONS(LLVMContext, LLVMContextRef )
841 DEFINE_STDCXX_CONVERSION_FUNCTIONS(PassManagerBase, LLVMPassManagerRef )
843 #undef DEFINE_STDCXX_CONVERSION_FUNCTIONS
844 #undef DEFINE_ISA_CONVERSION_FUNCTIONS
845 #undef DEFINE_SIMPLE_CONVERSION_FUNCTIONS
847 /* Specialized opaque type conversions.
849 inline Type **unwrap(LLVMTypeRef* Tys) {
850 return reinterpret_cast<Type**>(Tys);
853 inline LLVMTypeRef *wrap(const Type **Tys) {
854 return reinterpret_cast<LLVMTypeRef*>(const_cast<Type**>(Tys));
857 /* Specialized opaque value conversions.
859 inline Value **unwrap(LLVMValueRef *Vals) {
860 return reinterpret_cast<Value**>(Vals);
864 inline T **unwrap(LLVMValueRef *Vals, unsigned Length) {
866 for (LLVMValueRef *I = Vals, *E = Vals + Length; I != E; ++I)
869 return reinterpret_cast<T**>(Vals);
872 inline LLVMValueRef *wrap(const Value **Vals) {
873 return reinterpret_cast<LLVMValueRef*>(const_cast<Value**>(Vals));
877 #endif /* !defined(__cplusplus) */
879 #endif /* !defined(LLVM_C_CORE_H) */