Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions src/ion/data_structures.rs
Original file line number Diff line number Diff line change
Expand Up @@ -179,13 +179,13 @@ impl LiveRange {
pub struct Use {
pub operand: Operand,
pub pos: ProgPoint,
pub slot: u8,
pub slot: u16,
pub weight: u16,
}

impl Use {
#[inline(always)]
pub fn new(operand: Operand, pos: ProgPoint, slot: u8) -> Self {
pub fn new(operand: Operand, pos: ProgPoint, slot: u16) -> Self {
Self {
operand,
pos,
Expand Down Expand Up @@ -315,8 +315,8 @@ pub struct PRegData {
#[derive(Clone, Debug)]
pub struct MultiFixedRegFixup {
pub pos: ProgPoint,
pub from_slot: u8,
pub to_slot: u8,
pub from_slot: u16,
pub to_slot: u16,
pub level: FixedRegFixupLevel,
pub to_preg: PRegIndex,
pub vreg: VRegIndex,
Expand Down
23 changes: 18 additions & 5 deletions src/ion/liveranges.rs
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ use crate::{
Allocation, Block, Function, Inst, InstPosition, Operand, OperandConstraint, OperandKind,
OperandPos, PReg, ProgPoint, RegAllocError, VReg, VecExt,
};
use core::convert::TryFrom;
use smallvec::{smallvec, SmallVec};

/// A spill weight computed for a certain Use.
Expand Down Expand Up @@ -94,6 +95,10 @@ impl core::ops::Add<SpillWeight> for SpillWeight {
}
}

fn slot_idx(i: usize) -> Result<u16, RegAllocError> {
u16::try_from(i).map_err(|_| RegAllocError::TooManyOperands)
}

impl<'a, F: Function> Env<'a, F> {
pub fn create_pregs_and_vregs(&mut self) {
// Create PRegs from the env.
Expand Down Expand Up @@ -362,7 +367,7 @@ impl<'a, F: Function> Env<'a, F> {
Ok(())
}

pub fn build_liveranges(&mut self) {
pub fn build_liveranges(&mut self) -> Result<(), RegAllocError> {
// Create Uses and Defs referring to VRegs, and place the Uses
// in LiveRanges.
//
Expand Down Expand Up @@ -533,8 +538,8 @@ impl<'a, F: Function> Env<'a, F> {
let pos = ProgPoint::before(inst);
self.multi_fixed_reg_fixups.push(MultiFixedRegFixup {
pos,
from_slot: i as u8,
to_slot: i as u8,
from_slot: slot_idx(i)?,
to_slot: slot_idx(i)?,
to_preg: PRegIndex::new(preg.index()),
vreg: VRegIndex::new(operand.vreg().vreg()),
level: FixedRegFixupLevel::Initial,
Expand Down Expand Up @@ -638,7 +643,10 @@ impl<'a, F: Function> Env<'a, F> {
live.set(operand.vreg().vreg(), true);
}
// Create the use in the LiveRange.
self.insert_use_into_liverange(lr, Use::new(operand, pos, i as u8));
self.insert_use_into_liverange(
lr,
Use::new(operand, pos, slot_idx(i)?),
);
// If def (not mod), this reg is now dead,
// scanning backward; make it so.
if operand.kind() == OperandKind::Def {
Expand Down Expand Up @@ -681,7 +689,10 @@ impl<'a, F: Function> Env<'a, F> {

trace!("Use of {:?} at {:?} -> {:?}", operand, pos, lr,);

self.insert_use_into_liverange(lr, Use::new(operand, pos, i as u8));
self.insert_use_into_liverange(
lr,
Use::new(operand, pos, slot_idx(i)?),
);

// Add to live-set.
live.set(operand.vreg().vreg(), true);
Expand Down Expand Up @@ -756,6 +767,8 @@ impl<'a, F: Function> Env<'a, F> {
self.output.stats.blockparam_outs_count = self.blockparam_outs.len();
self.ctx.scratch_vreg_ranges = vreg_ranges;
self.ctx.scratch_operand_rewrites = operand_rewrites;

Ok(())
}

pub fn fixup_multi_fixed_vregs(&mut self) {
Expand Down
2 changes: 1 addition & 1 deletion src/ion/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ impl<'a, F: Function> Env<'a, F> {
pub(crate) fn init(&mut self) -> Result<(), RegAllocError> {
self.create_pregs_and_vregs();
self.compute_liveness()?;
self.build_liveranges();
self.build_liveranges()?;
self.fixup_multi_fixed_vregs();
self.merge_vreg_bundles();
self.queue_bundles();
Expand Down
3 changes: 3 additions & 0 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1577,6 +1577,9 @@ pub enum RegAllocError {
/// Too many pinned VRegs + Reg-constrained Operands are live at
/// once, making allocation impossible.
TooManyLiveRegs,
/// Too many operands on a single instruction (beyond limit of
/// 2^16 - 1).
TooManyOperands,
}

impl core::fmt::Display for RegAllocError {
Expand Down