Skip to content

Commit a8e6d5b

Browse files
committed
Merge commit '40b00f4200fbdeefd11815398cb46394b8cb0a5e' into sync_cg_clif-2021-12-30
2 parents 65d8785 + 40b00f4 commit a8e6d5b

20 files changed

+90
-81
lines changed

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

+15
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,21 @@ on:
55
- pull_request
66

77
jobs:
8+
rustfmt:
9+
runs-on: ubuntu-latest
10+
timeout-minutes: 10
11+
12+
steps:
13+
- uses: actions/checkout@v2
14+
15+
- name: Install rustfmt
16+
run: |
17+
rustup component add rustfmt
18+
19+
- name: Rustfmt
20+
run: |
21+
cargo fmt --check
22+
823
build:
924
runs-on: ${{ matrix.os }}
1025
timeout-minutes: 60

compiler/rustc_codegen_cranelift/.github/workflows/nightly-cranelift.yml

+1-1
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ name: Test nightly Cranelift
33
on:
44
push:
55
schedule:
6-
- cron: '1 17 * * *' # At 01:17 UTC every day.
6+
- cron: '17 1 * * *' # At 01:17 UTC every day.
77

88
jobs:
99
build:

compiler/rustc_codegen_cranelift/.gitignore

+1
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ perf.data.old
77
*.events
88
*.string*
99
/y.bin
10+
/y.bin.dSYM
1011
/build
1112
/build_sysroot/sysroot_src
1213
/build_sysroot/compiler-builtins

compiler/rustc_codegen_cranelift/Cargo.toml

-19
Original file line numberDiff line numberDiff line change
@@ -40,31 +40,12 @@ unstable-features = ["jit", "inline_asm"]
4040
jit = ["cranelift-jit", "libloading"]
4141
inline_asm = []
4242

43-
[profile.dev]
44-
# By compiling dependencies with optimizations, performing tests gets much faster.
45-
opt-level = 3
46-
47-
[profile.dev.package.rustc_codegen_cranelift]
48-
# Disabling optimizations for cg_clif itself makes compilation after a change faster.
49-
opt-level = 0
50-
51-
[profile.release.package.rustc_codegen_cranelift]
52-
incremental = true
53-
5443
# Disable optimizations and debuginfo of build scripts and some of the heavy build deps, as the
5544
# execution time of build scripts is so fast that optimizing them slows down the total build time.
56-
[profile.dev.build-override]
57-
opt-level = 0
58-
debug = false
59-
6045
[profile.release.build-override]
6146
opt-level = 0
6247
debug = false
6348

64-
[profile.dev.package.cranelift-codegen-meta]
65-
opt-level = 0
66-
debug = false
67-
6849
[profile.release.package.cranelift-codegen-meta]
6950
opt-level = 0
7051
debug = false

compiler/rustc_codegen_cranelift/Readme.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ Assuming `$cg_clif_dir` is the directory you cloned this repo into and you follo
3737
In the directory with your project (where you can do the usual `cargo build`), run:
3838

3939
```bash
40-
$ $cg_clif_dir/build/cargo build
40+
$ $cg_clif_dir/build/cargo-clif build
4141
```
4242

4343
This will build your project with rustc_codegen_cranelift instead of the usual LLVM backend.

compiler/rustc_codegen_cranelift/build_system/build_backend.rs

+19-12
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,18 @@ pub(crate) fn build_backend(
1010
let mut cmd = Command::new("cargo");
1111
cmd.arg("build").arg("--target").arg(host_triple);
1212

13+
cmd.env("CARGO_BUILD_INCREMENTAL", "true"); // Force incr comp even in release mode
14+
15+
let mut rustflags = env::var("RUSTFLAGS").unwrap_or_default();
16+
17+
if env::var("CI").as_ref().map(|val| &**val) == Ok("true") {
18+
// Deny warnings on CI
19+
rustflags += " -Dwarnings";
20+
21+
// Disabling incr comp reduces cache size and incr comp doesn't save as much on CI anyway
22+
cmd.env("CARGO_BUILD_INCREMENTAL", "false");
23+
}
24+
1325
if use_unstable_features {
1426
cmd.arg("--features").arg("unstable-features");
1527
}
@@ -22,25 +34,20 @@ pub(crate) fn build_backend(
2234
_ => unreachable!(),
2335
}
2436

37+
// Set the rpath to make the cg_clif executable find librustc_codegen_cranelift without changing
38+
// LD_LIBRARY_PATH
2539
if cfg!(unix) {
2640
if cfg!(target_os = "macos") {
27-
cmd.env(
28-
"RUSTFLAGS",
29-
"-Csplit-debuginfo=unpacked \
41+
rustflags += " -Csplit-debuginfo=unpacked \
3042
-Clink-arg=-Wl,-rpath,@loader_path/../lib \
31-
-Zosx-rpath-install-name"
32-
.to_string()
33-
+ env::var("RUSTFLAGS").as_deref().unwrap_or(""),
34-
);
43+
-Zosx-rpath-install-name";
3544
} else {
36-
cmd.env(
37-
"RUSTFLAGS",
38-
"-Clink-arg=-Wl,-rpath=$ORIGIN/../lib ".to_string()
39-
+ env::var("RUSTFLAGS").as_deref().unwrap_or(""),
40-
);
45+
rustflags += " -Clink-arg=-Wl,-rpath=$ORIGIN/../lib ";
4146
}
4247
}
4348

49+
cmd.env("RUSTFLAGS", rustflags);
50+
4451
eprintln!("[BUILD] rustc_codegen_cranelift");
4552
crate::utils::spawn_and_wait(cmd);
4653

compiler/rustc_codegen_cranelift/build_system/build_sysroot.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -46,9 +46,9 @@ pub(crate) fn build_sysroot(
4646
// Build and copy cargo wrapper
4747
let mut build_cargo_wrapper_cmd = Command::new("rustc");
4848
build_cargo_wrapper_cmd
49-
.arg("scripts/cargo.rs")
49+
.arg("scripts/cargo-clif.rs")
5050
.arg("-o")
51-
.arg(target_dir.join("cargo"))
51+
.arg(target_dir.join("cargo-clif"))
5252
.arg("-g");
5353
spawn_and_wait(build_cargo_wrapper_cmd);
5454

compiler/rustc_codegen_cranelift/docs/usage.md

+3-3
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ Assuming `$cg_clif_dir` is the directory you cloned this repo into and you follo
99
In the directory with your project (where you can do the usual `cargo build`), run:
1010

1111
```bash
12-
$ $cg_clif_dir/build/cargo build
12+
$ $cg_clif_dir/build/cargo-clif build
1313
```
1414

1515
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
3232
> The jit mode will probably need cargo integration to make this possible.
3333
3434
```bash
35-
$ $cg_clif_dir/build/cargo jit
35+
$ $cg_clif_dir/build/cargo-clif jit
3636
```
3737

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

4747
```bash
48-
$ $cg_clif_dir/build/cargo lazy-jit
48+
$ $cg_clif_dir/build/cargo-clif lazy-jit
4949
```
5050

5151
## Shell

compiler/rustc_codegen_cranelift/example/mini_core_hello_world.rs

+1
Original file line numberDiff line numberDiff line change
@@ -129,6 +129,7 @@ fn call_return_u128_pair() {
129129
return_u128_pair();
130130
}
131131

132+
#[allow(unreachable_code)] // FIXME false positive
132133
fn main() {
133134
take_unique(Unique {
134135
pointer: 0 as *const (),
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
11
[toolchain]
2-
channel = "nightly-2021-12-20"
2+
channel = "nightly-2021-12-30"
33
components = ["rust-src", "rustc-dev", "llvm-tools-preview"]

compiler/rustc_codegen_cranelift/scripts/setup_rust_fork.sh

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
#!/bin/bash
22
set -e
33

4-
./y.rs build
4+
./y.rs build --no-unstable-features
55
source scripts/config.sh
66

77
echo "[SETUP] Rust fork"

compiler/rustc_codegen_cranelift/scripts/test_rustc_tests.sh

+10-6
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,8 @@ rm src/test/ui/codegen/init-large-type.rs # same
4747
rm src/test/ui/sse2.rs # cpuid not supported, so sse2 not detected
4848
rm src/test/ui/issues/issue-33992.rs # unsupported linkages
4949
rm src/test/ui/issues/issue-51947.rs # same
50+
rm src/test/incremental/hashes/function_interfaces.rs # same
51+
rm src/test/incremental/hashes/statics.rs # same
5052
rm src/test/ui/numbers-arithmetic/saturating-float-casts.rs # intrinsic gives different but valid result
5153
rm src/test/ui/mir/mir_misc_casts.rs # depends on deduplication of constants
5254
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
6062

6163
rm src/test/incremental/hashes/inline_asm.rs # inline asm
6264
rm src/test/incremental/issue-72386.rs # same
63-
rm src/test/incremental/issue-49482.rs # same
64-
rm src/test/incremental/issue-54059.rs # same
6565
rm src/test/incremental/lto.rs # requires lto
66+
rm src/test/incremental/dirty_clean.rs # TODO
6667

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

72-
rm src/test/pretty/asm.rs # inline asm
73-
rm src/test/pretty/raw-str-nonexpr.rs # same
74-
7573
rm -r src/test/run-pass-valgrind/unsized-locals
7674

7775
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
9795

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

98+
rm src/test/incremental/issue-80691-bad-eval-cache.rs # wrong exit code
99+
rm src/test/incremental/spike-neg1.rs # errors out for some reason
100+
rm src/test/incremental/spike-neg2.rs # same
101+
102+
rm src/test/incremental/thinlto/cgu_invalidated_when_import_{added,removed}.rs # requires LLVM
103+
100104
echo "[TEST] rustc test suite"
101-
RUST_TEST_NOCAPTURE=1 COMPILETEST_FORCE_STAGE0=1 ./x.py test --stage 0 src/test/{codegen-units,run-make,run-pass-valgrind,ui}
105+
RUST_TEST_NOCAPTURE=1 COMPILETEST_FORCE_STAGE0=1 ./x.py test --stage 0 src/test/{codegen-units,run-make,run-pass-valgrind,ui,incremental}
102106
popd

compiler/rustc_codegen_cranelift/scripts/tests.sh

+18-18
Original file line numberDiff line numberDiff line change
@@ -80,73 +80,73 @@ function base_sysroot_tests() {
8080

8181
function extended_sysroot_tests() {
8282
pushd rand
83-
../build/cargo clean
83+
../build/cargo-clif clean
8484
if [[ "$HOST_TRIPLE" = "$TARGET_TRIPLE" ]]; then
8585
echo "[TEST] rust-random/rand"
86-
../build/cargo test --workspace
86+
../build/cargo-clif test --workspace
8787
else
8888
echo "[AOT] rust-random/rand"
89-
../build/cargo build --workspace --target $TARGET_TRIPLE --tests
89+
../build/cargo-clif build --workspace --target $TARGET_TRIPLE --tests
9090
fi
9191
popd
9292

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

100100
echo "[BENCH RUN] ebobby/simple-raytracer"
101101
cp ./target/debug/main ./raytracer_cg_clif
102102
hyperfine --runs "${RUN_RUNS:-10}" ./raytracer_cg_llvm ./raytracer_cg_clif
103103
else
104-
../build/cargo clean
104+
../build/cargo-clif clean
105105
echo "[BENCH COMPILE] ebobby/simple-raytracer (skipped)"
106106
echo "[COMPILE] ebobby/simple-raytracer"
107-
../build/cargo build --target $TARGET_TRIPLE
107+
../build/cargo-clif build --target $TARGET_TRIPLE
108108
echo "[BENCH RUN] ebobby/simple-raytracer (skipped)"
109109
fi
110110
popd
111111

112112
pushd build_sysroot/sysroot_src/library/core/tests
113113
echo "[TEST] libcore"
114-
../../../../../build/cargo clean
114+
../../../../../build/cargo-clif clean
115115
if [[ "$HOST_TRIPLE" = "$TARGET_TRIPLE" ]]; then
116-
../../../../../build/cargo test
116+
../../../../../build/cargo-clif test
117117
else
118-
../../../../../build/cargo build --target $TARGET_TRIPLE --tests
118+
../../../../../build/cargo-clif build --target $TARGET_TRIPLE --tests
119119
fi
120120
popd
121121

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

135135
if [[ "$HOST_TRIPLE" = "$TARGET_TRIPLE" ]]; then
136136
echo "[TEST] rust-lang/regex tests"
137-
../build/cargo test --tests -- --exclude-should-panic --test-threads 1 -Zunstable-options -q
137+
../build/cargo-clif test --tests -- --exclude-should-panic --test-threads 1 -Zunstable-options -q
138138
else
139139
echo "[AOT] rust-lang/regex tests"
140-
../build/cargo build --tests --target $TARGET_TRIPLE
140+
../build/cargo-clif build --tests --target $TARGET_TRIPLE
141141
fi
142142
popd
143143

144144
pushd portable-simd
145145
echo "[TEST] rust-lang/portable-simd"
146-
../build/cargo clean
147-
../build/cargo build --all-targets --target $TARGET_TRIPLE
146+
../build/cargo-clif clean
147+
../build/cargo-clif build --all-targets --target $TARGET_TRIPLE
148148
if [[ "$HOST_TRIPLE" = "$TARGET_TRIPLE" ]]; then
149-
../build/cargo test -q
149+
../build/cargo-clif test -q
150150
fi
151151
popd
152152
}

compiler/rustc_codegen_cranelift/src/common.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -237,7 +237,7 @@ pub(crate) struct FunctionCx<'m, 'clif, 'tcx: 'm> {
237237
pub(crate) module: &'m mut dyn Module,
238238
pub(crate) tcx: TyCtxt<'tcx>,
239239
pub(crate) target_config: TargetFrontendConfig, // Cached from module
240-
pub(crate) pointer_type: Type, // Cached from module
240+
pub(crate) pointer_type: Type, // Cached from module
241241
pub(crate) constants_cx: ConstantCx,
242242

243243
pub(crate) instance: Instance<'tcx>,

compiler/rustc_codegen_cranelift/src/debuginfo/emit.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@ impl WriterRelocate {
6767
}
6868

6969
/// Perform the collected relocations to be usable for JIT usage.
70-
#[cfg(feature = "jit")]
70+
#[cfg(all(feature = "jit", not(windows)))]
7171
pub(super) fn relocate_for_jit(mut self, jit_module: &cranelift_jit::JITModule) -> Vec<u8> {
7272
for reloc in self.relocs.drain(..) {
7373
match reloc.name {

compiler/rustc_codegen_cranelift/src/debuginfo/mod.rs

+7-11
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ use crate::prelude::*;
1010
use rustc_index::vec::IndexVec;
1111

1212
use cranelift_codegen::entity::EntityRef;
13-
use cranelift_codegen::ir::{LabelValueLoc, ValueLabel};
13+
use cranelift_codegen::ir::{Endianness, LabelValueLoc, ValueLabel};
1414
use cranelift_codegen::isa::TargetIsa;
1515
use cranelift_codegen::ValueLocRange;
1616

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

26-
fn target_endian(tcx: TyCtxt<'_>) -> RunTimeEndian {
27-
use rustc_target::abi::Endian;
28-
29-
match tcx.data_layout.endian {
30-
Endian::Big => RunTimeEndian::Big,
31-
Endian::Little => RunTimeEndian::Little,
32-
}
33-
}
34-
3526
pub(crate) struct DebugContext<'tcx> {
3627
tcx: TyCtxt<'tcx>,
3728

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

54+
let endian = match isa.endianness() {
55+
Endianness::Little => RunTimeEndian::Little,
56+
Endianness::Big => RunTimeEndian::Big,
57+
};
58+
6359
let mut dwarf = DwarfUnit::new(encoding);
6460

6561
let producer = format!(
@@ -108,7 +104,7 @@ impl<'tcx> DebugContext<'tcx> {
108104
DebugContext {
109105
tcx,
110106

111-
endian: target_endian(tcx),
107+
endian,
112108

113109
dwarf,
114110
unit_range_list: RangeList(Vec::new()),

0 commit comments

Comments
 (0)