diff --git a/src/rustllvm/ArchiveWrapper.cpp b/src/rustllvm/ArchiveWrapper.cpp index 1e873b5345c..12cd81ec700 100644 --- a/src/rustllvm/ArchiveWrapper.cpp +++ b/src/rustllvm/ArchiveWrapper.cpp @@ -22,7 +22,7 @@ struct RustArchiveMember { Archive::Child child; RustArchiveMember(): filename(NULL), name(NULL), -#if LLVM_VERSION_MINOR >= 8 +#if LLVM_VERSION_GE(3, 8) child(NULL, NULL, NULL) #else child(NULL, NULL) @@ -35,7 +35,7 @@ struct RustArchiveMember { struct RustArchiveIterator { Archive::child_iterator cur; Archive::child_iterator end; -#if LLVM_VERSION_MINOR >= 9 +#if LLVM_VERSION_GE(3, 9) Error err; #endif }; @@ -81,7 +81,7 @@ LLVMRustOpenArchive(char *path) { return nullptr; } -#if LLVM_VERSION_MINOR <= 8 +#if LLVM_VERSION_LE(3, 8) ErrorOr> archive_or = #else Expected> archive_or = @@ -89,7 +89,7 @@ LLVMRustOpenArchive(char *path) { Archive::create(buf_or.get()->getMemBufferRef()); if (!archive_or) { -#if LLVM_VERSION_MINOR <= 8 +#if LLVM_VERSION_LE(3, 8) LLVMRustSetLastError(archive_or.getError().message().c_str()); #else LLVMRustSetLastError(toString(archive_or.takeError()).c_str()); @@ -112,7 +112,7 @@ extern "C" LLVMRustArchiveIteratorRef LLVMRustArchiveIteratorNew(LLVMRustArchiveRef ra) { Archive *ar = ra->getBinary(); RustArchiveIterator *rai = new RustArchiveIterator(); -#if LLVM_VERSION_MINOR <= 8 +#if LLVM_VERSION_LE(3, 8) rai->cur = ar->child_begin(); #else rai->cur = ar->child_begin(rai->err); @@ -127,7 +127,7 @@ LLVMRustArchiveIteratorNew(LLVMRustArchiveRef ra) { extern "C" LLVMRustArchiveChildConstRef LLVMRustArchiveIteratorNext(LLVMRustArchiveIteratorRef rai) { -#if LLVM_VERSION_MINOR >= 9 +#if LLVM_VERSION_GE(3, 9) if (rai->err) { LLVMRustSetLastError(toString(std::move(rai->err)).c_str()); return NULL; @@ -135,7 +135,7 @@ LLVMRustArchiveIteratorNext(LLVMRustArchiveIteratorRef rai) { #endif if (rai->cur == rai->end) return NULL; -#if LLVM_VERSION_MINOR == 8 +#if LLVM_VERSION_EQ(3, 8) const ErrorOr* cur = rai->cur.operator->(); if (!*cur) { LLVMRustSetLastError(cur->getError().message().c_str()); @@ -207,7 +207,7 @@ LLVMRustWriteArchive(char *Dst, bool WriteSymbtab, LLVMRustArchiveKind rust_kind) { -#if LLVM_VERSION_MINOR <= 8 +#if LLVM_VERSION_LE(3, 8) std::vector Members; #else std::vector Members; @@ -218,20 +218,20 @@ LLVMRustWriteArchive(char *Dst, auto Member = NewMembers[i]; assert(Member->name); if (Member->filename) { -#if LLVM_VERSION_MINOR >= 9 +#if LLVM_VERSION_GE(3, 9) Expected MOrErr = NewArchiveMember::getFile(Member->filename, true); if (!MOrErr) { LLVMRustSetLastError(toString(MOrErr.takeError()).c_str()); return LLVMRustResult::Failure; } Members.push_back(std::move(*MOrErr)); -#elif LLVM_VERSION_MINOR == 8 +#elif LLVM_VERSION_EQ(3, 8) Members.push_back(NewArchiveIterator(Member->filename)); #else Members.push_back(NewArchiveIterator(Member->filename, Member->name)); #endif } else { -#if LLVM_VERSION_MINOR <= 8 +#if LLVM_VERSION_LE(3, 8) Members.push_back(NewArchiveIterator(Member->child, Member->name)); #else Expected MOrErr = NewArchiveMember::getOldMember(Member->child, true); @@ -243,7 +243,7 @@ LLVMRustWriteArchive(char *Dst, #endif } } -#if LLVM_VERSION_MINOR >= 8 +#if LLVM_VERSION_GE(3, 8) auto pair = writeArchive(Dst, Members, WriteSymbtab, Kind, true, false); #else auto pair = writeArchive(Dst, Members, WriteSymbtab, Kind, true); diff --git a/src/rustllvm/PassWrapper.cpp b/src/rustllvm/PassWrapper.cpp index a271987210b..60093e9bd37 100644 --- a/src/rustllvm/PassWrapper.cpp +++ b/src/rustllvm/PassWrapper.cpp @@ -46,7 +46,7 @@ LLVMInitializePasses() { initializeVectorization(Registry); initializeIPO(Registry); initializeAnalysis(Registry); -#if LLVM_VERSION_MINOR == 7 +#if LLVM_VERSION_EQ(3, 7) initializeIPA(Registry); #endif initializeTransformUtils(Registry); @@ -297,7 +297,7 @@ LLVMRustCreateTargetMachine(const char *triple, bool FunctionSections, bool DataSections) { -#if LLVM_VERSION_MINOR <= 8 +#if LLVM_VERSION_LE(3, 8) Reloc::Model RM; #else Optional RM; @@ -316,7 +316,7 @@ LLVMRustCreateTargetMachine(const char *triple, RM = Reloc::DynamicNoPIC; break; default: -#if LLVM_VERSION_MINOR <= 8 +#if LLVM_VERSION_LE(3, 8) RM = Reloc::Default; #endif break; @@ -337,7 +337,7 @@ LLVMRustCreateTargetMachine(const char *triple, } TargetOptions Options; -#if LLVM_VERSION_MINOR <= 8 +#if LLVM_VERSION_LE(3, 8) Options.PositionIndependentExecutable = PositionIndependentExecutable; #endif @@ -539,7 +539,7 @@ extern "C" void LLVMRustRunRestrictionPass(LLVMModuleRef M, char **symbols, size_t len) { llvm::legacy::PassManager passes; -#if LLVM_VERSION_MINOR <= 8 +#if LLVM_VERSION_LE(3, 8) ArrayRef ref(symbols, len); passes.add(llvm::createInternalizePass(ref)); #else @@ -593,7 +593,7 @@ LLVMRustGetModuleDataLayout(LLVMModuleRef M) { extern "C" void LLVMRustSetModulePIELevel(LLVMModuleRef M) { -#if LLVM_VERSION_MINOR >= 9 +#if LLVM_VERSION_GE(3, 9) unwrap(M)->setPIELevel(PIELevel::Level::Large); #endif } diff --git a/src/rustllvm/RustWrapper.cpp b/src/rustllvm/RustWrapper.cpp index 124eb1eba4f..672ab117f15 100644 --- a/src/rustllvm/RustWrapper.cpp +++ b/src/rustllvm/RustWrapper.cpp @@ -394,7 +394,7 @@ extern "C" LLVMRustMetadataRef LLVMRustDIBuilderCreateSubroutineType( LLVMRustMetadataRef File, LLVMRustMetadataRef ParameterTypes) { return wrap(Builder->createSubroutineType( -#if LLVM_VERSION_MINOR == 7 +#if LLVM_VERSION_EQ(3, 7) unwrapDI(File), #endif DITypeRefArray(unwrap(ParameterTypes)))); @@ -416,7 +416,7 @@ extern "C" LLVMRustMetadataRef LLVMRustDIBuilderCreateFunction( LLVMValueRef Fn, LLVMRustMetadataRef TParam, LLVMRustMetadataRef Decl) { -#if LLVM_VERSION_MINOR >= 8 +#if LLVM_VERSION_GE(3, 8) DITemplateParameterArray TParams = DITemplateParameterArray(unwrap(TParam)); DISubprogram *Sub = Builder->createFunction( @@ -565,7 +565,7 @@ extern "C" LLVMRustMetadataRef LLVMRustDIBuilderCreateVariable( int64_t* AddrOps, unsigned AddrOpsCount, unsigned ArgNo) { -#if LLVM_VERSION_MINOR >= 8 +#if LLVM_VERSION_GE(3, 8) if (Tag == 0x100) { // DW_TAG_auto_variable return wrap(Builder->createAutoVariable( unwrapDI(Scope), Name, @@ -814,7 +814,7 @@ LLVMRustLinkInExternalBitcode(LLVMModuleRef dst, char *bc, size_t len) { raw_string_ostream Stream(Err); DiagnosticPrinterRawOStream DP(Stream); -#if LLVM_VERSION_MINOR >= 8 +#if LLVM_VERSION_GE(3, 8) if (Linker::linkModules(*Dst, std::move(Src.get()))) { #else if (Linker::LinkModules(Dst, Src->get(), [&](const DiagnosticInfo &DI) { DI.print(DP); })) { @@ -937,14 +937,14 @@ to_rust(DiagnosticKind kind) return LLVMRustDiagnosticKind::OptimizationRemarkMissed; case DK_OptimizationRemarkAnalysis: return LLVMRustDiagnosticKind::OptimizationRemarkAnalysis; -#if LLVM_VERSION_MINOR >= 8 +#if LLVM_VERSION_GE(3, 8) case DK_OptimizationRemarkAnalysisFPCommute: return LLVMRustDiagnosticKind::OptimizationRemarkAnalysisFPCommute; case DK_OptimizationRemarkAnalysisAliasing: return LLVMRustDiagnosticKind::OptimizationRemarkAnalysisAliasing; #endif default: -#if LLVM_VERSION_MINOR >= 9 +#if LLVM_VERSION_GE(3, 9) return (kind >= DK_FirstRemark && kind <= DK_LastRemark) ? LLVMRustDiagnosticKind::OptimizationRemarkOther : LLVMRustDiagnosticKind::Other; @@ -994,7 +994,7 @@ extern "C" LLVMTypeKind LLVMRustGetTypeKind(LLVMTypeRef Ty) { return LLVMVectorTypeKind; case Type::X86_MMXTyID: return LLVMX86_MMXTypeKind; -#if LLVM_VERSION_MINOR >= 8 +#if LLVM_VERSION_GE(3, 8) case Type::TokenTyID: return LLVMTokenTypeKind; #endif @@ -1043,7 +1043,7 @@ LLVMRustBuildCleanupPad(LLVMBuilderRef Builder, unsigned ArgCnt, LLVMValueRef *LLArgs, const char *Name) { -#if LLVM_VERSION_MINOR >= 8 +#if LLVM_VERSION_GE(3, 8) Value **Args = unwrap(LLArgs); if (ParentPad == NULL) { Type *Ty = Type::getTokenTy(unwrap(Builder)->getContext()); @@ -1061,7 +1061,7 @@ extern "C" LLVMValueRef LLVMRustBuildCleanupRet(LLVMBuilderRef Builder, LLVMValueRef CleanupPad, LLVMBasicBlockRef UnwindBB) { -#if LLVM_VERSION_MINOR >= 8 +#if LLVM_VERSION_GE(3, 8) CleanupPadInst *Inst = cast(unwrap(CleanupPad)); return wrap(unwrap(Builder)->CreateCleanupRet(Inst, unwrap(UnwindBB))); #else @@ -1075,7 +1075,7 @@ LLVMRustBuildCatchPad(LLVMBuilderRef Builder, unsigned ArgCnt, LLVMValueRef *LLArgs, const char *Name) { -#if LLVM_VERSION_MINOR >= 8 +#if LLVM_VERSION_GE(3, 8) Value **Args = unwrap(LLArgs); return wrap(unwrap(Builder)->CreateCatchPad(unwrap(ParentPad), ArrayRef(Args, ArgCnt), @@ -1089,7 +1089,7 @@ extern "C" LLVMValueRef LLVMRustBuildCatchRet(LLVMBuilderRef Builder, LLVMValueRef Pad, LLVMBasicBlockRef BB) { -#if LLVM_VERSION_MINOR >= 8 +#if LLVM_VERSION_GE(3, 8) return wrap(unwrap(Builder)->CreateCatchRet(cast(unwrap(Pad)), unwrap(BB))); #else @@ -1103,7 +1103,7 @@ LLVMRustBuildCatchSwitch(LLVMBuilderRef Builder, LLVMBasicBlockRef BB, unsigned NumHandlers, const char *Name) { -#if LLVM_VERSION_MINOR >= 8 +#if LLVM_VERSION_GE(3, 8) if (ParentPad == NULL) { Type *Ty = Type::getTokenTy(unwrap(Builder)->getContext()); ParentPad = wrap(Constant::getNullValue(Ty)); @@ -1120,7 +1120,7 @@ LLVMRustBuildCatchSwitch(LLVMBuilderRef Builder, extern "C" void LLVMRustAddHandler(LLVMValueRef CatchSwitchRef, LLVMBasicBlockRef Handler) { -#if LLVM_VERSION_MINOR >= 8 +#if LLVM_VERSION_GE(3, 8) Value *CatchSwitch = unwrap(CatchSwitchRef); cast(CatchSwitch)->addHandler(unwrap(Handler)); #endif @@ -1129,14 +1129,14 @@ LLVMRustAddHandler(LLVMValueRef CatchSwitchRef, extern "C" void LLVMRustSetPersonalityFn(LLVMBuilderRef B, LLVMValueRef Personality) { -#if LLVM_VERSION_MINOR >= 8 +#if LLVM_VERSION_GE(3, 8) unwrap(B)->GetInsertBlock() ->getParent() ->setPersonalityFn(cast(unwrap(Personality))); #endif } -#if LLVM_VERSION_MINOR >= 8 +#if LLVM_VERSION_GE(3, 8) extern "C" OperandBundleDef* LLVMRustBuildOperandBundleDef(const char *Name, LLVMValueRef *Inputs, diff --git a/src/rustllvm/rustllvm.h b/src/rustllvm/rustllvm.h index 5aae11fb456..ffe94d1e22f 100644 --- a/src/rustllvm/rustllvm.h +++ b/src/rustllvm/rustllvm.h @@ -45,7 +45,16 @@ #include "llvm-c/ExecutionEngine.h" #include "llvm-c/Object.h" -#if LLVM_VERSION_MINOR >= 7 +#define LLVM_VERSION_GE(major, minor) \ + (LLVM_VERSION_MAJOR > (major) || LLVM_VERSION_MAJOR == (major) && LLVM_VERSION_MINOR >= (minor)) + +#define LLVM_VERSION_EQ(major, minor) \ + (LLVM_VERSION_MAJOR == (major) && LLVM_VERSION_MINOR == (minor)) + +#define LLVM_VERSION_LE(major, minor) \ + (LLVM_VERSION_MAJOR < (major) || LLVM_VERSION_MAJOR == (major) && LLVM_VERSION_MINOR <= (minor)) + +#if LLVM_VERSION_GE(3, 7) #include "llvm/IR/LegacyPassManager.h" #else #include "llvm/PassManager.h"