Commit Graph

169 Commits

Author SHA1 Message Date
Ryan Hunt
c360007b19 Drop 'basic-blocks' feature (#1363)
* All: Drop 'basic-blocks' feature

This makes it so that 'basic-blocks' cannot be disabled and we can
start assuming it everywhere.

* Tests: Replace non-bb filetests with bb version

* Tests: Adapt solver-fixedconflict filetests to use basic blocks
2020-01-23 22:36:06 -07:00
Ryan Hunt
32a95a89eb Wasm: Add support for typed select instruction
Reference types introduces a typed select operation. It has identical execution
semantics so no codegen change is needed.
2020-01-23 16:31:34 -06:00
Ryan Hunt
946251e655 Codegen: Align representation of stackmap with SpiderMonkey
This commit aligns the representation of stackmaps to be the same
as Spidermonkey's by:
 * Reversing the order of the bitmap from low addresses to high addresses
 * Including incoming stack arguments
 * Excluding outgoing stack arguments

Additionally, some accessor functions were added to allow Spidermonkey
to access the internals of the bitmap.
2020-01-23 13:37:11 -06:00
Ryan Hunt
3b1dda8e92 Wasm: Ensure result of ref.is_null is I32
The (r32|r64).is_null instruction yields a boolean type, so we must
convert a Wasm `ref.is_null` to an integer so we don't get verifier
errors.
2020-01-23 13:37:11 -06:00
Ryan Hunt
41f225804b Wasm: Allow environment to translate some global.set/get operations
Spidermonkey will need to emit pre/post barriers for global.set/get to a
reference type. #1176 and #1299 plan to add a template concept that could
be used to implement this. Once that has been stabilized, we should be able
to remove this code in favor of templates easily.
2020-01-23 13:37:11 -06:00
Ryan Hunt
f41bf5ecca Wasm: Use environment to translate reference types instructions and add support for multiple tables
This commit introduces environment functions to handle the translation of
reference type instructions, analogous to how bulk-memory was implemented.

Additionally, the bulk-memory instructions that operate on tables are extended
to support multiple table indices.
2020-01-23 13:37:11 -06:00
Andrew Brown
dfc9e195ee Add temporary translation of Wasm's load_splat using Cranelift's load and splat instructions (#1347)
If/when Cranelift gains a `load_splat` instruction, the `load + splat` could be replaced with a single Cranelift `load_splat`. This change allows the `simd_load_splat.wast` spec test to pass.
2020-01-21 08:18:52 -08:00
Alex Crichton
1266b68f9a Use is_wasm_parameter in translating wasm calls (#1352)
* Use `is_wasm_parameter` in translating wasm calls

Added in #1329 it's now possible for multiple parameters to be non-wasm
parameters, so the previous `param_types` method is no longer suitable
for acquiring all wasm-related parameters, rather then `FuncEnvironment`
must be consulted. This removes usage of `param_types()` as a method
from the wasm translation and instead adds a custom method inline for
filtering the parameters based on `is_wasm_parameter`.

* Apply feedback

* Run rustfmt

* Don't require `mut`

* Run rustfmt
2020-01-17 12:11:54 -08:00
Dan Gohman
8bec6fe869 Update to wasmparser 0.47. (#1331)
Co-authored-by: Yury Delendik <ydelendik@mozilla.com>
2020-01-10 15:31:37 -08:00
Andrew Brown
c7b0d49550 Fix V128AndNot type mapping (#1319)
Prior to this fix, `type_of` could not determine the Cranelift type for the parameters to `V128AndNot`.
2020-01-10 08:41:11 -08:00
Andrew Brown
46e58fbaaa Bitcasting at control flow exits (#1272)
* Bitcast vectors immediately before a return

* Bitcast vectors immediately before a block end

* Use helper function for bitcasting arguments

* Add FuncTranslationState::peekn_mut; allows mutating of peeked values

* Bitcast values in place, avoiding an allocation

Also, retrieves the correct EBB header types for bitcasting on Operator::End.

* Bitcast values of a function with no explicit Wasm return instruction

* Add Signature::return_types method

This eliminates some duplicate code and avoids extra `use`s of `Vec`.

* Add Signature::param_types method; only collect normal parameters in both this and Signature::return_types

* Move normal_args to Signature::num_normal_params method

This matches the organization of the other Signature::num_*_params methods.

* Bitcast values of Operator::Call and Operator::CallIndirect

* Add DataFlowGraph::ebb_param_types

* Bitcast values of Operator::Br and Operator::BrIf

* Bitcast values of Operator::BrTable
2020-01-06 15:33:22 -08:00
Andrew Brown
b486289ab8 Translate Wasm's V128AndNot to CLIF's band_not (#1297)
The CLIF is already implemented for x86 SIMD.
2019-12-18 13:50:12 -07:00
Andrew Brown
887f897c9a Update wasmparser to 0.45.0 (#1295)
Adds many new operators and a few API changes.
2019-12-17 14:07:11 -06:00
Andrew Brown
af64187ec7 Truncate over-large parameters to splat (#1276)
See https://github.com/WebAssembly/simd/issues/149 for associated discussion on this.
2019-12-12 13:52:26 -08:00
Andrew Brown
396eba5235 Bitcast values incoming to vall_true and vany_true before use in Wasm translation (#1275) 2019-12-09 10:05:47 -08:00
Yury Delendik
2c51341888 Add wasm reference/pointers translation. (#1073) 2019-12-06 17:46:03 -06:00
Ryan Hunt
aabf6559a0 Add hooks for implementing bulk-memory-operations (#1258) 2019-12-06 16:13:53 +01:00
Andrew Brown
f72a5d9caa Translate WASM floating-point abs and neg to CLIF 2019-11-15 13:45:25 -08:00
Projjal Chanda
cd4d7ca0a1 Merged scalar and simd logical operator 2019-11-15 08:56:51 -08:00
Andrew Brown
a2b28f9472 Ensure vectors are bitcast to the correct type
Due to SIMD's v128 operations, vectors that may have had an explicit type (e.g. f32x4) before a v128 operation will subsequently have CLIF's v128 stand-in type: i8x16. In order for follow-on operations (that may be more stricly typed, e.g. f32x4.add) to avoid CLIF errors, we must bitcast them back to the operation type. The raw_bitcast operation used to do this emits no machine code but does incur some small compile-time cost; it would be nice to avoid this in the future.
2019-11-12 17:05:39 -08:00
Andrew Brown
b425ddc52d Translate WASM floating-point arithmetic to CLIF 2019-11-12 17:05:39 -08:00
Andrew Brown
81df93e6a0 Translate WASM float comparisons to CLIF 2019-11-08 14:06:53 -08:00
Andrew Brown
1417215532 Translate WASM integer less-than to CLIF 2019-11-05 16:42:34 -08:00
Andrew Brown
ce67ea5d58 Factor out common translations for SIMD comparisons 2019-11-05 16:42:34 -08:00
Andrew Brown
7715c5e07a Translate WASM integer greater-than to CLIF 2019-11-05 16:42:34 -08:00
Andrew Brown
f053595748 Translate WASM iTxN.gt_s to CLIF 2019-11-05 16:42:34 -08:00
Andrew Brown
3a94e8d46a Translate WASM iTxN.ne to CLIF 2019-11-05 16:42:34 -08:00
Andrew Brown
f8c3dfeb17 Translate WASM iTxN.eq to CLIF 2019-11-05 16:42:34 -08:00
Peter Huene
9f506692c2 Fix clippy warnings.
This commit fixes the current set of (stable) clippy warnings in the repo.
2019-10-24 17:20:12 -07:00
Andrew Brown
77035b44a6 Translate WASM all_true to CLIF 2019-10-22 11:01:05 -07:00
Andrew Brown
65e18df12f Translate WASM any_true to CLIF 2019-10-22 11:01:05 -07:00
Andrew Brown
135f9eb4a6 Translate WASM bitselect to CLIF 2019-10-17 15:49:29 -07:00
Andrew Brown
19a980363e Translate WASM shr to CLIF sshr and ushr
As with shift left, the spec requires that the shift count is computed modulo the lane width (see https://github.com/WebAssembly/simd/blob/master/proposals/simd/SIMD.md#left-shift-by-scalar).
2019-10-15 15:51:50 -07:00
Andrew Brown
808885ce56 Translate WASM shl to CLIF ishl
Note how, according to the spec (see https://github.com/WebAssembly/simd/blob/master/proposals/simd/SIMD.md#left-shift-by-scalar), the shift count is computed modulo the lane width. E.g., a shift count of 17 on an i16x8 should not result in all zeroes as it does with Cranelift's `ishl` and x86's `PSSLW`--it should shift once to the left.
2019-10-15 15:51:50 -07:00
Andrew Brown
67733bd2fc Use ConstantData exclusively for inserting data into the constant pool
Previously we allowed anything that could be converted into ConstantData (e.g. a Vec).
2019-10-15 15:19:00 -07:00
Andrew Brown
a03f905d08 Replace V128Imm functionality with ConstantData
This moves most original uses of V128Imm (e.g. in parsing) to ConstantData and shifts the unit tests from V128Imm to ConstantData.
2019-10-15 15:19:00 -07:00
Nick Fitzgerald
bae0257fc3 cranelift-wasm: Fix reachability tracking for if .. else .. end
We weren't previously keeping track of quite the right information for whether
an `if .. else .. end`'s following block was reachable or not. It should be
reachable if the head is reachable and either the consequent or alternative end
reachable (and therefore fall through to the following block) or do an early
`br_if` to it.

This commit rejiggers `ControlStackFrame::If` to keep track of reachability at
the end of the consequent (we don't need to keep track of it at the end of the
alternative, since that is simply `state.reachable`) and adds Wasm tests for
every reachability situation we can encounter with `if .. else .. end`.

Fixes #1132
2019-10-15 10:37:59 -07:00
Nick Fitzgerald
ca53090f1b cranelift-wasm: Create ModuleTranslationState and polish API a little (#1111)
* cranelift-wasm: replace `WasmTypesMap` with `ModuleTranslationState`

The `ModuleTranslationState` contains information decoded from the Wasm module
that must be referenced during each Wasm function's translation.

This is only for data that is maintained by `cranelift-wasm` itself, as opposed
to being maintained by the embedder. Data that is maintained by the embedder is
represented with `ModuleEnvironment`.

A `ModuleTranslationState` is returned by `translate_module`, and can then be
used when translating functions from that module.

* cranelift-wasm: rename `TranslationState` to `FuncTranslationState`

To disambiguate a bit with the new `ModuleTranslationState`.

* cranelift-wasm: Reorganize the internal `state` module into submodules

One module for the `ModuleTranslationState` and another for the
`FuncTranslationState`.

* cranelift-wasm: replace `FuncTranslator` with methods on `ModuleTranslationState`

`FuncTranslator` was two methods that always took ownership of `self`, so it
didn't really make sense as an object as opposed to two different functions, or
in this case methods on the object that actually persists for a longer time.

I think this improves ergonomics nicely.

Before:

```rust
let module_translation = translate_module(...)?;
for body in func_bodies {
    let mut translator = FuncTranslator::new();
    translator.translate(body, ...)?;
}
```

After:

```rust
let module_translation = translate_module(...)?;
for body in func_bodies {
    module_translation.translate_func(body, ...)?;
}
```

Note that this commit does not remove `FuncTranslator`. It still exists, but is
just a wrapper over the `ModuleTranslationState` methods, and it is marked
deprecated, so that downstream users get a heads up. This should make the
transition easier.

* Revert "cranelift-wasm: replace `FuncTranslator` with methods on `ModuleTranslationState`"

This reverts commit 075f9ae933bcaae39348b61287c8f78a4009340d.
2019-10-11 12:37:17 -07:00
Andrew Brown
b19f804ed5 Convert WASM logical operators to CLIF 2019-10-11 11:05:24 -07:00
Nick Fitzgerald
913d26841a cranelift-wasm: Jump to the destination block at end of consequent
This commit fixes a bug where at the end of an `if..else..end`'s consequent
block, we would sometimes erroneously jump to the `else` block instead of to the
following destination block. Not good!
2019-10-02 17:33:56 -07:00
Nick Fitzgerald
10be3e4ba8 cranelift-wasm: support multi-value Wasm (#1049)
This commit introduces initial support for multi-value Wasm. Wasm blocks and
calls can now take and return an arbitrary number of values.

The encoding for multi-value blocks means that we need to keep the contents of
the "Types" section around when translating function bodies. To do this, we
introduce a `WasmTypesMap` type that maps the type indices to their parameters
and returns, construct it when parsing the "Types" section, and shepherd it
through a bunch of functions and methods when translating function bodies.
2019-10-02 12:40:35 -07:00
Andrew Brown
90c49a2f7c Add saturating subtraction with a SIMD encoding
This includes the new instructions `ssub_sat` and `usub_sat` and only encodes the i8x16 and i16x8 types; these are what is needed for implementing the SIMD spec (see https://github.com/WebAssembly/simd/blob/master/proposals/simd/SIMD.md#saturating-integer-subtraction).
2019-09-30 13:54:30 -07:00
Andrew Brown
21144068d4 Add saturating addition with a SIMD encoding
This includes the new instructions `sadd_sat` and `uadd_sat` and only encodes the i8x16 and i16x8 types; these are what is needed for implementing the SIMD spec (see https://github.com/WebAssembly/simd/blob/master/proposals/simd/SIMD.md#saturating-integer-addition).
2019-09-30 13:54:30 -07:00
Andrew Brown
630cb3ee62 Add x86 encoding for SIMD imul
Only i16x8 and i32x4 are encoded in this commit mainly because i8x16 and i64x2 do not have simple encodings in x86. i64x2 is not required by the SIMD spec and there is discussion (https://github.com/WebAssembly/simd/pull/98#issuecomment-530092217) about removing i8x16.
2019-09-30 13:54:30 -07:00
Andrew Brown
ba393afd4d Add x86 legalization for SIMD ineg 2019-09-30 13:54:30 -07:00
Andrew Brown
ca1df499a0 Add x86 encoding for isub 2019-09-30 13:54:30 -07:00
Andrew Brown
e45ef24d3b Convert SIMD load and store to their respective CLIF instructions 2019-09-27 12:48:30 -07:00
Anthony Ramine
eeb3159fe9 Make wasm_unsupported be composeable 2019-09-23 10:36:03 +02:00
Andrew Brown
766cf8ddfd Add x86 implemention for SIMD iadd 2019-09-19 12:04:14 -07:00
Andrew Brown
af1499ce99 Add x86 implementation of shuffle 2019-09-19 10:53:40 -07:00