[xbuild] Evaluate Import with MSBuildThisFile* properties set.
[mono.git] / mono / mini / mini-hppa.c
index 6f5f9243f2568cd6d3403093256f1d056d070ae2..264a86c78db9f018b6a613fb09695d4c0f3366cf 100644 (file)
 #include <mono/utils/mono-math.h>
 
 #include "mini-hppa.h"
-#include "inssel.h"
 #include "trace.h"
 #include "cpu-hppa.h"
 
-#define NOT_IMPLEMENTED do { g_assert_not_reached (); } while (0)
 #define ALIGN_TO(val,align) (((val) + ((align) - 1)) & ~((align) - 1))
 #define SIGNAL_STACK_SIZE (64 * 1024)
 
@@ -357,7 +355,7 @@ handle_enum:
                        
                case MONO_TYPE_VALUETYPE:
                        if (type->data.klass->enumtype) {
-                               type = type->data.klass->enum_basetype;
+                               type = mono_class_enum_basetype (type->data.klass);
                                goto handle_enum;
                        }
                        /* Fall through */
@@ -523,7 +521,7 @@ mono_arch_allocate_vars (MonoCompile *m)
        DEBUG_FUNC_ENTER();
        m->flags |= MONO_CFG_HAS_SPILLUP;
 
-       header = mono_method_get_header (m->method);
+       header = m->header;
 
        sig = mono_method_signature (m->method);
        DEBUG (printf ("Allocating locals - incoming params:\n"));
@@ -591,7 +589,7 @@ mono_arch_allocate_vars (MonoCompile *m)
                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);
                else
-                       size = mono_type_stack_size (inst->inst_vtype, &align);
+                       size = mini_type_stack_size (cfg->generic_sharing_context, inst->inst_vtype, &align);
 
                /* 
                 * This is needed since structures containing doubles must be doubleword 
@@ -779,8 +777,13 @@ mono_arch_call_opcode (MonoCompile *cfg, MonoBasicBlock* bb, MonoCallInst *call,
        return call;
 }
 
-static void
-peephole_pass (MonoCompile *cfg, MonoBasicBlock *bb)
+void
+mono_arch_peephole_pass_1 (MonoCompile *cfg, MonoBasicBlock *bb)
+{
+}
+
+void
+mono_arch_peephole_pass_2 (MonoCompile *cfg, MonoBasicBlock *bb)
 {
        DEBUG_FUNC_ENTER();
        DEBUG_FUNC_EXIT();
@@ -878,18 +881,13 @@ map_to_reg_reg_op (int op)
  * represented with very simple instructions with no register
  * requirements.
  */
-static void
+void
 mono_arch_lowering_pass (MonoCompile *cfg, MonoBasicBlock *bb)
 {
        MonoInst *ins, *next, *temp, *last_ins = NULL;
        int imm;
 
-       /* setup the virtual reg allocator */
-       if (bb->max_vreg > cfg->rs->next_vreg)
-               cfg->rs->next_vreg = bb->max_vreg;
-
-       ins = bb->code;
-       while (ins) {
+       MONO_BB_FOR_EACH_INS (bb, ins) {
 loop_start:
                switch (ins->opcode) {
                case OP_ADD_IMM:
@@ -897,7 +895,7 @@ loop_start:
                        if (!hppa_check_bits (ins->inst_imm, 11)) {
                                NEW_INS (cfg, temp, OP_ICONST);
                                temp->inst_c0 = ins->inst_imm;
-                               temp->dreg = mono_regstate_next_int (cfg->rs);
+                               temp->dreg = mono_alloc_ireg (cfg);
                                ins->sreg2 = temp->dreg;
                                ins->opcode = map_to_reg_reg_op (ins->opcode);
                        }
@@ -907,7 +905,7 @@ loop_start:
                        if (!hppa_check_bits (ins->inst_imm, 11)) {
                                NEW_INS (cfg, temp, OP_ICONST);
                                temp->inst_c0 = ins->inst_imm;
-                               temp->dreg = mono_regstate_next_int (cfg->rs);
+                               temp->dreg = mono_alloc_ireg (cfg);
                                ins->sreg2 = temp->dreg;
                                ins->opcode = map_to_reg_reg_op (ins->opcode);
                        }
@@ -930,7 +928,7 @@ loop_start:
                                break;
                        }
                        else {
-                               int tmp = mono_regstate_next_int (cfg->rs);
+                               int tmp = mono_alloc_ireg (cfg);
                                NEW_INS (cfg, temp, OP_ICONST);
                                temp->inst_c0 = ins->inst_c0;
                                temp->dreg = tmp;
@@ -943,8 +941,8 @@ loop_start:
                        break;
 
                case CEE_MUL: {
-                       int freg1 = mono_regstate_next_float (cfg->rs);
-                       int freg2 = mono_regstate_next_float (cfg->rs);
+                       int freg1 = mono_alloc_freg (cfg);
+                       int freg2 = mono_alloc_freg (cfg);
 
                        NEW_INS(cfg, temp, OP_STORE_MEMBASE_REG);
                        temp->sreg1 = ins->sreg1;
@@ -986,24 +984,12 @@ loop_start:
                        break;
                }
                last_ins = ins;
-               ins = ins->next;
        }
        bb->last_ins = last_ins;
-       bb->max_vreg = cfg->rs->next_vreg;
+       bb->max_vreg = cfg->next_vreg;
        
 }
 
-void
-mono_arch_local_regalloc (MonoCompile *cfg, MonoBasicBlock *bb)
-{
-       DEBUG_FUNC_ENTER();
-       if (!bb->code)
-               return;
-       mono_arch_lowering_pass (cfg, bb);
-       mono_local_regalloc (cfg, bb);
-       DEBUG_FUNC_EXIT();
-}
-
 void
 hppa_patch (guint32 *code, const gpointer target)
 {
@@ -1126,7 +1112,7 @@ emit_memcpy (guint32 *code, int doff, int dreg, int soff, int sreg, int size)
  *  Determine the vtable slot used by a virtual call.
  */
 gpointer*
-mono_arch_get_vcall_slot_addr (guint8 *code8, gpointer *regs)
+mono_arch_get_vcall_slot_addr (guint8 *code8, mgreg_t *regs)
 {
        guint32 *code = (guint32*)((unsigned long)code8 & ~3);
 
@@ -1168,21 +1154,13 @@ mono_arch_get_vcall_slot_addr (guint8 *code8, gpointer *regs)
 } while (0)
 
 #define EMIT_COND_BRANCH_FLAGS(ins,r1,r2,b0,b1) do {\
-       if (ins->flags & MONO_INST_BRLABEL) { \
-               mono_add_patch_info (cfg, (guint8*)code - cfg->native_code, MONO_PATCH_INFO_LABEL, ins->inst_i0); \
-               if (b0) \
-                       hppa_combt (code, r1, r2, b1, 0); \
-               else \
-                       hppa_combf (code, r1, r2, b1, 0); \
-       } else { \
-               if (b0) \
-                       hppa_combf (code, r1, r2, b1, 2); \
-               else \
-                       hppa_combt (code, r1, r2, b1, 2); \
-               hppa_nop (code); \
-               mono_add_patch_info (cfg, (guint8*)code - cfg->native_code, MONO_PATCH_INFO_BB, ins->inst_true_bb); \
-               hppa_bl (code, 0, hppa_r0); \
-       } \
+       if (b0) \
+               hppa_combf (code, r1, r2, b1, 2); \
+       else \
+               hppa_combt (code, r1, r2, b1, 2); \
+       hppa_nop (code); \
+       mono_add_patch_info (cfg, (guint8*)code - cfg->native_code, MONO_PATCH_INFO_BB, ins->inst_true_bb); \
+       hppa_bl (code, 0, hppa_r0); \
        hppa_nop (code); \
 } while (0)
 
@@ -1191,10 +1169,7 @@ mono_arch_get_vcall_slot_addr (guint8 *code8, gpointer *regs)
 #define EMIT_FLOAT_COND_BRANCH_FLAGS(ins,r1,r2,b0) do {\
        hppa_fcmp (code, HPPA_FP_FMT_DBL, b0, r1, r2); \
        hppa_ftest (code, 0); \
-       if (ins->flags & MONO_INST_BRLABEL) \
-               mono_add_patch_info (cfg, (guint8*)code - cfg->native_code, MONO_PATCH_INFO_LABEL, ins->inst_i0); \
-       else \
-               mono_add_patch_info (cfg, (guint8*)code - cfg->native_code, MONO_PATCH_INFO_BB, ins->inst_true_bb); \
+       mono_add_patch_info (cfg, (guint8*)code - cfg->native_code, MONO_PATCH_INFO_BB, ins->inst_true_bb); \
        hppa_bl (code, 8, hppa_r0); \
        hppa_nop (code); \
 } while (0)
@@ -1266,8 +1241,6 @@ mono_arch_output_basic_block (MonoCompile *cfg, MonoBasicBlock *bb)
        const char *spec;
 
        DEBUG_FUNC_ENTER();
-       if (cfg->opt & MONO_OPT_PEEPHOLE)
-               peephole_pass (cfg, bb);
 
        if (cfg->verbose_level > 2)
                g_print ("[%s::%s] Basic block %d starting at offset 0x%x\n", cfg->method->klass->name, cfg->method->name, bb->block_num, bb->native_offset);
@@ -1278,8 +1251,7 @@ mono_arch_output_basic_block (MonoCompile *cfg, MonoBasicBlock *bb)
                NOT_IMPLEMENTED;
        }
 
-       ins = bb->code;
-       while (ins) {
+       MONO_BB_FOR_EACH_INS (bb, ins) {
                guint8* code_start;
 
                offset = (guint8*)code - cfg->native_code;
@@ -1300,6 +1272,8 @@ mono_arch_output_basic_block (MonoCompile *cfg, MonoBasicBlock *bb)
                mono_debug_record_line_number (cfg, ins, offset);
 
                switch (ins->opcode) {
+               case OP_RELAXED_NOP:
+                       break;
                case OP_STOREI1_MEMBASE_IMM:
                        EMIT_STORE_MEMBASE_IMM (ins, stb);
                        break;
@@ -1320,11 +1294,6 @@ mono_arch_output_basic_block (MonoCompile *cfg, MonoBasicBlock *bb)
                case OP_STOREI4_MEMBASE_REG:
                        EMIT_STORE_MEMBASE_REG (ins, stw);
                        break;
-               case CEE_LDIND_I:
-               case CEE_LDIND_I4:
-               case CEE_LDIND_U4:
-                       NOT_IMPLEMENTED;
-                       break;
                case OP_LOADU1_MEMBASE:
                        EMIT_LOAD_MEMBASE (ins, ldb);
                        break;
@@ -1360,7 +1329,6 @@ mono_arch_output_basic_block (MonoCompile *cfg, MonoBasicBlock *bb)
                case CEE_CONV_I4:
                case CEE_CONV_U4:
                case OP_MOVE:
-               case OP_SETREG:
                        if (ins->sreg1 != ins->dreg)
                                hppa_copy (code, ins->sreg1, ins->dreg);
                        break;
@@ -1575,7 +1543,6 @@ mono_arch_output_basic_block (MonoCompile *cfg, MonoBasicBlock *bb)
                        g_warning ("unimplemented opcode %s in %s()\n", mono_inst_name (ins->opcode), __FUNCTION__);
                        NOT_IMPLEMENTED;
                        break;
-               case OP_SETFREG:
                case OP_FMOVE:
                        if (ins->sreg1 != ins->dreg)
                                hppa_fcpy (code, HPPA_FP_FMT_DBL, ins->sreg1, ins->dreg);
@@ -1608,7 +1575,7 @@ mono_arch_output_basic_block (MonoCompile *cfg, MonoBasicBlock *bb)
                case OP_LCALL:
                case OP_VCALL:
                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);
@@ -1747,11 +1714,7 @@ mono_arch_output_basic_block (MonoCompile *cfg, MonoBasicBlock *bb)
                case OP_BR: {
                        guint32 target;
                        DEBUG (printf ("target: %p, next: %p, curr: %p, last: %p\n", ins->inst_target_bb, bb->next_bb, ins, bb->last_ins));
-                       if (ins->flags & MONO_INST_BRLABEL) {
-                               mono_add_patch_info (cfg, offset, MONO_PATCH_INFO_LABEL, ins->inst_i0);
-                       } else {
-                               mono_add_patch_info (cfg, offset, MONO_PATCH_INFO_BB, ins->inst_target_bb);
-                       }
+                       mono_add_patch_info (cfg, offset, MONO_PATCH_INFO_BB, ins->inst_target_bb);
                        hppa_bl (code, 8, hppa_r0); 
                        /* TODO: if the branch is too long, we may need to
                         * use a long-branch sequence:
@@ -1767,7 +1730,7 @@ mono_arch_output_basic_block (MonoCompile *cfg, MonoBasicBlock *bb)
                        hppa_nop(code);
                        break;
 
-               case CEE_SWITCH: {
+               case OP_SWITCH: {
                        int i;
 
                        max_len += 8 * GPOINTER_TO_INT (ins->klass);
@@ -2064,8 +2027,6 @@ mono_arch_output_basic_block (MonoCompile *cfg, MonoBasicBlock *bb)
                cpos += max_len;
 
                last_ins = ins;
-               
-               ins = ins->next;
        }
 
        cfg->code_len = (guint8*)code - cfg->native_code;
@@ -2078,7 +2039,7 @@ mono_arch_register_lowlevel_calls (void)
 }
 
 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;
 
@@ -2155,7 +2116,7 @@ enum {
 };
 
 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;
        DEBUG_FUNC_ENTER();
@@ -2343,10 +2304,8 @@ mono_arch_emit_prolog (MonoCompile *cfg)
                if (cfg->prof_options & MONO_PROFILE_COVERAGE)
                        max_offset += 6; 
 
-               while (ins) {
+               MONO_BB_FOR_EACH_INS (bb, ins)
                        max_offset += ((guint8 *)ins_get_spec (ins->opcode))[MONO_INST_LEN];
-                       ins = ins->next;
-               }
        }
 
        DEBUG (printf ("Incoming arguments: \n"));
@@ -2890,20 +2849,20 @@ mono_arch_emit_this_vret_args (MonoCompile *cfg, MonoCallInst *inst, int this_re
        /* add the this argument */
        if (this_reg != -1) {
                MonoInst *this;
-               MONO_INST_NEW (cfg, this, OP_SETREG);
+               MONO_INST_NEW (cfg, this, OP_MOVE);
                this->type = this_type;
                this->sreg1 = this_reg;
-               this->dreg = mono_regstate_next_int (cfg->rs);
+               this->dreg = mono_alloc_ireg (cfg);
                mono_bblock_add_inst (cfg->cbb, this);
                mono_call_inst_add_outarg_reg (cfg, inst, this->dreg, hppa_r26, FALSE);
        }
 
        if (vt_reg != -1) {
                MonoInst *vtarg;
-               MONO_INST_NEW (cfg, vtarg, OP_SETREG);
+               MONO_INST_NEW (cfg, vtarg, OP_MOVE);
                vtarg->type = STACK_MP;
                vtarg->sreg1 = vt_reg;
-               vtarg->dreg = mono_regstate_next_int (cfg->rs);
+               vtarg->dreg = mono_alloc_ireg (cfg);
                mono_bblock_add_inst (cfg->cbb, vtarg);
                mono_call_inst_add_outarg_reg (cfg, inst, vtarg->dreg, hppa_r28, FALSE);
        }
@@ -2917,14 +2876,6 @@ mono_arch_get_inst_for_method (MonoCompile *cfg, MonoMethod *cmethod, MonoMethod
        DEBUG_FUNC_ENTER();
        DEBUG_FUNC_EXIT();
 
-#if 0
-       if (cmethod->klass == mono_defaults.thread_class &&
-               strcmp (cmethod->name, "MemoryBarrier") == 0) {
-               if (sparcv9)
-                       MONO_INST_NEW (cfg, ins, OP_MEMORY_BARRIER);
-       }
-#endif
-
        return ins;
 }
 
@@ -2976,7 +2927,9 @@ MonoInst* mono_arch_get_domain_intrinsic (MonoCompile* cfg)
        return NULL;
 }
 
-MonoInst* mono_arch_get_thread_intrinsic (MonoCompile* cfg)
+gpointer
+mono_arch_context_get_int_reg (MonoContext *ctx, int reg)
 {
-       return NULL;
+       /* FIXME: implement */
+       g_assert_not_reached ();
 }