*** empty log message ***
[libfirm] / ir / ir / irgmod.c
1 /* Copyright (C) 1998 - 2000 by Universitaet Karlsruhe
2 ** All rights reserved.
3 **
4 ** Authors: Martin Trapp, Christian Schaefer
5 **
6 ** irgmod: ir graph modification
7 */
8
9 # include "irnode_t.h"
10 # include "irgraph_t.h"
11 # include "irgmod.h"
12 # include "array.h"
13
14 /* Turns a node into a "useless" Tuple.  The Tuple just forms a tuple
15    from several inputs.
16    This is useful if a node returning a tuple is removed, but the Projs
17    extracting values from the tuple are not available. */
18 void
19 turn_into_tuple (ir_node *node, int arity)
20 {
21   assert(node);
22   set_irn_op(node, op_Tuple);
23   if (get_irn_arity(node) == arity) {
24     /* keep old array */
25   } else {
26     /* Allocate new array, don't free old in_array, it's on the obstack. */
27     ir_node *block = get_nodes_Block(node);
28     node->in = NEW_ARR_D (ir_node *, current_ir_graph->obst, arity+1);
29     set_nodes_Block(node, block);
30   }
31 }
32
33 /* Insert irnode `new' in place of irnode `old'
34    Since `new' may be bigger than `old' replace `old'
35    by an op_Id which is smaller than everything */
36 inline void
37 exchange (ir_node *old, ir_node *new)
38 {
39   ir_node *block = old->in[0];
40
41   old->op = op_Id;
42   old->in = NEW_ARR_D (ir_node *, current_ir_graph->obst, 2);
43   old->in[0] = block;
44   old->in[1] = new;
45 }