Skip to content

Commit 6db3f2a

Browse files
committed
Record copy hints for failed fragment coalescing
Interestingly, this didn't actually affect any of the test cases. Have I done something wrong?
1 parent 989e2d2 commit 6db3f2a

File tree

1 file changed

+14
-2
lines changed

1 file changed

+14
-2
lines changed

crates/codegen/src/regalloc/live_set.rs

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ use cranelift_entity::{
88
use log::trace;
99

1010
use crate::{
11-
lir::{UseOperandConstraint, VirtReg},
11+
lir::{Instr, UseOperandConstraint, VirtReg},
1212
machine::MachineRegalloc,
1313
};
1414

@@ -22,6 +22,7 @@ use super::{
2222
type VirtRegFragmentMap = SecondaryMap<VirtReg, PackedOption<LiveSetFragment>>;
2323

2424
struct CopyCandidate {
25+
instr: Instr,
2526
src: VirtReg,
2627
dest: VirtReg,
2728
weight: f32,
@@ -52,6 +53,7 @@ impl<M: MachineRegalloc> RegAllocContext<'_, M> {
5253
if let UseOperandConstraint::TiedToDef(i) = use_op.constraint() {
5354
let def = self.lir.instr_defs(instr)[i as usize];
5455
candidates.push(CopyCandidate {
56+
instr,
5557
src: use_op.reg(),
5658
dest: def.reg(),
5759
weight: get_weight_at_instr(self.lir, self.cfg_ctx, instr),
@@ -73,6 +75,7 @@ impl<M: MachineRegalloc> RegAllocContext<'_, M> {
7375
// terminator for weight purposes.
7476
let terminator = self.lir.block_terminator(block);
7577
candidates.push(CopyCandidate {
78+
instr: terminator,
7679
src: outgoing,
7780
dest: incoming,
7881
weight: get_weight_at_instr(self.lir, self.cfg_ctx, terminator),
@@ -97,7 +100,12 @@ impl<M: MachineRegalloc> RegAllocContext<'_, M> {
97100
candidate.dest,
98101
candidate.weight
99102
);
100-
self.try_coalesce(&mut fragments_by_vreg, candidate.dest, candidate.src);
103+
self.try_coalesce(
104+
&mut fragments_by_vreg,
105+
candidate.instr,
106+
candidate.dest,
107+
candidate.src,
108+
);
101109
}
102110

103111
// Fill in per-fragment data now that we actually know what the fragments are.
@@ -121,6 +129,7 @@ impl<M: MachineRegalloc> RegAllocContext<'_, M> {
121129
fn try_coalesce(
122130
&mut self,
123131
fragments_by_vreg: &mut VirtRegFragmentMap,
132+
instr: Instr,
124133
dest: VirtReg,
125134
src: VirtReg,
126135
) {
@@ -136,6 +145,9 @@ impl<M: MachineRegalloc> RegAllocContext<'_, M> {
136145
&self.live_set_fragments[dest_fragment].ranges,
137146
&self.live_set_fragments[src_fragment].ranges,
138147
) {
148+
// We couldn't coalesce these fragments now, but we might be able to later because of
149+
// splitting. Record a copy hint so we remember to do so.
150+
self.hint_fragment_copy(instr, src_fragment, dest_fragment);
139151
return;
140152
}
141153

0 commit comments

Comments
 (0)