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