Skip to content

Commit

Permalink
Flatten LABEL nodes
Browse files Browse the repository at this point in the history
We used to have the labels wrap a const, but that's really redundant,
as the label can't be anything but a constant itself. So instead lets
use the label as the const.
  • Loading branch information
bdw committed Jul 11, 2017
1 parent 6854e97 commit 6a3471a
Show file tree
Hide file tree
Showing 5 changed files with 34 additions and 15 deletions.
17 changes: 17 additions & 0 deletions docs/jit/todo.org
Expand Up @@ -133,6 +133,23 @@ it should crash at compile time.
Challenge is to specify the information in a way that the expr
template compiler (perl) and the expr tree processing code can use.

* DONE Flatten label

Currently we have (label (const ...))
and (branch (label (const ...)))
and (mark (label (const ...)))

and the const is really redundant.

** DONE Change expr_ops.h

NB: label really returns a register now.

** DONE Change core.expr
** DONE Change tiles
** DONE Change expr.c
Both add_label and add_const

* DONE Fix S-EXPR parser for tile list

I think it currently counts balancing parentheses, and it doesn't
Expand Down
12 changes: 5 additions & 7 deletions src/jit/core.expr
Expand Up @@ -85,23 +85,21 @@
(template: unless_i
(when
(zr $0)
(branch (label $1)
)))
(branch $1)))

(template: if_i
(when
(nz $0)
(branch (label $1)
)))
(branch $1)))

(template: ifnonnull
(when (all 2
(nz $0) (ne $0 (^vmnull)))
(branch (label $1))))
(branch $1)))

(template: goto (branch (label $0)))
(template: goto (branch $0))

(macro: ^exit () (branch (label (const branch_exit int_sz))))
(macro: ^exit () (branch (label branch_exit)))

(macro: ^p6obody (,a) (let: (($replace (^getf ,a MVMP6opaque body.replaced)))
(if (nz $replace)
Expand Down
8 changes: 5 additions & 3 deletions src/jit/expr.c
Expand Up @@ -126,7 +126,7 @@ static MVMint32 MVM_jit_expr_wrap_guard(MVMThreadContext *tc, MVMJitExprTree *tr

static MVMint32 MVM_jit_expr_add_label(MVMThreadContext *tc, MVMJitExprTree *tree, MVMint32 label) {
MVMint32 num = tree->nodes_num;
MVMJitExprNode template[] = { MVM_JIT_CONST, label, 4, MVM_JIT_LABEL, 0, MVM_JIT_MARK, 3 };
MVMJitExprNode template[] = { MVM_JIT_LABEL, label, MVM_JIT_MARK, 0 };
MVM_VECTOR_APPEND(tree->nodes, template, sizeof(template)/sizeof(template[0]));
return num;
}
Expand Down Expand Up @@ -162,6 +162,7 @@ static MVMint32 MVM_jit_expr_add_const(MVMThreadContext *tc, MVMJitExprTree *tre

MVMJitExprNode template[] = { MVM_JIT_CONST, 0, 0 };
MVMint32 num = tree->nodes_num;
MVMint32 size = 3;
switch(info & MVM_operand_type_mask) {
case MVM_operand_int8:
template[1] = opr.lit_i8;
Expand Down Expand Up @@ -199,8 +200,9 @@ static MVMint32 MVM_jit_expr_add_const(MVMThreadContext *tc, MVMJitExprTree *tre
template[2] = sizeof(MVMuint32);
break;
case MVM_operand_ins:
template[0] = MVM_JIT_LABEL;
template[1] = MVM_jit_label_before_bb(tc, tree->graph, opr.ins_bb);
template[2] = sizeof(MVMint32);
size = 2;
break;
case MVM_operand_callsite:
template[1] = opr.callsite_idx;
Expand All @@ -213,7 +215,7 @@ static MVMint32 MVM_jit_expr_add_const(MVMThreadContext *tc, MVMJitExprTree *tre
default:
MVM_oops(tc, "Can't add constant for operand type %d\n", (info & MVM_operand_type_mask) >> 3);
}
MVM_VECTOR_APPEND(tree->nodes, template, sizeof(template)/sizeof(MVMJitExprNode));
MVM_VECTOR_APPEND(tree->nodes, template, size);
return num;
}

Expand Down
4 changes: 2 additions & 2 deletions src/jit/expr_ops.h
Expand Up @@ -53,7 +53,8 @@
_(IF, 3, 0, REG, NO_CAST), \
_(IFV, 3, 0, VOID, NO_CAST), \
_(BRANCH, 1, 0, VOID, NO_CAST), \
_(LABEL, 1, 0, VOID, NO_CAST), \
_(LABEL, 0, 1, REG, NO_CAST), \
_(MARK, 1, 0, VOID, NO_CAST), \
/* special control operators */ \
_(INVOKISH, 1, 0, VOID, NO_CAST), \
_(THROWISH, 1, 0, VOID, NO_CAST), \
Expand All @@ -63,7 +64,6 @@
_(ARGLIST, -1, 0, C_ARGS, NO_CAST), \
_(CARG, 1, 1, VOID, NO_CAST), \
/* special constrol structures */ \
_(MARK, 1, 0, VOID, NO_CAST), \
_(GUARD, 1, 2, VOID, NO_CAST), \
/* interpreter special variables */ \
_(TC, 0, 0, REG, NO_CAST), \
Expand Down
8 changes: 5 additions & 3 deletions src/jit/x64/tiles.list
Expand Up @@ -103,9 +103,11 @@
(tile: flagval (flagval flag) reg 2)

# Labels and branches
(tile: mark (mark (label (const $value))) void 1)
(tile: label (label (const $val)) reg 2)
(tile: branch_label (branch (label (const $val))) void 2)
(tile: mark (mark (label $name)) void 1)
(tile: label (label $name) reg 2)
# (tile: branch (branch $reg) void 2)
(tile: branch_label (branch (label $name)) void 2)


# placeholder for arglist pseudotile
(define: (arglist (carg reg)) c_args 1)
Expand Down

0 comments on commit 6a3471a

Please sign in to comment.