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 other LLVM Intermediate Representation (IR)
51 * objects. See the llvm::Module class.
53 typedef struct LLVMOpaqueModule
*LLVMModuleRef
;
56 * Each value in the LLVM IR has a type, an LLVMTypeRef. See the llvm::Type
59 typedef struct LLVMOpaqueType
*LLVMTypeRef
;
62 * When building recursive types using LLVMRefineType, LLVMTypeRef values may
63 * become invalid; use LLVMTypeHandleRef to resolve this problem. See the
64 * llvm::AbstractTypeHolder class.
66 typedef struct LLVMOpaqueTypeHandle
*LLVMTypeHandleRef
;
68 typedef struct LLVMOpaqueValue
*LLVMValueRef
;
69 typedef struct LLVMOpaqueBasicBlock
*LLVMBasicBlockRef
;
70 typedef struct LLVMOpaqueBuilder
*LLVMBuilderRef
;
72 /* Used to provide a module to JIT or interpreter.
73 * See the llvm::ModuleProvider class.
75 typedef struct LLVMOpaqueModuleProvider
*LLVMModuleProviderRef
;
77 /* Used to provide a module to JIT or interpreter.
78 * See the llvm::MemoryBuffer class.
80 typedef struct LLVMOpaqueMemoryBuffer
*LLVMMemoryBufferRef
;
82 /** See the llvm::PassManagerBase class. */
83 typedef struct LLVMOpaquePassManager
*LLVMPassManagerRef
;
86 LLVMZExtAttribute
= 1<<0,
87 LLVMSExtAttribute
= 1<<1,
88 LLVMNoReturnAttribute
= 1<<2,
89 LLVMInRegAttribute
= 1<<3,
90 LLVMStructRetAttribute
= 1<<4,
91 LLVMNoUnwindAttribute
= 1<<5,
92 LLVMNoAliasAttribute
= 1<<6,
93 LLVMByValAttribute
= 1<<7,
94 LLVMNestAttribute
= 1<<8,
95 LLVMReadNoneAttribute
= 1<<9,
96 LLVMReadOnlyAttribute
= 1<<10
100 LLVMVoidTypeKind
, /**< type with no size */
101 LLVMFloatTypeKind
, /**< 32 bit floating point type */
102 LLVMDoubleTypeKind
, /**< 64 bit floating point type */
103 LLVMX86_FP80TypeKind
, /**< 80 bit floating point type (X87) */
104 LLVMFP128TypeKind
, /**< 128 bit floating point type (112-bit mantissa)*/
105 LLVMPPC_FP128TypeKind
, /**< 128 bit floating point type (two 64-bits) */
106 LLVMLabelTypeKind
, /**< Labels */
107 LLVMIntegerTypeKind
, /**< Arbitrary bit width integers */
108 LLVMFunctionTypeKind
, /**< Functions */
109 LLVMStructTypeKind
, /**< Structures */
110 LLVMArrayTypeKind
, /**< Arrays */
111 LLVMPointerTypeKind
, /**< Pointers */
112 LLVMOpaqueTypeKind
, /**< Opaque: type with unknown structure */
113 LLVMVectorTypeKind
/**< SIMD 'packed' format, or other vector type */
117 LLVMExternalLinkage
, /**< Externally visible function */
118 LLVMAvailableExternallyLinkage
,
119 LLVMLinkOnceAnyLinkage
, /**< Keep one copy of function when linking (inline)*/
120 LLVMLinkOnceODRLinkage
, /**< Same, but only replaced by something
122 LLVMWeakAnyLinkage
, /**< Keep one copy of function when linking (weak) */
123 LLVMWeakODRLinkage
, /**< Same, but only replaced by something
125 LLVMAppendingLinkage
, /**< Special purpose, only applies to global arrays */
126 LLVMInternalLinkage
, /**< Rename collisions when linking (static
128 LLVMPrivateLinkage
, /**< Like Internal, but omit from symbol table */
129 LLVMDLLImportLinkage
, /**< Function to be imported from DLL */
130 LLVMDLLExportLinkage
, /**< Function to be accessible from DLL */
131 LLVMExternalWeakLinkage
,/**< ExternalWeak linkage description */
132 LLVMGhostLinkage
, /**< Stand-in functions for streaming fns from
134 LLVMCommonLinkage
/**< Tentative definitions */
138 LLVMDefaultVisibility
, /**< The GV is visible */
139 LLVMHiddenVisibility
, /**< The GV is hidden */
140 LLVMProtectedVisibility
/**< The GV is protected */
145 LLVMFastCallConv
= 8,
146 LLVMColdCallConv
= 9,
147 LLVMX86StdcallCallConv
= 64,
148 LLVMX86FastcallCallConv
= 65
152 LLVMIntEQ
= 32, /**< equal */
153 LLVMIntNE
, /**< not equal */
154 LLVMIntUGT
, /**< unsigned greater than */
155 LLVMIntUGE
, /**< unsigned greater or equal */
156 LLVMIntULT
, /**< unsigned less than */
157 LLVMIntULE
, /**< unsigned less or equal */
158 LLVMIntSGT
, /**< signed greater than */
159 LLVMIntSGE
, /**< signed greater or equal */
160 LLVMIntSLT
, /**< signed less than */
161 LLVMIntSLE
/**< signed less or equal */
165 LLVMRealPredicateFalse
, /**< Always false (always folded) */
166 LLVMRealOEQ
, /**< True if ordered and equal */
167 LLVMRealOGT
, /**< True if ordered and greater than */
168 LLVMRealOGE
, /**< True if ordered and greater than or equal */
169 LLVMRealOLT
, /**< True if ordered and less than */
170 LLVMRealOLE
, /**< True if ordered and less than or equal */
171 LLVMRealONE
, /**< True if ordered and operands are unequal */
172 LLVMRealORD
, /**< True if ordered (no nans) */
173 LLVMRealUNO
, /**< True if unordered: isnan(X) | isnan(Y) */
174 LLVMRealUEQ
, /**< True if unordered or equal */
175 LLVMRealUGT
, /**< True if unordered or greater than */
176 LLVMRealUGE
, /**< True if unordered, greater than, or equal */
177 LLVMRealULT
, /**< True if unordered or less than */
178 LLVMRealULE
, /**< True if unordered, less than, or equal */
179 LLVMRealUNE
, /**< True if unordered or not equal */
180 LLVMRealPredicateTrue
/**< Always true (always folded) */
184 /*===-- Error handling ----------------------------------------------------===*/
186 void LLVMDisposeMessage(char *Message
);
189 /*===-- Modules -----------------------------------------------------------===*/
191 /* Create and destroy modules. */
192 /** See llvm::Module::Module. */
193 LLVMModuleRef
LLVMModuleCreateWithName(const char *ModuleID
);
195 /** See llvm::Module::~Module. */
196 void LLVMDisposeModule(LLVMModuleRef M
);
198 /** Data layout. See Module::getDataLayout. */
199 const char *LLVMGetDataLayout(LLVMModuleRef M
);
200 void LLVMSetDataLayout(LLVMModuleRef M
, const char *Triple
);
202 /** Target triple. See Module::getTargetTriple. */
203 const char *LLVMGetTarget(LLVMModuleRef M
);
204 void LLVMSetTarget(LLVMModuleRef M
, const char *Triple
);
206 /** See Module::addTypeName. */
207 int LLVMAddTypeName(LLVMModuleRef M
, const char *Name
, LLVMTypeRef Ty
);
208 void LLVMDeleteTypeName(LLVMModuleRef M
, const char *Name
);
210 /** See Module::dump. */
211 void LLVMDumpModule(LLVMModuleRef M
);
214 /*===-- Types -------------------------------------------------------------===*/
216 /* LLVM types conform to the following hierarchy:
231 /** See llvm::LLVMTypeKind::getTypeID. */
232 LLVMTypeKind
LLVMGetTypeKind(LLVMTypeRef Ty
);
234 /* Operations on integer types */
235 LLVMTypeRef
LLVMInt1Type(void);
236 LLVMTypeRef
LLVMInt8Type(void);
237 LLVMTypeRef
LLVMInt16Type(void);
238 LLVMTypeRef
LLVMInt32Type(void);
239 LLVMTypeRef
LLVMInt64Type(void);
240 LLVMTypeRef
LLVMIntType(unsigned NumBits
);
241 unsigned LLVMGetIntTypeWidth(LLVMTypeRef IntegerTy
);
243 /* Operations on real types */
244 LLVMTypeRef
LLVMFloatType(void);
245 LLVMTypeRef
LLVMDoubleType(void);
246 LLVMTypeRef
LLVMX86FP80Type(void);
247 LLVMTypeRef
LLVMFP128Type(void);
248 LLVMTypeRef
LLVMPPCFP128Type(void);
250 /* Operations on function types */
251 LLVMTypeRef
LLVMFunctionType(LLVMTypeRef ReturnType
,
252 LLVMTypeRef
*ParamTypes
, unsigned ParamCount
,
254 int LLVMIsFunctionVarArg(LLVMTypeRef FunctionTy
);
255 LLVMTypeRef
LLVMGetReturnType(LLVMTypeRef FunctionTy
);
256 unsigned LLVMCountParamTypes(LLVMTypeRef FunctionTy
);
257 void LLVMGetParamTypes(LLVMTypeRef FunctionTy
, LLVMTypeRef
*Dest
);
259 /* Operations on struct types */
260 LLVMTypeRef
LLVMStructType(LLVMTypeRef
*ElementTypes
, unsigned ElementCount
,
262 unsigned LLVMCountStructElementTypes(LLVMTypeRef StructTy
);
263 void LLVMGetStructElementTypes(LLVMTypeRef StructTy
, LLVMTypeRef
*Dest
);
264 int LLVMIsPackedStruct(LLVMTypeRef StructTy
);
266 /* Operations on array, pointer, and vector types (sequence types) */
267 LLVMTypeRef
LLVMArrayType(LLVMTypeRef ElementType
, unsigned ElementCount
);
268 LLVMTypeRef
LLVMPointerType(LLVMTypeRef ElementType
, unsigned AddressSpace
);
269 LLVMTypeRef
LLVMVectorType(LLVMTypeRef ElementType
, unsigned ElementCount
);
271 LLVMTypeRef
LLVMGetElementType(LLVMTypeRef Ty
);
272 unsigned LLVMGetArrayLength(LLVMTypeRef ArrayTy
);
273 unsigned LLVMGetPointerAddressSpace(LLVMTypeRef PointerTy
);
274 unsigned LLVMGetVectorSize(LLVMTypeRef VectorTy
);
276 /* Operations on other types */
277 LLVMTypeRef
LLVMVoidType(void);
278 LLVMTypeRef
LLVMLabelType(void);
279 LLVMTypeRef
LLVMOpaqueType(void);
281 /* Operations on type handles */
282 LLVMTypeHandleRef
LLVMCreateTypeHandle(LLVMTypeRef PotentiallyAbstractTy
);
283 void LLVMRefineType(LLVMTypeRef AbstractTy
, LLVMTypeRef ConcreteTy
);
284 LLVMTypeRef
LLVMResolveTypeHandle(LLVMTypeHandleRef TypeHandle
);
285 void LLVMDisposeTypeHandle(LLVMTypeHandleRef TypeHandle
);
288 /*===-- Values ------------------------------------------------------------===*/
290 /* The bulk of LLVM's object model consists of values, which comprise a very
291 * rich type hierarchy.
294 #define LLVM_FOR_EACH_VALUE_SUBCLASS(macro) \
300 macro(ConstantAggregateZero) \
301 macro(ConstantArray) \
302 macro(ConstantExpr) \
305 macro(ConstantPointerNull) \
306 macro(ConstantStruct) \
307 macro(ConstantVector) \
311 macro(GlobalVariable) \
314 macro(BinaryOperator) \
316 macro(IntrinsicInst) \
317 macro(DbgInfoIntrinsic) \
318 macro(DbgDeclareInst) \
319 macro(DbgFuncStartInst) \
320 macro(DbgRegionEndInst) \
321 macro(DbgRegionStartInst) \
322 macro(DbgStopPointInst) \
323 macro(EHSelectorInst) \
324 macro(MemIntrinsic) \
333 macro(ExtractElementInst) \
334 macro(GetElementPtrInst) \
335 macro(InsertElementInst) \
336 macro(InsertValueInst) \
339 macro(ShuffleVectorInst) \
341 macro(TerminatorInst) \
346 macro(UnreachableInst) \
348 macro(UnaryInstruction) \
349 macro(AllocationInst) \
358 macro(IntToPtrInst) \
359 macro(PtrToIntInst) \
365 macro(ExtractValueInst) \
370 /* Operations on all values */
371 LLVMTypeRef
LLVMTypeOf(LLVMValueRef Val
);
372 const char *LLVMGetValueName(LLVMValueRef Val
);
373 void LLVMSetValueName(LLVMValueRef Val
, const char *Name
);
374 void LLVMDumpValue(LLVMValueRef Val
);
376 /* Conversion functions. Return the input value if it is an instance of the
377 specified class, otherwise NULL. See llvm::dyn_cast_or_null<>. */
378 #define LLVM_DECLARE_VALUE_CAST(name) \
379 LLVMValueRef LLVMIsA##name(LLVMValueRef Val);
380 LLVM_FOR_EACH_VALUE_SUBCLASS(LLVM_DECLARE_VALUE_CAST
)
382 /* Operations on constants of any type */
383 LLVMValueRef
LLVMConstNull(LLVMTypeRef Ty
); /* all zeroes */
384 LLVMValueRef
LLVMConstAllOnes(LLVMTypeRef Ty
); /* only for int/vector */
385 LLVMValueRef
LLVMGetUndef(LLVMTypeRef Ty
);
386 int LLVMIsConstant(LLVMValueRef Val
);
387 int LLVMIsNull(LLVMValueRef Val
);
388 int LLVMIsUndef(LLVMValueRef Val
);
390 /* Operations on scalar constants */
391 LLVMValueRef
LLVMConstInt(LLVMTypeRef IntTy
, unsigned long long N
,
393 LLVMValueRef
LLVMConstReal(LLVMTypeRef RealTy
, double N
);
394 LLVMValueRef
LLVMConstRealOfString(LLVMTypeRef RealTy
, const char *Text
);
396 /* Operations on composite constants */
397 LLVMValueRef
LLVMConstString(const char *Str
, unsigned Length
,
398 int DontNullTerminate
);
399 LLVMValueRef
LLVMConstArray(LLVMTypeRef ElementTy
,
400 LLVMValueRef
*ConstantVals
, unsigned Length
);
401 LLVMValueRef
LLVMConstStruct(LLVMValueRef
*ConstantVals
, unsigned Count
,
403 LLVMValueRef
LLVMConstVector(LLVMValueRef
*ScalarConstantVals
, unsigned Size
);
405 /* Constant expressions */
406 LLVMValueRef
LLVMSizeOf(LLVMTypeRef Ty
);
407 LLVMValueRef
LLVMConstNeg(LLVMValueRef ConstantVal
);
408 LLVMValueRef
LLVMConstNot(LLVMValueRef ConstantVal
);
409 LLVMValueRef
LLVMConstAdd(LLVMValueRef LHSConstant
, LLVMValueRef RHSConstant
);
410 LLVMValueRef
LLVMConstSub(LLVMValueRef LHSConstant
, LLVMValueRef RHSConstant
);
411 LLVMValueRef
LLVMConstMul(LLVMValueRef LHSConstant
, LLVMValueRef RHSConstant
);
412 LLVMValueRef
LLVMConstUDiv(LLVMValueRef LHSConstant
, LLVMValueRef RHSConstant
);
413 LLVMValueRef
LLVMConstSDiv(LLVMValueRef LHSConstant
, LLVMValueRef RHSConstant
);
414 LLVMValueRef
LLVMConstFDiv(LLVMValueRef LHSConstant
, LLVMValueRef RHSConstant
);
415 LLVMValueRef
LLVMConstURem(LLVMValueRef LHSConstant
, LLVMValueRef RHSConstant
);
416 LLVMValueRef
LLVMConstSRem(LLVMValueRef LHSConstant
, LLVMValueRef RHSConstant
);
417 LLVMValueRef
LLVMConstFRem(LLVMValueRef LHSConstant
, LLVMValueRef RHSConstant
);
418 LLVMValueRef
LLVMConstAnd(LLVMValueRef LHSConstant
, LLVMValueRef RHSConstant
);
419 LLVMValueRef
LLVMConstOr(LLVMValueRef LHSConstant
, LLVMValueRef RHSConstant
);
420 LLVMValueRef
LLVMConstXor(LLVMValueRef LHSConstant
, LLVMValueRef RHSConstant
);
421 LLVMValueRef
LLVMConstICmp(LLVMIntPredicate Predicate
,
422 LLVMValueRef LHSConstant
, LLVMValueRef RHSConstant
);
423 LLVMValueRef
LLVMConstFCmp(LLVMRealPredicate Predicate
,
424 LLVMValueRef LHSConstant
, LLVMValueRef RHSConstant
);
425 LLVMValueRef
LLVMConstShl(LLVMValueRef LHSConstant
, LLVMValueRef RHSConstant
);
426 LLVMValueRef
LLVMConstLShr(LLVMValueRef LHSConstant
, LLVMValueRef RHSConstant
);
427 LLVMValueRef
LLVMConstAShr(LLVMValueRef LHSConstant
, LLVMValueRef RHSConstant
);
428 LLVMValueRef
LLVMConstGEP(LLVMValueRef ConstantVal
,
429 LLVMValueRef
*ConstantIndices
, unsigned NumIndices
);
430 LLVMValueRef
LLVMConstTrunc(LLVMValueRef ConstantVal
, LLVMTypeRef ToType
);
431 LLVMValueRef
LLVMConstSExt(LLVMValueRef ConstantVal
, LLVMTypeRef ToType
);
432 LLVMValueRef
LLVMConstZExt(LLVMValueRef ConstantVal
, LLVMTypeRef ToType
);
433 LLVMValueRef
LLVMConstFPTrunc(LLVMValueRef ConstantVal
, LLVMTypeRef ToType
);
434 LLVMValueRef
LLVMConstFPExt(LLVMValueRef ConstantVal
, LLVMTypeRef ToType
);
435 LLVMValueRef
LLVMConstUIToFP(LLVMValueRef ConstantVal
, LLVMTypeRef ToType
);
436 LLVMValueRef
LLVMConstSIToFP(LLVMValueRef ConstantVal
, LLVMTypeRef ToType
);
437 LLVMValueRef
LLVMConstFPToUI(LLVMValueRef ConstantVal
, LLVMTypeRef ToType
);
438 LLVMValueRef
LLVMConstFPToSI(LLVMValueRef ConstantVal
, LLVMTypeRef ToType
);
439 LLVMValueRef
LLVMConstPtrToInt(LLVMValueRef ConstantVal
, LLVMTypeRef ToType
);
440 LLVMValueRef
LLVMConstIntToPtr(LLVMValueRef ConstantVal
, LLVMTypeRef ToType
);
441 LLVMValueRef
LLVMConstBitCast(LLVMValueRef ConstantVal
, LLVMTypeRef ToType
);
442 LLVMValueRef
LLVMConstSelect(LLVMValueRef ConstantCondition
,
443 LLVMValueRef ConstantIfTrue
,
444 LLVMValueRef ConstantIfFalse
);
445 LLVMValueRef
LLVMConstExtractElement(LLVMValueRef VectorConstant
,
446 LLVMValueRef IndexConstant
);
447 LLVMValueRef
LLVMConstInsertElement(LLVMValueRef VectorConstant
,
448 LLVMValueRef ElementValueConstant
,
449 LLVMValueRef IndexConstant
);
450 LLVMValueRef
LLVMConstShuffleVector(LLVMValueRef VectorAConstant
,
451 LLVMValueRef VectorBConstant
,
452 LLVMValueRef MaskConstant
);
453 LLVMValueRef
LLVMConstExtractValue(LLVMValueRef AggConstant
, unsigned *IdxList
,
455 LLVMValueRef
LLVMConstInsertValue(LLVMValueRef AggConstant
,
456 LLVMValueRef ElementValueConstant
,
457 unsigned *IdxList
, unsigned NumIdx
);
458 LLVMValueRef
LLVMConstInlineAsm(LLVMTypeRef Ty
,
459 const char *AsmString
, const char *Constraints
,
462 /* Operations on global variables, functions, and aliases (globals) */
463 LLVMModuleRef
LLVMGetGlobalParent(LLVMValueRef Global
);
464 int LLVMIsDeclaration(LLVMValueRef Global
);
465 LLVMLinkage
LLVMGetLinkage(LLVMValueRef Global
);
466 void LLVMSetLinkage(LLVMValueRef Global
, LLVMLinkage Linkage
);
467 const char *LLVMGetSection(LLVMValueRef Global
);
468 void LLVMSetSection(LLVMValueRef Global
, const char *Section
);
469 LLVMVisibility
LLVMGetVisibility(LLVMValueRef Global
);
470 void LLVMSetVisibility(LLVMValueRef Global
, LLVMVisibility Viz
);
471 unsigned LLVMGetAlignment(LLVMValueRef Global
);
472 void LLVMSetAlignment(LLVMValueRef Global
, unsigned Bytes
);
474 /* Operations on global variables */
475 LLVMValueRef
LLVMAddGlobal(LLVMModuleRef M
, LLVMTypeRef Ty
, const char *Name
);
476 LLVMValueRef
LLVMGetNamedGlobal(LLVMModuleRef M
, const char *Name
);
477 LLVMValueRef
LLVMGetFirstGlobal(LLVMModuleRef M
);
478 LLVMValueRef
LLVMGetLastGlobal(LLVMModuleRef M
);
479 LLVMValueRef
LLVMGetNextGlobal(LLVMValueRef GlobalVar
);
480 LLVMValueRef
LLVMGetPreviousGlobal(LLVMValueRef GlobalVar
);
481 void LLVMDeleteGlobal(LLVMValueRef GlobalVar
);
482 LLVMValueRef
LLVMGetInitializer(LLVMValueRef GlobalVar
);
483 void LLVMSetInitializer(LLVMValueRef GlobalVar
, LLVMValueRef ConstantVal
);
484 int LLVMIsThreadLocal(LLVMValueRef GlobalVar
);
485 void LLVMSetThreadLocal(LLVMValueRef GlobalVar
, int IsThreadLocal
);
486 int LLVMIsGlobalConstant(LLVMValueRef GlobalVar
);
487 void LLVMSetGlobalConstant(LLVMValueRef GlobalVar
, int IsConstant
);
489 /* Operations on aliases */
490 LLVMValueRef
LLVMAddAlias(LLVMModuleRef M
, LLVMTypeRef Ty
, LLVMValueRef Aliasee
,
493 /* Operations on functions */
494 LLVMValueRef
LLVMAddFunction(LLVMModuleRef M
, const char *Name
,
495 LLVMTypeRef FunctionTy
);
496 LLVMValueRef
LLVMGetNamedFunction(LLVMModuleRef M
, const char *Name
);
497 LLVMValueRef
LLVMGetFirstFunction(LLVMModuleRef M
);
498 LLVMValueRef
LLVMGetLastFunction(LLVMModuleRef M
);
499 LLVMValueRef
LLVMGetNextFunction(LLVMValueRef Fn
);
500 LLVMValueRef
LLVMGetPreviousFunction(LLVMValueRef Fn
);
501 void LLVMDeleteFunction(LLVMValueRef Fn
);
502 unsigned LLVMGetIntrinsicID(LLVMValueRef Fn
);
503 unsigned LLVMGetFunctionCallConv(LLVMValueRef Fn
);
504 void LLVMSetFunctionCallConv(LLVMValueRef Fn
, unsigned CC
);
505 const char *LLVMGetGC(LLVMValueRef Fn
);
506 void LLVMSetGC(LLVMValueRef Fn
, const char *Name
);
508 /* Operations on parameters */
509 unsigned LLVMCountParams(LLVMValueRef Fn
);
510 void LLVMGetParams(LLVMValueRef Fn
, LLVMValueRef
*Params
);
511 LLVMValueRef
LLVMGetParam(LLVMValueRef Fn
, unsigned Index
);
512 LLVMValueRef
LLVMGetParamParent(LLVMValueRef Inst
);
513 LLVMValueRef
LLVMGetFirstParam(LLVMValueRef Fn
);
514 LLVMValueRef
LLVMGetLastParam(LLVMValueRef Fn
);
515 LLVMValueRef
LLVMGetNextParam(LLVMValueRef Arg
);
516 LLVMValueRef
LLVMGetPreviousParam(LLVMValueRef Arg
);
517 void LLVMAddAttribute(LLVMValueRef Arg
, LLVMAttribute PA
);
518 void LLVMRemoveAttribute(LLVMValueRef Arg
, LLVMAttribute PA
);
519 void LLVMSetParamAlignment(LLVMValueRef Arg
, unsigned align
);
521 /* Operations on basic blocks */
522 LLVMValueRef
LLVMBasicBlockAsValue(LLVMBasicBlockRef BB
);
523 int LLVMValueIsBasicBlock(LLVMValueRef Val
);
524 LLVMBasicBlockRef
LLVMValueAsBasicBlock(LLVMValueRef Val
);
525 LLVMValueRef
LLVMGetBasicBlockParent(LLVMBasicBlockRef BB
);
526 unsigned LLVMCountBasicBlocks(LLVMValueRef Fn
);
527 void LLVMGetBasicBlocks(LLVMValueRef Fn
, LLVMBasicBlockRef
*BasicBlocks
);
528 LLVMBasicBlockRef
LLVMGetFirstBasicBlock(LLVMValueRef Fn
);
529 LLVMBasicBlockRef
LLVMGetLastBasicBlock(LLVMValueRef Fn
);
530 LLVMBasicBlockRef
LLVMGetNextBasicBlock(LLVMBasicBlockRef BB
);
531 LLVMBasicBlockRef
LLVMGetPreviousBasicBlock(LLVMBasicBlockRef BB
);
532 LLVMBasicBlockRef
LLVMGetEntryBasicBlock(LLVMValueRef Fn
);
533 LLVMBasicBlockRef
LLVMAppendBasicBlock(LLVMValueRef Fn
, const char *Name
);
534 LLVMBasicBlockRef
LLVMInsertBasicBlock(LLVMBasicBlockRef InsertBeforeBB
,
536 void LLVMDeleteBasicBlock(LLVMBasicBlockRef BB
);
538 /* Operations on instructions */
539 LLVMBasicBlockRef
LLVMGetInstructionParent(LLVMValueRef Inst
);
540 LLVMValueRef
LLVMGetFirstInstruction(LLVMBasicBlockRef BB
);
541 LLVMValueRef
LLVMGetLastInstruction(LLVMBasicBlockRef BB
);
542 LLVMValueRef
LLVMGetNextInstruction(LLVMValueRef Inst
);
543 LLVMValueRef
LLVMGetPreviousInstruction(LLVMValueRef Inst
);
545 /* Operations on call sites */
546 void LLVMSetInstructionCallConv(LLVMValueRef Instr
, unsigned CC
);
547 unsigned LLVMGetInstructionCallConv(LLVMValueRef Instr
);
548 void LLVMAddInstrAttribute(LLVMValueRef Instr
, unsigned index
, LLVMAttribute
);
549 void LLVMRemoveInstrAttribute(LLVMValueRef Instr
, unsigned index
,
551 void LLVMSetInstrParamAlignment(LLVMValueRef Instr
, unsigned index
,
554 /* Operations on call instructions (only) */
555 int LLVMIsTailCall(LLVMValueRef CallInst
);
556 void LLVMSetTailCall(LLVMValueRef CallInst
, int IsTailCall
);
558 /* Operations on phi nodes */
559 void LLVMAddIncoming(LLVMValueRef PhiNode
, LLVMValueRef
*IncomingValues
,
560 LLVMBasicBlockRef
*IncomingBlocks
, unsigned Count
);
561 unsigned LLVMCountIncoming(LLVMValueRef PhiNode
);
562 LLVMValueRef
LLVMGetIncomingValue(LLVMValueRef PhiNode
, unsigned Index
);
563 LLVMBasicBlockRef
LLVMGetIncomingBlock(LLVMValueRef PhiNode
, unsigned Index
);
565 /*===-- Instruction builders ----------------------------------------------===*/
567 /* An instruction builder represents a point within a basic block, and is the
568 * exclusive means of building instructions using the C interface.
571 LLVMBuilderRef
LLVMCreateBuilder(void);
572 void LLVMPositionBuilder(LLVMBuilderRef Builder
, LLVMBasicBlockRef Block
,
574 void LLVMPositionBuilderBefore(LLVMBuilderRef Builder
, LLVMValueRef Instr
);
575 void LLVMPositionBuilderAtEnd(LLVMBuilderRef Builder
, LLVMBasicBlockRef Block
);
576 LLVMBasicBlockRef
LLVMGetInsertBlock(LLVMBuilderRef Builder
);
577 void LLVMClearInsertionPosition(LLVMBuilderRef Builder
);
578 void LLVMInsertIntoBuilder(LLVMBuilderRef Builder
, LLVMValueRef Instr
);
579 void LLVMDisposeBuilder(LLVMBuilderRef Builder
);
582 LLVMValueRef
LLVMBuildRetVoid(LLVMBuilderRef
);
583 LLVMValueRef
LLVMBuildRet(LLVMBuilderRef
, LLVMValueRef V
);
584 LLVMValueRef
LLVMBuildBr(LLVMBuilderRef
, LLVMBasicBlockRef Dest
);
585 LLVMValueRef
LLVMBuildCondBr(LLVMBuilderRef
, LLVMValueRef If
,
586 LLVMBasicBlockRef Then
, LLVMBasicBlockRef Else
);
587 LLVMValueRef
LLVMBuildSwitch(LLVMBuilderRef
, LLVMValueRef V
,
588 LLVMBasicBlockRef Else
, unsigned NumCases
);
589 LLVMValueRef
LLVMBuildInvoke(LLVMBuilderRef
, LLVMValueRef Fn
,
590 LLVMValueRef
*Args
, unsigned NumArgs
,
591 LLVMBasicBlockRef Then
, LLVMBasicBlockRef Catch
,
593 LLVMValueRef
LLVMBuildUnwind(LLVMBuilderRef
);
594 LLVMValueRef
LLVMBuildUnreachable(LLVMBuilderRef
);
596 /* Add a case to the switch instruction */
597 void LLVMAddCase(LLVMValueRef Switch
, LLVMValueRef OnVal
,
598 LLVMBasicBlockRef Dest
);
601 LLVMValueRef
LLVMBuildAdd(LLVMBuilderRef
, LLVMValueRef LHS
, LLVMValueRef RHS
,
603 LLVMValueRef
LLVMBuildSub(LLVMBuilderRef
, LLVMValueRef LHS
, LLVMValueRef RHS
,
605 LLVMValueRef
LLVMBuildMul(LLVMBuilderRef
, LLVMValueRef LHS
, LLVMValueRef RHS
,
607 LLVMValueRef
LLVMBuildUDiv(LLVMBuilderRef
, LLVMValueRef LHS
, LLVMValueRef RHS
,
609 LLVMValueRef
LLVMBuildSDiv(LLVMBuilderRef
, LLVMValueRef LHS
, LLVMValueRef RHS
,
611 LLVMValueRef
LLVMBuildFDiv(LLVMBuilderRef
, LLVMValueRef LHS
, LLVMValueRef RHS
,
613 LLVMValueRef
LLVMBuildURem(LLVMBuilderRef
, LLVMValueRef LHS
, LLVMValueRef RHS
,
615 LLVMValueRef
LLVMBuildSRem(LLVMBuilderRef
, LLVMValueRef LHS
, LLVMValueRef RHS
,
617 LLVMValueRef
LLVMBuildFRem(LLVMBuilderRef
, LLVMValueRef LHS
, LLVMValueRef RHS
,
619 LLVMValueRef
LLVMBuildShl(LLVMBuilderRef
, LLVMValueRef LHS
, LLVMValueRef RHS
,
621 LLVMValueRef
LLVMBuildLShr(LLVMBuilderRef
, LLVMValueRef LHS
, LLVMValueRef RHS
,
623 LLVMValueRef
LLVMBuildAShr(LLVMBuilderRef
, LLVMValueRef LHS
, LLVMValueRef RHS
,
625 LLVMValueRef
LLVMBuildAnd(LLVMBuilderRef
, LLVMValueRef LHS
, LLVMValueRef RHS
,
627 LLVMValueRef
LLVMBuildOr(LLVMBuilderRef
, LLVMValueRef LHS
, LLVMValueRef RHS
,
629 LLVMValueRef
LLVMBuildXor(LLVMBuilderRef
, LLVMValueRef LHS
, LLVMValueRef RHS
,
631 LLVMValueRef
LLVMBuildNeg(LLVMBuilderRef
, LLVMValueRef V
, const char *Name
);
632 LLVMValueRef
LLVMBuildNot(LLVMBuilderRef
, LLVMValueRef V
, const char *Name
);
635 LLVMValueRef
LLVMBuildMalloc(LLVMBuilderRef
, LLVMTypeRef Ty
, const char *Name
);
636 LLVMValueRef
LLVMBuildArrayMalloc(LLVMBuilderRef
, LLVMTypeRef Ty
,
637 LLVMValueRef Val
, const char *Name
);
638 LLVMValueRef
LLVMBuildAlloca(LLVMBuilderRef
, LLVMTypeRef Ty
, const char *Name
);
639 LLVMValueRef
LLVMBuildArrayAlloca(LLVMBuilderRef
, LLVMTypeRef Ty
,
640 LLVMValueRef Val
, const char *Name
);
641 LLVMValueRef
LLVMBuildFree(LLVMBuilderRef
, LLVMValueRef PointerVal
);
642 LLVMValueRef
LLVMBuildLoad(LLVMBuilderRef
, LLVMValueRef PointerVal
,
644 LLVMValueRef
LLVMBuildStore(LLVMBuilderRef
, LLVMValueRef Val
, LLVMValueRef Ptr
);
645 LLVMValueRef
LLVMBuildGEP(LLVMBuilderRef B
, LLVMValueRef Pointer
,
646 LLVMValueRef
*Indices
, unsigned NumIndices
,
650 LLVMValueRef
LLVMBuildTrunc(LLVMBuilderRef
, LLVMValueRef Val
,
651 LLVMTypeRef DestTy
, const char *Name
);
652 LLVMValueRef
LLVMBuildZExt(LLVMBuilderRef
, LLVMValueRef Val
,
653 LLVMTypeRef DestTy
, const char *Name
);
654 LLVMValueRef
LLVMBuildSExt(LLVMBuilderRef
, LLVMValueRef Val
,
655 LLVMTypeRef DestTy
, const char *Name
);
656 LLVMValueRef
LLVMBuildFPToUI(LLVMBuilderRef
, LLVMValueRef Val
,
657 LLVMTypeRef DestTy
, const char *Name
);
658 LLVMValueRef
LLVMBuildFPToSI(LLVMBuilderRef
, LLVMValueRef Val
,
659 LLVMTypeRef DestTy
, const char *Name
);
660 LLVMValueRef
LLVMBuildUIToFP(LLVMBuilderRef
, LLVMValueRef Val
,
661 LLVMTypeRef DestTy
, const char *Name
);
662 LLVMValueRef
LLVMBuildSIToFP(LLVMBuilderRef
, LLVMValueRef Val
,
663 LLVMTypeRef DestTy
, const char *Name
);
664 LLVMValueRef
LLVMBuildFPTrunc(LLVMBuilderRef
, LLVMValueRef Val
,
665 LLVMTypeRef DestTy
, const char *Name
);
666 LLVMValueRef
LLVMBuildFPExt(LLVMBuilderRef
, LLVMValueRef Val
,
667 LLVMTypeRef DestTy
, const char *Name
);
668 LLVMValueRef
LLVMBuildPtrToInt(LLVMBuilderRef
, LLVMValueRef Val
,
669 LLVMTypeRef DestTy
, const char *Name
);
670 LLVMValueRef
LLVMBuildIntToPtr(LLVMBuilderRef
, LLVMValueRef Val
,
671 LLVMTypeRef DestTy
, const char *Name
);
672 LLVMValueRef
LLVMBuildBitCast(LLVMBuilderRef
, LLVMValueRef Val
,
673 LLVMTypeRef DestTy
, const char *Name
);
676 LLVMValueRef
LLVMBuildICmp(LLVMBuilderRef
, LLVMIntPredicate Op
,
677 LLVMValueRef LHS
, LLVMValueRef RHS
,
679 LLVMValueRef
LLVMBuildFCmp(LLVMBuilderRef
, LLVMRealPredicate Op
,
680 LLVMValueRef LHS
, LLVMValueRef RHS
,
683 /* Miscellaneous instructions */
684 LLVMValueRef
LLVMBuildPhi(LLVMBuilderRef
, LLVMTypeRef Ty
, const char *Name
);
685 LLVMValueRef
LLVMBuildCall(LLVMBuilderRef
, LLVMValueRef Fn
,
686 LLVMValueRef
*Args
, unsigned NumArgs
,
688 LLVMValueRef
LLVMBuildSelect(LLVMBuilderRef
, LLVMValueRef If
,
689 LLVMValueRef Then
, LLVMValueRef Else
,
691 LLVMValueRef
LLVMBuildVAArg(LLVMBuilderRef
, LLVMValueRef List
, LLVMTypeRef Ty
,
693 LLVMValueRef
LLVMBuildExtractElement(LLVMBuilderRef
, LLVMValueRef VecVal
,
694 LLVMValueRef Index
, const char *Name
);
695 LLVMValueRef
LLVMBuildInsertElement(LLVMBuilderRef
, LLVMValueRef VecVal
,
696 LLVMValueRef EltVal
, LLVMValueRef Index
,
698 LLVMValueRef
LLVMBuildShuffleVector(LLVMBuilderRef
, LLVMValueRef V1
,
699 LLVMValueRef V2
, LLVMValueRef Mask
,
701 LLVMValueRef
LLVMBuildExtractValue(LLVMBuilderRef
, LLVMValueRef AggVal
,
702 unsigned Index
, const char *Name
);
703 LLVMValueRef
LLVMBuildInsertValue(LLVMBuilderRef
, LLVMValueRef AggVal
,
704 LLVMValueRef EltVal
, unsigned Index
,
708 /*===-- Module providers --------------------------------------------------===*/
710 /* Encapsulates the module M in a module provider, taking ownership of the
712 * See the constructor llvm::ExistingModuleProvider::ExistingModuleProvider.
714 LLVMModuleProviderRef
715 LLVMCreateModuleProviderForExistingModule(LLVMModuleRef M
);
717 /* Destroys the module provider MP as well as the contained module.
718 * See the destructor llvm::ModuleProvider::~ModuleProvider.
720 void LLVMDisposeModuleProvider(LLVMModuleProviderRef MP
);
723 /*===-- Memory buffers ----------------------------------------------------===*/
725 int LLVMCreateMemoryBufferWithContentsOfFile(const char *Path
,
726 LLVMMemoryBufferRef
*OutMemBuf
,
728 int LLVMCreateMemoryBufferWithSTDIN(LLVMMemoryBufferRef
*OutMemBuf
,
730 void LLVMDisposeMemoryBuffer(LLVMMemoryBufferRef MemBuf
);
733 /*===-- Pass Managers -----------------------------------------------------===*/
735 /** Constructs a new whole-module pass pipeline. This type of pipeline is
736 suitable for link-time optimization and whole-module transformations.
737 See llvm::PassManager::PassManager. */
738 LLVMPassManagerRef
LLVMCreatePassManager(void);
740 /** Constructs a new function-by-function pass pipeline over the module
741 provider. It does not take ownership of the module provider. This type of
742 pipeline is suitable for code generation and JIT compilation tasks.
743 See llvm::FunctionPassManager::FunctionPassManager. */
744 LLVMPassManagerRef
LLVMCreateFunctionPassManager(LLVMModuleProviderRef MP
);
746 /** Initializes, executes on the provided module, and finalizes all of the
747 passes scheduled in the pass manager. Returns 1 if any of the passes
748 modified the module, 0 otherwise. See llvm::PassManager::run(Module&). */
749 int LLVMRunPassManager(LLVMPassManagerRef PM
, LLVMModuleRef M
);
751 /** Initializes all of the function passes scheduled in the function pass
752 manager. Returns 1 if any of the passes modified the module, 0 otherwise.
753 See llvm::FunctionPassManager::doInitialization. */
754 int LLVMInitializeFunctionPassManager(LLVMPassManagerRef FPM
);
756 /** Executes all of the function passes scheduled in the function pass manager
757 on the provided function. Returns 1 if any of the passes modified the
758 function, false otherwise.
759 See llvm::FunctionPassManager::run(Function&). */
760 int LLVMRunFunctionPassManager(LLVMPassManagerRef FPM
, LLVMValueRef F
);
762 /** Finalizes all of the function passes scheduled in in the function pass
763 manager. Returns 1 if any of the passes modified the module, 0 otherwise.
764 See llvm::FunctionPassManager::doFinalization. */
765 int LLVMFinalizeFunctionPassManager(LLVMPassManagerRef FPM
);
767 /** Frees the memory of a pass pipeline. For function pipelines, does not free
769 See llvm::PassManagerBase::~PassManagerBase. */
770 void LLVMDisposePassManager(LLVMPassManagerRef PM
);
777 class ModuleProvider
;
779 class PassManagerBase
;
781 #define DEFINE_SIMPLE_CONVERSION_FUNCTIONS(ty, ref) \
782 inline ty *unwrap(ref P) { \
783 return reinterpret_cast<ty*>(P); \
786 inline ref wrap(const ty *P) { \
787 return reinterpret_cast<ref>(const_cast<ty*>(P)); \
790 #define DEFINE_ISA_CONVERSION_FUNCTIONS(ty, ref) \
791 DEFINE_SIMPLE_CONVERSION_FUNCTIONS(ty, ref) \
793 template<typename T> \
794 inline T *unwrap(ref P) { \
795 return cast<T>(unwrap(P)); \
798 #define DEFINE_STDCXX_CONVERSION_FUNCTIONS(ty, ref) \
799 DEFINE_SIMPLE_CONVERSION_FUNCTIONS(ty, ref) \
801 template<typename T> \
802 inline T *unwrap(ref P) { \
803 T *Q = dynamic_cast<T*>(unwrap(P)); \
804 assert(Q && "Invalid cast!"); \
808 DEFINE_ISA_CONVERSION_FUNCTIONS (Type
, LLVMTypeRef
)
809 DEFINE_ISA_CONVERSION_FUNCTIONS (Value
, LLVMValueRef
)
810 DEFINE_SIMPLE_CONVERSION_FUNCTIONS(Module
, LLVMModuleRef
)
811 DEFINE_SIMPLE_CONVERSION_FUNCTIONS(BasicBlock
, LLVMBasicBlockRef
)
812 DEFINE_SIMPLE_CONVERSION_FUNCTIONS(IRBuilder
<>, LLVMBuilderRef
)
813 DEFINE_SIMPLE_CONVERSION_FUNCTIONS(PATypeHolder
, LLVMTypeHandleRef
)
814 DEFINE_SIMPLE_CONVERSION_FUNCTIONS(ModuleProvider
, LLVMModuleProviderRef
)
815 DEFINE_SIMPLE_CONVERSION_FUNCTIONS(MemoryBuffer
, LLVMMemoryBufferRef
)
816 DEFINE_STDCXX_CONVERSION_FUNCTIONS(PassManagerBase
, LLVMPassManagerRef
)
818 #undef DEFINE_STDCXX_CONVERSION_FUNCTIONS
819 #undef DEFINE_ISA_CONVERSION_FUNCTIONS
820 #undef DEFINE_SIMPLE_CONVERSION_FUNCTIONS
822 /* Specialized opaque type conversions.
824 inline Type
**unwrap(LLVMTypeRef
* Tys
) {
825 return reinterpret_cast<Type
**>(Tys
);
828 inline LLVMTypeRef
*wrap(const Type
**Tys
) {
829 return reinterpret_cast<LLVMTypeRef
*>(const_cast<Type
**>(Tys
));
832 /* Specialized opaque value conversions.
834 inline Value
**unwrap(LLVMValueRef
*Vals
) {
835 return reinterpret_cast<Value
**>(Vals
);
839 inline T
**unwrap(LLVMValueRef
*Vals
, unsigned Length
) {
841 for (LLVMValueRef
*I
= Vals
, E
= Vals
+ Length
; I
!= E
; ++I
)
844 return reinterpret_cast<T
**>(Vals
);
847 inline LLVMValueRef
*wrap(const Value
**Vals
) {
848 return reinterpret_cast<LLVMValueRef
*>(const_cast<Value
**>(Vals
));
852 #endif /* !defined(__cplusplus) */
854 #endif /* !defined(LLVM_C_CORE_H) */