Skip to content

Commit 775eab5

Browse files
committed
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.
2 parents ca79ecd + 3cc8b17 commit 775eab5

File tree

6 files changed

+29
-259
lines changed

6 files changed

+29
-259
lines changed

src/librustc_codegen_llvm/back/lto.rs

+1-3
Original file line numberDiff line numberDiff line change
@@ -595,9 +595,7 @@ fn run_pass_manager(cgcx: &CodegenContext,
595595
};
596596
with_llvm_pmb(llmod, config, opt_level, false, &mut |b| {
597597
if thin {
598-
if !llvm::LLVMRustPassManagerBuilderPopulateThinLTOPassManager(b, pm) {
599-
panic!("this version of LLVM does not support ThinLTO");
600-
}
598+
llvm::LLVMRustPassManagerBuilderPopulateThinLTOPassManager(b, pm);
601599
} else {
602600
llvm::LLVMPassManagerBuilderPopulateLTOPassManager(b, pm,
603601
/* Internalize = */ False,

src/librustc_codegen_llvm/builder.rs

+13-44
Original file line numberDiff line numberDiff line change
@@ -874,8 +874,7 @@ impl Builder<'a, 'll, 'tcx> {
874874
// FIXME: add a non-fast math version once
875875
// https://bugs.llvm.org/show_bug.cgi?id=36732
876876
// is fixed.
877-
let instr = llvm::LLVMRustBuildVectorReduceFAdd(self.llbuilder, acc, src)
878-
.expect("LLVMRustBuildVectorReduceFAdd is not available in LLVM version < 5.0");
877+
let instr = llvm::LLVMRustBuildVectorReduceFAdd(self.llbuilder, acc, src);
879878
llvm::LLVMRustSetHasUnsafeAlgebra(instr);
880879
instr
881880
}
@@ -886,92 +885,62 @@ impl Builder<'a, 'll, 'tcx> {
886885
// FIXME: add a non-fast math version once
887886
// https://bugs.llvm.org/show_bug.cgi?id=36732
888887
// is fixed.
889-
let instr = llvm::LLVMRustBuildVectorReduceFMul(self.llbuilder, acc, src)
890-
.expect("LLVMRustBuildVectorReduceFMul is not available in LLVM version < 5.0");
888+
let instr = llvm::LLVMRustBuildVectorReduceFMul(self.llbuilder, acc, src);
891889
llvm::LLVMRustSetHasUnsafeAlgebra(instr);
892890
instr
893891
}
894892
}
895893
pub fn vector_reduce_add(&self, src: &'ll Value) -> &'ll Value {
896894
self.count_insn("vector.reduce.add");
897-
unsafe {
898-
let instr = llvm::LLVMRustBuildVectorReduceAdd(self.llbuilder, src);
899-
instr.expect("LLVMRustBuildVectorReduceAdd is not available in LLVM version < 5.0")
900-
}
895+
unsafe { llvm::LLVMRustBuildVectorReduceAdd(self.llbuilder, src) }
901896
}
902897
pub fn vector_reduce_mul(&self, src: &'ll Value) -> &'ll Value {
903898
self.count_insn("vector.reduce.mul");
904-
unsafe {
905-
let instr = llvm::LLVMRustBuildVectorReduceMul(self.llbuilder, src);
906-
instr.expect("LLVMRustBuildVectorReduceMul is not available in LLVM version < 5.0")
907-
}
899+
unsafe { llvm::LLVMRustBuildVectorReduceMul(self.llbuilder, src) }
908900
}
909901
pub fn vector_reduce_and(&self, src: &'ll Value) -> &'ll Value {
910902
self.count_insn("vector.reduce.and");
911-
unsafe {
912-
let instr = llvm::LLVMRustBuildVectorReduceAnd(self.llbuilder, src);
913-
instr.expect("LLVMRustBuildVectorReduceAnd is not available in LLVM version < 5.0")
914-
}
903+
unsafe { llvm::LLVMRustBuildVectorReduceAnd(self.llbuilder, src) }
915904
}
916905
pub fn vector_reduce_or(&self, src: &'ll Value) -> &'ll Value {
917906
self.count_insn("vector.reduce.or");
918-
unsafe {
919-
let instr = llvm::LLVMRustBuildVectorReduceOr(self.llbuilder, src);
920-
instr.expect("LLVMRustBuildVectorReduceOr is not available in LLVM version < 5.0")
921-
}
907+
unsafe { llvm::LLVMRustBuildVectorReduceOr(self.llbuilder, src) }
922908
}
923909
pub fn vector_reduce_xor(&self, src: &'ll Value) -> &'ll Value {
924910
self.count_insn("vector.reduce.xor");
925-
unsafe {
926-
let instr = llvm::LLVMRustBuildVectorReduceXor(self.llbuilder, src);
927-
instr.expect("LLVMRustBuildVectorReduceXor is not available in LLVM version < 5.0")
928-
}
911+
unsafe { llvm::LLVMRustBuildVectorReduceXor(self.llbuilder, src) }
929912
}
930913
pub fn vector_reduce_fmin(&self, src: &'ll Value) -> &'ll Value {
931914
self.count_insn("vector.reduce.fmin");
932-
unsafe {
933-
let instr = llvm::LLVMRustBuildVectorReduceFMin(self.llbuilder, src, /*NoNaNs:*/ false);
934-
instr.expect("LLVMRustBuildVectorReduceFMin is not available in LLVM version < 5.0")
935-
}
915+
unsafe { llvm::LLVMRustBuildVectorReduceFMin(self.llbuilder, src, /*NoNaNs:*/ false) }
936916
}
937917
pub fn vector_reduce_fmax(&self, src: &'ll Value) -> &'ll Value {
938918
self.count_insn("vector.reduce.fmax");
939-
unsafe {
940-
let instr = llvm::LLVMRustBuildVectorReduceFMax(self.llbuilder, src, /*NoNaNs:*/ false);
941-
instr.expect("LLVMRustBuildVectorReduceFMax is not available in LLVM version < 5.0")
942-
}
919+
unsafe { llvm::LLVMRustBuildVectorReduceFMax(self.llbuilder, src, /*NoNaNs:*/ false) }
943920
}
944921
pub fn vector_reduce_fmin_fast(&self, src: &'ll Value) -> &'ll Value {
945922
self.count_insn("vector.reduce.fmin_fast");
946923
unsafe {
947-
let instr = llvm::LLVMRustBuildVectorReduceFMin(self.llbuilder, src, /*NoNaNs:*/ true)
948-
.expect("LLVMRustBuildVectorReduceFMin is not available in LLVM version < 5.0");
924+
let instr = llvm::LLVMRustBuildVectorReduceFMin(self.llbuilder, src, /*NoNaNs:*/ true);
949925
llvm::LLVMRustSetHasUnsafeAlgebra(instr);
950926
instr
951927
}
952928
}
953929
pub fn vector_reduce_fmax_fast(&self, src: &'ll Value) -> &'ll Value {
954930
self.count_insn("vector.reduce.fmax_fast");
955931
unsafe {
956-
let instr = llvm::LLVMRustBuildVectorReduceFMax(self.llbuilder, src, /*NoNaNs:*/ true)
957-
.expect("LLVMRustBuildVectorReduceFMax is not available in LLVM version < 5.0");
932+
let instr = llvm::LLVMRustBuildVectorReduceFMax(self.llbuilder, src, /*NoNaNs:*/ true);
958933
llvm::LLVMRustSetHasUnsafeAlgebra(instr);
959934
instr
960935
}
961936
}
962937
pub fn vector_reduce_min(&self, src: &'ll Value, is_signed: bool) -> &'ll Value {
963938
self.count_insn("vector.reduce.min");
964-
unsafe {
965-
let instr = llvm::LLVMRustBuildVectorReduceMin(self.llbuilder, src, is_signed);
966-
instr.expect("LLVMRustBuildVectorReduceMin is not available in LLVM version < 5.0")
967-
}
939+
unsafe { llvm::LLVMRustBuildVectorReduceMin(self.llbuilder, src, is_signed) }
968940
}
969941
pub fn vector_reduce_max(&self, src: &'ll Value, is_signed: bool) -> &'ll Value {
970942
self.count_insn("vector.reduce.max");
971-
unsafe {
972-
let instr = llvm::LLVMRustBuildVectorReduceMax(self.llbuilder, src, is_signed);
973-
instr.expect("LLVMRustBuildVectorReduceMax is not available in LLVM version < 5.0")
974-
}
943+
unsafe { llvm::LLVMRustBuildVectorReduceMax(self.llbuilder, src, is_signed) }
975944
}
976945

977946
pub fn extract_value(&self, agg_val: &'ll Value, idx: u64) -> &'ll Value {

src/librustc_codegen_llvm/llvm/ffi.rs

+12-12
Original file line numberDiff line numberDiff line change
@@ -1057,42 +1057,42 @@ extern "C" {
10571057
pub fn LLVMRustBuildVectorReduceFAdd(B: &Builder<'a>,
10581058
Acc: &'a Value,
10591059
Src: &'a Value)
1060-
-> Option<&'a Value>;
1060+
-> &'a Value;
10611061
pub fn LLVMRustBuildVectorReduceFMul(B: &Builder<'a>,
10621062
Acc: &'a Value,
10631063
Src: &'a Value)
1064-
-> Option<&'a Value>;
1064+
-> &'a Value;
10651065
pub fn LLVMRustBuildVectorReduceAdd(B: &Builder<'a>,
10661066
Src: &'a Value)
1067-
-> Option<&'a Value>;
1067+
-> &'a Value;
10681068
pub fn LLVMRustBuildVectorReduceMul(B: &Builder<'a>,
10691069
Src: &'a Value)
1070-
-> Option<&'a Value>;
1070+
-> &'a Value;
10711071
pub fn LLVMRustBuildVectorReduceAnd(B: &Builder<'a>,
10721072
Src: &'a Value)
1073-
-> Option<&'a Value>;
1073+
-> &'a Value;
10741074
pub fn LLVMRustBuildVectorReduceOr(B: &Builder<'a>,
10751075
Src: &'a Value)
1076-
-> Option<&'a Value>;
1076+
-> &'a Value;
10771077
pub fn LLVMRustBuildVectorReduceXor(B: &Builder<'a>,
10781078
Src: &'a Value)
1079-
-> Option<&'a Value>;
1079+
-> &'a Value;
10801080
pub fn LLVMRustBuildVectorReduceMin(B: &Builder<'a>,
10811081
Src: &'a Value,
10821082
IsSigned: bool)
1083-
-> Option<&'a Value>;
1083+
-> &'a Value;
10841084
pub fn LLVMRustBuildVectorReduceMax(B: &Builder<'a>,
10851085
Src: &'a Value,
10861086
IsSigned: bool)
1087-
-> Option<&'a Value>;
1087+
-> &'a Value;
10881088
pub fn LLVMRustBuildVectorReduceFMin(B: &Builder<'a>,
10891089
Src: &'a Value,
10901090
IsNaN: bool)
1091-
-> Option<&'a Value>;
1091+
-> &'a Value;
10921092
pub fn LLVMRustBuildVectorReduceFMax(B: &Builder<'a>,
10931093
Src: &'a Value,
10941094
IsNaN: bool)
1095-
-> Option<&'a Value>;
1095+
-> &'a Value;
10961096

10971097
pub fn LLVMRustBuildMinNum(
10981098
B: &Builder<'a>,
@@ -1173,7 +1173,7 @@ extern "C" {
11731173
RunInliner: Bool);
11741174
pub fn LLVMRustPassManagerBuilderPopulateThinLTOPassManager(
11751175
PMB: &PassManagerBuilder,
1176-
PM: &PassManager) -> bool;
1176+
PM: &PassManager);
11771177

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

src/rustllvm/ArchiveWrapper.cpp

-2
Original file line numberDiff line numberDiff line change
@@ -204,9 +204,7 @@ LLVMRustWriteArchive(char *Dst, size_t NumMembers,
204204
LLVMRustSetLastError(toString(MOrErr.takeError()).c_str());
205205
return LLVMRustResult::Failure;
206206
}
207-
#if LLVM_VERSION_GE(5, 0)
208207
MOrErr->MemberName = sys::path::filename(MOrErr->MemberName);
209-
#endif
210208
Members.push_back(std::move(*MOrErr));
211209
} else {
212210
Expected<NewArchiveMember> MOrErr =

src/rustllvm/PassWrapper.cpp

+1-40
Original file line numberDiff line numberDiff line change
@@ -36,9 +36,6 @@
3636
#include "llvm/Transforms/IPO/FunctionImport.h"
3737
#include "llvm/Transforms/Utils/FunctionImportUtils.h"
3838
#include "llvm/LTO/LTO.h"
39-
#if LLVM_VERSION_LE(4, 0)
40-
#include "llvm/Object/ModuleSummaryIndexObjectFile.h"
41-
#endif
4239

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

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

113110
extern "C"
114-
bool LLVMRustPassManagerBuilderPopulateThinLTOPassManager(
111+
void LLVMRustPassManagerBuilderPopulateThinLTOPassManager(
115112
LLVMPassManagerBuilderRef PMBR,
116113
LLVMPassManagerRef PMR
117114
) {
118115
unwrap(PMBR)->populateThinLTOPassManager(*unwrap(PMR));
119-
return true;
120116
}
121117

122118
#ifdef LLVM_COMPONENT_X86
@@ -869,21 +865,10 @@ LLVMRustCreateThinLTOData(LLVMRustThinLTOModule *modules,
869865

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

872-
#if LLVM_VERSION_GE(5, 0)
873868
if (Error Err = readModuleSummaryIndex(mem_buffer, Ret->Index, i)) {
874869
LLVMRustSetLastError(toString(std::move(Err)).c_str());
875870
return nullptr;
876871
}
877-
#else
878-
Expected<std::unique_ptr<object::ModuleSummaryIndexObjectFile>> ObjOrErr =
879-
object::ModuleSummaryIndexObjectFile::create(mem_buffer);
880-
if (!ObjOrErr) {
881-
LLVMRustSetLastError(toString(ObjOrErr.takeError()).c_str());
882-
return nullptr;
883-
}
884-
auto Index = (*ObjOrErr)->takeIndex();
885-
Ret->Index.mergeFrom(std::move(Index), i);
886-
#endif
887872
}
888873

889874
// Collect for each module the list of function it defines (GUID -> Summary)
@@ -900,7 +885,6 @@ LLVMRustCreateThinLTOData(LLVMRustThinLTOModule *modules,
900885
// combined index
901886
//
902887
// This is copied from `lib/LTO/ThinLTOCodeGenerator.cpp`
903-
#if LLVM_VERSION_GE(5, 0)
904888
#if LLVM_VERSION_GE(7, 0)
905889
auto deadIsPrevailing = [&](GlobalValue::GUID G) {
906890
return PrevailingType::Unknown;
@@ -915,16 +899,6 @@ LLVMRustCreateThinLTOData(LLVMRustThinLTOModule *modules,
915899
Ret->ImportLists,
916900
Ret->ExportLists
917901
);
918-
#else
919-
auto DeadSymbols = computeDeadSymbols(Ret->Index, Ret->GUIDPreservedSymbols);
920-
ComputeCrossModuleImport(
921-
Ret->Index,
922-
Ret->ModuleToDefinedGVSummaries,
923-
Ret->ImportLists,
924-
Ret->ExportLists,
925-
&DeadSymbols
926-
);
927-
#endif
928902

929903
// Resolve LinkOnce/Weak symbols, this has to be computed early be cause it
930904
// impacts the caching.
@@ -934,13 +908,8 @@ LLVMRustCreateThinLTOData(LLVMRustThinLTOModule *modules,
934908
StringMap<std::map<GlobalValue::GUID, GlobalValue::LinkageTypes>> ResolvedODR;
935909
DenseMap<GlobalValue::GUID, const GlobalValueSummary *> PrevailingCopy;
936910
for (auto &I : Ret->Index) {
937-
#if LLVM_VERSION_GE(5, 0)
938911
if (I.second.SummaryList.size() > 1)
939912
PrevailingCopy[I.first] = getFirstDefinitionForLinker(I.second.SummaryList);
940-
#else
941-
if (I.second.size() > 1)
942-
PrevailingCopy[I.first] = getFirstDefinitionForLinker(I.second);
943-
#endif
944913
}
945914
auto isPrevailing = [&](GlobalValue::GUID GUID, const GlobalValueSummary *S) {
946915
const auto &Prevailing = PrevailingCopy.find(GUID);
@@ -962,19 +931,11 @@ LLVMRustCreateThinLTOData(LLVMRustThinLTOModule *modules,
962931
// linkage will stay as external, and internal will stay as internal.
963932
std::set<GlobalValue::GUID> ExportedGUIDs;
964933
for (auto &List : Ret->Index) {
965-
#if LLVM_VERSION_GE(5, 0)
966934
for (auto &GVS: List.second.SummaryList) {
967-
#else
968-
for (auto &GVS: List.second) {
969-
#endif
970935
if (GlobalValue::isLocalLinkage(GVS->linkage()))
971936
continue;
972937
auto GUID = GVS->getOriginalName();
973-
#if LLVM_VERSION_GE(5, 0)
974938
if (GVS->flags().Live)
975-
#else
976-
if (!DeadSymbols.count(GUID))
977-
#endif
978939
ExportedGUIDs.insert(GUID);
979940
}
980941
}

0 commit comments

Comments
 (0)