Auto merge of #133956 - bjorn3:sync_cg_clif-2024-12-06, r=bjorn3

Sync cg clif 2024 12 06

The main highlights this time are a Cranelift update disabling the clif ir verifier by default for better performance.

r? `@ghost`

`@rustbot` label +A-codegen +A-cranelift +T-compiler
This commit is contained in:
bors 2024-12-06 15:49:11 +00:00
commit cdeddae4f6
30 changed files with 398 additions and 428 deletions

View File

@ -46,24 +46,24 @@ checksum = "baf1de4339761588bc0619e3cbc0120ee582ebb74b53b4efbf79117bd2da40fd"
[[package]]
name = "cranelift-bforest"
version = "0.113.0"
version = "0.114.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "8ea5e7afe85cadb55c4c1176268a2ac046fdff8dfaeca39e18581b9dc319ca9e"
checksum = "2ba4f80548f22dc9c43911907b5e322c5555544ee85f785115701e6a28c9abe1"
dependencies = [
"cranelift-entity",
]
[[package]]
name = "cranelift-bitset"
version = "0.113.0"
version = "0.114.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "8ab25ef3be935a80680e393183e1f94ef507e93a24a8369494d2c6818aedb3e3"
checksum = "005884e3649c3e5ff2dc79e8a94b138f11569cc08a91244a292714d2a86e9156"
[[package]]
name = "cranelift-codegen"
version = "0.113.0"
version = "0.114.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "900a19b84545924f1851cbfe386962edfc4ecbc3366a254825cf1ecbcda8ba08"
checksum = "fe4036255ec33ce9a37495dfbcfc4e1118fd34e693eff9a1e106336b7cd16a9b"
dependencies = [
"bumpalo",
"cranelift-bforest",
@ -78,48 +78,49 @@ dependencies = [
"log",
"regalloc2",
"rustc-hash",
"serde",
"smallvec",
"target-lexicon",
]
[[package]]
name = "cranelift-codegen-meta"
version = "0.113.0"
version = "0.114.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "08c73b2395ffe9e7b4fdf7e2ebc052e7e27af13f68a964985346be4da477a5fc"
checksum = "f7ca74f4b68319da11d39e894437cb6e20ec7c2e11fbbda823c3bf207beedff7"
dependencies = [
"cranelift-codegen-shared",
]
[[package]]
name = "cranelift-codegen-shared"
version = "0.113.0"
version = "0.114.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "7d9ed0854e96a4ff0879bff39d078de8dea7f002721c9494c1fdb4e1baa86ccc"
checksum = "897e54f433a0269c4187871aa06d452214d5515d228d5bdc22219585e9eef895"
[[package]]
name = "cranelift-control"
version = "0.113.0"
version = "0.114.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "b4aca921dd422e781409de0129c255768fec5dec1dae83239b497fb9138abb89"
checksum = "29cb4018f5bf59fb53f515fa9d80e6f8c5ce19f198dc538984ebd23ecf8965ec"
dependencies = [
"arbitrary",
]
[[package]]
name = "cranelift-entity"
version = "0.113.0"
version = "0.114.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "e2d770e6605eccee15b49decdd82cd26f2b6404767802471459ea49c57379a98"
checksum = "305399fd781a2953ac78c1396f02ff53144f39c33eb7fc7789cf4e8936d13a96"
dependencies = [
"cranelift-bitset",
]
[[package]]
name = "cranelift-frontend"
version = "0.113.0"
version = "0.114.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "29268711cb889cb39215b10faf88b9087d4c9e1d2633581e4f722a2bf4bb4ef9"
checksum = "9230b460a128d53653456137751d27baf567947a3ab8c0c4d6e31fd08036d81e"
dependencies = [
"cranelift-codegen",
"log",
@ -129,15 +130,15 @@ dependencies = [
[[package]]
name = "cranelift-isle"
version = "0.113.0"
version = "0.114.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "dc65156f010aed1985767ad1bff0eb8d186743b7b03e23d0c17604a253e3f356"
checksum = "b961e24ae3ec9813a24a15ae64bbd2a42e4de4d79a7f3225a412e3b94e78d1c8"
[[package]]
name = "cranelift-jit"
version = "0.113.0"
version = "0.114.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "40ba6b46367a4f466cfb1abe32793fa1a0f96d862251491b01a44726b8ed9445"
checksum = "62699329d4ced20fe281fbaef45e11b473b7ab310491b4bdebcd8b818a8ef7fe"
dependencies = [
"anyhow",
"cranelift-codegen",
@ -155,9 +156,9 @@ dependencies = [
[[package]]
name = "cranelift-module"
version = "0.113.0"
version = "0.114.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "007607022a4883ebdffc46c0925e2e10babf2a565ae78518034ade722aa825d2"
checksum = "2f20b0b51ba962dac30fc7e812b86e4390d908acd4f59bcc8ac7610a8f3e0977"
dependencies = [
"anyhow",
"cranelift-codegen",
@ -166,9 +167,9 @@ dependencies = [
[[package]]
name = "cranelift-native"
version = "0.113.0"
version = "0.114.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "d8bf9b361eaf5a7627647270fabf1dc910d993edbeaf272a652c107861ebe9c2"
checksum = "4d5bd76df6c9151188dfa428c863b33da5b34561b67f43c0cf3f24a794f9fa1f"
dependencies = [
"cranelift-codegen",
"libc",
@ -177,9 +178,9 @@ dependencies = [
[[package]]
name = "cranelift-object"
version = "0.113.0"
version = "0.114.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "30ca5c38fa00c0cd943035391bdcc84ed00748f17c66c682e410f5a62f234d44"
checksum = "ee231640a7ecceedd0f1f2782d9288db6a6908cc70675ed9427e3bf0ea6daacd"
dependencies = [
"anyhow",
"cranelift-codegen",
@ -363,6 +364,26 @@ dependencies = [
"target-lexicon",
]
[[package]]
name = "serde"
version = "1.0.210"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "c8e3592472072e6e22e0a54d5904d9febf8508f65fb8552499a1abc7d1078c3a"
dependencies = [
"serde_derive",
]
[[package]]
name = "serde_derive"
version = "1.0.210"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "243902eda00fad750862fc144cea25caca5e20d615af0a81bee94ca738f1df1f"
dependencies = [
"proc-macro2",
"quote",
"syn",
]
[[package]]
name = "slice-group-by"
version = "0.3.1"
@ -412,9 +433,9 @@ checksum = "49874b5167b65d7193b8aba1567f5c7d93d001cafc34600cee003eda787e483f"
[[package]]
name = "wasmtime-jit-icache-coherence"
version = "26.0.0"
version = "27.0.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "6e458e6a1a010a53f86ac8d75837c0c6b2ce3e54b7503b2f1dc5629a4a541f5a"
checksum = "91b218a92866f74f35162f5d03a4e0f62cd0e1cc624285b1014275e5d4575fad"
dependencies = [
"anyhow",
"cfg-if",

View File

@ -8,12 +8,12 @@ crate-type = ["dylib"]
[dependencies]
# These have to be in sync with each other
cranelift-codegen = { version = "0.113.0", default-features = false, features = ["std", "unwind", "all-native-arch"] }
cranelift-frontend = { version = "0.113.0" }
cranelift-module = { version = "0.113.0" }
cranelift-native = { version = "0.113.0" }
cranelift-jit = { version = "0.113.0", optional = true }
cranelift-object = { version = "0.113.0" }
cranelift-codegen = { version = "0.114.0", default-features = false, features = ["std", "unwind", "all-native-arch"] }
cranelift-frontend = { version = "0.114.0" }
cranelift-module = { version = "0.114.0" }
cranelift-native = { version = "0.114.0" }
cranelift-jit = { version = "0.114.0", optional = true }
cranelift-object = { version = "0.114.0" }
target-lexicon = "0.12.0"
gimli = { version = "0.31", default-features = false, features = ["write"] }
object = { version = "0.36", default-features = false, features = ["std", "read_core", "write", "archive", "coff", "elf", "macho", "pe"] }

View File

@ -1,4 +1,4 @@
use crate::path::{Dirs, RelPath};
use crate::path::Dirs;
use crate::prepare::GitRepo;
use crate::utils::{CargoProject, Compiler, spawn_and_wait};
use crate::{CodegenBackend, SysrootKind, build_sysroot};
@ -20,7 +20,7 @@ pub(crate) fn run(
rustup_toolchain_name: Option<&str>,
bootstrap_host_compiler: &Compiler,
) {
RelPath::DOWNLOAD.ensure_exists(dirs);
std::fs::create_dir_all(&dirs.download_dir).unwrap();
ABI_CAFE_REPO.fetch(dirs);
ABI_CAFE_REPO.patch(dirs);

View File

@ -3,7 +3,7 @@ use std::io::Write;
use std::path::Path;
use std::process::Command;
use crate::path::{Dirs, RelPath};
use crate::path::Dirs;
use crate::prepare::GitRepo;
use crate::rustc_info::get_file_name;
use crate::utils::{Compiler, spawn_and_wait};
@ -39,11 +39,11 @@ fn benchmark_simple_raytracer(dirs: &Dirs, bootstrap_host_compiler: &Compiler) {
};
eprintln!("[BENCH COMPILE] ebobby/simple-raytracer");
let cargo_clif = RelPath::DIST
.to_path(dirs)
let cargo_clif = dirs
.dist_dir
.join(get_file_name(&bootstrap_host_compiler.rustc, "cargo_clif", "bin").replace('_', "-"));
let manifest_path = SIMPLE_RAYTRACER_REPO.source_dir().to_path(dirs).join("Cargo.toml");
let target_dir = RelPath::BUILD.join("simple_raytracer").to_path(dirs);
let target_dir = dirs.build_dir.join("simple_raytracer");
let clean_cmd = format!(
"RUSTC=rustc cargo clean --manifest-path {manifest_path} --target-dir {target_dir}",
@ -68,7 +68,7 @@ fn benchmark_simple_raytracer(dirs: &Dirs, bootstrap_host_compiler: &Compiler) {
target_dir = target_dir.display(),
);
let bench_compile_markdown = RelPath::DIST.to_path(dirs).join("bench_compile.md");
let bench_compile_markdown = dirs.dist_dir.join("bench_compile.md");
let bench_compile = hyperfine_command(
1,
@ -92,7 +92,7 @@ fn benchmark_simple_raytracer(dirs: &Dirs, bootstrap_host_compiler: &Compiler) {
eprintln!("[BENCH RUN] ebobby/simple-raytracer");
let bench_run_markdown = RelPath::DIST.to_path(dirs).join("bench_run.md");
let bench_run_markdown = dirs.dist_dir.join("bench_run.md");
let raytracer_cg_llvm = Path::new(".").join(get_file_name(
&bootstrap_host_compiler.rustc,
@ -120,7 +120,7 @@ fn benchmark_simple_raytracer(dirs: &Dirs, bootstrap_host_compiler: &Compiler) {
],
&bench_run_markdown,
);
bench_run.current_dir(RelPath::BUILD.to_path(dirs));
bench_run.current_dir(&dirs.build_dir);
spawn_and_wait(bench_run);
if let Some(gha_step_summary) = gha_step_summary.as_mut() {

View File

@ -6,7 +6,7 @@ use crate::rustc_info::get_file_name;
use crate::shared_utils::{rustflags_from_env, rustflags_to_cmd_env};
use crate::utils::{CargoProject, Compiler, LogGroup};
static CG_CLIF: CargoProject = CargoProject::new(&RelPath::SOURCE, "cg_clif");
static CG_CLIF: CargoProject = CargoProject::new(&RelPath::source("."), "cg_clif");
pub(crate) fn build_backend(
dirs: &Dirs,

View File

@ -22,9 +22,9 @@ pub(crate) fn build_sysroot(
eprintln!("[BUILD] sysroot {:?}", sysroot_kind);
let dist_dir = RelPath::DIST.to_path(dirs);
let dist_dir = &dirs.dist_dir;
ensure_empty_dir(&dist_dir);
ensure_empty_dir(dist_dir);
fs::create_dir_all(dist_dir.join("bin")).unwrap();
fs::create_dir_all(dist_dir.join("lib")).unwrap();
@ -55,7 +55,7 @@ pub(crate) fn build_sysroot(
let mut build_cargo_wrapper_cmd = Command::new(&bootstrap_host_compiler.rustc);
let wrapper_path = dist_dir.join(&wrapper_name);
build_cargo_wrapper_cmd
.arg(RelPath::SCRIPTS.to_path(dirs).join(&format!("{wrapper}.rs")))
.arg(dirs.source_dir.join("scripts").join(&format!("{wrapper}.rs")))
.arg("-o")
.arg(&wrapper_path)
.arg("-Cstrip=debuginfo");
@ -85,7 +85,7 @@ pub(crate) fn build_sysroot(
&cg_clif_dylib_path,
sysroot_kind,
);
host.install_into_sysroot(&dist_dir);
host.install_into_sysroot(dist_dir);
if !is_native {
build_sysroot_for_triple(
@ -99,7 +99,7 @@ pub(crate) fn build_sysroot(
&cg_clif_dylib_path,
sysroot_kind,
)
.install_into_sysroot(&dist_dir);
.install_into_sysroot(dist_dir);
}
let mut target_compiler = {
@ -143,10 +143,10 @@ impl SysrootTarget {
}
}
static STDLIB_SRC: RelPath = RelPath::BUILD.join("stdlib");
static STDLIB_SRC: RelPath = RelPath::build("stdlib");
static STANDARD_LIBRARY: CargoProject =
CargoProject::new(&STDLIB_SRC.join("library/sysroot"), "stdlib_target");
static RTSTARTUP_SYSROOT: RelPath = RelPath::BUILD.join("rtstartup");
CargoProject::new(&RelPath::build("stdlib/library/sysroot"), "stdlib_target");
static RTSTARTUP_SYSROOT: RelPath = RelPath::build("rtstartup");
fn build_sysroot_for_triple(
dirs: &Dirs,
@ -247,6 +247,7 @@ fn build_clif_sysroot_for_triple(
let mut build_cmd = STANDARD_LIBRARY.build(&compiler, dirs);
build_cmd.arg("--release");
build_cmd.arg("--features").arg("backtrace panic-unwind compiler-builtins-no-f16-f128");
build_cmd.arg(format!("-Zroot-dir={}", STDLIB_SRC.to_path(dirs).display()));
build_cmd.env("CARGO_PROFILE_RELEASE_DEBUG", "true");
build_cmd.env("__CARGO_DEFAULT_LIB_METADATA", "cg_clif");
if compiler.triple.contains("apple") {
@ -281,13 +282,14 @@ fn build_rtstartup(dirs: &Dirs, compiler: &Compiler) -> Option<SysrootTarget> {
return None;
}
RTSTARTUP_SYSROOT.ensure_fresh(dirs);
let rtstartup_sysroot = RTSTARTUP_SYSROOT.to_path(dirs);
ensure_empty_dir(&rtstartup_sysroot);
let rtstartup_src = STDLIB_SRC.to_path(dirs).join("library").join("rtstartup");
let mut target_libs = SysrootTarget { triple: compiler.triple.clone(), libs: vec![] };
for file in ["rsbegin", "rsend"] {
let obj = RTSTARTUP_SYSROOT.to_path(dirs).join(format!("{file}.o"));
let obj = rtstartup_sysroot.join(format!("{file}.o"));
let mut build_rtstartup_cmd = Command::new(&compiler.rustc);
build_rtstartup_cmd
.arg("--target")

View File

@ -185,12 +185,11 @@ fn main() {
frozen,
};
path::RelPath::BUILD.ensure_exists(&dirs);
std::fs::create_dir_all(&dirs.build_dir).unwrap();
{
// Make sure we always explicitly specify the target dir
let target =
path::RelPath::BUILD.join("target_dir_should_be_set_explicitly").to_path(&dirs);
let target = dirs.build_dir.join("target_dir_should_be_set_explicitly");
env::set_var("CARGO_TARGET_DIR", &target);
let _ = std::fs::remove_file(&target);
std::fs::File::create(target).unwrap();

View File

@ -1,8 +1,5 @@
use std::fs;
use std::path::PathBuf;
use crate::utils::ensure_empty_dir;
#[derive(Debug, Clone)]
pub(crate) struct Dirs {
pub(crate) source_dir: PathBuf,
@ -16,54 +13,34 @@ pub(crate) struct Dirs {
#[derive(Debug, Copy, Clone)]
pub(crate) enum PathBase {
Source,
Download,
Build,
Dist,
}
impl PathBase {
fn to_path(self, dirs: &Dirs) -> PathBuf {
match self {
PathBase::Source => dirs.source_dir.clone(),
PathBase::Download => dirs.download_dir.clone(),
PathBase::Build => dirs.build_dir.clone(),
PathBase::Dist => dirs.dist_dir.clone(),
}
}
}
#[derive(Debug, Copy, Clone)]
pub(crate) enum RelPath {
Base(PathBase),
Join(&'static RelPath, &'static str),
pub(crate) struct RelPath {
base: PathBase,
suffix: &'static str,
}
impl RelPath {
pub(crate) const SOURCE: RelPath = RelPath::Base(PathBase::Source);
pub(crate) const DOWNLOAD: RelPath = RelPath::Base(PathBase::Download);
pub(crate) const BUILD: RelPath = RelPath::Base(PathBase::Build);
pub(crate) const DIST: RelPath = RelPath::Base(PathBase::Dist);
pub(crate) const fn source(suffix: &'static str) -> RelPath {
RelPath { base: PathBase::Source, suffix }
}
pub(crate) const SCRIPTS: RelPath = RelPath::SOURCE.join("scripts");
pub(crate) const PATCHES: RelPath = RelPath::SOURCE.join("patches");
pub(crate) const fn join(&'static self, suffix: &'static str) -> RelPath {
RelPath::Join(self, suffix)
pub(crate) const fn build(suffix: &'static str) -> RelPath {
RelPath { base: PathBase::Build, suffix }
}
pub(crate) fn to_path(&self, dirs: &Dirs) -> PathBuf {
match self {
RelPath::Base(base) => base.to_path(dirs),
RelPath::Join(base, suffix) => base.to_path(dirs).join(suffix),
}
}
pub(crate) fn ensure_exists(&self, dirs: &Dirs) {
fs::create_dir_all(self.to_path(dirs)).unwrap();
}
pub(crate) fn ensure_fresh(&self, dirs: &Dirs) {
let path = self.to_path(dirs);
ensure_empty_dir(&path);
self.base.to_path(dirs).join(self.suffix)
}
}

View File

@ -8,7 +8,7 @@ use crate::path::{Dirs, RelPath};
use crate::utils::{copy_dir_recursively, ensure_empty_dir, spawn_and_wait};
pub(crate) fn prepare(dirs: &Dirs) {
RelPath::DOWNLOAD.ensure_exists(dirs);
std::fs::create_dir_all(&dirs.download_dir).unwrap();
crate::tests::RAND_REPO.fetch(dirs);
crate::tests::REGEX_REPO.fetch(dirs);
}
@ -79,13 +79,13 @@ impl GitRepo {
fn download_dir(&self, dirs: &Dirs) -> PathBuf {
match self.url {
GitRepoUrl::Github { user: _, repo } => RelPath::DOWNLOAD.join(repo).to_path(dirs),
GitRepoUrl::Github { user: _, repo } => dirs.download_dir.join(repo),
}
}
pub(crate) const fn source_dir(&self) -> RelPath {
match self.url {
GitRepoUrl::Github { user: _, repo } => RelPath::BUILD.join(repo),
GitRepoUrl::Github { user: _, repo } => RelPath::build(repo),
}
}
@ -130,7 +130,7 @@ impl GitRepo {
}
let source_lockfile =
RelPath::PATCHES.to_path(dirs).join(format!("{}-lock.toml", self.patch_name));
dirs.source_dir.join("patches").join(format!("{}-lock.toml", self.patch_name));
let target_lockfile = download_dir.join("Cargo.lock");
if source_lockfile.exists() {
assert!(!target_lockfile.exists());
@ -191,7 +191,7 @@ fn init_git_repo(repo_dir: &Path) {
}
fn get_patches(dirs: &Dirs, crate_name: &str) -> Vec<PathBuf> {
let mut patches: Vec<_> = fs::read_dir(RelPath::PATCHES.to_path(dirs))
let mut patches: Vec<_> = fs::read_dir(dirs.source_dir.join("patches"))
.unwrap()
.map(|entry| entry.unwrap().path())
.filter(|path| path.extension() == Some(OsStr::new("patch")))

View File

@ -7,10 +7,10 @@ use crate::path::{Dirs, RelPath};
use crate::prepare::{GitRepo, apply_patches};
use crate::rustc_info::get_default_sysroot;
use crate::shared_utils::rustflags_from_env;
use crate::utils::{CargoProject, Compiler, LogGroup, spawn_and_wait};
use crate::utils::{CargoProject, Compiler, LogGroup, ensure_empty_dir, spawn_and_wait};
use crate::{CodegenBackend, SysrootKind, build_sysroot, config};
static BUILD_EXAMPLE_OUT_DIR: RelPath = RelPath::BUILD.join("example");
static BUILD_EXAMPLE_OUT_DIR: RelPath = RelPath::build("example");
struct TestCase {
config: &'static str,
@ -129,11 +129,11 @@ pub(crate) static REGEX_REPO: GitRepo = GitRepo::github(
static REGEX: CargoProject = CargoProject::new(&REGEX_REPO.source_dir(), "regex_target");
static PORTABLE_SIMD_SRC: RelPath = RelPath::BUILD.join("portable-simd");
static PORTABLE_SIMD_SRC: RelPath = RelPath::build("portable-simd");
static PORTABLE_SIMD: CargoProject = CargoProject::new(&PORTABLE_SIMD_SRC, "portable-simd_target");
static LIBCORE_TESTS_SRC: RelPath = RelPath::BUILD.join("coretests");
static LIBCORE_TESTS_SRC: RelPath = RelPath::build("coretests");
static LIBCORE_TESTS: CargoProject = CargoProject::new(&LIBCORE_TESTS_SRC, "coretests_target");
@ -162,7 +162,7 @@ const EXTENDED_SYSROOT_SUITE: &[TestCase] = &[
&LIBCORE_TESTS_SRC.to_path(&runner.dirs),
);
let source_lockfile = RelPath::PATCHES.to_path(&runner.dirs).join("coretests-lock.toml");
let source_lockfile = runner.dirs.source_dir.join("patches/coretests-lock.toml");
let target_lockfile = LIBCORE_TESTS_SRC.to_path(&runner.dirs).join("Cargo.lock");
fs::copy(source_lockfile, target_lockfile).unwrap();
@ -267,7 +267,9 @@ pub(crate) fn run_tests(
stdlib_source.clone(),
);
BUILD_EXAMPLE_OUT_DIR.ensure_fresh(dirs);
let path = BUILD_EXAMPLE_OUT_DIR.to_path(dirs);
ensure_empty_dir(&path);
runner.run_testsuite(NO_SYSROOT_SUITE);
} else {
eprintln!("[SKIP] no_sysroot tests");

View File

@ -93,7 +93,7 @@ impl CargoProject {
}
pub(crate) fn target_dir(&self, dirs: &Dirs) -> PathBuf {
RelPath::BUILD.join(self.target).to_path(dirs)
dirs.build_dir.join(self.target)
}
#[must_use]

View File

@ -8,6 +8,9 @@
unboxed_closures
)]
#![allow(internal_features)]
// FIXME once abi_unsupported_vector_types is a hard error disable the foo test when the respective
// target feature is not enabled.
#![allow(abi_unsupported_vector_types)]
#[cfg(target_arch = "x86_64")]
use std::arch::x86_64::*;

View File

@ -38,7 +38,7 @@ index 42a26ae..5ac1042 100644
@@ -1,3 +1,4 @@
+#![cfg(test)]
// tidy-alphabetical-start
#![cfg_attr(bootstrap, feature(const_three_way_compare))]
#![cfg_attr(bootstrap, feature(strict_provenance))]
#![cfg_attr(target_has_atomic = "128", feature(integer_atomics))]
#![cfg_attr(test, feature(cfg_match))]
--
2.21.0 (Apple Git-122)

View File

@ -14,10 +14,9 @@ diff --git a/lib.rs b/lib.rs
index 1e336bf..35e6f54 100644
--- a/lib.rs
+++ b/lib.rs
@@ -2,7 +2,6 @@
#![cfg_attr(bootstrap, feature(const_three_way_compare))]
#![cfg_attr(bootstrap, feature(strict_provenance))]
#![cfg_attr(not(bootstrap), feature(strict_provenance_lints))]
@@ -2,6 +2,5 @@
#![cfg(test)]
// tidy-alphabetical-start
-#![cfg_attr(target_has_atomic = "128", feature(integer_atomics))]
#![cfg_attr(test, feature(cfg_match))]
#![feature(alloc_layout_extra)]

View File

@ -4,22 +4,23 @@ Date: Fri, 9 Aug 2024 15:44:51 +0000
Subject: [PATCH] Disable f16 and f128 in compiler-builtins
---
library/sysroot/Cargo.toml | 2 +-
library/liballoc/Cargo.toml | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/library/sysroot/Cargo.toml b/library/sysroot/Cargo.toml
diff --git a/library/liballoc/Cargo.toml b/library/liballoc/Cargo.toml
index 7165c3e48af..968552ad435 100644
--- a/library/sysroot/Cargo.toml
+++ b/library/sysroot/Cargo.toml
--- a/library/alloc/Cargo.toml
+++ b/library/alloc/Cargo.toml
@@ -11,7 +11,7 @@ test = { path = "../test" }
edition = "2021"
# Forward features to the `std` crate as necessary
[features]
-default = ["std_detect_file_io", "std_detect_dlsym_getauxval", "panic-unwind"]
+default = ["std_detect_file_io", "std_detect_dlsym_getauxval", "panic-unwind", "compiler-builtins-no-f16-f128"]
backtrace = ["std/backtrace"]
compiler-builtins-c = ["std/compiler-builtins-c"]
compiler-builtins-mem = ["std/compiler-builtins-mem"]
[dependencies]
core = { path = "../core" }
-compiler_builtins = { version = "=0.1.138", features = ['rustc-dep-of-std'] }
+compiler_builtins = { version = "=0.1.138", features = ['rustc-dep-of-std', 'no-f16-f128'] }
[dev-dependencies]
rand = { version = "0.8.5", default-features = false, features = ["alloc"] }
--
2.34.1

View File

@ -1,4 +1,4 @@
[toolchain]
channel = "nightly-2024-11-09"
channel = "nightly-2024-12-06"
components = ["rust-src", "rustc-dev", "llvm-tools"]
profile = "minimal"

View File

@ -33,6 +33,11 @@ fn main() {
args.push(OsString::from("--sysroot"));
args.push(OsString::from(sysroot.to_str().unwrap()));
}
if passed_args.is_empty() {
// Don't pass any arguments when the user didn't pass any arguments
// either to ensure the help message is shown.
args.clear();
}
args.extend(passed_args);
let rustc = if let Some(rustc) = option_env!("RUSTC") {

View File

@ -35,13 +35,14 @@ full-bootstrap = true
local-rebuild = true
[rust]
download-rustc = false
codegen-backends = ["cranelift"]
deny-warnings = false
verbose-tests = false
# The cg_clif sysroot doesn't contain llvm tools and unless llvm_tools is
# disabled bootstrap will crash trying to copy llvm tools for the bootstrap
# compiler.
llvm_tools = false
llvm-tools = false
EOF
popd

View File

@ -11,22 +11,5 @@ rm -r compiler/rustc_codegen_cranelift/{Cargo.*,src}
cp ../Cargo.* compiler/rustc_codegen_cranelift/
cp -r ../src compiler/rustc_codegen_cranelift/src
# FIXME(rust-lang/rust#132719) remove once it doesn't break without this patch
cat <<EOF | git apply -
diff --git a/src/bootstrap/src/core/build_steps/compile.rs b/src/bootstrap/src/core/build_steps/compile.rs
index 3394f2a84a0..cb980dd4d7c 100644
--- a/src/bootstrap/src/core/build_steps/compile.rs
+++ b/src/bootstrap/src/core/build_steps/compile.rs
@@ -1976,7 +1976,7 @@ fn run(self, builder: &Builder<'_>) -> Compiler {
}
}
- {
+ if builder.config.llvm_enabled(target_compiler.host) && builder.config.llvm_tools_enabled {
// \`llvm-strip\` is used by rustc, which is actually just a symlink to \`llvm-objcopy\`,
// so copy and rename \`llvm-objcopy\`.
let src_exe = exe("llvm-objcopy", target_compiler.host);
EOF
./x.py build --stage 1 library/std
popd

View File

@ -57,6 +57,7 @@ rm tests/ui/asm/x86_64/issue-96797.rs # const and sym inline asm operands don't
rm tests/ui/asm/x86_64/goto.rs # inline asm labels not supported
rm tests/ui/simd/simd-bitmask-notpow2.rs # non-pow-of-2 simd vector sizes
rm -r tests/run-make/embed-source-dwarf # embedding sources in debuginfo
rm tests/ui/simd-abi-checks.rs # vector types >128bits not yet supported
# requires LTO
rm -r tests/run-make/cdylib
@ -75,6 +76,8 @@ rm -r tests/ui/instrument-coverage/
rm tests/ui/half-open-range-patterns/half-open-range-pats-semantics.rs
rm tests/ui/asm/aarch64/type-f16.rs
rm tests/ui/float/conv-bits-runtime-const.rs
rm tests/ui/consts/const-eval/float_methods.rs
rm tests/ui/match/match-float.rs
# optimization tests
# ==================

View File

@ -125,8 +125,9 @@ impl<'tcx> FunctionCx<'_, '_, 'tcx> {
returns: Vec<AbiParam>,
args: &[Value],
) -> Cow<'_, [Value]> {
if self.tcx.sess.target.is_like_windows {
let (mut params, mut args): (Vec<_>, Vec<_>) = params
// Pass i128 arguments by-ref on Windows.
let (params, args): (Vec<_>, Cow<'_, [_]>) = if self.tcx.sess.target.is_like_windows {
let (params, args): (Vec<_>, Vec<_>) = params
.into_iter()
.zip(args)
.map(|(param, &arg)| {
@ -140,29 +141,42 @@ impl<'tcx> FunctionCx<'_, '_, 'tcx> {
})
.unzip();
let indirect_ret_val = returns.len() == 1 && returns[0].value_type == types::I128;
(params, args.into())
} else {
(params, args.into())
};
if indirect_ret_val {
params.insert(0, AbiParam::new(self.pointer_type));
let ret_ptr = self.create_stack_slot(16, 16);
args.insert(0, ret_ptr.get_addr(self));
self.lib_call_unadjusted(name, params, vec![], &args);
return Cow::Owned(vec![ret_ptr.load(self, types::I128, MemFlags::trusted())]);
// Return i128 using a return area pointer on Windows and s390x.
let adjust_ret_param =
if self.tcx.sess.target.is_like_windows || self.tcx.sess.target.arch == "s390x" {
returns.len() == 1 && returns[0].value_type == types::I128
} else {
return self.lib_call_unadjusted(name, params, returns, &args);
}
}
false
};
self.lib_call_unadjusted(name, params, returns, args)
if adjust_ret_param {
let mut params = params;
let mut args = args.to_vec();
params.insert(0, AbiParam::new(self.pointer_type));
let ret_ptr = self.create_stack_slot(16, 16);
args.insert(0, ret_ptr.get_addr(self));
self.lib_call_unadjusted(name, params, vec![], &args);
Cow::Owned(vec![ret_ptr.load(self, types::I128, MemFlags::trusted())])
} else {
Cow::Borrowed(self.lib_call_unadjusted(name, params, returns, &args))
}
}
pub(crate) fn lib_call_unadjusted(
fn lib_call_unadjusted(
&mut self,
name: &str,
params: Vec<AbiParam>,
returns: Vec<AbiParam>,
args: &[Value],
) -> Cow<'_, [Value]> {
) -> &[Value] {
let sig = Signature { params, returns, call_conv: self.target_config.default_call_conv };
let func_id = self.module.declare_function(name, Linkage::Import, &sig).unwrap();
let func_ref = self.module.declare_func_in_func(func_id, &mut self.bcx.func);
@ -175,7 +189,7 @@ impl<'tcx> FunctionCx<'_, '_, 'tcx> {
}
let results = self.bcx.inst_results(call_inst);
assert!(results.len() <= 2, "{}", results.len());
Cow::Borrowed(results)
results
}
}

View File

@ -6,6 +6,7 @@ use cranelift_frontend::{FunctionBuilder, FunctionBuilderContext};
use cranelift_module::ModuleError;
use rustc_ast::InlineAsmOptions;
use rustc_codegen_ssa::base::is_call_from_compiler_builtins_to_upstream_monomorphization;
use rustc_data_structures::profiling::SelfProfilerRef;
use rustc_index::IndexVec;
use rustc_middle::middle::codegen_fn_attrs::CodegenFnAttrFlags;
use rustc_middle::mir::InlineAsmMacro;
@ -16,6 +17,7 @@ use rustc_middle::ty::print::with_no_trimmed_paths;
use crate::constant::ConstantCx;
use crate::debuginfo::{FunctionDebugContext, TypeDebugContext};
use crate::enable_verifier;
use crate::inline_asm::codegen_naked_asm;
use crate::prelude::*;
use crate::pretty_clif::CommentWriter;
@ -169,12 +171,13 @@ pub(crate) fn codegen_fn<'tcx>(
pub(crate) fn compile_fn(
cx: &mut crate::CodegenCx,
profiler: &SelfProfilerRef,
cached_context: &mut Context,
module: &mut dyn Module,
codegened_func: CodegenedFunction,
) {
let _timer =
cx.profiler.generic_activity_with_arg("compile function", &*codegened_func.symbol_name);
profiler.generic_activity_with_arg("compile function", &*codegened_func.symbol_name);
let clif_comments = codegened_func.clif_comments;
@ -212,7 +215,7 @@ pub(crate) fn compile_fn(
};
// Define function
cx.profiler.generic_activity("define function").run(|| {
profiler.generic_activity("define function").run(|| {
context.want_disasm = cx.should_write_ir;
match module.define_function(codegened_func.func_id, context) {
Ok(()) => {}
@ -253,7 +256,7 @@ pub(crate) fn compile_fn(
// Define debuginfo for function
let debug_context = &mut cx.debug_context;
cx.profiler.generic_activity("generate debug info").run(|| {
profiler.generic_activity("generate debug info").run(|| {
if let Some(debug_context) = debug_context {
codegened_func.func_debug_cx.unwrap().finalize(
debug_context,
@ -264,11 +267,11 @@ pub(crate) fn compile_fn(
});
}
pub(crate) fn verify_func(
tcx: TyCtxt<'_>,
writer: &crate::pretty_clif::CommentWriter,
func: &Function,
) {
fn verify_func(tcx: TyCtxt<'_>, writer: &crate::pretty_clif::CommentWriter, func: &Function) {
if !enable_verifier(tcx.sess) {
return;
}
tcx.prof.generic_activity("verify clif ir").run(|| {
let flags = cranelift_codegen::settings::Flags::new(cranelift_codegen::settings::builder());
match cranelift_codegen::verify_function(&func, &flags) {

View File

@ -81,26 +81,6 @@ pub(crate) fn maybe_codegen_checked<'tcx>(
match bin_op {
BinOp::BitAnd | BinOp::BitOr | BinOp::BitXor => unreachable!(),
BinOp::Add | BinOp::Sub => None,
BinOp::Mul if is_signed => {
let out_ty = Ty::new_tup(fx.tcx, &[lhs.layout().ty, fx.tcx.types.bool]);
let oflow = CPlace::new_stack_slot(fx, fx.layout_of(fx.tcx.types.i32));
let lhs = lhs.load_scalar(fx);
let rhs = rhs.load_scalar(fx);
let oflow_ptr = oflow.to_ptr().get_addr(fx);
let res = fx.lib_call_unadjusted(
"__muloti4",
vec![
AbiParam::new(types::I128),
AbiParam::new(types::I128),
AbiParam::new(fx.pointer_type),
],
vec![AbiParam::new(types::I128)],
&[lhs, rhs, oflow_ptr],
)[0];
let oflow = oflow.to_cvalue(fx).load_scalar(fx);
let oflow = fx.bcx.ins().ireduce(types::I8, oflow);
Some(CValue::by_val_pair(res, oflow, fx.layout_of(out_ty)))
}
BinOp::Mul => {
let out_ty = Ty::new_tup(fx.tcx, &[lhs.layout().ty, fx.tcx.types.bool]);
let out_place = CPlace::new_stack_slot(fx, fx.layout_of(out_ty));
@ -110,7 +90,12 @@ pub(crate) fn maybe_codegen_checked<'tcx>(
AbiParam::new(types::I128),
];
let args = [out_place.to_ptr().get_addr(fx), lhs.load_scalar(fx), rhs.load_scalar(fx)];
fx.lib_call("__rust_u128_mulo", param_types, vec![], &args);
fx.lib_call(
if is_signed { "__rust_i128_mulo" } else { "__rust_u128_mulo" },
param_types,
vec![],
&args,
);
Some(out_place.to_cvalue(fx))
}
BinOp::AddUnchecked | BinOp::SubUnchecked | BinOp::MulUnchecked => unreachable!(),

View File

@ -1,10 +1,3 @@
use std::env;
use std::str::FromStr;
fn bool_env_var(key: &str) -> bool {
env::var(key).as_deref() == Ok("1")
}
/// The mode to use for compilation.
#[derive(Copy, Clone, Debug)]
pub enum CodegenMode {
@ -16,19 +9,6 @@ pub enum CodegenMode {
JitLazy,
}
impl FromStr for CodegenMode {
type Err = String;
fn from_str(s: &str) -> Result<Self, Self::Err> {
match s {
"aot" => Ok(CodegenMode::Aot),
"jit" => Ok(CodegenMode::Jit),
"jit-lazy" => Ok(CodegenMode::JitLazy),
_ => Err(format!("Unknown codegen mode `{}`", s)),
}
}
}
/// Configuration of cg_clif as passed in through `-Cllvm-args` and various env vars.
#[derive(Clone, Debug)]
pub struct BackendConfig {
@ -41,51 +21,22 @@ pub struct BackendConfig {
///
/// Defaults to the value of `CG_CLIF_JIT_ARGS`.
pub jit_args: Vec<String>,
/// Enable the Cranelift ir verifier for all compilation passes. If not set it will only run
/// once before passing the clif ir to Cranelift for compilation.
///
/// Defaults to true when the `CG_CLIF_ENABLE_VERIFIER` env var is set to 1 or when cg_clif is
/// compiled with debug assertions enabled or false otherwise. Can be set using
/// `-Cllvm-args=enable_verifier=...`.
pub enable_verifier: bool,
/// Don't cache object files in the incremental cache. Useful during development of cg_clif
/// to make it possible to use incremental mode for all analyses performed by rustc without
/// caching object files when their content should have been changed by a change to cg_clif.
///
/// Defaults to true when the `CG_CLIF_DISABLE_INCR_CACHE` env var is set to 1 or false
/// otherwise. Can be set using `-Cllvm-args=disable_incr_cache=...`.
pub disable_incr_cache: bool,
}
impl Default for BackendConfig {
fn default() -> Self {
BackendConfig {
codegen_mode: CodegenMode::Aot,
jit_args: {
match std::env::var("CG_CLIF_JIT_ARGS") {
Ok(args) => args.split(' ').map(|arg| arg.to_string()).collect(),
Err(std::env::VarError::NotPresent) => vec![],
Err(std::env::VarError::NotUnicode(s)) => {
panic!("CG_CLIF_JIT_ARGS not unicode: {:?}", s);
}
}
},
enable_verifier: cfg!(debug_assertions) || bool_env_var("CG_CLIF_ENABLE_VERIFIER"),
disable_incr_cache: bool_env_var("CG_CLIF_DISABLE_INCR_CACHE"),
}
}
}
impl BackendConfig {
/// Parse the configuration passed in using `-Cllvm-args`.
pub fn from_opts(opts: &[String]) -> Result<Self, String> {
fn parse_bool(name: &str, value: &str) -> Result<bool, String> {
value.parse().map_err(|_| format!("failed to parse value `{}` for {}", value, name))
}
let mut config = BackendConfig {
codegen_mode: CodegenMode::Aot,
jit_args: match std::env::var("CG_CLIF_JIT_ARGS") {
Ok(args) => args.split(' ').map(|arg| arg.to_string()).collect(),
Err(std::env::VarError::NotPresent) => vec![],
Err(std::env::VarError::NotUnicode(s)) => {
panic!("CG_CLIF_JIT_ARGS not unicode: {:?}", s);
}
},
};
let mut config = BackendConfig::default();
for opt in opts {
if opt.starts_with("-import-instr-limit") {
// Silently ignore -import-instr-limit. It is set by rust's build system even when
@ -94,9 +45,14 @@ impl BackendConfig {
}
if let Some((name, value)) = opt.split_once('=') {
match name {
"mode" => config.codegen_mode = value.parse()?,
"enable_verifier" => config.enable_verifier = parse_bool(name, value)?,
"disable_incr_cache" => config.disable_incr_cache = parse_bool(name, value)?,
"mode" => {
config.codegen_mode = match value {
"aot" => CodegenMode::Aot,
"jit" => CodegenMode::Jit,
"jit-lazy" => CodegenMode::JitLazy,
_ => return Err(format!("Unknown codegen mode `{}`", value)),
};
}
_ => return Err(format!("Unknown option `{}`", name)),
}
} else {

View File

@ -1,6 +1,7 @@
//! The AOT driver uses [`cranelift_object`] to write object files suitable for linking into a
//! standalone executable.
use std::env;
use std::fs::{self, File};
use std::io::BufWriter;
use std::path::{Path, PathBuf};
@ -25,13 +26,18 @@ use rustc_middle::mir::mono::{CodegenUnit, MonoItem};
use rustc_session::Session;
use rustc_session::config::{DebugInfo, OutFileName, OutputFilenames, OutputType};
use crate::BackendConfig;
use crate::CodegenCx;
use crate::base::CodegenedFunction;
use crate::concurrency_limiter::{ConcurrencyLimiter, ConcurrencyLimiterToken};
use crate::debuginfo::TypeDebugContext;
use crate::global_asm::GlobalAsmConfig;
use crate::prelude::*;
use crate::unwind_module::UnwindModule;
fn disable_incr_cache() -> bool {
env::var("CG_CLIF_DISABLE_INCR_CACHE").as_deref() == Ok("1")
}
struct ModuleCodegenResult {
module_regular: CompiledModule,
module_global_asm: Option<CompiledModule>,
@ -63,10 +69,10 @@ impl OngoingCodegen {
self,
sess: &Session,
outputs: &OutputFilenames,
backend_config: &BackendConfig,
) -> (CodegenResults, FxIndexMap<WorkProductId, WorkProduct>) {
let mut work_products = FxIndexMap::default();
let mut modules = vec![];
let disable_incr_cache = disable_incr_cache();
for module_codegen in self.modules {
let module_codegen_result = match module_codegen {
@ -87,7 +93,7 @@ impl OngoingCodegen {
if let Some((work_product_id, work_product)) = existing_work_product {
work_products.insert(work_product_id, work_product);
} else {
let work_product = if backend_config.disable_incr_cache {
let work_product = if disable_incr_cache {
None
} else if let Some(module_global_asm) = &module_global_asm {
rustc_incremental::copy_cgu_workproduct_to_incr_comp_cache_dir(
@ -322,12 +328,8 @@ fn produce_final_output_artifacts(
// These are used in linking steps and will be cleaned up afterward.
}
fn make_module(
sess: &Session,
backend_config: &BackendConfig,
name: String,
) -> UnwindModule<ObjectModule> {
let isa = crate::build_isa(sess, backend_config);
fn make_module(sess: &Session, name: String) -> UnwindModule<ObjectModule> {
let isa = crate::build_isa(sess);
let mut builder =
ObjectBuilder::new(isa, name + ".o", cranelift_module::default_libcall_names()).unwrap();
@ -412,7 +414,13 @@ fn emit_module(
Err(err) => return Err(format!("error writing object file: {}", err)),
};
prof.artifact_size("object_file", &*name, file.metadata().unwrap().len());
if prof.enabled() {
prof.artifact_size(
"object_file",
tmp_file.file_name().unwrap().to_string_lossy(),
file.metadata().unwrap().len(),
);
}
Ok(CompiledModule {
name,
@ -486,91 +494,101 @@ fn reuse_workproduct_for_cgu(
})
}
fn codegen_cgu_content(
tcx: TyCtxt<'_>,
module: &mut dyn Module,
cgu_name: rustc_span::Symbol,
) -> (CodegenCx, Vec<CodegenedFunction>) {
let _timer = tcx.prof.generic_activity_with_arg("codegen cgu", cgu_name.as_str());
let cgu = tcx.codegen_unit(cgu_name);
let mono_items = cgu.items_in_deterministic_order(tcx);
let mut cx = crate::CodegenCx::new(
tcx,
module.isa(),
tcx.sess.opts.debuginfo != DebugInfo::None,
cgu_name,
);
let mut type_dbg = TypeDebugContext::default();
super::predefine_mono_items(tcx, module, &mono_items);
let mut codegened_functions = vec![];
for (mono_item, _) in mono_items {
match mono_item {
MonoItem::Fn(inst) => {
if let Some(codegened_function) = crate::base::codegen_fn(
tcx,
&mut cx,
&mut type_dbg,
Function::new(),
module,
inst,
) {
codegened_functions.push(codegened_function);
}
}
MonoItem::Static(def_id) => {
let data_id = crate::constant::codegen_static(tcx, module, def_id);
if let Some(debug_context) = &mut cx.debug_context {
debug_context.define_static(tcx, &mut type_dbg, def_id, data_id);
}
}
MonoItem::GlobalAsm(item_id) => {
crate::global_asm::codegen_global_asm_item(tcx, &mut cx.global_asm, item_id);
}
}
}
crate::main_shim::maybe_create_entry_wrapper(tcx, module, false, cgu.is_primary());
(cx, codegened_functions)
}
fn module_codegen(
tcx: TyCtxt<'_>,
(backend_config, global_asm_config, cgu_name, token): (
BackendConfig,
(global_asm_config, cgu_name, token): (
Arc<GlobalAsmConfig>,
rustc_span::Symbol,
ConcurrencyLimiterToken,
),
) -> OngoingModuleCodegen {
let (cgu_name, mut cx, mut module, codegened_functions) =
tcx.prof.generic_activity_with_arg("codegen cgu", cgu_name.as_str()).run(|| {
let cgu = tcx.codegen_unit(cgu_name);
let mono_items = cgu.items_in_deterministic_order(tcx);
let mut module = make_module(tcx.sess, cgu_name.as_str().to_string());
let mut module = make_module(tcx.sess, &backend_config, cgu_name.as_str().to_string());
let (mut cx, codegened_functions) = codegen_cgu_content(tcx, &mut module, cgu_name);
let mut cx = crate::CodegenCx::new(
tcx,
module.isa(),
tcx.sess.opts.debuginfo != DebugInfo::None,
cgu_name,
);
let mut type_dbg = TypeDebugContext::default();
super::predefine_mono_items(tcx, &mut module, &mono_items);
let mut codegened_functions = vec![];
for (mono_item, _) in mono_items {
match mono_item {
MonoItem::Fn(inst) => {
if let Some(codegened_function) = crate::base::codegen_fn(
tcx,
&mut cx,
&mut type_dbg,
Function::new(),
&mut module,
inst,
) {
codegened_functions.push(codegened_function);
}
}
MonoItem::Static(def_id) => {
let data_id = crate::constant::codegen_static(tcx, &mut module, def_id);
if let Some(debug_context) = &mut cx.debug_context {
debug_context.define_static(tcx, &mut type_dbg, def_id, data_id);
}
}
MonoItem::GlobalAsm(item_id) => {
crate::global_asm::codegen_global_asm_item(
tcx,
&mut cx.global_asm,
item_id,
);
}
}
}
crate::main_shim::maybe_create_entry_wrapper(tcx, &mut module, false, cgu.is_primary());
let cgu_name = cgu.name().as_str().to_owned();
(cgu_name, cx, module, codegened_functions)
});
let cgu_name = cgu_name.as_str().to_owned();
let producer = crate::debuginfo::producer(tcx.sess);
let profiler = tcx.prof.clone();
OngoingModuleCodegen::Async(std::thread::spawn(move || {
cx.profiler.clone().generic_activity_with_arg("compile functions", &*cgu_name).run(|| {
profiler.clone().generic_activity_with_arg("compile functions", &*cgu_name).run(|| {
cranelift_codegen::timing::set_thread_profiler(Box::new(super::MeasuremeProfiler(
cx.profiler.clone(),
profiler.clone(),
)));
let mut cached_context = Context::new();
for codegened_func in codegened_functions {
crate::base::compile_fn(&mut cx, &mut cached_context, &mut module, codegened_func);
crate::base::compile_fn(
&mut cx,
&profiler,
&mut cached_context,
&mut module,
codegened_func,
);
}
});
let global_asm_object_file =
cx.profiler.generic_activity_with_arg("compile assembly", &*cgu_name).run(|| {
profiler.generic_activity_with_arg("compile assembly", &*cgu_name).run(|| {
crate::global_asm::compile_global_asm(&global_asm_config, &cgu_name, &cx.global_asm)
})?;
let codegen_result =
cx.profiler.generic_activity_with_arg("write object file", &*cgu_name).run(|| {
profiler.generic_activity_with_arg("write object file", &*cgu_name).run(|| {
emit_cgu(
&global_asm_config.output_filenames,
&cx.profiler,
&profiler,
cgu_name,
module,
cx.debug_context,
@ -583,9 +601,63 @@ fn module_codegen(
}))
}
fn emit_metadata_module(tcx: TyCtxt<'_>, metadata: &EncodedMetadata) -> CompiledModule {
use rustc_middle::mir::mono::CodegenUnitNameBuilder;
let _timer = tcx.sess.timer("write compressed metadata");
let cgu_name_builder = &mut CodegenUnitNameBuilder::new(tcx);
let metadata_cgu_name = cgu_name_builder
.build_cgu_name(LOCAL_CRATE, ["crate"], Some("metadata"))
.as_str()
.to_string();
let tmp_file =
tcx.output_filenames(()).temp_path(OutputType::Metadata, Some(&metadata_cgu_name));
let symbol_name = rustc_middle::middle::exported_symbols::metadata_symbol_name(tcx);
let obj = create_compressed_metadata_file(tcx.sess, metadata, &symbol_name);
if let Err(err) = std::fs::write(&tmp_file, obj) {
tcx.dcx().fatal(format!("error writing metadata object file: {}", err));
}
CompiledModule {
name: metadata_cgu_name,
kind: ModuleKind::Metadata,
object: Some(tmp_file),
dwarf_object: None,
bytecode: None,
assembly: None,
llvm_ir: None,
}
}
fn emit_allocator_module(tcx: TyCtxt<'_>) -> Option<CompiledModule> {
let mut allocator_module = make_module(tcx.sess, "allocator_shim".to_string());
let created_alloc_shim = crate::allocator::codegen(tcx, &mut allocator_module);
if created_alloc_shim {
let product = allocator_module.finish();
match emit_module(
tcx.output_filenames(()),
&tcx.sess.prof,
product.object,
ModuleKind::Allocator,
"allocator_shim".to_owned(),
&crate::debuginfo::producer(tcx.sess),
) {
Ok(allocator_module) => Some(allocator_module),
Err(err) => tcx.dcx().fatal(err),
}
} else {
None
}
}
pub(crate) fn run_aot(
tcx: TyCtxt<'_>,
backend_config: BackendConfig,
metadata: EncodedMetadata,
need_metadata_module: bool,
) -> Box<OngoingCodegen> {
@ -631,9 +703,10 @@ pub(crate) fn run_aot(
let global_asm_config = Arc::new(crate::global_asm::GlobalAsmConfig::new(tcx));
let disable_incr_cache = disable_incr_cache();
let (todo_cgus, done_cgus) =
cgus.into_iter().enumerate().partition::<Vec<_>, _>(|&(i, _)| match cgu_reuse[i] {
_ if backend_config.disable_incr_cache => true,
_ if disable_incr_cache => true,
CguReuse::No => true,
CguReuse::PreLto | CguReuse::PostLto => false,
});
@ -647,12 +720,7 @@ pub(crate) fn run_aot(
.with_task(
dep_node,
tcx,
(
backend_config.clone(),
global_asm_config.clone(),
cgu.name(),
concurrency_limiter.acquire(tcx.dcx()),
),
(global_asm_config.clone(), cgu.name(), concurrency_limiter.acquire(tcx.dcx())),
module_codegen,
Some(rustc_middle::dep_graph::hash_result),
)
@ -666,62 +734,10 @@ pub(crate) fn run_aot(
modules
});
let mut allocator_module = make_module(tcx.sess, &backend_config, "allocator_shim".to_string());
let created_alloc_shim = crate::allocator::codegen(tcx, &mut allocator_module);
let allocator_module = emit_allocator_module(tcx);
let allocator_module = if created_alloc_shim {
let product = allocator_module.finish();
match emit_module(
tcx.output_filenames(()),
&tcx.sess.prof,
product.object,
ModuleKind::Allocator,
"allocator_shim".to_owned(),
&crate::debuginfo::producer(tcx.sess),
) {
Ok(allocator_module) => Some(allocator_module),
Err(err) => tcx.dcx().fatal(err),
}
} else {
None
};
let metadata_module = if need_metadata_module {
let (metadata_cgu_name, tmp_file) = tcx.sess.time("write compressed metadata", || {
use rustc_middle::mir::mono::CodegenUnitNameBuilder;
let cgu_name_builder = &mut CodegenUnitNameBuilder::new(tcx);
let metadata_cgu_name = cgu_name_builder
.build_cgu_name(LOCAL_CRATE, ["crate"], Some("metadata"))
.as_str()
.to_string();
let tmp_file =
tcx.output_filenames(()).temp_path(OutputType::Metadata, Some(&metadata_cgu_name));
let symbol_name = rustc_middle::middle::exported_symbols::metadata_symbol_name(tcx);
let obj = create_compressed_metadata_file(tcx.sess, &metadata, &symbol_name);
if let Err(err) = std::fs::write(&tmp_file, obj) {
tcx.dcx().fatal(format!("error writing metadata object file: {}", err));
}
(metadata_cgu_name, tmp_file)
});
Some(CompiledModule {
name: metadata_cgu_name,
kind: ModuleKind::Metadata,
object: Some(tmp_file),
dwarf_object: None,
bytecode: None,
assembly: None,
llvm_ir: None,
})
} else {
None
};
let metadata_module =
if need_metadata_module { Some(emit_metadata_module(tcx, &metadata)) } else { None };
Box::new(OngoingCodegen {
modules,

View File

@ -11,12 +11,12 @@ use cranelift_jit::{JITBuilder, JITModule};
use rustc_codegen_ssa::CrateInfo;
use rustc_middle::mir::mono::MonoItem;
use rustc_session::Session;
use rustc_span::Symbol;
use rustc_span::sym;
use crate::debuginfo::TypeDebugContext;
use crate::prelude::*;
use crate::unwind_module::UnwindModule;
use crate::{BackendConfig, CodegenCx, CodegenMode};
use crate::{CodegenCx, CodegenMode};
struct JitState {
jit_module: UnwindModule<JITModule>,
@ -59,14 +59,10 @@ impl UnsafeMessage {
}
}
fn create_jit_module(
tcx: TyCtxt<'_>,
backend_config: &BackendConfig,
hotswap: bool,
) -> (UnwindModule<JITModule>, CodegenCx) {
fn create_jit_module(tcx: TyCtxt<'_>, hotswap: bool) -> (UnwindModule<JITModule>, CodegenCx) {
let crate_info = CrateInfo::new(tcx, "dummy_target_cpu".to_string());
let isa = crate::build_isa(tcx.sess, backend_config);
let isa = crate::build_isa(tcx.sess);
let mut jit_builder = JITBuilder::with_isa(isa, cranelift_module::default_libcall_names());
jit_builder.hotswap(hotswap);
crate::compiler_builtins::register_functions_for_jit(&mut jit_builder);
@ -81,7 +77,7 @@ fn create_jit_module(
(jit_module, cx)
}
pub(crate) fn run_jit(tcx: TyCtxt<'_>, backend_config: BackendConfig) -> ! {
pub(crate) fn run_jit(tcx: TyCtxt<'_>, codegen_mode: CodegenMode, jit_args: Vec<String>) -> ! {
if !tcx.sess.opts.output_types.should_codegen() {
tcx.dcx().fatal("JIT mode doesn't work with `cargo check`");
}
@ -90,11 +86,8 @@ pub(crate) fn run_jit(tcx: TyCtxt<'_>, backend_config: BackendConfig) -> ! {
tcx.dcx().fatal("can't jit non-executable crate");
}
let (mut jit_module, mut cx) = create_jit_module(
tcx,
&backend_config,
matches!(backend_config.codegen_mode, CodegenMode::JitLazy),
);
let (mut jit_module, mut cx) =
create_jit_module(tcx, matches!(codegen_mode, CodegenMode::JitLazy));
let mut cached_context = Context::new();
let (_, cgus) = tcx.collect_and_partition_mono_items(());
@ -110,7 +103,7 @@ pub(crate) fn run_jit(tcx: TyCtxt<'_>, backend_config: BackendConfig) -> ! {
super::predefine_mono_items(tcx, &mut jit_module, &mono_items);
for (mono_item, _) in mono_items {
match mono_item {
MonoItem::Fn(inst) => match backend_config.codegen_mode {
MonoItem::Fn(inst) => match codegen_mode {
CodegenMode::Aot => unreachable!(),
CodegenMode::Jit => {
codegen_and_compile_fn(
@ -151,7 +144,7 @@ pub(crate) fn run_jit(tcx: TyCtxt<'_>, backend_config: BackendConfig) -> ! {
);
let args = std::iter::once(&*tcx.crate_name(LOCAL_CRATE).as_str().to_string())
.chain(backend_config.jit_args.iter().map(|arg| &**arg))
.chain(jit_args.iter().map(|arg| &**arg))
.map(|arg| CString::new(arg).unwrap())
.collect::<Vec<_>>();
@ -211,7 +204,7 @@ pub(crate) fn codegen_and_compile_fn<'tcx>(
instance: Instance<'tcx>,
) {
cranelift_codegen::timing::set_thread_profiler(Box::new(super::MeasuremeProfiler(
cx.profiler.clone(),
tcx.prof.clone(),
)));
tcx.prof.generic_activity("codegen and compile fn").run(|| {
@ -227,7 +220,7 @@ pub(crate) fn codegen_and_compile_fn<'tcx>(
module,
instance,
) {
crate::base::compile_fn(cx, cached_context, module, codegened_func);
crate::base::compile_fn(cx, &tcx.prof, cached_context, module, codegened_func);
}
});
}

View File

@ -102,13 +102,12 @@ pub(crate) fn codegen_inline_asm_terminator<'tcx>(
// Pass a wrapper rather than the function itself as the function itself may not
// be exported from the main codegen unit and may thus be unreachable from the
// object file created by an external assembler.
let inline_asm_index = fx.cx.inline_asm_index.get();
fx.cx.inline_asm_index.set(inline_asm_index + 1);
let wrapper_name = format!(
"__inline_asm_{}_wrapper_n{}",
fx.cx.cgu_name.as_str().replace('.', "__").replace('-', "_"),
inline_asm_index
fx.cx.inline_asm_index
);
fx.cx.inline_asm_index += 1;
let sig =
get_function_sig(fx.tcx, fx.target_config.default_call_conv, instance);
create_wrapper_function(fx.module, sig, &wrapper_name, symbol.name);
@ -167,13 +166,12 @@ pub(crate) fn codegen_inline_asm_inner<'tcx>(
asm_gen.allocate_registers();
asm_gen.allocate_stack_slots();
let inline_asm_index = fx.cx.inline_asm_index.get();
fx.cx.inline_asm_index.set(inline_asm_index + 1);
let asm_name = format!(
"__inline_asm_{}_n{}",
fx.cx.cgu_name.as_str().replace('.', "__").replace('-', "_"),
inline_asm_index
fx.cx.inline_asm_index
);
fx.cx.inline_asm_index += 1;
let generated_asm = asm_gen.generate_asm_wrapper(&asm_name);
fx.cx.global_asm.push_str(&generated_asm);
@ -266,13 +264,12 @@ pub(crate) fn codegen_naked_asm<'tcx>(
// Pass a wrapper rather than the function itself as the function itself may not
// be exported from the main codegen unit and may thus be unreachable from the
// object file created by an external assembler.
let inline_asm_index = cx.inline_asm_index.get();
cx.inline_asm_index.set(inline_asm_index + 1);
let wrapper_name = format!(
"__inline_asm_{}_wrapper_n{}",
cx.cgu_name.as_str().replace('.', "__").replace('-', "_"),
inline_asm_index
cx.inline_asm_index
);
cx.inline_asm_index += 1;
let sig =
get_function_sig(tcx, module.target_config().default_call_conv, instance);
create_wrapper_function(module, sig, &wrapper_name, symbol.name);

View File

@ -1270,8 +1270,7 @@ fn codegen_regular_intrinsic_call<'tcx>(
}
sym::cold_path => {
// This is a no-op. The intrinsic is just a hint to the optimizer.
// We still have an impl here to avoid it being turned into a call.
fx.bcx.set_cold_block(fx.bcx.current_block().unwrap());
}
// Unimplemented intrinsics must have a fallback body. The fallback body is obtained

View File

@ -34,7 +34,7 @@ extern crate rustc_target;
extern crate rustc_driver;
use std::any::Any;
use std::cell::{Cell, RefCell};
use std::env;
use std::sync::Arc;
use cranelift_codegen::isa::TargetIsa;
@ -42,7 +42,6 @@ use cranelift_codegen::settings::{self, Configurable};
use rustc_codegen_ssa::CodegenResults;
use rustc_codegen_ssa::back::versioned_llvm_target;
use rustc_codegen_ssa::traits::CodegenBackend;
use rustc_data_structures::profiling::SelfProfilerRef;
use rustc_metadata::EncodedMetadata;
use rustc_middle::dep_graph::{WorkProduct, WorkProductId};
use rustc_session::Session;
@ -123,11 +122,10 @@ impl<F: Fn() -> String> Drop for PrintOnPanic<F> {
/// The codegen context holds any information shared between the codegen of individual functions
/// inside a single codegen unit with the exception of the Cranelift [`Module`](cranelift_module::Module).
struct CodegenCx {
profiler: SelfProfilerRef,
output_filenames: Arc<OutputFilenames>,
should_write_ir: bool,
global_asm: String,
inline_asm_index: Cell<usize>,
inline_asm_index: usize,
debug_context: Option<DebugContext>,
cgu_name: Symbol,
}
@ -142,11 +140,10 @@ impl CodegenCx {
None
};
CodegenCx {
profiler: tcx.prof.clone(),
output_filenames: tcx.output_filenames(()).clone(),
should_write_ir: crate::pretty_clif::should_write_ir(tcx),
global_asm: String::new(),
inline_asm_index: Cell::new(0),
inline_asm_index: 0,
debug_context,
cgu_name,
}
@ -154,7 +151,7 @@ impl CodegenCx {
}
pub struct CraneliftCodegenBackend {
pub config: RefCell<Option<BackendConfig>>,
pub config: Option<BackendConfig>,
}
impl CodegenBackend for CraneliftCodegenBackend {
@ -176,13 +173,6 @@ impl CodegenBackend for CraneliftCodegenBackend {
sess.dcx()
.fatal("`-Cinstrument-coverage` is LLVM specific and not supported by Cranelift");
}
let mut config = self.config.borrow_mut();
if config.is_none() {
let new_config = BackendConfig::from_opts(&sess.opts.cg.llvm_args)
.unwrap_or_else(|err| sess.dcx().fatal(err));
*config = Some(new_config);
}
}
fn target_features(&self, sess: &Session, _allow_unstable: bool) -> Vec<rustc_span::Symbol> {
@ -215,12 +205,15 @@ impl CodegenBackend for CraneliftCodegenBackend {
need_metadata_module: bool,
) -> Box<dyn Any> {
tcx.dcx().abort_if_errors();
let config = self.config.borrow().clone().unwrap();
let config = self.config.clone().unwrap_or_else(|| {
BackendConfig::from_opts(&tcx.sess.opts.cg.llvm_args)
.unwrap_or_else(|err| tcx.sess.dcx().fatal(err))
});
match config.codegen_mode {
CodegenMode::Aot => driver::aot::run_aot(tcx, config, metadata, need_metadata_module),
CodegenMode::Aot => driver::aot::run_aot(tcx, metadata, need_metadata_module),
CodegenMode::Jit | CodegenMode::JitLazy => {
#[cfg(feature = "jit")]
driver::jit::run_jit(tcx, config);
driver::jit::run_jit(tcx, config.codegen_mode, config.jit_args);
#[cfg(not(feature = "jit"))]
tcx.dcx().fatal("jit support was disabled when compiling rustc_codegen_cranelift");
@ -236,14 +229,20 @@ impl CodegenBackend for CraneliftCodegenBackend {
) -> (CodegenResults, FxIndexMap<WorkProductId, WorkProduct>) {
let _timer = sess.timer("finish_ongoing_codegen");
ongoing_codegen.downcast::<driver::aot::OngoingCodegen>().unwrap().join(
sess,
outputs,
self.config.borrow().as_ref().unwrap(),
)
ongoing_codegen.downcast::<driver::aot::OngoingCodegen>().unwrap().join(sess, outputs)
}
}
/// Determine if the Cranelift ir verifier should run.
///
/// Returns true when `-Zverify-llvm-ir` is passed, the `CG_CLIF_ENABLE_VERIFIER` env var is set to
/// 1 or when cg_clif is compiled with debug assertions enabled or false otherwise.
fn enable_verifier(sess: &Session) -> bool {
sess.verify_llvm_ir()
|| cfg!(debug_assertions)
|| env::var("CG_CLIF_ENABLE_VERIFIER").as_deref() == Ok("1")
}
fn target_triple(sess: &Session) -> target_lexicon::Triple {
// FIXME(madsmtm): Use `sess.target.llvm_target` once target-lexicon supports unversioned macOS.
// See <https://github.com/bytecodealliance/target-lexicon/pull/113>
@ -253,14 +252,14 @@ fn target_triple(sess: &Session) -> target_lexicon::Triple {
}
}
fn build_isa(sess: &Session, backend_config: &BackendConfig) -> Arc<dyn TargetIsa + 'static> {
fn build_isa(sess: &Session) -> Arc<dyn TargetIsa + 'static> {
use target_lexicon::BinaryFormat;
let target_triple = crate::target_triple(sess);
let mut flags_builder = settings::builder();
flags_builder.enable("is_pic").unwrap();
let enable_verifier = if backend_config.enable_verifier { "true" } else { "false" };
let enable_verifier = if enable_verifier(sess) { "true" } else { "false" };
flags_builder.set("enable_verifier", enable_verifier).unwrap();
flags_builder.set("regalloc_checker", enable_verifier).unwrap();
@ -295,6 +294,16 @@ fn build_isa(sess: &Session, backend_config: &BackendConfig) -> Arc<dyn TargetIs
}
}
if let target_lexicon::OperatingSystem::Windows = target_triple.operating_system {
// FIXME remove dependency on this from the Rust ABI. cc bytecodealliance/wasmtime#9510
flags_builder.enable("enable_multi_ret_implicit_sret").unwrap();
}
if let target_lexicon::Architecture::S390x = target_triple.architecture {
// FIXME remove dependency on this from the Rust ABI. cc bytecodealliance/wasmtime#9510
flags_builder.enable("enable_multi_ret_implicit_sret").unwrap();
}
if let target_lexicon::Architecture::Aarch64(_)
| target_lexicon::Architecture::Riscv64(_)
| target_lexicon::Architecture::X86_64 = target_triple.architecture
@ -347,5 +356,5 @@ fn build_isa(sess: &Session, backend_config: &BackendConfig) -> Arc<dyn TargetIs
/// This is the entrypoint for a hot plugged rustc_codegen_cranelift
#[no_mangle]
pub fn __rustc_codegen_backend() -> Box<dyn CodegenBackend> {
Box::new(CraneliftCodegenBackend { config: RefCell::new(None) })
Box::new(CraneliftCodegenBackend { config: None })
}

View File

@ -535,6 +535,8 @@ const PERMITTED_CRANELIFT_DEPENDENCIES: &[&str] = &[
"regalloc2",
"region",
"rustc-hash",
"serde",
"serde_derive",
"slice-group-by",
"smallvec",
"stable_deref_trait",