beinfo.c 3.43 KB
Newer Older
Matthias Braun's avatar
Matthias Braun 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
/*
 * Copyright (C) 1995-2008 University of Karlsruhe.  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.
 */

/**
 * @file
 * @author      Matthias Braun
 * @version     $Id$
 */
#include "config.h"

27
28
#include <stdbool.h>

Matthias Braun's avatar
Matthias Braun committed
29
#include "beinfo.h"
30
#include "bearch.h"
31
#include "benode_t.h"
Matthias Braun's avatar
Matthias Braun committed
32
33
34
35
36
37
38
39
#include "irgwalk.h"
#include "irnode_t.h"
#include "error.h"

static copy_attr_func  old_phi_copy_attr;

void be_info_new_node(ir_node *node)
{
Michael Beck's avatar
Michael Beck committed
40
41
42
43
	struct obstack *obst;
	backend_info_t *info;
	sched_info_t   *sinfo;

Matthias Braun's avatar
Matthias Braun committed
44
45
46
	if (is_Anchor(node))
		return;

47
48
49
	if (is_Proj(node)) // Projs need no be info, their tuple holds all information
		return;

Michael Beck's avatar
Michael Beck committed
50
51
52
	obst  = get_irg_obstack(current_ir_graph);
	info  = obstack_alloc(obst, sizeof(*info));
	sinfo = &info->sched_info;
Matthias Braun's avatar
Matthias Braun committed
53
54

	memset(info, 0, sizeof(*info));
55
56
	sinfo->next = NULL;
	sinfo->prev = NULL;
Matthias Braun's avatar
Matthias Braun committed
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105

	if (is_Phi(node)) {
		info->out_infos = NEW_ARR_D(reg_out_info_t, obst, 1);
		memset(info->out_infos, 0, 1 * sizeof(info->out_infos[0]));
	}
	assert(node->backend_info == NULL);
	node->backend_info = info;
}

static void new_Phi_copy_attr(const ir_node *old_node, ir_node *new_node)
{
	struct obstack *obst  = get_irg_obstack(get_irn_irg(new_node));
	backend_info_t *old_info = be_get_info(old_node);
	backend_info_t *new_info = be_get_info(new_node);

	old_phi_copy_attr(old_node, new_node);
	new_info->out_infos = DUP_ARR_D(reg_out_info_t, obst, old_info->out_infos);
}

int be_info_equal(const ir_node *node1, const ir_node *node2)
{
	backend_info_t *info1 = be_get_info(node1);
	backend_info_t *info2 = be_get_info(node2);
	int             len   = ARR_LEN(info1->out_infos);
	int             i;

	if (ARR_LEN(info2->out_infos) != len)
		return 0;

	for (i = 0; i < len; ++i) {
		const reg_out_info_t *out1 = &info1->out_infos[i];
		const reg_out_info_t *out2 = &info2->out_infos[i];
		if (out1->reg != out2->reg)
			return 0;
		if (!reg_reqs_equal(out1->req, out2->req))
			return 0;
	}

	/* TODO: in reqs */

	return 1;
}

static void init_walker(ir_node *node, void *data)
{
	(void) data;
	be_info_new_node(node);
}

106
static bool initialized = false;
Matthias Braun's avatar
Matthias Braun committed
107
108
109

void be_info_init(void)
{
110
	if (initialized)
Matthias Braun's avatar
Matthias Braun committed
111
112
113
114
		panic("double initialization of be_info");

	old_phi_copy_attr = op_Phi->ops.copy_attr;
	op_Phi->ops.copy_attr = new_Phi_copy_attr;
115
116
117
118
119
	initialized = true;

	/* phis have register and register requirements now which we want to dump */
	assert(op_Phi->ops.dump_node == NULL);
	op_Phi->ops.dump_node = be_dump_phi_reg_reqs;
Matthias Braun's avatar
Matthias Braun committed
120
121
122
123
124
125
126
127
128
129
130
131
132
133
}

void be_info_init_irg(ir_graph *irg)
{
	irg_walk_anchors(irg, init_walker, NULL, NULL);
}

void be_info_free(void)
{
	if (!initialized)
		panic("be_info_free called without prior init");

	assert(op_Phi->ops.copy_attr == new_Phi_copy_attr);
	op_Phi->ops.copy_attr = old_phi_copy_attr;
134
135
136
137
	initialized = false;

	assert(op_Phi->ops.dump_node == be_dump_phi_reg_reqs);
	op_Phi->ops.dump_node = NULL;
Matthias Braun's avatar
Matthias Braun committed
138
139
140
141
142
143
144
}

int be_info_initialized(const ir_graph *irg)
{
	(void) irg;
	return initialized;
}