3
0
Fork 0
mirror of https://github.com/Z3Prover/z3 synced 2025-07-28 23:17:56 +00:00

add op cache

Signed-off-by: Nikolaj Bjorner <nbjorner@microsoft.com>
This commit is contained in:
Nikolaj Bjorner 2020-06-02 12:52:42 -07:00
parent 023b630b5a
commit 4ef480e2a5
5 changed files with 76 additions and 7 deletions

View file

@ -3849,3 +3849,29 @@ bool seq_rewriter::reduce_subsequence(expr_ref_vector& ls, expr_ref_vector& rs,
}
return true;
}
seq_rewriter::op_cache::op_cache(ast_manager& m):
m(m),
m_trail(m)
{}
expr* seq_rewriter::op_cache::find(decl_kind op, expr* a, expr* b) {
op_entry e(op, a, b, nullptr);
m_table.find(e);
return e.r;
}
void seq_rewriter::op_cache::insert(decl_kind op, expr* a, expr* b, expr* r) {
cleanup();
if (a) m_trail.push_back(a);
if (b) m_trail.push_back(b);
if (r) m_trail.push_back(r);
m_table.insert(op_entry(op, a, b, r));
}
void seq_rewriter::op_cache::cleanup() {
if (m_table.size() >= m_max_cache_size) {
m_trail.reset();
m_table.reset();
}
}

View file

@ -127,6 +127,41 @@ class seq_rewriter {
unknown_c
};
class op_cache {
struct op_entry {
decl_kind k;
expr* a, *b, *r;
op_entry(decl_kind k, expr* a, expr* b, expr* r): k(k), a(a), b(b), r(r) {}
op_entry():k(0), a(nullptr), b(nullptr), r(nullptr) {}
};
struct hash_entry {
unsigned operator()(op_entry const& e) const {
return mk_mix(e.k, e.a ? e.a->get_id() : 0, e.b ? e.b->get_id() : 0);
}
};
struct eq_entry {
bool operator()(op_entry const& a, op_entry const& b) const {
return a.k == b.k && a.a == b.a && a.b == b.b;
}
};
typedef hashtable<op_entry, hash_entry, eq_entry> op_table;
ast_manager& m;
unsigned m_max_cache_size { 10000 };
expr_ref_vector m_trail;
op_table m_table;
void cleanup();
public:
op_cache(ast_manager& m);
expr* find(decl_kind op, expr* a, expr* b);
void insert(decl_kind op, expr* a, expr* b, expr* r);
};
length_comparison compare_lengths(expr_ref_vector const& as, expr_ref_vector const& bs) {
return compare_lengths(as.size(), as.c_ptr(), bs.size(), bs.c_ptr());
}