Skip to content

Commit

Permalink
cranelift: Compress vcode range-lists (bytecodealliance#8506)
Browse files Browse the repository at this point in the history
These lists of ranges always cover contiguous ranges of an index space,
meaning the start of one range is the same as the end of the previous
range, so we can cut storage in half by only storing one endpoint of
each range.

This in turn means we don't have to keep track of the other endpoint
while building these lists, reducing the state we need to keep while
building vcode and simplifying the various build steps.
  • Loading branch information
jameysharp authored May 2, 2024
1 parent c66c874 commit 2c40953
Show file tree
Hide file tree
Showing 4 changed files with 190 additions and 104 deletions.
1 change: 1 addition & 0 deletions cranelift/codegen/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,7 @@ mod iterators;
mod legalizer;
mod nan_canonicalization;
mod opts;
mod ranges;
mod remove_constant_phis;
mod result;
mod scoped_hash_map;
Expand Down
10 changes: 3 additions & 7 deletions cranelift/codegen/src/machinst/reg.rs
Original file line number Diff line number Diff line change
Expand Up @@ -288,7 +288,6 @@ pub type RegClass = regalloc2::RegClass;
#[derive(Debug)]
pub struct OperandCollector<'a, F: Fn(VReg) -> VReg> {
operands: &'a mut Vec<Operand>,
operands_start: usize,
clobbers: PRegSet,

/// The subset of physical registers that are allocatable.
Expand All @@ -300,10 +299,8 @@ pub struct OperandCollector<'a, F: Fn(VReg) -> VReg> {
impl<'a, F: Fn(VReg) -> VReg> OperandCollector<'a, F> {
/// Start gathering operands into one flattened operand array.
pub fn new(operands: &'a mut Vec<Operand>, allocatable: PRegSet, renamer: F) -> Self {
let operands_start = operands.len();
Self {
operands,
operands_start,
clobbers: PRegSet::default(),
allocatable,
renamer,
Expand All @@ -313,10 +310,9 @@ impl<'a, F: Fn(VReg) -> VReg> OperandCollector<'a, F> {
/// Finish the operand collection and return the tuple giving the
/// range of indices in the flattened operand array, and the
/// clobber set.
pub fn finish(self) -> ((u32, u32), PRegSet) {
let start = self.operands_start as u32;
let end = self.operands.len() as u32;
((start, end), self.clobbers)
pub fn finish(self) -> (usize, PRegSet) {
let end = self.operands.len();
(end, self.clobbers)
}
}

Expand Down
Loading

0 comments on commit 2c40953

Please sign in to comment.