Skip to content

Commit

Permalink
Merge pull request bytecodealliance#3 from dhil/weekly-merge
Browse files Browse the repository at this point in the history
Weekly merge
  • Loading branch information
dhil authored Sep 2, 2023
2 parents 677ca18 + 8964b82 commit a49b6d1
Show file tree
Hide file tree
Showing 52 changed files with 1,087 additions and 506 deletions.
27 changes: 19 additions & 8 deletions .github/actions/install-rust/action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ inputs:
toolchain:
description: 'Default toolchan to install'
required: false
default: '1.71.0'
default: 'default'
lockfiles:
description: 'Path glob for Cargo.lock files to use as cache keys'
required: false
Expand All @@ -14,13 +14,28 @@ inputs:
runs:
using: composite
steps:
- name: Install Rust
shell: bash
id: select
run: |
# Determine MSRV as N in `1.N.0` by looking at the `rust-version`
# located in the root `Cargo.toml`.
msrv=$(grep 'rust-version.*1' Cargo.toml | sed 's/.*\.\([0-9]*\)\..*/\1/')
if [ "${{ inputs.toolchain }}" = "default" ]; then
echo "version=1.$((msrv+2)).0" >> "$GITHUB_OUTPUT"
elif [ "${{ inputs.toolchain }}" = "msrv" ]; then
echo "version=1.$msrv.0" >> "$GITHUB_OUTPUT"
else
echo "version=${{ inputs.toolchain }}" >> "$GITHUB_OUTPUT"
fi
- name: Install Rust
shell: bash
run: |
rustup set profile minimal
rustup update "${{ inputs.toolchain }}" --no-self-update
rustup default "${{ inputs.toolchain }}"
rustup update "${{ steps.select.outputs.version }}" --no-self-update
rustup default "${{ steps.select.outputs.version }}"
# Save disk space by avoiding incremental compilation. Also turn down
# debuginfo from 2 to 0 to help save disk space.
Expand All @@ -31,11 +46,7 @@ runs:
EOF
# Deny warnings on CI to keep our code warning-free as it lands in-tree.
# Don't do this on nightly though, since there's a fair amount of
# warning churn there.
if [[ "${{ inputs.toolchain }}" != nightly* ]]; then
echo RUSTFLAGS="-D warnings" >> "$GITHUB_ENV"
fi
echo RUSTFLAGS="-D warnings" >> "$GITHUB_ENV"
if [[ "${{ runner.os }}" = "macOS" ]]; then
cat >> "$GITHUB_ENV" <<EOF
Expand Down
2 changes: 2 additions & 0 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -383,6 +383,8 @@ jobs:
with:
submodules: true
- uses: ./.github/actions/install-rust
with:
toolchain: ${{ matrix.rust }}

# Install targets in order to build various tests throughout the repo
- run: rustup target add wasm32-wasi wasm32-unknown-unknown ${{ matrix.target }}
Expand Down
4 changes: 3 additions & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,9 @@ exclude = [
version = "13.0.0"
authors = ["The Wasmtime Project Developers"]
edition = "2021"
rust-version = "1.71.0"
# Wasmtime's current policy is that this number can be no larger than the
# current stable release of Rust minus 2.
rust-version = "1.70.0"

[workspace.dependencies]
wasmtime-wmemcheck = { path = "crates/wmemcheck", version = "=13.0.0" }
Expand Down
7 changes: 0 additions & 7 deletions RELEASES.md
Original file line number Diff line number Diff line change
Expand Up @@ -80,13 +80,6 @@ Unreleased.
These methods do not affect the size of the pre-allocated pool.
[#6835](https://github.com/bytecodealliance/wasmtime/pull/6835)

* Options to the `wasmtime` CLI for Wasmtime itself must now come before the
WebAssembly module. For example `wasmtime run foo.wasm --disable-cache` now
must be specified as `wasmtime run --disable-cache foo.wasm`. Any
argument/option after the WebAssembly module is now interpreted as an argument
to the wasm module itself.
[#6737](https://github.com/bytecodealliance/wasmtime/pull/6737)

* Builder methods for WASI contexts onw use `&mut self` instead of `self`.
[#6770](https://github.com/bytecodealliance/wasmtime/pull/6770)

Expand Down
15 changes: 15 additions & 0 deletions ci/build-test-matrix.js
Original file line number Diff line number Diff line change
Expand Up @@ -32,13 +32,22 @@ const names = fs.readFileSync(process.argv[3]).toString();
// on CI.
// * `isa` - changes to `cranelift/codegen/src/$isa` will automatically run this
// test suite.
// * `rust` - the Rust version to install, and if unset this'll be set to
// `default`
const array = [
{
"os": "ubuntu-latest",
"name": "Test Linux x86_64",
"filter": "linux-x64",
"isa": "x64"
},
{
"os": "ubuntu-latest",
"name": "Test MSRV on Linux x86_64",
"filter": "linux-x64",
"isa": "x64",
"rust": "msrv",
},
{
"os": "macos-latest",
"name": "Test macOS x86_64",
Expand Down Expand Up @@ -90,6 +99,12 @@ const array = [
}
];

for (let config of array) {
if (config.rust === undefined) {
config.rust = 'default';
}
}

function myFilter(item) {
if (item.isa && names.includes(`cranelift/codegen/src/isa/${item.isa}`)) {
return true;
Expand Down
26 changes: 24 additions & 2 deletions cranelift/codegen/src/isa/aarch64/inst.isle
Original file line number Diff line number Diff line change
Expand Up @@ -3122,15 +3122,37 @@
(rule 5 (amode ty (iadd (sextend x @ (value_type $I32)) y) offset)
(AMode.RegExtended (amode_add y offset) x (ExtendOp.SXTW)))

;; `RegScaled*` rules where this matches an addition of an "index register" to a
;; base register. The index register is shifted by the size of the type loaded
;; in bytes to enable this mode matching.
;;
;; Note that this can additionally bundle an extending operation but the
;; extension must happen before the shift. This will pattern-match the shift
;; first and then if that succeeds afterwards try to find an extend.
(rule 6 (amode ty (iadd x (ishl y (iconst (u64_from_imm64 n)))) offset)
(if-let $true (u64_eq (ty_bytes ty) (u64_shl 1 n)))
(amode_reg_scaled (amode_add x offset) y ty))
(rule 7 (amode ty (iadd (ishl y (iconst (u64_from_imm64 n))) x) offset)
(if-let $true (u64_eq (ty_bytes ty) (u64_shl 1 n)))
(amode_reg_scaled (amode_add x offset) y ty))

(decl amode_reg_scaled (Reg Value Type) AMode)
(rule 0 (amode_reg_scaled base index ty)
(AMode.RegScaled base index ty))
(rule 1 (amode_reg_scaled base (uextend index @ (value_type $I32)) ty)
(AMode.RegScaledExtended base index ty (ExtendOp.UXTW)))
(rule 2 (amode_reg_scaled base (sextend index @ (value_type $I32)) ty)
(AMode.RegScaledExtended base index ty (ExtendOp.SXTW)))

;; Small optimizations where constants found in `iadd` are folded into the
;; `offset` immediate.
;;
;; NB: this should probably be done by mid-end optimizations rather than here
;; in the backend, but currently Cranelift doesn't do that.
(rule 6 (amode ty (iadd x (iconst (simm32 y))) offset)
(rule 8 (amode ty (iadd x (iconst (simm32 y))) offset)
(if-let new_offset (s32_add_fallible y offset))
(amode ty x new_offset))
(rule 7 (amode ty (iadd (iconst (simm32 x)) y) offset)
(rule 9 (amode ty (iadd (iconst (simm32 x)) y) offset)
(if-let new_offset (s32_add_fallible x offset))
(amode ty y new_offset))

Expand Down
12 changes: 12 additions & 0 deletions cranelift/codegen/src/isa/riscv64/inst/args.rs
Original file line number Diff line number Diff line change
Expand Up @@ -161,6 +161,18 @@ impl AMode {
}
}

/// Retrieve a MachLabel that corresponds to this addressing mode, if it exists.
pub(crate) fn get_label_with_sink(&self, sink: &mut MachBuffer<Inst>) -> Option<MachLabel> {
match self {
&AMode::Const(addr) => Some(sink.get_label_for_constant(addr)),
&AMode::Label(label) => Some(label),
&AMode::RegOffset(..)
| &AMode::SPOffset(..)
| &AMode::FPOffset(..)
| &AMode::NominalSPOffset(..) => None,
}
}

pub(crate) fn to_string_with_alloc(&self, allocs: &mut AllocationConsumer<'_>) -> String {
format!("{}", self.clone().with_allocs(allocs))
}
Expand Down
47 changes: 38 additions & 9 deletions cranelift/codegen/src/isa/riscv64/inst/emit.rs
Original file line number Diff line number Diff line change
Expand Up @@ -620,18 +620,49 @@ impl MachInstEmit for Inst {
let base = from.get_base_register();
let offset = from.get_offset_with_state(state);
let offset_imm12 = Imm12::maybe_from_i64(offset);
let label = from.get_label_with_sink(sink);

// TODO: We shouldn't just fall back to `LoadAddr` immediately. For `MachLabel`s
// we should try to emit the `auipc` and add a relocation on this load.
let (addr, imm12) = match (base, offset_imm12) {
// If the offset fits into an imm12 we can directly encode it.
(Some(base), Some(imm12)) => (base, imm12),
// Otherwise load the address it into a reg and load from it.
_ => {
let (addr, imm12) = match (base, offset_imm12, label) {
// When loading from a Reg+Offset, if the offset fits into an imm12 we can directly encode it.
(Some(base), Some(imm12), None) => (base, imm12),

// Otherwise, if the offset does not fit into a imm12, we need to materialize it into a
// register and load from that.
(Some(_), None, None) => {
let tmp = writable_spilltmp_reg();
Inst::LoadAddr { rd: tmp, mem: from }.emit(&[], sink, emit_info, state);
(tmp.to_reg(), Imm12::zero())
}

// If the AMode contains a label we can emit an internal relocation that gets
// resolved with the correct address later.
(None, Some(imm), Some(label)) => {
debug_assert_eq!(imm.as_i16(), 0);

// Get the current PC.
sink.use_label_at_offset(sink.cur_offset(), label, LabelUse::PCRelHi20);
Inst::Auipc {
rd,
imm: Imm20::from_bits(0),
}
.emit(&[], sink, emit_info, state);

// Emit a relocation for the load. This patches the offset into the instruction.
sink.use_label_at_offset(sink.cur_offset(), label, LabelUse::PCRelLo12I);

// Imm12 here is meaningless since it's going to get replaced.
(rd.to_reg(), Imm12::zero())
}

// These cases are impossible with the current AModes that we have. We either
// always have a register, or always have a label. Never both, and never neither.
(None, None, None)
| (None, Some(_), None)
| (Some(_), None, Some(_))
| (Some(_), Some(_), Some(_))
| (None, None, Some(_)) => {
unreachable!("Invalid load address")
}
};

let srcloc = state.cur_srcloc();
Expand All @@ -650,8 +681,6 @@ impl MachInstEmit for Inst {
let offset = to.get_offset_with_state(state);
let offset_imm12 = Imm12::maybe_from_i64(offset);

// TODO: We shouldn't just fall back to `LoadAddr` immediately. For `MachLabel`s
// we should try to emit the `auipc` and add a relocation on this store.
let (addr, imm12) = match (base, offset_imm12) {
// If the offset fits into an imm12 we can directly encode it.
(Some(base), Some(imm12)) => (base, imm12),
Expand Down
14 changes: 12 additions & 2 deletions cranelift/codegen/src/legalizer/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
use crate::cursor::{Cursor, FuncCursor};
use crate::flowgraph::ControlFlowGraph;
use crate::ir::immediates::Imm64;
use crate::ir::types::{I128, I64};
use crate::ir::types::{self, I128, I64};
use crate::ir::{self, InstBuilder, InstructionData, MemFlags, Value};
use crate::isa::TargetIsa;
use crate::trace;
Expand All @@ -38,7 +38,17 @@ fn imm_const(pos: &mut FuncCursor, arg: Value, imm: Imm64, is_signed: bool) -> V
let imm = pos.ins().iconst(I64, imm);
pos.ins().uextend(I128, imm)
}
_ => pos.ins().iconst(ty.lane_type(), imm),
_ => {
let bits = imm.bits();
let unsigned = match ty.lane_type() {
types::I8 => bits as u8 as i64,
types::I16 => bits as u16 as i64,
types::I32 => bits as u32 as i64,
types::I64 => bits,
_ => unreachable!(),
};
pos.ins().iconst(ty.lane_type(), unsigned)
}
}
}

Expand Down
1 change: 1 addition & 0 deletions cranelift/codegen/src/prelude.isle
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,7 @@

(decl pure u16_as_u64 (u16) u64)
(extern constructor u16_as_u64 u16_as_u64)
(convert u16 u64 u16_as_u64)

(decl pure u32_as_u64 (u32) u64)
(extern constructor u32_as_u64 u32_as_u64)
Expand Down
Loading

0 comments on commit a49b6d1

Please sign in to comment.