Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/master' into moar-jit
Browse files Browse the repository at this point in the history
Conflicts:
	src/core/ops.c
  • Loading branch information
bdw committed Jul 28, 2014
2 parents 7d70cb7 + 0513b67 commit 9bf2fb8
Show file tree
Hide file tree
Showing 27 changed files with 530 additions and 102 deletions.
32 changes: 24 additions & 8 deletions lib/MAST/Nodes.nqp
Expand Up @@ -41,7 +41,7 @@ class MAST::ExtOpRegistry {
}

# The extension of base number (everything below is internal).
my $EXTOP_BASE := 1024;
my int $EXTOP_BASE := 1024;

# The base class for all nodes.
class MAST::Node {
Expand Down Expand Up @@ -127,7 +127,7 @@ class MAST::CompUnit is MAST::Node {
}

method sc_idx($sc) {
my $handle := nqp::scgethandle($sc);
my str $handle := nqp::scgethandle($sc);
if nqp::existskey(%!sc_lookup, $handle) {
nqp::atkey(%!sc_lookup, $handle)
}
Expand All @@ -141,12 +141,12 @@ class MAST::CompUnit is MAST::Node {

# Gets the opcode for an extop in the current compilation unit. If this is
# the first use of the extop, gives it an index for this compilation unit.
method get_extop_code($name) {
method get_extop_code(str $name) {
if nqp::existskey(%!extop_idx, $name) {
%!extop_idx{$name} + $EXTOP_BASE
}
else {
my $idx := +@!extop_sigs;
my int $idx := +@!extop_sigs;
@!extop_names[$idx] := $name;
@!extop_sigs[$idx] := MAST::ExtOpRegistry.extop_signature($name);
%!extop_idx{$name} := $idx;
Expand Down Expand Up @@ -197,9 +197,9 @@ class MAST::Frame is MAST::Node {
my int $FRAME_FLAG_IS_THUNK := 2;
has int $!flags;

my $cuuid_src := 0;
my int $cuuid_src := 0;
sub fresh_id() {
$cuuid_src := $cuuid_src + 1;
$cuuid_src++;
"!MVM_CUUID_$cuuid_src"
}

Expand Down Expand Up @@ -319,7 +319,15 @@ class MAST::Op is MAST::Node {

my %op_codes := MAST::Ops.WHO<%codes>;
my @op_names := MAST::Ops.WHO<@names>;
method new(:$op!, *@operands) {

method new(str :$op!, *@operands) {
my $obj := nqp::create(self);
nqp::bindattr_i($obj, MAST::Op, '$!op', %op_codes{$op});
nqp::bindattr($obj, MAST::Op, '@!operands', @operands);
$obj
}

method new_with_operand_array(@operands, str :$op!) {
my $obj := nqp::create(self);
nqp::bindattr_i($obj, MAST::Op, '$!op', %op_codes{$op});
nqp::bindattr($obj, MAST::Op, '@!operands', @operands);
Expand All @@ -343,7 +351,15 @@ class MAST::ExtOp is MAST::Node {
has @!operands;
has str $!name;

method new(:$op!, :$cu!, *@operands) {
method new(str :$op!, :$cu!, *@operands) {
my $obj := nqp::create(self);
nqp::bindattr_i($obj, MAST::ExtOp, '$!op', $cu.get_extop_code($op));
nqp::bindattr($obj, MAST::ExtOp, '@!operands', @operands);
nqp::bindattr_s($obj, MAST::ExtOp, '$!name', $op);
$obj
}

method new_with_operand_array(@operands, str :$op!, :$cu!) {
my $obj := nqp::create(self);
nqp::bindattr_i($obj, MAST::ExtOp, '$!op', $cu.get_extop_code($op));
nqp::bindattr($obj, MAST::ExtOp, '@!operands', @operands);
Expand Down
6 changes: 6 additions & 0 deletions src/6model/reprs/MVMCompUnit.h
Expand Up @@ -15,6 +15,12 @@ struct MVMExtOpRecord {

/* Read from the bytecode stream. */
MVMuint8 operand_descriptor[MVM_MAX_OPERANDS];

/* Specialization function. */
MVMExtOpSpesh *spesh;

/* Discover facts for spesh. */
MVMExtOpFactDiscover *discover;
};

/* How to release memory. */
Expand Down
16 changes: 9 additions & 7 deletions src/6model/reprs/MVMMultiCache.c
Expand Up @@ -127,7 +127,9 @@ MVMObject * MVM_multi_cache_add(MVMThreadContext *tc, MVMObject *cache_obj, MVMO

/* If it's zero arity, just stick it in that slot. */
if (num_args == 0) {
MVM_ASSIGN_REF(tc, &(cache_obj->header), cache->zero_arity, result);
/* Can only be added if there are no named args */
if (!has_nameds)
MVM_ASSIGN_REF(tc, &(cache_obj->header), cache->zero_arity, result);
return cache_obj;
}

Expand Down Expand Up @@ -217,8 +219,8 @@ MVMObject * MVM_multi_cache_find(MVMThreadContext *tc, MVMObject *cache_obj, MVM
}

/* If it's zero-arity, return result right off. */
if (num_args == 0 && !has_nameds)
return cache->zero_arity;
if (num_args == 0)
return has_nameds ? NULL : cache->zero_arity;

/* If there's more args than the maximum, won't be in the cache. */
if (num_args > MVM_MULTICACHE_MAX_ARITY)
Expand Down Expand Up @@ -295,8 +297,8 @@ MVMObject * MVM_multi_cache_find_callsite_args(MVMThreadContext *tc, MVMObject *
has_nameds = cs->arg_count != cs->num_pos;

/* If it's zero-arity, return result right off. */
if (num_args == 0 && !has_nameds)
return cache->zero_arity;
if (num_args == 0)
return has_nameds ? NULL : cache->zero_arity;

/* If there's more args than the maximum, won't be in the cache. */
if (num_args > MVM_MULTICACHE_MAX_ARITY)
Expand Down Expand Up @@ -371,8 +373,8 @@ MVMObject * MVM_multi_cache_find_spesh(MVMThreadContext *tc, MVMObject *cache_ob
has_nameds = arg_info->cs->arg_count != arg_info->cs->num_pos;

/* If it's zero-arity, return result right off. */
if (num_args == 0 && !has_nameds)
return cache->zero_arity;
if (num_args == 0)
return has_nameds ? NULL : cache->zero_arity;

/* If there's more args than the maximum, won't be in the cache. Also
* check against maximum size of spesh call site. */
Expand Down
11 changes: 7 additions & 4 deletions src/core/exceptions.c
Expand Up @@ -513,11 +513,14 @@ MVMObject * MVM_exception_newlexotic(MVMThreadContext *tc, MVMuint32 offset) {
MVMLexotic *lexotic;

/* Locate handler associated with the specified label. */
MVMFrame *f = tc->cur_frame;
MVMStaticFrame *sf = f->static_info;
MVMint32 handler_idx = -1;
MVMFrame *f = tc->cur_frame;
MVMStaticFrame *sf = f->static_info;
MVMint32 handler_idx = -1;
MVMint32 num_handlers = f->spesh_cand
? f->spesh_cand->num_handlers
: sf->body.num_handlers;
MVMuint32 i;
for (i = 0; i < sf->body.num_handlers; i++) {
for (i = 0; i < num_handlers; i++) {
if (f->effective_handlers[i].action == MVM_EX_ACTION_GOTO &&
f->effective_handlers[i].goto_offset == offset) {
handler_idx = i;
Expand Down
15 changes: 10 additions & 5 deletions src/core/ext.c
Expand Up @@ -51,7 +51,8 @@ int MVM_ext_load(MVMThreadContext *tc, MVMString *lib, MVMString *ext) {
}

int MVM_ext_register_extop(MVMThreadContext *tc, const char *cname,
MVMExtOpFunc func, MVMuint8 num_operands, MVMuint8 operands[]) {
MVMExtOpFunc func, MVMuint8 num_operands, MVMuint8 operands[],
MVMExtOpSpesh *spesh, MVMExtOpFactDiscover *discover, MVMuint32 flags) {
MVMExtOpRegistry *entry;
MVMString *name = MVM_string_ascii_decode_nt(
tc, tc->instance->VMString, cname);
Expand Down Expand Up @@ -149,12 +150,14 @@ int MVM_ext_register_extop(MVMThreadContext *tc, const char *cname,
entry->info.mark[0] = '.';
entry->info.mark[1] = 'x';
entry->info.num_operands = num_operands;
entry->info.pure = 0;
entry->info.pure = flags & MVM_EXTOP_PURE;
entry->info.deopt_point = 0;
entry->info.no_inline = 0;
entry->info.no_inline = flags & MVM_EXTOP_NOINLINE;
memcpy(entry->info.operands, operands, num_operands);
memset(entry->info.operands + num_operands, 0,
MVM_MAX_OPERANDS - num_operands);
entry->spesh = spesh;
entry->discover = discover;

MVM_gc_root_add_permanent(tc, (MVMCollectable **)&entry->name);
MVM_HASH_BIND(tc, tc->instance->extop_registry, name, entry);
Expand Down Expand Up @@ -183,8 +186,10 @@ const MVMOpInfo * MVM_ext_resolve_extop_record(MVMThreadContext *tc,
}

/* Resolve record. */
record->info = &entry->info;
record->func = entry->func;
record->info = &entry->info;
record->func = entry->func;
record->spesh = entry->spesh;
record->discover = entry->discover;

uv_mutex_unlock(&tc->instance->mutex_extop_registry);

Expand Down
11 changes: 10 additions & 1 deletion src/core/ext.h
@@ -1,4 +1,10 @@
typedef void MVMExtOpFunc(MVMThreadContext *tc);
typedef void MVMExtOpSpesh(MVMThreadContext *tc, MVMSpeshGraph *g, MVMSpeshBB *bb, MVMSpeshIns *ins);
typedef void MVMExtOpFactDiscover(MVMThreadContext *tc, MVMSpeshGraph *g, MVMSpeshIns *ins);

/* Flags we might put on an extension op to indicate its properties. */
#define MVM_EXTOP_PURE 1
#define MVM_EXTOP_NOINLINE 2

struct MVMExtRegistry {
MVMDLLSym *sym;
Expand All @@ -10,11 +16,14 @@ struct MVMExtOpRegistry {
MVMString *name;
MVMExtOpFunc *func;
MVMOpInfo info;
MVMExtOpSpesh *spesh;
MVMExtOpFactDiscover *discover;
UT_hash_handle hash_handle;
};

int MVM_ext_load(MVMThreadContext *tc, MVMString *lib, MVMString *ext);
MVM_PUBLIC int MVM_ext_register_extop(MVMThreadContext *tc, const char *cname,
MVMExtOpFunc func, MVMuint8 num_operands, MVMuint8 operands[]);
MVMExtOpFunc func, MVMuint8 num_operands, MVMuint8 operands[],
MVMExtOpSpesh *spesh, MVMExtOpFactDiscover *discover, MVMuint32 flags);
const MVMOpInfo * MVM_ext_resolve_extop_record(MVMThreadContext *tc,
MVMExtOpRecord *record);
2 changes: 1 addition & 1 deletion src/core/frame.c
Expand Up @@ -331,7 +331,7 @@ void MVM_frame_invoke(MVMThreadContext *tc, MVMStaticFrame *static_frame,
if (!chosen_cand->osr_logging && cur_idx < MVM_SPESH_LOG_RUNS) {
if (MVM_cas(&(chosen_cand->log_enter_idx), cur_idx, cur_idx + 1) == cur_idx) {
/* We get to log. */
frame = allocate_frame(tc, static_frame_body, NULL); /* NULL as no inlines yet. */
frame = allocate_frame(tc, static_frame_body, chosen_cand);
frame->effective_bytecode = chosen_cand->bytecode;
frame->effective_handlers = chosen_cand->handlers;
frame->effective_spesh_slots = chosen_cand->spesh_slots;
Expand Down
10 changes: 6 additions & 4 deletions src/core/interp.c
Expand Up @@ -4636,21 +4636,23 @@ void MVM_interp_run(MVMThreadContext *tc, void (*initial_invoke)(MVMThreadContex
#if MVM_CGOTO
OP_CALL_EXTOP: {
/* Bounds checking? Never heard of that. */
MVMFrame *frame_before = tc->cur_frame;
MVMExtOpRecord *record = &cu->body.extops[op - MVM_OP_EXT_BASE];

record->func(tc);
cur_op += record->operand_bytes;
if (tc->cur_frame == frame_before)
cur_op += record->operand_bytes;
goto NEXT;
}
#else
default: {
if (op >= MVM_OP_EXT_BASE
&& (op - MVM_OP_EXT_BASE) < cu->body.num_extops) {
MVMFrame *frame_before = tc->cur_frame;
MVMExtOpRecord *record =
&cu->body.extops[op - MVM_OP_EXT_BASE];

record->func(tc);
cur_op += record->operand_bytes;
if (tc->cur_frame == frame_before)
cur_op += record->operand_bytes;
goto NEXT;
}

Expand Down
4 changes: 2 additions & 2 deletions src/core/oplist
Expand Up @@ -217,8 +217,8 @@ die w(obj) r(str)
rethrow r(obj)
resume r(obj)
takehandlerresult w(obj)
newlexotic w(obj) ins :noinline
lexoticresult w(obj) r(obj) :noinline
newlexotic w(obj) ins
lexoticresult w(obj) r(obj)
backtracestrings w(obj) r(obj) :pure
usecapture w(obj) :noinline
savecapture w(obj) :noinline
Expand Down
4 changes: 2 additions & 2 deletions src/core/ops.c
Expand Up @@ -1995,7 +1995,7 @@ static MVMOpInfo MVM_op_infos[] = {
2,
0,
0,
1,
0,
0,
{ MVM_operand_write_reg | MVM_operand_obj, MVM_operand_ins }
},
Expand All @@ -2006,7 +2006,7 @@ static MVMOpInfo MVM_op_infos[] = {
2,
0,
0,
1,
0,
0,
{ MVM_operand_write_reg | MVM_operand_obj, MVM_operand_read_reg | MVM_operand_obj }
},
Expand Down

0 comments on commit 9bf2fb8

Please sign in to comment.