|
|
@ -44,27 +44,23 @@ let is_non_primitive typ = Typ.is_pointer typ || Typ.is_struct typ
|
|
|
|
let is_def_unique_and_satisfy tenv var (loop_nodes : LoopNodes.t) ~is_inv_by_default
|
|
|
|
let is_def_unique_and_satisfy tenv var (loop_nodes : LoopNodes.t) ~is_inv_by_default
|
|
|
|
is_exp_invariant =
|
|
|
|
is_exp_invariant =
|
|
|
|
let equals_var id = Var.equal var (Var.of_id id) in
|
|
|
|
let equals_var id = Var.equal var (Var.of_id id) in
|
|
|
|
(* Use O(1) is_singleton check *)
|
|
|
|
match LoopNodes.is_singleton_or_more loop_nodes with
|
|
|
|
(* tedious parameter wrangling to make IContainer's fold interface happy *)
|
|
|
|
| IContainer.Singleton node ->
|
|
|
|
IContainer.is_singleton
|
|
|
|
Procdesc.Node.get_instrs node
|
|
|
|
~fold:(fun s ~init ~f -> LoopNodes.fold (fun node acc -> f acc node) s init)
|
|
|
|
|> Instrs.exists ~f:(function
|
|
|
|
loop_nodes
|
|
|
|
| Sil.Load (id, exp_rhs, _, _) when equals_var id && is_exp_invariant exp_rhs ->
|
|
|
|
&& LoopNodes.for_all
|
|
|
|
true
|
|
|
|
(fun node ->
|
|
|
|
| Sil.Store (exp_lhs, _, exp_rhs, _)
|
|
|
|
Procdesc.Node.get_instrs node
|
|
|
|
when Exp.equal exp_lhs (Var.to_exp var) && is_exp_invariant exp_rhs ->
|
|
|
|
|> Instrs.exists ~f:(function
|
|
|
|
true
|
|
|
|
| Sil.Load (id, exp_rhs, _, _) when equals_var id && is_exp_invariant exp_rhs ->
|
|
|
|
| Sil.Call ((id, _), Const (Cfun callee_pname), args, _, _) when equals_var id ->
|
|
|
|
true
|
|
|
|
PurityDomain.is_pure (get_purity tenv ~is_inv_by_default callee_pname args)
|
|
|
|
| Sil.Store (exp_lhs, _, exp_rhs, _)
|
|
|
|
&& (* check if all params are invariant *)
|
|
|
|
when Exp.equal exp_lhs (Var.to_exp var) && is_exp_invariant exp_rhs ->
|
|
|
|
List.for_all ~f:(fun (exp, _) -> is_exp_invariant exp) args
|
|
|
|
true
|
|
|
|
| _ ->
|
|
|
|
| Sil.Call ((id, _), Const (Cfun callee_pname), args, _, _) when equals_var id ->
|
|
|
|
false )
|
|
|
|
PurityDomain.is_pure (get_purity tenv ~is_inv_by_default callee_pname args)
|
|
|
|
| _ ->
|
|
|
|
&& (* check if all params are invariant *)
|
|
|
|
false
|
|
|
|
List.for_all ~f:(fun (exp, _) -> is_exp_invariant exp) args
|
|
|
|
|
|
|
|
| _ ->
|
|
|
|
|
|
|
|
false ) )
|
|
|
|
|
|
|
|
loop_nodes
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
let is_exp_invariant inv_vars invalidated_vars loop_nodes reaching_defs exp =
|
|
|
|
let is_exp_invariant inv_vars invalidated_vars loop_nodes reaching_defs exp =
|
|
|
|