Commit Graph

7256 Commits

Author SHA1 Message Date
Alex Crichton
e4c3fc5cf2 Update immediate and transitive dependencies
I don't think this has happened in awhile but I've run a `cargo update`
as well as trimming some of the duplicate/older dependencies in
`Cargo.lock` by updating some of our immediate dependencies as well.
2020-11-05 08:34:09 -08:00
Alex Crichton
ab1958434a Bump to 0.21.0 (#2359) 2020-11-05 09:39:53 -06:00
Alex Crichton
a277cf5ee4 Store WasmFuncType in FuncType (#2365)
This commit updates `wasmtime::FuncType` to exactly store an internal
`WasmFuncType` from the cranelift crates. This allows us to remove a
translation layer when we are given a `FuncType` and want to get an
internal cranelift type out as a result.

The other major change from this commit was changing the constructor and
accessors of `FuncType` to be iterator-based instead of exposing
implementation details.
2020-11-05 08:49:03 -06:00
Alex Crichton
ea3306e74c Use the psm crate to figure out the current stack pointer (#2358)
Currently the runtime needs to acquire the current stack pointer so it
can set a limit for where if the wasm stack goes below that point it
will abort the wasm code. Acquiring the stack pointer is done in a
brittle way right now which involves looking at the address of what we
hope is an on-stack structure. This turns out to not work at all with
ASan as well.

Instead this commit switches to the `psm` crate which is used by the
Rust compiler team for stack manipulation, namely a coarse version of
segmented stacks to avoid stack overflow in the compiler. We don't need
most of the implementation of `psm`, just the `stack_pointer` function,
but it shouldn't be a burden to bring in!

Closes #2344
2020-11-05 07:29:04 -06:00
Alex Crichton
6b137c2a3d Move native signatures out of Module (#2362)
After compilation there's actually no need to hold onto the native
signature for a wasm function type, so this commit moves out the
`ir::Signature` value from a `Module` into a separate field that's
deallocated when compilation is finished. This simplifies the
`SignatureRegistry` because it only needs to track wasm functino types
and it also means less work is done for `Func::wrap`.
2020-11-04 14:22:37 -06:00
Julian Seward
dd9bfcefaa CL/aarch64: implement the wasm SIMD v128.load{32,64}_zero instructions.
This patch implements, for aarch64, the following wasm SIMD extensions.

  v128.load32_zero and v128.load64_zero instructions
  https://github.com/WebAssembly/simd/pull/237

The changes are straightforward:

* no new CLIF instructions.  They are translated into an existing CLIF scalar
  load followed by a CLIF `scalar_to_vector`.

* the comment/specification for CLIF `scalar_to_vector` has been changed to
  match the actual intended semantics, per consulation with Andrew Brown.

* translation from `scalar_to_vector` to aarch64 `fmov` instruction.  This
  has been generalised slightly so as to allow both 32- and 64-bit transfers.

* special-case zero in `lower_constant_f128` in order to avoid a
  potentially slow call to `Inst::load_fp_constant128`.

* Once "Allow loads to merge into other operations during instruction
  selection in MachInst backends"
  (https://github.com/bytecodealliance/wasmtime/issues/2340) lands,
  we can use that functionality to pattern match the two-CLIF pair and
  emit a single AArch64 instruction.

* A simple filetest has been added.

There is no comprehensive testcase in this commit, because that is a separate
repo.  The implementation has been tested, nevertheless.
2020-11-04 20:00:04 +01:00
Nick Fitzgerald
285edeec3e Merge pull request #2319 from alexcrichton/remove-trampolines-from-instance
Refactor how signatures/trampolines are stored in `Store`
2020-11-04 10:49:55 -08:00
Chris Fallin
75e02276be Merge pull request #2360 from jgouly/reg_map
aarch64: Fix aarch64_map_regs for FpuRRI
2020-11-04 10:37:50 -08:00
Joey Gouly
0223cb2f8c aarch64: Fix aarch64_map_regs for FpuRRI
This was wrong since I added it in 02c3f238f.

Copyright (c) 2020, Arm Limited.
2020-11-04 16:53:25 +00:00
Ulrich Weigand
fa9c2a5172 Fix off-by-one error looking up frame info for a function (#2349)
The ModuleFrameInfo and FunctionInfo data structures maintain
a list of ranges via a BTreeMap.  The key to that map is one
past the end of the module/function in question.  This causes
a problem in the case of immediately adjacent ranges.  For
example, if we have two functions occupying adjacent ranges:
  A:   0-100
  B: 100-200
function A is stored with a key of 100 and B with a key of 200.

Now, when looking up the function associated with address 100,
we'd expect to find B.  However the current code:

       let (end, func) = info.functions.range(pc..).next()?;
       if pc < func.start || *end < pc {

will look up the value 100 in the map and return function A,
which will then fail the pc < func.start check in the next
line, so the result will be failure.

To fix this problem, make sure that the key used when
registering functions or modules is the address of the
last byte, not one past the end.
2020-11-03 13:54:27 -06:00
Chris Fallin
c210f4d6a6 Merge pull request #2356 from uweigand/abi-outgoingargs
machinst ABI: Support for accumulating outgoing args
2020-11-03 10:26:43 -08:00
Ulrich Weigand
80c2d70d2d machinst ABI: Support for accumulating outgoing args
When performing a function call, the platform ABI may require space
on the stack to hold outgoing arguments and/or return values.

Currently, this is supported via decrementing the stack pointer
before the call and incrementing it afterwards, using the
emit_stack_pre_adjust and emit_stack_post_adjust methods of
ABICaller.  However, on some platforms it would be preferable
to just allocate enough space for any call done in the function
in the caller's prologue instead.

This patch adds support to allow back-ends to choose that method.
Instead of calling emit_stack_pre/post_adjust around a call, they
simply call a new accumulate_outgoing_args_size method of
ABICaller instead.  This will pass on the required size to the
ABICallee structure of the calling function, which will accumulate
the maximum size required for all function calls.

That accumulated size is then passed to the gen_clobber_save
and gen_clobber_restore functions so they can include the size
in the stack allocation / deallocation that already happens in
the prologue / epilogue code.
2020-11-03 18:49:34 +01:00
Chris Fallin
5ab7b4aa7f Merge pull request #2345 from uweigand/abi-stackalign
machinst ABI: Allow back-end to define stack alignment
2020-11-03 09:02:41 -08:00
Chris Fallin
0c240991ae Merge pull request #2346 from uweigand/abi-noframepointer
machinst ABI: Pass fixed frame size to gen_clobber_restore
2020-11-03 09:00:59 -08:00
Julian Seward
5a5fb11979 CL/aarch64: implement the wasm SIMD i32x4.dot_i16x8_s instruction
This patch implements, for aarch64, the following wasm SIMD extensions

  i32x4.dot_i16x8_s instruction
  https://github.com/WebAssembly/simd/pull/127

It also updates dependencies as follows, in order that the new instruction can
be parsed, decoded, etc:

  wat          to  1.0.27
  wast         to  26.0.1
  wasmparser   to  0.65.0
  wasmprinter  to  0.2.12

The changes are straightforward:

* new CLIF instruction `widening_pairwise_dot_product_s`

* translation from wasm into `widening_pairwise_dot_product_s`

* new AArch64 instructions `smull`, `smull2` (part of the `VecRRR` group)

* translation from `widening_pairwise_dot_product_s` to `smull ; smull2 ; addv`

There is no testcase in this commit, because that is a separate repo.  The
implementation has been tested, nevertheless.
2020-11-03 14:25:04 +01:00
Ulrich Weigand
c9bc4edd08 machinst ABI: Pass fixed frame size to gen_clobber_restore
The ABI common code currently passes the fixed frame size to
the gen_clobber_save back-end routine, which is required to
emit code to allocate the required stack space in the prologue.

Similarly, the back-end needs to emit code to de-allocate the
stack in the epilogue.  However, at this point the back-end
does not have access to that fixed frame size value any more.
With targets that use a frame pointer, this does not matter,
since de-allocation can be done simply by assigning the frame
pointer back to the stack pointer.  However, on targets that
do not use a frame pointer, the frame size is required.

To allow back-ends that option, this patch changes ABI common
code to pass the fixed frame size to get_clobber_restore as
well (the same value as is passed to get_clobber_save).
2020-11-03 11:15:03 +01:00
Ulrich Weigand
d02ae3940c machinst ABI: Allow back-end to define stack alignment
The common gen_prologue code currently assumes that the stack
pointer has to be aligned to twice the word size.  While this
is true for many ABIs, it does not hold universally.

This patch adds a new callback stack_align that back-ends can
provide to define the specific stack alignment required by the
ABI on that platform.
2020-11-03 09:43:55 +01:00
Chris Fallin
54a97f784e Merge pull request #2353 from alexcrichton/update-nightly
Update nightly used on CI for testing
2020-11-02 20:47:36 -08:00
Alex Crichton
10b5cc50c3 Further compress the in-memory representation of address maps (#2324)
This commit reduces the size of `InstructionAddressMap` from 24 bytes to
8 bytes by dropping the `code_len` field and reducing `code_offset` to
`u32` instead of `usize`. The intention is to primarily make the
in-memory version take up less space, and the hunch is that the
`code_len` is largely not necessary since most entries in this map are
always adjacent to one another. The `code_len` field is now implied by
the `code_offset` field of the next entry in the map.

This isn't as big of an improvement to serialized module size as #2321
or #2322, primarily because of the switch to variable-length encoding.
Despite this though it shaves about 10MB off the encoded size of the
module from #2318
2020-11-02 20:37:18 -06:00
Alex Crichton
ead53b88c3 Update nightly used on CI for testing
Pull in a Cargo fix for flaky failures using `-Zpackage-features`
2020-11-02 18:30:58 -08:00
Alex Crichton
372ae2aeb6 Fix a panic in table-ops translation (#2350)
This fixes an issue where `ensure_inserted_block()` wasn't called before
we do some block manipulation in the Wasmtime translation of some
table-related instructions. It looks like `ensure_inserted_block()` is
otherwise called on most instructions being added, so we just need to
call it explicitly it seems here.

Closes #2347
2020-11-02 17:53:43 -06:00
Andrew Brown
6d50099816 Rewrite interpreter generically (#2323)
* Rewrite interpreter generically

This change re-implements the Cranelift interpreter to use generic values; this makes it possible to do abstract interpretation of Cranelift instructions. In doing so, the interpretation state is extracted from the `Interpreter` structure and is accessed via a `State` trait; this makes it possible to not only more clearly observe the interpreter's state but also to interpret using a dummy state (e.g. `ImmutableRegisterState`). This addition made it possible to implement more of the Cranelift instructions (~70%, ignoring the x86-specific instructions).

* Replace macros with closures
2020-11-02 12:28:07 -08:00
Chris Fallin
59a2ce4d34 Merge pull request #2352 from cfallin/x64-ci-lock
x64 new-backend CI: use `Cargo.lock` in build.
2020-11-02 11:59:06 -08:00
Nick Fitzgerald
8d9b03c154 Merge pull request #2351 from fitzgen/update-z3
peepmatic: Update to z3 version 0.7.1
2020-11-02 11:51:10 -08:00
Chris Fallin
afa54c0a32 x64 new-backend CI: use Cargo.lock in build.
We do a `cargo fetch --locked` for most of our CI builds, but
`run-experimental-x64-ci.sh` was not doing this. As a result, some CI
runs seem to fail depending on which versions of crates they download. A
common failure mode is that two different versions of the `syn` crate
get into the build somehow, resulting in errors in wiggle/witx.

This change simply adds the `--locked` flag to the `cargo test` run for
the new x64 backend.
2020-11-02 11:13:46 -08:00
Nick Fitzgerald
bfbe6ea348 peepmatic: Update to z3 version 0.7.1
This fixes a memory leak related to custom datatypes:
https://github.com/prove-rs/z3.rs/pull/104
2020-11-02 10:55:13 -08:00
Nick Fitzgerald
146a393a9a Merge pull request #2348 from alexcrichton/log-wat
Print a message in `log_wat` while fuzzing
2020-11-02 08:37:08 -08:00
Alex Crichton
3887881800 Refactor how signatures/trampolines are stored in Store
This commit refactors where trampolines and signature information is
stored within a `Store`, namely moving them from
`wasmtime_runtime::Instance` instead to `Store` itself. The goal here is
to remove an allocation inside of an `Instance` and make them a bit
cheaper to create. Additionally this should open up future possibilities
like not creating duplicate trampolines for signatures already in the
`Store` when using `Func::new`.
2020-11-02 07:54:18 -08:00
Alex Crichton
35327ed4d7 Print a message in log_wat while fuzzing
Similar to `log_wasm`, just indicates that a file was written.
2020-11-02 06:52:01 -08:00
Chris Fallin
d1be8dcfc0 Merge pull request #2310 from akirilov-arm/vector_constants
Cranelift AArch64: Improve code generation for vector constants
2020-11-01 21:56:40 -08:00
Chris Fallin
44cbdecea0 Merge pull request #2343 from bjorn3/fix_icmp_imm_i128
Fix icmp_imm.i128
2020-10-31 14:09:56 -07:00
bjorn3
23aafa1054 Fix icmp_imm.i128
The immediate splitting code contained a bug causing both low and high
to be equal for i128. This is the root cause for
bjorn3/rustc_codegen_cranelift#1097 and likely the only bug preventing
cg_clif from bootstrapping rustc.
2020-10-31 21:11:50 +01:00
Chris Fallin
53f044715b Merge pull request #2341 from jlb6740/update_comments_on_int_float_conversion
Updates comments on Int to Float conversion
2020-10-30 18:41:21 -07:00
Johnnie Birch
c32740ffcd Updates comments on Int to Float conversion
Int to float for unsigned ints has merged, but there were
some comments on a different PR for the same pull request that
are addressed in this PR
2020-10-30 16:49:30 -07:00
Anton Kirilov
207779fe1d Cranelift AArch64: Improve code generation for vector constants
In particular, introduce initial support for the MOVI and MVNI
instructions, with 8-bit elements. Also, treat vector constants
as 32- or 64-bit floating-point numbers, if their value allows
it, by relying on the architectural zero extension. Finally,
stop generating literal loads for 32-bit constants.

Copyright (c) 2020, Arm Limited.
2020-10-30 13:16:12 +00:00
Pat Hickey
7b43bf76ed Merge pull request #2287 from bjorn3/simplejit_improvements
Some SimpleJIT improvements
2020-10-29 12:09:37 -07:00
Nick Fitzgerald
ee42526c13 Merge pull request #2339 from fitzgen/update-z3
peepmatic: update z3 dependency to version 0.7.0
2020-10-29 12:00:33 -07:00
Nick Fitzgerald
5a09e47e38 peepmatic: update z3 dependency to version 0.7.0 2020-10-29 10:58:40 -07:00
Alex Crichton
b73b831892 Replace binaryen -ttf based fuzzing with wasm-smith (#2336)
This commit removes the binaryen support for fuzzing from wasmtime,
instead switching over to `wasm-smith`. In general it's great to have
what fuzzing we can, but our binaryen support suffers from a few issues:

* The Rust crate, binaryen-sys, seems largely unmaintained at this
  point. While we could likely take ownership and/or send PRs to update
  the crate it seems like the maintenance is largely on us at this point.

* Currently the binaryen-sys crate doesn't support fuzzing anything
  beyond MVP wasm, but we're interested at least in features like bulk
  memory and reference types. Additionally we'll also be interested in
  features like module-linking. New features would require either
  implementation work in binaryen or the binaryen-sys crate to support.

* We have 4-5 fuzz-bugs right now related to timeouts simply in
  generating a module for wasmtime to fuzz. One investigation along
  these lines in the past revealed a bug in binaryen itself, and in any
  case these bugs would otherwise need to get investigated, reported,
  and possibly fixed ourselves in upstream binaryen.

Overall I'm not sure at this point if maintaining binaryen fuzzing is
worth it with the advent of `wasm-smith` which has similar goals for
wasm module generation, but is much more readily maintainable on our
end.

Additonally in this commit I've added a fuzzer for wasm-smith's
`SwarmConfig`-based fuzzer which should expand the coverage of tested
modules.

Closes #2163
2020-10-29 10:02:59 -05:00
Qinxuan Chen
3cd9d52d32 Update the hashbrown to use the same version (#2338)
Signed-off-by: koushiro <koushiro.cqx@gmail.com>
2020-10-29 09:59:56 -05:00
Alex Crichton
61f0b8fc56 Remove Windows-specific code for static memory bounds
Added in c4e10227de I think the original
reason (which I'm not entirely knowledgeable of) may no longer be
applicable? In any case this is a significant difference on Windows from
other platforms because it makes loads/stores of wasm code have manual
checks instead of relying on the guard page, causing runtime and
compile-time slowdowns on Windows-only.

I originally rediscovered this when investigating #2318 and saw that
both the compile time of the module in question and trap information
tables were much larger than they were on Linux. Removing this
Windows-specific configuration fixed the discrepancies and afterwards
Linux and Windows were basically the same.
2020-10-28 16:49:53 -07:00
Andrew Brown
6c6d958f38 [machinst x64]: implement packed pmin/pmax 2020-10-28 16:03:53 -07:00
Andrew Brown
6725b6b129 [machinst x64]: implement bitmask 2020-10-28 15:16:36 -07:00
Andrew Brown
5b9a21e099 Add missing SourceLoc to newly-emitted instructions
The changes in https://github.com/bytecodealliance/wasmtime/pull/2278 added `SourceLoc`s to several x64 `Inst` variants; between when that PR was last run in CI and when it was merged, new instructions were added that require this new parameter. This change adds the parameter in order to fix CI.
2020-10-28 14:33:09 -07:00
Johnnie Birch
fa66daea25 Add filetests for fcvt_from_sint.f32x4
Add portions of filetests simd-conversion-legalize.clif and simd-conversion-run.clif
that test fcvt_from_sint.f32x4
2020-10-28 13:02:50 -07:00
Johnnie Birch
8bbe6a25a9 Add support for packed float to signed int conversion
Implements i32x4.trunc_sat_f32x4_s
2020-10-28 13:02:50 -07:00
Johnnie Birch
97392eae3d Adds support for converting packed unsigned integer to packed float 2020-10-28 13:02:50 -07:00
Chris Fallin
c35904a8bf Merge pull request #2278 from akirilov-arm/load_splat
Introduce the Cranelift IR instruction `LoadSplat`
2020-10-28 12:54:03 -07:00
Alex Crichton
3461ffa563 Remove source_loc from TrapInformation (#2325)
Turns out this wasn't needed anywhere! Additionally we can construct it
from `InstructionAddressMap` anyway. There's so many pieces of trap
information that it's best to keep these structures small as well.
2020-10-28 13:05:05 -05:00
Nick Fitzgerald
a1db0ff6a9 Merge pull request #2329 from fitzgen/upload-serialized-peepholes
CI: upload built peepholes as artifacts
2020-10-27 16:03:54 -07:00