narray first check in
[cacao.git] / jit / reg.c
index 5838bced60d6a34601197adbe375c2d287b4a3f3..09bd3ad8ac06e7a59ac6baaf23d2ebb3b2d338cf 100644 (file)
--- a/jit/reg.c
+++ b/jit/reg.c
@@ -257,6 +257,7 @@ static void interface_regalloc ()
                saved = (interfaces[s][TYPE_INT].flags | interfaces[s][TYPE_LNG].flags |
                         interfaces[s][TYPE_FLT].flags | interfaces[s][TYPE_DBL].flags |
                         interfaces[s][TYPE_ADR].flags) & SAVEDVAR;
                for (t = TYPE_INT; t <= TYPE_ADR; t++) {
                        v = &interfaces[s][t];
                        if (v->type >= 0) {
@@ -335,11 +336,13 @@ static void interface_regalloc ()
                                } /* if (type >= 0) */
                        }     /* for t */
                }         /* for s */
+
        maxmemuse = ifmemuse;
        maxtmpintreguse = iftmpintregcnt;
        maxsavintreguse = ifsavintregcnt;
        maxtmpfltreguse = iftmpfltregcnt;
        maxsavfltreguse = ifsavfltregcnt;
+
 }
 
 
@@ -351,11 +354,14 @@ static void interface_regalloc ()
        
 static void local_regalloc ()
 {
-       int     s, t;
-       int     intalloc, fltalloc;
+       int      s, t;
+       int      intalloc, fltalloc;
        varinfo *v;
        
        if (isleafmethod) {
+               int arg, doublewordarg;
+               arg = 0;
+               doublewordarg = 0;
                for (s = 0; s < maxlocals; s++) {
                        intalloc = -1; fltalloc = -1;
                        for (t = TYPE_INT; t <= TYPE_ADR; t++) {
@@ -366,9 +372,10 @@ static void local_regalloc ()
                                                        v->flags = locals[s][fltalloc].flags;
                                                        v->regoff = locals[s][fltalloc].regoff;
                                                        }
-                                               else if (s < fltreg_argnum) {
+                                               else if (!doublewordarg && (arg < mparamcount)
+                                                                       && (arg < fltreg_argnum)) {
                                                        v->flags = 0;
-                                                       v->regoff = argfltregs[s];
+                                                       v->regoff = argfltregs[arg];
                                                        }
                                                else if (maxtmpfltreguse > 0) {
                                                        maxtmpfltreguse--;
@@ -391,9 +398,10 @@ static void local_regalloc ()
                                                        v->flags = locals[s][intalloc].flags;
                                                        v->regoff = locals[s][intalloc].regoff;
                                                        }
-                                               else if (s < intreg_argnum) {
+                                               else if (!doublewordarg && (arg < mparamcount)
+                                                                       && (arg < intreg_argnum)) {
                                                        v->flags = 0;
-                                                       v->regoff = argintregs[s];
+                                                       v->regoff = argintregs[arg];
                                                        }
                                                else if (maxtmpintreguse > 0) {
                                                        maxtmpintreguse--;
@@ -413,6 +421,16 @@ static void local_regalloc ()
                                                }
                                        }
                                }
+                       if (arg < mparamcount) {
+                               if (doublewordarg) {
+                                       doublewordarg = 0;
+                                       arg++;
+                                       }
+                               else if (IS_2_WORD_TYPE(mparamtypes[arg]))
+                                       doublewordarg = 1;
+                               else
+                                       arg++;
+                               }
                        }
                return;
                }
@@ -580,18 +598,22 @@ static void allocate_scratch_registers()
        instruction *iptr = instr;
        basicblock  *bptr;
        
-       b_count = block_count;
+       /* b_count = block_count; */
+
        bptr = block;
-       while (--b_count >= 0) {
+       while (bptr != NULL) {
+
                if (bptr->flags >= BBREACHED) {
                        dst = bptr->instack;
                        reg_init_temp();
                        iptr = bptr->iinstr;
                        len = bptr->icount;
+  
                        while (--len >= 0)  {
                                src = dst;
                                dst = iptr->dst;
                                opcode = iptr->opc;
+
                                switch (opcode) {
 
                                        /* pop 0 push 0 */
@@ -635,6 +657,7 @@ static void allocate_scratch_registers()
                                        case ICMD_BALOAD:
                                        case ICMD_CALOAD:
                                        case ICMD_SALOAD:
+
                                                reg_free_temp(src);
                                                reg_free_temp(src->prev);
                                                reg_new_temp(dst);
@@ -651,6 +674,7 @@ static void allocate_scratch_registers()
                                        case ICMD_BASTORE:
                                        case ICMD_CASTORE:
                                        case ICMD_SASTORE:
+
                                                reg_free_temp(src);
                                                reg_free_temp(src->prev);
                                                reg_free_temp(src->prev->prev);
@@ -983,7 +1007,7 @@ static void allocate_scratch_registers()
                                iptr++;
                                } /* while instructions */
                        } /* if */
-               bptr++;
+               bptr = bptr->next;
        } /* while blocks */
 }