Commit Graph

2945 Commits

Author SHA1 Message Date
Erin Power
5426e42a27 Revert "Remove FunctionBuilderContext from API, and change FunctionBuilder API"
This reverts commit 39e638af99dbe6537bc935bfb1a74669b62877b3.
2019-09-17 08:58:46 +02:00
Till Schneidereit
8d62d5f724 Revert "Continuous fuzzing (#944)" (#1036)
This reverts commit 374fd238b06860a1e6e3f8bb9eb598afe91b90fe.
2019-09-17 15:06:37 +09:00
bookmoons
f8d0e6ecab Continuous fuzzing (#944)
Enables automated fuzzing on Fuzzit. Runs fuzz regression tests
every push and PR. Runs full fuzzing every push. Fuzzit emails
if it finds crashes.

Uses the existing fuzz targets:
* translate-module - Fuzz valid WebAssembly modules.
* reader-parse - Fuzz IR text format parsing.
2019-09-17 14:12:31 +09:00
Andy Wortman
99380fad1a Use 'xor r, r' to set registers to 0 instead of mov (#766) 2019-09-16 16:35:55 +02:00
julian-seward1
b95508c51a legalizer/split.rs: split_ebb_params: avoid pointless Vec allocations. (#1025)
This function is responsible for 2.2% of all heap allocation (calls) in CL.
This change avoids all of them in the (presumably) common case where none of
the parameters require splitting.  It also slightly reduces the compiler's
instruction count.
2019-09-16 15:01:07 +02:00
Wander Lairson Costa
a51606bfeb [frontend] Add message for pristine assertion violation
After we add any instruction to an EBB, we can't add EBB parameters
anymore. There is an assertion in `append_ebb_param` to detect this
error, but the backtrace generated doesn't give any hint what happened.

We add an error message to the assertion so the user can understand what
is wrong.

fixes #1003
2019-09-16 14:55:19 +02:00
Rett Berg
4aef679243 fix reflink in CONTRIBUTING.md 2019-09-16 10:45:51 +02:00
Ujjwal Sharma
3418fb6e18 [codegen] reintroduce support for carry and borrow instructions in RI… (#1005)
Reintroduce support for iadd carry variants and isub borrow variants for
RISC ISAs which had been removed in
https://github.com/CraneStation/cranelift/pull/961 and
https://github.com/CraneStation/cranelift/pull/962 because of the lack
of a proper flags register in RISC architectures.
2019-09-13 17:27:49 +02:00
Andrew Brown
cadd0ac655 Remove unused import when cross-compiling, fixes #1022 2019-09-12 09:28:39 -07:00
julian-seward1
92a01c816d Minor speedup tuning for SecondaryMap (#1020)
The `SecondaryMap` abstraction -- basically, resize-on-demand arrays with a
default value -- is very hot in Cranelift.  This small patch is the result of
many profiling runs.  It makes two changes:

* `fn index_mut` is changed to be `#[inline(always)]`, based on profile data.

* `fn index` and `fn index_mut` call `self.elems.resize()` directly, rather
  than via `self.resize()`.  The point of this is not to improve performance.
  Rather, it ensures that the public functions for `SecondaryMap` do not call
  each other.  When public interface functions call each other, it becomes
  difficult to interpret profiling results, because it's harder to see what
  fraction of costs for `SecondaryMap` as a whole come from outside the
  module, and what fraction is the result of "internal" calls to the external
  interface.

The overall result, for wasm_lua_binarytrees, is a 1.4% reduction in
instruction count for the compiler, and a 2.2% reduction in loads/stores.
2019-09-12 11:09:35 +02:00
Nicolas B. Pierron
e8dc9ad8c9 Fix x86/br-i128 test case to use basic blocks. 2019-09-11 20:24:48 +02:00
Wander Lairson Costa
35c6d869f5 Replace region::protect by make_exec in cranelift-filetests 2019-09-10 18:53:02 -07:00
Nicolas B. Pierron
abb157315b Basic Blocks: Fix frontend::sample_function test case. (#1007) 2019-09-10 15:02:11 -06:00
Benjamin Bouvier
cad2074587 [codegen] Don't simplify an operation if it would result in unnecessary legalization;
Converting something like iadd.i64 on a 32-bits architecture into a
iadd_imm.i64 will result in the instruction being legalized back to an
iadd.i64 later on, creating unnecessary churn.

This commit implements avoid doing so, and changes the target ISA to a
64-bits platform for tests than ran into this, as well as making sure
this won't happen on 32-bits platforms.
2019-09-10 19:50:34 +02:00
Benjamin Bouvier
3aa76b558c Legalize i64.const by breaking it into two i32.const, on 32-bits platforms; 2019-09-10 19:50:34 +02:00
Andrew Brown
6f1ed94e82 Fix documentation 2019-09-10 10:45:12 -07:00
Andrew Brown
295b2ef614 Avoid extra register movement when lowering an x86 insertlane to a float vector 2019-09-10 10:45:12 -07:00
Andrew Brown
3dfc68afb1 Avoid extra register movement when lowering the x86 scalar_to_vector of a float value 2019-09-10 10:45:12 -07:00
Andrew Brown
00bedca274 Avoid extra register movement when lowering the x86 extractlane of a float vector
This commit is based on the assumption that floats are already stored in XMM registers in x86. When extracting a lane, cranelift was moving the float to a regular register and back to an XMM register; this change avoids this by shuffling the float value to the lowest bits of the XMM register. It also assumes that the upper bits can be left as is (instead of zeroing them out).
2019-09-10 10:45:12 -07:00
Andrew Brown
f1363168a9 Translate the sign-extended and zero-extended versions of extract_lane 2019-09-10 10:45:12 -07:00
Andrew Brown
ebc783e49b Use raw_bitcast when legalizing splat
raw_bitcast matches the intent of this legalization more clearly (to simply change the CLIF type without changing any bits) and the additional null encodings added are necessary for later instructions
2019-09-10 10:45:12 -07:00
Andrew Brown
8a6686ec45 Enable SSSE3 setting when detected on CPU 2019-09-10 10:45:12 -07:00
Andrew Brown
7f152611a4 Log compiled and legalized functions 2019-09-10 10:45:12 -07:00
Sean Stangl
4b085b9cf7 Avoid unnecessary reallocations in domtree::with_function() (#1011) 2019-09-10 08:18:06 -06:00
julian-seward1
63367d205c Fix #975 (Structure of cranelift-wasm/src/translation_utils.rs causes many pointless heap allocations) (#1010)
This patch restricts the `Err(..)` return from `blocktype_to_type` to be
`Err(..)` only in the case where it really is an error to continue.  The three
use points of `blocktype_to_type` are changed to check for an `Err(..)` rather
than silently ignoring it.  There are also cosmetic changes to `type_to_type`
and `tabletype_to_type`.

When compiling wasm_lua_binarytrees, this reduces the number of blocks
allocated by CL by 1.9%.  Instruction count falls by 0.1%.

Details:

* `type_to_type` and `tabletype_to_type`:

   - Added the function name in the failure message

   - No functional change for non-error cases

   - Push the `Ok(..)` to expression leaves, where it really applies.  This
     corrects the misleading impression that, in the case of an unsupported
     type, the function returns `Ok` wrapped around whatever
     `wasm_unsupported` returns.  It doesn't do that, but it certainly reads
     like that.  This assumes that the LLVM backend will do tail merging, so
     the generated code will be unchanged.

* `blocktype_to_type`:

  - Change return type from `WasmResult<ir::Type>` to `WasmResult<Option<ir::Type>>`

  - Manually inline the call to `type_to_type`, to make this function easier
    to read.

  - For the non-error case: map `TypeOrFuncType::Type(Type::EmptyBlockType)`
    to `Ok(None)` rather than `Err(..)`, since that's what all the call sites
    expect - For the error cases, add the function name in the failure
    messages

* cranelift-wasm/src/code_translator.rs

  - For the three uses of `blocktype_to_type`, use `?` to detect failures and
    drop out immediately, meaning that the code will no longer silently ignore
    errors.
2019-09-10 15:06:10 +02:00
Nicolas B. Pierron
81fa5e7696 Add equivalent safepoint test cases for basic blocks. 2019-09-10 14:53:13 +02:00
Ujjwal Sharma
345b2dc0cc [codegen] add new recipe "rout" (#1014)
* [codegen] add new recipe "rout"

Add a new recipe "rout" intended to be used by arithematic operations
that output flags, currently being used for `iadd_cout` and `isub_bout`.

Fixes: https://github.com/CraneStation/cranelift/issues/1009
2019-09-10 12:55:24 +02:00
data-pup
ac2ca6116b allow module environment to parse name section 2019-09-10 11:30:54 +02:00
Philip Craig
3293ca6b69 Add cranelift-object 2019-09-09 21:54:20 -07:00
Nicolas B. Pierron
90b0b86f5c Simplify isa_builder macro 2019-09-09 13:30:02 +02:00
Julian Seward
d2443a75f3 legalizer/split.rs: simplify_branch_arguments: use SmallVec instead of Vec
This function is responsible for 8.5% of all heap allocation (calls) in CL.
This change avoids almost all of them by using a SmallVec::<[Value; 32]>
instead.  Dynamic instruction count falls by 0.25%.  The fixed size of 32 was
arrived at after profiling with fixed sizes of 1, 2, 4, 8, 16, 32, 64 and 128.
32 is as high as I can push it without the instruction count starting to creep
up again, and gets almost all the block-reduction win of 64 and 128.
2019-09-09 12:58:21 +02:00
Julian Seward
c6a4c60a0f EbbHeaderBlockData::predecessors: use SmallVec instead of Vec
Allocations associated with pushes to EbbHeaderBlockData::predecessors account
for 4.9% of all heap allocation (calls) in CL.  This change avoids almost all
of them by changing it to be a SmallVec<[PredBlock; 4]>.  Dynamic instruction
count falls by 0.15%.
2019-09-09 11:37:04 +02:00
Julian Seward
955cdd5f83 VirtRegs::find: use SmallVec instead of Vec for val_stack.
Pushing on the `val_stack` vector is CL's biggest source of calls to
malloc/realloc/free, by some margin.  It accounts for about 27.7% of all heap
blocks allocated when compiling wasm_lua_binarytrees.  This change removes
pretty much all dynamic allocation by changing to a SmallVec<[Value; 8]>
instead.  A fixed size of 4 gets all the gains to be had, in testing, so 8
gives some safety margin and is harmless from a stack-use perspective: 8
Values will occupy 32 bytes.

As a bonus, this change also reduces the compiler's dynamic instruction count
by about 0.5%.
2019-09-09 11:30:59 +02:00
Alex Crichton
705bfacf10 rustfmt 2019-09-07 16:20:23 -07:00
Alex Crichton
dfda794f55 Add a custom section hook to ModuleEnvironment
This commit adds a hook to the `ModuleEnvironment` trait to learn when a
custom section in a wasm file is read. This hook can in theory be used
to parse and handle custom sections as they appear in the wasm file
without having to re-iterate over the wasm file after cranelift has
already parsed the wasm file.

The `translate_module` function is now less strict in that it doesn't
require sections to be in a particular order, but it's figured that the
wasm file is already validated elsewhere to verify the section order.
2019-09-07 16:20:23 -07:00
Aaron Power
8fd1128990 Remove FunctionBuilderContext from API, and change FunctionBuilder API 2019-09-07 14:43:07 -07:00
bjorn3
0273eb84e0 Fix rebase 2019-09-07 09:55:09 -07:00
bjorn3
e8d4ef7c3d Fix review comments 2019-09-07 09:55:09 -07:00
bjorn3
e2b2b520eb Fix compilation 2019-09-07 09:55:09 -07:00
bjorn3
f4cdd3007c [split] Prevent double legalization of isplit and vsplit 2019-09-07 09:55:09 -07:00
bjorn3
2426bce9ac Fix load.i64 and store legalization 2019-09-07 09:55:09 -07:00
bjorn3
ffa1e946a7 Fix compilation 2019-09-07 09:55:09 -07:00
bjorn3
acd454890c Legalize load.i128 and store.i128 with arbitrary offsets 2019-09-07 09:55:09 -07:00
bjorn3
67593d997b Add b128 type to fix tests 2019-09-07 09:55:09 -07:00
bjorn3
fa9602df80 Legalize load.i128 and store.i128 2019-09-07 09:55:09 -07:00
bjorn3
3ae78fddde Fix warnings 2019-09-07 09:55:09 -07:00
bjorn3
dce521fa1c Fix lone isplit, when the corresponding iconcat will be created later during legalization 2019-09-07 09:55:09 -07:00
bjorn3
0d5b87038a Rustfmt 2019-09-07 09:55:09 -07:00
bjorn3
599b48d95f Narrowing legalize some more bitops 2019-09-07 09:55:09 -07:00
bjorn3
c7a8b6c9e5 Remove some dbg! invocations 2019-09-07 09:55:09 -07:00