-
-
Save timo/36c7b304a2917f67233c3ef910bd395d to your computer and use it in GitHub Desktop.
patternmatch a very common dispatch program for monomorphic dispatch cases in spesh log
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
diff --git a/src/spesh/disp.c b/src/spesh/disp.c | |
index 681a8133e..2b8b0e27e 100644 | |
--- a/src/spesh/disp.c | |
+++ b/src/spesh/disp.c | |
@@ -96,7 +96,24 @@ static void rewrite_unhit(MVMThreadContext *tc, MVMSpeshGraph *g, MVMSpeshIns *i | |
static void rewrite_monomorphic(MVMThreadContext *tc, MVMSpeshGraph *g, MVMSpeshIns *ins, | |
MVMuint32 bytecode_offset, MVMuint32 outcome) { | |
// TODO | |
- MVM_spesh_graph_add_comment(tc, g, ins, "Deemed monomorphic (outcome %d)", outcome); | |
+ MVMuint32 disp_slot = MVM_disp_inline_cache_get_slot(tc, g->sf, bytecode_offset); | |
+ MVMDispInlineCache *cache = &(g->sf->body.inline_cache); | |
+ MVMDispInlineCacheEntry *entry = cache->entries[bytecode_offset >> cache->bit_shift]; | |
+ MVMuint32 kind = MVM_disp_inline_cache_get_kind(tc, entry); | |
+ if (kind == MVM_INLINE_CACHE_KIND_MONOMORPHIC_DISPATCH) { | |
+ MVMDispProgram *dp = ((MVMDispInlineCacheEntryMonomorphicDispatch *)entry)->dp; | |
+ MVM_spesh_graph_add_comment(tc, g, ins, "dispatch program %p, %d ops", dp, dp->num_ops); | |
+ if (dp->num_ops == 3 && dp->num_gc_constants == 1 && dp->num_temporaries == 1 && dp->num_resumptions == 0) { | |
+ if (dp->ops[0].code == MVMDispOpcodeGuardArgTypeConc && dp->ops[0].arg_guard.arg_idx == 0 && dp->ops[0].arg_guard.checkee == 0) { | |
+ if (dp->ops[1].code == MVMDispOpcodeLoadCaptureValue && dp->ops[1].load.temp == 0 && dp->ops[1].load.idx == 0) { | |
+ if (dp->ops[2].code == MVMDispOpcodeResultValueObj && dp->ops[2].res_value.temp == 0) { | |
+ MVM_spesh_graph_add_comment(tc, g, ins, "Common DP Code: guard conc, load from capture, return immediately"); | |
+ } | |
+ } | |
+ } | |
+ } | |
+ } | |
+ MVM_spesh_graph_add_comment(tc, g, ins, "Deemed monomorphic (outcome %d, kind %d)", outcome, kind); | |
rewrite_to_sp_dispatch(tc, g, ins, bytecode_offset); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment