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