Revert "Revert "Merge branch 'master' of https://github.com/mono/mono""
[mono.git] / mono / mini / mini-codegen.c
index facd18c2494f911a5b96710d0d7f5ed94a62546a..6e5bf2f8586b331670c76f02325d0cb7585f3d95 100644 (file)
@@ -101,6 +101,7 @@ static const int regbank_move_ops [] = {
 
 #define regmask(reg) (((regmask_t)1) << (reg))
 
+#ifdef MONO_ARCH_USE_SHARED_FP_SIMD_BANK
 static const regmask_t regbank_callee_saved_regs [] = {
        MONO_ARCH_CALLEE_SAVED_REGS,
        MONO_ARCH_CALLEE_SAVED_FREGS,
@@ -108,6 +109,7 @@ static const regmask_t regbank_callee_saved_regs [] = {
        MONO_ARCH_CALLEE_SAVED_REGS,
        MONO_ARCH_CALLEE_SAVED_XREGS,
 };
+#endif
 
 static const regmask_t regbank_callee_regs [] = {
        MONO_ARCH_CALLEE_REGS,
@@ -409,17 +411,23 @@ typedef struct {
        regmask_t preferred_mask; /* the hreg where the register should be allocated, or 0 */
 } RegTrack;
 
-#ifndef DISABLE_LOGGING
+#if !defined(DISABLE_LOGGING) && !defined(DISABLE_JIT)
 
-static void
-print_ji (MonoJumpInfo *ji)
+static const char* const patch_info_str[] = {
+#define PATCH_INFO(a,b) "" #a,
+#include "patch-info.h"
+#undef PATCH_INFO
+};
+
+void
+mono_print_ji (const MonoJumpInfo *ji)
 {
        switch (ji->type) {
        case MONO_PATCH_INFO_RGCTX_FETCH: {
                MonoJumpInfoRgctxEntry *entry = ji->data.rgctx_entry;
 
                printf ("[RGCTX_FETCH ");
-               print_ji (entry->data);
+               mono_print_ji (entry->data);
                printf (" - %s]", mono_rgctx_info_type_to_str (entry->info_type));
                break;
        }
@@ -430,7 +438,7 @@ print_ji (MonoJumpInfo *ji)
                break;
        }
        default:
-               printf ("[%d]", ji->type);
+               printf ("[%s]", patch_info_str [ji->type]);
                break;
        }
 }
@@ -447,9 +455,22 @@ mono_print_ins_index (int i, MonoInst *ins)
        else
                printf (" %s", mono_inst_name (ins->opcode));
        if (spec == MONO_ARCH_CPU_SPEC) {
+               gboolean dest_base = FALSE;
+               switch (ins->opcode) {
+               case OP_STOREV_MEMBASE:
+                       dest_base = TRUE;
+                       break;
+               default:
+                       break;
+               }
+
                /* This is a lowered opcode */
-               if (ins->dreg != -1)
-                       printf (" R%d <-", ins->dreg);
+               if (ins->dreg != -1) {
+                       if (dest_base)
+                               printf (" [R%d + 0x%lx] <-", ins->dreg, (long)ins->inst_offset);
+                       else
+                               printf (" R%d <-", ins->dreg);
+               }
                if (ins->sreg1 != -1)
                        printf (" R%d", ins->sreg1);
                if (ins->sreg2 != -1)
@@ -492,6 +513,7 @@ mono_print_ins_index (int i, MonoInst *ins)
                        printf (" R%d", ((MonoInst*)ins->inst_p0)->dreg);
                        break;
                case OP_REGOFFSET:
+               case OP_GSHAREDVT_ARG_REGOFFSET:
                        printf (" + 0x%lx", (long)ins->inst_offset);
                        break;
                default:
@@ -577,11 +599,8 @@ mono_print_ins_index (int i, MonoInst *ins)
        case OP_CALL_MEMBASE:
        case OP_CALL_REG:
        case OP_FCALL:
-       case OP_FCALLVIRT:
        case OP_LCALL:
-       case OP_LCALLVIRT:
        case OP_VCALL:
-       case OP_VCALLVIRT:
        case OP_VCALL_REG:
        case OP_VCALL_MEMBASE:
        case OP_VCALL2:
@@ -589,7 +608,6 @@ mono_print_ins_index (int i, MonoInst *ins)
        case OP_VCALL2_MEMBASE:
        case OP_VOIDCALL:
        case OP_VOIDCALL_MEMBASE:
-       case OP_VOIDCALLVIRT:
        case OP_TAILCALL: {
                MonoCallInst *call = (MonoCallInst*)ins;
                GSList *list;
@@ -611,7 +629,7 @@ mono_print_ins_index (int i, MonoInst *ins)
                        MonoJumpInfo *ji = (MonoJumpInfo*)call->fptr;
 
                        printf (" ");
-                       print_ji (ji);
+                       mono_print_ji (ji);
                } else if (call->fptr) {
                        MonoJitICallInfo *info = mono_find_jit_icall_by_addr (call->fptr);
                        if (info)
@@ -699,11 +717,17 @@ print_regtrack (RegTrack *t, int num)
        }
 }
 #else
+
+void
+mono_print_ji (const MonoJumpInfo *ji)
+{
+}
+
 void
 mono_print_ins_index (int i, MonoInst *ins)
 {
 }
-#endif /* DISABLE_LOGGING */
+#endif /* !defined(DISABLE_LOGGING) && !defined(DISABLE_JIT) */
 
 void
 mono_print_ins (MonoInst *ins)
@@ -808,7 +832,7 @@ get_register_spilling (MonoCompile *cfg, MonoBasicBlock *bb, MonoInst **last, Mo
 
        g_assert (bank < MONO_NUM_REGBANKS);
 
-       DEBUG (printf ("\tstart regmask to assign R%d: 0x%08" G_GUINT64_FORMAT " (R%d <- R%d R%d R%d)\n", reg, (guint64)regmask, ins->dreg, ins->sreg1, ins->sreg2, ins->sreg3));
+       DEBUG (printf ("\tstart regmask to assign R%d: 0x%08llu (R%d <- R%d R%d R%d)\n", reg, (unsigned long long)regmask, ins->dreg, ins->sreg1, ins->sreg2, ins->sreg3));
        /* exclude the registers in the current instruction */
        num_sregs = mono_inst_get_src_registers (ins, sregs);
        for (i = 0; i < num_sregs; ++i) {
@@ -825,7 +849,7 @@ get_register_spilling (MonoCompile *cfg, MonoBasicBlock *bb, MonoInst **last, Mo
                DEBUG (printf ("\t\texcluding dreg %s\n", mono_regname_full (ins->dreg, bank)));
        }
 
-       DEBUG (printf ("\t\tavailable regmask: 0x%08" G_GUINT64_FORMAT "\n", (guint64)regmask));
+       DEBUG (printf ("\t\tavailable regmask: 0x%08llu\n", (unsigned long long)regmask));
        g_assert (regmask); /* need at least a register we can free */
        sel = 0;
        /* we should track prev_use and spill the register that's farther */
@@ -1041,8 +1065,9 @@ assign_reg (MonoCompile *cfg, MonoRegState *rs, int reg, int hreg, int bank)
        else {
                g_assert (reg >= MONO_MAX_IREGS);
                g_assert (hreg < MONO_MAX_IREGS);
-#ifndef TARGET_ARM
+#if !defined(TARGET_ARM) && !defined(TARGET_ARM64)
                /* this seems to trigger a gcc compilation bug sometime (hreg is 0) */
+               /* On arm64, rgctx_reg is a global hreg, and it is used to pass an argument */
                g_assert (! is_global_ireg (hreg));
 #endif
 
@@ -1100,7 +1125,7 @@ mono_local_regalloc (MonoCompile *cfg, MonoBasicBlock *bb)
                desc_to_fixed_reg_inited = TRUE;
 
                /* Validate the cpu description against the info in mini-ops.h */
-#if defined(TARGET_AMD64) || defined(TARGET_X86) || defined(TARGET_ARM)
+#if defined(TARGET_AMD64) || defined(TARGET_X86) || defined(TARGET_ARM) || defined(TARGET_ARM64)
                for (i = OP_LOAD; i < OP_LAST; ++i) {
                        const char *ispec;
 
@@ -1777,7 +1802,7 @@ mono_local_regalloc (MonoCompile *cfg, MonoBasicBlock *bb)
                                                        continue;
 
                                                s = regmask (j);
-                                               if ((clob_mask & s) && !(rs->free_mask [cur_bank] & s) && (j != ins->sreg1)) {
+                                               if ((clob_mask & s) && !(rs->free_mask [cur_bank] & s)) {
                                                        if (j != dreg)
                                                                free_up_hreg (cfg, bb, tmp, ins, j, cur_bank);
                                                        else if (rs->symbolic [cur_bank] [j])
@@ -2328,6 +2353,8 @@ mono_opcode_to_cond (int opcode)
        case OP_CMOV_IEQ:
        case OP_CMOV_LEQ:
                return CMP_EQ;
+       case OP_FCNEQ:
+       case OP_ICNEQ:
        case OP_IBNE_UN:
        case OP_LBNE_UN:
        case OP_FBNE_UN:
@@ -2336,12 +2363,16 @@ mono_opcode_to_cond (int opcode)
        case OP_CMOV_INE_UN:
        case OP_CMOV_LNE_UN:
                return CMP_NE;
+       case OP_FCLE:
+       case OP_ICLE:
        case OP_IBLE:
        case OP_LBLE:
        case OP_FBLE:
        case OP_CMOV_ILE:
        case OP_CMOV_LLE:
                return CMP_LE;
+       case OP_FCGE:
+       case OP_ICGE:
        case OP_IBGE:
        case OP_LBGE:
        case OP_FBGE:
@@ -2373,6 +2404,7 @@ mono_opcode_to_cond (int opcode)
        case OP_CMOV_LGT:
                return CMP_GT;
 
+       case OP_ICLE_UN:
        case OP_IBLE_UN:
        case OP_LBLE_UN:
        case OP_FBLE_UN:
@@ -2381,6 +2413,8 @@ mono_opcode_to_cond (int opcode)
        case OP_CMOV_ILE_UN:
        case OP_CMOV_LLE_UN:
                return CMP_LE_UN;
+
+       case OP_ICGE_UN:
        case OP_IBGE_UN:
        case OP_LBGE_UN:
        case OP_FBGE_UN:
@@ -2684,4 +2718,27 @@ mono_peephole_ins (MonoBasicBlock *bb, MonoInst *ins)
        }
 }
 
+int
+mini_exception_id_by_name (const char *name)
+{
+       if (strcmp (name, "IndexOutOfRangeException") == 0)
+               return MONO_EXC_INDEX_OUT_OF_RANGE;
+       if (strcmp (name, "OverflowException") == 0)
+               return MONO_EXC_OVERFLOW;
+       if (strcmp (name, "ArithmeticException") == 0)
+               return MONO_EXC_ARITHMETIC;
+       if (strcmp (name, "DivideByZeroException") == 0)
+               return MONO_EXC_DIVIDE_BY_ZERO;
+       if (strcmp (name, "InvalidCastException") == 0)
+               return MONO_EXC_INVALID_CAST;
+       if (strcmp (name, "NullReferenceException") == 0)
+               return MONO_EXC_NULL_REF;
+       if (strcmp (name, "ArrayTypeMismatchException") == 0)
+               return MONO_EXC_ARRAY_TYPE_MISMATCH;
+       if (strcmp (name, "ArgumentException") == 0)
+               return MONO_EXC_ARGUMENT;
+       g_error ("Unknown intrinsic exception %s\n", name);
+       return -1;
+}
+
 #endif /* DISABLE_JIT */