X-Git-Url: http://wien.tomnetworks.com/gitweb/?a=blobdiff_plain;f=mono%2Fmini%2Fmini-s390.c;h=a001ef7decfe11b13f7695a69cb72bab7b8cbe7d;hb=9342e7d1d4e5d0d3248de33d05b2c2b993314bd6;hp=6fdf1874f95237df1f8b1853f66084b09b6255c3;hpb=bd35146902473493b1fc9a51fa9cf9c8ad63a574;p=mono.git diff --git a/mono/mini/mini-s390.c b/mono/mini/mini-s390.c index 6fdf1874f95..a001ef7decf 100644 --- a/mono/mini/mini-s390.c +++ b/mono/mini/mini-s390.c @@ -20,70 +20,38 @@ #define EMIT_COND_BRANCH(ins,cond) \ { \ -if (ins->flags & MONO_INST_BRLABEL) { \ - if (ins->inst_i0->inst_c0) { \ - int displace; \ - displace = ((cfg->native_code + ins->inst_i0->inst_c0) - code) / 2; \ - if (s390_is_imm16(displace)) { \ - s390_brc (code, cond, displace); \ - } else { \ - s390_jcl (code, cond, displace); \ - } \ - } else { \ - mono_add_patch_info (cfg, code - cfg->native_code, \ - MONO_PATCH_INFO_LABEL, ins->inst_i0); \ - s390_jcl (code, cond, 0); \ - } \ -} else { \ - if (ins->inst_true_bb->native_offset) { \ - int displace; \ - displace = ((cfg->native_code + \ - ins->inst_true_bb->native_offset) - code) / 2; \ - if (s390_is_imm16(displace)) { \ - s390_brc (code, cond, displace); \ - } else { \ - s390_jcl (code, cond, displace); \ - } \ - } else { \ - mono_add_patch_info (cfg, code - cfg->native_code, \ - MONO_PATCH_INFO_BB, ins->inst_true_bb); \ - s390_jcl (code, cond, 0); \ - } \ -} \ +if (ins->inst_true_bb->native_offset) { \ + int displace; \ + displace = ((cfg->native_code + \ + ins->inst_true_bb->native_offset) - code) / 2; \ + if (s390_is_imm16(displace)) { \ + s390_brc (code, cond, displace); \ + } else { \ + s390_jcl (code, cond, displace); \ + } \ +} else { \ + mono_add_patch_info (cfg, code - cfg->native_code, \ + MONO_PATCH_INFO_BB, ins->inst_true_bb); \ + s390_jcl (code, cond, 0); \ +} \ } #define EMIT_UNCOND_BRANCH(ins) \ { \ -if (ins->flags & MONO_INST_BRLABEL) { \ - if (ins->inst_i0->inst_c0) { \ - int displace; \ - displace = ((cfg->native_code + ins->inst_i0->inst_c0) - code) / 2; \ - if (s390_is_imm16(displace)) { \ - s390_brc (code, S390_CC_UN, displace); \ - } else { \ - s390_jcl (code, S390_CC_UN, displace); \ - } \ - } else { \ - mono_add_patch_info (cfg, code - cfg->native_code, \ - MONO_PATCH_INFO_LABEL, ins->inst_i0); \ - s390_jcl (code, S390_CC_UN, 0); \ - } \ -} else { \ - if (ins->inst_target_bb->native_offset) { \ - int displace; \ - displace = ((cfg->native_code + \ - ins->inst_target_bb->native_offset) - code) / 2; \ - if (s390_is_imm16(displace)) { \ - s390_brc (code, S390_CC_UN, displace); \ - } else { \ - s390_jcl (code, S390_CC_UN, displace); \ - } \ - } else { \ - mono_add_patch_info (cfg, code - cfg->native_code, \ - MONO_PATCH_INFO_BB, ins->inst_target_bb); \ - s390_jcl (code, S390_CC_UN, 0); \ - } \ -} \ +if (ins->inst_target_bb->native_offset) { \ + int displace; \ + displace = ((cfg->native_code + \ + ins->inst_target_bb->native_offset) - code) / 2; \ + if (s390_is_imm16(displace)) { \ + s390_brc (code, S390_CC_UN, displace); \ + } else { \ + s390_jcl (code, S390_CC_UN, displace); \ + } \ +} else { \ + mono_add_patch_info (cfg, code - cfg->native_code, \ + MONO_PATCH_INFO_BB, ins->inst_target_bb); \ + s390_jcl (code, S390_CC_UN, 0); \ +} \ } #define EMIT_COND_SYSTEM_EXCEPTION(cond,exc_name) \ @@ -135,6 +103,107 @@ if (ins->flags & MONO_INST_BRLABEL) { \ s390_ldr (code, ins->dreg, ins->sreg1); \ } +#define MONO_EMIT_NEW_MOVE(cfg,dest,offset,src,imm,size) do { \ + MonoInst *inst; \ + int tmpr = 0; \ + int sReg, dReg; \ + MONO_INST_NEW (cfg, inst, OP_NOP); \ + if (size > 256) { \ + inst->dreg = dest; \ + inst->inst_offset = offset; \ + inst->sreg1 = src; \ + inst->inst_imm = imm; \ + } else { \ + if (s390_is_uimm12(offset)) { \ + inst->dreg = dest; \ + inst->inst_offset = offset; \ + } else { \ + dReg = mono_alloc_preg (cfg); \ + MONO_EMIT_NEW_BIALU_IMM(cfg, OP_ADD_IMM, \ + dReg, dest, offset); \ + inst->dreg = dReg; \ + inst->inst_offset = 0; \ + } \ + if (s390_is_uimm12(imm)) { \ + inst->sreg1 = src; \ + inst->inst_imm = imm; \ + } else { \ + sReg = mono_alloc_preg (cfg); \ + MONO_EMIT_NEW_BIALU_IMM(cfg, OP_ADD_IMM, \ + sReg, src, imm); \ + inst->sreg1 = sReg; \ + inst->inst_imm = 0; \ + } \ + } \ + inst->opcode = OP_S390_MOVE; \ + inst->backend.size = size; \ + MONO_ADD_INS (cfg->cbb, inst); \ + } while (0) + +#define MONO_OUTPUT_VTR(cfg, size, dr, sr, so) do { \ + int reg = mono_alloc_preg (cfg); \ + switch (size) { \ + case 0: \ + MONO_EMIT_NEW_ICONST(cfg, reg, 0); \ + mono_call_inst_add_outarg_reg(cfg, call, reg, dr, FALSE); \ + break; \ + case 1: \ + MONO_EMIT_NEW_LOAD_MEMBASE_OP(cfg, OP_LOADU1_MEMBASE, \ + reg, sr, so); \ + mono_call_inst_add_outarg_reg(cfg, call, reg, dr, FALSE); \ + break; \ + case 2: \ + MONO_EMIT_NEW_LOAD_MEMBASE_OP(cfg, OP_LOADU2_MEMBASE, \ + reg, sr, so); \ + mono_call_inst_add_outarg_reg(cfg, call, reg, dr, FALSE); \ + break; \ + case 4: \ + MONO_EMIT_NEW_LOAD_MEMBASE_OP(cfg, OP_LOAD_MEMBASE, \ + reg, sr, so); \ + mono_call_inst_add_outarg_reg(cfg, call, reg, dr, FALSE); \ + break; \ + case 8: \ + MONO_EMIT_NEW_LOAD_MEMBASE_OP(cfg, OP_LOAD_MEMBASE, \ + reg, sr, so); \ + mono_call_inst_add_outarg_reg(cfg, call, reg, dr, FALSE); \ + reg = mono_alloc_preg (cfg); \ + MONO_EMIT_NEW_LOAD_MEMBASE_OP(cfg, OP_LOAD_MEMBASE, \ + reg, sr, so + sizeof (guint32)); \ + mono_call_inst_add_outarg_reg(cfg, call, reg, dr + 1, FALSE); \ + break; \ + } \ +} while (0) + +#define MONO_OUTPUT_VTS(cfg, size, dr, dx, sr, so) do { \ + int tmpr; \ + switch (size) { \ + case 0: \ + tmpr = mono_alloc_preg (cfg); \ + MONO_EMIT_NEW_ICONST(cfg, tmpr, 0); \ + MONO_EMIT_NEW_STORE_MEMBASE(cfg, OP_STORE_MEMBASE_REG, \ + dr, dx, tmpr); \ + break; \ + case 1: \ + tmpr = mono_alloc_preg (cfg); \ + MONO_EMIT_NEW_LOAD_MEMBASE_OP(cfg, OP_LOADU1_MEMBASE, \ + tmpr, sr, so); \ + MONO_EMIT_NEW_STORE_MEMBASE(cfg, OP_STORE_MEMBASE_REG, \ + dr, dx, tmpr); \ + break; \ + case 2: \ + tmpr = mono_alloc_preg (cfg); \ + MONO_EMIT_NEW_LOAD_MEMBASE_OP(cfg, OP_LOADU2_MEMBASE, \ + tmpr, sr, so); \ + MONO_EMIT_NEW_STORE_MEMBASE(cfg, OP_STORE_MEMBASE_REG, \ + dr, dx, tmpr); \ + break; \ + case 4: \ + case 8: \ + MONO_EMIT_NEW_MOVE (cfg, dr, dx, sr, so, size); \ + break; \ + } \ +} while (0) + #undef DEBUG #define DEBUG(a) if (cfg->verbose_level > 1) a @@ -159,9 +228,9 @@ if (ins->flags & MONO_INST_BRLABEL) { \ #include #include "mini-s390.h" -#include "inssel.h" #include "cpu-s390.h" #include "jit-icalls.h" +#include "ir-emit.h" /*========================= End of Includes ========================*/ @@ -200,20 +269,22 @@ struct InstList { MonoInst *data; }; -enum { +typedef enum { RegTypeGeneral, RegTypeBase, RegTypeFP, + RegTypeFPR4, RegTypeStructByVal, + RegTypeStructByValInFP, RegTypeStructByAddr -}; +} ArgStorage; typedef struct { gint32 offset; /* offset from caller's stack */ gint32 offparm; /* offset from callee's stack */ guint16 vtsize; /* in param area */ guint8 reg; - guint8 regtype; /* See RegType* */ + ArgStorage regtype; /* See RegType* */ guint32 size; /* Size of structure used by RegTypeStructByVal */ } ArgInfo; @@ -224,6 +295,7 @@ typedef struct { guint32 struct_ret; ArgInfo ret; ArgInfo sigCookie; + size_data sz; ArgInfo args [1]; } CallInfo; @@ -247,12 +319,11 @@ static gboolean is_regsize_var (MonoType *); static inline void add_general (guint *, size_data *, ArgInfo *, gboolean); static inline void add_stackParm (guint *, size_data *, ArgInfo *, gint); static inline void add_float (guint *, size_data *, ArgInfo *); -static CallInfo * calculate_sizes (MonoCompile *, MonoMethodSignature *, size_data *, gboolean); -static void peephole_pass (MonoCompile *, MonoBasicBlock *); +static CallInfo * get_call_info (MonoCompile *, MonoMemPool *, MonoMethodSignature *, gboolean); static guchar * emit_float_to_int (MonoCompile *, guchar *, int, int, int, gboolean); gpointer mono_arch_get_lmf_addr (void); static guint8 * emit_load_volatile_registers(guint8 *, MonoCompile *); -static void emit_sig_cookie (MonoCompile *, MonoCallInst *, CallInfo *, int); +static void emit_sig_cookie (MonoCompile *, MonoCallInst *, CallInfo *); /*========================= End of Prototypes ======================*/ @@ -267,7 +338,6 @@ static int indent_level = 0; static gboolean tls_offset_inited = FALSE; static int appdomain_tls_offset = -1, - lmf_tls_offset = -1, thread_tls_offset = -1; pthread_key_t lmf_addr_key; @@ -590,7 +660,7 @@ enum_parmtype: MonoMarshalType *info; if (type->data.klass->enumtype) { - simpleType = type->data.klass->enum_basetype->type; + simpleType = mono_class_enum_basetype (type->data.klass)->type; printf("{VALUETYPE} - "); goto enum_parmtype; } @@ -633,7 +703,8 @@ enum_parmtype: /*========================= End of Function ========================*/ -static int lc = 0; +//static int lc = 0; + /*------------------------------------------------------------------*/ /* */ /* Name - enter_method */ @@ -653,7 +724,6 @@ enter_method (MonoMethod *method, RegParm *rParm, char *sp) guint32 ip; CallInfo *cinfo; ArgInfo *ainfo; - size_data sz; void *curParm; fname = mono_method_full_name (method, TRUE); @@ -669,7 +739,7 @@ enter_method (MonoMethod *method, RegParm *rParm, char *sp) sig = mono_method_signature (method); - cinfo = calculate_sizes (NULL, sig, &sz, sig->pinvoke); + cinfo = get_call_info (NULL, NULL, sig, sig->pinvoke); if (cinfo->struct_ret) { printf ("[STRUCTRET:%p], ", (gpointer) rParm->gr[0]); @@ -895,7 +965,7 @@ handle_enum: case MONO_TYPE_VALUETYPE: { MonoMarshalType *info; if (type->data.klass->enumtype) { - type = type->data.klass->enum_basetype; + type = mono_class_enum_basetype (type->data.klass); goto handle_enum; } else { guint8 *p = va_arg (ap, gpointer); @@ -1057,7 +1127,7 @@ is_regsize_var (MonoType *t) { return FALSE; case MONO_TYPE_VALUETYPE: if (t->data.klass->enumtype) - return is_regsize_var (t->data.klass->enum_basetype); + return is_regsize_var (mono_class_enum_basetype (t->data.klass)); return FALSE; } return FALSE; @@ -1119,12 +1189,14 @@ mono_arch_get_global_int_regs (MonoCompile *cfg) MonoMethodHeader *header; int i, top = 13; - header = mono_method_get_header (cfg->method); + header = cfg->header; if ((cfg->flags & MONO_CFG_HAS_ALLOCA) || header->num_clauses) cfg->frame_reg = s390_r11; + /* FIXME: s390_r12 is reserved for bkchain_reg. Only reserve it if needed */ + top = 12; for (i = 8; i < top; ++i) { - if (cfg->frame_reg != i) + if (cfg->frame_reg != i) regs = g_list_prepend (regs, GUINT_TO_POINTER (i)); } @@ -1148,6 +1220,21 @@ mono_arch_flush_icache (guint8 *code, gint size) /*========================= End of Function ========================*/ +/*------------------------------------------------------------------*/ +/* */ +/* Name - mono_arch_is_inst_imm */ +/* */ +/*------------------------------------------------------------------*/ + +gboolean +mono_arch_is_inst_imm (gint64 imm) +{ + /* The lowering pass will take care of it */ + return TRUE; +} + +/*========================= End of Function ========================*/ + /*------------------------------------------------------------------*/ /* */ /* Name - add_general */ @@ -1213,14 +1300,16 @@ add_stackParm (guint *gr, size_data *sz, ArgInfo *ainfo, gint size) { if (*gr > S390_LAST_ARG_REG) { sz->stack_size = S390_ALIGN(sz->stack_size, sizeof(long)); - ainfo->reg = STK_BASE; + ainfo->reg = STK_BASE; + ainfo->offset = sz->stack_size; + sz->stack_size += sizeof (gpointer); sz->parm_size += sizeof(gpointer); sz->offStruct += sizeof(gpointer); } else { ainfo->reg = *gr; + ainfo->offset = sz->stack_size; } (*gr) ++; - ainfo->offset = sz->stack_size; ainfo->offparm = sz->offset; sz->offset = S390_ALIGN(sz->offset+size, sizeof(long)); ainfo->size = size; @@ -1264,7 +1353,7 @@ add_float (guint *fr, size_data *sz, ArgInfo *ainfo) /*------------------------------------------------------------------*/ /* */ -/* Name - calculate_sizes */ +/* Name - get_call_info */ /* */ /* Function - Determine the amount of space required for code */ /* and stack. In addition determine starting points */ @@ -1274,21 +1363,27 @@ add_float (guint *fr, size_data *sz, ArgInfo *ainfo) /*------------------------------------------------------------------*/ static CallInfo * -calculate_sizes (MonoCompile *cfg, MonoMethodSignature *sig, size_data *sz, - gboolean string_ctor) +get_call_info (MonoCompile *cfg, MonoMemPool *mp, MonoMethodSignature *sig, gboolean is_pinvoke) { guint i, fr, gr, size; int nParm = sig->hasthis + sig->param_count; MonoType *ret_type; guint32 simpletype, align; - CallInfo *cinfo = g_malloc0 (sizeof (CallInfo) + sizeof (ArgInfo) * nParm); + CallInfo *cinfo; + size_data *sz; MonoGenericSharingContext *gsctx = cfg ? cfg->generic_sharing_context : NULL; + if (mp) + cinfo = mono_mempool_alloc0 (mp, sizeof (CallInfo) + sizeof (ArgInfo) * nParm); + else + cinfo = g_malloc0 (sizeof (CallInfo) + sizeof (ArgInfo) * nParm); + fr = 0; gr = s390_r2; - nParm = 0; + nParm = 0; cinfo->struct_ret = 0; - sz->offset = 0; + sz = &cinfo->sz; + sz->offset = 0; sz->offStruct = S390_MINIMAL_STACK_SIZE; sz->retStruct = 0; sz->stack_size = S390_MINIMAL_STACK_SIZE; @@ -1338,7 +1433,7 @@ enum_retvalue: sz->code_size += 4; 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.reg = s390_r2; sz->code_size += 4; break; @@ -1347,7 +1442,7 @@ enum_retvalue: case MONO_TYPE_VALUETYPE: { MonoClass *klass = mono_class_from_mono_type (sig->ret); if (klass->enumtype) { - simpletype = klass->enum_basetype->type; + simpletype = mono_class_enum_basetype (klass)->type; goto enum_retvalue; } if (sig->pinvoke) @@ -1462,7 +1557,7 @@ enum_retvalue: nParm++; break; case MONO_TYPE_GENERICINST: - if (!mono_type_generic_inst_is_valuetype (sig->params [i])) { + if (!mono_type_generic_inst_is_valuetype (ptype)) { cinfo->args[nParm].size = sizeof(gpointer); add_general (&gr, sz, cinfo->args+nParm, TRUE); nParm++; @@ -1484,6 +1579,7 @@ enum_retvalue: (info->fields[0].field->type->type == MONO_TYPE_R4)) { cinfo->args[nParm].size = sizeof(float); add_float(&fr, sz, cinfo->args+nParm); + nParm ++; break; } @@ -1492,6 +1588,7 @@ enum_retvalue: (info->fields[0].field->type->type == MONO_TYPE_R8)) { cinfo->args[nParm].size = sizeof(double); add_float(&fr, sz, cinfo->args+nParm); + nParm ++; break; } @@ -1624,15 +1721,18 @@ mono_arch_allocate_vars (MonoCompile *cfg) MonoMethodHeader *header; MonoInst *inst; CallInfo *cinfo; - size_data sz; int iParm, iVar, offset, size, align, curinst; int frame_reg = STK_BASE; int sArg, eArg; - header = mono_method_get_header (cfg->method); + header = cfg->header; cfg->flags |= MONO_CFG_HAS_SPILLUP; + sig = mono_method_signature (cfg->method); + + cinfo = get_call_info (cfg, cfg->mempool, sig, sig->pinvoke); + /*---------------------------------------------------------*/ /* We use the frame register also for any method that has */ /* filter clauses. This way, when the handlers are called, */ @@ -1648,17 +1748,16 @@ mono_arch_allocate_vars (MonoCompile *cfg) cfg->frame_reg = frame_reg; + cfg->arch.bkchain_reg = -1; + if (frame_reg != STK_BASE) cfg->used_int_regs |= 1 << frame_reg; sig = mono_method_signature (cfg->method); - cinfo = calculate_sizes (cfg, sig, &sz, sig->pinvoke); + cinfo = get_call_info (cfg, cfg->mempool, sig, sig->pinvoke); - if (cinfo->struct_ret) { - cfg->ret->opcode = OP_REGVAR; - cfg->ret->inst_c0 = s390_r2; - } else { + if (!cinfo->struct_ret) { switch (mono_type_get_underlying_type (sig->ret)->type) { case MONO_TYPE_VOID: break; @@ -1679,15 +1778,16 @@ mono_arch_allocate_vars (MonoCompile *cfg) cfg->sig_cookie = 0; if (cinfo->struct_ret) { - inst = cfg->ret; + inst = cfg->vret_addr; offset = S390_ALIGN(offset, sizeof(gpointer)); inst->inst_offset = offset; inst->opcode = OP_REGOFFSET; inst->inst_basereg = frame_reg; offset += sizeof(gpointer); - if ((sig->call_convention == MONO_CALL_VARARG) && - (!retFitsInReg (cinfo->ret.size))) - cfg->sig_cookie += cinfo->ret.size; + if (G_UNLIKELY (cfg->verbose_level > 1)) { + printf ("vret_addr ="); + mono_print_ins (cfg->vret_addr); + } } if (sig->hasthis) { @@ -1713,51 +1813,65 @@ mono_arch_allocate_vars (MonoCompile *cfg) inst = cfg->args [curinst]; if (inst->opcode != OP_REGVAR) { switch (cinfo->args[iParm].regtype) { - case RegTypeStructByAddr : - if (cinfo->args[iParm].reg == STK_BASE) { - inst->opcode = OP_S390_LOADARG; - inst->inst_basereg = frame_reg; - size = abs(cinfo->args[iParm].vtsize); - offset = S390_ALIGN(offset, sizeof(long)); - inst->inst_offset = offset; - inst->backend.arg_info = cinfo->args[iParm].offset; - } else { - inst->opcode = OP_S390_ARGREG; - inst->inst_basereg = frame_reg; - size = sizeof(gpointer); - offset = S390_ALIGN(offset, size); - inst->inst_offset = offset; - inst->backend.arg_info = cinfo->args[iParm].offset; + case RegTypeStructByAddr : { + MonoInst *indir; + + size = sizeof (gpointer); + + if (cinfo->args [iParm].reg == STK_BASE) { + cfg->arch.bkchain_reg = s390_r12; + cfg->used_int_regs |= 1 << cfg->arch.bkchain_reg; + + inst->opcode = OP_REGOFFSET; + inst->inst_basereg = cfg->arch.bkchain_reg; + inst->inst_offset = cinfo->args [iParm].offset; + } else { + inst->opcode = OP_REGOFFSET; + inst->inst_basereg = frame_reg; + inst->inst_offset = S390_ALIGN(offset, sizeof (gpointer)); + } + + /* Add a level of indirection */ + MONO_INST_NEW (cfg, indir, 0); + *indir = *inst; + inst->opcode = OP_VTARG_ADDR; + inst->inst_left = indir; } break; case RegTypeStructByVal : - inst->opcode = OP_S390_ARGPTR; - inst->inst_basereg = frame_reg; size = cinfo->args[iParm].size; offset = S390_ALIGN(offset, size); - inst->inst_offset = offset; - inst->backend.arg_info = cinfo->args[iParm].offset; + inst->opcode = OP_REGOFFSET; + inst->inst_basereg = frame_reg; + inst->inst_offset = S390_ALIGN (offset, size); break; default : - if (cinfo->args[iParm].reg != STK_BASE) { - inst->opcode = OP_REGOFFSET; - inst->inst_basereg = frame_reg; - size = (cinfo->args[iParm].size < 8 - ? sizeof(long) - : sizeof(long long)); - offset = S390_ALIGN(offset, size); - inst->inst_offset = offset; - } else { - inst->opcode = OP_S390_STKARG; - inst->inst_basereg = frame_reg; - size = (cinfo->args[iParm].size < 4 - ? 4 - cinfo->args[iParm].size - : 0); - inst->inst_offset = cinfo->args[iParm].offset + - size; - inst->backend.arg_info = 0; - size = sizeof(long); - } + if (cinfo->args [iParm].reg == STK_BASE) { + /* + * These arguments are in the previous frame, so we can't + * compute their offset from the current frame pointer right + * now, since cfg->stack_offset is not yet known, so dedicate a + * register holding the previous frame pointer. + */ + cfg->arch.bkchain_reg = s390_r12; + cfg->used_int_regs |= 1 << cfg->arch.bkchain_reg; + + inst->opcode = OP_REGOFFSET; + inst->inst_basereg = cfg->arch.bkchain_reg; + size = (cinfo->args[iParm].size < 4 + ? 4 - cinfo->args[iParm].size + : 0); + inst->inst_offset = cinfo->args [iParm].offset + size; + size = sizeof (long); + } else { + inst->opcode = OP_REGOFFSET; + inst->inst_basereg = frame_reg; + size = (cinfo->args[iParm].size < 8 + ? sizeof(long) + : sizeof(long long)); + offset = S390_ALIGN(offset, size); + inst->inst_offset = offset; + } } if ((sig->call_convention == MONO_CALL_VARARG) && (cinfo->args[iParm].regtype != RegTypeGeneral) && @@ -1812,118 +1926,281 @@ mono_arch_allocate_vars (MonoCompile *cfg) /*------------------------------------------------------*/ cfg->stack_offset = S390_ALIGN(offset, S390_STACK_ALIGNMENT); + /* Fix up offsets for arguments whose value is in the parent frame */ + for (iParm = sArg; iParm < eArg; ++iParm) { + inst = cfg->args [iParm]; + + if (inst->opcode == OP_S390_STKARG) { + inst->opcode = OP_REGOFFSET; + inst->inst_offset += cfg->stack_offset; + } + } } /*========================= End of Function ========================*/ /*------------------------------------------------------------------*/ /* */ -/* Name - mono_arch_call_opcode */ +/* Name - mono_arch_create_vars */ /* */ -/* Function - Take the arguments and generate the arch-specific */ -/* instructions to properly call the function. This */ -/* includes pushing, moving argments to the correct */ -/* etc. */ -/* */ /*------------------------------------------------------------------*/ -MonoCallInst* -mono_arch_call_opcode (MonoCompile *cfg, MonoBasicBlock* bb, - MonoCallInst *call, int is_virtual) { +void +mono_arch_create_vars (MonoCompile *cfg) +{ + MonoMethodSignature *sig; + CallInfo *cinfo; + + sig = mono_method_signature (cfg->method); + + cinfo = get_call_info (cfg, cfg->mempool, sig, sig->pinvoke); + + if (cinfo->struct_ret) { + cfg->vret_addr = mono_compile_create_var (cfg, &mono_defaults.int_class->byval_arg, OP_ARG); + if (G_UNLIKELY (cfg->verbose_level > 1)) { + printf ("vret_addr = "); + mono_print_ins (cfg->vret_addr); + } + } +} + +/*========================= End of Function ========================*/ + +static void +add_outarg_reg2 (MonoCompile *cfg, MonoCallInst *call, ArgStorage storage, int reg, MonoInst *tree) +{ + MonoInst *ins; + + switch (storage) { + case RegTypeGeneral: + MONO_INST_NEW (cfg, ins, OP_MOVE); + ins->dreg = mono_alloc_ireg (cfg); + ins->sreg1 = tree->dreg; + MONO_ADD_INS (cfg->cbb, ins); + mono_call_inst_add_outarg_reg (cfg, call, ins->dreg, reg, FALSE); + break; + case RegTypeFP: + MONO_INST_NEW (cfg, ins, OP_FMOVE); + ins->dreg = mono_alloc_freg (cfg); + ins->sreg1 = tree->dreg; + MONO_ADD_INS (cfg->cbb, ins); + mono_call_inst_add_outarg_reg (cfg, call, ins->dreg, reg, TRUE); + break; + case RegTypeFPR4: + MONO_INST_NEW (cfg, ins, OP_S390_SETF4RET); + ins->dreg = mono_alloc_freg (cfg); + ins->sreg1 = tree->dreg; + MONO_ADD_INS (cfg->cbb, ins); + mono_call_inst_add_outarg_reg (cfg, call, ins->dreg, reg, TRUE); + break; + default: + g_assert_not_reached (); + } +} + +static void +emit_sig_cookie (MonoCompile *cfg, MonoCallInst *call, CallInfo *cinfo) +{ + MonoMethodSignature *tmpSig; + MonoInst *sig_arg; + + cfg->disable_aot = TRUE; + + /*----------------------------------------------------------*/ + /* mono_ArgIterator_Setup assumes the signature cookie is */ + /* passed first and all the arguments which were before it */ + /* passed on the stack after the signature. So compensate */ + /* by passing a different signature. */ + /*----------------------------------------------------------*/ + tmpSig = mono_metadata_signature_dup (call->signature); + tmpSig->param_count -= call->signature->sentinelpos; + tmpSig->sentinelpos = 0; + if (tmpSig->param_count > 0) + memcpy (tmpSig->params, + call->signature->params + call->signature->sentinelpos, + tmpSig->param_count * sizeof(MonoType *)); + + MONO_INST_NEW (cfg, sig_arg, OP_ICONST); + sig_arg->dreg = mono_alloc_ireg (cfg); + sig_arg->inst_p0 = tmpSig; + MONO_ADD_INS (cfg->cbb, sig_arg); + + MONO_EMIT_NEW_STORE_MEMBASE (cfg, OP_STORE_MEMBASE_REG, STK_BASE, + cinfo->sigCookie.offset, sig_arg->dreg); +} + +/*------------------------------------------------------------------*/ +/* */ +/* Name - mono_arch_emit_call */ +/* */ +/*------------------------------------------------------------------*/ + +void +mono_arch_emit_call (MonoCompile *cfg, MonoCallInst *call) +{ MonoInst *in; - MonoCallArgParm *arg; MonoMethodSignature *sig; + MonoInst *ins; int i, n, lParamArea; CallInfo *cinfo; ArgInfo *ainfo = NULL; - size_data sz; int stackSize; sig = call->signature; n = sig->param_count + sig->hasthis; DEBUG (g_print ("Call requires: %d parameters\n",n)); - cinfo = calculate_sizes (cfg, sig, &sz, sig->pinvoke); + cinfo = get_call_info (cfg, cfg->mempool, sig, sig->pinvoke); - stackSize = sz.stack_size + sz.local_size + sz.parm_size + sz.offset; + stackSize = cinfo->sz.stack_size + cinfo->sz.local_size + cinfo->sz.parm_size + cinfo->sz.offset; call->stack_usage = MAX(stackSize, call->stack_usage); - lParamArea = MAX((call->stack_usage-S390_MINIMAL_STACK_SIZE-sz.parm_size), 0); + lParamArea = MAX((call->stack_usage-S390_MINIMAL_STACK_SIZE-cinfo->sz.parm_size), 0); cfg->param_area = MAX(((signed) cfg->param_area), lParamArea); cfg->flags |= MONO_CFG_HAS_CALLS; - if (cinfo->struct_ret) - call->used_iregs |= 1 << cinfo->ret.reg; + if (cinfo->struct_ret) { + MONO_INST_NEW (cfg, ins, OP_MOVE); + ins->sreg1 = call->vret_var->dreg; + ins->dreg = mono_alloc_preg (cfg); + MONO_ADD_INS (cfg->cbb, ins); + mono_call_inst_add_outarg_reg (cfg, call, ins->dreg, cinfo->ret.reg, FALSE); + } for (i = 0; i < n; ++i) { ainfo = cinfo->args + i; + MonoType *t; + + if (i >= sig->hasthis) + t = sig->params [i - sig->hasthis]; + else + t = &mono_defaults.int_class->byval_arg; + t = mono_type_get_underlying_type (t); + + in = call->args [i]; if ((sig->call_convention == MONO_CALL_VARARG) && (i == sig->sentinelpos)) { - emit_sig_cookie (cfg, call, cinfo, ainfo->size); + emit_sig_cookie (cfg, call, cinfo); } - if (is_virtual && i == 0) { - /* the argument will be attached to the call instrucion */ - in = call->args [i]; - call->used_iregs |= 1 << ainfo->reg; - } else { - MONO_INST_NEW_CALL_ARG (cfg, arg, OP_OUTARG); - in = call->args [i]; - arg->ins.cil_code = in->cil_code; - arg->ins.inst_left = in; - arg->ins.type = in->type; - MONO_INST_LIST_ADD_TAIL (&arg->ins.node, &call->out_args); - arg->ins.inst_right = (MonoInst *) call; - if (ainfo->regtype == RegTypeGeneral) { - arg->ins.backend.reg3 = ainfo->reg; - call->used_iregs |= 1 << ainfo->reg; - if (arg->ins.type == STACK_I8) - call->used_iregs |= 1 << (ainfo->reg + 1); - } else if (ainfo->regtype == RegTypeStructByAddr) { - call->used_iregs |= 1 << ainfo->reg; - arg->ins.sreg1 = ainfo->reg; - arg->ins.opcode = OP_OUTARG_VT; - arg->size = -ainfo->vtsize; - arg->offset = ainfo->offset; - arg->offPrm = ainfo->offparm + sz.offStruct; - } else if (ainfo->regtype == RegTypeStructByVal) { - if (ainfo->reg != STK_BASE) { - switch (ainfo->size) { - case 0: - case 1: - case 2: - case 4: - call->used_iregs |= 1 << ainfo->reg; - break; - case 8: - call->used_iregs |= 1 << ainfo->reg; - call->used_iregs |= 1 << (ainfo->reg+1); - break; - default: - call->used_iregs |= 1 << ainfo->reg; - } - } - arg->ins.sreg1 = ainfo->reg; - arg->ins.opcode = OP_OUTARG_VT; - arg->size = ainfo->size; - arg->offset = ainfo->offset; - arg->offPrm = ainfo->offparm + sz.offStruct; - } else if (ainfo->regtype == RegTypeBase) { - arg->ins.opcode = OP_OUTARG_MEMBASE; - arg->ins.sreg1 = ainfo->reg; - arg->size = ainfo->size; - arg->offset = ainfo->offset; - call->used_iregs |= 1 << ainfo->reg; - } else if (ainfo->regtype == RegTypeFP) { - arg->ins.backend.reg3 = ainfo->reg; - call->used_fregs |= 1 << ainfo->reg; + switch (ainfo->regtype) { + case RegTypeGeneral: + if (!t->byref && (t->type == MONO_TYPE_I8 || t->type == MONO_TYPE_U8)) { + MONO_INST_NEW (cfg, ins, OP_MOVE); + ins->dreg = mono_alloc_ireg (cfg); + ins->sreg1 = in->dreg + 2; + MONO_ADD_INS (cfg->cbb, ins); + mono_call_inst_add_outarg_reg (cfg, call, ins->dreg, ainfo->reg, FALSE); + MONO_INST_NEW (cfg, ins, OP_MOVE); + ins->dreg = mono_alloc_ireg (cfg); + ins->sreg1 = in->dreg + 1; + MONO_ADD_INS (cfg->cbb, ins); + mono_call_inst_add_outarg_reg (cfg, call, ins->dreg, ainfo->reg + 1, FALSE); + } else { + add_outarg_reg2 (cfg, call, ainfo->regtype, ainfo->reg, in); + } + break; + case RegTypeFP: + if (MONO_TYPE_ISSTRUCT (t)) { + /* Valuetype passed in one fp register */ + ainfo->regtype = RegTypeStructByValInFP; + /* Fall through */ + } else { if (ainfo->size == 4) - arg->ins.opcode = OP_OUTARG_R4; - else - arg->ins.opcode = OP_OUTARG_R8; + ainfo->regtype = RegTypeFPR4; + add_outarg_reg2 (cfg, call, ainfo->regtype, ainfo->reg, in); + break; + } + case RegTypeStructByVal: + case RegTypeStructByAddr: { + guint32 align; + guint32 size; + + 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 { + /* + * Other backends use mono_type_stack_size (), but that + * aligns the size to 8, 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. + */ + size = mono_class_value_size (in->klass, &align); + } + + g_assert (in->klass); + + ainfo->offparm += cinfo->sz.offStruct; + + MONO_INST_NEW (cfg, ins, OP_OUTARG_VT); + ins->sreg1 = in->dreg; + ins->klass = in->klass; + ins->backend.size = ainfo->size; + ins->inst_p0 = call; + ins->inst_p1 = mono_mempool_alloc (cfg->mempool, sizeof (ArgInfo)); + memcpy (ins->inst_p1, ainfo, sizeof (ArgInfo)); + + MONO_ADD_INS (cfg->cbb, ins); + + if (ainfo->regtype == RegTypeStructByAddr) { + /* + * 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. + */ + int treg = mono_alloc_preg (cfg); + MONO_EMIT_NEW_BIALU_IMM (cfg, OP_ADD_IMM, treg, + STK_BASE, ainfo->offparm); + if (ainfo->reg == STK_BASE) { + /* The address is passed on the stack */ + MONO_INST_NEW (cfg, ins, OP_STORE_MEMBASE_REG); + ins->inst_destbasereg = STK_BASE; + ins->inst_offset = ainfo->offset; + ins->sreg1 = treg; + MONO_ADD_INS (cfg->cbb, ins); + } else { + mono_call_inst_add_outarg_reg (cfg, call, treg, ainfo->reg, FALSE); + } + } + break; + } + case RegTypeBase: + if (!t->byref && t->type == MONO_TYPE_R4) { + MONO_EMIT_NEW_STORE_MEMBASE (cfg, OP_STORER4_MEMBASE_REG, + STK_BASE, ainfo->offset, + in->dreg); + } else if (!t->byref && (t->type == MONO_TYPE_R8)) { + MONO_EMIT_NEW_STORE_MEMBASE (cfg, OP_STORER8_MEMBASE_REG, + STK_BASE, ainfo->offset, + in->dreg); + } else if (!t->byref && (t->type == MONO_TYPE_I8 || t->type == MONO_TYPE_U8)) { + MONO_INST_NEW (cfg, ins, OP_STORE_MEMBASE_REG); + ins->inst_destbasereg = STK_BASE; + ins->inst_offset = ainfo->offset + MINI_LS_WORD_OFFSET; + ins->sreg1 = in->dreg + 1; + MONO_ADD_INS (cfg->cbb, ins); + + MONO_INST_NEW (cfg, ins, OP_STORE_MEMBASE_REG); + ins->inst_destbasereg = STK_BASE; + ins->inst_offset = ainfo->offset + MINI_MS_WORD_OFFSET; + ins->sreg1 = in->dreg + 2; + MONO_ADD_INS (cfg->cbb, ins); } else { - g_assert_not_reached (); + MONO_INST_NEW (cfg, ins, OP_STORE_MEMBASE_REG); + ins->inst_destbasereg = STK_BASE; + ins->inst_offset = ainfo->offset; + ins->sreg1 = in->dreg; + MONO_ADD_INS (cfg->cbb, ins); } + break; + default: + g_assert_not_reached (); + break; } } @@ -1932,57 +2209,84 @@ mono_arch_call_opcode (MonoCompile *cfg, MonoBasicBlock* bb, */ if ((sig->call_convention == MONO_CALL_VARARG) && (i == sig->sentinelpos)) { - emit_sig_cookie (cfg, call, cinfo, ainfo->size); + emit_sig_cookie (cfg, call, cinfo); } - - g_free (cinfo); - return call; } /*========================= End of Function ========================*/ /*------------------------------------------------------------------*/ /* */ -/* Name - emit_sig_cookie. */ +/* Name - mono_arch_emit_outarg_vt */ /* */ -/* Function - For variable length parameter lists construct a */ -/* signature cookie and emit it. */ -/* */ /*------------------------------------------------------------------*/ -static void -emit_sig_cookie (MonoCompile *cfg, MonoCallInst *call, - CallInfo *cinfo, int argSize) +void +mono_arch_emit_outarg_vt (MonoCompile *cfg, MonoInst *ins, MonoInst *src) { - MonoCallArgParm *arg; - MonoMethodSignature *tmpSig; - MonoInst *sigArg; - - cfg->disable_aot = TRUE; + MonoCallInst *call = (MonoCallInst*)ins->inst_p0; + ArgInfo *ainfo = (ArgInfo*)ins->inst_p1; + int size = ins->backend.size; - /*----------------------------------------------------------*/ - /* mono_ArgIterator_Setup assumes the signature cookie is */ - /* passed first and all the arguments which were before it */ - /* passed on the stack after the signature. So compensate */ - /* by passing a different signature. */ - /*----------------------------------------------------------*/ - tmpSig = mono_metadata_signature_dup (call->signature); - tmpSig->param_count -= call->signature->sentinelpos; - tmpSig->sentinelpos = 0; - if (tmpSig->param_count > 0) - memcpy (tmpSig->params, - call->signature->params + call->signature->sentinelpos, - tmpSig->param_count * sizeof(MonoType *)); + if (ainfo->regtype == RegTypeStructByVal) { + /* + arg->ins.sreg1 = ainfo->reg; + arg->ins.opcode = OP_OUTARG_VT; + arg->size = ainfo->size; + arg->offset = ainfo->offset; + arg->offPrm = ainfo->offparm + cinfo->sz.offStruct; + */ + if (ainfo->reg != STK_BASE) { + MONO_OUTPUT_VTR (cfg, size, ainfo->reg, src->dreg, 0); + } else { + MONO_OUTPUT_VTS (cfg, size, ainfo->reg, ainfo->offset, + src->dreg, 0); + } + } else if (ainfo->regtype == RegTypeStructByValInFP) { + int dreg = mono_alloc_freg (cfg); + + if (ainfo->size == 4) { + MONO_EMIT_NEW_LOAD_MEMBASE_OP (cfg, OP_LOADR4_MEMBASE, dreg, src->dreg, 0); + MONO_EMIT_NEW_UNALU (cfg, OP_S390_SETF4RET, dreg, dreg); + } else { + g_assert (ainfo->size == 8); + + MONO_EMIT_NEW_LOAD_MEMBASE_OP (cfg, OP_LOADR8_MEMBASE, dreg, src->dreg, 0); + } - MONO_INST_NEW (cfg, sigArg, OP_ICONST); - sigArg->inst_p0 = tmpSig; + mono_call_inst_add_outarg_reg (cfg, call, dreg, ainfo->reg, TRUE); + } else { + MONO_EMIT_NEW_MOVE (cfg, STK_BASE, ainfo->offparm, + src->dreg, 0, size); + } +} + +/*------------------------------------------------------------------*/ +/* */ +/* Name - mono_arch_emit_setret */ +/* */ +/*------------------------------------------------------------------*/ - MONO_INST_NEW_CALL_ARG (cfg, arg, OP_OUTARG_MEMBASE); - arg->ins.inst_left = sigArg; - arg->ins.inst_right = (MonoInst *) call; - arg->size = argSize; - arg->offset = cinfo->sigCookie.offset; - MONO_INST_LIST_ADD_TAIL (&arg->ins.node, &call->out_args); +void +mono_arch_emit_setret (MonoCompile *cfg, MonoMethod *method, MonoInst *val) +{ + MonoType *ret = mono_type_get_underlying_type (mono_method_signature (method)->ret); + + if (!ret->byref) { + if (ret->type == MONO_TYPE_R4) { + MONO_EMIT_NEW_UNALU (cfg, OP_S390_SETF4RET, s390_f0, val->dreg); + return; + } else if (ret->type == MONO_TYPE_R8) { + MONO_EMIT_NEW_UNALU (cfg, OP_FMOVE, s390_f0, val->dreg); + return; + } else if (ret->type == MONO_TYPE_I8 || ret->type == MONO_TYPE_U8) { + MONO_EMIT_NEW_UNALU (cfg, OP_MOVE, s390_r3, val->dreg + 1); + MONO_EMIT_NEW_UNALU (cfg, OP_MOVE, s390_r2, val->dreg + 2); + return; + } + } + + MONO_EMIT_NEW_UNALU (cfg, OP_MOVE, cfg->ret->dreg, val->dreg); } /*========================= End of Function ========================*/ @@ -2074,7 +2378,7 @@ mono_arch_instrument_prolog (MonoCompile *cfg, void *func, void *p, /*------------------------------------------------------------------*/ 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) { guchar *code = p; int save_mode = SAVE_NONE, @@ -2107,7 +2411,7 @@ handle_enum: break; case MONO_TYPE_VALUETYPE: if (mono_method_signature (method)->ret->data.klass->enumtype) { - rtype = mono_method_signature (method)->ret->data.klass->enum_basetype->type; + rtype = mono_class_enum_basetype (mono_method_signature (method)->ret->data.klass)->type; goto handle_enum; } save_mode = SAVE_STRUCT; @@ -2184,158 +2488,54 @@ handle_enum: /*========================= End of Function ========================*/ +void +mono_arch_peephole_pass_1 (MonoCompile *cfg, MonoBasicBlock *bb) +{ +} + /*------------------------------------------------------------------*/ /* */ -/* Name - peephole_pass */ +/* Name - mono_arch_peephole_pass */ /* */ /* Function - Form a peephole pass at the code looking for */ /* simple optimizations. */ /* */ /*------------------------------------------------------------------*/ -static void -peephole_pass (MonoCompile *cfg, MonoBasicBlock *bb) +void +mono_arch_peephole_pass_2 (MonoCompile *cfg, MonoBasicBlock *bb) { MonoInst *ins, *n; - MONO_INST_LIST_FOR_EACH_ENTRY_SAFE (ins, n, &bb->ins_list, node) { - MonoInst *last_ins = mono_inst_list_prev (&ins->node, &bb->ins_list); - switch (ins->opcode) { - case OP_MUL_IMM: - /* remove unnecessary multiplication with 1 */ - if (ins->inst_imm == 1) { - if (ins->dreg != ins->sreg1) { - ins->opcode = OP_MOVE; - } else { - MONO_DEL_INS (ins); - continue; - } - } - break; - case OP_LOAD_MEMBASE: - case OP_LOADI4_MEMBASE: - /* - * OP_STORE_MEMBASE_REG reg, offset(basereg) - * OP_LOAD_MEMBASE offset(basereg), reg - */ - if (last_ins && (last_ins->opcode == OP_STOREI4_MEMBASE_REG - || last_ins->opcode == OP_STORE_MEMBASE_REG) && - ins->inst_basereg == last_ins->inst_destbasereg && - ins->inst_offset == last_ins->inst_offset) { - if (ins->dreg == last_ins->sreg1) { - MONO_DEL_INS (ins); - continue; - } else { - ins->opcode = OP_MOVE; - ins->sreg1 = last_ins->sreg1; - } + MONO_BB_FOR_EACH_INS_SAFE (bb, n, ins) { + mono_peephole_ins (bb, ins); + } +} - /* - * Note: reg1 must be different from the basereg in the second load - * OP_LOAD_MEMBASE offset(basereg), reg1 - * OP_LOAD_MEMBASE offset(basereg), reg2 - * --> - * OP_LOAD_MEMBASE offset(basereg), reg1 - * OP_MOVE reg1, reg2 - */ - } if (last_ins && (last_ins->opcode == OP_LOADI4_MEMBASE - || last_ins->opcode == OP_LOAD_MEMBASE) && - ins->inst_basereg != last_ins->dreg && - ins->inst_basereg == last_ins->inst_basereg && - ins->inst_offset == last_ins->inst_offset) { - - if (ins->dreg == last_ins->dreg) { - MONO_DEL_INS (ins); - continue; - } else { - ins->opcode = OP_MOVE; - ins->sreg1 = last_ins->dreg; - } +/*========================= End of Function ========================*/ - //g_assert_not_reached (); +void +mono_arch_lowering_pass (MonoCompile *cfg, MonoBasicBlock *bb) +{ + MonoInst *ins, *next; -#if 0 - /* - * OP_STORE_MEMBASE_IMM imm, offset(basereg) - * OP_LOAD_MEMBASE offset(basereg), reg - * --> - * OP_STORE_MEMBASE_IMM imm, offset(basereg) - * OP_ICONST reg, imm - */ - } else if (last_ins && (last_ins->opcode == OP_STOREI4_MEMBASE_IMM - || last_ins->opcode == OP_STORE_MEMBASE_IMM) && - ins->inst_basereg == last_ins->inst_destbasereg && - ins->inst_offset == last_ins->inst_offset) { - //static int c = 0; printf ("MATCHX %s %d\n", cfg->method->name,c++); - ins->opcode = OP_ICONST; - ins->inst_c0 = last_ins->inst_imm; - g_assert_not_reached (); // check this rule -#endif - } - break; - case OP_LOADU1_MEMBASE: - case OP_LOADI1_MEMBASE: - if (last_ins && (last_ins->opcode == OP_STOREI1_MEMBASE_REG) && - ins->inst_basereg == last_ins->inst_destbasereg && - ins->inst_offset == last_ins->inst_offset) { - ins->opcode = (ins->opcode == OP_LOADI1_MEMBASE) ? CEE_CONV_I1 : CEE_CONV_U1; - ins->sreg1 = last_ins->sreg1; - } - break; - case OP_LOADU2_MEMBASE: - case OP_LOADI2_MEMBASE: - if (last_ins && (last_ins->opcode == OP_STOREI2_MEMBASE_REG) && - ins->inst_basereg == last_ins->inst_destbasereg && - ins->inst_offset == last_ins->inst_offset) { - ins->opcode = (ins->opcode == OP_LOADI2_MEMBASE) ? CEE_CONV_I2 : CEE_CONV_U2; - ins->sreg1 = last_ins->sreg1; - } + MONO_BB_FOR_EACH_INS_SAFE (bb, next, ins) { + switch (ins->opcode) { + case OP_DIV_IMM: + case OP_REM_IMM: + case OP_IDIV_IMM: + case OP_IREM_IMM: + case OP_IDIV_UN_IMM: + case OP_IREM_UN_IMM: + case OP_LOCALLOC_IMM: + mono_decompose_op_imm (cfg, bb, ins); break; - case CEE_CONV_I4: - case CEE_CONV_U4: - case OP_MOVE: - /* - * OP_MOVE reg, reg - */ - if (ins->dreg == ins->sreg1) { - MONO_DEL_INS (ins); - continue; - } - /* - * OP_MOVE sreg, dreg - * OP_MOVE dreg, sreg - */ - if (last_ins && last_ins->opcode == OP_MOVE && - ins->sreg1 == last_ins->dreg && - ins->dreg == last_ins->sreg1) { - MONO_DEL_INS (ins); - continue; - } + default: break; } } -} - -/*========================= End of Function ========================*/ - -/*------------------------------------------------------------------*/ -/* */ -/* Name - mono_arch_local_regalloc. */ -/* */ -/* Function - We first scan the list of instructions and we */ -/* save the liveness information of each register */ -/* (when the register is first used, when its value */ -/* is set etc.). We also reverse the list of instr- */ -/* uctions (in the InstList list) because assigning */ -/* registers backwards allows for more tricks to be */ -/* used. */ -/* */ -/*------------------------------------------------------------------*/ -void -mono_arch_local_regalloc (MonoCompile *cfg, MonoBasicBlock *bb) -{ - mono_local_regalloc(cfg, bb); + bb->max_vreg = cfg->next_vreg; } /*========================= End of Function ========================*/ @@ -2370,8 +2570,8 @@ emit_float_to_int (MonoCompile *cfg, guchar *code, int dreg, int sreg, int size, short *o[1]; s390_basr (code, s390_r13, 0); s390_j (code, 10); - s390_llong (code, 0x41e0000000000000); - s390_llong (code, 0x41f0000000000000); + s390_llong (code, 0x41e0000000000000LL); + s390_llong (code, 0x41f0000000000000LL); s390_ldr (code, s390_f15, sreg); s390_cdb (code, s390_f15, 0, s390_r13, 4); s390_jl (code, 0); CODEPTR(code, o[0]); @@ -2409,16 +2609,14 @@ emit_float_to_int (MonoCompile *cfg, guchar *code, int dreg, int sreg, int size, void mono_arch_output_basic_block (MonoCompile *cfg, MonoBasicBlock *bb) { - MonoInst *ins, *next; + MonoInst *ins; MonoCallInst *call; guint offset; guint8 *code = cfg->native_code + cfg->code_len; + MonoInst *last_ins = NULL; guint last_offset = 0; int max_len, cpos, src2; - if (cfg->opt & MONO_OPT_PEEPHOLE) - peephole_pass (cfg, bb); - /* we don't align basic blocks of loops on s390 */ if (cfg->verbose_level > 2) @@ -2619,32 +2817,22 @@ mono_arch_output_basic_block (MonoCompile *cfg, MonoBasicBlock *bb) s390_lr (code, ins->dreg, s390_r0); } break; - case CEE_CONV_I1: { - s390_lhi (code, s390_r0, 0x80); - if (ins->dreg != ins->sreg1) { + + case OP_ICONV_TO_I1: { + if (ins->dreg != ins->sreg1) s390_lr (code, ins->dreg, ins->sreg1); - } - s390_nr (code, s390_r0, ins->sreg1); - s390_jz (code, 7); - s390_lhi (code, s390_r13, -1); - s390_sll (code, s390_r13, 0, 8); - s390_or (code, ins->dreg, s390_r13); + s390_sll (code, ins->dreg, 0, 24); + s390_sra (code, ins->dreg, 0, 24); } break; - case CEE_CONV_I2: { - s390_lhi (code, s390_r0, 0x80); - s390_sll (code, s390_r0, 0, 8); - if (ins->dreg != ins->sreg1) { - s390_lr (code, ins->dreg, ins->sreg1); - } - s390_nr (code, s390_r0, ins->sreg1); - s390_jz (code, 7); - s390_lhi (code, s390_r13, -1); - s390_sll (code, s390_r13, 0, 16); - s390_or (code, ins->dreg, s390_r13); + case OP_ICONV_TO_I2: { + if (ins->dreg != ins->sreg1) + s390_lr (code, ins->dreg, ins->sreg1); + s390_sll (code, ins->dreg, 0, 16); + s390_sra (code, ins->dreg, 0, 16); } break; - case CEE_CONV_U1: { + case OP_ICONV_TO_U1: { s390_lhi (code, s390_r0, 0xff); if (ins->dreg != ins->sreg1) { s390_lr (code, ins->dreg, ins->sreg1); @@ -2652,7 +2840,7 @@ mono_arch_output_basic_block (MonoCompile *cfg, MonoBasicBlock *bb) s390_nr (code, ins->dreg, s390_r0); } break; - case CEE_CONV_U2: { + case OP_ICONV_TO_U2: { s390_lhi (code, s390_r0, -1); s390_sll (code, s390_r0, 0, 16); s390_srl (code, s390_r0, 0, 16); @@ -2662,31 +2850,51 @@ mono_arch_output_basic_block (MonoCompile *cfg, MonoBasicBlock *bb) s390_nr (code, ins->dreg, s390_r0); } break; - case OP_COMPARE: { - next = mono_inst_list_next (&ins->node, &bb->ins_list); + case OP_COMPARE: + case OP_ICOMPARE: { + gboolean un = FALSE; + MonoInst *next = ins->next; + if ((next) && - (((next->opcode >= CEE_BNE_UN) && - (next->opcode <= CEE_BLT_UN)) || + (((next->opcode >= OP_IBNE_UN) && + (next->opcode <= OP_IBLT_UN)) || ((next->opcode >= OP_COND_EXC_NE_UN) && (next->opcode <= OP_COND_EXC_LT_UN)) || + ((next->opcode >= OP_COND_EXC_INE_UN) && + (next->opcode <= OP_COND_EXC_ILT_UN)) || ((next->opcode == OP_CLT_UN) || - (next->opcode == OP_CGT_UN)))) + (next->opcode == OP_CGT_UN)) || + ((next->opcode == OP_ICLT_UN) || + (next->opcode == OP_ICGT_UN)))) + un = TRUE; + + if (un) s390_clr (code, ins->sreg1, ins->sreg2); else s390_cr (code, ins->sreg1, ins->sreg2); } break; - case OP_COMPARE_IMM: { - next = mono_inst_list_next (&ins->node, &bb->ins_list); + case OP_COMPARE_IMM: + case OP_ICOMPARE_IMM: { + gboolean un = FALSE; + MonoInst *next = ins->next; + + if ((next) && + (((next->opcode >= OP_IBNE_UN) && + (next->opcode <= OP_IBLT_UN)) || + ((next->opcode >= OP_COND_EXC_NE_UN) && + (next->opcode <= OP_COND_EXC_LT_UN)) || + ((next->opcode >= OP_COND_EXC_INE_UN) && + (next->opcode <= OP_COND_EXC_ILT_UN)) || + ((next->opcode == OP_CLT_UN) || + (next->opcode == OP_CGT_UN)) || + ((next->opcode == OP_ICLT_UN) || + (next->opcode == OP_ICGT_UN)))) + un = TRUE; + if (s390_is_imm16 (ins->inst_imm)) { s390_lhi (code, s390_r0, ins->inst_imm); - if ((next) && - (((next->opcode >= CEE_BNE_UN) && - (next->opcode <= CEE_BLT_UN)) || - ((next->opcode >= OP_COND_EXC_NE_UN) && - (next->opcode <= OP_COND_EXC_LT_UN)) || - ((next->opcode == OP_CLT_UN) || - (next->opcode == OP_CGT_UN)))) + if (un) s390_clr (code, ins->sreg1, s390_r0); else s390_cr (code, ins->sreg1, s390_r0); @@ -2695,13 +2903,7 @@ mono_arch_output_basic_block (MonoCompile *cfg, MonoBasicBlock *bb) s390_basr (code, s390_r13, 0); s390_j (code, 4); s390_word (code, ins->inst_imm); - if ((next) && - (((next->opcode >= CEE_BNE_UN) && - (next->opcode <= CEE_BLT_UN)) || - ((next->opcode >= OP_COND_EXC_NE_UN) && - (next->opcode <= OP_COND_EXC_LT_UN)) || - ((next->opcode == OP_CLT_UN) || - (next->opcode == OP_CGT_UN)))) + if (un) s390_cl (code, ins->sreg1, 0, s390_r13, 4); else s390_c (code, ins->sreg1, 0, s390_r13, 4); @@ -2713,28 +2915,30 @@ mono_arch_output_basic_block (MonoCompile *cfg, MonoBasicBlock *bb) s390_brasl (code, s390_r14, 0); } break; - case OP_ADDCC: { + case OP_ADDCC: + case OP_IADDCC: { CHECK_SRCDST_COM; s390_alr (code, ins->dreg, src2); } break; - case CEE_ADD: { + case OP_IADD: { CHECK_SRCDST_COM; s390_ar (code, ins->dreg, src2); } break; - case OP_ADC: { + case OP_ADC: + case OP_IADC: { CHECK_SRCDST_COM; s390_alcr (code, ins->dreg, src2); } break; - case OP_ADD_IMM: { + case OP_ADD_IMM: + case OP_IADD_IMM: { if (ins->dreg != ins->sreg1) { s390_lr (code, ins->dreg, ins->sreg1); } - next = mono_inst_list_next (&ins->node, &bb->ins_list); - if ((next) && - (next->opcode == OP_ADC_IMM)) { + if ((ins->next) && + (ins->next->opcode == OP_ADC_IMM)) { s390_basr (code, s390_r13, 0); s390_j (code, 4); s390_word (code, ins->inst_imm); @@ -2752,9 +2956,8 @@ mono_arch_output_basic_block (MonoCompile *cfg, MonoBasicBlock *bb) } break; case OP_ADDCC_IMM: { - next = mono_inst_list_next (&ins->node, &bb->ins_list); - if ((next) && - (next->opcode == OP_ADC_IMM)) { + if ((ins->next) && + (ins->next->opcode == OP_ADC_IMM)) { s390_basr (code, s390_r13, 0); s390_j (code, 4); s390_word (code, ins->inst_imm); @@ -2797,19 +3000,22 @@ mono_arch_output_basic_block (MonoCompile *cfg, MonoBasicBlock *bb) } } break; - case CEE_ADD_OVF: { + case OP_IADD_OVF: + case OP_S390_IADD_OVF: { CHECK_SRCDST_COM; s390_ar (code, ins->dreg, src2); EMIT_COND_SYSTEM_EXCEPTION (S390_CC_OV, "OverflowException"); } break; - case CEE_ADD_OVF_UN: { + case OP_IADD_OVF_UN: + case OP_S390_IADD_OVF_UN: { CHECK_SRCDST_COM; s390_alr (code, ins->dreg, src2); EMIT_COND_SYSTEM_EXCEPTION (S390_CC_CY, "OverflowException"); } break; - case OP_LADD: { + case OP_LADD: + case OP_S390_LADD: { s390_alr (code, s390_r0, ins->sreg1); s390_jnc (code, 4); s390_ahi (code, s390_r1, 1); @@ -2818,7 +3024,8 @@ mono_arch_output_basic_block (MonoCompile *cfg, MonoBasicBlock *bb) s390_lr (code, ins->dreg+1, s390_r1); } break; - case OP_LADD_OVF: { + case OP_LADD_OVF: + case OP_S390_LADD_OVF: { short int *o[1]; s390_alr (code, s390_r0, ins->sreg1); s390_jnc (code, 0); CODEPTR(code, o[0]); @@ -2831,7 +3038,8 @@ mono_arch_output_basic_block (MonoCompile *cfg, MonoBasicBlock *bb) s390_lr (code, ins->dreg+1, s390_r1); } break; - case OP_LADD_OVF_UN: { + case OP_LADD_OVF_UN: + case OP_S390_LADD_OVF_UN: { s390_alr (code, s390_r0, ins->sreg1); s390_alcr (code, s390_r1, ins->sreg2); EMIT_COND_SYSTEM_EXCEPTION (S390_CC_CY, "OverflowException"); @@ -2856,17 +3064,19 @@ mono_arch_output_basic_block (MonoCompile *cfg, MonoBasicBlock *bb) EMIT_COND_SYSTEM_EXCEPTION (S390_CC_CY, "OverflowException"); } break; - case OP_SUBCC: { + case OP_SUBCC: + case OP_ISUBCC: { CHECK_SRCDST_NCOM; s390_slr (code, ins->dreg, src2); } break; - case CEE_SUB: { + case OP_ISUB: { CHECK_SRCDST_NCOM; s390_sr (code, ins->dreg, src2); } break; - case OP_SBB: { + case OP_SBB: + case OP_ISBB: { CHECK_SRCDST_NCOM; s390_slbr (code, ins->dreg, src2); } @@ -2889,7 +3099,8 @@ mono_arch_output_basic_block (MonoCompile *cfg, MonoBasicBlock *bb) } } break; - case OP_SUB_IMM: { + case OP_SUB_IMM: + case OP_ISUB_IMM: { if (s390_is_imm16 (-ins->inst_imm)) { if (ins->dreg != ins->sreg1) { s390_lr (code, ins->dreg, ins->sreg1); @@ -2921,19 +3132,22 @@ mono_arch_output_basic_block (MonoCompile *cfg, MonoBasicBlock *bb) } } break; - case CEE_SUB_OVF: { + case OP_ISUB_OVF: + case OP_S390_ISUB_OVF: { CHECK_SRCDST_NCOM; s390_sr (code, ins->dreg, src2); EMIT_COND_SYSTEM_EXCEPTION (S390_CC_OV, "OverflowException"); } break; - case CEE_SUB_OVF_UN: { + case OP_ISUB_OVF_UN: + case OP_S390_ISUB_OVF_UN: { CHECK_SRCDST_NCOM; s390_slr (code, ins->dreg, src2); EMIT_COND_SYSTEM_EXCEPTION (S390_CC_NC, "OverflowException"); } break; - case OP_LSUB: { + case OP_LSUB: + case OP_S390_LSUB: { s390_lr (code, s390_r14, ins->sreg2); s390_slr (code, s390_r0, ins->sreg1); s390_jnl (code, 4); @@ -2943,7 +3157,8 @@ mono_arch_output_basic_block (MonoCompile *cfg, MonoBasicBlock *bb) s390_lr (code, ins->dreg+1, s390_r1); } break; - case OP_LSUB_OVF: { + case OP_LSUB_OVF: + case OP_S390_LSUB_OVF: { short int *o[1]; s390_lr (code, s390_r14, ins->sreg2); s390_slr (code, s390_r0, ins->sreg1); @@ -2957,7 +3172,8 @@ mono_arch_output_basic_block (MonoCompile *cfg, MonoBasicBlock *bb) s390_lr (code, ins->dreg+1, s390_r1); } break; - case OP_LSUB_OVF_UN: { + case OP_LSUB_OVF_UN: + case OP_S390_LSUB_OVF_UN: { s390_slr (code, s390_r0, ins->sreg1); s390_slbr (code, s390_r1, ins->sreg2); EMIT_COND_SYSTEM_EXCEPTION (S390_CC_LT, "OverflowException"); @@ -2982,7 +3198,7 @@ mono_arch_output_basic_block (MonoCompile *cfg, MonoBasicBlock *bb) EMIT_COND_SYSTEM_EXCEPTION (S390_CC_NC, "OverflowException"); } break; - case CEE_AND: { + case OP_IAND: { if (ins->sreg1 == ins->dreg) { s390_nr (code, ins->dreg, ins->sreg2); } @@ -2997,7 +3213,8 @@ mono_arch_output_basic_block (MonoCompile *cfg, MonoBasicBlock *bb) } } break; - case OP_AND_IMM: { + case OP_AND_IMM: + case OP_IAND_IMM: { if (s390_is_imm16 (ins->inst_imm)) { s390_lhi (code, s390_r0, ins->inst_imm); if (ins->dreg != ins->sreg1) { @@ -3015,66 +3232,34 @@ mono_arch_output_basic_block (MonoCompile *cfg, MonoBasicBlock *bb) } } break; - case CEE_DIV: { + case OP_IDIV: { s390_lr (code, s390_r0, ins->sreg1); s390_srda (code, s390_r0, 0, 32); s390_dr (code, s390_r0, ins->sreg2); s390_lr (code, ins->dreg, s390_r1); } break; - case CEE_DIV_UN: { + case OP_IDIV_UN: { s390_lr (code, s390_r0, ins->sreg1); s390_srdl (code, s390_r0, 0, 32); s390_dlr (code, s390_r0, ins->sreg2); s390_lr (code, ins->dreg, s390_r1); } break; - case OP_DIV_IMM: { - if (s390_is_imm16 (ins->inst_imm)) { - s390_lhi (code, s390_r13, ins->inst_imm); - s390_lr (code, s390_r0, ins->sreg1); - } else { - s390_basr (code, s390_r13, 0); - s390_j (code, 4); - s390_word (code, ins->inst_imm); - s390_lr (code, s390_r0, ins->sreg1); - s390_l (code, s390_r13, 0, s390_r13, 4); - } - s390_srda (code, s390_r0, 0, 32); - s390_dr (code, s390_r0, s390_r13); - s390_lr (code, ins->dreg, s390_r1); - } - break; - case CEE_REM: { + case OP_IREM: { s390_lr (code, s390_r0, ins->sreg1); s390_srda (code, s390_r0, 0, 32); s390_dr (code, s390_r0, ins->sreg2); s390_lr (code, ins->dreg, s390_r0); break; - case CEE_REM_UN: + case OP_IREM_UN: s390_lr (code, s390_r0, ins->sreg1); s390_srdl (code, s390_r0, 0, 32); s390_dlr (code, s390_r0, ins->sreg2); s390_lr (code, ins->dreg, s390_r0); } break; - case OP_REM_IMM: { - if (s390_is_imm16 (ins->inst_imm)) { - s390_lhi (code, s390_r13, ins->inst_imm); - s390_lr (code, s390_r0, ins->sreg1); - } else { - s390_basr (code, s390_r13, 0); - s390_j (code, 4); - s390_word (code, ins->inst_imm); - s390_lr (code, s390_r0, ins->sreg1); - s390_l (code, s390_r13, 0, s390_r13, 4); - } - s390_srda (code, s390_r0, 0, 32); - s390_dr (code, s390_r0, s390_r13); - s390_lr (code, ins->dreg, s390_r0); - } - break; - case CEE_OR: { + case OP_IOR: { if (ins->sreg1 == ins->dreg) { s390_or (code, ins->dreg, ins->sreg2); } @@ -3089,7 +3274,8 @@ mono_arch_output_basic_block (MonoCompile *cfg, MonoBasicBlock *bb) } } break; - case OP_OR_IMM: { + case OP_OR_IMM: + case OP_IOR_IMM: { if (s390_is_imm16 (ins->inst_imm)) { s390_lhi (code, s390_r0, ins->inst_imm); if (ins->dreg != ins->sreg1) { @@ -3107,7 +3293,7 @@ mono_arch_output_basic_block (MonoCompile *cfg, MonoBasicBlock *bb) } } break; - case CEE_XOR: { + case OP_IXOR: { if (ins->sreg1 == ins->dreg) { s390_xr (code, ins->dreg, ins->sreg2); } @@ -3122,7 +3308,8 @@ mono_arch_output_basic_block (MonoCompile *cfg, MonoBasicBlock *bb) } } break; - case OP_XOR_IMM: { + case OP_XOR_IMM: + case OP_IXOR_IMM: { if (s390_is_imm16 (ins->inst_imm)) { s390_lhi (code, s390_r0, ins->inst_imm); if (ins->dreg != ins->sreg1) { @@ -3140,43 +3327,46 @@ mono_arch_output_basic_block (MonoCompile *cfg, MonoBasicBlock *bb) } } break; - case CEE_SHL: { + case OP_ISHL: { CHECK_SRCDST_NCOM; s390_sll (code, ins->dreg, src2, 0); } break; - case OP_SHL_IMM: { + case OP_SHL_IMM: + case OP_ISHL_IMM: { if (ins->sreg1 != ins->dreg) { s390_lr (code, ins->dreg, ins->sreg1); } s390_sll (code, ins->dreg, 0, (ins->inst_imm & 0x1f)); } break; - case CEE_SHR: { + case OP_ISHR: { CHECK_SRCDST_NCOM; s390_sra (code, ins->dreg, src2, 0); } break; - case OP_SHR_IMM: { + case OP_SHR_IMM: + case OP_ISHR_IMM: { if (ins->sreg1 != ins->dreg) { s390_lr (code, ins->dreg, ins->sreg1); } s390_sra (code, ins->dreg, 0, (ins->inst_imm & 0x1f)); } break; - case OP_SHR_UN_IMM: { + case OP_SHR_UN_IMM: + case OP_ISHR_UN_IMM: { if (ins->sreg1 != ins->dreg) { s390_lr (code, ins->dreg, ins->sreg1); } s390_srl (code, ins->dreg, 0, (ins->inst_imm & 0x1f)); } break; - case CEE_SHR_UN: { + case OP_ISHR_UN: { CHECK_SRCDST_NCOM; s390_srl (code, ins->dreg, src2, 0); } break; - case CEE_NOT: { + case OP_INOT: { if (ins->sreg1 != ins->dreg) { s390_lr (code, ins->dreg, ins->sreg1); } @@ -3184,11 +3374,20 @@ mono_arch_output_basic_block (MonoCompile *cfg, MonoBasicBlock *bb) s390_xr (code, ins->dreg, s390_r0); } break; - case CEE_NEG: { + case OP_INEG: { + s390_lcr (code, ins->dreg, ins->sreg1); + } + break; + case OP_S390_LNEG: { + /* From gcc code */ + g_assert (ins->dreg + 1 != ins->sreg1); + s390_lcr (code, ins->dreg + 1, ins->sreg2); s390_lcr (code, ins->dreg, ins->sreg1); + s390_je (code, 3); + s390_bctr (code, ins->dreg + 1, 0); } break; - case CEE_MUL: { + case OP_IMUL: { if (ins->sreg1 == ins->dreg) { s390_msr (code, ins->dreg, ins->sreg2); } @@ -3203,7 +3402,8 @@ mono_arch_output_basic_block (MonoCompile *cfg, MonoBasicBlock *bb) } } break; - case OP_MUL_IMM: { + case OP_MUL_IMM: + case OP_IMUL_IMM: { if (s390_is_imm16 (ins->inst_imm)) { s390_lhi (code, s390_r13, ins->inst_imm); } else { @@ -3221,7 +3421,7 @@ mono_arch_output_basic_block (MonoCompile *cfg, MonoBasicBlock *bb) s390_msr (code, ins->dreg, s390_r13); } break; - case CEE_MUL_OVF: { + case OP_IMUL_OVF: { short int *o[2]; s390_ltr (code, s390_r1, ins->sreg1); s390_jz (code, 0); CODEPTR(code, o[0]); @@ -3240,7 +3440,7 @@ mono_arch_output_basic_block (MonoCompile *cfg, MonoBasicBlock *bb) s390_lr (code, ins->dreg, s390_r1); } break; - case CEE_MUL_OVF_UN: { + case OP_IMUL_OVF_UN: { s390_lhi (code, s390_r0, 0); s390_lr (code, s390_r1, ins->sreg1); s390_mlr (code, s390_r0, ins->sreg2); @@ -3284,8 +3484,17 @@ mono_arch_output_basic_block (MonoCompile *cfg, MonoBasicBlock *bb) s390_l (code,ins->dreg, 0, s390_r13, 4); } break; - case CEE_CONV_I4: - case CEE_CONV_U4: + case OP_JUMP_TABLE: { + mono_add_patch_info (cfg, code - cfg->native_code, + (MonoJumpInfoType)ins->inst_i1, ins->inst_p0); + s390_basr (code, s390_r13, 0); + s390_j (code, 4); + s390_word (code, 0); + s390_l (code, ins->dreg, 0, s390_r13, 4); + } + break; + case OP_ICONV_TO_I4: + case OP_ICONV_TO_U4: case OP_MOVE: { if (ins->dreg != ins->sreg1) { s390_lr (code, ins->dreg, ins->sreg1); @@ -3328,12 +3537,17 @@ mono_arch_output_basic_block (MonoCompile *cfg, MonoBasicBlock *bb) } break; case OP_FCONV_TO_R4: { + // FIXME: + if (ins->dreg != ins->sreg1) { + s390_ldr (code, ins->dreg, ins->sreg1); + } + /* NOT_IMPLEMENTED; - next = mono_inst_list_next (&ins->node, &bb->ins_list); - if ((next) && - (next->opcode != OP_FMOVE) && - (next->opcode != OP_STORER4_MEMBASE_REG)) + if ((ins->next) && + (ins->next->opcode != OP_FMOVE) && + (ins->next->opcode != OP_STORER4_MEMBASE_REG)) s390_ledbr (code, ins->dreg, ins->sreg1); + */ } break; case OP_JMP: { @@ -3387,8 +3601,9 @@ mono_arch_output_basic_block (MonoCompile *cfg, MonoBasicBlock *bb) break; case OP_LCALL: case OP_VCALL: + case OP_VCALL2: case OP_VOIDCALL: - case CEE_CALL: { + case OP_CALL: { call = (MonoCallInst*)ins; if (ins->flags & MONO_INST_HAS_METHOD) mono_add_patch_info (cfg, offset, MONO_PATCH_INFO_METHOD, call->method); @@ -3407,31 +3622,39 @@ mono_arch_output_basic_block (MonoCompile *cfg, MonoBasicBlock *bb) break; case OP_LCALL_REG: case OP_VCALL_REG: + case OP_VCALL2_REG: case OP_VOIDCALL_REG: case OP_CALL_REG: { s390_lr (code, s390_r1, ins->sreg1); s390_basr (code, s390_r14, s390_r1); } break; - case OP_FCALL_MEMBASE: { - call = (MonoCallInst*)ins; - s390_l (code, s390_r1, 0, ins->sreg1, ins->inst_offset); - s390_basr (code, s390_r14, s390_r1); - if (call->signature->ret->type == MONO_TYPE_R4) - s390_ldebr (code, s390_f0, s390_f0); - } - break; case OP_LCALL_MEMBASE: case OP_VCALL_MEMBASE: + case OP_VCALL2_MEMBASE: case OP_VOIDCALL_MEMBASE: + case OP_FCALL_MEMBASE: case OP_CALL_MEMBASE: { - s390_l (code, s390_r1, 0, ins->sreg1, ins->inst_offset); + call = (MonoCallInst*)ins; + if (s390_is_uimm12(ins->inst_offset)) + s390_l (code, s390_r1, 0, ins->inst_basereg, ins->inst_offset); + else { + if (s390_is_imm16(ins->inst_offset)) { + s390_lhi (code, s390_r13, ins->inst_offset); + s390_l (code, s390_r1, s390_r13, ins->inst_basereg, 0); + } else { + s390_basr (code, s390_r13, 0); + s390_j (code, 4); + s390_word (code, ins->inst_offset); + s390_l (code, s390_r13, 0, s390_r13, 4); + s390_l (code, s390_r1, s390_r13, ins->inst_basereg, 0); + } + } s390_basr (code, s390_r14, s390_r1); + if (ins->opcode == OP_FCALL_MEMBASE && call->signature->ret->type == MONO_TYPE_R4) + s390_ldebr (code, s390_f0, s390_f0); } break; - case OP_OUTARG: - g_assert_not_reached (); - break; case OP_LOCALLOC: { /*------------------------------------------*/ /* To allocate space on the stack we have */ @@ -3499,48 +3722,51 @@ mono_arch_output_basic_block (MonoCompile *cfg, MonoBasicBlock *bb) } break; case OP_START_HANDLER: { - if (s390_is_uimm12 (ins->inst_left->inst_offset)) { + MonoInst *spvar = mono_find_spvar_for_region (cfg, bb->region); + if (s390_is_uimm12 (spvar->inst_offset)) { s390_st (code, s390_r14, 0, - ins->inst_left->inst_basereg, - ins->inst_left->inst_offset); + spvar->inst_basereg, + spvar->inst_offset); } else { s390_basr (code, s390_r13, 0); s390_j (code, 4); - s390_word (code, ins->inst_left->inst_offset); + s390_word (code, spvar->inst_offset); s390_l (code, s390_r13, 0, s390_r13, 4); s390_st (code, s390_r14, s390_r13, - ins->inst_left->inst_basereg, 0); + spvar->inst_basereg, 0); } } break; case OP_ENDFILTER: { + MonoInst *spvar = mono_find_spvar_for_region (cfg, bb->region); if (ins->sreg1 != s390_r2) s390_lr (code, s390_r2, ins->sreg1); - if (s390_is_uimm12 (ins->inst_left->inst_offset)) { - s390_l (code, s390_r14, 0, ins->inst_left->inst_basereg, - ins->inst_left->inst_offset); + if (s390_is_uimm12 (spvar->inst_offset)) { + s390_l (code, s390_r14, 0, spvar->inst_basereg, + spvar->inst_offset); } else { s390_basr (code, s390_r13, 0); s390_j (code, 4); - s390_word (code, ins->inst_left->inst_offset); + s390_word (code, spvar->inst_offset); s390_l (code, s390_r13, 0, s390_r13, 4); s390_l (code, s390_r14, s390_r13, - ins->inst_left->inst_basereg, 0); + spvar->inst_basereg, 0); } s390_br (code, s390_r14); } break; case OP_ENDFINALLY: { - if (s390_is_uimm12 (ins->inst_left->inst_offset)) { - s390_l (code, s390_r14, 0, ins->inst_left->inst_basereg, - ins->inst_left->inst_offset); + MonoInst *spvar = mono_find_spvar_for_region (cfg, bb->region); + if (s390_is_uimm12 (spvar->inst_offset)) { + s390_l (code, s390_r14, 0, spvar->inst_basereg, + spvar->inst_offset); } else { s390_basr (code, s390_r13, 0); s390_j (code, 4); - s390_word (code, ins->inst_left->inst_offset); + s390_word (code, spvar->inst_offset); s390_l (code, s390_r13, 0, s390_r13, 4); s390_l (code, s390_r14, s390_r13, - ins->inst_left->inst_basereg, 0); + spvar->inst_basereg, 0); } s390_br (code, s390_r14); } @@ -3549,10 +3775,19 @@ mono_arch_output_basic_block (MonoCompile *cfg, MonoBasicBlock *bb) mono_add_patch_info (cfg, code-cfg->native_code, MONO_PATCH_INFO_BB, ins->inst_target_bb); s390_brasl (code, s390_r14, 0); + mono_cfg_add_try_hole (cfg, ins->inst_eh_block, code, bb); } break; case OP_LABEL: { ins->inst_c0 = code - cfg->native_code; + } + break; + case OP_RELAXED_NOP: + case OP_NOP: + case OP_DUMMY_USE: + case OP_DUMMY_STORE: + case OP_NOT_REACHED: + case OP_NOT_NULL: { } break; case OP_BR: @@ -3562,90 +3797,109 @@ mono_arch_output_basic_block (MonoCompile *cfg, MonoBasicBlock *bb) s390_br (code, ins->sreg1); } break; - case OP_CEQ: { + case OP_CEQ: + case OP_ICEQ: { s390_lhi (code, ins->dreg, 1); s390_jz (code, 4); s390_lhi (code, ins->dreg, 0); } break; - case OP_CLT: { + case OP_CLT: + case OP_ICLT: { s390_lhi (code, ins->dreg, 1); s390_jl (code, 4); s390_lhi (code, ins->dreg, 0); } break; - case OP_CLT_UN: { + case OP_CLT_UN: + case OP_ICLT_UN: { s390_lhi (code, ins->dreg, 1); s390_jlo (code, 4); s390_lhi (code, ins->dreg, 0); } break; - case OP_CGT: { + case OP_CGT: + case OP_ICGT: { s390_lhi (code, ins->dreg, 1); s390_jh (code, 4); s390_lhi (code, ins->dreg, 0); } break; - case OP_CGT_UN: { + case OP_CGT_UN: + case OP_ICGT_UN: { s390_lhi (code, ins->dreg, 1); s390_jho (code, 4); s390_lhi (code, ins->dreg, 0); } break; case OP_COND_EXC_EQ: + case OP_COND_EXC_IEQ: EMIT_COND_SYSTEM_EXCEPTION (S390_CC_EQ, ins->inst_p1); break; case OP_COND_EXC_NE_UN: + case OP_COND_EXC_INE_UN: EMIT_COND_SYSTEM_EXCEPTION (S390_CC_NE, ins->inst_p1); break; case OP_COND_EXC_LT: + case OP_COND_EXC_ILT: case OP_COND_EXC_LT_UN: + case OP_COND_EXC_ILT_UN: EMIT_COND_SYSTEM_EXCEPTION (S390_CC_LT, ins->inst_p1); break; case OP_COND_EXC_GT: + case OP_COND_EXC_IGT: case OP_COND_EXC_GT_UN: + case OP_COND_EXC_IGT_UN: EMIT_COND_SYSTEM_EXCEPTION (S390_CC_GT, ins->inst_p1); break; case OP_COND_EXC_GE: + case OP_COND_EXC_IGE: case OP_COND_EXC_GE_UN: + case OP_COND_EXC_IGE_UN: EMIT_COND_SYSTEM_EXCEPTION (S390_CC_GE, ins->inst_p1); break; case OP_COND_EXC_LE: + case OP_COND_EXC_ILE: case OP_COND_EXC_LE_UN: + case OP_COND_EXC_ILE_UN: EMIT_COND_SYSTEM_EXCEPTION (S390_CC_LE, ins->inst_p1); break; case OP_COND_EXC_OV: + case OP_COND_EXC_IOV: EMIT_COND_SYSTEM_EXCEPTION (S390_CC_OV, ins->inst_p1); break; case OP_COND_EXC_NO: + case OP_COND_EXC_INO: EMIT_COND_SYSTEM_EXCEPTION (S390_CC_NO, ins->inst_p1); break; case OP_COND_EXC_C: + case OP_COND_EXC_IC: EMIT_COND_SYSTEM_EXCEPTION (S390_CC_CY, ins->inst_p1); break; case OP_COND_EXC_NC: + case OP_COND_EXC_INC: EMIT_COND_SYSTEM_EXCEPTION (S390_CC_NC, ins->inst_p1); break; - case CEE_BEQ: + case OP_IBEQ: EMIT_COND_BRANCH (ins, S390_CC_EQ); break; - case CEE_BNE_UN: + case OP_IBNE_UN: EMIT_COND_BRANCH (ins, S390_CC_NE); break; - case CEE_BLT: - case CEE_BLT_UN: + case OP_IBLT: + case OP_IBLT_UN: EMIT_COND_BRANCH (ins, S390_CC_LT); break; - case CEE_BGT: - case CEE_BGT_UN: + case OP_IBGT: + case OP_IBGT_UN: EMIT_COND_BRANCH (ins, S390_CC_GT); break; - case CEE_BGE: - case CEE_BGE_UN: + case OP_IBGE: + case OP_IBGE_UN: EMIT_COND_BRANCH (ins, S390_CC_GE); break; - case CEE_BLE: - case CEE_BLE_UN: + case OP_IBLE: + case OP_IBLE_UN: EMIT_COND_BRANCH (ins, S390_CC_LE); break; @@ -3724,7 +3978,7 @@ mono_arch_output_basic_block (MonoCompile *cfg, MonoBasicBlock *bb) } } break; - case CEE_CONV_R_UN: { + case OP_ICONV_TO_R_UN: { s390_cdfbr (code, ins->dreg, ins->sreg1); s390_ltr (code, ins->sreg1, ins->sreg1); s390_jnl (code, 12); @@ -3735,11 +3989,11 @@ mono_arch_output_basic_block (MonoCompile *cfg, MonoBasicBlock *bb) s390_adb (code, ins->dreg, 0, s390_r13, 4); } break; - case CEE_CONV_R4: { + case OP_ICONV_TO_R4: { s390_cdfbr (code, ins->dreg, ins->sreg1); } break; - case CEE_CONV_R8: { + case OP_ICONV_TO_R8: { s390_cdfbr (code, ins->dreg, ins->sreg1); } break; @@ -3772,7 +4026,8 @@ mono_arch_output_basic_block (MonoCompile *cfg, MonoBasicBlock *bb) g_assert_not_reached (); /* Implemented as helper calls */ break; - case OP_LCONV_TO_OVF_I: { + case OP_LCONV_TO_OVF_I: + case OP_LCONV_TO_OVF_I4_2: { /* Valid ints: 0xffffffff:8000000 to 00000000:0x7f000000 */ short int *o[5]; s390_ltr (code, ins->sreg1, ins->sreg1); @@ -3782,8 +4037,6 @@ mono_arch_output_basic_block (MonoCompile *cfg, MonoBasicBlock *bb) s390_lhi (code, s390_r13, -1); s390_cr (code, ins->sreg2, s390_r13); s390_jnz (code, 0); CODEPTR(code, o[2]); - if (ins->dreg != ins->sreg1) - s390_lr (code, ins->dreg, ins->sreg1); s390_j (code, 0); CODEPTR(code, o[3]); PTRSLOT(code, o[0]); s390_ltr (code, ins->sreg2, ins->sreg2); @@ -3795,6 +4048,8 @@ mono_arch_output_basic_block (MonoCompile *cfg, MonoBasicBlock *bb) s390_brasl (code, s390_r14, 0); PTRSLOT(code, o[3]); PTRSLOT(code, o[4]); + if (ins->dreg != ins->sreg1) + s390_lr (code, ins->dreg, ins->sreg1); } break; case OP_SQRT: { @@ -3936,34 +4191,39 @@ mono_arch_output_basic_block (MonoCompile *cfg, MonoBasicBlock *bb) s390_mvc (code, ins->backend.size, ins->dreg, ins->inst_offset, ins->sreg1, ins->inst_imm); } else { - s390_lr (code, s390_r0, ins->dreg); + s390_lr (code, s390_r0, ins->dreg); if (s390_is_imm16 (ins->inst_offset)) { s390_ahi (code, s390_r0, ins->inst_offset); } else { s390_basr (code, s390_r13, 0); - s390_j (code, 4); - s390_word (code, ins->inst_offset); + s390_j (code, 6); + s390_long (code, ins->inst_offset); s390_a (code, s390_r0, 0, s390_r13, 4); } - s390_lr (code, s390_r14, s390_r12); - s390_lr (code, s390_r12, ins->sreg1); + s390_lr (code, s390_r12, ins->sreg1); if (s390_is_imm16 (ins->inst_imm)) { s390_ahi (code, s390_r12, ins->inst_imm); } else { s390_basr (code, s390_r13, 0); - s390_j (code, 4); - s390_word (code, ins->inst_imm); + s390_j (code, 6); + s390_long (code, ins->inst_imm); s390_a (code, s390_r12, 0, s390_r13, 4); } - s390_lr (code, s390_r1, ins->sreg1); + if (s390_is_imm16 (ins->backend.size)) { + s390x_lhi (code, s390_r1, ins->backend.size); + } else { + s390_basr (code, s390_r13, 0); + s390_j (code, 6); + s390_long (code, ins->backend.size); + s390_l (code, s390_r1, 0, s390_r13, 4); + } + s390_lr (code, s390_r1, ins->backend.size); s390_lr (code, s390_r13, s390_r1); s390_mvcle(code, s390_r0, s390_r12, 0, 0); s390_jo (code, -2); - s390_lr (code, s390_r12, s390_r14); } } } - break; case OP_ATOMIC_ADD_I4: { s390_lr (code, s390_r1, ins->sreg2); s390_l (code, s390_r0, 0, ins->inst_basereg, ins->inst_offset); @@ -4016,6 +4276,7 @@ mono_arch_output_basic_block (MonoCompile *cfg, MonoBasicBlock *bb) cpos += max_len; + last_ins = ins; last_offset = offset; } @@ -4052,7 +4313,7 @@ mono_arch_register_lowlevel_calls (void) void mono_arch_patch_code (MonoMethod *method, MonoDomain *domain, - guint8 *code, MonoJumpInfo *ji, gboolean run_cctors) + guint8 *code, MonoJumpInfo *ji, MonoCodeManager *dyn_code_mp, gboolean run_cctors) { MonoJumpInfo *patch_info; @@ -4117,23 +4378,22 @@ mono_arch_patch_code (MonoMethod *method, MonoDomain *domain, /*------------------------------------------------------------------*/ guint8 * -emit_load_volatile_registers(guint8 * code, MonoCompile *cfg) +emit_load_volatile_registers (guint8 * code, MonoCompile *cfg) { MonoMethod *method = cfg->method; MonoMethodSignature *sig; MonoInst *inst; int pos, i; CallInfo *cinfo; - size_data sz; sig = mono_method_signature (method); pos = 0; - cinfo = calculate_sizes (NULL, sig, &sz, sig->pinvoke); + cinfo = get_call_info (cfg, cfg->mempool, sig, sig->pinvoke); if (cinfo->struct_ret) { ArgInfo *ainfo = &cinfo->ret; - inst = cfg->ret; + inst = cfg->vret_addr; s390_l (code, ainfo->reg, 0, inst->inst_basereg, inst->inst_offset); } @@ -4209,8 +4469,6 @@ emit_load_volatile_registers(guint8 * code, MonoCompile *cfg) pos++; } - g_free (cinfo); - return code; } @@ -4235,18 +4493,20 @@ mono_arch_emit_prolog (MonoCompile *cfg) int alloc_size, pos, max_offset, i; guint8 *code; CallInfo *cinfo; - size_data sz; int tracing = 0; int lmfOffset; \ if (mono_jit_trace_calls != NULL && mono_trace_eval (method)) tracing = 1; - cfg->code_size = 512; + cfg->code_size = 1024; cfg->native_code = code = g_malloc (cfg->code_size); s390_stm (code, s390_r6, s390_r14, STK_BASE, S390_REG_SAVE_OFFSET); + if (cfg->arch.bkchain_reg != -1) + s390_lr (code, cfg->arch.bkchain_reg, STK_BASE); + if (cfg->flags & MONO_CFG_HAS_ALLOCA) { cfg->used_int_regs |= 1 << 11; } @@ -4276,7 +4536,7 @@ mono_arch_emit_prolog (MonoCompile *cfg) */ max_offset = 0; for (bb = cfg->bb_entry; bb; bb = bb->next_bb) { - MonoInst *ins; + MonoInst *ins = bb->code; bb->max_offset = max_offset; if (cfg->prof_options & MONO_PROFILE_COVERAGE) @@ -4290,11 +4550,11 @@ mono_arch_emit_prolog (MonoCompile *cfg) sig = mono_method_signature (method); pos = 0; - cinfo = calculate_sizes (cfg, sig, &sz, sig->pinvoke); + cinfo = get_call_info (cfg, cfg->mempool, sig, sig->pinvoke); if (cinfo->struct_ret) { ArgInfo *ainfo = &cinfo->ret; - inst = cfg->ret; + inst = cfg->vret_addr; inst->backend.size = ainfo->vtsize; s390_st (code, ainfo->reg, 0, inst->inst_basereg, inst->inst_offset); } @@ -4303,6 +4563,9 @@ mono_arch_emit_prolog (MonoCompile *cfg) ArgInfo *ainfo = cinfo->args + i; inst = cfg->args [pos]; + if (inst->opcode == OP_VTARG_ADDR) + inst = inst->inst_left; + if (inst->opcode == OP_REGVAR) { if (ainfo->regtype == RegTypeGeneral) s390_lr (code, inst->dreg, ainfo->reg); @@ -4483,7 +4746,8 @@ mono_arch_emit_prolog (MonoCompile *cfg) code = mono_arch_instrument_prolog(cfg, enter_method, code, TRUE); cfg->code_len = code - cfg->native_code; - g_free (cinfo); + + g_assert (cfg->code_len < cfg->code_size); return code; } @@ -4711,46 +4975,48 @@ mono_arch_setup_jit_tls_data (MonoJitTlsData *tls) void mono_arch_free_jit_tls_data (MonoJitTlsData *tls) { +} + +/*========================= End of Function ========================*/ +/*------------------------------------------------------------------*/ +/* */ +/* Name - mono_arch_emit_inst_for_method */ +/* */ +/*------------------------------------------------------------------*/ + +MonoInst* +mono_arch_emit_inst_for_method (MonoCompile *cfg, MonoMethod *cmethod, MonoMethodSignature *fsig, MonoInst **args) +{ + return NULL; } /*========================= End of Function ========================*/ /*------------------------------------------------------------------*/ /* */ -/* Name - mono_arch_emit_this_vret_args */ +/* Name - mono_arch_decompose_opts */ /* */ -/* Function - */ -/* */ /*------------------------------------------------------------------*/ void -mono_arch_emit_this_vret_args (MonoCompile *cfg, MonoCallInst *inst, int this_reg, int this_type, int vt_reg) +mono_arch_decompose_opts (MonoCompile *cfg, MonoInst *ins) { - int this_dreg = s390_r2; - - if (vt_reg != -1) - this_dreg = s390_r3; - - /* 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, inst, this->dreg, this_dreg, FALSE); - } - - if (vt_reg != -1) { - MonoInst *vtarg; - MONO_INST_NEW (cfg, vtarg, OP_MOVE); - vtarg->type = STACK_MP; - vtarg->sreg1 = vt_reg; - vtarg->dreg = mono_regstate_next_int (cfg->rs); - mono_bblock_add_inst (cfg->cbb, vtarg); - mono_call_inst_add_outarg_reg (cfg, inst, vtarg->dreg, s390_r2, FALSE); + switch (ins->opcode) { + case OP_ISUB_OVF: + ins->opcode = OP_S390_ISUB_OVF; + break; + case OP_ISUB_OVF_UN: + ins->opcode = OP_S390_ISUB_OVF_UN; + break; + case OP_IADD_OVF: + ins->opcode = OP_S390_IADD_OVF; + break; + case OP_IADD_OVF_UN: + ins->opcode = OP_S390_IADD_OVF_UN; + break; + default: + break; } } @@ -4758,66 +5024,83 @@ mono_arch_emit_this_vret_args (MonoCompile *cfg, MonoCallInst *inst, int this_re /*------------------------------------------------------------------*/ /* */ -/* Name - mono_arch_get_inst_for_method */ +/* Name - mono_arch_decompose_long_opts */ /* */ -/* Function - Check for opcodes we can handle directly in */ -/* hardware. */ -/* */ /*------------------------------------------------------------------*/ -MonoInst* -mono_arch_get_inst_for_method (MonoCompile *cfg, MonoMethod *cmethod, - MonoMethodSignature *fsig, MonoInst **args) +void +mono_arch_decompose_long_opts (MonoCompile *cfg, MonoInst *ins) { - MonoInst *ins = NULL; - - if (cmethod->klass == mono_defaults.math_class) { - if (strcmp (cmethod->name, "Sqrt") == 0) { - MONO_INST_NEW (cfg, ins, OP_SQRT); - ins->inst_i0 = args [0]; - } - } else if (cmethod->klass == mono_defaults.thread_class && - strcmp (cmethod->name, "MemoryBarrier") == 0) { - MONO_INST_NEW (cfg, ins, OP_MEMORY_BARRIER); - } else if(cmethod->klass->image == mono_defaults.corlib && - (strcmp (cmethod->klass->name_space, "System.Threading") == 0) && - (strcmp (cmethod->klass->name, "Interlocked") == 0)) { - - if (strcmp (cmethod->name, "Increment") == 0 && - fsig->params [0]->type == MONO_TYPE_I4) { - MonoInst *ins_iconst; - - MONO_INST_NEW (cfg, ins, OP_ATOMIC_ADD_NEW_I4); - MONO_INST_NEW (cfg, ins_iconst, OP_ICONST); - ins_iconst->inst_c0 = 1; - - ins->inst_i0 = args [0]; - ins->inst_i1 = ins_iconst; - } else if (strcmp (cmethod->name, "Decrement") == 0 && - fsig->params [0]->type == MONO_TYPE_I4) { - MonoInst *ins_iconst; - - MONO_INST_NEW (cfg, ins, OP_ATOMIC_ADD_NEW_I4); - MONO_INST_NEW (cfg, ins_iconst, OP_ICONST); - ins_iconst->inst_c0 = -1; - - ins->inst_i0 = args [0]; - ins->inst_i1 = ins_iconst; - } else if (strcmp (cmethod->name, "Exchange") == 0 && - fsig->params [0]->type == MONO_TYPE_I4) { - MONO_INST_NEW (cfg, ins, OP_ATOMIC_EXCHANGE_I4); - - ins->inst_i0 = args [0]; - ins->inst_i1 = args [1]; - } else if (strcmp (cmethod->name, "Add") == 0 && - fsig->params [0]->type == MONO_TYPE_I4) { - MONO_INST_NEW (cfg, ins, OP_ATOMIC_ADD_I4); - - ins->inst_i0 = args [0]; - ins->inst_i1 = args [1]; + // The generic code seems to work for OP_LSUB fine on s390, why is a different + // implementation needed ? gcc also seems to use the different implementation. + // FIXME: What about the other OP_L opcodes below ? + + switch (ins->opcode) { + case OP_LADD_OVF: + case OP_LADD_OVF_UN: + case OP_LSUB_OVF: + case OP_LSUB_OVF_UN: { + int opcode = 0; + + switch (ins->opcode) { + case OP_LADD: + opcode = OP_S390_LADD; + break; + case OP_LADD_OVF: + opcode = OP_S390_LADD_OVF; + break; + case OP_LADD_OVF_UN: + opcode = OP_S390_LADD_OVF_UN; + break; + case OP_LSUB: + opcode = OP_S390_LSUB; + break; + case OP_LSUB_OVF: + opcode = OP_S390_LSUB_OVF; + break; + case OP_LSUB_OVF_UN: + opcode = OP_S390_LSUB_OVF_UN; + break; + default: + g_assert_not_reached (); } + + /* These hard regs make ssa crazy */ + cfg->disable_ssa = TRUE; + MONO_EMIT_NEW_UNALU (cfg, OP_MOVE, s390_r0, ins->sreg1 + 1); + MONO_EMIT_NEW_UNALU (cfg, OP_MOVE, s390_r1, ins->sreg1 + 2); + MONO_EMIT_NEW_BIALU (cfg, opcode, ins->dreg, ins->sreg2 + 1, ins->sreg2 + 2); + NULLIFY_INS (ins); + break; + } + case OP_LADD_IMM: { + int dreg = mono_alloc_dreg (cfg, STACK_I8); + MONO_EMIT_NEW_I8CONST (cfg, dreg, ins->inst_l); + MONO_EMIT_NEW_BIALU (cfg, OP_LADD, ins->dreg, ins->sreg1, dreg); + NULLIFY_INS (ins); + break; + } + case OP_LSUB_IMM: { + int dreg = mono_alloc_dreg (cfg, STACK_I8); + MONO_EMIT_NEW_I8CONST (cfg, dreg, ins->inst_l); + MONO_EMIT_NEW_BIALU (cfg, OP_LSUB, ins->dreg, ins->sreg1, dreg); + NULLIFY_INS (ins); + break; + } + case OP_LNEG: { + MONO_EMIT_NEW_BIALU (cfg, OP_S390_LNEG, ins->dreg, ins->sreg1 + 1, ins->sreg1 + 2); + NULLIFY_INS (ins); + break; + } + case OP_ISUB_OVF: + ins->opcode = OP_S390_ISUB_OVF; + break; + case OP_ISUB_OVF_UN: + ins->opcode = OP_S390_ISUB_OVF_UN; + break; + default: + break; } - return ins; } /*========================= End of Function ========================*/ @@ -4930,31 +5213,6 @@ mono_arch_get_domain_intrinsic (MonoCompile* cfg) /*========================= End of Function ========================*/ -/*------------------------------------------------------------------*/ -/* */ -/* Name - mono_arch_get_thread_intrinsic */ -/* */ -/* Function - */ -/* */ -/* Returns - */ -/* */ -/*------------------------------------------------------------------*/ - -MonoInst * -mono_arch_get_thread_intrinsic (MonoCompile* cfg) -{ - MonoInst *ins; - - if (thread_tls_offset == -1) - return NULL; - - MONO_INST_NEW (cfg, ins, OP_TLS_GET); - ins->inst_offset = thread_tls_offset; - return (ins); -} - -/*========================= End of Function ========================*/ - /*------------------------------------------------------------------*/ /* */ /* Name - mono_arch_flush_register_windows */ @@ -5008,3 +5266,23 @@ mono_arch_get_patch_offset (guint8 *code) } /*========================= End of Function ========================*/ + +/*------------------------------------------------------------------*/ +/* */ +/* Name - mono_arch_context_get_int_reg. */ +/* */ +/* Function - Dummy entry point until s390x supports aot. */ +/* */ +/* Returns - Pointer to intreg. */ +/* */ +/*------------------------------------------------------------------*/ + +gpointer +mono_arch_context_get_int_reg (MonoContext *ctx, int reg) +{ + /* FIXME: implement */ + g_assert_not_reached (); + return NULL; +} + +/*========================= End of Function ========================*/