mirror of
https://github.com/Z3Prover/z3
synced 2025-06-06 06:03:23 +00:00
perf and memory smash fixes to internal node count routine
This commit is contained in:
parent
f0afbcbb87
commit
7cd8edce1f
4 changed files with 26 additions and 25 deletions
|
@ -45,7 +45,7 @@ unsigned get_num_exprs(expr * n) {
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
static void get_num_internal_exprs(unsigned_vector& counts, sbuffer<expr*>& todo, expr * n) {
|
void get_num_internal_exprs(unsigned_vector& counts, ptr_vector<expr>& todo, expr * n) {
|
||||||
counts.reserve(n->get_id() + 1);
|
counts.reserve(n->get_id() + 1);
|
||||||
unsigned& rc = counts[n->get_id()];
|
unsigned& rc = counts[n->get_id()];
|
||||||
if (rc > 0) {
|
if (rc > 0) {
|
||||||
|
@ -55,7 +55,6 @@ static void get_num_internal_exprs(unsigned_vector& counts, sbuffer<expr*>& todo
|
||||||
rc = n->get_ref_count() - 1;
|
rc = n->get_ref_count() - 1;
|
||||||
unsigned i = todo.size();
|
unsigned i = todo.size();
|
||||||
todo.push_back(n);
|
todo.push_back(n);
|
||||||
unsigned count = 0;
|
|
||||||
for (; i < todo.size(); ++i) {
|
for (; i < todo.size(); ++i) {
|
||||||
n = todo[i];
|
n = todo[i];
|
||||||
if (!is_app(n))
|
if (!is_app(n))
|
||||||
|
@ -74,27 +73,17 @@ static void get_num_internal_exprs(unsigned_vector& counts, sbuffer<expr*>& todo
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
unsigned get_num_internal_exprs(expr * n) {
|
unsigned count_internal_nodes(unsigned_vector& counts, ptr_vector<expr>& todo) {
|
||||||
unsigned_vector counts;
|
|
||||||
sbuffer<expr*> todo;
|
|
||||||
unsigned internal_nodes = 0;
|
unsigned internal_nodes = 0;
|
||||||
get_num_internal_exprs(counts, todo, n);
|
for (expr* t : todo) {
|
||||||
for (expr* t : todo)
|
|
||||||
if (counts[t->get_id()] == 0)
|
|
||||||
++internal_nodes;
|
|
||||||
return internal_nodes;
|
|
||||||
}
|
|
||||||
|
|
||||||
unsigned get_num_internal_exprs(unsigned sz, expr * const * args) {
|
|
||||||
unsigned_vector counts;
|
|
||||||
sbuffer<expr*> todo;
|
|
||||||
unsigned internal_nodes = 0;
|
|
||||||
for (unsigned i = 0; i < sz; ++i)
|
|
||||||
get_num_internal_exprs(counts, todo, args[i]);
|
|
||||||
for (expr* t : todo)
|
|
||||||
if (counts[t->get_id()] == 0)
|
if (counts[t->get_id()] == 0)
|
||||||
++internal_nodes;
|
++internal_nodes;
|
||||||
|
else
|
||||||
|
counts[t->get_id()] = 0;
|
||||||
|
}
|
||||||
|
todo.reset();
|
||||||
return internal_nodes;
|
return internal_nodes;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -163,12 +163,13 @@ struct for_each_expr_proc : public EscapeProc {
|
||||||
unsigned get_num_exprs(expr * n);
|
unsigned get_num_exprs(expr * n);
|
||||||
unsigned get_num_exprs(expr * n, expr_mark & visited);
|
unsigned get_num_exprs(expr * n, expr_mark & visited);
|
||||||
unsigned get_num_exprs(expr * n, expr_fast_mark1 & visited);
|
unsigned get_num_exprs(expr * n, expr_fast_mark1 & visited);
|
||||||
unsigned get_num_internal_exprs(expr * n);
|
void get_num_internal_exprs(unsigned_vector& counts, ptr_vector<expr>& todo, expr * n);
|
||||||
unsigned get_num_internal_exprs(unsigned sz, expr * const * args);
|
unsigned count_internal_nodes(unsigned_vector& counts, ptr_vector<expr>& todo);
|
||||||
|
|
||||||
bool has_skolem_functions(expr * n);
|
bool has_skolem_functions(expr * n);
|
||||||
|
|
||||||
// pre-order traversal of subterms
|
// pre-order traversal of subterms
|
||||||
|
|
||||||
class subterms {
|
class subterms {
|
||||||
bool m_include_bound = false;
|
bool m_include_bound = false;
|
||||||
expr_ref_vector m_es;
|
expr_ref_vector m_es;
|
||||||
|
|
|
@ -269,19 +269,28 @@ br_status bool_rewriter::mk_nflat_or_core(unsigned num_args, expr * const * args
|
||||||
return BR_DONE;
|
return BR_DONE;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#if 1
|
||||||
br_status st;
|
br_status st;
|
||||||
st = m_hoist.mk_or(buffer.size(), buffer.data(), result);
|
expr_ref r(m());
|
||||||
|
st = m_hoist.mk_or(buffer.size(), buffer.data(), r);
|
||||||
if (st != BR_FAILED) {
|
if (st != BR_FAILED) {
|
||||||
unsigned count1 = get_num_internal_exprs(result);
|
m_counts1.reserve(m().get_num_asts() + 1);
|
||||||
unsigned count2 = get_num_internal_exprs(buffer.size(), buffer.data());
|
m_counts2.reserve(m().get_num_asts() + 1);
|
||||||
|
get_num_internal_exprs(m_counts1, m_todo1, r);
|
||||||
|
for (unsigned i = 0; i < num_args; ++i)
|
||||||
|
get_num_internal_exprs(m_counts2, m_todo2, args[i]);
|
||||||
|
unsigned count1 = count_internal_nodes(m_counts1, m_todo1);
|
||||||
|
unsigned count2 = count_internal_nodes(m_counts2, m_todo2);
|
||||||
if (count1 > count2)
|
if (count1 > count2)
|
||||||
st = BR_FAILED;
|
st = BR_FAILED;
|
||||||
}
|
}
|
||||||
|
if (st != BR_FAILED)
|
||||||
|
result = r;
|
||||||
if (st == BR_DONE)
|
if (st == BR_DONE)
|
||||||
return BR_REWRITE1;
|
return BR_REWRITE1;
|
||||||
if (st != BR_FAILED)
|
if (st != BR_FAILED)
|
||||||
return st;
|
return st;
|
||||||
|
#endif
|
||||||
if (s) {
|
if (s) {
|
||||||
ast_lt lt;
|
ast_lt lt;
|
||||||
std::sort(buffer.begin(), buffer.end(), lt);
|
std::sort(buffer.begin(), buffer.end(), lt);
|
||||||
|
|
|
@ -62,6 +62,8 @@ class bool_rewriter {
|
||||||
unsigned m_local_ctx_limit;
|
unsigned m_local_ctx_limit;
|
||||||
unsigned m_local_ctx_cost;
|
unsigned m_local_ctx_cost;
|
||||||
bool m_elim_ite;
|
bool m_elim_ite;
|
||||||
|
ptr_vector<expr> m_todo1, m_todo2;
|
||||||
|
unsigned_vector m_counts1, m_counts2;
|
||||||
|
|
||||||
br_status mk_flat_and_core(unsigned num_args, expr * const * args, expr_ref & result);
|
br_status mk_flat_and_core(unsigned num_args, expr * const * args, expr_ref & result);
|
||||||
br_status mk_flat_or_core(unsigned num_args, expr * const * args, expr_ref & result);
|
br_status mk_flat_or_core(unsigned num_args, expr * const * args, expr_ref & result);
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue