File tree 3 files changed +32
-4
lines changed
3 files changed +32
-4
lines changed Original file line number Diff line number Diff line change @@ -757,6 +757,7 @@ decision_proceduret::resultt string_refinementt::dec_solve()
757
757
758
758
// Initial try without index set
759
759
const auto get = [this ](const exprt &expr) { return this ->get (expr); };
760
+ dependencies.clean_cache ();
760
761
const decision_proceduret::resultt res=supert::dec_solve ();
761
762
if (res==resultt::D_SATISFIABLE)
762
763
{
@@ -804,6 +805,7 @@ decision_proceduret::resultt string_refinementt::dec_solve()
804
805
805
806
while ((loop_bound_--)>0 )
806
807
{
808
+ dependencies.clean_cache ();
807
809
const decision_proceduret::resultt res=supert::dec_solve ();
808
810
809
811
if (res==resultt::D_SATISFIABLE)
Original file line number Diff line number Diff line change @@ -537,17 +537,36 @@ optionalt<exprt> string_dependenciest::eval(
537
537
const array_string_exprt &s,
538
538
const std::function<exprt(const exprt &)> &get_value) const
539
539
{
540
- const auto node = node_at (s);
541
- if (node && node->dependencies .size () == 1 )
540
+ const auto &it = node_index_pool.find (s);
541
+ if (it == node_index_pool.end ())
542
+ return {};
543
+
544
+ if (eval_string_cache[it->second ])
545
+ return eval_string_cache[it->second ];
546
+
547
+ const auto node = string_nodes[it->second ];
548
+
549
+ if (node.dependencies .size () == 1 )
542
550
{
543
- const auto &f = get_builtin_function (node-> dependencies [0 ]);
551
+ const auto &f = get_builtin_function (node. dependencies [0 ]);
544
552
const auto result = f.string_result ();
545
553
if (result && *result == s)
546
- return f.eval (get_value);
554
+ {
555
+ const auto value_opt = f.eval (get_value);
556
+ eval_string_cache[it->second ] = value_opt;
557
+ return value_opt;
558
+ }
547
559
}
548
560
return {};
549
561
}
550
562
563
+ void string_dependenciest::clean_cache ()
564
+ {
565
+ eval_string_cache.resize (string_nodes.size ());
566
+ for (auto &e : eval_string_cache)
567
+ e.reset ();
568
+ }
569
+
551
570
bool add_node (
552
571
string_dependenciest &dependencies,
553
572
const equal_exprt &equation,
Original file line number Diff line number Diff line change @@ -339,10 +339,15 @@ class string_dependenciest
339
339
340
340
// / Attempt to evaluate the given string from the dependencies and valuation
341
341
// / of strings on which it depends
342
+ // / Warning: eval uses a cache which must be cleaned everytime the valuations
343
+ // / given by get_value can change.
342
344
optionalt<exprt> eval (
343
345
const array_string_exprt &s,
344
346
const std::function<exprt(const exprt &)> &get_value) const ;
345
347
348
+ // / Clean the cache used by `eval`
349
+ void clean_cache ();
350
+
346
351
void output_dot (std::ostream &stream) const ;
347
352
348
353
private:
@@ -352,6 +357,8 @@ class string_dependenciest
352
357
// / Set of nodes representing strings
353
358
std::vector<string_nodet> string_nodes;
354
359
360
+ mutable std::vector<optionalt<exprt>> eval_string_cache;
361
+
355
362
// / Nodes describing dependencies of a string: values of the map correspond
356
363
// / to indexes in the vector `string_nodes`.
357
364
std::unordered_map<array_string_exprt, std::size_t , irep_hash>
You can’t perform that action at this time.
0 commit comments