Skip to content

Commit

Permalink
Auto merge of #55698 - nikic:remove-llvm-4-support, r=alexcrichton
Browse files Browse the repository at this point in the history
Remove support for building against LLVM 4

With emscripten removed in #55626, we no longer need to support building against LLVM 4.
  • Loading branch information
bors committed Nov 11, 2018
2 parents ca79ecd + 3cc8b17 commit 775eab5
Show file tree
Hide file tree
Showing 6 changed files with 29 additions and 259 deletions.
4 changes: 1 addition & 3 deletions src/librustc_codegen_llvm/back/lto.rs
Original file line number Diff line number Diff line change
Expand Up @@ -595,9 +595,7 @@ fn run_pass_manager(cgcx: &CodegenContext,
};
with_llvm_pmb(llmod, config, opt_level, false, &mut |b| {
if thin {
if !llvm::LLVMRustPassManagerBuilderPopulateThinLTOPassManager(b, pm) {
panic!("this version of LLVM does not support ThinLTO");
}
llvm::LLVMRustPassManagerBuilderPopulateThinLTOPassManager(b, pm);
} else {
llvm::LLVMPassManagerBuilderPopulateLTOPassManager(b, pm,
/* Internalize = */ False,
Expand Down
57 changes: 13 additions & 44 deletions src/librustc_codegen_llvm/builder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -874,8 +874,7 @@ impl Builder<'a, 'll, 'tcx> {
// FIXME: add a non-fast math version once
// https://bugs.llvm.org/show_bug.cgi?id=36732
// is fixed.
let instr = llvm::LLVMRustBuildVectorReduceFAdd(self.llbuilder, acc, src)
.expect("LLVMRustBuildVectorReduceFAdd is not available in LLVM version < 5.0");
let instr = llvm::LLVMRustBuildVectorReduceFAdd(self.llbuilder, acc, src);
llvm::LLVMRustSetHasUnsafeAlgebra(instr);
instr
}
Expand All @@ -886,92 +885,62 @@ impl Builder<'a, 'll, 'tcx> {
// FIXME: add a non-fast math version once
// https://bugs.llvm.org/show_bug.cgi?id=36732
// is fixed.
let instr = llvm::LLVMRustBuildVectorReduceFMul(self.llbuilder, acc, src)
.expect("LLVMRustBuildVectorReduceFMul is not available in LLVM version < 5.0");
let instr = llvm::LLVMRustBuildVectorReduceFMul(self.llbuilder, acc, src);
llvm::LLVMRustSetHasUnsafeAlgebra(instr);
instr
}
}
pub fn vector_reduce_add(&self, src: &'ll Value) -> &'ll Value {
self.count_insn("vector.reduce.add");
unsafe {
let instr = llvm::LLVMRustBuildVectorReduceAdd(self.llbuilder, src);
instr.expect("LLVMRustBuildVectorReduceAdd is not available in LLVM version < 5.0")
}
unsafe { llvm::LLVMRustBuildVectorReduceAdd(self.llbuilder, src) }
}
pub fn vector_reduce_mul(&self, src: &'ll Value) -> &'ll Value {
self.count_insn("vector.reduce.mul");
unsafe {
let instr = llvm::LLVMRustBuildVectorReduceMul(self.llbuilder, src);
instr.expect("LLVMRustBuildVectorReduceMul is not available in LLVM version < 5.0")
}
unsafe { llvm::LLVMRustBuildVectorReduceMul(self.llbuilder, src) }
}
pub fn vector_reduce_and(&self, src: &'ll Value) -> &'ll Value {
self.count_insn("vector.reduce.and");
unsafe {
let instr = llvm::LLVMRustBuildVectorReduceAnd(self.llbuilder, src);
instr.expect("LLVMRustBuildVectorReduceAnd is not available in LLVM version < 5.0")
}
unsafe { llvm::LLVMRustBuildVectorReduceAnd(self.llbuilder, src) }
}
pub fn vector_reduce_or(&self, src: &'ll Value) -> &'ll Value {
self.count_insn("vector.reduce.or");
unsafe {
let instr = llvm::LLVMRustBuildVectorReduceOr(self.llbuilder, src);
instr.expect("LLVMRustBuildVectorReduceOr is not available in LLVM version < 5.0")
}
unsafe { llvm::LLVMRustBuildVectorReduceOr(self.llbuilder, src) }
}
pub fn vector_reduce_xor(&self, src: &'ll Value) -> &'ll Value {
self.count_insn("vector.reduce.xor");
unsafe {
let instr = llvm::LLVMRustBuildVectorReduceXor(self.llbuilder, src);
instr.expect("LLVMRustBuildVectorReduceXor is not available in LLVM version < 5.0")
}
unsafe { llvm::LLVMRustBuildVectorReduceXor(self.llbuilder, src) }
}
pub fn vector_reduce_fmin(&self, src: &'ll Value) -> &'ll Value {
self.count_insn("vector.reduce.fmin");
unsafe {
let instr = llvm::LLVMRustBuildVectorReduceFMin(self.llbuilder, src, /*NoNaNs:*/ false);
instr.expect("LLVMRustBuildVectorReduceFMin is not available in LLVM version < 5.0")
}
unsafe { llvm::LLVMRustBuildVectorReduceFMin(self.llbuilder, src, /*NoNaNs:*/ false) }
}
pub fn vector_reduce_fmax(&self, src: &'ll Value) -> &'ll Value {
self.count_insn("vector.reduce.fmax");
unsafe {
let instr = llvm::LLVMRustBuildVectorReduceFMax(self.llbuilder, src, /*NoNaNs:*/ false);
instr.expect("LLVMRustBuildVectorReduceFMax is not available in LLVM version < 5.0")
}
unsafe { llvm::LLVMRustBuildVectorReduceFMax(self.llbuilder, src, /*NoNaNs:*/ false) }
}
pub fn vector_reduce_fmin_fast(&self, src: &'ll Value) -> &'ll Value {
self.count_insn("vector.reduce.fmin_fast");
unsafe {
let instr = llvm::LLVMRustBuildVectorReduceFMin(self.llbuilder, src, /*NoNaNs:*/ true)
.expect("LLVMRustBuildVectorReduceFMin is not available in LLVM version < 5.0");
let instr = llvm::LLVMRustBuildVectorReduceFMin(self.llbuilder, src, /*NoNaNs:*/ true);
llvm::LLVMRustSetHasUnsafeAlgebra(instr);
instr
}
}
pub fn vector_reduce_fmax_fast(&self, src: &'ll Value) -> &'ll Value {
self.count_insn("vector.reduce.fmax_fast");
unsafe {
let instr = llvm::LLVMRustBuildVectorReduceFMax(self.llbuilder, src, /*NoNaNs:*/ true)
.expect("LLVMRustBuildVectorReduceFMax is not available in LLVM version < 5.0");
let instr = llvm::LLVMRustBuildVectorReduceFMax(self.llbuilder, src, /*NoNaNs:*/ true);
llvm::LLVMRustSetHasUnsafeAlgebra(instr);
instr
}
}
pub fn vector_reduce_min(&self, src: &'ll Value, is_signed: bool) -> &'ll Value {
self.count_insn("vector.reduce.min");
unsafe {
let instr = llvm::LLVMRustBuildVectorReduceMin(self.llbuilder, src, is_signed);
instr.expect("LLVMRustBuildVectorReduceMin is not available in LLVM version < 5.0")
}
unsafe { llvm::LLVMRustBuildVectorReduceMin(self.llbuilder, src, is_signed) }
}
pub fn vector_reduce_max(&self, src: &'ll Value, is_signed: bool) -> &'ll Value {
self.count_insn("vector.reduce.max");
unsafe {
let instr = llvm::LLVMRustBuildVectorReduceMax(self.llbuilder, src, is_signed);
instr.expect("LLVMRustBuildVectorReduceMax is not available in LLVM version < 5.0")
}
unsafe { llvm::LLVMRustBuildVectorReduceMax(self.llbuilder, src, is_signed) }
}

pub fn extract_value(&self, agg_val: &'ll Value, idx: u64) -> &'ll Value {
Expand Down
24 changes: 12 additions & 12 deletions src/librustc_codegen_llvm/llvm/ffi.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1057,42 +1057,42 @@ extern "C" {
pub fn LLVMRustBuildVectorReduceFAdd(B: &Builder<'a>,
Acc: &'a Value,
Src: &'a Value)
-> Option<&'a Value>;
-> &'a Value;
pub fn LLVMRustBuildVectorReduceFMul(B: &Builder<'a>,
Acc: &'a Value,
Src: &'a Value)
-> Option<&'a Value>;
-> &'a Value;
pub fn LLVMRustBuildVectorReduceAdd(B: &Builder<'a>,
Src: &'a Value)
-> Option<&'a Value>;
-> &'a Value;
pub fn LLVMRustBuildVectorReduceMul(B: &Builder<'a>,
Src: &'a Value)
-> Option<&'a Value>;
-> &'a Value;
pub fn LLVMRustBuildVectorReduceAnd(B: &Builder<'a>,
Src: &'a Value)
-> Option<&'a Value>;
-> &'a Value;
pub fn LLVMRustBuildVectorReduceOr(B: &Builder<'a>,
Src: &'a Value)
-> Option<&'a Value>;
-> &'a Value;
pub fn LLVMRustBuildVectorReduceXor(B: &Builder<'a>,
Src: &'a Value)
-> Option<&'a Value>;
-> &'a Value;
pub fn LLVMRustBuildVectorReduceMin(B: &Builder<'a>,
Src: &'a Value,
IsSigned: bool)
-> Option<&'a Value>;
-> &'a Value;
pub fn LLVMRustBuildVectorReduceMax(B: &Builder<'a>,
Src: &'a Value,
IsSigned: bool)
-> Option<&'a Value>;
-> &'a Value;
pub fn LLVMRustBuildVectorReduceFMin(B: &Builder<'a>,
Src: &'a Value,
IsNaN: bool)
-> Option<&'a Value>;
-> &'a Value;
pub fn LLVMRustBuildVectorReduceFMax(B: &Builder<'a>,
Src: &'a Value,
IsNaN: bool)
-> Option<&'a Value>;
-> &'a Value;

pub fn LLVMRustBuildMinNum(
B: &Builder<'a>,
Expand Down Expand Up @@ -1173,7 +1173,7 @@ extern "C" {
RunInliner: Bool);
pub fn LLVMRustPassManagerBuilderPopulateThinLTOPassManager(
PMB: &PassManagerBuilder,
PM: &PassManager) -> bool;
PM: &PassManager);

// Stuff that's in rustllvm/ because it's not upstream yet.

Expand Down
2 changes: 0 additions & 2 deletions src/rustllvm/ArchiveWrapper.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -204,9 +204,7 @@ LLVMRustWriteArchive(char *Dst, size_t NumMembers,
LLVMRustSetLastError(toString(MOrErr.takeError()).c_str());
return LLVMRustResult::Failure;
}
#if LLVM_VERSION_GE(5, 0)
MOrErr->MemberName = sys::path::filename(MOrErr->MemberName);
#endif
Members.push_back(std::move(*MOrErr));
} else {
Expected<NewArchiveMember> MOrErr =
Expand Down
41 changes: 1 addition & 40 deletions src/rustllvm/PassWrapper.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -36,9 +36,6 @@
#include "llvm/Transforms/IPO/FunctionImport.h"
#include "llvm/Transforms/Utils/FunctionImportUtils.h"
#include "llvm/LTO/LTO.h"
#if LLVM_VERSION_LE(4, 0)
#include "llvm/Object/ModuleSummaryIndexObjectFile.h"
#endif

#include "llvm-c/Transforms/PassManagerBuilder.h"

Expand Down Expand Up @@ -111,12 +108,11 @@ extern "C" void LLVMRustAddPass(LLVMPassManagerRef PMR, LLVMPassRef RustPass) {
}

extern "C"
bool LLVMRustPassManagerBuilderPopulateThinLTOPassManager(
void LLVMRustPassManagerBuilderPopulateThinLTOPassManager(
LLVMPassManagerBuilderRef PMBR,
LLVMPassManagerRef PMR
) {
unwrap(PMBR)->populateThinLTOPassManager(*unwrap(PMR));
return true;
}

#ifdef LLVM_COMPONENT_X86
Expand Down Expand Up @@ -869,21 +865,10 @@ LLVMRustCreateThinLTOData(LLVMRustThinLTOModule *modules,

Ret->ModuleMap[module->identifier] = mem_buffer;

#if LLVM_VERSION_GE(5, 0)
if (Error Err = readModuleSummaryIndex(mem_buffer, Ret->Index, i)) {
LLVMRustSetLastError(toString(std::move(Err)).c_str());
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)
Expand All @@ -900,7 +885,6 @@ LLVMRustCreateThinLTOData(LLVMRustThinLTOModule *modules,
// combined index
//
// This is copied from `lib/LTO/ThinLTOCodeGenerator.cpp`
#if LLVM_VERSION_GE(5, 0)
#if LLVM_VERSION_GE(7, 0)
auto deadIsPrevailing = [&](GlobalValue::GUID G) {
return PrevailingType::Unknown;
Expand All @@ -915,16 +899,6 @@ LLVMRustCreateThinLTOData(LLVMRustThinLTOModule *modules,
Ret->ImportLists,
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
// impacts the caching.
Expand All @@ -934,13 +908,8 @@ LLVMRustCreateThinLTOData(LLVMRustThinLTOModule *modules,
StringMap<std::map<GlobalValue::GUID, GlobalValue::LinkageTypes>> ResolvedODR;
DenseMap<GlobalValue::GUID, const GlobalValueSummary *> PrevailingCopy;
for (auto &I : Ret->Index) {
#if LLVM_VERSION_GE(5, 0)
if (I.second.SummaryList.size() > 1)
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) {
const auto &Prevailing = PrevailingCopy.find(GUID);
Expand All @@ -962,19 +931,11 @@ LLVMRustCreateThinLTOData(LLVMRustThinLTOModule *modules,
// linkage will stay as external, and internal will stay as internal.
std::set<GlobalValue::GUID> ExportedGUIDs;
for (auto &List : Ret->Index) {
#if LLVM_VERSION_GE(5, 0)
for (auto &GVS: List.second.SummaryList) {
#else
for (auto &GVS: List.second) {
#endif
if (GlobalValue::isLocalLinkage(GVS->linkage()))
continue;
auto GUID = GVS->getOriginalName();
#if LLVM_VERSION_GE(5, 0)
if (GVS->flags().Live)
#else
if (!DeadSymbols.count(GUID))
#endif
ExportedGUIDs.insert(GUID);
}
}
Expand Down
Loading

0 comments on commit 775eab5

Please sign in to comment.