* Removed all Id tags.
[cacao.git] / src / vm / jit / schedule / schedule.c
index 78b3fc2195febe7f650131718f80197c607d3754..894821011cf8f1a252cdc7d3172dbcd8cd881df6 100644 (file)
@@ -1,10 +1,10 @@
 /* src/vm/jit/schedule/schedule.c - architecture independent instruction
                                     scheduler
 
-   Copyright (C) 1996-2005 R. Grafl, A. Krall, C. Kruegel, C. Oates,
-   R. Obermaisser, M. Platter, M. Probst, S. Ring, E. Steiner,
-   C. Thalinger, D. Thuernbeck, P. Tomsich, C. Ullrich, J. Wenninger,
-   Institut f. Computersprachen - TU Wien
+   Copyright (C) 1996-2005, 2006 R. Grafl, A. Krall, C. Kruegel,
+   C. Oates, R. Obermaisser, M. Platter, M. Probst, S. Ring,
+   E. Steiner, C. Thalinger, D. Thuernbeck, P. Tomsich, C. Ullrich,
+   J. Wenninger, Institut f. Computersprachen - TU Wien
 
    This file is part of CACAO.
 
 
    You should have received a copy of the GNU General Public License
    along with this program; if not, write to the Free Software
-   Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
-   02111-1307, USA.
+   Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
+   02110-1301, USA.
 
-   Contact: cacao@complang.tuwien.ac.at
+   Contact: cacao@cacaojvm.org
 
    Authors: Christian Thalinger
 
    Changes:
 
-   $Id: schedule.c 2055 2005-03-21 17:00:52Z twisti $
-
 */
 
 
+#include "config.h"
+
 #include <stdio.h>
 
-#include "config.h"
+#include "vm/types.h"
+
 #include "disass.h"
 
 #include "mm/memory.h"
@@ -58,7 +59,7 @@ scheduledata *schedule_init(methodinfo *m, registerdata *rd)
                (rd->savintregcnt - rd->maxsavintreguse) +
                (rd->savfltregcnt - rd->maxsavfltreguse) +
                rd->maxmemuse +
-               m->paramcount +
+               m->parseddesc->paramcount +
                1;                           /* index 0 are all other memory accesses */
 
        /* XXX quick hack: just use a fixed number of instructions */
@@ -168,7 +169,7 @@ void schedule_add_define_dep(scheduledata *sd, s1 opnum, edgenode **define_dep,
                                /* link current use node into dependency list */
 
                                useen->minum = minum;
-/*                             useen->opnum2 = opnum; */
+                               useen->opnum2 = opnum;
 
                                /* calculate latency, for define add 1 cycle */
                                useen->latency = (usemi->op[useen->opnum].lastcycle -
@@ -194,7 +195,7 @@ void schedule_add_define_dep(scheduledata *sd, s1 opnum, edgenode **define_dep,
                /* link current define node into dependency list */
 
                defen->minum = minum;
-/*             defen->opnum2 = opnum; */
+               defen->opnum2 = opnum;
 
                /* calculate latency, for define add 1 cycle */
                defen->latency = (defmi->op[defen->opnum].lastcycle -
@@ -249,7 +250,7 @@ void schedule_add_use_dep(scheduledata *sd, s1 opnum, edgenode **define_dep, edg
                en = DNEW(edgenode);
                en->minum = minum;
                en->opnum = defen->opnum;
-/*             en->opnum2 = opnum; */
+               en->opnum2 = opnum;
 
                /* calculate latency */
                en->latency = (defmi->op[defen->opnum].lastcycle -
@@ -501,9 +502,64 @@ void schedule_do_schedule(scheduledata *sd)
 
                schedule_calc_priorities(sd);
 
-#if 1
+               if (opt_verbose) {
+                       printf("bb start ---\n");
+                       printf("nodes: %d\n", sd->micount);
+                       printf("leaders: ");
+               }
+
+               leaders = 0;
+               criticalpath = 0;
+
+               en = sd->leaders;
+               while (en) {
+                       if (opt_verbose) {
+                               printf("#%d ", en->minum);
+                       }
+
+                       leaders++;
+                       if (sd->mi[en->minum].priority > criticalpath)
+                               criticalpath = sd->mi[en->minum].priority;
+                       en = en->next;
+               }
+
+               /* check last node for critical path (e.g. ret) */
+
+               if (sd->mi[sd->micount - 1].priority > criticalpath)
+                       criticalpath = sd->mi[sd->micount - 1].priority;
+               
+               if (opt_verbose) {
+                       printf("\n");
+                       printf("critical path: %d\n", criticalpath);
+
+                       for (i = 0, mi = sd->mi; i < sd->micount; i++, mi++) {
+                               disassinstr(stdout, &mi->instr);
+
+                               printf("\t--> #%d, prio=%d", i, mi->priority);
+
+                               printf(", mem=%d:%d", mi->op[0].firstcycle, mi->op[0].lastcycle);
+
+                               for (j = 1; j <= 3; j++) {
+                                       printf(", op%d=%d:%d", j, mi->op[j].firstcycle, mi->op[j].lastcycle);
+                               }
+
+                               printf(", deps= ");
+                               en = mi->deps;
+                               while (en) {
+                                       printf("#%d (op%d->op%d: %d) ", en->minum, en->opnum, en->opnum2, en->latency);
+                                       en = en->next;
+                               }
+                               printf("\n");
+                       }
+                       printf("bb end ---\n\n");
+
+                       schedule_create_graph(sd, criticalpath);
+               }
+
+
                /* set start time to zero */
 
+               printf("\n\nschedule start ---\n");
                time = 0;
                schedulecount = 0;
 
@@ -563,7 +619,6 @@ void schedule_do_schedule(scheduledata *sd)
 
                                                } else if ((mi->flags & SCHEDULE_UNIT_MEM) &&
                                                                   (!memmi || (mi->priority > memmi->priority))) {
-
                                                        if (preven)
                                                                if (memmi) {
                                                                        preven->next = memen;
@@ -584,18 +639,15 @@ void schedule_do_schedule(scheduledata *sd)
 
                                                /* check for a suitable BRANCH instruction */
 
-                                               } else if (mi->flags & SCHEDULE_UNIT_BRANCH) {
-                                                       if (!brmi || (mi->priority > brmi->priority)) {
-                                                               brmi = mi;
-                                                               bren = en;
-
-                                                               /* remove current node from leaders list */
+                                               } else if ((mi->flags & SCHEDULE_UNIT_BRANCH) &&
+                                                                  (!brmi || (mi->priority > brmi->priority))) {
+                                                       if (preven)
+                                                               preven->next = en->next;
+                                                       else
+                                                               sd->leaders = en->next;
 
-                                                               if (preven)
-                                                                       preven->next = en->next;
-                                                               else
-                                                                       sd->leaders = en->next;
-                                                       }
+                                                       memmi = mi;
+                                                       memen = en;
 
                                                } else
                                                        preven = en;
@@ -657,65 +709,9 @@ void schedule_do_schedule(scheduledata *sd)
 
                        time++;
                }
+               printf("schedule end ---\n\n");
 
-#else
-               if (opt_verbose) {
-                       printf("bb start ---\n");
-                       printf("nodes: %d\n", sd->micount);
-                       printf("leaders: ");
-               }
-
-               leaders = 0;
-               criticalpath = 0;
-
-               nl = sd->leaders;
-               while (nl) {
-
-                       if (opt_verbose) {
-                               printf("#%d ", nl->minum);
-                       }
-
-                       leaders++;
-                       if (sd->mi[nl->minum].priority > criticalpath)
-                               criticalpath = sd->mi[nl->minum].priority;
-                       nl = nl->next;
-               }
-
-               /* check last node for critical path (e.g. ret) */
-
-               if (sd->mi[sd->micount - 1].priority > criticalpath)
-                       criticalpath = sd->mi[sd->micount - 1].priority;
-               
-               if (opt_verbose) {
-                       printf("\n");
-                       printf("critical path: %d\n", criticalpath);
-
-                       for (i = 0, mi = sd->mi; i < sd->micount; i++, mi++) {
-                               disassinstr(stdout, &mi->instr);
-
-                               printf("\t--> #%d, prio=%d", i, mi->priority);
-
-                               printf(", mem=%d:%d", mi->op[0].firstcycle, mi->op[0].lastcycle);
-
-                               for (j = 1; j <= 3; j++) {
-                                       printf(", op%d=%d:%d", j, mi->op[j].firstcycle, mi->op[j].lastcycle);
-                               }
-
-                               printf(", deps= ");
-                               nl = mi->deps;
-                               while (nl) {
-                                       printf("#%d (op%d->op%d: %d) ", nl->minum, nl->opnum, nl->opnum2, nl->latency);
-                                       nl = nl->next;
-                               }
-                               printf("\n");
-                       }
-                       printf("bb end ---\n\n");
-
-                       schedule_create_graph(sd, criticalpath);
-               }
-#endif
-
-#if defined(STATISTICS)
+#if defined(ENABLE_STATISTICS)
                if (opt_stat) {
                        count_schedule_basic_blocks++;
                        count_schedule_nodes += sd->micount;