Skip to content

Commit

Permalink
Move TileList from linked list to vector
Browse files Browse the repository at this point in the history
Allow easier backwards and forwards traversal in the tilelist,
which is relevant in several steps of the register allocator
(such as precoloring).
  • Loading branch information
bdw committed Jun 1, 2016
1 parent cba12fc commit fcb2edb
Show file tree
Hide file tree
Showing 6 changed files with 26 additions and 37 deletions.
28 changes: 15 additions & 13 deletions src/jit/compile.c
Original file line number Diff line number Diff line change
Expand Up @@ -259,26 +259,26 @@ void MVM_jit_allocate_registers(MVMThreadContext *tc, MVMJitCompiler *compiler,
compiler->allocator->values_by_node = MVM_calloc(tree->nodes_num, sizeof(void*));

/* Get value descriptors and calculate live ranges */
for (tile = list->first; tile != NULL; tile = tile->next) {
for (i = 0; i < list->items_num; i++) {
tile = list->items[i];
if (tile->template == NULL) /* pseudotiles */
continue;
MVM_jit_get_values(tc, compiler, tree, tile);
tile->values[0]->first_created = tile->order_nr;
for (i = 0; i < tile->num_values; i++) {
tile->values[i+1]->last_use = tile->order_nr;
tile->values[i+1]->num_use++;
tile->values[0]->first_created = i;
for (j = 0; j < tile->num_values; j++) {
tile->values[j+1]->last_use = i;
tile->values[j+1]->num_use++;
}
}

/* Assign registers */
i = 0;
for (tile = list->first; tile != NULL; tile = tile->next) {
for (i = 0; i < list->items_num; i++) {
tile = list->items[i];
if (tile->template == NULL)
continue;
i++;
/* ensure that register values are live */
for (j = 1; j < tile->num_values; j++) {
value = tile->values[j];
for (j = 0; j < tile->num_values; j++) {
value = tile->values[j+1];
if (value->type != MVM_JIT_REG)
continue;
if (value->state == MVM_JIT_VALUE_SPILLED) {
Expand Down Expand Up @@ -330,7 +330,7 @@ void MVM_jit_allocate_registers(MVMThreadContext *tc, MVMJitCompiler *compiler,
if (tile->num_values > 0 &&
tile->values[1]->type == MVM_JIT_REG &&
tile->values[1]->state == MVM_JIT_VALUE_ALLOCATED &&
tile->values[1]->last_use == i) {
tile->values[1]->last_use == j) {
/* First register expires immediately, therefore we can safely cross-assign */
MVM_jit_register_assign(tc, compiler, value, tile->values[1]->reg_cls, tile->values[1]->reg_num);
} else {
Expand Down Expand Up @@ -371,22 +371,24 @@ void MVM_jit_compile_expr_tree(MVMThreadContext *tc, MVMJitCompiler *compiler, M
MVMJitRegisterAllocator allocator;
MVMJitTileList *list;
MVMJitTile *tile;
MVMint32 i;
/* First stage, tile the tree */
list = MVM_jit_tile_expr_tree(tc, tree);

/* log it, replacing logigng-during-compilation */
MVM_jit_log_tile_list(tc, list);

/* Second stage, allocate registers */
MVM_jit_register_allocator_init(tc, compiler, &allocator);
MVM_jit_register_allocator_init(tc, compiler, &allocator, list);
MVM_jit_allocate_registers(tc, compiler, tree, list);
MVM_jit_register_allocator_deinit(tc, compiler, &allocator);

/* Allocate sufficient space for the internal labels */
dasm_growpc(compiler, compiler->label_offset + tree->num_labels);

/* Third stage, emit the code */
for (tile = list->first; tile != NULL; tile = tile->next) {
for (i = 0; i < list->items_num; i++) {
tile = list->items[i];
tile->emit(tc, compiler, tree, tile->node, tile->values, tile->args);
}

Expand Down
6 changes: 4 additions & 2 deletions src/jit/log.c
Original file line number Diff line number Diff line change
Expand Up @@ -112,11 +112,13 @@ void MVM_jit_log_expr_tree(MVMThreadContext *tc, MVMJitExprTree *tree) {

void MVM_jit_log_tile_list(MVMThreadContext *tc, MVMJitTileList *list) {
MVMJitTile *tile;
MVMint32 i;
MVM_jit_log(tc, "Start log of JIT tile list\n"
"__________________________\n");
for (tile = list->first; tile != NULL; tile = tile->next) {
for (i = 0; i < list->items_num; i++) {
tile = list->items[i];
if (tile->template) {
MVM_jit_log(tc, "normal tile %d %s\n", tile->order_nr, tile->template->expr);
MVM_jit_log(tc, "normal tile %d %s\n", i, tile->template->expr);
} else {
MVM_jit_log(tc, "pseudo tile (node %d/%s)\n", tile->node,
list->tree->info[tile->node].op_info->name);
Expand Down
2 changes: 1 addition & 1 deletion src/jit/register.c
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ static MVMint8 free_num[] = { -1 };


void MVM_jit_register_allocator_init(MVMThreadContext *tc, MVMJitCompiler *compiler,
MVMJitRegisterAllocator *alc) {
MVMJitRegisterAllocator *alc, MVMJitTileList *list) {
/* Store live ranges */
MVM_DYNAR_INIT(alc->active, NUM_GPR);
/* Initialize free register buffer */
Expand Down
3 changes: 1 addition & 2 deletions src/jit/register.h
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,7 @@ struct MVMJitRegisterAllocator {
MVMint32 reg_lock;
};


void MVM_jit_register_allocator_init(MVMThreadContext *tc, MVMJitCompiler *compiler, MVMJitRegisterAllocator *allocator);
void MVM_jit_register_allocator_init(MVMThreadContext *tc, MVMJitCompiler *compiler, MVMJitRegisterAllocator *allocator, MVMJitTileList *list);
void MVM_jit_register_allocator_deinit(MVMThreadContext *tc, MVMJitCompiler *compiler, MVMJitRegisterAllocator *allocator);
/* Allocation and release */
MVMint8 MVM_jit_register_alloc(MVMThreadContext *tc, MVMJitCompiler *compiler, MVMint32 reg_cls);
Expand Down
19 changes: 4 additions & 15 deletions src/jit/tile.c
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@ struct TileTree {
MVM_DYNAR_DECL(struct TileState, states);
MVMSpeshGraph *sg;
MVMJitTileList *list;
MVMint32 order_nr;
};

/* Postorder collection of tile states (rulesets) */
Expand Down Expand Up @@ -240,14 +239,6 @@ static void select_tiles(MVMThreadContext *tc, MVMJitTreeTraverser *traverser,
}


MVM_STATIC_INLINE void append_tile(MVMJitTileList *list, MVMJitTile *tile) {
if (list->first == NULL)
list->first = tile;
if (list->last != NULL)
list->last->next = tile;
list->last = tile;
}


static void add_pseudotile(MVMThreadContext *tc, struct TileTree *tiles,
void * emit, MVMint32 node, MVMint32 nargs, ...) {
Expand All @@ -264,7 +255,7 @@ static void add_pseudotile(MVMThreadContext *tc, struct TileTree *tiles,
}
va_end(arglist);

append_tile(tiles->list, tile);
MVM_DYNAR_PUSH(tiles->list->items, tile);
}


Expand Down Expand Up @@ -386,17 +377,14 @@ static void build_tilelist(MVMThreadContext *tc, MVMJitTreeTraverser *traverser,
if (template->emit == NULL)
return;

/* pre-increment order nr */
tiles->order_nr++;

/* create tile object */
tile = MVM_spesh_alloc(tc, tiles->sg, sizeof(MVMJitTile));
tile->template = template;
tile->emit = template->emit;
tile->node = node;
tile->order_nr = tiles->order_nr;

append_tile(tiles->list, tile);
MVM_DYNAR_PUSH(tiles->list->items, tile);

}

Expand Down Expand Up @@ -424,7 +412,8 @@ MVMJitTileList * MVM_jit_tile_expr_tree(MVMThreadContext *tc, MVMJitExprTree *tr
tiles.sg = tree->graph->sg;
tiles.list = MVM_spesh_alloc(tc, tiles.sg, sizeof(MVMJitTileList));
tiles.list->tree = tree;
tiles.order_nr = 0;
MVM_DYNAR_INIT(tiles.list->items, tree->nodes_num / 2);

traverser.preorder = &select_tiles;
traverser.inorder = &build_blocks;
traverser.postorder = &build_tilelist;
Expand Down
5 changes: 1 addition & 4 deletions src/jit/tile.h
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,6 @@ struct MVMJitTile {
const MVMJitTileTemplate *template;
void (*emit)(MVMThreadContext *tc, MVMJitCompiler *compiler, MVMJitExprTree *tree,
MVMint32 node, MVMJitExprValue **values, MVMJitExprNode *args);
MVMJitTile *next;
MVMint32 order_nr;
MVMint32 node;
MVMint32 num_values;
/* buffers for the args of this (pseudo) tile */
Expand All @@ -26,8 +24,7 @@ struct MVMJitTile {

struct MVMJitTileList {
MVMJitExprTree *tree;
MVMJitTile *first;
MVMJitTile *last;
MVM_DYNAR_DECL(MVMJitTile*, items);
};

MVMJitTileList * MVM_jit_tile_expr_tree(MVMThreadContext *tc, MVMJitExprTree *tree);
Expand Down

0 comments on commit fcb2edb

Please sign in to comment.