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