Skip to content

Commit

Permalink
More things in their right place
Browse files Browse the repository at this point in the history
I can't implement loading spilled values just yet, because it
requires sensitivity to the relative ordering of insert-after,
and I'm not quite sure how to do that.
  • Loading branch information
bdw committed Jun 25, 2016
1 parent 168e11a commit 30a7932
Show file tree
Hide file tree
Showing 8 changed files with 216 additions and 105 deletions.
8 changes: 7 additions & 1 deletion src/jit/compile.c
Expand Up @@ -190,13 +190,19 @@ void MVM_jit_compile_store(MVMThreadContext *tc, MVMJitCompiler *compiler,
sizeof(MVMRegister));
}

void MVM_jit_compile_load(MVMThreadContext *tc, MVMJitCompiler *compiler,
MVMJitTile *tile, MVMJitExprTree *tree) {
MVM_jit_emit_load(tc, compiler, tile->args[0],
tile->values[0]->st_cls, tile->values[0]->st_pos,
sizeof(MVMRegister));
}

void MVM_jit_compile_expr_tree(MVMThreadContext *tc, MVMJitCompiler *compiler, MVMJitGraph *jg, MVMJitExprTree *tree) {
MVMJitTileList *list;
MVMJitTile *tile;
MVMint32 i;
/* First stage, tile the tree */
list = MVM_jit_tile_expr_tree(tc, tree);
list = MVM_jit_tile_expr_tree(tc, compiler, tree);

/* Log the tile list for debugging purposes */
MVM_jit_log_tile_list(tc, list);
Expand Down
2 changes: 2 additions & 0 deletions src/jit/compile.h
Expand Up @@ -43,3 +43,5 @@ void MVM_jit_compile_conditional_branch(MVMThreadContext *tc, MVMJitCompiler *co
MVMJitTile *tile, MVMJitExprTree *tree);
void MVM_jit_compile_store(MVMThreadContext *tc, MVMJitCompiler *compiler,
MVMJitTile *tile, MVMJitExprTree *tree);
void MVM_jit_compile_load(MVMThreadContext *tc, MVMJitCompiler *compiler,
MVMJitTile *tile, MVMJitExprTree *tree);
2 changes: 1 addition & 1 deletion src/jit/internal.h
Expand Up @@ -16,7 +16,7 @@
struct MVMJitCompiler {
dasm_State *dasm_handle;
void **dasm_globals;
MVMJitGraph *graph;
MVMJitGraph *graph;

MVMint32 label_offset;
MVMint32 label_max;
Expand Down
253 changes: 179 additions & 74 deletions src/jit/register.c

Large diffs are not rendered by default.

7 changes: 3 additions & 4 deletions src/jit/register.h
Expand Up @@ -6,8 +6,7 @@ typedef enum {
MVM_JIT_STORAGE_NVR /* non-volatile register */
} MVMJitStorageClass;

struct MVMJitValueDescriptor {
MVMJitTile *created_by;
struct MVMJitValue {
MVMint32 node;

MVMJitStorageClass st_cls;
Expand All @@ -16,8 +15,8 @@ struct MVMJitValueDescriptor {

MVMint32 range_start, range_end;

MVMJitValueDescriptor *next_by_node;
MVMJitValueDescriptor *next_by_position;
MVMJitValue *next_by_node;
MVMJitValue *next_by_position;
};


Expand Down
39 changes: 19 additions & 20 deletions src/jit/tile.c
@@ -1,6 +1,7 @@
#include "moar.h"
#include "dasm_proto.h"
#include "internal.h"
#include <math.h>

#if MVM_JIT_ARCH == MVM_JIT_ARCH_X64
#include "x64/tile_decl.h"
#include "x64/tile_tables.h"
Expand All @@ -17,7 +18,7 @@ struct TileState {

struct TileTree {
MVM_DYNAR_DECL(struct TileState, states);
MVMSpeshGraph *sg;
MVMJitCompiler *compiler;
MVMJitTileList *list;
};

Expand Down Expand Up @@ -238,13 +239,13 @@ static void select_tiles(MVMThreadContext *tc, MVMJitTreeTraverser *traverser,
/* (Currently) we never insert into the tile list here */
}

MVMJitTile* MVM_jit_tile_make(MVMThreadContext *tc, MVMSpeshGraph *sg,
MVMJitTile* MVM_jit_tile_make(MVMThreadContext *tc, MVMJitCompiler *compiler,
void *emit, MVMint32 node, MVMint32 nargs, ...) {
MVMJitTile *tile;
MVMint32 i;
va_list arglist;
va_start(arglist, nargs);
tile = MVM_spesh_alloc(tc, sg, sizeof(MVMJitTile));
tile = MVM_spesh_alloc(tc, compiler->graph->sg, sizeof(MVMJitTile));
tile->emit = emit;
tile->node = node;
tile->num_values = 0;
Expand Down Expand Up @@ -300,19 +301,18 @@ static void build_blocks(MVMThreadContext *tc, MVMJitTreeTraverser *traverser,
} else if (flag == MVM_JIT_ANY) {
/* If ANY hasn't short-circuited into the left
block, jump to the right block */
MVM_DYNAR_PUSH(tiles->list->items, MVM_jit_tile_make(tc, tiles->sg, MVM_jit_compile_branch, node, 1, label_value));;
MVM_DYNAR_PUSH(tiles->list->items, MVM_jit_tile_make(tc, tiles->compiler, MVM_jit_compile_branch, node, 1, label_value));;
/* Compile label for the left block entry */

MVM_DYNAR_PUSH(tiles->list->items, MVM_jit_tile_make(tc, tiles->sg, MVM_jit_compile_label, test, 1,
MVM_DYNAR_PUSH(tiles->list->items, MVM_jit_tile_make(tc, tiles->compiler, MVM_jit_compile_label, test, 1,
tree->info[test].label));
} else {
/* Other tests require a conditional branch */
MVM_DYNAR_PUSH(tiles->list->items, MVM_jit_tile_make(tc, tiles->sg, MVM_jit_compile_conditional_branch, node,
MVM_DYNAR_PUSH(tiles->list->items, MVM_jit_tile_make(tc, tiles->compiler, MVM_jit_compile_conditional_branch, node,
2, negate_flag(tc, flag), label_value));;
}
} else {
/* after child of WHEN, insert the label */
MVM_DYNAR_PUSH(tiles->list->items, MVM_jit_tile_make(tc, tiles->sg, MVM_jit_compile_label, node, 1, label_value));
MVM_DYNAR_PUSH(tiles->list->items, MVM_jit_tile_make(tc, tiles->compiler, MVM_jit_compile_label, node, 1, label_value));
}
break;
}
Expand All @@ -326,12 +326,12 @@ static void build_blocks(MVMThreadContext *tc, MVMJitTreeTraverser *traverser,
} else if (flag == MVM_JIT_ANY) {
/* If ANY reached it's end, that means it's false. So branch out */
MVMint32 any_label = tree->info[test].label;
MVM_DYNAR_PUSH(tiles->list->items, MVM_jit_tile_make(tc, tiles->sg, MVM_jit_compile_branch, node, 1, label));
MVM_DYNAR_PUSH(tiles->list->items, MVM_jit_tile_make(tc, tiles->compiler, MVM_jit_compile_branch, node, 1, label));
/* And if ANY short-circuits we should continue the evaluation of ALL */
MVM_DYNAR_PUSH(tiles->list->items, MVM_jit_tile_make(tc, tiles->sg, MVM_jit_compile_label, node, 1, any_label));
MVM_DYNAR_PUSH(tiles->list->items, MVM_jit_tile_make(tc, tiles->compiler, MVM_jit_compile_label, node, 1, any_label));
} else {
/* Flag should be negated (ALL = short-circiut unless condition)) */
MVM_DYNAR_PUSH(tiles->list->items, MVM_jit_tile_make(tc, tiles->sg, MVM_jit_compile_conditional_branch, node, 2,
MVM_DYNAR_PUSH(tiles->list->items, MVM_jit_tile_make(tc, tiles->compiler, MVM_jit_compile_conditional_branch, node, 2,
negate_flag(tc, flag), label));
}
break;
Expand All @@ -346,15 +346,15 @@ static void build_blocks(MVMThreadContext *tc, MVMJitTreeTraverser *traverser,
succesful, and short-circuit behaviour implies we
should branch out */
MVMint32 all_label = tree->info[test].label;
MVM_DYNAR_PUSH(tiles->list->items, MVM_jit_tile_make(tc, tiles->sg, MVM_jit_compile_branch, node, 1, label));
MVM_DYNAR_PUSH(tiles->list->items, MVM_jit_tile_make(tc, tiles->compiler, MVM_jit_compile_branch, node, 1, label));
/* If not succesful, testing should continue */
MVM_DYNAR_PUSH(tiles->list->items, MVM_jit_tile_make(tc, tiles->sg, MVM_jit_compile_label, node, 1, all_label));
MVM_DYNAR_PUSH(tiles->list->items, MVM_jit_tile_make(tc, tiles->compiler, MVM_jit_compile_label, node, 1, all_label));
} else if (flag == MVM_JIT_ANY) {
/* Nothing to do here, since nested ANY already
short-circuits to our label */
} else {
/* Normal evaluation (ANY = short-circuit if condition) */
MVM_DYNAR_PUSH(tiles->list->items, MVM_jit_tile_make(tc, tiles->sg, MVM_jit_compile_conditional_branch, node, 2, flag, label));
MVM_DYNAR_PUSH(tiles->list->items, MVM_jit_tile_make(tc, tiles->compiler, MVM_jit_compile_conditional_branch, node, 2, flag, label));
}
break;
}
Expand All @@ -379,7 +379,7 @@ static void build_tilelist(MVMThreadContext *tc, MVMJitTreeTraverser *traverser,


/* create tile object */
tile = MVM_spesh_alloc(tc, tiles->sg, sizeof(MVMJitTile));
tile = MVM_spesh_alloc(tc, tiles->compiler->graph->sg, sizeof(MVMJitTile));
tile->template = template;
tile->emit = template->emit;
tile->node = node;
Expand All @@ -389,7 +389,7 @@ static void build_tilelist(MVMThreadContext *tc, MVMJitTreeTraverser *traverser,
}


MVMJitTileList * MVM_jit_tile_expr_tree(MVMThreadContext *tc, MVMJitExprTree *tree) {
MVMJitTileList * MVM_jit_tile_expr_tree(MVMThreadContext *tc, MVMJitCompiler *compiler, MVMJitExprTree *tree) {
MVMJitTreeTraverser traverser;
MVMint32 i;
struct TileTree tiles;
Expand All @@ -409,8 +409,8 @@ MVMJitTileList * MVM_jit_tile_expr_tree(MVMThreadContext *tc, MVMJitExprTree *tr
}

/* Create serial list of actual tiles which represent the final low-level code */
tiles.sg = tree->graph->sg;
tiles.list = MVM_spesh_alloc(tc, tiles.sg, sizeof(MVMJitTileList));
tiles.compiler = compiler;
tiles.list = MVM_spesh_alloc(tc, tiles.compiler->graph->sg, sizeof(MVMJitTileList));
tiles.list->tree = tree;
MVM_DYNAR_INIT(tiles.list->items, tree->nodes_num / 2);

Expand All @@ -423,4 +423,3 @@ MVMJitTileList * MVM_jit_tile_expr_tree(MVMThreadContext *tc, MVMJitExprTree *tr
MVM_free(tiles.states);
return tiles.list;
}

8 changes: 4 additions & 4 deletions src/jit/tile.h
Expand Up @@ -16,7 +16,7 @@ struct MVMJitTile {
MVMint32 node;
MVMint32 num_values;
/* buffers for the args of this (pseudo) tile */
MVMJitValueDescriptor *values[8];
MVMJitValue *values[8];
MVMJitExprNode args[8];
};

Expand All @@ -26,6 +26,6 @@ struct MVMJitTileList {
/* TODO implement structures to mark basic blocks */
};

MVMJitTile * MVM_jit_tile_make(MVMThreadContext *tc, MVMSpeshGraph *sg, void *emit,
MVMint32 node, MVMint32 nargs, ...);
MVMJitTileList * MVM_jit_tile_expr_tree(MVMThreadContext *tc, MVMJitExprTree *tree);
MVMJitTile * MVM_jit_tile_make(MVMThreadContext *tc, MVMJitCompiler *compiler,
void *emit, MVMint32 node, MVMint32 nargs, ...);
MVMJitTileList * MVM_jit_tile_expr_tree(MVMThreadContext *tc, MVMJitCompiler *compiler, MVMJitExprTree *tree);
2 changes: 1 addition & 1 deletion src/types.h
Expand Up @@ -233,7 +233,7 @@ typedef struct MVMJitExprNodeInfo MVMJitExprNodeInfo;
typedef struct MVMJitTileTemplate MVMJitTileTemplate;
typedef struct MVMJitTile MVMJitTile;
typedef struct MVMJitTileList MVMJitTileList;
typedef struct MVMJitValueDescriptor MVMJitValueDescriptor;
typedef struct MVMJitValue MVMJitValue;
typedef struct MVMProfileThreadData MVMProfileThreadData;
typedef struct MVMProfileGC MVMProfileGC;
typedef struct MVMProfileCallNode MVMProfileCallNode;
Expand Down

0 comments on commit 30a7932

Please sign in to comment.