Skip to content

Commit

Permalink
Use new guards to check if specialization exists.
Browse files Browse the repository at this point in the history
For now, doing the original computation also to ensure we're getting
a match.
  • Loading branch information
jnthn committed Jul 6, 2017
1 parent 3c982ba commit 576fe32
Show file tree
Hide file tree
Showing 3 changed files with 76 additions and 0 deletions.
69 changes: 69 additions & 0 deletions src/spesh/arg_guard.c
Expand Up @@ -271,6 +271,75 @@ void MVM_spesh_arg_guard_add(MVMThreadContext *tc, MVMSpeshArgGuard **orig,
}
}

/* Tests if a guard for the specified callsite and type tuple already exists.
* Returns non-zero if it does, zero otherwise. Does it by just evaluating the
* guards against the type tuple to see if one matches it. */
MVMuint32 MVM_spesh_arg_guard_exists(MVMThreadContext *tc, MVMSpeshArgGuard *ag,
MVMCallsite *cs, MVMSpeshStatsType *types) {
MVMuint32 current_node = 0;
MVMSpeshStatsType *test = NULL;
MVMuint32 use_decont_type = 0;
if (!ag)
return 0;
do {
MVMSpeshArgGuardNode *agn = &(ag->nodes[current_node]);
switch (agn->op) {
case MVM_SPESH_GUARD_OP_CALLSITE:
current_node = agn->cs == cs ? agn->yes : agn->no;
break;
case MVM_SPESH_GUARD_OP_LOAD_ARG: {
test = &(types[agn->arg_index < cs->num_pos
? agn->arg_index
: cs->num_pos + (((agn->arg_index - 1) - cs->num_pos) / 2)]);
use_decont_type = 0;
current_node = agn->yes;
break;
case MVM_SPESH_GUARD_OP_STABLE_CONC:
if (use_decont_type)
current_node = test->decont_type_concrete && test->decont_type &&
test->decont_type->st == agn->st
? agn->yes
: agn->no;
else
current_node = test->type_concrete && test->type &&
test->type->st == agn->st
? agn->yes
: agn->no;
break;
case MVM_SPESH_GUARD_OP_STABLE_TYPE:
if (use_decont_type)
current_node = !test->decont_type_concrete && test->decont_type &&
test->decont_type->st == agn->st
? agn->yes
: agn->no;
else
current_node = !test->type_concrete && test->type &&
test->type->st == agn->st
? agn->yes
: agn->no;
break;
case MVM_SPESH_GUARD_OP_DEREF_VALUE:
if (test->decont_type) {
use_decont_type = 1;
current_node = agn->yes;
}
else {
current_node = agn->no;
}
break;
}
case MVM_SPESH_GUARD_OP_DEREF_RW:
current_node = test->rw_cont
? agn->yes
: agn->no;
break;
case MVM_SPESH_GUARD_OP_RESULT:
return 1;
}
} while (current_node != 0);
return 0;
}

/* Evaluates the argument guards. Returns >= 0 if there is a matching spesh
* candidate, or -1 if there is not. */
MVMint32 MVM_spesh_arg_guard_run(MVMThreadContext *tc, MVMSpeshArgGuard *ag,
Expand Down
2 changes: 2 additions & 0 deletions src/spesh/arg_guard.h
Expand Up @@ -75,6 +75,8 @@ struct MVMSpeshArgGuardNode {

void MVM_spesh_arg_guard_add(MVMThreadContext *tc, MVMSpeshArgGuard **orig,
MVMCallsite *cs, MVMSpeshStatsType *types, MVMuint32 candidate);
MVMuint32 MVM_spesh_arg_guard_exists(MVMThreadContext *tc, MVMSpeshArgGuard *ag,
MVMCallsite *cs, MVMSpeshStatsType *types);
MVMint32 MVM_spesh_arg_guard_run(MVMThreadContext *tc, MVMSpeshArgGuard *ag,
MVMCallsite *cs, MVMRegister *args);
MVMint32 MVM_spesh_arg_guard_run_callinfo(MVMThreadContext *tc, MVMSpeshArgGuard *ag,
Expand Down
5 changes: 5 additions & 0 deletions src/spesh/candidate.c
Expand Up @@ -124,6 +124,8 @@ MVMSpeshCandidate * MVM_spesh_candidate_setup(MVMThreadContext *tc,
MVMint32 i;
MVMSpeshStatsType *type_tuple = _tmp_type_tuple(tc, static_frame, callsite,
guards, num_guards);
MVMuint32 ag_existing_match = MVM_spesh_arg_guard_exists(tc,
static_frame->body.spesh_arg_guard, callsite, type_tuple);
for (i = 0; i < num_spesh; i++) {
MVMSpeshCandidate *compare = &static_frame->body.spesh_candidates[i];
if (compare->cs == callsite && compare->num_guards == num_guards &&
Expand All @@ -134,6 +136,9 @@ MVMSpeshCandidate * MVM_spesh_candidate_setup(MVMThreadContext *tc,
break;
}
}
if (existing_match != ag_existing_match)
MVM_oops(tc, "Spesh arg guard: existing match conflict (got %d, wanted %d)",
ag_existing_match, existing_match);
if (!result) {
if (!static_frame->body.spesh_candidates)
static_frame->body.spesh_candidates = MVM_calloc(
Expand Down

0 comments on commit 576fe32

Please sign in to comment.