From 4ff90c7e0aa60cfab0d4fd5e52fcc63a7afd81c3 Mon Sep 17 00:00:00 2001 From: gnzlbg Date: Fri, 29 Jun 2018 10:28:51 +0200 Subject: bump minimum LLVM version to 5.0 --- src/rustllvm/RustWrapper.cpp | 201 +------------------------------------------ 1 file changed, 3 insertions(+), 198 deletions(-) (limited to 'src/rustllvm/RustWrapper.cpp') diff --git a/src/rustllvm/RustWrapper.cpp b/src/rustllvm/RustWrapper.cpp index df8602d0803..2ac7a6a46ba 100644 --- a/src/rustllvm/RustWrapper.cpp +++ b/src/rustllvm/RustWrapper.cpp @@ -16,14 +16,8 @@ #include "llvm/Object/Archive.h" #include "llvm/Object/ObjectFile.h" #include "llvm/Bitcode/BitcodeWriterPass.h" - #include "llvm/IR/CallSite.h" - -#if LLVM_VERSION_GE(5, 0) #include "llvm/ADT/Optional.h" -#else -#include -#endif //===----------------------------------------------------------------------=== // @@ -176,14 +170,7 @@ extern "C" void LLVMRustAddCallSiteAttribute(LLVMValueRef Instr, unsigned Index, LLVMRustAttribute RustAttr) { CallSite Call = CallSite(unwrap(Instr)); Attribute Attr = Attribute::get(Call->getContext(), fromRust(RustAttr)); -#if LLVM_VERSION_GE(5, 0) Call.addAttribute(Index, Attr); -#else - AttrBuilder B(Attr); - Call.setAttributes(Call.getAttributes().addAttributes( - Call->getContext(), Index, - AttributeSet::get(Call->getContext(), Index, B))); -#endif } extern "C" void LLVMRustAddAlignmentCallSiteAttr(LLVMValueRef Instr, @@ -192,14 +179,8 @@ extern "C" void LLVMRustAddAlignmentCallSiteAttr(LLVMValueRef Instr, CallSite Call = CallSite(unwrap(Instr)); AttrBuilder B; B.addAlignmentAttr(Bytes); -#if LLVM_VERSION_GE(5, 0) Call.setAttributes(Call.getAttributes().addAttributes( Call->getContext(), Index, B)); -#else - Call.setAttributes(Call.getAttributes().addAttributes( - Call->getContext(), Index, - AttributeSet::get(Call->getContext(), Index, B))); -#endif } extern "C" void LLVMRustAddDereferenceableCallSiteAttr(LLVMValueRef Instr, @@ -208,14 +189,8 @@ extern "C" void LLVMRustAddDereferenceableCallSiteAttr(LLVMValueRef Instr, CallSite Call = CallSite(unwrap(Instr)); AttrBuilder B; B.addDereferenceableAttr(Bytes); -#if LLVM_VERSION_GE(5, 0) Call.setAttributes(Call.getAttributes().addAttributes( Call->getContext(), Index, B)); -#else - Call.setAttributes(Call.getAttributes().addAttributes( - Call->getContext(), Index, - AttributeSet::get(Call->getContext(), Index, B))); -#endif } extern "C" void LLVMRustAddDereferenceableOrNullCallSiteAttr(LLVMValueRef Instr, @@ -224,14 +199,8 @@ extern "C" void LLVMRustAddDereferenceableOrNullCallSiteAttr(LLVMValueRef Instr, CallSite Call = CallSite(unwrap(Instr)); AttrBuilder B; B.addDereferenceableOrNullAttr(Bytes); -#if LLVM_VERSION_GE(5, 0) Call.setAttributes(Call.getAttributes().addAttributes( Call->getContext(), Index, B)); -#else - Call.setAttributes(Call.getAttributes().addAttributes( - Call->getContext(), Index, - AttributeSet::get(Call->getContext(), Index, B))); -#endif } extern "C" void LLVMRustAddFunctionAttribute(LLVMValueRef Fn, unsigned Index, @@ -239,11 +208,7 @@ extern "C" void LLVMRustAddFunctionAttribute(LLVMValueRef Fn, unsigned Index, Function *A = unwrap(Fn); Attribute Attr = Attribute::get(A->getContext(), fromRust(RustAttr)); AttrBuilder B(Attr); -#if LLVM_VERSION_GE(5, 0) A->addAttributes(Index, B); -#else - A->addAttributes(Index, AttributeSet::get(A->getContext(), Index, B)); -#endif } extern "C" void LLVMRustAddAlignmentAttr(LLVMValueRef Fn, @@ -252,11 +217,7 @@ extern "C" void LLVMRustAddAlignmentAttr(LLVMValueRef Fn, Function *A = unwrap(Fn); AttrBuilder B; B.addAlignmentAttr(Bytes); -#if LLVM_VERSION_GE(5, 0) A->addAttributes(Index, B); -#else - A->addAttributes(Index, AttributeSet::get(A->getContext(), Index, B)); -#endif } extern "C" void LLVMRustAddDereferenceableAttr(LLVMValueRef Fn, unsigned Index, @@ -264,11 +225,7 @@ extern "C" void LLVMRustAddDereferenceableAttr(LLVMValueRef Fn, unsigned Index, Function *A = unwrap(Fn); AttrBuilder B; B.addDereferenceableAttr(Bytes); -#if LLVM_VERSION_GE(5, 0) A->addAttributes(Index, B); -#else - A->addAttributes(Index, AttributeSet::get(A->getContext(), Index, B)); -#endif } extern "C" void LLVMRustAddDereferenceableOrNullAttr(LLVMValueRef Fn, @@ -277,11 +234,7 @@ extern "C" void LLVMRustAddDereferenceableOrNullAttr(LLVMValueRef Fn, Function *A = unwrap(Fn); AttrBuilder B; B.addDereferenceableOrNullAttr(Bytes); -#if LLVM_VERSION_GE(5, 0) A->addAttributes(Index, B); -#else - A->addAttributes(Index, AttributeSet::get(A->getContext(), Index, B)); -#endif } extern "C" void LLVMRustAddFunctionAttrStringValue(LLVMValueRef Fn, @@ -291,11 +244,7 @@ extern "C" void LLVMRustAddFunctionAttrStringValue(LLVMValueRef Fn, Function *F = unwrap(Fn); AttrBuilder B; B.addAttribute(Name, Value); -#if LLVM_VERSION_GE(5, 0) F->addAttributes(Index, B); -#else - F->addAttributes(Index, AttributeSet::get(F->getContext(), Index, B)); -#endif } extern "C" void LLVMRustRemoveFunctionAttributes(LLVMValueRef Fn, @@ -305,12 +254,7 @@ extern "C" void LLVMRustRemoveFunctionAttributes(LLVMValueRef Fn, Attribute Attr = Attribute::get(F->getContext(), fromRust(RustAttr)); AttrBuilder B(Attr); auto PAL = F->getAttributes(); -#if LLVM_VERSION_GE(5, 0) auto PALNew = PAL.removeAttributes(F->getContext(), Index, B); -#else - const AttributeSet PALNew = PAL.removeAttributes( - F->getContext(), Index, AttributeSet::get(F->getContext(), Index, B)); -#endif F->setAttributes(PALNew); } @@ -360,7 +304,6 @@ enum class LLVMRustSynchronizationScope { CrossThread, }; -#if LLVM_VERSION_GE(5, 0) static SyncScope::ID fromRust(LLVMRustSynchronizationScope Scope) { switch (Scope) { case LLVMRustSynchronizationScope::SingleThread: @@ -371,18 +314,6 @@ static SyncScope::ID fromRust(LLVMRustSynchronizationScope Scope) { report_fatal_error("bad SynchronizationScope."); } } -#else -static SynchronizationScope fromRust(LLVMRustSynchronizationScope Scope) { - switch (Scope) { - case LLVMRustSynchronizationScope::SingleThread: - return SingleThread; - case LLVMRustSynchronizationScope::CrossThread: - return CrossThread; - default: - report_fatal_error("bad SynchronizationScope."); - } -} -#endif extern "C" LLVMValueRef LLVMRustBuildAtomicFence(LLVMBuilderRef B, LLVMAtomicOrdering Order, @@ -422,18 +353,6 @@ extern "C" void LLVMRustAppendModuleInlineAsm(LLVMModuleRef M, const char *Asm) typedef DIBuilder *LLVMRustDIBuilderRef; -#if LLVM_VERSION_LT(5, 0) -typedef struct LLVMOpaqueMetadata *LLVMMetadataRef; - -namespace llvm { -DEFINE_ISA_CONVERSION_FUNCTIONS(Metadata, LLVMMetadataRef) - -inline Metadata **unwrap(LLVMMetadataRef *Vals) { - return reinterpret_cast(Vals); -} -} -#endif - template DIT *unwrapDIPtr(LLVMMetadataRef Ref) { return (DIT *)(Ref ? unwrap(Ref) : nullptr); } @@ -492,13 +411,8 @@ inline LLVMRustDIFlags visibility(LLVMRustDIFlags F) { return static_cast(static_cast(F) & 0x3); } -#if LLVM_VERSION_GE(4, 0) static DINode::DIFlags fromRust(LLVMRustDIFlags Flags) { DINode::DIFlags Result = DINode::DIFlags::FlagZero; -#else -static unsigned fromRust(LLVMRustDIFlags Flags) { - unsigned Result = 0; -#endif switch (visibility(Flags)) { case LLVMRustDIFlags::FlagPrivate: @@ -554,25 +468,18 @@ static unsigned fromRust(LLVMRustDIFlags Flags) { if (isSet(Flags & LLVMRustDIFlags::FlagRValueReference)) { Result |= DINode::DIFlags::FlagRValueReference; } -#if LLVM_VERSION_LE(4, 0) - if (isSet(Flags & LLVMRustDIFlags::FlagExternalTypeRef)) { - Result |= DINode::DIFlags::FlagExternalTypeRef; - } -#endif if (isSet(Flags & LLVMRustDIFlags::FlagIntroducedVirtual)) { Result |= DINode::DIFlags::FlagIntroducedVirtual; } if (isSet(Flags & LLVMRustDIFlags::FlagBitField)) { Result |= DINode::DIFlags::FlagBitField; } -#if LLVM_RUSTLLVM || LLVM_VERSION_GE(4, 0) if (isSet(Flags & LLVMRustDIFlags::FlagNoReturn)) { Result |= DINode::DIFlags::FlagNoReturn; } if (isSet(Flags & LLVMRustDIFlags::FlagMainSubprogram)) { Result |= DINode::DIFlags::FlagMainSubprogram; } -#endif return Result; } @@ -612,14 +519,8 @@ extern "C" LLVMMetadataRef LLVMRustDIBuilderCreateCompileUnit( unsigned RuntimeVer, const char *SplitName) { auto *File = unwrapDI(FileRef); -#if LLVM_VERSION_GE(4, 0) return wrap(Builder->createCompileUnit(Lang, File, Producer, isOptimized, Flags, RuntimeVer, SplitName)); -#else - return wrap(Builder->createCompileUnit(Lang, File->getFilename(), - File->getDirectory(), Producer, isOptimized, - Flags, RuntimeVer, SplitName)); -#endif } extern "C" LLVMMetadataRef @@ -657,11 +558,7 @@ extern "C" LLVMMetadataRef LLVMRustDIBuilderCreateBasicType(LLVMRustDIBuilderRef Builder, const char *Name, uint64_t SizeInBits, uint32_t AlignInBits, unsigned Encoding) { - return wrap(Builder->createBasicType(Name, SizeInBits, -#if LLVM_VERSION_LE(3, 9) - AlignInBits, -#endif - Encoding)); + return wrap(Builder->createBasicType(Name, SizeInBits, Encoding)); } extern "C" LLVMMetadataRef LLVMRustDIBuilderCreatePointerType( @@ -669,9 +566,7 @@ extern "C" LLVMMetadataRef LLVMRustDIBuilderCreatePointerType( uint64_t SizeInBits, uint32_t AlignInBits, const char *Name) { return wrap(Builder->createPointerType(unwrapDI(PointeeTy), SizeInBits, AlignInBits, -#if LLVM_VERSION_GE(5, 0) /* DWARFAddressSpace */ None, -#endif Name)); } @@ -722,7 +617,6 @@ extern "C" LLVMMetadataRef LLVMRustDIBuilderCreateStaticVariable( LLVMMetadataRef Decl = nullptr, uint32_t AlignInBits = 0) { llvm::GlobalVariable *InitVal = cast(unwrap(V)); -#if LLVM_VERSION_GE(4, 0) llvm::DIExpression *InitExpr = nullptr; if (llvm::ConstantInt *IntVal = llvm::dyn_cast(InitVal)) { InitExpr = Builder->createConstantValueExpression( @@ -741,12 +635,6 @@ extern "C" LLVMMetadataRef LLVMRustDIBuilderCreateStaticVariable( InitVal->setMetadata("dbg", VarExpr); return wrap(VarExpr); -#else - return wrap(Builder->createGlobalVariable( - unwrapDI(Context), Name, LinkageName, - unwrapDI(File), LineNo, unwrapDI(Ty), IsLocalToUnit, - InitVal, unwrapDIPtr(Decl))); -#endif } extern "C" LLVMMetadataRef LLVMRustDIBuilderCreateVariable( @@ -757,12 +645,7 @@ extern "C" LLVMMetadataRef LLVMRustDIBuilderCreateVariable( if (Tag == 0x100) { // DW_TAG_auto_variable return wrap(Builder->createAutoVariable( unwrapDI(Scope), Name, unwrapDI(File), LineNo, - unwrapDI(Ty), AlwaysPreserve, fromRust(Flags) -#if LLVM_VERSION_GE(4, 0) - , - AlignInBits -#endif - )); + unwrapDI(Ty), AlwaysPreserve, fromRust(Flags), AlignInBits)); } else { return wrap(Builder->createParameterVariable( unwrapDI(Scope), Name, ArgNo, unwrapDI(File), @@ -854,15 +737,8 @@ LLVMRustDIBuilderCreateNameSpace(LLVMRustDIBuilderRef Builder, LLVMMetadataRef Scope, const char *Name, LLVMMetadataRef File, unsigned LineNo) { return wrap(Builder->createNameSpace( - unwrapDI(Scope), Name -#if LLVM_VERSION_LT(5, 0) - , - unwrapDI(File), LineNo -#endif -#if LLVM_VERSION_GE(4, 0) - , + unwrapDI(Scope), Name, false // ExportSymbols (only relevant for C++ anonymous namespaces) -#endif )); } @@ -891,12 +767,7 @@ extern "C" int64_t LLVMRustDIBuilderCreateOpDeref() { } extern "C" int64_t LLVMRustDIBuilderCreateOpPlusUconst() { -#if LLVM_VERSION_GE(5, 0) return dwarf::DW_OP_plus_uconst; -#else - // older LLVM used `plus` to behave like `plus_uconst`. - return dwarf::DW_OP_plus; -#endif } extern "C" void LLVMRustWriteTypeToString(LLVMTypeRef Ty, RustStringRef Str) { @@ -968,21 +839,12 @@ extern "C" void LLVMRustUnpackOptimizationDiagnostic( *FunctionOut = wrap(&Opt->getFunction()); RawRustStringOstream FilenameOS(FilenameOut); -#if LLVM_VERSION_GE(5,0) DiagnosticLocation loc = Opt->getLocation(); if (loc.isValid()) { *Line = loc.getLine(); *Column = loc.getColumn(); FilenameOS << loc.getFilename(); } -#else - const DebugLoc &loc = Opt->getDebugLoc(); - if (loc) { - *Line = loc.getLine(); - *Column = loc.getCol(); - FilenameOS << cast(loc.getScope())->getFilename(); - } -#endif RawRustStringOstream MessageOS(MessageOut); MessageOS << Opt->getMsg(); @@ -1402,7 +1264,6 @@ LLVMRustModuleCost(LLVMModuleRef M) { } // Vector reductions: -#if LLVM_VERSION_GE(5, 0) extern "C" LLVMValueRef LLVMRustBuildVectorReduceFAdd(LLVMBuilderRef B, LLVMValueRef Acc, LLVMValueRef Src) { return wrap(unwrap(B)->CreateFAddReduce(unwrap(Acc),unwrap(Src))); @@ -1448,62 +1309,6 @@ LLVMRustBuildVectorReduceFMax(LLVMBuilderRef B, LLVMValueRef Src, bool NoNaN) { return wrap(unwrap(B)->CreateFPMaxReduce(unwrap(Src), NoNaN)); } -#else - -extern "C" LLVMValueRef -LLVMRustBuildVectorReduceFAdd(LLVMBuilderRef, LLVMValueRef, LLVMValueRef) { - return nullptr; -} -extern "C" LLVMValueRef -LLVMRustBuildVectorReduceFMul(LLVMBuilderRef, LLVMValueRef, LLVMValueRef) { - return nullptr; -} -extern "C" LLVMValueRef -LLVMRustBuildVectorReduceAdd(LLVMBuilderRef, LLVMValueRef) { - return nullptr; -} -extern "C" LLVMValueRef -LLVMRustBuildVectorReduceMul(LLVMBuilderRef, LLVMValueRef) { - return nullptr; -} -extern "C" LLVMValueRef -LLVMRustBuildVectorReduceAnd(LLVMBuilderRef, LLVMValueRef) { - return nullptr; -} -extern "C" LLVMValueRef -LLVMRustBuildVectorReduceOr(LLVMBuilderRef, LLVMValueRef) { - return nullptr; -} -extern "C" LLVMValueRef -LLVMRustBuildVectorReduceXor(LLVMBuilderRef, LLVMValueRef) { - return nullptr; -} -extern "C" LLVMValueRef -LLVMRustBuildVectorReduceMin(LLVMBuilderRef, LLVMValueRef, bool) { - return nullptr; -} -extern "C" LLVMValueRef -LLVMRustBuildVectorReduceMax(LLVMBuilderRef, LLVMValueRef, bool) { - return nullptr; -} -extern "C" LLVMValueRef -LLVMRustBuildVectorReduceFMin(LLVMBuilderRef, LLVMValueRef, bool) { - return nullptr; -} -extern "C" LLVMValueRef -LLVMRustBuildVectorReduceFMax(LLVMBuilderRef, LLVMValueRef, bool) { - return nullptr; -} -#endif - -#if LLVM_VERSION_LT(4, 0) -extern "C" LLVMValueRef -LLVMBuildExactUDiv(LLVMBuilderRef B, LLVMValueRef LHS, - LLVMValueRef RHS, const char *Name) { - return wrap(unwrap(B)->CreateExactUDiv(unwrap(LHS), unwrap(RHS), Name)); -} -#endif - #if LLVM_VERSION_GE(6, 0) extern "C" LLVMValueRef LLVMRustBuildMinNum(LLVMBuilderRef B, LLVMValueRef LHS, LLVMValueRef RHS) { -- cgit 1.4.1-3-g733a5 From 23dfb42ab3010418d54f852ddad263b1e7148fab Mon Sep 17 00:00:00 2001 From: gnzlbg Date: Mon, 9 Jul 2018 11:29:13 +0200 Subject: still support LLVM4 for emscripten --- src/rustllvm/RustWrapper.cpp | 168 ++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 167 insertions(+), 1 deletion(-) (limited to 'src/rustllvm/RustWrapper.cpp') diff --git a/src/rustllvm/RustWrapper.cpp b/src/rustllvm/RustWrapper.cpp index 2ac7a6a46ba..d82410618d0 100644 --- a/src/rustllvm/RustWrapper.cpp +++ b/src/rustllvm/RustWrapper.cpp @@ -16,8 +16,14 @@ #include "llvm/Object/Archive.h" #include "llvm/Object/ObjectFile.h" #include "llvm/Bitcode/BitcodeWriterPass.h" + #include "llvm/IR/CallSite.h" + +#if LLVM_VERSION_GE(5, 0) #include "llvm/ADT/Optional.h" +#else +#include +#endif //===----------------------------------------------------------------------=== // @@ -170,7 +176,14 @@ extern "C" void LLVMRustAddCallSiteAttribute(LLVMValueRef Instr, unsigned Index, LLVMRustAttribute RustAttr) { CallSite Call = CallSite(unwrap(Instr)); Attribute Attr = Attribute::get(Call->getContext(), fromRust(RustAttr)); +#if LLVM_VERSION_GE(5, 0) Call.addAttribute(Index, Attr); +#else + AttrBuilder B(Attr); + Call.setAttributes(Call.getAttributes().addAttributes( + Call->getContext(), Index, + AttributeSet::get(Call->getContext(), Index, B))); +#endif } extern "C" void LLVMRustAddAlignmentCallSiteAttr(LLVMValueRef Instr, @@ -179,8 +192,14 @@ extern "C" void LLVMRustAddAlignmentCallSiteAttr(LLVMValueRef Instr, CallSite Call = CallSite(unwrap(Instr)); AttrBuilder B; B.addAlignmentAttr(Bytes); +#if LLVM_VERSION_GE(5, 0) Call.setAttributes(Call.getAttributes().addAttributes( Call->getContext(), Index, B)); +#else + Call.setAttributes(Call.getAttributes().addAttributes( + Call->getContext(), Index, + AttributeSet::get(Call->getContext(), Index, B))); +#endif } extern "C" void LLVMRustAddDereferenceableCallSiteAttr(LLVMValueRef Instr, @@ -189,8 +208,14 @@ extern "C" void LLVMRustAddDereferenceableCallSiteAttr(LLVMValueRef Instr, CallSite Call = CallSite(unwrap(Instr)); AttrBuilder B; B.addDereferenceableAttr(Bytes); +#if LLVM_VERSION_GE(5, 0) Call.setAttributes(Call.getAttributes().addAttributes( Call->getContext(), Index, B)); +#else + Call.setAttributes(Call.getAttributes().addAttributes( + Call->getContext(), Index, + AttributeSet::get(Call->getContext(), Index, B))); +#endif } extern "C" void LLVMRustAddDereferenceableOrNullCallSiteAttr(LLVMValueRef Instr, @@ -199,8 +224,14 @@ extern "C" void LLVMRustAddDereferenceableOrNullCallSiteAttr(LLVMValueRef Instr, CallSite Call = CallSite(unwrap(Instr)); AttrBuilder B; B.addDereferenceableOrNullAttr(Bytes); +#if LLVM_VERSION_GE(5, 0) Call.setAttributes(Call.getAttributes().addAttributes( Call->getContext(), Index, B)); +#else + Call.setAttributes(Call.getAttributes().addAttributes( + Call->getContext(), Index, + AttributeSet::get(Call->getContext(), Index, B))); +#endif } extern "C" void LLVMRustAddFunctionAttribute(LLVMValueRef Fn, unsigned Index, @@ -208,7 +239,11 @@ extern "C" void LLVMRustAddFunctionAttribute(LLVMValueRef Fn, unsigned Index, Function *A = unwrap(Fn); Attribute Attr = Attribute::get(A->getContext(), fromRust(RustAttr)); AttrBuilder B(Attr); +#if LLVM_VERSION_GE(5, 0) A->addAttributes(Index, B); +#else + A->addAttributes(Index, AttributeSet::get(A->getContext(), Index, B)); +#endif } extern "C" void LLVMRustAddAlignmentAttr(LLVMValueRef Fn, @@ -217,7 +252,11 @@ extern "C" void LLVMRustAddAlignmentAttr(LLVMValueRef Fn, Function *A = unwrap(Fn); AttrBuilder B; B.addAlignmentAttr(Bytes); +#if LLVM_VERSION_GE(5, 0) A->addAttributes(Index, B); +#else + A->addAttributes(Index, AttributeSet::get(A->getContext(), Index, B)); +#endif } extern "C" void LLVMRustAddDereferenceableAttr(LLVMValueRef Fn, unsigned Index, @@ -225,7 +264,11 @@ extern "C" void LLVMRustAddDereferenceableAttr(LLVMValueRef Fn, unsigned Index, Function *A = unwrap(Fn); AttrBuilder B; B.addDereferenceableAttr(Bytes); +#if LLVM_VERSION_GE(5, 0) A->addAttributes(Index, B); +#else + A->addAttributes(Index, AttributeSet::get(A->getContext(), Index, B)); +#endif } extern "C" void LLVMRustAddDereferenceableOrNullAttr(LLVMValueRef Fn, @@ -234,7 +277,11 @@ extern "C" void LLVMRustAddDereferenceableOrNullAttr(LLVMValueRef Fn, Function *A = unwrap(Fn); AttrBuilder B; B.addDereferenceableOrNullAttr(Bytes); +#if LLVM_VERSION_GE(5, 0) A->addAttributes(Index, B); +#else + A->addAttributes(Index, AttributeSet::get(A->getContext(), Index, B)); +#endif } extern "C" void LLVMRustAddFunctionAttrStringValue(LLVMValueRef Fn, @@ -244,7 +291,11 @@ extern "C" void LLVMRustAddFunctionAttrStringValue(LLVMValueRef Fn, Function *F = unwrap(Fn); AttrBuilder B; B.addAttribute(Name, Value); +#if LLVM_VERSION_GE(5, 0) F->addAttributes(Index, B); +#else + F->addAttributes(Index, AttributeSet::get(F->getContext(), Index, B)); +#endif } extern "C" void LLVMRustRemoveFunctionAttributes(LLVMValueRef Fn, @@ -254,7 +305,12 @@ extern "C" void LLVMRustRemoveFunctionAttributes(LLVMValueRef Fn, Attribute Attr = Attribute::get(F->getContext(), fromRust(RustAttr)); AttrBuilder B(Attr); auto PAL = F->getAttributes(); +#if LLVM_VERSION_GE(5, 0) auto PALNew = PAL.removeAttributes(F->getContext(), Index, B); +#else + const AttributeSet PALNew = PAL.removeAttributes( + F->getContext(), Index, AttributeSet::get(F->getContext(), Index, B)); +#endif F->setAttributes(PALNew); } @@ -304,6 +360,7 @@ enum class LLVMRustSynchronizationScope { CrossThread, }; +#if LLVM_VERSION_GE(5, 0) static SyncScope::ID fromRust(LLVMRustSynchronizationScope Scope) { switch (Scope) { case LLVMRustSynchronizationScope::SingleThread: @@ -314,6 +371,18 @@ static SyncScope::ID fromRust(LLVMRustSynchronizationScope Scope) { report_fatal_error("bad SynchronizationScope."); } } +#else +static SynchronizationScope fromRust(LLVMRustSynchronizationScope Scope) { + switch (Scope) { + case LLVMRustSynchronizationScope::SingleThread: + return SingleThread; + case LLVMRustSynchronizationScope::CrossThread: + return CrossThread; + default: + report_fatal_error("bad SynchronizationScope."); + } +} +#endif extern "C" LLVMValueRef LLVMRustBuildAtomicFence(LLVMBuilderRef B, LLVMAtomicOrdering Order, @@ -353,6 +422,18 @@ extern "C" void LLVMRustAppendModuleInlineAsm(LLVMModuleRef M, const char *Asm) typedef DIBuilder *LLVMRustDIBuilderRef; +#if LLVM_VERSION_LT(5, 0) +typedef struct LLVMOpaqueMetadata *LLVMMetadataRef; + +namespace llvm { +DEFINE_ISA_CONVERSION_FUNCTIONS(Metadata, LLVMMetadataRef) + +inline Metadata **unwrap(LLVMMetadataRef *Vals) { + return reinterpret_cast(Vals); +} +} +#endif + template DIT *unwrapDIPtr(LLVMMetadataRef Ref) { return (DIT *)(Ref ? unwrap(Ref) : nullptr); } @@ -468,6 +549,11 @@ static DINode::DIFlags fromRust(LLVMRustDIFlags Flags) { if (isSet(Flags & LLVMRustDIFlags::FlagRValueReference)) { Result |= DINode::DIFlags::FlagRValueReference; } +#if LLVM_VERSION_LE(4, 0) + if (isSet(Flags & LLVMRustDIFlags::FlagExternalTypeRef)) { + Result |= DINode::DIFlags::FlagExternalTypeRef; + } +#endif if (isSet(Flags & LLVMRustDIFlags::FlagIntroducedVirtual)) { Result |= DINode::DIFlags::FlagIntroducedVirtual; } @@ -566,7 +652,9 @@ extern "C" LLVMMetadataRef LLVMRustDIBuilderCreatePointerType( uint64_t SizeInBits, uint32_t AlignInBits, const char *Name) { return wrap(Builder->createPointerType(unwrapDI(PointeeTy), SizeInBits, AlignInBits, +#if LLVM_VERSION_GE(5, 0) /* DWARFAddressSpace */ None, +#endif Name)); } @@ -737,8 +825,15 @@ LLVMRustDIBuilderCreateNameSpace(LLVMRustDIBuilderRef Builder, LLVMMetadataRef Scope, const char *Name, LLVMMetadataRef File, unsigned LineNo) { return wrap(Builder->createNameSpace( - unwrapDI(Scope), Name, + unwrapDI(Scope), Name +#if LLVM_VERSION_LT(5, 0) + , + unwrapDI(File), LineNo +#endif +#if LLVM_VERSION_GE(4, 0) + , false // ExportSymbols (only relevant for C++ anonymous namespaces) +#endif )); } @@ -767,7 +862,12 @@ extern "C" int64_t LLVMRustDIBuilderCreateOpDeref() { } extern "C" int64_t LLVMRustDIBuilderCreateOpPlusUconst() { +#if LLVM_VERSION_GE(5, 0) return dwarf::DW_OP_plus_uconst; +#else + // older LLVM used `plus` to behave like `plus_uconst`. + return dwarf::DW_OP_plus; +#endif } extern "C" void LLVMRustWriteTypeToString(LLVMTypeRef Ty, RustStringRef Str) { @@ -839,12 +939,21 @@ extern "C" void LLVMRustUnpackOptimizationDiagnostic( *FunctionOut = wrap(&Opt->getFunction()); RawRustStringOstream FilenameOS(FilenameOut); +#if LLVM_VERSION_GE(5,0) DiagnosticLocation loc = Opt->getLocation(); if (loc.isValid()) { *Line = loc.getLine(); *Column = loc.getColumn(); FilenameOS << loc.getFilename(); } +#else + const DebugLoc &loc = Opt->getDebugLoc(); + if (loc) { + *Line = loc.getLine(); + *Column = loc.getCol(); + FilenameOS << cast(loc.getScope())->getFilename(); + } +#endif RawRustStringOstream MessageOS(MessageOut); MessageOS << Opt->getMsg(); @@ -1264,6 +1373,7 @@ LLVMRustModuleCost(LLVMModuleRef M) { } // Vector reductions: +#if LLVM_VERSION_GE(5, 0) extern "C" LLVMValueRef LLVMRustBuildVectorReduceFAdd(LLVMBuilderRef B, LLVMValueRef Acc, LLVMValueRef Src) { return wrap(unwrap(B)->CreateFAddReduce(unwrap(Acc),unwrap(Src))); @@ -1309,6 +1419,62 @@ LLVMRustBuildVectorReduceFMax(LLVMBuilderRef B, LLVMValueRef Src, bool NoNaN) { return wrap(unwrap(B)->CreateFPMaxReduce(unwrap(Src), NoNaN)); } +#else + +extern "C" LLVMValueRef +LLVMRustBuildVectorReduceFAdd(LLVMBuilderRef, LLVMValueRef, LLVMValueRef) { + return nullptr; +} +extern "C" LLVMValueRef +LLVMRustBuildVectorReduceFMul(LLVMBuilderRef, LLVMValueRef, LLVMValueRef) { + return nullptr; +} +extern "C" LLVMValueRef +LLVMRustBuildVectorReduceAdd(LLVMBuilderRef, LLVMValueRef) { + return nullptr; +} +extern "C" LLVMValueRef +LLVMRustBuildVectorReduceMul(LLVMBuilderRef, LLVMValueRef) { + return nullptr; +} +extern "C" LLVMValueRef +LLVMRustBuildVectorReduceAnd(LLVMBuilderRef, LLVMValueRef) { + return nullptr; +} +extern "C" LLVMValueRef +LLVMRustBuildVectorReduceOr(LLVMBuilderRef, LLVMValueRef) { + return nullptr; +} +extern "C" LLVMValueRef +LLVMRustBuildVectorReduceXor(LLVMBuilderRef, LLVMValueRef) { + return nullptr; +} +extern "C" LLVMValueRef +LLVMRustBuildVectorReduceMin(LLVMBuilderRef, LLVMValueRef, bool) { + return nullptr; +} +extern "C" LLVMValueRef +LLVMRustBuildVectorReduceMax(LLVMBuilderRef, LLVMValueRef, bool) { + return nullptr; +} +extern "C" LLVMValueRef +LLVMRustBuildVectorReduceFMin(LLVMBuilderRef, LLVMValueRef, bool) { + return nullptr; +} +extern "C" LLVMValueRef +LLVMRustBuildVectorReduceFMax(LLVMBuilderRef, LLVMValueRef, bool) { + return nullptr; +} +#endif + +#if LLVM_VERSION_LT(4, 0) +extern "C" LLVMValueRef +LLVMBuildExactUDiv(LLVMBuilderRef B, LLVMValueRef LHS, + LLVMValueRef RHS, const char *Name) { + return wrap(unwrap(B)->CreateExactUDiv(unwrap(LHS), unwrap(RHS), Name)); +} +#endif + #if LLVM_VERSION_GE(6, 0) extern "C" LLVMValueRef LLVMRustBuildMinNum(LLVMBuilderRef B, LLVMValueRef LHS, LLVMValueRef RHS) { -- cgit 1.4.1-3-g733a5