X-Git-Url: http://nsz.repo.hu/git/?a=blobdiff_plain;f=ir%2Fir%2Firgmod.c;h=6a4039aad3d09ff6e69db6482bac5096e382f0e9;hb=8f355cb9b3d20c10f71d1b1e17cbf59a51ced83b;hp=517051172edb8708ffde5a2934cb4bff2f1223f9;hpb=2cbb2203c867a84600d0608b7641895b03fdbd21;p=libfirm diff --git a/ir/ir/irgmod.c b/ir/ir/irgmod.c index 517051172..6a4039aad 100644 --- a/ir/ir/irgmod.c +++ b/ir/ir/irgmod.c @@ -1,15 +1,28 @@ /* - * Project: libFIRM - * File name: ir/ir/irgmod.c - * Purpose: Support for ir graph modification. - * Author: Martin Trapp, Christian Schaefer - * Modified by: Goetz Lindenmaier - * Created: - * CVS-ID: $Id$ - * Copyright: (c) 1998-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 Support for ir graph modification. + * @author Martin Trapp, Christian Schaefer, Goetz Lindenmaier + * @version $Id$ + */ #ifdef HAVE_CONFIG_H # include "config.h" #endif @@ -25,6 +38,7 @@ #include "irhooks.h" #include "iredges_t.h" #include "irtools.h" +#include "error.h" /** * Turns a node into a "useless" Tuple. The Tuple just forms a tuple @@ -32,20 +46,21 @@ * This is useful if a node returning a tuple is removed, but the Projs * extracting values from the tuple are not available. */ -void turn_into_tuple (ir_node *node, int arity) -{ +void turn_into_tuple(ir_node *node, int arity) { assert(node); set_irn_op(node, op_Tuple); if (get_irn_arity(node) == arity) { /* keep old array */ } else { - /* Allocate new array, don't free old in_array, it's on the obstack. */ - ir_node *block = get_nodes_block(node); + /* don't use get_nodes_block here, we allow turn_into_tuple for unpinned nodes */ + ir_node *block = get_irn_n(node, -1); edges_node_deleted(node, current_ir_graph); + /* Allocate new array, don't free old in_array, it's on the obstack. */ node->in = NEW_ARR_D(ir_node *, current_ir_graph->obst, arity+1); /* clear the new in array, else edge_notify tries to delete garbage */ memset(node->in, 0, (arity+1) * sizeof(node->in[0])); - set_nodes_block(node, block); + /* set the block back */ + set_irn_n(node, -1, block); } } @@ -54,8 +69,7 @@ void turn_into_tuple (ir_node *node, int arity) * Since `new' may be bigger than `old' replace `old' * by an op_Id which is smaller than everything. */ -void exchange(ir_node *old, ir_node *nw) -{ +void exchange(ir_node *old, ir_node *nw) { ir_graph *irg; assert(old && nw); @@ -67,12 +81,10 @@ void exchange(ir_node *old, ir_node *nw) hook_replace(old, nw); /* - * If new outs are on, we can skip the id node creation and reroute - * the edges from the old node to the new directly. - */ + * If new outs are on, we can skip the id node creation and reroute + * the edges from the old node to the new directly. + */ if (edges_activated(irg)) { - int i; - /* copy all dependencies from old to new */ add_irn_deps(nw, old); @@ -80,8 +92,7 @@ void exchange(ir_node *old, ir_node *nw) edges_reroute_kind(old, nw, EDGE_KIND_DEP, irg); edges_node_deleted(old, irg); old->op = op_Bad; - } - else { + } else { /* Else, do it the old-fashioned way. */ ir_node *block; @@ -94,9 +105,7 @@ void exchange(ir_node *old, ir_node *nw) block = is_Block(nw) ? nw : get_nodes_block(nw); if (! block) { - DDMN(old); - DDMN(nw); - assert(0 && "cannot find legal block for id"); + panic("cannot find legal block for id"); } } @@ -117,12 +126,12 @@ void exchange(ir_node *old, ir_node *nw) */ static void collect(ir_node *n, void *env) { ir_node *pred; + (void) env; if (is_Phi(n)) { set_irn_link(n, get_irn_link(get_nodes_block(n))); set_irn_link(get_nodes_block(n), n); - } - else if (is_Proj(n)) { + } else if (is_Proj(n)) { pred = n; do { pred = get_Proj_pred(pred); @@ -202,12 +211,21 @@ void part_block(ir_node *node) { set_irn_link(new_block, phi); set_irn_link(old_block, NULL); while (phi) { - if(get_nodes_block(phi) == old_block); /* @@@ inlinening chokes on phis that don't - obey this condition. How do they get into - the list??? Example: InterfaceIII */ set_nodes_block(phi, new_block); phi = get_irn_link(phi); } set_optimize(rem_opt); } + +/* kill a node by setting its predecessors to Bad and finally exchange the node by Bad itself. */ +void kill_node(ir_node *node) { + ir_graph *irg = get_irn_irg(node); + ir_node *bad = get_irg_bad(irg); + int i; + + for (i = get_irn_arity(node) - 1; i >= -1; --i) { + set_irn_n(node, i, bad); + } + exchange(node, bad); +}