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 */
150 LLVMLinkerPrivateLinkage /**< Like Private, but linker removes. */
154 LLVMDefaultVisibility, /**< The GV is visible */
155 LLVMHiddenVisibility, /**< The GV is hidden */
156 LLVMProtectedVisibility /**< The GV is protected */
161 LLVMFastCallConv = 8,
162 LLVMColdCallConv = 9,
163 LLVMX86StdcallCallConv = 64,
164 LLVMX86FastcallCallConv = 65
168 LLVMIntEQ = 32, /**< equal */
169 LLVMIntNE, /**< not equal */
170 LLVMIntUGT, /**< unsigned greater than */
171 LLVMIntUGE, /**< unsigned greater or equal */
172 LLVMIntULT, /**< unsigned less than */
173 LLVMIntULE, /**< unsigned less or equal */
174 LLVMIntSGT, /**< signed greater than */
175 LLVMIntSGE, /**< signed greater or equal */
176 LLVMIntSLT, /**< signed less than */
177 LLVMIntSLE /**< signed less or equal */
181 LLVMRealPredicateFalse, /**< Always false (always folded) */
182 LLVMRealOEQ, /**< True if ordered and equal */
183 LLVMRealOGT, /**< True if ordered and greater than */
184 LLVMRealOGE, /**< True if ordered and greater than or equal */
185 LLVMRealOLT, /**< True if ordered and less than */
186 LLVMRealOLE, /**< True if ordered and less than or equal */
187 LLVMRealONE, /**< True if ordered and operands are unequal */
188 LLVMRealORD, /**< True if ordered (no nans) */
189 LLVMRealUNO, /**< True if unordered: isnan(X) | isnan(Y) */
190 LLVMRealUEQ, /**< True if unordered or equal */
191 LLVMRealUGT, /**< True if unordered or greater than */
192 LLVMRealUGE, /**< True if unordered, greater than, or equal */
193 LLVMRealULT, /**< True if unordered or less than */
194 LLVMRealULE, /**< True if unordered, less than, or equal */
195 LLVMRealUNE, /**< True if unordered or not equal */
196 LLVMRealPredicateTrue /**< Always true (always folded) */
200 /*===-- Error handling ----------------------------------------------------===*/
202 void LLVMDisposeMessage(char *Message);
205 /*===-- Modules -----------------------------------------------------------===*/
207 /* Create and destroy contexts. */
208 LLVMContextRef LLVMContextCreate();
209 LLVMContextRef LLVMGetGlobalContext();
210 void LLVMContextDispose(LLVMContextRef C);
212 /* Create and destroy modules. */
213 /** See llvm::Module::Module. */
214 LLVMModuleRef LLVMModuleCreateWithName(const char *ModuleID);
215 LLVMModuleRef LLVMModuleCreateWithNameInContext(const char *ModuleID,
218 /** See llvm::Module::~Module. */
219 void LLVMDisposeModule(LLVMModuleRef M);
221 /** Data layout. See Module::getDataLayout. */
222 const char *LLVMGetDataLayout(LLVMModuleRef M);
223 void LLVMSetDataLayout(LLVMModuleRef M, const char *Triple);
225 /** Target triple. See Module::getTargetTriple. */
226 const char *LLVMGetTarget(LLVMModuleRef M);
227 void LLVMSetTarget(LLVMModuleRef M, const char *Triple);
229 /** See Module::addTypeName. */
230 int LLVMAddTypeName(LLVMModuleRef M, const char *Name, LLVMTypeRef Ty);
231 void LLVMDeleteTypeName(LLVMModuleRef M, const char *Name);
232 LLVMTypeRef LLVMGetTypeByName(LLVMModuleRef M, const char *Name);
234 /** See Module::dump. */
235 void LLVMDumpModule(LLVMModuleRef M);
238 /*===-- Types -------------------------------------------------------------===*/
240 /* LLVM types conform to the following hierarchy:
255 /** See llvm::LLVMTypeKind::getTypeID. */
256 LLVMTypeKind LLVMGetTypeKind(LLVMTypeRef Ty);
258 /* Operations on integer types */
259 LLVMTypeRef LLVMInt1Type(void);
260 LLVMTypeRef LLVMInt8Type(void);
261 LLVMTypeRef LLVMInt16Type(void);
262 LLVMTypeRef LLVMInt32Type(void);
263 LLVMTypeRef LLVMInt64Type(void);
264 LLVMTypeRef LLVMIntType(unsigned NumBits);
265 unsigned LLVMGetIntTypeWidth(LLVMTypeRef IntegerTy);
267 /* Operations on real types */
268 LLVMTypeRef LLVMFloatType(void);
269 LLVMTypeRef LLVMDoubleType(void);
270 LLVMTypeRef LLVMX86FP80Type(void);
271 LLVMTypeRef LLVMFP128Type(void);
272 LLVMTypeRef LLVMPPCFP128Type(void);
274 /* Operations on function types */
275 LLVMTypeRef LLVMFunctionType(LLVMTypeRef ReturnType,
276 LLVMTypeRef *ParamTypes, unsigned ParamCount,
278 int LLVMIsFunctionVarArg(LLVMTypeRef FunctionTy);
279 LLVMTypeRef LLVMGetReturnType(LLVMTypeRef FunctionTy);
280 unsigned LLVMCountParamTypes(LLVMTypeRef FunctionTy);
281 void LLVMGetParamTypes(LLVMTypeRef FunctionTy, LLVMTypeRef *Dest);
283 /* Operations on struct types */
284 LLVMTypeRef LLVMStructType(LLVMTypeRef *ElementTypes, unsigned ElementCount,
286 unsigned LLVMCountStructElementTypes(LLVMTypeRef StructTy);
287 void LLVMGetStructElementTypes(LLVMTypeRef StructTy, LLVMTypeRef *Dest);
288 int LLVMIsPackedStruct(LLVMTypeRef StructTy);
290 /* Operations on array, pointer, and vector types (sequence types) */
291 LLVMTypeRef LLVMArrayType(LLVMTypeRef ElementType, unsigned ElementCount);
292 LLVMTypeRef LLVMPointerType(LLVMTypeRef ElementType, unsigned AddressSpace);
293 LLVMTypeRef LLVMVectorType(LLVMTypeRef ElementType, unsigned ElementCount);
295 LLVMTypeRef LLVMGetElementType(LLVMTypeRef Ty);
296 unsigned LLVMGetArrayLength(LLVMTypeRef ArrayTy);
297 unsigned LLVMGetPointerAddressSpace(LLVMTypeRef PointerTy);
298 unsigned LLVMGetVectorSize(LLVMTypeRef VectorTy);
300 /* Operations on other types */
301 LLVMTypeRef LLVMVoidType(void);
302 LLVMTypeRef LLVMLabelType(void);
303 LLVMTypeRef LLVMOpaqueType(void);
305 /* Operations on type handles */
306 LLVMTypeHandleRef LLVMCreateTypeHandle(LLVMTypeRef PotentiallyAbstractTy);
307 void LLVMRefineType(LLVMTypeRef AbstractTy, LLVMTypeRef ConcreteTy);
308 LLVMTypeRef LLVMResolveTypeHandle(LLVMTypeHandleRef TypeHandle);
309 void LLVMDisposeTypeHandle(LLVMTypeHandleRef TypeHandle);
312 /*===-- Values ------------------------------------------------------------===*/
314 /* The bulk of LLVM's object model consists of values, which comprise a very
315 * rich type hierarchy.
318 #define LLVM_FOR_EACH_VALUE_SUBCLASS(macro) \
324 macro(ConstantAggregateZero) \
325 macro(ConstantArray) \
326 macro(ConstantExpr) \
329 macro(ConstantPointerNull) \
330 macro(ConstantStruct) \
331 macro(ConstantVector) \
335 macro(GlobalVariable) \
338 macro(BinaryOperator) \
340 macro(IntrinsicInst) \
341 macro(DbgInfoIntrinsic) \
342 macro(DbgDeclareInst) \
343 macro(DbgFuncStartInst) \
344 macro(DbgRegionEndInst) \
345 macro(DbgRegionStartInst) \
346 macro(DbgStopPointInst) \
347 macro(EHSelectorInst) \
348 macro(MemIntrinsic) \
355 macro(ExtractElementInst) \
356 macro(GetElementPtrInst) \
357 macro(InsertElementInst) \
358 macro(InsertValueInst) \
361 macro(ShuffleVectorInst) \
363 macro(TerminatorInst) \
368 macro(UnreachableInst) \
370 macro(UnaryInstruction) \
371 macro(AllocationInst) \
380 macro(IntToPtrInst) \
381 macro(PtrToIntInst) \
387 macro(ExtractValueInst) \
392 /* Operations on all values */
393 LLVMTypeRef LLVMTypeOf(LLVMValueRef Val);
394 const char *LLVMGetValueName(LLVMValueRef Val);
395 void LLVMSetValueName(LLVMValueRef Val, const char *Name);
396 void LLVMDumpValue(LLVMValueRef Val);
398 /* Conversion functions. Return the input value if it is an instance of the
399 specified class, otherwise NULL. See llvm::dyn_cast_or_null<>. */
400 #define LLVM_DECLARE_VALUE_CAST(name) \
401 LLVMValueRef LLVMIsA##name(LLVMValueRef Val);
402 LLVM_FOR_EACH_VALUE_SUBCLASS(LLVM_DECLARE_VALUE_CAST)
404 /* Operations on constants of any type */
405 LLVMValueRef LLVMConstNull(LLVMTypeRef Ty); /* all zeroes */
406 LLVMValueRef LLVMConstAllOnes(LLVMTypeRef Ty); /* only for int/vector */
407 LLVMValueRef LLVMGetUndef(LLVMTypeRef Ty);
408 int LLVMIsConstant(LLVMValueRef Val);
409 int LLVMIsNull(LLVMValueRef Val);
410 int LLVMIsUndef(LLVMValueRef Val);
411 LLVMValueRef LLVMConstPointerNull(LLVMTypeRef Ty);
413 /* Operations on scalar constants */
414 LLVMValueRef LLVMConstInt(LLVMTypeRef IntTy, unsigned long long N,
416 LLVMValueRef LLVMConstReal(LLVMTypeRef RealTy, double N);
417 LLVMValueRef LLVMConstRealOfString(LLVMTypeRef RealTy, const char *Text);
419 /* Operations on composite constants */
420 LLVMValueRef LLVMConstString(const char *Str, unsigned Length,
421 int DontNullTerminate);
422 LLVMValueRef LLVMConstArray(LLVMTypeRef ElementTy,
423 LLVMValueRef *ConstantVals, unsigned Length);
424 LLVMValueRef LLVMConstStruct(LLVMValueRef *ConstantVals, unsigned Count,
426 LLVMValueRef LLVMConstVector(LLVMValueRef *ScalarConstantVals, unsigned Size);
428 /* Constant expressions */
429 LLVMValueRef LLVMSizeOf(LLVMTypeRef Ty);
430 LLVMValueRef LLVMConstNeg(LLVMValueRef ConstantVal);
431 LLVMValueRef LLVMConstNot(LLVMValueRef ConstantVal);
432 LLVMValueRef LLVMConstAdd(LLVMValueRef LHSConstant, LLVMValueRef RHSConstant);
433 LLVMValueRef LLVMConstSub(LLVMValueRef LHSConstant, LLVMValueRef RHSConstant);
434 LLVMValueRef LLVMConstMul(LLVMValueRef LHSConstant, LLVMValueRef RHSConstant);
435 LLVMValueRef LLVMConstUDiv(LLVMValueRef LHSConstant, LLVMValueRef RHSConstant);
436 LLVMValueRef LLVMConstSDiv(LLVMValueRef LHSConstant, LLVMValueRef RHSConstant);
437 LLVMValueRef LLVMConstFDiv(LLVMValueRef LHSConstant, LLVMValueRef RHSConstant);
438 LLVMValueRef LLVMConstURem(LLVMValueRef LHSConstant, LLVMValueRef RHSConstant);
439 LLVMValueRef LLVMConstSRem(LLVMValueRef LHSConstant, LLVMValueRef RHSConstant);
440 LLVMValueRef LLVMConstFRem(LLVMValueRef LHSConstant, LLVMValueRef RHSConstant);
441 LLVMValueRef LLVMConstAnd(LLVMValueRef LHSConstant, LLVMValueRef RHSConstant);
442 LLVMValueRef LLVMConstOr(LLVMValueRef LHSConstant, LLVMValueRef RHSConstant);
443 LLVMValueRef LLVMConstXor(LLVMValueRef LHSConstant, LLVMValueRef RHSConstant);
444 LLVMValueRef LLVMConstICmp(LLVMIntPredicate Predicate,
445 LLVMValueRef LHSConstant, LLVMValueRef RHSConstant);
446 LLVMValueRef LLVMConstFCmp(LLVMRealPredicate Predicate,
447 LLVMValueRef LHSConstant, LLVMValueRef RHSConstant);
448 LLVMValueRef LLVMConstShl(LLVMValueRef LHSConstant, LLVMValueRef RHSConstant);
449 LLVMValueRef LLVMConstLShr(LLVMValueRef LHSConstant, LLVMValueRef RHSConstant);
450 LLVMValueRef LLVMConstAShr(LLVMValueRef LHSConstant, LLVMValueRef RHSConstant);
451 LLVMValueRef LLVMConstGEP(LLVMValueRef ConstantVal,
452 LLVMValueRef *ConstantIndices, unsigned NumIndices);
453 LLVMValueRef LLVMConstTrunc(LLVMValueRef ConstantVal, LLVMTypeRef ToType);
454 LLVMValueRef LLVMConstSExt(LLVMValueRef ConstantVal, LLVMTypeRef ToType);
455 LLVMValueRef LLVMConstZExt(LLVMValueRef ConstantVal, LLVMTypeRef ToType);
456 LLVMValueRef LLVMConstFPTrunc(LLVMValueRef ConstantVal, LLVMTypeRef ToType);
457 LLVMValueRef LLVMConstFPExt(LLVMValueRef ConstantVal, LLVMTypeRef ToType);
458 LLVMValueRef LLVMConstUIToFP(LLVMValueRef ConstantVal, LLVMTypeRef ToType);
459 LLVMValueRef LLVMConstSIToFP(LLVMValueRef ConstantVal, LLVMTypeRef ToType);
460 LLVMValueRef LLVMConstFPToUI(LLVMValueRef ConstantVal, LLVMTypeRef ToType);
461 LLVMValueRef LLVMConstFPToSI(LLVMValueRef ConstantVal, LLVMTypeRef ToType);
462 LLVMValueRef LLVMConstPtrToInt(LLVMValueRef ConstantVal, LLVMTypeRef ToType);
463 LLVMValueRef LLVMConstIntToPtr(LLVMValueRef ConstantVal, LLVMTypeRef ToType);
464 LLVMValueRef LLVMConstBitCast(LLVMValueRef ConstantVal, LLVMTypeRef ToType);
465 LLVMValueRef LLVMConstSelect(LLVMValueRef ConstantCondition,
466 LLVMValueRef ConstantIfTrue,
467 LLVMValueRef ConstantIfFalse);
468 LLVMValueRef LLVMConstExtractElement(LLVMValueRef VectorConstant,
469 LLVMValueRef IndexConstant);
470 LLVMValueRef LLVMConstInsertElement(LLVMValueRef VectorConstant,
471 LLVMValueRef ElementValueConstant,
472 LLVMValueRef IndexConstant);
473 LLVMValueRef LLVMConstShuffleVector(LLVMValueRef VectorAConstant,
474 LLVMValueRef VectorBConstant,
475 LLVMValueRef MaskConstant);
476 LLVMValueRef LLVMConstExtractValue(LLVMValueRef AggConstant, unsigned *IdxList,
478 LLVMValueRef LLVMConstInsertValue(LLVMValueRef AggConstant,
479 LLVMValueRef ElementValueConstant,
480 unsigned *IdxList, unsigned NumIdx);
481 LLVMValueRef LLVMConstInlineAsm(LLVMTypeRef Ty,
482 const char *AsmString, const char *Constraints,
485 /* Operations on global variables, functions, and aliases (globals) */
486 LLVMModuleRef LLVMGetGlobalParent(LLVMValueRef Global);
487 int LLVMIsDeclaration(LLVMValueRef Global);
488 LLVMLinkage LLVMGetLinkage(LLVMValueRef Global);
489 void LLVMSetLinkage(LLVMValueRef Global, LLVMLinkage Linkage);
490 const char *LLVMGetSection(LLVMValueRef Global);
491 void LLVMSetSection(LLVMValueRef Global, const char *Section);
492 LLVMVisibility LLVMGetVisibility(LLVMValueRef Global);
493 void LLVMSetVisibility(LLVMValueRef Global, LLVMVisibility Viz);
494 unsigned LLVMGetAlignment(LLVMValueRef Global);
495 void LLVMSetAlignment(LLVMValueRef Global, unsigned Bytes);
497 /* Operations on global variables */
498 LLVMValueRef LLVMAddGlobal(LLVMModuleRef M, LLVMTypeRef Ty, const char *Name);
499 LLVMValueRef LLVMGetNamedGlobal(LLVMModuleRef M, const char *Name);
500 LLVMValueRef LLVMGetFirstGlobal(LLVMModuleRef M);
501 LLVMValueRef LLVMGetLastGlobal(LLVMModuleRef M);
502 LLVMValueRef LLVMGetNextGlobal(LLVMValueRef GlobalVar);
503 LLVMValueRef LLVMGetPreviousGlobal(LLVMValueRef GlobalVar);
504 void LLVMDeleteGlobal(LLVMValueRef GlobalVar);
505 LLVMValueRef LLVMGetInitializer(LLVMValueRef GlobalVar);
506 void LLVMSetInitializer(LLVMValueRef GlobalVar, LLVMValueRef ConstantVal);
507 int LLVMIsThreadLocal(LLVMValueRef GlobalVar);
508 void LLVMSetThreadLocal(LLVMValueRef GlobalVar, int IsThreadLocal);
509 int LLVMIsGlobalConstant(LLVMValueRef GlobalVar);
510 void LLVMSetGlobalConstant(LLVMValueRef GlobalVar, int IsConstant);
512 /* Operations on aliases */
513 LLVMValueRef LLVMAddAlias(LLVMModuleRef M, LLVMTypeRef Ty, LLVMValueRef Aliasee,
516 /* Operations on functions */
517 LLVMValueRef LLVMAddFunction(LLVMModuleRef M, const char *Name,
518 LLVMTypeRef FunctionTy);
519 LLVMValueRef LLVMGetNamedFunction(LLVMModuleRef M, const char *Name);
520 LLVMValueRef LLVMGetFirstFunction(LLVMModuleRef M);
521 LLVMValueRef LLVMGetLastFunction(LLVMModuleRef M);
522 LLVMValueRef LLVMGetNextFunction(LLVMValueRef Fn);
523 LLVMValueRef LLVMGetPreviousFunction(LLVMValueRef Fn);
524 void LLVMDeleteFunction(LLVMValueRef Fn);
525 unsigned LLVMGetIntrinsicID(LLVMValueRef Fn);
526 unsigned LLVMGetFunctionCallConv(LLVMValueRef Fn);
527 void LLVMSetFunctionCallConv(LLVMValueRef Fn, unsigned CC);
528 const char *LLVMGetGC(LLVMValueRef Fn);
529 void LLVMSetGC(LLVMValueRef Fn, const char *Name);
530 void LLVMAddFunctionAttr(LLVMValueRef Fn, LLVMAttribute PA);
531 void LLVMRemoveFunctionAttr(LLVMValueRef Fn, LLVMAttribute PA);
533 /* Operations on parameters */
534 unsigned LLVMCountParams(LLVMValueRef Fn);
535 void LLVMGetParams(LLVMValueRef Fn, LLVMValueRef *Params);
536 LLVMValueRef LLVMGetParam(LLVMValueRef Fn, unsigned Index);
537 LLVMValueRef LLVMGetParamParent(LLVMValueRef Inst);
538 LLVMValueRef LLVMGetFirstParam(LLVMValueRef Fn);
539 LLVMValueRef LLVMGetLastParam(LLVMValueRef Fn);
540 LLVMValueRef LLVMGetNextParam(LLVMValueRef Arg);
541 LLVMValueRef LLVMGetPreviousParam(LLVMValueRef Arg);
542 void LLVMAddAttribute(LLVMValueRef Arg, LLVMAttribute PA);
543 void LLVMRemoveAttribute(LLVMValueRef Arg, LLVMAttribute PA);
544 void LLVMSetParamAlignment(LLVMValueRef Arg, unsigned align);
546 /* Operations on basic blocks */
547 LLVMValueRef LLVMBasicBlockAsValue(LLVMBasicBlockRef BB);
548 int LLVMValueIsBasicBlock(LLVMValueRef Val);
549 LLVMBasicBlockRef LLVMValueAsBasicBlock(LLVMValueRef Val);
550 LLVMValueRef LLVMGetBasicBlockParent(LLVMBasicBlockRef BB);
551 unsigned LLVMCountBasicBlocks(LLVMValueRef Fn);
552 void LLVMGetBasicBlocks(LLVMValueRef Fn, LLVMBasicBlockRef *BasicBlocks);
553 LLVMBasicBlockRef LLVMGetFirstBasicBlock(LLVMValueRef Fn);
554 LLVMBasicBlockRef LLVMGetLastBasicBlock(LLVMValueRef Fn);
555 LLVMBasicBlockRef LLVMGetNextBasicBlock(LLVMBasicBlockRef BB);
556 LLVMBasicBlockRef LLVMGetPreviousBasicBlock(LLVMBasicBlockRef BB);
557 LLVMBasicBlockRef LLVMGetEntryBasicBlock(LLVMValueRef Fn);
558 LLVMBasicBlockRef LLVMAppendBasicBlock(LLVMValueRef Fn, const char *Name);
559 LLVMBasicBlockRef LLVMInsertBasicBlock(LLVMBasicBlockRef InsertBeforeBB,
561 void LLVMDeleteBasicBlock(LLVMBasicBlockRef BB);
563 /* Operations on instructions */
564 LLVMBasicBlockRef LLVMGetInstructionParent(LLVMValueRef Inst);
565 LLVMValueRef LLVMGetFirstInstruction(LLVMBasicBlockRef BB);
566 LLVMValueRef LLVMGetLastInstruction(LLVMBasicBlockRef BB);
567 LLVMValueRef LLVMGetNextInstruction(LLVMValueRef Inst);
568 LLVMValueRef LLVMGetPreviousInstruction(LLVMValueRef Inst);
570 /* Operations on call sites */
571 void LLVMSetInstructionCallConv(LLVMValueRef Instr, unsigned CC);
572 unsigned LLVMGetInstructionCallConv(LLVMValueRef Instr);
573 void LLVMAddInstrAttribute(LLVMValueRef Instr, unsigned index, LLVMAttribute);
574 void LLVMRemoveInstrAttribute(LLVMValueRef Instr, unsigned index,
576 void LLVMSetInstrParamAlignment(LLVMValueRef Instr, unsigned index,
579 /* Operations on call instructions (only) */
580 int LLVMIsTailCall(LLVMValueRef CallInst);
581 void LLVMSetTailCall(LLVMValueRef CallInst, int IsTailCall);
583 /* Operations on phi nodes */
584 void LLVMAddIncoming(LLVMValueRef PhiNode, LLVMValueRef *IncomingValues,
585 LLVMBasicBlockRef *IncomingBlocks, unsigned Count);
586 unsigned LLVMCountIncoming(LLVMValueRef PhiNode);
587 LLVMValueRef LLVMGetIncomingValue(LLVMValueRef PhiNode, unsigned Index);
588 LLVMBasicBlockRef LLVMGetIncomingBlock(LLVMValueRef PhiNode, unsigned Index);
590 /*===-- Instruction builders ----------------------------------------------===*/
592 /* An instruction builder represents a point within a basic block, and is the
593 * exclusive means of building instructions using the C interface.
596 LLVMBuilderRef LLVMCreateBuilder(void);
597 void LLVMPositionBuilder(LLVMBuilderRef Builder, LLVMBasicBlockRef Block,
599 void LLVMPositionBuilderBefore(LLVMBuilderRef Builder, LLVMValueRef Instr);
600 void LLVMPositionBuilderAtEnd(LLVMBuilderRef Builder, LLVMBasicBlockRef Block);
601 LLVMBasicBlockRef LLVMGetInsertBlock(LLVMBuilderRef Builder);
602 void LLVMClearInsertionPosition(LLVMBuilderRef Builder);
603 void LLVMInsertIntoBuilder(LLVMBuilderRef Builder, LLVMValueRef Instr);
604 void LLVMDisposeBuilder(LLVMBuilderRef Builder);
607 LLVMValueRef LLVMBuildRetVoid(LLVMBuilderRef);
608 LLVMValueRef LLVMBuildRet(LLVMBuilderRef, LLVMValueRef V);
609 LLVMValueRef LLVMBuildBr(LLVMBuilderRef, LLVMBasicBlockRef Dest);
610 LLVMValueRef LLVMBuildCondBr(LLVMBuilderRef, LLVMValueRef If,
611 LLVMBasicBlockRef Then, LLVMBasicBlockRef Else);
612 LLVMValueRef LLVMBuildSwitch(LLVMBuilderRef, LLVMValueRef V,
613 LLVMBasicBlockRef Else, unsigned NumCases);
614 LLVMValueRef LLVMBuildInvoke(LLVMBuilderRef, LLVMValueRef Fn,
615 LLVMValueRef *Args, unsigned NumArgs,
616 LLVMBasicBlockRef Then, LLVMBasicBlockRef Catch,
618 LLVMValueRef LLVMBuildUnwind(LLVMBuilderRef);
619 LLVMValueRef LLVMBuildUnreachable(LLVMBuilderRef);
621 /* Add a case to the switch instruction */
622 void LLVMAddCase(LLVMValueRef Switch, LLVMValueRef OnVal,
623 LLVMBasicBlockRef Dest);
626 LLVMValueRef LLVMBuildAdd(LLVMBuilderRef, LLVMValueRef LHS, LLVMValueRef RHS,
628 LLVMValueRef LLVMBuildSub(LLVMBuilderRef, LLVMValueRef LHS, LLVMValueRef RHS,
630 LLVMValueRef LLVMBuildMul(LLVMBuilderRef, LLVMValueRef LHS, LLVMValueRef RHS,
632 LLVMValueRef LLVMBuildUDiv(LLVMBuilderRef, LLVMValueRef LHS, LLVMValueRef RHS,
634 LLVMValueRef LLVMBuildSDiv(LLVMBuilderRef, LLVMValueRef LHS, LLVMValueRef RHS,
636 LLVMValueRef LLVMBuildFDiv(LLVMBuilderRef, LLVMValueRef LHS, LLVMValueRef RHS,
638 LLVMValueRef LLVMBuildURem(LLVMBuilderRef, LLVMValueRef LHS, LLVMValueRef RHS,
640 LLVMValueRef LLVMBuildSRem(LLVMBuilderRef, LLVMValueRef LHS, LLVMValueRef RHS,
642 LLVMValueRef LLVMBuildFRem(LLVMBuilderRef, LLVMValueRef LHS, LLVMValueRef RHS,
644 LLVMValueRef LLVMBuildShl(LLVMBuilderRef, LLVMValueRef LHS, LLVMValueRef RHS,
646 LLVMValueRef LLVMBuildLShr(LLVMBuilderRef, LLVMValueRef LHS, LLVMValueRef RHS,
648 LLVMValueRef LLVMBuildAShr(LLVMBuilderRef, LLVMValueRef LHS, LLVMValueRef RHS,
650 LLVMValueRef LLVMBuildAnd(LLVMBuilderRef, LLVMValueRef LHS, LLVMValueRef RHS,
652 LLVMValueRef LLVMBuildOr(LLVMBuilderRef, LLVMValueRef LHS, LLVMValueRef RHS,
654 LLVMValueRef LLVMBuildXor(LLVMBuilderRef, LLVMValueRef LHS, LLVMValueRef RHS,
656 LLVMValueRef LLVMBuildNeg(LLVMBuilderRef, LLVMValueRef V, const char *Name);
657 LLVMValueRef LLVMBuildNot(LLVMBuilderRef, LLVMValueRef V, const char *Name);
660 LLVMValueRef LLVMBuildMalloc(LLVMBuilderRef, LLVMTypeRef Ty, const char *Name);
661 LLVMValueRef LLVMBuildArrayMalloc(LLVMBuilderRef, LLVMTypeRef Ty,
662 LLVMValueRef Val, const char *Name);
663 LLVMValueRef LLVMBuildAlloca(LLVMBuilderRef, LLVMTypeRef Ty, const char *Name);
664 LLVMValueRef LLVMBuildArrayAlloca(LLVMBuilderRef, LLVMTypeRef Ty,
665 LLVMValueRef Val, const char *Name);
666 LLVMValueRef LLVMBuildFree(LLVMBuilderRef, LLVMValueRef PointerVal);
667 LLVMValueRef LLVMBuildLoad(LLVMBuilderRef, LLVMValueRef PointerVal,
669 LLVMValueRef LLVMBuildStore(LLVMBuilderRef, LLVMValueRef Val, LLVMValueRef Ptr);
670 LLVMValueRef LLVMBuildGEP(LLVMBuilderRef B, LLVMValueRef Pointer,
671 LLVMValueRef *Indices, unsigned NumIndices,
675 LLVMValueRef LLVMBuildTrunc(LLVMBuilderRef, LLVMValueRef Val,
676 LLVMTypeRef DestTy, const char *Name);
677 LLVMValueRef LLVMBuildZExt(LLVMBuilderRef, LLVMValueRef Val,
678 LLVMTypeRef DestTy, const char *Name);
679 LLVMValueRef LLVMBuildSExt(LLVMBuilderRef, LLVMValueRef Val,
680 LLVMTypeRef DestTy, const char *Name);
681 LLVMValueRef LLVMBuildFPToUI(LLVMBuilderRef, LLVMValueRef Val,
682 LLVMTypeRef DestTy, const char *Name);
683 LLVMValueRef LLVMBuildFPToSI(LLVMBuilderRef, LLVMValueRef Val,
684 LLVMTypeRef DestTy, const char *Name);
685 LLVMValueRef LLVMBuildUIToFP(LLVMBuilderRef, LLVMValueRef Val,
686 LLVMTypeRef DestTy, const char *Name);
687 LLVMValueRef LLVMBuildSIToFP(LLVMBuilderRef, LLVMValueRef Val,
688 LLVMTypeRef DestTy, const char *Name);
689 LLVMValueRef LLVMBuildFPTrunc(LLVMBuilderRef, LLVMValueRef Val,
690 LLVMTypeRef DestTy, const char *Name);
691 LLVMValueRef LLVMBuildFPExt(LLVMBuilderRef, LLVMValueRef Val,
692 LLVMTypeRef DestTy, const char *Name);
693 LLVMValueRef LLVMBuildPtrToInt(LLVMBuilderRef, LLVMValueRef Val,
694 LLVMTypeRef DestTy, const char *Name);
695 LLVMValueRef LLVMBuildIntToPtr(LLVMBuilderRef, LLVMValueRef Val,
696 LLVMTypeRef DestTy, const char *Name);
697 LLVMValueRef LLVMBuildBitCast(LLVMBuilderRef, LLVMValueRef Val,
698 LLVMTypeRef DestTy, const char *Name);
701 LLVMValueRef LLVMBuildICmp(LLVMBuilderRef, LLVMIntPredicate Op,
702 LLVMValueRef LHS, LLVMValueRef RHS,
704 LLVMValueRef LLVMBuildFCmp(LLVMBuilderRef, LLVMRealPredicate Op,
705 LLVMValueRef LHS, LLVMValueRef RHS,
708 /* Miscellaneous instructions */
709 LLVMValueRef LLVMBuildPhi(LLVMBuilderRef, LLVMTypeRef Ty, const char *Name);
710 LLVMValueRef LLVMBuildCall(LLVMBuilderRef, LLVMValueRef Fn,
711 LLVMValueRef *Args, unsigned NumArgs,
713 LLVMValueRef LLVMBuildSelect(LLVMBuilderRef, LLVMValueRef If,
714 LLVMValueRef Then, LLVMValueRef Else,
716 LLVMValueRef LLVMBuildVAArg(LLVMBuilderRef, LLVMValueRef List, LLVMTypeRef Ty,
718 LLVMValueRef LLVMBuildExtractElement(LLVMBuilderRef, LLVMValueRef VecVal,
719 LLVMValueRef Index, const char *Name);
720 LLVMValueRef LLVMBuildInsertElement(LLVMBuilderRef, LLVMValueRef VecVal,
721 LLVMValueRef EltVal, LLVMValueRef Index,
723 LLVMValueRef LLVMBuildShuffleVector(LLVMBuilderRef, LLVMValueRef V1,
724 LLVMValueRef V2, LLVMValueRef Mask,
726 LLVMValueRef LLVMBuildExtractValue(LLVMBuilderRef, LLVMValueRef AggVal,
727 unsigned Index, const char *Name);
728 LLVMValueRef LLVMBuildInsertValue(LLVMBuilderRef, LLVMValueRef AggVal,
729 LLVMValueRef EltVal, unsigned Index,
733 /*===-- Module providers --------------------------------------------------===*/
735 /* Encapsulates the module M in a module provider, taking ownership of the
737 * See the constructor llvm::ExistingModuleProvider::ExistingModuleProvider.
739 LLVMModuleProviderRef
740 LLVMCreateModuleProviderForExistingModule(LLVMModuleRef M);
742 /* Destroys the module provider MP as well as the contained module.
743 * See the destructor llvm::ModuleProvider::~ModuleProvider.
745 void LLVMDisposeModuleProvider(LLVMModuleProviderRef MP);
748 /*===-- Memory buffers ----------------------------------------------------===*/
750 int LLVMCreateMemoryBufferWithContentsOfFile(const char *Path,
751 LLVMMemoryBufferRef *OutMemBuf,
753 int LLVMCreateMemoryBufferWithSTDIN(LLVMMemoryBufferRef *OutMemBuf,
755 void LLVMDisposeMemoryBuffer(LLVMMemoryBufferRef MemBuf);
758 /*===-- Pass Managers -----------------------------------------------------===*/
760 /** Constructs a new whole-module pass pipeline. This type of pipeline is
761 suitable for link-time optimization and whole-module transformations.
762 See llvm::PassManager::PassManager. */
763 LLVMPassManagerRef LLVMCreatePassManager(void);
765 /** Constructs a new function-by-function pass pipeline over the module
766 provider. It does not take ownership of the module provider. This type of
767 pipeline is suitable for code generation and JIT compilation tasks.
768 See llvm::FunctionPassManager::FunctionPassManager. */
769 LLVMPassManagerRef LLVMCreateFunctionPassManager(LLVMModuleProviderRef MP);
771 /** Initializes, executes on the provided module, and finalizes all of the
772 passes scheduled in the pass manager. Returns 1 if any of the passes
773 modified the module, 0 otherwise. See llvm::PassManager::run(Module&). */
774 int LLVMRunPassManager(LLVMPassManagerRef PM, LLVMModuleRef M);
776 /** Initializes all of the function passes scheduled in the function pass
777 manager. Returns 1 if any of the passes modified the module, 0 otherwise.
778 See llvm::FunctionPassManager::doInitialization. */
779 int LLVMInitializeFunctionPassManager(LLVMPassManagerRef FPM);
781 /** Executes all of the function passes scheduled in the function pass manager
782 on the provided function. Returns 1 if any of the passes modified the
783 function, false otherwise.
784 See llvm::FunctionPassManager::run(Function&). */
785 int LLVMRunFunctionPassManager(LLVMPassManagerRef FPM, LLVMValueRef F);
787 /** Finalizes all of the function passes scheduled in in the function pass
788 manager. Returns 1 if any of the passes modified the module, 0 otherwise.
789 See llvm::FunctionPassManager::doFinalization. */
790 int LLVMFinalizeFunctionPassManager(LLVMPassManagerRef FPM);
792 /** Frees the memory of a pass pipeline. For function pipelines, does not free
794 See llvm::PassManagerBase::~PassManagerBase. */
795 void LLVMDisposePassManager(LLVMPassManagerRef PM);
802 class ModuleProvider;
804 class PassManagerBase;
806 #define DEFINE_SIMPLE_CONVERSION_FUNCTIONS(ty, ref) \
807 inline ty *unwrap(ref P) { \
808 return reinterpret_cast<ty*>(P); \
811 inline ref wrap(const ty *P) { \
812 return reinterpret_cast<ref>(const_cast<ty*>(P)); \
815 #define DEFINE_ISA_CONVERSION_FUNCTIONS(ty, ref) \
816 DEFINE_SIMPLE_CONVERSION_FUNCTIONS(ty, ref) \
818 template<typename T> \
819 inline T *unwrap(ref P) { \
820 return cast<T>(unwrap(P)); \
823 #define DEFINE_STDCXX_CONVERSION_FUNCTIONS(ty, ref) \
824 DEFINE_SIMPLE_CONVERSION_FUNCTIONS(ty, ref) \
826 template<typename T> \
827 inline T *unwrap(ref P) { \
828 T *Q = dynamic_cast<T*>(unwrap(P)); \
829 assert(Q && "Invalid cast!"); \
833 DEFINE_ISA_CONVERSION_FUNCTIONS (Type, LLVMTypeRef )
834 DEFINE_ISA_CONVERSION_FUNCTIONS (Value, LLVMValueRef )
835 DEFINE_SIMPLE_CONVERSION_FUNCTIONS(Module, LLVMModuleRef )
836 DEFINE_SIMPLE_CONVERSION_FUNCTIONS(BasicBlock, LLVMBasicBlockRef )
837 DEFINE_SIMPLE_CONVERSION_FUNCTIONS(IRBuilder<>, LLVMBuilderRef )
838 DEFINE_SIMPLE_CONVERSION_FUNCTIONS(PATypeHolder, LLVMTypeHandleRef )
839 DEFINE_SIMPLE_CONVERSION_FUNCTIONS(ModuleProvider, LLVMModuleProviderRef)
840 DEFINE_SIMPLE_CONVERSION_FUNCTIONS(MemoryBuffer, LLVMMemoryBufferRef )
841 DEFINE_SIMPLE_CONVERSION_FUNCTIONS(LLVMContext, LLVMContextRef )
842 DEFINE_STDCXX_CONVERSION_FUNCTIONS(PassManagerBase, LLVMPassManagerRef )
844 #undef DEFINE_STDCXX_CONVERSION_FUNCTIONS
845 #undef DEFINE_ISA_CONVERSION_FUNCTIONS
846 #undef DEFINE_SIMPLE_CONVERSION_FUNCTIONS
848 /* Specialized opaque type conversions.
850 inline Type **unwrap(LLVMTypeRef* Tys) {
851 return reinterpret_cast<Type**>(Tys);
854 inline LLVMTypeRef *wrap(const Type **Tys) {
855 return reinterpret_cast<LLVMTypeRef*>(const_cast<Type**>(Tys));
858 /* Specialized opaque value conversions.
860 inline Value **unwrap(LLVMValueRef *Vals) {
861 return reinterpret_cast<Value**>(Vals);
865 inline T **unwrap(LLVMValueRef *Vals, unsigned Length) {
867 for (LLVMValueRef *I = Vals, *E = Vals + Length; I != E; ++I)
870 return reinterpret_cast<T**>(Vals);
873 inline LLVMValueRef *wrap(const Value **Vals) {
874 return reinterpret_cast<LLVMValueRef*>(const_cast<Value**>(Vals));
878 #endif /* !defined(__cplusplus) */
880 #endif /* !defined(LLVM_C_CORE_H) */