Home | History | Annotate | Download | only in llvm-c
      1 /*===-- llvm-c/Core.h - Core Library C Interface ------------------*- C -*-===*\
      2 |*                                                                            *|
      3 |*                     The LLVM Compiler Infrastructure                       *|
      4 |*                                                                            *|
      5 |* This file is distributed under the University of Illinois Open Source      *|
      6 |* License. See LICENSE.TXT for details.                                      *|
      7 |*                                                                            *|
      8 |*===----------------------------------------------------------------------===*|
      9 |*                                                                            *|
     10 |* This header declares the C interface to libLLVMCore.a, which implements    *|
     11 |* the LLVM intermediate representation.                                      *|
     12 |*                                                                            *|
     13 \*===----------------------------------------------------------------------===*/
     14 
     15 #ifndef LLVM_C_CORE_H
     16 #define LLVM_C_CORE_H
     17 
     18 #include "llvm/Support/DataTypes.h"
     19 
     20 #ifdef __cplusplus
     21 
     22 /* Need these includes to support the LLVM 'cast' template for the C++ 'wrap'
     23    and 'unwrap' conversion functions. */
     24 #include "llvm/IR/IRBuilder.h"
     25 #include "llvm/IR/Module.h"
     26 #include "llvm/PassRegistry.h"
     27 
     28 extern "C" {
     29 #endif
     30 
     31 /**
     32  * @defgroup LLVMC LLVM-C: C interface to LLVM
     33  *
     34  * This module exposes parts of the LLVM library as a C API.
     35  *
     36  * @{
     37  */
     38 
     39 /**
     40  * @defgroup LLVMCTransforms Transforms
     41  */
     42 
     43 /**
     44  * @defgroup LLVMCCore Core
     45  *
     46  * This modules provide an interface to libLLVMCore, which implements
     47  * the LLVM intermediate representation as well as other related types
     48  * and utilities.
     49  *
     50  * LLVM uses a polymorphic type hierarchy which C cannot represent, therefore
     51  * parameters must be passed as base types. Despite the declared types, most
     52  * of the functions provided operate only on branches of the type hierarchy.
     53  * The declared parameter names are descriptive and specify which type is
     54  * required. Additionally, each type hierarchy is documented along with the
     55  * functions that operate upon it. For more detail, refer to LLVM's C++ code.
     56  * If in doubt, refer to Core.cpp, which performs parameter downcasts in the
     57  * form unwrap<RequiredType>(Param).
     58  *
     59  * Many exotic languages can interoperate with C code but have a harder time
     60  * with C++ due to name mangling. So in addition to C, this interface enables
     61  * tools written in such languages.
     62  *
     63  * When included into a C++ source file, also declares 'wrap' and 'unwrap'
     64  * helpers to perform opaque reference<-->pointer conversions. These helpers
     65  * are shorter and more tightly typed than writing the casts by hand when
     66  * authoring bindings. In assert builds, they will do runtime type checking.
     67  *
     68  * @{
     69  */
     70 
     71 /**
     72  * @defgroup LLVMCCoreTypes Types and Enumerations
     73  *
     74  * @{
     75  */
     76 
     77 typedef int LLVMBool;
     78 
     79 /* Opaque types. */
     80 
     81 /**
     82  * The top-level container for all LLVM global data. See the LLVMContext class.
     83  */
     84 typedef struct LLVMOpaqueContext *LLVMContextRef;
     85 
     86 /**
     87  * The top-level container for all other LLVM Intermediate Representation (IR)
     88  * objects.
     89  *
     90  * @see llvm::Module
     91  */
     92 typedef struct LLVMOpaqueModule *LLVMModuleRef;
     93 
     94 /**
     95  * Each value in the LLVM IR has a type, an LLVMTypeRef.
     96  *
     97  * @see llvm::Type
     98  */
     99 typedef struct LLVMOpaqueType *LLVMTypeRef;
    100 
    101 /**
    102  * Represents an individual value in LLVM IR.
    103  *
    104  * This models llvm::Value.
    105  */
    106 typedef struct LLVMOpaqueValue *LLVMValueRef;
    107 
    108 /**
    109  * Represents a basic block of instructions in LLVM IR.
    110  *
    111  * This models llvm::BasicBlock.
    112  */
    113 typedef struct LLVMOpaqueBasicBlock *LLVMBasicBlockRef;
    114 
    115 /**
    116  * Represents an LLVM basic block builder.
    117  *
    118  * This models llvm::IRBuilder.
    119  */
    120 typedef struct LLVMOpaqueBuilder *LLVMBuilderRef;
    121 
    122 /**
    123  * Interface used to provide a module to JIT or interpreter.
    124  * This is now just a synonym for llvm::Module, but we have to keep using the
    125  * different type to keep binary compatibility.
    126  */
    127 typedef struct LLVMOpaqueModuleProvider *LLVMModuleProviderRef;
    128 
    129 /**
    130  * Used to provide a module to JIT or interpreter.
    131  *
    132  * @see llvm::MemoryBuffer
    133  */
    134 typedef struct LLVMOpaqueMemoryBuffer *LLVMMemoryBufferRef;
    135 
    136 /** @see llvm::PassManagerBase */
    137 typedef struct LLVMOpaquePassManager *LLVMPassManagerRef;
    138 
    139 /** @see llvm::PassRegistry */
    140 typedef struct LLVMOpaquePassRegistry *LLVMPassRegistryRef;
    141 
    142 /**
    143  * Used to get the users and usees of a Value.
    144  *
    145  * @see llvm::Use */
    146 typedef struct LLVMOpaqueUse *LLVMUseRef;
    147 
    148 typedef enum {
    149     LLVMZExtAttribute       = 1<<0,
    150     LLVMSExtAttribute       = 1<<1,
    151     LLVMNoReturnAttribute   = 1<<2,
    152     LLVMInRegAttribute      = 1<<3,
    153     LLVMStructRetAttribute  = 1<<4,
    154     LLVMNoUnwindAttribute   = 1<<5,
    155     LLVMNoAliasAttribute    = 1<<6,
    156     LLVMByValAttribute      = 1<<7,
    157     LLVMNestAttribute       = 1<<8,
    158     LLVMReadNoneAttribute   = 1<<9,
    159     LLVMReadOnlyAttribute   = 1<<10,
    160     LLVMNoInlineAttribute   = 1<<11,
    161     LLVMAlwaysInlineAttribute    = 1<<12,
    162     LLVMOptimizeForSizeAttribute = 1<<13,
    163     LLVMStackProtectAttribute    = 1<<14,
    164     LLVMStackProtectReqAttribute = 1<<15,
    165     LLVMAlignment = 31<<16,
    166     LLVMNoCaptureAttribute  = 1<<21,
    167     LLVMNoRedZoneAttribute  = 1<<22,
    168     LLVMNoImplicitFloatAttribute = 1<<23,
    169     LLVMNakedAttribute      = 1<<24,
    170     LLVMInlineHintAttribute = 1<<25,
    171     LLVMStackAlignment = 7<<26,
    172     LLVMReturnsTwice = 1 << 29,
    173     LLVMUWTable = 1 << 30,
    174     LLVMNonLazyBind = 1 << 31
    175 
    176     /* FIXME: These attributes are currently not included in the C API as
    177        a temporary measure until the API/ABI impact to the C API is understood
    178        and the path forward agreed upon.
    179     LLVMAddressSafety = 1ULL << 32,
    180     LLVMStackProtectStrongAttribute = 1ULL<<33
    181     */
    182 } LLVMAttribute;
    183 
    184 typedef enum {
    185   /* Terminator Instructions */
    186   LLVMRet            = 1,
    187   LLVMBr             = 2,
    188   LLVMSwitch         = 3,
    189   LLVMIndirectBr     = 4,
    190   LLVMInvoke         = 5,
    191   /* removed 6 due to API changes */
    192   LLVMUnreachable    = 7,
    193 
    194   /* Standard Binary Operators */
    195   LLVMAdd            = 8,
    196   LLVMFAdd           = 9,
    197   LLVMSub            = 10,
    198   LLVMFSub           = 11,
    199   LLVMMul            = 12,
    200   LLVMFMul           = 13,
    201   LLVMUDiv           = 14,
    202   LLVMSDiv           = 15,
    203   LLVMFDiv           = 16,
    204   LLVMURem           = 17,
    205   LLVMSRem           = 18,
    206   LLVMFRem           = 19,
    207 
    208   /* Logical Operators */
    209   LLVMShl            = 20,
    210   LLVMLShr           = 21,
    211   LLVMAShr           = 22,
    212   LLVMAnd            = 23,
    213   LLVMOr             = 24,
    214   LLVMXor            = 25,
    215 
    216   /* Memory Operators */
    217   LLVMAlloca         = 26,
    218   LLVMLoad           = 27,
    219   LLVMStore          = 28,
    220   LLVMGetElementPtr  = 29,
    221 
    222   /* Cast Operators */
    223   LLVMTrunc          = 30,
    224   LLVMZExt           = 31,
    225   LLVMSExt           = 32,
    226   LLVMFPToUI         = 33,
    227   LLVMFPToSI         = 34,
    228   LLVMUIToFP         = 35,
    229   LLVMSIToFP         = 36,
    230   LLVMFPTrunc        = 37,
    231   LLVMFPExt          = 38,
    232   LLVMPtrToInt       = 39,
    233   LLVMIntToPtr       = 40,
    234   LLVMBitCast        = 41,
    235 
    236   /* Other Operators */
    237   LLVMICmp           = 42,
    238   LLVMFCmp           = 43,
    239   LLVMPHI            = 44,
    240   LLVMCall           = 45,
    241   LLVMSelect         = 46,
    242   LLVMUserOp1        = 47,
    243   LLVMUserOp2        = 48,
    244   LLVMVAArg          = 49,
    245   LLVMExtractElement = 50,
    246   LLVMInsertElement  = 51,
    247   LLVMShuffleVector  = 52,
    248   LLVMExtractValue   = 53,
    249   LLVMInsertValue    = 54,
    250 
    251   /* Atomic operators */
    252   LLVMFence          = 55,
    253   LLVMAtomicCmpXchg  = 56,
    254   LLVMAtomicRMW      = 57,
    255 
    256   /* Exception Handling Operators */
    257   LLVMResume         = 58,
    258   LLVMLandingPad     = 59
    259 
    260 } LLVMOpcode;
    261 
    262 typedef enum {
    263   LLVMVoidTypeKind,        /**< type with no size */
    264   LLVMHalfTypeKind,        /**< 16 bit floating point type */
    265   LLVMFloatTypeKind,       /**< 32 bit floating point type */
    266   LLVMDoubleTypeKind,      /**< 64 bit floating point type */
    267   LLVMX86_FP80TypeKind,    /**< 80 bit floating point type (X87) */
    268   LLVMFP128TypeKind,       /**< 128 bit floating point type (112-bit mantissa)*/
    269   LLVMPPC_FP128TypeKind,   /**< 128 bit floating point type (two 64-bits) */
    270   LLVMLabelTypeKind,       /**< Labels */
    271   LLVMIntegerTypeKind,     /**< Arbitrary bit width integers */
    272   LLVMFunctionTypeKind,    /**< Functions */
    273   LLVMStructTypeKind,      /**< Structures */
    274   LLVMArrayTypeKind,       /**< Arrays */
    275   LLVMPointerTypeKind,     /**< Pointers */
    276   LLVMVectorTypeKind,      /**< SIMD 'packed' format, or other vector type */
    277   LLVMMetadataTypeKind,    /**< Metadata */
    278   LLVMX86_MMXTypeKind      /**< X86 MMX */
    279 } LLVMTypeKind;
    280 
    281 typedef enum {
    282   LLVMExternalLinkage,    /**< Externally visible function */
    283   LLVMAvailableExternallyLinkage,
    284   LLVMLinkOnceAnyLinkage, /**< Keep one copy of function when linking (inline)*/
    285   LLVMLinkOnceODRLinkage, /**< Same, but only replaced by something
    286                             equivalent. */
    287   LLVMLinkOnceODRAutoHideLinkage, /**< Like LinkOnceODR, but possibly hidden. */
    288   LLVMWeakAnyLinkage,     /**< Keep one copy of function when linking (weak) */
    289   LLVMWeakODRLinkage,     /**< Same, but only replaced by something
    290                             equivalent. */
    291   LLVMAppendingLinkage,   /**< Special purpose, only applies to global arrays */
    292   LLVMInternalLinkage,    /**< Rename collisions when linking (static
    293                                functions) */
    294   LLVMPrivateLinkage,     /**< Like Internal, but omit from symbol table */
    295   LLVMDLLImportLinkage,   /**< Function to be imported from DLL */
    296   LLVMDLLExportLinkage,   /**< Function to be accessible from DLL */
    297   LLVMExternalWeakLinkage,/**< ExternalWeak linkage description */
    298   LLVMGhostLinkage,       /**< Obsolete */
    299   LLVMCommonLinkage,      /**< Tentative definitions */
    300   LLVMLinkerPrivateLinkage, /**< Like Private, but linker removes. */
    301   LLVMLinkerPrivateWeakLinkage /**< Like LinkerPrivate, but is weak. */
    302 } LLVMLinkage;
    303 
    304 typedef enum {
    305   LLVMDefaultVisibility,  /**< The GV is visible */
    306   LLVMHiddenVisibility,   /**< The GV is hidden */
    307   LLVMProtectedVisibility /**< The GV is protected */
    308 } LLVMVisibility;
    309 
    310 typedef enum {
    311   LLVMCCallConv           = 0,
    312   LLVMFastCallConv        = 8,
    313   LLVMColdCallConv        = 9,
    314   LLVMX86StdcallCallConv  = 64,
    315   LLVMX86FastcallCallConv = 65
    316 } LLVMCallConv;
    317 
    318 typedef enum {
    319   LLVMIntEQ = 32, /**< equal */
    320   LLVMIntNE,      /**< not equal */
    321   LLVMIntUGT,     /**< unsigned greater than */
    322   LLVMIntUGE,     /**< unsigned greater or equal */
    323   LLVMIntULT,     /**< unsigned less than */
    324   LLVMIntULE,     /**< unsigned less or equal */
    325   LLVMIntSGT,     /**< signed greater than */
    326   LLVMIntSGE,     /**< signed greater or equal */
    327   LLVMIntSLT,     /**< signed less than */
    328   LLVMIntSLE      /**< signed less or equal */
    329 } LLVMIntPredicate;
    330 
    331 typedef enum {
    332   LLVMRealPredicateFalse, /**< Always false (always folded) */
    333   LLVMRealOEQ,            /**< True if ordered and equal */
    334   LLVMRealOGT,            /**< True if ordered and greater than */
    335   LLVMRealOGE,            /**< True if ordered and greater than or equal */
    336   LLVMRealOLT,            /**< True if ordered and less than */
    337   LLVMRealOLE,            /**< True if ordered and less than or equal */
    338   LLVMRealONE,            /**< True if ordered and operands are unequal */
    339   LLVMRealORD,            /**< True if ordered (no nans) */
    340   LLVMRealUNO,            /**< True if unordered: isnan(X) | isnan(Y) */
    341   LLVMRealUEQ,            /**< True if unordered or equal */
    342   LLVMRealUGT,            /**< True if unordered or greater than */
    343   LLVMRealUGE,            /**< True if unordered, greater than, or equal */
    344   LLVMRealULT,            /**< True if unordered or less than */
    345   LLVMRealULE,            /**< True if unordered, less than, or equal */
    346   LLVMRealUNE,            /**< True if unordered or not equal */
    347   LLVMRealPredicateTrue   /**< Always true (always folded) */
    348 } LLVMRealPredicate;
    349 
    350 typedef enum {
    351   LLVMLandingPadCatch,    /**< A catch clause   */
    352   LLVMLandingPadFilter    /**< A filter clause  */
    353 } LLVMLandingPadClauseTy;
    354 
    355 /**
    356  * @}
    357  */
    358 
    359 void LLVMInitializeCore(LLVMPassRegistryRef R);
    360 
    361 /** Deallocate and destroy all ManagedStatic variables.
    362     @see llvm::llvm_shutdown
    363     @see ManagedStatic */
    364 void LLVMShutdown();
    365 
    366 
    367 /*===-- Error handling ----------------------------------------------------===*/
    368 
    369 void LLVMDisposeMessage(char *Message);
    370 
    371 
    372 /**
    373  * @defgroup LLVMCCoreContext Contexts
    374  *
    375  * Contexts are execution states for the core LLVM IR system.
    376  *
    377  * Most types are tied to a context instance. Multiple contexts can
    378  * exist simultaneously. A single context is not thread safe. However,
    379  * different contexts can execute on different threads simultaneously.
    380  *
    381  * @{
    382  */
    383 
    384 /**
    385  * Create a new context.
    386  *
    387  * Every call to this function should be paired with a call to
    388  * LLVMContextDispose() or the context will leak memory.
    389  */
    390 LLVMContextRef LLVMContextCreate(void);
    391 
    392 /**
    393  * Obtain the global context instance.
    394  */
    395 LLVMContextRef LLVMGetGlobalContext(void);
    396 
    397 /**
    398  * Destroy a context instance.
    399  *
    400  * This should be called for every call to LLVMContextCreate() or memory
    401  * will be leaked.
    402  */
    403 void LLVMContextDispose(LLVMContextRef C);
    404 
    405 unsigned LLVMGetMDKindIDInContext(LLVMContextRef C, const char* Name,
    406                                   unsigned SLen);
    407 unsigned LLVMGetMDKindID(const char* Name, unsigned SLen);
    408 
    409 /**
    410  * @}
    411  */
    412 
    413 /**
    414  * @defgroup LLVMCCoreModule Modules
    415  *
    416  * Modules represent the top-level structure in a LLVM program. An LLVM
    417  * module is effectively a translation unit or a collection of
    418  * translation units merged together.
    419  *
    420  * @{
    421  */
    422 
    423 /**
    424  * Create a new, empty module in the global context.
    425  *
    426  * This is equivalent to calling LLVMModuleCreateWithNameInContext with
    427  * LLVMGetGlobalContext() as the context parameter.
    428  *
    429  * Every invocation should be paired with LLVMDisposeModule() or memory
    430  * will be leaked.
    431  */
    432 LLVMModuleRef LLVMModuleCreateWithName(const char *ModuleID);
    433 
    434 /**
    435  * Create a new, empty module in a specific context.
    436  *
    437  * Every invocation should be paired with LLVMDisposeModule() or memory
    438  * will be leaked.
    439  */
    440 LLVMModuleRef LLVMModuleCreateWithNameInContext(const char *ModuleID,
    441                                                 LLVMContextRef C);
    442 
    443 /**
    444  * Destroy a module instance.
    445  *
    446  * This must be called for every created module or memory will be
    447  * leaked.
    448  */
    449 void LLVMDisposeModule(LLVMModuleRef M);
    450 
    451 /**
    452  * Obtain the data layout for a module.
    453  *
    454  * @see Module::getDataLayout()
    455  */
    456 const char *LLVMGetDataLayout(LLVMModuleRef M);
    457 
    458 /**
    459  * Set the data layout for a module.
    460  *
    461  * @see Module::setDataLayout()
    462  */
    463 void LLVMSetDataLayout(LLVMModuleRef M, const char *Triple);
    464 
    465 /**
    466  * Obtain the target triple for a module.
    467  *
    468  * @see Module::getTargetTriple()
    469  */
    470 const char *LLVMGetTarget(LLVMModuleRef M);
    471 
    472 /**
    473  * Set the target triple for a module.
    474  *
    475  * @see Module::setTargetTriple()
    476  */
    477 void LLVMSetTarget(LLVMModuleRef M, const char *Triple);
    478 
    479 /**
    480  * Dump a representation of a module to stderr.
    481  *
    482  * @see Module::dump()
    483  */
    484 void LLVMDumpModule(LLVMModuleRef M);
    485 
    486 /**
    487  * Print a representation of a module to a file. The ErrorMessage needs to be
    488  * disposed with LLVMDisposeMessage. Returns 0 on success, 1 otherwise.
    489  *
    490  * @see Module::print()
    491  */
    492 LLVMBool LLVMPrintModuleToFile(LLVMModuleRef M, const char *Filename,
    493                                char **ErrorMessage);
    494 
    495 /**
    496  * Set inline assembly for a module.
    497  *
    498  * @see Module::setModuleInlineAsm()
    499  */
    500 void LLVMSetModuleInlineAsm(LLVMModuleRef M, const char *Asm);
    501 
    502 /**
    503  * Obtain the context to which this module is associated.
    504  *
    505  * @see Module::getContext()
    506  */
    507 LLVMContextRef LLVMGetModuleContext(LLVMModuleRef M);
    508 
    509 /**
    510  * Obtain a Type from a module by its registered name.
    511  */
    512 LLVMTypeRef LLVMGetTypeByName(LLVMModuleRef M, const char *Name);
    513 
    514 /**
    515  * Obtain the number of operands for named metadata in a module.
    516  *
    517  * @see llvm::Module::getNamedMetadata()
    518  */
    519 unsigned LLVMGetNamedMetadataNumOperands(LLVMModuleRef M, const char* name);
    520 
    521 /**
    522  * Obtain the named metadata operands for a module.
    523  *
    524  * The passed LLVMValueRef pointer should refer to an array of
    525  * LLVMValueRef at least LLVMGetNamedMetadataNumOperands long. This
    526  * array will be populated with the LLVMValueRef instances. Each
    527  * instance corresponds to a llvm::MDNode.
    528  *
    529  * @see llvm::Module::getNamedMetadata()
    530  * @see llvm::MDNode::getOperand()
    531  */
    532 void LLVMGetNamedMetadataOperands(LLVMModuleRef M, const char* name, LLVMValueRef *Dest);
    533 
    534 /**
    535  * Add an operand to named metadata.
    536  *
    537  * @see llvm::Module::getNamedMetadata()
    538  * @see llvm::MDNode::addOperand()
    539  */
    540 void LLVMAddNamedMetadataOperand(LLVMModuleRef M, const char* name,
    541                                  LLVMValueRef Val);
    542 
    543 /**
    544  * Add a function to a module under a specified name.
    545  *
    546  * @see llvm::Function::Create()
    547  */
    548 LLVMValueRef LLVMAddFunction(LLVMModuleRef M, const char *Name,
    549                              LLVMTypeRef FunctionTy);
    550 
    551 /**
    552  * Obtain a Function value from a Module by its name.
    553  *
    554  * The returned value corresponds to a llvm::Function value.
    555  *
    556  * @see llvm::Module::getFunction()
    557  */
    558 LLVMValueRef LLVMGetNamedFunction(LLVMModuleRef M, const char *Name);
    559 
    560 /**
    561  * Obtain an iterator to the first Function in a Module.
    562  *
    563  * @see llvm::Module::begin()
    564  */
    565 LLVMValueRef LLVMGetFirstFunction(LLVMModuleRef M);
    566 
    567 /**
    568  * Obtain an iterator to the last Function in a Module.
    569  *
    570  * @see llvm::Module::end()
    571  */
    572 LLVMValueRef LLVMGetLastFunction(LLVMModuleRef M);
    573 
    574 /**
    575  * Advance a Function iterator to the next Function.
    576  *
    577  * Returns NULL if the iterator was already at the end and there are no more
    578  * functions.
    579  */
    580 LLVMValueRef LLVMGetNextFunction(LLVMValueRef Fn);
    581 
    582 /**
    583  * Decrement a Function iterator to the previous Function.
    584  *
    585  * Returns NULL if the iterator was already at the beginning and there are
    586  * no previous functions.
    587  */
    588 LLVMValueRef LLVMGetPreviousFunction(LLVMValueRef Fn);
    589 
    590 /**
    591  * @}
    592  */
    593 
    594 /**
    595  * @defgroup LLVMCCoreType Types
    596  *
    597  * Types represent the type of a value.
    598  *
    599  * Types are associated with a context instance. The context internally
    600  * deduplicates types so there is only 1 instance of a specific type
    601  * alive at a time. In other words, a unique type is shared among all
    602  * consumers within a context.
    603  *
    604  * A Type in the C API corresponds to llvm::Type.
    605  *
    606  * Types have the following hierarchy:
    607  *
    608  *   types:
    609  *     integer type
    610  *     real type
    611  *     function type
    612  *     sequence types:
    613  *       array type
    614  *       pointer type
    615  *       vector type
    616  *     void type
    617  *     label type
    618  *     opaque type
    619  *
    620  * @{
    621  */
    622 
    623 /**
    624  * Obtain the enumerated type of a Type instance.
    625  *
    626  * @see llvm::Type:getTypeID()
    627  */
    628 LLVMTypeKind LLVMGetTypeKind(LLVMTypeRef Ty);
    629 
    630 /**
    631  * Whether the type has a known size.
    632  *
    633  * Things that don't have a size are abstract types, labels, and void.a
    634  *
    635  * @see llvm::Type::isSized()
    636  */
    637 LLVMBool LLVMTypeIsSized(LLVMTypeRef Ty);
    638 
    639 /**
    640  * Obtain the context to which this type instance is associated.
    641  *
    642  * @see llvm::Type::getContext()
    643  */
    644 LLVMContextRef LLVMGetTypeContext(LLVMTypeRef Ty);
    645 
    646 /**
    647  * @defgroup LLVMCCoreTypeInt Integer Types
    648  *
    649  * Functions in this section operate on integer types.
    650  *
    651  * @{
    652  */
    653 
    654 /**
    655  * Obtain an integer type from a context with specified bit width.
    656  */
    657 LLVMTypeRef LLVMInt1TypeInContext(LLVMContextRef C);
    658 LLVMTypeRef LLVMInt8TypeInContext(LLVMContextRef C);
    659 LLVMTypeRef LLVMInt16TypeInContext(LLVMContextRef C);
    660 LLVMTypeRef LLVMInt32TypeInContext(LLVMContextRef C);
    661 LLVMTypeRef LLVMInt64TypeInContext(LLVMContextRef C);
    662 LLVMTypeRef LLVMIntTypeInContext(LLVMContextRef C, unsigned NumBits);
    663 
    664 /**
    665  * Obtain an integer type from the global context with a specified bit
    666  * width.
    667  */
    668 LLVMTypeRef LLVMInt1Type(void);
    669 LLVMTypeRef LLVMInt8Type(void);
    670 LLVMTypeRef LLVMInt16Type(void);
    671 LLVMTypeRef LLVMInt32Type(void);
    672 LLVMTypeRef LLVMInt64Type(void);
    673 LLVMTypeRef LLVMIntType(unsigned NumBits);
    674 unsigned LLVMGetIntTypeWidth(LLVMTypeRef IntegerTy);
    675 
    676 /**
    677  * @}
    678  */
    679 
    680 /**
    681  * @defgroup LLVMCCoreTypeFloat Floating Point Types
    682  *
    683  * @{
    684  */
    685 
    686 /**
    687  * Obtain a 16-bit floating point type from a context.
    688  */
    689 LLVMTypeRef LLVMHalfTypeInContext(LLVMContextRef C);
    690 
    691 /**
    692  * Obtain a 32-bit floating point type from a context.
    693  */
    694 LLVMTypeRef LLVMFloatTypeInContext(LLVMContextRef C);
    695 
    696 /**
    697  * Obtain a 64-bit floating point type from a context.
    698  */
    699 LLVMTypeRef LLVMDoubleTypeInContext(LLVMContextRef C);
    700 
    701 /**
    702  * Obtain a 80-bit floating point type (X87) from a context.
    703  */
    704 LLVMTypeRef LLVMX86FP80TypeInContext(LLVMContextRef C);
    705 
    706 /**
    707  * Obtain a 128-bit floating point type (112-bit mantissa) from a
    708  * context.
    709  */
    710 LLVMTypeRef LLVMFP128TypeInContext(LLVMContextRef C);
    711 
    712 /**
    713  * Obtain a 128-bit floating point type (two 64-bits) from a context.
    714  */
    715 LLVMTypeRef LLVMPPCFP128TypeInContext(LLVMContextRef C);
    716 
    717 /**
    718  * Obtain a floating point type from the global context.
    719  *
    720  * These map to the functions in this group of the same name.
    721  */
    722 LLVMTypeRef LLVMHalfType(void);
    723 LLVMTypeRef LLVMFloatType(void);
    724 LLVMTypeRef LLVMDoubleType(void);
    725 LLVMTypeRef LLVMX86FP80Type(void);
    726 LLVMTypeRef LLVMFP128Type(void);
    727 LLVMTypeRef LLVMPPCFP128Type(void);
    728 
    729 /**
    730  * @}
    731  */
    732 
    733 /**
    734  * @defgroup LLVMCCoreTypeFunction Function Types
    735  *
    736  * @{
    737  */
    738 
    739 /**
    740  * Obtain a function type consisting of a specified signature.
    741  *
    742  * The function is defined as a tuple of a return Type, a list of
    743  * parameter types, and whether the function is variadic.
    744  */
    745 LLVMTypeRef LLVMFunctionType(LLVMTypeRef ReturnType,
    746                              LLVMTypeRef *ParamTypes, unsigned ParamCount,
    747                              LLVMBool IsVarArg);
    748 
    749 /**
    750  * Returns whether a function type is variadic.
    751  */
    752 LLVMBool LLVMIsFunctionVarArg(LLVMTypeRef FunctionTy);
    753 
    754 /**
    755  * Obtain the Type this function Type returns.
    756  */
    757 LLVMTypeRef LLVMGetReturnType(LLVMTypeRef FunctionTy);
    758 
    759 /**
    760  * Obtain the number of parameters this function accepts.
    761  */
    762 unsigned LLVMCountParamTypes(LLVMTypeRef FunctionTy);
    763 
    764 /**
    765  * Obtain the types of a function's parameters.
    766  *
    767  * The Dest parameter should point to a pre-allocated array of
    768  * LLVMTypeRef at least LLVMCountParamTypes() large. On return, the
    769  * first LLVMCountParamTypes() entries in the array will be populated
    770  * with LLVMTypeRef instances.
    771  *
    772  * @param FunctionTy The function type to operate on.
    773  * @param Dest Memory address of an array to be filled with result.
    774  */
    775 void LLVMGetParamTypes(LLVMTypeRef FunctionTy, LLVMTypeRef *Dest);
    776 
    777 /**
    778  * @}
    779  */
    780 
    781 /**
    782  * @defgroup LLVMCCoreTypeStruct Structure Types
    783  *
    784  * These functions relate to LLVMTypeRef instances.
    785  *
    786  * @see llvm::StructType
    787  *
    788  * @{
    789  */
    790 
    791 /**
    792  * Create a new structure type in a context.
    793  *
    794  * A structure is specified by a list of inner elements/types and
    795  * whether these can be packed together.
    796  *
    797  * @see llvm::StructType::create()
    798  */
    799 LLVMTypeRef LLVMStructTypeInContext(LLVMContextRef C, LLVMTypeRef *ElementTypes,
    800                                     unsigned ElementCount, LLVMBool Packed);
    801 
    802 /**
    803  * Create a new structure type in the global context.
    804  *
    805  * @see llvm::StructType::create()
    806  */
    807 LLVMTypeRef LLVMStructType(LLVMTypeRef *ElementTypes, unsigned ElementCount,
    808                            LLVMBool Packed);
    809 
    810 /**
    811  * Create an empty structure in a context having a specified name.
    812  *
    813  * @see llvm::StructType::create()
    814  */
    815 LLVMTypeRef LLVMStructCreateNamed(LLVMContextRef C, const char *Name);
    816 
    817 /**
    818  * Obtain the name of a structure.
    819  *
    820  * @see llvm::StructType::getName()
    821  */
    822 const char *LLVMGetStructName(LLVMTypeRef Ty);
    823 
    824 /**
    825  * Set the contents of a structure type.
    826  *
    827  * @see llvm::StructType::setBody()
    828  */
    829 void LLVMStructSetBody(LLVMTypeRef StructTy, LLVMTypeRef *ElementTypes,
    830                        unsigned ElementCount, LLVMBool Packed);
    831 
    832 /**
    833  * Get the number of elements defined inside the structure.
    834  *
    835  * @see llvm::StructType::getNumElements()
    836  */
    837 unsigned LLVMCountStructElementTypes(LLVMTypeRef StructTy);
    838 
    839 /**
    840  * Get the elements within a structure.
    841  *
    842  * The function is passed the address of a pre-allocated array of
    843  * LLVMTypeRef at least LLVMCountStructElementTypes() long. After
    844  * invocation, this array will be populated with the structure's
    845  * elements. The objects in the destination array will have a lifetime
    846  * of the structure type itself, which is the lifetime of the context it
    847  * is contained in.
    848  */
    849 void LLVMGetStructElementTypes(LLVMTypeRef StructTy, LLVMTypeRef *Dest);
    850 
    851 /**
    852  * Determine whether a structure is packed.
    853  *
    854  * @see llvm::StructType::isPacked()
    855  */
    856 LLVMBool LLVMIsPackedStruct(LLVMTypeRef StructTy);
    857 
    858 /**
    859  * Determine whether a structure is opaque.
    860  *
    861  * @see llvm::StructType::isOpaque()
    862  */
    863 LLVMBool LLVMIsOpaqueStruct(LLVMTypeRef StructTy);
    864 
    865 /**
    866  * @}
    867  */
    868 
    869 
    870 /**
    871  * @defgroup LLVMCCoreTypeSequential Sequential Types
    872  *
    873  * Sequential types represents "arrays" of types. This is a super class
    874  * for array, vector, and pointer types.
    875  *
    876  * @{
    877  */
    878 
    879 /**
    880  * Obtain the type of elements within a sequential type.
    881  *
    882  * This works on array, vector, and pointer types.
    883  *
    884  * @see llvm::SequentialType::getElementType()
    885  */
    886 LLVMTypeRef LLVMGetElementType(LLVMTypeRef Ty);
    887 
    888 /**
    889  * Create a fixed size array type that refers to a specific type.
    890  *
    891  * The created type will exist in the context that its element type
    892  * exists in.
    893  *
    894  * @see llvm::ArrayType::get()
    895  */
    896 LLVMTypeRef LLVMArrayType(LLVMTypeRef ElementType, unsigned ElementCount);
    897 
    898 /**
    899  * Obtain the length of an array type.
    900  *
    901  * This only works on types that represent arrays.
    902  *
    903  * @see llvm::ArrayType::getNumElements()
    904  */
    905 unsigned LLVMGetArrayLength(LLVMTypeRef ArrayTy);
    906 
    907 /**
    908  * Create a pointer type that points to a defined type.
    909  *
    910  * The created type will exist in the context that its pointee type
    911  * exists in.
    912  *
    913  * @see llvm::PointerType::get()
    914  */
    915 LLVMTypeRef LLVMPointerType(LLVMTypeRef ElementType, unsigned AddressSpace);
    916 
    917 /**
    918  * Obtain the address space of a pointer type.
    919  *
    920  * This only works on types that represent pointers.
    921  *
    922  * @see llvm::PointerType::getAddressSpace()
    923  */
    924 unsigned LLVMGetPointerAddressSpace(LLVMTypeRef PointerTy);
    925 
    926 /**
    927  * Create a vector type that contains a defined type and has a specific
    928  * number of elements.
    929  *
    930  * The created type will exist in the context thats its element type
    931  * exists in.
    932  *
    933  * @see llvm::VectorType::get()
    934  */
    935 LLVMTypeRef LLVMVectorType(LLVMTypeRef ElementType, unsigned ElementCount);
    936 
    937 /**
    938  * Obtain the number of elements in a vector type.
    939  *
    940  * This only works on types that represent vectors.
    941  *
    942  * @see llvm::VectorType::getNumElements()
    943  */
    944 unsigned LLVMGetVectorSize(LLVMTypeRef VectorTy);
    945 
    946 /**
    947  * @}
    948  */
    949 
    950 /**
    951  * @defgroup LLVMCCoreTypeOther Other Types
    952  *
    953  * @{
    954  */
    955 
    956 /**
    957  * Create a void type in a context.
    958  */
    959 LLVMTypeRef LLVMVoidTypeInContext(LLVMContextRef C);
    960 
    961 /**
    962  * Create a label type in a context.
    963  */
    964 LLVMTypeRef LLVMLabelTypeInContext(LLVMContextRef C);
    965 
    966 /**
    967  * Create a X86 MMX type in a context.
    968  */
    969 LLVMTypeRef LLVMX86MMXTypeInContext(LLVMContextRef C);
    970 
    971 /**
    972  * These are similar to the above functions except they operate on the
    973  * global context.
    974  */
    975 LLVMTypeRef LLVMVoidType(void);
    976 LLVMTypeRef LLVMLabelType(void);
    977 LLVMTypeRef LLVMX86MMXType(void);
    978 
    979 /**
    980  * @}
    981  */
    982 
    983 /**
    984  * @}
    985  */
    986 
    987 /**
    988  * @defgroup LLVMCCoreValues Values
    989  *
    990  * The bulk of LLVM's object model consists of values, which comprise a very
    991  * rich type hierarchy.
    992  *
    993  * LLVMValueRef essentially represents llvm::Value. There is a rich
    994  * hierarchy of classes within this type. Depending on the instance
    995  * obtained, not all APIs are available.
    996  *
    997  * Callers can determine the type of a LLVMValueRef by calling the
    998  * LLVMIsA* family of functions (e.g. LLVMIsAArgument()). These
    999  * functions are defined by a macro, so it isn't obvious which are
   1000  * available by looking at the Doxygen source code. Instead, look at the
   1001  * source definition of LLVM_FOR_EACH_VALUE_SUBCLASS and note the list
   1002  * of value names given. These value names also correspond to classes in
   1003  * the llvm::Value hierarchy.
   1004  *
   1005  * @{
   1006  */
   1007 
   1008 #define LLVM_FOR_EACH_VALUE_SUBCLASS(macro) \
   1009   macro(Argument)                           \
   1010   macro(BasicBlock)                         \
   1011   macro(InlineAsm)                          \
   1012   macro(MDNode)                             \
   1013   macro(MDString)                           \
   1014   macro(User)                               \
   1015     macro(Constant)                         \
   1016       macro(BlockAddress)                   \
   1017       macro(ConstantAggregateZero)          \
   1018       macro(ConstantArray)                  \
   1019       macro(ConstantExpr)                   \
   1020       macro(ConstantFP)                     \
   1021       macro(ConstantInt)                    \
   1022       macro(ConstantPointerNull)            \
   1023       macro(ConstantStruct)                 \
   1024       macro(ConstantVector)                 \
   1025       macro(GlobalValue)                    \
   1026         macro(Function)                     \
   1027         macro(GlobalAlias)                  \
   1028         macro(GlobalVariable)               \
   1029       macro(UndefValue)                     \
   1030     macro(Instruction)                      \
   1031       macro(BinaryOperator)                 \
   1032       macro(CallInst)                       \
   1033         macro(IntrinsicInst)                \
   1034           macro(DbgInfoIntrinsic)           \
   1035             macro(DbgDeclareInst)           \
   1036           macro(MemIntrinsic)               \
   1037             macro(MemCpyInst)               \
   1038             macro(MemMoveInst)              \
   1039             macro(MemSetInst)               \
   1040       macro(CmpInst)                        \
   1041         macro(FCmpInst)                     \
   1042         macro(ICmpInst)                     \
   1043       macro(ExtractElementInst)             \
   1044       macro(GetElementPtrInst)              \
   1045       macro(InsertElementInst)              \
   1046       macro(InsertValueInst)                \
   1047       macro(LandingPadInst)                 \
   1048       macro(PHINode)                        \
   1049       macro(SelectInst)                     \
   1050       macro(ShuffleVectorInst)              \
   1051       macro(StoreInst)                      \
   1052       macro(TerminatorInst)                 \
   1053         macro(BranchInst)                   \
   1054         macro(IndirectBrInst)               \
   1055         macro(InvokeInst)                   \
   1056         macro(ReturnInst)                   \
   1057         macro(SwitchInst)                   \
   1058         macro(UnreachableInst)              \
   1059         macro(ResumeInst)                   \
   1060     macro(UnaryInstruction)                 \
   1061       macro(AllocaInst)                     \
   1062       macro(CastInst)                       \
   1063         macro(BitCastInst)                  \
   1064         macro(FPExtInst)                    \
   1065         macro(FPToSIInst)                   \
   1066         macro(FPToUIInst)                   \
   1067         macro(FPTruncInst)                  \
   1068         macro(IntToPtrInst)                 \
   1069         macro(PtrToIntInst)                 \
   1070         macro(SExtInst)                     \
   1071         macro(SIToFPInst)                   \
   1072         macro(TruncInst)                    \
   1073         macro(UIToFPInst)                   \
   1074         macro(ZExtInst)                     \
   1075       macro(ExtractValueInst)               \
   1076       macro(LoadInst)                       \
   1077       macro(VAArgInst)
   1078 
   1079 /**
   1080  * @defgroup LLVMCCoreValueGeneral General APIs
   1081  *
   1082  * Functions in this section work on all LLVMValueRef instances,
   1083  * regardless of their sub-type. They correspond to functions available
   1084  * on llvm::Value.
   1085  *
   1086  * @{
   1087  */
   1088 
   1089 /**
   1090  * Obtain the type of a value.
   1091  *
   1092  * @see llvm::Value::getType()
   1093  */
   1094 LLVMTypeRef LLVMTypeOf(LLVMValueRef Val);
   1095 
   1096 /**
   1097  * Obtain the string name of a value.
   1098  *
   1099  * @see llvm::Value::getName()
   1100  */
   1101 const char *LLVMGetValueName(LLVMValueRef Val);
   1102 
   1103 /**
   1104  * Set the string name of a value.
   1105  *
   1106  * @see llvm::Value::setName()
   1107  */
   1108 void LLVMSetValueName(LLVMValueRef Val, const char *Name);
   1109 
   1110 /**
   1111  * Dump a representation of a value to stderr.
   1112  *
   1113  * @see llvm::Value::dump()
   1114  */
   1115 void LLVMDumpValue(LLVMValueRef Val);
   1116 
   1117 /**
   1118  * Replace all uses of a value with another one.
   1119  *
   1120  * @see llvm::Value::replaceAllUsesWith()
   1121  */
   1122 void LLVMReplaceAllUsesWith(LLVMValueRef OldVal, LLVMValueRef NewVal);
   1123 
   1124 /**
   1125  * Determine whether the specified constant instance is constant.
   1126  */
   1127 LLVMBool LLVMIsConstant(LLVMValueRef Val);
   1128 
   1129 /**
   1130  * Determine whether a value instance is undefined.
   1131  */
   1132 LLVMBool LLVMIsUndef(LLVMValueRef Val);
   1133 
   1134 /**
   1135  * Convert value instances between types.
   1136  *
   1137  * Internally, a LLVMValueRef is "pinned" to a specific type. This
   1138  * series of functions allows you to cast an instance to a specific
   1139  * type.
   1140  *
   1141  * If the cast is not valid for the specified type, NULL is returned.
   1142  *
   1143  * @see llvm::dyn_cast_or_null<>
   1144  */
   1145 #define LLVM_DECLARE_VALUE_CAST(name) \
   1146   LLVMValueRef LLVMIsA##name(LLVMValueRef Val);
   1147 LLVM_FOR_EACH_VALUE_SUBCLASS(LLVM_DECLARE_VALUE_CAST)
   1148 
   1149 /**
   1150  * @}
   1151  */
   1152 
   1153 /**
   1154  * @defgroup LLVMCCoreValueUses Usage
   1155  *
   1156  * This module defines functions that allow you to inspect the uses of a
   1157  * LLVMValueRef.
   1158  *
   1159  * It is possible to obtain a LLVMUseRef for any LLVMValueRef instance.
   1160  * Each LLVMUseRef (which corresponds to a llvm::Use instance) holds a
   1161  * llvm::User and llvm::Value.
   1162  *
   1163  * @{
   1164  */
   1165 
   1166 /**
   1167  * Obtain the first use of a value.
   1168  *
   1169  * Uses are obtained in an iterator fashion. First, call this function
   1170  * to obtain a reference to the first use. Then, call LLVMGetNextUse()
   1171  * on that instance and all subsequently obtained instances until
   1172  * LLVMGetNextUse() returns NULL.
   1173  *
   1174  * @see llvm::Value::use_begin()
   1175  */
   1176 LLVMUseRef LLVMGetFirstUse(LLVMValueRef Val);
   1177 
   1178 /**
   1179  * Obtain the next use of a value.
   1180  *
   1181  * This effectively advances the iterator. It returns NULL if you are on
   1182  * the final use and no more are available.
   1183  */
   1184 LLVMUseRef LLVMGetNextUse(LLVMUseRef U);
   1185 
   1186 /**
   1187  * Obtain the user value for a user.
   1188  *
   1189  * The returned value corresponds to a llvm::User type.
   1190  *
   1191  * @see llvm::Use::getUser()
   1192  */
   1193 LLVMValueRef LLVMGetUser(LLVMUseRef U);
   1194 
   1195 /**
   1196  * Obtain the value this use corresponds to.
   1197  *
   1198  * @see llvm::Use::get().
   1199  */
   1200 LLVMValueRef LLVMGetUsedValue(LLVMUseRef U);
   1201 
   1202 /**
   1203  * @}
   1204  */
   1205 
   1206 /**
   1207  * @defgroup LLVMCCoreValueUser User value
   1208  *
   1209  * Function in this group pertain to LLVMValueRef instances that descent
   1210  * from llvm::User. This includes constants, instructions, and
   1211  * operators.
   1212  *
   1213  * @{
   1214  */
   1215 
   1216 /**
   1217  * Obtain an operand at a specific index in a llvm::User value.
   1218  *
   1219  * @see llvm::User::getOperand()
   1220  */
   1221 LLVMValueRef LLVMGetOperand(LLVMValueRef Val, unsigned Index);
   1222 
   1223 /**
   1224  * Set an operand at a specific index in a llvm::User value.
   1225  *
   1226  * @see llvm::User::setOperand()
   1227  */
   1228 void LLVMSetOperand(LLVMValueRef User, unsigned Index, LLVMValueRef Val);
   1229 
   1230 /**
   1231  * Obtain the number of operands in a llvm::User value.
   1232  *
   1233  * @see llvm::User::getNumOperands()
   1234  */
   1235 int LLVMGetNumOperands(LLVMValueRef Val);
   1236 
   1237 /**
   1238  * @}
   1239  */
   1240 
   1241 /**
   1242  * @defgroup LLVMCCoreValueConstant Constants
   1243  *
   1244  * This section contains APIs for interacting with LLVMValueRef that
   1245  * correspond to llvm::Constant instances.
   1246  *
   1247  * These functions will work for any LLVMValueRef in the llvm::Constant
   1248  * class hierarchy.
   1249  *
   1250  * @{
   1251  */
   1252 
   1253 /**
   1254  * Obtain a constant value referring to the null instance of a type.
   1255  *
   1256  * @see llvm::Constant::getNullValue()
   1257  */
   1258 LLVMValueRef LLVMConstNull(LLVMTypeRef Ty); /* all zeroes */
   1259 
   1260 /**
   1261  * Obtain a constant value referring to the instance of a type
   1262  * consisting of all ones.
   1263  *
   1264  * This is only valid for integer types.
   1265  *
   1266  * @see llvm::Constant::getAllOnesValue()
   1267  */
   1268 LLVMValueRef LLVMConstAllOnes(LLVMTypeRef Ty);
   1269 
   1270 /**
   1271  * Obtain a constant value referring to an undefined value of a type.
   1272  *
   1273  * @see llvm::UndefValue::get()
   1274  */
   1275 LLVMValueRef LLVMGetUndef(LLVMTypeRef Ty);
   1276 
   1277 /**
   1278  * Determine whether a value instance is null.
   1279  *
   1280  * @see llvm::Constant::isNullValue()
   1281  */
   1282 LLVMBool LLVMIsNull(LLVMValueRef Val);
   1283 
   1284 /**
   1285  * Obtain a constant that is a constant pointer pointing to NULL for a
   1286  * specified type.
   1287  */
   1288 LLVMValueRef LLVMConstPointerNull(LLVMTypeRef Ty);
   1289 
   1290 /**
   1291  * @defgroup LLVMCCoreValueConstantScalar Scalar constants
   1292  *
   1293  * Functions in this group model LLVMValueRef instances that correspond
   1294  * to constants referring to scalar types.
   1295  *
   1296  * For integer types, the LLVMTypeRef parameter should correspond to a
   1297  * llvm::IntegerType instance and the returned LLVMValueRef will
   1298  * correspond to a llvm::ConstantInt.
   1299  *
   1300  * For floating point types, the LLVMTypeRef returned corresponds to a
   1301  * llvm::ConstantFP.
   1302  *
   1303  * @{
   1304  */
   1305 
   1306 /**
   1307  * Obtain a constant value for an integer type.
   1308  *
   1309  * The returned value corresponds to a llvm::ConstantInt.
   1310  *
   1311  * @see llvm::ConstantInt::get()
   1312  *
   1313  * @param IntTy Integer type to obtain value of.
   1314  * @param N The value the returned instance should refer to.
   1315  * @param SignExtend Whether to sign extend the produced value.
   1316  */
   1317 LLVMValueRef LLVMConstInt(LLVMTypeRef IntTy, unsigned long long N,
   1318                           LLVMBool SignExtend);
   1319 
   1320 /**
   1321  * Obtain a constant value for an integer of arbitrary precision.
   1322  *
   1323  * @see llvm::ConstantInt::get()
   1324  */
   1325 LLVMValueRef LLVMConstIntOfArbitraryPrecision(LLVMTypeRef IntTy,
   1326                                               unsigned NumWords,
   1327                                               const uint64_t Words[]);
   1328 
   1329 /**
   1330  * Obtain a constant value for an integer parsed from a string.
   1331  *
   1332  * A similar API, LLVMConstIntOfStringAndSize is also available. If the
   1333  * string's length is available, it is preferred to call that function
   1334  * instead.
   1335  *
   1336  * @see llvm::ConstantInt::get()
   1337  */
   1338 LLVMValueRef LLVMConstIntOfString(LLVMTypeRef IntTy, const char *Text,
   1339                                   uint8_t Radix);
   1340 
   1341 /**
   1342  * Obtain a constant value for an integer parsed from a string with
   1343  * specified length.
   1344  *
   1345  * @see llvm::ConstantInt::get()
   1346  */
   1347 LLVMValueRef LLVMConstIntOfStringAndSize(LLVMTypeRef IntTy, const char *Text,
   1348                                          unsigned SLen, uint8_t Radix);
   1349 
   1350 /**
   1351  * Obtain a constant value referring to a double floating point value.
   1352  */
   1353 LLVMValueRef LLVMConstReal(LLVMTypeRef RealTy, double N);
   1354 
   1355 /**
   1356  * Obtain a constant for a floating point value parsed from a string.
   1357  *
   1358  * A similar API, LLVMConstRealOfStringAndSize is also available. It
   1359  * should be used if the input string's length is known.
   1360  */
   1361 LLVMValueRef LLVMConstRealOfString(LLVMTypeRef RealTy, const char *Text);
   1362 
   1363 /**
   1364  * Obtain a constant for a floating point value parsed from a string.
   1365  */
   1366 LLVMValueRef LLVMConstRealOfStringAndSize(LLVMTypeRef RealTy, const char *Text,
   1367                                           unsigned SLen);
   1368 
   1369 /**
   1370  * Obtain the zero extended value for an integer constant value.
   1371  *
   1372  * @see llvm::ConstantInt::getZExtValue()
   1373  */
   1374 unsigned long long LLVMConstIntGetZExtValue(LLVMValueRef ConstantVal);
   1375 
   1376 /**
   1377  * Obtain the sign extended value for an integer constant value.
   1378  *
   1379  * @see llvm::ConstantInt::getSExtValue()
   1380  */
   1381 long long LLVMConstIntGetSExtValue(LLVMValueRef ConstantVal);
   1382 
   1383 /**
   1384  * @}
   1385  */
   1386 
   1387 /**
   1388  * @defgroup LLVMCCoreValueConstantComposite Composite Constants
   1389  *
   1390  * Functions in this group operate on composite constants.
   1391  *
   1392  * @{
   1393  */
   1394 
   1395 /**
   1396  * Create a ConstantDataSequential and initialize it with a string.
   1397  *
   1398  * @see llvm::ConstantDataArray::getString()
   1399  */
   1400 LLVMValueRef LLVMConstStringInContext(LLVMContextRef C, const char *Str,
   1401                                       unsigned Length, LLVMBool DontNullTerminate);
   1402 
   1403 /**
   1404  * Create a ConstantDataSequential with string content in the global context.
   1405  *
   1406  * This is the same as LLVMConstStringInContext except it operates on the
   1407  * global context.
   1408  *
   1409  * @see LLVMConstStringInContext()
   1410  * @see llvm::ConstantDataArray::getString()
   1411  */
   1412 LLVMValueRef LLVMConstString(const char *Str, unsigned Length,
   1413                              LLVMBool DontNullTerminate);
   1414 
   1415 /**
   1416  * Create an anonymous ConstantStruct with the specified values.
   1417  *
   1418  * @see llvm::ConstantStruct::getAnon()
   1419  */
   1420 LLVMValueRef LLVMConstStructInContext(LLVMContextRef C,
   1421                                       LLVMValueRef *ConstantVals,
   1422                                       unsigned Count, LLVMBool Packed);
   1423 
   1424 /**
   1425  * Create a ConstantStruct in the global Context.
   1426  *
   1427  * This is the same as LLVMConstStructInContext except it operates on the
   1428  * global Context.
   1429  *
   1430  * @see LLVMConstStructInContext()
   1431  */
   1432 LLVMValueRef LLVMConstStruct(LLVMValueRef *ConstantVals, unsigned Count,
   1433                              LLVMBool Packed);
   1434 
   1435 /**
   1436  * Create a ConstantArray from values.
   1437  *
   1438  * @see llvm::ConstantArray::get()
   1439  */
   1440 LLVMValueRef LLVMConstArray(LLVMTypeRef ElementTy,
   1441                             LLVMValueRef *ConstantVals, unsigned Length);
   1442 
   1443 /**
   1444  * Create a non-anonymous ConstantStruct from values.
   1445  *
   1446  * @see llvm::ConstantStruct::get()
   1447  */
   1448 LLVMValueRef LLVMConstNamedStruct(LLVMTypeRef StructTy,
   1449                                   LLVMValueRef *ConstantVals,
   1450                                   unsigned Count);
   1451 
   1452 /**
   1453  * Create a ConstantVector from values.
   1454  *
   1455  * @see llvm::ConstantVector::get()
   1456  */
   1457 LLVMValueRef LLVMConstVector(LLVMValueRef *ScalarConstantVals, unsigned Size);
   1458 
   1459 /**
   1460  * @}
   1461  */
   1462 
   1463 /**
   1464  * @defgroup LLVMCCoreValueConstantExpressions Constant Expressions
   1465  *
   1466  * Functions in this group correspond to APIs on llvm::ConstantExpr.
   1467  *
   1468  * @see llvm::ConstantExpr.
   1469  *
   1470  * @{
   1471  */
   1472 LLVMOpcode LLVMGetConstOpcode(LLVMValueRef ConstantVal);
   1473 LLVMValueRef LLVMAlignOf(LLVMTypeRef Ty);
   1474 LLVMValueRef LLVMSizeOf(LLVMTypeRef Ty);
   1475 LLVMValueRef LLVMConstNeg(LLVMValueRef ConstantVal);
   1476 LLVMValueRef LLVMConstNSWNeg(LLVMValueRef ConstantVal);
   1477 LLVMValueRef LLVMConstNUWNeg(LLVMValueRef ConstantVal);
   1478 LLVMValueRef LLVMConstFNeg(LLVMValueRef ConstantVal);
   1479 LLVMValueRef LLVMConstNot(LLVMValueRef ConstantVal);
   1480 LLVMValueRef LLVMConstAdd(LLVMValueRef LHSConstant, LLVMValueRef RHSConstant);
   1481 LLVMValueRef LLVMConstNSWAdd(LLVMValueRef LHSConstant, LLVMValueRef RHSConstant);
   1482 LLVMValueRef LLVMConstNUWAdd(LLVMValueRef LHSConstant, LLVMValueRef RHSConstant);
   1483 LLVMValueRef LLVMConstFAdd(LLVMValueRef LHSConstant, LLVMValueRef RHSConstant);
   1484 LLVMValueRef LLVMConstSub(LLVMValueRef LHSConstant, LLVMValueRef RHSConstant);
   1485 LLVMValueRef LLVMConstNSWSub(LLVMValueRef LHSConstant, LLVMValueRef RHSConstant);
   1486 LLVMValueRef LLVMConstNUWSub(LLVMValueRef LHSConstant, LLVMValueRef RHSConstant);
   1487 LLVMValueRef LLVMConstFSub(LLVMValueRef LHSConstant, LLVMValueRef RHSConstant);
   1488 LLVMValueRef LLVMConstMul(LLVMValueRef LHSConstant, LLVMValueRef RHSConstant);
   1489 LLVMValueRef LLVMConstNSWMul(LLVMValueRef LHSConstant, LLVMValueRef RHSConstant);
   1490 LLVMValueRef LLVMConstNUWMul(LLVMValueRef LHSConstant, LLVMValueRef RHSConstant);
   1491 LLVMValueRef LLVMConstFMul(LLVMValueRef LHSConstant, LLVMValueRef RHSConstant);
   1492 LLVMValueRef LLVMConstUDiv(LLVMValueRef LHSConstant, LLVMValueRef RHSConstant);
   1493 LLVMValueRef LLVMConstSDiv(LLVMValueRef LHSConstant, LLVMValueRef RHSConstant);
   1494 LLVMValueRef LLVMConstExactSDiv(LLVMValueRef LHSConstant, LLVMValueRef RHSConstant);
   1495 LLVMValueRef LLVMConstFDiv(LLVMValueRef LHSConstant, LLVMValueRef RHSConstant);
   1496 LLVMValueRef LLVMConstURem(LLVMValueRef LHSConstant, LLVMValueRef RHSConstant);
   1497 LLVMValueRef LLVMConstSRem(LLVMValueRef LHSConstant, LLVMValueRef RHSConstant);
   1498 LLVMValueRef LLVMConstFRem(LLVMValueRef LHSConstant, LLVMValueRef RHSConstant);
   1499 LLVMValueRef LLVMConstAnd(LLVMValueRef LHSConstant, LLVMValueRef RHSConstant);
   1500 LLVMValueRef LLVMConstOr(LLVMValueRef LHSConstant, LLVMValueRef RHSConstant);
   1501 LLVMValueRef LLVMConstXor(LLVMValueRef LHSConstant, LLVMValueRef RHSConstant);
   1502 LLVMValueRef LLVMConstICmp(LLVMIntPredicate Predicate,
   1503                            LLVMValueRef LHSConstant, LLVMValueRef RHSConstant);
   1504 LLVMValueRef LLVMConstFCmp(LLVMRealPredicate Predicate,
   1505                            LLVMValueRef LHSConstant, LLVMValueRef RHSConstant);
   1506 LLVMValueRef LLVMConstShl(LLVMValueRef LHSConstant, LLVMValueRef RHSConstant);
   1507 LLVMValueRef LLVMConstLShr(LLVMValueRef LHSConstant, LLVMValueRef RHSConstant);
   1508 LLVMValueRef LLVMConstAShr(LLVMValueRef LHSConstant, LLVMValueRef RHSConstant);
   1509 LLVMValueRef LLVMConstGEP(LLVMValueRef ConstantVal,
   1510                           LLVMValueRef *ConstantIndices, unsigned NumIndices);
   1511 LLVMValueRef LLVMConstInBoundsGEP(LLVMValueRef ConstantVal,
   1512                                   LLVMValueRef *ConstantIndices,
   1513                                   unsigned NumIndices);
   1514 LLVMValueRef LLVMConstTrunc(LLVMValueRef ConstantVal, LLVMTypeRef ToType);
   1515 LLVMValueRef LLVMConstSExt(LLVMValueRef ConstantVal, LLVMTypeRef ToType);
   1516 LLVMValueRef LLVMConstZExt(LLVMValueRef ConstantVal, LLVMTypeRef ToType);
   1517 LLVMValueRef LLVMConstFPTrunc(LLVMValueRef ConstantVal, LLVMTypeRef ToType);
   1518 LLVMValueRef LLVMConstFPExt(LLVMValueRef ConstantVal, LLVMTypeRef ToType);
   1519 LLVMValueRef LLVMConstUIToFP(LLVMValueRef ConstantVal, LLVMTypeRef ToType);
   1520 LLVMValueRef LLVMConstSIToFP(LLVMValueRef ConstantVal, LLVMTypeRef ToType);
   1521 LLVMValueRef LLVMConstFPToUI(LLVMValueRef ConstantVal, LLVMTypeRef ToType);
   1522 LLVMValueRef LLVMConstFPToSI(LLVMValueRef ConstantVal, LLVMTypeRef ToType);
   1523 LLVMValueRef LLVMConstPtrToInt(LLVMValueRef ConstantVal, LLVMTypeRef ToType);
   1524 LLVMValueRef LLVMConstIntToPtr(LLVMValueRef ConstantVal, LLVMTypeRef ToType);
   1525 LLVMValueRef LLVMConstBitCast(LLVMValueRef ConstantVal, LLVMTypeRef ToType);
   1526 LLVMValueRef LLVMConstZExtOrBitCast(LLVMValueRef ConstantVal,
   1527                                     LLVMTypeRef ToType);
   1528 LLVMValueRef LLVMConstSExtOrBitCast(LLVMValueRef ConstantVal,
   1529                                     LLVMTypeRef ToType);
   1530 LLVMValueRef LLVMConstTruncOrBitCast(LLVMValueRef ConstantVal,
   1531                                      LLVMTypeRef ToType);
   1532 LLVMValueRef LLVMConstPointerCast(LLVMValueRef ConstantVal,
   1533                                   LLVMTypeRef ToType);
   1534 LLVMValueRef LLVMConstIntCast(LLVMValueRef ConstantVal, LLVMTypeRef ToType,
   1535                               LLVMBool isSigned);
   1536 LLVMValueRef LLVMConstFPCast(LLVMValueRef ConstantVal, LLVMTypeRef ToType);
   1537 LLVMValueRef LLVMConstSelect(LLVMValueRef ConstantCondition,
   1538                              LLVMValueRef ConstantIfTrue,
   1539                              LLVMValueRef ConstantIfFalse);
   1540 LLVMValueRef LLVMConstExtractElement(LLVMValueRef VectorConstant,
   1541                                      LLVMValueRef IndexConstant);
   1542 LLVMValueRef LLVMConstInsertElement(LLVMValueRef VectorConstant,
   1543                                     LLVMValueRef ElementValueConstant,
   1544                                     LLVMValueRef IndexConstant);
   1545 LLVMValueRef LLVMConstShuffleVector(LLVMValueRef VectorAConstant,
   1546                                     LLVMValueRef VectorBConstant,
   1547                                     LLVMValueRef MaskConstant);
   1548 LLVMValueRef LLVMConstExtractValue(LLVMValueRef AggConstant, unsigned *IdxList,
   1549                                    unsigned NumIdx);
   1550 LLVMValueRef LLVMConstInsertValue(LLVMValueRef AggConstant,
   1551                                   LLVMValueRef ElementValueConstant,
   1552                                   unsigned *IdxList, unsigned NumIdx);
   1553 LLVMValueRef LLVMConstInlineAsm(LLVMTypeRef Ty,
   1554                                 const char *AsmString, const char *Constraints,
   1555                                 LLVMBool HasSideEffects, LLVMBool IsAlignStack);
   1556 LLVMValueRef LLVMBlockAddress(LLVMValueRef F, LLVMBasicBlockRef BB);
   1557 
   1558 /**
   1559  * @}
   1560  */
   1561 
   1562 /**
   1563  * @defgroup LLVMCCoreValueConstantGlobals Global Values
   1564  *
   1565  * This group contains functions that operate on global values. Functions in
   1566  * this group relate to functions in the llvm::GlobalValue class tree.
   1567  *
   1568  * @see llvm::GlobalValue
   1569  *
   1570  * @{
   1571  */
   1572 
   1573 LLVMModuleRef LLVMGetGlobalParent(LLVMValueRef Global);
   1574 LLVMBool LLVMIsDeclaration(LLVMValueRef Global);
   1575 LLVMLinkage LLVMGetLinkage(LLVMValueRef Global);
   1576 void LLVMSetLinkage(LLVMValueRef Global, LLVMLinkage Linkage);
   1577 const char *LLVMGetSection(LLVMValueRef Global);
   1578 void LLVMSetSection(LLVMValueRef Global, const char *Section);
   1579 LLVMVisibility LLVMGetVisibility(LLVMValueRef Global);
   1580 void LLVMSetVisibility(LLVMValueRef Global, LLVMVisibility Viz);
   1581 unsigned LLVMGetAlignment(LLVMValueRef Global);
   1582 void LLVMSetAlignment(LLVMValueRef Global, unsigned Bytes);
   1583 
   1584 /**
   1585  * @defgroup LLVMCoreValueConstantGlobalVariable Global Variables
   1586  *
   1587  * This group contains functions that operate on global variable values.
   1588  *
   1589  * @see llvm::GlobalVariable
   1590  *
   1591  * @{
   1592  */
   1593 LLVMValueRef LLVMAddGlobal(LLVMModuleRef M, LLVMTypeRef Ty, const char *Name);
   1594 LLVMValueRef LLVMAddGlobalInAddressSpace(LLVMModuleRef M, LLVMTypeRef Ty,
   1595                                          const char *Name,
   1596                                          unsigned AddressSpace);
   1597 LLVMValueRef LLVMGetNamedGlobal(LLVMModuleRef M, const char *Name);
   1598 LLVMValueRef LLVMGetFirstGlobal(LLVMModuleRef M);
   1599 LLVMValueRef LLVMGetLastGlobal(LLVMModuleRef M);
   1600 LLVMValueRef LLVMGetNextGlobal(LLVMValueRef GlobalVar);
   1601 LLVMValueRef LLVMGetPreviousGlobal(LLVMValueRef GlobalVar);
   1602 void LLVMDeleteGlobal(LLVMValueRef GlobalVar);
   1603 LLVMValueRef LLVMGetInitializer(LLVMValueRef GlobalVar);
   1604 void LLVMSetInitializer(LLVMValueRef GlobalVar, LLVMValueRef ConstantVal);
   1605 LLVMBool LLVMIsThreadLocal(LLVMValueRef GlobalVar);
   1606 void LLVMSetThreadLocal(LLVMValueRef GlobalVar, LLVMBool IsThreadLocal);
   1607 LLVMBool LLVMIsGlobalConstant(LLVMValueRef GlobalVar);
   1608 void LLVMSetGlobalConstant(LLVMValueRef GlobalVar, LLVMBool IsConstant);
   1609 
   1610 /**
   1611  * @}
   1612  */
   1613 
   1614 /**
   1615  * @defgroup LLVMCoreValueConstantGlobalAlias Global Aliases
   1616  *
   1617  * This group contains function that operate on global alias values.
   1618  *
   1619  * @see llvm::GlobalAlias
   1620  *
   1621  * @{
   1622  */
   1623 LLVMValueRef LLVMAddAlias(LLVMModuleRef M, LLVMTypeRef Ty, LLVMValueRef Aliasee,
   1624                           const char *Name);
   1625 
   1626 /**
   1627  * @}
   1628  */
   1629 
   1630 /**
   1631  * @defgroup LLVMCCoreValueFunction Function values
   1632  *
   1633  * Functions in this group operate on LLVMValueRef instances that
   1634  * correspond to llvm::Function instances.
   1635  *
   1636  * @see llvm::Function
   1637  *
   1638  * @{
   1639  */
   1640 
   1641 /**
   1642  * Remove a function from its containing module and deletes it.
   1643  *
   1644  * @see llvm::Function::eraseFromParent()
   1645  */
   1646 void LLVMDeleteFunction(LLVMValueRef Fn);
   1647 
   1648 /**
   1649  * Obtain the ID number from a function instance.
   1650  *
   1651  * @see llvm::Function::getIntrinsicID()
   1652  */
   1653 unsigned LLVMGetIntrinsicID(LLVMValueRef Fn);
   1654 
   1655 /**
   1656  * Obtain the calling function of a function.
   1657  *
   1658  * The returned value corresponds to the LLVMCallConv enumeration.
   1659  *
   1660  * @see llvm::Function::getCallingConv()
   1661  */
   1662 unsigned LLVMGetFunctionCallConv(LLVMValueRef Fn);
   1663 
   1664 /**
   1665  * Set the calling convention of a function.
   1666  *
   1667  * @see llvm::Function::setCallingConv()
   1668  *
   1669  * @param Fn Function to operate on
   1670  * @param CC LLVMCallConv to set calling convention to
   1671  */
   1672 void LLVMSetFunctionCallConv(LLVMValueRef Fn, unsigned CC);
   1673 
   1674 /**
   1675  * Obtain the name of the garbage collector to use during code
   1676  * generation.
   1677  *
   1678  * @see llvm::Function::getGC()
   1679  */
   1680 const char *LLVMGetGC(LLVMValueRef Fn);
   1681 
   1682 /**
   1683  * Define the garbage collector to use during code generation.
   1684  *
   1685  * @see llvm::Function::setGC()
   1686  */
   1687 void LLVMSetGC(LLVMValueRef Fn, const char *Name);
   1688 
   1689 /**
   1690  * Add an attribute to a function.
   1691  *
   1692  * @see llvm::Function::addAttribute()
   1693  */
   1694 void LLVMAddFunctionAttr(LLVMValueRef Fn, LLVMAttribute PA);
   1695 
   1696 /**
   1697  * Obtain an attribute from a function.
   1698  *
   1699  * @see llvm::Function::getAttributes()
   1700  */
   1701 LLVMAttribute LLVMGetFunctionAttr(LLVMValueRef Fn);
   1702 
   1703 /**
   1704  * Remove an attribute from a function.
   1705  */
   1706 void LLVMRemoveFunctionAttr(LLVMValueRef Fn, LLVMAttribute PA);
   1707 
   1708 /**
   1709  * @defgroup LLVMCCoreValueFunctionParameters Function Parameters
   1710  *
   1711  * Functions in this group relate to arguments/parameters on functions.
   1712  *
   1713  * Functions in this group expect LLVMValueRef instances that correspond
   1714  * to llvm::Function instances.
   1715  *
   1716  * @{
   1717  */
   1718 
   1719 /**
   1720  * Obtain the number of parameters in a function.
   1721  *
   1722  * @see llvm::Function::arg_size()
   1723  */
   1724 unsigned LLVMCountParams(LLVMValueRef Fn);
   1725 
   1726 /**
   1727  * Obtain the parameters in a function.
   1728  *
   1729  * The takes a pointer to a pre-allocated array of LLVMValueRef that is
   1730  * at least LLVMCountParams() long. This array will be filled with
   1731  * LLVMValueRef instances which correspond to the parameters the
   1732  * function receives. Each LLVMValueRef corresponds to a llvm::Argument
   1733  * instance.
   1734  *
   1735  * @see llvm::Function::arg_begin()
   1736  */
   1737 void LLVMGetParams(LLVMValueRef Fn, LLVMValueRef *Params);
   1738 
   1739 /**
   1740  * Obtain the parameter at the specified index.
   1741  *
   1742  * Parameters are indexed from 0.
   1743  *
   1744  * @see llvm::Function::arg_begin()
   1745  */
   1746 LLVMValueRef LLVMGetParam(LLVMValueRef Fn, unsigned Index);
   1747 
   1748 /**
   1749  * Obtain the function to which this argument belongs.
   1750  *
   1751  * Unlike other functions in this group, this one takes a LLVMValueRef
   1752  * that corresponds to a llvm::Attribute.
   1753  *
   1754  * The returned LLVMValueRef is the llvm::Function to which this
   1755  * argument belongs.
   1756  */
   1757 LLVMValueRef LLVMGetParamParent(LLVMValueRef Inst);
   1758 
   1759 /**
   1760  * Obtain the first parameter to a function.
   1761  *
   1762  * @see llvm::Function::arg_begin()
   1763  */
   1764 LLVMValueRef LLVMGetFirstParam(LLVMValueRef Fn);
   1765 
   1766 /**
   1767  * Obtain the last parameter to a function.
   1768  *
   1769  * @see llvm::Function::arg_end()
   1770  */
   1771 LLVMValueRef LLVMGetLastParam(LLVMValueRef Fn);
   1772 
   1773 /**
   1774  * Obtain the next parameter to a function.
   1775  *
   1776  * This takes a LLVMValueRef obtained from LLVMGetFirstParam() (which is
   1777  * actually a wrapped iterator) and obtains the next parameter from the
   1778  * underlying iterator.
   1779  */
   1780 LLVMValueRef LLVMGetNextParam(LLVMValueRef Arg);
   1781 
   1782 /**
   1783  * Obtain the previous parameter to a function.
   1784  *
   1785  * This is the opposite of LLVMGetNextParam().
   1786  */
   1787 LLVMValueRef LLVMGetPreviousParam(LLVMValueRef Arg);
   1788 
   1789 /**
   1790  * Add an attribute to a function argument.
   1791  *
   1792  * @see llvm::Argument::addAttr()
   1793  */
   1794 void LLVMAddAttribute(LLVMValueRef Arg, LLVMAttribute PA);
   1795 
   1796 /**
   1797  * Remove an attribute from a function argument.
   1798  *
   1799  * @see llvm::Argument::removeAttr()
   1800  */
   1801 void LLVMRemoveAttribute(LLVMValueRef Arg, LLVMAttribute PA);
   1802 
   1803 /**
   1804  * Get an attribute from a function argument.
   1805  */
   1806 LLVMAttribute LLVMGetAttribute(LLVMValueRef Arg);
   1807 
   1808 /**
   1809  * Set the alignment for a function parameter.
   1810  *
   1811  * @see llvm::Argument::addAttr()
   1812  * @see llvm::AttrBuilder::addAlignmentAttr()
   1813  */
   1814 void LLVMSetParamAlignment(LLVMValueRef Arg, unsigned align);
   1815 
   1816 /**
   1817  * @}
   1818  */
   1819 
   1820 /**
   1821  * @}
   1822  */
   1823 
   1824 /**
   1825  * @}
   1826  */
   1827 
   1828 /**
   1829  * @}
   1830  */
   1831 
   1832 /**
   1833  * @defgroup LLVMCCoreValueMetadata Metadata
   1834  *
   1835  * @{
   1836  */
   1837 
   1838 /**
   1839  * Obtain a MDString value from a context.
   1840  *
   1841  * The returned instance corresponds to the llvm::MDString class.
   1842  *
   1843  * The instance is specified by string data of a specified length. The
   1844  * string content is copied, so the backing memory can be freed after
   1845  * this function returns.
   1846  */
   1847 LLVMValueRef LLVMMDStringInContext(LLVMContextRef C, const char *Str,
   1848                                    unsigned SLen);
   1849 
   1850 /**
   1851  * Obtain a MDString value from the global context.
   1852  */
   1853 LLVMValueRef LLVMMDString(const char *Str, unsigned SLen);
   1854 
   1855 /**
   1856  * Obtain a MDNode value from a context.
   1857  *
   1858  * The returned value corresponds to the llvm::MDNode class.
   1859  */
   1860 LLVMValueRef LLVMMDNodeInContext(LLVMContextRef C, LLVMValueRef *Vals,
   1861                                  unsigned Count);
   1862 
   1863 /**
   1864  * Obtain a MDNode value from the global context.
   1865  */
   1866 LLVMValueRef LLVMMDNode(LLVMValueRef *Vals, unsigned Count);
   1867 
   1868 /**
   1869  * Obtain the underlying string from a MDString value.
   1870  *
   1871  * @param V Instance to obtain string from.
   1872  * @param Len Memory address which will hold length of returned string.
   1873  * @return String data in MDString.
   1874  */
   1875 const char  *LLVMGetMDString(LLVMValueRef V, unsigned* Len);
   1876 
   1877 /**
   1878  * Obtain the number of operands from an MDNode value.
   1879  *
   1880  * @param V MDNode to get number of operands from.
   1881  * @return Number of operands of the MDNode.
   1882  */
   1883 unsigned LLVMGetMDNodeNumOperands(LLVMValueRef V);
   1884 
   1885 /**
   1886  * Obtain the given MDNode's operands.
   1887  *
   1888  * The passed LLVMValueRef pointer should point to enough memory to hold all of
   1889  * the operands of the given MDNode (see LLVMGetMDNodeNumOperands) as
   1890  * LLVMValueRefs. This memory will be populated with the LLVMValueRefs of the
   1891  * MDNode's operands.
   1892  *
   1893  * @param V MDNode to get the operands from.
   1894  * @param Dest Destination array for operands.
   1895  */
   1896 void LLVMGetMDNodeOperands(LLVMValueRef V, LLVMValueRef *Dest);
   1897 
   1898 /**
   1899  * @}
   1900  */
   1901 
   1902 /**
   1903  * @defgroup LLVMCCoreValueBasicBlock Basic Block
   1904  *
   1905  * A basic block represents a single entry single exit section of code.
   1906  * Basic blocks contain a list of instructions which form the body of
   1907  * the block.
   1908  *
   1909  * Basic blocks belong to functions. They have the type of label.
   1910  *
   1911  * Basic blocks are themselves values. However, the C API models them as
   1912  * LLVMBasicBlockRef.
   1913  *
   1914  * @see llvm::BasicBlock
   1915  *
   1916  * @{
   1917  */
   1918 
   1919 /**
   1920  * Convert a basic block instance to a value type.
   1921  */
   1922 LLVMValueRef LLVMBasicBlockAsValue(LLVMBasicBlockRef BB);
   1923 
   1924 /**
   1925  * Determine whether a LLVMValueRef is itself a basic block.
   1926  */
   1927 LLVMBool LLVMValueIsBasicBlock(LLVMValueRef Val);
   1928 
   1929 /**
   1930  * Convert a LLVMValueRef to a LLVMBasicBlockRef instance.
   1931  */
   1932 LLVMBasicBlockRef LLVMValueAsBasicBlock(LLVMValueRef Val);
   1933 
   1934 /**
   1935  * Obtain the function to which a basic block belongs.
   1936  *
   1937  * @see llvm::BasicBlock::getParent()
   1938  */
   1939 LLVMValueRef LLVMGetBasicBlockParent(LLVMBasicBlockRef BB);
   1940 
   1941 /**
   1942  * Obtain the terminator instruction for a basic block.
   1943  *
   1944  * If the basic block does not have a terminator (it is not well-formed
   1945  * if it doesn't), then NULL is returned.
   1946  *
   1947  * The returned LLVMValueRef corresponds to a llvm::TerminatorInst.
   1948  *
   1949  * @see llvm::BasicBlock::getTerminator()
   1950  */
   1951 LLVMValueRef LLVMGetBasicBlockTerminator(LLVMBasicBlockRef BB);
   1952 
   1953 /**
   1954  * Obtain the number of basic blocks in a function.
   1955  *
   1956  * @param Fn Function value to operate on.
   1957  */
   1958 unsigned LLVMCountBasicBlocks(LLVMValueRef Fn);
   1959 
   1960 /**
   1961  * Obtain all of the basic blocks in a function.
   1962  *
   1963  * This operates on a function value. The BasicBlocks parameter is a
   1964  * pointer to a pre-allocated array of LLVMBasicBlockRef of at least
   1965  * LLVMCountBasicBlocks() in length. This array is populated with
   1966  * LLVMBasicBlockRef instances.
   1967  */
   1968 void LLVMGetBasicBlocks(LLVMValueRef Fn, LLVMBasicBlockRef *BasicBlocks);
   1969 
   1970 /**
   1971  * Obtain the first basic block in a function.
   1972  *
   1973  * The returned basic block can be used as an iterator. You will likely
   1974  * eventually call into LLVMGetNextBasicBlock() with it.
   1975  *
   1976  * @see llvm::Function::begin()
   1977  */
   1978 LLVMBasicBlockRef LLVMGetFirstBasicBlock(LLVMValueRef Fn);
   1979 
   1980 /**
   1981  * Obtain the last basic block in a function.
   1982  *
   1983  * @see llvm::Function::end()
   1984  */
   1985 LLVMBasicBlockRef LLVMGetLastBasicBlock(LLVMValueRef Fn);
   1986 
   1987 /**
   1988  * Advance a basic block iterator.
   1989  */
   1990 LLVMBasicBlockRef LLVMGetNextBasicBlock(LLVMBasicBlockRef BB);
   1991 
   1992 /**
   1993  * Go backwards in a basic block iterator.
   1994  */
   1995 LLVMBasicBlockRef LLVMGetPreviousBasicBlock(LLVMBasicBlockRef BB);
   1996 
   1997 /**
   1998  * Obtain the basic block that corresponds to the entry point of a
   1999  * function.
   2000  *
   2001  * @see llvm::Function::getEntryBlock()
   2002  */
   2003 LLVMBasicBlockRef LLVMGetEntryBasicBlock(LLVMValueRef Fn);
   2004 
   2005 /**
   2006  * Append a basic block to the end of a function.
   2007  *
   2008  * @see llvm::BasicBlock::Create()
   2009  */
   2010 LLVMBasicBlockRef LLVMAppendBasicBlockInContext(LLVMContextRef C,
   2011                                                 LLVMValueRef Fn,
   2012                                                 const char *Name);
   2013 
   2014 /**
   2015  * Append a basic block to the end of a function using the global
   2016  * context.
   2017  *
   2018  * @see llvm::BasicBlock::Create()
   2019  */
   2020 LLVMBasicBlockRef LLVMAppendBasicBlock(LLVMValueRef Fn, const char *Name);
   2021 
   2022 /**
   2023  * Insert a basic block in a function before another basic block.
   2024  *
   2025  * The function to add to is determined by the function of the
   2026  * passed basic block.
   2027  *
   2028  * @see llvm::BasicBlock::Create()
   2029  */
   2030 LLVMBasicBlockRef LLVMInsertBasicBlockInContext(LLVMContextRef C,
   2031                                                 LLVMBasicBlockRef BB,
   2032                                                 const char *Name);
   2033 
   2034 /**
   2035  * Insert a basic block in a function using the global context.
   2036  *
   2037  * @see llvm::BasicBlock::Create()
   2038  */
   2039 LLVMBasicBlockRef LLVMInsertBasicBlock(LLVMBasicBlockRef InsertBeforeBB,
   2040                                        const char *Name);
   2041 
   2042 /**
   2043  * Remove a basic block from a function and delete it.
   2044  *
   2045  * This deletes the basic block from its containing function and deletes
   2046  * the basic block itself.
   2047  *
   2048  * @see llvm::BasicBlock::eraseFromParent()
   2049  */
   2050 void LLVMDeleteBasicBlock(LLVMBasicBlockRef BB);
   2051 
   2052 /**
   2053  * Remove a basic block from a function.
   2054  *
   2055  * This deletes the basic block from its containing function but keep
   2056  * the basic block alive.
   2057  *
   2058  * @see llvm::BasicBlock::removeFromParent()
   2059  */
   2060 void LLVMRemoveBasicBlockFromParent(LLVMBasicBlockRef BB);
   2061 
   2062 /**
   2063  * Move a basic block to before another one.
   2064  *
   2065  * @see llvm::BasicBlock::moveBefore()
   2066  */
   2067 void LLVMMoveBasicBlockBefore(LLVMBasicBlockRef BB, LLVMBasicBlockRef MovePos);
   2068 
   2069 /**
   2070  * Move a basic block to after another one.
   2071  *
   2072  * @see llvm::BasicBlock::moveAfter()
   2073  */
   2074 void LLVMMoveBasicBlockAfter(LLVMBasicBlockRef BB, LLVMBasicBlockRef MovePos);
   2075 
   2076 /**
   2077  * Obtain the first instruction in a basic block.
   2078  *
   2079  * The returned LLVMValueRef corresponds to a llvm::Instruction
   2080  * instance.
   2081  */
   2082 LLVMValueRef LLVMGetFirstInstruction(LLVMBasicBlockRef BB);
   2083 
   2084 /**
   2085  * Obtain the last instruction in a basic block.
   2086  *
   2087  * The returned LLVMValueRef corresponds to a LLVM:Instruction.
   2088  */
   2089 LLVMValueRef LLVMGetLastInstruction(LLVMBasicBlockRef BB);
   2090 
   2091 /**
   2092  * @}
   2093  */
   2094 
   2095 /**
   2096  * @defgroup LLVMCCoreValueInstruction Instructions
   2097  *
   2098  * Functions in this group relate to the inspection and manipulation of
   2099  * individual instructions.
   2100  *
   2101  * In the C++ API, an instruction is modeled by llvm::Instruction. This
   2102  * class has a large number of descendents. llvm::Instruction is a
   2103  * llvm::Value and in the C API, instructions are modeled by
   2104  * LLVMValueRef.
   2105  *
   2106  * This group also contains sub-groups which operate on specific
   2107  * llvm::Instruction types, e.g. llvm::CallInst.
   2108  *
   2109  * @{
   2110  */
   2111 
   2112 /**
   2113  * Determine whether an instruction has any metadata attached.
   2114  */
   2115 int LLVMHasMetadata(LLVMValueRef Val);
   2116 
   2117 /**
   2118  * Return metadata associated with an instruction value.
   2119  */
   2120 LLVMValueRef LLVMGetMetadata(LLVMValueRef Val, unsigned KindID);
   2121 
   2122 /**
   2123  * Set metadata associated with an instruction value.
   2124  */
   2125 void LLVMSetMetadata(LLVMValueRef Val, unsigned KindID, LLVMValueRef Node);
   2126 
   2127 /**
   2128  * Obtain the basic block to which an instruction belongs.
   2129  *
   2130  * @see llvm::Instruction::getParent()
   2131  */
   2132 LLVMBasicBlockRef LLVMGetInstructionParent(LLVMValueRef Inst);
   2133 
   2134 /**
   2135  * Obtain the instruction that occurs after the one specified.
   2136  *
   2137  * The next instruction will be from the same basic block.
   2138  *
   2139  * If this is the last instruction in a basic block, NULL will be
   2140  * returned.
   2141  */
   2142 LLVMValueRef LLVMGetNextInstruction(LLVMValueRef Inst);
   2143 
   2144 /**
   2145  * Obtain the instruction that occurred before this one.
   2146  *
   2147  * If the instruction is the first instruction in a basic block, NULL
   2148  * will be returned.
   2149  */
   2150 LLVMValueRef LLVMGetPreviousInstruction(LLVMValueRef Inst);
   2151 
   2152 /**
   2153  * Remove and delete an instruction.
   2154  *
   2155  * The instruction specified is removed from its containing building
   2156  * block and then deleted.
   2157  *
   2158  * @see llvm::Instruction::eraseFromParent()
   2159  */
   2160 void LLVMInstructionEraseFromParent(LLVMValueRef Inst);
   2161 
   2162 /**
   2163  * Obtain the code opcode for an individual instruction.
   2164  *
   2165  * @see llvm::Instruction::getOpCode()
   2166  */
   2167 LLVMOpcode   LLVMGetInstructionOpcode(LLVMValueRef Inst);
   2168 
   2169 /**
   2170  * Obtain the predicate of an instruction.
   2171  *
   2172  * This is only valid for instructions that correspond to llvm::ICmpInst
   2173  * or llvm::ConstantExpr whose opcode is llvm::Instruction::ICmp.
   2174  *
   2175  * @see llvm::ICmpInst::getPredicate()
   2176  */
   2177 LLVMIntPredicate LLVMGetICmpPredicate(LLVMValueRef Inst);
   2178 
   2179 /**
   2180  * @defgroup LLVMCCoreValueInstructionCall Call Sites and Invocations
   2181  *
   2182  * Functions in this group apply to instructions that refer to call
   2183  * sites and invocations. These correspond to C++ types in the
   2184  * llvm::CallInst class tree.
   2185  *
   2186  * @{
   2187  */
   2188 
   2189 /**
   2190  * Set the calling convention for a call instruction.
   2191  *
   2192  * This expects an LLVMValueRef that corresponds to a llvm::CallInst or
   2193  * llvm::InvokeInst.
   2194  *
   2195  * @see llvm::CallInst::setCallingConv()
   2196  * @see llvm::InvokeInst::setCallingConv()
   2197  */
   2198 void LLVMSetInstructionCallConv(LLVMValueRef Instr, unsigned CC);
   2199 
   2200 /**
   2201  * Obtain the calling convention for a call instruction.
   2202  *
   2203  * This is the opposite of LLVMSetInstructionCallConv(). Reads its
   2204  * usage.
   2205  *
   2206  * @see LLVMSetInstructionCallConv()
   2207  */
   2208 unsigned LLVMGetInstructionCallConv(LLVMValueRef Instr);
   2209 
   2210 
   2211 void LLVMAddInstrAttribute(LLVMValueRef Instr, unsigned index, LLVMAttribute);
   2212 void LLVMRemoveInstrAttribute(LLVMValueRef Instr, unsigned index,
   2213                               LLVMAttribute);
   2214 void LLVMSetInstrParamAlignment(LLVMValueRef Instr, unsigned index,
   2215                                 unsigned align);
   2216 
   2217 /**
   2218  * Obtain whether a call instruction is a tail call.
   2219  *
   2220  * This only works on llvm::CallInst instructions.
   2221  *
   2222  * @see llvm::CallInst::isTailCall()
   2223  */
   2224 LLVMBool LLVMIsTailCall(LLVMValueRef CallInst);
   2225 
   2226 /**
   2227  * Set whether a call instruction is a tail call.
   2228  *
   2229  * This only works on llvm::CallInst instructions.
   2230  *
   2231  * @see llvm::CallInst::setTailCall()
   2232  */
   2233 void LLVMSetTailCall(LLVMValueRef CallInst, LLVMBool IsTailCall);
   2234 
   2235 /**
   2236  * @}
   2237  */
   2238 
   2239 /**
   2240  * Obtain the default destination basic block of a switch instruction.
   2241  *
   2242  * This only works on llvm::SwitchInst instructions.
   2243  *
   2244  * @see llvm::SwitchInst::getDefaultDest()
   2245  */
   2246 LLVMBasicBlockRef LLVMGetSwitchDefaultDest(LLVMValueRef SwitchInstr);
   2247 
   2248 /**
   2249  * @defgroup LLVMCCoreValueInstructionPHINode PHI Nodes
   2250  *
   2251  * Functions in this group only apply to instructions that map to
   2252  * llvm::PHINode instances.
   2253  *
   2254  * @{
   2255  */
   2256 
   2257 /**
   2258  * Add an incoming value to the end of a PHI list.
   2259  */
   2260 void LLVMAddIncoming(LLVMValueRef PhiNode, LLVMValueRef *IncomingValues,
   2261                      LLVMBasicBlockRef *IncomingBlocks, unsigned Count);
   2262 
   2263 /**
   2264  * Obtain the number of incoming basic blocks to a PHI node.
   2265  */
   2266 unsigned LLVMCountIncoming(LLVMValueRef PhiNode);
   2267 
   2268 /**
   2269  * Obtain an incoming value to a PHI node as a LLVMValueRef.
   2270  */
   2271 LLVMValueRef LLVMGetIncomingValue(LLVMValueRef PhiNode, unsigned Index);
   2272 
   2273 /**
   2274  * Obtain an incoming value to a PHI node as a LLVMBasicBlockRef.
   2275  */
   2276 LLVMBasicBlockRef LLVMGetIncomingBlock(LLVMValueRef PhiNode, unsigned Index);
   2277 
   2278 /**
   2279  * @}
   2280  */
   2281 
   2282 /**
   2283  * @}
   2284  */
   2285 
   2286 /**
   2287  * @}
   2288  */
   2289 
   2290 /**
   2291  * @defgroup LLVMCCoreInstructionBuilder Instruction Builders
   2292  *
   2293  * An instruction builder represents a point within a basic block and is
   2294  * the exclusive means of building instructions using the C interface.
   2295  *
   2296  * @{
   2297  */
   2298 
   2299 LLVMBuilderRef LLVMCreateBuilderInContext(LLVMContextRef C);
   2300 LLVMBuilderRef LLVMCreateBuilder(void);
   2301 void LLVMPositionBuilder(LLVMBuilderRef Builder, LLVMBasicBlockRef Block,
   2302                          LLVMValueRef Instr);
   2303 void LLVMPositionBuilderBefore(LLVMBuilderRef Builder, LLVMValueRef Instr);
   2304 void LLVMPositionBuilderAtEnd(LLVMBuilderRef Builder, LLVMBasicBlockRef Block);
   2305 LLVMBasicBlockRef LLVMGetInsertBlock(LLVMBuilderRef Builder);
   2306 void LLVMClearInsertionPosition(LLVMBuilderRef Builder);
   2307 void LLVMInsertIntoBuilder(LLVMBuilderRef Builder, LLVMValueRef Instr);
   2308 void LLVMInsertIntoBuilderWithName(LLVMBuilderRef Builder, LLVMValueRef Instr,
   2309                                    const char *Name);
   2310 void LLVMDisposeBuilder(LLVMBuilderRef Builder);
   2311 
   2312 /* Metadata */
   2313 void LLVMSetCurrentDebugLocation(LLVMBuilderRef Builder, LLVMValueRef L);
   2314 LLVMValueRef LLVMGetCurrentDebugLocation(LLVMBuilderRef Builder);
   2315 void LLVMSetInstDebugLocation(LLVMBuilderRef Builder, LLVMValueRef Inst);
   2316 
   2317 /* Terminators */
   2318 LLVMValueRef LLVMBuildRetVoid(LLVMBuilderRef);
   2319 LLVMValueRef LLVMBuildRet(LLVMBuilderRef, LLVMValueRef V);
   2320 LLVMValueRef LLVMBuildAggregateRet(LLVMBuilderRef, LLVMValueRef *RetVals,
   2321                                    unsigned N);
   2322 LLVMValueRef LLVMBuildBr(LLVMBuilderRef, LLVMBasicBlockRef Dest);
   2323 LLVMValueRef LLVMBuildCondBr(LLVMBuilderRef, LLVMValueRef If,
   2324                              LLVMBasicBlockRef Then, LLVMBasicBlockRef Else);
   2325 LLVMValueRef LLVMBuildSwitch(LLVMBuilderRef, LLVMValueRef V,
   2326                              LLVMBasicBlockRef Else, unsigned NumCases);
   2327 LLVMValueRef LLVMBuildIndirectBr(LLVMBuilderRef B, LLVMValueRef Addr,
   2328                                  unsigned NumDests);
   2329 LLVMValueRef LLVMBuildInvoke(LLVMBuilderRef, LLVMValueRef Fn,
   2330                              LLVMValueRef *Args, unsigned NumArgs,
   2331                              LLVMBasicBlockRef Then, LLVMBasicBlockRef Catch,
   2332                              const char *Name);
   2333 LLVMValueRef LLVMBuildLandingPad(LLVMBuilderRef B, LLVMTypeRef Ty,
   2334                                  LLVMValueRef PersFn, unsigned NumClauses,
   2335                                  const char *Name);
   2336 LLVMValueRef LLVMBuildResume(LLVMBuilderRef B, LLVMValueRef Exn);
   2337 LLVMValueRef LLVMBuildUnreachable(LLVMBuilderRef);
   2338 
   2339 /* Add a case to the switch instruction */
   2340 void LLVMAddCase(LLVMValueRef Switch, LLVMValueRef OnVal,
   2341                  LLVMBasicBlockRef Dest);
   2342 
   2343 /* Add a destination to the indirectbr instruction */
   2344 void LLVMAddDestination(LLVMValueRef IndirectBr, LLVMBasicBlockRef Dest);
   2345 
   2346 /* Add a catch or filter clause to the landingpad instruction */
   2347 void LLVMAddClause(LLVMValueRef LandingPad, LLVMValueRef ClauseVal);
   2348 
   2349 /* Set the 'cleanup' flag in the landingpad instruction */
   2350 void LLVMSetCleanup(LLVMValueRef LandingPad, LLVMBool Val);
   2351 
   2352 /* Arithmetic */
   2353 LLVMValueRef LLVMBuildAdd(LLVMBuilderRef, LLVMValueRef LHS, LLVMValueRef RHS,
   2354                           const char *Name);
   2355 LLVMValueRef LLVMBuildNSWAdd(LLVMBuilderRef, LLVMValueRef LHS, LLVMValueRef RHS,
   2356                              const char *Name);
   2357 LLVMValueRef LLVMBuildNUWAdd(LLVMBuilderRef, LLVMValueRef LHS, LLVMValueRef RHS,
   2358                              const char *Name);
   2359 LLVMValueRef LLVMBuildFAdd(LLVMBuilderRef, LLVMValueRef LHS, LLVMValueRef RHS,
   2360                            const char *Name);
   2361 LLVMValueRef LLVMBuildSub(LLVMBuilderRef, LLVMValueRef LHS, LLVMValueRef RHS,
   2362                           const char *Name);
   2363 LLVMValueRef LLVMBuildNSWSub(LLVMBuilderRef, LLVMValueRef LHS, LLVMValueRef RHS,
   2364                              const char *Name);
   2365 LLVMValueRef LLVMBuildNUWSub(LLVMBuilderRef, LLVMValueRef LHS, LLVMValueRef RHS,
   2366                              const char *Name);
   2367 LLVMValueRef LLVMBuildFSub(LLVMBuilderRef, LLVMValueRef LHS, LLVMValueRef RHS,
   2368                            const char *Name);
   2369 LLVMValueRef LLVMBuildMul(LLVMBuilderRef, LLVMValueRef LHS, LLVMValueRef RHS,
   2370                           const char *Name);
   2371 LLVMValueRef LLVMBuildNSWMul(LLVMBuilderRef, LLVMValueRef LHS, LLVMValueRef RHS,
   2372                              const char *Name);
   2373 LLVMValueRef LLVMBuildNUWMul(LLVMBuilderRef, LLVMValueRef LHS, LLVMValueRef RHS,
   2374                              const char *Name);
   2375 LLVMValueRef LLVMBuildFMul(LLVMBuilderRef, LLVMValueRef LHS, LLVMValueRef RHS,
   2376                            const char *Name);
   2377 LLVMValueRef LLVMBuildUDiv(LLVMBuilderRef, LLVMValueRef LHS, LLVMValueRef RHS,
   2378                            const char *Name);
   2379 LLVMValueRef LLVMBuildSDiv(LLVMBuilderRef, LLVMValueRef LHS, LLVMValueRef RHS,
   2380                            const char *Name);
   2381 LLVMValueRef LLVMBuildExactSDiv(LLVMBuilderRef, LLVMValueRef LHS, LLVMValueRef RHS,
   2382                                 const char *Name);
   2383 LLVMValueRef LLVMBuildFDiv(LLVMBuilderRef, LLVMValueRef LHS, LLVMValueRef RHS,
   2384                            const char *Name);
   2385 LLVMValueRef LLVMBuildURem(LLVMBuilderRef, LLVMValueRef LHS, LLVMValueRef RHS,
   2386                            const char *Name);
   2387 LLVMValueRef LLVMBuildSRem(LLVMBuilderRef, LLVMValueRef LHS, LLVMValueRef RHS,
   2388                            const char *Name);
   2389 LLVMValueRef LLVMBuildFRem(LLVMBuilderRef, LLVMValueRef LHS, LLVMValueRef RHS,
   2390                            const char *Name);
   2391 LLVMValueRef LLVMBuildShl(LLVMBuilderRef, LLVMValueRef LHS, LLVMValueRef RHS,
   2392                            const char *Name);
   2393 LLVMValueRef LLVMBuildLShr(LLVMBuilderRef, LLVMValueRef LHS, LLVMValueRef RHS,
   2394                            const char *Name);
   2395 LLVMValueRef LLVMBuildAShr(LLVMBuilderRef, LLVMValueRef LHS, LLVMValueRef RHS,
   2396                            const char *Name);
   2397 LLVMValueRef LLVMBuildAnd(LLVMBuilderRef, LLVMValueRef LHS, LLVMValueRef RHS,
   2398                           const char *Name);
   2399 LLVMValueRef LLVMBuildOr(LLVMBuilderRef, LLVMValueRef LHS, LLVMValueRef RHS,
   2400                           const char *Name);
   2401 LLVMValueRef LLVMBuildXor(LLVMBuilderRef, LLVMValueRef LHS, LLVMValueRef RHS,
   2402                           const char *Name);
   2403 LLVMValueRef LLVMBuildBinOp(LLVMBuilderRef B, LLVMOpcode Op,
   2404                             LLVMValueRef LHS, LLVMValueRef RHS,
   2405                             const char *Name);
   2406 LLVMValueRef LLVMBuildNeg(LLVMBuilderRef, LLVMValueRef V, const char *Name);
   2407 LLVMValueRef LLVMBuildNSWNeg(LLVMBuilderRef B, LLVMValueRef V,
   2408                              const char *Name);
   2409 LLVMValueRef LLVMBuildNUWNeg(LLVMBuilderRef B, LLVMValueRef V,
   2410                              const char *Name);
   2411 LLVMValueRef LLVMBuildFNeg(LLVMBuilderRef, LLVMValueRef V, const char *Name);
   2412 LLVMValueRef LLVMBuildNot(LLVMBuilderRef, LLVMValueRef V, const char *Name);
   2413 
   2414 /* Memory */
   2415 LLVMValueRef LLVMBuildMalloc(LLVMBuilderRef, LLVMTypeRef Ty, const char *Name);
   2416 LLVMValueRef LLVMBuildArrayMalloc(LLVMBuilderRef, LLVMTypeRef Ty,
   2417                                   LLVMValueRef Val, const char *Name);
   2418 LLVMValueRef LLVMBuildAlloca(LLVMBuilderRef, LLVMTypeRef Ty, const char *Name);
   2419 LLVMValueRef LLVMBuildArrayAlloca(LLVMBuilderRef, LLVMTypeRef Ty,
   2420                                   LLVMValueRef Val, const char *Name);
   2421 LLVMValueRef LLVMBuildFree(LLVMBuilderRef, LLVMValueRef PointerVal);
   2422 LLVMValueRef LLVMBuildLoad(LLVMBuilderRef, LLVMValueRef PointerVal,
   2423                            const char *Name);
   2424 LLVMValueRef LLVMBuildStore(LLVMBuilderRef, LLVMValueRef Val, LLVMValueRef Ptr);
   2425 LLVMValueRef LLVMBuildGEP(LLVMBuilderRef B, LLVMValueRef Pointer,
   2426                           LLVMValueRef *Indices, unsigned NumIndices,
   2427                           const char *Name);
   2428 LLVMValueRef LLVMBuildInBoundsGEP(LLVMBuilderRef B, LLVMValueRef Pointer,
   2429                                   LLVMValueRef *Indices, unsigned NumIndices,
   2430                                   const char *Name);
   2431 LLVMValueRef LLVMBuildStructGEP(LLVMBuilderRef B, LLVMValueRef Pointer,
   2432                                 unsigned Idx, const char *Name);
   2433 LLVMValueRef LLVMBuildGlobalString(LLVMBuilderRef B, const char *Str,
   2434                                    const char *Name);
   2435 LLVMValueRef LLVMBuildGlobalStringPtr(LLVMBuilderRef B, const char *Str,
   2436                                       const char *Name);
   2437 LLVMBool LLVMGetVolatile(LLVMValueRef MemoryAccessInst);
   2438 void LLVMSetVolatile(LLVMValueRef MemoryAccessInst, LLVMBool IsVolatile);
   2439 
   2440 /* Casts */
   2441 LLVMValueRef LLVMBuildTrunc(LLVMBuilderRef, LLVMValueRef Val,
   2442                             LLVMTypeRef DestTy, const char *Name);
   2443 LLVMValueRef LLVMBuildZExt(LLVMBuilderRef, LLVMValueRef Val,
   2444                            LLVMTypeRef DestTy, const char *Name);
   2445 LLVMValueRef LLVMBuildSExt(LLVMBuilderRef, LLVMValueRef Val,
   2446                            LLVMTypeRef DestTy, const char *Name);
   2447 LLVMValueRef LLVMBuildFPToUI(LLVMBuilderRef, LLVMValueRef Val,
   2448                              LLVMTypeRef DestTy, const char *Name);
   2449 LLVMValueRef LLVMBuildFPToSI(LLVMBuilderRef, LLVMValueRef Val,
   2450                              LLVMTypeRef DestTy, const char *Name);
   2451 LLVMValueRef LLVMBuildUIToFP(LLVMBuilderRef, LLVMValueRef Val,
   2452                              LLVMTypeRef DestTy, const char *Name);
   2453 LLVMValueRef LLVMBuildSIToFP(LLVMBuilderRef, LLVMValueRef Val,
   2454                              LLVMTypeRef DestTy, const char *Name);
   2455 LLVMValueRef LLVMBuildFPTrunc(LLVMBuilderRef, LLVMValueRef Val,
   2456                               LLVMTypeRef DestTy, const char *Name);
   2457 LLVMValueRef LLVMBuildFPExt(LLVMBuilderRef, LLVMValueRef Val,
   2458                             LLVMTypeRef DestTy, const char *Name);
   2459 LLVMValueRef LLVMBuildPtrToInt(LLVMBuilderRef, LLVMValueRef Val,
   2460                                LLVMTypeRef DestTy, const char *Name);
   2461 LLVMValueRef LLVMBuildIntToPtr(LLVMBuilderRef, LLVMValueRef Val,
   2462                                LLVMTypeRef DestTy, const char *Name);
   2463 LLVMValueRef LLVMBuildBitCast(LLVMBuilderRef, LLVMValueRef Val,
   2464                               LLVMTypeRef DestTy, const char *Name);
   2465 LLVMValueRef LLVMBuildZExtOrBitCast(LLVMBuilderRef, LLVMValueRef Val,
   2466                                     LLVMTypeRef DestTy, const char *Name);
   2467 LLVMValueRef LLVMBuildSExtOrBitCast(LLVMBuilderRef, LLVMValueRef Val,
   2468                                     LLVMTypeRef DestTy, const char *Name);
   2469 LLVMValueRef LLVMBuildTruncOrBitCast(LLVMBuilderRef, LLVMValueRef Val,
   2470                                      LLVMTypeRef DestTy, const char *Name);
   2471 LLVMValueRef LLVMBuildCast(LLVMBuilderRef B, LLVMOpcode Op, LLVMValueRef Val,
   2472                            LLVMTypeRef DestTy, const char *Name);
   2473 LLVMValueRef LLVMBuildPointerCast(LLVMBuilderRef, LLVMValueRef Val,
   2474                                   LLVMTypeRef DestTy, const char *Name);
   2475 LLVMValueRef LLVMBuildIntCast(LLVMBuilderRef, LLVMValueRef Val, /*Signed cast!*/
   2476                               LLVMTypeRef DestTy, const char *Name);
   2477 LLVMValueRef LLVMBuildFPCast(LLVMBuilderRef, LLVMValueRef Val,
   2478                              LLVMTypeRef DestTy, const char *Name);
   2479 
   2480 /* Comparisons */
   2481 LLVMValueRef LLVMBuildICmp(LLVMBuilderRef, LLVMIntPredicate Op,
   2482                            LLVMValueRef LHS, LLVMValueRef RHS,
   2483                            const char *Name);
   2484 LLVMValueRef LLVMBuildFCmp(LLVMBuilderRef, LLVMRealPredicate Op,
   2485                            LLVMValueRef LHS, LLVMValueRef RHS,
   2486                            const char *Name);
   2487 
   2488 /* Miscellaneous instructions */
   2489 LLVMValueRef LLVMBuildPhi(LLVMBuilderRef, LLVMTypeRef Ty, const char *Name);
   2490 LLVMValueRef LLVMBuildCall(LLVMBuilderRef, LLVMValueRef Fn,
   2491                            LLVMValueRef *Args, unsigned NumArgs,
   2492                            const char *Name);
   2493 LLVMValueRef LLVMBuildSelect(LLVMBuilderRef, LLVMValueRef If,
   2494                              LLVMValueRef Then, LLVMValueRef Else,
   2495                              const char *Name);
   2496 LLVMValueRef LLVMBuildVAArg(LLVMBuilderRef, LLVMValueRef List, LLVMTypeRef Ty,
   2497                             const char *Name);
   2498 LLVMValueRef LLVMBuildExtractElement(LLVMBuilderRef, LLVMValueRef VecVal,
   2499                                      LLVMValueRef Index, const char *Name);
   2500 LLVMValueRef LLVMBuildInsertElement(LLVMBuilderRef, LLVMValueRef VecVal,
   2501                                     LLVMValueRef EltVal, LLVMValueRef Index,
   2502                                     const char *Name);
   2503 LLVMValueRef LLVMBuildShuffleVector(LLVMBuilderRef, LLVMValueRef V1,
   2504                                     LLVMValueRef V2, LLVMValueRef Mask,
   2505                                     const char *Name);
   2506 LLVMValueRef LLVMBuildExtractValue(LLVMBuilderRef, LLVMValueRef AggVal,
   2507                                    unsigned Index, const char *Name);
   2508 LLVMValueRef LLVMBuildInsertValue(LLVMBuilderRef, LLVMValueRef AggVal,
   2509                                   LLVMValueRef EltVal, unsigned Index,
   2510                                   const char *Name);
   2511 
   2512 LLVMValueRef LLVMBuildIsNull(LLVMBuilderRef, LLVMValueRef Val,
   2513                              const char *Name);
   2514 LLVMValueRef LLVMBuildIsNotNull(LLVMBuilderRef, LLVMValueRef Val,
   2515                                 const char *Name);
   2516 LLVMValueRef LLVMBuildPtrDiff(LLVMBuilderRef, LLVMValueRef LHS,
   2517                               LLVMValueRef RHS, const char *Name);
   2518 
   2519 /**
   2520  * @}
   2521  */
   2522 
   2523 /**
   2524  * @defgroup LLVMCCoreModuleProvider Module Providers
   2525  *
   2526  * @{
   2527  */
   2528 
   2529 /**
   2530  * Changes the type of M so it can be passed to FunctionPassManagers and the
   2531  * JIT.  They take ModuleProviders for historical reasons.
   2532  */
   2533 LLVMModuleProviderRef
   2534 LLVMCreateModuleProviderForExistingModule(LLVMModuleRef M);
   2535 
   2536 /**
   2537  * Destroys the module M.
   2538  */
   2539 void LLVMDisposeModuleProvider(LLVMModuleProviderRef M);
   2540 
   2541 /**
   2542  * @}
   2543  */
   2544 
   2545 /**
   2546  * @defgroup LLVMCCoreMemoryBuffers Memory Buffers
   2547  *
   2548  * @{
   2549  */
   2550 
   2551 LLVMBool LLVMCreateMemoryBufferWithContentsOfFile(const char *Path,
   2552                                                   LLVMMemoryBufferRef *OutMemBuf,
   2553                                                   char **OutMessage);
   2554 LLVMBool LLVMCreateMemoryBufferWithSTDIN(LLVMMemoryBufferRef *OutMemBuf,
   2555                                          char **OutMessage);
   2556 LLVMMemoryBufferRef LLVMCreateMemoryBufferWithMemoryRange(const char *InputData,
   2557                                                           size_t InputDataLength,
   2558                                                           const char *BufferName,
   2559                                                           LLVMBool RequiresNullTerminator);
   2560 LLVMMemoryBufferRef LLVMCreateMemoryBufferWithMemoryRangeCopy(const char *InputData,
   2561                                                               size_t InputDataLength,
   2562                                                               const char *BufferName);
   2563 void LLVMDisposeMemoryBuffer(LLVMMemoryBufferRef MemBuf);
   2564 
   2565 /**
   2566  * @}
   2567  */
   2568 
   2569 /**
   2570  * @defgroup LLVMCCorePassRegistry Pass Registry
   2571  *
   2572  * @{
   2573  */
   2574 
   2575 /** Return the global pass registry, for use with initialization functions.
   2576     @see llvm::PassRegistry::getPassRegistry */
   2577 LLVMPassRegistryRef LLVMGetGlobalPassRegistry(void);
   2578 
   2579 /**
   2580  * @}
   2581  */
   2582 
   2583 /**
   2584  * @defgroup LLVMCCorePassManagers Pass Managers
   2585  *
   2586  * @{
   2587  */
   2588 
   2589 /** Constructs a new whole-module pass pipeline. This type of pipeline is
   2590     suitable for link-time optimization and whole-module transformations.
   2591     @see llvm::PassManager::PassManager */
   2592 LLVMPassManagerRef LLVMCreatePassManager(void);
   2593 
   2594 /** Constructs a new function-by-function pass pipeline over the module
   2595     provider. It does not take ownership of the module provider. This type of
   2596     pipeline is suitable for code generation and JIT compilation tasks.
   2597     @see llvm::FunctionPassManager::FunctionPassManager */
   2598 LLVMPassManagerRef LLVMCreateFunctionPassManagerForModule(LLVMModuleRef M);
   2599 
   2600 /** Deprecated: Use LLVMCreateFunctionPassManagerForModule instead. */
   2601 LLVMPassManagerRef LLVMCreateFunctionPassManager(LLVMModuleProviderRef MP);
   2602 
   2603 /** Initializes, executes on the provided module, and finalizes all of the
   2604     passes scheduled in the pass manager. Returns 1 if any of the passes
   2605     modified the module, 0 otherwise.
   2606     @see llvm::PassManager::run(Module&) */
   2607 LLVMBool LLVMRunPassManager(LLVMPassManagerRef PM, LLVMModuleRef M);
   2608 
   2609 /** Initializes all of the function passes scheduled in the function pass
   2610     manager. Returns 1 if any of the passes modified the module, 0 otherwise.
   2611     @see llvm::FunctionPassManager::doInitialization */
   2612 LLVMBool LLVMInitializeFunctionPassManager(LLVMPassManagerRef FPM);
   2613 
   2614 /** Executes all of the function passes scheduled in the function pass manager
   2615     on the provided function. Returns 1 if any of the passes modified the
   2616     function, false otherwise.
   2617     @see llvm::FunctionPassManager::run(Function&) */
   2618 LLVMBool LLVMRunFunctionPassManager(LLVMPassManagerRef FPM, LLVMValueRef F);
   2619 
   2620 /** Finalizes all of the function passes scheduled in in the function pass
   2621     manager. Returns 1 if any of the passes modified the module, 0 otherwise.
   2622     @see llvm::FunctionPassManager::doFinalization */
   2623 LLVMBool LLVMFinalizeFunctionPassManager(LLVMPassManagerRef FPM);
   2624 
   2625 /** Frees the memory of a pass pipeline. For function pipelines, does not free
   2626     the module provider.
   2627     @see llvm::PassManagerBase::~PassManagerBase. */
   2628 void LLVMDisposePassManager(LLVMPassManagerRef PM);
   2629 
   2630 /**
   2631  * @}
   2632  */
   2633 
   2634 /**
   2635  * @defgroup LLVMCCoreThreading Threading
   2636  *
   2637  * Handle the structures needed to make LLVM safe for multithreading.
   2638  *
   2639  * @{
   2640  */
   2641 
   2642 /** Allocate and initialize structures needed to make LLVM safe for
   2643     multithreading. The return value indicates whether multithreaded
   2644     initialization succeeded. Must be executed in isolation from all
   2645     other LLVM api calls.
   2646     @see llvm::llvm_start_multithreaded */
   2647 LLVMBool LLVMStartMultithreaded();
   2648 
   2649 /** Deallocate structures necessary to make LLVM safe for multithreading.
   2650     Must be executed in isolation from all other LLVM api calls.
   2651     @see llvm::llvm_stop_multithreaded */
   2652 void LLVMStopMultithreaded();
   2653 
   2654 /** Check whether LLVM is executing in thread-safe mode or not.
   2655     @see llvm::llvm_is_multithreaded */
   2656 LLVMBool LLVMIsMultithreaded();
   2657 
   2658 /**
   2659  * @}
   2660  */
   2661 
   2662 /**
   2663  * @}
   2664  */
   2665 
   2666 /**
   2667  * @}
   2668  */
   2669 
   2670 #ifdef __cplusplus
   2671 }
   2672 
   2673 namespace llvm {
   2674   class MemoryBuffer;
   2675   class PassManagerBase;
   2676 
   2677   #define DEFINE_SIMPLE_CONVERSION_FUNCTIONS(ty, ref)   \
   2678     inline ty *unwrap(ref P) {                          \
   2679       return reinterpret_cast<ty*>(P);                  \
   2680     }                                                   \
   2681                                                         \
   2682     inline ref wrap(const ty *P) {                      \
   2683       return reinterpret_cast<ref>(const_cast<ty*>(P)); \
   2684     }
   2685 
   2686   #define DEFINE_ISA_CONVERSION_FUNCTIONS(ty, ref)  \
   2687     DEFINE_SIMPLE_CONVERSION_FUNCTIONS(ty, ref)         \
   2688                                                         \
   2689     template<typename T>                                \
   2690     inline T *unwrap(ref P) {                           \
   2691       return cast<T>(unwrap(P));                        \
   2692     }
   2693 
   2694   #define DEFINE_STDCXX_CONVERSION_FUNCTIONS(ty, ref)   \
   2695     DEFINE_SIMPLE_CONVERSION_FUNCTIONS(ty, ref)         \
   2696                                                         \
   2697     template<typename T>                                \
   2698     inline T *unwrap(ref P) {                           \
   2699       T *Q = (T*)unwrap(P);                             \
   2700       assert(Q && "Invalid cast!");                     \
   2701       return Q;                                         \
   2702     }
   2703 
   2704   DEFINE_ISA_CONVERSION_FUNCTIONS   (Type,               LLVMTypeRef          )
   2705   DEFINE_ISA_CONVERSION_FUNCTIONS   (Value,              LLVMValueRef         )
   2706   DEFINE_SIMPLE_CONVERSION_FUNCTIONS(Module,             LLVMModuleRef        )
   2707   DEFINE_SIMPLE_CONVERSION_FUNCTIONS(BasicBlock,         LLVMBasicBlockRef    )
   2708   DEFINE_SIMPLE_CONVERSION_FUNCTIONS(IRBuilder<>,        LLVMBuilderRef       )
   2709   DEFINE_SIMPLE_CONVERSION_FUNCTIONS(MemoryBuffer,       LLVMMemoryBufferRef  )
   2710   DEFINE_SIMPLE_CONVERSION_FUNCTIONS(LLVMContext,        LLVMContextRef       )
   2711   DEFINE_SIMPLE_CONVERSION_FUNCTIONS(Use,                LLVMUseRef           )
   2712   DEFINE_STDCXX_CONVERSION_FUNCTIONS(PassManagerBase,    LLVMPassManagerRef   )
   2713   DEFINE_STDCXX_CONVERSION_FUNCTIONS(PassRegistry,       LLVMPassRegistryRef  )
   2714   /* LLVMModuleProviderRef exists for historical reasons, but now just holds a
   2715    * Module.
   2716    */
   2717   inline Module *unwrap(LLVMModuleProviderRef MP) {
   2718     return reinterpret_cast<Module*>(MP);
   2719   }
   2720 
   2721   #undef DEFINE_STDCXX_CONVERSION_FUNCTIONS
   2722   #undef DEFINE_ISA_CONVERSION_FUNCTIONS
   2723   #undef DEFINE_SIMPLE_CONVERSION_FUNCTIONS
   2724 
   2725   /* Specialized opaque context conversions.
   2726    */
   2727   inline LLVMContext **unwrap(LLVMContextRef* Tys) {
   2728     return reinterpret_cast<LLVMContext**>(Tys);
   2729   }
   2730 
   2731   inline LLVMContextRef *wrap(const LLVMContext **Tys) {
   2732     return reinterpret_cast<LLVMContextRef*>(const_cast<LLVMContext**>(Tys));
   2733   }
   2734 
   2735   /* Specialized opaque type conversions.
   2736    */
   2737   inline Type **unwrap(LLVMTypeRef* Tys) {
   2738     return reinterpret_cast<Type**>(Tys);
   2739   }
   2740 
   2741   inline LLVMTypeRef *wrap(Type **Tys) {
   2742     return reinterpret_cast<LLVMTypeRef*>(const_cast<Type**>(Tys));
   2743   }
   2744 
   2745   /* Specialized opaque value conversions.
   2746    */
   2747   inline Value **unwrap(LLVMValueRef *Vals) {
   2748     return reinterpret_cast<Value**>(Vals);
   2749   }
   2750 
   2751   template<typename T>
   2752   inline T **unwrap(LLVMValueRef *Vals, unsigned Length) {
   2753     #ifdef DEBUG
   2754     for (LLVMValueRef *I = Vals, *E = Vals + Length; I != E; ++I)
   2755       cast<T>(*I);
   2756     #endif
   2757     (void)Length;
   2758     return reinterpret_cast<T**>(Vals);
   2759   }
   2760 
   2761   inline LLVMValueRef *wrap(const Value **Vals) {
   2762     return reinterpret_cast<LLVMValueRef*>(const_cast<Value**>(Vals));
   2763   }
   2764 }
   2765 
   2766 #endif /* !defined(__cplusplus) */
   2767 
   2768 #endif /* !defined(LLVM_C_CORE_H) */
   2769