LLVM API Documentation

Core.h
Go to the documentation of this file.
00001 /*===-- llvm-c/Core.h - Core Library C Interface ------------------*- C -*-===*\
00002 |*                                                                            *|
00003 |*                     The LLVM Compiler Infrastructure                       *|
00004 |*                                                                            *|
00005 |* This file is distributed under the University of Illinois Open Source      *|
00006 |* License. See LICENSE.TXT for details.                                      *|
00007 |*                                                                            *|
00008 |*===----------------------------------------------------------------------===*|
00009 |*                                                                            *|
00010 |* This header declares the C interface to libLLVMCore.a, which implements    *|
00011 |* the LLVM intermediate representation.                                      *|
00012 |*                                                                            *|
00013 \*===----------------------------------------------------------------------===*/
00014 
00015 #ifndef LLVM_C_CORE_H
00016 #define LLVM_C_CORE_H
00017 
00018 #include "llvm-c/Support.h"
00019 
00020 #ifdef __cplusplus
00021 extern "C" {
00022 #endif
00023 
00024 /**
00025  * @defgroup LLVMC LLVM-C: C interface to LLVM
00026  *
00027  * This module exposes parts of the LLVM library as a C API.
00028  *
00029  * @{
00030  */
00031 
00032 /**
00033  * @defgroup LLVMCTransforms Transforms
00034  */
00035 
00036 /**
00037  * @defgroup LLVMCCore Core
00038  *
00039  * This modules provide an interface to libLLVMCore, which implements
00040  * the LLVM intermediate representation as well as other related types
00041  * and utilities.
00042  *
00043  * LLVM uses a polymorphic type hierarchy which C cannot represent, therefore
00044  * parameters must be passed as base types. Despite the declared types, most
00045  * of the functions provided operate only on branches of the type hierarchy.
00046  * The declared parameter names are descriptive and specify which type is
00047  * required. Additionally, each type hierarchy is documented along with the
00048  * functions that operate upon it. For more detail, refer to LLVM's C++ code.
00049  * If in doubt, refer to Core.cpp, which performs parameter downcasts in the
00050  * form unwrap<RequiredType>(Param).
00051  *
00052  * Many exotic languages can interoperate with C code but have a harder time
00053  * with C++ due to name mangling. So in addition to C, this interface enables
00054  * tools written in such languages.
00055  *
00056  * @{
00057  */
00058 
00059 /**
00060  * @defgroup LLVMCCoreTypes Types and Enumerations
00061  *
00062  * @{
00063  */
00064 
00065 /* Opaque types. */
00066 
00067 /**
00068  * The top-level container for all LLVM global data. See the LLVMContext class.
00069  */
00070 typedef struct LLVMOpaqueContext *LLVMContextRef;
00071 
00072 /**
00073  * The top-level container for all other LLVM Intermediate Representation (IR)
00074  * objects.
00075  *
00076  * @see llvm::Module
00077  */
00078 typedef struct LLVMOpaqueModule *LLVMModuleRef;
00079 
00080 /**
00081  * Each value in the LLVM IR has a type, an LLVMTypeRef.
00082  *
00083  * @see llvm::Type
00084  */
00085 typedef struct LLVMOpaqueType *LLVMTypeRef;
00086 
00087 /**
00088  * Represents an individual value in LLVM IR.
00089  *
00090  * This models llvm::Value.
00091  */
00092 typedef struct LLVMOpaqueValue *LLVMValueRef;
00093 
00094 /**
00095  * Represents a basic block of instructions in LLVM IR.
00096  *
00097  * This models llvm::BasicBlock.
00098  */
00099 typedef struct LLVMOpaqueBasicBlock *LLVMBasicBlockRef;
00100 
00101 /**
00102  * Represents an LLVM basic block builder.
00103  *
00104  * This models llvm::IRBuilder.
00105  */
00106 typedef struct LLVMOpaqueBuilder *LLVMBuilderRef;
00107 
00108 /**
00109  * Interface used to provide a module to JIT or interpreter.
00110  * This is now just a synonym for llvm::Module, but we have to keep using the
00111  * different type to keep binary compatibility.
00112  */
00113 typedef struct LLVMOpaqueModuleProvider *LLVMModuleProviderRef;
00114 
00115 /** @see llvm::PassManagerBase */
00116 typedef struct LLVMOpaquePassManager *LLVMPassManagerRef;
00117 
00118 /** @see llvm::PassRegistry */
00119 typedef struct LLVMOpaquePassRegistry *LLVMPassRegistryRef;
00120 
00121 /**
00122  * Used to get the users and usees of a Value.
00123  *
00124  * @see llvm::Use */
00125 typedef struct LLVMOpaqueUse *LLVMUseRef;
00126 
00127 
00128 /**
00129  * @see llvm::DiagnosticInfo
00130  */
00131 typedef struct LLVMOpaqueDiagnosticInfo *LLVMDiagnosticInfoRef;
00132 
00133 typedef enum {
00134     LLVMZExtAttribute       = 1<<0,
00135     LLVMSExtAttribute       = 1<<1,
00136     LLVMNoReturnAttribute   = 1<<2,
00137     LLVMInRegAttribute      = 1<<3,
00138     LLVMStructRetAttribute  = 1<<4,
00139     LLVMNoUnwindAttribute   = 1<<5,
00140     LLVMNoAliasAttribute    = 1<<6,
00141     LLVMByValAttribute      = 1<<7,
00142     LLVMNestAttribute       = 1<<8,
00143     LLVMReadNoneAttribute   = 1<<9,
00144     LLVMReadOnlyAttribute   = 1<<10,
00145     LLVMNoInlineAttribute   = 1<<11,
00146     LLVMAlwaysInlineAttribute    = 1<<12,
00147     LLVMOptimizeForSizeAttribute = 1<<13,
00148     LLVMStackProtectAttribute    = 1<<14,
00149     LLVMStackProtectReqAttribute = 1<<15,
00150     LLVMAlignment = 31<<16,
00151     LLVMNoCaptureAttribute  = 1<<21,
00152     LLVMNoRedZoneAttribute  = 1<<22,
00153     LLVMNoImplicitFloatAttribute = 1<<23,
00154     LLVMNakedAttribute      = 1<<24,
00155     LLVMInlineHintAttribute = 1<<25,
00156     LLVMStackAlignment = 7<<26,
00157     LLVMReturnsTwice = 1 << 29,
00158     LLVMUWTable = 1 << 30,
00159     LLVMNonLazyBind = 1 << 31
00160 
00161     /* FIXME: These attributes are currently not included in the C API as
00162        a temporary measure until the API/ABI impact to the C API is understood
00163        and the path forward agreed upon.
00164     LLVMAddressSafety = 1ULL << 32,
00165     LLVMStackProtectStrongAttribute = 1ULL<<33,
00166     LLVMCold = 1ULL << 34,
00167     LLVMOptimizeNone = 1ULL << 35,
00168     LLVMInAllocaAttribute = 1ULL << 36,
00169     LLVMNonNullAttribute = 1ULL << 37,
00170     LLVMJumpTableAttribute = 1ULL << 38,
00171     LLVMDereferenceableAttribute = 1ULL << 39,
00172     */
00173 } LLVMAttribute;
00174 
00175 typedef enum {
00176   /* Terminator Instructions */
00177   LLVMRet            = 1,
00178   LLVMBr             = 2,
00179   LLVMSwitch         = 3,
00180   LLVMIndirectBr     = 4,
00181   LLVMInvoke         = 5,
00182   /* removed 6 due to API changes */
00183   LLVMUnreachable    = 7,
00184 
00185   /* Standard Binary Operators */
00186   LLVMAdd            = 8,
00187   LLVMFAdd           = 9,
00188   LLVMSub            = 10,
00189   LLVMFSub           = 11,
00190   LLVMMul            = 12,
00191   LLVMFMul           = 13,
00192   LLVMUDiv           = 14,
00193   LLVMSDiv           = 15,
00194   LLVMFDiv           = 16,
00195   LLVMURem           = 17,
00196   LLVMSRem           = 18,
00197   LLVMFRem           = 19,
00198 
00199   /* Logical Operators */
00200   LLVMShl            = 20,
00201   LLVMLShr           = 21,
00202   LLVMAShr           = 22,
00203   LLVMAnd            = 23,
00204   LLVMOr             = 24,
00205   LLVMXor            = 25,
00206 
00207   /* Memory Operators */
00208   LLVMAlloca         = 26,
00209   LLVMLoad           = 27,
00210   LLVMStore          = 28,
00211   LLVMGetElementPtr  = 29,
00212 
00213   /* Cast Operators */
00214   LLVMTrunc          = 30,
00215   LLVMZExt           = 31,
00216   LLVMSExt           = 32,
00217   LLVMFPToUI         = 33,
00218   LLVMFPToSI         = 34,
00219   LLVMUIToFP         = 35,
00220   LLVMSIToFP         = 36,
00221   LLVMFPTrunc        = 37,
00222   LLVMFPExt          = 38,
00223   LLVMPtrToInt       = 39,
00224   LLVMIntToPtr       = 40,
00225   LLVMBitCast        = 41,
00226   LLVMAddrSpaceCast  = 60,
00227 
00228   /* Other Operators */
00229   LLVMICmp           = 42,
00230   LLVMFCmp           = 43,
00231   LLVMPHI            = 44,
00232   LLVMCall           = 45,
00233   LLVMSelect         = 46,
00234   LLVMUserOp1        = 47,
00235   LLVMUserOp2        = 48,
00236   LLVMVAArg          = 49,
00237   LLVMExtractElement = 50,
00238   LLVMInsertElement  = 51,
00239   LLVMShuffleVector  = 52,
00240   LLVMExtractValue   = 53,
00241   LLVMInsertValue    = 54,
00242 
00243   /* Atomic operators */
00244   LLVMFence          = 55,
00245   LLVMAtomicCmpXchg  = 56,
00246   LLVMAtomicRMW      = 57,
00247 
00248   /* Exception Handling Operators */
00249   LLVMResume         = 58,
00250   LLVMLandingPad     = 59
00251 
00252 } LLVMOpcode;
00253 
00254 typedef enum {
00255   LLVMVoidTypeKind,        /**< type with no size */
00256   LLVMHalfTypeKind,        /**< 16 bit floating point type */
00257   LLVMFloatTypeKind,       /**< 32 bit floating point type */
00258   LLVMDoubleTypeKind,      /**< 64 bit floating point type */
00259   LLVMX86_FP80TypeKind,    /**< 80 bit floating point type (X87) */
00260   LLVMFP128TypeKind,       /**< 128 bit floating point type (112-bit mantissa)*/
00261   LLVMPPC_FP128TypeKind,   /**< 128 bit floating point type (two 64-bits) */
00262   LLVMLabelTypeKind,       /**< Labels */
00263   LLVMIntegerTypeKind,     /**< Arbitrary bit width integers */
00264   LLVMFunctionTypeKind,    /**< Functions */
00265   LLVMStructTypeKind,      /**< Structures */
00266   LLVMArrayTypeKind,       /**< Arrays */
00267   LLVMPointerTypeKind,     /**< Pointers */
00268   LLVMVectorTypeKind,      /**< SIMD 'packed' format, or other vector type */
00269   LLVMMetadataTypeKind,    /**< Metadata */
00270   LLVMX86_MMXTypeKind      /**< X86 MMX */
00271 } LLVMTypeKind;
00272 
00273 typedef enum {
00274   LLVMExternalLinkage,    /**< Externally visible function */
00275   LLVMAvailableExternallyLinkage,
00276   LLVMLinkOnceAnyLinkage, /**< Keep one copy of function when linking (inline)*/
00277   LLVMLinkOnceODRLinkage, /**< Same, but only replaced by something
00278                             equivalent. */
00279   LLVMLinkOnceODRAutoHideLinkage, /**< Obsolete */
00280   LLVMWeakAnyLinkage,     /**< Keep one copy of function when linking (weak) */
00281   LLVMWeakODRLinkage,     /**< Same, but only replaced by something
00282                             equivalent. */
00283   LLVMAppendingLinkage,   /**< Special purpose, only applies to global arrays */
00284   LLVMInternalLinkage,    /**< Rename collisions when linking (static
00285                                functions) */
00286   LLVMPrivateLinkage,     /**< Like Internal, but omit from symbol table */
00287   LLVMDLLImportLinkage,   /**< Obsolete */
00288   LLVMDLLExportLinkage,   /**< Obsolete */
00289   LLVMExternalWeakLinkage,/**< ExternalWeak linkage description */
00290   LLVMGhostLinkage,       /**< Obsolete */
00291   LLVMCommonLinkage,      /**< Tentative definitions */
00292   LLVMLinkerPrivateLinkage, /**< Like Private, but linker removes. */
00293   LLVMLinkerPrivateWeakLinkage /**< Like LinkerPrivate, but is weak. */
00294 } LLVMLinkage;
00295 
00296 typedef enum {
00297   LLVMDefaultVisibility,  /**< The GV is visible */
00298   LLVMHiddenVisibility,   /**< The GV is hidden */
00299   LLVMProtectedVisibility /**< The GV is protected */
00300 } LLVMVisibility;
00301 
00302 typedef enum {
00303   LLVMDefaultStorageClass   = 0,
00304   LLVMDLLImportStorageClass = 1, /**< Function to be imported from DLL. */
00305   LLVMDLLExportStorageClass = 2  /**< Function to be accessible from DLL. */
00306 } LLVMDLLStorageClass;
00307 
00308 typedef enum {
00309   LLVMCCallConv           = 0,
00310   LLVMFastCallConv        = 8,
00311   LLVMColdCallConv        = 9,
00312   LLVMWebKitJSCallConv    = 12,
00313   LLVMAnyRegCallConv      = 13,
00314   LLVMX86StdcallCallConv  = 64,
00315   LLVMX86FastcallCallConv = 65
00316 } LLVMCallConv;
00317 
00318 typedef enum {
00319   LLVMIntEQ = 32, /**< equal */
00320   LLVMIntNE,      /**< not equal */
00321   LLVMIntUGT,     /**< unsigned greater than */
00322   LLVMIntUGE,     /**< unsigned greater or equal */
00323   LLVMIntULT,     /**< unsigned less than */
00324   LLVMIntULE,     /**< unsigned less or equal */
00325   LLVMIntSGT,     /**< signed greater than */
00326   LLVMIntSGE,     /**< signed greater or equal */
00327   LLVMIntSLT,     /**< signed less than */
00328   LLVMIntSLE      /**< signed less or equal */
00329 } LLVMIntPredicate;
00330 
00331 typedef enum {
00332   LLVMRealPredicateFalse, /**< Always false (always folded) */
00333   LLVMRealOEQ,            /**< True if ordered and equal */
00334   LLVMRealOGT,            /**< True if ordered and greater than */
00335   LLVMRealOGE,            /**< True if ordered and greater than or equal */
00336   LLVMRealOLT,            /**< True if ordered and less than */
00337   LLVMRealOLE,            /**< True if ordered and less than or equal */
00338   LLVMRealONE,            /**< True if ordered and operands are unequal */
00339   LLVMRealORD,            /**< True if ordered (no nans) */
00340   LLVMRealUNO,            /**< True if unordered: isnan(X) | isnan(Y) */
00341   LLVMRealUEQ,            /**< True if unordered or equal */
00342   LLVMRealUGT,            /**< True if unordered or greater than */
00343   LLVMRealUGE,            /**< True if unordered, greater than, or equal */
00344   LLVMRealULT,            /**< True if unordered or less than */
00345   LLVMRealULE,            /**< True if unordered, less than, or equal */
00346   LLVMRealUNE,            /**< True if unordered or not equal */
00347   LLVMRealPredicateTrue   /**< Always true (always folded) */
00348 } LLVMRealPredicate;
00349 
00350 typedef enum {
00351   LLVMLandingPadCatch,    /**< A catch clause   */
00352   LLVMLandingPadFilter    /**< A filter clause  */
00353 } LLVMLandingPadClauseTy;
00354 
00355 typedef enum {
00356   LLVMNotThreadLocal = 0,
00357   LLVMGeneralDynamicTLSModel,
00358   LLVMLocalDynamicTLSModel,
00359   LLVMInitialExecTLSModel,
00360   LLVMLocalExecTLSModel
00361 } LLVMThreadLocalMode;
00362 
00363 typedef enum {
00364   LLVMAtomicOrderingNotAtomic = 0, /**< A load or store which is not atomic */
00365   LLVMAtomicOrderingUnordered = 1, /**< Lowest level of atomicity, guarantees
00366                                      somewhat sane results, lock free. */
00367   LLVMAtomicOrderingMonotonic = 2, /**< guarantees that if you take all the
00368                                      operations affecting a specific address,
00369                                      a consistent ordering exists */
00370   LLVMAtomicOrderingAcquire = 4, /**< Acquire provides a barrier of the sort
00371                                    necessary to acquire a lock to access other
00372                                    memory with normal loads and stores. */
00373   LLVMAtomicOrderingRelease = 5, /**< Release is similar to Acquire, but with
00374                                    a barrier of the sort necessary to release
00375                                    a lock. */
00376   LLVMAtomicOrderingAcquireRelease = 6, /**< provides both an Acquire and a
00377                                           Release barrier (for fences and
00378                                           operations which both read and write
00379                                            memory). */
00380   LLVMAtomicOrderingSequentiallyConsistent = 7 /**< provides Acquire semantics
00381                                                  for loads and Release
00382                                                  semantics for stores.
00383                                                  Additionally, it guarantees
00384                                                  that a total ordering exists
00385                                                  between all
00386                                                  SequentiallyConsistent
00387                                                  operations. */
00388 } LLVMAtomicOrdering;
00389 
00390 typedef enum {
00391     LLVMAtomicRMWBinOpXchg, /**< Set the new value and return the one old */
00392     LLVMAtomicRMWBinOpAdd, /**< Add a value and return the old one */
00393     LLVMAtomicRMWBinOpSub, /**< Subtract a value and return the old one */
00394     LLVMAtomicRMWBinOpAnd, /**< And a value and return the old one */
00395     LLVMAtomicRMWBinOpNand, /**< Not-And a value and return the old one */
00396     LLVMAtomicRMWBinOpOr, /**< OR a value and return the old one */
00397     LLVMAtomicRMWBinOpXor, /**< Xor a value and return the old one */
00398     LLVMAtomicRMWBinOpMax, /**< Sets the value if it's greater than the
00399                              original using a signed comparison and return
00400                              the old one */
00401     LLVMAtomicRMWBinOpMin, /**< Sets the value if it's Smaller than the
00402                              original using a signed comparison and return
00403                              the old one */
00404     LLVMAtomicRMWBinOpUMax, /**< Sets the value if it's greater than the
00405                              original using an unsigned comparison and return
00406                              the old one */
00407     LLVMAtomicRMWBinOpUMin /**< Sets the value if it's greater than the
00408                              original using an unsigned comparison  and return
00409                              the old one */
00410 } LLVMAtomicRMWBinOp;
00411 
00412 typedef enum {
00413     LLVMDSError,
00414     LLVMDSWarning,
00415     LLVMDSRemark,
00416     LLVMDSNote
00417 } LLVMDiagnosticSeverity;
00418 
00419 /**
00420  * @}
00421  */
00422 
00423 void LLVMInitializeCore(LLVMPassRegistryRef R);
00424 
00425 /** Deallocate and destroy all ManagedStatic variables.
00426     @see llvm::llvm_shutdown
00427     @see ManagedStatic */
00428 void LLVMShutdown(void);
00429 
00430 
00431 /*===-- Error handling ----------------------------------------------------===*/
00432 
00433 char *LLVMCreateMessage(const char *Message);
00434 void LLVMDisposeMessage(char *Message);
00435 
00436 typedef void (*LLVMFatalErrorHandler)(const char *Reason);
00437 
00438 /**
00439  * Install a fatal error handler. By default, if LLVM detects a fatal error, it
00440  * will call exit(1). This may not be appropriate in many contexts. For example,
00441  * doing exit(1) will bypass many crash reporting/tracing system tools. This
00442  * function allows you to install a callback that will be invoked prior to the
00443  * call to exit(1).
00444  */
00445 void LLVMInstallFatalErrorHandler(LLVMFatalErrorHandler Handler);
00446 
00447 /**
00448  * Reset the fatal error handler. This resets LLVM's fatal error handling
00449  * behavior to the default.
00450  */
00451 void LLVMResetFatalErrorHandler(void);
00452 
00453 /**
00454  * Enable LLVM's built-in stack trace code. This intercepts the OS's crash
00455  * signals and prints which component of LLVM you were in at the time if the
00456  * crash.
00457  */
00458 void LLVMEnablePrettyStackTrace(void);
00459 
00460 /**
00461  * @defgroup LLVMCCoreContext Contexts
00462  *
00463  * Contexts are execution states for the core LLVM IR system.
00464  *
00465  * Most types are tied to a context instance. Multiple contexts can
00466  * exist simultaneously. A single context is not thread safe. However,
00467  * different contexts can execute on different threads simultaneously.
00468  *
00469  * @{
00470  */
00471 
00472 typedef void (*LLVMDiagnosticHandler)(LLVMDiagnosticInfoRef, void *);
00473 typedef void (*LLVMYieldCallback)(LLVMContextRef, void *);
00474 
00475 /**
00476  * Create a new context.
00477  *
00478  * Every call to this function should be paired with a call to
00479  * LLVMContextDispose() or the context will leak memory.
00480  */
00481 LLVMContextRef LLVMContextCreate(void);
00482 
00483 /**
00484  * Obtain the global context instance.
00485  */
00486 LLVMContextRef LLVMGetGlobalContext(void);
00487 
00488 /**
00489  * Set the diagnostic handler for this context.
00490  */
00491 void LLVMContextSetDiagnosticHandler(LLVMContextRef C,
00492                                      LLVMDiagnosticHandler Handler,
00493                                      void *DiagnosticContext);
00494 
00495 /**
00496  * Set the yield callback function for this context.
00497  *
00498  * @see LLVMContext::setYieldCallback()
00499  */
00500 void LLVMContextSetYieldCallback(LLVMContextRef C, LLVMYieldCallback Callback,
00501                                  void *OpaqueHandle);
00502 
00503 /**
00504  * Destroy a context instance.
00505  *
00506  * This should be called for every call to LLVMContextCreate() or memory
00507  * will be leaked.
00508  */
00509 void LLVMContextDispose(LLVMContextRef C);
00510 
00511 /**
00512  * Return a string representation of the DiagnosticInfo. Use
00513  * LLVMDisposeMessage to free the string.
00514  *
00515  * @see DiagnosticInfo::print()
00516  */
00517 char *LLVMGetDiagInfoDescription(LLVMDiagnosticInfoRef DI);
00518 
00519 /**
00520  * Return an enum LLVMDiagnosticSeverity.
00521  *
00522  * @see DiagnosticInfo::getSeverity()
00523  */
00524 LLVMDiagnosticSeverity LLVMGetDiagInfoSeverity(LLVMDiagnosticInfoRef DI);
00525 
00526 unsigned LLVMGetMDKindIDInContext(LLVMContextRef C, const char* Name,
00527                                   unsigned SLen);
00528 unsigned LLVMGetMDKindID(const char* Name, unsigned SLen);
00529 
00530 /**
00531  * @}
00532  */
00533 
00534 /**
00535  * @defgroup LLVMCCoreModule Modules
00536  *
00537  * Modules represent the top-level structure in an LLVM program. An LLVM
00538  * module is effectively a translation unit or a collection of
00539  * translation units merged together.
00540  *
00541  * @{
00542  */
00543 
00544 /**
00545  * Create a new, empty module in the global context.
00546  *
00547  * This is equivalent to calling LLVMModuleCreateWithNameInContext with
00548  * LLVMGetGlobalContext() as the context parameter.
00549  *
00550  * Every invocation should be paired with LLVMDisposeModule() or memory
00551  * will be leaked.
00552  */
00553 LLVMModuleRef LLVMModuleCreateWithName(const char *ModuleID);
00554 
00555 /**
00556  * Create a new, empty module in a specific context.
00557  *
00558  * Every invocation should be paired with LLVMDisposeModule() or memory
00559  * will be leaked.
00560  */
00561 LLVMModuleRef LLVMModuleCreateWithNameInContext(const char *ModuleID,
00562                                                 LLVMContextRef C);
00563 
00564 /**
00565  * Destroy a module instance.
00566  *
00567  * This must be called for every created module or memory will be
00568  * leaked.
00569  */
00570 void LLVMDisposeModule(LLVMModuleRef M);
00571 
00572 /**
00573  * Obtain the data layout for a module.
00574  *
00575  * @see Module::getDataLayout()
00576  */
00577 const char *LLVMGetDataLayout(LLVMModuleRef M);
00578 
00579 /**
00580  * Set the data layout for a module.
00581  *
00582  * @see Module::setDataLayout()
00583  */
00584 void LLVMSetDataLayout(LLVMModuleRef M, const char *Triple);
00585 
00586 /**
00587  * Obtain the target triple for a module.
00588  *
00589  * @see Module::getTargetTriple()
00590  */
00591 const char *LLVMGetTarget(LLVMModuleRef M);
00592 
00593 /**
00594  * Set the target triple for a module.
00595  *
00596  * @see Module::setTargetTriple()
00597  */
00598 void LLVMSetTarget(LLVMModuleRef M, const char *Triple);
00599 
00600 /**
00601  * Dump a representation of a module to stderr.
00602  *
00603  * @see Module::dump()
00604  */
00605 void LLVMDumpModule(LLVMModuleRef M);
00606 
00607 /**
00608  * Print a representation of a module to a file. The ErrorMessage needs to be
00609  * disposed with LLVMDisposeMessage. Returns 0 on success, 1 otherwise.
00610  *
00611  * @see Module::print()
00612  */
00613 LLVMBool LLVMPrintModuleToFile(LLVMModuleRef M, const char *Filename,
00614                                char **ErrorMessage);
00615 
00616 /**
00617  * Return a string representation of the module. Use
00618  * LLVMDisposeMessage to free the string.
00619  *
00620  * @see Module::print()
00621  */
00622 char *LLVMPrintModuleToString(LLVMModuleRef M);
00623 
00624 /**
00625  * Set inline assembly for a module.
00626  *
00627  * @see Module::setModuleInlineAsm()
00628  */
00629 void LLVMSetModuleInlineAsm(LLVMModuleRef M, const char *Asm);
00630 
00631 /**
00632  * Obtain the context to which this module is associated.
00633  *
00634  * @see Module::getContext()
00635  */
00636 LLVMContextRef LLVMGetModuleContext(LLVMModuleRef M);
00637 
00638 /**
00639  * Obtain a Type from a module by its registered name.
00640  */
00641 LLVMTypeRef LLVMGetTypeByName(LLVMModuleRef M, const char *Name);
00642 
00643 /**
00644  * Obtain the number of operands for named metadata in a module.
00645  *
00646  * @see llvm::Module::getNamedMetadata()
00647  */
00648 unsigned LLVMGetNamedMetadataNumOperands(LLVMModuleRef M, const char* name);
00649 
00650 /**
00651  * Obtain the named metadata operands for a module.
00652  *
00653  * The passed LLVMValueRef pointer should refer to an array of
00654  * LLVMValueRef at least LLVMGetNamedMetadataNumOperands long. This
00655  * array will be populated with the LLVMValueRef instances. Each
00656  * instance corresponds to a llvm::MDNode.
00657  *
00658  * @see llvm::Module::getNamedMetadata()
00659  * @see llvm::MDNode::getOperand()
00660  */
00661 void LLVMGetNamedMetadataOperands(LLVMModuleRef M, const char* name, LLVMValueRef *Dest);
00662 
00663 /**
00664  * Add an operand to named metadata.
00665  *
00666  * @see llvm::Module::getNamedMetadata()
00667  * @see llvm::MDNode::addOperand()
00668  */
00669 void LLVMAddNamedMetadataOperand(LLVMModuleRef M, const char* name,
00670                                  LLVMValueRef Val);
00671 
00672 /**
00673  * Add a function to a module under a specified name.
00674  *
00675  * @see llvm::Function::Create()
00676  */
00677 LLVMValueRef LLVMAddFunction(LLVMModuleRef M, const char *Name,
00678                              LLVMTypeRef FunctionTy);
00679 
00680 /**
00681  * Obtain a Function value from a Module by its name.
00682  *
00683  * The returned value corresponds to a llvm::Function value.
00684  *
00685  * @see llvm::Module::getFunction()
00686  */
00687 LLVMValueRef LLVMGetNamedFunction(LLVMModuleRef M, const char *Name);
00688 
00689 /**
00690  * Obtain an iterator to the first Function in a Module.
00691  *
00692  * @see llvm::Module::begin()
00693  */
00694 LLVMValueRef LLVMGetFirstFunction(LLVMModuleRef M);
00695 
00696 /**
00697  * Obtain an iterator to the last Function in a Module.
00698  *
00699  * @see llvm::Module::end()
00700  */
00701 LLVMValueRef LLVMGetLastFunction(LLVMModuleRef M);
00702 
00703 /**
00704  * Advance a Function iterator to the next Function.
00705  *
00706  * Returns NULL if the iterator was already at the end and there are no more
00707  * functions.
00708  */
00709 LLVMValueRef LLVMGetNextFunction(LLVMValueRef Fn);
00710 
00711 /**
00712  * Decrement a Function iterator to the previous Function.
00713  *
00714  * Returns NULL if the iterator was already at the beginning and there are
00715  * no previous functions.
00716  */
00717 LLVMValueRef LLVMGetPreviousFunction(LLVMValueRef Fn);
00718 
00719 /**
00720  * @}
00721  */
00722 
00723 /**
00724  * @defgroup LLVMCCoreType Types
00725  *
00726  * Types represent the type of a value.
00727  *
00728  * Types are associated with a context instance. The context internally
00729  * deduplicates types so there is only 1 instance of a specific type
00730  * alive at a time. In other words, a unique type is shared among all
00731  * consumers within a context.
00732  *
00733  * A Type in the C API corresponds to llvm::Type.
00734  *
00735  * Types have the following hierarchy:
00736  *
00737  *   types:
00738  *     integer type
00739  *     real type
00740  *     function type
00741  *     sequence types:
00742  *       array type
00743  *       pointer type
00744  *       vector type
00745  *     void type
00746  *     label type
00747  *     opaque type
00748  *
00749  * @{
00750  */
00751 
00752 /**
00753  * Obtain the enumerated type of a Type instance.
00754  *
00755  * @see llvm::Type:getTypeID()
00756  */
00757 LLVMTypeKind LLVMGetTypeKind(LLVMTypeRef Ty);
00758 
00759 /**
00760  * Whether the type has a known size.
00761  *
00762  * Things that don't have a size are abstract types, labels, and void.a
00763  *
00764  * @see llvm::Type::isSized()
00765  */
00766 LLVMBool LLVMTypeIsSized(LLVMTypeRef Ty);
00767 
00768 /**
00769  * Obtain the context to which this type instance is associated.
00770  *
00771  * @see llvm::Type::getContext()
00772  */
00773 LLVMContextRef LLVMGetTypeContext(LLVMTypeRef Ty);
00774 
00775 /**
00776  * Dump a representation of a type to stderr.
00777  *
00778  * @see llvm::Type::dump()
00779  */
00780 void LLVMDumpType(LLVMTypeRef Val);
00781 
00782 /**
00783  * Return a string representation of the type. Use
00784  * LLVMDisposeMessage to free the string.
00785  *
00786  * @see llvm::Type::print()
00787  */
00788 char *LLVMPrintTypeToString(LLVMTypeRef Val);
00789 
00790 /**
00791  * @defgroup LLVMCCoreTypeInt Integer Types
00792  *
00793  * Functions in this section operate on integer types.
00794  *
00795  * @{
00796  */
00797 
00798 /**
00799  * Obtain an integer type from a context with specified bit width.
00800  */
00801 LLVMTypeRef LLVMInt1TypeInContext(LLVMContextRef C);
00802 LLVMTypeRef LLVMInt8TypeInContext(LLVMContextRef C);
00803 LLVMTypeRef LLVMInt16TypeInContext(LLVMContextRef C);
00804 LLVMTypeRef LLVMInt32TypeInContext(LLVMContextRef C);
00805 LLVMTypeRef LLVMInt64TypeInContext(LLVMContextRef C);
00806 LLVMTypeRef LLVMIntTypeInContext(LLVMContextRef C, unsigned NumBits);
00807 
00808 /**
00809  * Obtain an integer type from the global context with a specified bit
00810  * width.
00811  */
00812 LLVMTypeRef LLVMInt1Type(void);
00813 LLVMTypeRef LLVMInt8Type(void);
00814 LLVMTypeRef LLVMInt16Type(void);
00815 LLVMTypeRef LLVMInt32Type(void);
00816 LLVMTypeRef LLVMInt64Type(void);
00817 LLVMTypeRef LLVMIntType(unsigned NumBits);
00818 unsigned LLVMGetIntTypeWidth(LLVMTypeRef IntegerTy);
00819 
00820 /**
00821  * @}
00822  */
00823 
00824 /**
00825  * @defgroup LLVMCCoreTypeFloat Floating Point Types
00826  *
00827  * @{
00828  */
00829 
00830 /**
00831  * Obtain a 16-bit floating point type from a context.
00832  */
00833 LLVMTypeRef LLVMHalfTypeInContext(LLVMContextRef C);
00834 
00835 /**
00836  * Obtain a 32-bit floating point type from a context.
00837  */
00838 LLVMTypeRef LLVMFloatTypeInContext(LLVMContextRef C);
00839 
00840 /**
00841  * Obtain a 64-bit floating point type from a context.
00842  */
00843 LLVMTypeRef LLVMDoubleTypeInContext(LLVMContextRef C);
00844 
00845 /**
00846  * Obtain a 80-bit floating point type (X87) from a context.
00847  */
00848 LLVMTypeRef LLVMX86FP80TypeInContext(LLVMContextRef C);
00849 
00850 /**
00851  * Obtain a 128-bit floating point type (112-bit mantissa) from a
00852  * context.
00853  */
00854 LLVMTypeRef LLVMFP128TypeInContext(LLVMContextRef C);
00855 
00856 /**
00857  * Obtain a 128-bit floating point type (two 64-bits) from a context.
00858  */
00859 LLVMTypeRef LLVMPPCFP128TypeInContext(LLVMContextRef C);
00860 
00861 /**
00862  * Obtain a floating point type from the global context.
00863  *
00864  * These map to the functions in this group of the same name.
00865  */
00866 LLVMTypeRef LLVMHalfType(void);
00867 LLVMTypeRef LLVMFloatType(void);
00868 LLVMTypeRef LLVMDoubleType(void);
00869 LLVMTypeRef LLVMX86FP80Type(void);
00870 LLVMTypeRef LLVMFP128Type(void);
00871 LLVMTypeRef LLVMPPCFP128Type(void);
00872 
00873 /**
00874  * @}
00875  */
00876 
00877 /**
00878  * @defgroup LLVMCCoreTypeFunction Function Types
00879  *
00880  * @{
00881  */
00882 
00883 /**
00884  * Obtain a function type consisting of a specified signature.
00885  *
00886  * The function is defined as a tuple of a return Type, a list of
00887  * parameter types, and whether the function is variadic.
00888  */
00889 LLVMTypeRef LLVMFunctionType(LLVMTypeRef ReturnType,
00890                              LLVMTypeRef *ParamTypes, unsigned ParamCount,
00891                              LLVMBool IsVarArg);
00892 
00893 /**
00894  * Returns whether a function type is variadic.
00895  */
00896 LLVMBool LLVMIsFunctionVarArg(LLVMTypeRef FunctionTy);
00897 
00898 /**
00899  * Obtain the Type this function Type returns.
00900  */
00901 LLVMTypeRef LLVMGetReturnType(LLVMTypeRef FunctionTy);
00902 
00903 /**
00904  * Obtain the number of parameters this function accepts.
00905  */
00906 unsigned LLVMCountParamTypes(LLVMTypeRef FunctionTy);
00907 
00908 /**
00909  * Obtain the types of a function's parameters.
00910  *
00911  * The Dest parameter should point to a pre-allocated array of
00912  * LLVMTypeRef at least LLVMCountParamTypes() large. On return, the
00913  * first LLVMCountParamTypes() entries in the array will be populated
00914  * with LLVMTypeRef instances.
00915  *
00916  * @param FunctionTy The function type to operate on.
00917  * @param Dest Memory address of an array to be filled with result.
00918  */
00919 void LLVMGetParamTypes(LLVMTypeRef FunctionTy, LLVMTypeRef *Dest);
00920 
00921 /**
00922  * @}
00923  */
00924 
00925 /**
00926  * @defgroup LLVMCCoreTypeStruct Structure Types
00927  *
00928  * These functions relate to LLVMTypeRef instances.
00929  *
00930  * @see llvm::StructType
00931  *
00932  * @{
00933  */
00934 
00935 /**
00936  * Create a new structure type in a context.
00937  *
00938  * A structure is specified by a list of inner elements/types and
00939  * whether these can be packed together.
00940  *
00941  * @see llvm::StructType::create()
00942  */
00943 LLVMTypeRef LLVMStructTypeInContext(LLVMContextRef C, LLVMTypeRef *ElementTypes,
00944                                     unsigned ElementCount, LLVMBool Packed);
00945 
00946 /**
00947  * Create a new structure type in the global context.
00948  *
00949  * @see llvm::StructType::create()
00950  */
00951 LLVMTypeRef LLVMStructType(LLVMTypeRef *ElementTypes, unsigned ElementCount,
00952                            LLVMBool Packed);
00953 
00954 /**
00955  * Create an empty structure in a context having a specified name.
00956  *
00957  * @see llvm::StructType::create()
00958  */
00959 LLVMTypeRef LLVMStructCreateNamed(LLVMContextRef C, const char *Name);
00960 
00961 /**
00962  * Obtain the name of a structure.
00963  *
00964  * @see llvm::StructType::getName()
00965  */
00966 const char *LLVMGetStructName(LLVMTypeRef Ty);
00967 
00968 /**
00969  * Set the contents of a structure type.
00970  *
00971  * @see llvm::StructType::setBody()
00972  */
00973 void LLVMStructSetBody(LLVMTypeRef StructTy, LLVMTypeRef *ElementTypes,
00974                        unsigned ElementCount, LLVMBool Packed);
00975 
00976 /**
00977  * Get the number of elements defined inside the structure.
00978  *
00979  * @see llvm::StructType::getNumElements()
00980  */
00981 unsigned LLVMCountStructElementTypes(LLVMTypeRef StructTy);
00982 
00983 /**
00984  * Get the elements within a structure.
00985  *
00986  * The function is passed the address of a pre-allocated array of
00987  * LLVMTypeRef at least LLVMCountStructElementTypes() long. After
00988  * invocation, this array will be populated with the structure's
00989  * elements. The objects in the destination array will have a lifetime
00990  * of the structure type itself, which is the lifetime of the context it
00991  * is contained in.
00992  */
00993 void LLVMGetStructElementTypes(LLVMTypeRef StructTy, LLVMTypeRef *Dest);
00994 
00995 /**
00996  * Determine whether a structure is packed.
00997  *
00998  * @see llvm::StructType::isPacked()
00999  */
01000 LLVMBool LLVMIsPackedStruct(LLVMTypeRef StructTy);
01001 
01002 /**
01003  * Determine whether a structure is opaque.
01004  *
01005  * @see llvm::StructType::isOpaque()
01006  */
01007 LLVMBool LLVMIsOpaqueStruct(LLVMTypeRef StructTy);
01008 
01009 /**
01010  * @}
01011  */
01012 
01013 
01014 /**
01015  * @defgroup LLVMCCoreTypeSequential Sequential Types
01016  *
01017  * Sequential types represents "arrays" of types. This is a super class
01018  * for array, vector, and pointer types.
01019  *
01020  * @{
01021  */
01022 
01023 /**
01024  * Obtain the type of elements within a sequential type.
01025  *
01026  * This works on array, vector, and pointer types.
01027  *
01028  * @see llvm::SequentialType::getElementType()
01029  */
01030 LLVMTypeRef LLVMGetElementType(LLVMTypeRef Ty);
01031 
01032 /**
01033  * Create a fixed size array type that refers to a specific type.
01034  *
01035  * The created type will exist in the context that its element type
01036  * exists in.
01037  *
01038  * @see llvm::ArrayType::get()
01039  */
01040 LLVMTypeRef LLVMArrayType(LLVMTypeRef ElementType, unsigned ElementCount);
01041 
01042 /**
01043  * Obtain the length of an array type.
01044  *
01045  * This only works on types that represent arrays.
01046  *
01047  * @see llvm::ArrayType::getNumElements()
01048  */
01049 unsigned LLVMGetArrayLength(LLVMTypeRef ArrayTy);
01050 
01051 /**
01052  * Create a pointer type that points to a defined type.
01053  *
01054  * The created type will exist in the context that its pointee type
01055  * exists in.
01056  *
01057  * @see llvm::PointerType::get()
01058  */
01059 LLVMTypeRef LLVMPointerType(LLVMTypeRef ElementType, unsigned AddressSpace);
01060 
01061 /**
01062  * Obtain the address space of a pointer type.
01063  *
01064  * This only works on types that represent pointers.
01065  *
01066  * @see llvm::PointerType::getAddressSpace()
01067  */
01068 unsigned LLVMGetPointerAddressSpace(LLVMTypeRef PointerTy);
01069 
01070 /**
01071  * Create a vector type that contains a defined type and has a specific
01072  * number of elements.
01073  *
01074  * The created type will exist in the context thats its element type
01075  * exists in.
01076  *
01077  * @see llvm::VectorType::get()
01078  */
01079 LLVMTypeRef LLVMVectorType(LLVMTypeRef ElementType, unsigned ElementCount);
01080 
01081 /**
01082  * Obtain the number of elements in a vector type.
01083  *
01084  * This only works on types that represent vectors.
01085  *
01086  * @see llvm::VectorType::getNumElements()
01087  */
01088 unsigned LLVMGetVectorSize(LLVMTypeRef VectorTy);
01089 
01090 /**
01091  * @}
01092  */
01093 
01094 /**
01095  * @defgroup LLVMCCoreTypeOther Other Types
01096  *
01097  * @{
01098  */
01099 
01100 /**
01101  * Create a void type in a context.
01102  */
01103 LLVMTypeRef LLVMVoidTypeInContext(LLVMContextRef C);
01104 
01105 /**
01106  * Create a label type in a context.
01107  */
01108 LLVMTypeRef LLVMLabelTypeInContext(LLVMContextRef C);
01109 
01110 /**
01111  * Create a X86 MMX type in a context.
01112  */
01113 LLVMTypeRef LLVMX86MMXTypeInContext(LLVMContextRef C);
01114 
01115 /**
01116  * These are similar to the above functions except they operate on the
01117  * global context.
01118  */
01119 LLVMTypeRef LLVMVoidType(void);
01120 LLVMTypeRef LLVMLabelType(void);
01121 LLVMTypeRef LLVMX86MMXType(void);
01122 
01123 /**
01124  * @}
01125  */
01126 
01127 /**
01128  * @}
01129  */
01130 
01131 /**
01132  * @defgroup LLVMCCoreValues Values
01133  *
01134  * The bulk of LLVM's object model consists of values, which comprise a very
01135  * rich type hierarchy.
01136  *
01137  * LLVMValueRef essentially represents llvm::Value. There is a rich
01138  * hierarchy of classes within this type. Depending on the instance
01139  * obtained, not all APIs are available.
01140  *
01141  * Callers can determine the type of an LLVMValueRef by calling the
01142  * LLVMIsA* family of functions (e.g. LLVMIsAArgument()). These
01143  * functions are defined by a macro, so it isn't obvious which are
01144  * available by looking at the Doxygen source code. Instead, look at the
01145  * source definition of LLVM_FOR_EACH_VALUE_SUBCLASS and note the list
01146  * of value names given. These value names also correspond to classes in
01147  * the llvm::Value hierarchy.
01148  *
01149  * @{
01150  */
01151 
01152 #define LLVM_FOR_EACH_VALUE_SUBCLASS(macro) \
01153   macro(Argument)                           \
01154   macro(BasicBlock)                         \
01155   macro(InlineAsm)                          \
01156   macro(MDNode)                             \
01157   macro(MDString)                           \
01158   macro(User)                               \
01159     macro(Constant)                         \
01160       macro(BlockAddress)                   \
01161       macro(ConstantAggregateZero)          \
01162       macro(ConstantArray)                  \
01163       macro(ConstantDataSequential)         \
01164         macro(ConstantDataArray)            \
01165         macro(ConstantDataVector)           \
01166       macro(ConstantExpr)                   \
01167       macro(ConstantFP)                     \
01168       macro(ConstantInt)                    \
01169       macro(ConstantPointerNull)            \
01170       macro(ConstantStruct)                 \
01171       macro(ConstantVector)                 \
01172       macro(GlobalValue)                    \
01173         macro(GlobalAlias)                  \
01174         macro(GlobalObject)                 \
01175           macro(Function)                   \
01176           macro(GlobalVariable)             \
01177       macro(UndefValue)                     \
01178     macro(Instruction)                      \
01179       macro(BinaryOperator)                 \
01180       macro(CallInst)                       \
01181         macro(IntrinsicInst)                \
01182           macro(DbgInfoIntrinsic)           \
01183             macro(DbgDeclareInst)           \
01184           macro(MemIntrinsic)               \
01185             macro(MemCpyInst)               \
01186             macro(MemMoveInst)              \
01187             macro(MemSetInst)               \
01188       macro(CmpInst)                        \
01189         macro(FCmpInst)                     \
01190         macro(ICmpInst)                     \
01191       macro(ExtractElementInst)             \
01192       macro(GetElementPtrInst)              \
01193       macro(InsertElementInst)              \
01194       macro(InsertValueInst)                \
01195       macro(LandingPadInst)                 \
01196       macro(PHINode)                        \
01197       macro(SelectInst)                     \
01198       macro(ShuffleVectorInst)              \
01199       macro(StoreInst)                      \
01200       macro(TerminatorInst)                 \
01201         macro(BranchInst)                   \
01202         macro(IndirectBrInst)               \
01203         macro(InvokeInst)                   \
01204         macro(ReturnInst)                   \
01205         macro(SwitchInst)                   \
01206         macro(UnreachableInst)              \
01207         macro(ResumeInst)                   \
01208       macro(UnaryInstruction)               \
01209         macro(AllocaInst)                   \
01210         macro(CastInst)                     \
01211           macro(AddrSpaceCastInst)          \
01212           macro(BitCastInst)                \
01213           macro(FPExtInst)                  \
01214           macro(FPToSIInst)                 \
01215           macro(FPToUIInst)                 \
01216           macro(FPTruncInst)                \
01217           macro(IntToPtrInst)               \
01218           macro(PtrToIntInst)               \
01219           macro(SExtInst)                   \
01220           macro(SIToFPInst)                 \
01221           macro(TruncInst)                  \
01222           macro(UIToFPInst)                 \
01223           macro(ZExtInst)                   \
01224         macro(ExtractValueInst)             \
01225         macro(LoadInst)                     \
01226         macro(VAArgInst)
01227 
01228 /**
01229  * @defgroup LLVMCCoreValueGeneral General APIs
01230  *
01231  * Functions in this section work on all LLVMValueRef instances,
01232  * regardless of their sub-type. They correspond to functions available
01233  * on llvm::Value.
01234  *
01235  * @{
01236  */
01237 
01238 /**
01239  * Obtain the type of a value.
01240  *
01241  * @see llvm::Value::getType()
01242  */
01243 LLVMTypeRef LLVMTypeOf(LLVMValueRef Val);
01244 
01245 /**
01246  * Obtain the string name of a value.
01247  *
01248  * @see llvm::Value::getName()
01249  */
01250 const char *LLVMGetValueName(LLVMValueRef Val);
01251 
01252 /**
01253  * Set the string name of a value.
01254  *
01255  * @see llvm::Value::setName()
01256  */
01257 void LLVMSetValueName(LLVMValueRef Val, const char *Name);
01258 
01259 /**
01260  * Dump a representation of a value to stderr.
01261  *
01262  * @see llvm::Value::dump()
01263  */
01264 void LLVMDumpValue(LLVMValueRef Val);
01265 
01266 /**
01267  * Return a string representation of the value. Use
01268  * LLVMDisposeMessage to free the string.
01269  *
01270  * @see llvm::Value::print()
01271  */
01272 char *LLVMPrintValueToString(LLVMValueRef Val);
01273 
01274 /**
01275  * Replace all uses of a value with another one.
01276  *
01277  * @see llvm::Value::replaceAllUsesWith()
01278  */
01279 void LLVMReplaceAllUsesWith(LLVMValueRef OldVal, LLVMValueRef NewVal);
01280 
01281 /**
01282  * Determine whether the specified constant instance is constant.
01283  */
01284 LLVMBool LLVMIsConstant(LLVMValueRef Val);
01285 
01286 /**
01287  * Determine whether a value instance is undefined.
01288  */
01289 LLVMBool LLVMIsUndef(LLVMValueRef Val);
01290 
01291 /**
01292  * Convert value instances between types.
01293  *
01294  * Internally, an LLVMValueRef is "pinned" to a specific type. This
01295  * series of functions allows you to cast an instance to a specific
01296  * type.
01297  *
01298  * If the cast is not valid for the specified type, NULL is returned.
01299  *
01300  * @see llvm::dyn_cast_or_null<>
01301  */
01302 #define LLVM_DECLARE_VALUE_CAST(name) \
01303   LLVMValueRef LLVMIsA##name(LLVMValueRef Val);
01304 LLVM_FOR_EACH_VALUE_SUBCLASS(LLVM_DECLARE_VALUE_CAST)
01305 
01306 /**
01307  * @}
01308  */
01309 
01310 /**
01311  * @defgroup LLVMCCoreValueUses Usage
01312  *
01313  * This module defines functions that allow you to inspect the uses of a
01314  * LLVMValueRef.
01315  *
01316  * It is possible to obtain an LLVMUseRef for any LLVMValueRef instance.
01317  * Each LLVMUseRef (which corresponds to a llvm::Use instance) holds a
01318  * llvm::User and llvm::Value.
01319  *
01320  * @{
01321  */
01322 
01323 /**
01324  * Obtain the first use of a value.
01325  *
01326  * Uses are obtained in an iterator fashion. First, call this function
01327  * to obtain a reference to the first use. Then, call LLVMGetNextUse()
01328  * on that instance and all subsequently obtained instances until
01329  * LLVMGetNextUse() returns NULL.
01330  *
01331  * @see llvm::Value::use_begin()
01332  */
01333 LLVMUseRef LLVMGetFirstUse(LLVMValueRef Val);
01334 
01335 /**
01336  * Obtain the next use of a value.
01337  *
01338  * This effectively advances the iterator. It returns NULL if you are on
01339  * the final use and no more are available.
01340  */
01341 LLVMUseRef LLVMGetNextUse(LLVMUseRef U);
01342 
01343 /**
01344  * Obtain the user value for a user.
01345  *
01346  * The returned value corresponds to a llvm::User type.
01347  *
01348  * @see llvm::Use::getUser()
01349  */
01350 LLVMValueRef LLVMGetUser(LLVMUseRef U);
01351 
01352 /**
01353  * Obtain the value this use corresponds to.
01354  *
01355  * @see llvm::Use::get().
01356  */
01357 LLVMValueRef LLVMGetUsedValue(LLVMUseRef U);
01358 
01359 /**
01360  * @}
01361  */
01362 
01363 /**
01364  * @defgroup LLVMCCoreValueUser User value
01365  *
01366  * Function in this group pertain to LLVMValueRef instances that descent
01367  * from llvm::User. This includes constants, instructions, and
01368  * operators.
01369  *
01370  * @{
01371  */
01372 
01373 /**
01374  * Obtain an operand at a specific index in a llvm::User value.
01375  *
01376  * @see llvm::User::getOperand()
01377  */
01378 LLVMValueRef LLVMGetOperand(LLVMValueRef Val, unsigned Index);
01379 
01380 /**
01381  * Obtain the use of an operand at a specific index in a llvm::User value.
01382  *
01383  * @see llvm::User::getOperandUse()
01384  */
01385 LLVMUseRef LLVMGetOperandUse(LLVMValueRef Val, unsigned Index);
01386 
01387 /**
01388  * Set an operand at a specific index in a llvm::User value.
01389  *
01390  * @see llvm::User::setOperand()
01391  */
01392 void LLVMSetOperand(LLVMValueRef User, unsigned Index, LLVMValueRef Val);
01393 
01394 /**
01395  * Obtain the number of operands in a llvm::User value.
01396  *
01397  * @see llvm::User::getNumOperands()
01398  */
01399 int LLVMGetNumOperands(LLVMValueRef Val);
01400 
01401 /**
01402  * @}
01403  */
01404 
01405 /**
01406  * @defgroup LLVMCCoreValueConstant Constants
01407  *
01408  * This section contains APIs for interacting with LLVMValueRef that
01409  * correspond to llvm::Constant instances.
01410  *
01411  * These functions will work for any LLVMValueRef in the llvm::Constant
01412  * class hierarchy.
01413  *
01414  * @{
01415  */
01416 
01417 /**
01418  * Obtain a constant value referring to the null instance of a type.
01419  *
01420  * @see llvm::Constant::getNullValue()
01421  */
01422 LLVMValueRef LLVMConstNull(LLVMTypeRef Ty); /* all zeroes */
01423 
01424 /**
01425  * Obtain a constant value referring to the instance of a type
01426  * consisting of all ones.
01427  *
01428  * This is only valid for integer types.
01429  *
01430  * @see llvm::Constant::getAllOnesValue()
01431  */
01432 LLVMValueRef LLVMConstAllOnes(LLVMTypeRef Ty);
01433 
01434 /**
01435  * Obtain a constant value referring to an undefined value of a type.
01436  *
01437  * @see llvm::UndefValue::get()
01438  */
01439 LLVMValueRef LLVMGetUndef(LLVMTypeRef Ty);
01440 
01441 /**
01442  * Determine whether a value instance is null.
01443  *
01444  * @see llvm::Constant::isNullValue()
01445  */
01446 LLVMBool LLVMIsNull(LLVMValueRef Val);
01447 
01448 /**
01449  * Obtain a constant that is a constant pointer pointing to NULL for a
01450  * specified type.
01451  */
01452 LLVMValueRef LLVMConstPointerNull(LLVMTypeRef Ty);
01453 
01454 /**
01455  * @defgroup LLVMCCoreValueConstantScalar Scalar constants
01456  *
01457  * Functions in this group model LLVMValueRef instances that correspond
01458  * to constants referring to scalar types.
01459  *
01460  * For integer types, the LLVMTypeRef parameter should correspond to a
01461  * llvm::IntegerType instance and the returned LLVMValueRef will
01462  * correspond to a llvm::ConstantInt.
01463  *
01464  * For floating point types, the LLVMTypeRef returned corresponds to a
01465  * llvm::ConstantFP.
01466  *
01467  * @{
01468  */
01469 
01470 /**
01471  * Obtain a constant value for an integer type.
01472  *
01473  * The returned value corresponds to a llvm::ConstantInt.
01474  *
01475  * @see llvm::ConstantInt::get()
01476  *
01477  * @param IntTy Integer type to obtain value of.
01478  * @param N The value the returned instance should refer to.
01479  * @param SignExtend Whether to sign extend the produced value.
01480  */
01481 LLVMValueRef LLVMConstInt(LLVMTypeRef IntTy, unsigned long long N,
01482                           LLVMBool SignExtend);
01483 
01484 /**
01485  * Obtain a constant value for an integer of arbitrary precision.
01486  *
01487  * @see llvm::ConstantInt::get()
01488  */
01489 LLVMValueRef LLVMConstIntOfArbitraryPrecision(LLVMTypeRef IntTy,
01490                                               unsigned NumWords,
01491                                               const uint64_t Words[]);
01492 
01493 /**
01494  * Obtain a constant value for an integer parsed from a string.
01495  *
01496  * A similar API, LLVMConstIntOfStringAndSize is also available. If the
01497  * string's length is available, it is preferred to call that function
01498  * instead.
01499  *
01500  * @see llvm::ConstantInt::get()
01501  */
01502 LLVMValueRef LLVMConstIntOfString(LLVMTypeRef IntTy, const char *Text,
01503                                   uint8_t Radix);
01504 
01505 /**
01506  * Obtain a constant value for an integer parsed from a string with
01507  * specified length.
01508  *
01509  * @see llvm::ConstantInt::get()
01510  */
01511 LLVMValueRef LLVMConstIntOfStringAndSize(LLVMTypeRef IntTy, const char *Text,
01512                                          unsigned SLen, uint8_t Radix);
01513 
01514 /**
01515  * Obtain a constant value referring to a double floating point value.
01516  */
01517 LLVMValueRef LLVMConstReal(LLVMTypeRef RealTy, double N);
01518 
01519 /**
01520  * Obtain a constant for a floating point value parsed from a string.
01521  *
01522  * A similar API, LLVMConstRealOfStringAndSize is also available. It
01523  * should be used if the input string's length is known.
01524  */
01525 LLVMValueRef LLVMConstRealOfString(LLVMTypeRef RealTy, const char *Text);
01526 
01527 /**
01528  * Obtain a constant for a floating point value parsed from a string.
01529  */
01530 LLVMValueRef LLVMConstRealOfStringAndSize(LLVMTypeRef RealTy, const char *Text,
01531                                           unsigned SLen);
01532 
01533 /**
01534  * Obtain the zero extended value for an integer constant value.
01535  *
01536  * @see llvm::ConstantInt::getZExtValue()
01537  */
01538 unsigned long long LLVMConstIntGetZExtValue(LLVMValueRef ConstantVal);
01539 
01540 /**
01541  * Obtain the sign extended value for an integer constant value.
01542  *
01543  * @see llvm::ConstantInt::getSExtValue()
01544  */
01545 long long LLVMConstIntGetSExtValue(LLVMValueRef ConstantVal);
01546 
01547 /**
01548  * @}
01549  */
01550 
01551 /**
01552  * @defgroup LLVMCCoreValueConstantComposite Composite Constants
01553  *
01554  * Functions in this group operate on composite constants.
01555  *
01556  * @{
01557  */
01558 
01559 /**
01560  * Create a ConstantDataSequential and initialize it with a string.
01561  *
01562  * @see llvm::ConstantDataArray::getString()
01563  */
01564 LLVMValueRef LLVMConstStringInContext(LLVMContextRef C, const char *Str,
01565                                       unsigned Length, LLVMBool DontNullTerminate);
01566 
01567 /**
01568  * Create a ConstantDataSequential with string content in the global context.
01569  *
01570  * This is the same as LLVMConstStringInContext except it operates on the
01571  * global context.
01572  *
01573  * @see LLVMConstStringInContext()
01574  * @see llvm::ConstantDataArray::getString()
01575  */
01576 LLVMValueRef LLVMConstString(const char *Str, unsigned Length,
01577                              LLVMBool DontNullTerminate);
01578 
01579 /**
01580  * Returns true if the specified constant is an array of i8.
01581  *
01582  * @see ConstantDataSequential::getAsString()
01583  */
01584 LLVMBool LLVMIsConstantString(LLVMValueRef c);
01585 
01586 /**
01587  * Get the given constant data sequential as a string.
01588  *
01589  * @see ConstantDataSequential::getAsString()
01590  */
01591 const char *LLVMGetAsString(LLVMValueRef c, size_t* out);
01592 
01593 /**
01594  * Create an anonymous ConstantStruct with the specified values.
01595  *
01596  * @see llvm::ConstantStruct::getAnon()
01597  */
01598 LLVMValueRef LLVMConstStructInContext(LLVMContextRef C,
01599                                       LLVMValueRef *ConstantVals,
01600                                       unsigned Count, LLVMBool Packed);
01601 
01602 /**
01603  * Create a ConstantStruct in the global Context.
01604  *
01605  * This is the same as LLVMConstStructInContext except it operates on the
01606  * global Context.
01607  *
01608  * @see LLVMConstStructInContext()
01609  */
01610 LLVMValueRef LLVMConstStruct(LLVMValueRef *ConstantVals, unsigned Count,
01611                              LLVMBool Packed);
01612 
01613 /**
01614  * Create a ConstantArray from values.
01615  *
01616  * @see llvm::ConstantArray::get()
01617  */
01618 LLVMValueRef LLVMConstArray(LLVMTypeRef ElementTy,
01619                             LLVMValueRef *ConstantVals, unsigned Length);
01620 
01621 /**
01622  * Create a non-anonymous ConstantStruct from values.
01623  *
01624  * @see llvm::ConstantStruct::get()
01625  */
01626 LLVMValueRef LLVMConstNamedStruct(LLVMTypeRef StructTy,
01627                                   LLVMValueRef *ConstantVals,
01628                                   unsigned Count);
01629 
01630 /**
01631  * Get an element at specified index as a constant.
01632  *
01633  * @see ConstantDataSequential::getElementAsConstant()
01634  */
01635 LLVMValueRef LLVMGetElementAsConstant(LLVMValueRef c, unsigned idx);
01636 
01637 /**
01638  * Create a ConstantVector from values.
01639  *
01640  * @see llvm::ConstantVector::get()
01641  */
01642 LLVMValueRef LLVMConstVector(LLVMValueRef *ScalarConstantVals, unsigned Size);
01643 
01644 /**
01645  * @}
01646  */
01647 
01648 /**
01649  * @defgroup LLVMCCoreValueConstantExpressions Constant Expressions
01650  *
01651  * Functions in this group correspond to APIs on llvm::ConstantExpr.
01652  *
01653  * @see llvm::ConstantExpr.
01654  *
01655  * @{
01656  */
01657 LLVMOpcode LLVMGetConstOpcode(LLVMValueRef ConstantVal);
01658 LLVMValueRef LLVMAlignOf(LLVMTypeRef Ty);
01659 LLVMValueRef LLVMSizeOf(LLVMTypeRef Ty);
01660 LLVMValueRef LLVMConstNeg(LLVMValueRef ConstantVal);
01661 LLVMValueRef LLVMConstNSWNeg(LLVMValueRef ConstantVal);
01662 LLVMValueRef LLVMConstNUWNeg(LLVMValueRef ConstantVal);
01663 LLVMValueRef LLVMConstFNeg(LLVMValueRef ConstantVal);
01664 LLVMValueRef LLVMConstNot(LLVMValueRef ConstantVal);
01665 LLVMValueRef LLVMConstAdd(LLVMValueRef LHSConstant, LLVMValueRef RHSConstant);
01666 LLVMValueRef LLVMConstNSWAdd(LLVMValueRef LHSConstant, LLVMValueRef RHSConstant);
01667 LLVMValueRef LLVMConstNUWAdd(LLVMValueRef LHSConstant, LLVMValueRef RHSConstant);
01668 LLVMValueRef LLVMConstFAdd(LLVMValueRef LHSConstant, LLVMValueRef RHSConstant);
01669 LLVMValueRef LLVMConstSub(LLVMValueRef LHSConstant, LLVMValueRef RHSConstant);
01670 LLVMValueRef LLVMConstNSWSub(LLVMValueRef LHSConstant, LLVMValueRef RHSConstant);
01671 LLVMValueRef LLVMConstNUWSub(LLVMValueRef LHSConstant, LLVMValueRef RHSConstant);
01672 LLVMValueRef LLVMConstFSub(LLVMValueRef LHSConstant, LLVMValueRef RHSConstant);
01673 LLVMValueRef LLVMConstMul(LLVMValueRef LHSConstant, LLVMValueRef RHSConstant);
01674 LLVMValueRef LLVMConstNSWMul(LLVMValueRef LHSConstant, LLVMValueRef RHSConstant);
01675 LLVMValueRef LLVMConstNUWMul(LLVMValueRef LHSConstant, LLVMValueRef RHSConstant);
01676 LLVMValueRef LLVMConstFMul(LLVMValueRef LHSConstant, LLVMValueRef RHSConstant);
01677 LLVMValueRef LLVMConstUDiv(LLVMValueRef LHSConstant, LLVMValueRef RHSConstant);
01678 LLVMValueRef LLVMConstSDiv(LLVMValueRef LHSConstant, LLVMValueRef RHSConstant);
01679 LLVMValueRef LLVMConstExactSDiv(LLVMValueRef LHSConstant, LLVMValueRef RHSConstant);
01680 LLVMValueRef LLVMConstFDiv(LLVMValueRef LHSConstant, LLVMValueRef RHSConstant);
01681 LLVMValueRef LLVMConstURem(LLVMValueRef LHSConstant, LLVMValueRef RHSConstant);
01682 LLVMValueRef LLVMConstSRem(LLVMValueRef LHSConstant, LLVMValueRef RHSConstant);
01683 LLVMValueRef LLVMConstFRem(LLVMValueRef LHSConstant, LLVMValueRef RHSConstant);
01684 LLVMValueRef LLVMConstAnd(LLVMValueRef LHSConstant, LLVMValueRef RHSConstant);
01685 LLVMValueRef LLVMConstOr(LLVMValueRef LHSConstant, LLVMValueRef RHSConstant);
01686 LLVMValueRef LLVMConstXor(LLVMValueRef LHSConstant, LLVMValueRef RHSConstant);
01687 LLVMValueRef LLVMConstICmp(LLVMIntPredicate Predicate,
01688                            LLVMValueRef LHSConstant, LLVMValueRef RHSConstant);
01689 LLVMValueRef LLVMConstFCmp(LLVMRealPredicate Predicate,
01690                            LLVMValueRef LHSConstant, LLVMValueRef RHSConstant);
01691 LLVMValueRef LLVMConstShl(LLVMValueRef LHSConstant, LLVMValueRef RHSConstant);
01692 LLVMValueRef LLVMConstLShr(LLVMValueRef LHSConstant, LLVMValueRef RHSConstant);
01693 LLVMValueRef LLVMConstAShr(LLVMValueRef LHSConstant, LLVMValueRef RHSConstant);
01694 LLVMValueRef LLVMConstGEP(LLVMValueRef ConstantVal,
01695                           LLVMValueRef *ConstantIndices, unsigned NumIndices);
01696 LLVMValueRef LLVMConstInBoundsGEP(LLVMValueRef ConstantVal,
01697                                   LLVMValueRef *ConstantIndices,
01698                                   unsigned NumIndices);
01699 LLVMValueRef LLVMConstTrunc(LLVMValueRef ConstantVal, LLVMTypeRef ToType);
01700 LLVMValueRef LLVMConstSExt(LLVMValueRef ConstantVal, LLVMTypeRef ToType);
01701 LLVMValueRef LLVMConstZExt(LLVMValueRef ConstantVal, LLVMTypeRef ToType);
01702 LLVMValueRef LLVMConstFPTrunc(LLVMValueRef ConstantVal, LLVMTypeRef ToType);
01703 LLVMValueRef LLVMConstFPExt(LLVMValueRef ConstantVal, LLVMTypeRef ToType);
01704 LLVMValueRef LLVMConstUIToFP(LLVMValueRef ConstantVal, LLVMTypeRef ToType);
01705 LLVMValueRef LLVMConstSIToFP(LLVMValueRef ConstantVal, LLVMTypeRef ToType);
01706 LLVMValueRef LLVMConstFPToUI(LLVMValueRef ConstantVal, LLVMTypeRef ToType);
01707 LLVMValueRef LLVMConstFPToSI(LLVMValueRef ConstantVal, LLVMTypeRef ToType);
01708 LLVMValueRef LLVMConstPtrToInt(LLVMValueRef ConstantVal, LLVMTypeRef ToType);
01709 LLVMValueRef LLVMConstIntToPtr(LLVMValueRef ConstantVal, LLVMTypeRef ToType);
01710 LLVMValueRef LLVMConstBitCast(LLVMValueRef ConstantVal, LLVMTypeRef ToType);
01711 LLVMValueRef LLVMConstAddrSpaceCast(LLVMValueRef ConstantVal, LLVMTypeRef ToType);
01712 LLVMValueRef LLVMConstZExtOrBitCast(LLVMValueRef ConstantVal,
01713                                     LLVMTypeRef ToType);
01714 LLVMValueRef LLVMConstSExtOrBitCast(LLVMValueRef ConstantVal,
01715                                     LLVMTypeRef ToType);
01716 LLVMValueRef LLVMConstTruncOrBitCast(LLVMValueRef ConstantVal,
01717                                      LLVMTypeRef ToType);
01718 LLVMValueRef LLVMConstPointerCast(LLVMValueRef ConstantVal,
01719                                   LLVMTypeRef ToType);
01720 LLVMValueRef LLVMConstIntCast(LLVMValueRef ConstantVal, LLVMTypeRef ToType,
01721                               LLVMBool isSigned);
01722 LLVMValueRef LLVMConstFPCast(LLVMValueRef ConstantVal, LLVMTypeRef ToType);
01723 LLVMValueRef LLVMConstSelect(LLVMValueRef ConstantCondition,
01724                              LLVMValueRef ConstantIfTrue,
01725                              LLVMValueRef ConstantIfFalse);
01726 LLVMValueRef LLVMConstExtractElement(LLVMValueRef VectorConstant,
01727                                      LLVMValueRef IndexConstant);
01728 LLVMValueRef LLVMConstInsertElement(LLVMValueRef VectorConstant,
01729                                     LLVMValueRef ElementValueConstant,
01730                                     LLVMValueRef IndexConstant);
01731 LLVMValueRef LLVMConstShuffleVector(LLVMValueRef VectorAConstant,
01732                                     LLVMValueRef VectorBConstant,
01733                                     LLVMValueRef MaskConstant);
01734 LLVMValueRef LLVMConstExtractValue(LLVMValueRef AggConstant, unsigned *IdxList,
01735                                    unsigned NumIdx);
01736 LLVMValueRef LLVMConstInsertValue(LLVMValueRef AggConstant,
01737                                   LLVMValueRef ElementValueConstant,
01738                                   unsigned *IdxList, unsigned NumIdx);
01739 LLVMValueRef LLVMConstInlineAsm(LLVMTypeRef Ty,
01740                                 const char *AsmString, const char *Constraints,
01741                                 LLVMBool HasSideEffects, LLVMBool IsAlignStack);
01742 LLVMValueRef LLVMBlockAddress(LLVMValueRef F, LLVMBasicBlockRef BB);
01743 
01744 /**
01745  * @}
01746  */
01747 
01748 /**
01749  * @defgroup LLVMCCoreValueConstantGlobals Global Values
01750  *
01751  * This group contains functions that operate on global values. Functions in
01752  * this group relate to functions in the llvm::GlobalValue class tree.
01753  *
01754  * @see llvm::GlobalValue
01755  *
01756  * @{
01757  */
01758 
01759 LLVMModuleRef LLVMGetGlobalParent(LLVMValueRef Global);
01760 LLVMBool LLVMIsDeclaration(LLVMValueRef Global);
01761 LLVMLinkage LLVMGetLinkage(LLVMValueRef Global);
01762 void LLVMSetLinkage(LLVMValueRef Global, LLVMLinkage Linkage);
01763 const char *LLVMGetSection(LLVMValueRef Global);
01764 void LLVMSetSection(LLVMValueRef Global, const char *Section);
01765 LLVMVisibility LLVMGetVisibility(LLVMValueRef Global);
01766 void LLVMSetVisibility(LLVMValueRef Global, LLVMVisibility Viz);
01767 LLVMDLLStorageClass LLVMGetDLLStorageClass(LLVMValueRef Global);
01768 void LLVMSetDLLStorageClass(LLVMValueRef Global, LLVMDLLStorageClass Class);
01769 LLVMBool LLVMHasUnnamedAddr(LLVMValueRef Global);
01770 void LLVMSetUnnamedAddr(LLVMValueRef Global, LLVMBool HasUnnamedAddr);
01771 
01772 /**
01773  * @defgroup LLVMCCoreValueWithAlignment Values with alignment
01774  *
01775  * Functions in this group only apply to values with alignment, i.e.
01776  * global variables, load and store instructions.
01777  */
01778 
01779 /**
01780  * Obtain the preferred alignment of the value.
01781  * @see llvm::AllocaInst::getAlignment()
01782  * @see llvm::LoadInst::getAlignment()
01783  * @see llvm::StoreInst::getAlignment()
01784  * @see llvm::GlobalValue::getAlignment()
01785  */
01786 unsigned LLVMGetAlignment(LLVMValueRef V);
01787 
01788 /**
01789  * Set the preferred alignment of the value.
01790  * @see llvm::AllocaInst::setAlignment()
01791  * @see llvm::LoadInst::setAlignment()
01792  * @see llvm::StoreInst::setAlignment()
01793  * @see llvm::GlobalValue::setAlignment()
01794  */
01795 void LLVMSetAlignment(LLVMValueRef V, unsigned Bytes);
01796 
01797 /**
01798   * @}
01799   */
01800 
01801 /**
01802  * @defgroup LLVMCoreValueConstantGlobalVariable Global Variables
01803  *
01804  * This group contains functions that operate on global variable values.
01805  *
01806  * @see llvm::GlobalVariable
01807  *
01808  * @{
01809  */
01810 LLVMValueRef LLVMAddGlobal(LLVMModuleRef M, LLVMTypeRef Ty, const char *Name);
01811 LLVMValueRef LLVMAddGlobalInAddressSpace(LLVMModuleRef M, LLVMTypeRef Ty,
01812                                          const char *Name,
01813                                          unsigned AddressSpace);
01814 LLVMValueRef LLVMGetNamedGlobal(LLVMModuleRef M, const char *Name);
01815 LLVMValueRef LLVMGetFirstGlobal(LLVMModuleRef M);
01816 LLVMValueRef LLVMGetLastGlobal(LLVMModuleRef M);
01817 LLVMValueRef LLVMGetNextGlobal(LLVMValueRef GlobalVar);
01818 LLVMValueRef LLVMGetPreviousGlobal(LLVMValueRef GlobalVar);
01819 void LLVMDeleteGlobal(LLVMValueRef GlobalVar);
01820 LLVMValueRef LLVMGetInitializer(LLVMValueRef GlobalVar);
01821 void LLVMSetInitializer(LLVMValueRef GlobalVar, LLVMValueRef ConstantVal);
01822 LLVMBool LLVMIsThreadLocal(LLVMValueRef GlobalVar);
01823 void LLVMSetThreadLocal(LLVMValueRef GlobalVar, LLVMBool IsThreadLocal);
01824 LLVMBool LLVMIsGlobalConstant(LLVMValueRef GlobalVar);
01825 void LLVMSetGlobalConstant(LLVMValueRef GlobalVar, LLVMBool IsConstant);
01826 LLVMThreadLocalMode LLVMGetThreadLocalMode(LLVMValueRef GlobalVar);
01827 void LLVMSetThreadLocalMode(LLVMValueRef GlobalVar, LLVMThreadLocalMode Mode);
01828 LLVMBool LLVMIsExternallyInitialized(LLVMValueRef GlobalVar);
01829 void LLVMSetExternallyInitialized(LLVMValueRef GlobalVar, LLVMBool IsExtInit);
01830 
01831 /**
01832  * @}
01833  */
01834 
01835 /**
01836  * @defgroup LLVMCoreValueConstantGlobalAlias Global Aliases
01837  *
01838  * This group contains function that operate on global alias values.
01839  *
01840  * @see llvm::GlobalAlias
01841  *
01842  * @{
01843  */
01844 LLVMValueRef LLVMAddAlias(LLVMModuleRef M, LLVMTypeRef Ty, LLVMValueRef Aliasee,
01845                           const char *Name);
01846 
01847 /**
01848  * @}
01849  */
01850 
01851 /**
01852  * @defgroup LLVMCCoreValueFunction Function values
01853  *
01854  * Functions in this group operate on LLVMValueRef instances that
01855  * correspond to llvm::Function instances.
01856  *
01857  * @see llvm::Function
01858  *
01859  * @{
01860  */
01861 
01862 /**
01863  * Remove a function from its containing module and deletes it.
01864  *
01865  * @see llvm::Function::eraseFromParent()
01866  */
01867 void LLVMDeleteFunction(LLVMValueRef Fn);
01868 
01869 /**
01870  * Obtain the ID number from a function instance.
01871  *
01872  * @see llvm::Function::getIntrinsicID()
01873  */
01874 unsigned LLVMGetIntrinsicID(LLVMValueRef Fn);
01875 
01876 /**
01877  * Obtain the calling function of a function.
01878  *
01879  * The returned value corresponds to the LLVMCallConv enumeration.
01880  *
01881  * @see llvm::Function::getCallingConv()
01882  */
01883 unsigned LLVMGetFunctionCallConv(LLVMValueRef Fn);
01884 
01885 /**
01886  * Set the calling convention of a function.
01887  *
01888  * @see llvm::Function::setCallingConv()
01889  *
01890  * @param Fn Function to operate on
01891  * @param CC LLVMCallConv to set calling convention to
01892  */
01893 void LLVMSetFunctionCallConv(LLVMValueRef Fn, unsigned CC);
01894 
01895 /**
01896  * Obtain the name of the garbage collector to use during code
01897  * generation.
01898  *
01899  * @see llvm::Function::getGC()
01900  */
01901 const char *LLVMGetGC(LLVMValueRef Fn);
01902 
01903 /**
01904  * Define the garbage collector to use during code generation.
01905  *
01906  * @see llvm::Function::setGC()
01907  */
01908 void LLVMSetGC(LLVMValueRef Fn, const char *Name);
01909 
01910 /**
01911  * Add an attribute to a function.
01912  *
01913  * @see llvm::Function::addAttribute()
01914  */
01915 void LLVMAddFunctionAttr(LLVMValueRef Fn, LLVMAttribute PA);
01916 
01917 /**
01918  * Add a target-dependent attribute to a fuction
01919  * @see llvm::AttrBuilder::addAttribute()
01920  */
01921 void LLVMAddTargetDependentFunctionAttr(LLVMValueRef Fn, const char *A,
01922                                         const char *V);
01923 
01924 /**
01925  * Obtain an attribute from a function.
01926  *
01927  * @see llvm::Function::getAttributes()
01928  */
01929 LLVMAttribute LLVMGetFunctionAttr(LLVMValueRef Fn);
01930 
01931 /**
01932  * Remove an attribute from a function.
01933  */
01934 void LLVMRemoveFunctionAttr(LLVMValueRef Fn, LLVMAttribute PA);
01935 
01936 /**
01937  * @defgroup LLVMCCoreValueFunctionParameters Function Parameters
01938  *
01939  * Functions in this group relate to arguments/parameters on functions.
01940  *
01941  * Functions in this group expect LLVMValueRef instances that correspond
01942  * to llvm::Function instances.
01943  *
01944  * @{
01945  */
01946 
01947 /**
01948  * Obtain the number of parameters in a function.
01949  *
01950  * @see llvm::Function::arg_size()
01951  */
01952 unsigned LLVMCountParams(LLVMValueRef Fn);
01953 
01954 /**
01955  * Obtain the parameters in a function.
01956  *
01957  * The takes a pointer to a pre-allocated array of LLVMValueRef that is
01958  * at least LLVMCountParams() long. This array will be filled with
01959  * LLVMValueRef instances which correspond to the parameters the
01960  * function receives. Each LLVMValueRef corresponds to a llvm::Argument
01961  * instance.
01962  *
01963  * @see llvm::Function::arg_begin()
01964  */
01965 void LLVMGetParams(LLVMValueRef Fn, LLVMValueRef *Params);
01966 
01967 /**
01968  * Obtain the parameter at the specified index.
01969  *
01970  * Parameters are indexed from 0.
01971  *
01972  * @see llvm::Function::arg_begin()
01973  */
01974 LLVMValueRef LLVMGetParam(LLVMValueRef Fn, unsigned Index);
01975 
01976 /**
01977  * Obtain the function to which this argument belongs.
01978  *
01979  * Unlike other functions in this group, this one takes an LLVMValueRef
01980  * that corresponds to a llvm::Attribute.
01981  *
01982  * The returned LLVMValueRef is the llvm::Function to which this
01983  * argument belongs.
01984  */
01985 LLVMValueRef LLVMGetParamParent(LLVMValueRef Inst);
01986 
01987 /**
01988  * Obtain the first parameter to a function.
01989  *
01990  * @see llvm::Function::arg_begin()
01991  */
01992 LLVMValueRef LLVMGetFirstParam(LLVMValueRef Fn);
01993 
01994 /**
01995  * Obtain the last parameter to a function.
01996  *
01997  * @see llvm::Function::arg_end()
01998  */
01999 LLVMValueRef LLVMGetLastParam(LLVMValueRef Fn);
02000 
02001 /**
02002  * Obtain the next parameter to a function.
02003  *
02004  * This takes an LLVMValueRef obtained from LLVMGetFirstParam() (which is
02005  * actually a wrapped iterator) and obtains the next parameter from the
02006  * underlying iterator.
02007  */
02008 LLVMValueRef LLVMGetNextParam(LLVMValueRef Arg);
02009 
02010 /**
02011  * Obtain the previous parameter to a function.
02012  *
02013  * This is the opposite of LLVMGetNextParam().
02014  */
02015 LLVMValueRef LLVMGetPreviousParam(LLVMValueRef Arg);
02016 
02017 /**
02018  * Add an attribute to a function argument.
02019  *
02020  * @see llvm::Argument::addAttr()
02021  */
02022 void LLVMAddAttribute(LLVMValueRef Arg, LLVMAttribute PA);
02023 
02024 /**
02025  * Remove an attribute from a function argument.
02026  *
02027  * @see llvm::Argument::removeAttr()
02028  */
02029 void LLVMRemoveAttribute(LLVMValueRef Arg, LLVMAttribute PA);
02030 
02031 /**
02032  * Get an attribute from a function argument.
02033  */
02034 LLVMAttribute LLVMGetAttribute(LLVMValueRef Arg);
02035 
02036 /**
02037  * Set the alignment for a function parameter.
02038  *
02039  * @see llvm::Argument::addAttr()
02040  * @see llvm::AttrBuilder::addAlignmentAttr()
02041  */
02042 void LLVMSetParamAlignment(LLVMValueRef Arg, unsigned align);
02043 
02044 /**
02045  * @}
02046  */
02047 
02048 /**
02049  * @}
02050  */
02051 
02052 /**
02053  * @}
02054  */
02055 
02056 /**
02057  * @}
02058  */
02059 
02060 /**
02061  * @defgroup LLVMCCoreValueMetadata Metadata
02062  *
02063  * @{
02064  */
02065 
02066 /**
02067  * Obtain a MDString value from a context.
02068  *
02069  * The returned instance corresponds to the llvm::MDString class.
02070  *
02071  * The instance is specified by string data of a specified length. The
02072  * string content is copied, so the backing memory can be freed after
02073  * this function returns.
02074  */
02075 LLVMValueRef LLVMMDStringInContext(LLVMContextRef C, const char *Str,
02076                                    unsigned SLen);
02077 
02078 /**
02079  * Obtain a MDString value from the global context.
02080  */
02081 LLVMValueRef LLVMMDString(const char *Str, unsigned SLen);
02082 
02083 /**
02084  * Obtain a MDNode value from a context.
02085  *
02086  * The returned value corresponds to the llvm::MDNode class.
02087  */
02088 LLVMValueRef LLVMMDNodeInContext(LLVMContextRef C, LLVMValueRef *Vals,
02089                                  unsigned Count);
02090 
02091 /**
02092  * Obtain a MDNode value from the global context.
02093  */
02094 LLVMValueRef LLVMMDNode(LLVMValueRef *Vals, unsigned Count);
02095 
02096 /**
02097  * Obtain the underlying string from a MDString value.
02098  *
02099  * @param V Instance to obtain string from.
02100  * @param Len Memory address which will hold length of returned string.
02101  * @return String data in MDString.
02102  */
02103 const char  *LLVMGetMDString(LLVMValueRef V, unsigned* Len);
02104 
02105 /**
02106  * Obtain the number of operands from an MDNode value.
02107  *
02108  * @param V MDNode to get number of operands from.
02109  * @return Number of operands of the MDNode.
02110  */
02111 unsigned LLVMGetMDNodeNumOperands(LLVMValueRef V);
02112 
02113 /**
02114  * Obtain the given MDNode's operands.
02115  *
02116  * The passed LLVMValueRef pointer should point to enough memory to hold all of
02117  * the operands of the given MDNode (see LLVMGetMDNodeNumOperands) as
02118  * LLVMValueRefs. This memory will be populated with the LLVMValueRefs of the
02119  * MDNode's operands.
02120  *
02121  * @param V MDNode to get the operands from.
02122  * @param Dest Destination array for operands.
02123  */
02124 void LLVMGetMDNodeOperands(LLVMValueRef V, LLVMValueRef *Dest);
02125 
02126 /**
02127  * @}
02128  */
02129 
02130 /**
02131  * @defgroup LLVMCCoreValueBasicBlock Basic Block
02132  *
02133  * A basic block represents a single entry single exit section of code.
02134  * Basic blocks contain a list of instructions which form the body of
02135  * the block.
02136  *
02137  * Basic blocks belong to functions. They have the type of label.
02138  *
02139  * Basic blocks are themselves values. However, the C API models them as
02140  * LLVMBasicBlockRef.
02141  *
02142  * @see llvm::BasicBlock
02143  *
02144  * @{
02145  */
02146 
02147 /**
02148  * Convert a basic block instance to a value type.
02149  */
02150 LLVMValueRef LLVMBasicBlockAsValue(LLVMBasicBlockRef BB);
02151 
02152 /**
02153  * Determine whether an LLVMValueRef is itself a basic block.
02154  */
02155 LLVMBool LLVMValueIsBasicBlock(LLVMValueRef Val);
02156 
02157 /**
02158  * Convert an LLVMValueRef to an LLVMBasicBlockRef instance.
02159  */
02160 LLVMBasicBlockRef LLVMValueAsBasicBlock(LLVMValueRef Val);
02161 
02162 /**
02163  * Obtain the function to which a basic block belongs.
02164  *
02165  * @see llvm::BasicBlock::getParent()
02166  */
02167 LLVMValueRef LLVMGetBasicBlockParent(LLVMBasicBlockRef BB);
02168 
02169 /**
02170  * Obtain the terminator instruction for a basic block.
02171  *
02172  * If the basic block does not have a terminator (it is not well-formed
02173  * if it doesn't), then NULL is returned.
02174  *
02175  * The returned LLVMValueRef corresponds to a llvm::TerminatorInst.
02176  *
02177  * @see llvm::BasicBlock::getTerminator()
02178  */
02179 LLVMValueRef LLVMGetBasicBlockTerminator(LLVMBasicBlockRef BB);
02180 
02181 /**
02182  * Obtain the number of basic blocks in a function.
02183  *
02184  * @param Fn Function value to operate on.
02185  */
02186 unsigned LLVMCountBasicBlocks(LLVMValueRef Fn);
02187 
02188 /**
02189  * Obtain all of the basic blocks in a function.
02190  *
02191  * This operates on a function value. The BasicBlocks parameter is a
02192  * pointer to a pre-allocated array of LLVMBasicBlockRef of at least
02193  * LLVMCountBasicBlocks() in length. This array is populated with
02194  * LLVMBasicBlockRef instances.
02195  */
02196 void LLVMGetBasicBlocks(LLVMValueRef Fn, LLVMBasicBlockRef *BasicBlocks);
02197 
02198 /**
02199  * Obtain the first basic block in a function.
02200  *
02201  * The returned basic block can be used as an iterator. You will likely
02202  * eventually call into LLVMGetNextBasicBlock() with it.
02203  *
02204  * @see llvm::Function::begin()
02205  */
02206 LLVMBasicBlockRef LLVMGetFirstBasicBlock(LLVMValueRef Fn);
02207 
02208 /**
02209  * Obtain the last basic block in a function.
02210  *
02211  * @see llvm::Function::end()
02212  */
02213 LLVMBasicBlockRef LLVMGetLastBasicBlock(LLVMValueRef Fn);
02214 
02215 /**
02216  * Advance a basic block iterator.
02217  */
02218 LLVMBasicBlockRef LLVMGetNextBasicBlock(LLVMBasicBlockRef BB);
02219 
02220 /**
02221  * Go backwards in a basic block iterator.
02222  */
02223 LLVMBasicBlockRef LLVMGetPreviousBasicBlock(LLVMBasicBlockRef BB);
02224 
02225 /**
02226  * Obtain the basic block that corresponds to the entry point of a
02227  * function.
02228  *
02229  * @see llvm::Function::getEntryBlock()
02230  */
02231 LLVMBasicBlockRef LLVMGetEntryBasicBlock(LLVMValueRef Fn);
02232 
02233 /**
02234  * Append a basic block to the end of a function.
02235  *
02236  * @see llvm::BasicBlock::Create()
02237  */
02238 LLVMBasicBlockRef LLVMAppendBasicBlockInContext(LLVMContextRef C,
02239                                                 LLVMValueRef Fn,
02240                                                 const char *Name);
02241 
02242 /**
02243  * Append a basic block to the end of a function using the global
02244  * context.
02245  *
02246  * @see llvm::BasicBlock::Create()
02247  */
02248 LLVMBasicBlockRef LLVMAppendBasicBlock(LLVMValueRef Fn, const char *Name);
02249 
02250 /**
02251  * Insert a basic block in a function before another basic block.
02252  *
02253  * The function to add to is determined by the function of the
02254  * passed basic block.
02255  *
02256  * @see llvm::BasicBlock::Create()
02257  */
02258 LLVMBasicBlockRef LLVMInsertBasicBlockInContext(LLVMContextRef C,
02259                                                 LLVMBasicBlockRef BB,
02260                                                 const char *Name);
02261 
02262 /**
02263  * Insert a basic block in a function using the global context.
02264  *
02265  * @see llvm::BasicBlock::Create()
02266  */
02267 LLVMBasicBlockRef LLVMInsertBasicBlock(LLVMBasicBlockRef InsertBeforeBB,
02268                                        const char *Name);
02269 
02270 /**
02271  * Remove a basic block from a function and delete it.
02272  *
02273  * This deletes the basic block from its containing function and deletes
02274  * the basic block itself.
02275  *
02276  * @see llvm::BasicBlock::eraseFromParent()
02277  */
02278 void LLVMDeleteBasicBlock(LLVMBasicBlockRef BB);
02279 
02280 /**
02281  * Remove a basic block from a function.
02282  *
02283  * This deletes the basic block from its containing function but keep
02284  * the basic block alive.
02285  *
02286  * @see llvm::BasicBlock::removeFromParent()
02287  */
02288 void LLVMRemoveBasicBlockFromParent(LLVMBasicBlockRef BB);
02289 
02290 /**
02291  * Move a basic block to before another one.
02292  *
02293  * @see llvm::BasicBlock::moveBefore()
02294  */
02295 void LLVMMoveBasicBlockBefore(LLVMBasicBlockRef BB, LLVMBasicBlockRef MovePos);
02296 
02297 /**
02298  * Move a basic block to after another one.
02299  *
02300  * @see llvm::BasicBlock::moveAfter()
02301  */
02302 void LLVMMoveBasicBlockAfter(LLVMBasicBlockRef BB, LLVMBasicBlockRef MovePos);
02303 
02304 /**
02305  * Obtain the first instruction in a basic block.
02306  *
02307  * The returned LLVMValueRef corresponds to a llvm::Instruction
02308  * instance.
02309  */
02310 LLVMValueRef LLVMGetFirstInstruction(LLVMBasicBlockRef BB);
02311 
02312 /**
02313  * Obtain the last instruction in a basic block.
02314  *
02315  * The returned LLVMValueRef corresponds to an LLVM:Instruction.
02316  */
02317 LLVMValueRef LLVMGetLastInstruction(LLVMBasicBlockRef BB);
02318 
02319 /**
02320  * @}
02321  */
02322 
02323 /**
02324  * @defgroup LLVMCCoreValueInstruction Instructions
02325  *
02326  * Functions in this group relate to the inspection and manipulation of
02327  * individual instructions.
02328  *
02329  * In the C++ API, an instruction is modeled by llvm::Instruction. This
02330  * class has a large number of descendents. llvm::Instruction is a
02331  * llvm::Value and in the C API, instructions are modeled by
02332  * LLVMValueRef.
02333  *
02334  * This group also contains sub-groups which operate on specific
02335  * llvm::Instruction types, e.g. llvm::CallInst.
02336  *
02337  * @{
02338  */
02339 
02340 /**
02341  * Determine whether an instruction has any metadata attached.
02342  */
02343 int LLVMHasMetadata(LLVMValueRef Val);
02344 
02345 /**
02346  * Return metadata associated with an instruction value.
02347  */
02348 LLVMValueRef LLVMGetMetadata(LLVMValueRef Val, unsigned KindID);
02349 
02350 /**
02351  * Set metadata associated with an instruction value.
02352  */
02353 void LLVMSetMetadata(LLVMValueRef Val, unsigned KindID, LLVMValueRef Node);
02354 
02355 /**
02356  * Obtain the basic block to which an instruction belongs.
02357  *
02358  * @see llvm::Instruction::getParent()
02359  */
02360 LLVMBasicBlockRef LLVMGetInstructionParent(LLVMValueRef Inst);
02361 
02362 /**
02363  * Obtain the instruction that occurs after the one specified.
02364  *
02365  * The next instruction will be from the same basic block.
02366  *
02367  * If this is the last instruction in a basic block, NULL will be
02368  * returned.
02369  */
02370 LLVMValueRef LLVMGetNextInstruction(LLVMValueRef Inst);
02371 
02372 /**
02373  * Obtain the instruction that occurred before this one.
02374  *
02375  * If the instruction is the first instruction in a basic block, NULL
02376  * will be returned.
02377  */
02378 LLVMValueRef LLVMGetPreviousInstruction(LLVMValueRef Inst);
02379 
02380 /**
02381  * Remove and delete an instruction.
02382  *
02383  * The instruction specified is removed from its containing building
02384  * block and then deleted.
02385  *
02386  * @see llvm::Instruction::eraseFromParent()
02387  */
02388 void LLVMInstructionEraseFromParent(LLVMValueRef Inst);
02389 
02390 /**
02391  * Obtain the code opcode for an individual instruction.
02392  *
02393  * @see llvm::Instruction::getOpCode()
02394  */
02395 LLVMOpcode   LLVMGetInstructionOpcode(LLVMValueRef Inst);
02396 
02397 /**
02398  * Obtain the predicate of an instruction.
02399  *
02400  * This is only valid for instructions that correspond to llvm::ICmpInst
02401  * or llvm::ConstantExpr whose opcode is llvm::Instruction::ICmp.
02402  *
02403  * @see llvm::ICmpInst::getPredicate()
02404  */
02405 LLVMIntPredicate LLVMGetICmpPredicate(LLVMValueRef Inst);
02406 
02407 /**
02408  * @defgroup LLVMCCoreValueInstructionCall Call Sites and Invocations
02409  *
02410  * Functions in this group apply to instructions that refer to call
02411  * sites and invocations. These correspond to C++ types in the
02412  * llvm::CallInst class tree.
02413  *
02414  * @{
02415  */
02416 
02417 /**
02418  * Set the calling convention for a call instruction.
02419  *
02420  * This expects an LLVMValueRef that corresponds to a llvm::CallInst or
02421  * llvm::InvokeInst.
02422  *
02423  * @see llvm::CallInst::setCallingConv()
02424  * @see llvm::InvokeInst::setCallingConv()
02425  */
02426 void LLVMSetInstructionCallConv(LLVMValueRef Instr, unsigned CC);
02427 
02428 /**
02429  * Obtain the calling convention for a call instruction.
02430  *
02431  * This is the opposite of LLVMSetInstructionCallConv(). Reads its
02432  * usage.
02433  *
02434  * @see LLVMSetInstructionCallConv()
02435  */
02436 unsigned LLVMGetInstructionCallConv(LLVMValueRef Instr);
02437 
02438 
02439 void LLVMAddInstrAttribute(LLVMValueRef Instr, unsigned index, LLVMAttribute);
02440 void LLVMRemoveInstrAttribute(LLVMValueRef Instr, unsigned index,
02441                               LLVMAttribute);
02442 void LLVMSetInstrParamAlignment(LLVMValueRef Instr, unsigned index,
02443                                 unsigned align);
02444 
02445 /**
02446  * Obtain whether a call instruction is a tail call.
02447  *
02448  * This only works on llvm::CallInst instructions.
02449  *
02450  * @see llvm::CallInst::isTailCall()
02451  */
02452 LLVMBool LLVMIsTailCall(LLVMValueRef CallInst);
02453 
02454 /**
02455  * Set whether a call instruction is a tail call.
02456  *
02457  * This only works on llvm::CallInst instructions.
02458  *
02459  * @see llvm::CallInst::setTailCall()
02460  */
02461 void LLVMSetTailCall(LLVMValueRef CallInst, LLVMBool IsTailCall);
02462 
02463 /**
02464  * @}
02465  */
02466 
02467 /**
02468  * Obtain the default destination basic block of a switch instruction.
02469  *
02470  * This only works on llvm::SwitchInst instructions.
02471  *
02472  * @see llvm::SwitchInst::getDefaultDest()
02473  */
02474 LLVMBasicBlockRef LLVMGetSwitchDefaultDest(LLVMValueRef SwitchInstr);
02475 
02476 /**
02477  * @defgroup LLVMCCoreValueInstructionPHINode PHI Nodes
02478  *
02479  * Functions in this group only apply to instructions that map to
02480  * llvm::PHINode instances.
02481  *
02482  * @{
02483  */
02484 
02485 /**
02486  * Add an incoming value to the end of a PHI list.
02487  */
02488 void LLVMAddIncoming(LLVMValueRef PhiNode, LLVMValueRef *IncomingValues,
02489                      LLVMBasicBlockRef *IncomingBlocks, unsigned Count);
02490 
02491 /**
02492  * Obtain the number of incoming basic blocks to a PHI node.
02493  */
02494 unsigned LLVMCountIncoming(LLVMValueRef PhiNode);
02495 
02496 /**
02497  * Obtain an incoming value to a PHI node as an LLVMValueRef.
02498  */
02499 LLVMValueRef LLVMGetIncomingValue(LLVMValueRef PhiNode, unsigned Index);
02500 
02501 /**
02502  * Obtain an incoming value to a PHI node as an LLVMBasicBlockRef.
02503  */
02504 LLVMBasicBlockRef LLVMGetIncomingBlock(LLVMValueRef PhiNode, unsigned Index);
02505 
02506 /**
02507  * @}
02508  */
02509 
02510 /**
02511  * @}
02512  */
02513 
02514 /**
02515  * @}
02516  */
02517 
02518 /**
02519  * @defgroup LLVMCCoreInstructionBuilder Instruction Builders
02520  *
02521  * An instruction builder represents a point within a basic block and is
02522  * the exclusive means of building instructions using the C interface.
02523  *
02524  * @{
02525  */
02526 
02527 LLVMBuilderRef LLVMCreateBuilderInContext(LLVMContextRef C);
02528 LLVMBuilderRef LLVMCreateBuilder(void);
02529 void LLVMPositionBuilder(LLVMBuilderRef Builder, LLVMBasicBlockRef Block,
02530                          LLVMValueRef Instr);
02531 void LLVMPositionBuilderBefore(LLVMBuilderRef Builder, LLVMValueRef Instr);
02532 void LLVMPositionBuilderAtEnd(LLVMBuilderRef Builder, LLVMBasicBlockRef Block);
02533 LLVMBasicBlockRef LLVMGetInsertBlock(LLVMBuilderRef Builder);
02534 void LLVMClearInsertionPosition(LLVMBuilderRef Builder);
02535 void LLVMInsertIntoBuilder(LLVMBuilderRef Builder, LLVMValueRef Instr);
02536 void LLVMInsertIntoBuilderWithName(LLVMBuilderRef Builder, LLVMValueRef Instr,
02537                                    const char *Name);
02538 void LLVMDisposeBuilder(LLVMBuilderRef Builder);
02539 
02540 /* Metadata */
02541 void LLVMSetCurrentDebugLocation(LLVMBuilderRef Builder, LLVMValueRef L);
02542 LLVMValueRef LLVMGetCurrentDebugLocation(LLVMBuilderRef Builder);
02543 void LLVMSetInstDebugLocation(LLVMBuilderRef Builder, LLVMValueRef Inst);
02544 
02545 /* Terminators */
02546 LLVMValueRef LLVMBuildRetVoid(LLVMBuilderRef);
02547 LLVMValueRef LLVMBuildRet(LLVMBuilderRef, LLVMValueRef V);
02548 LLVMValueRef LLVMBuildAggregateRet(LLVMBuilderRef, LLVMValueRef *RetVals,
02549                                    unsigned N);
02550 LLVMValueRef LLVMBuildBr(LLVMBuilderRef, LLVMBasicBlockRef Dest);
02551 LLVMValueRef LLVMBuildCondBr(LLVMBuilderRef, LLVMValueRef If,
02552                              LLVMBasicBlockRef Then, LLVMBasicBlockRef Else);
02553 LLVMValueRef LLVMBuildSwitch(LLVMBuilderRef, LLVMValueRef V,
02554                              LLVMBasicBlockRef Else, unsigned NumCases);
02555 LLVMValueRef LLVMBuildIndirectBr(LLVMBuilderRef B, LLVMValueRef Addr,
02556                                  unsigned NumDests);
02557 LLVMValueRef LLVMBuildInvoke(LLVMBuilderRef, LLVMValueRef Fn,
02558                              LLVMValueRef *Args, unsigned NumArgs,
02559                              LLVMBasicBlockRef Then, LLVMBasicBlockRef Catch,
02560                              const char *Name);
02561 LLVMValueRef LLVMBuildLandingPad(LLVMBuilderRef B, LLVMTypeRef Ty,
02562                                  LLVMValueRef PersFn, unsigned NumClauses,
02563                                  const char *Name);
02564 LLVMValueRef LLVMBuildResume(LLVMBuilderRef B, LLVMValueRef Exn);
02565 LLVMValueRef LLVMBuildUnreachable(LLVMBuilderRef);
02566 
02567 /* Add a case to the switch instruction */
02568 void LLVMAddCase(LLVMValueRef Switch, LLVMValueRef OnVal,
02569                  LLVMBasicBlockRef Dest);
02570 
02571 /* Add a destination to the indirectbr instruction */
02572 void LLVMAddDestination(LLVMValueRef IndirectBr, LLVMBasicBlockRef Dest);
02573 
02574 /* Add a catch or filter clause to the landingpad instruction */
02575 void LLVMAddClause(LLVMValueRef LandingPad, LLVMValueRef ClauseVal);
02576 
02577 /* Set the 'cleanup' flag in the landingpad instruction */
02578 void LLVMSetCleanup(LLVMValueRef LandingPad, LLVMBool Val);
02579 
02580 /* Arithmetic */
02581 LLVMValueRef LLVMBuildAdd(LLVMBuilderRef, LLVMValueRef LHS, LLVMValueRef RHS,
02582                           const char *Name);
02583 LLVMValueRef LLVMBuildNSWAdd(LLVMBuilderRef, LLVMValueRef LHS, LLVMValueRef RHS,
02584                              const char *Name);
02585 LLVMValueRef LLVMBuildNUWAdd(LLVMBuilderRef, LLVMValueRef LHS, LLVMValueRef RHS,
02586                              const char *Name);
02587 LLVMValueRef LLVMBuildFAdd(LLVMBuilderRef, LLVMValueRef LHS, LLVMValueRef RHS,
02588                            const char *Name);
02589 LLVMValueRef LLVMBuildSub(LLVMBuilderRef, LLVMValueRef LHS, LLVMValueRef RHS,
02590                           const char *Name);
02591 LLVMValueRef LLVMBuildNSWSub(LLVMBuilderRef, LLVMValueRef LHS, LLVMValueRef RHS,
02592                              const char *Name);
02593 LLVMValueRef LLVMBuildNUWSub(LLVMBuilderRef, LLVMValueRef LHS, LLVMValueRef RHS,
02594                              const char *Name);
02595 LLVMValueRef LLVMBuildFSub(LLVMBuilderRef, LLVMValueRef LHS, LLVMValueRef RHS,
02596                            const char *Name);
02597 LLVMValueRef LLVMBuildMul(LLVMBuilderRef, LLVMValueRef LHS, LLVMValueRef RHS,
02598                           const char *Name);
02599 LLVMValueRef LLVMBuildNSWMul(LLVMBuilderRef, LLVMValueRef LHS, LLVMValueRef RHS,
02600                              const char *Name);
02601 LLVMValueRef LLVMBuildNUWMul(LLVMBuilderRef, LLVMValueRef LHS, LLVMValueRef RHS,
02602                              const char *Name);
02603 LLVMValueRef LLVMBuildFMul(LLVMBuilderRef, LLVMValueRef LHS, LLVMValueRef RHS,
02604                            const char *Name);
02605 LLVMValueRef LLVMBuildUDiv(LLVMBuilderRef, LLVMValueRef LHS, LLVMValueRef RHS,
02606                            const char *Name);
02607 LLVMValueRef LLVMBuildSDiv(LLVMBuilderRef, LLVMValueRef LHS, LLVMValueRef RHS,
02608                            const char *Name);
02609 LLVMValueRef LLVMBuildExactSDiv(LLVMBuilderRef, LLVMValueRef LHS, LLVMValueRef RHS,
02610                                 const char *Name);
02611 LLVMValueRef LLVMBuildFDiv(LLVMBuilderRef, LLVMValueRef LHS, LLVMValueRef RHS,
02612                            const char *Name);
02613 LLVMValueRef LLVMBuildURem(LLVMBuilderRef, LLVMValueRef LHS, LLVMValueRef RHS,
02614                            const char *Name);
02615 LLVMValueRef LLVMBuildSRem(LLVMBuilderRef, LLVMValueRef LHS, LLVMValueRef RHS,
02616                            const char *Name);
02617 LLVMValueRef LLVMBuildFRem(LLVMBuilderRef, LLVMValueRef LHS, LLVMValueRef RHS,
02618                            const char *Name);
02619 LLVMValueRef LLVMBuildShl(LLVMBuilderRef, LLVMValueRef LHS, LLVMValueRef RHS,
02620                            const char *Name);
02621 LLVMValueRef LLVMBuildLShr(LLVMBuilderRef, LLVMValueRef LHS, LLVMValueRef RHS,
02622                            const char *Name);
02623 LLVMValueRef LLVMBuildAShr(LLVMBuilderRef, LLVMValueRef LHS, LLVMValueRef RHS,
02624                            const char *Name);
02625 LLVMValueRef LLVMBuildAnd(LLVMBuilderRef, LLVMValueRef LHS, LLVMValueRef RHS,
02626                           const char *Name);
02627 LLVMValueRef LLVMBuildOr(LLVMBuilderRef, LLVMValueRef LHS, LLVMValueRef RHS,
02628                           const char *Name);
02629 LLVMValueRef LLVMBuildXor(LLVMBuilderRef, LLVMValueRef LHS, LLVMValueRef RHS,
02630                           const char *Name);
02631 LLVMValueRef LLVMBuildBinOp(LLVMBuilderRef B, LLVMOpcode Op,
02632                             LLVMValueRef LHS, LLVMValueRef RHS,
02633                             const char *Name);
02634 LLVMValueRef LLVMBuildNeg(LLVMBuilderRef, LLVMValueRef V, const char *Name);
02635 LLVMValueRef LLVMBuildNSWNeg(LLVMBuilderRef B, LLVMValueRef V,
02636                              const char *Name);
02637 LLVMValueRef LLVMBuildNUWNeg(LLVMBuilderRef B, LLVMValueRef V,
02638                              const char *Name);
02639 LLVMValueRef LLVMBuildFNeg(LLVMBuilderRef, LLVMValueRef V, const char *Name);
02640 LLVMValueRef LLVMBuildNot(LLVMBuilderRef, LLVMValueRef V, const char *Name);
02641 
02642 /* Memory */
02643 LLVMValueRef LLVMBuildMalloc(LLVMBuilderRef, LLVMTypeRef Ty, const char *Name);
02644 LLVMValueRef LLVMBuildArrayMalloc(LLVMBuilderRef, LLVMTypeRef Ty,
02645                                   LLVMValueRef Val, const char *Name);
02646 LLVMValueRef LLVMBuildAlloca(LLVMBuilderRef, LLVMTypeRef Ty, const char *Name);
02647 LLVMValueRef LLVMBuildArrayAlloca(LLVMBuilderRef, LLVMTypeRef Ty,
02648                                   LLVMValueRef Val, const char *Name);
02649 LLVMValueRef LLVMBuildFree(LLVMBuilderRef, LLVMValueRef PointerVal);
02650 LLVMValueRef LLVMBuildLoad(LLVMBuilderRef, LLVMValueRef PointerVal,
02651                            const char *Name);
02652 LLVMValueRef LLVMBuildStore(LLVMBuilderRef, LLVMValueRef Val, LLVMValueRef Ptr);
02653 LLVMValueRef LLVMBuildGEP(LLVMBuilderRef B, LLVMValueRef Pointer,
02654                           LLVMValueRef *Indices, unsigned NumIndices,
02655                           const char *Name);
02656 LLVMValueRef LLVMBuildInBoundsGEP(LLVMBuilderRef B, LLVMValueRef Pointer,
02657                                   LLVMValueRef *Indices, unsigned NumIndices,
02658                                   const char *Name);
02659 LLVMValueRef LLVMBuildStructGEP(LLVMBuilderRef B, LLVMValueRef Pointer,
02660                                 unsigned Idx, const char *Name);
02661 LLVMValueRef LLVMBuildGlobalString(LLVMBuilderRef B, const char *Str,
02662                                    const char *Name);
02663 LLVMValueRef LLVMBuildGlobalStringPtr(LLVMBuilderRef B, const char *Str,
02664                                       const char *Name);
02665 LLVMBool LLVMGetVolatile(LLVMValueRef MemoryAccessInst);
02666 void LLVMSetVolatile(LLVMValueRef MemoryAccessInst, LLVMBool IsVolatile);
02667 
02668 /* Casts */
02669 LLVMValueRef LLVMBuildTrunc(LLVMBuilderRef, LLVMValueRef Val,
02670                             LLVMTypeRef DestTy, const char *Name);
02671 LLVMValueRef LLVMBuildZExt(LLVMBuilderRef, LLVMValueRef Val,
02672                            LLVMTypeRef DestTy, const char *Name);
02673 LLVMValueRef LLVMBuildSExt(LLVMBuilderRef, LLVMValueRef Val,
02674                            LLVMTypeRef DestTy, const char *Name);
02675 LLVMValueRef LLVMBuildFPToUI(LLVMBuilderRef, LLVMValueRef Val,
02676                              LLVMTypeRef DestTy, const char *Name);
02677 LLVMValueRef LLVMBuildFPToSI(LLVMBuilderRef, LLVMValueRef Val,
02678                              LLVMTypeRef DestTy, const char *Name);
02679 LLVMValueRef LLVMBuildUIToFP(LLVMBuilderRef, LLVMValueRef Val,
02680                              LLVMTypeRef DestTy, const char *Name);
02681 LLVMValueRef LLVMBuildSIToFP(LLVMBuilderRef, LLVMValueRef Val,
02682                              LLVMTypeRef DestTy, const char *Name);
02683 LLVMValueRef LLVMBuildFPTrunc(LLVMBuilderRef, LLVMValueRef Val,
02684                               LLVMTypeRef DestTy, const char *Name);
02685 LLVMValueRef LLVMBuildFPExt(LLVMBuilderRef, LLVMValueRef Val,
02686                             LLVMTypeRef DestTy, const char *Name);
02687 LLVMValueRef LLVMBuildPtrToInt(LLVMBuilderRef, LLVMValueRef Val,
02688                                LLVMTypeRef DestTy, const char *Name);
02689 LLVMValueRef LLVMBuildIntToPtr(LLVMBuilderRef, LLVMValueRef Val,
02690                                LLVMTypeRef DestTy, const char *Name);
02691 LLVMValueRef LLVMBuildBitCast(LLVMBuilderRef, LLVMValueRef Val,
02692                               LLVMTypeRef DestTy, const char *Name);
02693 LLVMValueRef LLVMBuildAddrSpaceCast(LLVMBuilderRef, LLVMValueRef Val,
02694                                     LLVMTypeRef DestTy, const char *Name);
02695 LLVMValueRef LLVMBuildZExtOrBitCast(LLVMBuilderRef, LLVMValueRef Val,
02696                                     LLVMTypeRef DestTy, const char *Name);
02697 LLVMValueRef LLVMBuildSExtOrBitCast(LLVMBuilderRef, LLVMValueRef Val,
02698                                     LLVMTypeRef DestTy, const char *Name);
02699 LLVMValueRef LLVMBuildTruncOrBitCast(LLVMBuilderRef, LLVMValueRef Val,
02700                                      LLVMTypeRef DestTy, const char *Name);
02701 LLVMValueRef LLVMBuildCast(LLVMBuilderRef B, LLVMOpcode Op, LLVMValueRef Val,
02702                            LLVMTypeRef DestTy, const char *Name);
02703 LLVMValueRef LLVMBuildPointerCast(LLVMBuilderRef, LLVMValueRef Val,
02704                                   LLVMTypeRef DestTy, const char *Name);
02705 LLVMValueRef LLVMBuildIntCast(LLVMBuilderRef, LLVMValueRef Val, /*Signed cast!*/
02706                               LLVMTypeRef DestTy, const char *Name);
02707 LLVMValueRef LLVMBuildFPCast(LLVMBuilderRef, LLVMValueRef Val,
02708                              LLVMTypeRef DestTy, const char *Name);
02709 
02710 /* Comparisons */
02711 LLVMValueRef LLVMBuildICmp(LLVMBuilderRef, LLVMIntPredicate Op,
02712                            LLVMValueRef LHS, LLVMValueRef RHS,
02713                            const char *Name);
02714 LLVMValueRef LLVMBuildFCmp(LLVMBuilderRef, LLVMRealPredicate Op,
02715                            LLVMValueRef LHS, LLVMValueRef RHS,
02716                            const char *Name);
02717 
02718 /* Miscellaneous instructions */
02719 LLVMValueRef LLVMBuildPhi(LLVMBuilderRef, LLVMTypeRef Ty, const char *Name);
02720 LLVMValueRef LLVMBuildCall(LLVMBuilderRef, LLVMValueRef Fn,
02721                            LLVMValueRef *Args, unsigned NumArgs,
02722                            const char *Name);
02723 LLVMValueRef LLVMBuildSelect(LLVMBuilderRef, LLVMValueRef If,
02724                              LLVMValueRef Then, LLVMValueRef Else,
02725                              const char *Name);
02726 LLVMValueRef LLVMBuildVAArg(LLVMBuilderRef, LLVMValueRef List, LLVMTypeRef Ty,
02727                             const char *Name);
02728 LLVMValueRef LLVMBuildExtractElement(LLVMBuilderRef, LLVMValueRef VecVal,
02729                                      LLVMValueRef Index, const char *Name);
02730 LLVMValueRef LLVMBuildInsertElement(LLVMBuilderRef, LLVMValueRef VecVal,
02731                                     LLVMValueRef EltVal, LLVMValueRef Index,
02732                                     const char *Name);
02733 LLVMValueRef LLVMBuildShuffleVector(LLVMBuilderRef, LLVMValueRef V1,
02734                                     LLVMValueRef V2, LLVMValueRef Mask,
02735                                     const char *Name);
02736 LLVMValueRef LLVMBuildExtractValue(LLVMBuilderRef, LLVMValueRef AggVal,
02737                                    unsigned Index, const char *Name);
02738 LLVMValueRef LLVMBuildInsertValue(LLVMBuilderRef, LLVMValueRef AggVal,
02739                                   LLVMValueRef EltVal, unsigned Index,
02740                                   const char *Name);
02741 
02742 LLVMValueRef LLVMBuildIsNull(LLVMBuilderRef, LLVMValueRef Val,
02743                              const char *Name);
02744 LLVMValueRef LLVMBuildIsNotNull(LLVMBuilderRef, LLVMValueRef Val,
02745                                 const char *Name);
02746 LLVMValueRef LLVMBuildPtrDiff(LLVMBuilderRef, LLVMValueRef LHS,
02747                               LLVMValueRef RHS, const char *Name);
02748 LLVMValueRef LLVMBuildFence(LLVMBuilderRef B, LLVMAtomicOrdering ordering,
02749                             LLVMBool singleThread, const char *Name);
02750 LLVMValueRef LLVMBuildAtomicRMW(LLVMBuilderRef B, LLVMAtomicRMWBinOp op,
02751                                 LLVMValueRef PTR, LLVMValueRef Val,
02752                                 LLVMAtomicOrdering ordering,
02753                                 LLVMBool singleThread);
02754 
02755 /**
02756  * @}
02757  */
02758 
02759 /**
02760  * @defgroup LLVMCCoreModuleProvider Module Providers
02761  *
02762  * @{
02763  */
02764 
02765 /**
02766  * Changes the type of M so it can be passed to FunctionPassManagers and the
02767  * JIT.  They take ModuleProviders for historical reasons.
02768  */
02769 LLVMModuleProviderRef
02770 LLVMCreateModuleProviderForExistingModule(LLVMModuleRef M);
02771 
02772 /**
02773  * Destroys the module M.
02774  */
02775 void LLVMDisposeModuleProvider(LLVMModuleProviderRef M);
02776 
02777 /**
02778  * @}
02779  */
02780 
02781 /**
02782  * @defgroup LLVMCCoreMemoryBuffers Memory Buffers
02783  *
02784  * @{
02785  */
02786 
02787 LLVMBool LLVMCreateMemoryBufferWithContentsOfFile(const char *Path,
02788                                                   LLVMMemoryBufferRef *OutMemBuf,
02789                                                   char **OutMessage);
02790 LLVMBool LLVMCreateMemoryBufferWithSTDIN(LLVMMemoryBufferRef *OutMemBuf,
02791                                          char **OutMessage);
02792 LLVMMemoryBufferRef LLVMCreateMemoryBufferWithMemoryRange(const char *InputData,
02793                                                           size_t InputDataLength,
02794                                                           const char *BufferName,
02795                                                           LLVMBool RequiresNullTerminator);
02796 LLVMMemoryBufferRef LLVMCreateMemoryBufferWithMemoryRangeCopy(const char *InputData,
02797                                                               size_t InputDataLength,
02798                                                               const char *BufferName);
02799 const char *LLVMGetBufferStart(LLVMMemoryBufferRef MemBuf);
02800 size_t LLVMGetBufferSize(LLVMMemoryBufferRef MemBuf);
02801 void LLVMDisposeMemoryBuffer(LLVMMemoryBufferRef MemBuf);
02802 
02803 /**
02804  * @}
02805  */
02806 
02807 /**
02808  * @defgroup LLVMCCorePassRegistry Pass Registry
02809  *
02810  * @{
02811  */
02812 
02813 /** Return the global pass registry, for use with initialization functions.
02814     @see llvm::PassRegistry::getPassRegistry */
02815 LLVMPassRegistryRef LLVMGetGlobalPassRegistry(void);
02816 
02817 /**
02818  * @}
02819  */
02820 
02821 /**
02822  * @defgroup LLVMCCorePassManagers Pass Managers
02823  *
02824  * @{
02825  */
02826 
02827 /** Constructs a new whole-module pass pipeline. This type of pipeline is
02828     suitable for link-time optimization and whole-module transformations.
02829     @see llvm::PassManager::PassManager */
02830 LLVMPassManagerRef LLVMCreatePassManager(void);
02831 
02832 /** Constructs a new function-by-function pass pipeline over the module
02833     provider. It does not take ownership of the module provider. This type of
02834     pipeline is suitable for code generation and JIT compilation tasks.
02835     @see llvm::FunctionPassManager::FunctionPassManager */
02836 LLVMPassManagerRef LLVMCreateFunctionPassManagerForModule(LLVMModuleRef M);
02837 
02838 /** Deprecated: Use LLVMCreateFunctionPassManagerForModule instead. */
02839 LLVMPassManagerRef LLVMCreateFunctionPassManager(LLVMModuleProviderRef MP);
02840 
02841 /** Initializes, executes on the provided module, and finalizes all of the
02842     passes scheduled in the pass manager. Returns 1 if any of the passes
02843     modified the module, 0 otherwise.
02844     @see llvm::PassManager::run(Module&) */
02845 LLVMBool LLVMRunPassManager(LLVMPassManagerRef PM, LLVMModuleRef M);
02846 
02847 /** Initializes all of the function passes scheduled in the function pass
02848     manager. Returns 1 if any of the passes modified the module, 0 otherwise.
02849     @see llvm::FunctionPassManager::doInitialization */
02850 LLVMBool LLVMInitializeFunctionPassManager(LLVMPassManagerRef FPM);
02851 
02852 /** Executes all of the function passes scheduled in the function pass manager
02853     on the provided function. Returns 1 if any of the passes modified the
02854     function, false otherwise.
02855     @see llvm::FunctionPassManager::run(Function&) */
02856 LLVMBool LLVMRunFunctionPassManager(LLVMPassManagerRef FPM, LLVMValueRef F);
02857 
02858 /** Finalizes all of the function passes scheduled in in the function pass
02859     manager. Returns 1 if any of the passes modified the module, 0 otherwise.
02860     @see llvm::FunctionPassManager::doFinalization */
02861 LLVMBool LLVMFinalizeFunctionPassManager(LLVMPassManagerRef FPM);
02862 
02863 /** Frees the memory of a pass pipeline. For function pipelines, does not free
02864     the module provider.
02865     @see llvm::PassManagerBase::~PassManagerBase. */
02866 void LLVMDisposePassManager(LLVMPassManagerRef PM);
02867 
02868 /**
02869  * @}
02870  */
02871 
02872 /**
02873  * @defgroup LLVMCCoreThreading Threading
02874  *
02875  * Handle the structures needed to make LLVM safe for multithreading.
02876  *
02877  * @{
02878  */
02879 
02880 /** Deprecated: Multi-threading can only be enabled/disabled with the compile
02881     time define LLVM_ENABLE_THREADS.  This function always returns
02882     LLVMIsMultithreaded(). */
02883 LLVMBool LLVMStartMultithreaded(void);
02884 
02885 /** Deprecated: Multi-threading can only be enabled/disabled with the compile
02886     time define LLVM_ENABLE_THREADS. */
02887 void LLVMStopMultithreaded(void);
02888 
02889 /** Check whether LLVM is executing in thread-safe mode or not.
02890     @see llvm::llvm_is_multithreaded */
02891 LLVMBool LLVMIsMultithreaded(void);
02892 
02893 /**
02894  * @}
02895  */
02896 
02897 /**
02898  * @}
02899  */
02900 
02901 /**
02902  * @}
02903  */
02904 
02905 #ifdef __cplusplus
02906 }
02907 #endif /* !defined(__cplusplus) */
02908 
02909 #endif /* !defined(LLVM_C_CORE_H) */