1 /*===-- llvm-c/Core.h - Core Library C Interface ------------------*- C -*-===*\ 2 |* *| 3 |* Part of the LLVM Project, under the Apache License v2.0 with LLVM *| 4 |* Exceptions. *| 5 |* See https://llvm.org/LICENSE.txt for license information. *| 6 |* SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception *| 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/Deprecated.h" 19 #include "llvm-c/ErrorHandling.h" 20 #include "llvm-c/ExternC.h" 21 22 #include "llvm-c/Types.h" 23 24 LLVM_C_EXTERN_C_BEGIN 25 26 /** 27 * @defgroup LLVMC LLVM-C: C interface to LLVM 28 * 29 * This module exposes parts of the LLVM library as a C API. 30 * 31 * @{ 32 */ 33 34 /** 35 * @defgroup LLVMCTransforms Transforms 36 */ 37 38 /** 39 * @defgroup LLVMCCore Core 40 * 41 * This modules provide an interface to libLLVMCore, which implements 42 * the LLVM intermediate representation as well as other related types 43 * and utilities. 44 * 45 * Many exotic languages can interoperate with C code but have a harder time 46 * with C++ due to name mangling. So in addition to C, this interface enables 47 * tools written in such languages. 48 * 49 * @{ 50 */ 51 52 /** 53 * @defgroup LLVMCCoreTypes Types and Enumerations 54 * 55 * @{ 56 */ 57 58 /// External users depend on the following values being stable. It is not safe 59 /// to reorder them. 60 typedef enum { 61 /* Terminator Instructions */ 62 LLVMRet = 1, 63 LLVMBr = 2, 64 LLVMSwitch = 3, 65 LLVMIndirectBr = 4, 66 LLVMInvoke = 5, 67 /* removed 6 due to API changes */ 68 LLVMUnreachable = 7, 69 LLVMCallBr = 67, 70 71 /* Standard Unary Operators */ 72 LLVMFNeg = 66, 73 74 /* Standard Binary Operators */ 75 LLVMAdd = 8, 76 LLVMFAdd = 9, 77 LLVMSub = 10, 78 LLVMFSub = 11, 79 LLVMMul = 12, 80 LLVMFMul = 13, 81 LLVMUDiv = 14, 82 LLVMSDiv = 15, 83 LLVMFDiv = 16, 84 LLVMURem = 17, 85 LLVMSRem = 18, 86 LLVMFRem = 19, 87 88 /* Logical Operators */ 89 LLVMShl = 20, 90 LLVMLShr = 21, 91 LLVMAShr = 22, 92 LLVMAnd = 23, 93 LLVMOr = 24, 94 LLVMXor = 25, 95 96 /* Memory Operators */ 97 LLVMAlloca = 26, 98 LLVMLoad = 27, 99 LLVMStore = 28, 100 LLVMGetElementPtr = 29, 101 102 /* Cast Operators */ 103 LLVMTrunc = 30, 104 LLVMZExt = 31, 105 LLVMSExt = 32, 106 LLVMFPToUI = 33, 107 LLVMFPToSI = 34, 108 LLVMUIToFP = 35, 109 LLVMSIToFP = 36, 110 LLVMFPTrunc = 37, 111 LLVMFPExt = 38, 112 LLVMPtrToInt = 39, 113 LLVMIntToPtr = 40, 114 LLVMBitCast = 41, 115 LLVMAddrSpaceCast = 60, 116 117 /* Other Operators */ 118 LLVMICmp = 42, 119 LLVMFCmp = 43, 120 LLVMPHI = 44, 121 LLVMCall = 45, 122 LLVMSelect = 46, 123 LLVMUserOp1 = 47, 124 LLVMUserOp2 = 48, 125 LLVMVAArg = 49, 126 LLVMExtractElement = 50, 127 LLVMInsertElement = 51, 128 LLVMShuffleVector = 52, 129 LLVMExtractValue = 53, 130 LLVMInsertValue = 54, 131 LLVMFreeze = 68, 132 133 /* Atomic operators */ 134 LLVMFence = 55, 135 LLVMAtomicCmpXchg = 56, 136 LLVMAtomicRMW = 57, 137 138 /* Exception Handling Operators */ 139 LLVMResume = 58, 140 LLVMLandingPad = 59, 141 LLVMCleanupRet = 61, 142 LLVMCatchRet = 62, 143 LLVMCatchPad = 63, 144 LLVMCleanupPad = 64, 145 LLVMCatchSwitch = 65 146 } LLVMOpcode; 147 148 typedef enum { 149 LLVMVoidTypeKind, /**< type with no size */ 150 LLVMHalfTypeKind, /**< 16 bit floating point type */ 151 LLVMFloatTypeKind, /**< 32 bit floating point type */ 152 LLVMDoubleTypeKind, /**< 64 bit floating point type */ 153 LLVMX86_FP80TypeKind, /**< 80 bit floating point type (X87) */ 154 LLVMFP128TypeKind, /**< 128 bit floating point type (112-bit mantissa)*/ 155 LLVMPPC_FP128TypeKind, /**< 128 bit floating point type (two 64-bits) */ 156 LLVMLabelTypeKind, /**< Labels */ 157 LLVMIntegerTypeKind, /**< Arbitrary bit width integers */ 158 LLVMFunctionTypeKind, /**< Functions */ 159 LLVMStructTypeKind, /**< Structures */ 160 LLVMArrayTypeKind, /**< Arrays */ 161 LLVMPointerTypeKind, /**< Pointers */ 162 LLVMVectorTypeKind, /**< Fixed width SIMD vector type */ 163 LLVMMetadataTypeKind, /**< Metadata */ 164 LLVMX86_MMXTypeKind, /**< X86 MMX */ 165 LLVMTokenTypeKind, /**< Tokens */ 166 LLVMScalableVectorTypeKind, /**< Scalable SIMD vector type */ 167 LLVMBFloatTypeKind, /**< 16 bit brain floating point type */ 168 LLVMX86_AMXTypeKind, /**< X86 AMX */ 169 LLVMTargetExtTypeKind, /**< Target extension type */ 170 } LLVMTypeKind; 171 172 typedef enum { 173 LLVMExternalLinkage, /**< Externally visible function */ 174 LLVMAvailableExternallyLinkage, 175 LLVMLinkOnceAnyLinkage, /**< Keep one copy of function when linking (inline)*/ 176 LLVMLinkOnceODRLinkage, /**< Same, but only replaced by something 177 equivalent. */ 178 LLVMLinkOnceODRAutoHideLinkage, /**< Obsolete */ 179 LLVMWeakAnyLinkage, /**< Keep one copy of function when linking (weak) */ 180 LLVMWeakODRLinkage, /**< Same, but only replaced by something 181 equivalent. */ 182 LLVMAppendingLinkage, /**< Special purpose, only applies to global arrays */ 183 LLVMInternalLinkage, /**< Rename collisions when linking (static 184 functions) */ 185 LLVMPrivateLinkage, /**< Like Internal, but omit from symbol table */ 186 LLVMDLLImportLinkage, /**< Obsolete */ 187 LLVMDLLExportLinkage, /**< Obsolete */ 188 LLVMExternalWeakLinkage,/**< ExternalWeak linkage description */ 189 LLVMGhostLinkage, /**< Obsolete */ 190 LLVMCommonLinkage, /**< Tentative definitions */ 191 LLVMLinkerPrivateLinkage, /**< Like Private, but linker removes. */ 192 LLVMLinkerPrivateWeakLinkage /**< Like LinkerPrivate, but is weak. */ 193 } LLVMLinkage; 194 195 typedef enum { 196 LLVMDefaultVisibility, /**< The GV is visible */ 197 LLVMHiddenVisibility, /**< The GV is hidden */ 198 LLVMProtectedVisibility /**< The GV is protected */ 199 } LLVMVisibility; 200 201 typedef enum { 202 LLVMNoUnnamedAddr, /**< Address of the GV is significant. */ 203 LLVMLocalUnnamedAddr, /**< Address of the GV is locally insignificant. */ 204 LLVMGlobalUnnamedAddr /**< Address of the GV is globally insignificant. */ 205 } LLVMUnnamedAddr; 206 207 typedef enum { 208 LLVMDefaultStorageClass = 0, 209 LLVMDLLImportStorageClass = 1, /**< Function to be imported from DLL. */ 210 LLVMDLLExportStorageClass = 2 /**< Function to be accessible from DLL. */ 211 } LLVMDLLStorageClass; 212 213 typedef enum { 214 LLVMCCallConv = 0, 215 LLVMFastCallConv = 8, 216 LLVMColdCallConv = 9, 217 LLVMGHCCallConv = 10, 218 LLVMHiPECallConv = 11, 219 LLVMAnyRegCallConv = 13, 220 LLVMPreserveMostCallConv = 14, 221 LLVMPreserveAllCallConv = 15, 222 LLVMSwiftCallConv = 16, 223 LLVMCXXFASTTLSCallConv = 17, 224 LLVMX86StdcallCallConv = 64, 225 LLVMX86FastcallCallConv = 65, 226 LLVMARMAPCSCallConv = 66, 227 LLVMARMAAPCSCallConv = 67, 228 LLVMARMAAPCSVFPCallConv = 68, 229 LLVMMSP430INTRCallConv = 69, 230 LLVMX86ThisCallCallConv = 70, 231 LLVMPTXKernelCallConv = 71, 232 LLVMPTXDeviceCallConv = 72, 233 LLVMSPIRFUNCCallConv = 75, 234 LLVMSPIRKERNELCallConv = 76, 235 LLVMIntelOCLBICallConv = 77, 236 LLVMX8664SysVCallConv = 78, 237 LLVMWin64CallConv = 79, 238 LLVMX86VectorCallCallConv = 80, 239 LLVMHHVMCallConv = 81, 240 LLVMHHVMCCallConv = 82, 241 LLVMX86INTRCallConv = 83, 242 LLVMAVRINTRCallConv = 84, 243 LLVMAVRSIGNALCallConv = 85, 244 LLVMAVRBUILTINCallConv = 86, 245 LLVMAMDGPUVSCallConv = 87, 246 LLVMAMDGPUGSCallConv = 88, 247 LLVMAMDGPUPSCallConv = 89, 248 LLVMAMDGPUCSCallConv = 90, 249 LLVMAMDGPUKERNELCallConv = 91, 250 LLVMX86RegCallCallConv = 92, 251 LLVMAMDGPUHSCallConv = 93, 252 LLVMMSP430BUILTINCallConv = 94, 253 LLVMAMDGPULSCallConv = 95, 254 LLVMAMDGPUESCallConv = 96 255 } LLVMCallConv; 256 257 typedef enum { 258 LLVMArgumentValueKind, 259 LLVMBasicBlockValueKind, 260 LLVMMemoryUseValueKind, 261 LLVMMemoryDefValueKind, 262 LLVMMemoryPhiValueKind, 263 264 LLVMFunctionValueKind, 265 LLVMGlobalAliasValueKind, 266 LLVMGlobalIFuncValueKind, 267 LLVMGlobalVariableValueKind, 268 LLVMBlockAddressValueKind, 269 LLVMConstantExprValueKind, 270 LLVMConstantArrayValueKind, 271 LLVMConstantStructValueKind, 272 LLVMConstantVectorValueKind, 273 274 LLVMUndefValueValueKind, 275 LLVMConstantAggregateZeroValueKind, 276 LLVMConstantDataArrayValueKind, 277 LLVMConstantDataVectorValueKind, 278 LLVMConstantIntValueKind, 279 LLVMConstantFPValueKind, 280 LLVMConstantPointerNullValueKind, 281 LLVMConstantTokenNoneValueKind, 282 283 LLVMMetadataAsValueValueKind, 284 LLVMInlineAsmValueKind, 285 286 LLVMInstructionValueKind, 287 LLVMPoisonValueValueKind, 288 LLVMConstantTargetNoneValueKind, 289 LLVMConstantPtrAuthValueKind, 290 } LLVMValueKind; 291 292 typedef enum { 293 LLVMIntEQ = 32, /**< equal */ 294 LLVMIntNE, /**< not equal */ 295 LLVMIntUGT, /**< unsigned greater than */ 296 LLVMIntUGE, /**< unsigned greater or equal */ 297 LLVMIntULT, /**< unsigned less than */ 298 LLVMIntULE, /**< unsigned less or equal */ 299 LLVMIntSGT, /**< signed greater than */ 300 LLVMIntSGE, /**< signed greater or equal */ 301 LLVMIntSLT, /**< signed less than */ 302 LLVMIntSLE /**< signed less or equal */ 303 } LLVMIntPredicate; 304 305 typedef enum { 306 LLVMRealPredicateFalse, /**< Always false (always folded) */ 307 LLVMRealOEQ, /**< True if ordered and equal */ 308 LLVMRealOGT, /**< True if ordered and greater than */ 309 LLVMRealOGE, /**< True if ordered and greater than or equal */ 310 LLVMRealOLT, /**< True if ordered and less than */ 311 LLVMRealOLE, /**< True if ordered and less than or equal */ 312 LLVMRealONE, /**< True if ordered and operands are unequal */ 313 LLVMRealORD, /**< True if ordered (no nans) */ 314 LLVMRealUNO, /**< True if unordered: isnan(X) | isnan(Y) */ 315 LLVMRealUEQ, /**< True if unordered or equal */ 316 LLVMRealUGT, /**< True if unordered or greater than */ 317 LLVMRealUGE, /**< True if unordered, greater than, or equal */ 318 LLVMRealULT, /**< True if unordered or less than */ 319 LLVMRealULE, /**< True if unordered, less than, or equal */ 320 LLVMRealUNE, /**< True if unordered or not equal */ 321 LLVMRealPredicateTrue /**< Always true (always folded) */ 322 } LLVMRealPredicate; 323 324 typedef enum { 325 LLVMLandingPadCatch, /**< A catch clause */ 326 LLVMLandingPadFilter /**< A filter clause */ 327 } LLVMLandingPadClauseTy; 328 329 typedef enum { 330 LLVMNotThreadLocal = 0, 331 LLVMGeneralDynamicTLSModel, 332 LLVMLocalDynamicTLSModel, 333 LLVMInitialExecTLSModel, 334 LLVMLocalExecTLSModel 335 } LLVMThreadLocalMode; 336 337 typedef enum { 338 LLVMAtomicOrderingNotAtomic = 0, /**< A load or store which is not atomic */ 339 LLVMAtomicOrderingUnordered = 1, /**< Lowest level of atomicity, guarantees 340 somewhat sane results, lock free. */ 341 LLVMAtomicOrderingMonotonic = 2, /**< guarantees that if you take all the 342 operations affecting a specific address, 343 a consistent ordering exists */ 344 LLVMAtomicOrderingAcquire = 4, /**< Acquire provides a barrier of the sort 345 necessary to acquire a lock to access other 346 memory with normal loads and stores. */ 347 LLVMAtomicOrderingRelease = 5, /**< Release is similar to Acquire, but with 348 a barrier of the sort necessary to release 349 a lock. */ 350 LLVMAtomicOrderingAcquireRelease = 6, /**< provides both an Acquire and a 351 Release barrier (for fences and 352 operations which both read and write 353 memory). */ 354 LLVMAtomicOrderingSequentiallyConsistent = 7 /**< provides Acquire semantics 355 for loads and Release 356 semantics for stores. 357 Additionally, it guarantees 358 that a total ordering exists 359 between all 360 SequentiallyConsistent 361 operations. */ 362 } LLVMAtomicOrdering; 363 364 typedef enum { 365 LLVMAtomicRMWBinOpXchg, /**< Set the new value and return the one old */ 366 LLVMAtomicRMWBinOpAdd, /**< Add a value and return the old one */ 367 LLVMAtomicRMWBinOpSub, /**< Subtract a value and return the old one */ 368 LLVMAtomicRMWBinOpAnd, /**< And a value and return the old one */ 369 LLVMAtomicRMWBinOpNand, /**< Not-And a value and return the old one */ 370 LLVMAtomicRMWBinOpOr, /**< OR a value and return the old one */ 371 LLVMAtomicRMWBinOpXor, /**< Xor a value and return the old one */ 372 LLVMAtomicRMWBinOpMax, /**< Sets the value if it's greater than the 373 original using a signed comparison and return 374 the old one */ 375 LLVMAtomicRMWBinOpMin, /**< Sets the value if it's Smaller than the 376 original using a signed comparison and return 377 the old one */ 378 LLVMAtomicRMWBinOpUMax, /**< Sets the value if it's greater than the 379 original using an unsigned comparison and return 380 the old one */ 381 LLVMAtomicRMWBinOpUMin, /**< Sets the value if it's greater than the 382 original using an unsigned comparison and return 383 the old one */ 384 LLVMAtomicRMWBinOpFAdd, /**< Add a floating point value and return the 385 old one */ 386 LLVMAtomicRMWBinOpFSub, /**< Subtract a floating point value and return the 387 old one */ 388 LLVMAtomicRMWBinOpFMax, /**< Sets the value if it's greater than the 389 original using an floating point comparison and 390 return the old one */ 391 LLVMAtomicRMWBinOpFMin, /**< Sets the value if it's smaller than the 392 original using an floating point comparison and 393 return the old one */ 394 LLVMAtomicRMWBinOpUIncWrap, /**< Increments the value, wrapping back to zero 395 when incremented above input value */ 396 LLVMAtomicRMWBinOpUDecWrap, /**< Decrements the value, wrapping back to 397 the input value when decremented below zero */ 398 } LLVMAtomicRMWBinOp; 399 400 typedef enum { 401 LLVMDSError, 402 LLVMDSWarning, 403 LLVMDSRemark, 404 LLVMDSNote 405 } LLVMDiagnosticSeverity; 406 407 typedef enum { 408 LLVMInlineAsmDialectATT, 409 LLVMInlineAsmDialectIntel 410 } LLVMInlineAsmDialect; 411 412 typedef enum { 413 /** 414 * Emits an error if two values disagree, otherwise the resulting value is 415 * that of the operands. 416 * 417 * @see Module::ModFlagBehavior::Error 418 */ 419 LLVMModuleFlagBehaviorError, 420 /** 421 * Emits a warning if two values disagree. The result value will be the 422 * operand for the flag from the first module being linked. 423 * 424 * @see Module::ModFlagBehavior::Warning 425 */ 426 LLVMModuleFlagBehaviorWarning, 427 /** 428 * Adds a requirement that another module flag be present and have a 429 * specified value after linking is performed. The value must be a metadata 430 * pair, where the first element of the pair is the ID of the module flag 431 * to be restricted, and the second element of the pair is the value the 432 * module flag should be restricted to. This behavior can be used to 433 * restrict the allowable results (via triggering of an error) of linking 434 * IDs with the **Override** behavior. 435 * 436 * @see Module::ModFlagBehavior::Require 437 */ 438 LLVMModuleFlagBehaviorRequire, 439 /** 440 * Uses the specified value, regardless of the behavior or value of the 441 * other module. If both modules specify **Override**, but the values 442 * differ, an error will be emitted. 443 * 444 * @see Module::ModFlagBehavior::Override 445 */ 446 LLVMModuleFlagBehaviorOverride, 447 /** 448 * Appends the two values, which are required to be metadata nodes. 449 * 450 * @see Module::ModFlagBehavior::Append 451 */ 452 LLVMModuleFlagBehaviorAppend, 453 /** 454 * Appends the two values, which are required to be metadata 455 * nodes. However, duplicate entries in the second list are dropped 456 * during the append operation. 457 * 458 * @see Module::ModFlagBehavior::AppendUnique 459 */ 460 LLVMModuleFlagBehaviorAppendUnique, 461 } LLVMModuleFlagBehavior; 462 463 /** 464 * Attribute index are either LLVMAttributeReturnIndex, 465 * LLVMAttributeFunctionIndex or a parameter number from 1 to N. 466 */ 467 enum { 468 LLVMAttributeReturnIndex = 0U, 469 // ISO C restricts enumerator values to range of 'int' 470 // (4294967295 is too large) 471 // LLVMAttributeFunctionIndex = ~0U, 472 LLVMAttributeFunctionIndex = -1, 473 }; 474 475 typedef unsigned LLVMAttributeIndex; 476 477 /** 478 * Tail call kind for LLVMSetTailCallKind and LLVMGetTailCallKind. 479 * 480 * Note that 'musttail' implies 'tail'. 481 * 482 * @see CallInst::TailCallKind 483 */ 484 typedef enum { 485 LLVMTailCallKindNone = 0, 486 LLVMTailCallKindTail = 1, 487 LLVMTailCallKindMustTail = 2, 488 LLVMTailCallKindNoTail = 3, 489 } LLVMTailCallKind; 490 491 enum { 492 LLVMFastMathAllowReassoc = (1 << 0), 493 LLVMFastMathNoNaNs = (1 << 1), 494 LLVMFastMathNoInfs = (1 << 2), 495 LLVMFastMathNoSignedZeros = (1 << 3), 496 LLVMFastMathAllowReciprocal = (1 << 4), 497 LLVMFastMathAllowContract = (1 << 5), 498 LLVMFastMathApproxFunc = (1 << 6), 499 LLVMFastMathNone = 0, 500 LLVMFastMathAll = LLVMFastMathAllowReassoc | LLVMFastMathNoNaNs | 501 LLVMFastMathNoInfs | LLVMFastMathNoSignedZeros | 502 LLVMFastMathAllowReciprocal | LLVMFastMathAllowContract | 503 LLVMFastMathApproxFunc, 504 }; 505 506 /** 507 * Flags to indicate what fast-math-style optimizations are allowed 508 * on operations. 509 * 510 * See https://llvm.org/docs/LangRef.html#fast-math-flags 511 */ 512 typedef unsigned LLVMFastMathFlags; 513 514 enum { 515 LLVMGEPFlagInBounds = (1 << 0), 516 LLVMGEPFlagNUSW = (1 << 1), 517 LLVMGEPFlagNUW = (1 << 2), 518 }; 519 520 /** 521 * Flags that constrain the allowed wrap semantics of a getelementptr 522 * instruction. 523 * 524 * See https://llvm.org/docs/LangRef.html#getelementptr-instruction 525 */ 526 typedef unsigned LLVMGEPNoWrapFlags; 527 528 /** 529 * @} 530 */ 531 532 /** Deallocate and destroy all ManagedStatic variables. 533 @see llvm::llvm_shutdown 534 @see ManagedStatic */ 535 void LLVMShutdown(void); 536 537 /*===-- Version query -----------------------------------------------------===*/ 538 539 /** 540 * Return the major, minor, and patch version of LLVM 541 * 542 * The version components are returned via the function's three output 543 * parameters or skipped if a NULL pointer was supplied. 544 */ 545 void LLVMGetVersion(unsigned *Major, unsigned *Minor, unsigned *Patch); 546 547 /*===-- Error handling ----------------------------------------------------===*/ 548 549 char *LLVMCreateMessage(const char *Message); 550 void LLVMDisposeMessage(char *Message); 551 552 /** 553 * @defgroup LLVMCCoreContext Contexts 554 * 555 * Contexts are execution states for the core LLVM IR system. 556 * 557 * Most types are tied to a context instance. Multiple contexts can 558 * exist simultaneously. A single context is not thread safe. However, 559 * different contexts can execute on different threads simultaneously. 560 * 561 * @{ 562 */ 563 564 typedef void (*LLVMDiagnosticHandler)(LLVMDiagnosticInfoRef, void *); 565 typedef void (*LLVMYieldCallback)(LLVMContextRef, void *); 566 567 /** 568 * Create a new context. 569 * 570 * Every call to this function should be paired with a call to 571 * LLVMContextDispose() or the context will leak memory. 572 */ 573 LLVMContextRef LLVMContextCreate(void); 574 575 /** 576 * Obtain the global context instance. 577 */ 578 LLVMContextRef LLVMGetGlobalContext(void); 579 580 /** 581 * Set the diagnostic handler for this context. 582 */ 583 void LLVMContextSetDiagnosticHandler(LLVMContextRef C, 584 LLVMDiagnosticHandler Handler, 585 void *DiagnosticContext); 586 587 /** 588 * Get the diagnostic handler of this context. 589 */ 590 LLVMDiagnosticHandler LLVMContextGetDiagnosticHandler(LLVMContextRef C); 591 592 /** 593 * Get the diagnostic context of this context. 594 */ 595 void *LLVMContextGetDiagnosticContext(LLVMContextRef C); 596 597 /** 598 * Set the yield callback function for this context. 599 * 600 * @see LLVMContext::setYieldCallback() 601 */ 602 void LLVMContextSetYieldCallback(LLVMContextRef C, LLVMYieldCallback Callback, 603 void *OpaqueHandle); 604 605 /** 606 * Retrieve whether the given context is set to discard all value names. 607 * 608 * @see LLVMContext::shouldDiscardValueNames() 609 */ 610 LLVMBool LLVMContextShouldDiscardValueNames(LLVMContextRef C); 611 612 /** 613 * Set whether the given context discards all value names. 614 * 615 * If true, only the names of GlobalValue objects will be available in the IR. 616 * This can be used to save memory and runtime, especially in release mode. 617 * 618 * @see LLVMContext::setDiscardValueNames() 619 */ 620 void LLVMContextSetDiscardValueNames(LLVMContextRef C, LLVMBool Discard); 621 622 /** 623 * Destroy a context instance. 624 * 625 * This should be called for every call to LLVMContextCreate() or memory 626 * will be leaked. 627 */ 628 void LLVMContextDispose(LLVMContextRef C); 629 630 /** 631 * Return a string representation of the DiagnosticInfo. Use 632 * LLVMDisposeMessage to free the string. 633 * 634 * @see DiagnosticInfo::print() 635 */ 636 char *LLVMGetDiagInfoDescription(LLVMDiagnosticInfoRef DI); 637 638 /** 639 * Return an enum LLVMDiagnosticSeverity. 640 * 641 * @see DiagnosticInfo::getSeverity() 642 */ 643 LLVMDiagnosticSeverity LLVMGetDiagInfoSeverity(LLVMDiagnosticInfoRef DI); 644 645 unsigned LLVMGetMDKindIDInContext(LLVMContextRef C, const char *Name, 646 unsigned SLen); 647 unsigned LLVMGetMDKindID(const char *Name, unsigned SLen); 648 649 /** 650 * Return an unique id given the name of a enum attribute, 651 * or 0 if no attribute by that name exists. 652 * 653 * See http://llvm.org/docs/LangRef.html#parameter-attributes 654 * and http://llvm.org/docs/LangRef.html#function-attributes 655 * for the list of available attributes. 656 * 657 * NB: Attribute names and/or id are subject to change without 658 * going through the C API deprecation cycle. 659 */ 660 unsigned LLVMGetEnumAttributeKindForName(const char *Name, size_t SLen); 661 unsigned LLVMGetLastEnumAttributeKind(void); 662 663 /** 664 * Create an enum attribute. 665 */ 666 LLVMAttributeRef LLVMCreateEnumAttribute(LLVMContextRef C, unsigned KindID, 667 uint64_t Val); 668 669 /** 670 * Get the unique id corresponding to the enum attribute 671 * passed as argument. 672 */ 673 unsigned LLVMGetEnumAttributeKind(LLVMAttributeRef A); 674 675 /** 676 * Get the enum attribute's value. 0 is returned if none exists. 677 */ 678 uint64_t LLVMGetEnumAttributeValue(LLVMAttributeRef A); 679 680 /** 681 * Create a type attribute 682 */ 683 LLVMAttributeRef LLVMCreateTypeAttribute(LLVMContextRef C, unsigned KindID, 684 LLVMTypeRef type_ref); 685 686 /** 687 * Get the type attribute's value. 688 */ 689 LLVMTypeRef LLVMGetTypeAttributeValue(LLVMAttributeRef A); 690 691 /** 692 * Create a ConstantRange attribute. 693 * 694 * LowerWords and UpperWords need to be NumBits divided by 64 rounded up 695 * elements long. 696 */ 697 LLVMAttributeRef LLVMCreateConstantRangeAttribute(LLVMContextRef C, 698 unsigned KindID, 699 unsigned NumBits, 700 const uint64_t LowerWords[], 701 const uint64_t UpperWords[]); 702 703 /** 704 * Create a string attribute. 705 */ 706 LLVMAttributeRef LLVMCreateStringAttribute(LLVMContextRef C, 707 const char *K, unsigned KLength, 708 const char *V, unsigned VLength); 709 710 /** 711 * Get the string attribute's kind. 712 */ 713 const char *LLVMGetStringAttributeKind(LLVMAttributeRef A, unsigned *Length); 714 715 /** 716 * Get the string attribute's value. 717 */ 718 const char *LLVMGetStringAttributeValue(LLVMAttributeRef A, unsigned *Length); 719 720 /** 721 * Check for the different types of attributes. 722 */ 723 LLVMBool LLVMIsEnumAttribute(LLVMAttributeRef A); 724 LLVMBool LLVMIsStringAttribute(LLVMAttributeRef A); 725 LLVMBool LLVMIsTypeAttribute(LLVMAttributeRef A); 726 727 /** 728 * Obtain a Type from a context by its registered name. 729 */ 730 LLVMTypeRef LLVMGetTypeByName2(LLVMContextRef C, const char *Name); 731 732 /** 733 * @} 734 */ 735 736 /** 737 * @defgroup LLVMCCoreModule Modules 738 * 739 * Modules represent the top-level structure in an LLVM program. An LLVM 740 * module is effectively a translation unit or a collection of 741 * translation units merged together. 742 * 743 * @{ 744 */ 745 746 /** 747 * Create a new, empty module in the global context. 748 * 749 * This is equivalent to calling LLVMModuleCreateWithNameInContext with 750 * LLVMGetGlobalContext() as the context parameter. 751 * 752 * Every invocation should be paired with LLVMDisposeModule() or memory 753 * will be leaked. 754 */ 755 LLVMModuleRef LLVMModuleCreateWithName(const char *ModuleID); 756 757 /** 758 * Create a new, empty module in a specific context. 759 * 760 * Every invocation should be paired with LLVMDisposeModule() or memory 761 * will be leaked. 762 */ 763 LLVMModuleRef LLVMModuleCreateWithNameInContext(const char *ModuleID, 764 LLVMContextRef C); 765 /** 766 * Return an exact copy of the specified module. 767 */ 768 LLVMModuleRef LLVMCloneModule(LLVMModuleRef M); 769 770 /** 771 * Destroy a module instance. 772 * 773 * This must be called for every created module or memory will be 774 * leaked. 775 */ 776 void LLVMDisposeModule(LLVMModuleRef M); 777 778 /** 779 * Soon to be deprecated. 780 * See https://llvm.org/docs/RemoveDIsDebugInfo.html#c-api-changes 781 * 782 * Returns true if the module is in the new debug info mode which uses 783 * non-instruction debug records instead of debug intrinsics for variable 784 * location tracking. 785 */ 786 LLVMBool LLVMIsNewDbgInfoFormat(LLVMModuleRef M); 787 788 /** 789 * Soon to be deprecated. 790 * See https://llvm.org/docs/RemoveDIsDebugInfo.html#c-api-changes 791 * 792 * Convert module into desired debug info format. 793 */ 794 void LLVMSetIsNewDbgInfoFormat(LLVMModuleRef M, LLVMBool UseNewFormat); 795 796 /** 797 * Obtain the identifier of a module. 798 * 799 * @param M Module to obtain identifier of 800 * @param Len Out parameter which holds the length of the returned string. 801 * @return The identifier of M. 802 * @see Module::getModuleIdentifier() 803 */ 804 const char *LLVMGetModuleIdentifier(LLVMModuleRef M, size_t *Len); 805 806 /** 807 * Set the identifier of a module to a string Ident with length Len. 808 * 809 * @param M The module to set identifier 810 * @param Ident The string to set M's identifier to 811 * @param Len Length of Ident 812 * @see Module::setModuleIdentifier() 813 */ 814 void LLVMSetModuleIdentifier(LLVMModuleRef M, const char *Ident, size_t Len); 815 816 /** 817 * Obtain the module's original source file name. 818 * 819 * @param M Module to obtain the name of 820 * @param Len Out parameter which holds the length of the returned string 821 * @return The original source file name of M 822 * @see Module::getSourceFileName() 823 */ 824 const char *LLVMGetSourceFileName(LLVMModuleRef M, size_t *Len); 825 826 /** 827 * Set the original source file name of a module to a string Name with length 828 * Len. 829 * 830 * @param M The module to set the source file name of 831 * @param Name The string to set M's source file name to 832 * @param Len Length of Name 833 * @see Module::setSourceFileName() 834 */ 835 void LLVMSetSourceFileName(LLVMModuleRef M, const char *Name, size_t Len); 836 837 /** 838 * Obtain the data layout for a module. 839 * 840 * @see Module::getDataLayoutStr() 841 * 842 * LLVMGetDataLayout is DEPRECATED, as the name is not only incorrect, 843 * but match the name of another method on the module. Prefer the use 844 * of LLVMGetDataLayoutStr, which is not ambiguous. 845 */ 846 const char *LLVMGetDataLayoutStr(LLVMModuleRef M); 847 const char *LLVMGetDataLayout(LLVMModuleRef M); 848 849 /** 850 * Set the data layout for a module. 851 * 852 * @see Module::setDataLayout() 853 */ 854 void LLVMSetDataLayout(LLVMModuleRef M, const char *DataLayoutStr); 855 856 /** 857 * Obtain the target triple for a module. 858 * 859 * @see Module::getTargetTriple() 860 */ 861 const char *LLVMGetTarget(LLVMModuleRef M); 862 863 /** 864 * Set the target triple for a module. 865 * 866 * @see Module::setTargetTriple() 867 */ 868 void LLVMSetTarget(LLVMModuleRef M, const char *Triple); 869 870 /** 871 * Returns the module flags as an array of flag-key-value triples. The caller 872 * is responsible for freeing this array by calling 873 * \c LLVMDisposeModuleFlagsMetadata. 874 * 875 * @see Module::getModuleFlagsMetadata() 876 */ 877 LLVMModuleFlagEntry *LLVMCopyModuleFlagsMetadata(LLVMModuleRef M, size_t *Len); 878 879 /** 880 * Destroys module flags metadata entries. 881 */ 882 void LLVMDisposeModuleFlagsMetadata(LLVMModuleFlagEntry *Entries); 883 884 /** 885 * Returns the flag behavior for a module flag entry at a specific index. 886 * 887 * @see Module::ModuleFlagEntry::Behavior 888 */ 889 LLVMModuleFlagBehavior 890 LLVMModuleFlagEntriesGetFlagBehavior(LLVMModuleFlagEntry *Entries, 891 unsigned Index); 892 893 /** 894 * Returns the key for a module flag entry at a specific index. 895 * 896 * @see Module::ModuleFlagEntry::Key 897 */ 898 const char *LLVMModuleFlagEntriesGetKey(LLVMModuleFlagEntry *Entries, 899 unsigned Index, size_t *Len); 900 901 /** 902 * Returns the metadata for a module flag entry at a specific index. 903 * 904 * @see Module::ModuleFlagEntry::Val 905 */ 906 LLVMMetadataRef LLVMModuleFlagEntriesGetMetadata(LLVMModuleFlagEntry *Entries, 907 unsigned Index); 908 909 /** 910 * Add a module-level flag to the module-level flags metadata if it doesn't 911 * already exist. 912 * 913 * @see Module::getModuleFlag() 914 */ 915 LLVMMetadataRef LLVMGetModuleFlag(LLVMModuleRef M, 916 const char *Key, size_t KeyLen); 917 918 /** 919 * Add a module-level flag to the module-level flags metadata if it doesn't 920 * already exist. 921 * 922 * @see Module::addModuleFlag() 923 */ 924 void LLVMAddModuleFlag(LLVMModuleRef M, LLVMModuleFlagBehavior Behavior, 925 const char *Key, size_t KeyLen, 926 LLVMMetadataRef Val); 927 928 /** 929 * Dump a representation of a module to stderr. 930 * 931 * @see Module::dump() 932 */ 933 void LLVMDumpModule(LLVMModuleRef M); 934 935 /** 936 * Print a representation of a module to a file. The ErrorMessage needs to be 937 * disposed with LLVMDisposeMessage. Returns 0 on success, 1 otherwise. 938 * 939 * @see Module::print() 940 */ 941 LLVMBool LLVMPrintModuleToFile(LLVMModuleRef M, const char *Filename, 942 char **ErrorMessage); 943 944 /** 945 * Return a string representation of the module. Use 946 * LLVMDisposeMessage to free the string. 947 * 948 * @see Module::print() 949 */ 950 char *LLVMPrintModuleToString(LLVMModuleRef M); 951 952 /** 953 * Get inline assembly for a module. 954 * 955 * @see Module::getModuleInlineAsm() 956 */ 957 const char *LLVMGetModuleInlineAsm(LLVMModuleRef M, size_t *Len); 958 959 /** 960 * Set inline assembly for a module. 961 * 962 * @see Module::setModuleInlineAsm() 963 */ 964 void LLVMSetModuleInlineAsm2(LLVMModuleRef M, const char *Asm, size_t Len); 965 966 /** 967 * Append inline assembly to a module. 968 * 969 * @see Module::appendModuleInlineAsm() 970 */ 971 void LLVMAppendModuleInlineAsm(LLVMModuleRef M, const char *Asm, size_t Len); 972 973 /** 974 * Create the specified uniqued inline asm string. 975 * 976 * @see InlineAsm::get() 977 */ 978 LLVMValueRef LLVMGetInlineAsm(LLVMTypeRef Ty, const char *AsmString, 979 size_t AsmStringSize, const char *Constraints, 980 size_t ConstraintsSize, LLVMBool HasSideEffects, 981 LLVMBool IsAlignStack, 982 LLVMInlineAsmDialect Dialect, LLVMBool CanThrow); 983 984 /** 985 * Get the template string used for an inline assembly snippet 986 * 987 */ 988 const char *LLVMGetInlineAsmAsmString(LLVMValueRef InlineAsmVal, size_t *Len); 989 990 /** 991 * Get the raw constraint string for an inline assembly snippet 992 * 993 */ 994 const char *LLVMGetInlineAsmConstraintString(LLVMValueRef InlineAsmVal, 995 size_t *Len); 996 997 /** 998 * Get the dialect used by the inline asm snippet 999 * 1000 */ 1001 LLVMInlineAsmDialect LLVMGetInlineAsmDialect(LLVMValueRef InlineAsmVal); 1002 1003 /** 1004 * Get the function type of the inline assembly snippet. The same type that 1005 * was passed into LLVMGetInlineAsm originally 1006 * 1007 * @see LLVMGetInlineAsm 1008 * 1009 */ 1010 LLVMTypeRef LLVMGetInlineAsmFunctionType(LLVMValueRef InlineAsmVal); 1011 1012 /** 1013 * Get if the inline asm snippet has side effects 1014 * 1015 */ 1016 LLVMBool LLVMGetInlineAsmHasSideEffects(LLVMValueRef InlineAsmVal); 1017 1018 /** 1019 * Get if the inline asm snippet needs an aligned stack 1020 * 1021 */ 1022 LLVMBool LLVMGetInlineAsmNeedsAlignedStack(LLVMValueRef InlineAsmVal); 1023 1024 /** 1025 * Get if the inline asm snippet may unwind the stack 1026 * 1027 */ 1028 LLVMBool LLVMGetInlineAsmCanUnwind(LLVMValueRef InlineAsmVal); 1029 1030 /** 1031 * Obtain the context to which this module is associated. 1032 * 1033 * @see Module::getContext() 1034 */ 1035 LLVMContextRef LLVMGetModuleContext(LLVMModuleRef M); 1036 1037 /** Deprecated: Use LLVMGetTypeByName2 instead. */ 1038 LLVMTypeRef LLVMGetTypeByName(LLVMModuleRef M, const char *Name); 1039 1040 /** 1041 * Obtain an iterator to the first NamedMDNode in a Module. 1042 * 1043 * @see llvm::Module::named_metadata_begin() 1044 */ 1045 LLVMNamedMDNodeRef LLVMGetFirstNamedMetadata(LLVMModuleRef M); 1046 1047 /** 1048 * Obtain an iterator to the last NamedMDNode in a Module. 1049 * 1050 * @see llvm::Module::named_metadata_end() 1051 */ 1052 LLVMNamedMDNodeRef LLVMGetLastNamedMetadata(LLVMModuleRef M); 1053 1054 /** 1055 * Advance a NamedMDNode iterator to the next NamedMDNode. 1056 * 1057 * Returns NULL if the iterator was already at the end and there are no more 1058 * named metadata nodes. 1059 */ 1060 LLVMNamedMDNodeRef LLVMGetNextNamedMetadata(LLVMNamedMDNodeRef NamedMDNode); 1061 1062 /** 1063 * Decrement a NamedMDNode iterator to the previous NamedMDNode. 1064 * 1065 * Returns NULL if the iterator was already at the beginning and there are 1066 * no previous named metadata nodes. 1067 */ 1068 LLVMNamedMDNodeRef LLVMGetPreviousNamedMetadata(LLVMNamedMDNodeRef NamedMDNode); 1069 1070 /** 1071 * Retrieve a NamedMDNode with the given name, returning NULL if no such 1072 * node exists. 1073 * 1074 * @see llvm::Module::getNamedMetadata() 1075 */ 1076 LLVMNamedMDNodeRef LLVMGetNamedMetadata(LLVMModuleRef M, 1077 const char *Name, size_t NameLen); 1078 1079 /** 1080 * Retrieve a NamedMDNode with the given name, creating a new node if no such 1081 * node exists. 1082 * 1083 * @see llvm::Module::getOrInsertNamedMetadata() 1084 */ 1085 LLVMNamedMDNodeRef LLVMGetOrInsertNamedMetadata(LLVMModuleRef M, 1086 const char *Name, 1087 size_t NameLen); 1088 1089 /** 1090 * Retrieve the name of a NamedMDNode. 1091 * 1092 * @see llvm::NamedMDNode::getName() 1093 */ 1094 const char *LLVMGetNamedMetadataName(LLVMNamedMDNodeRef NamedMD, 1095 size_t *NameLen); 1096 1097 /** 1098 * Obtain the number of operands for named metadata in a module. 1099 * 1100 * @see llvm::Module::getNamedMetadata() 1101 */ 1102 unsigned LLVMGetNamedMetadataNumOperands(LLVMModuleRef M, const char *Name); 1103 1104 /** 1105 * Obtain the named metadata operands for a module. 1106 * 1107 * The passed LLVMValueRef pointer should refer to an array of 1108 * LLVMValueRef at least LLVMGetNamedMetadataNumOperands long. This 1109 * array will be populated with the LLVMValueRef instances. Each 1110 * instance corresponds to a llvm::MDNode. 1111 * 1112 * @see llvm::Module::getNamedMetadata() 1113 * @see llvm::MDNode::getOperand() 1114 */ 1115 void LLVMGetNamedMetadataOperands(LLVMModuleRef M, const char *Name, 1116 LLVMValueRef *Dest); 1117 1118 /** 1119 * Add an operand to named metadata. 1120 * 1121 * @see llvm::Module::getNamedMetadata() 1122 * @see llvm::MDNode::addOperand() 1123 */ 1124 void LLVMAddNamedMetadataOperand(LLVMModuleRef M, const char *Name, 1125 LLVMValueRef Val); 1126 1127 /** 1128 * Return the directory of the debug location for this value, which must be 1129 * an llvm::Instruction, llvm::GlobalVariable, or llvm::Function. 1130 * 1131 * @see llvm::Instruction::getDebugLoc() 1132 * @see llvm::GlobalVariable::getDebugInfo() 1133 * @see llvm::Function::getSubprogram() 1134 */ 1135 const char *LLVMGetDebugLocDirectory(LLVMValueRef Val, unsigned *Length); 1136 1137 /** 1138 * Return the filename of the debug location for this value, which must be 1139 * an llvm::Instruction, llvm::GlobalVariable, or llvm::Function. 1140 * 1141 * @see llvm::Instruction::getDebugLoc() 1142 * @see llvm::GlobalVariable::getDebugInfo() 1143 * @see llvm::Function::getSubprogram() 1144 */ 1145 const char *LLVMGetDebugLocFilename(LLVMValueRef Val, unsigned *Length); 1146 1147 /** 1148 * Return the line number of the debug location for this value, which must be 1149 * an llvm::Instruction, llvm::GlobalVariable, or llvm::Function. 1150 * 1151 * @see llvm::Instruction::getDebugLoc() 1152 * @see llvm::GlobalVariable::getDebugInfo() 1153 * @see llvm::Function::getSubprogram() 1154 */ 1155 unsigned LLVMGetDebugLocLine(LLVMValueRef Val); 1156 1157 /** 1158 * Return the column number of the debug location for this value, which must be 1159 * an llvm::Instruction. 1160 * 1161 * @see llvm::Instruction::getDebugLoc() 1162 */ 1163 unsigned LLVMGetDebugLocColumn(LLVMValueRef Val); 1164 1165 /** 1166 * Add a function to a module under a specified name. 1167 * 1168 * @see llvm::Function::Create() 1169 */ 1170 LLVMValueRef LLVMAddFunction(LLVMModuleRef M, const char *Name, 1171 LLVMTypeRef FunctionTy); 1172 1173 /** 1174 * Obtain a Function value from a Module by its name. 1175 * 1176 * The returned value corresponds to a llvm::Function value. 1177 * 1178 * @see llvm::Module::getFunction() 1179 */ 1180 LLVMValueRef LLVMGetNamedFunction(LLVMModuleRef M, const char *Name); 1181 1182 /** 1183 * Obtain an iterator to the first Function in a Module. 1184 * 1185 * @see llvm::Module::begin() 1186 */ 1187 LLVMValueRef LLVMGetFirstFunction(LLVMModuleRef M); 1188 1189 /** 1190 * Obtain an iterator to the last Function in a Module. 1191 * 1192 * @see llvm::Module::end() 1193 */ 1194 LLVMValueRef LLVMGetLastFunction(LLVMModuleRef M); 1195 1196 /** 1197 * Advance a Function iterator to the next Function. 1198 * 1199 * Returns NULL if the iterator was already at the end and there are no more 1200 * functions. 1201 */ 1202 LLVMValueRef LLVMGetNextFunction(LLVMValueRef Fn); 1203 1204 /** 1205 * Decrement a Function iterator to the previous Function. 1206 * 1207 * Returns NULL if the iterator was already at the beginning and there are 1208 * no previous functions. 1209 */ 1210 LLVMValueRef LLVMGetPreviousFunction(LLVMValueRef Fn); 1211 1212 /** Deprecated: Use LLVMSetModuleInlineAsm2 instead. */ 1213 void LLVMSetModuleInlineAsm(LLVMModuleRef M, const char *Asm); 1214 1215 /** 1216 * @} 1217 */ 1218 1219 /** 1220 * @defgroup LLVMCCoreType Types 1221 * 1222 * Types represent the type of a value. 1223 * 1224 * Types are associated with a context instance. The context internally 1225 * deduplicates types so there is only 1 instance of a specific type 1226 * alive at a time. In other words, a unique type is shared among all 1227 * consumers within a context. 1228 * 1229 * A Type in the C API corresponds to llvm::Type. 1230 * 1231 * Types have the following hierarchy: 1232 * 1233 * types: 1234 * integer type 1235 * real type 1236 * function type 1237 * sequence types: 1238 * array type 1239 * pointer type 1240 * vector type 1241 * void type 1242 * label type 1243 * opaque type 1244 * 1245 * @{ 1246 */ 1247 1248 /** 1249 * Obtain the enumerated type of a Type instance. 1250 * 1251 * @see llvm::Type:getTypeID() 1252 */ 1253 LLVMTypeKind LLVMGetTypeKind(LLVMTypeRef Ty); 1254 1255 /** 1256 * Whether the type has a known size. 1257 * 1258 * Things that don't have a size are abstract types, labels, and void.a 1259 * 1260 * @see llvm::Type::isSized() 1261 */ 1262 LLVMBool LLVMTypeIsSized(LLVMTypeRef Ty); 1263 1264 /** 1265 * Obtain the context to which this type instance is associated. 1266 * 1267 * @see llvm::Type::getContext() 1268 */ 1269 LLVMContextRef LLVMGetTypeContext(LLVMTypeRef Ty); 1270 1271 /** 1272 * Dump a representation of a type to stderr. 1273 * 1274 * @see llvm::Type::dump() 1275 */ 1276 void LLVMDumpType(LLVMTypeRef Val); 1277 1278 /** 1279 * Return a string representation of the type. Use 1280 * LLVMDisposeMessage to free the string. 1281 * 1282 * @see llvm::Type::print() 1283 */ 1284 char *LLVMPrintTypeToString(LLVMTypeRef Val); 1285 1286 /** 1287 * @defgroup LLVMCCoreTypeInt Integer Types 1288 * 1289 * Functions in this section operate on integer types. 1290 * 1291 * @{ 1292 */ 1293 1294 /** 1295 * Obtain an integer type from a context with specified bit width. 1296 */ 1297 LLVMTypeRef LLVMInt1TypeInContext(LLVMContextRef C); 1298 LLVMTypeRef LLVMInt8TypeInContext(LLVMContextRef C); 1299 LLVMTypeRef LLVMInt16TypeInContext(LLVMContextRef C); 1300 LLVMTypeRef LLVMInt32TypeInContext(LLVMContextRef C); 1301 LLVMTypeRef LLVMInt64TypeInContext(LLVMContextRef C); 1302 LLVMTypeRef LLVMInt128TypeInContext(LLVMContextRef C); 1303 LLVMTypeRef LLVMIntTypeInContext(LLVMContextRef C, unsigned NumBits); 1304 1305 /** 1306 * Obtain an integer type from the global context with a specified bit 1307 * width. 1308 */ 1309 LLVMTypeRef LLVMInt1Type(void); 1310 LLVMTypeRef LLVMInt8Type(void); 1311 LLVMTypeRef LLVMInt16Type(void); 1312 LLVMTypeRef LLVMInt32Type(void); 1313 LLVMTypeRef LLVMInt64Type(void); 1314 LLVMTypeRef LLVMInt128Type(void); 1315 LLVMTypeRef LLVMIntType(unsigned NumBits); 1316 unsigned LLVMGetIntTypeWidth(LLVMTypeRef IntegerTy); 1317 1318 /** 1319 * @} 1320 */ 1321 1322 /** 1323 * @defgroup LLVMCCoreTypeFloat Floating Point Types 1324 * 1325 * @{ 1326 */ 1327 1328 /** 1329 * Obtain a 16-bit floating point type from a context. 1330 */ 1331 LLVMTypeRef LLVMHalfTypeInContext(LLVMContextRef C); 1332 1333 /** 1334 * Obtain a 16-bit brain floating point type from a context. 1335 */ 1336 LLVMTypeRef LLVMBFloatTypeInContext(LLVMContextRef C); 1337 1338 /** 1339 * Obtain a 32-bit floating point type from a context. 1340 */ 1341 LLVMTypeRef LLVMFloatTypeInContext(LLVMContextRef C); 1342 1343 /** 1344 * Obtain a 64-bit floating point type from a context. 1345 */ 1346 LLVMTypeRef LLVMDoubleTypeInContext(LLVMContextRef C); 1347 1348 /** 1349 * Obtain a 80-bit floating point type (X87) from a context. 1350 */ 1351 LLVMTypeRef LLVMX86FP80TypeInContext(LLVMContextRef C); 1352 1353 /** 1354 * Obtain a 128-bit floating point type (112-bit mantissa) from a 1355 * context. 1356 */ 1357 LLVMTypeRef LLVMFP128TypeInContext(LLVMContextRef C); 1358 1359 /** 1360 * Obtain a 128-bit floating point type (two 64-bits) from a context. 1361 */ 1362 LLVMTypeRef LLVMPPCFP128TypeInContext(LLVMContextRef C); 1363 1364 /** 1365 * Obtain a floating point type from the global context. 1366 * 1367 * These map to the functions in this group of the same name. 1368 */ 1369 LLVMTypeRef LLVMHalfType(void); 1370 LLVMTypeRef LLVMBFloatType(void); 1371 LLVMTypeRef LLVMFloatType(void); 1372 LLVMTypeRef LLVMDoubleType(void); 1373 LLVMTypeRef LLVMX86FP80Type(void); 1374 LLVMTypeRef LLVMFP128Type(void); 1375 LLVMTypeRef LLVMPPCFP128Type(void); 1376 1377 /** 1378 * @} 1379 */ 1380 1381 /** 1382 * @defgroup LLVMCCoreTypeFunction Function Types 1383 * 1384 * @{ 1385 */ 1386 1387 /** 1388 * Obtain a function type consisting of a specified signature. 1389 * 1390 * The function is defined as a tuple of a return Type, a list of 1391 * parameter types, and whether the function is variadic. 1392 */ 1393 LLVMTypeRef LLVMFunctionType(LLVMTypeRef ReturnType, 1394 LLVMTypeRef *ParamTypes, unsigned ParamCount, 1395 LLVMBool IsVarArg); 1396 1397 /** 1398 * Returns whether a function type is variadic. 1399 */ 1400 LLVMBool LLVMIsFunctionVarArg(LLVMTypeRef FunctionTy); 1401 1402 /** 1403 * Obtain the Type this function Type returns. 1404 */ 1405 LLVMTypeRef LLVMGetReturnType(LLVMTypeRef FunctionTy); 1406 1407 /** 1408 * Obtain the number of parameters this function accepts. 1409 */ 1410 unsigned LLVMCountParamTypes(LLVMTypeRef FunctionTy); 1411 1412 /** 1413 * Obtain the types of a function's parameters. 1414 * 1415 * The Dest parameter should point to a pre-allocated array of 1416 * LLVMTypeRef at least LLVMCountParamTypes() large. On return, the 1417 * first LLVMCountParamTypes() entries in the array will be populated 1418 * with LLVMTypeRef instances. 1419 * 1420 * @param FunctionTy The function type to operate on. 1421 * @param Dest Memory address of an array to be filled with result. 1422 */ 1423 void LLVMGetParamTypes(LLVMTypeRef FunctionTy, LLVMTypeRef *Dest); 1424 1425 /** 1426 * @} 1427 */ 1428 1429 /** 1430 * @defgroup LLVMCCoreTypeStruct Structure Types 1431 * 1432 * These functions relate to LLVMTypeRef instances. 1433 * 1434 * @see llvm::StructType 1435 * 1436 * @{ 1437 */ 1438 1439 /** 1440 * Create a new structure type in a context. 1441 * 1442 * A structure is specified by a list of inner elements/types and 1443 * whether these can be packed together. 1444 * 1445 * @see llvm::StructType::create() 1446 */ 1447 LLVMTypeRef LLVMStructTypeInContext(LLVMContextRef C, LLVMTypeRef *ElementTypes, 1448 unsigned ElementCount, LLVMBool Packed); 1449 1450 /** 1451 * Create a new structure type in the global context. 1452 * 1453 * @see llvm::StructType::create() 1454 */ 1455 LLVMTypeRef LLVMStructType(LLVMTypeRef *ElementTypes, unsigned ElementCount, 1456 LLVMBool Packed); 1457 1458 /** 1459 * Create an empty structure in a context having a specified name. 1460 * 1461 * @see llvm::StructType::create() 1462 */ 1463 LLVMTypeRef LLVMStructCreateNamed(LLVMContextRef C, const char *Name); 1464 1465 /** 1466 * Obtain the name of a structure. 1467 * 1468 * @see llvm::StructType::getName() 1469 */ 1470 const char *LLVMGetStructName(LLVMTypeRef Ty); 1471 1472 /** 1473 * Set the contents of a structure type. 1474 * 1475 * @see llvm::StructType::setBody() 1476 */ 1477 void LLVMStructSetBody(LLVMTypeRef StructTy, LLVMTypeRef *ElementTypes, 1478 unsigned ElementCount, LLVMBool Packed); 1479 1480 /** 1481 * Get the number of elements defined inside the structure. 1482 * 1483 * @see llvm::StructType::getNumElements() 1484 */ 1485 unsigned LLVMCountStructElementTypes(LLVMTypeRef StructTy); 1486 1487 /** 1488 * Get the elements within a structure. 1489 * 1490 * The function is passed the address of a pre-allocated array of 1491 * LLVMTypeRef at least LLVMCountStructElementTypes() long. After 1492 * invocation, this array will be populated with the structure's 1493 * elements. The objects in the destination array will have a lifetime 1494 * of the structure type itself, which is the lifetime of the context it 1495 * is contained in. 1496 */ 1497 void LLVMGetStructElementTypes(LLVMTypeRef StructTy, LLVMTypeRef *Dest); 1498 1499 /** 1500 * Get the type of the element at a given index in the structure. 1501 * 1502 * @see llvm::StructType::getTypeAtIndex() 1503 */ 1504 LLVMTypeRef LLVMStructGetTypeAtIndex(LLVMTypeRef StructTy, unsigned i); 1505 1506 /** 1507 * Determine whether a structure is packed. 1508 * 1509 * @see llvm::StructType::isPacked() 1510 */ 1511 LLVMBool LLVMIsPackedStruct(LLVMTypeRef StructTy); 1512 1513 /** 1514 * Determine whether a structure is opaque. 1515 * 1516 * @see llvm::StructType::isOpaque() 1517 */ 1518 LLVMBool LLVMIsOpaqueStruct(LLVMTypeRef StructTy); 1519 1520 /** 1521 * Determine whether a structure is literal. 1522 * 1523 * @see llvm::StructType::isLiteral() 1524 */ 1525 LLVMBool LLVMIsLiteralStruct(LLVMTypeRef StructTy); 1526 1527 /** 1528 * @} 1529 */ 1530 1531 /** 1532 * @defgroup LLVMCCoreTypeSequential Sequential Types 1533 * 1534 * Sequential types represents "arrays" of types. This is a super class 1535 * for array, vector, and pointer types. 1536 * 1537 * @{ 1538 */ 1539 1540 /** 1541 * Obtain the element type of an array or vector type. 1542 * 1543 * @see llvm::SequentialType::getElementType() 1544 */ 1545 LLVMTypeRef LLVMGetElementType(LLVMTypeRef Ty); 1546 1547 /** 1548 * Returns type's subtypes 1549 * 1550 * @see llvm::Type::subtypes() 1551 */ 1552 void LLVMGetSubtypes(LLVMTypeRef Tp, LLVMTypeRef *Arr); 1553 1554 /** 1555 * Return the number of types in the derived type. 1556 * 1557 * @see llvm::Type::getNumContainedTypes() 1558 */ 1559 unsigned LLVMGetNumContainedTypes(LLVMTypeRef Tp); 1560 1561 /** 1562 * Create a fixed size array type that refers to a specific type. 1563 * 1564 * The created type will exist in the context that its element type 1565 * exists in. 1566 * 1567 * @deprecated LLVMArrayType is deprecated in favor of the API accurate 1568 * LLVMArrayType2 1569 * @see llvm::ArrayType::get() 1570 */ 1571 LLVMTypeRef LLVMArrayType(LLVMTypeRef ElementType, unsigned ElementCount); 1572 1573 /** 1574 * Create a fixed size array type that refers to a specific type. 1575 * 1576 * The created type will exist in the context that its element type 1577 * exists in. 1578 * 1579 * @see llvm::ArrayType::get() 1580 */ 1581 LLVMTypeRef LLVMArrayType2(LLVMTypeRef ElementType, uint64_t ElementCount); 1582 1583 /** 1584 * Obtain the length of an array type. 1585 * 1586 * This only works on types that represent arrays. 1587 * 1588 * @deprecated LLVMGetArrayLength is deprecated in favor of the API accurate 1589 * LLVMGetArrayLength2 1590 * @see llvm::ArrayType::getNumElements() 1591 */ 1592 unsigned LLVMGetArrayLength(LLVMTypeRef ArrayTy); 1593 1594 /** 1595 * Obtain the length of an array type. 1596 * 1597 * This only works on types that represent arrays. 1598 * 1599 * @see llvm::ArrayType::getNumElements() 1600 */ 1601 uint64_t LLVMGetArrayLength2(LLVMTypeRef ArrayTy); 1602 1603 /** 1604 * Create a pointer type that points to a defined type. 1605 * 1606 * The created type will exist in the context that its pointee type 1607 * exists in. 1608 * 1609 * @see llvm::PointerType::get() 1610 */ 1611 LLVMTypeRef LLVMPointerType(LLVMTypeRef ElementType, unsigned AddressSpace); 1612 1613 /** 1614 * Determine whether a pointer is opaque. 1615 * 1616 * True if this is an instance of an opaque PointerType. 1617 * 1618 * @see llvm::Type::isOpaquePointerTy() 1619 */ 1620 LLVMBool LLVMPointerTypeIsOpaque(LLVMTypeRef Ty); 1621 1622 /** 1623 * Create an opaque pointer type in a context. 1624 * 1625 * @see llvm::PointerType::get() 1626 */ 1627 LLVMTypeRef LLVMPointerTypeInContext(LLVMContextRef C, unsigned AddressSpace); 1628 1629 /** 1630 * Obtain the address space of a pointer type. 1631 * 1632 * This only works on types that represent pointers. 1633 * 1634 * @see llvm::PointerType::getAddressSpace() 1635 */ 1636 unsigned LLVMGetPointerAddressSpace(LLVMTypeRef PointerTy); 1637 1638 /** 1639 * Create a vector type that contains a defined type and has a specific 1640 * number of elements. 1641 * 1642 * The created type will exist in the context thats its element type 1643 * exists in. 1644 * 1645 * @see llvm::VectorType::get() 1646 */ 1647 LLVMTypeRef LLVMVectorType(LLVMTypeRef ElementType, unsigned ElementCount); 1648 1649 /** 1650 * Create a vector type that contains a defined type and has a scalable 1651 * number of elements. 1652 * 1653 * The created type will exist in the context thats its element type 1654 * exists in. 1655 * 1656 * @see llvm::ScalableVectorType::get() 1657 */ 1658 LLVMTypeRef LLVMScalableVectorType(LLVMTypeRef ElementType, 1659 unsigned ElementCount); 1660 1661 /** 1662 * Obtain the (possibly scalable) number of elements in a vector type. 1663 * 1664 * This only works on types that represent vectors (fixed or scalable). 1665 * 1666 * @see llvm::VectorType::getNumElements() 1667 */ 1668 unsigned LLVMGetVectorSize(LLVMTypeRef VectorTy); 1669 1670 /** 1671 * Get the pointer value for the associated ConstantPtrAuth constant. 1672 * 1673 * @see llvm::ConstantPtrAuth::getPointer 1674 */ 1675 LLVMValueRef LLVMGetConstantPtrAuthPointer(LLVMValueRef PtrAuth); 1676 1677 /** 1678 * Get the key value for the associated ConstantPtrAuth constant. 1679 * 1680 * @see llvm::ConstantPtrAuth::getKey 1681 */ 1682 LLVMValueRef LLVMGetConstantPtrAuthKey(LLVMValueRef PtrAuth); 1683 1684 /** 1685 * Get the discriminator value for the associated ConstantPtrAuth constant. 1686 * 1687 * @see llvm::ConstantPtrAuth::getDiscriminator 1688 */ 1689 LLVMValueRef LLVMGetConstantPtrAuthDiscriminator(LLVMValueRef PtrAuth); 1690 1691 /** 1692 * Get the address discriminator value for the associated ConstantPtrAuth 1693 * constant. 1694 * 1695 * @see llvm::ConstantPtrAuth::getAddrDiscriminator 1696 */ 1697 LLVMValueRef LLVMGetConstantPtrAuthAddrDiscriminator(LLVMValueRef PtrAuth); 1698 1699 /** 1700 * @} 1701 */ 1702 1703 /** 1704 * @defgroup LLVMCCoreTypeOther Other Types 1705 * 1706 * @{ 1707 */ 1708 1709 /** 1710 * Create a void type in a context. 1711 */ 1712 LLVMTypeRef LLVMVoidTypeInContext(LLVMContextRef C); 1713 1714 /** 1715 * Create a label type in a context. 1716 */ 1717 LLVMTypeRef LLVMLabelTypeInContext(LLVMContextRef C); 1718 1719 /** 1720 * Create a X86 MMX type in a context. 1721 */ 1722 LLVMTypeRef LLVMX86MMXTypeInContext(LLVMContextRef C); 1723 1724 /** 1725 * Create a X86 AMX type in a context. 1726 */ 1727 LLVMTypeRef LLVMX86AMXTypeInContext(LLVMContextRef C); 1728 1729 /** 1730 * Create a token type in a context. 1731 */ 1732 LLVMTypeRef LLVMTokenTypeInContext(LLVMContextRef C); 1733 1734 /** 1735 * Create a metadata type in a context. 1736 */ 1737 LLVMTypeRef LLVMMetadataTypeInContext(LLVMContextRef C); 1738 1739 /** 1740 * These are similar to the above functions except they operate on the 1741 * global context. 1742 */ 1743 LLVMTypeRef LLVMVoidType(void); 1744 LLVMTypeRef LLVMLabelType(void); 1745 LLVMTypeRef LLVMX86MMXType(void); 1746 LLVMTypeRef LLVMX86AMXType(void); 1747 1748 /** 1749 * Create a target extension type in LLVM context. 1750 */ 1751 LLVMTypeRef LLVMTargetExtTypeInContext(LLVMContextRef C, const char *Name, 1752 LLVMTypeRef *TypeParams, 1753 unsigned TypeParamCount, 1754 unsigned *IntParams, 1755 unsigned IntParamCount); 1756 1757 /** 1758 * Obtain the name for this target extension type. 1759 * 1760 * @see llvm::TargetExtType::getName() 1761 */ 1762 const char *LLVMGetTargetExtTypeName(LLVMTypeRef TargetExtTy); 1763 1764 /** 1765 * Obtain the number of type parameters for this target extension type. 1766 * 1767 * @see llvm::TargetExtType::getNumTypeParameters() 1768 */ 1769 unsigned LLVMGetTargetExtTypeNumTypeParams(LLVMTypeRef TargetExtTy); 1770 1771 /** 1772 * Get the type parameter at the given index for the target extension type. 1773 * 1774 * @see llvm::TargetExtType::getTypeParameter() 1775 */ 1776 LLVMTypeRef LLVMGetTargetExtTypeTypeParam(LLVMTypeRef TargetExtTy, 1777 unsigned Idx); 1778 1779 /** 1780 * Obtain the number of int parameters for this target extension type. 1781 * 1782 * @see llvm::TargetExtType::getNumIntParameters() 1783 */ 1784 unsigned LLVMGetTargetExtTypeNumIntParams(LLVMTypeRef TargetExtTy); 1785 1786 /** 1787 * Get the int parameter at the given index for the target extension type. 1788 * 1789 * @see llvm::TargetExtType::getIntParameter() 1790 */ 1791 unsigned LLVMGetTargetExtTypeIntParam(LLVMTypeRef TargetExtTy, unsigned Idx); 1792 1793 /** 1794 * @} 1795 */ 1796 1797 /** 1798 * @} 1799 */ 1800 1801 /** 1802 * @defgroup LLVMCCoreValues Values 1803 * 1804 * The bulk of LLVM's object model consists of values, which comprise a very 1805 * rich type hierarchy. 1806 * 1807 * LLVMValueRef essentially represents llvm::Value. There is a rich 1808 * hierarchy of classes within this type. Depending on the instance 1809 * obtained, not all APIs are available. 1810 * 1811 * Callers can determine the type of an LLVMValueRef by calling the 1812 * LLVMIsA* family of functions (e.g. LLVMIsAArgument()). These 1813 * functions are defined by a macro, so it isn't obvious which are 1814 * available by looking at the Doxygen source code. Instead, look at the 1815 * source definition of LLVM_FOR_EACH_VALUE_SUBCLASS and note the list 1816 * of value names given. These value names also correspond to classes in 1817 * the llvm::Value hierarchy. 1818 * 1819 * @{ 1820 */ 1821 1822 // Currently, clang-format tries to format the LLVM_FOR_EACH_VALUE_SUBCLASS 1823 // macro in a progressively-indented fashion, which is not desired 1824 // clang-format off 1825 1826 #define LLVM_FOR_EACH_VALUE_SUBCLASS(macro) \ 1827 macro(Argument) \ 1828 macro(BasicBlock) \ 1829 macro(InlineAsm) \ 1830 macro(User) \ 1831 macro(Constant) \ 1832 macro(BlockAddress) \ 1833 macro(ConstantAggregateZero) \ 1834 macro(ConstantArray) \ 1835 macro(ConstantDataSequential) \ 1836 macro(ConstantDataArray) \ 1837 macro(ConstantDataVector) \ 1838 macro(ConstantExpr) \ 1839 macro(ConstantFP) \ 1840 macro(ConstantInt) \ 1841 macro(ConstantPointerNull) \ 1842 macro(ConstantStruct) \ 1843 macro(ConstantTokenNone) \ 1844 macro(ConstantVector) \ 1845 macro(ConstantPtrAuth) \ 1846 macro(GlobalValue) \ 1847 macro(GlobalAlias) \ 1848 macro(GlobalObject) \ 1849 macro(Function) \ 1850 macro(GlobalVariable) \ 1851 macro(GlobalIFunc) \ 1852 macro(UndefValue) \ 1853 macro(PoisonValue) \ 1854 macro(Instruction) \ 1855 macro(UnaryOperator) \ 1856 macro(BinaryOperator) \ 1857 macro(CallInst) \ 1858 macro(IntrinsicInst) \ 1859 macro(DbgInfoIntrinsic) \ 1860 macro(DbgVariableIntrinsic) \ 1861 macro(DbgDeclareInst) \ 1862 macro(DbgLabelInst) \ 1863 macro(MemIntrinsic) \ 1864 macro(MemCpyInst) \ 1865 macro(MemMoveInst) \ 1866 macro(MemSetInst) \ 1867 macro(CmpInst) \ 1868 macro(FCmpInst) \ 1869 macro(ICmpInst) \ 1870 macro(ExtractElementInst) \ 1871 macro(GetElementPtrInst) \ 1872 macro(InsertElementInst) \ 1873 macro(InsertValueInst) \ 1874 macro(LandingPadInst) \ 1875 macro(PHINode) \ 1876 macro(SelectInst) \ 1877 macro(ShuffleVectorInst) \ 1878 macro(StoreInst) \ 1879 macro(BranchInst) \ 1880 macro(IndirectBrInst) \ 1881 macro(InvokeInst) \ 1882 macro(ReturnInst) \ 1883 macro(SwitchInst) \ 1884 macro(UnreachableInst) \ 1885 macro(ResumeInst) \ 1886 macro(CleanupReturnInst) \ 1887 macro(CatchReturnInst) \ 1888 macro(CatchSwitchInst) \ 1889 macro(CallBrInst) \ 1890 macro(FuncletPadInst) \ 1891 macro(CatchPadInst) \ 1892 macro(CleanupPadInst) \ 1893 macro(UnaryInstruction) \ 1894 macro(AllocaInst) \ 1895 macro(CastInst) \ 1896 macro(AddrSpaceCastInst) \ 1897 macro(BitCastInst) \ 1898 macro(FPExtInst) \ 1899 macro(FPToSIInst) \ 1900 macro(FPToUIInst) \ 1901 macro(FPTruncInst) \ 1902 macro(IntToPtrInst) \ 1903 macro(PtrToIntInst) \ 1904 macro(SExtInst) \ 1905 macro(SIToFPInst) \ 1906 macro(TruncInst) \ 1907 macro(UIToFPInst) \ 1908 macro(ZExtInst) \ 1909 macro(ExtractValueInst) \ 1910 macro(LoadInst) \ 1911 macro(VAArgInst) \ 1912 macro(FreezeInst) \ 1913 macro(AtomicCmpXchgInst) \ 1914 macro(AtomicRMWInst) \ 1915 macro(FenceInst) 1916 1917 // clang-format on 1918 1919 /** 1920 * @defgroup LLVMCCoreValueGeneral General APIs 1921 * 1922 * Functions in this section work on all LLVMValueRef instances, 1923 * regardless of their sub-type. They correspond to functions available 1924 * on llvm::Value. 1925 * 1926 * @{ 1927 */ 1928 1929 /** 1930 * Obtain the type of a value. 1931 * 1932 * @see llvm::Value::getType() 1933 */ 1934 LLVMTypeRef LLVMTypeOf(LLVMValueRef Val); 1935 1936 /** 1937 * Obtain the enumerated type of a Value instance. 1938 * 1939 * @see llvm::Value::getValueID() 1940 */ 1941 LLVMValueKind LLVMGetValueKind(LLVMValueRef Val); 1942 1943 /** 1944 * Obtain the string name of a value. 1945 * 1946 * @see llvm::Value::getName() 1947 */ 1948 const char *LLVMGetValueName2(LLVMValueRef Val, size_t *Length); 1949 1950 /** 1951 * Set the string name of a value. 1952 * 1953 * @see llvm::Value::setName() 1954 */ 1955 void LLVMSetValueName2(LLVMValueRef Val, const char *Name, size_t NameLen); 1956 1957 /** 1958 * Dump a representation of a value to stderr. 1959 * 1960 * @see llvm::Value::dump() 1961 */ 1962 void LLVMDumpValue(LLVMValueRef Val); 1963 1964 /** 1965 * Return a string representation of the value. Use 1966 * LLVMDisposeMessage to free the string. 1967 * 1968 * @see llvm::Value::print() 1969 */ 1970 char *LLVMPrintValueToString(LLVMValueRef Val); 1971 1972 /** 1973 * Return a string representation of the DbgRecord. Use 1974 * LLVMDisposeMessage to free the string. 1975 * 1976 * @see llvm::DbgRecord::print() 1977 */ 1978 char *LLVMPrintDbgRecordToString(LLVMDbgRecordRef Record); 1979 1980 /** 1981 * Replace all uses of a value with another one. 1982 * 1983 * @see llvm::Value::replaceAllUsesWith() 1984 */ 1985 void LLVMReplaceAllUsesWith(LLVMValueRef OldVal, LLVMValueRef NewVal); 1986 1987 /** 1988 * Determine whether the specified value instance is constant. 1989 */ 1990 LLVMBool LLVMIsConstant(LLVMValueRef Val); 1991 1992 /** 1993 * Determine whether a value instance is undefined. 1994 */ 1995 LLVMBool LLVMIsUndef(LLVMValueRef Val); 1996 1997 /** 1998 * Determine whether a value instance is poisonous. 1999 */ 2000 LLVMBool LLVMIsPoison(LLVMValueRef Val); 2001 2002 /** 2003 * Convert value instances between types. 2004 * 2005 * Internally, an LLVMValueRef is "pinned" to a specific type. This 2006 * series of functions allows you to cast an instance to a specific 2007 * type. 2008 * 2009 * If the cast is not valid for the specified type, NULL is returned. 2010 * 2011 * @see llvm::dyn_cast_or_null<> 2012 */ 2013 #define LLVM_DECLARE_VALUE_CAST(name) \ 2014 LLVMValueRef LLVMIsA##name(LLVMValueRef Val); 2015 LLVM_FOR_EACH_VALUE_SUBCLASS(LLVM_DECLARE_VALUE_CAST) 2016 2017 LLVMValueRef LLVMIsAMDNode(LLVMValueRef Val); 2018 LLVMValueRef LLVMIsAValueAsMetadata(LLVMValueRef Val); 2019 LLVMValueRef LLVMIsAMDString(LLVMValueRef Val); 2020 2021 /** Deprecated: Use LLVMGetValueName2 instead. */ 2022 const char *LLVMGetValueName(LLVMValueRef Val); 2023 /** Deprecated: Use LLVMSetValueName2 instead. */ 2024 void LLVMSetValueName(LLVMValueRef Val, const char *Name); 2025 2026 /** 2027 * @} 2028 */ 2029 2030 /** 2031 * @defgroup LLVMCCoreValueUses Usage 2032 * 2033 * This module defines functions that allow you to inspect the uses of a 2034 * LLVMValueRef. 2035 * 2036 * It is possible to obtain an LLVMUseRef for any LLVMValueRef instance. 2037 * Each LLVMUseRef (which corresponds to a llvm::Use instance) holds a 2038 * llvm::User and llvm::Value. 2039 * 2040 * @{ 2041 */ 2042 2043 /** 2044 * Obtain the first use of a value. 2045 * 2046 * Uses are obtained in an iterator fashion. First, call this function 2047 * to obtain a reference to the first use. Then, call LLVMGetNextUse() 2048 * on that instance and all subsequently obtained instances until 2049 * LLVMGetNextUse() returns NULL. 2050 * 2051 * @see llvm::Value::use_begin() 2052 */ 2053 LLVMUseRef LLVMGetFirstUse(LLVMValueRef Val); 2054 2055 /** 2056 * Obtain the next use of a value. 2057 * 2058 * This effectively advances the iterator. It returns NULL if you are on 2059 * the final use and no more are available. 2060 */ 2061 LLVMUseRef LLVMGetNextUse(LLVMUseRef U); 2062 2063 /** 2064 * Obtain the user value for a user. 2065 * 2066 * The returned value corresponds to a llvm::User type. 2067 * 2068 * @see llvm::Use::getUser() 2069 */ 2070 LLVMValueRef LLVMGetUser(LLVMUseRef U); 2071 2072 /** 2073 * Obtain the value this use corresponds to. 2074 * 2075 * @see llvm::Use::get(). 2076 */ 2077 LLVMValueRef LLVMGetUsedValue(LLVMUseRef U); 2078 2079 /** 2080 * @} 2081 */ 2082 2083 /** 2084 * @defgroup LLVMCCoreValueUser User value 2085 * 2086 * Function in this group pertain to LLVMValueRef instances that descent 2087 * from llvm::User. This includes constants, instructions, and 2088 * operators. 2089 * 2090 * @{ 2091 */ 2092 2093 /** 2094 * Obtain an operand at a specific index in a llvm::User value. 2095 * 2096 * @see llvm::User::getOperand() 2097 */ 2098 LLVMValueRef LLVMGetOperand(LLVMValueRef Val, unsigned Index); 2099 2100 /** 2101 * Obtain the use of an operand at a specific index in a llvm::User value. 2102 * 2103 * @see llvm::User::getOperandUse() 2104 */ 2105 LLVMUseRef LLVMGetOperandUse(LLVMValueRef Val, unsigned Index); 2106 2107 /** 2108 * Set an operand at a specific index in a llvm::User value. 2109 * 2110 * @see llvm::User::setOperand() 2111 */ 2112 void LLVMSetOperand(LLVMValueRef User, unsigned Index, LLVMValueRef Val); 2113 2114 /** 2115 * Obtain the number of operands in a llvm::User value. 2116 * 2117 * @see llvm::User::getNumOperands() 2118 */ 2119 int LLVMGetNumOperands(LLVMValueRef Val); 2120 2121 /** 2122 * @} 2123 */ 2124 2125 /** 2126 * @defgroup LLVMCCoreValueConstant Constants 2127 * 2128 * This section contains APIs for interacting with LLVMValueRef that 2129 * correspond to llvm::Constant instances. 2130 * 2131 * These functions will work for any LLVMValueRef in the llvm::Constant 2132 * class hierarchy. 2133 * 2134 * @{ 2135 */ 2136 2137 /** 2138 * Obtain a constant value referring to the null instance of a type. 2139 * 2140 * @see llvm::Constant::getNullValue() 2141 */ 2142 LLVMValueRef LLVMConstNull(LLVMTypeRef Ty); /* all zeroes */ 2143 2144 /** 2145 * Obtain a constant value referring to the instance of a type 2146 * consisting of all ones. 2147 * 2148 * This is only valid for integer types. 2149 * 2150 * @see llvm::Constant::getAllOnesValue() 2151 */ 2152 LLVMValueRef LLVMConstAllOnes(LLVMTypeRef Ty); 2153 2154 /** 2155 * Obtain a constant value referring to an undefined value of a type. 2156 * 2157 * @see llvm::UndefValue::get() 2158 */ 2159 LLVMValueRef LLVMGetUndef(LLVMTypeRef Ty); 2160 2161 /** 2162 * Obtain a constant value referring to a poison value of a type. 2163 * 2164 * @see llvm::PoisonValue::get() 2165 */ 2166 LLVMValueRef LLVMGetPoison(LLVMTypeRef Ty); 2167 2168 /** 2169 * Determine whether a value instance is null. 2170 * 2171 * @see llvm::Constant::isNullValue() 2172 */ 2173 LLVMBool LLVMIsNull(LLVMValueRef Val); 2174 2175 /** 2176 * Obtain a constant that is a constant pointer pointing to NULL for a 2177 * specified type. 2178 */ 2179 LLVMValueRef LLVMConstPointerNull(LLVMTypeRef Ty); 2180 2181 /** 2182 * @defgroup LLVMCCoreValueConstantScalar Scalar constants 2183 * 2184 * Functions in this group model LLVMValueRef instances that correspond 2185 * to constants referring to scalar types. 2186 * 2187 * For integer types, the LLVMTypeRef parameter should correspond to a 2188 * llvm::IntegerType instance and the returned LLVMValueRef will 2189 * correspond to a llvm::ConstantInt. 2190 * 2191 * For floating point types, the LLVMTypeRef returned corresponds to a 2192 * llvm::ConstantFP. 2193 * 2194 * @{ 2195 */ 2196 2197 /** 2198 * Obtain a constant value for an integer type. 2199 * 2200 * The returned value corresponds to a llvm::ConstantInt. 2201 * 2202 * @see llvm::ConstantInt::get() 2203 * 2204 * @param IntTy Integer type to obtain value of. 2205 * @param N The value the returned instance should refer to. 2206 * @param SignExtend Whether to sign extend the produced value. 2207 */ 2208 LLVMValueRef LLVMConstInt(LLVMTypeRef IntTy, unsigned long long N, 2209 LLVMBool SignExtend); 2210 2211 /** 2212 * Obtain a constant value for an integer of arbitrary precision. 2213 * 2214 * @see llvm::ConstantInt::get() 2215 */ 2216 LLVMValueRef LLVMConstIntOfArbitraryPrecision(LLVMTypeRef IntTy, 2217 unsigned NumWords, 2218 const uint64_t Words[]); 2219 2220 /** 2221 * Obtain a constant value for an integer parsed from a string. 2222 * 2223 * A similar API, LLVMConstIntOfStringAndSize is also available. If the 2224 * string's length is available, it is preferred to call that function 2225 * instead. 2226 * 2227 * @see llvm::ConstantInt::get() 2228 */ 2229 LLVMValueRef LLVMConstIntOfString(LLVMTypeRef IntTy, const char *Text, 2230 uint8_t Radix); 2231 2232 /** 2233 * Obtain a constant value for an integer parsed from a string with 2234 * specified length. 2235 * 2236 * @see llvm::ConstantInt::get() 2237 */ 2238 LLVMValueRef LLVMConstIntOfStringAndSize(LLVMTypeRef IntTy, const char *Text, 2239 unsigned SLen, uint8_t Radix); 2240 2241 /** 2242 * Obtain a constant value referring to a double floating point value. 2243 */ 2244 LLVMValueRef LLVMConstReal(LLVMTypeRef RealTy, double N); 2245 2246 /** 2247 * Obtain a constant for a floating point value parsed from a string. 2248 * 2249 * A similar API, LLVMConstRealOfStringAndSize is also available. It 2250 * should be used if the input string's length is known. 2251 */ 2252 LLVMValueRef LLVMConstRealOfString(LLVMTypeRef RealTy, const char *Text); 2253 2254 /** 2255 * Obtain a constant for a floating point value parsed from a string. 2256 */ 2257 LLVMValueRef LLVMConstRealOfStringAndSize(LLVMTypeRef RealTy, const char *Text, 2258 unsigned SLen); 2259 2260 /** 2261 * Obtain the zero extended value for an integer constant value. 2262 * 2263 * @see llvm::ConstantInt::getZExtValue() 2264 */ 2265 unsigned long long LLVMConstIntGetZExtValue(LLVMValueRef ConstantVal); 2266 2267 /** 2268 * Obtain the sign extended value for an integer constant value. 2269 * 2270 * @see llvm::ConstantInt::getSExtValue() 2271 */ 2272 long long LLVMConstIntGetSExtValue(LLVMValueRef ConstantVal); 2273 2274 /** 2275 * Obtain the double value for an floating point constant value. 2276 * losesInfo indicates if some precision was lost in the conversion. 2277 * 2278 * @see llvm::ConstantFP::getDoubleValue 2279 */ 2280 double LLVMConstRealGetDouble(LLVMValueRef ConstantVal, LLVMBool *losesInfo); 2281 2282 /** 2283 * @} 2284 */ 2285 2286 /** 2287 * @defgroup LLVMCCoreValueConstantComposite Composite Constants 2288 * 2289 * Functions in this group operate on composite constants. 2290 * 2291 * @{ 2292 */ 2293 2294 /** 2295 * Create a ConstantDataSequential and initialize it with a string. 2296 * 2297 * @deprecated LLVMConstStringInContext is deprecated in favor of the API 2298 * accurate LLVMConstStringInContext2 2299 * @see llvm::ConstantDataArray::getString() 2300 */ 2301 LLVMValueRef LLVMConstStringInContext(LLVMContextRef C, const char *Str, 2302 unsigned Length, LLVMBool DontNullTerminate); 2303 2304 /** 2305 * Create a ConstantDataSequential and initialize it with a string. 2306 * 2307 * @see llvm::ConstantDataArray::getString() 2308 */ 2309 LLVMValueRef LLVMConstStringInContext2(LLVMContextRef C, const char *Str, 2310 size_t Length, 2311 LLVMBool DontNullTerminate); 2312 2313 /** 2314 * Create a ConstantDataSequential with string content in the global context. 2315 * 2316 * This is the same as LLVMConstStringInContext except it operates on the 2317 * global context. 2318 * 2319 * @see LLVMConstStringInContext() 2320 * @see llvm::ConstantDataArray::getString() 2321 */ 2322 LLVMValueRef LLVMConstString(const char *Str, unsigned Length, 2323 LLVMBool DontNullTerminate); 2324 2325 /** 2326 * Returns true if the specified constant is an array of i8. 2327 * 2328 * @see ConstantDataSequential::getAsString() 2329 */ 2330 LLVMBool LLVMIsConstantString(LLVMValueRef c); 2331 2332 /** 2333 * Get the given constant data sequential as a string. 2334 * 2335 * @see ConstantDataSequential::getAsString() 2336 */ 2337 const char *LLVMGetAsString(LLVMValueRef c, size_t *Length); 2338 2339 /** 2340 * Create an anonymous ConstantStruct with the specified values. 2341 * 2342 * @see llvm::ConstantStruct::getAnon() 2343 */ 2344 LLVMValueRef LLVMConstStructInContext(LLVMContextRef C, 2345 LLVMValueRef *ConstantVals, 2346 unsigned Count, LLVMBool Packed); 2347 2348 /** 2349 * Create a ConstantStruct in the global Context. 2350 * 2351 * This is the same as LLVMConstStructInContext except it operates on the 2352 * global Context. 2353 * 2354 * @see LLVMConstStructInContext() 2355 */ 2356 LLVMValueRef LLVMConstStruct(LLVMValueRef *ConstantVals, unsigned Count, 2357 LLVMBool Packed); 2358 2359 /** 2360 * Create a ConstantArray from values. 2361 * 2362 * @deprecated LLVMConstArray is deprecated in favor of the API accurate 2363 * LLVMConstArray2 2364 * @see llvm::ConstantArray::get() 2365 */ 2366 LLVMValueRef LLVMConstArray(LLVMTypeRef ElementTy, 2367 LLVMValueRef *ConstantVals, unsigned Length); 2368 2369 /** 2370 * Create a ConstantArray from values. 2371 * 2372 * @see llvm::ConstantArray::get() 2373 */ 2374 LLVMValueRef LLVMConstArray2(LLVMTypeRef ElementTy, LLVMValueRef *ConstantVals, 2375 uint64_t Length); 2376 2377 /** 2378 * Create a non-anonymous ConstantStruct from values. 2379 * 2380 * @see llvm::ConstantStruct::get() 2381 */ 2382 LLVMValueRef LLVMConstNamedStruct(LLVMTypeRef StructTy, 2383 LLVMValueRef *ConstantVals, 2384 unsigned Count); 2385 2386 /** 2387 * Get element of a constant aggregate (struct, array or vector) at the 2388 * specified index. Returns null if the index is out of range, or it's not 2389 * possible to determine the element (e.g., because the constant is a 2390 * constant expression.) 2391 * 2392 * @see llvm::Constant::getAggregateElement() 2393 */ 2394 LLVMValueRef LLVMGetAggregateElement(LLVMValueRef C, unsigned Idx); 2395 2396 /** 2397 * Get an element at specified index as a constant. 2398 * 2399 * @see ConstantDataSequential::getElementAsConstant() 2400 */ 2401 LLVM_ATTRIBUTE_C_DEPRECATED( 2402 LLVMValueRef LLVMGetElementAsConstant(LLVMValueRef C, unsigned idx), 2403 "Use LLVMGetAggregateElement instead"); 2404 2405 /** 2406 * Create a ConstantVector from values. 2407 * 2408 * @see llvm::ConstantVector::get() 2409 */ 2410 LLVMValueRef LLVMConstVector(LLVMValueRef *ScalarConstantVals, unsigned Size); 2411 2412 /** 2413 * Create a ConstantPtrAuth constant with the given values. 2414 * 2415 * @see llvm::ConstantPtrAuth::get() 2416 */ 2417 LLVMValueRef LLVMConstantPtrAuth(LLVMValueRef Ptr, LLVMValueRef Key, 2418 LLVMValueRef Disc, LLVMValueRef AddrDisc); 2419 2420 /** 2421 * @} 2422 */ 2423 2424 /** 2425 * @defgroup LLVMCCoreValueConstantExpressions Constant Expressions 2426 * 2427 * Functions in this group correspond to APIs on llvm::ConstantExpr. 2428 * 2429 * @see llvm::ConstantExpr. 2430 * 2431 * @{ 2432 */ 2433 LLVMOpcode LLVMGetConstOpcode(LLVMValueRef ConstantVal); 2434 LLVMValueRef LLVMAlignOf(LLVMTypeRef Ty); 2435 LLVMValueRef LLVMSizeOf(LLVMTypeRef Ty); 2436 LLVMValueRef LLVMConstNeg(LLVMValueRef ConstantVal); 2437 LLVMValueRef LLVMConstNSWNeg(LLVMValueRef ConstantVal); 2438 LLVM_ATTRIBUTE_C_DEPRECATED( 2439 LLVMValueRef LLVMConstNUWNeg(LLVMValueRef ConstantVal), 2440 "Use LLVMConstNull instead."); 2441 LLVMValueRef LLVMConstNot(LLVMValueRef ConstantVal); 2442 LLVMValueRef LLVMConstAdd(LLVMValueRef LHSConstant, LLVMValueRef RHSConstant); 2443 LLVMValueRef LLVMConstNSWAdd(LLVMValueRef LHSConstant, LLVMValueRef RHSConstant); 2444 LLVMValueRef LLVMConstNUWAdd(LLVMValueRef LHSConstant, LLVMValueRef RHSConstant); 2445 LLVMValueRef LLVMConstSub(LLVMValueRef LHSConstant, LLVMValueRef RHSConstant); 2446 LLVMValueRef LLVMConstNSWSub(LLVMValueRef LHSConstant, LLVMValueRef RHSConstant); 2447 LLVMValueRef LLVMConstNUWSub(LLVMValueRef LHSConstant, LLVMValueRef RHSConstant); 2448 LLVMValueRef LLVMConstMul(LLVMValueRef LHSConstant, LLVMValueRef RHSConstant); 2449 LLVMValueRef LLVMConstNSWMul(LLVMValueRef LHSConstant, LLVMValueRef RHSConstant); 2450 LLVMValueRef LLVMConstNUWMul(LLVMValueRef LHSConstant, LLVMValueRef RHSConstant); 2451 LLVMValueRef LLVMConstXor(LLVMValueRef LHSConstant, LLVMValueRef RHSConstant); 2452 LLVMValueRef LLVMConstGEP2(LLVMTypeRef Ty, LLVMValueRef ConstantVal, 2453 LLVMValueRef *ConstantIndices, unsigned NumIndices); 2454 LLVMValueRef LLVMConstInBoundsGEP2(LLVMTypeRef Ty, LLVMValueRef ConstantVal, 2455 LLVMValueRef *ConstantIndices, 2456 unsigned NumIndices); 2457 /** 2458 * Creates a constant GetElementPtr expression. Similar to LLVMConstGEP2, but 2459 * allows specifying the no-wrap flags. 2460 * 2461 * @see llvm::ConstantExpr::getGetElementPtr() 2462 */ 2463 LLVMValueRef LLVMConstGEPWithNoWrapFlags(LLVMTypeRef Ty, 2464 LLVMValueRef ConstantVal, 2465 LLVMValueRef *ConstantIndices, 2466 unsigned NumIndices, 2467 LLVMGEPNoWrapFlags NoWrapFlags); 2468 LLVMValueRef LLVMConstTrunc(LLVMValueRef ConstantVal, LLVMTypeRef ToType); 2469 LLVMValueRef LLVMConstPtrToInt(LLVMValueRef ConstantVal, LLVMTypeRef ToType); 2470 LLVMValueRef LLVMConstIntToPtr(LLVMValueRef ConstantVal, LLVMTypeRef ToType); 2471 LLVMValueRef LLVMConstBitCast(LLVMValueRef ConstantVal, LLVMTypeRef ToType); 2472 LLVMValueRef LLVMConstAddrSpaceCast(LLVMValueRef ConstantVal, LLVMTypeRef ToType); 2473 LLVMValueRef LLVMConstTruncOrBitCast(LLVMValueRef ConstantVal, 2474 LLVMTypeRef ToType); 2475 LLVMValueRef LLVMConstPointerCast(LLVMValueRef ConstantVal, 2476 LLVMTypeRef ToType); 2477 LLVMValueRef LLVMConstExtractElement(LLVMValueRef VectorConstant, 2478 LLVMValueRef IndexConstant); 2479 LLVMValueRef LLVMConstInsertElement(LLVMValueRef VectorConstant, 2480 LLVMValueRef ElementValueConstant, 2481 LLVMValueRef IndexConstant); 2482 LLVMValueRef LLVMConstShuffleVector(LLVMValueRef VectorAConstant, 2483 LLVMValueRef VectorBConstant, 2484 LLVMValueRef MaskConstant); 2485 LLVMValueRef LLVMBlockAddress(LLVMValueRef F, LLVMBasicBlockRef BB); 2486 2487 /** 2488 * Gets the function associated with a given BlockAddress constant value. 2489 */ 2490 LLVMValueRef LLVMGetBlockAddressFunction(LLVMValueRef BlockAddr); 2491 2492 /** 2493 * Gets the basic block associated with a given BlockAddress constant value. 2494 */ 2495 LLVMBasicBlockRef LLVMGetBlockAddressBasicBlock(LLVMValueRef BlockAddr); 2496 2497 /** Deprecated: Use LLVMGetInlineAsm instead. */ 2498 LLVMValueRef LLVMConstInlineAsm(LLVMTypeRef Ty, 2499 const char *AsmString, const char *Constraints, 2500 LLVMBool HasSideEffects, LLVMBool IsAlignStack); 2501 2502 /** 2503 * @} 2504 */ 2505 2506 /** 2507 * @defgroup LLVMCCoreValueConstantGlobals Global Values 2508 * 2509 * This group contains functions that operate on global values. Functions in 2510 * this group relate to functions in the llvm::GlobalValue class tree. 2511 * 2512 * @see llvm::GlobalValue 2513 * 2514 * @{ 2515 */ 2516 2517 LLVMModuleRef LLVMGetGlobalParent(LLVMValueRef Global); 2518 LLVMBool LLVMIsDeclaration(LLVMValueRef Global); 2519 LLVMLinkage LLVMGetLinkage(LLVMValueRef Global); 2520 void LLVMSetLinkage(LLVMValueRef Global, LLVMLinkage Linkage); 2521 const char *LLVMGetSection(LLVMValueRef Global); 2522 void LLVMSetSection(LLVMValueRef Global, const char *Section); 2523 LLVMVisibility LLVMGetVisibility(LLVMValueRef Global); 2524 void LLVMSetVisibility(LLVMValueRef Global, LLVMVisibility Viz); 2525 LLVMDLLStorageClass LLVMGetDLLStorageClass(LLVMValueRef Global); 2526 void LLVMSetDLLStorageClass(LLVMValueRef Global, LLVMDLLStorageClass Class); 2527 LLVMUnnamedAddr LLVMGetUnnamedAddress(LLVMValueRef Global); 2528 void LLVMSetUnnamedAddress(LLVMValueRef Global, LLVMUnnamedAddr UnnamedAddr); 2529 2530 /** 2531 * Returns the "value type" of a global value. This differs from the formal 2532 * type of a global value which is always a pointer type. 2533 * 2534 * @see llvm::GlobalValue::getValueType() 2535 */ 2536 LLVMTypeRef LLVMGlobalGetValueType(LLVMValueRef Global); 2537 2538 /** Deprecated: Use LLVMGetUnnamedAddress instead. */ 2539 LLVMBool LLVMHasUnnamedAddr(LLVMValueRef Global); 2540 /** Deprecated: Use LLVMSetUnnamedAddress instead. */ 2541 void LLVMSetUnnamedAddr(LLVMValueRef Global, LLVMBool HasUnnamedAddr); 2542 2543 /** 2544 * @defgroup LLVMCCoreValueWithAlignment Values with alignment 2545 * 2546 * Functions in this group only apply to values with alignment, i.e. 2547 * global variables, load and store instructions. 2548 */ 2549 2550 /** 2551 * Obtain the preferred alignment of the value. 2552 * @see llvm::AllocaInst::getAlignment() 2553 * @see llvm::LoadInst::getAlignment() 2554 * @see llvm::StoreInst::getAlignment() 2555 * @see llvm::AtomicRMWInst::setAlignment() 2556 * @see llvm::AtomicCmpXchgInst::setAlignment() 2557 * @see llvm::GlobalValue::getAlignment() 2558 */ 2559 unsigned LLVMGetAlignment(LLVMValueRef V); 2560 2561 /** 2562 * Set the preferred alignment of the value. 2563 * @see llvm::AllocaInst::setAlignment() 2564 * @see llvm::LoadInst::setAlignment() 2565 * @see llvm::StoreInst::setAlignment() 2566 * @see llvm::AtomicRMWInst::setAlignment() 2567 * @see llvm::AtomicCmpXchgInst::setAlignment() 2568 * @see llvm::GlobalValue::setAlignment() 2569 */ 2570 void LLVMSetAlignment(LLVMValueRef V, unsigned Bytes); 2571 2572 /** 2573 * Sets a metadata attachment, erasing the existing metadata attachment if 2574 * it already exists for the given kind. 2575 * 2576 * @see llvm::GlobalObject::setMetadata() 2577 */ 2578 void LLVMGlobalSetMetadata(LLVMValueRef Global, unsigned Kind, 2579 LLVMMetadataRef MD); 2580 2581 /** 2582 * Erases a metadata attachment of the given kind if it exists. 2583 * 2584 * @see llvm::GlobalObject::eraseMetadata() 2585 */ 2586 void LLVMGlobalEraseMetadata(LLVMValueRef Global, unsigned Kind); 2587 2588 /** 2589 * Removes all metadata attachments from this value. 2590 * 2591 * @see llvm::GlobalObject::clearMetadata() 2592 */ 2593 void LLVMGlobalClearMetadata(LLVMValueRef Global); 2594 2595 /** 2596 * Retrieves an array of metadata entries representing the metadata attached to 2597 * this value. The caller is responsible for freeing this array by calling 2598 * \c LLVMDisposeValueMetadataEntries. 2599 * 2600 * @see llvm::GlobalObject::getAllMetadata() 2601 */ 2602 LLVMValueMetadataEntry *LLVMGlobalCopyAllMetadata(LLVMValueRef Value, 2603 size_t *NumEntries); 2604 2605 /** 2606 * Destroys value metadata entries. 2607 */ 2608 void LLVMDisposeValueMetadataEntries(LLVMValueMetadataEntry *Entries); 2609 2610 /** 2611 * Returns the kind of a value metadata entry at a specific index. 2612 */ 2613 unsigned LLVMValueMetadataEntriesGetKind(LLVMValueMetadataEntry *Entries, 2614 unsigned Index); 2615 2616 /** 2617 * Returns the underlying metadata node of a value metadata entry at a 2618 * specific index. 2619 */ 2620 LLVMMetadataRef 2621 LLVMValueMetadataEntriesGetMetadata(LLVMValueMetadataEntry *Entries, 2622 unsigned Index); 2623 2624 /** 2625 * @} 2626 */ 2627 2628 /** 2629 * @defgroup LLVMCoreValueConstantGlobalVariable Global Variables 2630 * 2631 * This group contains functions that operate on global variable values. 2632 * 2633 * @see llvm::GlobalVariable 2634 * 2635 * @{ 2636 */ 2637 LLVMValueRef LLVMAddGlobal(LLVMModuleRef M, LLVMTypeRef Ty, const char *Name); 2638 LLVMValueRef LLVMAddGlobalInAddressSpace(LLVMModuleRef M, LLVMTypeRef Ty, 2639 const char *Name, 2640 unsigned AddressSpace); 2641 LLVMValueRef LLVMGetNamedGlobal(LLVMModuleRef M, const char *Name); 2642 LLVMValueRef LLVMGetFirstGlobal(LLVMModuleRef M); 2643 LLVMValueRef LLVMGetLastGlobal(LLVMModuleRef M); 2644 LLVMValueRef LLVMGetNextGlobal(LLVMValueRef GlobalVar); 2645 LLVMValueRef LLVMGetPreviousGlobal(LLVMValueRef GlobalVar); 2646 void LLVMDeleteGlobal(LLVMValueRef GlobalVar); 2647 LLVMValueRef LLVMGetInitializer(LLVMValueRef GlobalVar); 2648 void LLVMSetInitializer(LLVMValueRef GlobalVar, LLVMValueRef ConstantVal); 2649 LLVMBool LLVMIsThreadLocal(LLVMValueRef GlobalVar); 2650 void LLVMSetThreadLocal(LLVMValueRef GlobalVar, LLVMBool IsThreadLocal); 2651 LLVMBool LLVMIsGlobalConstant(LLVMValueRef GlobalVar); 2652 void LLVMSetGlobalConstant(LLVMValueRef GlobalVar, LLVMBool IsConstant); 2653 LLVMThreadLocalMode LLVMGetThreadLocalMode(LLVMValueRef GlobalVar); 2654 void LLVMSetThreadLocalMode(LLVMValueRef GlobalVar, LLVMThreadLocalMode Mode); 2655 LLVMBool LLVMIsExternallyInitialized(LLVMValueRef GlobalVar); 2656 void LLVMSetExternallyInitialized(LLVMValueRef GlobalVar, LLVMBool IsExtInit); 2657 2658 /** 2659 * @} 2660 */ 2661 2662 /** 2663 * @defgroup LLVMCoreValueConstantGlobalAlias Global Aliases 2664 * 2665 * This group contains function that operate on global alias values. 2666 * 2667 * @see llvm::GlobalAlias 2668 * 2669 * @{ 2670 */ 2671 2672 /** 2673 * Add a GlobalAlias with the given value type, address space and aliasee. 2674 * 2675 * @see llvm::GlobalAlias::create() 2676 */ 2677 LLVMValueRef LLVMAddAlias2(LLVMModuleRef M, LLVMTypeRef ValueTy, 2678 unsigned AddrSpace, LLVMValueRef Aliasee, 2679 const char *Name); 2680 2681 /** 2682 * Obtain a GlobalAlias value from a Module by its name. 2683 * 2684 * The returned value corresponds to a llvm::GlobalAlias value. 2685 * 2686 * @see llvm::Module::getNamedAlias() 2687 */ 2688 LLVMValueRef LLVMGetNamedGlobalAlias(LLVMModuleRef M, 2689 const char *Name, size_t NameLen); 2690 2691 /** 2692 * Obtain an iterator to the first GlobalAlias in a Module. 2693 * 2694 * @see llvm::Module::alias_begin() 2695 */ 2696 LLVMValueRef LLVMGetFirstGlobalAlias(LLVMModuleRef M); 2697 2698 /** 2699 * Obtain an iterator to the last GlobalAlias in a Module. 2700 * 2701 * @see llvm::Module::alias_end() 2702 */ 2703 LLVMValueRef LLVMGetLastGlobalAlias(LLVMModuleRef M); 2704 2705 /** 2706 * Advance a GlobalAlias iterator to the next GlobalAlias. 2707 * 2708 * Returns NULL if the iterator was already at the end and there are no more 2709 * global aliases. 2710 */ 2711 LLVMValueRef LLVMGetNextGlobalAlias(LLVMValueRef GA); 2712 2713 /** 2714 * Decrement a GlobalAlias iterator to the previous GlobalAlias. 2715 * 2716 * Returns NULL if the iterator was already at the beginning and there are 2717 * no previous global aliases. 2718 */ 2719 LLVMValueRef LLVMGetPreviousGlobalAlias(LLVMValueRef GA); 2720 2721 /** 2722 * Retrieve the target value of an alias. 2723 */ 2724 LLVMValueRef LLVMAliasGetAliasee(LLVMValueRef Alias); 2725 2726 /** 2727 * Set the target value of an alias. 2728 */ 2729 void LLVMAliasSetAliasee(LLVMValueRef Alias, LLVMValueRef Aliasee); 2730 2731 /** 2732 * @} 2733 */ 2734 2735 /** 2736 * @defgroup LLVMCCoreValueFunction Function values 2737 * 2738 * Functions in this group operate on LLVMValueRef instances that 2739 * correspond to llvm::Function instances. 2740 * 2741 * @see llvm::Function 2742 * 2743 * @{ 2744 */ 2745 2746 /** 2747 * Remove a function from its containing module and deletes it. 2748 * 2749 * @see llvm::Function::eraseFromParent() 2750 */ 2751 void LLVMDeleteFunction(LLVMValueRef Fn); 2752 2753 /** 2754 * Check whether the given function has a personality function. 2755 * 2756 * @see llvm::Function::hasPersonalityFn() 2757 */ 2758 LLVMBool LLVMHasPersonalityFn(LLVMValueRef Fn); 2759 2760 /** 2761 * Obtain the personality function attached to the function. 2762 * 2763 * @see llvm::Function::getPersonalityFn() 2764 */ 2765 LLVMValueRef LLVMGetPersonalityFn(LLVMValueRef Fn); 2766 2767 /** 2768 * Set the personality function attached to the function. 2769 * 2770 * @see llvm::Function::setPersonalityFn() 2771 */ 2772 void LLVMSetPersonalityFn(LLVMValueRef Fn, LLVMValueRef PersonalityFn); 2773 2774 /** 2775 * Obtain the intrinsic ID number which matches the given function name. 2776 * 2777 * @see llvm::Function::lookupIntrinsicID() 2778 */ 2779 unsigned LLVMLookupIntrinsicID(const char *Name, size_t NameLen); 2780 2781 /** 2782 * Obtain the ID number from a function instance. 2783 * 2784 * @see llvm::Function::getIntrinsicID() 2785 */ 2786 unsigned LLVMGetIntrinsicID(LLVMValueRef Fn); 2787 2788 /** 2789 * Create or insert the declaration of an intrinsic. For overloaded intrinsics, 2790 * parameter types must be provided to uniquely identify an overload. 2791 * 2792 * @see llvm::Intrinsic::getDeclaration() 2793 */ 2794 LLVMValueRef LLVMGetIntrinsicDeclaration(LLVMModuleRef Mod, 2795 unsigned ID, 2796 LLVMTypeRef *ParamTypes, 2797 size_t ParamCount); 2798 2799 /** 2800 * Retrieves the type of an intrinsic. For overloaded intrinsics, parameter 2801 * types must be provided to uniquely identify an overload. 2802 * 2803 * @see llvm::Intrinsic::getType() 2804 */ 2805 LLVMTypeRef LLVMIntrinsicGetType(LLVMContextRef Ctx, unsigned ID, 2806 LLVMTypeRef *ParamTypes, size_t ParamCount); 2807 2808 /** 2809 * Retrieves the name of an intrinsic. 2810 * 2811 * @see llvm::Intrinsic::getName() 2812 */ 2813 const char *LLVMIntrinsicGetName(unsigned ID, size_t *NameLength); 2814 2815 /** Deprecated: Use LLVMIntrinsicCopyOverloadedName2 instead. */ 2816 const char *LLVMIntrinsicCopyOverloadedName(unsigned ID, 2817 LLVMTypeRef *ParamTypes, 2818 size_t ParamCount, 2819 size_t *NameLength); 2820 2821 /** 2822 * Copies the name of an overloaded intrinsic identified by a given list of 2823 * parameter types. 2824 * 2825 * Unlike LLVMIntrinsicGetName, the caller is responsible for freeing the 2826 * returned string. 2827 * 2828 * This version also supports unnamed types. 2829 * 2830 * @see llvm::Intrinsic::getName() 2831 */ 2832 const char *LLVMIntrinsicCopyOverloadedName2(LLVMModuleRef Mod, unsigned ID, 2833 LLVMTypeRef *ParamTypes, 2834 size_t ParamCount, 2835 size_t *NameLength); 2836 2837 /** 2838 * Obtain if the intrinsic identified by the given ID is overloaded. 2839 * 2840 * @see llvm::Intrinsic::isOverloaded() 2841 */ 2842 LLVMBool LLVMIntrinsicIsOverloaded(unsigned ID); 2843 2844 /** 2845 * Obtain the calling function of a function. 2846 * 2847 * The returned value corresponds to the LLVMCallConv enumeration. 2848 * 2849 * @see llvm::Function::getCallingConv() 2850 */ 2851 unsigned LLVMGetFunctionCallConv(LLVMValueRef Fn); 2852 2853 /** 2854 * Set the calling convention of a function. 2855 * 2856 * @see llvm::Function::setCallingConv() 2857 * 2858 * @param Fn Function to operate on 2859 * @param CC LLVMCallConv to set calling convention to 2860 */ 2861 void LLVMSetFunctionCallConv(LLVMValueRef Fn, unsigned CC); 2862 2863 /** 2864 * Obtain the name of the garbage collector to use during code 2865 * generation. 2866 * 2867 * @see llvm::Function::getGC() 2868 */ 2869 const char *LLVMGetGC(LLVMValueRef Fn); 2870 2871 /** 2872 * Define the garbage collector to use during code generation. 2873 * 2874 * @see llvm::Function::setGC() 2875 */ 2876 void LLVMSetGC(LLVMValueRef Fn, const char *Name); 2877 2878 /** 2879 * Gets the prefix data associated with a function. Only valid on functions, and 2880 * only if LLVMHasPrefixData returns true. 2881 * See https://llvm.org/docs/LangRef.html#prefix-data 2882 */ 2883 LLVMValueRef LLVMGetPrefixData(LLVMValueRef Fn); 2884 2885 /** 2886 * Check if a given function has prefix data. Only valid on functions. 2887 * See https://llvm.org/docs/LangRef.html#prefix-data 2888 */ 2889 LLVMBool LLVMHasPrefixData(LLVMValueRef Fn); 2890 2891 /** 2892 * Sets the prefix data for the function. Only valid on functions. 2893 * See https://llvm.org/docs/LangRef.html#prefix-data 2894 */ 2895 void LLVMSetPrefixData(LLVMValueRef Fn, LLVMValueRef prefixData); 2896 2897 /** 2898 * Gets the prologue data associated with a function. Only valid on functions, 2899 * and only if LLVMHasPrologueData returns true. 2900 * See https://llvm.org/docs/LangRef.html#prologue-data 2901 */ 2902 LLVMValueRef LLVMGetPrologueData(LLVMValueRef Fn); 2903 2904 /** 2905 * Check if a given function has prologue data. Only valid on functions. 2906 * See https://llvm.org/docs/LangRef.html#prologue-data 2907 */ 2908 LLVMBool LLVMHasPrologueData(LLVMValueRef Fn); 2909 2910 /** 2911 * Sets the prologue data for the function. Only valid on functions. 2912 * See https://llvm.org/docs/LangRef.html#prologue-data 2913 */ 2914 void LLVMSetPrologueData(LLVMValueRef Fn, LLVMValueRef prologueData); 2915 2916 /** 2917 * Add an attribute to a function. 2918 * 2919 * @see llvm::Function::addAttribute() 2920 */ 2921 void LLVMAddAttributeAtIndex(LLVMValueRef F, LLVMAttributeIndex Idx, 2922 LLVMAttributeRef A); 2923 unsigned LLVMGetAttributeCountAtIndex(LLVMValueRef F, LLVMAttributeIndex Idx); 2924 void LLVMGetAttributesAtIndex(LLVMValueRef F, LLVMAttributeIndex Idx, 2925 LLVMAttributeRef *Attrs); 2926 LLVMAttributeRef LLVMGetEnumAttributeAtIndex(LLVMValueRef F, 2927 LLVMAttributeIndex Idx, 2928 unsigned KindID); 2929 LLVMAttributeRef LLVMGetStringAttributeAtIndex(LLVMValueRef F, 2930 LLVMAttributeIndex Idx, 2931 const char *K, unsigned KLen); 2932 void LLVMRemoveEnumAttributeAtIndex(LLVMValueRef F, LLVMAttributeIndex Idx, 2933 unsigned KindID); 2934 void LLVMRemoveStringAttributeAtIndex(LLVMValueRef F, LLVMAttributeIndex Idx, 2935 const char *K, unsigned KLen); 2936 2937 /** 2938 * Add a target-dependent attribute to a function 2939 * @see llvm::AttrBuilder::addAttribute() 2940 */ 2941 void LLVMAddTargetDependentFunctionAttr(LLVMValueRef Fn, const char *A, 2942 const char *V); 2943 2944 /** 2945 * @defgroup LLVMCCoreValueFunctionParameters Function Parameters 2946 * 2947 * Functions in this group relate to arguments/parameters on functions. 2948 * 2949 * Functions in this group expect LLVMValueRef instances that correspond 2950 * to llvm::Function instances. 2951 * 2952 * @{ 2953 */ 2954 2955 /** 2956 * Obtain the number of parameters in a function. 2957 * 2958 * @see llvm::Function::arg_size() 2959 */ 2960 unsigned LLVMCountParams(LLVMValueRef Fn); 2961 2962 /** 2963 * Obtain the parameters in a function. 2964 * 2965 * The takes a pointer to a pre-allocated array of LLVMValueRef that is 2966 * at least LLVMCountParams() long. This array will be filled with 2967 * LLVMValueRef instances which correspond to the parameters the 2968 * function receives. Each LLVMValueRef corresponds to a llvm::Argument 2969 * instance. 2970 * 2971 * @see llvm::Function::arg_begin() 2972 */ 2973 void LLVMGetParams(LLVMValueRef Fn, LLVMValueRef *Params); 2974 2975 /** 2976 * Obtain the parameter at the specified index. 2977 * 2978 * Parameters are indexed from 0. 2979 * 2980 * @see llvm::Function::arg_begin() 2981 */ 2982 LLVMValueRef LLVMGetParam(LLVMValueRef Fn, unsigned Index); 2983 2984 /** 2985 * Obtain the function to which this argument belongs. 2986 * 2987 * Unlike other functions in this group, this one takes an LLVMValueRef 2988 * that corresponds to a llvm::Attribute. 2989 * 2990 * The returned LLVMValueRef is the llvm::Function to which this 2991 * argument belongs. 2992 */ 2993 LLVMValueRef LLVMGetParamParent(LLVMValueRef Inst); 2994 2995 /** 2996 * Obtain the first parameter to a function. 2997 * 2998 * @see llvm::Function::arg_begin() 2999 */ 3000 LLVMValueRef LLVMGetFirstParam(LLVMValueRef Fn); 3001 3002 /** 3003 * Obtain the last parameter to a function. 3004 * 3005 * @see llvm::Function::arg_end() 3006 */ 3007 LLVMValueRef LLVMGetLastParam(LLVMValueRef Fn); 3008 3009 /** 3010 * Obtain the next parameter to a function. 3011 * 3012 * This takes an LLVMValueRef obtained from LLVMGetFirstParam() (which is 3013 * actually a wrapped iterator) and obtains the next parameter from the 3014 * underlying iterator. 3015 */ 3016 LLVMValueRef LLVMGetNextParam(LLVMValueRef Arg); 3017 3018 /** 3019 * Obtain the previous parameter to a function. 3020 * 3021 * This is the opposite of LLVMGetNextParam(). 3022 */ 3023 LLVMValueRef LLVMGetPreviousParam(LLVMValueRef Arg); 3024 3025 /** 3026 * Set the alignment for a function parameter. 3027 * 3028 * @see llvm::Argument::addAttr() 3029 * @see llvm::AttrBuilder::addAlignmentAttr() 3030 */ 3031 void LLVMSetParamAlignment(LLVMValueRef Arg, unsigned Align); 3032 3033 /** 3034 * @} 3035 */ 3036 3037 /** 3038 * @defgroup LLVMCCoreValueGlobalIFunc IFuncs 3039 * 3040 * Functions in this group relate to indirect functions. 3041 * 3042 * Functions in this group expect LLVMValueRef instances that correspond 3043 * to llvm::GlobalIFunc instances. 3044 * 3045 * @{ 3046 */ 3047 3048 /** 3049 * Add a global indirect function to a module under a specified name. 3050 * 3051 * @see llvm::GlobalIFunc::create() 3052 */ 3053 LLVMValueRef LLVMAddGlobalIFunc(LLVMModuleRef M, 3054 const char *Name, size_t NameLen, 3055 LLVMTypeRef Ty, unsigned AddrSpace, 3056 LLVMValueRef Resolver); 3057 3058 /** 3059 * Obtain a GlobalIFunc value from a Module by its name. 3060 * 3061 * The returned value corresponds to a llvm::GlobalIFunc value. 3062 * 3063 * @see llvm::Module::getNamedIFunc() 3064 */ 3065 LLVMValueRef LLVMGetNamedGlobalIFunc(LLVMModuleRef M, 3066 const char *Name, size_t NameLen); 3067 3068 /** 3069 * Obtain an iterator to the first GlobalIFunc in a Module. 3070 * 3071 * @see llvm::Module::ifunc_begin() 3072 */ 3073 LLVMValueRef LLVMGetFirstGlobalIFunc(LLVMModuleRef M); 3074 3075 /** 3076 * Obtain an iterator to the last GlobalIFunc in a Module. 3077 * 3078 * @see llvm::Module::ifunc_end() 3079 */ 3080 LLVMValueRef LLVMGetLastGlobalIFunc(LLVMModuleRef M); 3081 3082 /** 3083 * Advance a GlobalIFunc iterator to the next GlobalIFunc. 3084 * 3085 * Returns NULL if the iterator was already at the end and there are no more 3086 * global aliases. 3087 */ 3088 LLVMValueRef LLVMGetNextGlobalIFunc(LLVMValueRef IFunc); 3089 3090 /** 3091 * Decrement a GlobalIFunc iterator to the previous GlobalIFunc. 3092 * 3093 * Returns NULL if the iterator was already at the beginning and there are 3094 * no previous global aliases. 3095 */ 3096 LLVMValueRef LLVMGetPreviousGlobalIFunc(LLVMValueRef IFunc); 3097 3098 /** 3099 * Retrieves the resolver function associated with this indirect function, or 3100 * NULL if it doesn't not exist. 3101 * 3102 * @see llvm::GlobalIFunc::getResolver() 3103 */ 3104 LLVMValueRef LLVMGetGlobalIFuncResolver(LLVMValueRef IFunc); 3105 3106 /** 3107 * Sets the resolver function associated with this indirect function. 3108 * 3109 * @see llvm::GlobalIFunc::setResolver() 3110 */ 3111 void LLVMSetGlobalIFuncResolver(LLVMValueRef IFunc, LLVMValueRef Resolver); 3112 3113 /** 3114 * Remove a global indirect function from its parent module and delete it. 3115 * 3116 * @see llvm::GlobalIFunc::eraseFromParent() 3117 */ 3118 void LLVMEraseGlobalIFunc(LLVMValueRef IFunc); 3119 3120 /** 3121 * Remove a global indirect function from its parent module. 3122 * 3123 * This unlinks the global indirect function from its containing module but 3124 * keeps it alive. 3125 * 3126 * @see llvm::GlobalIFunc::removeFromParent() 3127 */ 3128 void LLVMRemoveGlobalIFunc(LLVMValueRef IFunc); 3129 3130 /** 3131 * @} 3132 */ 3133 3134 /** 3135 * @} 3136 */ 3137 3138 /** 3139 * @} 3140 */ 3141 3142 /** 3143 * @} 3144 */ 3145 3146 /** 3147 * @defgroup LLVMCCoreValueMetadata Metadata 3148 * 3149 * @{ 3150 */ 3151 3152 /** 3153 * Create an MDString value from a given string value. 3154 * 3155 * The MDString value does not take ownership of the given string, it remains 3156 * the responsibility of the caller to free it. 3157 * 3158 * @see llvm::MDString::get() 3159 */ 3160 LLVMMetadataRef LLVMMDStringInContext2(LLVMContextRef C, const char *Str, 3161 size_t SLen); 3162 3163 /** 3164 * Create an MDNode value with the given array of operands. 3165 * 3166 * @see llvm::MDNode::get() 3167 */ 3168 LLVMMetadataRef LLVMMDNodeInContext2(LLVMContextRef C, LLVMMetadataRef *MDs, 3169 size_t Count); 3170 3171 /** 3172 * Obtain a Metadata as a Value. 3173 */ 3174 LLVMValueRef LLVMMetadataAsValue(LLVMContextRef C, LLVMMetadataRef MD); 3175 3176 /** 3177 * Obtain a Value as a Metadata. 3178 */ 3179 LLVMMetadataRef LLVMValueAsMetadata(LLVMValueRef Val); 3180 3181 /** 3182 * Obtain the underlying string from a MDString value. 3183 * 3184 * @param V Instance to obtain string from. 3185 * @param Length Memory address which will hold length of returned string. 3186 * @return String data in MDString. 3187 */ 3188 const char *LLVMGetMDString(LLVMValueRef V, unsigned *Length); 3189 3190 /** 3191 * Obtain the number of operands from an MDNode value. 3192 * 3193 * @param V MDNode to get number of operands from. 3194 * @return Number of operands of the MDNode. 3195 */ 3196 unsigned LLVMGetMDNodeNumOperands(LLVMValueRef V); 3197 3198 /** 3199 * Obtain the given MDNode's operands. 3200 * 3201 * The passed LLVMValueRef pointer should point to enough memory to hold all of 3202 * the operands of the given MDNode (see LLVMGetMDNodeNumOperands) as 3203 * LLVMValueRefs. This memory will be populated with the LLVMValueRefs of the 3204 * MDNode's operands. 3205 * 3206 * @param V MDNode to get the operands from. 3207 * @param Dest Destination array for operands. 3208 */ 3209 void LLVMGetMDNodeOperands(LLVMValueRef V, LLVMValueRef *Dest); 3210 3211 /** 3212 * Replace an operand at a specific index in a llvm::MDNode value. 3213 * 3214 * @see llvm::MDNode::replaceOperandWith() 3215 */ 3216 void LLVMReplaceMDNodeOperandWith(LLVMValueRef V, unsigned Index, 3217 LLVMMetadataRef Replacement); 3218 3219 /** Deprecated: Use LLVMMDStringInContext2 instead. */ 3220 LLVMValueRef LLVMMDStringInContext(LLVMContextRef C, const char *Str, 3221 unsigned SLen); 3222 /** Deprecated: Use LLVMMDStringInContext2 instead. */ 3223 LLVMValueRef LLVMMDString(const char *Str, unsigned SLen); 3224 /** Deprecated: Use LLVMMDNodeInContext2 instead. */ 3225 LLVMValueRef LLVMMDNodeInContext(LLVMContextRef C, LLVMValueRef *Vals, 3226 unsigned Count); 3227 /** Deprecated: Use LLVMMDNodeInContext2 instead. */ 3228 LLVMValueRef LLVMMDNode(LLVMValueRef *Vals, unsigned Count); 3229 3230 /** 3231 * @} 3232 */ 3233 3234 /** 3235 * @defgroup LLVMCCoreOperandBundle Operand Bundles 3236 * 3237 * Functions in this group operate on LLVMOperandBundleRef instances that 3238 * correspond to llvm::OperandBundleDef instances. 3239 * 3240 * @see llvm::OperandBundleDef 3241 * 3242 * @{ 3243 */ 3244 3245 /** 3246 * Create a new operand bundle. 3247 * 3248 * Every invocation should be paired with LLVMDisposeOperandBundle() or memory 3249 * will be leaked. 3250 * 3251 * @param Tag Tag name of the operand bundle 3252 * @param TagLen Length of Tag 3253 * @param Args Memory address of an array of bundle operands 3254 * @param NumArgs Length of Args 3255 */ 3256 LLVMOperandBundleRef LLVMCreateOperandBundle(const char *Tag, size_t TagLen, 3257 LLVMValueRef *Args, 3258 unsigned NumArgs); 3259 3260 /** 3261 * Destroy an operand bundle. 3262 * 3263 * This must be called for every created operand bundle or memory will be 3264 * leaked. 3265 */ 3266 void LLVMDisposeOperandBundle(LLVMOperandBundleRef Bundle); 3267 3268 /** 3269 * Obtain the tag of an operand bundle as a string. 3270 * 3271 * @param Bundle Operand bundle to obtain tag of. 3272 * @param Len Out parameter which holds the length of the returned string. 3273 * @return The tag name of Bundle. 3274 * @see OperandBundleDef::getTag() 3275 */ 3276 const char *LLVMGetOperandBundleTag(LLVMOperandBundleRef Bundle, size_t *Len); 3277 3278 /** 3279 * Obtain the number of operands for an operand bundle. 3280 * 3281 * @param Bundle Operand bundle to obtain operand count of. 3282 * @return The number of operands. 3283 * @see OperandBundleDef::input_size() 3284 */ 3285 unsigned LLVMGetNumOperandBundleArgs(LLVMOperandBundleRef Bundle); 3286 3287 /** 3288 * Obtain the operand for an operand bundle at the given index. 3289 * 3290 * @param Bundle Operand bundle to obtain operand of. 3291 * @param Index An operand index, must be less than 3292 * LLVMGetNumOperandBundleArgs(). 3293 * @return The operand. 3294 */ 3295 LLVMValueRef LLVMGetOperandBundleArgAtIndex(LLVMOperandBundleRef Bundle, 3296 unsigned Index); 3297 3298 /** 3299 * @} 3300 */ 3301 3302 /** 3303 * @defgroup LLVMCCoreValueBasicBlock Basic Block 3304 * 3305 * A basic block represents a single entry single exit section of code. 3306 * Basic blocks contain a list of instructions which form the body of 3307 * the block. 3308 * 3309 * Basic blocks belong to functions. They have the type of label. 3310 * 3311 * Basic blocks are themselves values. However, the C API models them as 3312 * LLVMBasicBlockRef. 3313 * 3314 * @see llvm::BasicBlock 3315 * 3316 * @{ 3317 */ 3318 3319 /** 3320 * Convert a basic block instance to a value type. 3321 */ 3322 LLVMValueRef LLVMBasicBlockAsValue(LLVMBasicBlockRef BB); 3323 3324 /** 3325 * Determine whether an LLVMValueRef is itself a basic block. 3326 */ 3327 LLVMBool LLVMValueIsBasicBlock(LLVMValueRef Val); 3328 3329 /** 3330 * Convert an LLVMValueRef to an LLVMBasicBlockRef instance. 3331 */ 3332 LLVMBasicBlockRef LLVMValueAsBasicBlock(LLVMValueRef Val); 3333 3334 /** 3335 * Obtain the string name of a basic block. 3336 */ 3337 const char *LLVMGetBasicBlockName(LLVMBasicBlockRef BB); 3338 3339 /** 3340 * Obtain the function to which a basic block belongs. 3341 * 3342 * @see llvm::BasicBlock::getParent() 3343 */ 3344 LLVMValueRef LLVMGetBasicBlockParent(LLVMBasicBlockRef BB); 3345 3346 /** 3347 * Obtain the terminator instruction for a basic block. 3348 * 3349 * If the basic block does not have a terminator (it is not well-formed 3350 * if it doesn't), then NULL is returned. 3351 * 3352 * The returned LLVMValueRef corresponds to an llvm::Instruction. 3353 * 3354 * @see llvm::BasicBlock::getTerminator() 3355 */ 3356 LLVMValueRef LLVMGetBasicBlockTerminator(LLVMBasicBlockRef BB); 3357 3358 /** 3359 * Obtain the number of basic blocks in a function. 3360 * 3361 * @param Fn Function value to operate on. 3362 */ 3363 unsigned LLVMCountBasicBlocks(LLVMValueRef Fn); 3364 3365 /** 3366 * Obtain all of the basic blocks in a function. 3367 * 3368 * This operates on a function value. The BasicBlocks parameter is a 3369 * pointer to a pre-allocated array of LLVMBasicBlockRef of at least 3370 * LLVMCountBasicBlocks() in length. This array is populated with 3371 * LLVMBasicBlockRef instances. 3372 */ 3373 void LLVMGetBasicBlocks(LLVMValueRef Fn, LLVMBasicBlockRef *BasicBlocks); 3374 3375 /** 3376 * Obtain the first basic block in a function. 3377 * 3378 * The returned basic block can be used as an iterator. You will likely 3379 * eventually call into LLVMGetNextBasicBlock() with it. 3380 * 3381 * @see llvm::Function::begin() 3382 */ 3383 LLVMBasicBlockRef LLVMGetFirstBasicBlock(LLVMValueRef Fn); 3384 3385 /** 3386 * Obtain the last basic block in a function. 3387 * 3388 * @see llvm::Function::end() 3389 */ 3390 LLVMBasicBlockRef LLVMGetLastBasicBlock(LLVMValueRef Fn); 3391 3392 /** 3393 * Advance a basic block iterator. 3394 */ 3395 LLVMBasicBlockRef LLVMGetNextBasicBlock(LLVMBasicBlockRef BB); 3396 3397 /** 3398 * Go backwards in a basic block iterator. 3399 */ 3400 LLVMBasicBlockRef LLVMGetPreviousBasicBlock(LLVMBasicBlockRef BB); 3401 3402 /** 3403 * Obtain the basic block that corresponds to the entry point of a 3404 * function. 3405 * 3406 * @see llvm::Function::getEntryBlock() 3407 */ 3408 LLVMBasicBlockRef LLVMGetEntryBasicBlock(LLVMValueRef Fn); 3409 3410 /** 3411 * Insert the given basic block after the insertion point of the given builder. 3412 * 3413 * The insertion point must be valid. 3414 * 3415 * @see llvm::Function::BasicBlockListType::insertAfter() 3416 */ 3417 void LLVMInsertExistingBasicBlockAfterInsertBlock(LLVMBuilderRef Builder, 3418 LLVMBasicBlockRef BB); 3419 3420 /** 3421 * Append the given basic block to the basic block list of the given function. 3422 * 3423 * @see llvm::Function::BasicBlockListType::push_back() 3424 */ 3425 void LLVMAppendExistingBasicBlock(LLVMValueRef Fn, 3426 LLVMBasicBlockRef BB); 3427 3428 /** 3429 * Create a new basic block without inserting it into a function. 3430 * 3431 * @see llvm::BasicBlock::Create() 3432 */ 3433 LLVMBasicBlockRef LLVMCreateBasicBlockInContext(LLVMContextRef C, 3434 const char *Name); 3435 3436 /** 3437 * Append a basic block to the end of a function. 3438 * 3439 * @see llvm::BasicBlock::Create() 3440 */ 3441 LLVMBasicBlockRef LLVMAppendBasicBlockInContext(LLVMContextRef C, 3442 LLVMValueRef Fn, 3443 const char *Name); 3444 3445 /** 3446 * Append a basic block to the end of a function using the global 3447 * context. 3448 * 3449 * @see llvm::BasicBlock::Create() 3450 */ 3451 LLVMBasicBlockRef LLVMAppendBasicBlock(LLVMValueRef Fn, const char *Name); 3452 3453 /** 3454 * Insert a basic block in a function before another basic block. 3455 * 3456 * The function to add to is determined by the function of the 3457 * passed basic block. 3458 * 3459 * @see llvm::BasicBlock::Create() 3460 */ 3461 LLVMBasicBlockRef LLVMInsertBasicBlockInContext(LLVMContextRef C, 3462 LLVMBasicBlockRef BB, 3463 const char *Name); 3464 3465 /** 3466 * Insert a basic block in a function using the global context. 3467 * 3468 * @see llvm::BasicBlock::Create() 3469 */ 3470 LLVMBasicBlockRef LLVMInsertBasicBlock(LLVMBasicBlockRef InsertBeforeBB, 3471 const char *Name); 3472 3473 /** 3474 * Remove a basic block from a function and delete it. 3475 * 3476 * This deletes the basic block from its containing function and deletes 3477 * the basic block itself. 3478 * 3479 * @see llvm::BasicBlock::eraseFromParent() 3480 */ 3481 void LLVMDeleteBasicBlock(LLVMBasicBlockRef BB); 3482 3483 /** 3484 * Remove a basic block from a function. 3485 * 3486 * This deletes the basic block from its containing function but keep 3487 * the basic block alive. 3488 * 3489 * @see llvm::BasicBlock::removeFromParent() 3490 */ 3491 void LLVMRemoveBasicBlockFromParent(LLVMBasicBlockRef BB); 3492 3493 /** 3494 * Move a basic block to before another one. 3495 * 3496 * @see llvm::BasicBlock::moveBefore() 3497 */ 3498 void LLVMMoveBasicBlockBefore(LLVMBasicBlockRef BB, LLVMBasicBlockRef MovePos); 3499 3500 /** 3501 * Move a basic block to after another one. 3502 * 3503 * @see llvm::BasicBlock::moveAfter() 3504 */ 3505 void LLVMMoveBasicBlockAfter(LLVMBasicBlockRef BB, LLVMBasicBlockRef MovePos); 3506 3507 /** 3508 * Obtain the first instruction in a basic block. 3509 * 3510 * The returned LLVMValueRef corresponds to a llvm::Instruction 3511 * instance. 3512 */ 3513 LLVMValueRef LLVMGetFirstInstruction(LLVMBasicBlockRef BB); 3514 3515 /** 3516 * Obtain the last instruction in a basic block. 3517 * 3518 * The returned LLVMValueRef corresponds to an LLVM:Instruction. 3519 */ 3520 LLVMValueRef LLVMGetLastInstruction(LLVMBasicBlockRef BB); 3521 3522 /** 3523 * @} 3524 */ 3525 3526 /** 3527 * @defgroup LLVMCCoreValueInstruction Instructions 3528 * 3529 * Functions in this group relate to the inspection and manipulation of 3530 * individual instructions. 3531 * 3532 * In the C++ API, an instruction is modeled by llvm::Instruction. This 3533 * class has a large number of descendents. llvm::Instruction is a 3534 * llvm::Value and in the C API, instructions are modeled by 3535 * LLVMValueRef. 3536 * 3537 * This group also contains sub-groups which operate on specific 3538 * llvm::Instruction types, e.g. llvm::CallInst. 3539 * 3540 * @{ 3541 */ 3542 3543 /** 3544 * Determine whether an instruction has any metadata attached. 3545 */ 3546 int LLVMHasMetadata(LLVMValueRef Val); 3547 3548 /** 3549 * Return metadata associated with an instruction value. 3550 */ 3551 LLVMValueRef LLVMGetMetadata(LLVMValueRef Val, unsigned KindID); 3552 3553 /** 3554 * Set metadata associated with an instruction value. 3555 */ 3556 void LLVMSetMetadata(LLVMValueRef Val, unsigned KindID, LLVMValueRef Node); 3557 3558 /** 3559 * Returns the metadata associated with an instruction value, but filters out 3560 * all the debug locations. 3561 * 3562 * @see llvm::Instruction::getAllMetadataOtherThanDebugLoc() 3563 */ 3564 LLVMValueMetadataEntry * 3565 LLVMInstructionGetAllMetadataOtherThanDebugLoc(LLVMValueRef Instr, 3566 size_t *NumEntries); 3567 3568 /** 3569 * Obtain the basic block to which an instruction belongs. 3570 * 3571 * @see llvm::Instruction::getParent() 3572 */ 3573 LLVMBasicBlockRef LLVMGetInstructionParent(LLVMValueRef Inst); 3574 3575 /** 3576 * Obtain the instruction that occurs after the one specified. 3577 * 3578 * The next instruction will be from the same basic block. 3579 * 3580 * If this is the last instruction in a basic block, NULL will be 3581 * returned. 3582 */ 3583 LLVMValueRef LLVMGetNextInstruction(LLVMValueRef Inst); 3584 3585 /** 3586 * Obtain the instruction that occurred before this one. 3587 * 3588 * If the instruction is the first instruction in a basic block, NULL 3589 * will be returned. 3590 */ 3591 LLVMValueRef LLVMGetPreviousInstruction(LLVMValueRef Inst); 3592 3593 /** 3594 * Remove an instruction. 3595 * 3596 * The instruction specified is removed from its containing building 3597 * block but is kept alive. 3598 * 3599 * @see llvm::Instruction::removeFromParent() 3600 */ 3601 void LLVMInstructionRemoveFromParent(LLVMValueRef Inst); 3602 3603 /** 3604 * Remove and delete an instruction. 3605 * 3606 * The instruction specified is removed from its containing building 3607 * block and then deleted. 3608 * 3609 * @see llvm::Instruction::eraseFromParent() 3610 */ 3611 void LLVMInstructionEraseFromParent(LLVMValueRef Inst); 3612 3613 /** 3614 * Delete an instruction. 3615 * 3616 * The instruction specified is deleted. It must have previously been 3617 * removed from its containing building block. 3618 * 3619 * @see llvm::Value::deleteValue() 3620 */ 3621 void LLVMDeleteInstruction(LLVMValueRef Inst); 3622 3623 /** 3624 * Obtain the code opcode for an individual instruction. 3625 * 3626 * @see llvm::Instruction::getOpCode() 3627 */ 3628 LLVMOpcode LLVMGetInstructionOpcode(LLVMValueRef Inst); 3629 3630 /** 3631 * Obtain the predicate of an instruction. 3632 * 3633 * This is only valid for instructions that correspond to llvm::ICmpInst. 3634 * 3635 * @see llvm::ICmpInst::getPredicate() 3636 */ 3637 LLVMIntPredicate LLVMGetICmpPredicate(LLVMValueRef Inst); 3638 3639 /** 3640 * Obtain the float predicate of an instruction. 3641 * 3642 * This is only valid for instructions that correspond to llvm::FCmpInst. 3643 * 3644 * @see llvm::FCmpInst::getPredicate() 3645 */ 3646 LLVMRealPredicate LLVMGetFCmpPredicate(LLVMValueRef Inst); 3647 3648 /** 3649 * Create a copy of 'this' instruction that is identical in all ways 3650 * except the following: 3651 * * The instruction has no parent 3652 * * The instruction has no name 3653 * 3654 * @see llvm::Instruction::clone() 3655 */ 3656 LLVMValueRef LLVMInstructionClone(LLVMValueRef Inst); 3657 3658 /** 3659 * Determine whether an instruction is a terminator. This routine is named to 3660 * be compatible with historical functions that did this by querying the 3661 * underlying C++ type. 3662 * 3663 * @see llvm::Instruction::isTerminator() 3664 */ 3665 LLVMValueRef LLVMIsATerminatorInst(LLVMValueRef Inst); 3666 3667 /** 3668 * @defgroup LLVMCCoreValueInstructionCall Call Sites and Invocations 3669 * 3670 * Functions in this group apply to instructions that refer to call 3671 * sites and invocations. These correspond to C++ types in the 3672 * llvm::CallInst class tree. 3673 * 3674 * @{ 3675 */ 3676 3677 /** 3678 * Obtain the argument count for a call instruction. 3679 * 3680 * This expects an LLVMValueRef that corresponds to a llvm::CallInst, 3681 * llvm::InvokeInst, or llvm:FuncletPadInst. 3682 * 3683 * @see llvm::CallInst::getNumArgOperands() 3684 * @see llvm::InvokeInst::getNumArgOperands() 3685 * @see llvm::FuncletPadInst::getNumArgOperands() 3686 */ 3687 unsigned LLVMGetNumArgOperands(LLVMValueRef Instr); 3688 3689 /** 3690 * Set the calling convention for a call instruction. 3691 * 3692 * This expects an LLVMValueRef that corresponds to a llvm::CallInst or 3693 * llvm::InvokeInst. 3694 * 3695 * @see llvm::CallInst::setCallingConv() 3696 * @see llvm::InvokeInst::setCallingConv() 3697 */ 3698 void LLVMSetInstructionCallConv(LLVMValueRef Instr, unsigned CC); 3699 3700 /** 3701 * Obtain the calling convention for a call instruction. 3702 * 3703 * This is the opposite of LLVMSetInstructionCallConv(). Reads its 3704 * usage. 3705 * 3706 * @see LLVMSetInstructionCallConv() 3707 */ 3708 unsigned LLVMGetInstructionCallConv(LLVMValueRef Instr); 3709 3710 void LLVMSetInstrParamAlignment(LLVMValueRef Instr, LLVMAttributeIndex Idx, 3711 unsigned Align); 3712 3713 void LLVMAddCallSiteAttribute(LLVMValueRef C, LLVMAttributeIndex Idx, 3714 LLVMAttributeRef A); 3715 unsigned LLVMGetCallSiteAttributeCount(LLVMValueRef C, LLVMAttributeIndex Idx); 3716 void LLVMGetCallSiteAttributes(LLVMValueRef C, LLVMAttributeIndex Idx, 3717 LLVMAttributeRef *Attrs); 3718 LLVMAttributeRef LLVMGetCallSiteEnumAttribute(LLVMValueRef C, 3719 LLVMAttributeIndex Idx, 3720 unsigned KindID); 3721 LLVMAttributeRef LLVMGetCallSiteStringAttribute(LLVMValueRef C, 3722 LLVMAttributeIndex Idx, 3723 const char *K, unsigned KLen); 3724 void LLVMRemoveCallSiteEnumAttribute(LLVMValueRef C, LLVMAttributeIndex Idx, 3725 unsigned KindID); 3726 void LLVMRemoveCallSiteStringAttribute(LLVMValueRef C, LLVMAttributeIndex Idx, 3727 const char *K, unsigned KLen); 3728 3729 /** 3730 * Obtain the function type called by this instruction. 3731 * 3732 * @see llvm::CallBase::getFunctionType() 3733 */ 3734 LLVMTypeRef LLVMGetCalledFunctionType(LLVMValueRef C); 3735 3736 /** 3737 * Obtain the pointer to the function invoked by this instruction. 3738 * 3739 * This expects an LLVMValueRef that corresponds to a llvm::CallInst or 3740 * llvm::InvokeInst. 3741 * 3742 * @see llvm::CallInst::getCalledOperand() 3743 * @see llvm::InvokeInst::getCalledOperand() 3744 */ 3745 LLVMValueRef LLVMGetCalledValue(LLVMValueRef Instr); 3746 3747 /** 3748 * Obtain the number of operand bundles attached to this instruction. 3749 * 3750 * This only works on llvm::CallInst and llvm::InvokeInst instructions. 3751 * 3752 * @see llvm::CallBase::getNumOperandBundles() 3753 */ 3754 unsigned LLVMGetNumOperandBundles(LLVMValueRef C); 3755 3756 /** 3757 * Obtain the operand bundle attached to this instruction at the given index. 3758 * Use LLVMDisposeOperandBundle to free the operand bundle. 3759 * 3760 * This only works on llvm::CallInst and llvm::InvokeInst instructions. 3761 */ 3762 LLVMOperandBundleRef LLVMGetOperandBundleAtIndex(LLVMValueRef C, 3763 unsigned Index); 3764 3765 /** 3766 * Obtain whether a call instruction is a tail call. 3767 * 3768 * This only works on llvm::CallInst instructions. 3769 * 3770 * @see llvm::CallInst::isTailCall() 3771 */ 3772 LLVMBool LLVMIsTailCall(LLVMValueRef CallInst); 3773 3774 /** 3775 * Set whether a call instruction is a tail call. 3776 * 3777 * This only works on llvm::CallInst instructions. 3778 * 3779 * @see llvm::CallInst::setTailCall() 3780 */ 3781 void LLVMSetTailCall(LLVMValueRef CallInst, LLVMBool IsTailCall); 3782 3783 /** 3784 * Obtain a tail call kind of the call instruction. 3785 * 3786 * @see llvm::CallInst::setTailCallKind() 3787 */ 3788 LLVMTailCallKind LLVMGetTailCallKind(LLVMValueRef CallInst); 3789 3790 /** 3791 * Set the call kind of the call instruction. 3792 * 3793 * @see llvm::CallInst::getTailCallKind() 3794 */ 3795 void LLVMSetTailCallKind(LLVMValueRef CallInst, LLVMTailCallKind kind); 3796 3797 /** 3798 * Return the normal destination basic block. 3799 * 3800 * This only works on llvm::InvokeInst instructions. 3801 * 3802 * @see llvm::InvokeInst::getNormalDest() 3803 */ 3804 LLVMBasicBlockRef LLVMGetNormalDest(LLVMValueRef InvokeInst); 3805 3806 /** 3807 * Return the unwind destination basic block. 3808 * 3809 * Works on llvm::InvokeInst, llvm::CleanupReturnInst, and 3810 * llvm::CatchSwitchInst instructions. 3811 * 3812 * @see llvm::InvokeInst::getUnwindDest() 3813 * @see llvm::CleanupReturnInst::getUnwindDest() 3814 * @see llvm::CatchSwitchInst::getUnwindDest() 3815 */ 3816 LLVMBasicBlockRef LLVMGetUnwindDest(LLVMValueRef InvokeInst); 3817 3818 /** 3819 * Set the normal destination basic block. 3820 * 3821 * This only works on llvm::InvokeInst instructions. 3822 * 3823 * @see llvm::InvokeInst::setNormalDest() 3824 */ 3825 void LLVMSetNormalDest(LLVMValueRef InvokeInst, LLVMBasicBlockRef B); 3826 3827 /** 3828 * Set the unwind destination basic block. 3829 * 3830 * Works on llvm::InvokeInst, llvm::CleanupReturnInst, and 3831 * llvm::CatchSwitchInst instructions. 3832 * 3833 * @see llvm::InvokeInst::setUnwindDest() 3834 * @see llvm::CleanupReturnInst::setUnwindDest() 3835 * @see llvm::CatchSwitchInst::setUnwindDest() 3836 */ 3837 void LLVMSetUnwindDest(LLVMValueRef InvokeInst, LLVMBasicBlockRef B); 3838 3839 /** 3840 * Get the default destination of a CallBr instruction. 3841 * 3842 * @see llvm::CallBrInst::getDefaultDest() 3843 */ 3844 LLVMBasicBlockRef LLVMGetCallBrDefaultDest(LLVMValueRef CallBr); 3845 3846 /** 3847 * Get the number of indirect destinations of a CallBr instruction. 3848 * 3849 * @see llvm::CallBrInst::getNumIndirectDests() 3850 3851 */ 3852 unsigned LLVMGetCallBrNumIndirectDests(LLVMValueRef CallBr); 3853 3854 /** 3855 * Get the indirect destination of a CallBr instruction at the given index. 3856 * 3857 * @see llvm::CallBrInst::getIndirectDest() 3858 */ 3859 LLVMBasicBlockRef LLVMGetCallBrIndirectDest(LLVMValueRef CallBr, unsigned Idx); 3860 3861 /** 3862 * @} 3863 */ 3864 3865 /** 3866 * @defgroup LLVMCCoreValueInstructionTerminator Terminators 3867 * 3868 * Functions in this group only apply to instructions for which 3869 * LLVMIsATerminatorInst returns true. 3870 * 3871 * @{ 3872 */ 3873 3874 /** 3875 * Return the number of successors that this terminator has. 3876 * 3877 * @see llvm::Instruction::getNumSuccessors 3878 */ 3879 unsigned LLVMGetNumSuccessors(LLVMValueRef Term); 3880 3881 /** 3882 * Return the specified successor. 3883 * 3884 * @see llvm::Instruction::getSuccessor 3885 */ 3886 LLVMBasicBlockRef LLVMGetSuccessor(LLVMValueRef Term, unsigned i); 3887 3888 /** 3889 * Update the specified successor to point at the provided block. 3890 * 3891 * @see llvm::Instruction::setSuccessor 3892 */ 3893 void LLVMSetSuccessor(LLVMValueRef Term, unsigned i, LLVMBasicBlockRef block); 3894 3895 /** 3896 * Return if a branch is conditional. 3897 * 3898 * This only works on llvm::BranchInst instructions. 3899 * 3900 * @see llvm::BranchInst::isConditional 3901 */ 3902 LLVMBool LLVMIsConditional(LLVMValueRef Branch); 3903 3904 /** 3905 * Return the condition of a branch instruction. 3906 * 3907 * This only works on llvm::BranchInst instructions. 3908 * 3909 * @see llvm::BranchInst::getCondition 3910 */ 3911 LLVMValueRef LLVMGetCondition(LLVMValueRef Branch); 3912 3913 /** 3914 * Set the condition of a branch instruction. 3915 * 3916 * This only works on llvm::BranchInst instructions. 3917 * 3918 * @see llvm::BranchInst::setCondition 3919 */ 3920 void LLVMSetCondition(LLVMValueRef Branch, LLVMValueRef Cond); 3921 3922 /** 3923 * Obtain the default destination basic block of a switch instruction. 3924 * 3925 * This only works on llvm::SwitchInst instructions. 3926 * 3927 * @see llvm::SwitchInst::getDefaultDest() 3928 */ 3929 LLVMBasicBlockRef LLVMGetSwitchDefaultDest(LLVMValueRef SwitchInstr); 3930 3931 /** 3932 * @} 3933 */ 3934 3935 /** 3936 * @defgroup LLVMCCoreValueInstructionAlloca Allocas 3937 * 3938 * Functions in this group only apply to instructions that map to 3939 * llvm::AllocaInst instances. 3940 * 3941 * @{ 3942 */ 3943 3944 /** 3945 * Obtain the type that is being allocated by the alloca instruction. 3946 */ 3947 LLVMTypeRef LLVMGetAllocatedType(LLVMValueRef Alloca); 3948 3949 /** 3950 * @} 3951 */ 3952 3953 /** 3954 * @defgroup LLVMCCoreValueInstructionGetElementPointer GEPs 3955 * 3956 * Functions in this group only apply to instructions that map to 3957 * llvm::GetElementPtrInst instances. 3958 * 3959 * @{ 3960 */ 3961 3962 /** 3963 * Check whether the given GEP operator is inbounds. 3964 */ 3965 LLVMBool LLVMIsInBounds(LLVMValueRef GEP); 3966 3967 /** 3968 * Set the given GEP instruction to be inbounds or not. 3969 */ 3970 void LLVMSetIsInBounds(LLVMValueRef GEP, LLVMBool InBounds); 3971 3972 /** 3973 * Get the source element type of the given GEP operator. 3974 */ 3975 LLVMTypeRef LLVMGetGEPSourceElementType(LLVMValueRef GEP); 3976 3977 /** 3978 * Get the no-wrap related flags for the given GEP instruction. 3979 * 3980 * @see llvm::GetElementPtrInst::getNoWrapFlags 3981 */ 3982 LLVMGEPNoWrapFlags LLVMGEPGetNoWrapFlags(LLVMValueRef GEP); 3983 3984 /** 3985 * Set the no-wrap related flags for the given GEP instruction. 3986 * 3987 * @see llvm::GetElementPtrInst::setNoWrapFlags 3988 */ 3989 void LLVMGEPSetNoWrapFlags(LLVMValueRef GEP, LLVMGEPNoWrapFlags NoWrapFlags); 3990 3991 /** 3992 * @} 3993 */ 3994 3995 /** 3996 * @defgroup LLVMCCoreValueInstructionPHINode PHI Nodes 3997 * 3998 * Functions in this group only apply to instructions that map to 3999 * llvm::PHINode instances. 4000 * 4001 * @{ 4002 */ 4003 4004 /** 4005 * Add an incoming value to the end of a PHI list. 4006 */ 4007 void LLVMAddIncoming(LLVMValueRef PhiNode, LLVMValueRef *IncomingValues, 4008 LLVMBasicBlockRef *IncomingBlocks, unsigned Count); 4009 4010 /** 4011 * Obtain the number of incoming basic blocks to a PHI node. 4012 */ 4013 unsigned LLVMCountIncoming(LLVMValueRef PhiNode); 4014 4015 /** 4016 * Obtain an incoming value to a PHI node as an LLVMValueRef. 4017 */ 4018 LLVMValueRef LLVMGetIncomingValue(LLVMValueRef PhiNode, unsigned Index); 4019 4020 /** 4021 * Obtain an incoming value to a PHI node as an LLVMBasicBlockRef. 4022 */ 4023 LLVMBasicBlockRef LLVMGetIncomingBlock(LLVMValueRef PhiNode, unsigned Index); 4024 4025 /** 4026 * @} 4027 */ 4028 4029 /** 4030 * @defgroup LLVMCCoreValueInstructionExtractValue ExtractValue 4031 * @defgroup LLVMCCoreValueInstructionInsertValue InsertValue 4032 * 4033 * Functions in this group only apply to instructions that map to 4034 * llvm::ExtractValue and llvm::InsertValue instances. 4035 * 4036 * @{ 4037 */ 4038 4039 /** 4040 * Obtain the number of indices. 4041 * NB: This also works on GEP operators. 4042 */ 4043 unsigned LLVMGetNumIndices(LLVMValueRef Inst); 4044 4045 /** 4046 * Obtain the indices as an array. 4047 */ 4048 const unsigned *LLVMGetIndices(LLVMValueRef Inst); 4049 4050 /** 4051 * @} 4052 */ 4053 4054 /** 4055 * @} 4056 */ 4057 4058 /** 4059 * @} 4060 */ 4061 4062 /** 4063 * @defgroup LLVMCCoreInstructionBuilder Instruction Builders 4064 * 4065 * An instruction builder represents a point within a basic block and is 4066 * the exclusive means of building instructions using the C interface. 4067 * 4068 * @{ 4069 */ 4070 4071 LLVMBuilderRef LLVMCreateBuilderInContext(LLVMContextRef C); 4072 LLVMBuilderRef LLVMCreateBuilder(void); 4073 /** 4074 * Set the builder position before Instr but after any attached debug records, 4075 * or if Instr is null set the position to the end of Block. 4076 */ 4077 void LLVMPositionBuilder(LLVMBuilderRef Builder, LLVMBasicBlockRef Block, 4078 LLVMValueRef Instr); 4079 /** 4080 * Set the builder position before Instr and any attached debug records, 4081 * or if Instr is null set the position to the end of Block. 4082 */ 4083 void LLVMPositionBuilderBeforeDbgRecords(LLVMBuilderRef Builder, 4084 LLVMBasicBlockRef Block, 4085 LLVMValueRef Inst); 4086 /** 4087 * Set the builder position before Instr but after any attached debug records. 4088 */ 4089 void LLVMPositionBuilderBefore(LLVMBuilderRef Builder, LLVMValueRef Instr); 4090 /** 4091 * Set the builder position before Instr and any attached debug records. 4092 */ 4093 void LLVMPositionBuilderBeforeInstrAndDbgRecords(LLVMBuilderRef Builder, 4094 LLVMValueRef Instr); 4095 void LLVMPositionBuilderAtEnd(LLVMBuilderRef Builder, LLVMBasicBlockRef Block); 4096 LLVMBasicBlockRef LLVMGetInsertBlock(LLVMBuilderRef Builder); 4097 void LLVMClearInsertionPosition(LLVMBuilderRef Builder); 4098 void LLVMInsertIntoBuilder(LLVMBuilderRef Builder, LLVMValueRef Instr); 4099 void LLVMInsertIntoBuilderWithName(LLVMBuilderRef Builder, LLVMValueRef Instr, 4100 const char *Name); 4101 void LLVMDisposeBuilder(LLVMBuilderRef Builder); 4102 4103 /* Metadata */ 4104 4105 /** 4106 * Get location information used by debugging information. 4107 * 4108 * @see llvm::IRBuilder::getCurrentDebugLocation() 4109 */ 4110 LLVMMetadataRef LLVMGetCurrentDebugLocation2(LLVMBuilderRef Builder); 4111 4112 /** 4113 * Set location information used by debugging information. 4114 * 4115 * To clear the location metadata of the given instruction, pass NULL to \p Loc. 4116 * 4117 * @see llvm::IRBuilder::SetCurrentDebugLocation() 4118 */ 4119 void LLVMSetCurrentDebugLocation2(LLVMBuilderRef Builder, LLVMMetadataRef Loc); 4120 4121 /** 4122 * Attempts to set the debug location for the given instruction using the 4123 * current debug location for the given builder. If the builder has no current 4124 * debug location, this function is a no-op. 4125 * 4126 * @deprecated LLVMSetInstDebugLocation is deprecated in favor of the more general 4127 * LLVMAddMetadataToInst. 4128 * 4129 * @see llvm::IRBuilder::SetInstDebugLocation() 4130 */ 4131 void LLVMSetInstDebugLocation(LLVMBuilderRef Builder, LLVMValueRef Inst); 4132 4133 /** 4134 * Adds the metadata registered with the given builder to the given instruction. 4135 * 4136 * @see llvm::IRBuilder::AddMetadataToInst() 4137 */ 4138 void LLVMAddMetadataToInst(LLVMBuilderRef Builder, LLVMValueRef Inst); 4139 4140 /** 4141 * Get the dafult floating-point math metadata for a given builder. 4142 * 4143 * @see llvm::IRBuilder::getDefaultFPMathTag() 4144 */ 4145 LLVMMetadataRef LLVMBuilderGetDefaultFPMathTag(LLVMBuilderRef Builder); 4146 4147 /** 4148 * Set the default floating-point math metadata for the given builder. 4149 * 4150 * To clear the metadata, pass NULL to \p FPMathTag. 4151 * 4152 * @see llvm::IRBuilder::setDefaultFPMathTag() 4153 */ 4154 void LLVMBuilderSetDefaultFPMathTag(LLVMBuilderRef Builder, 4155 LLVMMetadataRef FPMathTag); 4156 4157 /** 4158 * Deprecated: Passing the NULL location will crash. 4159 * Use LLVMGetCurrentDebugLocation2 instead. 4160 */ 4161 void LLVMSetCurrentDebugLocation(LLVMBuilderRef Builder, LLVMValueRef L); 4162 /** 4163 * Deprecated: Returning the NULL location will crash. 4164 * Use LLVMGetCurrentDebugLocation2 instead. 4165 */ 4166 LLVMValueRef LLVMGetCurrentDebugLocation(LLVMBuilderRef Builder); 4167 4168 /* Terminators */ 4169 LLVMValueRef LLVMBuildRetVoid(LLVMBuilderRef); 4170 LLVMValueRef LLVMBuildRet(LLVMBuilderRef, LLVMValueRef V); 4171 LLVMValueRef LLVMBuildAggregateRet(LLVMBuilderRef, LLVMValueRef *RetVals, 4172 unsigned N); 4173 LLVMValueRef LLVMBuildBr(LLVMBuilderRef, LLVMBasicBlockRef Dest); 4174 LLVMValueRef LLVMBuildCondBr(LLVMBuilderRef, LLVMValueRef If, 4175 LLVMBasicBlockRef Then, LLVMBasicBlockRef Else); 4176 LLVMValueRef LLVMBuildSwitch(LLVMBuilderRef, LLVMValueRef V, 4177 LLVMBasicBlockRef Else, unsigned NumCases); 4178 LLVMValueRef LLVMBuildIndirectBr(LLVMBuilderRef B, LLVMValueRef Addr, 4179 unsigned NumDests); 4180 LLVMValueRef LLVMBuildCallBr(LLVMBuilderRef B, LLVMTypeRef Ty, LLVMValueRef Fn, 4181 LLVMBasicBlockRef DefaultDest, 4182 LLVMBasicBlockRef *IndirectDests, 4183 unsigned NumIndirectDests, LLVMValueRef *Args, 4184 unsigned NumArgs, LLVMOperandBundleRef *Bundles, 4185 unsigned NumBundles, const char *Name); 4186 LLVMValueRef LLVMBuildInvoke2(LLVMBuilderRef, LLVMTypeRef Ty, LLVMValueRef Fn, 4187 LLVMValueRef *Args, unsigned NumArgs, 4188 LLVMBasicBlockRef Then, LLVMBasicBlockRef Catch, 4189 const char *Name); 4190 LLVMValueRef LLVMBuildInvokeWithOperandBundles( 4191 LLVMBuilderRef, LLVMTypeRef Ty, LLVMValueRef Fn, LLVMValueRef *Args, 4192 unsigned NumArgs, LLVMBasicBlockRef Then, LLVMBasicBlockRef Catch, 4193 LLVMOperandBundleRef *Bundles, unsigned NumBundles, const char *Name); 4194 LLVMValueRef LLVMBuildUnreachable(LLVMBuilderRef); 4195 4196 /* Exception Handling */ 4197 LLVMValueRef LLVMBuildResume(LLVMBuilderRef B, LLVMValueRef Exn); 4198 LLVMValueRef LLVMBuildLandingPad(LLVMBuilderRef B, LLVMTypeRef Ty, 4199 LLVMValueRef PersFn, unsigned NumClauses, 4200 const char *Name); 4201 LLVMValueRef LLVMBuildCleanupRet(LLVMBuilderRef B, LLVMValueRef CatchPad, 4202 LLVMBasicBlockRef BB); 4203 LLVMValueRef LLVMBuildCatchRet(LLVMBuilderRef B, LLVMValueRef CatchPad, 4204 LLVMBasicBlockRef BB); 4205 LLVMValueRef LLVMBuildCatchPad(LLVMBuilderRef B, LLVMValueRef ParentPad, 4206 LLVMValueRef *Args, unsigned NumArgs, 4207 const char *Name); 4208 LLVMValueRef LLVMBuildCleanupPad(LLVMBuilderRef B, LLVMValueRef ParentPad, 4209 LLVMValueRef *Args, unsigned NumArgs, 4210 const char *Name); 4211 LLVMValueRef LLVMBuildCatchSwitch(LLVMBuilderRef B, LLVMValueRef ParentPad, 4212 LLVMBasicBlockRef UnwindBB, 4213 unsigned NumHandlers, const char *Name); 4214 4215 /* Add a case to the switch instruction */ 4216 void LLVMAddCase(LLVMValueRef Switch, LLVMValueRef OnVal, 4217 LLVMBasicBlockRef Dest); 4218 4219 /* Add a destination to the indirectbr instruction */ 4220 void LLVMAddDestination(LLVMValueRef IndirectBr, LLVMBasicBlockRef Dest); 4221 4222 /* Get the number of clauses on the landingpad instruction */ 4223 unsigned LLVMGetNumClauses(LLVMValueRef LandingPad); 4224 4225 /* Get the value of the clause at index Idx on the landingpad instruction */ 4226 LLVMValueRef LLVMGetClause(LLVMValueRef LandingPad, unsigned Idx); 4227 4228 /* Add a catch or filter clause to the landingpad instruction */ 4229 void LLVMAddClause(LLVMValueRef LandingPad, LLVMValueRef ClauseVal); 4230 4231 /* Get the 'cleanup' flag in the landingpad instruction */ 4232 LLVMBool LLVMIsCleanup(LLVMValueRef LandingPad); 4233 4234 /* Set the 'cleanup' flag in the landingpad instruction */ 4235 void LLVMSetCleanup(LLVMValueRef LandingPad, LLVMBool Val); 4236 4237 /* Add a destination to the catchswitch instruction */ 4238 void LLVMAddHandler(LLVMValueRef CatchSwitch, LLVMBasicBlockRef Dest); 4239 4240 /* Get the number of handlers on the catchswitch instruction */ 4241 unsigned LLVMGetNumHandlers(LLVMValueRef CatchSwitch); 4242 4243 /** 4244 * Obtain the basic blocks acting as handlers for a catchswitch instruction. 4245 * 4246 * The Handlers parameter should point to a pre-allocated array of 4247 * LLVMBasicBlockRefs at least LLVMGetNumHandlers() large. On return, the 4248 * first LLVMGetNumHandlers() entries in the array will be populated 4249 * with LLVMBasicBlockRef instances. 4250 * 4251 * @param CatchSwitch The catchswitch instruction to operate on. 4252 * @param Handlers Memory address of an array to be filled with basic blocks. 4253 */ 4254 void LLVMGetHandlers(LLVMValueRef CatchSwitch, LLVMBasicBlockRef *Handlers); 4255 4256 /* Funclets */ 4257 4258 /* Get the number of funcletpad arguments. */ 4259 LLVMValueRef LLVMGetArgOperand(LLVMValueRef Funclet, unsigned i); 4260 4261 /* Set a funcletpad argument at the given index. */ 4262 void LLVMSetArgOperand(LLVMValueRef Funclet, unsigned i, LLVMValueRef value); 4263 4264 /** 4265 * Get the parent catchswitch instruction of a catchpad instruction. 4266 * 4267 * This only works on llvm::CatchPadInst instructions. 4268 * 4269 * @see llvm::CatchPadInst::getCatchSwitch() 4270 */ 4271 LLVMValueRef LLVMGetParentCatchSwitch(LLVMValueRef CatchPad); 4272 4273 /** 4274 * Set the parent catchswitch instruction of a catchpad instruction. 4275 * 4276 * This only works on llvm::CatchPadInst instructions. 4277 * 4278 * @see llvm::CatchPadInst::setCatchSwitch() 4279 */ 4280 void LLVMSetParentCatchSwitch(LLVMValueRef CatchPad, LLVMValueRef CatchSwitch); 4281 4282 /* Arithmetic */ 4283 LLVMValueRef LLVMBuildAdd(LLVMBuilderRef, LLVMValueRef LHS, LLVMValueRef RHS, 4284 const char *Name); 4285 LLVMValueRef LLVMBuildNSWAdd(LLVMBuilderRef, LLVMValueRef LHS, LLVMValueRef RHS, 4286 const char *Name); 4287 LLVMValueRef LLVMBuildNUWAdd(LLVMBuilderRef, LLVMValueRef LHS, LLVMValueRef RHS, 4288 const char *Name); 4289 LLVMValueRef LLVMBuildFAdd(LLVMBuilderRef, LLVMValueRef LHS, LLVMValueRef RHS, 4290 const char *Name); 4291 LLVMValueRef LLVMBuildSub(LLVMBuilderRef, LLVMValueRef LHS, LLVMValueRef RHS, 4292 const char *Name); 4293 LLVMValueRef LLVMBuildNSWSub(LLVMBuilderRef, LLVMValueRef LHS, LLVMValueRef RHS, 4294 const char *Name); 4295 LLVMValueRef LLVMBuildNUWSub(LLVMBuilderRef, LLVMValueRef LHS, LLVMValueRef RHS, 4296 const char *Name); 4297 LLVMValueRef LLVMBuildFSub(LLVMBuilderRef, LLVMValueRef LHS, LLVMValueRef RHS, 4298 const char *Name); 4299 LLVMValueRef LLVMBuildMul(LLVMBuilderRef, LLVMValueRef LHS, LLVMValueRef RHS, 4300 const char *Name); 4301 LLVMValueRef LLVMBuildNSWMul(LLVMBuilderRef, LLVMValueRef LHS, LLVMValueRef RHS, 4302 const char *Name); 4303 LLVMValueRef LLVMBuildNUWMul(LLVMBuilderRef, LLVMValueRef LHS, LLVMValueRef RHS, 4304 const char *Name); 4305 LLVMValueRef LLVMBuildFMul(LLVMBuilderRef, LLVMValueRef LHS, LLVMValueRef RHS, 4306 const char *Name); 4307 LLVMValueRef LLVMBuildUDiv(LLVMBuilderRef, LLVMValueRef LHS, LLVMValueRef RHS, 4308 const char *Name); 4309 LLVMValueRef LLVMBuildExactUDiv(LLVMBuilderRef, LLVMValueRef LHS, LLVMValueRef RHS, 4310 const char *Name); 4311 LLVMValueRef LLVMBuildSDiv(LLVMBuilderRef, LLVMValueRef LHS, LLVMValueRef RHS, 4312 const char *Name); 4313 LLVMValueRef LLVMBuildExactSDiv(LLVMBuilderRef, LLVMValueRef LHS, LLVMValueRef RHS, 4314 const char *Name); 4315 LLVMValueRef LLVMBuildFDiv(LLVMBuilderRef, LLVMValueRef LHS, LLVMValueRef RHS, 4316 const char *Name); 4317 LLVMValueRef LLVMBuildURem(LLVMBuilderRef, LLVMValueRef LHS, LLVMValueRef RHS, 4318 const char *Name); 4319 LLVMValueRef LLVMBuildSRem(LLVMBuilderRef, LLVMValueRef LHS, LLVMValueRef RHS, 4320 const char *Name); 4321 LLVMValueRef LLVMBuildFRem(LLVMBuilderRef, LLVMValueRef LHS, LLVMValueRef RHS, 4322 const char *Name); 4323 LLVMValueRef LLVMBuildShl(LLVMBuilderRef, LLVMValueRef LHS, LLVMValueRef RHS, 4324 const char *Name); 4325 LLVMValueRef LLVMBuildLShr(LLVMBuilderRef, LLVMValueRef LHS, LLVMValueRef RHS, 4326 const char *Name); 4327 LLVMValueRef LLVMBuildAShr(LLVMBuilderRef, LLVMValueRef LHS, LLVMValueRef RHS, 4328 const char *Name); 4329 LLVMValueRef LLVMBuildAnd(LLVMBuilderRef, LLVMValueRef LHS, LLVMValueRef RHS, 4330 const char *Name); 4331 LLVMValueRef LLVMBuildOr(LLVMBuilderRef, LLVMValueRef LHS, LLVMValueRef RHS, 4332 const char *Name); 4333 LLVMValueRef LLVMBuildXor(LLVMBuilderRef, LLVMValueRef LHS, LLVMValueRef RHS, 4334 const char *Name); 4335 LLVMValueRef LLVMBuildBinOp(LLVMBuilderRef B, LLVMOpcode Op, 4336 LLVMValueRef LHS, LLVMValueRef RHS, 4337 const char *Name); 4338 LLVMValueRef LLVMBuildNeg(LLVMBuilderRef, LLVMValueRef V, const char *Name); 4339 LLVMValueRef LLVMBuildNSWNeg(LLVMBuilderRef B, LLVMValueRef V, 4340 const char *Name); 4341 LLVM_ATTRIBUTE_C_DEPRECATED(LLVMValueRef LLVMBuildNUWNeg(LLVMBuilderRef B, 4342 LLVMValueRef V, 4343 const char *Name), 4344 "Use LLVMBuildNeg + LLVMSetNUW instead."); 4345 LLVMValueRef LLVMBuildFNeg(LLVMBuilderRef, LLVMValueRef V, const char *Name); 4346 LLVMValueRef LLVMBuildNot(LLVMBuilderRef, LLVMValueRef V, const char *Name); 4347 4348 LLVMBool LLVMGetNUW(LLVMValueRef ArithInst); 4349 void LLVMSetNUW(LLVMValueRef ArithInst, LLVMBool HasNUW); 4350 LLVMBool LLVMGetNSW(LLVMValueRef ArithInst); 4351 void LLVMSetNSW(LLVMValueRef ArithInst, LLVMBool HasNSW); 4352 LLVMBool LLVMGetExact(LLVMValueRef DivOrShrInst); 4353 void LLVMSetExact(LLVMValueRef DivOrShrInst, LLVMBool IsExact); 4354 4355 /** 4356 * Gets if the instruction has the non-negative flag set. 4357 * Only valid for zext instructions. 4358 */ 4359 LLVMBool LLVMGetNNeg(LLVMValueRef NonNegInst); 4360 /** 4361 * Sets the non-negative flag for the instruction. 4362 * Only valid for zext instructions. 4363 */ 4364 void LLVMSetNNeg(LLVMValueRef NonNegInst, LLVMBool IsNonNeg); 4365 4366 /** 4367 * Get the flags for which fast-math-style optimizations are allowed for this 4368 * value. 4369 * 4370 * Only valid on floating point instructions. 4371 * @see LLVMCanValueUseFastMathFlags 4372 */ 4373 LLVMFastMathFlags LLVMGetFastMathFlags(LLVMValueRef FPMathInst); 4374 4375 /** 4376 * Sets the flags for which fast-math-style optimizations are allowed for this 4377 * value. 4378 * 4379 * Only valid on floating point instructions. 4380 * @see LLVMCanValueUseFastMathFlags 4381 */ 4382 void LLVMSetFastMathFlags(LLVMValueRef FPMathInst, LLVMFastMathFlags FMF); 4383 4384 /** 4385 * Check if a given value can potentially have fast math flags. 4386 * 4387 * Will return true for floating point arithmetic instructions, and for select, 4388 * phi, and call instructions whose type is a floating point type, or a vector 4389 * or array thereof. See https://llvm.org/docs/LangRef.html#fast-math-flags 4390 */ 4391 LLVMBool LLVMCanValueUseFastMathFlags(LLVMValueRef Inst); 4392 4393 /** 4394 * Gets whether the instruction has the disjoint flag set. 4395 * Only valid for or instructions. 4396 */ 4397 LLVMBool LLVMGetIsDisjoint(LLVMValueRef Inst); 4398 /** 4399 * Sets the disjoint flag for the instruction. 4400 * Only valid for or instructions. 4401 */ 4402 void LLVMSetIsDisjoint(LLVMValueRef Inst, LLVMBool IsDisjoint); 4403 4404 /* Memory */ 4405 LLVMValueRef LLVMBuildMalloc(LLVMBuilderRef, LLVMTypeRef Ty, const char *Name); 4406 LLVMValueRef LLVMBuildArrayMalloc(LLVMBuilderRef, LLVMTypeRef Ty, 4407 LLVMValueRef Val, const char *Name); 4408 4409 /** 4410 * Creates and inserts a memset to the specified pointer and the 4411 * specified value. 4412 * 4413 * @see llvm::IRRBuilder::CreateMemSet() 4414 */ 4415 LLVMValueRef LLVMBuildMemSet(LLVMBuilderRef B, LLVMValueRef Ptr, 4416 LLVMValueRef Val, LLVMValueRef Len, 4417 unsigned Align); 4418 /** 4419 * Creates and inserts a memcpy between the specified pointers. 4420 * 4421 * @see llvm::IRRBuilder::CreateMemCpy() 4422 */ 4423 LLVMValueRef LLVMBuildMemCpy(LLVMBuilderRef B, 4424 LLVMValueRef Dst, unsigned DstAlign, 4425 LLVMValueRef Src, unsigned SrcAlign, 4426 LLVMValueRef Size); 4427 /** 4428 * Creates and inserts a memmove between the specified pointers. 4429 * 4430 * @see llvm::IRRBuilder::CreateMemMove() 4431 */ 4432 LLVMValueRef LLVMBuildMemMove(LLVMBuilderRef B, 4433 LLVMValueRef Dst, unsigned DstAlign, 4434 LLVMValueRef Src, unsigned SrcAlign, 4435 LLVMValueRef Size); 4436 4437 LLVMValueRef LLVMBuildAlloca(LLVMBuilderRef, LLVMTypeRef Ty, const char *Name); 4438 LLVMValueRef LLVMBuildArrayAlloca(LLVMBuilderRef, LLVMTypeRef Ty, 4439 LLVMValueRef Val, const char *Name); 4440 LLVMValueRef LLVMBuildFree(LLVMBuilderRef, LLVMValueRef PointerVal); 4441 LLVMValueRef LLVMBuildLoad2(LLVMBuilderRef, LLVMTypeRef Ty, 4442 LLVMValueRef PointerVal, const char *Name); 4443 LLVMValueRef LLVMBuildStore(LLVMBuilderRef, LLVMValueRef Val, LLVMValueRef Ptr); 4444 LLVMValueRef LLVMBuildGEP2(LLVMBuilderRef B, LLVMTypeRef Ty, 4445 LLVMValueRef Pointer, LLVMValueRef *Indices, 4446 unsigned NumIndices, const char *Name); 4447 LLVMValueRef LLVMBuildInBoundsGEP2(LLVMBuilderRef B, LLVMTypeRef Ty, 4448 LLVMValueRef Pointer, LLVMValueRef *Indices, 4449 unsigned NumIndices, const char *Name); 4450 /** 4451 * Creates a GetElementPtr instruction. Similar to LLVMBuildGEP2, but allows 4452 * specifying the no-wrap flags. 4453 * 4454 * @see llvm::IRBuilder::CreateGEP() 4455 */ 4456 LLVMValueRef LLVMBuildGEPWithNoWrapFlags(LLVMBuilderRef B, LLVMTypeRef Ty, 4457 LLVMValueRef Pointer, 4458 LLVMValueRef *Indices, 4459 unsigned NumIndices, const char *Name, 4460 LLVMGEPNoWrapFlags NoWrapFlags); 4461 LLVMValueRef LLVMBuildStructGEP2(LLVMBuilderRef B, LLVMTypeRef Ty, 4462 LLVMValueRef Pointer, unsigned Idx, 4463 const char *Name); 4464 LLVMValueRef LLVMBuildGlobalString(LLVMBuilderRef B, const char *Str, 4465 const char *Name); 4466 LLVMValueRef LLVMBuildGlobalStringPtr(LLVMBuilderRef B, const char *Str, 4467 const char *Name); 4468 LLVMBool LLVMGetVolatile(LLVMValueRef MemoryAccessInst); 4469 void LLVMSetVolatile(LLVMValueRef MemoryAccessInst, LLVMBool IsVolatile); 4470 LLVMBool LLVMGetWeak(LLVMValueRef CmpXchgInst); 4471 void LLVMSetWeak(LLVMValueRef CmpXchgInst, LLVMBool IsWeak); 4472 LLVMAtomicOrdering LLVMGetOrdering(LLVMValueRef MemoryAccessInst); 4473 void LLVMSetOrdering(LLVMValueRef MemoryAccessInst, LLVMAtomicOrdering Ordering); 4474 LLVMAtomicRMWBinOp LLVMGetAtomicRMWBinOp(LLVMValueRef AtomicRMWInst); 4475 void LLVMSetAtomicRMWBinOp(LLVMValueRef AtomicRMWInst, LLVMAtomicRMWBinOp BinOp); 4476 4477 /* Casts */ 4478 LLVMValueRef LLVMBuildTrunc(LLVMBuilderRef, LLVMValueRef Val, 4479 LLVMTypeRef DestTy, const char *Name); 4480 LLVMValueRef LLVMBuildZExt(LLVMBuilderRef, LLVMValueRef Val, 4481 LLVMTypeRef DestTy, const char *Name); 4482 LLVMValueRef LLVMBuildSExt(LLVMBuilderRef, LLVMValueRef Val, 4483 LLVMTypeRef DestTy, const char *Name); 4484 LLVMValueRef LLVMBuildFPToUI(LLVMBuilderRef, LLVMValueRef Val, 4485 LLVMTypeRef DestTy, const char *Name); 4486 LLVMValueRef LLVMBuildFPToSI(LLVMBuilderRef, LLVMValueRef Val, 4487 LLVMTypeRef DestTy, const char *Name); 4488 LLVMValueRef LLVMBuildUIToFP(LLVMBuilderRef, LLVMValueRef Val, 4489 LLVMTypeRef DestTy, const char *Name); 4490 LLVMValueRef LLVMBuildSIToFP(LLVMBuilderRef, LLVMValueRef Val, 4491 LLVMTypeRef DestTy, const char *Name); 4492 LLVMValueRef LLVMBuildFPTrunc(LLVMBuilderRef, LLVMValueRef Val, 4493 LLVMTypeRef DestTy, const char *Name); 4494 LLVMValueRef LLVMBuildFPExt(LLVMBuilderRef, LLVMValueRef Val, 4495 LLVMTypeRef DestTy, const char *Name); 4496 LLVMValueRef LLVMBuildPtrToInt(LLVMBuilderRef, LLVMValueRef Val, 4497 LLVMTypeRef DestTy, const char *Name); 4498 LLVMValueRef LLVMBuildIntToPtr(LLVMBuilderRef, LLVMValueRef Val, 4499 LLVMTypeRef DestTy, const char *Name); 4500 LLVMValueRef LLVMBuildBitCast(LLVMBuilderRef, LLVMValueRef Val, 4501 LLVMTypeRef DestTy, const char *Name); 4502 LLVMValueRef LLVMBuildAddrSpaceCast(LLVMBuilderRef, LLVMValueRef Val, 4503 LLVMTypeRef DestTy, const char *Name); 4504 LLVMValueRef LLVMBuildZExtOrBitCast(LLVMBuilderRef, LLVMValueRef Val, 4505 LLVMTypeRef DestTy, const char *Name); 4506 LLVMValueRef LLVMBuildSExtOrBitCast(LLVMBuilderRef, LLVMValueRef Val, 4507 LLVMTypeRef DestTy, const char *Name); 4508 LLVMValueRef LLVMBuildTruncOrBitCast(LLVMBuilderRef, LLVMValueRef Val, 4509 LLVMTypeRef DestTy, const char *Name); 4510 LLVMValueRef LLVMBuildCast(LLVMBuilderRef B, LLVMOpcode Op, LLVMValueRef Val, 4511 LLVMTypeRef DestTy, const char *Name); 4512 LLVMValueRef LLVMBuildPointerCast(LLVMBuilderRef, LLVMValueRef Val, 4513 LLVMTypeRef DestTy, const char *Name); 4514 LLVMValueRef LLVMBuildIntCast2(LLVMBuilderRef, LLVMValueRef Val, 4515 LLVMTypeRef DestTy, LLVMBool IsSigned, 4516 const char *Name); 4517 LLVMValueRef LLVMBuildFPCast(LLVMBuilderRef, LLVMValueRef Val, 4518 LLVMTypeRef DestTy, const char *Name); 4519 4520 /** Deprecated: This cast is always signed. Use LLVMBuildIntCast2 instead. */ 4521 LLVMValueRef LLVMBuildIntCast(LLVMBuilderRef, LLVMValueRef Val, /*Signed cast!*/ 4522 LLVMTypeRef DestTy, const char *Name); 4523 4524 LLVMOpcode LLVMGetCastOpcode(LLVMValueRef Src, LLVMBool SrcIsSigned, 4525 LLVMTypeRef DestTy, LLVMBool DestIsSigned); 4526 4527 /* Comparisons */ 4528 LLVMValueRef LLVMBuildICmp(LLVMBuilderRef, LLVMIntPredicate Op, 4529 LLVMValueRef LHS, LLVMValueRef RHS, 4530 const char *Name); 4531 LLVMValueRef LLVMBuildFCmp(LLVMBuilderRef, LLVMRealPredicate Op, 4532 LLVMValueRef LHS, LLVMValueRef RHS, 4533 const char *Name); 4534 4535 /* Miscellaneous instructions */ 4536 LLVMValueRef LLVMBuildPhi(LLVMBuilderRef, LLVMTypeRef Ty, const char *Name); 4537 LLVMValueRef LLVMBuildCall2(LLVMBuilderRef, LLVMTypeRef, LLVMValueRef Fn, 4538 LLVMValueRef *Args, unsigned NumArgs, 4539 const char *Name); 4540 LLVMValueRef 4541 LLVMBuildCallWithOperandBundles(LLVMBuilderRef, LLVMTypeRef, LLVMValueRef Fn, 4542 LLVMValueRef *Args, unsigned NumArgs, 4543 LLVMOperandBundleRef *Bundles, 4544 unsigned NumBundles, const char *Name); 4545 LLVMValueRef LLVMBuildSelect(LLVMBuilderRef, LLVMValueRef If, 4546 LLVMValueRef Then, LLVMValueRef Else, 4547 const char *Name); 4548 LLVMValueRef LLVMBuildVAArg(LLVMBuilderRef, LLVMValueRef List, LLVMTypeRef Ty, 4549 const char *Name); 4550 LLVMValueRef LLVMBuildExtractElement(LLVMBuilderRef, LLVMValueRef VecVal, 4551 LLVMValueRef Index, const char *Name); 4552 LLVMValueRef LLVMBuildInsertElement(LLVMBuilderRef, LLVMValueRef VecVal, 4553 LLVMValueRef EltVal, LLVMValueRef Index, 4554 const char *Name); 4555 LLVMValueRef LLVMBuildShuffleVector(LLVMBuilderRef, LLVMValueRef V1, 4556 LLVMValueRef V2, LLVMValueRef Mask, 4557 const char *Name); 4558 LLVMValueRef LLVMBuildExtractValue(LLVMBuilderRef, LLVMValueRef AggVal, 4559 unsigned Index, const char *Name); 4560 LLVMValueRef LLVMBuildInsertValue(LLVMBuilderRef, LLVMValueRef AggVal, 4561 LLVMValueRef EltVal, unsigned Index, 4562 const char *Name); 4563 LLVMValueRef LLVMBuildFreeze(LLVMBuilderRef, LLVMValueRef Val, 4564 const char *Name); 4565 4566 LLVMValueRef LLVMBuildIsNull(LLVMBuilderRef, LLVMValueRef Val, 4567 const char *Name); 4568 LLVMValueRef LLVMBuildIsNotNull(LLVMBuilderRef, LLVMValueRef Val, 4569 const char *Name); 4570 LLVMValueRef LLVMBuildPtrDiff2(LLVMBuilderRef, LLVMTypeRef ElemTy, 4571 LLVMValueRef LHS, LLVMValueRef RHS, 4572 const char *Name); 4573 LLVMValueRef LLVMBuildFence(LLVMBuilderRef B, LLVMAtomicOrdering ordering, 4574 LLVMBool singleThread, const char *Name); 4575 LLVMValueRef LLVMBuildAtomicRMW(LLVMBuilderRef B, LLVMAtomicRMWBinOp op, 4576 LLVMValueRef PTR, LLVMValueRef Val, 4577 LLVMAtomicOrdering ordering, 4578 LLVMBool singleThread); 4579 LLVMValueRef LLVMBuildAtomicCmpXchg(LLVMBuilderRef B, LLVMValueRef Ptr, 4580 LLVMValueRef Cmp, LLVMValueRef New, 4581 LLVMAtomicOrdering SuccessOrdering, 4582 LLVMAtomicOrdering FailureOrdering, 4583 LLVMBool SingleThread); 4584 4585 /** 4586 * Get the number of elements in the mask of a ShuffleVector instruction. 4587 */ 4588 unsigned LLVMGetNumMaskElements(LLVMValueRef ShuffleVectorInst); 4589 4590 /** 4591 * \returns a constant that specifies that the result of a \c ShuffleVectorInst 4592 * is undefined. 4593 */ 4594 int LLVMGetUndefMaskElem(void); 4595 4596 /** 4597 * Get the mask value at position Elt in the mask of a ShuffleVector 4598 * instruction. 4599 * 4600 * \Returns the result of \c LLVMGetUndefMaskElem() if the mask value is 4601 * poison at that position. 4602 */ 4603 int LLVMGetMaskValue(LLVMValueRef ShuffleVectorInst, unsigned Elt); 4604 4605 LLVMBool LLVMIsAtomicSingleThread(LLVMValueRef AtomicInst); 4606 void LLVMSetAtomicSingleThread(LLVMValueRef AtomicInst, LLVMBool SingleThread); 4607 4608 LLVMAtomicOrdering LLVMGetCmpXchgSuccessOrdering(LLVMValueRef CmpXchgInst); 4609 void LLVMSetCmpXchgSuccessOrdering(LLVMValueRef CmpXchgInst, 4610 LLVMAtomicOrdering Ordering); 4611 LLVMAtomicOrdering LLVMGetCmpXchgFailureOrdering(LLVMValueRef CmpXchgInst); 4612 void LLVMSetCmpXchgFailureOrdering(LLVMValueRef CmpXchgInst, 4613 LLVMAtomicOrdering Ordering); 4614 4615 /** 4616 * @} 4617 */ 4618 4619 /** 4620 * @defgroup LLVMCCoreModuleProvider Module Providers 4621 * 4622 * @{ 4623 */ 4624 4625 /** 4626 * Changes the type of M so it can be passed to FunctionPassManagers and the 4627 * JIT. They take ModuleProviders for historical reasons. 4628 */ 4629 LLVMModuleProviderRef 4630 LLVMCreateModuleProviderForExistingModule(LLVMModuleRef M); 4631 4632 /** 4633 * Destroys the module M. 4634 */ 4635 void LLVMDisposeModuleProvider(LLVMModuleProviderRef M); 4636 4637 /** 4638 * @} 4639 */ 4640 4641 /** 4642 * @defgroup LLVMCCoreMemoryBuffers Memory Buffers 4643 * 4644 * @{ 4645 */ 4646 4647 LLVMBool LLVMCreateMemoryBufferWithContentsOfFile(const char *Path, 4648 LLVMMemoryBufferRef *OutMemBuf, 4649 char **OutMessage); 4650 LLVMBool LLVMCreateMemoryBufferWithSTDIN(LLVMMemoryBufferRef *OutMemBuf, 4651 char **OutMessage); 4652 LLVMMemoryBufferRef LLVMCreateMemoryBufferWithMemoryRange(const char *InputData, 4653 size_t InputDataLength, 4654 const char *BufferName, 4655 LLVMBool RequiresNullTerminator); 4656 LLVMMemoryBufferRef LLVMCreateMemoryBufferWithMemoryRangeCopy(const char *InputData, 4657 size_t InputDataLength, 4658 const char *BufferName); 4659 const char *LLVMGetBufferStart(LLVMMemoryBufferRef MemBuf); 4660 size_t LLVMGetBufferSize(LLVMMemoryBufferRef MemBuf); 4661 void LLVMDisposeMemoryBuffer(LLVMMemoryBufferRef MemBuf); 4662 4663 /** 4664 * @} 4665 */ 4666 4667 /** 4668 * @defgroup LLVMCCorePassManagers Pass Managers 4669 * @ingroup LLVMCCore 4670 * 4671 * @{ 4672 */ 4673 4674 /** Constructs a new whole-module pass pipeline. This type of pipeline is 4675 suitable for link-time optimization and whole-module transformations. 4676 @see llvm::PassManager::PassManager */ 4677 LLVMPassManagerRef LLVMCreatePassManager(void); 4678 4679 /** Constructs a new function-by-function pass pipeline over the module 4680 provider. It does not take ownership of the module provider. This type of 4681 pipeline is suitable for code generation and JIT compilation tasks. 4682 @see llvm::FunctionPassManager::FunctionPassManager */ 4683 LLVMPassManagerRef LLVMCreateFunctionPassManagerForModule(LLVMModuleRef M); 4684 4685 /** Deprecated: Use LLVMCreateFunctionPassManagerForModule instead. */ 4686 LLVMPassManagerRef LLVMCreateFunctionPassManager(LLVMModuleProviderRef MP); 4687 4688 /** Initializes, executes on the provided module, and finalizes all of the 4689 passes scheduled in the pass manager. Returns 1 if any of the passes 4690 modified the module, 0 otherwise. 4691 @see llvm::PassManager::run(Module&) */ 4692 LLVMBool LLVMRunPassManager(LLVMPassManagerRef PM, LLVMModuleRef M); 4693 4694 /** Initializes all of the function passes scheduled in the function pass 4695 manager. Returns 1 if any of the passes modified the module, 0 otherwise. 4696 @see llvm::FunctionPassManager::doInitialization */ 4697 LLVMBool LLVMInitializeFunctionPassManager(LLVMPassManagerRef FPM); 4698 4699 /** Executes all of the function passes scheduled in the function pass manager 4700 on the provided function. Returns 1 if any of the passes modified the 4701 function, false otherwise. 4702 @see llvm::FunctionPassManager::run(Function&) */ 4703 LLVMBool LLVMRunFunctionPassManager(LLVMPassManagerRef FPM, LLVMValueRef F); 4704 4705 /** Finalizes all of the function passes scheduled in the function pass 4706 manager. Returns 1 if any of the passes modified the module, 0 otherwise. 4707 @see llvm::FunctionPassManager::doFinalization */ 4708 LLVMBool LLVMFinalizeFunctionPassManager(LLVMPassManagerRef FPM); 4709 4710 /** Frees the memory of a pass pipeline. For function pipelines, does not free 4711 the module provider. 4712 @see llvm::PassManagerBase::~PassManagerBase. */ 4713 void LLVMDisposePassManager(LLVMPassManagerRef PM); 4714 4715 /** 4716 * @} 4717 */ 4718 4719 /** 4720 * @defgroup LLVMCCoreThreading Threading 4721 * 4722 * Handle the structures needed to make LLVM safe for multithreading. 4723 * 4724 * @{ 4725 */ 4726 4727 /** Deprecated: Multi-threading can only be enabled/disabled with the compile 4728 time define LLVM_ENABLE_THREADS. This function always returns 4729 LLVMIsMultithreaded(). */ 4730 LLVMBool LLVMStartMultithreaded(void); 4731 4732 /** Deprecated: Multi-threading can only be enabled/disabled with the compile 4733 time define LLVM_ENABLE_THREADS. */ 4734 void LLVMStopMultithreaded(void); 4735 4736 /** Check whether LLVM is executing in thread-safe mode or not. 4737 @see llvm::llvm_is_multithreaded */ 4738 LLVMBool LLVMIsMultithreaded(void); 4739 4740 /** 4741 * @} 4742 */ 4743 4744 /** 4745 * @} 4746 */ 4747 4748 /** 4749 * @} 4750 */ 4751 4752 LLVM_C_EXTERN_C_END 4753 4754 #endif /* LLVM_C_CORE_H */ 4755