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/IRBuilder.h"
25 #include "llvm/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: 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 LLVMLinkOnceODRAutoHideLinkage, /**< Like LinkOnceODR, but possibly hidden. */
286 LLVMWeakAnyLinkage, /**< Keep one copy of function when linking (weak) */
287 LLVMWeakODRLinkage, /**< Same, but only replaced by something
289 LLVMAppendingLinkage, /**< Special purpose, only applies to global arrays */
290 LLVMInternalLinkage, /**< Rename collisions when linking (static
292 LLVMPrivateLinkage, /**< Like Internal, but omit from symbol table */
293 LLVMDLLImportLinkage, /**< Function to be imported from DLL */
294 LLVMDLLExportLinkage, /**< Function to be accessible from DLL */
295 LLVMExternalWeakLinkage,/**< ExternalWeak linkage description */
296 LLVMGhostLinkage, /**< Obsolete */
297 LLVMCommonLinkage, /**< Tentative definitions */
298 LLVMLinkerPrivateLinkage, /**< Like Private, but linker removes. */
299 LLVMLinkerPrivateWeakLinkage /**< Like LinkerPrivate, but is weak. */
303 LLVMDefaultVisibility, /**< The GV is visible */
304 LLVMHiddenVisibility, /**< The GV is hidden */
305 LLVMProtectedVisibility /**< The GV is protected */
310 LLVMFastCallConv = 8,
311 LLVMColdCallConv = 9,
312 LLVMX86StdcallCallConv = 64,
313 LLVMX86FastcallCallConv = 65
317 LLVMIntEQ = 32, /**< equal */
318 LLVMIntNE, /**< not equal */
319 LLVMIntUGT, /**< unsigned greater than */
320 LLVMIntUGE, /**< unsigned greater or equal */
321 LLVMIntULT, /**< unsigned less than */
322 LLVMIntULE, /**< unsigned less or equal */
323 LLVMIntSGT, /**< signed greater than */
324 LLVMIntSGE, /**< signed greater or equal */
325 LLVMIntSLT, /**< signed less than */
326 LLVMIntSLE /**< signed less or equal */
330 LLVMRealPredicateFalse, /**< Always false (always folded) */
331 LLVMRealOEQ, /**< True if ordered and equal */
332 LLVMRealOGT, /**< True if ordered and greater than */
333 LLVMRealOGE, /**< True if ordered and greater than or equal */
334 LLVMRealOLT, /**< True if ordered and less than */
335 LLVMRealOLE, /**< True if ordered and less than or equal */
336 LLVMRealONE, /**< True if ordered and operands are unequal */
337 LLVMRealORD, /**< True if ordered (no nans) */
338 LLVMRealUNO, /**< True if unordered: isnan(X) | isnan(Y) */
339 LLVMRealUEQ, /**< True if unordered or equal */
340 LLVMRealUGT, /**< True if unordered or greater than */
341 LLVMRealUGE, /**< True if unordered, greater than, or equal */
342 LLVMRealULT, /**< True if unordered or less than */
343 LLVMRealULE, /**< True if unordered, less than, or equal */
344 LLVMRealUNE, /**< True if unordered or not equal */
345 LLVMRealPredicateTrue /**< Always true (always folded) */
349 LLVMLandingPadCatch, /**< A catch clause */
350 LLVMLandingPadFilter /**< A filter clause */
351 } LLVMLandingPadClauseTy;
357 void LLVMInitializeCore(LLVMPassRegistryRef R);
360 /*===-- Error handling ----------------------------------------------------===*/
362 void LLVMDisposeMessage(char *Message);
366 * @defgroup LLVMCCoreContext Contexts
368 * Contexts are execution states for the core LLVM IR system.
370 * Most types are tied to a context instance. Multiple contexts can
371 * exist simultaneously. A single context is not thread safe. However,
372 * different contexts can execute on different threads simultaneously.
378 * Create a new context.
380 * Every call to this function should be paired with a call to
381 * LLVMContextDispose() or the context will leak memory.
383 LLVMContextRef LLVMContextCreate(void);
386 * Obtain the global context instance.
388 LLVMContextRef LLVMGetGlobalContext(void);
391 * Destroy a context instance.
393 * This should be called for every call to LLVMContextCreate() or memory
396 void LLVMContextDispose(LLVMContextRef C);
398 unsigned LLVMGetMDKindIDInContext(LLVMContextRef C, const char* Name,
400 unsigned LLVMGetMDKindID(const char* Name, unsigned SLen);
407 * @defgroup LLVMCCoreModule Modules
409 * Modules represent the top-level structure in a LLVM program. An LLVM
410 * module is effectively a translation unit or a collection of
411 * translation units merged together.
417 * Create a new, empty module in the global context.
419 * This is equivalent to calling LLVMModuleCreateWithNameInContext with
420 * LLVMGetGlobalContext() as the context parameter.
422 * Every invocation should be paired with LLVMDisposeModule() or memory
425 LLVMModuleRef LLVMModuleCreateWithName(const char *ModuleID);
428 * Create a new, empty module in a specific context.
430 * Every invocation should be paired with LLVMDisposeModule() or memory
433 LLVMModuleRef LLVMModuleCreateWithNameInContext(const char *ModuleID,
437 * Destroy a module instance.
439 * This must be called for every created module or memory will be
442 void LLVMDisposeModule(LLVMModuleRef M);
445 * Obtain the data layout for a module.
447 * @see Module::getDataLayout()
449 const char *LLVMGetDataLayout(LLVMModuleRef M);
452 * Set the data layout for a module.
454 * @see Module::setDataLayout()
456 void LLVMSetDataLayout(LLVMModuleRef M, const char *Triple);
459 * Obtain the target triple for a module.
461 * @see Module::getTargetTriple()
463 const char *LLVMGetTarget(LLVMModuleRef M);
466 * Set the target triple for a module.
468 * @see Module::setTargetTriple()
470 void LLVMSetTarget(LLVMModuleRef M, const char *Triple);
473 * Dump a representation of a module to stderr.
475 * @see Module::dump()
477 void LLVMDumpModule(LLVMModuleRef M);
480 * Print a representation of a module to a file. The ErrorMessage needs to be
481 * disposed with LLVMDisposeMessage. Returns 0 on success, 1 otherwise.
483 * @see Module::print()
485 LLVMBool LLVMPrintModuleToFile(LLVMModuleRef M, const char *Filename,
486 char **ErrorMessage);
489 * Set inline assembly for a module.
491 * @see Module::setModuleInlineAsm()
493 void LLVMSetModuleInlineAsm(LLVMModuleRef M, const char *Asm);
496 * Obtain the context to which this module is associated.
498 * @see Module::getContext()
500 LLVMContextRef LLVMGetModuleContext(LLVMModuleRef M);
503 * Obtain a Type from a module by its registered name.
505 LLVMTypeRef LLVMGetTypeByName(LLVMModuleRef M, const char *Name);
508 * Obtain the number of operands for named metadata in a module.
510 * @see llvm::Module::getNamedMetadata()
512 unsigned LLVMGetNamedMetadataNumOperands(LLVMModuleRef M, const char* name);
515 * Obtain the named metadata operands for a module.
517 * The passed LLVMValueRef pointer should refer to an array of
518 * LLVMValueRef at least LLVMGetNamedMetadataNumOperands long. This
519 * array will be populated with the LLVMValueRef instances. Each
520 * instance corresponds to a llvm::MDNode.
522 * @see llvm::Module::getNamedMetadata()
523 * @see llvm::MDNode::getOperand()
525 void LLVMGetNamedMetadataOperands(LLVMModuleRef M, const char* name, LLVMValueRef *Dest);
528 * Add an operand to named metadata.
530 * @see llvm::Module::getNamedMetadata()
531 * @see llvm::MDNode::addOperand()
533 void LLVMAddNamedMetadataOperand(LLVMModuleRef M, const char* name,
537 * Add a function to a module under a specified name.
539 * @see llvm::Function::Create()
541 LLVMValueRef LLVMAddFunction(LLVMModuleRef M, const char *Name,
542 LLVMTypeRef FunctionTy);
545 * Obtain a Function value from a Module by its name.
547 * The returned value corresponds to a llvm::Function value.
549 * @see llvm::Module::getFunction()
551 LLVMValueRef LLVMGetNamedFunction(LLVMModuleRef M, const char *Name);
554 * Obtain an iterator to the first Function in a Module.
556 * @see llvm::Module::begin()
558 LLVMValueRef LLVMGetFirstFunction(LLVMModuleRef M);
561 * Obtain an iterator to the last Function in a Module.
563 * @see llvm::Module::end()
565 LLVMValueRef LLVMGetLastFunction(LLVMModuleRef M);
568 * Advance a Function iterator to the next Function.
570 * Returns NULL if the iterator was already at the end and there are no more
573 LLVMValueRef LLVMGetNextFunction(LLVMValueRef Fn);
576 * Decrement a Function iterator to the previous Function.
578 * Returns NULL if the iterator was already at the beginning and there are
579 * no previous functions.
581 LLVMValueRef LLVMGetPreviousFunction(LLVMValueRef Fn);
588 * @defgroup LLVMCCoreType Types
590 * Types represent the type of a value.
592 * Types are associated with a context instance. The context internally
593 * deduplicates types so there is only 1 instance of a specific type
594 * alive at a time. In other words, a unique type is shared among all
595 * consumers within a context.
597 * A Type in the C API corresponds to llvm::Type.
599 * Types have the following hierarchy:
617 * Obtain the enumerated type of a Type instance.
619 * @see llvm::Type:getTypeID()
621 LLVMTypeKind LLVMGetTypeKind(LLVMTypeRef Ty);
624 * Whether the type has a known size.
626 * Things that don't have a size are abstract types, labels, and void.a
628 * @see llvm::Type::isSized()
630 LLVMBool LLVMTypeIsSized(LLVMTypeRef Ty);
633 * Obtain the context to which this type instance is associated.
635 * @see llvm::Type::getContext()
637 LLVMContextRef LLVMGetTypeContext(LLVMTypeRef Ty);
640 * @defgroup LLVMCCoreTypeInt Integer Types
642 * Functions in this section operate on integer types.
648 * Obtain an integer type from a context with specified bit width.
650 LLVMTypeRef LLVMInt1TypeInContext(LLVMContextRef C);
651 LLVMTypeRef LLVMInt8TypeInContext(LLVMContextRef C);
652 LLVMTypeRef LLVMInt16TypeInContext(LLVMContextRef C);
653 LLVMTypeRef LLVMInt32TypeInContext(LLVMContextRef C);
654 LLVMTypeRef LLVMInt64TypeInContext(LLVMContextRef C);
655 LLVMTypeRef LLVMIntTypeInContext(LLVMContextRef C, unsigned NumBits);
658 * Obtain an integer type from the global context with a specified bit
661 LLVMTypeRef LLVMInt1Type(void);
662 LLVMTypeRef LLVMInt8Type(void);
663 LLVMTypeRef LLVMInt16Type(void);
664 LLVMTypeRef LLVMInt32Type(void);
665 LLVMTypeRef LLVMInt64Type(void);
666 LLVMTypeRef LLVMIntType(unsigned NumBits);
667 unsigned LLVMGetIntTypeWidth(LLVMTypeRef IntegerTy);
674 * @defgroup LLVMCCoreTypeFloat Floating Point Types
680 * Obtain a 16-bit floating point type from a context.
682 LLVMTypeRef LLVMHalfTypeInContext(LLVMContextRef C);
685 * Obtain a 32-bit floating point type from a context.
687 LLVMTypeRef LLVMFloatTypeInContext(LLVMContextRef C);
690 * Obtain a 64-bit floating point type from a context.
692 LLVMTypeRef LLVMDoubleTypeInContext(LLVMContextRef C);
695 * Obtain a 80-bit floating point type (X87) from a context.
697 LLVMTypeRef LLVMX86FP80TypeInContext(LLVMContextRef C);
700 * Obtain a 128-bit floating point type (112-bit mantissa) from a
703 LLVMTypeRef LLVMFP128TypeInContext(LLVMContextRef C);
706 * Obtain a 128-bit floating point type (two 64-bits) from a context.
708 LLVMTypeRef LLVMPPCFP128TypeInContext(LLVMContextRef C);
711 * Obtain a floating point type from the global context.
713 * These map to the functions in this group of the same name.
715 LLVMTypeRef LLVMHalfType(void);
716 LLVMTypeRef LLVMFloatType(void);
717 LLVMTypeRef LLVMDoubleType(void);
718 LLVMTypeRef LLVMX86FP80Type(void);
719 LLVMTypeRef LLVMFP128Type(void);
720 LLVMTypeRef LLVMPPCFP128Type(void);
727 * @defgroup LLVMCCoreTypeFunction Function Types
733 * Obtain a function type consisting of a specified signature.
735 * The function is defined as a tuple of a return Type, a list of
736 * parameter types, and whether the function is variadic.
738 LLVMTypeRef LLVMFunctionType(LLVMTypeRef ReturnType,
739 LLVMTypeRef *ParamTypes, unsigned ParamCount,
743 * Returns whether a function type is variadic.
745 LLVMBool LLVMIsFunctionVarArg(LLVMTypeRef FunctionTy);
748 * Obtain the Type this function Type returns.
750 LLVMTypeRef LLVMGetReturnType(LLVMTypeRef FunctionTy);
753 * Obtain the number of parameters this function accepts.
755 unsigned LLVMCountParamTypes(LLVMTypeRef FunctionTy);
758 * Obtain the types of a function's parameters.
760 * The Dest parameter should point to a pre-allocated array of
761 * LLVMTypeRef at least LLVMCountParamTypes() large. On return, the
762 * first LLVMCountParamTypes() entries in the array will be populated
763 * with LLVMTypeRef instances.
765 * @param FunctionTy The function type to operate on.
766 * @param Dest Memory address of an array to be filled with result.
768 void LLVMGetParamTypes(LLVMTypeRef FunctionTy, LLVMTypeRef *Dest);
775 * @defgroup LLVMCCoreTypeStruct Structure Types
777 * These functions relate to LLVMTypeRef instances.
779 * @see llvm::StructType
785 * Create a new structure type in a context.
787 * A structure is specified by a list of inner elements/types and
788 * whether these can be packed together.
790 * @see llvm::StructType::create()
792 LLVMTypeRef LLVMStructTypeInContext(LLVMContextRef C, LLVMTypeRef *ElementTypes,
793 unsigned ElementCount, LLVMBool Packed);
796 * Create a new structure type in the global context.
798 * @see llvm::StructType::create()
800 LLVMTypeRef LLVMStructType(LLVMTypeRef *ElementTypes, unsigned ElementCount,
804 * Create an empty structure in a context having a specified name.
806 * @see llvm::StructType::create()
808 LLVMTypeRef LLVMStructCreateNamed(LLVMContextRef C, const char *Name);
811 * Obtain the name of a structure.
813 * @see llvm::StructType::getName()
815 const char *LLVMGetStructName(LLVMTypeRef Ty);
818 * Set the contents of a structure type.
820 * @see llvm::StructType::setBody()
822 void LLVMStructSetBody(LLVMTypeRef StructTy, LLVMTypeRef *ElementTypes,
823 unsigned ElementCount, LLVMBool Packed);
826 * Get the number of elements defined inside the structure.
828 * @see llvm::StructType::getNumElements()
830 unsigned LLVMCountStructElementTypes(LLVMTypeRef StructTy);
833 * Get the elements within a structure.
835 * The function is passed the address of a pre-allocated array of
836 * LLVMTypeRef at least LLVMCountStructElementTypes() long. After
837 * invocation, this array will be populated with the structure's
838 * elements. The objects in the destination array will have a lifetime
839 * of the structure type itself, which is the lifetime of the context it
842 void LLVMGetStructElementTypes(LLVMTypeRef StructTy, LLVMTypeRef *Dest);
845 * Determine whether a structure is packed.
847 * @see llvm::StructType::isPacked()
849 LLVMBool LLVMIsPackedStruct(LLVMTypeRef StructTy);
852 * Determine whether a structure is opaque.
854 * @see llvm::StructType::isOpaque()
856 LLVMBool LLVMIsOpaqueStruct(LLVMTypeRef StructTy);
864 * @defgroup LLVMCCoreTypeSequential Sequential Types
866 * Sequential types represents "arrays" of types. This is a super class
867 * for array, vector, and pointer types.
873 * Obtain the type of elements within a sequential type.
875 * This works on array, vector, and pointer types.
877 * @see llvm::SequentialType::getElementType()
879 LLVMTypeRef LLVMGetElementType(LLVMTypeRef Ty);
882 * Create a fixed size array type that refers to a specific type.
884 * The created type will exist in the context that its element type
887 * @see llvm::ArrayType::get()
889 LLVMTypeRef LLVMArrayType(LLVMTypeRef ElementType, unsigned ElementCount);
892 * Obtain the length of an array type.
894 * This only works on types that represent arrays.
896 * @see llvm::ArrayType::getNumElements()
898 unsigned LLVMGetArrayLength(LLVMTypeRef ArrayTy);
901 * Create a pointer type that points to a defined type.
903 * The created type will exist in the context that its pointee type
906 * @see llvm::PointerType::get()
908 LLVMTypeRef LLVMPointerType(LLVMTypeRef ElementType, unsigned AddressSpace);
911 * Obtain the address space of a pointer type.
913 * This only works on types that represent pointers.
915 * @see llvm::PointerType::getAddressSpace()
917 unsigned LLVMGetPointerAddressSpace(LLVMTypeRef PointerTy);
920 * Create a vector type that contains a defined type and has a specific
921 * number of elements.
923 * The created type will exist in the context thats its element type
926 * @see llvm::VectorType::get()
928 LLVMTypeRef LLVMVectorType(LLVMTypeRef ElementType, unsigned ElementCount);
931 * Obtain the number of elements in a vector type.
933 * This only works on types that represent vectors.
935 * @see llvm::VectorType::getNumElements()
937 unsigned LLVMGetVectorSize(LLVMTypeRef VectorTy);
944 * @defgroup LLVMCCoreTypeOther Other Types
950 * Create a void type in a context.
952 LLVMTypeRef LLVMVoidTypeInContext(LLVMContextRef C);
955 * Create a label type in a context.
957 LLVMTypeRef LLVMLabelTypeInContext(LLVMContextRef C);
960 * Create a X86 MMX type in a context.
962 LLVMTypeRef LLVMX86MMXTypeInContext(LLVMContextRef C);
965 * These are similar to the above functions except they operate on the
968 LLVMTypeRef LLVMVoidType(void);
969 LLVMTypeRef LLVMLabelType(void);
970 LLVMTypeRef LLVMX86MMXType(void);
981 * @defgroup LLVMCCoreValues Values
983 * The bulk of LLVM's object model consists of values, which comprise a very
984 * rich type hierarchy.
986 * LLVMValueRef essentially represents llvm::Value. There is a rich
987 * hierarchy of classes within this type. Depending on the instance
988 * obtained, not all APIs are available.
990 * Callers can determine the type of a LLVMValueRef by calling the
991 * LLVMIsA* family of functions (e.g. LLVMIsAArgument()). These
992 * functions are defined by a macro, so it isn't obvious which are
993 * available by looking at the Doxygen source code. Instead, look at the
994 * source definition of LLVM_FOR_EACH_VALUE_SUBCLASS and note the list
995 * of value names given. These value names also correspond to classes in
996 * the llvm::Value hierarchy.
1001 #define LLVM_FOR_EACH_VALUE_SUBCLASS(macro) \
1009 macro(BlockAddress) \
1010 macro(ConstantAggregateZero) \
1011 macro(ConstantArray) \
1012 macro(ConstantExpr) \
1014 macro(ConstantInt) \
1015 macro(ConstantPointerNull) \
1016 macro(ConstantStruct) \
1017 macro(ConstantVector) \
1018 macro(GlobalValue) \
1020 macro(GlobalAlias) \
1021 macro(GlobalVariable) \
1023 macro(Instruction) \
1024 macro(BinaryOperator) \
1026 macro(IntrinsicInst) \
1027 macro(DbgInfoIntrinsic) \
1028 macro(DbgDeclareInst) \
1029 macro(MemIntrinsic) \
1031 macro(MemMoveInst) \
1036 macro(ExtractElementInst) \
1037 macro(GetElementPtrInst) \
1038 macro(InsertElementInst) \
1039 macro(InsertValueInst) \
1040 macro(LandingPadInst) \
1043 macro(ShuffleVectorInst) \
1045 macro(TerminatorInst) \
1047 macro(IndirectBrInst) \
1051 macro(UnreachableInst) \
1053 macro(UnaryInstruction) \
1056 macro(BitCastInst) \
1060 macro(FPTruncInst) \
1061 macro(IntToPtrInst) \
1062 macro(PtrToIntInst) \
1068 macro(ExtractValueInst) \
1073 * @defgroup LLVMCCoreValueGeneral General APIs
1075 * Functions in this section work on all LLVMValueRef instances,
1076 * regardless of their sub-type. They correspond to functions available
1083 * Obtain the type of a value.
1085 * @see llvm::Value::getType()
1087 LLVMTypeRef LLVMTypeOf(LLVMValueRef Val);
1090 * Obtain the string name of a value.
1092 * @see llvm::Value::getName()
1094 const char *LLVMGetValueName(LLVMValueRef Val);
1097 * Set the string name of a value.
1099 * @see llvm::Value::setName()
1101 void LLVMSetValueName(LLVMValueRef Val, const char *Name);
1104 * Dump a representation of a value to stderr.
1106 * @see llvm::Value::dump()
1108 void LLVMDumpValue(LLVMValueRef Val);
1111 * Replace all uses of a value with another one.
1113 * @see llvm::Value::replaceAllUsesWith()
1115 void LLVMReplaceAllUsesWith(LLVMValueRef OldVal, LLVMValueRef NewVal);
1118 * Determine whether the specified constant instance is constant.
1120 LLVMBool LLVMIsConstant(LLVMValueRef Val);
1123 * Determine whether a value instance is undefined.
1125 LLVMBool LLVMIsUndef(LLVMValueRef Val);
1128 * Convert value instances between types.
1130 * Internally, a LLVMValueRef is "pinned" to a specific type. This
1131 * series of functions allows you to cast an instance to a specific
1134 * If the cast is not valid for the specified type, NULL is returned.
1136 * @see llvm::dyn_cast_or_null<>
1138 #define LLVM_DECLARE_VALUE_CAST(name) \
1139 LLVMValueRef LLVMIsA##name(LLVMValueRef Val);
1140 LLVM_FOR_EACH_VALUE_SUBCLASS(LLVM_DECLARE_VALUE_CAST)
1147 * @defgroup LLVMCCoreValueUses Usage
1149 * This module defines functions that allow you to inspect the uses of a
1152 * It is possible to obtain a LLVMUseRef for any LLVMValueRef instance.
1153 * Each LLVMUseRef (which corresponds to a llvm::Use instance) holds a
1154 * llvm::User and llvm::Value.
1160 * Obtain the first use of a value.
1162 * Uses are obtained in an iterator fashion. First, call this function
1163 * to obtain a reference to the first use. Then, call LLVMGetNextUse()
1164 * on that instance and all subsequently obtained instances until
1165 * LLVMGetNextUse() returns NULL.
1167 * @see llvm::Value::use_begin()
1169 LLVMUseRef LLVMGetFirstUse(LLVMValueRef Val);
1172 * Obtain the next use of a value.
1174 * This effectively advances the iterator. It returns NULL if you are on
1175 * the final use and no more are available.
1177 LLVMUseRef LLVMGetNextUse(LLVMUseRef U);
1180 * Obtain the user value for a user.
1182 * The returned value corresponds to a llvm::User type.
1184 * @see llvm::Use::getUser()
1186 LLVMValueRef LLVMGetUser(LLVMUseRef U);
1189 * Obtain the value this use corresponds to.
1191 * @see llvm::Use::get().
1193 LLVMValueRef LLVMGetUsedValue(LLVMUseRef U);
1200 * @defgroup LLVMCCoreValueUser User value
1202 * Function in this group pertain to LLVMValueRef instances that descent
1203 * from llvm::User. This includes constants, instructions, and
1210 * Obtain an operand at a specific index in a llvm::User value.
1212 * @see llvm::User::getOperand()
1214 LLVMValueRef LLVMGetOperand(LLVMValueRef Val, unsigned Index);
1217 * Set an operand at a specific index in a llvm::User value.
1219 * @see llvm::User::setOperand()
1221 void LLVMSetOperand(LLVMValueRef User, unsigned Index, LLVMValueRef Val);
1224 * Obtain the number of operands in a llvm::User value.
1226 * @see llvm::User::getNumOperands()
1228 int LLVMGetNumOperands(LLVMValueRef Val);
1235 * @defgroup LLVMCCoreValueConstant Constants
1237 * This section contains APIs for interacting with LLVMValueRef that
1238 * correspond to llvm::Constant instances.
1240 * These functions will work for any LLVMValueRef in the llvm::Constant
1247 * Obtain a constant value referring to the null instance of a type.
1249 * @see llvm::Constant::getNullValue()
1251 LLVMValueRef LLVMConstNull(LLVMTypeRef Ty); /* all zeroes */
1254 * Obtain a constant value referring to the instance of a type
1255 * consisting of all ones.
1257 * This is only valid for integer types.
1259 * @see llvm::Constant::getAllOnesValue()
1261 LLVMValueRef LLVMConstAllOnes(LLVMTypeRef Ty);
1264 * Obtain a constant value referring to an undefined value of a type.
1266 * @see llvm::UndefValue::get()
1268 LLVMValueRef LLVMGetUndef(LLVMTypeRef Ty);
1271 * Determine whether a value instance is null.
1273 * @see llvm::Constant::isNullValue()
1275 LLVMBool LLVMIsNull(LLVMValueRef Val);
1278 * Obtain a constant that is a constant pointer pointing to NULL for a
1281 LLVMValueRef LLVMConstPointerNull(LLVMTypeRef Ty);
1284 * @defgroup LLVMCCoreValueConstantScalar Scalar constants
1286 * Functions in this group model LLVMValueRef instances that correspond
1287 * to constants referring to scalar types.
1289 * For integer types, the LLVMTypeRef parameter should correspond to a
1290 * llvm::IntegerType instance and the returned LLVMValueRef will
1291 * correspond to a llvm::ConstantInt.
1293 * For floating point types, the LLVMTypeRef returned corresponds to a
1300 * Obtain a constant value for an integer type.
1302 * The returned value corresponds to a llvm::ConstantInt.
1304 * @see llvm::ConstantInt::get()
1306 * @param IntTy Integer type to obtain value of.
1307 * @param N The value the returned instance should refer to.
1308 * @param SignExtend Whether to sign extend the produced value.
1310 LLVMValueRef LLVMConstInt(LLVMTypeRef IntTy, unsigned long long N,
1311 LLVMBool SignExtend);
1314 * Obtain a constant value for an integer of arbitrary precision.
1316 * @see llvm::ConstantInt::get()
1318 LLVMValueRef LLVMConstIntOfArbitraryPrecision(LLVMTypeRef IntTy,
1320 const uint64_t Words[]);
1323 * Obtain a constant value for an integer parsed from a string.
1325 * A similar API, LLVMConstIntOfStringAndSize is also available. If the
1326 * string's length is available, it is preferred to call that function
1329 * @see llvm::ConstantInt::get()
1331 LLVMValueRef LLVMConstIntOfString(LLVMTypeRef IntTy, const char *Text,
1335 * Obtain a constant value for an integer parsed from a string with
1338 * @see llvm::ConstantInt::get()
1340 LLVMValueRef LLVMConstIntOfStringAndSize(LLVMTypeRef IntTy, const char *Text,
1341 unsigned SLen, uint8_t Radix);
1344 * Obtain a constant value referring to a double floating point value.
1346 LLVMValueRef LLVMConstReal(LLVMTypeRef RealTy, double N);
1349 * Obtain a constant for a floating point value parsed from a string.
1351 * A similar API, LLVMConstRealOfStringAndSize is also available. It
1352 * should be used if the input string's length is known.
1354 LLVMValueRef LLVMConstRealOfString(LLVMTypeRef RealTy, const char *Text);
1357 * Obtain a constant for a floating point value parsed from a string.
1359 LLVMValueRef LLVMConstRealOfStringAndSize(LLVMTypeRef RealTy, const char *Text,
1363 * Obtain the zero extended value for an integer constant value.
1365 * @see llvm::ConstantInt::getZExtValue()
1367 unsigned long long LLVMConstIntGetZExtValue(LLVMValueRef ConstantVal);
1370 * Obtain the sign extended value for an integer constant value.
1372 * @see llvm::ConstantInt::getSExtValue()
1374 long long LLVMConstIntGetSExtValue(LLVMValueRef ConstantVal);
1381 * @defgroup LLVMCCoreValueConstantComposite Composite Constants
1383 * Functions in this group operate on composite constants.
1389 * Create a ConstantDataSequential and initialize it with a string.
1391 * @see llvm::ConstantDataArray::getString()
1393 LLVMValueRef LLVMConstStringInContext(LLVMContextRef C, const char *Str,
1394 unsigned Length, LLVMBool DontNullTerminate);
1397 * Create a ConstantDataSequential with string content in the global context.
1399 * This is the same as LLVMConstStringInContext except it operates on the
1402 * @see LLVMConstStringInContext()
1403 * @see llvm::ConstantDataArray::getString()
1405 LLVMValueRef LLVMConstString(const char *Str, unsigned Length,
1406 LLVMBool DontNullTerminate);
1409 * Create an anonymous ConstantStruct with the specified values.
1411 * @see llvm::ConstantStruct::getAnon()
1413 LLVMValueRef LLVMConstStructInContext(LLVMContextRef C,
1414 LLVMValueRef *ConstantVals,
1415 unsigned Count, LLVMBool Packed);
1418 * Create a ConstantStruct in the global Context.
1420 * This is the same as LLVMConstStructInContext except it operates on the
1423 * @see LLVMConstStructInContext()
1425 LLVMValueRef LLVMConstStruct(LLVMValueRef *ConstantVals, unsigned Count,
1429 * Create a ConstantArray from values.
1431 * @see llvm::ConstantArray::get()
1433 LLVMValueRef LLVMConstArray(LLVMTypeRef ElementTy,
1434 LLVMValueRef *ConstantVals, unsigned Length);
1437 * Create a non-anonymous ConstantStruct from values.
1439 * @see llvm::ConstantStruct::get()
1441 LLVMValueRef LLVMConstNamedStruct(LLVMTypeRef StructTy,
1442 LLVMValueRef *ConstantVals,
1446 * Create a ConstantVector from values.
1448 * @see llvm::ConstantVector::get()
1450 LLVMValueRef LLVMConstVector(LLVMValueRef *ScalarConstantVals, unsigned Size);
1457 * @defgroup LLVMCCoreValueConstantExpressions Constant Expressions
1459 * Functions in this group correspond to APIs on llvm::ConstantExpr.
1461 * @see llvm::ConstantExpr.
1465 LLVMOpcode LLVMGetConstOpcode(LLVMValueRef ConstantVal);
1466 LLVMValueRef LLVMAlignOf(LLVMTypeRef Ty);
1467 LLVMValueRef LLVMSizeOf(LLVMTypeRef Ty);
1468 LLVMValueRef LLVMConstNeg(LLVMValueRef ConstantVal);
1469 LLVMValueRef LLVMConstNSWNeg(LLVMValueRef ConstantVal);
1470 LLVMValueRef LLVMConstNUWNeg(LLVMValueRef ConstantVal);
1471 LLVMValueRef LLVMConstFNeg(LLVMValueRef ConstantVal);
1472 LLVMValueRef LLVMConstNot(LLVMValueRef ConstantVal);
1473 LLVMValueRef LLVMConstAdd(LLVMValueRef LHSConstant, LLVMValueRef RHSConstant);
1474 LLVMValueRef LLVMConstNSWAdd(LLVMValueRef LHSConstant, LLVMValueRef RHSConstant);
1475 LLVMValueRef LLVMConstNUWAdd(LLVMValueRef LHSConstant, LLVMValueRef RHSConstant);
1476 LLVMValueRef LLVMConstFAdd(LLVMValueRef LHSConstant, LLVMValueRef RHSConstant);
1477 LLVMValueRef LLVMConstSub(LLVMValueRef LHSConstant, LLVMValueRef RHSConstant);
1478 LLVMValueRef LLVMConstNSWSub(LLVMValueRef LHSConstant, LLVMValueRef RHSConstant);
1479 LLVMValueRef LLVMConstNUWSub(LLVMValueRef LHSConstant, LLVMValueRef RHSConstant);
1480 LLVMValueRef LLVMConstFSub(LLVMValueRef LHSConstant, LLVMValueRef RHSConstant);
1481 LLVMValueRef LLVMConstMul(LLVMValueRef LHSConstant, LLVMValueRef RHSConstant);
1482 LLVMValueRef LLVMConstNSWMul(LLVMValueRef LHSConstant, LLVMValueRef RHSConstant);
1483 LLVMValueRef LLVMConstNUWMul(LLVMValueRef LHSConstant, LLVMValueRef RHSConstant);
1484 LLVMValueRef LLVMConstFMul(LLVMValueRef LHSConstant, LLVMValueRef RHSConstant);
1485 LLVMValueRef LLVMConstUDiv(LLVMValueRef LHSConstant, LLVMValueRef RHSConstant);
1486 LLVMValueRef LLVMConstSDiv(LLVMValueRef LHSConstant, LLVMValueRef RHSConstant);
1487 LLVMValueRef LLVMConstExactSDiv(LLVMValueRef LHSConstant, LLVMValueRef RHSConstant);
1488 LLVMValueRef LLVMConstFDiv(LLVMValueRef LHSConstant, LLVMValueRef RHSConstant);
1489 LLVMValueRef LLVMConstURem(LLVMValueRef LHSConstant, LLVMValueRef RHSConstant);
1490 LLVMValueRef LLVMConstSRem(LLVMValueRef LHSConstant, LLVMValueRef RHSConstant);
1491 LLVMValueRef LLVMConstFRem(LLVMValueRef LHSConstant, LLVMValueRef RHSConstant);
1492 LLVMValueRef LLVMConstAnd(LLVMValueRef LHSConstant, LLVMValueRef RHSConstant);
1493 LLVMValueRef LLVMConstOr(LLVMValueRef LHSConstant, LLVMValueRef RHSConstant);
1494 LLVMValueRef LLVMConstXor(LLVMValueRef LHSConstant, LLVMValueRef RHSConstant);
1495 LLVMValueRef LLVMConstICmp(LLVMIntPredicate Predicate,
1496 LLVMValueRef LHSConstant, LLVMValueRef RHSConstant);
1497 LLVMValueRef LLVMConstFCmp(LLVMRealPredicate Predicate,
1498 LLVMValueRef LHSConstant, LLVMValueRef RHSConstant);
1499 LLVMValueRef LLVMConstShl(LLVMValueRef LHSConstant, LLVMValueRef RHSConstant);
1500 LLVMValueRef LLVMConstLShr(LLVMValueRef LHSConstant, LLVMValueRef RHSConstant);
1501 LLVMValueRef LLVMConstAShr(LLVMValueRef LHSConstant, LLVMValueRef RHSConstant);
1502 LLVMValueRef LLVMConstGEP(LLVMValueRef ConstantVal,
1503 LLVMValueRef *ConstantIndices, unsigned NumIndices);
1504 LLVMValueRef LLVMConstInBoundsGEP(LLVMValueRef ConstantVal,
1505 LLVMValueRef *ConstantIndices,
1506 unsigned NumIndices);
1507 LLVMValueRef LLVMConstTrunc(LLVMValueRef ConstantVal, LLVMTypeRef ToType);
1508 LLVMValueRef LLVMConstSExt(LLVMValueRef ConstantVal, LLVMTypeRef ToType);
1509 LLVMValueRef LLVMConstZExt(LLVMValueRef ConstantVal, LLVMTypeRef ToType);
1510 LLVMValueRef LLVMConstFPTrunc(LLVMValueRef ConstantVal, LLVMTypeRef ToType);
1511 LLVMValueRef LLVMConstFPExt(LLVMValueRef ConstantVal, LLVMTypeRef ToType);
1512 LLVMValueRef LLVMConstUIToFP(LLVMValueRef ConstantVal, LLVMTypeRef ToType);
1513 LLVMValueRef LLVMConstSIToFP(LLVMValueRef ConstantVal, LLVMTypeRef ToType);
1514 LLVMValueRef LLVMConstFPToUI(LLVMValueRef ConstantVal, LLVMTypeRef ToType);
1515 LLVMValueRef LLVMConstFPToSI(LLVMValueRef ConstantVal, LLVMTypeRef ToType);
1516 LLVMValueRef LLVMConstPtrToInt(LLVMValueRef ConstantVal, LLVMTypeRef ToType);
1517 LLVMValueRef LLVMConstIntToPtr(LLVMValueRef ConstantVal, LLVMTypeRef ToType);
1518 LLVMValueRef LLVMConstBitCast(LLVMValueRef ConstantVal, LLVMTypeRef ToType);
1519 LLVMValueRef LLVMConstZExtOrBitCast(LLVMValueRef ConstantVal,
1520 LLVMTypeRef ToType);
1521 LLVMValueRef LLVMConstSExtOrBitCast(LLVMValueRef ConstantVal,
1522 LLVMTypeRef ToType);
1523 LLVMValueRef LLVMConstTruncOrBitCast(LLVMValueRef ConstantVal,
1524 LLVMTypeRef ToType);
1525 LLVMValueRef LLVMConstPointerCast(LLVMValueRef ConstantVal,
1526 LLVMTypeRef ToType);
1527 LLVMValueRef LLVMConstIntCast(LLVMValueRef ConstantVal, LLVMTypeRef ToType,
1529 LLVMValueRef LLVMConstFPCast(LLVMValueRef ConstantVal, LLVMTypeRef ToType);
1530 LLVMValueRef LLVMConstSelect(LLVMValueRef ConstantCondition,
1531 LLVMValueRef ConstantIfTrue,
1532 LLVMValueRef ConstantIfFalse);
1533 LLVMValueRef LLVMConstExtractElement(LLVMValueRef VectorConstant,
1534 LLVMValueRef IndexConstant);
1535 LLVMValueRef LLVMConstInsertElement(LLVMValueRef VectorConstant,
1536 LLVMValueRef ElementValueConstant,
1537 LLVMValueRef IndexConstant);
1538 LLVMValueRef LLVMConstShuffleVector(LLVMValueRef VectorAConstant,
1539 LLVMValueRef VectorBConstant,
1540 LLVMValueRef MaskConstant);
1541 LLVMValueRef LLVMConstExtractValue(LLVMValueRef AggConstant, unsigned *IdxList,
1543 LLVMValueRef LLVMConstInsertValue(LLVMValueRef AggConstant,
1544 LLVMValueRef ElementValueConstant,
1545 unsigned *IdxList, unsigned NumIdx);
1546 LLVMValueRef LLVMConstInlineAsm(LLVMTypeRef Ty,
1547 const char *AsmString, const char *Constraints,
1548 LLVMBool HasSideEffects, LLVMBool IsAlignStack);
1549 LLVMValueRef LLVMBlockAddress(LLVMValueRef F, LLVMBasicBlockRef BB);
1556 * @defgroup LLVMCCoreValueConstantGlobals Global Values
1558 * This group contains functions that operate on global values. Functions in
1559 * this group relate to functions in the llvm::GlobalValue class tree.
1561 * @see llvm::GlobalValue
1566 LLVMModuleRef LLVMGetGlobalParent(LLVMValueRef Global);
1567 LLVMBool LLVMIsDeclaration(LLVMValueRef Global);
1568 LLVMLinkage LLVMGetLinkage(LLVMValueRef Global);
1569 void LLVMSetLinkage(LLVMValueRef Global, LLVMLinkage Linkage);
1570 const char *LLVMGetSection(LLVMValueRef Global);
1571 void LLVMSetSection(LLVMValueRef Global, const char *Section);
1572 LLVMVisibility LLVMGetVisibility(LLVMValueRef Global);
1573 void LLVMSetVisibility(LLVMValueRef Global, LLVMVisibility Viz);
1574 unsigned LLVMGetAlignment(LLVMValueRef Global);
1575 void LLVMSetAlignment(LLVMValueRef Global, unsigned Bytes);
1578 * @defgroup LLVMCoreValueConstantGlobalVariable Global Variables
1580 * This group contains functions that operate on global variable values.
1582 * @see llvm::GlobalVariable
1586 LLVMValueRef LLVMAddGlobal(LLVMModuleRef M, LLVMTypeRef Ty, const char *Name);
1587 LLVMValueRef LLVMAddGlobalInAddressSpace(LLVMModuleRef M, LLVMTypeRef Ty,
1589 unsigned AddressSpace);
1590 LLVMValueRef LLVMGetNamedGlobal(LLVMModuleRef M, const char *Name);
1591 LLVMValueRef LLVMGetFirstGlobal(LLVMModuleRef M);
1592 LLVMValueRef LLVMGetLastGlobal(LLVMModuleRef M);
1593 LLVMValueRef LLVMGetNextGlobal(LLVMValueRef GlobalVar);
1594 LLVMValueRef LLVMGetPreviousGlobal(LLVMValueRef GlobalVar);
1595 void LLVMDeleteGlobal(LLVMValueRef GlobalVar);
1596 LLVMValueRef LLVMGetInitializer(LLVMValueRef GlobalVar);
1597 void LLVMSetInitializer(LLVMValueRef GlobalVar, LLVMValueRef ConstantVal);
1598 LLVMBool LLVMIsThreadLocal(LLVMValueRef GlobalVar);
1599 void LLVMSetThreadLocal(LLVMValueRef GlobalVar, LLVMBool IsThreadLocal);
1600 LLVMBool LLVMIsGlobalConstant(LLVMValueRef GlobalVar);
1601 void LLVMSetGlobalConstant(LLVMValueRef GlobalVar, LLVMBool IsConstant);
1608 * @defgroup LLVMCoreValueConstantGlobalAlias Global Aliases
1610 * This group contains function that operate on global alias values.
1612 * @see llvm::GlobalAlias
1616 LLVMValueRef LLVMAddAlias(LLVMModuleRef M, LLVMTypeRef Ty, LLVMValueRef Aliasee,
1624 * @defgroup LLVMCCoreValueFunction Function values
1626 * Functions in this group operate on LLVMValueRef instances that
1627 * correspond to llvm::Function instances.
1629 * @see llvm::Function
1635 * Remove a function from its containing module and deletes it.
1637 * @see llvm::Function::eraseFromParent()
1639 void LLVMDeleteFunction(LLVMValueRef Fn);
1642 * Obtain the ID number from a function instance.
1644 * @see llvm::Function::getIntrinsicID()
1646 unsigned LLVMGetIntrinsicID(LLVMValueRef Fn);
1649 * Obtain the calling function of a function.
1651 * The returned value corresponds to the LLVMCallConv enumeration.
1653 * @see llvm::Function::getCallingConv()
1655 unsigned LLVMGetFunctionCallConv(LLVMValueRef Fn);
1658 * Set the calling convention of a function.
1660 * @see llvm::Function::setCallingConv()
1662 * @param Fn Function to operate on
1663 * @param CC LLVMCallConv to set calling convention to
1665 void LLVMSetFunctionCallConv(LLVMValueRef Fn, unsigned CC);
1668 * Obtain the name of the garbage collector to use during code
1671 * @see llvm::Function::getGC()
1673 const char *LLVMGetGC(LLVMValueRef Fn);
1676 * Define the garbage collector to use during code generation.
1678 * @see llvm::Function::setGC()
1680 void LLVMSetGC(LLVMValueRef Fn, const char *Name);
1683 * Add an attribute to a function.
1685 * @see llvm::Function::addAttribute()
1687 void LLVMAddFunctionAttr(LLVMValueRef Fn, LLVMAttribute PA);
1690 * Obtain an attribute from a function.
1692 * @see llvm::Function::getAttributes()
1694 LLVMAttribute LLVMGetFunctionAttr(LLVMValueRef Fn);
1697 * Remove an attribute from a function.
1699 void LLVMRemoveFunctionAttr(LLVMValueRef Fn, LLVMAttribute PA);
1702 * @defgroup LLVMCCoreValueFunctionParameters Function Parameters
1704 * Functions in this group relate to arguments/parameters on functions.
1706 * Functions in this group expect LLVMValueRef instances that correspond
1707 * to llvm::Function instances.
1713 * Obtain the number of parameters in a function.
1715 * @see llvm::Function::arg_size()
1717 unsigned LLVMCountParams(LLVMValueRef Fn);
1720 * Obtain the parameters in a function.
1722 * The takes a pointer to a pre-allocated array of LLVMValueRef that is
1723 * at least LLVMCountParams() long. This array will be filled with
1724 * LLVMValueRef instances which correspond to the parameters the
1725 * function receives. Each LLVMValueRef corresponds to a llvm::Argument
1728 * @see llvm::Function::arg_begin()
1730 void LLVMGetParams(LLVMValueRef Fn, LLVMValueRef *Params);
1733 * Obtain the parameter at the specified index.
1735 * Parameters are indexed from 0.
1737 * @see llvm::Function::arg_begin()
1739 LLVMValueRef LLVMGetParam(LLVMValueRef Fn, unsigned Index);
1742 * Obtain the function to which this argument belongs.
1744 * Unlike other functions in this group, this one takes a LLVMValueRef
1745 * that corresponds to a llvm::Attribute.
1747 * The returned LLVMValueRef is the llvm::Function to which this
1750 LLVMValueRef LLVMGetParamParent(LLVMValueRef Inst);
1753 * Obtain the first parameter to a function.
1755 * @see llvm::Function::arg_begin()
1757 LLVMValueRef LLVMGetFirstParam(LLVMValueRef Fn);
1760 * Obtain the last parameter to a function.
1762 * @see llvm::Function::arg_end()
1764 LLVMValueRef LLVMGetLastParam(LLVMValueRef Fn);
1767 * Obtain the next parameter to a function.
1769 * This takes a LLVMValueRef obtained from LLVMGetFirstParam() (which is
1770 * actually a wrapped iterator) and obtains the next parameter from the
1771 * underlying iterator.
1773 LLVMValueRef LLVMGetNextParam(LLVMValueRef Arg);
1776 * Obtain the previous parameter to a function.
1778 * This is the opposite of LLVMGetNextParam().
1780 LLVMValueRef LLVMGetPreviousParam(LLVMValueRef Arg);
1783 * Add an attribute to a function argument.
1785 * @see llvm::Argument::addAttr()
1787 void LLVMAddAttribute(LLVMValueRef Arg, LLVMAttribute PA);
1790 * Remove an attribute from a function argument.
1792 * @see llvm::Argument::removeAttr()
1794 void LLVMRemoveAttribute(LLVMValueRef Arg, LLVMAttribute PA);
1797 * Get an attribute from a function argument.
1799 LLVMAttribute LLVMGetAttribute(LLVMValueRef Arg);
1802 * Set the alignment for a function parameter.
1804 * @see llvm::Argument::addAttr()
1805 * @see llvm::Attribute::constructAlignmentFromInt()
1807 void LLVMSetParamAlignment(LLVMValueRef Arg, unsigned align);
1826 * @defgroup LLVMCCoreValueMetadata Metadata
1832 * Obtain a MDString value from a context.
1834 * The returned instance corresponds to the llvm::MDString class.
1836 * The instance is specified by string data of a specified length. The
1837 * string content is copied, so the backing memory can be freed after
1838 * this function returns.
1840 LLVMValueRef LLVMMDStringInContext(LLVMContextRef C, const char *Str,
1844 * Obtain a MDString value from the global context.
1846 LLVMValueRef LLVMMDString(const char *Str, unsigned SLen);
1849 * Obtain a MDNode value from a context.
1851 * The returned value corresponds to the llvm::MDNode class.
1853 LLVMValueRef LLVMMDNodeInContext(LLVMContextRef C, LLVMValueRef *Vals,
1857 * Obtain a MDNode value from the global context.
1859 LLVMValueRef LLVMMDNode(LLVMValueRef *Vals, unsigned Count);
1862 * Obtain the underlying string from a MDString value.
1864 * @param V Instance to obtain string from.
1865 * @param Len Memory address which will hold length of returned string.
1866 * @return String data in MDString.
1868 const char *LLVMGetMDString(LLVMValueRef V, unsigned* Len);
1875 * @defgroup LLVMCCoreValueBasicBlock Basic Block
1877 * A basic block represents a single entry single exit section of code.
1878 * Basic blocks contain a list of instructions which form the body of
1881 * Basic blocks belong to functions. They have the type of label.
1883 * Basic blocks are themselves values. However, the C API models them as
1884 * LLVMBasicBlockRef.
1886 * @see llvm::BasicBlock
1892 * Convert a basic block instance to a value type.
1894 LLVMValueRef LLVMBasicBlockAsValue(LLVMBasicBlockRef BB);
1897 * Determine whether a LLVMValueRef is itself a basic block.
1899 LLVMBool LLVMValueIsBasicBlock(LLVMValueRef Val);
1902 * Convert a LLVMValueRef to a LLVMBasicBlockRef instance.
1904 LLVMBasicBlockRef LLVMValueAsBasicBlock(LLVMValueRef Val);
1907 * Obtain the function to which a basic block belongs.
1909 * @see llvm::BasicBlock::getParent()
1911 LLVMValueRef LLVMGetBasicBlockParent(LLVMBasicBlockRef BB);
1914 * Obtain the terminator instruction for a basic block.
1916 * If the basic block does not have a terminator (it is not well-formed
1917 * if it doesn't), then NULL is returned.
1919 * The returned LLVMValueRef corresponds to a llvm::TerminatorInst.
1921 * @see llvm::BasicBlock::getTerminator()
1923 LLVMValueRef LLVMGetBasicBlockTerminator(LLVMBasicBlockRef BB);
1926 * Obtain the number of basic blocks in a function.
1928 * @param Fn Function value to operate on.
1930 unsigned LLVMCountBasicBlocks(LLVMValueRef Fn);
1933 * Obtain all of the basic blocks in a function.
1935 * This operates on a function value. The BasicBlocks parameter is a
1936 * pointer to a pre-allocated array of LLVMBasicBlockRef of at least
1937 * LLVMCountBasicBlocks() in length. This array is populated with
1938 * LLVMBasicBlockRef instances.
1940 void LLVMGetBasicBlocks(LLVMValueRef Fn, LLVMBasicBlockRef *BasicBlocks);
1943 * Obtain the first basic block in a function.
1945 * The returned basic block can be used as an iterator. You will likely
1946 * eventually call into LLVMGetNextBasicBlock() with it.
1948 * @see llvm::Function::begin()
1950 LLVMBasicBlockRef LLVMGetFirstBasicBlock(LLVMValueRef Fn);
1953 * Obtain the last basic block in a function.
1955 * @see llvm::Function::end()
1957 LLVMBasicBlockRef LLVMGetLastBasicBlock(LLVMValueRef Fn);
1960 * Advance a basic block iterator.
1962 LLVMBasicBlockRef LLVMGetNextBasicBlock(LLVMBasicBlockRef BB);
1965 * Go backwards in a basic block iterator.
1967 LLVMBasicBlockRef LLVMGetPreviousBasicBlock(LLVMBasicBlockRef BB);
1970 * Obtain the basic block that corresponds to the entry point of a
1973 * @see llvm::Function::getEntryBlock()
1975 LLVMBasicBlockRef LLVMGetEntryBasicBlock(LLVMValueRef Fn);
1978 * Append a basic block to the end of a function.
1980 * @see llvm::BasicBlock::Create()
1982 LLVMBasicBlockRef LLVMAppendBasicBlockInContext(LLVMContextRef C,
1987 * Append a basic block to the end of a function using the global
1990 * @see llvm::BasicBlock::Create()
1992 LLVMBasicBlockRef LLVMAppendBasicBlock(LLVMValueRef Fn, const char *Name);
1995 * Insert a basic block in a function before another basic block.
1997 * The function to add to is determined by the function of the
1998 * passed basic block.
2000 * @see llvm::BasicBlock::Create()
2002 LLVMBasicBlockRef LLVMInsertBasicBlockInContext(LLVMContextRef C,
2003 LLVMBasicBlockRef BB,
2007 * Insert a basic block in a function using the global context.
2009 * @see llvm::BasicBlock::Create()
2011 LLVMBasicBlockRef LLVMInsertBasicBlock(LLVMBasicBlockRef InsertBeforeBB,
2015 * Remove a basic block from a function and delete it.
2017 * This deletes the basic block from its containing function and deletes
2018 * the basic block itself.
2020 * @see llvm::BasicBlock::eraseFromParent()
2022 void LLVMDeleteBasicBlock(LLVMBasicBlockRef BB);
2025 * Remove a basic block from a function.
2027 * This deletes the basic block from its containing function but keep
2028 * the basic block alive.
2030 * @see llvm::BasicBlock::removeFromParent()
2032 void LLVMRemoveBasicBlockFromParent(LLVMBasicBlockRef BB);
2035 * Move a basic block to before another one.
2037 * @see llvm::BasicBlock::moveBefore()
2039 void LLVMMoveBasicBlockBefore(LLVMBasicBlockRef BB, LLVMBasicBlockRef MovePos);
2042 * Move a basic block to after another one.
2044 * @see llvm::BasicBlock::moveAfter()
2046 void LLVMMoveBasicBlockAfter(LLVMBasicBlockRef BB, LLVMBasicBlockRef MovePos);
2049 * Obtain the first instruction in a basic block.
2051 * The returned LLVMValueRef corresponds to a llvm::Instruction
2054 LLVMValueRef LLVMGetFirstInstruction(LLVMBasicBlockRef BB);
2057 * Obtain the last instruction in a basic block.
2059 * The returned LLVMValueRef corresponds to a LLVM:Instruction.
2061 LLVMValueRef LLVMGetLastInstruction(LLVMBasicBlockRef BB);
2068 * @defgroup LLVMCCoreValueInstruction Instructions
2070 * Functions in this group relate to the inspection and manipulation of
2071 * individual instructions.
2073 * In the C++ API, an instruction is modeled by llvm::Instruction. This
2074 * class has a large number of descendents. llvm::Instruction is a
2075 * llvm::Value and in the C API, instructions are modeled by
2078 * This group also contains sub-groups which operate on specific
2079 * llvm::Instruction types, e.g. llvm::CallInst.
2085 * Determine whether an instruction has any metadata attached.
2087 int LLVMHasMetadata(LLVMValueRef Val);
2090 * Return metadata associated with an instruction value.
2092 LLVMValueRef LLVMGetMetadata(LLVMValueRef Val, unsigned KindID);
2095 * Set metadata associated with an instruction value.
2097 void LLVMSetMetadata(LLVMValueRef Val, unsigned KindID, LLVMValueRef Node);
2100 * Obtain the basic block to which an instruction belongs.
2102 * @see llvm::Instruction::getParent()
2104 LLVMBasicBlockRef LLVMGetInstructionParent(LLVMValueRef Inst);
2107 * Obtain the instruction that occurs after the one specified.
2109 * The next instruction will be from the same basic block.
2111 * If this is the last instruction in a basic block, NULL will be
2114 LLVMValueRef LLVMGetNextInstruction(LLVMValueRef Inst);
2117 * Obtain the instruction that occurred before this one.
2119 * If the instruction is the first instruction in a basic block, NULL
2122 LLVMValueRef LLVMGetPreviousInstruction(LLVMValueRef Inst);
2125 * Remove and delete an instruction.
2127 * The instruction specified is removed from its containing building
2128 * block and then deleted.
2130 * @see llvm::Instruction::eraseFromParent()
2132 void LLVMInstructionEraseFromParent(LLVMValueRef Inst);
2135 * Obtain the code opcode for an individual instruction.
2137 * @see llvm::Instruction::getOpCode()
2139 LLVMOpcode LLVMGetInstructionOpcode(LLVMValueRef Inst);
2142 * Obtain the predicate of an instruction.
2144 * This is only valid for instructions that correspond to llvm::ICmpInst
2145 * or llvm::ConstantExpr whose opcode is llvm::Instruction::ICmp.
2147 * @see llvm::ICmpInst::getPredicate()
2149 LLVMIntPredicate LLVMGetICmpPredicate(LLVMValueRef Inst);
2152 * @defgroup LLVMCCoreValueInstructionCall Call Sites and Invocations
2154 * Functions in this group apply to instructions that refer to call
2155 * sites and invocations. These correspond to C++ types in the
2156 * llvm::CallInst class tree.
2162 * Set the calling convention for a call instruction.
2164 * This expects an LLVMValueRef that corresponds to a llvm::CallInst or
2167 * @see llvm::CallInst::setCallingConv()
2168 * @see llvm::InvokeInst::setCallingConv()
2170 void LLVMSetInstructionCallConv(LLVMValueRef Instr, unsigned CC);
2173 * Obtain the calling convention for a call instruction.
2175 * This is the opposite of LLVMSetInstructionCallConv(). Reads its
2178 * @see LLVMSetInstructionCallConv()
2180 unsigned LLVMGetInstructionCallConv(LLVMValueRef Instr);
2183 void LLVMAddInstrAttribute(LLVMValueRef Instr, unsigned index, LLVMAttribute);
2184 void LLVMRemoveInstrAttribute(LLVMValueRef Instr, unsigned index,
2186 void LLVMSetInstrParamAlignment(LLVMValueRef Instr, unsigned index,
2190 * Obtain whether a call instruction is a tail call.
2192 * This only works on llvm::CallInst instructions.
2194 * @see llvm::CallInst::isTailCall()
2196 LLVMBool LLVMIsTailCall(LLVMValueRef CallInst);
2199 * Set whether a call instruction is a tail call.
2201 * This only works on llvm::CallInst instructions.
2203 * @see llvm::CallInst::setTailCall()
2205 void LLVMSetTailCall(LLVMValueRef CallInst, LLVMBool IsTailCall);
2212 * Obtain the default destination basic block of a switch instruction.
2214 * This only works on llvm::SwitchInst instructions.
2216 * @see llvm::SwitchInst::getDefaultDest()
2218 LLVMBasicBlockRef LLVMGetSwitchDefaultDest(LLVMValueRef SwitchInstr);
2221 * @defgroup LLVMCCoreValueInstructionPHINode PHI Nodes
2223 * Functions in this group only apply to instructions that map to
2224 * llvm::PHINode instances.
2230 * Add an incoming value to the end of a PHI list.
2232 void LLVMAddIncoming(LLVMValueRef PhiNode, LLVMValueRef *IncomingValues,
2233 LLVMBasicBlockRef *IncomingBlocks, unsigned Count);
2236 * Obtain the number of incoming basic blocks to a PHI node.
2238 unsigned LLVMCountIncoming(LLVMValueRef PhiNode);
2241 * Obtain an incoming value to a PHI node as a LLVMValueRef.
2243 LLVMValueRef LLVMGetIncomingValue(LLVMValueRef PhiNode, unsigned Index);
2246 * Obtain an incoming value to a PHI node as a LLVMBasicBlockRef.
2248 LLVMBasicBlockRef LLVMGetIncomingBlock(LLVMValueRef PhiNode, unsigned Index);
2263 * @defgroup LLVMCCoreInstructionBuilder Instruction Builders
2265 * An instruction builder represents a point within a basic block and is
2266 * the exclusive means of building instructions using the C interface.
2271 LLVMBuilderRef LLVMCreateBuilderInContext(LLVMContextRef C);
2272 LLVMBuilderRef LLVMCreateBuilder(void);
2273 void LLVMPositionBuilder(LLVMBuilderRef Builder, LLVMBasicBlockRef Block,
2274 LLVMValueRef Instr);
2275 void LLVMPositionBuilderBefore(LLVMBuilderRef Builder, LLVMValueRef Instr);
2276 void LLVMPositionBuilderAtEnd(LLVMBuilderRef Builder, LLVMBasicBlockRef Block);
2277 LLVMBasicBlockRef LLVMGetInsertBlock(LLVMBuilderRef Builder);
2278 void LLVMClearInsertionPosition(LLVMBuilderRef Builder);
2279 void LLVMInsertIntoBuilder(LLVMBuilderRef Builder, LLVMValueRef Instr);
2280 void LLVMInsertIntoBuilderWithName(LLVMBuilderRef Builder, LLVMValueRef Instr,
2282 void LLVMDisposeBuilder(LLVMBuilderRef Builder);
2285 void LLVMSetCurrentDebugLocation(LLVMBuilderRef Builder, LLVMValueRef L);
2286 LLVMValueRef LLVMGetCurrentDebugLocation(LLVMBuilderRef Builder);
2287 void LLVMSetInstDebugLocation(LLVMBuilderRef Builder, LLVMValueRef Inst);
2290 LLVMValueRef LLVMBuildRetVoid(LLVMBuilderRef);
2291 LLVMValueRef LLVMBuildRet(LLVMBuilderRef, LLVMValueRef V);
2292 LLVMValueRef LLVMBuildAggregateRet(LLVMBuilderRef, LLVMValueRef *RetVals,
2294 LLVMValueRef LLVMBuildBr(LLVMBuilderRef, LLVMBasicBlockRef Dest);
2295 LLVMValueRef LLVMBuildCondBr(LLVMBuilderRef, LLVMValueRef If,
2296 LLVMBasicBlockRef Then, LLVMBasicBlockRef Else);
2297 LLVMValueRef LLVMBuildSwitch(LLVMBuilderRef, LLVMValueRef V,
2298 LLVMBasicBlockRef Else, unsigned NumCases);
2299 LLVMValueRef LLVMBuildIndirectBr(LLVMBuilderRef B, LLVMValueRef Addr,
2301 LLVMValueRef LLVMBuildInvoke(LLVMBuilderRef, LLVMValueRef Fn,
2302 LLVMValueRef *Args, unsigned NumArgs,
2303 LLVMBasicBlockRef Then, LLVMBasicBlockRef Catch,
2305 LLVMValueRef LLVMBuildLandingPad(LLVMBuilderRef B, LLVMTypeRef Ty,
2306 LLVMValueRef PersFn, unsigned NumClauses,
2308 LLVMValueRef LLVMBuildResume(LLVMBuilderRef B, LLVMValueRef Exn);
2309 LLVMValueRef LLVMBuildUnreachable(LLVMBuilderRef);
2311 /* Add a case to the switch instruction */
2312 void LLVMAddCase(LLVMValueRef Switch, LLVMValueRef OnVal,
2313 LLVMBasicBlockRef Dest);
2315 /* Add a destination to the indirectbr instruction */
2316 void LLVMAddDestination(LLVMValueRef IndirectBr, LLVMBasicBlockRef Dest);
2318 /* Add a catch or filter clause to the landingpad instruction */
2319 void LLVMAddClause(LLVMValueRef LandingPad, LLVMValueRef ClauseVal);
2321 /* Set the 'cleanup' flag in the landingpad instruction */
2322 void LLVMSetCleanup(LLVMValueRef LandingPad, LLVMBool Val);
2325 LLVMValueRef LLVMBuildAdd(LLVMBuilderRef, LLVMValueRef LHS, LLVMValueRef RHS,
2327 LLVMValueRef LLVMBuildNSWAdd(LLVMBuilderRef, LLVMValueRef LHS, LLVMValueRef RHS,
2329 LLVMValueRef LLVMBuildNUWAdd(LLVMBuilderRef, LLVMValueRef LHS, LLVMValueRef RHS,
2331 LLVMValueRef LLVMBuildFAdd(LLVMBuilderRef, LLVMValueRef LHS, LLVMValueRef RHS,
2333 LLVMValueRef LLVMBuildSub(LLVMBuilderRef, LLVMValueRef LHS, LLVMValueRef RHS,
2335 LLVMValueRef LLVMBuildNSWSub(LLVMBuilderRef, LLVMValueRef LHS, LLVMValueRef RHS,
2337 LLVMValueRef LLVMBuildNUWSub(LLVMBuilderRef, LLVMValueRef LHS, LLVMValueRef RHS,
2339 LLVMValueRef LLVMBuildFSub(LLVMBuilderRef, LLVMValueRef LHS, LLVMValueRef RHS,
2341 LLVMValueRef LLVMBuildMul(LLVMBuilderRef, LLVMValueRef LHS, LLVMValueRef RHS,
2343 LLVMValueRef LLVMBuildNSWMul(LLVMBuilderRef, LLVMValueRef LHS, LLVMValueRef RHS,
2345 LLVMValueRef LLVMBuildNUWMul(LLVMBuilderRef, LLVMValueRef LHS, LLVMValueRef RHS,
2347 LLVMValueRef LLVMBuildFMul(LLVMBuilderRef, LLVMValueRef LHS, LLVMValueRef RHS,
2349 LLVMValueRef LLVMBuildUDiv(LLVMBuilderRef, LLVMValueRef LHS, LLVMValueRef RHS,
2351 LLVMValueRef LLVMBuildSDiv(LLVMBuilderRef, LLVMValueRef LHS, LLVMValueRef RHS,
2353 LLVMValueRef LLVMBuildExactSDiv(LLVMBuilderRef, LLVMValueRef LHS, LLVMValueRef RHS,
2355 LLVMValueRef LLVMBuildFDiv(LLVMBuilderRef, LLVMValueRef LHS, LLVMValueRef RHS,
2357 LLVMValueRef LLVMBuildURem(LLVMBuilderRef, LLVMValueRef LHS, LLVMValueRef RHS,
2359 LLVMValueRef LLVMBuildSRem(LLVMBuilderRef, LLVMValueRef LHS, LLVMValueRef RHS,
2361 LLVMValueRef LLVMBuildFRem(LLVMBuilderRef, LLVMValueRef LHS, LLVMValueRef RHS,
2363 LLVMValueRef LLVMBuildShl(LLVMBuilderRef, LLVMValueRef LHS, LLVMValueRef RHS,
2365 LLVMValueRef LLVMBuildLShr(LLVMBuilderRef, LLVMValueRef LHS, LLVMValueRef RHS,
2367 LLVMValueRef LLVMBuildAShr(LLVMBuilderRef, LLVMValueRef LHS, LLVMValueRef RHS,
2369 LLVMValueRef LLVMBuildAnd(LLVMBuilderRef, LLVMValueRef LHS, LLVMValueRef RHS,
2371 LLVMValueRef LLVMBuildOr(LLVMBuilderRef, LLVMValueRef LHS, LLVMValueRef RHS,
2373 LLVMValueRef LLVMBuildXor(LLVMBuilderRef, LLVMValueRef LHS, LLVMValueRef RHS,
2375 LLVMValueRef LLVMBuildBinOp(LLVMBuilderRef B, LLVMOpcode Op,
2376 LLVMValueRef LHS, LLVMValueRef RHS,
2378 LLVMValueRef LLVMBuildNeg(LLVMBuilderRef, LLVMValueRef V, const char *Name);
2379 LLVMValueRef LLVMBuildNSWNeg(LLVMBuilderRef B, LLVMValueRef V,
2381 LLVMValueRef LLVMBuildNUWNeg(LLVMBuilderRef B, LLVMValueRef V,
2383 LLVMValueRef LLVMBuildFNeg(LLVMBuilderRef, LLVMValueRef V, const char *Name);
2384 LLVMValueRef LLVMBuildNot(LLVMBuilderRef, LLVMValueRef V, const char *Name);
2387 LLVMValueRef LLVMBuildMalloc(LLVMBuilderRef, LLVMTypeRef Ty, const char *Name);
2388 LLVMValueRef LLVMBuildArrayMalloc(LLVMBuilderRef, LLVMTypeRef Ty,
2389 LLVMValueRef Val, const char *Name);
2390 LLVMValueRef LLVMBuildAlloca(LLVMBuilderRef, LLVMTypeRef Ty, const char *Name);
2391 LLVMValueRef LLVMBuildArrayAlloca(LLVMBuilderRef, LLVMTypeRef Ty,
2392 LLVMValueRef Val, const char *Name);
2393 LLVMValueRef LLVMBuildFree(LLVMBuilderRef, LLVMValueRef PointerVal);
2394 LLVMValueRef LLVMBuildLoad(LLVMBuilderRef, LLVMValueRef PointerVal,
2396 LLVMValueRef LLVMBuildStore(LLVMBuilderRef, LLVMValueRef Val, LLVMValueRef Ptr);
2397 LLVMValueRef LLVMBuildGEP(LLVMBuilderRef B, LLVMValueRef Pointer,
2398 LLVMValueRef *Indices, unsigned NumIndices,
2400 LLVMValueRef LLVMBuildInBoundsGEP(LLVMBuilderRef B, LLVMValueRef Pointer,
2401 LLVMValueRef *Indices, unsigned NumIndices,
2403 LLVMValueRef LLVMBuildStructGEP(LLVMBuilderRef B, LLVMValueRef Pointer,
2404 unsigned Idx, const char *Name);
2405 LLVMValueRef LLVMBuildGlobalString(LLVMBuilderRef B, const char *Str,
2407 LLVMValueRef LLVMBuildGlobalStringPtr(LLVMBuilderRef B, const char *Str,
2409 LLVMBool LLVMGetVolatile(LLVMValueRef MemoryAccessInst);
2410 void LLVMSetVolatile(LLVMValueRef MemoryAccessInst, LLVMBool IsVolatile);
2413 LLVMValueRef LLVMBuildTrunc(LLVMBuilderRef, LLVMValueRef Val,
2414 LLVMTypeRef DestTy, const char *Name);
2415 LLVMValueRef LLVMBuildZExt(LLVMBuilderRef, LLVMValueRef Val,
2416 LLVMTypeRef DestTy, const char *Name);
2417 LLVMValueRef LLVMBuildSExt(LLVMBuilderRef, LLVMValueRef Val,
2418 LLVMTypeRef DestTy, const char *Name);
2419 LLVMValueRef LLVMBuildFPToUI(LLVMBuilderRef, LLVMValueRef Val,
2420 LLVMTypeRef DestTy, const char *Name);
2421 LLVMValueRef LLVMBuildFPToSI(LLVMBuilderRef, LLVMValueRef Val,
2422 LLVMTypeRef DestTy, const char *Name);
2423 LLVMValueRef LLVMBuildUIToFP(LLVMBuilderRef, LLVMValueRef Val,
2424 LLVMTypeRef DestTy, const char *Name);
2425 LLVMValueRef LLVMBuildSIToFP(LLVMBuilderRef, LLVMValueRef Val,
2426 LLVMTypeRef DestTy, const char *Name);
2427 LLVMValueRef LLVMBuildFPTrunc(LLVMBuilderRef, LLVMValueRef Val,
2428 LLVMTypeRef DestTy, const char *Name);
2429 LLVMValueRef LLVMBuildFPExt(LLVMBuilderRef, LLVMValueRef Val,
2430 LLVMTypeRef DestTy, const char *Name);
2431 LLVMValueRef LLVMBuildPtrToInt(LLVMBuilderRef, LLVMValueRef Val,
2432 LLVMTypeRef DestTy, const char *Name);
2433 LLVMValueRef LLVMBuildIntToPtr(LLVMBuilderRef, LLVMValueRef Val,
2434 LLVMTypeRef DestTy, const char *Name);
2435 LLVMValueRef LLVMBuildBitCast(LLVMBuilderRef, LLVMValueRef Val,
2436 LLVMTypeRef DestTy, const char *Name);
2437 LLVMValueRef LLVMBuildZExtOrBitCast(LLVMBuilderRef, LLVMValueRef Val,
2438 LLVMTypeRef DestTy, const char *Name);
2439 LLVMValueRef LLVMBuildSExtOrBitCast(LLVMBuilderRef, LLVMValueRef Val,
2440 LLVMTypeRef DestTy, const char *Name);
2441 LLVMValueRef LLVMBuildTruncOrBitCast(LLVMBuilderRef, LLVMValueRef Val,
2442 LLVMTypeRef DestTy, const char *Name);
2443 LLVMValueRef LLVMBuildCast(LLVMBuilderRef B, LLVMOpcode Op, LLVMValueRef Val,
2444 LLVMTypeRef DestTy, const char *Name);
2445 LLVMValueRef LLVMBuildPointerCast(LLVMBuilderRef, LLVMValueRef Val,
2446 LLVMTypeRef DestTy, const char *Name);
2447 LLVMValueRef LLVMBuildIntCast(LLVMBuilderRef, LLVMValueRef Val, /*Signed cast!*/
2448 LLVMTypeRef DestTy, const char *Name);
2449 LLVMValueRef LLVMBuildFPCast(LLVMBuilderRef, LLVMValueRef Val,
2450 LLVMTypeRef DestTy, const char *Name);
2453 LLVMValueRef LLVMBuildICmp(LLVMBuilderRef, LLVMIntPredicate Op,
2454 LLVMValueRef LHS, LLVMValueRef RHS,
2456 LLVMValueRef LLVMBuildFCmp(LLVMBuilderRef, LLVMRealPredicate Op,
2457 LLVMValueRef LHS, LLVMValueRef RHS,
2460 /* Miscellaneous instructions */
2461 LLVMValueRef LLVMBuildPhi(LLVMBuilderRef, LLVMTypeRef Ty, const char *Name);
2462 LLVMValueRef LLVMBuildCall(LLVMBuilderRef, LLVMValueRef Fn,
2463 LLVMValueRef *Args, unsigned NumArgs,
2465 LLVMValueRef LLVMBuildSelect(LLVMBuilderRef, LLVMValueRef If,
2466 LLVMValueRef Then, LLVMValueRef Else,
2468 LLVMValueRef LLVMBuildVAArg(LLVMBuilderRef, LLVMValueRef List, LLVMTypeRef Ty,
2470 LLVMValueRef LLVMBuildExtractElement(LLVMBuilderRef, LLVMValueRef VecVal,
2471 LLVMValueRef Index, const char *Name);
2472 LLVMValueRef LLVMBuildInsertElement(LLVMBuilderRef, LLVMValueRef VecVal,
2473 LLVMValueRef EltVal, LLVMValueRef Index,
2475 LLVMValueRef LLVMBuildShuffleVector(LLVMBuilderRef, LLVMValueRef V1,
2476 LLVMValueRef V2, LLVMValueRef Mask,
2478 LLVMValueRef LLVMBuildExtractValue(LLVMBuilderRef, LLVMValueRef AggVal,
2479 unsigned Index, const char *Name);
2480 LLVMValueRef LLVMBuildInsertValue(LLVMBuilderRef, LLVMValueRef AggVal,
2481 LLVMValueRef EltVal, unsigned Index,
2484 LLVMValueRef LLVMBuildIsNull(LLVMBuilderRef, LLVMValueRef Val,
2486 LLVMValueRef LLVMBuildIsNotNull(LLVMBuilderRef, LLVMValueRef Val,
2488 LLVMValueRef LLVMBuildPtrDiff(LLVMBuilderRef, LLVMValueRef LHS,
2489 LLVMValueRef RHS, const char *Name);
2496 * @defgroup LLVMCCoreModuleProvider Module Providers
2502 * Changes the type of M so it can be passed to FunctionPassManagers and the
2503 * JIT. They take ModuleProviders for historical reasons.
2505 LLVMModuleProviderRef
2506 LLVMCreateModuleProviderForExistingModule(LLVMModuleRef M);
2509 * Destroys the module M.
2511 void LLVMDisposeModuleProvider(LLVMModuleProviderRef M);
2518 * @defgroup LLVMCCoreMemoryBuffers Memory Buffers
2523 LLVMBool LLVMCreateMemoryBufferWithContentsOfFile(const char *Path,
2524 LLVMMemoryBufferRef *OutMemBuf,
2526 LLVMBool LLVMCreateMemoryBufferWithSTDIN(LLVMMemoryBufferRef *OutMemBuf,
2528 void LLVMDisposeMemoryBuffer(LLVMMemoryBufferRef MemBuf);
2535 * @defgroup LLVMCCorePassRegistry Pass Registry
2540 /** Return the global pass registry, for use with initialization functions.
2541 @see llvm::PassRegistry::getPassRegistry */
2542 LLVMPassRegistryRef LLVMGetGlobalPassRegistry(void);
2549 * @defgroup LLVMCCorePassManagers Pass Managers
2554 /** Constructs a new whole-module pass pipeline. This type of pipeline is
2555 suitable for link-time optimization and whole-module transformations.
2556 @see llvm::PassManager::PassManager */
2557 LLVMPassManagerRef LLVMCreatePassManager(void);
2559 /** Constructs a new function-by-function pass pipeline over the module
2560 provider. It does not take ownership of the module provider. This type of
2561 pipeline is suitable for code generation and JIT compilation tasks.
2562 @see llvm::FunctionPassManager::FunctionPassManager */
2563 LLVMPassManagerRef LLVMCreateFunctionPassManagerForModule(LLVMModuleRef M);
2565 /** Deprecated: Use LLVMCreateFunctionPassManagerForModule instead. */
2566 LLVMPassManagerRef LLVMCreateFunctionPassManager(LLVMModuleProviderRef MP);
2568 /** Initializes, executes on the provided module, and finalizes all of the
2569 passes scheduled in the pass manager. Returns 1 if any of the passes
2570 modified the module, 0 otherwise.
2571 @see llvm::PassManager::run(Module&) */
2572 LLVMBool LLVMRunPassManager(LLVMPassManagerRef PM, LLVMModuleRef M);
2574 /** Initializes all of the function passes scheduled in the function pass
2575 manager. Returns 1 if any of the passes modified the module, 0 otherwise.
2576 @see llvm::FunctionPassManager::doInitialization */
2577 LLVMBool LLVMInitializeFunctionPassManager(LLVMPassManagerRef FPM);
2579 /** Executes all of the function passes scheduled in the function pass manager
2580 on the provided function. Returns 1 if any of the passes modified the
2581 function, false otherwise.
2582 @see llvm::FunctionPassManager::run(Function&) */
2583 LLVMBool LLVMRunFunctionPassManager(LLVMPassManagerRef FPM, LLVMValueRef F);
2585 /** Finalizes all of the function passes scheduled in in the function pass
2586 manager. Returns 1 if any of the passes modified the module, 0 otherwise.
2587 @see llvm::FunctionPassManager::doFinalization */
2588 LLVMBool LLVMFinalizeFunctionPassManager(LLVMPassManagerRef FPM);
2590 /** Frees the memory of a pass pipeline. For function pipelines, does not free
2591 the module provider.
2592 @see llvm::PassManagerBase::~PassManagerBase. */
2593 void LLVMDisposePassManager(LLVMPassManagerRef PM);
2612 class PassManagerBase;
2614 #define DEFINE_SIMPLE_CONVERSION_FUNCTIONS(ty, ref) \
2615 inline ty *unwrap(ref P) { \
2616 return reinterpret_cast<ty*>(P); \
2619 inline ref wrap(const ty *P) { \
2620 return reinterpret_cast<ref>(const_cast<ty*>(P)); \
2623 #define DEFINE_ISA_CONVERSION_FUNCTIONS(ty, ref) \
2624 DEFINE_SIMPLE_CONVERSION_FUNCTIONS(ty, ref) \
2626 template<typename T> \
2627 inline T *unwrap(ref P) { \
2628 return cast<T>(unwrap(P)); \
2631 #define DEFINE_STDCXX_CONVERSION_FUNCTIONS(ty, ref) \
2632 DEFINE_SIMPLE_CONVERSION_FUNCTIONS(ty, ref) \
2634 template<typename T> \
2635 inline T *unwrap(ref P) { \
2636 T *Q = (T*)unwrap(P); \
2637 assert(Q && "Invalid cast!"); \
2641 DEFINE_ISA_CONVERSION_FUNCTIONS (Type, LLVMTypeRef )
2642 DEFINE_ISA_CONVERSION_FUNCTIONS (Value, LLVMValueRef )
2643 DEFINE_SIMPLE_CONVERSION_FUNCTIONS(Module, LLVMModuleRef )
2644 DEFINE_SIMPLE_CONVERSION_FUNCTIONS(BasicBlock, LLVMBasicBlockRef )
2645 DEFINE_SIMPLE_CONVERSION_FUNCTIONS(IRBuilder<>, LLVMBuilderRef )
2646 DEFINE_SIMPLE_CONVERSION_FUNCTIONS(MemoryBuffer, LLVMMemoryBufferRef )
2647 DEFINE_SIMPLE_CONVERSION_FUNCTIONS(LLVMContext, LLVMContextRef )
2648 DEFINE_SIMPLE_CONVERSION_FUNCTIONS(Use, LLVMUseRef )
2649 DEFINE_STDCXX_CONVERSION_FUNCTIONS(PassManagerBase, LLVMPassManagerRef )
2650 DEFINE_STDCXX_CONVERSION_FUNCTIONS(PassRegistry, LLVMPassRegistryRef )
2651 /* LLVMModuleProviderRef exists for historical reasons, but now just holds a
2654 inline Module *unwrap(LLVMModuleProviderRef MP) {
2655 return reinterpret_cast<Module*>(MP);
2658 #undef DEFINE_STDCXX_CONVERSION_FUNCTIONS
2659 #undef DEFINE_ISA_CONVERSION_FUNCTIONS
2660 #undef DEFINE_SIMPLE_CONVERSION_FUNCTIONS
2662 /* Specialized opaque context conversions.
2664 inline LLVMContext **unwrap(LLVMContextRef* Tys) {
2665 return reinterpret_cast<LLVMContext**>(Tys);
2668 inline LLVMContextRef *wrap(const LLVMContext **Tys) {
2669 return reinterpret_cast<LLVMContextRef*>(const_cast<LLVMContext**>(Tys));
2672 /* Specialized opaque type conversions.
2674 inline Type **unwrap(LLVMTypeRef* Tys) {
2675 return reinterpret_cast<Type**>(Tys);
2678 inline LLVMTypeRef *wrap(Type **Tys) {
2679 return reinterpret_cast<LLVMTypeRef*>(const_cast<Type**>(Tys));
2682 /* Specialized opaque value conversions.
2684 inline Value **unwrap(LLVMValueRef *Vals) {
2685 return reinterpret_cast<Value**>(Vals);
2688 template<typename T>
2689 inline T **unwrap(LLVMValueRef *Vals, unsigned Length) {
2691 for (LLVMValueRef *I = Vals, *E = Vals + Length; I != E; ++I)
2695 return reinterpret_cast<T**>(Vals);
2698 inline LLVMValueRef *wrap(const Value **Vals) {
2699 return reinterpret_cast<LLVMValueRef*>(const_cast<Value**>(Vals));
2703 #endif /* !defined(__cplusplus) */
2705 #endif /* !defined(LLVM_C_CORE_H) */