X-Git-Url: http://nsz.repo.hu/git/?a=blobdiff_plain;f=ir%2Fir%2Firgmod.c;h=260e2a8b64ad53a0b579ccc5cc7f559b1d70e367;hb=7d9f1e446adbc3456429dcfc7f8f4e587b8799aa;hp=46a71184ff86419b100622d6f50659e818d6d7a6;hpb=4e3fd9fecccfd54df03b342bd20e1ecd2d5c940f;p=libfirm diff --git a/ir/ir/irgmod.c b/ir/ir/irgmod.c index 46a71184f..260e2a8b6 100644 --- a/ir/ir/irgmod.c +++ b/ir/ir/irgmod.c @@ -1,6 +1,6 @@ /* * Project: libFIRM - * File name: ir/ir/irgmod.h + * File name: ir/ir/irgmod.c * Purpose: Support for ir graph modification. * Author: Martin Trapp, Christian Schaefer * Modified by: Goetz Lindenmaier @@ -11,17 +11,20 @@ */ #ifdef HAVE_CONFIG_H -# include +# include "config.h" #endif -# include "irvrfy.h" -# include "irflag.h" -# include "irgwalk.h" -# include "irnode_t.h" -# include "irgraph_t.h" -# include "irgmod.h" -# include "array.h" -# include "ircons.h" +#include "irvrfy.h" +#include "irflag_t.h" +#include "irgwalk.h" +#include "irnode_t.h" +#include "irgraph_t.h" +#include "irgmod.h" +#include "array.h" +#include "ircons.h" +#include "irhooks.h" +#include "iredges_t.h" +#include "irtools.h" /* Turns a node into a "useless" Tuple. The Tuple just forms a tuple from several inputs. @@ -36,42 +39,70 @@ turn_into_tuple (ir_node *node, int 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); - node->in = NEW_ARR_D (ir_node *, current_ir_graph->obst, arity+1); - set_nodes_Block(node, block); + ir_node *block = get_nodes_block(node); + edges_invalidate(node, current_ir_graph); + 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); } } /* Insert irnode `new' in place of irnode `old' Since `new' may be bigger than `old' replace `old' by an op_Id which is smaller than everything */ -INLINE void +void exchange (ir_node *old, ir_node *nw) { - assert(get_irn_op(old)->opar != oparity_dynamic); - ir_node *block = old->in[0]; + 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 (edges_activated(current_ir_graph)) { + edges_reroute(old, nw, current_ir_graph); + } + else { + /* Else, do it the old-fashioned way. */ - old->op = op_Id; - old->in = NEW_ARR_D (ir_node *, current_ir_graph->obst, 2); - old->in[0] = block; - old->in[1] = nw; -} + ir_graph *irg = get_irn_irg (old); + ir_node *block; -/**********************************************************************/ -/* Functionality for collect_phis */ -/**********************************************************************/ + assert(old != nw); + assert (irg); + assert(get_irn_op(old)->opar != oparity_dynamic); -static void -clear_link (ir_node *n, void *env) { - set_irn_link(n, NULL); + hook_turn_into_id(old); + + block = old->in[0]; + if (!block) { + block = is_Block(nw) ? nw : get_nodes_block(nw); + + if (!block) { + DDMN(old); + DDMN(nw); + assert(0 && "cannot find legal block for id"); + } + } + + old->op = op_Id; + old->in = NEW_ARR_D (ir_node *, irg->obst, 2); + old->in[0] = block; + old->in[1] = nw; + } } +/*--------------------------------------------------------------------*/ +/* Functionality for collect_phis */ +/*--------------------------------------------------------------------*/ + static void collect (ir_node *n, void *env) { ir_node *pred; if (get_irn_op(n) == op_Phi) { - set_irn_link(n, get_irn_link(get_nodes_Block(n))); - set_irn_link(get_nodes_Block(n), n); + set_irn_link(n, get_irn_link(get_nodes_block(n))); + set_irn_link(get_nodes_block(n), n); } if (get_irn_op(n) == op_Proj) { pred = n; @@ -89,32 +120,33 @@ void collect_phiprojs(ir_graph *irg) { rem = current_ir_graph; current_ir_graph = irg; - irg_walk(get_irg_end(current_ir_graph), clear_link, collect, NULL); + irg_walk(get_irg_end(current_ir_graph), firm_clear_link, collect, NULL); current_ir_graph = rem; } -/**********************************************************************/ -/* Funcionality for part_block */ -/**********************************************************************/ - -/* Moves node and all predecessors of node from from_bl to to_bl. - Does not move predecessors of Phi nodes (or block nodes). */ +/*--------------------------------------------------------------------*/ +/* Functionality for part_block */ +/*--------------------------------------------------------------------*/ +/** + * Moves node and all predecessors of node from from_bl to to_bl. + * Does not move predecessors of Phi nodes (or block nodes). + */ static void move (ir_node *node, ir_node *from_bl, ir_node *to_bl) { - int i; + int i, arity; ir_node *proj, *pred; /* move this node */ - set_nodes_Block(node, to_bl); + set_nodes_block(node, to_bl); /* move its projs */ if (get_irn_mode(node) == mode_T) { proj = get_irn_link(node); while (proj) { - if (get_nodes_Block(proj) == from_bl) - set_nodes_Block(proj, to_bl); + if (get_nodes_block(proj) == from_bl) + set_nodes_block(proj, to_bl); proj = get_irn_link(proj); } } @@ -122,9 +154,10 @@ static void move (ir_node *node, ir_node *from_bl, ir_node *to_bl) { /* recursion ... */ if (get_irn_op(node) == op_Phi) return; - for (i = 0; i < get_irn_arity(node); i++) { + arity = get_irn_arity(node); + for (i = 0; i < arity; i++) { pred = get_irn_n(node, i); - if (get_nodes_Block(pred) == from_bl) + if (get_nodes_block(pred) == from_bl) move(pred, from_bl, to_bl); } } @@ -135,18 +168,17 @@ void part_block(ir_node *node) { ir_node *phi; /* Turn off optimizations so that blocks are not merged again. */ - int rem_opt = get_optimize(); + int rem_opt = get_opt_optimize(); set_optimize(0); /* Transform the control flow */ - old_block = get_nodes_Block(node); + old_block = get_nodes_block(node); new_block = new_Block(get_Block_n_cfgpreds(old_block), - get_Block_cfgpred_arr(old_block)); + get_Block_cfgpred_arr(old_block)); set_irg_current_block(current_ir_graph, new_block); { - ir_node *in[1]; - in[0] = new_Jmp(); - set_irn_in(old_block, 1, in); + ir_node *jmp = new_Jmp(); + set_irn_in(old_block, 1, &jmp); irn_vrfy_irg(old_block, current_ir_graph); } @@ -158,10 +190,10 @@ 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); + 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); }