@@ -51,38 +51,30 @@ impl Cache {
51
51
52
52
pub fn predecessors ( & self , mir : & Mir ) -> Ref < IndexVec < Block , Vec < Block > > > {
53
53
if self . predecessors . borrow ( ) . is_none ( ) {
54
- * self . predecessors . borrow_mut ( ) = Some ( calculate_predecessors ( mir) ) ;
54
+ * self . predecessors . borrow_mut ( ) = Some ( self . calculate_predecessors ( mir) ) ;
55
55
}
56
56
57
57
Ref :: map ( self . predecessors . borrow ( ) , |p| p. as_ref ( ) . unwrap ( ) )
58
58
}
59
59
60
- pub fn successors ( & self , mir : & Mir ) -> Ref < IndexVec < Block , Vec < Block > > > {
61
- if self . successors . borrow ( ) . is_none ( ) {
62
- * self . successors . borrow_mut ( ) = Some ( calculate_successors ( mir) ) ;
60
+ fn calculate_predecessors ( & self , mir : & Mir ) -> IndexVec < Block , Vec < Block > > {
61
+ let mut result = IndexVec :: from_elem ( vec ! [ ] , mir. basic_blocks ( ) ) ;
62
+ for ( bb, bbs) in self . successors ( mir) . iter_enumerated ( ) {
63
+ for & tgt in bbs {
64
+ result[ tgt] . push ( bb) ;
65
+ }
63
66
}
64
67
65
- Ref :: map ( self . successors . borrow ( ) , |p| p . as_ref ( ) . unwrap ( ) )
68
+ result
66
69
}
67
- }
68
70
69
- fn calculate_predecessors ( mir : & Mir ) -> IndexVec < Block , Vec < Block > > {
70
- let mut result = IndexVec :: from_elem ( vec ! [ ] , mir. basic_blocks ( ) ) ;
71
- for ( bb, data) in mir. basic_blocks ( ) . iter_enumerated ( ) {
72
- for stmt in & data. statements {
73
- for & tgt in stmt. successors ( ) . iter ( ) {
74
- result[ tgt] . push ( bb) ;
75
- }
71
+ pub fn successors ( & self , mir : & Mir ) -> Ref < IndexVec < Block , Vec < Block > > > {
72
+ if self . successors . borrow ( ) . is_none ( ) {
73
+ * self . successors . borrow_mut ( ) = Some ( calculate_successors ( mir) ) ;
76
74
}
77
75
78
- if let Some ( ref term) = data. terminator {
79
- for & tgt in term. successors ( ) . iter ( ) {
80
- result[ tgt] . push ( bb) ;
81
- }
82
- }
76
+ Ref :: map ( self . successors . borrow ( ) , |p| p. as_ref ( ) . unwrap ( ) )
83
77
}
84
-
85
- result
86
78
}
87
79
88
80
fn calculate_successors ( mir : & Mir ) -> IndexVec < Block , Vec < Block > > {
0 commit comments