Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update the minimum external LLVM to 14 #107573

Merged
merged 2 commits into from Feb 15, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
8 changes: 2 additions & 6 deletions .github/workflows/ci.yml
Expand Up @@ -54,7 +54,7 @@ jobs:
tidy: true
os: ubuntu-20.04-xl
env: {}
- name: x86_64-gnu-llvm-13
- name: x86_64-gnu-llvm-14
tidy: false
os: ubuntu-20.04-xl
env: {}
Expand Down Expand Up @@ -300,11 +300,7 @@ jobs:
env:
RUST_BACKTRACE: 1
os: ubuntu-20.04-xl
- name: x86_64-gnu-llvm-13
env:
RUST_BACKTRACE: 1
os: ubuntu-20.04-xl
- name: x86_64-gnu-llvm-13-stage1
- name: x86_64-gnu-llvm-14-stage1
env:
RUST_BACKTRACE: 1
os: ubuntu-20.04-xl
Expand Down
4 changes: 2 additions & 2 deletions Cargo.lock
Expand Up @@ -883,9 +883,9 @@ dependencies = [

[[package]]
name = "compiler_builtins"
version = "0.1.85"
version = "0.1.87"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "13e81c6cd7ab79f51a0c927d22858d61ad12bd0b3865f0b13ece02a4486aeabb"
checksum = "f867ce54c09855ccd135ad4a50c777182a0c7af5ff20a8f537617bd648b10d50"
dependencies = [
"cc",
"rustc-std-workspace-core",
Expand Down
9 changes: 1 addition & 8 deletions compiler/rustc_codegen_llvm/src/consts.rs
Expand Up @@ -3,7 +3,6 @@ use crate::common::{self, CodegenCx};
use crate::debuginfo;
use crate::errors::{InvalidMinimumAlignment, SymbolAlreadyDefined};
use crate::llvm::{self, True};
use crate::llvm_util;
use crate::type_::Type;
use crate::type_of::LayoutLlvmExt;
use crate::value::Value;
Expand Down Expand Up @@ -56,13 +55,7 @@ pub fn const_alloc_to_llvm<'ll>(cx: &CodegenCx<'ll, '_>, alloc: ConstAllocation<
// to avoid the cost of generating large complex const expressions.
// For example, `[(u32, u8); 1024 * 1024]` contains uninit padding in each element,
// and would result in `{ [5 x i8] zeroinitializer, [3 x i8] undef, ...repeat 1M times... }`.
let max = if llvm_util::get_version() < (14, 0, 0) {
// Generating partially-uninit consts inhibits optimizations in LLVM < 14.
// See https://github.com/rust-lang/rust/issues/84565.
1
} else {
cx.sess().opts.unstable_opts.uninit_const_chunk_threshold
};
let max = cx.sess().opts.unstable_opts.uninit_const_chunk_threshold;
let allow_uninit_chunks = chunks.clone().take(max.saturating_add(1)).count() <= max;

if allow_uninit_chunks {
Expand Down
11 changes: 0 additions & 11 deletions compiler/rustc_codegen_llvm/src/context.rs
Expand Up @@ -143,17 +143,6 @@ pub unsafe fn create_module<'ll>(

let mut target_data_layout = sess.target.data_layout.to_string();
let llvm_version = llvm_util::get_version();
if llvm_version < (14, 0, 0) {
if sess.target.llvm_target == "i686-pc-windows-msvc"
|| sess.target.llvm_target == "i586-pc-windows-msvc"
{
target_data_layout =
"e-m:x-p:32:32-p270:32:32-p271:32:32-p272:64:64-i64:64-f80:32-n8:16:32-a:0:32-S32"
.to_string();
} else if sess.target.arch == "wasm32" {
target_data_layout = target_data_layout.replace("-p10:8:8-p20:8:8", "");
}
}
if llvm_version < (16, 0, 0) {
if sess.target.arch == "s390x" {
target_data_layout = target_data_layout.replace("-v128:64", "");
Expand Down
26 changes: 3 additions & 23 deletions compiler/rustc_codegen_llvm/src/llvm_util.rs
Expand Up @@ -152,13 +152,7 @@ pub fn time_trace_profiler_finish(file_name: &Path) {
pub fn to_llvm_features<'a>(sess: &Session, s: &'a str) -> SmallVec<[&'a str; 2]> {
let arch = if sess.target.arch == "x86_64" { "x86" } else { &*sess.target.arch };
match (arch, s) {
("x86", "sse4.2") => {
if get_version() >= (14, 0, 0) {
smallvec!["sse4.2", "crc32"]
} else {
smallvec!["sse4.2"]
}
}
("x86", "sse4.2") => smallvec!["sse4.2", "crc32"],
("x86", "pclmulqdq") => smallvec!["pclmul"],
("x86", "rdrand") => smallvec!["rdrnd"],
("x86", "bmi1") => smallvec!["bmi"],
Expand Down Expand Up @@ -217,7 +211,7 @@ pub fn check_tied_features(
/// Must express features in the way Rust understands them
pub fn target_features(sess: &Session, allow_unstable: bool) -> Vec<Symbol> {
let target_machine = create_informational_target_machine(sess);
let mut features: Vec<Symbol> = supported_target_features(sess)
supported_target_features(sess)
.iter()
.filter_map(|&(feature, gate)| {
if sess.is_nightly_build() || allow_unstable || gate.is_none() {
Expand All @@ -237,16 +231,7 @@ pub fn target_features(sess: &Session, allow_unstable: bool) -> Vec<Symbol> {
true
})
.map(|feature| Symbol::intern(feature))
.collect();

// LLVM 14 changed the ABI for i128 arguments to __float/__fix builtins on Win64
// (see https://reviews.llvm.org/D110413). This unstable target feature is intended for use
// by compiler-builtins, to export the builtins with the expected, LLVM-version-dependent ABI.
// The target feature can be dropped once we no longer support older LLVM versions.
if sess.is_nightly_build() && get_version() >= (14, 0, 0) {
features.push(Symbol::intern("llvm14-builtins-abi"));
}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

So this is somewhat unfortunate in that this introduces a constraint on the version of compiler-builtins that works with the new version of LLVM due to how this feature was set up (rather than enabling the behaviour for old LLVM versions it enables the behaviour for the new LLVM versions). I wonder if it would make sense to keep setting this feature for a little longer…? Maybe I’m overthinking this and nobody is really depending on the crate except for rustc?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The risk would be using an older version of compiler_builtins with a nightly where we've removed this feature -- but I think that's kind of par for the course with nightly crates. It looks like most of the reverse dependencies are just for rustc-std-workspace hacking, but I'm not sure.

features
.collect()
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If my memory serves me right, addition of the special case caused this function to start returning a Vec<_> so now that we no longer support the old LLVM this can return the iterator…

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That addition was commit 0605a41, so no, it was already returning a Vec<Symbol> before that. It's passed back in trait CodegenBackend::target_features, so we'd have to use TAIT to return impl Iterator there.

}

pub fn print_version() {
Expand Down Expand Up @@ -494,11 +479,6 @@ pub(crate) fn global_llvm_features(sess: &Session, diagnostics: bool) -> Vec<Str
.flatten();
features.extend(feats);

// FIXME: Move v8a to target definition list when earliest supported LLVM is 14.
if get_version() >= (14, 0, 0) && sess.target.arch == "aarch64" {
features.push("+v8a".into());
}

if diagnostics && let Some(f) = check_tied_features(sess, &featsmap) {
sess.emit_err(TargetFeatureDisableOrEnable {
features: f,
Expand Down
7 changes: 2 additions & 5 deletions compiler/rustc_codegen_llvm/src/type_of.rs
@@ -1,6 +1,5 @@
use crate::common::*;
use crate::context::TypeLowering;
use crate::llvm_util::get_version;
use crate::type_::Type;
use rustc_codegen_ssa::traits::*;
use rustc_middle::bug;
Expand Down Expand Up @@ -43,10 +42,8 @@ fn uncached_llvm_type<'a, 'tcx>(
// in problematically distinct types due to HRTB and subtyping (see #47638).
// ty::Dynamic(..) |
ty::Adt(..) | ty::Closure(..) | ty::Foreign(..) | ty::Generator(..) | ty::Str
// For performance reasons we use names only when emitting LLVM IR. Unless we are on
// LLVM < 14, where the use of unnamed types resulted in various issues, e.g., #76213,
// #79564, and #79246.
if get_version() < (14, 0, 0) || !cx.sess().fewer_names() =>
// For performance reasons we use names only when emitting LLVM IR.
if !cx.sess().fewer_names() =>
{
let mut name = with_no_visible_paths!(with_no_trimmed_paths!(layout.ty.to_string()));
if let (&ty::Adt(def, _), &Variants::Single { index }) =
Expand Down
44 changes: 3 additions & 41 deletions compiler/rustc_llvm/llvm-wrapper/PassWrapper.cpp
Expand Up @@ -14,6 +14,7 @@
#include "llvm/IR/AssemblyAnnotationWriter.h"
#include "llvm/IR/IntrinsicInst.h"
#include "llvm/IR/Verifier.h"
#include "llvm/MC/TargetRegistry.h"
#include "llvm/Object/ObjectFile.h"
#include "llvm/Object/IRObjectFile.h"
#include "llvm/Passes/PassBuilder.h"
Expand All @@ -25,11 +26,6 @@
#include "llvm/Support/VirtualFileSystem.h"
#endif
#include "llvm/Support/Host.h"
#if LLVM_VERSION_LT(14, 0)
#include "llvm/Support/TargetRegistry.h"
#else
#include "llvm/MC/TargetRegistry.h"
#endif
#include "llvm/Target/TargetMachine.h"
#include "llvm/Transforms/IPO/PassManagerBuilder.h"
#include "llvm/Transforms/IPO/AlwaysInliner.h"
Expand Down Expand Up @@ -267,10 +263,6 @@ enum class LLVMRustPassBuilderOptLevel {
Oz,
};

#if LLVM_VERSION_LT(14,0)
using OptimizationLevel = PassBuilder::OptimizationLevel;
#endif

static OptimizationLevel fromRust(LLVMRustPassBuilderOptLevel Level) {
switch (Level) {
case LLVMRustPassBuilderOptLevel::O0:
Expand Down Expand Up @@ -747,27 +739,18 @@ LLVMRustOptimize(

if (SanitizerOptions) {
if (SanitizerOptions->SanitizeMemory) {
#if LLVM_VERSION_GE(14, 0)
MemorySanitizerOptions Options(
SanitizerOptions->SanitizeMemoryTrackOrigins,
SanitizerOptions->SanitizeMemoryRecover,
/*CompileKernel=*/false,
/*EagerChecks=*/true);
#else
MemorySanitizerOptions Options(
SanitizerOptions->SanitizeMemoryTrackOrigins,
SanitizerOptions->SanitizeMemoryRecover,
/*CompileKernel=*/false);
#endif
OptimizerLastEPCallbacks.push_back(
[Options](ModulePassManager &MPM, OptimizationLevel Level) {
#if LLVM_VERSION_GE(14, 0) && LLVM_VERSION_LT(16, 0)
#if LLVM_VERSION_LT(16, 0)
MPM.addPass(ModuleMemorySanitizerPass(Options));
MPM.addPass(createModuleToFunctionPassAdaptor(MemorySanitizerPass(Options)));
#else
MPM.addPass(MemorySanitizerPass(Options));
#endif
#if LLVM_VERSION_LT(16, 0)
MPM.addPass(createModuleToFunctionPassAdaptor(MemorySanitizerPass(Options)));
#endif
}
);
Expand All @@ -776,11 +759,7 @@ LLVMRustOptimize(
if (SanitizerOptions->SanitizeThread) {
OptimizerLastEPCallbacks.push_back(
[](ModulePassManager &MPM, OptimizationLevel Level) {
#if LLVM_VERSION_GE(14, 0)
MPM.addPass(ModuleThreadSanitizerPass());
#else
MPM.addPass(ThreadSanitizerPass());
#endif
MPM.addPass(createModuleToFunctionPassAdaptor(ThreadSanitizerPass()));
}
);
Expand All @@ -792,7 +771,6 @@ LLVMRustOptimize(
#if LLVM_VERSION_LT(15, 0)
MPM.addPass(RequireAnalysisPass<ASanGlobalsMetadataAnalysis, Module>());
#endif
#if LLVM_VERSION_GE(14, 0)
AddressSanitizerOptions opts = AddressSanitizerOptions{
/*CompileKernel=*/false,
SanitizerOptions->SanitizeAddressRecover,
Expand All @@ -803,29 +781,17 @@ LLVMRustOptimize(
MPM.addPass(ModuleAddressSanitizerPass(opts));
#else
MPM.addPass(AddressSanitizerPass(opts));
#endif
#else
MPM.addPass(ModuleAddressSanitizerPass(
/*CompileKernel=*/false, SanitizerOptions->SanitizeAddressRecover));
MPM.addPass(createModuleToFunctionPassAdaptor(AddressSanitizerPass(
/*CompileKernel=*/false, SanitizerOptions->SanitizeAddressRecover,
/*UseAfterScope=*/true)));
#endif
}
);
}
if (SanitizerOptions->SanitizeHWAddress) {
OptimizerLastEPCallbacks.push_back(
[SanitizerOptions](ModulePassManager &MPM, OptimizationLevel Level) {
#if LLVM_VERSION_GE(14, 0)
HWAddressSanitizerOptions opts(
/*CompileKernel=*/false, SanitizerOptions->SanitizeHWAddressRecover,
/*DisableOptimization=*/false);
MPM.addPass(HWAddressSanitizerPass(opts));
#else
MPM.addPass(HWAddressSanitizerPass(
/*CompileKernel=*/false, SanitizerOptions->SanitizeHWAddressRecover));
#endif
}
);
}
Expand Down Expand Up @@ -1328,11 +1294,7 @@ extern "C" bool
LLVMRustPrepareThinLTOResolveWeak(const LLVMRustThinLTOData *Data, LLVMModuleRef M) {
Module &Mod = *unwrap(M);
const auto &DefinedGlobals = Data->ModuleToDefinedGVSummaries.lookup(Mod.getModuleIdentifier());
#if LLVM_VERSION_GE(14, 0)
thinLTOFinalizeInModule(Mod, DefinedGlobals, /*PropagateAttrs=*/true);
#else
thinLTOResolvePrevailingInModule(Mod, DefinedGlobals);
#endif
return true;
}

Expand Down
14 changes: 1 addition & 13 deletions compiler/rustc_llvm/llvm-wrapper/RustWrapper.cpp
Expand Up @@ -63,11 +63,7 @@ static LLVM_THREAD_LOCAL char *LastError;
//
// Notably it exits the process with code 101, unlike LLVM's default of 1.
static void FatalErrorHandler(void *UserData,
#if LLVM_VERSION_LT(14, 0)
const std::string& Reason,
#else
const char* Reason,
#endif
bool GenCrashDiag) {
// Do the same thing that the default error handler does.
std::cerr << "LLVM ERROR: " << Reason << std::endl;
Expand Down Expand Up @@ -249,18 +245,10 @@ static Attribute::AttrKind fromRust(LLVMRustAttribute Kind) {
template<typename T> static inline void AddAttributes(T *t, unsigned Index,
LLVMAttributeRef *Attrs, size_t AttrsLen) {
AttributeList PAL = t->getAttributes();
AttributeList PALNew;
#if LLVM_VERSION_LT(14, 0)
AttrBuilder B;
for (LLVMAttributeRef Attr : makeArrayRef(Attrs, AttrsLen))
B.addAttribute(unwrap(Attr));
PALNew = PAL.addAttributes(t->getContext(), Index, B);
#else
AttrBuilder B(t->getContext());
for (LLVMAttributeRef Attr : ArrayRef<LLVMAttributeRef>(Attrs, AttrsLen))
B.addAttribute(unwrap(Attr));
PALNew = PAL.addAttributesAtIndex(t->getContext(), Index, B);
#endif
AttributeList PALNew = PAL.addAttributesAtIndex(t->getContext(), Index, B);
t->setAttributes(PALNew);
}

Expand Down
Expand Up @@ -8,7 +8,7 @@ pub fn target() -> Target {
data_layout: "E-m:e-i8:8:32-i16:16:32-i64:64-i128:128-n32:64-S128".into(),
arch: "aarch64".into(),
options: TargetOptions {
features: "+outline-atomics".into(),
features: "+v8a,+outline-atomics".into(),
max_atomic_width: Some(128),
mcount: "\u{1}_mcount".into(),
endian: Endian::Big,
Expand Down
Expand Up @@ -12,7 +12,7 @@ pub fn target() -> Target {
arch: "aarch64".into(),
options: TargetOptions {
abi: "ilp32".into(),
features: "+outline-atomics".into(),
features: "+v8a,+outline-atomics".into(),
mcount: "\u{1}_mcount".into(),
endian: Endian::Big,
..base
Expand Down
2 changes: 1 addition & 1 deletion compiler/rustc_target/src/spec/aarch64_kmc_solid_asp3.rs
Expand Up @@ -9,7 +9,7 @@ pub fn target() -> Target {
arch: "aarch64".into(),
options: TargetOptions {
linker: Some("aarch64-kmc-elf-gcc".into()),
features: "+neon,+fp-armv8".into(),
features: "+v8a,+neon,+fp-armv8".into(),
relocation_model: RelocModel::Static,
disable_redzone: true,
max_atomic_width: Some(128),
Expand Down
2 changes: 1 addition & 1 deletion compiler/rustc_target/src/spec/aarch64_linux_android.rs
Expand Up @@ -13,7 +13,7 @@ pub fn target() -> Target {
max_atomic_width: Some(128),
// As documented in https://developer.android.com/ndk/guides/cpu-features.html
// the neon (ASIMD) and FP must exist on all android aarch64 targets.
features: "+neon,+fp-armv8".into(),
features: "+v8a,+neon,+fp-armv8".into(),
supported_sanitizers: SanitizerSet::CFI
| SanitizerSet::HWADDRESS
| SanitizerSet::MEMTAG
Expand Down
Expand Up @@ -10,6 +10,7 @@ pub fn target() -> Target {
data_layout: "e-m:e-i8:8:32-i16:16:32-i64:64-i128:128-n32:64-S128".into(),
arch: "aarch64".into(),
options: TargetOptions {
features: "+v8a".into(),
linker_flavor: LinkerFlavor::Gnu(Cc::No, Lld::Yes),
linker: Some("rust-lld".into()),
link_script: Some(LINKER_SCRIPT.into()),
Expand Down
Expand Up @@ -3,7 +3,7 @@ use crate::spec::Target;
pub fn target() -> Target {
let mut base = super::windows_gnullvm_base::opts();
base.max_atomic_width = Some(128);
base.features = "+neon,+fp-armv8".into();
base.features = "+v8a,+neon,+fp-armv8".into();
base.linker = Some("aarch64-w64-mingw32-clang".into());

Target {
Expand Down
2 changes: 1 addition & 1 deletion compiler/rustc_target/src/spec/aarch64_pc_windows_msvc.rs
Expand Up @@ -3,7 +3,7 @@ use crate::spec::Target;
pub fn target() -> Target {
let mut base = super::windows_msvc_base::opts();
base.max_atomic_width = Some(128);
base.features = "+neon,+fp-armv8".into();
base.features = "+v8a,+neon,+fp-armv8".into();

Target {
llvm_target: "aarch64-pc-windows-msvc".into(),
Expand Down
1 change: 1 addition & 0 deletions compiler/rustc_target/src/spec/aarch64_unknown_freebsd.rs
Expand Up @@ -7,6 +7,7 @@ pub fn target() -> Target {
data_layout: "e-m:e-i8:8:32-i16:16:32-i64:64-i128:128-n32:64-S128".into(),
arch: "aarch64".into(),
options: TargetOptions {
features: "+v8a".into(),
max_atomic_width: Some(128),
supported_sanitizers: SanitizerSet::ADDRESS
| SanitizerSet::CFI
Expand Down
1 change: 1 addition & 0 deletions compiler/rustc_target/src/spec/aarch64_unknown_fuchsia.rs
Expand Up @@ -7,6 +7,7 @@ pub fn target() -> Target {
data_layout: "e-m:e-i8:8:32-i16:16:32-i64:64-i128:128-n32:64-S128".into(),
arch: "aarch64".into(),
options: TargetOptions {
features: "+v8a".into(),
max_atomic_width: Some(128),
supported_sanitizers: SanitizerSet::ADDRESS
| SanitizerSet::CFI
Expand Down
2 changes: 1 addition & 1 deletion compiler/rustc_target/src/spec/aarch64_unknown_hermit.rs
Expand Up @@ -3,7 +3,7 @@ use crate::spec::Target;
pub fn target() -> Target {
let mut base = super::hermit_base::opts();
base.max_atomic_width = Some(128);
base.features = "+strict-align,+neon,+fp-armv8".into();
base.features = "+v8a,+strict-align,+neon,+fp-armv8".into();

Target {
llvm_target: "aarch64-unknown-hermit".into(),
Expand Down
Expand Up @@ -7,7 +7,7 @@ pub fn target() -> Target {
data_layout: "e-m:e-i8:8:32-i16:16:32-i64:64-i128:128-n32:64-S128".into(),
arch: "aarch64".into(),
options: TargetOptions {
features: "+outline-atomics".into(),
features: "+v8a,+outline-atomics".into(),
mcount: "\u{1}_mcount".into(),
max_atomic_width: Some(128),
supported_sanitizers: SanitizerSet::ADDRESS
Expand Down