Skip to content

Commit

Permalink
Merge branch 'nqp-mbc'
Browse files Browse the repository at this point in the history
  • Loading branch information
niner committed Nov 3, 2018
2 parents 7aa9500 + 25e7fa4 commit 4fbaeee
Show file tree
Hide file tree
Showing 12 changed files with 8,547 additions and 358 deletions.
1,234 changes: 903 additions & 331 deletions lib/MAST/Nodes.nqp

Large diffs are not rendered by default.

7,377 changes: 7,377 additions & 0 deletions lib/MAST/Ops.nqp

Large diffs are not rendered by default.

4 changes: 2 additions & 2 deletions src/6model/reprs/MVMMultiCache.c
Expand Up @@ -104,8 +104,8 @@ static const MVMREPROps MVMMultiCache_this_repr = {

/* Filters for various parts of action.arg_match. */
#define MVM_MULTICACHE_ARG_IDX_FILTER (2 * MVM_INTERN_ARITY_LIMIT - 1)
#define MVM_MULTICACHE_ARG_CONC_FILTER 0x10
#define MVM_MULTICACHE_ARG_RW_FILTER 0x20
#define MVM_MULTICACHE_ARG_CONC_FILTER (2 * MVM_INTERN_ARITY_LIMIT)
#define MVM_MULTICACHE_ARG_RW_FILTER (4 * MVM_INTERN_ARITY_LIMIT)
#define MVM_MULTICACHE_TYPE_ID_FILTER (0xFFFFFFFFFFFFFFFFULL ^ (MVM_TYPE_CACHE_ID_INCR - 1))

/* Debug support dumps the tree after each addition. */
Expand Down
8 changes: 7 additions & 1 deletion src/6model/serialization.c
Expand Up @@ -1388,6 +1388,8 @@ MVMObject * MVM_serialization_serialize(MVMThreadContext *tc, MVMSerializationCo
MVMSerializationWriter *writer;
MVMObject *result = NULL;
MVMint32 sc_elems = (MVMint32)sc->body->num_objects;
MVMint64 i = 0;
MVMint64 seed_strings = MVM_repr_elems(tc, empty_string_heap);

/* We don't sufficiently root things in here for the GC, so enforce gen2
* allocation. */
Expand All @@ -1402,6 +1404,10 @@ MVMObject * MVM_serialization_serialize(MVMThreadContext *tc, MVMSerializationCo
writer->root.dependent_scs = MVM_calloc(1, sizeof(MVMSerializationContext *));
writer->seen_strings = MVM_repr_alloc_init(tc, tc->instance->boot_types.BOOTHash);

for (i = 0; i < seed_strings; i++) {
MVM_repr_bind_key_int(tc, writer->seen_strings, MVM_repr_at_pos_s(tc, empty_string_heap, i), i + 1);
}

/* Allocate initial memory space for storing serialized tables and data. */
writer->dependencies_table_alloc = DEP_TABLE_ENTRY_SIZE * 4;
writer->root.dependencies_table = (char *)MVM_calloc(1, writer->dependencies_table_alloc);
Expand All @@ -1423,7 +1429,7 @@ MVMObject * MVM_serialization_serialize(MVMThreadContext *tc, MVMSerializationCo
writer->root.param_interns_data = (char *)MVM_calloc(1, writer->param_interns_data_alloc);

/* Initialize MVMString heap so first entry is the NULL MVMString. */
MVM_repr_push_s(tc, empty_string_heap, NULL);
MVM_repr_unshift_s(tc, empty_string_heap, NULL);

/* Start serializing. */
serialize(tc, writer);
Expand Down
2 changes: 1 addition & 1 deletion src/core/bytecodedump.c
Expand Up @@ -138,7 +138,7 @@ static void bytecode_dump_frame_internal(MVMThreadContext *tc, MVMStaticFrame *f
}
else {
MVMint16 ext_op_num = op_num - MVM_OP_EXT_BASE;
if (ext_op_num < cu->body.num_extops) {
if (0 <= ext_op_num && ext_op_num < cu->body.num_extops) {
MVMExtOpRecord r = cu->body.extops[ext_op_num];
MVMuint8 j;
memset(&tmp_extop_info, 0, sizeof(MVMOpInfo));
Expand Down
6 changes: 3 additions & 3 deletions src/core/callsite.c
Expand Up @@ -201,13 +201,13 @@ MVM_PUBLIC void MVM_callsite_try_intern(MVMThreadContext *tc, MVMCallsite **cs_p

/* If it wasn't found, store it for the future. */
if (!found) {
if (interns->num_by_arity[num_flags] % 8 == 0) {
if (interns->num_by_arity[num_flags] % MVM_INTERN_ARITY_LIMIT == 0) {
if (interns->num_by_arity[num_flags])
interns->by_arity[num_flags] = MVM_realloc(
interns->by_arity[num_flags],
sizeof(MVMCallsite *) * (interns->num_by_arity[num_flags] + 8));
sizeof(MVMCallsite *) * (interns->num_by_arity[num_flags] + MVM_INTERN_ARITY_LIMIT));
else
interns->by_arity[num_flags] = MVM_malloc(sizeof(MVMCallsite *) * 8);
interns->by_arity[num_flags] = MVM_malloc(sizeof(MVMCallsite *) * MVM_INTERN_ARITY_LIMIT);
}
interns->by_arity[num_flags][interns->num_by_arity[num_flags]++] = cs;
cs->is_interned = 1;
Expand Down
4 changes: 2 additions & 2 deletions src/core/validation.c
Expand Up @@ -292,8 +292,8 @@ static void validate_reg_operand(Validator *val, MVMuint32 flags) {
}

if (reg_type != operand_type)
fail(val, MSG(val, "operand type %"PRIu32" does not match register type %"PRIu32),
operand_type, reg_type);
fail(val, MSG(val, "operand type %PRIu32 does not match register type %PRIu32 for op %s in frame %s"),
operand_type, reg_type, val->cur_info->name, MVM_string_utf8_maybe_encode_C_string(val->tc, val->frame->body.name));

next_operand:
val->cur_op += 2;
Expand Down
27 changes: 27 additions & 0 deletions src/jit/core_templates.expr
Expand Up @@ -802,6 +802,14 @@
(carg (tc) ptr)
(carg $1 ptr)) ptr_sz))

(template: unbox_u
(call (^getf (^repr $1) MVMREPROps box_funcs.get_uint)
(arglist
(carg (tc) ptr)
(carg (^stable $1) ptr)
(carg $1 ptr)
(carg (^body $1) ptr)) int_sz))

(template: atpos_i!
(callv (^getf (^repr $1) MVMREPROps pos_funcs.at_pos)
(arglist
Expand Down Expand Up @@ -2440,6 +2448,14 @@
(^getf $hllconfig MVMHLLConfig true_value)
(^getf $hllconfig MVMHLLConfig false_value))))

(template: serializetobuf
(call (^func &MVM_serialization_serialize)
(arglist
(carg (tc) ptr)
(carg $1 ptr)
(carg $2 ptr)
(carg $3 ptr)) ptr_sz))

(template: sp_resolvecode
(call (^func &MVM_frame_resolve_invokee_spesh)
(arglist
Expand All @@ -2465,6 +2481,17 @@

(template: sp_getspeshslot (^spesh_slot_value $1))

(template: sp_findmeth!
(ifv (eq (^stable $1) (^spesh_slot_value $3))
(store \$0 (^spesh_slot_value (add $3 (const 1 int_sz))) ptr_sz)
(callv (^func &MVM_6model_find_method_spesh)
(arglist
(carg (tc) ptr)
(carg $1 ptr)
(carg (^cu_string $2) ptr)
(carg $3 int)
(carg \$0 ptr)))))

(template: sp_fastcreate!
(let: (($block (call (^func &MVM_gc_allocate_nursery)
(arglist
Expand Down
2 changes: 2 additions & 0 deletions src/jit/graph.c
Expand Up @@ -110,6 +110,7 @@ static void * op_to_func(MVMThreadContext *tc, MVMint16 opcode) {
case MVM_OP_return_o: return MVM_args_set_result_obj;
case MVM_OP_return_n: return MVM_args_set_result_num;
case MVM_OP_coerce_is: return MVM_coerce_i_s;
case MVM_OP_coerce_us: return MVM_coerce_u_s;
case MVM_OP_coerce_ns: return MVM_coerce_n_s;
case MVM_OP_coerce_si: return MVM_coerce_s_i;
case MVM_OP_coerce_sn: return MVM_coerce_s_n;
Expand Down Expand Up @@ -2588,6 +2589,7 @@ static MVMint32 consume_ins(MVMThreadContext *tc, MVMJitGraph *jg,
case MVM_OP_coerce_ns:
case MVM_OP_coerce_si:
case MVM_OP_coerce_is:
case MVM_OP_coerce_us:
case MVM_OP_coerce_In: {
MVMint16 src = ins->operands[1].reg.orig;
MVMint16 dst = ins->operands[0].reg.orig;
Expand Down
29 changes: 25 additions & 4 deletions src/spesh/args.c
Expand Up @@ -251,6 +251,7 @@ void MVM_spesh_args(MVMThreadContext *tc, MVMSpeshGraph *g, MVMCallsite *cs,
checkarity_bb = bb;
break;
case MVM_OP_param_rp_i:
case MVM_OP_param_rp_u:
case MVM_OP_param_rp_n:
case MVM_OP_param_rp_s:
case MVM_OP_param_rp_o: {
Expand All @@ -267,6 +268,7 @@ void MVM_spesh_args(MVMThreadContext *tc, MVMSpeshGraph *g, MVMCallsite *cs,
break;
}
case MVM_OP_param_op_i:
case MVM_OP_param_op_u:
case MVM_OP_param_op_n:
case MVM_OP_param_op_s:
case MVM_OP_param_op_o: {
Expand All @@ -285,10 +287,12 @@ void MVM_spesh_args(MVMThreadContext *tc, MVMSpeshGraph *g, MVMCallsite *cs,
break;
}
case MVM_OP_param_on_i:
case MVM_OP_param_on_u:
case MVM_OP_param_on_n:
case MVM_OP_param_on_s:
case MVM_OP_param_on_o:
case MVM_OP_param_rn_i:
case MVM_OP_param_rn_u:
case MVM_OP_param_rn_n:
case MVM_OP_param_rn_s:
case MVM_OP_param_rn_o:
Expand Down Expand Up @@ -323,10 +327,6 @@ void MVM_spesh_args(MVMThreadContext *tc, MVMSpeshGraph *g, MVMCallsite *cs,
case MVM_OP_param_on2_n:
case MVM_OP_param_on2_s:
case MVM_OP_param_on2_o:
case MVM_OP_param_rp_u:
case MVM_OP_param_op_u:
case MVM_OP_param_rn_u:
case MVM_OP_param_on_u:
case MVM_OP_param_rn2_u:
case MVM_OP_param_on2_u:
/* Don't understand how to specialize these yet. */
Expand Down Expand Up @@ -365,6 +365,14 @@ void MVM_spesh_args(MVMThreadContext *tc, MVMSpeshGraph *g, MVMCallsite *cs,
prim_spec(tc, type_tuple, i) != MVM_STORAGE_SPEC_BP_INT)
goto cleanup;
break;
case MVM_OP_param_rp_u:
case MVM_OP_param_op_u:
if (arg_flag != MVM_CALLSITE_ARG_INT)
if (arg_flag != MVM_CALLSITE_ARG_OBJ ||
prim_spec(tc, type_tuple, i) != MVM_STORAGE_SPEC_BP_INT) {
goto cleanup;
}
break;
case MVM_OP_param_rp_n:
case MVM_OP_param_op_n:
if (arg_flag != MVM_CALLSITE_ARG_NUM)
Expand Down Expand Up @@ -398,6 +406,7 @@ void MVM_spesh_args(MVMThreadContext *tc, MVMSpeshGraph *g, MVMCallsite *cs,
for (i = 0; i < cs->num_pos; i++) {
MVMCallsiteEntry arg_flag = cs->arg_flags[i];
switch (pos_ins[i]->info->opcode) {
/* FIXME add support for param_rp_u here */
case MVM_OP_param_rp_i:
case MVM_OP_param_op_i:
if (arg_flag == MVM_CALLSITE_ARG_INT) {
Expand All @@ -410,6 +419,18 @@ void MVM_spesh_args(MVMThreadContext *tc, MVMSpeshGraph *g, MVMCallsite *cs,
add_facts(tc, g, i, type_tuple[i], pos_ins[i]);
}
break;
case MVM_OP_param_rp_u:
case MVM_OP_param_op_u:
if (arg_flag == MVM_CALLSITE_ARG_INT) {
pos_ins[i]->info = MVM_op_get_op(MVM_OP_sp_getarg_i);
}
else {
pos_unbox(tc, g, pos_bb[i], pos_ins[i], MVM_op_get_op(MVM_OP_unbox_i));
pos_added[i]++;
if (type_tuple && type_tuple[i].type)
add_facts(tc, g, i, type_tuple[i], pos_ins[i]);
}
break;
case MVM_OP_param_rp_n:
case MVM_OP_param_op_n:
if (arg_flag == MVM_CALLSITE_ARG_NUM) {
Expand Down
12 changes: 10 additions & 2 deletions src/spesh/optimize.c
Expand Up @@ -236,7 +236,7 @@ static void optimize_istype(MVMThreadContext *tc, MVMSpeshGraph *g, MVMSpeshIns
* values, we can resolve it to a 1. If we know the types differ, we can
* resolve it to a 0. */
static void optimize_eqaddr(MVMThreadContext *tc, MVMSpeshGraph *g, MVMSpeshIns *ins) {
MVMSpeshFacts *obj_a_facts = MVM_spesh_get_facts(tc, g, ins->operands[1]);
MVMSpeshFacts *obj_a_facts = MVM_spesh_get_facts(tc, g, ins->operands[1]);
MVMSpeshFacts *obj_b_facts = MVM_spesh_get_facts(tc, g, ins->operands[2]);
MVMint16 known_result = -1;
if (obj_a_facts->flags & MVM_SPESH_FACT_KNOWN_VALUE &&
Expand Down Expand Up @@ -2456,6 +2456,7 @@ static void analyze_phi(MVMThreadContext *tc, MVMSpeshGraph *g, MVMSpeshIns *ins
MVMuint32 operand;
MVMint32 common_flags;
MVMObject *common_type;
MVMObject *common_value;
MVMObject *common_decont_type;
MVMSpeshFacts *target_facts = get_facts_direct(tc, g, ins->operands[0]);
MVMSpeshFacts *cur_operand_facts;
Expand All @@ -2469,13 +2470,15 @@ static void analyze_phi(MVMThreadContext *tc, MVMSpeshGraph *g, MVMSpeshIns *ins
cur_operand_facts = get_facts_direct(tc, g, ins->operands[1]);
common_flags = cur_operand_facts->flags;
common_type = cur_operand_facts->type;
common_value = cur_operand_facts->value.o;
common_decont_type = cur_operand_facts->decont_type;
total_log_guards = cur_operand_facts->num_log_guards;

for (operand = 2; operand < ins->info->num_operands; operand++) {
cur_operand_facts = get_facts_direct(tc, g, ins->operands[operand]);
common_flags = common_flags & cur_operand_facts->flags;
common_type = common_type == cur_operand_facts->type && common_type ? common_type : NULL;
common_value = common_value == cur_operand_facts->value.o && common_value ? common_value : NULL;
common_decont_type = common_decont_type == cur_operand_facts->decont_type && common_decont_type
? common_decont_type
: NULL;
Expand All @@ -2493,7 +2496,12 @@ static void analyze_phi(MVMThreadContext *tc, MVMSpeshGraph *g, MVMSpeshIns *ins
}
/*else fprintf(stderr, "(diverging type) ");*/
}
/*if (common_flags & MVM_SPESH_FACT_KNOWN_VALUE) fprintf(stderr, "value ");*/
if (common_flags & MVM_SPESH_FACT_KNOWN_VALUE) {
if (common_value) {
target_facts->flags |= MVM_SPESH_FACT_KNOWN_VALUE;
target_facts->value.o = common_value;
}
}
if (common_flags & MVM_SPESH_FACT_CONCRETE) {
/*fprintf(stderr, "concrete ");*/
target_facts->flags |= MVM_SPESH_FACT_CONCRETE;
Expand Down

0 comments on commit 4fbaeee

Please sign in to comment.