X-Git-Url: http://plrg.eecs.uci.edu/git/?p=oota-llvm.git;a=blobdiff_plain;f=include%2Fllvm-c%2FCore.h;h=6c4b5de2b6ab9f9ca821a27c9e412fe45bbe738b;hp=696ef6a168b1e347dd19c4d52979e719e6b7b1c4;hb=d78c0f5a7255e4347cbd82f7435c51401096652c;hpb=1ae6135fa37eb061499d079b9b33dc82dcc1283f diff --git a/include/llvm-c/Core.h b/include/llvm-c/Core.h index 696ef6a168b..6c4b5de2b6a 100644 --- a/include/llvm-c/Core.h +++ b/include/llvm-c/Core.h @@ -2,8 +2,8 @@ |* *| |* The LLVM Compiler Infrastructure *| |* *| -|* This file was developed by Gordon Henriksen and is distributed under the *| -|* University of Illinois Open Source License. See LICENSE.TXT for details. *| +|* This file is distributed under the University of Illinois Open Source *| +|* License. See LICENSE.TXT for details. *| |* *| |*===----------------------------------------------------------------------===*| |* *| @@ -39,53 +39,86 @@ and 'unwrap' conversion functions. */ #include "llvm/Module.h" #include "llvm/Support/LLVMBuilder.h" +#include "llvm/Pass.h" +#include "llvm/PassManager.h" extern "C" { #endif /* Opaque types. */ + +/** + * The top-level container for all other LLVM Intermediate Representation (IR) + * objects. See the llvm::Module class. + */ typedef struct LLVMOpaqueModule *LLVMModuleRef; + +/** + * Each value in the LLVM IR has a type, an LLVMTypeRef. See the llvm::Type + * class. + */ typedef struct LLVMOpaqueType *LLVMTypeRef; + +/** + * When building recursive types using LLVMRefineType, LLVMTypeRef values may + * become invalid; use LLVMTypeHandleRef to resolve this problem. See the + * llvm::AbstractTypeHolder class. + */ typedef struct LLVMOpaqueTypeHandle *LLVMTypeHandleRef; + typedef struct LLVMOpaqueValue *LLVMValueRef; typedef struct LLVMOpaqueBasicBlock *LLVMBasicBlockRef; typedef struct LLVMOpaqueBuilder *LLVMBuilderRef; + +/* Used to provide a module to JIT or interpreter. + * See the llvm::ModuleProvider class. + */ typedef struct LLVMOpaqueModuleProvider *LLVMModuleProviderRef; +/* Used to provide a module to JIT or interpreter. + * See the llvm::MemoryBuffer class. + */ +typedef struct LLVMOpaqueMemoryBuffer *LLVMMemoryBufferRef; + +/** See the llvm::PassManagerBase class. */ +typedef struct LLVMOpaquePassManager *LLVMPassManagerRef; + typedef enum { - LLVMVoidTypeKind, /* type with no size */ - LLVMFloatTypeKind, /* 32 bit floating point type */ - LLVMDoubleTypeKind, /* 64 bit floating point type */ - LLVMX86_FP80TypeKind, /* 80 bit floating point type (X87) */ - LLVMFP128TypeKind, /* 128 bit floating point type (112-bit mantissa) */ - LLVMPPC_FP128TypeKind, /* 128 bit floating point type (two 64-bits) */ - LLVMLabelTypeKind, /* Labels */ - LLVMIntegerTypeKind, /* Arbitrary bit width integers */ - LLVMFunctionTypeKind, /* Functions */ - LLVMStructTypeKind, /* Structures */ - LLVMArrayTypeKind, /* Arrays */ - LLVMPointerTypeKind, /* Pointers */ - LLVMOpaqueTypeKind, /* Opaque: type with unknown structure */ - LLVMVectorTypeKind /* SIMD 'packed' format, or other vector type */ + LLVMVoidTypeKind, /**< type with no size */ + LLVMFloatTypeKind, /**< 32 bit floating point type */ + LLVMDoubleTypeKind, /**< 64 bit floating point type */ + LLVMX86_FP80TypeKind, /**< 80 bit floating point type (X87) */ + LLVMFP128TypeKind, /**< 128 bit floating point type (112-bit mantissa)*/ + LLVMPPC_FP128TypeKind, /**< 128 bit floating point type (two 64-bits) */ + LLVMLabelTypeKind, /**< Labels */ + LLVMIntegerTypeKind, /**< Arbitrary bit width integers */ + LLVMFunctionTypeKind, /**< Functions */ + LLVMStructTypeKind, /**< Structures */ + LLVMArrayTypeKind, /**< Arrays */ + LLVMPointerTypeKind, /**< Pointers */ + LLVMOpaqueTypeKind, /**< Opaque: type with unknown structure */ + LLVMVectorTypeKind /**< SIMD 'packed' format, or other vector type */ } LLVMTypeKind; typedef enum { - LLVMExternalLinkage, /* Externally visible function */ - LLVMLinkOnceLinkage, /* Keep one copy of function when linking (inline) */ - LLVMWeakLinkage, /* Keep one copy of function when linking (weak) */ - LLVMAppendingLinkage, /* Special purpose, only applies to global arrays */ - LLVMInternalLinkage, /* Rename collisions when linking (static functions)*/ - LLVMDLLImportLinkage, /* Function to be imported from DLL */ - LLVMDLLExportLinkage, /* Function to be accessible from DLL */ - LLVMExternalWeakLinkage,/* ExternalWeak linkage description */ - LLVMGhostLinkage /* Stand-in functions for streaming fns from bitcode*/ + LLVMExternalLinkage, /**< Externally visible function */ + LLVMLinkOnceLinkage, /**< Keep one copy of function when linking (inline)*/ + LLVMWeakLinkage, /**< Keep one copy of function when linking (weak) */ + LLVMAppendingLinkage, /**< Special purpose, only applies to global arrays */ + LLVMInternalLinkage, /**< Rename collisions when linking (static + functions) */ + LLVMDLLImportLinkage, /**< Function to be imported from DLL */ + LLVMDLLExportLinkage, /**< Function to be accessible from DLL */ + LLVMExternalWeakLinkage,/**< ExternalWeak linkage description */ + LLVMGhostLinkage /**< Stand-in functions for streaming fns from + bitcode */ } LLVMLinkage; typedef enum { - LLVMDefaultVisibility, /* The GV is visible */ - LLVMHiddenVisibility, /* The GV is hidden */ - LLVMProtectedVisibility /* The GV is protected */ + LLVMDefaultVisibility, /**< The GV is visible */ + LLVMHiddenVisibility, /**< The GV is hidden */ + LLVMProtectedVisibility /**< The GV is protected */ } LLVMVisibility; typedef enum { @@ -97,48 +130,67 @@ typedef enum { } LLVMCallConv; typedef enum { - LLVMIntEQ = 32, /* equal */ - LLVMIntNE, /* not equal */ - LLVMIntUGT, /* unsigned greater than */ - LLVMIntUGE, /* unsigned greater or equal */ - LLVMIntULT, /* unsigned less than */ - LLVMIntULE, /* unsigned less or equal */ - LLVMIntSGT, /* signed greater than */ - LLVMIntSGE, /* signed greater or equal */ - LLVMIntSLT, /* signed less than */ - LLVMIntSLE /* signed less or equal */ + LLVMIntEQ = 32, /**< equal */ + LLVMIntNE, /**< not equal */ + LLVMIntUGT, /**< unsigned greater than */ + LLVMIntUGE, /**< unsigned greater or equal */ + LLVMIntULT, /**< unsigned less than */ + LLVMIntULE, /**< unsigned less or equal */ + LLVMIntSGT, /**< signed greater than */ + LLVMIntSGE, /**< signed greater or equal */ + LLVMIntSLT, /**< signed less than */ + LLVMIntSLE /**< signed less or equal */ } LLVMIntPredicate; typedef enum { - LLVMRealPredicateFalse, /* Always false (always folded) */ - LLVMRealOEQ, /* True if ordered and equal */ - LLVMRealOGT, /* True if ordered and greater than */ - LLVMRealOGE, /* True if ordered and greater than or equal */ - LLVMRealOLT, /* True if ordered and less than */ - LLVMRealOLE, /* True if ordered and less than or equal */ - LLVMRealONE, /* True if ordered and operands are unequal */ - LLVMRealORD, /* True if ordered (no nans) */ - LLVMRealUNO, /* True if unordered: isnan(X) | isnan(Y) */ - LLVMRealUEQ, /* True if unordered or equal */ - LLVMRealUGT, /* True if unordered or greater than */ - LLVMRealUGE, /* True if unordered, greater than, or equal */ - LLVMRealULT, /* True if unordered or less than */ - LLVMRealULE, /* True if unordered, less than, or equal */ - LLVMRealUNE, /* True if unordered or not equal */ - LLVMRealPredicateTrue /* Always true (always folded) */ + LLVMRealPredicateFalse, /**< Always false (always folded) */ + LLVMRealOEQ, /**< True if ordered and equal */ + LLVMRealOGT, /**< True if ordered and greater than */ + LLVMRealOGE, /**< True if ordered and greater than or equal */ + LLVMRealOLT, /**< True if ordered and less than */ + LLVMRealOLE, /**< True if ordered and less than or equal */ + LLVMRealONE, /**< True if ordered and operands are unequal */ + LLVMRealORD, /**< True if ordered (no nans) */ + LLVMRealUNO, /**< True if unordered: isnan(X) | isnan(Y) */ + LLVMRealUEQ, /**< True if unordered or equal */ + LLVMRealUGT, /**< True if unordered or greater than */ + LLVMRealUGE, /**< True if unordered, greater than, or equal */ + LLVMRealULT, /**< True if unordered or less than */ + LLVMRealULE, /**< True if unordered, less than, or equal */ + LLVMRealUNE, /**< True if unordered or not equal */ + LLVMRealPredicateTrue /**< Always true (always folded) */ } LLVMRealPredicate; +/*===-- Error handling ----------------------------------------------------===*/ + +void LLVMDisposeMessage(char *Message); + + /*===-- Modules -----------------------------------------------------------===*/ /* Create and destroy modules. */ +/** See llvm::Module::Module. */ LLVMModuleRef LLVMModuleCreateWithName(const char *ModuleID); + +/** See llvm::Module::~Module. */ void LLVMDisposeModule(LLVMModuleRef M); -/* Same as Module::addTypeName. */ +/** Data layout. See Module::getDataLayout. */ +const char *LLVMGetDataLayout(LLVMModuleRef M); +void LLVMSetDataLayout(LLVMModuleRef M, const char *Triple); + +/** Target triple. See Module::getTargetTriple. */ +const char *LLVMGetTarget(LLVMModuleRef M); +void LLVMSetTarget(LLVMModuleRef M, const char *Triple); + +/** See Module::addTypeName. */ int LLVMAddTypeName(LLVMModuleRef M, const char *Name, LLVMTypeRef Ty); void LLVMDeleteTypeName(LLVMModuleRef M, const char *Name); +/** See Module::dump. */ +void LLVMDumpModule(LLVMModuleRef M); + /*===-- Types -------------------------------------------------------------===*/ @@ -157,7 +209,10 @@ void LLVMDeleteTypeName(LLVMModuleRef M, const char *Name); * opaque type */ +/** See llvm::LLVMTypeKind::getTypeID. */ LLVMTypeKind LLVMGetTypeKind(LLVMTypeRef Ty); + +/** See llvm::DerivedType::refineAbstractTypeTo. */ void LLVMRefineAbstractType(LLVMTypeRef AbstractType, LLVMTypeRef ConcreteType); /* Operations on integer types */ @@ -194,11 +249,12 @@ int LLVMIsPackedStruct(LLVMTypeRef StructTy); /* Operations on array, pointer, and vector types (sequence types) */ LLVMTypeRef LLVMArrayType(LLVMTypeRef ElementType, unsigned ElementCount); -LLVMTypeRef LLVMPointerType(LLVMTypeRef ElementType); +LLVMTypeRef LLVMPointerType(LLVMTypeRef ElementType, unsigned AddressSpace); LLVMTypeRef LLVMVectorType(LLVMTypeRef ElementType, unsigned ElementCount); LLVMTypeRef LLVMGetElementType(LLVMTypeRef Ty); unsigned LLVMGetArrayLength(LLVMTypeRef ArrayTy); +unsigned LLVMGetPointerAddressSpace(LLVMTypeRef PointerTy); unsigned LLVMGetVectorSize(LLVMTypeRef VectorTy); /* Operations on other types */ @@ -247,6 +303,7 @@ int LLVMIsUndef(LLVMValueRef Val); LLVMValueRef LLVMConstInt(LLVMTypeRef IntTy, unsigned long long N, int SignExtend); LLVMValueRef LLVMConstReal(LLVMTypeRef RealTy, double N); +LLVMValueRef LLVMConstRealOfString(LLVMTypeRef RealTy, const char *Text); /* Operations on composite constants */ LLVMValueRef LLVMConstString(const char *Str, unsigned Length, @@ -355,6 +412,10 @@ LLVMBasicBlockRef LLVMInsertBasicBlock(LLVMBasicBlockRef InsertBeforeBB, const char *Name); void LLVMDeleteBasicBlock(LLVMBasicBlockRef BB); +/* Operations on call sites */ +void LLVMSetInstructionCallConv(LLVMValueRef Instr, unsigned CC); +unsigned LLVMGetInstructionCallConv(LLVMValueRef Instr); + /* Operations on phi nodes */ void LLVMAddIncoming(LLVMValueRef PhiNode, LLVMValueRef *IncomingValues, LLVMBasicBlockRef *IncomingBlocks, unsigned Count); @@ -388,6 +449,10 @@ LLVMValueRef LLVMBuildInvoke(LLVMBuilderRef, LLVMValueRef Fn, LLVMValueRef LLVMBuildUnwind(LLVMBuilderRef); LLVMValueRef LLVMBuildUnreachable(LLVMBuilderRef); +/* Add a case to the switch instruction */ +void LLVMAddCase(LLVMValueRef Switch, LLVMValueRef OnVal, + LLVMBasicBlockRef Dest); + /* Arithmetic */ LLVMValueRef LLVMBuildAdd(LLVMBuilderRef, LLVMValueRef LHS, LLVMValueRef RHS, const char *Name); @@ -490,6 +555,7 @@ LLVMValueRef LLVMBuildShuffleVector(LLVMBuilderRef, LLVMValueRef V1, LLVMValueRef V2, LLVMValueRef Mask, const char *Name); + /*===-- Module providers --------------------------------------------------===*/ /* Encapsulates the module M in a module provider, taking ownership of the @@ -504,56 +570,117 @@ LLVMCreateModuleProviderForExistingModule(LLVMModuleRef M); */ void LLVMDisposeModuleProvider(LLVMModuleProviderRef MP); + +/*===-- Memory buffers ----------------------------------------------------===*/ + +int LLVMCreateMemoryBufferWithContentsOfFile(const char *Path, + LLVMMemoryBufferRef *OutMemBuf, + char **OutMessage); +int LLVMCreateMemoryBufferWithSTDIN(LLVMMemoryBufferRef *OutMemBuf, + char **OutMessage); +void LLVMDisposeMemoryBuffer(LLVMMemoryBufferRef MemBuf); + + +/*===-- Pass Managers -----------------------------------------------------===*/ + +/** Constructs a new whole-module pass pipeline. This type of pipeline is + suitable for link-time optimization and whole-module transformations. + See llvm::PassManager::PassManager. */ +LLVMPassManagerRef LLVMCreatePassManager(); + +/** Constructs a new function-by-function pass pipeline over the module + provider. It does not take ownership of the module provider. This type of + pipeline is suitable for code generation and JIT compilation tasks. + See llvm::FunctionPassManager::FunctionPassManager. */ +LLVMPassManagerRef LLVMCreateFunctionPassManager(LLVMModuleProviderRef MP); + +/** Initializes, executes on the provided module, and finalizes all of the + passes scheduled in the pass manager. Returns 1 if any of the passes + modified the module, 0 otherwise. See llvm::PassManager::run(Module&). */ +int LLVMRunPassManager(LLVMPassManagerRef PM, LLVMModuleRef M); + +/** Initializes all of the function passes scheduled in the function pass + manager. Returns 1 if any of the passes modified the module, 0 otherwise. + See llvm::FunctionPassManager::doInitialization. */ +int LLVMInitializeFunctionPassManager(LLVMPassManagerRef FPM); + +/** Executes all of the function passes scheduled in the function pass manager + on the provided function. Returns 1 if any of the passes modified the + function, false otherwise. + See llvm::FunctionPassManager::run(Function&). */ +int LLVMRunFunctionPassManager(LLVMPassManagerRef FPM, LLVMValueRef F); + +/** Finalizes all of the function passes scheduled in in the function pass + manager. Returns 1 if any of the passes modified the module, 0 otherwise. + See llvm::FunctionPassManager::doFinalization. */ +int LLVMFinalizeFunctionPassManager(LLVMPassManagerRef FPM); + +/** Frees the memory of a pass pipeline. For function pipelines, does not free + the module provider. + See llvm::PassManagerBase::~PassManagerBase. */ +void LLVMDisposePassManager(LLVMPassManagerRef PM); + + #ifdef __cplusplus } namespace llvm { class ModuleProvider; + class MemoryBuffer; - /* Opaque module conversions - */ - inline Module *unwrap(LLVMModuleRef M) { - return reinterpret_cast(M); - } + #define DEFINE_SIMPLE_CONVERSION_FUNCTIONS(ty, ref) \ + inline ty *unwrap(ref P) { \ + return reinterpret_cast(P); \ + } \ + \ + inline ref wrap(const ty *P) { \ + return reinterpret_cast(const_cast(P)); \ + } - inline LLVMModuleRef wrap(Module *M) { - return reinterpret_cast(M); - } + #define DEFINE_ISA_CONVERSION_FUNCTIONS(ty, ref) \ + DEFINE_SIMPLE_CONVERSION_FUNCTIONS(ty, ref) \ + \ + template \ + inline T *unwrap(ref P) { \ + return cast(unwrap(P)); \ + } - /* Opaque type conversions - */ - inline Type *unwrap(LLVMTypeRef Ty) { - return reinterpret_cast(Ty); - } + #define DEFINE_STDCXX_CONVERSION_FUNCTIONS(ty, ref) \ + DEFINE_SIMPLE_CONVERSION_FUNCTIONS(ty, ref) \ + \ + template \ + inline T *unwrap(ref P) { \ + T *Q = dynamic_cast(unwrap(P)); \ + assert(Q && "Invalid cast!"); \ + return Q; \ + } - template - inline T *unwrap(LLVMTypeRef Ty) { - return cast(unwrap(Ty)); - } + DEFINE_ISA_CONVERSION_FUNCTIONS (Type, LLVMTypeRef ) + DEFINE_ISA_CONVERSION_FUNCTIONS (Value, LLVMValueRef ) + DEFINE_SIMPLE_CONVERSION_FUNCTIONS(Module, LLVMModuleRef ) + DEFINE_SIMPLE_CONVERSION_FUNCTIONS(BasicBlock, LLVMBasicBlockRef ) + DEFINE_SIMPLE_CONVERSION_FUNCTIONS(LLVMFoldingBuilder, LLVMBuilderRef ) + DEFINE_SIMPLE_CONVERSION_FUNCTIONS(PATypeHolder, LLVMTypeHandleRef ) + DEFINE_SIMPLE_CONVERSION_FUNCTIONS(ModuleProvider, LLVMModuleProviderRef) + DEFINE_SIMPLE_CONVERSION_FUNCTIONS(MemoryBuffer, LLVMMemoryBufferRef ) + DEFINE_STDCXX_CONVERSION_FUNCTIONS(PassManagerBase, LLVMPassManagerRef ) + + #undef DEFINE_STDCXX_CONVERSION_FUNCTIONS + #undef DEFINE_ISA_CONVERSION_FUNCTIONS + #undef DEFINE_SIMPLE_CONVERSION_FUNCTIONS + /* Specialized opaque type conversions. + */ inline Type **unwrap(LLVMTypeRef* Tys) { return reinterpret_cast(Tys); } - inline LLVMTypeRef wrap(const Type *Ty) { - return reinterpret_cast(const_cast(Ty)); - } - inline LLVMTypeRef *wrap(const Type **Tys) { return reinterpret_cast(const_cast(Tys)); } - /* Opaque value conversions + /* Specialized opaque value conversions. */ - inline Value *unwrap(LLVMValueRef Val) { - return reinterpret_cast(Val); - } - - template - inline T *unwrap(LLVMValueRef Val) { - return cast(unwrap(Val)); - } - inline Value **unwrap(LLVMValueRef *Vals) { return reinterpret_cast(Vals); } @@ -567,53 +694,9 @@ namespace llvm { return reinterpret_cast(Vals); } - inline LLVMValueRef wrap(const Value *Val) { - return reinterpret_cast(const_cast(Val)); - } - inline LLVMValueRef *wrap(const Value **Vals) { return reinterpret_cast(const_cast(Vals)); } - - /* Basic block conversions - */ - inline BasicBlock *unwrap(LLVMBasicBlockRef BBRef) { - return reinterpret_cast(BBRef); - } - - inline LLVMBasicBlockRef wrap(const BasicBlock *BB) { - return reinterpret_cast(const_cast(BB)); - } - - /* Opaque builder conversions. - */ - inline LLVMBuilder *unwrap(LLVMBuilderRef B) { - return reinterpret_cast(B); - } - - inline LLVMBuilderRef wrap(LLVMBuilder *B) { - return reinterpret_cast(B); - } - - /* Opaque type handle conversions. - */ - inline PATypeHolder *unwrap(LLVMTypeHandleRef B) { - return reinterpret_cast(B); - } - - inline LLVMTypeHandleRef wrap(PATypeHolder *B) { - return reinterpret_cast(B); - } - - /* Opaque module provider conversions. - */ - inline ModuleProvider *unwrap(LLVMModuleProviderRef P) { - return reinterpret_cast(P); - } - - inline LLVMModuleProviderRef wrap(ModuleProvider *P) { - return reinterpret_cast(P); - } } #endif /* !defined(__cplusplus) */