3
0
Fork 0
mirror of https://github.com/Z3Prover/z3 synced 2025-08-23 19:47:52 +00:00

count internal nodes, use to block expanding use of hoist, #6683

This commit is contained in:
Nikolaj Bjorner 2023-04-12 19:40:19 -07:00
parent 444238bc53
commit e8222433c3
3 changed files with 63 additions and 2 deletions

View file

@ -44,6 +44,60 @@ unsigned get_num_exprs(expr * n) {
return get_num_exprs(n, visited);
}
static void get_num_internal_exprs(unsigned_vector& counts, sbuffer<expr*>& todo, expr * n) {
counts.reserve(n->get_id() + 1);
unsigned& rc = counts[n->get_id()];
if (rc > 0) {
--rc;
return;
}
rc = n->get_ref_count() - 1;
unsigned i = todo.size();
todo.push_back(n);
unsigned count = 0;
for (; i < todo.size(); ++i) {
n = todo[i];
if (!is_app(n))
continue;
for (expr* arg : *to_app(n)) {
unsigned id = arg->get_id();
counts.reserve(id + 1);
unsigned& rc = counts[id];
if (rc > 0) {
--rc;
continue;
}
rc = arg->get_ref_count() - 1;
todo.push_back(arg);
}
}
}
unsigned get_num_internal_exprs(expr * n) {
unsigned_vector counts;
sbuffer<expr*> todo;
unsigned internal_nodes = 0;
get_num_internal_exprs(counts, todo, n);
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)
++internal_nodes;
return internal_nodes;
}
namespace has_skolem_functions_ns {
struct found {};
struct proc {