2 /* Copyright (C) 1998 - 2000 by Universitaet Karlsruhe
5 * Authors: Martin Trapp, Christian Schaefer
7 * irgmod: ir graph modification
19 # include "irnode_t.h"
20 # include "irgraph_t.h"
25 /* Turns a node into a "useless" Tuple. The Tuple just forms a tuple
27 This is useful if a node returning a tuple is removed, but the Projs
28 extracting values from the tuple are not available. */
30 turn_into_tuple (ir_node *node, int arity)
33 set_irn_op(node, op_Tuple);
34 if (get_irn_arity(node) == arity) {
37 /* Allocate new array, don't free old in_array, it's on the obstack. */
38 ir_node *block = get_nodes_Block(node);
39 node->in = NEW_ARR_D (ir_node *, current_ir_graph->obst, arity+1);
40 set_nodes_Block(node, block);
44 /* Insert irnode `new' in place of irnode `old'
45 Since `new' may be bigger than `old' replace `old'
46 by an op_Id which is smaller than everything */
48 exchange (ir_node *old, ir_node *nw)
50 ir_node *block = old->in[0];
53 old->in = NEW_ARR_D (ir_node *, current_ir_graph->obst, 2);
58 /**********************************************************************/
59 /* Functionality for collect_phis */
60 /**********************************************************************/
63 clear_link (ir_node *n, void *env) {
64 set_irn_link(n, NULL);
68 collect (ir_node *n, void *env) {
70 if (get_irn_op(n) == op_Phi) {
71 set_irn_link(n, get_irn_link(get_nodes_Block(n)));
72 set_irn_link(get_nodes_Block(n), n);
74 if (get_irn_op(n) == op_Proj) {
76 while (get_irn_op(pred) == op_Proj)
77 pred = get_Proj_pred(pred);
78 set_irn_link(n, get_irn_link(pred));
79 set_irn_link(pred, n);
83 void collect_phiprojs(ir_graph *irg) {
86 /* Remember external state of current_ir_graph. */
87 rem = current_ir_graph;
88 current_ir_graph = irg;
90 irg_walk(get_irg_end(current_ir_graph), clear_link, collect, NULL);
92 current_ir_graph = rem;
96 /**********************************************************************/
97 /* Funcionality for part_block */
98 /**********************************************************************/
100 /* Moves node and all predecessors of node from from_bl to to_bl.
101 Does not move predecessors of Phi nodes (or block nodes). */
103 static void move (ir_node *node, ir_node *from_bl, ir_node *to_bl) {
105 ir_node *proj, *pred;
108 set_nodes_Block(node, to_bl);
111 if (get_irn_mode(node) == mode_T) {
112 proj = get_irn_link(node);
114 if (get_nodes_Block(proj) == from_bl)
115 set_nodes_Block(proj, to_bl);
116 proj = get_irn_link(proj);
121 if (get_irn_op(node) == op_Phi) return;
123 for (i = 0; i < get_irn_arity(node); i++) {
124 pred = get_irn_n(node, i);
125 if (get_nodes_Block(pred) == from_bl)
126 move(pred, from_bl, to_bl);
130 void part_block(ir_node *node) {
135 /* Turn off optimizations so that blocks are not merged again. */
136 int rem_opt = get_optimize();
139 /* Transform the control flow */
140 old_block = get_nodes_Block(node);
141 new_block = new_Block(get_Block_n_cfgpreds(old_block),
142 get_Block_cfgpred_arr(old_block));
143 set_irg_current_block(current_ir_graph, new_block);
147 set_irn_in(old_block, 1, in);
151 /* move node and its predecessors to new_block */
152 move(node, old_block, new_block);
154 /* move Phi nodes to new_block */
155 phi = get_irn_link(old_block);
156 set_irn_link(new_block, phi);
157 set_irn_link(old_block, NULL);
159 if(get_nodes_Block(phi) == old_block); /* @@@ inlinening chokes on phis that don't
160 obey this condition. How do they get into
161 the list??? Example: InterfaceIII */
162 set_nodes_Block(phi, new_block);
163 phi = get_irn_link(phi);
166 set_optimize(rem_opt);