1 /*===-- llvm-c/Core.h - Core Library C Interface ------------------*- C -*-===*\
3 |* The LLVM Compiler Infrastructure *|
5 |* This file is distributed under the University of Illinois Open Source *|
6 |* License. See LICENSE.TXT for details. *|
8 |*===----------------------------------------------------------------------===*|
10 |* This header declares the C interface to libLLVMCore.a, which implements *|
11 |* the LLVM intermediate representation. *|
13 |* LLVM uses a polymorphic type hierarchy which C cannot represent, therefore *|
14 |* parameters must be passed as base types. Despite the declared types, most *|
15 |* of the functions provided operate only on branches of the type hierarchy. *|
16 |* The declared parameter names are descriptive and specify which type is *|
17 |* required. Additionally, each type hierarchy is documented along with the *|
18 |* functions that operate upon it. For more detail, refer to LLVM's C++ code. *|
19 |* If in doubt, refer to Core.cpp, which performs paramter downcasts in the *|
20 |* form unwrap<RequiredType>(Param). *|
22 |* Many exotic languages can interoperate with C code but have a harder time *|
23 |* with C++ due to name mangling. So in addition to C, this interface enables *|
24 |* tools written in such languages. *|
26 |* When included into a C++ source file, also declares 'wrap' and 'unwrap' *|
27 |* helpers to perform opaque reference<-->pointer conversions. These helpers *|
28 |* are shorter and more tightly typed than writing the casts by hand when *|
29 |* authoring bindings. In assert builds, they will do runtime type checking. *|
31 \*===----------------------------------------------------------------------===*/
38 /* Need these includes to support the LLVM 'cast' template for the C++ 'wrap'
39 and 'unwrap' conversion functions. */
40 #include "llvm/Module.h"
41 #include "llvm/Support/IRBuilder.h"
50 * The top-level container for all LLVM global data. See the LLVMContext class.
52 typedef struct LLVMCtxt
*LLVMContextRef
;
55 * The top-level container for all other LLVM Intermediate Representation (IR)
56 * objects. See the llvm::Module class.
58 typedef struct LLVMOpaqueModule
*LLVMModuleRef
;
61 * Each value in the LLVM IR has a type, an LLVMTypeRef. See the llvm::Type
64 typedef struct LLVMOpaqueType
*LLVMTypeRef
;
67 * When building recursive types using LLVMRefineType, LLVMTypeRef values may
68 * become invalid; use LLVMTypeHandleRef to resolve this problem. See the
69 * llvm::AbstractTypeHolder class.
71 typedef struct LLVMOpaqueTypeHandle
*LLVMTypeHandleRef
;
73 typedef struct LLVMOpaqueValue
*LLVMValueRef
;
74 typedef struct LLVMOpaqueBasicBlock
*LLVMBasicBlockRef
;
75 typedef struct LLVMOpaqueBuilder
*LLVMBuilderRef
;
77 /* Used to provide a module to JIT or interpreter.
78 * See the llvm::ModuleProvider class.
80 typedef struct LLVMOpaqueModuleProvider
*LLVMModuleProviderRef
;
82 /* Used to provide a module to JIT or interpreter.
83 * See the llvm::MemoryBuffer class.
85 typedef struct LLVMOpaqueMemoryBuffer
*LLVMMemoryBufferRef
;
87 /** See the llvm::PassManagerBase class. */
88 typedef struct LLVMOpaquePassManager
*LLVMPassManagerRef
;
91 LLVMZExtAttribute
= 1<<0,
92 LLVMSExtAttribute
= 1<<1,
93 LLVMNoReturnAttribute
= 1<<2,
94 LLVMInRegAttribute
= 1<<3,
95 LLVMStructRetAttribute
= 1<<4,
96 LLVMNoUnwindAttribute
= 1<<5,
97 LLVMNoAliasAttribute
= 1<<6,
98 LLVMByValAttribute
= 1<<7,
99 LLVMNestAttribute
= 1<<8,
100 LLVMReadNoneAttribute
= 1<<9,
101 LLVMReadOnlyAttribute
= 1<<10
105 LLVMVoidTypeKind
, /**< type with no size */
106 LLVMFloatTypeKind
, /**< 32 bit floating point type */
107 LLVMDoubleTypeKind
, /**< 64 bit floating point type */
108 LLVMX86_FP80TypeKind
, /**< 80 bit floating point type (X87) */
109 LLVMFP128TypeKind
, /**< 128 bit floating point type (112-bit mantissa)*/
110 LLVMPPC_FP128TypeKind
, /**< 128 bit floating point type (two 64-bits) */
111 LLVMLabelTypeKind
, /**< Labels */
112 LLVMIntegerTypeKind
, /**< Arbitrary bit width integers */
113 LLVMFunctionTypeKind
, /**< Functions */
114 LLVMStructTypeKind
, /**< Structures */
115 LLVMArrayTypeKind
, /**< Arrays */
116 LLVMPointerTypeKind
, /**< Pointers */
117 LLVMOpaqueTypeKind
, /**< Opaque: type with unknown structure */
118 LLVMVectorTypeKind
, /**< SIMD 'packed' format, or other vector type */
119 LLVMMetadataTypeKind
/**< Metadata */
123 LLVMExternalLinkage
, /**< Externally visible function */
124 LLVMAvailableExternallyLinkage
,
125 LLVMLinkOnceAnyLinkage
, /**< Keep one copy of function when linking (inline)*/
126 LLVMLinkOnceODRLinkage
, /**< Same, but only replaced by something
128 LLVMWeakAnyLinkage
, /**< Keep one copy of function when linking (weak) */
129 LLVMWeakODRLinkage
, /**< Same, but only replaced by something
131 LLVMAppendingLinkage
, /**< Special purpose, only applies to global arrays */
132 LLVMInternalLinkage
, /**< Rename collisions when linking (static
134 LLVMPrivateLinkage
, /**< Like Internal, but omit from symbol table */
135 LLVMDLLImportLinkage
, /**< Function to be imported from DLL */
136 LLVMDLLExportLinkage
, /**< Function to be accessible from DLL */
137 LLVMExternalWeakLinkage
,/**< ExternalWeak linkage description */
138 LLVMGhostLinkage
, /**< Stand-in functions for streaming fns from
140 LLVMCommonLinkage
/**< Tentative definitions */
144 LLVMDefaultVisibility
, /**< The GV is visible */
145 LLVMHiddenVisibility
, /**< The GV is hidden */
146 LLVMProtectedVisibility
/**< The GV is protected */
151 LLVMFastCallConv
= 8,
152 LLVMColdCallConv
= 9,
153 LLVMX86StdcallCallConv
= 64,
154 LLVMX86FastcallCallConv
= 65
158 LLVMIntEQ
= 32, /**< equal */
159 LLVMIntNE
, /**< not equal */
160 LLVMIntUGT
, /**< unsigned greater than */
161 LLVMIntUGE
, /**< unsigned greater or equal */
162 LLVMIntULT
, /**< unsigned less than */
163 LLVMIntULE
, /**< unsigned less or equal */
164 LLVMIntSGT
, /**< signed greater than */
165 LLVMIntSGE
, /**< signed greater or equal */
166 LLVMIntSLT
, /**< signed less than */
167 LLVMIntSLE
/**< signed less or equal */
171 LLVMRealPredicateFalse
, /**< Always false (always folded) */
172 LLVMRealOEQ
, /**< True if ordered and equal */
173 LLVMRealOGT
, /**< True if ordered and greater than */
174 LLVMRealOGE
, /**< True if ordered and greater than or equal */
175 LLVMRealOLT
, /**< True if ordered and less than */
176 LLVMRealOLE
, /**< True if ordered and less than or equal */
177 LLVMRealONE
, /**< True if ordered and operands are unequal */
178 LLVMRealORD
, /**< True if ordered (no nans) */
179 LLVMRealUNO
, /**< True if unordered: isnan(X) | isnan(Y) */
180 LLVMRealUEQ
, /**< True if unordered or equal */
181 LLVMRealUGT
, /**< True if unordered or greater than */
182 LLVMRealUGE
, /**< True if unordered, greater than, or equal */
183 LLVMRealULT
, /**< True if unordered or less than */
184 LLVMRealULE
, /**< True if unordered, less than, or equal */
185 LLVMRealUNE
, /**< True if unordered or not equal */
186 LLVMRealPredicateTrue
/**< Always true (always folded) */
190 /*===-- Error handling ----------------------------------------------------===*/
192 void LLVMDisposeMessage(char *Message
);
195 /*===-- Modules -----------------------------------------------------------===*/
197 /* Create and destroy contexts. */
198 LLVMContextRef
LLVMContextCreate();
199 LLVMContextRef
LLVMGetGlobalContext();
200 void LLVMContextDispose(LLVMContextRef C
);
202 /* Create and destroy modules. */
203 /** See llvm::Module::Module. */
204 LLVMModuleRef
LLVMModuleCreateWithName(const char *ModuleID
);
205 LLVMModuleRef
LLVMModuleCreateWithNameInContext(const char *ModuleID
,
208 /** See llvm::Module::~Module. */
209 void LLVMDisposeModule(LLVMModuleRef M
);
211 /** Data layout. See Module::getDataLayout. */
212 const char *LLVMGetDataLayout(LLVMModuleRef M
);
213 void LLVMSetDataLayout(LLVMModuleRef M
, const char *Triple
);
215 /** Target triple. See Module::getTargetTriple. */
216 const char *LLVMGetTarget(LLVMModuleRef M
);
217 void LLVMSetTarget(LLVMModuleRef M
, const char *Triple
);
219 /** See Module::addTypeName. */
220 int LLVMAddTypeName(LLVMModuleRef M
, const char *Name
, LLVMTypeRef Ty
);
221 void LLVMDeleteTypeName(LLVMModuleRef M
, const char *Name
);
222 LLVMTypeRef
LLVMGetTypeByName(LLVMModuleRef M
, const char *Name
);
224 /** See Module::dump. */
225 void LLVMDumpModule(LLVMModuleRef M
);
228 /*===-- Types -------------------------------------------------------------===*/
230 /* LLVM types conform to the following hierarchy:
245 /** See llvm::LLVMTypeKind::getTypeID. */
246 LLVMTypeKind
LLVMGetTypeKind(LLVMTypeRef Ty
);
248 /* Operations on integer types */
249 LLVMTypeRef
LLVMInt1Type(void);
250 LLVMTypeRef
LLVMInt8Type(void);
251 LLVMTypeRef
LLVMInt16Type(void);
252 LLVMTypeRef
LLVMInt32Type(void);
253 LLVMTypeRef
LLVMInt64Type(void);
254 LLVMTypeRef
LLVMIntType(unsigned NumBits
);
255 unsigned LLVMGetIntTypeWidth(LLVMTypeRef IntegerTy
);
257 /* Operations on real types */
258 LLVMTypeRef
LLVMFloatType(void);
259 LLVMTypeRef
LLVMDoubleType(void);
260 LLVMTypeRef
LLVMX86FP80Type(void);
261 LLVMTypeRef
LLVMFP128Type(void);
262 LLVMTypeRef
LLVMPPCFP128Type(void);
264 /* Operations on function types */
265 LLVMTypeRef
LLVMFunctionType(LLVMTypeRef ReturnType
,
266 LLVMTypeRef
*ParamTypes
, unsigned ParamCount
,
268 int LLVMIsFunctionVarArg(LLVMTypeRef FunctionTy
);
269 LLVMTypeRef
LLVMGetReturnType(LLVMTypeRef FunctionTy
);
270 unsigned LLVMCountParamTypes(LLVMTypeRef FunctionTy
);
271 void LLVMGetParamTypes(LLVMTypeRef FunctionTy
, LLVMTypeRef
*Dest
);
273 /* Operations on struct types */
274 LLVMTypeRef
LLVMStructType(LLVMTypeRef
*ElementTypes
, unsigned ElementCount
,
276 unsigned LLVMCountStructElementTypes(LLVMTypeRef StructTy
);
277 void LLVMGetStructElementTypes(LLVMTypeRef StructTy
, LLVMTypeRef
*Dest
);
278 int LLVMIsPackedStruct(LLVMTypeRef StructTy
);
280 /* Operations on array, pointer, and vector types (sequence types) */
281 LLVMTypeRef
LLVMArrayType(LLVMTypeRef ElementType
, unsigned ElementCount
);
282 LLVMTypeRef
LLVMPointerType(LLVMTypeRef ElementType
, unsigned AddressSpace
);
283 LLVMTypeRef
LLVMVectorType(LLVMTypeRef ElementType
, unsigned ElementCount
);
285 LLVMTypeRef
LLVMGetElementType(LLVMTypeRef Ty
);
286 unsigned LLVMGetArrayLength(LLVMTypeRef ArrayTy
);
287 unsigned LLVMGetPointerAddressSpace(LLVMTypeRef PointerTy
);
288 unsigned LLVMGetVectorSize(LLVMTypeRef VectorTy
);
290 /* Operations on other types */
291 LLVMTypeRef
LLVMVoidType(void);
292 LLVMTypeRef
LLVMLabelType(void);
293 LLVMTypeRef
LLVMOpaqueType(void);
295 /* Operations on type handles */
296 LLVMTypeHandleRef
LLVMCreateTypeHandle(LLVMTypeRef PotentiallyAbstractTy
);
297 void LLVMRefineType(LLVMTypeRef AbstractTy
, LLVMTypeRef ConcreteTy
);
298 LLVMTypeRef
LLVMResolveTypeHandle(LLVMTypeHandleRef TypeHandle
);
299 void LLVMDisposeTypeHandle(LLVMTypeHandleRef TypeHandle
);
302 /*===-- Values ------------------------------------------------------------===*/
304 /* The bulk of LLVM's object model consists of values, which comprise a very
305 * rich type hierarchy.
308 #define LLVM_FOR_EACH_VALUE_SUBCLASS(macro) \
314 macro(ConstantAggregateZero) \
315 macro(ConstantArray) \
316 macro(ConstantExpr) \
319 macro(ConstantPointerNull) \
320 macro(ConstantStruct) \
321 macro(ConstantVector) \
325 macro(GlobalVariable) \
328 macro(BinaryOperator) \
330 macro(IntrinsicInst) \
331 macro(DbgInfoIntrinsic) \
332 macro(DbgDeclareInst) \
333 macro(DbgFuncStartInst) \
334 macro(DbgRegionEndInst) \
335 macro(DbgRegionStartInst) \
336 macro(DbgStopPointInst) \
337 macro(EHSelectorInst) \
338 macro(MemIntrinsic) \
345 macro(ExtractElementInst) \
346 macro(GetElementPtrInst) \
347 macro(InsertElementInst) \
348 macro(InsertValueInst) \
351 macro(ShuffleVectorInst) \
353 macro(TerminatorInst) \
358 macro(UnreachableInst) \
360 macro(UnaryInstruction) \
361 macro(AllocationInst) \
370 macro(IntToPtrInst) \
371 macro(PtrToIntInst) \
377 macro(ExtractValueInst) \
382 /* Operations on all values */
383 LLVMTypeRef
LLVMTypeOf(LLVMValueRef Val
);
384 const char *LLVMGetValueName(LLVMValueRef Val
);
385 void LLVMSetValueName(LLVMValueRef Val
, const char *Name
);
386 void LLVMDumpValue(LLVMValueRef Val
);
388 /* Conversion functions. Return the input value if it is an instance of the
389 specified class, otherwise NULL. See llvm::dyn_cast_or_null<>. */
390 #define LLVM_DECLARE_VALUE_CAST(name) \
391 LLVMValueRef LLVMIsA##name(LLVMValueRef Val);
392 LLVM_FOR_EACH_VALUE_SUBCLASS(LLVM_DECLARE_VALUE_CAST
)
394 /* Operations on constants of any type */
395 LLVMValueRef
LLVMConstNull(LLVMTypeRef Ty
); /* all zeroes */
396 LLVMValueRef
LLVMConstAllOnes(LLVMTypeRef Ty
); /* only for int/vector */
397 LLVMValueRef
LLVMGetUndef(LLVMTypeRef Ty
);
398 int LLVMIsConstant(LLVMValueRef Val
);
399 int LLVMIsNull(LLVMValueRef Val
);
400 int LLVMIsUndef(LLVMValueRef Val
);
401 LLVMValueRef
LLVMConstPointerNull(LLVMTypeRef Ty
);
403 /* Operations on scalar constants */
404 LLVMValueRef
LLVMConstInt(LLVMTypeRef IntTy
, unsigned long long N
,
406 LLVMValueRef
LLVMConstReal(LLVMTypeRef RealTy
, double N
);
407 LLVMValueRef
LLVMConstRealOfString(LLVMTypeRef RealTy
, const char *Text
);
409 /* Operations on composite constants */
410 LLVMValueRef
LLVMConstString(const char *Str
, unsigned Length
,
411 int DontNullTerminate
);
412 LLVMValueRef
LLVMConstArray(LLVMTypeRef ElementTy
,
413 LLVMValueRef
*ConstantVals
, unsigned Length
);
414 LLVMValueRef
LLVMConstStruct(LLVMValueRef
*ConstantVals
, unsigned Count
,
416 LLVMValueRef
LLVMConstVector(LLVMValueRef
*ScalarConstantVals
, unsigned Size
);
418 /* Constant expressions */
419 LLVMValueRef
LLVMSizeOf(LLVMTypeRef Ty
);
420 LLVMValueRef
LLVMConstNeg(LLVMValueRef ConstantVal
);
421 LLVMValueRef
LLVMConstNot(LLVMValueRef ConstantVal
);
422 LLVMValueRef
LLVMConstAdd(LLVMValueRef LHSConstant
, LLVMValueRef RHSConstant
);
423 LLVMValueRef
LLVMConstSub(LLVMValueRef LHSConstant
, LLVMValueRef RHSConstant
);
424 LLVMValueRef
LLVMConstMul(LLVMValueRef LHSConstant
, LLVMValueRef RHSConstant
);
425 LLVMValueRef
LLVMConstUDiv(LLVMValueRef LHSConstant
, LLVMValueRef RHSConstant
);
426 LLVMValueRef
LLVMConstSDiv(LLVMValueRef LHSConstant
, LLVMValueRef RHSConstant
);
427 LLVMValueRef
LLVMConstFDiv(LLVMValueRef LHSConstant
, LLVMValueRef RHSConstant
);
428 LLVMValueRef
LLVMConstURem(LLVMValueRef LHSConstant
, LLVMValueRef RHSConstant
);
429 LLVMValueRef
LLVMConstSRem(LLVMValueRef LHSConstant
, LLVMValueRef RHSConstant
);
430 LLVMValueRef
LLVMConstFRem(LLVMValueRef LHSConstant
, LLVMValueRef RHSConstant
);
431 LLVMValueRef
LLVMConstAnd(LLVMValueRef LHSConstant
, LLVMValueRef RHSConstant
);
432 LLVMValueRef
LLVMConstOr(LLVMValueRef LHSConstant
, LLVMValueRef RHSConstant
);
433 LLVMValueRef
LLVMConstXor(LLVMValueRef LHSConstant
, LLVMValueRef RHSConstant
);
434 LLVMValueRef
LLVMConstICmp(LLVMIntPredicate Predicate
,
435 LLVMValueRef LHSConstant
, LLVMValueRef RHSConstant
);
436 LLVMValueRef
LLVMConstFCmp(LLVMRealPredicate Predicate
,
437 LLVMValueRef LHSConstant
, LLVMValueRef RHSConstant
);
438 LLVMValueRef
LLVMConstShl(LLVMValueRef LHSConstant
, LLVMValueRef RHSConstant
);
439 LLVMValueRef
LLVMConstLShr(LLVMValueRef LHSConstant
, LLVMValueRef RHSConstant
);
440 LLVMValueRef
LLVMConstAShr(LLVMValueRef LHSConstant
, LLVMValueRef RHSConstant
);
441 LLVMValueRef
LLVMConstGEP(LLVMValueRef ConstantVal
,
442 LLVMValueRef
*ConstantIndices
, unsigned NumIndices
);
443 LLVMValueRef
LLVMConstTrunc(LLVMValueRef ConstantVal
, LLVMTypeRef ToType
);
444 LLVMValueRef
LLVMConstSExt(LLVMValueRef ConstantVal
, LLVMTypeRef ToType
);
445 LLVMValueRef
LLVMConstZExt(LLVMValueRef ConstantVal
, LLVMTypeRef ToType
);
446 LLVMValueRef
LLVMConstFPTrunc(LLVMValueRef ConstantVal
, LLVMTypeRef ToType
);
447 LLVMValueRef
LLVMConstFPExt(LLVMValueRef ConstantVal
, LLVMTypeRef ToType
);
448 LLVMValueRef
LLVMConstUIToFP(LLVMValueRef ConstantVal
, LLVMTypeRef ToType
);
449 LLVMValueRef
LLVMConstSIToFP(LLVMValueRef ConstantVal
, LLVMTypeRef ToType
);
450 LLVMValueRef
LLVMConstFPToUI(LLVMValueRef ConstantVal
, LLVMTypeRef ToType
);
451 LLVMValueRef
LLVMConstFPToSI(LLVMValueRef ConstantVal
, LLVMTypeRef ToType
);
452 LLVMValueRef
LLVMConstPtrToInt(LLVMValueRef ConstantVal
, LLVMTypeRef ToType
);
453 LLVMValueRef
LLVMConstIntToPtr(LLVMValueRef ConstantVal
, LLVMTypeRef ToType
);
454 LLVMValueRef
LLVMConstBitCast(LLVMValueRef ConstantVal
, LLVMTypeRef ToType
);
455 LLVMValueRef
LLVMConstSelect(LLVMValueRef ConstantCondition
,
456 LLVMValueRef ConstantIfTrue
,
457 LLVMValueRef ConstantIfFalse
);
458 LLVMValueRef
LLVMConstExtractElement(LLVMValueRef VectorConstant
,
459 LLVMValueRef IndexConstant
);
460 LLVMValueRef
LLVMConstInsertElement(LLVMValueRef VectorConstant
,
461 LLVMValueRef ElementValueConstant
,
462 LLVMValueRef IndexConstant
);
463 LLVMValueRef
LLVMConstShuffleVector(LLVMValueRef VectorAConstant
,
464 LLVMValueRef VectorBConstant
,
465 LLVMValueRef MaskConstant
);
466 LLVMValueRef
LLVMConstExtractValue(LLVMValueRef AggConstant
, unsigned *IdxList
,
468 LLVMValueRef
LLVMConstInsertValue(LLVMValueRef AggConstant
,
469 LLVMValueRef ElementValueConstant
,
470 unsigned *IdxList
, unsigned NumIdx
);
471 LLVMValueRef
LLVMConstInlineAsm(LLVMTypeRef Ty
,
472 const char *AsmString
, const char *Constraints
,
475 /* Operations on global variables, functions, and aliases (globals) */
476 LLVMModuleRef
LLVMGetGlobalParent(LLVMValueRef Global
);
477 int LLVMIsDeclaration(LLVMValueRef Global
);
478 LLVMLinkage
LLVMGetLinkage(LLVMValueRef Global
);
479 void LLVMSetLinkage(LLVMValueRef Global
, LLVMLinkage Linkage
);
480 const char *LLVMGetSection(LLVMValueRef Global
);
481 void LLVMSetSection(LLVMValueRef Global
, const char *Section
);
482 LLVMVisibility
LLVMGetVisibility(LLVMValueRef Global
);
483 void LLVMSetVisibility(LLVMValueRef Global
, LLVMVisibility Viz
);
484 unsigned LLVMGetAlignment(LLVMValueRef Global
);
485 void LLVMSetAlignment(LLVMValueRef Global
, unsigned Bytes
);
487 /* Operations on global variables */
488 LLVMValueRef
LLVMAddGlobal(LLVMModuleRef M
, LLVMTypeRef Ty
, const char *Name
);
489 LLVMValueRef
LLVMGetNamedGlobal(LLVMModuleRef M
, const char *Name
);
490 LLVMValueRef
LLVMGetFirstGlobal(LLVMModuleRef M
);
491 LLVMValueRef
LLVMGetLastGlobal(LLVMModuleRef M
);
492 LLVMValueRef
LLVMGetNextGlobal(LLVMValueRef GlobalVar
);
493 LLVMValueRef
LLVMGetPreviousGlobal(LLVMValueRef GlobalVar
);
494 void LLVMDeleteGlobal(LLVMValueRef GlobalVar
);
495 LLVMValueRef
LLVMGetInitializer(LLVMValueRef GlobalVar
);
496 void LLVMSetInitializer(LLVMValueRef GlobalVar
, LLVMValueRef ConstantVal
);
497 int LLVMIsThreadLocal(LLVMValueRef GlobalVar
);
498 void LLVMSetThreadLocal(LLVMValueRef GlobalVar
, int IsThreadLocal
);
499 int LLVMIsGlobalConstant(LLVMValueRef GlobalVar
);
500 void LLVMSetGlobalConstant(LLVMValueRef GlobalVar
, int IsConstant
);
502 /* Operations on aliases */
503 LLVMValueRef
LLVMAddAlias(LLVMModuleRef M
, LLVMTypeRef Ty
, LLVMValueRef Aliasee
,
506 /* Operations on functions */
507 LLVMValueRef
LLVMAddFunction(LLVMModuleRef M
, const char *Name
,
508 LLVMTypeRef FunctionTy
);
509 LLVMValueRef
LLVMGetNamedFunction(LLVMModuleRef M
, const char *Name
);
510 LLVMValueRef
LLVMGetFirstFunction(LLVMModuleRef M
);
511 LLVMValueRef
LLVMGetLastFunction(LLVMModuleRef M
);
512 LLVMValueRef
LLVMGetNextFunction(LLVMValueRef Fn
);
513 LLVMValueRef
LLVMGetPreviousFunction(LLVMValueRef Fn
);
514 void LLVMDeleteFunction(LLVMValueRef Fn
);
515 unsigned LLVMGetIntrinsicID(LLVMValueRef Fn
);
516 unsigned LLVMGetFunctionCallConv(LLVMValueRef Fn
);
517 void LLVMSetFunctionCallConv(LLVMValueRef Fn
, unsigned CC
);
518 const char *LLVMGetGC(LLVMValueRef Fn
);
519 void LLVMSetGC(LLVMValueRef Fn
, const char *Name
);
520 void LLVMAddFunctionAttr(LLVMValueRef Fn
, LLVMAttribute PA
);
521 void LLVMRemoveFunctionAttr(LLVMValueRef Fn
, LLVMAttribute PA
);
523 /* Operations on parameters */
524 unsigned LLVMCountParams(LLVMValueRef Fn
);
525 void LLVMGetParams(LLVMValueRef Fn
, LLVMValueRef
*Params
);
526 LLVMValueRef
LLVMGetParam(LLVMValueRef Fn
, unsigned Index
);
527 LLVMValueRef
LLVMGetParamParent(LLVMValueRef Inst
);
528 LLVMValueRef
LLVMGetFirstParam(LLVMValueRef Fn
);
529 LLVMValueRef
LLVMGetLastParam(LLVMValueRef Fn
);
530 LLVMValueRef
LLVMGetNextParam(LLVMValueRef Arg
);
531 LLVMValueRef
LLVMGetPreviousParam(LLVMValueRef Arg
);
532 void LLVMAddAttribute(LLVMValueRef Arg
, LLVMAttribute PA
);
533 void LLVMRemoveAttribute(LLVMValueRef Arg
, LLVMAttribute PA
);
534 void LLVMSetParamAlignment(LLVMValueRef Arg
, unsigned align
);
536 /* Operations on basic blocks */
537 LLVMValueRef
LLVMBasicBlockAsValue(LLVMBasicBlockRef BB
);
538 int LLVMValueIsBasicBlock(LLVMValueRef Val
);
539 LLVMBasicBlockRef
LLVMValueAsBasicBlock(LLVMValueRef Val
);
540 LLVMValueRef
LLVMGetBasicBlockParent(LLVMBasicBlockRef BB
);
541 unsigned LLVMCountBasicBlocks(LLVMValueRef Fn
);
542 void LLVMGetBasicBlocks(LLVMValueRef Fn
, LLVMBasicBlockRef
*BasicBlocks
);
543 LLVMBasicBlockRef
LLVMGetFirstBasicBlock(LLVMValueRef Fn
);
544 LLVMBasicBlockRef
LLVMGetLastBasicBlock(LLVMValueRef Fn
);
545 LLVMBasicBlockRef
LLVMGetNextBasicBlock(LLVMBasicBlockRef BB
);
546 LLVMBasicBlockRef
LLVMGetPreviousBasicBlock(LLVMBasicBlockRef BB
);
547 LLVMBasicBlockRef
LLVMGetEntryBasicBlock(LLVMValueRef Fn
);
548 LLVMBasicBlockRef
LLVMAppendBasicBlock(LLVMValueRef Fn
, const char *Name
);
549 LLVMBasicBlockRef
LLVMInsertBasicBlock(LLVMBasicBlockRef InsertBeforeBB
,
551 void LLVMDeleteBasicBlock(LLVMBasicBlockRef BB
);
553 /* Operations on instructions */
554 LLVMBasicBlockRef
LLVMGetInstructionParent(LLVMValueRef Inst
);
555 LLVMValueRef
LLVMGetFirstInstruction(LLVMBasicBlockRef BB
);
556 LLVMValueRef
LLVMGetLastInstruction(LLVMBasicBlockRef BB
);
557 LLVMValueRef
LLVMGetNextInstruction(LLVMValueRef Inst
);
558 LLVMValueRef
LLVMGetPreviousInstruction(LLVMValueRef Inst
);
560 /* Operations on call sites */
561 void LLVMSetInstructionCallConv(LLVMValueRef Instr
, unsigned CC
);
562 unsigned LLVMGetInstructionCallConv(LLVMValueRef Instr
);
563 void LLVMAddInstrAttribute(LLVMValueRef Instr
, unsigned index
, LLVMAttribute
);
564 void LLVMRemoveInstrAttribute(LLVMValueRef Instr
, unsigned index
,
566 void LLVMSetInstrParamAlignment(LLVMValueRef Instr
, unsigned index
,
569 /* Operations on call instructions (only) */
570 int LLVMIsTailCall(LLVMValueRef CallInst
);
571 void LLVMSetTailCall(LLVMValueRef CallInst
, int IsTailCall
);
573 /* Operations on phi nodes */
574 void LLVMAddIncoming(LLVMValueRef PhiNode
, LLVMValueRef
*IncomingValues
,
575 LLVMBasicBlockRef
*IncomingBlocks
, unsigned Count
);
576 unsigned LLVMCountIncoming(LLVMValueRef PhiNode
);
577 LLVMValueRef
LLVMGetIncomingValue(LLVMValueRef PhiNode
, unsigned Index
);
578 LLVMBasicBlockRef
LLVMGetIncomingBlock(LLVMValueRef PhiNode
, unsigned Index
);
580 /*===-- Instruction builders ----------------------------------------------===*/
582 /* An instruction builder represents a point within a basic block, and is the
583 * exclusive means of building instructions using the C interface.
586 LLVMBuilderRef
LLVMCreateBuilder(void);
587 void LLVMPositionBuilder(LLVMBuilderRef Builder
, LLVMBasicBlockRef Block
,
589 void LLVMPositionBuilderBefore(LLVMBuilderRef Builder
, LLVMValueRef Instr
);
590 void LLVMPositionBuilderAtEnd(LLVMBuilderRef Builder
, LLVMBasicBlockRef Block
);
591 LLVMBasicBlockRef
LLVMGetInsertBlock(LLVMBuilderRef Builder
);
592 void LLVMClearInsertionPosition(LLVMBuilderRef Builder
);
593 void LLVMInsertIntoBuilder(LLVMBuilderRef Builder
, LLVMValueRef Instr
);
594 void LLVMDisposeBuilder(LLVMBuilderRef Builder
);
597 LLVMValueRef
LLVMBuildRetVoid(LLVMBuilderRef
);
598 LLVMValueRef
LLVMBuildRet(LLVMBuilderRef
, LLVMValueRef V
);
599 LLVMValueRef
LLVMBuildBr(LLVMBuilderRef
, LLVMBasicBlockRef Dest
);
600 LLVMValueRef
LLVMBuildCondBr(LLVMBuilderRef
, LLVMValueRef If
,
601 LLVMBasicBlockRef Then
, LLVMBasicBlockRef Else
);
602 LLVMValueRef
LLVMBuildSwitch(LLVMBuilderRef
, LLVMValueRef V
,
603 LLVMBasicBlockRef Else
, unsigned NumCases
);
604 LLVMValueRef
LLVMBuildInvoke(LLVMBuilderRef
, LLVMValueRef Fn
,
605 LLVMValueRef
*Args
, unsigned NumArgs
,
606 LLVMBasicBlockRef Then
, LLVMBasicBlockRef Catch
,
608 LLVMValueRef
LLVMBuildUnwind(LLVMBuilderRef
);
609 LLVMValueRef
LLVMBuildUnreachable(LLVMBuilderRef
);
611 /* Add a case to the switch instruction */
612 void LLVMAddCase(LLVMValueRef Switch
, LLVMValueRef OnVal
,
613 LLVMBasicBlockRef Dest
);
616 LLVMValueRef
LLVMBuildAdd(LLVMBuilderRef
, LLVMValueRef LHS
, LLVMValueRef RHS
,
618 LLVMValueRef
LLVMBuildSub(LLVMBuilderRef
, LLVMValueRef LHS
, LLVMValueRef RHS
,
620 LLVMValueRef
LLVMBuildMul(LLVMBuilderRef
, LLVMValueRef LHS
, LLVMValueRef RHS
,
622 LLVMValueRef
LLVMBuildUDiv(LLVMBuilderRef
, LLVMValueRef LHS
, LLVMValueRef RHS
,
624 LLVMValueRef
LLVMBuildSDiv(LLVMBuilderRef
, LLVMValueRef LHS
, LLVMValueRef RHS
,
626 LLVMValueRef
LLVMBuildFDiv(LLVMBuilderRef
, LLVMValueRef LHS
, LLVMValueRef RHS
,
628 LLVMValueRef
LLVMBuildURem(LLVMBuilderRef
, LLVMValueRef LHS
, LLVMValueRef RHS
,
630 LLVMValueRef
LLVMBuildSRem(LLVMBuilderRef
, LLVMValueRef LHS
, LLVMValueRef RHS
,
632 LLVMValueRef
LLVMBuildFRem(LLVMBuilderRef
, LLVMValueRef LHS
, LLVMValueRef RHS
,
634 LLVMValueRef
LLVMBuildShl(LLVMBuilderRef
, LLVMValueRef LHS
, LLVMValueRef RHS
,
636 LLVMValueRef
LLVMBuildLShr(LLVMBuilderRef
, LLVMValueRef LHS
, LLVMValueRef RHS
,
638 LLVMValueRef
LLVMBuildAShr(LLVMBuilderRef
, LLVMValueRef LHS
, LLVMValueRef RHS
,
640 LLVMValueRef
LLVMBuildAnd(LLVMBuilderRef
, LLVMValueRef LHS
, LLVMValueRef RHS
,
642 LLVMValueRef
LLVMBuildOr(LLVMBuilderRef
, LLVMValueRef LHS
, LLVMValueRef RHS
,
644 LLVMValueRef
LLVMBuildXor(LLVMBuilderRef
, LLVMValueRef LHS
, LLVMValueRef RHS
,
646 LLVMValueRef
LLVMBuildNeg(LLVMBuilderRef
, LLVMValueRef V
, const char *Name
);
647 LLVMValueRef
LLVMBuildNot(LLVMBuilderRef
, LLVMValueRef V
, const char *Name
);
650 LLVMValueRef
LLVMBuildMalloc(LLVMBuilderRef
, LLVMTypeRef Ty
, const char *Name
);
651 LLVMValueRef
LLVMBuildArrayMalloc(LLVMBuilderRef
, LLVMTypeRef Ty
,
652 LLVMValueRef Val
, const char *Name
);
653 LLVMValueRef
LLVMBuildAlloca(LLVMBuilderRef
, LLVMTypeRef Ty
, const char *Name
);
654 LLVMValueRef
LLVMBuildArrayAlloca(LLVMBuilderRef
, LLVMTypeRef Ty
,
655 LLVMValueRef Val
, const char *Name
);
656 LLVMValueRef
LLVMBuildFree(LLVMBuilderRef
, LLVMValueRef PointerVal
);
657 LLVMValueRef
LLVMBuildLoad(LLVMBuilderRef
, LLVMValueRef PointerVal
,
659 LLVMValueRef
LLVMBuildStore(LLVMBuilderRef
, LLVMValueRef Val
, LLVMValueRef Ptr
);
660 LLVMValueRef
LLVMBuildGEP(LLVMBuilderRef B
, LLVMValueRef Pointer
,
661 LLVMValueRef
*Indices
, unsigned NumIndices
,
665 LLVMValueRef
LLVMBuildTrunc(LLVMBuilderRef
, LLVMValueRef Val
,
666 LLVMTypeRef DestTy
, const char *Name
);
667 LLVMValueRef
LLVMBuildZExt(LLVMBuilderRef
, LLVMValueRef Val
,
668 LLVMTypeRef DestTy
, const char *Name
);
669 LLVMValueRef
LLVMBuildSExt(LLVMBuilderRef
, LLVMValueRef Val
,
670 LLVMTypeRef DestTy
, const char *Name
);
671 LLVMValueRef
LLVMBuildFPToUI(LLVMBuilderRef
, LLVMValueRef Val
,
672 LLVMTypeRef DestTy
, const char *Name
);
673 LLVMValueRef
LLVMBuildFPToSI(LLVMBuilderRef
, LLVMValueRef Val
,
674 LLVMTypeRef DestTy
, const char *Name
);
675 LLVMValueRef
LLVMBuildUIToFP(LLVMBuilderRef
, LLVMValueRef Val
,
676 LLVMTypeRef DestTy
, const char *Name
);
677 LLVMValueRef
LLVMBuildSIToFP(LLVMBuilderRef
, LLVMValueRef Val
,
678 LLVMTypeRef DestTy
, const char *Name
);
679 LLVMValueRef
LLVMBuildFPTrunc(LLVMBuilderRef
, LLVMValueRef Val
,
680 LLVMTypeRef DestTy
, const char *Name
);
681 LLVMValueRef
LLVMBuildFPExt(LLVMBuilderRef
, LLVMValueRef Val
,
682 LLVMTypeRef DestTy
, const char *Name
);
683 LLVMValueRef
LLVMBuildPtrToInt(LLVMBuilderRef
, LLVMValueRef Val
,
684 LLVMTypeRef DestTy
, const char *Name
);
685 LLVMValueRef
LLVMBuildIntToPtr(LLVMBuilderRef
, LLVMValueRef Val
,
686 LLVMTypeRef DestTy
, const char *Name
);
687 LLVMValueRef
LLVMBuildBitCast(LLVMBuilderRef
, LLVMValueRef Val
,
688 LLVMTypeRef DestTy
, const char *Name
);
691 LLVMValueRef
LLVMBuildICmp(LLVMBuilderRef
, LLVMIntPredicate Op
,
692 LLVMValueRef LHS
, LLVMValueRef RHS
,
694 LLVMValueRef
LLVMBuildFCmp(LLVMBuilderRef
, LLVMRealPredicate Op
,
695 LLVMValueRef LHS
, LLVMValueRef RHS
,
698 /* Miscellaneous instructions */
699 LLVMValueRef
LLVMBuildPhi(LLVMBuilderRef
, LLVMTypeRef Ty
, const char *Name
);
700 LLVMValueRef
LLVMBuildCall(LLVMBuilderRef
, LLVMValueRef Fn
,
701 LLVMValueRef
*Args
, unsigned NumArgs
,
703 LLVMValueRef
LLVMBuildSelect(LLVMBuilderRef
, LLVMValueRef If
,
704 LLVMValueRef Then
, LLVMValueRef Else
,
706 LLVMValueRef
LLVMBuildVAArg(LLVMBuilderRef
, LLVMValueRef List
, LLVMTypeRef Ty
,
708 LLVMValueRef
LLVMBuildExtractElement(LLVMBuilderRef
, LLVMValueRef VecVal
,
709 LLVMValueRef Index
, const char *Name
);
710 LLVMValueRef
LLVMBuildInsertElement(LLVMBuilderRef
, LLVMValueRef VecVal
,
711 LLVMValueRef EltVal
, LLVMValueRef Index
,
713 LLVMValueRef
LLVMBuildShuffleVector(LLVMBuilderRef
, LLVMValueRef V1
,
714 LLVMValueRef V2
, LLVMValueRef Mask
,
716 LLVMValueRef
LLVMBuildExtractValue(LLVMBuilderRef
, LLVMValueRef AggVal
,
717 unsigned Index
, const char *Name
);
718 LLVMValueRef
LLVMBuildInsertValue(LLVMBuilderRef
, LLVMValueRef AggVal
,
719 LLVMValueRef EltVal
, unsigned Index
,
723 /*===-- Module providers --------------------------------------------------===*/
725 /* Encapsulates the module M in a module provider, taking ownership of the
727 * See the constructor llvm::ExistingModuleProvider::ExistingModuleProvider.
729 LLVMModuleProviderRef
730 LLVMCreateModuleProviderForExistingModule(LLVMModuleRef M
);
732 /* Destroys the module provider MP as well as the contained module.
733 * See the destructor llvm::ModuleProvider::~ModuleProvider.
735 void LLVMDisposeModuleProvider(LLVMModuleProviderRef MP
);
738 /*===-- Memory buffers ----------------------------------------------------===*/
740 int LLVMCreateMemoryBufferWithContentsOfFile(const char *Path
,
741 LLVMMemoryBufferRef
*OutMemBuf
,
743 int LLVMCreateMemoryBufferWithSTDIN(LLVMMemoryBufferRef
*OutMemBuf
,
745 void LLVMDisposeMemoryBuffer(LLVMMemoryBufferRef MemBuf
);
748 /*===-- Pass Managers -----------------------------------------------------===*/
750 /** Constructs a new whole-module pass pipeline. This type of pipeline is
751 suitable for link-time optimization and whole-module transformations.
752 See llvm::PassManager::PassManager. */
753 LLVMPassManagerRef
LLVMCreatePassManager(void);
755 /** Constructs a new function-by-function pass pipeline over the module
756 provider. It does not take ownership of the module provider. This type of
757 pipeline is suitable for code generation and JIT compilation tasks.
758 See llvm::FunctionPassManager::FunctionPassManager. */
759 LLVMPassManagerRef
LLVMCreateFunctionPassManager(LLVMModuleProviderRef MP
);
761 /** Initializes, executes on the provided module, and finalizes all of the
762 passes scheduled in the pass manager. Returns 1 if any of the passes
763 modified the module, 0 otherwise. See llvm::PassManager::run(Module&). */
764 int LLVMRunPassManager(LLVMPassManagerRef PM
, LLVMModuleRef M
);
766 /** Initializes all of the function passes scheduled in the function pass
767 manager. Returns 1 if any of the passes modified the module, 0 otherwise.
768 See llvm::FunctionPassManager::doInitialization. */
769 int LLVMInitializeFunctionPassManager(LLVMPassManagerRef FPM
);
771 /** Executes all of the function passes scheduled in the function pass manager
772 on the provided function. Returns 1 if any of the passes modified the
773 function, false otherwise.
774 See llvm::FunctionPassManager::run(Function&). */
775 int LLVMRunFunctionPassManager(LLVMPassManagerRef FPM
, LLVMValueRef F
);
777 /** Finalizes all of the function passes scheduled in in the function pass
778 manager. Returns 1 if any of the passes modified the module, 0 otherwise.
779 See llvm::FunctionPassManager::doFinalization. */
780 int LLVMFinalizeFunctionPassManager(LLVMPassManagerRef FPM
);
782 /** Frees the memory of a pass pipeline. For function pipelines, does not free
784 See llvm::PassManagerBase::~PassManagerBase. */
785 void LLVMDisposePassManager(LLVMPassManagerRef PM
);
792 class ModuleProvider
;
794 class PassManagerBase
;
796 #define DEFINE_SIMPLE_CONVERSION_FUNCTIONS(ty, ref) \
797 inline ty *unwrap(ref P) { \
798 return reinterpret_cast<ty*>(P); \
801 inline ref wrap(const ty *P) { \
802 return reinterpret_cast<ref>(const_cast<ty*>(P)); \
805 #define DEFINE_ISA_CONVERSION_FUNCTIONS(ty, ref) \
806 DEFINE_SIMPLE_CONVERSION_FUNCTIONS(ty, ref) \
808 template<typename T> \
809 inline T *unwrap(ref P) { \
810 return cast<T>(unwrap(P)); \
813 #define DEFINE_STDCXX_CONVERSION_FUNCTIONS(ty, ref) \
814 DEFINE_SIMPLE_CONVERSION_FUNCTIONS(ty, ref) \
816 template<typename T> \
817 inline T *unwrap(ref P) { \
818 T *Q = dynamic_cast<T*>(unwrap(P)); \
819 assert(Q && "Invalid cast!"); \
823 DEFINE_ISA_CONVERSION_FUNCTIONS (Type
, LLVMTypeRef
)
824 DEFINE_ISA_CONVERSION_FUNCTIONS (Value
, LLVMValueRef
)
825 DEFINE_SIMPLE_CONVERSION_FUNCTIONS(Module
, LLVMModuleRef
)
826 DEFINE_SIMPLE_CONVERSION_FUNCTIONS(BasicBlock
, LLVMBasicBlockRef
)
827 DEFINE_SIMPLE_CONVERSION_FUNCTIONS(IRBuilder
<>, LLVMBuilderRef
)
828 DEFINE_SIMPLE_CONVERSION_FUNCTIONS(PATypeHolder
, LLVMTypeHandleRef
)
829 DEFINE_SIMPLE_CONVERSION_FUNCTIONS(ModuleProvider
, LLVMModuleProviderRef
)
830 DEFINE_SIMPLE_CONVERSION_FUNCTIONS(MemoryBuffer
, LLVMMemoryBufferRef
)
831 DEFINE_SIMPLE_CONVERSION_FUNCTIONS(LLVMContext
, LLVMContextRef
)
832 DEFINE_STDCXX_CONVERSION_FUNCTIONS(PassManagerBase
, LLVMPassManagerRef
)
834 #undef DEFINE_STDCXX_CONVERSION_FUNCTIONS
835 #undef DEFINE_ISA_CONVERSION_FUNCTIONS
836 #undef DEFINE_SIMPLE_CONVERSION_FUNCTIONS
838 /* Specialized opaque type conversions.
840 inline Type
**unwrap(LLVMTypeRef
* Tys
) {
841 return reinterpret_cast<Type
**>(Tys
);
844 inline LLVMTypeRef
*wrap(const Type
**Tys
) {
845 return reinterpret_cast<LLVMTypeRef
*>(const_cast<Type
**>(Tys
));
848 /* Specialized opaque value conversions.
850 inline Value
**unwrap(LLVMValueRef
*Vals
) {
851 return reinterpret_cast<Value
**>(Vals
);
855 inline T
**unwrap(LLVMValueRef
*Vals
, unsigned Length
) {
857 for (LLVMValueRef
*I
= Vals
, *E
= Vals
+ Length
; I
!= E
; ++I
)
860 return reinterpret_cast<T
**>(Vals
);
863 inline LLVMValueRef
*wrap(const Value
**Vals
) {
864 return reinterpret_cast<LLVMValueRef
*>(const_cast<Value
**>(Vals
));
868 #endif /* !defined(__cplusplus) */
870 #endif /* !defined(LLVM_C_CORE_H) */