Skip to content

Commit 3cc8b17

Browse files
committed
Remove support for building against LLVM 4
With emscripten removed in #55626, we no longer need to support building against LLVM 4.
1 parent 6cfc603 commit 3cc8b17

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
@@ -859,8 +859,7 @@ impl Builder<'a, 'll, 'tcx> {
859859
// FIXME: add a non-fast math version once
860860
// https://bugs.llvm.org/show_bug.cgi?id=36732
861861
// is fixed.
862-
let instr = llvm::LLVMRustBuildVectorReduceFAdd(self.llbuilder, acc, src)
863-
.expect("LLVMRustBuildVectorReduceFAdd is not available in LLVM version < 5.0");
862+
let instr = llvm::LLVMRustBuildVectorReduceFAdd(self.llbuilder, acc, src);
864863
llvm::LLVMRustSetHasUnsafeAlgebra(instr);
865864
instr
866865
}
@@ -871,92 +870,62 @@ impl Builder<'a, 'll, 'tcx> {
871870
// FIXME: add a non-fast math version once
872871
// https://bugs.llvm.org/show_bug.cgi?id=36732
873872
// is fixed.
874-
let instr = llvm::LLVMRustBuildVectorReduceFMul(self.llbuilder, acc, src)
875-
.expect("LLVMRustBuildVectorReduceFMul is not available in LLVM version < 5.0");
873+
let instr = llvm::LLVMRustBuildVectorReduceFMul(self.llbuilder, acc, src);
876874
llvm::LLVMRustSetHasUnsafeAlgebra(instr);
877875
instr
878876
}
879877
}
880878
pub fn vector_reduce_add(&self, src: &'ll Value) -> &'ll Value {
881879
self.count_insn("vector.reduce.add");
882-
unsafe {
883-
let instr = llvm::LLVMRustBuildVectorReduceAdd(self.llbuilder, src);
884-
instr.expect("LLVMRustBuildVectorReduceAdd is not available in LLVM version < 5.0")
885-
}
880+
unsafe { llvm::LLVMRustBuildVectorReduceAdd(self.llbuilder, src) }
886881
}
887882
pub fn vector_reduce_mul(&self, src: &'ll Value) -> &'ll Value {
888883
self.count_insn("vector.reduce.mul");
889-
unsafe {
890-
let instr = llvm::LLVMRustBuildVectorReduceMul(self.llbuilder, src);
891-
instr.expect("LLVMRustBuildVectorReduceMul is not available in LLVM version < 5.0")
892-
}
884+
unsafe { llvm::LLVMRustBuildVectorReduceMul(self.llbuilder, src) }
893885
}
894886
pub fn vector_reduce_and(&self, src: &'ll Value) -> &'ll Value {
895887
self.count_insn("vector.reduce.and");
896-
unsafe {
897-
let instr = llvm::LLVMRustBuildVectorReduceAnd(self.llbuilder, src);
898-
instr.expect("LLVMRustBuildVectorReduceAnd is not available in LLVM version < 5.0")
899-
}
888+
unsafe { llvm::LLVMRustBuildVectorReduceAnd(self.llbuilder, src) }
900889
}
901890
pub fn vector_reduce_or(&self, src: &'ll Value) -> &'ll Value {
902891
self.count_insn("vector.reduce.or");
903-
unsafe {
904-
let instr = llvm::LLVMRustBuildVectorReduceOr(self.llbuilder, src);
905-
instr.expect("LLVMRustBuildVectorReduceOr is not available in LLVM version < 5.0")
906-
}
892+
unsafe { llvm::LLVMRustBuildVectorReduceOr(self.llbuilder, src) }
907893
}
908894
pub fn vector_reduce_xor(&self, src: &'ll Value) -> &'ll Value {
909895
self.count_insn("vector.reduce.xor");
910-
unsafe {
911-
let instr = llvm::LLVMRustBuildVectorReduceXor(self.llbuilder, src);
912-
instr.expect("LLVMRustBuildVectorReduceXor is not available in LLVM version < 5.0")
913-
}
896+
unsafe { llvm::LLVMRustBuildVectorReduceXor(self.llbuilder, src) }
914897
}
915898
pub fn vector_reduce_fmin(&self, src: &'ll Value) -> &'ll Value {
916899
self.count_insn("vector.reduce.fmin");
917-
unsafe {
918-
let instr = llvm::LLVMRustBuildVectorReduceFMin(self.llbuilder, src, /*NoNaNs:*/ false);
919-
instr.expect("LLVMRustBuildVectorReduceFMin is not available in LLVM version < 5.0")
920-
}
900+
unsafe { llvm::LLVMRustBuildVectorReduceFMin(self.llbuilder, src, /*NoNaNs:*/ false) }
921901
}
922902
pub fn vector_reduce_fmax(&self, src: &'ll Value) -> &'ll Value {
923903
self.count_insn("vector.reduce.fmax");
924-
unsafe {
925-
let instr = llvm::LLVMRustBuildVectorReduceFMax(self.llbuilder, src, /*NoNaNs:*/ false);
926-
instr.expect("LLVMRustBuildVectorReduceFMax is not available in LLVM version < 5.0")
927-
}
904+
unsafe { llvm::LLVMRustBuildVectorReduceFMax(self.llbuilder, src, /*NoNaNs:*/ false) }
928905
}
929906
pub fn vector_reduce_fmin_fast(&self, src: &'ll Value) -> &'ll Value {
930907
self.count_insn("vector.reduce.fmin_fast");
931908
unsafe {
932-
let instr = llvm::LLVMRustBuildVectorReduceFMin(self.llbuilder, src, /*NoNaNs:*/ true)
933-
.expect("LLVMRustBuildVectorReduceFMin is not available in LLVM version < 5.0");
909+
let instr = llvm::LLVMRustBuildVectorReduceFMin(self.llbuilder, src, /*NoNaNs:*/ true);
934910
llvm::LLVMRustSetHasUnsafeAlgebra(instr);
935911
instr
936912
}
937913
}
938914
pub fn vector_reduce_fmax_fast(&self, src: &'ll Value) -> &'ll Value {
939915
self.count_insn("vector.reduce.fmax_fast");
940916
unsafe {
941-
let instr = llvm::LLVMRustBuildVectorReduceFMax(self.llbuilder, src, /*NoNaNs:*/ true)
942-
.expect("LLVMRustBuildVectorReduceFMax is not available in LLVM version < 5.0");
917+
let instr = llvm::LLVMRustBuildVectorReduceFMax(self.llbuilder, src, /*NoNaNs:*/ true);
943918
llvm::LLVMRustSetHasUnsafeAlgebra(instr);
944919
instr
945920
}
946921
}
947922
pub fn vector_reduce_min(&self, src: &'ll Value, is_signed: bool) -> &'ll Value {
948923
self.count_insn("vector.reduce.min");
949-
unsafe {
950-
let instr = llvm::LLVMRustBuildVectorReduceMin(self.llbuilder, src, is_signed);
951-
instr.expect("LLVMRustBuildVectorReduceMin is not available in LLVM version < 5.0")
952-
}
924+
unsafe { llvm::LLVMRustBuildVectorReduceMin(self.llbuilder, src, is_signed) }
953925
}
954926
pub fn vector_reduce_max(&self, src: &'ll Value, is_signed: bool) -> &'ll Value {
955927
self.count_insn("vector.reduce.max");
956-
unsafe {
957-
let instr = llvm::LLVMRustBuildVectorReduceMax(self.llbuilder, src, is_signed);
958-
instr.expect("LLVMRustBuildVectorReduceMax is not available in LLVM version < 5.0")
959-
}
928+
unsafe { llvm::LLVMRustBuildVectorReduceMax(self.llbuilder, src, is_signed) }
960929
}
961930

962931
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
@@ -1041,42 +1041,42 @@ extern "C" {
10411041
pub fn LLVMRustBuildVectorReduceFAdd(B: &Builder<'a>,
10421042
Acc: &'a Value,
10431043
Src: &'a Value)
1044-
-> Option<&'a Value>;
1044+
-> &'a Value;
10451045
pub fn LLVMRustBuildVectorReduceFMul(B: &Builder<'a>,
10461046
Acc: &'a Value,
10471047
Src: &'a Value)
1048-
-> Option<&'a Value>;
1048+
-> &'a Value;
10491049
pub fn LLVMRustBuildVectorReduceAdd(B: &Builder<'a>,
10501050
Src: &'a Value)
1051-
-> Option<&'a Value>;
1051+
-> &'a Value;
10521052
pub fn LLVMRustBuildVectorReduceMul(B: &Builder<'a>,
10531053
Src: &'a Value)
1054-
-> Option<&'a Value>;
1054+
-> &'a Value;
10551055
pub fn LLVMRustBuildVectorReduceAnd(B: &Builder<'a>,
10561056
Src: &'a Value)
1057-
-> Option<&'a Value>;
1057+
-> &'a Value;
10581058
pub fn LLVMRustBuildVectorReduceOr(B: &Builder<'a>,
10591059
Src: &'a Value)
1060-
-> Option<&'a Value>;
1060+
-> &'a Value;
10611061
pub fn LLVMRustBuildVectorReduceXor(B: &Builder<'a>,
10621062
Src: &'a Value)
1063-
-> Option<&'a Value>;
1063+
-> &'a Value;
10641064
pub fn LLVMRustBuildVectorReduceMin(B: &Builder<'a>,
10651065
Src: &'a Value,
10661066
IsSigned: bool)
1067-
-> Option<&'a Value>;
1067+
-> &'a Value;
10681068
pub fn LLVMRustBuildVectorReduceMax(B: &Builder<'a>,
10691069
Src: &'a Value,
10701070
IsSigned: bool)
1071-
-> Option<&'a Value>;
1071+
-> &'a Value;
10721072
pub fn LLVMRustBuildVectorReduceFMin(B: &Builder<'a>,
10731073
Src: &'a Value,
10741074
IsNaN: bool)
1075-
-> Option<&'a Value>;
1075+
-> &'a Value;
10761076
pub fn LLVMRustBuildVectorReduceFMax(B: &Builder<'a>,
10771077
Src: &'a Value,
10781078
IsNaN: bool)
1079-
-> Option<&'a Value>;
1079+
-> &'a Value;
10801080

10811081
pub fn LLVMRustBuildMinNum(
10821082
B: &Builder<'a>,
@@ -1157,7 +1157,7 @@ extern "C" {
11571157
RunInliner: Bool);
11581158
pub fn LLVMRustPassManagerBuilderPopulateThinLTOPassManager(
11591159
PMB: &PassManagerBuilder,
1160-
PM: &PassManager) -> bool;
1160+
PM: &PassManager);
11611161

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

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)