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