Skip to content

Commit

Permalink
Merge commit '1eded3619d0e55d57521a259bf27a03906fdfad0' into sync_cg_…
Browse files Browse the repository at this point in the history
…clif-2023-07-22
  • Loading branch information
bjorn3 committed Jul 22, 2023
2 parents 42f5419 + 1eded36 commit 3670812
Show file tree
Hide file tree
Showing 30 changed files with 668 additions and 170 deletions.
10 changes: 6 additions & 4 deletions compiler/rustc_codegen_cranelift/.github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,11 @@ jobs:
steps:
- uses: actions/checkout@v3

- name: Install rustfmt
- name: Avoid installing rustc-dev
run: |
rustup component add rustfmt
sed -i 's/components.*/components = ["rustfmt"]/' rust-toolchain
echo 'profile = "minimal"' >> rust-toolchain
rustfmt -v
- name: Rustfmt
run: |
Expand Down Expand Up @@ -127,7 +129,7 @@ jobs:
- uses: actions/checkout@v3

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

- name: Disable JIT tests
run: |
Expand All @@ -136,7 +138,7 @@ jobs:
- name: Test
env:
TARGET_TRIPLE: x86_64-unknown-linux-gnu
run: ./y.rs test --use-backend llvm
run: ./y.sh test --use-backend llvm

bench:
runs-on: ubuntu-latest
Expand Down
84 changes: 53 additions & 31 deletions compiler/rustc_codegen_cranelift/Cargo.lock
Original file line number Diff line number Diff line change
Expand Up @@ -51,18 +51,18 @@ checksum = "baf1de4339761588bc0619e3cbc0120ee582ebb74b53b4efbf79117bd2da40fd"

[[package]]
name = "cranelift-bforest"
version = "0.96.1"
version = "0.98.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "9b6160c0a96253993b79fb7e0983534a4515ecf666120ddf8f92068114997ebc"
checksum = "ec27af72e56235eb326b5bf2de4e70ab7c5ac1fb683a1829595badaf821607fd"
dependencies = [
"cranelift-entity",
]

[[package]]
name = "cranelift-codegen"
version = "0.96.1"
version = "0.98.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "7b38da5f63562e42f3c929d7c76871098e5ad12c8ab44b0659ffc529f22a5b3a"
checksum = "2231e12925e6c5f4bc9c95b62a798eea6ed669a95bc3e00f8b2adb3b7b9b7a80"
dependencies = [
"bumpalo",
"cranelift-bforest",
Expand All @@ -81,39 +81,39 @@ dependencies = [

[[package]]
name = "cranelift-codegen-meta"
version = "0.96.1"
version = "0.98.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "011371e213e163b55dd9e8404b3f2d9fa52cd14dc2f3dc5b83e61ffceff126db"
checksum = "413b00b8dfb3aab85674a534677e7ca08854b503f164a70ec0634fce80996e2c"
dependencies = [
"cranelift-codegen-shared",
]

[[package]]
name = "cranelift-codegen-shared"
version = "0.96.1"
version = "0.98.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "1bf97dde7f5ad571161cdd203a2c9c88682ef669830aea3c14ea5d164ef8bb43"
checksum = "cd0feb9ecc8193ef5cb04f494c5bd835e5bfec4bde726e7ac0444fc9dd76229e"

[[package]]
name = "cranelift-control"
version = "0.96.1"
version = "0.98.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "fd9a9254aee733b0f2b68e5eaaf0337ad53cb23252a056c10a35370551be8d40"
checksum = "72eedd2afcf5fee1e042eaaf18d3750e48ad0eca364a9f5971ecfdd5ef85bf71"
dependencies = [
"arbitrary",
]

[[package]]
name = "cranelift-entity"
version = "0.96.1"
version = "0.98.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "baf39a33ee39479d1337cd9333f3c09786c5a0ca1ec509edcaf9d1346d5de0e5"
checksum = "7af19157be42671073cf8c2a52d6a4ae1e7b11f1dcb4131fede356d9f91c29dd"

[[package]]
name = "cranelift-frontend"
version = "0.96.1"
version = "0.98.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "65e260b92a193a0a2dccc3938f133d9532e7dcfe8d03e36bf8b7d3518c1c1793"
checksum = "c2dc7636c5fad156be7d9ae691cd1aaecd97326caf2ab534ba168056d56aa76c"
dependencies = [
"cranelift-codegen",
"log",
Expand All @@ -123,15 +123,15 @@ dependencies = [

[[package]]
name = "cranelift-isle"
version = "0.96.1"
version = "0.98.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "9446c8e1aadfcdacee1a49592bc2c25d1d9bf5484782c163e7f5485c92cd3c1c"
checksum = "c1111aea4fb6fade5779903f184249a3fc685a799fe4ec59126f9af59c7c2a74"

[[package]]
name = "cranelift-jit"
version = "0.96.1"
version = "0.98.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "689a6df165d0f860c1e1a3d53c28944e2743c3e9ee4c678cf190fe60ad7a6ef5"
checksum = "dadf88076317f6286ec77ebbe65978734fb43b6befdc96f52ff4c4c511841644"
dependencies = [
"anyhow",
"cranelift-codegen",
Expand All @@ -149,9 +149,9 @@ dependencies = [

[[package]]
name = "cranelift-module"
version = "0.96.1"
version = "0.98.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "0b1402d6ff1695b429536b2eaa126db560fc94c375ed0e9cfb15051fc07427f7"
checksum = "c6bae8a82dbf82241b1083e57e06870d2c2bdc9852727be99d58477513816953"
dependencies = [
"anyhow",
"cranelift-codegen",
Expand All @@ -160,9 +160,9 @@ dependencies = [

[[package]]
name = "cranelift-native"
version = "0.96.1"
version = "0.98.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "eac916f3c5aff4b817e42fc2e682292b931495b3fe2603d5e3c3cf602d74e344"
checksum = "1ecfc01a634448468a698beac433d98040033046678a0eed3ca39a3a9f63ae86"
dependencies = [
"cranelift-codegen",
"libc",
Expand All @@ -171,9 +171,9 @@ dependencies = [

[[package]]
name = "cranelift-object"
version = "0.96.1"
version = "0.98.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "23860f4cd064017f2108e6bc5d25660a77cd6eea77f1ac0756870a00abb12e93"
checksum = "0ee14a7276999f0dcaae2de84043e2c2de50820fb89b3db56fab586a4ad26734"
dependencies = [
"anyhow",
"cranelift-codegen",
Expand All @@ -193,6 +193,12 @@ dependencies = [
"cfg-if",
]

[[package]]
name = "equivalent"
version = "1.0.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "88bffebc5d80432c9b140ee17875ff173a8ab62faad5b257da912bd2f6c1c0a1"

[[package]]
name = "fallible-iterator"
version = "0.2.0"
Expand All @@ -206,7 +212,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "ad0a93d233ebf96623465aad4046a8d3aa4da22d4f4beba5388838c8a434bbb4"
dependencies = [
"fallible-iterator",
"indexmap",
"indexmap 1.9.3",
"stable_deref_trait",
]

Expand All @@ -225,6 +231,12 @@ dependencies = [
"ahash",
]

[[package]]
name = "hashbrown"
version = "0.14.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "2c6201b9ff9fd90a5a3bac2e56a830d0caa509576f0e503818ee82c181b3437a"

[[package]]
name = "indexmap"
version = "1.9.3"
Expand All @@ -235,6 +247,16 @@ dependencies = [
"hashbrown 0.12.3",
]

[[package]]
name = "indexmap"
version = "2.0.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "d5477fe2230a79769d8dc68e0eabf5437907c0457a5614a9e8dddb67f65eb65d"
dependencies = [
"equivalent",
"hashbrown 0.14.0",
]

[[package]]
name = "libc"
version = "0.2.138"
Expand Down Expand Up @@ -283,7 +305,7 @@ checksum = "03b4680b86d9cfafba8fc491dc9b6df26b68cf40e9e6cd73909194759a63c385"
dependencies = [
"crc32fast",
"hashbrown 0.13.2",
"indexmap",
"indexmap 1.9.3",
"memchr",
]

Expand All @@ -295,9 +317,9 @@ checksum = "86f0b0d4bf799edbc74508c1e8bf170ff5f41238e5f8225603ca7caaae2b7860"

[[package]]
name = "regalloc2"
version = "0.8.1"
version = "0.9.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "d4a52e724646c6c0800fc456ec43b4165d2f91fba88ceaca06d9e0b400023478"
checksum = "5b4dcbd3a2ae7fb94b5813fa0e957c6ab51bf5d0a8ee1b69e0c2d0f1e6eb8485"
dependencies = [
"hashbrown 0.13.2",
"log",
Expand Down Expand Up @@ -335,7 +357,7 @@ dependencies = [
"cranelift-native",
"cranelift-object",
"gimli",
"indexmap",
"indexmap 2.0.0",
"libloading",
"object",
"smallvec",
Expand Down Expand Up @@ -374,9 +396,9 @@ checksum = "49874b5167b65d7193b8aba1567f5c7d93d001cafc34600cee003eda787e483f"

[[package]]
name = "wasmtime-jit-icache-coherence"
version = "9.0.1"
version = "11.0.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "7d90933b781e1cef7656baed671c7a90bdba0c1c694e04fdd4124419308f5cbb"
checksum = "e34eb67f0829a5614ec54716c8e0c9fe68fab7b9df3686c85f719c9d247f7169"
dependencies = [
"cfg-if",
"libc",
Expand Down
14 changes: 7 additions & 7 deletions compiler/rustc_codegen_cranelift/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -8,17 +8,17 @@ crate-type = ["dylib"]

[dependencies]
# These have to be in sync with each other
cranelift-codegen = { version = "0.96.1", features = ["unwind", "all-arch"] }
cranelift-frontend = { version = "0.96.1" }
cranelift-module = { version = "0.96.1" }
cranelift-native = { version = "0.96.1" }
cranelift-jit = { version = "0.96.1", optional = true }
cranelift-object = { version = "0.96.1" }
cranelift-codegen = { version = "0.98", features = ["unwind", "all-arch"] }
cranelift-frontend = { version = "0.98" }
cranelift-module = { version = "0.98" }
cranelift-native = { version = "0.98" }
cranelift-jit = { version = "0.98", optional = true }
cranelift-object = { version = "0.98" }
target-lexicon = "0.12.0"
gimli = { version = "0.27.2", default-features = false, features = ["write"]}
object = { version = "0.30.3", default-features = false, features = ["std", "read_core", "write", "archive", "coff", "elf", "macho", "pe"] }

indexmap = "1.9.3"
indexmap = "2.0.0"
libloading = { version = "0.7.3", optional = true }
smallvec = "1.8.1"

Expand Down
10 changes: 5 additions & 5 deletions compiler/rustc_codegen_cranelift/Readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -65,12 +65,12 @@ to `./build/host/stage2/bin/`. Note that you would need to do this every time yo
5. Copy cargo from another toolchain: `cp $(rustup which cargo) .build/<your hostname triple>/stage2/bin/cargo`
* Another option is to build it at step 3 and copy with other executables at step 4.
6. Link your new `rustc` to toolchain: `rustup toolchain link stage2 ./build/host/stage2/`.
7. (Windows only) compile y.rs: `rustc +stage2 -O y.rs`.
8. You need to prefix every `./y.rs` (or `y` if you built `y.rs`) command by `rustup run stage2` to make cg_clif use your local changes in rustc.
7. (Windows only) compile the build system: `rustc +stage2 -O build_system/main.rs -o y.exe`.
8. You need to prefix every `./y.sh` (or `y` if you built `build_system/main.rs` as `y`) command by `rustup run stage2` to make cg_clif use your local changes in rustc.

* `rustup run stage2 ./y.rs prepare`
* `rustup run stage2 ./y.rs build`
* (Optional) run tests: `rustup run stage2 ./y.rs test`
* `rustup run stage2 ./y.sh prepare`
* `rustup run stage2 ./y.sh build`
* (Optional) run tests: `rustup run stage2 ./y.sh test`
9. Now you can use your cg_clif build to compile other Rust programs, e.g. you can open any Rust crate and run commands like `$RustCheckoutDir/compiler/rustc_codegen_cranelift/dist/cargo-clif build --release`.

## Configuration
Expand Down
61 changes: 48 additions & 13 deletions compiler/rustc_codegen_cranelift/build_system/bench.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
use std::env;
use std::io::Write;
use std::path::Path;

use super::path::{Dirs, RelPath};
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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();
}
}
Loading

0 comments on commit 3670812

Please sign in to comment.