Skip to content

Commit

Permalink
Remove op_info pointer
Browse files Browse the repository at this point in the history
The op_info pointer is always going to be identical to that which is
loaded from the MVM_jit_expr_op_info function, which is itself just a
constant table lookup. So there's no need to keep it arround.
  • Loading branch information
bdw committed Jun 26, 2018
1 parent b2b0ddf commit 1b823fa
Show file tree
Hide file tree
Showing 4 changed files with 28 additions and 26 deletions.
25 changes: 9 additions & 16 deletions src/jit/expr.c
@@ -1,5 +1,11 @@
#include "moar.h"

const MVMJitExprOpInfo MVM_JIT_EXPR_OP_INFO_TABLE[] = {
#define OP_INFO(name, nchild, nargs, vtype, cast) { #name, nchild, nargs, MVM_JIT_ ## vtype, MVM_JIT_ ## cast }
MVM_JIT_EXPR_OPS(OP_INFO)
#undef OP_INFO
};

/* Mathematical min and max macro's */
#ifndef MAX
#define MAX(a,b) ((a) > (b) ? (a) : (b));
Expand All @@ -10,6 +16,8 @@
#endif




/* macros used in the expression list templates, defined here so they
don't overwrite other definitions */
#define CONST_PTR(x) ((uintptr_t)(x))
Expand All @@ -20,20 +28,6 @@
#include "jit/core_templates.h"


static const MVMJitExprOpInfo expr_op_info[] = {
#define OP_INFO(name, nchild, nargs, vtype, cast) { #name, nchild, nargs, MVM_JIT_ ## vtype, MVM_JIT_ ## cast }
MVM_JIT_EXPR_OPS(OP_INFO)
#undef OP_INFO
};


const MVMJitExprOpInfo * MVM_jit_expr_op_info(MVMThreadContext *tc, MVMint32 op) {
if (op < 0 || op >= MVM_JIT_MAX_NODES) {
MVM_oops(tc, "JIT: Expr op index out of bounds: %d", op);
}
return &expr_op_info[op];
}

/* Record the node that defines a value */
struct ValueDefinition {
MVMint32 node;
Expand Down Expand Up @@ -379,7 +373,6 @@ static void analyze_node(MVMThreadContext *tc, MVMJitTreeTraverser *traverser,
MVMJitExprNodeInfo *node_info = tree->info + node;
MVMint32 i;

node_info->op_info = op_info;
/* propagate node sizes and assign labels */
switch (tree->nodes[node]) {
case MVM_JIT_CONST:
Expand Down Expand Up @@ -986,7 +979,7 @@ void MVM_jit_expr_tree_traverse(MVMThreadContext *tc, MVMJitExprTree *tree,
}


#define FIRST_CHILD(t,x) (t->info[x].op_info->nchild < 0 ? x + 2 : x + 1)
#define FIRST_CHILD(t,x) (MVM_jit_expr_op_info(tc, (t)->nodes[x])->nchild < 0 ? x + 2 : x + 1)
/* Walk tree to get nodes along a path */
MVMint32 MVM_jit_expr_tree_get_nodes(MVMThreadContext *tc, MVMJitExprTree *tree,
MVMint32 node, const char *path,
Expand Down
14 changes: 12 additions & 2 deletions src/jit/expr.h
Expand Up @@ -44,7 +44,6 @@ struct MVMJitExprOpInfo {
/* Tree node information for easy access and use during compilation (a
symbol table entry of sorts) */
struct MVMJitExprNodeInfo {
const MVMJitExprOpInfo *op_info;
/* VM instruction represented by this node */
MVMSpeshIns *spesh_ins;
/* VM 'register' type represented by this node */
Expand Down Expand Up @@ -96,7 +95,8 @@ struct MVMJitTreeTraverser {
};


const MVMJitExprOpInfo * MVM_jit_expr_op_info(MVMThreadContext *tc, MVMint32 op);


/* properties of expression ops */
MVMint32 MVM_jit_expr_op_negate_flag(MVMThreadContext *tc, MVMint32 op);
MVMint32 MVM_jit_expr_op_is_binary_noncommutative(MVMThreadContext *tc, MVMint32 op);
Expand All @@ -108,3 +108,13 @@ void MVM_jit_expr_tree_traverse(MVMThreadContext *tc, MVMJitExprTree *tree, MVMJ
void MVM_jit_expr_tree_destroy(MVMThreadContext *tc, MVMJitExprTree *tree);
MVMint32 MVM_jit_expr_tree_get_nodes(MVMThreadContext *tc, MVMJitExprTree *tree,
MVMint32 node, const char *path, MVMJitExprNode *buffer);

extern const MVMJitExprOpInfo MVM_JIT_EXPR_OP_INFO_TABLE[];
MVM_STATIC_INLINE const MVMJitExprOpInfo * MVM_jit_expr_op_info(MVMThreadContext *tc, MVMint32 op) {
#ifdef MVM_JIT_DEBUG
if (op < 0 || op >= MVM_JIT_MAX_NODES) {
MVM_oops(tc, "JIT: Expr op index out of bounds: %d", op);
}
#endif
return &MVM_JIT_EXPR_OP_INFO_TABLE[op];
}
4 changes: 2 additions & 2 deletions src/jit/log.c
Expand Up @@ -52,7 +52,7 @@ void MVM_jit_log_bytecode(MVMThreadContext *tc, MVMJitCode *code) {
static void dump_tree(MVMThreadContext *tc, MVMJitTreeTraverser *traverser,
MVMJitExprTree *tree, MVMint32 node) {
MVMJitExprNodeInfo *info = &tree->info[node];
const MVMJitExprOpInfo *op = info->op_info;
const MVMJitExprOpInfo *op = MVM_jit_expr_op_info(tc, tree->nodes[node]);
MVMint32 *depth = traverser->data;
MVMint32 i, j;
char indent[64];
Expand Down Expand Up @@ -86,7 +86,7 @@ static void ascend_tree(MVMThreadContext *tc, MVMJitTreeTraverser *traverser,
static void write_graphviz_node(MVMThreadContext *tc, MVMJitTreeTraverser *traverser,
MVMJitExprTree *tree, MVMint32 node) {
FILE *graph_file = traverser->data;
const MVMJitExprOpInfo *op_info = tree->info[node].op_info;
const MVMJitExprOpInfo *op_info = MVM_jit_expr_op_info(tc, tree->nodes[node]);
MVMint32 first_child = node + 1;
MVMint32 nchild = op_info->nchild < 0 ? tree->nodes[first_child++] : op_info->nchild;
MVMint32 first_arg = first_child + nchild;
Expand Down
11 changes: 5 additions & 6 deletions src/jit/tile.c
Expand Up @@ -58,7 +58,7 @@ static void tile_node(MVMThreadContext *tc, MVMJitTreeTraverser *traverser,
MVMJitExprTree *tree, MVMint32 node) {
struct TreeTiler *tiler = traverser->data;
MVMJitExprNode op = tree->nodes[node];
const MVMJitExprOpInfo *info = tree->info[node].op_info;
const MVMJitExprOpInfo *info = MVM_jit_expr_op_info(tc, op);
MVMint32 first_child = node+1;
MVMint32 nchild = info->nchild < 0 ? tree->nodes[first_child++] : info->nchild;
MVMint32 *state_info = NULL;
Expand Down Expand Up @@ -158,7 +158,7 @@ static MVMint32 assign_tile(MVMThreadContext *tc, MVMJitExprTree *tree,
return node;
} else {
/* resolve conflict by copying this node */
const MVMJitExprOpInfo *info = tree->info[node].op_info;
const MVMJitExprOpInfo *info = MVM_jit_expr_op_info(tc, tree->nodes[node]);
MVMint32 space = (info->nchild < 0 ?
2 + tree->nodes[node+1] + info->nargs :
1 + info->nchild + info->nargs);
Expand Down Expand Up @@ -197,9 +197,8 @@ static void select_tiles(MVMThreadContext *tc, MVMJitTreeTraverser *traverser,

MVMJitExprNode op = tree->nodes[node];
MVMint32 first_child = node+1;
MVMint32 nchild = (tree->info[node].op_info->nchild < 0 ?
tree->nodes[first_child++] :
tree->info[node].op_info->nchild);
const MVMJitExprOpInfo *info = MVM_jit_expr_op_info(tc, op);
MVMint32 nchild = (info->nchild < 0 ? tree->nodes[first_child++] : info->nchild);
struct TreeTiler *tiler = traverser->data;

const MVMJitTileTemplate *tile = tiler->states[node].template;
Expand Down Expand Up @@ -262,7 +261,7 @@ static void select_tiles(MVMThreadContext *tc, MVMJitTreeTraverser *traverser,
default:
{
_ASSERT(nchild <= 2, "Can't tile %d children of %s", nchild,
tree->info[node].op_info->name);
MVM_jit_expr_op_info(tc, tree->nodes[node])->name);
if (nchild > 0) {
DO_ASSIGN_CHILD(0, left_sym);
}
Expand Down

0 comments on commit 1b823fa

Please sign in to comment.