Misc refactorings (#116)

* Use a while-let instead of checking is_empty and popping

* This conditional should always be true, as we expect the input is in ssa

* Use iter_mut instead of iterating the index

* We don't support multiple defs of the same vreg anymore

* Drain instead of clear
This commit is contained in:
Trevor Elliott
2023-02-28 10:42:13 -08:00
committed by GitHub
parent 1e8da4f99b
commit 34a9ae7379

View File

@@ -334,8 +334,7 @@ impl<'a, F: Function> Env<'a, F> {
workqueue_set.insert(block);
}
while !workqueue.is_empty() {
let block = workqueue.pop_front().unwrap();
while let Some(block) = workqueue.pop_front() {
workqueue_set.remove(&block);
let insns = self.func.block_insns(block);
@@ -522,9 +521,11 @@ impl<'a, F: Function> Env<'a, F> {
// If this is a move, handle specially.
if let Some((src, dst)) = self.func.is_move(inst) {
// We can completely skip the move if it is
// trivial (vreg to same vreg).
if src.vreg() != dst.vreg() {
assert!(
src.vreg() != dst.vreg(),
"Invalid move: overwriting an SSA value"
);
trace!(" -> move inst{}: src {} -> dst {}", inst.index(), src, dst);
debug_assert_eq!(src.class(), dst.class());
@@ -628,8 +629,8 @@ impl<'a, F: Function> Env<'a, F> {
from: self.cfginfo.block_entry[block.index()],
to: pos.next(),
};
let src_lr = self
.add_liverange_to_vreg(VRegIndex::new(src.vreg().vreg()), range);
let src_lr =
self.add_liverange_to_vreg(VRegIndex::new(src.vreg().vreg()), range);
vreg_ranges[src.vreg().vreg()] = src_lr;
src_lr
} else {
@@ -656,7 +657,6 @@ impl<'a, F: Function> Env<'a, F> {
self.stats.prog_moves_dead_src += 1;
self.prog_move_merges.push((src_lr, dst_lr));
}
}
continue;
}
@@ -959,12 +959,9 @@ impl<'a, F: Function> Env<'a, F> {
}
}
for range in 0..self.ranges.len() {
self.ranges[range].uses.reverse();
debug_assert!(self.ranges[range]
.uses
.windows(2)
.all(|win| win[0].pos <= win[1].pos));
for range in &mut self.ranges {
range.uses.reverse();
debug_assert!(range.uses.windows(2).all(|win| win[0].pos <= win[1].pos));
}
// Insert safepoint virtual stack uses, if needed.
@@ -1032,7 +1029,7 @@ impl<'a, F: Function> Env<'a, F> {
pub fn fixup_multi_fixed_vregs(&mut self) {
// Do a fixed-reg cleanup pass: if there are any LiveRanges with
// multiple uses (or defs) at the same ProgPoint and there is
// multiple uses at the same ProgPoint and there is
// more than one FixedReg constraint at that ProgPoint, we
// need to record all but one of them in a special fixup list
// and handle them later; otherwise, bundle-splitting to
@@ -1154,15 +1151,13 @@ impl<'a, F: Function> Env<'a, F> {
}
}
for &(clobber, pos) in &extra_clobbers {
for (clobber, pos) in extra_clobbers.drain(..) {
let range = CodeRange {
from: pos,
to: pos.next(),
};
self.add_liverange_to_preg(range, clobber);
}
extra_clobbers.clear();
}
}
}