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);
408 * @defgroup LLVMCCoreModule Modules
410 * Modules represent the top-level structure in a LLVM program. An LLVM
411 * module is effectively a translation unit or a collection of
412 * translation units merged together.
418 * Create a new, empty module in the global context.
420 * This is equivalent to calling LLVMModuleCreateWithNameInContext with
421 * LLVMGetGlobalContext() as the context parameter.
423 * Every invocation should be paired with LLVMDisposeModule() or memory
426 LLVMModuleRef LLVMModuleCreateWithName(const char *ModuleID);
429 * Create a new, empty module in a specific context.
431 * Every invocation should be paired with LLVMDisposeModule() or memory
434 LLVMModuleRef LLVMModuleCreateWithNameInContext(const char *ModuleID,
438 * Destroy a module instance.
440 * This must be called for every created module or memory will be
443 void LLVMDisposeModule(LLVMModuleRef M);
446 * Obtain the data layout for a module.
448 * @see Module::getDataLayout()
450 const char *LLVMGetDataLayout(LLVMModuleRef M);
453 * Set the data layout for a module.
455 * @see Module::setDataLayout()
457 void LLVMSetDataLayout(LLVMModuleRef M, const char *Triple);
460 * Obtain the target triple for a module.
462 * @see Module::getTargetTriple()
464 const char *LLVMGetTarget(LLVMModuleRef M);
467 * Set the target triple for a module.
469 * @see Module::setTargetTriple()
471 void LLVMSetTarget(LLVMModuleRef M, const char *Triple);
474 * Dump a representation of a module to stderr.
476 * @see Module::dump()
478 void LLVMDumpModule(LLVMModuleRef M);
481 * Set inline assembly for a module.
483 * @see Module::setModuleInlineAsm()
485 void LLVMSetModuleInlineAsm(LLVMModuleRef M, const char *Asm);
488 * Obtain the context to which this module is associated.
490 * @see Module::getContext()
492 LLVMContextRef LLVMGetModuleContext(LLVMModuleRef M);
495 * Obtain a Type from a module by its registered name.
497 LLVMTypeRef LLVMGetTypeByName(LLVMModuleRef M, const char *Name);
500 * Obtain the number of operands for named metadata in a module.
502 * @see llvm::Module::getNamedMetadata()
504 unsigned LLVMGetNamedMetadataNumOperands(LLVMModuleRef M, const char* name);
507 * Obtain the named metadata operands for a module.
509 * The passed LLVMValueRef pointer should refer to an array of
510 * LLVMValueRef at least LLVMGetNamedMetadataNumOperands long. This
511 * array will be populated with the LLVMValueRef instances. Each
512 * instance corresponds to a llvm::MDNode.
514 * @see llvm::Module::getNamedMetadata()
515 * @see llvm::MDNode::getOperand()
517 void LLVMGetNamedMetadataOperands(LLVMModuleRef M, const char* name, LLVMValueRef *Dest);
520 * Add an operand to named metadata.
522 * @see llvm::Module::getNamedMetadata()
523 * @see llvm::MDNode::addOperand()
525 void LLVMAddNamedMetadataOperand(LLVMModuleRef M, const char* name,
529 * Add a function to a module under a specified name.
531 * @see llvm::Function::Create()
533 LLVMValueRef LLVMAddFunction(LLVMModuleRef M, const char *Name,
534 LLVMTypeRef FunctionTy);
537 * Obtain a Function value from a Module by its name.
539 * The returned value corresponds to a llvm::Function value.
541 * @see llvm::Module::getFunction()
543 LLVMValueRef LLVMGetNamedFunction(LLVMModuleRef M, const char *Name);
546 * Obtain an iterator to the first Function in a Module.
548 * @see llvm::Module::begin()
550 LLVMValueRef LLVMGetFirstFunction(LLVMModuleRef M);
553 * Obtain an iterator to the last Function in a Module.
555 * @see llvm::Module::end()
557 LLVMValueRef LLVMGetLastFunction(LLVMModuleRef M);
560 * Advance a Function iterator to the next Function.
562 * Returns NULL if the iterator was already at the end and there are no more
565 LLVMValueRef LLVMGetNextFunction(LLVMValueRef Fn);
568 * Decrement a Function iterator to the previous Function.
570 * Returns NULL if the iterator was already at the beginning and there are
571 * no previous functions.
573 LLVMValueRef LLVMGetPreviousFunction(LLVMValueRef Fn);
580 * @defgroup LLVMCCoreType Types
582 * Types represent the type of a value.
584 * Types are associated with a context instance. The context internally
585 * deduplicates types so there is only 1 instance of a specific type
586 * alive at a time. In other words, a unique type is shared among all
587 * consumers within a context.
589 * A Type in the C API corresponds to llvm::Type.
591 * Types have the following hierarchy:
609 * Obtain the enumerated type of a Type instance.
611 * @see llvm::Type:getTypeID()
613 LLVMTypeKind LLVMGetTypeKind(LLVMTypeRef Ty);
616 * Whether the type has a known size.
618 * Things that don't have a size are abstract types, labels, and void.a
620 * @see llvm::Type::isSized()
622 LLVMBool LLVMTypeIsSized(LLVMTypeRef Ty);
625 * Obtain the context to which this type instance is associated.
627 * @see llvm::Type::getContext()
629 LLVMContextRef LLVMGetTypeContext(LLVMTypeRef Ty);
632 * @defgroup LLVMCCoreTypeInt Integer Types
634 * Functions in this section operate on integer types.
640 * Obtain an integer type from a context with specified bit width.
642 LLVMTypeRef LLVMInt1TypeInContext(LLVMContextRef C);
643 LLVMTypeRef LLVMInt8TypeInContext(LLVMContextRef C);
644 LLVMTypeRef LLVMInt16TypeInContext(LLVMContextRef C);
645 LLVMTypeRef LLVMInt32TypeInContext(LLVMContextRef C);
646 LLVMTypeRef LLVMInt64TypeInContext(LLVMContextRef C);
647 LLVMTypeRef LLVMIntTypeInContext(LLVMContextRef C, unsigned NumBits);
650 * Obtain an integer type from the global context with a specified bit
653 LLVMTypeRef LLVMInt1Type(void);
654 LLVMTypeRef LLVMInt8Type(void);
655 LLVMTypeRef LLVMInt16Type(void);
656 LLVMTypeRef LLVMInt32Type(void);
657 LLVMTypeRef LLVMInt64Type(void);
658 LLVMTypeRef LLVMIntType(unsigned NumBits);
659 unsigned LLVMGetIntTypeWidth(LLVMTypeRef IntegerTy);
666 * @defgroup LLVMCCoreTypeFloat Floating Point Types
672 * Obtain a 16-bit floating point type from a context.
674 LLVMTypeRef LLVMHalfTypeInContext(LLVMContextRef C);
677 * Obtain a 32-bit floating point type from a context.
679 LLVMTypeRef LLVMFloatTypeInContext(LLVMContextRef C);
682 * Obtain a 64-bit floating point type from a context.
684 LLVMTypeRef LLVMDoubleTypeInContext(LLVMContextRef C);
687 * Obtain a 80-bit floating point type (X87) from a context.
689 LLVMTypeRef LLVMX86FP80TypeInContext(LLVMContextRef C);
692 * Obtain a 128-bit floating point type (112-bit mantissa) from a
695 LLVMTypeRef LLVMFP128TypeInContext(LLVMContextRef C);
698 * Obtain a 128-bit floating point type (two 64-bits) from a context.
700 LLVMTypeRef LLVMPPCFP128TypeInContext(LLVMContextRef C);
703 * Obtain a floating point type from the global context.
705 * These map to the functions in this group of the same name.
707 LLVMTypeRef LLVMHalfType(void);
708 LLVMTypeRef LLVMFloatType(void);
709 LLVMTypeRef LLVMDoubleType(void);
710 LLVMTypeRef LLVMX86FP80Type(void);
711 LLVMTypeRef LLVMFP128Type(void);
712 LLVMTypeRef LLVMPPCFP128Type(void);
719 * @defgroup LLVMCCoreTypeFunction Function Types
725 * Obtain a function type consisting of a specified signature.
727 * The function is defined as a tuple of a return Type, a list of
728 * parameter types, and whether the function is variadic.
730 LLVMTypeRef LLVMFunctionType(LLVMTypeRef ReturnType,
731 LLVMTypeRef *ParamTypes, unsigned ParamCount,
735 * Returns whether a function type is variadic.
737 LLVMBool LLVMIsFunctionVarArg(LLVMTypeRef FunctionTy);
740 * Obtain the Type this function Type returns.
742 LLVMTypeRef LLVMGetReturnType(LLVMTypeRef FunctionTy);
745 * Obtain the number of parameters this function accepts.
747 unsigned LLVMCountParamTypes(LLVMTypeRef FunctionTy);
750 * Obtain the types of a function's parameters.
752 * The Dest parameter should point to a pre-allocated array of
753 * LLVMTypeRef at least LLVMCountParamTypes() large. On return, the
754 * first LLVMCountParamTypes() entries in the array will be populated
755 * with LLVMTypeRef instances.
757 * @param FunctionTy The function type to operate on.
758 * @param Dest Memory address of an array to be filled with result.
760 void LLVMGetParamTypes(LLVMTypeRef FunctionTy, LLVMTypeRef *Dest);
767 * @defgroup LLVMCCoreTypeStruct Structure Types
769 * These functions relate to LLVMTypeRef instances.
771 * @see llvm::StructType
777 * Create a new structure type in a context.
779 * A structure is specified by a list of inner elements/types and
780 * whether these can be packed together.
782 * @see llvm::StructType::create()
784 LLVMTypeRef LLVMStructTypeInContext(LLVMContextRef C, LLVMTypeRef *ElementTypes,
785 unsigned ElementCount, LLVMBool Packed);
788 * Create a new structure type in the global context.
790 * @see llvm::StructType::create()
792 LLVMTypeRef LLVMStructType(LLVMTypeRef *ElementTypes, unsigned ElementCount,
796 * Create an empty structure in a context having a specified name.
798 * @see llvm::StructType::create()
800 LLVMTypeRef LLVMStructCreateNamed(LLVMContextRef C, const char *Name);
803 * Obtain the name of a structure.
805 * @see llvm::StructType::getName()
807 const char *LLVMGetStructName(LLVMTypeRef Ty);
810 * Set the contents of a structure type.
812 * @see llvm::StructType::setBody()
814 void LLVMStructSetBody(LLVMTypeRef StructTy, LLVMTypeRef *ElementTypes,
815 unsigned ElementCount, LLVMBool Packed);
818 * Get the number of elements defined inside the structure.
820 * @see llvm::StructType::getNumElements()
822 unsigned LLVMCountStructElementTypes(LLVMTypeRef StructTy);
825 * Get the elements within a structure.
827 * The function is passed the address of a pre-allocated array of
828 * LLVMTypeRef at least LLVMCountStructElementTypes() long. After
829 * invocation, this array will be populated with the structure's
830 * elements. The objects in the destination array will have a lifetime
831 * of the structure type itself, which is the lifetime of the context it
834 void LLVMGetStructElementTypes(LLVMTypeRef StructTy, LLVMTypeRef *Dest);
837 * Determine whether a structure is packed.
839 * @see llvm::StructType::isPacked()
841 LLVMBool LLVMIsPackedStruct(LLVMTypeRef StructTy);
844 * Determine whether a structure is opaque.
846 * @see llvm::StructType::isOpaque()
848 LLVMBool LLVMIsOpaqueStruct(LLVMTypeRef StructTy);
856 * @defgroup LLVMCCoreTypeSequential Sequential Types
858 * Sequential types represents "arrays" of types. This is a super class
859 * for array, vector, and pointer types.
865 * Obtain the type of elements within a sequential type.
867 * This works on array, vector, and pointer types.
869 * @see llvm::SequentialType::getElementType()
871 LLVMTypeRef LLVMGetElementType(LLVMTypeRef Ty);
874 * Create a fixed size array type that refers to a specific type.
876 * The created type will exist in the context that its element type
879 * @see llvm::ArrayType::get()
881 LLVMTypeRef LLVMArrayType(LLVMTypeRef ElementType, unsigned ElementCount);
884 * Obtain the length of an array type.
886 * This only works on types that represent arrays.
888 * @see llvm::ArrayType::getNumElements()
890 unsigned LLVMGetArrayLength(LLVMTypeRef ArrayTy);
893 * Create a pointer type that points to a defined type.
895 * The created type will exist in the context that its pointee type
898 * @see llvm::PointerType::get()
900 LLVMTypeRef LLVMPointerType(LLVMTypeRef ElementType, unsigned AddressSpace);
903 * Obtain the address space of a pointer type.
905 * This only works on types that represent pointers.
907 * @see llvm::PointerType::getAddressSpace()
909 unsigned LLVMGetPointerAddressSpace(LLVMTypeRef PointerTy);
912 * Create a vector type that contains a defined type and has a specific
913 * number of elements.
915 * The created type will exist in the context thats its element type
918 * @see llvm::VectorType::get()
920 LLVMTypeRef LLVMVectorType(LLVMTypeRef ElementType, unsigned ElementCount);
923 * Obtain the number of elements in a vector type.
925 * This only works on types that represent vectors.
927 * @see llvm::VectorType::getNumElements()
929 unsigned LLVMGetVectorSize(LLVMTypeRef VectorTy);
936 * @defgroup LLVMCCoreTypeOther Other Types
942 * Create a void type in a context.
944 LLVMTypeRef LLVMVoidTypeInContext(LLVMContextRef C);
947 * Create a label type in a context.
949 LLVMTypeRef LLVMLabelTypeInContext(LLVMContextRef C);
952 * Create a X86 MMX type in a context.
954 LLVMTypeRef LLVMX86MMXTypeInContext(LLVMContextRef C);
957 * These are similar to the above functions except they operate on the
960 LLVMTypeRef LLVMVoidType(void);
961 LLVMTypeRef LLVMLabelType(void);
962 LLVMTypeRef LLVMX86MMXType(void);
973 * @defgroup LLVMCCoreValues Values
975 * The bulk of LLVM's object model consists of values, which comprise a very
976 * rich type hierarchy.
978 * LLVMValueRef essentially represents llvm::Value. There is a rich
979 * hierarchy of classes within this type. Depending on the instance
980 * obtain, not all APIs are available.
982 * Callers can determine the type of a LLVMValueRef by calling the
983 * LLVMIsA* family of functions (e.g. LLVMIsAArgument()). These
984 * functions are defined by a macro, so it isn't obvious which are
985 * available by looking at the Doxygen source code. Instead, look at the
986 * source definition of LLVM_FOR_EACH_VALUE_SUBCLASS and note the list
987 * of value names given. These value names also correspond to classes in
988 * the llvm::Value hierarchy.
993 #define LLVM_FOR_EACH_VALUE_SUBCLASS(macro) \
1001 macro(BlockAddress) \
1002 macro(ConstantAggregateZero) \
1003 macro(ConstantArray) \
1004 macro(ConstantExpr) \
1006 macro(ConstantInt) \
1007 macro(ConstantPointerNull) \
1008 macro(ConstantStruct) \
1009 macro(ConstantVector) \
1010 macro(GlobalValue) \
1012 macro(GlobalAlias) \
1013 macro(GlobalVariable) \
1015 macro(Instruction) \
1016 macro(BinaryOperator) \
1018 macro(IntrinsicInst) \
1019 macro(DbgInfoIntrinsic) \
1020 macro(DbgDeclareInst) \
1021 macro(MemIntrinsic) \
1023 macro(MemMoveInst) \
1028 macro(ExtractElementInst) \
1029 macro(GetElementPtrInst) \
1030 macro(InsertElementInst) \
1031 macro(InsertValueInst) \
1032 macro(LandingPadInst) \
1035 macro(ShuffleVectorInst) \
1037 macro(TerminatorInst) \
1039 macro(IndirectBrInst) \
1043 macro(UnreachableInst) \
1045 macro(UnaryInstruction) \
1048 macro(BitCastInst) \
1052 macro(FPTruncInst) \
1053 macro(IntToPtrInst) \
1054 macro(PtrToIntInst) \
1060 macro(ExtractValueInst) \
1065 * @defgroup LLVMCCoreValueGeneral General APIs
1067 * Functions in this section work on all LLVMValueRef instances,
1068 * regardless of their sub-type. They correspond to functions available
1075 * Obtain the type of a value.
1077 * @see llvm::Value::getType()
1079 LLVMTypeRef LLVMTypeOf(LLVMValueRef Val);
1082 * Obtain the string name of a value.
1084 * @see llvm::Value::getName()
1086 const char *LLVMGetValueName(LLVMValueRef Val);
1089 * Set the string name of a value.
1091 * @see llvm::Value::setName()
1093 void LLVMSetValueName(LLVMValueRef Val, const char *Name);
1096 * Dump a representation of a value to stderr.
1098 * @see llvm::Value::dump()
1100 void LLVMDumpValue(LLVMValueRef Val);
1103 * Replace all uses of a value with another one.
1105 * @see llvm::Value::replaceAllUsesWith()
1107 void LLVMReplaceAllUsesWith(LLVMValueRef OldVal, LLVMValueRef NewVal);
1110 * Determine whether the specified constant instance is constant.
1112 LLVMBool LLVMIsConstant(LLVMValueRef Val);
1115 * Determine whether a value instance is undefined.
1117 LLVMBool LLVMIsUndef(LLVMValueRef Val);
1120 * Convert value instances between types.
1122 * Internally, a LLVMValueRef is "pinned" to a specific type. This
1123 * series of functions allows you to cast an instance to a specific
1126 * If the cast is not valid for the specified type, NULL is returned.
1128 * @see llvm::dyn_cast_or_null<>
1130 #define LLVM_DECLARE_VALUE_CAST(name) \
1131 LLVMValueRef LLVMIsA##name(LLVMValueRef Val);
1132 LLVM_FOR_EACH_VALUE_SUBCLASS(LLVM_DECLARE_VALUE_CAST)
1139 * @defgroup LLVMCCoreValueUses Usage
1141 * This module defines functions that allow you to inspect the uses of a
1144 * It is possible to obtain a LLVMUseRef for any LLVMValueRef instance.
1145 * Each LLVMUseRef (which corresponds to a llvm::Use instance) holds a
1146 * llvm::User and llvm::Value.
1152 * Obtain the first use of a value.
1154 * Uses are obtained in an iterator fashion. First, call this function
1155 * to obtain a reference to the first use. Then, call LLVMGetNextUse()
1156 * on that instance and all subsequently obtained instances untl
1157 * LLVMGetNextUse() returns NULL.
1159 * @see llvm::Value::use_begin()
1161 LLVMUseRef LLVMGetFirstUse(LLVMValueRef Val);
1164 * Obtain the next use of a value.
1166 * This effectively advances the iterator. It returns NULL if you are on
1167 * the final use and no more are available.
1169 LLVMUseRef LLVMGetNextUse(LLVMUseRef U);
1172 * Obtain the user value for a user.
1174 * The returned value corresponds to a llvm::User type.
1176 * @see llvm::Use::getUser()
1178 LLVMValueRef LLVMGetUser(LLVMUseRef U);
1181 * Obtain the value this use corresponds to.
1183 * @see llvm::Use::get().
1185 LLVMValueRef LLVMGetUsedValue(LLVMUseRef U);
1192 * @defgroup LLVMCCoreValueUser User value
1194 * Function in this group pertain to LLVMValueRef instances that descent
1195 * from llvm::User. This includes constants, instructions, and
1202 * Obtain an operand at a specific index in a llvm::User value.
1204 * @see llvm::User::getOperand()
1206 LLVMValueRef LLVMGetOperand(LLVMValueRef Val, unsigned Index);
1209 * Set an operand at a specific index in a llvm::User value.
1211 * @see llvm::User::setOperand()
1213 void LLVMSetOperand(LLVMValueRef User, unsigned Index, LLVMValueRef Val);
1216 * Obtain the number of operands in a llvm::User value.
1218 * @see llvm::User::getNumOperands()
1220 int LLVMGetNumOperands(LLVMValueRef Val);
1227 * @defgroup LLVMCCoreValueConstant Constants
1229 * This section contains APIs for interacting with LLVMValueRef that
1230 * correspond to llvm::Constant instances.
1232 * These functions will work for any LLVMValueRef in the llvm::Constant
1239 * Obtain a constant value referring to the null instance of a type.
1241 * @see llvm::Constant::getNullValue()
1243 LLVMValueRef LLVMConstNull(LLVMTypeRef Ty); /* all zeroes */
1246 * Obtain a constant value referring to the instance of a type
1247 * consisting of all ones.
1249 * This is only valid for integer types.
1251 * @see llvm::Constant::getAllOnesValue()
1253 LLVMValueRef LLVMConstAllOnes(LLVMTypeRef Ty);
1256 * Obtain a constant value referring to an undefined value of a type.
1258 * @see llvm::UndefValue::get()
1260 LLVMValueRef LLVMGetUndef(LLVMTypeRef Ty);
1263 * Determine whether a value instance is null.
1265 * @see llvm::Constant::isNullValue()
1267 LLVMBool LLVMIsNull(LLVMValueRef Val);
1270 * Obtain a constant that is a constant pointer pointing to NULL for a
1273 LLVMValueRef LLVMConstPointerNull(LLVMTypeRef Ty);
1276 * @defgroup LLVMCCoreValueConstantScalar Scalar constants
1278 * Functions in this group model LLVMValueRef instances that correspond
1279 * to constants referring to scalar types.
1281 * For integer types, the LLVMTypeRef parameter should correspond to a
1282 * llvm::IntegerType instance and the returned LLVMValueRef will
1283 * correspond to a llvm::ConstantInt.
1285 * For floating point types, the LLVMTypeRef returned corresponds to a
1292 * Obtain a constant value for an integer type.
1294 * The returned value corresponds to a llvm::ConstantInt.
1296 * @see llvm::ConstantInt::get()
1298 * @param IntTy Integer type to obtain value of.
1299 * @param N The value the returned instance should refer to.
1300 * @param SignExtend Whether to sign extend the produced value.
1302 LLVMValueRef LLVMConstInt(LLVMTypeRef IntTy, unsigned long long N,
1303 LLVMBool SignExtend);
1306 * Obtain a constant value for an integer of arbitrary precision.
1308 * @see llvm::ConstantInt::get()
1310 LLVMValueRef LLVMConstIntOfArbitraryPrecision(LLVMTypeRef IntTy,
1312 const uint64_t Words[]);
1315 * Obtain a constant value for an integer parsed from a string.
1317 * A similar API, LLVMConstIntOfStringAndSize is also available. If the
1318 * string's length is available, it is preferred to call that function
1321 * @see llvm::ConstantInt::get()
1323 LLVMValueRef LLVMConstIntOfString(LLVMTypeRef IntTy, const char *Text,
1327 * Obtain a constant value for an integer parsed from a string with
1330 * @see llvm::ConstantInt::get()
1332 LLVMValueRef LLVMConstIntOfStringAndSize(LLVMTypeRef IntTy, const char *Text,
1333 unsigned SLen, uint8_t Radix);
1336 * Obtain a constant value referring to a double floating point value.
1338 LLVMValueRef LLVMConstReal(LLVMTypeRef RealTy, double N);
1341 * Obtain a constant for a floating point value parsed from a string.
1343 * A similar API, LLVMConstRealOfStringAndSize is also available. It
1344 * should be used if the input string's length is known.
1346 LLVMValueRef LLVMConstRealOfString(LLVMTypeRef RealTy, const char *Text);
1349 * Obtain a constant for a floating point value parsed from a string.
1351 LLVMValueRef LLVMConstRealOfStringAndSize(LLVMTypeRef RealTy, const char *Text,
1355 * Obtain the zero extended value for an integer constant value.
1357 * @see llvm::ConstantInt::getZExtValue()
1359 unsigned long long LLVMConstIntGetZExtValue(LLVMValueRef ConstantVal);
1362 * Obtain the sign extended value for an integer constant value.
1364 * @see llvm::ConstantInt::getSExtValue()
1366 long long LLVMConstIntGetSExtValue(LLVMValueRef ConstantVal);
1373 * @defgroup LLVMCCoreValueConstantComposite Composite Constants
1375 * Functions in this group operate on composite constants.
1381 * Create a ConstantDataSequential and initialize it with a string.
1383 * @see llvm::ConstantDataArray::getString()
1385 LLVMValueRef LLVMConstStringInContext(LLVMContextRef C, const char *Str,
1386 unsigned Length, LLVMBool DontNullTerminate);
1389 * Create a ConstantDataSequential with string content in the global context.
1391 * This is the same as LLVMConstStringInContext except it operates on the
1394 * @see LLVMConstStringInContext()
1395 * @see llvm::ConstantDataArray::getString()
1397 LLVMValueRef LLVMConstString(const char *Str, unsigned Length,
1398 LLVMBool DontNullTerminate);
1401 * Create an anonymous ConstantStruct with the specified values.
1403 * @see llvm::ConstantStruct::getAnon()
1405 LLVMValueRef LLVMConstStructInContext(LLVMContextRef C,
1406 LLVMValueRef *ConstantVals,
1407 unsigned Count, LLVMBool Packed);
1410 * Create a ConstantStruct in the global Context.
1412 * This is the same as LLVMConstStructInContext except it operates on the
1415 * @see LLVMConstStructInContext()
1417 LLVMValueRef LLVMConstStruct(LLVMValueRef *ConstantVals, unsigned Count,
1421 * Create a ConstantArray from values.
1423 * @see llvm::ConstantArray::get()
1425 LLVMValueRef LLVMConstArray(LLVMTypeRef ElementTy,
1426 LLVMValueRef *ConstantVals, unsigned Length);
1429 * Create a non-anonymous ConstantStruct from values.
1431 * @see llvm::ConstantStruct::get()
1433 LLVMValueRef LLVMConstNamedStruct(LLVMTypeRef StructTy,
1434 LLVMValueRef *ConstantVals,
1438 * Create a ConstantVector from values.
1440 * @see llvm::ConstantVector::get()
1442 LLVMValueRef LLVMConstVector(LLVMValueRef *ScalarConstantVals, unsigned Size);
1449 * @defgroup LLVMCCoreValueConstantExpressions Constant Expressions
1451 * Functions in this group correspond to APIs on llvm::ConstantExpr.
1453 * @see llvm::ConstantExpr.
1457 LLVMOpcode LLVMGetConstOpcode(LLVMValueRef ConstantVal);
1458 LLVMValueRef LLVMAlignOf(LLVMTypeRef Ty);
1459 LLVMValueRef LLVMSizeOf(LLVMTypeRef Ty);
1460 LLVMValueRef LLVMConstNeg(LLVMValueRef ConstantVal);
1461 LLVMValueRef LLVMConstNSWNeg(LLVMValueRef ConstantVal);
1462 LLVMValueRef LLVMConstNUWNeg(LLVMValueRef ConstantVal);
1463 LLVMValueRef LLVMConstFNeg(LLVMValueRef ConstantVal);
1464 LLVMValueRef LLVMConstNot(LLVMValueRef ConstantVal);
1465 LLVMValueRef LLVMConstAdd(LLVMValueRef LHSConstant, LLVMValueRef RHSConstant);
1466 LLVMValueRef LLVMConstNSWAdd(LLVMValueRef LHSConstant, LLVMValueRef RHSConstant);
1467 LLVMValueRef LLVMConstNUWAdd(LLVMValueRef LHSConstant, LLVMValueRef RHSConstant);
1468 LLVMValueRef LLVMConstFAdd(LLVMValueRef LHSConstant, LLVMValueRef RHSConstant);
1469 LLVMValueRef LLVMConstSub(LLVMValueRef LHSConstant, LLVMValueRef RHSConstant);
1470 LLVMValueRef LLVMConstNSWSub(LLVMValueRef LHSConstant, LLVMValueRef RHSConstant);
1471 LLVMValueRef LLVMConstNUWSub(LLVMValueRef LHSConstant, LLVMValueRef RHSConstant);
1472 LLVMValueRef LLVMConstFSub(LLVMValueRef LHSConstant, LLVMValueRef RHSConstant);
1473 LLVMValueRef LLVMConstMul(LLVMValueRef LHSConstant, LLVMValueRef RHSConstant);
1474 LLVMValueRef LLVMConstNSWMul(LLVMValueRef LHSConstant, LLVMValueRef RHSConstant);
1475 LLVMValueRef LLVMConstNUWMul(LLVMValueRef LHSConstant, LLVMValueRef RHSConstant);
1476 LLVMValueRef LLVMConstFMul(LLVMValueRef LHSConstant, LLVMValueRef RHSConstant);
1477 LLVMValueRef LLVMConstUDiv(LLVMValueRef LHSConstant, LLVMValueRef RHSConstant);
1478 LLVMValueRef LLVMConstSDiv(LLVMValueRef LHSConstant, LLVMValueRef RHSConstant);
1479 LLVMValueRef LLVMConstExactSDiv(LLVMValueRef LHSConstant, LLVMValueRef RHSConstant);
1480 LLVMValueRef LLVMConstFDiv(LLVMValueRef LHSConstant, LLVMValueRef RHSConstant);
1481 LLVMValueRef LLVMConstURem(LLVMValueRef LHSConstant, LLVMValueRef RHSConstant);
1482 LLVMValueRef LLVMConstSRem(LLVMValueRef LHSConstant, LLVMValueRef RHSConstant);
1483 LLVMValueRef LLVMConstFRem(LLVMValueRef LHSConstant, LLVMValueRef RHSConstant);
1484 LLVMValueRef LLVMConstAnd(LLVMValueRef LHSConstant, LLVMValueRef RHSConstant);
1485 LLVMValueRef LLVMConstOr(LLVMValueRef LHSConstant, LLVMValueRef RHSConstant);
1486 LLVMValueRef LLVMConstXor(LLVMValueRef LHSConstant, LLVMValueRef RHSConstant);
1487 LLVMValueRef LLVMConstICmp(LLVMIntPredicate Predicate,
1488 LLVMValueRef LHSConstant, LLVMValueRef RHSConstant);
1489 LLVMValueRef LLVMConstFCmp(LLVMRealPredicate Predicate,
1490 LLVMValueRef LHSConstant, LLVMValueRef RHSConstant);
1491 LLVMValueRef LLVMConstShl(LLVMValueRef LHSConstant, LLVMValueRef RHSConstant);
1492 LLVMValueRef LLVMConstLShr(LLVMValueRef LHSConstant, LLVMValueRef RHSConstant);
1493 LLVMValueRef LLVMConstAShr(LLVMValueRef LHSConstant, LLVMValueRef RHSConstant);
1494 LLVMValueRef LLVMConstGEP(LLVMValueRef ConstantVal,
1495 LLVMValueRef *ConstantIndices, unsigned NumIndices);
1496 LLVMValueRef LLVMConstInBoundsGEP(LLVMValueRef ConstantVal,
1497 LLVMValueRef *ConstantIndices,
1498 unsigned NumIndices);
1499 LLVMValueRef LLVMConstTrunc(LLVMValueRef ConstantVal, LLVMTypeRef ToType);
1500 LLVMValueRef LLVMConstSExt(LLVMValueRef ConstantVal, LLVMTypeRef ToType);
1501 LLVMValueRef LLVMConstZExt(LLVMValueRef ConstantVal, LLVMTypeRef ToType);
1502 LLVMValueRef LLVMConstFPTrunc(LLVMValueRef ConstantVal, LLVMTypeRef ToType);
1503 LLVMValueRef LLVMConstFPExt(LLVMValueRef ConstantVal, LLVMTypeRef ToType);
1504 LLVMValueRef LLVMConstUIToFP(LLVMValueRef ConstantVal, LLVMTypeRef ToType);
1505 LLVMValueRef LLVMConstSIToFP(LLVMValueRef ConstantVal, LLVMTypeRef ToType);
1506 LLVMValueRef LLVMConstFPToUI(LLVMValueRef ConstantVal, LLVMTypeRef ToType);
1507 LLVMValueRef LLVMConstFPToSI(LLVMValueRef ConstantVal, LLVMTypeRef ToType);
1508 LLVMValueRef LLVMConstPtrToInt(LLVMValueRef ConstantVal, LLVMTypeRef ToType);
1509 LLVMValueRef LLVMConstIntToPtr(LLVMValueRef ConstantVal, LLVMTypeRef ToType);
1510 LLVMValueRef LLVMConstBitCast(LLVMValueRef ConstantVal, LLVMTypeRef ToType);
1511 LLVMValueRef LLVMConstZExtOrBitCast(LLVMValueRef ConstantVal,
1512 LLVMTypeRef ToType);
1513 LLVMValueRef LLVMConstSExtOrBitCast(LLVMValueRef ConstantVal,
1514 LLVMTypeRef ToType);
1515 LLVMValueRef LLVMConstTruncOrBitCast(LLVMValueRef ConstantVal,
1516 LLVMTypeRef ToType);
1517 LLVMValueRef LLVMConstPointerCast(LLVMValueRef ConstantVal,
1518 LLVMTypeRef ToType);
1519 LLVMValueRef LLVMConstIntCast(LLVMValueRef ConstantVal, LLVMTypeRef ToType,
1521 LLVMValueRef LLVMConstFPCast(LLVMValueRef ConstantVal, LLVMTypeRef ToType);
1522 LLVMValueRef LLVMConstSelect(LLVMValueRef ConstantCondition,
1523 LLVMValueRef ConstantIfTrue,
1524 LLVMValueRef ConstantIfFalse);
1525 LLVMValueRef LLVMConstExtractElement(LLVMValueRef VectorConstant,
1526 LLVMValueRef IndexConstant);
1527 LLVMValueRef LLVMConstInsertElement(LLVMValueRef VectorConstant,
1528 LLVMValueRef ElementValueConstant,
1529 LLVMValueRef IndexConstant);
1530 LLVMValueRef LLVMConstShuffleVector(LLVMValueRef VectorAConstant,
1531 LLVMValueRef VectorBConstant,
1532 LLVMValueRef MaskConstant);
1533 LLVMValueRef LLVMConstExtractValue(LLVMValueRef AggConstant, unsigned *IdxList,
1535 LLVMValueRef LLVMConstInsertValue(LLVMValueRef AggConstant,
1536 LLVMValueRef ElementValueConstant,
1537 unsigned *IdxList, unsigned NumIdx);
1538 LLVMValueRef LLVMConstInlineAsm(LLVMTypeRef Ty,
1539 const char *AsmString, const char *Constraints,
1540 LLVMBool HasSideEffects, LLVMBool IsAlignStack);
1541 LLVMValueRef LLVMBlockAddress(LLVMValueRef F, LLVMBasicBlockRef BB);
1548 * @defgroup LLVMCCoreValueConstantGlobals Global Values
1550 * This group contains functions that operate on global values. Functions in
1551 * this group relate to functions in the llvm::GlobalValue class tree.
1553 * @see llvm::GlobalValue
1558 LLVMModuleRef LLVMGetGlobalParent(LLVMValueRef Global);
1559 LLVMBool LLVMIsDeclaration(LLVMValueRef Global);
1560 LLVMLinkage LLVMGetLinkage(LLVMValueRef Global);
1561 void LLVMSetLinkage(LLVMValueRef Global, LLVMLinkage Linkage);
1562 const char *LLVMGetSection(LLVMValueRef Global);
1563 void LLVMSetSection(LLVMValueRef Global, const char *Section);
1564 LLVMVisibility LLVMGetVisibility(LLVMValueRef Global);
1565 void LLVMSetVisibility(LLVMValueRef Global, LLVMVisibility Viz);
1566 unsigned LLVMGetAlignment(LLVMValueRef Global);
1567 void LLVMSetAlignment(LLVMValueRef Global, unsigned Bytes);
1570 * @defgroup LLVMCoreValueConstantGlobalVariable Global Variables
1572 * This group contains functions that operate on global variable values.
1574 * @see llvm::GlobalVariable
1578 LLVMValueRef LLVMAddGlobal(LLVMModuleRef M, LLVMTypeRef Ty, const char *Name);
1579 LLVMValueRef LLVMAddGlobalInAddressSpace(LLVMModuleRef M, LLVMTypeRef Ty,
1581 unsigned AddressSpace);
1582 LLVMValueRef LLVMGetNamedGlobal(LLVMModuleRef M, const char *Name);
1583 LLVMValueRef LLVMGetFirstGlobal(LLVMModuleRef M);
1584 LLVMValueRef LLVMGetLastGlobal(LLVMModuleRef M);
1585 LLVMValueRef LLVMGetNextGlobal(LLVMValueRef GlobalVar);
1586 LLVMValueRef LLVMGetPreviousGlobal(LLVMValueRef GlobalVar);
1587 void LLVMDeleteGlobal(LLVMValueRef GlobalVar);
1588 LLVMValueRef LLVMGetInitializer(LLVMValueRef GlobalVar);
1589 void LLVMSetInitializer(LLVMValueRef GlobalVar, LLVMValueRef ConstantVal);
1590 LLVMBool LLVMIsThreadLocal(LLVMValueRef GlobalVar);
1591 void LLVMSetThreadLocal(LLVMValueRef GlobalVar, LLVMBool IsThreadLocal);
1592 LLVMBool LLVMIsGlobalConstant(LLVMValueRef GlobalVar);
1593 void LLVMSetGlobalConstant(LLVMValueRef GlobalVar, LLVMBool IsConstant);
1600 * @defgroup LLVMCoreValueConstantGlobalAlias Global Aliases
1602 * This group contains function that operate on global alias values.
1604 * @see llvm::GlobalAlias
1608 LLVMValueRef LLVMAddAlias(LLVMModuleRef M, LLVMTypeRef Ty, LLVMValueRef Aliasee,
1616 * @defgroup LLVMCCoreValueFunction Function values
1618 * Functions in this group operate on LLVMValueRef instances that
1619 * correspond to llvm::Function instances.
1621 * @see llvm::Function
1627 * Remove a function from its containing module and deletes it.
1629 * @see llvm::Function::eraseFromParent()
1631 void LLVMDeleteFunction(LLVMValueRef Fn);
1634 * Obtain the ID number from a function instance.
1636 * @see llvm::Function::getIntrinsicID()
1638 unsigned LLVMGetIntrinsicID(LLVMValueRef Fn);
1641 * Obtain the calling function of a function.
1643 * The returned value corresponds to the LLVMCallConv enumeration.
1645 * @see llvm::Function::getCallingConv()
1647 unsigned LLVMGetFunctionCallConv(LLVMValueRef Fn);
1650 * Set the calling convention of a function.
1652 * @see llvm::Function::setCallingConv()
1654 * @param Fn Function to operate on
1655 * @param CC LLVMCallConv to set calling convention to
1657 void LLVMSetFunctionCallConv(LLVMValueRef Fn, unsigned CC);
1660 * Obtain the name of the garbage collector to use during code
1663 * @see llvm::Function::getGC()
1665 const char *LLVMGetGC(LLVMValueRef Fn);
1668 * Define the garbage collector to use during code generation.
1670 * @see llvm::Function::setGC()
1672 void LLVMSetGC(LLVMValueRef Fn, const char *Name);
1675 * Add an attribute to a function.
1677 * @see llvm::Function::addAttribute()
1679 void LLVMAddFunctionAttr(LLVMValueRef Fn, LLVMAttribute PA);
1682 * Obtain an attribute from a function.
1684 * @see llvm::Function::getAttributes()
1686 LLVMAttribute LLVMGetFunctionAttr(LLVMValueRef Fn);
1689 * Remove an attribute from a function.
1691 void LLVMRemoveFunctionAttr(LLVMValueRef Fn, LLVMAttribute PA);
1694 * @defgroup LLVMCCoreValueFunctionParameters Function Parameters
1696 * Functions in this group relate to arguments/parameters on functions.
1698 * Functions in this group expect LLVMValueRef instances that correspond
1699 * to llvm::Function instances.
1705 * Obtain the number of parameters in a function.
1707 * @see llvm::Function::arg_size()
1709 unsigned LLVMCountParams(LLVMValueRef Fn);
1712 * Obtain the parameters in a function.
1714 * The takes a pointer to a pre-allocated array of LLVMValueRef that is
1715 * at least LLVMCountParams() long. This array will be filled with
1716 * LLVMValueRef instances which correspond to the parameters the
1717 * function receives. Each LLVMValueRef corresponds to a llvm::Argument
1720 * @see llvm::Function::arg_begin()
1722 void LLVMGetParams(LLVMValueRef Fn, LLVMValueRef *Params);
1725 * Obtain the parameter at the specified index.
1727 * Parameters are indexed from 0.
1729 * @see llvm::Function::arg_begin()
1731 LLVMValueRef LLVMGetParam(LLVMValueRef Fn, unsigned Index);
1734 * Obtain the function to which this argument belongs.
1736 * Unlike other functions in this group, this one takes a LLVMValueRef
1737 * that corresponds to a llvm::Attribute.
1739 * The returned LLVMValueRef is the llvm::Function to which this
1742 LLVMValueRef LLVMGetParamParent(LLVMValueRef Inst);
1745 * Obtain the first parameter to a function.
1747 * @see llvm::Function::arg_begin()
1749 LLVMValueRef LLVMGetFirstParam(LLVMValueRef Fn);
1752 * Obtain the last parameter to a function.
1754 * @see llvm::Function::arg_end()
1756 LLVMValueRef LLVMGetLastParam(LLVMValueRef Fn);
1759 * Obtain the next parameter to a function.
1761 * This takes a LLVMValueRef obtained from LLVMGetFirstParam() (which is
1762 * actually a wrapped iterator) and obtains the next parameter from the
1763 * underlying iterator.
1765 LLVMValueRef LLVMGetNextParam(LLVMValueRef Arg);
1768 * Obtain the previous parameter to a function.
1770 * This is the opposite of LLVMGetNextParam().
1772 LLVMValueRef LLVMGetPreviousParam(LLVMValueRef Arg);
1775 * Add an attribute to a function argument.
1777 * @see llvm::Argument::addAttr()
1779 void LLVMAddAttribute(LLVMValueRef Arg, LLVMAttribute PA);
1782 * Remove an attribute from a function argument.
1784 * @see llvm::Argument::removeAttr()
1786 void LLVMRemoveAttribute(LLVMValueRef Arg, LLVMAttribute PA);
1789 * Get an attribute from a function argument.
1791 LLVMAttribute LLVMGetAttribute(LLVMValueRef Arg);
1794 * Set the alignment for a function parameter.
1796 * @see llvm::Argument::addAttr()
1797 * @see llvm::Attribute::constructAlignmentFromInt()
1799 void LLVMSetParamAlignment(LLVMValueRef Arg, unsigned align);
1818 * @defgroup LLVMCCoreValueMetadata Metadata
1824 * Obtain a MDString value from a context.
1826 * The returned instance corresponds to the llvm::MDString class.
1828 * The instance is specified by string data of a specified length. The
1829 * string content is copied, so the backing memory can be freed after
1830 * this function returns.
1832 LLVMValueRef LLVMMDStringInContext(LLVMContextRef C, const char *Str,
1836 * Obtain a MDString value from the global context.
1838 LLVMValueRef LLVMMDString(const char *Str, unsigned SLen);
1841 * Obtain a MDNode value from a context.
1843 * The returned value corresponds to the llvm::MDNode class.
1845 LLVMValueRef LLVMMDNodeInContext(LLVMContextRef C, LLVMValueRef *Vals,
1849 * Obtain a MDNode value from the global context.
1851 LLVMValueRef LLVMMDNode(LLVMValueRef *Vals, unsigned Count);
1854 * Obtain the underlying string from a MDString value.
1856 * @param V Instance to obtain string from.
1857 * @param Len Memory address which will hold length of returned string.
1858 * @return String data in MDString.
1860 const char *LLVMGetMDString(LLVMValueRef V, unsigned* Len);
1867 * @defgroup LLVMCCoreValueBasicBlock Basic Block
1869 * A basic block represents a single entry single exit section of code.
1870 * Basic blocks contain a list of instructions which form the body of
1873 * Basic blocks belong to functions. They have the type of label.
1875 * Basic blocks are themselves values. However, the C API models them as
1876 * LLVMBasicBlockRef.
1878 * @see llvm::BasicBlock
1884 * Convert a basic block instance to a value type.
1886 LLVMValueRef LLVMBasicBlockAsValue(LLVMBasicBlockRef BB);
1889 * Determine whether a LLVMValueRef is itself a basic block.
1891 LLVMBool LLVMValueIsBasicBlock(LLVMValueRef Val);
1894 * Convert a LLVMValueRef to a LLVMBasicBlockRef instance.
1896 LLVMBasicBlockRef LLVMValueAsBasicBlock(LLVMValueRef Val);
1899 * Obtain the function to which a basic block belongs.
1901 * @see llvm::BasicBlock::getParent()
1903 LLVMValueRef LLVMGetBasicBlockParent(LLVMBasicBlockRef BB);
1906 * Obtain the terminator instruction for a basic block.
1908 * If the basic block does not have a terminator (it is not well-formed
1909 * if it doesn't), then NULL is returned.
1911 * The returned LLVMValueRef corresponds to a llvm::TerminatorInst.
1913 * @see llvm::BasicBlock::getTerminator()
1915 LLVMValueRef LLVMGetBasicBlockTerminator(LLVMBasicBlockRef BB);
1918 * Obtain the number of basic blocks in a function.
1920 * @param Fn Function value to operate on.
1922 unsigned LLVMCountBasicBlocks(LLVMValueRef Fn);
1925 * Obtain all of the basic blocks in a function.
1927 * This operates on a function value. The BasicBlocks parameter is a
1928 * pointer to a pre-allocated array of LLVMBasicBlockRef of at least
1929 * LLVMCountBasicBlocks() in length. This array is populated with
1930 * LLVMBasicBlockRef instances.
1932 void LLVMGetBasicBlocks(LLVMValueRef Fn, LLVMBasicBlockRef *BasicBlocks);
1935 * Obtain the first basic block in a function.
1937 * The returned basic block can be used as an iterator. You will likely
1938 * eventually call into LLVMGetNextBasicBlock() with it.
1940 * @see llvm::Function::begin()
1942 LLVMBasicBlockRef LLVMGetFirstBasicBlock(LLVMValueRef Fn);
1945 * Obtain the last basic block in a function.
1947 * @see llvm::Function::end()
1949 LLVMBasicBlockRef LLVMGetLastBasicBlock(LLVMValueRef Fn);
1952 * Advance a basic block iterator.
1954 LLVMBasicBlockRef LLVMGetNextBasicBlock(LLVMBasicBlockRef BB);
1957 * Go backwards in a basic block iterator.
1959 LLVMBasicBlockRef LLVMGetPreviousBasicBlock(LLVMBasicBlockRef BB);
1962 * Obtain the basic block that corresponds to the entry point of a
1965 * @see llvm::Function::getEntryBlock()
1967 LLVMBasicBlockRef LLVMGetEntryBasicBlock(LLVMValueRef Fn);
1970 * Append a basic block to the end of a function.
1972 * @see llvm::BasicBlock::Create()
1974 LLVMBasicBlockRef LLVMAppendBasicBlockInContext(LLVMContextRef C,
1979 * Append a basic block to the end of a function using the global
1982 * @see llvm::BasicBlock::Create()
1984 LLVMBasicBlockRef LLVMAppendBasicBlock(LLVMValueRef Fn, const char *Name);
1987 * Insert a basic block in a function before another basic block.
1989 * The function to add to is determined by the function of the
1990 * passed basic block.
1992 * @see llvm::BasicBlock::Create()
1994 LLVMBasicBlockRef LLVMInsertBasicBlockInContext(LLVMContextRef C,
1995 LLVMBasicBlockRef BB,
1999 * Insert a basic block in a function using the global context.
2001 * @see llvm::BasicBlock::Create()
2003 LLVMBasicBlockRef LLVMInsertBasicBlock(LLVMBasicBlockRef InsertBeforeBB,
2007 * Remove a basic block from a function and delete it.
2009 * This deletes the basic block from its containing function and deletes
2010 * the basic block itself.
2012 * @see llvm::BasicBlock::eraseFromParent()
2014 void LLVMDeleteBasicBlock(LLVMBasicBlockRef BB);
2017 * Remove a basic block from a function.
2019 * This deletes the basic block from its containing function but keep
2020 * the basic block alive.
2022 * @see llvm::BasicBlock::removeFromParent()
2024 void LLVMRemoveBasicBlockFromParent(LLVMBasicBlockRef BB);
2027 * Move a basic block to before another one.
2029 * @see llvm::BasicBlock::moveBefore()
2031 void LLVMMoveBasicBlockBefore(LLVMBasicBlockRef BB, LLVMBasicBlockRef MovePos);
2034 * Move a basic block to after another one.
2036 * @see llvm::BasicBlock::moveAfter()
2038 void LLVMMoveBasicBlockAfter(LLVMBasicBlockRef BB, LLVMBasicBlockRef MovePos);
2041 * Obtain the first instruction in a basic block.
2043 * The returned LLVMValueRef corresponds to a llvm::Instruction
2046 LLVMValueRef LLVMGetFirstInstruction(LLVMBasicBlockRef BB);
2049 * Obtain the last instruction in a basic block.
2051 * The returned LLVMValueRef corresponds to a LLVM:Instruction.
2053 LLVMValueRef LLVMGetLastInstruction(LLVMBasicBlockRef BB);
2060 * @defgroup LLVMCCoreValueInstruction Instructions
2062 * Functions in this group relate to the inspection and manipulation of
2063 * individual instructions.
2065 * In the C++ API, an instruction is modeled by llvm::Instruction. This
2066 * class has a large number of descendents. llvm::Instruction is a
2067 * llvm::Value and in the C API, instructions are modeled by
2070 * This group also contains sub-groups which operate on specific
2071 * llvm::Instruction types, e.g. llvm::CallInst.
2077 * Determine whether an instruction has any metadata attached.
2079 int LLVMHasMetadata(LLVMValueRef Val);
2082 * Return metadata associated with an instruction value.
2084 LLVMValueRef LLVMGetMetadata(LLVMValueRef Val, unsigned KindID);
2087 * Set metadata associated with an instruction value.
2089 void LLVMSetMetadata(LLVMValueRef Val, unsigned KindID, LLVMValueRef Node);
2092 * Obtain the basic block to which an instruction belongs.
2094 * @see llvm::Instruction::getParent()
2096 LLVMBasicBlockRef LLVMGetInstructionParent(LLVMValueRef Inst);
2099 * Obtain the instruction that occurs after the one specified.
2101 * The next instruction will be from the same basic block.
2103 * If this is the last instruction in a basic block, NULL will be
2106 LLVMValueRef LLVMGetNextInstruction(LLVMValueRef Inst);
2109 * Obtain the instruction that occured before this one.
2111 * If the instruction is the first instruction in a basic block, NULL
2114 LLVMValueRef LLVMGetPreviousInstruction(LLVMValueRef Inst);
2117 * Remove and delete an instruction.
2119 * The instruction specified is removed from its containing building
2120 * block and then deleted.
2122 * @see llvm::Instruction::eraseFromParent()
2124 void LLVMInstructionEraseFromParent(LLVMValueRef Inst);
2127 * Obtain the code opcode for an individual instruction.
2129 * @see llvm::Instruction::getOpCode()
2131 LLVMOpcode LLVMGetInstructionOpcode(LLVMValueRef Inst);
2134 * Obtain the predicate of an instruction.
2136 * This is only valid for instructions that correspond to llvm::ICmpInst
2137 * or llvm::ConstantExpr whose opcode is llvm::Instruction::ICmp.
2139 * @see llvm::ICmpInst::getPredicate()
2141 LLVMIntPredicate LLVMGetICmpPredicate(LLVMValueRef Inst);
2144 * @defgroup LLVMCCoreValueInstructionCall Call Sites and Invocations
2146 * Functions in this group apply to instructions that refer to call
2147 * sites and invocations. These correspond to C++ types in the
2148 * llvm::CallInst class tree.
2154 * Set the calling convention for a call instruction.
2156 * This expects an LLVMValueRef that corresponds to a llvm::CallInst or
2159 * @see llvm::CallInst::setCallingConv()
2160 * @see llvm::InvokeInst::setCallingConv()
2162 void LLVMSetInstructionCallConv(LLVMValueRef Instr, unsigned CC);
2165 * Obtain the calling convention for a call instruction.
2167 * This is the opposite of LLVMSetInstructionCallConv(). Reads its
2170 * @see LLVMSetInstructionCallConv()
2172 unsigned LLVMGetInstructionCallConv(LLVMValueRef Instr);
2175 void LLVMAddInstrAttribute(LLVMValueRef Instr, unsigned index, LLVMAttribute);
2176 void LLVMRemoveInstrAttribute(LLVMValueRef Instr, unsigned index,
2178 void LLVMSetInstrParamAlignment(LLVMValueRef Instr, unsigned index,
2182 * Obtain whether a call instruction is a tail call.
2184 * This only works on llvm::CallInst instructions.
2186 * @see llvm::CallInst::isTailCall()
2188 LLVMBool LLVMIsTailCall(LLVMValueRef CallInst);
2191 * Set whether a call instruction is a tail call.
2193 * This only works on llvm::CallInst instructions.
2195 * @see llvm::CallInst::setTailCall()
2197 void LLVMSetTailCall(LLVMValueRef CallInst, LLVMBool IsTailCall);
2204 * Obtain the default destination basic block of a switch instruction.
2206 * This only works on llvm::SwitchInst instructions.
2208 * @see llvm::SwitchInst::getDefaultDest()
2210 LLVMBasicBlockRef LLVMGetSwitchDefaultDest(LLVMValueRef SwitchInstr);
2213 * @defgroup LLVMCCoreValueInstructionPHINode PHI Nodes
2215 * Functions in this group only apply to instructions that map to
2216 * llvm::PHINode instances.
2222 * Add an incoming value to the end of a PHI list.
2224 void LLVMAddIncoming(LLVMValueRef PhiNode, LLVMValueRef *IncomingValues,
2225 LLVMBasicBlockRef *IncomingBlocks, unsigned Count);
2228 * Obtain the number of incoming basic blocks to a PHI node.
2230 unsigned LLVMCountIncoming(LLVMValueRef PhiNode);
2233 * Obtain an incoming value to a PHI node as a LLVMValueRef.
2235 LLVMValueRef LLVMGetIncomingValue(LLVMValueRef PhiNode, unsigned Index);
2238 * Obtain an incoming value to a PHI node as a LLVMBasicBlockRef.
2240 LLVMBasicBlockRef LLVMGetIncomingBlock(LLVMValueRef PhiNode, unsigned Index);
2255 * @defgroup LLVMCCoreInstructionBuilder Instruction Builders
2257 * An instruction builder represents a point within a basic block and is
2258 * the exclusive means of building instructions using the C interface.
2263 LLVMBuilderRef LLVMCreateBuilderInContext(LLVMContextRef C);
2264 LLVMBuilderRef LLVMCreateBuilder(void);
2265 void LLVMPositionBuilder(LLVMBuilderRef Builder, LLVMBasicBlockRef Block,
2266 LLVMValueRef Instr);
2267 void LLVMPositionBuilderBefore(LLVMBuilderRef Builder, LLVMValueRef Instr);
2268 void LLVMPositionBuilderAtEnd(LLVMBuilderRef Builder, LLVMBasicBlockRef Block);
2269 LLVMBasicBlockRef LLVMGetInsertBlock(LLVMBuilderRef Builder);
2270 void LLVMClearInsertionPosition(LLVMBuilderRef Builder);
2271 void LLVMInsertIntoBuilder(LLVMBuilderRef Builder, LLVMValueRef Instr);
2272 void LLVMInsertIntoBuilderWithName(LLVMBuilderRef Builder, LLVMValueRef Instr,
2274 void LLVMDisposeBuilder(LLVMBuilderRef Builder);
2277 void LLVMSetCurrentDebugLocation(LLVMBuilderRef Builder, LLVMValueRef L);
2278 LLVMValueRef LLVMGetCurrentDebugLocation(LLVMBuilderRef Builder);
2279 void LLVMSetInstDebugLocation(LLVMBuilderRef Builder, LLVMValueRef Inst);
2282 LLVMValueRef LLVMBuildRetVoid(LLVMBuilderRef);
2283 LLVMValueRef LLVMBuildRet(LLVMBuilderRef, LLVMValueRef V);
2284 LLVMValueRef LLVMBuildAggregateRet(LLVMBuilderRef, LLVMValueRef *RetVals,
2286 LLVMValueRef LLVMBuildBr(LLVMBuilderRef, LLVMBasicBlockRef Dest);
2287 LLVMValueRef LLVMBuildCondBr(LLVMBuilderRef, LLVMValueRef If,
2288 LLVMBasicBlockRef Then, LLVMBasicBlockRef Else);
2289 LLVMValueRef LLVMBuildSwitch(LLVMBuilderRef, LLVMValueRef V,
2290 LLVMBasicBlockRef Else, unsigned NumCases);
2291 LLVMValueRef LLVMBuildIndirectBr(LLVMBuilderRef B, LLVMValueRef Addr,
2293 LLVMValueRef LLVMBuildInvoke(LLVMBuilderRef, LLVMValueRef Fn,
2294 LLVMValueRef *Args, unsigned NumArgs,
2295 LLVMBasicBlockRef Then, LLVMBasicBlockRef Catch,
2297 LLVMValueRef LLVMBuildLandingPad(LLVMBuilderRef B, LLVMTypeRef Ty,
2298 LLVMValueRef PersFn, unsigned NumClauses,
2300 LLVMValueRef LLVMBuildResume(LLVMBuilderRef B, LLVMValueRef Exn);
2301 LLVMValueRef LLVMBuildUnreachable(LLVMBuilderRef);
2303 /* Add a case to the switch instruction */
2304 void LLVMAddCase(LLVMValueRef Switch, LLVMValueRef OnVal,
2305 LLVMBasicBlockRef Dest);
2307 /* Add a destination to the indirectbr instruction */
2308 void LLVMAddDestination(LLVMValueRef IndirectBr, LLVMBasicBlockRef Dest);
2310 /* Add a catch or filter clause to the landingpad instruction */
2311 void LLVMAddClause(LLVMValueRef LandingPad, LLVMValueRef ClauseVal);
2313 /* Set the 'cleanup' flag in the landingpad instruction */
2314 void LLVMSetCleanup(LLVMValueRef LandingPad, LLVMBool Val);
2317 LLVMValueRef LLVMBuildAdd(LLVMBuilderRef, LLVMValueRef LHS, LLVMValueRef RHS,
2319 LLVMValueRef LLVMBuildNSWAdd(LLVMBuilderRef, LLVMValueRef LHS, LLVMValueRef RHS,
2321 LLVMValueRef LLVMBuildNUWAdd(LLVMBuilderRef, LLVMValueRef LHS, LLVMValueRef RHS,
2323 LLVMValueRef LLVMBuildFAdd(LLVMBuilderRef, LLVMValueRef LHS, LLVMValueRef RHS,
2325 LLVMValueRef LLVMBuildSub(LLVMBuilderRef, LLVMValueRef LHS, LLVMValueRef RHS,
2327 LLVMValueRef LLVMBuildNSWSub(LLVMBuilderRef, LLVMValueRef LHS, LLVMValueRef RHS,
2329 LLVMValueRef LLVMBuildNUWSub(LLVMBuilderRef, LLVMValueRef LHS, LLVMValueRef RHS,
2331 LLVMValueRef LLVMBuildFSub(LLVMBuilderRef, LLVMValueRef LHS, LLVMValueRef RHS,
2333 LLVMValueRef LLVMBuildMul(LLVMBuilderRef, LLVMValueRef LHS, LLVMValueRef RHS,
2335 LLVMValueRef LLVMBuildNSWMul(LLVMBuilderRef, LLVMValueRef LHS, LLVMValueRef RHS,
2337 LLVMValueRef LLVMBuildNUWMul(LLVMBuilderRef, LLVMValueRef LHS, LLVMValueRef RHS,
2339 LLVMValueRef LLVMBuildFMul(LLVMBuilderRef, LLVMValueRef LHS, LLVMValueRef RHS,
2341 LLVMValueRef LLVMBuildUDiv(LLVMBuilderRef, LLVMValueRef LHS, LLVMValueRef RHS,
2343 LLVMValueRef LLVMBuildSDiv(LLVMBuilderRef, LLVMValueRef LHS, LLVMValueRef RHS,
2345 LLVMValueRef LLVMBuildExactSDiv(LLVMBuilderRef, LLVMValueRef LHS, LLVMValueRef RHS,
2347 LLVMValueRef LLVMBuildFDiv(LLVMBuilderRef, LLVMValueRef LHS, LLVMValueRef RHS,
2349 LLVMValueRef LLVMBuildURem(LLVMBuilderRef, LLVMValueRef LHS, LLVMValueRef RHS,
2351 LLVMValueRef LLVMBuildSRem(LLVMBuilderRef, LLVMValueRef LHS, LLVMValueRef RHS,
2353 LLVMValueRef LLVMBuildFRem(LLVMBuilderRef, LLVMValueRef LHS, LLVMValueRef RHS,
2355 LLVMValueRef LLVMBuildShl(LLVMBuilderRef, LLVMValueRef LHS, LLVMValueRef RHS,
2357 LLVMValueRef LLVMBuildLShr(LLVMBuilderRef, LLVMValueRef LHS, LLVMValueRef RHS,
2359 LLVMValueRef LLVMBuildAShr(LLVMBuilderRef, LLVMValueRef LHS, LLVMValueRef RHS,
2361 LLVMValueRef LLVMBuildAnd(LLVMBuilderRef, LLVMValueRef LHS, LLVMValueRef RHS,
2363 LLVMValueRef LLVMBuildOr(LLVMBuilderRef, LLVMValueRef LHS, LLVMValueRef RHS,
2365 LLVMValueRef LLVMBuildXor(LLVMBuilderRef, LLVMValueRef LHS, LLVMValueRef RHS,
2367 LLVMValueRef LLVMBuildBinOp(LLVMBuilderRef B, LLVMOpcode Op,
2368 LLVMValueRef LHS, LLVMValueRef RHS,
2370 LLVMValueRef LLVMBuildNeg(LLVMBuilderRef, LLVMValueRef V, const char *Name);
2371 LLVMValueRef LLVMBuildNSWNeg(LLVMBuilderRef B, LLVMValueRef V,
2373 LLVMValueRef LLVMBuildNUWNeg(LLVMBuilderRef B, LLVMValueRef V,
2375 LLVMValueRef LLVMBuildFNeg(LLVMBuilderRef, LLVMValueRef V, const char *Name);
2376 LLVMValueRef LLVMBuildNot(LLVMBuilderRef, LLVMValueRef V, const char *Name);
2379 LLVMValueRef LLVMBuildMalloc(LLVMBuilderRef, LLVMTypeRef Ty, const char *Name);
2380 LLVMValueRef LLVMBuildArrayMalloc(LLVMBuilderRef, LLVMTypeRef Ty,
2381 LLVMValueRef Val, const char *Name);
2382 LLVMValueRef LLVMBuildAlloca(LLVMBuilderRef, LLVMTypeRef Ty, const char *Name);
2383 LLVMValueRef LLVMBuildArrayAlloca(LLVMBuilderRef, LLVMTypeRef Ty,
2384 LLVMValueRef Val, const char *Name);
2385 LLVMValueRef LLVMBuildFree(LLVMBuilderRef, LLVMValueRef PointerVal);
2386 LLVMValueRef LLVMBuildLoad(LLVMBuilderRef, LLVMValueRef PointerVal,
2388 LLVMValueRef LLVMBuildStore(LLVMBuilderRef, LLVMValueRef Val, LLVMValueRef Ptr);
2389 LLVMValueRef LLVMBuildGEP(LLVMBuilderRef B, LLVMValueRef Pointer,
2390 LLVMValueRef *Indices, unsigned NumIndices,
2392 LLVMValueRef LLVMBuildInBoundsGEP(LLVMBuilderRef B, LLVMValueRef Pointer,
2393 LLVMValueRef *Indices, unsigned NumIndices,
2395 LLVMValueRef LLVMBuildStructGEP(LLVMBuilderRef B, LLVMValueRef Pointer,
2396 unsigned Idx, const char *Name);
2397 LLVMValueRef LLVMBuildGlobalString(LLVMBuilderRef B, const char *Str,
2399 LLVMValueRef LLVMBuildGlobalStringPtr(LLVMBuilderRef B, const char *Str,
2401 LLVMBool LLVMGetVolatile(LLVMValueRef MemoryAccessInst);
2402 void LLVMSetVolatile(LLVMValueRef MemoryAccessInst, LLVMBool IsVolatile);
2405 LLVMValueRef LLVMBuildTrunc(LLVMBuilderRef, LLVMValueRef Val,
2406 LLVMTypeRef DestTy, const char *Name);
2407 LLVMValueRef LLVMBuildZExt(LLVMBuilderRef, LLVMValueRef Val,
2408 LLVMTypeRef DestTy, const char *Name);
2409 LLVMValueRef LLVMBuildSExt(LLVMBuilderRef, LLVMValueRef Val,
2410 LLVMTypeRef DestTy, const char *Name);
2411 LLVMValueRef LLVMBuildFPToUI(LLVMBuilderRef, LLVMValueRef Val,
2412 LLVMTypeRef DestTy, const char *Name);
2413 LLVMValueRef LLVMBuildFPToSI(LLVMBuilderRef, LLVMValueRef Val,
2414 LLVMTypeRef DestTy, const char *Name);
2415 LLVMValueRef LLVMBuildUIToFP(LLVMBuilderRef, LLVMValueRef Val,
2416 LLVMTypeRef DestTy, const char *Name);
2417 LLVMValueRef LLVMBuildSIToFP(LLVMBuilderRef, LLVMValueRef Val,
2418 LLVMTypeRef DestTy, const char *Name);
2419 LLVMValueRef LLVMBuildFPTrunc(LLVMBuilderRef, LLVMValueRef Val,
2420 LLVMTypeRef DestTy, const char *Name);
2421 LLVMValueRef LLVMBuildFPExt(LLVMBuilderRef, LLVMValueRef Val,
2422 LLVMTypeRef DestTy, const char *Name);
2423 LLVMValueRef LLVMBuildPtrToInt(LLVMBuilderRef, LLVMValueRef Val,
2424 LLVMTypeRef DestTy, const char *Name);
2425 LLVMValueRef LLVMBuildIntToPtr(LLVMBuilderRef, LLVMValueRef Val,
2426 LLVMTypeRef DestTy, const char *Name);
2427 LLVMValueRef LLVMBuildBitCast(LLVMBuilderRef, LLVMValueRef Val,
2428 LLVMTypeRef DestTy, const char *Name);
2429 LLVMValueRef LLVMBuildZExtOrBitCast(LLVMBuilderRef, LLVMValueRef Val,
2430 LLVMTypeRef DestTy, const char *Name);
2431 LLVMValueRef LLVMBuildSExtOrBitCast(LLVMBuilderRef, LLVMValueRef Val,
2432 LLVMTypeRef DestTy, const char *Name);
2433 LLVMValueRef LLVMBuildTruncOrBitCast(LLVMBuilderRef, LLVMValueRef Val,
2434 LLVMTypeRef DestTy, const char *Name);
2435 LLVMValueRef LLVMBuildCast(LLVMBuilderRef B, LLVMOpcode Op, LLVMValueRef Val,
2436 LLVMTypeRef DestTy, const char *Name);
2437 LLVMValueRef LLVMBuildPointerCast(LLVMBuilderRef, LLVMValueRef Val,
2438 LLVMTypeRef DestTy, const char *Name);
2439 LLVMValueRef LLVMBuildIntCast(LLVMBuilderRef, LLVMValueRef Val, /*Signed cast!*/
2440 LLVMTypeRef DestTy, const char *Name);
2441 LLVMValueRef LLVMBuildFPCast(LLVMBuilderRef, LLVMValueRef Val,
2442 LLVMTypeRef DestTy, const char *Name);
2445 LLVMValueRef LLVMBuildICmp(LLVMBuilderRef, LLVMIntPredicate Op,
2446 LLVMValueRef LHS, LLVMValueRef RHS,
2448 LLVMValueRef LLVMBuildFCmp(LLVMBuilderRef, LLVMRealPredicate Op,
2449 LLVMValueRef LHS, LLVMValueRef RHS,
2452 /* Miscellaneous instructions */
2453 LLVMValueRef LLVMBuildPhi(LLVMBuilderRef, LLVMTypeRef Ty, const char *Name);
2454 LLVMValueRef LLVMBuildCall(LLVMBuilderRef, LLVMValueRef Fn,
2455 LLVMValueRef *Args, unsigned NumArgs,
2457 LLVMValueRef LLVMBuildSelect(LLVMBuilderRef, LLVMValueRef If,
2458 LLVMValueRef Then, LLVMValueRef Else,
2460 LLVMValueRef LLVMBuildVAArg(LLVMBuilderRef, LLVMValueRef List, LLVMTypeRef Ty,
2462 LLVMValueRef LLVMBuildExtractElement(LLVMBuilderRef, LLVMValueRef VecVal,
2463 LLVMValueRef Index, const char *Name);
2464 LLVMValueRef LLVMBuildInsertElement(LLVMBuilderRef, LLVMValueRef VecVal,
2465 LLVMValueRef EltVal, LLVMValueRef Index,
2467 LLVMValueRef LLVMBuildShuffleVector(LLVMBuilderRef, LLVMValueRef V1,
2468 LLVMValueRef V2, LLVMValueRef Mask,
2470 LLVMValueRef LLVMBuildExtractValue(LLVMBuilderRef, LLVMValueRef AggVal,
2471 unsigned Index, const char *Name);
2472 LLVMValueRef LLVMBuildInsertValue(LLVMBuilderRef, LLVMValueRef AggVal,
2473 LLVMValueRef EltVal, unsigned Index,
2476 LLVMValueRef LLVMBuildIsNull(LLVMBuilderRef, LLVMValueRef Val,
2478 LLVMValueRef LLVMBuildIsNotNull(LLVMBuilderRef, LLVMValueRef Val,
2480 LLVMValueRef LLVMBuildPtrDiff(LLVMBuilderRef, LLVMValueRef LHS,
2481 LLVMValueRef RHS, const char *Name);
2488 * @defgroup LLVMCCoreModuleProvider Module Providers
2494 * Changes the type of M so it can be passed to FunctionPassManagers and the
2495 * JIT. They take ModuleProviders for historical reasons.
2497 LLVMModuleProviderRef
2498 LLVMCreateModuleProviderForExistingModule(LLVMModuleRef M);
2501 * Destroys the module M.
2503 void LLVMDisposeModuleProvider(LLVMModuleProviderRef M);
2510 * @defgroup LLVMCCoreMemoryBuffers Memory Buffers
2515 LLVMBool LLVMCreateMemoryBufferWithContentsOfFile(const char *Path,
2516 LLVMMemoryBufferRef *OutMemBuf,
2518 LLVMBool LLVMCreateMemoryBufferWithSTDIN(LLVMMemoryBufferRef *OutMemBuf,
2520 void LLVMDisposeMemoryBuffer(LLVMMemoryBufferRef MemBuf);
2527 * @defgroup LLVMCCorePassRegistry Pass Registry
2532 /** Return the global pass registry, for use with initialization functions.
2533 @see llvm::PassRegistry::getPassRegistry */
2534 LLVMPassRegistryRef LLVMGetGlobalPassRegistry(void);
2541 * @defgroup LLVMCCorePassManagers Pass Managers
2546 /** Constructs a new whole-module pass pipeline. This type of pipeline is
2547 suitable for link-time optimization and whole-module transformations.
2548 @see llvm::PassManager::PassManager */
2549 LLVMPassManagerRef LLVMCreatePassManager(void);
2551 /** Constructs a new function-by-function pass pipeline over the module
2552 provider. It does not take ownership of the module provider. This type of
2553 pipeline is suitable for code generation and JIT compilation tasks.
2554 @see llvm::FunctionPassManager::FunctionPassManager */
2555 LLVMPassManagerRef LLVMCreateFunctionPassManagerForModule(LLVMModuleRef M);
2557 /** Deprecated: Use LLVMCreateFunctionPassManagerForModule instead. */
2558 LLVMPassManagerRef LLVMCreateFunctionPassManager(LLVMModuleProviderRef MP);
2560 /** Initializes, executes on the provided module, and finalizes all of the
2561 passes scheduled in the pass manager. Returns 1 if any of the passes
2562 modified the module, 0 otherwise.
2563 @see llvm::PassManager::run(Module&) */
2564 LLVMBool LLVMRunPassManager(LLVMPassManagerRef PM, LLVMModuleRef M);
2566 /** Initializes all of the function passes scheduled in the function pass
2567 manager. Returns 1 if any of the passes modified the module, 0 otherwise.
2568 @see llvm::FunctionPassManager::doInitialization */
2569 LLVMBool LLVMInitializeFunctionPassManager(LLVMPassManagerRef FPM);
2571 /** Executes all of the function passes scheduled in the function pass manager
2572 on the provided function. Returns 1 if any of the passes modified the
2573 function, false otherwise.
2574 @see llvm::FunctionPassManager::run(Function&) */
2575 LLVMBool LLVMRunFunctionPassManager(LLVMPassManagerRef FPM, LLVMValueRef F);
2577 /** Finalizes all of the function passes scheduled in in the function pass
2578 manager. Returns 1 if any of the passes modified the module, 0 otherwise.
2579 @see llvm::FunctionPassManager::doFinalization */
2580 LLVMBool LLVMFinalizeFunctionPassManager(LLVMPassManagerRef FPM);
2582 /** Frees the memory of a pass pipeline. For function pipelines, does not free
2583 the module provider.
2584 @see llvm::PassManagerBase::~PassManagerBase. */
2585 void LLVMDisposePassManager(LLVMPassManagerRef PM);
2604 class PassManagerBase;
2606 #define DEFINE_SIMPLE_CONVERSION_FUNCTIONS(ty, ref) \
2607 inline ty *unwrap(ref P) { \
2608 return reinterpret_cast<ty*>(P); \
2611 inline ref wrap(const ty *P) { \
2612 return reinterpret_cast<ref>(const_cast<ty*>(P)); \
2615 #define DEFINE_ISA_CONVERSION_FUNCTIONS(ty, ref) \
2616 DEFINE_SIMPLE_CONVERSION_FUNCTIONS(ty, ref) \
2618 template<typename T> \
2619 inline T *unwrap(ref P) { \
2620 return cast<T>(unwrap(P)); \
2623 #define DEFINE_STDCXX_CONVERSION_FUNCTIONS(ty, ref) \
2624 DEFINE_SIMPLE_CONVERSION_FUNCTIONS(ty, ref) \
2626 template<typename T> \
2627 inline T *unwrap(ref P) { \
2628 T *Q = (T*)unwrap(P); \
2629 assert(Q && "Invalid cast!"); \
2633 DEFINE_ISA_CONVERSION_FUNCTIONS (Type, LLVMTypeRef )
2634 DEFINE_ISA_CONVERSION_FUNCTIONS (Value, LLVMValueRef )
2635 DEFINE_SIMPLE_CONVERSION_FUNCTIONS(Module, LLVMModuleRef )
2636 DEFINE_SIMPLE_CONVERSION_FUNCTIONS(BasicBlock, LLVMBasicBlockRef )
2637 DEFINE_SIMPLE_CONVERSION_FUNCTIONS(IRBuilder<>, LLVMBuilderRef )
2638 DEFINE_SIMPLE_CONVERSION_FUNCTIONS(MemoryBuffer, LLVMMemoryBufferRef )
2639 DEFINE_SIMPLE_CONVERSION_FUNCTIONS(LLVMContext, LLVMContextRef )
2640 DEFINE_SIMPLE_CONVERSION_FUNCTIONS(Use, LLVMUseRef )
2641 DEFINE_STDCXX_CONVERSION_FUNCTIONS(PassManagerBase, LLVMPassManagerRef )
2642 DEFINE_STDCXX_CONVERSION_FUNCTIONS(PassRegistry, LLVMPassRegistryRef )
2643 /* LLVMModuleProviderRef exists for historical reasons, but now just holds a
2646 inline Module *unwrap(LLVMModuleProviderRef MP) {
2647 return reinterpret_cast<Module*>(MP);
2650 #undef DEFINE_STDCXX_CONVERSION_FUNCTIONS
2651 #undef DEFINE_ISA_CONVERSION_FUNCTIONS
2652 #undef DEFINE_SIMPLE_CONVERSION_FUNCTIONS
2654 /* Specialized opaque context conversions.
2656 inline LLVMContext **unwrap(LLVMContextRef* Tys) {
2657 return reinterpret_cast<LLVMContext**>(Tys);
2660 inline LLVMContextRef *wrap(const LLVMContext **Tys) {
2661 return reinterpret_cast<LLVMContextRef*>(const_cast<LLVMContext**>(Tys));
2664 /* Specialized opaque type conversions.
2666 inline Type **unwrap(LLVMTypeRef* Tys) {
2667 return reinterpret_cast<Type**>(Tys);
2670 inline LLVMTypeRef *wrap(Type **Tys) {
2671 return reinterpret_cast<LLVMTypeRef*>(const_cast<Type**>(Tys));
2674 /* Specialized opaque value conversions.
2676 inline Value **unwrap(LLVMValueRef *Vals) {
2677 return reinterpret_cast<Value**>(Vals);
2680 template<typename T>
2681 inline T **unwrap(LLVMValueRef *Vals, unsigned Length) {
2683 for (LLVMValueRef *I = Vals, *E = Vals + Length; I != E; ++I)
2687 return reinterpret_cast<T**>(Vals);
2690 inline LLVMValueRef *wrap(const Value **Vals) {
2691 return reinterpret_cast<LLVMValueRef*>(const_cast<Value**>(Vals));
2695 #endif /* !defined(__cplusplus) */
2697 #endif /* !defined(LLVM_C_CORE_H) */