Skip to content

Commit

Permalink
Rollup merge of #92435 - bjorn3:sync_cg_clif-2021-12-30, r=bjorn3
Browse files Browse the repository at this point in the history
Sync rustc_codegen_cranelift

The main highlight this sync is enforcing rustfmt and lack of warnings on cg_clif's CI. I will open a separate PR to remove the cg_clif exceptions for them from this repo.

r? `@ghost`

`@rustbot` label +A-codegen +A-cranelift +T-compiler
  • Loading branch information
matthiaskrgr authored Dec 31, 2021
2 parents 81f5dbd + a8e6d5b commit 4e4d258
Show file tree
Hide file tree
Showing 20 changed files with 90 additions and 81 deletions.
15 changes: 15 additions & 0 deletions compiler/rustc_codegen_cranelift/.github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,21 @@ on:
- pull_request

jobs:
rustfmt:
runs-on: ubuntu-latest
timeout-minutes: 10

steps:
- uses: actions/checkout@v2

- name: Install rustfmt
run: |
rustup component add rustfmt
- name: Rustfmt
run: |
cargo fmt --check
build:
runs-on: ${{ matrix.os }}
timeout-minutes: 60
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ name: Test nightly Cranelift
on:
push:
schedule:
- cron: '1 17 * * *' # At 01:17 UTC every day.
- cron: '17 1 * * *' # At 01:17 UTC every day.

jobs:
build:
Expand Down
1 change: 1 addition & 0 deletions compiler/rustc_codegen_cranelift/.gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ perf.data.old
*.events
*.string*
/y.bin
/y.bin.dSYM
/build
/build_sysroot/sysroot_src
/build_sysroot/compiler-builtins
Expand Down
19 changes: 0 additions & 19 deletions compiler/rustc_codegen_cranelift/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -40,31 +40,12 @@ unstable-features = ["jit", "inline_asm"]
jit = ["cranelift-jit", "libloading"]
inline_asm = []

[profile.dev]
# By compiling dependencies with optimizations, performing tests gets much faster.
opt-level = 3

[profile.dev.package.rustc_codegen_cranelift]
# Disabling optimizations for cg_clif itself makes compilation after a change faster.
opt-level = 0

[profile.release.package.rustc_codegen_cranelift]
incremental = true

# Disable optimizations and debuginfo of build scripts and some of the heavy build deps, as the
# execution time of build scripts is so fast that optimizing them slows down the total build time.
[profile.dev.build-override]
opt-level = 0
debug = false

[profile.release.build-override]
opt-level = 0
debug = false

[profile.dev.package.cranelift-codegen-meta]
opt-level = 0
debug = false

[profile.release.package.cranelift-codegen-meta]
opt-level = 0
debug = false
Expand Down
2 changes: 1 addition & 1 deletion compiler/rustc_codegen_cranelift/Readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ Assuming `$cg_clif_dir` is the directory you cloned this repo into and you follo
In the directory with your project (where you can do the usual `cargo build`), run:

```bash
$ $cg_clif_dir/build/cargo build
$ $cg_clif_dir/build/cargo-clif build
```

This will build your project with rustc_codegen_cranelift instead of the usual LLVM backend.
Expand Down
31 changes: 19 additions & 12 deletions compiler/rustc_codegen_cranelift/build_system/build_backend.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,18 @@ pub(crate) fn build_backend(
let mut cmd = Command::new("cargo");
cmd.arg("build").arg("--target").arg(host_triple);

cmd.env("CARGO_BUILD_INCREMENTAL", "true"); // Force incr comp even in release mode

let mut rustflags = env::var("RUSTFLAGS").unwrap_or_default();

if env::var("CI").as_ref().map(|val| &**val) == Ok("true") {
// Deny warnings on CI
rustflags += " -Dwarnings";

// Disabling incr comp reduces cache size and incr comp doesn't save as much on CI anyway
cmd.env("CARGO_BUILD_INCREMENTAL", "false");
}

if use_unstable_features {
cmd.arg("--features").arg("unstable-features");
}
Expand All @@ -22,25 +34,20 @@ pub(crate) fn build_backend(
_ => unreachable!(),
}

// Set the rpath to make the cg_clif executable find librustc_codegen_cranelift without changing
// LD_LIBRARY_PATH
if cfg!(unix) {
if cfg!(target_os = "macos") {
cmd.env(
"RUSTFLAGS",
"-Csplit-debuginfo=unpacked \
rustflags += " -Csplit-debuginfo=unpacked \
-Clink-arg=-Wl,-rpath,@loader_path/../lib \
-Zosx-rpath-install-name"
.to_string()
+ env::var("RUSTFLAGS").as_deref().unwrap_or(""),
);
-Zosx-rpath-install-name";
} else {
cmd.env(
"RUSTFLAGS",
"-Clink-arg=-Wl,-rpath=$ORIGIN/../lib ".to_string()
+ env::var("RUSTFLAGS").as_deref().unwrap_or(""),
);
rustflags += " -Clink-arg=-Wl,-rpath=$ORIGIN/../lib ";
}
}

cmd.env("RUSTFLAGS", rustflags);

eprintln!("[BUILD] rustc_codegen_cranelift");
crate::utils::spawn_and_wait(cmd);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,9 +46,9 @@ pub(crate) fn build_sysroot(
// Build and copy cargo wrapper
let mut build_cargo_wrapper_cmd = Command::new("rustc");
build_cargo_wrapper_cmd
.arg("scripts/cargo.rs")
.arg("scripts/cargo-clif.rs")
.arg("-o")
.arg(target_dir.join("cargo"))
.arg(target_dir.join("cargo-clif"))
.arg("-g");
spawn_and_wait(build_cargo_wrapper_cmd);

Expand Down
6 changes: 3 additions & 3 deletions compiler/rustc_codegen_cranelift/docs/usage.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ Assuming `$cg_clif_dir` is the directory you cloned this repo into and you follo
In the directory with your project (where you can do the usual `cargo build`), run:

```bash
$ $cg_clif_dir/build/cargo build
$ $cg_clif_dir/build/cargo-clif build
```

This will build your project with rustc_codegen_cranelift instead of the usual LLVM backend.
Expand All @@ -32,7 +32,7 @@ In jit mode cg_clif will immediately execute your code without creating an execu
> The jit mode will probably need cargo integration to make this possible.
```bash
$ $cg_clif_dir/build/cargo jit
$ $cg_clif_dir/build/cargo-clif jit
```

or
Expand All @@ -45,7 +45,7 @@ There is also an experimental lazy jit mode. In this mode functions are only com
first called.

```bash
$ $cg_clif_dir/build/cargo lazy-jit
$ $cg_clif_dir/build/cargo-clif lazy-jit
```

## Shell
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -129,6 +129,7 @@ fn call_return_u128_pair() {
return_u128_pair();
}

#[allow(unreachable_code)] // FIXME false positive
fn main() {
take_unique(Unique {
pointer: 0 as *const (),
Expand Down
2 changes: 1 addition & 1 deletion compiler/rustc_codegen_cranelift/rust-toolchain
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
[toolchain]
channel = "nightly-2021-12-20"
channel = "nightly-2021-12-30"
components = ["rust-src", "rustc-dev", "llvm-tools-preview"]
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
#!/bin/bash
set -e

./y.rs build
./y.rs build --no-unstable-features
source scripts/config.sh

echo "[SETUP] Rust fork"
Expand Down
16 changes: 10 additions & 6 deletions compiler/rustc_codegen_cranelift/scripts/test_rustc_tests.sh
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,8 @@ rm src/test/ui/codegen/init-large-type.rs # same
rm src/test/ui/sse2.rs # cpuid not supported, so sse2 not detected
rm src/test/ui/issues/issue-33992.rs # unsupported linkages
rm src/test/ui/issues/issue-51947.rs # same
rm src/test/incremental/hashes/function_interfaces.rs # same
rm src/test/incremental/hashes/statics.rs # same
rm src/test/ui/numbers-arithmetic/saturating-float-casts.rs # intrinsic gives different but valid result
rm src/test/ui/mir/mir_misc_casts.rs # depends on deduplication of constants
rm src/test/ui/mir/mir_raw_fat_ptr.rs # same
Expand All @@ -60,18 +62,14 @@ rm src/test/ui/intrinsics/intrinsic-nearby.rs # unimplemented nearbyintf32 and n

rm src/test/incremental/hashes/inline_asm.rs # inline asm
rm src/test/incremental/issue-72386.rs # same
rm src/test/incremental/issue-49482.rs # same
rm src/test/incremental/issue-54059.rs # same
rm src/test/incremental/lto.rs # requires lto
rm src/test/incremental/dirty_clean.rs # TODO

rm -r src/test/run-make/emit-shared-files # requires the rustdoc executable in build/bin/
rm -r src/test/run-make/unstable-flag-required # same
rm -r src/test/run-make/rustdoc-* # same
rm -r src/test/run-make/emit-named-files # requires full --emit support

rm src/test/pretty/asm.rs # inline asm
rm src/test/pretty/raw-str-nonexpr.rs # same

rm -r src/test/run-pass-valgrind/unsized-locals

rm src/test/ui/json-bom-plus-crlf-multifile.rs # differing warning
Expand All @@ -97,6 +95,12 @@ rm src/test/ui/command/command-current-dir.rs # can't find libstd.so

rm src/test/ui/abi/stack-protector.rs # requires stack protector support

rm src/test/incremental/issue-80691-bad-eval-cache.rs # wrong exit code
rm src/test/incremental/spike-neg1.rs # errors out for some reason
rm src/test/incremental/spike-neg2.rs # same

rm src/test/incremental/thinlto/cgu_invalidated_when_import_{added,removed}.rs # requires LLVM

echo "[TEST] rustc test suite"
RUST_TEST_NOCAPTURE=1 COMPILETEST_FORCE_STAGE0=1 ./x.py test --stage 0 src/test/{codegen-units,run-make,run-pass-valgrind,ui}
RUST_TEST_NOCAPTURE=1 COMPILETEST_FORCE_STAGE0=1 ./x.py test --stage 0 src/test/{codegen-units,run-make,run-pass-valgrind,ui,incremental}
popd
36 changes: 18 additions & 18 deletions compiler/rustc_codegen_cranelift/scripts/tests.sh
Original file line number Diff line number Diff line change
Expand Up @@ -80,73 +80,73 @@ function base_sysroot_tests() {

function extended_sysroot_tests() {
pushd rand
../build/cargo clean
../build/cargo-clif clean
if [[ "$HOST_TRIPLE" = "$TARGET_TRIPLE" ]]; then
echo "[TEST] rust-random/rand"
../build/cargo test --workspace
../build/cargo-clif test --workspace
else
echo "[AOT] rust-random/rand"
../build/cargo build --workspace --target $TARGET_TRIPLE --tests
../build/cargo-clif build --workspace --target $TARGET_TRIPLE --tests
fi
popd

pushd simple-raytracer
if [[ "$HOST_TRIPLE" = "$TARGET_TRIPLE" ]]; then
echo "[BENCH COMPILE] ebobby/simple-raytracer"
hyperfine --runs "${RUN_RUNS:-10}" --warmup 1 --prepare "../build/cargo clean" \
hyperfine --runs "${RUN_RUNS:-10}" --warmup 1 --prepare "../build/cargo-clif clean" \
"RUSTC=rustc RUSTFLAGS='' cargo build" \
"../build/cargo build"
"../build/cargo-clif build"

echo "[BENCH RUN] ebobby/simple-raytracer"
cp ./target/debug/main ./raytracer_cg_clif
hyperfine --runs "${RUN_RUNS:-10}" ./raytracer_cg_llvm ./raytracer_cg_clif
else
../build/cargo clean
../build/cargo-clif clean
echo "[BENCH COMPILE] ebobby/simple-raytracer (skipped)"
echo "[COMPILE] ebobby/simple-raytracer"
../build/cargo build --target $TARGET_TRIPLE
../build/cargo-clif build --target $TARGET_TRIPLE
echo "[BENCH RUN] ebobby/simple-raytracer (skipped)"
fi
popd

pushd build_sysroot/sysroot_src/library/core/tests
echo "[TEST] libcore"
../../../../../build/cargo clean
../../../../../build/cargo-clif clean
if [[ "$HOST_TRIPLE" = "$TARGET_TRIPLE" ]]; then
../../../../../build/cargo test
../../../../../build/cargo-clif test
else
../../../../../build/cargo build --target $TARGET_TRIPLE --tests
../../../../../build/cargo-clif build --target $TARGET_TRIPLE --tests
fi
popd

pushd regex
echo "[TEST] rust-lang/regex example shootout-regex-dna"
../build/cargo clean
../build/cargo-clif clean
export RUSTFLAGS="$RUSTFLAGS --cap-lints warn" # newer aho_corasick versions throw a deprecation warning
# Make sure `[codegen mono items] start` doesn't poison the diff
../build/cargo build --example shootout-regex-dna --target $TARGET_TRIPLE
../build/cargo-clif build --example shootout-regex-dna --target $TARGET_TRIPLE
if [[ "$HOST_TRIPLE" = "$TARGET_TRIPLE" ]]; then
cat examples/regexdna-input.txt \
| ../build/cargo run --example shootout-regex-dna --target $TARGET_TRIPLE \
| ../build/cargo-clif run --example shootout-regex-dna --target $TARGET_TRIPLE \
| grep -v "Spawned thread" > res.txt
diff -u res.txt examples/regexdna-output.txt
fi

if [[ "$HOST_TRIPLE" = "$TARGET_TRIPLE" ]]; then
echo "[TEST] rust-lang/regex tests"
../build/cargo test --tests -- --exclude-should-panic --test-threads 1 -Zunstable-options -q
../build/cargo-clif test --tests -- --exclude-should-panic --test-threads 1 -Zunstable-options -q
else
echo "[AOT] rust-lang/regex tests"
../build/cargo build --tests --target $TARGET_TRIPLE
../build/cargo-clif build --tests --target $TARGET_TRIPLE
fi
popd

pushd portable-simd
echo "[TEST] rust-lang/portable-simd"
../build/cargo clean
../build/cargo build --all-targets --target $TARGET_TRIPLE
../build/cargo-clif clean
../build/cargo-clif build --all-targets --target $TARGET_TRIPLE
if [[ "$HOST_TRIPLE" = "$TARGET_TRIPLE" ]]; then
../build/cargo test -q
../build/cargo-clif test -q
fi
popd
}
Expand Down
2 changes: 1 addition & 1 deletion compiler/rustc_codegen_cranelift/src/common.rs
Original file line number Diff line number Diff line change
Expand Up @@ -237,7 +237,7 @@ pub(crate) struct FunctionCx<'m, 'clif, 'tcx: 'm> {
pub(crate) module: &'m mut dyn Module,
pub(crate) tcx: TyCtxt<'tcx>,
pub(crate) target_config: TargetFrontendConfig, // Cached from module
pub(crate) pointer_type: Type, // Cached from module
pub(crate) pointer_type: Type, // Cached from module
pub(crate) constants_cx: ConstantCx,

pub(crate) instance: Instance<'tcx>,
Expand Down
2 changes: 1 addition & 1 deletion compiler/rustc_codegen_cranelift/src/debuginfo/emit.rs
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ impl WriterRelocate {
}

/// Perform the collected relocations to be usable for JIT usage.
#[cfg(feature = "jit")]
#[cfg(all(feature = "jit", not(windows)))]
pub(super) fn relocate_for_jit(mut self, jit_module: &cranelift_jit::JITModule) -> Vec<u8> {
for reloc in self.relocs.drain(..) {
match reloc.name {
Expand Down
18 changes: 7 additions & 11 deletions compiler/rustc_codegen_cranelift/src/debuginfo/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ use crate::prelude::*;
use rustc_index::vec::IndexVec;

use cranelift_codegen::entity::EntityRef;
use cranelift_codegen::ir::{LabelValueLoc, ValueLabel};
use cranelift_codegen::ir::{Endianness, LabelValueLoc, ValueLabel};
use cranelift_codegen::isa::TargetIsa;
use cranelift_codegen::ValueLocRange;

Expand All @@ -23,15 +23,6 @@ use gimli::{Encoding, Format, LineEncoding, RunTimeEndian, X86_64};
pub(crate) use emit::{DebugReloc, DebugRelocName};
pub(crate) use unwind::UnwindContext;

fn target_endian(tcx: TyCtxt<'_>) -> RunTimeEndian {
use rustc_target::abi::Endian;

match tcx.data_layout.endian {
Endian::Big => RunTimeEndian::Big,
Endian::Little => RunTimeEndian::Little,
}
}

pub(crate) struct DebugContext<'tcx> {
tcx: TyCtxt<'tcx>,

Expand Down Expand Up @@ -60,6 +51,11 @@ impl<'tcx> DebugContext<'tcx> {
address_size: isa.frontend_config().pointer_bytes(),
};

let endian = match isa.endianness() {
Endianness::Little => RunTimeEndian::Little,
Endianness::Big => RunTimeEndian::Big,
};

let mut dwarf = DwarfUnit::new(encoding);

let producer = format!(
Expand Down Expand Up @@ -108,7 +104,7 @@ impl<'tcx> DebugContext<'tcx> {
DebugContext {
tcx,

endian: target_endian(tcx),
endian,

dwarf,
unit_range_list: RangeList(Vec::new()),
Expand Down
Loading

0 comments on commit 4e4d258

Please sign in to comment.