Skip to content

Commit

Permalink
Update to core>=0.16
Browse files Browse the repository at this point in the history
  • Loading branch information
acieroid committed Jan 16, 2024
1 parent 674f460 commit bd35c80
Show file tree
Hide file tree
Showing 4 changed files with 48 additions and 48 deletions.
34 changes: 17 additions & 17 deletions lib/analysis/slice/slicing.ml
Original file line number Diff line number Diff line change
Expand Up @@ -35,33 +35,33 @@ end

type preanalysis_results = {
control_dependencies : Instr.Label.Set.t Instr.Label.Map.t;
control_time : Time.Span.t;
control_time : Time_float.Span.t;
data_dependencies : Use_def.UseDefChains.t;
data_time : Time.Span.t;
data_time : Time_float.Span.t;
mem_dependencies : Memory_deps.t;
mem_time : Time.Span.t;
mem_time : Time_float.Span.t;
global_set_instructions : InSlice.Set.t;
global_time : Time.Span.t;
global_time : Time_float.Span.t;
}

(** Performs the pre-analysis phase in order to slice a function, according to any slicing criterion *)
let preanalysis (cfg : Spec.t Cfg.t) (cfg_instructions : Spec.t Instr.t Instr.Label.Map.t) : preanalysis_results =
let t0 = Time.now () in
let t0 = Time_float.now () in
let control_dependencies = Control_deps.control_deps_exact_instrs cfg in
let t1 = Time.now () in
let t1 = Time_float.now () in
let (_, _, data_dependencies) = Use_def.make cfg in
let t2 = Time.now () in
let t2 = Time_float.now () in
let mem_dependencies = Memory_deps.make cfg in
let t3 = Time.now () in
let t3 = Time_float.now () in
let global_set_instructions = InSlice.Set.of_list (List.map ~f:(fun label -> InSlice.{ label; reason = None })
(Instr.Label.Map.keys (Instr.Label.Map.filter cfg_instructions ~f:(function
| Data { instr = GlobalSet _; _ } -> true
| _ -> false)))) in
let t4 = Time.now () in
let control_time = Time.diff t1 t0 in
let data_time = Time.diff t2 t1 in
let mem_time = Time.diff t3 t2 in
let global_time = Time.diff t4 t3 in
let t4 = Time_float.now () in
let control_time = Time_float.diff t1 t0 in
let data_time = Time_float.diff t2 t1 in
let mem_time = Time_float.diff t3 t2 in
let global_time = Time_float.diff t4 t3 in
{ control_dependencies; control_time;
data_dependencies; data_time;
mem_dependencies; mem_time;
Expand All @@ -72,9 +72,9 @@ let preanalysis (cfg : Spec.t Cfg.t) (cfg_instructions : Spec.t Instr.t Instr.La
slicing criterion `criterion`, encoded as an instruction index. Returns the
set of instructions that are part of the slice, as a set of instruction
labels. *)
let instructions_to_keep (cfg : Spec.t Cfg.t) (cfg_instructions : Spec.t Instr.t Instr.Label.Map.t) (preanalysis : preanalysis_results) (criteria : Instr.Label.Set.t) : (Instr.Label.Set.t * (Time.Span.t * Time.Span.t * Time.Span.t * Time.Span.t * Time.Span.t)) =
let instructions_to_keep (cfg : Spec.t Cfg.t) (cfg_instructions : Spec.t Instr.t Instr.Label.Map.t) (preanalysis : preanalysis_results) (criteria : Instr.Label.Set.t) : (Instr.Label.Set.t * (Time_float.Span.t * Time_float.Span.t * Time_float.Span.t * Time_float.Span.t * Time_float.Span.t)) =
Log.info (Printf.sprintf "Slicing with criteria %s" (Instr.Label.Set.to_string criteria));
let t0 = Time.now () in
let t0 = Time_float.now () in
let rec loop (worklist : InSlice.Set.t) (slice : Instr.Label.Set.t) (visited : InSlice.Set.t) : Instr.Label.Set.t =
(* Perform backward slicing as follows:
Given an instruction as the slicing criterion (we can derive variable uses from instructions),
Expand Down Expand Up @@ -165,8 +165,8 @@ let instructions_to_keep (cfg : Spec.t Cfg.t) (cfg_instructions : Spec.t Instr.t
(* Merge instructions do not need to be marked as part of the slice once slicing has been performed *)
false
| _ -> true) in
let t1 = Time.now () in
(slice, (preanalysis.control_time, preanalysis.data_time, preanalysis.mem_time, preanalysis.global_time, Time.diff t1 t0))
let t1 = Time_float.now () in
(slice, (preanalysis.control_time, preanalysis.data_time, preanalysis.mem_time, preanalysis.global_time, Time_float.diff t1 t0))

type instr_type_element =
| T of Type.t
Expand Down
4 changes: 2 additions & 2 deletions main.ml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
open Core

let report_time (msg : string) (t0 : Time.t) (t1 : Time.t) : unit =
Printf.printf "Time for '%s': %s\n%!" msg (Time.Span.to_string (Time.diff t1 t0))
let report_time (msg : string) (t0 : Time_float.t) (t1 : Time_float.t) : unit =
Printf.printf "Time_float for '%s': %s\n%!" msg (Time_float.Span.to_string (Time_float.diff t1 t0))

let () =
Wassail.Log.enable_info ();
Expand Down
56 changes: 28 additions & 28 deletions slicing_evaluation.ml
Original file line number Diff line number Diff line change
Expand Up @@ -7,14 +7,14 @@ type slicing_result = {
initial_number_of_instrs : int;
slice_size_before_adaptation : int;
slice_size_after_adaptation : int;
cfg_time : Time.Span.t;
spec_time : Time.Span.t;
control_time : Time.Span.t;
data_time : Time.Span.t;
mem_time : Time.Span.t;
global_time : Time.Span.t;
slicing_time1 : Time.Span.t;
slicing_time2 : Time.Span.t;
cfg_time : Time_float.Span.t;
spec_time : Time_float.Span.t;
control_time : Time_float.Span.t;
data_time : Time_float.Span.t;
mem_time : Time_float.Span.t;
global_time : Time_float.Span.t;
slicing_time1 : Time_float.Span.t;
slicing_time2 : Time_float.Span.t;
}

type ignored_reason =
Expand All @@ -35,11 +35,11 @@ let all_labels (instrs : 'a Instr.t list) : Instr.Label.Set.t =
~f:(fun acc instr ->
Instr.Label.Set.union acc (Instr.all_labels_no_merge instr))

let time (f : unit -> 'a) : 'a * Time.Span.t =
let t0 = Time.now () in
let time (f : unit -> 'a) : 'a * Time_float.Span.t =
let t0 = Time_float.now () in
let res = f () in
let t1 = Time.now () in
(res, Time.diff t1 t0)
let t1 = Time_float.now () in
(res, Time_float.diff t1 t0)

let prefix : string ref = ref "."

Expand All @@ -55,14 +55,14 @@ let output_slicing_result filename = function
string_of_int r.initial_number_of_instrs; (* 3 *)
string_of_int r.slice_size_before_adaptation; (* 4 *)
string_of_int r.slice_size_after_adaptation; (* 5 *)
string_of_float (Time.Span.to_ms r.cfg_time); (* 6 *)
string_of_float (Time.Span.to_ms r.spec_time); (* 7 *)
string_of_float (Time.Span.to_ms r.control_time); (* 8 *)
string_of_float (Time.Span.to_ms r.data_time); (* 9 *)
string_of_float (Time.Span.to_ms r.mem_time); (* 10 *)
string_of_float (Time.Span.to_ms r.global_time); (* 11 *)
string_of_float (Time.Span.to_ms r.slicing_time1); (* 12 *)
string_of_float (Time.Span.to_ms r.slicing_time2)] (* 13 *)
string_of_float (Time_float.Span.to_ms r.cfg_time); (* 6 *)
string_of_float (Time_float.Span.to_ms r.spec_time); (* 7 *)
string_of_float (Time_float.Span.to_ms r.control_time); (* 8 *)
string_of_float (Time_float.Span.to_ms r.data_time); (* 9 *)
string_of_float (Time_float.Span.to_ms r.mem_time); (* 10 *)
string_of_float (Time_float.Span.to_ms r.global_time); (* 11 *)
string_of_float (Time_float.Span.to_ms r.slicing_time1); (* 12 *)
string_of_float (Time_float.Span.to_ms r.slicing_time2)] (* 13 *)
| Ignored NoFunction ->
output "nofunction.txt" [filename]
| Ignored (NoInstruction f) ->
Expand Down Expand Up @@ -107,12 +107,12 @@ let slices (filename : string) (criterion_selection : [`Random | `All | `Last ])
output_slicing_result filename (Ignored (NoInstruction func.idx))
else
try
let t0 = Time.now () in
let t0 = Time_float.now () in
let cfg_raw = Cfg_builder.build wasm_mod func.idx in
let cfg_time = Time.diff (Time.now ()) t0 in
let t0 = Time.now () in
let cfg_time = Time_float.diff (Time_float.now ()) t0 in
let t0 = Time_float.now () in
let cfg, () = Spec_inference.Intra.analyze wasm_mod cfg_raw Int32Map.empty in
let spec_time = Time.diff (Time.now ()) t0 in
let spec_time = Time_float.diff (Time_float.now ()) t0 in
let cfg_instructions = Cfg.all_instructions cfg in
let preanalysis = Slicing.preanalysis cfg cfg_instructions in
List.iter (match criterion_selection with
Expand All @@ -123,10 +123,10 @@ let slices (filename : string) (criterion_selection : [`Random | `All | `Last ])
try
let instrs_to_keep, (control_time, data_time, mem_time, global_time, slicing_time1) = Slicing.instructions_to_keep cfg cfg_instructions preanalysis (Instr.Label.Set.singleton slicing_criterion) in
try
let t0 = Time.now () in
let t0 = Time_float.now () in
let sliced_func = Slicing.slice_to_funcinst cfg ~instrs:(Some instrs_to_keep) cfg_instructions (Instr.Label.Set.singleton slicing_criterion) in
let t1 = Time.now () in
let slicing_time2 = Time.diff t1 t0 in
let t1 = Time_float.now () in
let slicing_time2 = Time_float.diff t1 t0 in
let sliced_labels = all_labels sliced_func.code.body in
(* Printf.printf "fun %ld:%s -- initial: %s, before: %s, after: %d\n" func.idx (Instr.Label.to_string slicing_criterion) (Instr.Label.Set.to_string (all_labels func.code.body)) (Instr.Label.Set.to_string instrs_to_keep) (Instr.Label.Set.length sliced_labels); *)
output_slicing_result filename (Success {
Expand Down Expand Up @@ -167,7 +167,7 @@ let evaluate =
(* Generate a slice for printf function calls with a specific string *)
let generate_slice (filename : string) (output_file : string) =
let refined = false in (* Set to false if you want to slice the printf call, to true if you want to slice on the second printf argument *)
let only_function = true in (* set to false to generate the whole module *)
let only_function = false in (* set to false to generate the whole module *)
let pattern = "\nORBS:" in
Spec_inference.propagate_globals := false;
Spec_inference.propagate_locals := false;
Expand Down
2 changes: 1 addition & 1 deletion wassail.opam
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ homepage: "https://github.com/acieroid/wassail"
bug-reports: "https://github.com/acieroid/wassail"
depends: [
# "apron" # LGPL
"core" {< "v0.16"} # MIT
"core" {>= "v0.16"} # MIT
"core_kernel" # MIT
"dune" {>= "2.7.0"} # MIT
"ppx_compare" # MIT
Expand Down

0 comments on commit bd35c80

Please sign in to comment.