Skip to content

Commit 77048c0

Browse files
authored
Merge pull request #443 from goblint/td3-narrow-reuse-eq
TD3: optimize switch to narrow by reusing computed right-hand side
2 parents 4e31ee9 + 6d0e6c0 commit 77048c0

File tree

1 file changed

+8
-3
lines changed

1 file changed

+8
-3
lines changed

src/solvers/td3.ml

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -112,7 +112,7 @@ module WP =
112112
HM.remove stable y;
113113
HM.mem called y || destabilize_vs y || b || was_stable && List.mem y vs
114114
) w false
115-
and solve x phase =
115+
and solve ?reuse_eq x phase =
116116
if tracing then trace "sol2" "solve %a, called: %b, stable: %b\n" S.Var.pretty_trace x (HM.mem called x) (HM.mem stable x);
117117
init x;
118118
assert (S.system x <> None);
@@ -122,7 +122,12 @@ module WP =
122122
let wp = HM.mem wpoint x in
123123
let old = HM.find rho x in
124124
let l = HM.create 10 in
125-
let tmp = eq x (eval l x) (side ~x) in
125+
let tmp =
126+
match reuse_eq with
127+
| Some d -> d
128+
| None -> eq x (eval l x) (side ~x)
129+
in
130+
let new_eq = tmp in
126131
(* let tmp = if GobConfig.get_bool "ana.opt.hashcons" then S.Dom.join (S.Dom.bot ()) tmp else tmp in (* Call hashcons via dummy join so that the tag of the rhs value is up to date. Otherwise we might get the same value as old, but still with a different tag (because no lattice operation was called after a change), and since Printable.HConsed.equal just looks at the tag, we would uneccessarily destabilize below. Seems like this does not happen. *) *)
127132
if tracing then trace "sol" "Var: %a\n" S.Var.pretty_trace x ;
128133
if tracing then trace "sol" "Contrib:%a\n" S.Dom.pretty tmp;
@@ -150,7 +155,7 @@ module WP =
150155
) else if term && phase = Widen && HM.mem wpoint x then ( (* TODO: or use wp? *)
151156
if tracing then trace "sol2" "solve switching to narrow %a\n" S.Var.pretty_trace x;
152157
HM.remove stable x;
153-
(solve[@tailcall]) x Narrow;
158+
(solve[@tailcall]) ~reuse_eq:new_eq x Narrow;
154159
) else if not space && (not term || phase = Narrow) then ( (* this makes e.g. nested loops precise, ex. tests/regression/34-localization/01-nested.c - if we do not remove wpoint, the inner loop head will stay a wpoint and widen the outer loop variable. *)
155160
if tracing then trace "sol2" "solve removing wpoint %a\n" S.Var.pretty_trace x;
156161
HM.remove wpoint x;

0 commit comments

Comments
 (0)