Rollup merge of #78848 - DevJPM:ci-llvm-9, r=nikic

Bump minimal supported LLVM version to 9

This bumps the minimal tested llvm version to 9.
This should enable supporting newer LLVM features (and CPU extensions).

This was motived by #78361 having to drop features because of LLVM 8 not supporting certain CPU extensions yet.
This was declared relatively uncontroversial on [Zulip](215957859).

Paging ````@eddyb```` because there was a comment in the [dockerfile](https://github.com/rust-lang/rust/blob/master/src/ci/docker/host-x86_64/x86_64-gnu-llvm-8/Dockerfile#L42) describing a hack (which I don't quite understand) which was also blocked by not having LLVM 9.
This commit is contained in:
Dylan DPC 2020-11-15 03:02:39 +01:00 committed by GitHub
commit ae7020fcb4
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
13 changed files with 15 additions and 100 deletions

View file

@ -43,7 +43,7 @@ jobs:
- name: mingw-check - name: mingw-check
os: ubuntu-latest-xl os: ubuntu-latest-xl
env: {} env: {}
- name: x86_64-gnu-llvm-8 - name: x86_64-gnu-llvm-9
os: ubuntu-latest-xl os: ubuntu-latest-xl
env: {} env: {}
- name: x86_64-gnu-tools - name: x86_64-gnu-tools
@ -265,7 +265,7 @@ jobs:
- name: x86_64-gnu-distcheck - name: x86_64-gnu-distcheck
os: ubuntu-latest-xl os: ubuntu-latest-xl
env: {} env: {}
- name: x86_64-gnu-llvm-8 - name: x86_64-gnu-llvm-9
env: env:
RUST_BACKTRACE: 1 RUST_BACKTRACE: 1
os: ubuntu-latest-xl os: ubuntu-latest-xl

View file

@ -144,25 +144,6 @@ fn set_probestack(cx: &CodegenCx<'ll, '_>, llfn: &'ll Value) {
); );
} }
fn translate_obsolete_target_features(feature: &str) -> &str {
const LLVM9_FEATURE_CHANGES: &[(&str, &str)] =
&[("+fp-only-sp", "-fp64"), ("-fp-only-sp", "+fp64"), ("+d16", "-d32"), ("-d16", "+d32")];
if llvm_util::get_major_version() >= 9 {
for &(old, new) in LLVM9_FEATURE_CHANGES {
if feature == old {
return new;
}
}
} else {
for &(old, new) in LLVM9_FEATURE_CHANGES {
if feature == new {
return old;
}
}
}
feature
}
pub fn llvm_target_features(sess: &Session) -> impl Iterator<Item = &str> { pub fn llvm_target_features(sess: &Session) -> impl Iterator<Item = &str> {
const RUSTC_SPECIFIC_FEATURES: &[&str] = &["crt-static"]; const RUSTC_SPECIFIC_FEATURES: &[&str] = &["crt-static"];
@ -172,12 +153,7 @@ pub fn llvm_target_features(sess: &Session) -> impl Iterator<Item = &str> {
.target_feature .target_feature
.split(',') .split(',')
.filter(|f| !RUSTC_SPECIFIC_FEATURES.iter().any(|s| f.contains(s))); .filter(|f| !RUSTC_SPECIFIC_FEATURES.iter().any(|s| f.contains(s)));
sess.target sess.target.features.split(',').chain(cmdline).filter(|l| !l.is_empty())
.features
.split(',')
.chain(cmdline)
.filter(|l| !l.is_empty())
.map(translate_obsolete_target_features)
} }
pub fn apply_target_cpu_attr(cx: &CodegenCx<'ll, '_>, llfn: &'ll Value) { pub fn apply_target_cpu_attr(cx: &CodegenCx<'ll, '_>, llfn: &'ll Value) {

View file

@ -377,11 +377,6 @@ fn get_pgo_use_path(config: &ModuleConfig) -> Option<CString> {
} }
pub(crate) fn should_use_new_llvm_pass_manager(config: &ModuleConfig) -> bool { pub(crate) fn should_use_new_llvm_pass_manager(config: &ModuleConfig) -> bool {
// We only support the new pass manager starting with LLVM 9.
if llvm_util::get_major_version() < 9 {
return false;
}
// The new pass manager is disabled by default. // The new pass manager is disabled by default.
config.new_llvm_pass_manager config.new_llvm_pass_manager
} }

View file

@ -100,11 +100,6 @@ fn to_llvm_tls_model(tls_model: TlsModel) -> llvm::ThreadLocalMode {
} }
} }
fn strip_function_ptr_alignment(data_layout: String) -> String {
// FIXME: Make this more general.
data_layout.replace("-Fi8-", "-")
}
fn strip_x86_address_spaces(data_layout: String) -> String { fn strip_x86_address_spaces(data_layout: String) -> String {
data_layout.replace("-p270:32:32-p271:32:32-p272:64:64-", "-") data_layout.replace("-p270:32:32-p271:32:32-p272:64:64-", "-")
} }
@ -119,9 +114,6 @@ pub unsafe fn create_module(
let llmod = llvm::LLVMModuleCreateWithNameInContext(mod_name.as_ptr(), llcx); let llmod = llvm::LLVMModuleCreateWithNameInContext(mod_name.as_ptr(), llcx);
let mut target_data_layout = sess.target.data_layout.clone(); let mut target_data_layout = sess.target.data_layout.clone();
if llvm_util::get_major_version() < 9 {
target_data_layout = strip_function_ptr_alignment(target_data_layout);
}
if llvm_util::get_major_version() < 10 if llvm_util::get_major_version() < 10
&& (sess.target.arch == "x86" || sess.target.arch == "x86_64") && (sess.target.arch == "x86" || sess.target.arch == "x86_64")
{ {

View file

@ -104,7 +104,7 @@ unsafe fn configure_llvm(sess: &Session) {
} }
} }
if sess.opts.debugging_opts.llvm_time_trace && get_major_version() >= 9 { if sess.opts.debugging_opts.llvm_time_trace {
// time-trace is not thread safe and running it in parallel will cause seg faults. // time-trace is not thread safe and running it in parallel will cause seg faults.
if !sess.opts.debugging_opts.no_parallel_llvm { if !sess.opts.debugging_opts.no_parallel_llvm {
bug!("`-Z llvm-time-trace` requires `-Z no-parallel-llvm") bug!("`-Z llvm-time-trace` requires `-Z no-parallel-llvm")
@ -122,10 +122,8 @@ unsafe fn configure_llvm(sess: &Session) {
pub fn time_trace_profiler_finish(file_name: &str) { pub fn time_trace_profiler_finish(file_name: &str) {
unsafe { unsafe {
if get_major_version() >= 9 { let file_name = CString::new(file_name).unwrap();
let file_name = CString::new(file_name).unwrap(); llvm::LLVMTimeTraceProfilerFinish(file_name.as_ptr());
llvm::LLVMTimeTraceProfilerFinish(file_name.as_ptr());
}
} }
} }

View file

@ -16,9 +16,7 @@
#include "llvm/Object/ObjectFile.h" #include "llvm/Object/ObjectFile.h"
#include "llvm/Object/IRObjectFile.h" #include "llvm/Object/IRObjectFile.h"
#include "llvm/Passes/PassBuilder.h" #include "llvm/Passes/PassBuilder.h"
#if LLVM_VERSION_GE(9, 0)
#include "llvm/Passes/StandardInstrumentations.h" #include "llvm/Passes/StandardInstrumentations.h"
#endif
#include "llvm/Support/CBindingWrapping.h" #include "llvm/Support/CBindingWrapping.h"
#include "llvm/Support/FileSystem.h" #include "llvm/Support/FileSystem.h"
#include "llvm/Support/Host.h" #include "llvm/Support/Host.h"
@ -31,15 +29,11 @@
#include "llvm-c/Transforms/PassManagerBuilder.h" #include "llvm-c/Transforms/PassManagerBuilder.h"
#include "llvm/Transforms/Instrumentation.h" #include "llvm/Transforms/Instrumentation.h"
#if LLVM_VERSION_GE(9, 0)
#include "llvm/Transforms/Instrumentation/AddressSanitizer.h" #include "llvm/Transforms/Instrumentation/AddressSanitizer.h"
#include "llvm/Support/TimeProfiler.h" #include "llvm/Support/TimeProfiler.h"
#endif
#include "llvm/Transforms/Instrumentation/ThreadSanitizer.h" #include "llvm/Transforms/Instrumentation/ThreadSanitizer.h"
#include "llvm/Transforms/Instrumentation/MemorySanitizer.h" #include "llvm/Transforms/Instrumentation/MemorySanitizer.h"
#if LLVM_VERSION_GE(9, 0)
#include "llvm/Transforms/Utils/CanonicalizeAliases.h" #include "llvm/Transforms/Utils/CanonicalizeAliases.h"
#endif
#include "llvm/Transforms/Utils/NameAnonGlobals.h" #include "llvm/Transforms/Utils/NameAnonGlobals.h"
using namespace llvm; using namespace llvm;
@ -73,20 +67,18 @@ extern "C" void LLVMTimeTraceProfilerInitialize() {
timeTraceProfilerInitialize( timeTraceProfilerInitialize(
/* TimeTraceGranularity */ 0, /* TimeTraceGranularity */ 0,
/* ProcName */ "rustc"); /* ProcName */ "rustc");
#elif LLVM_VERSION_GE(9, 0) #else
timeTraceProfilerInitialize(); timeTraceProfilerInitialize();
#endif #endif
} }
extern "C" void LLVMTimeTraceProfilerFinish(const char* FileName) { extern "C" void LLVMTimeTraceProfilerFinish(const char* FileName) {
#if LLVM_VERSION_GE(9, 0)
StringRef FN(FileName); StringRef FN(FileName);
std::error_code EC; std::error_code EC;
raw_fd_ostream OS(FN, EC, sys::fs::CD_CreateAlways); raw_fd_ostream OS(FN, EC, sys::fs::CD_CreateAlways);
timeTraceProfilerWrite(OS); timeTraceProfilerWrite(OS);
timeTraceProfilerCleanup(); timeTraceProfilerCleanup();
#endif
} }
enum class LLVMRustPassKind { enum class LLVMRustPassKind {
@ -127,22 +119,14 @@ extern "C" LLVMPassRef LLVMRustCreateAddressSanitizerFunctionPass(bool Recover)
extern "C" LLVMPassRef LLVMRustCreateModuleAddressSanitizerPass(bool Recover) { extern "C" LLVMPassRef LLVMRustCreateModuleAddressSanitizerPass(bool Recover) {
const bool CompileKernel = false; const bool CompileKernel = false;
#if LLVM_VERSION_GE(9, 0)
return wrap(createModuleAddressSanitizerLegacyPassPass(CompileKernel, Recover)); return wrap(createModuleAddressSanitizerLegacyPassPass(CompileKernel, Recover));
#else
return wrap(createAddressSanitizerModulePass(CompileKernel, Recover));
#endif
} }
extern "C" LLVMPassRef LLVMRustCreateMemorySanitizerPass(int TrackOrigins, bool Recover) { extern "C" LLVMPassRef LLVMRustCreateMemorySanitizerPass(int TrackOrigins, bool Recover) {
#if LLVM_VERSION_GE(9, 0)
const bool CompileKernel = false; const bool CompileKernel = false;
return wrap(createMemorySanitizerLegacyPassPass( return wrap(createMemorySanitizerLegacyPassPass(
MemorySanitizerOptions{TrackOrigins, Recover, CompileKernel})); MemorySanitizerOptions{TrackOrigins, Recover, CompileKernel}));
#else
return wrap(createMemorySanitizerLegacyPassPass(TrackOrigins, Recover));
#endif
} }
extern "C" LLVMPassRef LLVMRustCreateThreadSanitizerPass() { extern "C" LLVMPassRef LLVMRustCreateThreadSanitizerPass() {
@ -657,8 +641,6 @@ extern "C" typedef void (*LLVMRustSelfProfileBeforePassCallback)(void*, // LlvmS
const char*); // IR name const char*); // IR name
extern "C" typedef void (*LLVMRustSelfProfileAfterPassCallback)(void*); // LlvmSelfProfiler extern "C" typedef void (*LLVMRustSelfProfileAfterPassCallback)(void*); // LlvmSelfProfiler
#if LLVM_VERSION_GE(9, 0)
std::string LLVMRustwrappedIrGetName(const llvm::Any &WrappedIr) { std::string LLVMRustwrappedIrGetName(const llvm::Any &WrappedIr) {
if (any_isa<const Module *>(WrappedIr)) if (any_isa<const Module *>(WrappedIr))
return any_cast<const Module *>(WrappedIr)->getName().str(); return any_cast<const Module *>(WrappedIr)->getName().str();
@ -706,7 +688,6 @@ void LLVMSelfProfileInitializeCallbacks(
AfterPassCallback(LlvmSelfProfiler); AfterPassCallback(LlvmSelfProfiler);
}); });
} }
#endif
enum class LLVMRustOptStage { enum class LLVMRustOptStage {
PreLinkNoLTO, PreLinkNoLTO,
@ -739,7 +720,6 @@ LLVMRustOptimizeWithNewPassManager(
void* LlvmSelfProfiler, void* LlvmSelfProfiler,
LLVMRustSelfProfileBeforePassCallback BeforePassCallback, LLVMRustSelfProfileBeforePassCallback BeforePassCallback,
LLVMRustSelfProfileAfterPassCallback AfterPassCallback) { LLVMRustSelfProfileAfterPassCallback AfterPassCallback) {
#if LLVM_VERSION_GE(9, 0)
Module *TheModule = unwrap(ModuleRef); Module *TheModule = unwrap(ModuleRef);
TargetMachine *TM = unwrap(TMRef); TargetMachine *TM = unwrap(TMRef);
PassBuilder::OptimizationLevel OptLevel = fromRust(OptLevelRust); PassBuilder::OptimizationLevel OptLevel = fromRust(OptLevelRust);
@ -970,11 +950,6 @@ LLVMRustOptimizeWithNewPassManager(
UpgradeCallsToIntrinsic(&*I++); // must be post-increment, as we remove UpgradeCallsToIntrinsic(&*I++); // must be post-increment, as we remove
MPM.run(*TheModule, MAM); MPM.run(*TheModule, MAM);
#else
// The new pass manager has been available for a long time,
// but we don't bother supporting it on old LLVM versions.
report_fatal_error("New pass manager only supported since LLVM 9");
#endif
} }
// Callback to demangle function name // Callback to demangle function name
@ -1325,12 +1300,9 @@ LLVMRustCreateThinLTOData(LLVMRustThinLTOModule *modules,
GlobalValue::LinkageTypes NewLinkage) { GlobalValue::LinkageTypes NewLinkage) {
Ret->ResolvedODR[ModuleIdentifier][GUID] = NewLinkage; Ret->ResolvedODR[ModuleIdentifier][GUID] = NewLinkage;
}; };
#if LLVM_VERSION_GE(9, 0)
thinLTOResolvePrevailingInIndex(Ret->Index, isPrevailing, recordNewLinkage, thinLTOResolvePrevailingInIndex(Ret->Index, isPrevailing, recordNewLinkage,
Ret->GUIDPreservedSymbols); Ret->GUIDPreservedSymbols);
#else
thinLTOResolvePrevailingInIndex(Ret->Index, isPrevailing, recordNewLinkage);
#endif
// Here we calculate an `ExportedGUIDs` set for use in the `isExported` // Here we calculate an `ExportedGUIDs` set for use in the `isExported`
// callback below. This callback below will dictate the linkage for all // callback below. This callback below will dictate the linkage for all

View file

@ -124,9 +124,7 @@ extern "C" LLVMValueRef LLVMRustGetOrInsertFunction(LLVMModuleRef M,
return wrap(unwrap(M) return wrap(unwrap(M)
->getOrInsertFunction(StringRef(Name, NameLen), ->getOrInsertFunction(StringRef(Name, NameLen),
unwrap<FunctionType>(FunctionTy)) unwrap<FunctionType>(FunctionTy))
#if LLVM_VERSION_GE(9, 0)
.getCallee() .getCallee()
#endif
); );
} }
@ -251,11 +249,7 @@ extern "C" void LLVMRustAddDereferenceableOrNullCallSiteAttr(LLVMValueRef Instr,
extern "C" void LLVMRustAddByValCallSiteAttr(LLVMValueRef Instr, unsigned Index, extern "C" void LLVMRustAddByValCallSiteAttr(LLVMValueRef Instr, unsigned Index,
LLVMTypeRef Ty) { LLVMTypeRef Ty) {
CallBase *Call = unwrap<CallBase>(Instr); CallBase *Call = unwrap<CallBase>(Instr);
#if LLVM_VERSION_GE(9, 0)
Attribute Attr = Attribute::getWithByValType(Call->getContext(), unwrap(Ty)); Attribute Attr = Attribute::getWithByValType(Call->getContext(), unwrap(Ty));
#else
Attribute Attr = Attribute::get(Call->getContext(), Attribute::ByVal);
#endif
Call->addAttribute(Index, Attr); Call->addAttribute(Index, Attr);
} }
@ -296,11 +290,7 @@ extern "C" void LLVMRustAddDereferenceableOrNullAttr(LLVMValueRef Fn,
extern "C" void LLVMRustAddByValAttr(LLVMValueRef Fn, unsigned Index, extern "C" void LLVMRustAddByValAttr(LLVMValueRef Fn, unsigned Index,
LLVMTypeRef Ty) { LLVMTypeRef Ty) {
Function *F = unwrap<Function>(Fn); Function *F = unwrap<Function>(Fn);
#if LLVM_VERSION_GE(9, 0)
Attribute Attr = Attribute::getWithByValType(F->getContext(), unwrap(Ty)); Attribute Attr = Attribute::getWithByValType(F->getContext(), unwrap(Ty));
#else
Attribute Attr = Attribute::get(F->getContext(), Attribute::ByVal);
#endif
F->addAttribute(Index, Attr); F->addAttribute(Index, Attr);
} }
@ -616,11 +606,9 @@ static DISubprogram::DISPFlags fromRust(LLVMRustDISPFlags SPFlags) {
if (isSet(SPFlags & LLVMRustDISPFlags::SPFlagOptimized)) { if (isSet(SPFlags & LLVMRustDISPFlags::SPFlagOptimized)) {
Result |= DISubprogram::DISPFlags::SPFlagOptimized; Result |= DISubprogram::DISPFlags::SPFlagOptimized;
} }
#if LLVM_VERSION_GE(9, 0)
if (isSet(SPFlags & LLVMRustDISPFlags::SPFlagMainSubprogram)) { if (isSet(SPFlags & LLVMRustDISPFlags::SPFlagMainSubprogram)) {
Result |= DISubprogram::DISPFlags::SPFlagMainSubprogram; Result |= DISubprogram::DISPFlags::SPFlagMainSubprogram;
} }
#endif
return Result; return Result;
} }
@ -744,10 +732,6 @@ extern "C" LLVMMetadataRef LLVMRustDIBuilderCreateFunction(
DITemplateParameterArray(unwrap<MDTuple>(TParam)); DITemplateParameterArray(unwrap<MDTuple>(TParam));
DISubprogram::DISPFlags llvmSPFlags = fromRust(SPFlags); DISubprogram::DISPFlags llvmSPFlags = fromRust(SPFlags);
DINode::DIFlags llvmFlags = fromRust(Flags); DINode::DIFlags llvmFlags = fromRust(Flags);
#if LLVM_VERSION_LT(9, 0)
if (isSet(SPFlags & LLVMRustDISPFlags::SPFlagMainSubprogram))
llvmFlags |= DINode::DIFlags::FlagMainSubprogram;
#endif
DISubprogram *Sub = Builder->createFunction( DISubprogram *Sub = Builder->createFunction(
unwrapDI<DIScope>(Scope), unwrapDI<DIScope>(Scope),
StringRef(Name, NameLen), StringRef(Name, NameLen),

View file

@ -348,11 +348,11 @@ fn check_llvm_version(builder: &Builder<'_>, llvm_config: &Path) {
let version = output(cmd.arg("--version")); let version = output(cmd.arg("--version"));
let mut parts = version.split('.').take(2).filter_map(|s| s.parse::<u32>().ok()); let mut parts = version.split('.').take(2).filter_map(|s| s.parse::<u32>().ok());
if let (Some(major), Some(_minor)) = (parts.next(), parts.next()) { if let (Some(major), Some(_minor)) = (parts.next(), parts.next()) {
if major >= 8 { if major >= 9 {
return; return;
} }
} }
panic!("\n\nbad LLVM version: {}, need >=8.0\n\n", version) panic!("\n\nbad LLVM version: {}, need >=9.0\n\n", version)
} }
fn configure_cmake( fn configure_cmake(

View file

@ -13,7 +13,8 @@ RUN apt-get update && apt-get install -y --no-install-recommends \
cmake \ cmake \
sudo \ sudo \
gdb \ gdb \
llvm-8-tools \ llvm-9-tools \
llvm-9-dev \
libedit-dev \ libedit-dev \
libssl-dev \ libssl-dev \
pkg-config \ pkg-config \
@ -27,7 +28,7 @@ RUN sh /scripts/sccache.sh
# using llvm-link-shared due to libffi issues -- see #34486 # using llvm-link-shared due to libffi issues -- see #34486
ENV RUST_CONFIGURE_ARGS \ ENV RUST_CONFIGURE_ARGS \
--build=x86_64-unknown-linux-gnu \ --build=x86_64-unknown-linux-gnu \
--llvm-root=/usr/lib/llvm-8 \ --llvm-root=/usr/lib/llvm-9 \
--enable-llvm-link-shared \ --enable-llvm-link-shared \
--set rust.thin-lto-import-instr-limit=10 --set rust.thin-lto-import-instr-limit=10

View file

@ -280,7 +280,7 @@ jobs:
- name: mingw-check - name: mingw-check
<<: *job-linux-xl <<: *job-linux-xl
- name: x86_64-gnu-llvm-8 - name: x86_64-gnu-llvm-9
<<: *job-linux-xl <<: *job-linux-xl
- name: x86_64-gnu-tools - name: x86_64-gnu-tools
@ -412,7 +412,7 @@ jobs:
- name: x86_64-gnu-distcheck - name: x86_64-gnu-distcheck
<<: *job-linux-xl <<: *job-linux-xl
- name: x86_64-gnu-llvm-8 - name: x86_64-gnu-llvm-9
env: env:
RUST_BACKTRACE: 1 RUST_BACKTRACE: 1
<<: *job-linux-xl <<: *job-linux-xl

View file

@ -1,7 +1,6 @@
// Checks if the correct annotation for the efiapi ABI is passed to llvm. // Checks if the correct annotation for the efiapi ABI is passed to llvm.
// revisions:x86_64 i686 aarch64 arm riscv // revisions:x86_64 i686 aarch64 arm riscv
// min-llvm-version: 9.0
// needs-llvm-components: aarch64 arm riscv // needs-llvm-components: aarch64 arm riscv
//[x86_64] compile-flags: --target x86_64-unknown-uefi //[x86_64] compile-flags: --target x86_64-unknown-uefi

View file

@ -1,4 +1,3 @@
// min-llvm-version: 8.0
// compile-flags: -C no-prepopulate-passes -C force-unwind-tables=y // compile-flags: -C no-prepopulate-passes -C force-unwind-tables=y
#![crate_type="lib"] #![crate_type="lib"]

View file

@ -2,7 +2,6 @@
// being run when compiling with new LLVM pass manager and ThinLTO. // being run when compiling with new LLVM pass manager and ThinLTO.
// Note: The issue occurred only on non-zero opt-level. // Note: The issue occurred only on non-zero opt-level.
// //
// min-llvm-version: 9.0
// needs-sanitizer-support // needs-sanitizer-support
// needs-sanitizer-address // needs-sanitizer-address
// //