remove the concept of a strictconv
[libfirm] / ir / ir / rm_tuples.c
1 /*
2  * Copyright (C) 2011 Karlsruhe Institute of Technology.  All right reserved.
3  *
4  * This file is part of libFirm.
5  *
6  * This file may be distributed and/or modified under the terms of the
7  * GNU General Public License version 2 as published by the Free Software
8  * Foundation and appearing in the file LICENSE.GPL included in the
9  * packaging of this file.
10  *
11  * Licensees holding valid libFirm Professional Edition licenses may use
12  * this file in accordance with the libFirm Commercial License.
13  * Agreement provided with the Software.
14  *
15  * This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE
16  * WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR
17  * PURPOSE.
18  */
19
20 /**
21  * @brief    Remove all Tuple nodes from ir graph
22  * @author   Andreas Zwinkau
23  */
24 #include "config.h"
25
26 #include "irnode_t.h"
27 #include "irgopt.h"
28 #include "irgmod.h"
29 #include "irgwalk.h"
30 #include "irtools.h"
31 #include "irgopt.h"
32
33 /** Transforms:
34  *    a
35  *    |
36  *   Tuple
37  *    |        =>
38  *   Proj x          a
39  */
40 static void exchange_tuple_projs(ir_node *node, void *env)
41 {
42         ir_node *pred;
43         int proj;
44         (void)env;
45
46         if (!is_Proj(node)) return;
47
48         pred = get_Proj_pred(node);
49         proj = get_Proj_proj(node);
50
51         if (!is_Tuple(pred)) return;
52
53         pred = get_Tuple_pred(pred, proj);
54         exchange(node, pred);
55 }
56
57 void remove_tuples(ir_graph *irg)
58 {
59         irg_walk_graph(irg, exchange_tuple_projs, NULL, NULL);
60
61         ir_node *end          = get_irg_end(irg);
62         int      n_keepalives = get_End_n_keepalives(end);
63         int      i;
64
65         for (i = n_keepalives - 1; i >= 0; --i) {
66                 ir_node *irn = get_End_keepalive(end, i);
67
68                 if (is_Tuple(irn)) {
69                         remove_End_keepalive(end, irn);
70                 }
71         }
72
73         add_irg_properties(irg, IR_GRAPH_PROPERTY_NO_TUPLES);
74 }