2 * Copyright (C) 1995-2011 University of Karlsruhe. All right reserved.
4 * This file is part of libFirm.
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.
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.
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
22 * @author Matthias Braun
38 static copy_attr_func old_phi_copy_attr;
40 void be_info_new_node(ir_node *node)
46 /* Projs need no be info, their tuple holds all information */
50 obst = be_get_be_obst(current_ir_graph);
51 info = OALLOCZ(obst, backend_info_t);
53 assert(node->backend_info == NULL);
54 node->backend_info = info;
56 /* Hack! We still have middle end nodes in the backend (which was probably
57 a bad decision back then), which have no register constraints.
58 Set some none_requirements here.
60 opcode = get_irn_opcode(node);
61 if (opcode <= iro_Last) {
62 ir_mode *mode = get_irn_mode(node);
64 info->out_infos = NEW_ARR_D(reg_out_info_t, obst, 1);
65 memset(info->out_infos, 0, 1 * sizeof(info->out_infos[0]));
66 info->out_infos[0].req = arch_no_register_req;
79 info->flags |= arch_irn_flags_not_scheduled;
85 static void new_phi_copy_attr(ir_graph *irg, const ir_node *old_node,
88 backend_info_t *old_info = be_get_info(old_node);
89 backend_info_t *new_info = be_get_info(new_node);
91 *new_info = *old_info;
93 old_phi_copy_attr(irg, old_node, new_node);
96 int be_nodes_equal(const ir_node *node1, const ir_node *node2)
98 const backend_info_t *info1 = be_get_info(node1);
99 const backend_info_t *info2 = be_get_info(node2);
100 size_t len = ARR_LEN(info1->out_infos);
101 int arity = get_irn_arity(node1);
105 if (ARR_LEN(info2->out_infos) != len)
108 assert(arity == get_irn_arity(node2));
110 for (in = 0; in < arity; ++in) {
111 if (info1->in_reqs[in] != info2->in_reqs[in])
115 for (i = 0; i < len; ++i) {
116 const reg_out_info_t *out1 = &info1->out_infos[i];
117 const reg_out_info_t *out2 = &info2->out_infos[i];
118 if (out1->reg != out2->reg)
120 if (!reg_reqs_equal(out1->req, out2->req))
127 static void init_walker(ir_node *node, void *data)
130 be_info_new_node(node);
133 static bool initialized = false;
135 void be_info_init(void)
138 panic("double initialization of be_info");
140 old_phi_copy_attr = op_Phi->ops.copy_attr;
141 op_Phi->ops.copy_attr = new_phi_copy_attr;
144 /* phis have register and register requirements now which we want to dump */
145 assert(op_Phi->ops.dump_node == NULL);
146 op_Phi->ops.dump_node = be_dump_phi_reg_reqs;
150 * Edge hook to dump the schedule edges.
152 static void sched_edge_hook(FILE *F, ir_node *irn)
156 if (get_irn_irg(irn)->be_data == NULL)
159 if (sched_is_scheduled(irn) && sched_has_prev(irn)) {
160 ir_node *prev = sched_prev(irn);
161 fprintf(F, "edge:{sourcename:\"");
163 fprintf(F, "\" targetname:\"");
165 fprintf(F, "\" color:magenta}\n");
169 void be_info_init_irg(ir_graph *irg)
171 irg_walk_anchors(irg, init_walker, NULL, NULL);
173 set_dump_node_edge_hook(sched_edge_hook);
176 void be_info_free(void)
179 panic("be_info_free called without prior init");
181 assert(op_Phi->ops.copy_attr == new_phi_copy_attr);
182 op_Phi->ops.copy_attr = old_phi_copy_attr;
185 assert(op_Phi->ops.dump_node == be_dump_phi_reg_reqs);
186 op_Phi->ops.dump_node = NULL;
189 int be_info_initialized(const ir_graph *irg)