From 7c94ce8cd4c8d5748debcc119ea3ed1cbdf68ebd Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ezgi=20=C3=87i=C3=A7ek?= Date: Tue, 28 Jan 2020 05:22:19 -0800 Subject: [PATCH] [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 --- infer/src/cost/constraintSolver.ml | 4 +--- infer/src/cost/constraintSolver.mli | 13 +++++++++++-- infer/src/cost/cost.ml | 5 ++++- 3 files changed, 16 insertions(+), 6 deletions(-) diff --git a/infer/src/cost/constraintSolver.ml b/infer/src/cost/constraintSolver.ml index cdfb8730a..52ec9a7a8 100644 --- a/infer/src/cost/constraintSolver.ml +++ b/infer/src/cost/constraintSolver.ml @@ -181,9 +181,7 @@ let compute_costs ~debug bound_map equalities = debug.f "[ConstraintSolver][CImpr] %a@\n" Equalities.pp_costs equalities -let get_node_nb_exec ~debug node_cfg bound_map node_id = - let equalities = collect_constraints ~debug node_cfg in - let () = compute_costs ~debug bound_map equalities in +let get_node_nb_exec equalities node_id = let set = node_id |> ControlFlowCost.make_node |> Equalities.find equalities |> Equalities.find_set equalities diff --git a/infer/src/cost/constraintSolver.mli b/infer/src/cost/constraintSolver.mli index 8c8316644..f7a3712e1 100644 --- a/infer/src/cost/constraintSolver.mli +++ b/infer/src/cost/constraintSolver.mli @@ -12,7 +12,16 @@ module Node = ProcCfg.DefaultNode type debug = {f: 'a. ('a, F.formatter, unit, unit) IStd.format4 -> 'a} [@@unboxed] -val get_node_nb_exec : - debug:debug -> Procdesc.t -> BasicCost.t Node.IdMap.t -> Node.id -> BasicCost.t +module Equalities : sig + 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 (e.g. control-flow) constraints *) + +val collect_constraints : debug:debug -> Procdesc.t -> Equalities.t +(** collect initial constraints for a CFG *) diff --git a/infer/src/cost/cost.ml b/infer/src/cost/cost.ml index f17dc0e5a..6860b7d9d 100644 --- a/infer/src/cost/cost.ml +++ b/infer/src/cost/cost.ml @@ -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 NodePrinter.with_session start_node ~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