* mini-codegen.c (mono_local_regalloc): Make free mask
[mono.git] / mono / mini / mini-alpha.c
index 3707331f9ecdda6a75d2e4e23c62fd49194a3051..354efe6f8a24160324c88722d36baaf873299a04 100644 (file)
 /*------------------------------------------------------------------*/
 /*                 D e f i n e s                                    */
 /*------------------------------------------------------------------*/
-
-#define NOT_IMPLEMENTED(x) \
-   g_error ("FIXME: %s is not yet implemented.", x);
-
 #define ALPHA_DEBUG(x) \
    if (mini_alpha_verbose_level) \
        g_debug ("ALPHA_DEBUG: %s is called.", x);
@@ -73,6 +69,7 @@
 #include "mini-alpha.h"
 #include "inssel.h"
 #include "cpu-alpha.h"
+#include "jit-icalls.h"
 
 /*========================= End of Includes ========================*/
 
@@ -94,9 +91,11 @@ pthread_key_t lmf_addr_key;
 
 gboolean lmf_addr_key_inited = FALSE;
 
+MonoBreakpointInfo
+mono_breakpoint_info [MONO_BREAKPOINT_ARRAY_SIZE];
+
 /*====================== End of Global Variables ===================*/
 
-static void mono_arch_break(void);
 gpointer mono_arch_get_lmf_addr (void);
 
 typedef enum {
@@ -195,7 +194,7 @@ add_float (guint32 *gr, guint32 *stack_size, ArgInfo *ainfo,
 }
 
 static void
-add_valuetype (MonoGenericSharingContext *ctx, MonoMethodSignature *sig, ArgInfo *ainfo, MonoType *type,
+add_valuetype (MonoGenericSharingContext *gsctx, MonoMethodSignature *sig, ArgInfo *ainfo, MonoType *type,
                gboolean is_return,
                guint32 *gr, guint32 *fr, guint32 *stack_size)
 {
@@ -439,21 +438,28 @@ mono_arch_free_jit_tls_data (MonoJitTlsData *tls)
 
 /*========================= End of Function ========================*/
 
-static void
-  peephole_pass (MonoCompile *cfg, MonoBasicBlock *bb)
+// This peephole function is called before "local_regalloc" method
+// TSV_TODO - Check what we need to move here
+void
+mono_arch_peephole_pass_1 (MonoCompile *cfg, MonoBasicBlock *bb)
+{
+  CFG_DEBUG(3) g_print ("ALPHA: PEEPHOLE_1 pass\n");
+}
+
+// This peephole function is called after "local_regalloc" method
+void
+mono_arch_peephole_pass_2 (MonoCompile *cfg, MonoBasicBlock *bb)
 {
-  MonoInst *ins, *last_ins = NULL;
+  MonoInst *ins, *n, *last_ins = NULL;
   ins = bb->code;
    
-  CFG_DEBUG(3) g_print ("ALPHA: PEEPHOLE pass\n");
+  CFG_DEBUG(3) g_print ("ALPHA: PEEPHOLE_2 pass\n");
 
-  while (ins) 
-    {  
+  MONO_BB_FOR_EACH_INS_SAFE (bb, n, ins) {
       switch (ins->opcode) 
        {        
        case OP_MOVE:
        case OP_FMOVE:
-       case OP_SETREG:
          /*
           * Removes:
           *
@@ -462,10 +468,7 @@ static void
          if (ins->dreg == ins->sreg1 &&
              ins->dreg != alpha_at) 
            {
-             if (last_ins)
-               last_ins->next = ins->next;
-             
-             ins = ins->next;
+             MONO_DELETE_INS (bb, ins);
              continue;
            }
          
@@ -480,9 +483,7 @@ static void
              last_ins->dreg != alpha_at &&
              ins->dreg == last_ins->sreg1) 
            {
-             last_ins->next = ins->next;
-             
-             ins = ins->next;
+             MONO_DELETE_INS (bb, ins);
              continue;
            }
          
@@ -498,8 +499,7 @@ static void
                }
              else 
                {
-                 last_ins->next = ins->next;
-                 ins = ins->next;
+                 MONO_DELETE_INS (bb, ins);
                  continue;
                }
            }
@@ -525,9 +525,7 @@ static void
             {
               if (ins->dreg == last_ins->sreg1)
                 {
-                  last_ins->next = ins->next;
-
-                  ins = ins->next;
+                 MONO_DELETE_INS (bb, ins);
                   continue;
                 }
               else
@@ -558,9 +556,7 @@ static void
            {
              if (ins->dreg == last_ins->sreg1)
                {
-                 last_ins->next = ins->next;
-
-                 ins = ins->next;
+                 MONO_DELETE_INS (bb, ins);
                  continue;
                }
              else
@@ -589,9 +585,7 @@ static void
            {
              if (ins->dreg == last_ins->dreg)
                {
-                 last_ins->next = ins->next;
-                 
-                 ins = ins->next;
+                 MONO_DELETE_INS (bb, ins);
                  continue;
                }
              else
@@ -613,8 +607,6 @@ static void
   bb->last_ins = last_ins;
 }
 
-
-
 // Convert to opposite branch opcode
 static guint16 cvt_branch_opcode(guint16 opcode)
 {
@@ -946,10 +938,10 @@ static void cvt_cmp_branch(MonoInst *curr, MonoInst *next)
  * Converts complex opcodes into simpler ones so that each IR instruction
  * corresponds to one machine instruction.
  */
-static void
-  mono_arch_lowering_pass (MonoCompile *cfg, MonoBasicBlock *bb)
+void
+mono_arch_lowering_pass (MonoCompile *cfg, MonoBasicBlock *bb)
 {   
-   MonoInst *ins, *temp, *last_ins = NULL;
+   MonoInst *ins, *n, *temp, *last_ins = NULL;
    MonoInst *next;
    
    ins = bb->code;
@@ -963,8 +955,7 @@ static void
     * cdq.
     */
    
-   while (ins) 
-     {
+   MONO_BB_FOR_EACH_INS_SAFE (bb, n, ins) {
        switch (ins->opcode) 
         {       
         case OP_DIV_IMM:
@@ -1022,7 +1013,7 @@ static void
               ins->sreg2 = temp->dreg;
                                  
               // We should try to reevaluate new IR opcode
-              continue;
+              //continue;
             }
           
           next = ins->next;
@@ -1041,7 +1032,7 @@ static void
                ins->sreg2 = temp->dreg;
 
                // We should try to reevaluate new IR opcode
-               continue;
+               //continue;
              }
 
            next = ins->next;
@@ -1213,33 +1204,6 @@ static void
    bb->max_vreg = cfg->rs->next_vreg;
 }
 
-/*------------------------------------------------------------------*/
-/*                                                                  */
-/* 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)
-{
-  CFG_DEBUG(2) ALPHA_DEBUG("mono_arch_local_regalloc");
-   
-  if (!bb->code)
-    return;
-   
-  mono_arch_lowering_pass (cfg, bb);
-   
-  mono_local_regalloc(cfg, bb);
-}
-
 /*========================= End of Function ========================*/
 
 #define AXP_GENERAL_REGS     6
@@ -2239,9 +2203,6 @@ mono_arch_output_basic_block (MonoCompile *cfg, MonoBasicBlock *bb)
    
    CFG_DEBUG(2) ALPHA_DEBUG("mono_arch_output_basic_block");
    
-   if (cfg->opt & MONO_OPT_PEEPHOLE)
-     peephole_pass (cfg, bb);
-    
    CFG_DEBUG(2) g_print ("Basic block %d(%p) starting at offset 0x%x\n",
                         bb->block_num, bb, bb->native_offset);
    
@@ -2251,9 +2212,7 @@ mono_arch_output_basic_block (MonoCompile *cfg, MonoBasicBlock *bb)
 
    mono_debug_open_block (cfg, bb, offset);
    
-   ins = bb->code;
-   while (ins)
-     {
+   MONO_BB_FOR_EACH_INS (bb, ins) {
        offset = ((char *)code) - ((char *)cfg->native_code);
          
        max_len = ((guint8 *)ins_get_spec (ins->opcode))[MONO_INST_LEN];
@@ -2273,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",
@@ -3727,7 +3688,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:
           CFG_DEBUG(4) g_print("ALPHA_CHECK: [fcall/lcall/vcall/voidcall/call] Target: [");
           call = (MonoCallInst*)ins;
           
@@ -3873,12 +3834,6 @@ mono_arch_output_basic_block (MonoCompile *cfg, MonoBasicBlock *bb)
             alpha_bsr(code, alpha_ra, 0);
           }
           break;
-          
-        case CEE_RET:
-          CFG_DEBUG(4) g_print("ALPHA_CHECK: [ret]\n");
-          
-          alpha_ret(code, alpha_ra, 1);
-          break;
 
         case OP_THROW:
           CFG_DEBUG(4) g_print("ALPHA_CHECK: [throw] sreg1=%0x\n",
@@ -4009,9 +3964,7 @@ mono_arch_output_basic_block (MonoCompile *cfg, MonoBasicBlock *bb)
        
        last_ins = ins;
        last_offset = offset;
-       
-       ins = ins->next;          
-     }
+   }
    
    cfg->code_len = ((char *)code) - ((char *)cfg->native_code);
 }
@@ -4193,7 +4146,7 @@ mono_arch_patch_code (MonoMethod *method, MonoDomain *domain,
  
            if (*ip2 != (t_addr & 0xFFFFFFFF) ||
                *(ip2+1) != ((t_addr>>32) & 0xFFFFFFFF))
-                   NOT_IMPLEMENTED("mono_arch_patch_code: MONO_PATCH_INFO_CLASS_INIT");
+                       NOT_IMPLEMENTED;
            //  amd64_call_code (ip2, 0);
            break;
          }
@@ -5090,19 +5043,6 @@ mono_arch_call_opcode (MonoCompile *cfg, MonoBasicBlock* bb,
 
 /*========================= End of Function ========================*/
 
-/*------------------------------------------------------------------*/
-/*                                                                  */
-/* Name         - mono_arch_break                                   */
-/*                                                                  */
-/* Function     - Process a "break" operation for debugging.        */
-/*                                                                  */
-/*------------------------------------------------------------------*/
-
-static void
-mono_arch_break(void) {
-}
-
-
 /*------------------------------------------------------------------*/
 /*                                                                  */
 /* Name         - mono_arch_register_lowlevel_calls                 */
@@ -5116,7 +5056,6 @@ mono_arch_register_lowlevel_calls (void)
 {
    ALPHA_DEBUG("mono_arch_register_lowlevel_calls");
    
-   mono_register_jit_icall (mono_arch_break, "mono_arch_break", NULL, TRUE);
    mono_register_jit_icall (mono_arch_get_lmf_addr, "mono_arch_get_lmf_addr",
                                                        NULL, TRUE);
 }
@@ -5290,11 +5229,6 @@ mono_arch_get_inst_for_method (MonoCompile *cfg, MonoMethod *cmethod,
    
    CFG_DEBUG(3) g_print("mono_arch_get_inst_for_method: %s\n", cmethod->name);
    
-   if (cmethod->klass == mono_defaults.thread_class &&
-       strcmp (cmethod->name, "MemoryBarrier") == 0) {
-     MONO_INST_NEW (cfg, ins, OP_MEMORY_BARRIER);
-   }
-   
    return ins;
 }
 
@@ -5321,7 +5255,7 @@ mono_arch_create_class_init_trampoline (MonoVTable *vtable)
 {
    ALPHA_DEBUG("mono_arch_create_class_init_trampoline");
    
-   NOT_IMPLEMENTED("mono_arch_create_class_init_trampoline: check MONO_ARCH_HAVE_CREATE_SPECIFIC_TRAMPOLINE define");
+   NOT_IMPLEMENTED;
    
    return 0;
 }
@@ -5847,7 +5781,7 @@ mono_arch_allocate_vars (MonoCompile *cfg)
               break;
 
             default:
-              NOT_IMPLEMENTED("");
+              NOT_IMPLEMENTED;
             }
 
           if (!inreg && (ainfo->storage != ArgOnStack))
@@ -5979,9 +5913,45 @@ mono_arch_get_vcall_slot_addr (guint8* code, gpointer *regs)
   return 0;
 }
 
+gpointer
+mono_arch_get_this_arg_from_call (MonoGenericSharingContext *gsctx, MonoMethodSignature *sig, gssize *regs, guint8 *code)
+{
+  unsigned int *pc = (unsigned int *)code;
+
+  ALPHA_PRINT g_debug("ALPHA_CHECK: [mono_arch_get_this_arg_from_call] code: %p regs: %p",
+          pc, regs);
+
+        if (MONO_TYPE_ISSTRUCT (sig->ret))
+                return (gpointer)regs [alpha_a1];
+        else
+                return (gpointer)regs [alpha_a0];
+}
+
+gpointer
+mono_arch_get_delegate_invoke_impl (MonoMethodSignature *sig, gboolean has_target)
+{
+       unsigned int *code, *start;
+        MonoDomain *domain = mono_domain_get ();
+        int i;
+
+       ALPHA_PRINT g_debug("ALPHA_CHECK: [mono_arch_get_delegate_invoke_impl]");
+
+        /* FIXME: Support more cases */
+        if (MONO_TYPE_ISSTRUCT (sig->ret))
+                return NULL;
+
+       return NULL;
+}
 
 guint32
 mono_arch_get_patch_offset (guint8 *code)
 {
   return 3;
 }
+
+gpointer
+mono_arch_context_get_int_reg (MonoContext *ctx, int reg)
+{
+       /* FIXME: implement */
+       g_assert_not_reached ();
+}