Core.h revision 210299
1278277Sgonzo/*===-- llvm-c/Core.h - Core Library C Interface ------------------*- C -*-===*\ 2290245Sgonzo|* *| 3278277Sgonzo|* The LLVM Compiler Infrastructure *| 4278277Sgonzo|* *| 5278277Sgonzo|* This file is distributed under the University of Illinois Open Source *| 6278277Sgonzo|* License. See LICENSE.TXT for details. *| 7278277Sgonzo|* *| 8278277Sgonzo|*===----------------------------------------------------------------------===*| 9278277Sgonzo|* *| 10278277Sgonzo|* This header declares the C interface to libLLVMCore.a, which implements *| 11278277Sgonzo|* the LLVM intermediate representation. *| 12278277Sgonzo|* *| 13278277Sgonzo|* LLVM uses a polymorphic type hierarchy which C cannot represent, therefore *| 14278277Sgonzo|* parameters must be passed as base types. Despite the declared types, most *| 15278277Sgonzo|* of the functions provided operate only on branches of the type hierarchy. *| 16278277Sgonzo|* The declared parameter names are descriptive and specify which type is *| 17278277Sgonzo|* required. Additionally, each type hierarchy is documented along with the *| 18278277Sgonzo|* functions that operate upon it. For more detail, refer to LLVM's C++ code. *| 19278277Sgonzo|* If in doubt, refer to Core.cpp, which performs paramter downcasts in the *| 20278277Sgonzo|* form unwrap<RequiredType>(Param). *| 21278277Sgonzo|* *| 22278277Sgonzo|* Many exotic languages can interoperate with C code but have a harder time *| 23278277Sgonzo|* with C++ due to name mangling. So in addition to C, this interface enables *| 24278277Sgonzo|* tools written in such languages. *| 25278277Sgonzo|* *| 26278277Sgonzo|* When included into a C++ source file, also declares 'wrap' and 'unwrap' *| 27278277Sgonzo|* helpers to perform opaque reference<-->pointer conversions. These helpers *| 28278277Sgonzo|* are shorter and more tightly typed than writing the casts by hand when *| 29278277Sgonzo|* authoring bindings. In assert builds, they will do runtime type checking. *| 30278277Sgonzo|* *| 31278277Sgonzo\*===----------------------------------------------------------------------===*/ 32278277Sgonzo 33278277Sgonzo#ifndef LLVM_C_CORE_H 34278277Sgonzo#define LLVM_C_CORE_H 35278277Sgonzo 36278277Sgonzo#include "llvm/System/DataTypes.h" 37278277Sgonzo 38278277Sgonzo#ifdef __cplusplus 39278277Sgonzo 40278277Sgonzo/* Need these includes to support the LLVM 'cast' template for the C++ 'wrap' 41278277Sgonzo and 'unwrap' conversion functions. */ 42278277Sgonzo#include "llvm/Module.h" 43278277Sgonzo#include "llvm/Support/IRBuilder.h" 44278277Sgonzo 45278277Sgonzoextern "C" { 46278277Sgonzo#endif 47278277Sgonzo 48278277Sgonzo 49278277Sgonzotypedef int LLVMBool; 50278277Sgonzo 51278277Sgonzo/* Opaque types. */ 52278277Sgonzo 53278277Sgonzo/** 54278277Sgonzo * The top-level container for all LLVM global data. See the LLVMContext class. 55278277Sgonzo */ 56278277Sgonzotypedef struct LLVMOpaqueContext *LLVMContextRef; 57278277Sgonzo 58278277Sgonzo/** 59278277Sgonzo * The top-level container for all other LLVM Intermediate Representation (IR) 60278277Sgonzo * objects. See the llvm::Module class. 61278277Sgonzo */ 62278277Sgonzotypedef struct LLVMOpaqueModule *LLVMModuleRef; 63278277Sgonzo 64278277Sgonzo/** 65278277Sgonzo * Each value in the LLVM IR has a type, an LLVMTypeRef. See the llvm::Type 66278277Sgonzo * class. 67278277Sgonzo */ 68278277Sgonzotypedef struct LLVMOpaqueType *LLVMTypeRef; 69278277Sgonzo 70278277Sgonzo/** 71278277Sgonzo * When building recursive types using LLVMRefineType, LLVMTypeRef values may 72278277Sgonzo * become invalid; use LLVMTypeHandleRef to resolve this problem. See the 73278277Sgonzo * llvm::AbstractTypeHolder class. 74278277Sgonzo */ 75278277Sgonzotypedef struct LLVMOpaqueTypeHandle *LLVMTypeHandleRef; 76278277Sgonzo 77278277Sgonzotypedef struct LLVMOpaqueValue *LLVMValueRef; 78278277Sgonzotypedef struct LLVMOpaqueBasicBlock *LLVMBasicBlockRef; 79278277Sgonzotypedef struct LLVMOpaqueBuilder *LLVMBuilderRef; 80278277Sgonzo 81278277Sgonzo/* Interface used to provide a module to JIT or interpreter. This is now just a 82278277Sgonzo * synonym for llvm::Module, but we have to keep using the different type to 83278277Sgonzo * keep binary compatibility. 84278277Sgonzo */ 85278277Sgonzotypedef struct LLVMOpaqueModuleProvider *LLVMModuleProviderRef; 86278277Sgonzo 87278277Sgonzo/* Used to provide a module to JIT or interpreter. 88278277Sgonzo * See the llvm::MemoryBuffer class. 89278277Sgonzo */ 90278277Sgonzotypedef struct LLVMOpaqueMemoryBuffer *LLVMMemoryBufferRef; 91278277Sgonzo 92278277Sgonzo/** See the llvm::PassManagerBase class. */ 93278277Sgonzotypedef struct LLVMOpaquePassManager *LLVMPassManagerRef; 94278277Sgonzo 95278277Sgonzo/** Used to get the users and usees of a Value. See the llvm::Use class. */ 96278277Sgonzotypedef struct LLVMOpaqueUse *LLVMUseRef; 97278277Sgonzo 98278277Sgonzotypedef enum { 99278277Sgonzo LLVMZExtAttribute = 1<<0, 100278277Sgonzo LLVMSExtAttribute = 1<<1, 101278277Sgonzo LLVMNoReturnAttribute = 1<<2, 102278277Sgonzo LLVMInRegAttribute = 1<<3, 103278277Sgonzo LLVMStructRetAttribute = 1<<4, 104278277Sgonzo LLVMNoUnwindAttribute = 1<<5, 105278277Sgonzo LLVMNoAliasAttribute = 1<<6, 106278277Sgonzo LLVMByValAttribute = 1<<7, 107278277Sgonzo LLVMNestAttribute = 1<<8, 108278277Sgonzo LLVMReadNoneAttribute = 1<<9, 109278277Sgonzo LLVMReadOnlyAttribute = 1<<10, 110278277Sgonzo LLVMNoInlineAttribute = 1<<11, 111278277Sgonzo LLVMAlwaysInlineAttribute = 1<<12, 112278277Sgonzo LLVMOptimizeForSizeAttribute = 1<<13, 113278277Sgonzo LLVMStackProtectAttribute = 1<<14, 114278277Sgonzo LLVMStackProtectReqAttribute = 1<<15, 115278277Sgonzo LLVMAlignment = 31<<16, 116278277Sgonzo LLVMNoCaptureAttribute = 1<<21, 117278277Sgonzo LLVMNoRedZoneAttribute = 1<<22, 118278277Sgonzo LLVMNoImplicitFloatAttribute = 1<<23, 119278277Sgonzo LLVMNakedAttribute = 1<<24, 120278277Sgonzo LLVMInlineHintAttribute = 1<<25, 121278277Sgonzo LLVMStackAlignment = 7<<26 122278277Sgonzo} LLVMAttribute; 123278277Sgonzo 124278277Sgonzotypedef enum { 125278277Sgonzo /* Terminator Instructions */ 126278277Sgonzo LLVMRet = 1, 127278277Sgonzo LLVMBr = 2, 128278277Sgonzo LLVMSwitch = 3, 129278277Sgonzo LLVMIndirectBr = 4, 130278277Sgonzo LLVMInvoke = 5, 131278277Sgonzo LLVMUnwind = 6, 132278277Sgonzo LLVMUnreachable = 7, 133278277Sgonzo 134278277Sgonzo /* Standard Binary Operators */ 135278277Sgonzo LLVMAdd = 8, 136278277Sgonzo LLVMFAdd = 9, 137278277Sgonzo LLVMSub = 10, 138278277Sgonzo LLVMFSub = 11, 139278277Sgonzo LLVMMul = 12, 140278277Sgonzo LLVMFMul = 13, 141278277Sgonzo LLVMUDiv = 14, 142278277Sgonzo LLVMSDiv = 15, 143278277Sgonzo LLVMFDiv = 16, 144278277Sgonzo LLVMURem = 17, 145278277Sgonzo LLVMSRem = 18, 146278277Sgonzo LLVMFRem = 19, 147278277Sgonzo 148278277Sgonzo /* Logical Operators */ 149278277Sgonzo LLVMShl = 20, 150278277Sgonzo LLVMLShr = 21, 151278277Sgonzo LLVMAShr = 22, 152278277Sgonzo LLVMAnd = 23, 153278277Sgonzo LLVMOr = 24, 154278277Sgonzo LLVMXor = 25, 155278277Sgonzo 156278277Sgonzo /* Memory Operators */ 157290245Sgonzo LLVMAlloca = 26, 158290245Sgonzo LLVMLoad = 27, 159290245Sgonzo LLVMStore = 28, 160278277Sgonzo LLVMGetElementPtr = 29, 161278277Sgonzo 162278277Sgonzo /* Cast Operators */ 163278277Sgonzo LLVMTrunc = 30, 164278277Sgonzo LLVMZExt = 31, 165278277Sgonzo LLVMSExt = 32, 166278277Sgonzo LLVMFPToUI = 33, 167278277Sgonzo LLVMFPToSI = 34, 168278277Sgonzo LLVMUIToFP = 35, 169278277Sgonzo LLVMSIToFP = 36, 170278277Sgonzo LLVMFPTrunc = 37, 171278277Sgonzo LLVMFPExt = 38, 172278277Sgonzo LLVMPtrToInt = 39, 173278277Sgonzo LLVMIntToPtr = 40, 174278277Sgonzo LLVMBitCast = 41, 175278277Sgonzo 176278277Sgonzo /* Other Operators */ 177278277Sgonzo LLVMICmp = 42, 178278277Sgonzo LLVMFCmp = 43, 179278277Sgonzo LLVMPHI = 44, 180278277Sgonzo LLVMCall = 45, 181278277Sgonzo LLVMSelect = 46, 182278277Sgonzo /* UserOp1 */ 183278277Sgonzo /* UserOp2 */ 184278277Sgonzo LLVMVAArg = 49, 185278277Sgonzo LLVMExtractElement = 50, 186278277Sgonzo LLVMInsertElement = 51, 187290245Sgonzo LLVMShuffleVector = 52, 188290245Sgonzo LLVMExtractValue = 53, 189290245Sgonzo LLVMInsertValue = 54 190290245Sgonzo} LLVMOpcode; 191290245Sgonzo 192290245Sgonzotypedef enum { 193290245Sgonzo LLVMVoidTypeKind, /**< type with no size */ 194290245Sgonzo LLVMFloatTypeKind, /**< 32 bit floating point type */ 195290245Sgonzo LLVMDoubleTypeKind, /**< 64 bit floating point type */ 196290245Sgonzo LLVMX86_FP80TypeKind, /**< 80 bit floating point type (X87) */ 197290245Sgonzo LLVMFP128TypeKind, /**< 128 bit floating point type (112-bit mantissa)*/ 198290245Sgonzo LLVMPPC_FP128TypeKind, /**< 128 bit floating point type (two 64-bits) */ 199290245Sgonzo LLVMLabelTypeKind, /**< Labels */ 200290245Sgonzo LLVMIntegerTypeKind, /**< Arbitrary bit width integers */ 201290245Sgonzo LLVMFunctionTypeKind, /**< Functions */ 202290245Sgonzo LLVMStructTypeKind, /**< Structures */ 203290245Sgonzo LLVMArrayTypeKind, /**< Arrays */ 204290245Sgonzo LLVMPointerTypeKind, /**< Pointers */ 205278277Sgonzo LLVMOpaqueTypeKind, /**< Opaque: type with unknown structure */ 206278277Sgonzo LLVMVectorTypeKind, /**< SIMD 'packed' format, or other vector type */ 207278277Sgonzo LLVMMetadataTypeKind, /**< Metadata */ 208290245Sgonzo LLVMUnionTypeKind /**< Unions */ 209278277Sgonzo} LLVMTypeKind; 210278277Sgonzo 211278277Sgonzotypedef enum { 212290245Sgonzo LLVMExternalLinkage, /**< Externally visible function */ 213278277Sgonzo LLVMAvailableExternallyLinkage, 214278277Sgonzo LLVMLinkOnceAnyLinkage, /**< Keep one copy of function when linking (inline)*/ 215278277Sgonzo LLVMLinkOnceODRLinkage, /**< Same, but only replaced by something 216 equivalent. */ 217 LLVMWeakAnyLinkage, /**< Keep one copy of function when linking (weak) */ 218 LLVMWeakODRLinkage, /**< Same, but only replaced by something 219 equivalent. */ 220 LLVMAppendingLinkage, /**< Special purpose, only applies to global arrays */ 221 LLVMInternalLinkage, /**< Rename collisions when linking (static 222 functions) */ 223 LLVMPrivateLinkage, /**< Like Internal, but omit from symbol table */ 224 LLVMDLLImportLinkage, /**< Function to be imported from DLL */ 225 LLVMDLLExportLinkage, /**< Function to be accessible from DLL */ 226 LLVMExternalWeakLinkage,/**< ExternalWeak linkage description */ 227 LLVMGhostLinkage, /**< Obsolete */ 228 LLVMCommonLinkage, /**< Tentative definitions */ 229 LLVMLinkerPrivateLinkage, /**< Like Private, but linker removes. */ 230 LLVMLinkerPrivateWeakLinkage /**< Like LinkerPrivate, but is weak. */ 231} LLVMLinkage; 232 233typedef enum { 234 LLVMDefaultVisibility, /**< The GV is visible */ 235 LLVMHiddenVisibility, /**< The GV is hidden */ 236 LLVMProtectedVisibility /**< The GV is protected */ 237} LLVMVisibility; 238 239typedef enum { 240 LLVMCCallConv = 0, 241 LLVMFastCallConv = 8, 242 LLVMColdCallConv = 9, 243 LLVMX86StdcallCallConv = 64, 244 LLVMX86FastcallCallConv = 65 245} LLVMCallConv; 246 247typedef enum { 248 LLVMIntEQ = 32, /**< equal */ 249 LLVMIntNE, /**< not equal */ 250 LLVMIntUGT, /**< unsigned greater than */ 251 LLVMIntUGE, /**< unsigned greater or equal */ 252 LLVMIntULT, /**< unsigned less than */ 253 LLVMIntULE, /**< unsigned less or equal */ 254 LLVMIntSGT, /**< signed greater than */ 255 LLVMIntSGE, /**< signed greater or equal */ 256 LLVMIntSLT, /**< signed less than */ 257 LLVMIntSLE /**< signed less or equal */ 258} LLVMIntPredicate; 259 260typedef enum { 261 LLVMRealPredicateFalse, /**< Always false (always folded) */ 262 LLVMRealOEQ, /**< True if ordered and equal */ 263 LLVMRealOGT, /**< True if ordered and greater than */ 264 LLVMRealOGE, /**< True if ordered and greater than or equal */ 265 LLVMRealOLT, /**< True if ordered and less than */ 266 LLVMRealOLE, /**< True if ordered and less than or equal */ 267 LLVMRealONE, /**< True if ordered and operands are unequal */ 268 LLVMRealORD, /**< True if ordered (no nans) */ 269 LLVMRealUNO, /**< True if unordered: isnan(X) | isnan(Y) */ 270 LLVMRealUEQ, /**< True if unordered or equal */ 271 LLVMRealUGT, /**< True if unordered or greater than */ 272 LLVMRealUGE, /**< True if unordered, greater than, or equal */ 273 LLVMRealULT, /**< True if unordered or less than */ 274 LLVMRealULE, /**< True if unordered, less than, or equal */ 275 LLVMRealUNE, /**< True if unordered or not equal */ 276 LLVMRealPredicateTrue /**< Always true (always folded) */ 277} LLVMRealPredicate; 278 279 280/*===-- Error handling ----------------------------------------------------===*/ 281 282void LLVMDisposeMessage(char *Message); 283 284 285/*===-- Contexts ----------------------------------------------------------===*/ 286 287/* Create and destroy contexts. */ 288LLVMContextRef LLVMContextCreate(void); 289LLVMContextRef LLVMGetGlobalContext(void); 290void LLVMContextDispose(LLVMContextRef C); 291 292unsigned LLVMGetMDKindIDInContext(LLVMContextRef C, const char* Name, 293 unsigned SLen); 294unsigned LLVMGetMDKindID(const char* Name, unsigned SLen); 295 296/*===-- Modules -----------------------------------------------------------===*/ 297 298/* Create and destroy modules. */ 299/** See llvm::Module::Module. */ 300LLVMModuleRef LLVMModuleCreateWithName(const char *ModuleID); 301LLVMModuleRef LLVMModuleCreateWithNameInContext(const char *ModuleID, 302 LLVMContextRef C); 303 304/** See llvm::Module::~Module. */ 305void LLVMDisposeModule(LLVMModuleRef M); 306 307/** Data layout. See Module::getDataLayout. */ 308const char *LLVMGetDataLayout(LLVMModuleRef M); 309void LLVMSetDataLayout(LLVMModuleRef M, const char *Triple); 310 311/** Target triple. See Module::getTargetTriple. */ 312const char *LLVMGetTarget(LLVMModuleRef M); 313void LLVMSetTarget(LLVMModuleRef M, const char *Triple); 314 315/** See Module::addTypeName. */ 316LLVMBool LLVMAddTypeName(LLVMModuleRef M, const char *Name, LLVMTypeRef Ty); 317void LLVMDeleteTypeName(LLVMModuleRef M, const char *Name); 318LLVMTypeRef LLVMGetTypeByName(LLVMModuleRef M, const char *Name); 319 320/** See Module::dump. */ 321void LLVMDumpModule(LLVMModuleRef M); 322 323/** See Module::setModuleInlineAsm. */ 324void LLVMSetModuleInlineAsm(LLVMModuleRef M, const char *Asm); 325 326/*===-- Types -------------------------------------------------------------===*/ 327 328/* LLVM types conform to the following hierarchy: 329 * 330 * types: 331 * integer type 332 * real type 333 * function type 334 * sequence types: 335 * array type 336 * pointer type 337 * vector type 338 * void type 339 * label type 340 * opaque type 341 */ 342 343/** See llvm::LLVMTypeKind::getTypeID. */ 344LLVMTypeKind LLVMGetTypeKind(LLVMTypeRef Ty); 345 346/** See llvm::LLVMType::getContext. */ 347LLVMContextRef LLVMGetTypeContext(LLVMTypeRef Ty); 348 349/* Operations on integer types */ 350LLVMTypeRef LLVMInt1TypeInContext(LLVMContextRef C); 351LLVMTypeRef LLVMInt8TypeInContext(LLVMContextRef C); 352LLVMTypeRef LLVMInt16TypeInContext(LLVMContextRef C); 353LLVMTypeRef LLVMInt32TypeInContext(LLVMContextRef C); 354LLVMTypeRef LLVMInt64TypeInContext(LLVMContextRef C); 355LLVMTypeRef LLVMIntTypeInContext(LLVMContextRef C, unsigned NumBits); 356 357LLVMTypeRef LLVMInt1Type(void); 358LLVMTypeRef LLVMInt8Type(void); 359LLVMTypeRef LLVMInt16Type(void); 360LLVMTypeRef LLVMInt32Type(void); 361LLVMTypeRef LLVMInt64Type(void); 362LLVMTypeRef LLVMIntType(unsigned NumBits); 363unsigned LLVMGetIntTypeWidth(LLVMTypeRef IntegerTy); 364 365/* Operations on real types */ 366LLVMTypeRef LLVMFloatTypeInContext(LLVMContextRef C); 367LLVMTypeRef LLVMDoubleTypeInContext(LLVMContextRef C); 368LLVMTypeRef LLVMX86FP80TypeInContext(LLVMContextRef C); 369LLVMTypeRef LLVMFP128TypeInContext(LLVMContextRef C); 370LLVMTypeRef LLVMPPCFP128TypeInContext(LLVMContextRef C); 371 372LLVMTypeRef LLVMFloatType(void); 373LLVMTypeRef LLVMDoubleType(void); 374LLVMTypeRef LLVMX86FP80Type(void); 375LLVMTypeRef LLVMFP128Type(void); 376LLVMTypeRef LLVMPPCFP128Type(void); 377 378/* Operations on function types */ 379LLVMTypeRef LLVMFunctionType(LLVMTypeRef ReturnType, 380 LLVMTypeRef *ParamTypes, unsigned ParamCount, 381 LLVMBool IsVarArg); 382LLVMBool LLVMIsFunctionVarArg(LLVMTypeRef FunctionTy); 383LLVMTypeRef LLVMGetReturnType(LLVMTypeRef FunctionTy); 384unsigned LLVMCountParamTypes(LLVMTypeRef FunctionTy); 385void LLVMGetParamTypes(LLVMTypeRef FunctionTy, LLVMTypeRef *Dest); 386 387/* Operations on struct types */ 388LLVMTypeRef LLVMStructTypeInContext(LLVMContextRef C, LLVMTypeRef *ElementTypes, 389 unsigned ElementCount, LLVMBool Packed); 390LLVMTypeRef LLVMStructType(LLVMTypeRef *ElementTypes, unsigned ElementCount, 391 LLVMBool Packed); 392unsigned LLVMCountStructElementTypes(LLVMTypeRef StructTy); 393void LLVMGetStructElementTypes(LLVMTypeRef StructTy, LLVMTypeRef *Dest); 394LLVMBool LLVMIsPackedStruct(LLVMTypeRef StructTy); 395 396/* Operations on union types */ 397LLVMTypeRef LLVMUnionTypeInContext(LLVMContextRef C, LLVMTypeRef *ElementTypes, 398 unsigned ElementCount); 399LLVMTypeRef LLVMUnionType(LLVMTypeRef *ElementTypes, unsigned ElementCount); 400unsigned LLVMCountUnionElementTypes(LLVMTypeRef UnionTy); 401void LLVMGetUnionElementTypes(LLVMTypeRef UnionTy, LLVMTypeRef *Dest); 402 403/* Operations on array, pointer, and vector types (sequence types) */ 404LLVMTypeRef LLVMArrayType(LLVMTypeRef ElementType, unsigned ElementCount); 405LLVMTypeRef LLVMPointerType(LLVMTypeRef ElementType, unsigned AddressSpace); 406LLVMTypeRef LLVMVectorType(LLVMTypeRef ElementType, unsigned ElementCount); 407 408LLVMTypeRef LLVMGetElementType(LLVMTypeRef Ty); 409unsigned LLVMGetArrayLength(LLVMTypeRef ArrayTy); 410unsigned LLVMGetPointerAddressSpace(LLVMTypeRef PointerTy); 411unsigned LLVMGetVectorSize(LLVMTypeRef VectorTy); 412 413/* Operations on other types */ 414LLVMTypeRef LLVMVoidTypeInContext(LLVMContextRef C); 415LLVMTypeRef LLVMLabelTypeInContext(LLVMContextRef C); 416LLVMTypeRef LLVMOpaqueTypeInContext(LLVMContextRef C); 417 418LLVMTypeRef LLVMVoidType(void); 419LLVMTypeRef LLVMLabelType(void); 420LLVMTypeRef LLVMOpaqueType(void); 421 422/* Operations on type handles */ 423LLVMTypeHandleRef LLVMCreateTypeHandle(LLVMTypeRef PotentiallyAbstractTy); 424void LLVMRefineType(LLVMTypeRef AbstractTy, LLVMTypeRef ConcreteTy); 425LLVMTypeRef LLVMResolveTypeHandle(LLVMTypeHandleRef TypeHandle); 426void LLVMDisposeTypeHandle(LLVMTypeHandleRef TypeHandle); 427 428 429/*===-- Values ------------------------------------------------------------===*/ 430 431/* The bulk of LLVM's object model consists of values, which comprise a very 432 * rich type hierarchy. 433 */ 434 435#define LLVM_FOR_EACH_VALUE_SUBCLASS(macro) \ 436 macro(Argument) \ 437 macro(BasicBlock) \ 438 macro(InlineAsm) \ 439 macro(User) \ 440 macro(Constant) \ 441 macro(ConstantAggregateZero) \ 442 macro(ConstantArray) \ 443 macro(ConstantExpr) \ 444 macro(ConstantFP) \ 445 macro(ConstantInt) \ 446 macro(ConstantPointerNull) \ 447 macro(ConstantStruct) \ 448 macro(ConstantVector) \ 449 macro(GlobalValue) \ 450 macro(Function) \ 451 macro(GlobalAlias) \ 452 macro(GlobalVariable) \ 453 macro(UndefValue) \ 454 macro(Instruction) \ 455 macro(BinaryOperator) \ 456 macro(CallInst) \ 457 macro(IntrinsicInst) \ 458 macro(DbgInfoIntrinsic) \ 459 macro(DbgDeclareInst) \ 460 macro(EHSelectorInst) \ 461 macro(MemIntrinsic) \ 462 macro(MemCpyInst) \ 463 macro(MemMoveInst) \ 464 macro(MemSetInst) \ 465 macro(CmpInst) \ 466 macro(FCmpInst) \ 467 macro(ICmpInst) \ 468 macro(ExtractElementInst) \ 469 macro(GetElementPtrInst) \ 470 macro(InsertElementInst) \ 471 macro(InsertValueInst) \ 472 macro(PHINode) \ 473 macro(SelectInst) \ 474 macro(ShuffleVectorInst) \ 475 macro(StoreInst) \ 476 macro(TerminatorInst) \ 477 macro(BranchInst) \ 478 macro(InvokeInst) \ 479 macro(ReturnInst) \ 480 macro(SwitchInst) \ 481 macro(UnreachableInst) \ 482 macro(UnwindInst) \ 483 macro(UnaryInstruction) \ 484 macro(AllocaInst) \ 485 macro(CastInst) \ 486 macro(BitCastInst) \ 487 macro(FPExtInst) \ 488 macro(FPToSIInst) \ 489 macro(FPToUIInst) \ 490 macro(FPTruncInst) \ 491 macro(IntToPtrInst) \ 492 macro(PtrToIntInst) \ 493 macro(SExtInst) \ 494 macro(SIToFPInst) \ 495 macro(TruncInst) \ 496 macro(UIToFPInst) \ 497 macro(ZExtInst) \ 498 macro(ExtractValueInst) \ 499 macro(LoadInst) \ 500 macro(VAArgInst) 501 502/* Operations on all values */ 503LLVMTypeRef LLVMTypeOf(LLVMValueRef Val); 504const char *LLVMGetValueName(LLVMValueRef Val); 505void LLVMSetValueName(LLVMValueRef Val, const char *Name); 506void LLVMDumpValue(LLVMValueRef Val); 507void LLVMReplaceAllUsesWith(LLVMValueRef OldVal, LLVMValueRef NewVal); 508int LLVMHasMetadata(LLVMValueRef Val); 509LLVMValueRef LLVMGetMetadata(LLVMValueRef Val, unsigned KindID); 510void LLVMSetMetadata(LLVMValueRef Val, unsigned KindID, LLVMValueRef Node); 511 512/* Conversion functions. Return the input value if it is an instance of the 513 specified class, otherwise NULL. See llvm::dyn_cast_or_null<>. */ 514#define LLVM_DECLARE_VALUE_CAST(name) \ 515 LLVMValueRef LLVMIsA##name(LLVMValueRef Val); 516LLVM_FOR_EACH_VALUE_SUBCLASS(LLVM_DECLARE_VALUE_CAST) 517 518/* Operations on Uses */ 519LLVMUseRef LLVMGetFirstUse(LLVMValueRef Val); 520LLVMUseRef LLVMGetNextUse(LLVMUseRef U); 521LLVMValueRef LLVMGetUser(LLVMUseRef U); 522LLVMValueRef LLVMGetUsedValue(LLVMUseRef U); 523 524/* Operations on Users */ 525LLVMValueRef LLVMGetOperand(LLVMValueRef Val, unsigned Index); 526 527/* Operations on constants of any type */ 528LLVMValueRef LLVMConstNull(LLVMTypeRef Ty); /* all zeroes */ 529LLVMValueRef LLVMConstAllOnes(LLVMTypeRef Ty); /* only for int/vector */ 530LLVMValueRef LLVMGetUndef(LLVMTypeRef Ty); 531LLVMBool LLVMIsConstant(LLVMValueRef Val); 532LLVMBool LLVMIsNull(LLVMValueRef Val); 533LLVMBool LLVMIsUndef(LLVMValueRef Val); 534LLVMValueRef LLVMConstPointerNull(LLVMTypeRef Ty); 535 536/* Operations on metadata */ 537LLVMValueRef LLVMMDStringInContext(LLVMContextRef C, const char *Str, 538 unsigned SLen); 539LLVMValueRef LLVMMDString(const char *Str, unsigned SLen); 540LLVMValueRef LLVMMDNodeInContext(LLVMContextRef C, LLVMValueRef *Vals, 541 unsigned Count); 542LLVMValueRef LLVMMDNode(LLVMValueRef *Vals, unsigned Count); 543 544/* Operations on scalar constants */ 545LLVMValueRef LLVMConstInt(LLVMTypeRef IntTy, unsigned long long N, 546 LLVMBool SignExtend); 547LLVMValueRef LLVMConstIntOfString(LLVMTypeRef IntTy, const char *Text, 548 uint8_t Radix); 549LLVMValueRef LLVMConstIntOfStringAndSize(LLVMTypeRef IntTy, const char *Text, 550 unsigned SLen, uint8_t Radix); 551LLVMValueRef LLVMConstReal(LLVMTypeRef RealTy, double N); 552LLVMValueRef LLVMConstRealOfString(LLVMTypeRef RealTy, const char *Text); 553LLVMValueRef LLVMConstRealOfStringAndSize(LLVMTypeRef RealTy, const char *Text, 554 unsigned SLen); 555unsigned long long LLVMConstIntGetZExtValue(LLVMValueRef ConstantVal); 556long long LLVMConstIntGetSExtValue(LLVMValueRef ConstantVal); 557 558 559/* Operations on composite constants */ 560LLVMValueRef LLVMConstStringInContext(LLVMContextRef C, const char *Str, 561 unsigned Length, LLVMBool DontNullTerminate); 562LLVMValueRef LLVMConstStructInContext(LLVMContextRef C, 563 LLVMValueRef *ConstantVals, 564 unsigned Count, LLVMBool Packed); 565 566LLVMValueRef LLVMConstString(const char *Str, unsigned Length, 567 LLVMBool DontNullTerminate); 568LLVMValueRef LLVMConstArray(LLVMTypeRef ElementTy, 569 LLVMValueRef *ConstantVals, unsigned Length); 570LLVMValueRef LLVMConstStruct(LLVMValueRef *ConstantVals, unsigned Count, 571 LLVMBool Packed); 572LLVMValueRef LLVMConstVector(LLVMValueRef *ScalarConstantVals, unsigned Size); 573LLVMValueRef LLVMConstUnion(LLVMTypeRef Ty, LLVMValueRef Val); 574 575/* Constant expressions */ 576LLVMOpcode LLVMGetConstOpcode(LLVMValueRef ConstantVal); 577LLVMValueRef LLVMAlignOf(LLVMTypeRef Ty); 578LLVMValueRef LLVMSizeOf(LLVMTypeRef Ty); 579LLVMValueRef LLVMConstNeg(LLVMValueRef ConstantVal); 580LLVMValueRef LLVMConstNSWNeg(LLVMValueRef ConstantVal); 581LLVMValueRef LLVMConstNUWNeg(LLVMValueRef ConstantVal); 582LLVMValueRef LLVMConstFNeg(LLVMValueRef ConstantVal); 583LLVMValueRef LLVMConstNot(LLVMValueRef ConstantVal); 584LLVMValueRef LLVMConstAdd(LLVMValueRef LHSConstant, LLVMValueRef RHSConstant); 585LLVMValueRef LLVMConstNSWAdd(LLVMValueRef LHSConstant, LLVMValueRef RHSConstant); 586LLVMValueRef LLVMConstNUWAdd(LLVMValueRef LHSConstant, LLVMValueRef RHSConstant); 587LLVMValueRef LLVMConstFAdd(LLVMValueRef LHSConstant, LLVMValueRef RHSConstant); 588LLVMValueRef LLVMConstSub(LLVMValueRef LHSConstant, LLVMValueRef RHSConstant); 589LLVMValueRef LLVMConstNSWSub(LLVMValueRef LHSConstant, LLVMValueRef RHSConstant); 590LLVMValueRef LLVMConstNUWSub(LLVMValueRef LHSConstant, LLVMValueRef RHSConstant); 591LLVMValueRef LLVMConstFSub(LLVMValueRef LHSConstant, LLVMValueRef RHSConstant); 592LLVMValueRef LLVMConstMul(LLVMValueRef LHSConstant, LLVMValueRef RHSConstant); 593LLVMValueRef LLVMConstNSWMul(LLVMValueRef LHSConstant, LLVMValueRef RHSConstant); 594LLVMValueRef LLVMConstNUWMul(LLVMValueRef LHSConstant, LLVMValueRef RHSConstant); 595LLVMValueRef LLVMConstFMul(LLVMValueRef LHSConstant, LLVMValueRef RHSConstant); 596LLVMValueRef LLVMConstUDiv(LLVMValueRef LHSConstant, LLVMValueRef RHSConstant); 597LLVMValueRef LLVMConstSDiv(LLVMValueRef LHSConstant, LLVMValueRef RHSConstant); 598LLVMValueRef LLVMConstExactSDiv(LLVMValueRef LHSConstant, LLVMValueRef RHSConstant); 599LLVMValueRef LLVMConstFDiv(LLVMValueRef LHSConstant, LLVMValueRef RHSConstant); 600LLVMValueRef LLVMConstURem(LLVMValueRef LHSConstant, LLVMValueRef RHSConstant); 601LLVMValueRef LLVMConstSRem(LLVMValueRef LHSConstant, LLVMValueRef RHSConstant); 602LLVMValueRef LLVMConstFRem(LLVMValueRef LHSConstant, LLVMValueRef RHSConstant); 603LLVMValueRef LLVMConstAnd(LLVMValueRef LHSConstant, LLVMValueRef RHSConstant); 604LLVMValueRef LLVMConstOr(LLVMValueRef LHSConstant, LLVMValueRef RHSConstant); 605LLVMValueRef LLVMConstXor(LLVMValueRef LHSConstant, LLVMValueRef RHSConstant); 606LLVMValueRef LLVMConstICmp(LLVMIntPredicate Predicate, 607 LLVMValueRef LHSConstant, LLVMValueRef RHSConstant); 608LLVMValueRef LLVMConstFCmp(LLVMRealPredicate Predicate, 609 LLVMValueRef LHSConstant, LLVMValueRef RHSConstant); 610LLVMValueRef LLVMConstShl(LLVMValueRef LHSConstant, LLVMValueRef RHSConstant); 611LLVMValueRef LLVMConstLShr(LLVMValueRef LHSConstant, LLVMValueRef RHSConstant); 612LLVMValueRef LLVMConstAShr(LLVMValueRef LHSConstant, LLVMValueRef RHSConstant); 613LLVMValueRef LLVMConstGEP(LLVMValueRef ConstantVal, 614 LLVMValueRef *ConstantIndices, unsigned NumIndices); 615LLVMValueRef LLVMConstInBoundsGEP(LLVMValueRef ConstantVal, 616 LLVMValueRef *ConstantIndices, 617 unsigned NumIndices); 618LLVMValueRef LLVMConstTrunc(LLVMValueRef ConstantVal, LLVMTypeRef ToType); 619LLVMValueRef LLVMConstSExt(LLVMValueRef ConstantVal, LLVMTypeRef ToType); 620LLVMValueRef LLVMConstZExt(LLVMValueRef ConstantVal, LLVMTypeRef ToType); 621LLVMValueRef LLVMConstFPTrunc(LLVMValueRef ConstantVal, LLVMTypeRef ToType); 622LLVMValueRef LLVMConstFPExt(LLVMValueRef ConstantVal, LLVMTypeRef ToType); 623LLVMValueRef LLVMConstUIToFP(LLVMValueRef ConstantVal, LLVMTypeRef ToType); 624LLVMValueRef LLVMConstSIToFP(LLVMValueRef ConstantVal, LLVMTypeRef ToType); 625LLVMValueRef LLVMConstFPToUI(LLVMValueRef ConstantVal, LLVMTypeRef ToType); 626LLVMValueRef LLVMConstFPToSI(LLVMValueRef ConstantVal, LLVMTypeRef ToType); 627LLVMValueRef LLVMConstPtrToInt(LLVMValueRef ConstantVal, LLVMTypeRef ToType); 628LLVMValueRef LLVMConstIntToPtr(LLVMValueRef ConstantVal, LLVMTypeRef ToType); 629LLVMValueRef LLVMConstBitCast(LLVMValueRef ConstantVal, LLVMTypeRef ToType); 630LLVMValueRef LLVMConstZExtOrBitCast(LLVMValueRef ConstantVal, 631 LLVMTypeRef ToType); 632LLVMValueRef LLVMConstSExtOrBitCast(LLVMValueRef ConstantVal, 633 LLVMTypeRef ToType); 634LLVMValueRef LLVMConstTruncOrBitCast(LLVMValueRef ConstantVal, 635 LLVMTypeRef ToType); 636LLVMValueRef LLVMConstPointerCast(LLVMValueRef ConstantVal, 637 LLVMTypeRef ToType); 638LLVMValueRef LLVMConstIntCast(LLVMValueRef ConstantVal, LLVMTypeRef ToType, 639 LLVMBool isSigned); 640LLVMValueRef LLVMConstFPCast(LLVMValueRef ConstantVal, LLVMTypeRef ToType); 641LLVMValueRef LLVMConstSelect(LLVMValueRef ConstantCondition, 642 LLVMValueRef ConstantIfTrue, 643 LLVMValueRef ConstantIfFalse); 644LLVMValueRef LLVMConstExtractElement(LLVMValueRef VectorConstant, 645 LLVMValueRef IndexConstant); 646LLVMValueRef LLVMConstInsertElement(LLVMValueRef VectorConstant, 647 LLVMValueRef ElementValueConstant, 648 LLVMValueRef IndexConstant); 649LLVMValueRef LLVMConstShuffleVector(LLVMValueRef VectorAConstant, 650 LLVMValueRef VectorBConstant, 651 LLVMValueRef MaskConstant); 652LLVMValueRef LLVMConstExtractValue(LLVMValueRef AggConstant, unsigned *IdxList, 653 unsigned NumIdx); 654LLVMValueRef LLVMConstInsertValue(LLVMValueRef AggConstant, 655 LLVMValueRef ElementValueConstant, 656 unsigned *IdxList, unsigned NumIdx); 657LLVMValueRef LLVMConstInlineAsm(LLVMTypeRef Ty, 658 const char *AsmString, const char *Constraints, 659 LLVMBool HasSideEffects, LLVMBool IsAlignStack); 660LLVMValueRef LLVMBlockAddress(LLVMValueRef F, LLVMBasicBlockRef BB); 661 662/* Operations on global variables, functions, and aliases (globals) */ 663LLVMModuleRef LLVMGetGlobalParent(LLVMValueRef Global); 664LLVMBool LLVMIsDeclaration(LLVMValueRef Global); 665LLVMLinkage LLVMGetLinkage(LLVMValueRef Global); 666void LLVMSetLinkage(LLVMValueRef Global, LLVMLinkage Linkage); 667const char *LLVMGetSection(LLVMValueRef Global); 668void LLVMSetSection(LLVMValueRef Global, const char *Section); 669LLVMVisibility LLVMGetVisibility(LLVMValueRef Global); 670void LLVMSetVisibility(LLVMValueRef Global, LLVMVisibility Viz); 671unsigned LLVMGetAlignment(LLVMValueRef Global); 672void LLVMSetAlignment(LLVMValueRef Global, unsigned Bytes); 673 674/* Operations on global variables */ 675LLVMValueRef LLVMAddGlobal(LLVMModuleRef M, LLVMTypeRef Ty, const char *Name); 676LLVMValueRef LLVMAddGlobalInAddressSpace(LLVMModuleRef M, LLVMTypeRef Ty, 677 const char *Name, 678 unsigned AddressSpace); 679LLVMValueRef LLVMGetNamedGlobal(LLVMModuleRef M, const char *Name); 680LLVMValueRef LLVMGetFirstGlobal(LLVMModuleRef M); 681LLVMValueRef LLVMGetLastGlobal(LLVMModuleRef M); 682LLVMValueRef LLVMGetNextGlobal(LLVMValueRef GlobalVar); 683LLVMValueRef LLVMGetPreviousGlobal(LLVMValueRef GlobalVar); 684void LLVMDeleteGlobal(LLVMValueRef GlobalVar); 685LLVMValueRef LLVMGetInitializer(LLVMValueRef GlobalVar); 686void LLVMSetInitializer(LLVMValueRef GlobalVar, LLVMValueRef ConstantVal); 687LLVMBool LLVMIsThreadLocal(LLVMValueRef GlobalVar); 688void LLVMSetThreadLocal(LLVMValueRef GlobalVar, LLVMBool IsThreadLocal); 689LLVMBool LLVMIsGlobalConstant(LLVMValueRef GlobalVar); 690void LLVMSetGlobalConstant(LLVMValueRef GlobalVar, LLVMBool IsConstant); 691 692/* Operations on aliases */ 693LLVMValueRef LLVMAddAlias(LLVMModuleRef M, LLVMTypeRef Ty, LLVMValueRef Aliasee, 694 const char *Name); 695 696/* Operations on functions */ 697LLVMValueRef LLVMAddFunction(LLVMModuleRef M, const char *Name, 698 LLVMTypeRef FunctionTy); 699LLVMValueRef LLVMGetNamedFunction(LLVMModuleRef M, const char *Name); 700LLVMValueRef LLVMGetFirstFunction(LLVMModuleRef M); 701LLVMValueRef LLVMGetLastFunction(LLVMModuleRef M); 702LLVMValueRef LLVMGetNextFunction(LLVMValueRef Fn); 703LLVMValueRef LLVMGetPreviousFunction(LLVMValueRef Fn); 704void LLVMDeleteFunction(LLVMValueRef Fn); 705unsigned LLVMGetIntrinsicID(LLVMValueRef Fn); 706unsigned LLVMGetFunctionCallConv(LLVMValueRef Fn); 707void LLVMSetFunctionCallConv(LLVMValueRef Fn, unsigned CC); 708const char *LLVMGetGC(LLVMValueRef Fn); 709void LLVMSetGC(LLVMValueRef Fn, const char *Name); 710void LLVMAddFunctionAttr(LLVMValueRef Fn, LLVMAttribute PA); 711LLVMAttribute LLVMGetFunctionAttr(LLVMValueRef Fn); 712void LLVMRemoveFunctionAttr(LLVMValueRef Fn, LLVMAttribute PA); 713 714/* Operations on parameters */ 715unsigned LLVMCountParams(LLVMValueRef Fn); 716void LLVMGetParams(LLVMValueRef Fn, LLVMValueRef *Params); 717LLVMValueRef LLVMGetParam(LLVMValueRef Fn, unsigned Index); 718LLVMValueRef LLVMGetParamParent(LLVMValueRef Inst); 719LLVMValueRef LLVMGetFirstParam(LLVMValueRef Fn); 720LLVMValueRef LLVMGetLastParam(LLVMValueRef Fn); 721LLVMValueRef LLVMGetNextParam(LLVMValueRef Arg); 722LLVMValueRef LLVMGetPreviousParam(LLVMValueRef Arg); 723void LLVMAddAttribute(LLVMValueRef Arg, LLVMAttribute PA); 724void LLVMRemoveAttribute(LLVMValueRef Arg, LLVMAttribute PA); 725LLVMAttribute LLVMGetAttribute(LLVMValueRef Arg); 726void LLVMSetParamAlignment(LLVMValueRef Arg, unsigned align); 727 728/* Operations on basic blocks */ 729LLVMValueRef LLVMBasicBlockAsValue(LLVMBasicBlockRef BB); 730LLVMBool LLVMValueIsBasicBlock(LLVMValueRef Val); 731LLVMBasicBlockRef LLVMValueAsBasicBlock(LLVMValueRef Val); 732LLVMValueRef LLVMGetBasicBlockParent(LLVMBasicBlockRef BB); 733unsigned LLVMCountBasicBlocks(LLVMValueRef Fn); 734void LLVMGetBasicBlocks(LLVMValueRef Fn, LLVMBasicBlockRef *BasicBlocks); 735LLVMBasicBlockRef LLVMGetFirstBasicBlock(LLVMValueRef Fn); 736LLVMBasicBlockRef LLVMGetLastBasicBlock(LLVMValueRef Fn); 737LLVMBasicBlockRef LLVMGetNextBasicBlock(LLVMBasicBlockRef BB); 738LLVMBasicBlockRef LLVMGetPreviousBasicBlock(LLVMBasicBlockRef BB); 739LLVMBasicBlockRef LLVMGetEntryBasicBlock(LLVMValueRef Fn); 740 741LLVMBasicBlockRef LLVMAppendBasicBlockInContext(LLVMContextRef C, 742 LLVMValueRef Fn, 743 const char *Name); 744LLVMBasicBlockRef LLVMInsertBasicBlockInContext(LLVMContextRef C, 745 LLVMBasicBlockRef BB, 746 const char *Name); 747 748LLVMBasicBlockRef LLVMAppendBasicBlock(LLVMValueRef Fn, const char *Name); 749LLVMBasicBlockRef LLVMInsertBasicBlock(LLVMBasicBlockRef InsertBeforeBB, 750 const char *Name); 751void LLVMDeleteBasicBlock(LLVMBasicBlockRef BB); 752 753/* Operations on instructions */ 754LLVMBasicBlockRef LLVMGetInstructionParent(LLVMValueRef Inst); 755LLVMValueRef LLVMGetFirstInstruction(LLVMBasicBlockRef BB); 756LLVMValueRef LLVMGetLastInstruction(LLVMBasicBlockRef BB); 757LLVMValueRef LLVMGetNextInstruction(LLVMValueRef Inst); 758LLVMValueRef LLVMGetPreviousInstruction(LLVMValueRef Inst); 759 760/* Operations on call sites */ 761void LLVMSetInstructionCallConv(LLVMValueRef Instr, unsigned CC); 762unsigned LLVMGetInstructionCallConv(LLVMValueRef Instr); 763void LLVMAddInstrAttribute(LLVMValueRef Instr, unsigned index, LLVMAttribute); 764void LLVMRemoveInstrAttribute(LLVMValueRef Instr, unsigned index, 765 LLVMAttribute); 766void LLVMSetInstrParamAlignment(LLVMValueRef Instr, unsigned index, 767 unsigned align); 768 769/* Operations on call instructions (only) */ 770LLVMBool LLVMIsTailCall(LLVMValueRef CallInst); 771void LLVMSetTailCall(LLVMValueRef CallInst, LLVMBool IsTailCall); 772 773/* Operations on phi nodes */ 774void LLVMAddIncoming(LLVMValueRef PhiNode, LLVMValueRef *IncomingValues, 775 LLVMBasicBlockRef *IncomingBlocks, unsigned Count); 776unsigned LLVMCountIncoming(LLVMValueRef PhiNode); 777LLVMValueRef LLVMGetIncomingValue(LLVMValueRef PhiNode, unsigned Index); 778LLVMBasicBlockRef LLVMGetIncomingBlock(LLVMValueRef PhiNode, unsigned Index); 779 780/*===-- Instruction builders ----------------------------------------------===*/ 781 782/* An instruction builder represents a point within a basic block, and is the 783 * exclusive means of building instructions using the C interface. 784 */ 785 786LLVMBuilderRef LLVMCreateBuilderInContext(LLVMContextRef C); 787LLVMBuilderRef LLVMCreateBuilder(void); 788void LLVMPositionBuilder(LLVMBuilderRef Builder, LLVMBasicBlockRef Block, 789 LLVMValueRef Instr); 790void LLVMPositionBuilderBefore(LLVMBuilderRef Builder, LLVMValueRef Instr); 791void LLVMPositionBuilderAtEnd(LLVMBuilderRef Builder, LLVMBasicBlockRef Block); 792LLVMBasicBlockRef LLVMGetInsertBlock(LLVMBuilderRef Builder); 793void LLVMClearInsertionPosition(LLVMBuilderRef Builder); 794void LLVMInsertIntoBuilder(LLVMBuilderRef Builder, LLVMValueRef Instr); 795void LLVMInsertIntoBuilderWithName(LLVMBuilderRef Builder, LLVMValueRef Instr, 796 const char *Name); 797void LLVMDisposeBuilder(LLVMBuilderRef Builder); 798 799/* Metadata */ 800void LLVMSetCurrentDebugLocation(LLVMBuilderRef Builder, LLVMValueRef L); 801LLVMValueRef LLVMGetCurrentDebugLocation(LLVMBuilderRef Builder); 802void LLVMSetInstDebugLocation(LLVMBuilderRef Builder, LLVMValueRef Inst); 803 804/* Terminators */ 805LLVMValueRef LLVMBuildRetVoid(LLVMBuilderRef); 806LLVMValueRef LLVMBuildRet(LLVMBuilderRef, LLVMValueRef V); 807LLVMValueRef LLVMBuildAggregateRet(LLVMBuilderRef, LLVMValueRef *RetVals, 808 unsigned N); 809LLVMValueRef LLVMBuildBr(LLVMBuilderRef, LLVMBasicBlockRef Dest); 810LLVMValueRef LLVMBuildCondBr(LLVMBuilderRef, LLVMValueRef If, 811 LLVMBasicBlockRef Then, LLVMBasicBlockRef Else); 812LLVMValueRef LLVMBuildSwitch(LLVMBuilderRef, LLVMValueRef V, 813 LLVMBasicBlockRef Else, unsigned NumCases); 814LLVMValueRef LLVMBuildIndirectBr(LLVMBuilderRef B, LLVMValueRef Addr, 815 unsigned NumDests); 816LLVMValueRef LLVMBuildInvoke(LLVMBuilderRef, LLVMValueRef Fn, 817 LLVMValueRef *Args, unsigned NumArgs, 818 LLVMBasicBlockRef Then, LLVMBasicBlockRef Catch, 819 const char *Name); 820LLVMValueRef LLVMBuildUnwind(LLVMBuilderRef); 821LLVMValueRef LLVMBuildUnreachable(LLVMBuilderRef); 822 823/* Add a case to the switch instruction */ 824void LLVMAddCase(LLVMValueRef Switch, LLVMValueRef OnVal, 825 LLVMBasicBlockRef Dest); 826 827/* Add a destination to the indirectbr instruction */ 828void LLVMAddDestination(LLVMValueRef IndirectBr, LLVMBasicBlockRef Dest); 829 830/* Arithmetic */ 831LLVMValueRef LLVMBuildAdd(LLVMBuilderRef, LLVMValueRef LHS, LLVMValueRef RHS, 832 const char *Name); 833LLVMValueRef LLVMBuildNSWAdd(LLVMBuilderRef, LLVMValueRef LHS, LLVMValueRef RHS, 834 const char *Name); 835LLVMValueRef LLVMBuildNUWAdd(LLVMBuilderRef, LLVMValueRef LHS, LLVMValueRef RHS, 836 const char *Name); 837LLVMValueRef LLVMBuildFAdd(LLVMBuilderRef, LLVMValueRef LHS, LLVMValueRef RHS, 838 const char *Name); 839LLVMValueRef LLVMBuildSub(LLVMBuilderRef, LLVMValueRef LHS, LLVMValueRef RHS, 840 const char *Name); 841LLVMValueRef LLVMBuildNSWSub(LLVMBuilderRef, LLVMValueRef LHS, LLVMValueRef RHS, 842 const char *Name); 843LLVMValueRef LLVMBuildNUWSub(LLVMBuilderRef, LLVMValueRef LHS, LLVMValueRef RHS, 844 const char *Name); 845LLVMValueRef LLVMBuildFSub(LLVMBuilderRef, LLVMValueRef LHS, LLVMValueRef RHS, 846 const char *Name); 847LLVMValueRef LLVMBuildMul(LLVMBuilderRef, LLVMValueRef LHS, LLVMValueRef RHS, 848 const char *Name); 849LLVMValueRef LLVMBuildNSWMul(LLVMBuilderRef, LLVMValueRef LHS, LLVMValueRef RHS, 850 const char *Name); 851LLVMValueRef LLVMBuildNUWMul(LLVMBuilderRef, LLVMValueRef LHS, LLVMValueRef RHS, 852 const char *Name); 853LLVMValueRef LLVMBuildFMul(LLVMBuilderRef, LLVMValueRef LHS, LLVMValueRef RHS, 854 const char *Name); 855LLVMValueRef LLVMBuildUDiv(LLVMBuilderRef, LLVMValueRef LHS, LLVMValueRef RHS, 856 const char *Name); 857LLVMValueRef LLVMBuildSDiv(LLVMBuilderRef, LLVMValueRef LHS, LLVMValueRef RHS, 858 const char *Name); 859LLVMValueRef LLVMBuildExactSDiv(LLVMBuilderRef, LLVMValueRef LHS, LLVMValueRef RHS, 860 const char *Name); 861LLVMValueRef LLVMBuildFDiv(LLVMBuilderRef, LLVMValueRef LHS, LLVMValueRef RHS, 862 const char *Name); 863LLVMValueRef LLVMBuildURem(LLVMBuilderRef, LLVMValueRef LHS, LLVMValueRef RHS, 864 const char *Name); 865LLVMValueRef LLVMBuildSRem(LLVMBuilderRef, LLVMValueRef LHS, LLVMValueRef RHS, 866 const char *Name); 867LLVMValueRef LLVMBuildFRem(LLVMBuilderRef, LLVMValueRef LHS, LLVMValueRef RHS, 868 const char *Name); 869LLVMValueRef LLVMBuildShl(LLVMBuilderRef, LLVMValueRef LHS, LLVMValueRef RHS, 870 const char *Name); 871LLVMValueRef LLVMBuildLShr(LLVMBuilderRef, LLVMValueRef LHS, LLVMValueRef RHS, 872 const char *Name); 873LLVMValueRef LLVMBuildAShr(LLVMBuilderRef, LLVMValueRef LHS, LLVMValueRef RHS, 874 const char *Name); 875LLVMValueRef LLVMBuildAnd(LLVMBuilderRef, LLVMValueRef LHS, LLVMValueRef RHS, 876 const char *Name); 877LLVMValueRef LLVMBuildOr(LLVMBuilderRef, LLVMValueRef LHS, LLVMValueRef RHS, 878 const char *Name); 879LLVMValueRef LLVMBuildXor(LLVMBuilderRef, LLVMValueRef LHS, LLVMValueRef RHS, 880 const char *Name); 881LLVMValueRef LLVMBuildBinOp(LLVMBuilderRef B, LLVMOpcode Op, 882 LLVMValueRef LHS, LLVMValueRef RHS, 883 const char *Name); 884LLVMValueRef LLVMBuildNeg(LLVMBuilderRef, LLVMValueRef V, const char *Name); 885LLVMValueRef LLVMBuildNSWNeg(LLVMBuilderRef B, LLVMValueRef V, 886 const char *Name); 887LLVMValueRef LLVMBuildNUWNeg(LLVMBuilderRef B, LLVMValueRef V, 888 const char *Name); 889LLVMValueRef LLVMBuildFNeg(LLVMBuilderRef, LLVMValueRef V, const char *Name); 890LLVMValueRef LLVMBuildNot(LLVMBuilderRef, LLVMValueRef V, const char *Name); 891 892/* Memory */ 893LLVMValueRef LLVMBuildMalloc(LLVMBuilderRef, LLVMTypeRef Ty, const char *Name); 894LLVMValueRef LLVMBuildArrayMalloc(LLVMBuilderRef, LLVMTypeRef Ty, 895 LLVMValueRef Val, const char *Name); 896LLVMValueRef LLVMBuildAlloca(LLVMBuilderRef, LLVMTypeRef Ty, const char *Name); 897LLVMValueRef LLVMBuildArrayAlloca(LLVMBuilderRef, LLVMTypeRef Ty, 898 LLVMValueRef Val, const char *Name); 899LLVMValueRef LLVMBuildFree(LLVMBuilderRef, LLVMValueRef PointerVal); 900LLVMValueRef LLVMBuildLoad(LLVMBuilderRef, LLVMValueRef PointerVal, 901 const char *Name); 902LLVMValueRef LLVMBuildStore(LLVMBuilderRef, LLVMValueRef Val, LLVMValueRef Ptr); 903LLVMValueRef LLVMBuildGEP(LLVMBuilderRef B, LLVMValueRef Pointer, 904 LLVMValueRef *Indices, unsigned NumIndices, 905 const char *Name); 906LLVMValueRef LLVMBuildInBoundsGEP(LLVMBuilderRef B, LLVMValueRef Pointer, 907 LLVMValueRef *Indices, unsigned NumIndices, 908 const char *Name); 909LLVMValueRef LLVMBuildStructGEP(LLVMBuilderRef B, LLVMValueRef Pointer, 910 unsigned Idx, const char *Name); 911LLVMValueRef LLVMBuildGlobalString(LLVMBuilderRef B, const char *Str, 912 const char *Name); 913LLVMValueRef LLVMBuildGlobalStringPtr(LLVMBuilderRef B, const char *Str, 914 const char *Name); 915 916/* Casts */ 917LLVMValueRef LLVMBuildTrunc(LLVMBuilderRef, LLVMValueRef Val, 918 LLVMTypeRef DestTy, const char *Name); 919LLVMValueRef LLVMBuildZExt(LLVMBuilderRef, LLVMValueRef Val, 920 LLVMTypeRef DestTy, const char *Name); 921LLVMValueRef LLVMBuildSExt(LLVMBuilderRef, LLVMValueRef Val, 922 LLVMTypeRef DestTy, const char *Name); 923LLVMValueRef LLVMBuildFPToUI(LLVMBuilderRef, LLVMValueRef Val, 924 LLVMTypeRef DestTy, const char *Name); 925LLVMValueRef LLVMBuildFPToSI(LLVMBuilderRef, LLVMValueRef Val, 926 LLVMTypeRef DestTy, const char *Name); 927LLVMValueRef LLVMBuildUIToFP(LLVMBuilderRef, LLVMValueRef Val, 928 LLVMTypeRef DestTy, const char *Name); 929LLVMValueRef LLVMBuildSIToFP(LLVMBuilderRef, LLVMValueRef Val, 930 LLVMTypeRef DestTy, const char *Name); 931LLVMValueRef LLVMBuildFPTrunc(LLVMBuilderRef, LLVMValueRef Val, 932 LLVMTypeRef DestTy, const char *Name); 933LLVMValueRef LLVMBuildFPExt(LLVMBuilderRef, LLVMValueRef Val, 934 LLVMTypeRef DestTy, const char *Name); 935LLVMValueRef LLVMBuildPtrToInt(LLVMBuilderRef, LLVMValueRef Val, 936 LLVMTypeRef DestTy, const char *Name); 937LLVMValueRef LLVMBuildIntToPtr(LLVMBuilderRef, LLVMValueRef Val, 938 LLVMTypeRef DestTy, const char *Name); 939LLVMValueRef LLVMBuildBitCast(LLVMBuilderRef, LLVMValueRef Val, 940 LLVMTypeRef DestTy, const char *Name); 941LLVMValueRef LLVMBuildZExtOrBitCast(LLVMBuilderRef, LLVMValueRef Val, 942 LLVMTypeRef DestTy, const char *Name); 943LLVMValueRef LLVMBuildSExtOrBitCast(LLVMBuilderRef, LLVMValueRef Val, 944 LLVMTypeRef DestTy, const char *Name); 945LLVMValueRef LLVMBuildTruncOrBitCast(LLVMBuilderRef, LLVMValueRef Val, 946 LLVMTypeRef DestTy, const char *Name); 947LLVMValueRef LLVMBuildCast(LLVMBuilderRef B, LLVMOpcode Op, LLVMValueRef Val, 948 LLVMTypeRef DestTy, const char *Name); 949LLVMValueRef LLVMBuildPointerCast(LLVMBuilderRef, LLVMValueRef Val, 950 LLVMTypeRef DestTy, const char *Name); 951LLVMValueRef LLVMBuildIntCast(LLVMBuilderRef, LLVMValueRef Val, /*Signed cast!*/ 952 LLVMTypeRef DestTy, const char *Name); 953LLVMValueRef LLVMBuildFPCast(LLVMBuilderRef, LLVMValueRef Val, 954 LLVMTypeRef DestTy, const char *Name); 955 956/* Comparisons */ 957LLVMValueRef LLVMBuildICmp(LLVMBuilderRef, LLVMIntPredicate Op, 958 LLVMValueRef LHS, LLVMValueRef RHS, 959 const char *Name); 960LLVMValueRef LLVMBuildFCmp(LLVMBuilderRef, LLVMRealPredicate Op, 961 LLVMValueRef LHS, LLVMValueRef RHS, 962 const char *Name); 963 964/* Miscellaneous instructions */ 965LLVMValueRef LLVMBuildPhi(LLVMBuilderRef, LLVMTypeRef Ty, const char *Name); 966LLVMValueRef LLVMBuildCall(LLVMBuilderRef, LLVMValueRef Fn, 967 LLVMValueRef *Args, unsigned NumArgs, 968 const char *Name); 969LLVMValueRef LLVMBuildSelect(LLVMBuilderRef, LLVMValueRef If, 970 LLVMValueRef Then, LLVMValueRef Else, 971 const char *Name); 972LLVMValueRef LLVMBuildVAArg(LLVMBuilderRef, LLVMValueRef List, LLVMTypeRef Ty, 973 const char *Name); 974LLVMValueRef LLVMBuildExtractElement(LLVMBuilderRef, LLVMValueRef VecVal, 975 LLVMValueRef Index, const char *Name); 976LLVMValueRef LLVMBuildInsertElement(LLVMBuilderRef, LLVMValueRef VecVal, 977 LLVMValueRef EltVal, LLVMValueRef Index, 978 const char *Name); 979LLVMValueRef LLVMBuildShuffleVector(LLVMBuilderRef, LLVMValueRef V1, 980 LLVMValueRef V2, LLVMValueRef Mask, 981 const char *Name); 982LLVMValueRef LLVMBuildExtractValue(LLVMBuilderRef, LLVMValueRef AggVal, 983 unsigned Index, const char *Name); 984LLVMValueRef LLVMBuildInsertValue(LLVMBuilderRef, LLVMValueRef AggVal, 985 LLVMValueRef EltVal, unsigned Index, 986 const char *Name); 987 988LLVMValueRef LLVMBuildIsNull(LLVMBuilderRef, LLVMValueRef Val, 989 const char *Name); 990LLVMValueRef LLVMBuildIsNotNull(LLVMBuilderRef, LLVMValueRef Val, 991 const char *Name); 992LLVMValueRef LLVMBuildPtrDiff(LLVMBuilderRef, LLVMValueRef LHS, 993 LLVMValueRef RHS, const char *Name); 994 995 996/*===-- Module providers --------------------------------------------------===*/ 997 998/* Changes the type of M so it can be passed to FunctionPassManagers and the 999 * JIT. They take ModuleProviders for historical reasons. 1000 */ 1001LLVMModuleProviderRef 1002LLVMCreateModuleProviderForExistingModule(LLVMModuleRef M); 1003 1004/* Destroys the module M. 1005 */ 1006void LLVMDisposeModuleProvider(LLVMModuleProviderRef M); 1007 1008 1009/*===-- Memory buffers ----------------------------------------------------===*/ 1010 1011LLVMBool LLVMCreateMemoryBufferWithContentsOfFile(const char *Path, 1012 LLVMMemoryBufferRef *OutMemBuf, 1013 char **OutMessage); 1014LLVMBool LLVMCreateMemoryBufferWithSTDIN(LLVMMemoryBufferRef *OutMemBuf, 1015 char **OutMessage); 1016void LLVMDisposeMemoryBuffer(LLVMMemoryBufferRef MemBuf); 1017 1018 1019/*===-- Pass Managers -----------------------------------------------------===*/ 1020 1021/** Constructs a new whole-module pass pipeline. This type of pipeline is 1022 suitable for link-time optimization and whole-module transformations. 1023 See llvm::PassManager::PassManager. */ 1024LLVMPassManagerRef LLVMCreatePassManager(void); 1025 1026/** Constructs a new function-by-function pass pipeline over the module 1027 provider. It does not take ownership of the module provider. This type of 1028 pipeline is suitable for code generation and JIT compilation tasks. 1029 See llvm::FunctionPassManager::FunctionPassManager. */ 1030LLVMPassManagerRef LLVMCreateFunctionPassManagerForModule(LLVMModuleRef M); 1031 1032/** Deprecated: Use LLVMCreateFunctionPassManagerForModule instead. */ 1033LLVMPassManagerRef LLVMCreateFunctionPassManager(LLVMModuleProviderRef MP); 1034 1035/** Initializes, executes on the provided module, and finalizes all of the 1036 passes scheduled in the pass manager. Returns 1 if any of the passes 1037 modified the module, 0 otherwise. See llvm::PassManager::run(Module&). */ 1038LLVMBool LLVMRunPassManager(LLVMPassManagerRef PM, LLVMModuleRef M); 1039 1040/** Initializes all of the function passes scheduled in the function pass 1041 manager. Returns 1 if any of the passes modified the module, 0 otherwise. 1042 See llvm::FunctionPassManager::doInitialization. */ 1043LLVMBool LLVMInitializeFunctionPassManager(LLVMPassManagerRef FPM); 1044 1045/** Executes all of the function passes scheduled in the function pass manager 1046 on the provided function. Returns 1 if any of the passes modified the 1047 function, false otherwise. 1048 See llvm::FunctionPassManager::run(Function&). */ 1049LLVMBool LLVMRunFunctionPassManager(LLVMPassManagerRef FPM, LLVMValueRef F); 1050 1051/** Finalizes all of the function passes scheduled in in the function pass 1052 manager. Returns 1 if any of the passes modified the module, 0 otherwise. 1053 See llvm::FunctionPassManager::doFinalization. */ 1054LLVMBool LLVMFinalizeFunctionPassManager(LLVMPassManagerRef FPM); 1055 1056/** Frees the memory of a pass pipeline. For function pipelines, does not free 1057 the module provider. 1058 See llvm::PassManagerBase::~PassManagerBase. */ 1059void LLVMDisposePassManager(LLVMPassManagerRef PM); 1060 1061 1062#ifdef __cplusplus 1063} 1064 1065namespace llvm { 1066 class MemoryBuffer; 1067 class PassManagerBase; 1068 1069 #define DEFINE_SIMPLE_CONVERSION_FUNCTIONS(ty, ref) \ 1070 inline ty *unwrap(ref P) { \ 1071 return reinterpret_cast<ty*>(P); \ 1072 } \ 1073 \ 1074 inline ref wrap(const ty *P) { \ 1075 return reinterpret_cast<ref>(const_cast<ty*>(P)); \ 1076 } 1077 1078 #define DEFINE_ISA_CONVERSION_FUNCTIONS(ty, ref) \ 1079 DEFINE_SIMPLE_CONVERSION_FUNCTIONS(ty, ref) \ 1080 \ 1081 template<typename T> \ 1082 inline T *unwrap(ref P) { \ 1083 return cast<T>(unwrap(P)); \ 1084 } 1085 1086 #define DEFINE_STDCXX_CONVERSION_FUNCTIONS(ty, ref) \ 1087 DEFINE_SIMPLE_CONVERSION_FUNCTIONS(ty, ref) \ 1088 \ 1089 template<typename T> \ 1090 inline T *unwrap(ref P) { \ 1091 T *Q = (T*)unwrap(P); \ 1092 assert(Q && "Invalid cast!"); \ 1093 return Q; \ 1094 } 1095 1096 DEFINE_ISA_CONVERSION_FUNCTIONS (Type, LLVMTypeRef ) 1097 DEFINE_ISA_CONVERSION_FUNCTIONS (Value, LLVMValueRef ) 1098 DEFINE_SIMPLE_CONVERSION_FUNCTIONS(Module, LLVMModuleRef ) 1099 DEFINE_SIMPLE_CONVERSION_FUNCTIONS(BasicBlock, LLVMBasicBlockRef ) 1100 DEFINE_SIMPLE_CONVERSION_FUNCTIONS(IRBuilder<>, LLVMBuilderRef ) 1101 DEFINE_SIMPLE_CONVERSION_FUNCTIONS(PATypeHolder, LLVMTypeHandleRef ) 1102 DEFINE_SIMPLE_CONVERSION_FUNCTIONS(MemoryBuffer, LLVMMemoryBufferRef ) 1103 DEFINE_SIMPLE_CONVERSION_FUNCTIONS(LLVMContext, LLVMContextRef ) 1104 DEFINE_SIMPLE_CONVERSION_FUNCTIONS(Use, LLVMUseRef ) 1105 DEFINE_STDCXX_CONVERSION_FUNCTIONS(PassManagerBase, LLVMPassManagerRef ) 1106 /* LLVMModuleProviderRef exists for historical reasons, but now just holds a 1107 * Module. 1108 */ 1109 inline Module *unwrap(LLVMModuleProviderRef MP) { 1110 return reinterpret_cast<Module*>(MP); 1111 } 1112 1113 #undef DEFINE_STDCXX_CONVERSION_FUNCTIONS 1114 #undef DEFINE_ISA_CONVERSION_FUNCTIONS 1115 #undef DEFINE_SIMPLE_CONVERSION_FUNCTIONS 1116 1117 /* Specialized opaque context conversions. 1118 */ 1119 inline LLVMContext **unwrap(LLVMContextRef* Tys) { 1120 return reinterpret_cast<LLVMContext**>(Tys); 1121 } 1122 1123 inline LLVMContextRef *wrap(const LLVMContext **Tys) { 1124 return reinterpret_cast<LLVMContextRef*>(const_cast<LLVMContext**>(Tys)); 1125 } 1126 1127 /* Specialized opaque type conversions. 1128 */ 1129 inline Type **unwrap(LLVMTypeRef* Tys) { 1130 return reinterpret_cast<Type**>(Tys); 1131 } 1132 1133 inline LLVMTypeRef *wrap(const Type **Tys) { 1134 return reinterpret_cast<LLVMTypeRef*>(const_cast<Type**>(Tys)); 1135 } 1136 1137 /* Specialized opaque value conversions. 1138 */ 1139 inline Value **unwrap(LLVMValueRef *Vals) { 1140 return reinterpret_cast<Value**>(Vals); 1141 } 1142 1143 template<typename T> 1144 inline T **unwrap(LLVMValueRef *Vals, unsigned Length) { 1145 #if DEBUG 1146 for (LLVMValueRef *I = Vals, *E = Vals + Length; I != E; ++I) 1147 cast<T>(*I); 1148 #endif 1149 return reinterpret_cast<T**>(Vals); 1150 } 1151 1152 inline LLVMValueRef *wrap(const Value **Vals) { 1153 return reinterpret_cast<LLVMValueRef*>(const_cast<Value**>(Vals)); 1154 } 1155} 1156 1157#endif /* !defined(__cplusplus) */ 1158 1159#endif /* !defined(LLVM_C_CORE_H) */ 1160