309 Commits

Author SHA1 Message Date
Tobias Schwarz
db8e06d3a8 WIP 2023-06-21 20:43:36 +02:00
T0b1
3f379b9d69 WIP 2023-06-15 02:26:17 +02:00
T0b1
c1f2b0f3a3 WIP 2023-06-09 00:35:20 +02:00
Tobias Schwarz
7a7dc20731 find_free_preg 2023-06-06 19:21:16 +02:00
T0b1
9f7d6bb3b4 WIP 2023-05-25 02:30:08 +02:00
Tobias Schwarz
6e6e408a05 WIP 2023-05-24 20:00:52 +02:00
T0b1
b6cccb7ecb WIP 2023-05-23 13:37:23 +02:00
T0b1
8746af2882 more stuff in regs 2023-05-05 23:37:09 +02:00
T0b1
8fb8aa15b0 fixed first reg version 2023-05-05 02:10:23 +02:00
T0b1
b6cc306d7a first steps to keeping stuff in register 2023-04-30 23:10:59 +02:00
T0b1
12e996f7de dont alloc a new stack slot if value dies on edge 2023-04-30 01:31:52 +02:00
T0b1
ef1e46d8ef first try handly cycles/chains (doesnt work) 2023-04-28 01:10:49 +02:00
T0b1
a0404ec851 cur changes 2023-04-18 12:18:44 +02:00
T0b1
a0e2851620 reuse stack slot if variable dies outgoing 2023-04-16 15:09:54 +02:00
T0b1
d9bbbcfbe2 save some work 2023-04-16 14:43:18 +02:00
T0b1
f5f984c81a Revert "try using bitmap instead of indexset"
This reverts commit 84a1e58b97.
2023-04-16 14:24:26 +02:00
T0b1
74873feb96 Revert "try bigger smallvec for vregs"
This reverts commit 75fdc9d3a4.
2023-04-16 14:24:23 +02:00
T0b1
75fdc9d3a4 try bigger smallvec for vregs 2023-04-16 14:10:24 +02:00
T0b1
84a1e58b97 try using bitmap instead of indexset 2023-04-16 13:52:37 +02:00
T0b1
8b724e1796 fix unused Result 2023-04-16 03:24:32 +02:00
T0b1
74f8e9a1fd calc live bitmaps 2023-04-16 03:23:36 +02:00
T0b1
d31dbaaa16 calculate use positions 2023-04-16 02:03:50 +02:00
T0b1
9d1dbadd04 fix stackmaps 2023-04-16 01:17:49 +02:00
T0b1
c4a0d85b72 dont calc cfginfo 2023-04-15 03:11:32 +02:00
T0b1
dcb95541a7 only do clobber string computation if tracing 2023-04-14 19:36:21 +02:00
T0b1
2c8b9a680f change regs_allocated to PRegSet 2023-04-14 19:33:54 +02:00
T0b1
e2061d2e04 first impl 2023-04-14 18:18:15 +02:00
T0b1
993074a974 something 2023-04-13 03:38:59 +02:00
T0b1
706c44513e init 2023-04-12 03:49:50 +02:00
Trevor Elliott
f0e9cde328 Use drain instead of clear (#123) 2023-04-06 14:21:42 -07:00
Johan Milanov
9c6d6dc9aa Slightly more efficient vec initialization (#120)
This will, at least on x86_64, compile down to simpler, shorter assembly that uses a zeroed allocation instead of a regular allocation, a memset and various `raw_vec` methods.
2023-04-03 13:49:36 -07:00
Amanieu d'Antras
2bd03256b3 Make regalloc2 #![no_std] (#119)
* Make regalloc2 `#![no_std]`

This crate doesn't require any features from the standard library, so it
can be made `no_std` to allow it to be used in environments that can't
use the Rust standard library.

This PR mainly performs the following mechanical changes:
- `std::collections` is replaced with `alloc::collections`.
- `std::*` is replaced with `core::*`.
- `Vec`, `vec!`, `format!` and `ToString` are imported when needed since
  they are no longer in the prelude.
- `HashSet` and `HashMap` are taken from the `hashbrown` crate, which is
  the same implementation that the standard library uses.
- `FxHashSet` and `FxHashMap` are typedefs in `lib.rs` that are based on
  the `hashbrown` types.

The only functional change is that `RegAllocError` no longer implements
the `Error` trait since that is not available in `core`.

Dependencies were adjusted to not require `std` and this is tested in CI
by building against the `thumbv6m-none-eabi` target that doesn't have
`std`.

* Add the Error trait impl back under a "std" feature
2023-03-09 11:25:59 -08:00
Amanieu d'Antras
7354cfedde Remove support for program moves (#118) 2023-03-04 16:38:05 -08:00
Amanieu d'Antras
54f074e507 Re-introduce optional dedicated scratch registers (#117)
* Re-introduce optional dedicated scratch registers

Dedicated scratch registers used for resolving move cycles were removed
in #51 and replaced with an algorithm to automatically allocate a
scratch register as needed.

However in many cases, a client will already have a non-allocatable
scratch register available for things like extended jumps (see #91). It
makes sense to re-use this register for regalloc than potentially
spilling an existing register.

* Clarify comment
2023-03-04 14:49:10 -08:00
Trevor Elliott
34a9ae7379 Misc refactorings (#116)
* Use a while-let instead of checking is_empty and popping

* This conditional should always be true, as we expect the input is in ssa

* Use iter_mut instead of iterating the index

* We don't support multiple defs of the same vreg anymore

* Drain instead of clear
2023-02-28 10:42:13 -08:00
Chris Fallin
1e8da4f99b Bump version to 0.6.1. (#115) 2023-02-16 02:06:40 +00:00
Jamey Sharp
7bb83a3361 checker: Use a couple of Rust idioms (#114)
This should have no functional change, just makes the source slightly
easier to read and reason about.
2023-02-16 01:59:20 +00:00
Chris Fallin
c3e513c4cb Fix checker when empty blocks result in unchanged-from-Top entry state. (#113)
The checker works by keeping a worklist of blocks to process, and adds a
block to the worklist when its entry state changes. Every entry state is
initially `Top` (in a lattice). The entry block is explicitly added to
the worklist to kick off the processing.

In ordinary cases, the entry block has some instructions that change
state from `Top` to something else (lower in the lattice), and this is
propagated to its successors; its successors are added to the worklist;
and so on. No other state is `Top` from then on (because of
monotonicity) so every reachable block is processed.

However, if the entry block is completely empty except for the
terminating branch, the state remains `Top`; then the entry state of its
successors, even when updated, is still `Top`; and the state didn't
change so the blocks are not added to the worklist. (Nevermind that they
were not processed in the first place!) The bug is that the invariant
"has been processed already with current state" is not true initially,
when the current state is set to `Top` but nothing has been processed.

This PR makes a simple fix: it adds every block to the worklist
initially to be processed, in input order (which is usually RPO order in
practice) as a good first heuristic; then if after processing the input
state changes again, it can be reprocessed until fixpoint as always.

Fixes bytecodealliance/wasmtime#5791.
2023-02-15 17:42:51 -08:00
Trevor Elliott
50b9cf8fe2 Bump to version 0.6.0 (#112)
Bump the version to 0.6.0 for the next publish to crates.io.

This version removes pinned registers and mod operands, which requires the bump to 0.6.0.
2023-02-07 14:57:22 -08:00
Chris Fallin
376294e828 Fix indent/conditional removal in #108 that removed wrong brace. (#111)
In #108, we had removed a conditional that became constant-false with
the removal of pinned vregs. Unfortunately, in a pretty embarrassing
text-editing error, I removed the wrong end-brace and re-indented. This
had the effect of moving some of the move-resolution code around in the
regalloc backend, skipping moves in some cases and generating incorrect
results.

Caught as a fuzzbug by OSS-Fuzz in [0] (public after this merges and is
detected as fixed).

[0]: https://bugs.chromium.org/p/oss-fuzz/issues/detail?id=55391
2023-01-25 13:20:26 -08:00
Chris Fallin
0edb11d3a7 Remove mod operands. (#109)
* Remove Mod operands.

* Typo fix.
2023-01-24 17:41:46 -08:00
Chris Fallin
e09f6519a6 Remove pinned VRegs. (#108) 2023-01-24 17:31:41 -08:00
Trevor Elliott
e41c6140de Bump to 0.5.1 (#106) 2022-12-06 12:51:08 -08:00
Trevor Elliott
bc398bd19b SSA Validator Fixes (#105)
* Don't check for defs on a use of a fixed-nonallocatable operand

* Add traces to the ssa validator to aid debugging

* Format
2022-11-30 16:31:27 -08:00
Trevor Elliott
346b7f38a3 Bump to 0.5.0 (#104) 2022-11-29 10:03:24 -08:00
Trevor Elliott
7f0d0b98d0 Expose ssa verification as a regalloc2 option (#102)
Adds the validate_ssa flag to the RegallocOptions struct, enabling ssa validation of inputs before register allocation takes place.
2022-11-29 09:30:59 -08:00
Trevor Elliott
25b08c6cff Bump the checkout action to v3 to avoid node12 deprecation (#103) 2022-11-28 17:55:01 -08:00
Trevor Elliott
51561285d3 Add a From<&MachineEnv> impl for PRegSet (#101) 2022-11-09 11:31:56 -08:00
Nick Fitzgerald
b41b1f9a3c Use maximum inline capacity available for SmallVec<VRegIndex> in SpillSet (#100)
* Use maximum inline capacity available for `SmallVec<VRegIndex>` in `SpillSet`

We were using 2, which is the maximum for 32-bit architectures, but on 64-bit
architectures we can get 4 inline elements without growing the size of the
`SmallVec`.

This is a statistically significant speed up, but is so small that our
formatting of floats truncates it (so less than 1%).

```
compilation :: instructions-retired :: benchmarks/bz2/benchmark.wasm

  Δ = 3360297.85 ± 40136.18 (confidence = 99%)

  more-inline-capacity.so is 1.00x to 1.00x faster than main.so!

  [945563401 945906690.73 946043245] main.so
  [942192473 942546392.88 942729104] more-inline-capacity.so

compilation :: instructions-retired :: benchmarks/pulldown-cmark/benchmark.wasm

  Δ = 1780540.13 ± 39362.84 (confidence = 99%)

  more-inline-capacity.so is 1.00x to 1.00x faster than main.so!

  [1544990595 1545359408.41 1545626251] main.so
  [1543269057 1543578868.28 1543851201] more-inline-capacity.so

compilation :: instructions-retired :: benchmarks/spidermonkey/benchmark.wasm

  Δ = 36577153.54 ± 243753.54 (confidence = 99%)

  more-inline-capacity.so is 1.00x to 1.00x faster than main.so!

  [33956158997 33957780594.50 33959538220] main.so
  [33919762415 33921203440.96 33923023358] more-inline-capacity.so
```

* Use a `const fn` to calculate number of inline elements
2022-11-02 12:16:22 -07:00
Nick Fitzgerald
eb0a8fd22f Bump to version 0.4.2 (#99)
* Bump to version 0.4.2

* Remove take-and-replace dance

There are no conflicting borrows of `self` anymore.
2022-11-01 10:30:30 -07:00