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