Skip to content

Commit

Permalink
shrink ast's app by 8 bytes on 64-bit platforms when number of args > 0
Browse files Browse the repository at this point in the history
  • Loading branch information
nunoplopes committed Dec 20, 2023
1 parent b2d5c24 commit 4898a15
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 37 deletions.
33 changes: 6 additions & 27 deletions src/ast/ast.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -319,26 +319,6 @@ func_decl::func_decl(symbol const & name, unsigned arity, sort * const * domain,
//
// -----------------------------------

static app_flags mk_const_flags() {
app_flags r;
r.m_depth = 1;
r.m_ground = true;
r.m_has_quantifiers = false;
r.m_has_labels = false;
return r;
}

static app_flags mk_default_app_flags() {
app_flags r;
r.m_depth = 1;
r.m_ground = true;
r.m_has_quantifiers = false;
r.m_has_labels = false;
return r;
}

app_flags app::g_constant_flags = mk_const_flags();

app::app(func_decl * decl, unsigned num_args, expr * const * args):
expr(AST_APP),
m_decl(decl),
Expand Down Expand Up @@ -1762,8 +1742,7 @@ ast * ast_manager::register_node_core(ast * n) {
inc_ref(t->get_decl());
unsigned num_args = t->get_num_args();
if (num_args > 0) {
app_flags * f = t->flags();
*f = mk_default_app_flags();
app_flags * f = &t->m_flags;
SASSERT(t->is_ground());
SASSERT(!t->has_quantifiers());
SASSERT(!t->has_labels());
Expand All @@ -1776,13 +1755,13 @@ ast * ast_manager::register_node_core(ast * n) {
unsigned arg_depth = 0;
switch (arg->get_kind()) {
case AST_APP: {
app_flags * arg_flags = to_app(arg)->flags();
arg_depth = arg_flags->m_depth;
if (arg_flags->m_has_quantifiers)
app *app = to_app(arg);
arg_depth = app->get_depth();
if (app->has_quantifiers())
f->m_has_quantifiers = true;
if (arg_flags->m_has_labels)
if (app->has_labels())
f->m_has_labels = true;
if (!arg_flags->m_ground)
if (!app->is_ground())
f->m_ground = false;
break;
}
Expand Down
17 changes: 7 additions & 10 deletions src/ast/ast.h
Original file line number Diff line number Diff line change
Expand Up @@ -704,26 +704,23 @@ struct app_flags {
unsigned m_ground:1; // application does not have free variables or nested quantifiers.
unsigned m_has_quantifiers:1; // application has nested quantifiers.
unsigned m_has_labels:1; // application has nested labels.
app_flags() : m_depth(1), m_ground(1), m_has_quantifiers(0), m_has_labels(0) {}
};

class app : public expr {
friend class ast_manager;

func_decl * m_decl;
unsigned m_num_args;
app_flags m_flags;
expr * m_args[0];

static app_flags g_constant_flags;

// remark: store term depth in the end of the app. the depth is only stored if the num_args > 0
static unsigned get_obj_size(unsigned num_args) {
return num_args == 0 ? sizeof(app) : sizeof(app) + num_args * sizeof(expr *) + sizeof(app_flags);
return sizeof(app) + num_args * sizeof(expr *);
}

friend class tmp_app;

app_flags * flags() const { return m_num_args == 0 ? &g_constant_flags : reinterpret_cast<app_flags*>(const_cast<expr**>(m_args + m_num_args)); }

app(func_decl * decl, unsigned num_args, expr * const * args);
public:
func_decl * get_decl() const { return m_decl; }
Expand All @@ -744,10 +741,10 @@ class app : public expr {
expr * const * end() const { return m_args + m_num_args; }
sort * _get_sort() const { return get_decl()->get_range(); }

unsigned get_depth() const { return flags()->m_depth; }
bool is_ground() const { return flags()->m_ground; }
bool has_quantifiers() const { return flags()->m_has_quantifiers; }
bool has_labels() const { return flags()->m_has_labels; }
unsigned get_depth() const { return m_flags.m_depth; }
bool is_ground() const { return m_flags.m_ground; }
bool has_quantifiers() const { return m_flags.m_has_quantifiers; }
bool has_labels() const { return m_flags.m_has_labels; }
};

// -----------------------------------
Expand Down

0 comments on commit 4898a15

Please sign in to comment.