add RPO to BB CFG cache
This commit is contained in:
parent
e596579066
commit
066d38190b
@ -27,6 +27,7 @@ struct Cache {
|
||||
switch_sources: OnceCell<SwitchSources>,
|
||||
is_cyclic: OnceCell<bool>,
|
||||
postorder: OnceCell<Vec<BasicBlock>>,
|
||||
reverse_postorder: OnceCell<Vec<BasicBlock>>,
|
||||
dominators: OnceCell<Dominators<BasicBlock>>,
|
||||
}
|
||||
|
||||
@ -70,6 +71,17 @@ impl<'tcx> BasicBlocks<'tcx> {
|
||||
})
|
||||
}
|
||||
|
||||
/// Returns basic blocks in a reverse postorder.
|
||||
#[inline]
|
||||
pub fn reverse_postorder(&self) -> &[BasicBlock] {
|
||||
self.cache.reverse_postorder.get_or_init(|| {
|
||||
let mut rpo: Vec<_> =
|
||||
Postorder::new(&self.basic_blocks, START_BLOCK).map(|(bb, _)| bb).collect();
|
||||
rpo.reverse();
|
||||
rpo
|
||||
})
|
||||
}
|
||||
|
||||
/// `switch_sources()[&(target, switch)]` returns a list of switch
|
||||
/// values that lead to a `target` block from a `switch` block.
|
||||
#[inline]
|
||||
|
Loading…
x
Reference in New Issue
Block a user