Skip to content

Commit 75a6550

Browse files
committed
---
yaml --- r: 658 b: refs/heads/master c: 79dc07d h: refs/heads/master v: v3
1 parent 7addbd0 commit 75a6550

File tree

4 files changed

+41
-27
lines changed

4 files changed

+41
-27
lines changed

[refs]

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,2 @@
11
---
2-
refs/heads/master: a9e2327a18e782df524c14dc42910d61a4785324
2+
refs/heads/master: 79dc07d6487612ebf9ac62e43a5729ea774488b9

trunk/src/boot/be/abi.ml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -118,7 +118,7 @@ type abi =
118118
abi_str_of_hardreg: (int -> string);
119119

120120
abi_emit_target_specific: (Il.emitter -> Il.quad -> unit);
121-
abi_constrain_vregs: (Il.quad -> Bits.t array -> unit);
121+
abi_constrain_vregs: (Il.quad -> (Il.vreg,Bits.t) Hashtbl.t -> unit);
122122

123123
abi_emit_fn_prologue: (Il.emitter
124124
-> Common.size (* framesz *)

trunk/src/boot/be/ra.ml

Lines changed: 32 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -324,11 +324,11 @@ let dump_quads cx =
324324

325325
let calculate_vreg_constraints
326326
(cx:ctxt)
327-
(constraints:Bits.t array)
327+
(constraints:(Il.vreg,Bits.t) Hashtbl.t)
328328
(q:quad)
329329
: unit =
330330
let abi = cx.ctxt_abi in
331-
Array.iter (fun c -> Bits.clear c; Bits.invert c) constraints;
331+
Hashtbl.clear constraints;
332332
abi.Abi.abi_constrain_vregs q constraints;
333333
iflog cx
334334
begin
@@ -341,9 +341,12 @@ let calculate_vreg_constraints
341341
match r with
342342
Il.Hreg _ -> ()
343343
| Il.Vreg v ->
344-
let hregs = Bits.to_list constraints.(v) in
345-
log cx "<v%d> constrained to hregs: [%s]"
346-
v (list_to_str hregs hr_str)
344+
match htab_search constraints v with
345+
None -> log cx "<v%d> unconstrained" v
346+
| Some c ->
347+
let hregs = Bits.to_list c in
348+
log cx "<v%d> constrained to hregs: [%s]"
349+
v (list_to_str hregs hr_str)
347350
end;
348351
r
349352
in
@@ -376,10 +379,9 @@ let reg_alloc
376379
let (live_in_vregs, live_out_vregs) =
377380
calculate_live_bitvectors cx
378381
in
379-
let n_vregs = cx.ctxt_n_vregs in
380-
let n_hregs = abi.Abi.abi_n_hardregs in
381-
let (vreg_constraints:Bits.t array) = (* vreg idx -> hreg bits.t *)
382-
Array.init n_vregs (fun _ -> Bits.create n_hregs true)
382+
(* vreg idx -> hreg bits.t *)
383+
let (vreg_constraints:(Il.vreg,Bits.t) Hashtbl.t) =
384+
Hashtbl.create 0
383385
in
384386
let inactive_hregs = ref [] in (* [hreg] *)
385387
let active_hregs = ref [] in (* [hreg] *)
@@ -497,6 +499,13 @@ let reg_alloc
497499
else ()
498500
in
499501

502+
let get_vreg_constraints v =
503+
match htab_search vreg_constraints v with
504+
None -> all_hregs
505+
| Some c -> c
506+
in
507+
508+
500509
let use_vreg def i vreg =
501510
if Hashtbl.mem vreg_to_hreg vreg
502511
then
@@ -508,18 +517,19 @@ let reg_alloc
508517
end
509518
else
510519
let hreg =
511-
let constrs = vreg_constraints.(vreg) in
512-
match select_constrained constrs (!inactive_hregs) with
513-
None ->
514-
let h = spill_constrained constrs i in
515-
iflog cx
516-
(fun _ -> log cx "selected %s to spill and use for <v%d>"
517-
(hr_str h) vreg);
520+
let constrs = get_vreg_constraints vreg in
521+
match select_constrained constrs (!inactive_hregs) with
522+
None ->
523+
let h = spill_constrained constrs i in
524+
iflog cx
525+
(fun _ ->
526+
log cx "selected %s to spill and use for <v%d>"
527+
(hr_str h) vreg);
528+
h
529+
| Some h ->
530+
iflog cx (fun _ -> log cx "selected inactive %s for <v%d>"
531+
(hr_str h) vreg);
518532
h
519-
| Some h ->
520-
iflog cx (fun _ -> log cx "selected inactive %s for <v%d>"
521-
(hr_str h) vreg);
522-
h
523533
in
524534
inactive_hregs :=
525535
List.filter (fun x -> x != hreg) (!inactive_hregs);
@@ -569,15 +579,15 @@ let reg_alloc
569579
* This is awful but it saves us from cached/constrained
570580
* interference as was found in issue #152. *)
571581
if List.exists
572-
(fun v -> not (Bits.equal vreg_constraints.(v) all_hregs))
582+
(fun v -> not (Bits.equal (get_vreg_constraints v) all_hregs))
573583
used
574584
then
575585
begin
576586
(* Regfence. *)
577587
spill_all_regs i;
578588
(* Check for over-constrained-ness after any such regfence. *)
579589
let vreg_constrs v =
580-
(v, Bits.to_list (vreg_constraints.(v)))
590+
(v, Bits.to_list (get_vreg_constraints v))
581591
in
582592
let constrs = List.map vreg_constrs (used @ defined) in
583593
let constrs_collide (v1,c1) =

trunk/src/boot/be/x86.ml

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -385,7 +385,7 @@ let emit_target_specific
385385
;;
386386

387387

388-
let constrain_vregs (q:Il.quad) (hregs:Bits.t array) : unit =
388+
let constrain_vregs (q:Il.quad) (hregs:(Il.vreg,Bits.t) Hashtbl.t) : unit =
389389

390390
let involves_8bit_cell =
391391
let b = ref false in
@@ -402,14 +402,18 @@ let constrain_vregs (q:Il.quad) (hregs:Bits.t array) : unit =
402402
!b
403403
in
404404

405+
let get_hregs v =
406+
htab_search_or_add hregs v (fun _ -> Bits.create n_hardregs true)
407+
in
408+
405409
let qp_mem _ m = m in
406410
let qp_cell _ c =
407411
begin
408412
match c with
409413
Il.Reg (Il.Vreg v, _) when involves_8bit_cell ->
410414
(* 8-bit register cells must only be al, cl, dl, bl.
411415
* Not esi/edi. *)
412-
let hv = hregs.(v) in
416+
let hv = get_hregs v in
413417
List.iter (fun bad -> Bits.set hv bad false) [esi; edi]
414418
| _ -> ()
415419
end;
@@ -425,7 +429,7 @@ let constrain_vregs (q:Il.quad) (hregs:Bits.t array) : unit =
425429
begin
426430
match b.Il.binary_rhs with
427431
Il.Cell (Il.Reg (Il.Vreg v, _)) ->
428-
let hv = hregs.(v) in
432+
let hv = get_hregs v in
429433
(* Shift src has to be ecx. *)
430434
List.iter
431435
(fun bad -> Bits.set hv bad false)

0 commit comments

Comments
 (0)