X-Git-Url: http://nsz.repo.hu/git/?a=blobdiff_plain;f=ir%2Fir%2Firphase.c;h=cc7a0d9262aec810315c62652b182f7259f673bc;hb=b4647d67ab7885d5da32c2a30242fbc4ed93d81b;hp=28f5ac3788d71d8f52351f81036d214217c28064;hpb=4e99d6de95366ff4467a8152362818f4c5ad946b;p=libfirm diff --git a/ir/ir/irphase.c b/ir/ir/irphase.c index 28f5ac378..cc7a0d926 100644 --- a/ir/ir/irphase.c +++ b/ir/ir/irphase.c @@ -1,73 +1,128 @@ /* - * Project: libFIRM - * File name: ir/ir/irphase.c - * Purpose: Phase information handling using node indexes. - * Author: Sebastian Hack - * Modified by: - * Created: - * CVS-ID: $Id$ - * Copyright: (c) 1998-2006 Universitaet 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. */ -#ifdef _HAVE_CONFIG_H +/** + * @file + * @brief Phase information handling using node indexes. + * @author Sebastian Hack + * @version $Id$ + * @brief + * A phase contains a link to private data for each node in an ir graph. + * A phase is independent from the globally visible link field of ir nodes. + */ #include "config.h" -#endif #include "array.h" +#include "util.h" #include "irnode_t.h" +#include "irgraph_t.h" #include "irphase_t.h" -phase_t *phase_init(phase_t *ph, const char *name, ir_graph *irg, size_t data_size, unsigned growth_factor, phase_irn_data_init_t *data_init) +void *phase_irn_init_default(ir_phase *ph, const ir_node *irn) { - assert(growth_factor >= 1.0 && "growth factor must greater or equal to 1.0"); + (void) ph; + (void) irn; + return NULL; +} - obstack_init(&ph->obst); +void phase_init(ir_phase *phase, ir_graph *irg, phase_irn_init *data_init) +{ + memset(phase, 0, sizeof(*phase)); - ph->name = name; - ph->growth_factor = growth_factor; - ph->data_init = data_init; - ph->data_size = data_size; - ph->irg = irg; - ph->n_data_ptr = 0; - ph->data_ptr = NULL; + obstack_init(&phase->obst); + phase->data_init = data_init; + phase->irg = irg; + phase->n_data_ptr = 0; + phase->data_ptr = NULL; +} - return ph; +ir_phase *new_phase(ir_graph *irg, phase_irn_init *data_init) +{ + ir_phase *phase = xmalloc(sizeof(*phase)); + phase_init(phase, irg, data_init); + return phase; } -void phase_free(phase_t *phase) +void phase_deinit(ir_phase *phase) { obstack_free(&phase->obst, NULL); - if(phase->data_ptr) + if (phase->data_ptr) xfree(phase->data_ptr); } -phase_stat_t *phase_stat(const phase_t *phase, phase_stat_t *stat) +void phase_free(ir_phase *phase) { - int i, n; + phase_deinit(phase); + xfree(phase); +} + +phase_stat_t *phase_stat(const ir_phase *phase, phase_stat_t *stat) +{ + unsigned i, n; memset(stat, 0, sizeof(stat[0])); stat->node_map_bytes = phase->n_data_ptr * sizeof(phase->data_ptr[0]); stat->node_slots = phase->n_data_ptr; - for(i = 0, n = phase->n_data_ptr; i < n; ++i) { - if(phase->data_ptr[i] != NULL) { + for (i = 0, n = phase->n_data_ptr; i < n; ++i) { + if (phase->data_ptr[i] != NULL) { stat->node_slots_used++; - stat->node_data_bytes += phase->data_size; } } - stat->overall_bytes = stat->node_map_bytes + obstack_memory_used(&((phase_t *)phase)->obst); + stat->overall_bytes = stat->node_map_bytes + obstack_memory_used(&((ir_phase *)phase)->obst); return stat; } -void phase_reinit_irn_data(phase_t *phase) +void phase_reinit_irn_data(ir_phase *phase, phase_irn_reinit *data_reinit) { - int i, n; + unsigned i, n; + ir_graph *irg; - if(!phase->data_init) + if (! phase->data_init) return; - for(i = 0, n = phase->n_data_ptr; i < n; ++i) { - if(phase->data_ptr[i]) - phase->data_init(phase, NULL, phase->data_ptr[i]); + irg = phase->irg; + for (i = 0, n = phase->n_data_ptr; i < n; ++i) { + if (phase->data_ptr[i]) { + ir_node *node = get_idx_irn(irg, i); + phase->data_ptr[i] = data_reinit(phase, node, phase->data_ptr[i]); + } } } + +ir_node *phase_get_first_node(const ir_phase *phase) +{ + unsigned i; + + for (i = 0; i < phase->n_data_ptr; ++i) + if (phase->data_ptr[i]) + return get_idx_irn(phase->irg, i); + + return NULL; +} + +ir_node *phase_get_next_node(const ir_phase *phase, ir_node *start) +{ + unsigned i; + + for (i = get_irn_idx(start) + 1; i < phase->n_data_ptr; ++i) + if (phase->data_ptr[i]) + return get_idx_irn(phase->irg, i); + + return NULL; +}