X-Git-Url: http://nsz.repo.hu/git/?a=blobdiff_plain;f=ir%2Fbe%2Fbeifg_std.c;h=a68a86f551c378b336f0bb707fe0527bf75ae74d;hb=5ddb95b789dd1acbc59e04f6771085a544483545;hp=e040888a934d10227eb2ef00e4bd8d3992cd9d01;hpb=48f893878b07f6e334389ff52abda5cc2adbf179;p=libfirm diff --git a/ir/be/beifg_std.c b/ir/be/beifg_std.c index e040888a9..a68a86f55 100644 --- a/ir/be/beifg_std.c +++ b/ir/be/beifg_std.c @@ -1,36 +1,55 @@ -/** - * @file beifg_std.c - * @date 18.11.2005 - * @author Sebastian Hack +/* + * 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. * - * Copyright (C) 2005 Universitaet Karlsruhe - * Released under the GPL + * 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. */ -#ifdef HAVE_CONFIG_H +/** + * @file + * @brief Default ifg implementation. + * @author Sebastian Hack + * @date 18.11.2005 + * @version $Id$ + */ #include "config.h" -#endif #include #include "list.h" #include "irnode_t.h" +#include "irnodeset.h" #include "irgraph_t.h" #include "irgwalk.h" +#include "irtools.h" +#include "bearch.h" #include "be_t.h" #include "belive_t.h" #include "bera.h" #include "beifg_t.h" +#include "beifg_impl.h" #include "bechordal_t.h" - -#define MAX(x, y) ((x) > (y) ? (x) : (y)) +#include "beirg.h" +#include "beintlive_t.h" typedef struct _ifg_std_t ifg_std_t; struct _ifg_std_t { - const be_ifg_impl_t *impl; + const be_ifg_impl_t *impl; const be_chordal_env_t *env; }; @@ -42,33 +61,33 @@ static void ifg_std_free(void *self) static int ifg_std_connected(const void *self, const ir_node *a, const ir_node *b) { const ifg_std_t *ifg = self; - return values_interfere(ifg->env->lv, a, b); + return be_values_interfere(ifg->env->birg->lv, a, b); } typedef struct _nodes_iter_t { const be_chordal_env_t *env; - struct obstack obst; - int n; - int curr; - ir_node **nodes; + struct obstack obst; + int n; + int curr; + ir_node **nodes; } nodes_iter_t; static void nodes_walker(ir_node *bl, void *data) { - nodes_iter_t *it = data; + nodes_iter_t *it = data; struct list_head *head = get_block_border_head(it->env, bl); - - border_t *b; + border_t *b; foreach_border_head(head, b) { - if(b->is_def && b->is_real) { + if (b->is_def && b->is_real) { obstack_ptr_grow(&it->obst, b->irn); it->n++; } } } -static void find_nodes(const void *self, void *iter) { +static void find_nodes(const void *self, void *iter) +{ const ifg_std_t *ifg = self; nodes_iter_t *it = iter; @@ -82,9 +101,9 @@ static void find_nodes(const void *self, void *iter) { it->nodes = obstack_finish(&it->obst); } -static INLINE void node_break(nodes_iter_t *it, int force) +static inline void node_break(nodes_iter_t *it, int force) { - if((it->curr >= it->n || force) && it->nodes) { + if ((it->curr >= it->n || force) && it->nodes) { obstack_free(&it->obst, NULL); it->nodes = NULL; } @@ -95,7 +114,7 @@ static ir_node *get_next_node(void *iter) nodes_iter_t *it = iter; ir_node *res = NULL; - if(it->curr < it->n) + if (it->curr < it->n) res = it->nodes[it->curr++]; node_break(it, 0); @@ -111,19 +130,22 @@ static ir_node *ifg_std_nodes_begin(const void *self, void *iter) static ir_node *ifg_std_nodes_next(const void *self, void *iter) { + (void) self; return get_next_node(iter); } static void ifg_std_nodes_break(const void *self, void *iter) { + (void) self; node_break(iter, 1); } typedef struct _adj_iter_t { const be_chordal_env_t *env; - const ir_node *irn; - int reached_end; - pset *neighbours; + const ir_node *irn; + int valid; + ir_nodeset_t neighbours; + ir_nodeset_iterator_t iter; } adj_iter_t; static void find_neighbour_walker(ir_node *block, void *data) @@ -134,25 +156,25 @@ static void find_neighbour_walker(ir_node *block, void *data) border_t *b; int has_started = 0; - if(!be_is_live_in(it->env->lv, block, it->irn) && block != get_nodes_block(it->irn)) + if (!be_is_live_in(it->env->birg->lv, block, it->irn) && block != get_nodes_block(it->irn)) return; foreach_border_head(head, b) { ir_node *irn = b->irn; - if(irn == it->irn) { - if(b->is_def) + if (irn == it->irn) { + if (b->is_def) has_started = 1; else break; /* if we reached the end of the node's lifetime we can safely break */ } - else if(b->is_def) { + else if (b->is_def) { /* if any other node than the one in question starts living, add it to the set */ - pset_insert_ptr(it->neighbours, irn); + ir_nodeset_insert(&it->neighbours, irn); } - else if(!has_started) { + else if (!has_started) { /* we only delete, if the live range in question has not yet started */ - pset_remove_ptr(it->neighbours, irn); + ir_nodeset_remove(&it->neighbours, irn); } } @@ -162,26 +184,29 @@ static void find_neighbours(const ifg_std_t *ifg, adj_iter_t *it, const ir_node { it->env = ifg->env; it->irn = irn; - it->neighbours = pset_new_ptr(16); - it->reached_end = 0; + it->valid = 1; + ir_nodeset_init(&it->neighbours); dom_tree_walk(get_nodes_block(irn), find_neighbour_walker, NULL, it); + + ir_nodeset_iterator_init(&it->iter, &it->neighbours); } -static INLINE void neighbours_break(adj_iter_t *it, int force) +static inline void neighbours_break(adj_iter_t *it, int force) { - if((it->reached_end || force) && it->neighbours) { - del_pset(it->neighbours); - it->neighbours = NULL; - } + (void) force; + assert(it->valid == 1); + ir_nodeset_destroy(&it->neighbours); + it->valid = 0; } -static ir_node *get_next_neighbour(adj_iter_t *it) { - ir_node *res = pset_next(it->neighbours); - - it->reached_end = res == NULL; - neighbours_break(it, 0); +static ir_node *get_next_neighbour(adj_iter_t *it) +{ + ir_node *res = ir_nodeset_iterator_next(&it->iter); + if (res == NULL) { + ir_nodeset_destroy(&it->neighbours); + } return res; } @@ -189,16 +214,18 @@ static ir_node *ifg_std_neighbours_begin(const void *self, void *iter, const ir_ { adj_iter_t *it = iter; find_neighbours(self, iter, irn); - return pset_first(it->neighbours); + return ir_nodeset_iterator_next(&it->iter); } static ir_node *ifg_std_neighbours_next(const void *self, void *iter) { + (void) self; return get_next_neighbour(iter); } static void ifg_std_neighbours_break(const void *self, void *iter) { + (void) self; neighbours_break(iter, 1); } @@ -212,25 +239,28 @@ typedef struct _cliques_iter_t { pset *living; } cliques_iter_t; -static INLINE void free_clique_iter(cliques_iter_t *it) { +static inline void free_clique_iter(cliques_iter_t *it) +{ it->n_blocks = -1; obstack_free(&it->ob, NULL); del_pset(it->living); } -static void get_blocks_dom_order(ir_node *blk, void *env) { +static void get_blocks_dom_order(ir_node *blk, void *env) +{ cliques_iter_t *it = env; obstack_ptr_grow(&it->ob, blk); } -#define pset_foreach(pset, irn) for(irn=pset_first(pset); irn; irn=pset_next(pset)) +#define pset_foreach(pset, irn) for (irn=pset_first(pset); irn; irn=pset_next(pset)) /** * NOTE: Be careful when changing this function! * First understand the control flow of consecutive calls. */ -static INLINE int get_next_clique(cliques_iter_t *it) { +static inline int get_next_clique(cliques_iter_t *it) +{ /* continue in the block we left the last time */ for (; it->blk < it->n_blocks; it->blk++) { @@ -304,11 +334,13 @@ static int ifg_std_cliques_begin(const void *self, void *iter, ir_node **buf) static int ifg_std_cliques_next(const void *self, void *iter) { + (void) self; return get_next_clique(iter); } static void ifg_std_cliques_break(const void *self, void *iter) { + (void) self; free_clique_iter(iter); } @@ -318,7 +350,7 @@ static int ifg_std_degree(const void *self, const ir_node *irn) adj_iter_t it; int degree; find_neighbours(self, &it, irn); - degree = pset_count(it.neighbours); + degree = ir_nodeset_size(&it.neighbours); neighbours_break(&it, 1); return degree; } @@ -344,7 +376,7 @@ static const be_ifg_impl_t ifg_std_impl = { be_ifg_t *be_ifg_std_new(const be_chordal_env_t *env) { - ifg_std_t *ifg = xmalloc(sizeof(*ifg)); + ifg_std_t *ifg = XMALLOC(ifg_std_t); ifg->impl = &ifg_std_impl; ifg->env = env;