Index: include/llvm-c/Core.h =================================================================== --- include/llvm-c/Core.h +++ include/llvm-c/Core.h @@ -248,6 +248,34 @@ } LLVMCallConv; typedef enum { + LLVMArgumentValueKind, + LLVMBasicBlockValueKind, + LLVMInlineAsmValueKind, + LLVMMDNodeValueKind, + LLVMMDStringValueKind, + LLVMUserValueKind, + LLVMConstantValueKind, + LLVMBlockAddressValueKind, + LLVMConstantAggregateZeroValueKind, + LLVMConstantArrayValueKind, + LLVMConstantDataSequentialValueKind, + LLVMConstantDataArrayValueKind, + LLVMConstantDataVectorValueKind, + LLVMConstantExprValueKind, + LLVMConstantFPValueKind, + LLVMConstantIntValueKind, + LLVMConstantPointerNullValueKind, + LLVMConstantStructValueKind, + LLVMConstantVectorValueKind, + LLVMGlobalValueValueKind, + LLVMFunctionValueKind, + LLVMGlobalAliasValueKind, + LLVMGlobalVariableValueKind, + LLVMUndefValueValueKind, + LLVMInstructionValueKind +} LLVMValueKind; + +typedef enum { LLVMIntEQ = 32, /**< equal */ LLVMIntNE, /**< not equal */ LLVMIntUGT, /**< unsigned greater than */ @@ -342,6 +370,11 @@ } LLVMAtomicRMWBinOp; typedef enum { + LLVMSynchronizationScopeSingleThread, + LLVMSynchronizationScopeCrossThread +} LLVMSyncronizationScope; + +typedef enum { LLVMDSError, LLVMDSWarning, LLVMDSRemark, @@ -481,6 +514,19 @@ void LLVMDisposeModule(LLVMModuleRef M); /** + * Obtain the identifier of a module. The result must be discarded with + * LLVMDisposeMessage. + * @see Module::getModuleIdentifier() + */ +char *LLVMGetModuleIdentifier(LLVMModuleRef M); + +/** + * Set the identifier of a module. + * @see Module::setModuleIdentifier() + */ +void LLVMSetModuleIdentifier(LLVMModuleRef M, const char* ID); + +/** * Obtain the data layout for a module. * * @see Module::getDataLayoutStr() @@ -1030,6 +1076,7 @@ * Create a label type in a context. */ LLVMTypeRef LLVMLabelTypeInContext(LLVMContextRef C); +LLVMTypeRef LLVMMetadataTypeInContext(LLVMContextRef C); /** * Create a X86 MMX type in a context. @@ -1042,6 +1089,7 @@ */ LLVMTypeRef LLVMVoidType(void); LLVMTypeRef LLVMLabelType(void); +LLVMTypeRef LLVMMetadataType(void); LLVMTypeRef LLVMX86MMXType(void); /** @@ -1073,6 +1121,29 @@ * @{ */ +#define LLVM_FOR_EACH_VALUE_KIND(macro) \ + macro(Argument) \ + macro(BasicBlock) \ + macro(InlineAsm) \ + macro(MDNode) \ + macro(MDString) \ + macro(BlockAddress) \ + macro(ConstantAggregateZero) \ + macro(ConstantArray) \ + macro(ConstantDataArray) \ + macro(ConstantDataVector) \ + macro(ConstantExpr) \ + macro(ConstantFP) \ + macro(ConstantInt) \ + macro(ConstantPointerNull) \ + macro(ConstantStruct) \ + macro(ConstantVector) \ + macro(Function) \ + macro(GlobalAlias) \ + macro(GlobalVariable) \ + macro(UndefValue) \ + macro(Instruction) + #define LLVM_FOR_EACH_VALUE_SUBCLASS(macro) \ macro(Argument) \ macro(BasicBlock) \ @@ -1171,6 +1242,13 @@ LLVMTypeRef LLVMTypeOf(LLVMValueRef Val); /** + * Obtain the enumerated type of a Value instance. + * + * @see llvm::Type:getValueID() + */ +LLVMValueKind LLVMGetValueKind(LLVMValueRef Val); + +/** * Obtain the string name of a value. * * @see llvm::Value::getName() @@ -1443,6 +1521,30 @@ unsigned SLen, uint8_t Radix); /** + * Obtain the zero extended value for an integer constant value. + * + * @see llvm::ConstantInt::getZExtValue() + */ +unsigned long long LLVMConstIntGetZExtValue(LLVMValueRef ConstantVal); + +/** + * Obtain the sign extended value for an integer constant value. + * + * @see llvm::ConstantInt::getSExtValue() + */ +long long LLVMConstIntGetSExtValue(LLVMValueRef ConstantVal); + +/** + * Obtain the words of an integer constant value. \p n should point to + * a variable which will hold the amount of words. The return value + * points to an array of \p n words, owned by the context. The caller + * must not capture pointer to the array. + * + * @see llvm::ConstantInt::getValue() + */ +const uint64_t *LLVMConstIntGetWords(LLVMValueRef v, unsigned *n); + +/** * Obtain a constant value referring to a double floating point value. */ LLVMValueRef LLVMConstReal(LLVMTypeRef RealTy, double N); @@ -1462,18 +1564,13 @@ unsigned SLen); /** - * Obtain the zero extended value for an integer constant value. + * Obtain a constant value for a floating point value of arbitrary precision. * - * @see llvm::ConstantInt::getZExtValue() + * @see llvm::ConstantFP::get() */ -unsigned long long LLVMConstIntGetZExtValue(LLVMValueRef ConstantVal); - -/** - * Obtain the sign extended value for an integer constant value. - * - * @see llvm::ConstantInt::getSExtValue() - */ -long long LLVMConstIntGetSExtValue(LLVMValueRef ConstantVal); +LLVMValueRef LLVMConstRealOfArbitraryPrecision(LLVMTypeRef RealTy, + unsigned NumWords, + const uint64_t Words[]); /** * Obtain the double value for an floating point constant value. @@ -1484,6 +1581,16 @@ double LLVMConstRealGetDouble(LLVMValueRef ConstantVal, LLVMBool *losesInfo); /** + * Obtain the words of a floating point constant value. \p n should point to + * a variable which will hold the amount of words. The return value + * points to an array of \p n words, owned by the context. The caller + * must not capture pointer to the array. + * + * @see llvm::ConstantFP::getValueAPF() + */ +const uint64_t *LLVMConstRealGetWords(LLVMValueRef v, unsigned *n); + +/** * @} */ @@ -1594,6 +1701,7 @@ * @{ */ LLVMOpcode LLVMGetConstOpcode(LLVMValueRef ConstantVal); +LLVMValueRef LLVMGetElementAsConstant(LLVMValueRef ConstantVal, unsigned n); LLVMValueRef LLVMAlignOf(LLVMTypeRef Ty); LLVMValueRef LLVMSizeOf(LLVMTypeRef Ty); LLVMValueRef LLVMConstNeg(LLVMValueRef ConstantVal); @@ -1681,6 +1789,18 @@ LLVMValueRef LLVMBlockAddress(LLVMValueRef F, LLVMBasicBlockRef BB); /** + * Obtain the function of a blockaddress expression. + * @see llvm::BlockAdress::getFunction() + */ +LLVMValueRef LLVMGetBlockAddressFunction(LLVMValueRef BA); + +/** + * Obtain the basic block of a blockaddress expression. + * @see llvm::BlockAddress::getBasicBlock() + */ +LLVMBasicBlockRef LLVMGetBlockAddressBlock(LLVMValueRef BA); + +/** * @} */ @@ -1782,6 +1902,26 @@ */ LLVMValueRef LLVMAddAlias(LLVMModuleRef M, LLVMTypeRef Ty, LLVMValueRef Aliasee, const char *Name); +LLVMValueRef LLVMGetNamedAlias(LLVMModuleRef M, const char *Name); +LLVMValueRef LLVMGetFirstAlias(LLVMModuleRef M); +LLVMValueRef LLVMGetLastAlias(LLVMModuleRef M); +LLVMValueRef LLVMGetNextAlias(LLVMValueRef Alias); +LLVMValueRef LLVMGetPreviousAlias(LLVMValueRef Alias); +void LLVMDeleteAlias(LLVMValueRef GlobalVar); + +/** + * Get the aliased value of an alias. The value can be a constant or a constant + * bitcast. + * @see llvm::GlobalAlias::getAliasee() + */ +LLVMValueRef LLVMGetAliasee(LLVMValueRef A); + +/** + * Set the aliased value of an alias. The value can be a constant or a constant + * bitcast. + * @see llvm::GlobalAlias::setAliasee() + */ +void LLVMSetAliasee(LLVMValueRef A, LLVMValueRef Aliasee); /** * @} @@ -2370,6 +2510,16 @@ LLVMOpcode LLVMGetInstructionOpcode(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); + +/** * Obtain the predicate of an instruction. * * This is only valid for instructions that correspond to llvm::ICmpInst @@ -2390,14 +2540,199 @@ 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 + * @defgroup LLVMCCoreValueInstructionGEP GetElementPtr * - * @see llvm::Instruction::clone() + * Functions in this group apply to instructions that refer to getelementptr + * instructions or constant expressions. These correspond to C++ types in the + * llvm::GetElementPtrInst or llvm::GetElementPtrConstantExpr classes. + * + * @{ + */ + +/** + * Obtain whether a getelementptr is "inbounds". + * + * This is only valid for instructions that correspond to + * llvm::GetElementPtrInst or llvm::GetElementPtrConstantExpr. + * + * @see llvm::GetElementPtrInst::isInBounds() + */ +LLVMBool LLVMIsInBounds(LLVMValueRef Inst); + +/** + * Set whether a getelementptr is "inbounds". + * + * This is only valid for instructions that correspond to + * llvm::GetElementPtrInst or llvm::GetElementPtrConstantExpr. + * + * @see llvm::GetElementPtrInst::setIsInBounds() + */ +void LLVMSetIsInBounds(LLVMValueRef Inst, LLVMBool IsInBounds); + +/** + * @} + */ + +/** + * @defgroup LLVMCCoreValueInstructionBinOp Binary Operators + * + * Functions in this group apply to instructions that refer to binary + * operators. These correspond to C++ types in the llvm::BinaryOperator class + * tree. + * + * @{ + */ + +/** + * Obtain whether the operation cannot result in a signed integer wraparound. + * @see llvm::BinaryOperator::hasNoSignedWrap() + */ +LLVMBool LLVMHasNoSignedWrap(LLVMValueRef Instr); + +/** + * Set whether the operation cannot result in a signed integer wraparound. + * @see llvm::BinaryOperator::hasNoSignedWrap() + */ +void LLVMSetHasNoSignedWrap(LLVMValueRef Instr, LLVMBool HasNoSignedWrap); + +/** + * Obtain whether the operation cannot result in a unsigned integer wraparound. + * @see llvm::BinaryOperator::hasNoUnsignedWrap() + */ +LLVMBool LLVMHasNoUnsignedWrap(LLVMValueRef Instr); + +/** + * Set whether the operation cannot result in a unsigned integer wraparound. + * @see llvm::BinaryOperator::hasNoUnsignedWrap() + */ +void LLVMSetHasNoUnsignedWrap(LLVMValueRef Instr, LLVMBool HasNoSignedWrap); + +/** + * Obtain whether the operation cannot result in an inexact result. + * @see llvm::BinaryOperator::isExact() + */ +LLVMBool LLVMIsExact(LLVMValueRef Instr); + +/** + * Set whether the operation cannot result in an inexact result. + * @see llvm::BinaryOperator::isExact() + */ +void LLVMSetIsExact(LLVMValueRef Instr, LLVMBool IsExact); + +/** + * @} + */ + +/** + * @defgroup LLVMCCoreValueInstructionAlloca Alloca + * + * Functions in this group apply to the alloca instruction. + * @see llvm::AllocaInst + * + * @{ + */ + +/** + * Obtain whether an alloca instruction allocates an array. + * @see llvm::AllocaInst::isArrayAllocation() + */ +LLVMBool LLVMIsArrayAlloca(LLVMValueRef Instr); + +/** + * Obtain the number of elements allocated by an alloca instruction. + * @see llvm::AllocaInst::getArraySize() + */ +LLVMValueRef LLVMGetAllocaNumElements(LLVMValueRef Instr); + +/** + * Obtain the type of elements allocated by an alloca instruction. + * @see llvm::AllocaInst::getAllocatedType() + */ +LLVMTypeRef LLVMGetAllocatedType(LLVMValueRef Instr); + +/** + * @} + */ + +/** + * @defgroup LLVMCCoreValueInstructionAtomic Atomic instructions + * + * Functions in this group apply to instructions with atomic forms, that is + * load, store, fence, atomicrmw and cmpxchg. + * @see llvm::AtomicRMWInst + * + * @{ + */ + +/** + * Obtain the atomic ordering of an instruction with an atomic form. + * @see llvm::LoadInst::getAtomicOrdering() + * @see llvm::StoreInst::getAtomicOrdering() + * @see llvm::FenceInst::getAtomicOrdering() + * @see llvm::AtomicRMWInst::getAtomicOrdering() + * @see llvm::AtomicCmpXchgInst::getAtomicOrdering() + */ +LLVMAtomicOrdering LLVMGetAtomicOrdering(LLVMValueRef Instr); + +/** + * Set the atomic ordering of an instruction with an atomic form. + * @see llvm::LoadInst::setAtomicOrdering() + * @see llvm::StoreInst::setAtomicOrdering() + * @see llvm::FenceInst::setAtomicOrdering() + * @see llvm::AtomicRMWInst::setAtomicOrdering() + * @see llvm::AtomicCmpXchgInst::setAtomicOrdering() + */ +void LLVMSetAtomicOrdering(LLVMValueRef Instr, LLVMAtomicOrdering Ordering); + +/** + * Obtain the synchronization scope of an instruction with an atomic form. + * @see llvm::LoadInst::getSynchronizationScope() + * @see llvm::StoreInst::getSynchronizationScope() + * @see llvm::FenceInst::getSynchronizationScope() + * @see llvm::AtomicRMWInst::getSynchronizationScope() + * @see llvm::AtomicCmpXchgInst::getSynchronizationScope() + */ +LLVMSynchronizationScope LLVMGetSynchronizationScope(LLVMValueRef Instr); + +/** + * Set the atomic ordering of an instruction with an atomic form. + * @see llvm::LoadInst::setSynchronizationScope() + * @see llvm::StoreInst::setSynchronizationScope() + * @see llvm::FenceInst::setSynchronizationScope() + * @see llvm::AtomicRMWInst::setSynchronizationScope() + * @see llvm::AtomicCmpXchgInst::setSynchronizationScope() + */ +void LLVMSetSynchronizationScope(LLVMValueRef Instr, + LLVMSynchronizationScope Scope); + +/** + * @} + */ + +/** + * @defgroup LLVMCCoreValueInstructionAtomicRMW AtomicRMW + * + * Functions in this group apply to the atomicrmw instruction. + * @see llvm::AtomicRMWInst + * + * @{ + */ + +/** + * Obtain the operation of an atomicrmw instruction. + * @see llvm::AtomicRMWInst::getOperation() + */ +LLVMAtomicRMWBinOp LLVMGetAtomicRMWOperation(LLVMValueRef Instr); + +/** + * Set the operation of an atomicrmw instruction. + * @see llvm::AtomicRMWInst::setOperation() + */ +void LLVMSetAtomicRMWOperation(LLVMValueRef Instr, LLVMAtomicRMWBinOp Op); + +/** + * @} */ -LLVMValueRef LLVMInstructionClone(LLVMValueRef Inst); /** * @defgroup LLVMCCoreValueInstructionCall Call Sites and Invocations @@ -2441,7 +2776,6 @@ */ unsigned LLVMGetInstructionCallConv(LLVMValueRef Instr); - void LLVMAddInstrAttribute(LLVMValueRef Instr, unsigned index, LLVMAttribute); void LLVMRemoveInstrAttribute(LLVMValueRef Instr, unsigned index, LLVMAttribute); @@ -2575,15 +2909,82 @@ void LLVMSetCondition(LLVMValueRef Branch, LLVMValueRef Cond); /** - * Obtain the default destination basic block of a switch instruction. + * @defgroup LLVMCCoreValueInstructionSwitch Switch Instructions * - * This only works on llvm::SwitchInst instructions. + * Functions in this group only apply to switch instructions. + * + * @{ + */ + +/** + * Add a case to a switch instruction. \p OnVal must be a constant integer. + * + * @see llvm::SwitchInst::addCase() + */ +void LLVMAddCase(LLVMValueRef Switch, LLVMValueRef OnVal, + LLVMBasicBlockRef Dest); + +/** + * Obtain the default destination basic block of a switch instruction. * * @see llvm::SwitchInst::getDefaultDest() */ LLVMBasicBlockRef LLVMGetSwitchDefaultDest(LLVMValueRef SwitchInstr); /** + * Obtain the amount of non-default destinations of a switch instruction. + * + * @see llvm::SwitchInst::getNumCases() + */ +unsigned LLVMGetSwitchNumCases(LLVMValueRef SwitchInstr); + +/** + * Obtain the case values and destinations for all cases of a switch + * instruction. \p Values and \p Successors should point to arrays of + * sufficient size, which can be determined by \p LLVMGetSwitchNumCases. + */ +void LLVMGetSwitchCases(LLVMValueRef SwitchInstr, LLVMValueRef *Values, + LLVMBasicBlockRef *Successors); + +/** + * @} + */ + +/** + * @defgroup LLVMCCoreValueInstructionIndirectBr Indirectbr Instructions + * + * Functions in this group only apply to indirectbr instructions. + * + * @{ + */ + +/** + * Add a destination to the indirectbr instruction. + * + * @see llvm::IndirectBrInst::addDestination() + */ +void LLVMAddDestination(LLVMValueRef IndirectBr, LLVMBasicBlockRef Dest); + +/** + * Obtain the amount of destinations of an indirectbr instruction. + * + * @see llvm::IndirectBrInst::getNumDestinations() + */ +unsigned LLVMGetIndirectBrNumDestinations(LLVMValueRef IndirectBr); + +/** + * Obtain the destinations for all cases of an indirectbr instruction. + * \p Successors should point to an array of sufficient size, which can be + * determined by \p LLVMGetIndirectBrNumDestinations. + */ +void LLVMGetIndirectBrDestinations(LLVMValueRef IndirectBr, + LLVMBasicBlockRef *Successors); + +/** + * @} + */ + +/** * @} */ @@ -2744,13 +3145,6 @@ LLVMValueRef LLVMBuildResume(LLVMBuilderRef B, LLVMValueRef Exn); LLVMValueRef LLVMBuildUnreachable(LLVMBuilderRef); -/* Add a case to the switch instruction */ -void LLVMAddCase(LLVMValueRef Switch, LLVMValueRef OnVal, - LLVMBasicBlockRef Dest); - -/* Add a destination to the indirectbr instruction */ -void LLVMAddDestination(LLVMValueRef IndirectBr, LLVMBasicBlockRef Dest); - /* Get the number of clauses on the landingpad instruction */ unsigned LLVMGetNumClauses(LLVMValueRef LandingPad); @@ -2760,11 +3154,18 @@ /* Add a catch or filter clause to the landingpad instruction */ void LLVMAddClause(LLVMValueRef LandingPad, LLVMValueRef ClauseVal); -/* Get the 'cleanup' flag in the landingpad instruction */ +/** + * Obtain the cleanup flag in the landingpad instruction. + * @see llvm::LandingPadInst::isCleanup() + */ LLVMBool LLVMIsCleanup(LLVMValueRef LandingPad); -/* Set the 'cleanup' flag in the landingpad instruction */ -void LLVMSetCleanup(LLVMValueRef LandingPad, LLVMBool Val); + +/** + * Set the cleanup flag in the landingpad instruction + * @see llvm::LandingPadInst::setCleanup() + */ +void LLVMSetCleanup(LLVMValueRef LandingPad, LLVMBool Cleanup); /* Arithmetic */ LLVMValueRef LLVMBuildAdd(LLVMBuilderRef, LLVMValueRef LHS, LLVMValueRef RHS, Index: lib/IR/Core.cpp =================================================================== --- lib/IR/Core.cpp +++ lib/IR/Core.cpp @@ -157,6 +157,14 @@ delete unwrap(M); } +char *LLVMGetModuleIdentifier(LLVMModuleRef M) { + return strdup(unwrap(M)->getModuleIdentifier().c_str()); +} + +void LLVMSetModuleIdentifier(LLVMModuleRef M, const char *ID) { + unwrap(M)->setModuleIdentifier(ID); +} + /*--.. Data layout .........................................................--*/ const char *LLVMGetDataLayoutStr(LLVMModuleRef M) { return unwrap(M)->getDataLayoutStr().c_str(); @@ -523,6 +531,9 @@ LLVMTypeRef LLVMLabelTypeInContext(LLVMContextRef C) { return wrap(Type::getLabelTy(*unwrap(C))); } +LLVMTypeRef LLVMMetadataTypeInContext(LLVMContextRef C) { + return wrap(Type::getMetadataTy(*unwrap(C))); +} LLVMTypeRef LLVMVoidType(void) { return LLVMVoidTypeInContext(LLVMGetGlobalContext()); @@ -530,6 +541,9 @@ LLVMTypeRef LLVMLabelType(void) { return LLVMLabelTypeInContext(LLVMGetGlobalContext()); } +LLVMTypeRef LLVMMetadataType(void) { + return LLVMMetadataTypeInContext(LLVMGetGlobalContext()); +} /*===-- Operations on values ----------------------------------------------===*/ @@ -539,6 +553,18 @@ return wrap(unwrap(Val)->getType()); } +LLVMValueKind LLVMGetValueKind(LLVMValueRef Val) { + switch(unwrap(Val)->getValueID()) { +#define VALUE_KIND_CASE(class) \ + case Value::class ## Val: \ + return LLVM ## class ## ValueKind; + LLVM_FOR_EACH_VALUE_KIND(VALUE_KIND_CASE) +#undef VALUE_KIND_CASE + default: break; + } + return LLVMValueKind(0); +} + const char *LLVMGetValueName(LLVMValueRef Val) { return unwrap(Val)->getName().data(); } @@ -858,6 +884,22 @@ Radix)); } + +unsigned long long LLVMConstIntGetZExtValue(LLVMValueRef ConstantVal) { + return unwrap(ConstantVal)->getZExtValue(); +} + +long long LLVMConstIntGetSExtValue(LLVMValueRef ConstantVal) { + return unwrap(ConstantVal)->getSExtValue(); +} + +const uint64_t *LLVMConstIntGetWords(LLVMValueRef ConstantVal, unsigned *n) { + const APInt &Int = unwrap(ConstantVal)->getValue(); + + *n = Int.getNumWords(); + return Int.getRawData(); +} + LLVMValueRef LLVMConstReal(LLVMTypeRef RealTy, double N) { return wrap(ConstantFP::get(unwrap(RealTy), N)); } @@ -871,12 +913,15 @@ return wrap(ConstantFP::get(unwrap(RealTy), StringRef(Str, SLen))); } -unsigned long long LLVMConstIntGetZExtValue(LLVMValueRef ConstantVal) { - return unwrap(ConstantVal)->getZExtValue(); -} +LLVMValueRef LLVMConstRealOfArbitraryPrecision(LLVMTypeRef RealTy, + unsigned NumWords, + const uint64_t Words[]) { + Type *Ty = unwrap(RealTy); + APInt IntRepr = APInt(Ty->getPrimitiveSizeInBits(), + makeArrayRef(Words, NumWords)); + APFloat Float = APFloat(Ty->getFltSemantics(), IntRepr); -long long LLVMConstIntGetSExtValue(LLVMValueRef ConstantVal) { - return unwrap(ConstantVal)->getSExtValue(); + return wrap(ConstantFP::get(Ty->getContext(), Float)); } double LLVMConstRealGetDouble(LLVMValueRef ConstantVal, LLVMBool *LosesInfo) { @@ -900,6 +945,15 @@ return APF.convertToDouble(); } +const uint64_t *LLVMConstRealGetWords(LLVMValueRef ConstantVal, unsigned *n) { + const APFloat &Float = unwrap(ConstantVal)->getValueAPF(); + const APInt &IntRepr = Float.bitcastToAPInt(); + + *n = IntRepr.getNumWords(); + return IntRepr.getRawData(); +} + + /*--.. Operations on composite constants ...................................--*/ LLVMValueRef LLVMConstStringInContext(LLVMContextRef C, const char *Str, @@ -993,6 +1047,11 @@ return map_to_llvmopcode(unwrap(ConstantVal)->getOpcode()); } +LLVMValueRef LLVMGetElementAsConstant(LLVMValueRef ConstantVal, unsigned n) { + return wrap(unwrap(ConstantVal)-> + getElementAsConstant(n)); +} + LLVMValueRef LLVMAlignOf(LLVMTypeRef Ty) { return wrap(ConstantExpr::getAlignOf(unwrap(Ty))); } @@ -1342,6 +1401,14 @@ return wrap(BlockAddress::get(unwrap(F), unwrap(BB))); } +LLVMValueRef LLVMGetBlockAddressFunction(LLVMValueRef BA) { + return wrap(unwrap(BA)->getFunction()); +} + +LLVMBasicBlockRef LLVMGetBlockAddressBlock(LLVMValueRef BA) { + return wrap(unwrap(BA)->getBasicBlock()); +} + /*--.. Operations on global variables, functions, and aliases (globals) ....--*/ LLVMModuleRef LLVMGetGlobalParent(LLVMValueRef Global) { @@ -1652,6 +1719,54 @@ unwrap(Aliasee), unwrap(M))); } +LLVMValueRef LLVMGetNamedAlias(LLVMModuleRef M, const char *Name) { + return wrap(unwrap(M)->getNamedAlias(Name)); +} + +LLVMValueRef LLVMGetFirstAlias(LLVMModuleRef M) { + Module *Mod = unwrap(M); + Module::alias_iterator I = Mod->alias_begin(); + if (I == Mod->alias_end()) + return 0; + return wrap(I); +} + +LLVMValueRef LLVMGetLastAlias(LLVMModuleRef M) { + Module *Mod = unwrap(M); + Module::alias_iterator I = Mod->alias_end(); + if (I == Mod->alias_begin()) + return 0; + return wrap(--I); +} + +LLVMValueRef LLVMGetNextAlias(LLVMValueRef Alias) { + GlobalAlias *GV = unwrap(Alias); + Module::alias_iterator I = GV; + if (++I == GV->getParent()->alias_end()) + return 0; + return wrap(I); +} + +LLVMValueRef LLVMGetPreviousAlias(LLVMValueRef Alias) { + GlobalAlias *GV = unwrap(Alias); + Module::alias_iterator I = GV; + if (I == GV->getParent()->alias_begin()) + return 0; + return wrap(--I); +} + +void LLVMDeleteAlias(LLVMValueRef Alias) { + unwrap(Alias)->eraseFromParent(); +} + +LLVMValueRef LLVMGetAliasee(LLVMValueRef A) { + return wrap(unwrap(A)->getAliasee()); +} + +void LLVMSetAliasee(LLVMValueRef A, LLVMValueRef Aliasee) { + unwrap(A)->setAliasee(unwrap(Aliasee)); +} + /*--.. Operations on functions .............................................--*/ LLVMValueRef LLVMAddFunction(LLVMModuleRef M, const char *Name, @@ -2050,6 +2165,227 @@ return nullptr; } +/*--.. GetElementPtr instruction ...........................................--*/ + +LLVMBool LLVMIsInBounds(LLVMValueRef Inst) { + return unwrap(Inst)->isInBounds(); +} + +void LLVMSetIsInBounds(LLVMValueRef Inst, LLVMBool IsInBounds) { + unwrap(Inst)->setIsInBounds(IsInBounds != 0); +} + +/*--.. Binary operators ....................................................--*/ + +LLVMBool LLVMHasNoSignedWrap(LLVMValueRef Instr) { + return unwrap(Instr)->hasNoSignedWrap(); +} + +void LLVMSetHasNoSignedWrap(LLVMValueRef Instr, LLVMBool HasNoSignedWrap) { + unwrap(Instr)->setHasNoSignedWrap(HasNoSignedWrap != 0); +} + +LLVMBool LLVMHasNoUnsignedWrap(LLVMValueRef Instr) { + return unwrap(Instr)->hasNoUnsignedWrap(); +} + +void LLVMSetHasNoUnsignedWrap(LLVMValueRef Instr, LLVMBool HasNoUnsignedWrap) { + unwrap(Instr)->setHasNoUnsignedWrap(HasNoUnsignedWrap != 0); +} + +LLVMBool LLVMIsExact(LLVMValueRef Instr) { + return unwrap(Instr)->isExact(); +} + +void LLVMSetIsExact(LLVMValueRef Instr, LLVMBool IsExact) { + unwrap(Instr)->setIsExact(IsExact != 0); +} + +/*--.. Alloca instructions .................................................--*/ + +LLVMBool LLVMIsArrayAlloca(LLVMValueRef Instr) { + return unwrap(Instr)->isArrayAllocation(); +} + +LLVMValueRef LLVMGetAllocaNumElements(LLVMValueRef Instr) { + return wrap(unwrap(Instr)->getArraySize()); +} + +LLVMTypeRef LLVMGetAllocatedType(LLVMValueRef Instr) { + return wrap(unwrap(Instr)->getAllocatedType()); +} + +/*--.. Atomic instructions .................................................--*/ + +static LLVMAtomicOrdering wrap(AtomicOrdering Ordering) { + switch(Ordering) { + case NotAtomic: + return LLVMAtomicOrderingNotAtomic; + case Unordered: + return LLVMAtomicOrderingUnordered; + case Monotonic: + return LLVMAtomicOrderingMonotonic; + case Acquire: + return LLVMAtomicOrderingAcquire; + case Release: + return LLVMAtomicOrderingRelease; + case AcquireRelease: + return LLVMAtomicOrderingAcquireRelease; + case SequentiallyConsistent: + return LLVMAtomicOrderingSequentiallyConsistent; + } +} + +static AtomicOrdering unwrap(LLVMAtomicOrdering ExtOrdering) { + switch(ExtOrdering) { + case LLVMAtomicOrderingNotAtomic: + return NotAtomic; + case LLVMAtomicOrderingUnordered: + return Unordered; + case LLVMAtomicOrderingMonotonic: + return Monotonic; + case LLVMAtomicOrderingAcquire: + return Acquire; + case LLVMAtomicOrderingRelease: + return Release; + case LLVMAtomicOrderingAcquireRelease: + return AcquireRelease; + case LLVMAtomicOrderingSequentiallyConsistent: + return SequentiallyConsistent; + } +} + +LLVMAtomicOrdering LLVMGetAtomicOrdering(LLVMValueRef Instr) { + AtomicOrdering Ordering; + + if(LoadInst *LI = dyn_cast_or_null(unwrap(Instr))) + Ordering = LI->getOrdering(); + else if(StoreInst *SI = dyn_cast_or_null(unwrap(Instr))) + Ordering = SI->getOrdering(); + else if(FenceInst *FI = dyn_cast_or_null(unwrap(Instr))) + Ordering = FI->getOrdering(); + else if(AtomicRMWInst *ARMWI = dyn_cast_or_null(unwrap(Instr))) + Ordering = ARMWI->getOrdering(); + else if(AtomicCmpXchgInst *ACXI = + dyn_cast_or_null(unwrap(Instr))) + Ordering = ACXI->getOrdering(); + + return wrap(Ordering); +} + +void LLVMSetAtomicOrdering(LLVMValueRef Instr, LLVMAtomicOrdering ExtOrdering) { + AtomicOrdering Ordering = unwrap(ExtOrdering); + + if(LoadInst *LI = dyn_cast_or_null(unwrap(Instr))) + LI->setOrdering(Ordering); + else if(StoreInst *SI = dyn_cast_or_null(unwrap(Instr))) + SI->setOrdering(Ordering); + else if(FenceInst *FI = dyn_cast_or_null(unwrap(Instr))) + FI->setOrdering(Ordering); + else if(AtomicRMWInst *ARMWI = dyn_cast_or_null(unwrap(Instr))) + ARMWI->setOrdering(Ordering); + else if(AtomicCmpXchgInst *ACXI = + dyn_cast_or_null(unwrap(Instr))) + ACXI->setOrdering(Ordering); +} + +static LLVMSynchronizationScope wrap(SynchronizationScope Scope) { + switch(Scope) { + case SingleThread: + return LLVMSynchronizationScopeSingleThread; + case CrossThread: + return LLVMSynchronizationScopeCrossThread; + } +} + +static SynchronizationScope unwrap(LLVMSynchronizationScope ExtScope) { + switch(ExtScope) { + case LLVMSynchronizationScopeSingleThread: + return SingleThread; + case LLVMSynchronizationScopeCrossThread: + return CrossThread; + } +} + +LLVMSynchronizationScope LLVMGetSynchronizationScope(LLVMValueRef Instr) { + SynchronizationScope Scope; + + if(LoadInst *LI = dyn_cast_or_null(unwrap(Instr))) + Scope = LI->getSynchScope(); + else if(StoreInst *SI = dyn_cast_or_null(unwrap(Instr))) + Scope = SI->getSynchScope(); + else if(FenceInst *FI = dyn_cast_or_null(unwrap(Instr))) + Scope = FI->getSynchScope(); + else if(AtomicRMWInst *ARMWI = dyn_cast_or_null(unwrap(Instr))) + Scope = ARMWI->getSynchScope(); + else if(AtomicCmpXchgInst *ACXI = + dyn_cast_or_null(unwrap(Instr))) + Scope = ACXI->getSynchScope(); + + return wrap(Scope); +} + +void LLVMSetSynchronizationScope(LLVMValueRef Instr, + LLVMSynchronizationScope ExtScope) { + SynchronizationScope Scope = unwrap(ExtScope); + + if(LoadInst *LI = dyn_cast_or_null(unwrap(Instr))) + LI->setSynchScope(Scope); + else if(StoreInst *SI = dyn_cast_or_null(unwrap(Instr))) + SI->setSynchScope(Scope); + else if(FenceInst *FI = dyn_cast_or_null(unwrap(Instr))) + FI->setSynchScope(Scope); + else if(AtomicRMWInst *ARMWI = dyn_cast_or_null(unwrap(Instr))) + ARMWI->setSynchScope(Scope); + else if(AtomicCmpXchgInst *ACXI = + dyn_cast_or_null(unwrap(Instr))) + ACXI->setSynchScope(Scope); +} + +/*--.. AtomicRMW instructions ..............................................--*/ + +static LLVMAtomicRMWBinOp wrap(AtomicRMWInst::BinOp Op) { + switch (Op) { + default: llvm_unreachable("Unknown LLVMAtomicRMWBinOp"); + case AtomicRMWInst::Xchg: return LLVMAtomicRMWBinOpXchg; + case AtomicRMWInst::Add: return LLVMAtomicRMWBinOpAdd; + case AtomicRMWInst::Sub: return LLVMAtomicRMWBinOpSub; + case AtomicRMWInst::And: return LLVMAtomicRMWBinOpAnd; + case AtomicRMWInst::Nand: return LLVMAtomicRMWBinOpNand; + case AtomicRMWInst::Or: return LLVMAtomicRMWBinOpOr; + case AtomicRMWInst::Xor: return LLVMAtomicRMWBinOpXor; + case AtomicRMWInst::Max: return LLVMAtomicRMWBinOpMax; + case AtomicRMWInst::Min: return LLVMAtomicRMWBinOpMin; + case AtomicRMWInst::UMax: return LLVMAtomicRMWBinOpUMax; + case AtomicRMWInst::UMin: return LLVMAtomicRMWBinOpUMin; + } +} + +static AtomicRMWInst::BinOp unwrap(LLVMAtomicRMWBinOp ExtOp) { + switch (ExtOp) { + case LLVMAtomicRMWBinOpXchg: return AtomicRMWInst::Xchg; + case LLVMAtomicRMWBinOpAdd: return AtomicRMWInst::Add; + case LLVMAtomicRMWBinOpSub: return AtomicRMWInst::Sub; + case LLVMAtomicRMWBinOpAnd: return AtomicRMWInst::And; + case LLVMAtomicRMWBinOpNand: return AtomicRMWInst::Nand; + case LLVMAtomicRMWBinOpOr: return AtomicRMWInst::Or; + case LLVMAtomicRMWBinOpXor: return AtomicRMWInst::Xor; + case LLVMAtomicRMWBinOpMax: return AtomicRMWInst::Max; + case LLVMAtomicRMWBinOpMin: return AtomicRMWInst::Min; + case LLVMAtomicRMWBinOpUMax: return AtomicRMWInst::UMax; + case LLVMAtomicRMWBinOpUMin: return AtomicRMWInst::UMin; + } +} + +LLVMAtomicRMWBinOp LLVMGetAtomicRMWOperation(LLVMValueRef Instr) { + return wrap(unwrap(Instr)->getOperation()); +} + +void LLVMSetAtomicRMWOperation(LLVMValueRef Instr, LLVMAtomicRMWBinOp ExtOp) { + dyn_cast(unwrap(Instr))->setOperation(unwrap(ExtOp)); +} + + /*--.. Call and invoke instructions ........................................--*/ unsigned LLVMGetNumArgOperands(LLVMValueRef Instr) { @@ -2158,10 +2494,50 @@ /*--.. Operations on switch instructions (only) ............................--*/ +void LLVMAddCase(LLVMValueRef Switch, LLVMValueRef OnVal, + LLVMBasicBlockRef Dest) { + unwrap(Switch)->addCase(unwrap(OnVal), unwrap(Dest)); +} + LLVMBasicBlockRef LLVMGetSwitchDefaultDest(LLVMValueRef Switch) { return wrap(unwrap(Switch)->getDefaultDest()); } +unsigned LLVMGetSwitchNumCases(LLVMValueRef SwitchInstr) { + return unwrap(SwitchInstr)->getNumCases(); +} + +void LLVMGetSwitchCases(LLVMValueRef SwitchInstr, LLVMValueRef *Values, + LLVMBasicBlockRef *Successors) { + SwitchInst *SI = unwrap(SwitchInstr); + + for (SwitchInst::CaseIt i = SI->case_begin(); + i != SI->case_end(); ++i, ++Values, ++Successors) { + *Values = wrap(i.getCaseValue()); + *Successors = wrap(i.getCaseSuccessor()); + } +} + +/*--.. Operations on indirectbr instructions (only) ........................--*/ + +void LLVMAddDestination(LLVMValueRef IndirectBr, LLVMBasicBlockRef Dest) { + unwrap(IndirectBr)->addDestination(unwrap(Dest)); +} + +unsigned LLVMGetIndirectBrNumDestinations(LLVMValueRef IndirectBr) { + return unwrap(IndirectBr)->getNumDestinations(); +} + +void LLVMGetIndirectBrDestinations(LLVMValueRef IndirectBr, + LLVMBasicBlockRef *Successors) { + IndirectBrInst *IBI = unwrap(IndirectBr); + + for (unsigned i = 0; i != IBI->getNumDestinations(); ++i, ++Successors) { + *Successors = wrap(IBI->getDestination(i)); + } +} + + /*--.. Operations on alloca instructions (only) ............................--*/ LLVMTypeRef LLVMGetAllocatedType(LLVMValueRef Alloca) { @@ -2354,15 +2730,6 @@ return wrap(unwrap(B)->CreateUnreachable()); } -void LLVMAddCase(LLVMValueRef Switch, LLVMValueRef OnVal, - LLVMBasicBlockRef Dest) { - unwrap(Switch)->addCase(unwrap(OnVal), unwrap(Dest)); -} - -void LLVMAddDestination(LLVMValueRef IndirectBr, LLVMBasicBlockRef Dest) { - unwrap(IndirectBr)->addDestination(unwrap(Dest)); -} - unsigned LLVMGetNumClauses(LLVMValueRef LandingPad) { return unwrap(LandingPad)->getNumClauses(); } @@ -2886,38 +3253,25 @@ return wrap(unwrap(B)->CreatePtrDiff(unwrap(LHS), unwrap(RHS), Name)); } -LLVMValueRef LLVMBuildAtomicRMW(LLVMBuilderRef B,LLVMAtomicRMWBinOp op, - LLVMValueRef PTR, LLVMValueRef Val, - LLVMAtomicOrdering ordering, - LLVMBool singleThread) { - AtomicRMWInst::BinOp intop; - switch (op) { - case LLVMAtomicRMWBinOpXchg: intop = AtomicRMWInst::Xchg; break; - case LLVMAtomicRMWBinOpAdd: intop = AtomicRMWInst::Add; break; - case LLVMAtomicRMWBinOpSub: intop = AtomicRMWInst::Sub; break; - case LLVMAtomicRMWBinOpAnd: intop = AtomicRMWInst::And; break; - case LLVMAtomicRMWBinOpNand: intop = AtomicRMWInst::Nand; break; - case LLVMAtomicRMWBinOpOr: intop = AtomicRMWInst::Or; break; - case LLVMAtomicRMWBinOpXor: intop = AtomicRMWInst::Xor; break; - case LLVMAtomicRMWBinOpMax: intop = AtomicRMWInst::Max; break; - case LLVMAtomicRMWBinOpMin: intop = AtomicRMWInst::Min; break; - case LLVMAtomicRMWBinOpUMax: intop = AtomicRMWInst::UMax; break; - case LLVMAtomicRMWBinOpUMin: intop = AtomicRMWInst::UMin; break; - } - return wrap(unwrap(B)->CreateAtomicRMW(intop, unwrap(PTR), unwrap(Val), - mapFromLLVMOrdering(ordering), singleThread ? SingleThread : CrossThread)); + +LLVMValueRef LLVMBuildAtomicRMW(LLVMBuilderRef B, LLVMAtomicRMWBinOp Op, + LLVMValueRef Ptr, LLVMValueRef Val, + LLVMAtomicOrdering Ordering, + LLVMBool oneThread) { + return wrap(unwrap(B)->CreateAtomicRMW(unwrap(Op), unwrap(Ptr), unwrap(Val), + unwrap(Ordering), oneThread ? SingleThread : CrossThread)); } LLVMValueRef LLVMBuildAtomicCmpXchg(LLVMBuilderRef B, LLVMValueRef Ptr, - LLVMValueRef Cmp, LLVMValueRef New, - LLVMAtomicOrdering SuccessOrdering, - LLVMAtomicOrdering FailureOrdering, - LLVMBool singleThread) { - - return wrap(unwrap(B)->CreateAtomicCmpXchg(unwrap(Ptr), unwrap(Cmp), - unwrap(New), mapFromLLVMOrdering(SuccessOrdering), - mapFromLLVMOrdering(FailureOrdering), - singleThread ? SingleThread : CrossThread)); + LLVMValueRef Cmp, LLVMValueRef Val, + LLVMAtomicOrdering Ordering, + LLVMSynchronizationScope Scope, + const char *Name) { + Value *Instr = unwrap(B)->CreateAtomicCmpXchg(unwrap(Ptr), unwrap(Cmp), + unwrap(Val), unwrap(Ordering), unwrap(Scope)); + Instr->setName(Name); + + return wrap(Instr); }