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