bearch: Disallow passing Projs to get_irn_ops().
[libfirm] / ir / stat / dags.c
index 2ae134c..ffbea71 100644 (file)
@@ -1,27 +1,12 @@
 /*
- * 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.
+ * Copyright (C) 2012 University of Karlsruhe.
  */
 
 /**
  * @file
  * @brief   Statistics for Firm. DAG's in graphs.
  * @author  Michael Beck
- * @version $Id$
  */
 #include "config.h"
 
@@ -31,6 +16,7 @@
 #include "irdump.h"
 #include "dags.h"
 #include "irtools.h"
+#include "ircons.h"
 
 enum dag_counting_options_t {
        FIRMSTAT_COPY_CONSTANTS = 0x00000001,  /**< if set, constants will be treated as they are in
@@ -71,9 +57,9 @@ struct dag_entry_t {
 /**
  * return an DAG entry for the node n
  */
-static dag_entry_t *get_irn_dag_entry(ir_node *n)
+static dag_entry_t *get_irn_dag_entry(const ir_node *n)
 {
-       dag_entry_t *p = get_irn_link(n);
+       dag_entry_t *p = (dag_entry_t*)get_irn_link(n);
 
        if (p) {
                /* skip any dead links */
@@ -81,11 +67,12 @@ static dag_entry_t *get_irn_dag_entry(ir_node *n)
                        do {
                                p = p->link;
                        } while (p->link != NULL);
-                       set_irn_link(n, p);
+                       /* hacky cast to ir_node* */
+                       set_irn_link((ir_node*)n, p);
                }
-       }  /* if */
+       }
        return p;
-}  /* get_irn_dag_entry */
+}
 
 #define set_irn_dag_entry(n, e) set_irn_link(n, e)
 
@@ -103,7 +90,7 @@ static int is_arg(ir_node *node)
 
        node = get_Proj_pred(node);
        return is_Start(node);
-}  /* is_arg */
+}
 
 /**
  * Allocate a new DAG entry.
@@ -127,14 +114,14 @@ static dag_entry_t *new_dag_entry(dag_env_t *dag_env, ir_node *node)
 
        set_irn_dag_entry(node, entry);
        return entry;
-}  /* new_dag_entry */
+}
 
 /**
  * Post-walker to detect DAG roots that are referenced form other blocks
  */
 static void find_dag_roots(ir_node *node, void *env)
 {
-       dag_env_t   *dag_env = env;
+       dag_env_t   *dag_env = (dag_env_t*)env;
        int         i, arity;
        dag_entry_t *entry;
        ir_node     *block;
@@ -145,10 +132,9 @@ static void find_dag_roots(ir_node *node, void *env)
        block = get_nodes_block(node);
 
        /* ignore start end end blocks */
-       if (block == get_irg_start_block(current_ir_graph) ||
-               block == get_irg_end_block(current_ir_graph)) {
+       ir_graph *const irg = get_Block_irg(block);
+       if (block == get_irg_start_block(irg) || block == get_irg_end_block(irg))
                return;
-       }  /* if */
 
        /* Phi nodes always references nodes from "other" block */
        if (is_Phi(node)) {
@@ -162,7 +148,7 @@ static void find_dag_roots(ir_node *node, void *env)
                                if (dag_env->options & FIRMSTAT_COPY_CONSTANTS) {
                                        if (is_irn_constlike(prev))
                                                continue;
-                               }  /* if */
+                               }
 
                                entry = get_irn_dag_entry(prev);
 
@@ -170,9 +156,9 @@ static void find_dag_roots(ir_node *node, void *env)
                                        /* found an unassigned node, a new root */
                                        entry = new_dag_entry(dag_env, node);
                                        entry->is_ext_ref = 1;
-                               }  /* if */
-                       }  /* for */
-               }  /* if */
+                               }
+                       }
+               }
        } else {
 
                for (i = 0, arity = get_irn_arity(node); i < arity; ++i) {
@@ -188,7 +174,7 @@ static void find_dag_roots(ir_node *node, void *env)
                                if (dag_env->options & FIRMSTAT_COPY_CONSTANTS) {
                                        if (is_irn_constlike(prev))
                                                continue;
-                               }  /* if */
+                               }
 
                                if (get_nodes_block(prev) != block) {
                                        /* The predecessor is from another block. It forms
@@ -198,18 +184,18 @@ static void find_dag_roots(ir_node *node, void *env)
                                                /* found an unassigned node, a new root */
                                                entry = new_dag_entry(dag_env, node);
                                                entry->is_ext_ref = 1;
-                                       }  /* if */
-                               }  /* if */
-                       }  /* for */
-       }  /* if */
-}  /* find_dag_roots */
+                                       }
+                               }
+                       }
+       }
+}
 
 /**
  * Pre-walker for connecting DAGs and counting.
  */
 static void connect_dags(ir_node *node, void *env)
 {
-       dag_env_t   *dag_env = env;
+       dag_env_t   *dag_env = (dag_env_t*)env;
        int         i, arity;
        ir_node     *block;
        dag_entry_t *entry;
@@ -221,10 +207,9 @@ static void connect_dags(ir_node *node, void *env)
        block = get_nodes_block(node);
 
        /* ignore start end end blocks */
-       if (block == get_irg_start_block(current_ir_graph) ||
-               block == get_irg_end_block(current_ir_graph)) {
+       ir_graph *const irg = get_Block_irg(block);
+       if (block == get_irg_start_block(irg) || block == get_irg_end_block(irg))
                return;
-       }  /* if */
 
        /* ignore Phi nodes */
        if (is_Phi(node))
@@ -237,7 +222,7 @@ static void connect_dags(ir_node *node, void *env)
        if (mode == mode_X || mode == mode_M) {
                /* do NOT count mode_X and mode_M nodes */
                return;
-       }  /* if */
+       }
 
        /* if this option is set, Loads are always leaves */
        if (dag_env->options & FIRMSTAT_LOAD_IS_LEAVE && is_Load(node))
@@ -251,7 +236,7 @@ static void connect_dags(ir_node *node, void *env)
        if (! entry) {
                /* found an unassigned node, maybe a new root */
                entry = new_dag_entry(dag_env, node);
-       }  /* if */
+       }
 
        /* put the predecessors into the same DAG as the current */
        for (i = 0, arity = get_irn_arity(node); i < arity; ++i) {
@@ -273,8 +258,8 @@ static void connect_dags(ir_node *node, void *env)
                        if (is_irn_constlike(prev)) {
                                ++entry->num_nodes;
                                ++entry->num_inner_nodes;
-                       }  /* if */
-               }  /* if */
+                       }
+               }
 
                /* only nodes from the same block goes into the DAG */
                if (get_nodes_block(prev) == block) {
@@ -302,11 +287,11 @@ static void connect_dags(ir_node *node, void *env)
 
                                        prev_entry->is_dead = 1;
                                        prev_entry->link    = entry;
-                               }  /* if */
-                       }  /* if */
-               }  /* if */
-       }  /* for */
-}  /* connect_dags */
+                               }
+                       }
+               }
+       }
+}
 
 #define DEFAULT_RET     1
 #define COLOR_RET       1
@@ -316,27 +301,23 @@ static unsigned mark_options;
 /**
  * a vcg attribute hook
  */
-static int stat_dag_mark_hook(FILE *F, ir_node *n, ir_node *l)
+static int stat_dag_mark_hook(FILE *F, const ir_node *n, const ir_node *l)
 {
        static const char *colors[] = { "purple", "pink", "lightblue", "orange", "khaki", "orchid", "lilac", "turquoise" };
        dag_entry_t *entry;
 
        /* do not count Bad / NoMem */
        if (l) {
-               ir_op *op = get_irn_op(l);
-
-               if (op == op_NoMem || op == op_Bad)
+               if (is_NoMem(l) || is_Bad(l))
                        return DEFAULT_RET;
 
                /* check for additional options */
-               op = get_irn_op(n);
-
-               if (mark_options & FIRMSTAT_LOAD_IS_LEAVE && op == op_Load)
+               if (mark_options & FIRMSTAT_LOAD_IS_LEAVE && is_Load(n))
                        return DEFAULT_RET;
 
-               if (mark_options & FIRMSTAT_CALL_IS_LEAVE && op == op_Call)
+               if (mark_options & FIRMSTAT_CALL_IS_LEAVE && is_Call(n))
                        return DEFAULT_RET;
-       }  /* if */
+       }
 
        entry = get_irn_dag_entry(n);
        if (! entry)
@@ -346,7 +327,7 @@ static int stat_dag_mark_hook(FILE *F, ir_node *n, ir_node *l)
 
        /* I know the color! */
        return COLOR_RET;
-}  /* stat_dag_mark_hook */
+}
 
 /**
  * count the DAG's size of a graph
@@ -391,19 +372,17 @@ void count_dags_in_graph(graph_entry_t *global, graph_entry_t *graph)
                        entry->num_roots,
                        entry->num_nodes,
                        entry->num_inner_nodes,
-                       entry->is_tree,
+                       (unsigned)entry->is_tree,
                        get_irn_node_nr(entry->root));
-       }  /* for */
+       }
 
-#if 1
        /* dump for test */
        mark_options = root_env.options;
        set_dump_node_vcgattr_hook(stat_dag_mark_hook);
-       dump_ir_graph(graph->irg, "-dag");
+       dump_ir_graph(graph->irg, "dag");
        set_dump_node_vcgattr_hook(NULL);
-#endif
 
        assert(id == root_env.num_of_dags);
 
        obstack_free(&root_env.obst, NULL);
-}  /* count_dags_in_graph */
+}