X-Git-Url: http://plrg.eecs.uci.edu/git/?p=oota-llvm.git;a=blobdiff_plain;f=include%2Fllvm-c%2FCore.h;h=c8fda15c5ed66128c098654a1cfbb242e3989c10;hp=8693a3020aba346c811dca559662d4bf2aa6aacb;hb=561f3680a12638e8290ff3473bec4f0e9cb18bac;hpb=a4d0ff9cd1fb3fe4c3a58d0747dc523f7d9e9e3f diff --git a/include/llvm-c/Core.h b/include/llvm-c/Core.h index 8693a3020ab..c8fda15c5ed 100644 --- a/include/llvm-c/Core.h +++ b/include/llvm-c/Core.h @@ -15,7 +15,8 @@ #ifndef LLVM_C_CORE_H #define LLVM_C_CORE_H -#include "llvm-c/Support.h" +#include "llvm-c/ErrorHandling.h" +#include "llvm-c/Types.h" #ifdef __cplusplus extern "C" { @@ -40,15 +41,6 @@ extern "C" { * the LLVM intermediate representation as well as other related types * and utilities. * - * LLVM uses a polymorphic type hierarchy which C cannot represent, therefore - * parameters must be passed as base types. Despite the declared types, most - * of the functions provided operate only on branches of the type hierarchy. - * The declared parameter names are descriptive and specify which type is - * required. Additionally, each type hierarchy is documented along with the - * functions that operate upon it. For more detail, refer to LLVM's C++ code. - * If in doubt, refer to Core.cpp, which performs parameter downcasts in the - * form unwrap(Param). - * * Many exotic languages can interoperate with C code but have a harder time * with C++ due to name mangling. So in addition to C, this interface enables * tools written in such languages. @@ -62,74 +54,6 @@ extern "C" { * @{ */ -/* Opaque types. */ - -/** - * The top-level container for all LLVM global data. See the LLVMContext class. - */ -typedef struct LLVMOpaqueContext *LLVMContextRef; - -/** - * The top-level container for all other LLVM Intermediate Representation (IR) - * objects. - * - * @see llvm::Module - */ -typedef struct LLVMOpaqueModule *LLVMModuleRef; - -/** - * Each value in the LLVM IR has a type, an LLVMTypeRef. - * - * @see llvm::Type - */ -typedef struct LLVMOpaqueType *LLVMTypeRef; - -/** - * Represents an individual value in LLVM IR. - * - * This models llvm::Value. - */ -typedef struct LLVMOpaqueValue *LLVMValueRef; - -/** - * Represents a basic block of instructions in LLVM IR. - * - * This models llvm::BasicBlock. - */ -typedef struct LLVMOpaqueBasicBlock *LLVMBasicBlockRef; - -/** - * Represents an LLVM basic block builder. - * - * This models llvm::IRBuilder. - */ -typedef struct LLVMOpaqueBuilder *LLVMBuilderRef; - -/** - * Interface used to provide a module to JIT or interpreter. - * This is now just a synonym for llvm::Module, but we have to keep using the - * different type to keep binary compatibility. - */ -typedef struct LLVMOpaqueModuleProvider *LLVMModuleProviderRef; - -/** @see llvm::PassManagerBase */ -typedef struct LLVMOpaquePassManager *LLVMPassManagerRef; - -/** @see llvm::PassRegistry */ -typedef struct LLVMOpaquePassRegistry *LLVMPassRegistryRef; - -/** - * Used to get the users and usees of a Value. - * - * @see llvm::Use */ -typedef struct LLVMOpaqueUse *LLVMUseRef; - - -/** - * @see llvm::DiagnosticInfo - */ -typedef struct LLVMOpaqueDiagnosticInfo *LLVMDiagnosticInfoRef; - typedef enum { LLVMZExtAttribute = 1<<0, LLVMSExtAttribute = 1<<1, @@ -161,13 +85,15 @@ typedef enum { /* FIXME: These attributes are currently not included in the C API as a temporary measure until the API/ABI impact to the C API is understood and the path forward agreed upon. - LLVMAddressSafety = 1ULL << 32, - LLVMStackProtectStrongAttribute = 1ULL<<33, - LLVMCold = 1ULL << 34, - LLVMOptimizeNone = 1ULL << 35, - LLVMInAllocaAttribute = 1ULL << 36, - LLVMNonNullAttribute = 1ULL << 37, - LLVMJumpTableAttribute = 1ULL << 38, + LLVMSanitizeAddressAttribute = 1ULL << 32, + LLVMStackProtectStrongAttribute = 1ULL<<35, + LLVMColdAttribute = 1ULL << 40, + LLVMOptimizeNoneAttribute = 1ULL << 42, + LLVMInAllocaAttribute = 1ULL << 43, + LLVMNonNullAttribute = 1ULL << 44, + LLVMJumpTableAttribute = 1ULL << 45, + LLVMConvergentAttribute = 1ULL << 46, + LLVMSafeStackAttribute = 1ULL << 47, */ } LLVMAttribute; @@ -246,8 +172,12 @@ typedef enum { /* Exception Handling Operators */ LLVMResume = 58, - LLVMLandingPad = 59 - + LLVMLandingPad = 59, + LLVMCleanupRet = 61, + LLVMCatchRet = 62, + LLVMCatchPad = 63, + LLVMCleanupPad = 64, + LLVMCatchSwitch = 65 } LLVMOpcode; typedef enum { @@ -266,7 +196,8 @@ typedef enum { LLVMPointerTypeKind, /**< Pointers */ LLVMVectorTypeKind, /**< SIMD 'packed' format, or other vector type */ LLVMMetadataTypeKind, /**< Metadata */ - LLVMX86_MMXTypeKind /**< X86 MMX */ + LLVMX86_MMXTypeKind, /**< X86 MMX */ + LLVMTokenTypeKind /**< Tokens */ } LLVMTypeKind; typedef enum { @@ -426,36 +357,11 @@ void LLVMInitializeCore(LLVMPassRegistryRef R); @see ManagedStatic */ void LLVMShutdown(void); - /*===-- Error handling ----------------------------------------------------===*/ char *LLVMCreateMessage(const char *Message); void LLVMDisposeMessage(char *Message); -typedef void (*LLVMFatalErrorHandler)(const char *Reason); - -/** - * Install a fatal error handler. By default, if LLVM detects a fatal error, it - * will call exit(1). This may not be appropriate in many contexts. For example, - * doing exit(1) will bypass many crash reporting/tracing system tools. This - * function allows you to install a callback that will be invoked prior to the - * call to exit(1). - */ -void LLVMInstallFatalErrorHandler(LLVMFatalErrorHandler Handler); - -/** - * Reset the fatal error handler. This resets LLVM's fatal error handling - * behavior to the default. - */ -void LLVMResetFatalErrorHandler(void); - -/** - * Enable LLVM's built-in stack trace code. This intercepts the OS's crash - * signals and prints which component of LLVM you were in at the time if the - * crash. - */ -void LLVMEnablePrettyStackTrace(void); - /** * @defgroup LLVMCCoreContext Contexts * @@ -559,6 +465,10 @@ LLVMModuleRef LLVMModuleCreateWithName(const char *ModuleID); */ LLVMModuleRef LLVMModuleCreateWithNameInContext(const char *ModuleID, LLVMContextRef C); +/** + * Return an exact copy of the specified module. + */ +LLVMModuleRef LLVMCloneModule(LLVMModuleRef M); /** * Destroy a module instance. @@ -802,6 +712,7 @@ LLVMTypeRef LLVMInt8TypeInContext(LLVMContextRef C); LLVMTypeRef LLVMInt16TypeInContext(LLVMContextRef C); LLVMTypeRef LLVMInt32TypeInContext(LLVMContextRef C); LLVMTypeRef LLVMInt64TypeInContext(LLVMContextRef C); +LLVMTypeRef LLVMInt128TypeInContext(LLVMContextRef C); LLVMTypeRef LLVMIntTypeInContext(LLVMContextRef C, unsigned NumBits); /** @@ -813,6 +724,7 @@ LLVMTypeRef LLVMInt8Type(void); LLVMTypeRef LLVMInt16Type(void); LLVMTypeRef LLVMInt32Type(void); LLVMTypeRef LLVMInt64Type(void); +LLVMTypeRef LLVMInt128Type(void); LLVMTypeRef LLVMIntType(unsigned NumBits); unsigned LLVMGetIntTypeWidth(LLVMTypeRef IntegerTy); @@ -991,6 +903,13 @@ unsigned LLVMCountStructElementTypes(LLVMTypeRef StructTy); */ void LLVMGetStructElementTypes(LLVMTypeRef StructTy, LLVMTypeRef *Dest); +/** + * Get the type of the element at a given index in the structure. + * + * @see llvm::StructType::getTypeAtIndex() + */ +LLVMTypeRef LLVMStructGetTypeAtIndex(LLVMTypeRef StructTy, unsigned i); + /** * Determine whether a structure is packed. * @@ -1009,7 +928,6 @@ LLVMBool LLVMIsOpaqueStruct(LLVMTypeRef StructTy); * @} */ - /** * @defgroup LLVMCCoreTypeSequential Sequential Types * @@ -1152,8 +1070,6 @@ LLVMTypeRef LLVMX86MMXType(void); macro(Argument) \ macro(BasicBlock) \ macro(InlineAsm) \ - macro(MDNode) \ - macro(MDString) \ macro(User) \ macro(Constant) \ macro(BlockAddress) \ @@ -1167,6 +1083,7 @@ LLVMTypeRef LLVMX86MMXType(void); macro(ConstantInt) \ macro(ConstantPointerNull) \ macro(ConstantStruct) \ + macro(ConstantTokenNone) \ macro(ConstantVector) \ macro(GlobalValue) \ macro(GlobalAlias) \ @@ -1204,6 +1121,11 @@ LLVMTypeRef LLVMX86MMXType(void); macro(SwitchInst) \ macro(UnreachableInst) \ macro(ResumeInst) \ + macro(CleanupReturnInst) \ + macro(CatchReturnInst) \ + macro(FuncletPadInst) \ + macro(CatchPadInst) \ + macro(CleanupPadInst) \ macro(UnaryInstruction) \ macro(AllocaInst) \ macro(CastInst) \ @@ -1302,6 +1224,9 @@ LLVMBool LLVMIsUndef(LLVMValueRef Val); LLVMValueRef LLVMIsA##name(LLVMValueRef Val); LLVM_FOR_EACH_VALUE_SUBCLASS(LLVM_DECLARE_VALUE_CAST) +LLVMValueRef LLVMIsAMDNode(LLVMValueRef Val); +LLVMValueRef LLVMIsAMDString(LLVMValueRef Val); + /** * @} */ @@ -1376,6 +1301,13 @@ LLVMValueRef LLVMGetUsedValue(LLVMUseRef U); */ LLVMValueRef LLVMGetOperand(LLVMValueRef Val, unsigned Index); +/** + * Obtain the use of an operand at a specific index in a llvm::User value. + * + * @see llvm::User::getOperandUse() + */ +LLVMUseRef LLVMGetOperandUse(LLVMValueRef Val, unsigned Index); + /** * Set an operand at a specific index in a llvm::User value. * @@ -1536,6 +1468,14 @@ unsigned long long LLVMConstIntGetZExtValue(LLVMValueRef ConstantVal); */ long long LLVMConstIntGetSExtValue(LLVMValueRef ConstantVal); +/** + * Obtain the double value for an floating point constant value. + * losesInfo indicates if some precision was lost in the conversion. + * + * @see llvm::ConstantFP::getDoubleValue + */ +double LLVMConstRealGetDouble(LLVMValueRef ConstantVal, LLVMBool *losesInfo); + /** * @} */ @@ -1568,6 +1508,20 @@ LLVMValueRef LLVMConstStringInContext(LLVMContextRef C, const char *Str, LLVMValueRef LLVMConstString(const char *Str, unsigned Length, LLVMBool DontNullTerminate); +/** + * Returns true if the specified constant is an array of i8. + * + * @see ConstantDataSequential::getAsString() + */ +LLVMBool LLVMIsConstantString(LLVMValueRef c); + +/** + * Get the given constant data sequential as a string. + * + * @see ConstantDataSequential::getAsString() + */ +const char *LLVMGetAsString(LLVMValueRef c, size_t* out); + /** * Create an anonymous ConstantStruct with the specified values. * @@ -1605,6 +1559,13 @@ LLVMValueRef LLVMConstNamedStruct(LLVMTypeRef StructTy, LLVMValueRef *ConstantVals, unsigned Count); +/** + * Get an element at specified index as a constant. + * + * @see ConstantDataSequential::getElementAsConstant() + */ +LLVMValueRef LLVMGetElementAsConstant(LLVMValueRef c, unsigned idx); + /** * Create a ConstantVector from values. * @@ -1837,6 +1798,20 @@ LLVMValueRef LLVMAddAlias(LLVMModuleRef M, LLVMTypeRef Ty, LLVMValueRef Aliasee, */ void LLVMDeleteFunction(LLVMValueRef Fn); +/** + * Obtain the personality function attached to the function. + * + * @see llvm::Function::getPersonalityFn() + */ +LLVMValueRef LLVMGetPersonalityFn(LLVMValueRef Fn); + +/** + * Set the personality function attached to the function. + * + * @see llvm::Function::setPersonalityFn() + */ +void LLVMSetPersonalityFn(LLVMValueRef Fn, LLVMValueRef PersonalityFn); + /** * Obtain the ID number from a function instance. * @@ -1886,7 +1861,7 @@ void LLVMSetGC(LLVMValueRef Fn, const char *Name); void LLVMAddFunctionAttr(LLVMValueRef Fn, LLVMAttribute PA); /** - * Add a target-dependent attribute to a fuction + * Add a target-dependent attribute to a function * @see llvm::AttrBuilder::addAttribute() */ void LLVMAddTargetDependentFunctionAttr(LLVMValueRef Fn, const char *A, @@ -2363,7 +2338,7 @@ void LLVMInstructionEraseFromParent(LLVMValueRef Inst); * * @see llvm::Instruction::getOpCode() */ -LLVMOpcode LLVMGetInstructionOpcode(LLVMValueRef Inst); +LLVMOpcode LLVMGetInstructionOpcode(LLVMValueRef Inst); /** * Obtain the predicate of an instruction. @@ -2375,6 +2350,26 @@ LLVMOpcode LLVMGetInstructionOpcode(LLVMValueRef Inst); */ LLVMIntPredicate LLVMGetICmpPredicate(LLVMValueRef Inst); +/** + * Obtain the float predicate of an instruction. + * + * This is only valid for instructions that correspond to llvm::FCmpInst + * or llvm::ConstantExpr whose opcode is llvm::Instruction::FCmp. + * + * @see llvm::FCmpInst::getPredicate() + */ +LLVMRealPredicate LLVMGetFCmpPredicate(LLVMValueRef Inst); + +/** + * Create a copy of 'this' instruction that is identical in all ways + * except the following: + * * The instruction has no parent + * * The instruction has no name + * + * @see llvm::Instruction::clone() + */ +LLVMValueRef LLVMInstructionClone(LLVMValueRef Inst); + /** * @defgroup LLVMCCoreValueInstructionCall Call Sites and Invocations * @@ -2435,6 +2430,63 @@ void LLVMSetTailCall(LLVMValueRef CallInst, LLVMBool IsTailCall); * @} */ +/** + * @defgroup LLVMCCoreValueInstructionTerminator Terminators + * + * Functions in this group only apply to instructions that map to + * llvm::TerminatorInst instances. + * + * @{ + */ + +/** + * Return the number of successors that this terminator has. + * + * @see llvm::TerminatorInst::getNumSuccessors + */ +unsigned LLVMGetNumSuccessors(LLVMValueRef Term); + +/** + * Return the specified successor. + * + * @see llvm::TerminatorInst::getSuccessor + */ +LLVMBasicBlockRef LLVMGetSuccessor(LLVMValueRef Term, unsigned i); + +/** + * Update the specified successor to point at the provided block. + * + * @see llvm::TerminatorInst::setSuccessor + */ +void LLVMSetSuccessor(LLVMValueRef Term, unsigned i, LLVMBasicBlockRef block); + +/** + * Return if a branch is conditional. + * + * This only works on llvm::BranchInst instructions. + * + * @see llvm::BranchInst::isConditional + */ +LLVMBool LLVMIsConditional(LLVMValueRef Branch); + +/** + * Return the condition of a branch instruction. + * + * This only works on llvm::BranchInst instructions. + * + * @see llvm::BranchInst::getCondition + */ +LLVMValueRef LLVMGetCondition(LLVMValueRef Branch); + +/** + * Set the condition of a branch instruction. + * + * This only works on llvm::BranchInst instructions. + * + * @see llvm::BranchInst::setCondition + */ +void LLVMSetCondition(LLVMValueRef Branch, LLVMValueRef Cond); + /** * Obtain the default destination basic block of a switch instruction. * @@ -2444,6 +2496,10 @@ void LLVMSetTailCall(LLVMValueRef CallInst, LLVMBool IsTailCall); */ LLVMBasicBlockRef LLVMGetSwitchDefaultDest(LLVMValueRef SwitchInstr); +/** + * @} + */ + /** * @defgroup LLVMCCoreValueInstructionPHINode PHI Nodes * @@ -2635,6 +2691,8 @@ LLVMValueRef LLVMBuildGlobalStringPtr(LLVMBuilderRef B, const char *Str, const char *Name); LLVMBool LLVMGetVolatile(LLVMValueRef MemoryAccessInst); void LLVMSetVolatile(LLVMValueRef MemoryAccessInst, LLVMBool IsVolatile); +LLVMAtomicOrdering LLVMGetOrdering(LLVMValueRef MemoryAccessInst); +void LLVMSetOrdering(LLVMValueRef MemoryAccessInst, LLVMAtomicOrdering Ordering); /* Casts */ LLVMValueRef LLVMBuildTrunc(LLVMBuilderRef, LLVMValueRef Val, @@ -2875,6 +2933,6 @@ LLVMBool LLVMIsMultithreaded(void); #ifdef __cplusplus } -#endif /* !defined(__cplusplus) */ +#endif -#endif /* !defined(LLVM_C_CORE_H) */ +#endif /* LLVM_C_CORE_H */