1 /*===-- llvm-c/Core.h - Core Library C Interface ------------------*- C -*-===*\ 2 |* *| 3 |* The LLVM Compiler Infrastructure *| 4 |* *| 5 |* This file is distributed under the University of Illinois Open Source *| 6 |* License. See LICENSE.TXT for details. *| 7 |* *| 8 |*===----------------------------------------------------------------------===*| 9 |* *| 10 |* This header declares the C interface to libLLVMCore.a, which implements *| 11 |* the LLVM intermediate representation. *| 12 |* *| 13 \*===----------------------------------------------------------------------===*/ 14 15 module llvm.c.core; 16 17 public import llvm.c.types; 18 19 extern(C) nothrow: 20 21 /** 22 * @defgroup LLVMC LLVM-C: C interface to LLVM 23 * 24 * This module exposes parts of the LLVM library as a C API. 25 * 26 * @{ 27 */ 28 29 /** 30 * @defgroup LLVMCTransforms Transforms 31 */ 32 33 /** 34 * @defgroup LLVMCCore Core 35 * 36 * This modules provide an interface to libLLVMCore, which implements 37 * the LLVM intermediate representation as well as other related types 38 * and utilities. 39 * 40 * Many exotic languages can interoperate with C code but have a harder time 41 * with C++ due to name mangling. So in addition to C, this interface enables 42 * tools written in such languages. 43 * 44 * @{ 45 */ 46 47 /** 48 * @defgroup LLVMCCoreTypes Types and Enumerations 49 * 50 * @{ 51 */ 52 53 enum LLVMAttribute { 54 ZExt = 1 << 0, 55 SExt = 1 << 1, 56 NoReturn = 1 << 2, 57 InReg = 1 << 3, 58 StructRet = 1 << 4, 59 NoUnwind = 1 << 5, 60 NoAlias = 1 << 6, 61 ByVal = 1 << 7, 62 Nest = 1 << 8, 63 ReadNone = 1 << 9, 64 ReadOnly = 1 << 10, 65 NoInline = 1 << 11, 66 AlwaysInline = 1 << 12, 67 OptimizeForSize = 1 << 13, 68 StackProtect = 1 << 14, 69 StackProtectReq = 1 << 15, 70 Alignment = 31<< 16, 71 NoCapture = 1 << 21, 72 NoRedZone = 1 << 22, 73 NoImplicitFloat = 1 << 23, 74 Naked = 1 << 24, 75 InlineHint = 1 << 25, 76 StackAlignment = 7 << 26, 77 ReturnsTwice = 1 << 29, 78 UWTable = 1 << 30, 79 NonLazyBind = 1 << 31, 80 81 /* FIXME: These attributes are currently not included in the C API as 82 a temporary measure until the API/ABI impact to the C API is understood 83 and the path forward agreed upon. 84 SanitizeAddress = 1ULL << 32, 85 StackProtectStrongAttribute = 1ULL<<35, 86 Cold = 1ULL << 40, 87 OptimizeNone = 1ULL << 42, 88 InAlloca = 1ULL << 43, 89 NonNull = 1ULL << 44, 90 JumpTable = 1ULL << 45, 91 Convergent = 1ULL << 46, 92 SafeStack = 1ULL << 47, 93 SwiftSelf = 1ULL << 48, 94 SwiftError = 1ULL << 49, 95 */ 96 } 97 98 enum LLVMOpcode { 99 /* Terminator Instructions */ 100 Ret = 1, 101 Br = 2, 102 Switch = 3, 103 IndirectBr = 4, 104 Invoke = 5, 105 /* removed 6 due to API changes */ 106 Unreachable = 7, 107 108 /* Standard Binary Operators */ 109 Add = 8, 110 FAdd = 9, 111 Sub = 10, 112 FSub = 11, 113 Mul = 12, 114 FMul = 13, 115 UDiv = 14, 116 SDiv = 15, 117 FDiv = 16, 118 URem = 17, 119 SRem = 18, 120 FRem = 19, 121 122 /* Logical Operators */ 123 Shl = 20, 124 LShr = 21, 125 AShr = 22, 126 And = 23, 127 Or = 24, 128 Xor = 25, 129 130 /* Memory Operators */ 131 Alloca = 26, 132 Load = 27, 133 Store = 28, 134 GetElementPtr = 29, 135 136 /* Cast Operators */ 137 Trunc = 30, 138 ZExt = 31, 139 SExt = 32, 140 FPToUI = 33, 141 FPToSI = 34, 142 UIToFP = 35, 143 SIToFP = 36, 144 FPTrunc = 37, 145 FPExt = 38, 146 PtrToInt = 39, 147 IntToPtr = 40, 148 BitCast = 41, 149 AddrSpaceCast = 60, 150 151 /* Other Operators */ 152 ICmp = 42, 153 FCmp = 43, 154 PHI = 44, 155 Call = 45, 156 Select = 46, 157 UserOp1 = 47, 158 UserOp2 = 48, 159 VAArg = 49, 160 ExtractElement = 50, 161 InsertElement = 51, 162 ShuffleVector = 52, 163 ExtractValue = 53, 164 InsertValue = 54, 165 166 /* Atomic operators */ 167 Fence = 55, 168 AtomicCmpXchg = 56, 169 AtomicRMW = 57, 170 171 /* Exception Handling Operators */ 172 Resume = 58, 173 LandingPad = 59, 174 CleanupRet = 61, 175 CatchRet = 62, 176 CatchPad = 63, 177 CleanupPad = 64, 178 CatchSwitch = 65, 179 } 180 181 enum LLVMTypeKind { 182 Void, /**< type with no size */ 183 Half, /**< 16 bit floating point type */ 184 Float, /**< 32 bit floating point type */ 185 Double, /**< 64 bit floating point type */ 186 X86_FP80, /**< 80 bit floating point type (X87) */ 187 FP128, /**< 128 bit floating point type (112-bit mantissa)*/ 188 PPC_FP128, /**< 128 bit floating point type (two 64-bits) */ 189 Label, /**< Labels */ 190 Integer, /**< Arbitrary bit width integers */ 191 Function, /**< Functions */ 192 Struct, /**< Structures */ 193 Array, /**< Arrays */ 194 Pointer, /**< Pointers */ 195 Vector, /**< SIMD 'packed' format, or other vector type */ 196 Metadata, /**< Metadata */ 197 X86_MMX, /**< X86 MMX */ 198 Token, /**< Tokens */ 199 } 200 201 enum LLVMLinkage { 202 External, /**< Externally visible function */ 203 AvailableExternally, 204 LinkOnceAny, /**< Keep one copy of function when linking (inline)*/ 205 LinkOnceODR, /**< Same, but only replaced by something 206 equivalent. */ 207 LinkOnceODRAutoHide, /**< Obsolete */ 208 WeakAny, /**< Keep one copy of function when linking (weak) */ 209 WeakODR, /**< Same, but only replaced by something 210 equivalent. */ 211 Appending, /**< Special purpose, only applies to global arrays */ 212 Internal, /**< Rename collisions when linking (static 213 functions) */ 214 Private, /**< Like Internal, but omit from symbol table */ 215 DLLImport, /**< Obsolete */ 216 DLLExport, /**< Obsolete */ 217 ExternalWeak,/**< ExternalWeak linkage description */ 218 Ghost, /**< Obsolete */ 219 Common, /**< Tentative definitions */ 220 LinkerPrivate, /**< Like Private, but linker removes. */ 221 LinkerPrivateWeak, /**< Like LinkerPrivate, but is weak. */ 222 } 223 224 enum LLVMVisibility { 225 Default, /**< The GV is visible */ 226 Hidden, /**< The GV is hidden */ 227 Protected, /**< The GV is protected */ 228 } 229 230 enum LLVMDLLStorageClass { 231 Default = 0, 232 DLLImport = 1, /**< Function to be imported from DLL. */ 233 DLLExport = 2, /**< Function to be accessible from DLL. */ 234 } 235 236 enum LLVMCallConv { 237 C = 0, 238 Fast = 8, 239 Cold = 9, 240 WebKitJS = 12, 241 AnyReg = 13, 242 X86Stdcall = 64, 243 X86Fastcall = 65, 244 } 245 246 enum LLVMValueKind { 247 Argument, 248 BasicBlock, 249 MemoryUse, 250 MemoryDef, 251 MemoryPhi, 252 253 Function, 254 GlobalAlias, 255 GlobalIFunc, 256 GobalVariable, 257 BlockAddress, 258 ConstantExpr, 259 ConstantArray, 260 ConstantStruct, 261 ConstantVector, 262 263 UndefValue, 264 ConstantAggregateZero, 265 ConstantDataArray, 266 ConstantDataVector, 267 ConstantInt, 268 ConstantFP, 269 ConstantPointerNull, 270 ConstantTokenNone, 271 272 MetadataAsValue, 273 InlineAsm, 274 275 Instruction, 276 } 277 278 enum LLVMIntPredicate { 279 EQ = 32, /**< equal */ 280 NE, /**< not equal */ 281 UGT, /**< unsigned greater than */ 282 UGE, /**< unsigned greater or equal */ 283 ULT, /**< unsigned less than */ 284 ULE, /**< unsigned less or equal */ 285 SGT, /**< signed greater than */ 286 SGE, /**< signed greater or equal */ 287 SLT, /**< signed less than */ 288 SLE, /**< signed less or equal */ 289 } 290 291 enum LLVMRealPredicate { 292 False, /**< Always false (always folded) */ 293 OEQ, /**< True if ordered and equal */ 294 OGT, /**< True if ordered and greater than */ 295 OGE, /**< True if ordered and greater than or equal */ 296 OLT, /**< True if ordered and less than */ 297 OLE, /**< True if ordered and less than or equal */ 298 ONE, /**< True if ordered and operands are unequal */ 299 ORD, /**< True if ordered (no nans) */ 300 UNO, /**< True if unordered: isnan(X) | isnan(Y) */ 301 UEQ, /**< True if unordered or equal */ 302 UGT, /**< True if unordered or greater than */ 303 UGE, /**< True if unordered, greater than, or equal */ 304 ULT, /**< True if unordered or less than */ 305 ULE, /**< True if unordered, less than, or equal */ 306 UNE, /**< True if unordered or not equal */ 307 True, /**< Always true (always folded) */ 308 } 309 310 enum LLVMLandingPadClauseTy { 311 Catch, /**< A catch clause */ 312 Filter, /**< A filter clause */ 313 } 314 315 enum LLVMThreadLocalMode { 316 NotThreadLocal = 0, 317 GeneralDynamic, 318 LocalDynamic, 319 InitialExec, 320 LocalExec, 321 } 322 323 enum LLVMAtomicOrdering { 324 NotAtomic = 0, /**< A load or store which is not atomic */ 325 Unordered = 1, /**< Lowest level of atomicity, guarantees 326 somewhat sane results, lock free. */ 327 Monotonic = 2, /**< guarantees that if you take all the 328 operations affecting a specific address, 329 a consistent ordering exists */ 330 Acquire = 4, /**< Acquire provides a barrier of the sort 331 necessary to acquire a lock to access other 332 memory with normal loads and stores. */ 333 Release = 5, /**< Release is similar to Acquire, but with 334 a barrier of the sort necessary to release 335 a lock. */ 336 AcquireRelease = 6, /**< provides both an Acquire and a 337 Release barrier (for fences and 338 operations which both read and write 339 memory). */ 340 SequentiallyConsistent = 7, /**< provides Acquire semantics 341 for loads and Release 342 semantics for stores. 343 Additionally, it guarantees 344 that a total ordering exists 345 between all 346 SequentiallyConsistent 347 operations. */ 348 } 349 350 enum LLVMAtomicRMWBinOp { 351 Xchg, /**< Set the new value and return the one old */ 352 Add, /**< Add a value and return the old one */ 353 Sub, /**< Subtract a value and return the old one */ 354 And, /**< And a value and return the old one */ 355 Nand, /**< Not-And a value and return the old one */ 356 Or, /**< OR a value and return the old one */ 357 Xor, /**< Xor a value and return the old one */ 358 Max, /**< Sets the value if it's greater than the 359 original using a signed comparison and return 360 the old one */ 361 Min, /**< Sets the value if it's Smaller than the 362 original using a signed comparison and return 363 the old one */ 364 UMax, /**< Sets the value if it's greater than the 365 original using an unsigned comparison and return 366 the old one */ 367 UMin, /**< Sets the value if it's greater than the 368 original using an unsigned comparison and return 369 the old one */ 370 } 371 372 enum LLVMDiagnosticSeverity { 373 Error, 374 Warning, 375 Remark, 376 Note, 377 } 378 379 /** 380 * Attribute index are either LLVMAttributeReturnIndex, 381 * LLVMAttributeFunctionIndex or a parameter number from 1 to N. 382 */ 383 enum : uint { 384 LLVMAttributeReturnIndex = 0U, 385 // ISO C restricts enumerator values to range of 'int' 386 // (4294967295 is too large) 387 // LLVMAttributeFunctionIndex = ~0U, 388 LLVMAttributeFunctionIndex = -1, 389 }; 390 391 alias LLVMAttributeIndex = uint; 392 393 /** 394 * @} 395 */ 396 397 void LLVMInitializeCore(LLVMPassRegistryRef R); 398 399 /** Deallocate and destroy all ManagedStatic variables. 400 @see llvm::llvm_shutdown 401 @see ManagedStatic */ 402 void LLVMShutdown(); 403 404 /*===-- Error handling ----------------------------------------------------===*/ 405 406 char* LLVMCreateMessage(const(char)* Message); 407 void LLVMDisposeMessage(char* Message); 408 409 /** 410 * @defgroup LLVMCCoreContext Contexts 411 * 412 * Contexts are execution states for the core LLVM IR system. 413 * 414 * Most types are tied to a context instance. Multiple contexts can 415 * exist simultaneously. A single context is not thread safe. However, 416 * different contexts can execute on different threads simultaneously. 417 * 418 * @{ 419 */ 420 421 alias LLVMDiagnosticHandler = void function(LLVMDiagnosticInfoRef, void*); 422 alias LLVMYieldCallback = void function(LLVMContextRef, void*); 423 424 /** 425 * Create a new context. 426 * 427 * Every call to this function should be paired with a call to 428 * LLVMContextDispose() or the context will leak memory. 429 */ 430 LLVMContextRef LLVMContextCreate(); 431 432 /** 433 * Obtain the global context instance. 434 */ 435 LLVMContextRef LLVMGetGlobalContext(); 436 437 /** 438 * Set the diagnostic handler for this context. 439 */ 440 void LLVMContextSetDiagnosticHandler(LLVMContextRef C, 441 LLVMDiagnosticHandler Handler, 442 void* DiagnosticContext); 443 444 /** 445 * Get the diagnostic handler of this context. 446 */ 447 LLVMDiagnosticHandler LLVMContextGetDiagnosticHandler(LLVMContextRef C); 448 449 /** 450 * Get the diagnostic context of this context. 451 */ 452 void* LLVMContextGetDiagnosticContext(LLVMContextRef C); 453 454 /** 455 * Set the yield callback function for this context. 456 * 457 * @see LLVMContext::setYieldCallback() 458 */ 459 void LLVMContextSetYieldCallback(LLVMContextRef C, LLVMYieldCallback Callback, 460 void* OpaqueHandle); 461 462 /** 463 * Destroy a context instance. 464 * 465 * This should be called for every call to LLVMContextCreate() or memory 466 * will be leaked. 467 */ 468 void LLVMContextDispose(LLVMContextRef C); 469 470 /** 471 * Return a string representation of the DiagnosticInfo. Use 472 * LLVMDisposeMessage to free the string. 473 * 474 * @see DiagnosticInfo::print() 475 */ 476 char* LLVMGetDiagInfoDescription(LLVMDiagnosticInfoRef DI); 477 478 /** 479 * Return an enum LLVMDiagnosticSeverity. 480 * 481 * @see DiagnosticInfo::getSeverity() 482 */ 483 LLVMDiagnosticSeverity LLVMGetDiagInfoSeverity(LLVMDiagnosticInfoRef DI); 484 485 uint LLVMGetMDKindIDInContext(LLVMContextRef C, const(char)* Name, 486 uint SLen); 487 uint LLVMGetMDKindID(const(char)* Name, uint SLen); 488 489 /** 490 * Return an unique id given the name of a enum attribute, 491 * or 0 if no attribute by that name exists. 492 * 493 * See http://llvm.org/docs/LangRef.html#parameter-attributes 494 * and http://llvm.org/docs/LangRef.html#function-attributes 495 * for the list of available attributes. 496 * 497 * NB: Attribute names and/or id are subject to change without 498 * going through the C API deprecation cycle. 499 */ 500 uint LLVMGetEnumAttributeKindForName(const char *Name, size_t SLen); 501 uint LLVMGetLastEnumAttributeKind(); 502 503 /** 504 * Create an enum attribute. 505 */ 506 LLVMAttributeRef LLVMCreateEnumAttribute(LLVMContextRef C, uint KindID, 507 ulong Val); 508 509 /** 510 * Get the unique id corresponding to the enum attribute 511 * passed as argument. 512 */ 513 uint LLVMGetEnumAttributeKind(LLVMAttributeRef A); 514 515 /** 516 * Get the enum attribute's value. 0 is returned if none exists. 517 */ 518 ulong LLVMGetEnumAttributeValue(LLVMAttributeRef A); 519 520 /** 521 * Create a string attribute. 522 */ 523 LLVMAttributeRef LLVMCreateStringAttribute(LLVMContextRef C, 524 const(char)* K, uint KLength, 525 const(char)* V, uint VLength); 526 527 /** 528 * Get the string attribute's kind. 529 */ 530 const(char)* LLVMGetStringAttributeKind(LLVMAttributeRef A, uint* Length); 531 532 /** 533 * Get the string attribute's value. 534 */ 535 const(char)* LLVMGetStringAttributeValue(LLVMAttributeRef A, uint* Length); 536 537 /** 538 * Check for the different types of attributes. 539 */ 540 LLVMBool LLVMIsEnumAttribute(LLVMAttributeRef A); 541 LLVMBool LLVMIsStringAttribute(LLVMAttributeRef A); 542 543 /** 544 * @} 545 */ 546 547 /** 548 * @defgroup LLVMCCoreModule Modules 549 * 550 * Modules represent the top-level structure in an LLVM program. An LLVM 551 * module is effectively a translation unit or a collection of 552 * translation units merged together. 553 * 554 * @{ 555 */ 556 557 /** 558 * Create a new, empty module in the global context. 559 * 560 * This is equivalent to calling LLVMModuleCreateWithNameInContext with 561 * LLVMGetGlobalContext() as the context parameter. 562 * 563 * Every invocation should be paired with LLVMDisposeModule() or memory 564 * will be leaked. 565 */ 566 LLVMModuleRef LLVMModuleCreateWithName(const(char)* ModuleID); 567 568 /** 569 * Create a new, empty module in a specific context. 570 * 571 * Every invocation should be paired with LLVMDisposeModule() or memory 572 * will be leaked. 573 */ 574 LLVMModuleRef LLVMModuleCreateWithNameInContext(const(char)* ModuleID, 575 LLVMContextRef C); 576 /** 577 * Return an exact copy of the specified module. 578 */ 579 LLVMModuleRef LLVMCloneModule(LLVMModuleRef M); 580 581 /** 582 * Destroy a module instance. 583 * 584 * This must be called for every created module or memory will be 585 * leaked. 586 */ 587 void LLVMDisposeModule(LLVMModuleRef M); 588 589 /** 590 * Obtain the identifier of a module. 591 * 592 * @param M Module to obtain identifier of 593 * @param Len Out parameter which holds the length of the returned string. 594 * @return The identifier of M. 595 * @see Module::getModuleIdentifier() 596 */ 597 const(char)* LLVMGetModuleIdentifier(LLVMModuleRef M, size_t* Len); 598 599 /** 600 * Set the identifier of a module to a string Ident with length Len. 601 * 602 * @param M The module to set identifier 603 * @param Ident The string to set M's identifier to 604 * @param Len Length of Ident 605 * @see Module::setModuleIdentifier() 606 */ 607 void LLVMSetModuleIdentifier(LLVMModuleRef M, const(char)* Ident, size_t Len); 608 609 /** 610 * Obtain the data layout for a module. 611 * 612 * @see Module::getDataLayoutStr() 613 * 614 * LLVMGetDataLayout is DEPRECATED, as the name is not only incorrect, 615 * but match the name of another method on the module. Prefer the use 616 * of LLVMGetDataLayoutStr, which is not ambiguous. 617 */ 618 const(char)* LLVMGetDataLayoutStr(LLVMModuleRef M); 619 const(char)* LLVMGetDataLayout(LLVMModuleRef M); 620 621 /** 622 * Set the data layout for a module. 623 * 624 * @see Module::setDataLayout() 625 */ 626 void LLVMSetDataLayout(LLVMModuleRef M, const(char)* DataLayoutStr); 627 628 /** 629 * Obtain the target triple for a module. 630 * 631 * @see Module::getTargetTriple() 632 */ 633 const(char)* LLVMGetTarget(LLVMModuleRef M); 634 635 /** 636 * Set the target triple for a module. 637 * 638 * @see Module::setTargetTriple() 639 */ 640 void LLVMSetTarget(LLVMModuleRef M, const(char)* Triple); 641 642 /** 643 * Dump a representation of a module to stderr. 644 * 645 * @see Module::dump() 646 */ 647 void LLVMDumpModule(LLVMModuleRef M); 648 649 /** 650 * Print a representation of a module to a file. The ErrorMessage needs to be 651 * disposed with LLVMDisposeMessage. Returns 0 on success, 1 otherwise. 652 * 653 * @see Module::print() 654 */ 655 LLVMBool LLVMPrintModuleToFile(LLVMModuleRef M, const(char)* Filename, 656 char** ErrorMessage); 657 658 /** 659 * Return a string representation of the module. Use 660 * LLVMDisposeMessage to free the string. 661 * 662 * @see Module::print() 663 */ 664 char* LLVMPrintModuleToString(LLVMModuleRef M); 665 666 /** 667 * Set inline assembly for a module. 668 * 669 * @see Module::setModuleInlineAsm() 670 */ 671 void LLVMSetModuleInlineAsm(LLVMModuleRef M, const(char)* Asm); 672 673 /** 674 * Obtain the context to which this module is associated. 675 * 676 * @see Module::getContext() 677 */ 678 LLVMContextRef LLVMGetModuleContext(LLVMModuleRef M); 679 680 /** 681 * Obtain a Type from a module by its registered name. 682 */ 683 LLVMTypeRef LLVMGetTypeByName(LLVMModuleRef M, const(char)* Name); 684 685 /** 686 * Obtain the number of operands for named metadata in a module. 687 * 688 * @see llvm::Module::getNamedMetadata() 689 */ 690 uint LLVMGetNamedMetadataNumOperands(LLVMModuleRef M, const(char)* Name); 691 692 /** 693 * Obtain the named metadata operands for a module. 694 * 695 * The passed LLVMValueRef pointer should refer to an array of 696 * LLVMValueRef at least LLVMGetNamedMetadataNumOperands long. This 697 * array will be populated with the LLVMValueRef instances. Each 698 * instance corresponds to a llvm::MDNode. 699 * 700 * @see llvm::Module::getNamedMetadata() 701 * @see llvm::MDNode::getOperand() 702 */ 703 void LLVMGetNamedMetadataOperands(LLVMModuleRef M, const(char)* Name, 704 LLVMValueRef* Dest); 705 706 /** 707 * Add an operand to named metadata. 708 * 709 * @see llvm::Module::getNamedMetadata() 710 * @see llvm::MDNode::addOperand() 711 */ 712 void LLVMAddNamedMetadataOperand(LLVMModuleRef M, const(char)* Name, 713 LLVMValueRef Val); 714 715 /** 716 * Add a function to a module under a specified name. 717 * 718 * @see llvm::Function::Create() 719 */ 720 LLVMValueRef LLVMAddFunction(LLVMModuleRef M, const(char)* Name, 721 LLVMTypeRef FunctionTy); 722 723 /** 724 * Obtain a Function value from a Module by its name. 725 * 726 * The returned value corresponds to a llvm::Function value. 727 * 728 * @see llvm::Module::getFunction() 729 */ 730 LLVMValueRef LLVMGetNamedFunction(LLVMModuleRef M, const(char)* Name); 731 732 /** 733 * Obtain an iterator to the first Function in a Module. 734 * 735 * @see llvm::Module::begin() 736 */ 737 LLVMValueRef LLVMGetFirstFunction(LLVMModuleRef M); 738 739 /** 740 * Obtain an iterator to the last Function in a Module. 741 * 742 * @see llvm::Module::end() 743 */ 744 LLVMValueRef LLVMGetLastFunction(LLVMModuleRef M); 745 746 /** 747 * Advance a Function iterator to the next Function. 748 * 749 * Returns NULL if the iterator was already at the end and there are no more 750 * functions. 751 */ 752 LLVMValueRef LLVMGetNextFunction(LLVMValueRef Fn); 753 754 /** 755 * Decrement a Function iterator to the previous Function. 756 * 757 * Returns NULL if the iterator was already at the beginning and there are 758 * no previous functions. 759 */ 760 LLVMValueRef LLVMGetPreviousFunction(LLVMValueRef Fn); 761 762 /** 763 * @} 764 */ 765 766 /** 767 * @defgroup LLVMCCoreType Types 768 * 769 * Types represent the type of a value. 770 * 771 * Types are associated with a context instance. The context internally 772 * deduplicates types so there is only 1 instance of a specific type 773 * alive at a time. In other words, a unique type is shared among all 774 * consumers within a context. 775 * 776 * A Type in the C API corresponds to llvm::Type. 777 * 778 * Types have the following hierarchy: 779 * 780 * types: 781 * integer type 782 * real type 783 * function type 784 * sequence types: 785 * array type 786 * pointer type 787 * vector type 788 * void type 789 * label type 790 * opaque type 791 * 792 * @{ 793 */ 794 795 /** 796 * Obtain the enumerated type of a Type instance. 797 * 798 * @see llvm::Type:getTypeID() 799 */ 800 LLVMTypeKind LLVMGetTypeKind(LLVMTypeRef Ty); 801 802 /** 803 * Whether the type has a known size. 804 * 805 * Things that don't have a size are abstract types, labels, and void.a 806 * 807 * @see llvm::Type::isSized() 808 */ 809 LLVMBool LLVMTypeIsSized(LLVMTypeRef Ty); 810 811 /** 812 * Obtain the context to which this type instance is associated. 813 * 814 * @see llvm::Type::getContext() 815 */ 816 LLVMContextRef LLVMGetTypeContext(LLVMTypeRef Ty); 817 818 /** 819 * Dump a representation of a type to stderr. 820 * 821 * @see llvm::Type::dump() 822 */ 823 void LLVMDumpType(LLVMTypeRef Val); 824 825 /** 826 * Return a string representation of the type. Use 827 * LLVMDisposeMessage to free the string. 828 * 829 * @see llvm::Type::print() 830 */ 831 char* LLVMPrintTypeToString(LLVMTypeRef Val); 832 833 /** 834 * @defgroup LLVMCCoreTypeInt Integer Types 835 * 836 * Functions in this section operate on integer types. 837 * 838 * @{ 839 */ 840 841 /** 842 * Obtain an integer type from a context with specified bit width. 843 */ 844 LLVMTypeRef LLVMInt1TypeInContext(LLVMContextRef C); 845 LLVMTypeRef LLVMInt8TypeInContext(LLVMContextRef C); 846 LLVMTypeRef LLVMInt16TypeInContext(LLVMContextRef C); 847 LLVMTypeRef LLVMInt32TypeInContext(LLVMContextRef C); 848 LLVMTypeRef LLVMInt64TypeInContext(LLVMContextRef C); 849 LLVMTypeRef LLVMInt128TypeInContext(LLVMContextRef C); 850 LLVMTypeRef LLVMIntTypeInContext(LLVMContextRef C, uint NumBits); 851 852 /** 853 * Obtain an integer type from the global context with a specified bit 854 * width. 855 */ 856 LLVMTypeRef LLVMInt1Type(); 857 LLVMTypeRef LLVMInt8Type(); 858 LLVMTypeRef LLVMInt16Type(); 859 LLVMTypeRef LLVMInt32Type(); 860 LLVMTypeRef LLVMInt64Type(); 861 LLVMTypeRef LLVMInt128Type(); 862 LLVMTypeRef LLVMIntType(uint NumBits); 863 uint LLVMGetIntTypeWidth(LLVMTypeRef IntegerTy); 864 865 /** 866 * @} 867 */ 868 869 /** 870 * @defgroup LLVMCCoreTypeFloat Floating Point Types 871 * 872 * @{ 873 */ 874 875 /** 876 * Obtain a 16-bit floating point type from a context. 877 */ 878 LLVMTypeRef LLVMHalfTypeInContext(LLVMContextRef C); 879 880 /** 881 * Obtain a 32-bit floating point type from a context. 882 */ 883 LLVMTypeRef LLVMFloatTypeInContext(LLVMContextRef C); 884 885 /** 886 * Obtain a 64-bit floating point type from a context. 887 */ 888 LLVMTypeRef LLVMDoubleTypeInContext(LLVMContextRef C); 889 890 /** 891 * Obtain a 80-bit floating point type (X87) from a context. 892 */ 893 LLVMTypeRef LLVMX86FP80TypeInContext(LLVMContextRef C); 894 895 /** 896 * Obtain a 128-bit floating point type (112-bit mantissa) from a 897 * context. 898 */ 899 LLVMTypeRef LLVMFP128TypeInContext(LLVMContextRef C); 900 901 /** 902 * Obtain a 128-bit floating point type (two 64-bits) from a context. 903 */ 904 LLVMTypeRef LLVMPPCFP128TypeInContext(LLVMContextRef C); 905 906 /** 907 * Obtain a floating point type from the global context. 908 * 909 * These map to the functions in this group of the same name. 910 */ 911 LLVMTypeRef LLVMHalfType(); 912 LLVMTypeRef LLVMFloatType(); 913 LLVMTypeRef LLVMDoubleType(); 914 LLVMTypeRef LLVMX86FP80Type(); 915 LLVMTypeRef LLVMFP128Type(); 916 LLVMTypeRef LLVMPPCFP128Type(); 917 918 /** 919 * @} 920 */ 921 922 /** 923 * @defgroup LLVMCCoreTypeFunction Function Types 924 * 925 * @{ 926 */ 927 928 /** 929 * Obtain a function type consisting of a specified signature. 930 * 931 * The function is defined as a tuple of a return Type, a list of 932 * parameter types, and whether the function is variadic. 933 */ 934 LLVMTypeRef LLVMFunctionType(LLVMTypeRef ReturnType, 935 LLVMTypeRef *ParamTypes, uint ParamCount, 936 LLVMBool IsVarArg); 937 938 /** 939 * Returns whether a function type is variadic. 940 */ 941 LLVMBool LLVMIsFunctionVarArg(LLVMTypeRef FunctionTy); 942 943 /** 944 * Obtain the Type this function Type returns. 945 */ 946 LLVMTypeRef LLVMGetReturnType(LLVMTypeRef FunctionTy); 947 948 /** 949 * Obtain the number of parameters this function accepts. 950 */ 951 uint LLVMCountParamTypes(LLVMTypeRef FunctionTy); 952 953 /** 954 * Obtain the types of a function's parameters. 955 * 956 * The Dest parameter should point to a pre-allocated array of 957 * LLVMTypeRef at least LLVMCountParamTypes() large. On return, the 958 * first LLVMCountParamTypes() entries in the array will be populated 959 * with LLVMTypeRef instances. 960 * 961 * @param FunctionTy The function type to operate on. 962 * @param Dest Memory address of an array to be filled with result. 963 */ 964 void LLVMGetParamTypes(LLVMTypeRef FunctionTy, LLVMTypeRef* Dest); 965 966 /** 967 * @} 968 */ 969 970 /** 971 * @defgroup LLVMCCoreTypeStruct Structure Types 972 * 973 * These functions relate to LLVMTypeRef instances. 974 * 975 * @see llvm::StructType 976 * 977 * @{ 978 */ 979 980 /** 981 * Create a new structure type in a context. 982 * 983 * A structure is specified by a list of inner elements/types and 984 * whether these can be packed together. 985 * 986 * @see llvm::StructType::create() 987 */ 988 LLVMTypeRef LLVMStructTypeInContext(LLVMContextRef C, LLVMTypeRef* ElementTypes, 989 uint ElementCount, LLVMBool Packed); 990 991 /** 992 * Create a new structure type in the global context. 993 * 994 * @see llvm::StructType::create() 995 */ 996 LLVMTypeRef LLVMStructType(LLVMTypeRef *ElementTypes, uint ElementCount, 997 LLVMBool Packed); 998 999 /** 1000 * Create an empty structure in a context having a specified name. 1001 * 1002 * @see llvm::StructType::create() 1003 */ 1004 LLVMTypeRef LLVMStructCreateNamed(LLVMContextRef C, const(char)* Name); 1005 1006 /** 1007 * Obtain the name of a structure. 1008 * 1009 * @see llvm::StructType::getName() 1010 */ 1011 const(char)* LLVMGetStructName(LLVMTypeRef Ty); 1012 1013 /** 1014 * Set the contents of a structure type. 1015 * 1016 * @see llvm::StructType::setBody() 1017 */ 1018 void LLVMStructSetBody(LLVMTypeRef StructTy, LLVMTypeRef* ElementTypes, 1019 uint ElementCount, LLVMBool Packed); 1020 1021 /** 1022 * Get the number of elements defined inside the structure. 1023 * 1024 * @see llvm::StructType::getNumElements() 1025 */ 1026 uint LLVMCountStructElementTypes(LLVMTypeRef StructTy); 1027 1028 /** 1029 * Get the elements within a structure. 1030 * 1031 * The function is passed the address of a pre-allocated array of 1032 * LLVMTypeRef at least LLVMCountStructElementTypes() long. After 1033 * invocation, this array will be populated with the structure's 1034 * elements. The objects in the destination array will have a lifetime 1035 * of the structure type itself, which is the lifetime of the context it 1036 * is contained in. 1037 */ 1038 void LLVMGetStructElementTypes(LLVMTypeRef StructTy, LLVMTypeRef *Dest); 1039 1040 /** 1041 * Get the type of the element at a given index in the structure. 1042 * 1043 * @see llvm::StructType::getTypeAtIndex() 1044 */ 1045 LLVMTypeRef LLVMStructGetTypeAtIndex(LLVMTypeRef StructTy, uint i); 1046 1047 /** 1048 * Determine whether a structure is packed. 1049 * 1050 * @see llvm::StructType::isPacked() 1051 */ 1052 LLVMBool LLVMIsPackedStruct(LLVMTypeRef StructTy); 1053 1054 /** 1055 * Determine whether a structure is opaque. 1056 * 1057 * @see llvm::StructType::isOpaque() 1058 */ 1059 LLVMBool LLVMIsOpaqueStruct(LLVMTypeRef StructTy); 1060 1061 /** 1062 * @} 1063 */ 1064 1065 /** 1066 * @defgroup LLVMCCoreTypeSequential Sequential Types 1067 * 1068 * Sequential types represents "arrays" of types. This is a super class 1069 * for array, vector, and pointer types. 1070 * 1071 * @{ 1072 */ 1073 1074 /** 1075 * Obtain the type of elements within a sequential type. 1076 * 1077 * This works on array, vector, and pointer types. 1078 * 1079 * @see llvm::SequentialType::getElementType() 1080 */ 1081 LLVMTypeRef LLVMGetElementType(LLVMTypeRef Ty); 1082 1083 /** 1084 * Create a fixed size array type that refers to a specific type. 1085 * 1086 * The created type will exist in the context that its element type 1087 * exists in. 1088 * 1089 * @see llvm::ArrayType::get() 1090 */ 1091 LLVMTypeRef LLVMArrayType(LLVMTypeRef ElementType, uint ElementCount); 1092 1093 /** 1094 * Obtain the length of an array type. 1095 * 1096 * This only works on types that represent arrays. 1097 * 1098 * @see llvm::ArrayType::getNumElements() 1099 */ 1100 uint LLVMGetArrayLength(LLVMTypeRef ArrayTy); 1101 1102 /** 1103 * Create a pointer type that points to a defined type. 1104 * 1105 * The created type will exist in the context that its pointee type 1106 * exists in. 1107 * 1108 * @see llvm::PointerType::get() 1109 */ 1110 LLVMTypeRef LLVMPointerType(LLVMTypeRef ElementType, uint AddressSpace); 1111 1112 /** 1113 * Obtain the address space of a pointer type. 1114 * 1115 * This only works on types that represent pointers. 1116 * 1117 * @see llvm::PointerType::getAddressSpace() 1118 */ 1119 uint LLVMGetPointerAddressSpace(LLVMTypeRef PointerTy); 1120 1121 /** 1122 * Create a vector type that contains a defined type and has a specific 1123 * number of elements. 1124 * 1125 * The created type will exist in the context thats its element type 1126 * exists in. 1127 * 1128 * @see llvm::VectorType::get() 1129 */ 1130 LLVMTypeRef LLVMVectorType(LLVMTypeRef ElementType, uint ElementCount); 1131 1132 /** 1133 * Obtain the number of elements in a vector type. 1134 * 1135 * This only works on types that represent vectors. 1136 * 1137 * @see llvm::VectorType::getNumElements() 1138 */ 1139 uint LLVMGetVectorSize(LLVMTypeRef VectorTy); 1140 1141 /** 1142 * @} 1143 */ 1144 1145 /** 1146 * @defgroup LLVMCCoreTypeOther Other Types 1147 * 1148 * @{ 1149 */ 1150 1151 /** 1152 * Create a void type in a context. 1153 */ 1154 LLVMTypeRef LLVMVoidTypeInContext(LLVMContextRef C); 1155 1156 /** 1157 * Create a label type in a context. 1158 */ 1159 LLVMTypeRef LLVMLabelTypeInContext(LLVMContextRef C); 1160 1161 /** 1162 * Create a X86 MMX type in a context. 1163 */ 1164 LLVMTypeRef LLVMX86MMXTypeInContext(LLVMContextRef C); 1165 1166 /** 1167 * These are similar to the above functions except they operate on the 1168 * global context. 1169 */ 1170 LLVMTypeRef LLVMVoidType(); 1171 LLVMTypeRef LLVMLabelType(); 1172 LLVMTypeRef LLVMX86MMXType(); 1173 1174 /** 1175 * @} 1176 */ 1177 1178 /** 1179 * @} 1180 */ 1181 1182 /** 1183 * @defgroup LLVMCCoreValues Values 1184 * 1185 * The bulk of LLVM's object model consists of values, which comprise a very 1186 * rich type hierarchy. 1187 * 1188 * LLVMValueRef essentially represents llvm::Value. There is a rich 1189 * hierarchy of classes within this type. Depending on the instance 1190 * obtained, not all APIs are available. 1191 * 1192 * Callers can determine the type of an LLVMValueRef by calling the 1193 * LLVMIsA* family of functions (e.g. LLVMIsAArgument()). These 1194 * functions are defined by a macro, so it isn't obvious which are 1195 * available by looking at the Doxygen source code. Instead, look at the 1196 * source definition of LLVM_FOR_EACH_VALUE_SUBCLASS and note the list 1197 * of value names given. These value names also correspond to classes in 1198 * the llvm::Value hierarchy. 1199 * 1200 * @{ 1201 */ 1202 1203 extern(D) string LLVM_FOR_EACH_VALUE_SUBCLASS( 1204 string delegate(string) nothrow fun, 1205 ) { 1206 string ret; 1207 foreach (str; [ 1208 "Argument", 1209 "BasicBlock", 1210 "InlineAsm", 1211 "User", 1212 "Constant", 1213 "BlockAddress", 1214 "ConstantAggregateZero", 1215 "ConstantArray", 1216 "ConstantDataSequential", 1217 "ConstantDataArray", 1218 "ConstantDataVector", 1219 "ConstantExpr", 1220 "ConstantFP", 1221 "ConstantInt", 1222 "ConstantPointerNull", 1223 "ConstantStruct", 1224 "ConstantTokenNone", 1225 "ConstantVector", 1226 "GlobalValue", 1227 "GlobalAlias", 1228 "GlobalObject", 1229 "Function", 1230 "GlobalVariable", 1231 "UndefValue", 1232 "Instruction", 1233 "BinaryOperator", 1234 "CallInst", 1235 "IntrinsicInst", 1236 "DbgInfoIntrinsic", 1237 "DbgDeclareInst", 1238 "MemIntrinsic", 1239 "MemCpyInst", 1240 "MemMoveInst", 1241 "MemSetInst", 1242 "CmpInst", 1243 "FCmpInst", 1244 "ICmpInst", 1245 "ExtractElementInst", 1246 "GetElementPtrInst", 1247 "InsertElementInst", 1248 "InsertValueInst", 1249 "LandingPadInst", 1250 "PHINode", 1251 "SelectInst", 1252 "ShuffleVectorInst", 1253 "StoreInst", 1254 "TerminatorInst", 1255 "BranchInst", 1256 "IndirectBrInst", 1257 "InvokeInst", 1258 "ReturnInst", 1259 "SwitchInst", 1260 "UnreachableInst", 1261 "ResumeInst", 1262 "CleanupReturnInst", 1263 "CatchReturnInst", 1264 "FuncletPadInst", 1265 "CatchPadInst", 1266 "CleanupPadInst", 1267 "UnaryInstruction", 1268 "AllocaInst", 1269 "CastInst", 1270 "AddrSpaceCastInst", 1271 "BitCastInst", 1272 "FPExtInst", 1273 "FPToSIInst", 1274 "FPToUIInst", 1275 "FPTruncInst", 1276 "IntToPtrInst", 1277 "PtrToIntInst", 1278 "SExtInst", 1279 "SIToFPInst", 1280 "TruncInst", 1281 "UIToFPInst", 1282 "ZExtInst", 1283 "ExtractValueInst", 1284 "LoadInst", 1285 "VAArgInst", 1286 ]) { 1287 ret ~= fun(str) ~ "\n"; 1288 } 1289 1290 return ret; 1291 } 1292 1293 /** 1294 * @defgroup LLVMCCoreValueGeneral General APIs 1295 * 1296 * Functions in this section work on all LLVMValueRef instances, 1297 * regardless of their sub-type. They correspond to functions available 1298 * on llvm::Value. 1299 * 1300 * @{ 1301 */ 1302 1303 /** 1304 * Obtain the type of a value. 1305 * 1306 * @see llvm::Value::getType() 1307 */ 1308 LLVMTypeRef LLVMTypeOf(LLVMValueRef Val); 1309 1310 /** 1311 * Obtain the enumerated type of a Value instance. 1312 * 1313 * @see llvm::Value::getValueID() 1314 */ 1315 LLVMValueKind LLVMGetValueKind(LLVMValueRef Val); 1316 1317 /** 1318 * Obtain the string name of a value. 1319 * 1320 * @see llvm::Value::getName() 1321 */ 1322 const(char)* LLVMGetValueName(LLVMValueRef Val); 1323 1324 /** 1325 * Set the string name of a value. 1326 * 1327 * @see llvm::Value::setName() 1328 */ 1329 void LLVMSetValueName(LLVMValueRef Val, const(char)* Name); 1330 1331 /** 1332 * Dump a representation of a value to stderr. 1333 * 1334 * @see llvm::Value::dump() 1335 */ 1336 void LLVMDumpValue(LLVMValueRef Val); 1337 1338 /** 1339 * Return a string representation of the value. Use 1340 * LLVMDisposeMessage to free the string. 1341 * 1342 * @see llvm::Value::print() 1343 */ 1344 char* LLVMPrintValueToString(LLVMValueRef Val); 1345 1346 /** 1347 * Replace all uses of a value with another one. 1348 * 1349 * @see llvm::Value::replaceAllUsesWith() 1350 */ 1351 void LLVMReplaceAllUsesWith(LLVMValueRef OldVal, LLVMValueRef NewVal); 1352 1353 /** 1354 * Determine whether the specified value instance is constant. 1355 */ 1356 LLVMBool LLVMIsConstant(LLVMValueRef Val); 1357 1358 /** 1359 * Determine whether a value instance is undefined. 1360 */ 1361 LLVMBool LLVMIsUndef(LLVMValueRef Val); 1362 1363 /** 1364 * Convert value instances between types. 1365 * 1366 * Internally, an LLVMValueRef is "pinned" to a specific type. This 1367 * series of functions allows you to cast an instance to a specific 1368 * type. 1369 * 1370 * If the cast is not valid for the specified type, NULL is returned. 1371 * 1372 * @see llvm::dyn_cast_or_null<> 1373 */ 1374 extern(D) mixin(LLVM_FOR_EACH_VALUE_SUBCLASS(delegate string(string name) { 1375 return "extern(C) LLVMValueRef LLVMIsA" ~ name ~ "(LLVMValueRef Val);"; 1376 })); 1377 1378 LLVMValueRef LLVMIsAMDNode(LLVMValueRef Val); 1379 LLVMValueRef LLVMIsAMDString(LLVMValueRef Val); 1380 1381 /** 1382 * @} 1383 */ 1384 1385 /** 1386 * @defgroup LLVMCCoreValueUses Usage 1387 * 1388 * This module defines functions that allow you to inspect the uses of a 1389 * LLVMValueRef. 1390 * 1391 * It is possible to obtain an LLVMUseRef for any LLVMValueRef instance. 1392 * Each LLVMUseRef (which corresponds to a llvm::Use instance) holds a 1393 * llvm::User and llvm::Value. 1394 * 1395 * @{ 1396 */ 1397 1398 /** 1399 * Obtain the first use of a value. 1400 * 1401 * Uses are obtained in an iterator fashion. First, call this function 1402 * to obtain a reference to the first use. Then, call LLVMGetNextUse() 1403 * on that instance and all subsequently obtained instances until 1404 * LLVMGetNextUse() returns NULL. 1405 * 1406 * @see llvm::Value::use_begin() 1407 */ 1408 LLVMUseRef LLVMGetFirstUse(LLVMValueRef Val); 1409 1410 /** 1411 * Obtain the next use of a value. 1412 * 1413 * This effectively advances the iterator. It returns NULL if you are on 1414 * the final use and no more are available. 1415 */ 1416 LLVMUseRef LLVMGetNextUse(LLVMUseRef U); 1417 1418 /** 1419 * Obtain the user value for a user. 1420 * 1421 * The returned value corresponds to a llvm::User type. 1422 * 1423 * @see llvm::Use::getUser() 1424 */ 1425 LLVMValueRef LLVMGetUser(LLVMUseRef U); 1426 1427 /** 1428 * Obtain the value this use corresponds to. 1429 * 1430 * @see llvm::Use::get(). 1431 */ 1432 LLVMValueRef LLVMGetUsedValue(LLVMUseRef U); 1433 1434 /** 1435 * @} 1436 */ 1437 1438 /** 1439 * @defgroup LLVMCCoreValueUser User value 1440 * 1441 * Function in this group pertain to LLVMValueRef instances that descent 1442 * from llvm::User. This includes constants, instructions, and 1443 * operators. 1444 * 1445 * @{ 1446 */ 1447 1448 /** 1449 * Obtain an operand at a specific index in a llvm::User value. 1450 * 1451 * @see llvm::User::getOperand() 1452 */ 1453 LLVMValueRef LLVMGetOperand(LLVMValueRef Val, uint Index); 1454 1455 /** 1456 * Obtain the use of an operand at a specific index in a llvm::User value. 1457 * 1458 * @see llvm::User::getOperandUse() 1459 */ 1460 LLVMUseRef LLVMGetOperandUse(LLVMValueRef Val, uint Index); 1461 1462 /** 1463 * Set an operand at a specific index in a llvm::User value. 1464 * 1465 * @see llvm::User::setOperand() 1466 */ 1467 void LLVMSetOperand(LLVMValueRef User, uint Index, LLVMValueRef Val); 1468 1469 /** 1470 * Obtain the number of operands in a llvm::User value. 1471 * 1472 * @see llvm::User::getNumOperands() 1473 */ 1474 int LLVMGetNumOperands(LLVMValueRef Val); 1475 1476 /** 1477 * @} 1478 */ 1479 1480 /** 1481 * @defgroup LLVMCCoreValueConstant Constants 1482 * 1483 * This section contains APIs for interacting with LLVMValueRef that 1484 * correspond to llvm::Constant instances. 1485 * 1486 * These functions will work for any LLVMValueRef in the llvm::Constant 1487 * class hierarchy. 1488 * 1489 * @{ 1490 */ 1491 1492 /** 1493 * Obtain a constant value referring to the null instance of a type. 1494 * 1495 * @see llvm::Constant::getNullValue() 1496 */ 1497 LLVMValueRef LLVMConstNull(LLVMTypeRef Ty); /* all zeroes */ 1498 1499 /** 1500 * Obtain a constant value referring to the instance of a type 1501 * consisting of all ones. 1502 * 1503 * This is only valid for integer types. 1504 * 1505 * @see llvm::Constant::getAllOnesValue() 1506 */ 1507 LLVMValueRef LLVMConstAllOnes(LLVMTypeRef Ty); 1508 1509 /** 1510 * Obtain a constant value referring to an undefined value of a type. 1511 * 1512 * @see llvm::UndefValue::get() 1513 */ 1514 LLVMValueRef LLVMGetUndef(LLVMTypeRef Ty); 1515 1516 /** 1517 * Determine whether a value instance is null. 1518 * 1519 * @see llvm::Constant::isNullValue() 1520 */ 1521 LLVMBool LLVMIsNull(LLVMValueRef Val); 1522 1523 /** 1524 * Obtain a constant that is a constant pointer pointing to NULL for a 1525 * specified type. 1526 */ 1527 LLVMValueRef LLVMConstPointerNull(LLVMTypeRef Ty); 1528 1529 /** 1530 * @defgroup LLVMCCoreValueConstantScalar Scalar constants 1531 * 1532 * Functions in this group model LLVMValueRef instances that correspond 1533 * to constants referring to scalar types. 1534 * 1535 * For integer types, the LLVMTypeRef parameter should correspond to a 1536 * llvm::IntegerType instance and the returned LLVMValueRef will 1537 * correspond to a llvm::ConstantInt. 1538 * 1539 * For floating point types, the LLVMTypeRef returned corresponds to a 1540 * llvm::ConstantFP. 1541 * 1542 * @{ 1543 */ 1544 1545 /** 1546 * Obtain a constant value for an integer type. 1547 * 1548 * The returned value corresponds to a llvm::ConstantInt. 1549 * 1550 * @see llvm::ConstantInt::get() 1551 * 1552 * @param IntTy Integer type to obtain value of. 1553 * @param N The value the returned instance should refer to. 1554 * @param SignExtend Whether to sign extend the produced value. 1555 */ 1556 LLVMValueRef LLVMConstInt(LLVMTypeRef IntTy, ulong N, 1557 LLVMBool SignExtend); 1558 1559 /** 1560 * Obtain a constant value for an integer of arbitrary precision. 1561 * 1562 * @see llvm::ConstantInt::get() 1563 */ 1564 LLVMValueRef LLVMConstIntOfArbitraryPrecision(LLVMTypeRef IntTy, 1565 uint NumWords, 1566 const(ulong)* Words); 1567 1568 /** 1569 * Obtain a constant value for an integer parsed from a string. 1570 * 1571 * A similar API, LLVMConstIntOfStringAndSize is also available. If the 1572 * string's length is available, it is preferred to call that function 1573 * instead. 1574 * 1575 * @see llvm::ConstantInt::get() 1576 */ 1577 LLVMValueRef LLVMConstIntOfString(LLVMTypeRef IntTy, const(char)* Text, 1578 ubyte Radix); 1579 1580 /** 1581 * Obtain a constant value for an integer parsed from a string with 1582 * specified length. 1583 * 1584 * @see llvm::ConstantInt::get() 1585 */ 1586 LLVMValueRef LLVMConstIntOfStringAndSize(LLVMTypeRef IntTy, const(char)* Text, 1587 uint SLen, ubyte Radix); 1588 1589 /** 1590 * Obtain a constant value referring to a double floating point value. 1591 */ 1592 LLVMValueRef LLVMConstReal(LLVMTypeRef RealTy, double N); 1593 1594 /** 1595 * Obtain a constant for a floating point value parsed from a string. 1596 * 1597 * A similar API, LLVMConstRealOfStringAndSize is also available. It 1598 * should be used if the input string's length is known. 1599 */ 1600 LLVMValueRef LLVMConstRealOfString(LLVMTypeRef RealTy, const(char)* Text); 1601 1602 /** 1603 * Obtain a constant for a floating point value parsed from a string. 1604 */ 1605 LLVMValueRef LLVMConstRealOfStringAndSize(LLVMTypeRef RealTy, const(char)* Text, 1606 uint SLen); 1607 1608 /** 1609 * Obtain the zero extended value for an integer constant value. 1610 * 1611 * @see llvm::ConstantInt::getZExtValue() 1612 */ 1613 ulong LLVMConstIntGetZExtValue(LLVMValueRef ConstantVal); 1614 1615 /** 1616 * Obtain the sign extended value for an integer constant value. 1617 * 1618 * @see llvm::ConstantInt::getSExtValue() 1619 */ 1620 long LLVMConstIntGetSExtValue(LLVMValueRef ConstantVal); 1621 1622 /** 1623 * Obtain the double value for an floating point constant value. 1624 * losesInfo indicates if some precision was lost in the conversion. 1625 * 1626 * @see llvm::ConstantFP::getDoubleValue 1627 */ 1628 double LLVMConstRealGetDouble(LLVMValueRef ConstantVal, LLVMBool *losesInfo); 1629 1630 /** 1631 * @} 1632 */ 1633 1634 /** 1635 * @defgroup LLVMCCoreValueConstantComposite Composite Constants 1636 * 1637 * Functions in this group operate on composite constants. 1638 * 1639 * @{ 1640 */ 1641 1642 /** 1643 * Create a ConstantDataSequential and initialize it with a string. 1644 * 1645 * @see llvm::ConstantDataArray::getString() 1646 */ 1647 LLVMValueRef LLVMConstStringInContext(LLVMContextRef C, const(char)* Str, 1648 uint Length, LLVMBool DontNullTerminate); 1649 1650 /** 1651 * Create a ConstantDataSequential with string content in the global context. 1652 * 1653 * This is the same as LLVMConstStringInContext except it operates on the 1654 * global context. 1655 * 1656 * @see LLVMConstStringInContext() 1657 * @see llvm::ConstantDataArray::getString() 1658 */ 1659 LLVMValueRef LLVMConstString(const(char)* Str, uint Length, 1660 LLVMBool DontNullTerminate); 1661 1662 /** 1663 * Returns true if the specified constant is an array of i8. 1664 * 1665 * @see ConstantDataSequential::getAsString() 1666 */ 1667 LLVMBool LLVMIsConstantString(LLVMValueRef c); 1668 1669 /** 1670 * Get the given constant data sequential as a string. 1671 * 1672 * @see ConstantDataSequential::getAsString() 1673 */ 1674 const(char)* LLVMGetAsString(LLVMValueRef c, size_t* Length); 1675 1676 /** 1677 * Create an anonymous ConstantStruct with the specified values. 1678 * 1679 * @see llvm::ConstantStruct::getAnon() 1680 */ 1681 LLVMValueRef LLVMConstStructInContext(LLVMContextRef C, 1682 LLVMValueRef* ConstantVals, 1683 uint Count, LLVMBool Packed); 1684 1685 /** 1686 * Create a ConstantStruct in the global Context. 1687 * 1688 * This is the same as LLVMConstStructInContext except it operates on the 1689 * global Context. 1690 * 1691 * @see LLVMConstStructInContext() 1692 */ 1693 LLVMValueRef LLVMConstStruct(LLVMValueRef* ConstantVals, uint Count, 1694 LLVMBool Packed); 1695 1696 /** 1697 * Create a ConstantArray from values. 1698 * 1699 * @see llvm::ConstantArray::get() 1700 */ 1701 LLVMValueRef LLVMConstArray(LLVMTypeRef ElementTy, 1702 LLVMValueRef* ConstantVals, uint Length); 1703 1704 /** 1705 * Create a non-anonymous ConstantStruct from values. 1706 * 1707 * @see llvm::ConstantStruct::get() 1708 */ 1709 LLVMValueRef LLVMConstNamedStruct(LLVMTypeRef StructTy, 1710 LLVMValueRef *ConstantVals, 1711 uint Count); 1712 1713 /** 1714 * Get an element at specified index as a constant. 1715 * 1716 * @see ConstantDataSequential::getElementAsConstant() 1717 */ 1718 LLVMValueRef LLVMGetElementAsConstant(LLVMValueRef C, uint idx); 1719 1720 /** 1721 * Create a ConstantVector from values. 1722 * 1723 * @see llvm::ConstantVector::get() 1724 */ 1725 LLVMValueRef LLVMConstVector(LLVMValueRef *ScalarConstantVals, uint Size); 1726 1727 /** 1728 * @} 1729 */ 1730 1731 /** 1732 * @defgroup LLVMCCoreValueConstantExpressions Constant Expressions 1733 * 1734 * Functions in this group correspond to APIs on llvm::ConstantExpr. 1735 * 1736 * @see llvm::ConstantExpr. 1737 * 1738 * @{ 1739 */ 1740 LLVMOpcode LLVMGetConstOpcode(LLVMValueRef ConstantVal); 1741 LLVMValueRef LLVMAlignOf(LLVMTypeRef Ty); 1742 LLVMValueRef LLVMSizeOf(LLVMTypeRef Ty); 1743 LLVMValueRef LLVMConstNeg(LLVMValueRef ConstantVal); 1744 LLVMValueRef LLVMConstNSWNeg(LLVMValueRef ConstantVal); 1745 LLVMValueRef LLVMConstNUWNeg(LLVMValueRef ConstantVal); 1746 LLVMValueRef LLVMConstFNeg(LLVMValueRef ConstantVal); 1747 LLVMValueRef LLVMConstNot(LLVMValueRef ConstantVal); 1748 LLVMValueRef LLVMConstAdd(LLVMValueRef LHSConstant, LLVMValueRef RHSConstant); 1749 LLVMValueRef LLVMConstNSWAdd(LLVMValueRef LHSConstant, LLVMValueRef RHSConstant); 1750 LLVMValueRef LLVMConstNUWAdd(LLVMValueRef LHSConstant, LLVMValueRef RHSConstant); 1751 LLVMValueRef LLVMConstFAdd(LLVMValueRef LHSConstant, LLVMValueRef RHSConstant); 1752 LLVMValueRef LLVMConstSub(LLVMValueRef LHSConstant, LLVMValueRef RHSConstant); 1753 LLVMValueRef LLVMConstNSWSub(LLVMValueRef LHSConstant, LLVMValueRef RHSConstant); 1754 LLVMValueRef LLVMConstNUWSub(LLVMValueRef LHSConstant, LLVMValueRef RHSConstant); 1755 LLVMValueRef LLVMConstFSub(LLVMValueRef LHSConstant, LLVMValueRef RHSConstant); 1756 LLVMValueRef LLVMConstMul(LLVMValueRef LHSConstant, LLVMValueRef RHSConstant); 1757 LLVMValueRef LLVMConstNSWMul(LLVMValueRef LHSConstant, LLVMValueRef RHSConstant); 1758 LLVMValueRef LLVMConstNUWMul(LLVMValueRef LHSConstant, LLVMValueRef RHSConstant); 1759 LLVMValueRef LLVMConstFMul(LLVMValueRef LHSConstant, LLVMValueRef RHSConstant); 1760 LLVMValueRef LLVMConstUDiv(LLVMValueRef LHSConstant, LLVMValueRef RHSConstant); 1761 LLVMValueRef LLVMConstSDiv(LLVMValueRef LHSConstant, LLVMValueRef RHSConstant); 1762 LLVMValueRef LLVMConstExactSDiv(LLVMValueRef LHSConstant, LLVMValueRef RHSConstant); 1763 LLVMValueRef LLVMConstFDiv(LLVMValueRef LHSConstant, LLVMValueRef RHSConstant); 1764 LLVMValueRef LLVMConstURem(LLVMValueRef LHSConstant, LLVMValueRef RHSConstant); 1765 LLVMValueRef LLVMConstSRem(LLVMValueRef LHSConstant, LLVMValueRef RHSConstant); 1766 LLVMValueRef LLVMConstFRem(LLVMValueRef LHSConstant, LLVMValueRef RHSConstant); 1767 LLVMValueRef LLVMConstAnd(LLVMValueRef LHSConstant, LLVMValueRef RHSConstant); 1768 LLVMValueRef LLVMConstOr(LLVMValueRef LHSConstant, LLVMValueRef RHSConstant); 1769 LLVMValueRef LLVMConstXor(LLVMValueRef LHSConstant, LLVMValueRef RHSConstant); 1770 LLVMValueRef LLVMConstICmp(LLVMIntPredicate Predicate, 1771 LLVMValueRef LHSConstant, LLVMValueRef RHSConstant); 1772 LLVMValueRef LLVMConstFCmp(LLVMRealPredicate Predicate, 1773 LLVMValueRef LHSConstant, LLVMValueRef RHSConstant); 1774 LLVMValueRef LLVMConstShl(LLVMValueRef LHSConstant, LLVMValueRef RHSConstant); 1775 LLVMValueRef LLVMConstLShr(LLVMValueRef LHSConstant, LLVMValueRef RHSConstant); 1776 LLVMValueRef LLVMConstAShr(LLVMValueRef LHSConstant, LLVMValueRef RHSConstant); 1777 LLVMValueRef LLVMConstGEP(LLVMValueRef ConstantVal, 1778 LLVMValueRef* ConstantIndices, uint NumIndices); 1779 LLVMValueRef LLVMConstInBoundsGEP(LLVMValueRef ConstantVal, 1780 LLVMValueRef *ConstantIndices, 1781 uint NumIndices); 1782 LLVMValueRef LLVMConstTrunc(LLVMValueRef ConstantVal, LLVMTypeRef ToType); 1783 LLVMValueRef LLVMConstSExt(LLVMValueRef ConstantVal, LLVMTypeRef ToType); 1784 LLVMValueRef LLVMConstZExt(LLVMValueRef ConstantVal, LLVMTypeRef ToType); 1785 LLVMValueRef LLVMConstFPTrunc(LLVMValueRef ConstantVal, LLVMTypeRef ToType); 1786 LLVMValueRef LLVMConstFPExt(LLVMValueRef ConstantVal, LLVMTypeRef ToType); 1787 LLVMValueRef LLVMConstUIToFP(LLVMValueRef ConstantVal, LLVMTypeRef ToType); 1788 LLVMValueRef LLVMConstSIToFP(LLVMValueRef ConstantVal, LLVMTypeRef ToType); 1789 LLVMValueRef LLVMConstFPToUI(LLVMValueRef ConstantVal, LLVMTypeRef ToType); 1790 LLVMValueRef LLVMConstFPToSI(LLVMValueRef ConstantVal, LLVMTypeRef ToType); 1791 LLVMValueRef LLVMConstPtrToInt(LLVMValueRef ConstantVal, LLVMTypeRef ToType); 1792 LLVMValueRef LLVMConstIntToPtr(LLVMValueRef ConstantVal, LLVMTypeRef ToType); 1793 LLVMValueRef LLVMConstBitCast(LLVMValueRef ConstantVal, LLVMTypeRef ToType); 1794 LLVMValueRef LLVMConstAddrSpaceCast(LLVMValueRef ConstantVal, LLVMTypeRef ToType); 1795 LLVMValueRef LLVMConstZExtOrBitCast(LLVMValueRef ConstantVal, 1796 LLVMTypeRef ToType); 1797 LLVMValueRef LLVMConstSExtOrBitCast(LLVMValueRef ConstantVal, 1798 LLVMTypeRef ToType); 1799 LLVMValueRef LLVMConstTruncOrBitCast(LLVMValueRef ConstantVal, 1800 LLVMTypeRef ToType); 1801 LLVMValueRef LLVMConstPointerCast(LLVMValueRef ConstantVal, 1802 LLVMTypeRef ToType); 1803 LLVMValueRef LLVMConstIntCast(LLVMValueRef ConstantVal, LLVMTypeRef ToType, 1804 LLVMBool isSigned); 1805 LLVMValueRef LLVMConstFPCast(LLVMValueRef ConstantVal, LLVMTypeRef ToType); 1806 LLVMValueRef LLVMConstSelect(LLVMValueRef ConstantCondition, 1807 LLVMValueRef ConstantIfTrue, 1808 LLVMValueRef ConstantIfFalse); 1809 LLVMValueRef LLVMConstExtractElement(LLVMValueRef VectorConstant, 1810 LLVMValueRef IndexConstant); 1811 LLVMValueRef LLVMConstInsertElement(LLVMValueRef VectorConstant, 1812 LLVMValueRef ElementValueConstant, 1813 LLVMValueRef IndexConstant); 1814 LLVMValueRef LLVMConstShuffleVector(LLVMValueRef VectorAConstant, 1815 LLVMValueRef VectorBConstant, 1816 LLVMValueRef MaskConstant); 1817 LLVMValueRef LLVMConstExtractValue(LLVMValueRef AggConstant, uint* IdxList, 1818 uint NumIdx); 1819 LLVMValueRef LLVMConstInsertValue(LLVMValueRef AggConstant, 1820 LLVMValueRef ElementValueConstant, 1821 uint* IdxList, uint NumIdx); 1822 LLVMValueRef LLVMConstInlineAsm(LLVMTypeRef Ty, 1823 const(char)* AsmString, const(char)* Constraints, 1824 LLVMBool HasSideEffects, LLVMBool IsAlignStack); 1825 LLVMValueRef LLVMBlockAddress(LLVMValueRef F, LLVMBasicBlockRef BB); 1826 1827 /** 1828 * @} 1829 */ 1830 1831 /** 1832 * @defgroup LLVMCCoreValueConstantGlobals Global Values 1833 * 1834 * This group contains functions that operate on global values. Functions in 1835 * this group relate to functions in the llvm::GlobalValue class tree. 1836 * 1837 * @see llvm::GlobalValue 1838 * 1839 * @{ 1840 */ 1841 1842 LLVMModuleRef LLVMGetGlobalParent(LLVMValueRef Global); 1843 LLVMBool LLVMIsDeclaration(LLVMValueRef Global); 1844 LLVMLinkage LLVMGetLinkage(LLVMValueRef Global); 1845 void LLVMSetLinkage(LLVMValueRef Global, LLVMLinkage Linkage); 1846 const(char)* LLVMGetSection(LLVMValueRef Global); 1847 void LLVMSetSection(LLVMValueRef Global, const(char)* Section); 1848 LLVMVisibility LLVMGetVisibility(LLVMValueRef Global); 1849 void LLVMSetVisibility(LLVMValueRef Global, LLVMVisibility Viz); 1850 LLVMDLLStorageClass LLVMGetDLLStorageClass(LLVMValueRef Global); 1851 void LLVMSetDLLStorageClass(LLVMValueRef Global, LLVMDLLStorageClass Class); 1852 LLVMBool LLVMHasUnnamedAddr(LLVMValueRef Global); 1853 void LLVMSetUnnamedAddr(LLVMValueRef Global, LLVMBool HasUnnamedAddr); 1854 1855 /** 1856 * @defgroup LLVMCCoreValueWithAlignment Values with alignment 1857 * 1858 * Functions in this group only apply to values with alignment, i.e. 1859 * global variables, load and store instructions. 1860 */ 1861 1862 /** 1863 * Obtain the preferred alignment of the value. 1864 * @see llvm::AllocaInst::getAlignment() 1865 * @see llvm::LoadInst::getAlignment() 1866 * @see llvm::StoreInst::getAlignment() 1867 * @see llvm::GlobalValue::getAlignment() 1868 */ 1869 uint LLVMGetAlignment(LLVMValueRef V); 1870 1871 /** 1872 * Set the preferred alignment of the value. 1873 * @see llvm::AllocaInst::setAlignment() 1874 * @see llvm::LoadInst::setAlignment() 1875 * @see llvm::StoreInst::setAlignment() 1876 * @see llvm::GlobalValue::setAlignment() 1877 */ 1878 void LLVMSetAlignment(LLVMValueRef V, uint Bytes); 1879 1880 /** 1881 * @} 1882 */ 1883 1884 /** 1885 * @defgroup LLVMCoreValueConstantGlobalVariable Global Variables 1886 * 1887 * This group contains functions that operate on global variable values. 1888 * 1889 * @see llvm::GlobalVariable 1890 * 1891 * @{ 1892 */ 1893 LLVMValueRef LLVMAddGlobal(LLVMModuleRef M, LLVMTypeRef Ty, const(char)* Name); 1894 LLVMValueRef LLVMAddGlobalInAddressSpace(LLVMModuleRef M, LLVMTypeRef Ty, 1895 const(char)* Name, 1896 uint AddressSpace); 1897 LLVMValueRef LLVMGetNamedGlobal(LLVMModuleRef M, const(char)* Name); 1898 LLVMValueRef LLVMGetFirstGlobal(LLVMModuleRef M); 1899 LLVMValueRef LLVMGetLastGlobal(LLVMModuleRef M); 1900 LLVMValueRef LLVMGetNextGlobal(LLVMValueRef GlobalVar); 1901 LLVMValueRef LLVMGetPreviousGlobal(LLVMValueRef GlobalVar); 1902 void LLVMDeleteGlobal(LLVMValueRef GlobalVar); 1903 LLVMValueRef LLVMGetInitializer(LLVMValueRef GlobalVar); 1904 void LLVMSetInitializer(LLVMValueRef GlobalVar, LLVMValueRef ConstantVal); 1905 LLVMBool LLVMIsThreadLocal(LLVMValueRef GlobalVar); 1906 void LLVMSetThreadLocal(LLVMValueRef GlobalVar, LLVMBool IsThreadLocal); 1907 LLVMBool LLVMIsGlobalConstant(LLVMValueRef GlobalVar); 1908 void LLVMSetGlobalConstant(LLVMValueRef GlobalVar, LLVMBool IsConstant); 1909 LLVMThreadLocalMode LLVMGetThreadLocalMode(LLVMValueRef GlobalVar); 1910 void LLVMSetThreadLocalMode(LLVMValueRef GlobalVar, LLVMThreadLocalMode Mode); 1911 LLVMBool LLVMIsExternallyInitialized(LLVMValueRef GlobalVar); 1912 void LLVMSetExternallyInitialized(LLVMValueRef GlobalVar, LLVMBool IsExtInit); 1913 1914 /** 1915 * @} 1916 */ 1917 1918 /** 1919 * @defgroup LLVMCoreValueConstantGlobalAlias Global Aliases 1920 * 1921 * This group contains function that operate on global alias values. 1922 * 1923 * @see llvm::GlobalAlias 1924 * 1925 * @{ 1926 */ 1927 LLVMValueRef LLVMAddAlias(LLVMModuleRef M, LLVMTypeRef Ty, LLVMValueRef Aliasee, 1928 const(char)* Name); 1929 1930 /** 1931 * @} 1932 */ 1933 1934 /** 1935 * @defgroup LLVMCCoreValueFunction Function values 1936 * 1937 * Functions in this group operate on LLVMValueRef instances that 1938 * correspond to llvm::Function instances. 1939 * 1940 * @see llvm::Function 1941 * 1942 * @{ 1943 */ 1944 1945 /** 1946 * Remove a function from its containing module and deletes it. 1947 * 1948 * @see llvm::Function::eraseFromParent() 1949 */ 1950 void LLVMDeleteFunction(LLVMValueRef Fn); 1951 1952 /** 1953 * Check whether the given function has a personality function. 1954 * 1955 * @see llvm::Function::hasPersonalityFn() 1956 */ 1957 LLVMBool LLVMHasPersonalityFn(LLVMValueRef Fn); 1958 1959 /** 1960 * Obtain the personality function attached to the function. 1961 * 1962 * @see llvm::Function::getPersonalityFn() 1963 */ 1964 LLVMValueRef LLVMGetPersonalityFn(LLVMValueRef Fn); 1965 1966 /** 1967 * Set the personality function attached to the function. 1968 * 1969 * @see llvm::Function::setPersonalityFn() 1970 */ 1971 void LLVMSetPersonalityFn(LLVMValueRef Fn, LLVMValueRef PersonalityFn); 1972 1973 /** 1974 * Obtain the ID number from a function instance. 1975 * 1976 * @see llvm::Function::getIntrinsicID() 1977 */ 1978 uint LLVMGetIntrinsicID(LLVMValueRef Fn); 1979 1980 /** 1981 * Obtain the calling function of a function. 1982 * 1983 * The returned value corresponds to the LLVMCallConv enumeration. 1984 * 1985 * @see llvm::Function::getCallingConv() 1986 */ 1987 uint LLVMGetFunctionCallConv(LLVMValueRef Fn); 1988 1989 /** 1990 * Set the calling convention of a function. 1991 * 1992 * @see llvm::Function::setCallingConv() 1993 * 1994 * @param Fn Function to operate on 1995 * @param CC LLVMCallConv to set calling convention to 1996 */ 1997 void LLVMSetFunctionCallConv(LLVMValueRef Fn, uint CC); 1998 1999 /** 2000 * Obtain the name of the garbage collector to use during code 2001 * generation. 2002 * 2003 * @see llvm::Function::getGC() 2004 */ 2005 const(char)* LLVMGetGC(LLVMValueRef Fn); 2006 2007 /** 2008 * Define the garbage collector to use during code generation. 2009 * 2010 * @see llvm::Function::setGC() 2011 */ 2012 void LLVMSetGC(LLVMValueRef Fn, const(char)* Name); 2013 2014 /** 2015 * Add an attribute to a function. 2016 * 2017 * @see llvm::Function::addAttribute() 2018 */ 2019 void LLVMAddFunctionAttr(LLVMValueRef Fn, LLVMAttribute PA); 2020 2021 void LLVMAddAttributeAtIndex(LLVMValueRef F, LLVMAttributeIndex Idx, 2022 LLVMAttributeRef A); 2023 uint LLVMGetAttributeCountAtIndex(LLVMValueRef F, LLVMAttributeIndex Idx); 2024 void LLVMGetAttributesAtIndex(LLVMValueRef F, LLVMAttributeIndex Idx, 2025 LLVMAttributeRef* Attrs); 2026 LLVMAttributeRef LLVMGetEnumAttributeAtIndex(LLVMValueRef F, 2027 LLVMAttributeIndex Idx, 2028 uint KindID); 2029 LLVMAttributeRef LLVMGetStringAttributeAtIndex(LLVMValueRef F, 2030 LLVMAttributeIndex Idx, 2031 const(char)* K, uint KLen); 2032 void LLVMRemoveEnumAttributeAtIndex(LLVMValueRef F, LLVMAttributeIndex Idx, 2033 uint KindID); 2034 void LLVMRemoveStringAttributeAtIndex(LLVMValueRef F, LLVMAttributeIndex Idx, 2035 const(char)* K, uint KLen); 2036 2037 /** 2038 * Add a target-dependent attribute to a function 2039 * @see llvm::AttrBuilder::addAttribute() 2040 */ 2041 void LLVMAddTargetDependentFunctionAttr(LLVMValueRef Fn, const char *A, 2042 const char *V); 2043 2044 /** 2045 * Obtain an attribute from a function. 2046 * 2047 * @see llvm::Function::getAttributes() 2048 */ 2049 LLVMAttribute LLVMGetFunctionAttr(LLVMValueRef Fn); 2050 2051 /** 2052 * Remove an attribute from a function. 2053 */ 2054 void LLVMRemoveFunctionAttr(LLVMValueRef Fn, LLVMAttribute PA); 2055 2056 /** 2057 * @defgroup LLVMCCoreValueFunctionParameters Function Parameters 2058 * 2059 * Functions in this group relate to arguments/parameters on functions. 2060 * 2061 * Functions in this group expect LLVMValueRef instances that correspond 2062 * to llvm::Function instances. 2063 * 2064 * @{ 2065 */ 2066 2067 /** 2068 * Obtain the number of parameters in a function. 2069 * 2070 * @see llvm::Function::arg_size() 2071 */ 2072 uint LLVMCountParams(LLVMValueRef Fn); 2073 2074 /** 2075 * Obtain the parameters in a function. 2076 * 2077 * The takes a pointer to a pre-allocated array of LLVMValueRef that is 2078 * at least LLVMCountParams() long. This array will be filled with 2079 * LLVMValueRef instances which correspond to the parameters the 2080 * function receives. Each LLVMValueRef corresponds to a llvm::Argument 2081 * instance. 2082 * 2083 * @see llvm::Function::arg_begin() 2084 */ 2085 void LLVMGetParams(LLVMValueRef Fn, LLVMValueRef *Params); 2086 2087 /** 2088 * Obtain the parameter at the specified index. 2089 * 2090 * Parameters are indexed from 0. 2091 * 2092 * @see llvm::Function::arg_begin() 2093 */ 2094 LLVMValueRef LLVMGetParam(LLVMValueRef Fn, uint Index); 2095 2096 /** 2097 * Obtain the function to which this argument belongs. 2098 * 2099 * Unlike other functions in this group, this one takes an LLVMValueRef 2100 * that corresponds to a llvm::Attribute. 2101 * 2102 * The returned LLVMValueRef is the llvm::Function to which this 2103 * argument belongs. 2104 */ 2105 LLVMValueRef LLVMGetParamParent(LLVMValueRef Inst); 2106 2107 /** 2108 * Obtain the first parameter to a function. 2109 * 2110 * @see llvm::Function::arg_begin() 2111 */ 2112 LLVMValueRef LLVMGetFirstParam(LLVMValueRef Fn); 2113 2114 /** 2115 * Obtain the last parameter to a function. 2116 * 2117 * @see llvm::Function::arg_end() 2118 */ 2119 LLVMValueRef LLVMGetLastParam(LLVMValueRef Fn); 2120 2121 /** 2122 * Obtain the next parameter to a function. 2123 * 2124 * This takes an LLVMValueRef obtained from LLVMGetFirstParam() (which is 2125 * actually a wrapped iterator) and obtains the next parameter from the 2126 * underlying iterator. 2127 */ 2128 LLVMValueRef LLVMGetNextParam(LLVMValueRef Arg); 2129 2130 /** 2131 * Obtain the previous parameter to a function. 2132 * 2133 * This is the opposite of LLVMGetNextParam(). 2134 */ 2135 LLVMValueRef LLVMGetPreviousParam(LLVMValueRef Arg); 2136 2137 /** 2138 * Add an attribute to a function argument. 2139 * 2140 * @see llvm::Argument::addAttr() 2141 */ 2142 void LLVMAddAttribute(LLVMValueRef Arg, LLVMAttribute PA); 2143 2144 /** 2145 * Remove an attribute from a function argument. 2146 * 2147 * @see llvm::Argument::removeAttr() 2148 */ 2149 void LLVMRemoveAttribute(LLVMValueRef Arg, LLVMAttribute PA); 2150 2151 /** 2152 * Get an attribute from a function argument. 2153 */ 2154 LLVMAttribute LLVMGetAttribute(LLVMValueRef Arg); 2155 2156 /** 2157 * Set the alignment for a function parameter. 2158 * 2159 * @see llvm::Argument::addAttr() 2160 * @see llvm::AttrBuilder::addAlignmentAttr() 2161 */ 2162 void LLVMSetParamAlignment(LLVMValueRef Arg, uint Align); 2163 2164 /** 2165 * @} 2166 */ 2167 2168 /** 2169 * @} 2170 */ 2171 2172 /** 2173 * @} 2174 */ 2175 2176 /** 2177 * @} 2178 */ 2179 2180 /** 2181 * @defgroup LLVMCCoreValueMetadata Metadata 2182 * 2183 * @{ 2184 */ 2185 2186 /** 2187 * Obtain a MDString value from a context. 2188 * 2189 * The returned instance corresponds to the llvm::MDString class. 2190 * 2191 * The instance is specified by string data of a specified length. The 2192 * string content is copied, so the backing memory can be freed after 2193 * this function returns. 2194 */ 2195 LLVMValueRef LLVMMDStringInContext(LLVMContextRef C, const(char)* Str, 2196 uint SLen); 2197 2198 /** 2199 * Obtain a MDString value from the global context. 2200 */ 2201 LLVMValueRef LLVMMDString(const(char)* Str, uint SLen); 2202 2203 /** 2204 * Obtain a MDNode value from a context. 2205 * 2206 * The returned value corresponds to the llvm::MDNode class. 2207 */ 2208 LLVMValueRef LLVMMDNodeInContext(LLVMContextRef C, LLVMValueRef* Vals, 2209 uint Count); 2210 2211 /** 2212 * Obtain a MDNode value from the global context. 2213 */ 2214 LLVMValueRef LLVMMDNode(LLVMValueRef* Vals, uint Count); 2215 2216 /** 2217 * Obtain the underlying string from a MDString value. 2218 * 2219 * @param V Instance to obtain string from. 2220 * @param Length Memory address which will hold length of returned string. 2221 * @return String data in MDString. 2222 */ 2223 const(char)* LLVMGetMDString(LLVMValueRef V, uint* Length); 2224 2225 /** 2226 * Obtain the number of operands from an MDNode value. 2227 * 2228 * @param V MDNode to get number of operands from. 2229 * @return Number of operands of the MDNode. 2230 */ 2231 uint LLVMGetMDNodeNumOperands(LLVMValueRef V); 2232 2233 /** 2234 * Obtain the given MDNode's operands. 2235 * 2236 * The passed LLVMValueRef pointer should point to enough memory to hold all of 2237 * the operands of the given MDNode (see LLVMGetMDNodeNumOperands) as 2238 * LLVMValueRefs. This memory will be populated with the LLVMValueRefs of the 2239 * MDNode's operands. 2240 * 2241 * @param V MDNode to get the operands from. 2242 * @param Dest Destination array for operands. 2243 */ 2244 void LLVMGetMDNodeOperands(LLVMValueRef V, LLVMValueRef *Dest); 2245 2246 /** 2247 * @} 2248 */ 2249 2250 /** 2251 * @defgroup LLVMCCoreValueBasicBlock Basic Block 2252 * 2253 * A basic block represents a single entry single exit section of code. 2254 * Basic blocks contain a list of instructions which form the body of 2255 * the block. 2256 * 2257 * Basic blocks belong to functions. They have the type of label. 2258 * 2259 * Basic blocks are themselves values. However, the C API models them as 2260 * LLVMBasicBlockRef. 2261 * 2262 * @see llvm::BasicBlock 2263 * 2264 * @{ 2265 */ 2266 2267 /** 2268 * Convert a basic block instance to a value type. 2269 */ 2270 LLVMValueRef LLVMBasicBlockAsValue(LLVMBasicBlockRef BB); 2271 2272 /** 2273 * Determine whether an LLVMValueRef is itself a basic block. 2274 */ 2275 LLVMBool LLVMValueIsBasicBlock(LLVMValueRef Val); 2276 2277 /** 2278 * Convert an LLVMValueRef to an LLVMBasicBlockRef instance. 2279 */ 2280 LLVMBasicBlockRef LLVMValueAsBasicBlock(LLVMValueRef Val); 2281 2282 /** 2283 * Obtain the string name of a basic block. 2284 */ 2285 const(char)* LLVMGetBasicBlockName(LLVMBasicBlockRef BB); 2286 2287 /** 2288 * Obtain the function to which a basic block belongs. 2289 * 2290 * @see llvm::BasicBlock::getParent() 2291 */ 2292 LLVMValueRef LLVMGetBasicBlockParent(LLVMBasicBlockRef BB); 2293 2294 /** 2295 * Obtain the terminator instruction for a basic block. 2296 * 2297 * If the basic block does not have a terminator (it is not well-formed 2298 * if it doesn't), then NULL is returned. 2299 * 2300 * The returned LLVMValueRef corresponds to a llvm::TerminatorInst. 2301 * 2302 * @see llvm::BasicBlock::getTerminator() 2303 */ 2304 LLVMValueRef LLVMGetBasicBlockTerminator(LLVMBasicBlockRef BB); 2305 2306 /** 2307 * Obtain the number of basic blocks in a function. 2308 * 2309 * @param Fn Function value to operate on. 2310 */ 2311 uint LLVMCountBasicBlocks(LLVMValueRef Fn); 2312 2313 /** 2314 * Obtain all of the basic blocks in a function. 2315 * 2316 * This operates on a function value. The BasicBlocks parameter is a 2317 * pointer to a pre-allocated array of LLVMBasicBlockRef of at least 2318 * LLVMCountBasicBlocks() in length. This array is populated with 2319 * LLVMBasicBlockRef instances. 2320 */ 2321 void LLVMGetBasicBlocks(LLVMValueRef Fn, LLVMBasicBlockRef *BasicBlocks); 2322 2323 /** 2324 * Obtain the first basic block in a function. 2325 * 2326 * The returned basic block can be used as an iterator. You will likely 2327 * eventually call into LLVMGetNextBasicBlock() with it. 2328 * 2329 * @see llvm::Function::begin() 2330 */ 2331 LLVMBasicBlockRef LLVMGetFirstBasicBlock(LLVMValueRef Fn); 2332 2333 /** 2334 * Obtain the last basic block in a function. 2335 * 2336 * @see llvm::Function::end() 2337 */ 2338 LLVMBasicBlockRef LLVMGetLastBasicBlock(LLVMValueRef Fn); 2339 2340 /** 2341 * Advance a basic block iterator. 2342 */ 2343 LLVMBasicBlockRef LLVMGetNextBasicBlock(LLVMBasicBlockRef BB); 2344 2345 /** 2346 * Go backwards in a basic block iterator. 2347 */ 2348 LLVMBasicBlockRef LLVMGetPreviousBasicBlock(LLVMBasicBlockRef BB); 2349 2350 /** 2351 * Obtain the basic block that corresponds to the entry point of a 2352 * function. 2353 * 2354 * @see llvm::Function::getEntryBlock() 2355 */ 2356 LLVMBasicBlockRef LLVMGetEntryBasicBlock(LLVMValueRef Fn); 2357 2358 /** 2359 * Append a basic block to the end of a function. 2360 * 2361 * @see llvm::BasicBlock::Create() 2362 */ 2363 LLVMBasicBlockRef LLVMAppendBasicBlockInContext(LLVMContextRef C, 2364 LLVMValueRef Fn, 2365 const(char)* Name); 2366 2367 /** 2368 * Append a basic block to the end of a function using the global 2369 * context. 2370 * 2371 * @see llvm::BasicBlock::Create() 2372 */ 2373 LLVMBasicBlockRef LLVMAppendBasicBlock(LLVMValueRef Fn, const(char)* Name); 2374 2375 /** 2376 * Insert a basic block in a function before another basic block. 2377 * 2378 * The function to add to is determined by the function of the 2379 * passed basic block. 2380 * 2381 * @see llvm::BasicBlock::Create() 2382 */ 2383 LLVMBasicBlockRef LLVMInsertBasicBlockInContext(LLVMContextRef C, 2384 LLVMBasicBlockRef BB, 2385 const(char)* Name); 2386 2387 /** 2388 * Insert a basic block in a function using the global context. 2389 * 2390 * @see llvm::BasicBlock::Create() 2391 */ 2392 LLVMBasicBlockRef LLVMInsertBasicBlock(LLVMBasicBlockRef InsertBeforeBB, 2393 const(char)* Name); 2394 2395 /** 2396 * Remove a basic block from a function and delete it. 2397 * 2398 * This deletes the basic block from its containing function and deletes 2399 * the basic block itself. 2400 * 2401 * @see llvm::BasicBlock::eraseFromParent() 2402 */ 2403 void LLVMDeleteBasicBlock(LLVMBasicBlockRef BB); 2404 2405 /** 2406 * Remove a basic block from a function. 2407 * 2408 * This deletes the basic block from its containing function but keep 2409 * the basic block alive. 2410 * 2411 * @see llvm::BasicBlock::removeFromParent() 2412 */ 2413 void LLVMRemoveBasicBlockFromParent(LLVMBasicBlockRef BB); 2414 2415 /** 2416 * Move a basic block to before another one. 2417 * 2418 * @see llvm::BasicBlock::moveBefore() 2419 */ 2420 void LLVMMoveBasicBlockBefore(LLVMBasicBlockRef BB, LLVMBasicBlockRef MovePos); 2421 2422 /** 2423 * Move a basic block to after another one. 2424 * 2425 * @see llvm::BasicBlock::moveAfter() 2426 */ 2427 void LLVMMoveBasicBlockAfter(LLVMBasicBlockRef BB, LLVMBasicBlockRef MovePos); 2428 2429 /** 2430 * Obtain the first instruction in a basic block. 2431 * 2432 * The returned LLVMValueRef corresponds to a llvm::Instruction 2433 * instance. 2434 */ 2435 LLVMValueRef LLVMGetFirstInstruction(LLVMBasicBlockRef BB); 2436 2437 /** 2438 * Obtain the last instruction in a basic block. 2439 * 2440 * The returned LLVMValueRef corresponds to an LLVM:Instruction. 2441 */ 2442 LLVMValueRef LLVMGetLastInstruction(LLVMBasicBlockRef BB); 2443 2444 /** 2445 * @} 2446 */ 2447 2448 /** 2449 * @defgroup LLVMCCoreValueInstruction Instructions 2450 * 2451 * Functions in this group relate to the inspection and manipulation of 2452 * individual instructions. 2453 * 2454 * In the C++ API, an instruction is modeled by llvm::Instruction. This 2455 * class has a large number of descendents. llvm::Instruction is a 2456 * llvm::Value and in the C API, instructions are modeled by 2457 * LLVMValueRef. 2458 * 2459 * This group also contains sub-groups which operate on specific 2460 * llvm::Instruction types, e.g. llvm::CallInst. 2461 * 2462 * @{ 2463 */ 2464 2465 /** 2466 * Determine whether an instruction has any metadata attached. 2467 */ 2468 int LLVMHasMetadata(LLVMValueRef Val); 2469 2470 /** 2471 * Return metadata associated with an instruction value. 2472 */ 2473 LLVMValueRef LLVMGetMetadata(LLVMValueRef Val, uint KindID); 2474 2475 /** 2476 * Set metadata associated with an instruction value. 2477 */ 2478 void LLVMSetMetadata(LLVMValueRef Val, uint KindID, LLVMValueRef Node); 2479 2480 /** 2481 * Obtain the basic block to which an instruction belongs. 2482 * 2483 * @see llvm::Instruction::getParent() 2484 */ 2485 LLVMBasicBlockRef LLVMGetInstructionParent(LLVMValueRef Inst); 2486 2487 /** 2488 * Obtain the instruction that occurs after the one specified. 2489 * 2490 * The next instruction will be from the same basic block. 2491 * 2492 * If this is the last instruction in a basic block, NULL will be 2493 * returned. 2494 */ 2495 LLVMValueRef LLVMGetNextInstruction(LLVMValueRef Inst); 2496 2497 /** 2498 * Obtain the instruction that occurred before this one. 2499 * 2500 * If the instruction is the first instruction in a basic block, NULL 2501 * will be returned. 2502 */ 2503 LLVMValueRef LLVMGetPreviousInstruction(LLVMValueRef Inst); 2504 2505 /** 2506 * Remove and delete an instruction. 2507 * 2508 * The instruction specified is removed from its containing building 2509 * block but is kept alive. 2510 * 2511 * @see llvm::Instruction::removeFromParent() 2512 */ 2513 void LLVMInstructionRemoveFromParent(LLVMValueRef Inst); 2514 2515 /** 2516 * Remove and delete an instruction. 2517 * 2518 * The instruction specified is removed from its containing building 2519 * block and then deleted. 2520 * 2521 * @see llvm::Instruction::eraseFromParent() 2522 */ 2523 void LLVMInstructionEraseFromParent(LLVMValueRef Inst); 2524 2525 /** 2526 * Obtain the code opcode for an individual instruction. 2527 * 2528 * @see llvm::Instruction::getOpCode() 2529 */ 2530 LLVMOpcode LLVMGetInstructionOpcode(LLVMValueRef Inst); 2531 2532 /** 2533 * Obtain the predicate of an instruction. 2534 * 2535 * This is only valid for instructions that correspond to llvm::ICmpInst 2536 * or llvm::ConstantExpr whose opcode is llvm::Instruction::ICmp. 2537 * 2538 * @see llvm::ICmpInst::getPredicate() 2539 */ 2540 LLVMIntPredicate LLVMGetICmpPredicate(LLVMValueRef Inst); 2541 2542 /** 2543 * Obtain the float predicate of an instruction. 2544 * 2545 * This is only valid for instructions that correspond to llvm::FCmpInst 2546 * or llvm::ConstantExpr whose opcode is llvm::Instruction::FCmp. 2547 * 2548 * @see llvm::FCmpInst::getPredicate() 2549 */ 2550 LLVMRealPredicate LLVMGetFCmpPredicate(LLVMValueRef Inst); 2551 2552 /** 2553 * Create a copy of 'this' instruction that is identical in all ways 2554 * except the following: 2555 * * The instruction has no parent 2556 * * The instruction has no name 2557 * 2558 * @see llvm::Instruction::clone() 2559 */ 2560 LLVMValueRef LLVMInstructionClone(LLVMValueRef Inst); 2561 2562 /** 2563 * @defgroup LLVMCCoreValueInstructionCall Call Sites and Invocations 2564 * 2565 * Functions in this group apply to instructions that refer to call 2566 * sites and invocations. These correspond to C++ types in the 2567 * llvm::CallInst class tree. 2568 * 2569 * @{ 2570 */ 2571 2572 /** 2573 * Obtain the argument count for a call instruction. 2574 * 2575 * This expects an LLVMValueRef that corresponds to a llvm::CallInst or 2576 * llvm::InvokeInst. 2577 * 2578 * @see llvm::CallInst::getNumArgOperands() 2579 * @see llvm::InvokeInst::getNumArgOperands() 2580 */ 2581 uint LLVMGetNumArgOperands(LLVMValueRef Instr); 2582 2583 /** 2584 * Set the calling convention for a call instruction. 2585 * 2586 * This expects an LLVMValueRef that corresponds to a llvm::CallInst or 2587 * llvm::InvokeInst. 2588 * 2589 * @see llvm::CallInst::setCallingConv() 2590 * @see llvm::InvokeInst::setCallingConv() 2591 */ 2592 void LLVMSetInstructionCallConv(LLVMValueRef Instr, uint CC); 2593 2594 /** 2595 * Obtain the calling convention for a call instruction. 2596 * 2597 * This is the opposite of LLVMSetInstructionCallConv(). Reads its 2598 * usage. 2599 * 2600 * @see LLVMSetInstructionCallConv() 2601 */ 2602 uint LLVMGetInstructionCallConv(LLVMValueRef Instr); 2603 2604 2605 void LLVMAddInstrAttribute(LLVMValueRef Instr, uint index, LLVMAttribute); 2606 void LLVMRemoveInstrAttribute(LLVMValueRef Instr, uint index, 2607 LLVMAttribute); 2608 void LLVMSetInstrParamAlignment(LLVMValueRef Instr, uint index, 2609 uint Align); 2610 2611 void LLVMAddCallSiteAttribute(LLVMValueRef C, LLVMAttributeIndex Idx, 2612 LLVMAttributeRef A); 2613 uint LLVMGetCallSiteAttributeCount(LLVMValueRef C, LLVMAttributeIndex Idx); 2614 void LLVMGetCallSiteAttributes(LLVMValueRef C, LLVMAttributeIndex Idx, 2615 LLVMAttributeRef* Attrs); 2616 LLVMAttributeRef LLVMGetCallSiteEnumAttribute(LLVMValueRef C, 2617 LLVMAttributeIndex Idx, 2618 uint KindID); 2619 LLVMAttributeRef LLVMGetCallSiteStringAttribute(LLVMValueRef C, 2620 LLVMAttributeIndex Idx, 2621 const(char)* K, uint KLen); 2622 void LLVMRemoveCallSiteEnumAttribute(LLVMValueRef C, LLVMAttributeIndex Idx, 2623 uint KindID); 2624 void LLVMRemoveCallSiteStringAttribute(LLVMValueRef C, LLVMAttributeIndex Idx, 2625 const(char)* K, uint KLen); 2626 2627 /** 2628 * Obtain the pointer to the function invoked by this instruction. 2629 * 2630 * This expects an LLVMValueRef that corresponds to a llvm::CallInst or 2631 * llvm::InvokeInst. 2632 * 2633 * @see llvm::CallInst::getCalledValue() 2634 * @see llvm::InvokeInst::getCalledValue() 2635 */ 2636 LLVMValueRef LLVMGetCalledValue(LLVMValueRef Instr); 2637 2638 /** 2639 * Obtain whether a call instruction is a tail call. 2640 * 2641 * This only works on llvm::CallInst instructions. 2642 * 2643 * @see llvm::CallInst::isTailCall() 2644 */ 2645 LLVMBool LLVMIsTailCall(LLVMValueRef CallInst); 2646 2647 /** 2648 * Set whether a call instruction is a tail call. 2649 * 2650 * This only works on llvm::CallInst instructions. 2651 * 2652 * @see llvm::CallInst::setTailCall() 2653 */ 2654 void LLVMSetTailCall(LLVMValueRef CallInst, LLVMBool IsTailCall); 2655 2656 /** 2657 * Return the normal destination basic block. 2658 * 2659 * This only works on llvm::InvokeInst instructions. 2660 * 2661 * @see llvm::InvokeInst::getNormalDest() 2662 */ 2663 LLVMBasicBlockRef LLVMGetNormalDest(LLVMValueRef InvokeInst); 2664 2665 /** 2666 * Return the unwind destination basic block. 2667 * 2668 * This only works on llvm::InvokeInst instructions. 2669 * 2670 * @see llvm::InvokeInst::getUnwindDest() 2671 */ 2672 LLVMBasicBlockRef LLVMGetUnwindDest(LLVMValueRef InvokeInst); 2673 2674 /** 2675 * Set the normal destination basic block. 2676 * 2677 * This only works on llvm::InvokeInst instructions. 2678 * 2679 * @see llvm::InvokeInst::setNormalDest() 2680 */ 2681 void LLVMSetNormalDest(LLVMValueRef InvokeInst, LLVMBasicBlockRef B); 2682 2683 /** 2684 * Set the unwind destination basic block. 2685 * 2686 * This only works on llvm::InvokeInst instructions. 2687 * 2688 * @see llvm::InvokeInst::setUnwindDest() 2689 */ 2690 void LLVMSetUnwindDest(LLVMValueRef InvokeInst, LLVMBasicBlockRef B); 2691 2692 /** 2693 * @} 2694 */ 2695 2696 /** 2697 * @defgroup LLVMCCoreValueInstructionTerminator Terminators 2698 * 2699 * Functions in this group only apply to instructions that map to 2700 * llvm::TerminatorInst instances. 2701 * 2702 * @{ 2703 */ 2704 2705 /** 2706 * Return the number of successors that this terminator has. 2707 * 2708 * @see llvm::TerminatorInst::getNumSuccessors 2709 */ 2710 uint LLVMGetNumSuccessors(LLVMValueRef Term); 2711 2712 /** 2713 * Return the specified successor. 2714 * 2715 * @see llvm::TerminatorInst::getSuccessor 2716 */ 2717 LLVMBasicBlockRef LLVMGetSuccessor(LLVMValueRef Term, uint i); 2718 2719 /** 2720 * Update the specified successor to point at the provided block. 2721 * 2722 * @see llvm::TerminatorInst::setSuccessor 2723 */ 2724 void LLVMSetSuccessor(LLVMValueRef Term, uint i, LLVMBasicBlockRef block); 2725 2726 /** 2727 * Return if a branch is conditional. 2728 * 2729 * This only works on llvm::BranchInst instructions. 2730 * 2731 * @see llvm::BranchInst::isConditional 2732 */ 2733 LLVMBool LLVMIsConditional(LLVMValueRef Branch); 2734 2735 /** 2736 * Return the condition of a branch instruction. 2737 * 2738 * This only works on llvm::BranchInst instructions. 2739 * 2740 * @see llvm::BranchInst::getCondition 2741 */ 2742 LLVMValueRef LLVMGetCondition(LLVMValueRef Branch); 2743 2744 /** 2745 * Set the condition of a branch instruction. 2746 * 2747 * This only works on llvm::BranchInst instructions. 2748 * 2749 * @see llvm::BranchInst::setCondition 2750 */ 2751 void LLVMSetCondition(LLVMValueRef Branch, LLVMValueRef Cond); 2752 2753 /** 2754 * Obtain the default destination basic block of a switch instruction. 2755 * 2756 * This only works on llvm::SwitchInst instructions. 2757 * 2758 * @see llvm::SwitchInst::getDefaultDest() 2759 */ 2760 LLVMBasicBlockRef LLVMGetSwitchDefaultDest(LLVMValueRef SwitchInstr); 2761 2762 /** 2763 * @} 2764 */ 2765 2766 /** 2767 * @defgroup LLVMCCoreValueInstructionAlloca Allocas 2768 * 2769 * Functions in this group only apply to instructions that map to 2770 * llvm::AllocaInst instances. 2771 * 2772 * @{ 2773 */ 2774 2775 /** 2776 * Obtain the type that is being allocated by the alloca instruction. 2777 */ 2778 LLVMTypeRef LLVMGetAllocatedType(LLVMValueRef Alloca); 2779 2780 /** 2781 * @} 2782 */ 2783 2784 /** 2785 * @defgroup LLVMCCoreValueInstructionGetElementPointer GEPs 2786 * 2787 * Functions in this group only apply to instructions that map to 2788 * llvm::GetElementPtrInst instances. 2789 * 2790 * @{ 2791 */ 2792 2793 /** 2794 * Check whether the given GEP instruction is inbounds. 2795 */ 2796 LLVMBool LLVMIsInBounds(LLVMValueRef GEP); 2797 2798 /** 2799 * Set the given GEP instruction to be inbounds or not. 2800 */ 2801 void LLVMSetIsInBounds(LLVMValueRef GEP, LLVMBool InBounds); 2802 2803 /** 2804 * @} 2805 */ 2806 2807 /** 2808 * @defgroup LLVMCCoreValueInstructionPHINode PHI Nodes 2809 * 2810 * Functions in this group only apply to instructions that map to 2811 * llvm::PHINode instances. 2812 * 2813 * @{ 2814 */ 2815 2816 /** 2817 * Add an incoming value to the end of a PHI list. 2818 */ 2819 void LLVMAddIncoming(LLVMValueRef PhiNode, LLVMValueRef *IncomingValues, 2820 LLVMBasicBlockRef* IncomingBlocks, uint Count); 2821 2822 /** 2823 * Obtain the number of incoming basic blocks to a PHI node. 2824 */ 2825 uint LLVMCountIncoming(LLVMValueRef PhiNode); 2826 2827 /** 2828 * Obtain an incoming value to a PHI node as an LLVMValueRef. 2829 */ 2830 LLVMValueRef LLVMGetIncomingValue(LLVMValueRef PhiNode, uint Index); 2831 2832 /** 2833 * Obtain an incoming value to a PHI node as an LLVMBasicBlockRef. 2834 */ 2835 LLVMBasicBlockRef LLVMGetIncomingBlock(LLVMValueRef PhiNode, uint Index); 2836 2837 /** 2838 * @} 2839 */ 2840 2841 /** 2842 * @defgroup LLVMCCoreValueInstructionExtractValue ExtractValue 2843 * @defgroup LLVMCCoreValueInstructionInsertValue InsertValue 2844 * 2845 * Functions in this group only apply to instructions that map to 2846 * llvm::ExtractValue and llvm::InsertValue instances. 2847 * 2848 * @{ 2849 */ 2850 2851 /** 2852 * Obtain the number of indices. 2853 * NB: This also works on GEP. 2854 */ 2855 uint LLVMGetNumIndices(LLVMValueRef Inst); 2856 2857 /** 2858 * Obtain the indices as an array. 2859 */ 2860 const(uint)* LLVMGetIndices(LLVMValueRef Inst); 2861 2862 /** 2863 * @} 2864 */ 2865 2866 /** 2867 * @} 2868 */ 2869 2870 /** 2871 * @} 2872 */ 2873 2874 /** 2875 * @defgroup LLVMCCoreInstructionBuilder Instruction Builders 2876 * 2877 * An instruction builder represents a point within a basic block and is 2878 * the exclusive means of building instructions using the C interface. 2879 * 2880 * @{ 2881 */ 2882 2883 LLVMBuilderRef LLVMCreateBuilderInContext(LLVMContextRef C); 2884 LLVMBuilderRef LLVMCreateBuilder(); 2885 void LLVMPositionBuilder(LLVMBuilderRef Builder, LLVMBasicBlockRef Block, 2886 LLVMValueRef Instr); 2887 void LLVMPositionBuilderBefore(LLVMBuilderRef Builder, LLVMValueRef Instr); 2888 void LLVMPositionBuilderAtEnd(LLVMBuilderRef Builder, LLVMBasicBlockRef Block); 2889 LLVMBasicBlockRef LLVMGetInsertBlock(LLVMBuilderRef Builder); 2890 void LLVMClearInsertionPosition(LLVMBuilderRef Builder); 2891 void LLVMInsertIntoBuilder(LLVMBuilderRef Builder, LLVMValueRef Instr); 2892 void LLVMInsertIntoBuilderWithName(LLVMBuilderRef Builder, LLVMValueRef Instr, 2893 const(char)* Name); 2894 void LLVMDisposeBuilder(LLVMBuilderRef Builder); 2895 2896 /* Metadata */ 2897 void LLVMSetCurrentDebugLocation(LLVMBuilderRef Builder, LLVMValueRef L); 2898 LLVMValueRef LLVMGetCurrentDebugLocation(LLVMBuilderRef Builder); 2899 void LLVMSetInstDebugLocation(LLVMBuilderRef Builder, LLVMValueRef Inst); 2900 2901 /* Terminators */ 2902 LLVMValueRef LLVMBuildRetVoid(LLVMBuilderRef); 2903 LLVMValueRef LLVMBuildRet(LLVMBuilderRef, LLVMValueRef V); 2904 LLVMValueRef LLVMBuildAggregateRet(LLVMBuilderRef, LLVMValueRef *RetVals, 2905 uint N); 2906 LLVMValueRef LLVMBuildBr(LLVMBuilderRef, LLVMBasicBlockRef Dest); 2907 LLVMValueRef LLVMBuildCondBr(LLVMBuilderRef, LLVMValueRef If, 2908 LLVMBasicBlockRef Then, LLVMBasicBlockRef Else); 2909 LLVMValueRef LLVMBuildSwitch(LLVMBuilderRef, LLVMValueRef V, 2910 LLVMBasicBlockRef Else, uint NumCases); 2911 LLVMValueRef LLVMBuildIndirectBr(LLVMBuilderRef B, LLVMValueRef Addr, 2912 uint NumDests); 2913 LLVMValueRef LLVMBuildInvoke(LLVMBuilderRef, LLVMValueRef Fn, 2914 LLVMValueRef* Args, uint NumArgs, 2915 LLVMBasicBlockRef Then, LLVMBasicBlockRef Catch, 2916 const(char)* Name); 2917 LLVMValueRef LLVMBuildLandingPad(LLVMBuilderRef B, LLVMTypeRef Ty, 2918 LLVMValueRef PersFn, uint NumClauses, 2919 const(char)* Name); 2920 LLVMValueRef LLVMBuildResume(LLVMBuilderRef B, LLVMValueRef Exn); 2921 LLVMValueRef LLVMBuildUnreachable(LLVMBuilderRef); 2922 2923 /* Add a case to the switch instruction */ 2924 void LLVMAddCase(LLVMValueRef Switch, LLVMValueRef OnVal, 2925 LLVMBasicBlockRef Dest); 2926 2927 /* Add a destination to the indirectbr instruction */ 2928 void LLVMAddDestination(LLVMValueRef IndirectBr, LLVMBasicBlockRef Dest); 2929 2930 /* Get the number of clauses on the landingpad instruction */ 2931 uint LLVMGetNumClauses(LLVMValueRef LandingPad); 2932 2933 /* Get the value of the clause at idnex Idx on the landingpad instruction */ 2934 LLVMValueRef LLVMGetClause(LLVMValueRef LandingPad, uint Idx); 2935 2936 /* Add a catch or filter clause to the landingpad instruction */ 2937 void LLVMAddClause(LLVMValueRef LandingPad, LLVMValueRef ClauseVal); 2938 2939 /* Get the 'cleanup' flag in the landingpad instruction */ 2940 LLVMBool LLVMIsCleanup(LLVMValueRef LandingPad); 2941 2942 /* Set the 'cleanup' flag in the landingpad instruction */ 2943 void LLVMSetCleanup(LLVMValueRef LandingPad, LLVMBool Val); 2944 2945 /* Arithmetic */ 2946 LLVMValueRef LLVMBuildAdd(LLVMBuilderRef, LLVMValueRef LHS, LLVMValueRef RHS, 2947 const(char)* Name); 2948 LLVMValueRef LLVMBuildNSWAdd(LLVMBuilderRef, LLVMValueRef LHS, LLVMValueRef RHS, 2949 const(char)* Name); 2950 LLVMValueRef LLVMBuildNUWAdd(LLVMBuilderRef, LLVMValueRef LHS, LLVMValueRef RHS, 2951 const(char)* Name); 2952 LLVMValueRef LLVMBuildFAdd(LLVMBuilderRef, LLVMValueRef LHS, LLVMValueRef RHS, 2953 const(char)* Name); 2954 LLVMValueRef LLVMBuildSub(LLVMBuilderRef, LLVMValueRef LHS, LLVMValueRef RHS, 2955 const(char)* Name); 2956 LLVMValueRef LLVMBuildNSWSub(LLVMBuilderRef, LLVMValueRef LHS, LLVMValueRef RHS, 2957 const(char)* Name); 2958 LLVMValueRef LLVMBuildNUWSub(LLVMBuilderRef, LLVMValueRef LHS, LLVMValueRef RHS, 2959 const(char)* Name); 2960 LLVMValueRef LLVMBuildFSub(LLVMBuilderRef, LLVMValueRef LHS, LLVMValueRef RHS, 2961 const(char)* Name); 2962 LLVMValueRef LLVMBuildMul(LLVMBuilderRef, LLVMValueRef LHS, LLVMValueRef RHS, 2963 const(char)* Name); 2964 LLVMValueRef LLVMBuildNSWMul(LLVMBuilderRef, LLVMValueRef LHS, LLVMValueRef RHS, 2965 const(char)* Name); 2966 LLVMValueRef LLVMBuildNUWMul(LLVMBuilderRef, LLVMValueRef LHS, LLVMValueRef RHS, 2967 const(char)* Name); 2968 LLVMValueRef LLVMBuildFMul(LLVMBuilderRef, LLVMValueRef LHS, LLVMValueRef RHS, 2969 const(char)* Name); 2970 LLVMValueRef LLVMBuildUDiv(LLVMBuilderRef, LLVMValueRef LHS, LLVMValueRef RHS, 2971 const(char)* Name); 2972 LLVMValueRef LLVMBuildSDiv(LLVMBuilderRef, LLVMValueRef LHS, LLVMValueRef RHS, 2973 const(char)* Name); 2974 LLVMValueRef LLVMBuildExactSDiv(LLVMBuilderRef, LLVMValueRef LHS, LLVMValueRef RHS, 2975 const(char)* Name); 2976 LLVMValueRef LLVMBuildFDiv(LLVMBuilderRef, LLVMValueRef LHS, LLVMValueRef RHS, 2977 const(char)* Name); 2978 LLVMValueRef LLVMBuildURem(LLVMBuilderRef, LLVMValueRef LHS, LLVMValueRef RHS, 2979 const(char)* Name); 2980 LLVMValueRef LLVMBuildSRem(LLVMBuilderRef, LLVMValueRef LHS, LLVMValueRef RHS, 2981 const(char)* Name); 2982 LLVMValueRef LLVMBuildFRem(LLVMBuilderRef, LLVMValueRef LHS, LLVMValueRef RHS, 2983 const(char)* Name); 2984 LLVMValueRef LLVMBuildShl(LLVMBuilderRef, LLVMValueRef LHS, LLVMValueRef RHS, 2985 const(char)* Name); 2986 LLVMValueRef LLVMBuildLShr(LLVMBuilderRef, LLVMValueRef LHS, LLVMValueRef RHS, 2987 const(char)* Name); 2988 LLVMValueRef LLVMBuildAShr(LLVMBuilderRef, LLVMValueRef LHS, LLVMValueRef RHS, 2989 const(char)* Name); 2990 LLVMValueRef LLVMBuildAnd(LLVMBuilderRef, LLVMValueRef LHS, LLVMValueRef RHS, 2991 const(char)* Name); 2992 LLVMValueRef LLVMBuildOr(LLVMBuilderRef, LLVMValueRef LHS, LLVMValueRef RHS, 2993 const(char)* Name); 2994 LLVMValueRef LLVMBuildXor(LLVMBuilderRef, LLVMValueRef LHS, LLVMValueRef RHS, 2995 const(char)* Name); 2996 LLVMValueRef LLVMBuildBinOp(LLVMBuilderRef B, LLVMOpcode Op, 2997 LLVMValueRef LHS, LLVMValueRef RHS, 2998 const(char)* Name); 2999 LLVMValueRef LLVMBuildNeg(LLVMBuilderRef, LLVMValueRef V, const(char)* Name); 3000 LLVMValueRef LLVMBuildNSWNeg(LLVMBuilderRef B, LLVMValueRef V, 3001 const(char)* Name); 3002 LLVMValueRef LLVMBuildNUWNeg(LLVMBuilderRef B, LLVMValueRef V, 3003 const(char)* Name); 3004 LLVMValueRef LLVMBuildFNeg(LLVMBuilderRef, LLVMValueRef V, const(char)* Name); 3005 LLVMValueRef LLVMBuildNot(LLVMBuilderRef, LLVMValueRef V, const(char)* Name); 3006 3007 /* Memory */ 3008 LLVMValueRef LLVMBuildMalloc(LLVMBuilderRef, LLVMTypeRef Ty, const(char)* Name); 3009 LLVMValueRef LLVMBuildArrayMalloc(LLVMBuilderRef, LLVMTypeRef Ty, 3010 LLVMValueRef Val, const(char)* Name); 3011 LLVMValueRef LLVMBuildAlloca(LLVMBuilderRef, LLVMTypeRef Ty, const(char)* Name); 3012 LLVMValueRef LLVMBuildArrayAlloca(LLVMBuilderRef, LLVMTypeRef Ty, 3013 LLVMValueRef Val, const(char)* Name); 3014 LLVMValueRef LLVMBuildFree(LLVMBuilderRef, LLVMValueRef PointerVal); 3015 LLVMValueRef LLVMBuildLoad(LLVMBuilderRef, LLVMValueRef PointerVal, 3016 const(char)* Name); 3017 LLVMValueRef LLVMBuildStore(LLVMBuilderRef, LLVMValueRef Val, LLVMValueRef Ptr); 3018 LLVMValueRef LLVMBuildGEP(LLVMBuilderRef B, LLVMValueRef Pointer, 3019 LLVMValueRef *Indices, uint NumIndices, 3020 const(char)* Name); 3021 LLVMValueRef LLVMBuildInBoundsGEP(LLVMBuilderRef B, LLVMValueRef Pointer, 3022 LLVMValueRef *Indices, uint NumIndices, 3023 const(char)* Name); 3024 LLVMValueRef LLVMBuildStructGEP(LLVMBuilderRef B, LLVMValueRef Pointer, 3025 uint Idx, const(char)* Name); 3026 LLVMValueRef LLVMBuildGlobalString(LLVMBuilderRef B, const(char)* Str, 3027 const(char)* Name); 3028 LLVMValueRef LLVMBuildGlobalStringPtr(LLVMBuilderRef B, const(char)* Str, 3029 const(char)* Name); 3030 LLVMBool LLVMGetVolatile(LLVMValueRef MemoryAccessInst); 3031 void LLVMSetVolatile(LLVMValueRef MemoryAccessInst, LLVMBool IsVolatile); 3032 LLVMAtomicOrdering LLVMGetOrdering(LLVMValueRef MemoryAccessInst); 3033 void LLVMSetOrdering(LLVMValueRef MemoryAccessInst, LLVMAtomicOrdering Ordering); 3034 3035 /* Casts */ 3036 LLVMValueRef LLVMBuildTrunc(LLVMBuilderRef, LLVMValueRef Val, 3037 LLVMTypeRef DestTy, const(char)* Name); 3038 LLVMValueRef LLVMBuildZExt(LLVMBuilderRef, LLVMValueRef Val, 3039 LLVMTypeRef DestTy, const(char)* Name); 3040 LLVMValueRef LLVMBuildSExt(LLVMBuilderRef, LLVMValueRef Val, 3041 LLVMTypeRef DestTy, const(char)* Name); 3042 LLVMValueRef LLVMBuildFPToUI(LLVMBuilderRef, LLVMValueRef Val, 3043 LLVMTypeRef DestTy, const(char)* Name); 3044 LLVMValueRef LLVMBuildFPToSI(LLVMBuilderRef, LLVMValueRef Val, 3045 LLVMTypeRef DestTy, const(char)* Name); 3046 LLVMValueRef LLVMBuildUIToFP(LLVMBuilderRef, LLVMValueRef Val, 3047 LLVMTypeRef DestTy, const(char)* Name); 3048 LLVMValueRef LLVMBuildSIToFP(LLVMBuilderRef, LLVMValueRef Val, 3049 LLVMTypeRef DestTy, const(char)* Name); 3050 LLVMValueRef LLVMBuildFPTrunc(LLVMBuilderRef, LLVMValueRef Val, 3051 LLVMTypeRef DestTy, const(char)* Name); 3052 LLVMValueRef LLVMBuildFPExt(LLVMBuilderRef, LLVMValueRef Val, 3053 LLVMTypeRef DestTy, const(char)* Name); 3054 LLVMValueRef LLVMBuildPtrToInt(LLVMBuilderRef, LLVMValueRef Val, 3055 LLVMTypeRef DestTy, const(char)* Name); 3056 LLVMValueRef LLVMBuildIntToPtr(LLVMBuilderRef, LLVMValueRef Val, 3057 LLVMTypeRef DestTy, const(char)* Name); 3058 LLVMValueRef LLVMBuildBitCast(LLVMBuilderRef, LLVMValueRef Val, 3059 LLVMTypeRef DestTy, const(char)* Name); 3060 LLVMValueRef LLVMBuildAddrSpaceCast(LLVMBuilderRef, LLVMValueRef Val, 3061 LLVMTypeRef DestTy, const(char)* Name); 3062 LLVMValueRef LLVMBuildZExtOrBitCast(LLVMBuilderRef, LLVMValueRef Val, 3063 LLVMTypeRef DestTy, const(char)* Name); 3064 LLVMValueRef LLVMBuildSExtOrBitCast(LLVMBuilderRef, LLVMValueRef Val, 3065 LLVMTypeRef DestTy, const(char)* Name); 3066 LLVMValueRef LLVMBuildTruncOrBitCast(LLVMBuilderRef, LLVMValueRef Val, 3067 LLVMTypeRef DestTy, const(char)* Name); 3068 LLVMValueRef LLVMBuildCast(LLVMBuilderRef B, LLVMOpcode Op, LLVMValueRef Val, 3069 LLVMTypeRef DestTy, const(char)* Name); 3070 LLVMValueRef LLVMBuildPointerCast(LLVMBuilderRef, LLVMValueRef Val, 3071 LLVMTypeRef DestTy, const(char)* Name); 3072 LLVMValueRef LLVMBuildIntCast(LLVMBuilderRef, LLVMValueRef Val, /*Signed cast!*/ 3073 LLVMTypeRef DestTy, const(char)* Name); 3074 LLVMValueRef LLVMBuildFPCast(LLVMBuilderRef, LLVMValueRef Val, 3075 LLVMTypeRef DestTy, const(char)* Name); 3076 3077 /* Comparisons */ 3078 LLVMValueRef LLVMBuildICmp(LLVMBuilderRef, LLVMIntPredicate Op, 3079 LLVMValueRef LHS, LLVMValueRef RHS, 3080 const(char)* Name); 3081 LLVMValueRef LLVMBuildFCmp(LLVMBuilderRef, LLVMRealPredicate Op, 3082 LLVMValueRef LHS, LLVMValueRef RHS, 3083 const(char)* Name); 3084 3085 /* Miscellaneous instructions */ 3086 LLVMValueRef LLVMBuildPhi(LLVMBuilderRef, LLVMTypeRef Ty, const(char)* Name); 3087 LLVMValueRef LLVMBuildCall(LLVMBuilderRef, LLVMValueRef Fn, 3088 LLVMValueRef *Args, uint NumArgs, 3089 const(char)* Name); 3090 LLVMValueRef LLVMBuildSelect(LLVMBuilderRef, LLVMValueRef If, 3091 LLVMValueRef Then, LLVMValueRef Else, 3092 const(char)* Name); 3093 LLVMValueRef LLVMBuildVAArg(LLVMBuilderRef, LLVMValueRef List, LLVMTypeRef Ty, 3094 const(char)* Name); 3095 LLVMValueRef LLVMBuildExtractElement(LLVMBuilderRef, LLVMValueRef VecVal, 3096 LLVMValueRef Index, const(char)* Name); 3097 LLVMValueRef LLVMBuildInsertElement(LLVMBuilderRef, LLVMValueRef VecVal, 3098 LLVMValueRef EltVal, LLVMValueRef Index, 3099 const(char)* Name); 3100 LLVMValueRef LLVMBuildShuffleVector(LLVMBuilderRef, LLVMValueRef V1, 3101 LLVMValueRef V2, LLVMValueRef Mask, 3102 const(char)* Name); 3103 LLVMValueRef LLVMBuildExtractValue(LLVMBuilderRef, LLVMValueRef AggVal, 3104 uint Index, const(char)* Name); 3105 LLVMValueRef LLVMBuildInsertValue(LLVMBuilderRef, LLVMValueRef AggVal, 3106 LLVMValueRef EltVal, uint Index, 3107 const(char)* Name); 3108 3109 LLVMValueRef LLVMBuildIsNull(LLVMBuilderRef, LLVMValueRef Val, 3110 const(char)* Name); 3111 LLVMValueRef LLVMBuildIsNotNull(LLVMBuilderRef, LLVMValueRef Val, 3112 const(char)* Name); 3113 LLVMValueRef LLVMBuildPtrDiff(LLVMBuilderRef, LLVMValueRef LHS, 3114 LLVMValueRef RHS, const(char)* Name); 3115 LLVMValueRef LLVMBuildFence(LLVMBuilderRef B, LLVMAtomicOrdering ordering, 3116 LLVMBool singleThread, const(char)* Name); 3117 LLVMValueRef LLVMBuildAtomicRMW(LLVMBuilderRef B, LLVMAtomicRMWBinOp op, 3118 LLVMValueRef PTR, LLVMValueRef Val, 3119 LLVMAtomicOrdering ordering, 3120 LLVMBool singleThread); 3121 LLVMValueRef LLVMBuildAtomicCmpXchg(LLVMBuilderRef B, LLVMValueRef Ptr, 3122 LLVMValueRef Cmp, LLVMValueRef New, 3123 LLVMAtomicOrdering SuccessOrdering, 3124 LLVMAtomicOrdering FailureOrdering, 3125 LLVMBool SingleThread); 3126 3127 LLVMBool LLVMIsAtomicSingleThread(LLVMValueRef AtomicInst); 3128 void LLVMSetAtomicSingleThread(LLVMValueRef AtomicInst, LLVMBool SingleThread); 3129 3130 LLVMAtomicOrdering LLVMGetCmpXchgSuccessOrdering(LLVMValueRef CmpXchgInst); 3131 void LLVMSetCmpXchgSuccessOrdering(LLVMValueRef CmpXchgInst, 3132 LLVMAtomicOrdering Ordering); 3133 LLVMAtomicOrdering LLVMGetCmpXchgFailureOrdering(LLVMValueRef CmpXchgInst); 3134 void LLVMSetCmpXchgFailureOrdering(LLVMValueRef CmpXchgInst, 3135 LLVMAtomicOrdering Ordering); 3136 3137 /** 3138 * @} 3139 */ 3140 3141 /** 3142 * @defgroup LLVMCCoreModuleProvider Module Providers 3143 * 3144 * @{ 3145 */ 3146 3147 /** 3148 * Changes the type of M so it can be passed to FunctionPassManagers and the 3149 * JIT. They take ModuleProviders for historical reasons. 3150 */ 3151 LLVMModuleProviderRef 3152 LLVMCreateModuleProviderForExistingModule(LLVMModuleRef M); 3153 3154 /** 3155 * Destroys the module M. 3156 */ 3157 void LLVMDisposeModuleProvider(LLVMModuleProviderRef M); 3158 3159 /** 3160 * @} 3161 */ 3162 3163 /** 3164 * @defgroup LLVMCCoreMemoryBuffers Memory Buffers 3165 * 3166 * @{ 3167 */ 3168 3169 LLVMBool LLVMCreateMemoryBufferWithContentsOfFile(const(char)* Path, 3170 LLVMMemoryBufferRef *OutMemBuf, 3171 char **OutMessage); 3172 LLVMBool LLVMCreateMemoryBufferWithSTDIN(LLVMMemoryBufferRef *OutMemBuf, 3173 char **OutMessage); 3174 LLVMMemoryBufferRef LLVMCreateMemoryBufferWithMemoryRange(const char *InputData, 3175 size_t InputDataLength, 3176 const char *BufferName, 3177 LLVMBool RequiresNullTerminator); 3178 LLVMMemoryBufferRef LLVMCreateMemoryBufferWithMemoryRangeCopy(const char *InputData, 3179 size_t InputDataLength, 3180 const char *BufferName); 3181 const(char)* LLVMGetBufferStart(LLVMMemoryBufferRef MemBuf); 3182 size_t LLVMGetBufferSize(LLVMMemoryBufferRef MemBuf); 3183 void LLVMDisposeMemoryBuffer(LLVMMemoryBufferRef MemBuf); 3184 3185 /** 3186 * @} 3187 */ 3188 3189 /** 3190 * @defgroup LLVMCCorePassRegistry Pass Registry 3191 * 3192 * @{ 3193 */ 3194 3195 /** Return the global pass registry, for use with initialization functions. 3196 @see llvm::PassRegistry::getPassRegistry */ 3197 LLVMPassRegistryRef LLVMGetGlobalPassRegistry(); 3198 3199 /** 3200 * @} 3201 */ 3202 3203 /** 3204 * @defgroup LLVMCCorePassManagers Pass Managers 3205 * 3206 * @{ 3207 */ 3208 3209 /** Constructs a new whole-module pass pipeline. This type of pipeline is 3210 suitable for link-time optimization and whole-module transformations. 3211 @see llvm::PassManager::PassManager */ 3212 LLVMPassManagerRef LLVMCreatePassManager(); 3213 3214 /** Constructs a new function-by-function pass pipeline over the module 3215 provider. It does not take ownership of the module provider. This type of 3216 pipeline is suitable for code generation and JIT compilation tasks. 3217 @see llvm::FunctionPassManager::FunctionPassManager */ 3218 LLVMPassManagerRef LLVMCreateFunctionPassManagerForModule(LLVMModuleRef M); 3219 3220 /** Deprecated: Use LLVMCreateFunctionPassManagerForModule instead. */ 3221 LLVMPassManagerRef LLVMCreateFunctionPassManager(LLVMModuleProviderRef MP); 3222 3223 /** Initializes, executes on the provided module, and finalizes all of the 3224 passes scheduled in the pass manager. Returns 1 if any of the passes 3225 modified the module, 0 otherwise. 3226 @see llvm::PassManager::run(Module&) */ 3227 LLVMBool LLVMRunPassManager(LLVMPassManagerRef PM, LLVMModuleRef M); 3228 3229 /** Initializes all of the function passes scheduled in the function pass 3230 manager. Returns 1 if any of the passes modified the module, 0 otherwise. 3231 @see llvm::FunctionPassManager::doInitialization */ 3232 LLVMBool LLVMInitializeFunctionPassManager(LLVMPassManagerRef FPM); 3233 3234 /** Executes all of the function passes scheduled in the function pass manager 3235 on the provided function. Returns 1 if any of the passes modified the 3236 function, false otherwise. 3237 @see llvm::FunctionPassManager::run(Function&) */ 3238 LLVMBool LLVMRunFunctionPassManager(LLVMPassManagerRef FPM, LLVMValueRef F); 3239 3240 /** Finalizes all of the function passes scheduled in in the function pass 3241 manager. Returns 1 if any of the passes modified the module, 0 otherwise. 3242 @see llvm::FunctionPassManager::doFinalization */ 3243 LLVMBool LLVMFinalizeFunctionPassManager(LLVMPassManagerRef FPM); 3244 3245 /** Frees the memory of a pass pipeline. For function pipelines, does not free 3246 the module provider. 3247 @see llvm::PassManagerBase::~PassManagerBase. */ 3248 void LLVMDisposePassManager(LLVMPassManagerRef PM); 3249 3250 /** 3251 * @} 3252 */ 3253 3254 /** 3255 * @defgroup LLVMCCoreThreading Threading 3256 * 3257 * Handle the structures needed to make LLVM safe for multithreading. 3258 * 3259 * @{ 3260 */ 3261 3262 /** Deprecated: Multi-threading can only be enabled/disabled with the compile 3263 time define LLVM_ENABLE_THREADS. This function always returns 3264 LLVMIsMultithreaded(). */ 3265 LLVMBool LLVMStartMultithreaded(); 3266 3267 /** Deprecated: Multi-threading can only be enabled/disabled with the compile 3268 time define LLVM_ENABLE_THREADS. */ 3269 void LLVMStopMultithreaded(); 3270 3271 /** Check whether LLVM is executing in thread-safe mode or not. 3272 @see llvm::llvm_is_multithreaded */ 3273 LLVMBool LLVMIsMultithreaded(); 3274 3275 /** 3276 * @} 3277 */ 3278 3279 /** 3280 * @} 3281 */ 3282 3283 /** 3284 * @} 3285 */