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