[cost] Fix nb_node_exec

Summary: D19496263 had refactored cost to its own subdirectory. In this process, it introduced a perf degradation by bundling of collection and computation of constraints which relies on imperative union find. This diff fixes that by separating them.

Reviewed By: ngorogiannis

Differential Revision: D19598610

fbshipit-source-id: 0e466522d
master
Ezgi Çiçek 5 years ago committed by Facebook Github Bot
parent 7d89e5e049
commit 7c94ce8cd4

@ -181,9 +181,7 @@ let compute_costs ~debug bound_map equalities =
debug.f "[ConstraintSolver][CImpr] %a@\n" Equalities.pp_costs equalities debug.f "[ConstraintSolver][CImpr] %a@\n" Equalities.pp_costs equalities
let get_node_nb_exec ~debug node_cfg bound_map node_id = let get_node_nb_exec equalities node_id =
let equalities = collect_constraints ~debug node_cfg in
let () = compute_costs ~debug bound_map equalities in
let set = let set =
node_id |> ControlFlowCost.make_node |> Equalities.find equalities node_id |> ControlFlowCost.make_node |> Equalities.find equalities
|> Equalities.find_set equalities |> Equalities.find_set equalities

@ -12,7 +12,16 @@ module Node = ProcCfg.DefaultNode
type debug = {f: 'a. ('a, F.formatter, unit, unit) IStd.format4 -> 'a} [@@unboxed] type debug = {f: 'a. ('a, F.formatter, unit, unit) IStd.format4 -> 'a} [@@unboxed]
val get_node_nb_exec : module Equalities : sig
debug:debug -> Procdesc.t -> BasicCost.t Node.IdMap.t -> Node.id -> BasicCost.t type t
end
val compute_costs : debug:debug -> BasicCost.t Node.IdMap.t -> Equalities.t -> unit
(** repeatedly improve the costs given the constraints *)
val get_node_nb_exec : Equalities.t -> Node.id -> BasicCost.t
(** compute the number of times a node is executed by taking into account the program structural (** compute the number of times a node is executed by taking into account the program structural
(e.g. control-flow) constraints *) (e.g. control-flow) constraints *)
val collect_constraints : debug:debug -> Procdesc.t -> Equalities.t
(** collect initial constraints for a CFG *)

@ -303,7 +303,10 @@ let compute_get_node_nb_exec node_cfg bound_map : get_node_nb_exec =
let start_node = NodeCFG.start_node node_cfg in let start_node = NodeCFG.start_node node_cfg in
NodePrinter.with_session start_node NodePrinter.with_session start_node
~pp_name:(fun fmt -> F.pp_print_string fmt "cost(constraints)") ~pp_name:(fun fmt -> F.pp_print_string fmt "cost(constraints)")
~f:(fun () -> ConstraintSolver.get_node_nb_exec ~debug node_cfg bound_map) ~f:(fun () ->
let equalities = ConstraintSolver.collect_constraints ~debug node_cfg in
let () = ConstraintSolver.compute_costs ~debug bound_map equalities in
ConstraintSolver.get_node_nb_exec equalities )
let compute_worst_case_cost tenv integer_type_widths get_callee_summary_and_formals instr_cfg_wto let compute_worst_case_cost tenv integer_type_widths get_callee_summary_and_formals instr_cfg_wto

Loading…
Cancel
Save