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-c/ErrorHandling.h"
19 #include "llvm-c/Types.h"
26 * @defgroup LLVMC LLVM-C: C interface to LLVM
28 * This module exposes parts of the LLVM library as a C API.
34 * @defgroup LLVMCTransforms Transforms
38 * @defgroup LLVMCCore Core
40 * This modules provide an interface to libLLVMCore, which implements
41 * the LLVM intermediate representation as well as other related types
44 * Many exotic languages can interoperate with C code but have a harder time
45 * with C++ due to name mangling. So in addition to C, this interface enables
46 * tools written in such languages.
52 * @defgroup LLVMCCoreTypes Types and Enumerations
58 LLVMZExtAttribute = 1<<0,
59 LLVMSExtAttribute = 1<<1,
60 LLVMNoReturnAttribute = 1<<2,
61 LLVMInRegAttribute = 1<<3,
62 LLVMStructRetAttribute = 1<<4,
63 LLVMNoUnwindAttribute = 1<<5,
64 LLVMNoAliasAttribute = 1<<6,
65 LLVMByValAttribute = 1<<7,
66 LLVMNestAttribute = 1<<8,
67 LLVMReadNoneAttribute = 1<<9,
68 LLVMReadOnlyAttribute = 1<<10,
69 LLVMNoInlineAttribute = 1<<11,
70 LLVMAlwaysInlineAttribute = 1<<12,
71 LLVMOptimizeForSizeAttribute = 1<<13,
72 LLVMStackProtectAttribute = 1<<14,
73 LLVMStackProtectReqAttribute = 1<<15,
74 LLVMAlignment = 31<<16,
75 LLVMNoCaptureAttribute = 1<<21,
76 LLVMNoRedZoneAttribute = 1<<22,
77 LLVMNoImplicitFloatAttribute = 1<<23,
78 LLVMNakedAttribute = 1<<24,
79 LLVMInlineHintAttribute = 1<<25,
80 LLVMStackAlignment = 7<<26,
81 LLVMReturnsTwice = 1 << 29,
82 LLVMUWTable = 1 << 30,
83 LLVMNonLazyBind = 1 << 31
85 /* FIXME: These attributes are currently not included in the C API as
86 a temporary measure until the API/ABI impact to the C API is understood
87 and the path forward agreed upon.
88 LLVMSanitizeAddressAttribute = 1ULL << 32,
89 LLVMStackProtectStrongAttribute = 1ULL<<35,
90 LLVMColdAttribute = 1ULL << 40,
91 LLVMOptimizeNoneAttribute = 1ULL << 42,
92 LLVMInAllocaAttribute = 1ULL << 43,
93 LLVMNonNullAttribute = 1ULL << 44,
94 LLVMJumpTableAttribute = 1ULL << 45,
95 LLVMConvergentAttribute = 1ULL << 46,
96 LLVMSafeStackAttribute = 1ULL << 47,
101 /* Terminator Instructions */
107 /* removed 6 due to API changes */
110 /* Standard Binary Operators */
124 /* Logical Operators */
132 /* Memory Operators */
136 LLVMGetElementPtr = 29,
151 LLVMAddrSpaceCast = 60,
153 /* Other Operators */
162 LLVMExtractElement = 50,
163 LLVMInsertElement = 51,
164 LLVMShuffleVector = 52,
165 LLVMExtractValue = 53,
166 LLVMInsertValue = 54,
168 /* Atomic operators */
170 LLVMAtomicCmpXchg = 56,
173 /* Exception Handling Operators */
184 LLVMVoidTypeKind, /**< type with no size */
185 LLVMHalfTypeKind, /**< 16 bit floating point type */
186 LLVMFloatTypeKind, /**< 32 bit floating point type */
187 LLVMDoubleTypeKind, /**< 64 bit floating point type */
188 LLVMX86_FP80TypeKind, /**< 80 bit floating point type (X87) */
189 LLVMFP128TypeKind, /**< 128 bit floating point type (112-bit mantissa)*/
190 LLVMPPC_FP128TypeKind, /**< 128 bit floating point type (two 64-bits) */
191 LLVMLabelTypeKind, /**< Labels */
192 LLVMIntegerTypeKind, /**< Arbitrary bit width integers */
193 LLVMFunctionTypeKind, /**< Functions */
194 LLVMStructTypeKind, /**< Structures */
195 LLVMArrayTypeKind, /**< Arrays */
196 LLVMPointerTypeKind, /**< Pointers */
197 LLVMVectorTypeKind, /**< SIMD 'packed' format, or other vector type */
198 LLVMMetadataTypeKind, /**< Metadata */
199 LLVMX86_MMXTypeKind, /**< X86 MMX */
200 LLVMTokenTypeKind /**< Tokens */
204 LLVMExternalLinkage, /**< Externally visible function */
205 LLVMAvailableExternallyLinkage,
206 LLVMLinkOnceAnyLinkage, /**< Keep one copy of function when linking (inline)*/
207 LLVMLinkOnceODRLinkage, /**< Same, but only replaced by something
209 LLVMLinkOnceODRAutoHideLinkage, /**< Obsolete */
210 LLVMWeakAnyLinkage, /**< Keep one copy of function when linking (weak) */
211 LLVMWeakODRLinkage, /**< Same, but only replaced by something
213 LLVMAppendingLinkage, /**< Special purpose, only applies to global arrays */
214 LLVMInternalLinkage, /**< Rename collisions when linking (static
216 LLVMPrivateLinkage, /**< Like Internal, but omit from symbol table */
217 LLVMDLLImportLinkage, /**< Obsolete */
218 LLVMDLLExportLinkage, /**< Obsolete */
219 LLVMExternalWeakLinkage,/**< ExternalWeak linkage description */
220 LLVMGhostLinkage, /**< Obsolete */
221 LLVMCommonLinkage, /**< Tentative definitions */
222 LLVMLinkerPrivateLinkage, /**< Like Private, but linker removes. */
223 LLVMLinkerPrivateWeakLinkage /**< Like LinkerPrivate, but is weak. */
227 LLVMDefaultVisibility, /**< The GV is visible */
228 LLVMHiddenVisibility, /**< The GV is hidden */
229 LLVMProtectedVisibility /**< The GV is protected */
233 LLVMDefaultStorageClass = 0,
234 LLVMDLLImportStorageClass = 1, /**< Function to be imported from DLL. */
235 LLVMDLLExportStorageClass = 2 /**< Function to be accessible from DLL. */
236 } LLVMDLLStorageClass;
240 LLVMFastCallConv = 8,
241 LLVMColdCallConv = 9,
242 LLVMWebKitJSCallConv = 12,
243 LLVMAnyRegCallConv = 13,
244 LLVMX86StdcallCallConv = 64,
245 LLVMX86FastcallCallConv = 65
249 LLVMIntEQ = 32, /**< equal */
250 LLVMIntNE, /**< not equal */
251 LLVMIntUGT, /**< unsigned greater than */
252 LLVMIntUGE, /**< unsigned greater or equal */
253 LLVMIntULT, /**< unsigned less than */
254 LLVMIntULE, /**< unsigned less or equal */
255 LLVMIntSGT, /**< signed greater than */
256 LLVMIntSGE, /**< signed greater or equal */
257 LLVMIntSLT, /**< signed less than */
258 LLVMIntSLE /**< signed less or equal */
262 LLVMRealPredicateFalse, /**< Always false (always folded) */
263 LLVMRealOEQ, /**< True if ordered and equal */
264 LLVMRealOGT, /**< True if ordered and greater than */
265 LLVMRealOGE, /**< True if ordered and greater than or equal */
266 LLVMRealOLT, /**< True if ordered and less than */
267 LLVMRealOLE, /**< True if ordered and less than or equal */
268 LLVMRealONE, /**< True if ordered and operands are unequal */
269 LLVMRealORD, /**< True if ordered (no nans) */
270 LLVMRealUNO, /**< True if unordered: isnan(X) | isnan(Y) */
271 LLVMRealUEQ, /**< True if unordered or equal */
272 LLVMRealUGT, /**< True if unordered or greater than */
273 LLVMRealUGE, /**< True if unordered, greater than, or equal */
274 LLVMRealULT, /**< True if unordered or less than */
275 LLVMRealULE, /**< True if unordered, less than, or equal */
276 LLVMRealUNE, /**< True if unordered or not equal */
277 LLVMRealPredicateTrue /**< Always true (always folded) */
281 LLVMLandingPadCatch, /**< A catch clause */
282 LLVMLandingPadFilter /**< A filter clause */
283 } LLVMLandingPadClauseTy;
286 LLVMNotThreadLocal = 0,
287 LLVMGeneralDynamicTLSModel,
288 LLVMLocalDynamicTLSModel,
289 LLVMInitialExecTLSModel,
290 LLVMLocalExecTLSModel
291 } LLVMThreadLocalMode;
294 LLVMAtomicOrderingNotAtomic = 0, /**< A load or store which is not atomic */
295 LLVMAtomicOrderingUnordered = 1, /**< Lowest level of atomicity, guarantees
296 somewhat sane results, lock free. */
297 LLVMAtomicOrderingMonotonic = 2, /**< guarantees that if you take all the
298 operations affecting a specific address,
299 a consistent ordering exists */
300 LLVMAtomicOrderingAcquire = 4, /**< Acquire provides a barrier of the sort
301 necessary to acquire a lock to access other
302 memory with normal loads and stores. */
303 LLVMAtomicOrderingRelease = 5, /**< Release is similar to Acquire, but with
304 a barrier of the sort necessary to release
306 LLVMAtomicOrderingAcquireRelease = 6, /**< provides both an Acquire and a
307 Release barrier (for fences and
308 operations which both read and write
310 LLVMAtomicOrderingSequentiallyConsistent = 7 /**< provides Acquire semantics
311 for loads and Release
312 semantics for stores.
313 Additionally, it guarantees
314 that a total ordering exists
316 SequentiallyConsistent
318 } LLVMAtomicOrdering;
321 LLVMAtomicRMWBinOpXchg, /**< Set the new value and return the one old */
322 LLVMAtomicRMWBinOpAdd, /**< Add a value and return the old one */
323 LLVMAtomicRMWBinOpSub, /**< Subtract a value and return the old one */
324 LLVMAtomicRMWBinOpAnd, /**< And a value and return the old one */
325 LLVMAtomicRMWBinOpNand, /**< Not-And a value and return the old one */
326 LLVMAtomicRMWBinOpOr, /**< OR a value and return the old one */
327 LLVMAtomicRMWBinOpXor, /**< Xor a value and return the old one */
328 LLVMAtomicRMWBinOpMax, /**< Sets the value if it's greater than the
329 original using a signed comparison and return
331 LLVMAtomicRMWBinOpMin, /**< Sets the value if it's Smaller than the
332 original using a signed comparison and return
334 LLVMAtomicRMWBinOpUMax, /**< Sets the value if it's greater than the
335 original using an unsigned comparison and return
337 LLVMAtomicRMWBinOpUMin /**< Sets the value if it's greater than the
338 original using an unsigned comparison and return
340 } LLVMAtomicRMWBinOp;
347 } LLVMDiagnosticSeverity;
353 void LLVMInitializeCore(LLVMPassRegistryRef R);
355 /** Deallocate and destroy all ManagedStatic variables.
356 @see llvm::llvm_shutdown
357 @see ManagedStatic */
358 void LLVMShutdown(void);
360 /*===-- Error handling ----------------------------------------------------===*/
362 char *LLVMCreateMessage(const char *Message);
363 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.
377 typedef void (*LLVMDiagnosticHandler)(LLVMDiagnosticInfoRef, void *);
378 typedef void (*LLVMYieldCallback)(LLVMContextRef, void *);
381 * Create a new context.
383 * Every call to this function should be paired with a call to
384 * LLVMContextDispose() or the context will leak memory.
386 LLVMContextRef LLVMContextCreate(void);
389 * Obtain the global context instance.
391 LLVMContextRef LLVMGetGlobalContext(void);
394 * Set the diagnostic handler for this context.
396 void LLVMContextSetDiagnosticHandler(LLVMContextRef C,
397 LLVMDiagnosticHandler Handler,
398 void *DiagnosticContext);
401 * Set the yield callback function for this context.
403 * @see LLVMContext::setYieldCallback()
405 void LLVMContextSetYieldCallback(LLVMContextRef C, LLVMYieldCallback Callback,
409 * Destroy a context instance.
411 * This should be called for every call to LLVMContextCreate() or memory
414 void LLVMContextDispose(LLVMContextRef C);
417 * Return a string representation of the DiagnosticInfo. Use
418 * LLVMDisposeMessage to free the string.
420 * @see DiagnosticInfo::print()
422 char *LLVMGetDiagInfoDescription(LLVMDiagnosticInfoRef DI);
425 * Return an enum LLVMDiagnosticSeverity.
427 * @see DiagnosticInfo::getSeverity()
429 LLVMDiagnosticSeverity LLVMGetDiagInfoSeverity(LLVMDiagnosticInfoRef DI);
431 unsigned LLVMGetMDKindIDInContext(LLVMContextRef C, const char* Name,
433 unsigned LLVMGetMDKindID(const char* Name, unsigned SLen);
440 * @defgroup LLVMCCoreModule Modules
442 * Modules represent the top-level structure in an LLVM program. An LLVM
443 * module is effectively a translation unit or a collection of
444 * translation units merged together.
450 * Create a new, empty module in the global context.
452 * This is equivalent to calling LLVMModuleCreateWithNameInContext with
453 * LLVMGetGlobalContext() as the context parameter.
455 * Every invocation should be paired with LLVMDisposeModule() or memory
458 LLVMModuleRef LLVMModuleCreateWithName(const char *ModuleID);
461 * Create a new, empty module in a specific context.
463 * Every invocation should be paired with LLVMDisposeModule() or memory
466 LLVMModuleRef LLVMModuleCreateWithNameInContext(const char *ModuleID,
469 * Return an exact copy of the specified module.
471 LLVMModuleRef LLVMCloneModule(LLVMModuleRef M);
474 * Destroy a module instance.
476 * This must be called for every created module or memory will be
479 void LLVMDisposeModule(LLVMModuleRef M);
482 * Obtain the data layout for a module.
484 * @see Module::getDataLayout()
486 const char *LLVMGetDataLayout(LLVMModuleRef M);
489 * Set the data layout for a module.
491 * @see Module::setDataLayout()
493 void LLVMSetDataLayout(LLVMModuleRef M, const char *Triple);
496 * Obtain the target triple for a module.
498 * @see Module::getTargetTriple()
500 const char *LLVMGetTarget(LLVMModuleRef M);
503 * Set the target triple for a module.
505 * @see Module::setTargetTriple()
507 void LLVMSetTarget(LLVMModuleRef M, const char *Triple);
510 * Dump a representation of a module to stderr.
512 * @see Module::dump()
514 void LLVMDumpModule(LLVMModuleRef M);
517 * Print a representation of a module to a file. The ErrorMessage needs to be
518 * disposed with LLVMDisposeMessage. Returns 0 on success, 1 otherwise.
520 * @see Module::print()
522 LLVMBool LLVMPrintModuleToFile(LLVMModuleRef M, const char *Filename,
523 char **ErrorMessage);
526 * Return a string representation of the module. Use
527 * LLVMDisposeMessage to free the string.
529 * @see Module::print()
531 char *LLVMPrintModuleToString(LLVMModuleRef M);
534 * Set inline assembly for a module.
536 * @see Module::setModuleInlineAsm()
538 void LLVMSetModuleInlineAsm(LLVMModuleRef M, const char *Asm);
541 * Obtain the context to which this module is associated.
543 * @see Module::getContext()
545 LLVMContextRef LLVMGetModuleContext(LLVMModuleRef M);
548 * Obtain a Type from a module by its registered name.
550 LLVMTypeRef LLVMGetTypeByName(LLVMModuleRef M, const char *Name);
553 * Obtain the number of operands for named metadata in a module.
555 * @see llvm::Module::getNamedMetadata()
557 unsigned LLVMGetNamedMetadataNumOperands(LLVMModuleRef M, const char* name);
560 * Obtain the named metadata operands for a module.
562 * The passed LLVMValueRef pointer should refer to an array of
563 * LLVMValueRef at least LLVMGetNamedMetadataNumOperands long. This
564 * array will be populated with the LLVMValueRef instances. Each
565 * instance corresponds to a llvm::MDNode.
567 * @see llvm::Module::getNamedMetadata()
568 * @see llvm::MDNode::getOperand()
570 void LLVMGetNamedMetadataOperands(LLVMModuleRef M, const char* name, LLVMValueRef *Dest);
573 * Add an operand to named metadata.
575 * @see llvm::Module::getNamedMetadata()
576 * @see llvm::MDNode::addOperand()
578 void LLVMAddNamedMetadataOperand(LLVMModuleRef M, const char* name,
582 * Add a function to a module under a specified name.
584 * @see llvm::Function::Create()
586 LLVMValueRef LLVMAddFunction(LLVMModuleRef M, const char *Name,
587 LLVMTypeRef FunctionTy);
590 * Obtain a Function value from a Module by its name.
592 * The returned value corresponds to a llvm::Function value.
594 * @see llvm::Module::getFunction()
596 LLVMValueRef LLVMGetNamedFunction(LLVMModuleRef M, const char *Name);
599 * Obtain an iterator to the first Function in a Module.
601 * @see llvm::Module::begin()
603 LLVMValueRef LLVMGetFirstFunction(LLVMModuleRef M);
606 * Obtain an iterator to the last Function in a Module.
608 * @see llvm::Module::end()
610 LLVMValueRef LLVMGetLastFunction(LLVMModuleRef M);
613 * Advance a Function iterator to the next Function.
615 * Returns NULL if the iterator was already at the end and there are no more
618 LLVMValueRef LLVMGetNextFunction(LLVMValueRef Fn);
621 * Decrement a Function iterator to the previous Function.
623 * Returns NULL if the iterator was already at the beginning and there are
624 * no previous functions.
626 LLVMValueRef LLVMGetPreviousFunction(LLVMValueRef Fn);
633 * @defgroup LLVMCCoreType Types
635 * Types represent the type of a value.
637 * Types are associated with a context instance. The context internally
638 * deduplicates types so there is only 1 instance of a specific type
639 * alive at a time. In other words, a unique type is shared among all
640 * consumers within a context.
642 * A Type in the C API corresponds to llvm::Type.
644 * Types have the following hierarchy:
662 * Obtain the enumerated type of a Type instance.
664 * @see llvm::Type:getTypeID()
666 LLVMTypeKind LLVMGetTypeKind(LLVMTypeRef Ty);
669 * Whether the type has a known size.
671 * Things that don't have a size are abstract types, labels, and void.a
673 * @see llvm::Type::isSized()
675 LLVMBool LLVMTypeIsSized(LLVMTypeRef Ty);
678 * Obtain the context to which this type instance is associated.
680 * @see llvm::Type::getContext()
682 LLVMContextRef LLVMGetTypeContext(LLVMTypeRef Ty);
685 * Dump a representation of a type to stderr.
687 * @see llvm::Type::dump()
689 void LLVMDumpType(LLVMTypeRef Val);
692 * Return a string representation of the type. Use
693 * LLVMDisposeMessage to free the string.
695 * @see llvm::Type::print()
697 char *LLVMPrintTypeToString(LLVMTypeRef Val);
700 * @defgroup LLVMCCoreTypeInt Integer Types
702 * Functions in this section operate on integer types.
708 * Obtain an integer type from a context with specified bit width.
710 LLVMTypeRef LLVMInt1TypeInContext(LLVMContextRef C);
711 LLVMTypeRef LLVMInt8TypeInContext(LLVMContextRef C);
712 LLVMTypeRef LLVMInt16TypeInContext(LLVMContextRef C);
713 LLVMTypeRef LLVMInt32TypeInContext(LLVMContextRef C);
714 LLVMTypeRef LLVMInt64TypeInContext(LLVMContextRef C);
715 LLVMTypeRef LLVMInt128TypeInContext(LLVMContextRef C);
716 LLVMTypeRef LLVMIntTypeInContext(LLVMContextRef C, unsigned NumBits);
719 * Obtain an integer type from the global context with a specified bit
722 LLVMTypeRef LLVMInt1Type(void);
723 LLVMTypeRef LLVMInt8Type(void);
724 LLVMTypeRef LLVMInt16Type(void);
725 LLVMTypeRef LLVMInt32Type(void);
726 LLVMTypeRef LLVMInt64Type(void);
727 LLVMTypeRef LLVMInt128Type(void);
728 LLVMTypeRef LLVMIntType(unsigned NumBits);
729 unsigned LLVMGetIntTypeWidth(LLVMTypeRef IntegerTy);
736 * @defgroup LLVMCCoreTypeFloat Floating Point Types
742 * Obtain a 16-bit floating point type from a context.
744 LLVMTypeRef LLVMHalfTypeInContext(LLVMContextRef C);
747 * Obtain a 32-bit floating point type from a context.
749 LLVMTypeRef LLVMFloatTypeInContext(LLVMContextRef C);
752 * Obtain a 64-bit floating point type from a context.
754 LLVMTypeRef LLVMDoubleTypeInContext(LLVMContextRef C);
757 * Obtain a 80-bit floating point type (X87) from a context.
759 LLVMTypeRef LLVMX86FP80TypeInContext(LLVMContextRef C);
762 * Obtain a 128-bit floating point type (112-bit mantissa) from a
765 LLVMTypeRef LLVMFP128TypeInContext(LLVMContextRef C);
768 * Obtain a 128-bit floating point type (two 64-bits) from a context.
770 LLVMTypeRef LLVMPPCFP128TypeInContext(LLVMContextRef C);
773 * Obtain a floating point type from the global context.
775 * These map to the functions in this group of the same name.
777 LLVMTypeRef LLVMHalfType(void);
778 LLVMTypeRef LLVMFloatType(void);
779 LLVMTypeRef LLVMDoubleType(void);
780 LLVMTypeRef LLVMX86FP80Type(void);
781 LLVMTypeRef LLVMFP128Type(void);
782 LLVMTypeRef LLVMPPCFP128Type(void);
789 * @defgroup LLVMCCoreTypeFunction Function Types
795 * Obtain a function type consisting of a specified signature.
797 * The function is defined as a tuple of a return Type, a list of
798 * parameter types, and whether the function is variadic.
800 LLVMTypeRef LLVMFunctionType(LLVMTypeRef ReturnType,
801 LLVMTypeRef *ParamTypes, unsigned ParamCount,
805 * Returns whether a function type is variadic.
807 LLVMBool LLVMIsFunctionVarArg(LLVMTypeRef FunctionTy);
810 * Obtain the Type this function Type returns.
812 LLVMTypeRef LLVMGetReturnType(LLVMTypeRef FunctionTy);
815 * Obtain the number of parameters this function accepts.
817 unsigned LLVMCountParamTypes(LLVMTypeRef FunctionTy);
820 * Obtain the types of a function's parameters.
822 * The Dest parameter should point to a pre-allocated array of
823 * LLVMTypeRef at least LLVMCountParamTypes() large. On return, the
824 * first LLVMCountParamTypes() entries in the array will be populated
825 * with LLVMTypeRef instances.
827 * @param FunctionTy The function type to operate on.
828 * @param Dest Memory address of an array to be filled with result.
830 void LLVMGetParamTypes(LLVMTypeRef FunctionTy, LLVMTypeRef *Dest);
837 * @defgroup LLVMCCoreTypeStruct Structure Types
839 * These functions relate to LLVMTypeRef instances.
841 * @see llvm::StructType
847 * Create a new structure type in a context.
849 * A structure is specified by a list of inner elements/types and
850 * whether these can be packed together.
852 * @see llvm::StructType::create()
854 LLVMTypeRef LLVMStructTypeInContext(LLVMContextRef C, LLVMTypeRef *ElementTypes,
855 unsigned ElementCount, LLVMBool Packed);
858 * Create a new structure type in the global context.
860 * @see llvm::StructType::create()
862 LLVMTypeRef LLVMStructType(LLVMTypeRef *ElementTypes, unsigned ElementCount,
866 * Create an empty structure in a context having a specified name.
868 * @see llvm::StructType::create()
870 LLVMTypeRef LLVMStructCreateNamed(LLVMContextRef C, const char *Name);
873 * Obtain the name of a structure.
875 * @see llvm::StructType::getName()
877 const char *LLVMGetStructName(LLVMTypeRef Ty);
880 * Set the contents of a structure type.
882 * @see llvm::StructType::setBody()
884 void LLVMStructSetBody(LLVMTypeRef StructTy, LLVMTypeRef *ElementTypes,
885 unsigned ElementCount, LLVMBool Packed);
888 * Get the number of elements defined inside the structure.
890 * @see llvm::StructType::getNumElements()
892 unsigned LLVMCountStructElementTypes(LLVMTypeRef StructTy);
895 * Get the elements within a structure.
897 * The function is passed the address of a pre-allocated array of
898 * LLVMTypeRef at least LLVMCountStructElementTypes() long. After
899 * invocation, this array will be populated with the structure's
900 * elements. The objects in the destination array will have a lifetime
901 * of the structure type itself, which is the lifetime of the context it
904 void LLVMGetStructElementTypes(LLVMTypeRef StructTy, LLVMTypeRef *Dest);
907 * Get the type of the element at a given index in the structure.
909 * @see llvm::StructType::getTypeAtIndex()
911 LLVMTypeRef LLVMStructGetTypeAtIndex(LLVMTypeRef StructTy, unsigned i);
914 * Determine whether a structure is packed.
916 * @see llvm::StructType::isPacked()
918 LLVMBool LLVMIsPackedStruct(LLVMTypeRef StructTy);
921 * Determine whether a structure is opaque.
923 * @see llvm::StructType::isOpaque()
925 LLVMBool LLVMIsOpaqueStruct(LLVMTypeRef StructTy);
932 * @defgroup LLVMCCoreTypeSequential Sequential Types
934 * Sequential types represents "arrays" of types. This is a super class
935 * for array, vector, and pointer types.
941 * Obtain the type of elements within a sequential type.
943 * This works on array, vector, and pointer types.
945 * @see llvm::SequentialType::getElementType()
947 LLVMTypeRef LLVMGetElementType(LLVMTypeRef Ty);
950 * Create a fixed size array type that refers to a specific type.
952 * The created type will exist in the context that its element type
955 * @see llvm::ArrayType::get()
957 LLVMTypeRef LLVMArrayType(LLVMTypeRef ElementType, unsigned ElementCount);
960 * Obtain the length of an array type.
962 * This only works on types that represent arrays.
964 * @see llvm::ArrayType::getNumElements()
966 unsigned LLVMGetArrayLength(LLVMTypeRef ArrayTy);
969 * Create a pointer type that points to a defined type.
971 * The created type will exist in the context that its pointee type
974 * @see llvm::PointerType::get()
976 LLVMTypeRef LLVMPointerType(LLVMTypeRef ElementType, unsigned AddressSpace);
979 * Obtain the address space of a pointer type.
981 * This only works on types that represent pointers.
983 * @see llvm::PointerType::getAddressSpace()
985 unsigned LLVMGetPointerAddressSpace(LLVMTypeRef PointerTy);
988 * Create a vector type that contains a defined type and has a specific
989 * number of elements.
991 * The created type will exist in the context thats its element type
994 * @see llvm::VectorType::get()
996 LLVMTypeRef LLVMVectorType(LLVMTypeRef ElementType, unsigned ElementCount);
999 * Obtain the number of elements in a vector type.
1001 * This only works on types that represent vectors.
1003 * @see llvm::VectorType::getNumElements()
1005 unsigned LLVMGetVectorSize(LLVMTypeRef VectorTy);
1012 * @defgroup LLVMCCoreTypeOther Other Types
1018 * Create a void type in a context.
1020 LLVMTypeRef LLVMVoidTypeInContext(LLVMContextRef C);
1023 * Create a label type in a context.
1025 LLVMTypeRef LLVMLabelTypeInContext(LLVMContextRef C);
1028 * Create a X86 MMX type in a context.
1030 LLVMTypeRef LLVMX86MMXTypeInContext(LLVMContextRef C);
1033 * These are similar to the above functions except they operate on the
1036 LLVMTypeRef LLVMVoidType(void);
1037 LLVMTypeRef LLVMLabelType(void);
1038 LLVMTypeRef LLVMX86MMXType(void);
1049 * @defgroup LLVMCCoreValues Values
1051 * The bulk of LLVM's object model consists of values, which comprise a very
1052 * rich type hierarchy.
1054 * LLVMValueRef essentially represents llvm::Value. There is a rich
1055 * hierarchy of classes within this type. Depending on the instance
1056 * obtained, not all APIs are available.
1058 * Callers can determine the type of an LLVMValueRef by calling the
1059 * LLVMIsA* family of functions (e.g. LLVMIsAArgument()). These
1060 * functions are defined by a macro, so it isn't obvious which are
1061 * available by looking at the Doxygen source code. Instead, look at the
1062 * source definition of LLVM_FOR_EACH_VALUE_SUBCLASS and note the list
1063 * of value names given. These value names also correspond to classes in
1064 * the llvm::Value hierarchy.
1069 #define LLVM_FOR_EACH_VALUE_SUBCLASS(macro) \
1075 macro(BlockAddress) \
1076 macro(ConstantAggregateZero) \
1077 macro(ConstantArray) \
1078 macro(ConstantDataSequential) \
1079 macro(ConstantDataArray) \
1080 macro(ConstantDataVector) \
1081 macro(ConstantExpr) \
1083 macro(ConstantInt) \
1084 macro(ConstantPointerNull) \
1085 macro(ConstantStruct) \
1086 macro(ConstantTokenNone) \
1087 macro(ConstantVector) \
1088 macro(GlobalValue) \
1089 macro(GlobalAlias) \
1090 macro(GlobalObject) \
1092 macro(GlobalVariable) \
1094 macro(Instruction) \
1095 macro(BinaryOperator) \
1097 macro(IntrinsicInst) \
1098 macro(DbgInfoIntrinsic) \
1099 macro(DbgDeclareInst) \
1100 macro(MemIntrinsic) \
1102 macro(MemMoveInst) \
1107 macro(ExtractElementInst) \
1108 macro(GetElementPtrInst) \
1109 macro(InsertElementInst) \
1110 macro(InsertValueInst) \
1111 macro(LandingPadInst) \
1114 macro(ShuffleVectorInst) \
1116 macro(TerminatorInst) \
1118 macro(IndirectBrInst) \
1122 macro(UnreachableInst) \
1124 macro(CleanupReturnInst) \
1125 macro(CatchReturnInst) \
1126 macro(FuncletPadInst) \
1127 macro(CatchPadInst) \
1128 macro(CleanupPadInst) \
1129 macro(UnaryInstruction) \
1132 macro(AddrSpaceCastInst) \
1133 macro(BitCastInst) \
1137 macro(FPTruncInst) \
1138 macro(IntToPtrInst) \
1139 macro(PtrToIntInst) \
1145 macro(ExtractValueInst) \
1150 * @defgroup LLVMCCoreValueGeneral General APIs
1152 * Functions in this section work on all LLVMValueRef instances,
1153 * regardless of their sub-type. They correspond to functions available
1160 * Obtain the type of a value.
1162 * @see llvm::Value::getType()
1164 LLVMTypeRef LLVMTypeOf(LLVMValueRef Val);
1167 * Obtain the string name of a value.
1169 * @see llvm::Value::getName()
1171 const char *LLVMGetValueName(LLVMValueRef Val);
1174 * Set the string name of a value.
1176 * @see llvm::Value::setName()
1178 void LLVMSetValueName(LLVMValueRef Val, const char *Name);
1181 * Dump a representation of a value to stderr.
1183 * @see llvm::Value::dump()
1185 void LLVMDumpValue(LLVMValueRef Val);
1188 * Return a string representation of the value. Use
1189 * LLVMDisposeMessage to free the string.
1191 * @see llvm::Value::print()
1193 char *LLVMPrintValueToString(LLVMValueRef Val);
1196 * Replace all uses of a value with another one.
1198 * @see llvm::Value::replaceAllUsesWith()
1200 void LLVMReplaceAllUsesWith(LLVMValueRef OldVal, LLVMValueRef NewVal);
1203 * Determine whether the specified constant instance is constant.
1205 LLVMBool LLVMIsConstant(LLVMValueRef Val);
1208 * Determine whether a value instance is undefined.
1210 LLVMBool LLVMIsUndef(LLVMValueRef Val);
1213 * Convert value instances between types.
1215 * Internally, an LLVMValueRef is "pinned" to a specific type. This
1216 * series of functions allows you to cast an instance to a specific
1219 * If the cast is not valid for the specified type, NULL is returned.
1221 * @see llvm::dyn_cast_or_null<>
1223 #define LLVM_DECLARE_VALUE_CAST(name) \
1224 LLVMValueRef LLVMIsA##name(LLVMValueRef Val);
1225 LLVM_FOR_EACH_VALUE_SUBCLASS(LLVM_DECLARE_VALUE_CAST)
1227 LLVMValueRef LLVMIsAMDNode(LLVMValueRef Val);
1228 LLVMValueRef LLVMIsAMDString(LLVMValueRef Val);
1235 * @defgroup LLVMCCoreValueUses Usage
1237 * This module defines functions that allow you to inspect the uses of a
1240 * It is possible to obtain an LLVMUseRef for any LLVMValueRef instance.
1241 * Each LLVMUseRef (which corresponds to a llvm::Use instance) holds a
1242 * llvm::User and llvm::Value.
1248 * Obtain the first use of a value.
1250 * Uses are obtained in an iterator fashion. First, call this function
1251 * to obtain a reference to the first use. Then, call LLVMGetNextUse()
1252 * on that instance and all subsequently obtained instances until
1253 * LLVMGetNextUse() returns NULL.
1255 * @see llvm::Value::use_begin()
1257 LLVMUseRef LLVMGetFirstUse(LLVMValueRef Val);
1260 * Obtain the next use of a value.
1262 * This effectively advances the iterator. It returns NULL if you are on
1263 * the final use and no more are available.
1265 LLVMUseRef LLVMGetNextUse(LLVMUseRef U);
1268 * Obtain the user value for a user.
1270 * The returned value corresponds to a llvm::User type.
1272 * @see llvm::Use::getUser()
1274 LLVMValueRef LLVMGetUser(LLVMUseRef U);
1277 * Obtain the value this use corresponds to.
1279 * @see llvm::Use::get().
1281 LLVMValueRef LLVMGetUsedValue(LLVMUseRef U);
1288 * @defgroup LLVMCCoreValueUser User value
1290 * Function in this group pertain to LLVMValueRef instances that descent
1291 * from llvm::User. This includes constants, instructions, and
1298 * Obtain an operand at a specific index in a llvm::User value.
1300 * @see llvm::User::getOperand()
1302 LLVMValueRef LLVMGetOperand(LLVMValueRef Val, unsigned Index);
1305 * Obtain the use of an operand at a specific index in a llvm::User value.
1307 * @see llvm::User::getOperandUse()
1309 LLVMUseRef LLVMGetOperandUse(LLVMValueRef Val, unsigned Index);
1312 * Set an operand at a specific index in a llvm::User value.
1314 * @see llvm::User::setOperand()
1316 void LLVMSetOperand(LLVMValueRef User, unsigned Index, LLVMValueRef Val);
1319 * Obtain the number of operands in a llvm::User value.
1321 * @see llvm::User::getNumOperands()
1323 int LLVMGetNumOperands(LLVMValueRef Val);
1330 * @defgroup LLVMCCoreValueConstant Constants
1332 * This section contains APIs for interacting with LLVMValueRef that
1333 * correspond to llvm::Constant instances.
1335 * These functions will work for any LLVMValueRef in the llvm::Constant
1342 * Obtain a constant value referring to the null instance of a type.
1344 * @see llvm::Constant::getNullValue()
1346 LLVMValueRef LLVMConstNull(LLVMTypeRef Ty); /* all zeroes */
1349 * Obtain a constant value referring to the instance of a type
1350 * consisting of all ones.
1352 * This is only valid for integer types.
1354 * @see llvm::Constant::getAllOnesValue()
1356 LLVMValueRef LLVMConstAllOnes(LLVMTypeRef Ty);
1359 * Obtain a constant value referring to an undefined value of a type.
1361 * @see llvm::UndefValue::get()
1363 LLVMValueRef LLVMGetUndef(LLVMTypeRef Ty);
1366 * Determine whether a value instance is null.
1368 * @see llvm::Constant::isNullValue()
1370 LLVMBool LLVMIsNull(LLVMValueRef Val);
1373 * Obtain a constant that is a constant pointer pointing to NULL for a
1376 LLVMValueRef LLVMConstPointerNull(LLVMTypeRef Ty);
1379 * @defgroup LLVMCCoreValueConstantScalar Scalar constants
1381 * Functions in this group model LLVMValueRef instances that correspond
1382 * to constants referring to scalar types.
1384 * For integer types, the LLVMTypeRef parameter should correspond to a
1385 * llvm::IntegerType instance and the returned LLVMValueRef will
1386 * correspond to a llvm::ConstantInt.
1388 * For floating point types, the LLVMTypeRef returned corresponds to a
1395 * Obtain a constant value for an integer type.
1397 * The returned value corresponds to a llvm::ConstantInt.
1399 * @see llvm::ConstantInt::get()
1401 * @param IntTy Integer type to obtain value of.
1402 * @param N The value the returned instance should refer to.
1403 * @param SignExtend Whether to sign extend the produced value.
1405 LLVMValueRef LLVMConstInt(LLVMTypeRef IntTy, unsigned long long N,
1406 LLVMBool SignExtend);
1409 * Obtain a constant value for an integer of arbitrary precision.
1411 * @see llvm::ConstantInt::get()
1413 LLVMValueRef LLVMConstIntOfArbitraryPrecision(LLVMTypeRef IntTy,
1415 const uint64_t Words[]);
1418 * Obtain a constant value for an integer parsed from a string.
1420 * A similar API, LLVMConstIntOfStringAndSize is also available. If the
1421 * string's length is available, it is preferred to call that function
1424 * @see llvm::ConstantInt::get()
1426 LLVMValueRef LLVMConstIntOfString(LLVMTypeRef IntTy, const char *Text,
1430 * Obtain a constant value for an integer parsed from a string with
1433 * @see llvm::ConstantInt::get()
1435 LLVMValueRef LLVMConstIntOfStringAndSize(LLVMTypeRef IntTy, const char *Text,
1436 unsigned SLen, uint8_t Radix);
1439 * Obtain a constant value referring to a double floating point value.
1441 LLVMValueRef LLVMConstReal(LLVMTypeRef RealTy, double N);
1444 * Obtain a constant for a floating point value parsed from a string.
1446 * A similar API, LLVMConstRealOfStringAndSize is also available. It
1447 * should be used if the input string's length is known.
1449 LLVMValueRef LLVMConstRealOfString(LLVMTypeRef RealTy, const char *Text);
1452 * Obtain a constant for a floating point value parsed from a string.
1454 LLVMValueRef LLVMConstRealOfStringAndSize(LLVMTypeRef RealTy, const char *Text,
1458 * Obtain the zero extended value for an integer constant value.
1460 * @see llvm::ConstantInt::getZExtValue()
1462 unsigned long long LLVMConstIntGetZExtValue(LLVMValueRef ConstantVal);
1465 * Obtain the sign extended value for an integer constant value.
1467 * @see llvm::ConstantInt::getSExtValue()
1469 long long LLVMConstIntGetSExtValue(LLVMValueRef ConstantVal);
1472 * Obtain the double value for an floating point constant value.
1473 * losesInfo indicates if some precision was lost in the conversion.
1475 * @see llvm::ConstantFP::getDoubleValue
1477 double LLVMConstRealGetDouble(LLVMValueRef ConstantVal, LLVMBool *losesInfo);
1484 * @defgroup LLVMCCoreValueConstantComposite Composite Constants
1486 * Functions in this group operate on composite constants.
1492 * Create a ConstantDataSequential and initialize it with a string.
1494 * @see llvm::ConstantDataArray::getString()
1496 LLVMValueRef LLVMConstStringInContext(LLVMContextRef C, const char *Str,
1497 unsigned Length, LLVMBool DontNullTerminate);
1500 * Create a ConstantDataSequential with string content in the global context.
1502 * This is the same as LLVMConstStringInContext except it operates on the
1505 * @see LLVMConstStringInContext()
1506 * @see llvm::ConstantDataArray::getString()
1508 LLVMValueRef LLVMConstString(const char *Str, unsigned Length,
1509 LLVMBool DontNullTerminate);
1512 * Returns true if the specified constant is an array of i8.
1514 * @see ConstantDataSequential::getAsString()
1516 LLVMBool LLVMIsConstantString(LLVMValueRef c);
1519 * Get the given constant data sequential as a string.
1521 * @see ConstantDataSequential::getAsString()
1523 const char *LLVMGetAsString(LLVMValueRef c, size_t* out);
1526 * Create an anonymous ConstantStruct with the specified values.
1528 * @see llvm::ConstantStruct::getAnon()
1530 LLVMValueRef LLVMConstStructInContext(LLVMContextRef C,
1531 LLVMValueRef *ConstantVals,
1532 unsigned Count, LLVMBool Packed);
1535 * Create a ConstantStruct in the global Context.
1537 * This is the same as LLVMConstStructInContext except it operates on the
1540 * @see LLVMConstStructInContext()
1542 LLVMValueRef LLVMConstStruct(LLVMValueRef *ConstantVals, unsigned Count,
1546 * Create a ConstantArray from values.
1548 * @see llvm::ConstantArray::get()
1550 LLVMValueRef LLVMConstArray(LLVMTypeRef ElementTy,
1551 LLVMValueRef *ConstantVals, unsigned Length);
1554 * Create a non-anonymous ConstantStruct from values.
1556 * @see llvm::ConstantStruct::get()
1558 LLVMValueRef LLVMConstNamedStruct(LLVMTypeRef StructTy,
1559 LLVMValueRef *ConstantVals,
1563 * Get an element at specified index as a constant.
1565 * @see ConstantDataSequential::getElementAsConstant()
1567 LLVMValueRef LLVMGetElementAsConstant(LLVMValueRef c, unsigned idx);
1570 * Create a ConstantVector from values.
1572 * @see llvm::ConstantVector::get()
1574 LLVMValueRef LLVMConstVector(LLVMValueRef *ScalarConstantVals, unsigned Size);
1581 * @defgroup LLVMCCoreValueConstantExpressions Constant Expressions
1583 * Functions in this group correspond to APIs on llvm::ConstantExpr.
1585 * @see llvm::ConstantExpr.
1589 LLVMOpcode LLVMGetConstOpcode(LLVMValueRef ConstantVal);
1590 LLVMValueRef LLVMAlignOf(LLVMTypeRef Ty);
1591 LLVMValueRef LLVMSizeOf(LLVMTypeRef Ty);
1592 LLVMValueRef LLVMConstNeg(LLVMValueRef ConstantVal);
1593 LLVMValueRef LLVMConstNSWNeg(LLVMValueRef ConstantVal);
1594 LLVMValueRef LLVMConstNUWNeg(LLVMValueRef ConstantVal);
1595 LLVMValueRef LLVMConstFNeg(LLVMValueRef ConstantVal);
1596 LLVMValueRef LLVMConstNot(LLVMValueRef ConstantVal);
1597 LLVMValueRef LLVMConstAdd(LLVMValueRef LHSConstant, LLVMValueRef RHSConstant);
1598 LLVMValueRef LLVMConstNSWAdd(LLVMValueRef LHSConstant, LLVMValueRef RHSConstant);
1599 LLVMValueRef LLVMConstNUWAdd(LLVMValueRef LHSConstant, LLVMValueRef RHSConstant);
1600 LLVMValueRef LLVMConstFAdd(LLVMValueRef LHSConstant, LLVMValueRef RHSConstant);
1601 LLVMValueRef LLVMConstSub(LLVMValueRef LHSConstant, LLVMValueRef RHSConstant);
1602 LLVMValueRef LLVMConstNSWSub(LLVMValueRef LHSConstant, LLVMValueRef RHSConstant);
1603 LLVMValueRef LLVMConstNUWSub(LLVMValueRef LHSConstant, LLVMValueRef RHSConstant);
1604 LLVMValueRef LLVMConstFSub(LLVMValueRef LHSConstant, LLVMValueRef RHSConstant);
1605 LLVMValueRef LLVMConstMul(LLVMValueRef LHSConstant, LLVMValueRef RHSConstant);
1606 LLVMValueRef LLVMConstNSWMul(LLVMValueRef LHSConstant, LLVMValueRef RHSConstant);
1607 LLVMValueRef LLVMConstNUWMul(LLVMValueRef LHSConstant, LLVMValueRef RHSConstant);
1608 LLVMValueRef LLVMConstFMul(LLVMValueRef LHSConstant, LLVMValueRef RHSConstant);
1609 LLVMValueRef LLVMConstUDiv(LLVMValueRef LHSConstant, LLVMValueRef RHSConstant);
1610 LLVMValueRef LLVMConstSDiv(LLVMValueRef LHSConstant, LLVMValueRef RHSConstant);
1611 LLVMValueRef LLVMConstExactSDiv(LLVMValueRef LHSConstant, LLVMValueRef RHSConstant);
1612 LLVMValueRef LLVMConstFDiv(LLVMValueRef LHSConstant, LLVMValueRef RHSConstant);
1613 LLVMValueRef LLVMConstURem(LLVMValueRef LHSConstant, LLVMValueRef RHSConstant);
1614 LLVMValueRef LLVMConstSRem(LLVMValueRef LHSConstant, LLVMValueRef RHSConstant);
1615 LLVMValueRef LLVMConstFRem(LLVMValueRef LHSConstant, LLVMValueRef RHSConstant);
1616 LLVMValueRef LLVMConstAnd(LLVMValueRef LHSConstant, LLVMValueRef RHSConstant);
1617 LLVMValueRef LLVMConstOr(LLVMValueRef LHSConstant, LLVMValueRef RHSConstant);
1618 LLVMValueRef LLVMConstXor(LLVMValueRef LHSConstant, LLVMValueRef RHSConstant);
1619 LLVMValueRef LLVMConstICmp(LLVMIntPredicate Predicate,
1620 LLVMValueRef LHSConstant, LLVMValueRef RHSConstant);
1621 LLVMValueRef LLVMConstFCmp(LLVMRealPredicate Predicate,
1622 LLVMValueRef LHSConstant, LLVMValueRef RHSConstant);
1623 LLVMValueRef LLVMConstShl(LLVMValueRef LHSConstant, LLVMValueRef RHSConstant);
1624 LLVMValueRef LLVMConstLShr(LLVMValueRef LHSConstant, LLVMValueRef RHSConstant);
1625 LLVMValueRef LLVMConstAShr(LLVMValueRef LHSConstant, LLVMValueRef RHSConstant);
1626 LLVMValueRef LLVMConstGEP(LLVMValueRef ConstantVal,
1627 LLVMValueRef *ConstantIndices, unsigned NumIndices);
1628 LLVMValueRef LLVMConstInBoundsGEP(LLVMValueRef ConstantVal,
1629 LLVMValueRef *ConstantIndices,
1630 unsigned NumIndices);
1631 LLVMValueRef LLVMConstTrunc(LLVMValueRef ConstantVal, LLVMTypeRef ToType);
1632 LLVMValueRef LLVMConstSExt(LLVMValueRef ConstantVal, LLVMTypeRef ToType);
1633 LLVMValueRef LLVMConstZExt(LLVMValueRef ConstantVal, LLVMTypeRef ToType);
1634 LLVMValueRef LLVMConstFPTrunc(LLVMValueRef ConstantVal, LLVMTypeRef ToType);
1635 LLVMValueRef LLVMConstFPExt(LLVMValueRef ConstantVal, LLVMTypeRef ToType);
1636 LLVMValueRef LLVMConstUIToFP(LLVMValueRef ConstantVal, LLVMTypeRef ToType);
1637 LLVMValueRef LLVMConstSIToFP(LLVMValueRef ConstantVal, LLVMTypeRef ToType);
1638 LLVMValueRef LLVMConstFPToUI(LLVMValueRef ConstantVal, LLVMTypeRef ToType);
1639 LLVMValueRef LLVMConstFPToSI(LLVMValueRef ConstantVal, LLVMTypeRef ToType);
1640 LLVMValueRef LLVMConstPtrToInt(LLVMValueRef ConstantVal, LLVMTypeRef ToType);
1641 LLVMValueRef LLVMConstIntToPtr(LLVMValueRef ConstantVal, LLVMTypeRef ToType);
1642 LLVMValueRef LLVMConstBitCast(LLVMValueRef ConstantVal, LLVMTypeRef ToType);
1643 LLVMValueRef LLVMConstAddrSpaceCast(LLVMValueRef ConstantVal, LLVMTypeRef ToType);
1644 LLVMValueRef LLVMConstZExtOrBitCast(LLVMValueRef ConstantVal,
1645 LLVMTypeRef ToType);
1646 LLVMValueRef LLVMConstSExtOrBitCast(LLVMValueRef ConstantVal,
1647 LLVMTypeRef ToType);
1648 LLVMValueRef LLVMConstTruncOrBitCast(LLVMValueRef ConstantVal,
1649 LLVMTypeRef ToType);
1650 LLVMValueRef LLVMConstPointerCast(LLVMValueRef ConstantVal,
1651 LLVMTypeRef ToType);
1652 LLVMValueRef LLVMConstIntCast(LLVMValueRef ConstantVal, LLVMTypeRef ToType,
1654 LLVMValueRef LLVMConstFPCast(LLVMValueRef ConstantVal, LLVMTypeRef ToType);
1655 LLVMValueRef LLVMConstSelect(LLVMValueRef ConstantCondition,
1656 LLVMValueRef ConstantIfTrue,
1657 LLVMValueRef ConstantIfFalse);
1658 LLVMValueRef LLVMConstExtractElement(LLVMValueRef VectorConstant,
1659 LLVMValueRef IndexConstant);
1660 LLVMValueRef LLVMConstInsertElement(LLVMValueRef VectorConstant,
1661 LLVMValueRef ElementValueConstant,
1662 LLVMValueRef IndexConstant);
1663 LLVMValueRef LLVMConstShuffleVector(LLVMValueRef VectorAConstant,
1664 LLVMValueRef VectorBConstant,
1665 LLVMValueRef MaskConstant);
1666 LLVMValueRef LLVMConstExtractValue(LLVMValueRef AggConstant, unsigned *IdxList,
1668 LLVMValueRef LLVMConstInsertValue(LLVMValueRef AggConstant,
1669 LLVMValueRef ElementValueConstant,
1670 unsigned *IdxList, unsigned NumIdx);
1671 LLVMValueRef LLVMConstInlineAsm(LLVMTypeRef Ty,
1672 const char *AsmString, const char *Constraints,
1673 LLVMBool HasSideEffects, LLVMBool IsAlignStack);
1674 LLVMValueRef LLVMBlockAddress(LLVMValueRef F, LLVMBasicBlockRef BB);
1681 * @defgroup LLVMCCoreValueConstantGlobals Global Values
1683 * This group contains functions that operate on global values. Functions in
1684 * this group relate to functions in the llvm::GlobalValue class tree.
1686 * @see llvm::GlobalValue
1691 LLVMModuleRef LLVMGetGlobalParent(LLVMValueRef Global);
1692 LLVMBool LLVMIsDeclaration(LLVMValueRef Global);
1693 LLVMLinkage LLVMGetLinkage(LLVMValueRef Global);
1694 void LLVMSetLinkage(LLVMValueRef Global, LLVMLinkage Linkage);
1695 const char *LLVMGetSection(LLVMValueRef Global);
1696 void LLVMSetSection(LLVMValueRef Global, const char *Section);
1697 LLVMVisibility LLVMGetVisibility(LLVMValueRef Global);
1698 void LLVMSetVisibility(LLVMValueRef Global, LLVMVisibility Viz);
1699 LLVMDLLStorageClass LLVMGetDLLStorageClass(LLVMValueRef Global);
1700 void LLVMSetDLLStorageClass(LLVMValueRef Global, LLVMDLLStorageClass Class);
1701 LLVMBool LLVMHasUnnamedAddr(LLVMValueRef Global);
1702 void LLVMSetUnnamedAddr(LLVMValueRef Global, LLVMBool HasUnnamedAddr);
1705 * @defgroup LLVMCCoreValueWithAlignment Values with alignment
1707 * Functions in this group only apply to values with alignment, i.e.
1708 * global variables, load and store instructions.
1712 * Obtain the preferred alignment of the value.
1713 * @see llvm::AllocaInst::getAlignment()
1714 * @see llvm::LoadInst::getAlignment()
1715 * @see llvm::StoreInst::getAlignment()
1716 * @see llvm::GlobalValue::getAlignment()
1718 unsigned LLVMGetAlignment(LLVMValueRef V);
1721 * Set the preferred alignment of the value.
1722 * @see llvm::AllocaInst::setAlignment()
1723 * @see llvm::LoadInst::setAlignment()
1724 * @see llvm::StoreInst::setAlignment()
1725 * @see llvm::GlobalValue::setAlignment()
1727 void LLVMSetAlignment(LLVMValueRef V, unsigned Bytes);
1734 * @defgroup LLVMCoreValueConstantGlobalVariable Global Variables
1736 * This group contains functions that operate on global variable values.
1738 * @see llvm::GlobalVariable
1742 LLVMValueRef LLVMAddGlobal(LLVMModuleRef M, LLVMTypeRef Ty, const char *Name);
1743 LLVMValueRef LLVMAddGlobalInAddressSpace(LLVMModuleRef M, LLVMTypeRef Ty,
1745 unsigned AddressSpace);
1746 LLVMValueRef LLVMGetNamedGlobal(LLVMModuleRef M, const char *Name);
1747 LLVMValueRef LLVMGetFirstGlobal(LLVMModuleRef M);
1748 LLVMValueRef LLVMGetLastGlobal(LLVMModuleRef M);
1749 LLVMValueRef LLVMGetNextGlobal(LLVMValueRef GlobalVar);
1750 LLVMValueRef LLVMGetPreviousGlobal(LLVMValueRef GlobalVar);
1751 void LLVMDeleteGlobal(LLVMValueRef GlobalVar);
1752 LLVMValueRef LLVMGetInitializer(LLVMValueRef GlobalVar);
1753 void LLVMSetInitializer(LLVMValueRef GlobalVar, LLVMValueRef ConstantVal);
1754 LLVMBool LLVMIsThreadLocal(LLVMValueRef GlobalVar);
1755 void LLVMSetThreadLocal(LLVMValueRef GlobalVar, LLVMBool IsThreadLocal);
1756 LLVMBool LLVMIsGlobalConstant(LLVMValueRef GlobalVar);
1757 void LLVMSetGlobalConstant(LLVMValueRef GlobalVar, LLVMBool IsConstant);
1758 LLVMThreadLocalMode LLVMGetThreadLocalMode(LLVMValueRef GlobalVar);
1759 void LLVMSetThreadLocalMode(LLVMValueRef GlobalVar, LLVMThreadLocalMode Mode);
1760 LLVMBool LLVMIsExternallyInitialized(LLVMValueRef GlobalVar);
1761 void LLVMSetExternallyInitialized(LLVMValueRef GlobalVar, LLVMBool IsExtInit);
1768 * @defgroup LLVMCoreValueConstantGlobalAlias Global Aliases
1770 * This group contains function that operate on global alias values.
1772 * @see llvm::GlobalAlias
1776 LLVMValueRef LLVMAddAlias(LLVMModuleRef M, LLVMTypeRef Ty, LLVMValueRef Aliasee,
1784 * @defgroup LLVMCCoreValueFunction Function values
1786 * Functions in this group operate on LLVMValueRef instances that
1787 * correspond to llvm::Function instances.
1789 * @see llvm::Function
1795 * Remove a function from its containing module and deletes it.
1797 * @see llvm::Function::eraseFromParent()
1799 void LLVMDeleteFunction(LLVMValueRef Fn);
1802 * Obtain the personality function attached to the function.
1804 * @see llvm::Function::getPersonalityFn()
1806 LLVMValueRef LLVMGetPersonalityFn(LLVMValueRef Fn);
1809 * Set the personality function attached to the function.
1811 * @see llvm::Function::setPersonalityFn()
1813 void LLVMSetPersonalityFn(LLVMValueRef Fn, LLVMValueRef PersonalityFn);
1816 * Obtain the ID number from a function instance.
1818 * @see llvm::Function::getIntrinsicID()
1820 unsigned LLVMGetIntrinsicID(LLVMValueRef Fn);
1823 * Obtain the calling function of a function.
1825 * The returned value corresponds to the LLVMCallConv enumeration.
1827 * @see llvm::Function::getCallingConv()
1829 unsigned LLVMGetFunctionCallConv(LLVMValueRef Fn);
1832 * Set the calling convention of a function.
1834 * @see llvm::Function::setCallingConv()
1836 * @param Fn Function to operate on
1837 * @param CC LLVMCallConv to set calling convention to
1839 void LLVMSetFunctionCallConv(LLVMValueRef Fn, unsigned CC);
1842 * Obtain the name of the garbage collector to use during code
1845 * @see llvm::Function::getGC()
1847 const char *LLVMGetGC(LLVMValueRef Fn);
1850 * Define the garbage collector to use during code generation.
1852 * @see llvm::Function::setGC()
1854 void LLVMSetGC(LLVMValueRef Fn, const char *Name);
1857 * Add an attribute to a function.
1859 * @see llvm::Function::addAttribute()
1861 void LLVMAddFunctionAttr(LLVMValueRef Fn, LLVMAttribute PA);
1864 * Add a target-dependent attribute to a function
1865 * @see llvm::AttrBuilder::addAttribute()
1867 void LLVMAddTargetDependentFunctionAttr(LLVMValueRef Fn, const char *A,
1871 * Obtain an attribute from a function.
1873 * @see llvm::Function::getAttributes()
1875 LLVMAttribute LLVMGetFunctionAttr(LLVMValueRef Fn);
1878 * Remove an attribute from a function.
1880 void LLVMRemoveFunctionAttr(LLVMValueRef Fn, LLVMAttribute PA);
1883 * @defgroup LLVMCCoreValueFunctionParameters Function Parameters
1885 * Functions in this group relate to arguments/parameters on functions.
1887 * Functions in this group expect LLVMValueRef instances that correspond
1888 * to llvm::Function instances.
1894 * Obtain the number of parameters in a function.
1896 * @see llvm::Function::arg_size()
1898 unsigned LLVMCountParams(LLVMValueRef Fn);
1901 * Obtain the parameters in a function.
1903 * The takes a pointer to a pre-allocated array of LLVMValueRef that is
1904 * at least LLVMCountParams() long. This array will be filled with
1905 * LLVMValueRef instances which correspond to the parameters the
1906 * function receives. Each LLVMValueRef corresponds to a llvm::Argument
1909 * @see llvm::Function::arg_begin()
1911 void LLVMGetParams(LLVMValueRef Fn, LLVMValueRef *Params);
1914 * Obtain the parameter at the specified index.
1916 * Parameters are indexed from 0.
1918 * @see llvm::Function::arg_begin()
1920 LLVMValueRef LLVMGetParam(LLVMValueRef Fn, unsigned Index);
1923 * Obtain the function to which this argument belongs.
1925 * Unlike other functions in this group, this one takes an LLVMValueRef
1926 * that corresponds to a llvm::Attribute.
1928 * The returned LLVMValueRef is the llvm::Function to which this
1931 LLVMValueRef LLVMGetParamParent(LLVMValueRef Inst);
1934 * Obtain the first parameter to a function.
1936 * @see llvm::Function::arg_begin()
1938 LLVMValueRef LLVMGetFirstParam(LLVMValueRef Fn);
1941 * Obtain the last parameter to a function.
1943 * @see llvm::Function::arg_end()
1945 LLVMValueRef LLVMGetLastParam(LLVMValueRef Fn);
1948 * Obtain the next parameter to a function.
1950 * This takes an LLVMValueRef obtained from LLVMGetFirstParam() (which is
1951 * actually a wrapped iterator) and obtains the next parameter from the
1952 * underlying iterator.
1954 LLVMValueRef LLVMGetNextParam(LLVMValueRef Arg);
1957 * Obtain the previous parameter to a function.
1959 * This is the opposite of LLVMGetNextParam().
1961 LLVMValueRef LLVMGetPreviousParam(LLVMValueRef Arg);
1964 * Add an attribute to a function argument.
1966 * @see llvm::Argument::addAttr()
1968 void LLVMAddAttribute(LLVMValueRef Arg, LLVMAttribute PA);
1971 * Remove an attribute from a function argument.
1973 * @see llvm::Argument::removeAttr()
1975 void LLVMRemoveAttribute(LLVMValueRef Arg, LLVMAttribute PA);
1978 * Get an attribute from a function argument.
1980 LLVMAttribute LLVMGetAttribute(LLVMValueRef Arg);
1983 * Set the alignment for a function parameter.
1985 * @see llvm::Argument::addAttr()
1986 * @see llvm::AttrBuilder::addAlignmentAttr()
1988 void LLVMSetParamAlignment(LLVMValueRef Arg, unsigned align);
2007 * @defgroup LLVMCCoreValueMetadata Metadata
2013 * Obtain a MDString value from a context.
2015 * The returned instance corresponds to the llvm::MDString class.
2017 * The instance is specified by string data of a specified length. The
2018 * string content is copied, so the backing memory can be freed after
2019 * this function returns.
2021 LLVMValueRef LLVMMDStringInContext(LLVMContextRef C, const char *Str,
2025 * Obtain a MDString value from the global context.
2027 LLVMValueRef LLVMMDString(const char *Str, unsigned SLen);
2030 * Obtain a MDNode value from a context.
2032 * The returned value corresponds to the llvm::MDNode class.
2034 LLVMValueRef LLVMMDNodeInContext(LLVMContextRef C, LLVMValueRef *Vals,
2038 * Obtain a MDNode value from the global context.
2040 LLVMValueRef LLVMMDNode(LLVMValueRef *Vals, unsigned Count);
2043 * Obtain the underlying string from a MDString value.
2045 * @param V Instance to obtain string from.
2046 * @param Len Memory address which will hold length of returned string.
2047 * @return String data in MDString.
2049 const char *LLVMGetMDString(LLVMValueRef V, unsigned* Len);
2052 * Obtain the number of operands from an MDNode value.
2054 * @param V MDNode to get number of operands from.
2055 * @return Number of operands of the MDNode.
2057 unsigned LLVMGetMDNodeNumOperands(LLVMValueRef V);
2060 * Obtain the given MDNode's operands.
2062 * The passed LLVMValueRef pointer should point to enough memory to hold all of
2063 * the operands of the given MDNode (see LLVMGetMDNodeNumOperands) as
2064 * LLVMValueRefs. This memory will be populated with the LLVMValueRefs of the
2065 * MDNode's operands.
2067 * @param V MDNode to get the operands from.
2068 * @param Dest Destination array for operands.
2070 void LLVMGetMDNodeOperands(LLVMValueRef V, LLVMValueRef *Dest);
2077 * @defgroup LLVMCCoreValueBasicBlock Basic Block
2079 * A basic block represents a single entry single exit section of code.
2080 * Basic blocks contain a list of instructions which form the body of
2083 * Basic blocks belong to functions. They have the type of label.
2085 * Basic blocks are themselves values. However, the C API models them as
2086 * LLVMBasicBlockRef.
2088 * @see llvm::BasicBlock
2094 * Convert a basic block instance to a value type.
2096 LLVMValueRef LLVMBasicBlockAsValue(LLVMBasicBlockRef BB);
2099 * Determine whether an LLVMValueRef is itself a basic block.
2101 LLVMBool LLVMValueIsBasicBlock(LLVMValueRef Val);
2104 * Convert an LLVMValueRef to an LLVMBasicBlockRef instance.
2106 LLVMBasicBlockRef LLVMValueAsBasicBlock(LLVMValueRef Val);
2109 * Obtain the function to which a basic block belongs.
2111 * @see llvm::BasicBlock::getParent()
2113 LLVMValueRef LLVMGetBasicBlockParent(LLVMBasicBlockRef BB);
2116 * Obtain the terminator instruction for a basic block.
2118 * If the basic block does not have a terminator (it is not well-formed
2119 * if it doesn't), then NULL is returned.
2121 * The returned LLVMValueRef corresponds to a llvm::TerminatorInst.
2123 * @see llvm::BasicBlock::getTerminator()
2125 LLVMValueRef LLVMGetBasicBlockTerminator(LLVMBasicBlockRef BB);
2128 * Obtain the number of basic blocks in a function.
2130 * @param Fn Function value to operate on.
2132 unsigned LLVMCountBasicBlocks(LLVMValueRef Fn);
2135 * Obtain all of the basic blocks in a function.
2137 * This operates on a function value. The BasicBlocks parameter is a
2138 * pointer to a pre-allocated array of LLVMBasicBlockRef of at least
2139 * LLVMCountBasicBlocks() in length. This array is populated with
2140 * LLVMBasicBlockRef instances.
2142 void LLVMGetBasicBlocks(LLVMValueRef Fn, LLVMBasicBlockRef *BasicBlocks);
2145 * Obtain the first basic block in a function.
2147 * The returned basic block can be used as an iterator. You will likely
2148 * eventually call into LLVMGetNextBasicBlock() with it.
2150 * @see llvm::Function::begin()
2152 LLVMBasicBlockRef LLVMGetFirstBasicBlock(LLVMValueRef Fn);
2155 * Obtain the last basic block in a function.
2157 * @see llvm::Function::end()
2159 LLVMBasicBlockRef LLVMGetLastBasicBlock(LLVMValueRef Fn);
2162 * Advance a basic block iterator.
2164 LLVMBasicBlockRef LLVMGetNextBasicBlock(LLVMBasicBlockRef BB);
2167 * Go backwards in a basic block iterator.
2169 LLVMBasicBlockRef LLVMGetPreviousBasicBlock(LLVMBasicBlockRef BB);
2172 * Obtain the basic block that corresponds to the entry point of a
2175 * @see llvm::Function::getEntryBlock()
2177 LLVMBasicBlockRef LLVMGetEntryBasicBlock(LLVMValueRef Fn);
2180 * Append a basic block to the end of a function.
2182 * @see llvm::BasicBlock::Create()
2184 LLVMBasicBlockRef LLVMAppendBasicBlockInContext(LLVMContextRef C,
2189 * Append a basic block to the end of a function using the global
2192 * @see llvm::BasicBlock::Create()
2194 LLVMBasicBlockRef LLVMAppendBasicBlock(LLVMValueRef Fn, const char *Name);
2197 * Insert a basic block in a function before another basic block.
2199 * The function to add to is determined by the function of the
2200 * passed basic block.
2202 * @see llvm::BasicBlock::Create()
2204 LLVMBasicBlockRef LLVMInsertBasicBlockInContext(LLVMContextRef C,
2205 LLVMBasicBlockRef BB,
2209 * Insert a basic block in a function using the global context.
2211 * @see llvm::BasicBlock::Create()
2213 LLVMBasicBlockRef LLVMInsertBasicBlock(LLVMBasicBlockRef InsertBeforeBB,
2217 * Remove a basic block from a function and delete it.
2219 * This deletes the basic block from its containing function and deletes
2220 * the basic block itself.
2222 * @see llvm::BasicBlock::eraseFromParent()
2224 void LLVMDeleteBasicBlock(LLVMBasicBlockRef BB);
2227 * Remove a basic block from a function.
2229 * This deletes the basic block from its containing function but keep
2230 * the basic block alive.
2232 * @see llvm::BasicBlock::removeFromParent()
2234 void LLVMRemoveBasicBlockFromParent(LLVMBasicBlockRef BB);
2237 * Move a basic block to before another one.
2239 * @see llvm::BasicBlock::moveBefore()
2241 void LLVMMoveBasicBlockBefore(LLVMBasicBlockRef BB, LLVMBasicBlockRef MovePos);
2244 * Move a basic block to after another one.
2246 * @see llvm::BasicBlock::moveAfter()
2248 void LLVMMoveBasicBlockAfter(LLVMBasicBlockRef BB, LLVMBasicBlockRef MovePos);
2251 * Obtain the first instruction in a basic block.
2253 * The returned LLVMValueRef corresponds to a llvm::Instruction
2256 LLVMValueRef LLVMGetFirstInstruction(LLVMBasicBlockRef BB);
2259 * Obtain the last instruction in a basic block.
2261 * The returned LLVMValueRef corresponds to an LLVM:Instruction.
2263 LLVMValueRef LLVMGetLastInstruction(LLVMBasicBlockRef BB);
2270 * @defgroup LLVMCCoreValueInstruction Instructions
2272 * Functions in this group relate to the inspection and manipulation of
2273 * individual instructions.
2275 * In the C++ API, an instruction is modeled by llvm::Instruction. This
2276 * class has a large number of descendents. llvm::Instruction is a
2277 * llvm::Value and in the C API, instructions are modeled by
2280 * This group also contains sub-groups which operate on specific
2281 * llvm::Instruction types, e.g. llvm::CallInst.
2287 * Determine whether an instruction has any metadata attached.
2289 int LLVMHasMetadata(LLVMValueRef Val);
2292 * Return metadata associated with an instruction value.
2294 LLVMValueRef LLVMGetMetadata(LLVMValueRef Val, unsigned KindID);
2297 * Set metadata associated with an instruction value.
2299 void LLVMSetMetadata(LLVMValueRef Val, unsigned KindID, LLVMValueRef Node);
2302 * Obtain the basic block to which an instruction belongs.
2304 * @see llvm::Instruction::getParent()
2306 LLVMBasicBlockRef LLVMGetInstructionParent(LLVMValueRef Inst);
2309 * Obtain the instruction that occurs after the one specified.
2311 * The next instruction will be from the same basic block.
2313 * If this is the last instruction in a basic block, NULL will be
2316 LLVMValueRef LLVMGetNextInstruction(LLVMValueRef Inst);
2319 * Obtain the instruction that occurred before this one.
2321 * If the instruction is the first instruction in a basic block, NULL
2324 LLVMValueRef LLVMGetPreviousInstruction(LLVMValueRef Inst);
2327 * Remove and delete an instruction.
2329 * The instruction specified is removed from its containing building
2330 * block and then deleted.
2332 * @see llvm::Instruction::eraseFromParent()
2334 void LLVMInstructionEraseFromParent(LLVMValueRef Inst);
2337 * Obtain the code opcode for an individual instruction.
2339 * @see llvm::Instruction::getOpCode()
2341 LLVMOpcode LLVMGetInstructionOpcode(LLVMValueRef Inst);
2344 * Obtain the predicate of an instruction.
2346 * This is only valid for instructions that correspond to llvm::ICmpInst
2347 * or llvm::ConstantExpr whose opcode is llvm::Instruction::ICmp.
2349 * @see llvm::ICmpInst::getPredicate()
2351 LLVMIntPredicate LLVMGetICmpPredicate(LLVMValueRef Inst);
2354 * Obtain the float predicate of an instruction.
2356 * This is only valid for instructions that correspond to llvm::FCmpInst
2357 * or llvm::ConstantExpr whose opcode is llvm::Instruction::FCmp.
2359 * @see llvm::FCmpInst::getPredicate()
2361 LLVMRealPredicate LLVMGetFCmpPredicate(LLVMValueRef Inst);
2364 * Create a copy of 'this' instruction that is identical in all ways
2365 * except the following:
2366 * * The instruction has no parent
2367 * * The instruction has no name
2369 * @see llvm::Instruction::clone()
2371 LLVMValueRef LLVMInstructionClone(LLVMValueRef Inst);
2374 * @defgroup LLVMCCoreValueInstructionCall Call Sites and Invocations
2376 * Functions in this group apply to instructions that refer to call
2377 * sites and invocations. These correspond to C++ types in the
2378 * llvm::CallInst class tree.
2384 * Set the calling convention for a call instruction.
2386 * This expects an LLVMValueRef that corresponds to a llvm::CallInst or
2389 * @see llvm::CallInst::setCallingConv()
2390 * @see llvm::InvokeInst::setCallingConv()
2392 void LLVMSetInstructionCallConv(LLVMValueRef Instr, unsigned CC);
2395 * Obtain the calling convention for a call instruction.
2397 * This is the opposite of LLVMSetInstructionCallConv(). Reads its
2400 * @see LLVMSetInstructionCallConv()
2402 unsigned LLVMGetInstructionCallConv(LLVMValueRef Instr);
2405 void LLVMAddInstrAttribute(LLVMValueRef Instr, unsigned index, LLVMAttribute);
2406 void LLVMRemoveInstrAttribute(LLVMValueRef Instr, unsigned index,
2408 void LLVMSetInstrParamAlignment(LLVMValueRef Instr, unsigned index,
2412 * Obtain whether a call instruction is a tail call.
2414 * This only works on llvm::CallInst instructions.
2416 * @see llvm::CallInst::isTailCall()
2418 LLVMBool LLVMIsTailCall(LLVMValueRef CallInst);
2421 * Set whether a call instruction is a tail call.
2423 * This only works on llvm::CallInst instructions.
2425 * @see llvm::CallInst::setTailCall()
2427 void LLVMSetTailCall(LLVMValueRef CallInst, LLVMBool IsTailCall);
2434 * @defgroup LLVMCCoreValueInstructionTerminator Terminators
2436 * Functions in this group only apply to instructions that map to
2437 * llvm::TerminatorInst instances.
2443 * Return the number of successors that this terminator has.
2445 * @see llvm::TerminatorInst::getNumSuccessors
2447 unsigned LLVMGetNumSuccessors(LLVMValueRef Term);
2450 * Return the specified successor.
2452 * @see llvm::TerminatorInst::getSuccessor
2454 LLVMBasicBlockRef LLVMGetSuccessor(LLVMValueRef Term, unsigned i);
2457 * Update the specified successor to point at the provided block.
2459 * @see llvm::TerminatorInst::setSuccessor
2461 void LLVMSetSuccessor(LLVMValueRef Term, unsigned i, LLVMBasicBlockRef block);
2464 * Return if a branch is conditional.
2466 * This only works on llvm::BranchInst instructions.
2468 * @see llvm::BranchInst::isConditional
2470 LLVMBool LLVMIsConditional(LLVMValueRef Branch);
2473 * Return the condition of a branch instruction.
2475 * This only works on llvm::BranchInst instructions.
2477 * @see llvm::BranchInst::getCondition
2479 LLVMValueRef LLVMGetCondition(LLVMValueRef Branch);
2482 * Set the condition of a branch instruction.
2484 * This only works on llvm::BranchInst instructions.
2486 * @see llvm::BranchInst::setCondition
2488 void LLVMSetCondition(LLVMValueRef Branch, LLVMValueRef Cond);
2491 * Obtain the default destination basic block of a switch instruction.
2493 * This only works on llvm::SwitchInst instructions.
2495 * @see llvm::SwitchInst::getDefaultDest()
2497 LLVMBasicBlockRef LLVMGetSwitchDefaultDest(LLVMValueRef SwitchInstr);
2504 * @defgroup LLVMCCoreValueInstructionPHINode PHI Nodes
2506 * Functions in this group only apply to instructions that map to
2507 * llvm::PHINode instances.
2513 * Add an incoming value to the end of a PHI list.
2515 void LLVMAddIncoming(LLVMValueRef PhiNode, LLVMValueRef *IncomingValues,
2516 LLVMBasicBlockRef *IncomingBlocks, unsigned Count);
2519 * Obtain the number of incoming basic blocks to a PHI node.
2521 unsigned LLVMCountIncoming(LLVMValueRef PhiNode);
2524 * Obtain an incoming value to a PHI node as an LLVMValueRef.
2526 LLVMValueRef LLVMGetIncomingValue(LLVMValueRef PhiNode, unsigned Index);
2529 * Obtain an incoming value to a PHI node as an LLVMBasicBlockRef.
2531 LLVMBasicBlockRef LLVMGetIncomingBlock(LLVMValueRef PhiNode, unsigned Index);
2546 * @defgroup LLVMCCoreInstructionBuilder Instruction Builders
2548 * An instruction builder represents a point within a basic block and is
2549 * the exclusive means of building instructions using the C interface.
2554 LLVMBuilderRef LLVMCreateBuilderInContext(LLVMContextRef C);
2555 LLVMBuilderRef LLVMCreateBuilder(void);
2556 void LLVMPositionBuilder(LLVMBuilderRef Builder, LLVMBasicBlockRef Block,
2557 LLVMValueRef Instr);
2558 void LLVMPositionBuilderBefore(LLVMBuilderRef Builder, LLVMValueRef Instr);
2559 void LLVMPositionBuilderAtEnd(LLVMBuilderRef Builder, LLVMBasicBlockRef Block);
2560 LLVMBasicBlockRef LLVMGetInsertBlock(LLVMBuilderRef Builder);
2561 void LLVMClearInsertionPosition(LLVMBuilderRef Builder);
2562 void LLVMInsertIntoBuilder(LLVMBuilderRef Builder, LLVMValueRef Instr);
2563 void LLVMInsertIntoBuilderWithName(LLVMBuilderRef Builder, LLVMValueRef Instr,
2565 void LLVMDisposeBuilder(LLVMBuilderRef Builder);
2568 void LLVMSetCurrentDebugLocation(LLVMBuilderRef Builder, LLVMValueRef L);
2569 LLVMValueRef LLVMGetCurrentDebugLocation(LLVMBuilderRef Builder);
2570 void LLVMSetInstDebugLocation(LLVMBuilderRef Builder, LLVMValueRef Inst);
2573 LLVMValueRef LLVMBuildRetVoid(LLVMBuilderRef);
2574 LLVMValueRef LLVMBuildRet(LLVMBuilderRef, LLVMValueRef V);
2575 LLVMValueRef LLVMBuildAggregateRet(LLVMBuilderRef, LLVMValueRef *RetVals,
2577 LLVMValueRef LLVMBuildBr(LLVMBuilderRef, LLVMBasicBlockRef Dest);
2578 LLVMValueRef LLVMBuildCondBr(LLVMBuilderRef, LLVMValueRef If,
2579 LLVMBasicBlockRef Then, LLVMBasicBlockRef Else);
2580 LLVMValueRef LLVMBuildSwitch(LLVMBuilderRef, LLVMValueRef V,
2581 LLVMBasicBlockRef Else, unsigned NumCases);
2582 LLVMValueRef LLVMBuildIndirectBr(LLVMBuilderRef B, LLVMValueRef Addr,
2584 LLVMValueRef LLVMBuildInvoke(LLVMBuilderRef, LLVMValueRef Fn,
2585 LLVMValueRef *Args, unsigned NumArgs,
2586 LLVMBasicBlockRef Then, LLVMBasicBlockRef Catch,
2588 LLVMValueRef LLVMBuildLandingPad(LLVMBuilderRef B, LLVMTypeRef Ty,
2589 LLVMValueRef PersFn, unsigned NumClauses,
2591 LLVMValueRef LLVMBuildResume(LLVMBuilderRef B, LLVMValueRef Exn);
2592 LLVMValueRef LLVMBuildUnreachable(LLVMBuilderRef);
2594 /* Add a case to the switch instruction */
2595 void LLVMAddCase(LLVMValueRef Switch, LLVMValueRef OnVal,
2596 LLVMBasicBlockRef Dest);
2598 /* Add a destination to the indirectbr instruction */
2599 void LLVMAddDestination(LLVMValueRef IndirectBr, LLVMBasicBlockRef Dest);
2601 /* Add a catch or filter clause to the landingpad instruction */
2602 void LLVMAddClause(LLVMValueRef LandingPad, LLVMValueRef ClauseVal);
2604 /* Set the 'cleanup' flag in the landingpad instruction */
2605 void LLVMSetCleanup(LLVMValueRef LandingPad, LLVMBool Val);
2608 LLVMValueRef LLVMBuildAdd(LLVMBuilderRef, LLVMValueRef LHS, LLVMValueRef RHS,
2610 LLVMValueRef LLVMBuildNSWAdd(LLVMBuilderRef, LLVMValueRef LHS, LLVMValueRef RHS,
2612 LLVMValueRef LLVMBuildNUWAdd(LLVMBuilderRef, LLVMValueRef LHS, LLVMValueRef RHS,
2614 LLVMValueRef LLVMBuildFAdd(LLVMBuilderRef, LLVMValueRef LHS, LLVMValueRef RHS,
2616 LLVMValueRef LLVMBuildSub(LLVMBuilderRef, LLVMValueRef LHS, LLVMValueRef RHS,
2618 LLVMValueRef LLVMBuildNSWSub(LLVMBuilderRef, LLVMValueRef LHS, LLVMValueRef RHS,
2620 LLVMValueRef LLVMBuildNUWSub(LLVMBuilderRef, LLVMValueRef LHS, LLVMValueRef RHS,
2622 LLVMValueRef LLVMBuildFSub(LLVMBuilderRef, LLVMValueRef LHS, LLVMValueRef RHS,
2624 LLVMValueRef LLVMBuildMul(LLVMBuilderRef, LLVMValueRef LHS, LLVMValueRef RHS,
2626 LLVMValueRef LLVMBuildNSWMul(LLVMBuilderRef, LLVMValueRef LHS, LLVMValueRef RHS,
2628 LLVMValueRef LLVMBuildNUWMul(LLVMBuilderRef, LLVMValueRef LHS, LLVMValueRef RHS,
2630 LLVMValueRef LLVMBuildFMul(LLVMBuilderRef, LLVMValueRef LHS, LLVMValueRef RHS,
2632 LLVMValueRef LLVMBuildUDiv(LLVMBuilderRef, LLVMValueRef LHS, LLVMValueRef RHS,
2634 LLVMValueRef LLVMBuildSDiv(LLVMBuilderRef, LLVMValueRef LHS, LLVMValueRef RHS,
2636 LLVMValueRef LLVMBuildExactSDiv(LLVMBuilderRef, LLVMValueRef LHS, LLVMValueRef RHS,
2638 LLVMValueRef LLVMBuildFDiv(LLVMBuilderRef, LLVMValueRef LHS, LLVMValueRef RHS,
2640 LLVMValueRef LLVMBuildURem(LLVMBuilderRef, LLVMValueRef LHS, LLVMValueRef RHS,
2642 LLVMValueRef LLVMBuildSRem(LLVMBuilderRef, LLVMValueRef LHS, LLVMValueRef RHS,
2644 LLVMValueRef LLVMBuildFRem(LLVMBuilderRef, LLVMValueRef LHS, LLVMValueRef RHS,
2646 LLVMValueRef LLVMBuildShl(LLVMBuilderRef, LLVMValueRef LHS, LLVMValueRef RHS,
2648 LLVMValueRef LLVMBuildLShr(LLVMBuilderRef, LLVMValueRef LHS, LLVMValueRef RHS,
2650 LLVMValueRef LLVMBuildAShr(LLVMBuilderRef, LLVMValueRef LHS, LLVMValueRef RHS,
2652 LLVMValueRef LLVMBuildAnd(LLVMBuilderRef, LLVMValueRef LHS, LLVMValueRef RHS,
2654 LLVMValueRef LLVMBuildOr(LLVMBuilderRef, LLVMValueRef LHS, LLVMValueRef RHS,
2656 LLVMValueRef LLVMBuildXor(LLVMBuilderRef, LLVMValueRef LHS, LLVMValueRef RHS,
2658 LLVMValueRef LLVMBuildBinOp(LLVMBuilderRef B, LLVMOpcode Op,
2659 LLVMValueRef LHS, LLVMValueRef RHS,
2661 LLVMValueRef LLVMBuildNeg(LLVMBuilderRef, LLVMValueRef V, const char *Name);
2662 LLVMValueRef LLVMBuildNSWNeg(LLVMBuilderRef B, LLVMValueRef V,
2664 LLVMValueRef LLVMBuildNUWNeg(LLVMBuilderRef B, LLVMValueRef V,
2666 LLVMValueRef LLVMBuildFNeg(LLVMBuilderRef, LLVMValueRef V, const char *Name);
2667 LLVMValueRef LLVMBuildNot(LLVMBuilderRef, LLVMValueRef V, const char *Name);
2670 LLVMValueRef LLVMBuildMalloc(LLVMBuilderRef, LLVMTypeRef Ty, const char *Name);
2671 LLVMValueRef LLVMBuildArrayMalloc(LLVMBuilderRef, LLVMTypeRef Ty,
2672 LLVMValueRef Val, const char *Name);
2673 LLVMValueRef LLVMBuildAlloca(LLVMBuilderRef, LLVMTypeRef Ty, const char *Name);
2674 LLVMValueRef LLVMBuildArrayAlloca(LLVMBuilderRef, LLVMTypeRef Ty,
2675 LLVMValueRef Val, const char *Name);
2676 LLVMValueRef LLVMBuildFree(LLVMBuilderRef, LLVMValueRef PointerVal);
2677 LLVMValueRef LLVMBuildLoad(LLVMBuilderRef, LLVMValueRef PointerVal,
2679 LLVMValueRef LLVMBuildStore(LLVMBuilderRef, LLVMValueRef Val, LLVMValueRef Ptr);
2680 LLVMValueRef LLVMBuildGEP(LLVMBuilderRef B, LLVMValueRef Pointer,
2681 LLVMValueRef *Indices, unsigned NumIndices,
2683 LLVMValueRef LLVMBuildInBoundsGEP(LLVMBuilderRef B, LLVMValueRef Pointer,
2684 LLVMValueRef *Indices, unsigned NumIndices,
2686 LLVMValueRef LLVMBuildStructGEP(LLVMBuilderRef B, LLVMValueRef Pointer,
2687 unsigned Idx, const char *Name);
2688 LLVMValueRef LLVMBuildGlobalString(LLVMBuilderRef B, const char *Str,
2690 LLVMValueRef LLVMBuildGlobalStringPtr(LLVMBuilderRef B, const char *Str,
2692 LLVMBool LLVMGetVolatile(LLVMValueRef MemoryAccessInst);
2693 void LLVMSetVolatile(LLVMValueRef MemoryAccessInst, LLVMBool IsVolatile);
2694 LLVMAtomicOrdering LLVMGetOrdering(LLVMValueRef MemoryAccessInst);
2695 void LLVMSetOrdering(LLVMValueRef MemoryAccessInst, LLVMAtomicOrdering Ordering);
2698 LLVMValueRef LLVMBuildTrunc(LLVMBuilderRef, LLVMValueRef Val,
2699 LLVMTypeRef DestTy, const char *Name);
2700 LLVMValueRef LLVMBuildZExt(LLVMBuilderRef, LLVMValueRef Val,
2701 LLVMTypeRef DestTy, const char *Name);
2702 LLVMValueRef LLVMBuildSExt(LLVMBuilderRef, LLVMValueRef Val,
2703 LLVMTypeRef DestTy, const char *Name);
2704 LLVMValueRef LLVMBuildFPToUI(LLVMBuilderRef, LLVMValueRef Val,
2705 LLVMTypeRef DestTy, const char *Name);
2706 LLVMValueRef LLVMBuildFPToSI(LLVMBuilderRef, LLVMValueRef Val,
2707 LLVMTypeRef DestTy, const char *Name);
2708 LLVMValueRef LLVMBuildUIToFP(LLVMBuilderRef, LLVMValueRef Val,
2709 LLVMTypeRef DestTy, const char *Name);
2710 LLVMValueRef LLVMBuildSIToFP(LLVMBuilderRef, LLVMValueRef Val,
2711 LLVMTypeRef DestTy, const char *Name);
2712 LLVMValueRef LLVMBuildFPTrunc(LLVMBuilderRef, LLVMValueRef Val,
2713 LLVMTypeRef DestTy, const char *Name);
2714 LLVMValueRef LLVMBuildFPExt(LLVMBuilderRef, LLVMValueRef Val,
2715 LLVMTypeRef DestTy, const char *Name);
2716 LLVMValueRef LLVMBuildPtrToInt(LLVMBuilderRef, LLVMValueRef Val,
2717 LLVMTypeRef DestTy, const char *Name);
2718 LLVMValueRef LLVMBuildIntToPtr(LLVMBuilderRef, LLVMValueRef Val,
2719 LLVMTypeRef DestTy, const char *Name);
2720 LLVMValueRef LLVMBuildBitCast(LLVMBuilderRef, LLVMValueRef Val,
2721 LLVMTypeRef DestTy, const char *Name);
2722 LLVMValueRef LLVMBuildAddrSpaceCast(LLVMBuilderRef, LLVMValueRef Val,
2723 LLVMTypeRef DestTy, const char *Name);
2724 LLVMValueRef LLVMBuildZExtOrBitCast(LLVMBuilderRef, LLVMValueRef Val,
2725 LLVMTypeRef DestTy, const char *Name);
2726 LLVMValueRef LLVMBuildSExtOrBitCast(LLVMBuilderRef, LLVMValueRef Val,
2727 LLVMTypeRef DestTy, const char *Name);
2728 LLVMValueRef LLVMBuildTruncOrBitCast(LLVMBuilderRef, LLVMValueRef Val,
2729 LLVMTypeRef DestTy, const char *Name);
2730 LLVMValueRef LLVMBuildCast(LLVMBuilderRef B, LLVMOpcode Op, LLVMValueRef Val,
2731 LLVMTypeRef DestTy, const char *Name);
2732 LLVMValueRef LLVMBuildPointerCast(LLVMBuilderRef, LLVMValueRef Val,
2733 LLVMTypeRef DestTy, const char *Name);
2734 LLVMValueRef LLVMBuildIntCast(LLVMBuilderRef, LLVMValueRef Val, /*Signed cast!*/
2735 LLVMTypeRef DestTy, const char *Name);
2736 LLVMValueRef LLVMBuildFPCast(LLVMBuilderRef, LLVMValueRef Val,
2737 LLVMTypeRef DestTy, const char *Name);
2740 LLVMValueRef LLVMBuildICmp(LLVMBuilderRef, LLVMIntPredicate Op,
2741 LLVMValueRef LHS, LLVMValueRef RHS,
2743 LLVMValueRef LLVMBuildFCmp(LLVMBuilderRef, LLVMRealPredicate Op,
2744 LLVMValueRef LHS, LLVMValueRef RHS,
2747 /* Miscellaneous instructions */
2748 LLVMValueRef LLVMBuildPhi(LLVMBuilderRef, LLVMTypeRef Ty, const char *Name);
2749 LLVMValueRef LLVMBuildCall(LLVMBuilderRef, LLVMValueRef Fn,
2750 LLVMValueRef *Args, unsigned NumArgs,
2752 LLVMValueRef LLVMBuildSelect(LLVMBuilderRef, LLVMValueRef If,
2753 LLVMValueRef Then, LLVMValueRef Else,
2755 LLVMValueRef LLVMBuildVAArg(LLVMBuilderRef, LLVMValueRef List, LLVMTypeRef Ty,
2757 LLVMValueRef LLVMBuildExtractElement(LLVMBuilderRef, LLVMValueRef VecVal,
2758 LLVMValueRef Index, const char *Name);
2759 LLVMValueRef LLVMBuildInsertElement(LLVMBuilderRef, LLVMValueRef VecVal,
2760 LLVMValueRef EltVal, LLVMValueRef Index,
2762 LLVMValueRef LLVMBuildShuffleVector(LLVMBuilderRef, LLVMValueRef V1,
2763 LLVMValueRef V2, LLVMValueRef Mask,
2765 LLVMValueRef LLVMBuildExtractValue(LLVMBuilderRef, LLVMValueRef AggVal,
2766 unsigned Index, const char *Name);
2767 LLVMValueRef LLVMBuildInsertValue(LLVMBuilderRef, LLVMValueRef AggVal,
2768 LLVMValueRef EltVal, unsigned Index,
2771 LLVMValueRef LLVMBuildIsNull(LLVMBuilderRef, LLVMValueRef Val,
2773 LLVMValueRef LLVMBuildIsNotNull(LLVMBuilderRef, LLVMValueRef Val,
2775 LLVMValueRef LLVMBuildPtrDiff(LLVMBuilderRef, LLVMValueRef LHS,
2776 LLVMValueRef RHS, const char *Name);
2777 LLVMValueRef LLVMBuildFence(LLVMBuilderRef B, LLVMAtomicOrdering ordering,
2778 LLVMBool singleThread, const char *Name);
2779 LLVMValueRef LLVMBuildAtomicRMW(LLVMBuilderRef B, LLVMAtomicRMWBinOp op,
2780 LLVMValueRef PTR, LLVMValueRef Val,
2781 LLVMAtomicOrdering ordering,
2782 LLVMBool singleThread);
2789 * @defgroup LLVMCCoreModuleProvider Module Providers
2795 * Changes the type of M so it can be passed to FunctionPassManagers and the
2796 * JIT. They take ModuleProviders for historical reasons.
2798 LLVMModuleProviderRef
2799 LLVMCreateModuleProviderForExistingModule(LLVMModuleRef M);
2802 * Destroys the module M.
2804 void LLVMDisposeModuleProvider(LLVMModuleProviderRef M);
2811 * @defgroup LLVMCCoreMemoryBuffers Memory Buffers
2816 LLVMBool LLVMCreateMemoryBufferWithContentsOfFile(const char *Path,
2817 LLVMMemoryBufferRef *OutMemBuf,
2819 LLVMBool LLVMCreateMemoryBufferWithSTDIN(LLVMMemoryBufferRef *OutMemBuf,
2821 LLVMMemoryBufferRef LLVMCreateMemoryBufferWithMemoryRange(const char *InputData,
2822 size_t InputDataLength,
2823 const char *BufferName,
2824 LLVMBool RequiresNullTerminator);
2825 LLVMMemoryBufferRef LLVMCreateMemoryBufferWithMemoryRangeCopy(const char *InputData,
2826 size_t InputDataLength,
2827 const char *BufferName);
2828 const char *LLVMGetBufferStart(LLVMMemoryBufferRef MemBuf);
2829 size_t LLVMGetBufferSize(LLVMMemoryBufferRef MemBuf);
2830 void LLVMDisposeMemoryBuffer(LLVMMemoryBufferRef MemBuf);
2837 * @defgroup LLVMCCorePassRegistry Pass Registry
2842 /** Return the global pass registry, for use with initialization functions.
2843 @see llvm::PassRegistry::getPassRegistry */
2844 LLVMPassRegistryRef LLVMGetGlobalPassRegistry(void);
2851 * @defgroup LLVMCCorePassManagers Pass Managers
2856 /** Constructs a new whole-module pass pipeline. This type of pipeline is
2857 suitable for link-time optimization and whole-module transformations.
2858 @see llvm::PassManager::PassManager */
2859 LLVMPassManagerRef LLVMCreatePassManager(void);
2861 /** Constructs a new function-by-function pass pipeline over the module
2862 provider. It does not take ownership of the module provider. This type of
2863 pipeline is suitable for code generation and JIT compilation tasks.
2864 @see llvm::FunctionPassManager::FunctionPassManager */
2865 LLVMPassManagerRef LLVMCreateFunctionPassManagerForModule(LLVMModuleRef M);
2867 /** Deprecated: Use LLVMCreateFunctionPassManagerForModule instead. */
2868 LLVMPassManagerRef LLVMCreateFunctionPassManager(LLVMModuleProviderRef MP);
2870 /** Initializes, executes on the provided module, and finalizes all of the
2871 passes scheduled in the pass manager. Returns 1 if any of the passes
2872 modified the module, 0 otherwise.
2873 @see llvm::PassManager::run(Module&) */
2874 LLVMBool LLVMRunPassManager(LLVMPassManagerRef PM, LLVMModuleRef M);
2876 /** Initializes all of the function passes scheduled in the function pass
2877 manager. Returns 1 if any of the passes modified the module, 0 otherwise.
2878 @see llvm::FunctionPassManager::doInitialization */
2879 LLVMBool LLVMInitializeFunctionPassManager(LLVMPassManagerRef FPM);
2881 /** Executes all of the function passes scheduled in the function pass manager
2882 on the provided function. Returns 1 if any of the passes modified the
2883 function, false otherwise.
2884 @see llvm::FunctionPassManager::run(Function&) */
2885 LLVMBool LLVMRunFunctionPassManager(LLVMPassManagerRef FPM, LLVMValueRef F);
2887 /** Finalizes all of the function passes scheduled in in the function pass
2888 manager. Returns 1 if any of the passes modified the module, 0 otherwise.
2889 @see llvm::FunctionPassManager::doFinalization */
2890 LLVMBool LLVMFinalizeFunctionPassManager(LLVMPassManagerRef FPM);
2892 /** Frees the memory of a pass pipeline. For function pipelines, does not free
2893 the module provider.
2894 @see llvm::PassManagerBase::~PassManagerBase. */
2895 void LLVMDisposePassManager(LLVMPassManagerRef PM);
2902 * @defgroup LLVMCCoreThreading Threading
2904 * Handle the structures needed to make LLVM safe for multithreading.
2909 /** Deprecated: Multi-threading can only be enabled/disabled with the compile
2910 time define LLVM_ENABLE_THREADS. This function always returns
2911 LLVMIsMultithreaded(). */
2912 LLVMBool LLVMStartMultithreaded(void);
2914 /** Deprecated: Multi-threading can only be enabled/disabled with the compile
2915 time define LLVM_ENABLE_THREADS. */
2916 void LLVMStopMultithreaded(void);
2918 /** Check whether LLVM is executing in thread-safe mode or not.
2919 @see llvm::llvm_is_multithreaded */
2920 LLVMBool LLVMIsMultithreaded(void);
2938 #endif /* LLVM_C_CORE_H */