Remove all-empty-ranges-to-spill-bundle: prioritizing same-alloc for all empty ranges over allowing some to live in registers results in too much spilling

This commit is contained in:
Chris Fallin
2021-05-20 10:21:22 -07:00
parent ce935c1040
commit f0b24cf9fa

View File

@@ -2627,13 +2627,6 @@ impl<'a, F: Function> Env<'a, F> {
// to the above invariants to keep this code maintainable. // to the above invariants to keep this code maintainable.
let spillset = self.bundles[bundle.index()].spillset; let spillset = self.bundles[bundle.index()].spillset;
// Get the spill bundle, which is the single bundle into which
// we place empty ranges (those with no uses). This may be
// `LiveBundleIndex::invalid()`, in which case we'll create it
// when we first need it.
let mut spill_bundle = self.spillsets[spillset.index()].spill_bundle;
let mut split_idx = 0; let mut split_idx = 0;
// Fast-forward past any splits that occur before or exactly // Fast-forward past any splits that occur before or exactly
@@ -2688,7 +2681,7 @@ impl<'a, F: Function> Env<'a, F> {
log::debug!(" -> use at {:?}", u.pos); log::debug!(" -> use at {:?}", u.pos);
self.ranges[cur_lr.index()].uses.push(u); self.ranges[cur_lr.index()].uses.push(u);
} }
if self.ranges[cur_lr.index()].uses.len() > 0 {
self.ranges[cur_lr.index()].bundle = cur_bundle; self.ranges[cur_lr.index()].bundle = cur_bundle;
self.bundles[cur_bundle.index()] self.bundles[cur_bundle.index()]
.ranges .ranges
@@ -2696,33 +2689,6 @@ impl<'a, F: Function> Env<'a, F> {
range: cur_range, range: cur_range,
index: cur_lr, index: cur_lr,
}); });
} else {
if spill_bundle.is_invalid() {
spill_bundle = self.create_bundle();
log::debug!(
" -> allocating new spill-bundle for empty ranges: bundle{}",
spill_bundle.index()
);
self.bundles[spill_bundle.index()].spillset = spillset;
self.spillsets[spillset.index()].spill_bundle = spill_bundle;
self.spilled_bundles.push(spill_bundle);
}
// Range lists in empty-range bundles are not
// sorted until later (when we try to allocate
// regs or spillslots for them).
log::debug!(
" -> no uses in range{}; placing in empty-range spill-bundle bundle{}",
cur_lr.index(),
spill_bundle.index()
);
self.ranges[cur_lr.index()].bundle = spill_bundle;
self.bundles[spill_bundle.index()]
.ranges
.push(LiveRangeListEntry {
range: cur_range,
index: cur_lr,
});
}
break; break;
} }
@@ -2793,7 +2759,6 @@ impl<'a, F: Function> Env<'a, F> {
cur_uses.next(); cur_uses.next();
} }
if self.ranges[cur_lr.index()].uses.len() > 0 {
log::debug!( log::debug!(
" -> adding current LR {:?} to current bundle {:?}", " -> adding current LR {:?} to current bundle {:?}",
cur_lr, cur_lr,
@@ -2806,30 +2771,6 @@ impl<'a, F: Function> Env<'a, F> {
range: existing_range, range: existing_range,
index: cur_lr, index: cur_lr,
}); });
} else {
if spill_bundle.is_invalid() {
spill_bundle = self.create_bundle();
log::debug!(
" -> allocating new spill-bundle for empty ranges: bundle{}",
spill_bundle.index()
);
self.bundles[spill_bundle.index()].spillset = spillset;
self.spillsets[spillset.index()].spill_bundle = spill_bundle;
self.spilled_bundles.push(spill_bundle);
}
log::debug!(
" -> no uses in range{}; placing in empty-range spill-bundle bundle{}",
cur_lr.index(),
spill_bundle.index()
);
self.ranges[cur_lr.index()].bundle = spill_bundle;
self.bundles[spill_bundle.index()]
.ranges
.push(LiveRangeListEntry {
range: cur_range,
index: cur_lr,
});
}
if self.annotations_enabled && log::log_enabled!(log::Level::Debug) { if self.annotations_enabled && log::log_enabled!(log::Level::Debug) {
self.annotate( self.annotate(
@@ -2866,21 +2807,17 @@ impl<'a, F: Function> Env<'a, F> {
// Recompute weights and priorities of all bundles, and // Recompute weights and priorities of all bundles, and
// enqueue all split-bundles on the allocation queue. // enqueue all split-bundles on the allocation queue.
if self.bundles[bundle.index()].ranges.len() > 0 {
let prio = self.compute_bundle_prio(bundle); let prio = self.compute_bundle_prio(bundle);
self.bundles[bundle.index()].prio = prio; self.bundles[bundle.index()].prio = prio;
self.recompute_bundle_properties(bundle); self.recompute_bundle_properties(bundle);
self.allocation_queue.insert(bundle, prio as usize); self.allocation_queue.insert(bundle, prio as usize);
}
for &b in &new_bundles { for &b in &new_bundles {
if self.bundles[b.index()].ranges.len() > 0 {
let prio = self.compute_bundle_prio(b); let prio = self.compute_bundle_prio(b);
self.bundles[b.index()].prio = prio; self.bundles[b.index()].prio = prio;
self.recompute_bundle_properties(b); self.recompute_bundle_properties(b);
self.allocation_queue.insert(b, prio as usize); self.allocation_queue.insert(b, prio as usize);
} }
} }
}
fn process_bundle(&mut self, bundle: LiveBundleIndex) -> Result<(), RegAllocError> { fn process_bundle(&mut self, bundle: LiveBundleIndex) -> Result<(), RegAllocError> {
// Find any requirements: for every LR, for every def/use, gather // Find any requirements: for every LR, for every def/use, gather