Skip to content

Commit 066d381

Browse files
committed
add RPO to BB CFG cache
1 parent e596579 commit 066d381

File tree

1 file changed

+12
-0
lines changed

1 file changed

+12
-0
lines changed

compiler/rustc_middle/src/mir/basic_blocks.rs

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ struct Cache {
2727
switch_sources: OnceCell<SwitchSources>,
2828
is_cyclic: OnceCell<bool>,
2929
postorder: OnceCell<Vec<BasicBlock>>,
30+
reverse_postorder: OnceCell<Vec<BasicBlock>>,
3031
dominators: OnceCell<Dominators<BasicBlock>>,
3132
}
3233

@@ -70,6 +71,17 @@ impl<'tcx> BasicBlocks<'tcx> {
7071
})
7172
}
7273

74+
/// Returns basic blocks in a reverse postorder.
75+
#[inline]
76+
pub fn reverse_postorder(&self) -> &[BasicBlock] {
77+
self.cache.reverse_postorder.get_or_init(|| {
78+
let mut rpo: Vec<_> =
79+
Postorder::new(&self.basic_blocks, START_BLOCK).map(|(bb, _)| bb).collect();
80+
rpo.reverse();
81+
rpo
82+
})
83+
}
84+
7385
/// `switch_sources()[&(target, switch)]` returns a list of switch
7486
/// values that lead to a `target` block from a `switch` block.
7587
#[inline]

0 commit comments

Comments
 (0)