Skip to content

Sync rustc_codegen_cranelift #107843

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 43 commits into from
Feb 9, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
43 commits
Select commit Hold shift + click to select a range
ef5ec77
abi: add `AddressSpace` field to `Primitive::Pointer`
erikdesjardins Jan 23, 2023
706d7ff
Update codegen cranelift for ConstEvalCounter
bryangarza Dec 29, 2022
39b34dc
Thread a ParamEnv down to might_permit_raw_init
saethlin Jan 22, 2023
b67610f
Merge commit '598f0909568a51de8a2d1148f55a644fd8dffad0' into sync_cg_…
bjorn3 Jan 24, 2023
89e90ed
Vendor newer version of cranelift-native
bjorn3 Jan 25, 2023
ff56716
Fix CI
bjorn3 Jan 25, 2023
801b1a1
Auto merge of #105582 - saethlin:instcombine-assert-inhabited, r=cjgi…
bors Jan 26, 2023
3ac370b
Auto merge of #107314 - matthiaskrgr:rollup-j40lnlj, r=matthiaskrgr
bors Jan 26, 2023
02d5f7f
Auto merge of #107269 - bjorn3:sync_cg_clif-2023-01-24, r=bjorn3
bors Jan 27, 2023
a88ec47
replace usages of fn_sig query with bound_fn_sig
kylematsuda Jan 18, 2023
7bb0bfe
change fn_sig query to use EarlyBinder; remove bound_fn_sig query; ad…
kylematsuda Jan 18, 2023
2157590
add EarlyBinder::no_bound_vars
kylematsuda Jan 19, 2023
56cb727
Sync from rust 18890f05f6cea40fd25bb4bb9aa6f7372b69f641
bjorn3 Jan 27, 2023
e24fa2f
Rustup to rustc 1.69.0-nightly (d7948c843 2023-01-26)
bjorn3 Jan 27, 2023
7ef46c8
Auto merge of #107055 - kylematsuda:eb-fn-sig, r=lcnr
bors Jan 27, 2023
3ba9b13
Don't download abi-cafe and simple-raytracer in ./y.rs prepare
bjorn3 Jan 27, 2023
ba7bb62
Auto merge of #106227 - bryangarza:ctfe-limit, r=oli-obk
bors Jan 29, 2023
572e32b
Fix rustc test suite
bjorn3 Jan 31, 2023
d1024b6
Fix y.rs bench
bjorn3 Jan 31, 2023
79f4cc0
Run y.rs bench in CI
bjorn3 Jan 31, 2023
df04fd6
Don't force many scalar pair values to the stack in write_cvalue_mayb…
bjorn3 Feb 1, 2023
78bf4af
Fix hyperfine install on CI
bjorn3 Feb 1, 2023
21bdff8
Fix transmute from vector to scalar pair again
bjorn3 Feb 1, 2023
a465d6a
Move codegen_and_compile_fn to driver/jit.rs
bjorn3 Feb 3, 2023
d2ffe40
Cleanup -Ztime-passes output
bjorn3 Feb 3, 2023
469783c
Use generic_activity_with_arg in codegen_fn and compile_fn
bjorn3 Feb 3, 2023
a0d3b09
Record cranelift pass timings in self profile results
bjorn3 Feb 3, 2023
2c229a8
Merge pull request #1346 from bjorn3/self_profile_cleanup
bjorn3 Feb 3, 2023
f5669a3
Fix assert_mem_uninitialized_valid in release mode
bjorn3 Feb 3, 2023
efb92a1
Use packed debuginfo for the sysroot on macOS
bjorn3 Feb 3, 2023
761a91a
Build CI dist artifacts without debug assertions
bjorn3 Feb 4, 2023
8b48138
Merge pull request #1347 from bjorn3/dist_no_debug_assertions
bjorn3 Feb 5, 2023
044a3a6
Support const and sym operands in inline asm
bjorn3 Jan 4, 2023
2e93be3
Add create_wrapper_function helper
bjorn3 Feb 5, 2023
a2719a2
Fix linker error when inline asm sym operand is not exported from loc…
bjorn3 Feb 5, 2023
e238ea6
Merge pull request #1350 from bjorn3/inline_asm_sym
bjorn3 Feb 5, 2023
df6b067
Implement const operands for global asm
bjorn3 Feb 5, 2023
178e267
Implement sym operands for global asm
bjorn3 Feb 5, 2023
5ab690d
Merge pull request #1351 from bjorn3/global_asm_const
bjorn3 Feb 5, 2023
6dfa3c9
Sync from rust 044a28a4091f2e1a5883f7fa990223f8b200a2cd
bjorn3 Feb 6, 2023
8494882
Rustup to rustc 1.69.0-nightly (75a0be98f 2023-02-05)
bjorn3 Feb 6, 2023
7d53619
Force the allocator to be looked up from the perspective of the rustc…
bjorn3 Feb 6, 2023
e25566e
Merge commit '7d53619064ab7045c383644cb445052d2a3d46db' into sync_cg_…
bjorn3 Feb 9, 2023
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
146 changes: 128 additions & 18 deletions compiler/rustc_codegen_cranelift/.github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ jobs:
cargo fmt --check
rustfmt --check build_system/mod.rs


build:
runs-on: ${{ matrix.os }}
timeout-minutes: 60
Expand All @@ -33,7 +34,7 @@ jobs:
fail-fast: false
matrix:
include:
- os: ubuntu-20.04 # FIXME switch to ubuntu-22.04 once #1303 is fixed
- os: ubuntu-latest
env:
TARGET_TRIPLE: x86_64-unknown-linux-gnu
- os: macos-latest
Expand Down Expand Up @@ -112,23 +113,6 @@ jobs:
TARGET_TRIPLE: ${{ matrix.env.TARGET_TRIPLE }}
run: ./y.rs test

- name: Package prebuilt cg_clif
run: tar cvfJ cg_clif.tar.xz dist

- name: Upload prebuilt cg_clif
if: matrix.os == 'windows-latest' || matrix.env.TARGET_TRIPLE != 'x86_64-pc-windows-gnu'
uses: actions/upload-artifact@v3
with:
name: cg_clif-${{ matrix.env.TARGET_TRIPLE }}
path: cg_clif.tar.xz

- name: Upload prebuilt cg_clif (cross compile)
if: matrix.os != 'windows-latest' && matrix.env.TARGET_TRIPLE == 'x86_64-pc-windows-gnu'
uses: actions/upload-artifact@v3
with:
name: cg_clif-${{ runner.os }}-cross-x86_64-mingw
path: cg_clif.tar.xz


abi_cafe:
runs-on: ${{ matrix.os }}
Expand Down Expand Up @@ -185,3 +169,129 @@ jobs:
env:
TARGET_TRIPLE: ${{ matrix.env.TARGET_TRIPLE }}
run: ./y.rs abi-cafe


bench:
runs-on: ubuntu-latest
timeout-minutes: 60

defaults:
run:
shell: bash

steps:
- uses: actions/checkout@v3

- name: Cache cargo target dir
uses: actions/cache@v3
with:
path: build/cg_clif
key: ${{ runner.os }}-x86_64-unknown-linux-gnu-cargo-build-target-${{ hashFiles('rust-toolchain', '**/Cargo.lock') }}

- name: Cache cargo bin dir
uses: actions/cache@v3
with:
path: ~/.cargo/bin
key: ${{ runner.os }}-${{ matrix.env.TARGET_TRIPLE }}-cargo-bin-dir-${{ hashFiles('rust-toolchain', '**/Cargo.lock') }}

- name: Use sparse cargo registry
run: |
cat >> ~/.cargo/config.toml <<EOF
[unstable]
sparse-registry = true
EOF

- name: Install hyperfine
run: cargo install hyperfine || true

- name: Prepare dependencies
run: ./y.rs prepare

- name: Build
run: CI_OPT=1 ./y.rs build --sysroot none

- name: Benchmark
run: CI_OPT=1 ./y.rs bench


dist:
runs-on: ${{ matrix.os }}
timeout-minutes: 60

defaults:
run:
shell: bash

strategy:
fail-fast: false
matrix:
include:
# FIXME update at some point in the future once most distros use a newer glibc
- os: ubuntu-20.04
env:
TARGET_TRIPLE: x86_64-unknown-linux-gnu
- os: macos-latest
env:
TARGET_TRIPLE: x86_64-apple-darwin
# cross-compile from Linux to Windows using mingw
- os: ubuntu-latest
env:
TARGET_TRIPLE: x86_64-pc-windows-gnu
- os: windows-latest
env:
TARGET_TRIPLE: x86_64-pc-windows-msvc
- os: windows-latest
env:
TARGET_TRIPLE: x86_64-pc-windows-gnu

steps:
- uses: actions/checkout@v3

- name: Cache cargo target dir
uses: actions/cache@v3
with:
path: build/cg_clif
key: ${{ runner.os }}-${{ matrix.env.TARGET_TRIPLE }}-dist-cargo-build-target-${{ hashFiles('rust-toolchain', '**/Cargo.lock') }}

- name: Set MinGW as the default toolchain
if: matrix.os == 'windows-latest' && matrix.env.TARGET_TRIPLE == 'x86_64-pc-windows-gnu'
run: rustup set default-host x86_64-pc-windows-gnu

- name: Install MinGW toolchain and wine
if: matrix.os == 'ubuntu-latest' && matrix.env.TARGET_TRIPLE == 'x86_64-pc-windows-gnu'
run: |
sudo apt-get update
sudo apt-get install -y gcc-mingw-w64-x86-64 wine-stable

- name: Use sparse cargo registry
run: |
cat >> ~/.cargo/config.toml <<EOF
[unstable]
sparse-registry = true
EOF

- name: Prepare dependencies
run: ./y.rs prepare

- name: Build backend
run: CI_OPT=1 ./y.rs build --sysroot none

- name: Build sysroot
run: CI_OPT=1 ./y.rs build

- name: Package prebuilt cg_clif
run: tar cvfJ cg_clif.tar.xz dist

- name: Upload prebuilt cg_clif
if: matrix.os == 'windows-latest' || matrix.env.TARGET_TRIPLE != 'x86_64-pc-windows-gnu'
uses: actions/upload-artifact@v3
with:
name: cg_clif-${{ matrix.env.TARGET_TRIPLE }}
path: cg_clif.tar.xz

- name: Upload prebuilt cg_clif (cross compile)
if: matrix.os != 'windows-latest' && matrix.env.TARGET_TRIPLE == 'x86_64-pc-windows-gnu'
uses: actions/upload-artifact@v3
with:
name: cg_clif-${{ runner.os }}-cross-x86_64-mingw
path: cg_clif.tar.xz
4 changes: 2 additions & 2 deletions compiler/rustc_codegen_cranelift/build_sysroot/Cargo.lock
Original file line number Diff line number Diff line change
Expand Up @@ -34,9 +34,9 @@ dependencies = [

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

[[package]]
name = "cfg-if"
Expand Down
8 changes: 5 additions & 3 deletions compiler/rustc_codegen_cranelift/build_system/abi_cafe.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,10 @@ use super::prepare::GitRepo;
use super::utils::{spawn_and_wait, CargoProject, Compiler};
use super::SysrootKind;

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

pub(crate) static ABI_CAFE: CargoProject =
CargoProject::new(&ABI_CAFE_REPO.source_dir(), "abi_cafe");
static ABI_CAFE: CargoProject = CargoProject::new(&ABI_CAFE_REPO.source_dir(), "abi_cafe");

pub(crate) fn run(
channel: &str,
Expand All @@ -19,6 +18,9 @@ pub(crate) fn run(
cg_clif_dylib: &Path,
bootstrap_host_compiler: &Compiler,
) {
ABI_CAFE_REPO.fetch(dirs);
spawn_and_wait(ABI_CAFE.fetch("cargo", &bootstrap_host_compiler.rustc, dirs));

eprintln!("Building sysroot for abi-cafe");
build_sysroot::build_sysroot(
dirs,
Expand Down
32 changes: 19 additions & 13 deletions compiler/rustc_codegen_cranelift/build_system/bench.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,20 +5,20 @@ use std::path::Path;
use super::path::{Dirs, RelPath};
use super::prepare::GitRepo;
use super::rustc_info::get_file_name;
use super::utils::{hyperfine_command, is_ci, spawn_and_wait, CargoProject, Compiler};
use super::utils::{hyperfine_command, spawn_and_wait, CargoProject, Compiler};

pub(crate) static SIMPLE_RAYTRACER_REPO: GitRepo = GitRepo::github(
static SIMPLE_RAYTRACER_REPO: GitRepo = GitRepo::github(
"ebobby",
"simple-raytracer",
"804a7a21b9e673a482797aa289a18ed480e4d813",
"<none>",
);

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

pub(crate) static SIMPLE_RAYTRACER: CargoProject =
static SIMPLE_RAYTRACER: CargoProject =
CargoProject::new(&SIMPLE_RAYTRACER_REPO.source_dir(), "simple_raytracer");

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

if !SIMPLE_RAYTRACER_REPO.source_dir().to_path(dirs).exists() {
SIMPLE_RAYTRACER_REPO.fetch(dirs);
spawn_and_wait(SIMPLE_RAYTRACER.fetch(
&bootstrap_host_compiler.cargo,
&bootstrap_host_compiler.rustc,
dirs,
));
}

eprintln!("[LLVM BUILD] simple-raytracer");
let build_cmd = SIMPLE_RAYTRACER_LLVM.build(bootstrap_host_compiler, dirs);
spawn_and_wait(build_cmd);
Expand All @@ -45,10 +54,7 @@ fn benchmark_simple_raytracer(dirs: &Dirs, bootstrap_host_compiler: &Compiler) {
)
.unwrap();

let run_runs = env::var("RUN_RUNS")
.unwrap_or(if is_ci() { "2" } else { "10" }.to_string())
.parse()
.unwrap();
let bench_runs = env::var("BENCH_RUNS").unwrap_or_else(|_| "10".to_string()).parse().unwrap();

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

let clean_cmd = format!(
"cargo clean --manifest-path {manifest_path} --target-dir {target_dir}",
"RUSTC=rustc cargo clean --manifest-path {manifest_path} --target-dir {target_dir}",
manifest_path = manifest_path.display(),
target_dir = target_dir.display(),
);
let llvm_build_cmd = format!(
"cargo build --manifest-path {manifest_path} --target-dir {target_dir}",
"RUSTC=rustc cargo build --manifest-path {manifest_path} --target-dir {target_dir}",
manifest_path = manifest_path.display(),
target_dir = target_dir.display(),
);
let clif_build_cmd = format!(
"{cargo_clif} build --manifest-path {manifest_path} --target-dir {target_dir}",
"RUSTC=rustc {cargo_clif} build --manifest-path {manifest_path} --target-dir {target_dir}",
cargo_clif = cargo_clif.display(),
manifest_path = manifest_path.display(),
target_dir = target_dir.display(),
);

let bench_compile =
hyperfine_command(1, run_runs, Some(&clean_cmd), &llvm_build_cmd, &clif_build_cmd);
hyperfine_command(1, bench_runs, Some(&clean_cmd), &llvm_build_cmd, &clif_build_cmd);

spawn_and_wait(bench_compile);

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

let mut bench_run = hyperfine_command(
0,
run_runs,
bench_runs,
None,
Path::new(".").join(get_file_name("raytracer_cg_llvm", "bin")).to_str().unwrap(),
Path::new(".").join(get_file_name("raytracer_cg_clif", "bin")).to_str().unwrap(),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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, CargoProject, Compiler};
use super::utils::{is_ci, is_ci_opt, CargoProject, Compiler};

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

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

cmd.env("CARGO_PROFILE_RELEASE_DEBUG_ASSERTIONS", "true");
if !is_ci_opt() {
cmd.env("CARGO_PROFILE_RELEASE_DEBUG_ASSERTIONS", "true");
}
}

if use_unstable_features {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -248,6 +248,9 @@ fn build_clif_sysroot_for_triple(
build_cmd.arg("--release");
}
build_cmd.env("__CARGO_DEFAULT_LIB_METADATA", "cg_clif");
if compiler.triple.contains("apple") {
build_cmd.env("CARGO_PROFILE_RELEASE_SPLIT_DEBUGINFO", "packed");
}
spawn_and_wait(build_cmd);

for entry in fs::read_dir(build_dir.join("deps")).unwrap() {
Expand Down
8 changes: 5 additions & 3 deletions compiler/rustc_codegen_cranelift/build_system/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ use std::env;
use std::path::PathBuf;
use std::process;

use self::utils::{is_ci, Compiler};
use self::utils::{is_ci, is_ci_opt, Compiler};

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

// Enable the Cranelift verifier
env::set_var("CG_CLIF_ENABLE_VERIFIER", "1");
if !is_ci_opt() {
// Enable the Cranelift verifier
env::set_var("CG_CLIF_ENABLE_VERIFIER", "1");
}
}

let mut args = env::args().skip(1);
Expand Down
18 changes: 7 additions & 11 deletions compiler/rustc_codegen_cranelift/build_system/prepare.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,22 +11,18 @@ use super::utils::{copy_dir_recursively, git_command, retry_spawn_and_wait, spaw
pub(crate) fn prepare(dirs: &Dirs) {
RelPath::DOWNLOAD.ensure_fresh(dirs);

spawn_and_wait(super::build_backend::CG_CLIF.fetch("cargo", dirs));
spawn_and_wait(super::build_backend::CG_CLIF.fetch("cargo", "rustc", dirs));

prepare_sysroot(dirs);
spawn_and_wait(super::build_sysroot::STANDARD_LIBRARY.fetch("cargo", dirs));
spawn_and_wait(super::tests::LIBCORE_TESTS.fetch("cargo", dirs));
spawn_and_wait(super::build_sysroot::STANDARD_LIBRARY.fetch("cargo", "rustc", dirs));
spawn_and_wait(super::tests::LIBCORE_TESTS.fetch("cargo", "rustc", dirs));

super::abi_cafe::ABI_CAFE_REPO.fetch(dirs);
spawn_and_wait(super::abi_cafe::ABI_CAFE.fetch("cargo", dirs));
super::tests::RAND_REPO.fetch(dirs);
spawn_and_wait(super::tests::RAND.fetch("cargo", dirs));
spawn_and_wait(super::tests::RAND.fetch("cargo", "rustc", dirs));
super::tests::REGEX_REPO.fetch(dirs);
spawn_and_wait(super::tests::REGEX.fetch("cargo", dirs));
spawn_and_wait(super::tests::REGEX.fetch("cargo", "rustc", dirs));
super::tests::PORTABLE_SIMD_REPO.fetch(dirs);
spawn_and_wait(super::tests::PORTABLE_SIMD.fetch("cargo", dirs));
super::bench::SIMPLE_RAYTRACER_REPO.fetch(dirs);
spawn_and_wait(super::bench::SIMPLE_RAYTRACER.fetch("cargo", dirs));
spawn_and_wait(super::tests::PORTABLE_SIMD.fetch("cargo", "rustc", dirs));
}

fn prepare_sysroot(dirs: &Dirs) {
Expand Down Expand Up @@ -80,7 +76,7 @@ impl GitRepo {
}
}

fn fetch(&self, dirs: &Dirs) {
pub(crate) fn fetch(&self, dirs: &Dirs) {
match self.url {
GitRepoUrl::Github { user, repo } => {
clone_repo_shallow_github(
Expand Down
Loading