* src/vm/jit/alpha/emit.c [ENABLE_THREADS] (threads/native/lock.h):
[cacao.git] / src / vm / jit / stack.c
index 7e39f13578cbeeb23c702795c90a736ee6eac8d2..beb5a6c8f78c77646fdccea52c6831e80c9f3053 100644 (file)
@@ -30,7 +30,7 @@
             Christian Thalinger
             Christian Ullrich
 
-   $Id: stack.c 5216 2006-08-08 12:45:31Z twisti $
+   $Id: stack.c 5251 2006-08-18 13:01:00Z twisti $
 
 */
 
@@ -550,7 +550,7 @@ bool new_stack_analyse(jitdata *jd)
 
                while (--b_count >= 0) {
 #if defined(STACK_VERBOSE)
-                       printf("ANALYZING BLOCK L%03d\n", bptr->debug_nr);
+                       printf("ANALYZING BLOCK L%03d\n", bptr->nr);
 #endif
 
                        if (bptr->flags == BBDELETED) {
@@ -2511,8 +2511,9 @@ icmd_BUILTIN:
                                                REQUIRE(i);
 
                                                /* XXX optimize for <= 2 args */
-                                               iptr->s1.argcount = i;
-                                               iptr->sx.s23.s2.args = DMNEW(stackptr, i);
+                                               /* XXX not for ICMD_BUILTIN */
+                                               iptr->s1.argcount = stackdepth;
+                                               iptr->sx.s23.s2.args = DMNEW(stackptr, stackdepth);
 
                                                copy = curstack;
                                                for (i-- ; i >= 0; i--) {
@@ -2568,11 +2569,19 @@ icmd_BUILTIN:
                                                        copy = copy->prev;
                                                }
 
+                                               /* deal with live-through stack slots "under" the arguments */
+                                               /* XXX not for ICMD_BUILTIN */
+
+                                               i = md->paramcount;
+
                                                while (copy) {
+                                                       iptr->sx.s23.s2.args[i++] = copy;
                                                        copy->flags |= SAVEDVAR;
                                                        copy = copy->prev;
                                                }
 
+                                               /* pop the arguments */
+
                                                i = md->paramcount;
 
                                                stackdepth -= i;
@@ -2580,6 +2589,8 @@ icmd_BUILTIN:
                                                        POPANY;
                                                }
 
+                                               /* push the return value */
+
                                                if (md->returntype.type != TYPE_VOID) {
                                                        NEW_DST(md->returntype.type, stackdepth);
                                                        stackdepth++;
@@ -2604,11 +2615,11 @@ icmd_BUILTIN:
 
 #if defined(SPECIALMEMUSE)
 # if defined(__DARWIN__)
-                                               if (rd->memuse < (i + INT_ARG_CNT + LA_WORD_SIZE))
-                                                       rd->memuse = i + LA_WORD_SIZE + INT_ARG_CNT;
+                                               if (rd->memuse < (i + INT_ARG_CNT + LA_SIZE_IN_POINTERS))
+                                                       rd->memuse = i + LA_SIZE_IN_POINTERS + INT_ARG_CNT;
 # else
-                                               if (rd->memuse < (i + LA_WORD_SIZE + 3))
-                                                       rd->memuse = i + LA_WORD_SIZE + 3;
+                                               if (rd->memuse < (i + LA_SIZE_IN_POINTERS + 3))
+                                                       rd->memuse = i + LA_SIZE_IN_POINTERS + 3;
 # endif
 #else
 # if defined(__I386__)
@@ -2632,9 +2643,9 @@ icmd_BUILTIN:
                                                                copy->flags |= INMEMORY;
 #if defined(SPECIALMEMUSE)
 # if defined(__DARWIN__)
-                                                               copy->regoff = i + LA_WORD_SIZE + INT_ARG_CNT;
+                                                               copy->regoff = i + LA_SIZE_IN_POINTERS + INT_ARG_CNT;
 # else
-                                                               copy->regoff = i + LA_WORD_SIZE + 3;
+                                                               copy->regoff = i + LA_SIZE_IN_POINTERS + 3;
 # endif
 #else
 # if defined(__I386__)
@@ -2862,10 +2873,6 @@ bool stack_analyse(jitdata *jd)
        cd   = jd->cd;
        rd   = jd->rd;
 
-#if defined(ENABLE_LSRA)
-       m->maxlifetimes = 0;
-#endif
-
        last_store = DMNEW(s4 , cd->maxlocals * 5);
        
        new = m->stack;
@@ -2933,10 +2940,18 @@ bool stack_analyse(jitdata *jd)
                                while (--len >= 0)  {
                                        opcode = iptr->opc;
 
+                                       /* check if ICMD opcode could throw an exception        */
+                                       /* and if so remember the instruction index in last_pei */
+
+                                       if (op_data[opcode][PEI])
+                                               last_pei = bptr->icount - len - 1;
+
 #if defined(USEBUILTINTABLE)
 # if defined(ENABLE_INTRP)
                                        if (!opt_intrp) {
 # endif
+                                               /* check for opcodes to replace */
+
                                                bte = builtintable_get_automatic(opcode);
 
                                                if (bte && bte->opcode == opcode) {
@@ -2951,6 +2966,12 @@ bool stack_analyse(jitdata *jd)
 # endif
 #endif /* defined(USEBUILTINTABLE) */
 
+                                       /* Check for functions to replace with builtin
+                                          functions. */
+
+                                       if (builtintable_replace_function(iptr))
+                                               goto builtin;
+
                                        /* this is the main switch */
 
                                        switch (opcode) {
@@ -4867,9 +4888,7 @@ bool stack_analyse(jitdata *jd)
                                        /* pop many push any */
 
                                        case ICMD_BUILTIN:
-#if defined(USEBUILTINTABLE)
                                        builtin:
-#endif
                                                bte = (builtintable_entry *) iptr->val.a;
                                                md = bte->md;
                                                goto _callhandling;
@@ -4885,7 +4904,7 @@ bool stack_analyse(jitdata *jd)
 
                                        _callhandling:
 
-                                               last_pei = bptr->icount - len - 1;
+/*                                             last_pei = bptr->icount - len - 1; */
 
                                                i = md->paramcount;
 
@@ -4974,11 +4993,11 @@ bool stack_analyse(jitdata *jd)
                                                REQUIRE(i);
 #if defined(SPECIALMEMUSE)
 # if defined(__DARWIN__)
-                                               if (rd->memuse < (i + INT_ARG_CNT + LA_WORD_SIZE))
-                                                       rd->memuse = i + LA_WORD_SIZE + INT_ARG_CNT;
+                                               if (rd->memuse < (i + INT_ARG_CNT + LA_SIZE_IN_POINTERS))
+                                                       rd->memuse = i + LA_SIZE_IN_POINTERS + INT_ARG_CNT;
 # else
-                                               if (rd->memuse < (i + LA_WORD_SIZE + 3))
-                                                       rd->memuse = i + LA_WORD_SIZE + 3;
+                                               if (rd->memuse < (i + LA_SIZE_IN_POINTERS + 3))
+                                                       rd->memuse = i + LA_SIZE_IN_POINTERS + 3;
 # endif
 #else
 # if defined(__I386__)
@@ -5001,9 +5020,9 @@ bool stack_analyse(jitdata *jd)
                                                                copy->flags |= INMEMORY;
 #if defined(SPECIALMEMUSE)
 # if defined(__DARWIN__)
-                                                               copy->regoff = i + LA_WORD_SIZE + INT_ARG_CNT;
+                                                               copy->regoff = i + LA_SIZE_IN_POINTERS + INT_ARG_CNT;
 # else
-                                                               copy->regoff = i + LA_WORD_SIZE + 3;
+                                                               copy->regoff = i + LA_SIZE_IN_POINTERS + 3;
 # endif
 #else
 # if defined(__I386__)
@@ -5168,7 +5187,7 @@ throw_stack_overflow:
        return false;
 
 throw_stack_depth_error:
-       exceptions_throw_verifyerror(m,"Stack depth mismatch");
+       exceptions_throw_verifyerror(m, "Stack depth mismatch");
        return false;
 
 throw_stack_type_error: