- removed useless be_req_t which was a wrapper around an arch_register_req_t
[libfirm] / ir / be / beschedregpress.c
index dc8c04c..5f5e659 100644 (file)
@@ -1,15 +1,36 @@
+/*
+ * 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.
+ */
+
 /**
- * Regpressure node selector.
- * Originally implemented by Sebastian Hack.
- * @author Christian Wuerdig
- * @date   29.08.2006
- * @cvs-id $Id$
+ * @file
+ * @brief       Register pressure node selector.
+ * @author      Sebastian Hack
+ * @date        29.08.2006
+ * @version     $Id$
  */
+#include "config.h"
 
 #include <stdlib.h>
 
 #include "iredges_t.h"
 #include "irgwalk.h"
+#include "irtools.h"
 
 #include "besched_t.h"
 #include "belistsched.h"
@@ -27,14 +48,13 @@ typedef struct _usage_stats_t {
 
 typedef struct {
        const list_sched_selector_t *vtab;
-       const arch_env_t *arch_env;
 } reg_pressure_main_env_t;
 
 typedef struct {
        struct obstack obst;
        const reg_pressure_main_env_t *main_env;
        usage_stats_t *root;
-       nodeset *already_scheduled;
+       ir_nodeset_t already_scheduled;
 } reg_pressure_selector_env_t;
 
 
@@ -66,7 +86,7 @@ static int cmp_usage(const void *a, const void *b)
 }
 #endif
 
-static INLINE usage_stats_t *get_or_set_usage_stats(reg_pressure_selector_env_t *env, ir_node *irn)
+static inline usage_stats_t *get_or_set_usage_stats(reg_pressure_selector_env_t *env, ir_node *irn)
 {
        usage_stats_t *us = get_irn_link(irn);
 
@@ -83,7 +103,7 @@ static INLINE usage_stats_t *get_or_set_usage_stats(reg_pressure_selector_env_t
        return us;
 }
 
-static INLINE usage_stats_t *get_usage_stats(ir_node *irn)
+static inline usage_stats_t *get_usage_stats(ir_node *irn)
 {
        usage_stats_t *us = get_irn_link(irn);
        assert(us && "This node must have usage stats");
@@ -104,7 +124,7 @@ static int max_hops_walker(reg_pressure_selector_env_t *env, ir_node *irn, ir_no
        * If the node is in the current block but not
        * yet scheduled, we keep on searching from that node.
        */
-       if(!nodeset_find(env->already_scheduled, irn)) {
+       if(!ir_nodeset_contains(&env->already_scheduled, irn)) {
                int i, n;
                int res = 0;
                for(i = 0, n = get_irn_ins_or_deps(irn); i < n; ++i) {
@@ -151,18 +171,17 @@ static int compute_max_hops(reg_pressure_selector_env_t *env, ir_node *irn)
        return res;
 }
 
-static void *reg_pressure_graph_init(const list_sched_selector_t *vtab, const arch_env_t *arch_env, ir_graph *irg)
+static void *reg_pressure_graph_init(const list_sched_selector_t *vtab, const be_irg_t *birg)
 {
-       reg_pressure_main_env_t *main_env = xmalloc(sizeof(main_env[0]));
+       reg_pressure_main_env_t *main_env = XMALLOC(reg_pressure_main_env_t);
 
-       main_env->arch_env = arch_env;
-       main_env->vtab     = vtab;
-       irg_walk_graph(irg, firm_clear_link, NULL, NULL);
+       main_env->vtab = vtab;
+       irg_walk_graph(be_get_birg_irg(birg), firm_clear_link, NULL, NULL);
 
        return main_env;
 }
 
-static INLINE int must_appear_in_schedule(const list_sched_selector_t *sel, void *block_env, const ir_node *irn)
+static inline int must_appear_in_schedule(const list_sched_selector_t *sel, void *block_env, const ir_node *irn)
 {
        int res = -1;
 
@@ -175,10 +194,10 @@ static INLINE int must_appear_in_schedule(const list_sched_selector_t *sel, void
 static void *reg_pressure_block_init(void *graph_env, ir_node *bl)
 {
        ir_node *irn;
-       reg_pressure_selector_env_t *env  = xmalloc(sizeof(env[0]));
+       reg_pressure_selector_env_t *env = XMALLOC(reg_pressure_selector_env_t);
 
        obstack_init(&env->obst);
-       env->already_scheduled = new_nodeset(32);
+       ir_nodeset_init(&env->already_scheduled);
        env->root              = NULL;
        env->main_env          = graph_env;
 
@@ -216,7 +235,7 @@ static void reg_pressure_block_free(void *block_env)
                set_irn_link(us->irn, NULL);
 
        obstack_free(&env->obst, NULL);
-       del_nodeset(env->already_scheduled);
+       ir_nodeset_destroy(&env->already_scheduled);
        free(env);
 }
 
@@ -237,7 +256,7 @@ static int get_result_hops_sum(reg_pressure_selector_env_t *env, ir_node *irn)
        return res;
 }
 
-static INLINE int reg_pr_costs(reg_pressure_selector_env_t *env, ir_node *irn)
+static inline int reg_pr_costs(reg_pressure_selector_env_t *env, ir_node *irn)
 {
        int i, n;
        int sum = 0;
@@ -254,20 +273,24 @@ static INLINE int reg_pr_costs(reg_pressure_selector_env_t *env, ir_node *irn)
        return sum;
 }
 
-static ir_node *reg_pressure_select(void *block_env, nodeset *ready_set, nodeset *live_set)
+static ir_node *reg_pressure_select(void *block_env, ir_nodeset_t *ready_set,
+                                    ir_nodeset_t *live_set)
 {
+       ir_nodeset_iterator_t iter;
        reg_pressure_selector_env_t *env = block_env;
        ir_node *irn, *res     = NULL;
        int curr_cost          = INT_MAX;
+       (void) live_set;
 
-       assert(nodeset_count(ready_set) > 0);
+       assert(ir_nodeset_size(ready_set) > 0);
 
-       for (irn = nodeset_first(ready_set); irn; irn = nodeset_next(ready_set)) {
+       ir_nodeset_iterator_init(&iter, ready_set);
+       while( (irn = ir_nodeset_iterator_next(&iter)) != NULL) {
                /*
                Ignore branch instructions for the time being.
                They should only be scheduled if there is nothing else.
                */
-               if (! arch_irn_class_is(env->main_env->arch_env, irn, branch)) {
+               if (!arch_irn_class_is(irn, branch)) {
                        int costs = reg_pr_costs(env, irn);
                        if (costs <= curr_cost) {
                                res       = irn;
@@ -282,17 +305,17 @@ static ir_node *reg_pressure_select(void *block_env, nodeset *ready_set, nodeset
        */
 
        if(!res) {
-               res = nodeset_first(ready_set);
-               nodeset_break(ready_set);
+               ir_nodeset_iterator_init(&iter, ready_set);
+               res = ir_nodeset_iterator_next(&iter);
 
                assert(res && "There must be a node scheduled.");
        }
 
-       nodeset_insert(env->already_scheduled, res);
+       ir_nodeset_insert(&env->already_scheduled, res);
        return res;
 }
 
-static const list_sched_selector_t reg_pressure_selector_struct = {
+const list_sched_selector_t reg_pressure_selector = {
        reg_pressure_graph_init,
        reg_pressure_block_init,
        reg_pressure_select,
@@ -304,5 +327,3 @@ static const list_sched_selector_t reg_pressure_selector_struct = {
        reg_pressure_block_free,
        free
 };
-
-const list_sched_selector_t *reg_pressure_selector = &reg_pressure_selector_struct;