@@ -100,12 +100,12 @@ impl LoopAnalysis {
100
100
101
101
impl LoopAnalysis {
102
102
/// Detects the loops in a function. Needs the control flow graph and the dominator tree.
103
- pub fn compute ( & mut self , func : & Function , cfg : & ControlFlowGraph , domtree : & DominatorTree ) {
103
+ pub fn compute ( & mut self , func : & mut Function , cfg : & ControlFlowGraph , domtree : & DominatorTree ) {
104
104
let _tt = timing:: loop_analysis ( ) ;
105
105
self . loops . clear ( ) ;
106
106
self . block_loop_map . clear ( ) ;
107
107
self . block_loop_map . resize ( func. dfg . num_blocks ( ) ) ;
108
- self . find_loop_headers ( cfg, domtree, & func. layout ) ;
108
+ self . find_loop_headers ( cfg, domtree, & mut func. layout ) ;
109
109
self . discover_loop_blocks ( cfg, domtree, & func. layout ) ;
110
110
self . valid = true ;
111
111
}
@@ -134,7 +134,7 @@ impl LoopAnalysis {
134
134
& mut self ,
135
135
cfg : & ControlFlowGraph ,
136
136
domtree : & DominatorTree ,
137
- layout : & Layout ,
137
+ layout : & mut Layout ,
138
138
) {
139
139
// We traverse the CFG in reverse postorder
140
140
for & block in domtree. cfg_postorder ( ) . iter ( ) . rev ( ) {
@@ -147,6 +147,8 @@ impl LoopAnalysis {
147
147
// This block is a loop header, so we create its associated loop
148
148
let lp = self . loops . push ( LoopData :: new ( block, None ) ) ;
149
149
self . block_loop_map [ block] = lp. into ( ) ;
150
+ // We also need to mark this block as a loop header in the layout.
151
+ layout. set_loop_header ( block) ;
150
152
break ;
151
153
// We break because we only need one back edge to identify a loop header.
152
154
}
@@ -270,7 +272,7 @@ mod tests {
270
272
let mut domtree = DominatorTree :: new ( ) ;
271
273
cfg. compute ( & func) ;
272
274
domtree. compute ( & func, & cfg) ;
273
- loop_analysis. compute ( & func, & cfg, & domtree) ;
275
+ loop_analysis. compute ( & mut func, & cfg, & domtree) ;
274
276
275
277
let loops = loop_analysis. loops ( ) . collect :: < Vec < Loop > > ( ) ;
276
278
assert_eq ! ( loops. len( ) , 2 ) ;
@@ -329,7 +331,7 @@ mod tests {
329
331
let mut domtree = DominatorTree :: new ( ) ;
330
332
cfg. compute ( & func) ;
331
333
domtree. compute ( & func, & cfg) ;
332
- loop_analysis. compute ( & func, & cfg, & domtree) ;
334
+ loop_analysis. compute ( & mut func, & cfg, & domtree) ;
333
335
334
336
let loops = loop_analysis. loops ( ) . collect :: < Vec < Loop > > ( ) ;
335
337
assert_eq ! ( loops. len( ) , 3 ) ;
0 commit comments