Skip to content

Commit

Permalink
Teach the FP register allocator about hints.
Browse files Browse the repository at this point in the history
This is enough for FP hints to be at least somewhat useful: without
this, they don't have any effect. There is more we can port over from
the GP allocator, but I'd like to think about the bigger picture at
another point.
  • Loading branch information
ltratt committed Jan 7, 2025
1 parent d17ffd7 commit 354b464
Showing 1 changed file with 30 additions and 1 deletion.
31 changes: 30 additions & 1 deletion ykrt/src/compile/jitc_yk/codegen/x64/lsregalloc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -963,7 +963,7 @@ impl LSRegAlloc<'_> {
&mut self,
asm: &mut Assembler,
iidx: InstIdx,
constraints: [RegConstraint<Rx>; N],
mut constraints: [RegConstraint<Rx>; N],
) -> [Rx; N] {
// All constraint operands should be float-typed.
#[cfg(debug_assertions)]
Expand Down Expand Up @@ -1031,6 +1031,35 @@ impl LSRegAlloc<'_> {
}
}

// If we have a hint for a constraint, use it.
for (i, cnstr) in constraints.iter_mut().enumerate() {
match cnstr {
RegConstraint::Output
| RegConstraint::OutputCanBeSameAsInput(_)
| RegConstraint::InputOutput(_) => {
if let Some(reg_alloc::Register::FP(reg)) =
self.rev_an.reg_hints[usize::from(iidx)]
{
if !avoid.is_set(reg) {
*cnstr = match cnstr {
RegConstraint::Output => RegConstraint::OutputFromReg(reg),
RegConstraint::OutputCanBeSameAsInput(_) => {
RegConstraint::OutputFromReg(reg)
}
RegConstraint::InputOutput(op) => {
RegConstraint::InputOutputIntoReg(op.clone(), reg)
}
_ => unreachable!(),
};
asgn[i] = Some(reg);
avoid.set(reg);
}
}
}
_ => (),
}
}

// If we already have the value in a register, don't assign a new register.
for (i, cnstr) in constraints.iter().enumerate() {
match cnstr {
Expand Down

0 comments on commit 354b464

Please sign in to comment.