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 \*===----------------------------------------------------------------------===*/
18 #include "llvm/Support/DataTypes.h"
20 #if defined(__cplusplus) && !defined(LLVM_DO_NOT_INCLUDE_CPP_HEADERS)
21 /* Need these includes to support the LLVM 'cast' template for the C++ 'wrap'
22 and 'unwrap' conversion functions. */
23 #include "llvm/IR/IRBuilder.h"
24 #include "llvm/IR/Module.h"
25 #include "llvm/PassRegistry.h"
26 #endif /* defined(__cplusplus) && !defined(LLVM_DO_NOT_INCLUDE_CPP_HEADERS) */
33 * @defgroup LLVMC LLVM-C: C interface to LLVM
35 * This module exposes parts of the LLVM library as a C API.
41 * @defgroup LLVMCTransforms Transforms
45 * @defgroup LLVMCCore Core
47 * This modules provide an interface to libLLVMCore, which implements
48 * the LLVM intermediate representation as well as other related types
51 * LLVM uses a polymorphic type hierarchy which C cannot represent, therefore
52 * parameters must be passed as base types. Despite the declared types, most
53 * of the functions provided operate only on branches of the type hierarchy.
54 * The declared parameter names are descriptive and specify which type is
55 * required. Additionally, each type hierarchy is documented along with the
56 * functions that operate upon it. For more detail, refer to LLVM's C++ code.
57 * If in doubt, refer to Core.cpp, which performs parameter downcasts in the
58 * form unwrap<RequiredType>(Param).
60 * Many exotic languages can interoperate with C code but have a harder time
61 * with C++ due to name mangling. So in addition to C, this interface enables
62 * tools written in such languages.
64 * When included into a C++ source file, also declares 'wrap' and 'unwrap'
65 * helpers to perform opaque reference<-->pointer conversions. These helpers
66 * are shorter and more tightly typed than writing the casts by hand when
67 * authoring bindings. In assert builds, they will do runtime type checking.
73 * @defgroup LLVMCCoreTypes Types and Enumerations
83 * The top-level container for all LLVM global data. See the LLVMContext class.
85 typedef struct LLVMOpaqueContext *LLVMContextRef;
88 * The top-level container for all other LLVM Intermediate Representation (IR)
93 typedef struct LLVMOpaqueModule *LLVMModuleRef;
96 * Each value in the LLVM IR has a type, an LLVMTypeRef.
100 typedef struct LLVMOpaqueType *LLVMTypeRef;
103 * Represents an individual value in LLVM IR.
105 * This models llvm::Value.
107 typedef struct LLVMOpaqueValue *LLVMValueRef;
110 * Represents a basic block of instructions in LLVM IR.
112 * This models llvm::BasicBlock.
114 typedef struct LLVMOpaqueBasicBlock *LLVMBasicBlockRef;
117 * Represents an LLVM basic block builder.
119 * This models llvm::IRBuilder.
121 typedef struct LLVMOpaqueBuilder *LLVMBuilderRef;
124 * Interface used to provide a module to JIT or interpreter.
125 * This is now just a synonym for llvm::Module, but we have to keep using the
126 * different type to keep binary compatibility.
128 typedef struct LLVMOpaqueModuleProvider *LLVMModuleProviderRef;
131 * Used to provide a module to JIT or interpreter.
133 * @see llvm::MemoryBuffer
135 typedef struct LLVMOpaqueMemoryBuffer *LLVMMemoryBufferRef;
137 /** @see llvm::PassManagerBase */
138 typedef struct LLVMOpaquePassManager *LLVMPassManagerRef;
140 /** @see llvm::PassRegistry */
141 typedef struct LLVMOpaquePassRegistry *LLVMPassRegistryRef;
144 * Used to get the users and usees of a Value.
147 typedef struct LLVMOpaqueUse *LLVMUseRef;
150 LLVMZExtAttribute = 1<<0,
151 LLVMSExtAttribute = 1<<1,
152 LLVMNoReturnAttribute = 1<<2,
153 LLVMInRegAttribute = 1<<3,
154 LLVMStructRetAttribute = 1<<4,
155 LLVMNoUnwindAttribute = 1<<5,
156 LLVMNoAliasAttribute = 1<<6,
157 LLVMByValAttribute = 1<<7,
158 LLVMNestAttribute = 1<<8,
159 LLVMReadNoneAttribute = 1<<9,
160 LLVMReadOnlyAttribute = 1<<10,
161 LLVMNoInlineAttribute = 1<<11,
162 LLVMAlwaysInlineAttribute = 1<<12,
163 LLVMOptimizeForSizeAttribute = 1<<13,
164 LLVMStackProtectAttribute = 1<<14,
165 LLVMStackProtectReqAttribute = 1<<15,
166 LLVMAlignment = 31<<16,
167 LLVMNoCaptureAttribute = 1<<21,
168 LLVMNoRedZoneAttribute = 1<<22,
169 LLVMNoImplicitFloatAttribute = 1<<23,
170 LLVMNakedAttribute = 1<<24,
171 LLVMInlineHintAttribute = 1<<25,
172 LLVMStackAlignment = 7<<26,
173 LLVMReturnsTwice = 1 << 29,
174 LLVMUWTable = 1 << 30,
175 LLVMNonLazyBind = 1 << 31
177 /* FIXME: These attributes are currently not included in the C API as
178 a temporary measure until the API/ABI impact to the C API is understood
179 and the path forward agreed upon.
180 LLVMAddressSafety = 1ULL << 32,
181 LLVMStackProtectStrongAttribute = 1ULL<<33
186 /* Terminator Instructions */
192 /* removed 6 due to API changes */
195 /* Standard Binary Operators */
209 /* Logical Operators */
217 /* Memory Operators */
221 LLVMGetElementPtr = 29,
237 /* Other Operators */
246 LLVMExtractElement = 50,
247 LLVMInsertElement = 51,
248 LLVMShuffleVector = 52,
249 LLVMExtractValue = 53,
250 LLVMInsertValue = 54,
252 /* Atomic operators */
254 LLVMAtomicCmpXchg = 56,
257 /* Exception Handling Operators */
264 LLVMVoidTypeKind, /**< type with no size */
265 LLVMHalfTypeKind, /**< 16 bit floating point type */
266 LLVMFloatTypeKind, /**< 32 bit floating point type */
267 LLVMDoubleTypeKind, /**< 64 bit floating point type */
268 LLVMX86_FP80TypeKind, /**< 80 bit floating point type (X87) */
269 LLVMFP128TypeKind, /**< 128 bit floating point type (112-bit mantissa)*/
270 LLVMPPC_FP128TypeKind, /**< 128 bit floating point type (two 64-bits) */
271 LLVMLabelTypeKind, /**< Labels */
272 LLVMIntegerTypeKind, /**< Arbitrary bit width integers */
273 LLVMFunctionTypeKind, /**< Functions */
274 LLVMStructTypeKind, /**< Structures */
275 LLVMArrayTypeKind, /**< Arrays */
276 LLVMPointerTypeKind, /**< Pointers */
277 LLVMVectorTypeKind, /**< SIMD 'packed' format, or other vector type */
278 LLVMMetadataTypeKind, /**< Metadata */
279 LLVMX86_MMXTypeKind /**< X86 MMX */
283 LLVMExternalLinkage, /**< Externally visible function */
284 LLVMAvailableExternallyLinkage,
285 LLVMLinkOnceAnyLinkage, /**< Keep one copy of function when linking (inline)*/
286 LLVMLinkOnceODRLinkage, /**< Same, but only replaced by something
288 LLVMLinkOnceODRAutoHideLinkage, /**< Like LinkOnceODR, but possibly hidden. */
289 LLVMWeakAnyLinkage, /**< Keep one copy of function when linking (weak) */
290 LLVMWeakODRLinkage, /**< Same, but only replaced by something
292 LLVMAppendingLinkage, /**< Special purpose, only applies to global arrays */
293 LLVMInternalLinkage, /**< Rename collisions when linking (static
295 LLVMPrivateLinkage, /**< Like Internal, but omit from symbol table */
296 LLVMDLLImportLinkage, /**< Function to be imported from DLL */
297 LLVMDLLExportLinkage, /**< Function to be accessible from DLL */
298 LLVMExternalWeakLinkage,/**< ExternalWeak linkage description */
299 LLVMGhostLinkage, /**< Obsolete */
300 LLVMCommonLinkage, /**< Tentative definitions */
301 LLVMLinkerPrivateLinkage, /**< Like Private, but linker removes. */
302 LLVMLinkerPrivateWeakLinkage /**< Like LinkerPrivate, but is weak. */
306 LLVMDefaultVisibility, /**< The GV is visible */
307 LLVMHiddenVisibility, /**< The GV is hidden */
308 LLVMProtectedVisibility /**< The GV is protected */
313 LLVMFastCallConv = 8,
314 LLVMColdCallConv = 9,
315 LLVMX86StdcallCallConv = 64,
316 LLVMX86FastcallCallConv = 65
320 LLVMIntEQ = 32, /**< equal */
321 LLVMIntNE, /**< not equal */
322 LLVMIntUGT, /**< unsigned greater than */
323 LLVMIntUGE, /**< unsigned greater or equal */
324 LLVMIntULT, /**< unsigned less than */
325 LLVMIntULE, /**< unsigned less or equal */
326 LLVMIntSGT, /**< signed greater than */
327 LLVMIntSGE, /**< signed greater or equal */
328 LLVMIntSLT, /**< signed less than */
329 LLVMIntSLE /**< signed less or equal */
333 LLVMRealPredicateFalse, /**< Always false (always folded) */
334 LLVMRealOEQ, /**< True if ordered and equal */
335 LLVMRealOGT, /**< True if ordered and greater than */
336 LLVMRealOGE, /**< True if ordered and greater than or equal */
337 LLVMRealOLT, /**< True if ordered and less than */
338 LLVMRealOLE, /**< True if ordered and less than or equal */
339 LLVMRealONE, /**< True if ordered and operands are unequal */
340 LLVMRealORD, /**< True if ordered (no nans) */
341 LLVMRealUNO, /**< True if unordered: isnan(X) | isnan(Y) */
342 LLVMRealUEQ, /**< True if unordered or equal */
343 LLVMRealUGT, /**< True if unordered or greater than */
344 LLVMRealUGE, /**< True if unordered, greater than, or equal */
345 LLVMRealULT, /**< True if unordered or less than */
346 LLVMRealULE, /**< True if unordered, less than, or equal */
347 LLVMRealUNE, /**< True if unordered or not equal */
348 LLVMRealPredicateTrue /**< Always true (always folded) */
352 LLVMLandingPadCatch, /**< A catch clause */
353 LLVMLandingPadFilter /**< A filter clause */
354 } LLVMLandingPadClauseTy;
360 void LLVMInitializeCore(LLVMPassRegistryRef R);
362 /** Deallocate and destroy all ManagedStatic variables.
363 @see llvm::llvm_shutdown
364 @see ManagedStatic */
368 /*===-- Error handling ----------------------------------------------------===*/
370 void LLVMDisposeMessage(char *Message);
374 * @defgroup LLVMCCoreContext Contexts
376 * Contexts are execution states for the core LLVM IR system.
378 * Most types are tied to a context instance. Multiple contexts can
379 * exist simultaneously. A single context is not thread safe. However,
380 * different contexts can execute on different threads simultaneously.
386 * Create a new context.
388 * Every call to this function should be paired with a call to
389 * LLVMContextDispose() or the context will leak memory.
391 LLVMContextRef LLVMContextCreate(void);
394 * Obtain the global context instance.
396 LLVMContextRef LLVMGetGlobalContext(void);
399 * Destroy a context instance.
401 * This should be called for every call to LLVMContextCreate() or memory
404 void LLVMContextDispose(LLVMContextRef C);
406 unsigned LLVMGetMDKindIDInContext(LLVMContextRef C, const char* Name,
408 unsigned LLVMGetMDKindID(const char* Name, unsigned SLen);
415 * @defgroup LLVMCCoreModule Modules
417 * Modules represent the top-level structure in a LLVM program. An LLVM
418 * module is effectively a translation unit or a collection of
419 * translation units merged together.
425 * Create a new, empty module in the global context.
427 * This is equivalent to calling LLVMModuleCreateWithNameInContext with
428 * LLVMGetGlobalContext() as the context parameter.
430 * Every invocation should be paired with LLVMDisposeModule() or memory
433 LLVMModuleRef LLVMModuleCreateWithName(const char *ModuleID);
436 * Create a new, empty module in a specific context.
438 * Every invocation should be paired with LLVMDisposeModule() or memory
441 LLVMModuleRef LLVMModuleCreateWithNameInContext(const char *ModuleID,
445 * Destroy a module instance.
447 * This must be called for every created module or memory will be
450 void LLVMDisposeModule(LLVMModuleRef M);
453 * Obtain the data layout for a module.
455 * @see Module::getDataLayout()
457 const char *LLVMGetDataLayout(LLVMModuleRef M);
460 * Set the data layout for a module.
462 * @see Module::setDataLayout()
464 void LLVMSetDataLayout(LLVMModuleRef M, const char *Triple);
467 * Obtain the target triple for a module.
469 * @see Module::getTargetTriple()
471 const char *LLVMGetTarget(LLVMModuleRef M);
474 * Set the target triple for a module.
476 * @see Module::setTargetTriple()
478 void LLVMSetTarget(LLVMModuleRef M, const char *Triple);
481 * Dump a representation of a module to stderr.
483 * @see Module::dump()
485 void LLVMDumpModule(LLVMModuleRef M);
488 * Print a representation of a module to a file. The ErrorMessage needs to be
489 * disposed with LLVMDisposeMessage. Returns 0 on success, 1 otherwise.
491 * @see Module::print()
493 LLVMBool LLVMPrintModuleToFile(LLVMModuleRef M, const char *Filename,
494 char **ErrorMessage);
497 * Set inline assembly for a module.
499 * @see Module::setModuleInlineAsm()
501 void LLVMSetModuleInlineAsm(LLVMModuleRef M, const char *Asm);
504 * Obtain the context to which this module is associated.
506 * @see Module::getContext()
508 LLVMContextRef LLVMGetModuleContext(LLVMModuleRef M);
511 * Obtain a Type from a module by its registered name.
513 LLVMTypeRef LLVMGetTypeByName(LLVMModuleRef M, const char *Name);
516 * Obtain the number of operands for named metadata in a module.
518 * @see llvm::Module::getNamedMetadata()
520 unsigned LLVMGetNamedMetadataNumOperands(LLVMModuleRef M, const char* name);
523 * Obtain the named metadata operands for a module.
525 * The passed LLVMValueRef pointer should refer to an array of
526 * LLVMValueRef at least LLVMGetNamedMetadataNumOperands long. This
527 * array will be populated with the LLVMValueRef instances. Each
528 * instance corresponds to a llvm::MDNode.
530 * @see llvm::Module::getNamedMetadata()
531 * @see llvm::MDNode::getOperand()
533 void LLVMGetNamedMetadataOperands(LLVMModuleRef M, const char* name, LLVMValueRef *Dest);
536 * Add an operand to named metadata.
538 * @see llvm::Module::getNamedMetadata()
539 * @see llvm::MDNode::addOperand()
541 void LLVMAddNamedMetadataOperand(LLVMModuleRef M, const char* name,
545 * Add a function to a module under a specified name.
547 * @see llvm::Function::Create()
549 LLVMValueRef LLVMAddFunction(LLVMModuleRef M, const char *Name,
550 LLVMTypeRef FunctionTy);
553 * Obtain a Function value from a Module by its name.
555 * The returned value corresponds to a llvm::Function value.
557 * @see llvm::Module::getFunction()
559 LLVMValueRef LLVMGetNamedFunction(LLVMModuleRef M, const char *Name);
562 * Obtain an iterator to the first Function in a Module.
564 * @see llvm::Module::begin()
566 LLVMValueRef LLVMGetFirstFunction(LLVMModuleRef M);
569 * Obtain an iterator to the last Function in a Module.
571 * @see llvm::Module::end()
573 LLVMValueRef LLVMGetLastFunction(LLVMModuleRef M);
576 * Advance a Function iterator to the next Function.
578 * Returns NULL if the iterator was already at the end and there are no more
581 LLVMValueRef LLVMGetNextFunction(LLVMValueRef Fn);
584 * Decrement a Function iterator to the previous Function.
586 * Returns NULL if the iterator was already at the beginning and there are
587 * no previous functions.
589 LLVMValueRef LLVMGetPreviousFunction(LLVMValueRef Fn);
596 * @defgroup LLVMCCoreType Types
598 * Types represent the type of a value.
600 * Types are associated with a context instance. The context internally
601 * deduplicates types so there is only 1 instance of a specific type
602 * alive at a time. In other words, a unique type is shared among all
603 * consumers within a context.
605 * A Type in the C API corresponds to llvm::Type.
607 * Types have the following hierarchy:
625 * Obtain the enumerated type of a Type instance.
627 * @see llvm::Type:getTypeID()
629 LLVMTypeKind LLVMGetTypeKind(LLVMTypeRef Ty);
632 * Whether the type has a known size.
634 * Things that don't have a size are abstract types, labels, and void.a
636 * @see llvm::Type::isSized()
638 LLVMBool LLVMTypeIsSized(LLVMTypeRef Ty);
641 * Obtain the context to which this type instance is associated.
643 * @see llvm::Type::getContext()
645 LLVMContextRef LLVMGetTypeContext(LLVMTypeRef Ty);
648 * @defgroup LLVMCCoreTypeInt Integer Types
650 * Functions in this section operate on integer types.
656 * Obtain an integer type from a context with specified bit width.
658 LLVMTypeRef LLVMInt1TypeInContext(LLVMContextRef C);
659 LLVMTypeRef LLVMInt8TypeInContext(LLVMContextRef C);
660 LLVMTypeRef LLVMInt16TypeInContext(LLVMContextRef C);
661 LLVMTypeRef LLVMInt32TypeInContext(LLVMContextRef C);
662 LLVMTypeRef LLVMInt64TypeInContext(LLVMContextRef C);
663 LLVMTypeRef LLVMIntTypeInContext(LLVMContextRef C, unsigned NumBits);
666 * Obtain an integer type from the global context with a specified bit
669 LLVMTypeRef LLVMInt1Type(void);
670 LLVMTypeRef LLVMInt8Type(void);
671 LLVMTypeRef LLVMInt16Type(void);
672 LLVMTypeRef LLVMInt32Type(void);
673 LLVMTypeRef LLVMInt64Type(void);
674 LLVMTypeRef LLVMIntType(unsigned NumBits);
675 unsigned LLVMGetIntTypeWidth(LLVMTypeRef IntegerTy);
682 * @defgroup LLVMCCoreTypeFloat Floating Point Types
688 * Obtain a 16-bit floating point type from a context.
690 LLVMTypeRef LLVMHalfTypeInContext(LLVMContextRef C);
693 * Obtain a 32-bit floating point type from a context.
695 LLVMTypeRef LLVMFloatTypeInContext(LLVMContextRef C);
698 * Obtain a 64-bit floating point type from a context.
700 LLVMTypeRef LLVMDoubleTypeInContext(LLVMContextRef C);
703 * Obtain a 80-bit floating point type (X87) from a context.
705 LLVMTypeRef LLVMX86FP80TypeInContext(LLVMContextRef C);
708 * Obtain a 128-bit floating point type (112-bit mantissa) from a
711 LLVMTypeRef LLVMFP128TypeInContext(LLVMContextRef C);
714 * Obtain a 128-bit floating point type (two 64-bits) from a context.
716 LLVMTypeRef LLVMPPCFP128TypeInContext(LLVMContextRef C);
719 * Obtain a floating point type from the global context.
721 * These map to the functions in this group of the same name.
723 LLVMTypeRef LLVMHalfType(void);
724 LLVMTypeRef LLVMFloatType(void);
725 LLVMTypeRef LLVMDoubleType(void);
726 LLVMTypeRef LLVMX86FP80Type(void);
727 LLVMTypeRef LLVMFP128Type(void);
728 LLVMTypeRef LLVMPPCFP128Type(void);
735 * @defgroup LLVMCCoreTypeFunction Function Types
741 * Obtain a function type consisting of a specified signature.
743 * The function is defined as a tuple of a return Type, a list of
744 * parameter types, and whether the function is variadic.
746 LLVMTypeRef LLVMFunctionType(LLVMTypeRef ReturnType,
747 LLVMTypeRef *ParamTypes, unsigned ParamCount,
751 * Returns whether a function type is variadic.
753 LLVMBool LLVMIsFunctionVarArg(LLVMTypeRef FunctionTy);
756 * Obtain the Type this function Type returns.
758 LLVMTypeRef LLVMGetReturnType(LLVMTypeRef FunctionTy);
761 * Obtain the number of parameters this function accepts.
763 unsigned LLVMCountParamTypes(LLVMTypeRef FunctionTy);
766 * Obtain the types of a function's parameters.
768 * The Dest parameter should point to a pre-allocated array of
769 * LLVMTypeRef at least LLVMCountParamTypes() large. On return, the
770 * first LLVMCountParamTypes() entries in the array will be populated
771 * with LLVMTypeRef instances.
773 * @param FunctionTy The function type to operate on.
774 * @param Dest Memory address of an array to be filled with result.
776 void LLVMGetParamTypes(LLVMTypeRef FunctionTy, LLVMTypeRef *Dest);
783 * @defgroup LLVMCCoreTypeStruct Structure Types
785 * These functions relate to LLVMTypeRef instances.
787 * @see llvm::StructType
793 * Create a new structure type in a context.
795 * A structure is specified by a list of inner elements/types and
796 * whether these can be packed together.
798 * @see llvm::StructType::create()
800 LLVMTypeRef LLVMStructTypeInContext(LLVMContextRef C, LLVMTypeRef *ElementTypes,
801 unsigned ElementCount, LLVMBool Packed);
804 * Create a new structure type in the global context.
806 * @see llvm::StructType::create()
808 LLVMTypeRef LLVMStructType(LLVMTypeRef *ElementTypes, unsigned ElementCount,
812 * Create an empty structure in a context having a specified name.
814 * @see llvm::StructType::create()
816 LLVMTypeRef LLVMStructCreateNamed(LLVMContextRef C, const char *Name);
819 * Obtain the name of a structure.
821 * @see llvm::StructType::getName()
823 const char *LLVMGetStructName(LLVMTypeRef Ty);
826 * Set the contents of a structure type.
828 * @see llvm::StructType::setBody()
830 void LLVMStructSetBody(LLVMTypeRef StructTy, LLVMTypeRef *ElementTypes,
831 unsigned ElementCount, LLVMBool Packed);
834 * Get the number of elements defined inside the structure.
836 * @see llvm::StructType::getNumElements()
838 unsigned LLVMCountStructElementTypes(LLVMTypeRef StructTy);
841 * Get the elements within a structure.
843 * The function is passed the address of a pre-allocated array of
844 * LLVMTypeRef at least LLVMCountStructElementTypes() long. After
845 * invocation, this array will be populated with the structure's
846 * elements. The objects in the destination array will have a lifetime
847 * of the structure type itself, which is the lifetime of the context it
850 void LLVMGetStructElementTypes(LLVMTypeRef StructTy, LLVMTypeRef *Dest);
853 * Determine whether a structure is packed.
855 * @see llvm::StructType::isPacked()
857 LLVMBool LLVMIsPackedStruct(LLVMTypeRef StructTy);
860 * Determine whether a structure is opaque.
862 * @see llvm::StructType::isOpaque()
864 LLVMBool LLVMIsOpaqueStruct(LLVMTypeRef StructTy);
872 * @defgroup LLVMCCoreTypeSequential Sequential Types
874 * Sequential types represents "arrays" of types. This is a super class
875 * for array, vector, and pointer types.
881 * Obtain the type of elements within a sequential type.
883 * This works on array, vector, and pointer types.
885 * @see llvm::SequentialType::getElementType()
887 LLVMTypeRef LLVMGetElementType(LLVMTypeRef Ty);
890 * Create a fixed size array type that refers to a specific type.
892 * The created type will exist in the context that its element type
895 * @see llvm::ArrayType::get()
897 LLVMTypeRef LLVMArrayType(LLVMTypeRef ElementType, unsigned ElementCount);
900 * Obtain the length of an array type.
902 * This only works on types that represent arrays.
904 * @see llvm::ArrayType::getNumElements()
906 unsigned LLVMGetArrayLength(LLVMTypeRef ArrayTy);
909 * Create a pointer type that points to a defined type.
911 * The created type will exist in the context that its pointee type
914 * @see llvm::PointerType::get()
916 LLVMTypeRef LLVMPointerType(LLVMTypeRef ElementType, unsigned AddressSpace);
919 * Obtain the address space of a pointer type.
921 * This only works on types that represent pointers.
923 * @see llvm::PointerType::getAddressSpace()
925 unsigned LLVMGetPointerAddressSpace(LLVMTypeRef PointerTy);
928 * Create a vector type that contains a defined type and has a specific
929 * number of elements.
931 * The created type will exist in the context thats its element type
934 * @see llvm::VectorType::get()
936 LLVMTypeRef LLVMVectorType(LLVMTypeRef ElementType, unsigned ElementCount);
939 * Obtain the number of elements in a vector type.
941 * This only works on types that represent vectors.
943 * @see llvm::VectorType::getNumElements()
945 unsigned LLVMGetVectorSize(LLVMTypeRef VectorTy);
952 * @defgroup LLVMCCoreTypeOther Other Types
958 * Create a void type in a context.
960 LLVMTypeRef LLVMVoidTypeInContext(LLVMContextRef C);
963 * Create a label type in a context.
965 LLVMTypeRef LLVMLabelTypeInContext(LLVMContextRef C);
968 * Create a X86 MMX type in a context.
970 LLVMTypeRef LLVMX86MMXTypeInContext(LLVMContextRef C);
973 * These are similar to the above functions except they operate on the
976 LLVMTypeRef LLVMVoidType(void);
977 LLVMTypeRef LLVMLabelType(void);
978 LLVMTypeRef LLVMX86MMXType(void);
989 * @defgroup LLVMCCoreValues Values
991 * The bulk of LLVM's object model consists of values, which comprise a very
992 * rich type hierarchy.
994 * LLVMValueRef essentially represents llvm::Value. There is a rich
995 * hierarchy of classes within this type. Depending on the instance
996 * obtained, not all APIs are available.
998 * Callers can determine the type of a LLVMValueRef by calling the
999 * LLVMIsA* family of functions (e.g. LLVMIsAArgument()). These
1000 * functions are defined by a macro, so it isn't obvious which are
1001 * available by looking at the Doxygen source code. Instead, look at the
1002 * source definition of LLVM_FOR_EACH_VALUE_SUBCLASS and note the list
1003 * of value names given. These value names also correspond to classes in
1004 * the llvm::Value hierarchy.
1009 #define LLVM_FOR_EACH_VALUE_SUBCLASS(macro) \
1017 macro(BlockAddress) \
1018 macro(ConstantAggregateZero) \
1019 macro(ConstantArray) \
1020 macro(ConstantExpr) \
1022 macro(ConstantInt) \
1023 macro(ConstantPointerNull) \
1024 macro(ConstantStruct) \
1025 macro(ConstantVector) \
1026 macro(GlobalValue) \
1028 macro(GlobalAlias) \
1029 macro(GlobalVariable) \
1031 macro(Instruction) \
1032 macro(BinaryOperator) \
1034 macro(IntrinsicInst) \
1035 macro(DbgInfoIntrinsic) \
1036 macro(DbgDeclareInst) \
1037 macro(MemIntrinsic) \
1039 macro(MemMoveInst) \
1044 macro(ExtractElementInst) \
1045 macro(GetElementPtrInst) \
1046 macro(InsertElementInst) \
1047 macro(InsertValueInst) \
1048 macro(LandingPadInst) \
1051 macro(ShuffleVectorInst) \
1053 macro(TerminatorInst) \
1055 macro(IndirectBrInst) \
1059 macro(UnreachableInst) \
1061 macro(UnaryInstruction) \
1064 macro(BitCastInst) \
1068 macro(FPTruncInst) \
1069 macro(IntToPtrInst) \
1070 macro(PtrToIntInst) \
1076 macro(ExtractValueInst) \
1081 * @defgroup LLVMCCoreValueGeneral General APIs
1083 * Functions in this section work on all LLVMValueRef instances,
1084 * regardless of their sub-type. They correspond to functions available
1091 * Obtain the type of a value.
1093 * @see llvm::Value::getType()
1095 LLVMTypeRef LLVMTypeOf(LLVMValueRef Val);
1098 * Obtain the string name of a value.
1100 * @see llvm::Value::getName()
1102 const char *LLVMGetValueName(LLVMValueRef Val);
1105 * Set the string name of a value.
1107 * @see llvm::Value::setName()
1109 void LLVMSetValueName(LLVMValueRef Val, const char *Name);
1112 * Dump a representation of a value to stderr.
1114 * @see llvm::Value::dump()
1116 void LLVMDumpValue(LLVMValueRef Val);
1119 * Replace all uses of a value with another one.
1121 * @see llvm::Value::replaceAllUsesWith()
1123 void LLVMReplaceAllUsesWith(LLVMValueRef OldVal, LLVMValueRef NewVal);
1126 * Determine whether the specified constant instance is constant.
1128 LLVMBool LLVMIsConstant(LLVMValueRef Val);
1131 * Determine whether a value instance is undefined.
1133 LLVMBool LLVMIsUndef(LLVMValueRef Val);
1136 * Convert value instances between types.
1138 * Internally, a LLVMValueRef is "pinned" to a specific type. This
1139 * series of functions allows you to cast an instance to a specific
1142 * If the cast is not valid for the specified type, NULL is returned.
1144 * @see llvm::dyn_cast_or_null<>
1146 #define LLVM_DECLARE_VALUE_CAST(name) \
1147 LLVMValueRef LLVMIsA##name(LLVMValueRef Val);
1148 LLVM_FOR_EACH_VALUE_SUBCLASS(LLVM_DECLARE_VALUE_CAST)
1155 * @defgroup LLVMCCoreValueUses Usage
1157 * This module defines functions that allow you to inspect the uses of a
1160 * It is possible to obtain a LLVMUseRef for any LLVMValueRef instance.
1161 * Each LLVMUseRef (which corresponds to a llvm::Use instance) holds a
1162 * llvm::User and llvm::Value.
1168 * Obtain the first use of a value.
1170 * Uses are obtained in an iterator fashion. First, call this function
1171 * to obtain a reference to the first use. Then, call LLVMGetNextUse()
1172 * on that instance and all subsequently obtained instances until
1173 * LLVMGetNextUse() returns NULL.
1175 * @see llvm::Value::use_begin()
1177 LLVMUseRef LLVMGetFirstUse(LLVMValueRef Val);
1180 * Obtain the next use of a value.
1182 * This effectively advances the iterator. It returns NULL if you are on
1183 * the final use and no more are available.
1185 LLVMUseRef LLVMGetNextUse(LLVMUseRef U);
1188 * Obtain the user value for a user.
1190 * The returned value corresponds to a llvm::User type.
1192 * @see llvm::Use::getUser()
1194 LLVMValueRef LLVMGetUser(LLVMUseRef U);
1197 * Obtain the value this use corresponds to.
1199 * @see llvm::Use::get().
1201 LLVMValueRef LLVMGetUsedValue(LLVMUseRef U);
1208 * @defgroup LLVMCCoreValueUser User value
1210 * Function in this group pertain to LLVMValueRef instances that descent
1211 * from llvm::User. This includes constants, instructions, and
1218 * Obtain an operand at a specific index in a llvm::User value.
1220 * @see llvm::User::getOperand()
1222 LLVMValueRef LLVMGetOperand(LLVMValueRef Val, unsigned Index);
1225 * Set an operand at a specific index in a llvm::User value.
1227 * @see llvm::User::setOperand()
1229 void LLVMSetOperand(LLVMValueRef User, unsigned Index, LLVMValueRef Val);
1232 * Obtain the number of operands in a llvm::User value.
1234 * @see llvm::User::getNumOperands()
1236 int LLVMGetNumOperands(LLVMValueRef Val);
1243 * @defgroup LLVMCCoreValueConstant Constants
1245 * This section contains APIs for interacting with LLVMValueRef that
1246 * correspond to llvm::Constant instances.
1248 * These functions will work for any LLVMValueRef in the llvm::Constant
1255 * Obtain a constant value referring to the null instance of a type.
1257 * @see llvm::Constant::getNullValue()
1259 LLVMValueRef LLVMConstNull(LLVMTypeRef Ty); /* all zeroes */
1262 * Obtain a constant value referring to the instance of a type
1263 * consisting of all ones.
1265 * This is only valid for integer types.
1267 * @see llvm::Constant::getAllOnesValue()
1269 LLVMValueRef LLVMConstAllOnes(LLVMTypeRef Ty);
1272 * Obtain a constant value referring to an undefined value of a type.
1274 * @see llvm::UndefValue::get()
1276 LLVMValueRef LLVMGetUndef(LLVMTypeRef Ty);
1279 * Determine whether a value instance is null.
1281 * @see llvm::Constant::isNullValue()
1283 LLVMBool LLVMIsNull(LLVMValueRef Val);
1286 * Obtain a constant that is a constant pointer pointing to NULL for a
1289 LLVMValueRef LLVMConstPointerNull(LLVMTypeRef Ty);
1292 * @defgroup LLVMCCoreValueConstantScalar Scalar constants
1294 * Functions in this group model LLVMValueRef instances that correspond
1295 * to constants referring to scalar types.
1297 * For integer types, the LLVMTypeRef parameter should correspond to a
1298 * llvm::IntegerType instance and the returned LLVMValueRef will
1299 * correspond to a llvm::ConstantInt.
1301 * For floating point types, the LLVMTypeRef returned corresponds to a
1308 * Obtain a constant value for an integer type.
1310 * The returned value corresponds to a llvm::ConstantInt.
1312 * @see llvm::ConstantInt::get()
1314 * @param IntTy Integer type to obtain value of.
1315 * @param N The value the returned instance should refer to.
1316 * @param SignExtend Whether to sign extend the produced value.
1318 LLVMValueRef LLVMConstInt(LLVMTypeRef IntTy, unsigned long long N,
1319 LLVMBool SignExtend);
1322 * Obtain a constant value for an integer of arbitrary precision.
1324 * @see llvm::ConstantInt::get()
1326 LLVMValueRef LLVMConstIntOfArbitraryPrecision(LLVMTypeRef IntTy,
1328 const uint64_t Words[]);
1331 * Obtain a constant value for an integer parsed from a string.
1333 * A similar API, LLVMConstIntOfStringAndSize is also available. If the
1334 * string's length is available, it is preferred to call that function
1337 * @see llvm::ConstantInt::get()
1339 LLVMValueRef LLVMConstIntOfString(LLVMTypeRef IntTy, const char *Text,
1343 * Obtain a constant value for an integer parsed from a string with
1346 * @see llvm::ConstantInt::get()
1348 LLVMValueRef LLVMConstIntOfStringAndSize(LLVMTypeRef IntTy, const char *Text,
1349 unsigned SLen, uint8_t Radix);
1352 * Obtain a constant value referring to a double floating point value.
1354 LLVMValueRef LLVMConstReal(LLVMTypeRef RealTy, double N);
1357 * Obtain a constant for a floating point value parsed from a string.
1359 * A similar API, LLVMConstRealOfStringAndSize is also available. It
1360 * should be used if the input string's length is known.
1362 LLVMValueRef LLVMConstRealOfString(LLVMTypeRef RealTy, const char *Text);
1365 * Obtain a constant for a floating point value parsed from a string.
1367 LLVMValueRef LLVMConstRealOfStringAndSize(LLVMTypeRef RealTy, const char *Text,
1371 * Obtain the zero extended value for an integer constant value.
1373 * @see llvm::ConstantInt::getZExtValue()
1375 unsigned long long LLVMConstIntGetZExtValue(LLVMValueRef ConstantVal);
1378 * Obtain the sign extended value for an integer constant value.
1380 * @see llvm::ConstantInt::getSExtValue()
1382 long long LLVMConstIntGetSExtValue(LLVMValueRef ConstantVal);
1389 * @defgroup LLVMCCoreValueConstantComposite Composite Constants
1391 * Functions in this group operate on composite constants.
1397 * Create a ConstantDataSequential and initialize it with a string.
1399 * @see llvm::ConstantDataArray::getString()
1401 LLVMValueRef LLVMConstStringInContext(LLVMContextRef C, const char *Str,
1402 unsigned Length, LLVMBool DontNullTerminate);
1405 * Create a ConstantDataSequential with string content in the global context.
1407 * This is the same as LLVMConstStringInContext except it operates on the
1410 * @see LLVMConstStringInContext()
1411 * @see llvm::ConstantDataArray::getString()
1413 LLVMValueRef LLVMConstString(const char *Str, unsigned Length,
1414 LLVMBool DontNullTerminate);
1417 * Create an anonymous ConstantStruct with the specified values.
1419 * @see llvm::ConstantStruct::getAnon()
1421 LLVMValueRef LLVMConstStructInContext(LLVMContextRef C,
1422 LLVMValueRef *ConstantVals,
1423 unsigned Count, LLVMBool Packed);
1426 * Create a ConstantStruct in the global Context.
1428 * This is the same as LLVMConstStructInContext except it operates on the
1431 * @see LLVMConstStructInContext()
1433 LLVMValueRef LLVMConstStruct(LLVMValueRef *ConstantVals, unsigned Count,
1437 * Create a ConstantArray from values.
1439 * @see llvm::ConstantArray::get()
1441 LLVMValueRef LLVMConstArray(LLVMTypeRef ElementTy,
1442 LLVMValueRef *ConstantVals, unsigned Length);
1445 * Create a non-anonymous ConstantStruct from values.
1447 * @see llvm::ConstantStruct::get()
1449 LLVMValueRef LLVMConstNamedStruct(LLVMTypeRef StructTy,
1450 LLVMValueRef *ConstantVals,
1454 * Create a ConstantVector from values.
1456 * @see llvm::ConstantVector::get()
1458 LLVMValueRef LLVMConstVector(LLVMValueRef *ScalarConstantVals, unsigned Size);
1465 * @defgroup LLVMCCoreValueConstantExpressions Constant Expressions
1467 * Functions in this group correspond to APIs on llvm::ConstantExpr.
1469 * @see llvm::ConstantExpr.
1473 LLVMOpcode LLVMGetConstOpcode(LLVMValueRef ConstantVal);
1474 LLVMValueRef LLVMAlignOf(LLVMTypeRef Ty);
1475 LLVMValueRef LLVMSizeOf(LLVMTypeRef Ty);
1476 LLVMValueRef LLVMConstNeg(LLVMValueRef ConstantVal);
1477 LLVMValueRef LLVMConstNSWNeg(LLVMValueRef ConstantVal);
1478 LLVMValueRef LLVMConstNUWNeg(LLVMValueRef ConstantVal);
1479 LLVMValueRef LLVMConstFNeg(LLVMValueRef ConstantVal);
1480 LLVMValueRef LLVMConstNot(LLVMValueRef ConstantVal);
1481 LLVMValueRef LLVMConstAdd(LLVMValueRef LHSConstant, LLVMValueRef RHSConstant);
1482 LLVMValueRef LLVMConstNSWAdd(LLVMValueRef LHSConstant, LLVMValueRef RHSConstant);
1483 LLVMValueRef LLVMConstNUWAdd(LLVMValueRef LHSConstant, LLVMValueRef RHSConstant);
1484 LLVMValueRef LLVMConstFAdd(LLVMValueRef LHSConstant, LLVMValueRef RHSConstant);
1485 LLVMValueRef LLVMConstSub(LLVMValueRef LHSConstant, LLVMValueRef RHSConstant);
1486 LLVMValueRef LLVMConstNSWSub(LLVMValueRef LHSConstant, LLVMValueRef RHSConstant);
1487 LLVMValueRef LLVMConstNUWSub(LLVMValueRef LHSConstant, LLVMValueRef RHSConstant);
1488 LLVMValueRef LLVMConstFSub(LLVMValueRef LHSConstant, LLVMValueRef RHSConstant);
1489 LLVMValueRef LLVMConstMul(LLVMValueRef LHSConstant, LLVMValueRef RHSConstant);
1490 LLVMValueRef LLVMConstNSWMul(LLVMValueRef LHSConstant, LLVMValueRef RHSConstant);
1491 LLVMValueRef LLVMConstNUWMul(LLVMValueRef LHSConstant, LLVMValueRef RHSConstant);
1492 LLVMValueRef LLVMConstFMul(LLVMValueRef LHSConstant, LLVMValueRef RHSConstant);
1493 LLVMValueRef LLVMConstUDiv(LLVMValueRef LHSConstant, LLVMValueRef RHSConstant);
1494 LLVMValueRef LLVMConstSDiv(LLVMValueRef LHSConstant, LLVMValueRef RHSConstant);
1495 LLVMValueRef LLVMConstExactSDiv(LLVMValueRef LHSConstant, LLVMValueRef RHSConstant);
1496 LLVMValueRef LLVMConstFDiv(LLVMValueRef LHSConstant, LLVMValueRef RHSConstant);
1497 LLVMValueRef LLVMConstURem(LLVMValueRef LHSConstant, LLVMValueRef RHSConstant);
1498 LLVMValueRef LLVMConstSRem(LLVMValueRef LHSConstant, LLVMValueRef RHSConstant);
1499 LLVMValueRef LLVMConstFRem(LLVMValueRef LHSConstant, LLVMValueRef RHSConstant);
1500 LLVMValueRef LLVMConstAnd(LLVMValueRef LHSConstant, LLVMValueRef RHSConstant);
1501 LLVMValueRef LLVMConstOr(LLVMValueRef LHSConstant, LLVMValueRef RHSConstant);
1502 LLVMValueRef LLVMConstXor(LLVMValueRef LHSConstant, LLVMValueRef RHSConstant);
1503 LLVMValueRef LLVMConstICmp(LLVMIntPredicate Predicate,
1504 LLVMValueRef LHSConstant, LLVMValueRef RHSConstant);
1505 LLVMValueRef LLVMConstFCmp(LLVMRealPredicate Predicate,
1506 LLVMValueRef LHSConstant, LLVMValueRef RHSConstant);
1507 LLVMValueRef LLVMConstShl(LLVMValueRef LHSConstant, LLVMValueRef RHSConstant);
1508 LLVMValueRef LLVMConstLShr(LLVMValueRef LHSConstant, LLVMValueRef RHSConstant);
1509 LLVMValueRef LLVMConstAShr(LLVMValueRef LHSConstant, LLVMValueRef RHSConstant);
1510 LLVMValueRef LLVMConstGEP(LLVMValueRef ConstantVal,
1511 LLVMValueRef *ConstantIndices, unsigned NumIndices);
1512 LLVMValueRef LLVMConstInBoundsGEP(LLVMValueRef ConstantVal,
1513 LLVMValueRef *ConstantIndices,
1514 unsigned NumIndices);
1515 LLVMValueRef LLVMConstTrunc(LLVMValueRef ConstantVal, LLVMTypeRef ToType);
1516 LLVMValueRef LLVMConstSExt(LLVMValueRef ConstantVal, LLVMTypeRef ToType);
1517 LLVMValueRef LLVMConstZExt(LLVMValueRef ConstantVal, LLVMTypeRef ToType);
1518 LLVMValueRef LLVMConstFPTrunc(LLVMValueRef ConstantVal, LLVMTypeRef ToType);
1519 LLVMValueRef LLVMConstFPExt(LLVMValueRef ConstantVal, LLVMTypeRef ToType);
1520 LLVMValueRef LLVMConstUIToFP(LLVMValueRef ConstantVal, LLVMTypeRef ToType);
1521 LLVMValueRef LLVMConstSIToFP(LLVMValueRef ConstantVal, LLVMTypeRef ToType);
1522 LLVMValueRef LLVMConstFPToUI(LLVMValueRef ConstantVal, LLVMTypeRef ToType);
1523 LLVMValueRef LLVMConstFPToSI(LLVMValueRef ConstantVal, LLVMTypeRef ToType);
1524 LLVMValueRef LLVMConstPtrToInt(LLVMValueRef ConstantVal, LLVMTypeRef ToType);
1525 LLVMValueRef LLVMConstIntToPtr(LLVMValueRef ConstantVal, LLVMTypeRef ToType);
1526 LLVMValueRef LLVMConstBitCast(LLVMValueRef ConstantVal, LLVMTypeRef ToType);
1527 LLVMValueRef LLVMConstZExtOrBitCast(LLVMValueRef ConstantVal,
1528 LLVMTypeRef ToType);
1529 LLVMValueRef LLVMConstSExtOrBitCast(LLVMValueRef ConstantVal,
1530 LLVMTypeRef ToType);
1531 LLVMValueRef LLVMConstTruncOrBitCast(LLVMValueRef ConstantVal,
1532 LLVMTypeRef ToType);
1533 LLVMValueRef LLVMConstPointerCast(LLVMValueRef ConstantVal,
1534 LLVMTypeRef ToType);
1535 LLVMValueRef LLVMConstIntCast(LLVMValueRef ConstantVal, LLVMTypeRef ToType,
1537 LLVMValueRef LLVMConstFPCast(LLVMValueRef ConstantVal, LLVMTypeRef ToType);
1538 LLVMValueRef LLVMConstSelect(LLVMValueRef ConstantCondition,
1539 LLVMValueRef ConstantIfTrue,
1540 LLVMValueRef ConstantIfFalse);
1541 LLVMValueRef LLVMConstExtractElement(LLVMValueRef VectorConstant,
1542 LLVMValueRef IndexConstant);
1543 LLVMValueRef LLVMConstInsertElement(LLVMValueRef VectorConstant,
1544 LLVMValueRef ElementValueConstant,
1545 LLVMValueRef IndexConstant);
1546 LLVMValueRef LLVMConstShuffleVector(LLVMValueRef VectorAConstant,
1547 LLVMValueRef VectorBConstant,
1548 LLVMValueRef MaskConstant);
1549 LLVMValueRef LLVMConstExtractValue(LLVMValueRef AggConstant, unsigned *IdxList,
1551 LLVMValueRef LLVMConstInsertValue(LLVMValueRef AggConstant,
1552 LLVMValueRef ElementValueConstant,
1553 unsigned *IdxList, unsigned NumIdx);
1554 LLVMValueRef LLVMConstInlineAsm(LLVMTypeRef Ty,
1555 const char *AsmString, const char *Constraints,
1556 LLVMBool HasSideEffects, LLVMBool IsAlignStack);
1557 LLVMValueRef LLVMBlockAddress(LLVMValueRef F, LLVMBasicBlockRef BB);
1564 * @defgroup LLVMCCoreValueConstantGlobals Global Values
1566 * This group contains functions that operate on global values. Functions in
1567 * this group relate to functions in the llvm::GlobalValue class tree.
1569 * @see llvm::GlobalValue
1574 LLVMModuleRef LLVMGetGlobalParent(LLVMValueRef Global);
1575 LLVMBool LLVMIsDeclaration(LLVMValueRef Global);
1576 LLVMLinkage LLVMGetLinkage(LLVMValueRef Global);
1577 void LLVMSetLinkage(LLVMValueRef Global, LLVMLinkage Linkage);
1578 const char *LLVMGetSection(LLVMValueRef Global);
1579 void LLVMSetSection(LLVMValueRef Global, const char *Section);
1580 LLVMVisibility LLVMGetVisibility(LLVMValueRef Global);
1581 void LLVMSetVisibility(LLVMValueRef Global, LLVMVisibility Viz);
1582 unsigned LLVMGetAlignment(LLVMValueRef Global);
1583 void LLVMSetAlignment(LLVMValueRef Global, unsigned Bytes);
1586 * @defgroup LLVMCoreValueConstantGlobalVariable Global Variables
1588 * This group contains functions that operate on global variable values.
1590 * @see llvm::GlobalVariable
1594 LLVMValueRef LLVMAddGlobal(LLVMModuleRef M, LLVMTypeRef Ty, const char *Name);
1595 LLVMValueRef LLVMAddGlobalInAddressSpace(LLVMModuleRef M, LLVMTypeRef Ty,
1597 unsigned AddressSpace);
1598 LLVMValueRef LLVMGetNamedGlobal(LLVMModuleRef M, const char *Name);
1599 LLVMValueRef LLVMGetFirstGlobal(LLVMModuleRef M);
1600 LLVMValueRef LLVMGetLastGlobal(LLVMModuleRef M);
1601 LLVMValueRef LLVMGetNextGlobal(LLVMValueRef GlobalVar);
1602 LLVMValueRef LLVMGetPreviousGlobal(LLVMValueRef GlobalVar);
1603 void LLVMDeleteGlobal(LLVMValueRef GlobalVar);
1604 LLVMValueRef LLVMGetInitializer(LLVMValueRef GlobalVar);
1605 void LLVMSetInitializer(LLVMValueRef GlobalVar, LLVMValueRef ConstantVal);
1606 LLVMBool LLVMIsThreadLocal(LLVMValueRef GlobalVar);
1607 void LLVMSetThreadLocal(LLVMValueRef GlobalVar, LLVMBool IsThreadLocal);
1608 LLVMBool LLVMIsGlobalConstant(LLVMValueRef GlobalVar);
1609 void LLVMSetGlobalConstant(LLVMValueRef GlobalVar, LLVMBool IsConstant);
1616 * @defgroup LLVMCoreValueConstantGlobalAlias Global Aliases
1618 * This group contains function that operate on global alias values.
1620 * @see llvm::GlobalAlias
1624 LLVMValueRef LLVMAddAlias(LLVMModuleRef M, LLVMTypeRef Ty, LLVMValueRef Aliasee,
1632 * @defgroup LLVMCCoreValueFunction Function values
1634 * Functions in this group operate on LLVMValueRef instances that
1635 * correspond to llvm::Function instances.
1637 * @see llvm::Function
1643 * Remove a function from its containing module and deletes it.
1645 * @see llvm::Function::eraseFromParent()
1647 void LLVMDeleteFunction(LLVMValueRef Fn);
1650 * Obtain the ID number from a function instance.
1652 * @see llvm::Function::getIntrinsicID()
1654 unsigned LLVMGetIntrinsicID(LLVMValueRef Fn);
1657 * Obtain the calling function of a function.
1659 * The returned value corresponds to the LLVMCallConv enumeration.
1661 * @see llvm::Function::getCallingConv()
1663 unsigned LLVMGetFunctionCallConv(LLVMValueRef Fn);
1666 * Set the calling convention of a function.
1668 * @see llvm::Function::setCallingConv()
1670 * @param Fn Function to operate on
1671 * @param CC LLVMCallConv to set calling convention to
1673 void LLVMSetFunctionCallConv(LLVMValueRef Fn, unsigned CC);
1676 * Obtain the name of the garbage collector to use during code
1679 * @see llvm::Function::getGC()
1681 const char *LLVMGetGC(LLVMValueRef Fn);
1684 * Define the garbage collector to use during code generation.
1686 * @see llvm::Function::setGC()
1688 void LLVMSetGC(LLVMValueRef Fn, const char *Name);
1691 * Add an attribute to a function.
1693 * @see llvm::Function::addAttribute()
1695 void LLVMAddFunctionAttr(LLVMValueRef Fn, LLVMAttribute PA);
1698 * Obtain an attribute from a function.
1700 * @see llvm::Function::getAttributes()
1702 LLVMAttribute LLVMGetFunctionAttr(LLVMValueRef Fn);
1705 * Remove an attribute from a function.
1707 void LLVMRemoveFunctionAttr(LLVMValueRef Fn, LLVMAttribute PA);
1710 * @defgroup LLVMCCoreValueFunctionParameters Function Parameters
1712 * Functions in this group relate to arguments/parameters on functions.
1714 * Functions in this group expect LLVMValueRef instances that correspond
1715 * to llvm::Function instances.
1721 * Obtain the number of parameters in a function.
1723 * @see llvm::Function::arg_size()
1725 unsigned LLVMCountParams(LLVMValueRef Fn);
1728 * Obtain the parameters in a function.
1730 * The takes a pointer to a pre-allocated array of LLVMValueRef that is
1731 * at least LLVMCountParams() long. This array will be filled with
1732 * LLVMValueRef instances which correspond to the parameters the
1733 * function receives. Each LLVMValueRef corresponds to a llvm::Argument
1736 * @see llvm::Function::arg_begin()
1738 void LLVMGetParams(LLVMValueRef Fn, LLVMValueRef *Params);
1741 * Obtain the parameter at the specified index.
1743 * Parameters are indexed from 0.
1745 * @see llvm::Function::arg_begin()
1747 LLVMValueRef LLVMGetParam(LLVMValueRef Fn, unsigned Index);
1750 * Obtain the function to which this argument belongs.
1752 * Unlike other functions in this group, this one takes a LLVMValueRef
1753 * that corresponds to a llvm::Attribute.
1755 * The returned LLVMValueRef is the llvm::Function to which this
1758 LLVMValueRef LLVMGetParamParent(LLVMValueRef Inst);
1761 * Obtain the first parameter to a function.
1763 * @see llvm::Function::arg_begin()
1765 LLVMValueRef LLVMGetFirstParam(LLVMValueRef Fn);
1768 * Obtain the last parameter to a function.
1770 * @see llvm::Function::arg_end()
1772 LLVMValueRef LLVMGetLastParam(LLVMValueRef Fn);
1775 * Obtain the next parameter to a function.
1777 * This takes a LLVMValueRef obtained from LLVMGetFirstParam() (which is
1778 * actually a wrapped iterator) and obtains the next parameter from the
1779 * underlying iterator.
1781 LLVMValueRef LLVMGetNextParam(LLVMValueRef Arg);
1784 * Obtain the previous parameter to a function.
1786 * This is the opposite of LLVMGetNextParam().
1788 LLVMValueRef LLVMGetPreviousParam(LLVMValueRef Arg);
1791 * Add an attribute to a function argument.
1793 * @see llvm::Argument::addAttr()
1795 void LLVMAddAttribute(LLVMValueRef Arg, LLVMAttribute PA);
1798 * Remove an attribute from a function argument.
1800 * @see llvm::Argument::removeAttr()
1802 void LLVMRemoveAttribute(LLVMValueRef Arg, LLVMAttribute PA);
1805 * Get an attribute from a function argument.
1807 LLVMAttribute LLVMGetAttribute(LLVMValueRef Arg);
1810 * Set the alignment for a function parameter.
1812 * @see llvm::Argument::addAttr()
1813 * @see llvm::AttrBuilder::addAlignmentAttr()
1815 void LLVMSetParamAlignment(LLVMValueRef Arg, unsigned align);
1834 * @defgroup LLVMCCoreValueMetadata Metadata
1840 * Obtain a MDString value from a context.
1842 * The returned instance corresponds to the llvm::MDString class.
1844 * The instance is specified by string data of a specified length. The
1845 * string content is copied, so the backing memory can be freed after
1846 * this function returns.
1848 LLVMValueRef LLVMMDStringInContext(LLVMContextRef C, const char *Str,
1852 * Obtain a MDString value from the global context.
1854 LLVMValueRef LLVMMDString(const char *Str, unsigned SLen);
1857 * Obtain a MDNode value from a context.
1859 * The returned value corresponds to the llvm::MDNode class.
1861 LLVMValueRef LLVMMDNodeInContext(LLVMContextRef C, LLVMValueRef *Vals,
1865 * Obtain a MDNode value from the global context.
1867 LLVMValueRef LLVMMDNode(LLVMValueRef *Vals, unsigned Count);
1870 * Obtain the underlying string from a MDString value.
1872 * @param V Instance to obtain string from.
1873 * @param Len Memory address which will hold length of returned string.
1874 * @return String data in MDString.
1876 const char *LLVMGetMDString(LLVMValueRef V, unsigned* Len);
1879 * Obtain the number of operands from an MDNode value.
1881 * @param V MDNode to get number of operands from.
1882 * @return Number of operands of the MDNode.
1884 unsigned LLVMGetMDNodeNumOperands(LLVMValueRef V);
1887 * Obtain the given MDNode's operands.
1889 * The passed LLVMValueRef pointer should point to enough memory to hold all of
1890 * the operands of the given MDNode (see LLVMGetMDNodeNumOperands) as
1891 * LLVMValueRefs. This memory will be populated with the LLVMValueRefs of the
1892 * MDNode's operands.
1894 * @param V MDNode to get the operands from.
1895 * @param Dest Destination array for operands.
1897 void LLVMGetMDNodeOperands(LLVMValueRef V, LLVMValueRef *Dest);
1904 * @defgroup LLVMCCoreValueBasicBlock Basic Block
1906 * A basic block represents a single entry single exit section of code.
1907 * Basic blocks contain a list of instructions which form the body of
1910 * Basic blocks belong to functions. They have the type of label.
1912 * Basic blocks are themselves values. However, the C API models them as
1913 * LLVMBasicBlockRef.
1915 * @see llvm::BasicBlock
1921 * Convert a basic block instance to a value type.
1923 LLVMValueRef LLVMBasicBlockAsValue(LLVMBasicBlockRef BB);
1926 * Determine whether a LLVMValueRef is itself a basic block.
1928 LLVMBool LLVMValueIsBasicBlock(LLVMValueRef Val);
1931 * Convert a LLVMValueRef to a LLVMBasicBlockRef instance.
1933 LLVMBasicBlockRef LLVMValueAsBasicBlock(LLVMValueRef Val);
1936 * Obtain the function to which a basic block belongs.
1938 * @see llvm::BasicBlock::getParent()
1940 LLVMValueRef LLVMGetBasicBlockParent(LLVMBasicBlockRef BB);
1943 * Obtain the terminator instruction for a basic block.
1945 * If the basic block does not have a terminator (it is not well-formed
1946 * if it doesn't), then NULL is returned.
1948 * The returned LLVMValueRef corresponds to a llvm::TerminatorInst.
1950 * @see llvm::BasicBlock::getTerminator()
1952 LLVMValueRef LLVMGetBasicBlockTerminator(LLVMBasicBlockRef BB);
1955 * Obtain the number of basic blocks in a function.
1957 * @param Fn Function value to operate on.
1959 unsigned LLVMCountBasicBlocks(LLVMValueRef Fn);
1962 * Obtain all of the basic blocks in a function.
1964 * This operates on a function value. The BasicBlocks parameter is a
1965 * pointer to a pre-allocated array of LLVMBasicBlockRef of at least
1966 * LLVMCountBasicBlocks() in length. This array is populated with
1967 * LLVMBasicBlockRef instances.
1969 void LLVMGetBasicBlocks(LLVMValueRef Fn, LLVMBasicBlockRef *BasicBlocks);
1972 * Obtain the first basic block in a function.
1974 * The returned basic block can be used as an iterator. You will likely
1975 * eventually call into LLVMGetNextBasicBlock() with it.
1977 * @see llvm::Function::begin()
1979 LLVMBasicBlockRef LLVMGetFirstBasicBlock(LLVMValueRef Fn);
1982 * Obtain the last basic block in a function.
1984 * @see llvm::Function::end()
1986 LLVMBasicBlockRef LLVMGetLastBasicBlock(LLVMValueRef Fn);
1989 * Advance a basic block iterator.
1991 LLVMBasicBlockRef LLVMGetNextBasicBlock(LLVMBasicBlockRef BB);
1994 * Go backwards in a basic block iterator.
1996 LLVMBasicBlockRef LLVMGetPreviousBasicBlock(LLVMBasicBlockRef BB);
1999 * Obtain the basic block that corresponds to the entry point of a
2002 * @see llvm::Function::getEntryBlock()
2004 LLVMBasicBlockRef LLVMGetEntryBasicBlock(LLVMValueRef Fn);
2007 * Append a basic block to the end of a function.
2009 * @see llvm::BasicBlock::Create()
2011 LLVMBasicBlockRef LLVMAppendBasicBlockInContext(LLVMContextRef C,
2016 * Append a basic block to the end of a function using the global
2019 * @see llvm::BasicBlock::Create()
2021 LLVMBasicBlockRef LLVMAppendBasicBlock(LLVMValueRef Fn, const char *Name);
2024 * Insert a basic block in a function before another basic block.
2026 * The function to add to is determined by the function of the
2027 * passed basic block.
2029 * @see llvm::BasicBlock::Create()
2031 LLVMBasicBlockRef LLVMInsertBasicBlockInContext(LLVMContextRef C,
2032 LLVMBasicBlockRef BB,
2036 * Insert a basic block in a function using the global context.
2038 * @see llvm::BasicBlock::Create()
2040 LLVMBasicBlockRef LLVMInsertBasicBlock(LLVMBasicBlockRef InsertBeforeBB,
2044 * Remove a basic block from a function and delete it.
2046 * This deletes the basic block from its containing function and deletes
2047 * the basic block itself.
2049 * @see llvm::BasicBlock::eraseFromParent()
2051 void LLVMDeleteBasicBlock(LLVMBasicBlockRef BB);
2054 * Remove a basic block from a function.
2056 * This deletes the basic block from its containing function but keep
2057 * the basic block alive.
2059 * @see llvm::BasicBlock::removeFromParent()
2061 void LLVMRemoveBasicBlockFromParent(LLVMBasicBlockRef BB);
2064 * Move a basic block to before another one.
2066 * @see llvm::BasicBlock::moveBefore()
2068 void LLVMMoveBasicBlockBefore(LLVMBasicBlockRef BB, LLVMBasicBlockRef MovePos);
2071 * Move a basic block to after another one.
2073 * @see llvm::BasicBlock::moveAfter()
2075 void LLVMMoveBasicBlockAfter(LLVMBasicBlockRef BB, LLVMBasicBlockRef MovePos);
2078 * Obtain the first instruction in a basic block.
2080 * The returned LLVMValueRef corresponds to a llvm::Instruction
2083 LLVMValueRef LLVMGetFirstInstruction(LLVMBasicBlockRef BB);
2086 * Obtain the last instruction in a basic block.
2088 * The returned LLVMValueRef corresponds to a LLVM:Instruction.
2090 LLVMValueRef LLVMGetLastInstruction(LLVMBasicBlockRef BB);
2097 * @defgroup LLVMCCoreValueInstruction Instructions
2099 * Functions in this group relate to the inspection and manipulation of
2100 * individual instructions.
2102 * In the C++ API, an instruction is modeled by llvm::Instruction. This
2103 * class has a large number of descendents. llvm::Instruction is a
2104 * llvm::Value and in the C API, instructions are modeled by
2107 * This group also contains sub-groups which operate on specific
2108 * llvm::Instruction types, e.g. llvm::CallInst.
2114 * Determine whether an instruction has any metadata attached.
2116 int LLVMHasMetadata(LLVMValueRef Val);
2119 * Return metadata associated with an instruction value.
2121 LLVMValueRef LLVMGetMetadata(LLVMValueRef Val, unsigned KindID);
2124 * Set metadata associated with an instruction value.
2126 void LLVMSetMetadata(LLVMValueRef Val, unsigned KindID, LLVMValueRef Node);
2129 * Obtain the basic block to which an instruction belongs.
2131 * @see llvm::Instruction::getParent()
2133 LLVMBasicBlockRef LLVMGetInstructionParent(LLVMValueRef Inst);
2136 * Obtain the instruction that occurs after the one specified.
2138 * The next instruction will be from the same basic block.
2140 * If this is the last instruction in a basic block, NULL will be
2143 LLVMValueRef LLVMGetNextInstruction(LLVMValueRef Inst);
2146 * Obtain the instruction that occurred before this one.
2148 * If the instruction is the first instruction in a basic block, NULL
2151 LLVMValueRef LLVMGetPreviousInstruction(LLVMValueRef Inst);
2154 * Remove and delete an instruction.
2156 * The instruction specified is removed from its containing building
2157 * block and then deleted.
2159 * @see llvm::Instruction::eraseFromParent()
2161 void LLVMInstructionEraseFromParent(LLVMValueRef Inst);
2164 * Obtain the code opcode for an individual instruction.
2166 * @see llvm::Instruction::getOpCode()
2168 LLVMOpcode LLVMGetInstructionOpcode(LLVMValueRef Inst);
2171 * Obtain the predicate of an instruction.
2173 * This is only valid for instructions that correspond to llvm::ICmpInst
2174 * or llvm::ConstantExpr whose opcode is llvm::Instruction::ICmp.
2176 * @see llvm::ICmpInst::getPredicate()
2178 LLVMIntPredicate LLVMGetICmpPredicate(LLVMValueRef Inst);
2181 * @defgroup LLVMCCoreValueInstructionCall Call Sites and Invocations
2183 * Functions in this group apply to instructions that refer to call
2184 * sites and invocations. These correspond to C++ types in the
2185 * llvm::CallInst class tree.
2191 * Set the calling convention for a call instruction.
2193 * This expects an LLVMValueRef that corresponds to a llvm::CallInst or
2196 * @see llvm::CallInst::setCallingConv()
2197 * @see llvm::InvokeInst::setCallingConv()
2199 void LLVMSetInstructionCallConv(LLVMValueRef Instr, unsigned CC);
2202 * Obtain the calling convention for a call instruction.
2204 * This is the opposite of LLVMSetInstructionCallConv(). Reads its
2207 * @see LLVMSetInstructionCallConv()
2209 unsigned LLVMGetInstructionCallConv(LLVMValueRef Instr);
2212 void LLVMAddInstrAttribute(LLVMValueRef Instr, unsigned index, LLVMAttribute);
2213 void LLVMRemoveInstrAttribute(LLVMValueRef Instr, unsigned index,
2215 void LLVMSetInstrParamAlignment(LLVMValueRef Instr, unsigned index,
2219 * Obtain whether a call instruction is a tail call.
2221 * This only works on llvm::CallInst instructions.
2223 * @see llvm::CallInst::isTailCall()
2225 LLVMBool LLVMIsTailCall(LLVMValueRef CallInst);
2228 * Set whether a call instruction is a tail call.
2230 * This only works on llvm::CallInst instructions.
2232 * @see llvm::CallInst::setTailCall()
2234 void LLVMSetTailCall(LLVMValueRef CallInst, LLVMBool IsTailCall);
2241 * Obtain the default destination basic block of a switch instruction.
2243 * This only works on llvm::SwitchInst instructions.
2245 * @see llvm::SwitchInst::getDefaultDest()
2247 LLVMBasicBlockRef LLVMGetSwitchDefaultDest(LLVMValueRef SwitchInstr);
2250 * @defgroup LLVMCCoreValueInstructionPHINode PHI Nodes
2252 * Functions in this group only apply to instructions that map to
2253 * llvm::PHINode instances.
2259 * Add an incoming value to the end of a PHI list.
2261 void LLVMAddIncoming(LLVMValueRef PhiNode, LLVMValueRef *IncomingValues,
2262 LLVMBasicBlockRef *IncomingBlocks, unsigned Count);
2265 * Obtain the number of incoming basic blocks to a PHI node.
2267 unsigned LLVMCountIncoming(LLVMValueRef PhiNode);
2270 * Obtain an incoming value to a PHI node as a LLVMValueRef.
2272 LLVMValueRef LLVMGetIncomingValue(LLVMValueRef PhiNode, unsigned Index);
2275 * Obtain an incoming value to a PHI node as a LLVMBasicBlockRef.
2277 LLVMBasicBlockRef LLVMGetIncomingBlock(LLVMValueRef PhiNode, unsigned Index);
2292 * @defgroup LLVMCCoreInstructionBuilder Instruction Builders
2294 * An instruction builder represents a point within a basic block and is
2295 * the exclusive means of building instructions using the C interface.
2300 LLVMBuilderRef LLVMCreateBuilderInContext(LLVMContextRef C);
2301 LLVMBuilderRef LLVMCreateBuilder(void);
2302 void LLVMPositionBuilder(LLVMBuilderRef Builder, LLVMBasicBlockRef Block,
2303 LLVMValueRef Instr);
2304 void LLVMPositionBuilderBefore(LLVMBuilderRef Builder, LLVMValueRef Instr);
2305 void LLVMPositionBuilderAtEnd(LLVMBuilderRef Builder, LLVMBasicBlockRef Block);
2306 LLVMBasicBlockRef LLVMGetInsertBlock(LLVMBuilderRef Builder);
2307 void LLVMClearInsertionPosition(LLVMBuilderRef Builder);
2308 void LLVMInsertIntoBuilder(LLVMBuilderRef Builder, LLVMValueRef Instr);
2309 void LLVMInsertIntoBuilderWithName(LLVMBuilderRef Builder, LLVMValueRef Instr,
2311 void LLVMDisposeBuilder(LLVMBuilderRef Builder);
2314 void LLVMSetCurrentDebugLocation(LLVMBuilderRef Builder, LLVMValueRef L);
2315 LLVMValueRef LLVMGetCurrentDebugLocation(LLVMBuilderRef Builder);
2316 void LLVMSetInstDebugLocation(LLVMBuilderRef Builder, LLVMValueRef Inst);
2319 LLVMValueRef LLVMBuildRetVoid(LLVMBuilderRef);
2320 LLVMValueRef LLVMBuildRet(LLVMBuilderRef, LLVMValueRef V);
2321 LLVMValueRef LLVMBuildAggregateRet(LLVMBuilderRef, LLVMValueRef *RetVals,
2323 LLVMValueRef LLVMBuildBr(LLVMBuilderRef, LLVMBasicBlockRef Dest);
2324 LLVMValueRef LLVMBuildCondBr(LLVMBuilderRef, LLVMValueRef If,
2325 LLVMBasicBlockRef Then, LLVMBasicBlockRef Else);
2326 LLVMValueRef LLVMBuildSwitch(LLVMBuilderRef, LLVMValueRef V,
2327 LLVMBasicBlockRef Else, unsigned NumCases);
2328 LLVMValueRef LLVMBuildIndirectBr(LLVMBuilderRef B, LLVMValueRef Addr,
2330 LLVMValueRef LLVMBuildInvoke(LLVMBuilderRef, LLVMValueRef Fn,
2331 LLVMValueRef *Args, unsigned NumArgs,
2332 LLVMBasicBlockRef Then, LLVMBasicBlockRef Catch,
2334 LLVMValueRef LLVMBuildLandingPad(LLVMBuilderRef B, LLVMTypeRef Ty,
2335 LLVMValueRef PersFn, unsigned NumClauses,
2337 LLVMValueRef LLVMBuildResume(LLVMBuilderRef B, LLVMValueRef Exn);
2338 LLVMValueRef LLVMBuildUnreachable(LLVMBuilderRef);
2340 /* Add a case to the switch instruction */
2341 void LLVMAddCase(LLVMValueRef Switch, LLVMValueRef OnVal,
2342 LLVMBasicBlockRef Dest);
2344 /* Add a destination to the indirectbr instruction */
2345 void LLVMAddDestination(LLVMValueRef IndirectBr, LLVMBasicBlockRef Dest);
2347 /* Add a catch or filter clause to the landingpad instruction */
2348 void LLVMAddClause(LLVMValueRef LandingPad, LLVMValueRef ClauseVal);
2350 /* Set the 'cleanup' flag in the landingpad instruction */
2351 void LLVMSetCleanup(LLVMValueRef LandingPad, LLVMBool Val);
2354 LLVMValueRef LLVMBuildAdd(LLVMBuilderRef, LLVMValueRef LHS, LLVMValueRef RHS,
2356 LLVMValueRef LLVMBuildNSWAdd(LLVMBuilderRef, LLVMValueRef LHS, LLVMValueRef RHS,
2358 LLVMValueRef LLVMBuildNUWAdd(LLVMBuilderRef, LLVMValueRef LHS, LLVMValueRef RHS,
2360 LLVMValueRef LLVMBuildFAdd(LLVMBuilderRef, LLVMValueRef LHS, LLVMValueRef RHS,
2362 LLVMValueRef LLVMBuildSub(LLVMBuilderRef, LLVMValueRef LHS, LLVMValueRef RHS,
2364 LLVMValueRef LLVMBuildNSWSub(LLVMBuilderRef, LLVMValueRef LHS, LLVMValueRef RHS,
2366 LLVMValueRef LLVMBuildNUWSub(LLVMBuilderRef, LLVMValueRef LHS, LLVMValueRef RHS,
2368 LLVMValueRef LLVMBuildFSub(LLVMBuilderRef, LLVMValueRef LHS, LLVMValueRef RHS,
2370 LLVMValueRef LLVMBuildMul(LLVMBuilderRef, LLVMValueRef LHS, LLVMValueRef RHS,
2372 LLVMValueRef LLVMBuildNSWMul(LLVMBuilderRef, LLVMValueRef LHS, LLVMValueRef RHS,
2374 LLVMValueRef LLVMBuildNUWMul(LLVMBuilderRef, LLVMValueRef LHS, LLVMValueRef RHS,
2376 LLVMValueRef LLVMBuildFMul(LLVMBuilderRef, LLVMValueRef LHS, LLVMValueRef RHS,
2378 LLVMValueRef LLVMBuildUDiv(LLVMBuilderRef, LLVMValueRef LHS, LLVMValueRef RHS,
2380 LLVMValueRef LLVMBuildSDiv(LLVMBuilderRef, LLVMValueRef LHS, LLVMValueRef RHS,
2382 LLVMValueRef LLVMBuildExactSDiv(LLVMBuilderRef, LLVMValueRef LHS, LLVMValueRef RHS,
2384 LLVMValueRef LLVMBuildFDiv(LLVMBuilderRef, LLVMValueRef LHS, LLVMValueRef RHS,
2386 LLVMValueRef LLVMBuildURem(LLVMBuilderRef, LLVMValueRef LHS, LLVMValueRef RHS,
2388 LLVMValueRef LLVMBuildSRem(LLVMBuilderRef, LLVMValueRef LHS, LLVMValueRef RHS,
2390 LLVMValueRef LLVMBuildFRem(LLVMBuilderRef, LLVMValueRef LHS, LLVMValueRef RHS,
2392 LLVMValueRef LLVMBuildShl(LLVMBuilderRef, LLVMValueRef LHS, LLVMValueRef RHS,
2394 LLVMValueRef LLVMBuildLShr(LLVMBuilderRef, LLVMValueRef LHS, LLVMValueRef RHS,
2396 LLVMValueRef LLVMBuildAShr(LLVMBuilderRef, LLVMValueRef LHS, LLVMValueRef RHS,
2398 LLVMValueRef LLVMBuildAnd(LLVMBuilderRef, LLVMValueRef LHS, LLVMValueRef RHS,
2400 LLVMValueRef LLVMBuildOr(LLVMBuilderRef, LLVMValueRef LHS, LLVMValueRef RHS,
2402 LLVMValueRef LLVMBuildXor(LLVMBuilderRef, LLVMValueRef LHS, LLVMValueRef RHS,
2404 LLVMValueRef LLVMBuildBinOp(LLVMBuilderRef B, LLVMOpcode Op,
2405 LLVMValueRef LHS, LLVMValueRef RHS,
2407 LLVMValueRef LLVMBuildNeg(LLVMBuilderRef, LLVMValueRef V, const char *Name);
2408 LLVMValueRef LLVMBuildNSWNeg(LLVMBuilderRef B, LLVMValueRef V,
2410 LLVMValueRef LLVMBuildNUWNeg(LLVMBuilderRef B, LLVMValueRef V,
2412 LLVMValueRef LLVMBuildFNeg(LLVMBuilderRef, LLVMValueRef V, const char *Name);
2413 LLVMValueRef LLVMBuildNot(LLVMBuilderRef, LLVMValueRef V, const char *Name);
2416 LLVMValueRef LLVMBuildMalloc(LLVMBuilderRef, LLVMTypeRef Ty, const char *Name);
2417 LLVMValueRef LLVMBuildArrayMalloc(LLVMBuilderRef, LLVMTypeRef Ty,
2418 LLVMValueRef Val, const char *Name);
2419 LLVMValueRef LLVMBuildAlloca(LLVMBuilderRef, LLVMTypeRef Ty, const char *Name);
2420 LLVMValueRef LLVMBuildArrayAlloca(LLVMBuilderRef, LLVMTypeRef Ty,
2421 LLVMValueRef Val, const char *Name);
2422 LLVMValueRef LLVMBuildFree(LLVMBuilderRef, LLVMValueRef PointerVal);
2423 LLVMValueRef LLVMBuildLoad(LLVMBuilderRef, LLVMValueRef PointerVal,
2425 LLVMValueRef LLVMBuildStore(LLVMBuilderRef, LLVMValueRef Val, LLVMValueRef Ptr);
2426 LLVMValueRef LLVMBuildGEP(LLVMBuilderRef B, LLVMValueRef Pointer,
2427 LLVMValueRef *Indices, unsigned NumIndices,
2429 LLVMValueRef LLVMBuildInBoundsGEP(LLVMBuilderRef B, LLVMValueRef Pointer,
2430 LLVMValueRef *Indices, unsigned NumIndices,
2432 LLVMValueRef LLVMBuildStructGEP(LLVMBuilderRef B, LLVMValueRef Pointer,
2433 unsigned Idx, const char *Name);
2434 LLVMValueRef LLVMBuildGlobalString(LLVMBuilderRef B, const char *Str,
2436 LLVMValueRef LLVMBuildGlobalStringPtr(LLVMBuilderRef B, const char *Str,
2438 LLVMBool LLVMGetVolatile(LLVMValueRef MemoryAccessInst);
2439 void LLVMSetVolatile(LLVMValueRef MemoryAccessInst, LLVMBool IsVolatile);
2442 LLVMValueRef LLVMBuildTrunc(LLVMBuilderRef, LLVMValueRef Val,
2443 LLVMTypeRef DestTy, const char *Name);
2444 LLVMValueRef LLVMBuildZExt(LLVMBuilderRef, LLVMValueRef Val,
2445 LLVMTypeRef DestTy, const char *Name);
2446 LLVMValueRef LLVMBuildSExt(LLVMBuilderRef, LLVMValueRef Val,
2447 LLVMTypeRef DestTy, const char *Name);
2448 LLVMValueRef LLVMBuildFPToUI(LLVMBuilderRef, LLVMValueRef Val,
2449 LLVMTypeRef DestTy, const char *Name);
2450 LLVMValueRef LLVMBuildFPToSI(LLVMBuilderRef, LLVMValueRef Val,
2451 LLVMTypeRef DestTy, const char *Name);
2452 LLVMValueRef LLVMBuildUIToFP(LLVMBuilderRef, LLVMValueRef Val,
2453 LLVMTypeRef DestTy, const char *Name);
2454 LLVMValueRef LLVMBuildSIToFP(LLVMBuilderRef, LLVMValueRef Val,
2455 LLVMTypeRef DestTy, const char *Name);
2456 LLVMValueRef LLVMBuildFPTrunc(LLVMBuilderRef, LLVMValueRef Val,
2457 LLVMTypeRef DestTy, const char *Name);
2458 LLVMValueRef LLVMBuildFPExt(LLVMBuilderRef, LLVMValueRef Val,
2459 LLVMTypeRef DestTy, const char *Name);
2460 LLVMValueRef LLVMBuildPtrToInt(LLVMBuilderRef, LLVMValueRef Val,
2461 LLVMTypeRef DestTy, const char *Name);
2462 LLVMValueRef LLVMBuildIntToPtr(LLVMBuilderRef, LLVMValueRef Val,
2463 LLVMTypeRef DestTy, const char *Name);
2464 LLVMValueRef LLVMBuildBitCast(LLVMBuilderRef, LLVMValueRef Val,
2465 LLVMTypeRef DestTy, const char *Name);
2466 LLVMValueRef LLVMBuildZExtOrBitCast(LLVMBuilderRef, LLVMValueRef Val,
2467 LLVMTypeRef DestTy, const char *Name);
2468 LLVMValueRef LLVMBuildSExtOrBitCast(LLVMBuilderRef, LLVMValueRef Val,
2469 LLVMTypeRef DestTy, const char *Name);
2470 LLVMValueRef LLVMBuildTruncOrBitCast(LLVMBuilderRef, LLVMValueRef Val,
2471 LLVMTypeRef DestTy, const char *Name);
2472 LLVMValueRef LLVMBuildCast(LLVMBuilderRef B, LLVMOpcode Op, LLVMValueRef Val,
2473 LLVMTypeRef DestTy, const char *Name);
2474 LLVMValueRef LLVMBuildPointerCast(LLVMBuilderRef, LLVMValueRef Val,
2475 LLVMTypeRef DestTy, const char *Name);
2476 LLVMValueRef LLVMBuildIntCast(LLVMBuilderRef, LLVMValueRef Val, /*Signed cast!*/
2477 LLVMTypeRef DestTy, const char *Name);
2478 LLVMValueRef LLVMBuildFPCast(LLVMBuilderRef, LLVMValueRef Val,
2479 LLVMTypeRef DestTy, const char *Name);
2482 LLVMValueRef LLVMBuildICmp(LLVMBuilderRef, LLVMIntPredicate Op,
2483 LLVMValueRef LHS, LLVMValueRef RHS,
2485 LLVMValueRef LLVMBuildFCmp(LLVMBuilderRef, LLVMRealPredicate Op,
2486 LLVMValueRef LHS, LLVMValueRef RHS,
2489 /* Miscellaneous instructions */
2490 LLVMValueRef LLVMBuildPhi(LLVMBuilderRef, LLVMTypeRef Ty, const char *Name);
2491 LLVMValueRef LLVMBuildCall(LLVMBuilderRef, LLVMValueRef Fn,
2492 LLVMValueRef *Args, unsigned NumArgs,
2494 LLVMValueRef LLVMBuildSelect(LLVMBuilderRef, LLVMValueRef If,
2495 LLVMValueRef Then, LLVMValueRef Else,
2497 LLVMValueRef LLVMBuildVAArg(LLVMBuilderRef, LLVMValueRef List, LLVMTypeRef Ty,
2499 LLVMValueRef LLVMBuildExtractElement(LLVMBuilderRef, LLVMValueRef VecVal,
2500 LLVMValueRef Index, const char *Name);
2501 LLVMValueRef LLVMBuildInsertElement(LLVMBuilderRef, LLVMValueRef VecVal,
2502 LLVMValueRef EltVal, LLVMValueRef Index,
2504 LLVMValueRef LLVMBuildShuffleVector(LLVMBuilderRef, LLVMValueRef V1,
2505 LLVMValueRef V2, LLVMValueRef Mask,
2507 LLVMValueRef LLVMBuildExtractValue(LLVMBuilderRef, LLVMValueRef AggVal,
2508 unsigned Index, const char *Name);
2509 LLVMValueRef LLVMBuildInsertValue(LLVMBuilderRef, LLVMValueRef AggVal,
2510 LLVMValueRef EltVal, unsigned Index,
2513 LLVMValueRef LLVMBuildIsNull(LLVMBuilderRef, LLVMValueRef Val,
2515 LLVMValueRef LLVMBuildIsNotNull(LLVMBuilderRef, LLVMValueRef Val,
2517 LLVMValueRef LLVMBuildPtrDiff(LLVMBuilderRef, LLVMValueRef LHS,
2518 LLVMValueRef RHS, const char *Name);
2525 * @defgroup LLVMCCoreModuleProvider Module Providers
2531 * Changes the type of M so it can be passed to FunctionPassManagers and the
2532 * JIT. They take ModuleProviders for historical reasons.
2534 LLVMModuleProviderRef
2535 LLVMCreateModuleProviderForExistingModule(LLVMModuleRef M);
2538 * Destroys the module M.
2540 void LLVMDisposeModuleProvider(LLVMModuleProviderRef M);
2547 * @defgroup LLVMCCoreMemoryBuffers Memory Buffers
2552 LLVMBool LLVMCreateMemoryBufferWithContentsOfFile(const char *Path,
2553 LLVMMemoryBufferRef *OutMemBuf,
2555 LLVMBool LLVMCreateMemoryBufferWithSTDIN(LLVMMemoryBufferRef *OutMemBuf,
2557 LLVMMemoryBufferRef LLVMCreateMemoryBufferWithMemoryRange(const char *InputData,
2558 size_t InputDataLength,
2559 const char *BufferName,
2560 LLVMBool RequiresNullTerminator);
2561 LLVMMemoryBufferRef LLVMCreateMemoryBufferWithMemoryRangeCopy(const char *InputData,
2562 size_t InputDataLength,
2563 const char *BufferName);
2564 void LLVMDisposeMemoryBuffer(LLVMMemoryBufferRef MemBuf);
2571 * @defgroup LLVMCCorePassRegistry Pass Registry
2576 /** Return the global pass registry, for use with initialization functions.
2577 @see llvm::PassRegistry::getPassRegistry */
2578 LLVMPassRegistryRef LLVMGetGlobalPassRegistry(void);
2585 * @defgroup LLVMCCorePassManagers Pass Managers
2590 /** Constructs a new whole-module pass pipeline. This type of pipeline is
2591 suitable for link-time optimization and whole-module transformations.
2592 @see llvm::PassManager::PassManager */
2593 LLVMPassManagerRef LLVMCreatePassManager(void);
2595 /** Constructs a new function-by-function pass pipeline over the module
2596 provider. It does not take ownership of the module provider. This type of
2597 pipeline is suitable for code generation and JIT compilation tasks.
2598 @see llvm::FunctionPassManager::FunctionPassManager */
2599 LLVMPassManagerRef LLVMCreateFunctionPassManagerForModule(LLVMModuleRef M);
2601 /** Deprecated: Use LLVMCreateFunctionPassManagerForModule instead. */
2602 LLVMPassManagerRef LLVMCreateFunctionPassManager(LLVMModuleProviderRef MP);
2604 /** Initializes, executes on the provided module, and finalizes all of the
2605 passes scheduled in the pass manager. Returns 1 if any of the passes
2606 modified the module, 0 otherwise.
2607 @see llvm::PassManager::run(Module&) */
2608 LLVMBool LLVMRunPassManager(LLVMPassManagerRef PM, LLVMModuleRef M);
2610 /** Initializes all of the function passes scheduled in the function pass
2611 manager. Returns 1 if any of the passes modified the module, 0 otherwise.
2612 @see llvm::FunctionPassManager::doInitialization */
2613 LLVMBool LLVMInitializeFunctionPassManager(LLVMPassManagerRef FPM);
2615 /** Executes all of the function passes scheduled in the function pass manager
2616 on the provided function. Returns 1 if any of the passes modified the
2617 function, false otherwise.
2618 @see llvm::FunctionPassManager::run(Function&) */
2619 LLVMBool LLVMRunFunctionPassManager(LLVMPassManagerRef FPM, LLVMValueRef F);
2621 /** Finalizes all of the function passes scheduled in in the function pass
2622 manager. Returns 1 if any of the passes modified the module, 0 otherwise.
2623 @see llvm::FunctionPassManager::doFinalization */
2624 LLVMBool LLVMFinalizeFunctionPassManager(LLVMPassManagerRef FPM);
2626 /** Frees the memory of a pass pipeline. For function pipelines, does not free
2627 the module provider.
2628 @see llvm::PassManagerBase::~PassManagerBase. */
2629 void LLVMDisposePassManager(LLVMPassManagerRef PM);
2636 * @defgroup LLVMCCoreThreading Threading
2638 * Handle the structures needed to make LLVM safe for multithreading.
2643 /** Allocate and initialize structures needed to make LLVM safe for
2644 multithreading. The return value indicates whether multithreaded
2645 initialization succeeded. Must be executed in isolation from all
2646 other LLVM api calls.
2647 @see llvm::llvm_start_multithreaded */
2648 LLVMBool LLVMStartMultithreaded();
2650 /** Deallocate structures necessary to make LLVM safe for multithreading.
2651 Must be executed in isolation from all other LLVM api calls.
2652 @see llvm::llvm_stop_multithreaded */
2653 void LLVMStopMultithreaded();
2655 /** Check whether LLVM is executing in thread-safe mode or not.
2656 @see llvm::llvm_is_multithreaded */
2657 LLVMBool LLVMIsMultithreaded();
2675 #if defined(__cplusplus) && !defined(LLVM_DO_NOT_INCLUDE_CPP_HEADERS)
2678 class PassManagerBase;
2680 #define DEFINE_SIMPLE_CONVERSION_FUNCTIONS(ty, ref) \
2681 inline ty *unwrap(ref P) { \
2682 return reinterpret_cast<ty*>(P); \
2685 inline ref wrap(const ty *P) { \
2686 return reinterpret_cast<ref>(const_cast<ty*>(P)); \
2689 #define DEFINE_ISA_CONVERSION_FUNCTIONS(ty, ref) \
2690 DEFINE_SIMPLE_CONVERSION_FUNCTIONS(ty, ref) \
2692 template<typename T> \
2693 inline T *unwrap(ref P) { \
2694 return cast<T>(unwrap(P)); \
2697 #define DEFINE_STDCXX_CONVERSION_FUNCTIONS(ty, ref) \
2698 DEFINE_SIMPLE_CONVERSION_FUNCTIONS(ty, ref) \
2700 template<typename T> \
2701 inline T *unwrap(ref P) { \
2702 T *Q = (T*)unwrap(P); \
2703 assert(Q && "Invalid cast!"); \
2707 DEFINE_ISA_CONVERSION_FUNCTIONS (Type, LLVMTypeRef )
2708 DEFINE_ISA_CONVERSION_FUNCTIONS (Value, LLVMValueRef )
2709 DEFINE_SIMPLE_CONVERSION_FUNCTIONS(Module, LLVMModuleRef )
2710 DEFINE_SIMPLE_CONVERSION_FUNCTIONS(BasicBlock, LLVMBasicBlockRef )
2711 DEFINE_SIMPLE_CONVERSION_FUNCTIONS(IRBuilder<>, LLVMBuilderRef )
2712 DEFINE_SIMPLE_CONVERSION_FUNCTIONS(MemoryBuffer, LLVMMemoryBufferRef )
2713 DEFINE_SIMPLE_CONVERSION_FUNCTIONS(LLVMContext, LLVMContextRef )
2714 DEFINE_SIMPLE_CONVERSION_FUNCTIONS(Use, LLVMUseRef )
2715 DEFINE_STDCXX_CONVERSION_FUNCTIONS(PassManagerBase, LLVMPassManagerRef )
2716 DEFINE_STDCXX_CONVERSION_FUNCTIONS(PassRegistry, LLVMPassRegistryRef )
2717 /* LLVMModuleProviderRef exists for historical reasons, but now just holds a
2720 inline Module *unwrap(LLVMModuleProviderRef MP) {
2721 return reinterpret_cast<Module*>(MP);
2724 #undef DEFINE_STDCXX_CONVERSION_FUNCTIONS
2725 #undef DEFINE_ISA_CONVERSION_FUNCTIONS
2726 #undef DEFINE_SIMPLE_CONVERSION_FUNCTIONS
2728 /* Specialized opaque context conversions.
2730 inline LLVMContext **unwrap(LLVMContextRef* Tys) {
2731 return reinterpret_cast<LLVMContext**>(Tys);
2734 inline LLVMContextRef *wrap(const LLVMContext **Tys) {
2735 return reinterpret_cast<LLVMContextRef*>(const_cast<LLVMContext**>(Tys));
2738 /* Specialized opaque type conversions.
2740 inline Type **unwrap(LLVMTypeRef* Tys) {
2741 return reinterpret_cast<Type**>(Tys);
2744 inline LLVMTypeRef *wrap(Type **Tys) {
2745 return reinterpret_cast<LLVMTypeRef*>(const_cast<Type**>(Tys));
2748 /* Specialized opaque value conversions.
2750 inline Value **unwrap(LLVMValueRef *Vals) {
2751 return reinterpret_cast<Value**>(Vals);
2754 template<typename T>
2755 inline T **unwrap(LLVMValueRef *Vals, unsigned Length) {
2757 for (LLVMValueRef *I = Vals, *E = Vals + Length; I != E; ++I)
2761 return reinterpret_cast<T**>(Vals);
2764 inline LLVMValueRef *wrap(const Value **Vals) {
2765 return reinterpret_cast<LLVMValueRef*>(const_cast<Value**>(Vals));
2769 #endif /* defined(__cplusplus) && !defined(LLVM_DO_NOT_INCLUDE_CPP_HEADERS) */
2771 #endif /* defined(LLVM_C_CORE_H) */