Skip to content

Commit

Permalink
tmp_enode: don't heap allocate an app. store it inline instead.
Browse files Browse the repository at this point in the history
Saves heap allocations and double indirections
  • Loading branch information
nunoplopes committed Dec 20, 2023
1 parent 4898a15 commit c9c53b7
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 16 deletions.
4 changes: 4 additions & 0 deletions src/ast/ast.h
Original file line number Diff line number Diff line change
Expand Up @@ -707,6 +707,8 @@ struct app_flags {
app_flags() : m_depth(1), m_ground(1), m_has_quantifiers(0), m_has_labels(0) {}
};

namespace smt { class tmp_enode; }

class app : public expr {
friend class ast_manager;

Expand All @@ -720,8 +722,10 @@ class app : public expr {
}

friend class tmp_app;
friend class smt::tmp_enode;

app(func_decl * decl, unsigned num_args, expr * const * args);
app() : expr(AST_APP) {}
public:
func_decl * get_decl() const { return m_decl; }
family_id get_family_id() const { return get_decl()->get_family_id(); }
Expand Down
18 changes: 4 additions & 14 deletions src/smt/smt_enode.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -327,7 +327,6 @@ namespace smt {
}

tmp_enode::tmp_enode():
m_app(0),
m_capacity(0),
m_enode_data(nullptr) {
SASSERT(m_app.get_app()->get_decl() == 0);
Expand All @@ -340,14 +339,13 @@ namespace smt {

void tmp_enode::set_capacity(unsigned new_capacity) {
SASSERT(new_capacity > m_capacity);
if (m_enode_data)
dealloc_svect(m_enode_data);
dealloc_svect(m_enode_data);
m_capacity = new_capacity;
unsigned sz = sizeof(enode) + m_capacity * sizeof(enode*);
m_enode_data = alloc_svect(char, sz);
memset(m_enode_data, 0, sz);
enode * n = get_enode();
n->m_owner = m_app.get_app();
n->m_owner = &m_app;
n->m_root = n;
n->m_next = n;
n->m_class_size = 1;
Expand All @@ -359,19 +357,11 @@ namespace smt {
if (num_args > m_capacity)
set_capacity(num_args * 2);
enode * r = get_enode();
if (m_app.get_app()->get_decl() != f) {
r->m_func_decl_id = UINT_MAX;
}
m_app.set_decl(f);
m_app.set_num_args(num_args);
m_app.m_decl = f;
m_app.m_num_args = num_args;
r->m_commutative = num_args == 2 && f->is_commutative();
memcpy(get_enode()->m_args, args, sizeof(enode*)*num_args);
return r;
}

void tmp_enode::reset() {
get_enode()->m_func_decl_id = UINT_MAX;
}

};

3 changes: 1 addition & 2 deletions src/smt/smt_enode.h
Original file line number Diff line number Diff line change
Expand Up @@ -456,7 +456,7 @@ namespace smt {
void unmark_enodes2(unsigned num_enodes, enode * const * enodes);

class tmp_enode {
tmp_app m_app;
app m_app;
unsigned m_capacity;
char * m_enode_data;
enode * get_enode() { return reinterpret_cast<enode*>(m_enode_data); }
Expand All @@ -465,7 +465,6 @@ namespace smt {
tmp_enode();
~tmp_enode();
enode * set(func_decl * f, unsigned num_args, enode * const * args);
void reset();
};

inline mk_pp pp(enode* n, ast_manager& m) { return mk_pp(n->get_expr(), m); }
Expand Down

0 comments on commit c9c53b7

Please sign in to comment.