Skip to content

Instantly share code, notes, and snippets.

@MasterDuke17
Created May 3, 2020 08:15
Show Gist options
  • Save MasterDuke17/958a9ce9001df0b7d5cf13619190cf4c to your computer and use it in GitHub Desktop.
Save MasterDuke17/958a9ce9001df0b7d5cf13619190cf4c to your computer and use it in GitHub Desktop.
diff --git src/core/interp.c src/core/interp.c
index 783df4ddb..4f8abd4d3 100644
--- src/core/interp.c
+++ src/core/interp.c
@@ -2760,6 +2760,12 @@ void MVM_interp_run(MVMThreadContext *tc, void (*initial_invoke)(MVMThreadContex
cur_op += 4;
goto NEXT;
}
+ OP(sp_getcurhllsym): {
+ MVMString *hll_name = (MVMString *)tc->cur_frame->effective_spesh_slots[GET_UI16(cur_op, 4)];
+ GET_REG(cur_op, 0).o = MVM_hll_sym_get(tc, hll_name, GET_REG(cur_op, 2).s);
+ cur_op += 6;
+ goto NEXT;
+ }
OP(bindcurhllsym): {
MVMObject *syms = tc->instance->hll_syms, *hash;
MVMString *hll_name = tc->cur_frame->static_info->body.cu->body.hll_name;
diff --git src/core/oplist src/core/oplist
index 7709c9183..137900f0e 100644
--- src/core/oplist
+++ src/core/oplist
@@ -1062,6 +1062,8 @@ sp_mul_I .s w(obj) int16 sslot r(obj) r(obj) int16 int16 :pure
sp_bool_I .s w(int64) r(obj) int16 :pure
+sp_getcurhllsym .s w(obj) r(str) sslot :pure
+
# Profiler recording ops. Naming convention: start with prof_. Must all be
# marked .s, which is how the validator knows to exclude them. (For that
# purpose, we treat them as a kind of spesh op).
diff --git src/jit/core_templates.expr src/jit/core_templates.expr
index e08dfea25..7bac63c0a 100644
--- src/jit/core_templates.expr
+++ src/jit/core_templates.expr
@@ -1434,13 +1434,16 @@
(template: hllhash
(^getf (^hllconfig) MVMHLLConfig slurpy_hash_type))
-(template: getcurhllsym
- (let: (($hllname (^getf (cu) MVMCompUnit body.hll_name)))
- (call (^func &MVM_hll_sym_get)
- (arglist
- (carg (tc) ptr)
- (carg $hllname ptr)
- (carg $1 ptr)) ptr_sz)))
+(template: sp_getcurhllsym
+ (do
+ (callv (^func MVM_dump_backtrace)
+ (arglist
+ (carg (tc) ptr)))
+ (call (^func &MVM_hll_sym_get)
+ (arglist
+ (carg (tc) ptr)
+ (carg (^spesh_slot_value $2) ptr)
+ (carg $1 ptr)) ptr_sz)))
(template: gethllsym
(call (^func &MVM_hll_sym_get)
diff --git src/jit/graph.c src/jit/graph.c
index a610001ee..cda586d4f 100644
--- src/jit/graph.c
+++ src/jit/graph.c
@@ -293,6 +293,7 @@ static void * op_to_func(MVMThreadContext *tc, MVMint16 opcode) {
case MVM_OP_nfarunproto: return MVM_nfa_run_proto;
case MVM_OP_nfafromstatelist: return MVM_nfa_from_statelist;
case MVM_OP_hllize: return MVM_hll_map;
+ case MVM_OP_sp_getcurhllsym: return MVM_hll_sym_get;
case MVM_OP_gethllsym: return MVM_hll_sym_get;
case MVM_OP_clone: return MVM_repr_clone;
case MVM_OP_create: return MVM_repr_alloc_init;
@@ -2027,6 +2028,16 @@ start:
jg_append_call_c(tc, jg, op_to_func(tc, op), 4, args, MVM_JIT_RV_VOID, -1);
break;
}
+ case MVM_OP_sp_getcurhllsym: {
+ MVMint16 dst = ins->operands[0].reg.orig;
+ MVMint32 sym = ins->operands[1].reg.orig;
+ MVMint16 idx = ins->operands[2].lit_i16;
+ MVMJitCallArg args[] = { { MVM_JIT_INTERP_VAR, MVM_JIT_INTERP_TC },
+ { MVM_JIT_SPESH_SLOT_VALUE, idx },
+ { MVM_JIT_REG_VAL, sym } };
+ jg_append_call_c(tc, jg, op_to_func(tc, op), 3, args, MVM_JIT_RV_PTR, dst);
+ break;
+ }
case MVM_OP_gethllsym: {
MVMint16 dst = ins->operands[0].reg.orig;
MVMint16 hll = ins->operands[1].reg.orig;
diff --git src/spesh/optimize.c src/spesh/optimize.c
index 49061eda7..9b62c7f2a 100644
--- src/spesh/optimize.c
+++ src/spesh/optimize.c
@@ -1305,6 +1305,17 @@ static void optimize_hllbool(MVMThreadContext *tc, MVMSpeshGraph *g, MVMSpeshIns
}
}
+/* Turns a getcurhllsym instruction into an sp_getcurhllsym with the HLL name added to
+ * a spesh slot so the function call can be jitted. */
+static void optimize_getcurhllsym(MVMThreadContext *tc, MVMSpeshGraph *g, MVMSpeshIns *ins) {
+ MVMSpeshOperand *orig_o = ins->operands;
+ MVM_spesh_graph_add_comment(tc, g, ins, "specialized from %s", ins->info->name);
+ ins->info = MVM_op_get_op(MVM_OP_sp_getcurhllsym);
+ ins->operands = MVM_spesh_alloc(tc, g, 3 * sizeof(MVMSpeshOperand));
+ memcpy(ins->operands, orig_o, 2 * sizeof(MVMSpeshOperand));
+ ins->operands[2].lit_i16 = MVM_spesh_add_spesh_slot_try_reuse(tc, g, (MVMCollectable *)g->sf->body.cu->body.hll_name);
+}
+
/* Optimize an object conditional (if_o, unless_o) to simpler operations.
*
* We always perform the split of the if_o to istrue + if_i, because a branch
@@ -2648,6 +2659,9 @@ static void optimize_bb_switch(MVMThreadContext *tc, MVMSpeshGraph *g, MVMSpeshB
case MVM_OP_hllboolfor:
optimize_hllbool(tc, g, ins);
break;
+ case MVM_OP_getcurhllsym:
+ optimize_getcurhllsym(tc, g, ins);
+ break;
case MVM_OP_if_i:
case MVM_OP_unless_i:
case MVM_OP_if_n:
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment