Commit Graph

178 Commits

Author SHA1 Message Date
Chris Fallin
822f2bc937 Merge pull request #18 from Amanieu/blockparam
Rework the API for outgoing blockparams
2021-12-01 10:24:12 -08:00
Amanieu d'Antras
6621a57cb7 Fix liveranges for branch parameters 2021-12-01 01:43:20 +00:00
Amanieu d'Antras
0cb3a8019f Rework the API for outgoing blockparams 2021-12-01 01:43:20 +00:00
Chris Fallin
fdd9913a7a Merge pull request #20 from cfallin/fuzzbug-fix
Fix fuzzbug related to bundle priority ordering.
2021-11-30 15:45:35 -08:00
Chris Fallin
c53fbb4a5c Fix fuzzbug related to bundle priority ordering.
Changes in computation of bundle priorities during review of the initial
PR introduced a possible mis-ordering of priorities: inner-loop bundle
use weights could exceed the weights of 1_000_000 and 2_000_000 used for
minimal bundles without and with fixed uses (respectively). These two
kinds of minimal bundle are meant to be the highest-priority bundles,
evicting any other bundle they need to, because they can't be split
further. This PR introduces two special bundle weights for these two
kinds of bundles, and clamps all other bundle weights to just below
them.

Thanks to @Amanieu for reporting the issue! Fixes #19.
2021-11-30 15:36:12 -08:00
Chris Fallin
c7bc6c941c Merge pull request #15 from cfallin/relicensing
Relicense fully to Apache-2.0 WITH LLVM-exception.
2021-11-18 12:40:54 -08:00
Chris Fallin
9774e97939 Merge pull request #16 from Amanieu/misc
Various fixes & minor improvements
2021-11-15 17:50:47 -08:00
Amanieu d'Antras
a516e6d6f3 Return safepoint_slots as Allocations instead of SpillSlots
This enables us to support reftype vregs in register locations in the
future.
2021-11-16 00:47:43 +00:00
Amanieu d'Antras
a527a6d25a Remove unused clobbers vector 2021-11-16 00:46:05 +00:00
Chris Fallin
cf0d515709 Relicense fully to Apache-2.0 WITH LLVM-exception.
Large parts of the code in regalloc2 are currently licensed under the
Mozilla Public License (MPL) 2.0, because they derive in meaningful
ways from the register allocator in IonMonkey, which is part of
Firefox. The relevant source files are marked as such, with references
to the files in the Firefox source tree.

The intent of the regalloc2 project was to port the register allocator
from Firefox to use in Cranelift, borrowing good technology and
improving on it in the spirit of open source.

However, Several use-cases of Cranelift require, or at least strongly
prefer, the Apache-2.0 license with the LLVM exception (matching the
license of Cranelift itself, and Bytecode Alliance projects
generally). While using this license is not strictly necessary for
regalloc2 to be usable (The MPL is an excellent open-source license!),
relicensing fully under this license to harmonize with the rest of
Cranelift and Bytecode Alliance codebases significantly widens
possibilities and reduces friction; then regalloc2 is "just another
part of Cranelift" and doesn't have to be treated specially.

The source in `src/ion/` specifically began as a fairly direct port of
the algorithms in the following files in the `mozilla-central`
repository (Firefox codebase):

* The bulk of the "backtracking allocator" algorithm:
  * `js/src/jit/BacktrackingAllocator.{cpp,h}`
* Helpers and definitions in the surrounding infrastructure:
  * `js/src/jit/RegisterAllocator.h`
  * `js/src/jit/RegisterAllocator.cpp`
  * `js/src/jit/StackSlotAllocator.h`
  * `js/src/jit/LIR.h`
* A few data structure implementations:
  * `js/src/ds/SplayTree.h`
  * `js/src/ds/PriorityQueue.h`

Subsequent work in improving regalloc2 has caused it to drift from the
direct port -- for example, it no longer uses splay trees or the
direct port of the priority queue above -- but it is of course very
clearly still a derivative work.

Analysis of the contributors to these files indicates that we need
signoff from the following folks:

* Mozilla Corp, for contributions made by Mozilla employees (the
  majority of the code). Communications with Mozilla (thanks
  @tschneidereit and @bholley for doing the work here!) indicate that
  @ekr is able to sign off when ready here.

* Andy Wingo, specifically for the work done in [Bug
  1620197](https://bugzilla.mozilla.org/show_bug.cgi?id=1620197) and
  [Bug 1609057](https://bugzilla.mozilla.org/show_bug.cgi?id=1609057) to
  generalize the stack allocator for a Wasm feature (multiple returns).

Additionally, since the initial port, we have had three contributions
from @Amanieu:
[#9](https://github.com/bytecodealliance/regalloc2/pull/9),
[#11](https://github.com/bytecodealliance/regalloc2/pull/11),
[#13](https://github.com/bytecodealliance/regalloc2/pull/13).

So, if everyone applicable is happy with this relicensing, this PR
removes the MPL-2.0 license in `src/ion/` and marks all files as
covered under `Apache-2.0 WITH LLVM-exception`. Please let us know if
this is OK!

Signoffs:

- [ ] @ekr, for Mozilla's contributions
- [ ] @wingo, for contributions to original code in `mozilla-central`
- [ ] @Amanieu, for the three PRs linked above

Thanks!
2021-11-10 10:54:28 -08:00
Amanieu d'Antras
358c831b31 Remove regs from MachineEnv
It isn't exactly clear what purpose it serves.
2021-09-19 16:40:27 +01:00
Amanieu d'Antras
af527aca88 Fix PReg indexing with >32 pregs 2021-09-19 16:39:56 +01:00
Chris Fallin
44612690dc Merge pull request #13 from Amanieu/operand_encoding
Adjust Operand encoding
2021-09-14 08:56:07 -07:00
Amanieu d'Antras
9e2ab3d5f7 Address review feedback 2021-09-14 13:12:52 +01:00
Amanieu d'Antras
35ed2109b1 Adjust Operand encoding
The encoding for OperandConstraint is adjusted to free up 2 bits which
allows for 2^21 vregs and 2^6 pregs.
2021-09-13 08:33:17 +01:00
Chris Fallin
ef2c9b3f26 Merge pull request #11 from Amanieu/requirement
Simplify Requirement by removing register classes
2021-09-09 10:37:17 -07:00
Chris Fallin
c56e695ff7 Merge pull request #9 from Amanieu/remove_is_call
Remove Function::is_call
2021-09-09 10:36:58 -07:00
Amanieu d'Antras
448f210e32 Simplify Requirement by removing register classes
We never merge bundles from vregs of different classes, so we don't
need to check for register class conflicts.
2021-09-09 11:16:19 +01:00
Amanieu d'Antras
a243c4e575 Remove Function::is_call
The documentation says that this is only used for heuristics, but it
is never actually called. This should be removed for now and perhaps
added back later if we find an actual use for it.
2021-09-09 11:16:11 +01:00
Chris Fallin
7724dc6f5a Merge pull request #10 from cfallin/cargo-deny-config
Add cargo-deny config.
2021-09-06 20:01:12 -07:00
Chris Fallin
8191d6cbcf Add cargo-deny config.
This was excluded by mistake in #1; without a configuration, cargo-deny
runs with a default one, and rejects a lot of things (largely due to
open-source-but-not-allowlisted licenses).

This `deny.toml` comes from the regalloc.rs repo. It results in one
warning currently that will be resolved once #7 is.
2021-09-03 09:04:20 -07:00
Chris Fallin
57ccaefa04 Merge pull request #1 from cfallin/initial-regalloc
Initial implementation of regalloc2.
2021-08-31 18:19:59 -07:00
Chris Fallin
6f0893d69d Address review comments. 2021-08-31 17:56:06 -07:00
Chris Fallin
6389071e09 Address review comments. 2021-08-31 17:42:50 -07:00
Chris Fallin
b19fa4857f Rename operand positions to Early and Late, and make weights f16/f32 values. 2021-08-31 17:31:23 -07:00
Chris Fallin
3a18564e98 Addressed more review comments. 2021-08-30 17:51:55 -07:00
Chris Fallin
6d313f2b56 Address review comments: more doc comments and some minor refactorings. 2021-08-30 17:15:37 -07:00
Chris Fallin
e10bffbca8 Fix bug in refactored BitVec (found by @Amanieu). 2021-08-14 13:40:43 -07:00
Chris Fallin
69ad31f013 Replace remaining instances of use of debug feature with debug_assertions.
Also fix some code that did not build in debug mode anymore (d'oh!) in
`src/ion/merges.rs`, as exposed by this change.
2021-08-12 17:35:55 -07:00
Chris Fallin
8ed83e3a57 Fix BitVec::get_or_insert to scan only once. 2021-08-12 15:40:34 -07:00
Chris Fallin
f1a989f1b7 Add malloc/free optimization to TODO 2021-08-12 14:53:53 -07:00
Chris Fallin
ffc06b2099 Debug output for Operands: omit default/most common positions. 2021-08-12 14:49:42 -07:00
Chris Fallin
c071e44fc0 Derive PartialOrd/Ord/Hash for Operand. 2021-08-12 14:43:13 -07:00
Chris Fallin
eaf8647fdf BitVec: remove zero words to avoid expanding when unnecessary. 2021-08-12 14:40:18 -07:00
Chris Fallin
82b7e6ba7b Review feedback: bitvec: struct-like enum variants, and factor out one-item cache. 2021-08-12 14:33:35 -07:00
Chris Fallin
7652b4b109 Review feedback. 2021-08-12 14:27:20 -07:00
Chris Fallin
2f856435f4 Review feedback. 2021-08-12 14:08:10 -07:00
Chris Fallin
b76b7747d0 Fix comment in postorder.rs. 2021-08-12 14:00:20 -07:00
Chris Fallin
1f30958b5a Improve domtree as per @Amanieu's feedback. 2021-08-12 12:13:56 -07:00
Chris Fallin
3e1e0f39b6 Convert all log::debug to log::trace. 2021-08-12 12:05:19 -07:00
Chris Fallin
38323e0c27 Some more design-doc and TODO updates from @julian-seward1's feedback. 2021-08-12 11:39:38 -07:00
Chris Fallin
0c795842fd Add some more detail about spill bundles to design doc. 2021-08-12 11:26:45 -07:00
Chris Fallin
a591535fe9 Use "vector" or "sequence" in lieu of "list" in DESIGN.md, except when referring to linked lists.
From feedback from @julian-seward1. I had used "list" in a more generic
sense, meaning ordered sequence of elements, while in a Rust context it
can sometimes be confused with "linked list" specifically. These
alternative terms are more precise.
2021-08-12 11:23:47 -07:00
Chris Fallin
84285c26fb Rename OperandPolicy to OperandConstraint as per feedback from @julian-seward1. 2021-08-12 11:17:52 -07:00
Chris Fallin
c9e8a87cea Update TODO with new items from private feedback from @julian-seward1. 2021-08-12 11:17:37 -07:00
Chris Fallin
4c193a9499 Fix heuristic-cost function overflow with high loop depth (found by @Amanieu). 2021-07-28 12:37:32 -07:00
Chris Fallin
66d6821c7b Fix perf issue with many safepoints.
In wasmtime's `gc::many_live_refs` unit-test, approximately ~1K vregs
are live over ~1K safepoints (actually, each vreg is live over half the
safepoints on average, in a LIFO sort of arrangement).

This causes a huge slowdown with the current heuristics. Basically, each
vreg had a `Conflict` requirement because it had both stack uses
(safepoints) and register uses (the actual def and normal use). The
action in this case when processing the vreg's bundle is to split off
the first use -- a conservative-but-correct approach that will always
eventually split bundles far enough to get non-conflicting-requirement
pieces.

However, because each vreg had N stack uses followed by one register
use, this meant that each had to be split N times (!) -- so we had
O(n^2) splits and O(n^2) bundles by the end of the allocation.

This instead implements another simple heuristic that is much better:
when the requirements are conflicting, scan forward and find the exact
point at which the requirements become conflicting, such that the prefix
(first half prior to the split) still has no conflict, and split there.
This turns the above test-case into an O(n)-bundle / O(n)-split
situation.
2021-06-22 14:06:59 -07:00
Chris Fallin
f27abc9c48 Remove infinite-loop check: it is not a high enough bound in some pathological cases (e.g., gc::many_live_refs test in wasmtime), and it has served its purpose in testing. We can rely on more detailed assertions, e.g. that splits actually shrink bundles and that bundles evict only lower-priority bundles, instead. 2021-06-22 12:06:12 -07:00
Chris Fallin
245c212289 Revert "Add fixed-non-allocatable operand support."
This feature needs more thought; for now we will of course continue to
support pinned vregs, but perhaps we can do better for
"pass-through-and-forget" operands that are given non-allocatable
registers.

This reverts commit 736f636c36.
2021-06-20 23:03:44 -07:00
Chris Fallin
21fb233809 reduce nesting level in DESIGN.md to make pandoc-to-pdf happy 2021-06-19 13:41:26 -07:00