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/IR/IRBuilder.h"
25 #include "llvm/IR/Module.h"
26 #include "llvm/PassRegistry.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 parameter 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 instructions 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: These attributes are 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,
180 LLVMStackProtectStrongAttribute = 1ULL<<33
185 /* Terminator Instructions */
191 /* removed 6 due to API changes */
194 /* Standard Binary Operators */
208 /* Logical Operators */
216 /* Memory Operators */
220 LLVMGetElementPtr = 29,
236 /* Other Operators */
245 LLVMExtractElement = 50,
246 LLVMInsertElement = 51,
247 LLVMShuffleVector = 52,
248 LLVMExtractValue = 53,
249 LLVMInsertValue = 54,
251 /* Atomic operators */
253 LLVMAtomicCmpXchg = 56,
256 /* Exception Handling Operators */
263 LLVMVoidTypeKind, /**< type with no size */
264 LLVMHalfTypeKind, /**< 16 bit floating point type */
265 LLVMFloatTypeKind, /**< 32 bit floating point type */
266 LLVMDoubleTypeKind, /**< 64 bit floating point type */
267 LLVMX86_FP80TypeKind, /**< 80 bit floating point type (X87) */
268 LLVMFP128TypeKind, /**< 128 bit floating point type (112-bit mantissa)*/
269 LLVMPPC_FP128TypeKind, /**< 128 bit floating point type (two 64-bits) */
270 LLVMLabelTypeKind, /**< Labels */
271 LLVMIntegerTypeKind, /**< Arbitrary bit width integers */
272 LLVMFunctionTypeKind, /**< Functions */
273 LLVMStructTypeKind, /**< Structures */
274 LLVMArrayTypeKind, /**< Arrays */
275 LLVMPointerTypeKind, /**< Pointers */
276 LLVMVectorTypeKind, /**< SIMD 'packed' format, or other vector type */
277 LLVMMetadataTypeKind, /**< Metadata */
278 LLVMX86_MMXTypeKind /**< X86 MMX */
282 LLVMExternalLinkage, /**< Externally visible function */
283 LLVMAvailableExternallyLinkage,
284 LLVMLinkOnceAnyLinkage, /**< Keep one copy of function when linking (inline)*/
285 LLVMLinkOnceODRLinkage, /**< Same, but only replaced by something
287 LLVMLinkOnceODRAutoHideLinkage, /**< Like LinkOnceODR, but possibly hidden. */
288 LLVMWeakAnyLinkage, /**< Keep one copy of function when linking (weak) */
289 LLVMWeakODRLinkage, /**< Same, but only replaced by something
291 LLVMAppendingLinkage, /**< Special purpose, only applies to global arrays */
292 LLVMInternalLinkage, /**< Rename collisions when linking (static
294 LLVMPrivateLinkage, /**< Like Internal, but omit from symbol table */
295 LLVMDLLImportLinkage, /**< Function to be imported from DLL */
296 LLVMDLLExportLinkage, /**< Function to be accessible from DLL */
297 LLVMExternalWeakLinkage,/**< ExternalWeak linkage description */
298 LLVMGhostLinkage, /**< Obsolete */
299 LLVMCommonLinkage, /**< Tentative definitions */
300 LLVMLinkerPrivateLinkage, /**< Like Private, but linker removes. */
301 LLVMLinkerPrivateWeakLinkage /**< Like LinkerPrivate, but is weak. */
305 LLVMDefaultVisibility, /**< The GV is visible */
306 LLVMHiddenVisibility, /**< The GV is hidden */
307 LLVMProtectedVisibility /**< The GV is protected */
312 LLVMFastCallConv = 8,
313 LLVMColdCallConv = 9,
314 LLVMX86StdcallCallConv = 64,
315 LLVMX86FastcallCallConv = 65
319 LLVMIntEQ = 32, /**< equal */
320 LLVMIntNE, /**< not equal */
321 LLVMIntUGT, /**< unsigned greater than */
322 LLVMIntUGE, /**< unsigned greater or equal */
323 LLVMIntULT, /**< unsigned less than */
324 LLVMIntULE, /**< unsigned less or equal */
325 LLVMIntSGT, /**< signed greater than */
326 LLVMIntSGE, /**< signed greater or equal */
327 LLVMIntSLT, /**< signed less than */
328 LLVMIntSLE /**< signed less or equal */
332 LLVMRealPredicateFalse, /**< Always false (always folded) */
333 LLVMRealOEQ, /**< True if ordered and equal */
334 LLVMRealOGT, /**< True if ordered and greater than */
335 LLVMRealOGE, /**< True if ordered and greater than or equal */
336 LLVMRealOLT, /**< True if ordered and less than */
337 LLVMRealOLE, /**< True if ordered and less than or equal */
338 LLVMRealONE, /**< True if ordered and operands are unequal */
339 LLVMRealORD, /**< True if ordered (no nans) */
340 LLVMRealUNO, /**< True if unordered: isnan(X) | isnan(Y) */
341 LLVMRealUEQ, /**< True if unordered or equal */
342 LLVMRealUGT, /**< True if unordered or greater than */
343 LLVMRealUGE, /**< True if unordered, greater than, or equal */
344 LLVMRealULT, /**< True if unordered or less than */
345 LLVMRealULE, /**< True if unordered, less than, or equal */
346 LLVMRealUNE, /**< True if unordered or not equal */
347 LLVMRealPredicateTrue /**< Always true (always folded) */
351 LLVMLandingPadCatch, /**< A catch clause */
352 LLVMLandingPadFilter /**< A filter clause */
353 } LLVMLandingPadClauseTy;
359 void LLVMInitializeCore(LLVMPassRegistryRef R);
361 /** Deallocate and destroy all ManagedStatic variables.
362 @see llvm::llvm_shutdown
363 @see ManagedStatic */
367 /*===-- Error handling ----------------------------------------------------===*/
369 void LLVMDisposeMessage(char *Message);
373 * @defgroup LLVMCCoreContext Contexts
375 * Contexts are execution states for the core LLVM IR system.
377 * Most types are tied to a context instance. Multiple contexts can
378 * exist simultaneously. A single context is not thread safe. However,
379 * different contexts can execute on different threads simultaneously.
385 * Create a new context.
387 * Every call to this function should be paired with a call to
388 * LLVMContextDispose() or the context will leak memory.
390 LLVMContextRef LLVMContextCreate(void);
393 * Obtain the global context instance.
395 LLVMContextRef LLVMGetGlobalContext(void);
398 * Destroy a context instance.
400 * This should be called for every call to LLVMContextCreate() or memory
403 void LLVMContextDispose(LLVMContextRef C);
405 unsigned LLVMGetMDKindIDInContext(LLVMContextRef C, const char* Name,
407 unsigned LLVMGetMDKindID(const char* Name, unsigned SLen);
414 * @defgroup LLVMCCoreModule Modules
416 * Modules represent the top-level structure in a LLVM program. An LLVM
417 * module is effectively a translation unit or a collection of
418 * translation units merged together.
424 * Create a new, empty module in the global context.
426 * This is equivalent to calling LLVMModuleCreateWithNameInContext with
427 * LLVMGetGlobalContext() as the context parameter.
429 * Every invocation should be paired with LLVMDisposeModule() or memory
432 LLVMModuleRef LLVMModuleCreateWithName(const char *ModuleID);
435 * Create a new, empty module in a specific context.
437 * Every invocation should be paired with LLVMDisposeModule() or memory
440 LLVMModuleRef LLVMModuleCreateWithNameInContext(const char *ModuleID,
444 * Destroy a module instance.
446 * This must be called for every created module or memory will be
449 void LLVMDisposeModule(LLVMModuleRef M);
452 * Obtain the data layout for a module.
454 * @see Module::getDataLayout()
456 const char *LLVMGetDataLayout(LLVMModuleRef M);
459 * Set the data layout for a module.
461 * @see Module::setDataLayout()
463 void LLVMSetDataLayout(LLVMModuleRef M, const char *Triple);
466 * Obtain the target triple for a module.
468 * @see Module::getTargetTriple()
470 const char *LLVMGetTarget(LLVMModuleRef M);
473 * Set the target triple for a module.
475 * @see Module::setTargetTriple()
477 void LLVMSetTarget(LLVMModuleRef M, const char *Triple);
480 * Dump a representation of a module to stderr.
482 * @see Module::dump()
484 void LLVMDumpModule(LLVMModuleRef M);
487 * Print a representation of a module to a file. The ErrorMessage needs to be
488 * disposed with LLVMDisposeMessage. Returns 0 on success, 1 otherwise.
490 * @see Module::print()
492 LLVMBool LLVMPrintModuleToFile(LLVMModuleRef M, const char *Filename,
493 char **ErrorMessage);
496 * Set inline assembly for a module.
498 * @see Module::setModuleInlineAsm()
500 void LLVMSetModuleInlineAsm(LLVMModuleRef M, const char *Asm);
503 * Obtain the context to which this module is associated.
505 * @see Module::getContext()
507 LLVMContextRef LLVMGetModuleContext(LLVMModuleRef M);
510 * Obtain a Type from a module by its registered name.
512 LLVMTypeRef LLVMGetTypeByName(LLVMModuleRef M, const char *Name);
515 * Obtain the number of operands for named metadata in a module.
517 * @see llvm::Module::getNamedMetadata()
519 unsigned LLVMGetNamedMetadataNumOperands(LLVMModuleRef M, const char* name);
522 * Obtain the named metadata operands for a module.
524 * The passed LLVMValueRef pointer should refer to an array of
525 * LLVMValueRef at least LLVMGetNamedMetadataNumOperands long. This
526 * array will be populated with the LLVMValueRef instances. Each
527 * instance corresponds to a llvm::MDNode.
529 * @see llvm::Module::getNamedMetadata()
530 * @see llvm::MDNode::getOperand()
532 void LLVMGetNamedMetadataOperands(LLVMModuleRef M, const char* name, LLVMValueRef *Dest);
535 * Add an operand to named metadata.
537 * @see llvm::Module::getNamedMetadata()
538 * @see llvm::MDNode::addOperand()
540 void LLVMAddNamedMetadataOperand(LLVMModuleRef M, const char* name,
544 * Add a function to a module under a specified name.
546 * @see llvm::Function::Create()
548 LLVMValueRef LLVMAddFunction(LLVMModuleRef M, const char *Name,
549 LLVMTypeRef FunctionTy);
552 * Obtain a Function value from a Module by its name.
554 * The returned value corresponds to a llvm::Function value.
556 * @see llvm::Module::getFunction()
558 LLVMValueRef LLVMGetNamedFunction(LLVMModuleRef M, const char *Name);
561 * Obtain an iterator to the first Function in a Module.
563 * @see llvm::Module::begin()
565 LLVMValueRef LLVMGetFirstFunction(LLVMModuleRef M);
568 * Obtain an iterator to the last Function in a Module.
570 * @see llvm::Module::end()
572 LLVMValueRef LLVMGetLastFunction(LLVMModuleRef M);
575 * Advance a Function iterator to the next Function.
577 * Returns NULL if the iterator was already at the end and there are no more
580 LLVMValueRef LLVMGetNextFunction(LLVMValueRef Fn);
583 * Decrement a Function iterator to the previous Function.
585 * Returns NULL if the iterator was already at the beginning and there are
586 * no previous functions.
588 LLVMValueRef LLVMGetPreviousFunction(LLVMValueRef Fn);
595 * @defgroup LLVMCCoreType Types
597 * Types represent the type of a value.
599 * Types are associated with a context instance. The context internally
600 * deduplicates types so there is only 1 instance of a specific type
601 * alive at a time. In other words, a unique type is shared among all
602 * consumers within a context.
604 * A Type in the C API corresponds to llvm::Type.
606 * Types have the following hierarchy:
624 * Obtain the enumerated type of a Type instance.
626 * @see llvm::Type:getTypeID()
628 LLVMTypeKind LLVMGetTypeKind(LLVMTypeRef Ty);
631 * Whether the type has a known size.
633 * Things that don't have a size are abstract types, labels, and void.a
635 * @see llvm::Type::isSized()
637 LLVMBool LLVMTypeIsSized(LLVMTypeRef Ty);
640 * Obtain the context to which this type instance is associated.
642 * @see llvm::Type::getContext()
644 LLVMContextRef LLVMGetTypeContext(LLVMTypeRef Ty);
647 * @defgroup LLVMCCoreTypeInt Integer Types
649 * Functions in this section operate on integer types.
655 * Obtain an integer type from a context with specified bit width.
657 LLVMTypeRef LLVMInt1TypeInContext(LLVMContextRef C);
658 LLVMTypeRef LLVMInt8TypeInContext(LLVMContextRef C);
659 LLVMTypeRef LLVMInt16TypeInContext(LLVMContextRef C);
660 LLVMTypeRef LLVMInt32TypeInContext(LLVMContextRef C);
661 LLVMTypeRef LLVMInt64TypeInContext(LLVMContextRef C);
662 LLVMTypeRef LLVMIntTypeInContext(LLVMContextRef C, unsigned NumBits);
665 * Obtain an integer type from the global context with a specified bit
668 LLVMTypeRef LLVMInt1Type(void);
669 LLVMTypeRef LLVMInt8Type(void);
670 LLVMTypeRef LLVMInt16Type(void);
671 LLVMTypeRef LLVMInt32Type(void);
672 LLVMTypeRef LLVMInt64Type(void);
673 LLVMTypeRef LLVMIntType(unsigned NumBits);
674 unsigned LLVMGetIntTypeWidth(LLVMTypeRef IntegerTy);
681 * @defgroup LLVMCCoreTypeFloat Floating Point Types
687 * Obtain a 16-bit floating point type from a context.
689 LLVMTypeRef LLVMHalfTypeInContext(LLVMContextRef C);
692 * Obtain a 32-bit floating point type from a context.
694 LLVMTypeRef LLVMFloatTypeInContext(LLVMContextRef C);
697 * Obtain a 64-bit floating point type from a context.
699 LLVMTypeRef LLVMDoubleTypeInContext(LLVMContextRef C);
702 * Obtain a 80-bit floating point type (X87) from a context.
704 LLVMTypeRef LLVMX86FP80TypeInContext(LLVMContextRef C);
707 * Obtain a 128-bit floating point type (112-bit mantissa) from a
710 LLVMTypeRef LLVMFP128TypeInContext(LLVMContextRef C);
713 * Obtain a 128-bit floating point type (two 64-bits) from a context.
715 LLVMTypeRef LLVMPPCFP128TypeInContext(LLVMContextRef C);
718 * Obtain a floating point type from the global context.
720 * These map to the functions in this group of the same name.
722 LLVMTypeRef LLVMHalfType(void);
723 LLVMTypeRef LLVMFloatType(void);
724 LLVMTypeRef LLVMDoubleType(void);
725 LLVMTypeRef LLVMX86FP80Type(void);
726 LLVMTypeRef LLVMFP128Type(void);
727 LLVMTypeRef LLVMPPCFP128Type(void);
734 * @defgroup LLVMCCoreTypeFunction Function Types
740 * Obtain a function type consisting of a specified signature.
742 * The function is defined as a tuple of a return Type, a list of
743 * parameter types, and whether the function is variadic.
745 LLVMTypeRef LLVMFunctionType(LLVMTypeRef ReturnType,
746 LLVMTypeRef *ParamTypes, unsigned ParamCount,
750 * Returns whether a function type is variadic.
752 LLVMBool LLVMIsFunctionVarArg(LLVMTypeRef FunctionTy);
755 * Obtain the Type this function Type returns.
757 LLVMTypeRef LLVMGetReturnType(LLVMTypeRef FunctionTy);
760 * Obtain the number of parameters this function accepts.
762 unsigned LLVMCountParamTypes(LLVMTypeRef FunctionTy);
765 * Obtain the types of a function's parameters.
767 * The Dest parameter should point to a pre-allocated array of
768 * LLVMTypeRef at least LLVMCountParamTypes() large. On return, the
769 * first LLVMCountParamTypes() entries in the array will be populated
770 * with LLVMTypeRef instances.
772 * @param FunctionTy The function type to operate on.
773 * @param Dest Memory address of an array to be filled with result.
775 void LLVMGetParamTypes(LLVMTypeRef FunctionTy, LLVMTypeRef *Dest);
782 * @defgroup LLVMCCoreTypeStruct Structure Types
784 * These functions relate to LLVMTypeRef instances.
786 * @see llvm::StructType
792 * Create a new structure type in a context.
794 * A structure is specified by a list of inner elements/types and
795 * whether these can be packed together.
797 * @see llvm::StructType::create()
799 LLVMTypeRef LLVMStructTypeInContext(LLVMContextRef C, LLVMTypeRef *ElementTypes,
800 unsigned ElementCount, LLVMBool Packed);
803 * Create a new structure type in the global context.
805 * @see llvm::StructType::create()
807 LLVMTypeRef LLVMStructType(LLVMTypeRef *ElementTypes, unsigned ElementCount,
811 * Create an empty structure in a context having a specified name.
813 * @see llvm::StructType::create()
815 LLVMTypeRef LLVMStructCreateNamed(LLVMContextRef C, const char *Name);
818 * Obtain the name of a structure.
820 * @see llvm::StructType::getName()
822 const char *LLVMGetStructName(LLVMTypeRef Ty);
825 * Set the contents of a structure type.
827 * @see llvm::StructType::setBody()
829 void LLVMStructSetBody(LLVMTypeRef StructTy, LLVMTypeRef *ElementTypes,
830 unsigned ElementCount, LLVMBool Packed);
833 * Get the number of elements defined inside the structure.
835 * @see llvm::StructType::getNumElements()
837 unsigned LLVMCountStructElementTypes(LLVMTypeRef StructTy);
840 * Get the elements within a structure.
842 * The function is passed the address of a pre-allocated array of
843 * LLVMTypeRef at least LLVMCountStructElementTypes() long. After
844 * invocation, this array will be populated with the structure's
845 * elements. The objects in the destination array will have a lifetime
846 * of the structure type itself, which is the lifetime of the context it
849 void LLVMGetStructElementTypes(LLVMTypeRef StructTy, LLVMTypeRef *Dest);
852 * Determine whether a structure is packed.
854 * @see llvm::StructType::isPacked()
856 LLVMBool LLVMIsPackedStruct(LLVMTypeRef StructTy);
859 * Determine whether a structure is opaque.
861 * @see llvm::StructType::isOpaque()
863 LLVMBool LLVMIsOpaqueStruct(LLVMTypeRef StructTy);
871 * @defgroup LLVMCCoreTypeSequential Sequential Types
873 * Sequential types represents "arrays" of types. This is a super class
874 * for array, vector, and pointer types.
880 * Obtain the type of elements within a sequential type.
882 * This works on array, vector, and pointer types.
884 * @see llvm::SequentialType::getElementType()
886 LLVMTypeRef LLVMGetElementType(LLVMTypeRef Ty);
889 * Create a fixed size array type that refers to a specific type.
891 * The created type will exist in the context that its element type
894 * @see llvm::ArrayType::get()
896 LLVMTypeRef LLVMArrayType(LLVMTypeRef ElementType, unsigned ElementCount);
899 * Obtain the length of an array type.
901 * This only works on types that represent arrays.
903 * @see llvm::ArrayType::getNumElements()
905 unsigned LLVMGetArrayLength(LLVMTypeRef ArrayTy);
908 * Create a pointer type that points to a defined type.
910 * The created type will exist in the context that its pointee type
913 * @see llvm::PointerType::get()
915 LLVMTypeRef LLVMPointerType(LLVMTypeRef ElementType, unsigned AddressSpace);
918 * Obtain the address space of a pointer type.
920 * This only works on types that represent pointers.
922 * @see llvm::PointerType::getAddressSpace()
924 unsigned LLVMGetPointerAddressSpace(LLVMTypeRef PointerTy);
927 * Create a vector type that contains a defined type and has a specific
928 * number of elements.
930 * The created type will exist in the context thats its element type
933 * @see llvm::VectorType::get()
935 LLVMTypeRef LLVMVectorType(LLVMTypeRef ElementType, unsigned ElementCount);
938 * Obtain the number of elements in a vector type.
940 * This only works on types that represent vectors.
942 * @see llvm::VectorType::getNumElements()
944 unsigned LLVMGetVectorSize(LLVMTypeRef VectorTy);
951 * @defgroup LLVMCCoreTypeOther Other Types
957 * Create a void type in a context.
959 LLVMTypeRef LLVMVoidTypeInContext(LLVMContextRef C);
962 * Create a label type in a context.
964 LLVMTypeRef LLVMLabelTypeInContext(LLVMContextRef C);
967 * Create a X86 MMX type in a context.
969 LLVMTypeRef LLVMX86MMXTypeInContext(LLVMContextRef C);
972 * These are similar to the above functions except they operate on the
975 LLVMTypeRef LLVMVoidType(void);
976 LLVMTypeRef LLVMLabelType(void);
977 LLVMTypeRef LLVMX86MMXType(void);
988 * @defgroup LLVMCCoreValues Values
990 * The bulk of LLVM's object model consists of values, which comprise a very
991 * rich type hierarchy.
993 * LLVMValueRef essentially represents llvm::Value. There is a rich
994 * hierarchy of classes within this type. Depending on the instance
995 * obtained, not all APIs are available.
997 * Callers can determine the type of a LLVMValueRef by calling the
998 * LLVMIsA* family of functions (e.g. LLVMIsAArgument()). These
999 * functions are defined by a macro, so it isn't obvious which are
1000 * available by looking at the Doxygen source code. Instead, look at the
1001 * source definition of LLVM_FOR_EACH_VALUE_SUBCLASS and note the list
1002 * of value names given. These value names also correspond to classes in
1003 * the llvm::Value hierarchy.
1008 #define LLVM_FOR_EACH_VALUE_SUBCLASS(macro) \
1016 macro(BlockAddress) \
1017 macro(ConstantAggregateZero) \
1018 macro(ConstantArray) \
1019 macro(ConstantExpr) \
1021 macro(ConstantInt) \
1022 macro(ConstantPointerNull) \
1023 macro(ConstantStruct) \
1024 macro(ConstantVector) \
1025 macro(GlobalValue) \
1027 macro(GlobalAlias) \
1028 macro(GlobalVariable) \
1030 macro(Instruction) \
1031 macro(BinaryOperator) \
1033 macro(IntrinsicInst) \
1034 macro(DbgInfoIntrinsic) \
1035 macro(DbgDeclareInst) \
1036 macro(MemIntrinsic) \
1038 macro(MemMoveInst) \
1043 macro(ExtractElementInst) \
1044 macro(GetElementPtrInst) \
1045 macro(InsertElementInst) \
1046 macro(InsertValueInst) \
1047 macro(LandingPadInst) \
1050 macro(ShuffleVectorInst) \
1052 macro(TerminatorInst) \
1054 macro(IndirectBrInst) \
1058 macro(UnreachableInst) \
1060 macro(UnaryInstruction) \
1063 macro(BitCastInst) \
1067 macro(FPTruncInst) \
1068 macro(IntToPtrInst) \
1069 macro(PtrToIntInst) \
1075 macro(ExtractValueInst) \
1080 * @defgroup LLVMCCoreValueGeneral General APIs
1082 * Functions in this section work on all LLVMValueRef instances,
1083 * regardless of their sub-type. They correspond to functions available
1090 * Obtain the type of a value.
1092 * @see llvm::Value::getType()
1094 LLVMTypeRef LLVMTypeOf(LLVMValueRef Val);
1097 * Obtain the string name of a value.
1099 * @see llvm::Value::getName()
1101 const char *LLVMGetValueName(LLVMValueRef Val);
1104 * Set the string name of a value.
1106 * @see llvm::Value::setName()
1108 void LLVMSetValueName(LLVMValueRef Val, const char *Name);
1111 * Dump a representation of a value to stderr.
1113 * @see llvm::Value::dump()
1115 void LLVMDumpValue(LLVMValueRef Val);
1118 * Replace all uses of a value with another one.
1120 * @see llvm::Value::replaceAllUsesWith()
1122 void LLVMReplaceAllUsesWith(LLVMValueRef OldVal, LLVMValueRef NewVal);
1125 * Determine whether the specified constant instance is constant.
1127 LLVMBool LLVMIsConstant(LLVMValueRef Val);
1130 * Determine whether a value instance is undefined.
1132 LLVMBool LLVMIsUndef(LLVMValueRef Val);
1135 * Convert value instances between types.
1137 * Internally, a LLVMValueRef is "pinned" to a specific type. This
1138 * series of functions allows you to cast an instance to a specific
1141 * If the cast is not valid for the specified type, NULL is returned.
1143 * @see llvm::dyn_cast_or_null<>
1145 #define LLVM_DECLARE_VALUE_CAST(name) \
1146 LLVMValueRef LLVMIsA##name(LLVMValueRef Val);
1147 LLVM_FOR_EACH_VALUE_SUBCLASS(LLVM_DECLARE_VALUE_CAST)
1154 * @defgroup LLVMCCoreValueUses Usage
1156 * This module defines functions that allow you to inspect the uses of a
1159 * It is possible to obtain a LLVMUseRef for any LLVMValueRef instance.
1160 * Each LLVMUseRef (which corresponds to a llvm::Use instance) holds a
1161 * llvm::User and llvm::Value.
1167 * Obtain the first use of a value.
1169 * Uses are obtained in an iterator fashion. First, call this function
1170 * to obtain a reference to the first use. Then, call LLVMGetNextUse()
1171 * on that instance and all subsequently obtained instances until
1172 * LLVMGetNextUse() returns NULL.
1174 * @see llvm::Value::use_begin()
1176 LLVMUseRef LLVMGetFirstUse(LLVMValueRef Val);
1179 * Obtain the next use of a value.
1181 * This effectively advances the iterator. It returns NULL if you are on
1182 * the final use and no more are available.
1184 LLVMUseRef LLVMGetNextUse(LLVMUseRef U);
1187 * Obtain the user value for a user.
1189 * The returned value corresponds to a llvm::User type.
1191 * @see llvm::Use::getUser()
1193 LLVMValueRef LLVMGetUser(LLVMUseRef U);
1196 * Obtain the value this use corresponds to.
1198 * @see llvm::Use::get().
1200 LLVMValueRef LLVMGetUsedValue(LLVMUseRef U);
1207 * @defgroup LLVMCCoreValueUser User value
1209 * Function in this group pertain to LLVMValueRef instances that descent
1210 * from llvm::User. This includes constants, instructions, and
1217 * Obtain an operand at a specific index in a llvm::User value.
1219 * @see llvm::User::getOperand()
1221 LLVMValueRef LLVMGetOperand(LLVMValueRef Val, unsigned Index);
1224 * Set an operand at a specific index in a llvm::User value.
1226 * @see llvm::User::setOperand()
1228 void LLVMSetOperand(LLVMValueRef User, unsigned Index, LLVMValueRef Val);
1231 * Obtain the number of operands in a llvm::User value.
1233 * @see llvm::User::getNumOperands()
1235 int LLVMGetNumOperands(LLVMValueRef Val);
1242 * @defgroup LLVMCCoreValueConstant Constants
1244 * This section contains APIs for interacting with LLVMValueRef that
1245 * correspond to llvm::Constant instances.
1247 * These functions will work for any LLVMValueRef in the llvm::Constant
1254 * Obtain a constant value referring to the null instance of a type.
1256 * @see llvm::Constant::getNullValue()
1258 LLVMValueRef LLVMConstNull(LLVMTypeRef Ty); /* all zeroes */
1261 * Obtain a constant value referring to the instance of a type
1262 * consisting of all ones.
1264 * This is only valid for integer types.
1266 * @see llvm::Constant::getAllOnesValue()
1268 LLVMValueRef LLVMConstAllOnes(LLVMTypeRef Ty);
1271 * Obtain a constant value referring to an undefined value of a type.
1273 * @see llvm::UndefValue::get()
1275 LLVMValueRef LLVMGetUndef(LLVMTypeRef Ty);
1278 * Determine whether a value instance is null.
1280 * @see llvm::Constant::isNullValue()
1282 LLVMBool LLVMIsNull(LLVMValueRef Val);
1285 * Obtain a constant that is a constant pointer pointing to NULL for a
1288 LLVMValueRef LLVMConstPointerNull(LLVMTypeRef Ty);
1291 * @defgroup LLVMCCoreValueConstantScalar Scalar constants
1293 * Functions in this group model LLVMValueRef instances that correspond
1294 * to constants referring to scalar types.
1296 * For integer types, the LLVMTypeRef parameter should correspond to a
1297 * llvm::IntegerType instance and the returned LLVMValueRef will
1298 * correspond to a llvm::ConstantInt.
1300 * For floating point types, the LLVMTypeRef returned corresponds to a
1307 * Obtain a constant value for an integer type.
1309 * The returned value corresponds to a llvm::ConstantInt.
1311 * @see llvm::ConstantInt::get()
1313 * @param IntTy Integer type to obtain value of.
1314 * @param N The value the returned instance should refer to.
1315 * @param SignExtend Whether to sign extend the produced value.
1317 LLVMValueRef LLVMConstInt(LLVMTypeRef IntTy, unsigned long long N,
1318 LLVMBool SignExtend);
1321 * Obtain a constant value for an integer of arbitrary precision.
1323 * @see llvm::ConstantInt::get()
1325 LLVMValueRef LLVMConstIntOfArbitraryPrecision(LLVMTypeRef IntTy,
1327 const uint64_t Words[]);
1330 * Obtain a constant value for an integer parsed from a string.
1332 * A similar API, LLVMConstIntOfStringAndSize is also available. If the
1333 * string's length is available, it is preferred to call that function
1336 * @see llvm::ConstantInt::get()
1338 LLVMValueRef LLVMConstIntOfString(LLVMTypeRef IntTy, const char *Text,
1342 * Obtain a constant value for an integer parsed from a string with
1345 * @see llvm::ConstantInt::get()
1347 LLVMValueRef LLVMConstIntOfStringAndSize(LLVMTypeRef IntTy, const char *Text,
1348 unsigned SLen, uint8_t Radix);
1351 * Obtain a constant value referring to a double floating point value.
1353 LLVMValueRef LLVMConstReal(LLVMTypeRef RealTy, double N);
1356 * Obtain a constant for a floating point value parsed from a string.
1358 * A similar API, LLVMConstRealOfStringAndSize is also available. It
1359 * should be used if the input string's length is known.
1361 LLVMValueRef LLVMConstRealOfString(LLVMTypeRef RealTy, const char *Text);
1364 * Obtain a constant for a floating point value parsed from a string.
1366 LLVMValueRef LLVMConstRealOfStringAndSize(LLVMTypeRef RealTy, const char *Text,
1370 * Obtain the zero extended value for an integer constant value.
1372 * @see llvm::ConstantInt::getZExtValue()
1374 unsigned long long LLVMConstIntGetZExtValue(LLVMValueRef ConstantVal);
1377 * Obtain the sign extended value for an integer constant value.
1379 * @see llvm::ConstantInt::getSExtValue()
1381 long long LLVMConstIntGetSExtValue(LLVMValueRef ConstantVal);
1388 * @defgroup LLVMCCoreValueConstantComposite Composite Constants
1390 * Functions in this group operate on composite constants.
1396 * Create a ConstantDataSequential and initialize it with a string.
1398 * @see llvm::ConstantDataArray::getString()
1400 LLVMValueRef LLVMConstStringInContext(LLVMContextRef C, const char *Str,
1401 unsigned Length, LLVMBool DontNullTerminate);
1404 * Create a ConstantDataSequential with string content in the global context.
1406 * This is the same as LLVMConstStringInContext except it operates on the
1409 * @see LLVMConstStringInContext()
1410 * @see llvm::ConstantDataArray::getString()
1412 LLVMValueRef LLVMConstString(const char *Str, unsigned Length,
1413 LLVMBool DontNullTerminate);
1416 * Create an anonymous ConstantStruct with the specified values.
1418 * @see llvm::ConstantStruct::getAnon()
1420 LLVMValueRef LLVMConstStructInContext(LLVMContextRef C,
1421 LLVMValueRef *ConstantVals,
1422 unsigned Count, LLVMBool Packed);
1425 * Create a ConstantStruct in the global Context.
1427 * This is the same as LLVMConstStructInContext except it operates on the
1430 * @see LLVMConstStructInContext()
1432 LLVMValueRef LLVMConstStruct(LLVMValueRef *ConstantVals, unsigned Count,
1436 * Create a ConstantArray from values.
1438 * @see llvm::ConstantArray::get()
1440 LLVMValueRef LLVMConstArray(LLVMTypeRef ElementTy,
1441 LLVMValueRef *ConstantVals, unsigned Length);
1444 * Create a non-anonymous ConstantStruct from values.
1446 * @see llvm::ConstantStruct::get()
1448 LLVMValueRef LLVMConstNamedStruct(LLVMTypeRef StructTy,
1449 LLVMValueRef *ConstantVals,
1453 * Create a ConstantVector from values.
1455 * @see llvm::ConstantVector::get()
1457 LLVMValueRef LLVMConstVector(LLVMValueRef *ScalarConstantVals, unsigned Size);
1464 * @defgroup LLVMCCoreValueConstantExpressions Constant Expressions
1466 * Functions in this group correspond to APIs on llvm::ConstantExpr.
1468 * @see llvm::ConstantExpr.
1472 LLVMOpcode LLVMGetConstOpcode(LLVMValueRef ConstantVal);
1473 LLVMValueRef LLVMAlignOf(LLVMTypeRef Ty);
1474 LLVMValueRef LLVMSizeOf(LLVMTypeRef Ty);
1475 LLVMValueRef LLVMConstNeg(LLVMValueRef ConstantVal);
1476 LLVMValueRef LLVMConstNSWNeg(LLVMValueRef ConstantVal);
1477 LLVMValueRef LLVMConstNUWNeg(LLVMValueRef ConstantVal);
1478 LLVMValueRef LLVMConstFNeg(LLVMValueRef ConstantVal);
1479 LLVMValueRef LLVMConstNot(LLVMValueRef ConstantVal);
1480 LLVMValueRef LLVMConstAdd(LLVMValueRef LHSConstant, LLVMValueRef RHSConstant);
1481 LLVMValueRef LLVMConstNSWAdd(LLVMValueRef LHSConstant, LLVMValueRef RHSConstant);
1482 LLVMValueRef LLVMConstNUWAdd(LLVMValueRef LHSConstant, LLVMValueRef RHSConstant);
1483 LLVMValueRef LLVMConstFAdd(LLVMValueRef LHSConstant, LLVMValueRef RHSConstant);
1484 LLVMValueRef LLVMConstSub(LLVMValueRef LHSConstant, LLVMValueRef RHSConstant);
1485 LLVMValueRef LLVMConstNSWSub(LLVMValueRef LHSConstant, LLVMValueRef RHSConstant);
1486 LLVMValueRef LLVMConstNUWSub(LLVMValueRef LHSConstant, LLVMValueRef RHSConstant);
1487 LLVMValueRef LLVMConstFSub(LLVMValueRef LHSConstant, LLVMValueRef RHSConstant);
1488 LLVMValueRef LLVMConstMul(LLVMValueRef LHSConstant, LLVMValueRef RHSConstant);
1489 LLVMValueRef LLVMConstNSWMul(LLVMValueRef LHSConstant, LLVMValueRef RHSConstant);
1490 LLVMValueRef LLVMConstNUWMul(LLVMValueRef LHSConstant, LLVMValueRef RHSConstant);
1491 LLVMValueRef LLVMConstFMul(LLVMValueRef LHSConstant, LLVMValueRef RHSConstant);
1492 LLVMValueRef LLVMConstUDiv(LLVMValueRef LHSConstant, LLVMValueRef RHSConstant);
1493 LLVMValueRef LLVMConstSDiv(LLVMValueRef LHSConstant, LLVMValueRef RHSConstant);
1494 LLVMValueRef LLVMConstExactSDiv(LLVMValueRef LHSConstant, LLVMValueRef RHSConstant);
1495 LLVMValueRef LLVMConstFDiv(LLVMValueRef LHSConstant, LLVMValueRef RHSConstant);
1496 LLVMValueRef LLVMConstURem(LLVMValueRef LHSConstant, LLVMValueRef RHSConstant);
1497 LLVMValueRef LLVMConstSRem(LLVMValueRef LHSConstant, LLVMValueRef RHSConstant);
1498 LLVMValueRef LLVMConstFRem(LLVMValueRef LHSConstant, LLVMValueRef RHSConstant);
1499 LLVMValueRef LLVMConstAnd(LLVMValueRef LHSConstant, LLVMValueRef RHSConstant);
1500 LLVMValueRef LLVMConstOr(LLVMValueRef LHSConstant, LLVMValueRef RHSConstant);
1501 LLVMValueRef LLVMConstXor(LLVMValueRef LHSConstant, LLVMValueRef RHSConstant);
1502 LLVMValueRef LLVMConstICmp(LLVMIntPredicate Predicate,
1503 LLVMValueRef LHSConstant, LLVMValueRef RHSConstant);
1504 LLVMValueRef LLVMConstFCmp(LLVMRealPredicate Predicate,
1505 LLVMValueRef LHSConstant, LLVMValueRef RHSConstant);
1506 LLVMValueRef LLVMConstShl(LLVMValueRef LHSConstant, LLVMValueRef RHSConstant);
1507 LLVMValueRef LLVMConstLShr(LLVMValueRef LHSConstant, LLVMValueRef RHSConstant);
1508 LLVMValueRef LLVMConstAShr(LLVMValueRef LHSConstant, LLVMValueRef RHSConstant);
1509 LLVMValueRef LLVMConstGEP(LLVMValueRef ConstantVal,
1510 LLVMValueRef *ConstantIndices, unsigned NumIndices);
1511 LLVMValueRef LLVMConstInBoundsGEP(LLVMValueRef ConstantVal,
1512 LLVMValueRef *ConstantIndices,
1513 unsigned NumIndices);
1514 LLVMValueRef LLVMConstTrunc(LLVMValueRef ConstantVal, LLVMTypeRef ToType);
1515 LLVMValueRef LLVMConstSExt(LLVMValueRef ConstantVal, LLVMTypeRef ToType);
1516 LLVMValueRef LLVMConstZExt(LLVMValueRef ConstantVal, LLVMTypeRef ToType);
1517 LLVMValueRef LLVMConstFPTrunc(LLVMValueRef ConstantVal, LLVMTypeRef ToType);
1518 LLVMValueRef LLVMConstFPExt(LLVMValueRef ConstantVal, LLVMTypeRef ToType);
1519 LLVMValueRef LLVMConstUIToFP(LLVMValueRef ConstantVal, LLVMTypeRef ToType);
1520 LLVMValueRef LLVMConstSIToFP(LLVMValueRef ConstantVal, LLVMTypeRef ToType);
1521 LLVMValueRef LLVMConstFPToUI(LLVMValueRef ConstantVal, LLVMTypeRef ToType);
1522 LLVMValueRef LLVMConstFPToSI(LLVMValueRef ConstantVal, LLVMTypeRef ToType);
1523 LLVMValueRef LLVMConstPtrToInt(LLVMValueRef ConstantVal, LLVMTypeRef ToType);
1524 LLVMValueRef LLVMConstIntToPtr(LLVMValueRef ConstantVal, LLVMTypeRef ToType);
1525 LLVMValueRef LLVMConstBitCast(LLVMValueRef ConstantVal, LLVMTypeRef ToType);
1526 LLVMValueRef LLVMConstZExtOrBitCast(LLVMValueRef ConstantVal,
1527 LLVMTypeRef ToType);
1528 LLVMValueRef LLVMConstSExtOrBitCast(LLVMValueRef ConstantVal,
1529 LLVMTypeRef ToType);
1530 LLVMValueRef LLVMConstTruncOrBitCast(LLVMValueRef ConstantVal,
1531 LLVMTypeRef ToType);
1532 LLVMValueRef LLVMConstPointerCast(LLVMValueRef ConstantVal,
1533 LLVMTypeRef ToType);
1534 LLVMValueRef LLVMConstIntCast(LLVMValueRef ConstantVal, LLVMTypeRef ToType,
1536 LLVMValueRef LLVMConstFPCast(LLVMValueRef ConstantVal, LLVMTypeRef ToType);
1537 LLVMValueRef LLVMConstSelect(LLVMValueRef ConstantCondition,
1538 LLVMValueRef ConstantIfTrue,
1539 LLVMValueRef ConstantIfFalse);
1540 LLVMValueRef LLVMConstExtractElement(LLVMValueRef VectorConstant,
1541 LLVMValueRef IndexConstant);
1542 LLVMValueRef LLVMConstInsertElement(LLVMValueRef VectorConstant,
1543 LLVMValueRef ElementValueConstant,
1544 LLVMValueRef IndexConstant);
1545 LLVMValueRef LLVMConstShuffleVector(LLVMValueRef VectorAConstant,
1546 LLVMValueRef VectorBConstant,
1547 LLVMValueRef MaskConstant);
1548 LLVMValueRef LLVMConstExtractValue(LLVMValueRef AggConstant, unsigned *IdxList,
1550 LLVMValueRef LLVMConstInsertValue(LLVMValueRef AggConstant,
1551 LLVMValueRef ElementValueConstant,
1552 unsigned *IdxList, unsigned NumIdx);
1553 LLVMValueRef LLVMConstInlineAsm(LLVMTypeRef Ty,
1554 const char *AsmString, const char *Constraints,
1555 LLVMBool HasSideEffects, LLVMBool IsAlignStack);
1556 LLVMValueRef LLVMBlockAddress(LLVMValueRef F, LLVMBasicBlockRef BB);
1563 * @defgroup LLVMCCoreValueConstantGlobals Global Values
1565 * This group contains functions that operate on global values. Functions in
1566 * this group relate to functions in the llvm::GlobalValue class tree.
1568 * @see llvm::GlobalValue
1573 LLVMModuleRef LLVMGetGlobalParent(LLVMValueRef Global);
1574 LLVMBool LLVMIsDeclaration(LLVMValueRef Global);
1575 LLVMLinkage LLVMGetLinkage(LLVMValueRef Global);
1576 void LLVMSetLinkage(LLVMValueRef Global, LLVMLinkage Linkage);
1577 const char *LLVMGetSection(LLVMValueRef Global);
1578 void LLVMSetSection(LLVMValueRef Global, const char *Section);
1579 LLVMVisibility LLVMGetVisibility(LLVMValueRef Global);
1580 void LLVMSetVisibility(LLVMValueRef Global, LLVMVisibility Viz);
1581 unsigned LLVMGetAlignment(LLVMValueRef Global);
1582 void LLVMSetAlignment(LLVMValueRef Global, unsigned Bytes);
1585 * @defgroup LLVMCoreValueConstantGlobalVariable Global Variables
1587 * This group contains functions that operate on global variable values.
1589 * @see llvm::GlobalVariable
1593 LLVMValueRef LLVMAddGlobal(LLVMModuleRef M, LLVMTypeRef Ty, const char *Name);
1594 LLVMValueRef LLVMAddGlobalInAddressSpace(LLVMModuleRef M, LLVMTypeRef Ty,
1596 unsigned AddressSpace);
1597 LLVMValueRef LLVMGetNamedGlobal(LLVMModuleRef M, const char *Name);
1598 LLVMValueRef LLVMGetFirstGlobal(LLVMModuleRef M);
1599 LLVMValueRef LLVMGetLastGlobal(LLVMModuleRef M);
1600 LLVMValueRef LLVMGetNextGlobal(LLVMValueRef GlobalVar);
1601 LLVMValueRef LLVMGetPreviousGlobal(LLVMValueRef GlobalVar);
1602 void LLVMDeleteGlobal(LLVMValueRef GlobalVar);
1603 LLVMValueRef LLVMGetInitializer(LLVMValueRef GlobalVar);
1604 void LLVMSetInitializer(LLVMValueRef GlobalVar, LLVMValueRef ConstantVal);
1605 LLVMBool LLVMIsThreadLocal(LLVMValueRef GlobalVar);
1606 void LLVMSetThreadLocal(LLVMValueRef GlobalVar, LLVMBool IsThreadLocal);
1607 LLVMBool LLVMIsGlobalConstant(LLVMValueRef GlobalVar);
1608 void LLVMSetGlobalConstant(LLVMValueRef GlobalVar, LLVMBool IsConstant);
1615 * @defgroup LLVMCoreValueConstantGlobalAlias Global Aliases
1617 * This group contains function that operate on global alias values.
1619 * @see llvm::GlobalAlias
1623 LLVMValueRef LLVMAddAlias(LLVMModuleRef M, LLVMTypeRef Ty, LLVMValueRef Aliasee,
1631 * @defgroup LLVMCCoreValueFunction Function values
1633 * Functions in this group operate on LLVMValueRef instances that
1634 * correspond to llvm::Function instances.
1636 * @see llvm::Function
1642 * Remove a function from its containing module and deletes it.
1644 * @see llvm::Function::eraseFromParent()
1646 void LLVMDeleteFunction(LLVMValueRef Fn);
1649 * Obtain the ID number from a function instance.
1651 * @see llvm::Function::getIntrinsicID()
1653 unsigned LLVMGetIntrinsicID(LLVMValueRef Fn);
1656 * Obtain the calling function of a function.
1658 * The returned value corresponds to the LLVMCallConv enumeration.
1660 * @see llvm::Function::getCallingConv()
1662 unsigned LLVMGetFunctionCallConv(LLVMValueRef Fn);
1665 * Set the calling convention of a function.
1667 * @see llvm::Function::setCallingConv()
1669 * @param Fn Function to operate on
1670 * @param CC LLVMCallConv to set calling convention to
1672 void LLVMSetFunctionCallConv(LLVMValueRef Fn, unsigned CC);
1675 * Obtain the name of the garbage collector to use during code
1678 * @see llvm::Function::getGC()
1680 const char *LLVMGetGC(LLVMValueRef Fn);
1683 * Define the garbage collector to use during code generation.
1685 * @see llvm::Function::setGC()
1687 void LLVMSetGC(LLVMValueRef Fn, const char *Name);
1690 * Add an attribute to a function.
1692 * @see llvm::Function::addAttribute()
1694 void LLVMAddFunctionAttr(LLVMValueRef Fn, LLVMAttribute PA);
1697 * Obtain an attribute from a function.
1699 * @see llvm::Function::getAttributes()
1701 LLVMAttribute LLVMGetFunctionAttr(LLVMValueRef Fn);
1704 * Remove an attribute from a function.
1706 void LLVMRemoveFunctionAttr(LLVMValueRef Fn, LLVMAttribute PA);
1709 * @defgroup LLVMCCoreValueFunctionParameters Function Parameters
1711 * Functions in this group relate to arguments/parameters on functions.
1713 * Functions in this group expect LLVMValueRef instances that correspond
1714 * to llvm::Function instances.
1720 * Obtain the number of parameters in a function.
1722 * @see llvm::Function::arg_size()
1724 unsigned LLVMCountParams(LLVMValueRef Fn);
1727 * Obtain the parameters in a function.
1729 * The takes a pointer to a pre-allocated array of LLVMValueRef that is
1730 * at least LLVMCountParams() long. This array will be filled with
1731 * LLVMValueRef instances which correspond to the parameters the
1732 * function receives. Each LLVMValueRef corresponds to a llvm::Argument
1735 * @see llvm::Function::arg_begin()
1737 void LLVMGetParams(LLVMValueRef Fn, LLVMValueRef *Params);
1740 * Obtain the parameter at the specified index.
1742 * Parameters are indexed from 0.
1744 * @see llvm::Function::arg_begin()
1746 LLVMValueRef LLVMGetParam(LLVMValueRef Fn, unsigned Index);
1749 * Obtain the function to which this argument belongs.
1751 * Unlike other functions in this group, this one takes a LLVMValueRef
1752 * that corresponds to a llvm::Attribute.
1754 * The returned LLVMValueRef is the llvm::Function to which this
1757 LLVMValueRef LLVMGetParamParent(LLVMValueRef Inst);
1760 * Obtain the first parameter to a function.
1762 * @see llvm::Function::arg_begin()
1764 LLVMValueRef LLVMGetFirstParam(LLVMValueRef Fn);
1767 * Obtain the last parameter to a function.
1769 * @see llvm::Function::arg_end()
1771 LLVMValueRef LLVMGetLastParam(LLVMValueRef Fn);
1774 * Obtain the next parameter to a function.
1776 * This takes a LLVMValueRef obtained from LLVMGetFirstParam() (which is
1777 * actually a wrapped iterator) and obtains the next parameter from the
1778 * underlying iterator.
1780 LLVMValueRef LLVMGetNextParam(LLVMValueRef Arg);
1783 * Obtain the previous parameter to a function.
1785 * This is the opposite of LLVMGetNextParam().
1787 LLVMValueRef LLVMGetPreviousParam(LLVMValueRef Arg);
1790 * Add an attribute to a function argument.
1792 * @see llvm::Argument::addAttr()
1794 void LLVMAddAttribute(LLVMValueRef Arg, LLVMAttribute PA);
1797 * Remove an attribute from a function argument.
1799 * @see llvm::Argument::removeAttr()
1801 void LLVMRemoveAttribute(LLVMValueRef Arg, LLVMAttribute PA);
1804 * Get an attribute from a function argument.
1806 LLVMAttribute LLVMGetAttribute(LLVMValueRef Arg);
1809 * Set the alignment for a function parameter.
1811 * @see llvm::Argument::addAttr()
1812 * @see llvm::AttrBuilder::addAlignmentAttr()
1814 void LLVMSetParamAlignment(LLVMValueRef Arg, unsigned align);
1833 * @defgroup LLVMCCoreValueMetadata Metadata
1839 * Obtain a MDString value from a context.
1841 * The returned instance corresponds to the llvm::MDString class.
1843 * The instance is specified by string data of a specified length. The
1844 * string content is copied, so the backing memory can be freed after
1845 * this function returns.
1847 LLVMValueRef LLVMMDStringInContext(LLVMContextRef C, const char *Str,
1851 * Obtain a MDString value from the global context.
1853 LLVMValueRef LLVMMDString(const char *Str, unsigned SLen);
1856 * Obtain a MDNode value from a context.
1858 * The returned value corresponds to the llvm::MDNode class.
1860 LLVMValueRef LLVMMDNodeInContext(LLVMContextRef C, LLVMValueRef *Vals,
1864 * Obtain a MDNode value from the global context.
1866 LLVMValueRef LLVMMDNode(LLVMValueRef *Vals, unsigned Count);
1869 * Obtain the underlying string from a MDString value.
1871 * @param V Instance to obtain string from.
1872 * @param Len Memory address which will hold length of returned string.
1873 * @return String data in MDString.
1875 const char *LLVMGetMDString(LLVMValueRef V, unsigned* Len);
1878 * Obtain the number of operands from an MDNode value.
1880 * @param V MDNode to get number of operands from.
1881 * @return Number of operands of the MDNode.
1883 unsigned LLVMGetMDNodeNumOperands(LLVMValueRef V);
1886 * Obtain the given MDNode's operands.
1888 * The passed LLVMValueRef pointer should point to enough memory to hold all of
1889 * the operands of the given MDNode (see LLVMGetMDNodeNumOperands) as
1890 * LLVMValueRefs. This memory will be populated with the LLVMValueRefs of the
1891 * MDNode's operands.
1893 * @param V MDNode to get the operands from.
1894 * @param Dest Destination array for operands.
1896 void LLVMGetMDNodeOperands(LLVMValueRef V, LLVMValueRef *Dest);
1903 * @defgroup LLVMCCoreValueBasicBlock Basic Block
1905 * A basic block represents a single entry single exit section of code.
1906 * Basic blocks contain a list of instructions which form the body of
1909 * Basic blocks belong to functions. They have the type of label.
1911 * Basic blocks are themselves values. However, the C API models them as
1912 * LLVMBasicBlockRef.
1914 * @see llvm::BasicBlock
1920 * Convert a basic block instance to a value type.
1922 LLVMValueRef LLVMBasicBlockAsValue(LLVMBasicBlockRef BB);
1925 * Determine whether a LLVMValueRef is itself a basic block.
1927 LLVMBool LLVMValueIsBasicBlock(LLVMValueRef Val);
1930 * Convert a LLVMValueRef to a LLVMBasicBlockRef instance.
1932 LLVMBasicBlockRef LLVMValueAsBasicBlock(LLVMValueRef Val);
1935 * Obtain the function to which a basic block belongs.
1937 * @see llvm::BasicBlock::getParent()
1939 LLVMValueRef LLVMGetBasicBlockParent(LLVMBasicBlockRef BB);
1942 * Obtain the terminator instruction for a basic block.
1944 * If the basic block does not have a terminator (it is not well-formed
1945 * if it doesn't), then NULL is returned.
1947 * The returned LLVMValueRef corresponds to a llvm::TerminatorInst.
1949 * @see llvm::BasicBlock::getTerminator()
1951 LLVMValueRef LLVMGetBasicBlockTerminator(LLVMBasicBlockRef BB);
1954 * Obtain the number of basic blocks in a function.
1956 * @param Fn Function value to operate on.
1958 unsigned LLVMCountBasicBlocks(LLVMValueRef Fn);
1961 * Obtain all of the basic blocks in a function.
1963 * This operates on a function value. The BasicBlocks parameter is a
1964 * pointer to a pre-allocated array of LLVMBasicBlockRef of at least
1965 * LLVMCountBasicBlocks() in length. This array is populated with
1966 * LLVMBasicBlockRef instances.
1968 void LLVMGetBasicBlocks(LLVMValueRef Fn, LLVMBasicBlockRef *BasicBlocks);
1971 * Obtain the first basic block in a function.
1973 * The returned basic block can be used as an iterator. You will likely
1974 * eventually call into LLVMGetNextBasicBlock() with it.
1976 * @see llvm::Function::begin()
1978 LLVMBasicBlockRef LLVMGetFirstBasicBlock(LLVMValueRef Fn);
1981 * Obtain the last basic block in a function.
1983 * @see llvm::Function::end()
1985 LLVMBasicBlockRef LLVMGetLastBasicBlock(LLVMValueRef Fn);
1988 * Advance a basic block iterator.
1990 LLVMBasicBlockRef LLVMGetNextBasicBlock(LLVMBasicBlockRef BB);
1993 * Go backwards in a basic block iterator.
1995 LLVMBasicBlockRef LLVMGetPreviousBasicBlock(LLVMBasicBlockRef BB);
1998 * Obtain the basic block that corresponds to the entry point of a
2001 * @see llvm::Function::getEntryBlock()
2003 LLVMBasicBlockRef LLVMGetEntryBasicBlock(LLVMValueRef Fn);
2006 * Append a basic block to the end of a function.
2008 * @see llvm::BasicBlock::Create()
2010 LLVMBasicBlockRef LLVMAppendBasicBlockInContext(LLVMContextRef C,
2015 * Append a basic block to the end of a function using the global
2018 * @see llvm::BasicBlock::Create()
2020 LLVMBasicBlockRef LLVMAppendBasicBlock(LLVMValueRef Fn, const char *Name);
2023 * Insert a basic block in a function before another basic block.
2025 * The function to add to is determined by the function of the
2026 * passed basic block.
2028 * @see llvm::BasicBlock::Create()
2030 LLVMBasicBlockRef LLVMInsertBasicBlockInContext(LLVMContextRef C,
2031 LLVMBasicBlockRef BB,
2035 * Insert a basic block in a function using the global context.
2037 * @see llvm::BasicBlock::Create()
2039 LLVMBasicBlockRef LLVMInsertBasicBlock(LLVMBasicBlockRef InsertBeforeBB,
2043 * Remove a basic block from a function and delete it.
2045 * This deletes the basic block from its containing function and deletes
2046 * the basic block itself.
2048 * @see llvm::BasicBlock::eraseFromParent()
2050 void LLVMDeleteBasicBlock(LLVMBasicBlockRef BB);
2053 * Remove a basic block from a function.
2055 * This deletes the basic block from its containing function but keep
2056 * the basic block alive.
2058 * @see llvm::BasicBlock::removeFromParent()
2060 void LLVMRemoveBasicBlockFromParent(LLVMBasicBlockRef BB);
2063 * Move a basic block to before another one.
2065 * @see llvm::BasicBlock::moveBefore()
2067 void LLVMMoveBasicBlockBefore(LLVMBasicBlockRef BB, LLVMBasicBlockRef MovePos);
2070 * Move a basic block to after another one.
2072 * @see llvm::BasicBlock::moveAfter()
2074 void LLVMMoveBasicBlockAfter(LLVMBasicBlockRef BB, LLVMBasicBlockRef MovePos);
2077 * Obtain the first instruction in a basic block.
2079 * The returned LLVMValueRef corresponds to a llvm::Instruction
2082 LLVMValueRef LLVMGetFirstInstruction(LLVMBasicBlockRef BB);
2085 * Obtain the last instruction in a basic block.
2087 * The returned LLVMValueRef corresponds to a LLVM:Instruction.
2089 LLVMValueRef LLVMGetLastInstruction(LLVMBasicBlockRef BB);
2096 * @defgroup LLVMCCoreValueInstruction Instructions
2098 * Functions in this group relate to the inspection and manipulation of
2099 * individual instructions.
2101 * In the C++ API, an instruction is modeled by llvm::Instruction. This
2102 * class has a large number of descendents. llvm::Instruction is a
2103 * llvm::Value and in the C API, instructions are modeled by
2106 * This group also contains sub-groups which operate on specific
2107 * llvm::Instruction types, e.g. llvm::CallInst.
2113 * Determine whether an instruction has any metadata attached.
2115 int LLVMHasMetadata(LLVMValueRef Val);
2118 * Return metadata associated with an instruction value.
2120 LLVMValueRef LLVMGetMetadata(LLVMValueRef Val, unsigned KindID);
2123 * Set metadata associated with an instruction value.
2125 void LLVMSetMetadata(LLVMValueRef Val, unsigned KindID, LLVMValueRef Node);
2128 * Obtain the basic block to which an instruction belongs.
2130 * @see llvm::Instruction::getParent()
2132 LLVMBasicBlockRef LLVMGetInstructionParent(LLVMValueRef Inst);
2135 * Obtain the instruction that occurs after the one specified.
2137 * The next instruction will be from the same basic block.
2139 * If this is the last instruction in a basic block, NULL will be
2142 LLVMValueRef LLVMGetNextInstruction(LLVMValueRef Inst);
2145 * Obtain the instruction that occurred before this one.
2147 * If the instruction is the first instruction in a basic block, NULL
2150 LLVMValueRef LLVMGetPreviousInstruction(LLVMValueRef Inst);
2153 * Remove and delete an instruction.
2155 * The instruction specified is removed from its containing building
2156 * block and then deleted.
2158 * @see llvm::Instruction::eraseFromParent()
2160 void LLVMInstructionEraseFromParent(LLVMValueRef Inst);
2163 * Obtain the code opcode for an individual instruction.
2165 * @see llvm::Instruction::getOpCode()
2167 LLVMOpcode LLVMGetInstructionOpcode(LLVMValueRef Inst);
2170 * Obtain the predicate of an instruction.
2172 * This is only valid for instructions that correspond to llvm::ICmpInst
2173 * or llvm::ConstantExpr whose opcode is llvm::Instruction::ICmp.
2175 * @see llvm::ICmpInst::getPredicate()
2177 LLVMIntPredicate LLVMGetICmpPredicate(LLVMValueRef Inst);
2180 * @defgroup LLVMCCoreValueInstructionCall Call Sites and Invocations
2182 * Functions in this group apply to instructions that refer to call
2183 * sites and invocations. These correspond to C++ types in the
2184 * llvm::CallInst class tree.
2190 * Set the calling convention for a call instruction.
2192 * This expects an LLVMValueRef that corresponds to a llvm::CallInst or
2195 * @see llvm::CallInst::setCallingConv()
2196 * @see llvm::InvokeInst::setCallingConv()
2198 void LLVMSetInstructionCallConv(LLVMValueRef Instr, unsigned CC);
2201 * Obtain the calling convention for a call instruction.
2203 * This is the opposite of LLVMSetInstructionCallConv(). Reads its
2206 * @see LLVMSetInstructionCallConv()
2208 unsigned LLVMGetInstructionCallConv(LLVMValueRef Instr);
2211 void LLVMAddInstrAttribute(LLVMValueRef Instr, unsigned index, LLVMAttribute);
2212 void LLVMRemoveInstrAttribute(LLVMValueRef Instr, unsigned index,
2214 void LLVMSetInstrParamAlignment(LLVMValueRef Instr, unsigned index,
2218 * Obtain whether a call instruction is a tail call.
2220 * This only works on llvm::CallInst instructions.
2222 * @see llvm::CallInst::isTailCall()
2224 LLVMBool LLVMIsTailCall(LLVMValueRef CallInst);
2227 * Set whether a call instruction is a tail call.
2229 * This only works on llvm::CallInst instructions.
2231 * @see llvm::CallInst::setTailCall()
2233 void LLVMSetTailCall(LLVMValueRef CallInst, LLVMBool IsTailCall);
2240 * Obtain the default destination basic block of a switch instruction.
2242 * This only works on llvm::SwitchInst instructions.
2244 * @see llvm::SwitchInst::getDefaultDest()
2246 LLVMBasicBlockRef LLVMGetSwitchDefaultDest(LLVMValueRef SwitchInstr);
2249 * @defgroup LLVMCCoreValueInstructionPHINode PHI Nodes
2251 * Functions in this group only apply to instructions that map to
2252 * llvm::PHINode instances.
2258 * Add an incoming value to the end of a PHI list.
2260 void LLVMAddIncoming(LLVMValueRef PhiNode, LLVMValueRef *IncomingValues,
2261 LLVMBasicBlockRef *IncomingBlocks, unsigned Count);
2264 * Obtain the number of incoming basic blocks to a PHI node.
2266 unsigned LLVMCountIncoming(LLVMValueRef PhiNode);
2269 * Obtain an incoming value to a PHI node as a LLVMValueRef.
2271 LLVMValueRef LLVMGetIncomingValue(LLVMValueRef PhiNode, unsigned Index);
2274 * Obtain an incoming value to a PHI node as a LLVMBasicBlockRef.
2276 LLVMBasicBlockRef LLVMGetIncomingBlock(LLVMValueRef PhiNode, unsigned Index);
2291 * @defgroup LLVMCCoreInstructionBuilder Instruction Builders
2293 * An instruction builder represents a point within a basic block and is
2294 * the exclusive means of building instructions using the C interface.
2299 LLVMBuilderRef LLVMCreateBuilderInContext(LLVMContextRef C);
2300 LLVMBuilderRef LLVMCreateBuilder(void);
2301 void LLVMPositionBuilder(LLVMBuilderRef Builder, LLVMBasicBlockRef Block,
2302 LLVMValueRef Instr);
2303 void LLVMPositionBuilderBefore(LLVMBuilderRef Builder, LLVMValueRef Instr);
2304 void LLVMPositionBuilderAtEnd(LLVMBuilderRef Builder, LLVMBasicBlockRef Block);
2305 LLVMBasicBlockRef LLVMGetInsertBlock(LLVMBuilderRef Builder);
2306 void LLVMClearInsertionPosition(LLVMBuilderRef Builder);
2307 void LLVMInsertIntoBuilder(LLVMBuilderRef Builder, LLVMValueRef Instr);
2308 void LLVMInsertIntoBuilderWithName(LLVMBuilderRef Builder, LLVMValueRef Instr,
2310 void LLVMDisposeBuilder(LLVMBuilderRef Builder);
2313 void LLVMSetCurrentDebugLocation(LLVMBuilderRef Builder, LLVMValueRef L);
2314 LLVMValueRef LLVMGetCurrentDebugLocation(LLVMBuilderRef Builder);
2315 void LLVMSetInstDebugLocation(LLVMBuilderRef Builder, LLVMValueRef Inst);
2318 LLVMValueRef LLVMBuildRetVoid(LLVMBuilderRef);
2319 LLVMValueRef LLVMBuildRet(LLVMBuilderRef, LLVMValueRef V);
2320 LLVMValueRef LLVMBuildAggregateRet(LLVMBuilderRef, LLVMValueRef *RetVals,
2322 LLVMValueRef LLVMBuildBr(LLVMBuilderRef, LLVMBasicBlockRef Dest);
2323 LLVMValueRef LLVMBuildCondBr(LLVMBuilderRef, LLVMValueRef If,
2324 LLVMBasicBlockRef Then, LLVMBasicBlockRef Else);
2325 LLVMValueRef LLVMBuildSwitch(LLVMBuilderRef, LLVMValueRef V,
2326 LLVMBasicBlockRef Else, unsigned NumCases);
2327 LLVMValueRef LLVMBuildIndirectBr(LLVMBuilderRef B, LLVMValueRef Addr,
2329 LLVMValueRef LLVMBuildInvoke(LLVMBuilderRef, LLVMValueRef Fn,
2330 LLVMValueRef *Args, unsigned NumArgs,
2331 LLVMBasicBlockRef Then, LLVMBasicBlockRef Catch,
2333 LLVMValueRef LLVMBuildLandingPad(LLVMBuilderRef B, LLVMTypeRef Ty,
2334 LLVMValueRef PersFn, unsigned NumClauses,
2336 LLVMValueRef LLVMBuildResume(LLVMBuilderRef B, LLVMValueRef Exn);
2337 LLVMValueRef LLVMBuildUnreachable(LLVMBuilderRef);
2339 /* Add a case to the switch instruction */
2340 void LLVMAddCase(LLVMValueRef Switch, LLVMValueRef OnVal,
2341 LLVMBasicBlockRef Dest);
2343 /* Add a destination to the indirectbr instruction */
2344 void LLVMAddDestination(LLVMValueRef IndirectBr, LLVMBasicBlockRef Dest);
2346 /* Add a catch or filter clause to the landingpad instruction */
2347 void LLVMAddClause(LLVMValueRef LandingPad, LLVMValueRef ClauseVal);
2349 /* Set the 'cleanup' flag in the landingpad instruction */
2350 void LLVMSetCleanup(LLVMValueRef LandingPad, LLVMBool Val);
2353 LLVMValueRef LLVMBuildAdd(LLVMBuilderRef, LLVMValueRef LHS, LLVMValueRef RHS,
2355 LLVMValueRef LLVMBuildNSWAdd(LLVMBuilderRef, LLVMValueRef LHS, LLVMValueRef RHS,
2357 LLVMValueRef LLVMBuildNUWAdd(LLVMBuilderRef, LLVMValueRef LHS, LLVMValueRef RHS,
2359 LLVMValueRef LLVMBuildFAdd(LLVMBuilderRef, LLVMValueRef LHS, LLVMValueRef RHS,
2361 LLVMValueRef LLVMBuildSub(LLVMBuilderRef, LLVMValueRef LHS, LLVMValueRef RHS,
2363 LLVMValueRef LLVMBuildNSWSub(LLVMBuilderRef, LLVMValueRef LHS, LLVMValueRef RHS,
2365 LLVMValueRef LLVMBuildNUWSub(LLVMBuilderRef, LLVMValueRef LHS, LLVMValueRef RHS,
2367 LLVMValueRef LLVMBuildFSub(LLVMBuilderRef, LLVMValueRef LHS, LLVMValueRef RHS,
2369 LLVMValueRef LLVMBuildMul(LLVMBuilderRef, LLVMValueRef LHS, LLVMValueRef RHS,
2371 LLVMValueRef LLVMBuildNSWMul(LLVMBuilderRef, LLVMValueRef LHS, LLVMValueRef RHS,
2373 LLVMValueRef LLVMBuildNUWMul(LLVMBuilderRef, LLVMValueRef LHS, LLVMValueRef RHS,
2375 LLVMValueRef LLVMBuildFMul(LLVMBuilderRef, LLVMValueRef LHS, LLVMValueRef RHS,
2377 LLVMValueRef LLVMBuildUDiv(LLVMBuilderRef, LLVMValueRef LHS, LLVMValueRef RHS,
2379 LLVMValueRef LLVMBuildSDiv(LLVMBuilderRef, LLVMValueRef LHS, LLVMValueRef RHS,
2381 LLVMValueRef LLVMBuildExactSDiv(LLVMBuilderRef, LLVMValueRef LHS, LLVMValueRef RHS,
2383 LLVMValueRef LLVMBuildFDiv(LLVMBuilderRef, LLVMValueRef LHS, LLVMValueRef RHS,
2385 LLVMValueRef LLVMBuildURem(LLVMBuilderRef, LLVMValueRef LHS, LLVMValueRef RHS,
2387 LLVMValueRef LLVMBuildSRem(LLVMBuilderRef, LLVMValueRef LHS, LLVMValueRef RHS,
2389 LLVMValueRef LLVMBuildFRem(LLVMBuilderRef, LLVMValueRef LHS, LLVMValueRef RHS,
2391 LLVMValueRef LLVMBuildShl(LLVMBuilderRef, LLVMValueRef LHS, LLVMValueRef RHS,
2393 LLVMValueRef LLVMBuildLShr(LLVMBuilderRef, LLVMValueRef LHS, LLVMValueRef RHS,
2395 LLVMValueRef LLVMBuildAShr(LLVMBuilderRef, LLVMValueRef LHS, LLVMValueRef RHS,
2397 LLVMValueRef LLVMBuildAnd(LLVMBuilderRef, LLVMValueRef LHS, LLVMValueRef RHS,
2399 LLVMValueRef LLVMBuildOr(LLVMBuilderRef, LLVMValueRef LHS, LLVMValueRef RHS,
2401 LLVMValueRef LLVMBuildXor(LLVMBuilderRef, LLVMValueRef LHS, LLVMValueRef RHS,
2403 LLVMValueRef LLVMBuildBinOp(LLVMBuilderRef B, LLVMOpcode Op,
2404 LLVMValueRef LHS, LLVMValueRef RHS,
2406 LLVMValueRef LLVMBuildNeg(LLVMBuilderRef, LLVMValueRef V, const char *Name);
2407 LLVMValueRef LLVMBuildNSWNeg(LLVMBuilderRef B, LLVMValueRef V,
2409 LLVMValueRef LLVMBuildNUWNeg(LLVMBuilderRef B, LLVMValueRef V,
2411 LLVMValueRef LLVMBuildFNeg(LLVMBuilderRef, LLVMValueRef V, const char *Name);
2412 LLVMValueRef LLVMBuildNot(LLVMBuilderRef, LLVMValueRef V, const char *Name);
2415 LLVMValueRef LLVMBuildMalloc(LLVMBuilderRef, LLVMTypeRef Ty, const char *Name);
2416 LLVMValueRef LLVMBuildArrayMalloc(LLVMBuilderRef, LLVMTypeRef Ty,
2417 LLVMValueRef Val, const char *Name);
2418 LLVMValueRef LLVMBuildAlloca(LLVMBuilderRef, LLVMTypeRef Ty, const char *Name);
2419 LLVMValueRef LLVMBuildArrayAlloca(LLVMBuilderRef, LLVMTypeRef Ty,
2420 LLVMValueRef Val, const char *Name);
2421 LLVMValueRef LLVMBuildFree(LLVMBuilderRef, LLVMValueRef PointerVal);
2422 LLVMValueRef LLVMBuildLoad(LLVMBuilderRef, LLVMValueRef PointerVal,
2424 LLVMValueRef LLVMBuildStore(LLVMBuilderRef, LLVMValueRef Val, LLVMValueRef Ptr);
2425 LLVMValueRef LLVMBuildGEP(LLVMBuilderRef B, LLVMValueRef Pointer,
2426 LLVMValueRef *Indices, unsigned NumIndices,
2428 LLVMValueRef LLVMBuildInBoundsGEP(LLVMBuilderRef B, LLVMValueRef Pointer,
2429 LLVMValueRef *Indices, unsigned NumIndices,
2431 LLVMValueRef LLVMBuildStructGEP(LLVMBuilderRef B, LLVMValueRef Pointer,
2432 unsigned Idx, const char *Name);
2433 LLVMValueRef LLVMBuildGlobalString(LLVMBuilderRef B, const char *Str,
2435 LLVMValueRef LLVMBuildGlobalStringPtr(LLVMBuilderRef B, const char *Str,
2437 LLVMBool LLVMGetVolatile(LLVMValueRef MemoryAccessInst);
2438 void LLVMSetVolatile(LLVMValueRef MemoryAccessInst, LLVMBool IsVolatile);
2441 LLVMValueRef LLVMBuildTrunc(LLVMBuilderRef, LLVMValueRef Val,
2442 LLVMTypeRef DestTy, const char *Name);
2443 LLVMValueRef LLVMBuildZExt(LLVMBuilderRef, LLVMValueRef Val,
2444 LLVMTypeRef DestTy, const char *Name);
2445 LLVMValueRef LLVMBuildSExt(LLVMBuilderRef, LLVMValueRef Val,
2446 LLVMTypeRef DestTy, const char *Name);
2447 LLVMValueRef LLVMBuildFPToUI(LLVMBuilderRef, LLVMValueRef Val,
2448 LLVMTypeRef DestTy, const char *Name);
2449 LLVMValueRef LLVMBuildFPToSI(LLVMBuilderRef, LLVMValueRef Val,
2450 LLVMTypeRef DestTy, const char *Name);
2451 LLVMValueRef LLVMBuildUIToFP(LLVMBuilderRef, LLVMValueRef Val,
2452 LLVMTypeRef DestTy, const char *Name);
2453 LLVMValueRef LLVMBuildSIToFP(LLVMBuilderRef, LLVMValueRef Val,
2454 LLVMTypeRef DestTy, const char *Name);
2455 LLVMValueRef LLVMBuildFPTrunc(LLVMBuilderRef, LLVMValueRef Val,
2456 LLVMTypeRef DestTy, const char *Name);
2457 LLVMValueRef LLVMBuildFPExt(LLVMBuilderRef, LLVMValueRef Val,
2458 LLVMTypeRef DestTy, const char *Name);
2459 LLVMValueRef LLVMBuildPtrToInt(LLVMBuilderRef, LLVMValueRef Val,
2460 LLVMTypeRef DestTy, const char *Name);
2461 LLVMValueRef LLVMBuildIntToPtr(LLVMBuilderRef, LLVMValueRef Val,
2462 LLVMTypeRef DestTy, const char *Name);
2463 LLVMValueRef LLVMBuildBitCast(LLVMBuilderRef, LLVMValueRef Val,
2464 LLVMTypeRef DestTy, const char *Name);
2465 LLVMValueRef LLVMBuildZExtOrBitCast(LLVMBuilderRef, LLVMValueRef Val,
2466 LLVMTypeRef DestTy, const char *Name);
2467 LLVMValueRef LLVMBuildSExtOrBitCast(LLVMBuilderRef, LLVMValueRef Val,
2468 LLVMTypeRef DestTy, const char *Name);
2469 LLVMValueRef LLVMBuildTruncOrBitCast(LLVMBuilderRef, LLVMValueRef Val,
2470 LLVMTypeRef DestTy, const char *Name);
2471 LLVMValueRef LLVMBuildCast(LLVMBuilderRef B, LLVMOpcode Op, LLVMValueRef Val,
2472 LLVMTypeRef DestTy, const char *Name);
2473 LLVMValueRef LLVMBuildPointerCast(LLVMBuilderRef, LLVMValueRef Val,
2474 LLVMTypeRef DestTy, const char *Name);
2475 LLVMValueRef LLVMBuildIntCast(LLVMBuilderRef, LLVMValueRef Val, /*Signed cast!*/
2476 LLVMTypeRef DestTy, const char *Name);
2477 LLVMValueRef LLVMBuildFPCast(LLVMBuilderRef, LLVMValueRef Val,
2478 LLVMTypeRef DestTy, const char *Name);
2481 LLVMValueRef LLVMBuildICmp(LLVMBuilderRef, LLVMIntPredicate Op,
2482 LLVMValueRef LHS, LLVMValueRef RHS,
2484 LLVMValueRef LLVMBuildFCmp(LLVMBuilderRef, LLVMRealPredicate Op,
2485 LLVMValueRef LHS, LLVMValueRef RHS,
2488 /* Miscellaneous instructions */
2489 LLVMValueRef LLVMBuildPhi(LLVMBuilderRef, LLVMTypeRef Ty, const char *Name);
2490 LLVMValueRef LLVMBuildCall(LLVMBuilderRef, LLVMValueRef Fn,
2491 LLVMValueRef *Args, unsigned NumArgs,
2493 LLVMValueRef LLVMBuildSelect(LLVMBuilderRef, LLVMValueRef If,
2494 LLVMValueRef Then, LLVMValueRef Else,
2496 LLVMValueRef LLVMBuildVAArg(LLVMBuilderRef, LLVMValueRef List, LLVMTypeRef Ty,
2498 LLVMValueRef LLVMBuildExtractElement(LLVMBuilderRef, LLVMValueRef VecVal,
2499 LLVMValueRef Index, const char *Name);
2500 LLVMValueRef LLVMBuildInsertElement(LLVMBuilderRef, LLVMValueRef VecVal,
2501 LLVMValueRef EltVal, LLVMValueRef Index,
2503 LLVMValueRef LLVMBuildShuffleVector(LLVMBuilderRef, LLVMValueRef V1,
2504 LLVMValueRef V2, LLVMValueRef Mask,
2506 LLVMValueRef LLVMBuildExtractValue(LLVMBuilderRef, LLVMValueRef AggVal,
2507 unsigned Index, const char *Name);
2508 LLVMValueRef LLVMBuildInsertValue(LLVMBuilderRef, LLVMValueRef AggVal,
2509 LLVMValueRef EltVal, unsigned Index,
2512 LLVMValueRef LLVMBuildIsNull(LLVMBuilderRef, LLVMValueRef Val,
2514 LLVMValueRef LLVMBuildIsNotNull(LLVMBuilderRef, LLVMValueRef Val,
2516 LLVMValueRef LLVMBuildPtrDiff(LLVMBuilderRef, LLVMValueRef LHS,
2517 LLVMValueRef RHS, const char *Name);
2524 * @defgroup LLVMCCoreModuleProvider Module Providers
2530 * Changes the type of M so it can be passed to FunctionPassManagers and the
2531 * JIT. They take ModuleProviders for historical reasons.
2533 LLVMModuleProviderRef
2534 LLVMCreateModuleProviderForExistingModule(LLVMModuleRef M);
2537 * Destroys the module M.
2539 void LLVMDisposeModuleProvider(LLVMModuleProviderRef M);
2546 * @defgroup LLVMCCoreMemoryBuffers Memory Buffers
2551 LLVMBool LLVMCreateMemoryBufferWithContentsOfFile(const char *Path,
2552 LLVMMemoryBufferRef *OutMemBuf,
2554 LLVMBool LLVMCreateMemoryBufferWithSTDIN(LLVMMemoryBufferRef *OutMemBuf,
2556 LLVMMemoryBufferRef LLVMCreateMemoryBufferWithMemoryRange(const char *InputData,
2557 size_t InputDataLength,
2558 const char *BufferName,
2559 LLVMBool RequiresNullTerminator);
2560 LLVMMemoryBufferRef LLVMCreateMemoryBufferWithMemoryRangeCopy(const char *InputData,
2561 size_t InputDataLength,
2562 const char *BufferName);
2563 void LLVMDisposeMemoryBuffer(LLVMMemoryBufferRef MemBuf);
2570 * @defgroup LLVMCCorePassRegistry Pass Registry
2575 /** Return the global pass registry, for use with initialization functions.
2576 @see llvm::PassRegistry::getPassRegistry */
2577 LLVMPassRegistryRef LLVMGetGlobalPassRegistry(void);
2584 * @defgroup LLVMCCorePassManagers Pass Managers
2589 /** Constructs a new whole-module pass pipeline. This type of pipeline is
2590 suitable for link-time optimization and whole-module transformations.
2591 @see llvm::PassManager::PassManager */
2592 LLVMPassManagerRef LLVMCreatePassManager(void);
2594 /** Constructs a new function-by-function pass pipeline over the module
2595 provider. It does not take ownership of the module provider. This type of
2596 pipeline is suitable for code generation and JIT compilation tasks.
2597 @see llvm::FunctionPassManager::FunctionPassManager */
2598 LLVMPassManagerRef LLVMCreateFunctionPassManagerForModule(LLVMModuleRef M);
2600 /** Deprecated: Use LLVMCreateFunctionPassManagerForModule instead. */
2601 LLVMPassManagerRef LLVMCreateFunctionPassManager(LLVMModuleProviderRef MP);
2603 /** Initializes, executes on the provided module, and finalizes all of the
2604 passes scheduled in the pass manager. Returns 1 if any of the passes
2605 modified the module, 0 otherwise.
2606 @see llvm::PassManager::run(Module&) */
2607 LLVMBool LLVMRunPassManager(LLVMPassManagerRef PM, LLVMModuleRef M);
2609 /** Initializes all of the function passes scheduled in the function pass
2610 manager. Returns 1 if any of the passes modified the module, 0 otherwise.
2611 @see llvm::FunctionPassManager::doInitialization */
2612 LLVMBool LLVMInitializeFunctionPassManager(LLVMPassManagerRef FPM);
2614 /** Executes all of the function passes scheduled in the function pass manager
2615 on the provided function. Returns 1 if any of the passes modified the
2616 function, false otherwise.
2617 @see llvm::FunctionPassManager::run(Function&) */
2618 LLVMBool LLVMRunFunctionPassManager(LLVMPassManagerRef FPM, LLVMValueRef F);
2620 /** Finalizes all of the function passes scheduled in in the function pass
2621 manager. Returns 1 if any of the passes modified the module, 0 otherwise.
2622 @see llvm::FunctionPassManager::doFinalization */
2623 LLVMBool LLVMFinalizeFunctionPassManager(LLVMPassManagerRef FPM);
2625 /** Frees the memory of a pass pipeline. For function pipelines, does not free
2626 the module provider.
2627 @see llvm::PassManagerBase::~PassManagerBase. */
2628 void LLVMDisposePassManager(LLVMPassManagerRef PM);
2635 * @defgroup LLVMCCoreThreading Threading
2637 * Handle the structures needed to make LLVM safe for multithreading.
2642 /** Allocate and initialize structures needed to make LLVM safe for
2643 multithreading. The return value indicates whether multithreaded
2644 initialization succeeded. Must be executed in isolation from all
2645 other LLVM api calls.
2646 @see llvm::llvm_start_multithreaded */
2647 LLVMBool LLVMStartMultithreaded();
2649 /** Deallocate structures necessary to make LLVM safe for multithreading.
2650 Must be executed in isolation from all other LLVM api calls.
2651 @see llvm::llvm_stop_multithreaded */
2652 void LLVMStopMultithreaded();
2654 /** Check whether LLVM is executing in thread-safe mode or not.
2655 @see llvm::llvm_is_multithreaded */
2656 LLVMBool LLVMIsMultithreaded();
2675 class PassManagerBase;
2677 #define DEFINE_SIMPLE_CONVERSION_FUNCTIONS(ty, ref) \
2678 inline ty *unwrap(ref P) { \
2679 return reinterpret_cast<ty*>(P); \
2682 inline ref wrap(const ty *P) { \
2683 return reinterpret_cast<ref>(const_cast<ty*>(P)); \
2686 #define DEFINE_ISA_CONVERSION_FUNCTIONS(ty, ref) \
2687 DEFINE_SIMPLE_CONVERSION_FUNCTIONS(ty, ref) \
2689 template<typename T> \
2690 inline T *unwrap(ref P) { \
2691 return cast<T>(unwrap(P)); \
2694 #define DEFINE_STDCXX_CONVERSION_FUNCTIONS(ty, ref) \
2695 DEFINE_SIMPLE_CONVERSION_FUNCTIONS(ty, ref) \
2697 template<typename T> \
2698 inline T *unwrap(ref P) { \
2699 T *Q = (T*)unwrap(P); \
2700 assert(Q && "Invalid cast!"); \
2704 DEFINE_ISA_CONVERSION_FUNCTIONS (Type, LLVMTypeRef )
2705 DEFINE_ISA_CONVERSION_FUNCTIONS (Value, LLVMValueRef )
2706 DEFINE_SIMPLE_CONVERSION_FUNCTIONS(Module, LLVMModuleRef )
2707 DEFINE_SIMPLE_CONVERSION_FUNCTIONS(BasicBlock, LLVMBasicBlockRef )
2708 DEFINE_SIMPLE_CONVERSION_FUNCTIONS(IRBuilder<>, LLVMBuilderRef )
2709 DEFINE_SIMPLE_CONVERSION_FUNCTIONS(MemoryBuffer, LLVMMemoryBufferRef )
2710 DEFINE_SIMPLE_CONVERSION_FUNCTIONS(LLVMContext, LLVMContextRef )
2711 DEFINE_SIMPLE_CONVERSION_FUNCTIONS(Use, LLVMUseRef )
2712 DEFINE_STDCXX_CONVERSION_FUNCTIONS(PassManagerBase, LLVMPassManagerRef )
2713 DEFINE_STDCXX_CONVERSION_FUNCTIONS(PassRegistry, LLVMPassRegistryRef )
2714 /* LLVMModuleProviderRef exists for historical reasons, but now just holds a
2717 inline Module *unwrap(LLVMModuleProviderRef MP) {
2718 return reinterpret_cast<Module*>(MP);
2721 #undef DEFINE_STDCXX_CONVERSION_FUNCTIONS
2722 #undef DEFINE_ISA_CONVERSION_FUNCTIONS
2723 #undef DEFINE_SIMPLE_CONVERSION_FUNCTIONS
2725 /* Specialized opaque context conversions.
2727 inline LLVMContext **unwrap(LLVMContextRef* Tys) {
2728 return reinterpret_cast<LLVMContext**>(Tys);
2731 inline LLVMContextRef *wrap(const LLVMContext **Tys) {
2732 return reinterpret_cast<LLVMContextRef*>(const_cast<LLVMContext**>(Tys));
2735 /* Specialized opaque type conversions.
2737 inline Type **unwrap(LLVMTypeRef* Tys) {
2738 return reinterpret_cast<Type**>(Tys);
2741 inline LLVMTypeRef *wrap(Type **Tys) {
2742 return reinterpret_cast<LLVMTypeRef*>(const_cast<Type**>(Tys));
2745 /* Specialized opaque value conversions.
2747 inline Value **unwrap(LLVMValueRef *Vals) {
2748 return reinterpret_cast<Value**>(Vals);
2751 template<typename T>
2752 inline T **unwrap(LLVMValueRef *Vals, unsigned Length) {
2754 for (LLVMValueRef *I = Vals, *E = Vals + Length; I != E; ++I)
2758 return reinterpret_cast<T**>(Vals);
2761 inline LLVMValueRef *wrap(const Value **Vals) {
2762 return reinterpret_cast<LLVMValueRef*>(const_cast<Value**>(Vals));
2766 #endif /* !defined(__cplusplus) */
2768 #endif /* !defined(LLVM_C_CORE_H) */