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