Core.h revision 5768bb8d77892926dff0d078b1fb08c14ea791f3
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#ifndef LLVM_C_CORE_H 16#define LLVM_C_CORE_H 17 18#include "llvm/Support/DataTypes.h" 19 20#ifdef __cplusplus 21extern "C" { 22#endif 23 24/** 25 * @defgroup LLVMC LLVM-C: C interface to LLVM 26 * 27 * This module exposes parts of the LLVM library as a C API. 28 * 29 * @{ 30 */ 31 32/** 33 * @defgroup LLVMCTransforms Transforms 34 */ 35 36/** 37 * @defgroup LLVMCCore Core 38 * 39 * This modules provide an interface to libLLVMCore, which implements 40 * the LLVM intermediate representation as well as other related types 41 * and utilities. 42 * 43 * LLVM uses a polymorphic type hierarchy which C cannot represent, therefore 44 * parameters must be passed as base types. Despite the declared types, most 45 * of the functions provided operate only on branches of the type hierarchy. 46 * The declared parameter names are descriptive and specify which type is 47 * required. Additionally, each type hierarchy is documented along with the 48 * functions that operate upon it. For more detail, refer to LLVM's C++ code. 49 * If in doubt, refer to Core.cpp, which performs parameter downcasts in the 50 * form unwrap<RequiredType>(Param). 51 * 52 * Many exotic languages can interoperate with C code but have a harder time 53 * with C++ due to name mangling. So in addition to C, this interface enables 54 * tools written in such languages. 55 * 56 * @{ 57 */ 58 59/** 60 * @defgroup LLVMCCoreTypes Types and Enumerations 61 * 62 * @{ 63 */ 64 65typedef int LLVMBool; 66 67/* Opaque types. */ 68 69/** 70 * The top-level container for all LLVM global data. See the LLVMContext class. 71 */ 72typedef struct LLVMOpaqueContext *LLVMContextRef; 73 74/** 75 * The top-level container for all other LLVM Intermediate Representation (IR) 76 * objects. 77 * 78 * @see llvm::Module 79 */ 80typedef struct LLVMOpaqueModule *LLVMModuleRef; 81 82/** 83 * Each value in the LLVM IR has a type, an LLVMTypeRef. 84 * 85 * @see llvm::Type 86 */ 87typedef struct LLVMOpaqueType *LLVMTypeRef; 88 89/** 90 * Represents an individual value in LLVM IR. 91 * 92 * This models llvm::Value. 93 */ 94typedef struct LLVMOpaqueValue *LLVMValueRef; 95 96/** 97 * Represents a basic block of instructions in LLVM IR. 98 * 99 * This models llvm::BasicBlock. 100 */ 101typedef struct LLVMOpaqueBasicBlock *LLVMBasicBlockRef; 102 103/** 104 * Represents an LLVM basic block builder. 105 * 106 * This models llvm::IRBuilder. 107 */ 108typedef struct LLVMOpaqueBuilder *LLVMBuilderRef; 109 110/** 111 * Interface used to provide a module to JIT or interpreter. 112 * This is now just a synonym for llvm::Module, but we have to keep using the 113 * different type to keep binary compatibility. 114 */ 115typedef struct LLVMOpaqueModuleProvider *LLVMModuleProviderRef; 116 117/** 118 * Used to provide a module to JIT or interpreter. 119 * 120 * @see llvm::MemoryBuffer 121 */ 122typedef struct LLVMOpaqueMemoryBuffer *LLVMMemoryBufferRef; 123 124/** @see llvm::PassManagerBase */ 125typedef struct LLVMOpaquePassManager *LLVMPassManagerRef; 126 127/** @see llvm::PassRegistry */ 128typedef struct LLVMOpaquePassRegistry *LLVMPassRegistryRef; 129 130/** 131 * Used to get the users and usees of a Value. 132 * 133 * @see llvm::Use */ 134typedef struct LLVMOpaqueUse *LLVMUseRef; 135 136typedef enum { 137 LLVMZExtAttribute = 1<<0, 138 LLVMSExtAttribute = 1<<1, 139 LLVMNoReturnAttribute = 1<<2, 140 LLVMInRegAttribute = 1<<3, 141 LLVMStructRetAttribute = 1<<4, 142 LLVMNoUnwindAttribute = 1<<5, 143 LLVMNoAliasAttribute = 1<<6, 144 LLVMByValAttribute = 1<<7, 145 LLVMNestAttribute = 1<<8, 146 LLVMReadNoneAttribute = 1<<9, 147 LLVMReadOnlyAttribute = 1<<10, 148 LLVMNoInlineAttribute = 1<<11, 149 LLVMAlwaysInlineAttribute = 1<<12, 150 LLVMOptimizeForSizeAttribute = 1<<13, 151 LLVMStackProtectAttribute = 1<<14, 152 LLVMStackProtectReqAttribute = 1<<15, 153 LLVMAlignment = 31<<16, 154 LLVMNoCaptureAttribute = 1<<21, 155 LLVMNoRedZoneAttribute = 1<<22, 156 LLVMNoImplicitFloatAttribute = 1<<23, 157 LLVMNakedAttribute = 1<<24, 158 LLVMInlineHintAttribute = 1<<25, 159 LLVMStackAlignment = 7<<26, 160 LLVMReturnsTwice = 1 << 29, 161 LLVMUWTable = 1 << 30, 162 LLVMNonLazyBind = 1 << 31 163 164 /* FIXME: These attributes are currently not included in the C API as 165 a temporary measure until the API/ABI impact to the C API is understood 166 and the path forward agreed upon. 167 LLVMAddressSafety = 1ULL << 32, 168 LLVMStackProtectStrongAttribute = 1ULL<<33, 169 LLVMCold = 1ULL << 34, 170 LLVMOptimizeNone = 1ULL << 35 171 */ 172} LLVMAttribute; 173 174typedef enum { 175 /* Terminator Instructions */ 176 LLVMRet = 1, 177 LLVMBr = 2, 178 LLVMSwitch = 3, 179 LLVMIndirectBr = 4, 180 LLVMInvoke = 5, 181 /* removed 6 due to API changes */ 182 LLVMUnreachable = 7, 183 184 /* Standard Binary Operators */ 185 LLVMAdd = 8, 186 LLVMFAdd = 9, 187 LLVMSub = 10, 188 LLVMFSub = 11, 189 LLVMMul = 12, 190 LLVMFMul = 13, 191 LLVMUDiv = 14, 192 LLVMSDiv = 15, 193 LLVMFDiv = 16, 194 LLVMURem = 17, 195 LLVMSRem = 18, 196 LLVMFRem = 19, 197 198 /* Logical Operators */ 199 LLVMShl = 20, 200 LLVMLShr = 21, 201 LLVMAShr = 22, 202 LLVMAnd = 23, 203 LLVMOr = 24, 204 LLVMXor = 25, 205 206 /* Memory Operators */ 207 LLVMAlloca = 26, 208 LLVMLoad = 27, 209 LLVMStore = 28, 210 LLVMGetElementPtr = 29, 211 212 /* Cast Operators */ 213 LLVMTrunc = 30, 214 LLVMZExt = 31, 215 LLVMSExt = 32, 216 LLVMFPToUI = 33, 217 LLVMFPToSI = 34, 218 LLVMUIToFP = 35, 219 LLVMSIToFP = 36, 220 LLVMFPTrunc = 37, 221 LLVMFPExt = 38, 222 LLVMPtrToInt = 39, 223 LLVMIntToPtr = 40, 224 LLVMBitCast = 41, 225 226 /* Other Operators */ 227 LLVMICmp = 42, 228 LLVMFCmp = 43, 229 LLVMPHI = 44, 230 LLVMCall = 45, 231 LLVMSelect = 46, 232 LLVMUserOp1 = 47, 233 LLVMUserOp2 = 48, 234 LLVMVAArg = 49, 235 LLVMExtractElement = 50, 236 LLVMInsertElement = 51, 237 LLVMShuffleVector = 52, 238 LLVMExtractValue = 53, 239 LLVMInsertValue = 54, 240 241 /* Atomic operators */ 242 LLVMFence = 55, 243 LLVMAtomicCmpXchg = 56, 244 LLVMAtomicRMW = 57, 245 246 /* Exception Handling Operators */ 247 LLVMResume = 58, 248 LLVMLandingPad = 59 249 250} LLVMOpcode; 251 252typedef enum { 253 LLVMVoidTypeKind, /**< type with no size */ 254 LLVMHalfTypeKind, /**< 16 bit floating point type */ 255 LLVMFloatTypeKind, /**< 32 bit floating point type */ 256 LLVMDoubleTypeKind, /**< 64 bit floating point type */ 257 LLVMX86_FP80TypeKind, /**< 80 bit floating point type (X87) */ 258 LLVMFP128TypeKind, /**< 128 bit floating point type (112-bit mantissa)*/ 259 LLVMPPC_FP128TypeKind, /**< 128 bit floating point type (two 64-bits) */ 260 LLVMLabelTypeKind, /**< Labels */ 261 LLVMIntegerTypeKind, /**< Arbitrary bit width integers */ 262 LLVMFunctionTypeKind, /**< Functions */ 263 LLVMStructTypeKind, /**< Structures */ 264 LLVMArrayTypeKind, /**< Arrays */ 265 LLVMPointerTypeKind, /**< Pointers */ 266 LLVMVectorTypeKind, /**< SIMD 'packed' format, or other vector type */ 267 LLVMMetadataTypeKind, /**< Metadata */ 268 LLVMX86_MMXTypeKind /**< X86 MMX */ 269} LLVMTypeKind; 270 271typedef enum { 272 LLVMExternalLinkage, /**< Externally visible function */ 273 LLVMAvailableExternallyLinkage, 274 LLVMLinkOnceAnyLinkage, /**< Keep one copy of function when linking (inline)*/ 275 LLVMLinkOnceODRLinkage, /**< Same, but only replaced by something 276 equivalent. */ 277 LLVMLinkOnceODRAutoHideLinkage, /**< Like LinkOnceODR, but possibly hidden. */ 278 LLVMWeakAnyLinkage, /**< Keep one copy of function when linking (weak) */ 279 LLVMWeakODRLinkage, /**< Same, but only replaced by something 280 equivalent. */ 281 LLVMAppendingLinkage, /**< Special purpose, only applies to global arrays */ 282 LLVMInternalLinkage, /**< Rename collisions when linking (static 283 functions) */ 284 LLVMPrivateLinkage, /**< Like Internal, but omit from symbol table */ 285 LLVMDLLImportLinkage, /**< Function to be imported from DLL */ 286 LLVMDLLExportLinkage, /**< Function to be accessible from DLL */ 287 LLVMExternalWeakLinkage,/**< ExternalWeak linkage description */ 288 LLVMGhostLinkage, /**< Obsolete */ 289 LLVMCommonLinkage, /**< Tentative definitions */ 290 LLVMLinkerPrivateLinkage, /**< Like Private, but linker removes. */ 291 LLVMLinkerPrivateWeakLinkage /**< Like LinkerPrivate, but is weak. */ 292} LLVMLinkage; 293 294typedef enum { 295 LLVMDefaultVisibility, /**< The GV is visible */ 296 LLVMHiddenVisibility, /**< The GV is hidden */ 297 LLVMProtectedVisibility /**< The GV is protected */ 298} LLVMVisibility; 299 300typedef enum { 301 LLVMCCallConv = 0, 302 LLVMFastCallConv = 8, 303 LLVMColdCallConv = 9, 304 LLVMX86StdcallCallConv = 64, 305 LLVMX86FastcallCallConv = 65 306} LLVMCallConv; 307 308typedef enum { 309 LLVMIntEQ = 32, /**< equal */ 310 LLVMIntNE, /**< not equal */ 311 LLVMIntUGT, /**< unsigned greater than */ 312 LLVMIntUGE, /**< unsigned greater or equal */ 313 LLVMIntULT, /**< unsigned less than */ 314 LLVMIntULE, /**< unsigned less or equal */ 315 LLVMIntSGT, /**< signed greater than */ 316 LLVMIntSGE, /**< signed greater or equal */ 317 LLVMIntSLT, /**< signed less than */ 318 LLVMIntSLE /**< signed less or equal */ 319} LLVMIntPredicate; 320 321typedef enum { 322 LLVMRealPredicateFalse, /**< Always false (always folded) */ 323 LLVMRealOEQ, /**< True if ordered and equal */ 324 LLVMRealOGT, /**< True if ordered and greater than */ 325 LLVMRealOGE, /**< True if ordered and greater than or equal */ 326 LLVMRealOLT, /**< True if ordered and less than */ 327 LLVMRealOLE, /**< True if ordered and less than or equal */ 328 LLVMRealONE, /**< True if ordered and operands are unequal */ 329 LLVMRealORD, /**< True if ordered (no nans) */ 330 LLVMRealUNO, /**< True if unordered: isnan(X) | isnan(Y) */ 331 LLVMRealUEQ, /**< True if unordered or equal */ 332 LLVMRealUGT, /**< True if unordered or greater than */ 333 LLVMRealUGE, /**< True if unordered, greater than, or equal */ 334 LLVMRealULT, /**< True if unordered or less than */ 335 LLVMRealULE, /**< True if unordered, less than, or equal */ 336 LLVMRealUNE, /**< True if unordered or not equal */ 337 LLVMRealPredicateTrue /**< Always true (always folded) */ 338} LLVMRealPredicate; 339 340typedef enum { 341 LLVMLandingPadCatch, /**< A catch clause */ 342 LLVMLandingPadFilter /**< A filter clause */ 343} LLVMLandingPadClauseTy; 344 345typedef enum { 346 LLVMNotThreadLocal = 0, 347 LLVMGeneralDynamicTLSModel, 348 LLVMLocalDynamicTLSModel, 349 LLVMInitialExecTLSModel, 350 LLVMLocalExecTLSModel 351} LLVMThreadLocalMode; 352 353typedef enum { 354 LLVMAtomicOrderingNotAtomic = 0, /**< A load or store which is not atomic */ 355 LLVMAtomicOrderingUnordered = 1, /**< Lowest level of atomicity, guarantees 356 somewhat sane results, lock free. */ 357 LLVMAtomicOrderingMonotonic = 2, /**< guarantees that if you take all the 358 operations affecting a specific address, 359 a consistent ordering exists */ 360 LLVMAtomicOrderingAcquire = 4, /**< Acquire provides a barrier of the sort 361 necessary to acquire a lock to access other 362 memory with normal loads and stores. */ 363 LLVMAtomicOrderingRelease = 5, /**< Release is similar to Acquire, but with 364 a barrier of the sort necessary to release 365 a lock. */ 366 LLVMAtomicOrderingAcquireRelease = 6, /**< provides both an Acquire and a 367 Release barrier (for fences and 368 operations which both read and write 369 memory). */ 370 LLVMAtomicOrderingSequentiallyConsistent = 7 /**< provides Acquire semantics 371 for loads and Release 372 semantics for stores. 373 Additionally, it guarantees 374 that a total ordering exists 375 between all 376 SequentiallyConsistent 377 operations. */ 378} LLVMAtomicOrdering; 379 380typedef enum { 381 LLVMAtomicRMWBinOpXchg, /**< Set the new value and return the one old */ 382 LLVMAtomicRMWBinOpAdd, /**< Add a value and return the old one */ 383 LLVMAtomicRMWBinOpSub, /**< Subtract a value and return the old one */ 384 LLVMAtomicRMWBinOpAnd, /**< And a value and return the old one */ 385 LLVMAtomicRMWBinOpNand, /**< Not-And a value and return the old one */ 386 LLVMAtomicRMWBinOpOr, /**< OR a value and return the old one */ 387 LLVMAtomicRMWBinOpXor, /**< Xor a value and return the old one */ 388 LLVMAtomicRMWBinOpMax, /**< Sets the value if it's greater than the 389 original using a signed comparison and return 390 the old one */ 391 LLVMAtomicRMWBinOpMin, /**< Sets the value if it's Smaller than the 392 original using a signed comparison and return 393 the old one */ 394 LLVMAtomicRMWBinOpUMax, /**< Sets the value if it's greater than the 395 original using an unsigned comparison and return 396 the old one */ 397 LLVMAtomicRMWBinOpUMin /**< Sets the value if it's greater than the 398 original using an unsigned comparison and return 399 the old one */ 400} LLVMAtomicRMWBinOp; 401 402/** 403 * @} 404 */ 405 406void LLVMInitializeCore(LLVMPassRegistryRef R); 407 408/** Deallocate and destroy all ManagedStatic variables. 409 @see llvm::llvm_shutdown 410 @see ManagedStatic */ 411void LLVMShutdown(); 412 413 414/*===-- Error handling ----------------------------------------------------===*/ 415 416char *LLVMCreateMessage(const char *Message); 417void LLVMDisposeMessage(char *Message); 418 419 420/** 421 * @defgroup LLVMCCoreContext Contexts 422 * 423 * Contexts are execution states for the core LLVM IR system. 424 * 425 * Most types are tied to a context instance. Multiple contexts can 426 * exist simultaneously. A single context is not thread safe. However, 427 * different contexts can execute on different threads simultaneously. 428 * 429 * @{ 430 */ 431 432/** 433 * Create a new context. 434 * 435 * Every call to this function should be paired with a call to 436 * LLVMContextDispose() or the context will leak memory. 437 */ 438LLVMContextRef LLVMContextCreate(void); 439 440/** 441 * Obtain the global context instance. 442 */ 443LLVMContextRef LLVMGetGlobalContext(void); 444 445/** 446 * Destroy a context instance. 447 * 448 * This should be called for every call to LLVMContextCreate() or memory 449 * will be leaked. 450 */ 451void LLVMContextDispose(LLVMContextRef C); 452 453unsigned LLVMGetMDKindIDInContext(LLVMContextRef C, const char* Name, 454 unsigned SLen); 455unsigned LLVMGetMDKindID(const char* Name, unsigned SLen); 456 457/** 458 * @} 459 */ 460 461/** 462 * @defgroup LLVMCCoreModule Modules 463 * 464 * Modules represent the top-level structure in an LLVM program. An LLVM 465 * module is effectively a translation unit or a collection of 466 * translation units merged together. 467 * 468 * @{ 469 */ 470 471/** 472 * Create a new, empty module in the global context. 473 * 474 * This is equivalent to calling LLVMModuleCreateWithNameInContext with 475 * LLVMGetGlobalContext() as the context parameter. 476 * 477 * Every invocation should be paired with LLVMDisposeModule() or memory 478 * will be leaked. 479 */ 480LLVMModuleRef LLVMModuleCreateWithName(const char *ModuleID); 481 482/** 483 * Create a new, empty module in a specific context. 484 * 485 * Every invocation should be paired with LLVMDisposeModule() or memory 486 * will be leaked. 487 */ 488LLVMModuleRef LLVMModuleCreateWithNameInContext(const char *ModuleID, 489 LLVMContextRef C); 490 491/** 492 * Destroy a module instance. 493 * 494 * This must be called for every created module or memory will be 495 * leaked. 496 */ 497void LLVMDisposeModule(LLVMModuleRef M); 498 499/** 500 * Obtain the data layout for a module. 501 * 502 * @see Module::getDataLayout() 503 */ 504const char *LLVMGetDataLayout(LLVMModuleRef M); 505 506/** 507 * Set the data layout for a module. 508 * 509 * @see Module::setDataLayout() 510 */ 511void LLVMSetDataLayout(LLVMModuleRef M, const char *Triple); 512 513/** 514 * Obtain the target triple for a module. 515 * 516 * @see Module::getTargetTriple() 517 */ 518const char *LLVMGetTarget(LLVMModuleRef M); 519 520/** 521 * Set the target triple for a module. 522 * 523 * @see Module::setTargetTriple() 524 */ 525void LLVMSetTarget(LLVMModuleRef M, const char *Triple); 526 527/** 528 * Dump a representation of a module to stderr. 529 * 530 * @see Module::dump() 531 */ 532void LLVMDumpModule(LLVMModuleRef M); 533 534/** 535 * Print a representation of a module to a file. The ErrorMessage needs to be 536 * disposed with LLVMDisposeMessage. Returns 0 on success, 1 otherwise. 537 * 538 * @see Module::print() 539 */ 540LLVMBool LLVMPrintModuleToFile(LLVMModuleRef M, const char *Filename, 541 char **ErrorMessage); 542 543/** 544 * Set inline assembly for a module. 545 * 546 * @see Module::setModuleInlineAsm() 547 */ 548void LLVMSetModuleInlineAsm(LLVMModuleRef M, const char *Asm); 549 550/** 551 * Obtain the context to which this module is associated. 552 * 553 * @see Module::getContext() 554 */ 555LLVMContextRef LLVMGetModuleContext(LLVMModuleRef M); 556 557/** 558 * Obtain a Type from a module by its registered name. 559 */ 560LLVMTypeRef LLVMGetTypeByName(LLVMModuleRef M, const char *Name); 561 562/** 563 * Obtain the number of operands for named metadata in a module. 564 * 565 * @see llvm::Module::getNamedMetadata() 566 */ 567unsigned LLVMGetNamedMetadataNumOperands(LLVMModuleRef M, const char* name); 568 569/** 570 * Obtain the named metadata operands for a module. 571 * 572 * The passed LLVMValueRef pointer should refer to an array of 573 * LLVMValueRef at least LLVMGetNamedMetadataNumOperands long. This 574 * array will be populated with the LLVMValueRef instances. Each 575 * instance corresponds to a llvm::MDNode. 576 * 577 * @see llvm::Module::getNamedMetadata() 578 * @see llvm::MDNode::getOperand() 579 */ 580void LLVMGetNamedMetadataOperands(LLVMModuleRef M, const char* name, LLVMValueRef *Dest); 581 582/** 583 * Add an operand to named metadata. 584 * 585 * @see llvm::Module::getNamedMetadata() 586 * @see llvm::MDNode::addOperand() 587 */ 588void LLVMAddNamedMetadataOperand(LLVMModuleRef M, const char* name, 589 LLVMValueRef Val); 590 591/** 592 * Add a function to a module under a specified name. 593 * 594 * @see llvm::Function::Create() 595 */ 596LLVMValueRef LLVMAddFunction(LLVMModuleRef M, const char *Name, 597 LLVMTypeRef FunctionTy); 598 599/** 600 * Obtain a Function value from a Module by its name. 601 * 602 * The returned value corresponds to a llvm::Function value. 603 * 604 * @see llvm::Module::getFunction() 605 */ 606LLVMValueRef LLVMGetNamedFunction(LLVMModuleRef M, const char *Name); 607 608/** 609 * Obtain an iterator to the first Function in a Module. 610 * 611 * @see llvm::Module::begin() 612 */ 613LLVMValueRef LLVMGetFirstFunction(LLVMModuleRef M); 614 615/** 616 * Obtain an iterator to the last Function in a Module. 617 * 618 * @see llvm::Module::end() 619 */ 620LLVMValueRef LLVMGetLastFunction(LLVMModuleRef M); 621 622/** 623 * Advance a Function iterator to the next Function. 624 * 625 * Returns NULL if the iterator was already at the end and there are no more 626 * functions. 627 */ 628LLVMValueRef LLVMGetNextFunction(LLVMValueRef Fn); 629 630/** 631 * Decrement a Function iterator to the previous Function. 632 * 633 * Returns NULL if the iterator was already at the beginning and there are 634 * no previous functions. 635 */ 636LLVMValueRef LLVMGetPreviousFunction(LLVMValueRef Fn); 637 638/** 639 * @} 640 */ 641 642/** 643 * @defgroup LLVMCCoreType Types 644 * 645 * Types represent the type of a value. 646 * 647 * Types are associated with a context instance. The context internally 648 * deduplicates types so there is only 1 instance of a specific type 649 * alive at a time. In other words, a unique type is shared among all 650 * consumers within a context. 651 * 652 * A Type in the C API corresponds to llvm::Type. 653 * 654 * Types have the following hierarchy: 655 * 656 * types: 657 * integer type 658 * real type 659 * function type 660 * sequence types: 661 * array type 662 * pointer type 663 * vector type 664 * void type 665 * label type 666 * opaque type 667 * 668 * @{ 669 */ 670 671/** 672 * Obtain the enumerated type of a Type instance. 673 * 674 * @see llvm::Type:getTypeID() 675 */ 676LLVMTypeKind LLVMGetTypeKind(LLVMTypeRef Ty); 677 678/** 679 * Whether the type has a known size. 680 * 681 * Things that don't have a size are abstract types, labels, and void.a 682 * 683 * @see llvm::Type::isSized() 684 */ 685LLVMBool LLVMTypeIsSized(LLVMTypeRef Ty); 686 687/** 688 * Obtain the context to which this type instance is associated. 689 * 690 * @see llvm::Type::getContext() 691 */ 692LLVMContextRef LLVMGetTypeContext(LLVMTypeRef Ty); 693 694/** 695 * @defgroup LLVMCCoreTypeInt Integer Types 696 * 697 * Functions in this section operate on integer types. 698 * 699 * @{ 700 */ 701 702/** 703 * Obtain an integer type from a context with specified bit width. 704 */ 705LLVMTypeRef LLVMInt1TypeInContext(LLVMContextRef C); 706LLVMTypeRef LLVMInt8TypeInContext(LLVMContextRef C); 707LLVMTypeRef LLVMInt16TypeInContext(LLVMContextRef C); 708LLVMTypeRef LLVMInt32TypeInContext(LLVMContextRef C); 709LLVMTypeRef LLVMInt64TypeInContext(LLVMContextRef C); 710LLVMTypeRef LLVMIntTypeInContext(LLVMContextRef C, unsigned NumBits); 711 712/** 713 * Obtain an integer type from the global context with a specified bit 714 * width. 715 */ 716LLVMTypeRef LLVMInt1Type(void); 717LLVMTypeRef LLVMInt8Type(void); 718LLVMTypeRef LLVMInt16Type(void); 719LLVMTypeRef LLVMInt32Type(void); 720LLVMTypeRef LLVMInt64Type(void); 721LLVMTypeRef LLVMIntType(unsigned NumBits); 722unsigned LLVMGetIntTypeWidth(LLVMTypeRef IntegerTy); 723 724/** 725 * @} 726 */ 727 728/** 729 * @defgroup LLVMCCoreTypeFloat Floating Point Types 730 * 731 * @{ 732 */ 733 734/** 735 * Obtain a 16-bit floating point type from a context. 736 */ 737LLVMTypeRef LLVMHalfTypeInContext(LLVMContextRef C); 738 739/** 740 * Obtain a 32-bit floating point type from a context. 741 */ 742LLVMTypeRef LLVMFloatTypeInContext(LLVMContextRef C); 743 744/** 745 * Obtain a 64-bit floating point type from a context. 746 */ 747LLVMTypeRef LLVMDoubleTypeInContext(LLVMContextRef C); 748 749/** 750 * Obtain a 80-bit floating point type (X87) from a context. 751 */ 752LLVMTypeRef LLVMX86FP80TypeInContext(LLVMContextRef C); 753 754/** 755 * Obtain a 128-bit floating point type (112-bit mantissa) from a 756 * context. 757 */ 758LLVMTypeRef LLVMFP128TypeInContext(LLVMContextRef C); 759 760/** 761 * Obtain a 128-bit floating point type (two 64-bits) from a context. 762 */ 763LLVMTypeRef LLVMPPCFP128TypeInContext(LLVMContextRef C); 764 765/** 766 * Obtain a floating point type from the global context. 767 * 768 * These map to the functions in this group of the same name. 769 */ 770LLVMTypeRef LLVMHalfType(void); 771LLVMTypeRef LLVMFloatType(void); 772LLVMTypeRef LLVMDoubleType(void); 773LLVMTypeRef LLVMX86FP80Type(void); 774LLVMTypeRef LLVMFP128Type(void); 775LLVMTypeRef LLVMPPCFP128Type(void); 776 777/** 778 * @} 779 */ 780 781/** 782 * @defgroup LLVMCCoreTypeFunction Function Types 783 * 784 * @{ 785 */ 786 787/** 788 * Obtain a function type consisting of a specified signature. 789 * 790 * The function is defined as a tuple of a return Type, a list of 791 * parameter types, and whether the function is variadic. 792 */ 793LLVMTypeRef LLVMFunctionType(LLVMTypeRef ReturnType, 794 LLVMTypeRef *ParamTypes, unsigned ParamCount, 795 LLVMBool IsVarArg); 796 797/** 798 * Returns whether a function type is variadic. 799 */ 800LLVMBool LLVMIsFunctionVarArg(LLVMTypeRef FunctionTy); 801 802/** 803 * Obtain the Type this function Type returns. 804 */ 805LLVMTypeRef LLVMGetReturnType(LLVMTypeRef FunctionTy); 806 807/** 808 * Obtain the number of parameters this function accepts. 809 */ 810unsigned LLVMCountParamTypes(LLVMTypeRef FunctionTy); 811 812/** 813 * Obtain the types of a function's parameters. 814 * 815 * The Dest parameter should point to a pre-allocated array of 816 * LLVMTypeRef at least LLVMCountParamTypes() large. On return, the 817 * first LLVMCountParamTypes() entries in the array will be populated 818 * with LLVMTypeRef instances. 819 * 820 * @param FunctionTy The function type to operate on. 821 * @param Dest Memory address of an array to be filled with result. 822 */ 823void LLVMGetParamTypes(LLVMTypeRef FunctionTy, LLVMTypeRef *Dest); 824 825/** 826 * @} 827 */ 828 829/** 830 * @defgroup LLVMCCoreTypeStruct Structure Types 831 * 832 * These functions relate to LLVMTypeRef instances. 833 * 834 * @see llvm::StructType 835 * 836 * @{ 837 */ 838 839/** 840 * Create a new structure type in a context. 841 * 842 * A structure is specified by a list of inner elements/types and 843 * whether these can be packed together. 844 * 845 * @see llvm::StructType::create() 846 */ 847LLVMTypeRef LLVMStructTypeInContext(LLVMContextRef C, LLVMTypeRef *ElementTypes, 848 unsigned ElementCount, LLVMBool Packed); 849 850/** 851 * Create a new structure type in the global context. 852 * 853 * @see llvm::StructType::create() 854 */ 855LLVMTypeRef LLVMStructType(LLVMTypeRef *ElementTypes, unsigned ElementCount, 856 LLVMBool Packed); 857 858/** 859 * Create an empty structure in a context having a specified name. 860 * 861 * @see llvm::StructType::create() 862 */ 863LLVMTypeRef LLVMStructCreateNamed(LLVMContextRef C, const char *Name); 864 865/** 866 * Obtain the name of a structure. 867 * 868 * @see llvm::StructType::getName() 869 */ 870const char *LLVMGetStructName(LLVMTypeRef Ty); 871 872/** 873 * Set the contents of a structure type. 874 * 875 * @see llvm::StructType::setBody() 876 */ 877void LLVMStructSetBody(LLVMTypeRef StructTy, LLVMTypeRef *ElementTypes, 878 unsigned ElementCount, LLVMBool Packed); 879 880/** 881 * Get the number of elements defined inside the structure. 882 * 883 * @see llvm::StructType::getNumElements() 884 */ 885unsigned LLVMCountStructElementTypes(LLVMTypeRef StructTy); 886 887/** 888 * Get the elements within a structure. 889 * 890 * The function is passed the address of a pre-allocated array of 891 * LLVMTypeRef at least LLVMCountStructElementTypes() long. After 892 * invocation, this array will be populated with the structure's 893 * elements. The objects in the destination array will have a lifetime 894 * of the structure type itself, which is the lifetime of the context it 895 * is contained in. 896 */ 897void LLVMGetStructElementTypes(LLVMTypeRef StructTy, LLVMTypeRef *Dest); 898 899/** 900 * Determine whether a structure is packed. 901 * 902 * @see llvm::StructType::isPacked() 903 */ 904LLVMBool LLVMIsPackedStruct(LLVMTypeRef StructTy); 905 906/** 907 * Determine whether a structure is opaque. 908 * 909 * @see llvm::StructType::isOpaque() 910 */ 911LLVMBool LLVMIsOpaqueStruct(LLVMTypeRef StructTy); 912 913/** 914 * @} 915 */ 916 917 918/** 919 * @defgroup LLVMCCoreTypeSequential Sequential Types 920 * 921 * Sequential types represents "arrays" of types. This is a super class 922 * for array, vector, and pointer types. 923 * 924 * @{ 925 */ 926 927/** 928 * Obtain the type of elements within a sequential type. 929 * 930 * This works on array, vector, and pointer types. 931 * 932 * @see llvm::SequentialType::getElementType() 933 */ 934LLVMTypeRef LLVMGetElementType(LLVMTypeRef Ty); 935 936/** 937 * Create a fixed size array type that refers to a specific type. 938 * 939 * The created type will exist in the context that its element type 940 * exists in. 941 * 942 * @see llvm::ArrayType::get() 943 */ 944LLVMTypeRef LLVMArrayType(LLVMTypeRef ElementType, unsigned ElementCount); 945 946/** 947 * Obtain the length of an array type. 948 * 949 * This only works on types that represent arrays. 950 * 951 * @see llvm::ArrayType::getNumElements() 952 */ 953unsigned LLVMGetArrayLength(LLVMTypeRef ArrayTy); 954 955/** 956 * Create a pointer type that points to a defined type. 957 * 958 * The created type will exist in the context that its pointee type 959 * exists in. 960 * 961 * @see llvm::PointerType::get() 962 */ 963LLVMTypeRef LLVMPointerType(LLVMTypeRef ElementType, unsigned AddressSpace); 964 965/** 966 * Obtain the address space of a pointer type. 967 * 968 * This only works on types that represent pointers. 969 * 970 * @see llvm::PointerType::getAddressSpace() 971 */ 972unsigned LLVMGetPointerAddressSpace(LLVMTypeRef PointerTy); 973 974/** 975 * Create a vector type that contains a defined type and has a specific 976 * number of elements. 977 * 978 * The created type will exist in the context thats its element type 979 * exists in. 980 * 981 * @see llvm::VectorType::get() 982 */ 983LLVMTypeRef LLVMVectorType(LLVMTypeRef ElementType, unsigned ElementCount); 984 985/** 986 * Obtain the number of elements in a vector type. 987 * 988 * This only works on types that represent vectors. 989 * 990 * @see llvm::VectorType::getNumElements() 991 */ 992unsigned LLVMGetVectorSize(LLVMTypeRef VectorTy); 993 994/** 995 * @} 996 */ 997 998/** 999 * @defgroup LLVMCCoreTypeOther Other Types 1000 * 1001 * @{ 1002 */ 1003 1004/** 1005 * Create a void type in a context. 1006 */ 1007LLVMTypeRef LLVMVoidTypeInContext(LLVMContextRef C); 1008 1009/** 1010 * Create a label type in a context. 1011 */ 1012LLVMTypeRef LLVMLabelTypeInContext(LLVMContextRef C); 1013 1014/** 1015 * Create a X86 MMX type in a context. 1016 */ 1017LLVMTypeRef LLVMX86MMXTypeInContext(LLVMContextRef C); 1018 1019/** 1020 * These are similar to the above functions except they operate on the 1021 * global context. 1022 */ 1023LLVMTypeRef LLVMVoidType(void); 1024LLVMTypeRef LLVMLabelType(void); 1025LLVMTypeRef LLVMX86MMXType(void); 1026 1027/** 1028 * @} 1029 */ 1030 1031/** 1032 * @} 1033 */ 1034 1035/** 1036 * @defgroup LLVMCCoreValues Values 1037 * 1038 * The bulk of LLVM's object model consists of values, which comprise a very 1039 * rich type hierarchy. 1040 * 1041 * LLVMValueRef essentially represents llvm::Value. There is a rich 1042 * hierarchy of classes within this type. Depending on the instance 1043 * obtained, not all APIs are available. 1044 * 1045 * Callers can determine the type of an LLVMValueRef by calling the 1046 * LLVMIsA* family of functions (e.g. LLVMIsAArgument()). These 1047 * functions are defined by a macro, so it isn't obvious which are 1048 * available by looking at the Doxygen source code. Instead, look at the 1049 * source definition of LLVM_FOR_EACH_VALUE_SUBCLASS and note the list 1050 * of value names given. These value names also correspond to classes in 1051 * the llvm::Value hierarchy. 1052 * 1053 * @{ 1054 */ 1055 1056#define LLVM_FOR_EACH_VALUE_SUBCLASS(macro) \ 1057 macro(Argument) \ 1058 macro(BasicBlock) \ 1059 macro(InlineAsm) \ 1060 macro(MDNode) \ 1061 macro(MDString) \ 1062 macro(User) \ 1063 macro(Constant) \ 1064 macro(BlockAddress) \ 1065 macro(ConstantAggregateZero) \ 1066 macro(ConstantArray) \ 1067 macro(ConstantExpr) \ 1068 macro(ConstantFP) \ 1069 macro(ConstantInt) \ 1070 macro(ConstantPointerNull) \ 1071 macro(ConstantStruct) \ 1072 macro(ConstantVector) \ 1073 macro(GlobalValue) \ 1074 macro(Function) \ 1075 macro(GlobalAlias) \ 1076 macro(GlobalVariable) \ 1077 macro(UndefValue) \ 1078 macro(Instruction) \ 1079 macro(BinaryOperator) \ 1080 macro(CallInst) \ 1081 macro(IntrinsicInst) \ 1082 macro(DbgInfoIntrinsic) \ 1083 macro(DbgDeclareInst) \ 1084 macro(MemIntrinsic) \ 1085 macro(MemCpyInst) \ 1086 macro(MemMoveInst) \ 1087 macro(MemSetInst) \ 1088 macro(CmpInst) \ 1089 macro(FCmpInst) \ 1090 macro(ICmpInst) \ 1091 macro(ExtractElementInst) \ 1092 macro(GetElementPtrInst) \ 1093 macro(InsertElementInst) \ 1094 macro(InsertValueInst) \ 1095 macro(LandingPadInst) \ 1096 macro(PHINode) \ 1097 macro(SelectInst) \ 1098 macro(ShuffleVectorInst) \ 1099 macro(StoreInst) \ 1100 macro(TerminatorInst) \ 1101 macro(BranchInst) \ 1102 macro(IndirectBrInst) \ 1103 macro(InvokeInst) \ 1104 macro(ReturnInst) \ 1105 macro(SwitchInst) \ 1106 macro(UnreachableInst) \ 1107 macro(ResumeInst) \ 1108 macro(UnaryInstruction) \ 1109 macro(AllocaInst) \ 1110 macro(CastInst) \ 1111 macro(BitCastInst) \ 1112 macro(FPExtInst) \ 1113 macro(FPToSIInst) \ 1114 macro(FPToUIInst) \ 1115 macro(FPTruncInst) \ 1116 macro(IntToPtrInst) \ 1117 macro(PtrToIntInst) \ 1118 macro(SExtInst) \ 1119 macro(SIToFPInst) \ 1120 macro(TruncInst) \ 1121 macro(UIToFPInst) \ 1122 macro(ZExtInst) \ 1123 macro(ExtractValueInst) \ 1124 macro(LoadInst) \ 1125 macro(VAArgInst) 1126 1127/** 1128 * @defgroup LLVMCCoreValueGeneral General APIs 1129 * 1130 * Functions in this section work on all LLVMValueRef instances, 1131 * regardless of their sub-type. They correspond to functions available 1132 * on llvm::Value. 1133 * 1134 * @{ 1135 */ 1136 1137/** 1138 * Obtain the type of a value. 1139 * 1140 * @see llvm::Value::getType() 1141 */ 1142LLVMTypeRef LLVMTypeOf(LLVMValueRef Val); 1143 1144/** 1145 * Obtain the string name of a value. 1146 * 1147 * @see llvm::Value::getName() 1148 */ 1149const char *LLVMGetValueName(LLVMValueRef Val); 1150 1151/** 1152 * Set the string name of a value. 1153 * 1154 * @see llvm::Value::setName() 1155 */ 1156void LLVMSetValueName(LLVMValueRef Val, const char *Name); 1157 1158/** 1159 * Dump a representation of a value to stderr. 1160 * 1161 * @see llvm::Value::dump() 1162 */ 1163void LLVMDumpValue(LLVMValueRef Val); 1164 1165/** 1166 * Replace all uses of a value with another one. 1167 * 1168 * @see llvm::Value::replaceAllUsesWith() 1169 */ 1170void LLVMReplaceAllUsesWith(LLVMValueRef OldVal, LLVMValueRef NewVal); 1171 1172/** 1173 * Determine whether the specified constant instance is constant. 1174 */ 1175LLVMBool LLVMIsConstant(LLVMValueRef Val); 1176 1177/** 1178 * Determine whether a value instance is undefined. 1179 */ 1180LLVMBool LLVMIsUndef(LLVMValueRef Val); 1181 1182/** 1183 * Convert value instances between types. 1184 * 1185 * Internally, an LLVMValueRef is "pinned" to a specific type. This 1186 * series of functions allows you to cast an instance to a specific 1187 * type. 1188 * 1189 * If the cast is not valid for the specified type, NULL is returned. 1190 * 1191 * @see llvm::dyn_cast_or_null<> 1192 */ 1193#define LLVM_DECLARE_VALUE_CAST(name) \ 1194 LLVMValueRef LLVMIsA##name(LLVMValueRef Val); 1195LLVM_FOR_EACH_VALUE_SUBCLASS(LLVM_DECLARE_VALUE_CAST) 1196 1197/** 1198 * @} 1199 */ 1200 1201/** 1202 * @defgroup LLVMCCoreValueUses Usage 1203 * 1204 * This module defines functions that allow you to inspect the uses of a 1205 * LLVMValueRef. 1206 * 1207 * It is possible to obtain an LLVMUseRef for any LLVMValueRef instance. 1208 * Each LLVMUseRef (which corresponds to a llvm::Use instance) holds a 1209 * llvm::User and llvm::Value. 1210 * 1211 * @{ 1212 */ 1213 1214/** 1215 * Obtain the first use of a value. 1216 * 1217 * Uses are obtained in an iterator fashion. First, call this function 1218 * to obtain a reference to the first use. Then, call LLVMGetNextUse() 1219 * on that instance and all subsequently obtained instances until 1220 * LLVMGetNextUse() returns NULL. 1221 * 1222 * @see llvm::Value::use_begin() 1223 */ 1224LLVMUseRef LLVMGetFirstUse(LLVMValueRef Val); 1225 1226/** 1227 * Obtain the next use of a value. 1228 * 1229 * This effectively advances the iterator. It returns NULL if you are on 1230 * the final use and no more are available. 1231 */ 1232LLVMUseRef LLVMGetNextUse(LLVMUseRef U); 1233 1234/** 1235 * Obtain the user value for a user. 1236 * 1237 * The returned value corresponds to a llvm::User type. 1238 * 1239 * @see llvm::Use::getUser() 1240 */ 1241LLVMValueRef LLVMGetUser(LLVMUseRef U); 1242 1243/** 1244 * Obtain the value this use corresponds to. 1245 * 1246 * @see llvm::Use::get(). 1247 */ 1248LLVMValueRef LLVMGetUsedValue(LLVMUseRef U); 1249 1250/** 1251 * @} 1252 */ 1253 1254/** 1255 * @defgroup LLVMCCoreValueUser User value 1256 * 1257 * Function in this group pertain to LLVMValueRef instances that descent 1258 * from llvm::User. This includes constants, instructions, and 1259 * operators. 1260 * 1261 * @{ 1262 */ 1263 1264/** 1265 * Obtain an operand at a specific index in a llvm::User value. 1266 * 1267 * @see llvm::User::getOperand() 1268 */ 1269LLVMValueRef LLVMGetOperand(LLVMValueRef Val, unsigned Index); 1270 1271/** 1272 * Set an operand at a specific index in a llvm::User value. 1273 * 1274 * @see llvm::User::setOperand() 1275 */ 1276void LLVMSetOperand(LLVMValueRef User, unsigned Index, LLVMValueRef Val); 1277 1278/** 1279 * Obtain the number of operands in a llvm::User value. 1280 * 1281 * @see llvm::User::getNumOperands() 1282 */ 1283int LLVMGetNumOperands(LLVMValueRef Val); 1284 1285/** 1286 * @} 1287 */ 1288 1289/** 1290 * @defgroup LLVMCCoreValueConstant Constants 1291 * 1292 * This section contains APIs for interacting with LLVMValueRef that 1293 * correspond to llvm::Constant instances. 1294 * 1295 * These functions will work for any LLVMValueRef in the llvm::Constant 1296 * class hierarchy. 1297 * 1298 * @{ 1299 */ 1300 1301/** 1302 * Obtain a constant value referring to the null instance of a type. 1303 * 1304 * @see llvm::Constant::getNullValue() 1305 */ 1306LLVMValueRef LLVMConstNull(LLVMTypeRef Ty); /* all zeroes */ 1307 1308/** 1309 * Obtain a constant value referring to the instance of a type 1310 * consisting of all ones. 1311 * 1312 * This is only valid for integer types. 1313 * 1314 * @see llvm::Constant::getAllOnesValue() 1315 */ 1316LLVMValueRef LLVMConstAllOnes(LLVMTypeRef Ty); 1317 1318/** 1319 * Obtain a constant value referring to an undefined value of a type. 1320 * 1321 * @see llvm::UndefValue::get() 1322 */ 1323LLVMValueRef LLVMGetUndef(LLVMTypeRef Ty); 1324 1325/** 1326 * Determine whether a value instance is null. 1327 * 1328 * @see llvm::Constant::isNullValue() 1329 */ 1330LLVMBool LLVMIsNull(LLVMValueRef Val); 1331 1332/** 1333 * Obtain a constant that is a constant pointer pointing to NULL for a 1334 * specified type. 1335 */ 1336LLVMValueRef LLVMConstPointerNull(LLVMTypeRef Ty); 1337 1338/** 1339 * @defgroup LLVMCCoreValueConstantScalar Scalar constants 1340 * 1341 * Functions in this group model LLVMValueRef instances that correspond 1342 * to constants referring to scalar types. 1343 * 1344 * For integer types, the LLVMTypeRef parameter should correspond to a 1345 * llvm::IntegerType instance and the returned LLVMValueRef will 1346 * correspond to a llvm::ConstantInt. 1347 * 1348 * For floating point types, the LLVMTypeRef returned corresponds to a 1349 * llvm::ConstantFP. 1350 * 1351 * @{ 1352 */ 1353 1354/** 1355 * Obtain a constant value for an integer type. 1356 * 1357 * The returned value corresponds to a llvm::ConstantInt. 1358 * 1359 * @see llvm::ConstantInt::get() 1360 * 1361 * @param IntTy Integer type to obtain value of. 1362 * @param N The value the returned instance should refer to. 1363 * @param SignExtend Whether to sign extend the produced value. 1364 */ 1365LLVMValueRef LLVMConstInt(LLVMTypeRef IntTy, unsigned long long N, 1366 LLVMBool SignExtend); 1367 1368/** 1369 * Obtain a constant value for an integer of arbitrary precision. 1370 * 1371 * @see llvm::ConstantInt::get() 1372 */ 1373LLVMValueRef LLVMConstIntOfArbitraryPrecision(LLVMTypeRef IntTy, 1374 unsigned NumWords, 1375 const uint64_t Words[]); 1376 1377/** 1378 * Obtain a constant value for an integer parsed from a string. 1379 * 1380 * A similar API, LLVMConstIntOfStringAndSize is also available. If the 1381 * string's length is available, it is preferred to call that function 1382 * instead. 1383 * 1384 * @see llvm::ConstantInt::get() 1385 */ 1386LLVMValueRef LLVMConstIntOfString(LLVMTypeRef IntTy, const char *Text, 1387 uint8_t Radix); 1388 1389/** 1390 * Obtain a constant value for an integer parsed from a string with 1391 * specified length. 1392 * 1393 * @see llvm::ConstantInt::get() 1394 */ 1395LLVMValueRef LLVMConstIntOfStringAndSize(LLVMTypeRef IntTy, const char *Text, 1396 unsigned SLen, uint8_t Radix); 1397 1398/** 1399 * Obtain a constant value referring to a double floating point value. 1400 */ 1401LLVMValueRef LLVMConstReal(LLVMTypeRef RealTy, double N); 1402 1403/** 1404 * Obtain a constant for a floating point value parsed from a string. 1405 * 1406 * A similar API, LLVMConstRealOfStringAndSize is also available. It 1407 * should be used if the input string's length is known. 1408 */ 1409LLVMValueRef LLVMConstRealOfString(LLVMTypeRef RealTy, const char *Text); 1410 1411/** 1412 * Obtain a constant for a floating point value parsed from a string. 1413 */ 1414LLVMValueRef LLVMConstRealOfStringAndSize(LLVMTypeRef RealTy, const char *Text, 1415 unsigned SLen); 1416 1417/** 1418 * Obtain the zero extended value for an integer constant value. 1419 * 1420 * @see llvm::ConstantInt::getZExtValue() 1421 */ 1422unsigned long long LLVMConstIntGetZExtValue(LLVMValueRef ConstantVal); 1423 1424/** 1425 * Obtain the sign extended value for an integer constant value. 1426 * 1427 * @see llvm::ConstantInt::getSExtValue() 1428 */ 1429long long LLVMConstIntGetSExtValue(LLVMValueRef ConstantVal); 1430 1431/** 1432 * @} 1433 */ 1434 1435/** 1436 * @defgroup LLVMCCoreValueConstantComposite Composite Constants 1437 * 1438 * Functions in this group operate on composite constants. 1439 * 1440 * @{ 1441 */ 1442 1443/** 1444 * Create a ConstantDataSequential and initialize it with a string. 1445 * 1446 * @see llvm::ConstantDataArray::getString() 1447 */ 1448LLVMValueRef LLVMConstStringInContext(LLVMContextRef C, const char *Str, 1449 unsigned Length, LLVMBool DontNullTerminate); 1450 1451/** 1452 * Create a ConstantDataSequential with string content in the global context. 1453 * 1454 * This is the same as LLVMConstStringInContext except it operates on the 1455 * global context. 1456 * 1457 * @see LLVMConstStringInContext() 1458 * @see llvm::ConstantDataArray::getString() 1459 */ 1460LLVMValueRef LLVMConstString(const char *Str, unsigned Length, 1461 LLVMBool DontNullTerminate); 1462 1463/** 1464 * Create an anonymous ConstantStruct with the specified values. 1465 * 1466 * @see llvm::ConstantStruct::getAnon() 1467 */ 1468LLVMValueRef LLVMConstStructInContext(LLVMContextRef C, 1469 LLVMValueRef *ConstantVals, 1470 unsigned Count, LLVMBool Packed); 1471 1472/** 1473 * Create a ConstantStruct in the global Context. 1474 * 1475 * This is the same as LLVMConstStructInContext except it operates on the 1476 * global Context. 1477 * 1478 * @see LLVMConstStructInContext() 1479 */ 1480LLVMValueRef LLVMConstStruct(LLVMValueRef *ConstantVals, unsigned Count, 1481 LLVMBool Packed); 1482 1483/** 1484 * Create a ConstantArray from values. 1485 * 1486 * @see llvm::ConstantArray::get() 1487 */ 1488LLVMValueRef LLVMConstArray(LLVMTypeRef ElementTy, 1489 LLVMValueRef *ConstantVals, unsigned Length); 1490 1491/** 1492 * Create a non-anonymous ConstantStruct from values. 1493 * 1494 * @see llvm::ConstantStruct::get() 1495 */ 1496LLVMValueRef LLVMConstNamedStruct(LLVMTypeRef StructTy, 1497 LLVMValueRef *ConstantVals, 1498 unsigned Count); 1499 1500/** 1501 * Create a ConstantVector from values. 1502 * 1503 * @see llvm::ConstantVector::get() 1504 */ 1505LLVMValueRef LLVMConstVector(LLVMValueRef *ScalarConstantVals, unsigned Size); 1506 1507/** 1508 * @} 1509 */ 1510 1511/** 1512 * @defgroup LLVMCCoreValueConstantExpressions Constant Expressions 1513 * 1514 * Functions in this group correspond to APIs on llvm::ConstantExpr. 1515 * 1516 * @see llvm::ConstantExpr. 1517 * 1518 * @{ 1519 */ 1520LLVMOpcode LLVMGetConstOpcode(LLVMValueRef ConstantVal); 1521LLVMValueRef LLVMAlignOf(LLVMTypeRef Ty); 1522LLVMValueRef LLVMSizeOf(LLVMTypeRef Ty); 1523LLVMValueRef LLVMConstNeg(LLVMValueRef ConstantVal); 1524LLVMValueRef LLVMConstNSWNeg(LLVMValueRef ConstantVal); 1525LLVMValueRef LLVMConstNUWNeg(LLVMValueRef ConstantVal); 1526LLVMValueRef LLVMConstFNeg(LLVMValueRef ConstantVal); 1527LLVMValueRef LLVMConstNot(LLVMValueRef ConstantVal); 1528LLVMValueRef LLVMConstAdd(LLVMValueRef LHSConstant, LLVMValueRef RHSConstant); 1529LLVMValueRef LLVMConstNSWAdd(LLVMValueRef LHSConstant, LLVMValueRef RHSConstant); 1530LLVMValueRef LLVMConstNUWAdd(LLVMValueRef LHSConstant, LLVMValueRef RHSConstant); 1531LLVMValueRef LLVMConstFAdd(LLVMValueRef LHSConstant, LLVMValueRef RHSConstant); 1532LLVMValueRef LLVMConstSub(LLVMValueRef LHSConstant, LLVMValueRef RHSConstant); 1533LLVMValueRef LLVMConstNSWSub(LLVMValueRef LHSConstant, LLVMValueRef RHSConstant); 1534LLVMValueRef LLVMConstNUWSub(LLVMValueRef LHSConstant, LLVMValueRef RHSConstant); 1535LLVMValueRef LLVMConstFSub(LLVMValueRef LHSConstant, LLVMValueRef RHSConstant); 1536LLVMValueRef LLVMConstMul(LLVMValueRef LHSConstant, LLVMValueRef RHSConstant); 1537LLVMValueRef LLVMConstNSWMul(LLVMValueRef LHSConstant, LLVMValueRef RHSConstant); 1538LLVMValueRef LLVMConstNUWMul(LLVMValueRef LHSConstant, LLVMValueRef RHSConstant); 1539LLVMValueRef LLVMConstFMul(LLVMValueRef LHSConstant, LLVMValueRef RHSConstant); 1540LLVMValueRef LLVMConstUDiv(LLVMValueRef LHSConstant, LLVMValueRef RHSConstant); 1541LLVMValueRef LLVMConstSDiv(LLVMValueRef LHSConstant, LLVMValueRef RHSConstant); 1542LLVMValueRef LLVMConstExactSDiv(LLVMValueRef LHSConstant, LLVMValueRef RHSConstant); 1543LLVMValueRef LLVMConstFDiv(LLVMValueRef LHSConstant, LLVMValueRef RHSConstant); 1544LLVMValueRef LLVMConstURem(LLVMValueRef LHSConstant, LLVMValueRef RHSConstant); 1545LLVMValueRef LLVMConstSRem(LLVMValueRef LHSConstant, LLVMValueRef RHSConstant); 1546LLVMValueRef LLVMConstFRem(LLVMValueRef LHSConstant, LLVMValueRef RHSConstant); 1547LLVMValueRef LLVMConstAnd(LLVMValueRef LHSConstant, LLVMValueRef RHSConstant); 1548LLVMValueRef LLVMConstOr(LLVMValueRef LHSConstant, LLVMValueRef RHSConstant); 1549LLVMValueRef LLVMConstXor(LLVMValueRef LHSConstant, LLVMValueRef RHSConstant); 1550LLVMValueRef LLVMConstICmp(LLVMIntPredicate Predicate, 1551 LLVMValueRef LHSConstant, LLVMValueRef RHSConstant); 1552LLVMValueRef LLVMConstFCmp(LLVMRealPredicate Predicate, 1553 LLVMValueRef LHSConstant, LLVMValueRef RHSConstant); 1554LLVMValueRef LLVMConstShl(LLVMValueRef LHSConstant, LLVMValueRef RHSConstant); 1555LLVMValueRef LLVMConstLShr(LLVMValueRef LHSConstant, LLVMValueRef RHSConstant); 1556LLVMValueRef LLVMConstAShr(LLVMValueRef LHSConstant, LLVMValueRef RHSConstant); 1557LLVMValueRef LLVMConstGEP(LLVMValueRef ConstantVal, 1558 LLVMValueRef *ConstantIndices, unsigned NumIndices); 1559LLVMValueRef LLVMConstInBoundsGEP(LLVMValueRef ConstantVal, 1560 LLVMValueRef *ConstantIndices, 1561 unsigned NumIndices); 1562LLVMValueRef LLVMConstTrunc(LLVMValueRef ConstantVal, LLVMTypeRef ToType); 1563LLVMValueRef LLVMConstSExt(LLVMValueRef ConstantVal, LLVMTypeRef ToType); 1564LLVMValueRef LLVMConstZExt(LLVMValueRef ConstantVal, LLVMTypeRef ToType); 1565LLVMValueRef LLVMConstFPTrunc(LLVMValueRef ConstantVal, LLVMTypeRef ToType); 1566LLVMValueRef LLVMConstFPExt(LLVMValueRef ConstantVal, LLVMTypeRef ToType); 1567LLVMValueRef LLVMConstUIToFP(LLVMValueRef ConstantVal, LLVMTypeRef ToType); 1568LLVMValueRef LLVMConstSIToFP(LLVMValueRef ConstantVal, LLVMTypeRef ToType); 1569LLVMValueRef LLVMConstFPToUI(LLVMValueRef ConstantVal, LLVMTypeRef ToType); 1570LLVMValueRef LLVMConstFPToSI(LLVMValueRef ConstantVal, LLVMTypeRef ToType); 1571LLVMValueRef LLVMConstPtrToInt(LLVMValueRef ConstantVal, LLVMTypeRef ToType); 1572LLVMValueRef LLVMConstIntToPtr(LLVMValueRef ConstantVal, LLVMTypeRef ToType); 1573LLVMValueRef LLVMConstBitCast(LLVMValueRef ConstantVal, LLVMTypeRef ToType); 1574LLVMValueRef LLVMConstZExtOrBitCast(LLVMValueRef ConstantVal, 1575 LLVMTypeRef ToType); 1576LLVMValueRef LLVMConstSExtOrBitCast(LLVMValueRef ConstantVal, 1577 LLVMTypeRef ToType); 1578LLVMValueRef LLVMConstTruncOrBitCast(LLVMValueRef ConstantVal, 1579 LLVMTypeRef ToType); 1580LLVMValueRef LLVMConstPointerCast(LLVMValueRef ConstantVal, 1581 LLVMTypeRef ToType); 1582LLVMValueRef LLVMConstIntCast(LLVMValueRef ConstantVal, LLVMTypeRef ToType, 1583 LLVMBool isSigned); 1584LLVMValueRef LLVMConstFPCast(LLVMValueRef ConstantVal, LLVMTypeRef ToType); 1585LLVMValueRef LLVMConstSelect(LLVMValueRef ConstantCondition, 1586 LLVMValueRef ConstantIfTrue, 1587 LLVMValueRef ConstantIfFalse); 1588LLVMValueRef LLVMConstExtractElement(LLVMValueRef VectorConstant, 1589 LLVMValueRef IndexConstant); 1590LLVMValueRef LLVMConstInsertElement(LLVMValueRef VectorConstant, 1591 LLVMValueRef ElementValueConstant, 1592 LLVMValueRef IndexConstant); 1593LLVMValueRef LLVMConstShuffleVector(LLVMValueRef VectorAConstant, 1594 LLVMValueRef VectorBConstant, 1595 LLVMValueRef MaskConstant); 1596LLVMValueRef LLVMConstExtractValue(LLVMValueRef AggConstant, unsigned *IdxList, 1597 unsigned NumIdx); 1598LLVMValueRef LLVMConstInsertValue(LLVMValueRef AggConstant, 1599 LLVMValueRef ElementValueConstant, 1600 unsigned *IdxList, unsigned NumIdx); 1601LLVMValueRef LLVMConstInlineAsm(LLVMTypeRef Ty, 1602 const char *AsmString, const char *Constraints, 1603 LLVMBool HasSideEffects, LLVMBool IsAlignStack); 1604LLVMValueRef LLVMBlockAddress(LLVMValueRef F, LLVMBasicBlockRef BB); 1605 1606/** 1607 * @} 1608 */ 1609 1610/** 1611 * @defgroup LLVMCCoreValueConstantGlobals Global Values 1612 * 1613 * This group contains functions that operate on global values. Functions in 1614 * this group relate to functions in the llvm::GlobalValue class tree. 1615 * 1616 * @see llvm::GlobalValue 1617 * 1618 * @{ 1619 */ 1620 1621LLVMModuleRef LLVMGetGlobalParent(LLVMValueRef Global); 1622LLVMBool LLVMIsDeclaration(LLVMValueRef Global); 1623LLVMLinkage LLVMGetLinkage(LLVMValueRef Global); 1624void LLVMSetLinkage(LLVMValueRef Global, LLVMLinkage Linkage); 1625const char *LLVMGetSection(LLVMValueRef Global); 1626void LLVMSetSection(LLVMValueRef Global, const char *Section); 1627LLVMVisibility LLVMGetVisibility(LLVMValueRef Global); 1628void LLVMSetVisibility(LLVMValueRef Global, LLVMVisibility Viz); 1629unsigned LLVMGetAlignment(LLVMValueRef Global); 1630void LLVMSetAlignment(LLVMValueRef Global, unsigned Bytes); 1631 1632/** 1633 * @defgroup LLVMCoreValueConstantGlobalVariable Global Variables 1634 * 1635 * This group contains functions that operate on global variable values. 1636 * 1637 * @see llvm::GlobalVariable 1638 * 1639 * @{ 1640 */ 1641LLVMValueRef LLVMAddGlobal(LLVMModuleRef M, LLVMTypeRef Ty, const char *Name); 1642LLVMValueRef LLVMAddGlobalInAddressSpace(LLVMModuleRef M, LLVMTypeRef Ty, 1643 const char *Name, 1644 unsigned AddressSpace); 1645LLVMValueRef LLVMGetNamedGlobal(LLVMModuleRef M, const char *Name); 1646LLVMValueRef LLVMGetFirstGlobal(LLVMModuleRef M); 1647LLVMValueRef LLVMGetLastGlobal(LLVMModuleRef M); 1648LLVMValueRef LLVMGetNextGlobal(LLVMValueRef GlobalVar); 1649LLVMValueRef LLVMGetPreviousGlobal(LLVMValueRef GlobalVar); 1650void LLVMDeleteGlobal(LLVMValueRef GlobalVar); 1651LLVMValueRef LLVMGetInitializer(LLVMValueRef GlobalVar); 1652void LLVMSetInitializer(LLVMValueRef GlobalVar, LLVMValueRef ConstantVal); 1653LLVMBool LLVMIsThreadLocal(LLVMValueRef GlobalVar); 1654void LLVMSetThreadLocal(LLVMValueRef GlobalVar, LLVMBool IsThreadLocal); 1655LLVMBool LLVMIsGlobalConstant(LLVMValueRef GlobalVar); 1656void LLVMSetGlobalConstant(LLVMValueRef GlobalVar, LLVMBool IsConstant); 1657LLVMThreadLocalMode LLVMGetThreadLocalMode(LLVMValueRef GlobalVar); 1658void LLVMSetThreadLocalMode(LLVMValueRef GlobalVar, LLVMThreadLocalMode Mode); 1659LLVMBool LLVMIsExternallyInitialized(LLVMValueRef GlobalVar); 1660void LLVMSetExternallyInitialized(LLVMValueRef GlobalVar, LLVMBool IsExtInit); 1661 1662/** 1663 * @} 1664 */ 1665 1666/** 1667 * @defgroup LLVMCoreValueConstantGlobalAlias Global Aliases 1668 * 1669 * This group contains function that operate on global alias values. 1670 * 1671 * @see llvm::GlobalAlias 1672 * 1673 * @{ 1674 */ 1675LLVMValueRef LLVMAddAlias(LLVMModuleRef M, LLVMTypeRef Ty, LLVMValueRef Aliasee, 1676 const char *Name); 1677 1678/** 1679 * @} 1680 */ 1681 1682/** 1683 * @defgroup LLVMCCoreValueFunction Function values 1684 * 1685 * Functions in this group operate on LLVMValueRef instances that 1686 * correspond to llvm::Function instances. 1687 * 1688 * @see llvm::Function 1689 * 1690 * @{ 1691 */ 1692 1693/** 1694 * Remove a function from its containing module and deletes it. 1695 * 1696 * @see llvm::Function::eraseFromParent() 1697 */ 1698void LLVMDeleteFunction(LLVMValueRef Fn); 1699 1700/** 1701 * Obtain the ID number from a function instance. 1702 * 1703 * @see llvm::Function::getIntrinsicID() 1704 */ 1705unsigned LLVMGetIntrinsicID(LLVMValueRef Fn); 1706 1707/** 1708 * Obtain the calling function of a function. 1709 * 1710 * The returned value corresponds to the LLVMCallConv enumeration. 1711 * 1712 * @see llvm::Function::getCallingConv() 1713 */ 1714unsigned LLVMGetFunctionCallConv(LLVMValueRef Fn); 1715 1716/** 1717 * Set the calling convention of a function. 1718 * 1719 * @see llvm::Function::setCallingConv() 1720 * 1721 * @param Fn Function to operate on 1722 * @param CC LLVMCallConv to set calling convention to 1723 */ 1724void LLVMSetFunctionCallConv(LLVMValueRef Fn, unsigned CC); 1725 1726/** 1727 * Obtain the name of the garbage collector to use during code 1728 * generation. 1729 * 1730 * @see llvm::Function::getGC() 1731 */ 1732const char *LLVMGetGC(LLVMValueRef Fn); 1733 1734/** 1735 * Define the garbage collector to use during code generation. 1736 * 1737 * @see llvm::Function::setGC() 1738 */ 1739void LLVMSetGC(LLVMValueRef Fn, const char *Name); 1740 1741/** 1742 * Add an attribute to a function. 1743 * 1744 * @see llvm::Function::addAttribute() 1745 */ 1746void LLVMAddFunctionAttr(LLVMValueRef Fn, LLVMAttribute PA); 1747 1748/** 1749 * Add a target-dependent attribute to a fuction 1750 * @see llvm::AttrBuilder::addAttribute() 1751 */ 1752void LLVMAddTargetDependentFunctionAttr(LLVMValueRef Fn, const char *A, 1753 const char *V); 1754 1755/** 1756 * Obtain an attribute from a function. 1757 * 1758 * @see llvm::Function::getAttributes() 1759 */ 1760LLVMAttribute LLVMGetFunctionAttr(LLVMValueRef Fn); 1761 1762/** 1763 * Remove an attribute from a function. 1764 */ 1765void LLVMRemoveFunctionAttr(LLVMValueRef Fn, LLVMAttribute PA); 1766 1767/** 1768 * @defgroup LLVMCCoreValueFunctionParameters Function Parameters 1769 * 1770 * Functions in this group relate to arguments/parameters on functions. 1771 * 1772 * Functions in this group expect LLVMValueRef instances that correspond 1773 * to llvm::Function instances. 1774 * 1775 * @{ 1776 */ 1777 1778/** 1779 * Obtain the number of parameters in a function. 1780 * 1781 * @see llvm::Function::arg_size() 1782 */ 1783unsigned LLVMCountParams(LLVMValueRef Fn); 1784 1785/** 1786 * Obtain the parameters in a function. 1787 * 1788 * The takes a pointer to a pre-allocated array of LLVMValueRef that is 1789 * at least LLVMCountParams() long. This array will be filled with 1790 * LLVMValueRef instances which correspond to the parameters the 1791 * function receives. Each LLVMValueRef corresponds to a llvm::Argument 1792 * instance. 1793 * 1794 * @see llvm::Function::arg_begin() 1795 */ 1796void LLVMGetParams(LLVMValueRef Fn, LLVMValueRef *Params); 1797 1798/** 1799 * Obtain the parameter at the specified index. 1800 * 1801 * Parameters are indexed from 0. 1802 * 1803 * @see llvm::Function::arg_begin() 1804 */ 1805LLVMValueRef LLVMGetParam(LLVMValueRef Fn, unsigned Index); 1806 1807/** 1808 * Obtain the function to which this argument belongs. 1809 * 1810 * Unlike other functions in this group, this one takes an LLVMValueRef 1811 * that corresponds to a llvm::Attribute. 1812 * 1813 * The returned LLVMValueRef is the llvm::Function to which this 1814 * argument belongs. 1815 */ 1816LLVMValueRef LLVMGetParamParent(LLVMValueRef Inst); 1817 1818/** 1819 * Obtain the first parameter to a function. 1820 * 1821 * @see llvm::Function::arg_begin() 1822 */ 1823LLVMValueRef LLVMGetFirstParam(LLVMValueRef Fn); 1824 1825/** 1826 * Obtain the last parameter to a function. 1827 * 1828 * @see llvm::Function::arg_end() 1829 */ 1830LLVMValueRef LLVMGetLastParam(LLVMValueRef Fn); 1831 1832/** 1833 * Obtain the next parameter to a function. 1834 * 1835 * This takes an LLVMValueRef obtained from LLVMGetFirstParam() (which is 1836 * actually a wrapped iterator) and obtains the next parameter from the 1837 * underlying iterator. 1838 */ 1839LLVMValueRef LLVMGetNextParam(LLVMValueRef Arg); 1840 1841/** 1842 * Obtain the previous parameter to a function. 1843 * 1844 * This is the opposite of LLVMGetNextParam(). 1845 */ 1846LLVMValueRef LLVMGetPreviousParam(LLVMValueRef Arg); 1847 1848/** 1849 * Add an attribute to a function argument. 1850 * 1851 * @see llvm::Argument::addAttr() 1852 */ 1853void LLVMAddAttribute(LLVMValueRef Arg, LLVMAttribute PA); 1854 1855/** 1856 * Remove an attribute from a function argument. 1857 * 1858 * @see llvm::Argument::removeAttr() 1859 */ 1860void LLVMRemoveAttribute(LLVMValueRef Arg, LLVMAttribute PA); 1861 1862/** 1863 * Get an attribute from a function argument. 1864 */ 1865LLVMAttribute LLVMGetAttribute(LLVMValueRef Arg); 1866 1867/** 1868 * Set the alignment for a function parameter. 1869 * 1870 * @see llvm::Argument::addAttr() 1871 * @see llvm::AttrBuilder::addAlignmentAttr() 1872 */ 1873void LLVMSetParamAlignment(LLVMValueRef Arg, unsigned align); 1874 1875/** 1876 * @} 1877 */ 1878 1879/** 1880 * @} 1881 */ 1882 1883/** 1884 * @} 1885 */ 1886 1887/** 1888 * @} 1889 */ 1890 1891/** 1892 * @defgroup LLVMCCoreValueMetadata Metadata 1893 * 1894 * @{ 1895 */ 1896 1897/** 1898 * Obtain a MDString value from a context. 1899 * 1900 * The returned instance corresponds to the llvm::MDString class. 1901 * 1902 * The instance is specified by string data of a specified length. The 1903 * string content is copied, so the backing memory can be freed after 1904 * this function returns. 1905 */ 1906LLVMValueRef LLVMMDStringInContext(LLVMContextRef C, const char *Str, 1907 unsigned SLen); 1908 1909/** 1910 * Obtain a MDString value from the global context. 1911 */ 1912LLVMValueRef LLVMMDString(const char *Str, unsigned SLen); 1913 1914/** 1915 * Obtain a MDNode value from a context. 1916 * 1917 * The returned value corresponds to the llvm::MDNode class. 1918 */ 1919LLVMValueRef LLVMMDNodeInContext(LLVMContextRef C, LLVMValueRef *Vals, 1920 unsigned Count); 1921 1922/** 1923 * Obtain a MDNode value from the global context. 1924 */ 1925LLVMValueRef LLVMMDNode(LLVMValueRef *Vals, unsigned Count); 1926 1927/** 1928 * Obtain the underlying string from a MDString value. 1929 * 1930 * @param V Instance to obtain string from. 1931 * @param Len Memory address which will hold length of returned string. 1932 * @return String data in MDString. 1933 */ 1934const char *LLVMGetMDString(LLVMValueRef V, unsigned* Len); 1935 1936/** 1937 * Obtain the number of operands from an MDNode value. 1938 * 1939 * @param V MDNode to get number of operands from. 1940 * @return Number of operands of the MDNode. 1941 */ 1942unsigned LLVMGetMDNodeNumOperands(LLVMValueRef V); 1943 1944/** 1945 * Obtain the given MDNode's operands. 1946 * 1947 * The passed LLVMValueRef pointer should point to enough memory to hold all of 1948 * the operands of the given MDNode (see LLVMGetMDNodeNumOperands) as 1949 * LLVMValueRefs. This memory will be populated with the LLVMValueRefs of the 1950 * MDNode's operands. 1951 * 1952 * @param V MDNode to get the operands from. 1953 * @param Dest Destination array for operands. 1954 */ 1955void LLVMGetMDNodeOperands(LLVMValueRef V, LLVMValueRef *Dest); 1956 1957/** 1958 * @} 1959 */ 1960 1961/** 1962 * @defgroup LLVMCCoreValueBasicBlock Basic Block 1963 * 1964 * A basic block represents a single entry single exit section of code. 1965 * Basic blocks contain a list of instructions which form the body of 1966 * the block. 1967 * 1968 * Basic blocks belong to functions. They have the type of label. 1969 * 1970 * Basic blocks are themselves values. However, the C API models them as 1971 * LLVMBasicBlockRef. 1972 * 1973 * @see llvm::BasicBlock 1974 * 1975 * @{ 1976 */ 1977 1978/** 1979 * Convert a basic block instance to a value type. 1980 */ 1981LLVMValueRef LLVMBasicBlockAsValue(LLVMBasicBlockRef BB); 1982 1983/** 1984 * Determine whether an LLVMValueRef is itself a basic block. 1985 */ 1986LLVMBool LLVMValueIsBasicBlock(LLVMValueRef Val); 1987 1988/** 1989 * Convert an LLVMValueRef to an LLVMBasicBlockRef instance. 1990 */ 1991LLVMBasicBlockRef LLVMValueAsBasicBlock(LLVMValueRef Val); 1992 1993/** 1994 * Obtain the function to which a basic block belongs. 1995 * 1996 * @see llvm::BasicBlock::getParent() 1997 */ 1998LLVMValueRef LLVMGetBasicBlockParent(LLVMBasicBlockRef BB); 1999 2000/** 2001 * Obtain the terminator instruction for a basic block. 2002 * 2003 * If the basic block does not have a terminator (it is not well-formed 2004 * if it doesn't), then NULL is returned. 2005 * 2006 * The returned LLVMValueRef corresponds to a llvm::TerminatorInst. 2007 * 2008 * @see llvm::BasicBlock::getTerminator() 2009 */ 2010LLVMValueRef LLVMGetBasicBlockTerminator(LLVMBasicBlockRef BB); 2011 2012/** 2013 * Obtain the number of basic blocks in a function. 2014 * 2015 * @param Fn Function value to operate on. 2016 */ 2017unsigned LLVMCountBasicBlocks(LLVMValueRef Fn); 2018 2019/** 2020 * Obtain all of the basic blocks in a function. 2021 * 2022 * This operates on a function value. The BasicBlocks parameter is a 2023 * pointer to a pre-allocated array of LLVMBasicBlockRef of at least 2024 * LLVMCountBasicBlocks() in length. This array is populated with 2025 * LLVMBasicBlockRef instances. 2026 */ 2027void LLVMGetBasicBlocks(LLVMValueRef Fn, LLVMBasicBlockRef *BasicBlocks); 2028 2029/** 2030 * Obtain the first basic block in a function. 2031 * 2032 * The returned basic block can be used as an iterator. You will likely 2033 * eventually call into LLVMGetNextBasicBlock() with it. 2034 * 2035 * @see llvm::Function::begin() 2036 */ 2037LLVMBasicBlockRef LLVMGetFirstBasicBlock(LLVMValueRef Fn); 2038 2039/** 2040 * Obtain the last basic block in a function. 2041 * 2042 * @see llvm::Function::end() 2043 */ 2044LLVMBasicBlockRef LLVMGetLastBasicBlock(LLVMValueRef Fn); 2045 2046/** 2047 * Advance a basic block iterator. 2048 */ 2049LLVMBasicBlockRef LLVMGetNextBasicBlock(LLVMBasicBlockRef BB); 2050 2051/** 2052 * Go backwards in a basic block iterator. 2053 */ 2054LLVMBasicBlockRef LLVMGetPreviousBasicBlock(LLVMBasicBlockRef BB); 2055 2056/** 2057 * Obtain the basic block that corresponds to the entry point of a 2058 * function. 2059 * 2060 * @see llvm::Function::getEntryBlock() 2061 */ 2062LLVMBasicBlockRef LLVMGetEntryBasicBlock(LLVMValueRef Fn); 2063 2064/** 2065 * Append a basic block to the end of a function. 2066 * 2067 * @see llvm::BasicBlock::Create() 2068 */ 2069LLVMBasicBlockRef LLVMAppendBasicBlockInContext(LLVMContextRef C, 2070 LLVMValueRef Fn, 2071 const char *Name); 2072 2073/** 2074 * Append a basic block to the end of a function using the global 2075 * context. 2076 * 2077 * @see llvm::BasicBlock::Create() 2078 */ 2079LLVMBasicBlockRef LLVMAppendBasicBlock(LLVMValueRef Fn, const char *Name); 2080 2081/** 2082 * Insert a basic block in a function before another basic block. 2083 * 2084 * The function to add to is determined by the function of the 2085 * passed basic block. 2086 * 2087 * @see llvm::BasicBlock::Create() 2088 */ 2089LLVMBasicBlockRef LLVMInsertBasicBlockInContext(LLVMContextRef C, 2090 LLVMBasicBlockRef BB, 2091 const char *Name); 2092 2093/** 2094 * Insert a basic block in a function using the global context. 2095 * 2096 * @see llvm::BasicBlock::Create() 2097 */ 2098LLVMBasicBlockRef LLVMInsertBasicBlock(LLVMBasicBlockRef InsertBeforeBB, 2099 const char *Name); 2100 2101/** 2102 * Remove a basic block from a function and delete it. 2103 * 2104 * This deletes the basic block from its containing function and deletes 2105 * the basic block itself. 2106 * 2107 * @see llvm::BasicBlock::eraseFromParent() 2108 */ 2109void LLVMDeleteBasicBlock(LLVMBasicBlockRef BB); 2110 2111/** 2112 * Remove a basic block from a function. 2113 * 2114 * This deletes the basic block from its containing function but keep 2115 * the basic block alive. 2116 * 2117 * @see llvm::BasicBlock::removeFromParent() 2118 */ 2119void LLVMRemoveBasicBlockFromParent(LLVMBasicBlockRef BB); 2120 2121/** 2122 * Move a basic block to before another one. 2123 * 2124 * @see llvm::BasicBlock::moveBefore() 2125 */ 2126void LLVMMoveBasicBlockBefore(LLVMBasicBlockRef BB, LLVMBasicBlockRef MovePos); 2127 2128/** 2129 * Move a basic block to after another one. 2130 * 2131 * @see llvm::BasicBlock::moveAfter() 2132 */ 2133void LLVMMoveBasicBlockAfter(LLVMBasicBlockRef BB, LLVMBasicBlockRef MovePos); 2134 2135/** 2136 * Obtain the first instruction in a basic block. 2137 * 2138 * The returned LLVMValueRef corresponds to a llvm::Instruction 2139 * instance. 2140 */ 2141LLVMValueRef LLVMGetFirstInstruction(LLVMBasicBlockRef BB); 2142 2143/** 2144 * Obtain the last instruction in a basic block. 2145 * 2146 * The returned LLVMValueRef corresponds to an LLVM:Instruction. 2147 */ 2148LLVMValueRef LLVMGetLastInstruction(LLVMBasicBlockRef BB); 2149 2150/** 2151 * @} 2152 */ 2153 2154/** 2155 * @defgroup LLVMCCoreValueInstruction Instructions 2156 * 2157 * Functions in this group relate to the inspection and manipulation of 2158 * individual instructions. 2159 * 2160 * In the C++ API, an instruction is modeled by llvm::Instruction. This 2161 * class has a large number of descendents. llvm::Instruction is a 2162 * llvm::Value and in the C API, instructions are modeled by 2163 * LLVMValueRef. 2164 * 2165 * This group also contains sub-groups which operate on specific 2166 * llvm::Instruction types, e.g. llvm::CallInst. 2167 * 2168 * @{ 2169 */ 2170 2171/** 2172 * Determine whether an instruction has any metadata attached. 2173 */ 2174int LLVMHasMetadata(LLVMValueRef Val); 2175 2176/** 2177 * Return metadata associated with an instruction value. 2178 */ 2179LLVMValueRef LLVMGetMetadata(LLVMValueRef Val, unsigned KindID); 2180 2181/** 2182 * Set metadata associated with an instruction value. 2183 */ 2184void LLVMSetMetadata(LLVMValueRef Val, unsigned KindID, LLVMValueRef Node); 2185 2186/** 2187 * Obtain the basic block to which an instruction belongs. 2188 * 2189 * @see llvm::Instruction::getParent() 2190 */ 2191LLVMBasicBlockRef LLVMGetInstructionParent(LLVMValueRef Inst); 2192 2193/** 2194 * Obtain the instruction that occurs after the one specified. 2195 * 2196 * The next instruction will be from the same basic block. 2197 * 2198 * If this is the last instruction in a basic block, NULL will be 2199 * returned. 2200 */ 2201LLVMValueRef LLVMGetNextInstruction(LLVMValueRef Inst); 2202 2203/** 2204 * Obtain the instruction that occurred before this one. 2205 * 2206 * If the instruction is the first instruction in a basic block, NULL 2207 * will be returned. 2208 */ 2209LLVMValueRef LLVMGetPreviousInstruction(LLVMValueRef Inst); 2210 2211/** 2212 * Remove and delete an instruction. 2213 * 2214 * The instruction specified is removed from its containing building 2215 * block and then deleted. 2216 * 2217 * @see llvm::Instruction::eraseFromParent() 2218 */ 2219void LLVMInstructionEraseFromParent(LLVMValueRef Inst); 2220 2221/** 2222 * Obtain the code opcode for an individual instruction. 2223 * 2224 * @see llvm::Instruction::getOpCode() 2225 */ 2226LLVMOpcode LLVMGetInstructionOpcode(LLVMValueRef Inst); 2227 2228/** 2229 * Obtain the predicate of an instruction. 2230 * 2231 * This is only valid for instructions that correspond to llvm::ICmpInst 2232 * or llvm::ConstantExpr whose opcode is llvm::Instruction::ICmp. 2233 * 2234 * @see llvm::ICmpInst::getPredicate() 2235 */ 2236LLVMIntPredicate LLVMGetICmpPredicate(LLVMValueRef Inst); 2237 2238/** 2239 * @defgroup LLVMCCoreValueInstructionCall Call Sites and Invocations 2240 * 2241 * Functions in this group apply to instructions that refer to call 2242 * sites and invocations. These correspond to C++ types in the 2243 * llvm::CallInst class tree. 2244 * 2245 * @{ 2246 */ 2247 2248/** 2249 * Set the calling convention for a call instruction. 2250 * 2251 * This expects an LLVMValueRef that corresponds to a llvm::CallInst or 2252 * llvm::InvokeInst. 2253 * 2254 * @see llvm::CallInst::setCallingConv() 2255 * @see llvm::InvokeInst::setCallingConv() 2256 */ 2257void LLVMSetInstructionCallConv(LLVMValueRef Instr, unsigned CC); 2258 2259/** 2260 * Obtain the calling convention for a call instruction. 2261 * 2262 * This is the opposite of LLVMSetInstructionCallConv(). Reads its 2263 * usage. 2264 * 2265 * @see LLVMSetInstructionCallConv() 2266 */ 2267unsigned LLVMGetInstructionCallConv(LLVMValueRef Instr); 2268 2269 2270void LLVMAddInstrAttribute(LLVMValueRef Instr, unsigned index, LLVMAttribute); 2271void LLVMRemoveInstrAttribute(LLVMValueRef Instr, unsigned index, 2272 LLVMAttribute); 2273void LLVMSetInstrParamAlignment(LLVMValueRef Instr, unsigned index, 2274 unsigned align); 2275 2276/** 2277 * Obtain whether a call instruction is a tail call. 2278 * 2279 * This only works on llvm::CallInst instructions. 2280 * 2281 * @see llvm::CallInst::isTailCall() 2282 */ 2283LLVMBool LLVMIsTailCall(LLVMValueRef CallInst); 2284 2285/** 2286 * Set whether a call instruction is a tail call. 2287 * 2288 * This only works on llvm::CallInst instructions. 2289 * 2290 * @see llvm::CallInst::setTailCall() 2291 */ 2292void LLVMSetTailCall(LLVMValueRef CallInst, LLVMBool IsTailCall); 2293 2294/** 2295 * @} 2296 */ 2297 2298/** 2299 * Obtain the default destination basic block of a switch instruction. 2300 * 2301 * This only works on llvm::SwitchInst instructions. 2302 * 2303 * @see llvm::SwitchInst::getDefaultDest() 2304 */ 2305LLVMBasicBlockRef LLVMGetSwitchDefaultDest(LLVMValueRef SwitchInstr); 2306 2307/** 2308 * @defgroup LLVMCCoreValueInstructionPHINode PHI Nodes 2309 * 2310 * Functions in this group only apply to instructions that map to 2311 * llvm::PHINode instances. 2312 * 2313 * @{ 2314 */ 2315 2316/** 2317 * Add an incoming value to the end of a PHI list. 2318 */ 2319void LLVMAddIncoming(LLVMValueRef PhiNode, LLVMValueRef *IncomingValues, 2320 LLVMBasicBlockRef *IncomingBlocks, unsigned Count); 2321 2322/** 2323 * Obtain the number of incoming basic blocks to a PHI node. 2324 */ 2325unsigned LLVMCountIncoming(LLVMValueRef PhiNode); 2326 2327/** 2328 * Obtain an incoming value to a PHI node as an LLVMValueRef. 2329 */ 2330LLVMValueRef LLVMGetIncomingValue(LLVMValueRef PhiNode, unsigned Index); 2331 2332/** 2333 * Obtain an incoming value to a PHI node as an LLVMBasicBlockRef. 2334 */ 2335LLVMBasicBlockRef LLVMGetIncomingBlock(LLVMValueRef PhiNode, unsigned Index); 2336 2337/** 2338 * @} 2339 */ 2340 2341/** 2342 * @} 2343 */ 2344 2345/** 2346 * @} 2347 */ 2348 2349/** 2350 * @defgroup LLVMCCoreInstructionBuilder Instruction Builders 2351 * 2352 * An instruction builder represents a point within a basic block and is 2353 * the exclusive means of building instructions using the C interface. 2354 * 2355 * @{ 2356 */ 2357 2358LLVMBuilderRef LLVMCreateBuilderInContext(LLVMContextRef C); 2359LLVMBuilderRef LLVMCreateBuilder(void); 2360void LLVMPositionBuilder(LLVMBuilderRef Builder, LLVMBasicBlockRef Block, 2361 LLVMValueRef Instr); 2362void LLVMPositionBuilderBefore(LLVMBuilderRef Builder, LLVMValueRef Instr); 2363void LLVMPositionBuilderAtEnd(LLVMBuilderRef Builder, LLVMBasicBlockRef Block); 2364LLVMBasicBlockRef LLVMGetInsertBlock(LLVMBuilderRef Builder); 2365void LLVMClearInsertionPosition(LLVMBuilderRef Builder); 2366void LLVMInsertIntoBuilder(LLVMBuilderRef Builder, LLVMValueRef Instr); 2367void LLVMInsertIntoBuilderWithName(LLVMBuilderRef Builder, LLVMValueRef Instr, 2368 const char *Name); 2369void LLVMDisposeBuilder(LLVMBuilderRef Builder); 2370 2371/* Metadata */ 2372void LLVMSetCurrentDebugLocation(LLVMBuilderRef Builder, LLVMValueRef L); 2373LLVMValueRef LLVMGetCurrentDebugLocation(LLVMBuilderRef Builder); 2374void LLVMSetInstDebugLocation(LLVMBuilderRef Builder, LLVMValueRef Inst); 2375 2376/* Terminators */ 2377LLVMValueRef LLVMBuildRetVoid(LLVMBuilderRef); 2378LLVMValueRef LLVMBuildRet(LLVMBuilderRef, LLVMValueRef V); 2379LLVMValueRef LLVMBuildAggregateRet(LLVMBuilderRef, LLVMValueRef *RetVals, 2380 unsigned N); 2381LLVMValueRef LLVMBuildBr(LLVMBuilderRef, LLVMBasicBlockRef Dest); 2382LLVMValueRef LLVMBuildCondBr(LLVMBuilderRef, LLVMValueRef If, 2383 LLVMBasicBlockRef Then, LLVMBasicBlockRef Else); 2384LLVMValueRef LLVMBuildSwitch(LLVMBuilderRef, LLVMValueRef V, 2385 LLVMBasicBlockRef Else, unsigned NumCases); 2386LLVMValueRef LLVMBuildIndirectBr(LLVMBuilderRef B, LLVMValueRef Addr, 2387 unsigned NumDests); 2388LLVMValueRef LLVMBuildInvoke(LLVMBuilderRef, LLVMValueRef Fn, 2389 LLVMValueRef *Args, unsigned NumArgs, 2390 LLVMBasicBlockRef Then, LLVMBasicBlockRef Catch, 2391 const char *Name); 2392LLVMValueRef LLVMBuildLandingPad(LLVMBuilderRef B, LLVMTypeRef Ty, 2393 LLVMValueRef PersFn, unsigned NumClauses, 2394 const char *Name); 2395LLVMValueRef LLVMBuildResume(LLVMBuilderRef B, LLVMValueRef Exn); 2396LLVMValueRef LLVMBuildUnreachable(LLVMBuilderRef); 2397 2398/* Add a case to the switch instruction */ 2399void LLVMAddCase(LLVMValueRef Switch, LLVMValueRef OnVal, 2400 LLVMBasicBlockRef Dest); 2401 2402/* Add a destination to the indirectbr instruction */ 2403void LLVMAddDestination(LLVMValueRef IndirectBr, LLVMBasicBlockRef Dest); 2404 2405/* Add a catch or filter clause to the landingpad instruction */ 2406void LLVMAddClause(LLVMValueRef LandingPad, LLVMValueRef ClauseVal); 2407 2408/* Set the 'cleanup' flag in the landingpad instruction */ 2409void LLVMSetCleanup(LLVMValueRef LandingPad, LLVMBool Val); 2410 2411/* Arithmetic */ 2412LLVMValueRef LLVMBuildAdd(LLVMBuilderRef, LLVMValueRef LHS, LLVMValueRef RHS, 2413 const char *Name); 2414LLVMValueRef LLVMBuildNSWAdd(LLVMBuilderRef, LLVMValueRef LHS, LLVMValueRef RHS, 2415 const char *Name); 2416LLVMValueRef LLVMBuildNUWAdd(LLVMBuilderRef, LLVMValueRef LHS, LLVMValueRef RHS, 2417 const char *Name); 2418LLVMValueRef LLVMBuildFAdd(LLVMBuilderRef, LLVMValueRef LHS, LLVMValueRef RHS, 2419 const char *Name); 2420LLVMValueRef LLVMBuildSub(LLVMBuilderRef, LLVMValueRef LHS, LLVMValueRef RHS, 2421 const char *Name); 2422LLVMValueRef LLVMBuildNSWSub(LLVMBuilderRef, LLVMValueRef LHS, LLVMValueRef RHS, 2423 const char *Name); 2424LLVMValueRef LLVMBuildNUWSub(LLVMBuilderRef, LLVMValueRef LHS, LLVMValueRef RHS, 2425 const char *Name); 2426LLVMValueRef LLVMBuildFSub(LLVMBuilderRef, LLVMValueRef LHS, LLVMValueRef RHS, 2427 const char *Name); 2428LLVMValueRef LLVMBuildMul(LLVMBuilderRef, LLVMValueRef LHS, LLVMValueRef RHS, 2429 const char *Name); 2430LLVMValueRef LLVMBuildNSWMul(LLVMBuilderRef, LLVMValueRef LHS, LLVMValueRef RHS, 2431 const char *Name); 2432LLVMValueRef LLVMBuildNUWMul(LLVMBuilderRef, LLVMValueRef LHS, LLVMValueRef RHS, 2433 const char *Name); 2434LLVMValueRef LLVMBuildFMul(LLVMBuilderRef, LLVMValueRef LHS, LLVMValueRef RHS, 2435 const char *Name); 2436LLVMValueRef LLVMBuildUDiv(LLVMBuilderRef, LLVMValueRef LHS, LLVMValueRef RHS, 2437 const char *Name); 2438LLVMValueRef LLVMBuildSDiv(LLVMBuilderRef, LLVMValueRef LHS, LLVMValueRef RHS, 2439 const char *Name); 2440LLVMValueRef LLVMBuildExactSDiv(LLVMBuilderRef, LLVMValueRef LHS, LLVMValueRef RHS, 2441 const char *Name); 2442LLVMValueRef LLVMBuildFDiv(LLVMBuilderRef, LLVMValueRef LHS, LLVMValueRef RHS, 2443 const char *Name); 2444LLVMValueRef LLVMBuildURem(LLVMBuilderRef, LLVMValueRef LHS, LLVMValueRef RHS, 2445 const char *Name); 2446LLVMValueRef LLVMBuildSRem(LLVMBuilderRef, LLVMValueRef LHS, LLVMValueRef RHS, 2447 const char *Name); 2448LLVMValueRef LLVMBuildFRem(LLVMBuilderRef, LLVMValueRef LHS, LLVMValueRef RHS, 2449 const char *Name); 2450LLVMValueRef LLVMBuildShl(LLVMBuilderRef, LLVMValueRef LHS, LLVMValueRef RHS, 2451 const char *Name); 2452LLVMValueRef LLVMBuildLShr(LLVMBuilderRef, LLVMValueRef LHS, LLVMValueRef RHS, 2453 const char *Name); 2454LLVMValueRef LLVMBuildAShr(LLVMBuilderRef, LLVMValueRef LHS, LLVMValueRef RHS, 2455 const char *Name); 2456LLVMValueRef LLVMBuildAnd(LLVMBuilderRef, LLVMValueRef LHS, LLVMValueRef RHS, 2457 const char *Name); 2458LLVMValueRef LLVMBuildOr(LLVMBuilderRef, LLVMValueRef LHS, LLVMValueRef RHS, 2459 const char *Name); 2460LLVMValueRef LLVMBuildXor(LLVMBuilderRef, LLVMValueRef LHS, LLVMValueRef RHS, 2461 const char *Name); 2462LLVMValueRef LLVMBuildBinOp(LLVMBuilderRef B, LLVMOpcode Op, 2463 LLVMValueRef LHS, LLVMValueRef RHS, 2464 const char *Name); 2465LLVMValueRef LLVMBuildNeg(LLVMBuilderRef, LLVMValueRef V, const char *Name); 2466LLVMValueRef LLVMBuildNSWNeg(LLVMBuilderRef B, LLVMValueRef V, 2467 const char *Name); 2468LLVMValueRef LLVMBuildNUWNeg(LLVMBuilderRef B, LLVMValueRef V, 2469 const char *Name); 2470LLVMValueRef LLVMBuildFNeg(LLVMBuilderRef, LLVMValueRef V, const char *Name); 2471LLVMValueRef LLVMBuildNot(LLVMBuilderRef, LLVMValueRef V, const char *Name); 2472 2473/* Memory */ 2474LLVMValueRef LLVMBuildMalloc(LLVMBuilderRef, LLVMTypeRef Ty, const char *Name); 2475LLVMValueRef LLVMBuildArrayMalloc(LLVMBuilderRef, LLVMTypeRef Ty, 2476 LLVMValueRef Val, const char *Name); 2477LLVMValueRef LLVMBuildAlloca(LLVMBuilderRef, LLVMTypeRef Ty, const char *Name); 2478LLVMValueRef LLVMBuildArrayAlloca(LLVMBuilderRef, LLVMTypeRef Ty, 2479 LLVMValueRef Val, const char *Name); 2480LLVMValueRef LLVMBuildFree(LLVMBuilderRef, LLVMValueRef PointerVal); 2481LLVMValueRef LLVMBuildLoad(LLVMBuilderRef, LLVMValueRef PointerVal, 2482 const char *Name); 2483LLVMValueRef LLVMBuildStore(LLVMBuilderRef, LLVMValueRef Val, LLVMValueRef Ptr); 2484LLVMValueRef LLVMBuildGEP(LLVMBuilderRef B, LLVMValueRef Pointer, 2485 LLVMValueRef *Indices, unsigned NumIndices, 2486 const char *Name); 2487LLVMValueRef LLVMBuildInBoundsGEP(LLVMBuilderRef B, LLVMValueRef Pointer, 2488 LLVMValueRef *Indices, unsigned NumIndices, 2489 const char *Name); 2490LLVMValueRef LLVMBuildStructGEP(LLVMBuilderRef B, LLVMValueRef Pointer, 2491 unsigned Idx, const char *Name); 2492LLVMValueRef LLVMBuildGlobalString(LLVMBuilderRef B, const char *Str, 2493 const char *Name); 2494LLVMValueRef LLVMBuildGlobalStringPtr(LLVMBuilderRef B, const char *Str, 2495 const char *Name); 2496LLVMBool LLVMGetVolatile(LLVMValueRef MemoryAccessInst); 2497void LLVMSetVolatile(LLVMValueRef MemoryAccessInst, LLVMBool IsVolatile); 2498 2499/* Casts */ 2500LLVMValueRef LLVMBuildTrunc(LLVMBuilderRef, LLVMValueRef Val, 2501 LLVMTypeRef DestTy, const char *Name); 2502LLVMValueRef LLVMBuildZExt(LLVMBuilderRef, LLVMValueRef Val, 2503 LLVMTypeRef DestTy, const char *Name); 2504LLVMValueRef LLVMBuildSExt(LLVMBuilderRef, LLVMValueRef Val, 2505 LLVMTypeRef DestTy, const char *Name); 2506LLVMValueRef LLVMBuildFPToUI(LLVMBuilderRef, LLVMValueRef Val, 2507 LLVMTypeRef DestTy, const char *Name); 2508LLVMValueRef LLVMBuildFPToSI(LLVMBuilderRef, LLVMValueRef Val, 2509 LLVMTypeRef DestTy, const char *Name); 2510LLVMValueRef LLVMBuildUIToFP(LLVMBuilderRef, LLVMValueRef Val, 2511 LLVMTypeRef DestTy, const char *Name); 2512LLVMValueRef LLVMBuildSIToFP(LLVMBuilderRef, LLVMValueRef Val, 2513 LLVMTypeRef DestTy, const char *Name); 2514LLVMValueRef LLVMBuildFPTrunc(LLVMBuilderRef, LLVMValueRef Val, 2515 LLVMTypeRef DestTy, const char *Name); 2516LLVMValueRef LLVMBuildFPExt(LLVMBuilderRef, LLVMValueRef Val, 2517 LLVMTypeRef DestTy, const char *Name); 2518LLVMValueRef LLVMBuildPtrToInt(LLVMBuilderRef, LLVMValueRef Val, 2519 LLVMTypeRef DestTy, const char *Name); 2520LLVMValueRef LLVMBuildIntToPtr(LLVMBuilderRef, LLVMValueRef Val, 2521 LLVMTypeRef DestTy, const char *Name); 2522LLVMValueRef LLVMBuildBitCast(LLVMBuilderRef, LLVMValueRef Val, 2523 LLVMTypeRef DestTy, const char *Name); 2524LLVMValueRef LLVMBuildZExtOrBitCast(LLVMBuilderRef, LLVMValueRef Val, 2525 LLVMTypeRef DestTy, const char *Name); 2526LLVMValueRef LLVMBuildSExtOrBitCast(LLVMBuilderRef, LLVMValueRef Val, 2527 LLVMTypeRef DestTy, const char *Name); 2528LLVMValueRef LLVMBuildTruncOrBitCast(LLVMBuilderRef, LLVMValueRef Val, 2529 LLVMTypeRef DestTy, const char *Name); 2530LLVMValueRef LLVMBuildCast(LLVMBuilderRef B, LLVMOpcode Op, LLVMValueRef Val, 2531 LLVMTypeRef DestTy, const char *Name); 2532LLVMValueRef LLVMBuildPointerCast(LLVMBuilderRef, LLVMValueRef Val, 2533 LLVMTypeRef DestTy, const char *Name); 2534LLVMValueRef LLVMBuildIntCast(LLVMBuilderRef, LLVMValueRef Val, /*Signed cast!*/ 2535 LLVMTypeRef DestTy, const char *Name); 2536LLVMValueRef LLVMBuildFPCast(LLVMBuilderRef, LLVMValueRef Val, 2537 LLVMTypeRef DestTy, const char *Name); 2538 2539/* Comparisons */ 2540LLVMValueRef LLVMBuildICmp(LLVMBuilderRef, LLVMIntPredicate Op, 2541 LLVMValueRef LHS, LLVMValueRef RHS, 2542 const char *Name); 2543LLVMValueRef LLVMBuildFCmp(LLVMBuilderRef, LLVMRealPredicate Op, 2544 LLVMValueRef LHS, LLVMValueRef RHS, 2545 const char *Name); 2546 2547/* Miscellaneous instructions */ 2548LLVMValueRef LLVMBuildPhi(LLVMBuilderRef, LLVMTypeRef Ty, const char *Name); 2549LLVMValueRef LLVMBuildCall(LLVMBuilderRef, LLVMValueRef Fn, 2550 LLVMValueRef *Args, unsigned NumArgs, 2551 const char *Name); 2552LLVMValueRef LLVMBuildSelect(LLVMBuilderRef, LLVMValueRef If, 2553 LLVMValueRef Then, LLVMValueRef Else, 2554 const char *Name); 2555LLVMValueRef LLVMBuildVAArg(LLVMBuilderRef, LLVMValueRef List, LLVMTypeRef Ty, 2556 const char *Name); 2557LLVMValueRef LLVMBuildExtractElement(LLVMBuilderRef, LLVMValueRef VecVal, 2558 LLVMValueRef Index, const char *Name); 2559LLVMValueRef LLVMBuildInsertElement(LLVMBuilderRef, LLVMValueRef VecVal, 2560 LLVMValueRef EltVal, LLVMValueRef Index, 2561 const char *Name); 2562LLVMValueRef LLVMBuildShuffleVector(LLVMBuilderRef, LLVMValueRef V1, 2563 LLVMValueRef V2, LLVMValueRef Mask, 2564 const char *Name); 2565LLVMValueRef LLVMBuildExtractValue(LLVMBuilderRef, LLVMValueRef AggVal, 2566 unsigned Index, const char *Name); 2567LLVMValueRef LLVMBuildInsertValue(LLVMBuilderRef, LLVMValueRef AggVal, 2568 LLVMValueRef EltVal, unsigned Index, 2569 const char *Name); 2570 2571LLVMValueRef LLVMBuildIsNull(LLVMBuilderRef, LLVMValueRef Val, 2572 const char *Name); 2573LLVMValueRef LLVMBuildIsNotNull(LLVMBuilderRef, LLVMValueRef Val, 2574 const char *Name); 2575LLVMValueRef LLVMBuildPtrDiff(LLVMBuilderRef, LLVMValueRef LHS, 2576 LLVMValueRef RHS, const char *Name); 2577LLVMValueRef LLVMBuildAtomicRMW(LLVMBuilderRef B,LLVMAtomicRMWBinOp op, 2578 LLVMValueRef PTR, LLVMValueRef Val, 2579 LLVMAtomicOrdering ordering, 2580 LLVMBool singleThread); 2581 2582/** 2583 * @} 2584 */ 2585 2586/** 2587 * @defgroup LLVMCCoreModuleProvider Module Providers 2588 * 2589 * @{ 2590 */ 2591 2592/** 2593 * Changes the type of M so it can be passed to FunctionPassManagers and the 2594 * JIT. They take ModuleProviders for historical reasons. 2595 */ 2596LLVMModuleProviderRef 2597LLVMCreateModuleProviderForExistingModule(LLVMModuleRef M); 2598 2599/** 2600 * Destroys the module M. 2601 */ 2602void LLVMDisposeModuleProvider(LLVMModuleProviderRef M); 2603 2604/** 2605 * @} 2606 */ 2607 2608/** 2609 * @defgroup LLVMCCoreMemoryBuffers Memory Buffers 2610 * 2611 * @{ 2612 */ 2613 2614LLVMBool LLVMCreateMemoryBufferWithContentsOfFile(const char *Path, 2615 LLVMMemoryBufferRef *OutMemBuf, 2616 char **OutMessage); 2617LLVMBool LLVMCreateMemoryBufferWithSTDIN(LLVMMemoryBufferRef *OutMemBuf, 2618 char **OutMessage); 2619LLVMMemoryBufferRef LLVMCreateMemoryBufferWithMemoryRange(const char *InputData, 2620 size_t InputDataLength, 2621 const char *BufferName, 2622 LLVMBool RequiresNullTerminator); 2623LLVMMemoryBufferRef LLVMCreateMemoryBufferWithMemoryRangeCopy(const char *InputData, 2624 size_t InputDataLength, 2625 const char *BufferName); 2626const char *LLVMGetBufferStart(LLVMMemoryBufferRef MemBuf); 2627size_t LLVMGetBufferSize(LLVMMemoryBufferRef MemBuf); 2628void LLVMDisposeMemoryBuffer(LLVMMemoryBufferRef MemBuf); 2629 2630/** 2631 * @} 2632 */ 2633 2634/** 2635 * @defgroup LLVMCCorePassRegistry Pass Registry 2636 * 2637 * @{ 2638 */ 2639 2640/** Return the global pass registry, for use with initialization functions. 2641 @see llvm::PassRegistry::getPassRegistry */ 2642LLVMPassRegistryRef LLVMGetGlobalPassRegistry(void); 2643 2644/** 2645 * @} 2646 */ 2647 2648/** 2649 * @defgroup LLVMCCorePassManagers Pass Managers 2650 * 2651 * @{ 2652 */ 2653 2654/** Constructs a new whole-module pass pipeline. This type of pipeline is 2655 suitable for link-time optimization and whole-module transformations. 2656 @see llvm::PassManager::PassManager */ 2657LLVMPassManagerRef LLVMCreatePassManager(void); 2658 2659/** Constructs a new function-by-function pass pipeline over the module 2660 provider. It does not take ownership of the module provider. This type of 2661 pipeline is suitable for code generation and JIT compilation tasks. 2662 @see llvm::FunctionPassManager::FunctionPassManager */ 2663LLVMPassManagerRef LLVMCreateFunctionPassManagerForModule(LLVMModuleRef M); 2664 2665/** Deprecated: Use LLVMCreateFunctionPassManagerForModule instead. */ 2666LLVMPassManagerRef LLVMCreateFunctionPassManager(LLVMModuleProviderRef MP); 2667 2668/** Initializes, executes on the provided module, and finalizes all of the 2669 passes scheduled in the pass manager. Returns 1 if any of the passes 2670 modified the module, 0 otherwise. 2671 @see llvm::PassManager::run(Module&) */ 2672LLVMBool LLVMRunPassManager(LLVMPassManagerRef PM, LLVMModuleRef M); 2673 2674/** Initializes all of the function passes scheduled in the function pass 2675 manager. Returns 1 if any of the passes modified the module, 0 otherwise. 2676 @see llvm::FunctionPassManager::doInitialization */ 2677LLVMBool LLVMInitializeFunctionPassManager(LLVMPassManagerRef FPM); 2678 2679/** Executes all of the function passes scheduled in the function pass manager 2680 on the provided function. Returns 1 if any of the passes modified the 2681 function, false otherwise. 2682 @see llvm::FunctionPassManager::run(Function&) */ 2683LLVMBool LLVMRunFunctionPassManager(LLVMPassManagerRef FPM, LLVMValueRef F); 2684 2685/** Finalizes all of the function passes scheduled in in the function pass 2686 manager. Returns 1 if any of the passes modified the module, 0 otherwise. 2687 @see llvm::FunctionPassManager::doFinalization */ 2688LLVMBool LLVMFinalizeFunctionPassManager(LLVMPassManagerRef FPM); 2689 2690/** Frees the memory of a pass pipeline. For function pipelines, does not free 2691 the module provider. 2692 @see llvm::PassManagerBase::~PassManagerBase. */ 2693void LLVMDisposePassManager(LLVMPassManagerRef PM); 2694 2695/** 2696 * @} 2697 */ 2698 2699/** 2700 * @defgroup LLVMCCoreThreading Threading 2701 * 2702 * Handle the structures needed to make LLVM safe for multithreading. 2703 * 2704 * @{ 2705 */ 2706 2707/** Allocate and initialize structures needed to make LLVM safe for 2708 multithreading. The return value indicates whether multithreaded 2709 initialization succeeded. Must be executed in isolation from all 2710 other LLVM api calls. 2711 @see llvm::llvm_start_multithreaded */ 2712LLVMBool LLVMStartMultithreaded(); 2713 2714/** Deallocate structures necessary to make LLVM safe for multithreading. 2715 Must be executed in isolation from all other LLVM api calls. 2716 @see llvm::llvm_stop_multithreaded */ 2717void LLVMStopMultithreaded(); 2718 2719/** Check whether LLVM is executing in thread-safe mode or not. 2720 @see llvm::llvm_is_multithreaded */ 2721LLVMBool LLVMIsMultithreaded(); 2722 2723/** 2724 * @} 2725 */ 2726 2727/** 2728 * @} 2729 */ 2730 2731/** 2732 * @} 2733 */ 2734 2735#ifdef __cplusplus 2736} 2737#endif /* !defined(__cplusplus) */ 2738 2739#endif /* !defined(LLVM_C_CORE_H) */ 2740