Skip to content

Commit

Permalink
Avoid allocating multiple vtable indices to subordinate methods
Browse files Browse the repository at this point in the history
This reduces vtable sizes.
  • Loading branch information
Benoit Vey committed Apr 25, 2018
1 parent 9c3df96 commit a872255
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 0 deletions.
3 changes: 3 additions & 0 deletions src/libponyc/codegen/gendesc.c
Original file line number Diff line number Diff line change
Expand Up @@ -302,6 +302,9 @@ static LLVMValueRef make_vtable(compile_t* c, reach_type_t* t)

while((m = reach_mangled_next(&n->r_mangled, &j)) != NULL)
{
if(m->is_subordinate)
continue;

uint32_t index = m->vtable_index;
pony_assert(index != (uint32_t)-1);
pony_assert(vtable[index] == NULL);
Expand Down
14 changes: 14 additions & 0 deletions src/libponyc/reach/paint.c
Original file line number Diff line number Diff line change
Expand Up @@ -287,6 +287,9 @@ static void find_names_types_use(painter_t* painter, reach_types_t* types)

while((m = reach_mangled_next(&n->r_mangled, &k)) != NULL)
{
if(m->is_subordinate)
continue;

const char* name = m->mangled_name;
name_record_t* name_rec = find_name(painter, name);

Expand Down Expand Up @@ -369,6 +372,9 @@ static void distribute_info(painter_t* painter, reach_types_t* types)

while((m = reach_mangled_next(&n->r_mangled, &k)) != NULL)
{
if(m->is_subordinate)
continue;

// Store colour assigned to name in reachable types set
const char* name = m->mangled_name;
name_record_t* name_rec = find_name(painter, name);
Expand All @@ -377,6 +383,14 @@ static void distribute_info(painter_t* painter, reach_types_t* types)
uint32_t colour = name_rec->colour;
m->vtable_index = colour;

reach_method_t* s = m->subordinate;

while(s != NULL)
{
s->vtable_index = colour;
s = s->subordinate;
}

if(colour > max_colour)
max_colour = colour;
}
Expand Down
4 changes: 4 additions & 0 deletions src/libponyc/reach/reach.c
Original file line number Diff line number Diff line change
Expand Up @@ -1348,6 +1348,7 @@ static void reachable_method(reach_t* r, deferred_reification_t* reify,
if(subordinate)
{
m2->intrinsic = true;
m2->is_subordinate = true;
m->subordinate = m2;
m = m2;
}
Expand All @@ -1358,6 +1359,7 @@ static void reachable_method(reach_t* r, deferred_reification_t* reify,
if(subordinate)
{
m2->intrinsic = true;
m2->is_subordinate = true;
m->subordinate = m2;
m = m2;
}
Expand All @@ -1366,6 +1368,7 @@ static void reachable_method(reach_t* r, deferred_reification_t* reify,
{
m2 = add_rmethod(r, t, n, TK_BOX, typeargs, opt, false);
m2->intrinsic = true;
m2->is_subordinate = true;
m->subordinate = m2;
m = m2;
}
Expand Down Expand Up @@ -1647,6 +1650,7 @@ static void reach_method_serialise(pony_ctx_t* ctx, void* object, void* buf,

dst->subordinate = (reach_method_t*)pony_serialise_offset(ctx,
m->subordinate);
dst->is_subordinate = m->is_subordinate;

dst->param_count = m->param_count;
dst->params = (reach_param_t*)pony_serialise_offset(ctx, m->params);
Expand Down
1 change: 1 addition & 0 deletions src/libponyc/reach/reach.h
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ struct reach_method_t

// Linked list of instantiations that use the same func.
reach_method_t* subordinate;
bool is_subordinate;

size_t param_count;
reach_param_t* params;
Expand Down

0 comments on commit a872255

Please sign in to comment.