Core.h revision 877ee973e2d6ade85e38babbd303d96347c7dc8e
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|* LLVM uses a polymorphic type hierarchy which C cannot represent, therefore *| 14|* parameters must be passed as base types. Despite the declared types, most *| 15|* of the functions provided operate only on branches of the type hierarchy. *| 16|* The declared parameter names are descriptive and specify which type is *| 17|* required. Additionally, each type hierarchy is documented along with the *| 18|* functions that operate upon it. For more detail, refer to LLVM's C++ code. *| 19|* If in doubt, refer to Core.cpp, which performs paramter downcasts in the *| 20|* form unwrap<RequiredType>(Param). *| 21|* *| 22|* Many exotic languages can interoperate with C code but have a harder time *| 23|* with C++ due to name mangling. So in addition to C, this interface enables *| 24|* tools written in such languages. *| 25|* *| 26|* When included into a C++ source file, also declares 'wrap' and 'unwrap' *| 27|* helpers to perform opaque reference<-->pointer conversions. These helpers *| 28|* are shorter and more tightly typed than writing the casts by hand when *| 29|* authoring bindings. In assert builds, they will do runtime type checking. *| 30|* *| 31\*===----------------------------------------------------------------------===*/ 32 33#ifndef LLVM_C_CORE_H 34#define LLVM_C_CORE_H 35 36#ifdef __cplusplus 37 38/* Need these includes to support the LLVM 'cast' template for the C++ 'wrap' 39 and 'unwrap' conversion functions. */ 40#include "llvm/Module.h" 41#include "llvm/Support/IRBuilder.h" 42 43extern "C" { 44#endif 45 46 47/* Opaque types. */ 48 49/** 50 * The top-level container for all other LLVM Intermediate Representation (IR) 51 * objects. See the llvm::Module class. 52 */ 53typedef struct LLVMOpaqueModule *LLVMModuleRef; 54 55/** 56 * Each value in the LLVM IR has a type, an LLVMTypeRef. See the llvm::Type 57 * class. 58 */ 59typedef struct LLVMOpaqueType *LLVMTypeRef; 60 61/** 62 * When building recursive types using LLVMRefineType, LLVMTypeRef values may 63 * become invalid; use LLVMTypeHandleRef to resolve this problem. See the 64 * llvm::AbstractTypeHolder class. 65 */ 66typedef struct LLVMOpaqueTypeHandle *LLVMTypeHandleRef; 67 68typedef struct LLVMOpaqueValue *LLVMValueRef; 69typedef struct LLVMOpaqueBasicBlock *LLVMBasicBlockRef; 70typedef struct LLVMOpaqueBuilder *LLVMBuilderRef; 71 72/* Used to provide a module to JIT or interpreter. 73 * See the llvm::ModuleProvider class. 74 */ 75typedef struct LLVMOpaqueModuleProvider *LLVMModuleProviderRef; 76 77/* Used to provide a module to JIT or interpreter. 78 * See the llvm::MemoryBuffer class. 79 */ 80typedef struct LLVMOpaqueMemoryBuffer *LLVMMemoryBufferRef; 81 82/** See the llvm::PassManagerBase class. */ 83typedef struct LLVMOpaquePassManager *LLVMPassManagerRef; 84 85typedef enum { 86 LLVMVoidTypeKind, /**< type with no size */ 87 LLVMFloatTypeKind, /**< 32 bit floating point type */ 88 LLVMDoubleTypeKind, /**< 64 bit floating point type */ 89 LLVMX86_FP80TypeKind, /**< 80 bit floating point type (X87) */ 90 LLVMFP128TypeKind, /**< 128 bit floating point type (112-bit mantissa)*/ 91 LLVMPPC_FP128TypeKind, /**< 128 bit floating point type (two 64-bits) */ 92 LLVMLabelTypeKind, /**< Labels */ 93 LLVMIntegerTypeKind, /**< Arbitrary bit width integers */ 94 LLVMFunctionTypeKind, /**< Functions */ 95 LLVMStructTypeKind, /**< Structures */ 96 LLVMArrayTypeKind, /**< Arrays */ 97 LLVMPointerTypeKind, /**< Pointers */ 98 LLVMOpaqueTypeKind, /**< Opaque: type with unknown structure */ 99 LLVMVectorTypeKind /**< SIMD 'packed' format, or other vector type */ 100} LLVMTypeKind; 101 102typedef enum { 103 LLVMExternalLinkage, /**< Externally visible function */ 104 LLVMLinkOnceLinkage, /**< Keep one copy of function when linking (inline)*/ 105 LLVMWeakLinkage, /**< Keep one copy of function when linking (weak) */ 106 LLVMAppendingLinkage, /**< Special purpose, only applies to global arrays */ 107 LLVMInternalLinkage, /**< Rename collisions when linking (static 108 functions) */ 109 LLVMDLLImportLinkage, /**< Function to be imported from DLL */ 110 LLVMDLLExportLinkage, /**< Function to be accessible from DLL */ 111 LLVMExternalWeakLinkage,/**< ExternalWeak linkage description */ 112 LLVMGhostLinkage /**< Stand-in functions for streaming fns from 113 bitcode */ 114} LLVMLinkage; 115 116typedef enum { 117 LLVMDefaultVisibility, /**< The GV is visible */ 118 LLVMHiddenVisibility, /**< The GV is hidden */ 119 LLVMProtectedVisibility /**< The GV is protected */ 120} LLVMVisibility; 121 122typedef enum { 123 LLVMCCallConv = 0, 124 LLVMFastCallConv = 8, 125 LLVMColdCallConv = 9, 126 LLVMX86StdcallCallConv = 64, 127 LLVMX86FastcallCallConv = 65 128} LLVMCallConv; 129 130typedef enum { 131 LLVMIntEQ = 32, /**< equal */ 132 LLVMIntNE, /**< not equal */ 133 LLVMIntUGT, /**< unsigned greater than */ 134 LLVMIntUGE, /**< unsigned greater or equal */ 135 LLVMIntULT, /**< unsigned less than */ 136 LLVMIntULE, /**< unsigned less or equal */ 137 LLVMIntSGT, /**< signed greater than */ 138 LLVMIntSGE, /**< signed greater or equal */ 139 LLVMIntSLT, /**< signed less than */ 140 LLVMIntSLE /**< signed less or equal */ 141} LLVMIntPredicate; 142 143typedef enum { 144 LLVMRealPredicateFalse, /**< Always false (always folded) */ 145 LLVMRealOEQ, /**< True if ordered and equal */ 146 LLVMRealOGT, /**< True if ordered and greater than */ 147 LLVMRealOGE, /**< True if ordered and greater than or equal */ 148 LLVMRealOLT, /**< True if ordered and less than */ 149 LLVMRealOLE, /**< True if ordered and less than or equal */ 150 LLVMRealONE, /**< True if ordered and operands are unequal */ 151 LLVMRealORD, /**< True if ordered (no nans) */ 152 LLVMRealUNO, /**< True if unordered: isnan(X) | isnan(Y) */ 153 LLVMRealUEQ, /**< True if unordered or equal */ 154 LLVMRealUGT, /**< True if unordered or greater than */ 155 LLVMRealUGE, /**< True if unordered, greater than, or equal */ 156 LLVMRealULT, /**< True if unordered or less than */ 157 LLVMRealULE, /**< True if unordered, less than, or equal */ 158 LLVMRealUNE, /**< True if unordered or not equal */ 159 LLVMRealPredicateTrue /**< Always true (always folded) */ 160} LLVMRealPredicate; 161 162 163/*===-- Error handling ----------------------------------------------------===*/ 164 165void LLVMDisposeMessage(char *Message); 166 167 168/*===-- Modules -----------------------------------------------------------===*/ 169 170/* Create and destroy modules. */ 171/** See llvm::Module::Module. */ 172LLVMModuleRef LLVMModuleCreateWithName(const char *ModuleID); 173 174/** See llvm::Module::~Module. */ 175void LLVMDisposeModule(LLVMModuleRef M); 176 177/** Data layout. See Module::getDataLayout. */ 178const char *LLVMGetDataLayout(LLVMModuleRef M); 179void LLVMSetDataLayout(LLVMModuleRef M, const char *Triple); 180 181/** Target triple. See Module::getTargetTriple. */ 182const char *LLVMGetTarget(LLVMModuleRef M); 183void LLVMSetTarget(LLVMModuleRef M, const char *Triple); 184 185/** See Module::addTypeName. */ 186int LLVMAddTypeName(LLVMModuleRef M, const char *Name, LLVMTypeRef Ty); 187void LLVMDeleteTypeName(LLVMModuleRef M, const char *Name); 188 189/** See Module::dump. */ 190void LLVMDumpModule(LLVMModuleRef M); 191 192 193/*===-- Types -------------------------------------------------------------===*/ 194 195/* LLVM types conform to the following hierarchy: 196 * 197 * types: 198 * integer type 199 * real type 200 * function type 201 * sequence types: 202 * array type 203 * pointer type 204 * vector type 205 * void type 206 * label type 207 * opaque type 208 */ 209 210/** See llvm::LLVMTypeKind::getTypeID. */ 211LLVMTypeKind LLVMGetTypeKind(LLVMTypeRef Ty); 212 213/** See llvm::DerivedType::refineAbstractTypeTo. */ 214void LLVMRefineAbstractType(LLVMTypeRef AbstractType, LLVMTypeRef ConcreteType); 215 216/* Operations on integer types */ 217LLVMTypeRef LLVMInt1Type(); 218LLVMTypeRef LLVMInt8Type(); 219LLVMTypeRef LLVMInt16Type(); 220LLVMTypeRef LLVMInt32Type(); 221LLVMTypeRef LLVMInt64Type(); 222LLVMTypeRef LLVMIntType(unsigned NumBits); 223unsigned LLVMGetIntTypeWidth(LLVMTypeRef IntegerTy); 224 225/* Operations on real types */ 226LLVMTypeRef LLVMFloatType(); 227LLVMTypeRef LLVMDoubleType(); 228LLVMTypeRef LLVMX86FP80Type(); 229LLVMTypeRef LLVMFP128Type(); 230LLVMTypeRef LLVMPPCFP128Type(); 231 232/* Operations on function types */ 233LLVMTypeRef LLVMFunctionType(LLVMTypeRef ReturnType, 234 LLVMTypeRef *ParamTypes, unsigned ParamCount, 235 int IsVarArg); 236int LLVMIsFunctionVarArg(LLVMTypeRef FunctionTy); 237LLVMTypeRef LLVMGetReturnType(LLVMTypeRef FunctionTy); 238unsigned LLVMCountParamTypes(LLVMTypeRef FunctionTy); 239void LLVMGetParamTypes(LLVMTypeRef FunctionTy, LLVMTypeRef *Dest); 240 241/* Operations on struct types */ 242LLVMTypeRef LLVMStructType(LLVMTypeRef *ElementTypes, unsigned ElementCount, 243 int Packed); 244unsigned LLVMCountStructElementTypes(LLVMTypeRef StructTy); 245void LLVMGetStructElementTypes(LLVMTypeRef StructTy, LLVMTypeRef *Dest); 246int LLVMIsPackedStruct(LLVMTypeRef StructTy); 247 248/* Operations on array, pointer, and vector types (sequence types) */ 249LLVMTypeRef LLVMArrayType(LLVMTypeRef ElementType, unsigned ElementCount); 250LLVMTypeRef LLVMPointerType(LLVMTypeRef ElementType, unsigned AddressSpace); 251LLVMTypeRef LLVMVectorType(LLVMTypeRef ElementType, unsigned ElementCount); 252 253LLVMTypeRef LLVMGetElementType(LLVMTypeRef Ty); 254unsigned LLVMGetArrayLength(LLVMTypeRef ArrayTy); 255unsigned LLVMGetPointerAddressSpace(LLVMTypeRef PointerTy); 256unsigned LLVMGetVectorSize(LLVMTypeRef VectorTy); 257 258/* Operations on other types */ 259LLVMTypeRef LLVMVoidType(); 260LLVMTypeRef LLVMLabelType(); 261LLVMTypeRef LLVMOpaqueType(); 262 263/* Operations on type handles */ 264LLVMTypeHandleRef LLVMCreateTypeHandle(LLVMTypeRef PotentiallyAbstractTy); 265void LLVMRefineType(LLVMTypeRef AbstractTy, LLVMTypeRef ConcreteTy); 266LLVMTypeRef LLVMResolveTypeHandle(LLVMTypeHandleRef TypeHandle); 267void LLVMDisposeTypeHandle(LLVMTypeHandleRef TypeHandle); 268 269 270/*===-- Values ------------------------------------------------------------===*/ 271 272/* The bulk of LLVM's object model consists of values, which comprise a very 273 * rich type hierarchy. 274 * 275 * values: 276 * constants: 277 * scalar constants 278 * composite contants 279 * globals: 280 * global variable 281 * function 282 * alias 283 * basic blocks 284 */ 285 286/* Operations on all values */ 287LLVMTypeRef LLVMTypeOf(LLVMValueRef Val); 288const char *LLVMGetValueName(LLVMValueRef Val); 289void LLVMSetValueName(LLVMValueRef Val, const char *Name); 290void LLVMDumpValue(LLVMValueRef Val); 291 292/* Operations on constants of any type */ 293LLVMValueRef LLVMConstNull(LLVMTypeRef Ty); /* all zeroes */ 294LLVMValueRef LLVMConstAllOnes(LLVMTypeRef Ty); /* only for int/vector */ 295LLVMValueRef LLVMGetUndef(LLVMTypeRef Ty); 296int LLVMIsConstant(LLVMValueRef Val); 297int LLVMIsNull(LLVMValueRef Val); 298int LLVMIsUndef(LLVMValueRef Val); 299 300/* Operations on scalar constants */ 301LLVMValueRef LLVMConstInt(LLVMTypeRef IntTy, unsigned long long N, 302 int SignExtend); 303LLVMValueRef LLVMConstReal(LLVMTypeRef RealTy, double N); 304LLVMValueRef LLVMConstRealOfString(LLVMTypeRef RealTy, const char *Text); 305 306/* Operations on composite constants */ 307LLVMValueRef LLVMConstString(const char *Str, unsigned Length, 308 int DontNullTerminate); 309LLVMValueRef LLVMConstArray(LLVMTypeRef ElementTy, 310 LLVMValueRef *ConstantVals, unsigned Length); 311LLVMValueRef LLVMConstStruct(LLVMValueRef *ConstantVals, unsigned Count, 312 int packed); 313LLVMValueRef LLVMConstVector(LLVMValueRef *ScalarConstantVals, unsigned Size); 314 315/* Constant expressions */ 316LLVMValueRef LLVMSizeOf(LLVMTypeRef Ty); 317LLVMValueRef LLVMConstNeg(LLVMValueRef ConstantVal); 318LLVMValueRef LLVMConstNot(LLVMValueRef ConstantVal); 319LLVMValueRef LLVMConstAdd(LLVMValueRef LHSConstant, LLVMValueRef RHSConstant); 320LLVMValueRef LLVMConstSub(LLVMValueRef LHSConstant, LLVMValueRef RHSConstant); 321LLVMValueRef LLVMConstMul(LLVMValueRef LHSConstant, LLVMValueRef RHSConstant); 322LLVMValueRef LLVMConstUDiv(LLVMValueRef LHSConstant, LLVMValueRef RHSConstant); 323LLVMValueRef LLVMConstSDiv(LLVMValueRef LHSConstant, LLVMValueRef RHSConstant); 324LLVMValueRef LLVMConstFDiv(LLVMValueRef LHSConstant, LLVMValueRef RHSConstant); 325LLVMValueRef LLVMConstURem(LLVMValueRef LHSConstant, LLVMValueRef RHSConstant); 326LLVMValueRef LLVMConstSRem(LLVMValueRef LHSConstant, LLVMValueRef RHSConstant); 327LLVMValueRef LLVMConstFRem(LLVMValueRef LHSConstant, LLVMValueRef RHSConstant); 328LLVMValueRef LLVMConstAnd(LLVMValueRef LHSConstant, LLVMValueRef RHSConstant); 329LLVMValueRef LLVMConstOr(LLVMValueRef LHSConstant, LLVMValueRef RHSConstant); 330LLVMValueRef LLVMConstXor(LLVMValueRef LHSConstant, LLVMValueRef RHSConstant); 331LLVMValueRef LLVMConstICmp(LLVMIntPredicate Predicate, 332 LLVMValueRef LHSConstant, LLVMValueRef RHSConstant); 333LLVMValueRef LLVMConstFCmp(LLVMRealPredicate Predicate, 334 LLVMValueRef LHSConstant, LLVMValueRef RHSConstant); 335LLVMValueRef LLVMConstShl(LLVMValueRef LHSConstant, LLVMValueRef RHSConstant); 336LLVMValueRef LLVMConstLShr(LLVMValueRef LHSConstant, LLVMValueRef RHSConstant); 337LLVMValueRef LLVMConstAShr(LLVMValueRef LHSConstant, LLVMValueRef RHSConstant); 338LLVMValueRef LLVMConstGEP(LLVMValueRef ConstantVal, 339 LLVMValueRef *ConstantIndices, unsigned NumIndices); 340LLVMValueRef LLVMConstTrunc(LLVMValueRef ConstantVal, LLVMTypeRef ToType); 341LLVMValueRef LLVMConstSExt(LLVMValueRef ConstantVal, LLVMTypeRef ToType); 342LLVMValueRef LLVMConstZExt(LLVMValueRef ConstantVal, LLVMTypeRef ToType); 343LLVMValueRef LLVMConstFPTrunc(LLVMValueRef ConstantVal, LLVMTypeRef ToType); 344LLVMValueRef LLVMConstFPExt(LLVMValueRef ConstantVal, LLVMTypeRef ToType); 345LLVMValueRef LLVMConstUIToFP(LLVMValueRef ConstantVal, LLVMTypeRef ToType); 346LLVMValueRef LLVMConstSIToFP(LLVMValueRef ConstantVal, LLVMTypeRef ToType); 347LLVMValueRef LLVMConstFPToUI(LLVMValueRef ConstantVal, LLVMTypeRef ToType); 348LLVMValueRef LLVMConstFPToSI(LLVMValueRef ConstantVal, LLVMTypeRef ToType); 349LLVMValueRef LLVMConstPtrToInt(LLVMValueRef ConstantVal, LLVMTypeRef ToType); 350LLVMValueRef LLVMConstIntToPtr(LLVMValueRef ConstantVal, LLVMTypeRef ToType); 351LLVMValueRef LLVMConstBitCast(LLVMValueRef ConstantVal, LLVMTypeRef ToType); 352LLVMValueRef LLVMConstSelect(LLVMValueRef ConstantCondition, 353 LLVMValueRef ConstantIfTrue, 354 LLVMValueRef ConstantIfFalse); 355LLVMValueRef LLVMConstExtractElement(LLVMValueRef VectorConstant, 356 LLVMValueRef IndexConstant); 357LLVMValueRef LLVMConstInsertElement(LLVMValueRef VectorConstant, 358 LLVMValueRef ElementValueConstant, 359 LLVMValueRef IndexConstant); 360LLVMValueRef LLVMConstShuffleVector(LLVMValueRef VectorAConstant, 361 LLVMValueRef VectorBConstant, 362 LLVMValueRef MaskConstant); 363 364/* Operations on global variables, functions, and aliases (globals) */ 365LLVMModuleRef LLVMGetGlobalParent(LLVMValueRef Global); 366int LLVMIsDeclaration(LLVMValueRef Global); 367LLVMLinkage LLVMGetLinkage(LLVMValueRef Global); 368void LLVMSetLinkage(LLVMValueRef Global, LLVMLinkage Linkage); 369const char *LLVMGetSection(LLVMValueRef Global); 370void LLVMSetSection(LLVMValueRef Global, const char *Section); 371LLVMVisibility LLVMGetVisibility(LLVMValueRef Global); 372void LLVMSetVisibility(LLVMValueRef Global, LLVMVisibility Viz); 373unsigned LLVMGetAlignment(LLVMValueRef Global); 374void LLVMSetAlignment(LLVMValueRef Global, unsigned Bytes); 375 376/* Operations on global variables */ 377LLVMValueRef LLVMAddGlobal(LLVMModuleRef M, LLVMTypeRef Ty, const char *Name); 378LLVMValueRef LLVMGetNamedGlobal(LLVMModuleRef M, const char *Name); 379LLVMValueRef LLVMGetFirstGlobal(LLVMModuleRef M); 380LLVMValueRef LLVMGetLastGlobal(LLVMModuleRef M); 381LLVMValueRef LLVMGetNextGlobal(LLVMValueRef GlobalVar); 382LLVMValueRef LLVMGetPreviousGlobal(LLVMValueRef GlobalVar); 383void LLVMDeleteGlobal(LLVMValueRef GlobalVar); 384int LLVMHasInitializer(LLVMValueRef GlobalVar); 385LLVMValueRef LLVMGetInitializer(LLVMValueRef GlobalVar); 386void LLVMSetInitializer(LLVMValueRef GlobalVar, LLVMValueRef ConstantVal); 387int LLVMIsThreadLocal(LLVMValueRef GlobalVar); 388void LLVMSetThreadLocal(LLVMValueRef GlobalVar, int IsThreadLocal); 389int LLVMIsGlobalConstant(LLVMValueRef GlobalVar); 390void LLVMSetGlobalConstant(LLVMValueRef GlobalVar, int IsConstant); 391 392/* Operations on functions */ 393LLVMValueRef LLVMAddFunction(LLVMModuleRef M, const char *Name, 394 LLVMTypeRef FunctionTy); 395LLVMValueRef LLVMGetNamedFunction(LLVMModuleRef M, const char *Name); 396LLVMValueRef LLVMGetFirstFunction(LLVMModuleRef M); 397LLVMValueRef LLVMGetLastFunction(LLVMModuleRef M); 398LLVMValueRef LLVMGetNextFunction(LLVMValueRef Fn); 399LLVMValueRef LLVMGetPreviousFunction(LLVMValueRef Fn); 400void LLVMDeleteFunction(LLVMValueRef Fn); 401unsigned LLVMGetIntrinsicID(LLVMValueRef Fn); 402unsigned LLVMGetFunctionCallConv(LLVMValueRef Fn); 403void LLVMSetFunctionCallConv(LLVMValueRef Fn, unsigned CC); 404const char *LLVMGetCollector(LLVMValueRef Fn); 405void LLVMSetCollector(LLVMValueRef Fn, const char *Coll); 406 407/* Operations on parameters */ 408unsigned LLVMCountParams(LLVMValueRef Fn); 409void LLVMGetParams(LLVMValueRef Fn, LLVMValueRef *Params); 410LLVMValueRef LLVMGetParam(LLVMValueRef Fn, unsigned Index); 411LLVMValueRef LLVMGetParamParent(LLVMValueRef Inst); 412LLVMValueRef LLVMGetFirstParam(LLVMValueRef Fn); 413LLVMValueRef LLVMGetLastParam(LLVMValueRef Fn); 414LLVMValueRef LLVMGetNextParam(LLVMValueRef Arg); 415LLVMValueRef LLVMGetPreviousParam(LLVMValueRef Arg); 416 417/* Operations on basic blocks */ 418LLVMValueRef LLVMBasicBlockAsValue(LLVMBasicBlockRef BB); 419int LLVMValueIsBasicBlock(LLVMValueRef Val); 420LLVMBasicBlockRef LLVMValueAsBasicBlock(LLVMValueRef Val); 421LLVMValueRef LLVMGetBasicBlockParent(LLVMBasicBlockRef BB); 422unsigned LLVMCountBasicBlocks(LLVMValueRef Fn); 423void LLVMGetBasicBlocks(LLVMValueRef Fn, LLVMBasicBlockRef *BasicBlocks); 424LLVMBasicBlockRef LLVMGetFirstBasicBlock(LLVMValueRef Fn); 425LLVMBasicBlockRef LLVMGetLastBasicBlock(LLVMValueRef Fn); 426LLVMBasicBlockRef LLVMGetNextBasicBlock(LLVMBasicBlockRef BB); 427LLVMBasicBlockRef LLVMGetPreviousBasicBlock(LLVMBasicBlockRef BB); 428LLVMBasicBlockRef LLVMGetEntryBasicBlock(LLVMValueRef Fn); 429LLVMBasicBlockRef LLVMAppendBasicBlock(LLVMValueRef Fn, const char *Name); 430LLVMBasicBlockRef LLVMInsertBasicBlock(LLVMBasicBlockRef InsertBeforeBB, 431 const char *Name); 432void LLVMDeleteBasicBlock(LLVMBasicBlockRef BB); 433 434/* Operations on instructions */ 435LLVMBasicBlockRef LLVMGetInstructionParent(LLVMValueRef Inst); 436LLVMValueRef LLVMGetFirstInstruction(LLVMBasicBlockRef BB); 437LLVMValueRef LLVMGetLastInstruction(LLVMBasicBlockRef BB); 438LLVMValueRef LLVMGetNextInstruction(LLVMValueRef Inst); 439LLVMValueRef LLVMGetPreviousInstruction(LLVMValueRef Inst); 440 441/* Operations on call sites */ 442void LLVMSetInstructionCallConv(LLVMValueRef Instr, unsigned CC); 443unsigned LLVMGetInstructionCallConv(LLVMValueRef Instr); 444 445/* Operations on phi nodes */ 446void LLVMAddIncoming(LLVMValueRef PhiNode, LLVMValueRef *IncomingValues, 447 LLVMBasicBlockRef *IncomingBlocks, unsigned Count); 448unsigned LLVMCountIncoming(LLVMValueRef PhiNode); 449LLVMValueRef LLVMGetIncomingValue(LLVMValueRef PhiNode, unsigned Index); 450LLVMBasicBlockRef LLVMGetIncomingBlock(LLVMValueRef PhiNode, unsigned Index); 451 452/*===-- Instruction builders ----------------------------------------------===*/ 453 454/* An instruction builder represents a point within a basic block, and is the 455 * exclusive means of building instructions using the C interface. 456 */ 457 458LLVMBuilderRef LLVMCreateBuilder(); 459void LLVMPositionBuilder(LLVMBuilderRef Builder, LLVMBasicBlockRef Block, 460 LLVMValueRef Instr); 461void LLVMPositionBuilderBefore(LLVMBuilderRef Builder, LLVMValueRef Instr); 462void LLVMPositionBuilderAtEnd(LLVMBuilderRef Builder, LLVMBasicBlockRef Block); 463LLVMBasicBlockRef LLVMGetInsertBlock(LLVMBuilderRef Builder); 464void LLVMDisposeBuilder(LLVMBuilderRef Builder); 465 466/* Terminators */ 467LLVMValueRef LLVMBuildRetVoid(LLVMBuilderRef); 468LLVMValueRef LLVMBuildRet(LLVMBuilderRef, LLVMValueRef V); 469LLVMValueRef LLVMBuildBr(LLVMBuilderRef, LLVMBasicBlockRef Dest); 470LLVMValueRef LLVMBuildCondBr(LLVMBuilderRef, LLVMValueRef If, 471 LLVMBasicBlockRef Then, LLVMBasicBlockRef Else); 472LLVMValueRef LLVMBuildSwitch(LLVMBuilderRef, LLVMValueRef V, 473 LLVMBasicBlockRef Else, unsigned NumCases); 474LLVMValueRef LLVMBuildInvoke(LLVMBuilderRef, LLVMValueRef Fn, 475 LLVMValueRef *Args, unsigned NumArgs, 476 LLVMBasicBlockRef Then, LLVMBasicBlockRef Catch, 477 const char *Name); 478LLVMValueRef LLVMBuildUnwind(LLVMBuilderRef); 479LLVMValueRef LLVMBuildUnreachable(LLVMBuilderRef); 480 481/* Add a case to the switch instruction */ 482void LLVMAddCase(LLVMValueRef Switch, LLVMValueRef OnVal, 483 LLVMBasicBlockRef Dest); 484 485/* Arithmetic */ 486LLVMValueRef LLVMBuildAdd(LLVMBuilderRef, LLVMValueRef LHS, LLVMValueRef RHS, 487 const char *Name); 488LLVMValueRef LLVMBuildSub(LLVMBuilderRef, LLVMValueRef LHS, LLVMValueRef RHS, 489 const char *Name); 490LLVMValueRef LLVMBuildMul(LLVMBuilderRef, LLVMValueRef LHS, LLVMValueRef RHS, 491 const char *Name); 492LLVMValueRef LLVMBuildUDiv(LLVMBuilderRef, LLVMValueRef LHS, LLVMValueRef RHS, 493 const char *Name); 494LLVMValueRef LLVMBuildSDiv(LLVMBuilderRef, LLVMValueRef LHS, LLVMValueRef RHS, 495 const char *Name); 496LLVMValueRef LLVMBuildFDiv(LLVMBuilderRef, LLVMValueRef LHS, LLVMValueRef RHS, 497 const char *Name); 498LLVMValueRef LLVMBuildURem(LLVMBuilderRef, LLVMValueRef LHS, LLVMValueRef RHS, 499 const char *Name); 500LLVMValueRef LLVMBuildSRem(LLVMBuilderRef, LLVMValueRef LHS, LLVMValueRef RHS, 501 const char *Name); 502LLVMValueRef LLVMBuildFRem(LLVMBuilderRef, LLVMValueRef LHS, LLVMValueRef RHS, 503 const char *Name); 504LLVMValueRef LLVMBuildShl(LLVMBuilderRef, LLVMValueRef LHS, LLVMValueRef RHS, 505 const char *Name); 506LLVMValueRef LLVMBuildLShr(LLVMBuilderRef, LLVMValueRef LHS, LLVMValueRef RHS, 507 const char *Name); 508LLVMValueRef LLVMBuildAShr(LLVMBuilderRef, LLVMValueRef LHS, LLVMValueRef RHS, 509 const char *Name); 510LLVMValueRef LLVMBuildAnd(LLVMBuilderRef, LLVMValueRef LHS, LLVMValueRef RHS, 511 const char *Name); 512LLVMValueRef LLVMBuildOr(LLVMBuilderRef, LLVMValueRef LHS, LLVMValueRef RHS, 513 const char *Name); 514LLVMValueRef LLVMBuildXor(LLVMBuilderRef, LLVMValueRef LHS, LLVMValueRef RHS, 515 const char *Name); 516LLVMValueRef LLVMBuildNeg(LLVMBuilderRef, LLVMValueRef V, const char *Name); 517LLVMValueRef LLVMBuildNot(LLVMBuilderRef, LLVMValueRef V, const char *Name); 518 519/* Memory */ 520LLVMValueRef LLVMBuildMalloc(LLVMBuilderRef, LLVMTypeRef Ty, const char *Name); 521LLVMValueRef LLVMBuildArrayMalloc(LLVMBuilderRef, LLVMTypeRef Ty, 522 LLVMValueRef Val, const char *Name); 523LLVMValueRef LLVMBuildAlloca(LLVMBuilderRef, LLVMTypeRef Ty, const char *Name); 524LLVMValueRef LLVMBuildArrayAlloca(LLVMBuilderRef, LLVMTypeRef Ty, 525 LLVMValueRef Val, const char *Name); 526LLVMValueRef LLVMBuildFree(LLVMBuilderRef, LLVMValueRef PointerVal); 527LLVMValueRef LLVMBuildLoad(LLVMBuilderRef, LLVMValueRef PointerVal, 528 const char *Name); 529LLVMValueRef LLVMBuildStore(LLVMBuilderRef, LLVMValueRef Val, LLVMValueRef Ptr); 530LLVMValueRef LLVMBuildGEP(LLVMBuilderRef B, LLVMValueRef Pointer, 531 LLVMValueRef *Indices, unsigned NumIndices, 532 const char *Name); 533 534/* Casts */ 535LLVMValueRef LLVMBuildTrunc(LLVMBuilderRef, LLVMValueRef Val, 536 LLVMTypeRef DestTy, const char *Name); 537LLVMValueRef LLVMBuildZExt(LLVMBuilderRef, LLVMValueRef Val, 538 LLVMTypeRef DestTy, const char *Name); 539LLVMValueRef LLVMBuildSExt(LLVMBuilderRef, LLVMValueRef Val, 540 LLVMTypeRef DestTy, const char *Name); 541LLVMValueRef LLVMBuildFPToUI(LLVMBuilderRef, LLVMValueRef Val, 542 LLVMTypeRef DestTy, const char *Name); 543LLVMValueRef LLVMBuildFPToSI(LLVMBuilderRef, LLVMValueRef Val, 544 LLVMTypeRef DestTy, const char *Name); 545LLVMValueRef LLVMBuildUIToFP(LLVMBuilderRef, LLVMValueRef Val, 546 LLVMTypeRef DestTy, const char *Name); 547LLVMValueRef LLVMBuildSIToFP(LLVMBuilderRef, LLVMValueRef Val, 548 LLVMTypeRef DestTy, const char *Name); 549LLVMValueRef LLVMBuildFPTrunc(LLVMBuilderRef, LLVMValueRef Val, 550 LLVMTypeRef DestTy, const char *Name); 551LLVMValueRef LLVMBuildFPExt(LLVMBuilderRef, LLVMValueRef Val, 552 LLVMTypeRef DestTy, const char *Name); 553LLVMValueRef LLVMBuildPtrToInt(LLVMBuilderRef, LLVMValueRef Val, 554 LLVMTypeRef DestTy, const char *Name); 555LLVMValueRef LLVMBuildIntToPtr(LLVMBuilderRef, LLVMValueRef Val, 556 LLVMTypeRef DestTy, const char *Name); 557LLVMValueRef LLVMBuildBitCast(LLVMBuilderRef, LLVMValueRef Val, 558 LLVMTypeRef DestTy, const char *Name); 559 560/* Comparisons */ 561LLVMValueRef LLVMBuildICmp(LLVMBuilderRef, LLVMIntPredicate Op, 562 LLVMValueRef LHS, LLVMValueRef RHS, 563 const char *Name); 564LLVMValueRef LLVMBuildFCmp(LLVMBuilderRef, LLVMRealPredicate Op, 565 LLVMValueRef LHS, LLVMValueRef RHS, 566 const char *Name); 567 568/* Miscellaneous instructions */ 569LLVMValueRef LLVMBuildPhi(LLVMBuilderRef, LLVMTypeRef Ty, const char *Name); 570LLVMValueRef LLVMBuildCall(LLVMBuilderRef, LLVMValueRef Fn, 571 LLVMValueRef *Args, unsigned NumArgs, 572 const char *Name); 573LLVMValueRef LLVMBuildSelect(LLVMBuilderRef, LLVMValueRef If, 574 LLVMValueRef Then, LLVMValueRef Else, 575 const char *Name); 576LLVMValueRef LLVMBuildVAArg(LLVMBuilderRef, LLVMValueRef List, LLVMTypeRef Ty, 577 const char *Name); 578LLVMValueRef LLVMBuildExtractElement(LLVMBuilderRef, LLVMValueRef VecVal, 579 LLVMValueRef Index, const char *Name); 580LLVMValueRef LLVMBuildInsertElement(LLVMBuilderRef, LLVMValueRef VecVal, 581 LLVMValueRef EltVal, LLVMValueRef Index, 582 const char *Name); 583LLVMValueRef LLVMBuildShuffleVector(LLVMBuilderRef, LLVMValueRef V1, 584 LLVMValueRef V2, LLVMValueRef Mask, 585 const char *Name); 586 587 588/*===-- Module providers --------------------------------------------------===*/ 589 590/* Encapsulates the module M in a module provider, taking ownership of the 591 * module. 592 * See the constructor llvm::ExistingModuleProvider::ExistingModuleProvider. 593 */ 594LLVMModuleProviderRef 595LLVMCreateModuleProviderForExistingModule(LLVMModuleRef M); 596 597/* Destroys the module provider MP as well as the contained module. 598 * See the destructor llvm::ModuleProvider::~ModuleProvider. 599 */ 600void LLVMDisposeModuleProvider(LLVMModuleProviderRef MP); 601 602 603/*===-- Memory buffers ----------------------------------------------------===*/ 604 605int LLVMCreateMemoryBufferWithContentsOfFile(const char *Path, 606 LLVMMemoryBufferRef *OutMemBuf, 607 char **OutMessage); 608int LLVMCreateMemoryBufferWithSTDIN(LLVMMemoryBufferRef *OutMemBuf, 609 char **OutMessage); 610void LLVMDisposeMemoryBuffer(LLVMMemoryBufferRef MemBuf); 611 612 613/*===-- Pass Managers -----------------------------------------------------===*/ 614 615/** Constructs a new whole-module pass pipeline. This type of pipeline is 616 suitable for link-time optimization and whole-module transformations. 617 See llvm::PassManager::PassManager. */ 618LLVMPassManagerRef LLVMCreatePassManager(); 619 620/** Constructs a new function-by-function pass pipeline over the module 621 provider. It does not take ownership of the module provider. This type of 622 pipeline is suitable for code generation and JIT compilation tasks. 623 See llvm::FunctionPassManager::FunctionPassManager. */ 624LLVMPassManagerRef LLVMCreateFunctionPassManager(LLVMModuleProviderRef MP); 625 626/** Initializes, executes on the provided module, and finalizes all of the 627 passes scheduled in the pass manager. Returns 1 if any of the passes 628 modified the module, 0 otherwise. See llvm::PassManager::run(Module&). */ 629int LLVMRunPassManager(LLVMPassManagerRef PM, LLVMModuleRef M); 630 631/** Initializes all of the function passes scheduled in the function pass 632 manager. Returns 1 if any of the passes modified the module, 0 otherwise. 633 See llvm::FunctionPassManager::doInitialization. */ 634int LLVMInitializeFunctionPassManager(LLVMPassManagerRef FPM); 635 636/** Executes all of the function passes scheduled in the function pass manager 637 on the provided function. Returns 1 if any of the passes modified the 638 function, false otherwise. 639 See llvm::FunctionPassManager::run(Function&). */ 640int LLVMRunFunctionPassManager(LLVMPassManagerRef FPM, LLVMValueRef F); 641 642/** Finalizes all of the function passes scheduled in in the function pass 643 manager. Returns 1 if any of the passes modified the module, 0 otherwise. 644 See llvm::FunctionPassManager::doFinalization. */ 645int LLVMFinalizeFunctionPassManager(LLVMPassManagerRef FPM); 646 647/** Frees the memory of a pass pipeline. For function pipelines, does not free 648 the module provider. 649 See llvm::PassManagerBase::~PassManagerBase. */ 650void LLVMDisposePassManager(LLVMPassManagerRef PM); 651 652 653#ifdef __cplusplus 654} 655 656namespace llvm { 657 class ModuleProvider; 658 class MemoryBuffer; 659 class PassManagerBase; 660 661 #define DEFINE_SIMPLE_CONVERSION_FUNCTIONS(ty, ref) \ 662 inline ty *unwrap(ref P) { \ 663 return reinterpret_cast<ty*>(P); \ 664 } \ 665 \ 666 inline ref wrap(const ty *P) { \ 667 return reinterpret_cast<ref>(const_cast<ty*>(P)); \ 668 } 669 670 #define DEFINE_ISA_CONVERSION_FUNCTIONS(ty, ref) \ 671 DEFINE_SIMPLE_CONVERSION_FUNCTIONS(ty, ref) \ 672 \ 673 template<typename T> \ 674 inline T *unwrap(ref P) { \ 675 return cast<T>(unwrap(P)); \ 676 } 677 678 #define DEFINE_STDCXX_CONVERSION_FUNCTIONS(ty, ref) \ 679 DEFINE_SIMPLE_CONVERSION_FUNCTIONS(ty, ref) \ 680 \ 681 template<typename T> \ 682 inline T *unwrap(ref P) { \ 683 T *Q = dynamic_cast<T*>(unwrap(P)); \ 684 assert(Q && "Invalid cast!"); \ 685 return Q; \ 686 } 687 688 DEFINE_ISA_CONVERSION_FUNCTIONS (Type, LLVMTypeRef ) 689 DEFINE_ISA_CONVERSION_FUNCTIONS (Value, LLVMValueRef ) 690 DEFINE_SIMPLE_CONVERSION_FUNCTIONS(Module, LLVMModuleRef ) 691 DEFINE_SIMPLE_CONVERSION_FUNCTIONS(BasicBlock, LLVMBasicBlockRef ) 692 DEFINE_SIMPLE_CONVERSION_FUNCTIONS(IRBuilder, LLVMBuilderRef ) 693 DEFINE_SIMPLE_CONVERSION_FUNCTIONS(PATypeHolder, LLVMTypeHandleRef ) 694 DEFINE_SIMPLE_CONVERSION_FUNCTIONS(ModuleProvider, LLVMModuleProviderRef) 695 DEFINE_SIMPLE_CONVERSION_FUNCTIONS(MemoryBuffer, LLVMMemoryBufferRef ) 696 DEFINE_STDCXX_CONVERSION_FUNCTIONS(PassManagerBase, LLVMPassManagerRef ) 697 698 #undef DEFINE_STDCXX_CONVERSION_FUNCTIONS 699 #undef DEFINE_ISA_CONVERSION_FUNCTIONS 700 #undef DEFINE_SIMPLE_CONVERSION_FUNCTIONS 701 702 /* Specialized opaque type conversions. 703 */ 704 inline Type **unwrap(LLVMTypeRef* Tys) { 705 return reinterpret_cast<Type**>(Tys); 706 } 707 708 inline LLVMTypeRef *wrap(const Type **Tys) { 709 return reinterpret_cast<LLVMTypeRef*>(const_cast<Type**>(Tys)); 710 } 711 712 /* Specialized opaque value conversions. 713 */ 714 inline Value **unwrap(LLVMValueRef *Vals) { 715 return reinterpret_cast<Value**>(Vals); 716 } 717 718 template<typename T> 719 inline T **unwrap(LLVMValueRef *Vals, unsigned Length) { 720 #if DEBUG 721 for (LLVMValueRef *I = Vals, E = Vals + Length; I != E; ++I) 722 cast<T>(*I); 723 #endif 724 return reinterpret_cast<T**>(Vals); 725 } 726 727 inline LLVMValueRef *wrap(const Value **Vals) { 728 return reinterpret_cast<LLVMValueRef*>(const_cast<Value**>(Vals)); 729 } 730} 731 732#endif /* !defined(__cplusplus) */ 733 734#endif /* !defined(LLVM_C_CORE_H) */ 735