@@ -324,11 +324,11 @@ let dump_quads cx =
324
324
325
325
let calculate_vreg_constraints
326
326
(cx :ctxt )
327
- (constraints :Bits.t array )
327
+ (constraints :(Il.vreg, Bits.t) Hashtbl.t )
328
328
(q :quad )
329
329
: unit =
330
330
let abi = cx.ctxt_abi in
331
- Array. iter ( fun c -> Bits. clear c; Bits. invert c) constraints;
331
+ Hashtbl. clear constraints;
332
332
abi.Abi. abi_constrain_vregs q constraints;
333
333
iflog cx
334
334
begin
@@ -341,9 +341,12 @@ let calculate_vreg_constraints
341
341
match r with
342
342
Il. Hreg _ -> ()
343
343
| 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)
347
350
end ;
348
351
r
349
352
in
@@ -376,10 +379,9 @@ let reg_alloc
376
379
let (live_in_vregs, live_out_vregs) =
377
380
calculate_live_bitvectors cx
378
381
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
383
385
in
384
386
let inactive_hregs = ref [] in (* [hreg] *)
385
387
let active_hregs = ref [] in (* [hreg] *)
@@ -497,6 +499,13 @@ let reg_alloc
497
499
else ()
498
500
in
499
501
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
+
500
509
let use_vreg def i vreg =
501
510
if Hashtbl. mem vreg_to_hreg vreg
502
511
then
@@ -508,18 +517,19 @@ let reg_alloc
508
517
end
509
518
else
510
519
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);
518
532
h
519
- | Some h ->
520
- iflog cx (fun _ -> log cx " selected inactive %s for <v%d>"
521
- (hr_str h) vreg);
522
- h
523
533
in
524
534
inactive_hregs :=
525
535
List. filter (fun x -> x != hreg) (! inactive_hregs);
@@ -569,15 +579,15 @@ let reg_alloc
569
579
* This is awful but it saves us from cached/constrained
570
580
* interference as was found in issue #152. *)
571
581
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))
573
583
used
574
584
then
575
585
begin
576
586
(* Regfence. *)
577
587
spill_all_regs i;
578
588
(* Check for over-constrained-ness after any such regfence. *)
579
589
let vreg_constrs v =
580
- (v, Bits. to_list (vreg_constraints.(v) ))
590
+ (v, Bits. to_list (get_vreg_constraints v ))
581
591
in
582
592
let constrs = List. map vreg_constrs (used @ defined) in
583
593
let constrs_collide (v1 ,c1 ) =
0 commit comments