Commit Graph

41 Commits

Author SHA1 Message Date
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
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
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
3e1e0f39b6 Convert all log::debug to log::trace. 2021-08-12 12:05:19 -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
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
22eed0a6ae Make bitvec public; it is used by regalloc.rs shim too. 2021-06-19 12:47:02 -07:00
Chris Fallin
736f636c36 Add fixed-non-allocatable operand support. 2021-06-19 12:17:18 -07:00
Chris Fallin
50eb6fc42f Keep internal modules private, but re-export under fuzzing feature flag 2021-06-19 12:08:37 -07:00
Chris Fallin
36975b8b6f Add doc-comment note on Edit that stack-to-stack moves are never generated. 2021-06-19 11:34:05 -07:00
Chris Fallin
6ec6207717 Add design document. 2021-06-18 13:59:12 -07:00
Chris Fallin
1bd1248cb5 Avoid stack-to-stack moves by allocating an extra spillslot and re-using the scratch reg instead. 2021-06-10 22:36:02 -07:00
Chris Fallin
c6bcd3c941 WIP: redundant-move elimination. 2021-06-07 21:15:32 -07:00
Chris Fallin
2a5f571b80 WIP: Handle moves between realregs (pregs) and vregs somewhat specially, by converting into operand constraints
Still has a fuzzbug in interaction between R->R and V->R moves. Will
likely rework to make pinned-vreg handling more general but want to save
a checkpoint here; idea for rework:
- set allocs immediately if an Operand is a pinned vreg;
- reserve preg ranges;
- then, in rest of liveness computation / LR construction, convert
  pinned-vregs to operands with constraints, but otherwise do not
  special-case as we do in this commit.
2021-05-20 19:53:19 -07:00
Chris Fallin
f1c6dfe807 Optionally show annotations in final allocation/program dump based on RegallocOptions flag 2021-05-19 16:36:36 -07:00
Chris Fallin
e1f67e860f Pinned VRegs for use with regalloc.rs shim to support RealRegs. 2021-05-18 22:40:43 -07:00
Chris Fallin
f0fbf3aa0c Rework data structures: bundles have a SmallVec of ranges, and ranges a SmallVec of uses.
Appears to be a small speed improvement on the highly-artificial
fuzz-generator test inputs; Cranelift tests TBD.
2021-05-17 22:44:10 -07:00
Chris Fallin
5b55948feb Check branch-args for conflicts with edge-move placement. 2021-05-13 17:25:11 -07:00
Chris Fallin
1f9258bea5 Detect undefined liveins. 2021-05-12 01:06:27 -07:00
Chris Fallin
37fa3ec763 Improve prog-move handling: no use/def records, just directly connect the LRs.
Also requires some metadata in edit output to properly hook up the
checker in regalloc.rs to track user-moves without seeing the original
insts with operands.
2021-05-11 23:59:12 -07:00
Chris Fallin
4f26b1c78f Properly handle prog-moves with fixed srcs or dests 2021-05-09 13:35:38 -07:00
Chris Fallin
b9e89885c4 Error checking: properly signal a crit-edge requirement failure (used for regalloc.rs fuzzer) 2021-05-08 21:48:58 -07:00
Chris Fallin
a6e3128821 Support mod (modify) operands, for better efficiency with regalloc.rs/Cranelift shim. 2021-05-07 19:48:34 -07:00
Chris Fallin
df59b5ede4 Inline all the things (ProgPoint edition) 2021-05-07 17:55:04 -07:00
Chris Fallin
4f6346768e Pinned-VReg mechanism. 2021-05-07 17:45:51 -07:00
Chris Fallin
2ba518517d Fuzzbugfix: actually do need eager liveness computation; must uphold invariant that all earlier-in-postorder blocks have full livein sets. 2021-05-06 23:29:59 -07:00
Chris Fallin
02b6516acd Some memory-size/bitpacking optimizations 2021-05-06 20:47:17 -07:00
Chris Fallin
ab828b6c86 MachineEnv fields are public 2021-05-05 23:14:04 -07:00
Chris Fallin
15ed2d6522 Allow multiple defs per vreg (i.e., accept non-SSA code).
This generalizes the allocator to accept multiple defs by making defs
just another type of "use" (uses are now perhaps more properly called
"mentions", but for now we abuse the terminology slightly).

It turns out that this actually was not terribly hard, because we don't
rely on the properties that a strict SSA requirement otherwise might
allow us to: e.g., defs always at exactly the start of a vreg's ranges.
Because we already accepted arbitrary block order and irreducible CFGs,
and approximated live-ranges with the single-pass algorithm, we are
robust in our "stitching" (move insertion) and so all we really care
about is computing some superset of the actual live-ranges and then a
non-interfering coloring of (split pieces of) those ranges. Multiple
defs don't change that, as long as we compute the ranges properly.

We still have blockparams in this design, so the client *can* provide
SSA directly, and everything will work as before. But a client that
produces non-SSA need not use them at all; it can just happily reassign
to vregs and everything will Just Work.

This is part of the effort to port Cranelift over to regalloc2; I have
decided that it may be easier to build a compatibility shim that matches
regalloc.rs's interface than to continue boiling the ocean and
converting all of the lowering sequences to SSA. It then becomes a
separable piece of work (and simply further performance improvements and
simplifications) to remove the need for this shim.
2021-05-05 22:49:45 -07:00
Chris Fallin
9e7021cfd0 Derive Ord/hash on OperandOrAllocation. 2021-05-03 19:18:19 -07:00
Chris Fallin
49c54b6144 Misc usability and functionality enhancements:
- Support preferred and non-preferred subsets of a register class. This
  allows allocating, e.g., caller-saved registers before callee-saved
  registers.
- Allow branch blockparam args to start an a certain offset in branch
  operands; this allows branches to have other operands too (e.g.,
  conditional-branch inputs).
- Allow `OperandOrAllocation` to be constructed from an `Allocation` and
  `OperandKind` as well (i.e., an allocation with an use/def bit).
2021-04-30 21:14:09 -07:00
Chris Fallin
414f3f828d Factored out test program and fuzzing features; core crate now only depends on smallvec and log. 2021-04-18 14:19:32 -07:00
Chris Fallin
940c1b719d Changes from review comments. 2021-04-18 13:12:33 -07:00
Chris Fallin
a08b0121a0 Add support for reftypes/stackmaps and Stack constraints, and misc API changes.
The main enhancement in this commit is support for reference types and
stackmaps. This requires tracking whether each VReg is a "reference" or
"pointer". At certain instructions designated as "safepoints", the
regalloc will (i) ensure that all references are in spillslots rather
than in registers, and (ii) provide a list of exactly which spillslots
have live references at that program point. This can be used by, e.g., a
GC to trace and possibly modify pointers. The stackmap of spillslots is
precise: it includes all live references, and *only* live references.

This commit also brings in some API tweaks as part of the in-progress
Cranelift glue. In particular, it makes Allocations and Operands
mutually disjoint by using the same bitfield for the type-tag in both
and choosing non-overlapping tags. This will allow instructions to carry
an Operand for each register slot and then overwrite these in place with
Allocations. The `OperandOrAllocation` type does the necessary magic to
make this look like an enum, but staying in 32 bits.
2021-04-17 21:29:13 -07:00
Chris Fallin
8e923b0ad9 Initial public commit of regalloc2. 2021-04-13 17:40:12 -07:00