File tree Expand file tree Collapse file tree 1 file changed +12
-0
lines changed
compiler/rustc_middle/src/mir Expand file tree Collapse file tree 1 file changed +12
-0
lines changed Original file line number Diff line number Diff 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]
You can’t perform that action at this time.
0 commit comments