Merge commit '03f01bbe901d60b71cf2c5ec766aef5e532ab79d' into update_cg_clif-2020-11-01

This commit is contained in:
bjorn3 2020-11-03 11:00:04 +01:00
parent 793d26047f
commit 285c7c66dc
53 changed files with 609 additions and 385 deletions

44
.github/workflows/bootstrap_rustc.yml vendored Normal file
View File

@ -0,0 +1,44 @@
name: Bootstrap rustc using cg_clif
on:
- push
jobs:
bootstrap_rustc:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- name: Cache cargo installed crates
uses: actions/cache@v2
with:
path: ~/.cargo/bin
key: ${{ runner.os }}-cargo-installed-crates
- name: Cache cargo registry and index
uses: actions/cache@v2
with:
path: |
~/.cargo/registry
~/.cargo/git
key: ${{ runner.os }}-cargo-registry-and-index-${{ hashFiles('**/Cargo.lock') }}
- name: Cache cargo target dir
uses: actions/cache@v2
with:
path: target
key: ${{ runner.os }}-cargo-build-target-${{ hashFiles('rust-toolchain', '**/Cargo.lock') }}
- name: Prepare dependencies
run: |
git config --global user.email "user@example.com"
git config --global user.name "User"
./prepare.sh
- name: Test
run: |
# Enable backtraces for easier debugging
export RUST_BACKTRACE=1
./scripts/test_bootstrap.sh

View File

@ -51,4 +51,13 @@ jobs:
export COMPILE_RUNS=2
export RUN_RUNS=2
./test.sh --release
./test.sh
- name: Package prebuilt cg_clif
run: tar cvfJ cg_clif.tar.xz build
- name: Upload prebuilt cg_clif
uses: actions/upload-artifact@v2
with:
name: cg_clif-${{ runner.os }}
path: cg_clif.tar.xz

2
.gitignore vendored
View File

@ -6,7 +6,7 @@ perf.data
perf.data.old
*.events
*.string*
/build_sysroot/sysroot
/build
/build_sysroot/sysroot_src
/rust
/rand

20
Cargo.lock generated
View File

@ -44,7 +44,7 @@ checksum = "4785bdd1c96b2a846b2bd7cc02e86b6b3dbf14e7e53446c4f54c92a361040822"
[[package]]
name = "cranelift-bforest"
version = "0.67.0"
source = "git+https://github.com/bytecodealliance/wasmtime/?branch=main#4fd90dccabb266e983740e1f5daf8bde9266b286"
source = "git+https://github.com/bytecodealliance/wasmtime/?branch=main#44cbdecea03c360ea82e6482f0cf6c614effef21"
dependencies = [
"cranelift-entity",
]
@ -52,7 +52,7 @@ dependencies = [
[[package]]
name = "cranelift-codegen"
version = "0.67.0"
source = "git+https://github.com/bytecodealliance/wasmtime/?branch=main#4fd90dccabb266e983740e1f5daf8bde9266b286"
source = "git+https://github.com/bytecodealliance/wasmtime/?branch=main#44cbdecea03c360ea82e6482f0cf6c614effef21"
dependencies = [
"byteorder",
"cranelift-bforest",
@ -70,7 +70,7 @@ dependencies = [
[[package]]
name = "cranelift-codegen-meta"
version = "0.67.0"
source = "git+https://github.com/bytecodealliance/wasmtime/?branch=main#4fd90dccabb266e983740e1f5daf8bde9266b286"
source = "git+https://github.com/bytecodealliance/wasmtime/?branch=main#44cbdecea03c360ea82e6482f0cf6c614effef21"
dependencies = [
"cranelift-codegen-shared",
"cranelift-entity",
@ -79,17 +79,17 @@ dependencies = [
[[package]]
name = "cranelift-codegen-shared"
version = "0.67.0"
source = "git+https://github.com/bytecodealliance/wasmtime/?branch=main#4fd90dccabb266e983740e1f5daf8bde9266b286"
source = "git+https://github.com/bytecodealliance/wasmtime/?branch=main#44cbdecea03c360ea82e6482f0cf6c614effef21"
[[package]]
name = "cranelift-entity"
version = "0.67.0"
source = "git+https://github.com/bytecodealliance/wasmtime/?branch=main#4fd90dccabb266e983740e1f5daf8bde9266b286"
source = "git+https://github.com/bytecodealliance/wasmtime/?branch=main#44cbdecea03c360ea82e6482f0cf6c614effef21"
[[package]]
name = "cranelift-frontend"
version = "0.67.0"
source = "git+https://github.com/bytecodealliance/wasmtime/?branch=main#4fd90dccabb266e983740e1f5daf8bde9266b286"
source = "git+https://github.com/bytecodealliance/wasmtime/?branch=main#44cbdecea03c360ea82e6482f0cf6c614effef21"
dependencies = [
"cranelift-codegen",
"log",
@ -100,7 +100,7 @@ dependencies = [
[[package]]
name = "cranelift-module"
version = "0.67.0"
source = "git+https://github.com/bytecodealliance/wasmtime/?branch=main#4fd90dccabb266e983740e1f5daf8bde9266b286"
source = "git+https://github.com/bytecodealliance/wasmtime/?branch=main#44cbdecea03c360ea82e6482f0cf6c614effef21"
dependencies = [
"anyhow",
"cranelift-codegen",
@ -112,7 +112,7 @@ dependencies = [
[[package]]
name = "cranelift-native"
version = "0.67.0"
source = "git+https://github.com/bytecodealliance/wasmtime/?branch=main#4fd90dccabb266e983740e1f5daf8bde9266b286"
source = "git+https://github.com/bytecodealliance/wasmtime/?branch=main#44cbdecea03c360ea82e6482f0cf6c614effef21"
dependencies = [
"cranelift-codegen",
"raw-cpuid",
@ -122,7 +122,7 @@ dependencies = [
[[package]]
name = "cranelift-object"
version = "0.67.0"
source = "git+https://github.com/bytecodealliance/wasmtime/?branch=main#4fd90dccabb266e983740e1f5daf8bde9266b286"
source = "git+https://github.com/bytecodealliance/wasmtime/?branch=main#44cbdecea03c360ea82e6482f0cf6c614effef21"
dependencies = [
"anyhow",
"cranelift-codegen",
@ -135,7 +135,7 @@ dependencies = [
[[package]]
name = "cranelift-simplejit"
version = "0.67.0"
source = "git+https://github.com/bytecodealliance/wasmtime/?branch=main#4fd90dccabb266e983740e1f5daf8bde9266b286"
source = "git+https://github.com/bytecodealliance/wasmtime/?branch=main#44cbdecea03c360ea82e6482f0cf6c614effef21"
dependencies = [
"cranelift-codegen",
"cranelift-entity",

View File

@ -2,41 +2,56 @@
> ⚠⚠⚠ Certain kinds of FFI don't work yet. ⚠⚠⚠
The goal of this project is to create an alternative codegen backend for the rust compiler based on [Cranelift](https://github.com/bytecodealliance/wasmtime/blob/master/cranelift). This has the potential to improve compilation times in debug mode. If your project doesn't use any of the things listed under "Not yet supported", it should work fine. If not please open an issue.
The goal of this project is to create an alternative codegen backend for the rust compiler based on [Cranelift](https://github.com/bytecodealliance/wasmtime/blob/master/cranelift).
This has the potential to improve compilation times in debug mode.
If your project doesn't use any of the things listed under "Not yet supported", it should work fine.
If not please open an issue.
## Building
## Building and testing
```bash
$ git clone https://github.com/bjorn3/rustc_codegen_cranelift.git
$ cd rustc_codegen_cranelift
$ ./prepare.sh # download and patch sysroot src and install hyperfine for benchmarking
$ ./test.sh --release
$ ./build.sh
```
To run the test suite replace the last command with:
```bash
$ ./test.sh
```
This will implicitly build cg_clif too. Both `build.sh` and `test.sh` accept a `--debug` argument to
build in debug mode.
Alternatively you can download a pre built version from [GHA]. It is listed in the artifacts section
of workflow runs. Unfortunately due to GHA restrictions you need to be logged in to access it.
[GHA]: https://github.com/bjorn3/rustc_codegen_cranelift/actions?query=branch%3Amaster+event%3Apush+is%3Asuccess
## Usage
rustc_codegen_cranelift can be used as a near-drop-in replacement for `cargo build` or `cargo run` for existing projects.
Assuming `$cg_clif_dir` is the directory you cloned this repo into and you followed the instructions (`prepare.sh` and `test.sh`).
Assuming `$cg_clif_dir` is the directory you cloned this repo into and you followed the instructions (`prepare.sh` and `build.sh` or `test.sh`).
### Cargo
In the directory with your project (where you can do the usual `cargo build`), run:
```bash
$ $cg_clif_dir/cargo.sh run
$ $cg_clif_dir/build/cargo.sh run
```
This should build and run your project with rustc_codegen_cranelift instead of the usual LLVM backend.
If you compiled cg_clif in debug mode (aka you didn't pass `--release` to `./test.sh`) you should set `CHANNEL="debug"`.
### Rustc
> You should prefer using the Cargo method.
```bash
$ $cg_clif_dir/target/release/cg_clif my_crate.rs
$ $cg_clif_dir/build/cg_clif my_crate.rs
```
### Jit mode
@ -47,13 +62,13 @@ 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/cargo.sh jit
$ $cg_clif_dir/build/cargo.sh jit
```
or
```bash
$ $cg_clif_dir/target/release/cg_clif --jit my_crate.rs
$ $cg_clif_dir/build/cg_clif --jit my_crate.rs
```
### Shell
@ -62,7 +77,7 @@ These are a few functions that allow you to easily run rust code from the shell
```bash
function jit_naked() {
echo "$@" | $cg_clif_dir/target/release/cg_clif - --jit
echo "$@" | $cg_clif_dir/build/cg_clif - --jit
}
function jit() {

47
build.sh Executable file
View File

@ -0,0 +1,47 @@
#!/bin/bash
set -e
# Settings
export CHANNEL="release"
build_sysroot=1
target_dir='build'
while [[ $# != 0 ]]; do
case $1 in
"--debug")
export CHANNEL="debug"
;;
"--without-sysroot")
build_sysroot=0
;;
"--target-dir")
target_dir=$2
shift
;;
*)
echo "Unknown flag '$1'"
echo "Usage: ./build.sh [--debug] [--without-sysroot] [--target-dir DIR]"
;;
esac
shift
done
# Build cg_clif
export RUSTFLAGS="-Zrun_dsymutil=no"
if [[ "$CHANNEL" == "release" ]]; then
cargo build --release
else
cargo build
fi
rm -rf $target_dir
mkdir $target_dir
cp -a target/$CHANNEL/cg_clif{,_build_sysroot} target/$CHANNEL/*rustc_codegen_cranelift* $target_dir/
cp -a rust-toolchain scripts/config.sh scripts/cargo.sh $target_dir
if [[ "$build_sysroot" == "1" ]]; then
echo "[BUILD] sysroot"
export CG_CLIF_INCR_CACHE_DISABLED=1
dir=$(pwd)
cd $target_dir
time $dir/build_sysroot/build_sysroot.sh
fi

View File

@ -3,25 +3,28 @@
# Requires the CHANNEL env var to be set to `debug` or `release.`
set -e
cd $(dirname "$0")
pushd ../ >/dev/null
source ./scripts/config.sh
popd >/dev/null
source ./config.sh
dir=$(pwd)
# Use rustc with cg_clif as hotpluggable backend instead of the custom cg_clif driver so that
# build scripts are still compiled using cg_llvm.
export RUSTC=$dir"/cg_clif_build_sysroot"
export RUSTFLAGS=$RUSTFLAGS" --clif"
cd $(dirname "$0")
# Cleanup for previous run
# v Clean target dir except for build scripts and incremental cache
rm -r target/*/{debug,release}/{build,deps,examples,libsysroot*,native} 2>/dev/null || true
rm -r sysroot/ 2>/dev/null || true
# Use rustc with cg_clif as hotpluggable backend instead of the custom cg_clif driver so that
# build scripts are still compiled using cg_llvm.
export RUSTC=$(pwd)/../"target/"$CHANNEL"/cg_clif_build_sysroot"
export RUSTFLAGS=$RUSTFLAGS" --clif"
# We expect the target dir in the default location. Guard against the user changing it.
export CARGO_TARGET_DIR=target
# Build libs
export RUSTFLAGS="$RUSTFLAGS -Zforce-unstable-if-unmarked -Cpanic=abort"
if [[ "$1" == "--release" ]]; then
if [[ "$1" != "--debug" ]]; then
sysroot_channel='release'
# FIXME Enable incremental again once rust-lang/rust#74946 is fixed
# FIXME Enable -Zmir-opt-level=2 again once it doesn't ice anymore
@ -32,5 +35,5 @@ else
fi
# Copy files to sysroot
mkdir -p sysroot/lib/rustlib/$TARGET_TRIPLE/lib/
cp -r target/$TARGET_TRIPLE/$sysroot_channel/deps/* sysroot/lib/rustlib/$TARGET_TRIPLE/lib/
mkdir -p $dir/sysroot/lib/rustlib/$TARGET_TRIPLE/lib/
cp -a target/$TARGET_TRIPLE/$sysroot_channel/deps/* $dir/sysroot/lib/rustlib/$TARGET_TRIPLE/lib/

View File

@ -12,7 +12,7 @@ fi
rm -rf $DST_DIR
mkdir -p $DST_DIR/library
cp -r $SRC_DIR/library $DST_DIR/
cp -a $SRC_DIR/library $DST_DIR/
pushd $DST_DIR
echo "[GIT] init"

View File

@ -1,5 +1,5 @@
#!/bin/bash --verbose
set -e
rm -rf target/ build_sysroot/{sysroot/,sysroot_src/,target/} perf.data{,.old}
rm -rf target/ build/ build_sysroot/{sysroot_src/,target/} perf.data{,.old}
rm -rf rand/ regex/ simple-raytracer/

View File

@ -9,7 +9,4 @@
object files when their content should have been changed by a change to cg_clif.</dd>
<dt>CG_CLIF_DISPLAY_CG_TIME</dt>
<dd>If "1", display the time it took to perform codegen for a crate</dd>
<dt>CG_CLIF_FUNCTION_SECTIONS</dt>
<dd>Use a single section for each function. This will often reduce the executable size at the
cost of making linking significantly slower.</dd>
</dl>

View File

@ -48,6 +48,7 @@ unsafe impl Copy for u8 {}
unsafe impl Copy for u16 {}
unsafe impl Copy for u32 {}
unsafe impl Copy for u64 {}
unsafe impl Copy for u128 {}
unsafe impl Copy for usize {}
unsafe impl Copy for i8 {}
unsafe impl Copy for i16 {}
@ -283,6 +284,15 @@ impl PartialEq for u64 {
}
}
impl PartialEq for u128 {
fn eq(&self, other: &u128) -> bool {
(*self) == (*other)
}
fn ne(&self, other: &u128) -> bool {
(*self) != (*other)
}
}
impl PartialEq for usize {
fn eq(&self, other: &usize) -> bool {
(*self) == (*other)

View File

@ -287,6 +287,8 @@ fn main() {
assert_eq!(repeat[0], Some(42));
assert_eq!(repeat[1], Some(42));
from_decimal_string();
#[cfg(not(jit))]
test_tls();
@ -446,3 +448,23 @@ fn check_niche_behavior () {
intrinsics::abort();
}
}
fn from_decimal_string() {
loop {
let multiplier = 1;
take_multiplier_ref(&multiplier);
if multiplier == 1 {
break;
}
unreachable();
}
}
fn take_multiplier_ref(_multiplier: &u128) {}
fn unreachable() -> ! {
panic("unreachable")
}

View File

@ -315,13 +315,13 @@ fn test_checked_mul() {
assert_eq!(1i8.checked_mul(-128i8), Some(-128i8));
assert_eq!((-128i8).checked_mul(-128i8), None);
assert_eq!(1u64.checked_mul(u64::max_value()), Some(u64::max_value()));
assert_eq!(u64::max_value().checked_mul(u64::max_value()), None);
assert_eq!(1i64.checked_mul(i64::max_value()), Some(i64::max_value()));
assert_eq!(i64::max_value().checked_mul(i64::max_value()), None);
assert_eq!((-1i64).checked_mul(i64::min_value() + 1), Some(i64::max_value()));
assert_eq!(1i64.checked_mul(i64::min_value()), Some(i64::min_value()));
assert_eq!(i64::min_value().checked_mul(i64::min_value()), None);
assert_eq!(1u64.checked_mul(u64::MAX), Some(u64::MAX));
assert_eq!(u64::MAX.checked_mul(u64::MAX), None);
assert_eq!(1i64.checked_mul(i64::MAX), Some(i64::MAX));
assert_eq!(i64::MAX.checked_mul(i64::MAX), None);
assert_eq!((-1i64).checked_mul(i64::MIN + 1), Some(i64::MAX));
assert_eq!(1i64.checked_mul(i64::MIN), Some(i64::MIN));
assert_eq!(i64::MIN.checked_mul(i64::MIN), None);
}
#[derive(PartialEq)]

View File

@ -1 +1 @@
nightly-2020-10-26
nightly-2020-10-31

View File

@ -1,19 +1,13 @@
#!/bin/bash
if [ -z $CHANNEL ]; then
export CHANNEL='release'
fi
pushd $(dirname "$0") >/dev/null
source scripts/config.sh
dir=$(dirname "$0")
source $dir/config.sh
# read nightly compiler from rust-toolchain file
TOOLCHAIN=$(cat rust-toolchain)
popd >/dev/null
TOOLCHAIN=$(cat $dir/rust-toolchain)
cmd=$1
shift
shift || true
if [[ "$cmd" = "jit" ]]; then
cargo +${TOOLCHAIN} rustc $@ -- --jit

View File

@ -39,18 +39,19 @@ echo
export RUSTC_WRAPPER=
fi
export RUSTC=$(pwd)/"target/"$CHANNEL"/cg_clif"
dir=$(cd $(dirname "$BASH_SOURCE"); pwd)
export RUSTC=$dir"/cg_clif"
export RUSTFLAGS=$linker
export RUSTDOCFLAGS=$linker' -Ztrim-diagnostic-paths=no -Cpanic=abort -Zpanic-abort-tests '\
'-Zcodegen-backend='$(pwd)'/target/'$CHANNEL'/librustc_codegen_cranelift.'$dylib_ext' --sysroot '$(pwd)'/build_sysroot/sysroot'
'-Zcodegen-backend='$dir'/librustc_codegen_cranelift.'$dylib_ext' --sysroot '$dir'/sysroot'
# FIXME remove once the atomic shim is gone
if [[ `uname` == 'Darwin' ]]; then
export RUSTFLAGS="$RUSTFLAGS -Clink-arg=-undefined -Clink-arg=dynamic_lookup"
fi
export LD_LIBRARY_PATH="$(pwd)/target/out:$(pwd)/build_sysroot/sysroot/lib/rustlib/"$TARGET_TRIPLE"/lib:\
$(pwd)/target/"$CHANNEL":$(rustc --print sysroot)/lib"
export LD_LIBRARY_PATH="$dir:$(rustc --print sysroot)/lib:$dir/target/out:$dir/sysroot/lib/rustlib/"$TARGET_TRIPLE"/lib"
export DYLD_LIBRARY_PATH=$LD_LIBRARY_PATH
export CG_CLIF_DISPLAY_CG_TIME=1

View File

@ -1,9 +1,8 @@
#!/bin/bash
#![forbid(unsafe_code)]/* This line is ignored by bash
# This block is ignored by rustc
CHANNEL="release"
pushd $(dirname "$0")/../
source scripts/config.sh
source build/config.sh
popd
PROFILE=$1 OUTPUT=$2 exec $RUSTC $RUSTFLAGS --jit $0
#*/

View File

@ -26,6 +26,15 @@ case $1 in
git add rust-toolchain build_sysroot/Cargo.lock
git commit -m "Rustup to $(rustc -V)"
;;
"push")
cg_clif=$(pwd)
pushd ../rust
branch=update_cg_clif-$(date +%Y-%m-%d)
git checkout -b $branch
git subtree pull --prefix=compiler/rustc_codegen_cranelift/ https://github.com/bjorn3/rustc_codegen_cranelift.git master
git push -u my $branch
popd
;;
*)
echo "Unknown command '$1'"
echo "Usage: ./rustup.sh prepare|commit"

65
scripts/test_bootstrap.sh Executable file
View File

@ -0,0 +1,65 @@
#!/bin/bash
set -e
cd $(dirname "$0")/../
./build.sh
source build/config.sh
echo "[TEST] Bootstrap of rustc"
git clone https://github.com/rust-lang/rust.git || true
pushd rust
git fetch
git checkout -- .
git checkout $(rustc -V | cut -d' ' -f3 | tr -d '(')
git apply - <<EOF
diff --git a/.gitmodules b/.gitmodules
index 984113151de..c1e9d960d56 100644
--- a/.gitmodules
+++ b/.gitmodules
@@ -34,10 +34,6 @@
[submodule "src/doc/edition-guide"]
path = src/doc/edition-guide
url = https://github.com/rust-lang/edition-guide.git
-[submodule "src/llvm-project"]
- path = src/llvm-project
- url = https://github.com/rust-lang/llvm-project.git
- branch = rustc/11.0-2020-10-12
[submodule "src/doc/embedded-book"]
path = src/doc/embedded-book
url = https://github.com/rust-embedded/book.git
diff --git a/compiler/rustc_data_structures/Cargo.toml b/compiler/rustc_data_structures/Cargo.toml
index 23e689fcae7..5f077b765b6 100644
--- a/compiler/rustc_data_structures/Cargo.toml
+++ b/compiler/rustc_data_structures/Cargo.toml
@@ -32,7 +32,6 @@ tempfile = "3.0.5"
[dependencies.parking_lot]
version = "0.11"
-features = ["nightly"]
[target.'cfg(windows)'.dependencies]
winapi = { version = "0.3", features = ["fileapi", "psapi"] }
EOF
cat > config.toml <<EOF
[llvm]
ninja = false
[build]
rustc = "$(pwd)/../build/cg_clif"
cargo = "$(rustup which cargo)"
full-bootstrap = true
local-rebuild = true
[rust]
codegen-backends = ["cranelift"]
EOF
rm -r compiler/rustc_codegen_cranelift/{Cargo.*,src}
cp ../Cargo.* compiler/rustc_codegen_cranelift/
cp -r ../src compiler/rustc_codegen_cranelift/src
./x.py build --stage 1 library/std
popd

123
scripts/tests.sh Executable file
View File

@ -0,0 +1,123 @@
#!/bin/bash
set -e
source build/config.sh
export CG_CLIF_INCR_CACHE_DISABLED=1
MY_RUSTC=$RUSTC" "$RUSTFLAGS" -L crate=target/out --out-dir target/out -Cdebuginfo=2"
function no_sysroot_tests() {
echo "[BUILD] mini_core"
$MY_RUSTC example/mini_core.rs --crate-name mini_core --crate-type lib,dylib --target $TARGET_TRIPLE
echo "[BUILD] example"
$MY_RUSTC example/example.rs --crate-type lib --target $TARGET_TRIPLE
if [[ "$JIT_SUPPORTED" = "1" ]]; then
echo "[JIT] mini_core_hello_world"
CG_CLIF_JIT_ARGS="abc bcd" $MY_RUSTC --jit example/mini_core_hello_world.rs --cfg jit --target $HOST_TRIPLE
else
echo "[JIT] mini_core_hello_world (skipped)"
fi
echo "[AOT] mini_core_hello_world"
$MY_RUSTC example/mini_core_hello_world.rs --crate-name mini_core_hello_world --crate-type bin -g --target $TARGET_TRIPLE
$RUN_WRAPPER ./target/out/mini_core_hello_world abc bcd
# (echo "break set -n main"; echo "run"; sleep 1; echo "si -c 10"; sleep 1; echo "frame variable") | lldb -- ./target/out/mini_core_hello_world abc bcd
echo "[AOT] arbitrary_self_types_pointers_and_wrappers"
$MY_RUSTC example/arbitrary_self_types_pointers_and_wrappers.rs --crate-name arbitrary_self_types_pointers_and_wrappers --crate-type bin --target $TARGET_TRIPLE
$RUN_WRAPPER ./target/out/arbitrary_self_types_pointers_and_wrappers
}
function base_sysroot_tests() {
echo "[AOT] alloc_example"
$MY_RUSTC example/alloc_example.rs --crate-type bin --target $TARGET_TRIPLE
$RUN_WRAPPER ./target/out/alloc_example
if [[ "$JIT_SUPPORTED" = "1" ]]; then
echo "[JIT] std_example"
$MY_RUSTC --jit example/std_example.rs --target $HOST_TRIPLE
else
echo "[JIT] std_example (skipped)"
fi
echo "[AOT] dst_field_align"
# FIXME Re-add -Zmir-opt-level=2 once rust-lang/rust#67529 is fixed.
$MY_RUSTC example/dst-field-align.rs --crate-name dst_field_align --crate-type bin --target $TARGET_TRIPLE
$RUN_WRAPPER ./target/out/dst_field_align || (echo $?; false)
echo "[AOT] std_example"
$MY_RUSTC example/std_example.rs --crate-type bin --target $TARGET_TRIPLE
$RUN_WRAPPER ./target/out/std_example arg
echo "[AOT] subslice-patterns-const-eval"
$MY_RUSTC example/subslice-patterns-const-eval.rs --crate-type bin -Cpanic=abort --target $TARGET_TRIPLE
$RUN_WRAPPER ./target/out/subslice-patterns-const-eval
echo "[AOT] track-caller-attribute"
$MY_RUSTC example/track-caller-attribute.rs --crate-type bin -Cpanic=abort --target $TARGET_TRIPLE
$RUN_WRAPPER ./target/out/track-caller-attribute
echo "[AOT] mod_bench"
$MY_RUSTC example/mod_bench.rs --crate-type bin --target $TARGET_TRIPLE
$RUN_WRAPPER ./target/out/mod_bench
pushd rand
rm -r ./target || true
../build/cargo.sh test --workspace
popd
}
function extended_sysroot_tests() {
pushd simple-raytracer
if [[ "$HOST_TRIPLE" = "$TARGET_TRIPLE" ]]; then
echo "[BENCH COMPILE] ebobby/simple-raytracer"
hyperfine --runs ${RUN_RUNS:-10} --warmup 1 --prepare "cargo clean" \
"RUSTC=rustc RUSTFLAGS='' cargo build" \
"../build/cargo.sh 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
echo "[BENCH COMPILE] ebobby/simple-raytracer (skipped)"
echo "[COMPILE] ebobby/simple-raytracer"
../cargo.sh build
echo "[BENCH RUN] ebobby/simple-raytracer (skipped)"
fi
popd
pushd build_sysroot/sysroot_src/library/core/tests
echo "[TEST] libcore"
rm -r ./target || true
../../../../../build/cargo.sh test
popd
pushd regex
echo "[TEST] rust-lang/regex example shootout-regex-dna"
../build/cargo.sh clean
# Make sure `[codegen mono items] start` doesn't poison the diff
../build/cargo.sh build --example shootout-regex-dna
cat examples/regexdna-input.txt | ../build/cargo.sh run --example shootout-regex-dna | grep -v "Spawned thread" > res.txt
diff -u res.txt examples/regexdna-output.txt
echo "[TEST] rust-lang/regex tests"
../build/cargo.sh test --tests -- --exclude-should-panic --test-threads 1 -Zunstable-options -q
popd
}
case "$1" in
"no_sysroot")
no_sysroot_tests
;;
"base_sysroot")
base_sysroot_tests
;;
"extended_sysroot")
extended_sysroot_tests
;;
*)
echo "unknown test suite"
;;
esac

View File

@ -11,9 +11,9 @@ use crate::abi::pass_mode::*;
use crate::prelude::*;
pub(super) fn add_args_header_comment(fx: &mut FunctionCx<'_, '_, impl Module>) {
fx.add_global_comment(format!(
"kind loc.idx param pass mode ty"
));
fx.add_global_comment(
"kind loc.idx param pass mode ty".to_string(),
);
}
pub(super) fn add_arg_comment<'tcx>(
@ -56,9 +56,9 @@ pub(super) fn add_arg_comment<'tcx>(
pub(super) fn add_locals_header_comment(fx: &mut FunctionCx<'_, '_, impl Module>) {
fx.add_global_comment(String::new());
fx.add_global_comment(format!(
"kind local ty size align (abi,pref)"
));
fx.add_global_comment(
"kind local ty size align (abi,pref)".to_string(),
);
}
pub(super) fn add_local_place_comments<'tcx>(

View File

@ -300,7 +300,7 @@ impl<'tcx, M: Module> FunctionCx<'_, 'tcx, M> {
return_ty: Ty<'tcx>,
) -> CValue<'tcx> {
let (input_tys, args): (Vec<_>, Vec<_>) = args
.into_iter()
.iter()
.map(|arg| {
(
self.clif_type(arg.layout().ty).unwrap(),
@ -421,34 +421,31 @@ pub(crate) fn codegen_fn_prelude<'tcx>(
// While this is normally an optimization to prevent an unnecessary copy when an argument is
// not mutated by the current function, this is necessary to support unsized arguments.
match arg_kind {
ArgKind::Normal(Some(val)) => {
if let Some((addr, meta)) = val.try_to_ptr() {
let local_decl = &fx.mir.local_decls[local];
// v this ! is important
let internally_mutable = !val.layout().ty.is_freeze(
fx.tcx.at(local_decl.source_info.span),
ParamEnv::reveal_all(),
);
if local_decl.mutability == mir::Mutability::Not && !internally_mutable {
// We wont mutate this argument, so it is fine to borrow the backing storage
// of this argument, to prevent a copy.
if let ArgKind::Normal(Some(val)) = arg_kind {
if let Some((addr, meta)) = val.try_to_ptr() {
let local_decl = &fx.mir.local_decls[local];
// v this ! is important
let internally_mutable = !val.layout().ty.is_freeze(
fx.tcx.at(local_decl.source_info.span),
ParamEnv::reveal_all(),
);
if local_decl.mutability == mir::Mutability::Not && !internally_mutable {
// We wont mutate this argument, so it is fine to borrow the backing storage
// of this argument, to prevent a copy.
let place = if let Some(meta) = meta {
CPlace::for_ptr_with_extra(addr, meta, val.layout())
} else {
CPlace::for_ptr(addr, val.layout())
};
let place = if let Some(meta) = meta {
CPlace::for_ptr_with_extra(addr, meta, val.layout())
} else {
CPlace::for_ptr(addr, val.layout())
};
#[cfg(debug_assertions)]
self::comments::add_local_place_comments(fx, place, local);
#[cfg(debug_assertions)]
self::comments::add_local_place_comments(fx, place, local);
assert_eq!(fx.local_map.push(place), local);
continue;
}
assert_eq!(fx.local_map.push(place), local);
continue;
}
}
_ => {}
}
let place = make_local_place(fx, local, layout, is_ssa);
@ -500,7 +497,7 @@ pub(crate) fn codegen_terminator_call<'tcx>(
.tcx
.normalize_erasing_late_bound_regions(ParamEnv::reveal_all(), &fn_ty.fn_sig(fx.tcx));
let destination = destination.map(|(place, bb)| (trans_place(fx, place), bb));
let destination = destination.map(|(place, bb)| (codegen_place(fx, place), bb));
// Handle special calls like instrinsics and empty drop glue.
let instance = if let ty::FnDef(def_id, substs) = *fn_ty.kind() {
@ -553,8 +550,8 @@ pub(crate) fn codegen_terminator_call<'tcx>(
// Unpack arguments tuple for closures
let args = if fn_sig.abi == Abi::RustCall {
assert_eq!(args.len(), 2, "rust-call abi requires two arguments");
let self_arg = trans_operand(fx, &args[0]);
let pack_arg = trans_operand(fx, &args[1]);
let self_arg = codegen_operand(fx, &args[0]);
let pack_arg = codegen_operand(fx, &args[1]);
let tupled_arguments = match pack_arg.layout().ty.kind() {
ty::Tuple(ref tupled_arguments) => tupled_arguments,
@ -568,8 +565,8 @@ pub(crate) fn codegen_terminator_call<'tcx>(
}
args
} else {
args.into_iter()
.map(|arg| trans_operand(fx, arg))
args.iter()
.map(|arg| codegen_operand(fx, arg))
.collect::<Vec<_>>()
};
@ -613,7 +610,7 @@ pub(crate) fn codegen_terminator_call<'tcx>(
let nop_inst = fx.bcx.ins().nop();
fx.add_comment(nop_inst, "indirect call");
}
let func = trans_operand(fx, func).load_scalar(fx);
let func = codegen_operand(fx, func).load_scalar(fx);
(
Some(func),
args.get(0)

View File

@ -123,7 +123,7 @@ fn codegen_inner(
.unwrap();
let mut ctx = Context::new();
ctx.func = Function::with_name_signature(ExternalName::user(0, 0), sig.clone());
ctx.func = Function::with_name_signature(ExternalName::user(0, 0), sig);
{
let mut func_ctx = FunctionBuilderContext::new();
let mut bcx = FunctionBuilder::new(&mut ctx.func, &mut func_ctx);
@ -131,7 +131,7 @@ fn codegen_inner(
let block = bcx.create_block();
bcx.switch_to_block(block);
let args = (&[usize_ty, usize_ty])
.into_iter()
.iter()
.map(|&ty| bcx.append_block_param(block, ty))
.collect::<Vec<Value>>();

View File

@ -132,7 +132,7 @@ impl<'a> ArchiveBuilder<'a> for ArArchiveBuilder<'a> {
}
// ok, don't skip this
return false;
false
})
}

View File

@ -7,7 +7,7 @@ use crate::prelude::*;
#[cfg(all(feature = "jit", unix))]
#[no_mangle]
pub static mut __cg_clif_global_atomic_mutex: libc::pthread_mutex_t =
static mut __cg_clif_global_atomic_mutex: libc::pthread_mutex_t =
libc::PTHREAD_MUTEX_INITIALIZER;
pub(crate) fn init_global_lock(

View File

@ -73,7 +73,7 @@ impl WriteDebugInfo for ObjectProduct {
// FIXME use SHT_X86_64_UNWIND for .eh_frame
let section_id = self.object.add_section(
segment,
name.clone(),
name,
if id == SectionId::EhFrame {
SectionKind::ReadOnlyData
} else {
@ -198,9 +198,9 @@ pub(crate) fn make_module(sess: &Session, name: String) -> ObjectModule {
cranelift_module::default_libcall_names(),
)
.unwrap();
if std::env::var("CG_CLIF_FUNCTION_SECTIONS").is_ok() {
builder.per_function_section(true);
}
let module = ObjectModule::new(builder);
module
// Unlike cg_llvm, cg_clif defaults to disabling -Zfunction-sections. For cg_llvm binary size
// is important, while cg_clif cares more about compilation times. Enabling -Zfunction-sections
// can easily double the amount of time necessary to perform linking.
builder.per_function_section(sess.opts.debugging_opts.function_sections.unwrap_or(false));
ObjectModule::new(builder)
}

View File

@ -5,7 +5,7 @@ use rustc_middle::ty::adjustment::PointerCast;
use crate::prelude::*;
pub(crate) fn trans_fn<'tcx>(
pub(crate) fn codegen_fn<'tcx>(
cx: &mut crate::CodegenCx<'tcx, impl Module>,
instance: Instance<'tcx>,
linkage: Linkage,
@ -202,7 +202,7 @@ fn codegen_fn_content(fx: &mut FunctionCx<'_, '_, impl Module>) {
fx.bcx.ins().nop();
for stmt in &bb_data.statements {
fx.set_debug_loc(stmt.source_info);
trans_stmt(fx, block, stmt);
codegen_stmt(fx, block, stmt);
}
#[cfg(debug_assertions)]
@ -258,7 +258,7 @@ fn codegen_fn_content(fx: &mut FunctionCx<'_, '_, impl Module>) {
continue;
}
}
let cond = trans_operand(fx, cond).load_scalar(fx);
let cond = codegen_operand(fx, cond).load_scalar(fx);
let target = fx.get_block(*target);
let failure = fx.bcx.create_block();
@ -276,8 +276,8 @@ fn codegen_fn_content(fx: &mut FunctionCx<'_, '_, impl Module>) {
match msg {
AssertKind::BoundsCheck { ref len, ref index } => {
let len = trans_operand(fx, len).load_scalar(fx);
let index = trans_operand(fx, index).load_scalar(fx);
let len = codegen_operand(fx, len).load_scalar(fx);
let index = codegen_operand(fx, index).load_scalar(fx);
let location = fx
.get_caller_location(bb_data.terminator().source_info.span)
.load_scalar(fx);
@ -301,7 +301,7 @@ fn codegen_fn_content(fx: &mut FunctionCx<'_, '_, impl Module>) {
switch_ty,
targets,
} => {
let discr = trans_operand(fx, discr).load_scalar(fx);
let discr = codegen_operand(fx, discr).load_scalar(fx);
if switch_ty.kind() == fx.tcx.types.bool.kind() {
assert_eq!(targets.iter().count(), 1);
@ -396,14 +396,14 @@ fn codegen_fn_content(fx: &mut FunctionCx<'_, '_, impl Module>) {
| TerminatorKind::FalseUnwind { .. }
| TerminatorKind::DropAndReplace { .. }
| TerminatorKind::GeneratorDrop => {
bug!("shouldn't exist at trans {:?}", bb_data.terminator());
bug!("shouldn't exist at codegen {:?}", bb_data.terminator());
}
TerminatorKind::Drop {
place,
target,
unwind: _,
} => {
let drop_place = trans_place(fx, *place);
let drop_place = codegen_place(fx, *place);
crate::abi::codegen_drop(fx, bb_data.terminator().source_info.span, drop_place);
let target_block = fx.get_block(*target);
@ -416,7 +416,7 @@ fn codegen_fn_content(fx: &mut FunctionCx<'_, '_, impl Module>) {
fx.bcx.finalize();
}
fn trans_stmt<'tcx>(
fn codegen_stmt<'tcx>(
fx: &mut FunctionCx<'_, 'tcx, impl Module>,
#[allow(unused_variables)] cur_block: Block,
stmt: &Statement<'tcx>,
@ -439,19 +439,19 @@ fn trans_stmt<'tcx>(
place,
variant_index,
} => {
let place = trans_place(fx, **place);
let place = codegen_place(fx, **place);
crate::discriminant::codegen_set_discriminant(fx, place, *variant_index);
}
StatementKind::Assign(to_place_and_rval) => {
let lval = trans_place(fx, to_place_and_rval.0);
let lval = codegen_place(fx, to_place_and_rval.0);
let dest_layout = lval.layout();
match &to_place_and_rval.1 {
Rvalue::Use(operand) => {
let val = trans_operand(fx, operand);
let val = codegen_operand(fx, operand);
lval.write_cvalue(fx, val);
}
Rvalue::Ref(_, _, place) | Rvalue::AddressOf(_, place) => {
let place = trans_place(fx, *place);
let place = codegen_place(fx, *place);
let ref_ = place.place_ref(fx, lval.layout());
lval.write_cvalue(fx, ref_);
}
@ -460,29 +460,29 @@ fn trans_stmt<'tcx>(
lval.write_cvalue(fx, val);
}
Rvalue::BinaryOp(bin_op, lhs, rhs) => {
let lhs = trans_operand(fx, lhs);
let rhs = trans_operand(fx, rhs);
let lhs = codegen_operand(fx, lhs);
let rhs = codegen_operand(fx, rhs);
let res = crate::num::codegen_binop(fx, *bin_op, lhs, rhs);
lval.write_cvalue(fx, res);
}
Rvalue::CheckedBinaryOp(bin_op, lhs, rhs) => {
let lhs = trans_operand(fx, lhs);
let rhs = trans_operand(fx, rhs);
let lhs = codegen_operand(fx, lhs);
let rhs = codegen_operand(fx, rhs);
let res = if !fx.tcx.sess.overflow_checks() {
let val =
crate::num::trans_int_binop(fx, *bin_op, lhs, rhs).load_scalar(fx);
crate::num::codegen_int_binop(fx, *bin_op, lhs, rhs).load_scalar(fx);
let is_overflow = fx.bcx.ins().iconst(types::I8, 0);
CValue::by_val_pair(val, is_overflow, lval.layout())
} else {
crate::num::trans_checked_int_binop(fx, *bin_op, lhs, rhs)
crate::num::codegen_checked_int_binop(fx, *bin_op, lhs, rhs)
};
lval.write_cvalue(fx, res);
}
Rvalue::UnaryOp(un_op, operand) => {
let operand = trans_operand(fx, operand);
let operand = codegen_operand(fx, operand);
let layout = operand.layout();
let val = operand.load_scalar(fx);
let res = match un_op {
@ -500,7 +500,7 @@ fn trans_stmt<'tcx>(
ty::Int(IntTy::I128) => {
// FIXME remove this case once ineg.i128 works
let zero = CValue::const_val(fx, layout, 0);
crate::num::trans_int_binop(fx, BinOp::Sub, zero, operand)
crate::num::codegen_int_binop(fx, BinOp::Sub, zero, operand)
}
ty::Int(_) => CValue::by_val(fx.bcx.ins().ineg(val), layout),
ty::Float(_) => CValue::by_val(fx.bcx.ins().fneg(val), layout),
@ -534,11 +534,11 @@ fn trans_stmt<'tcx>(
| Rvalue::Cast(CastKind::Pointer(PointerCast::MutToConstPointer), operand, to_ty)
| Rvalue::Cast(CastKind::Pointer(PointerCast::ArrayToPointer), operand, to_ty) => {
let to_layout = fx.layout_of(fx.monomorphize(to_ty));
let operand = trans_operand(fx, operand);
let operand = codegen_operand(fx, operand);
lval.write_cvalue(fx, operand.cast_pointer_to(to_layout));
}
Rvalue::Cast(CastKind::Misc, operand, to_ty) => {
let operand = trans_operand(fx, operand);
let operand = codegen_operand(fx, operand);
let from_ty = operand.layout().ty;
let to_ty = fx.monomorphize(to_ty);
@ -639,7 +639,7 @@ fn trans_stmt<'tcx>(
operand,
_to_ty,
) => {
let operand = trans_operand(fx, operand);
let operand = codegen_operand(fx, operand);
match *operand.layout().ty.kind() {
ty::Closure(def_id, substs) => {
let instance = Instance::resolve_closure(
@ -657,18 +657,18 @@ fn trans_stmt<'tcx>(
}
}
Rvalue::Cast(CastKind::Pointer(PointerCast::Unsize), operand, _to_ty) => {
let operand = trans_operand(fx, operand);
let operand = codegen_operand(fx, operand);
operand.unsize_value(fx, lval);
}
Rvalue::Discriminant(place) => {
let place = trans_place(fx, *place);
let place = codegen_place(fx, *place);
let value = place.to_cvalue(fx);
let discr =
crate::discriminant::codegen_get_discriminant(fx, value, dest_layout);
lval.write_cvalue(fx, discr);
}
Rvalue::Repeat(operand, times) => {
let operand = trans_operand(fx, operand);
let operand = codegen_operand(fx, operand);
let times = fx
.monomorphize(times)
.eval(fx.tcx, ParamEnv::reveal_all())
@ -706,7 +706,7 @@ fn trans_stmt<'tcx>(
}
}
Rvalue::Len(place) => {
let place = trans_place(fx, *place);
let place = codegen_place(fx, *place);
let usize_layout = fx.layout_of(fx.tcx.types.usize);
let len = codegen_array_len(fx, place);
lval.write_cvalue(fx, CValue::by_val(len, usize_layout));
@ -753,14 +753,14 @@ fn trans_stmt<'tcx>(
}
Rvalue::Aggregate(kind, operands) => match **kind {
AggregateKind::Array(_ty) => {
for (i, operand) in operands.into_iter().enumerate() {
let operand = trans_operand(fx, operand);
for (i, operand) in operands.iter().enumerate() {
let operand = codegen_operand(fx, operand);
let index = fx.bcx.ins().iconst(fx.pointer_type, i as i64);
let to = lval.place_index(fx, index);
to.write_cvalue(fx, operand);
}
}
_ => unreachable!("shouldn't exist at trans {:?}", to_place_and_rval.1),
_ => unreachable!("shouldn't exist at codegen {:?}", to_place_and_rval.1),
},
}
}
@ -813,20 +813,20 @@ fn trans_stmt<'tcx>(
assert!(!alignstack);
assert_eq!(inputs.len(), 2);
let leaf = trans_operand(fx, &inputs[0].1).load_scalar(fx); // %eax
let subleaf = trans_operand(fx, &inputs[1].1).load_scalar(fx); // %ecx
let leaf = codegen_operand(fx, &inputs[0].1).load_scalar(fx); // %eax
let subleaf = codegen_operand(fx, &inputs[1].1).load_scalar(fx); // %ecx
let (eax, ebx, ecx, edx) =
crate::intrinsics::codegen_cpuid_call(fx, leaf, subleaf);
assert_eq!(outputs.len(), 4);
trans_place(fx, outputs[0])
codegen_place(fx, outputs[0])
.write_cvalue(fx, CValue::by_val(eax, fx.layout_of(fx.tcx.types.u32)));
trans_place(fx, outputs[1])
codegen_place(fx, outputs[1])
.write_cvalue(fx, CValue::by_val(ebx, fx.layout_of(fx.tcx.types.u32)));
trans_place(fx, outputs[2])
codegen_place(fx, outputs[2])
.write_cvalue(fx, CValue::by_val(ecx, fx.layout_of(fx.tcx.types.u32)));
trans_place(fx, outputs[3])
codegen_place(fx, outputs[3])
.write_cvalue(fx, CValue::by_val(edx, fx.layout_of(fx.tcx.types.u32)));
}
"xgetbv" => {
@ -892,7 +892,7 @@ fn codegen_array_len<'tcx>(
}
}
pub(crate) fn trans_place<'tcx>(
pub(crate) fn codegen_place<'tcx>(
fx: &mut FunctionCx<'_, 'tcx, impl Module>,
place: Place<'tcx>,
) -> CPlace<'tcx> {
@ -938,7 +938,7 @@ pub(crate) fn trans_place<'tcx>(
let ptr = cplace.to_ptr();
cplace = CPlace::for_ptr(
ptr.offset_i64(fx, elem_layout.size.bytes() as i64 * (from as i64)),
fx.layout_of(fx.tcx.mk_array(elem_ty, u64::from(to) - u64::from(from))),
fx.layout_of(fx.tcx.mk_array(elem_ty, to - from)),
);
}
ty::Slice(elem_ty) => {
@ -964,16 +964,16 @@ pub(crate) fn trans_place<'tcx>(
cplace
}
pub(crate) fn trans_operand<'tcx>(
pub(crate) fn codegen_operand<'tcx>(
fx: &mut FunctionCx<'_, 'tcx, impl Module>,
operand: &Operand<'tcx>,
) -> CValue<'tcx> {
match operand {
Operand::Move(place) | Operand::Copy(place) => {
let cplace = trans_place(fx, *place);
let cplace = codegen_place(fx, *place);
cplace.to_cvalue(fx)
}
Operand::Constant(const_) => crate::constant::trans_constant(fx, const_),
Operand::Constant(const_) => crate::constant::codegen_constant(fx, const_),
}
}

View File

@ -24,22 +24,16 @@ impl rustc_driver::Callbacks for CraneliftPassesCallbacks {
self.time_passes = config.opts.prints.is_empty()
&& (config.opts.debugging_opts.time_passes || config.opts.debugging_opts.time);
// FIXME workaround for an ICE
config.opts.debugging_opts.trim_diagnostic_paths = false;
config.opts.cg.panic = Some(PanicStrategy::Abort);
config.opts.debugging_opts.panic_abort_tests = true;
config.opts.maybe_sysroot = Some(
std::env::current_exe()
.unwrap()
.parent()
.unwrap()
.parent()
.unwrap()
.parent()
.unwrap()
.join("build_sysroot")
.join("sysroot"),
config.opts.maybe_sysroot.clone().unwrap_or(
std::env::current_exe()
.unwrap()
.parent()
.unwrap()
.join("sysroot"),
),
);
}
}

View File

@ -44,9 +44,6 @@ impl rustc_driver::Callbacks for CraneliftPassesCallbacks {
return;
}
// FIXME workaround for an ICE
config.opts.debugging_opts.trim_diagnostic_paths = false;
config.opts.cg.panic = Some(PanicStrategy::Abort);
config.opts.debugging_opts.panic_abort_tests = true;
config.opts.maybe_sysroot = Some(

View File

@ -181,12 +181,10 @@ pub(crate) fn clif_int_or_float_cast(
fx.bcx.ins().select(has_overflow, max_val, val)
};
fx.bcx.ins().ireduce(to_ty, val)
} else if to_signed {
fx.bcx.ins().fcvt_to_sint_sat(to_ty, from)
} else {
if to_signed {
fx.bcx.ins().fcvt_to_sint_sat(to_ty, from)
} else {
fx.bcx.ins().fcvt_to_uint_sat(to_ty, from)
}
fx.bcx.ins().fcvt_to_uint_sat(to_ty, from)
}
} else if from_ty.is_float() && to_ty.is_float() {
// float -> float

View File

@ -21,9 +21,9 @@ pub(crate) fn maybe_codegen<'tcx>(
match bin_op {
BinOp::BitAnd | BinOp::BitOr | BinOp::BitXor => {
assert!(!checked);
return None;
None
}
BinOp::Add | BinOp::Sub if !checked => return None,
BinOp::Add | BinOp::Sub if !checked => None,
BinOp::Add => {
let out_ty = fx.tcx.mk_tup([lhs.layout().ty, fx.tcx.types.bool].iter());
return Some(if is_signed {
@ -57,7 +57,7 @@ pub(crate) fn maybe_codegen<'tcx>(
};
fx.easy_call("__multi3", &[lhs, rhs], val_ty)
};
return Some(res);
Some(res)
}
BinOp::Div => {
assert!(!checked);
@ -77,7 +77,7 @@ pub(crate) fn maybe_codegen<'tcx>(
}
BinOp::Lt | BinOp::Le | BinOp::Eq | BinOp::Ge | BinOp::Gt | BinOp::Ne => {
assert!(!checked);
return None;
None
}
BinOp::Shl | BinOp::Shr => {
let is_overflow = if checked {

View File

@ -406,7 +406,7 @@ impl<'tcx, M: Module> FunctionCx<'_, 'tcx, M> {
caller.line as u32,
caller.col_display as u32 + 1,
));
crate::constant::trans_const_value(self, const_loc, self.tcx.caller_location_ty())
crate::constant::codegen_const_value(self, const_loc, self.tcx.caller_location_ty())
}
pub(crate) fn triple(&self) -> &target_lexicon::Triple {

View File

@ -106,7 +106,7 @@ fn codegen_static_ref<'tcx>(
CPlace::for_ptr(crate::pointer::Pointer::new(global_ptr), layout)
}
pub(crate) fn trans_constant<'tcx>(
pub(crate) fn codegen_constant<'tcx>(
fx: &mut FunctionCx<'_, 'tcx, impl Module>,
constant: &Constant<'tcx>,
) -> CValue<'tcx> {
@ -151,10 +151,10 @@ pub(crate) fn trans_constant<'tcx>(
| ConstKind::Error(_) => unreachable!("{:?}", const_),
};
trans_const_value(fx, const_val, const_.ty)
codegen_const_value(fx, const_val, const_.ty)
}
pub(crate) fn trans_const_value<'tcx>(
pub(crate) fn codegen_const_value<'tcx>(
fx: &mut FunctionCx<'_, 'tcx, impl Module>,
const_val: ConstValue<'tcx>,
ty: Ty<'tcx>,
@ -164,7 +164,7 @@ pub(crate) fn trans_const_value<'tcx>(
if layout.is_zst() {
return CValue::by_ref(
crate::Pointer::const_addr(fx, i64::try_from(layout.align.pref.bytes()).unwrap()),
crate::Pointer::dangling(layout.align.pref),
layout,
);
}
@ -188,7 +188,7 @@ pub(crate) fn trans_const_value<'tcx>(
match x {
Scalar::Raw { data, size } => {
assert_eq!(u64::from(size), layout.size.bytes());
return CValue::const_val(fx, layout, data);
CValue::const_val(fx, layout, data)
}
Scalar::Ptr(ptr) => {
let alloc_kind = fx.tcx.get_global_alloc(ptr.alloc_id);
@ -232,7 +232,7 @@ pub(crate) fn trans_const_value<'tcx>(
} else {
base_addr
};
return CValue::by_val(val, layout);
CValue::by_val(val, layout)
}
}
}
@ -276,7 +276,7 @@ fn data_id_for_alloc_id(
) -> DataId {
module
.declare_data(
&format!("__alloc_{:x}", alloc_id.0),
&format!(".L__alloc_{:x}", alloc_id.0),
Linkage::Local,
mutability == rustc_hir::Mutability::Mut,
false,
@ -293,14 +293,12 @@ fn data_id_for_static(
let rlinkage = tcx.codegen_fn_attrs(def_id).linkage;
let linkage = if definition {
crate::linkage::get_static_linkage(tcx, def_id)
} else if rlinkage == Some(rustc_middle::mir::mono::Linkage::ExternalWeak)
|| rlinkage == Some(rustc_middle::mir::mono::Linkage::WeakAny)
{
Linkage::Preemptible
} else {
if rlinkage == Some(rustc_middle::mir::mono::Linkage::ExternalWeak)
|| rlinkage == Some(rustc_middle::mir::mono::Linkage::WeakAny)
{
Linkage::Preemptible
} else {
Linkage::Import
}
Linkage::Import
};
let instance = Instance::mono(tcx, def_id).polymorphize(tcx);

View File

@ -195,9 +195,7 @@ impl Writer for WriterRelocate {
});
self.write_udata(0, size)
}
_ => {
return Err(gimli::write::Error::UnsupportedPointerEncoding(eh_pe));
}
_ => Err(gimli::write::Error::UnsupportedPointerEncoding(eh_pe)),
},
}
}

View File

@ -49,7 +49,7 @@ fn osstr_as_utf8_bytes(path: &OsStr) -> &[u8] {
pub(crate) const MD5_LEN: usize = 16;
pub fn make_file_info(hash: SourceFileHash) -> Option<FileInfo> {
pub(crate) fn make_file_info(hash: SourceFileHash) -> Option<FileInfo> {
if hash.kind == SourceFileHashAlgorithm::Md5 {
let mut buf = [0u8; MD5_LEN];
buf.copy_from_slice(hash.hash_bytes());
@ -190,7 +190,7 @@ impl<'tcx> DebugContext<'tcx> {
if current_file_changed {
let file_id = line_program_add_file(line_program, line_strings, &file);
line_program.row().file = file_id;
last_file = Some(file.clone());
last_file = Some(file);
}
line_program.row().line = line;

View File

@ -55,6 +55,7 @@ impl<'tcx> UnwindContext<'tcx> {
UnwindInfo::WindowsX64(_) => {
// FIXME implement this
}
unwind_info => unimplemented!("{:?}", unwind_info),
}
}

View File

@ -94,7 +94,7 @@ pub(super) fn run_jit(tcx: TyCtxt<'_>) -> ! {
let args = ::std::env::var("CG_CLIF_JIT_ARGS").unwrap_or_else(|_| String::new());
let args = std::iter::once(&*tcx.crate_name(LOCAL_CRATE).as_str().to_string())
.chain(args.split(" "))
.chain(args.split(' '))
.map(|arg| CString::new(arg).unwrap())
.collect::<Vec<_>>();
let mut argv = args.iter().map(|arg| arg.as_ptr()).collect::<Vec<_>>();
@ -151,7 +151,7 @@ fn load_imported_symbols_for_jit(tcx: TyCtxt<'_>) -> Vec<(String, *const u8)> {
}
let dlsym_name = if cfg!(target_os = "macos") {
// On macOS `dlsym` expects the name without leading `_`.
assert!(name.starts_with("_"), "{:?}", name);
assert!(name.starts_with('_'), "{:?}", name);
&name[1..]
} else {
&name

View File

@ -64,11 +64,11 @@ fn codegen_mono_items<'tcx>(
for (mono_item, (linkage, visibility)) in mono_items {
let linkage = crate::linkage::get_clif_linkage(mono_item, linkage, visibility);
trans_mono_item(cx, mono_item, linkage);
codegen_mono_item(cx, mono_item, linkage);
}
}
fn trans_mono_item<'tcx, M: Module>(
fn codegen_mono_item<'tcx, M: Module>(
cx: &mut crate::CodegenCx<'tcx, M>,
mono_item: MonoItem<'tcx>,
linkage: Linkage,
@ -80,7 +80,7 @@ fn trans_mono_item<'tcx, M: Module>(
crate::PrintOnPanic(|| format!("{:?} {}", inst, tcx.symbol_name(inst).name));
debug_assert!(!inst.substs.needs_infer());
tcx.sess
.time("codegen fn", || crate::base::trans_fn(cx, inst, linkage));
.time("codegen fn", || crate::base::codegen_fn(cx, inst, linkage));
}
MonoItem::Static(def_id) => {
crate::constant::codegen_static(&mut cx.constants_cx, def_id);

View File

@ -50,7 +50,7 @@ pub(crate) fn codegen_inline_asm<'tcx>(
inputs.push((
reg,
new_slot(reg.reg_class()),
crate::base::trans_operand(fx, value).load_scalar(fx),
crate::base::codegen_operand(fx, value).load_scalar(fx),
));
}
InlineAsmOperand::Out {
@ -64,7 +64,7 @@ pub(crate) fn codegen_inline_asm<'tcx>(
outputs.push((
reg,
new_slot(reg.reg_class()),
crate::base::trans_place(fx, place),
crate::base::codegen_place(fx, place),
));
}
}
@ -79,13 +79,13 @@ pub(crate) fn codegen_inline_asm<'tcx>(
inputs.push((
reg,
new_slot(reg.reg_class()),
crate::base::trans_operand(fx, in_value).load_scalar(fx),
crate::base::codegen_operand(fx, in_value).load_scalar(fx),
));
if let Some(out_place) = out_place {
outputs.push((
reg,
new_slot(reg.reg_class()),
crate::base::trans_place(fx, out_place),
crate::base::codegen_place(fx, out_place),
));
}
}

View File

@ -53,7 +53,7 @@ pub(crate) fn codegen_llvm_intrinsic_call<'tcx>(
};
llvm.x86.sse2.cmp.ps | llvm.x86.sse2.cmp.pd, (c x, c y, o kind) {
let kind_const = crate::constant::mir_operand_get_const_val(fx, kind).expect("llvm.x86.sse2.cmp.* kind not const");
let flt_cc = match kind_const.val.try_to_bits(Size::from_bytes(1)).expect(&format!("kind not scalar: {:?}", kind_const)) {
let flt_cc = match kind_const.val.try_to_bits(Size::from_bytes(1)).unwrap_or_else(|| panic!("kind not scalar: {:?}", kind_const)) {
0 => FloatCC::Equal,
1 => FloatCC::LessThan,
2 => FloatCC::LessThanOrEqual,
@ -84,7 +84,7 @@ pub(crate) fn codegen_llvm_intrinsic_call<'tcx>(
llvm.x86.sse2.psrli.d, (c a, o imm8) {
let imm8 = crate::constant::mir_operand_get_const_val(fx, imm8).expect("llvm.x86.sse2.psrli.d imm8 not const");
simd_for_each_lane(fx, a, ret, |fx, _lane_layout, res_lane_layout, lane| {
let res_lane = match imm8.val.try_to_bits(Size::from_bytes(4)).expect(&format!("imm8 not scalar: {:?}", imm8)) {
let res_lane = match imm8.val.try_to_bits(Size::from_bytes(4)).unwrap_or_else(|| panic!("imm8 not scalar: {:?}", imm8)) {
imm8 if imm8 < 32 => fx.bcx.ins().ushr_imm(lane, i64::from(imm8 as u8)),
_ => fx.bcx.ins().iconst(types::I32, 0),
};
@ -94,7 +94,7 @@ pub(crate) fn codegen_llvm_intrinsic_call<'tcx>(
llvm.x86.sse2.pslli.d, (c a, o imm8) {
let imm8 = crate::constant::mir_operand_get_const_val(fx, imm8).expect("llvm.x86.sse2.psrli.d imm8 not const");
simd_for_each_lane(fx, a, ret, |fx, _lane_layout, res_lane_layout, lane| {
let res_lane = match imm8.val.try_to_bits(Size::from_bytes(4)).expect(&format!("imm8 not scalar: {:?}", imm8)) {
let res_lane = match imm8.val.try_to_bits(Size::from_bytes(4)).unwrap_or_else(|| panic!("imm8 not scalar: {:?}", imm8)) {
imm8 if imm8 < 32 => fx.bcx.ins().ishl_imm(lane, i64::from(imm8 as u8)),
_ => fx.bcx.ins().iconst(types::I32, 0),
};

View File

@ -9,6 +9,7 @@ pub(crate) use cpuid::codegen_cpuid_call;
pub(crate) use llvm::codegen_llvm_intrinsic_call;
use crate::prelude::*;
use rustc_middle::ty::print::with_no_trimmed_paths;
macro intrinsic_pat {
(_) => {
@ -30,10 +31,10 @@ macro intrinsic_arg {
$arg
},
(c $fx:expr, $arg:ident) => {
trans_operand($fx, $arg)
codegen_operand($fx, $arg)
},
(v $fx:expr, $arg:ident) => {
trans_operand($fx, $arg).load_scalar($fx)
codegen_operand($fx, $arg).load_scalar($fx)
}
}
@ -89,7 +90,7 @@ macro call_intrinsic_match {
assert!($substs.is_noop());
if let [$(ref $arg),*] = *$args {
let ($($arg,)*) = (
$(trans_operand($fx, $arg),)*
$(codegen_operand($fx, $arg),)*
);
let res = $fx.easy_call(stringify!($func), &[$($arg),*], $fx.tcx.types.$ty);
$ret.write_cvalue($fx, res);
@ -576,7 +577,7 @@ pub(crate) fn codegen_intrinsic_call<'tcx>(
"unchecked_shr" => BinOp::Shr,
_ => unreachable!("intrinsic {}", intrinsic),
};
let res = crate::num::trans_int_binop(fx, bin_op, x, y);
let res = crate::num::codegen_int_binop(fx, bin_op, x, y);
ret.write_cvalue(fx, res);
};
_ if intrinsic.ends_with("_with_overflow"), (c x, c y) {
@ -588,7 +589,7 @@ pub(crate) fn codegen_intrinsic_call<'tcx>(
_ => unreachable!("intrinsic {}", intrinsic),
};
let res = crate::num::trans_checked_int_binop(
let res = crate::num::codegen_checked_int_binop(
fx,
bin_op,
x,
@ -604,7 +605,7 @@ pub(crate) fn codegen_intrinsic_call<'tcx>(
"wrapping_mul" => BinOp::Mul,
_ => unreachable!("intrinsic {}", intrinsic),
};
let res = crate::num::trans_int_binop(
let res = crate::num::codegen_int_binop(
fx,
bin_op,
x,
@ -622,7 +623,7 @@ pub(crate) fn codegen_intrinsic_call<'tcx>(
let signed = type_sign(T);
let checked_res = crate::num::trans_checked_int_binop(
let checked_res = crate::num::codegen_checked_int_binop(
fx,
bin_op,
lhs,
@ -819,29 +820,29 @@ pub(crate) fn codegen_intrinsic_call<'tcx>(
assert_inhabited | assert_zero_valid | assert_uninit_valid, <T> () {
let layout = fx.layout_of(T);
if layout.abi.is_uninhabited() {
crate::base::codegen_panic(
with_no_trimmed_paths(|| crate::base::codegen_panic(
fx,
&format!("attempted to instantiate uninhabited type `{}`", T),
span,
);
));
return;
}
if intrinsic == "assert_zero_valid" && !layout.might_permit_raw_init(fx, /*zero:*/ true).unwrap() {
crate::base::codegen_panic(
with_no_trimmed_paths(|| crate::base::codegen_panic(
fx,
&format!("attempted to zero-initialize type `{}`, which is invalid", T),
span,
);
));
return;
}
if intrinsic == "assert_uninit_valid" && !layout.might_permit_raw_init(fx, /*zero:*/ false).unwrap() {
crate::base::codegen_panic(
with_no_trimmed_paths(|| crate::base::codegen_panic(
fx,
&format!("attempted to leave type `{}` uninitialized, which is invalid", T),
span,
);
));
return;
}
};
@ -866,7 +867,7 @@ pub(crate) fn codegen_intrinsic_call<'tcx>(
size_of | pref_align_of | min_align_of | needs_drop | type_id | type_name | variant_count, () {
let const_val =
fx.tcx.const_eval_instance(ParamEnv::reveal_all(), instance, None).unwrap();
let val = crate::constant::trans_const_value(
let val = crate::constant::codegen_const_value(
fx,
const_val,
ret.layout().ty,
@ -885,12 +886,12 @@ pub(crate) fn codegen_intrinsic_call<'tcx>(
};
ptr_guaranteed_eq, (c a, c b) {
let val = crate::num::trans_ptr_binop(fx, BinOp::Eq, a, b);
let val = crate::num::codegen_ptr_binop(fx, BinOp::Eq, a, b);
ret.write_cvalue(fx, val);
};
ptr_guaranteed_ne, (c a, c b) {
let val = crate::num::trans_ptr_binop(fx, BinOp::Ne, a, b);
let val = crate::num::codegen_ptr_binop(fx, BinOp::Ne, a, b);
ret.write_cvalue(fx, val);
};
@ -1068,7 +1069,7 @@ pub(crate) fn codegen_intrinsic_call<'tcx>(
};
fadd_fast | fsub_fast | fmul_fast | fdiv_fast | frem_fast, (c x, c y) {
let res = crate::num::trans_float_binop(fx, match intrinsic {
let res = crate::num::codegen_float_binop(fx, match intrinsic {
"fadd_fast" => BinOp::Add,
"fsub_fast" => BinOp::Sub,
"fmul_fast" => BinOp::Mul,

View File

@ -127,7 +127,7 @@ pub(super) fn codegen_simd_intrinsic_call<'tcx>(
);
};
let idx = idx_const.val.try_to_bits(Size::from_bytes(4 /* u32*/)).expect(&format!("kind not scalar: {:?}", idx_const));
let idx = idx_const.val.try_to_bits(Size::from_bytes(4 /* u32*/)).unwrap_or_else(|| panic!("kind not scalar: {:?}", idx_const));
let (_lane_type, lane_count) = lane_type_and_count(fx.tcx, base.layout());
if idx >= lane_count.into() {
fx.tcx.sess.span_fatal(fx.mir.span, &format!("[simd_insert] idx {} >= lane_count {}", idx, lane_count));
@ -149,7 +149,7 @@ pub(super) fn codegen_simd_intrinsic_call<'tcx>(
);
};
let idx = idx_const.val.try_to_bits(Size::from_bytes(4 /* u32*/)).expect(&format!("kind not scalar: {:?}", idx_const));
let idx = idx_const.val.try_to_bits(Size::from_bytes(4 /* u32*/)).unwrap_or_else(|| panic!("kind not scalar: {:?}", idx_const));
let (_lane_type, lane_count) = lane_type_and_count(fx.tcx, v.layout());
if idx >= lane_count.into() {
fx.tcx.sess.span_fatal(fx.mir.span, &format!("[simd_extract] idx {} >= lane_count {}", idx, lane_count));

View File

@ -9,6 +9,7 @@
)]
#![warn(rust_2018_idioms)]
#![warn(unused_lifetimes)]
#![warn(unreachable_pub)]
#[cfg(feature = "jit")]
extern crate libc;
@ -110,7 +111,7 @@ mod prelude {
pub(crate) use cranelift_module::{self, DataContext, DataId, FuncId, Linkage, Module};
pub(crate) use crate::abi::*;
pub(crate) use crate::base::{trans_operand, trans_place};
pub(crate) use crate::base::{codegen_operand, codegen_place};
pub(crate) use crate::cast::*;
pub(crate) use crate::common::*;
pub(crate) use crate::debuginfo::{DebugContext, UnwindContext};

View File

@ -25,11 +25,9 @@ pub(crate) fn get_static_linkage(tcx: TyCtxt<'_>, def_id: DefId) -> Linkage {
RLinkage::ExternalWeak | RLinkage::WeakAny => Linkage::Preemptible,
_ => panic!("{:?}", linkage),
}
} else if tcx.is_reachable_non_generic(def_id) {
Linkage::Export
} else {
if tcx.is_reachable_non_generic(def_id) {
Linkage::Export
} else {
Linkage::Hidden
}
Linkage::Hidden
}
}

View File

@ -76,7 +76,7 @@ pub(crate) fn maybe_create_entry_wrapper(
.unwrap();
let mut ctx = Context::new();
ctx.func = Function::with_name_signature(ExternalName::user(0, 0), cmain_sig.clone());
ctx.func = Function::with_name_signature(ExternalName::user(0, 0), cmain_sig);
{
let mut func_ctx = FunctionBuilderContext::new();
let mut bcx = FunctionBuilder::new(&mut ctx.func, &mut func_ctx);

View File

@ -29,7 +29,7 @@ impl MetadataLoader for CraneliftMetadataLoader {
.expect("Rlib metadata file too big to load into memory."),
);
::std::io::copy(&mut entry, &mut buf).map_err(|e| format!("{:?}", e))?;
let buf: OwningRef<Vec<u8>, [u8]> = OwningRef::new(buf).into();
let buf: OwningRef<Vec<u8>, [u8]> = OwningRef::new(buf);
return Ok(rustc_erase_owner!(buf.map_owner_box()));
}
}
@ -47,7 +47,7 @@ impl MetadataLoader for CraneliftMetadataLoader {
.data()
.map_err(|e| format!("failed to read .rustc section: {:?}", e))?
.to_owned();
let buf: OwningRef<Vec<u8>, [u8]> = OwningRef::new(buf).into();
let buf: OwningRef<Vec<u8>, [u8]> = OwningRef::new(buf);
Ok(rustc_erase_owner!(buf.map_owner_box()))
}
}

View File

@ -89,10 +89,10 @@ pub(crate) fn codegen_binop<'tcx>(
}
match in_lhs.layout().ty.kind() {
ty::Bool => crate::num::trans_bool_binop(fx, bin_op, in_lhs, in_rhs),
ty::Uint(_) | ty::Int(_) => crate::num::trans_int_binop(fx, bin_op, in_lhs, in_rhs),
ty::Float(_) => crate::num::trans_float_binop(fx, bin_op, in_lhs, in_rhs),
ty::RawPtr(..) | ty::FnPtr(..) => crate::num::trans_ptr_binop(fx, bin_op, in_lhs, in_rhs),
ty::Bool => crate::num::codegen_bool_binop(fx, bin_op, in_lhs, in_rhs),
ty::Uint(_) | ty::Int(_) => crate::num::codegen_int_binop(fx, bin_op, in_lhs, in_rhs),
ty::Float(_) => crate::num::codegen_float_binop(fx, bin_op, in_lhs, in_rhs),
ty::RawPtr(..) | ty::FnPtr(..) => crate::num::codegen_ptr_binop(fx, bin_op, in_lhs, in_rhs),
_ => unreachable!(
"{:?}({:?}, {:?})",
bin_op,
@ -102,7 +102,7 @@ pub(crate) fn codegen_binop<'tcx>(
}
}
pub(crate) fn trans_bool_binop<'tcx>(
pub(crate) fn codegen_bool_binop<'tcx>(
fx: &mut FunctionCx<'_, 'tcx, impl Module>,
bin_op: BinOp,
in_lhs: CValue<'tcx>,
@ -123,7 +123,7 @@ pub(crate) fn trans_bool_binop<'tcx>(
CValue::by_val(res, fx.layout_of(fx.tcx.types.bool))
}
pub(crate) fn trans_int_binop<'tcx>(
pub(crate) fn codegen_int_binop<'tcx>(
fx: &mut FunctionCx<'_, 'tcx, impl Module>,
bin_op: BinOp,
in_lhs: CValue<'tcx>,
@ -196,7 +196,7 @@ pub(crate) fn trans_int_binop<'tcx>(
CValue::by_val(val, in_lhs.layout())
}
pub(crate) fn trans_checked_int_binop<'tcx>(
pub(crate) fn codegen_checked_int_binop<'tcx>(
fx: &mut FunctionCx<'_, 'tcx, impl Module>,
bin_op: BinOp,
in_lhs: CValue<'tcx>,
@ -357,7 +357,7 @@ pub(crate) fn trans_checked_int_binop<'tcx>(
out_place.to_cvalue(fx)
}
pub(crate) fn trans_float_binop<'tcx>(
pub(crate) fn codegen_float_binop<'tcx>(
fx: &mut FunctionCx<'_, 'tcx, impl Module>,
bin_op: BinOp,
in_lhs: CValue<'tcx>,
@ -402,7 +402,7 @@ pub(crate) fn trans_float_binop<'tcx>(
CValue::by_val(res, in_lhs.layout())
}
pub(crate) fn trans_ptr_binop<'tcx>(
pub(crate) fn codegen_ptr_binop<'tcx>(
fx: &mut FunctionCx<'_, 'tcx, impl Module>,
bin_op: BinOp,
in_lhs: CValue<'tcx>,

View File

@ -228,7 +228,8 @@ pub(super) fn optimize_function(
match *potential_stores {
[] => {
#[cfg(debug_assertions)]
clif_comments.add_comment(load, format!("[BUG?] Reading uninitialized memory"));
clif_comments
.add_comment(load, "[BUG?] Reading uninitialized memory".to_string());
}
[store]
if spatial_overlap(&opt_ctx.ctx.func, store, load) == SpatialOverlap::Full

View File

@ -131,11 +131,11 @@ impl FuncWriter for &'_ CommentWriter {
if !comment.is_empty() {
writeln!(w, "; {}", comment)?;
} else {
writeln!(w, "")?;
writeln!(w)?;
}
}
if !self.global_comments.is_empty() {
writeln!(w, "")?;
writeln!(w)?;
}
self.super_preamble(w, func, reg_info)
@ -153,7 +153,7 @@ impl FuncWriter for &'_ CommentWriter {
if let Some(comment) = self.entity_comments.get(&entity) {
writeln!(w, " ; {}", comment.replace('\n', "\n; "))
} else {
writeln!(w, "")
writeln!(w)
}
}
@ -261,7 +261,7 @@ pub(crate) fn write_clif_file<'tcx>(
writeln!(file, "set is_pic")?;
writeln!(file, "set enable_simd")?;
writeln!(file, "target {} haswell", target_triple)?;
writeln!(file, "")?;
writeln!(file)?;
file.write_all(clif.as_bytes())?;
};
if let Err(err) = res {

View File

@ -67,4 +67,3 @@ pub(crate) fn trap_unimplemented(fx: &mut FunctionCx<'_, '_, impl Module>, msg:
let true_ = fx.bcx.ins().iconst(types::I32, 1);
fx.bcx.ins().trapnz(true_, TrapCode::User(!0));
}

View File

@ -27,10 +27,10 @@ fn codegen_field<'tcx>(
return simple(fx);
}
match field_layout.ty.kind() {
ty::Slice(..) | ty::Str | ty::Foreign(..) => return simple(fx),
ty::Slice(..) | ty::Str | ty::Foreign(..) => simple(fx),
ty::Adt(def, _) if def.repr.packed() => {
assert_eq!(layout.align.abi.bytes(), 1);
return simple(fx);
simple(fx)
}
_ => {
// We have to align the offset for DST's
@ -237,15 +237,12 @@ impl<'tcx> CValue<'tcx> {
let clif_ty = fx.clif_type(layout.ty).unwrap();
match layout.ty.kind() {
ty::Bool => {
assert!(
const_val == 0 || const_val == 1,
"Invalid bool 0x{:032X}",
const_val
);
}
_ => {}
if let ty::Bool = layout.ty.kind() {
assert!(
const_val == 0 || const_val == 1,
"Invalid bool 0x{:032X}",
const_val
);
}
let val = match layout.ty.kind() {
@ -335,7 +332,7 @@ impl<'tcx> CPlace<'tcx> {
let stack_slot = fx.bcx.create_stack_slot(StackSlotData {
kind: StackSlotKind::ExplicitSlot,
size: layout.size.bytes() as u32,
size: u32::try_from(layout.size.bytes()).unwrap(),
offset: None,
});
CPlace {
@ -533,6 +530,13 @@ impl<'tcx> CPlace<'tcx> {
dst_ty: Type,
) {
let src_ty = fx.bcx.func.dfg.value_type(data);
assert_eq!(
src_ty.bytes(),
dst_ty.bytes(),
"write_cvalue_transmute: {:?} -> {:?}",
src_ty,
dst_ty,
);
let data = match (src_ty, dst_ty) {
(_, _) if src_ty == dst_ty => data,
@ -544,6 +548,17 @@ impl<'tcx> CPlace<'tcx> {
_ if src_ty.is_vector() && dst_ty.is_vector() => {
fx.bcx.ins().raw_bitcast(dst_ty, data)
}
_ if src_ty.is_vector() || dst_ty.is_vector() => {
// FIXME do something more efficient for transmutes between vectors and integers.
let stack_slot = fx.bcx.create_stack_slot(StackSlotData {
kind: StackSlotKind::ExplicitSlot,
size: src_ty.bytes(),
offset: None,
});
let ptr = Pointer::stack_slot(stack_slot);
ptr.store(fx, data, MemFlags::trusted());
ptr.load(fx, dst_ty, MemFlags::trusted())
}
_ => unreachable!("write_cvalue_transmute: {:?} -> {:?}", src_ty, dst_ty),
};
fx.bcx

View File

@ -108,14 +108,14 @@ fn build_vtable<'tcx>(
(&[]).iter()
};
let methods = methods.cloned().map(|opt_mth| {
opt_mth.map_or(None, |(def_id, substs)| {
Some(import_function(
opt_mth.map(|(def_id, substs)| {
import_function(
tcx,
&mut fx.cx.module,
Instance::resolve_for_vtable(tcx, ParamEnv::reveal_all(), def_id, substs)
.unwrap()
.polymorphize(fx.tcx),
))
)
})
});
components.extend(methods);
@ -137,15 +137,7 @@ fn build_vtable<'tcx>(
}
}
data_ctx.set_align(
fx.tcx
.data_layout
.pointer_align
.pref
.bytes()
.try_into()
.unwrap(),
);
data_ctx.set_align(fx.tcx.data_layout.pointer_align.pref.bytes());
let data_id = fx
.cx

114
test.sh
View File

@ -1,119 +1,15 @@
#!/bin/bash
set -e
# Build cg_clif
export RUSTFLAGS="-Zrun_dsymutil=no"
if [[ "$1" == "--release" ]]; then
export CHANNEL='release'
cargo build --release
else
export CHANNEL='debug'
cargo build --bin cg_clif
fi
# Config
source scripts/config.sh
export CG_CLIF_INCR_CACHE_DISABLED=1
RUSTC=$RUSTC" "$RUSTFLAGS" -L crate=target/out --out-dir target/out -Cdebuginfo=2"
./build.sh --without-sysroot $@
# Cleanup
rm -r target/out || true
# Perform all tests
echo "[BUILD] mini_core"
$RUSTC example/mini_core.rs --crate-name mini_core --crate-type lib,dylib --target $TARGET_TRIPLE
scripts/tests.sh no_sysroot
echo "[BUILD] example"
$RUSTC example/example.rs --crate-type lib --target $TARGET_TRIPLE
./build.sh $@
if [[ "$JIT_SUPPORTED" = "1" ]]; then
echo "[JIT] mini_core_hello_world"
CG_CLIF_JIT_ARGS="abc bcd" $RUSTC --jit example/mini_core_hello_world.rs --cfg jit --target $HOST_TRIPLE
else
echo "[JIT] mini_core_hello_world (skipped)"
fi
echo "[AOT] mini_core_hello_world"
$RUSTC example/mini_core_hello_world.rs --crate-name mini_core_hello_world --crate-type bin -g --target $TARGET_TRIPLE
$RUN_WRAPPER ./target/out/mini_core_hello_world abc bcd
# (echo "break set -n main"; echo "run"; sleep 1; echo "si -c 10"; sleep 1; echo "frame variable") | lldb -- ./target/out/mini_core_hello_world abc bcd
echo "[AOT] arbitrary_self_types_pointers_and_wrappers"
$RUSTC example/arbitrary_self_types_pointers_and_wrappers.rs --crate-name arbitrary_self_types_pointers_and_wrappers --crate-type bin --target $TARGET_TRIPLE
$RUN_WRAPPER ./target/out/arbitrary_self_types_pointers_and_wrappers
echo "[BUILD] sysroot"
time ./build_sysroot/build_sysroot.sh --release
echo "[AOT] alloc_example"
$RUSTC example/alloc_example.rs --crate-type bin --target $TARGET_TRIPLE
$RUN_WRAPPER ./target/out/alloc_example
if [[ "$JIT_SUPPORTED" = "1" ]]; then
echo "[JIT] std_example"
$RUSTC --jit example/std_example.rs --target $HOST_TRIPLE
else
echo "[JIT] std_example (skipped)"
fi
echo "[AOT] dst_field_align"
# FIXME Re-add -Zmir-opt-level=2 once rust-lang/rust#67529 is fixed.
$RUSTC example/dst-field-align.rs --crate-name dst_field_align --crate-type bin --target $TARGET_TRIPLE
$RUN_WRAPPER ./target/out/dst_field_align || (echo $?; false)
echo "[AOT] std_example"
$RUSTC example/std_example.rs --crate-type bin --target $TARGET_TRIPLE
$RUN_WRAPPER ./target/out/std_example arg
echo "[AOT] subslice-patterns-const-eval"
$RUSTC example/subslice-patterns-const-eval.rs --crate-type bin -Cpanic=abort --target $TARGET_TRIPLE
$RUN_WRAPPER ./target/out/subslice-patterns-const-eval
echo "[AOT] track-caller-attribute"
$RUSTC example/track-caller-attribute.rs --crate-type bin -Cpanic=abort --target $TARGET_TRIPLE
$RUN_WRAPPER ./target/out/track-caller-attribute
echo "[AOT] mod_bench"
$RUSTC example/mod_bench.rs --crate-type bin --target $TARGET_TRIPLE
$RUN_WRAPPER ./target/out/mod_bench
pushd rand
rm -r ./target || true
../cargo.sh test --workspace
popd
pushd simple-raytracer
if [[ "$HOST_TRIPLE" = "$TARGET_TRIPLE" ]]; then
echo "[BENCH COMPILE] ebobby/simple-raytracer"
hyperfine --runs ${RUN_RUNS:-10} --warmup 1 --prepare "cargo clean" \
"RUSTC=rustc RUSTFLAGS='' cargo build" \
"../cargo.sh 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
echo "[BENCH COMPILE] ebobby/simple-raytracer (skipped)"
echo "[COMPILE] ebobby/simple-raytracer"
../cargo.sh build
echo "[BENCH RUN] ebobby/simple-raytracer (skipped)"
fi
popd
pushd build_sysroot/sysroot_src/library/core/tests
echo "[TEST] libcore"
rm -r ./target || true
../../../../../cargo.sh test
popd
pushd regex
echo "[TEST] rust-lang/regex example shootout-regex-dna"
../cargo.sh clean
# Make sure `[codegen mono items] start` doesn't poison the diff
../cargo.sh build --example shootout-regex-dna
cat examples/regexdna-input.txt | ../cargo.sh run --example shootout-regex-dna | grep -v "Spawned thread" > res.txt
diff -u res.txt examples/regexdna-output.txt
echo "[TEST] rust-lang/regex tests"
../cargo.sh test --tests -- --exclude-should-panic --test-threads 1 -Zunstable-options
popd
scripts/tests.sh base_sysroot
scripts/tests.sh extended_sysroot