@@ -40,6 +40,11 @@ let rpo : RPO.t ref = ref RPO.empty
4040
4141(* Spill environment: used to build the basic environment, etc. *)
4242module SpillEnv = struct
43+ (* *
44+ Data structure for data-flow analysis.
45+ Here W stands for working registers (those aren't spilled);
46+ S stands for spilled registers.
47+ *)
4348 type spill_info =
4449 { entryW : SlotSet .t
4550 ; exitW : SlotSet .t
@@ -145,7 +150,7 @@ let compute_every_inst_nextuse (bl : VBlockLabel.t) : int SlotMap.t Vec.t =
145150 let block = VProg. get_block ! vprog bl in
146151 let b_liveinfo = Liveness. get_liveinfo ! live_info bl in
147152 let n = Vec. length block.body in
148- let nextUse = Vec. make ~dummy: SlotMap. empty (n + 1 ) in
153+ let nextUse = Vec. of_list ( List. init (n + 1 ) ( fun _ -> SlotMap. empty) ) in
149154
150155 (* 1. Initialization *)
151156 SlotMap. iter b_liveinfo.exitNextUse (fun var dist ->
@@ -439,7 +444,7 @@ let apply_min_algorithm (bl : VBlockLabel.t) (nextUse : int SlotMap.t Vec.t) =
439444
440445 (* 3. Reload/Spill to be inserted before each instruction, including before Term, so it is n+1 *)
441446 let body_size = Vec. length block.body in
442- let addInsts = Vec. make ~dummy: ( Vec. empty () ) ( body_size + 1 ) in
447+ let addInsts = Vec. of_list ( List. init ( body_size + 1 ) ( fun _ -> Vec. empty () ) ) in
443448
444449 (* 4. Common apply_inner function, but for clarity, the function to adjust k is passed in *)
445450 let apply_inner
@@ -472,7 +477,8 @@ let apply_min_algorithm (bl : VBlockLabel.t) (nextUse : int SlotMap.t Vec.t) =
472477 SlotSet. iter dests (fun var -> w := SlotSet. add ! w var);
473478 let protected = dests in
474479 (* At this point, protected protects the registers being defined *)
475- let _ = limit_func nextUse w s spill protected (i + 1 ) adjust_k in
480+ if i <> body_size then
481+ limit_func nextUse w s spill protected (i + 1 ) adjust_k;
476482
477483 (* e. Insert reload/spill instructions *)
478484 SlotSet. iter ! reload (fun var -> Vec. push addInsts.! [i] (Inst. generate_reload var));
@@ -580,9 +586,10 @@ let spill_reload_func (f_label : VFuncLabel.t) (func : VFunc.t) =
580586;;
581587
582588(* Main function: used to handle the entire program *)
583- let spill_regs (vprog_in : VProg.t ) (rpo : RPO.t ) =
589+ let spill_regs (vprog_in : VProg.t ) (rpo_arg : RPO.t ) =
584590 vprog := vprog_in;
585- live_info := Liveness. liveness_analysis ! vprog rpo;
591+ live_info := Liveness. liveness_analysis ! vprog rpo_arg;
592+ rpo := rpo_arg;
586593 VFuncMap. iter ! vprog.funcs spill_reload_func;
587594 ()
588595;;
0 commit comments