Rollup merge of #92435 - bjorn3:sync_cg_clif-2021-12-30, r=bjorn3

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
This commit is contained in:
Matthias Krüger 2021-12-31 23:14:48 +01:00 committed by GitHub
commit 4e4d2585e5
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
20 changed files with 90 additions and 81 deletions

View File

@ -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

View File

@ -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:

View File

@ -7,6 +7,7 @@ perf.data.old
*.events
*.string*
/y.bin
/y.bin.dSYM
/build
/build_sysroot/sysroot_src
/build_sysroot/compiler-builtins

View File

@ -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

View File

@ -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.

View File

@ -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");
}
@ -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);

View File

@ -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);

View File

@ -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.
@ -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
@ -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

View File

@ -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 (),

View File

@ -1,3 +1,3 @@
[toolchain]
channel = "nightly-2021-12-20"
channel = "nightly-2021-12-30"
components = ["rust-src", "rustc-dev", "llvm-tools-preview"]

View File

@ -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"

View File

@ -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
@ -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
@ -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

View File

@ -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
}

View File

@ -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>,

View File

@ -67,7 +67,7 @@ pub(super) fn new(endian: RunTimeEndian) -> Self {
}
/// 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 {

View File

@ -10,7 +10,7 @@
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;
@ -23,15 +23,6 @@
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>,
@ -60,6 +51,11 @@ pub(crate) fn new(tcx: TyCtxt<'tcx>, isa: &dyn TargetIsa) -> Self {
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!(
@ -108,7 +104,7 @@ pub(crate) fn new(tcx: TyCtxt<'tcx>, isa: &dyn TargetIsa) -> Self {
DebugContext {
tcx,
endian: target_endian(tcx),
endian,
dwarf,
unit_range_list: RangeList(Vec::new()),

View File

@ -2,6 +2,7 @@
use crate::prelude::*;
use cranelift_codegen::ir::Endianness;
use cranelift_codegen::isa::{unwind::UnwindInfo, TargetIsa};
use cranelift_object::ObjectProduct;
@ -17,8 +18,11 @@ pub(crate) struct UnwindContext {
}
impl UnwindContext {
pub(crate) fn new(tcx: TyCtxt<'_>, isa: &dyn TargetIsa, pic_eh_frame: bool) -> Self {
let endian = super::target_endian(tcx);
pub(crate) fn new(isa: &dyn TargetIsa, pic_eh_frame: bool) -> Self {
let endian = match isa.endianness() {
Endianness::Little => RunTimeEndian::Little,
Endianness::Big => RunTimeEndian::Big,
};
let mut frame_table = FrameTable::default();
let cie_id = if let Some(mut cie) = isa.create_systemv_cie() {

View File

@ -243,7 +243,7 @@ pub(crate) fn run_aot(
let isa = crate::build_isa(tcx.sess, &backend_config);
let mut allocator_module = make_module(tcx.sess, isa, "allocator_shim".to_string());
assert_eq!(pointer_ty(tcx), allocator_module.target_config().pointer_type());
let mut allocator_unwind_context = UnwindContext::new(tcx, allocator_module.isa(), true);
let mut allocator_unwind_context = UnwindContext::new(allocator_module.isa(), true);
let created_alloc_shim =
crate::allocator::codegen(tcx, &mut allocator_module, &mut allocator_unwind_context);

View File

@ -141,7 +141,7 @@ fn new(
assert_eq!(pointer_ty(tcx), isa.pointer_type());
let unwind_context =
UnwindContext::new(tcx, isa, matches!(backend_config.codegen_mode, CodegenMode::Aot));
UnwindContext::new(isa, matches!(backend_config.codegen_mode, CodegenMode::Aot));
let debug_context = if debug_info { Some(DebugContext::new(tcx, isa)) } else { None };
CodegenCx {
tcx,