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
184 /* Terminator Instructions */
190 /* removed 6 due to API changes */
193 /* Standard Binary Operators */
207 /* Logical Operators */
215 /* Memory Operators */
219 LLVMGetElementPtr = 29,
235 /* Other Operators */
244 LLVMExtractElement = 50,
245 LLVMInsertElement = 51,
246 LLVMShuffleVector = 52,
247 LLVMExtractValue = 53,
248 LLVMInsertValue = 54,
250 /* Atomic operators */
252 LLVMAtomicCmpXchg = 56,
255 /* Exception Handling Operators */
262 LLVMVoidTypeKind, /**< type with no size */
263 LLVMHalfTypeKind, /**< 16 bit floating point type */
264 LLVMFloatTypeKind, /**< 32 bit floating point type */
265 LLVMDoubleTypeKind, /**< 64 bit floating point type */
266 LLVMX86_FP80TypeKind, /**< 80 bit floating point type (X87) */
267 LLVMFP128TypeKind, /**< 128 bit floating point type (112-bit mantissa)*/
268 LLVMPPC_FP128TypeKind, /**< 128 bit floating point type (two 64-bits) */
269 LLVMLabelTypeKind, /**< Labels */
270 LLVMIntegerTypeKind, /**< Arbitrary bit width integers */
271 LLVMFunctionTypeKind, /**< Functions */
272 LLVMStructTypeKind, /**< Structures */
273 LLVMArrayTypeKind, /**< Arrays */
274 LLVMPointerTypeKind, /**< Pointers */
275 LLVMVectorTypeKind, /**< SIMD 'packed' format, or other vector type */
276 LLVMMetadataTypeKind, /**< Metadata */
277 LLVMX86_MMXTypeKind /**< X86 MMX */
281 LLVMExternalLinkage, /**< Externally visible function */
282 LLVMAvailableExternallyLinkage,
283 LLVMLinkOnceAnyLinkage, /**< Keep one copy of function when linking (inline)*/
284 LLVMLinkOnceODRLinkage, /**< Same, but only replaced by something
286 LLVMLinkOnceODRAutoHideLinkage, /**< Like LinkOnceODR, but possibly hidden. */
287 LLVMWeakAnyLinkage, /**< Keep one copy of function when linking (weak) */
288 LLVMWeakODRLinkage, /**< Same, but only replaced by something
290 LLVMAppendingLinkage, /**< Special purpose, only applies to global arrays */
291 LLVMInternalLinkage, /**< Rename collisions when linking (static
293 LLVMPrivateLinkage, /**< Like Internal, but omit from symbol table */
294 LLVMDLLImportLinkage, /**< Function to be imported from DLL */
295 LLVMDLLExportLinkage, /**< Function to be accessible from DLL */
296 LLVMExternalWeakLinkage,/**< ExternalWeak linkage description */
297 LLVMGhostLinkage, /**< Obsolete */
298 LLVMCommonLinkage, /**< Tentative definitions */
299 LLVMLinkerPrivateLinkage, /**< Like Private, but linker removes. */
300 LLVMLinkerPrivateWeakLinkage /**< Like LinkerPrivate, but is weak. */
304 LLVMDefaultVisibility, /**< The GV is visible */
305 LLVMHiddenVisibility, /**< The GV is hidden */
306 LLVMProtectedVisibility /**< The GV is protected */
311 LLVMFastCallConv = 8,
312 LLVMColdCallConv = 9,
313 LLVMX86StdcallCallConv = 64,
314 LLVMX86FastcallCallConv = 65
318 LLVMIntEQ = 32, /**< equal */
319 LLVMIntNE, /**< not equal */
320 LLVMIntUGT, /**< unsigned greater than */
321 LLVMIntUGE, /**< unsigned greater or equal */
322 LLVMIntULT, /**< unsigned less than */
323 LLVMIntULE, /**< unsigned less or equal */
324 LLVMIntSGT, /**< signed greater than */
325 LLVMIntSGE, /**< signed greater or equal */
326 LLVMIntSLT, /**< signed less than */
327 LLVMIntSLE /**< signed less or equal */
331 LLVMRealPredicateFalse, /**< Always false (always folded) */
332 LLVMRealOEQ, /**< True if ordered and equal */
333 LLVMRealOGT, /**< True if ordered and greater than */
334 LLVMRealOGE, /**< True if ordered and greater than or equal */
335 LLVMRealOLT, /**< True if ordered and less than */
336 LLVMRealOLE, /**< True if ordered and less than or equal */
337 LLVMRealONE, /**< True if ordered and operands are unequal */
338 LLVMRealORD, /**< True if ordered (no nans) */
339 LLVMRealUNO, /**< True if unordered: isnan(X) | isnan(Y) */
340 LLVMRealUEQ, /**< True if unordered or equal */
341 LLVMRealUGT, /**< True if unordered or greater than */
342 LLVMRealUGE, /**< True if unordered, greater than, or equal */
343 LLVMRealULT, /**< True if unordered or less than */
344 LLVMRealULE, /**< True if unordered, less than, or equal */
345 LLVMRealUNE, /**< True if unordered or not equal */
346 LLVMRealPredicateTrue /**< Always true (always folded) */
350 LLVMLandingPadCatch, /**< A catch clause */
351 LLVMLandingPadFilter /**< A filter clause */
352 } LLVMLandingPadClauseTy;
358 void LLVMInitializeCore(LLVMPassRegistryRef R);
361 /*===-- Error handling ----------------------------------------------------===*/
363 void LLVMDisposeMessage(char *Message);
367 * @defgroup LLVMCCoreContext Contexts
369 * Contexts are execution states for the core LLVM IR system.
371 * Most types are tied to a context instance. Multiple contexts can
372 * exist simultaneously. A single context is not thread safe. However,
373 * different contexts can execute on different threads simultaneously.
379 * Create a new context.
381 * Every call to this function should be paired with a call to
382 * LLVMContextDispose() or the context will leak memory.
384 LLVMContextRef LLVMContextCreate(void);
387 * Obtain the global context instance.
389 LLVMContextRef LLVMGetGlobalContext(void);
392 * Destroy a context instance.
394 * This should be called for every call to LLVMContextCreate() or memory
397 void LLVMContextDispose(LLVMContextRef C);
399 unsigned LLVMGetMDKindIDInContext(LLVMContextRef C, const char* Name,
401 unsigned LLVMGetMDKindID(const char* Name, unsigned SLen);
408 * @defgroup LLVMCCoreModule Modules
410 * Modules represent the top-level structure in a LLVM program. An LLVM
411 * module is effectively a translation unit or a collection of
412 * translation units merged together.
418 * Create a new, empty module in the global context.
420 * This is equivalent to calling LLVMModuleCreateWithNameInContext with
421 * LLVMGetGlobalContext() as the context parameter.
423 * Every invocation should be paired with LLVMDisposeModule() or memory
426 LLVMModuleRef LLVMModuleCreateWithName(const char *ModuleID);
429 * Create a new, empty module in a specific context.
431 * Every invocation should be paired with LLVMDisposeModule() or memory
434 LLVMModuleRef LLVMModuleCreateWithNameInContext(const char *ModuleID,
438 * Destroy a module instance.
440 * This must be called for every created module or memory will be
443 void LLVMDisposeModule(LLVMModuleRef M);
446 * Obtain the data layout for a module.
448 * @see Module::getDataLayout()
450 const char *LLVMGetDataLayout(LLVMModuleRef M);
453 * Set the data layout for a module.
455 * @see Module::setDataLayout()
457 void LLVMSetDataLayout(LLVMModuleRef M, const char *Triple);
460 * Obtain the target triple for a module.
462 * @see Module::getTargetTriple()
464 const char *LLVMGetTarget(LLVMModuleRef M);
467 * Set the target triple for a module.
469 * @see Module::setTargetTriple()
471 void LLVMSetTarget(LLVMModuleRef M, const char *Triple);
474 * Dump a representation of a module to stderr.
476 * @see Module::dump()
478 void LLVMDumpModule(LLVMModuleRef M);
481 * Print a representation of a module to a file. The ErrorMessage needs to be
482 * disposed with LLVMDisposeMessage. Returns 0 on success, 1 otherwise.
484 * @see Module::print()
486 LLVMBool LLVMPrintModuleToFile(LLVMModuleRef M, const char *Filename,
487 char **ErrorMessage);
490 * Set inline assembly for a module.
492 * @see Module::setModuleInlineAsm()
494 void LLVMSetModuleInlineAsm(LLVMModuleRef M, const char *Asm);
497 * Obtain the context to which this module is associated.
499 * @see Module::getContext()
501 LLVMContextRef LLVMGetModuleContext(LLVMModuleRef M);
504 * Obtain a Type from a module by its registered name.
506 LLVMTypeRef LLVMGetTypeByName(LLVMModuleRef M, const char *Name);
509 * Obtain the number of operands for named metadata in a module.
511 * @see llvm::Module::getNamedMetadata()
513 unsigned LLVMGetNamedMetadataNumOperands(LLVMModuleRef M, const char* name);
516 * Obtain the named metadata operands for a module.
518 * The passed LLVMValueRef pointer should refer to an array of
519 * LLVMValueRef at least LLVMGetNamedMetadataNumOperands long. This
520 * array will be populated with the LLVMValueRef instances. Each
521 * instance corresponds to a llvm::MDNode.
523 * @see llvm::Module::getNamedMetadata()
524 * @see llvm::MDNode::getOperand()
526 void LLVMGetNamedMetadataOperands(LLVMModuleRef M, const char* name, LLVMValueRef *Dest);
529 * Add an operand to named metadata.
531 * @see llvm::Module::getNamedMetadata()
532 * @see llvm::MDNode::addOperand()
534 void LLVMAddNamedMetadataOperand(LLVMModuleRef M, const char* name,
538 * Add a function to a module under a specified name.
540 * @see llvm::Function::Create()
542 LLVMValueRef LLVMAddFunction(LLVMModuleRef M, const char *Name,
543 LLVMTypeRef FunctionTy);
546 * Obtain a Function value from a Module by its name.
548 * The returned value corresponds to a llvm::Function value.
550 * @see llvm::Module::getFunction()
552 LLVMValueRef LLVMGetNamedFunction(LLVMModuleRef M, const char *Name);
555 * Obtain an iterator to the first Function in a Module.
557 * @see llvm::Module::begin()
559 LLVMValueRef LLVMGetFirstFunction(LLVMModuleRef M);
562 * Obtain an iterator to the last Function in a Module.
564 * @see llvm::Module::end()
566 LLVMValueRef LLVMGetLastFunction(LLVMModuleRef M);
569 * Advance a Function iterator to the next Function.
571 * Returns NULL if the iterator was already at the end and there are no more
574 LLVMValueRef LLVMGetNextFunction(LLVMValueRef Fn);
577 * Decrement a Function iterator to the previous Function.
579 * Returns NULL if the iterator was already at the beginning and there are
580 * no previous functions.
582 LLVMValueRef LLVMGetPreviousFunction(LLVMValueRef Fn);
589 * @defgroup LLVMCCoreType Types
591 * Types represent the type of a value.
593 * Types are associated with a context instance. The context internally
594 * deduplicates types so there is only 1 instance of a specific type
595 * alive at a time. In other words, a unique type is shared among all
596 * consumers within a context.
598 * A Type in the C API corresponds to llvm::Type.
600 * Types have the following hierarchy:
618 * Obtain the enumerated type of a Type instance.
620 * @see llvm::Type:getTypeID()
622 LLVMTypeKind LLVMGetTypeKind(LLVMTypeRef Ty);
625 * Whether the type has a known size.
627 * Things that don't have a size are abstract types, labels, and void.a
629 * @see llvm::Type::isSized()
631 LLVMBool LLVMTypeIsSized(LLVMTypeRef Ty);
634 * Obtain the context to which this type instance is associated.
636 * @see llvm::Type::getContext()
638 LLVMContextRef LLVMGetTypeContext(LLVMTypeRef Ty);
641 * @defgroup LLVMCCoreTypeInt Integer Types
643 * Functions in this section operate on integer types.
649 * Obtain an integer type from a context with specified bit width.
651 LLVMTypeRef LLVMInt1TypeInContext(LLVMContextRef C);
652 LLVMTypeRef LLVMInt8TypeInContext(LLVMContextRef C);
653 LLVMTypeRef LLVMInt16TypeInContext(LLVMContextRef C);
654 LLVMTypeRef LLVMInt32TypeInContext(LLVMContextRef C);
655 LLVMTypeRef LLVMInt64TypeInContext(LLVMContextRef C);
656 LLVMTypeRef LLVMIntTypeInContext(LLVMContextRef C, unsigned NumBits);
659 * Obtain an integer type from the global context with a specified bit
662 LLVMTypeRef LLVMInt1Type(void);
663 LLVMTypeRef LLVMInt8Type(void);
664 LLVMTypeRef LLVMInt16Type(void);
665 LLVMTypeRef LLVMInt32Type(void);
666 LLVMTypeRef LLVMInt64Type(void);
667 LLVMTypeRef LLVMIntType(unsigned NumBits);
668 unsigned LLVMGetIntTypeWidth(LLVMTypeRef IntegerTy);
675 * @defgroup LLVMCCoreTypeFloat Floating Point Types
681 * Obtain a 16-bit floating point type from a context.
683 LLVMTypeRef LLVMHalfTypeInContext(LLVMContextRef C);
686 * Obtain a 32-bit floating point type from a context.
688 LLVMTypeRef LLVMFloatTypeInContext(LLVMContextRef C);
691 * Obtain a 64-bit floating point type from a context.
693 LLVMTypeRef LLVMDoubleTypeInContext(LLVMContextRef C);
696 * Obtain a 80-bit floating point type (X87) from a context.
698 LLVMTypeRef LLVMX86FP80TypeInContext(LLVMContextRef C);
701 * Obtain a 128-bit floating point type (112-bit mantissa) from a
704 LLVMTypeRef LLVMFP128TypeInContext(LLVMContextRef C);
707 * Obtain a 128-bit floating point type (two 64-bits) from a context.
709 LLVMTypeRef LLVMPPCFP128TypeInContext(LLVMContextRef C);
712 * Obtain a floating point type from the global context.
714 * These map to the functions in this group of the same name.
716 LLVMTypeRef LLVMHalfType(void);
717 LLVMTypeRef LLVMFloatType(void);
718 LLVMTypeRef LLVMDoubleType(void);
719 LLVMTypeRef LLVMX86FP80Type(void);
720 LLVMTypeRef LLVMFP128Type(void);
721 LLVMTypeRef LLVMPPCFP128Type(void);
728 * @defgroup LLVMCCoreTypeFunction Function Types
734 * Obtain a function type consisting of a specified signature.
736 * The function is defined as a tuple of a return Type, a list of
737 * parameter types, and whether the function is variadic.
739 LLVMTypeRef LLVMFunctionType(LLVMTypeRef ReturnType,
740 LLVMTypeRef *ParamTypes, unsigned ParamCount,
744 * Returns whether a function type is variadic.
746 LLVMBool LLVMIsFunctionVarArg(LLVMTypeRef FunctionTy);
749 * Obtain the Type this function Type returns.
751 LLVMTypeRef LLVMGetReturnType(LLVMTypeRef FunctionTy);
754 * Obtain the number of parameters this function accepts.
756 unsigned LLVMCountParamTypes(LLVMTypeRef FunctionTy);
759 * Obtain the types of a function's parameters.
761 * The Dest parameter should point to a pre-allocated array of
762 * LLVMTypeRef at least LLVMCountParamTypes() large. On return, the
763 * first LLVMCountParamTypes() entries in the array will be populated
764 * with LLVMTypeRef instances.
766 * @param FunctionTy The function type to operate on.
767 * @param Dest Memory address of an array to be filled with result.
769 void LLVMGetParamTypes(LLVMTypeRef FunctionTy, LLVMTypeRef *Dest);
776 * @defgroup LLVMCCoreTypeStruct Structure Types
778 * These functions relate to LLVMTypeRef instances.
780 * @see llvm::StructType
786 * Create a new structure type in a context.
788 * A structure is specified by a list of inner elements/types and
789 * whether these can be packed together.
791 * @see llvm::StructType::create()
793 LLVMTypeRef LLVMStructTypeInContext(LLVMContextRef C, LLVMTypeRef *ElementTypes,
794 unsigned ElementCount, LLVMBool Packed);
797 * Create a new structure type in the global context.
799 * @see llvm::StructType::create()
801 LLVMTypeRef LLVMStructType(LLVMTypeRef *ElementTypes, unsigned ElementCount,
805 * Create an empty structure in a context having a specified name.
807 * @see llvm::StructType::create()
809 LLVMTypeRef LLVMStructCreateNamed(LLVMContextRef C, const char *Name);
812 * Obtain the name of a structure.
814 * @see llvm::StructType::getName()
816 const char *LLVMGetStructName(LLVMTypeRef Ty);
819 * Set the contents of a structure type.
821 * @see llvm::StructType::setBody()
823 void LLVMStructSetBody(LLVMTypeRef StructTy, LLVMTypeRef *ElementTypes,
824 unsigned ElementCount, LLVMBool Packed);
827 * Get the number of elements defined inside the structure.
829 * @see llvm::StructType::getNumElements()
831 unsigned LLVMCountStructElementTypes(LLVMTypeRef StructTy);
834 * Get the elements within a structure.
836 * The function is passed the address of a pre-allocated array of
837 * LLVMTypeRef at least LLVMCountStructElementTypes() long. After
838 * invocation, this array will be populated with the structure's
839 * elements. The objects in the destination array will have a lifetime
840 * of the structure type itself, which is the lifetime of the context it
843 void LLVMGetStructElementTypes(LLVMTypeRef StructTy, LLVMTypeRef *Dest);
846 * Determine whether a structure is packed.
848 * @see llvm::StructType::isPacked()
850 LLVMBool LLVMIsPackedStruct(LLVMTypeRef StructTy);
853 * Determine whether a structure is opaque.
855 * @see llvm::StructType::isOpaque()
857 LLVMBool LLVMIsOpaqueStruct(LLVMTypeRef StructTy);
865 * @defgroup LLVMCCoreTypeSequential Sequential Types
867 * Sequential types represents "arrays" of types. This is a super class
868 * for array, vector, and pointer types.
874 * Obtain the type of elements within a sequential type.
876 * This works on array, vector, and pointer types.
878 * @see llvm::SequentialType::getElementType()
880 LLVMTypeRef LLVMGetElementType(LLVMTypeRef Ty);
883 * Create a fixed size array type that refers to a specific type.
885 * The created type will exist in the context that its element type
888 * @see llvm::ArrayType::get()
890 LLVMTypeRef LLVMArrayType(LLVMTypeRef ElementType, unsigned ElementCount);
893 * Obtain the length of an array type.
895 * This only works on types that represent arrays.
897 * @see llvm::ArrayType::getNumElements()
899 unsigned LLVMGetArrayLength(LLVMTypeRef ArrayTy);
902 * Create a pointer type that points to a defined type.
904 * The created type will exist in the context that its pointee type
907 * @see llvm::PointerType::get()
909 LLVMTypeRef LLVMPointerType(LLVMTypeRef ElementType, unsigned AddressSpace);
912 * Obtain the address space of a pointer type.
914 * This only works on types that represent pointers.
916 * @see llvm::PointerType::getAddressSpace()
918 unsigned LLVMGetPointerAddressSpace(LLVMTypeRef PointerTy);
921 * Create a vector type that contains a defined type and has a specific
922 * number of elements.
924 * The created type will exist in the context thats its element type
927 * @see llvm::VectorType::get()
929 LLVMTypeRef LLVMVectorType(LLVMTypeRef ElementType, unsigned ElementCount);
932 * Obtain the number of elements in a vector type.
934 * This only works on types that represent vectors.
936 * @see llvm::VectorType::getNumElements()
938 unsigned LLVMGetVectorSize(LLVMTypeRef VectorTy);
945 * @defgroup LLVMCCoreTypeOther Other Types
951 * Create a void type in a context.
953 LLVMTypeRef LLVMVoidTypeInContext(LLVMContextRef C);
956 * Create a label type in a context.
958 LLVMTypeRef LLVMLabelTypeInContext(LLVMContextRef C);
961 * Create a X86 MMX type in a context.
963 LLVMTypeRef LLVMX86MMXTypeInContext(LLVMContextRef C);
966 * These are similar to the above functions except they operate on the
969 LLVMTypeRef LLVMVoidType(void);
970 LLVMTypeRef LLVMLabelType(void);
971 LLVMTypeRef LLVMX86MMXType(void);
982 * @defgroup LLVMCCoreValues Values
984 * The bulk of LLVM's object model consists of values, which comprise a very
985 * rich type hierarchy.
987 * LLVMValueRef essentially represents llvm::Value. There is a rich
988 * hierarchy of classes within this type. Depending on the instance
989 * obtained, not all APIs are available.
991 * Callers can determine the type of a LLVMValueRef by calling the
992 * LLVMIsA* family of functions (e.g. LLVMIsAArgument()). These
993 * functions are defined by a macro, so it isn't obvious which are
994 * available by looking at the Doxygen source code. Instead, look at the
995 * source definition of LLVM_FOR_EACH_VALUE_SUBCLASS and note the list
996 * of value names given. These value names also correspond to classes in
997 * the llvm::Value hierarchy.
1002 #define LLVM_FOR_EACH_VALUE_SUBCLASS(macro) \
1010 macro(BlockAddress) \
1011 macro(ConstantAggregateZero) \
1012 macro(ConstantArray) \
1013 macro(ConstantExpr) \
1015 macro(ConstantInt) \
1016 macro(ConstantPointerNull) \
1017 macro(ConstantStruct) \
1018 macro(ConstantVector) \
1019 macro(GlobalValue) \
1021 macro(GlobalAlias) \
1022 macro(GlobalVariable) \
1024 macro(Instruction) \
1025 macro(BinaryOperator) \
1027 macro(IntrinsicInst) \
1028 macro(DbgInfoIntrinsic) \
1029 macro(DbgDeclareInst) \
1030 macro(MemIntrinsic) \
1032 macro(MemMoveInst) \
1037 macro(ExtractElementInst) \
1038 macro(GetElementPtrInst) \
1039 macro(InsertElementInst) \
1040 macro(InsertValueInst) \
1041 macro(LandingPadInst) \
1044 macro(ShuffleVectorInst) \
1046 macro(TerminatorInst) \
1048 macro(IndirectBrInst) \
1052 macro(UnreachableInst) \
1054 macro(UnaryInstruction) \
1057 macro(BitCastInst) \
1061 macro(FPTruncInst) \
1062 macro(IntToPtrInst) \
1063 macro(PtrToIntInst) \
1069 macro(ExtractValueInst) \
1074 * @defgroup LLVMCCoreValueGeneral General APIs
1076 * Functions in this section work on all LLVMValueRef instances,
1077 * regardless of their sub-type. They correspond to functions available
1084 * Obtain the type of a value.
1086 * @see llvm::Value::getType()
1088 LLVMTypeRef LLVMTypeOf(LLVMValueRef Val);
1091 * Obtain the string name of a value.
1093 * @see llvm::Value::getName()
1095 const char *LLVMGetValueName(LLVMValueRef Val);
1098 * Set the string name of a value.
1100 * @see llvm::Value::setName()
1102 void LLVMSetValueName(LLVMValueRef Val, const char *Name);
1105 * Dump a representation of a value to stderr.
1107 * @see llvm::Value::dump()
1109 void LLVMDumpValue(LLVMValueRef Val);
1112 * Replace all uses of a value with another one.
1114 * @see llvm::Value::replaceAllUsesWith()
1116 void LLVMReplaceAllUsesWith(LLVMValueRef OldVal, LLVMValueRef NewVal);
1119 * Determine whether the specified constant instance is constant.
1121 LLVMBool LLVMIsConstant(LLVMValueRef Val);
1124 * Determine whether a value instance is undefined.
1126 LLVMBool LLVMIsUndef(LLVMValueRef Val);
1129 * Convert value instances between types.
1131 * Internally, a LLVMValueRef is "pinned" to a specific type. This
1132 * series of functions allows you to cast an instance to a specific
1135 * If the cast is not valid for the specified type, NULL is returned.
1137 * @see llvm::dyn_cast_or_null<>
1139 #define LLVM_DECLARE_VALUE_CAST(name) \
1140 LLVMValueRef LLVMIsA##name(LLVMValueRef Val);
1141 LLVM_FOR_EACH_VALUE_SUBCLASS(LLVM_DECLARE_VALUE_CAST)
1148 * @defgroup LLVMCCoreValueUses Usage
1150 * This module defines functions that allow you to inspect the uses of a
1153 * It is possible to obtain a LLVMUseRef for any LLVMValueRef instance.
1154 * Each LLVMUseRef (which corresponds to a llvm::Use instance) holds a
1155 * llvm::User and llvm::Value.
1161 * Obtain the first use of a value.
1163 * Uses are obtained in an iterator fashion. First, call this function
1164 * to obtain a reference to the first use. Then, call LLVMGetNextUse()
1165 * on that instance and all subsequently obtained instances until
1166 * LLVMGetNextUse() returns NULL.
1168 * @see llvm::Value::use_begin()
1170 LLVMUseRef LLVMGetFirstUse(LLVMValueRef Val);
1173 * Obtain the next use of a value.
1175 * This effectively advances the iterator. It returns NULL if you are on
1176 * the final use and no more are available.
1178 LLVMUseRef LLVMGetNextUse(LLVMUseRef U);
1181 * Obtain the user value for a user.
1183 * The returned value corresponds to a llvm::User type.
1185 * @see llvm::Use::getUser()
1187 LLVMValueRef LLVMGetUser(LLVMUseRef U);
1190 * Obtain the value this use corresponds to.
1192 * @see llvm::Use::get().
1194 LLVMValueRef LLVMGetUsedValue(LLVMUseRef U);
1201 * @defgroup LLVMCCoreValueUser User value
1203 * Function in this group pertain to LLVMValueRef instances that descent
1204 * from llvm::User. This includes constants, instructions, and
1211 * Obtain an operand at a specific index in a llvm::User value.
1213 * @see llvm::User::getOperand()
1215 LLVMValueRef LLVMGetOperand(LLVMValueRef Val, unsigned Index);
1218 * Set an operand at a specific index in a llvm::User value.
1220 * @see llvm::User::setOperand()
1222 void LLVMSetOperand(LLVMValueRef User, unsigned Index, LLVMValueRef Val);
1225 * Obtain the number of operands in a llvm::User value.
1227 * @see llvm::User::getNumOperands()
1229 int LLVMGetNumOperands(LLVMValueRef Val);
1236 * @defgroup LLVMCCoreValueConstant Constants
1238 * This section contains APIs for interacting with LLVMValueRef that
1239 * correspond to llvm::Constant instances.
1241 * These functions will work for any LLVMValueRef in the llvm::Constant
1248 * Obtain a constant value referring to the null instance of a type.
1250 * @see llvm::Constant::getNullValue()
1252 LLVMValueRef LLVMConstNull(LLVMTypeRef Ty); /* all zeroes */
1255 * Obtain a constant value referring to the instance of a type
1256 * consisting of all ones.
1258 * This is only valid for integer types.
1260 * @see llvm::Constant::getAllOnesValue()
1262 LLVMValueRef LLVMConstAllOnes(LLVMTypeRef Ty);
1265 * Obtain a constant value referring to an undefined value of a type.
1267 * @see llvm::UndefValue::get()
1269 LLVMValueRef LLVMGetUndef(LLVMTypeRef Ty);
1272 * Determine whether a value instance is null.
1274 * @see llvm::Constant::isNullValue()
1276 LLVMBool LLVMIsNull(LLVMValueRef Val);
1279 * Obtain a constant that is a constant pointer pointing to NULL for a
1282 LLVMValueRef LLVMConstPointerNull(LLVMTypeRef Ty);
1285 * @defgroup LLVMCCoreValueConstantScalar Scalar constants
1287 * Functions in this group model LLVMValueRef instances that correspond
1288 * to constants referring to scalar types.
1290 * For integer types, the LLVMTypeRef parameter should correspond to a
1291 * llvm::IntegerType instance and the returned LLVMValueRef will
1292 * correspond to a llvm::ConstantInt.
1294 * For floating point types, the LLVMTypeRef returned corresponds to a
1301 * Obtain a constant value for an integer type.
1303 * The returned value corresponds to a llvm::ConstantInt.
1305 * @see llvm::ConstantInt::get()
1307 * @param IntTy Integer type to obtain value of.
1308 * @param N The value the returned instance should refer to.
1309 * @param SignExtend Whether to sign extend the produced value.
1311 LLVMValueRef LLVMConstInt(LLVMTypeRef IntTy, unsigned long long N,
1312 LLVMBool SignExtend);
1315 * Obtain a constant value for an integer of arbitrary precision.
1317 * @see llvm::ConstantInt::get()
1319 LLVMValueRef LLVMConstIntOfArbitraryPrecision(LLVMTypeRef IntTy,
1321 const uint64_t Words[]);
1324 * Obtain a constant value for an integer parsed from a string.
1326 * A similar API, LLVMConstIntOfStringAndSize is also available. If the
1327 * string's length is available, it is preferred to call that function
1330 * @see llvm::ConstantInt::get()
1332 LLVMValueRef LLVMConstIntOfString(LLVMTypeRef IntTy, const char *Text,
1336 * Obtain a constant value for an integer parsed from a string with
1339 * @see llvm::ConstantInt::get()
1341 LLVMValueRef LLVMConstIntOfStringAndSize(LLVMTypeRef IntTy, const char *Text,
1342 unsigned SLen, uint8_t Radix);
1345 * Obtain a constant value referring to a double floating point value.
1347 LLVMValueRef LLVMConstReal(LLVMTypeRef RealTy, double N);
1350 * Obtain a constant for a floating point value parsed from a string.
1352 * A similar API, LLVMConstRealOfStringAndSize is also available. It
1353 * should be used if the input string's length is known.
1355 LLVMValueRef LLVMConstRealOfString(LLVMTypeRef RealTy, const char *Text);
1358 * Obtain a constant for a floating point value parsed from a string.
1360 LLVMValueRef LLVMConstRealOfStringAndSize(LLVMTypeRef RealTy, const char *Text,
1364 * Obtain the zero extended value for an integer constant value.
1366 * @see llvm::ConstantInt::getZExtValue()
1368 unsigned long long LLVMConstIntGetZExtValue(LLVMValueRef ConstantVal);
1371 * Obtain the sign extended value for an integer constant value.
1373 * @see llvm::ConstantInt::getSExtValue()
1375 long long LLVMConstIntGetSExtValue(LLVMValueRef ConstantVal);
1382 * @defgroup LLVMCCoreValueConstantComposite Composite Constants
1384 * Functions in this group operate on composite constants.
1390 * Create a ConstantDataSequential and initialize it with a string.
1392 * @see llvm::ConstantDataArray::getString()
1394 LLVMValueRef LLVMConstStringInContext(LLVMContextRef C, const char *Str,
1395 unsigned Length, LLVMBool DontNullTerminate);
1398 * Create a ConstantDataSequential with string content in the global context.
1400 * This is the same as LLVMConstStringInContext except it operates on the
1403 * @see LLVMConstStringInContext()
1404 * @see llvm::ConstantDataArray::getString()
1406 LLVMValueRef LLVMConstString(const char *Str, unsigned Length,
1407 LLVMBool DontNullTerminate);
1410 * Create an anonymous ConstantStruct with the specified values.
1412 * @see llvm::ConstantStruct::getAnon()
1414 LLVMValueRef LLVMConstStructInContext(LLVMContextRef C,
1415 LLVMValueRef *ConstantVals,
1416 unsigned Count, LLVMBool Packed);
1419 * Create a ConstantStruct in the global Context.
1421 * This is the same as LLVMConstStructInContext except it operates on the
1424 * @see LLVMConstStructInContext()
1426 LLVMValueRef LLVMConstStruct(LLVMValueRef *ConstantVals, unsigned Count,
1430 * Create a ConstantArray from values.
1432 * @see llvm::ConstantArray::get()
1434 LLVMValueRef LLVMConstArray(LLVMTypeRef ElementTy,
1435 LLVMValueRef *ConstantVals, unsigned Length);
1438 * Create a non-anonymous ConstantStruct from values.
1440 * @see llvm::ConstantStruct::get()
1442 LLVMValueRef LLVMConstNamedStruct(LLVMTypeRef StructTy,
1443 LLVMValueRef *ConstantVals,
1447 * Create a ConstantVector from values.
1449 * @see llvm::ConstantVector::get()
1451 LLVMValueRef LLVMConstVector(LLVMValueRef *ScalarConstantVals, unsigned Size);
1458 * @defgroup LLVMCCoreValueConstantExpressions Constant Expressions
1460 * Functions in this group correspond to APIs on llvm::ConstantExpr.
1462 * @see llvm::ConstantExpr.
1466 LLVMOpcode LLVMGetConstOpcode(LLVMValueRef ConstantVal);
1467 LLVMValueRef LLVMAlignOf(LLVMTypeRef Ty);
1468 LLVMValueRef LLVMSizeOf(LLVMTypeRef Ty);
1469 LLVMValueRef LLVMConstNeg(LLVMValueRef ConstantVal);
1470 LLVMValueRef LLVMConstNSWNeg(LLVMValueRef ConstantVal);
1471 LLVMValueRef LLVMConstNUWNeg(LLVMValueRef ConstantVal);
1472 LLVMValueRef LLVMConstFNeg(LLVMValueRef ConstantVal);
1473 LLVMValueRef LLVMConstNot(LLVMValueRef ConstantVal);
1474 LLVMValueRef LLVMConstAdd(LLVMValueRef LHSConstant, LLVMValueRef RHSConstant);
1475 LLVMValueRef LLVMConstNSWAdd(LLVMValueRef LHSConstant, LLVMValueRef RHSConstant);
1476 LLVMValueRef LLVMConstNUWAdd(LLVMValueRef LHSConstant, LLVMValueRef RHSConstant);
1477 LLVMValueRef LLVMConstFAdd(LLVMValueRef LHSConstant, LLVMValueRef RHSConstant);
1478 LLVMValueRef LLVMConstSub(LLVMValueRef LHSConstant, LLVMValueRef RHSConstant);
1479 LLVMValueRef LLVMConstNSWSub(LLVMValueRef LHSConstant, LLVMValueRef RHSConstant);
1480 LLVMValueRef LLVMConstNUWSub(LLVMValueRef LHSConstant, LLVMValueRef RHSConstant);
1481 LLVMValueRef LLVMConstFSub(LLVMValueRef LHSConstant, LLVMValueRef RHSConstant);
1482 LLVMValueRef LLVMConstMul(LLVMValueRef LHSConstant, LLVMValueRef RHSConstant);
1483 LLVMValueRef LLVMConstNSWMul(LLVMValueRef LHSConstant, LLVMValueRef RHSConstant);
1484 LLVMValueRef LLVMConstNUWMul(LLVMValueRef LHSConstant, LLVMValueRef RHSConstant);
1485 LLVMValueRef LLVMConstFMul(LLVMValueRef LHSConstant, LLVMValueRef RHSConstant);
1486 LLVMValueRef LLVMConstUDiv(LLVMValueRef LHSConstant, LLVMValueRef RHSConstant);
1487 LLVMValueRef LLVMConstSDiv(LLVMValueRef LHSConstant, LLVMValueRef RHSConstant);
1488 LLVMValueRef LLVMConstExactSDiv(LLVMValueRef LHSConstant, LLVMValueRef RHSConstant);
1489 LLVMValueRef LLVMConstFDiv(LLVMValueRef LHSConstant, LLVMValueRef RHSConstant);
1490 LLVMValueRef LLVMConstURem(LLVMValueRef LHSConstant, LLVMValueRef RHSConstant);
1491 LLVMValueRef LLVMConstSRem(LLVMValueRef LHSConstant, LLVMValueRef RHSConstant);
1492 LLVMValueRef LLVMConstFRem(LLVMValueRef LHSConstant, LLVMValueRef RHSConstant);
1493 LLVMValueRef LLVMConstAnd(LLVMValueRef LHSConstant, LLVMValueRef RHSConstant);
1494 LLVMValueRef LLVMConstOr(LLVMValueRef LHSConstant, LLVMValueRef RHSConstant);
1495 LLVMValueRef LLVMConstXor(LLVMValueRef LHSConstant, LLVMValueRef RHSConstant);
1496 LLVMValueRef LLVMConstICmp(LLVMIntPredicate Predicate,
1497 LLVMValueRef LHSConstant, LLVMValueRef RHSConstant);
1498 LLVMValueRef LLVMConstFCmp(LLVMRealPredicate Predicate,
1499 LLVMValueRef LHSConstant, LLVMValueRef RHSConstant);
1500 LLVMValueRef LLVMConstShl(LLVMValueRef LHSConstant, LLVMValueRef RHSConstant);
1501 LLVMValueRef LLVMConstLShr(LLVMValueRef LHSConstant, LLVMValueRef RHSConstant);
1502 LLVMValueRef LLVMConstAShr(LLVMValueRef LHSConstant, LLVMValueRef RHSConstant);
1503 LLVMValueRef LLVMConstGEP(LLVMValueRef ConstantVal,
1504 LLVMValueRef *ConstantIndices, unsigned NumIndices);
1505 LLVMValueRef LLVMConstInBoundsGEP(LLVMValueRef ConstantVal,
1506 LLVMValueRef *ConstantIndices,
1507 unsigned NumIndices);
1508 LLVMValueRef LLVMConstTrunc(LLVMValueRef ConstantVal, LLVMTypeRef ToType);
1509 LLVMValueRef LLVMConstSExt(LLVMValueRef ConstantVal, LLVMTypeRef ToType);
1510 LLVMValueRef LLVMConstZExt(LLVMValueRef ConstantVal, LLVMTypeRef ToType);
1511 LLVMValueRef LLVMConstFPTrunc(LLVMValueRef ConstantVal, LLVMTypeRef ToType);
1512 LLVMValueRef LLVMConstFPExt(LLVMValueRef ConstantVal, LLVMTypeRef ToType);
1513 LLVMValueRef LLVMConstUIToFP(LLVMValueRef ConstantVal, LLVMTypeRef ToType);
1514 LLVMValueRef LLVMConstSIToFP(LLVMValueRef ConstantVal, LLVMTypeRef ToType);
1515 LLVMValueRef LLVMConstFPToUI(LLVMValueRef ConstantVal, LLVMTypeRef ToType);
1516 LLVMValueRef LLVMConstFPToSI(LLVMValueRef ConstantVal, LLVMTypeRef ToType);
1517 LLVMValueRef LLVMConstPtrToInt(LLVMValueRef ConstantVal, LLVMTypeRef ToType);
1518 LLVMValueRef LLVMConstIntToPtr(LLVMValueRef ConstantVal, LLVMTypeRef ToType);
1519 LLVMValueRef LLVMConstBitCast(LLVMValueRef ConstantVal, LLVMTypeRef ToType);
1520 LLVMValueRef LLVMConstZExtOrBitCast(LLVMValueRef ConstantVal,
1521 LLVMTypeRef ToType);
1522 LLVMValueRef LLVMConstSExtOrBitCast(LLVMValueRef ConstantVal,
1523 LLVMTypeRef ToType);
1524 LLVMValueRef LLVMConstTruncOrBitCast(LLVMValueRef ConstantVal,
1525 LLVMTypeRef ToType);
1526 LLVMValueRef LLVMConstPointerCast(LLVMValueRef ConstantVal,
1527 LLVMTypeRef ToType);
1528 LLVMValueRef LLVMConstIntCast(LLVMValueRef ConstantVal, LLVMTypeRef ToType,
1530 LLVMValueRef LLVMConstFPCast(LLVMValueRef ConstantVal, LLVMTypeRef ToType);
1531 LLVMValueRef LLVMConstSelect(LLVMValueRef ConstantCondition,
1532 LLVMValueRef ConstantIfTrue,
1533 LLVMValueRef ConstantIfFalse);
1534 LLVMValueRef LLVMConstExtractElement(LLVMValueRef VectorConstant,
1535 LLVMValueRef IndexConstant);
1536 LLVMValueRef LLVMConstInsertElement(LLVMValueRef VectorConstant,
1537 LLVMValueRef ElementValueConstant,
1538 LLVMValueRef IndexConstant);
1539 LLVMValueRef LLVMConstShuffleVector(LLVMValueRef VectorAConstant,
1540 LLVMValueRef VectorBConstant,
1541 LLVMValueRef MaskConstant);
1542 LLVMValueRef LLVMConstExtractValue(LLVMValueRef AggConstant, unsigned *IdxList,
1544 LLVMValueRef LLVMConstInsertValue(LLVMValueRef AggConstant,
1545 LLVMValueRef ElementValueConstant,
1546 unsigned *IdxList, unsigned NumIdx);
1547 LLVMValueRef LLVMConstInlineAsm(LLVMTypeRef Ty,
1548 const char *AsmString, const char *Constraints,
1549 LLVMBool HasSideEffects, LLVMBool IsAlignStack);
1550 LLVMValueRef LLVMBlockAddress(LLVMValueRef F, LLVMBasicBlockRef BB);
1557 * @defgroup LLVMCCoreValueConstantGlobals Global Values
1559 * This group contains functions that operate on global values. Functions in
1560 * this group relate to functions in the llvm::GlobalValue class tree.
1562 * @see llvm::GlobalValue
1567 LLVMModuleRef LLVMGetGlobalParent(LLVMValueRef Global);
1568 LLVMBool LLVMIsDeclaration(LLVMValueRef Global);
1569 LLVMLinkage LLVMGetLinkage(LLVMValueRef Global);
1570 void LLVMSetLinkage(LLVMValueRef Global, LLVMLinkage Linkage);
1571 const char *LLVMGetSection(LLVMValueRef Global);
1572 void LLVMSetSection(LLVMValueRef Global, const char *Section);
1573 LLVMVisibility LLVMGetVisibility(LLVMValueRef Global);
1574 void LLVMSetVisibility(LLVMValueRef Global, LLVMVisibility Viz);
1575 unsigned LLVMGetAlignment(LLVMValueRef Global);
1576 void LLVMSetAlignment(LLVMValueRef Global, unsigned Bytes);
1579 * @defgroup LLVMCoreValueConstantGlobalVariable Global Variables
1581 * This group contains functions that operate on global variable values.
1583 * @see llvm::GlobalVariable
1587 LLVMValueRef LLVMAddGlobal(LLVMModuleRef M, LLVMTypeRef Ty, const char *Name);
1588 LLVMValueRef LLVMAddGlobalInAddressSpace(LLVMModuleRef M, LLVMTypeRef Ty,
1590 unsigned AddressSpace);
1591 LLVMValueRef LLVMGetNamedGlobal(LLVMModuleRef M, const char *Name);
1592 LLVMValueRef LLVMGetFirstGlobal(LLVMModuleRef M);
1593 LLVMValueRef LLVMGetLastGlobal(LLVMModuleRef M);
1594 LLVMValueRef LLVMGetNextGlobal(LLVMValueRef GlobalVar);
1595 LLVMValueRef LLVMGetPreviousGlobal(LLVMValueRef GlobalVar);
1596 void LLVMDeleteGlobal(LLVMValueRef GlobalVar);
1597 LLVMValueRef LLVMGetInitializer(LLVMValueRef GlobalVar);
1598 void LLVMSetInitializer(LLVMValueRef GlobalVar, LLVMValueRef ConstantVal);
1599 LLVMBool LLVMIsThreadLocal(LLVMValueRef GlobalVar);
1600 void LLVMSetThreadLocal(LLVMValueRef GlobalVar, LLVMBool IsThreadLocal);
1601 LLVMBool LLVMIsGlobalConstant(LLVMValueRef GlobalVar);
1602 void LLVMSetGlobalConstant(LLVMValueRef GlobalVar, LLVMBool IsConstant);
1609 * @defgroup LLVMCoreValueConstantGlobalAlias Global Aliases
1611 * This group contains function that operate on global alias values.
1613 * @see llvm::GlobalAlias
1617 LLVMValueRef LLVMAddAlias(LLVMModuleRef M, LLVMTypeRef Ty, LLVMValueRef Aliasee,
1625 * @defgroup LLVMCCoreValueFunction Function values
1627 * Functions in this group operate on LLVMValueRef instances that
1628 * correspond to llvm::Function instances.
1630 * @see llvm::Function
1636 * Remove a function from its containing module and deletes it.
1638 * @see llvm::Function::eraseFromParent()
1640 void LLVMDeleteFunction(LLVMValueRef Fn);
1643 * Obtain the ID number from a function instance.
1645 * @see llvm::Function::getIntrinsicID()
1647 unsigned LLVMGetIntrinsicID(LLVMValueRef Fn);
1650 * Obtain the calling function of a function.
1652 * The returned value corresponds to the LLVMCallConv enumeration.
1654 * @see llvm::Function::getCallingConv()
1656 unsigned LLVMGetFunctionCallConv(LLVMValueRef Fn);
1659 * Set the calling convention of a function.
1661 * @see llvm::Function::setCallingConv()
1663 * @param Fn Function to operate on
1664 * @param CC LLVMCallConv to set calling convention to
1666 void LLVMSetFunctionCallConv(LLVMValueRef Fn, unsigned CC);
1669 * Obtain the name of the garbage collector to use during code
1672 * @see llvm::Function::getGC()
1674 const char *LLVMGetGC(LLVMValueRef Fn);
1677 * Define the garbage collector to use during code generation.
1679 * @see llvm::Function::setGC()
1681 void LLVMSetGC(LLVMValueRef Fn, const char *Name);
1684 * Add an attribute to a function.
1686 * @see llvm::Function::addAttribute()
1688 void LLVMAddFunctionAttr(LLVMValueRef Fn, LLVMAttribute PA);
1691 * Obtain an attribute from a function.
1693 * @see llvm::Function::getAttributes()
1695 LLVMAttribute LLVMGetFunctionAttr(LLVMValueRef Fn);
1698 * Remove an attribute from a function.
1700 void LLVMRemoveFunctionAttr(LLVMValueRef Fn, LLVMAttribute PA);
1703 * @defgroup LLVMCCoreValueFunctionParameters Function Parameters
1705 * Functions in this group relate to arguments/parameters on functions.
1707 * Functions in this group expect LLVMValueRef instances that correspond
1708 * to llvm::Function instances.
1714 * Obtain the number of parameters in a function.
1716 * @see llvm::Function::arg_size()
1718 unsigned LLVMCountParams(LLVMValueRef Fn);
1721 * Obtain the parameters in a function.
1723 * The takes a pointer to a pre-allocated array of LLVMValueRef that is
1724 * at least LLVMCountParams() long. This array will be filled with
1725 * LLVMValueRef instances which correspond to the parameters the
1726 * function receives. Each LLVMValueRef corresponds to a llvm::Argument
1729 * @see llvm::Function::arg_begin()
1731 void LLVMGetParams(LLVMValueRef Fn, LLVMValueRef *Params);
1734 * Obtain the parameter at the specified index.
1736 * Parameters are indexed from 0.
1738 * @see llvm::Function::arg_begin()
1740 LLVMValueRef LLVMGetParam(LLVMValueRef Fn, unsigned Index);
1743 * Obtain the function to which this argument belongs.
1745 * Unlike other functions in this group, this one takes a LLVMValueRef
1746 * that corresponds to a llvm::Attribute.
1748 * The returned LLVMValueRef is the llvm::Function to which this
1751 LLVMValueRef LLVMGetParamParent(LLVMValueRef Inst);
1754 * Obtain the first parameter to a function.
1756 * @see llvm::Function::arg_begin()
1758 LLVMValueRef LLVMGetFirstParam(LLVMValueRef Fn);
1761 * Obtain the last parameter to a function.
1763 * @see llvm::Function::arg_end()
1765 LLVMValueRef LLVMGetLastParam(LLVMValueRef Fn);
1768 * Obtain the next parameter to a function.
1770 * This takes a LLVMValueRef obtained from LLVMGetFirstParam() (which is
1771 * actually a wrapped iterator) and obtains the next parameter from the
1772 * underlying iterator.
1774 LLVMValueRef LLVMGetNextParam(LLVMValueRef Arg);
1777 * Obtain the previous parameter to a function.
1779 * This is the opposite of LLVMGetNextParam().
1781 LLVMValueRef LLVMGetPreviousParam(LLVMValueRef Arg);
1784 * Add an attribute to a function argument.
1786 * @see llvm::Argument::addAttr()
1788 void LLVMAddAttribute(LLVMValueRef Arg, LLVMAttribute PA);
1791 * Remove an attribute from a function argument.
1793 * @see llvm::Argument::removeAttr()
1795 void LLVMRemoveAttribute(LLVMValueRef Arg, LLVMAttribute PA);
1798 * Get an attribute from a function argument.
1800 LLVMAttribute LLVMGetAttribute(LLVMValueRef Arg);
1803 * Set the alignment for a function parameter.
1805 * @see llvm::Argument::addAttr()
1806 * @see llvm::Attribute::constructAlignmentFromInt()
1808 void LLVMSetParamAlignment(LLVMValueRef Arg, unsigned align);
1827 * @defgroup LLVMCCoreValueMetadata Metadata
1833 * Obtain a MDString value from a context.
1835 * The returned instance corresponds to the llvm::MDString class.
1837 * The instance is specified by string data of a specified length. The
1838 * string content is copied, so the backing memory can be freed after
1839 * this function returns.
1841 LLVMValueRef LLVMMDStringInContext(LLVMContextRef C, const char *Str,
1845 * Obtain a MDString value from the global context.
1847 LLVMValueRef LLVMMDString(const char *Str, unsigned SLen);
1850 * Obtain a MDNode value from a context.
1852 * The returned value corresponds to the llvm::MDNode class.
1854 LLVMValueRef LLVMMDNodeInContext(LLVMContextRef C, LLVMValueRef *Vals,
1858 * Obtain a MDNode value from the global context.
1860 LLVMValueRef LLVMMDNode(LLVMValueRef *Vals, unsigned Count);
1863 * Obtain the underlying string from a MDString value.
1865 * @param V Instance to obtain string from.
1866 * @param Len Memory address which will hold length of returned string.
1867 * @return String data in MDString.
1869 const char *LLVMGetMDString(LLVMValueRef V, unsigned* Len);
1876 * @defgroup LLVMCCoreValueBasicBlock Basic Block
1878 * A basic block represents a single entry single exit section of code.
1879 * Basic blocks contain a list of instructions which form the body of
1882 * Basic blocks belong to functions. They have the type of label.
1884 * Basic blocks are themselves values. However, the C API models them as
1885 * LLVMBasicBlockRef.
1887 * @see llvm::BasicBlock
1893 * Convert a basic block instance to a value type.
1895 LLVMValueRef LLVMBasicBlockAsValue(LLVMBasicBlockRef BB);
1898 * Determine whether a LLVMValueRef is itself a basic block.
1900 LLVMBool LLVMValueIsBasicBlock(LLVMValueRef Val);
1903 * Convert a LLVMValueRef to a LLVMBasicBlockRef instance.
1905 LLVMBasicBlockRef LLVMValueAsBasicBlock(LLVMValueRef Val);
1908 * Obtain the function to which a basic block belongs.
1910 * @see llvm::BasicBlock::getParent()
1912 LLVMValueRef LLVMGetBasicBlockParent(LLVMBasicBlockRef BB);
1915 * Obtain the terminator instruction for a basic block.
1917 * If the basic block does not have a terminator (it is not well-formed
1918 * if it doesn't), then NULL is returned.
1920 * The returned LLVMValueRef corresponds to a llvm::TerminatorInst.
1922 * @see llvm::BasicBlock::getTerminator()
1924 LLVMValueRef LLVMGetBasicBlockTerminator(LLVMBasicBlockRef BB);
1927 * Obtain the number of basic blocks in a function.
1929 * @param Fn Function value to operate on.
1931 unsigned LLVMCountBasicBlocks(LLVMValueRef Fn);
1934 * Obtain all of the basic blocks in a function.
1936 * This operates on a function value. The BasicBlocks parameter is a
1937 * pointer to a pre-allocated array of LLVMBasicBlockRef of at least
1938 * LLVMCountBasicBlocks() in length. This array is populated with
1939 * LLVMBasicBlockRef instances.
1941 void LLVMGetBasicBlocks(LLVMValueRef Fn, LLVMBasicBlockRef *BasicBlocks);
1944 * Obtain the first basic block in a function.
1946 * The returned basic block can be used as an iterator. You will likely
1947 * eventually call into LLVMGetNextBasicBlock() with it.
1949 * @see llvm::Function::begin()
1951 LLVMBasicBlockRef LLVMGetFirstBasicBlock(LLVMValueRef Fn);
1954 * Obtain the last basic block in a function.
1956 * @see llvm::Function::end()
1958 LLVMBasicBlockRef LLVMGetLastBasicBlock(LLVMValueRef Fn);
1961 * Advance a basic block iterator.
1963 LLVMBasicBlockRef LLVMGetNextBasicBlock(LLVMBasicBlockRef BB);
1966 * Go backwards in a basic block iterator.
1968 LLVMBasicBlockRef LLVMGetPreviousBasicBlock(LLVMBasicBlockRef BB);
1971 * Obtain the basic block that corresponds to the entry point of a
1974 * @see llvm::Function::getEntryBlock()
1976 LLVMBasicBlockRef LLVMGetEntryBasicBlock(LLVMValueRef Fn);
1979 * Append a basic block to the end of a function.
1981 * @see llvm::BasicBlock::Create()
1983 LLVMBasicBlockRef LLVMAppendBasicBlockInContext(LLVMContextRef C,
1988 * Append a basic block to the end of a function using the global
1991 * @see llvm::BasicBlock::Create()
1993 LLVMBasicBlockRef LLVMAppendBasicBlock(LLVMValueRef Fn, const char *Name);
1996 * Insert a basic block in a function before another basic block.
1998 * The function to add to is determined by the function of the
1999 * passed basic block.
2001 * @see llvm::BasicBlock::Create()
2003 LLVMBasicBlockRef LLVMInsertBasicBlockInContext(LLVMContextRef C,
2004 LLVMBasicBlockRef BB,
2008 * Insert a basic block in a function using the global context.
2010 * @see llvm::BasicBlock::Create()
2012 LLVMBasicBlockRef LLVMInsertBasicBlock(LLVMBasicBlockRef InsertBeforeBB,
2016 * Remove a basic block from a function and delete it.
2018 * This deletes the basic block from its containing function and deletes
2019 * the basic block itself.
2021 * @see llvm::BasicBlock::eraseFromParent()
2023 void LLVMDeleteBasicBlock(LLVMBasicBlockRef BB);
2026 * Remove a basic block from a function.
2028 * This deletes the basic block from its containing function but keep
2029 * the basic block alive.
2031 * @see llvm::BasicBlock::removeFromParent()
2033 void LLVMRemoveBasicBlockFromParent(LLVMBasicBlockRef BB);
2036 * Move a basic block to before another one.
2038 * @see llvm::BasicBlock::moveBefore()
2040 void LLVMMoveBasicBlockBefore(LLVMBasicBlockRef BB, LLVMBasicBlockRef MovePos);
2043 * Move a basic block to after another one.
2045 * @see llvm::BasicBlock::moveAfter()
2047 void LLVMMoveBasicBlockAfter(LLVMBasicBlockRef BB, LLVMBasicBlockRef MovePos);
2050 * Obtain the first instruction in a basic block.
2052 * The returned LLVMValueRef corresponds to a llvm::Instruction
2055 LLVMValueRef LLVMGetFirstInstruction(LLVMBasicBlockRef BB);
2058 * Obtain the last instruction in a basic block.
2060 * The returned LLVMValueRef corresponds to a LLVM:Instruction.
2062 LLVMValueRef LLVMGetLastInstruction(LLVMBasicBlockRef BB);
2069 * @defgroup LLVMCCoreValueInstruction Instructions
2071 * Functions in this group relate to the inspection and manipulation of
2072 * individual instructions.
2074 * In the C++ API, an instruction is modeled by llvm::Instruction. This
2075 * class has a large number of descendents. llvm::Instruction is a
2076 * llvm::Value and in the C API, instructions are modeled by
2079 * This group also contains sub-groups which operate on specific
2080 * llvm::Instruction types, e.g. llvm::CallInst.
2086 * Determine whether an instruction has any metadata attached.
2088 int LLVMHasMetadata(LLVMValueRef Val);
2091 * Return metadata associated with an instruction value.
2093 LLVMValueRef LLVMGetMetadata(LLVMValueRef Val, unsigned KindID);
2096 * Set metadata associated with an instruction value.
2098 void LLVMSetMetadata(LLVMValueRef Val, unsigned KindID, LLVMValueRef Node);
2101 * Obtain the basic block to which an instruction belongs.
2103 * @see llvm::Instruction::getParent()
2105 LLVMBasicBlockRef LLVMGetInstructionParent(LLVMValueRef Inst);
2108 * Obtain the instruction that occurs after the one specified.
2110 * The next instruction will be from the same basic block.
2112 * If this is the last instruction in a basic block, NULL will be
2115 LLVMValueRef LLVMGetNextInstruction(LLVMValueRef Inst);
2118 * Obtain the instruction that occurred before this one.
2120 * If the instruction is the first instruction in a basic block, NULL
2123 LLVMValueRef LLVMGetPreviousInstruction(LLVMValueRef Inst);
2126 * Remove and delete an instruction.
2128 * The instruction specified is removed from its containing building
2129 * block and then deleted.
2131 * @see llvm::Instruction::eraseFromParent()
2133 void LLVMInstructionEraseFromParent(LLVMValueRef Inst);
2136 * Obtain the code opcode for an individual instruction.
2138 * @see llvm::Instruction::getOpCode()
2140 LLVMOpcode LLVMGetInstructionOpcode(LLVMValueRef Inst);
2143 * Obtain the predicate of an instruction.
2145 * This is only valid for instructions that correspond to llvm::ICmpInst
2146 * or llvm::ConstantExpr whose opcode is llvm::Instruction::ICmp.
2148 * @see llvm::ICmpInst::getPredicate()
2150 LLVMIntPredicate LLVMGetICmpPredicate(LLVMValueRef Inst);
2153 * @defgroup LLVMCCoreValueInstructionCall Call Sites and Invocations
2155 * Functions in this group apply to instructions that refer to call
2156 * sites and invocations. These correspond to C++ types in the
2157 * llvm::CallInst class tree.
2163 * Set the calling convention for a call instruction.
2165 * This expects an LLVMValueRef that corresponds to a llvm::CallInst or
2168 * @see llvm::CallInst::setCallingConv()
2169 * @see llvm::InvokeInst::setCallingConv()
2171 void LLVMSetInstructionCallConv(LLVMValueRef Instr, unsigned CC);
2174 * Obtain the calling convention for a call instruction.
2176 * This is the opposite of LLVMSetInstructionCallConv(). Reads its
2179 * @see LLVMSetInstructionCallConv()
2181 unsigned LLVMGetInstructionCallConv(LLVMValueRef Instr);
2184 void LLVMAddInstrAttribute(LLVMValueRef Instr, unsigned index, LLVMAttribute);
2185 void LLVMRemoveInstrAttribute(LLVMValueRef Instr, unsigned index,
2187 void LLVMSetInstrParamAlignment(LLVMValueRef Instr, unsigned index,
2191 * Obtain whether a call instruction is a tail call.
2193 * This only works on llvm::CallInst instructions.
2195 * @see llvm::CallInst::isTailCall()
2197 LLVMBool LLVMIsTailCall(LLVMValueRef CallInst);
2200 * Set whether a call instruction is a tail call.
2202 * This only works on llvm::CallInst instructions.
2204 * @see llvm::CallInst::setTailCall()
2206 void LLVMSetTailCall(LLVMValueRef CallInst, LLVMBool IsTailCall);
2213 * Obtain the default destination basic block of a switch instruction.
2215 * This only works on llvm::SwitchInst instructions.
2217 * @see llvm::SwitchInst::getDefaultDest()
2219 LLVMBasicBlockRef LLVMGetSwitchDefaultDest(LLVMValueRef SwitchInstr);
2222 * @defgroup LLVMCCoreValueInstructionPHINode PHI Nodes
2224 * Functions in this group only apply to instructions that map to
2225 * llvm::PHINode instances.
2231 * Add an incoming value to the end of a PHI list.
2233 void LLVMAddIncoming(LLVMValueRef PhiNode, LLVMValueRef *IncomingValues,
2234 LLVMBasicBlockRef *IncomingBlocks, unsigned Count);
2237 * Obtain the number of incoming basic blocks to a PHI node.
2239 unsigned LLVMCountIncoming(LLVMValueRef PhiNode);
2242 * Obtain an incoming value to a PHI node as a LLVMValueRef.
2244 LLVMValueRef LLVMGetIncomingValue(LLVMValueRef PhiNode, unsigned Index);
2247 * Obtain an incoming value to a PHI node as a LLVMBasicBlockRef.
2249 LLVMBasicBlockRef LLVMGetIncomingBlock(LLVMValueRef PhiNode, unsigned Index);
2264 * @defgroup LLVMCCoreInstructionBuilder Instruction Builders
2266 * An instruction builder represents a point within a basic block and is
2267 * the exclusive means of building instructions using the C interface.
2272 LLVMBuilderRef LLVMCreateBuilderInContext(LLVMContextRef C);
2273 LLVMBuilderRef LLVMCreateBuilder(void);
2274 void LLVMPositionBuilder(LLVMBuilderRef Builder, LLVMBasicBlockRef Block,
2275 LLVMValueRef Instr);
2276 void LLVMPositionBuilderBefore(LLVMBuilderRef Builder, LLVMValueRef Instr);
2277 void LLVMPositionBuilderAtEnd(LLVMBuilderRef Builder, LLVMBasicBlockRef Block);
2278 LLVMBasicBlockRef LLVMGetInsertBlock(LLVMBuilderRef Builder);
2279 void LLVMClearInsertionPosition(LLVMBuilderRef Builder);
2280 void LLVMInsertIntoBuilder(LLVMBuilderRef Builder, LLVMValueRef Instr);
2281 void LLVMInsertIntoBuilderWithName(LLVMBuilderRef Builder, LLVMValueRef Instr,
2283 void LLVMDisposeBuilder(LLVMBuilderRef Builder);
2286 void LLVMSetCurrentDebugLocation(LLVMBuilderRef Builder, LLVMValueRef L);
2287 LLVMValueRef LLVMGetCurrentDebugLocation(LLVMBuilderRef Builder);
2288 void LLVMSetInstDebugLocation(LLVMBuilderRef Builder, LLVMValueRef Inst);
2291 LLVMValueRef LLVMBuildRetVoid(LLVMBuilderRef);
2292 LLVMValueRef LLVMBuildRet(LLVMBuilderRef, LLVMValueRef V);
2293 LLVMValueRef LLVMBuildAggregateRet(LLVMBuilderRef, LLVMValueRef *RetVals,
2295 LLVMValueRef LLVMBuildBr(LLVMBuilderRef, LLVMBasicBlockRef Dest);
2296 LLVMValueRef LLVMBuildCondBr(LLVMBuilderRef, LLVMValueRef If,
2297 LLVMBasicBlockRef Then, LLVMBasicBlockRef Else);
2298 LLVMValueRef LLVMBuildSwitch(LLVMBuilderRef, LLVMValueRef V,
2299 LLVMBasicBlockRef Else, unsigned NumCases);
2300 LLVMValueRef LLVMBuildIndirectBr(LLVMBuilderRef B, LLVMValueRef Addr,
2302 LLVMValueRef LLVMBuildInvoke(LLVMBuilderRef, LLVMValueRef Fn,
2303 LLVMValueRef *Args, unsigned NumArgs,
2304 LLVMBasicBlockRef Then, LLVMBasicBlockRef Catch,
2306 LLVMValueRef LLVMBuildLandingPad(LLVMBuilderRef B, LLVMTypeRef Ty,
2307 LLVMValueRef PersFn, unsigned NumClauses,
2309 LLVMValueRef LLVMBuildResume(LLVMBuilderRef B, LLVMValueRef Exn);
2310 LLVMValueRef LLVMBuildUnreachable(LLVMBuilderRef);
2312 /* Add a case to the switch instruction */
2313 void LLVMAddCase(LLVMValueRef Switch, LLVMValueRef OnVal,
2314 LLVMBasicBlockRef Dest);
2316 /* Add a destination to the indirectbr instruction */
2317 void LLVMAddDestination(LLVMValueRef IndirectBr, LLVMBasicBlockRef Dest);
2319 /* Add a catch or filter clause to the landingpad instruction */
2320 void LLVMAddClause(LLVMValueRef LandingPad, LLVMValueRef ClauseVal);
2322 /* Set the 'cleanup' flag in the landingpad instruction */
2323 void LLVMSetCleanup(LLVMValueRef LandingPad, LLVMBool Val);
2326 LLVMValueRef LLVMBuildAdd(LLVMBuilderRef, LLVMValueRef LHS, LLVMValueRef RHS,
2328 LLVMValueRef LLVMBuildNSWAdd(LLVMBuilderRef, LLVMValueRef LHS, LLVMValueRef RHS,
2330 LLVMValueRef LLVMBuildNUWAdd(LLVMBuilderRef, LLVMValueRef LHS, LLVMValueRef RHS,
2332 LLVMValueRef LLVMBuildFAdd(LLVMBuilderRef, LLVMValueRef LHS, LLVMValueRef RHS,
2334 LLVMValueRef LLVMBuildSub(LLVMBuilderRef, LLVMValueRef LHS, LLVMValueRef RHS,
2336 LLVMValueRef LLVMBuildNSWSub(LLVMBuilderRef, LLVMValueRef LHS, LLVMValueRef RHS,
2338 LLVMValueRef LLVMBuildNUWSub(LLVMBuilderRef, LLVMValueRef LHS, LLVMValueRef RHS,
2340 LLVMValueRef LLVMBuildFSub(LLVMBuilderRef, LLVMValueRef LHS, LLVMValueRef RHS,
2342 LLVMValueRef LLVMBuildMul(LLVMBuilderRef, LLVMValueRef LHS, LLVMValueRef RHS,
2344 LLVMValueRef LLVMBuildNSWMul(LLVMBuilderRef, LLVMValueRef LHS, LLVMValueRef RHS,
2346 LLVMValueRef LLVMBuildNUWMul(LLVMBuilderRef, LLVMValueRef LHS, LLVMValueRef RHS,
2348 LLVMValueRef LLVMBuildFMul(LLVMBuilderRef, LLVMValueRef LHS, LLVMValueRef RHS,
2350 LLVMValueRef LLVMBuildUDiv(LLVMBuilderRef, LLVMValueRef LHS, LLVMValueRef RHS,
2352 LLVMValueRef LLVMBuildSDiv(LLVMBuilderRef, LLVMValueRef LHS, LLVMValueRef RHS,
2354 LLVMValueRef LLVMBuildExactSDiv(LLVMBuilderRef, LLVMValueRef LHS, LLVMValueRef RHS,
2356 LLVMValueRef LLVMBuildFDiv(LLVMBuilderRef, LLVMValueRef LHS, LLVMValueRef RHS,
2358 LLVMValueRef LLVMBuildURem(LLVMBuilderRef, LLVMValueRef LHS, LLVMValueRef RHS,
2360 LLVMValueRef LLVMBuildSRem(LLVMBuilderRef, LLVMValueRef LHS, LLVMValueRef RHS,
2362 LLVMValueRef LLVMBuildFRem(LLVMBuilderRef, LLVMValueRef LHS, LLVMValueRef RHS,
2364 LLVMValueRef LLVMBuildShl(LLVMBuilderRef, LLVMValueRef LHS, LLVMValueRef RHS,
2366 LLVMValueRef LLVMBuildLShr(LLVMBuilderRef, LLVMValueRef LHS, LLVMValueRef RHS,
2368 LLVMValueRef LLVMBuildAShr(LLVMBuilderRef, LLVMValueRef LHS, LLVMValueRef RHS,
2370 LLVMValueRef LLVMBuildAnd(LLVMBuilderRef, LLVMValueRef LHS, LLVMValueRef RHS,
2372 LLVMValueRef LLVMBuildOr(LLVMBuilderRef, LLVMValueRef LHS, LLVMValueRef RHS,
2374 LLVMValueRef LLVMBuildXor(LLVMBuilderRef, LLVMValueRef LHS, LLVMValueRef RHS,
2376 LLVMValueRef LLVMBuildBinOp(LLVMBuilderRef B, LLVMOpcode Op,
2377 LLVMValueRef LHS, LLVMValueRef RHS,
2379 LLVMValueRef LLVMBuildNeg(LLVMBuilderRef, LLVMValueRef V, const char *Name);
2380 LLVMValueRef LLVMBuildNSWNeg(LLVMBuilderRef B, LLVMValueRef V,
2382 LLVMValueRef LLVMBuildNUWNeg(LLVMBuilderRef B, LLVMValueRef V,
2384 LLVMValueRef LLVMBuildFNeg(LLVMBuilderRef, LLVMValueRef V, const char *Name);
2385 LLVMValueRef LLVMBuildNot(LLVMBuilderRef, LLVMValueRef V, const char *Name);
2388 LLVMValueRef LLVMBuildMalloc(LLVMBuilderRef, LLVMTypeRef Ty, const char *Name);
2389 LLVMValueRef LLVMBuildArrayMalloc(LLVMBuilderRef, LLVMTypeRef Ty,
2390 LLVMValueRef Val, const char *Name);
2391 LLVMValueRef LLVMBuildAlloca(LLVMBuilderRef, LLVMTypeRef Ty, const char *Name);
2392 LLVMValueRef LLVMBuildArrayAlloca(LLVMBuilderRef, LLVMTypeRef Ty,
2393 LLVMValueRef Val, const char *Name);
2394 LLVMValueRef LLVMBuildFree(LLVMBuilderRef, LLVMValueRef PointerVal);
2395 LLVMValueRef LLVMBuildLoad(LLVMBuilderRef, LLVMValueRef PointerVal,
2397 LLVMValueRef LLVMBuildStore(LLVMBuilderRef, LLVMValueRef Val, LLVMValueRef Ptr);
2398 LLVMValueRef LLVMBuildGEP(LLVMBuilderRef B, LLVMValueRef Pointer,
2399 LLVMValueRef *Indices, unsigned NumIndices,
2401 LLVMValueRef LLVMBuildInBoundsGEP(LLVMBuilderRef B, LLVMValueRef Pointer,
2402 LLVMValueRef *Indices, unsigned NumIndices,
2404 LLVMValueRef LLVMBuildStructGEP(LLVMBuilderRef B, LLVMValueRef Pointer,
2405 unsigned Idx, const char *Name);
2406 LLVMValueRef LLVMBuildGlobalString(LLVMBuilderRef B, const char *Str,
2408 LLVMValueRef LLVMBuildGlobalStringPtr(LLVMBuilderRef B, const char *Str,
2410 LLVMBool LLVMGetVolatile(LLVMValueRef MemoryAccessInst);
2411 void LLVMSetVolatile(LLVMValueRef MemoryAccessInst, LLVMBool IsVolatile);
2414 LLVMValueRef LLVMBuildTrunc(LLVMBuilderRef, LLVMValueRef Val,
2415 LLVMTypeRef DestTy, const char *Name);
2416 LLVMValueRef LLVMBuildZExt(LLVMBuilderRef, LLVMValueRef Val,
2417 LLVMTypeRef DestTy, const char *Name);
2418 LLVMValueRef LLVMBuildSExt(LLVMBuilderRef, LLVMValueRef Val,
2419 LLVMTypeRef DestTy, const char *Name);
2420 LLVMValueRef LLVMBuildFPToUI(LLVMBuilderRef, LLVMValueRef Val,
2421 LLVMTypeRef DestTy, const char *Name);
2422 LLVMValueRef LLVMBuildFPToSI(LLVMBuilderRef, LLVMValueRef Val,
2423 LLVMTypeRef DestTy, const char *Name);
2424 LLVMValueRef LLVMBuildUIToFP(LLVMBuilderRef, LLVMValueRef Val,
2425 LLVMTypeRef DestTy, const char *Name);
2426 LLVMValueRef LLVMBuildSIToFP(LLVMBuilderRef, LLVMValueRef Val,
2427 LLVMTypeRef DestTy, const char *Name);
2428 LLVMValueRef LLVMBuildFPTrunc(LLVMBuilderRef, LLVMValueRef Val,
2429 LLVMTypeRef DestTy, const char *Name);
2430 LLVMValueRef LLVMBuildFPExt(LLVMBuilderRef, LLVMValueRef Val,
2431 LLVMTypeRef DestTy, const char *Name);
2432 LLVMValueRef LLVMBuildPtrToInt(LLVMBuilderRef, LLVMValueRef Val,
2433 LLVMTypeRef DestTy, const char *Name);
2434 LLVMValueRef LLVMBuildIntToPtr(LLVMBuilderRef, LLVMValueRef Val,
2435 LLVMTypeRef DestTy, const char *Name);
2436 LLVMValueRef LLVMBuildBitCast(LLVMBuilderRef, LLVMValueRef Val,
2437 LLVMTypeRef DestTy, const char *Name);
2438 LLVMValueRef LLVMBuildZExtOrBitCast(LLVMBuilderRef, LLVMValueRef Val,
2439 LLVMTypeRef DestTy, const char *Name);
2440 LLVMValueRef LLVMBuildSExtOrBitCast(LLVMBuilderRef, LLVMValueRef Val,
2441 LLVMTypeRef DestTy, const char *Name);
2442 LLVMValueRef LLVMBuildTruncOrBitCast(LLVMBuilderRef, LLVMValueRef Val,
2443 LLVMTypeRef DestTy, const char *Name);
2444 LLVMValueRef LLVMBuildCast(LLVMBuilderRef B, LLVMOpcode Op, LLVMValueRef Val,
2445 LLVMTypeRef DestTy, const char *Name);
2446 LLVMValueRef LLVMBuildPointerCast(LLVMBuilderRef, LLVMValueRef Val,
2447 LLVMTypeRef DestTy, const char *Name);
2448 LLVMValueRef LLVMBuildIntCast(LLVMBuilderRef, LLVMValueRef Val, /*Signed cast!*/
2449 LLVMTypeRef DestTy, const char *Name);
2450 LLVMValueRef LLVMBuildFPCast(LLVMBuilderRef, LLVMValueRef Val,
2451 LLVMTypeRef DestTy, const char *Name);
2454 LLVMValueRef LLVMBuildICmp(LLVMBuilderRef, LLVMIntPredicate Op,
2455 LLVMValueRef LHS, LLVMValueRef RHS,
2457 LLVMValueRef LLVMBuildFCmp(LLVMBuilderRef, LLVMRealPredicate Op,
2458 LLVMValueRef LHS, LLVMValueRef RHS,
2461 /* Miscellaneous instructions */
2462 LLVMValueRef LLVMBuildPhi(LLVMBuilderRef, LLVMTypeRef Ty, const char *Name);
2463 LLVMValueRef LLVMBuildCall(LLVMBuilderRef, LLVMValueRef Fn,
2464 LLVMValueRef *Args, unsigned NumArgs,
2466 LLVMValueRef LLVMBuildSelect(LLVMBuilderRef, LLVMValueRef If,
2467 LLVMValueRef Then, LLVMValueRef Else,
2469 LLVMValueRef LLVMBuildVAArg(LLVMBuilderRef, LLVMValueRef List, LLVMTypeRef Ty,
2471 LLVMValueRef LLVMBuildExtractElement(LLVMBuilderRef, LLVMValueRef VecVal,
2472 LLVMValueRef Index, const char *Name);
2473 LLVMValueRef LLVMBuildInsertElement(LLVMBuilderRef, LLVMValueRef VecVal,
2474 LLVMValueRef EltVal, LLVMValueRef Index,
2476 LLVMValueRef LLVMBuildShuffleVector(LLVMBuilderRef, LLVMValueRef V1,
2477 LLVMValueRef V2, LLVMValueRef Mask,
2479 LLVMValueRef LLVMBuildExtractValue(LLVMBuilderRef, LLVMValueRef AggVal,
2480 unsigned Index, const char *Name);
2481 LLVMValueRef LLVMBuildInsertValue(LLVMBuilderRef, LLVMValueRef AggVal,
2482 LLVMValueRef EltVal, unsigned Index,
2485 LLVMValueRef LLVMBuildIsNull(LLVMBuilderRef, LLVMValueRef Val,
2487 LLVMValueRef LLVMBuildIsNotNull(LLVMBuilderRef, LLVMValueRef Val,
2489 LLVMValueRef LLVMBuildPtrDiff(LLVMBuilderRef, LLVMValueRef LHS,
2490 LLVMValueRef RHS, const char *Name);
2497 * @defgroup LLVMCCoreModuleProvider Module Providers
2503 * Changes the type of M so it can be passed to FunctionPassManagers and the
2504 * JIT. They take ModuleProviders for historical reasons.
2506 LLVMModuleProviderRef
2507 LLVMCreateModuleProviderForExistingModule(LLVMModuleRef M);
2510 * Destroys the module M.
2512 void LLVMDisposeModuleProvider(LLVMModuleProviderRef M);
2519 * @defgroup LLVMCCoreMemoryBuffers Memory Buffers
2524 LLVMBool LLVMCreateMemoryBufferWithContentsOfFile(const char *Path,
2525 LLVMMemoryBufferRef *OutMemBuf,
2527 LLVMBool LLVMCreateMemoryBufferWithSTDIN(LLVMMemoryBufferRef *OutMemBuf,
2529 void LLVMDisposeMemoryBuffer(LLVMMemoryBufferRef MemBuf);
2536 * @defgroup LLVMCCorePassRegistry Pass Registry
2541 /** Return the global pass registry, for use with initialization functions.
2542 @see llvm::PassRegistry::getPassRegistry */
2543 LLVMPassRegistryRef LLVMGetGlobalPassRegistry(void);
2550 * @defgroup LLVMCCorePassManagers Pass Managers
2555 /** Constructs a new whole-module pass pipeline. This type of pipeline is
2556 suitable for link-time optimization and whole-module transformations.
2557 @see llvm::PassManager::PassManager */
2558 LLVMPassManagerRef LLVMCreatePassManager(void);
2560 /** Constructs a new function-by-function pass pipeline over the module
2561 provider. It does not take ownership of the module provider. This type of
2562 pipeline is suitable for code generation and JIT compilation tasks.
2563 @see llvm::FunctionPassManager::FunctionPassManager */
2564 LLVMPassManagerRef LLVMCreateFunctionPassManagerForModule(LLVMModuleRef M);
2566 /** Deprecated: Use LLVMCreateFunctionPassManagerForModule instead. */
2567 LLVMPassManagerRef LLVMCreateFunctionPassManager(LLVMModuleProviderRef MP);
2569 /** Initializes, executes on the provided module, and finalizes all of the
2570 passes scheduled in the pass manager. Returns 1 if any of the passes
2571 modified the module, 0 otherwise.
2572 @see llvm::PassManager::run(Module&) */
2573 LLVMBool LLVMRunPassManager(LLVMPassManagerRef PM, LLVMModuleRef M);
2575 /** Initializes all of the function passes scheduled in the function pass
2576 manager. Returns 1 if any of the passes modified the module, 0 otherwise.
2577 @see llvm::FunctionPassManager::doInitialization */
2578 LLVMBool LLVMInitializeFunctionPassManager(LLVMPassManagerRef FPM);
2580 /** Executes all of the function passes scheduled in the function pass manager
2581 on the provided function. Returns 1 if any of the passes modified the
2582 function, false otherwise.
2583 @see llvm::FunctionPassManager::run(Function&) */
2584 LLVMBool LLVMRunFunctionPassManager(LLVMPassManagerRef FPM, LLVMValueRef F);
2586 /** Finalizes all of the function passes scheduled in in the function pass
2587 manager. Returns 1 if any of the passes modified the module, 0 otherwise.
2588 @see llvm::FunctionPassManager::doFinalization */
2589 LLVMBool LLVMFinalizeFunctionPassManager(LLVMPassManagerRef FPM);
2591 /** Frees the memory of a pass pipeline. For function pipelines, does not free
2592 the module provider.
2593 @see llvm::PassManagerBase::~PassManagerBase. */
2594 void LLVMDisposePassManager(LLVMPassManagerRef PM);
2613 class PassManagerBase;
2615 #define DEFINE_SIMPLE_CONVERSION_FUNCTIONS(ty, ref) \
2616 inline ty *unwrap(ref P) { \
2617 return reinterpret_cast<ty*>(P); \
2620 inline ref wrap(const ty *P) { \
2621 return reinterpret_cast<ref>(const_cast<ty*>(P)); \
2624 #define DEFINE_ISA_CONVERSION_FUNCTIONS(ty, ref) \
2625 DEFINE_SIMPLE_CONVERSION_FUNCTIONS(ty, ref) \
2627 template<typename T> \
2628 inline T *unwrap(ref P) { \
2629 return cast<T>(unwrap(P)); \
2632 #define DEFINE_STDCXX_CONVERSION_FUNCTIONS(ty, ref) \
2633 DEFINE_SIMPLE_CONVERSION_FUNCTIONS(ty, ref) \
2635 template<typename T> \
2636 inline T *unwrap(ref P) { \
2637 T *Q = (T*)unwrap(P); \
2638 assert(Q && "Invalid cast!"); \
2642 DEFINE_ISA_CONVERSION_FUNCTIONS (Type, LLVMTypeRef )
2643 DEFINE_ISA_CONVERSION_FUNCTIONS (Value, LLVMValueRef )
2644 DEFINE_SIMPLE_CONVERSION_FUNCTIONS(Module, LLVMModuleRef )
2645 DEFINE_SIMPLE_CONVERSION_FUNCTIONS(BasicBlock, LLVMBasicBlockRef )
2646 DEFINE_SIMPLE_CONVERSION_FUNCTIONS(IRBuilder<>, LLVMBuilderRef )
2647 DEFINE_SIMPLE_CONVERSION_FUNCTIONS(MemoryBuffer, LLVMMemoryBufferRef )
2648 DEFINE_SIMPLE_CONVERSION_FUNCTIONS(LLVMContext, LLVMContextRef )
2649 DEFINE_SIMPLE_CONVERSION_FUNCTIONS(Use, LLVMUseRef )
2650 DEFINE_STDCXX_CONVERSION_FUNCTIONS(PassManagerBase, LLVMPassManagerRef )
2651 DEFINE_STDCXX_CONVERSION_FUNCTIONS(PassRegistry, LLVMPassRegistryRef )
2652 /* LLVMModuleProviderRef exists for historical reasons, but now just holds a
2655 inline Module *unwrap(LLVMModuleProviderRef MP) {
2656 return reinterpret_cast<Module*>(MP);
2659 #undef DEFINE_STDCXX_CONVERSION_FUNCTIONS
2660 #undef DEFINE_ISA_CONVERSION_FUNCTIONS
2661 #undef DEFINE_SIMPLE_CONVERSION_FUNCTIONS
2663 /* Specialized opaque context conversions.
2665 inline LLVMContext **unwrap(LLVMContextRef* Tys) {
2666 return reinterpret_cast<LLVMContext**>(Tys);
2669 inline LLVMContextRef *wrap(const LLVMContext **Tys) {
2670 return reinterpret_cast<LLVMContextRef*>(const_cast<LLVMContext**>(Tys));
2673 /* Specialized opaque type conversions.
2675 inline Type **unwrap(LLVMTypeRef* Tys) {
2676 return reinterpret_cast<Type**>(Tys);
2679 inline LLVMTypeRef *wrap(Type **Tys) {
2680 return reinterpret_cast<LLVMTypeRef*>(const_cast<Type**>(Tys));
2683 /* Specialized opaque value conversions.
2685 inline Value **unwrap(LLVMValueRef *Vals) {
2686 return reinterpret_cast<Value**>(Vals);
2689 template<typename T>
2690 inline T **unwrap(LLVMValueRef *Vals, unsigned Length) {
2692 for (LLVMValueRef *I = Vals, *E = Vals + Length; I != E; ++I)
2696 return reinterpret_cast<T**>(Vals);
2699 inline LLVMValueRef *wrap(const Value **Vals) {
2700 return reinterpret_cast<LLVMValueRef*>(const_cast<Value**>(Vals));
2704 #endif /* !defined(__cplusplus) */
2706 #endif /* !defined(LLVM_C_CORE_H) */