Skip to content

Commit 9eeb788

Browse files
committed
Change wording of checks and documentation.
1 parent cf441a9 commit 9eeb788

File tree

3 files changed

+21
-11
lines changed

3 files changed

+21
-11
lines changed

src/lib.rs

Lines changed: 14 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1120,9 +1120,6 @@ pub enum AllocationKind {
11201120
///
11211121
/// (This trait's design is inspired by, and derives heavily from, the
11221122
/// trait of the same name in regalloc.rs.)
1123-
///
1124-
/// The ids used in [`Block`] and [`VReg`] must start their numbering
1125-
/// at zero and be sequential.
11261123
pub trait Function {
11271124
// -------------
11281125
// CFG traversal
@@ -1131,7 +1128,13 @@ pub trait Function {
11311128
/// How many instructions are there?
11321129
fn num_insts(&self) -> usize;
11331130

1134-
/// How many blocks are there?
1131+
/// Number of entries to allocate [`Block`] storage for.
1132+
///
1133+
/// The block ids are used as indices into a container, this
1134+
/// container is allocated with this number of elements. This means
1135+
/// that the value returned here must be the highest block index in
1136+
/// the function plus one. The block indices themselves need not be
1137+
/// consecutive.
11351138
fn num_blocks(&self) -> usize;
11361139

11371140
/// Get the index of the entry block.
@@ -1201,7 +1204,13 @@ pub trait Function {
12011204
/// value(s).
12021205
fn inst_clobbers(&self, insn: Inst) -> PRegSet;
12031206

1204-
/// Get the number of `VReg` in use in this function.
1207+
/// Number of entries to allocate [`VReg`] storage for.
1208+
///
1209+
/// The VReg ids are used as indices into a container, this
1210+
/// container is allocated with this number of elements. This
1211+
/// means that the value returned here must be the highest block
1212+
/// index in the function plus one. The vreg indices themselves
1213+
/// need not be consecutive.
12051214
fn num_vregs(&self) -> usize;
12061215

12071216
/// Get the VRegs for which we should generate value-location

src/postorder.rs

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -38,11 +38,12 @@ pub fn calculate<'a, SuccFn: Fn(Block) -> &'a [Block]>(
3838
while let Some(ref mut state) = stack.last_mut() {
3939
// Perform one action: push to new succ, skip an already-visited succ, or pop.
4040
if let Some(&succ) = state.succs.next() {
41-
let succ_visit = visited
42-
.get_mut(succ.index())
43-
.ok_or(RegAllocError::BB(succ))?;
44-
if !*succ_visit {
45-
*succ_visit = true;
41+
if succ.index() >= visited.len() {
42+
trace!("Block index {:?} exceeds f.num_blocks().", succ);
43+
return Err(RegAllocError::BB(succ));
44+
}
45+
if !visited[succ.index()] {
46+
visited[succ.index()] = true;
4647
stack.push(State {
4748
block: succ,
4849
succs: succ_blocks(succ).iter(),

src/ssa.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ pub fn validate_ssa<F: Function>(f: &F, cfginfo: &CFGInfo) -> Result<(), RegAllo
1717
let block = Block::new(block);
1818
let mut def = |vreg: VReg, inst| {
1919
if vreg.vreg() >= defined_in.len() {
20-
trace!("VRegs not numbered consecutively {:?}", vreg);
20+
trace!("VReg index {:?} exceeds exceeds f.num_vregs().", vreg);
2121
return Err(RegAllocError::SSA(vreg, inst));
2222
}
2323
if defined_in[vreg.vreg()].is_valid() {

0 commit comments

Comments
 (0)