X-Git-Url: http://nsz.repo.hu/git/?a=blobdiff_plain;f=ir%2Fcommon%2Ffirmwalk.c;h=ff02992e44bf0f4178ef650a5652958eed5c280f;hb=0cc8bfc863da28d3799e9eca1d1765d564b6e573;hp=a0d7ee7b56eeb139680bf506ed4e771f2323d640;hpb=ee1890dea4f8d9627c0f761ded67bbc93e332b85;p=libfirm diff --git a/ir/common/firmwalk.c b/ir/common/firmwalk.c index a0d7ee7b5..ff02992e4 100644 --- a/ir/common/firmwalk.c +++ b/ir/common/firmwalk.c @@ -1,20 +1,36 @@ /* - * Project: libFIRM - * File name: ir/common/firmwalk.c - * Purpose: Walker that touches all Firm data structures - * Author: Sebastian Felis - * Modified by: - * Created: 7.2003 - * CVS-ID: $Id$ - * Copyright: (c) 2003 Universität Karlsruhe - * Licence: This file protected by GPL - GNU GENERAL PUBLIC LICENSE. + * 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. */ +/** + * @file + * @brief Walker that touches all Firm data structures + * @author Sebastian Felis + * @date 7.2003 + * @version $Id$ + */ #ifdef HAVE_CONFIG_H -# include +# include "config.h" #endif -#include +#ifdef HAVE_STRING_H +# include +#endif #include "firmwalk.h" @@ -22,6 +38,7 @@ #include "irnode_t.h" #include "irprog_t.h" #include "irgwalk.h" +#include "irtools.h" #include "array.h" #include "obst.h" @@ -30,8 +47,6 @@ /** obstack for firm walker */ static struct obstack fw_obst; -/** This map stores all types of firm */ -static pmap *mode_map = NULL; /** This map stores all types of firm */ static pmap *type_map = NULL; /** This map stores all entities of firm */ @@ -203,17 +218,10 @@ void *get_firm_walk_link(void *thing) } } -/** Set link field of a ir node to NULL */ -static -void fw_clear_link(ir_node * node, void * env) -{ - set_irn_link(node, NULL); -} - /** Fill maps of type and entity. * This function will be called by the firm walk initializer * to collect all types and entities of program's firm ir. - * All types will be colleced in the hash table type_map + * All types will be collected in the hash table type_map * and all entity are stored in entity_map. The mode of an * type will be collected as well. * @@ -221,33 +229,26 @@ void fw_clear_link(ir_node * node, void * env) * @param env Environment pointer (currently unused) */ static -void fw_collect_tore(type_or_ent *tore, void *env) +void fw_collect_tore(type_or_ent tore, void *env) { - ir_mode *mode; - type *tp; - entity *ent; + ir_type *tp; + ir_entity *ent; - switch (get_kind(tore)) { + switch (get_kind(tore.ent)) { case k_entity: - ent = (entity *)tore; + ent = tore.ent; /* append entity to list */ set_entity_link(ent, NULL); if (!pmap_contains(entity_map, ent)) pmap_insert(entity_map, ent, env); break; case k_type: - tp = (type *)tore; - mode = get_type_mode(tp); + tp = tore.typ; + /* append type to list */ set_type_link(tp, NULL); if (!pmap_contains(type_map, tp)) pmap_insert(type_map, tp, env); - - /* insert only modes (non atomic types, i.e. class, array or struct - have no mode. The link field will be cleared in the walk_do_mode() - callback function. */ - if ((NULL != mode) && (!pmap_contains(mode_map, mode))) - pmap_insert(mode_map, mode, env); break; default: break; } @@ -265,23 +266,16 @@ static void fw_collect_irn(ir_node *irn, void *env) { fw_data *data; - ir_mode *mode = get_irn_mode(irn); - - /* The link field will be cleared in the walk_do_mode() - callback function. */ - if ((NULL != mode) && (!pmap_contains(mode_map, mode))) - pmap_insert(mode_map, mode, env); + (void) env; /* block nodes. */ - if (is_Block(irn)) - { + if (is_Block(irn)) { /* add this block to ir graph's block list */ data = fw_get_data(get_current_ir_graph()); ARR_APP1(ir_node *, FW_GET_DATA_LIST(data), irn); } /* non block nodes */ - else - { + else { /* add this node to block's node list */ ir_node *block = get_nodes_block(irn); data = fw_get_data(block); @@ -293,6 +287,7 @@ void fw_collect_irn(ir_node *irn, void *env) static void fw_free_colleted_data(ir_node *irn, void *env) { + (void) env; /* Free node list from blocks */ if (is_Block(irn)) { @@ -312,55 +307,28 @@ void firm_walk_init(firm_walk_flags flags) /* init obstack */ obstack_init(&fw_obst); - /* Init map of modes and lists of type and entity. If map or list - allready exists, free it. */ - if (mode_map) - { - pmap_destroy(mode_map); - } - mode_map = pmap_create(); - + /* Init map of type and entity. If map or list + already exists, free it. */ if (type_map) - { pmap_destroy(type_map); - } type_map = pmap_create(); if (entity_map) - { pmap_destroy(entity_map); - } entity_map = pmap_create(); - /* insert internal modes to mode hash. The link field will be cleared - in the walk_do_mode() callback function. - Other used modes are added by collecting types */ - - /* - ### RG: should be done by inspection the mode of all irn - - pmap_insert(mode_map, mode_BB, NULL); - pmap_insert(mode_map, mode_T, NULL); - pmap_insert(mode_map, mode_ANY, NULL); - pmap_insert(mode_map, mode_BAD, NULL); - pmap_insert(mode_map, mode_X, NULL); - pmap_insert(mode_map, mode_M, NULL); - pmap_insert(mode_map, mode_b, NULL); - */ - /* Collect all types (also unused types) if flag is set */ if (FW_WITH_ALL_TYPES & flags) type_walk(fw_collect_tore, NULL, NULL); /* for each ir graph */ - for (i = 0; i < get_irp_n_irgs(); i++) - { + for (i = get_irp_n_irgs() - 1; i >= 0; --i) { ir_graph *irg = get_irp_irg(i); set_irg_link(irg, NULL); type_walk_irg(irg, fw_collect_tore, NULL, NULL); - irg_walk_graph(irg, fw_clear_link, fw_collect_irn, NULL); + irg_walk_graph(irg, firm_clear_link, fw_collect_irn, NULL); } } @@ -371,8 +339,6 @@ void firm_walk_finalize(void) int i; /* free all used maps and lists */ - pmap_destroy(mode_map); - mode_map = NULL; pmap_destroy(type_map); type_map = NULL; pmap_destroy(entity_map); @@ -393,8 +359,8 @@ void firm_walk_finalize(void) /** Dumps the firm ir. * * After initializing the firm walker by calling firm_walk_init() - * the firm structure could be accessed by definign the firm walk interface - * wif. This function could be called serveral times to customize the + * the firm structure could be accessed by defining the firm walk interface + * wif. This function could be called several times to customize the * walk order or definitions. * * @param wif Walk interface which contains the callback function @@ -402,7 +368,7 @@ void firm_walk_finalize(void) * @see firm_walk_interface */ void firm_walk(firm_walk_interface *wif) { - int irg_i, block_i, block_list_len, irn_i, irn_list_len; + int mode_i, irg_i, block_i, block_list_len, irn_i, irn_list_len; pmap_entry *entry; fw_data *data; ir_node *block, **block_list, **irn_list; @@ -414,11 +380,8 @@ void firm_walk(firm_walk_interface *wif) if (wif->do_mode_init) wif->do_mode_init(wif->env); if (wif->do_mode) { - for (entry = pmap_first(mode_map); entry; entry = pmap_next(mode_map)) - { - set_mode_link((ir_mode*)entry->key, NULL); - wif->do_mode(entry->key, wif->env); - } + for (mode_i = get_irp_n_modes() - 1; mode_i >= 0; --mode_i) + wif->do_mode(get_irp_mode(mode_i), wif->env); } if (wif->do_mode_finalize) wif->do_mode_finalize(wif->env); @@ -427,7 +390,7 @@ void firm_walk(firm_walk_interface *wif) if (wif->do_type) { for (entry = pmap_first(type_map); entry; entry = pmap_next(type_map)) - wif->do_type((type *)entry->key, wif->env); + wif->do_type((ir_type *)entry->key, wif->env); } if (wif->do_type_finalize) wif->do_type_finalize(wif->env); @@ -436,7 +399,7 @@ void firm_walk(firm_walk_interface *wif) if (wif->do_entity) { for (entry = pmap_first(entity_map); entry; entry = pmap_next(entity_map)) - wif->do_entity((entity *)entry->key, wif->env); + wif->do_entity((ir_entity *)entry->key, wif->env); } if (wif->do_entity_finalize) wif->do_entity_finalize(wif->env);