Add fixed-non-allocatable operand support.

This commit is contained in:
Chris Fallin
2021-06-19 12:17:18 -07:00
parent 50eb6fc42f
commit 736f636c36
3 changed files with 43 additions and 1 deletions

View File

@@ -144,6 +144,15 @@ impl VReg {
pub fn invalid() -> Self {
VReg::new(Self::MAX, RegClass::Int)
}
#[inline(always)]
pub fn is_valid(self) -> bool {
self != Self::invalid()
}
#[inline(always)]
pub fn is_invalid(self) -> bool {
self == Self::invalid()
}
}
impl std::fmt::Debug for VReg {
@@ -328,6 +337,19 @@ impl Operand {
)
}
/// Create an Operand that always results in an assignment to the
/// given fixed `preg`, *without* tracking liveranges in that
/// `preg`. Must only be used for non-allocatable registers.
#[inline(always)]
pub fn fixed(preg: PReg) -> Self {
Operand::new(
VReg::invalid(),
OperandPolicy::FixedReg(preg),
OperandKind::Use, // doesn't matter
OperandPos::Before, // doesn't matter
)
}
#[inline(always)]
pub fn vreg(self) -> VReg {
let vreg_idx = ((self.bits as usize) & VReg::MAX) as usize;
@@ -379,6 +401,14 @@ impl Operand {
}
}
#[inline(always)]
pub fn as_fixed(self) -> Option<PReg> {
match (self.vreg().is_invalid(), self.policy()) {
(true, OperandPolicy::FixedReg(preg)) => Some(preg),
_ => None,
}
}
#[inline(always)]
pub fn bits(self) -> u32 {
self.bits