MCPcopy Index your code
hub / github.com/Amanieu/regalloc3

github.com/Amanieu/regalloc3 @main

Chat with this repo
repository ↗ · DeepWiki ↗ · + Follow
880 symbols 2,902 edges 63 files 357 documented · 41%
What it actually does AI analysis from the code graph — generated when you open this
loading…
README

regalloc3

New register allocator implementation designed as a successor to regalloc2. The design takes inspiration from many sources, including LLVM's greedy register allocator.

New API-level features compared to regalloc2: - Support for 2^28 (~268M) values ("vregs" in regalloc2) per function. - Support for up to 64 different register classes. - Support for up to 512 registers. - Support for compound registers and overlapping registers (e.g. S0 / S1 / D0 on AArch32). - Support for multi-register groups (e.g. CASP register pairs on AArch64, LD4 SIMD vector loads on AArch64). - Support for rematerialization of constants as an alternative to spilling. - Support for explicit block frequencies. - Register descriptions are described by a RegInfo trait. - Functions and register descriptions can be serialized to a text format and parsed back into memory. - Faster compilation of multiple functions by preserving and reusing memory allocations across runs. - Validation functions to check Function and RegInfo implementations.

Refer to the extensive design document for more detail on the internal implementation of the allocator.

Flags

This crate has the following Cargo features:

  • parse: Support for parsing a GenericFunction from a text representation. Requires std.
  • serde: Support for serializing and de-serializing all public types.
  • arbitrary: Support for generating randomized functions for testing.
  • trace-log: Enables detailed logging which can be somewhat expensive and very verbose.

Debugging register allocation issues

Regalloc3 includes many utlities for debugging issues related to register allocation. The very first thing that you should do if you encounter any issues is to check that your Function and RegInfo implementations both pass the validation functions under the debug_utils module.

If this doesn't solve your issues then you can dump these to a text format using DisplayRegInfo and DisplayFunction which can then be passed to regalloc3-tool for further debugging.

License

Licensed under either of:

  • Apache License, Version 2.0, (LICENSE-APACHE or https://www.apache.org/licenses/LICENSE-2.0)
  • MIT license (LICENSE-MIT or https://opensource.org/licenses/MIT)

at your option.

Contribution

Unless you explicitly state otherwise, any contribution intentionally submitted for inclusion in the work by you, as defined in the Apache-2.0 license, shall be dual licensed as above, without any additional terms or conditions.

Extension points exported contracts — how you extend this code

Function (Interface)
A trait defined by the register allocator client to provide access to its machine-instruction / CFG representation. See [2 …
src/function.rs
InterferenceSegment (Interface)
A live range segment that interference should be checked against. [2 implementers]
src/internal/reg_matrix.rs
ReservedValue (Interface)
Types that have a reserved value which does not represent a valid value. [2 implementers]
src/entity/packed_option.rs
RegInfo (Interface)
Trait which describes the physical registers and register classes that may be allocated from. This is separate from the [1 …
src/reginfo.rs
AbstractVirtRegGroup (Interface)
Abstraction over a virtual register group. We want to optimize allocation speed for the case of single virtual register [2 …
src/internal/allocator/mod.rs
EntityRef (Interface)
A typed wrapper around an integer index. Types implementing this trait can be used as keys for collections like [`Prima [1 …
src/entity/base.rs
SmallSetWord (Interface)
(no doc) [2 implementers]
src/entity/small_set.rs

Core symbols most depended-on inside this repo

push
called by 224
src/entity/primary_map.rs
kind
called by 72
src/output.rs
slot
called by 65
src/internal/live_range.rs
iter
called by 64
src/internal/uses.rs
insert
called by 60
src/entity/set.rs
clear
called by 58
src/internal/uses.rs
index
called by 57
src/internal/uses.rs
next
called by 51
src/internal/live_range.rs

Shape

Method 665
Class 133
Function 40
Enum 35
Interface 7

Languages

Rust100%

Modules by API surface

src/entity/sparse.rs40 symbols
src/entity/primary_map.rs31 symbols
src/internal/move_resolver.rs30 symbols
src/entity/small_set.rs30 symbols
src/entity/set.rs29 symbols
src/debug_utils/generic_function/mod.rs29 symbols
src/internal/uses.rs28 symbols
src/debug_utils/generic_reginfo/mod.rs28 symbols
src/function.rs27 symbols
src/debug_utils/checker.rs27 symbols
fuzz/fuzz_targets/parallel_moves.rs27 symbols
src/internal/parallel_moves.rs26 symbols

For agents

$ claude mcp add regalloc3 \
  -- python -m otcore.mcp_server <graph>

⬇ download graph artifact