@@ -184,7 +184,7 @@ let calculate_live_bitvectors
184
184
(cx :ctxt )
185
185
: ((Bits.t array) * (Bits.t array)) =
186
186
187
- log cx " calculating live bitvectors" ;
187
+ iflog cx ( fun _ -> log cx " calculating live bitvectors" ) ;
188
188
189
189
let quads = cx.ctxt_quads in
190
190
let n_quads = Array. length quads in
@@ -198,10 +198,9 @@ let calculate_live_bitvectors
198
198
let (quad_uncond_jmp:bool array ) = Array. make n_quads false in
199
199
let (quad_jmp_targs:(Il.label list) array ) = Array. make n_quads [] in
200
200
201
- let outer_changed = ref true in
202
-
203
201
(* Working bit-vector. *)
204
202
let scratch = new_bitv() in
203
+ let changed = ref true in
205
204
206
205
(* bit-vector helpers. *)
207
206
(* Setup pass. *)
@@ -217,62 +216,39 @@ let calculate_live_bitvectors
217
216
(quad_defined_vregs q)
218
217
done ;
219
218
220
- while ! outer_changed do
221
- iflog cx (fun _ -> log cx " iterating outer bitvector calculation" );
222
- outer_changed := false ;
223
- for i = 0 to n_quads - 1 do
224
- Bits. clear live_in_vregs.(i);
225
- Bits. clear live_out_vregs.(i)
219
+ while ! changed do
220
+ changed := false ;
221
+ iflog cx
222
+ (fun _ ->
223
+ log cx " iterating inner bitvector calculation over %d quads"
224
+ n_quads);
225
+ for i = n_quads - 1 downto 0 do
226
+
227
+ let note_change b = if b then changed := true in
228
+ let live_in = live_in_vregs.(i) in
229
+ let live_out = live_out_vregs.(i) in
230
+ let used = quad_used_vrs.(i) in
231
+ let defined = quad_defined_vrs.(i) in
232
+
233
+ (* Union in the vregs we use. *)
234
+ note_change (Bits. union live_in used);
235
+
236
+ (* Union in all our jump targets. *)
237
+ List. iter
238
+ (fun i -> note_change (Bits. union live_out live_in_vregs.(i)))
239
+ (quad_jmp_targs.(i));
240
+
241
+ (* Union in our block successor if we have one *)
242
+ if i < (n_quads - 1 ) && (not (quad_uncond_jmp.(i)))
243
+ then note_change (Bits. union live_out live_in_vregs.(i+ 1 ));
244
+
245
+ (* Propagate live-out to live-in on anything we don't define. *)
246
+ ignore (Bits. copy scratch defined);
247
+ Bits. invert scratch;
248
+ ignore (Bits. intersect scratch live_out);
249
+ note_change (Bits. union live_in scratch);
250
+
226
251
done ;
227
- let inner_changed = ref true in
228
- while ! inner_changed do
229
- inner_changed := false ;
230
- iflog cx
231
- (fun _ ->
232
- log cx " iterating inner bitvector calculation over %d quads"
233
- n_quads);
234
- for i = n_quads - 1 downto 0 do
235
-
236
- let note_change b = if b then inner_changed := true in
237
- let live_in = live_in_vregs.(i) in
238
- let live_out = live_out_vregs.(i) in
239
- let used = quad_used_vrs.(i) in
240
- let defined = quad_defined_vrs.(i) in
241
-
242
- (* Union in the vregs we use. *)
243
- note_change (Bits. union live_in used);
244
-
245
- (* Union in all our jump targets. *)
246
- List. iter
247
- (fun i -> note_change (Bits. union live_out live_in_vregs.(i)))
248
- (quad_jmp_targs.(i));
249
-
250
- (* Union in our block successor if we have one *)
251
- if i < (n_quads - 1 ) && (not (quad_uncond_jmp.(i)))
252
- then note_change (Bits. union live_out live_in_vregs.(i+ 1 ));
253
-
254
- (* Propagate live-out to live-in on anything we don't define. *)
255
- ignore (Bits. copy scratch defined);
256
- Bits. invert scratch;
257
- ignore (Bits. intersect scratch live_out);
258
- note_change (Bits. union live_in scratch);
259
-
260
- done
261
- done ;
262
- let kill_mov_to_dead_target i q =
263
- match q.Il. quad_body with
264
- Il. Unary { Il. unary_op =uop ;
265
- Il. unary_dst =Il. Reg (Il. Vreg v , _ ) }
266
- when
267
- ((Il. is_mov uop) &&
268
- not (Bits. get live_out_vregs.(i) v)) ->
269
- begin
270
- kill_quad i cx;
271
- outer_changed := true ;
272
- end
273
- | _ -> ()
274
- in
275
- Array. iteri kill_mov_to_dead_target quads
276
252
done ;
277
253
iflog cx
278
254
begin
@@ -340,7 +316,10 @@ let dump_quads cx =
340
316
None -> " "
341
317
| Some f -> f.fixup_name ^ " :"
342
318
in
343
- log cx " [%s] %s %s" (padded_num i len) (padded_str lab (! maxlablen)) qs
319
+ iflog cx
320
+ (fun _ ->
321
+ log cx " [%s] %s %s"
322
+ (padded_num i len) (padded_str lab (! maxlablen)) qs)
344
323
done
345
324
;;
346
325
@@ -449,8 +428,11 @@ let reg_alloc
449
428
in
450
429
let spill_mem = spill_slot spill_idx in
451
430
let spill_cell = Il. Mem (spill_mem, Il. ScalarTy word_ty) in
452
- log cx " spilling <%d> from %s to %s"
453
- vreg (hr_str hreg) (string_of_mem hr_str spill_mem);
431
+ iflog cx
432
+ (fun _ ->
433
+ log cx " spilling <%d> from %s to %s"
434
+ vreg (hr_str hreg) (string_of_mem
435
+ hr_str spill_mem));
454
436
prepend (Il. mk_quad
455
437
(Il. umov spill_cell (Il. Cell (hr hreg))));
456
438
else ()
0 commit comments