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"
22 /* Need these includes to support the LLVM 'cast' template for the C++ 'wrap'
23 and 'unwrap' conversion functions. */
24 #include "llvm/Module.h"
25 #include "llvm/PassRegistry.h"
26 #include "llvm/Support/IRBuilder.h"
32 * @defgroup LLVMC LLVM-C: C interface to LLVM
34 * This module exposes parts of the LLVM library as a C API.
40 * @defgroup LLVMCTransforms Transforms
44 * @defgroup LLVMCCore Core
46 * This modules provide an interface to libLLVMCore, which implements
47 * the LLVM intermediate representation as well as other related types
50 * LLVM uses a polymorphic type hierarchy which C cannot represent, therefore
51 * parameters must be passed as base types. Despite the declared types, most
52 * of the functions provided operate only on branches of the type hierarchy.
53 * The declared parameter names are descriptive and specify which type is
54 * required. Additionally, each type hierarchy is documented along with the
55 * functions that operate upon it. For more detail, refer to LLVM's C++ code.
56 * If in doubt, refer to Core.cpp, which performs paramter downcasts in the
57 * form unwrap<RequiredType>(Param).
59 * Many exotic languages can interoperate with C code but have a harder time
60 * with C++ due to name mangling. So in addition to C, this interface enables
61 * tools written in such languages.
63 * When included into a C++ source file, also declares 'wrap' and 'unwrap'
64 * helpers to perform opaque reference<-->pointer conversions. These helpers
65 * are shorter and more tightly typed than writing the casts by hand when
66 * authoring bindings. In assert builds, they will do runtime type checking.
72 * @defgroup LLVMCCoreTypes Types and Enumerations
82 * The top-level container for all LLVM global data. See the LLVMContext class.
84 typedef struct LLVMOpaqueContext *LLVMContextRef;
87 * The top-level container for all other LLVM Intermediate Representation (IR)
92 typedef struct LLVMOpaqueModule *LLVMModuleRef;
95 * Each value in the LLVM IR has a type, an LLVMTypeRef.
99 typedef struct LLVMOpaqueType *LLVMTypeRef;
102 * Represents an individual value in LLVM IR.
104 * This models llvm::Value.
106 typedef struct LLVMOpaqueValue *LLVMValueRef;
109 * Represents a basic block of instruction in LLVM IR.
111 * This models llvm::BasicBlock.
113 typedef struct LLVMOpaqueBasicBlock *LLVMBasicBlockRef;
116 * Represents an LLVM basic block builder.
118 * This models llvm::IRBuilder.
120 typedef struct LLVMOpaqueBuilder *LLVMBuilderRef;
123 * Interface used to provide a module to JIT or interpreter.
124 * This is now just a synonym for llvm::Module, but we have to keep using the
125 * different type to keep binary compatibility.
127 typedef struct LLVMOpaqueModuleProvider *LLVMModuleProviderRef;
130 * Used to provide a module to JIT or interpreter.
132 * @see llvm::MemoryBuffer
134 typedef struct LLVMOpaqueMemoryBuffer *LLVMMemoryBufferRef;
136 /** @see llvm::PassManagerBase */
137 typedef struct LLVMOpaquePassManager *LLVMPassManagerRef;
139 /** @see llvm::PassRegistry */
140 typedef struct LLVMOpaquePassRegistry *LLVMPassRegistryRef;
143 * Used to get the users and usees of a Value.
146 typedef struct LLVMOpaqueUse *LLVMUseRef;
149 LLVMZExtAttribute = 1<<0,
150 LLVMSExtAttribute = 1<<1,
151 LLVMNoReturnAttribute = 1<<2,
152 LLVMInRegAttribute = 1<<3,
153 LLVMStructRetAttribute = 1<<4,
154 LLVMNoUnwindAttribute = 1<<5,
155 LLVMNoAliasAttribute = 1<<6,
156 LLVMByValAttribute = 1<<7,
157 LLVMNestAttribute = 1<<8,
158 LLVMReadNoneAttribute = 1<<9,
159 LLVMReadOnlyAttribute = 1<<10,
160 LLVMNoInlineAttribute = 1<<11,
161 LLVMAlwaysInlineAttribute = 1<<12,
162 LLVMOptimizeForSizeAttribute = 1<<13,
163 LLVMStackProtectAttribute = 1<<14,
164 LLVMStackProtectReqAttribute = 1<<15,
165 LLVMAlignment = 31<<16,
166 LLVMNoCaptureAttribute = 1<<21,
167 LLVMNoRedZoneAttribute = 1<<22,
168 LLVMNoImplicitFloatAttribute = 1<<23,
169 LLVMNakedAttribute = 1<<24,
170 LLVMInlineHintAttribute = 1<<25,
171 LLVMStackAlignment = 7<<26,
172 LLVMReturnsTwice = 1 << 29,
173 LLVMUWTable = 1 << 30,
174 LLVMNonLazyBind = 1 << 31
176 // FIXME: This attribute is currently not included in the C API as
177 // a temporary measure until the API/ABI impact to the C API is understood
178 // and the path forward agreed upon.
179 //LLVMAddressSafety = 1ULL << 32
183 /* Terminator Instructions */
189 /* removed 6 due to API changes */
192 /* Standard Binary Operators */
206 /* Logical Operators */
214 /* Memory Operators */
218 LLVMGetElementPtr = 29,
234 /* Other Operators */
243 LLVMExtractElement = 50,
244 LLVMInsertElement = 51,
245 LLVMShuffleVector = 52,
246 LLVMExtractValue = 53,
247 LLVMInsertValue = 54,
249 /* Atomic operators */
251 LLVMAtomicCmpXchg = 56,
254 /* Exception Handling Operators */
261 LLVMVoidTypeKind, /**< type with no size */
262 LLVMHalfTypeKind, /**< 16 bit floating point type */
263 LLVMFloatTypeKind, /**< 32 bit floating point type */
264 LLVMDoubleTypeKind, /**< 64 bit floating point type */
265 LLVMX86_FP80TypeKind, /**< 80 bit floating point type (X87) */
266 LLVMFP128TypeKind, /**< 128 bit floating point type (112-bit mantissa)*/
267 LLVMPPC_FP128TypeKind, /**< 128 bit floating point type (two 64-bits) */
268 LLVMLabelTypeKind, /**< Labels */
269 LLVMIntegerTypeKind, /**< Arbitrary bit width integers */
270 LLVMFunctionTypeKind, /**< Functions */
271 LLVMStructTypeKind, /**< Structures */
272 LLVMArrayTypeKind, /**< Arrays */
273 LLVMPointerTypeKind, /**< Pointers */
274 LLVMVectorTypeKind, /**< SIMD 'packed' format, or other vector type */
275 LLVMMetadataTypeKind, /**< Metadata */
276 LLVMX86_MMXTypeKind /**< X86 MMX */
280 LLVMExternalLinkage, /**< Externally visible function */
281 LLVMAvailableExternallyLinkage,
282 LLVMLinkOnceAnyLinkage, /**< Keep one copy of function when linking (inline)*/
283 LLVMLinkOnceODRLinkage, /**< Same, but only replaced by something
285 LLVMWeakAnyLinkage, /**< Keep one copy of function when linking (weak) */
286 LLVMWeakODRLinkage, /**< Same, but only replaced by something
288 LLVMAppendingLinkage, /**< Special purpose, only applies to global arrays */
289 LLVMInternalLinkage, /**< Rename collisions when linking (static
291 LLVMPrivateLinkage, /**< Like Internal, but omit from symbol table */
292 LLVMDLLImportLinkage, /**< Function to be imported from DLL */
293 LLVMDLLExportLinkage, /**< Function to be accessible from DLL */
294 LLVMExternalWeakLinkage,/**< ExternalWeak linkage description */
295 LLVMGhostLinkage, /**< Obsolete */
296 LLVMCommonLinkage, /**< Tentative definitions */
297 LLVMLinkerPrivateLinkage, /**< Like Private, but linker removes. */
298 LLVMLinkerPrivateWeakLinkage, /**< Like LinkerPrivate, but is weak. */
299 LLVMLinkerPrivateWeakDefAutoLinkage /**< Like LinkerPrivateWeak, but possibly
304 LLVMDefaultVisibility, /**< The GV is visible */
305 LLVMHiddenVisibility, /**< The GV is hidden */
306 LLVMProtectedVisibility /**< The GV is protected */
311 LLVMFastCallConv = 8,
312 LLVMColdCallConv = 9,
313 LLVMX86StdcallCallConv = 64,
314 LLVMX86FastcallCallConv = 65
318 LLVMIntEQ = 32, /**< equal */
319 LLVMIntNE, /**< not equal */
320 LLVMIntUGT, /**< unsigned greater than */
321 LLVMIntUGE, /**< unsigned greater or equal */
322 LLVMIntULT, /**< unsigned less than */
323 LLVMIntULE, /**< unsigned less or equal */
324 LLVMIntSGT, /**< signed greater than */
325 LLVMIntSGE, /**< signed greater or equal */
326 LLVMIntSLT, /**< signed less than */
327 LLVMIntSLE /**< signed less or equal */
331 LLVMRealPredicateFalse, /**< Always false (always folded) */
332 LLVMRealOEQ, /**< True if ordered and equal */
333 LLVMRealOGT, /**< True if ordered and greater than */
334 LLVMRealOGE, /**< True if ordered and greater than or equal */
335 LLVMRealOLT, /**< True if ordered and less than */
336 LLVMRealOLE, /**< True if ordered and less than or equal */
337 LLVMRealONE, /**< True if ordered and operands are unequal */
338 LLVMRealORD, /**< True if ordered (no nans) */
339 LLVMRealUNO, /**< True if unordered: isnan(X) | isnan(Y) */
340 LLVMRealUEQ, /**< True if unordered or equal */
341 LLVMRealUGT, /**< True if unordered or greater than */
342 LLVMRealUGE, /**< True if unordered, greater than, or equal */
343 LLVMRealULT, /**< True if unordered or less than */
344 LLVMRealULE, /**< True if unordered, less than, or equal */
345 LLVMRealUNE, /**< True if unordered or not equal */
346 LLVMRealPredicateTrue /**< Always true (always folded) */
350 LLVMLandingPadCatch, /**< A catch clause */
351 LLVMLandingPadFilter /**< A filter clause */
352 } LLVMLandingPadClauseTy;
358 void LLVMInitializeCore(LLVMPassRegistryRef R);
361 /*===-- Error handling ----------------------------------------------------===*/
363 void LLVMDisposeMessage(char *Message);
367 * @defgroup LLVMCCoreContext Contexts
369 * Contexts are execution states for the core LLVM IR system.
371 * Most types are tied to a context instance. Multiple contexts can
372 * exist simultaneously. A single context is not thread safe. However,
373 * different contexts can execute on different threads simultaneously.
379 * Create a new context.
381 * Every call to this function should be paired with a call to
382 * LLVMContextDispose() or the context will leak memory.
384 LLVMContextRef LLVMContextCreate(void);
387 * Obtain the global context instance.
389 LLVMContextRef LLVMGetGlobalContext(void);
392 * Destroy a context instance.
394 * This should be called for every call to LLVMContextCreate() or memory
397 void LLVMContextDispose(LLVMContextRef C);
399 unsigned LLVMGetMDKindIDInContext(LLVMContextRef C, const char* Name,
401 unsigned LLVMGetMDKindID(const char* Name, unsigned SLen);
407 /** @defgroup LLVMCCoreModule Modules
409 * Modules represent the top-level structure in a LLVM program. An LLVM
410 * module is effectively a translation unit or a collection of
411 * translation units merged together.
416 /*===-- Modules -----------------------------------------------------------===*/
418 /* Create and destroy modules. */
419 /** @see llvm::Module::Module */
422 * Create a new, empty module in the global context.
424 * This is equivalent to calling LLVMModuleCreateWithNameInContext with
425 * LLVMGetGlobalContext() as the context parameter.
427 * Every invocation should be paired with LLVMDisposeModule() or memory
430 LLVMModuleRef LLVMModuleCreateWithName(const char *ModuleID);
433 * Create a new, empty module in a specific context.
435 * Every invocation should be paired with LLVMDisposeModule() or memory
438 LLVMModuleRef LLVMModuleCreateWithNameInContext(const char *ModuleID,
442 * Destroy a module instance.
444 * This must be called for every created module or memory will be
447 void LLVMDisposeModule(LLVMModuleRef M);
450 * Obtain the data layout for a module.
452 * @see Module::getDataLayout()
454 const char *LLVMGetDataLayout(LLVMModuleRef M);
457 * Set the data layout for a module.
459 * @see Module::setDataLayout()
461 void LLVMSetDataLayout(LLVMModuleRef M, const char *Triple);
464 * Obtain the target triple for a module.
466 * @see Module::getTargetTriple()
468 const char *LLVMGetTarget(LLVMModuleRef M);
471 * Set the target triple for a module.
473 * @see Module::setTargetTriple()
475 void LLVMSetTarget(LLVMModuleRef M, const char *Triple);
478 * Dump a representation of a module to stderr.
480 * @see Module::dump()
482 void LLVMDumpModule(LLVMModuleRef M);
485 * Set inline assembly for a module.
487 * @see Module::setModuleInlineAsm()
489 void LLVMSetModuleInlineAsm(LLVMModuleRef M, const char *Asm);
492 * Obtain the context to which this module is associated.
494 * @see Module::getContext()
496 LLVMContextRef LLVMGetModuleContext(LLVMModuleRef M);
499 * Obtain a Type from a module by its registered name.
501 LLVMTypeRef LLVMGetTypeByName(LLVMModuleRef M, const char *Name);
504 * Obtain the number of operands for named metadata in a module.
506 * @see llvm::Module::getNamedMetadata()
508 unsigned LLVMGetNamedMetadataNumOperands(LLVMModuleRef M, const char* name);
511 * Obtain the named metadata operands for a module.
513 * The passed LLVMValueRef pointer should refer to an array of
514 * LLVMValueRef at least LLVMGetNamedMetadataNumOperands long. This
515 * array will be populated with the LLVMValueRef instances. Each
516 * instance corresponds to a llvm::MDNode.
518 * @see llvm::Module::getNamedMetadata()
519 * @see llvm::MDNode::getOperand()
521 void LLVMGetNamedMetadataOperands(LLVMModuleRef M, const char* name, LLVMValueRef *Dest);
524 * Add an operand to named metadata.
526 * @see llvm::Module::getNamedMetadata()
527 * @see llvm::MDNode::addOperand()
529 void LLVMAddNamedMetadataOperand(LLVMModuleRef M, const char* name,
538 * @defgroup LLVMCCoreType Types
540 * Types represent the type of a value.
542 * Types are associated with a context instance. The context internally
543 * deduplicates types so there is only 1 instance of a specific type
544 * alive at a time. In other words, a unique type is shared among all
545 * consumers within a context.
547 * A Type in the C API corresponds to llvm::Type.
549 * Types have the following hierarchy:
567 * Obtain the enumerated type of a Type instance.
569 * @see llvm::Type:getTypeID()
571 LLVMTypeKind LLVMGetTypeKind(LLVMTypeRef Ty);
574 * Whether the type has a known size.
576 * Things that don't have a size are abstract types, labels, and void.a
578 * @see llvm::Type::isSized()
580 LLVMBool LLVMTypeIsSized(LLVMTypeRef Ty);
583 * Obtain the context to which this type instance is associated.
585 * @see llvm::Type::getContext()
587 LLVMContextRef LLVMGetTypeContext(LLVMTypeRef Ty);
590 * @defgroup LLVMCCoreTypeInt Integer Types
592 * Functions in this section operate on integer types.
598 * Obtain an integer type from a context with specified bit width.
600 LLVMTypeRef LLVMInt1TypeInContext(LLVMContextRef C);
601 LLVMTypeRef LLVMInt8TypeInContext(LLVMContextRef C);
602 LLVMTypeRef LLVMInt16TypeInContext(LLVMContextRef C);
603 LLVMTypeRef LLVMInt32TypeInContext(LLVMContextRef C);
604 LLVMTypeRef LLVMInt64TypeInContext(LLVMContextRef C);
605 LLVMTypeRef LLVMIntTypeInContext(LLVMContextRef C, unsigned NumBits);
608 * Obtain an integer type from the global context with a specified bit
611 LLVMTypeRef LLVMInt1Type(void);
612 LLVMTypeRef LLVMInt8Type(void);
613 LLVMTypeRef LLVMInt16Type(void);
614 LLVMTypeRef LLVMInt32Type(void);
615 LLVMTypeRef LLVMInt64Type(void);
616 LLVMTypeRef LLVMIntType(unsigned NumBits);
617 unsigned LLVMGetIntTypeWidth(LLVMTypeRef IntegerTy);
624 * @defgroup LLVMCCoreTypeFloat Floating Point Types
630 * Obtain a 16-bit floating point type from a context.
632 LLVMTypeRef LLVMHalfTypeInContext(LLVMContextRef C);
635 * Obtain a 32-bit floating point type from a context.
637 LLVMTypeRef LLVMFloatTypeInContext(LLVMContextRef C);
640 * Obtain a 64-bit floating point type from a context.
642 LLVMTypeRef LLVMDoubleTypeInContext(LLVMContextRef C);
645 * Obtain a 80-bit floating point type (X87) from a context.
647 LLVMTypeRef LLVMX86FP80TypeInContext(LLVMContextRef C);
650 * Obtain a 128-bit floating point type (112-bit mantissa) from a
653 LLVMTypeRef LLVMFP128TypeInContext(LLVMContextRef C);
656 * Obtain a 128-bit floating point type (two 64-bits) from a context.
658 LLVMTypeRef LLVMPPCFP128TypeInContext(LLVMContextRef C);
661 * Obtain a floating point type from the global context.
663 * These map to the functions in this group of the same name.
665 LLVMTypeRef LLVMHalfType(void);
666 LLVMTypeRef LLVMFloatType(void);
667 LLVMTypeRef LLVMDoubleType(void);
668 LLVMTypeRef LLVMX86FP80Type(void);
669 LLVMTypeRef LLVMFP128Type(void);
670 LLVMTypeRef LLVMPPCFP128Type(void);
677 * @defgroup LLVMCCoreTypeFunction Function Types
683 * Obtain a function type consisting of a specified signature.
685 * The function is defined as a tuple of a return Type, a list of
686 * parameter types, and whether the function is variadic.
688 LLVMTypeRef LLVMFunctionType(LLVMTypeRef ReturnType,
689 LLVMTypeRef *ParamTypes, unsigned ParamCount,
693 * Returns whether a function type is variadic.
695 LLVMBool LLVMIsFunctionVarArg(LLVMTypeRef FunctionTy);
698 * Obtain the Type this function Type returns.
700 LLVMTypeRef LLVMGetReturnType(LLVMTypeRef FunctionTy);
703 * Obtain the number of parameters this function accepts.
705 unsigned LLVMCountParamTypes(LLVMTypeRef FunctionTy);
708 * Obtain the types of a function's parameters.
710 * The Dest parameter should point to a pre-allocated array of
711 * LLVMTypeRef at least LLVMCountParamTypes() large. On return, the
712 * first LLVMCountParamTypes() entries in the array will be populated
713 * with LLVMTypeRef instances.
715 * @param FunctionTy The function type to operate on.
716 * @param Dest Memory address of an array to be filled with result.
718 void LLVMGetParamTypes(LLVMTypeRef FunctionTy, LLVMTypeRef *Dest);
725 * @defgroup LLVMCCoreTypeStruct Structure Types
727 * These functions relate to LLVMTypeRef instances.
729 * @see llvm::StructType
735 * Create a new structure type in a context.
737 * A structure is specified by a list of inner elements/types and
738 * whether these can be packed together.
740 * @see llvm::StructType::create()
742 LLVMTypeRef LLVMStructTypeInContext(LLVMContextRef C, LLVMTypeRef *ElementTypes,
743 unsigned ElementCount, LLVMBool Packed);
746 * Create a new structure type in the global context.
748 * @see llvm::StructType::create()
750 LLVMTypeRef LLVMStructType(LLVMTypeRef *ElementTypes, unsigned ElementCount,
754 * Create an empty structure in a context having a specified name.
756 * @see llvm::StructType::create()
758 LLVMTypeRef LLVMStructCreateNamed(LLVMContextRef C, const char *Name);
761 * Obtain the name of a structure.
763 * @see llvm::StructType::getName()
765 const char *LLVMGetStructName(LLVMTypeRef Ty);
768 * Set the contents of a structure type.
770 * @see llvm::StructType::setBody()
772 void LLVMStructSetBody(LLVMTypeRef StructTy, LLVMTypeRef *ElementTypes,
773 unsigned ElementCount, LLVMBool Packed);
776 * Get the number of elements defined inside the structure.
778 * @see llvm::StructType::getNumElements()
780 unsigned LLVMCountStructElementTypes(LLVMTypeRef StructTy);
783 * Get the elements within a structure.
785 * The function is passed the address of a pre-allocated array of
786 * LLVMTypeRef at least LLVMCountStructElementTypes() long. After
787 * invocation, this array will be populated with the structure's
788 * elements. The objects in the destination array will have a lifetime
789 * of the structure type itself, which is the lifetime of the context it
792 void LLVMGetStructElementTypes(LLVMTypeRef StructTy, LLVMTypeRef *Dest);
795 * Determine whether a structure is packed.
797 * @see llvm::StructType::isPacked()
799 LLVMBool LLVMIsPackedStruct(LLVMTypeRef StructTy);
802 * Determine whether a structure is opaque.
804 * @see llvm::StructType::isOpaque()
806 LLVMBool LLVMIsOpaqueStruct(LLVMTypeRef StructTy);
814 * @defgroup LLVMCCoreTypeSequential Sequential Types
816 * Sequential types represents "arrays" of types. This is a super class
817 * for array, vector, and pointer types.
823 * Obtain the type of elements within a sequential type.
825 * This works on array, vector, and pointer types.
827 * @see llvm::SequentialType::getElementType()
829 LLVMTypeRef LLVMGetElementType(LLVMTypeRef Ty);
832 * Create a fixed size array type that refers to a specific type.
834 * The created type will exist in the context that its element type
837 * @see llvm::ArrayType::get()
839 LLVMTypeRef LLVMArrayType(LLVMTypeRef ElementType, unsigned ElementCount);
842 * Obtain the length of an array type.
844 * This only works on types that represent arrays.
846 * @see llvm::ArrayType::getNumElements()
848 unsigned LLVMGetArrayLength(LLVMTypeRef ArrayTy);
851 * Create a pointer type that points to a defined type.
853 * The created type will exist in the context that its pointee type
856 * @see llvm::PointerType::get()
858 LLVMTypeRef LLVMPointerType(LLVMTypeRef ElementType, unsigned AddressSpace);
861 * Obtain the address space of a pointer type.
863 * This only works on types that represent pointers.
865 * @see llvm::PointerType::getAddressSpace()
867 unsigned LLVMGetPointerAddressSpace(LLVMTypeRef PointerTy);
870 * Create a vector type that contains a defined type and has a specific
871 * number of elements.
873 * The created type will exist in the context thats its element type
876 * @see llvm::VectorType::get()
878 LLVMTypeRef LLVMVectorType(LLVMTypeRef ElementType, unsigned ElementCount);
881 * Obtain the number of elements in a vector type.
883 * This only works on types that represent vectors.
885 * @see llvm::VectorType::getNumElements()
887 unsigned LLVMGetVectorSize(LLVMTypeRef VectorTy);
894 * @defgroup LLVMCCoreTypeOther Other Types
900 * Create a void type in a context.
902 LLVMTypeRef LLVMVoidTypeInContext(LLVMContextRef C);
905 * Create a label type in a context.
907 LLVMTypeRef LLVMLabelTypeInContext(LLVMContextRef C);
910 * Create a X86 MMX type in a context.
912 LLVMTypeRef LLVMX86MMXTypeInContext(LLVMContextRef C);
915 * These are similar to the above functions except they operate on the
918 LLVMTypeRef LLVMVoidType(void);
919 LLVMTypeRef LLVMLabelType(void);
920 LLVMTypeRef LLVMX86MMXType(void);
931 * @defgroup LLVMCCoreValues Values
933 * The bulk of LLVM's object model consists of values, which comprise a very
934 * rich type hierarchy.
936 * LLVMValueRef essentially represents llvm::Value. There is a rich
937 * hierarchy of classes within this type. Depending on the instance
938 * obtain, not all APIs are available.
940 * Callers can determine the type of a LLVMValueRef by calling the
941 * LLVMIsA* family of functions (e.g. LLVMIsAArgument()). These
942 * functions are defined by a macro, so it isn't obvious which are
943 * available by looking at the Doxygen source code. Instead, look at the
944 * source definition of LLVM_FOR_EACH_VALUE_SUBCLASS and note the list
945 * of value names given. These value names also correspond to classes in
946 * the llvm::Value hierarchy.
951 #define LLVM_FOR_EACH_VALUE_SUBCLASS(macro) \
959 macro(BlockAddress) \
960 macro(ConstantAggregateZero) \
961 macro(ConstantArray) \
962 macro(ConstantExpr) \
965 macro(ConstantPointerNull) \
966 macro(ConstantStruct) \
967 macro(ConstantVector) \
971 macro(GlobalVariable) \
974 macro(BinaryOperator) \
976 macro(IntrinsicInst) \
977 macro(DbgInfoIntrinsic) \
978 macro(DbgDeclareInst) \
979 macro(MemIntrinsic) \
986 macro(ExtractElementInst) \
987 macro(GetElementPtrInst) \
988 macro(InsertElementInst) \
989 macro(InsertValueInst) \
990 macro(LandingPadInst) \
993 macro(ShuffleVectorInst) \
995 macro(TerminatorInst) \
997 macro(IndirectBrInst) \
1001 macro(UnreachableInst) \
1003 macro(UnaryInstruction) \
1006 macro(BitCastInst) \
1010 macro(FPTruncInst) \
1011 macro(IntToPtrInst) \
1012 macro(PtrToIntInst) \
1018 macro(ExtractValueInst) \
1023 * @defgroup LLVMCCoreValueGeneral General APIs
1025 * Functions in this section work on all LLVMValueRef instances,
1026 * regardless of their sub-type. They correspond to functions available
1033 * Obtain the type of a value.
1035 * @see llvm::Value::getType()
1037 LLVMTypeRef LLVMTypeOf(LLVMValueRef Val);
1040 * Obtain the string name of a value.
1042 * @see llvm::Value::getName()
1044 const char *LLVMGetValueName(LLVMValueRef Val);
1047 * Set the string name of a value.
1049 * @see llvm::Value::setName()
1051 void LLVMSetValueName(LLVMValueRef Val, const char *Name);
1054 * Dump a representation of a value to stderr.
1056 * @see llvm::Value::dump()
1058 void LLVMDumpValue(LLVMValueRef Val);
1061 * Replace all uses of a value with another one.
1063 * @see llvm::Value::replaceAllUsesWith()
1065 void LLVMReplaceAllUsesWith(LLVMValueRef OldVal, LLVMValueRef NewVal);
1068 * Determine whether the specified constant instance is constant.
1070 LLVMBool LLVMIsConstant(LLVMValueRef Val);
1073 * Determine whether a value instance is undefined.
1075 LLVMBool LLVMIsUndef(LLVMValueRef Val);
1078 * Convert value instances between types.
1080 * Internally, a LLVMValueRef is "pinned" to a specific type. This
1081 * series of functions allows you to cast an instance to a specific
1084 * If the cast is not valid for the specified type, NULL is returned.
1086 * @see llvm::dyn_cast_or_null<>
1088 #define LLVM_DECLARE_VALUE_CAST(name) \
1089 LLVMValueRef LLVMIsA##name(LLVMValueRef Val);
1090 LLVM_FOR_EACH_VALUE_SUBCLASS(LLVM_DECLARE_VALUE_CAST)
1097 * @defgroup LLVMCCoreValueUses Usage
1099 * This module defines functions that allow you to inspect the uses of a
1102 * It is possible to obtain a LLVMUseRef for any LLVMValueRef instance.
1103 * Each LLVMUseRef (which corresponds to a llvm::Use instance) holds a
1104 * llvm::User and llvm::Value.
1110 * Obtain the first use of a value.
1112 * Uses are obtained in an iterator fashion. First, call this function
1113 * to obtain a reference to the first use. Then, call LLVMGetNextUse()
1114 * on that instance and all subsequently obtained instances untl
1115 * LLVMGetNextUse() returns NULL.
1117 * @see llvm::Value::use_begin()
1119 LLVMUseRef LLVMGetFirstUse(LLVMValueRef Val);
1122 * Obtain the next use of a value.
1124 * This effectively advances the iterator. It returns NULL if you are on
1125 * the final use and no more are available.
1127 LLVMUseRef LLVMGetNextUse(LLVMUseRef U);
1130 * Obtain the user value for a user.
1132 * The returned value corresponds to a llvm::User type.
1134 * @see llvm::Use::getUser()
1136 LLVMValueRef LLVMGetUser(LLVMUseRef U);
1139 * Obtain the value this use corresponds to.
1141 * @see llvm::Use::get().
1143 LLVMValueRef LLVMGetUsedValue(LLVMUseRef U);
1150 * @defgroup LLVMCValueUser User value
1152 * Function in this group pertain to LLVMValueRef instances that descent
1153 * from llvm::User. This includes constants, instructions, and
1160 * Obtain an operand at a specific index in a llvm::User value.
1162 * @see llvm::User::getOperand()
1164 LLVMValueRef LLVMGetOperand(LLVMValueRef Val, unsigned Index);
1167 * Set an operand at a specific index in a llvm::User value.
1169 * @see llvm::User::setOperand()
1171 void LLVMSetOperand(LLVMValueRef User, unsigned Index, LLVMValueRef Val);
1174 * Obtain the number of operands in a llvm::User value.
1176 * @see llvm::User::getNumOperands()
1178 int LLVMGetNumOperands(LLVMValueRef Val);
1185 * @defgroup LLVMCoreValueConstant Constant values
1187 * This section contains APIs for interacting with LLVMValueRef that
1188 * correspond to llvm::Constant instances.
1190 * These functions will work for any LLVMValueRef in the llvm::Constant
1197 * Obtain a constant value referring to the null instance of a type.
1199 * @see llvm::Constant::getNullValue()
1201 LLVMValueRef LLVMConstNull(LLVMTypeRef Ty); /* all zeroes */
1204 * Obtain a constant value referring to the instance of a type
1205 * consisting of all ones.
1207 * This is only valid for integer types.
1209 * @see llvm::Constant::getAllOnesValue()
1211 LLVMValueRef LLVMConstAllOnes(LLVMTypeRef Ty);
1214 * Obtain a constant value referring to an undefined value of a type.
1216 * @see llvm::UndefValue::get()
1218 LLVMValueRef LLVMGetUndef(LLVMTypeRef Ty);
1221 * Determine whether a value instance is null.
1223 * @see llvm::Constant::isNullValue()
1225 LLVMBool LLVMIsNull(LLVMValueRef Val);
1228 * Obtain a constant that is a constant pointer pointing to NULL for a
1231 LLVMValueRef LLVMConstPointerNull(LLVMTypeRef Ty);
1234 * @defgroup LLVMCCoreValueConstantScalar Scalar constants
1236 * Functions in this group model LLVMValueRef instances that correspond
1237 * to constants referring to scalar types.
1239 * For integer types, the LLVMTypeRef parameter should correspond to a
1240 * llvm::IntegerType instance and the returned LLVMValueRef will
1241 * correspond to a llvm::ConstantInt.
1243 * For floating point types, the LLVMTypeRef returned corresponds to a
1250 * Obtain a constant value for an integer type.
1252 * The returned value corresponds to a llvm::ConstantInt.
1254 * @see llvm::ConstantInt::get()
1256 * @param IntTy Integer type to obtain value of.
1257 * @param N The value the returned instance should refer to.
1258 * @param SignExtend Whether to sign extend the produced value.
1260 LLVMValueRef LLVMConstInt(LLVMTypeRef IntTy, unsigned long long N,
1261 LLVMBool SignExtend);
1264 * Obtain a constant value for an integer of arbitrary precision.
1266 * @see llvm::ConstantInt::get()
1268 LLVMValueRef LLVMConstIntOfArbitraryPrecision(LLVMTypeRef IntTy,
1270 const uint64_t Words[]);
1273 * Obtain a constant value for an integer parsed from a string.
1275 * A similar API, LLVMConstIntOfStringAndSize is also available. If the
1276 * string's length is available, it is preferred to call that function
1279 * @see llvm::ConstantInt::get()
1281 LLVMValueRef LLVMConstIntOfString(LLVMTypeRef IntTy, const char *Text,
1285 * Obtain a constant value for an integer parsed from a string with
1288 * @see llvm::ConstantInt::get()
1290 LLVMValueRef LLVMConstIntOfStringAndSize(LLVMTypeRef IntTy, const char *Text,
1291 unsigned SLen, uint8_t Radix);
1294 * Obtain a constant value referring to a double floating point value.
1296 LLVMValueRef LLVMConstReal(LLVMTypeRef RealTy, double N);
1299 * Obtain a constant for a floating point value parsed from a string.
1301 * A similar API, LLVMConstRealOfStringAndSize is also available. It
1302 * should be used if the input string's length is known.
1304 LLVMValueRef LLVMConstRealOfString(LLVMTypeRef RealTy, const char *Text);
1307 * Obtain a constant for a floating point value parsed from a string.
1309 LLVMValueRef LLVMConstRealOfStringAndSize(LLVMTypeRef RealTy, const char *Text,
1313 * Obtain the zero extended value for an integer constant value.
1315 * @see llvm::ConstantInt::getZExtValue()
1317 unsigned long long LLVMConstIntGetZExtValue(LLVMValueRef ConstantVal);
1320 * Obtain the sign extended value for an integer constant value.
1322 * @see llvm::ConstantInt::getSExtValue()
1324 long long LLVMConstIntGetSExtValue(LLVMValueRef ConstantVal);
1335 * @defgroup LLVMCCoreValueMetadata Metadata
1341 * Obtain a MDString value from a context.
1343 * The returned instance corresponds to the llvm::MDString class.
1345 * The instance is specified by string data of a specified length. The
1346 * string content is copied, so the backing memory can be freed after
1347 * this function returns.
1349 LLVMValueRef LLVMMDStringInContext(LLVMContextRef C, const char *Str,
1353 * Obtain a MDString value from the global context.
1355 LLVMValueRef LLVMMDString(const char *Str, unsigned SLen);
1358 * Obtain a MDNode value from a context.
1360 * The returned value corresponds to the llvm::MDNode class.
1362 LLVMValueRef LLVMMDNodeInContext(LLVMContextRef C, LLVMValueRef *Vals,
1366 * Obtain a MDNode value from the global context.
1368 LLVMValueRef LLVMMDNode(LLVMValueRef *Vals, unsigned Count);
1371 * Obtain the underlying string from a MDString value.
1373 * @param V Instance to obtain string from.
1374 * @param Len Memory address which will hold length of returned string.
1375 * @return String data in MDString.
1377 const char *LLVMGetMDString(LLVMValueRef V, unsigned* Len);
1384 * @defgroup LLVMCCoreValueUNCATEGORIZED UNCATEGORIZED
1386 * Functions in this group are not yet categorized. They belong
1387 * somewhere else and will be organized there in the future. Perhaps you
1388 * can help by submitting a patch to the documentation.
1393 /* Operations on composite constants */
1394 LLVMValueRef LLVMConstStringInContext(LLVMContextRef C, const char *Str,
1395 unsigned Length, LLVMBool DontNullTerminate);
1396 LLVMValueRef LLVMConstStructInContext(LLVMContextRef C,
1397 LLVMValueRef *ConstantVals,
1398 unsigned Count, LLVMBool Packed);
1400 LLVMValueRef LLVMConstString(const char *Str, unsigned Length,
1401 LLVMBool DontNullTerminate);
1402 LLVMValueRef LLVMConstArray(LLVMTypeRef ElementTy,
1403 LLVMValueRef *ConstantVals, unsigned Length);
1404 LLVMValueRef LLVMConstStruct(LLVMValueRef *ConstantVals, unsigned Count,
1406 LLVMValueRef LLVMConstNamedStruct(LLVMTypeRef StructTy,
1407 LLVMValueRef *ConstantVals,
1409 LLVMValueRef LLVMConstVector(LLVMValueRef *ScalarConstantVals, unsigned Size);
1411 /* Constant expressions */
1412 LLVMOpcode LLVMGetConstOpcode(LLVMValueRef ConstantVal);
1413 LLVMValueRef LLVMAlignOf(LLVMTypeRef Ty);
1414 LLVMValueRef LLVMSizeOf(LLVMTypeRef Ty);
1415 LLVMValueRef LLVMConstNeg(LLVMValueRef ConstantVal);
1416 LLVMValueRef LLVMConstNSWNeg(LLVMValueRef ConstantVal);
1417 LLVMValueRef LLVMConstNUWNeg(LLVMValueRef ConstantVal);
1418 LLVMValueRef LLVMConstFNeg(LLVMValueRef ConstantVal);
1419 LLVMValueRef LLVMConstNot(LLVMValueRef ConstantVal);
1420 LLVMValueRef LLVMConstAdd(LLVMValueRef LHSConstant, LLVMValueRef RHSConstant);
1421 LLVMValueRef LLVMConstNSWAdd(LLVMValueRef LHSConstant, LLVMValueRef RHSConstant);
1422 LLVMValueRef LLVMConstNUWAdd(LLVMValueRef LHSConstant, LLVMValueRef RHSConstant);
1423 LLVMValueRef LLVMConstFAdd(LLVMValueRef LHSConstant, LLVMValueRef RHSConstant);
1424 LLVMValueRef LLVMConstSub(LLVMValueRef LHSConstant, LLVMValueRef RHSConstant);
1425 LLVMValueRef LLVMConstNSWSub(LLVMValueRef LHSConstant, LLVMValueRef RHSConstant);
1426 LLVMValueRef LLVMConstNUWSub(LLVMValueRef LHSConstant, LLVMValueRef RHSConstant);
1427 LLVMValueRef LLVMConstFSub(LLVMValueRef LHSConstant, LLVMValueRef RHSConstant);
1428 LLVMValueRef LLVMConstMul(LLVMValueRef LHSConstant, LLVMValueRef RHSConstant);
1429 LLVMValueRef LLVMConstNSWMul(LLVMValueRef LHSConstant, LLVMValueRef RHSConstant);
1430 LLVMValueRef LLVMConstNUWMul(LLVMValueRef LHSConstant, LLVMValueRef RHSConstant);
1431 LLVMValueRef LLVMConstFMul(LLVMValueRef LHSConstant, LLVMValueRef RHSConstant);
1432 LLVMValueRef LLVMConstUDiv(LLVMValueRef LHSConstant, LLVMValueRef RHSConstant);
1433 LLVMValueRef LLVMConstSDiv(LLVMValueRef LHSConstant, LLVMValueRef RHSConstant);
1434 LLVMValueRef LLVMConstExactSDiv(LLVMValueRef LHSConstant, LLVMValueRef RHSConstant);
1435 LLVMValueRef LLVMConstFDiv(LLVMValueRef LHSConstant, LLVMValueRef RHSConstant);
1436 LLVMValueRef LLVMConstURem(LLVMValueRef LHSConstant, LLVMValueRef RHSConstant);
1437 LLVMValueRef LLVMConstSRem(LLVMValueRef LHSConstant, LLVMValueRef RHSConstant);
1438 LLVMValueRef LLVMConstFRem(LLVMValueRef LHSConstant, LLVMValueRef RHSConstant);
1439 LLVMValueRef LLVMConstAnd(LLVMValueRef LHSConstant, LLVMValueRef RHSConstant);
1440 LLVMValueRef LLVMConstOr(LLVMValueRef LHSConstant, LLVMValueRef RHSConstant);
1441 LLVMValueRef LLVMConstXor(LLVMValueRef LHSConstant, LLVMValueRef RHSConstant);
1442 LLVMValueRef LLVMConstICmp(LLVMIntPredicate Predicate,
1443 LLVMValueRef LHSConstant, LLVMValueRef RHSConstant);
1444 LLVMValueRef LLVMConstFCmp(LLVMRealPredicate Predicate,
1445 LLVMValueRef LHSConstant, LLVMValueRef RHSConstant);
1446 LLVMValueRef LLVMConstShl(LLVMValueRef LHSConstant, LLVMValueRef RHSConstant);
1447 LLVMValueRef LLVMConstLShr(LLVMValueRef LHSConstant, LLVMValueRef RHSConstant);
1448 LLVMValueRef LLVMConstAShr(LLVMValueRef LHSConstant, LLVMValueRef RHSConstant);
1449 LLVMValueRef LLVMConstGEP(LLVMValueRef ConstantVal,
1450 LLVMValueRef *ConstantIndices, unsigned NumIndices);
1451 LLVMValueRef LLVMConstInBoundsGEP(LLVMValueRef ConstantVal,
1452 LLVMValueRef *ConstantIndices,
1453 unsigned NumIndices);
1454 LLVMValueRef LLVMConstTrunc(LLVMValueRef ConstantVal, LLVMTypeRef ToType);
1455 LLVMValueRef LLVMConstSExt(LLVMValueRef ConstantVal, LLVMTypeRef ToType);
1456 LLVMValueRef LLVMConstZExt(LLVMValueRef ConstantVal, LLVMTypeRef ToType);
1457 LLVMValueRef LLVMConstFPTrunc(LLVMValueRef ConstantVal, LLVMTypeRef ToType);
1458 LLVMValueRef LLVMConstFPExt(LLVMValueRef ConstantVal, LLVMTypeRef ToType);
1459 LLVMValueRef LLVMConstUIToFP(LLVMValueRef ConstantVal, LLVMTypeRef ToType);
1460 LLVMValueRef LLVMConstSIToFP(LLVMValueRef ConstantVal, LLVMTypeRef ToType);
1461 LLVMValueRef LLVMConstFPToUI(LLVMValueRef ConstantVal, LLVMTypeRef ToType);
1462 LLVMValueRef LLVMConstFPToSI(LLVMValueRef ConstantVal, LLVMTypeRef ToType);
1463 LLVMValueRef LLVMConstPtrToInt(LLVMValueRef ConstantVal, LLVMTypeRef ToType);
1464 LLVMValueRef LLVMConstIntToPtr(LLVMValueRef ConstantVal, LLVMTypeRef ToType);
1465 LLVMValueRef LLVMConstBitCast(LLVMValueRef ConstantVal, LLVMTypeRef ToType);
1466 LLVMValueRef LLVMConstZExtOrBitCast(LLVMValueRef ConstantVal,
1467 LLVMTypeRef ToType);
1468 LLVMValueRef LLVMConstSExtOrBitCast(LLVMValueRef ConstantVal,
1469 LLVMTypeRef ToType);
1470 LLVMValueRef LLVMConstTruncOrBitCast(LLVMValueRef ConstantVal,
1471 LLVMTypeRef ToType);
1472 LLVMValueRef LLVMConstPointerCast(LLVMValueRef ConstantVal,
1473 LLVMTypeRef ToType);
1474 LLVMValueRef LLVMConstIntCast(LLVMValueRef ConstantVal, LLVMTypeRef ToType,
1476 LLVMValueRef LLVMConstFPCast(LLVMValueRef ConstantVal, LLVMTypeRef ToType);
1477 LLVMValueRef LLVMConstSelect(LLVMValueRef ConstantCondition,
1478 LLVMValueRef ConstantIfTrue,
1479 LLVMValueRef ConstantIfFalse);
1480 LLVMValueRef LLVMConstExtractElement(LLVMValueRef VectorConstant,
1481 LLVMValueRef IndexConstant);
1482 LLVMValueRef LLVMConstInsertElement(LLVMValueRef VectorConstant,
1483 LLVMValueRef ElementValueConstant,
1484 LLVMValueRef IndexConstant);
1485 LLVMValueRef LLVMConstShuffleVector(LLVMValueRef VectorAConstant,
1486 LLVMValueRef VectorBConstant,
1487 LLVMValueRef MaskConstant);
1488 LLVMValueRef LLVMConstExtractValue(LLVMValueRef AggConstant, unsigned *IdxList,
1490 LLVMValueRef LLVMConstInsertValue(LLVMValueRef AggConstant,
1491 LLVMValueRef ElementValueConstant,
1492 unsigned *IdxList, unsigned NumIdx);
1493 LLVMValueRef LLVMConstInlineAsm(LLVMTypeRef Ty,
1494 const char *AsmString, const char *Constraints,
1495 LLVMBool HasSideEffects, LLVMBool IsAlignStack);
1496 LLVMValueRef LLVMBlockAddress(LLVMValueRef F, LLVMBasicBlockRef BB);
1498 /* Operations on global variables, functions, and aliases (globals) */
1499 LLVMModuleRef LLVMGetGlobalParent(LLVMValueRef Global);
1500 LLVMBool LLVMIsDeclaration(LLVMValueRef Global);
1501 LLVMLinkage LLVMGetLinkage(LLVMValueRef Global);
1502 void LLVMSetLinkage(LLVMValueRef Global, LLVMLinkage Linkage);
1503 const char *LLVMGetSection(LLVMValueRef Global);
1504 void LLVMSetSection(LLVMValueRef Global, const char *Section);
1505 LLVMVisibility LLVMGetVisibility(LLVMValueRef Global);
1506 void LLVMSetVisibility(LLVMValueRef Global, LLVMVisibility Viz);
1507 unsigned LLVMGetAlignment(LLVMValueRef Global);
1508 void LLVMSetAlignment(LLVMValueRef Global, unsigned Bytes);
1510 /* Operations on global variables */
1511 LLVMValueRef LLVMAddGlobal(LLVMModuleRef M, LLVMTypeRef Ty, const char *Name);
1512 LLVMValueRef LLVMAddGlobalInAddressSpace(LLVMModuleRef M, LLVMTypeRef Ty,
1514 unsigned AddressSpace);
1515 LLVMValueRef LLVMGetNamedGlobal(LLVMModuleRef M, const char *Name);
1516 LLVMValueRef LLVMGetFirstGlobal(LLVMModuleRef M);
1517 LLVMValueRef LLVMGetLastGlobal(LLVMModuleRef M);
1518 LLVMValueRef LLVMGetNextGlobal(LLVMValueRef GlobalVar);
1519 LLVMValueRef LLVMGetPreviousGlobal(LLVMValueRef GlobalVar);
1520 void LLVMDeleteGlobal(LLVMValueRef GlobalVar);
1521 LLVMValueRef LLVMGetInitializer(LLVMValueRef GlobalVar);
1522 void LLVMSetInitializer(LLVMValueRef GlobalVar, LLVMValueRef ConstantVal);
1523 LLVMBool LLVMIsThreadLocal(LLVMValueRef GlobalVar);
1524 void LLVMSetThreadLocal(LLVMValueRef GlobalVar, LLVMBool IsThreadLocal);
1525 LLVMBool LLVMIsGlobalConstant(LLVMValueRef GlobalVar);
1526 void LLVMSetGlobalConstant(LLVMValueRef GlobalVar, LLVMBool IsConstant);
1528 /* Operations on aliases */
1529 LLVMValueRef LLVMAddAlias(LLVMModuleRef M, LLVMTypeRef Ty, LLVMValueRef Aliasee,
1532 /* Operations on functions */
1533 LLVMValueRef LLVMAddFunction(LLVMModuleRef M, const char *Name,
1534 LLVMTypeRef FunctionTy);
1535 LLVMValueRef LLVMGetNamedFunction(LLVMModuleRef M, const char *Name);
1536 LLVMValueRef LLVMGetFirstFunction(LLVMModuleRef M);
1537 LLVMValueRef LLVMGetLastFunction(LLVMModuleRef M);
1538 LLVMValueRef LLVMGetNextFunction(LLVMValueRef Fn);
1539 LLVMValueRef LLVMGetPreviousFunction(LLVMValueRef Fn);
1546 * @defgroup LLVMCCoreValueFunction Function values
1548 * Functions in this group operate on LLVMValueRef instances that
1549 * correspond to llvm::Function instances.
1551 * @see llvm::Function
1557 * Remove a function from its containing module and deletes it.
1559 * @see llvm::Function::eraseFromParent()
1561 void LLVMDeleteFunction(LLVMValueRef Fn);
1564 * Obtain the ID number from a function instance.
1566 * @see llvm::Function::getIntrinsicID()
1568 unsigned LLVMGetIntrinsicID(LLVMValueRef Fn);
1571 * Obtain the calling function of a function.
1573 * The returned value corresponds to the LLVMCallConv enumeration.
1575 * @see llvm::Function::getCallingConv()
1577 unsigned LLVMGetFunctionCallConv(LLVMValueRef Fn);
1580 * Set the calling convention of a function.
1582 * @see llvm::Function::setCallingConv()
1584 * @param Fn Function to operate on
1585 * @param CC LLVMCallConv to set calling convention to
1587 void LLVMSetFunctionCallConv(LLVMValueRef Fn, unsigned CC);
1590 * Obtain the name of the garbage collector to use during code
1593 * @see llvm::Function::getGC()
1595 const char *LLVMGetGC(LLVMValueRef Fn);
1598 * Define the garbage collector to use during code generation.
1600 * @see llvm::Function::setGC()
1602 void LLVMSetGC(LLVMValueRef Fn, const char *Name);
1605 * Add an attribute to a function.
1607 * @see llvm::Function::addAttribute()
1609 void LLVMAddFunctionAttr(LLVMValueRef Fn, LLVMAttribute PA);
1612 * Obtain an attribute from a function.
1614 * @see llvm::Function::getAttributes()
1616 LLVMAttribute LLVMGetFunctionAttr(LLVMValueRef Fn);
1619 * Remove an attribute from a function.
1621 void LLVMRemoveFunctionAttr(LLVMValueRef Fn, LLVMAttribute PA);
1624 * @defgroup LLVMCCoreValueFunctionParameters Function Parameters
1626 * Functions in this group relate to arguments/parameters on functions.
1628 * Functions in this group expect LLVMValueRef instances that correspond
1629 * to llvm::Function instances.
1635 * Obtain the number of parameters in a function.
1637 * @see llvm::Function::arg_size()
1639 unsigned LLVMCountParams(LLVMValueRef Fn);
1642 * Obtain the parameters in a function.
1644 * The takes a pointer to a pre-allocated array of LLVMValueRef that is
1645 * at least LLVMCountParams() long. This array will be filled with
1646 * LLVMValueRef instances which correspond to the parameters the
1647 * function receives. Each LLVMValueRef corresponds to a llvm::Argument
1650 * @see llvm::Function::arg_begin()
1652 void LLVMGetParams(LLVMValueRef Fn, LLVMValueRef *Params);
1655 * Obtain the parameter at the specified index.
1657 * Parameters are indexed from 0.
1659 * @see llvm::Function::arg_begin()
1661 LLVMValueRef LLVMGetParam(LLVMValueRef Fn, unsigned Index);
1664 * Obtain the function to which this argument belongs.
1666 * Unlike other functions in this group, this one takes a LLVMValueRef
1667 * that corresponds to a llvm::Attribute.
1669 * The returned LLVMValueRef is the llvm::Function to which this
1672 LLVMValueRef LLVMGetParamParent(LLVMValueRef Inst);
1675 * Obtain the first parameter to a function.
1677 * @see llvm::Function::arg_begin()
1679 LLVMValueRef LLVMGetFirstParam(LLVMValueRef Fn);
1682 * Obtain the last parameter to a function.
1684 * @see llvm::Function::arg_end()
1686 LLVMValueRef LLVMGetLastParam(LLVMValueRef Fn);
1689 * Obtain the next parameter to a function.
1691 * This takes a LLVMValueRef obtained from LLVMGetFirstParam() (which is
1692 * actually a wrapped iterator) and obtains the next parameter from the
1693 * underlying iterator.
1695 LLVMValueRef LLVMGetNextParam(LLVMValueRef Arg);
1698 * Obtain the previous parameter to a function.
1700 * This is the opposite of LLVMGetNextParam().
1702 LLVMValueRef LLVMGetPreviousParam(LLVMValueRef Arg);
1705 * Add an attribute to a function argument.
1707 * @see llvm::Argument::addAttr()
1709 void LLVMAddAttribute(LLVMValueRef Arg, LLVMAttribute PA);
1712 * Remove an attribute from a function argument.
1714 * @see llvm::Argument::removeAttr()
1716 void LLVMRemoveAttribute(LLVMValueRef Arg, LLVMAttribute PA);
1719 * Get an attribute from a function argument.
1721 LLVMAttribute LLVMGetAttribute(LLVMValueRef Arg);
1724 * Set the alignment for a function parameter.
1726 * @see llvm::Argument::addAttr()
1727 * @see llvm::Attribute::constructAlignmentFromInt()
1729 void LLVMSetParamAlignment(LLVMValueRef Arg, unsigned align);
1740 * @defgroup LLVMCCoreValueBasicBlock Basic Block
1742 * A basic block represents a single entry single exit section of code.
1743 * Basic blocks contain a list of instructions which form the body of
1746 * Basic blocks belong to functions. They have the type of label.
1748 * Basic blocks are themselves values. However, the C API models them as
1749 * LLVMBasicBlockRef.
1751 * @see llvm::BasicBlock
1757 * Convert a basic block instance to a value type.
1759 LLVMValueRef LLVMBasicBlockAsValue(LLVMBasicBlockRef BB);
1762 * Determine whether a LLVMValueRef is itself a basic block.
1764 LLVMBool LLVMValueIsBasicBlock(LLVMValueRef Val);
1767 * Convert a LLVMValueRef to a LLVMBasicBlockRef instance.
1769 LLVMBasicBlockRef LLVMValueAsBasicBlock(LLVMValueRef Val);
1772 * Obtain the function to which a basic block belongs.
1774 * @see llvm::BasicBlock::getParent()
1776 LLVMValueRef LLVMGetBasicBlockParent(LLVMBasicBlockRef BB);
1779 * Obtain the terminator instruction for a basic block.
1781 * If the basic block does not have a terminator (it is not well-formed
1782 * if it doesn't), then NULL is returned.
1784 * The returned LLVMValueRef corresponds to a llvm::TerminatorInst.
1786 * @see llvm::BasicBlock::getTerminator()
1788 LLVMValueRef LLVMGetBasicBlockTerminator(LLVMBasicBlockRef BB);
1791 * Obtain the number of basic blocks in a function.
1793 * @param Fn Function value to operate on.
1795 unsigned LLVMCountBasicBlocks(LLVMValueRef Fn);
1798 * Obtain all of the basic blocks in a function.
1800 * This operates on a function value. The BasicBlocks parameter is a
1801 * pointer to a pre-allocated array of LLVMBasicBlockRef of at least
1802 * LLVMCountBasicBlocks() in length. This array is populated with
1803 * LLVMBasicBlockRef instances.
1805 void LLVMGetBasicBlocks(LLVMValueRef Fn, LLVMBasicBlockRef *BasicBlocks);
1808 * Obtain the first basic block in a function.
1810 * The returned basic block can be used as an iterator. You will likely
1811 * eventually call into LLVMGetNextBasicBlock() with it.
1813 * @see llvm::Function::begin()
1815 LLVMBasicBlockRef LLVMGetFirstBasicBlock(LLVMValueRef Fn);
1818 * Obtain the last basic block in a function.
1820 * @see llvm::Function::end()
1822 LLVMBasicBlockRef LLVMGetLastBasicBlock(LLVMValueRef Fn);
1825 * Advance a basic block iterator.
1827 LLVMBasicBlockRef LLVMGetNextBasicBlock(LLVMBasicBlockRef BB);
1830 * Go backwards in a basic block iterator.
1832 LLVMBasicBlockRef LLVMGetPreviousBasicBlock(LLVMBasicBlockRef BB);
1835 * Obtain the basic block that corresponds to the entry point of a
1838 * @see llvm::Function::getEntryBlock()
1840 LLVMBasicBlockRef LLVMGetEntryBasicBlock(LLVMValueRef Fn);
1843 * Append a basic block to the end of a function.
1845 * @see llvm::BasicBlock::Create()
1847 LLVMBasicBlockRef LLVMAppendBasicBlockInContext(LLVMContextRef C,
1852 * Append a basic block to the end of a function using the global
1855 * @see llvm::BasicBlock::Create()
1857 LLVMBasicBlockRef LLVMAppendBasicBlock(LLVMValueRef Fn, const char *Name);
1860 * Insert a basic block in a function before another basic block.
1862 * The function to add to is determined by the function of the
1863 * passed basic block.
1865 * @see llvm::BasicBlock::Create()
1867 LLVMBasicBlockRef LLVMInsertBasicBlockInContext(LLVMContextRef C,
1868 LLVMBasicBlockRef BB,
1872 * Insert a basic block in a function using the global context.
1874 * @see llvm::BasicBlock::Create()
1876 LLVMBasicBlockRef LLVMInsertBasicBlock(LLVMBasicBlockRef InsertBeforeBB,
1880 * Remove a basic block from a function and delete it.
1882 * This deletes the basic block from its containing function and deletes
1883 * the basic block itself.
1885 * @see llvm::BasicBlock::eraseFromParent()
1887 void LLVMDeleteBasicBlock(LLVMBasicBlockRef BB);
1890 * Remove a basic block from a function.
1892 * This deletes the basic block from its containing function but keep
1893 * the basic block alive.
1895 * @see llvm::BasicBlock::removeFromParent()
1897 void LLVMRemoveBasicBlockFromParent(LLVMBasicBlockRef BB);
1900 * Move a basic block to before another one.
1902 * @see llvm::BasicBlock::moveBefore()
1904 void LLVMMoveBasicBlockBefore(LLVMBasicBlockRef BB, LLVMBasicBlockRef MovePos);
1907 * Move a basic block to after another one.
1909 * @see llvm::BasicBlock::moveAfter()
1911 void LLVMMoveBasicBlockAfter(LLVMBasicBlockRef BB, LLVMBasicBlockRef MovePos);
1914 * Obtain the first instruction in a basic block.
1916 * The returned LLVMValueRef corresponds to a llvm::Instruction
1919 LLVMValueRef LLVMGetFirstInstruction(LLVMBasicBlockRef BB);
1922 * Obtain the last instruction in a basic block.
1924 * The returned LLVMValueRef corresponds to a LLVM:Instruction.
1926 LLVMValueRef LLVMGetLastInstruction(LLVMBasicBlockRef BB);
1933 * @defgroup LLVMCCoreValueInstruction Instructions
1935 * Functions in this group relate to the inspection and manipulation of
1936 * individual instructions.
1938 * In the C++ API, an instruction is modeled by llvm::Instruction. This
1939 * class has a large number of descendents. llvm::Instruction is a
1940 * llvm::Value and in the C API, instructions are modeled by
1943 * This group also contains sub-groups which operate on specific
1944 * llvm::Instruction types, e.g. llvm::CallInst.
1950 * Determine whether an instruction has any metadata attached.
1952 int LLVMHasMetadata(LLVMValueRef Val);
1955 * Return metadata associated with an instruction value.
1957 LLVMValueRef LLVMGetMetadata(LLVMValueRef Val, unsigned KindID);
1960 * Set metadata associated with an instruction value.
1962 void LLVMSetMetadata(LLVMValueRef Val, unsigned KindID, LLVMValueRef Node);
1965 * Obtain the basic block to which an instruction belongs.
1967 * @see llvm::Instruction::getParent()
1969 LLVMBasicBlockRef LLVMGetInstructionParent(LLVMValueRef Inst);
1972 * Obtain the instruction that occurs after the one specified.
1974 * The next instruction will be from the same basic block.
1976 * If this is the last instruction in a basic block, NULL will be
1979 LLVMValueRef LLVMGetNextInstruction(LLVMValueRef Inst);
1982 * Obtain the instruction that occured before this one.
1984 * If the instruction is the first instruction in a basic block, NULL
1987 LLVMValueRef LLVMGetPreviousInstruction(LLVMValueRef Inst);
1990 * Remove and delete an instruction.
1992 * The instruction specified is removed from its containing building
1993 * block and then deleted.
1995 * @see llvm::Instruction::eraseFromParent()
1997 void LLVMInstructionEraseFromParent(LLVMValueRef Inst);
2000 * Obtain the code opcode for an individual instruction.
2002 * @see llvm::Instruction::getOpCode()
2004 LLVMOpcode LLVMGetInstructionOpcode(LLVMValueRef Inst);
2007 * Obtain the predicate of an instruction.
2009 * This is only valid for instructions that correspond to llvm::ICmpInst
2010 * or llvm::ConstantExpr whose opcode is llvm::Instruction::ICmp.
2012 * @see llvm::ICmpInst::getPredicate()
2014 LLVMIntPredicate LLVMGetICmpPredicate(LLVMValueRef Inst);
2017 * @defgroup LLVMCCoreValueInstructionCall Call Sites and Invocations
2019 * Functions in this group apply to instructions that refer to call
2020 * sites and invocations. These correspond to C++ types in the
2021 * llvm::CallInst class tree.
2027 * Set the calling convention for a call instruction.
2029 * This expects an LLVMValueRef that corresponds to a llvm::CallInst or
2032 * @see llvm::CallInst::setCallingConv()
2033 * @see llvm::InvokeInst::setCallingConv()
2035 void LLVMSetInstructionCallConv(LLVMValueRef Instr, unsigned CC);
2038 * Obtain the calling convention for a call instruction.
2040 * This is the opposite of LLVMSetInstructionCallConv(). Reads its
2043 * @see LLVMSetInstructionCallConv()
2045 unsigned LLVMGetInstructionCallConv(LLVMValueRef Instr);
2048 void LLVMAddInstrAttribute(LLVMValueRef Instr, unsigned index, LLVMAttribute);
2049 void LLVMRemoveInstrAttribute(LLVMValueRef Instr, unsigned index,
2051 void LLVMSetInstrParamAlignment(LLVMValueRef Instr, unsigned index,
2055 * Obtain whether a call instruction is a tail call.
2057 * This only works on llvm::CallInst instructions.
2059 * @see llvm::CallInst::isTailCall()
2061 LLVMBool LLVMIsTailCall(LLVMValueRef CallInst);
2064 * Set whether a call instruction is a tail call.
2066 * This only works on llvm::CallInst instructions.
2068 * @see llvm::CallInst::setTailCall()
2070 void LLVMSetTailCall(LLVMValueRef CallInst, LLVMBool IsTailCall);
2077 * Obtain the default destination basic block of a switch instruction.
2079 * This only works on llvm::SwitchInst instructions.
2081 * @see llvm::SwitchInst::getDefaultDest()
2083 LLVMBasicBlockRef LLVMGetSwitchDefaultDest(LLVMValueRef SwitchInstr);
2086 * @defgroup LLVMCCoreValueInstructionPHINode PHI Nodes
2088 * Functions in this group only apply to instructions that map to
2089 * llvm::PHINode instances.
2095 * Add an incoming value to the end of a PHI list.
2097 void LLVMAddIncoming(LLVMValueRef PhiNode, LLVMValueRef *IncomingValues,
2098 LLVMBasicBlockRef *IncomingBlocks, unsigned Count);
2101 * Obtain the number of incoming basic blocks to a PHI node.
2103 unsigned LLVMCountIncoming(LLVMValueRef PhiNode);
2106 * Obtain an incoming value to a PHI node as a LLVMValueRef.
2108 LLVMValueRef LLVMGetIncomingValue(LLVMValueRef PhiNode, unsigned Index);
2111 * Obtain an incoming value to a PHI node as a LLVMBasicBlockRef.
2113 LLVMBasicBlockRef LLVMGetIncomingBlock(LLVMValueRef PhiNode, unsigned Index);
2128 * @defgroup LLVMCCoreInstructionBuilder Instruction Builders
2130 * An instruction builder represents a point within a basic block and is
2131 * the exclusive means of building instructions using the C interface.
2136 LLVMBuilderRef LLVMCreateBuilderInContext(LLVMContextRef C);
2137 LLVMBuilderRef LLVMCreateBuilder(void);
2138 void LLVMPositionBuilder(LLVMBuilderRef Builder, LLVMBasicBlockRef Block,
2139 LLVMValueRef Instr);
2140 void LLVMPositionBuilderBefore(LLVMBuilderRef Builder, LLVMValueRef Instr);
2141 void LLVMPositionBuilderAtEnd(LLVMBuilderRef Builder, LLVMBasicBlockRef Block);
2142 LLVMBasicBlockRef LLVMGetInsertBlock(LLVMBuilderRef Builder);
2143 void LLVMClearInsertionPosition(LLVMBuilderRef Builder);
2144 void LLVMInsertIntoBuilder(LLVMBuilderRef Builder, LLVMValueRef Instr);
2145 void LLVMInsertIntoBuilderWithName(LLVMBuilderRef Builder, LLVMValueRef Instr,
2147 void LLVMDisposeBuilder(LLVMBuilderRef Builder);
2150 void LLVMSetCurrentDebugLocation(LLVMBuilderRef Builder, LLVMValueRef L);
2151 LLVMValueRef LLVMGetCurrentDebugLocation(LLVMBuilderRef Builder);
2152 void LLVMSetInstDebugLocation(LLVMBuilderRef Builder, LLVMValueRef Inst);
2155 LLVMValueRef LLVMBuildRetVoid(LLVMBuilderRef);
2156 LLVMValueRef LLVMBuildRet(LLVMBuilderRef, LLVMValueRef V);
2157 LLVMValueRef LLVMBuildAggregateRet(LLVMBuilderRef, LLVMValueRef *RetVals,
2159 LLVMValueRef LLVMBuildBr(LLVMBuilderRef, LLVMBasicBlockRef Dest);
2160 LLVMValueRef LLVMBuildCondBr(LLVMBuilderRef, LLVMValueRef If,
2161 LLVMBasicBlockRef Then, LLVMBasicBlockRef Else);
2162 LLVMValueRef LLVMBuildSwitch(LLVMBuilderRef, LLVMValueRef V,
2163 LLVMBasicBlockRef Else, unsigned NumCases);
2164 LLVMValueRef LLVMBuildIndirectBr(LLVMBuilderRef B, LLVMValueRef Addr,
2166 LLVMValueRef LLVMBuildInvoke(LLVMBuilderRef, LLVMValueRef Fn,
2167 LLVMValueRef *Args, unsigned NumArgs,
2168 LLVMBasicBlockRef Then, LLVMBasicBlockRef Catch,
2170 LLVMValueRef LLVMBuildLandingPad(LLVMBuilderRef B, LLVMTypeRef Ty,
2171 LLVMValueRef PersFn, unsigned NumClauses,
2173 LLVMValueRef LLVMBuildResume(LLVMBuilderRef B, LLVMValueRef Exn);
2174 LLVMValueRef LLVMBuildUnreachable(LLVMBuilderRef);
2176 /* Add a case to the switch instruction */
2177 void LLVMAddCase(LLVMValueRef Switch, LLVMValueRef OnVal,
2178 LLVMBasicBlockRef Dest);
2180 /* Add a destination to the indirectbr instruction */
2181 void LLVMAddDestination(LLVMValueRef IndirectBr, LLVMBasicBlockRef Dest);
2183 /* Add a catch or filter clause to the landingpad instruction */
2184 void LLVMAddClause(LLVMValueRef LandingPad, LLVMValueRef ClauseVal);
2186 /* Set the 'cleanup' flag in the landingpad instruction */
2187 void LLVMSetCleanup(LLVMValueRef LandingPad, LLVMBool Val);
2190 LLVMValueRef LLVMBuildAdd(LLVMBuilderRef, LLVMValueRef LHS, LLVMValueRef RHS,
2192 LLVMValueRef LLVMBuildNSWAdd(LLVMBuilderRef, LLVMValueRef LHS, LLVMValueRef RHS,
2194 LLVMValueRef LLVMBuildNUWAdd(LLVMBuilderRef, LLVMValueRef LHS, LLVMValueRef RHS,
2196 LLVMValueRef LLVMBuildFAdd(LLVMBuilderRef, LLVMValueRef LHS, LLVMValueRef RHS,
2198 LLVMValueRef LLVMBuildSub(LLVMBuilderRef, LLVMValueRef LHS, LLVMValueRef RHS,
2200 LLVMValueRef LLVMBuildNSWSub(LLVMBuilderRef, LLVMValueRef LHS, LLVMValueRef RHS,
2202 LLVMValueRef LLVMBuildNUWSub(LLVMBuilderRef, LLVMValueRef LHS, LLVMValueRef RHS,
2204 LLVMValueRef LLVMBuildFSub(LLVMBuilderRef, LLVMValueRef LHS, LLVMValueRef RHS,
2206 LLVMValueRef LLVMBuildMul(LLVMBuilderRef, LLVMValueRef LHS, LLVMValueRef RHS,
2208 LLVMValueRef LLVMBuildNSWMul(LLVMBuilderRef, LLVMValueRef LHS, LLVMValueRef RHS,
2210 LLVMValueRef LLVMBuildNUWMul(LLVMBuilderRef, LLVMValueRef LHS, LLVMValueRef RHS,
2212 LLVMValueRef LLVMBuildFMul(LLVMBuilderRef, LLVMValueRef LHS, LLVMValueRef RHS,
2214 LLVMValueRef LLVMBuildUDiv(LLVMBuilderRef, LLVMValueRef LHS, LLVMValueRef RHS,
2216 LLVMValueRef LLVMBuildSDiv(LLVMBuilderRef, LLVMValueRef LHS, LLVMValueRef RHS,
2218 LLVMValueRef LLVMBuildExactSDiv(LLVMBuilderRef, LLVMValueRef LHS, LLVMValueRef RHS,
2220 LLVMValueRef LLVMBuildFDiv(LLVMBuilderRef, LLVMValueRef LHS, LLVMValueRef RHS,
2222 LLVMValueRef LLVMBuildURem(LLVMBuilderRef, LLVMValueRef LHS, LLVMValueRef RHS,
2224 LLVMValueRef LLVMBuildSRem(LLVMBuilderRef, LLVMValueRef LHS, LLVMValueRef RHS,
2226 LLVMValueRef LLVMBuildFRem(LLVMBuilderRef, LLVMValueRef LHS, LLVMValueRef RHS,
2228 LLVMValueRef LLVMBuildShl(LLVMBuilderRef, LLVMValueRef LHS, LLVMValueRef RHS,
2230 LLVMValueRef LLVMBuildLShr(LLVMBuilderRef, LLVMValueRef LHS, LLVMValueRef RHS,
2232 LLVMValueRef LLVMBuildAShr(LLVMBuilderRef, LLVMValueRef LHS, LLVMValueRef RHS,
2234 LLVMValueRef LLVMBuildAnd(LLVMBuilderRef, LLVMValueRef LHS, LLVMValueRef RHS,
2236 LLVMValueRef LLVMBuildOr(LLVMBuilderRef, LLVMValueRef LHS, LLVMValueRef RHS,
2238 LLVMValueRef LLVMBuildXor(LLVMBuilderRef, LLVMValueRef LHS, LLVMValueRef RHS,
2240 LLVMValueRef LLVMBuildBinOp(LLVMBuilderRef B, LLVMOpcode Op,
2241 LLVMValueRef LHS, LLVMValueRef RHS,
2243 LLVMValueRef LLVMBuildNeg(LLVMBuilderRef, LLVMValueRef V, const char *Name);
2244 LLVMValueRef LLVMBuildNSWNeg(LLVMBuilderRef B, LLVMValueRef V,
2246 LLVMValueRef LLVMBuildNUWNeg(LLVMBuilderRef B, LLVMValueRef V,
2248 LLVMValueRef LLVMBuildFNeg(LLVMBuilderRef, LLVMValueRef V, const char *Name);
2249 LLVMValueRef LLVMBuildNot(LLVMBuilderRef, LLVMValueRef V, const char *Name);
2252 LLVMValueRef LLVMBuildMalloc(LLVMBuilderRef, LLVMTypeRef Ty, const char *Name);
2253 LLVMValueRef LLVMBuildArrayMalloc(LLVMBuilderRef, LLVMTypeRef Ty,
2254 LLVMValueRef Val, const char *Name);
2255 LLVMValueRef LLVMBuildAlloca(LLVMBuilderRef, LLVMTypeRef Ty, const char *Name);
2256 LLVMValueRef LLVMBuildArrayAlloca(LLVMBuilderRef, LLVMTypeRef Ty,
2257 LLVMValueRef Val, const char *Name);
2258 LLVMValueRef LLVMBuildFree(LLVMBuilderRef, LLVMValueRef PointerVal);
2259 LLVMValueRef LLVMBuildLoad(LLVMBuilderRef, LLVMValueRef PointerVal,
2261 LLVMValueRef LLVMBuildStore(LLVMBuilderRef, LLVMValueRef Val, LLVMValueRef Ptr);
2262 LLVMValueRef LLVMBuildGEP(LLVMBuilderRef B, LLVMValueRef Pointer,
2263 LLVMValueRef *Indices, unsigned NumIndices,
2265 LLVMValueRef LLVMBuildInBoundsGEP(LLVMBuilderRef B, LLVMValueRef Pointer,
2266 LLVMValueRef *Indices, unsigned NumIndices,
2268 LLVMValueRef LLVMBuildStructGEP(LLVMBuilderRef B, LLVMValueRef Pointer,
2269 unsigned Idx, const char *Name);
2270 LLVMValueRef LLVMBuildGlobalString(LLVMBuilderRef B, const char *Str,
2272 LLVMValueRef LLVMBuildGlobalStringPtr(LLVMBuilderRef B, const char *Str,
2276 LLVMValueRef LLVMBuildTrunc(LLVMBuilderRef, LLVMValueRef Val,
2277 LLVMTypeRef DestTy, const char *Name);
2278 LLVMValueRef LLVMBuildZExt(LLVMBuilderRef, LLVMValueRef Val,
2279 LLVMTypeRef DestTy, const char *Name);
2280 LLVMValueRef LLVMBuildSExt(LLVMBuilderRef, LLVMValueRef Val,
2281 LLVMTypeRef DestTy, const char *Name);
2282 LLVMValueRef LLVMBuildFPToUI(LLVMBuilderRef, LLVMValueRef Val,
2283 LLVMTypeRef DestTy, const char *Name);
2284 LLVMValueRef LLVMBuildFPToSI(LLVMBuilderRef, LLVMValueRef Val,
2285 LLVMTypeRef DestTy, const char *Name);
2286 LLVMValueRef LLVMBuildUIToFP(LLVMBuilderRef, LLVMValueRef Val,
2287 LLVMTypeRef DestTy, const char *Name);
2288 LLVMValueRef LLVMBuildSIToFP(LLVMBuilderRef, LLVMValueRef Val,
2289 LLVMTypeRef DestTy, const char *Name);
2290 LLVMValueRef LLVMBuildFPTrunc(LLVMBuilderRef, LLVMValueRef Val,
2291 LLVMTypeRef DestTy, const char *Name);
2292 LLVMValueRef LLVMBuildFPExt(LLVMBuilderRef, LLVMValueRef Val,
2293 LLVMTypeRef DestTy, const char *Name);
2294 LLVMValueRef LLVMBuildPtrToInt(LLVMBuilderRef, LLVMValueRef Val,
2295 LLVMTypeRef DestTy, const char *Name);
2296 LLVMValueRef LLVMBuildIntToPtr(LLVMBuilderRef, LLVMValueRef Val,
2297 LLVMTypeRef DestTy, const char *Name);
2298 LLVMValueRef LLVMBuildBitCast(LLVMBuilderRef, LLVMValueRef Val,
2299 LLVMTypeRef DestTy, const char *Name);
2300 LLVMValueRef LLVMBuildZExtOrBitCast(LLVMBuilderRef, LLVMValueRef Val,
2301 LLVMTypeRef DestTy, const char *Name);
2302 LLVMValueRef LLVMBuildSExtOrBitCast(LLVMBuilderRef, LLVMValueRef Val,
2303 LLVMTypeRef DestTy, const char *Name);
2304 LLVMValueRef LLVMBuildTruncOrBitCast(LLVMBuilderRef, LLVMValueRef Val,
2305 LLVMTypeRef DestTy, const char *Name);
2306 LLVMValueRef LLVMBuildCast(LLVMBuilderRef B, LLVMOpcode Op, LLVMValueRef Val,
2307 LLVMTypeRef DestTy, const char *Name);
2308 LLVMValueRef LLVMBuildPointerCast(LLVMBuilderRef, LLVMValueRef Val,
2309 LLVMTypeRef DestTy, const char *Name);
2310 LLVMValueRef LLVMBuildIntCast(LLVMBuilderRef, LLVMValueRef Val, /*Signed cast!*/
2311 LLVMTypeRef DestTy, const char *Name);
2312 LLVMValueRef LLVMBuildFPCast(LLVMBuilderRef, LLVMValueRef Val,
2313 LLVMTypeRef DestTy, const char *Name);
2316 LLVMValueRef LLVMBuildICmp(LLVMBuilderRef, LLVMIntPredicate Op,
2317 LLVMValueRef LHS, LLVMValueRef RHS,
2319 LLVMValueRef LLVMBuildFCmp(LLVMBuilderRef, LLVMRealPredicate Op,
2320 LLVMValueRef LHS, LLVMValueRef RHS,
2323 /* Miscellaneous instructions */
2324 LLVMValueRef LLVMBuildPhi(LLVMBuilderRef, LLVMTypeRef Ty, const char *Name);
2325 LLVMValueRef LLVMBuildCall(LLVMBuilderRef, LLVMValueRef Fn,
2326 LLVMValueRef *Args, unsigned NumArgs,
2328 LLVMValueRef LLVMBuildSelect(LLVMBuilderRef, LLVMValueRef If,
2329 LLVMValueRef Then, LLVMValueRef Else,
2331 LLVMValueRef LLVMBuildVAArg(LLVMBuilderRef, LLVMValueRef List, LLVMTypeRef Ty,
2333 LLVMValueRef LLVMBuildExtractElement(LLVMBuilderRef, LLVMValueRef VecVal,
2334 LLVMValueRef Index, const char *Name);
2335 LLVMValueRef LLVMBuildInsertElement(LLVMBuilderRef, LLVMValueRef VecVal,
2336 LLVMValueRef EltVal, LLVMValueRef Index,
2338 LLVMValueRef LLVMBuildShuffleVector(LLVMBuilderRef, LLVMValueRef V1,
2339 LLVMValueRef V2, LLVMValueRef Mask,
2341 LLVMValueRef LLVMBuildExtractValue(LLVMBuilderRef, LLVMValueRef AggVal,
2342 unsigned Index, const char *Name);
2343 LLVMValueRef LLVMBuildInsertValue(LLVMBuilderRef, LLVMValueRef AggVal,
2344 LLVMValueRef EltVal, unsigned Index,
2347 LLVMValueRef LLVMBuildIsNull(LLVMBuilderRef, LLVMValueRef Val,
2349 LLVMValueRef LLVMBuildIsNotNull(LLVMBuilderRef, LLVMValueRef Val,
2351 LLVMValueRef LLVMBuildPtrDiff(LLVMBuilderRef, LLVMValueRef LHS,
2352 LLVMValueRef RHS, const char *Name);
2359 * @defgroup LLVMCCoreModuleProvider Module Providers
2365 * Changes the type of M so it can be passed to FunctionPassManagers and the
2366 * JIT. They take ModuleProviders for historical reasons.
2368 LLVMModuleProviderRef
2369 LLVMCreateModuleProviderForExistingModule(LLVMModuleRef M);
2372 * Destroys the module M.
2374 void LLVMDisposeModuleProvider(LLVMModuleProviderRef M);
2381 * @defgroup LLVMCCoreMemoryBuffers Memory Buffers
2386 LLVMBool LLVMCreateMemoryBufferWithContentsOfFile(const char *Path,
2387 LLVMMemoryBufferRef *OutMemBuf,
2389 LLVMBool LLVMCreateMemoryBufferWithSTDIN(LLVMMemoryBufferRef *OutMemBuf,
2391 void LLVMDisposeMemoryBuffer(LLVMMemoryBufferRef MemBuf);
2398 * @defgroup LLVMCCorePassRegistry Pass Registry
2403 /** Return the global pass registry, for use with initialization functions.
2404 @see llvm::PassRegistry::getPassRegistry */
2405 LLVMPassRegistryRef LLVMGetGlobalPassRegistry(void);
2412 * @defgroup LLVMCCorePassManagers Pass Managers
2417 /** Constructs a new whole-module pass pipeline. This type of pipeline is
2418 suitable for link-time optimization and whole-module transformations.
2419 @see llvm::PassManager::PassManager */
2420 LLVMPassManagerRef LLVMCreatePassManager(void);
2422 /** Constructs a new function-by-function pass pipeline over the module
2423 provider. It does not take ownership of the module provider. This type of
2424 pipeline is suitable for code generation and JIT compilation tasks.
2425 @see llvm::FunctionPassManager::FunctionPassManager */
2426 LLVMPassManagerRef LLVMCreateFunctionPassManagerForModule(LLVMModuleRef M);
2428 /** Deprecated: Use LLVMCreateFunctionPassManagerForModule instead. */
2429 LLVMPassManagerRef LLVMCreateFunctionPassManager(LLVMModuleProviderRef MP);
2431 /** Initializes, executes on the provided module, and finalizes all of the
2432 passes scheduled in the pass manager. Returns 1 if any of the passes
2433 modified the module, 0 otherwise.
2434 @see llvm::PassManager::run(Module&) */
2435 LLVMBool LLVMRunPassManager(LLVMPassManagerRef PM, LLVMModuleRef M);
2437 /** Initializes all of the function passes scheduled in the function pass
2438 manager. Returns 1 if any of the passes modified the module, 0 otherwise.
2439 @see llvm::FunctionPassManager::doInitialization */
2440 LLVMBool LLVMInitializeFunctionPassManager(LLVMPassManagerRef FPM);
2442 /** Executes all of the function passes scheduled in the function pass manager
2443 on the provided function. Returns 1 if any of the passes modified the
2444 function, false otherwise.
2445 @see llvm::FunctionPassManager::run(Function&) */
2446 LLVMBool LLVMRunFunctionPassManager(LLVMPassManagerRef FPM, LLVMValueRef F);
2448 /** Finalizes all of the function passes scheduled in in the function pass
2449 manager. Returns 1 if any of the passes modified the module, 0 otherwise.
2450 @see llvm::FunctionPassManager::doFinalization */
2451 LLVMBool LLVMFinalizeFunctionPassManager(LLVMPassManagerRef FPM);
2453 /** Frees the memory of a pass pipeline. For function pipelines, does not free
2454 the module provider.
2455 @see llvm::PassManagerBase::~PassManagerBase. */
2456 void LLVMDisposePassManager(LLVMPassManagerRef PM);
2475 class PassManagerBase;
2477 #define DEFINE_SIMPLE_CONVERSION_FUNCTIONS(ty, ref) \
2478 inline ty *unwrap(ref P) { \
2479 return reinterpret_cast<ty*>(P); \
2482 inline ref wrap(const ty *P) { \
2483 return reinterpret_cast<ref>(const_cast<ty*>(P)); \
2486 #define DEFINE_ISA_CONVERSION_FUNCTIONS(ty, ref) \
2487 DEFINE_SIMPLE_CONVERSION_FUNCTIONS(ty, ref) \
2489 template<typename T> \
2490 inline T *unwrap(ref P) { \
2491 return cast<T>(unwrap(P)); \
2494 #define DEFINE_STDCXX_CONVERSION_FUNCTIONS(ty, ref) \
2495 DEFINE_SIMPLE_CONVERSION_FUNCTIONS(ty, ref) \
2497 template<typename T> \
2498 inline T *unwrap(ref P) { \
2499 T *Q = (T*)unwrap(P); \
2500 assert(Q && "Invalid cast!"); \
2504 DEFINE_ISA_CONVERSION_FUNCTIONS (Type, LLVMTypeRef )
2505 DEFINE_ISA_CONVERSION_FUNCTIONS (Value, LLVMValueRef )
2506 DEFINE_SIMPLE_CONVERSION_FUNCTIONS(Module, LLVMModuleRef )
2507 DEFINE_SIMPLE_CONVERSION_FUNCTIONS(BasicBlock, LLVMBasicBlockRef )
2508 DEFINE_SIMPLE_CONVERSION_FUNCTIONS(IRBuilder<>, LLVMBuilderRef )
2509 DEFINE_SIMPLE_CONVERSION_FUNCTIONS(MemoryBuffer, LLVMMemoryBufferRef )
2510 DEFINE_SIMPLE_CONVERSION_FUNCTIONS(LLVMContext, LLVMContextRef )
2511 DEFINE_SIMPLE_CONVERSION_FUNCTIONS(Use, LLVMUseRef )
2512 DEFINE_STDCXX_CONVERSION_FUNCTIONS(PassManagerBase, LLVMPassManagerRef )
2513 DEFINE_STDCXX_CONVERSION_FUNCTIONS(PassRegistry, LLVMPassRegistryRef )
2514 /* LLVMModuleProviderRef exists for historical reasons, but now just holds a
2517 inline Module *unwrap(LLVMModuleProviderRef MP) {
2518 return reinterpret_cast<Module*>(MP);
2521 #undef DEFINE_STDCXX_CONVERSION_FUNCTIONS
2522 #undef DEFINE_ISA_CONVERSION_FUNCTIONS
2523 #undef DEFINE_SIMPLE_CONVERSION_FUNCTIONS
2525 /* Specialized opaque context conversions.
2527 inline LLVMContext **unwrap(LLVMContextRef* Tys) {
2528 return reinterpret_cast<LLVMContext**>(Tys);
2531 inline LLVMContextRef *wrap(const LLVMContext **Tys) {
2532 return reinterpret_cast<LLVMContextRef*>(const_cast<LLVMContext**>(Tys));
2535 /* Specialized opaque type conversions.
2537 inline Type **unwrap(LLVMTypeRef* Tys) {
2538 return reinterpret_cast<Type**>(Tys);
2541 inline LLVMTypeRef *wrap(Type **Tys) {
2542 return reinterpret_cast<LLVMTypeRef*>(const_cast<Type**>(Tys));
2545 /* Specialized opaque value conversions.
2547 inline Value **unwrap(LLVMValueRef *Vals) {
2548 return reinterpret_cast<Value**>(Vals);
2551 template<typename T>
2552 inline T **unwrap(LLVMValueRef *Vals, unsigned Length) {
2554 for (LLVMValueRef *I = Vals, *E = Vals + Length; I != E; ++I)
2558 return reinterpret_cast<T**>(Vals);
2561 inline LLVMValueRef *wrap(const Value **Vals) {
2562 return reinterpret_cast<LLVMValueRef*>(const_cast<Value**>(Vals));
2566 #endif /* !defined(__cplusplus) */
2568 #endif /* !defined(LLVM_C_CORE_H) */