irgmod.c 1.26 KB
Newer Older
Götz Lindenmaier's avatar
Götz Lindenmaier committed
1

Christian Schäfer's avatar
Christian Schäfer committed
2
3
4
5
6
7
8
9
/* Copyright (C) 1998 - 2000 by Universitaet Karlsruhe
** All rights reserved.
**
** Authors: Martin Trapp, Christian Schaefer
**
** irgmod: ir graph modification
*/

Boris Boesler's avatar
added    
Boris Boesler committed
10
11
12
13
#ifdef HAVE_CONFIG_H
# include <config.h>
#endif

Götz Lindenmaier's avatar
Götz Lindenmaier committed
14
# include "irnode_t.h"
Götz Lindenmaier's avatar
Götz Lindenmaier committed
15
# include "irgraph_t.h"
Christian Schäfer's avatar
Christian Schäfer committed
16
# include "irgmod.h"
Götz Lindenmaier's avatar
Götz Lindenmaier committed
17
# include "array.h"
Christian Schäfer's avatar
Christian Schäfer committed
18

Götz Lindenmaier's avatar
Götz Lindenmaier committed
19
20
21
22
/* Turns a node into a "useless" Tuple.  The Tuple just forms a tuple
   from several inputs.
   This is useful if a node returning a tuple is removed, but the Projs
   extracting values from the tuple are not available. */
Christian Schäfer's avatar
Christian Schäfer committed
23
24
25
26
27
28
29
30
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 {
Götz Lindenmaier's avatar
Götz Lindenmaier committed
31
32
    /* Allocate new array, don't free old in_array, it's on the obstack. */
    ir_node *block = get_nodes_Block(node);
Christian Schäfer's avatar
Christian Schäfer committed
33
    node->in = NEW_ARR_D (ir_node *, current_ir_graph->obst, arity+1);
Götz Lindenmaier's avatar
Götz Lindenmaier committed
34
    set_nodes_Block(node, block);
Christian Schäfer's avatar
Christian Schäfer committed
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
  }
}

/* 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
exchange (ir_node *old, ir_node *new)
{
  ir_node *block = old->in[0];

  old->op = op_Id;
  old->in = NEW_ARR_D (ir_node *, current_ir_graph->obst, 2);
  old->in[0] = block;
  old->in[1] = new;
}