becopyheur2: Cache the admissible registers eagerly.
[libfirm] / ir / ir / rm_tuples.c
1 /*
2  * This file is part of libFirm.
3  * Copyright (C) 2012 Karlsruhe Institute of Technology.
4  */
5
6 /**
7  * @brief    Remove all Tuple nodes from ir graph
8  * @author   Andreas Zwinkau
9  */
10 #include "config.h"
11
12 #include "irnode_t.h"
13 #include "irgopt.h"
14 #include "irgmod.h"
15 #include "irgwalk.h"
16 #include "irtools.h"
17 #include "irgopt.h"
18
19 /** Transforms:
20  *    a
21  *    |
22  *   Tuple
23  *    |        =>
24  *   Proj x          a
25  */
26 static void exchange_tuple_projs(ir_node *node, void *env)
27 {
28         ir_node *pred;
29         int proj;
30         (void)env;
31
32         if (!is_Proj(node)) return;
33
34         pred = get_Proj_pred(node);
35         proj = get_Proj_proj(node);
36
37         if (!is_Tuple(pred)) return;
38
39         pred = get_Tuple_pred(pred, proj);
40         exchange(node, pred);
41 }
42
43 void remove_tuples(ir_graph *irg)
44 {
45         irg_walk_graph(irg, exchange_tuple_projs, NULL, NULL);
46
47         ir_node *end          = get_irg_end(irg);
48         int      n_keepalives = get_End_n_keepalives(end);
49         int      i;
50
51         for (i = n_keepalives - 1; i >= 0; --i) {
52                 ir_node *irn = get_End_keepalive(end, i);
53
54                 if (is_Tuple(irn)) {
55                         remove_End_keepalive(end, irn);
56                 }
57         }
58
59         add_irg_properties(irg, IR_GRAPH_PROPERTY_NO_TUPLES);
60 }