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