X-Git-Url: http://nsz.repo.hu/git/?a=blobdiff_plain;f=ir%2Fbe%2Fbeifg_clique.c;h=1eb410b26a29513156775c80cfc1e2af73b2ad05;hb=7946c76e39669957af8cf9c5a520116eb77b9cb5;hp=4dc57b30d8ffda7900e9571b26224c2159ba44ef;hpb=489fc097405115e806d56e9d9073edb0559d62de;p=libfirm diff --git a/ir/be/beifg_clique.c b/ir/be/beifg_clique.c index 4dc57b30d..1eb410b26 100644 --- a/ir/be/beifg_clique.c +++ b/ir/be/beifg_clique.c @@ -1,10 +1,28 @@ -/** - * @file beifg_clique.c - * @date 18.11.2005 - * @author Sebastian Hack +/* + * Copyright (C) 1995-2007 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. * - * Copyright (C) 2005 Universitaet Karlsruhe - * Released under the GPL + * This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE + * WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR + * PURPOSE. + */ + +/** + * @file + * @brief Clique calculation for chordal ifg. + * @author Sebastian Hack + * @date 18.11.2005 + * @version $Id$ */ #ifdef HAVE_CONFIG_H #include "config.h" @@ -20,38 +38,40 @@ #include "irgwalk.h" #include "irbitset.h" +#include "bearch_t.h" #include "be_t.h" -#include "bera.h" +#include "beintlive_t.h" #include "beifg_t.h" #include "bechordal_t.h" +#include "benodesets.h" typedef struct _cli_head_t { - struct list_head list; + struct list_head list; struct _cli_head_t *next_cli_head; - ir_node *min; - ir_node *max; + ir_node *min; + ir_node *max; } cli_head_t; typedef struct _ifg_clique_t { - const be_ifg_impl_t *impl; + const be_ifg_impl_t *impl; const be_chordal_env_t *env; - cli_head_t *cli_root; - struct obstack obst; - cli_head_t *curr_cli_head; - bitset_t *visited_nodes; - bitset_t *visited_neighbours; + cli_head_t *cli_root; + struct obstack obst; + cli_head_t *curr_cli_head; } ifg_clique_t; typedef struct _cli_element_t { struct list_head list; - ir_node *irn; + ir_node *irn; } cli_element_t; typedef struct _cli_iter_t { - ifg_clique_t *ifg; - cli_head_t *curr_cli_head; - cli_element_t *curr_cli_element; - const ir_node *curr_irn; + const ifg_clique_t *ifg; + cli_head_t *curr_cli_head; + cli_element_t *curr_cli_element; + const ir_node *curr_irn; + bitset_t *visited_neighbours; + bitset_t *visited_nodes; } cli_iter_t; /* PRIVATE FUNCTIONS */ @@ -168,9 +188,6 @@ static cli_head_t *get_next_cli_head(const ir_node *irn, cli_iter_t *it) /* ...c is_dominated_by_max = value_dominates(head->max, irn); //dominates_min = value_dominates(irn, head->min); - if(head->min->node_nr == 2000) - assert("stop"); - if ((is_dominated_by_max) || (irn == head->max)) /* node could be in clique */ { /* check if node is in clique */ @@ -179,9 +196,11 @@ static cli_head_t *get_next_cli_head(const ir_node *irn, cli_iter_t *it) /* ...c if (&element->list != &head->list) { if (element->irn == irn) - { /* node is in clique */ + { + /* node is in clique */ it->curr_cli_head = head; - it->curr_cli_element = (void *) head; /* needed because the next element is searched with list.next of it->curr_cli_element */ + /* needed because the next element is searched with list.next of it->curr_cli_element */ + it->curr_cli_element = (void *) head; break; } } @@ -201,10 +220,11 @@ static cli_head_t *get_next_cli_head(const ir_node *irn, cli_iter_t *it) /* ...c return head; } -static cli_element_t *get_next_element(const ir_node *irn, cli_iter_t *it) /* ... of the current clique, returns NULL if there were no more elements ..*/ +/* ... of the current clique, returns NULL if there were no more elements ..*/ +static cli_element_t *get_next_element(const ir_node *irn, cli_iter_t *it) { cli_element_t *element = it->curr_cli_element; - cli_head_t *head = it->curr_cli_head; + cli_head_t *head = it->curr_cli_head; if (!head || it->curr_cli_element == NULL) /* way back of recursion or there are no more heads */ { @@ -238,12 +258,13 @@ static void find_nodes(const ifg_clique_t *ifg, cli_iter_t *it) cli_element_t *element; cli_head_t *cli_head = ifg->cli_root; - bitset_clear_all(ifg->visited_nodes); - - assert(cli_head && "There is no root entry to work on!"); + bitset_t *bitset_visnodes = bitset_malloc(get_irg_last_idx(ifg->env->irg)); + it->visited_nodes = bitset_visnodes; it->curr_cli_head = cli_head; + assert(cli_head && "There is no root entry to work on!"); + if (cli_head->list.next != &cli_head->list) /* if cli_head contains an element */ { element = list_entry(cli_head->list.next, cli_element_t, list); @@ -289,13 +310,13 @@ static ir_node *get_next_node(cli_iter_t *it) } if (!(irn == NULL)) { - if (bitset_is_set(it->ifg->visited_nodes, get_irn_idx(irn))) + if (bitset_is_set(it->visited_nodes, get_irn_idx(irn))) { irn = get_next_node(it); } if (!(irn == NULL)) { - bitset_set(it->ifg->visited_nodes, get_irn_idx(irn)); + bitset_set(it->visited_nodes, get_irn_idx(irn)); } } @@ -304,20 +325,17 @@ static ir_node *get_next_node(cli_iter_t *it) static void find_neighbour_walker(ir_node *bl, void *data) { - ifg_clique_t *ifg = data; - struct list_head *head = get_block_border_head(ifg->env, bl); - border_t *b; - int was_def = 0; - nodeset *live = new_nodeset(ifg->env->cls->n_regs); + ifg_clique_t *ifg = data; + struct list_head *head = get_block_border_head(ifg->env, bl); + int was_def = 0; + nodeset *live = new_nodeset(ifg->env->cls->n_regs); + border_t *b; assert(is_Block(bl) && "There is no block to work on."); foreach_border_head(head, b) /* follow the borders of the block */ { ir_node *irn = b->irn; -// -// if (b->irn->node_nr == 1869) -// printf(""); if (b->is_def) /* b is a new node */ { @@ -342,8 +360,9 @@ static void find_neighbour_walker(ir_node *bl, void *data) static void find_first_neighbour(const ifg_clique_t *ifg, cli_iter_t *it, const ir_node *irn) { - cli_head_t *cli_head = ifg->cli_root; + cli_head_t *cli_head = ifg->cli_root; cli_element_t *element; + bitset_t *bitset_visneighbours = bitset_malloc(get_irg_last_idx(ifg->env->irg)); int is_dominated_by_max = 0; int dominates_min = 0; @@ -351,7 +370,7 @@ static void find_first_neighbour(const ifg_clique_t *ifg, cli_iter_t *it, const it->curr_cli_head = cli_head; it->ifg = ifg; - bitset_clear_all(it->ifg->visited_neighbours); + it->visited_neighbours = bitset_visneighbours; assert(cli_head && "There is no root entry for a cli_head."); @@ -363,15 +382,12 @@ static void find_first_neighbour(const ifg_clique_t *ifg, cli_iter_t *it, const /* check if node is in clique */ list_for_each_entry(cli_element_t, element, &cli_head->list, list) { - if (&element->list != &cli_head->list) + if (element->irn == irn) /* node is in clique */ { - if (element->irn == irn) - { /* node is in clique */ - it->curr_cli_element = (void *) cli_head; /* needed because the next element is searched with list.next of it->curr_cli_element */ - is_in_clique = 1; - element = get_next_element(irn, it); - break; - } + it->curr_cli_element = (void *) cli_head; /* needed because the next element is searched with list.next of it->curr_cli_element */ + is_in_clique = 1; + element = get_next_element(irn, it); + break; } } } @@ -390,7 +406,6 @@ static void find_first_neighbour(const ifg_clique_t *ifg, cli_iter_t *it, const static ir_node *get_next_neighbour(cli_iter_t *it) { ir_node *res = NULL; - cli_head_t *cli_head = it->curr_cli_head; const ir_node *irn = it->curr_irn; if (it->curr_cli_element != NULL) @@ -402,13 +417,13 @@ static ir_node *get_next_neighbour(cli_iter_t *it) if (res) { - if (bitset_contains_irn(it->ifg->visited_neighbours, res)) + if (bitset_contains_irn(it->visited_neighbours, res)) { res = get_next_neighbour(it); } else { - bitset_set(it->ifg->visited_neighbours, get_irn_idx(res)); + bitset_set(it->visited_neighbours, get_irn_idx(res)); } } @@ -423,14 +438,12 @@ static void ifg_clique_free(void *self) ifg_clique_t *ifg = self; obstack_free(&ifg->obst, NULL); - bitset_free(ifg->visited_neighbours); - bitset_free(ifg->visited_nodes); - free(self); } -static int ifg_clique_connected(const ifg_clique_t *ifg, const ir_node *a, const ir_node *b) +static int ifg_clique_connected(const void *self, const ir_node *a, const ir_node *b) { + const ifg_clique_t *ifg = self; cli_iter_t it; int connected = -1; ir_node *irn = NULL; @@ -459,11 +472,17 @@ static ir_node *ifg_clique_neighbours_begin(const void *self, void *iter, const static ir_node *ifg_clique_neighbours_next(const void *self, void *iter) { + (void) self; return get_next_neighbour(iter); } static void ifg_clique_neighbours_break(const void *self, void *iter) { + cli_iter_t *it = iter; + (void) self; + + bitset_free(it->visited_neighbours); + return; } @@ -475,11 +494,17 @@ static ir_node *ifg_clique_nodes_begin(const void *self, void *iter) static ir_node *ifg_clique_nodes_next(const void *self, void *iter) { + (void) self; return get_next_node(iter); } static void ifg_clique_nodes_break(const void *self, void *iter) { + cli_iter_t *it = iter; + (void) self; + + bitset_free(it->visited_nodes); + return; } @@ -521,10 +546,7 @@ static const be_ifg_impl_t ifg_clique_impl = { be_ifg_t *be_ifg_clique_new(const be_chordal_env_t *env) { ifg_clique_t *ifg = xmalloc(sizeof(*ifg)); - bitset_t *bitset_visnodes = bitset_malloc(get_irg_last_idx(env->irg)); - bitset_t *bitset_visneighbours = bitset_malloc(get_irg_last_idx(env->irg)); - ifg->visited_nodes = bitset_visnodes; - ifg->visited_neighbours = bitset_visneighbours; + ifg->impl = &ifg_clique_impl; ifg->env = env;