Commit Graph

7191 Commits

Author SHA1 Message Date
Andrew Brown
6ebbab61b9 Update cfg-if dependency 2020-10-23 16:50:51 -07:00
Yury Delendik
de4af90af6 machinst x64: New backend unwind (#2266)
Addresses unwind for experimental x64 backend. The preliminary code enables backtrace on SystemV call convension.
2020-10-23 15:19:41 -05:00
Julian Seward
2702942050 CL/aarch64 back end: implement the wasm SIMD bitmask instructions
The `bitmask.{8x16,16x8,32x4}` instructions do not map neatly to any single
AArch64 SIMD instruction, and instead need a sequence of around ten
instructions.  Because of this, this patch is somewhat longer and more complex
than it would be for (eg) x64.

Main changes are:

* the relevant testsuite test (`simd_boolean.wast`) has been enabled on aarch64.

* at the CLIF level, add a new instruction `vhigh_bits`, into which these wasm
  instructions are to be translated.

* in the wasm->CLIF translation (code_translator.rs), translate into
  `vhigh_bits`.  This is straightforward.

* in the CLIF->AArch64 translation (lower_inst.rs), translate `vhigh_bits`
  into equivalent sequences of AArch64 instructions.  There is a different
  sequence for each of the `{8x16, 16x8, 32x4}` variants.

All other changes are AArch64-specific, and add instruction definitions needed
by the previous step:

* Add two new families of AArch64 instructions: `VecShiftImm` (vector shift by
  immediate) and `VecExtract` (effectively a double-length vector shift)

* To the existing AArch64 family `VecRRR`, add a `zip1` variant.  To the
  `VecLanesOp` family add an `addv` variant.

* Add supporting code for the above changes to AArch64 instructions:
  - getting the register uses (`aarch64_get_regs`)
  - mapping the registers (`aarch64_map_regs`)
  - printing instructions
  - emitting instructions (`impl MachInstEmit for Inst`).  The handling of
    `VecShiftImm` is a bit complex.
  - emission tests for new instructions and variants.
2020-10-23 05:26:25 +02:00
Yury Delendik
b10e027fef Refactor UnwindInfo codes and frame_register (#2307)
* Refactor UnwindInfo codes and frame_register

* use isa word_size

* fix filetests

* Add comment about UnwindCode::PushRegister
2020-10-22 14:52:42 -05:00
Nick Fitzgerald
4f104d3a4e CI: fix rebuilding peepmatic peephole optimizers (#2311)
The test that triggers the rebuild of the peephole optimizers is in the
`cranelift-codegen` crate, not the umbrella cranelift crate. This was previously
successfully running zero tests, and then successfully reporting no `git diff`
because no peephole optimizers were ever rebuilt.

This change fixes it so that we run the correct test that triggers the
rebuilding of the peephole optimizers.
2020-10-22 12:39:40 -05:00
Nick Fitzgerald
c5a2bd3215 Merge pull request #2298 from EmbarkStudios/directories-next2
Replace unmaintained directories crate - RUSTSEC-2020-0054
2020-10-21 15:16:57 -07:00
Nick Fitzgerald
1532834f3e Merge pull request #2305 from alexcrichton/no-arc
Don't store `Arc<VMInterrupts>` in instances
2020-10-21 13:21:51 -07:00
Nick Fitzgerald
aa04917ddf Merge pull request #2306 from alexcrichton/no-finished-functions
Remove the `finished_functions` field in `Instance`
2020-10-21 13:21:04 -07:00
Alex Crichton
461ed42772 Remove the finished_functions field in Instance
Turns out we don't actually need it anywhere any more! This removes an
allocation when instantiating.
2020-10-21 11:43:11 -07:00
Alex Crichton
04e85b044e Don't store Arc<VMInterrupts> in instances
Similar to other data structures owned by the `Store` there's no need
for `Instance` to have a strong `Arc` reference, instead it's sufficient
for `Store` to have the owning reference.
2020-10-21 11:42:57 -07:00
Julian Seward
ab65d8f10c wasm->CLIF translation: consistently bitcast V128 values that are block formal parameters.
In the current translation of wasm (128-bit) SIMD into CLIF, we work around differences in the
type system models of wasm vs CLIF by inserting `bitcast` (a no-op cast) CLIF instructions before
more or less every use of a SIMD value.  Unfortunately this was not being done consistently and
even small examples with a single if-then-else diamond that produces a SIMD value, could cause a
verification failure downstream.  In this case, the jump out of the "else" block needed a
bitcast, but didn't have one.

This patch wraps creation of CLIF jumps and conditional branches up into three functions,
`canonicalise_then_jump` and `canonicalise_then_br{z,nz}`, and uses them consistently.  They
first cast the relevant block formal parameters, then generate the relevant kind of branch/jump.
Hence, provided they are also used consistently in future to generate branches/jumps in this
file, we are protected against such failures.

The patch also adds a large(ish) comment at the top explaining this in more detail.
2020-10-21 17:43:49 +02:00
Nick Fitzgerald
76998f0404 Merge pull request #2300 from alexcrichton/no-allocate-isa
Don't allocate a new ISA for each `Func::wrap`
2020-10-18 13:36:29 -07:00
Nick Fitzgerald
1a0a2bc259 Merge pull request #2301 from alexcrichton/no-name-alloc
Avoid allocations in trampoline shims
2020-10-18 13:34:08 -07:00
Alex Crichton
b8794448b0 Avoid allocations in trampoline shims
There's no need to name each export since each synthetic instance we're
creating only has one export, so let's use the empty string which
doesn't require any allocations.
2020-10-18 11:54:52 -07:00
Johan Andersson
9820c5c3dd Replace unmaintained directories crate
Fixes RUSTSEC-2020-0054 warning from cargo-audit/cargo-deny, follows the recommendation to switch to the new maintained `directories-next` crate fork

Only affects the cache directory determination for the environment and was a simple search'n'replace to this fork so don't think behavior has changed.

https://rustsec.org/advisories/RUSTSEC-2020-0054
2020-10-17 13:08:59 +02:00
Johnnie Birch
f27c0f3434 Adds support for signed packed integer conversion to float
f32x4.convert_i32x4_s
2020-10-16 14:16:53 -07:00
Alex Crichton
4a82f17d91 Don't allocate a new ISA for each Func::wrap
Instead we can reuse the existing one in `Store`.
2020-10-16 08:21:32 -07:00
Nick Fitzgerald
2dad74f9d0 Merge pull request #2292 from abrown/fix-typo
Fix typo
2020-10-15 16:13:15 -07:00
Andrew Brown
f36ceac010 Fix typo 2020-10-15 11:31:04 -07:00
Yury Delendik
3c68845813 Cranelift: refactoring of unwind info (#2289)
* factor common code

* move fde/unwind emit to more abstract level

* code_len -> function_size

* speedup block scanning

* better function_size calciulation

* Rename UnwindCode enums
2020-10-15 08:34:50 -05:00
Alex Crichton
e659d5cecd Add initial support for the multi-memory proposal (#2263)
This commit adds initial (gated) support for the multi-memory wasm
proposal. This was actually quite easy since almost all of wasmtime
already expected multi-memory to be implemented one day. The only real
substantive change is the `memory.copy` intrinsic changes, which now
accounts for the source/destination memories possibly being different.
2020-10-13 19:13:52 -05:00
Nick Fitzgerald
c2d01fe56f Merge pull request #2257 from fitzgen/peepmatic-no-paths-in-linear-ir
Peepmatic: Do not use paths in linear IR
2020-10-13 12:18:26 -07:00
Nick Fitzgerald
122c67d90a peepmatic: Update example automata image
The linear IR that the automata uses has changed, so the image needs to be
updated to reflect that.
2020-10-13 11:03:48 -07:00
Nick Fitzgerald
c015d69eb8 peepmatic: Do not use paths in linear IR
Rather than using paths from the root instruction to the instruction we are
matching against or checking if it is constant or whatever, use temporary
variables. When we successfully match an instruction's opcode, we simultaneously
define these temporaries for the instruction's operands. This is similar to how
open-coding these matches in Rust would use `match` expressions with pattern
matching to bind the operands to variables at the same time.

This saves about 1.8% of instructions retired when Peepmatic is enabled.
2020-10-13 11:03:48 -07:00
Nick Fitzgerald
4fd90dccab Merge pull request #2284 from alexcrichton/fix-interrupts
Fix enabling interrupts in fuzzers
2020-10-09 13:11:52 -07:00
Alex Crichton
cdf158cd50 Fix enabling interrupts in fuzzers
Modifying the `Config` after the gneine has been created has no effect,
so be sure to flag the configuration as interruptible earlier.
2020-10-09 10:09:27 -07:00
Andrew Brown
0ba35171fb [machinst x64]: port more CLIF filetests 2020-10-09 10:04:50 -07:00
Andrew Brown
d5d84e2ec3 [machinst x64]: enable simd_bitwise.wast 2020-10-09 10:04:50 -07:00
Andrew Brown
1799b0947f [machinst x64]: implement packed bitselect 2020-10-09 10:04:50 -07:00
Andrew Brown
95f0e96e62 [machinst x64]: implement packed not
This begins to use `Inst` helper functions as discussed in #2252.
2020-10-09 10:04:50 -07:00
Andrew Brown
3c55523d40 [machinst x64]: implement packed and, and_not, xor, or 2020-10-09 10:04:50 -07:00
Benjamin Bouvier
e8c2a1763a machinst x64: avoid emitting movzx when the input is an ALU 32-bits operation; 2020-10-09 18:49:27 +02:00
Benjamin Bouvier
3980a43cda machinst x64: use the (base,offset) addressing mode even in the presence of a uextend; 2020-10-09 18:49:27 +02:00
Pat Hickey
88d975d396 Merge pull request #2249 from bjorn3/module_rework
Rework the interface of cranelift-module
2020-10-08 09:52:30 -07:00
Andrew Brown
c8cce5d2d7 [machinst x64]: enable packed saturated arithmetic 2020-10-08 08:46:20 -07:00
Benjamin Bouvier
116acb8dcd machinst x64: emit nop of variable sizes; 2020-10-08 10:05:57 +02:00
Benjamin Bouvier
a470f1e0cd machinst x64: remove dead code and allow(dead_code) annotation;
The BranchTarget is always used as a label, so just use a plain
MachLabel in this case.
2020-10-08 10:05:57 +02:00
Benjamin Bouvier
e32e6fb612 machinst x64: check SSE requirements for instructions against enabled features; 2020-10-08 09:21:51 +02:00
Benjamin Bouvier
c5bbc87498 machinst: allow passing constant information to the instruction emitter;
A new associated type Info is added to MachInstEmit, which is the
immutable counterpart to State. It can't easily be constructed from an
ABICallee, since it would require adding an associated type to the
latter, and making so leaks the associated type in a lot of places in
the code base and makes the code harder to read. Instead, the EmitInfo
state can simply be passed to the `Vcode::emit` function directly.
2020-10-08 09:21:51 +02:00
Pat Hickey
13c6bdd9ba cranelift-module: add iterator methods to ModuleDeclarations
The predecessor interface made it possible to iterate across all
function and data declarations. This is still useful and easy enough to
provide.
2020-10-07 20:06:58 -07:00
Andrew Brown
3778fa025c Switch DataValue to use Ieee32/Ieee64
As discussed in #2251, in order to be very confident that NaN signaling bits are correctly handled by the compiler, this switches `DataValue` to use Cranelift's `Ieee32` and `Ieee64` structures. This makes it a bit more inconvenient to interpreter Cranelift FP operations but this should change to something like `rustc_apfloat` in the future.
2020-10-07 12:17:17 -07:00
Andrew Brown
ce44719e1f refactor: change LowerCtx::get_immediate to return a DataValue
This change abstracts away (from the perspective of the new backend) how immediate values are stored in InstructionData. It gathers large immediates from necessary places (e.g. constant pool) and delegates to `InstructionData::imm_value` for the rest. This refactor only touches original users of `LowerCtx::get_immediate` but a future change could do the same for any place the new backend is accessing InstructionData directly to retrieve immediates.
2020-10-07 12:17:17 -07:00
Andrew Brown
3a2025fdc7 Add InstructionData::imm_value() 2020-10-07 12:17:17 -07:00
Andrew Brown
6f6f79ef2b refactor: move DataValue from cranelift-reader to cranelift-codegen
This is no change to functionality; the move is necessary in order to return InstructionData immediates in a structure way (see next commit).
2020-10-07 12:17:17 -07:00
Gabor Greif
387afc805e debug: Normalise value prior to right shifts (#2276)
* normalise value prior to right shifts

by first left-aligning (shift left by 32 bits)
then shifting back (respecting signedness)

* Update crates/debug/src/transform/expression.rs

Co-authored-by: bjorn3 <bjorn3@users.noreply.github.com>

* Update crates/debug/src/transform/expression.rs

* Update crates/debug/src/transform/expression.rs

* update translation of DW_OP_shr in test

* add translation test for DW_OP_shra

* explain normalisation

* optimise the expression by performing only one right shift

We assume that the expression evaluator permits collapsing
two shifts as long as they go in the same direction.

Review feedback.

Co-authored-by: bjorn3 <bjorn3@users.noreply.github.com>
2020-10-07 12:42:20 -05:00
subtly
d91f0c3933 get pc for freebsd (#2270)
* get pc for freebsd

* whitespace :|

* fix; i386 to x86

* remove x86 since uc_mcontext isn't yet in libc

* freebsd build of rust uses libcc/unwind
2020-10-07 06:30:14 -05:00
Benjamin Bouvier
84ac3feef8 machinst x64: use zero-latency move instructions for f32/f64;
As found by @julian-seward1, movss/movsd aren't included in the
zero-latency move instructions section of the Intel optimization manual.
Use MOVAPS instead for those moves.
2020-10-07 10:55:44 +02:00
Chris Fallin
fc430eef76 Merge pull request #2267 from cfallin/fix-aarch64-abi
Fix AArch64 ABI to respect half-caller-save, half-callee-save vec regs.
2020-10-06 15:42:51 -07:00
Chris Fallin
71768bb6cf Fix AArch64 ABI to respect half-caller-save, half-callee-save vec regs.
This PR updates the AArch64 ABI implementation so that it (i) properly
respects that v8-v15 inclusive have callee-save lower halves, and
caller-save upper halves, by conservatively approximating (to full
registers) in the appropriate directions when generating prologue
caller-saves and when informing the regalloc of clobbered regs across
callsites.

In order to prevent saving all of these vector registers in the prologue
of every non-leaf function due to the above approximation, this also
makes use of a new regalloc.rs feature to exclude call instructions'
writes from the clobber set returned by register allocation. This is
safe whenever the caller and callee have the same ABI (because anything
the callee could clobber, the caller is allowed to clobber as well
without saving it in the prologue).

Fixes #2254.
2020-10-06 14:44:02 -07:00
Alex Crichton
e22e2c3722 Update Github Actions CI set-env/add-path (#2265)
In accordance with [this
advisory](https://github.blog/changelog/2020-10-01-github-actions-deprecating-set-env-and-add-path-commands/)
it's recommended we moved to a different scheme of setting env vars and
updating PATH.
2020-10-05 15:08:56 -05:00