@@ -100,12 +100,17 @@ 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 (
104
+ & mut self ,
105
+ func : & mut Function ,
106
+ cfg : & ControlFlowGraph ,
107
+ domtree : & DominatorTree ,
108
+ ) {
104
109
let _tt = timing:: loop_analysis ( ) ;
105
110
self . loops . clear ( ) ;
106
111
self . block_loop_map . clear ( ) ;
107
112
self . block_loop_map . resize ( func. dfg . num_blocks ( ) ) ;
108
- self . find_loop_headers ( cfg, domtree, & func. layout ) ;
113
+ self . find_loop_headers ( cfg, domtree, & mut func. layout ) ;
109
114
self . discover_loop_blocks ( cfg, domtree, & func. layout ) ;
110
115
self . valid = true ;
111
116
}
@@ -134,7 +139,7 @@ impl LoopAnalysis {
134
139
& mut self ,
135
140
cfg : & ControlFlowGraph ,
136
141
domtree : & DominatorTree ,
137
- layout : & Layout ,
142
+ layout : & mut Layout ,
138
143
) {
139
144
// We traverse the CFG in reverse postorder
140
145
for & block in domtree. cfg_postorder ( ) . iter ( ) . rev ( ) {
@@ -147,6 +152,8 @@ impl LoopAnalysis {
147
152
// This block is a loop header, so we create its associated loop
148
153
let lp = self . loops . push ( LoopData :: new ( block, None ) ) ;
149
154
self . block_loop_map [ block] = lp. into ( ) ;
155
+ // We also need to mark this block as a loop header in the layout.
156
+ layout. set_loop_header ( block) ;
150
157
break ;
151
158
// We break because we only need one back edge to identify a loop header.
152
159
}
@@ -270,7 +277,7 @@ mod tests {
270
277
let mut domtree = DominatorTree :: new ( ) ;
271
278
cfg. compute ( & func) ;
272
279
domtree. compute ( & func, & cfg) ;
273
- loop_analysis. compute ( & func, & cfg, & domtree) ;
280
+ loop_analysis. compute ( & mut func, & cfg, & domtree) ;
274
281
275
282
let loops = loop_analysis. loops ( ) . collect :: < Vec < Loop > > ( ) ;
276
283
assert_eq ! ( loops. len( ) , 2 ) ;
@@ -329,7 +336,7 @@ mod tests {
329
336
let mut domtree = DominatorTree :: new ( ) ;
330
337
cfg. compute ( & func) ;
331
338
domtree. compute ( & func, & cfg) ;
332
- loop_analysis. compute ( & func, & cfg, & domtree) ;
339
+ loop_analysis. compute ( & mut func, & cfg, & domtree) ;
333
340
334
341
let loops = loop_analysis. loops ( ) . collect :: < Vec < Loop > > ( ) ;
335
342
assert_eq ! ( loops. len( ) , 3 ) ;
0 commit comments