typo
[libfirm] / ir / be / beschedtrace.c
index 55a47ad..5bb8d72 100644 (file)
@@ -1,5 +1,5 @@
 /*
- * Copyright (C) 1995-2007 University of Karlsruhe.  All right reserved.
+ * Copyright (C) 1995-2008 University of Karlsruhe.  All right reserved.
  *
  * This file is part of libFirm.
  *
@@ -24,9 +24,7 @@
  * @date        28.08.2006
  * @version     $Id$
  */
-#ifdef HAVE_CONFIG_H
 #include "config.h"
-#endif
 
 #include <stdlib.h>
 
@@ -52,7 +50,6 @@ typedef struct _trace_irn {
 
 typedef struct _trace_env {
        trace_irn_t      *sched_info;               /**< trace scheduling information about the nodes */
-       const arch_env_t *arch_env;                 /**< the arch environment */
        sched_timestep_t curr_time;                 /**< current time of the scheduler */
        void             *selector_env;             /**< the backend selector environment */
        const list_sched_selector_t *selector;      /**< the actual backend selector */
@@ -74,7 +71,7 @@ static ir_node *get_nodeset_node(const ir_nodeset_t *nodeset)
 /**
  * Returns non-zero if the node is a root node
  */
-static INLINE unsigned is_root_node(trace_env_t *env, ir_node *n)
+static inline unsigned is_root_node(trace_env_t *env, ir_node *n)
 {
        int idx = get_irn_idx(n);
 
@@ -85,7 +82,7 @@ static INLINE unsigned is_root_node(trace_env_t *env, ir_node *n)
 /**
  * Mark a node as root node
  */
-static INLINE void mark_root_node(trace_env_t *env, ir_node *n)
+static inline void mark_root_node(trace_env_t *env, ir_node *n)
 {
        int idx = get_irn_idx(n);
 
@@ -96,7 +93,7 @@ static INLINE void mark_root_node(trace_env_t *env, ir_node *n)
 /**
  * Get the current delay.
  */
-static INLINE sched_timestep_t get_irn_delay(trace_env_t *env, ir_node *n) {
+static inline sched_timestep_t get_irn_delay(trace_env_t *env, ir_node *n) {
        int idx = get_irn_idx(n);
 
        assert(idx < ARR_LEN(env->sched_info));
@@ -106,7 +103,7 @@ static INLINE sched_timestep_t get_irn_delay(trace_env_t *env, ir_node *n) {
 /**
  * Set the current delay.
  */
-static INLINE void set_irn_delay(trace_env_t *env, ir_node *n, sched_timestep_t delay) {
+static inline void set_irn_delay(trace_env_t *env, ir_node *n, sched_timestep_t delay) {
        int idx = get_irn_idx(n);
 
        assert(idx < ARR_LEN(env->sched_info));
@@ -116,7 +113,7 @@ static INLINE void set_irn_delay(trace_env_t *env, ir_node *n, sched_timestep_t
 /**
  * Get the current etime.
  */
-static INLINE sched_timestep_t get_irn_etime(trace_env_t *env, ir_node *n) {
+static inline sched_timestep_t get_irn_etime(trace_env_t *env, ir_node *n) {
        int idx = get_irn_idx(n);
 
        assert(idx < ARR_LEN(env->sched_info));
@@ -126,7 +123,7 @@ static INLINE sched_timestep_t get_irn_etime(trace_env_t *env, ir_node *n) {
 /**
  * Set the current etime.
  */
-static INLINE void set_irn_etime(trace_env_t *env, ir_node *n, sched_timestep_t etime) {
+static inline void set_irn_etime(trace_env_t *env, ir_node *n, sched_timestep_t etime) {
        int idx = get_irn_idx(n);
 
        assert(idx < ARR_LEN(env->sched_info));
@@ -136,7 +133,7 @@ static INLINE void set_irn_etime(trace_env_t *env, ir_node *n, sched_timestep_t
 /**
  * Get the number of users.
  */
-static INLINE unsigned get_irn_num_user(trace_env_t *env, ir_node *n) {
+static inline unsigned get_irn_num_user(trace_env_t *env, ir_node *n) {
        int idx = get_irn_idx(n);
 
        assert(idx < ARR_LEN(env->sched_info));
@@ -146,7 +143,7 @@ static INLINE unsigned get_irn_num_user(trace_env_t *env, ir_node *n) {
 /**
  * Set the number of users.
  */
-static INLINE void set_irn_num_user(trace_env_t *env, ir_node *n, unsigned num_user) {
+static inline void set_irn_num_user(trace_env_t *env, ir_node *n, unsigned num_user) {
        int idx = get_irn_idx(n);
 
        assert(idx < ARR_LEN(env->sched_info));
@@ -156,7 +153,7 @@ static INLINE void set_irn_num_user(trace_env_t *env, ir_node *n, unsigned num_u
 /**
  * Get the register difference.
  */
-static INLINE int get_irn_reg_diff(trace_env_t *env, ir_node *n) {
+static inline int get_irn_reg_diff(trace_env_t *env, ir_node *n) {
        int idx = get_irn_idx(n);
 
        assert(idx < ARR_LEN(env->sched_info));
@@ -166,7 +163,7 @@ static INLINE int get_irn_reg_diff(trace_env_t *env, ir_node *n) {
 /**
  * Set the register difference.
  */
-static INLINE void set_irn_reg_diff(trace_env_t *env, ir_node *n, int reg_diff) {
+static inline void set_irn_reg_diff(trace_env_t *env, ir_node *n, int reg_diff) {
        int idx = get_irn_idx(n);
 
        assert(idx < ARR_LEN(env->sched_info));
@@ -176,7 +173,7 @@ static INLINE void set_irn_reg_diff(trace_env_t *env, ir_node *n, int reg_diff)
 /**
  * Get the pre-order position.
  */
-static INLINE int get_irn_preorder(trace_env_t *env, ir_node *n) {
+static inline int get_irn_preorder(trace_env_t *env, ir_node *n) {
        int idx = get_irn_idx(n);
 
        assert(idx < ARR_LEN(env->sched_info));
@@ -186,7 +183,7 @@ static INLINE int get_irn_preorder(trace_env_t *env, ir_node *n) {
 /**
  * Set the pre-order position.
  */
-static INLINE void set_irn_preorder(trace_env_t *env, ir_node *n, int pos) {
+static inline void set_irn_preorder(trace_env_t *env, ir_node *n, int pos) {
        int idx = get_irn_idx(n);
 
        assert(idx < ARR_LEN(env->sched_info));
@@ -196,7 +193,7 @@ static INLINE void set_irn_preorder(trace_env_t *env, ir_node *n, int pos) {
 /**
  * Get the pre-order position.
  */
-static INLINE unsigned get_irn_critical_path_len(trace_env_t *env, ir_node *n) {
+static inline unsigned get_irn_critical_path_len(trace_env_t *env, ir_node *n) {
        int idx = get_irn_idx(n);
 
        assert(idx < ARR_LEN(env->sched_info));
@@ -206,7 +203,7 @@ static INLINE unsigned get_irn_critical_path_len(trace_env_t *env, ir_node *n) {
 /**
  * Set the pre-order position.
  */
-static INLINE void set_irn_critical_path_len(trace_env_t *env, ir_node *n, unsigned len) {
+static inline void set_irn_critical_path_len(trace_env_t *env, ir_node *n, unsigned len) {
        int idx = get_irn_idx(n);
 
        assert(idx < ARR_LEN(env->sched_info));
@@ -285,7 +282,7 @@ static int get_reg_difference(trace_env_t *env, ir_node *irn) {
        ir_node *block = get_nodes_block(irn);
 
        if (be_is_Call(irn)) {
-               /* we want calls prefered */
+               /* we want calls preferred */
                return -5;
        }
 
@@ -305,11 +302,9 @@ 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 (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 */
-
-                       ) {
+               if (mode_is_datab(get_irn_mode(in)) &&           /* must be data node */
+                   !arch_irn_is(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++;
                }
        }
@@ -394,8 +389,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_Anchor(succ))
+               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);
@@ -420,7 +423,7 @@ static void trace_preprocess_block(trace_env_t *env, ir_node *block) {
        for (cur_pos = 0, curr = root; curr; curr = get_irn_link(curr), cur_pos++) {
                sched_timestep_t d;
 
-               if (arch_irn_class_is(env->arch_env, curr, branch)) {
+               if (arch_irn_class_is(curr, branch)) {
                        /* assure, that branches can be executed last */
                        d = 0;
                }
@@ -488,11 +491,10 @@ static void trace_update_time(void *data, ir_node *irn) {
  * @return The environment
  */
 static trace_env_t *trace_init(const be_irg_t *birg) {
-       trace_env_t *env = xcalloc(1, sizeof(*env));
+       trace_env_t *env = XMALLOCZ(trace_env_t);
        ir_graph    *irg = be_get_birg_irg(birg);
        int         nn   = get_irg_last_idx(irg);
 
-       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(birg);
@@ -518,13 +520,14 @@ static void trace_free(void *data) {
 /**
  * Simple selector. Just assure that jumps are scheduled last.
  */
-static ir_node *basic_selection(const arch_env_t *arch_env, ir_nodeset_t *ready_set) {
+static ir_node *basic_selection(ir_nodeset_t *ready_set)
+{
        ir_node *irn = NULL;
        ir_nodeset_iterator_t iter;
 
        /* assure that branches and constants are executed last */
        foreach_ir_nodeset(ready_set, irn, iter) {
-               if (! arch_irn_class_is(arch_env, irn, branch)) {
+               if (!arch_irn_class_is(irn, branch)) {
                        return irn;
                }
        }
@@ -576,7 +579,7 @@ static ir_node *muchnik_select(void *block_env, ir_nodeset_t *ready_set, ir_node
                if (cnt == 1) {
                        irn = get_nodeset_node(&ecands);
 
-                       if (arch_irn_class_is(env->arch_env, irn, branch)) {
+                       if (arch_irn_class_is(irn, branch)) {
                                /* BEWARE: don't select a JUMP if others are still possible */
                                goto force_mcands;
                        }
@@ -584,12 +587,12 @@ static ir_node *muchnik_select(void *block_env, ir_nodeset_t *ready_set, ir_node
                }
                else if (cnt > 1) {
                        DB((env->dbg, LEVEL_3, "\tecand = %d, max_delay = %u\n", cnt, max_delay));
-                       irn = basic_selection(env->arch_env, &ecands);
+                       irn = basic_selection(&ecands);
                }
                else {
 force_mcands:
                        DB((env->dbg, LEVEL_3, "\tmcand = %d\n", ir_nodeset_size(&mcands)));
-                       irn = basic_selection(env->arch_env, &mcands);
+                       irn = basic_selection(&mcands);
                }
        }
 
@@ -652,7 +655,7 @@ static ir_node *heuristic_select(void *block_env, ir_nodeset_t *ns, ir_nodeset_t
        /* priority based selection, heuristic inspired by mueller diss */
        foreach_ir_nodeset(ns, irn, iter) {
                /* make sure that branches are scheduled last */
-               if (! arch_irn_class_is(trace_env->arch_env, irn, branch)) {
+               if (!arch_irn_class_is(irn, branch)) {
                        int rdiff = get_irn_reg_diff(trace_env, irn);
                        int sign  = rdiff < 0;
                        int chg   = (rdiff < 0 ? -rdiff : rdiff) << PRIO_CHG_PRESS;
@@ -692,7 +695,7 @@ static ir_node *heuristic_select(void *block_env, ir_nodeset_t *ns, ir_nodeset_t
                DBG((trace_env->dbg, LEVEL_4, "heuristic selected %+F:\n", cand));
        }
        else {
-               cand = basic_selection(trace_env->arch_env, ns);
+               cand = basic_selection(ns);
        }
 
        return cand;