typo fixed
[libfirm] / ir / be / beschedtrace.c
index 8ccfdeb..e64296b 100644 (file)
@@ -1,9 +1,28 @@
+/*
+ * Copyright (C) 1995-2008 University of Karlsruhe.  All right reserved.
+ *
+ * This file is part of libFirm.
+ *
+ * This file may be distributed and/or modified under the terms of the
+ * GNU General Public License version 2 as published by the Free Software
+ * Foundation and appearing in the file LICENSE.GPL included in the
+ * packaging of this file.
+ *
+ * Licensees holding valid libFirm Professional Edition licenses may use
+ * this file in accordance with the libFirm Commercial License.
+ * Agreement provided with the Software.
+ *
+ * This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE
+ * WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+ * PURPOSE.
+ */
+
 /**
- * Implements a trace scheduler as presented in Muchnik[TM].
- * Originally implemented by Michael Beck.
- * @author Christian Wuerdig
- * @date   28.08.2006
- * @cvs-id $Id$
+ * @file
+ * @brief       Implements a trace scheduler as presented in Muchnik[TM].
+ * @author      Michael Beck
+ * @date        28.08.2006
+ * @version     $Id$
  */
 #ifdef HAVE_CONFIG_H
 #include "config.h"
@@ -286,10 +305,13 @@ static int get_reg_difference(trace_env_t *env, ir_node *irn) {
        for (i = get_irn_arity(irn) - 1; i >= 0; i--) {
                ir_node *in = get_irn_n(irn, i);
 
-               if (! be_is_live_end(env->liveness, block, in) &&  /* if the value lives outside of block: do not count */
-                       mode_is_datab(get_irn_mode(in))             &&  /* must be data node */
-                       ! arch_irn_is(env->arch_env, in, ignore))       /* ignore "ignore" nodes :) */
+               if (mode_is_datab(get_irn_mode(in))             &&  /* must be data node */
+                   ! arch_irn_is(env->arch_env, in, ignore)    &&  /* ignore "ignore" nodes :) */
+                   ! be_is_live_end(env->liveness, block, in)      /* if the value lives outside of block: do not count */
+
+                       ) {
                        num_in++;
+               }
        }
 
        return num_out - num_in;
@@ -372,6 +394,16 @@ static void trace_preprocess_block(trace_env_t *env, ir_node *block) {
        foreach_out_edge(block, edge) {
                ir_node *succ = get_edge_src_irn(edge);
 
+               if (is_Block(succ)) {
+                       /* A Block-Block edge. This should be the MacroBlock
+                        * edge, ignore it. */
+                       assert(get_Block_MacroBlock(succ) == block && "Block-Block edge found");
+                       continue;
+               }
+               if (is_Anchor(succ)) {
+                       /* ignore a keep alive edge */
+                       continue;
+               }
                if (is_root(succ, block)) {
                        mark_root_node(env, succ);
                        set_irn_link(succ, root);
@@ -463,16 +495,18 @@ static void trace_update_time(void *data, ir_node *irn) {
  * @param birg   The backend irg object
  * @return The environment
  */
-static trace_env_t *trace_init(const arch_env_t *arch_env, ir_graph *irg) {
+static trace_env_t *trace_init(const be_irg_t *birg) {
        trace_env_t *env = xcalloc(1, sizeof(*env));
+       ir_graph    *irg = be_get_birg_irg(birg);
        int         nn   = get_irg_last_idx(irg);
 
-       env->arch_env   = arch_env;
+       env->arch_env   = be_get_birg_arch_env(birg);
        env->curr_time  = 0;
        env->sched_info = NEW_ARR_F(trace_irn_t, nn);
-       env->liveness   = be_liveness(irg);
+       env->liveness   = be_liveness(birg);
        FIRM_DBG_REGISTER(env->dbg, "firm.be.sched.trace");
 
+       be_liveness_assure_chk(env->liveness);
        memset(env->sched_info, 0, nn * sizeof(*(env->sched_info)));
 
        return env;
@@ -519,6 +553,7 @@ static ir_node *muchnik_select(void *block_env, ir_nodeset_t *ready_set, ir_node
        ir_nodeset_iterator_t iter;
        sched_timestep_t max_delay = 0;
        ir_node *irn;
+       (void) live_set;
 
        /* calculate the max delay of all candidates */
        foreach_ir_nodeset(ready_set, irn, iter) {
@@ -569,11 +604,11 @@ force_mcands:
        return irn;
 }
 
-static void *muchnik_init_graph(const list_sched_selector_t *vtab, const arch_env_t *arch_env, ir_graph *irg)
+static void *muchnik_init_graph(const list_sched_selector_t *vtab, const be_irg_t *birg)
 {
-       trace_env_t *env  = trace_init(arch_env, irg);
+       trace_env_t *env  = trace_init(birg);
        env->selector     = vtab;
-       env->selector_env = (void*) arch_env;
+       env->selector_env = (void*) be_get_birg_arch_env(birg);
        return (void *)env;
 }
 
@@ -583,7 +618,7 @@ static void *muchnik_init_block(void *graph_env, ir_node *bl)
        return graph_env;
 }
 
-static const list_sched_selector_t muchnik_selector_struct = {
+const list_sched_selector_t muchnik_selector = {
        muchnik_init_graph,
        muchnik_init_block,
        muchnik_select,
@@ -596,8 +631,6 @@ static const list_sched_selector_t muchnik_selector_struct = {
        trace_free           /* finish_graph */
 };
 
-const list_sched_selector_t *muchnik_selector = &muchnik_selector_struct;
-
 /**
  * Execute the heuristic function.
  */
@@ -632,7 +665,7 @@ static ir_node *heuristic_select(void *block_env, ir_nodeset_t *ns, ir_nodeset_t
                        int sign  = rdiff < 0;
                        int chg   = (rdiff < 0 ? -rdiff : rdiff) << PRIO_CHG_PRESS;
 
-                       //reg_fact = chg << cur_pressure;
+                       /* reg_fact = chg << cur_pressure; */
                        reg_fact = chg * cur_pressure;
                        if (reg_fact < chg)
                                reg_fact = INT_MAX - 2;
@@ -673,7 +706,7 @@ static ir_node *heuristic_select(void *block_env, ir_nodeset_t *ns, ir_nodeset_t
        return cand;
 }
 
-static const list_sched_selector_t heuristic_selector_struct = {
+const list_sched_selector_t heuristic_selector = {
        muchnik_init_graph,
        muchnik_init_block,
        heuristic_select,
@@ -685,5 +718,3 @@ static const list_sched_selector_t heuristic_selector_struct = {
        NULL,                /* finish_block */
        trace_free           /* finish_graph */
 };
-
-const list_sched_selector_t *heuristic_selector = &heuristic_selector_struct;