Skip to content

Simplify Requirement by removing register classes #11

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Sep 9, 2021
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
15 changes: 8 additions & 7 deletions src/ion/process.rs
Original file line number Diff line number Diff line change
Expand Up @@ -748,6 +748,7 @@ impl<'a, F: Function> Env<'a, F> {
bundle: LiveBundleIndex,
reg_hint: PReg,
) -> Result<(), RegAllocError> {
let class = self.spillsets[self.bundles[bundle.index()].spillset.index()].class;
let req = self.compute_requirement(bundle);
// Grab a hint from either the queue or our spillset, if any.
let hint_reg = if reg_hint != PReg::invalid() {
Expand Down Expand Up @@ -778,7 +779,7 @@ impl<'a, F: Function> Env<'a, F> {
// spill bundle is already present, then move the LRs over to
// the spill bundle right away.
match req {
Requirement::Unknown | Requirement::Any(_) => {
Requirement::Unknown | Requirement::Any => {
if let Some(spill) =
self.get_or_create_spill_bundle(bundle, /* create_if_absent = */ false)
{
Expand All @@ -801,17 +802,17 @@ impl<'a, F: Function> Env<'a, F> {
log::trace!("attempt {}, req {:?}", attempts, req);
debug_assert!(attempts < 100 * self.func.num_insts());

let (class, fixed_preg) = match req {
Requirement::Fixed(preg) => (preg.class(), Some(preg)),
Requirement::Register(class) => (class, None),
Requirement::Stack(_) => {
let fixed_preg = match req {
Requirement::Fixed(preg) => Some(preg),
Requirement::Register => None,
Requirement::Stack => {
// If we must be on the stack, mark our spillset
// as required immediately.
self.spillsets[self.bundles[bundle.index()].spillset.index()].required = true;
return Ok(());
}

Requirement::Any(_) | Requirement::Unknown => {
Requirement::Any | Requirement::Unknown => {
self.spilled_bundles.push(bundle);
return Ok(());
}
Expand Down Expand Up @@ -966,7 +967,7 @@ impl<'a, F: Function> Env<'a, F> {
|| lowest_cost_evict_conflict_cost.is_none()
|| lowest_cost_evict_conflict_cost.unwrap() >= our_spill_weight)
{
if let Requirement::Register(class) = req {
if let Requirement::Register = req {
// Check if this is a too-many-live-registers situation.
let range = self.bundles[bundle.index()].ranges[0].range;
log::trace!("checking for too many live regs");
Expand Down
61 changes: 12 additions & 49 deletions src/ion/requirement.rs
Original file line number Diff line number Diff line change
@@ -1,63 +1,28 @@
//! Requirements computation.

use super::{Env, LiveBundleIndex};
use crate::{Function, Operand, OperandConstraint, PReg, RegClass};
use crate::{Function, Operand, OperandConstraint, PReg};

#[derive(Clone, Copy, Debug, PartialEq, Eq)]
pub enum Requirement {
Unknown,
Fixed(PReg),
Register(RegClass),
Stack(RegClass),
Any(RegClass),
Register,
Stack,
Any,
Conflict,
}
impl Requirement {
#[inline(always)]
pub fn class(self) -> RegClass {
match self {
Requirement::Unknown => panic!("No class for unknown Requirement"),
Requirement::Fixed(preg) => preg.class(),
Requirement::Register(class) | Requirement::Any(class) | Requirement::Stack(class) => {
class
}
Requirement::Conflict => panic!("No class for conflicted Requirement"),
}
}
#[inline(always)]
pub fn merge(self, other: Requirement) -> Requirement {
match (self, other) {
(Requirement::Unknown, other) | (other, Requirement::Unknown) => other,
(Requirement::Conflict, _) | (_, Requirement::Conflict) => Requirement::Conflict,
(other, Requirement::Any(rc)) | (Requirement::Any(rc), other) => {
if other.class() == rc {
other
} else {
Requirement::Conflict
}
}
(Requirement::Stack(rc1), Requirement::Stack(rc2)) => {
if rc1 == rc2 {
self
} else {
Requirement::Conflict
}
}
(Requirement::Register(rc), Requirement::Fixed(preg))
| (Requirement::Fixed(preg), Requirement::Register(rc)) => {
if rc == preg.class() {
Requirement::Fixed(preg)
} else {
Requirement::Conflict
}
}
(Requirement::Register(rc1), Requirement::Register(rc2)) => {
if rc1 == rc2 {
self
} else {
Requirement::Conflict
}
}
(other, Requirement::Any) | (Requirement::Any, other) => other,
(Requirement::Stack, Requirement::Stack) => self,
(Requirement::Register, Requirement::Fixed(preg))
| (Requirement::Fixed(preg), Requirement::Register) => Requirement::Fixed(preg),
(Requirement::Register, Requirement::Register) => self,
(Requirement::Fixed(a), Requirement::Fixed(b)) if a == b => self,
_ => Requirement::Conflict,
}
Expand All @@ -66,11 +31,9 @@ impl Requirement {
pub fn from_operand(op: Operand) -> Requirement {
match op.constraint() {
OperandConstraint::FixedReg(preg) => Requirement::Fixed(preg),
OperandConstraint::Reg | OperandConstraint::Reuse(_) => {
Requirement::Register(op.class())
}
OperandConstraint::Stack => Requirement::Stack(op.class()),
_ => Requirement::Any(op.class()),
OperandConstraint::Reg | OperandConstraint::Reuse(_) => Requirement::Register,
OperandConstraint::Stack => Requirement::Stack,
_ => Requirement::Any,
}
}
}
Expand Down