* mini-codegen.c (mono_local_regalloc): Make free mask
[mono.git] / mono / mini / mini-alpha.c
index dad5a18eb3d31efabb3a9b85cdb3794a46958b3c..354efe6f8a24160324c88722d36baaf873299a04 100644 (file)
 
 #define ALPHA_PRINT if (mini_alpha_verbose_level)
 
-#define NEW_INS(cfg,ins,dest,op) do {                                  \
-   (dest) = mono_mempool_alloc0 ((cfg)->mempool, sizeof (MonoInst));    \
-   (dest)->opcode = (op);                                               \
-   MONO_INST_LIST_ADD_TAIL (&(dest)->node, &(ins)->node);               \
+#define NEW_INS(cfg,dest,op) do {       \
+   (dest) = mono_mempool_alloc0 ((cfg)->mempool, sizeof (MonoInst));       \
+   (dest)->opcode = (op);  \
+   insert_after_ins (bb, last_ins, (dest)); \
 } while (0)
 
 #define NEW_ICONST(cfg,dest,val) do {                                  \
@@ -294,6 +294,22 @@ add_outarg_reg (MonoCompile *cfg, MonoCallInst *call, MonoInst *arg,
     }
 }
 
+static void
+insert_after_ins (MonoBasicBlock *bb, MonoInst *ins, MonoInst *to_insert)
+{
+   if (ins == NULL)
+     {
+       ins = bb->code;
+       bb->code = to_insert;
+       to_insert->next = ins;
+     }
+   else
+     {
+       to_insert->next = ins->next;
+       ins->next = to_insert;
+     }
+}
+
 static void add_got_entry(MonoCompile *cfg, AlphaGotType ge_type,
                          AlphaGotData ge_data,
                          int ip, MonoJumpInfoType type, gconstpointer target)
@@ -434,12 +450,12 @@ mono_arch_peephole_pass_1 (MonoCompile *cfg, MonoBasicBlock *bb)
 void
 mono_arch_peephole_pass_2 (MonoCompile *cfg, MonoBasicBlock *bb)
 {
-  MonoInst *ins, *n;
+  MonoInst *ins, *n, *last_ins = NULL;
+  ins = bb->code;
    
   CFG_DEBUG(3) g_print ("ALPHA: PEEPHOLE_2 pass\n");
 
   MONO_BB_FOR_EACH_INS_SAFE (bb, n, ins) {
-      MonoInst *last_ins = mono_inst_list_prev (&ins->node, &bb->ins_list);
       switch (ins->opcode) 
        {        
        case OP_MOVE:
@@ -583,7 +599,12 @@ mono_arch_peephole_pass_2 (MonoCompile *cfg, MonoBasicBlock *bb)
          break;      
 #endif
        }
+      
+      last_ins = ins;
+      ins = ins->next;
     }
+   
+  bb->last_ins = last_ins;
 }
 
 // Convert to opposite branch opcode
@@ -920,7 +941,10 @@ static void cvt_cmp_branch(MonoInst *curr, MonoInst *next)
 void
 mono_arch_lowering_pass (MonoCompile *cfg, MonoBasicBlock *bb)
 {   
-   MonoInst *ins, *n, *next, *temp;
+   MonoInst *ins, *n, *temp, *last_ins = NULL;
+   MonoInst *next;
+   
+   ins = bb->code;
    
    if (bb->max_vreg > cfg->rs->next_vreg)
         cfg->rs->next_vreg = bb->max_vreg;
@@ -939,7 +963,7 @@ mono_arch_lowering_pass (MonoCompile *cfg, MonoBasicBlock *bb)
         case OP_IDIV_IMM:
         case OP_IREM_IMM:
         case OP_MUL_IMM:
-          NEW_INS (cfg, ins, temp, OP_I8CONST);
+          NEW_INS (cfg, temp, OP_I8CONST);
           temp->inst_c0 = ins->inst_imm;
           temp->dreg = mono_regstate_next_int (cfg->rs);
           
@@ -973,8 +997,7 @@ mono_arch_lowering_pass (MonoCompile *cfg, MonoBasicBlock *bb)
             // Instead of compare+b<cond>/fcompare+b<cond>,
             // Alpha has compare<cond>+br<cond>/fcompare<cond>+br<cond>
             // we need to convert
-            next = mono_inst_list_next (&ins->node, &bb->ins_list);
-            g_assert(next);
+            next = ins->next;
 
             cvt_cmp_branch(ins, next);
           }
@@ -983,7 +1006,7 @@ mono_arch_lowering_pass (MonoCompile *cfg, MonoBasicBlock *bb)
         case OP_COMPARE_IMM:
           if (!alpha_is_imm (ins->inst_imm)) 
             {    
-              NEW_INS (cfg, ins, temp, OP_I8CONST);
+              NEW_INS (cfg, temp, OP_I8CONST);
               temp->inst_c0 = ins->inst_imm;
               temp->dreg = mono_regstate_next_int (cfg->rs);
               ins->opcode = OP_COMPARE;
@@ -993,8 +1016,7 @@ mono_arch_lowering_pass (MonoCompile *cfg, MonoBasicBlock *bb)
               //continue;
             }
           
-          next = mono_inst_list_next (&ins->node, &bb->ins_list);
-          g_assert(next);
+          next = ins->next;
           
           cvt_cmp_branch(ins, next);
                         
@@ -1003,7 +1025,7 @@ mono_arch_lowering_pass (MonoCompile *cfg, MonoBasicBlock *bb)
         case OP_ICOMPARE_IMM:
            if (!alpha_is_imm (ins->inst_imm))
              {
-              NEW_INS (cfg, ins, temp, OP_ICONST);
+               NEW_INS (cfg, temp, OP_ICONST);
                temp->inst_c0 = ins->inst_imm;
                temp->dreg = mono_regstate_next_int (cfg->rs);
                ins->opcode = OP_ICOMPARE;
@@ -1013,8 +1035,7 @@ mono_arch_lowering_pass (MonoCompile *cfg, MonoBasicBlock *bb)
                //continue;
              }
 
-          next = mono_inst_list_next (&ins->node, &bb->ins_list);
-          g_assert(next);
+           next = ins->next;
 
            cvt_cmp_branch(ins, next);
 
@@ -1024,7 +1045,7 @@ mono_arch_lowering_pass (MonoCompile *cfg, MonoBasicBlock *bb)
         case OP_STOREI8_MEMBASE_IMM:
           if (ins->inst_imm != 0) 
             {    
-              NEW_INS (cfg, ins, temp, OP_I8CONST);
+              NEW_INS (cfg, temp, OP_I8CONST);
               temp->inst_c0 = ins->inst_imm;
               temp->dreg = mono_regstate_next_int (cfg->rs);
               ins->opcode = OP_STOREI8_MEMBASE_REG;
@@ -1036,7 +1057,7 @@ mono_arch_lowering_pass (MonoCompile *cfg, MonoBasicBlock *bb)
           if (ins->inst_imm != 0)
             {
               MonoInst *temp;
-              NEW_INS (cfg, ins, temp, OP_ICONST);
+              NEW_INS (cfg, temp, OP_ICONST);
               temp->inst_c0 = ins->inst_imm;
               temp->dreg = mono_regstate_next_int (cfg->rs);
               ins->opcode = OP_STOREI4_MEMBASE_REG;
@@ -1048,7 +1069,7 @@ mono_arch_lowering_pass (MonoCompile *cfg, MonoBasicBlock *bb)
           if (ins->inst_imm != 0 || !bwx_supported)
              {
                MonoInst *temp;
-               NEW_INS (cfg, ins, temp, OP_ICONST);
+               NEW_INS (cfg, temp, OP_ICONST);
                temp->inst_c0 = ins->inst_imm;
                temp->dreg = mono_regstate_next_int (cfg->rs);
                ins->opcode = OP_STOREI1_MEMBASE_REG;
@@ -1060,7 +1081,7 @@ mono_arch_lowering_pass (MonoCompile *cfg, MonoBasicBlock *bb)
            if (ins->inst_imm != 0 || !bwx_supported)
           {
             MonoInst *temp;
-            NEW_INS (cfg, ins, temp, OP_ICONST);
+            NEW_INS (cfg, temp, OP_ICONST);
             temp->inst_c0 = ins->inst_imm;
             temp->dreg = mono_regstate_next_int (cfg->rs);
             ins->opcode = OP_STOREI2_MEMBASE_REG;
@@ -1079,7 +1100,7 @@ mono_arch_lowering_pass (MonoCompile *cfg, MonoBasicBlock *bb)
           if (!alpha_is_imm(ins->inst_imm))
             {
               MonoInst *temp;
-              NEW_INS (cfg, ins, temp, OP_ICONST);
+              NEW_INS (cfg, temp, OP_ICONST);
               temp->inst_c0 = ins->inst_imm;
               temp->dreg = mono_regstate_next_int (cfg->rs);
                                  
@@ -1122,7 +1143,7 @@ mono_arch_lowering_pass (MonoCompile *cfg, MonoBasicBlock *bb)
           if (!alpha_is_imm(ins->inst_imm))
             {
               MonoInst *temp;
-              NEW_INS (cfg, ins, temp, OP_ICONST);
+              NEW_INS (cfg, temp, OP_ICONST);
               temp->inst_c0 = ins->inst_imm;
               temp->dreg = mono_regstate_next_int (cfg->rs);
               
@@ -1151,7 +1172,7 @@ mono_arch_lowering_pass (MonoCompile *cfg, MonoBasicBlock *bb)
           if (!alpha_is_imm(ins->inst_imm))
             {
               MonoInst *temp;
-              NEW_INS(cfg, ins, temp, OP_ICONST);
+              NEW_INS(cfg, temp, OP_ICONST);
               temp->inst_c0 = ins->inst_imm;
               temp->dreg = mono_regstate_next_int(cfg->rs);
               ins->sreg2 = temp->dreg;
@@ -1162,7 +1183,7 @@ mono_arch_lowering_pass (MonoCompile *cfg, MonoBasicBlock *bb)
            if (!alpha_is_imm(ins->inst_imm))
              {
                MonoInst *temp;
-               NEW_INS(cfg, ins, temp, OP_ICONST);
+               NEW_INS(cfg, temp, OP_ICONST);
                temp->inst_c0 = ins->inst_imm;
                temp->dreg = mono_regstate_next_int(cfg->rs);
                ins->sreg2 = temp->dreg;
@@ -1173,8 +1194,13 @@ mono_arch_lowering_pass (MonoCompile *cfg, MonoBasicBlock *bb)
         default:
           break;
         }
+               
+       last_ins = ins;
+       ins = ins->next;
      }
    
+   bb->last_ins = last_ins;
+   
    bb->max_vreg = cfg->rs->next_vreg;
 }
 
@@ -2171,6 +2197,7 @@ mono_arch_output_basic_block (MonoCompile *cfg, MonoBasicBlock *bb)
    MonoCallInst *call;
    guint offset;
    unsigned int *code = (unsigned int *)(cfg->native_code + cfg->code_len);
+   MonoInst *last_ins = NULL;
    guint last_offset = 0;
    int max_len, cpos;
    
@@ -2205,6 +2232,8 @@ mono_arch_output_basic_block (MonoCompile *cfg, MonoBasicBlock *bb)
          
        switch (ins->opcode)
         {
+        case OP_RELAXED_NOP:
+               break;
         case OP_LSHR:
           // Shift 64 bit value right
           CFG_DEBUG(4) g_print("ALPHA_CHECK: [long_shr] dreg=%d, sreg1=%d, sreg2=%d\n",
@@ -3596,6 +3625,9 @@ mono_arch_output_basic_block (MonoCompile *cfg, MonoBasicBlock *bb)
           break;
           
         case OP_BR:
+          CFG_DEBUG(4) g_print("ALPHA_CHECK: [br] target: %p, next: %p, curr: %p, last: %p [",
+                 ins->inst_target_bb, bb->next_bb, ins, bb->last_ins);
+          
           if (ins->flags & MONO_INST_BRLABEL)
             {
               if (ins->inst_i0->inst_c0)
@@ -3930,8 +3962,9 @@ mono_arch_output_basic_block (MonoCompile *cfg, MonoBasicBlock *bb)
        
        cpos += max_len;
        
+       last_ins = ins;
        last_offset = offset;
-     }
+   }
    
    cfg->code_len = ((char *)code) - ((char *)cfg->native_code);
 }
@@ -4763,7 +4796,10 @@ mono_arch_call_opcode (MonoCompile *cfg, MonoBasicBlock* bb,
           MONO_INST_NEW (cfg, arg, OP_OUTARG);
           arg->inst_left = sig_arg;
           arg->type = STACK_PTR;
-          MONO_INST_LIST_ADD (&arg->node, &call->out_args);
+          
+          /* prepend, so they get reversed */
+          arg->next = call->out_args;
+          call->out_args = arg;
         }
                
        if (is_virtual && i == 0) {
@@ -4778,7 +4814,9 @@ mono_arch_call_opcode (MonoCompile *cfg, MonoBasicBlock* bb,
         arg->cil_code = in->cil_code;
         arg->inst_left = in;
         arg->type = in->type;
-        MONO_INST_LIST_ADD (&arg->node, &call->out_args);
+        /* prepend, so they get reversed */
+        arg->next = call->out_args;
+        call->out_args = arg;
 
         CFG_DEBUG(3) g_print("ALPHA: Param[%d] - ", i);
 
@@ -4846,9 +4884,10 @@ mono_arch_call_opcode (MonoCompile *cfg, MonoBasicBlock* bb,
 
                     add_outarg_reg (cfg, call, set_reg, arg_storage,
                                     dest_reg, load);
-                    if (&set_reg->node != call->out_args.next)
+                    if (set_reg != call->out_args)
                       {
-                        MONO_INST_LIST_ADD (&set_reg->node, &call->out_args);
+                        set_reg->next = call->out_args;
+                        call->out_args = set_reg;
                     }
                   }
 
@@ -4882,9 +4921,10 @@ mono_arch_call_opcode (MonoCompile *cfg, MonoBasicBlock* bb,
                     //outarg->inst_imm = 16 + ainfo->offset + (slot - 8) * 8;
                     outarg->dreg = ainfo->offset + (slot - 22) * 8;
 
-                    if (&outarg->node != call->out_args.next)
+                    if (outarg != call->out_args)
                       {
-                        MONO_INST_LIST_ADD (&outarg->node, &call->out_args);
+                        outarg->next = call->out_args;
+                        call->out_args = outarg;
                       }
                   }
                
@@ -4895,7 +4935,10 @@ mono_arch_call_opcode (MonoCompile *cfg, MonoBasicBlock* bb,
                 arg->inst_left = vtaddr;
                 arg->inst_right = in;
                 arg->type = in->type;
-                MONO_INST_LIST_ADD (&arg->node, &call->out_args);
+
+                /* prepend, so they get reversed */
+                arg->next = call->out_args;
+                call->out_args = arg;
               }
             else
               {
@@ -4975,7 +5018,9 @@ mono_arch_call_opcode (MonoCompile *cfg, MonoBasicBlock* bb,
         zero_inst->inst_p0 = 0;
         arg->inst_left = zero_inst;
         arg->type = STACK_PTR;
-        MONO_INST_LIST_ADD (&arg->node, &call->out_args);
+        /* prepend, so they get reversed */
+        arg->next = call->out_args;
+        call->out_args = arg;
        }
        else
         /* if the function returns a struct, the called method a
@@ -5869,7 +5914,7 @@ mono_arch_get_vcall_slot_addr (guint8* code, gpointer *regs)
 }
 
 gpointer
-mono_arch_get_this_arg_from_call (MonoMethodSignature *sig, gssize *regs, guint8 *code)
+mono_arch_get_this_arg_from_call (MonoGenericSharingContext *gsctx, MonoMethodSignature *sig, gssize *regs, guint8 *code)
 {
   unsigned int *pc = (unsigned int *)code;