Merge commit '57845a397e
' into sync_cg_clif-2024-12-06
This commit is contained in:
commit
b3d837afe1
29 changed files with 396 additions and 428 deletions
|
@ -46,24 +46,24 @@ checksum = "baf1de4339761588bc0619e3cbc0120ee582ebb74b53b4efbf79117bd2da40fd"
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "cranelift-bforest"
|
name = "cranelift-bforest"
|
||||||
version = "0.113.0"
|
version = "0.114.0"
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "8ea5e7afe85cadb55c4c1176268a2ac046fdff8dfaeca39e18581b9dc319ca9e"
|
checksum = "2ba4f80548f22dc9c43911907b5e322c5555544ee85f785115701e6a28c9abe1"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"cranelift-entity",
|
"cranelift-entity",
|
||||||
]
|
]
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "cranelift-bitset"
|
name = "cranelift-bitset"
|
||||||
version = "0.113.0"
|
version = "0.114.0"
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "8ab25ef3be935a80680e393183e1f94ef507e93a24a8369494d2c6818aedb3e3"
|
checksum = "005884e3649c3e5ff2dc79e8a94b138f11569cc08a91244a292714d2a86e9156"
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "cranelift-codegen"
|
name = "cranelift-codegen"
|
||||||
version = "0.113.0"
|
version = "0.114.0"
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "900a19b84545924f1851cbfe386962edfc4ecbc3366a254825cf1ecbcda8ba08"
|
checksum = "fe4036255ec33ce9a37495dfbcfc4e1118fd34e693eff9a1e106336b7cd16a9b"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"bumpalo",
|
"bumpalo",
|
||||||
"cranelift-bforest",
|
"cranelift-bforest",
|
||||||
|
@ -78,48 +78,49 @@ dependencies = [
|
||||||
"log",
|
"log",
|
||||||
"regalloc2",
|
"regalloc2",
|
||||||
"rustc-hash",
|
"rustc-hash",
|
||||||
|
"serde",
|
||||||
"smallvec",
|
"smallvec",
|
||||||
"target-lexicon",
|
"target-lexicon",
|
||||||
]
|
]
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "cranelift-codegen-meta"
|
name = "cranelift-codegen-meta"
|
||||||
version = "0.113.0"
|
version = "0.114.0"
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "08c73b2395ffe9e7b4fdf7e2ebc052e7e27af13f68a964985346be4da477a5fc"
|
checksum = "f7ca74f4b68319da11d39e894437cb6e20ec7c2e11fbbda823c3bf207beedff7"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"cranelift-codegen-shared",
|
"cranelift-codegen-shared",
|
||||||
]
|
]
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "cranelift-codegen-shared"
|
name = "cranelift-codegen-shared"
|
||||||
version = "0.113.0"
|
version = "0.114.0"
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "7d9ed0854e96a4ff0879bff39d078de8dea7f002721c9494c1fdb4e1baa86ccc"
|
checksum = "897e54f433a0269c4187871aa06d452214d5515d228d5bdc22219585e9eef895"
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "cranelift-control"
|
name = "cranelift-control"
|
||||||
version = "0.113.0"
|
version = "0.114.0"
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "b4aca921dd422e781409de0129c255768fec5dec1dae83239b497fb9138abb89"
|
checksum = "29cb4018f5bf59fb53f515fa9d80e6f8c5ce19f198dc538984ebd23ecf8965ec"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"arbitrary",
|
"arbitrary",
|
||||||
]
|
]
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "cranelift-entity"
|
name = "cranelift-entity"
|
||||||
version = "0.113.0"
|
version = "0.114.0"
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "e2d770e6605eccee15b49decdd82cd26f2b6404767802471459ea49c57379a98"
|
checksum = "305399fd781a2953ac78c1396f02ff53144f39c33eb7fc7789cf4e8936d13a96"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"cranelift-bitset",
|
"cranelift-bitset",
|
||||||
]
|
]
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "cranelift-frontend"
|
name = "cranelift-frontend"
|
||||||
version = "0.113.0"
|
version = "0.114.0"
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "29268711cb889cb39215b10faf88b9087d4c9e1d2633581e4f722a2bf4bb4ef9"
|
checksum = "9230b460a128d53653456137751d27baf567947a3ab8c0c4d6e31fd08036d81e"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"cranelift-codegen",
|
"cranelift-codegen",
|
||||||
"log",
|
"log",
|
||||||
|
@ -129,15 +130,15 @@ dependencies = [
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "cranelift-isle"
|
name = "cranelift-isle"
|
||||||
version = "0.113.0"
|
version = "0.114.0"
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "dc65156f010aed1985767ad1bff0eb8d186743b7b03e23d0c17604a253e3f356"
|
checksum = "b961e24ae3ec9813a24a15ae64bbd2a42e4de4d79a7f3225a412e3b94e78d1c8"
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "cranelift-jit"
|
name = "cranelift-jit"
|
||||||
version = "0.113.0"
|
version = "0.114.0"
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "40ba6b46367a4f466cfb1abe32793fa1a0f96d862251491b01a44726b8ed9445"
|
checksum = "62699329d4ced20fe281fbaef45e11b473b7ab310491b4bdebcd8b818a8ef7fe"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"anyhow",
|
"anyhow",
|
||||||
"cranelift-codegen",
|
"cranelift-codegen",
|
||||||
|
@ -155,9 +156,9 @@ dependencies = [
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "cranelift-module"
|
name = "cranelift-module"
|
||||||
version = "0.113.0"
|
version = "0.114.0"
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "007607022a4883ebdffc46c0925e2e10babf2a565ae78518034ade722aa825d2"
|
checksum = "2f20b0b51ba962dac30fc7e812b86e4390d908acd4f59bcc8ac7610a8f3e0977"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"anyhow",
|
"anyhow",
|
||||||
"cranelift-codegen",
|
"cranelift-codegen",
|
||||||
|
@ -166,9 +167,9 @@ dependencies = [
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "cranelift-native"
|
name = "cranelift-native"
|
||||||
version = "0.113.0"
|
version = "0.114.0"
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "d8bf9b361eaf5a7627647270fabf1dc910d993edbeaf272a652c107861ebe9c2"
|
checksum = "4d5bd76df6c9151188dfa428c863b33da5b34561b67f43c0cf3f24a794f9fa1f"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"cranelift-codegen",
|
"cranelift-codegen",
|
||||||
"libc",
|
"libc",
|
||||||
|
@ -177,9 +178,9 @@ dependencies = [
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "cranelift-object"
|
name = "cranelift-object"
|
||||||
version = "0.113.0"
|
version = "0.114.0"
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "30ca5c38fa00c0cd943035391bdcc84ed00748f17c66c682e410f5a62f234d44"
|
checksum = "ee231640a7ecceedd0f1f2782d9288db6a6908cc70675ed9427e3bf0ea6daacd"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"anyhow",
|
"anyhow",
|
||||||
"cranelift-codegen",
|
"cranelift-codegen",
|
||||||
|
@ -363,6 +364,26 @@ dependencies = [
|
||||||
"target-lexicon",
|
"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]]
|
[[package]]
|
||||||
name = "slice-group-by"
|
name = "slice-group-by"
|
||||||
version = "0.3.1"
|
version = "0.3.1"
|
||||||
|
@ -412,9 +433,9 @@ checksum = "49874b5167b65d7193b8aba1567f5c7d93d001cafc34600cee003eda787e483f"
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "wasmtime-jit-icache-coherence"
|
name = "wasmtime-jit-icache-coherence"
|
||||||
version = "26.0.0"
|
version = "27.0.0"
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "6e458e6a1a010a53f86ac8d75837c0c6b2ce3e54b7503b2f1dc5629a4a541f5a"
|
checksum = "91b218a92866f74f35162f5d03a4e0f62cd0e1cc624285b1014275e5d4575fad"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"anyhow",
|
"anyhow",
|
||||||
"cfg-if",
|
"cfg-if",
|
||||||
|
|
|
@ -8,12 +8,12 @@ crate-type = ["dylib"]
|
||||||
|
|
||||||
[dependencies]
|
[dependencies]
|
||||||
# These have to be in sync with each other
|
# 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-codegen = { version = "0.114.0", default-features = false, features = ["std", "unwind", "all-native-arch"] }
|
||||||
cranelift-frontend = { version = "0.113.0" }
|
cranelift-frontend = { version = "0.114.0" }
|
||||||
cranelift-module = { version = "0.113.0" }
|
cranelift-module = { version = "0.114.0" }
|
||||||
cranelift-native = { version = "0.113.0" }
|
cranelift-native = { version = "0.114.0" }
|
||||||
cranelift-jit = { version = "0.113.0", optional = true }
|
cranelift-jit = { version = "0.114.0", optional = true }
|
||||||
cranelift-object = { version = "0.113.0" }
|
cranelift-object = { version = "0.114.0" }
|
||||||
target-lexicon = "0.12.0"
|
target-lexicon = "0.12.0"
|
||||||
gimli = { version = "0.31", default-features = false, features = ["write"] }
|
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"] }
|
object = { version = "0.36", default-features = false, features = ["std", "read_core", "write", "archive", "coff", "elf", "macho", "pe"] }
|
||||||
|
|
|
@ -1,4 +1,4 @@
|
||||||
use crate::path::{Dirs, RelPath};
|
use crate::path::Dirs;
|
||||||
use crate::prepare::GitRepo;
|
use crate::prepare::GitRepo;
|
||||||
use crate::utils::{CargoProject, Compiler, spawn_and_wait};
|
use crate::utils::{CargoProject, Compiler, spawn_and_wait};
|
||||||
use crate::{CodegenBackend, SysrootKind, build_sysroot};
|
use crate::{CodegenBackend, SysrootKind, build_sysroot};
|
||||||
|
@ -20,7 +20,7 @@ pub(crate) fn run(
|
||||||
rustup_toolchain_name: Option<&str>,
|
rustup_toolchain_name: Option<&str>,
|
||||||
bootstrap_host_compiler: &Compiler,
|
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.fetch(dirs);
|
||||||
ABI_CAFE_REPO.patch(dirs);
|
ABI_CAFE_REPO.patch(dirs);
|
||||||
|
|
||||||
|
|
|
@ -3,7 +3,7 @@ use std::io::Write;
|
||||||
use std::path::Path;
|
use std::path::Path;
|
||||||
use std::process::Command;
|
use std::process::Command;
|
||||||
|
|
||||||
use crate::path::{Dirs, RelPath};
|
use crate::path::Dirs;
|
||||||
use crate::prepare::GitRepo;
|
use crate::prepare::GitRepo;
|
||||||
use crate::rustc_info::get_file_name;
|
use crate::rustc_info::get_file_name;
|
||||||
use crate::utils::{Compiler, spawn_and_wait};
|
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");
|
eprintln!("[BENCH COMPILE] ebobby/simple-raytracer");
|
||||||
let cargo_clif = RelPath::DIST
|
let cargo_clif = dirs
|
||||||
.to_path(dirs)
|
.dist_dir
|
||||||
.join(get_file_name(&bootstrap_host_compiler.rustc, "cargo_clif", "bin").replace('_', "-"));
|
.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 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!(
|
let clean_cmd = format!(
|
||||||
"RUSTC=rustc cargo clean --manifest-path {manifest_path} --target-dir {target_dir}",
|
"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(),
|
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(
|
let bench_compile = hyperfine_command(
|
||||||
1,
|
1,
|
||||||
|
@ -92,7 +92,7 @@ fn benchmark_simple_raytracer(dirs: &Dirs, bootstrap_host_compiler: &Compiler) {
|
||||||
|
|
||||||
eprintln!("[BENCH RUN] ebobby/simple-raytracer");
|
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(
|
let raytracer_cg_llvm = Path::new(".").join(get_file_name(
|
||||||
&bootstrap_host_compiler.rustc,
|
&bootstrap_host_compiler.rustc,
|
||||||
|
@ -120,7 +120,7 @@ fn benchmark_simple_raytracer(dirs: &Dirs, bootstrap_host_compiler: &Compiler) {
|
||||||
],
|
],
|
||||||
&bench_run_markdown,
|
&bench_run_markdown,
|
||||||
);
|
);
|
||||||
bench_run.current_dir(RelPath::BUILD.to_path(dirs));
|
bench_run.current_dir(&dirs.build_dir);
|
||||||
spawn_and_wait(bench_run);
|
spawn_and_wait(bench_run);
|
||||||
|
|
||||||
if let Some(gha_step_summary) = gha_step_summary.as_mut() {
|
if let Some(gha_step_summary) = gha_step_summary.as_mut() {
|
||||||
|
|
|
@ -6,7 +6,7 @@ use crate::rustc_info::get_file_name;
|
||||||
use crate::shared_utils::{rustflags_from_env, rustflags_to_cmd_env};
|
use crate::shared_utils::{rustflags_from_env, rustflags_to_cmd_env};
|
||||||
use crate::utils::{CargoProject, Compiler, LogGroup};
|
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(
|
pub(crate) fn build_backend(
|
||||||
dirs: &Dirs,
|
dirs: &Dirs,
|
||||||
|
|
|
@ -22,9 +22,9 @@ pub(crate) fn build_sysroot(
|
||||||
|
|
||||||
eprintln!("[BUILD] sysroot {:?}", sysroot_kind);
|
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("bin")).unwrap();
|
||||||
fs::create_dir_all(dist_dir.join("lib")).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 mut build_cargo_wrapper_cmd = Command::new(&bootstrap_host_compiler.rustc);
|
||||||
let wrapper_path = dist_dir.join(&wrapper_name);
|
let wrapper_path = dist_dir.join(&wrapper_name);
|
||||||
build_cargo_wrapper_cmd
|
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("-o")
|
||||||
.arg(&wrapper_path)
|
.arg(&wrapper_path)
|
||||||
.arg("-Cstrip=debuginfo");
|
.arg("-Cstrip=debuginfo");
|
||||||
|
@ -85,7 +85,7 @@ pub(crate) fn build_sysroot(
|
||||||
&cg_clif_dylib_path,
|
&cg_clif_dylib_path,
|
||||||
sysroot_kind,
|
sysroot_kind,
|
||||||
);
|
);
|
||||||
host.install_into_sysroot(&dist_dir);
|
host.install_into_sysroot(dist_dir);
|
||||||
|
|
||||||
if !is_native {
|
if !is_native {
|
||||||
build_sysroot_for_triple(
|
build_sysroot_for_triple(
|
||||||
|
@ -99,7 +99,7 @@ pub(crate) fn build_sysroot(
|
||||||
&cg_clif_dylib_path,
|
&cg_clif_dylib_path,
|
||||||
sysroot_kind,
|
sysroot_kind,
|
||||||
)
|
)
|
||||||
.install_into_sysroot(&dist_dir);
|
.install_into_sysroot(dist_dir);
|
||||||
}
|
}
|
||||||
|
|
||||||
let mut target_compiler = {
|
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 =
|
static STANDARD_LIBRARY: CargoProject =
|
||||||
CargoProject::new(&STDLIB_SRC.join("library/sysroot"), "stdlib_target");
|
CargoProject::new(&RelPath::build("stdlib/library/sysroot"), "stdlib_target");
|
||||||
static RTSTARTUP_SYSROOT: RelPath = RelPath::BUILD.join("rtstartup");
|
static RTSTARTUP_SYSROOT: RelPath = RelPath::build("rtstartup");
|
||||||
|
|
||||||
fn build_sysroot_for_triple(
|
fn build_sysroot_for_triple(
|
||||||
dirs: &Dirs,
|
dirs: &Dirs,
|
||||||
|
@ -247,6 +247,7 @@ fn build_clif_sysroot_for_triple(
|
||||||
let mut build_cmd = STANDARD_LIBRARY.build(&compiler, dirs);
|
let mut build_cmd = STANDARD_LIBRARY.build(&compiler, dirs);
|
||||||
build_cmd.arg("--release");
|
build_cmd.arg("--release");
|
||||||
build_cmd.arg("--features").arg("backtrace panic-unwind compiler-builtins-no-f16-f128");
|
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_PROFILE_RELEASE_DEBUG", "true");
|
||||||
build_cmd.env("__CARGO_DEFAULT_LIB_METADATA", "cg_clif");
|
build_cmd.env("__CARGO_DEFAULT_LIB_METADATA", "cg_clif");
|
||||||
if compiler.triple.contains("apple") {
|
if compiler.triple.contains("apple") {
|
||||||
|
@ -281,13 +282,14 @@ fn build_rtstartup(dirs: &Dirs, compiler: &Compiler) -> Option<SysrootTarget> {
|
||||||
return None;
|
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 rtstartup_src = STDLIB_SRC.to_path(dirs).join("library").join("rtstartup");
|
||||||
let mut target_libs = SysrootTarget { triple: compiler.triple.clone(), libs: vec![] };
|
let mut target_libs = SysrootTarget { triple: compiler.triple.clone(), libs: vec![] };
|
||||||
|
|
||||||
for file in ["rsbegin", "rsend"] {
|
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);
|
let mut build_rtstartup_cmd = Command::new(&compiler.rustc);
|
||||||
build_rtstartup_cmd
|
build_rtstartup_cmd
|
||||||
.arg("--target")
|
.arg("--target")
|
||||||
|
|
|
@ -185,12 +185,11 @@ fn main() {
|
||||||
frozen,
|
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
|
// Make sure we always explicitly specify the target dir
|
||||||
let target =
|
let target = dirs.build_dir.join("target_dir_should_be_set_explicitly");
|
||||||
path::RelPath::BUILD.join("target_dir_should_be_set_explicitly").to_path(&dirs);
|
|
||||||
env::set_var("CARGO_TARGET_DIR", &target);
|
env::set_var("CARGO_TARGET_DIR", &target);
|
||||||
let _ = std::fs::remove_file(&target);
|
let _ = std::fs::remove_file(&target);
|
||||||
std::fs::File::create(target).unwrap();
|
std::fs::File::create(target).unwrap();
|
||||||
|
|
|
@ -1,8 +1,5 @@
|
||||||
use std::fs;
|
|
||||||
use std::path::PathBuf;
|
use std::path::PathBuf;
|
||||||
|
|
||||||
use crate::utils::ensure_empty_dir;
|
|
||||||
|
|
||||||
#[derive(Debug, Clone)]
|
#[derive(Debug, Clone)]
|
||||||
pub(crate) struct Dirs {
|
pub(crate) struct Dirs {
|
||||||
pub(crate) source_dir: PathBuf,
|
pub(crate) source_dir: PathBuf,
|
||||||
|
@ -16,54 +13,34 @@ pub(crate) struct Dirs {
|
||||||
#[derive(Debug, Copy, Clone)]
|
#[derive(Debug, Copy, Clone)]
|
||||||
pub(crate) enum PathBase {
|
pub(crate) enum PathBase {
|
||||||
Source,
|
Source,
|
||||||
Download,
|
|
||||||
Build,
|
Build,
|
||||||
Dist,
|
|
||||||
}
|
}
|
||||||
|
|
||||||
impl PathBase {
|
impl PathBase {
|
||||||
fn to_path(self, dirs: &Dirs) -> PathBuf {
|
fn to_path(self, dirs: &Dirs) -> PathBuf {
|
||||||
match self {
|
match self {
|
||||||
PathBase::Source => dirs.source_dir.clone(),
|
PathBase::Source => dirs.source_dir.clone(),
|
||||||
PathBase::Download => dirs.download_dir.clone(),
|
|
||||||
PathBase::Build => dirs.build_dir.clone(),
|
PathBase::Build => dirs.build_dir.clone(),
|
||||||
PathBase::Dist => dirs.dist_dir.clone(),
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Debug, Copy, Clone)]
|
#[derive(Debug, Copy, Clone)]
|
||||||
pub(crate) enum RelPath {
|
pub(crate) struct RelPath {
|
||||||
Base(PathBase),
|
base: PathBase,
|
||||||
Join(&'static RelPath, &'static str),
|
suffix: &'static str,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl RelPath {
|
impl RelPath {
|
||||||
pub(crate) const SOURCE: RelPath = RelPath::Base(PathBase::Source);
|
pub(crate) const fn source(suffix: &'static str) -> RelPath {
|
||||||
pub(crate) const DOWNLOAD: RelPath = RelPath::Base(PathBase::Download);
|
RelPath { base: PathBase::Source, suffix }
|
||||||
pub(crate) const BUILD: RelPath = RelPath::Base(PathBase::Build);
|
}
|
||||||
pub(crate) const DIST: RelPath = RelPath::Base(PathBase::Dist);
|
|
||||||
|
|
||||||
pub(crate) const SCRIPTS: RelPath = RelPath::SOURCE.join("scripts");
|
pub(crate) const fn build(suffix: &'static str) -> RelPath {
|
||||||
pub(crate) const PATCHES: RelPath = RelPath::SOURCE.join("patches");
|
RelPath { base: PathBase::Build, suffix }
|
||||||
|
|
||||||
pub(crate) const fn join(&'static self, suffix: &'static str) -> RelPath {
|
|
||||||
RelPath::Join(self, suffix)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
pub(crate) fn to_path(&self, dirs: &Dirs) -> PathBuf {
|
pub(crate) fn to_path(&self, dirs: &Dirs) -> PathBuf {
|
||||||
match self {
|
self.base.to_path(dirs).join(self.suffix)
|
||||||
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);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -8,7 +8,7 @@ use crate::path::{Dirs, RelPath};
|
||||||
use crate::utils::{copy_dir_recursively, ensure_empty_dir, spawn_and_wait};
|
use crate::utils::{copy_dir_recursively, ensure_empty_dir, spawn_and_wait};
|
||||||
|
|
||||||
pub(crate) fn prepare(dirs: &Dirs) {
|
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::RAND_REPO.fetch(dirs);
|
||||||
crate::tests::REGEX_REPO.fetch(dirs);
|
crate::tests::REGEX_REPO.fetch(dirs);
|
||||||
}
|
}
|
||||||
|
@ -79,13 +79,13 @@ impl GitRepo {
|
||||||
|
|
||||||
fn download_dir(&self, dirs: &Dirs) -> PathBuf {
|
fn download_dir(&self, dirs: &Dirs) -> PathBuf {
|
||||||
match self.url {
|
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 {
|
pub(crate) const fn source_dir(&self) -> RelPath {
|
||||||
match self.url {
|
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 =
|
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");
|
let target_lockfile = download_dir.join("Cargo.lock");
|
||||||
if source_lockfile.exists() {
|
if source_lockfile.exists() {
|
||||||
assert!(!target_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> {
|
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()
|
.unwrap()
|
||||||
.map(|entry| entry.unwrap().path())
|
.map(|entry| entry.unwrap().path())
|
||||||
.filter(|path| path.extension() == Some(OsStr::new("patch")))
|
.filter(|path| path.extension() == Some(OsStr::new("patch")))
|
||||||
|
|
|
@ -7,10 +7,10 @@ use crate::path::{Dirs, RelPath};
|
||||||
use crate::prepare::{GitRepo, apply_patches};
|
use crate::prepare::{GitRepo, apply_patches};
|
||||||
use crate::rustc_info::get_default_sysroot;
|
use crate::rustc_info::get_default_sysroot;
|
||||||
use crate::shared_utils::rustflags_from_env;
|
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};
|
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 {
|
struct TestCase {
|
||||||
config: &'static str,
|
config: &'static str,
|
||||||
|
@ -129,11 +129,11 @@ pub(crate) static REGEX_REPO: GitRepo = GitRepo::github(
|
||||||
|
|
||||||
static REGEX: CargoProject = CargoProject::new(®EX_REPO.source_dir(), "regex_target");
|
static REGEX: CargoProject = CargoProject::new(®EX_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 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");
|
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),
|
&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");
|
let target_lockfile = LIBCORE_TESTS_SRC.to_path(&runner.dirs).join("Cargo.lock");
|
||||||
fs::copy(source_lockfile, target_lockfile).unwrap();
|
fs::copy(source_lockfile, target_lockfile).unwrap();
|
||||||
|
|
||||||
|
@ -267,7 +267,9 @@ pub(crate) fn run_tests(
|
||||||
stdlib_source.clone(),
|
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);
|
runner.run_testsuite(NO_SYSROOT_SUITE);
|
||||||
} else {
|
} else {
|
||||||
eprintln!("[SKIP] no_sysroot tests");
|
eprintln!("[SKIP] no_sysroot tests");
|
||||||
|
|
|
@ -93,7 +93,7 @@ impl CargoProject {
|
||||||
}
|
}
|
||||||
|
|
||||||
pub(crate) fn target_dir(&self, dirs: &Dirs) -> PathBuf {
|
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]
|
#[must_use]
|
||||||
|
|
|
@ -8,6 +8,9 @@
|
||||||
unboxed_closures
|
unboxed_closures
|
||||||
)]
|
)]
|
||||||
#![allow(internal_features)]
|
#![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")]
|
#[cfg(target_arch = "x86_64")]
|
||||||
use std::arch::x86_64::*;
|
use std::arch::x86_64::*;
|
||||||
|
|
|
@ -38,7 +38,7 @@ index 42a26ae..5ac1042 100644
|
||||||
@@ -1,3 +1,4 @@
|
@@ -1,3 +1,4 @@
|
||||||
+#![cfg(test)]
|
+#![cfg(test)]
|
||||||
// tidy-alphabetical-start
|
// tidy-alphabetical-start
|
||||||
#![cfg_attr(bootstrap, feature(const_three_way_compare))]
|
#![cfg_attr(target_has_atomic = "128", feature(integer_atomics))]
|
||||||
#![cfg_attr(bootstrap, feature(strict_provenance))]
|
#![cfg_attr(test, feature(cfg_match))]
|
||||||
--
|
--
|
||||||
2.21.0 (Apple Git-122)
|
2.21.0 (Apple Git-122)
|
||||||
|
|
|
@ -14,10 +14,9 @@ diff --git a/lib.rs b/lib.rs
|
||||||
index 1e336bf..35e6f54 100644
|
index 1e336bf..35e6f54 100644
|
||||||
--- a/lib.rs
|
--- a/lib.rs
|
||||||
+++ b/lib.rs
|
+++ b/lib.rs
|
||||||
@@ -2,7 +2,6 @@
|
@@ -2,6 +2,5 @@
|
||||||
#![cfg_attr(bootstrap, feature(const_three_way_compare))]
|
#![cfg(test)]
|
||||||
#![cfg_attr(bootstrap, feature(strict_provenance))]
|
// tidy-alphabetical-start
|
||||||
#![cfg_attr(not(bootstrap), feature(strict_provenance_lints))]
|
|
||||||
-#![cfg_attr(target_has_atomic = "128", feature(integer_atomics))]
|
-#![cfg_attr(target_has_atomic = "128", feature(integer_atomics))]
|
||||||
#![cfg_attr(test, feature(cfg_match))]
|
#![cfg_attr(test, feature(cfg_match))]
|
||||||
#![feature(alloc_layout_extra)]
|
#![feature(alloc_layout_extra)]
|
||||||
|
|
|
@ -4,22 +4,23 @@ Date: Fri, 9 Aug 2024 15:44:51 +0000
|
||||||
Subject: [PATCH] Disable f16 and f128 in compiler-builtins
|
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(-)
|
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
|
index 7165c3e48af..968552ad435 100644
|
||||||
--- a/library/sysroot/Cargo.toml
|
--- a/library/alloc/Cargo.toml
|
||||||
+++ b/library/sysroot/Cargo.toml
|
+++ b/library/alloc/Cargo.toml
|
||||||
@@ -11,7 +11,7 @@ test = { path = "../test" }
|
@@ -11,7 +11,7 @@ test = { path = "../test" }
|
||||||
|
edition = "2021"
|
||||||
|
|
||||||
# Forward features to the `std` crate as necessary
|
[dependencies]
|
||||||
[features]
|
core = { path = "../core" }
|
||||||
-default = ["std_detect_file_io", "std_detect_dlsym_getauxval", "panic-unwind"]
|
-compiler_builtins = { version = "=0.1.138", features = ['rustc-dep-of-std'] }
|
||||||
+default = ["std_detect_file_io", "std_detect_dlsym_getauxval", "panic-unwind", "compiler-builtins-no-f16-f128"]
|
+compiler_builtins = { version = "=0.1.138", features = ['rustc-dep-of-std', 'no-f16-f128'] }
|
||||||
backtrace = ["std/backtrace"]
|
|
||||||
compiler-builtins-c = ["std/compiler-builtins-c"]
|
[dev-dependencies]
|
||||||
compiler-builtins-mem = ["std/compiler-builtins-mem"]
|
rand = { version = "0.8.5", default-features = false, features = ["alloc"] }
|
||||||
--
|
--
|
||||||
2.34.1
|
2.34.1
|
||||||
|
|
||||||
|
|
|
@ -1,4 +1,4 @@
|
||||||
[toolchain]
|
[toolchain]
|
||||||
channel = "nightly-2024-11-09"
|
channel = "nightly-2024-12-06"
|
||||||
components = ["rust-src", "rustc-dev", "llvm-tools"]
|
components = ["rust-src", "rustc-dev", "llvm-tools"]
|
||||||
profile = "minimal"
|
profile = "minimal"
|
||||||
|
|
|
@ -33,6 +33,11 @@ fn main() {
|
||||||
args.push(OsString::from("--sysroot"));
|
args.push(OsString::from("--sysroot"));
|
||||||
args.push(OsString::from(sysroot.to_str().unwrap()));
|
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);
|
args.extend(passed_args);
|
||||||
|
|
||||||
let rustc = if let Some(rustc) = option_env!("RUSTC") {
|
let rustc = if let Some(rustc) = option_env!("RUSTC") {
|
||||||
|
|
|
@ -35,13 +35,14 @@ full-bootstrap = true
|
||||||
local-rebuild = true
|
local-rebuild = true
|
||||||
|
|
||||||
[rust]
|
[rust]
|
||||||
|
download-rustc = false
|
||||||
codegen-backends = ["cranelift"]
|
codegen-backends = ["cranelift"]
|
||||||
deny-warnings = false
|
deny-warnings = false
|
||||||
verbose-tests = false
|
verbose-tests = false
|
||||||
# The cg_clif sysroot doesn't contain llvm tools and unless llvm_tools is
|
# 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
|
# disabled bootstrap will crash trying to copy llvm tools for the bootstrap
|
||||||
# compiler.
|
# compiler.
|
||||||
llvm_tools = false
|
llvm-tools = false
|
||||||
|
|
||||||
EOF
|
EOF
|
||||||
popd
|
popd
|
||||||
|
|
|
@ -11,22 +11,5 @@ rm -r compiler/rustc_codegen_cranelift/{Cargo.*,src}
|
||||||
cp ../Cargo.* compiler/rustc_codegen_cranelift/
|
cp ../Cargo.* compiler/rustc_codegen_cranelift/
|
||||||
cp -r ../src compiler/rustc_codegen_cranelift/src
|
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
|
./x.py build --stage 1 library/std
|
||||||
popd
|
popd
|
||||||
|
|
|
@ -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/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 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 -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
|
# requires LTO
|
||||||
rm -r tests/run-make/cdylib
|
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/half-open-range-patterns/half-open-range-pats-semantics.rs
|
||||||
rm tests/ui/asm/aarch64/type-f16.rs
|
rm tests/ui/asm/aarch64/type-f16.rs
|
||||||
rm tests/ui/float/conv-bits-runtime-const.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
|
# optimization tests
|
||||||
# ==================
|
# ==================
|
||||||
|
|
|
@ -125,8 +125,9 @@ impl<'tcx> FunctionCx<'_, '_, 'tcx> {
|
||||||
returns: Vec<AbiParam>,
|
returns: Vec<AbiParam>,
|
||||||
args: &[Value],
|
args: &[Value],
|
||||||
) -> Cow<'_, [Value]> {
|
) -> Cow<'_, [Value]> {
|
||||||
if self.tcx.sess.target.is_like_windows {
|
// Pass i128 arguments by-ref on Windows.
|
||||||
let (mut params, mut args): (Vec<_>, Vec<_>) = params
|
let (params, args): (Vec<_>, Cow<'_, [_]>) = if self.tcx.sess.target.is_like_windows {
|
||||||
|
let (params, args): (Vec<_>, Vec<_>) = params
|
||||||
.into_iter()
|
.into_iter()
|
||||||
.zip(args)
|
.zip(args)
|
||||||
.map(|(param, &arg)| {
|
.map(|(param, &arg)| {
|
||||||
|
@ -140,29 +141,42 @@ impl<'tcx> FunctionCx<'_, '_, 'tcx> {
|
||||||
})
|
})
|
||||||
.unzip();
|
.unzip();
|
||||||
|
|
||||||
let indirect_ret_val = returns.len() == 1 && returns[0].value_type == types::I128;
|
(params, args.into())
|
||||||
|
} else {
|
||||||
|
(params, args.into())
|
||||||
|
};
|
||||||
|
|
||||||
|
// 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 {
|
||||||
|
false
|
||||||
|
};
|
||||||
|
|
||||||
|
if adjust_ret_param {
|
||||||
|
let mut params = params;
|
||||||
|
let mut args = args.to_vec();
|
||||||
|
|
||||||
if indirect_ret_val {
|
|
||||||
params.insert(0, AbiParam::new(self.pointer_type));
|
params.insert(0, AbiParam::new(self.pointer_type));
|
||||||
let ret_ptr = self.create_stack_slot(16, 16);
|
let ret_ptr = self.create_stack_slot(16, 16);
|
||||||
args.insert(0, ret_ptr.get_addr(self));
|
args.insert(0, ret_ptr.get_addr(self));
|
||||||
|
|
||||||
self.lib_call_unadjusted(name, params, vec![], &args);
|
self.lib_call_unadjusted(name, params, vec![], &args);
|
||||||
return Cow::Owned(vec![ret_ptr.load(self, types::I128, MemFlags::trusted())]);
|
|
||||||
|
Cow::Owned(vec![ret_ptr.load(self, types::I128, MemFlags::trusted())])
|
||||||
} else {
|
} else {
|
||||||
return self.lib_call_unadjusted(name, params, returns, &args);
|
Cow::Borrowed(self.lib_call_unadjusted(name, params, returns, &args))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
self.lib_call_unadjusted(name, params, returns, args)
|
fn lib_call_unadjusted(
|
||||||
}
|
|
||||||
|
|
||||||
pub(crate) fn lib_call_unadjusted(
|
|
||||||
&mut self,
|
&mut self,
|
||||||
name: &str,
|
name: &str,
|
||||||
params: Vec<AbiParam>,
|
params: Vec<AbiParam>,
|
||||||
returns: Vec<AbiParam>,
|
returns: Vec<AbiParam>,
|
||||||
args: &[Value],
|
args: &[Value],
|
||||||
) -> Cow<'_, [Value]> {
|
) -> &[Value] {
|
||||||
let sig = Signature { params, returns, call_conv: self.target_config.default_call_conv };
|
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_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);
|
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);
|
let results = self.bcx.inst_results(call_inst);
|
||||||
assert!(results.len() <= 2, "{}", results.len());
|
assert!(results.len() <= 2, "{}", results.len());
|
||||||
Cow::Borrowed(results)
|
results
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -6,6 +6,7 @@ use cranelift_frontend::{FunctionBuilder, FunctionBuilderContext};
|
||||||
use cranelift_module::ModuleError;
|
use cranelift_module::ModuleError;
|
||||||
use rustc_ast::InlineAsmOptions;
|
use rustc_ast::InlineAsmOptions;
|
||||||
use rustc_codegen_ssa::base::is_call_from_compiler_builtins_to_upstream_monomorphization;
|
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_index::IndexVec;
|
||||||
use rustc_middle::middle::codegen_fn_attrs::CodegenFnAttrFlags;
|
use rustc_middle::middle::codegen_fn_attrs::CodegenFnAttrFlags;
|
||||||
use rustc_middle::mir::InlineAsmMacro;
|
use rustc_middle::mir::InlineAsmMacro;
|
||||||
|
@ -16,6 +17,7 @@ use rustc_middle::ty::print::with_no_trimmed_paths;
|
||||||
|
|
||||||
use crate::constant::ConstantCx;
|
use crate::constant::ConstantCx;
|
||||||
use crate::debuginfo::{FunctionDebugContext, TypeDebugContext};
|
use crate::debuginfo::{FunctionDebugContext, TypeDebugContext};
|
||||||
|
use crate::enable_verifier;
|
||||||
use crate::inline_asm::codegen_naked_asm;
|
use crate::inline_asm::codegen_naked_asm;
|
||||||
use crate::prelude::*;
|
use crate::prelude::*;
|
||||||
use crate::pretty_clif::CommentWriter;
|
use crate::pretty_clif::CommentWriter;
|
||||||
|
@ -169,12 +171,13 @@ pub(crate) fn codegen_fn<'tcx>(
|
||||||
|
|
||||||
pub(crate) fn compile_fn(
|
pub(crate) fn compile_fn(
|
||||||
cx: &mut crate::CodegenCx,
|
cx: &mut crate::CodegenCx,
|
||||||
|
profiler: &SelfProfilerRef,
|
||||||
cached_context: &mut Context,
|
cached_context: &mut Context,
|
||||||
module: &mut dyn Module,
|
module: &mut dyn Module,
|
||||||
codegened_func: CodegenedFunction,
|
codegened_func: CodegenedFunction,
|
||||||
) {
|
) {
|
||||||
let _timer =
|
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;
|
let clif_comments = codegened_func.clif_comments;
|
||||||
|
|
||||||
|
@ -212,7 +215,7 @@ pub(crate) fn compile_fn(
|
||||||
};
|
};
|
||||||
|
|
||||||
// Define function
|
// Define function
|
||||||
cx.profiler.generic_activity("define function").run(|| {
|
profiler.generic_activity("define function").run(|| {
|
||||||
context.want_disasm = cx.should_write_ir;
|
context.want_disasm = cx.should_write_ir;
|
||||||
match module.define_function(codegened_func.func_id, context) {
|
match module.define_function(codegened_func.func_id, context) {
|
||||||
Ok(()) => {}
|
Ok(()) => {}
|
||||||
|
@ -253,7 +256,7 @@ pub(crate) fn compile_fn(
|
||||||
|
|
||||||
// Define debuginfo for function
|
// Define debuginfo for function
|
||||||
let debug_context = &mut cx.debug_context;
|
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 {
|
if let Some(debug_context) = debug_context {
|
||||||
codegened_func.func_debug_cx.unwrap().finalize(
|
codegened_func.func_debug_cx.unwrap().finalize(
|
||||||
debug_context,
|
debug_context,
|
||||||
|
@ -264,11 +267,11 @@ pub(crate) fn compile_fn(
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
pub(crate) fn verify_func(
|
fn verify_func(tcx: TyCtxt<'_>, writer: &crate::pretty_clif::CommentWriter, func: &Function) {
|
||||||
tcx: TyCtxt<'_>,
|
if !enable_verifier(tcx.sess) {
|
||||||
writer: &crate::pretty_clif::CommentWriter,
|
return;
|
||||||
func: &Function,
|
}
|
||||||
) {
|
|
||||||
tcx.prof.generic_activity("verify clif ir").run(|| {
|
tcx.prof.generic_activity("verify clif ir").run(|| {
|
||||||
let flags = cranelift_codegen::settings::Flags::new(cranelift_codegen::settings::builder());
|
let flags = cranelift_codegen::settings::Flags::new(cranelift_codegen::settings::builder());
|
||||||
match cranelift_codegen::verify_function(&func, &flags) {
|
match cranelift_codegen::verify_function(&func, &flags) {
|
||||||
|
|
|
@ -81,26 +81,6 @@ pub(crate) fn maybe_codegen_checked<'tcx>(
|
||||||
match bin_op {
|
match bin_op {
|
||||||
BinOp::BitAnd | BinOp::BitOr | BinOp::BitXor => unreachable!(),
|
BinOp::BitAnd | BinOp::BitOr | BinOp::BitXor => unreachable!(),
|
||||||
BinOp::Add | BinOp::Sub => None,
|
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 => {
|
BinOp::Mul => {
|
||||||
let out_ty = Ty::new_tup(fx.tcx, &[lhs.layout().ty, fx.tcx.types.bool]);
|
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));
|
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),
|
AbiParam::new(types::I128),
|
||||||
];
|
];
|
||||||
let args = [out_place.to_ptr().get_addr(fx), lhs.load_scalar(fx), rhs.load_scalar(fx)];
|
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))
|
Some(out_place.to_cvalue(fx))
|
||||||
}
|
}
|
||||||
BinOp::AddUnchecked | BinOp::SubUnchecked | BinOp::MulUnchecked => unreachable!(),
|
BinOp::AddUnchecked | BinOp::SubUnchecked | BinOp::MulUnchecked => unreachable!(),
|
||||||
|
|
|
@ -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.
|
/// The mode to use for compilation.
|
||||||
#[derive(Copy, Clone, Debug)]
|
#[derive(Copy, Clone, Debug)]
|
||||||
pub enum CodegenMode {
|
pub enum CodegenMode {
|
||||||
|
@ -16,19 +9,6 @@ pub enum CodegenMode {
|
||||||
JitLazy,
|
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.
|
/// Configuration of cg_clif as passed in through `-Cllvm-args` and various env vars.
|
||||||
#[derive(Clone, Debug)]
|
#[derive(Clone, Debug)]
|
||||||
pub struct BackendConfig {
|
pub struct BackendConfig {
|
||||||
|
@ -41,51 +21,22 @@ pub struct BackendConfig {
|
||||||
///
|
///
|
||||||
/// Defaults to the value of `CG_CLIF_JIT_ARGS`.
|
/// Defaults to the value of `CG_CLIF_JIT_ARGS`.
|
||||||
pub jit_args: Vec<String>,
|
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 {
|
impl BackendConfig {
|
||||||
/// Parse the configuration passed in using `-Cllvm-args`.
|
/// Parse the configuration passed in using `-Cllvm-args`.
|
||||||
pub fn from_opts(opts: &[String]) -> Result<Self, String> {
|
pub fn from_opts(opts: &[String]) -> Result<Self, String> {
|
||||||
fn parse_bool(name: &str, value: &str) -> Result<bool, String> {
|
let mut config = BackendConfig {
|
||||||
value.parse().map_err(|_| format!("failed to parse value `{}` for {}", value, name))
|
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 {
|
for opt in opts {
|
||||||
if opt.starts_with("-import-instr-limit") {
|
if opt.starts_with("-import-instr-limit") {
|
||||||
// Silently ignore -import-instr-limit. It is set by rust's build system even when
|
// 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('=') {
|
if let Some((name, value)) = opt.split_once('=') {
|
||||||
match name {
|
match name {
|
||||||
"mode" => config.codegen_mode = value.parse()?,
|
"mode" => {
|
||||||
"enable_verifier" => config.enable_verifier = parse_bool(name, value)?,
|
config.codegen_mode = match value {
|
||||||
"disable_incr_cache" => config.disable_incr_cache = parse_bool(name, value)?,
|
"aot" => CodegenMode::Aot,
|
||||||
|
"jit" => CodegenMode::Jit,
|
||||||
|
"jit-lazy" => CodegenMode::JitLazy,
|
||||||
|
_ => return Err(format!("Unknown codegen mode `{}`", value)),
|
||||||
|
};
|
||||||
|
}
|
||||||
_ => return Err(format!("Unknown option `{}`", name)),
|
_ => return Err(format!("Unknown option `{}`", name)),
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
|
|
|
@ -1,6 +1,7 @@
|
||||||
//! The AOT driver uses [`cranelift_object`] to write object files suitable for linking into a
|
//! The AOT driver uses [`cranelift_object`] to write object files suitable for linking into a
|
||||||
//! standalone executable.
|
//! standalone executable.
|
||||||
|
|
||||||
|
use std::env;
|
||||||
use std::fs::{self, File};
|
use std::fs::{self, File};
|
||||||
use std::io::BufWriter;
|
use std::io::BufWriter;
|
||||||
use std::path::{Path, PathBuf};
|
use std::path::{Path, PathBuf};
|
||||||
|
@ -25,13 +26,18 @@ use rustc_middle::mir::mono::{CodegenUnit, MonoItem};
|
||||||
use rustc_session::Session;
|
use rustc_session::Session;
|
||||||
use rustc_session::config::{DebugInfo, OutFileName, OutputFilenames, OutputType};
|
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::concurrency_limiter::{ConcurrencyLimiter, ConcurrencyLimiterToken};
|
||||||
use crate::debuginfo::TypeDebugContext;
|
use crate::debuginfo::TypeDebugContext;
|
||||||
use crate::global_asm::GlobalAsmConfig;
|
use crate::global_asm::GlobalAsmConfig;
|
||||||
use crate::prelude::*;
|
use crate::prelude::*;
|
||||||
use crate::unwind_module::UnwindModule;
|
use crate::unwind_module::UnwindModule;
|
||||||
|
|
||||||
|
fn disable_incr_cache() -> bool {
|
||||||
|
env::var("CG_CLIF_DISABLE_INCR_CACHE").as_deref() == Ok("1")
|
||||||
|
}
|
||||||
|
|
||||||
struct ModuleCodegenResult {
|
struct ModuleCodegenResult {
|
||||||
module_regular: CompiledModule,
|
module_regular: CompiledModule,
|
||||||
module_global_asm: Option<CompiledModule>,
|
module_global_asm: Option<CompiledModule>,
|
||||||
|
@ -63,10 +69,10 @@ impl OngoingCodegen {
|
||||||
self,
|
self,
|
||||||
sess: &Session,
|
sess: &Session,
|
||||||
outputs: &OutputFilenames,
|
outputs: &OutputFilenames,
|
||||||
backend_config: &BackendConfig,
|
|
||||||
) -> (CodegenResults, FxIndexMap<WorkProductId, WorkProduct>) {
|
) -> (CodegenResults, FxIndexMap<WorkProductId, WorkProduct>) {
|
||||||
let mut work_products = FxIndexMap::default();
|
let mut work_products = FxIndexMap::default();
|
||||||
let mut modules = vec![];
|
let mut modules = vec![];
|
||||||
|
let disable_incr_cache = disable_incr_cache();
|
||||||
|
|
||||||
for module_codegen in self.modules {
|
for module_codegen in self.modules {
|
||||||
let module_codegen_result = match module_codegen {
|
let module_codegen_result = match module_codegen {
|
||||||
|
@ -87,7 +93,7 @@ impl OngoingCodegen {
|
||||||
if let Some((work_product_id, work_product)) = existing_work_product {
|
if let Some((work_product_id, work_product)) = existing_work_product {
|
||||||
work_products.insert(work_product_id, work_product);
|
work_products.insert(work_product_id, work_product);
|
||||||
} else {
|
} else {
|
||||||
let work_product = if backend_config.disable_incr_cache {
|
let work_product = if disable_incr_cache {
|
||||||
None
|
None
|
||||||
} else if let Some(module_global_asm) = &module_global_asm {
|
} else if let Some(module_global_asm) = &module_global_asm {
|
||||||
rustc_incremental::copy_cgu_workproduct_to_incr_comp_cache_dir(
|
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.
|
// These are used in linking steps and will be cleaned up afterward.
|
||||||
}
|
}
|
||||||
|
|
||||||
fn make_module(
|
fn make_module(sess: &Session, name: String) -> UnwindModule<ObjectModule> {
|
||||||
sess: &Session,
|
let isa = crate::build_isa(sess);
|
||||||
backend_config: &BackendConfig,
|
|
||||||
name: String,
|
|
||||||
) -> UnwindModule<ObjectModule> {
|
|
||||||
let isa = crate::build_isa(sess, backend_config);
|
|
||||||
|
|
||||||
let mut builder =
|
let mut builder =
|
||||||
ObjectBuilder::new(isa, name + ".o", cranelift_module::default_libcall_names()).unwrap();
|
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)),
|
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 {
|
Ok(CompiledModule {
|
||||||
name,
|
name,
|
||||||
|
@ -486,22 +494,16 @@ fn reuse_workproduct_for_cgu(
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
fn module_codegen(
|
fn codegen_cgu_content(
|
||||||
tcx: TyCtxt<'_>,
|
tcx: TyCtxt<'_>,
|
||||||
(backend_config, global_asm_config, cgu_name, token): (
|
module: &mut dyn Module,
|
||||||
BackendConfig,
|
cgu_name: rustc_span::Symbol,
|
||||||
Arc<GlobalAsmConfig>,
|
) -> (CodegenCx, Vec<CodegenedFunction>) {
|
||||||
rustc_span::Symbol,
|
let _timer = tcx.prof.generic_activity_with_arg("codegen cgu", cgu_name.as_str());
|
||||||
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 cgu = tcx.codegen_unit(cgu_name);
|
||||||
let mono_items = cgu.items_in_deterministic_order(tcx);
|
let mono_items = cgu.items_in_deterministic_order(tcx);
|
||||||
|
|
||||||
let mut module = make_module(tcx.sess, &backend_config, cgu_name.as_str().to_string());
|
|
||||||
|
|
||||||
let mut cx = crate::CodegenCx::new(
|
let mut cx = crate::CodegenCx::new(
|
||||||
tcx,
|
tcx,
|
||||||
module.isa(),
|
module.isa(),
|
||||||
|
@ -509,7 +511,7 @@ fn module_codegen(
|
||||||
cgu_name,
|
cgu_name,
|
||||||
);
|
);
|
||||||
let mut type_dbg = TypeDebugContext::default();
|
let mut type_dbg = TypeDebugContext::default();
|
||||||
super::predefine_mono_items(tcx, &mut module, &mono_items);
|
super::predefine_mono_items(tcx, module, &mono_items);
|
||||||
let mut codegened_functions = vec![];
|
let mut codegened_functions = vec![];
|
||||||
for (mono_item, _) in mono_items {
|
for (mono_item, _) in mono_items {
|
||||||
match mono_item {
|
match mono_item {
|
||||||
|
@ -519,58 +521,74 @@ fn module_codegen(
|
||||||
&mut cx,
|
&mut cx,
|
||||||
&mut type_dbg,
|
&mut type_dbg,
|
||||||
Function::new(),
|
Function::new(),
|
||||||
&mut module,
|
module,
|
||||||
inst,
|
inst,
|
||||||
) {
|
) {
|
||||||
codegened_functions.push(codegened_function);
|
codegened_functions.push(codegened_function);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
MonoItem::Static(def_id) => {
|
MonoItem::Static(def_id) => {
|
||||||
let data_id = crate::constant::codegen_static(tcx, &mut module, def_id);
|
let data_id = crate::constant::codegen_static(tcx, module, def_id);
|
||||||
if let Some(debug_context) = &mut cx.debug_context {
|
if let Some(debug_context) = &mut cx.debug_context {
|
||||||
debug_context.define_static(tcx, &mut type_dbg, def_id, data_id);
|
debug_context.define_static(tcx, &mut type_dbg, def_id, data_id);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
MonoItem::GlobalAsm(item_id) => {
|
MonoItem::GlobalAsm(item_id) => {
|
||||||
crate::global_asm::codegen_global_asm_item(
|
crate::global_asm::codegen_global_asm_item(tcx, &mut cx.global_asm, item_id);
|
||||||
tcx,
|
|
||||||
&mut cx.global_asm,
|
|
||||||
item_id,
|
|
||||||
);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
crate::main_shim::maybe_create_entry_wrapper(tcx, &mut module, false, cgu.is_primary());
|
crate::main_shim::maybe_create_entry_wrapper(tcx, module, false, cgu.is_primary());
|
||||||
|
|
||||||
let cgu_name = cgu.name().as_str().to_owned();
|
(cx, codegened_functions)
|
||||||
|
}
|
||||||
|
|
||||||
(cgu_name, cx, module, codegened_functions)
|
fn module_codegen(
|
||||||
});
|
tcx: TyCtxt<'_>,
|
||||||
|
(global_asm_config, cgu_name, token): (
|
||||||
|
Arc<GlobalAsmConfig>,
|
||||||
|
rustc_span::Symbol,
|
||||||
|
ConcurrencyLimiterToken,
|
||||||
|
),
|
||||||
|
) -> OngoingModuleCodegen {
|
||||||
|
let mut module = make_module(tcx.sess, cgu_name.as_str().to_string());
|
||||||
|
|
||||||
|
let (mut cx, codegened_functions) = codegen_cgu_content(tcx, &mut module, cgu_name);
|
||||||
|
|
||||||
|
let cgu_name = cgu_name.as_str().to_owned();
|
||||||
|
|
||||||
let producer = crate::debuginfo::producer(tcx.sess);
|
let producer = crate::debuginfo::producer(tcx.sess);
|
||||||
|
|
||||||
|
let profiler = tcx.prof.clone();
|
||||||
|
|
||||||
OngoingModuleCodegen::Async(std::thread::spawn(move || {
|
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(
|
cranelift_codegen::timing::set_thread_profiler(Box::new(super::MeasuremeProfiler(
|
||||||
cx.profiler.clone(),
|
profiler.clone(),
|
||||||
)));
|
)));
|
||||||
|
|
||||||
let mut cached_context = Context::new();
|
let mut cached_context = Context::new();
|
||||||
for codegened_func in codegened_functions {
|
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 =
|
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)
|
crate::global_asm::compile_global_asm(&global_asm_config, &cgu_name, &cx.global_asm)
|
||||||
})?;
|
})?;
|
||||||
|
|
||||||
let codegen_result =
|
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(
|
emit_cgu(
|
||||||
&global_asm_config.output_filenames,
|
&global_asm_config.output_filenames,
|
||||||
&cx.profiler,
|
&profiler,
|
||||||
cgu_name,
|
cgu_name,
|
||||||
module,
|
module,
|
||||||
cx.debug_context,
|
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(
|
pub(crate) fn run_aot(
|
||||||
tcx: TyCtxt<'_>,
|
tcx: TyCtxt<'_>,
|
||||||
backend_config: BackendConfig,
|
|
||||||
metadata: EncodedMetadata,
|
metadata: EncodedMetadata,
|
||||||
need_metadata_module: bool,
|
need_metadata_module: bool,
|
||||||
) -> Box<OngoingCodegen> {
|
) -> Box<OngoingCodegen> {
|
||||||
|
@ -631,9 +703,10 @@ pub(crate) fn run_aot(
|
||||||
|
|
||||||
let global_asm_config = Arc::new(crate::global_asm::GlobalAsmConfig::new(tcx));
|
let global_asm_config = Arc::new(crate::global_asm::GlobalAsmConfig::new(tcx));
|
||||||
|
|
||||||
|
let disable_incr_cache = disable_incr_cache();
|
||||||
let (todo_cgus, done_cgus) =
|
let (todo_cgus, done_cgus) =
|
||||||
cgus.into_iter().enumerate().partition::<Vec<_>, _>(|&(i, _)| match cgu_reuse[i] {
|
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::No => true,
|
||||||
CguReuse::PreLto | CguReuse::PostLto => false,
|
CguReuse::PreLto | CguReuse::PostLto => false,
|
||||||
});
|
});
|
||||||
|
@ -647,12 +720,7 @@ pub(crate) fn run_aot(
|
||||||
.with_task(
|
.with_task(
|
||||||
dep_node,
|
dep_node,
|
||||||
tcx,
|
tcx,
|
||||||
(
|
(global_asm_config.clone(), cgu.name(), concurrency_limiter.acquire(tcx.dcx())),
|
||||||
backend_config.clone(),
|
|
||||||
global_asm_config.clone(),
|
|
||||||
cgu.name(),
|
|
||||||
concurrency_limiter.acquire(tcx.dcx()),
|
|
||||||
),
|
|
||||||
module_codegen,
|
module_codegen,
|
||||||
Some(rustc_middle::dep_graph::hash_result),
|
Some(rustc_middle::dep_graph::hash_result),
|
||||||
)
|
)
|
||||||
|
@ -666,62 +734,10 @@ pub(crate) fn run_aot(
|
||||||
modules
|
modules
|
||||||
});
|
});
|
||||||
|
|
||||||
let mut allocator_module = make_module(tcx.sess, &backend_config, "allocator_shim".to_string());
|
let allocator_module = emit_allocator_module(tcx);
|
||||||
let created_alloc_shim = crate::allocator::codegen(tcx, &mut allocator_module);
|
|
||||||
|
|
||||||
let allocator_module = if created_alloc_shim {
|
let metadata_module =
|
||||||
let product = allocator_module.finish();
|
if need_metadata_module { Some(emit_metadata_module(tcx, &metadata)) } else { None };
|
||||||
|
|
||||||
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
|
|
||||||
};
|
|
||||||
|
|
||||||
Box::new(OngoingCodegen {
|
Box::new(OngoingCodegen {
|
||||||
modules,
|
modules,
|
||||||
|
|
|
@ -11,12 +11,12 @@ use cranelift_jit::{JITBuilder, JITModule};
|
||||||
use rustc_codegen_ssa::CrateInfo;
|
use rustc_codegen_ssa::CrateInfo;
|
||||||
use rustc_middle::mir::mono::MonoItem;
|
use rustc_middle::mir::mono::MonoItem;
|
||||||
use rustc_session::Session;
|
use rustc_session::Session;
|
||||||
use rustc_span::Symbol;
|
use rustc_span::sym;
|
||||||
|
|
||||||
use crate::debuginfo::TypeDebugContext;
|
use crate::debuginfo::TypeDebugContext;
|
||||||
use crate::prelude::*;
|
use crate::prelude::*;
|
||||||
use crate::unwind_module::UnwindModule;
|
use crate::unwind_module::UnwindModule;
|
||||||
use crate::{BackendConfig, CodegenCx, CodegenMode};
|
use crate::{CodegenCx, CodegenMode};
|
||||||
|
|
||||||
struct JitState {
|
struct JitState {
|
||||||
jit_module: UnwindModule<JITModule>,
|
jit_module: UnwindModule<JITModule>,
|
||||||
|
@ -59,14 +59,10 @@ impl UnsafeMessage {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fn create_jit_module(
|
fn create_jit_module(tcx: TyCtxt<'_>, hotswap: bool) -> (UnwindModule<JITModule>, CodegenCx) {
|
||||||
tcx: TyCtxt<'_>,
|
|
||||||
backend_config: &BackendConfig,
|
|
||||||
hotswap: bool,
|
|
||||||
) -> (UnwindModule<JITModule>, CodegenCx) {
|
|
||||||
let crate_info = CrateInfo::new(tcx, "dummy_target_cpu".to_string());
|
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());
|
let mut jit_builder = JITBuilder::with_isa(isa, cranelift_module::default_libcall_names());
|
||||||
jit_builder.hotswap(hotswap);
|
jit_builder.hotswap(hotswap);
|
||||||
crate::compiler_builtins::register_functions_for_jit(&mut jit_builder);
|
crate::compiler_builtins::register_functions_for_jit(&mut jit_builder);
|
||||||
|
@ -81,7 +77,7 @@ fn create_jit_module(
|
||||||
(jit_module, cx)
|
(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() {
|
if !tcx.sess.opts.output_types.should_codegen() {
|
||||||
tcx.dcx().fatal("JIT mode doesn't work with `cargo check`");
|
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");
|
tcx.dcx().fatal("can't jit non-executable crate");
|
||||||
}
|
}
|
||||||
|
|
||||||
let (mut jit_module, mut cx) = create_jit_module(
|
let (mut jit_module, mut cx) =
|
||||||
tcx,
|
create_jit_module(tcx, matches!(codegen_mode, CodegenMode::JitLazy));
|
||||||
&backend_config,
|
|
||||||
matches!(backend_config.codegen_mode, CodegenMode::JitLazy),
|
|
||||||
);
|
|
||||||
let mut cached_context = Context::new();
|
let mut cached_context = Context::new();
|
||||||
|
|
||||||
let (_, cgus) = tcx.collect_and_partition_mono_items(());
|
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);
|
super::predefine_mono_items(tcx, &mut jit_module, &mono_items);
|
||||||
for (mono_item, _) in mono_items {
|
for (mono_item, _) in mono_items {
|
||||||
match mono_item {
|
match mono_item {
|
||||||
MonoItem::Fn(inst) => match backend_config.codegen_mode {
|
MonoItem::Fn(inst) => match codegen_mode {
|
||||||
CodegenMode::Aot => unreachable!(),
|
CodegenMode::Aot => unreachable!(),
|
||||||
CodegenMode::Jit => {
|
CodegenMode::Jit => {
|
||||||
codegen_and_compile_fn(
|
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())
|
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())
|
.map(|arg| CString::new(arg).unwrap())
|
||||||
.collect::<Vec<_>>();
|
.collect::<Vec<_>>();
|
||||||
|
|
||||||
|
@ -211,7 +204,7 @@ pub(crate) fn codegen_and_compile_fn<'tcx>(
|
||||||
instance: Instance<'tcx>,
|
instance: Instance<'tcx>,
|
||||||
) {
|
) {
|
||||||
cranelift_codegen::timing::set_thread_profiler(Box::new(super::MeasuremeProfiler(
|
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(|| {
|
tcx.prof.generic_activity("codegen and compile fn").run(|| {
|
||||||
|
@ -227,7 +220,7 @@ pub(crate) fn codegen_and_compile_fn<'tcx>(
|
||||||
module,
|
module,
|
||||||
instance,
|
instance,
|
||||||
) {
|
) {
|
||||||
crate::base::compile_fn(cx, cached_context, module, codegened_func);
|
crate::base::compile_fn(cx, &tcx.prof, cached_context, module, codegened_func);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
|
@ -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
|
// 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
|
// be exported from the main codegen unit and may thus be unreachable from the
|
||||||
// object file created by an external assembler.
|
// 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!(
|
let wrapper_name = format!(
|
||||||
"__inline_asm_{}_wrapper_n{}",
|
"__inline_asm_{}_wrapper_n{}",
|
||||||
fx.cx.cgu_name.as_str().replace('.', "__").replace('-', "_"),
|
fx.cx.cgu_name.as_str().replace('.', "__").replace('-', "_"),
|
||||||
inline_asm_index
|
fx.cx.inline_asm_index
|
||||||
);
|
);
|
||||||
|
fx.cx.inline_asm_index += 1;
|
||||||
let sig =
|
let sig =
|
||||||
get_function_sig(fx.tcx, fx.target_config.default_call_conv, instance);
|
get_function_sig(fx.tcx, fx.target_config.default_call_conv, instance);
|
||||||
create_wrapper_function(fx.module, sig, &wrapper_name, symbol.name);
|
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_registers();
|
||||||
asm_gen.allocate_stack_slots();
|
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!(
|
let asm_name = format!(
|
||||||
"__inline_asm_{}_n{}",
|
"__inline_asm_{}_n{}",
|
||||||
fx.cx.cgu_name.as_str().replace('.', "__").replace('-', "_"),
|
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);
|
let generated_asm = asm_gen.generate_asm_wrapper(&asm_name);
|
||||||
fx.cx.global_asm.push_str(&generated_asm);
|
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
|
// 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
|
// be exported from the main codegen unit and may thus be unreachable from the
|
||||||
// object file created by an external assembler.
|
// 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!(
|
let wrapper_name = format!(
|
||||||
"__inline_asm_{}_wrapper_n{}",
|
"__inline_asm_{}_wrapper_n{}",
|
||||||
cx.cgu_name.as_str().replace('.', "__").replace('-', "_"),
|
cx.cgu_name.as_str().replace('.', "__").replace('-', "_"),
|
||||||
inline_asm_index
|
cx.inline_asm_index
|
||||||
);
|
);
|
||||||
|
cx.inline_asm_index += 1;
|
||||||
let sig =
|
let sig =
|
||||||
get_function_sig(tcx, module.target_config().default_call_conv, instance);
|
get_function_sig(tcx, module.target_config().default_call_conv, instance);
|
||||||
create_wrapper_function(module, sig, &wrapper_name, symbol.name);
|
create_wrapper_function(module, sig, &wrapper_name, symbol.name);
|
||||||
|
|
|
@ -1270,8 +1270,7 @@ fn codegen_regular_intrinsic_call<'tcx>(
|
||||||
}
|
}
|
||||||
|
|
||||||
sym::cold_path => {
|
sym::cold_path => {
|
||||||
// This is a no-op. The intrinsic is just a hint to the optimizer.
|
fx.bcx.set_cold_block(fx.bcx.current_block().unwrap());
|
||||||
// We still have an impl here to avoid it being turned into a call.
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Unimplemented intrinsics must have a fallback body. The fallback body is obtained
|
// Unimplemented intrinsics must have a fallback body. The fallback body is obtained
|
||||||
|
|
|
@ -34,7 +34,7 @@ extern crate rustc_target;
|
||||||
extern crate rustc_driver;
|
extern crate rustc_driver;
|
||||||
|
|
||||||
use std::any::Any;
|
use std::any::Any;
|
||||||
use std::cell::{Cell, RefCell};
|
use std::env;
|
||||||
use std::sync::Arc;
|
use std::sync::Arc;
|
||||||
|
|
||||||
use cranelift_codegen::isa::TargetIsa;
|
use cranelift_codegen::isa::TargetIsa;
|
||||||
|
@ -42,7 +42,6 @@ use cranelift_codegen::settings::{self, Configurable};
|
||||||
use rustc_codegen_ssa::CodegenResults;
|
use rustc_codegen_ssa::CodegenResults;
|
||||||
use rustc_codegen_ssa::back::versioned_llvm_target;
|
use rustc_codegen_ssa::back::versioned_llvm_target;
|
||||||
use rustc_codegen_ssa::traits::CodegenBackend;
|
use rustc_codegen_ssa::traits::CodegenBackend;
|
||||||
use rustc_data_structures::profiling::SelfProfilerRef;
|
|
||||||
use rustc_metadata::EncodedMetadata;
|
use rustc_metadata::EncodedMetadata;
|
||||||
use rustc_middle::dep_graph::{WorkProduct, WorkProductId};
|
use rustc_middle::dep_graph::{WorkProduct, WorkProductId};
|
||||||
use rustc_session::Session;
|
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
|
/// 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).
|
/// inside a single codegen unit with the exception of the Cranelift [`Module`](cranelift_module::Module).
|
||||||
struct CodegenCx {
|
struct CodegenCx {
|
||||||
profiler: SelfProfilerRef,
|
|
||||||
output_filenames: Arc<OutputFilenames>,
|
output_filenames: Arc<OutputFilenames>,
|
||||||
should_write_ir: bool,
|
should_write_ir: bool,
|
||||||
global_asm: String,
|
global_asm: String,
|
||||||
inline_asm_index: Cell<usize>,
|
inline_asm_index: usize,
|
||||||
debug_context: Option<DebugContext>,
|
debug_context: Option<DebugContext>,
|
||||||
cgu_name: Symbol,
|
cgu_name: Symbol,
|
||||||
}
|
}
|
||||||
|
@ -142,11 +140,10 @@ impl CodegenCx {
|
||||||
None
|
None
|
||||||
};
|
};
|
||||||
CodegenCx {
|
CodegenCx {
|
||||||
profiler: tcx.prof.clone(),
|
|
||||||
output_filenames: tcx.output_filenames(()).clone(),
|
output_filenames: tcx.output_filenames(()).clone(),
|
||||||
should_write_ir: crate::pretty_clif::should_write_ir(tcx),
|
should_write_ir: crate::pretty_clif::should_write_ir(tcx),
|
||||||
global_asm: String::new(),
|
global_asm: String::new(),
|
||||||
inline_asm_index: Cell::new(0),
|
inline_asm_index: 0,
|
||||||
debug_context,
|
debug_context,
|
||||||
cgu_name,
|
cgu_name,
|
||||||
}
|
}
|
||||||
|
@ -154,7 +151,7 @@ impl CodegenCx {
|
||||||
}
|
}
|
||||||
|
|
||||||
pub struct CraneliftCodegenBackend {
|
pub struct CraneliftCodegenBackend {
|
||||||
pub config: RefCell<Option<BackendConfig>>,
|
pub config: Option<BackendConfig>,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl CodegenBackend for CraneliftCodegenBackend {
|
impl CodegenBackend for CraneliftCodegenBackend {
|
||||||
|
@ -176,13 +173,6 @@ impl CodegenBackend for CraneliftCodegenBackend {
|
||||||
sess.dcx()
|
sess.dcx()
|
||||||
.fatal("`-Cinstrument-coverage` is LLVM specific and not supported by Cranelift");
|
.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> {
|
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,
|
need_metadata_module: bool,
|
||||||
) -> Box<dyn Any> {
|
) -> Box<dyn Any> {
|
||||||
tcx.dcx().abort_if_errors();
|
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 {
|
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 => {
|
CodegenMode::Jit | CodegenMode::JitLazy => {
|
||||||
#[cfg(feature = "jit")]
|
#[cfg(feature = "jit")]
|
||||||
driver::jit::run_jit(tcx, config);
|
driver::jit::run_jit(tcx, config.codegen_mode, config.jit_args);
|
||||||
|
|
||||||
#[cfg(not(feature = "jit"))]
|
#[cfg(not(feature = "jit"))]
|
||||||
tcx.dcx().fatal("jit support was disabled when compiling rustc_codegen_cranelift");
|
tcx.dcx().fatal("jit support was disabled when compiling rustc_codegen_cranelift");
|
||||||
|
@ -236,14 +229,20 @@ impl CodegenBackend for CraneliftCodegenBackend {
|
||||||
) -> (CodegenResults, FxIndexMap<WorkProductId, WorkProduct>) {
|
) -> (CodegenResults, FxIndexMap<WorkProductId, WorkProduct>) {
|
||||||
let _timer = sess.timer("finish_ongoing_codegen");
|
let _timer = sess.timer("finish_ongoing_codegen");
|
||||||
|
|
||||||
ongoing_codegen.downcast::<driver::aot::OngoingCodegen>().unwrap().join(
|
ongoing_codegen.downcast::<driver::aot::OngoingCodegen>().unwrap().join(sess, outputs)
|
||||||
sess,
|
|
||||||
outputs,
|
|
||||||
self.config.borrow().as_ref().unwrap(),
|
|
||||||
)
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// 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 {
|
fn target_triple(sess: &Session) -> target_lexicon::Triple {
|
||||||
// FIXME(madsmtm): Use `sess.target.llvm_target` once target-lexicon supports unversioned macOS.
|
// FIXME(madsmtm): Use `sess.target.llvm_target` once target-lexicon supports unversioned macOS.
|
||||||
// See <https://github.com/bytecodealliance/target-lexicon/pull/113>
|
// 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;
|
use target_lexicon::BinaryFormat;
|
||||||
|
|
||||||
let target_triple = crate::target_triple(sess);
|
let target_triple = crate::target_triple(sess);
|
||||||
|
|
||||||
let mut flags_builder = settings::builder();
|
let mut flags_builder = settings::builder();
|
||||||
flags_builder.enable("is_pic").unwrap();
|
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("enable_verifier", enable_verifier).unwrap();
|
||||||
flags_builder.set("regalloc_checker", 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(_)
|
if let target_lexicon::Architecture::Aarch64(_)
|
||||||
| target_lexicon::Architecture::Riscv64(_)
|
| target_lexicon::Architecture::Riscv64(_)
|
||||||
| target_lexicon::Architecture::X86_64 = target_triple.architecture
|
| 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
|
/// This is the entrypoint for a hot plugged rustc_codegen_cranelift
|
||||||
#[no_mangle]
|
#[no_mangle]
|
||||||
pub fn __rustc_codegen_backend() -> Box<dyn CodegenBackend> {
|
pub fn __rustc_codegen_backend() -> Box<dyn CodegenBackend> {
|
||||||
Box::new(CraneliftCodegenBackend { config: RefCell::new(None) })
|
Box::new(CraneliftCodegenBackend { config: None })
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue