|
@@ -488,7 +488,7 @@ let code_graph (f:fundecl) =
|
|
in
|
|
in
|
|
blocks_pos, make_block 0
|
|
blocks_pos, make_block 0
|
|
|
|
|
|
-let optimize dump (f:fundecl) =
|
|
|
|
|
|
+let optimize dump get_str (f:fundecl) =
|
|
let nregs = Array.length f.regs in
|
|
let nregs = Array.length f.regs in
|
|
let old_code = match dump with None -> f.code | Some _ -> Array.copy f.code in
|
|
let old_code = match dump with None -> f.code | Some _ -> Array.copy f.code in
|
|
let op index = f.code.(index) in
|
|
let op index = f.code.(index) in
|
|
@@ -743,6 +743,8 @@ let optimize dump (f:fundecl) =
|
|
|
|
|
|
(* done *)
|
|
(* done *)
|
|
if dump <> None then begin
|
|
if dump <> None then begin
|
|
|
|
+ let assigns = Hashtbl.create 0 in
|
|
|
|
+ Array.iter (fun (var,pos) -> if pos >= 0 then Hashtbl.replace assigns pos var) f.assigns;
|
|
let rec loop i block =
|
|
let rec loop i block =
|
|
if i = Array.length f.code then () else
|
|
if i = Array.length f.code then () else
|
|
let block = try
|
|
let block = try
|
|
@@ -765,10 +767,17 @@ let optimize dump (f:fundecl) =
|
|
live_loop (r + 1) (if is_live r i then r :: l else l)
|
|
live_loop (r + 1) (if is_live r i then r :: l else l)
|
|
in
|
|
in
|
|
let live = "LIVE=" ^ String.concat "," (List.map string_of_int (live_loop 0 [])) in
|
|
let live = "LIVE=" ^ String.concat "," (List.map string_of_int (live_loop 0 [])) in
|
|
- write (Printf.sprintf "\t@%-3X %-20s %-20s%s" i (ostr string_of_int old) (if opcode_eq old op then "" else ostr string_of_int op) live);
|
|
|
|
|
|
+ let var_set = (try let v = Hashtbl.find assigns i in "set " ^ get_str v with Not_found -> "") in
|
|
|
|
+ write (Printf.sprintf "\t@%-3X %-20s %-20s %-20s %s" i (ostr string_of_int old) (if opcode_eq old op then "" else ostr string_of_int op) var_set live);
|
|
loop (i + 1) block
|
|
loop (i + 1) block
|
|
in
|
|
in
|
|
write (Printf.sprintf "%s@%d" (fundecl_name f) f.findex);
|
|
write (Printf.sprintf "%s@%d" (fundecl_name f) f.findex);
|
|
|
|
+ let rec loop_arg = function
|
|
|
|
+ | [] -> []
|
|
|
|
+ | (_,p) :: _ when p >= 0 -> []
|
|
|
|
+ | (str,p) :: l -> (get_str str ^ ":" ^ string_of_int p) :: loop_arg l
|
|
|
|
+ in
|
|
|
|
+ write (Printf.sprintf "ARGS = %s\n" (String.concat ", " (loop_arg (Array.to_list f.assigns))));
|
|
if reg_remap then begin
|
|
if reg_remap then begin
|
|
for i=0 to nregs-1 do
|
|
for i=0 to nregs-1 do
|
|
write (Printf.sprintf "\tr%-2d %-10s%s" i (tstr f.regs.(i)) (if reg_map.(i) < 0 then " unused" else if reg_map.(i) = i then "" else Printf.sprintf " r%-2d" reg_map.(i)))
|
|
write (Printf.sprintf "\tr%-2d %-10s%s" i (tstr f.regs.(i)) (if reg_map.(i) < 0 then " unused" else if reg_map.(i) = i then "" else Printf.sprintf " r%-2d" reg_map.(i)))
|