#include <thread.h>
#endif
+#include <unistd.h>
+#include <sys/mman.h>
+
#include <mono/metadata/appdomain.h>
#include <mono/metadata/debug-helpers.h>
+#include <mono/metadata/tokentype.h>
#include <mono/utils/mono-math.h>
#include "mini-sparc.h"
* Register usage:
* - %i0..%i<n> hold the incoming arguments, these are never written by JITted
* code. Unused input registers are used for global register allocation.
- * - %l0..%l7 is used for local register allocation
- * - %o0..%o6 is used for outgoing arguments
+ * - %o0..%o5 and %l7 is used for local register allocation and passing arguments
+ * - %l0..%l6 is used for global register allocation
* - %o7 and %g1 is used as scratch registers in opcodes
* - all floating point registers are used for local register allocation except %f0.
* Only double precision registers are used.
* Possible optimizations:
* - delay slot scheduling
* - allocate large constants to registers
- * - use %o registers for local allocation
- * - implement unwinding through native frames
* - add more mul/div/rem optimizations
*/
return "unknown";
}
+const char*
+mono_arch_fregname (int reg) {
+ static const char *rnames [] = {
+ "sparc_f0", "sparc_f1", "sparc_f2", "sparc_f3", "sparc_f4",
+ "sparc_f5", "sparc_f6", "sparc_f7", "sparc_f8", "sparc_f9",
+ "sparc_f10", "sparc_f11", "sparc_f12", "sparc_f13", "sparc_f14",
+ "sparc_f15", "sparc_f16", "sparc_f17", "sparc_f18", "sparc_f19",
+ "sparc_f20", "sparc_f21", "sparc_f22", "sparc_f23", "sparc_f24",
+ "sparc_f25", "sparc_f26", "sparc_f27", "sparc_f28", "sparc_f29",
+ "sparc_f30", "sparc_f31"
+ };
+
+ if (reg >= 0 && reg < 32)
+ return rnames [reg];
+ else
+ return "unknown";
+}
+
/*
* Initialize the cpu to execute managed code.
*/
if (sig->hasthis)
add_general (&gr, &stack_size, cinfo->args + 0, FALSE);
+ if ((sig->call_convention == MONO_CALL_VARARG) && (n == 0)) {
+ gr = PARAM_REGS;
+
+ /* Emit the signature cookie just before the implicit arguments */
+ add_general (&gr, &stack_size, &cinfo->sig_cookie, FALSE);
+ }
+
for (i = 0; i < sig->param_count; ++i) {
ArgInfo *ainfo = &cinfo->args [sig->hasthis + i];
if ((sig->call_convention == MONO_CALL_VARARG) && (i == sig->sentinelpos)) {
+ gr = PARAM_REGS;
+
/* Emit the signature cookie just before the implicit arguments */
add_general (&gr, &stack_size, &cinfo->sig_cookie, FALSE);
- /* Prevent implicit arguments from being passed in registers */
- gr = PARAM_REGS;
}
DEBUG(printf("param %d: ", i));
case MONO_TYPE_I:
case MONO_TYPE_U:
case MONO_TYPE_PTR:
+ case MONO_TYPE_FNPTR:
case MONO_TYPE_CLASS:
case MONO_TYPE_OBJECT:
case MONO_TYPE_STRING:
}
}
+ if (!sig->pinvoke && (sig->call_convention == MONO_CALL_VARARG) && (n > 0) && (sig->sentinelpos == sig->param_count)) {
+ gr = PARAM_REGS;
+
+ /* Emit the signature cookie just before the implicit arguments */
+ add_general (&gr, &stack_size, &cinfo->sig_cookie, FALSE);
+ }
+
/* return value */
{
switch (mono_type_get_underlying_type (sig->ret)->type) {
case MONO_TYPE_I:
case MONO_TYPE_U:
case MONO_TYPE_PTR:
+ case MONO_TYPE_FNPTR:
case MONO_TYPE_CLASS:
case MONO_TYPE_OBJECT:
case MONO_TYPE_SZARRAY:
MonoMethodSignature *sig;
CallInfo *cinfo;
- sig = cfg->method->signature;
+ sig = mono_method_signature (cfg->method);
cinfo = get_call_info (sig, FALSE);
for (i = cinfo->reg_usage; i < 6; ++i)
regs = g_list_prepend (regs, GUINT_TO_POINTER (sparc_i0 + i));
- /* Use %l0..%l3 as global registers */
- for (i = sparc_l0; i < sparc_l4; ++i)
+ /* Use %l0..%l6 as global registers */
+ for (i = sparc_l0; i < sparc_l7; ++i)
regs = g_list_prepend (regs, GUINT_TO_POINTER (i));
g_free (cinfo);
int i, offset, size, align, curinst;
CallInfo *cinfo;
- header = ((MonoMethodNormal *)m->method)->header;
+ header = mono_method_get_header (m->method);
- sig = m->method->signature;
+ sig = mono_method_signature (m->method);
cinfo = get_call_info (sig, FALSE);
continue;
}
+ if (inst->flags & MONO_INST_IS_DEAD)
+ continue;
+
/* inst->unused indicates native sized value types, this is used by the
* pinvoke wrappers when they call functions returning structure */
if (inst->unused && MONO_TYPE_ISSTRUCT (inst->inst_vtype) && inst->inst_vtype->type != MONO_TYPE_TYPEDBYREF)
g_free (cinfo);
}
+static MonoInst *
+make_group (MonoCompile *cfg, MonoInst *left, int basereg, int offset)
+{
+ MonoInst *group;
+
+ MONO_INST_NEW (cfg, group, OP_GROUP);
+ group->inst_left = left;
+ group->inst_basereg = basereg;
+ group->inst_imm = offset;
+
+ return group;
+}
+
/*
* take the arguments and generate the arch-specific
* instructions to properly call the function in call.
for (i = 0; i < n; ++i) {
ainfo = cinfo->args + i;
+
+ if ((sig->call_convention == MONO_CALL_VARARG) && (i == sig->sentinelpos)) {
+ /* Emit the signature cookie just before the first implicit argument */
+ MonoInst *sig_arg;
+ MonoMethodSignature *tmp_sig;
+
+ /*
+ * mono_ArgIterator_Setup assumes the signature cookie is
+ * passed first and all the arguments which were before it are
+ * passed on the stack after the signature. So compensate by
+ * passing a different signature.
+ */
+ tmp_sig = mono_metadata_signature_dup (call->signature);
+ tmp_sig->param_count -= call->signature->sentinelpos;
+ tmp_sig->sentinelpos = 0;
+ memcpy (tmp_sig->params, call->signature->params + call->signature->sentinelpos, tmp_sig->param_count * sizeof (MonoType*));
+
+ /* FIXME: Add support for signature tokens to AOT */
+ cfg->disable_aot = TRUE;
+ /* We allways pass the signature on the stack for simplicity */
+ MONO_INST_NEW (cfg, arg, OP_SPARC_OUTARG_MEM);
+ arg->inst_right = make_group (cfg, (MonoInst*)call, sparc_sp, ARGS_OFFSET + cinfo->sig_cookie.offset);
+ MONO_INST_NEW (cfg, sig_arg, OP_ICONST);
+ sig_arg->inst_p0 = tmp_sig;
+ arg->inst_left = sig_arg;
+ arg->type = STACK_PTR;
+ /* prepend, so they get reversed */
+ arg->next = call->out_args;
+ call->out_args = arg;
+ }
+
if (is_virtual && i == 0) {
/* the argument will be attached to the call instruction */
in = call->args [i];
} else {
- if ((sig->call_convention == MONO_CALL_VARARG) && (i == sig->sentinelpos)) {
- /* FIXME: Test varargs with 0 implicit args */
- /* FIXME: Test interaction with hasthis */
- /* Emit the signature cookie just before the first implicit argument */
- MonoInst *sig_arg;
- /* FIXME: Add support for signature tokens to AOT */
- cfg->disable_aot = TRUE;
- /* We allways pass the signature on the stack for simplicity */
- MONO_INST_NEW (cfg, arg, OP_SPARC_OUTARG_MEM);
- arg->inst_basereg = sparc_sp;
- arg->inst_imm = ARGS_OFFSET + cinfo->sig_cookie.offset;
- MONO_INST_NEW (cfg, sig_arg, OP_ICONST);
- sig_arg->inst_p0 = call->signature;
- arg->inst_left = sig_arg;
- arg->type = STACK_PTR;
- /* prepend, so they get reversed */
- arg->next = call->out_args;
- call->out_args = arg;
- }
-
MONO_INST_NEW (cfg, arg, OP_OUTARG);
in = call->args [i];
arg->cil_code = in->cil_code;
cinfo->stack_usage += pad;
}
+ arg->inst_right = make_group (cfg, (MonoInst*)call, sparc_sp, ARGS_OFFSET + ainfo->offset);
+
switch (ainfo->storage) {
case ArgInIReg:
case ArgInFReg:
arg->unused = sparc_o0 + ainfo->reg;
call->used_iregs |= 1 << ainfo->reg;
- if ((i >= sig->hasthis) && (sig->params [i - sig->hasthis]->type == MONO_TYPE_R8)) {
+ if ((i >= sig->hasthis) && !sig->params [i - sig->hasthis]->byref && ((sig->params [i - sig->hasthis]->type == MONO_TYPE_R8) || (sig->params [i - sig->hasthis]->type == MONO_TYPE_R4))) {
+ /* An fp value is passed in an ireg */
+
+ if (arg->opcode == OP_SPARC_OUTARG_REGPAIR)
+ arg->opcode = OP_SPARC_OUTARG_REGPAIR_FLOAT;
+ else
+ arg->opcode = OP_SPARC_OUTARG_FLOAT;
+
/*
* The OUTARG (freg) implementation needs an extra dword to store
* the temporary value.
- */
+ */
extra_space += 8;
}
break;
default:
NOT_IMPLEMENTED;
}
-
- arg->inst_basereg = sparc_sp;
- arg->inst_imm = ARGS_OFFSET + ainfo->offset;
}
}
call->out_args = prev;
}
call->stack_usage = cinfo->stack_usage + extra_space;
+ call->out_ireg_args = NULL;
+ call->out_freg_args = NULL;
cfg->param_area = MAX (cfg->param_area, call->stack_usage);
cfg->flags |= MONO_CFG_HAS_CALLS;
sparc_nop (code); \
} while (0);
-extern gboolean mono_compile_aot;
-
/*
* A call template is 7 instructions long, so we want to avoid it if possible.
*/
gpointer target;
/* FIXME: This only works if the target method is already compiled */
- if (0 && v64 && !mono_compile_aot) {
+ if (0 && v64 && !cfg->compile_aot) {
MonoJumpInfo patch_info;
patch_info.type = patch_type;
* Only do this if the method is small since BPr only has a 16bit
* displacement.
*/
- if (v64 && (((MonoMethodNormal*)cfg->method)->header->code_size < 10000) && last_ins &&
+ if (v64 && (mono_method_get_header (cfg->method)->code_size < 10000) && last_ins &&
(last_ins->opcode == OP_COMPARE_IMM) &&
(last_ins->inst_imm == 0)) {
MonoInst *next = ins->next;
bb->last_ins = last_ins;
}
-/* Parameters used by the register allocator */
-
-/* Use %l4..%l7 as local registers */
-#define ARCH_CALLER_REGS (0xf0<<16)
-
-#ifdef SPARCV9
-/* Use %d34..%d62 as the double precision floating point local registers */
-/* %d32 has the same encoding as %f1, so %d36%d38 == 0b1010 == 0xa */
-#define ARCH_CALLER_FREGS (0xaaaaaaa8)
-#else
-/* Use %f2..%f30 as the double precision floating point local registers */
-#define ARCH_CALLER_FREGS (0x55555554)
-#endif
-
-#undef DEBUG
-#define DEBUG(a) if (cfg->verbose_level > 1) a
-//#define DEBUG(a)
-#define reg_is_freeable(r) ((1 << (r)) & ARCH_CALLER_REGS)
-#define freg_is_freeable(r) (((1) << (r)) & ARCH_CALLER_FREGS)
-
-typedef struct {
- int born_in;
- int killed_in;
- int last_use;
- int prev_use;
-} RegTrack;
-
static const char*const * ins_spec = sparc_desc;
static inline const char*
return ins_spec [CEE_ADD];
}
-static void
-print_ins (int i, MonoInst *ins)
-{
- const char *spec = get_ins_spec (ins->opcode);
- g_print ("\t%-2d %s", i, mono_inst_name (ins->opcode));
- if (spec [MONO_INST_DEST]) {
- if (ins->dreg >= MONO_MAX_IREGS)
- g_print (" R%d <-", ins->dreg);
- else
- if (spec [MONO_INST_DEST] == 'b')
- g_print (" [%s + 0x%lx] <-", mono_arch_regname (ins->dreg), (long)ins->inst_offset);
- else
- g_print (" %s <-", mono_arch_regname (ins->dreg));
- }
- if (spec [MONO_INST_SRC1]) {
- if (ins->sreg1 >= MONO_MAX_IREGS)
- g_print (" R%d", ins->sreg1);
- else
- if (spec [MONO_INST_SRC1] == 'b')
- g_print (" [%s + 0x%lx]", mono_arch_regname (ins->sreg1), (long)ins->inst_offset);
- else
- g_print (" %s", mono_arch_regname (ins->sreg1));
- }
- if (spec [MONO_INST_SRC2]) {
- if (ins->sreg2 >= MONO_MAX_IREGS)
- g_print (" R%d", ins->sreg2);
- else
- g_print (" %s", mono_arch_regname (ins->sreg2));
- }
- if (spec [MONO_INST_CLOB])
- g_print (" clobbers: %c", spec [MONO_INST_CLOB]);
- g_print ("\n");
-}
-
-static void
-print_regtrack (RegTrack *t, int num)
-{
- int i;
- char buf [32];
- const char *r;
-
- for (i = 0; i < num; ++i) {
- if (!t [i].born_in)
- continue;
- if (i >= MONO_MAX_IREGS) {
- g_snprintf (buf, sizeof(buf), "R%d", i);
- r = buf;
- } else
- r = mono_arch_regname (i);
- g_print ("liveness: %s [%d - %d]\n", r, t [i].born_in, t[i].last_use);
- }
-}
-
-typedef struct InstList InstList;
-
-struct InstList {
- InstList *prev;
- InstList *next;
- MonoInst *data;
-};
-
-static inline InstList*
-inst_list_prepend (MonoMemPool *pool, InstList *list, MonoInst *data)
-{
- InstList *item = mono_mempool_alloc (pool, sizeof (InstList));
- item->data = data;
- item->prev = NULL;
- item->next = list;
- if (list)
- list->prev = item;
- return item;
-}
-
-#define STACK_OFFSETS_POSITIVE
-
-/*
- * returns the offset used by spillvar. It allocates a new
- * spill variable if necessary.
- */
-static int
-mono_spillvar_offset (MonoCompile *cfg, int spillvar)
-{
- MonoSpillInfo **si, *info;
- int i = 0;
-
- si = &cfg->spill_info;
-
- while (i <= spillvar) {
-
- if (!*si) {
- *si = info = mono_mempool_alloc (cfg->mempool, sizeof (MonoSpillInfo));
- info->next = NULL;
- cfg->stack_offset += sizeof (gpointer);
- info->offset = - cfg->stack_offset;
- }
-
- if (i == spillvar)
- return MONO_SPARC_STACK_BIAS + (*si)->offset;
-
- i++;
- si = &(*si)->next;
- }
-
- g_assert_not_reached ();
- return 0;
-}
-
static int
mono_spillvar_offset_float (MonoCompile *cfg, int spillvar)
{
return 0;
}
-/*
- * Force the spilling of the variable in the symbolic register 'reg'.
- */
-G_GNUC_UNUSED static int
-get_register_force_spilling (MonoCompile *cfg, InstList *item, MonoInst *ins, int reg)
-{
- MonoInst *load;
- int i, sel, spill;
-
- sel = cfg->rs->iassign [reg];
- /*i = cfg->rs->isymbolic [sel];
- g_assert (i == reg);*/
- i = reg;
- spill = ++cfg->spill_count;
- cfg->rs->iassign [i] = -spill - 1;
- mono_regstate_free_int (cfg->rs, sel);
- /* we need to create a spill var and insert a load to sel after the current instruction */
- MONO_INST_NEW (cfg, load, OP_LOAD_MEMBASE);
- load->dreg = sel;
- load->inst_basereg = cfg->frame_reg;
- load->inst_offset = mono_spillvar_offset (cfg, spill);
- if (item->prev) {
- while (ins->next != item->prev->data)
- ins = ins->next;
- }
- load->next = ins->next;
- ins->next = load;
- DEBUG (g_print ("SPILLED LOAD (%d at 0x%08lx(%%sp)) R%d (freed %s)\n", spill, (long)load->inst_offset, i, mono_arch_regname (sel)));
- i = mono_regstate_alloc_int (cfg->rs, 1 << sel);
- g_assert (i == sel);
-
- return sel;
-}
-
-static int
-get_register_spilling (MonoCompile *cfg, InstList *item, MonoInst *ins, guint32 regmask, int reg)
-{
- MonoInst *load;
- int i, sel, spill;
-
- DEBUG (g_print ("start regmask to assign R%d: 0x%08x (R%d <- R%d R%d)\n", reg, regmask, ins->dreg, ins->sreg1, ins->sreg2));
- /* exclude the registers in the current instruction */
- if (reg != ins->sreg1 && (reg_is_freeable (ins->sreg1) || (ins->sreg1 >= MONO_MAX_IREGS && cfg->rs->iassign [ins->sreg1] >= 0))) {
- if (ins->sreg1 >= MONO_MAX_IREGS)
- regmask &= ~ (1 << cfg->rs->iassign [ins->sreg1]);
- else
- regmask &= ~ (1 << ins->sreg1);
- DEBUG (g_print ("excluding sreg1 %s\n", mono_arch_regname (ins->sreg1)));
- }
- if (reg != ins->sreg2 && (reg_is_freeable (ins->sreg2) || (ins->sreg2 >= MONO_MAX_IREGS && cfg->rs->iassign [ins->sreg2] >= 0))) {
- if (ins->sreg2 >= MONO_MAX_IREGS)
- regmask &= ~ (1 << cfg->rs->iassign [ins->sreg2]);
- else
- regmask &= ~ (1 << ins->sreg2);
- DEBUG (g_print ("excluding sreg2 %s %d\n", mono_arch_regname (ins->sreg2), ins->sreg2));
- }
- if (reg != ins->dreg && reg_is_freeable (ins->dreg)) {
- regmask &= ~ (1 << ins->dreg);
- DEBUG (g_print ("excluding dreg %s\n", mono_arch_regname (ins->dreg)));
- }
-
- DEBUG (g_print ("available regmask: 0x%08x\n", regmask));
- g_assert (regmask); /* need at least a register we can free */
- sel = -1;
- /* we should track prev_use and spill the register that's farther */
- for (i = 0; i < MONO_MAX_IREGS; ++i) {
- if (regmask & (1 << i)) {
- sel = i;
- DEBUG (g_print ("selected register %s has assignment %d\n", mono_arch_regname (sel), cfg->rs->iassign [sel]));
- break;
- }
- }
- i = cfg->rs->isymbolic [sel];
- spill = ++cfg->spill_count;
- cfg->rs->iassign [i] = -spill - 1;
- mono_regstate_free_int (cfg->rs, sel);
- /* we need to create a spill var and insert a load to sel after the current instruction */
- MONO_INST_NEW (cfg, load, OP_LOAD_MEMBASE);
- load->dreg = sel;
- load->inst_basereg = cfg->frame_reg;
- load->inst_offset = mono_spillvar_offset (cfg, spill);
- if (item->prev) {
- while (ins->next != item->prev->data)
- ins = ins->next;
- }
- load->next = ins->next;
- ins->next = load;
- DEBUG (g_print ("SPILLED LOAD (%d at 0x%08lx(%%sp)) R%d (freed %s)\n", spill, (long)load->inst_offset, i, mono_arch_regname (sel)));
- i = mono_regstate_alloc_int (cfg->rs, 1 << sel);
- g_assert (i == sel);
-
- return sel;
-}
-
-static int
-get_float_register_spilling (MonoCompile *cfg, InstList *item, MonoInst *ins, guint32 regmask, int reg)
-{
- MonoInst *load;
- int i, sel, spill;
-
- DEBUG (g_print ("start regmask to assign R%d: 0x%08x (R%d <- R%d R%d)\n", reg, regmask, ins->dreg, ins->sreg1, ins->sreg2));
- /* exclude the registers in the current instruction */
- if (reg != ins->sreg1 && (freg_is_freeable (ins->sreg1) || (ins->sreg1 >= MONO_MAX_FREGS && cfg->rs->fassign [ins->sreg1] >= 0))) {
- if (ins->sreg1 >= MONO_MAX_FREGS)
- regmask &= ~ (1 << cfg->rs->fassign [ins->sreg1]);
- else
- regmask &= ~ (1 << ins->sreg1);
- DEBUG (g_print ("excluding sreg1 %s\n", mono_arch_regname (ins->sreg1)));
- }
- if (reg != ins->sreg2 && (freg_is_freeable (ins->sreg2) || (ins->sreg2 >= MONO_MAX_FREGS && cfg->rs->fassign [ins->sreg2] >= 0))) {
- if (ins->sreg2 >= MONO_MAX_FREGS)
- regmask &= ~ (1 << cfg->rs->fassign [ins->sreg2]);
- else
- regmask &= ~ (1 << ins->sreg2);
- DEBUG (g_print ("excluding sreg2 %s %d\n", mono_arch_regname (ins->sreg2), ins->sreg2));
- }
- if (reg != ins->dreg && freg_is_freeable (ins->dreg)) {
- regmask &= ~ (1 << ins->dreg);
- DEBUG (g_print ("excluding dreg %s\n", mono_arch_regname (ins->dreg)));
- }
-
- DEBUG (g_print ("available regmask: 0x%08x\n", regmask));
- g_assert (regmask); /* need at least a register we can free */
- sel = -1;
- /* we should track prev_use and spill the register that's farther */
- for (i = 0; i < MONO_MAX_FREGS; ++i) {
- if (regmask & (1 << i)) {
- sel = i;
- DEBUG (g_print ("selected register %s has assignment %d\n", mono_arch_regname (sel), cfg->rs->fassign [sel]));
- break;
- }
- }
- i = cfg->rs->fsymbolic [sel];
- spill = ++cfg->spill_count;
- cfg->rs->fassign [i] = -spill - 1;
- mono_regstate_free_float(cfg->rs, sel);
- /* we need to create a spill var and insert a load to sel after the current instruction */
- MONO_INST_NEW (cfg, load, OP_LOADR8_MEMBASE);
- load->dreg = sel;
- load->inst_basereg = cfg->frame_reg;
- load->inst_offset = mono_spillvar_offset_float (cfg, spill);
- if (item->prev) {
- while (ins->next != item->prev->data)
- ins = ins->next;
- }
- load->next = ins->next;
- ins->next = load;
- DEBUG (g_print ("SPILLED LOAD (%d at 0x%08lx(%%sp)) R%d (freed %s)\n", spill, (long)load->inst_offset, i, mono_arch_regname (sel)));
- i = mono_regstate_alloc_float (cfg->rs, 1 << sel);
- g_assert (i == sel);
-
- return sel;
-}
-
-static MonoInst*
-create_copy_ins (MonoCompile *cfg, int dest, int src, MonoInst *ins)
-{
- MonoInst *copy;
- MONO_INST_NEW (cfg, copy, OP_MOVE);
- copy->dreg = dest;
- copy->sreg1 = src;
- if (ins) {
- copy->next = ins->next;
- ins->next = copy;
- }
- DEBUG (g_print ("\tforced copy from %s to %s\n", mono_arch_regname (src), mono_arch_regname (dest)));
- return copy;
-}
-
-G_GNUC_UNUSED static MonoInst*
-create_copy_ins_float (MonoCompile *cfg, int dest, int src, MonoInst *ins)
-{
- MonoInst *copy;
- MONO_INST_NEW (cfg, copy, OP_FMOVE);
- copy->dreg = dest;
- copy->sreg1 = src;
- if (ins) {
- copy->next = ins->next;
- ins->next = copy;
- }
- DEBUG (g_print ("\tforced copy from %s to %s\n", mono_arch_regname (src), mono_arch_regname (dest)));
- return copy;
-}
-
-static MonoInst*
-create_spilled_store (MonoCompile *cfg, int spill, int reg, int prev_reg, MonoInst *ins)
-{
- MonoInst *store;
- MONO_INST_NEW (cfg, store, OP_STORE_MEMBASE_REG);
- store->sreg1 = reg;
- store->inst_destbasereg = cfg->frame_reg;
- store->inst_offset = mono_spillvar_offset (cfg, spill);
- if (ins) {
- store->next = ins->next;
- ins->next = store;
- }
- DEBUG (g_print ("SPILLED STORE (%d at 0x%08lx(%%sp)) R%d (from %s)\n", spill, (long)store->inst_offset, prev_reg, mono_arch_regname (reg)));
- return store;
-}
-
-static MonoInst*
-create_spilled_store_float (MonoCompile *cfg, int spill, int reg, int prev_reg, MonoInst *ins)
-{
- MonoInst *store;
- MONO_INST_NEW (cfg, store, OP_STORER8_MEMBASE_REG);
- store->sreg1 = reg;
- store->inst_destbasereg = cfg->frame_reg;
- store->inst_offset = mono_spillvar_offset_float (cfg, spill);
- if (ins) {
- store->next = ins->next;
- ins->next = store;
- }
- DEBUG (g_print ("SPILLED STORE (%d at 0x%08lx(%%sp)) R%d (from %s)\n", spill, (long)store->inst_offset, prev_reg, mono_arch_regname (reg)));
- return store;
-}
-
-static void
-insert_before_ins (MonoInst *ins, InstList *item, MonoInst* to_insert)
-{
- MonoInst *prev;
- g_assert (item->next);
- prev = item->next->data;
-
- while (prev->next != ins)
- prev = prev->next;
- to_insert->next = ins;
- prev->next = to_insert;
- /*
- * needed otherwise in the next instruction we can add an ins to the
- * end and that would get past this instruction.
- */
- item->data = to_insert;
-}
-
-G_GNUC_UNUSED static int
-alloc_int_reg (MonoCompile *cfg, InstList *curinst, MonoInst *ins, int sym_reg, guint32 allow_mask)
-{
- int val = cfg->rs->iassign [sym_reg];
- if (val < 0) {
- int spill = 0;
- if (val < -1) {
- /* the register gets spilled after this inst */
- spill = -val -1;
- }
- val = mono_regstate_alloc_int (cfg->rs, allow_mask);
- if (val < 0)
- val = get_register_spilling (cfg, curinst, ins, allow_mask, sym_reg);
- cfg->rs->iassign [sym_reg] = val;
- /* add option to store before the instruction for src registers */
- if (spill)
- create_spilled_store (cfg, spill, val, sym_reg, ins);
- }
- cfg->rs->isymbolic [val] = sym_reg;
- return val;
-}
-
/* FIXME: Strange loads from the stack in basic-float.cs:test_2_rem */
-/*
- * Local register allocation.
- * We first scan the list of instructions and we save the liveness info of
- * each register (when the register is first used, when it's value is set etc.).
- * We also reverse the list of instructions (in the InstList list) because assigning
- * registers backwards allows for more tricks to be used.
- */
void
mono_arch_local_regalloc (MonoCompile *cfg, MonoBasicBlock *bb)
{
- MonoInst *ins;
- MonoRegState *rs = cfg->rs;
- int i, val;
- RegTrack *reginfo, *reginfof;
- RegTrack *reginfo1, *reginfo2, *reginfod;
- InstList *tmp, *reversed = NULL;
- const char *spec;
- guint32 src1_mask, src2_mask, dest_mask;
- guint32 cur_iregs, cur_fregs;
-
- /* FIXME: Use caller saved regs and %i1-%2 for allocation */
-
- if (!bb->code)
- return;
- rs->next_vireg = bb->max_ireg;
- rs->next_vfreg = bb->max_freg;
- mono_regstate_assign (rs);
- reginfo = mono_mempool_alloc0 (cfg->mempool, sizeof (RegTrack) * rs->next_vireg);
- reginfof = mono_mempool_alloc0 (cfg->mempool, sizeof (RegTrack) * rs->next_vfreg);
- rs->ifree_mask = ARCH_CALLER_REGS;
- rs->ffree_mask = ARCH_CALLER_FREGS;
-
- ins = bb->code;
- i = 1;
- DEBUG (g_print ("LOCAL regalloc: basic block: %d\n", bb->block_num));
- /* forward pass on the instructions to collect register liveness info */
- while (ins) {
- spec = ins_spec [ins->opcode];
- if (!spec) {
- /* Use a default */
- spec = ins_spec [CEE_ADD];
- }
- DEBUG (print_ins (i, ins));
-
- if (spec [MONO_INST_SRC1]) {
- if (spec [MONO_INST_SRC1] == 'f')
- reginfo1 = reginfof;
- else
- reginfo1 = reginfo;
- reginfo1 [ins->sreg1].prev_use = reginfo1 [ins->sreg1].last_use;
- reginfo1 [ins->sreg1].last_use = i;
- } else {
- ins->sreg1 = -1;
- }
- if (spec [MONO_INST_SRC2]) {
- if (spec [MONO_INST_SRC2] == 'f')
- reginfo2 = reginfof;
- else
- reginfo2 = reginfo;
- reginfo2 [ins->sreg2].prev_use = reginfo2 [ins->sreg2].last_use;
- reginfo2 [ins->sreg2].last_use = i;
- } else {
- ins->sreg2 = -1;
- }
- if (spec [MONO_INST_DEST]) {
- if (spec [MONO_INST_DEST] == 'f')
- reginfod = reginfof;
- else
- reginfod = reginfo;
- if (spec [MONO_INST_DEST] != 'b') /* it's not just a base register */
- reginfod [ins->dreg].killed_in = i;
- reginfod [ins->dreg].prev_use = reginfod [ins->dreg].last_use;
- reginfod [ins->dreg].last_use = i;
- if (reginfod [ins->dreg].born_in == 0 || reginfod [ins->dreg].born_in > i)
- reginfod [ins->dreg].born_in = i;
- if (!v64 && (spec [MONO_INST_DEST] == 'l')) {
- /* result in a regpair, the virtual register is allocated sequentially */
- reginfod [ins->dreg + 1].prev_use = reginfod [ins->dreg + 1].last_use;
- reginfod [ins->dreg + 1].last_use = i;
- if (reginfod [ins->dreg + 1].born_in == 0 || reginfod [ins->dreg + 1].born_in > i)
- reginfod [ins->dreg + 1].born_in = i;
- }
- } else {
- ins->dreg = -1;
- }
- reversed = inst_list_prepend (cfg->mempool, reversed, ins);
- ++i;
- ins = ins->next;
- }
-
- cur_iregs = ARCH_CALLER_REGS;
- cur_fregs = ARCH_CALLER_FREGS;
-
- DEBUG (print_regtrack (reginfo, rs->next_vireg));
- DEBUG (print_regtrack (reginfof, rs->next_vfreg));
- tmp = reversed;
- while (tmp) {
- int prev_dreg, prev_sreg1, prev_sreg2;
- --i;
- ins = tmp->data;
- spec = ins_spec [ins->opcode];
- if (!spec)
- spec = ins_spec [CEE_ADD];
- DEBUG (g_print ("processing:"));
- DEBUG (print_ins (i, ins));
-
- /* make the register available for allocation: FIXME add fp reg */
- if (ins->opcode == OP_SETREG || ins->opcode == OP_SETREGIMM) {
- /* Dont free register which can't be allocated */
- if (reg_is_freeable (ins->dreg)) {
- cur_iregs |= 1 << ins->dreg;
- DEBUG (g_print ("adding %d to cur_iregs\n", ins->dreg));
- }
- } else if (ins->opcode == OP_SETFREG) {
- if (freg_is_freeable (ins->dreg)) {
- cur_fregs |= 1 << ins->dreg;
- DEBUG (g_print ("adding %d to cur_fregs\n", ins->dreg));
- }
- } else if (spec [MONO_INST_CLOB] == 'c') {
- MonoCallInst *cinst = (MonoCallInst*)ins;
- DEBUG (g_print ("excluding regs 0x%lx from cur_iregs (0x%x)\n", (long)cinst->used_iregs, cur_iregs));
- cur_iregs &= ~cinst->used_iregs;
- cur_fregs &= ~cinst->used_fregs;
- DEBUG (g_print ("available cur_iregs: 0x%x\n", cur_iregs));
- /* registers used by the calling convention are excluded from
- * allocation: they will be selectively enabled when they are
- * assigned by the special SETREG opcodes.
- */
- }
- dest_mask = src1_mask = src2_mask = cur_iregs;
-
- /*
- * DEST
- */
- /* update for use with FP regs... */
- if (spec [MONO_INST_DEST] == 'f') {
- if (ins->dreg >= MONO_MAX_FREGS) {
- val = rs->fassign [ins->dreg];
- prev_dreg = ins->dreg;
- if (val < 0) {
- int spill = 0;
- if (val < -1) {
- /* the register gets spilled after this inst */
- spill = -val -1;
- }
- dest_mask = cur_fregs;
- val = mono_regstate_alloc_float (rs, dest_mask);
- if (val < 0)
- val = get_float_register_spilling (cfg, tmp, ins, dest_mask, ins->dreg);
- rs->fassign [ins->dreg] = val;
- if (spill)
- create_spilled_store_float (cfg, spill, val, prev_dreg, ins);
- }
- DEBUG (g_print ("\tassigned dreg %s to dest R%d\n", mono_arch_regname (val), ins->dreg));
- rs->fsymbolic [val] = prev_dreg;
- ins->dreg = val;
- } else {
- prev_dreg = -1;
- }
- if (freg_is_freeable (ins->dreg) && prev_dreg >= 0 && (reginfo [prev_dreg].born_in >= i || !(cur_fregs & (1 << ins->dreg)))) {
- DEBUG (g_print ("\tfreeable %s (R%d) (born in %d)\n", mono_arch_regname (ins->dreg), prev_dreg, reginfo [prev_dreg].born_in));
- mono_regstate_free_float (rs, ins->dreg);
- }
- } else if (ins->dreg >= MONO_MAX_IREGS) {
- val = rs->iassign [ins->dreg];
- prev_dreg = ins->dreg;
- if (val < 0) {
- int spill = 0;
- if (val < -1) {
- /* the register gets spilled after this inst */
- spill = -val -1;
- }
- val = mono_regstate_alloc_int (rs, dest_mask);
- if (val < 0)
- val = get_register_spilling (cfg, tmp, ins, dest_mask, ins->dreg);
- rs->iassign [ins->dreg] = val;
- if (spill)
- create_spilled_store (cfg, spill, val, prev_dreg, ins);
- }
- DEBUG (g_print ("\tassigned dreg %s to dest R%d\n", mono_arch_regname (val), ins->dreg));
- rs->isymbolic [val] = prev_dreg;
- ins->dreg = val;
- if (!v64 && spec [MONO_INST_DEST] == 'l') {
- int hreg = prev_dreg + 1;
- val = rs->iassign [hreg];
- if (val < 0) {
- int spill = 0;
- if (val < -1) {
- /* the register gets spilled after this inst */
- spill = -val -1;
- }
- /* The second register must be a pair of the first */
- dest_mask = 1 << (rs->iassign [prev_dreg] + 1);
- val = mono_regstate_alloc_int (rs, dest_mask);
- if (val < 0)
- val = get_register_spilling (cfg, tmp, ins, dest_mask, hreg);
- rs->iassign [hreg] = val;
- if (spill)
- create_spilled_store (cfg, spill, val, hreg, ins);
- }
- else {
- /* The second register must be a pair of the first */
- if (val != rs->iassign [prev_dreg] + 1) {
- dest_mask = 1 << (rs->iassign [prev_dreg] + 1);
-
- val = mono_regstate_alloc_int (rs, dest_mask);
- if (val < 0)
- val = get_register_spilling (cfg, tmp, ins, dest_mask, hreg);
-
- create_copy_ins (cfg, rs->iassign [hreg], val, ins);
-
- rs->iassign [hreg] = val;
- }
- }
-
- DEBUG (g_print ("\tassigned hreg %s to dest R%d\n", mono_arch_regname (val), hreg));
- rs->isymbolic [val] = hreg;
-
- if (reg_is_freeable (val) && hreg >= 0 && (reginfo [hreg].born_in >= i && !(cur_iregs & (1 << val)))) {
- DEBUG (g_print ("\tfreeable %s (R%d)\n", mono_arch_regname (val), hreg));
- mono_regstate_free_int (rs, val);
- }
- }
- } else {
- prev_dreg = -1;
- }
- if (spec [MONO_INST_DEST] != 'f' && reg_is_freeable (ins->dreg) && prev_dreg >= 0 && (reginfo [prev_dreg].born_in >= i)) {
- DEBUG (g_print ("\tfreeable %s (R%d) (born in %d)\n", mono_arch_regname (ins->dreg), prev_dreg, reginfo [prev_dreg].born_in));
- mono_regstate_free_int (rs, ins->dreg);
- }
-
- /**
- * SRC1
- */
- if (spec [MONO_INST_SRC1] == 'f') {
- if (ins->sreg1 >= MONO_MAX_FREGS) {
- val = rs->fassign [ins->sreg1];
- prev_sreg1 = ins->sreg1;
- if (val < 0) {
- int spill = 0;
- if (val < -1) {
- /* the register gets spilled after this inst */
- spill = -val -1;
- }
- //g_assert (val == -1); /* source cannot be spilled */
- src1_mask = cur_fregs;
- val = mono_regstate_alloc_float (rs, src1_mask);
- if (val < 0)
- val = get_float_register_spilling (cfg, tmp, ins, src1_mask, ins->sreg1);
- rs->fassign [ins->sreg1] = val;
- DEBUG (g_print ("\tassigned sreg1 %s to R%d\n", mono_arch_regname (val), ins->sreg1));
- if (spill) {
- MonoInst *store = create_spilled_store_float (cfg, spill, val, prev_sreg1, NULL);
- insert_before_ins (ins, tmp, store);
- }
- }
- rs->fsymbolic [val] = prev_sreg1;
- ins->sreg1 = val;
- } else {
- prev_sreg1 = -1;
- }
- } else if (ins->sreg1 >= MONO_MAX_IREGS) {
- val = rs->iassign [ins->sreg1];
- prev_sreg1 = ins->sreg1;
- if (val < 0) {
- int spill = 0;
- if (val < -1) {
- /* the register gets spilled after this inst */
- spill = -val -1;
- }
- if (0 && (ins->opcode == OP_MOVE) && reg_is_freeable (ins->dreg)) {
- /*
- * small optimization: the dest register is already allocated
- * but the src one is not: we can simply assign the same register
- * here and peephole will get rid of the instruction later.
- * This optimization may interfere with the clobbering handling:
- * it removes a mov operation that will be added again to handle clobbering.
- * There are also some other issues that should with make testjit.
- */
- mono_regstate_alloc_int (rs, 1 << ins->dreg);
- val = rs->iassign [ins->sreg1] = ins->dreg;
- //g_assert (val >= 0);
- DEBUG (g_print ("\tfast assigned sreg1 %s to R%d\n", mono_arch_regname (val), ins->sreg1));
- } else {
- //g_assert (val == -1); /* source cannot be spilled */
- val = mono_regstate_alloc_int (rs, src1_mask);
- if (val < 0)
- val = get_register_spilling (cfg, tmp, ins, src1_mask, ins->sreg1);
- rs->iassign [ins->sreg1] = val;
- DEBUG (g_print ("\tassigned sreg1 %s to R%d\n", mono_arch_regname (val), ins->sreg1));
- }
- if (spill) {
- MonoInst *store = create_spilled_store (cfg, spill, val, prev_sreg1, NULL);
- insert_before_ins (ins, tmp, store);
- }
- }
- rs->isymbolic [val] = prev_sreg1;
- ins->sreg1 = val;
- } else {
- prev_sreg1 = -1;
- }
-
- /*
- * SRC2
- */
- if (spec [MONO_INST_SRC2] == 'f') {
- if (ins->sreg2 >= MONO_MAX_FREGS) {
- val = rs->fassign [ins->sreg2];
- prev_sreg2 = ins->sreg2;
- if (val < 0) {
- int spill = 0;
- if (val < -1) {
- /* the register gets spilled after this inst */
- spill = -val -1;
- }
- src2_mask = cur_fregs;
- val = mono_regstate_alloc_float (rs, src2_mask);
- if (val < 0)
- val = get_float_register_spilling (cfg, tmp, ins, src2_mask, ins->sreg2);
- rs->fassign [ins->sreg2] = val;
- DEBUG (g_print ("\tassigned sreg2 %s to R%d\n", mono_arch_regname (val), ins->sreg2));
- if (spill)
- create_spilled_store_float (cfg, spill, val, prev_sreg2, ins);
- }
- rs->fsymbolic [val] = prev_sreg2;
- ins->sreg2 = val;
- } else {
- prev_sreg2 = -1;
- }
- } else if (ins->sreg2 >= MONO_MAX_IREGS) {
- val = rs->iassign [ins->sreg2];
- prev_sreg2 = ins->sreg2;
- if (val < 0) {
- int spill = 0;
- if (val < -1) {
- /* the register gets spilled after this inst */
- spill = -val -1;
- }
- val = mono_regstate_alloc_int (rs, src2_mask);
- if (val < 0)
- val = get_register_spilling (cfg, tmp, ins, src2_mask, ins->sreg2);
- rs->iassign [ins->sreg2] = val;
- DEBUG (g_print ("\tassigned sreg2 %s to R%d\n", mono_arch_regname (val), ins->sreg2));
- if (spill)
- create_spilled_store (cfg, spill, val, prev_sreg2, ins);
- }
- rs->isymbolic [val] = prev_sreg2;
- ins->sreg2 = val;
- } else {
- prev_sreg2 = -1;
- }
-
- if (spec [MONO_INST_CLOB] == 'c') {
- int j, s;
- guint32 clob_mask = ARCH_CALLER_REGS;
- for (j = 0; j < MONO_MAX_IREGS; ++j) {
- s = 1 << j;
- if ((clob_mask & s) && !(rs->ifree_mask & s) && j != ins->sreg1) {
- //g_warning ("register %s busy at call site\n", mono_arch_regname (j));
- }
- }
- }
- /*if (reg_is_freeable (ins->sreg1) && prev_sreg1 >= 0 && reginfo [prev_sreg1].born_in >= i) {
- DEBUG (g_print ("freeable %s\n", mono_arch_regname (ins->sreg1)));
- mono_regstate_free_int (rs, ins->sreg1);
- }
- if (reg_is_freeable (ins->sreg2) && prev_sreg2 >= 0 && reginfo [prev_sreg2].born_in >= i) {
- DEBUG (g_print ("freeable %s\n", mono_arch_regname (ins->sreg2)));
- mono_regstate_free_int (rs, ins->sreg2);
- }*/
-
- //DEBUG (print_ins (i, ins));
-
- tmp = tmp->next;
- }
+ mono_local_regalloc (cfg, bb);
}
static void
emit_move_return_value (MonoInst *ins, guint32 *code)
{
/* Move return value to the target register */
- /* FIXME: do this in the local reg allocator */
+ /* FIXME: do more things in the local reg allocator */
switch (ins->opcode) {
case OP_VOIDCALL:
case OP_VOIDCALL_REG:
case CEE_CALL:
case OP_CALL_REG:
case OP_CALL_MEMBASE:
- sparc_mov_reg_reg (code, sparc_o0, ins->dreg);
+ g_assert (ins->dreg == sparc_o0);
break;
case OP_LCALL:
case OP_LCALL_REG:
case OP_LCALL_MEMBASE:
/*
* ins->dreg is the least significant reg due to the lreg: LCALL rule
- * in inssel.brg.
+ * in inssel-long32.brg.
*/
#ifdef SPARCV9
sparc_mov_reg_reg (code, sparc_o0, ins->dreg);
#else
- sparc_mov_reg_reg (code, sparc_o0, ins->dreg + 1);
- sparc_mov_reg_reg (code, sparc_o1, ins->dreg);
+ g_assert (ins->dreg == sparc_o1);
#endif
break;
case OP_FCALL:
/* FIXME: Generate intermediate code instead */
- sig = method->signature;
+ sig = mono_method_signature (method);
cinfo = get_call_info (sig, FALSE);
}
/*
- * mono_sparc_get_vcall_slot_addr:
+ * mono_arch_get_vcall_slot_addr:
*
* Determine the vtable slot used by a virtual call.
*/
gpointer*
-mono_sparc_get_vcall_slot_addr (guint32 *code, gpointer *fp)
+mono_arch_get_vcall_slot_addr (guint8 *code8, gpointer *regs)
{
+ guint32 *code = (guint32*)(gpointer)code8;
guint32 ins = code [0];
guint32 prev_ins = code [-1];
mono_sparc_flushw ();
- fp = (gpointer*)((guint8*)fp + MONO_SPARC_STACK_BIAS);
+ if (!mono_sparc_is_virtual_call (code))
+ return NULL;
if ((sparc_inst_op (ins) == 0x2) && (sparc_inst_op3 (ins) == 0x38)) {
if ((sparc_inst_op (prev_ins) == 0x3) && (sparc_inst_op3 (prev_ins) == 0 || sparc_inst_op3 (prev_ins) == 0xb)) {
g_assert (sparc_inst_rd (prev_ins) == sparc_inst_rs1 (ins));
g_assert ((base >= sparc_o0) && (base <= sparc_i7));
-
- base_val = fp [base - 16];
+
+ base_val = regs [base - sparc_o0];
return (gpointer)((guint8*)base_val + disp);
}
else
g_assert_not_reached ();
- return FALSE;
+ return NULL;
}
/*
code = emit_move_return_value (ins, code);
break;
case OP_SETFRET:
- if (cfg->method->signature->ret->type == MONO_TYPE_R4)
+ if (mono_method_signature (cfg->method)->ret->type == MONO_TYPE_R4)
sparc_fdtos (code, ins->sreg1, sparc_f0);
else {
#ifdef SPARCV9
case OP_OUTARG:
g_assert_not_reached ();
break;
- case OP_LOCALLOC:
+ case OP_LOCALLOC: {
+ guint32 size_reg;
+
+#ifdef MONO_ARCH_SIGSEGV_ON_ALTSTACK
+ /* Perform stack touching */
+ NOT_IMPLEMENTED;
+#endif
+
/* Keep alignment */
sparc_add_imm (code, FALSE, ins->sreg1, MONO_ARCH_FRAME_ALIGNMENT - 1, ins->dreg);
sparc_set (code, ~(MONO_ARCH_FRAME_ALIGNMENT - 1), sparc_o7);
sparc_and (code, FALSE, ins->dreg, sparc_o7, ins->dreg);
+
+ if ((ins->flags & MONO_INST_INIT) && (ins->sreg1 == ins->dreg)) {
+#ifdef SPARCV9
+ size_reg = sparc_g4;
+#else
+ size_reg = sparc_g1;
+#endif
+ sparc_mov_reg_reg (code, ins->dreg, size_reg);
+ }
+ else
+ size_reg = ins->sreg1;
+
sparc_sub (code, FALSE, sparc_sp, ins->dreg, ins->dreg);
/* Keep %sp valid at all times */
sparc_mov_reg_reg (code, ins->dreg, sparc_sp);
- g_assert (sparc_is_imm13 (cfg->arch.localloc_offset));
+ g_assert (sparc_is_imm13 (MONO_SPARC_STACK_BIAS + cfg->arch.localloc_offset));
sparc_add_imm (code, FALSE, ins->dreg, MONO_SPARC_STACK_BIAS + cfg->arch.localloc_offset, ins->dreg);
+
+ if (ins->flags & MONO_INST_INIT) {
+ guint32 *br [3];
+ /* Initialize memory region */
+ sparc_cmp_imm (code, size_reg, 0);
+ br [0] = code;
+ sparc_branch (code, 0, sparc_be, 0);
+ /* delay slot */
+ sparc_set (code, 0, sparc_o7);
+ sparc_sub_imm (code, 0, size_reg, sparcv9 ? 8 : 4, size_reg);
+ /* start of loop */
+ br [1] = code;
+ if (sparcv9)
+ sparc_stx (code, sparc_g0, ins->dreg, sparc_o7);
+ else
+ sparc_st (code, sparc_g0, ins->dreg, sparc_o7);
+ sparc_cmp (code, sparc_o7, size_reg);
+ br [2] = code;
+ sparc_branch (code, 0, sparc_bl, 0);
+ sparc_patch (br [2], br [1]);
+ /* delay slot */
+ sparc_add_imm (code, 0, sparc_o7, sparcv9 ? 8 : 4, sparc_o7);
+ sparc_patch (br [0], code);
+ }
break;
+ }
case OP_SPARC_LOCALLOC_IMM: {
gint32 offset = ins->inst_c0;
+
+#ifdef MONO_ARCH_SIGSEGV_ON_ALTSTACK
+ /* Perform stack touching */
+ NOT_IMPLEMENTED;
+#endif
+
offset = ALIGN_TO (offset, MONO_ARCH_FRAME_ALIGNMENT);
if (sparc_is_imm13 (offset))
sparc_sub_imm (code, FALSE, sparc_sp, offset, sparc_sp);
sparc_set (code, offset, sparc_o7);
sparc_sub (code, FALSE, sparc_sp, sparc_o7, sparc_sp);
}
- sparc_mov_reg_reg (code, sparc_sp, ins->dreg);
- g_assert (sparc_is_imm13 (cfg->arch.localloc_offset));
- sparc_add_imm (code, FALSE, ins->dreg, MONO_SPARC_STACK_BIAS + cfg->arch.localloc_offset, ins->dreg);
+ g_assert (sparc_is_imm13 (MONO_SPARC_STACK_BIAS + cfg->arch.localloc_offset));
+ sparc_add_imm (code, FALSE, sparc_sp, MONO_SPARC_STACK_BIAS + cfg->arch.localloc_offset, ins->dreg);
+ if ((ins->flags & MONO_INST_INIT) && (offset > 0)) {
+ guint32 *br [2];
+ int i;
+
+ if (offset <= 16) {
+ i = 0;
+ while (i < offset) {
+ if (sparcv9) {
+ sparc_stx_imm (code, sparc_g0, ins->dreg, i);
+ i += 8;
+ }
+ else {
+ sparc_st_imm (code, sparc_g0, ins->dreg, i);
+ i += 4;
+ }
+ }
+ }
+ else {
+ sparc_set (code, offset, sparc_o7);
+ sparc_sub_imm (code, 0, sparc_o7, sparcv9 ? 8 : 4, sparc_o7);
+ /* beginning of loop */
+ br [0] = code;
+ if (sparcv9)
+ sparc_stx (code, sparc_g0, ins->dreg, sparc_o7);
+ else
+ sparc_st (code, sparc_g0, ins->dreg, sparc_o7);
+ sparc_cmp_imm (code, sparc_o7, 0);
+ br [1] = code;
+ sparc_branch (code, 0, sparc_bne, 0);
+ /* delay slot */
+ sparc_sub_imm (code, 0, sparc_o7, sparcv9 ? 8 : 4, sparc_o7);
+ sparc_patch (br [1], br [0]);
+ }
+ }
break;
}
case CEE_RET:
(gpointer)"mono_arch_throw_exception");
EMIT_CALL ();
break;
+ case OP_RETHROW:
+ sparc_mov_reg_reg (code, ins->sreg1, sparc_o0);
+ mono_add_patch_info (cfg, (guint8*)code - cfg->native_code, MONO_PATCH_INFO_INTERNAL_METHOD,
+ (gpointer)"mono_arch_rethrow_exception");
+ EMIT_CALL ();
+ break;
case OP_START_HANDLER: {
/*
* The START_HANDLER instruction marks the beginning of a handler
gint32 offset = mono_spillvar_offset_float (cfg, 0);
if (!sparc_is_imm13 (offset))
NOT_IMPLEMENTED;
- /* FIXME: Is having the same code for all of these ok ? */
sparc_fdtoi (code, ins->sreg1, FP_SCRATCH_REG);
sparc_stdf_imm (code, FP_SCRATCH_REG, sparc_sp, offset);
sparc_ld_imm (code, sparc_sp, offset, ins->dreg);
+
+ switch (ins->opcode) {
+ case OP_FCONV_TO_I1:
+ case OP_FCONV_TO_U1:
+ sparc_and_imm (code, 0, ins->dreg, 0xff, ins->dreg);
+ break;
+ case OP_FCONV_TO_I2:
+ case OP_FCONV_TO_U2:
+ sparc_set (code, 0xffff, sparc_o7);
+ sparc_and (code, 0, ins->dreg, sparc_o7, ins->dreg);
+ break;
+ default:
+ break;
+ }
break;
}
case OP_FCONV_TO_I8:
sparc_cmp_imm (code, ins->sreg2, -1);
br [2] = code;
sparc_branch (code, 1, sparc_bne, 0);
+ sparc_nop (code);
sparc_patch (br [2], label [0]);
/* Ok */
target = mono_resolve_patch_target (method, domain, code, patch_info, run_cctors);
switch (patch_info->type) {
+ case MONO_PATCH_INFO_NONE:
+ continue;
case MONO_PATCH_INFO_CLASS_INIT: {
guint32 *ip2 = (guint32*)ip;
/* Might already been changed to a nop */
}
}
-void
-mono_arch_instrument_mem_needs (MonoMethod *method, int *stack, int *code)
-{
- *stack = 0;
- *code = 512;
-}
-
void*
mono_arch_instrument_prolog (MonoCompile *cfg, void *func, void *p, gboolean enable_arguments)
{
- int i, stack, code_size;
+ int i;
guint32 *code = (guint32*)p;
- MonoMethodSignature *sig = cfg->method->signature;
+ MonoMethodSignature *sig = mono_method_signature (cfg->method);
CallInfo *cinfo;
/* Save registers to stack */
}
}
- mono_arch_instrument_mem_needs (cfg->method, &stack, &code_size);
-
- g_assert ((code - (guint32*)p) <= (code_size * 4));
-
g_free (cinfo);
return code;
int save_mode = SAVE_NONE;
MonoMethod *method = cfg->method;
- switch (mono_type_get_underlying_type (method->signature->ret)->type) {
+ switch (mono_type_get_underlying_type (mono_method_signature (method)->ret)->type) {
case MONO_TYPE_VOID:
/* special case string .ctor icall */
if (strcmp (".ctor", method->name) && method->klass == mono_defaults.string_class)
return code;
}
-int
-mono_arch_max_epilog_size (MonoCompile *cfg)
-{
- int exc_count = 0, max_epilog_size = 16 + 20*4;
- MonoJumpInfo *patch_info;
-
- if (cfg->method->save_lmf)
- max_epilog_size += 128;
-
- if (mono_jit_trace_calls != NULL)
- max_epilog_size += 50;
-
- if (cfg->prof_options & MONO_PROFILE_ENTER_LEAVE)
- max_epilog_size += 50;
-
- /* count the number of exception infos */
-
- for (patch_info = cfg->patch_info; patch_info; patch_info = patch_info->next) {
- if (patch_info->type == MONO_PATCH_INFO_EXC)
- exc_count++;
- }
-
- /*
- * make sure we have enough space for exceptions
- */
-#ifdef SPARCV9
- max_epilog_size += exc_count * (20 * 4);
-#else
- max_epilog_size += exc_count * 24;
-#endif
-
- return max_epilog_size;
-}
-
guint8 *
mono_arch_emit_prolog (MonoCompile *cfg)
{
cfg->stack_offset = offset;
+#ifdef MONO_ARCH_SIGSEGV_ON_ALTSTACK
+ /* Perform stack touching */
+ NOT_IMPLEMENTED;
+#endif
+
if (!sparc_is_imm13 (- cfg->stack_offset)) {
/* Can't use sparc_o7 here, since we're still in the caller's frame */
sparc_set (code, (- cfg->stack_offset), GP_SCRATCH_REG);
sparc_save_imm (code, sparc_sp, - cfg->stack_offset, sparc_sp);
/*
- if (strstr (cfg->method->name, "test_marshal_struct")) {
- mono_add_patch_info (cfg, code - cfg->native_code, MONO_PATCH_INFO_ABS, mono_sparc_break);
+ if (strstr (cfg->method->name, "foo")) {
+ mono_add_patch_info (cfg, (guint8*)code - cfg->native_code, MONO_PATCH_INFO_ABS, mono_sparc_break);
sparc_call_simple (code, 0);
sparc_nop (code);
}
*/
- sig = method->signature;
+ sig = mono_method_signature (method);
cinfo = get_call_info (sig, FALSE);
void
mono_arch_emit_epilog (MonoCompile *cfg)
{
- MonoJumpInfo *patch_info;
MonoMethod *method = cfg->method;
guint32 *code;
int can_fold = 0;
+ int max_epilog_size = 16 + 20 * 4;
+
+ if (cfg->method->save_lmf)
+ max_epilog_size += 128;
+
+ if (mono_jit_trace_calls != NULL)
+ max_epilog_size += 50;
+
+ if (cfg->prof_options & MONO_PROFILE_ENTER_LEAVE)
+ max_epilog_size += 50;
+
+ while (cfg->code_len + max_epilog_size > (cfg->code_size - 16)) {
+ cfg->code_size *= 2;
+ cfg->native_code = g_realloc (cfg->native_code, cfg->code_size);
+ mono_jit_stats.code_reallocs++;
+ }
code = (guint32*)(cfg->native_code + cfg->code_len);
* The V8 ABI requires that calls to functions which return a structure
* return to %i7+12
*/
- if (!v64 && cfg->method->signature->pinvoke && MONO_TYPE_ISSTRUCT(cfg->method->signature->ret))
+ if (!v64 && mono_method_signature (cfg->method)->pinvoke && MONO_TYPE_ISSTRUCT(mono_method_signature (cfg->method)->ret))
sparc_jmpl_imm (code, sparc_i7, 12, sparc_g0);
else
sparc_ret (code);
else
sparc_restore_imm (code, sparc_g0, 0, sparc_g0);
- /* add code to raise exceptions */
+ cfg->code_len = (guint8*)code - cfg->native_code;
+
+ g_assert (cfg->code_len < cfg->code_size);
+
+}
+
+void
+mono_arch_emit_exceptions (MonoCompile *cfg)
+{
+ MonoJumpInfo *patch_info;
+ guint32 *code;
+ int nthrows = 0, i;
+ int exc_count = 0;
+ guint32 code_size;
+ MonoClass *exc_classes [16];
+ guint8 *exc_throw_start [16], *exc_throw_end [16];
+
+ /* Compute needed space */
for (patch_info = cfg->patch_info; patch_info; patch_info = patch_info->next) {
- glong offset = patch_info->ip.i;
+ if (patch_info->type == MONO_PATCH_INFO_EXC)
+ exc_count++;
+ }
+
+ /*
+ * make sure we have enough space for exceptions
+ */
+#ifdef SPARCV9
+ code_size = exc_count * (20 * 4);
+#else
+ code_size = exc_count * 24;
+#endif
+
+ while (cfg->code_len + code_size > (cfg->code_size - 16)) {
+ cfg->code_size *= 2;
+ cfg->native_code = g_realloc (cfg->native_code, cfg->code_size);
+ mono_jit_stats.code_reallocs++;
+ }
+ code = (guint32*)(cfg->native_code + cfg->code_len);
+
+ for (patch_info = cfg->patch_info; patch_info; patch_info = patch_info->next) {
switch (patch_info->type) {
- case MONO_PATCH_INFO_EXC:
+ case MONO_PATCH_INFO_EXC: {
+ MonoClass *exc_class;
+ guint32 *buf, *buf2;
+ guint32 throw_ip, type_idx;
+ gint32 disp;
+
sparc_patch ((guint32*)(cfg->native_code + patch_info->ip.i), code);
- mono_add_patch_info (cfg, (guint8*)code - cfg->native_code, MONO_PATCH_INFO_EXC_NAME, patch_info->data.target);
- sparc_set_template (code, sparc_o0);
- mono_add_patch_info (cfg, (guint8*)code - cfg->native_code, MONO_PATCH_INFO_METHOD_REL, (gpointer)offset);
- sparc_set_template (code, sparc_o1);
- patch_info->type = MONO_PATCH_INFO_INTERNAL_METHOD;
- patch_info->data.name = "mono_arch_throw_exception_by_name";
- patch_info->ip.i = (guint8*)code - cfg->native_code;
- EMIT_CALL ();
+
+ exc_class = mono_class_from_name (mono_defaults.corlib, "System", patch_info->data.name);
+ type_idx = exc_class->type_token - MONO_TOKEN_TYPE_DEF;
+ g_assert (exc_class);
+ throw_ip = patch_info->ip.i;
+
+ /* Find a throw sequence for the same exception class */
+ for (i = 0; i < nthrows; ++i)
+ if (exc_classes [i] == exc_class)
+ break;
+
+ if (i < nthrows) {
+ guint32 throw_offset = (((guint8*)exc_throw_end [i] - cfg->native_code) - throw_ip) >> 2;
+ if (!sparc_is_imm13 (throw_offset))
+ sparc_set32 (code, throw_offset, sparc_o1);
+
+ disp = (exc_throw_start [i] - (guint8*)code) >> 2;
+ g_assert (sparc_is_imm22 (disp));
+ sparc_branch (code, 0, sparc_ba, disp);
+ if (sparc_is_imm13 (throw_offset))
+ sparc_set32 (code, throw_offset, sparc_o1);
+ else
+ sparc_nop (code);
+ patch_info->type = MONO_PATCH_INFO_NONE;
+ }
+ else {
+ /* Emit the template for setting o1 */
+ buf = code;
+ if (sparc_is_imm13 (((((guint8*)code - cfg->native_code) - throw_ip) >> 2) - 8))
+ /* Can use a short form */
+ sparc_nop (code);
+ else
+ sparc_set_template (code, sparc_o1);
+ buf2 = code;
+
+ if (nthrows < 16) {
+ exc_classes [nthrows] = exc_class;
+ exc_throw_start [nthrows] = (guint8*)code;
+ }
+
+ /*
+ mono_add_patch_info (cfg, (guint8*)code - cfg->native_code, MONO_PATCH_INFO_ABS, mono_sparc_break);
+ EMIT_CALL();
+ */
+
+ /* first arg = type token */
+ /* Pass the type index to reduce the size of the sparc_set */
+ if (!sparc_is_imm13 (type_idx))
+ sparc_set32 (code, type_idx, sparc_o0);
+
+ /* second arg = offset between the throw ip and the current ip */
+ /* On sparc, the saved ip points to the call instruction */
+ disp = (((guint8*)code - cfg->native_code) - throw_ip) >> 2;
+ sparc_set32 (buf, disp, sparc_o1);
+ while (buf < buf2)
+ sparc_nop (buf);
+
+ if (nthrows < 16) {
+ exc_throw_end [nthrows] = (guint8*)code;
+ nthrows ++;
+ }
+
+ patch_info->data.name = "mono_arch_throw_corlib_exception";
+ patch_info->type = MONO_PATCH_INFO_INTERNAL_METHOD;
+ patch_info->ip.i = (guint8*)code - cfg->native_code;
+
+ EMIT_CALL ();
+
+ if (sparc_is_imm13 (type_idx)) {
+ /* Put it into the delay slot */
+ code --;
+ buf = code;
+ sparc_set32 (code, type_idx, sparc_o0);
+ g_assert (code - buf == 1);
+ }
+ }
break;
+ }
default:
/* do nothing */
break;
#endif
}
-void
-mono_arch_setup_jit_tls_data (MonoJitTlsData *tls)
-{
#ifdef MONO_ARCH_SIGSEGV_ON_ALTSTACK
+
+/*
+ * There seems to be no way to determine stack boundaries under solaris,
+ * so it's not possible to determine whenever a SIGSEGV is caused by stack
+ * overflow or not.
+ */
+#error "--with-sigaltstack=yes not supported on solaris"
+
+static void
+setup_stack (MonoJitTlsData *tls)
+{
#ifdef __linux__
struct sigaltstack sa;
#else
stack_t sigstk;
#endif
- printf ("SIGALT!\n");
/* Setup an alternate signal stack */
- tls->signal_stack = g_malloc (SIGNAL_STACK_SIZE);
+ tls->signal_stack = mmap (0, SIGNAL_STACK_SIZE, PROT_READ|PROT_WRITE|PROT_EXEC, MAP_PRIVATE|MAP_ANONYMOUS, -1, 0);
tls->signal_stack_size = SIGNAL_STACK_SIZE;
#ifdef __linux__
sigstk.ss_flags = 0;
g_assert (sigaltstack (&sigstk, NULL) == 0);
#endif
+}
+
#endif
+void
+mono_arch_setup_jit_tls_data (MonoJitTlsData *tls)
+{
if (!lmf_addr_key_inited) {
int res;
#else
pthread_setspecific (lmf_addr_key, &tls->lmf);
#endif
+
+#ifdef MONO_ARCH_SIGSEGV_ON_ALTSTACK
+ setup_stack (tls);
+#endif
}
void
}
void
-mono_arch_emit_this_vret_args (MonoCompile *cfg, MonoCallInst *inst, int this_reg, int this_type, int vt_reg)
+mono_arch_emit_this_vret_args (MonoCompile *cfg, MonoCallInst *call, int this_reg, int this_type, int vt_reg)
{
int this_out_reg = sparc_o0;
MonoInst *ins;
MONO_INST_NEW (cfg, ins, OP_SETREG);
ins->sreg1 = vt_reg;
- ins->dreg = sparc_o0;
+ ins->dreg = mono_regstate_next_int (cfg->rs);
mono_bblock_add_inst (cfg->cbb, ins);
+
+ mono_call_inst_add_outarg_reg (call, ins->dreg, sparc_o0, FALSE);
+
this_out_reg = sparc_o1;
#else
/* Set the 'struct/union return pointer' location on the stack */
MONO_INST_NEW (cfg, this, OP_SETREG);
this->type = this_type;
this->sreg1 = this_reg;
- this->dreg = this_out_reg;
+ this->dreg = mono_regstate_next_int (cfg->rs);
mono_bblock_add_inst (cfg->cbb, this);
+
+ mono_call_inst_add_outarg_reg (call, this->dreg, this_out_reg, FALSE);
}
}
-gint
-mono_arch_get_opcode_for_method (MonoCompile *cfg, MonoMethod *cmethod, MonoMethodSignature *fsig, MonoInst **args)
+MonoInst*
+mono_arch_get_inst_for_method (MonoCompile *cfg, MonoMethod *cmethod, MonoMethodSignature *fsig, MonoInst **args)
{
- return -1;
+ return NULL;
}
/*