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