Commit 4b61b098 authored by Cyril SIX's avatar Cyril SIX
Browse files

Adding more precise heuristic measures

parent 5500fccc
...@@ -44,12 +44,35 @@ let stats_nb_missed_opportunities = ref 0 ...@@ -44,12 +44,35 @@ let stats_nb_missed_opportunities = ref 0
(* we predicted something (say Some true) but the profiling preferred not to predict anything (None) *) (* we predicted something (say Some true) but the profiling preferred not to predict anything (None) *)
let stats_nb_overpredict = ref 0 let stats_nb_overpredict = ref 0
(* heuristic specific counters *)
let wrong_opcode = ref 0
let wrong_return = ref 0
let wrong_loop2 = ref 0
let wrong_loop = ref 0
let wrong_call = ref 0
let right_opcode = ref 0
let right_return = ref 0
let right_loop2 = ref 0
let right_loop = ref 0
let right_call = ref 0
let reset_stats () = begin let reset_stats () = begin
stats_nb_total := 0; stats_nb_total := 0;
stats_nb_correct_predicts := 0; stats_nb_correct_predicts := 0;
stats_nb_mispredicts := 0; stats_nb_mispredicts := 0;
stats_nb_missed_opportunities := 0; stats_nb_missed_opportunities := 0;
stats_nb_overpredict := 0; stats_nb_overpredict := 0;
wrong_opcode := 0;
wrong_return := 0;
wrong_loop2 := 0;
wrong_loop := 0;
wrong_call := 0;
right_opcode := 0;
right_return := 0;
right_loop2 := 0;
right_loop := 0;
right_call := 0;
end end
let incr theref = theref := !theref + 1 let incr theref = theref := !theref + 1
...@@ -62,7 +85,12 @@ let write_stats_oc () = ...@@ -62,7 +85,12 @@ let write_stats_oc () =
match !stats_oc with match !stats_oc with
| None -> () | None -> ()
| Some oc -> begin | Some oc -> begin
Printf.fprintf oc "%d %d %d %d %d\n" !stats_nb_total !stats_nb_correct_predicts !stats_nb_mispredicts !stats_nb_missed_opportunities !stats_nb_overpredict; Printf.fprintf oc "%d %d %d %d %d %d %d %d %d %d %d %d %d %d %d\n" !stats_nb_total
!stats_nb_correct_predicts !stats_nb_mispredicts !stats_nb_missed_opportunities
!stats_nb_overpredict
!wrong_opcode !wrong_return !wrong_loop2 !wrong_loop !wrong_call
!right_opcode !right_return !right_loop2 !right_loop !right_call
;
close_out oc close_out oc
end end
...@@ -446,11 +474,43 @@ let get_directions f code entrypoint = begin ...@@ -446,11 +474,43 @@ let get_directions f code entrypoint = begin
do_return_heuristic; do_loop2_heuristic loop_info n; do_loop_heuristic; do_call_heuristic; do_return_heuristic; do_loop2_heuristic loop_info n; do_loop_heuristic; do_call_heuristic;
(* do_store_heuristic *) ] in (* do_store_heuristic *) ] in
let preferred = ref None in let preferred = ref None in
let current_heuristic = ref 0 in
begin begin
debug "Deciding condition for RTL node %d\n" (P.to_int n); debug "Deciding condition for RTL node %d\n" (P.to_int n);
List.iter (fun do_heur -> List.iter (fun do_heur ->
match !preferred with match !preferred with
| None -> preferred := do_heur code cond ifso ifnot is_loop_header | None -> begin
preferred := do_heur code cond ifso ifnot is_loop_header;
if stats_oc_recording () then begin
(* Getting stats about mispredictions from each heuristic *)
(match !preferred, pred with
| Some false, Some true
| Some true, Some false
(* | Some _, None *) (* Uncomment for overpredicts *)
-> begin
match !current_heuristic with
| 0 -> incr wrong_opcode
| 1 -> incr wrong_return
| 2 -> incr wrong_loop2
| 3 -> incr wrong_loop
| 4 -> incr wrong_call
| _ -> failwith "Shouldn't happen"
end
| Some false, Some false
| Some true, Some true -> begin
match !current_heuristic with
| 0 -> incr right_opcode
| 1 -> incr right_return
| 2 -> incr right_loop2
| 3 -> incr right_loop
| 4 -> incr right_call
| _ -> failwith "Shouldn't happen"
end
| _ -> ()
);
incr current_heuristic
end
end
| Some _ -> () | Some _ -> ()
) heuristics; ) heuristics;
directions := PTree.set n !preferred !directions; directions := PTree.set n !preferred !directions;
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment