Address review comments: more doc comments and some minor refactorings.

This commit is contained in:
Chris Fallin
2021-08-30 17:15:37 -07:00
parent e10bffbca8
commit 6d313f2b56
11 changed files with 256 additions and 153 deletions

View File

@@ -61,7 +61,7 @@ impl<'a, F: Function> Env<'a, F> {
pub fn dump_results(&self) {
log::info!("=== REGALLOC RESULTS ===");
for block in 0..self.func.blocks() {
for block in 0..self.func.num_blocks() {
let block = Block::new(block);
log::info!(
"block{}: [succs {:?} preds {:?}]",

View File

@@ -82,7 +82,7 @@ impl<'a, F: Function> Env<'a, F> {
self.vregs[v.vreg()].is_pinned = true;
}
// Create allocations too.
for inst in 0..self.func.insts() {
for inst in 0..self.func.num_insts() {
let start = self.allocs.len() as u32;
self.inst_alloc_offsets.push(start);
for _ in 0..self.func.inst_operands(Inst::new(inst)).len() {
@@ -247,7 +247,7 @@ impl<'a, F: Function> Env<'a, F> {
pub fn compute_liveness(&mut self) -> Result<(), RegAllocError> {
// Create initial LiveIn and LiveOut bitsets.
for _ in 0..self.func.blocks() {
for _ in 0..self.func.num_blocks() {
self.liveins.push(BitVec::new());
self.liveouts.push(BitVec::new());
}
@@ -347,7 +347,7 @@ impl<'a, F: Function> Env<'a, F> {
let mut vreg_ranges: Vec<LiveRangeIndex> =
vec![LiveRangeIndex::invalid(); self.func.num_vregs()];
for i in (0..self.func.blocks()).rev() {
for i in (0..self.func.num_blocks()).rev() {
let block = Block::new(i);
self.stats.livein_blocks += 1;

View File

@@ -303,7 +303,7 @@ impl<'a, F: Function> Env<'a, F> {
self.bundles[bundle.index()].spillset = ssidx;
}
for inst in 0..self.func.insts() {
for inst in 0..self.func.num_insts() {
let inst = Inst::new(inst);
// Attempt to merge Reuse-constraint operand outputs with the

View File

@@ -44,14 +44,14 @@ impl<'a, F: Function> Env<'a, F> {
cfginfo: CFGInfo,
annotations_enabled: bool,
) -> Self {
let n = func.insts();
let n = func.num_insts();
Self {
func,
env,
cfginfo,
liveins: Vec::with_capacity(func.blocks()),
liveouts: Vec::with_capacity(func.blocks()),
liveins: Vec::with_capacity(func.num_blocks()),
liveouts: Vec::with_capacity(func.num_blocks()),
blockparam_outs: vec![],
blockparam_ins: vec![],
blockparam_allocs: vec![],

View File

@@ -166,8 +166,8 @@ impl<'a, F: Function> Env<'a, F> {
}
}
let mut half_moves: Vec<HalfMove> = Vec::with_capacity(6 * self.func.insts());
let mut reuse_input_insts = Vec::with_capacity(self.func.insts() / 2);
let mut half_moves: Vec<HalfMove> = Vec::with_capacity(6 * self.func.num_insts());
let mut reuse_input_insts = Vec::with_capacity(self.func.num_insts() / 2);
let mut blockparam_in_idx = 0;
let mut blockparam_out_idx = 0;
@@ -290,7 +290,7 @@ impl<'a, F: Function> Env<'a, F> {
// same allocation) and if the vreg is live, add a
// Source half-move.
let mut block = self.cfginfo.insn_block[range.from.inst().index()];
while block.is_valid() && block.index() < self.func.blocks() {
while block.is_valid() && block.index() < self.func.num_blocks() {
if range.to < self.cfginfo.block_exit[block.index()].next() {
break;
}
@@ -376,7 +376,7 @@ impl<'a, F: Function> Env<'a, F> {
if self.cfginfo.block_entry[block.index()] < range.from {
block = block.next();
}
while block.is_valid() && block.index() < self.func.blocks() {
while block.is_valid() && block.index() < self.func.num_blocks() {
if self.cfginfo.block_entry[block.index()] >= range.to {
break;
}
@@ -1114,11 +1114,13 @@ impl<'a, F: Function> Env<'a, F> {
.collect::<Vec<_>>();
assert_eq!(vregs.len(), self.func.block_params(block).len());
assert_eq!(allocs.len(), self.func.block_params(block).len());
self.add_edit(
self.cfginfo.block_entry[block.index()],
InsertMovePrio::BlockParam,
Edit::BlockParams { vregs, allocs },
);
for (vreg, alloc) in vregs.into_iter().zip(allocs.into_iter()) {
self.add_edit(
self.cfginfo.block_entry[block.index()],
InsertMovePrio::BlockParam,
Edit::DefAlloc { alloc, vreg },
);
}
}
// Ensure edits are in sorted ProgPoint order. N.B.: this must
@@ -1139,13 +1141,6 @@ impl<'a, F: Function> Env<'a, F> {
format!("move {} -> {} ({:?})", from, to, to_vreg),
);
}
&Edit::BlockParams {
ref vregs,
ref allocs,
} => {
let s = format!("blockparams vregs:{:?} allocs:{:?}", vregs, allocs);
self.annotate(ProgPoint::from_index(pos), s);
}
&Edit::DefAlloc { alloc, vreg } => {
let s = format!("defalloc {:?} := {:?}", alloc, vreg);
self.annotate(ProgPoint::from_index(pos), s);

View File

@@ -798,7 +798,7 @@ impl<'a, F: Function> Env<'a, F> {
loop {
attempts += 1;
log::trace!("attempt {}, req {:?}", attempts, req);
debug_assert!(attempts < 100 * self.func.insts());
debug_assert!(attempts < 100 * self.func.num_insts());
let (class, fixed_preg) = match req {
Requirement::Fixed(preg) => (preg.class(), Some(preg)),