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/Support.h"
25 * @defgroup LLVMC LLVM-C: C interface to LLVM
27 * This module exposes parts of the LLVM library as a C API.
33 * @defgroup LLVMCTransforms Transforms
37 * @defgroup LLVMCCore Core
39 * This modules provide an interface to libLLVMCore, which implements
40 * the LLVM intermediate representation as well as other related types
43 * LLVM uses a polymorphic type hierarchy which C cannot represent, therefore
44 * parameters must be passed as base types. Despite the declared types, most
45 * of the functions provided operate only on branches of the type hierarchy.
46 * The declared parameter names are descriptive and specify which type is
47 * required. Additionally, each type hierarchy is documented along with the
48 * functions that operate upon it. For more detail, refer to LLVM's C++ code.
49 * If in doubt, refer to Core.cpp, which performs parameter downcasts in the
50 * form unwrap<RequiredType>(Param).
52 * Many exotic languages can interoperate with C code but have a harder time
53 * with C++ due to name mangling. So in addition to C, this interface enables
54 * tools written in such languages.
60 * @defgroup LLVMCCoreTypes Types and Enumerations
68 * The top-level container for all LLVM global data. See the LLVMContext class.
70 typedef struct LLVMOpaqueContext *LLVMContextRef;
73 * The top-level container for all other LLVM Intermediate Representation (IR)
78 typedef struct LLVMOpaqueModule *LLVMModuleRef;
81 * Each value in the LLVM IR has a type, an LLVMTypeRef.
85 typedef struct LLVMOpaqueType *LLVMTypeRef;
88 * Represents an individual value in LLVM IR.
90 * This models llvm::Value.
92 typedef struct LLVMOpaqueValue *LLVMValueRef;
95 * Represents a basic block of instructions in LLVM IR.
97 * This models llvm::BasicBlock.
99 typedef struct LLVMOpaqueBasicBlock *LLVMBasicBlockRef;
102 * Represents an LLVM basic block builder.
104 * This models llvm::IRBuilder.
106 typedef struct LLVMOpaqueBuilder *LLVMBuilderRef;
109 * Interface used to provide a module to JIT or interpreter.
110 * This is now just a synonym for llvm::Module, but we have to keep using the
111 * different type to keep binary compatibility.
113 typedef struct LLVMOpaqueModuleProvider *LLVMModuleProviderRef;
115 /** @see llvm::PassManagerBase */
116 typedef struct LLVMOpaquePassManager *LLVMPassManagerRef;
118 /** @see llvm::PassRegistry */
119 typedef struct LLVMOpaquePassRegistry *LLVMPassRegistryRef;
122 * Used to get the users and usees of a Value.
125 typedef struct LLVMOpaqueUse *LLVMUseRef;
129 * @see llvm::DiagnosticInfo
131 typedef struct LLVMOpaqueDiagnosticInfo *LLVMDiagnosticInfoRef;
134 LLVMZExtAttribute = 1<<0,
135 LLVMSExtAttribute = 1<<1,
136 LLVMNoReturnAttribute = 1<<2,
137 LLVMInRegAttribute = 1<<3,
138 LLVMStructRetAttribute = 1<<4,
139 LLVMNoUnwindAttribute = 1<<5,
140 LLVMNoAliasAttribute = 1<<6,
141 LLVMByValAttribute = 1<<7,
142 LLVMNestAttribute = 1<<8,
143 LLVMReadNoneAttribute = 1<<9,
144 LLVMReadOnlyAttribute = 1<<10,
145 LLVMNoInlineAttribute = 1<<11,
146 LLVMAlwaysInlineAttribute = 1<<12,
147 LLVMOptimizeForSizeAttribute = 1<<13,
148 LLVMStackProtectAttribute = 1<<14,
149 LLVMStackProtectReqAttribute = 1<<15,
150 LLVMAlignment = 31<<16,
151 LLVMNoCaptureAttribute = 1<<21,
152 LLVMNoRedZoneAttribute = 1<<22,
153 LLVMNoImplicitFloatAttribute = 1<<23,
154 LLVMNakedAttribute = 1<<24,
155 LLVMInlineHintAttribute = 1<<25,
156 LLVMStackAlignment = 7<<26,
157 LLVMReturnsTwice = 1 << 29,
158 LLVMUWTable = 1 << 30,
159 LLVMNonLazyBind = 1 << 31
161 /* FIXME: These attributes are currently not included in the C API as
162 a temporary measure until the API/ABI impact to the C API is understood
163 and the path forward agreed upon.
164 LLVMAddressSafety = 1ULL << 32,
165 LLVMStackProtectStrongAttribute = 1ULL<<33,
166 LLVMCold = 1ULL << 34,
167 LLVMOptimizeNone = 1ULL << 35,
168 LLVMInAllocaAttribute = 1ULL << 36
173 /* Terminator Instructions */
179 /* removed 6 due to API changes */
182 /* Standard Binary Operators */
196 /* Logical Operators */
204 /* Memory Operators */
208 LLVMGetElementPtr = 29,
223 LLVMAddrSpaceCast = 60,
225 /* Other Operators */
234 LLVMExtractElement = 50,
235 LLVMInsertElement = 51,
236 LLVMShuffleVector = 52,
237 LLVMExtractValue = 53,
238 LLVMInsertValue = 54,
240 /* Atomic operators */
242 LLVMAtomicCmpXchg = 56,
245 /* Exception Handling Operators */
252 LLVMVoidTypeKind, /**< type with no size */
253 LLVMHalfTypeKind, /**< 16 bit floating point type */
254 LLVMFloatTypeKind, /**< 32 bit floating point type */
255 LLVMDoubleTypeKind, /**< 64 bit floating point type */
256 LLVMX86_FP80TypeKind, /**< 80 bit floating point type (X87) */
257 LLVMFP128TypeKind, /**< 128 bit floating point type (112-bit mantissa)*/
258 LLVMPPC_FP128TypeKind, /**< 128 bit floating point type (two 64-bits) */
259 LLVMLabelTypeKind, /**< Labels */
260 LLVMIntegerTypeKind, /**< Arbitrary bit width integers */
261 LLVMFunctionTypeKind, /**< Functions */
262 LLVMStructTypeKind, /**< Structures */
263 LLVMArrayTypeKind, /**< Arrays */
264 LLVMPointerTypeKind, /**< Pointers */
265 LLVMVectorTypeKind, /**< SIMD 'packed' format, or other vector type */
266 LLVMMetadataTypeKind, /**< Metadata */
267 LLVMX86_MMXTypeKind /**< X86 MMX */
271 LLVMExternalLinkage, /**< Externally visible function */
272 LLVMAvailableExternallyLinkage,
273 LLVMLinkOnceAnyLinkage, /**< Keep one copy of function when linking (inline)*/
274 LLVMLinkOnceODRLinkage, /**< Same, but only replaced by something
276 LLVMLinkOnceODRAutoHideLinkage, /**< Obsolete */
277 LLVMWeakAnyLinkage, /**< Keep one copy of function when linking (weak) */
278 LLVMWeakODRLinkage, /**< Same, but only replaced by something
280 LLVMAppendingLinkage, /**< Special purpose, only applies to global arrays */
281 LLVMInternalLinkage, /**< Rename collisions when linking (static
283 LLVMPrivateLinkage, /**< Like Internal, but omit from symbol table */
284 LLVMDLLImportLinkage, /**< Obsolete */
285 LLVMDLLExportLinkage, /**< Obsolete */
286 LLVMExternalWeakLinkage,/**< ExternalWeak linkage description */
287 LLVMGhostLinkage, /**< Obsolete */
288 LLVMCommonLinkage, /**< Tentative definitions */
289 LLVMLinkerPrivateLinkage, /**< Like Private, but linker removes. */
290 LLVMLinkerPrivateWeakLinkage /**< Like LinkerPrivate, but is weak. */
294 LLVMDefaultVisibility, /**< The GV is visible */
295 LLVMHiddenVisibility, /**< The GV is hidden */
296 LLVMProtectedVisibility /**< The GV is protected */
300 LLVMDefaultStorageClass = 0,
301 LLVMDLLImportStorageClass = 1, /**< Function to be imported from DLL. */
302 LLVMDLLExportStorageClass = 2 /**< Function to be accessible from DLL. */
303 } LLVMDLLStorageClass;
307 LLVMFastCallConv = 8,
308 LLVMColdCallConv = 9,
309 LLVMWebKitJSCallConv = 12,
310 LLVMAnyRegCallConv = 13,
311 LLVMX86StdcallCallConv = 64,
312 LLVMX86FastcallCallConv = 65
316 LLVMIntEQ = 32, /**< equal */
317 LLVMIntNE, /**< not equal */
318 LLVMIntUGT, /**< unsigned greater than */
319 LLVMIntUGE, /**< unsigned greater or equal */
320 LLVMIntULT, /**< unsigned less than */
321 LLVMIntULE, /**< unsigned less or equal */
322 LLVMIntSGT, /**< signed greater than */
323 LLVMIntSGE, /**< signed greater or equal */
324 LLVMIntSLT, /**< signed less than */
325 LLVMIntSLE /**< signed less or equal */
329 LLVMRealPredicateFalse, /**< Always false (always folded) */
330 LLVMRealOEQ, /**< True if ordered and equal */
331 LLVMRealOGT, /**< True if ordered and greater than */
332 LLVMRealOGE, /**< True if ordered and greater than or equal */
333 LLVMRealOLT, /**< True if ordered and less than */
334 LLVMRealOLE, /**< True if ordered and less than or equal */
335 LLVMRealONE, /**< True if ordered and operands are unequal */
336 LLVMRealORD, /**< True if ordered (no nans) */
337 LLVMRealUNO, /**< True if unordered: isnan(X) | isnan(Y) */
338 LLVMRealUEQ, /**< True if unordered or equal */
339 LLVMRealUGT, /**< True if unordered or greater than */
340 LLVMRealUGE, /**< True if unordered, greater than, or equal */
341 LLVMRealULT, /**< True if unordered or less than */
342 LLVMRealULE, /**< True if unordered, less than, or equal */
343 LLVMRealUNE, /**< True if unordered or not equal */
344 LLVMRealPredicateTrue /**< Always true (always folded) */
348 LLVMLandingPadCatch, /**< A catch clause */
349 LLVMLandingPadFilter /**< A filter clause */
350 } LLVMLandingPadClauseTy;
353 LLVMNotThreadLocal = 0,
354 LLVMGeneralDynamicTLSModel,
355 LLVMLocalDynamicTLSModel,
356 LLVMInitialExecTLSModel,
357 LLVMLocalExecTLSModel
358 } LLVMThreadLocalMode;
361 LLVMAtomicOrderingNotAtomic = 0, /**< A load or store which is not atomic */
362 LLVMAtomicOrderingUnordered = 1, /**< Lowest level of atomicity, guarantees
363 somewhat sane results, lock free. */
364 LLVMAtomicOrderingMonotonic = 2, /**< guarantees that if you take all the
365 operations affecting a specific address,
366 a consistent ordering exists */
367 LLVMAtomicOrderingAcquire = 4, /**< Acquire provides a barrier of the sort
368 necessary to acquire a lock to access other
369 memory with normal loads and stores. */
370 LLVMAtomicOrderingRelease = 5, /**< Release is similar to Acquire, but with
371 a barrier of the sort necessary to release
373 LLVMAtomicOrderingAcquireRelease = 6, /**< provides both an Acquire and a
374 Release barrier (for fences and
375 operations which both read and write
377 LLVMAtomicOrderingSequentiallyConsistent = 7 /**< provides Acquire semantics
378 for loads and Release
379 semantics for stores.
380 Additionally, it guarantees
381 that a total ordering exists
383 SequentiallyConsistent
385 } LLVMAtomicOrdering;
388 LLVMAtomicRMWBinOpXchg, /**< Set the new value and return the one old */
389 LLVMAtomicRMWBinOpAdd, /**< Add a value and return the old one */
390 LLVMAtomicRMWBinOpSub, /**< Subtract a value and return the old one */
391 LLVMAtomicRMWBinOpAnd, /**< And a value and return the old one */
392 LLVMAtomicRMWBinOpNand, /**< Not-And a value and return the old one */
393 LLVMAtomicRMWBinOpOr, /**< OR a value and return the old one */
394 LLVMAtomicRMWBinOpXor, /**< Xor a value and return the old one */
395 LLVMAtomicRMWBinOpMax, /**< Sets the value if it's greater than the
396 original using a signed comparison and return
398 LLVMAtomicRMWBinOpMin, /**< Sets the value if it's Smaller than the
399 original using a signed comparison and return
401 LLVMAtomicRMWBinOpUMax, /**< Sets the value if it's greater than the
402 original using an unsigned comparison and return
404 LLVMAtomicRMWBinOpUMin /**< Sets the value if it's greater than the
405 original using an unsigned comparison and return
407 } LLVMAtomicRMWBinOp;
414 } LLVMDiagnosticSeverity;
420 void LLVMInitializeCore(LLVMPassRegistryRef R);
422 /** Deallocate and destroy all ManagedStatic variables.
423 @see llvm::llvm_shutdown
424 @see ManagedStatic */
425 void LLVMShutdown(void);
428 /*===-- Error handling ----------------------------------------------------===*/
430 char *LLVMCreateMessage(const char *Message);
431 void LLVMDisposeMessage(char *Message);
433 typedef void (*LLVMFatalErrorHandler)(const char *Reason);
436 * Install a fatal error handler. By default, if LLVM detects a fatal error, it
437 * will call exit(1). This may not be appropriate in many contexts. For example,
438 * doing exit(1) will bypass many crash reporting/tracing system tools. This
439 * function allows you to install a callback that will be invoked prior to the
442 void LLVMInstallFatalErrorHandler(LLVMFatalErrorHandler Handler);
445 * Reset the fatal error handler. This resets LLVM's fatal error handling
446 * behavior to the default.
448 void LLVMResetFatalErrorHandler(void);
451 * Enable LLVM's built-in stack trace code. This intercepts the OS's crash
452 * signals and prints which component of LLVM you were in at the time if the
455 void LLVMEnablePrettyStackTrace(void);
458 * @defgroup LLVMCCoreContext Contexts
460 * Contexts are execution states for the core LLVM IR system.
462 * Most types are tied to a context instance. Multiple contexts can
463 * exist simultaneously. A single context is not thread safe. However,
464 * different contexts can execute on different threads simultaneously.
469 typedef void (*LLVMDiagnosticHandler)(LLVMDiagnosticInfoRef, void *);
470 typedef void (*LLVMYieldCallback)(LLVMContextRef, void *);
473 * Create a new context.
475 * Every call to this function should be paired with a call to
476 * LLVMContextDispose() or the context will leak memory.
478 LLVMContextRef LLVMContextCreate(void);
481 * Obtain the global context instance.
483 LLVMContextRef LLVMGetGlobalContext(void);
486 * Set the diagnostic handler for this context.
488 void LLVMContextSetDiagnosticHandler(LLVMContextRef C,
489 LLVMDiagnosticHandler Handler,
490 void *DiagnosticContext);
493 * Set the yield callback function for this context.
495 * @see LLVMContext::setYieldCallback()
497 void LLVMContextSetYieldCallback(LLVMContextRef C, LLVMYieldCallback Callback,
501 * Destroy a context instance.
503 * This should be called for every call to LLVMContextCreate() or memory
506 void LLVMContextDispose(LLVMContextRef C);
509 * Return a string representation of the DiagnosticInfo. Use
510 * LLVMDisposeMessage to free the string.
512 * @see DiagnosticInfo::print()
514 char *LLVMGetDiagInfoDescription(LLVMDiagnosticInfoRef DI);
517 * Return an enum LLVMDiagnosticSeverity.
519 * @see DiagnosticInfo::getSeverity()
521 LLVMDiagnosticSeverity LLVMGetDiagInfoSeverity(LLVMDiagnosticInfoRef DI);
523 unsigned LLVMGetMDKindIDInContext(LLVMContextRef C, const char* Name,
525 unsigned LLVMGetMDKindID(const char* Name, unsigned SLen);
532 * @defgroup LLVMCCoreModule Modules
534 * Modules represent the top-level structure in an LLVM program. An LLVM
535 * module is effectively a translation unit or a collection of
536 * translation units merged together.
542 * Create a new, empty module in the global context.
544 * This is equivalent to calling LLVMModuleCreateWithNameInContext with
545 * LLVMGetGlobalContext() as the context parameter.
547 * Every invocation should be paired with LLVMDisposeModule() or memory
550 LLVMModuleRef LLVMModuleCreateWithName(const char *ModuleID);
553 * Create a new, empty module in a specific context.
555 * Every invocation should be paired with LLVMDisposeModule() or memory
558 LLVMModuleRef LLVMModuleCreateWithNameInContext(const char *ModuleID,
562 * Destroy a module instance.
564 * This must be called for every created module or memory will be
567 void LLVMDisposeModule(LLVMModuleRef M);
570 * Obtain the data layout for a module.
572 * @see Module::getDataLayout()
574 const char *LLVMGetDataLayout(LLVMModuleRef M);
577 * Set the data layout for a module.
579 * @see Module::setDataLayout()
581 void LLVMSetDataLayout(LLVMModuleRef M, const char *Triple);
584 * Obtain the target triple for a module.
586 * @see Module::getTargetTriple()
588 const char *LLVMGetTarget(LLVMModuleRef M);
591 * Set the target triple for a module.
593 * @see Module::setTargetTriple()
595 void LLVMSetTarget(LLVMModuleRef M, const char *Triple);
598 * Dump a representation of a module to stderr.
600 * @see Module::dump()
602 void LLVMDumpModule(LLVMModuleRef M);
605 * Print a representation of a module to a file. The ErrorMessage needs to be
606 * disposed with LLVMDisposeMessage. Returns 0 on success, 1 otherwise.
608 * @see Module::print()
610 LLVMBool LLVMPrintModuleToFile(LLVMModuleRef M, const char *Filename,
611 char **ErrorMessage);
614 * Return a string representation of the module. Use
615 * LLVMDisposeMessage to free the string.
617 * @see Module::print()
619 char *LLVMPrintModuleToString(LLVMModuleRef M);
622 * Set inline assembly for a module.
624 * @see Module::setModuleInlineAsm()
626 void LLVMSetModuleInlineAsm(LLVMModuleRef M, const char *Asm);
629 * Obtain the context to which this module is associated.
631 * @see Module::getContext()
633 LLVMContextRef LLVMGetModuleContext(LLVMModuleRef M);
636 * Obtain a Type from a module by its registered name.
638 LLVMTypeRef LLVMGetTypeByName(LLVMModuleRef M, const char *Name);
641 * Obtain the number of operands for named metadata in a module.
643 * @see llvm::Module::getNamedMetadata()
645 unsigned LLVMGetNamedMetadataNumOperands(LLVMModuleRef M, const char* name);
648 * Obtain the named metadata operands for a module.
650 * The passed LLVMValueRef pointer should refer to an array of
651 * LLVMValueRef at least LLVMGetNamedMetadataNumOperands long. This
652 * array will be populated with the LLVMValueRef instances. Each
653 * instance corresponds to a llvm::MDNode.
655 * @see llvm::Module::getNamedMetadata()
656 * @see llvm::MDNode::getOperand()
658 void LLVMGetNamedMetadataOperands(LLVMModuleRef M, const char* name, LLVMValueRef *Dest);
661 * Add an operand to named metadata.
663 * @see llvm::Module::getNamedMetadata()
664 * @see llvm::MDNode::addOperand()
666 void LLVMAddNamedMetadataOperand(LLVMModuleRef M, const char* name,
670 * Add a function to a module under a specified name.
672 * @see llvm::Function::Create()
674 LLVMValueRef LLVMAddFunction(LLVMModuleRef M, const char *Name,
675 LLVMTypeRef FunctionTy);
678 * Obtain a Function value from a Module by its name.
680 * The returned value corresponds to a llvm::Function value.
682 * @see llvm::Module::getFunction()
684 LLVMValueRef LLVMGetNamedFunction(LLVMModuleRef M, const char *Name);
687 * Obtain an iterator to the first Function in a Module.
689 * @see llvm::Module::begin()
691 LLVMValueRef LLVMGetFirstFunction(LLVMModuleRef M);
694 * Obtain an iterator to the last Function in a Module.
696 * @see llvm::Module::end()
698 LLVMValueRef LLVMGetLastFunction(LLVMModuleRef M);
701 * Advance a Function iterator to the next Function.
703 * Returns NULL if the iterator was already at the end and there are no more
706 LLVMValueRef LLVMGetNextFunction(LLVMValueRef Fn);
709 * Decrement a Function iterator to the previous Function.
711 * Returns NULL if the iterator was already at the beginning and there are
712 * no previous functions.
714 LLVMValueRef LLVMGetPreviousFunction(LLVMValueRef Fn);
721 * @defgroup LLVMCCoreType Types
723 * Types represent the type of a value.
725 * Types are associated with a context instance. The context internally
726 * deduplicates types so there is only 1 instance of a specific type
727 * alive at a time. In other words, a unique type is shared among all
728 * consumers within a context.
730 * A Type in the C API corresponds to llvm::Type.
732 * Types have the following hierarchy:
750 * Obtain the enumerated type of a Type instance.
752 * @see llvm::Type:getTypeID()
754 LLVMTypeKind LLVMGetTypeKind(LLVMTypeRef Ty);
757 * Whether the type has a known size.
759 * Things that don't have a size are abstract types, labels, and void.a
761 * @see llvm::Type::isSized()
763 LLVMBool LLVMTypeIsSized(LLVMTypeRef Ty);
766 * Obtain the context to which this type instance is associated.
768 * @see llvm::Type::getContext()
770 LLVMContextRef LLVMGetTypeContext(LLVMTypeRef Ty);
773 * Dump a representation of a type to stderr.
775 * @see llvm::Type::dump()
777 void LLVMDumpType(LLVMTypeRef Val);
780 * Return a string representation of the type. Use
781 * LLVMDisposeMessage to free the string.
783 * @see llvm::Type::print()
785 char *LLVMPrintTypeToString(LLVMTypeRef Val);
788 * @defgroup LLVMCCoreTypeInt Integer Types
790 * Functions in this section operate on integer types.
796 * Obtain an integer type from a context with specified bit width.
798 LLVMTypeRef LLVMInt1TypeInContext(LLVMContextRef C);
799 LLVMTypeRef LLVMInt8TypeInContext(LLVMContextRef C);
800 LLVMTypeRef LLVMInt16TypeInContext(LLVMContextRef C);
801 LLVMTypeRef LLVMInt32TypeInContext(LLVMContextRef C);
802 LLVMTypeRef LLVMInt64TypeInContext(LLVMContextRef C);
803 LLVMTypeRef LLVMIntTypeInContext(LLVMContextRef C, unsigned NumBits);
806 * Obtain an integer type from the global context with a specified bit
809 LLVMTypeRef LLVMInt1Type(void);
810 LLVMTypeRef LLVMInt8Type(void);
811 LLVMTypeRef LLVMInt16Type(void);
812 LLVMTypeRef LLVMInt32Type(void);
813 LLVMTypeRef LLVMInt64Type(void);
814 LLVMTypeRef LLVMIntType(unsigned NumBits);
815 unsigned LLVMGetIntTypeWidth(LLVMTypeRef IntegerTy);
822 * @defgroup LLVMCCoreTypeFloat Floating Point Types
828 * Obtain a 16-bit floating point type from a context.
830 LLVMTypeRef LLVMHalfTypeInContext(LLVMContextRef C);
833 * Obtain a 32-bit floating point type from a context.
835 LLVMTypeRef LLVMFloatTypeInContext(LLVMContextRef C);
838 * Obtain a 64-bit floating point type from a context.
840 LLVMTypeRef LLVMDoubleTypeInContext(LLVMContextRef C);
843 * Obtain a 80-bit floating point type (X87) from a context.
845 LLVMTypeRef LLVMX86FP80TypeInContext(LLVMContextRef C);
848 * Obtain a 128-bit floating point type (112-bit mantissa) from a
851 LLVMTypeRef LLVMFP128TypeInContext(LLVMContextRef C);
854 * Obtain a 128-bit floating point type (two 64-bits) from a context.
856 LLVMTypeRef LLVMPPCFP128TypeInContext(LLVMContextRef C);
859 * Obtain a floating point type from the global context.
861 * These map to the functions in this group of the same name.
863 LLVMTypeRef LLVMHalfType(void);
864 LLVMTypeRef LLVMFloatType(void);
865 LLVMTypeRef LLVMDoubleType(void);
866 LLVMTypeRef LLVMX86FP80Type(void);
867 LLVMTypeRef LLVMFP128Type(void);
868 LLVMTypeRef LLVMPPCFP128Type(void);
875 * @defgroup LLVMCCoreTypeFunction Function Types
881 * Obtain a function type consisting of a specified signature.
883 * The function is defined as a tuple of a return Type, a list of
884 * parameter types, and whether the function is variadic.
886 LLVMTypeRef LLVMFunctionType(LLVMTypeRef ReturnType,
887 LLVMTypeRef *ParamTypes, unsigned ParamCount,
891 * Returns whether a function type is variadic.
893 LLVMBool LLVMIsFunctionVarArg(LLVMTypeRef FunctionTy);
896 * Obtain the Type this function Type returns.
898 LLVMTypeRef LLVMGetReturnType(LLVMTypeRef FunctionTy);
901 * Obtain the number of parameters this function accepts.
903 unsigned LLVMCountParamTypes(LLVMTypeRef FunctionTy);
906 * Obtain the types of a function's parameters.
908 * The Dest parameter should point to a pre-allocated array of
909 * LLVMTypeRef at least LLVMCountParamTypes() large. On return, the
910 * first LLVMCountParamTypes() entries in the array will be populated
911 * with LLVMTypeRef instances.
913 * @param FunctionTy The function type to operate on.
914 * @param Dest Memory address of an array to be filled with result.
916 void LLVMGetParamTypes(LLVMTypeRef FunctionTy, LLVMTypeRef *Dest);
923 * @defgroup LLVMCCoreTypeStruct Structure Types
925 * These functions relate to LLVMTypeRef instances.
927 * @see llvm::StructType
933 * Create a new structure type in a context.
935 * A structure is specified by a list of inner elements/types and
936 * whether these can be packed together.
938 * @see llvm::StructType::create()
940 LLVMTypeRef LLVMStructTypeInContext(LLVMContextRef C, LLVMTypeRef *ElementTypes,
941 unsigned ElementCount, LLVMBool Packed);
944 * Create a new structure type in the global context.
946 * @see llvm::StructType::create()
948 LLVMTypeRef LLVMStructType(LLVMTypeRef *ElementTypes, unsigned ElementCount,
952 * Create an empty structure in a context having a specified name.
954 * @see llvm::StructType::create()
956 LLVMTypeRef LLVMStructCreateNamed(LLVMContextRef C, const char *Name);
959 * Obtain the name of a structure.
961 * @see llvm::StructType::getName()
963 const char *LLVMGetStructName(LLVMTypeRef Ty);
966 * Set the contents of a structure type.
968 * @see llvm::StructType::setBody()
970 void LLVMStructSetBody(LLVMTypeRef StructTy, LLVMTypeRef *ElementTypes,
971 unsigned ElementCount, LLVMBool Packed);
974 * Get the number of elements defined inside the structure.
976 * @see llvm::StructType::getNumElements()
978 unsigned LLVMCountStructElementTypes(LLVMTypeRef StructTy);
981 * Get the elements within a structure.
983 * The function is passed the address of a pre-allocated array of
984 * LLVMTypeRef at least LLVMCountStructElementTypes() long. After
985 * invocation, this array will be populated with the structure's
986 * elements. The objects in the destination array will have a lifetime
987 * of the structure type itself, which is the lifetime of the context it
990 void LLVMGetStructElementTypes(LLVMTypeRef StructTy, LLVMTypeRef *Dest);
993 * Determine whether a structure is packed.
995 * @see llvm::StructType::isPacked()
997 LLVMBool LLVMIsPackedStruct(LLVMTypeRef StructTy);
1000 * Determine whether a structure is opaque.
1002 * @see llvm::StructType::isOpaque()
1004 LLVMBool LLVMIsOpaqueStruct(LLVMTypeRef StructTy);
1012 * @defgroup LLVMCCoreTypeSequential Sequential Types
1014 * Sequential types represents "arrays" of types. This is a super class
1015 * for array, vector, and pointer types.
1021 * Obtain the type of elements within a sequential type.
1023 * This works on array, vector, and pointer types.
1025 * @see llvm::SequentialType::getElementType()
1027 LLVMTypeRef LLVMGetElementType(LLVMTypeRef Ty);
1030 * Create a fixed size array type that refers to a specific type.
1032 * The created type will exist in the context that its element type
1035 * @see llvm::ArrayType::get()
1037 LLVMTypeRef LLVMArrayType(LLVMTypeRef ElementType, unsigned ElementCount);
1040 * Obtain the length of an array type.
1042 * This only works on types that represent arrays.
1044 * @see llvm::ArrayType::getNumElements()
1046 unsigned LLVMGetArrayLength(LLVMTypeRef ArrayTy);
1049 * Create a pointer type that points to a defined type.
1051 * The created type will exist in the context that its pointee type
1054 * @see llvm::PointerType::get()
1056 LLVMTypeRef LLVMPointerType(LLVMTypeRef ElementType, unsigned AddressSpace);
1059 * Obtain the address space of a pointer type.
1061 * This only works on types that represent pointers.
1063 * @see llvm::PointerType::getAddressSpace()
1065 unsigned LLVMGetPointerAddressSpace(LLVMTypeRef PointerTy);
1068 * Create a vector type that contains a defined type and has a specific
1069 * number of elements.
1071 * The created type will exist in the context thats its element type
1074 * @see llvm::VectorType::get()
1076 LLVMTypeRef LLVMVectorType(LLVMTypeRef ElementType, unsigned ElementCount);
1079 * Obtain the number of elements in a vector type.
1081 * This only works on types that represent vectors.
1083 * @see llvm::VectorType::getNumElements()
1085 unsigned LLVMGetVectorSize(LLVMTypeRef VectorTy);
1092 * @defgroup LLVMCCoreTypeOther Other Types
1098 * Create a void type in a context.
1100 LLVMTypeRef LLVMVoidTypeInContext(LLVMContextRef C);
1103 * Create a label type in a context.
1105 LLVMTypeRef LLVMLabelTypeInContext(LLVMContextRef C);
1108 * Create a X86 MMX type in a context.
1110 LLVMTypeRef LLVMX86MMXTypeInContext(LLVMContextRef C);
1113 * These are similar to the above functions except they operate on the
1116 LLVMTypeRef LLVMVoidType(void);
1117 LLVMTypeRef LLVMLabelType(void);
1118 LLVMTypeRef LLVMX86MMXType(void);
1129 * @defgroup LLVMCCoreValues Values
1131 * The bulk of LLVM's object model consists of values, which comprise a very
1132 * rich type hierarchy.
1134 * LLVMValueRef essentially represents llvm::Value. There is a rich
1135 * hierarchy of classes within this type. Depending on the instance
1136 * obtained, not all APIs are available.
1138 * Callers can determine the type of an LLVMValueRef by calling the
1139 * LLVMIsA* family of functions (e.g. LLVMIsAArgument()). These
1140 * functions are defined by a macro, so it isn't obvious which are
1141 * available by looking at the Doxygen source code. Instead, look at the
1142 * source definition of LLVM_FOR_EACH_VALUE_SUBCLASS and note the list
1143 * of value names given. These value names also correspond to classes in
1144 * the llvm::Value hierarchy.
1149 #define LLVM_FOR_EACH_VALUE_SUBCLASS(macro) \
1157 macro(BlockAddress) \
1158 macro(ConstantAggregateZero) \
1159 macro(ConstantArray) \
1160 macro(ConstantDataSequential) \
1161 macro(ConstantDataArray) \
1162 macro(ConstantDataVector) \
1163 macro(ConstantExpr) \
1165 macro(ConstantInt) \
1166 macro(ConstantPointerNull) \
1167 macro(ConstantStruct) \
1168 macro(ConstantVector) \
1169 macro(GlobalValue) \
1170 macro(GlobalAlias) \
1171 macro(GlobalObject) \
1173 macro(GlobalVariable) \
1175 macro(Instruction) \
1176 macro(BinaryOperator) \
1178 macro(IntrinsicInst) \
1179 macro(DbgInfoIntrinsic) \
1180 macro(DbgDeclareInst) \
1181 macro(MemIntrinsic) \
1183 macro(MemMoveInst) \
1188 macro(ExtractElementInst) \
1189 macro(GetElementPtrInst) \
1190 macro(InsertElementInst) \
1191 macro(InsertValueInst) \
1192 macro(LandingPadInst) \
1195 macro(ShuffleVectorInst) \
1197 macro(TerminatorInst) \
1199 macro(IndirectBrInst) \
1203 macro(UnreachableInst) \
1205 macro(UnaryInstruction) \
1208 macro(AddrSpaceCastInst) \
1209 macro(BitCastInst) \
1213 macro(FPTruncInst) \
1214 macro(IntToPtrInst) \
1215 macro(PtrToIntInst) \
1221 macro(ExtractValueInst) \
1226 * @defgroup LLVMCCoreValueGeneral General APIs
1228 * Functions in this section work on all LLVMValueRef instances,
1229 * regardless of their sub-type. They correspond to functions available
1236 * Obtain the type of a value.
1238 * @see llvm::Value::getType()
1240 LLVMTypeRef LLVMTypeOf(LLVMValueRef Val);
1243 * Obtain the string name of a value.
1245 * @see llvm::Value::getName()
1247 const char *LLVMGetValueName(LLVMValueRef Val);
1250 * Set the string name of a value.
1252 * @see llvm::Value::setName()
1254 void LLVMSetValueName(LLVMValueRef Val, const char *Name);
1257 * Dump a representation of a value to stderr.
1259 * @see llvm::Value::dump()
1261 void LLVMDumpValue(LLVMValueRef Val);
1264 * Return a string representation of the value. Use
1265 * LLVMDisposeMessage to free the string.
1267 * @see llvm::Value::print()
1269 char *LLVMPrintValueToString(LLVMValueRef Val);
1272 * Replace all uses of a value with another one.
1274 * @see llvm::Value::replaceAllUsesWith()
1276 void LLVMReplaceAllUsesWith(LLVMValueRef OldVal, LLVMValueRef NewVal);
1279 * Determine whether the specified constant instance is constant.
1281 LLVMBool LLVMIsConstant(LLVMValueRef Val);
1284 * Determine whether a value instance is undefined.
1286 LLVMBool LLVMIsUndef(LLVMValueRef Val);
1289 * Convert value instances between types.
1291 * Internally, an LLVMValueRef is "pinned" to a specific type. This
1292 * series of functions allows you to cast an instance to a specific
1295 * If the cast is not valid for the specified type, NULL is returned.
1297 * @see llvm::dyn_cast_or_null<>
1299 #define LLVM_DECLARE_VALUE_CAST(name) \
1300 LLVMValueRef LLVMIsA##name(LLVMValueRef Val);
1301 LLVM_FOR_EACH_VALUE_SUBCLASS(LLVM_DECLARE_VALUE_CAST)
1308 * @defgroup LLVMCCoreValueUses Usage
1310 * This module defines functions that allow you to inspect the uses of a
1313 * It is possible to obtain an LLVMUseRef for any LLVMValueRef instance.
1314 * Each LLVMUseRef (which corresponds to a llvm::Use instance) holds a
1315 * llvm::User and llvm::Value.
1321 * Obtain the first use of a value.
1323 * Uses are obtained in an iterator fashion. First, call this function
1324 * to obtain a reference to the first use. Then, call LLVMGetNextUse()
1325 * on that instance and all subsequently obtained instances until
1326 * LLVMGetNextUse() returns NULL.
1328 * @see llvm::Value::use_begin()
1330 LLVMUseRef LLVMGetFirstUse(LLVMValueRef Val);
1333 * Obtain the next use of a value.
1335 * This effectively advances the iterator. It returns NULL if you are on
1336 * the final use and no more are available.
1338 LLVMUseRef LLVMGetNextUse(LLVMUseRef U);
1341 * Obtain the user value for a user.
1343 * The returned value corresponds to a llvm::User type.
1345 * @see llvm::Use::getUser()
1347 LLVMValueRef LLVMGetUser(LLVMUseRef U);
1350 * Obtain the value this use corresponds to.
1352 * @see llvm::Use::get().
1354 LLVMValueRef LLVMGetUsedValue(LLVMUseRef U);
1361 * @defgroup LLVMCCoreValueUser User value
1363 * Function in this group pertain to LLVMValueRef instances that descent
1364 * from llvm::User. This includes constants, instructions, and
1371 * Obtain an operand at a specific index in a llvm::User value.
1373 * @see llvm::User::getOperand()
1375 LLVMValueRef LLVMGetOperand(LLVMValueRef Val, unsigned Index);
1378 * Set an operand at a specific index in a llvm::User value.
1380 * @see llvm::User::setOperand()
1382 void LLVMSetOperand(LLVMValueRef User, unsigned Index, LLVMValueRef Val);
1385 * Obtain the number of operands in a llvm::User value.
1387 * @see llvm::User::getNumOperands()
1389 int LLVMGetNumOperands(LLVMValueRef Val);
1396 * @defgroup LLVMCCoreValueConstant Constants
1398 * This section contains APIs for interacting with LLVMValueRef that
1399 * correspond to llvm::Constant instances.
1401 * These functions will work for any LLVMValueRef in the llvm::Constant
1408 * Obtain a constant value referring to the null instance of a type.
1410 * @see llvm::Constant::getNullValue()
1412 LLVMValueRef LLVMConstNull(LLVMTypeRef Ty); /* all zeroes */
1415 * Obtain a constant value referring to the instance of a type
1416 * consisting of all ones.
1418 * This is only valid for integer types.
1420 * @see llvm::Constant::getAllOnesValue()
1422 LLVMValueRef LLVMConstAllOnes(LLVMTypeRef Ty);
1425 * Obtain a constant value referring to an undefined value of a type.
1427 * @see llvm::UndefValue::get()
1429 LLVMValueRef LLVMGetUndef(LLVMTypeRef Ty);
1432 * Determine whether a value instance is null.
1434 * @see llvm::Constant::isNullValue()
1436 LLVMBool LLVMIsNull(LLVMValueRef Val);
1439 * Obtain a constant that is a constant pointer pointing to NULL for a
1442 LLVMValueRef LLVMConstPointerNull(LLVMTypeRef Ty);
1445 * @defgroup LLVMCCoreValueConstantScalar Scalar constants
1447 * Functions in this group model LLVMValueRef instances that correspond
1448 * to constants referring to scalar types.
1450 * For integer types, the LLVMTypeRef parameter should correspond to a
1451 * llvm::IntegerType instance and the returned LLVMValueRef will
1452 * correspond to a llvm::ConstantInt.
1454 * For floating point types, the LLVMTypeRef returned corresponds to a
1461 * Obtain a constant value for an integer type.
1463 * The returned value corresponds to a llvm::ConstantInt.
1465 * @see llvm::ConstantInt::get()
1467 * @param IntTy Integer type to obtain value of.
1468 * @param N The value the returned instance should refer to.
1469 * @param SignExtend Whether to sign extend the produced value.
1471 LLVMValueRef LLVMConstInt(LLVMTypeRef IntTy, unsigned long long N,
1472 LLVMBool SignExtend);
1475 * Obtain a constant value for an integer of arbitrary precision.
1477 * @see llvm::ConstantInt::get()
1479 LLVMValueRef LLVMConstIntOfArbitraryPrecision(LLVMTypeRef IntTy,
1481 const uint64_t Words[]);
1484 * Obtain a constant value for an integer parsed from a string.
1486 * A similar API, LLVMConstIntOfStringAndSize is also available. If the
1487 * string's length is available, it is preferred to call that function
1490 * @see llvm::ConstantInt::get()
1492 LLVMValueRef LLVMConstIntOfString(LLVMTypeRef IntTy, const char *Text,
1496 * Obtain a constant value for an integer parsed from a string with
1499 * @see llvm::ConstantInt::get()
1501 LLVMValueRef LLVMConstIntOfStringAndSize(LLVMTypeRef IntTy, const char *Text,
1502 unsigned SLen, uint8_t Radix);
1505 * Obtain a constant value referring to a double floating point value.
1507 LLVMValueRef LLVMConstReal(LLVMTypeRef RealTy, double N);
1510 * Obtain a constant for a floating point value parsed from a string.
1512 * A similar API, LLVMConstRealOfStringAndSize is also available. It
1513 * should be used if the input string's length is known.
1515 LLVMValueRef LLVMConstRealOfString(LLVMTypeRef RealTy, const char *Text);
1518 * Obtain a constant for a floating point value parsed from a string.
1520 LLVMValueRef LLVMConstRealOfStringAndSize(LLVMTypeRef RealTy, const char *Text,
1524 * Obtain the zero extended value for an integer constant value.
1526 * @see llvm::ConstantInt::getZExtValue()
1528 unsigned long long LLVMConstIntGetZExtValue(LLVMValueRef ConstantVal);
1531 * Obtain the sign extended value for an integer constant value.
1533 * @see llvm::ConstantInt::getSExtValue()
1535 long long LLVMConstIntGetSExtValue(LLVMValueRef ConstantVal);
1542 * @defgroup LLVMCCoreValueConstantComposite Composite Constants
1544 * Functions in this group operate on composite constants.
1550 * Create a ConstantDataSequential and initialize it with a string.
1552 * @see llvm::ConstantDataArray::getString()
1554 LLVMValueRef LLVMConstStringInContext(LLVMContextRef C, const char *Str,
1555 unsigned Length, LLVMBool DontNullTerminate);
1558 * Create a ConstantDataSequential with string content in the global context.
1560 * This is the same as LLVMConstStringInContext except it operates on the
1563 * @see LLVMConstStringInContext()
1564 * @see llvm::ConstantDataArray::getString()
1566 LLVMValueRef LLVMConstString(const char *Str, unsigned Length,
1567 LLVMBool DontNullTerminate);
1570 * Create an anonymous ConstantStruct with the specified values.
1572 * @see llvm::ConstantStruct::getAnon()
1574 LLVMValueRef LLVMConstStructInContext(LLVMContextRef C,
1575 LLVMValueRef *ConstantVals,
1576 unsigned Count, LLVMBool Packed);
1579 * Create a ConstantStruct in the global Context.
1581 * This is the same as LLVMConstStructInContext except it operates on the
1584 * @see LLVMConstStructInContext()
1586 LLVMValueRef LLVMConstStruct(LLVMValueRef *ConstantVals, unsigned Count,
1590 * Create a ConstantArray from values.
1592 * @see llvm::ConstantArray::get()
1594 LLVMValueRef LLVMConstArray(LLVMTypeRef ElementTy,
1595 LLVMValueRef *ConstantVals, unsigned Length);
1598 * Create a non-anonymous ConstantStruct from values.
1600 * @see llvm::ConstantStruct::get()
1602 LLVMValueRef LLVMConstNamedStruct(LLVMTypeRef StructTy,
1603 LLVMValueRef *ConstantVals,
1607 * Create a ConstantVector from values.
1609 * @see llvm::ConstantVector::get()
1611 LLVMValueRef LLVMConstVector(LLVMValueRef *ScalarConstantVals, unsigned Size);
1618 * @defgroup LLVMCCoreValueConstantExpressions Constant Expressions
1620 * Functions in this group correspond to APIs on llvm::ConstantExpr.
1622 * @see llvm::ConstantExpr.
1626 LLVMOpcode LLVMGetConstOpcode(LLVMValueRef ConstantVal);
1627 LLVMValueRef LLVMAlignOf(LLVMTypeRef Ty);
1628 LLVMValueRef LLVMSizeOf(LLVMTypeRef Ty);
1629 LLVMValueRef LLVMConstNeg(LLVMValueRef ConstantVal);
1630 LLVMValueRef LLVMConstNSWNeg(LLVMValueRef ConstantVal);
1631 LLVMValueRef LLVMConstNUWNeg(LLVMValueRef ConstantVal);
1632 LLVMValueRef LLVMConstFNeg(LLVMValueRef ConstantVal);
1633 LLVMValueRef LLVMConstNot(LLVMValueRef ConstantVal);
1634 LLVMValueRef LLVMConstAdd(LLVMValueRef LHSConstant, LLVMValueRef RHSConstant);
1635 LLVMValueRef LLVMConstNSWAdd(LLVMValueRef LHSConstant, LLVMValueRef RHSConstant);
1636 LLVMValueRef LLVMConstNUWAdd(LLVMValueRef LHSConstant, LLVMValueRef RHSConstant);
1637 LLVMValueRef LLVMConstFAdd(LLVMValueRef LHSConstant, LLVMValueRef RHSConstant);
1638 LLVMValueRef LLVMConstSub(LLVMValueRef LHSConstant, LLVMValueRef RHSConstant);
1639 LLVMValueRef LLVMConstNSWSub(LLVMValueRef LHSConstant, LLVMValueRef RHSConstant);
1640 LLVMValueRef LLVMConstNUWSub(LLVMValueRef LHSConstant, LLVMValueRef RHSConstant);
1641 LLVMValueRef LLVMConstFSub(LLVMValueRef LHSConstant, LLVMValueRef RHSConstant);
1642 LLVMValueRef LLVMConstMul(LLVMValueRef LHSConstant, LLVMValueRef RHSConstant);
1643 LLVMValueRef LLVMConstNSWMul(LLVMValueRef LHSConstant, LLVMValueRef RHSConstant);
1644 LLVMValueRef LLVMConstNUWMul(LLVMValueRef LHSConstant, LLVMValueRef RHSConstant);
1645 LLVMValueRef LLVMConstFMul(LLVMValueRef LHSConstant, LLVMValueRef RHSConstant);
1646 LLVMValueRef LLVMConstUDiv(LLVMValueRef LHSConstant, LLVMValueRef RHSConstant);
1647 LLVMValueRef LLVMConstSDiv(LLVMValueRef LHSConstant, LLVMValueRef RHSConstant);
1648 LLVMValueRef LLVMConstExactSDiv(LLVMValueRef LHSConstant, LLVMValueRef RHSConstant);
1649 LLVMValueRef LLVMConstFDiv(LLVMValueRef LHSConstant, LLVMValueRef RHSConstant);
1650 LLVMValueRef LLVMConstURem(LLVMValueRef LHSConstant, LLVMValueRef RHSConstant);
1651 LLVMValueRef LLVMConstSRem(LLVMValueRef LHSConstant, LLVMValueRef RHSConstant);
1652 LLVMValueRef LLVMConstFRem(LLVMValueRef LHSConstant, LLVMValueRef RHSConstant);
1653 LLVMValueRef LLVMConstAnd(LLVMValueRef LHSConstant, LLVMValueRef RHSConstant);
1654 LLVMValueRef LLVMConstOr(LLVMValueRef LHSConstant, LLVMValueRef RHSConstant);
1655 LLVMValueRef LLVMConstXor(LLVMValueRef LHSConstant, LLVMValueRef RHSConstant);
1656 LLVMValueRef LLVMConstICmp(LLVMIntPredicate Predicate,
1657 LLVMValueRef LHSConstant, LLVMValueRef RHSConstant);
1658 LLVMValueRef LLVMConstFCmp(LLVMRealPredicate Predicate,
1659 LLVMValueRef LHSConstant, LLVMValueRef RHSConstant);
1660 LLVMValueRef LLVMConstShl(LLVMValueRef LHSConstant, LLVMValueRef RHSConstant);
1661 LLVMValueRef LLVMConstLShr(LLVMValueRef LHSConstant, LLVMValueRef RHSConstant);
1662 LLVMValueRef LLVMConstAShr(LLVMValueRef LHSConstant, LLVMValueRef RHSConstant);
1663 LLVMValueRef LLVMConstGEP(LLVMValueRef ConstantVal,
1664 LLVMValueRef *ConstantIndices, unsigned NumIndices);
1665 LLVMValueRef LLVMConstInBoundsGEP(LLVMValueRef ConstantVal,
1666 LLVMValueRef *ConstantIndices,
1667 unsigned NumIndices);
1668 LLVMValueRef LLVMConstTrunc(LLVMValueRef ConstantVal, LLVMTypeRef ToType);
1669 LLVMValueRef LLVMConstSExt(LLVMValueRef ConstantVal, LLVMTypeRef ToType);
1670 LLVMValueRef LLVMConstZExt(LLVMValueRef ConstantVal, LLVMTypeRef ToType);
1671 LLVMValueRef LLVMConstFPTrunc(LLVMValueRef ConstantVal, LLVMTypeRef ToType);
1672 LLVMValueRef LLVMConstFPExt(LLVMValueRef ConstantVal, LLVMTypeRef ToType);
1673 LLVMValueRef LLVMConstUIToFP(LLVMValueRef ConstantVal, LLVMTypeRef ToType);
1674 LLVMValueRef LLVMConstSIToFP(LLVMValueRef ConstantVal, LLVMTypeRef ToType);
1675 LLVMValueRef LLVMConstFPToUI(LLVMValueRef ConstantVal, LLVMTypeRef ToType);
1676 LLVMValueRef LLVMConstFPToSI(LLVMValueRef ConstantVal, LLVMTypeRef ToType);
1677 LLVMValueRef LLVMConstPtrToInt(LLVMValueRef ConstantVal, LLVMTypeRef ToType);
1678 LLVMValueRef LLVMConstIntToPtr(LLVMValueRef ConstantVal, LLVMTypeRef ToType);
1679 LLVMValueRef LLVMConstBitCast(LLVMValueRef ConstantVal, LLVMTypeRef ToType);
1680 LLVMValueRef LLVMConstAddrSpaceCast(LLVMValueRef ConstantVal, LLVMTypeRef ToType);
1681 LLVMValueRef LLVMConstZExtOrBitCast(LLVMValueRef ConstantVal,
1682 LLVMTypeRef ToType);
1683 LLVMValueRef LLVMConstSExtOrBitCast(LLVMValueRef ConstantVal,
1684 LLVMTypeRef ToType);
1685 LLVMValueRef LLVMConstTruncOrBitCast(LLVMValueRef ConstantVal,
1686 LLVMTypeRef ToType);
1687 LLVMValueRef LLVMConstPointerCast(LLVMValueRef ConstantVal,
1688 LLVMTypeRef ToType);
1689 LLVMValueRef LLVMConstIntCast(LLVMValueRef ConstantVal, LLVMTypeRef ToType,
1691 LLVMValueRef LLVMConstFPCast(LLVMValueRef ConstantVal, LLVMTypeRef ToType);
1692 LLVMValueRef LLVMConstSelect(LLVMValueRef ConstantCondition,
1693 LLVMValueRef ConstantIfTrue,
1694 LLVMValueRef ConstantIfFalse);
1695 LLVMValueRef LLVMConstExtractElement(LLVMValueRef VectorConstant,
1696 LLVMValueRef IndexConstant);
1697 LLVMValueRef LLVMConstInsertElement(LLVMValueRef VectorConstant,
1698 LLVMValueRef ElementValueConstant,
1699 LLVMValueRef IndexConstant);
1700 LLVMValueRef LLVMConstShuffleVector(LLVMValueRef VectorAConstant,
1701 LLVMValueRef VectorBConstant,
1702 LLVMValueRef MaskConstant);
1703 LLVMValueRef LLVMConstExtractValue(LLVMValueRef AggConstant, unsigned *IdxList,
1705 LLVMValueRef LLVMConstInsertValue(LLVMValueRef AggConstant,
1706 LLVMValueRef ElementValueConstant,
1707 unsigned *IdxList, unsigned NumIdx);
1708 LLVMValueRef LLVMConstInlineAsm(LLVMTypeRef Ty,
1709 const char *AsmString, const char *Constraints,
1710 LLVMBool HasSideEffects, LLVMBool IsAlignStack);
1711 LLVMValueRef LLVMBlockAddress(LLVMValueRef F, LLVMBasicBlockRef BB);
1718 * @defgroup LLVMCCoreValueConstantGlobals Global Values
1720 * This group contains functions that operate on global values. Functions in
1721 * this group relate to functions in the llvm::GlobalValue class tree.
1723 * @see llvm::GlobalValue
1728 LLVMModuleRef LLVMGetGlobalParent(LLVMValueRef Global);
1729 LLVMBool LLVMIsDeclaration(LLVMValueRef Global);
1730 LLVMLinkage LLVMGetLinkage(LLVMValueRef Global);
1731 void LLVMSetLinkage(LLVMValueRef Global, LLVMLinkage Linkage);
1732 const char *LLVMGetSection(LLVMValueRef Global);
1733 void LLVMSetSection(LLVMValueRef Global, const char *Section);
1734 LLVMVisibility LLVMGetVisibility(LLVMValueRef Global);
1735 void LLVMSetVisibility(LLVMValueRef Global, LLVMVisibility Viz);
1736 LLVMDLLStorageClass LLVMGetDLLStorageClass(LLVMValueRef Global);
1737 void LLVMSetDLLStorageClass(LLVMValueRef Global, LLVMDLLStorageClass Class);
1738 LLVMBool LLVMHasUnnamedAddr(LLVMValueRef Global);
1739 void LLVMSetUnnamedAddr(LLVMValueRef Global, LLVMBool HasUnnamedAddr);
1742 * @defgroup LLVMCCoreValueWithAlignment Values with alignment
1744 * Functions in this group only apply to values with alignment, i.e.
1745 * global variables, load and store instructions.
1749 * Obtain the preferred alignment of the value.
1750 * @see llvm::AllocaInst::getAlignment()
1751 * @see llvm::LoadInst::getAlignment()
1752 * @see llvm::StoreInst::getAlignment()
1753 * @see llvm::GlobalValue::getAlignment()
1755 unsigned LLVMGetAlignment(LLVMValueRef V);
1758 * Set the preferred alignment of the value.
1759 * @see llvm::AllocaInst::setAlignment()
1760 * @see llvm::LoadInst::setAlignment()
1761 * @see llvm::StoreInst::setAlignment()
1762 * @see llvm::GlobalValue::setAlignment()
1764 void LLVMSetAlignment(LLVMValueRef V, unsigned Bytes);
1771 * @defgroup LLVMCoreValueConstantGlobalVariable Global Variables
1773 * This group contains functions that operate on global variable values.
1775 * @see llvm::GlobalVariable
1779 LLVMValueRef LLVMAddGlobal(LLVMModuleRef M, LLVMTypeRef Ty, const char *Name);
1780 LLVMValueRef LLVMAddGlobalInAddressSpace(LLVMModuleRef M, LLVMTypeRef Ty,
1782 unsigned AddressSpace);
1783 LLVMValueRef LLVMGetNamedGlobal(LLVMModuleRef M, const char *Name);
1784 LLVMValueRef LLVMGetFirstGlobal(LLVMModuleRef M);
1785 LLVMValueRef LLVMGetLastGlobal(LLVMModuleRef M);
1786 LLVMValueRef LLVMGetNextGlobal(LLVMValueRef GlobalVar);
1787 LLVMValueRef LLVMGetPreviousGlobal(LLVMValueRef GlobalVar);
1788 void LLVMDeleteGlobal(LLVMValueRef GlobalVar);
1789 LLVMValueRef LLVMGetInitializer(LLVMValueRef GlobalVar);
1790 void LLVMSetInitializer(LLVMValueRef GlobalVar, LLVMValueRef ConstantVal);
1791 LLVMBool LLVMIsThreadLocal(LLVMValueRef GlobalVar);
1792 void LLVMSetThreadLocal(LLVMValueRef GlobalVar, LLVMBool IsThreadLocal);
1793 LLVMBool LLVMIsGlobalConstant(LLVMValueRef GlobalVar);
1794 void LLVMSetGlobalConstant(LLVMValueRef GlobalVar, LLVMBool IsConstant);
1795 LLVMThreadLocalMode LLVMGetThreadLocalMode(LLVMValueRef GlobalVar);
1796 void LLVMSetThreadLocalMode(LLVMValueRef GlobalVar, LLVMThreadLocalMode Mode);
1797 LLVMBool LLVMIsExternallyInitialized(LLVMValueRef GlobalVar);
1798 void LLVMSetExternallyInitialized(LLVMValueRef GlobalVar, LLVMBool IsExtInit);
1805 * @defgroup LLVMCoreValueConstantGlobalAlias Global Aliases
1807 * This group contains function that operate on global alias values.
1809 * @see llvm::GlobalAlias
1813 LLVMValueRef LLVMAddAlias(LLVMModuleRef M, LLVMTypeRef Ty, LLVMValueRef Aliasee,
1821 * @defgroup LLVMCCoreValueFunction Function values
1823 * Functions in this group operate on LLVMValueRef instances that
1824 * correspond to llvm::Function instances.
1826 * @see llvm::Function
1832 * Remove a function from its containing module and deletes it.
1834 * @see llvm::Function::eraseFromParent()
1836 void LLVMDeleteFunction(LLVMValueRef Fn);
1839 * Obtain the ID number from a function instance.
1841 * @see llvm::Function::getIntrinsicID()
1843 unsigned LLVMGetIntrinsicID(LLVMValueRef Fn);
1846 * Obtain the calling function of a function.
1848 * The returned value corresponds to the LLVMCallConv enumeration.
1850 * @see llvm::Function::getCallingConv()
1852 unsigned LLVMGetFunctionCallConv(LLVMValueRef Fn);
1855 * Set the calling convention of a function.
1857 * @see llvm::Function::setCallingConv()
1859 * @param Fn Function to operate on
1860 * @param CC LLVMCallConv to set calling convention to
1862 void LLVMSetFunctionCallConv(LLVMValueRef Fn, unsigned CC);
1865 * Obtain the name of the garbage collector to use during code
1868 * @see llvm::Function::getGC()
1870 const char *LLVMGetGC(LLVMValueRef Fn);
1873 * Define the garbage collector to use during code generation.
1875 * @see llvm::Function::setGC()
1877 void LLVMSetGC(LLVMValueRef Fn, const char *Name);
1880 * Add an attribute to a function.
1882 * @see llvm::Function::addAttribute()
1884 void LLVMAddFunctionAttr(LLVMValueRef Fn, LLVMAttribute PA);
1887 * Add a target-dependent attribute to a fuction
1888 * @see llvm::AttrBuilder::addAttribute()
1890 void LLVMAddTargetDependentFunctionAttr(LLVMValueRef Fn, const char *A,
1894 * Obtain an attribute from a function.
1896 * @see llvm::Function::getAttributes()
1898 LLVMAttribute LLVMGetFunctionAttr(LLVMValueRef Fn);
1901 * Remove an attribute from a function.
1903 void LLVMRemoveFunctionAttr(LLVMValueRef Fn, LLVMAttribute PA);
1906 * @defgroup LLVMCCoreValueFunctionParameters Function Parameters
1908 * Functions in this group relate to arguments/parameters on functions.
1910 * Functions in this group expect LLVMValueRef instances that correspond
1911 * to llvm::Function instances.
1917 * Obtain the number of parameters in a function.
1919 * @see llvm::Function::arg_size()
1921 unsigned LLVMCountParams(LLVMValueRef Fn);
1924 * Obtain the parameters in a function.
1926 * The takes a pointer to a pre-allocated array of LLVMValueRef that is
1927 * at least LLVMCountParams() long. This array will be filled with
1928 * LLVMValueRef instances which correspond to the parameters the
1929 * function receives. Each LLVMValueRef corresponds to a llvm::Argument
1932 * @see llvm::Function::arg_begin()
1934 void LLVMGetParams(LLVMValueRef Fn, LLVMValueRef *Params);
1937 * Obtain the parameter at the specified index.
1939 * Parameters are indexed from 0.
1941 * @see llvm::Function::arg_begin()
1943 LLVMValueRef LLVMGetParam(LLVMValueRef Fn, unsigned Index);
1946 * Obtain the function to which this argument belongs.
1948 * Unlike other functions in this group, this one takes an LLVMValueRef
1949 * that corresponds to a llvm::Attribute.
1951 * The returned LLVMValueRef is the llvm::Function to which this
1954 LLVMValueRef LLVMGetParamParent(LLVMValueRef Inst);
1957 * Obtain the first parameter to a function.
1959 * @see llvm::Function::arg_begin()
1961 LLVMValueRef LLVMGetFirstParam(LLVMValueRef Fn);
1964 * Obtain the last parameter to a function.
1966 * @see llvm::Function::arg_end()
1968 LLVMValueRef LLVMGetLastParam(LLVMValueRef Fn);
1971 * Obtain the next parameter to a function.
1973 * This takes an LLVMValueRef obtained from LLVMGetFirstParam() (which is
1974 * actually a wrapped iterator) and obtains the next parameter from the
1975 * underlying iterator.
1977 LLVMValueRef LLVMGetNextParam(LLVMValueRef Arg);
1980 * Obtain the previous parameter to a function.
1982 * This is the opposite of LLVMGetNextParam().
1984 LLVMValueRef LLVMGetPreviousParam(LLVMValueRef Arg);
1987 * Add an attribute to a function argument.
1989 * @see llvm::Argument::addAttr()
1991 void LLVMAddAttribute(LLVMValueRef Arg, LLVMAttribute PA);
1994 * Remove an attribute from a function argument.
1996 * @see llvm::Argument::removeAttr()
1998 void LLVMRemoveAttribute(LLVMValueRef Arg, LLVMAttribute PA);
2001 * Get an attribute from a function argument.
2003 LLVMAttribute LLVMGetAttribute(LLVMValueRef Arg);
2006 * Set the alignment for a function parameter.
2008 * @see llvm::Argument::addAttr()
2009 * @see llvm::AttrBuilder::addAlignmentAttr()
2011 void LLVMSetParamAlignment(LLVMValueRef Arg, unsigned align);
2030 * @defgroup LLVMCCoreValueMetadata Metadata
2036 * Obtain a MDString value from a context.
2038 * The returned instance corresponds to the llvm::MDString class.
2040 * The instance is specified by string data of a specified length. The
2041 * string content is copied, so the backing memory can be freed after
2042 * this function returns.
2044 LLVMValueRef LLVMMDStringInContext(LLVMContextRef C, const char *Str,
2048 * Obtain a MDString value from the global context.
2050 LLVMValueRef LLVMMDString(const char *Str, unsigned SLen);
2053 * Obtain a MDNode value from a context.
2055 * The returned value corresponds to the llvm::MDNode class.
2057 LLVMValueRef LLVMMDNodeInContext(LLVMContextRef C, LLVMValueRef *Vals,
2061 * Obtain a MDNode value from the global context.
2063 LLVMValueRef LLVMMDNode(LLVMValueRef *Vals, unsigned Count);
2066 * Obtain the underlying string from a MDString value.
2068 * @param V Instance to obtain string from.
2069 * @param Len Memory address which will hold length of returned string.
2070 * @return String data in MDString.
2072 const char *LLVMGetMDString(LLVMValueRef V, unsigned* Len);
2075 * Obtain the number of operands from an MDNode value.
2077 * @param V MDNode to get number of operands from.
2078 * @return Number of operands of the MDNode.
2080 unsigned LLVMGetMDNodeNumOperands(LLVMValueRef V);
2083 * Obtain the given MDNode's operands.
2085 * The passed LLVMValueRef pointer should point to enough memory to hold all of
2086 * the operands of the given MDNode (see LLVMGetMDNodeNumOperands) as
2087 * LLVMValueRefs. This memory will be populated with the LLVMValueRefs of the
2088 * MDNode's operands.
2090 * @param V MDNode to get the operands from.
2091 * @param Dest Destination array for operands.
2093 void LLVMGetMDNodeOperands(LLVMValueRef V, LLVMValueRef *Dest);
2100 * @defgroup LLVMCCoreValueBasicBlock Basic Block
2102 * A basic block represents a single entry single exit section of code.
2103 * Basic blocks contain a list of instructions which form the body of
2106 * Basic blocks belong to functions. They have the type of label.
2108 * Basic blocks are themselves values. However, the C API models them as
2109 * LLVMBasicBlockRef.
2111 * @see llvm::BasicBlock
2117 * Convert a basic block instance to a value type.
2119 LLVMValueRef LLVMBasicBlockAsValue(LLVMBasicBlockRef BB);
2122 * Determine whether an LLVMValueRef is itself a basic block.
2124 LLVMBool LLVMValueIsBasicBlock(LLVMValueRef Val);
2127 * Convert an LLVMValueRef to an LLVMBasicBlockRef instance.
2129 LLVMBasicBlockRef LLVMValueAsBasicBlock(LLVMValueRef Val);
2132 * Obtain the function to which a basic block belongs.
2134 * @see llvm::BasicBlock::getParent()
2136 LLVMValueRef LLVMGetBasicBlockParent(LLVMBasicBlockRef BB);
2139 * Obtain the terminator instruction for a basic block.
2141 * If the basic block does not have a terminator (it is not well-formed
2142 * if it doesn't), then NULL is returned.
2144 * The returned LLVMValueRef corresponds to a llvm::TerminatorInst.
2146 * @see llvm::BasicBlock::getTerminator()
2148 LLVMValueRef LLVMGetBasicBlockTerminator(LLVMBasicBlockRef BB);
2151 * Obtain the number of basic blocks in a function.
2153 * @param Fn Function value to operate on.
2155 unsigned LLVMCountBasicBlocks(LLVMValueRef Fn);
2158 * Obtain all of the basic blocks in a function.
2160 * This operates on a function value. The BasicBlocks parameter is a
2161 * pointer to a pre-allocated array of LLVMBasicBlockRef of at least
2162 * LLVMCountBasicBlocks() in length. This array is populated with
2163 * LLVMBasicBlockRef instances.
2165 void LLVMGetBasicBlocks(LLVMValueRef Fn, LLVMBasicBlockRef *BasicBlocks);
2168 * Obtain the first basic block in a function.
2170 * The returned basic block can be used as an iterator. You will likely
2171 * eventually call into LLVMGetNextBasicBlock() with it.
2173 * @see llvm::Function::begin()
2175 LLVMBasicBlockRef LLVMGetFirstBasicBlock(LLVMValueRef Fn);
2178 * Obtain the last basic block in a function.
2180 * @see llvm::Function::end()
2182 LLVMBasicBlockRef LLVMGetLastBasicBlock(LLVMValueRef Fn);
2185 * Advance a basic block iterator.
2187 LLVMBasicBlockRef LLVMGetNextBasicBlock(LLVMBasicBlockRef BB);
2190 * Go backwards in a basic block iterator.
2192 LLVMBasicBlockRef LLVMGetPreviousBasicBlock(LLVMBasicBlockRef BB);
2195 * Obtain the basic block that corresponds to the entry point of a
2198 * @see llvm::Function::getEntryBlock()
2200 LLVMBasicBlockRef LLVMGetEntryBasicBlock(LLVMValueRef Fn);
2203 * Append a basic block to the end of a function.
2205 * @see llvm::BasicBlock::Create()
2207 LLVMBasicBlockRef LLVMAppendBasicBlockInContext(LLVMContextRef C,
2212 * Append a basic block to the end of a function using the global
2215 * @see llvm::BasicBlock::Create()
2217 LLVMBasicBlockRef LLVMAppendBasicBlock(LLVMValueRef Fn, const char *Name);
2220 * Insert a basic block in a function before another basic block.
2222 * The function to add to is determined by the function of the
2223 * passed basic block.
2225 * @see llvm::BasicBlock::Create()
2227 LLVMBasicBlockRef LLVMInsertBasicBlockInContext(LLVMContextRef C,
2228 LLVMBasicBlockRef BB,
2232 * Insert a basic block in a function using the global context.
2234 * @see llvm::BasicBlock::Create()
2236 LLVMBasicBlockRef LLVMInsertBasicBlock(LLVMBasicBlockRef InsertBeforeBB,
2240 * Remove a basic block from a function and delete it.
2242 * This deletes the basic block from its containing function and deletes
2243 * the basic block itself.
2245 * @see llvm::BasicBlock::eraseFromParent()
2247 void LLVMDeleteBasicBlock(LLVMBasicBlockRef BB);
2250 * Remove a basic block from a function.
2252 * This deletes the basic block from its containing function but keep
2253 * the basic block alive.
2255 * @see llvm::BasicBlock::removeFromParent()
2257 void LLVMRemoveBasicBlockFromParent(LLVMBasicBlockRef BB);
2260 * Move a basic block to before another one.
2262 * @see llvm::BasicBlock::moveBefore()
2264 void LLVMMoveBasicBlockBefore(LLVMBasicBlockRef BB, LLVMBasicBlockRef MovePos);
2267 * Move a basic block to after another one.
2269 * @see llvm::BasicBlock::moveAfter()
2271 void LLVMMoveBasicBlockAfter(LLVMBasicBlockRef BB, LLVMBasicBlockRef MovePos);
2274 * Obtain the first instruction in a basic block.
2276 * The returned LLVMValueRef corresponds to a llvm::Instruction
2279 LLVMValueRef LLVMGetFirstInstruction(LLVMBasicBlockRef BB);
2282 * Obtain the last instruction in a basic block.
2284 * The returned LLVMValueRef corresponds to an LLVM:Instruction.
2286 LLVMValueRef LLVMGetLastInstruction(LLVMBasicBlockRef BB);
2293 * @defgroup LLVMCCoreValueInstruction Instructions
2295 * Functions in this group relate to the inspection and manipulation of
2296 * individual instructions.
2298 * In the C++ API, an instruction is modeled by llvm::Instruction. This
2299 * class has a large number of descendents. llvm::Instruction is a
2300 * llvm::Value and in the C API, instructions are modeled by
2303 * This group also contains sub-groups which operate on specific
2304 * llvm::Instruction types, e.g. llvm::CallInst.
2310 * Determine whether an instruction has any metadata attached.
2312 int LLVMHasMetadata(LLVMValueRef Val);
2315 * Return metadata associated with an instruction value.
2317 LLVMValueRef LLVMGetMetadata(LLVMValueRef Val, unsigned KindID);
2320 * Set metadata associated with an instruction value.
2322 void LLVMSetMetadata(LLVMValueRef Val, unsigned KindID, LLVMValueRef Node);
2325 * Obtain the basic block to which an instruction belongs.
2327 * @see llvm::Instruction::getParent()
2329 LLVMBasicBlockRef LLVMGetInstructionParent(LLVMValueRef Inst);
2332 * Obtain the instruction that occurs after the one specified.
2334 * The next instruction will be from the same basic block.
2336 * If this is the last instruction in a basic block, NULL will be
2339 LLVMValueRef LLVMGetNextInstruction(LLVMValueRef Inst);
2342 * Obtain the instruction that occurred before this one.
2344 * If the instruction is the first instruction in a basic block, NULL
2347 LLVMValueRef LLVMGetPreviousInstruction(LLVMValueRef Inst);
2350 * Remove and delete an instruction.
2352 * The instruction specified is removed from its containing building
2353 * block and then deleted.
2355 * @see llvm::Instruction::eraseFromParent()
2357 void LLVMInstructionEraseFromParent(LLVMValueRef Inst);
2360 * Obtain the code opcode for an individual instruction.
2362 * @see llvm::Instruction::getOpCode()
2364 LLVMOpcode LLVMGetInstructionOpcode(LLVMValueRef Inst);
2367 * Obtain the predicate of an instruction.
2369 * This is only valid for instructions that correspond to llvm::ICmpInst
2370 * or llvm::ConstantExpr whose opcode is llvm::Instruction::ICmp.
2372 * @see llvm::ICmpInst::getPredicate()
2374 LLVMIntPredicate LLVMGetICmpPredicate(LLVMValueRef Inst);
2377 * @defgroup LLVMCCoreValueInstructionCall Call Sites and Invocations
2379 * Functions in this group apply to instructions that refer to call
2380 * sites and invocations. These correspond to C++ types in the
2381 * llvm::CallInst class tree.
2387 * Set the calling convention for a call instruction.
2389 * This expects an LLVMValueRef that corresponds to a llvm::CallInst or
2392 * @see llvm::CallInst::setCallingConv()
2393 * @see llvm::InvokeInst::setCallingConv()
2395 void LLVMSetInstructionCallConv(LLVMValueRef Instr, unsigned CC);
2398 * Obtain the calling convention for a call instruction.
2400 * This is the opposite of LLVMSetInstructionCallConv(). Reads its
2403 * @see LLVMSetInstructionCallConv()
2405 unsigned LLVMGetInstructionCallConv(LLVMValueRef Instr);
2408 void LLVMAddInstrAttribute(LLVMValueRef Instr, unsigned index, LLVMAttribute);
2409 void LLVMRemoveInstrAttribute(LLVMValueRef Instr, unsigned index,
2411 void LLVMSetInstrParamAlignment(LLVMValueRef Instr, unsigned index,
2415 * Obtain whether a call instruction is a tail call.
2417 * This only works on llvm::CallInst instructions.
2419 * @see llvm::CallInst::isTailCall()
2421 LLVMBool LLVMIsTailCall(LLVMValueRef CallInst);
2424 * Set whether a call instruction is a tail call.
2426 * This only works on llvm::CallInst instructions.
2428 * @see llvm::CallInst::setTailCall()
2430 void LLVMSetTailCall(LLVMValueRef CallInst, LLVMBool IsTailCall);
2437 * Obtain the default destination basic block of a switch instruction.
2439 * This only works on llvm::SwitchInst instructions.
2441 * @see llvm::SwitchInst::getDefaultDest()
2443 LLVMBasicBlockRef LLVMGetSwitchDefaultDest(LLVMValueRef SwitchInstr);
2446 * @defgroup LLVMCCoreValueInstructionPHINode PHI Nodes
2448 * Functions in this group only apply to instructions that map to
2449 * llvm::PHINode instances.
2455 * Add an incoming value to the end of a PHI list.
2457 void LLVMAddIncoming(LLVMValueRef PhiNode, LLVMValueRef *IncomingValues,
2458 LLVMBasicBlockRef *IncomingBlocks, unsigned Count);
2461 * Obtain the number of incoming basic blocks to a PHI node.
2463 unsigned LLVMCountIncoming(LLVMValueRef PhiNode);
2466 * Obtain an incoming value to a PHI node as an LLVMValueRef.
2468 LLVMValueRef LLVMGetIncomingValue(LLVMValueRef PhiNode, unsigned Index);
2471 * Obtain an incoming value to a PHI node as an LLVMBasicBlockRef.
2473 LLVMBasicBlockRef LLVMGetIncomingBlock(LLVMValueRef PhiNode, unsigned Index);
2488 * @defgroup LLVMCCoreInstructionBuilder Instruction Builders
2490 * An instruction builder represents a point within a basic block and is
2491 * the exclusive means of building instructions using the C interface.
2496 LLVMBuilderRef LLVMCreateBuilderInContext(LLVMContextRef C);
2497 LLVMBuilderRef LLVMCreateBuilder(void);
2498 void LLVMPositionBuilder(LLVMBuilderRef Builder, LLVMBasicBlockRef Block,
2499 LLVMValueRef Instr);
2500 void LLVMPositionBuilderBefore(LLVMBuilderRef Builder, LLVMValueRef Instr);
2501 void LLVMPositionBuilderAtEnd(LLVMBuilderRef Builder, LLVMBasicBlockRef Block);
2502 LLVMBasicBlockRef LLVMGetInsertBlock(LLVMBuilderRef Builder);
2503 void LLVMClearInsertionPosition(LLVMBuilderRef Builder);
2504 void LLVMInsertIntoBuilder(LLVMBuilderRef Builder, LLVMValueRef Instr);
2505 void LLVMInsertIntoBuilderWithName(LLVMBuilderRef Builder, LLVMValueRef Instr,
2507 void LLVMDisposeBuilder(LLVMBuilderRef Builder);
2510 void LLVMSetCurrentDebugLocation(LLVMBuilderRef Builder, LLVMValueRef L);
2511 LLVMValueRef LLVMGetCurrentDebugLocation(LLVMBuilderRef Builder);
2512 void LLVMSetInstDebugLocation(LLVMBuilderRef Builder, LLVMValueRef Inst);
2515 LLVMValueRef LLVMBuildRetVoid(LLVMBuilderRef);
2516 LLVMValueRef LLVMBuildRet(LLVMBuilderRef, LLVMValueRef V);
2517 LLVMValueRef LLVMBuildAggregateRet(LLVMBuilderRef, LLVMValueRef *RetVals,
2519 LLVMValueRef LLVMBuildBr(LLVMBuilderRef, LLVMBasicBlockRef Dest);
2520 LLVMValueRef LLVMBuildCondBr(LLVMBuilderRef, LLVMValueRef If,
2521 LLVMBasicBlockRef Then, LLVMBasicBlockRef Else);
2522 LLVMValueRef LLVMBuildSwitch(LLVMBuilderRef, LLVMValueRef V,
2523 LLVMBasicBlockRef Else, unsigned NumCases);
2524 LLVMValueRef LLVMBuildIndirectBr(LLVMBuilderRef B, LLVMValueRef Addr,
2526 LLVMValueRef LLVMBuildInvoke(LLVMBuilderRef, LLVMValueRef Fn,
2527 LLVMValueRef *Args, unsigned NumArgs,
2528 LLVMBasicBlockRef Then, LLVMBasicBlockRef Catch,
2530 LLVMValueRef LLVMBuildLandingPad(LLVMBuilderRef B, LLVMTypeRef Ty,
2531 LLVMValueRef PersFn, unsigned NumClauses,
2533 LLVMValueRef LLVMBuildResume(LLVMBuilderRef B, LLVMValueRef Exn);
2534 LLVMValueRef LLVMBuildUnreachable(LLVMBuilderRef);
2536 /* Add a case to the switch instruction */
2537 void LLVMAddCase(LLVMValueRef Switch, LLVMValueRef OnVal,
2538 LLVMBasicBlockRef Dest);
2540 /* Add a destination to the indirectbr instruction */
2541 void LLVMAddDestination(LLVMValueRef IndirectBr, LLVMBasicBlockRef Dest);
2543 /* Add a catch or filter clause to the landingpad instruction */
2544 void LLVMAddClause(LLVMValueRef LandingPad, LLVMValueRef ClauseVal);
2546 /* Set the 'cleanup' flag in the landingpad instruction */
2547 void LLVMSetCleanup(LLVMValueRef LandingPad, LLVMBool Val);
2550 LLVMValueRef LLVMBuildAdd(LLVMBuilderRef, LLVMValueRef LHS, LLVMValueRef RHS,
2552 LLVMValueRef LLVMBuildNSWAdd(LLVMBuilderRef, LLVMValueRef LHS, LLVMValueRef RHS,
2554 LLVMValueRef LLVMBuildNUWAdd(LLVMBuilderRef, LLVMValueRef LHS, LLVMValueRef RHS,
2556 LLVMValueRef LLVMBuildFAdd(LLVMBuilderRef, LLVMValueRef LHS, LLVMValueRef RHS,
2558 LLVMValueRef LLVMBuildSub(LLVMBuilderRef, LLVMValueRef LHS, LLVMValueRef RHS,
2560 LLVMValueRef LLVMBuildNSWSub(LLVMBuilderRef, LLVMValueRef LHS, LLVMValueRef RHS,
2562 LLVMValueRef LLVMBuildNUWSub(LLVMBuilderRef, LLVMValueRef LHS, LLVMValueRef RHS,
2564 LLVMValueRef LLVMBuildFSub(LLVMBuilderRef, LLVMValueRef LHS, LLVMValueRef RHS,
2566 LLVMValueRef LLVMBuildMul(LLVMBuilderRef, LLVMValueRef LHS, LLVMValueRef RHS,
2568 LLVMValueRef LLVMBuildNSWMul(LLVMBuilderRef, LLVMValueRef LHS, LLVMValueRef RHS,
2570 LLVMValueRef LLVMBuildNUWMul(LLVMBuilderRef, LLVMValueRef LHS, LLVMValueRef RHS,
2572 LLVMValueRef LLVMBuildFMul(LLVMBuilderRef, LLVMValueRef LHS, LLVMValueRef RHS,
2574 LLVMValueRef LLVMBuildUDiv(LLVMBuilderRef, LLVMValueRef LHS, LLVMValueRef RHS,
2576 LLVMValueRef LLVMBuildSDiv(LLVMBuilderRef, LLVMValueRef LHS, LLVMValueRef RHS,
2578 LLVMValueRef LLVMBuildExactSDiv(LLVMBuilderRef, LLVMValueRef LHS, LLVMValueRef RHS,
2580 LLVMValueRef LLVMBuildFDiv(LLVMBuilderRef, LLVMValueRef LHS, LLVMValueRef RHS,
2582 LLVMValueRef LLVMBuildURem(LLVMBuilderRef, LLVMValueRef LHS, LLVMValueRef RHS,
2584 LLVMValueRef LLVMBuildSRem(LLVMBuilderRef, LLVMValueRef LHS, LLVMValueRef RHS,
2586 LLVMValueRef LLVMBuildFRem(LLVMBuilderRef, LLVMValueRef LHS, LLVMValueRef RHS,
2588 LLVMValueRef LLVMBuildShl(LLVMBuilderRef, LLVMValueRef LHS, LLVMValueRef RHS,
2590 LLVMValueRef LLVMBuildLShr(LLVMBuilderRef, LLVMValueRef LHS, LLVMValueRef RHS,
2592 LLVMValueRef LLVMBuildAShr(LLVMBuilderRef, LLVMValueRef LHS, LLVMValueRef RHS,
2594 LLVMValueRef LLVMBuildAnd(LLVMBuilderRef, LLVMValueRef LHS, LLVMValueRef RHS,
2596 LLVMValueRef LLVMBuildOr(LLVMBuilderRef, LLVMValueRef LHS, LLVMValueRef RHS,
2598 LLVMValueRef LLVMBuildXor(LLVMBuilderRef, LLVMValueRef LHS, LLVMValueRef RHS,
2600 LLVMValueRef LLVMBuildBinOp(LLVMBuilderRef B, LLVMOpcode Op,
2601 LLVMValueRef LHS, LLVMValueRef RHS,
2603 LLVMValueRef LLVMBuildNeg(LLVMBuilderRef, LLVMValueRef V, const char *Name);
2604 LLVMValueRef LLVMBuildNSWNeg(LLVMBuilderRef B, LLVMValueRef V,
2606 LLVMValueRef LLVMBuildNUWNeg(LLVMBuilderRef B, LLVMValueRef V,
2608 LLVMValueRef LLVMBuildFNeg(LLVMBuilderRef, LLVMValueRef V, const char *Name);
2609 LLVMValueRef LLVMBuildNot(LLVMBuilderRef, LLVMValueRef V, const char *Name);
2612 LLVMValueRef LLVMBuildMalloc(LLVMBuilderRef, LLVMTypeRef Ty, const char *Name);
2613 LLVMValueRef LLVMBuildArrayMalloc(LLVMBuilderRef, LLVMTypeRef Ty,
2614 LLVMValueRef Val, const char *Name);
2615 LLVMValueRef LLVMBuildAlloca(LLVMBuilderRef, LLVMTypeRef Ty, const char *Name);
2616 LLVMValueRef LLVMBuildArrayAlloca(LLVMBuilderRef, LLVMTypeRef Ty,
2617 LLVMValueRef Val, const char *Name);
2618 LLVMValueRef LLVMBuildFree(LLVMBuilderRef, LLVMValueRef PointerVal);
2619 LLVMValueRef LLVMBuildLoad(LLVMBuilderRef, LLVMValueRef PointerVal,
2621 LLVMValueRef LLVMBuildStore(LLVMBuilderRef, LLVMValueRef Val, LLVMValueRef Ptr);
2622 LLVMValueRef LLVMBuildGEP(LLVMBuilderRef B, LLVMValueRef Pointer,
2623 LLVMValueRef *Indices, unsigned NumIndices,
2625 LLVMValueRef LLVMBuildInBoundsGEP(LLVMBuilderRef B, LLVMValueRef Pointer,
2626 LLVMValueRef *Indices, unsigned NumIndices,
2628 LLVMValueRef LLVMBuildStructGEP(LLVMBuilderRef B, LLVMValueRef Pointer,
2629 unsigned Idx, const char *Name);
2630 LLVMValueRef LLVMBuildGlobalString(LLVMBuilderRef B, const char *Str,
2632 LLVMValueRef LLVMBuildGlobalStringPtr(LLVMBuilderRef B, const char *Str,
2634 LLVMBool LLVMGetVolatile(LLVMValueRef MemoryAccessInst);
2635 void LLVMSetVolatile(LLVMValueRef MemoryAccessInst, LLVMBool IsVolatile);
2638 LLVMValueRef LLVMBuildTrunc(LLVMBuilderRef, LLVMValueRef Val,
2639 LLVMTypeRef DestTy, const char *Name);
2640 LLVMValueRef LLVMBuildZExt(LLVMBuilderRef, LLVMValueRef Val,
2641 LLVMTypeRef DestTy, const char *Name);
2642 LLVMValueRef LLVMBuildSExt(LLVMBuilderRef, LLVMValueRef Val,
2643 LLVMTypeRef DestTy, const char *Name);
2644 LLVMValueRef LLVMBuildFPToUI(LLVMBuilderRef, LLVMValueRef Val,
2645 LLVMTypeRef DestTy, const char *Name);
2646 LLVMValueRef LLVMBuildFPToSI(LLVMBuilderRef, LLVMValueRef Val,
2647 LLVMTypeRef DestTy, const char *Name);
2648 LLVMValueRef LLVMBuildUIToFP(LLVMBuilderRef, LLVMValueRef Val,
2649 LLVMTypeRef DestTy, const char *Name);
2650 LLVMValueRef LLVMBuildSIToFP(LLVMBuilderRef, LLVMValueRef Val,
2651 LLVMTypeRef DestTy, const char *Name);
2652 LLVMValueRef LLVMBuildFPTrunc(LLVMBuilderRef, LLVMValueRef Val,
2653 LLVMTypeRef DestTy, const char *Name);
2654 LLVMValueRef LLVMBuildFPExt(LLVMBuilderRef, LLVMValueRef Val,
2655 LLVMTypeRef DestTy, const char *Name);
2656 LLVMValueRef LLVMBuildPtrToInt(LLVMBuilderRef, LLVMValueRef Val,
2657 LLVMTypeRef DestTy, const char *Name);
2658 LLVMValueRef LLVMBuildIntToPtr(LLVMBuilderRef, LLVMValueRef Val,
2659 LLVMTypeRef DestTy, const char *Name);
2660 LLVMValueRef LLVMBuildBitCast(LLVMBuilderRef, LLVMValueRef Val,
2661 LLVMTypeRef DestTy, const char *Name);
2662 LLVMValueRef LLVMBuildAddrSpaceCast(LLVMBuilderRef, LLVMValueRef Val,
2663 LLVMTypeRef DestTy, const char *Name);
2664 LLVMValueRef LLVMBuildZExtOrBitCast(LLVMBuilderRef, LLVMValueRef Val,
2665 LLVMTypeRef DestTy, const char *Name);
2666 LLVMValueRef LLVMBuildSExtOrBitCast(LLVMBuilderRef, LLVMValueRef Val,
2667 LLVMTypeRef DestTy, const char *Name);
2668 LLVMValueRef LLVMBuildTruncOrBitCast(LLVMBuilderRef, LLVMValueRef Val,
2669 LLVMTypeRef DestTy, const char *Name);
2670 LLVMValueRef LLVMBuildCast(LLVMBuilderRef B, LLVMOpcode Op, LLVMValueRef Val,
2671 LLVMTypeRef DestTy, const char *Name);
2672 LLVMValueRef LLVMBuildPointerCast(LLVMBuilderRef, LLVMValueRef Val,
2673 LLVMTypeRef DestTy, const char *Name);
2674 LLVMValueRef LLVMBuildIntCast(LLVMBuilderRef, LLVMValueRef Val, /*Signed cast!*/
2675 LLVMTypeRef DestTy, const char *Name);
2676 LLVMValueRef LLVMBuildFPCast(LLVMBuilderRef, LLVMValueRef Val,
2677 LLVMTypeRef DestTy, const char *Name);
2680 LLVMValueRef LLVMBuildICmp(LLVMBuilderRef, LLVMIntPredicate Op,
2681 LLVMValueRef LHS, LLVMValueRef RHS,
2683 LLVMValueRef LLVMBuildFCmp(LLVMBuilderRef, LLVMRealPredicate Op,
2684 LLVMValueRef LHS, LLVMValueRef RHS,
2687 /* Miscellaneous instructions */
2688 LLVMValueRef LLVMBuildPhi(LLVMBuilderRef, LLVMTypeRef Ty, const char *Name);
2689 LLVMValueRef LLVMBuildCall(LLVMBuilderRef, LLVMValueRef Fn,
2690 LLVMValueRef *Args, unsigned NumArgs,
2692 LLVMValueRef LLVMBuildSelect(LLVMBuilderRef, LLVMValueRef If,
2693 LLVMValueRef Then, LLVMValueRef Else,
2695 LLVMValueRef LLVMBuildVAArg(LLVMBuilderRef, LLVMValueRef List, LLVMTypeRef Ty,
2697 LLVMValueRef LLVMBuildExtractElement(LLVMBuilderRef, LLVMValueRef VecVal,
2698 LLVMValueRef Index, const char *Name);
2699 LLVMValueRef LLVMBuildInsertElement(LLVMBuilderRef, LLVMValueRef VecVal,
2700 LLVMValueRef EltVal, LLVMValueRef Index,
2702 LLVMValueRef LLVMBuildShuffleVector(LLVMBuilderRef, LLVMValueRef V1,
2703 LLVMValueRef V2, LLVMValueRef Mask,
2705 LLVMValueRef LLVMBuildExtractValue(LLVMBuilderRef, LLVMValueRef AggVal,
2706 unsigned Index, const char *Name);
2707 LLVMValueRef LLVMBuildInsertValue(LLVMBuilderRef, LLVMValueRef AggVal,
2708 LLVMValueRef EltVal, unsigned Index,
2711 LLVMValueRef LLVMBuildIsNull(LLVMBuilderRef, LLVMValueRef Val,
2713 LLVMValueRef LLVMBuildIsNotNull(LLVMBuilderRef, LLVMValueRef Val,
2715 LLVMValueRef LLVMBuildPtrDiff(LLVMBuilderRef, LLVMValueRef LHS,
2716 LLVMValueRef RHS, const char *Name);
2717 LLVMValueRef LLVMBuildFence(LLVMBuilderRef B, LLVMAtomicOrdering ordering,
2718 LLVMBool singleThread, const char *Name);
2719 LLVMValueRef LLVMBuildAtomicRMW(LLVMBuilderRef B, LLVMAtomicRMWBinOp op,
2720 LLVMValueRef PTR, LLVMValueRef Val,
2721 LLVMAtomicOrdering ordering,
2722 LLVMBool singleThread);
2729 * @defgroup LLVMCCoreModuleProvider Module Providers
2735 * Changes the type of M so it can be passed to FunctionPassManagers and the
2736 * JIT. They take ModuleProviders for historical reasons.
2738 LLVMModuleProviderRef
2739 LLVMCreateModuleProviderForExistingModule(LLVMModuleRef M);
2742 * Destroys the module M.
2744 void LLVMDisposeModuleProvider(LLVMModuleProviderRef M);
2751 * @defgroup LLVMCCoreMemoryBuffers Memory Buffers
2756 LLVMBool LLVMCreateMemoryBufferWithContentsOfFile(const char *Path,
2757 LLVMMemoryBufferRef *OutMemBuf,
2759 LLVMBool LLVMCreateMemoryBufferWithSTDIN(LLVMMemoryBufferRef *OutMemBuf,
2761 LLVMMemoryBufferRef LLVMCreateMemoryBufferWithMemoryRange(const char *InputData,
2762 size_t InputDataLength,
2763 const char *BufferName,
2764 LLVMBool RequiresNullTerminator);
2765 LLVMMemoryBufferRef LLVMCreateMemoryBufferWithMemoryRangeCopy(const char *InputData,
2766 size_t InputDataLength,
2767 const char *BufferName);
2768 const char *LLVMGetBufferStart(LLVMMemoryBufferRef MemBuf);
2769 size_t LLVMGetBufferSize(LLVMMemoryBufferRef MemBuf);
2770 void LLVMDisposeMemoryBuffer(LLVMMemoryBufferRef MemBuf);
2777 * @defgroup LLVMCCorePassRegistry Pass Registry
2782 /** Return the global pass registry, for use with initialization functions.
2783 @see llvm::PassRegistry::getPassRegistry */
2784 LLVMPassRegistryRef LLVMGetGlobalPassRegistry(void);
2791 * @defgroup LLVMCCorePassManagers Pass Managers
2796 /** Constructs a new whole-module pass pipeline. This type of pipeline is
2797 suitable for link-time optimization and whole-module transformations.
2798 @see llvm::PassManager::PassManager */
2799 LLVMPassManagerRef LLVMCreatePassManager(void);
2801 /** Constructs a new function-by-function pass pipeline over the module
2802 provider. It does not take ownership of the module provider. This type of
2803 pipeline is suitable for code generation and JIT compilation tasks.
2804 @see llvm::FunctionPassManager::FunctionPassManager */
2805 LLVMPassManagerRef LLVMCreateFunctionPassManagerForModule(LLVMModuleRef M);
2807 /** Deprecated: Use LLVMCreateFunctionPassManagerForModule instead. */
2808 LLVMPassManagerRef LLVMCreateFunctionPassManager(LLVMModuleProviderRef MP);
2810 /** Initializes, executes on the provided module, and finalizes all of the
2811 passes scheduled in the pass manager. Returns 1 if any of the passes
2812 modified the module, 0 otherwise.
2813 @see llvm::PassManager::run(Module&) */
2814 LLVMBool LLVMRunPassManager(LLVMPassManagerRef PM, LLVMModuleRef M);
2816 /** Initializes all of the function passes scheduled in the function pass
2817 manager. Returns 1 if any of the passes modified the module, 0 otherwise.
2818 @see llvm::FunctionPassManager::doInitialization */
2819 LLVMBool LLVMInitializeFunctionPassManager(LLVMPassManagerRef FPM);
2821 /** Executes all of the function passes scheduled in the function pass manager
2822 on the provided function. Returns 1 if any of the passes modified the
2823 function, false otherwise.
2824 @see llvm::FunctionPassManager::run(Function&) */
2825 LLVMBool LLVMRunFunctionPassManager(LLVMPassManagerRef FPM, LLVMValueRef F);
2827 /** Finalizes all of the function passes scheduled in in the function pass
2828 manager. Returns 1 if any of the passes modified the module, 0 otherwise.
2829 @see llvm::FunctionPassManager::doFinalization */
2830 LLVMBool LLVMFinalizeFunctionPassManager(LLVMPassManagerRef FPM);
2832 /** Frees the memory of a pass pipeline. For function pipelines, does not free
2833 the module provider.
2834 @see llvm::PassManagerBase::~PassManagerBase. */
2835 void LLVMDisposePassManager(LLVMPassManagerRef PM);
2842 * @defgroup LLVMCCoreThreading Threading
2844 * Handle the structures needed to make LLVM safe for multithreading.
2849 /** Allocate and initialize structures needed to make LLVM safe for
2850 multithreading. The return value indicates whether multithreaded
2851 initialization succeeded. Must be executed in isolation from all
2852 other LLVM api calls.
2853 @see llvm::llvm_start_multithreaded */
2854 LLVMBool LLVMStartMultithreaded(void);
2856 /** Deallocate structures necessary to make LLVM safe for multithreading.
2857 Must be executed in isolation from all other LLVM api calls.
2858 @see llvm::llvm_stop_multithreaded */
2859 void LLVMStopMultithreaded(void);
2861 /** Check whether LLVM is executing in thread-safe mode or not.
2862 @see llvm::llvm_is_multithreaded */
2863 LLVMBool LLVMIsMultithreaded(void);
2879 #endif /* !defined(__cplusplus) */
2881 #endif /* !defined(LLVM_C_CORE_H) */