Auto merge of #55698 - nikic:remove-llvm-4-support, r=alexcrichton

Remove support for building against LLVM 4

With emscripten removed in #55626, we no longer need to support building against LLVM 4.
This commit is contained in:
bors 2018-11-11 22:38:54 +00:00
commit 775eab5883
6 changed files with 29 additions and 259 deletions

View file

@ -595,9 +595,7 @@ fn run_pass_manager(cgcx: &CodegenContext,
}; };
with_llvm_pmb(llmod, config, opt_level, false, &mut |b| { with_llvm_pmb(llmod, config, opt_level, false, &mut |b| {
if thin { if thin {
if !llvm::LLVMRustPassManagerBuilderPopulateThinLTOPassManager(b, pm) { llvm::LLVMRustPassManagerBuilderPopulateThinLTOPassManager(b, pm);
panic!("this version of LLVM does not support ThinLTO");
}
} else { } else {
llvm::LLVMPassManagerBuilderPopulateLTOPassManager(b, pm, llvm::LLVMPassManagerBuilderPopulateLTOPassManager(b, pm,
/* Internalize = */ False, /* Internalize = */ False,

View file

@ -874,8 +874,7 @@ impl Builder<'a, 'll, 'tcx> {
// FIXME: add a non-fast math version once // FIXME: add a non-fast math version once
// https://bugs.llvm.org/show_bug.cgi?id=36732 // https://bugs.llvm.org/show_bug.cgi?id=36732
// is fixed. // is fixed.
let instr = llvm::LLVMRustBuildVectorReduceFAdd(self.llbuilder, acc, src) let instr = llvm::LLVMRustBuildVectorReduceFAdd(self.llbuilder, acc, src);
.expect("LLVMRustBuildVectorReduceFAdd is not available in LLVM version < 5.0");
llvm::LLVMRustSetHasUnsafeAlgebra(instr); llvm::LLVMRustSetHasUnsafeAlgebra(instr);
instr instr
} }
@ -886,66 +885,43 @@ impl Builder<'a, 'll, 'tcx> {
// FIXME: add a non-fast math version once // FIXME: add a non-fast math version once
// https://bugs.llvm.org/show_bug.cgi?id=36732 // https://bugs.llvm.org/show_bug.cgi?id=36732
// is fixed. // is fixed.
let instr = llvm::LLVMRustBuildVectorReduceFMul(self.llbuilder, acc, src) let instr = llvm::LLVMRustBuildVectorReduceFMul(self.llbuilder, acc, src);
.expect("LLVMRustBuildVectorReduceFMul is not available in LLVM version < 5.0");
llvm::LLVMRustSetHasUnsafeAlgebra(instr); llvm::LLVMRustSetHasUnsafeAlgebra(instr);
instr instr
} }
} }
pub fn vector_reduce_add(&self, src: &'ll Value) -> &'ll Value { pub fn vector_reduce_add(&self, src: &'ll Value) -> &'ll Value {
self.count_insn("vector.reduce.add"); self.count_insn("vector.reduce.add");
unsafe { unsafe { llvm::LLVMRustBuildVectorReduceAdd(self.llbuilder, src) }
let instr = llvm::LLVMRustBuildVectorReduceAdd(self.llbuilder, src);
instr.expect("LLVMRustBuildVectorReduceAdd is not available in LLVM version < 5.0")
}
} }
pub fn vector_reduce_mul(&self, src: &'ll Value) -> &'ll Value { pub fn vector_reduce_mul(&self, src: &'ll Value) -> &'ll Value {
self.count_insn("vector.reduce.mul"); self.count_insn("vector.reduce.mul");
unsafe { unsafe { llvm::LLVMRustBuildVectorReduceMul(self.llbuilder, src) }
let instr = llvm::LLVMRustBuildVectorReduceMul(self.llbuilder, src);
instr.expect("LLVMRustBuildVectorReduceMul is not available in LLVM version < 5.0")
}
} }
pub fn vector_reduce_and(&self, src: &'ll Value) -> &'ll Value { pub fn vector_reduce_and(&self, src: &'ll Value) -> &'ll Value {
self.count_insn("vector.reduce.and"); self.count_insn("vector.reduce.and");
unsafe { unsafe { llvm::LLVMRustBuildVectorReduceAnd(self.llbuilder, src) }
let instr = llvm::LLVMRustBuildVectorReduceAnd(self.llbuilder, src);
instr.expect("LLVMRustBuildVectorReduceAnd is not available in LLVM version < 5.0")
}
} }
pub fn vector_reduce_or(&self, src: &'ll Value) -> &'ll Value { pub fn vector_reduce_or(&self, src: &'ll Value) -> &'ll Value {
self.count_insn("vector.reduce.or"); self.count_insn("vector.reduce.or");
unsafe { unsafe { llvm::LLVMRustBuildVectorReduceOr(self.llbuilder, src) }
let instr = llvm::LLVMRustBuildVectorReduceOr(self.llbuilder, src);
instr.expect("LLVMRustBuildVectorReduceOr is not available in LLVM version < 5.0")
}
} }
pub fn vector_reduce_xor(&self, src: &'ll Value) -> &'ll Value { pub fn vector_reduce_xor(&self, src: &'ll Value) -> &'ll Value {
self.count_insn("vector.reduce.xor"); self.count_insn("vector.reduce.xor");
unsafe { unsafe { llvm::LLVMRustBuildVectorReduceXor(self.llbuilder, src) }
let instr = llvm::LLVMRustBuildVectorReduceXor(self.llbuilder, src);
instr.expect("LLVMRustBuildVectorReduceXor is not available in LLVM version < 5.0")
}
} }
pub fn vector_reduce_fmin(&self, src: &'ll Value) -> &'ll Value { pub fn vector_reduce_fmin(&self, src: &'ll Value) -> &'ll Value {
self.count_insn("vector.reduce.fmin"); self.count_insn("vector.reduce.fmin");
unsafe { unsafe { llvm::LLVMRustBuildVectorReduceFMin(self.llbuilder, src, /*NoNaNs:*/ false) }
let instr = llvm::LLVMRustBuildVectorReduceFMin(self.llbuilder, src, /*NoNaNs:*/ false);
instr.expect("LLVMRustBuildVectorReduceFMin is not available in LLVM version < 5.0")
}
} }
pub fn vector_reduce_fmax(&self, src: &'ll Value) -> &'ll Value { pub fn vector_reduce_fmax(&self, src: &'ll Value) -> &'ll Value {
self.count_insn("vector.reduce.fmax"); self.count_insn("vector.reduce.fmax");
unsafe { unsafe { llvm::LLVMRustBuildVectorReduceFMax(self.llbuilder, src, /*NoNaNs:*/ false) }
let instr = llvm::LLVMRustBuildVectorReduceFMax(self.llbuilder, src, /*NoNaNs:*/ false);
instr.expect("LLVMRustBuildVectorReduceFMax is not available in LLVM version < 5.0")
}
} }
pub fn vector_reduce_fmin_fast(&self, src: &'ll Value) -> &'ll Value { pub fn vector_reduce_fmin_fast(&self, src: &'ll Value) -> &'ll Value {
self.count_insn("vector.reduce.fmin_fast"); self.count_insn("vector.reduce.fmin_fast");
unsafe { unsafe {
let instr = llvm::LLVMRustBuildVectorReduceFMin(self.llbuilder, src, /*NoNaNs:*/ true) let instr = llvm::LLVMRustBuildVectorReduceFMin(self.llbuilder, src, /*NoNaNs:*/ true);
.expect("LLVMRustBuildVectorReduceFMin is not available in LLVM version < 5.0");
llvm::LLVMRustSetHasUnsafeAlgebra(instr); llvm::LLVMRustSetHasUnsafeAlgebra(instr);
instr instr
} }
@ -953,25 +929,18 @@ impl Builder<'a, 'll, 'tcx> {
pub fn vector_reduce_fmax_fast(&self, src: &'ll Value) -> &'ll Value { pub fn vector_reduce_fmax_fast(&self, src: &'ll Value) -> &'ll Value {
self.count_insn("vector.reduce.fmax_fast"); self.count_insn("vector.reduce.fmax_fast");
unsafe { unsafe {
let instr = llvm::LLVMRustBuildVectorReduceFMax(self.llbuilder, src, /*NoNaNs:*/ true) let instr = llvm::LLVMRustBuildVectorReduceFMax(self.llbuilder, src, /*NoNaNs:*/ true);
.expect("LLVMRustBuildVectorReduceFMax is not available in LLVM version < 5.0");
llvm::LLVMRustSetHasUnsafeAlgebra(instr); llvm::LLVMRustSetHasUnsafeAlgebra(instr);
instr instr
} }
} }
pub fn vector_reduce_min(&self, src: &'ll Value, is_signed: bool) -> &'ll Value { pub fn vector_reduce_min(&self, src: &'ll Value, is_signed: bool) -> &'ll Value {
self.count_insn("vector.reduce.min"); self.count_insn("vector.reduce.min");
unsafe { unsafe { llvm::LLVMRustBuildVectorReduceMin(self.llbuilder, src, is_signed) }
let instr = llvm::LLVMRustBuildVectorReduceMin(self.llbuilder, src, is_signed);
instr.expect("LLVMRustBuildVectorReduceMin is not available in LLVM version < 5.0")
}
} }
pub fn vector_reduce_max(&self, src: &'ll Value, is_signed: bool) -> &'ll Value { pub fn vector_reduce_max(&self, src: &'ll Value, is_signed: bool) -> &'ll Value {
self.count_insn("vector.reduce.max"); self.count_insn("vector.reduce.max");
unsafe { unsafe { llvm::LLVMRustBuildVectorReduceMax(self.llbuilder, src, is_signed) }
let instr = llvm::LLVMRustBuildVectorReduceMax(self.llbuilder, src, is_signed);
instr.expect("LLVMRustBuildVectorReduceMax is not available in LLVM version < 5.0")
}
} }
pub fn extract_value(&self, agg_val: &'ll Value, idx: u64) -> &'ll Value { pub fn extract_value(&self, agg_val: &'ll Value, idx: u64) -> &'ll Value {

View file

@ -1057,42 +1057,42 @@ extern "C" {
pub fn LLVMRustBuildVectorReduceFAdd(B: &Builder<'a>, pub fn LLVMRustBuildVectorReduceFAdd(B: &Builder<'a>,
Acc: &'a Value, Acc: &'a Value,
Src: &'a Value) Src: &'a Value)
-> Option<&'a Value>; -> &'a Value;
pub fn LLVMRustBuildVectorReduceFMul(B: &Builder<'a>, pub fn LLVMRustBuildVectorReduceFMul(B: &Builder<'a>,
Acc: &'a Value, Acc: &'a Value,
Src: &'a Value) Src: &'a Value)
-> Option<&'a Value>; -> &'a Value;
pub fn LLVMRustBuildVectorReduceAdd(B: &Builder<'a>, pub fn LLVMRustBuildVectorReduceAdd(B: &Builder<'a>,
Src: &'a Value) Src: &'a Value)
-> Option<&'a Value>; -> &'a Value;
pub fn LLVMRustBuildVectorReduceMul(B: &Builder<'a>, pub fn LLVMRustBuildVectorReduceMul(B: &Builder<'a>,
Src: &'a Value) Src: &'a Value)
-> Option<&'a Value>; -> &'a Value;
pub fn LLVMRustBuildVectorReduceAnd(B: &Builder<'a>, pub fn LLVMRustBuildVectorReduceAnd(B: &Builder<'a>,
Src: &'a Value) Src: &'a Value)
-> Option<&'a Value>; -> &'a Value;
pub fn LLVMRustBuildVectorReduceOr(B: &Builder<'a>, pub fn LLVMRustBuildVectorReduceOr(B: &Builder<'a>,
Src: &'a Value) Src: &'a Value)
-> Option<&'a Value>; -> &'a Value;
pub fn LLVMRustBuildVectorReduceXor(B: &Builder<'a>, pub fn LLVMRustBuildVectorReduceXor(B: &Builder<'a>,
Src: &'a Value) Src: &'a Value)
-> Option<&'a Value>; -> &'a Value;
pub fn LLVMRustBuildVectorReduceMin(B: &Builder<'a>, pub fn LLVMRustBuildVectorReduceMin(B: &Builder<'a>,
Src: &'a Value, Src: &'a Value,
IsSigned: bool) IsSigned: bool)
-> Option<&'a Value>; -> &'a Value;
pub fn LLVMRustBuildVectorReduceMax(B: &Builder<'a>, pub fn LLVMRustBuildVectorReduceMax(B: &Builder<'a>,
Src: &'a Value, Src: &'a Value,
IsSigned: bool) IsSigned: bool)
-> Option<&'a Value>; -> &'a Value;
pub fn LLVMRustBuildVectorReduceFMin(B: &Builder<'a>, pub fn LLVMRustBuildVectorReduceFMin(B: &Builder<'a>,
Src: &'a Value, Src: &'a Value,
IsNaN: bool) IsNaN: bool)
-> Option<&'a Value>; -> &'a Value;
pub fn LLVMRustBuildVectorReduceFMax(B: &Builder<'a>, pub fn LLVMRustBuildVectorReduceFMax(B: &Builder<'a>,
Src: &'a Value, Src: &'a Value,
IsNaN: bool) IsNaN: bool)
-> Option<&'a Value>; -> &'a Value;
pub fn LLVMRustBuildMinNum( pub fn LLVMRustBuildMinNum(
B: &Builder<'a>, B: &Builder<'a>,
@ -1173,7 +1173,7 @@ extern "C" {
RunInliner: Bool); RunInliner: Bool);
pub fn LLVMRustPassManagerBuilderPopulateThinLTOPassManager( pub fn LLVMRustPassManagerBuilderPopulateThinLTOPassManager(
PMB: &PassManagerBuilder, PMB: &PassManagerBuilder,
PM: &PassManager) -> bool; PM: &PassManager);
// Stuff that's in rustllvm/ because it's not upstream yet. // Stuff that's in rustllvm/ because it's not upstream yet.

View file

@ -204,9 +204,7 @@ LLVMRustWriteArchive(char *Dst, size_t NumMembers,
LLVMRustSetLastError(toString(MOrErr.takeError()).c_str()); LLVMRustSetLastError(toString(MOrErr.takeError()).c_str());
return LLVMRustResult::Failure; return LLVMRustResult::Failure;
} }
#if LLVM_VERSION_GE(5, 0)
MOrErr->MemberName = sys::path::filename(MOrErr->MemberName); MOrErr->MemberName = sys::path::filename(MOrErr->MemberName);
#endif
Members.push_back(std::move(*MOrErr)); Members.push_back(std::move(*MOrErr));
} else { } else {
Expected<NewArchiveMember> MOrErr = Expected<NewArchiveMember> MOrErr =

View file

@ -36,9 +36,6 @@
#include "llvm/Transforms/IPO/FunctionImport.h" #include "llvm/Transforms/IPO/FunctionImport.h"
#include "llvm/Transforms/Utils/FunctionImportUtils.h" #include "llvm/Transforms/Utils/FunctionImportUtils.h"
#include "llvm/LTO/LTO.h" #include "llvm/LTO/LTO.h"
#if LLVM_VERSION_LE(4, 0)
#include "llvm/Object/ModuleSummaryIndexObjectFile.h"
#endif
#include "llvm-c/Transforms/PassManagerBuilder.h" #include "llvm-c/Transforms/PassManagerBuilder.h"
@ -111,12 +108,11 @@ extern "C" void LLVMRustAddPass(LLVMPassManagerRef PMR, LLVMPassRef RustPass) {
} }
extern "C" extern "C"
bool LLVMRustPassManagerBuilderPopulateThinLTOPassManager( void LLVMRustPassManagerBuilderPopulateThinLTOPassManager(
LLVMPassManagerBuilderRef PMBR, LLVMPassManagerBuilderRef PMBR,
LLVMPassManagerRef PMR LLVMPassManagerRef PMR
) { ) {
unwrap(PMBR)->populateThinLTOPassManager(*unwrap(PMR)); unwrap(PMBR)->populateThinLTOPassManager(*unwrap(PMR));
return true;
} }
#ifdef LLVM_COMPONENT_X86 #ifdef LLVM_COMPONENT_X86
@ -869,21 +865,10 @@ LLVMRustCreateThinLTOData(LLVMRustThinLTOModule *modules,
Ret->ModuleMap[module->identifier] = mem_buffer; Ret->ModuleMap[module->identifier] = mem_buffer;
#if LLVM_VERSION_GE(5, 0)
if (Error Err = readModuleSummaryIndex(mem_buffer, Ret->Index, i)) { if (Error Err = readModuleSummaryIndex(mem_buffer, Ret->Index, i)) {
LLVMRustSetLastError(toString(std::move(Err)).c_str()); LLVMRustSetLastError(toString(std::move(Err)).c_str());
return nullptr; return nullptr;
} }
#else
Expected<std::unique_ptr<object::ModuleSummaryIndexObjectFile>> ObjOrErr =
object::ModuleSummaryIndexObjectFile::create(mem_buffer);
if (!ObjOrErr) {
LLVMRustSetLastError(toString(ObjOrErr.takeError()).c_str());
return nullptr;
}
auto Index = (*ObjOrErr)->takeIndex();
Ret->Index.mergeFrom(std::move(Index), i);
#endif
} }
// Collect for each module the list of function it defines (GUID -> Summary) // Collect for each module the list of function it defines (GUID -> Summary)
@ -900,7 +885,6 @@ LLVMRustCreateThinLTOData(LLVMRustThinLTOModule *modules,
// combined index // combined index
// //
// This is copied from `lib/LTO/ThinLTOCodeGenerator.cpp` // This is copied from `lib/LTO/ThinLTOCodeGenerator.cpp`
#if LLVM_VERSION_GE(5, 0)
#if LLVM_VERSION_GE(7, 0) #if LLVM_VERSION_GE(7, 0)
auto deadIsPrevailing = [&](GlobalValue::GUID G) { auto deadIsPrevailing = [&](GlobalValue::GUID G) {
return PrevailingType::Unknown; return PrevailingType::Unknown;
@ -915,16 +899,6 @@ LLVMRustCreateThinLTOData(LLVMRustThinLTOModule *modules,
Ret->ImportLists, Ret->ImportLists,
Ret->ExportLists Ret->ExportLists
); );
#else
auto DeadSymbols = computeDeadSymbols(Ret->Index, Ret->GUIDPreservedSymbols);
ComputeCrossModuleImport(
Ret->Index,
Ret->ModuleToDefinedGVSummaries,
Ret->ImportLists,
Ret->ExportLists,
&DeadSymbols
);
#endif
// Resolve LinkOnce/Weak symbols, this has to be computed early be cause it // Resolve LinkOnce/Weak symbols, this has to be computed early be cause it
// impacts the caching. // impacts the caching.
@ -934,13 +908,8 @@ LLVMRustCreateThinLTOData(LLVMRustThinLTOModule *modules,
StringMap<std::map<GlobalValue::GUID, GlobalValue::LinkageTypes>> ResolvedODR; StringMap<std::map<GlobalValue::GUID, GlobalValue::LinkageTypes>> ResolvedODR;
DenseMap<GlobalValue::GUID, const GlobalValueSummary *> PrevailingCopy; DenseMap<GlobalValue::GUID, const GlobalValueSummary *> PrevailingCopy;
for (auto &I : Ret->Index) { for (auto &I : Ret->Index) {
#if LLVM_VERSION_GE(5, 0)
if (I.second.SummaryList.size() > 1) if (I.second.SummaryList.size() > 1)
PrevailingCopy[I.first] = getFirstDefinitionForLinker(I.second.SummaryList); PrevailingCopy[I.first] = getFirstDefinitionForLinker(I.second.SummaryList);
#else
if (I.second.size() > 1)
PrevailingCopy[I.first] = getFirstDefinitionForLinker(I.second);
#endif
} }
auto isPrevailing = [&](GlobalValue::GUID GUID, const GlobalValueSummary *S) { auto isPrevailing = [&](GlobalValue::GUID GUID, const GlobalValueSummary *S) {
const auto &Prevailing = PrevailingCopy.find(GUID); const auto &Prevailing = PrevailingCopy.find(GUID);
@ -962,19 +931,11 @@ LLVMRustCreateThinLTOData(LLVMRustThinLTOModule *modules,
// linkage will stay as external, and internal will stay as internal. // linkage will stay as external, and internal will stay as internal.
std::set<GlobalValue::GUID> ExportedGUIDs; std::set<GlobalValue::GUID> ExportedGUIDs;
for (auto &List : Ret->Index) { for (auto &List : Ret->Index) {
#if LLVM_VERSION_GE(5, 0)
for (auto &GVS: List.second.SummaryList) { for (auto &GVS: List.second.SummaryList) {
#else
for (auto &GVS: List.second) {
#endif
if (GlobalValue::isLocalLinkage(GVS->linkage())) if (GlobalValue::isLocalLinkage(GVS->linkage()))
continue; continue;
auto GUID = GVS->getOriginalName(); auto GUID = GVS->getOriginalName();
#if LLVM_VERSION_GE(5, 0)
if (GVS->flags().Live) if (GVS->flags().Live)
#else
if (!DeadSymbols.count(GUID))
#endif
ExportedGUIDs.insert(GUID); ExportedGUIDs.insert(GUID);
} }
} }

View file

@ -9,6 +9,7 @@
// except according to those terms. // except according to those terms.
#include "rustllvm.h" #include "rustllvm.h"
#include "llvm/IR/CallSite.h"
#include "llvm/IR/DebugInfoMetadata.h" #include "llvm/IR/DebugInfoMetadata.h"
#include "llvm/IR/DiagnosticInfo.h" #include "llvm/IR/DiagnosticInfo.h"
#include "llvm/IR/DiagnosticPrinter.h" #include "llvm/IR/DiagnosticPrinter.h"
@ -18,14 +19,7 @@
#include "llvm/Object/ObjectFile.h" #include "llvm/Object/ObjectFile.h"
#include "llvm/Bitcode/BitcodeWriterPass.h" #include "llvm/Bitcode/BitcodeWriterPass.h"
#include "llvm/Support/Signals.h" #include "llvm/Support/Signals.h"
#include "llvm/IR/CallSite.h"
#if LLVM_VERSION_GE(5, 0)
#include "llvm/ADT/Optional.h" #include "llvm/ADT/Optional.h"
#else
#include <cstdlib>
#endif
#include <iostream> #include <iostream>
@ -212,14 +206,7 @@ extern "C" void LLVMRustAddCallSiteAttribute(LLVMValueRef Instr, unsigned Index,
LLVMRustAttribute RustAttr) { LLVMRustAttribute RustAttr) {
CallSite Call = CallSite(unwrap<Instruction>(Instr)); CallSite Call = CallSite(unwrap<Instruction>(Instr));
Attribute Attr = Attribute::get(Call->getContext(), fromRust(RustAttr)); Attribute Attr = Attribute::get(Call->getContext(), fromRust(RustAttr));
#if LLVM_VERSION_GE(5, 0)
Call.addAttribute(Index, Attr); 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, extern "C" void LLVMRustAddAlignmentCallSiteAttr(LLVMValueRef Instr,
@ -228,14 +215,8 @@ extern "C" void LLVMRustAddAlignmentCallSiteAttr(LLVMValueRef Instr,
CallSite Call = CallSite(unwrap<Instruction>(Instr)); CallSite Call = CallSite(unwrap<Instruction>(Instr));
AttrBuilder B; AttrBuilder B;
B.addAlignmentAttr(Bytes); B.addAlignmentAttr(Bytes);
#if LLVM_VERSION_GE(5, 0)
Call.setAttributes(Call.getAttributes().addAttributes( Call.setAttributes(Call.getAttributes().addAttributes(
Call->getContext(), Index, B)); 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, extern "C" void LLVMRustAddDereferenceableCallSiteAttr(LLVMValueRef Instr,
@ -244,14 +225,8 @@ extern "C" void LLVMRustAddDereferenceableCallSiteAttr(LLVMValueRef Instr,
CallSite Call = CallSite(unwrap<Instruction>(Instr)); CallSite Call = CallSite(unwrap<Instruction>(Instr));
AttrBuilder B; AttrBuilder B;
B.addDereferenceableAttr(Bytes); B.addDereferenceableAttr(Bytes);
#if LLVM_VERSION_GE(5, 0)
Call.setAttributes(Call.getAttributes().addAttributes( Call.setAttributes(Call.getAttributes().addAttributes(
Call->getContext(), Index, B)); 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, extern "C" void LLVMRustAddDereferenceableOrNullCallSiteAttr(LLVMValueRef Instr,
@ -260,14 +235,8 @@ extern "C" void LLVMRustAddDereferenceableOrNullCallSiteAttr(LLVMValueRef Instr,
CallSite Call = CallSite(unwrap<Instruction>(Instr)); CallSite Call = CallSite(unwrap<Instruction>(Instr));
AttrBuilder B; AttrBuilder B;
B.addDereferenceableOrNullAttr(Bytes); B.addDereferenceableOrNullAttr(Bytes);
#if LLVM_VERSION_GE(5, 0)
Call.setAttributes(Call.getAttributes().addAttributes( Call.setAttributes(Call.getAttributes().addAttributes(
Call->getContext(), Index, B)); 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, extern "C" void LLVMRustAddFunctionAttribute(LLVMValueRef Fn, unsigned Index,
@ -275,11 +244,7 @@ extern "C" void LLVMRustAddFunctionAttribute(LLVMValueRef Fn, unsigned Index,
Function *A = unwrap<Function>(Fn); Function *A = unwrap<Function>(Fn);
Attribute Attr = Attribute::get(A->getContext(), fromRust(RustAttr)); Attribute Attr = Attribute::get(A->getContext(), fromRust(RustAttr));
AttrBuilder B(Attr); AttrBuilder B(Attr);
#if LLVM_VERSION_GE(5, 0)
A->addAttributes(Index, B); A->addAttributes(Index, B);
#else
A->addAttributes(Index, AttributeSet::get(A->getContext(), Index, B));
#endif
} }
extern "C" void LLVMRustAddAlignmentAttr(LLVMValueRef Fn, extern "C" void LLVMRustAddAlignmentAttr(LLVMValueRef Fn,
@ -288,11 +253,7 @@ extern "C" void LLVMRustAddAlignmentAttr(LLVMValueRef Fn,
Function *A = unwrap<Function>(Fn); Function *A = unwrap<Function>(Fn);
AttrBuilder B; AttrBuilder B;
B.addAlignmentAttr(Bytes); B.addAlignmentAttr(Bytes);
#if LLVM_VERSION_GE(5, 0)
A->addAttributes(Index, B); A->addAttributes(Index, B);
#else
A->addAttributes(Index, AttributeSet::get(A->getContext(), Index, B));
#endif
} }
extern "C" void LLVMRustAddDereferenceableAttr(LLVMValueRef Fn, unsigned Index, extern "C" void LLVMRustAddDereferenceableAttr(LLVMValueRef Fn, unsigned Index,
@ -300,11 +261,7 @@ extern "C" void LLVMRustAddDereferenceableAttr(LLVMValueRef Fn, unsigned Index,
Function *A = unwrap<Function>(Fn); Function *A = unwrap<Function>(Fn);
AttrBuilder B; AttrBuilder B;
B.addDereferenceableAttr(Bytes); B.addDereferenceableAttr(Bytes);
#if LLVM_VERSION_GE(5, 0)
A->addAttributes(Index, B); A->addAttributes(Index, B);
#else
A->addAttributes(Index, AttributeSet::get(A->getContext(), Index, B));
#endif
} }
extern "C" void LLVMRustAddDereferenceableOrNullAttr(LLVMValueRef Fn, extern "C" void LLVMRustAddDereferenceableOrNullAttr(LLVMValueRef Fn,
@ -313,11 +270,7 @@ extern "C" void LLVMRustAddDereferenceableOrNullAttr(LLVMValueRef Fn,
Function *A = unwrap<Function>(Fn); Function *A = unwrap<Function>(Fn);
AttrBuilder B; AttrBuilder B;
B.addDereferenceableOrNullAttr(Bytes); B.addDereferenceableOrNullAttr(Bytes);
#if LLVM_VERSION_GE(5, 0)
A->addAttributes(Index, B); A->addAttributes(Index, B);
#else
A->addAttributes(Index, AttributeSet::get(A->getContext(), Index, B));
#endif
} }
extern "C" void LLVMRustAddFunctionAttrStringValue(LLVMValueRef Fn, extern "C" void LLVMRustAddFunctionAttrStringValue(LLVMValueRef Fn,
@ -327,11 +280,7 @@ extern "C" void LLVMRustAddFunctionAttrStringValue(LLVMValueRef Fn,
Function *F = unwrap<Function>(Fn); Function *F = unwrap<Function>(Fn);
AttrBuilder B; AttrBuilder B;
B.addAttribute(Name, Value); B.addAttribute(Name, Value);
#if LLVM_VERSION_GE(5, 0)
F->addAttributes(Index, B); F->addAttributes(Index, B);
#else
F->addAttributes(Index, AttributeSet::get(F->getContext(), Index, B));
#endif
} }
extern "C" void LLVMRustRemoveFunctionAttributes(LLVMValueRef Fn, extern "C" void LLVMRustRemoveFunctionAttributes(LLVMValueRef Fn,
@ -341,12 +290,7 @@ extern "C" void LLVMRustRemoveFunctionAttributes(LLVMValueRef Fn,
Attribute Attr = Attribute::get(F->getContext(), fromRust(RustAttr)); Attribute Attr = Attribute::get(F->getContext(), fromRust(RustAttr));
AttrBuilder B(Attr); AttrBuilder B(Attr);
auto PAL = F->getAttributes(); auto PAL = F->getAttributes();
#if LLVM_VERSION_GE(5, 0)
auto PALNew = PAL.removeAttributes(F->getContext(), Index, B); 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); F->setAttributes(PALNew);
} }
@ -396,7 +340,6 @@ enum class LLVMRustSynchronizationScope {
CrossThread, CrossThread,
}; };
#if LLVM_VERSION_GE(5, 0)
static SyncScope::ID fromRust(LLVMRustSynchronizationScope Scope) { static SyncScope::ID fromRust(LLVMRustSynchronizationScope Scope) {
switch (Scope) { switch (Scope) {
case LLVMRustSynchronizationScope::SingleThread: case LLVMRustSynchronizationScope::SingleThread:
@ -407,18 +350,6 @@ static SyncScope::ID fromRust(LLVMRustSynchronizationScope Scope) {
report_fatal_error("bad SynchronizationScope."); 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 extern "C" LLVMValueRef
LLVMRustBuildAtomicFence(LLVMBuilderRef B, LLVMAtomicOrdering Order, LLVMRustBuildAtomicFence(LLVMBuilderRef B, LLVMAtomicOrdering Order,
@ -463,18 +394,6 @@ extern "C" void LLVMRustAppendModuleInlineAsm(LLVMModuleRef M, const char *Asm)
typedef DIBuilder *LLVMRustDIBuilderRef; 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<Metadata **>(Vals);
}
}
#endif
template <typename DIT> DIT *unwrapDIPtr(LLVMMetadataRef Ref) { template <typename DIT> DIT *unwrapDIPtr(LLVMMetadataRef Ref) {
return (DIT *)(Ref ? unwrap<MDNode>(Ref) : nullptr); return (DIT *)(Ref ? unwrap<MDNode>(Ref) : nullptr);
} }
@ -590,11 +509,6 @@ static DINode::DIFlags fromRust(LLVMRustDIFlags Flags) {
if (isSet(Flags & LLVMRustDIFlags::FlagRValueReference)) { if (isSet(Flags & LLVMRustDIFlags::FlagRValueReference)) {
Result |= DINode::DIFlags::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)) { if (isSet(Flags & LLVMRustDIFlags::FlagIntroducedVirtual)) {
Result |= DINode::DIFlags::FlagIntroducedVirtual; Result |= DINode::DIFlags::FlagIntroducedVirtual;
} }
@ -693,9 +607,7 @@ extern "C" LLVMMetadataRef LLVMRustDIBuilderCreatePointerType(
uint64_t SizeInBits, uint32_t AlignInBits, const char *Name) { uint64_t SizeInBits, uint32_t AlignInBits, const char *Name) {
return wrap(Builder->createPointerType(unwrapDI<DIType>(PointeeTy), return wrap(Builder->createPointerType(unwrapDI<DIType>(PointeeTy),
SizeInBits, AlignInBits, SizeInBits, AlignInBits,
#if LLVM_VERSION_GE(5, 0)
/* DWARFAddressSpace */ None, /* DWARFAddressSpace */ None,
#endif
Name)); Name));
} }
@ -902,12 +814,7 @@ LLVMRustDIBuilderCreateNameSpace(LLVMRustDIBuilderRef Builder,
LLVMMetadataRef Scope, const char *Name, LLVMMetadataRef Scope, const char *Name,
LLVMMetadataRef File, unsigned LineNo) { LLVMMetadataRef File, unsigned LineNo) {
return wrap(Builder->createNameSpace( return wrap(Builder->createNameSpace(
unwrapDI<DIDescriptor>(Scope), Name unwrapDI<DIDescriptor>(Scope), Name,
#if LLVM_VERSION_LT(5, 0)
,
unwrapDI<DIFile>(File), LineNo
#endif
,
false // ExportSymbols (only relevant for C++ anonymous namespaces) false // ExportSymbols (only relevant for C++ anonymous namespaces)
)); ));
} }
@ -937,12 +844,7 @@ extern "C" int64_t LLVMRustDIBuilderCreateOpDeref() {
} }
extern "C" int64_t LLVMRustDIBuilderCreateOpPlusUconst() { extern "C" int64_t LLVMRustDIBuilderCreateOpPlusUconst() {
#if LLVM_VERSION_GE(5, 0)
return dwarf::DW_OP_plus_uconst; 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) { extern "C" void LLVMRustWriteTypeToString(LLVMTypeRef Ty, RustStringRef Str) {
@ -1014,21 +916,12 @@ extern "C" void LLVMRustUnpackOptimizationDiagnostic(
*FunctionOut = wrap(&Opt->getFunction()); *FunctionOut = wrap(&Opt->getFunction());
RawRustStringOstream FilenameOS(FilenameOut); RawRustStringOstream FilenameOS(FilenameOut);
#if LLVM_VERSION_GE(5,0)
DiagnosticLocation loc = Opt->getLocation(); DiagnosticLocation loc = Opt->getLocation();
if (loc.isValid()) { if (loc.isValid()) {
*Line = loc.getLine(); *Line = loc.getLine();
*Column = loc.getColumn(); *Column = loc.getColumn();
FilenameOS << loc.getFilename(); FilenameOS << loc.getFilename();
} }
#else
const DebugLoc &loc = Opt->getDebugLoc();
if (loc) {
*Line = loc.getLine();
*Column = loc.getCol();
FilenameOS << cast<DIScope>(loc.getScope())->getFilename();
}
#endif
RawRustStringOstream MessageOS(MessageOut); RawRustStringOstream MessageOS(MessageOut);
MessageOS << Opt->getMsg(); MessageOS << Opt->getMsg();
@ -1485,7 +1378,6 @@ LLVMRustModuleCost(LLVMModuleRef M) {
} }
// Vector reductions: // Vector reductions:
#if LLVM_VERSION_GE(5, 0)
extern "C" LLVMValueRef extern "C" LLVMValueRef
LLVMRustBuildVectorReduceFAdd(LLVMBuilderRef B, LLVMValueRef Acc, LLVMValueRef Src) { LLVMRustBuildVectorReduceFAdd(LLVMBuilderRef B, LLVMValueRef Acc, LLVMValueRef Src) {
return wrap(unwrap(B)->CreateFAddReduce(unwrap(Acc),unwrap(Src))); return wrap(unwrap(B)->CreateFAddReduce(unwrap(Acc),unwrap(Src)));
@ -1531,54 +1423,6 @@ LLVMRustBuildVectorReduceFMax(LLVMBuilderRef B, LLVMValueRef Src, bool NoNaN) {
return wrap(unwrap(B)->CreateFPMaxReduce(unwrap(Src), 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_GE(6, 0) #if LLVM_VERSION_GE(6, 0)
extern "C" LLVMValueRef extern "C" LLVMValueRef
LLVMRustBuildMinNum(LLVMBuilderRef B, LLVMValueRef LHS, LLVMValueRef RHS) { LLVMRustBuildMinNum(LLVMBuilderRef B, LLVMValueRef LHS, LLVMValueRef RHS) {