Skip to content

Instantly share code, notes, and snippets.

@timo
Created July 14, 2014 18:39
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save timo/9369c4f53eecd40d60b4 to your computer and use it in GitHub Desktop.
Save timo/9369c4f53eecd40d60b4 to your computer and use it in GitHub Desktop.
commit ae5cc859d5e86867b2cc434c820d08957345793c
Author: Timo Paulssen <timonator@perpetuum-immobile.de>
Date: Mon Jul 14 19:41:09 2014 +0200
spesh graphs_s and codes_s into sp_get_i
diff --git a/src/spesh/optimize.c b/src/spesh/optimize.c
index 4eb1a67..1f89179 100644
--- a/src/spesh/optimize.c
+++ b/src/spesh/optimize.c
@@ -48,6 +48,26 @@ MVMint16 MVM_spesh_add_spesh_slot(MVMThreadContext *tc, MVMSpeshGraph *g, MVMCol
return g->num_spesh_slots++;
}
+/* Some ops are just lookups in a struct, so we emit sp_p6oget_* ops for those.
+ * This code assumes all our structs lengths fit into a 16 bit unsigned int. */
+static void optimize_simple_struct_lookup(MVMThreadContext *tc, MVMSpeshGraph *g, MVMSpeshIns *ins, MVMuint16 offset)
+ switch(ins->info->opcode) {
+ case MVM_OP_graphs_s:
+ case MVM_OP_codes_s:
+ ins->info = MVM_op_get_op(MVM_OP_sp_get_i);
+ break;
+ default:
+ return;
+ }
+
+ {
+ MVMSpeshOperand *old_operands = ins->operands;
+ ins->operands = MVM_spesh_alloc(tc, g, 2 * sizeof(MVMSpeshOperand));
+ ins->operands[0] = old_operands[0];
+ ins->operands[1].lit_i16 = offset;
+ }
+}
+
/* Performs optimization on a method lookup. If we know the type that we'll
* be dispatching on, resolve it right off. If not, add a cache. */
static void optimize_method_lookup(MVMThreadContext *tc, MVMSpeshGraph *g, MVMSpeshIns *ins) {
@@ -743,6 +763,12 @@ static void optimize_bb(MVMThreadContext *tc, MVMSpeshGraph *g, MVMSpeshBB *bb)
if (specialized_on_invocant(tc, g))
optimize_getlex_known(tc, g, bb, ins);
break;
+ case MVM_OP_graphs_s:
+ optimize_simple_struct_lookup(tc, g, ins, offsetof( MVMString, body.graphs ));
+ break;
+ case MVM_OP_codes_s:
+ optimize_simple_struct_lookup(tc, g, ins, offsetof( MVMString, body.codes ));
+ break;
case MVM_OP_sp_log:
case MVM_OP_sp_osrfinalize:
/* Left-over log instruction that didn't become a guard, or OSR
@bdw
Copy link

bdw commented Jul 14, 2014

This doesn't seem to be that big of an optimization (why would sp_p6oget_o be any faster than hard-compiled struct lookups), and as for JIT support, it'd seem to me that it'd be better to add a 'struct access node' to the JIT graph rather than to try and fix it on spesh level.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment