rm_tuples.c 1.42 KB
Newer Older
Andreas Zwinkau's avatar
Andreas Zwinkau committed
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
/*
 * Copyright (C) 2011 Karlsruhe Institute of Technology.  All right reserved.
 *
 * This file is part of libFirm.
 *
 * This file may be distributed and/or modified under the terms of the
 * GNU General Public License version 2 as published by the Free Software
 * Foundation and appearing in the file LICENSE.GPL included in the
 * packaging of this file.
 *
 * Licensees holding valid libFirm Professional Edition licenses may use
 * this file in accordance with the libFirm Commercial License.
 * Agreement provided with the Software.
 *
 * This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE
 * WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR
 * PURPOSE.
 */

/**
 * @brief    Remove all Tuple nodes from ir graph
 * @author   Andreas Zwinkau
 */
#include "config.h"

#include "irnode_t.h"
#include "irgopt.h"
#include "irgmod.h"
#include "irgwalk.h"
#include "irtools.h"
#include "irgopt.h"

/** Transforms:
 *    a
 *    |
 *   Tuple
 *    |        =>
 *   Proj x          a
 */
static void exchange_tuple_projs(ir_node *node, void *env)
{
	ir_node *pred;
	int proj;
44
	(void)env;
Andreas Zwinkau's avatar
Andreas Zwinkau committed
45
46
47
48
49
50
51
52
53
54
55
56

	if (!is_Proj(node)) return;

	pred = get_Proj_pred(node);
	proj = get_Proj_proj(node);

	if (!is_Tuple(pred)) return;

	pred = get_Tuple_pred(pred, proj);
	exchange(node, pred);
}

57
void remove_tuples(ir_graph *irg)
Andreas Zwinkau's avatar
Andreas Zwinkau committed
58
{
59
	irg_walk_graph(irg, exchange_tuple_projs, NULL, NULL);
60
	add_irg_properties(irg, IR_GRAPH_PROPERTY_NO_TUPLES);
Andreas Zwinkau's avatar
Andreas Zwinkau committed
61
}