Skip to content

Commit

Permalink
Auto merge of #133956 - bjorn3:sync_cg_clif-2024-12-06, r=bjorn3
Browse files Browse the repository at this point in the history
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
  • Loading branch information
bors committed Dec 6, 2024
2 parents bc145ce + 063e21b commit cdeddae
Show file tree
Hide file tree
Showing 30 changed files with 398 additions and 428 deletions.
77 changes: 49 additions & 28 deletions compiler/rustc_codegen_cranelift/Cargo.lock
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand All @@ -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",
Expand All @@ -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",
Expand All @@ -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",
Expand All @@ -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",
Expand All @@ -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",
Expand Down Expand Up @@ -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"
Expand Down Expand Up @@ -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",
Expand Down
12 changes: 6 additions & 6 deletions compiler/rustc_codegen_cranelift/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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"] }
Expand Down
4 changes: 2 additions & 2 deletions compiler/rustc_codegen_cranelift/build_system/abi_cafe.rs
Original file line number Diff line number Diff line change
@@ -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};
Expand All @@ -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);

Expand Down
14 changes: 7 additions & 7 deletions compiler/rustc_codegen_cranelift/build_system/bench.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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};
Expand Down Expand Up @@ -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}",
Expand All @@ -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,
Expand All @@ -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,
Expand Down Expand Up @@ -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() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
22 changes: 12 additions & 10 deletions compiler/rustc_codegen_cranelift/build_system/build_sysroot.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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();

Expand Down Expand Up @@ -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");
Expand Down Expand Up @@ -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(
Expand All @@ -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 = {
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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") {
Expand Down Expand Up @@ -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")
Expand Down
5 changes: 2 additions & 3 deletions compiler/rustc_codegen_cranelift/build_system/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down
Loading

0 comments on commit cdeddae

Please sign in to comment.