Permalink
Browse files

Move TileList from linked list to vector

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 fcb2edb40ecc737c4de162f21666dd6557d8eb00
Showing with 26 additions and 37 deletions.
  1. +15 −13 src/jit/compile.c
  2. +4 −2 src/jit/log.c
  3. +1 −1 src/jit/register.c
  4. +1 −2 src/jit/register.h
  5. +4 −15 src/jit/tile.c
  6. +1 −4 src/jit/tile.h
View
@@ -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) {
@@ -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 {
@@ -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);
}
View
@@ -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);
View
@@ -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 */
View
@@ -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);
View
@@ -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) */
@@ -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, ...) {
@@ -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);
}
@@ -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);
}
@@ -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;
View
@@ -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 */
@@ -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);

0 comments on commit fcb2edb

Please sign in to comment.