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 \*===----------------------------------------------------------------------===*/
36 #include "llvm/System/DataTypes.h"
40 /* Need these includes to support the LLVM 'cast' template for the C++ 'wrap'
41 and 'unwrap' conversion functions. */
42 #include "llvm/Module.h"
43 #include "llvm/Support/IRBuilder.h"
54 * The top-level container for all LLVM global data. See the LLVMContext class.
56 typedef struct LLVMOpaqueContext
*LLVMContextRef
;
59 * The top-level container for all other LLVM Intermediate Representation (IR)
60 * objects. See the llvm::Module class.
62 typedef struct LLVMOpaqueModule
*LLVMModuleRef
;
65 * Each value in the LLVM IR has a type, an LLVMTypeRef. See the llvm::Type
68 typedef struct LLVMOpaqueType
*LLVMTypeRef
;
71 * When building recursive types using LLVMRefineType, LLVMTypeRef values may
72 * become invalid; use LLVMTypeHandleRef to resolve this problem. See the
73 * llvm::AbstractTypeHolder class.
75 typedef struct LLVMOpaqueTypeHandle
*LLVMTypeHandleRef
;
77 typedef struct LLVMOpaqueValue
*LLVMValueRef
;
78 typedef struct LLVMOpaqueBasicBlock
*LLVMBasicBlockRef
;
79 typedef struct LLVMOpaqueBuilder
*LLVMBuilderRef
;
81 /* Interface used to provide a module to JIT or interpreter. This is now just a
82 * synonym for llvm::Module, but we have to keep using the different type to
83 * keep binary compatibility.
85 typedef struct LLVMOpaqueModuleProvider
*LLVMModuleProviderRef
;
87 /* Used to provide a module to JIT or interpreter.
88 * See the llvm::MemoryBuffer class.
90 typedef struct LLVMOpaqueMemoryBuffer
*LLVMMemoryBufferRef
;
92 /** See the llvm::PassManagerBase class. */
93 typedef struct LLVMOpaquePassManager
*LLVMPassManagerRef
;
95 /** Used to get the users and usees of a Value. See the llvm::Use class. */
96 typedef struct LLVMOpaqueUse
*LLVMUseRef
;
99 LLVMZExtAttribute
= 1<<0,
100 LLVMSExtAttribute
= 1<<1,
101 LLVMNoReturnAttribute
= 1<<2,
102 LLVMInRegAttribute
= 1<<3,
103 LLVMStructRetAttribute
= 1<<4,
104 LLVMNoUnwindAttribute
= 1<<5,
105 LLVMNoAliasAttribute
= 1<<6,
106 LLVMByValAttribute
= 1<<7,
107 LLVMNestAttribute
= 1<<8,
108 LLVMReadNoneAttribute
= 1<<9,
109 LLVMReadOnlyAttribute
= 1<<10,
110 LLVMNoInlineAttribute
= 1<<11,
111 LLVMAlwaysInlineAttribute
= 1<<12,
112 LLVMOptimizeForSizeAttribute
= 1<<13,
113 LLVMStackProtectAttribute
= 1<<14,
114 LLVMStackProtectReqAttribute
= 1<<15,
115 LLVMAlignment
= 31<<16,
116 LLVMNoCaptureAttribute
= 1<<21,
117 LLVMNoRedZoneAttribute
= 1<<22,
118 LLVMNoImplicitFloatAttribute
= 1<<23,
119 LLVMNakedAttribute
= 1<<24,
120 LLVMInlineHintAttribute
= 1<<25,
121 LLVMStackAlignment
= 7<<26
125 /* Terminator Instructions */
134 /* Standard Binary Operators */
148 /* Logical Operators */
156 /* Memory Operators */
160 LLVMGetElementPtr
= 29,
176 /* Other Operators */
185 LLVMExtractElement
= 50,
186 LLVMInsertElement
= 51,
187 LLVMShuffleVector
= 52,
188 LLVMExtractValue
= 53,
193 LLVMVoidTypeKind
, /**< type with no size */
194 LLVMFloatTypeKind
, /**< 32 bit floating point type */
195 LLVMDoubleTypeKind
, /**< 64 bit floating point type */
196 LLVMX86_FP80TypeKind
, /**< 80 bit floating point type (X87) */
197 LLVMFP128TypeKind
, /**< 128 bit floating point type (112-bit mantissa)*/
198 LLVMPPC_FP128TypeKind
, /**< 128 bit floating point type (two 64-bits) */
199 LLVMLabelTypeKind
, /**< Labels */
200 LLVMIntegerTypeKind
, /**< Arbitrary bit width integers */
201 LLVMFunctionTypeKind
, /**< Functions */
202 LLVMStructTypeKind
, /**< Structures */
203 LLVMArrayTypeKind
, /**< Arrays */
204 LLVMPointerTypeKind
, /**< Pointers */
205 LLVMOpaqueTypeKind
, /**< Opaque: type with unknown structure */
206 LLVMVectorTypeKind
, /**< SIMD 'packed' format, or other vector type */
207 LLVMMetadataTypeKind
, /**< Metadata */
208 LLVMUnionTypeKind
/**< Unions */
212 LLVMExternalLinkage
, /**< Externally visible function */
213 LLVMAvailableExternallyLinkage
,
214 LLVMLinkOnceAnyLinkage
, /**< Keep one copy of function when linking (inline)*/
215 LLVMLinkOnceODRLinkage
, /**< Same, but only replaced by something
217 LLVMWeakAnyLinkage
, /**< Keep one copy of function when linking (weak) */
218 LLVMWeakODRLinkage
, /**< Same, but only replaced by something
220 LLVMAppendingLinkage
, /**< Special purpose, only applies to global arrays */
221 LLVMInternalLinkage
, /**< Rename collisions when linking (static
223 LLVMPrivateLinkage
, /**< Like Internal, but omit from symbol table */
224 LLVMDLLImportLinkage
, /**< Function to be imported from DLL */
225 LLVMDLLExportLinkage
, /**< Function to be accessible from DLL */
226 LLVMExternalWeakLinkage
,/**< ExternalWeak linkage description */
227 LLVMGhostLinkage
, /**< Obsolete */
228 LLVMCommonLinkage
, /**< Tentative definitions */
229 LLVMLinkerPrivateLinkage
, /**< Like Private, but linker removes. */
230 LLVMLinkerPrivateWeakLinkage
/**< Like LinkerPrivate, but is weak. */
234 LLVMDefaultVisibility
, /**< The GV is visible */
235 LLVMHiddenVisibility
, /**< The GV is hidden */
236 LLVMProtectedVisibility
/**< The GV is protected */
241 LLVMFastCallConv
= 8,
242 LLVMColdCallConv
= 9,
243 LLVMX86StdcallCallConv
= 64,
244 LLVMX86FastcallCallConv
= 65
248 LLVMIntEQ
= 32, /**< equal */
249 LLVMIntNE
, /**< not equal */
250 LLVMIntUGT
, /**< unsigned greater than */
251 LLVMIntUGE
, /**< unsigned greater or equal */
252 LLVMIntULT
, /**< unsigned less than */
253 LLVMIntULE
, /**< unsigned less or equal */
254 LLVMIntSGT
, /**< signed greater than */
255 LLVMIntSGE
, /**< signed greater or equal */
256 LLVMIntSLT
, /**< signed less than */
257 LLVMIntSLE
/**< signed less or equal */
261 LLVMRealPredicateFalse
, /**< Always false (always folded) */
262 LLVMRealOEQ
, /**< True if ordered and equal */
263 LLVMRealOGT
, /**< True if ordered and greater than */
264 LLVMRealOGE
, /**< True if ordered and greater than or equal */
265 LLVMRealOLT
, /**< True if ordered and less than */
266 LLVMRealOLE
, /**< True if ordered and less than or equal */
267 LLVMRealONE
, /**< True if ordered and operands are unequal */
268 LLVMRealORD
, /**< True if ordered (no nans) */
269 LLVMRealUNO
, /**< True if unordered: isnan(X) | isnan(Y) */
270 LLVMRealUEQ
, /**< True if unordered or equal */
271 LLVMRealUGT
, /**< True if unordered or greater than */
272 LLVMRealUGE
, /**< True if unordered, greater than, or equal */
273 LLVMRealULT
, /**< True if unordered or less than */
274 LLVMRealULE
, /**< True if unordered, less than, or equal */
275 LLVMRealUNE
, /**< True if unordered or not equal */
276 LLVMRealPredicateTrue
/**< Always true (always folded) */
280 /*===-- Error handling ----------------------------------------------------===*/
282 void LLVMDisposeMessage(char *Message
);
285 /*===-- Contexts ----------------------------------------------------------===*/
287 /* Create and destroy contexts. */
288 LLVMContextRef
LLVMContextCreate(void);
289 LLVMContextRef
LLVMGetGlobalContext(void);
290 void LLVMContextDispose(LLVMContextRef C
);
292 unsigned LLVMGetMDKindIDInContext(LLVMContextRef C
, const char* Name
,
294 unsigned LLVMGetMDKindID(const char* Name
, unsigned SLen
);
296 /*===-- Modules -----------------------------------------------------------===*/
298 /* Create and destroy modules. */
299 /** See llvm::Module::Module. */
300 LLVMModuleRef
LLVMModuleCreateWithName(const char *ModuleID
);
301 LLVMModuleRef
LLVMModuleCreateWithNameInContext(const char *ModuleID
,
304 /** See llvm::Module::~Module. */
305 void LLVMDisposeModule(LLVMModuleRef M
);
307 /** Data layout. See Module::getDataLayout. */
308 const char *LLVMGetDataLayout(LLVMModuleRef M
);
309 void LLVMSetDataLayout(LLVMModuleRef M
, const char *Triple
);
311 /** Target triple. See Module::getTargetTriple. */
312 const char *LLVMGetTarget(LLVMModuleRef M
);
313 void LLVMSetTarget(LLVMModuleRef M
, const char *Triple
);
315 /** See Module::addTypeName. */
316 LLVMBool
LLVMAddTypeName(LLVMModuleRef M
, const char *Name
, LLVMTypeRef Ty
);
317 void LLVMDeleteTypeName(LLVMModuleRef M
, const char *Name
);
318 LLVMTypeRef
LLVMGetTypeByName(LLVMModuleRef M
, const char *Name
);
320 /** See Module::dump. */
321 void LLVMDumpModule(LLVMModuleRef M
);
323 /** See Module::setModuleInlineAsm. */
324 void LLVMSetModuleInlineAsm(LLVMModuleRef M
, const char *Asm
);
326 /*===-- Types -------------------------------------------------------------===*/
328 /* LLVM types conform to the following hierarchy:
343 /** See llvm::LLVMTypeKind::getTypeID. */
344 LLVMTypeKind
LLVMGetTypeKind(LLVMTypeRef Ty
);
346 /** See llvm::LLVMType::getContext. */
347 LLVMContextRef
LLVMGetTypeContext(LLVMTypeRef Ty
);
349 /* Operations on integer types */
350 LLVMTypeRef
LLVMInt1TypeInContext(LLVMContextRef C
);
351 LLVMTypeRef
LLVMInt8TypeInContext(LLVMContextRef C
);
352 LLVMTypeRef
LLVMInt16TypeInContext(LLVMContextRef C
);
353 LLVMTypeRef
LLVMInt32TypeInContext(LLVMContextRef C
);
354 LLVMTypeRef
LLVMInt64TypeInContext(LLVMContextRef C
);
355 LLVMTypeRef
LLVMIntTypeInContext(LLVMContextRef C
, unsigned NumBits
);
357 LLVMTypeRef
LLVMInt1Type(void);
358 LLVMTypeRef
LLVMInt8Type(void);
359 LLVMTypeRef
LLVMInt16Type(void);
360 LLVMTypeRef
LLVMInt32Type(void);
361 LLVMTypeRef
LLVMInt64Type(void);
362 LLVMTypeRef
LLVMIntType(unsigned NumBits
);
363 unsigned LLVMGetIntTypeWidth(LLVMTypeRef IntegerTy
);
365 /* Operations on real types */
366 LLVMTypeRef
LLVMFloatTypeInContext(LLVMContextRef C
);
367 LLVMTypeRef
LLVMDoubleTypeInContext(LLVMContextRef C
);
368 LLVMTypeRef
LLVMX86FP80TypeInContext(LLVMContextRef C
);
369 LLVMTypeRef
LLVMFP128TypeInContext(LLVMContextRef C
);
370 LLVMTypeRef
LLVMPPCFP128TypeInContext(LLVMContextRef C
);
372 LLVMTypeRef
LLVMFloatType(void);
373 LLVMTypeRef
LLVMDoubleType(void);
374 LLVMTypeRef
LLVMX86FP80Type(void);
375 LLVMTypeRef
LLVMFP128Type(void);
376 LLVMTypeRef
LLVMPPCFP128Type(void);
378 /* Operations on function types */
379 LLVMTypeRef
LLVMFunctionType(LLVMTypeRef ReturnType
,
380 LLVMTypeRef
*ParamTypes
, unsigned ParamCount
,
382 LLVMBool
LLVMIsFunctionVarArg(LLVMTypeRef FunctionTy
);
383 LLVMTypeRef
LLVMGetReturnType(LLVMTypeRef FunctionTy
);
384 unsigned LLVMCountParamTypes(LLVMTypeRef FunctionTy
);
385 void LLVMGetParamTypes(LLVMTypeRef FunctionTy
, LLVMTypeRef
*Dest
);
387 /* Operations on struct types */
388 LLVMTypeRef
LLVMStructTypeInContext(LLVMContextRef C
, LLVMTypeRef
*ElementTypes
,
389 unsigned ElementCount
, LLVMBool Packed
);
390 LLVMTypeRef
LLVMStructType(LLVMTypeRef
*ElementTypes
, unsigned ElementCount
,
392 unsigned LLVMCountStructElementTypes(LLVMTypeRef StructTy
);
393 void LLVMGetStructElementTypes(LLVMTypeRef StructTy
, LLVMTypeRef
*Dest
);
394 LLVMBool
LLVMIsPackedStruct(LLVMTypeRef StructTy
);
396 /* Operations on union types */
397 LLVMTypeRef
LLVMUnionTypeInContext(LLVMContextRef C
, LLVMTypeRef
*ElementTypes
,
398 unsigned ElementCount
);
399 LLVMTypeRef
LLVMUnionType(LLVMTypeRef
*ElementTypes
, unsigned ElementCount
);
400 unsigned LLVMCountUnionElementTypes(LLVMTypeRef UnionTy
);
401 void LLVMGetUnionElementTypes(LLVMTypeRef UnionTy
, LLVMTypeRef
*Dest
);
403 /* Operations on array, pointer, and vector types (sequence types) */
404 LLVMTypeRef
LLVMArrayType(LLVMTypeRef ElementType
, unsigned ElementCount
);
405 LLVMTypeRef
LLVMPointerType(LLVMTypeRef ElementType
, unsigned AddressSpace
);
406 LLVMTypeRef
LLVMVectorType(LLVMTypeRef ElementType
, unsigned ElementCount
);
408 LLVMTypeRef
LLVMGetElementType(LLVMTypeRef Ty
);
409 unsigned LLVMGetArrayLength(LLVMTypeRef ArrayTy
);
410 unsigned LLVMGetPointerAddressSpace(LLVMTypeRef PointerTy
);
411 unsigned LLVMGetVectorSize(LLVMTypeRef VectorTy
);
413 /* Operations on other types */
414 LLVMTypeRef
LLVMVoidTypeInContext(LLVMContextRef C
);
415 LLVMTypeRef
LLVMLabelTypeInContext(LLVMContextRef C
);
416 LLVMTypeRef
LLVMOpaqueTypeInContext(LLVMContextRef C
);
418 LLVMTypeRef
LLVMVoidType(void);
419 LLVMTypeRef
LLVMLabelType(void);
420 LLVMTypeRef
LLVMOpaqueType(void);
422 /* Operations on type handles */
423 LLVMTypeHandleRef
LLVMCreateTypeHandle(LLVMTypeRef PotentiallyAbstractTy
);
424 void LLVMRefineType(LLVMTypeRef AbstractTy
, LLVMTypeRef ConcreteTy
);
425 LLVMTypeRef
LLVMResolveTypeHandle(LLVMTypeHandleRef TypeHandle
);
426 void LLVMDisposeTypeHandle(LLVMTypeHandleRef TypeHandle
);
429 /*===-- Values ------------------------------------------------------------===*/
431 /* The bulk of LLVM's object model consists of values, which comprise a very
432 * rich type hierarchy.
435 #define LLVM_FOR_EACH_VALUE_SUBCLASS(macro) \
441 macro(ConstantAggregateZero) \
442 macro(ConstantArray) \
443 macro(ConstantExpr) \
446 macro(ConstantPointerNull) \
447 macro(ConstantStruct) \
448 macro(ConstantVector) \
452 macro(GlobalVariable) \
455 macro(BinaryOperator) \
457 macro(IntrinsicInst) \
458 macro(DbgInfoIntrinsic) \
459 macro(DbgDeclareInst) \
460 macro(EHSelectorInst) \
461 macro(MemIntrinsic) \
468 macro(ExtractElementInst) \
469 macro(GetElementPtrInst) \
470 macro(InsertElementInst) \
471 macro(InsertValueInst) \
474 macro(ShuffleVectorInst) \
476 macro(TerminatorInst) \
481 macro(UnreachableInst) \
483 macro(UnaryInstruction) \
491 macro(IntToPtrInst) \
492 macro(PtrToIntInst) \
498 macro(ExtractValueInst) \
502 /* Operations on all values */
503 LLVMTypeRef
LLVMTypeOf(LLVMValueRef Val
);
504 const char *LLVMGetValueName(LLVMValueRef Val
);
505 void LLVMSetValueName(LLVMValueRef Val
, const char *Name
);
506 void LLVMDumpValue(LLVMValueRef Val
);
507 void LLVMReplaceAllUsesWith(LLVMValueRef OldVal
, LLVMValueRef NewVal
);
508 int LLVMHasMetadata(LLVMValueRef Val
);
509 LLVMValueRef
LLVMGetMetadata(LLVMValueRef Val
, unsigned KindID
);
510 void LLVMSetMetadata(LLVMValueRef Val
, unsigned KindID
, LLVMValueRef Node
);
512 /* Conversion functions. Return the input value if it is an instance of the
513 specified class, otherwise NULL. See llvm::dyn_cast_or_null<>. */
514 #define LLVM_DECLARE_VALUE_CAST(name) \
515 LLVMValueRef LLVMIsA##name(LLVMValueRef Val);
516 LLVM_FOR_EACH_VALUE_SUBCLASS(LLVM_DECLARE_VALUE_CAST
)
518 /* Operations on Uses */
519 LLVMUseRef
LLVMGetFirstUse(LLVMValueRef Val
);
520 LLVMUseRef
LLVMGetNextUse(LLVMUseRef U
);
521 LLVMValueRef
LLVMGetUser(LLVMUseRef U
);
522 LLVMValueRef
LLVMGetUsedValue(LLVMUseRef U
);
524 /* Operations on Users */
525 LLVMValueRef
LLVMGetOperand(LLVMValueRef Val
, unsigned Index
);
527 /* Operations on constants of any type */
528 LLVMValueRef
LLVMConstNull(LLVMTypeRef Ty
); /* all zeroes */
529 LLVMValueRef
LLVMConstAllOnes(LLVMTypeRef Ty
); /* only for int/vector */
530 LLVMValueRef
LLVMGetUndef(LLVMTypeRef Ty
);
531 LLVMBool
LLVMIsConstant(LLVMValueRef Val
);
532 LLVMBool
LLVMIsNull(LLVMValueRef Val
);
533 LLVMBool
LLVMIsUndef(LLVMValueRef Val
);
534 LLVMValueRef
LLVMConstPointerNull(LLVMTypeRef Ty
);
536 /* Operations on metadata */
537 LLVMValueRef
LLVMMDStringInContext(LLVMContextRef C
, const char *Str
,
539 LLVMValueRef
LLVMMDString(const char *Str
, unsigned SLen
);
540 LLVMValueRef
LLVMMDNodeInContext(LLVMContextRef C
, LLVMValueRef
*Vals
,
542 LLVMValueRef
LLVMMDNode(LLVMValueRef
*Vals
, unsigned Count
);
544 /* Operations on scalar constants */
545 LLVMValueRef
LLVMConstInt(LLVMTypeRef IntTy
, unsigned long long N
,
546 LLVMBool SignExtend
);
547 LLVMValueRef
LLVMConstIntOfString(LLVMTypeRef IntTy
, const char *Text
,
549 LLVMValueRef
LLVMConstIntOfStringAndSize(LLVMTypeRef IntTy
, const char *Text
,
550 unsigned SLen
, uint8_t Radix
);
551 LLVMValueRef
LLVMConstReal(LLVMTypeRef RealTy
, double N
);
552 LLVMValueRef
LLVMConstRealOfString(LLVMTypeRef RealTy
, const char *Text
);
553 LLVMValueRef
LLVMConstRealOfStringAndSize(LLVMTypeRef RealTy
, const char *Text
,
555 unsigned long long LLVMConstIntGetZExtValue(LLVMValueRef ConstantVal
);
556 long long LLVMConstIntGetSExtValue(LLVMValueRef ConstantVal
);
559 /* Operations on composite constants */
560 LLVMValueRef
LLVMConstStringInContext(LLVMContextRef C
, const char *Str
,
561 unsigned Length
, LLVMBool DontNullTerminate
);
562 LLVMValueRef
LLVMConstStructInContext(LLVMContextRef C
,
563 LLVMValueRef
*ConstantVals
,
564 unsigned Count
, LLVMBool Packed
);
566 LLVMValueRef
LLVMConstString(const char *Str
, unsigned Length
,
567 LLVMBool DontNullTerminate
);
568 LLVMValueRef
LLVMConstArray(LLVMTypeRef ElementTy
,
569 LLVMValueRef
*ConstantVals
, unsigned Length
);
570 LLVMValueRef
LLVMConstStruct(LLVMValueRef
*ConstantVals
, unsigned Count
,
572 LLVMValueRef
LLVMConstVector(LLVMValueRef
*ScalarConstantVals
, unsigned Size
);
573 LLVMValueRef
LLVMConstUnion(LLVMTypeRef Ty
, LLVMValueRef Val
);
575 /* Constant expressions */
576 LLVMOpcode
LLVMGetConstOpcode(LLVMValueRef ConstantVal
);
577 LLVMValueRef
LLVMAlignOf(LLVMTypeRef Ty
);
578 LLVMValueRef
LLVMSizeOf(LLVMTypeRef Ty
);
579 LLVMValueRef
LLVMConstNeg(LLVMValueRef ConstantVal
);
580 LLVMValueRef
LLVMConstNSWNeg(LLVMValueRef ConstantVal
);
581 LLVMValueRef
LLVMConstNUWNeg(LLVMValueRef ConstantVal
);
582 LLVMValueRef
LLVMConstFNeg(LLVMValueRef ConstantVal
);
583 LLVMValueRef
LLVMConstNot(LLVMValueRef ConstantVal
);
584 LLVMValueRef
LLVMConstAdd(LLVMValueRef LHSConstant
, LLVMValueRef RHSConstant
);
585 LLVMValueRef
LLVMConstNSWAdd(LLVMValueRef LHSConstant
, LLVMValueRef RHSConstant
);
586 LLVMValueRef
LLVMConstNUWAdd(LLVMValueRef LHSConstant
, LLVMValueRef RHSConstant
);
587 LLVMValueRef
LLVMConstFAdd(LLVMValueRef LHSConstant
, LLVMValueRef RHSConstant
);
588 LLVMValueRef
LLVMConstSub(LLVMValueRef LHSConstant
, LLVMValueRef RHSConstant
);
589 LLVMValueRef
LLVMConstNSWSub(LLVMValueRef LHSConstant
, LLVMValueRef RHSConstant
);
590 LLVMValueRef
LLVMConstNUWSub(LLVMValueRef LHSConstant
, LLVMValueRef RHSConstant
);
591 LLVMValueRef
LLVMConstFSub(LLVMValueRef LHSConstant
, LLVMValueRef RHSConstant
);
592 LLVMValueRef
LLVMConstMul(LLVMValueRef LHSConstant
, LLVMValueRef RHSConstant
);
593 LLVMValueRef
LLVMConstNSWMul(LLVMValueRef LHSConstant
, LLVMValueRef RHSConstant
);
594 LLVMValueRef
LLVMConstNUWMul(LLVMValueRef LHSConstant
, LLVMValueRef RHSConstant
);
595 LLVMValueRef
LLVMConstFMul(LLVMValueRef LHSConstant
, LLVMValueRef RHSConstant
);
596 LLVMValueRef
LLVMConstUDiv(LLVMValueRef LHSConstant
, LLVMValueRef RHSConstant
);
597 LLVMValueRef
LLVMConstSDiv(LLVMValueRef LHSConstant
, LLVMValueRef RHSConstant
);
598 LLVMValueRef
LLVMConstExactSDiv(LLVMValueRef LHSConstant
, LLVMValueRef RHSConstant
);
599 LLVMValueRef
LLVMConstFDiv(LLVMValueRef LHSConstant
, LLVMValueRef RHSConstant
);
600 LLVMValueRef
LLVMConstURem(LLVMValueRef LHSConstant
, LLVMValueRef RHSConstant
);
601 LLVMValueRef
LLVMConstSRem(LLVMValueRef LHSConstant
, LLVMValueRef RHSConstant
);
602 LLVMValueRef
LLVMConstFRem(LLVMValueRef LHSConstant
, LLVMValueRef RHSConstant
);
603 LLVMValueRef
LLVMConstAnd(LLVMValueRef LHSConstant
, LLVMValueRef RHSConstant
);
604 LLVMValueRef
LLVMConstOr(LLVMValueRef LHSConstant
, LLVMValueRef RHSConstant
);
605 LLVMValueRef
LLVMConstXor(LLVMValueRef LHSConstant
, LLVMValueRef RHSConstant
);
606 LLVMValueRef
LLVMConstICmp(LLVMIntPredicate Predicate
,
607 LLVMValueRef LHSConstant
, LLVMValueRef RHSConstant
);
608 LLVMValueRef
LLVMConstFCmp(LLVMRealPredicate Predicate
,
609 LLVMValueRef LHSConstant
, LLVMValueRef RHSConstant
);
610 LLVMValueRef
LLVMConstShl(LLVMValueRef LHSConstant
, LLVMValueRef RHSConstant
);
611 LLVMValueRef
LLVMConstLShr(LLVMValueRef LHSConstant
, LLVMValueRef RHSConstant
);
612 LLVMValueRef
LLVMConstAShr(LLVMValueRef LHSConstant
, LLVMValueRef RHSConstant
);
613 LLVMValueRef
LLVMConstGEP(LLVMValueRef ConstantVal
,
614 LLVMValueRef
*ConstantIndices
, unsigned NumIndices
);
615 LLVMValueRef
LLVMConstInBoundsGEP(LLVMValueRef ConstantVal
,
616 LLVMValueRef
*ConstantIndices
,
617 unsigned NumIndices
);
618 LLVMValueRef
LLVMConstTrunc(LLVMValueRef ConstantVal
, LLVMTypeRef ToType
);
619 LLVMValueRef
LLVMConstSExt(LLVMValueRef ConstantVal
, LLVMTypeRef ToType
);
620 LLVMValueRef
LLVMConstZExt(LLVMValueRef ConstantVal
, LLVMTypeRef ToType
);
621 LLVMValueRef
LLVMConstFPTrunc(LLVMValueRef ConstantVal
, LLVMTypeRef ToType
);
622 LLVMValueRef
LLVMConstFPExt(LLVMValueRef ConstantVal
, LLVMTypeRef ToType
);
623 LLVMValueRef
LLVMConstUIToFP(LLVMValueRef ConstantVal
, LLVMTypeRef ToType
);
624 LLVMValueRef
LLVMConstSIToFP(LLVMValueRef ConstantVal
, LLVMTypeRef ToType
);
625 LLVMValueRef
LLVMConstFPToUI(LLVMValueRef ConstantVal
, LLVMTypeRef ToType
);
626 LLVMValueRef
LLVMConstFPToSI(LLVMValueRef ConstantVal
, LLVMTypeRef ToType
);
627 LLVMValueRef
LLVMConstPtrToInt(LLVMValueRef ConstantVal
, LLVMTypeRef ToType
);
628 LLVMValueRef
LLVMConstIntToPtr(LLVMValueRef ConstantVal
, LLVMTypeRef ToType
);
629 LLVMValueRef
LLVMConstBitCast(LLVMValueRef ConstantVal
, LLVMTypeRef ToType
);
630 LLVMValueRef
LLVMConstZExtOrBitCast(LLVMValueRef ConstantVal
,
632 LLVMValueRef
LLVMConstSExtOrBitCast(LLVMValueRef ConstantVal
,
634 LLVMValueRef
LLVMConstTruncOrBitCast(LLVMValueRef ConstantVal
,
636 LLVMValueRef
LLVMConstPointerCast(LLVMValueRef ConstantVal
,
638 LLVMValueRef
LLVMConstIntCast(LLVMValueRef ConstantVal
, LLVMTypeRef ToType
,
640 LLVMValueRef
LLVMConstFPCast(LLVMValueRef ConstantVal
, LLVMTypeRef ToType
);
641 LLVMValueRef
LLVMConstSelect(LLVMValueRef ConstantCondition
,
642 LLVMValueRef ConstantIfTrue
,
643 LLVMValueRef ConstantIfFalse
);
644 LLVMValueRef
LLVMConstExtractElement(LLVMValueRef VectorConstant
,
645 LLVMValueRef IndexConstant
);
646 LLVMValueRef
LLVMConstInsertElement(LLVMValueRef VectorConstant
,
647 LLVMValueRef ElementValueConstant
,
648 LLVMValueRef IndexConstant
);
649 LLVMValueRef
LLVMConstShuffleVector(LLVMValueRef VectorAConstant
,
650 LLVMValueRef VectorBConstant
,
651 LLVMValueRef MaskConstant
);
652 LLVMValueRef
LLVMConstExtractValue(LLVMValueRef AggConstant
, unsigned *IdxList
,
654 LLVMValueRef
LLVMConstInsertValue(LLVMValueRef AggConstant
,
655 LLVMValueRef ElementValueConstant
,
656 unsigned *IdxList
, unsigned NumIdx
);
657 LLVMValueRef
LLVMConstInlineAsm(LLVMTypeRef Ty
,
658 const char *AsmString
, const char *Constraints
,
659 LLVMBool HasSideEffects
, LLVMBool IsAlignStack
);
660 LLVMValueRef
LLVMBlockAddress(LLVMValueRef F
, LLVMBasicBlockRef BB
);
662 /* Operations on global variables, functions, and aliases (globals) */
663 LLVMModuleRef
LLVMGetGlobalParent(LLVMValueRef Global
);
664 LLVMBool
LLVMIsDeclaration(LLVMValueRef Global
);
665 LLVMLinkage
LLVMGetLinkage(LLVMValueRef Global
);
666 void LLVMSetLinkage(LLVMValueRef Global
, LLVMLinkage Linkage
);
667 const char *LLVMGetSection(LLVMValueRef Global
);
668 void LLVMSetSection(LLVMValueRef Global
, const char *Section
);
669 LLVMVisibility
LLVMGetVisibility(LLVMValueRef Global
);
670 void LLVMSetVisibility(LLVMValueRef Global
, LLVMVisibility Viz
);
671 unsigned LLVMGetAlignment(LLVMValueRef Global
);
672 void LLVMSetAlignment(LLVMValueRef Global
, unsigned Bytes
);
674 /* Operations on global variables */
675 LLVMValueRef
LLVMAddGlobal(LLVMModuleRef M
, LLVMTypeRef Ty
, const char *Name
);
676 LLVMValueRef
LLVMAddGlobalInAddressSpace(LLVMModuleRef M
, LLVMTypeRef Ty
,
678 unsigned AddressSpace
);
679 LLVMValueRef
LLVMGetNamedGlobal(LLVMModuleRef M
, const char *Name
);
680 LLVMValueRef
LLVMGetFirstGlobal(LLVMModuleRef M
);
681 LLVMValueRef
LLVMGetLastGlobal(LLVMModuleRef M
);
682 LLVMValueRef
LLVMGetNextGlobal(LLVMValueRef GlobalVar
);
683 LLVMValueRef
LLVMGetPreviousGlobal(LLVMValueRef GlobalVar
);
684 void LLVMDeleteGlobal(LLVMValueRef GlobalVar
);
685 LLVMValueRef
LLVMGetInitializer(LLVMValueRef GlobalVar
);
686 void LLVMSetInitializer(LLVMValueRef GlobalVar
, LLVMValueRef ConstantVal
);
687 LLVMBool
LLVMIsThreadLocal(LLVMValueRef GlobalVar
);
688 void LLVMSetThreadLocal(LLVMValueRef GlobalVar
, LLVMBool IsThreadLocal
);
689 LLVMBool
LLVMIsGlobalConstant(LLVMValueRef GlobalVar
);
690 void LLVMSetGlobalConstant(LLVMValueRef GlobalVar
, LLVMBool IsConstant
);
692 /* Operations on aliases */
693 LLVMValueRef
LLVMAddAlias(LLVMModuleRef M
, LLVMTypeRef Ty
, LLVMValueRef Aliasee
,
696 /* Operations on functions */
697 LLVMValueRef
LLVMAddFunction(LLVMModuleRef M
, const char *Name
,
698 LLVMTypeRef FunctionTy
);
699 LLVMValueRef
LLVMGetNamedFunction(LLVMModuleRef M
, const char *Name
);
700 LLVMValueRef
LLVMGetFirstFunction(LLVMModuleRef M
);
701 LLVMValueRef
LLVMGetLastFunction(LLVMModuleRef M
);
702 LLVMValueRef
LLVMGetNextFunction(LLVMValueRef Fn
);
703 LLVMValueRef
LLVMGetPreviousFunction(LLVMValueRef Fn
);
704 void LLVMDeleteFunction(LLVMValueRef Fn
);
705 unsigned LLVMGetIntrinsicID(LLVMValueRef Fn
);
706 unsigned LLVMGetFunctionCallConv(LLVMValueRef Fn
);
707 void LLVMSetFunctionCallConv(LLVMValueRef Fn
, unsigned CC
);
708 const char *LLVMGetGC(LLVMValueRef Fn
);
709 void LLVMSetGC(LLVMValueRef Fn
, const char *Name
);
710 void LLVMAddFunctionAttr(LLVMValueRef Fn
, LLVMAttribute PA
);
711 LLVMAttribute
LLVMGetFunctionAttr(LLVMValueRef Fn
);
712 void LLVMRemoveFunctionAttr(LLVMValueRef Fn
, LLVMAttribute PA
);
714 /* Operations on parameters */
715 unsigned LLVMCountParams(LLVMValueRef Fn
);
716 void LLVMGetParams(LLVMValueRef Fn
, LLVMValueRef
*Params
);
717 LLVMValueRef
LLVMGetParam(LLVMValueRef Fn
, unsigned Index
);
718 LLVMValueRef
LLVMGetParamParent(LLVMValueRef Inst
);
719 LLVMValueRef
LLVMGetFirstParam(LLVMValueRef Fn
);
720 LLVMValueRef
LLVMGetLastParam(LLVMValueRef Fn
);
721 LLVMValueRef
LLVMGetNextParam(LLVMValueRef Arg
);
722 LLVMValueRef
LLVMGetPreviousParam(LLVMValueRef Arg
);
723 void LLVMAddAttribute(LLVMValueRef Arg
, LLVMAttribute PA
);
724 void LLVMRemoveAttribute(LLVMValueRef Arg
, LLVMAttribute PA
);
725 LLVMAttribute
LLVMGetAttribute(LLVMValueRef Arg
);
726 void LLVMSetParamAlignment(LLVMValueRef Arg
, unsigned align
);
728 /* Operations on basic blocks */
729 LLVMValueRef
LLVMBasicBlockAsValue(LLVMBasicBlockRef BB
);
730 LLVMBool
LLVMValueIsBasicBlock(LLVMValueRef Val
);
731 LLVMBasicBlockRef
LLVMValueAsBasicBlock(LLVMValueRef Val
);
732 LLVMValueRef
LLVMGetBasicBlockParent(LLVMBasicBlockRef BB
);
733 unsigned LLVMCountBasicBlocks(LLVMValueRef Fn
);
734 void LLVMGetBasicBlocks(LLVMValueRef Fn
, LLVMBasicBlockRef
*BasicBlocks
);
735 LLVMBasicBlockRef
LLVMGetFirstBasicBlock(LLVMValueRef Fn
);
736 LLVMBasicBlockRef
LLVMGetLastBasicBlock(LLVMValueRef Fn
);
737 LLVMBasicBlockRef
LLVMGetNextBasicBlock(LLVMBasicBlockRef BB
);
738 LLVMBasicBlockRef
LLVMGetPreviousBasicBlock(LLVMBasicBlockRef BB
);
739 LLVMBasicBlockRef
LLVMGetEntryBasicBlock(LLVMValueRef Fn
);
741 LLVMBasicBlockRef
LLVMAppendBasicBlockInContext(LLVMContextRef C
,
744 LLVMBasicBlockRef
LLVMInsertBasicBlockInContext(LLVMContextRef C
,
745 LLVMBasicBlockRef BB
,
748 LLVMBasicBlockRef
LLVMAppendBasicBlock(LLVMValueRef Fn
, const char *Name
);
749 LLVMBasicBlockRef
LLVMInsertBasicBlock(LLVMBasicBlockRef InsertBeforeBB
,
751 void LLVMDeleteBasicBlock(LLVMBasicBlockRef BB
);
753 void LLVMMoveBasicBlockBefore(LLVMBasicBlockRef BB
, LLVMBasicBlockRef MovePos
);
754 void LLVMMoveBasicBlockAfter(LLVMBasicBlockRef BB
, LLVMBasicBlockRef MovePos
);
756 /* Operations on instructions */
757 LLVMBasicBlockRef
LLVMGetInstructionParent(LLVMValueRef Inst
);
758 LLVMValueRef
LLVMGetFirstInstruction(LLVMBasicBlockRef BB
);
759 LLVMValueRef
LLVMGetLastInstruction(LLVMBasicBlockRef BB
);
760 LLVMValueRef
LLVMGetNextInstruction(LLVMValueRef Inst
);
761 LLVMValueRef
LLVMGetPreviousInstruction(LLVMValueRef Inst
);
763 /* Operations on call sites */
764 void LLVMSetInstructionCallConv(LLVMValueRef Instr
, unsigned CC
);
765 unsigned LLVMGetInstructionCallConv(LLVMValueRef Instr
);
766 void LLVMAddInstrAttribute(LLVMValueRef Instr
, unsigned index
, LLVMAttribute
);
767 void LLVMRemoveInstrAttribute(LLVMValueRef Instr
, unsigned index
,
769 void LLVMSetInstrParamAlignment(LLVMValueRef Instr
, unsigned index
,
772 /* Operations on call instructions (only) */
773 LLVMBool
LLVMIsTailCall(LLVMValueRef CallInst
);
774 void LLVMSetTailCall(LLVMValueRef CallInst
, LLVMBool IsTailCall
);
776 /* Operations on phi nodes */
777 void LLVMAddIncoming(LLVMValueRef PhiNode
, LLVMValueRef
*IncomingValues
,
778 LLVMBasicBlockRef
*IncomingBlocks
, unsigned Count
);
779 unsigned LLVMCountIncoming(LLVMValueRef PhiNode
);
780 LLVMValueRef
LLVMGetIncomingValue(LLVMValueRef PhiNode
, unsigned Index
);
781 LLVMBasicBlockRef
LLVMGetIncomingBlock(LLVMValueRef PhiNode
, unsigned Index
);
783 /*===-- Instruction builders ----------------------------------------------===*/
785 /* An instruction builder represents a point within a basic block, and is the
786 * exclusive means of building instructions using the C interface.
789 LLVMBuilderRef
LLVMCreateBuilderInContext(LLVMContextRef C
);
790 LLVMBuilderRef
LLVMCreateBuilder(void);
791 void LLVMPositionBuilder(LLVMBuilderRef Builder
, LLVMBasicBlockRef Block
,
793 void LLVMPositionBuilderBefore(LLVMBuilderRef Builder
, LLVMValueRef Instr
);
794 void LLVMPositionBuilderAtEnd(LLVMBuilderRef Builder
, LLVMBasicBlockRef Block
);
795 LLVMBasicBlockRef
LLVMGetInsertBlock(LLVMBuilderRef Builder
);
796 void LLVMClearInsertionPosition(LLVMBuilderRef Builder
);
797 void LLVMInsertIntoBuilder(LLVMBuilderRef Builder
, LLVMValueRef Instr
);
798 void LLVMInsertIntoBuilderWithName(LLVMBuilderRef Builder
, LLVMValueRef Instr
,
800 void LLVMDisposeBuilder(LLVMBuilderRef Builder
);
803 void LLVMSetCurrentDebugLocation(LLVMBuilderRef Builder
, LLVMValueRef L
);
804 LLVMValueRef
LLVMGetCurrentDebugLocation(LLVMBuilderRef Builder
);
805 void LLVMSetInstDebugLocation(LLVMBuilderRef Builder
, LLVMValueRef Inst
);
808 LLVMValueRef
LLVMBuildRetVoid(LLVMBuilderRef
);
809 LLVMValueRef
LLVMBuildRet(LLVMBuilderRef
, LLVMValueRef V
);
810 LLVMValueRef
LLVMBuildAggregateRet(LLVMBuilderRef
, LLVMValueRef
*RetVals
,
812 LLVMValueRef
LLVMBuildBr(LLVMBuilderRef
, LLVMBasicBlockRef Dest
);
813 LLVMValueRef
LLVMBuildCondBr(LLVMBuilderRef
, LLVMValueRef If
,
814 LLVMBasicBlockRef Then
, LLVMBasicBlockRef Else
);
815 LLVMValueRef
LLVMBuildSwitch(LLVMBuilderRef
, LLVMValueRef V
,
816 LLVMBasicBlockRef Else
, unsigned NumCases
);
817 LLVMValueRef
LLVMBuildIndirectBr(LLVMBuilderRef B
, LLVMValueRef Addr
,
819 LLVMValueRef
LLVMBuildInvoke(LLVMBuilderRef
, LLVMValueRef Fn
,
820 LLVMValueRef
*Args
, unsigned NumArgs
,
821 LLVMBasicBlockRef Then
, LLVMBasicBlockRef Catch
,
823 LLVMValueRef
LLVMBuildUnwind(LLVMBuilderRef
);
824 LLVMValueRef
LLVMBuildUnreachable(LLVMBuilderRef
);
826 /* Add a case to the switch instruction */
827 void LLVMAddCase(LLVMValueRef Switch
, LLVMValueRef OnVal
,
828 LLVMBasicBlockRef Dest
);
830 /* Add a destination to the indirectbr instruction */
831 void LLVMAddDestination(LLVMValueRef IndirectBr
, LLVMBasicBlockRef Dest
);
834 LLVMValueRef
LLVMBuildAdd(LLVMBuilderRef
, LLVMValueRef LHS
, LLVMValueRef RHS
,
836 LLVMValueRef
LLVMBuildNSWAdd(LLVMBuilderRef
, LLVMValueRef LHS
, LLVMValueRef RHS
,
838 LLVMValueRef
LLVMBuildNUWAdd(LLVMBuilderRef
, LLVMValueRef LHS
, LLVMValueRef RHS
,
840 LLVMValueRef
LLVMBuildFAdd(LLVMBuilderRef
, LLVMValueRef LHS
, LLVMValueRef RHS
,
842 LLVMValueRef
LLVMBuildSub(LLVMBuilderRef
, LLVMValueRef LHS
, LLVMValueRef RHS
,
844 LLVMValueRef
LLVMBuildNSWSub(LLVMBuilderRef
, LLVMValueRef LHS
, LLVMValueRef RHS
,
846 LLVMValueRef
LLVMBuildNUWSub(LLVMBuilderRef
, LLVMValueRef LHS
, LLVMValueRef RHS
,
848 LLVMValueRef
LLVMBuildFSub(LLVMBuilderRef
, LLVMValueRef LHS
, LLVMValueRef RHS
,
850 LLVMValueRef
LLVMBuildMul(LLVMBuilderRef
, LLVMValueRef LHS
, LLVMValueRef RHS
,
852 LLVMValueRef
LLVMBuildNSWMul(LLVMBuilderRef
, LLVMValueRef LHS
, LLVMValueRef RHS
,
854 LLVMValueRef
LLVMBuildNUWMul(LLVMBuilderRef
, LLVMValueRef LHS
, LLVMValueRef RHS
,
856 LLVMValueRef
LLVMBuildFMul(LLVMBuilderRef
, LLVMValueRef LHS
, LLVMValueRef RHS
,
858 LLVMValueRef
LLVMBuildUDiv(LLVMBuilderRef
, LLVMValueRef LHS
, LLVMValueRef RHS
,
860 LLVMValueRef
LLVMBuildSDiv(LLVMBuilderRef
, LLVMValueRef LHS
, LLVMValueRef RHS
,
862 LLVMValueRef
LLVMBuildExactSDiv(LLVMBuilderRef
, LLVMValueRef LHS
, LLVMValueRef RHS
,
864 LLVMValueRef
LLVMBuildFDiv(LLVMBuilderRef
, LLVMValueRef LHS
, LLVMValueRef RHS
,
866 LLVMValueRef
LLVMBuildURem(LLVMBuilderRef
, LLVMValueRef LHS
, LLVMValueRef RHS
,
868 LLVMValueRef
LLVMBuildSRem(LLVMBuilderRef
, LLVMValueRef LHS
, LLVMValueRef RHS
,
870 LLVMValueRef
LLVMBuildFRem(LLVMBuilderRef
, LLVMValueRef LHS
, LLVMValueRef RHS
,
872 LLVMValueRef
LLVMBuildShl(LLVMBuilderRef
, LLVMValueRef LHS
, LLVMValueRef RHS
,
874 LLVMValueRef
LLVMBuildLShr(LLVMBuilderRef
, LLVMValueRef LHS
, LLVMValueRef RHS
,
876 LLVMValueRef
LLVMBuildAShr(LLVMBuilderRef
, LLVMValueRef LHS
, LLVMValueRef RHS
,
878 LLVMValueRef
LLVMBuildAnd(LLVMBuilderRef
, LLVMValueRef LHS
, LLVMValueRef RHS
,
880 LLVMValueRef
LLVMBuildOr(LLVMBuilderRef
, LLVMValueRef LHS
, LLVMValueRef RHS
,
882 LLVMValueRef
LLVMBuildXor(LLVMBuilderRef
, LLVMValueRef LHS
, LLVMValueRef RHS
,
884 LLVMValueRef
LLVMBuildBinOp(LLVMBuilderRef B
, LLVMOpcode Op
,
885 LLVMValueRef LHS
, LLVMValueRef RHS
,
887 LLVMValueRef
LLVMBuildNeg(LLVMBuilderRef
, LLVMValueRef V
, const char *Name
);
888 LLVMValueRef
LLVMBuildNSWNeg(LLVMBuilderRef B
, LLVMValueRef V
,
890 LLVMValueRef
LLVMBuildNUWNeg(LLVMBuilderRef B
, LLVMValueRef V
,
892 LLVMValueRef
LLVMBuildFNeg(LLVMBuilderRef
, LLVMValueRef V
, const char *Name
);
893 LLVMValueRef
LLVMBuildNot(LLVMBuilderRef
, LLVMValueRef V
, const char *Name
);
896 LLVMValueRef
LLVMBuildMalloc(LLVMBuilderRef
, LLVMTypeRef Ty
, const char *Name
);
897 LLVMValueRef
LLVMBuildArrayMalloc(LLVMBuilderRef
, LLVMTypeRef Ty
,
898 LLVMValueRef Val
, const char *Name
);
899 LLVMValueRef
LLVMBuildAlloca(LLVMBuilderRef
, LLVMTypeRef Ty
, const char *Name
);
900 LLVMValueRef
LLVMBuildArrayAlloca(LLVMBuilderRef
, LLVMTypeRef Ty
,
901 LLVMValueRef Val
, const char *Name
);
902 LLVMValueRef
LLVMBuildFree(LLVMBuilderRef
, LLVMValueRef PointerVal
);
903 LLVMValueRef
LLVMBuildLoad(LLVMBuilderRef
, LLVMValueRef PointerVal
,
905 LLVMValueRef
LLVMBuildStore(LLVMBuilderRef
, LLVMValueRef Val
, LLVMValueRef Ptr
);
906 LLVMValueRef
LLVMBuildGEP(LLVMBuilderRef B
, LLVMValueRef Pointer
,
907 LLVMValueRef
*Indices
, unsigned NumIndices
,
909 LLVMValueRef
LLVMBuildInBoundsGEP(LLVMBuilderRef B
, LLVMValueRef Pointer
,
910 LLVMValueRef
*Indices
, unsigned NumIndices
,
912 LLVMValueRef
LLVMBuildStructGEP(LLVMBuilderRef B
, LLVMValueRef Pointer
,
913 unsigned Idx
, const char *Name
);
914 LLVMValueRef
LLVMBuildGlobalString(LLVMBuilderRef B
, const char *Str
,
916 LLVMValueRef
LLVMBuildGlobalStringPtr(LLVMBuilderRef B
, const char *Str
,
920 LLVMValueRef
LLVMBuildTrunc(LLVMBuilderRef
, LLVMValueRef Val
,
921 LLVMTypeRef DestTy
, const char *Name
);
922 LLVMValueRef
LLVMBuildZExt(LLVMBuilderRef
, LLVMValueRef Val
,
923 LLVMTypeRef DestTy
, const char *Name
);
924 LLVMValueRef
LLVMBuildSExt(LLVMBuilderRef
, LLVMValueRef Val
,
925 LLVMTypeRef DestTy
, const char *Name
);
926 LLVMValueRef
LLVMBuildFPToUI(LLVMBuilderRef
, LLVMValueRef Val
,
927 LLVMTypeRef DestTy
, const char *Name
);
928 LLVMValueRef
LLVMBuildFPToSI(LLVMBuilderRef
, LLVMValueRef Val
,
929 LLVMTypeRef DestTy
, const char *Name
);
930 LLVMValueRef
LLVMBuildUIToFP(LLVMBuilderRef
, LLVMValueRef Val
,
931 LLVMTypeRef DestTy
, const char *Name
);
932 LLVMValueRef
LLVMBuildSIToFP(LLVMBuilderRef
, LLVMValueRef Val
,
933 LLVMTypeRef DestTy
, const char *Name
);
934 LLVMValueRef
LLVMBuildFPTrunc(LLVMBuilderRef
, LLVMValueRef Val
,
935 LLVMTypeRef DestTy
, const char *Name
);
936 LLVMValueRef
LLVMBuildFPExt(LLVMBuilderRef
, LLVMValueRef Val
,
937 LLVMTypeRef DestTy
, const char *Name
);
938 LLVMValueRef
LLVMBuildPtrToInt(LLVMBuilderRef
, LLVMValueRef Val
,
939 LLVMTypeRef DestTy
, const char *Name
);
940 LLVMValueRef
LLVMBuildIntToPtr(LLVMBuilderRef
, LLVMValueRef Val
,
941 LLVMTypeRef DestTy
, const char *Name
);
942 LLVMValueRef
LLVMBuildBitCast(LLVMBuilderRef
, LLVMValueRef Val
,
943 LLVMTypeRef DestTy
, const char *Name
);
944 LLVMValueRef
LLVMBuildZExtOrBitCast(LLVMBuilderRef
, LLVMValueRef Val
,
945 LLVMTypeRef DestTy
, const char *Name
);
946 LLVMValueRef
LLVMBuildSExtOrBitCast(LLVMBuilderRef
, LLVMValueRef Val
,
947 LLVMTypeRef DestTy
, const char *Name
);
948 LLVMValueRef
LLVMBuildTruncOrBitCast(LLVMBuilderRef
, LLVMValueRef Val
,
949 LLVMTypeRef DestTy
, const char *Name
);
950 LLVMValueRef
LLVMBuildCast(LLVMBuilderRef B
, LLVMOpcode Op
, LLVMValueRef Val
,
951 LLVMTypeRef DestTy
, const char *Name
);
952 LLVMValueRef
LLVMBuildPointerCast(LLVMBuilderRef
, LLVMValueRef Val
,
953 LLVMTypeRef DestTy
, const char *Name
);
954 LLVMValueRef
LLVMBuildIntCast(LLVMBuilderRef
, LLVMValueRef Val
, /*Signed cast!*/
955 LLVMTypeRef DestTy
, const char *Name
);
956 LLVMValueRef
LLVMBuildFPCast(LLVMBuilderRef
, LLVMValueRef Val
,
957 LLVMTypeRef DestTy
, const char *Name
);
960 LLVMValueRef
LLVMBuildICmp(LLVMBuilderRef
, LLVMIntPredicate Op
,
961 LLVMValueRef LHS
, LLVMValueRef RHS
,
963 LLVMValueRef
LLVMBuildFCmp(LLVMBuilderRef
, LLVMRealPredicate Op
,
964 LLVMValueRef LHS
, LLVMValueRef RHS
,
967 /* Miscellaneous instructions */
968 LLVMValueRef
LLVMBuildPhi(LLVMBuilderRef
, LLVMTypeRef Ty
, const char *Name
);
969 LLVMValueRef
LLVMBuildCall(LLVMBuilderRef
, LLVMValueRef Fn
,
970 LLVMValueRef
*Args
, unsigned NumArgs
,
972 LLVMValueRef
LLVMBuildSelect(LLVMBuilderRef
, LLVMValueRef If
,
973 LLVMValueRef Then
, LLVMValueRef Else
,
975 LLVMValueRef
LLVMBuildVAArg(LLVMBuilderRef
, LLVMValueRef List
, LLVMTypeRef Ty
,
977 LLVMValueRef
LLVMBuildExtractElement(LLVMBuilderRef
, LLVMValueRef VecVal
,
978 LLVMValueRef Index
, const char *Name
);
979 LLVMValueRef
LLVMBuildInsertElement(LLVMBuilderRef
, LLVMValueRef VecVal
,
980 LLVMValueRef EltVal
, LLVMValueRef Index
,
982 LLVMValueRef
LLVMBuildShuffleVector(LLVMBuilderRef
, LLVMValueRef V1
,
983 LLVMValueRef V2
, LLVMValueRef Mask
,
985 LLVMValueRef
LLVMBuildExtractValue(LLVMBuilderRef
, LLVMValueRef AggVal
,
986 unsigned Index
, const char *Name
);
987 LLVMValueRef
LLVMBuildInsertValue(LLVMBuilderRef
, LLVMValueRef AggVal
,
988 LLVMValueRef EltVal
, unsigned Index
,
991 LLVMValueRef
LLVMBuildIsNull(LLVMBuilderRef
, LLVMValueRef Val
,
993 LLVMValueRef
LLVMBuildIsNotNull(LLVMBuilderRef
, LLVMValueRef Val
,
995 LLVMValueRef
LLVMBuildPtrDiff(LLVMBuilderRef
, LLVMValueRef LHS
,
996 LLVMValueRef RHS
, const char *Name
);
999 /*===-- Module providers --------------------------------------------------===*/
1001 /* Changes the type of M so it can be passed to FunctionPassManagers and the
1002 * JIT. They take ModuleProviders for historical reasons.
1004 LLVMModuleProviderRef
1005 LLVMCreateModuleProviderForExistingModule(LLVMModuleRef M
);
1007 /* Destroys the module M.
1009 void LLVMDisposeModuleProvider(LLVMModuleProviderRef M
);
1012 /*===-- Memory buffers ----------------------------------------------------===*/
1014 LLVMBool
LLVMCreateMemoryBufferWithContentsOfFile(const char *Path
,
1015 LLVMMemoryBufferRef
*OutMemBuf
,
1017 LLVMBool
LLVMCreateMemoryBufferWithSTDIN(LLVMMemoryBufferRef
*OutMemBuf
,
1019 void LLVMDisposeMemoryBuffer(LLVMMemoryBufferRef MemBuf
);
1022 /*===-- Pass Managers -----------------------------------------------------===*/
1024 /** Constructs a new whole-module pass pipeline. This type of pipeline is
1025 suitable for link-time optimization and whole-module transformations.
1026 See llvm::PassManager::PassManager. */
1027 LLVMPassManagerRef
LLVMCreatePassManager(void);
1029 /** Constructs a new function-by-function pass pipeline over the module
1030 provider. It does not take ownership of the module provider. This type of
1031 pipeline is suitable for code generation and JIT compilation tasks.
1032 See llvm::FunctionPassManager::FunctionPassManager. */
1033 LLVMPassManagerRef
LLVMCreateFunctionPassManagerForModule(LLVMModuleRef M
);
1035 /** Deprecated: Use LLVMCreateFunctionPassManagerForModule instead. */
1036 LLVMPassManagerRef
LLVMCreateFunctionPassManager(LLVMModuleProviderRef MP
);
1038 /** Initializes, executes on the provided module, and finalizes all of the
1039 passes scheduled in the pass manager. Returns 1 if any of the passes
1040 modified the module, 0 otherwise. See llvm::PassManager::run(Module&). */
1041 LLVMBool
LLVMRunPassManager(LLVMPassManagerRef PM
, LLVMModuleRef M
);
1043 /** Initializes all of the function passes scheduled in the function pass
1044 manager. Returns 1 if any of the passes modified the module, 0 otherwise.
1045 See llvm::FunctionPassManager::doInitialization. */
1046 LLVMBool
LLVMInitializeFunctionPassManager(LLVMPassManagerRef FPM
);
1048 /** Executes all of the function passes scheduled in the function pass manager
1049 on the provided function. Returns 1 if any of the passes modified the
1050 function, false otherwise.
1051 See llvm::FunctionPassManager::run(Function&). */
1052 LLVMBool
LLVMRunFunctionPassManager(LLVMPassManagerRef FPM
, LLVMValueRef F
);
1054 /** Finalizes all of the function passes scheduled in in the function pass
1055 manager. Returns 1 if any of the passes modified the module, 0 otherwise.
1056 See llvm::FunctionPassManager::doFinalization. */
1057 LLVMBool
LLVMFinalizeFunctionPassManager(LLVMPassManagerRef FPM
);
1059 /** Frees the memory of a pass pipeline. For function pipelines, does not free
1060 the module provider.
1061 See llvm::PassManagerBase::~PassManagerBase. */
1062 void LLVMDisposePassManager(LLVMPassManagerRef PM
);
1070 class PassManagerBase
;
1072 #define DEFINE_SIMPLE_CONVERSION_FUNCTIONS(ty, ref) \
1073 inline ty *unwrap(ref P) { \
1074 return reinterpret_cast<ty*>(P); \
1077 inline ref wrap(const ty *P) { \
1078 return reinterpret_cast<ref>(const_cast<ty*>(P)); \
1081 #define DEFINE_ISA_CONVERSION_FUNCTIONS(ty, ref) \
1082 DEFINE_SIMPLE_CONVERSION_FUNCTIONS(ty, ref) \
1084 template<typename T> \
1085 inline T *unwrap(ref P) { \
1086 return cast<T>(unwrap(P)); \
1089 #define DEFINE_STDCXX_CONVERSION_FUNCTIONS(ty, ref) \
1090 DEFINE_SIMPLE_CONVERSION_FUNCTIONS(ty, ref) \
1092 template<typename T> \
1093 inline T *unwrap(ref P) { \
1094 T *Q = (T*)unwrap(P); \
1095 assert(Q && "Invalid cast!"); \
1099 DEFINE_ISA_CONVERSION_FUNCTIONS (Type
, LLVMTypeRef
)
1100 DEFINE_ISA_CONVERSION_FUNCTIONS (Value
, LLVMValueRef
)
1101 DEFINE_SIMPLE_CONVERSION_FUNCTIONS(Module
, LLVMModuleRef
)
1102 DEFINE_SIMPLE_CONVERSION_FUNCTIONS(BasicBlock
, LLVMBasicBlockRef
)
1103 DEFINE_SIMPLE_CONVERSION_FUNCTIONS(IRBuilder
<>, LLVMBuilderRef
)
1104 DEFINE_SIMPLE_CONVERSION_FUNCTIONS(PATypeHolder
, LLVMTypeHandleRef
)
1105 DEFINE_SIMPLE_CONVERSION_FUNCTIONS(MemoryBuffer
, LLVMMemoryBufferRef
)
1106 DEFINE_SIMPLE_CONVERSION_FUNCTIONS(LLVMContext
, LLVMContextRef
)
1107 DEFINE_SIMPLE_CONVERSION_FUNCTIONS(Use
, LLVMUseRef
)
1108 DEFINE_STDCXX_CONVERSION_FUNCTIONS(PassManagerBase
, LLVMPassManagerRef
)
1109 /* LLVMModuleProviderRef exists for historical reasons, but now just holds a
1112 inline Module
*unwrap(LLVMModuleProviderRef MP
) {
1113 return reinterpret_cast<Module
*>(MP
);
1116 #undef DEFINE_STDCXX_CONVERSION_FUNCTIONS
1117 #undef DEFINE_ISA_CONVERSION_FUNCTIONS
1118 #undef DEFINE_SIMPLE_CONVERSION_FUNCTIONS
1120 /* Specialized opaque context conversions.
1122 inline LLVMContext
**unwrap(LLVMContextRef
* Tys
) {
1123 return reinterpret_cast<LLVMContext
**>(Tys
);
1126 inline LLVMContextRef
*wrap(const LLVMContext
**Tys
) {
1127 return reinterpret_cast<LLVMContextRef
*>(const_cast<LLVMContext
**>(Tys
));
1130 /* Specialized opaque type conversions.
1132 inline Type
**unwrap(LLVMTypeRef
* Tys
) {
1133 return reinterpret_cast<Type
**>(Tys
);
1136 inline LLVMTypeRef
*wrap(const Type
**Tys
) {
1137 return reinterpret_cast<LLVMTypeRef
*>(const_cast<Type
**>(Tys
));
1140 /* Specialized opaque value conversions.
1142 inline Value
**unwrap(LLVMValueRef
*Vals
) {
1143 return reinterpret_cast<Value
**>(Vals
);
1146 template<typename T
>
1147 inline T
**unwrap(LLVMValueRef
*Vals
, unsigned Length
) {
1149 for (LLVMValueRef
*I
= Vals
, *E
= Vals
+ Length
; I
!= E
; ++I
)
1152 return reinterpret_cast<T
**>(Vals
);
1155 inline LLVMValueRef
*wrap(const Value
**Vals
) {
1156 return reinterpret_cast<LLVMValueRef
*>(const_cast<Value
**>(Vals
));
1160 #endif /* !defined(__cplusplus) */
1162 #endif /* !defined(LLVM_C_CORE_H) */