Skip to content

Commit 8cca42a

Browse files
committed
Auto merge of rust-lang#107843 - bjorn3:sync_cg_clif-2023-02-09, r=bjorn3
Sync rustc_codegen_cranelift * Couple of bugfixes * A significant runtime perf improvement * Implemented sym and const support for inline asm * Improved self profile integration r? `@ghost` `@rustbot` label +A-codegen +A-cranelift +T-compiler
2 parents 5919f62 + e25566e commit 8cca42a

26 files changed

+640
-331
lines changed

compiler/rustc_codegen_cranelift/.github/workflows/main.yml

+128-18
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ jobs:
2121
cargo fmt --check
2222
rustfmt --check build_system/mod.rs
2323
24+
2425
build:
2526
runs-on: ${{ matrix.os }}
2627
timeout-minutes: 60
@@ -33,7 +34,7 @@ jobs:
3334
fail-fast: false
3435
matrix:
3536
include:
36-
- os: ubuntu-20.04 # FIXME switch to ubuntu-22.04 once #1303 is fixed
37+
- os: ubuntu-latest
3738
env:
3839
TARGET_TRIPLE: x86_64-unknown-linux-gnu
3940
- os: macos-latest
@@ -112,23 +113,6 @@ jobs:
112113
TARGET_TRIPLE: ${{ matrix.env.TARGET_TRIPLE }}
113114
run: ./y.rs test
114115

115-
- name: Package prebuilt cg_clif
116-
run: tar cvfJ cg_clif.tar.xz dist
117-
118-
- name: Upload prebuilt cg_clif
119-
if: matrix.os == 'windows-latest' || matrix.env.TARGET_TRIPLE != 'x86_64-pc-windows-gnu'
120-
uses: actions/upload-artifact@v3
121-
with:
122-
name: cg_clif-${{ matrix.env.TARGET_TRIPLE }}
123-
path: cg_clif.tar.xz
124-
125-
- name: Upload prebuilt cg_clif (cross compile)
126-
if: matrix.os != 'windows-latest' && matrix.env.TARGET_TRIPLE == 'x86_64-pc-windows-gnu'
127-
uses: actions/upload-artifact@v3
128-
with:
129-
name: cg_clif-${{ runner.os }}-cross-x86_64-mingw
130-
path: cg_clif.tar.xz
131-
132116

133117
abi_cafe:
134118
runs-on: ${{ matrix.os }}
@@ -185,3 +169,129 @@ jobs:
185169
env:
186170
TARGET_TRIPLE: ${{ matrix.env.TARGET_TRIPLE }}
187171
run: ./y.rs abi-cafe
172+
173+
174+
bench:
175+
runs-on: ubuntu-latest
176+
timeout-minutes: 60
177+
178+
defaults:
179+
run:
180+
shell: bash
181+
182+
steps:
183+
- uses: actions/checkout@v3
184+
185+
- name: Cache cargo target dir
186+
uses: actions/cache@v3
187+
with:
188+
path: build/cg_clif
189+
key: ${{ runner.os }}-x86_64-unknown-linux-gnu-cargo-build-target-${{ hashFiles('rust-toolchain', '**/Cargo.lock') }}
190+
191+
- name: Cache cargo bin dir
192+
uses: actions/cache@v3
193+
with:
194+
path: ~/.cargo/bin
195+
key: ${{ runner.os }}-${{ matrix.env.TARGET_TRIPLE }}-cargo-bin-dir-${{ hashFiles('rust-toolchain', '**/Cargo.lock') }}
196+
197+
- name: Use sparse cargo registry
198+
run: |
199+
cat >> ~/.cargo/config.toml <<EOF
200+
[unstable]
201+
sparse-registry = true
202+
EOF
203+
204+
- name: Install hyperfine
205+
run: cargo install hyperfine || true
206+
207+
- name: Prepare dependencies
208+
run: ./y.rs prepare
209+
210+
- name: Build
211+
run: CI_OPT=1 ./y.rs build --sysroot none
212+
213+
- name: Benchmark
214+
run: CI_OPT=1 ./y.rs bench
215+
216+
217+
dist:
218+
runs-on: ${{ matrix.os }}
219+
timeout-minutes: 60
220+
221+
defaults:
222+
run:
223+
shell: bash
224+
225+
strategy:
226+
fail-fast: false
227+
matrix:
228+
include:
229+
# FIXME update at some point in the future once most distros use a newer glibc
230+
- os: ubuntu-20.04
231+
env:
232+
TARGET_TRIPLE: x86_64-unknown-linux-gnu
233+
- os: macos-latest
234+
env:
235+
TARGET_TRIPLE: x86_64-apple-darwin
236+
# cross-compile from Linux to Windows using mingw
237+
- os: ubuntu-latest
238+
env:
239+
TARGET_TRIPLE: x86_64-pc-windows-gnu
240+
- os: windows-latest
241+
env:
242+
TARGET_TRIPLE: x86_64-pc-windows-msvc
243+
- os: windows-latest
244+
env:
245+
TARGET_TRIPLE: x86_64-pc-windows-gnu
246+
247+
steps:
248+
- uses: actions/checkout@v3
249+
250+
- name: Cache cargo target dir
251+
uses: actions/cache@v3
252+
with:
253+
path: build/cg_clif
254+
key: ${{ runner.os }}-${{ matrix.env.TARGET_TRIPLE }}-dist-cargo-build-target-${{ hashFiles('rust-toolchain', '**/Cargo.lock') }}
255+
256+
- name: Set MinGW as the default toolchain
257+
if: matrix.os == 'windows-latest' && matrix.env.TARGET_TRIPLE == 'x86_64-pc-windows-gnu'
258+
run: rustup set default-host x86_64-pc-windows-gnu
259+
260+
- name: Install MinGW toolchain and wine
261+
if: matrix.os == 'ubuntu-latest' && matrix.env.TARGET_TRIPLE == 'x86_64-pc-windows-gnu'
262+
run: |
263+
sudo apt-get update
264+
sudo apt-get install -y gcc-mingw-w64-x86-64 wine-stable
265+
266+
- name: Use sparse cargo registry
267+
run: |
268+
cat >> ~/.cargo/config.toml <<EOF
269+
[unstable]
270+
sparse-registry = true
271+
EOF
272+
273+
- name: Prepare dependencies
274+
run: ./y.rs prepare
275+
276+
- name: Build backend
277+
run: CI_OPT=1 ./y.rs build --sysroot none
278+
279+
- name: Build sysroot
280+
run: CI_OPT=1 ./y.rs build
281+
282+
- name: Package prebuilt cg_clif
283+
run: tar cvfJ cg_clif.tar.xz dist
284+
285+
- name: Upload prebuilt cg_clif
286+
if: matrix.os == 'windows-latest' || matrix.env.TARGET_TRIPLE != 'x86_64-pc-windows-gnu'
287+
uses: actions/upload-artifact@v3
288+
with:
289+
name: cg_clif-${{ matrix.env.TARGET_TRIPLE }}
290+
path: cg_clif.tar.xz
291+
292+
- name: Upload prebuilt cg_clif (cross compile)
293+
if: matrix.os != 'windows-latest' && matrix.env.TARGET_TRIPLE == 'x86_64-pc-windows-gnu'
294+
uses: actions/upload-artifact@v3
295+
with:
296+
name: cg_clif-${{ runner.os }}-cross-x86_64-mingw
297+
path: cg_clif.tar.xz

compiler/rustc_codegen_cranelift/build_sysroot/Cargo.lock

+2-2
Original file line numberDiff line numberDiff line change
@@ -34,9 +34,9 @@ dependencies = [
3434

3535
[[package]]
3636
name = "cc"
37-
version = "1.0.78"
37+
version = "1.0.79"
3838
source = "registry+https://github.com/rust-lang/crates.io-index"
39-
checksum = "a20104e2335ce8a659d6dd92a51a767a0c062599c73b343fd152cb401e828c3d"
39+
checksum = "50d30906286121d95be3d479533b458f87493b30a4b5f79a607db8f5d11aa91f"
4040

4141
[[package]]
4242
name = "cfg-if"

compiler/rustc_codegen_cranelift/build_system/abi_cafe.rs

+5-3
Original file line numberDiff line numberDiff line change
@@ -6,11 +6,10 @@ use super::prepare::GitRepo;
66
use super::utils::{spawn_and_wait, CargoProject, Compiler};
77
use super::SysrootKind;
88

9-
pub(crate) static ABI_CAFE_REPO: GitRepo =
9+
static ABI_CAFE_REPO: GitRepo =
1010
GitRepo::github("Gankra", "abi-cafe", "4c6dc8c9c687e2b3a760ff2176ce236872b37212", "abi-cafe");
1111

12-
pub(crate) static ABI_CAFE: CargoProject =
13-
CargoProject::new(&ABI_CAFE_REPO.source_dir(), "abi_cafe");
12+
static ABI_CAFE: CargoProject = CargoProject::new(&ABI_CAFE_REPO.source_dir(), "abi_cafe");
1413

1514
pub(crate) fn run(
1615
channel: &str,
@@ -19,6 +18,9 @@ pub(crate) fn run(
1918
cg_clif_dylib: &Path,
2019
bootstrap_host_compiler: &Compiler,
2120
) {
21+
ABI_CAFE_REPO.fetch(dirs);
22+
spawn_and_wait(ABI_CAFE.fetch("cargo", &bootstrap_host_compiler.rustc, dirs));
23+
2224
eprintln!("Building sysroot for abi-cafe");
2325
build_sysroot::build_sysroot(
2426
dirs,

compiler/rustc_codegen_cranelift/build_system/bench.rs

+19-13
Original file line numberDiff line numberDiff line change
@@ -5,20 +5,20 @@ use std::path::Path;
55
use super::path::{Dirs, RelPath};
66
use super::prepare::GitRepo;
77
use super::rustc_info::get_file_name;
8-
use super::utils::{hyperfine_command, is_ci, spawn_and_wait, CargoProject, Compiler};
8+
use super::utils::{hyperfine_command, spawn_and_wait, CargoProject, Compiler};
99

10-
pub(crate) static SIMPLE_RAYTRACER_REPO: GitRepo = GitRepo::github(
10+
static SIMPLE_RAYTRACER_REPO: GitRepo = GitRepo::github(
1111
"ebobby",
1212
"simple-raytracer",
1313
"804a7a21b9e673a482797aa289a18ed480e4d813",
1414
"<none>",
1515
);
1616

1717
// Use a separate target dir for the initial LLVM build to reduce unnecessary recompiles
18-
pub(crate) static SIMPLE_RAYTRACER_LLVM: CargoProject =
18+
static SIMPLE_RAYTRACER_LLVM: CargoProject =
1919
CargoProject::new(&SIMPLE_RAYTRACER_REPO.source_dir(), "simple_raytracer_llvm");
2020

21-
pub(crate) static SIMPLE_RAYTRACER: CargoProject =
21+
static SIMPLE_RAYTRACER: CargoProject =
2222
CargoProject::new(&SIMPLE_RAYTRACER_REPO.source_dir(), "simple_raytracer");
2323

2424
pub(crate) fn benchmark(dirs: &Dirs, bootstrap_host_compiler: &Compiler) {
@@ -32,6 +32,15 @@ fn benchmark_simple_raytracer(dirs: &Dirs, bootstrap_host_compiler: &Compiler) {
3232
std::process::exit(1);
3333
}
3434

35+
if !SIMPLE_RAYTRACER_REPO.source_dir().to_path(dirs).exists() {
36+
SIMPLE_RAYTRACER_REPO.fetch(dirs);
37+
spawn_and_wait(SIMPLE_RAYTRACER.fetch(
38+
&bootstrap_host_compiler.cargo,
39+
&bootstrap_host_compiler.rustc,
40+
dirs,
41+
));
42+
}
43+
3544
eprintln!("[LLVM BUILD] simple-raytracer");
3645
let build_cmd = SIMPLE_RAYTRACER_LLVM.build(bootstrap_host_compiler, dirs);
3746
spawn_and_wait(build_cmd);
@@ -45,10 +54,7 @@ fn benchmark_simple_raytracer(dirs: &Dirs, bootstrap_host_compiler: &Compiler) {
4554
)
4655
.unwrap();
4756

48-
let run_runs = env::var("RUN_RUNS")
49-
.unwrap_or(if is_ci() { "2" } else { "10" }.to_string())
50-
.parse()
51-
.unwrap();
57+
let bench_runs = env::var("BENCH_RUNS").unwrap_or_else(|_| "10".to_string()).parse().unwrap();
5258

5359
eprintln!("[BENCH COMPILE] ebobby/simple-raytracer");
5460
let cargo_clif =
@@ -57,24 +63,24 @@ fn benchmark_simple_raytracer(dirs: &Dirs, bootstrap_host_compiler: &Compiler) {
5763
let target_dir = SIMPLE_RAYTRACER.target_dir(dirs);
5864

5965
let clean_cmd = format!(
60-
"cargo clean --manifest-path {manifest_path} --target-dir {target_dir}",
66+
"RUSTC=rustc cargo clean --manifest-path {manifest_path} --target-dir {target_dir}",
6167
manifest_path = manifest_path.display(),
6268
target_dir = target_dir.display(),
6369
);
6470
let llvm_build_cmd = format!(
65-
"cargo build --manifest-path {manifest_path} --target-dir {target_dir}",
71+
"RUSTC=rustc cargo build --manifest-path {manifest_path} --target-dir {target_dir}",
6672
manifest_path = manifest_path.display(),
6773
target_dir = target_dir.display(),
6874
);
6975
let clif_build_cmd = format!(
70-
"{cargo_clif} build --manifest-path {manifest_path} --target-dir {target_dir}",
76+
"RUSTC=rustc {cargo_clif} build --manifest-path {manifest_path} --target-dir {target_dir}",
7177
cargo_clif = cargo_clif.display(),
7278
manifest_path = manifest_path.display(),
7379
target_dir = target_dir.display(),
7480
);
7581

7682
let bench_compile =
77-
hyperfine_command(1, run_runs, Some(&clean_cmd), &llvm_build_cmd, &clif_build_cmd);
83+
hyperfine_command(1, bench_runs, Some(&clean_cmd), &llvm_build_cmd, &clif_build_cmd);
7884

7985
spawn_and_wait(bench_compile);
8086

@@ -87,7 +93,7 @@ fn benchmark_simple_raytracer(dirs: &Dirs, bootstrap_host_compiler: &Compiler) {
8793

8894
let mut bench_run = hyperfine_command(
8995
0,
90-
run_runs,
96+
bench_runs,
9197
None,
9298
Path::new(".").join(get_file_name("raytracer_cg_llvm", "bin")).to_str().unwrap(),
9399
Path::new(".").join(get_file_name("raytracer_cg_clif", "bin")).to_str().unwrap(),

compiler/rustc_codegen_cranelift/build_system/build_backend.rs

+4-2
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ use std::path::PathBuf;
33

44
use super::path::{Dirs, RelPath};
55
use super::rustc_info::get_file_name;
6-
use super::utils::{is_ci, CargoProject, Compiler};
6+
use super::utils::{is_ci, is_ci_opt, CargoProject, Compiler};
77

88
pub(crate) static CG_CLIF: CargoProject = CargoProject::new(&RelPath::SOURCE, "cg_clif");
99

@@ -26,7 +26,9 @@ pub(crate) fn build_backend(
2626
// Disabling incr comp reduces cache size and incr comp doesn't save as much on CI anyway
2727
cmd.env("CARGO_BUILD_INCREMENTAL", "false");
2828

29-
cmd.env("CARGO_PROFILE_RELEASE_DEBUG_ASSERTIONS", "true");
29+
if !is_ci_opt() {
30+
cmd.env("CARGO_PROFILE_RELEASE_DEBUG_ASSERTIONS", "true");
31+
}
3032
}
3133

3234
if use_unstable_features {

compiler/rustc_codegen_cranelift/build_system/build_sysroot.rs

+3
Original file line numberDiff line numberDiff line change
@@ -248,6 +248,9 @@ fn build_clif_sysroot_for_triple(
248248
build_cmd.arg("--release");
249249
}
250250
build_cmd.env("__CARGO_DEFAULT_LIB_METADATA", "cg_clif");
251+
if compiler.triple.contains("apple") {
252+
build_cmd.env("CARGO_PROFILE_RELEASE_SPLIT_DEBUGINFO", "packed");
253+
}
251254
spawn_and_wait(build_cmd);
252255

253256
for entry in fs::read_dir(build_dir.join("deps")).unwrap() {

compiler/rustc_codegen_cranelift/build_system/mod.rs

+5-3
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ use std::env;
22
use std::path::PathBuf;
33
use std::process;
44

5-
use self::utils::{is_ci, Compiler};
5+
use self::utils::{is_ci, is_ci_opt, Compiler};
66

77
mod abi_cafe;
88
mod bench;
@@ -53,8 +53,10 @@ pub fn main() {
5353
// Disabling incr comp reduces cache size and incr comp doesn't save as much on CI anyway
5454
env::set_var("CARGO_BUILD_INCREMENTAL", "false");
5555

56-
// Enable the Cranelift verifier
57-
env::set_var("CG_CLIF_ENABLE_VERIFIER", "1");
56+
if !is_ci_opt() {
57+
// Enable the Cranelift verifier
58+
env::set_var("CG_CLIF_ENABLE_VERIFIER", "1");
59+
}
5860
}
5961

6062
let mut args = env::args().skip(1);

compiler/rustc_codegen_cranelift/build_system/prepare.rs

+7-11
Original file line numberDiff line numberDiff line change
@@ -11,22 +11,18 @@ use super::utils::{copy_dir_recursively, git_command, retry_spawn_and_wait, spaw
1111
pub(crate) fn prepare(dirs: &Dirs) {
1212
RelPath::DOWNLOAD.ensure_fresh(dirs);
1313

14-
spawn_and_wait(super::build_backend::CG_CLIF.fetch("cargo", dirs));
14+
spawn_and_wait(super::build_backend::CG_CLIF.fetch("cargo", "rustc", dirs));
1515

1616
prepare_sysroot(dirs);
17-
spawn_and_wait(super::build_sysroot::STANDARD_LIBRARY.fetch("cargo", dirs));
18-
spawn_and_wait(super::tests::LIBCORE_TESTS.fetch("cargo", dirs));
17+
spawn_and_wait(super::build_sysroot::STANDARD_LIBRARY.fetch("cargo", "rustc", dirs));
18+
spawn_and_wait(super::tests::LIBCORE_TESTS.fetch("cargo", "rustc", dirs));
1919

20-
super::abi_cafe::ABI_CAFE_REPO.fetch(dirs);
21-
spawn_and_wait(super::abi_cafe::ABI_CAFE.fetch("cargo", dirs));
2220
super::tests::RAND_REPO.fetch(dirs);
23-
spawn_and_wait(super::tests::RAND.fetch("cargo", dirs));
21+
spawn_and_wait(super::tests::RAND.fetch("cargo", "rustc", dirs));
2422
super::tests::REGEX_REPO.fetch(dirs);
25-
spawn_and_wait(super::tests::REGEX.fetch("cargo", dirs));
23+
spawn_and_wait(super::tests::REGEX.fetch("cargo", "rustc", dirs));
2624
super::tests::PORTABLE_SIMD_REPO.fetch(dirs);
27-
spawn_and_wait(super::tests::PORTABLE_SIMD.fetch("cargo", dirs));
28-
super::bench::SIMPLE_RAYTRACER_REPO.fetch(dirs);
29-
spawn_and_wait(super::bench::SIMPLE_RAYTRACER.fetch("cargo", dirs));
25+
spawn_and_wait(super::tests::PORTABLE_SIMD.fetch("cargo", "rustc", dirs));
3026
}
3127

3228
fn prepare_sysroot(dirs: &Dirs) {
@@ -80,7 +76,7 @@ impl GitRepo {
8076
}
8177
}
8278

83-
fn fetch(&self, dirs: &Dirs) {
79+
pub(crate) fn fetch(&self, dirs: &Dirs) {
8480
match self.url {
8581
GitRepoUrl::Github { user, repo } => {
8682
clone_repo_shallow_github(

0 commit comments

Comments
 (0)