1
Fork 0

Merge commit '1eded3619d' into sync_cg_clif-2023-07-22

This commit is contained in:
bjorn3 2023-07-22 13:32:34 +00:00
commit 36708123c1
30 changed files with 668 additions and 170 deletions

View file

@ -1,4 +1,5 @@
use std::env;
use std::io::Write;
use std::path::Path;
use super::path::{Dirs, RelPath};
@ -30,6 +31,12 @@ fn benchmark_simple_raytracer(dirs: &Dirs, bootstrap_host_compiler: &Compiler) {
let bench_runs = env::var("BENCH_RUNS").unwrap_or_else(|_| "10".to_string()).parse().unwrap();
let mut gha_step_summary = if let Ok(file) = std::env::var("GITHUB_STEP_SUMMARY") {
Some(std::fs::OpenOptions::new().append(true).open(file).unwrap())
} else {
None
};
eprintln!("[BENCH COMPILE] ebobby/simple-raytracer");
let cargo_clif = RelPath::DIST
.to_path(dirs)
@ -60,36 +67,64 @@ 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 = hyperfine_command(
1,
bench_runs,
Some(&clean_cmd),
&[&llvm_build_cmd, &clif_build_cmd, &clif_build_opt_cmd],
&[
("cargo build", &llvm_build_cmd),
("cargo-clif build", &clif_build_cmd),
("cargo-clif build --release", &clif_build_opt_cmd),
],
&bench_compile_markdown,
);
spawn_and_wait(bench_compile);
if let Some(gha_step_summary) = gha_step_summary.as_mut() {
gha_step_summary.write_all(b"## Compile ebobby/simple-raytracer\n\n").unwrap();
gha_step_summary.write_all(&std::fs::read(bench_compile_markdown).unwrap()).unwrap();
gha_step_summary.write_all(b"\n").unwrap();
}
eprintln!("[BENCH RUN] ebobby/simple-raytracer");
let bench_run_markdown = RelPath::DIST.to_path(dirs).join("bench_run.md");
let raytracer_cg_llvm = Path::new(".").join(get_file_name(
&bootstrap_host_compiler.rustc,
"raytracer_cg_llvm",
"bin",
));
let raytracer_cg_clif = Path::new(".").join(get_file_name(
&bootstrap_host_compiler.rustc,
"raytracer_cg_clif",
"bin",
));
let raytracer_cg_clif_opt = Path::new(".").join(get_file_name(
&bootstrap_host_compiler.rustc,
"raytracer_cg_clif_opt",
"bin",
));
let mut bench_run = hyperfine_command(
0,
bench_runs,
None,
&[
Path::new(".")
.join(get_file_name(&bootstrap_host_compiler.rustc, "raytracer_cg_llvm", "bin"))
.to_str()
.unwrap(),
Path::new(".")
.join(get_file_name(&bootstrap_host_compiler.rustc, "raytracer_cg_clif", "bin"))
.to_str()
.unwrap(),
Path::new(".")
.join(get_file_name(&bootstrap_host_compiler.rustc, "raytracer_cg_clif_opt", "bin"))
.to_str()
.unwrap(),
("", raytracer_cg_llvm.to_str().unwrap()),
("", raytracer_cg_clif.to_str().unwrap()),
("", raytracer_cg_clif_opt.to_str().unwrap()),
],
&bench_run_markdown,
);
bench_run.current_dir(RelPath::BUILD.to_path(dirs));
spawn_and_wait(bench_run);
if let Some(gha_step_summary) = gha_step_summary.as_mut() {
gha_step_summary.write_all(b"## Run ebobby/simple-raytracer\n\n").unwrap();
gha_step_summary.write_all(&std::fs::read(bench_run_markdown).unwrap()).unwrap();
gha_step_summary.write_all(b"\n").unwrap();
}
}

View file

@ -3,7 +3,7 @@ use std::path::PathBuf;
use super::path::{Dirs, RelPath};
use super::rustc_info::get_file_name;
use super::utils::{is_ci, is_ci_opt, maybe_incremental, CargoProject, Compiler};
use super::utils::{is_ci, is_ci_opt, maybe_incremental, CargoProject, Compiler, LogGroup};
pub(crate) static CG_CLIF: CargoProject = CargoProject::new(&RelPath::SOURCE, "cg_clif");
@ -13,6 +13,8 @@ pub(crate) fn build_backend(
bootstrap_host_compiler: &Compiler,
use_unstable_features: bool,
) -> PathBuf {
let _group = LogGroup::guard("Build backend");
let mut cmd = CG_CLIF.build(&bootstrap_host_compiler, dirs);
maybe_incremental(&mut cmd);

View file

@ -6,6 +6,7 @@ use super::path::{Dirs, RelPath};
use super::rustc_info::get_file_name;
use super::utils::{
maybe_incremental, remove_dir_if_exists, spawn_and_wait, try_hard_link, CargoProject, Compiler,
LogGroup,
};
use super::{CodegenBackend, SysrootKind};
@ -22,6 +23,8 @@ pub(crate) fn build_sysroot(
rustup_toolchain_name: Option<&str>,
target_triple: String,
) -> Compiler {
let _guard = LogGroup::guard("Build sysroot");
eprintln!("[BUILD] sysroot {:?}", sysroot_kind);
DIST_DIR.ensure_fresh(dirs);
@ -251,7 +254,10 @@ fn build_clif_sysroot_for_triple(
rustflags
.push_str(&format!(" --sysroot {}", RTSTARTUP_SYSROOT.to_path(dirs).to_str().unwrap()));
if channel == "release" {
rustflags.push_str(" -Zmir-opt-level=3");
// Incremental compilation by default disables mir inlining. This leads to both a decent
// compile perf and a significant runtime perf regression. As such forcefully enable mir
// inlining.
rustflags.push_str(" -Zinline-mir");
}
compiler.rustflags += &rustflags;
let mut build_cmd = STANDARD_LIBRARY.build(&compiler, dirs);

View file

@ -27,6 +27,7 @@ pub(crate) fn prepare_stdlib(dirs: &Dirs, rustc: &Path) {
STDLIB_SRC.to_path(dirs).join("Cargo.toml"),
r#"
[workspace]
resolver = "1"
members = ["./library/sysroot"]
[patch.crates-io]

View file

@ -3,7 +3,7 @@ use super::config;
use super::path::{Dirs, RelPath};
use super::prepare::{apply_patches, GitRepo};
use super::rustc_info::get_default_sysroot;
use super::utils::{spawn_and_wait, spawn_and_wait_with_input, CargoProject, Compiler};
use super::utils::{spawn_and_wait, spawn_and_wait_with_input, CargoProject, Compiler, LogGroup};
use super::{CodegenBackend, SysrootKind};
use std::env;
use std::ffi::OsStr;
@ -21,6 +21,7 @@ struct TestCase {
enum TestCaseCmd {
Custom { func: &'static dyn Fn(&TestRunner<'_>) },
BuildLib { source: &'static str, crate_types: &'static str },
BuildBin { source: &'static str },
BuildBinAndRun { source: &'static str, args: &'static [&'static str] },
JitBin { source: &'static str, args: &'static str },
}
@ -39,6 +40,10 @@ impl TestCase {
Self { config, cmd: TestCaseCmd::BuildLib { source, crate_types } }
}
const fn build_bin(config: &'static str, source: &'static str) -> Self {
Self { config, cmd: TestCaseCmd::BuildBin { source } }
}
const fn build_bin_and_run(
config: &'static str,
source: &'static str,
@ -92,6 +97,7 @@ const BASE_SYSROOT_SUITE: &[TestCase] = &[
TestCase::build_bin_and_run("aot.float-minmax-pass", "example/float-minmax-pass.rs", &[]),
TestCase::build_bin_and_run("aot.mod_bench", "example/mod_bench.rs", &[]),
TestCase::build_bin_and_run("aot.issue-72793", "example/issue-72793.rs", &[]),
TestCase::build_bin("aot.issue-59326", "example/issue-59326.rs"),
];
// FIXME(rust-random/rand#1293): Newer rand versions fail to test on Windows. Update once this is
@ -119,8 +125,8 @@ pub(crate) static REGEX: CargoProject = CargoProject::new(&REGEX_REPO.source_dir
pub(crate) static PORTABLE_SIMD_REPO: GitRepo = GitRepo::github(
"rust-lang",
"portable-simd",
"ad8afa8c81273b3b49acbea38cd3bcf17a34cf2b",
"800548f8000e31bd",
"7c7dbe0c505ccbc02ff30c1e37381ab1d47bf46f",
"5bcc9c544f6fa7bd",
"portable-simd",
);
@ -380,15 +386,17 @@ impl<'a> TestRunner<'a> {
let tag = tag.to_uppercase();
let is_jit_test = tag == "JIT";
if !config::get_bool(config)
let _guard = if !config::get_bool(config)
|| (is_jit_test && !self.jit_supported)
|| self.skip_tests.contains(&config)
{
eprintln!("[{tag}] {testname} (skipped)");
continue;
} else {
let guard = LogGroup::guard(&format!("[{tag}] {testname}"));
eprintln!("[{tag}] {testname}");
}
guard
};
match *cmd {
TestCaseCmd::Custom { func } => func(self),
@ -405,6 +413,13 @@ impl<'a> TestRunner<'a> {
]);
}
}
TestCaseCmd::BuildBin { source } => {
if self.use_unstable_features {
self.run_rustc([source]);
} else {
self.run_rustc([source, "--cfg", "no_unstable_features"]);
}
}
TestCaseCmd::BuildBinAndRun { source, args } => {
if self.use_unstable_features {
self.run_rustc([source]);

View file

@ -3,6 +3,7 @@ use std::fs;
use std::io::{self, Write};
use std::path::{Path, PathBuf};
use std::process::{self, Command, Stdio};
use std::sync::atomic::{AtomicBool, Ordering};
use super::path::{Dirs, RelPath};
@ -136,10 +137,13 @@ pub(crate) fn hyperfine_command(
warmup: u64,
runs: u64,
prepare: Option<&str>,
cmds: &[&str],
cmds: &[(&str, &str)],
markdown_export: &Path,
) -> Command {
let mut bench = Command::new("hyperfine");
bench.arg("--export-markdown").arg(markdown_export);
if warmup != 0 {
bench.arg("--warmup").arg(warmup.to_string());
}
@ -152,7 +156,12 @@ pub(crate) fn hyperfine_command(
bench.arg("--prepare").arg(prepare);
}
bench.args(cmds);
for &(name, cmd) in cmds {
if name != "" {
bench.arg("-n").arg(name);
}
bench.arg(cmd);
}
bench
}
@ -167,6 +176,8 @@ pub(crate) fn git_command<'a>(repo_dir: impl Into<Option<&'a Path>>, cmd: &str)
.arg("user.email=dummy@example.com")
.arg("-c")
.arg("core.autocrlf=false")
.arg("-c")
.arg("commit.gpgSign=false")
.arg(cmd);
if let Some(repo_dir) = repo_dir.into() {
git_cmd.current_dir(repo_dir);
@ -259,6 +270,33 @@ pub(crate) fn is_ci_opt() -> bool {
env::var("CI_OPT").is_ok()
}
static IN_GROUP: AtomicBool = AtomicBool::new(false);
pub(crate) struct LogGroup {
is_gha: bool,
}
impl LogGroup {
pub(crate) fn guard(name: &str) -> LogGroup {
let is_gha = env::var("GITHUB_ACTIONS").is_ok();
assert!(!IN_GROUP.swap(true, Ordering::SeqCst));
if is_gha {
eprintln!("::group::{name}");
}
LogGroup { is_gha }
}
}
impl Drop for LogGroup {
fn drop(&mut self) {
if self.is_gha {
eprintln!("::endgroup::");
}
IN_GROUP.store(false, Ordering::SeqCst);
}
}
pub(crate) fn maybe_incremental(cmd: &mut Command) {
if is_ci() || std::env::var("CARGO_BUILD_INCREMENTAL").map_or(false, |val| val == "false") {
// Disabling incr comp reduces cache size and incr comp doesn't save as much on CI anyway