#include <mono/utils/mono-math.h>
#include "mini-sparc.h"
-#include "inssel.h"
#include "trace.h"
#include "cpu-sparc.h"
#include "jit-icalls.h"
+#include "ir-emit.h"
/*
* Sparc V9 means two things:
{
guint32 dummy;
/* make sure sparcv9 is initialized for embedded use */
- mono_arch_cpu_optimizazions(&dummy);
+ mono_arch_cpu_optimizations(&dummy);
}
/*
* This function returns the optimizations supported on this cpu.
*/
guint32
-mono_arch_cpu_optimizazions (guint32 *exclude_mask)
+mono_arch_cpu_optimizations (guint32 *exclude_mask)
{
char buf [1024];
guint32 opts = 0;
return opts;
}
+/*
+ * This function test for all SIMD functions supported.
+ *
+ * Returns a bitmask corresponding to all supported versions.
+ *
+ */
+guint32
+mono_arch_cpu_enumerate_simd_versions (void)
+{
+ /* SIMD is currently unimplemented */
+ return 0;
+}
+
#ifdef __GNUC__
#define flushi(addr) __asm__ __volatile__ ("iflush %0"::"r"(addr):"memory")
#else /* assume Sun's compiler */
/* The address of the return value is passed in %o0 */
add_general (&gr, &stack_size, &cinfo->ret, FALSE);
cinfo->ret.reg += sparc_i0;
+ /* FIXME: Pass this after this as on other platforms */
+ NOT_IMPLEMENTED;
}
#endif
add_general (&gr, &stack_size, ainfo, FALSE);
break;
case MONO_TYPE_GENERICINST:
- if (!mono_type_generic_inst_is_valuetype (sig->params [i])) {
+ if (!mono_type_generic_inst_is_valuetype (ptype)) {
add_general (&gr, &stack_size, ainfo, FALSE);
break;
}
cinfo->ret.reg = sparc_f0;
break;
case MONO_TYPE_GENERICINST:
- if (!mono_type_generic_inst_is_valuetype (sig->ret)) {
+ if (!mono_type_generic_inst_is_valuetype (ret_type)) {
cinfo->ret.storage = ArgInIReg;
cinfo->ret.reg = sparc_i0;
if (gr < 1)
int i, offset, size, align, curinst;
CallInfo *cinfo;
- header = mono_method_get_header (cfg->method);
+ header = cfg->header;
sig = mono_method_signature (cfg->method);
cfg->ret->opcode = OP_REGVAR;
cfg->ret->inst_c0 = cinfo->ret.reg;
break;
- case ArgInIRegPair:
- if (cfg->new_ir && ((sig->ret->type == MONO_TYPE_I8) || (sig->ret->type == MONO_TYPE_U8))) {
+ case ArgInIRegPair: {
+ MonoType *t = mono_type_get_underlying_type (sig->ret);
+ if (((t->type == MONO_TYPE_I8) || (t->type == MONO_TYPE_U8))) {
MonoInst *low = get_vreg_to_inst (cfg, cfg->ret->dreg + 1);
MonoInst *high = get_vreg_to_inst (cfg, cfg->ret->dreg + 2);
cfg->ret->opcode = OP_REGVAR;
cfg->ret->inst_c0 = cinfo->ret.reg;
break;
+ }
case ArgOnStack:
#ifdef SPARCV9
g_assert_not_reached ();
/* inst->backend.is_pinvoke indicates native sized value types, this is used by the
* pinvoke wrappers when they call functions returning structure */
if (inst->backend.is_pinvoke && MONO_TYPE_ISSTRUCT (inst->inst_vtype) && inst->inst_vtype->type != MONO_TYPE_TYPEDBYREF)
- size = mono_class_native_size (inst->inst_vtype->data.klass, &align);
+ size = mono_class_native_size (mono_class_from_mono_type (inst->inst_vtype), &align);
else
size = mini_type_stack_size (cfg->generic_sharing_context, inst->inst_vtype, &align);
inst->dreg = sparc_i0 + ainfo->reg;
break;
case ArgInIRegPair:
- if (cfg->new_ir && (inst->type == STACK_I8)) {
+ if (inst->type == STACK_I8) {
MonoInst *low = get_vreg_to_inst (cfg, inst->dreg + 1);
MonoInst *high = get_vreg_to_inst (cfg, inst->dreg + 2);
high->dreg = sparc_i0 + ainfo->reg;
}
inst->opcode = OP_REGVAR;
- inst->dreg = sparc_i0 + ainfo->reg;
+ inst->dreg = sparc_i0 + ainfo->reg;
break;
case ArgInFloatReg:
case ArgInDoubleReg:
}
}
- /* Add a properly aligned dword for use by int<->float conversion opcodes */
- offset += 8;
- offset = ALIGN_TO (offset, 8);
- cfg->arch.float_spill_slot_offset = offset;
-
/*
* spillvars are stored between the normal locals and the storage reserved
* by the ABI.
mono_print_ins (cfg->vret_addr);
}
}
-}
-
-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;
-}
-
-static void
-emit_sig_cookie (MonoCompile *cfg, MonoCallInst *call, CallInfo *cinfo)
-{
- MonoInst *arg;
- MonoMethodSignature *tmp_sig;
- MonoInst *sig_arg;
-
- /*
- * 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;
-}
-
-/*
- * take the arguments and generate the arch-specific
- * instructions to properly call the function in call.
- * This includes pushing, moving arguments to the right register
- * etc.
- */
-MonoCallInst*
-mono_arch_call_opcode (MonoCompile *cfg, MonoBasicBlock* bb, MonoCallInst *call, int is_virtual) {
- MonoInst *arg, *in;
- MonoMethodSignature *sig;
- int i, n;
- CallInfo *cinfo;
- ArgInfo *ainfo;
- guint32 extra_space = 0;
-
- sig = call->signature;
- n = sig->param_count + sig->hasthis;
-
- cinfo = get_call_info (cfg, sig, sig->pinvoke);
-
- 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 */
- emit_sig_cookie (cfg, call, cinfo);
- }
-
- if (is_virtual && i == 0) {
- /* the argument will be attached to the call instruction */
- in = call->args [i];
- } else {
- MONO_INST_NEW (cfg, arg, OP_OUTARG);
- in = call->args [i];
- arg->cil_code = in->cil_code;
- arg->inst_left = in;
- arg->type = in->type;
- /* prepend, we'll need to reverse them later */
- arg->next = call->out_args;
- call->out_args = arg;
-
- if ((i >= sig->hasthis) && (MONO_TYPE_ISSTRUCT(sig->params [i - sig->hasthis]))) {
- MonoInst *inst;
- gint align;
- guint32 offset, pad;
- guint32 size;
-
-#ifdef SPARCV9
- if (sig->pinvoke)
- NOT_IMPLEMENTED;
-#endif
-
- if (sig->params [i - sig->hasthis]->type == MONO_TYPE_TYPEDBYREF) {
- size = sizeof (MonoTypedRef);
- align = sizeof (gpointer);
- }
- else
- if (sig->pinvoke)
- size = mono_type_native_stack_size (&in->klass->byval_arg, &align);
- else {
- /*
- * Can't use mini_type_stack_size (), but that
- * aligns the size to sizeof (gpointer), which is larger
- * than the size of the source, leading to reads of invalid
- * memory if the source is at the end of address space or
- * misaligned reads.
- */
- size = mono_class_value_size (in->klass, &align);
- }
-
- /*
- * We use OP_OUTARG_VT to copy the valuetype to a stack location, then
- * use the normal OUTARG opcodes to pass the address of the location to
- * the callee.
- */
- MONO_INST_NEW (cfg, inst, OP_OUTARG_VT);
- inst->inst_left = in;
-
- /* The first 6 argument locations are reserved */
- if (cinfo->stack_usage < 6 * sizeof (gpointer))
- cinfo->stack_usage = 6 * sizeof (gpointer);
-
- offset = ALIGN_TO ((ARGS_OFFSET - STACK_BIAS) + cinfo->stack_usage, align);
- pad = offset - ((ARGS_OFFSET - STACK_BIAS) + cinfo->stack_usage);
-
- inst->inst_c1 = STACK_BIAS + offset;
- inst->backend.size = size;
- arg->inst_left = inst;
-
- cinfo->stack_usage += size;
- 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:
- case ArgInIRegPair:
- if (ainfo->storage == ArgInIRegPair)
- arg->opcode = OP_SPARC_OUTARG_REGPAIR;
- arg->backend.reg3 = sparc_o0 + ainfo->reg;
- call->used_iregs |= 1 << ainfo->reg;
-
- 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;
- case ArgOnStack:
- arg->opcode = OP_SPARC_OUTARG_MEM;
- break;
- case ArgOnStackPair:
- arg->opcode = OP_SPARC_OUTARG_MEMPAIR;
- break;
- case ArgInSplitRegStack:
- arg->opcode = OP_SPARC_OUTARG_SPLIT_REG_STACK;
- arg->backend.reg3 = sparc_o0 + ainfo->reg;
- call->used_iregs |= 1 << ainfo->reg;
- break;
- case ArgInFloatReg:
- arg->opcode = OP_SPARC_OUTARG_FLOAT_REG;
- arg->backend.reg3 = sparc_f0 + ainfo->reg;
- break;
- case ArgInDoubleReg:
- arg->opcode = OP_SPARC_OUTARG_DOUBLE_REG;
- arg->backend.reg3 = sparc_f0 + ainfo->reg;
- break;
- default:
- NOT_IMPLEMENTED;
- }
- }
- }
- /* Handle the case where there are no implicit arguments */
- if (!sig->pinvoke && (sig->call_convention == MONO_CALL_VARARG) && (n == sig->sentinelpos)) {
- emit_sig_cookie (cfg, call, cinfo);
- }
+ if (!sig->ret->byref && (sig->ret->type == MONO_TYPE_I8 || sig->ret->type == MONO_TYPE_U8)) {
+ MonoInst *low = get_vreg_to_inst (cfg, cfg->ret->dreg + 1);
+ MonoInst *high = get_vreg_to_inst (cfg, cfg->ret->dreg + 2);
- /*
- * Reverse the call->out_args list.
- */
- {
- MonoInst *prev = NULL, *list = call->out_args, *next;
- while (list) {
- next = list->next;
- list->next = prev;
- prev = list;
- list = next;
- }
- call->out_args = prev;
+ low->flags |= MONO_INST_VOLATILE;
+ high->flags |= MONO_INST_VOLATILE;
}
- 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;
- g_free (cinfo);
- return call;
+ /* Add a properly aligned dword for use by int<->float conversion opcodes */
+ cfg->arch.float_spill_slot = mono_compile_create_var (cfg, &mono_defaults.double_class->byval_arg, OP_ARG);
+ ((MonoInst*)cfg->arch.float_spill_slot)->flags |= MONO_INST_VOLATILE;
}
-/* FIXME: Remove these later */
-#define NEW_LOAD_MEMBASE(cfg,dest,op,dr,base,offset) do { \
- MONO_INST_NEW ((cfg), (dest), (op)); \
- (dest)->dreg = (dr); \
- (dest)->inst_basereg = (base); \
- (dest)->inst_offset = (offset); \
- (dest)->type = STACK_I4; \
- } while (0)
-
-#define EMIT_NEW_LOAD_MEMBASE(cfg,dest,op,dr,base,offset) do { NEW_LOAD_MEMBASE ((cfg), (dest), (op), (dr), (base), (offset)); MONO_ADD_INS ((cfg)->cbb, (dest)); } while (0)
-
-#undef MONO_EMIT_NEW_STORE_MEMBASE_IMM
-#define MONO_EMIT_NEW_STORE_MEMBASE_IMM(cfg,op,base,offset,imm) do { \
- MonoInst *inst; \
- MONO_INST_NEW ((cfg), (inst), (op)); \
- inst->inst_destbasereg = base; \
- inst->inst_offset = offset; \
- inst->inst_p1 = (gpointer)(gssize)imm; \
- MONO_ADD_INS ((cfg)->cbb, inst); \
- } while (0)
-
static void
-add_outarg_reg2 (MonoCompile *cfg, MonoCallInst *call, ArgStorage storage, int reg, guint32 sreg)
+add_outarg_reg (MonoCompile *cfg, MonoCallInst *call, ArgStorage storage, int reg, guint32 sreg)
{
MonoInst *arg;
static void
add_outarg_load (MonoCompile *cfg, MonoCallInst *call, int opcode, int basereg, int offset, int reg)
{
- MonoInst *arg;
int dreg = mono_alloc_ireg (cfg);
- EMIT_NEW_LOAD_MEMBASE (cfg, arg, OP_LOAD_MEMBASE, dreg, sparc_sp, offset);
- MONO_ADD_INS (cfg->cbb, arg);
+ MONO_EMIT_NEW_LOAD_MEMBASE (cfg, dreg, sparc_sp, offset);
mono_call_inst_add_outarg_reg (cfg, call, dreg, reg, FALSE);
}
switch (ainfo->storage) {
case ArgInIRegPair:
- add_outarg_reg2 (cfg, call, ArgInIReg, sparc_o0 + ainfo->reg + 1, in->dreg + 1);
- add_outarg_reg2 (cfg, call, ArgInIReg, sparc_o0 + ainfo->reg, in->dreg + 2);
+ add_outarg_reg (cfg, call, ArgInIReg, sparc_o0 + ainfo->reg + 1, in->dreg + 1);
+ add_outarg_reg (cfg, call, ArgInIReg, sparc_o0 + ainfo->reg, in->dreg + 2);
break;
case ArgOnStackPair:
MONO_EMIT_NEW_STORE_MEMBASE (cfg, OP_STOREI4_MEMBASE_REG, sparc_sp, offset, in->dreg + 2);
MONO_EMIT_NEW_STORE_MEMBASE (cfg, OP_STOREI4_MEMBASE_REG, sparc_sp, offset + 4, in->dreg + 1);
break;
case ArgInSplitRegStack:
- add_outarg_reg2 (cfg, call, ArgInIReg, sparc_o0 + ainfo->reg, in->dreg + 2);
+ add_outarg_reg (cfg, call, ArgInIReg, sparc_o0 + ainfo->reg, in->dreg + 2);
MONO_EMIT_NEW_STORE_MEMBASE (cfg, OP_STOREI4_MEMBASE_REG, sparc_sp, offset + 4, in->dreg + 1);
break;
default:
switch (ainfo->storage) {
case ArgInIReg:
- add_outarg_reg2 (cfg, call, ArgInIReg, sparc_o0 + ainfo->reg, in->dreg);
+ add_outarg_reg (cfg, call, ArgInIReg, sparc_o0 + ainfo->reg, in->dreg);
break;
case ArgOnStack:
#ifdef SPARCV9
}
static void
-emit_sig_cookie2 (MonoCompile *cfg, MonoCallInst *call, CallInfo *cinfo)
+emit_sig_cookie (MonoCompile *cfg, MonoCallInst *call, CallInfo *cinfo)
{
MonoMethodSignature *tmp_sig;
if ((sig->call_convention == MONO_CALL_VARARG) && (i == sig->sentinelpos)) {
/* Emit the signature cookie just before the first implicit argument */
- emit_sig_cookie2 (cfg, call, cinfo);
+ emit_sig_cookie (cfg, call, cinfo);
}
in = call->args [i];
else
arg_type = sig->params [i - sig->hasthis];
+ arg_type = mono_type_get_underlying_type (arg_type);
if ((i >= sig->hasthis) && (MONO_TYPE_ISSTRUCT(sig->params [i - sig->hasthis])))
emit_pass_vtype (cfg, call, cinfo, ainfo, arg_type, in, sig->pinvoke);
else if (!arg_type->byref && ((arg_type->type == MONO_TYPE_I8) || (arg_type->type == MONO_TYPE_U8)))
/* Handle the case where there are no implicit arguments */
if (!sig->pinvoke && (sig->call_convention == MONO_CALL_VARARG) && (n == sig->sentinelpos)) {
- emit_sig_cookie2 (cfg, call, cinfo);
+ emit_sig_cookie (cfg, call, cinfo);
}
call->stack_usage = cinfo->stack_usage + extra_space;
ArgInfo *ainfo = (ArgInfo*)ins->inst_p1;
int size = ins->backend.size;
- mini_emit_memcpy2 (cfg, sparc_sp, ainfo->offset, src->dreg, 0, size, 0);
+ mini_emit_memcpy (cfg, sparc_sp, ainfo->offset, src->dreg, 0, size, 0);
}
void
mono_arch_emit_setret (MonoCompile *cfg, MonoMethod *method, MonoInst *val)
{
CallInfo *cinfo = get_call_info (cfg, mono_method_signature (method), FALSE);
+ MonoType *ret = mini_type_get_underlying_type (cfg->generic_sharing_context, mono_method_signature (method)->ret);
switch (cinfo->ret.storage) {
case ArgInIReg:
MONO_EMIT_NEW_UNALU (cfg, OP_MOVE, cfg->ret->dreg, val->dreg);
break;
case ArgInIRegPair:
- MONO_EMIT_NEW_UNALU (cfg, OP_MOVE, cfg->ret->dreg, val->dreg + 2);
- MONO_EMIT_NEW_UNALU (cfg, OP_MOVE, cfg->ret->dreg + 1, val->dreg + 1);
+ if (ret->type == MONO_TYPE_I8 || ret->type == MONO_TYPE_U8) {
+ MONO_EMIT_NEW_UNALU (cfg, OP_LMOVE, cfg->ret->dreg, val->dreg);
+ } else {
+ MONO_EMIT_NEW_UNALU (cfg, OP_MOVE, cfg->ret->dreg + 2, val->dreg + 2);
+ MONO_EMIT_NEW_UNALU (cfg, OP_MOVE, cfg->ret->dreg + 1, val->dreg + 1);
+ }
break;
case ArgInFReg:
- if (mono_method_signature (method)->ret->type == MONO_TYPE_R4)
+ if (ret->type == MONO_TYPE_R4)
MONO_EMIT_NEW_UNALU (cfg, OP_SETFRET, cfg->ret->dreg, val->dreg);
else
MONO_EMIT_NEW_UNALU (cfg, OP_FMOVE, cfg->ret->dreg, val->dreg);
}
#define COMPUTE_DISP(ins) \
-if (ins->flags & MONO_INST_BRLABEL) { \
- if (ins->inst_i0->inst_c0) \
- disp = (ins->inst_i0->inst_c0 - ((guint8*)code - cfg->native_code)) >> 2; \
- else { \
- disp = 0; \
- mono_add_patch_info (cfg, (guint8*)code - cfg->native_code, MONO_PATCH_INFO_LABEL, ins->inst_i0); \
- } \
-} else { \
- if (ins->inst_true_bb->native_offset) \
- disp = (ins->inst_true_bb->native_offset - ((guint8*)code - cfg->native_code)) >> 2; \
- else { \
- disp = 0; \
- mono_add_patch_info (cfg, (guint8*)code - cfg->native_code, MONO_PATCH_INFO_BB, ins->inst_true_bb); \
- } \
+if (ins->inst_true_bb->native_offset) \
+ disp = (ins->inst_true_bb->native_offset - ((guint8*)code - cfg->native_code)) >> 2; \
+else { \
+ disp = 0; \
+ mono_add_patch_info (cfg, (guint8*)code - cfg->native_code, MONO_PATCH_INFO_BB, ins->inst_true_bb); \
}
#ifdef SPARCV9
* Only do this if the method is small since BPr only has a 16bit
* displacement.
*/
- if (v64 && (mono_method_get_header (cfg->method)->code_size < 10000) && last_ins &&
+ if (v64 && (cfg->header->code_size < 10000) && last_ins &&
(last_ins->opcode == OP_COMPARE_IMM) &&
(last_ins->inst_imm == 0)) {
switch (ins->opcode) {
bb->last_ins = last_ins;
}
+void
+mono_arch_decompose_long_opts (MonoCompile *cfg, MonoInst *ins)
+{
+ switch (ins->opcode) {
+ case OP_LNEG:
+ MONO_EMIT_NEW_BIALU (cfg, OP_SUBCC, ins->dreg + 1, 0, ins->sreg1 + 1);
+ MONO_EMIT_NEW_BIALU (cfg, OP_SBB, ins->dreg + 2, 0, ins->sreg1 + 2);
+ NULLIFY_INS (ins);
+ break;
+ default:
+ break;
+ }
+}
+
void
mono_arch_lowering_pass (MonoCompile *cfg, MonoBasicBlock *bb)
{
return FALSE;
}
-/*
- * mono_arch_get_vcall_slot:
- *
- * Determine the vtable slot used by a virtual call.
- */
-gpointer
-mono_arch_get_vcall_slot (guint8 *code8, gpointer *regs, int *displacement)
-{
- guint32 *code = (guint32*)(gpointer)code8;
- guint32 ins = code [0];
- guint32 prev_ins = code [-1];
-
- mono_sparc_flushw ();
-
- *displacement = 0;
-
- 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_i (prev_ins) == 1) && (sparc_inst_op3 (prev_ins) == 0 || sparc_inst_op3 (prev_ins) == 0xb)) {
- /* ld [r1 + CONST ], r2; call r2 */
- guint32 base = sparc_inst_rs1 (prev_ins);
- gint32 disp = (((gint32)(sparc_inst_imm13 (prev_ins))) << 19) >> 19;
- gpointer base_val;
-
- g_assert (sparc_inst_rd (prev_ins) == sparc_inst_rs1 (ins));
-
- g_assert ((base >= sparc_o0) && (base <= sparc_i7));
-
- base_val = regs [base];
-
- *displacement = disp;
-
- return (gpointer)base_val;
- }
- else if ((sparc_inst_op (prev_ins) == 0x3) && (sparc_inst_i (prev_ins) == 0) && (sparc_inst_op3 (prev_ins) == 0)) {
- /* set r1, ICONST; ld [r1 + r2], r2; call r2 */
- /* Decode a sparc_set32 */
- guint32 base = sparc_inst_rs1 (prev_ins);
- guint32 disp;
- gpointer base_val;
- guint32 s1 = code [-3];
- guint32 s2 = code [-2];
-
-#ifdef SPARCV9
- NOT_IMPLEMENTED;
-#endif
-
- /* sparc_sethi */
- g_assert (sparc_inst_op (s1) == 0);
- g_assert (sparc_inst_op2 (s1) == 4);
-
- /* sparc_or_imm */
- g_assert (sparc_inst_op (s2) == 2);
- g_assert (sparc_inst_op3 (s2) == 2);
- g_assert (sparc_inst_i (s2) == 1);
- g_assert (sparc_inst_rs1 (s2) == sparc_inst_rd (s2));
- g_assert (sparc_inst_rd (s1) == sparc_inst_rs1 (s2));
-
- disp = ((s1 & 0x3fffff) << 10) | sparc_inst_imm13 (s2);
-
- g_assert ((base >= sparc_o0) && (base <= sparc_i7));
-
- base_val = regs [base];
-
- *displacement = disp;
-
- return (gpointer)base_val;
- } else
- g_assert_not_reached ();
- }
- else
- g_assert_not_reached ();
-
- return NULL;
-}
-
-gpointer*
-mono_arch_get_vcall_slot_addr (guint8 *code, gpointer *regs)
-{
- gpointer vt;
- int displacement;
- vt = mono_arch_get_vcall_slot (code, regs, &displacement);
- if (!vt)
- return NULL;
- return (gpointer*)((char*)vt + displacement);
-}
-
#define CMP_SIZE 3
#define BR_SMALL_SIZE 2
#define BR_LARGE_SIZE 2
* LOCKING: called with the domain lock held
*/
gpointer
-mono_arch_build_imt_thunk (MonoVTable *vtable, MonoDomain *domain, MonoIMTCheckItem **imt_entries, int count)
+mono_arch_build_imt_thunk (MonoVTable *vtable, MonoDomain *domain, MonoIMTCheckItem **imt_entries, int count,
+ gpointer fail_tramp)
{
int i;
int size = 0;
item->chunk_size += CMP_SIZE;
item->chunk_size += BR_SMALL_SIZE + JUMP_IMM_SIZE;
} else {
+ if (fail_tramp)
+ item->chunk_size += 16;
item->chunk_size += JUMP_IMM_SIZE;
#if ENABLE_WRONG_METHOD_CHECK
item->chunk_size += CMP_SIZE + BR_SMALL_SIZE + 1;
}
size += item->chunk_size;
}
- code = mono_code_manager_reserve (domain->code_mp, size * 4);
+ if (fail_tramp)
+ code = mono_method_alloc_generic_virtual_thunk (domain, size * 4);
+ else
+ code = mono_domain_code_reserve (domain, size * 4);
start = code;
-
for (i = 0; i < count; ++i) {
MonoIMTCheckItem *item = imt_entries [i];
item->code_target = (guint8*)code;
if (item->is_equals) {
- if (item->check_target_idx) {
- if (!item->compare_done) {
- sparc_set (code, (guint32)item->method, sparc_g5);
+ gboolean fail_case = !item->check_target_idx && fail_tramp;
+
+ if (item->check_target_idx || fail_case) {
+ if (!item->compare_done || fail_case) {
+ sparc_set (code, (guint32)item->key, sparc_g5);
sparc_cmp (code, MONO_ARCH_IMT_REG, sparc_g5);
}
item->jmp_code = (guint8*)code;
sparc_branch (code, 0, sparc_bne, 0);
sparc_nop (code);
- sparc_set (code, ((guint32)(&(vtable->vtable [item->vtable_slot]))), sparc_g5);
- sparc_ld (code, sparc_g5, 0, sparc_g5);
+ if (item->has_target_code) {
+ sparc_set (code, item->value.target_code, sparc_f5);
+ } else {
+ sparc_set (code, ((guint32)(&(vtable->vtable [item->value.vtable_slot]))), sparc_g5);
+ sparc_ld (code, sparc_g5, 0, sparc_g5);
+ }
sparc_jmpl (code, sparc_g5, sparc_g0, sparc_g0);
sparc_nop (code);
+
+ if (fail_case) {
+ sparc_patch (item->jmp_code, code);
+ sparc_set (code, fail_tramp, sparc_g5);
+ sparc_jmpl (code, sparc_g5, sparc_g0, sparc_g0);
+ sparc_nop (code);
+ item->jmp_code = NULL;
+ }
} else {
/* enable the commented code to assert on wrong method */
#if ENABLE_WRONG_METHOD_CHECK
g_assert_not_reached ();
#endif
- sparc_set (code, ((guint32)(&(vtable->vtable [item->vtable_slot]))), sparc_g5);
+ sparc_set (code, ((guint32)(&(vtable->vtable [item->value.vtable_slot]))), sparc_g5);
sparc_ld (code, sparc_g5, 0, sparc_g5);
sparc_jmpl (code, sparc_g5, sparc_g0, sparc_g0);
sparc_nop (code);
#endif
}
} else {
- sparc_set (code, (guint32)item->method, sparc_g5);
+ sparc_set (code, (guint32)item->key, sparc_g5);
sparc_cmp (code, MONO_ARCH_IMT_REG, sparc_g5);
item->jmp_code = (guint8*)code;
sparc_branch (code, 0, sparc_beu, 0);
}
MonoMethod*
-mono_arch_find_imt_method (gpointer *regs, guint8 *code)
+mono_arch_find_imt_method (mgreg_t *regs, guint8 *code)
{
#ifdef SPARCV9
g_assert_not_reached ();
return (MonoMethod*)regs [sparc_g1];
}
-MonoObject*
-mono_arch_find_this_argument (gpointer *regs, MonoMethod *method, MonoGenericSharingContext *gsctx)
+gpointer
+mono_arch_get_this_arg_from_call (mgreg_t *regs, guint8 *code)
{
mono_sparc_flushw ();
}
sparc_sub (code, FALSE, ins->sreg1, sparc_o7, ins->dreg);
break;
+ case OP_IREM_UN_IMM:
+ sparc_set (code, ins->inst_imm, GP_SCRATCH_REG);
+ sparc_wry (code, sparc_g0, sparc_g0);
+ sparc_udiv (code, FALSE, ins->sreg1, GP_SCRATCH_REG, sparc_o7);
+ sparc_umul (code, FALSE, GP_SCRATCH_REG, sparc_o7, sparc_o7);
+ sparc_sub (code, FALSE, ins->sreg1, sparc_o7, ins->dreg);
+ break;
case OP_IOR:
sparc_or (code, FALSE, ins->sreg1, ins->sreg2, ins->dreg);
break;
sparc_fmovs (code, ins->sreg1 + 1, ins->dreg + 1);
#endif
break;
- case OP_SPARC_SETFREG_FLOAT:
- /* Only used on V9 */
- sparc_fdtos (code, ins->sreg1, ins->dreg);
- break;
case OP_JMP:
if (cfg->method->save_lmf)
NOT_IMPLEMENTED;
#endif
}
break;
- case OP_OUTARG:
- g_assert_not_reached ();
- break;
case OP_LOCALLOC: {
guint32 size_reg;
gint32 offset2;
/* This is a jump inside the method, so call_simple works even on V9 */
sparc_call_simple (code, 0);
sparc_nop (code);
+ mono_cfg_add_try_hole (cfg, ins->inst_eh_block, code, bb);
break;
case OP_LABEL:
ins->inst_c0 = (guint8*)code - cfg->native_code;
break;
+ case OP_RELAXED_NOP:
case OP_NOP:
case OP_DUMMY_USE:
case OP_DUMMY_STORE:
//g_print ("target: %p, next: %p, curr: %p, last: %p\n", ins->inst_target_bb, bb->next_bb, ins, bb->last_ins);
if ((ins->inst_target_bb == bb->next_bb) && ins == bb->last_ins)
break;
- if (ins->flags & MONO_INST_BRLABEL) {
- if (ins->inst_i0->inst_c0) {
- gint32 disp = (ins->inst_i0->inst_c0 - ((guint8*)code - cfg->native_code)) >> 2;
- g_assert (sparc_is_imm22 (disp));
- sparc_branch (code, 1, sparc_ba, disp);
- } else {
- mono_add_patch_info (cfg, offset, MONO_PATCH_INFO_LABEL, ins->inst_i0);
- sparc_branch (code, 1, sparc_ba, 0);
- }
+ if (ins->inst_target_bb->native_offset) {
+ gint32 disp = (ins->inst_target_bb->native_offset - ((guint8*)code - cfg->native_code)) >> 2;
+ g_assert (sparc_is_imm22 (disp));
+ sparc_branch (code, 1, sparc_ba, disp);
} else {
- if (ins->inst_target_bb->native_offset) {
- gint32 disp = (ins->inst_target_bb->native_offset - ((guint8*)code - cfg->native_code)) >> 2;
- g_assert (sparc_is_imm22 (disp));
- sparc_branch (code, 1, sparc_ba, disp);
- } else {
- mono_add_patch_info (cfg, offset, MONO_PATCH_INFO_BB, ins->inst_target_bb);
- sparc_branch (code, 1, sparc_ba, 0);
- }
+ mono_add_patch_info (cfg, offset, MONO_PATCH_INFO_BB, ins->inst_target_bb);
+ sparc_branch (code, 1, sparc_ba, 0);
}
sparc_nop (code);
break;
break;
}
case OP_ICONV_TO_R4: {
- gint32 offset = cfg->arch.float_spill_slot_offset;
+ MonoInst *spill = cfg->arch.float_spill_slot;
+ gint32 reg = spill->inst_basereg;
+ gint32 offset = spill->inst_offset;
+
+ g_assert (spill->opcode == OP_REGOFFSET);
#ifdef SPARCV9
if (!sparc_is_imm13 (offset)) {
sparc_set (code, offset, sparc_o7);
- sparc_stx (code, ins->sreg1, sparc_sp, offset);
- sparc_lddf (code, sparc_sp, offset, FP_SCRATCH_REG);
+ sparc_stx (code, ins->sreg1, reg, offset);
+ sparc_lddf (code, reg, offset, FP_SCRATCH_REG);
} else {
- sparc_stx_imm (code, ins->sreg1, sparc_sp, offset);
- sparc_lddf_imm (code, sparc_sp, offset, FP_SCRATCH_REG);
+ sparc_stx_imm (code, ins->sreg1, reg, offset);
+ sparc_lddf_imm (code, reg, offset, FP_SCRATCH_REG);
}
sparc_fxtos (code, FP_SCRATCH_REG, FP_SCRATCH_REG);
#else
if (!sparc_is_imm13 (offset)) {
sparc_set (code, offset, sparc_o7);
- sparc_st (code, ins->sreg1, sparc_sp, sparc_o7);
- sparc_ldf (code, sparc_sp, sparc_o7, FP_SCRATCH_REG);
+ sparc_st (code, ins->sreg1, reg, sparc_o7);
+ sparc_ldf (code, reg, sparc_o7, FP_SCRATCH_REG);
} else {
- sparc_st_imm (code, ins->sreg1, sparc_sp, offset);
- sparc_ldf_imm (code, sparc_sp, offset, FP_SCRATCH_REG);
+ sparc_st_imm (code, ins->sreg1, reg, offset);
+ sparc_ldf_imm (code, reg, offset, FP_SCRATCH_REG);
}
sparc_fitos (code, FP_SCRATCH_REG, FP_SCRATCH_REG);
#endif
break;
}
case OP_ICONV_TO_R8: {
- gint32 offset = cfg->arch.float_spill_slot_offset;
+ MonoInst *spill = cfg->arch.float_spill_slot;
+ gint32 reg = spill->inst_basereg;
+ gint32 offset = spill->inst_offset;
+
+ g_assert (spill->opcode == OP_REGOFFSET);
+
#ifdef SPARCV9
if (!sparc_is_imm13 (offset)) {
sparc_set (code, offset, sparc_o7);
- sparc_stx (code, ins->sreg1, sparc_sp, sparc_o7);
- sparc_lddf (code, sparc_sp, sparc_o7, FP_SCRATCH_REG);
+ sparc_stx (code, ins->sreg1, reg, sparc_o7);
+ sparc_lddf (code, reg, sparc_o7, FP_SCRATCH_REG);
} else {
- sparc_stx_imm (code, ins->sreg1, sparc_sp, offset);
- sparc_lddf_imm (code, sparc_sp, offset, FP_SCRATCH_REG);
+ sparc_stx_imm (code, ins->sreg1, reg, offset);
+ sparc_lddf_imm (code, reg, offset, FP_SCRATCH_REG);
}
sparc_fxtod (code, FP_SCRATCH_REG, ins->dreg);
#else
if (!sparc_is_imm13 (offset)) {
sparc_set (code, offset, sparc_o7);
- sparc_st (code, ins->sreg1, sparc_sp, sparc_o7);
- sparc_ldf (code, sparc_sp, sparc_o7, FP_SCRATCH_REG);
+ sparc_st (code, ins->sreg1, reg, sparc_o7);
+ sparc_ldf (code, reg, sparc_o7, FP_SCRATCH_REG);
} else {
- sparc_st_imm (code, ins->sreg1, sparc_sp, offset);
- sparc_ldf_imm (code, sparc_sp, offset, FP_SCRATCH_REG);
+ sparc_st_imm (code, ins->sreg1, reg, offset);
+ sparc_ldf_imm (code, reg, offset, FP_SCRATCH_REG);
}
sparc_fitod (code, FP_SCRATCH_REG, ins->dreg);
#endif
#endif
case OP_FCONV_TO_I4:
case OP_FCONV_TO_U4: {
- gint32 offset = cfg->arch.float_spill_slot_offset;
+ MonoInst *spill = cfg->arch.float_spill_slot;
+ gint32 reg = spill->inst_basereg;
+ gint32 offset = spill->inst_offset;
+
+ g_assert (spill->opcode == OP_REGOFFSET);
+
sparc_fdtoi (code, ins->sreg1, FP_SCRATCH_REG);
if (!sparc_is_imm13 (offset)) {
sparc_set (code, offset, sparc_o7);
- sparc_stdf (code, FP_SCRATCH_REG, sparc_sp, sparc_o7);
- sparc_ld (code, sparc_sp, sparc_o7, ins->dreg);
+ sparc_stdf (code, FP_SCRATCH_REG, reg, sparc_o7);
+ sparc_ld (code, reg, sparc_o7, ins->dreg);
} else {
- sparc_stdf_imm (code, FP_SCRATCH_REG, sparc_sp, offset);
- sparc_ld_imm (code, sparc_sp, offset, ins->dreg);
+ sparc_stdf_imm (code, FP_SCRATCH_REG, reg, offset);
+ sparc_ld_imm (code, reg, offset, ins->dreg);
}
switch (ins->opcode) {
EMIT_FLOAT_COND_BRANCH (ins, sparc_fbu, 1, 1);
break;
case OP_CKFINITE: {
- gint32 offset = cfg->arch.float_spill_slot_offset;
+ MonoInst *spill = cfg->arch.float_spill_slot;
+ gint32 reg = spill->inst_basereg;
+ gint32 offset = spill->inst_offset;
+
+ g_assert (spill->opcode == OP_REGOFFSET);
+
if (!sparc_is_imm13 (offset)) {
sparc_set (code, offset, sparc_o7);
- sparc_stdf (code, ins->sreg1, sparc_sp, sparc_o7);
- sparc_lduh (code, sparc_sp, sparc_o7, sparc_o7);
+ sparc_stdf (code, ins->sreg1, reg, sparc_o7);
+ sparc_lduh (code, reg, sparc_o7, sparc_o7);
} else {
- sparc_stdf_imm (code, ins->sreg1, sparc_sp, offset);
- sparc_lduh_imm (code, sparc_sp, offset, sparc_o7);
+ sparc_stdf_imm (code, ins->sreg1, reg, offset);
+ sparc_lduh_imm (code, reg, offset, sparc_o7);
}
sparc_srl_imm (code, sparc_o7, 4, sparc_o7);
sparc_and_imm (code, FALSE, sparc_o7, 2047, sparc_o7);
}
void
-mono_arch_patch_code (MonoMethod *method, MonoDomain *domain, guint8 *code, MonoJumpInfo *ji, gboolean run_cctors)
+mono_arch_patch_code (MonoMethod *method, MonoDomain *domain, guint8 *code, MonoJumpInfo *ji, MonoCodeManager *dyn_code_mp, gboolean run_cctors)
{
MonoJumpInfo *patch_info;
};
void*
-mono_arch_instrument_epilog (MonoCompile *cfg, void *func, void *p, gboolean enable_arguments)
+mono_arch_instrument_epilog_full (MonoCompile *cfg, void *func, void *p, gboolean enable_arguments, gboolean preserve_argument_registers)
{
guint32 *code = (guint32*)p;
int save_mode = SAVE_NONE;
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++;
+ cfg->stat_code_reallocs++;
}
code = (guint32*)(cfg->native_code + cfg->code_len);
if (cfg->bb_exit->in_count == 1 && cfg->bb_exit->in_bb[0]->native_offset != cfg->bb_exit->native_offset)
can_fold = 1;
- if (cfg->new_ir) {
- /*
- * FIXME: The last instruction might have a branch pointing into it like in
- * int_ceq sparc_i0 <-
- */
- can_fold = 0;
- }
+ /*
+ * FIXME: The last instruction might have a branch pointing into it like in
+ * int_ceq sparc_i0 <-
+ */
+ can_fold = 0;
/* Try folding last instruction into the restore */
if (can_fold && (sparc_inst_op (code [-2]) == 0x2) && (sparc_inst_op3 (code [-2]) == 0x2) && sparc_inst_imm (code [-2]) && (sparc_inst_rd (code [-2]) == sparc_i0)) {
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++;
+ cfg->stat_code_reallocs++;
}
code = (guint32*)(cfg->native_code + cfg->code_len);
#endif
void
-mono_arch_setup_jit_tls_data (MonoJitTlsData *tls)
+mono_arch_finish_init (void)
{
if (!lmf_addr_key_inited) {
int res;
{
}
-void
-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;
-
- if (vt_reg != -1) {
-#ifdef SPARCV9
- MonoInst *ins;
- MONO_INST_NEW (cfg, ins, OP_MOVE);
- ins->sreg1 = vt_reg;
- ins->dreg = mono_regstate_next_int (cfg->rs);
- mono_bblock_add_inst (cfg->cbb, ins);
-
- mono_call_inst_add_outarg_reg (cfg, call, ins->dreg, sparc_o0, FALSE);
-
- this_out_reg = sparc_o1;
-#else
- /* Set the 'struct/union return pointer' location on the stack */
- MONO_EMIT_NEW_STORE_MEMBASE (cfg, OP_STOREI4_MEMBASE_REG, sparc_sp, 64, vt_reg);
-#endif
- }
-
- /* add the this argument */
- if (this_reg != -1) {
- MonoInst *this;
- MONO_INST_NEW (cfg, this, OP_MOVE);
- this->type = this_type;
- this->sreg1 = this_reg;
- this->dreg = mono_regstate_next_int (cfg->rs);
- mono_bblock_add_inst (cfg->cbb, this);
-
- mono_call_inst_add_outarg_reg (cfg, call, this->dreg, this_out_reg, FALSE);
- }
-}
-
-
-MonoInst*
-mono_arch_get_inst_for_method (MonoCompile *cfg, MonoMethod *cmethod, MonoMethodSignature *fsig, MonoInst **args)
-{
- MonoInst *ins = NULL;
-
- return ins;
-}
-
MonoInst*
mono_arch_emit_inst_for_method (MonoCompile *cfg, MonoMethod *cmethod, MonoMethodSignature *fsig, MonoInst **args)
{
* Returns the size of the activation frame.
*/
int
-mono_arch_get_argument_info (MonoMethodSignature *csig, int param_count, MonoJitArgumentInfo *arg_info)
+mono_arch_get_argument_info (MonoGenericSharingContext *gsctx, MonoMethodSignature *csig, int param_count, MonoJitArgumentInfo *arg_info)
{
int k, align;
CallInfo *cinfo;
return NULL;
}
-MonoInst* mono_arch_get_thread_intrinsic (MonoCompile* cfg)
-{
- return NULL;
-}
-
-gpointer
+mgreg_t
mono_arch_context_get_int_reg (MonoContext *ctx, int reg)
{
/* FIXME: implement */