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,
169 LLVMNonNullAttribute = 1ULL << 37
174 /* Terminator Instructions */
180 /* removed 6 due to API changes */
183 /* Standard Binary Operators */
197 /* Logical Operators */
205 /* Memory Operators */
209 LLVMGetElementPtr = 29,
224 LLVMAddrSpaceCast = 60,
226 /* Other Operators */
235 LLVMExtractElement = 50,
236 LLVMInsertElement = 51,
237 LLVMShuffleVector = 52,
238 LLVMExtractValue = 53,
239 LLVMInsertValue = 54,
241 /* Atomic operators */
243 LLVMAtomicCmpXchg = 56,
246 /* Exception Handling Operators */
253 LLVMVoidTypeKind, /**< type with no size */
254 LLVMHalfTypeKind, /**< 16 bit floating point type */
255 LLVMFloatTypeKind, /**< 32 bit floating point type */
256 LLVMDoubleTypeKind, /**< 64 bit floating point type */
257 LLVMX86_FP80TypeKind, /**< 80 bit floating point type (X87) */
258 LLVMFP128TypeKind, /**< 128 bit floating point type (112-bit mantissa)*/
259 LLVMPPC_FP128TypeKind, /**< 128 bit floating point type (two 64-bits) */
260 LLVMLabelTypeKind, /**< Labels */
261 LLVMIntegerTypeKind, /**< Arbitrary bit width integers */
262 LLVMFunctionTypeKind, /**< Functions */
263 LLVMStructTypeKind, /**< Structures */
264 LLVMArrayTypeKind, /**< Arrays */
265 LLVMPointerTypeKind, /**< Pointers */
266 LLVMVectorTypeKind, /**< SIMD 'packed' format, or other vector type */
267 LLVMMetadataTypeKind, /**< Metadata */
268 LLVMX86_MMXTypeKind /**< X86 MMX */
272 LLVMExternalLinkage, /**< Externally visible function */
273 LLVMAvailableExternallyLinkage,
274 LLVMLinkOnceAnyLinkage, /**< Keep one copy of function when linking (inline)*/
275 LLVMLinkOnceODRLinkage, /**< Same, but only replaced by something
277 LLVMLinkOnceODRAutoHideLinkage, /**< Obsolete */
278 LLVMWeakAnyLinkage, /**< Keep one copy of function when linking (weak) */
279 LLVMWeakODRLinkage, /**< Same, but only replaced by something
281 LLVMAppendingLinkage, /**< Special purpose, only applies to global arrays */
282 LLVMInternalLinkage, /**< Rename collisions when linking (static
284 LLVMPrivateLinkage, /**< Like Internal, but omit from symbol table */
285 LLVMDLLImportLinkage, /**< Obsolete */
286 LLVMDLLExportLinkage, /**< Obsolete */
287 LLVMExternalWeakLinkage,/**< ExternalWeak linkage description */
288 LLVMGhostLinkage, /**< Obsolete */
289 LLVMCommonLinkage, /**< Tentative definitions */
290 LLVMLinkerPrivateLinkage, /**< Like Private, but linker removes. */
291 LLVMLinkerPrivateWeakLinkage /**< Like LinkerPrivate, but is weak. */
295 LLVMDefaultVisibility, /**< The GV is visible */
296 LLVMHiddenVisibility, /**< The GV is hidden */
297 LLVMProtectedVisibility /**< The GV is protected */
301 LLVMDefaultStorageClass = 0,
302 LLVMDLLImportStorageClass = 1, /**< Function to be imported from DLL. */
303 LLVMDLLExportStorageClass = 2 /**< Function to be accessible from DLL. */
304 } LLVMDLLStorageClass;
308 LLVMFastCallConv = 8,
309 LLVMColdCallConv = 9,
310 LLVMWebKitJSCallConv = 12,
311 LLVMAnyRegCallConv = 13,
312 LLVMX86StdcallCallConv = 64,
313 LLVMX86FastcallCallConv = 65
317 LLVMIntEQ = 32, /**< equal */
318 LLVMIntNE, /**< not equal */
319 LLVMIntUGT, /**< unsigned greater than */
320 LLVMIntUGE, /**< unsigned greater or equal */
321 LLVMIntULT, /**< unsigned less than */
322 LLVMIntULE, /**< unsigned less or equal */
323 LLVMIntSGT, /**< signed greater than */
324 LLVMIntSGE, /**< signed greater or equal */
325 LLVMIntSLT, /**< signed less than */
326 LLVMIntSLE /**< signed less or equal */
330 LLVMRealPredicateFalse, /**< Always false (always folded) */
331 LLVMRealOEQ, /**< True if ordered and equal */
332 LLVMRealOGT, /**< True if ordered and greater than */
333 LLVMRealOGE, /**< True if ordered and greater than or equal */
334 LLVMRealOLT, /**< True if ordered and less than */
335 LLVMRealOLE, /**< True if ordered and less than or equal */
336 LLVMRealONE, /**< True if ordered and operands are unequal */
337 LLVMRealORD, /**< True if ordered (no nans) */
338 LLVMRealUNO, /**< True if unordered: isnan(X) | isnan(Y) */
339 LLVMRealUEQ, /**< True if unordered or equal */
340 LLVMRealUGT, /**< True if unordered or greater than */
341 LLVMRealUGE, /**< True if unordered, greater than, or equal */
342 LLVMRealULT, /**< True if unordered or less than */
343 LLVMRealULE, /**< True if unordered, less than, or equal */
344 LLVMRealUNE, /**< True if unordered or not equal */
345 LLVMRealPredicateTrue /**< Always true (always folded) */
349 LLVMLandingPadCatch, /**< A catch clause */
350 LLVMLandingPadFilter /**< A filter clause */
351 } LLVMLandingPadClauseTy;
354 LLVMNotThreadLocal = 0,
355 LLVMGeneralDynamicTLSModel,
356 LLVMLocalDynamicTLSModel,
357 LLVMInitialExecTLSModel,
358 LLVMLocalExecTLSModel
359 } LLVMThreadLocalMode;
362 LLVMAtomicOrderingNotAtomic = 0, /**< A load or store which is not atomic */
363 LLVMAtomicOrderingUnordered = 1, /**< Lowest level of atomicity, guarantees
364 somewhat sane results, lock free. */
365 LLVMAtomicOrderingMonotonic = 2, /**< guarantees that if you take all the
366 operations affecting a specific address,
367 a consistent ordering exists */
368 LLVMAtomicOrderingAcquire = 4, /**< Acquire provides a barrier of the sort
369 necessary to acquire a lock to access other
370 memory with normal loads and stores. */
371 LLVMAtomicOrderingRelease = 5, /**< Release is similar to Acquire, but with
372 a barrier of the sort necessary to release
374 LLVMAtomicOrderingAcquireRelease = 6, /**< provides both an Acquire and a
375 Release barrier (for fences and
376 operations which both read and write
378 LLVMAtomicOrderingSequentiallyConsistent = 7 /**< provides Acquire semantics
379 for loads and Release
380 semantics for stores.
381 Additionally, it guarantees
382 that a total ordering exists
384 SequentiallyConsistent
386 } LLVMAtomicOrdering;
389 LLVMAtomicRMWBinOpXchg, /**< Set the new value and return the one old */
390 LLVMAtomicRMWBinOpAdd, /**< Add a value and return the old one */
391 LLVMAtomicRMWBinOpSub, /**< Subtract a value and return the old one */
392 LLVMAtomicRMWBinOpAnd, /**< And a value and return the old one */
393 LLVMAtomicRMWBinOpNand, /**< Not-And a value and return the old one */
394 LLVMAtomicRMWBinOpOr, /**< OR a value and return the old one */
395 LLVMAtomicRMWBinOpXor, /**< Xor a value and return the old one */
396 LLVMAtomicRMWBinOpMax, /**< Sets the value if it's greater than the
397 original using a signed comparison and return
399 LLVMAtomicRMWBinOpMin, /**< Sets the value if it's Smaller than the
400 original using a signed comparison and return
402 LLVMAtomicRMWBinOpUMax, /**< Sets the value if it's greater than the
403 original using an unsigned comparison and return
405 LLVMAtomicRMWBinOpUMin /**< Sets the value if it's greater than the
406 original using an unsigned comparison and return
408 } LLVMAtomicRMWBinOp;
415 } LLVMDiagnosticSeverity;
421 void LLVMInitializeCore(LLVMPassRegistryRef R);
423 /** Deallocate and destroy all ManagedStatic variables.
424 @see llvm::llvm_shutdown
425 @see ManagedStatic */
426 void LLVMShutdown(void);
429 /*===-- Error handling ----------------------------------------------------===*/
431 char *LLVMCreateMessage(const char *Message);
432 void LLVMDisposeMessage(char *Message);
434 typedef void (*LLVMFatalErrorHandler)(const char *Reason);
437 * Install a fatal error handler. By default, if LLVM detects a fatal error, it
438 * will call exit(1). This may not be appropriate in many contexts. For example,
439 * doing exit(1) will bypass many crash reporting/tracing system tools. This
440 * function allows you to install a callback that will be invoked prior to the
443 void LLVMInstallFatalErrorHandler(LLVMFatalErrorHandler Handler);
446 * Reset the fatal error handler. This resets LLVM's fatal error handling
447 * behavior to the default.
449 void LLVMResetFatalErrorHandler(void);
452 * Enable LLVM's built-in stack trace code. This intercepts the OS's crash
453 * signals and prints which component of LLVM you were in at the time if the
456 void LLVMEnablePrettyStackTrace(void);
459 * @defgroup LLVMCCoreContext Contexts
461 * Contexts are execution states for the core LLVM IR system.
463 * Most types are tied to a context instance. Multiple contexts can
464 * exist simultaneously. A single context is not thread safe. However,
465 * different contexts can execute on different threads simultaneously.
470 typedef void (*LLVMDiagnosticHandler)(LLVMDiagnosticInfoRef, void *);
471 typedef void (*LLVMYieldCallback)(LLVMContextRef, void *);
474 * Create a new context.
476 * Every call to this function should be paired with a call to
477 * LLVMContextDispose() or the context will leak memory.
479 LLVMContextRef LLVMContextCreate(void);
482 * Obtain the global context instance.
484 LLVMContextRef LLVMGetGlobalContext(void);
487 * Set the diagnostic handler for this context.
489 void LLVMContextSetDiagnosticHandler(LLVMContextRef C,
490 LLVMDiagnosticHandler Handler,
491 void *DiagnosticContext);
494 * Set the yield callback function for this context.
496 * @see LLVMContext::setYieldCallback()
498 void LLVMContextSetYieldCallback(LLVMContextRef C, LLVMYieldCallback Callback,
502 * Destroy a context instance.
504 * This should be called for every call to LLVMContextCreate() or memory
507 void LLVMContextDispose(LLVMContextRef C);
510 * Return a string representation of the DiagnosticInfo. Use
511 * LLVMDisposeMessage to free the string.
513 * @see DiagnosticInfo::print()
515 char *LLVMGetDiagInfoDescription(LLVMDiagnosticInfoRef DI);
518 * Return an enum LLVMDiagnosticSeverity.
520 * @see DiagnosticInfo::getSeverity()
522 LLVMDiagnosticSeverity LLVMGetDiagInfoSeverity(LLVMDiagnosticInfoRef DI);
524 unsigned LLVMGetMDKindIDInContext(LLVMContextRef C, const char* Name,
526 unsigned LLVMGetMDKindID(const char* Name, unsigned SLen);
533 * @defgroup LLVMCCoreModule Modules
535 * Modules represent the top-level structure in an LLVM program. An LLVM
536 * module is effectively a translation unit or a collection of
537 * translation units merged together.
543 * Create a new, empty module in the global context.
545 * This is equivalent to calling LLVMModuleCreateWithNameInContext with
546 * LLVMGetGlobalContext() as the context parameter.
548 * Every invocation should be paired with LLVMDisposeModule() or memory
551 LLVMModuleRef LLVMModuleCreateWithName(const char *ModuleID);
554 * Create a new, empty module in a specific context.
556 * Every invocation should be paired with LLVMDisposeModule() or memory
559 LLVMModuleRef LLVMModuleCreateWithNameInContext(const char *ModuleID,
563 * Destroy a module instance.
565 * This must be called for every created module or memory will be
568 void LLVMDisposeModule(LLVMModuleRef M);
571 * Obtain the data layout for a module.
573 * @see Module::getDataLayout()
575 const char *LLVMGetDataLayout(LLVMModuleRef M);
578 * Set the data layout for a module.
580 * @see Module::setDataLayout()
582 void LLVMSetDataLayout(LLVMModuleRef M, const char *Triple);
585 * Obtain the target triple for a module.
587 * @see Module::getTargetTriple()
589 const char *LLVMGetTarget(LLVMModuleRef M);
592 * Set the target triple for a module.
594 * @see Module::setTargetTriple()
596 void LLVMSetTarget(LLVMModuleRef M, const char *Triple);
599 * Dump a representation of a module to stderr.
601 * @see Module::dump()
603 void LLVMDumpModule(LLVMModuleRef M);
606 * Print a representation of a module to a file. The ErrorMessage needs to be
607 * disposed with LLVMDisposeMessage. Returns 0 on success, 1 otherwise.
609 * @see Module::print()
611 LLVMBool LLVMPrintModuleToFile(LLVMModuleRef M, const char *Filename,
612 char **ErrorMessage);
615 * Return a string representation of the module. Use
616 * LLVMDisposeMessage to free the string.
618 * @see Module::print()
620 char *LLVMPrintModuleToString(LLVMModuleRef M);
623 * Set inline assembly for a module.
625 * @see Module::setModuleInlineAsm()
627 void LLVMSetModuleInlineAsm(LLVMModuleRef M, const char *Asm);
630 * Obtain the context to which this module is associated.
632 * @see Module::getContext()
634 LLVMContextRef LLVMGetModuleContext(LLVMModuleRef M);
637 * Obtain a Type from a module by its registered name.
639 LLVMTypeRef LLVMGetTypeByName(LLVMModuleRef M, const char *Name);
642 * Obtain the number of operands for named metadata in a module.
644 * @see llvm::Module::getNamedMetadata()
646 unsigned LLVMGetNamedMetadataNumOperands(LLVMModuleRef M, const char* name);
649 * Obtain the named metadata operands for a module.
651 * The passed LLVMValueRef pointer should refer to an array of
652 * LLVMValueRef at least LLVMGetNamedMetadataNumOperands long. This
653 * array will be populated with the LLVMValueRef instances. Each
654 * instance corresponds to a llvm::MDNode.
656 * @see llvm::Module::getNamedMetadata()
657 * @see llvm::MDNode::getOperand()
659 void LLVMGetNamedMetadataOperands(LLVMModuleRef M, const char* name, LLVMValueRef *Dest);
662 * Add an operand to named metadata.
664 * @see llvm::Module::getNamedMetadata()
665 * @see llvm::MDNode::addOperand()
667 void LLVMAddNamedMetadataOperand(LLVMModuleRef M, const char* name,
671 * Add a function to a module under a specified name.
673 * @see llvm::Function::Create()
675 LLVMValueRef LLVMAddFunction(LLVMModuleRef M, const char *Name,
676 LLVMTypeRef FunctionTy);
679 * Obtain a Function value from a Module by its name.
681 * The returned value corresponds to a llvm::Function value.
683 * @see llvm::Module::getFunction()
685 LLVMValueRef LLVMGetNamedFunction(LLVMModuleRef M, const char *Name);
688 * Obtain an iterator to the first Function in a Module.
690 * @see llvm::Module::begin()
692 LLVMValueRef LLVMGetFirstFunction(LLVMModuleRef M);
695 * Obtain an iterator to the last Function in a Module.
697 * @see llvm::Module::end()
699 LLVMValueRef LLVMGetLastFunction(LLVMModuleRef M);
702 * Advance a Function iterator to the next Function.
704 * Returns NULL if the iterator was already at the end and there are no more
707 LLVMValueRef LLVMGetNextFunction(LLVMValueRef Fn);
710 * Decrement a Function iterator to the previous Function.
712 * Returns NULL if the iterator was already at the beginning and there are
713 * no previous functions.
715 LLVMValueRef LLVMGetPreviousFunction(LLVMValueRef Fn);
722 * @defgroup LLVMCCoreType Types
724 * Types represent the type of a value.
726 * Types are associated with a context instance. The context internally
727 * deduplicates types so there is only 1 instance of a specific type
728 * alive at a time. In other words, a unique type is shared among all
729 * consumers within a context.
731 * A Type in the C API corresponds to llvm::Type.
733 * Types have the following hierarchy:
751 * Obtain the enumerated type of a Type instance.
753 * @see llvm::Type:getTypeID()
755 LLVMTypeKind LLVMGetTypeKind(LLVMTypeRef Ty);
758 * Whether the type has a known size.
760 * Things that don't have a size are abstract types, labels, and void.a
762 * @see llvm::Type::isSized()
764 LLVMBool LLVMTypeIsSized(LLVMTypeRef Ty);
767 * Obtain the context to which this type instance is associated.
769 * @see llvm::Type::getContext()
771 LLVMContextRef LLVMGetTypeContext(LLVMTypeRef Ty);
774 * Dump a representation of a type to stderr.
776 * @see llvm::Type::dump()
778 void LLVMDumpType(LLVMTypeRef Val);
781 * Return a string representation of the type. Use
782 * LLVMDisposeMessage to free the string.
784 * @see llvm::Type::print()
786 char *LLVMPrintTypeToString(LLVMTypeRef Val);
789 * @defgroup LLVMCCoreTypeInt Integer Types
791 * Functions in this section operate on integer types.
797 * Obtain an integer type from a context with specified bit width.
799 LLVMTypeRef LLVMInt1TypeInContext(LLVMContextRef C);
800 LLVMTypeRef LLVMInt8TypeInContext(LLVMContextRef C);
801 LLVMTypeRef LLVMInt16TypeInContext(LLVMContextRef C);
802 LLVMTypeRef LLVMInt32TypeInContext(LLVMContextRef C);
803 LLVMTypeRef LLVMInt64TypeInContext(LLVMContextRef C);
804 LLVMTypeRef LLVMIntTypeInContext(LLVMContextRef C, unsigned NumBits);
807 * Obtain an integer type from the global context with a specified bit
810 LLVMTypeRef LLVMInt1Type(void);
811 LLVMTypeRef LLVMInt8Type(void);
812 LLVMTypeRef LLVMInt16Type(void);
813 LLVMTypeRef LLVMInt32Type(void);
814 LLVMTypeRef LLVMInt64Type(void);
815 LLVMTypeRef LLVMIntType(unsigned NumBits);
816 unsigned LLVMGetIntTypeWidth(LLVMTypeRef IntegerTy);
823 * @defgroup LLVMCCoreTypeFloat Floating Point Types
829 * Obtain a 16-bit floating point type from a context.
831 LLVMTypeRef LLVMHalfTypeInContext(LLVMContextRef C);
834 * Obtain a 32-bit floating point type from a context.
836 LLVMTypeRef LLVMFloatTypeInContext(LLVMContextRef C);
839 * Obtain a 64-bit floating point type from a context.
841 LLVMTypeRef LLVMDoubleTypeInContext(LLVMContextRef C);
844 * Obtain a 80-bit floating point type (X87) from a context.
846 LLVMTypeRef LLVMX86FP80TypeInContext(LLVMContextRef C);
849 * Obtain a 128-bit floating point type (112-bit mantissa) from a
852 LLVMTypeRef LLVMFP128TypeInContext(LLVMContextRef C);
855 * Obtain a 128-bit floating point type (two 64-bits) from a context.
857 LLVMTypeRef LLVMPPCFP128TypeInContext(LLVMContextRef C);
860 * Obtain a floating point type from the global context.
862 * These map to the functions in this group of the same name.
864 LLVMTypeRef LLVMHalfType(void);
865 LLVMTypeRef LLVMFloatType(void);
866 LLVMTypeRef LLVMDoubleType(void);
867 LLVMTypeRef LLVMX86FP80Type(void);
868 LLVMTypeRef LLVMFP128Type(void);
869 LLVMTypeRef LLVMPPCFP128Type(void);
876 * @defgroup LLVMCCoreTypeFunction Function Types
882 * Obtain a function type consisting of a specified signature.
884 * The function is defined as a tuple of a return Type, a list of
885 * parameter types, and whether the function is variadic.
887 LLVMTypeRef LLVMFunctionType(LLVMTypeRef ReturnType,
888 LLVMTypeRef *ParamTypes, unsigned ParamCount,
892 * Returns whether a function type is variadic.
894 LLVMBool LLVMIsFunctionVarArg(LLVMTypeRef FunctionTy);
897 * Obtain the Type this function Type returns.
899 LLVMTypeRef LLVMGetReturnType(LLVMTypeRef FunctionTy);
902 * Obtain the number of parameters this function accepts.
904 unsigned LLVMCountParamTypes(LLVMTypeRef FunctionTy);
907 * Obtain the types of a function's parameters.
909 * The Dest parameter should point to a pre-allocated array of
910 * LLVMTypeRef at least LLVMCountParamTypes() large. On return, the
911 * first LLVMCountParamTypes() entries in the array will be populated
912 * with LLVMTypeRef instances.
914 * @param FunctionTy The function type to operate on.
915 * @param Dest Memory address of an array to be filled with result.
917 void LLVMGetParamTypes(LLVMTypeRef FunctionTy, LLVMTypeRef *Dest);
924 * @defgroup LLVMCCoreTypeStruct Structure Types
926 * These functions relate to LLVMTypeRef instances.
928 * @see llvm::StructType
934 * Create a new structure type in a context.
936 * A structure is specified by a list of inner elements/types and
937 * whether these can be packed together.
939 * @see llvm::StructType::create()
941 LLVMTypeRef LLVMStructTypeInContext(LLVMContextRef C, LLVMTypeRef *ElementTypes,
942 unsigned ElementCount, LLVMBool Packed);
945 * Create a new structure type in the global context.
947 * @see llvm::StructType::create()
949 LLVMTypeRef LLVMStructType(LLVMTypeRef *ElementTypes, unsigned ElementCount,
953 * Create an empty structure in a context having a specified name.
955 * @see llvm::StructType::create()
957 LLVMTypeRef LLVMStructCreateNamed(LLVMContextRef C, const char *Name);
960 * Obtain the name of a structure.
962 * @see llvm::StructType::getName()
964 const char *LLVMGetStructName(LLVMTypeRef Ty);
967 * Set the contents of a structure type.
969 * @see llvm::StructType::setBody()
971 void LLVMStructSetBody(LLVMTypeRef StructTy, LLVMTypeRef *ElementTypes,
972 unsigned ElementCount, LLVMBool Packed);
975 * Get the number of elements defined inside the structure.
977 * @see llvm::StructType::getNumElements()
979 unsigned LLVMCountStructElementTypes(LLVMTypeRef StructTy);
982 * Get the elements within a structure.
984 * The function is passed the address of a pre-allocated array of
985 * LLVMTypeRef at least LLVMCountStructElementTypes() long. After
986 * invocation, this array will be populated with the structure's
987 * elements. The objects in the destination array will have a lifetime
988 * of the structure type itself, which is the lifetime of the context it
991 void LLVMGetStructElementTypes(LLVMTypeRef StructTy, LLVMTypeRef *Dest);
994 * Determine whether a structure is packed.
996 * @see llvm::StructType::isPacked()
998 LLVMBool LLVMIsPackedStruct(LLVMTypeRef StructTy);
1001 * Determine whether a structure is opaque.
1003 * @see llvm::StructType::isOpaque()
1005 LLVMBool LLVMIsOpaqueStruct(LLVMTypeRef StructTy);
1013 * @defgroup LLVMCCoreTypeSequential Sequential Types
1015 * Sequential types represents "arrays" of types. This is a super class
1016 * for array, vector, and pointer types.
1022 * Obtain the type of elements within a sequential type.
1024 * This works on array, vector, and pointer types.
1026 * @see llvm::SequentialType::getElementType()
1028 LLVMTypeRef LLVMGetElementType(LLVMTypeRef Ty);
1031 * Create a fixed size array type that refers to a specific type.
1033 * The created type will exist in the context that its element type
1036 * @see llvm::ArrayType::get()
1038 LLVMTypeRef LLVMArrayType(LLVMTypeRef ElementType, unsigned ElementCount);
1041 * Obtain the length of an array type.
1043 * This only works on types that represent arrays.
1045 * @see llvm::ArrayType::getNumElements()
1047 unsigned LLVMGetArrayLength(LLVMTypeRef ArrayTy);
1050 * Create a pointer type that points to a defined type.
1052 * The created type will exist in the context that its pointee type
1055 * @see llvm::PointerType::get()
1057 LLVMTypeRef LLVMPointerType(LLVMTypeRef ElementType, unsigned AddressSpace);
1060 * Obtain the address space of a pointer type.
1062 * This only works on types that represent pointers.
1064 * @see llvm::PointerType::getAddressSpace()
1066 unsigned LLVMGetPointerAddressSpace(LLVMTypeRef PointerTy);
1069 * Create a vector type that contains a defined type and has a specific
1070 * number of elements.
1072 * The created type will exist in the context thats its element type
1075 * @see llvm::VectorType::get()
1077 LLVMTypeRef LLVMVectorType(LLVMTypeRef ElementType, unsigned ElementCount);
1080 * Obtain the number of elements in a vector type.
1082 * This only works on types that represent vectors.
1084 * @see llvm::VectorType::getNumElements()
1086 unsigned LLVMGetVectorSize(LLVMTypeRef VectorTy);
1093 * @defgroup LLVMCCoreTypeOther Other Types
1099 * Create a void type in a context.
1101 LLVMTypeRef LLVMVoidTypeInContext(LLVMContextRef C);
1104 * Create a label type in a context.
1106 LLVMTypeRef LLVMLabelTypeInContext(LLVMContextRef C);
1109 * Create a X86 MMX type in a context.
1111 LLVMTypeRef LLVMX86MMXTypeInContext(LLVMContextRef C);
1114 * These are similar to the above functions except they operate on the
1117 LLVMTypeRef LLVMVoidType(void);
1118 LLVMTypeRef LLVMLabelType(void);
1119 LLVMTypeRef LLVMX86MMXType(void);
1130 * @defgroup LLVMCCoreValues Values
1132 * The bulk of LLVM's object model consists of values, which comprise a very
1133 * rich type hierarchy.
1135 * LLVMValueRef essentially represents llvm::Value. There is a rich
1136 * hierarchy of classes within this type. Depending on the instance
1137 * obtained, not all APIs are available.
1139 * Callers can determine the type of an LLVMValueRef by calling the
1140 * LLVMIsA* family of functions (e.g. LLVMIsAArgument()). These
1141 * functions are defined by a macro, so it isn't obvious which are
1142 * available by looking at the Doxygen source code. Instead, look at the
1143 * source definition of LLVM_FOR_EACH_VALUE_SUBCLASS and note the list
1144 * of value names given. These value names also correspond to classes in
1145 * the llvm::Value hierarchy.
1150 #define LLVM_FOR_EACH_VALUE_SUBCLASS(macro) \
1158 macro(BlockAddress) \
1159 macro(ConstantAggregateZero) \
1160 macro(ConstantArray) \
1161 macro(ConstantDataSequential) \
1162 macro(ConstantDataArray) \
1163 macro(ConstantDataVector) \
1164 macro(ConstantExpr) \
1166 macro(ConstantInt) \
1167 macro(ConstantPointerNull) \
1168 macro(ConstantStruct) \
1169 macro(ConstantVector) \
1170 macro(GlobalValue) \
1171 macro(GlobalAlias) \
1172 macro(GlobalObject) \
1174 macro(GlobalVariable) \
1176 macro(Instruction) \
1177 macro(BinaryOperator) \
1179 macro(IntrinsicInst) \
1180 macro(DbgInfoIntrinsic) \
1181 macro(DbgDeclareInst) \
1182 macro(MemIntrinsic) \
1184 macro(MemMoveInst) \
1189 macro(ExtractElementInst) \
1190 macro(GetElementPtrInst) \
1191 macro(InsertElementInst) \
1192 macro(InsertValueInst) \
1193 macro(LandingPadInst) \
1196 macro(ShuffleVectorInst) \
1198 macro(TerminatorInst) \
1200 macro(IndirectBrInst) \
1204 macro(UnreachableInst) \
1206 macro(UnaryInstruction) \
1209 macro(AddrSpaceCastInst) \
1210 macro(BitCastInst) \
1214 macro(FPTruncInst) \
1215 macro(IntToPtrInst) \
1216 macro(PtrToIntInst) \
1222 macro(ExtractValueInst) \
1227 * @defgroup LLVMCCoreValueGeneral General APIs
1229 * Functions in this section work on all LLVMValueRef instances,
1230 * regardless of their sub-type. They correspond to functions available
1237 * Obtain the type of a value.
1239 * @see llvm::Value::getType()
1241 LLVMTypeRef LLVMTypeOf(LLVMValueRef Val);
1244 * Obtain the string name of a value.
1246 * @see llvm::Value::getName()
1248 const char *LLVMGetValueName(LLVMValueRef Val);
1251 * Set the string name of a value.
1253 * @see llvm::Value::setName()
1255 void LLVMSetValueName(LLVMValueRef Val, const char *Name);
1258 * Dump a representation of a value to stderr.
1260 * @see llvm::Value::dump()
1262 void LLVMDumpValue(LLVMValueRef Val);
1265 * Return a string representation of the value. Use
1266 * LLVMDisposeMessage to free the string.
1268 * @see llvm::Value::print()
1270 char *LLVMPrintValueToString(LLVMValueRef Val);
1273 * Replace all uses of a value with another one.
1275 * @see llvm::Value::replaceAllUsesWith()
1277 void LLVMReplaceAllUsesWith(LLVMValueRef OldVal, LLVMValueRef NewVal);
1280 * Determine whether the specified constant instance is constant.
1282 LLVMBool LLVMIsConstant(LLVMValueRef Val);
1285 * Determine whether a value instance is undefined.
1287 LLVMBool LLVMIsUndef(LLVMValueRef Val);
1290 * Convert value instances between types.
1292 * Internally, an LLVMValueRef is "pinned" to a specific type. This
1293 * series of functions allows you to cast an instance to a specific
1296 * If the cast is not valid for the specified type, NULL is returned.
1298 * @see llvm::dyn_cast_or_null<>
1300 #define LLVM_DECLARE_VALUE_CAST(name) \
1301 LLVMValueRef LLVMIsA##name(LLVMValueRef Val);
1302 LLVM_FOR_EACH_VALUE_SUBCLASS(LLVM_DECLARE_VALUE_CAST)
1309 * @defgroup LLVMCCoreValueUses Usage
1311 * This module defines functions that allow you to inspect the uses of a
1314 * It is possible to obtain an LLVMUseRef for any LLVMValueRef instance.
1315 * Each LLVMUseRef (which corresponds to a llvm::Use instance) holds a
1316 * llvm::User and llvm::Value.
1322 * Obtain the first use of a value.
1324 * Uses are obtained in an iterator fashion. First, call this function
1325 * to obtain a reference to the first use. Then, call LLVMGetNextUse()
1326 * on that instance and all subsequently obtained instances until
1327 * LLVMGetNextUse() returns NULL.
1329 * @see llvm::Value::use_begin()
1331 LLVMUseRef LLVMGetFirstUse(LLVMValueRef Val);
1334 * Obtain the next use of a value.
1336 * This effectively advances the iterator. It returns NULL if you are on
1337 * the final use and no more are available.
1339 LLVMUseRef LLVMGetNextUse(LLVMUseRef U);
1342 * Obtain the user value for a user.
1344 * The returned value corresponds to a llvm::User type.
1346 * @see llvm::Use::getUser()
1348 LLVMValueRef LLVMGetUser(LLVMUseRef U);
1351 * Obtain the value this use corresponds to.
1353 * @see llvm::Use::get().
1355 LLVMValueRef LLVMGetUsedValue(LLVMUseRef U);
1362 * @defgroup LLVMCCoreValueUser User value
1364 * Function in this group pertain to LLVMValueRef instances that descent
1365 * from llvm::User. This includes constants, instructions, and
1372 * Obtain an operand at a specific index in a llvm::User value.
1374 * @see llvm::User::getOperand()
1376 LLVMValueRef LLVMGetOperand(LLVMValueRef Val, unsigned Index);
1379 * Set an operand at a specific index in a llvm::User value.
1381 * @see llvm::User::setOperand()
1383 void LLVMSetOperand(LLVMValueRef User, unsigned Index, LLVMValueRef Val);
1386 * Obtain the number of operands in a llvm::User value.
1388 * @see llvm::User::getNumOperands()
1390 int LLVMGetNumOperands(LLVMValueRef Val);
1397 * @defgroup LLVMCCoreValueConstant Constants
1399 * This section contains APIs for interacting with LLVMValueRef that
1400 * correspond to llvm::Constant instances.
1402 * These functions will work for any LLVMValueRef in the llvm::Constant
1409 * Obtain a constant value referring to the null instance of a type.
1411 * @see llvm::Constant::getNullValue()
1413 LLVMValueRef LLVMConstNull(LLVMTypeRef Ty); /* all zeroes */
1416 * Obtain a constant value referring to the instance of a type
1417 * consisting of all ones.
1419 * This is only valid for integer types.
1421 * @see llvm::Constant::getAllOnesValue()
1423 LLVMValueRef LLVMConstAllOnes(LLVMTypeRef Ty);
1426 * Obtain a constant value referring to an undefined value of a type.
1428 * @see llvm::UndefValue::get()
1430 LLVMValueRef LLVMGetUndef(LLVMTypeRef Ty);
1433 * Determine whether a value instance is null.
1435 * @see llvm::Constant::isNullValue()
1437 LLVMBool LLVMIsNull(LLVMValueRef Val);
1440 * Obtain a constant that is a constant pointer pointing to NULL for a
1443 LLVMValueRef LLVMConstPointerNull(LLVMTypeRef Ty);
1446 * @defgroup LLVMCCoreValueConstantScalar Scalar constants
1448 * Functions in this group model LLVMValueRef instances that correspond
1449 * to constants referring to scalar types.
1451 * For integer types, the LLVMTypeRef parameter should correspond to a
1452 * llvm::IntegerType instance and the returned LLVMValueRef will
1453 * correspond to a llvm::ConstantInt.
1455 * For floating point types, the LLVMTypeRef returned corresponds to a
1462 * Obtain a constant value for an integer type.
1464 * The returned value corresponds to a llvm::ConstantInt.
1466 * @see llvm::ConstantInt::get()
1468 * @param IntTy Integer type to obtain value of.
1469 * @param N The value the returned instance should refer to.
1470 * @param SignExtend Whether to sign extend the produced value.
1472 LLVMValueRef LLVMConstInt(LLVMTypeRef IntTy, unsigned long long N,
1473 LLVMBool SignExtend);
1476 * Obtain a constant value for an integer of arbitrary precision.
1478 * @see llvm::ConstantInt::get()
1480 LLVMValueRef LLVMConstIntOfArbitraryPrecision(LLVMTypeRef IntTy,
1482 const uint64_t Words[]);
1485 * Obtain a constant value for an integer parsed from a string.
1487 * A similar API, LLVMConstIntOfStringAndSize is also available. If the
1488 * string's length is available, it is preferred to call that function
1491 * @see llvm::ConstantInt::get()
1493 LLVMValueRef LLVMConstIntOfString(LLVMTypeRef IntTy, const char *Text,
1497 * Obtain a constant value for an integer parsed from a string with
1500 * @see llvm::ConstantInt::get()
1502 LLVMValueRef LLVMConstIntOfStringAndSize(LLVMTypeRef IntTy, const char *Text,
1503 unsigned SLen, uint8_t Radix);
1506 * Obtain a constant value referring to a double floating point value.
1508 LLVMValueRef LLVMConstReal(LLVMTypeRef RealTy, double N);
1511 * Obtain a constant for a floating point value parsed from a string.
1513 * A similar API, LLVMConstRealOfStringAndSize is also available. It
1514 * should be used if the input string's length is known.
1516 LLVMValueRef LLVMConstRealOfString(LLVMTypeRef RealTy, const char *Text);
1519 * Obtain a constant for a floating point value parsed from a string.
1521 LLVMValueRef LLVMConstRealOfStringAndSize(LLVMTypeRef RealTy, const char *Text,
1525 * Obtain the zero extended value for an integer constant value.
1527 * @see llvm::ConstantInt::getZExtValue()
1529 unsigned long long LLVMConstIntGetZExtValue(LLVMValueRef ConstantVal);
1532 * Obtain the sign extended value for an integer constant value.
1534 * @see llvm::ConstantInt::getSExtValue()
1536 long long LLVMConstIntGetSExtValue(LLVMValueRef ConstantVal);
1543 * @defgroup LLVMCCoreValueConstantComposite Composite Constants
1545 * Functions in this group operate on composite constants.
1551 * Create a ConstantDataSequential and initialize it with a string.
1553 * @see llvm::ConstantDataArray::getString()
1555 LLVMValueRef LLVMConstStringInContext(LLVMContextRef C, const char *Str,
1556 unsigned Length, LLVMBool DontNullTerminate);
1559 * Create a ConstantDataSequential with string content in the global context.
1561 * This is the same as LLVMConstStringInContext except it operates on the
1564 * @see LLVMConstStringInContext()
1565 * @see llvm::ConstantDataArray::getString()
1567 LLVMValueRef LLVMConstString(const char *Str, unsigned Length,
1568 LLVMBool DontNullTerminate);
1571 * Create an anonymous ConstantStruct with the specified values.
1573 * @see llvm::ConstantStruct::getAnon()
1575 LLVMValueRef LLVMConstStructInContext(LLVMContextRef C,
1576 LLVMValueRef *ConstantVals,
1577 unsigned Count, LLVMBool Packed);
1580 * Create a ConstantStruct in the global Context.
1582 * This is the same as LLVMConstStructInContext except it operates on the
1585 * @see LLVMConstStructInContext()
1587 LLVMValueRef LLVMConstStruct(LLVMValueRef *ConstantVals, unsigned Count,
1591 * Create a ConstantArray from values.
1593 * @see llvm::ConstantArray::get()
1595 LLVMValueRef LLVMConstArray(LLVMTypeRef ElementTy,
1596 LLVMValueRef *ConstantVals, unsigned Length);
1599 * Create a non-anonymous ConstantStruct from values.
1601 * @see llvm::ConstantStruct::get()
1603 LLVMValueRef LLVMConstNamedStruct(LLVMTypeRef StructTy,
1604 LLVMValueRef *ConstantVals,
1608 * Create a ConstantVector from values.
1610 * @see llvm::ConstantVector::get()
1612 LLVMValueRef LLVMConstVector(LLVMValueRef *ScalarConstantVals, unsigned Size);
1619 * @defgroup LLVMCCoreValueConstantExpressions Constant Expressions
1621 * Functions in this group correspond to APIs on llvm::ConstantExpr.
1623 * @see llvm::ConstantExpr.
1627 LLVMOpcode LLVMGetConstOpcode(LLVMValueRef ConstantVal);
1628 LLVMValueRef LLVMAlignOf(LLVMTypeRef Ty);
1629 LLVMValueRef LLVMSizeOf(LLVMTypeRef Ty);
1630 LLVMValueRef LLVMConstNeg(LLVMValueRef ConstantVal);
1631 LLVMValueRef LLVMConstNSWNeg(LLVMValueRef ConstantVal);
1632 LLVMValueRef LLVMConstNUWNeg(LLVMValueRef ConstantVal);
1633 LLVMValueRef LLVMConstFNeg(LLVMValueRef ConstantVal);
1634 LLVMValueRef LLVMConstNot(LLVMValueRef ConstantVal);
1635 LLVMValueRef LLVMConstAdd(LLVMValueRef LHSConstant, LLVMValueRef RHSConstant);
1636 LLVMValueRef LLVMConstNSWAdd(LLVMValueRef LHSConstant, LLVMValueRef RHSConstant);
1637 LLVMValueRef LLVMConstNUWAdd(LLVMValueRef LHSConstant, LLVMValueRef RHSConstant);
1638 LLVMValueRef LLVMConstFAdd(LLVMValueRef LHSConstant, LLVMValueRef RHSConstant);
1639 LLVMValueRef LLVMConstSub(LLVMValueRef LHSConstant, LLVMValueRef RHSConstant);
1640 LLVMValueRef LLVMConstNSWSub(LLVMValueRef LHSConstant, LLVMValueRef RHSConstant);
1641 LLVMValueRef LLVMConstNUWSub(LLVMValueRef LHSConstant, LLVMValueRef RHSConstant);
1642 LLVMValueRef LLVMConstFSub(LLVMValueRef LHSConstant, LLVMValueRef RHSConstant);
1643 LLVMValueRef LLVMConstMul(LLVMValueRef LHSConstant, LLVMValueRef RHSConstant);
1644 LLVMValueRef LLVMConstNSWMul(LLVMValueRef LHSConstant, LLVMValueRef RHSConstant);
1645 LLVMValueRef LLVMConstNUWMul(LLVMValueRef LHSConstant, LLVMValueRef RHSConstant);
1646 LLVMValueRef LLVMConstFMul(LLVMValueRef LHSConstant, LLVMValueRef RHSConstant);
1647 LLVMValueRef LLVMConstUDiv(LLVMValueRef LHSConstant, LLVMValueRef RHSConstant);
1648 LLVMValueRef LLVMConstSDiv(LLVMValueRef LHSConstant, LLVMValueRef RHSConstant);
1649 LLVMValueRef LLVMConstExactSDiv(LLVMValueRef LHSConstant, LLVMValueRef RHSConstant);
1650 LLVMValueRef LLVMConstFDiv(LLVMValueRef LHSConstant, LLVMValueRef RHSConstant);
1651 LLVMValueRef LLVMConstURem(LLVMValueRef LHSConstant, LLVMValueRef RHSConstant);
1652 LLVMValueRef LLVMConstSRem(LLVMValueRef LHSConstant, LLVMValueRef RHSConstant);
1653 LLVMValueRef LLVMConstFRem(LLVMValueRef LHSConstant, LLVMValueRef RHSConstant);
1654 LLVMValueRef LLVMConstAnd(LLVMValueRef LHSConstant, LLVMValueRef RHSConstant);
1655 LLVMValueRef LLVMConstOr(LLVMValueRef LHSConstant, LLVMValueRef RHSConstant);
1656 LLVMValueRef LLVMConstXor(LLVMValueRef LHSConstant, LLVMValueRef RHSConstant);
1657 LLVMValueRef LLVMConstICmp(LLVMIntPredicate Predicate,
1658 LLVMValueRef LHSConstant, LLVMValueRef RHSConstant);
1659 LLVMValueRef LLVMConstFCmp(LLVMRealPredicate Predicate,
1660 LLVMValueRef LHSConstant, LLVMValueRef RHSConstant);
1661 LLVMValueRef LLVMConstShl(LLVMValueRef LHSConstant, LLVMValueRef RHSConstant);
1662 LLVMValueRef LLVMConstLShr(LLVMValueRef LHSConstant, LLVMValueRef RHSConstant);
1663 LLVMValueRef LLVMConstAShr(LLVMValueRef LHSConstant, LLVMValueRef RHSConstant);
1664 LLVMValueRef LLVMConstGEP(LLVMValueRef ConstantVal,
1665 LLVMValueRef *ConstantIndices, unsigned NumIndices);
1666 LLVMValueRef LLVMConstInBoundsGEP(LLVMValueRef ConstantVal,
1667 LLVMValueRef *ConstantIndices,
1668 unsigned NumIndices);
1669 LLVMValueRef LLVMConstTrunc(LLVMValueRef ConstantVal, LLVMTypeRef ToType);
1670 LLVMValueRef LLVMConstSExt(LLVMValueRef ConstantVal, LLVMTypeRef ToType);
1671 LLVMValueRef LLVMConstZExt(LLVMValueRef ConstantVal, LLVMTypeRef ToType);
1672 LLVMValueRef LLVMConstFPTrunc(LLVMValueRef ConstantVal, LLVMTypeRef ToType);
1673 LLVMValueRef LLVMConstFPExt(LLVMValueRef ConstantVal, LLVMTypeRef ToType);
1674 LLVMValueRef LLVMConstUIToFP(LLVMValueRef ConstantVal, LLVMTypeRef ToType);
1675 LLVMValueRef LLVMConstSIToFP(LLVMValueRef ConstantVal, LLVMTypeRef ToType);
1676 LLVMValueRef LLVMConstFPToUI(LLVMValueRef ConstantVal, LLVMTypeRef ToType);
1677 LLVMValueRef LLVMConstFPToSI(LLVMValueRef ConstantVal, LLVMTypeRef ToType);
1678 LLVMValueRef LLVMConstPtrToInt(LLVMValueRef ConstantVal, LLVMTypeRef ToType);
1679 LLVMValueRef LLVMConstIntToPtr(LLVMValueRef ConstantVal, LLVMTypeRef ToType);
1680 LLVMValueRef LLVMConstBitCast(LLVMValueRef ConstantVal, LLVMTypeRef ToType);
1681 LLVMValueRef LLVMConstAddrSpaceCast(LLVMValueRef ConstantVal, LLVMTypeRef ToType);
1682 LLVMValueRef LLVMConstZExtOrBitCast(LLVMValueRef ConstantVal,
1683 LLVMTypeRef ToType);
1684 LLVMValueRef LLVMConstSExtOrBitCast(LLVMValueRef ConstantVal,
1685 LLVMTypeRef ToType);
1686 LLVMValueRef LLVMConstTruncOrBitCast(LLVMValueRef ConstantVal,
1687 LLVMTypeRef ToType);
1688 LLVMValueRef LLVMConstPointerCast(LLVMValueRef ConstantVal,
1689 LLVMTypeRef ToType);
1690 LLVMValueRef LLVMConstIntCast(LLVMValueRef ConstantVal, LLVMTypeRef ToType,
1692 LLVMValueRef LLVMConstFPCast(LLVMValueRef ConstantVal, LLVMTypeRef ToType);
1693 LLVMValueRef LLVMConstSelect(LLVMValueRef ConstantCondition,
1694 LLVMValueRef ConstantIfTrue,
1695 LLVMValueRef ConstantIfFalse);
1696 LLVMValueRef LLVMConstExtractElement(LLVMValueRef VectorConstant,
1697 LLVMValueRef IndexConstant);
1698 LLVMValueRef LLVMConstInsertElement(LLVMValueRef VectorConstant,
1699 LLVMValueRef ElementValueConstant,
1700 LLVMValueRef IndexConstant);
1701 LLVMValueRef LLVMConstShuffleVector(LLVMValueRef VectorAConstant,
1702 LLVMValueRef VectorBConstant,
1703 LLVMValueRef MaskConstant);
1704 LLVMValueRef LLVMConstExtractValue(LLVMValueRef AggConstant, unsigned *IdxList,
1706 LLVMValueRef LLVMConstInsertValue(LLVMValueRef AggConstant,
1707 LLVMValueRef ElementValueConstant,
1708 unsigned *IdxList, unsigned NumIdx);
1709 LLVMValueRef LLVMConstInlineAsm(LLVMTypeRef Ty,
1710 const char *AsmString, const char *Constraints,
1711 LLVMBool HasSideEffects, LLVMBool IsAlignStack);
1712 LLVMValueRef LLVMBlockAddress(LLVMValueRef F, LLVMBasicBlockRef BB);
1719 * @defgroup LLVMCCoreValueConstantGlobals Global Values
1721 * This group contains functions that operate on global values. Functions in
1722 * this group relate to functions in the llvm::GlobalValue class tree.
1724 * @see llvm::GlobalValue
1729 LLVMModuleRef LLVMGetGlobalParent(LLVMValueRef Global);
1730 LLVMBool LLVMIsDeclaration(LLVMValueRef Global);
1731 LLVMLinkage LLVMGetLinkage(LLVMValueRef Global);
1732 void LLVMSetLinkage(LLVMValueRef Global, LLVMLinkage Linkage);
1733 const char *LLVMGetSection(LLVMValueRef Global);
1734 void LLVMSetSection(LLVMValueRef Global, const char *Section);
1735 LLVMVisibility LLVMGetVisibility(LLVMValueRef Global);
1736 void LLVMSetVisibility(LLVMValueRef Global, LLVMVisibility Viz);
1737 LLVMDLLStorageClass LLVMGetDLLStorageClass(LLVMValueRef Global);
1738 void LLVMSetDLLStorageClass(LLVMValueRef Global, LLVMDLLStorageClass Class);
1739 LLVMBool LLVMHasUnnamedAddr(LLVMValueRef Global);
1740 void LLVMSetUnnamedAddr(LLVMValueRef Global, LLVMBool HasUnnamedAddr);
1743 * @defgroup LLVMCCoreValueWithAlignment Values with alignment
1745 * Functions in this group only apply to values with alignment, i.e.
1746 * global variables, load and store instructions.
1750 * Obtain the preferred alignment of the value.
1751 * @see llvm::AllocaInst::getAlignment()
1752 * @see llvm::LoadInst::getAlignment()
1753 * @see llvm::StoreInst::getAlignment()
1754 * @see llvm::GlobalValue::getAlignment()
1756 unsigned LLVMGetAlignment(LLVMValueRef V);
1759 * Set the preferred alignment of the value.
1760 * @see llvm::AllocaInst::setAlignment()
1761 * @see llvm::LoadInst::setAlignment()
1762 * @see llvm::StoreInst::setAlignment()
1763 * @see llvm::GlobalValue::setAlignment()
1765 void LLVMSetAlignment(LLVMValueRef V, unsigned Bytes);
1772 * @defgroup LLVMCoreValueConstantGlobalVariable Global Variables
1774 * This group contains functions that operate on global variable values.
1776 * @see llvm::GlobalVariable
1780 LLVMValueRef LLVMAddGlobal(LLVMModuleRef M, LLVMTypeRef Ty, const char *Name);
1781 LLVMValueRef LLVMAddGlobalInAddressSpace(LLVMModuleRef M, LLVMTypeRef Ty,
1783 unsigned AddressSpace);
1784 LLVMValueRef LLVMGetNamedGlobal(LLVMModuleRef M, const char *Name);
1785 LLVMValueRef LLVMGetFirstGlobal(LLVMModuleRef M);
1786 LLVMValueRef LLVMGetLastGlobal(LLVMModuleRef M);
1787 LLVMValueRef LLVMGetNextGlobal(LLVMValueRef GlobalVar);
1788 LLVMValueRef LLVMGetPreviousGlobal(LLVMValueRef GlobalVar);
1789 void LLVMDeleteGlobal(LLVMValueRef GlobalVar);
1790 LLVMValueRef LLVMGetInitializer(LLVMValueRef GlobalVar);
1791 void LLVMSetInitializer(LLVMValueRef GlobalVar, LLVMValueRef ConstantVal);
1792 LLVMBool LLVMIsThreadLocal(LLVMValueRef GlobalVar);
1793 void LLVMSetThreadLocal(LLVMValueRef GlobalVar, LLVMBool IsThreadLocal);
1794 LLVMBool LLVMIsGlobalConstant(LLVMValueRef GlobalVar);
1795 void LLVMSetGlobalConstant(LLVMValueRef GlobalVar, LLVMBool IsConstant);
1796 LLVMThreadLocalMode LLVMGetThreadLocalMode(LLVMValueRef GlobalVar);
1797 void LLVMSetThreadLocalMode(LLVMValueRef GlobalVar, LLVMThreadLocalMode Mode);
1798 LLVMBool LLVMIsExternallyInitialized(LLVMValueRef GlobalVar);
1799 void LLVMSetExternallyInitialized(LLVMValueRef GlobalVar, LLVMBool IsExtInit);
1806 * @defgroup LLVMCoreValueConstantGlobalAlias Global Aliases
1808 * This group contains function that operate on global alias values.
1810 * @see llvm::GlobalAlias
1814 LLVMValueRef LLVMAddAlias(LLVMModuleRef M, LLVMTypeRef Ty, LLVMValueRef Aliasee,
1822 * @defgroup LLVMCCoreValueFunction Function values
1824 * Functions in this group operate on LLVMValueRef instances that
1825 * correspond to llvm::Function instances.
1827 * @see llvm::Function
1833 * Remove a function from its containing module and deletes it.
1835 * @see llvm::Function::eraseFromParent()
1837 void LLVMDeleteFunction(LLVMValueRef Fn);
1840 * Obtain the ID number from a function instance.
1842 * @see llvm::Function::getIntrinsicID()
1844 unsigned LLVMGetIntrinsicID(LLVMValueRef Fn);
1847 * Obtain the calling function of a function.
1849 * The returned value corresponds to the LLVMCallConv enumeration.
1851 * @see llvm::Function::getCallingConv()
1853 unsigned LLVMGetFunctionCallConv(LLVMValueRef Fn);
1856 * Set the calling convention of a function.
1858 * @see llvm::Function::setCallingConv()
1860 * @param Fn Function to operate on
1861 * @param CC LLVMCallConv to set calling convention to
1863 void LLVMSetFunctionCallConv(LLVMValueRef Fn, unsigned CC);
1866 * Obtain the name of the garbage collector to use during code
1869 * @see llvm::Function::getGC()
1871 const char *LLVMGetGC(LLVMValueRef Fn);
1874 * Define the garbage collector to use during code generation.
1876 * @see llvm::Function::setGC()
1878 void LLVMSetGC(LLVMValueRef Fn, const char *Name);
1881 * Add an attribute to a function.
1883 * @see llvm::Function::addAttribute()
1885 void LLVMAddFunctionAttr(LLVMValueRef Fn, LLVMAttribute PA);
1888 * Add a target-dependent attribute to a fuction
1889 * @see llvm::AttrBuilder::addAttribute()
1891 void LLVMAddTargetDependentFunctionAttr(LLVMValueRef Fn, const char *A,
1895 * Obtain an attribute from a function.
1897 * @see llvm::Function::getAttributes()
1899 LLVMAttribute LLVMGetFunctionAttr(LLVMValueRef Fn);
1902 * Remove an attribute from a function.
1904 void LLVMRemoveFunctionAttr(LLVMValueRef Fn, LLVMAttribute PA);
1907 * @defgroup LLVMCCoreValueFunctionParameters Function Parameters
1909 * Functions in this group relate to arguments/parameters on functions.
1911 * Functions in this group expect LLVMValueRef instances that correspond
1912 * to llvm::Function instances.
1918 * Obtain the number of parameters in a function.
1920 * @see llvm::Function::arg_size()
1922 unsigned LLVMCountParams(LLVMValueRef Fn);
1925 * Obtain the parameters in a function.
1927 * The takes a pointer to a pre-allocated array of LLVMValueRef that is
1928 * at least LLVMCountParams() long. This array will be filled with
1929 * LLVMValueRef instances which correspond to the parameters the
1930 * function receives. Each LLVMValueRef corresponds to a llvm::Argument
1933 * @see llvm::Function::arg_begin()
1935 void LLVMGetParams(LLVMValueRef Fn, LLVMValueRef *Params);
1938 * Obtain the parameter at the specified index.
1940 * Parameters are indexed from 0.
1942 * @see llvm::Function::arg_begin()
1944 LLVMValueRef LLVMGetParam(LLVMValueRef Fn, unsigned Index);
1947 * Obtain the function to which this argument belongs.
1949 * Unlike other functions in this group, this one takes an LLVMValueRef
1950 * that corresponds to a llvm::Attribute.
1952 * The returned LLVMValueRef is the llvm::Function to which this
1955 LLVMValueRef LLVMGetParamParent(LLVMValueRef Inst);
1958 * Obtain the first parameter to a function.
1960 * @see llvm::Function::arg_begin()
1962 LLVMValueRef LLVMGetFirstParam(LLVMValueRef Fn);
1965 * Obtain the last parameter to a function.
1967 * @see llvm::Function::arg_end()
1969 LLVMValueRef LLVMGetLastParam(LLVMValueRef Fn);
1972 * Obtain the next parameter to a function.
1974 * This takes an LLVMValueRef obtained from LLVMGetFirstParam() (which is
1975 * actually a wrapped iterator) and obtains the next parameter from the
1976 * underlying iterator.
1978 LLVMValueRef LLVMGetNextParam(LLVMValueRef Arg);
1981 * Obtain the previous parameter to a function.
1983 * This is the opposite of LLVMGetNextParam().
1985 LLVMValueRef LLVMGetPreviousParam(LLVMValueRef Arg);
1988 * Add an attribute to a function argument.
1990 * @see llvm::Argument::addAttr()
1992 void LLVMAddAttribute(LLVMValueRef Arg, LLVMAttribute PA);
1995 * Remove an attribute from a function argument.
1997 * @see llvm::Argument::removeAttr()
1999 void LLVMRemoveAttribute(LLVMValueRef Arg, LLVMAttribute PA);
2002 * Get an attribute from a function argument.
2004 LLVMAttribute LLVMGetAttribute(LLVMValueRef Arg);
2007 * Set the alignment for a function parameter.
2009 * @see llvm::Argument::addAttr()
2010 * @see llvm::AttrBuilder::addAlignmentAttr()
2012 void LLVMSetParamAlignment(LLVMValueRef Arg, unsigned align);
2031 * @defgroup LLVMCCoreValueMetadata Metadata
2037 * Obtain a MDString value from a context.
2039 * The returned instance corresponds to the llvm::MDString class.
2041 * The instance is specified by string data of a specified length. The
2042 * string content is copied, so the backing memory can be freed after
2043 * this function returns.
2045 LLVMValueRef LLVMMDStringInContext(LLVMContextRef C, const char *Str,
2049 * Obtain a MDString value from the global context.
2051 LLVMValueRef LLVMMDString(const char *Str, unsigned SLen);
2054 * Obtain a MDNode value from a context.
2056 * The returned value corresponds to the llvm::MDNode class.
2058 LLVMValueRef LLVMMDNodeInContext(LLVMContextRef C, LLVMValueRef *Vals,
2062 * Obtain a MDNode value from the global context.
2064 LLVMValueRef LLVMMDNode(LLVMValueRef *Vals, unsigned Count);
2067 * Obtain the underlying string from a MDString value.
2069 * @param V Instance to obtain string from.
2070 * @param Len Memory address which will hold length of returned string.
2071 * @return String data in MDString.
2073 const char *LLVMGetMDString(LLVMValueRef V, unsigned* Len);
2076 * Obtain the number of operands from an MDNode value.
2078 * @param V MDNode to get number of operands from.
2079 * @return Number of operands of the MDNode.
2081 unsigned LLVMGetMDNodeNumOperands(LLVMValueRef V);
2084 * Obtain the given MDNode's operands.
2086 * The passed LLVMValueRef pointer should point to enough memory to hold all of
2087 * the operands of the given MDNode (see LLVMGetMDNodeNumOperands) as
2088 * LLVMValueRefs. This memory will be populated with the LLVMValueRefs of the
2089 * MDNode's operands.
2091 * @param V MDNode to get the operands from.
2092 * @param Dest Destination array for operands.
2094 void LLVMGetMDNodeOperands(LLVMValueRef V, LLVMValueRef *Dest);
2101 * @defgroup LLVMCCoreValueBasicBlock Basic Block
2103 * A basic block represents a single entry single exit section of code.
2104 * Basic blocks contain a list of instructions which form the body of
2107 * Basic blocks belong to functions. They have the type of label.
2109 * Basic blocks are themselves values. However, the C API models them as
2110 * LLVMBasicBlockRef.
2112 * @see llvm::BasicBlock
2118 * Convert a basic block instance to a value type.
2120 LLVMValueRef LLVMBasicBlockAsValue(LLVMBasicBlockRef BB);
2123 * Determine whether an LLVMValueRef is itself a basic block.
2125 LLVMBool LLVMValueIsBasicBlock(LLVMValueRef Val);
2128 * Convert an LLVMValueRef to an LLVMBasicBlockRef instance.
2130 LLVMBasicBlockRef LLVMValueAsBasicBlock(LLVMValueRef Val);
2133 * Obtain the function to which a basic block belongs.
2135 * @see llvm::BasicBlock::getParent()
2137 LLVMValueRef LLVMGetBasicBlockParent(LLVMBasicBlockRef BB);
2140 * Obtain the terminator instruction for a basic block.
2142 * If the basic block does not have a terminator (it is not well-formed
2143 * if it doesn't), then NULL is returned.
2145 * The returned LLVMValueRef corresponds to a llvm::TerminatorInst.
2147 * @see llvm::BasicBlock::getTerminator()
2149 LLVMValueRef LLVMGetBasicBlockTerminator(LLVMBasicBlockRef BB);
2152 * Obtain the number of basic blocks in a function.
2154 * @param Fn Function value to operate on.
2156 unsigned LLVMCountBasicBlocks(LLVMValueRef Fn);
2159 * Obtain all of the basic blocks in a function.
2161 * This operates on a function value. The BasicBlocks parameter is a
2162 * pointer to a pre-allocated array of LLVMBasicBlockRef of at least
2163 * LLVMCountBasicBlocks() in length. This array is populated with
2164 * LLVMBasicBlockRef instances.
2166 void LLVMGetBasicBlocks(LLVMValueRef Fn, LLVMBasicBlockRef *BasicBlocks);
2169 * Obtain the first basic block in a function.
2171 * The returned basic block can be used as an iterator. You will likely
2172 * eventually call into LLVMGetNextBasicBlock() with it.
2174 * @see llvm::Function::begin()
2176 LLVMBasicBlockRef LLVMGetFirstBasicBlock(LLVMValueRef Fn);
2179 * Obtain the last basic block in a function.
2181 * @see llvm::Function::end()
2183 LLVMBasicBlockRef LLVMGetLastBasicBlock(LLVMValueRef Fn);
2186 * Advance a basic block iterator.
2188 LLVMBasicBlockRef LLVMGetNextBasicBlock(LLVMBasicBlockRef BB);
2191 * Go backwards in a basic block iterator.
2193 LLVMBasicBlockRef LLVMGetPreviousBasicBlock(LLVMBasicBlockRef BB);
2196 * Obtain the basic block that corresponds to the entry point of a
2199 * @see llvm::Function::getEntryBlock()
2201 LLVMBasicBlockRef LLVMGetEntryBasicBlock(LLVMValueRef Fn);
2204 * Append a basic block to the end of a function.
2206 * @see llvm::BasicBlock::Create()
2208 LLVMBasicBlockRef LLVMAppendBasicBlockInContext(LLVMContextRef C,
2213 * Append a basic block to the end of a function using the global
2216 * @see llvm::BasicBlock::Create()
2218 LLVMBasicBlockRef LLVMAppendBasicBlock(LLVMValueRef Fn, const char *Name);
2221 * Insert a basic block in a function before another basic block.
2223 * The function to add to is determined by the function of the
2224 * passed basic block.
2226 * @see llvm::BasicBlock::Create()
2228 LLVMBasicBlockRef LLVMInsertBasicBlockInContext(LLVMContextRef C,
2229 LLVMBasicBlockRef BB,
2233 * Insert a basic block in a function using the global context.
2235 * @see llvm::BasicBlock::Create()
2237 LLVMBasicBlockRef LLVMInsertBasicBlock(LLVMBasicBlockRef InsertBeforeBB,
2241 * Remove a basic block from a function and delete it.
2243 * This deletes the basic block from its containing function and deletes
2244 * the basic block itself.
2246 * @see llvm::BasicBlock::eraseFromParent()
2248 void LLVMDeleteBasicBlock(LLVMBasicBlockRef BB);
2251 * Remove a basic block from a function.
2253 * This deletes the basic block from its containing function but keep
2254 * the basic block alive.
2256 * @see llvm::BasicBlock::removeFromParent()
2258 void LLVMRemoveBasicBlockFromParent(LLVMBasicBlockRef BB);
2261 * Move a basic block to before another one.
2263 * @see llvm::BasicBlock::moveBefore()
2265 void LLVMMoveBasicBlockBefore(LLVMBasicBlockRef BB, LLVMBasicBlockRef MovePos);
2268 * Move a basic block to after another one.
2270 * @see llvm::BasicBlock::moveAfter()
2272 void LLVMMoveBasicBlockAfter(LLVMBasicBlockRef BB, LLVMBasicBlockRef MovePos);
2275 * Obtain the first instruction in a basic block.
2277 * The returned LLVMValueRef corresponds to a llvm::Instruction
2280 LLVMValueRef LLVMGetFirstInstruction(LLVMBasicBlockRef BB);
2283 * Obtain the last instruction in a basic block.
2285 * The returned LLVMValueRef corresponds to an LLVM:Instruction.
2287 LLVMValueRef LLVMGetLastInstruction(LLVMBasicBlockRef BB);
2294 * @defgroup LLVMCCoreValueInstruction Instructions
2296 * Functions in this group relate to the inspection and manipulation of
2297 * individual instructions.
2299 * In the C++ API, an instruction is modeled by llvm::Instruction. This
2300 * class has a large number of descendents. llvm::Instruction is a
2301 * llvm::Value and in the C API, instructions are modeled by
2304 * This group also contains sub-groups which operate on specific
2305 * llvm::Instruction types, e.g. llvm::CallInst.
2311 * Determine whether an instruction has any metadata attached.
2313 int LLVMHasMetadata(LLVMValueRef Val);
2316 * Return metadata associated with an instruction value.
2318 LLVMValueRef LLVMGetMetadata(LLVMValueRef Val, unsigned KindID);
2321 * Set metadata associated with an instruction value.
2323 void LLVMSetMetadata(LLVMValueRef Val, unsigned KindID, LLVMValueRef Node);
2326 * Obtain the basic block to which an instruction belongs.
2328 * @see llvm::Instruction::getParent()
2330 LLVMBasicBlockRef LLVMGetInstructionParent(LLVMValueRef Inst);
2333 * Obtain the instruction that occurs after the one specified.
2335 * The next instruction will be from the same basic block.
2337 * If this is the last instruction in a basic block, NULL will be
2340 LLVMValueRef LLVMGetNextInstruction(LLVMValueRef Inst);
2343 * Obtain the instruction that occurred before this one.
2345 * If the instruction is the first instruction in a basic block, NULL
2348 LLVMValueRef LLVMGetPreviousInstruction(LLVMValueRef Inst);
2351 * Remove and delete an instruction.
2353 * The instruction specified is removed from its containing building
2354 * block and then deleted.
2356 * @see llvm::Instruction::eraseFromParent()
2358 void LLVMInstructionEraseFromParent(LLVMValueRef Inst);
2361 * Obtain the code opcode for an individual instruction.
2363 * @see llvm::Instruction::getOpCode()
2365 LLVMOpcode LLVMGetInstructionOpcode(LLVMValueRef Inst);
2368 * Obtain the predicate of an instruction.
2370 * This is only valid for instructions that correspond to llvm::ICmpInst
2371 * or llvm::ConstantExpr whose opcode is llvm::Instruction::ICmp.
2373 * @see llvm::ICmpInst::getPredicate()
2375 LLVMIntPredicate LLVMGetICmpPredicate(LLVMValueRef Inst);
2378 * @defgroup LLVMCCoreValueInstructionCall Call Sites and Invocations
2380 * Functions in this group apply to instructions that refer to call
2381 * sites and invocations. These correspond to C++ types in the
2382 * llvm::CallInst class tree.
2388 * Set the calling convention for a call instruction.
2390 * This expects an LLVMValueRef that corresponds to a llvm::CallInst or
2393 * @see llvm::CallInst::setCallingConv()
2394 * @see llvm::InvokeInst::setCallingConv()
2396 void LLVMSetInstructionCallConv(LLVMValueRef Instr, unsigned CC);
2399 * Obtain the calling convention for a call instruction.
2401 * This is the opposite of LLVMSetInstructionCallConv(). Reads its
2404 * @see LLVMSetInstructionCallConv()
2406 unsigned LLVMGetInstructionCallConv(LLVMValueRef Instr);
2409 void LLVMAddInstrAttribute(LLVMValueRef Instr, unsigned index, LLVMAttribute);
2410 void LLVMRemoveInstrAttribute(LLVMValueRef Instr, unsigned index,
2412 void LLVMSetInstrParamAlignment(LLVMValueRef Instr, unsigned index,
2416 * Obtain whether a call instruction is a tail call.
2418 * This only works on llvm::CallInst instructions.
2420 * @see llvm::CallInst::isTailCall()
2422 LLVMBool LLVMIsTailCall(LLVMValueRef CallInst);
2425 * Set whether a call instruction is a tail call.
2427 * This only works on llvm::CallInst instructions.
2429 * @see llvm::CallInst::setTailCall()
2431 void LLVMSetTailCall(LLVMValueRef CallInst, LLVMBool IsTailCall);
2438 * Obtain the default destination basic block of a switch instruction.
2440 * This only works on llvm::SwitchInst instructions.
2442 * @see llvm::SwitchInst::getDefaultDest()
2444 LLVMBasicBlockRef LLVMGetSwitchDefaultDest(LLVMValueRef SwitchInstr);
2447 * @defgroup LLVMCCoreValueInstructionPHINode PHI Nodes
2449 * Functions in this group only apply to instructions that map to
2450 * llvm::PHINode instances.
2456 * Add an incoming value to the end of a PHI list.
2458 void LLVMAddIncoming(LLVMValueRef PhiNode, LLVMValueRef *IncomingValues,
2459 LLVMBasicBlockRef *IncomingBlocks, unsigned Count);
2462 * Obtain the number of incoming basic blocks to a PHI node.
2464 unsigned LLVMCountIncoming(LLVMValueRef PhiNode);
2467 * Obtain an incoming value to a PHI node as an LLVMValueRef.
2469 LLVMValueRef LLVMGetIncomingValue(LLVMValueRef PhiNode, unsigned Index);
2472 * Obtain an incoming value to a PHI node as an LLVMBasicBlockRef.
2474 LLVMBasicBlockRef LLVMGetIncomingBlock(LLVMValueRef PhiNode, unsigned Index);
2489 * @defgroup LLVMCCoreInstructionBuilder Instruction Builders
2491 * An instruction builder represents a point within a basic block and is
2492 * the exclusive means of building instructions using the C interface.
2497 LLVMBuilderRef LLVMCreateBuilderInContext(LLVMContextRef C);
2498 LLVMBuilderRef LLVMCreateBuilder(void);
2499 void LLVMPositionBuilder(LLVMBuilderRef Builder, LLVMBasicBlockRef Block,
2500 LLVMValueRef Instr);
2501 void LLVMPositionBuilderBefore(LLVMBuilderRef Builder, LLVMValueRef Instr);
2502 void LLVMPositionBuilderAtEnd(LLVMBuilderRef Builder, LLVMBasicBlockRef Block);
2503 LLVMBasicBlockRef LLVMGetInsertBlock(LLVMBuilderRef Builder);
2504 void LLVMClearInsertionPosition(LLVMBuilderRef Builder);
2505 void LLVMInsertIntoBuilder(LLVMBuilderRef Builder, LLVMValueRef Instr);
2506 void LLVMInsertIntoBuilderWithName(LLVMBuilderRef Builder, LLVMValueRef Instr,
2508 void LLVMDisposeBuilder(LLVMBuilderRef Builder);
2511 void LLVMSetCurrentDebugLocation(LLVMBuilderRef Builder, LLVMValueRef L);
2512 LLVMValueRef LLVMGetCurrentDebugLocation(LLVMBuilderRef Builder);
2513 void LLVMSetInstDebugLocation(LLVMBuilderRef Builder, LLVMValueRef Inst);
2516 LLVMValueRef LLVMBuildRetVoid(LLVMBuilderRef);
2517 LLVMValueRef LLVMBuildRet(LLVMBuilderRef, LLVMValueRef V);
2518 LLVMValueRef LLVMBuildAggregateRet(LLVMBuilderRef, LLVMValueRef *RetVals,
2520 LLVMValueRef LLVMBuildBr(LLVMBuilderRef, LLVMBasicBlockRef Dest);
2521 LLVMValueRef LLVMBuildCondBr(LLVMBuilderRef, LLVMValueRef If,
2522 LLVMBasicBlockRef Then, LLVMBasicBlockRef Else);
2523 LLVMValueRef LLVMBuildSwitch(LLVMBuilderRef, LLVMValueRef V,
2524 LLVMBasicBlockRef Else, unsigned NumCases);
2525 LLVMValueRef LLVMBuildIndirectBr(LLVMBuilderRef B, LLVMValueRef Addr,
2527 LLVMValueRef LLVMBuildInvoke(LLVMBuilderRef, LLVMValueRef Fn,
2528 LLVMValueRef *Args, unsigned NumArgs,
2529 LLVMBasicBlockRef Then, LLVMBasicBlockRef Catch,
2531 LLVMValueRef LLVMBuildLandingPad(LLVMBuilderRef B, LLVMTypeRef Ty,
2532 LLVMValueRef PersFn, unsigned NumClauses,
2534 LLVMValueRef LLVMBuildResume(LLVMBuilderRef B, LLVMValueRef Exn);
2535 LLVMValueRef LLVMBuildUnreachable(LLVMBuilderRef);
2537 /* Add a case to the switch instruction */
2538 void LLVMAddCase(LLVMValueRef Switch, LLVMValueRef OnVal,
2539 LLVMBasicBlockRef Dest);
2541 /* Add a destination to the indirectbr instruction */
2542 void LLVMAddDestination(LLVMValueRef IndirectBr, LLVMBasicBlockRef Dest);
2544 /* Add a catch or filter clause to the landingpad instruction */
2545 void LLVMAddClause(LLVMValueRef LandingPad, LLVMValueRef ClauseVal);
2547 /* Set the 'cleanup' flag in the landingpad instruction */
2548 void LLVMSetCleanup(LLVMValueRef LandingPad, LLVMBool Val);
2551 LLVMValueRef LLVMBuildAdd(LLVMBuilderRef, LLVMValueRef LHS, LLVMValueRef RHS,
2553 LLVMValueRef LLVMBuildNSWAdd(LLVMBuilderRef, LLVMValueRef LHS, LLVMValueRef RHS,
2555 LLVMValueRef LLVMBuildNUWAdd(LLVMBuilderRef, LLVMValueRef LHS, LLVMValueRef RHS,
2557 LLVMValueRef LLVMBuildFAdd(LLVMBuilderRef, LLVMValueRef LHS, LLVMValueRef RHS,
2559 LLVMValueRef LLVMBuildSub(LLVMBuilderRef, LLVMValueRef LHS, LLVMValueRef RHS,
2561 LLVMValueRef LLVMBuildNSWSub(LLVMBuilderRef, LLVMValueRef LHS, LLVMValueRef RHS,
2563 LLVMValueRef LLVMBuildNUWSub(LLVMBuilderRef, LLVMValueRef LHS, LLVMValueRef RHS,
2565 LLVMValueRef LLVMBuildFSub(LLVMBuilderRef, LLVMValueRef LHS, LLVMValueRef RHS,
2567 LLVMValueRef LLVMBuildMul(LLVMBuilderRef, LLVMValueRef LHS, LLVMValueRef RHS,
2569 LLVMValueRef LLVMBuildNSWMul(LLVMBuilderRef, LLVMValueRef LHS, LLVMValueRef RHS,
2571 LLVMValueRef LLVMBuildNUWMul(LLVMBuilderRef, LLVMValueRef LHS, LLVMValueRef RHS,
2573 LLVMValueRef LLVMBuildFMul(LLVMBuilderRef, LLVMValueRef LHS, LLVMValueRef RHS,
2575 LLVMValueRef LLVMBuildUDiv(LLVMBuilderRef, LLVMValueRef LHS, LLVMValueRef RHS,
2577 LLVMValueRef LLVMBuildSDiv(LLVMBuilderRef, LLVMValueRef LHS, LLVMValueRef RHS,
2579 LLVMValueRef LLVMBuildExactSDiv(LLVMBuilderRef, LLVMValueRef LHS, LLVMValueRef RHS,
2581 LLVMValueRef LLVMBuildFDiv(LLVMBuilderRef, LLVMValueRef LHS, LLVMValueRef RHS,
2583 LLVMValueRef LLVMBuildURem(LLVMBuilderRef, LLVMValueRef LHS, LLVMValueRef RHS,
2585 LLVMValueRef LLVMBuildSRem(LLVMBuilderRef, LLVMValueRef LHS, LLVMValueRef RHS,
2587 LLVMValueRef LLVMBuildFRem(LLVMBuilderRef, LLVMValueRef LHS, LLVMValueRef RHS,
2589 LLVMValueRef LLVMBuildShl(LLVMBuilderRef, LLVMValueRef LHS, LLVMValueRef RHS,
2591 LLVMValueRef LLVMBuildLShr(LLVMBuilderRef, LLVMValueRef LHS, LLVMValueRef RHS,
2593 LLVMValueRef LLVMBuildAShr(LLVMBuilderRef, LLVMValueRef LHS, LLVMValueRef RHS,
2595 LLVMValueRef LLVMBuildAnd(LLVMBuilderRef, LLVMValueRef LHS, LLVMValueRef RHS,
2597 LLVMValueRef LLVMBuildOr(LLVMBuilderRef, LLVMValueRef LHS, LLVMValueRef RHS,
2599 LLVMValueRef LLVMBuildXor(LLVMBuilderRef, LLVMValueRef LHS, LLVMValueRef RHS,
2601 LLVMValueRef LLVMBuildBinOp(LLVMBuilderRef B, LLVMOpcode Op,
2602 LLVMValueRef LHS, LLVMValueRef RHS,
2604 LLVMValueRef LLVMBuildNeg(LLVMBuilderRef, LLVMValueRef V, const char *Name);
2605 LLVMValueRef LLVMBuildNSWNeg(LLVMBuilderRef B, LLVMValueRef V,
2607 LLVMValueRef LLVMBuildNUWNeg(LLVMBuilderRef B, LLVMValueRef V,
2609 LLVMValueRef LLVMBuildFNeg(LLVMBuilderRef, LLVMValueRef V, const char *Name);
2610 LLVMValueRef LLVMBuildNot(LLVMBuilderRef, LLVMValueRef V, const char *Name);
2613 LLVMValueRef LLVMBuildMalloc(LLVMBuilderRef, LLVMTypeRef Ty, const char *Name);
2614 LLVMValueRef LLVMBuildArrayMalloc(LLVMBuilderRef, LLVMTypeRef Ty,
2615 LLVMValueRef Val, const char *Name);
2616 LLVMValueRef LLVMBuildAlloca(LLVMBuilderRef, LLVMTypeRef Ty, const char *Name);
2617 LLVMValueRef LLVMBuildArrayAlloca(LLVMBuilderRef, LLVMTypeRef Ty,
2618 LLVMValueRef Val, const char *Name);
2619 LLVMValueRef LLVMBuildFree(LLVMBuilderRef, LLVMValueRef PointerVal);
2620 LLVMValueRef LLVMBuildLoad(LLVMBuilderRef, LLVMValueRef PointerVal,
2622 LLVMValueRef LLVMBuildStore(LLVMBuilderRef, LLVMValueRef Val, LLVMValueRef Ptr);
2623 LLVMValueRef LLVMBuildGEP(LLVMBuilderRef B, LLVMValueRef Pointer,
2624 LLVMValueRef *Indices, unsigned NumIndices,
2626 LLVMValueRef LLVMBuildInBoundsGEP(LLVMBuilderRef B, LLVMValueRef Pointer,
2627 LLVMValueRef *Indices, unsigned NumIndices,
2629 LLVMValueRef LLVMBuildStructGEP(LLVMBuilderRef B, LLVMValueRef Pointer,
2630 unsigned Idx, const char *Name);
2631 LLVMValueRef LLVMBuildGlobalString(LLVMBuilderRef B, const char *Str,
2633 LLVMValueRef LLVMBuildGlobalStringPtr(LLVMBuilderRef B, const char *Str,
2635 LLVMBool LLVMGetVolatile(LLVMValueRef MemoryAccessInst);
2636 void LLVMSetVolatile(LLVMValueRef MemoryAccessInst, LLVMBool IsVolatile);
2639 LLVMValueRef LLVMBuildTrunc(LLVMBuilderRef, LLVMValueRef Val,
2640 LLVMTypeRef DestTy, const char *Name);
2641 LLVMValueRef LLVMBuildZExt(LLVMBuilderRef, LLVMValueRef Val,
2642 LLVMTypeRef DestTy, const char *Name);
2643 LLVMValueRef LLVMBuildSExt(LLVMBuilderRef, LLVMValueRef Val,
2644 LLVMTypeRef DestTy, const char *Name);
2645 LLVMValueRef LLVMBuildFPToUI(LLVMBuilderRef, LLVMValueRef Val,
2646 LLVMTypeRef DestTy, const char *Name);
2647 LLVMValueRef LLVMBuildFPToSI(LLVMBuilderRef, LLVMValueRef Val,
2648 LLVMTypeRef DestTy, const char *Name);
2649 LLVMValueRef LLVMBuildUIToFP(LLVMBuilderRef, LLVMValueRef Val,
2650 LLVMTypeRef DestTy, const char *Name);
2651 LLVMValueRef LLVMBuildSIToFP(LLVMBuilderRef, LLVMValueRef Val,
2652 LLVMTypeRef DestTy, const char *Name);
2653 LLVMValueRef LLVMBuildFPTrunc(LLVMBuilderRef, LLVMValueRef Val,
2654 LLVMTypeRef DestTy, const char *Name);
2655 LLVMValueRef LLVMBuildFPExt(LLVMBuilderRef, LLVMValueRef Val,
2656 LLVMTypeRef DestTy, const char *Name);
2657 LLVMValueRef LLVMBuildPtrToInt(LLVMBuilderRef, LLVMValueRef Val,
2658 LLVMTypeRef DestTy, const char *Name);
2659 LLVMValueRef LLVMBuildIntToPtr(LLVMBuilderRef, LLVMValueRef Val,
2660 LLVMTypeRef DestTy, const char *Name);
2661 LLVMValueRef LLVMBuildBitCast(LLVMBuilderRef, LLVMValueRef Val,
2662 LLVMTypeRef DestTy, const char *Name);
2663 LLVMValueRef LLVMBuildAddrSpaceCast(LLVMBuilderRef, LLVMValueRef Val,
2664 LLVMTypeRef DestTy, const char *Name);
2665 LLVMValueRef LLVMBuildZExtOrBitCast(LLVMBuilderRef, LLVMValueRef Val,
2666 LLVMTypeRef DestTy, const char *Name);
2667 LLVMValueRef LLVMBuildSExtOrBitCast(LLVMBuilderRef, LLVMValueRef Val,
2668 LLVMTypeRef DestTy, const char *Name);
2669 LLVMValueRef LLVMBuildTruncOrBitCast(LLVMBuilderRef, LLVMValueRef Val,
2670 LLVMTypeRef DestTy, const char *Name);
2671 LLVMValueRef LLVMBuildCast(LLVMBuilderRef B, LLVMOpcode Op, LLVMValueRef Val,
2672 LLVMTypeRef DestTy, const char *Name);
2673 LLVMValueRef LLVMBuildPointerCast(LLVMBuilderRef, LLVMValueRef Val,
2674 LLVMTypeRef DestTy, const char *Name);
2675 LLVMValueRef LLVMBuildIntCast(LLVMBuilderRef, LLVMValueRef Val, /*Signed cast!*/
2676 LLVMTypeRef DestTy, const char *Name);
2677 LLVMValueRef LLVMBuildFPCast(LLVMBuilderRef, LLVMValueRef Val,
2678 LLVMTypeRef DestTy, const char *Name);
2681 LLVMValueRef LLVMBuildICmp(LLVMBuilderRef, LLVMIntPredicate Op,
2682 LLVMValueRef LHS, LLVMValueRef RHS,
2684 LLVMValueRef LLVMBuildFCmp(LLVMBuilderRef, LLVMRealPredicate Op,
2685 LLVMValueRef LHS, LLVMValueRef RHS,
2688 /* Miscellaneous instructions */
2689 LLVMValueRef LLVMBuildPhi(LLVMBuilderRef, LLVMTypeRef Ty, const char *Name);
2690 LLVMValueRef LLVMBuildCall(LLVMBuilderRef, LLVMValueRef Fn,
2691 LLVMValueRef *Args, unsigned NumArgs,
2693 LLVMValueRef LLVMBuildSelect(LLVMBuilderRef, LLVMValueRef If,
2694 LLVMValueRef Then, LLVMValueRef Else,
2696 LLVMValueRef LLVMBuildVAArg(LLVMBuilderRef, LLVMValueRef List, LLVMTypeRef Ty,
2698 LLVMValueRef LLVMBuildExtractElement(LLVMBuilderRef, LLVMValueRef VecVal,
2699 LLVMValueRef Index, const char *Name);
2700 LLVMValueRef LLVMBuildInsertElement(LLVMBuilderRef, LLVMValueRef VecVal,
2701 LLVMValueRef EltVal, LLVMValueRef Index,
2703 LLVMValueRef LLVMBuildShuffleVector(LLVMBuilderRef, LLVMValueRef V1,
2704 LLVMValueRef V2, LLVMValueRef Mask,
2706 LLVMValueRef LLVMBuildExtractValue(LLVMBuilderRef, LLVMValueRef AggVal,
2707 unsigned Index, const char *Name);
2708 LLVMValueRef LLVMBuildInsertValue(LLVMBuilderRef, LLVMValueRef AggVal,
2709 LLVMValueRef EltVal, unsigned Index,
2712 LLVMValueRef LLVMBuildIsNull(LLVMBuilderRef, LLVMValueRef Val,
2714 LLVMValueRef LLVMBuildIsNotNull(LLVMBuilderRef, LLVMValueRef Val,
2716 LLVMValueRef LLVMBuildPtrDiff(LLVMBuilderRef, LLVMValueRef LHS,
2717 LLVMValueRef RHS, const char *Name);
2718 LLVMValueRef LLVMBuildFence(LLVMBuilderRef B, LLVMAtomicOrdering ordering,
2719 LLVMBool singleThread, const char *Name);
2720 LLVMValueRef LLVMBuildAtomicRMW(LLVMBuilderRef B, LLVMAtomicRMWBinOp op,
2721 LLVMValueRef PTR, LLVMValueRef Val,
2722 LLVMAtomicOrdering ordering,
2723 LLVMBool singleThread);
2730 * @defgroup LLVMCCoreModuleProvider Module Providers
2736 * Changes the type of M so it can be passed to FunctionPassManagers and the
2737 * JIT. They take ModuleProviders for historical reasons.
2739 LLVMModuleProviderRef
2740 LLVMCreateModuleProviderForExistingModule(LLVMModuleRef M);
2743 * Destroys the module M.
2745 void LLVMDisposeModuleProvider(LLVMModuleProviderRef M);
2752 * @defgroup LLVMCCoreMemoryBuffers Memory Buffers
2757 LLVMBool LLVMCreateMemoryBufferWithContentsOfFile(const char *Path,
2758 LLVMMemoryBufferRef *OutMemBuf,
2760 LLVMBool LLVMCreateMemoryBufferWithSTDIN(LLVMMemoryBufferRef *OutMemBuf,
2762 LLVMMemoryBufferRef LLVMCreateMemoryBufferWithMemoryRange(const char *InputData,
2763 size_t InputDataLength,
2764 const char *BufferName,
2765 LLVMBool RequiresNullTerminator);
2766 LLVMMemoryBufferRef LLVMCreateMemoryBufferWithMemoryRangeCopy(const char *InputData,
2767 size_t InputDataLength,
2768 const char *BufferName);
2769 const char *LLVMGetBufferStart(LLVMMemoryBufferRef MemBuf);
2770 size_t LLVMGetBufferSize(LLVMMemoryBufferRef MemBuf);
2771 void LLVMDisposeMemoryBuffer(LLVMMemoryBufferRef MemBuf);
2778 * @defgroup LLVMCCorePassRegistry Pass Registry
2783 /** Return the global pass registry, for use with initialization functions.
2784 @see llvm::PassRegistry::getPassRegistry */
2785 LLVMPassRegistryRef LLVMGetGlobalPassRegistry(void);
2792 * @defgroup LLVMCCorePassManagers Pass Managers
2797 /** Constructs a new whole-module pass pipeline. This type of pipeline is
2798 suitable for link-time optimization and whole-module transformations.
2799 @see llvm::PassManager::PassManager */
2800 LLVMPassManagerRef LLVMCreatePassManager(void);
2802 /** Constructs a new function-by-function pass pipeline over the module
2803 provider. It does not take ownership of the module provider. This type of
2804 pipeline is suitable for code generation and JIT compilation tasks.
2805 @see llvm::FunctionPassManager::FunctionPassManager */
2806 LLVMPassManagerRef LLVMCreateFunctionPassManagerForModule(LLVMModuleRef M);
2808 /** Deprecated: Use LLVMCreateFunctionPassManagerForModule instead. */
2809 LLVMPassManagerRef LLVMCreateFunctionPassManager(LLVMModuleProviderRef MP);
2811 /** Initializes, executes on the provided module, and finalizes all of the
2812 passes scheduled in the pass manager. Returns 1 if any of the passes
2813 modified the module, 0 otherwise.
2814 @see llvm::PassManager::run(Module&) */
2815 LLVMBool LLVMRunPassManager(LLVMPassManagerRef PM, LLVMModuleRef M);
2817 /** Initializes all of the function passes scheduled in the function pass
2818 manager. Returns 1 if any of the passes modified the module, 0 otherwise.
2819 @see llvm::FunctionPassManager::doInitialization */
2820 LLVMBool LLVMInitializeFunctionPassManager(LLVMPassManagerRef FPM);
2822 /** Executes all of the function passes scheduled in the function pass manager
2823 on the provided function. Returns 1 if any of the passes modified the
2824 function, false otherwise.
2825 @see llvm::FunctionPassManager::run(Function&) */
2826 LLVMBool LLVMRunFunctionPassManager(LLVMPassManagerRef FPM, LLVMValueRef F);
2828 /** Finalizes all of the function passes scheduled in in the function pass
2829 manager. Returns 1 if any of the passes modified the module, 0 otherwise.
2830 @see llvm::FunctionPassManager::doFinalization */
2831 LLVMBool LLVMFinalizeFunctionPassManager(LLVMPassManagerRef FPM);
2833 /** Frees the memory of a pass pipeline. For function pipelines, does not free
2834 the module provider.
2835 @see llvm::PassManagerBase::~PassManagerBase. */
2836 void LLVMDisposePassManager(LLVMPassManagerRef PM);
2843 * @defgroup LLVMCCoreThreading Threading
2845 * Handle the structures needed to make LLVM safe for multithreading.
2850 /** Allocate and initialize structures needed to make LLVM safe for
2851 multithreading. The return value indicates whether multithreaded
2852 initialization succeeded. Must be executed in isolation from all
2853 other LLVM api calls.
2854 @see llvm::llvm_start_multithreaded */
2855 LLVMBool LLVMStartMultithreaded(void);
2857 /** Deallocate structures necessary to make LLVM safe for multithreading.
2858 Must be executed in isolation from all other LLVM api calls.
2859 @see llvm::llvm_stop_multithreaded */
2860 void LLVMStopMultithreaded(void);
2862 /** Check whether LLVM is executing in thread-safe mode or not.
2863 @see llvm::llvm_is_multithreaded */
2864 LLVMBool LLVMIsMultithreaded(void);
2880 #endif /* !defined(__cplusplus) */
2882 #endif /* !defined(LLVM_C_CORE_H) */