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
41 static copy_attr_func old_phi_copy_attr;
43 void be_info_new_node(ir_graph *irg, ir_node *node)
48 /* Projs need no be info, all info is fetched from their predecessor */
52 obst = be_get_be_obst(irg);
53 info = OALLOCZ(obst, backend_info_t);
55 assert(node->backend_info == NULL);
56 node->backend_info = info;
59 * Set backend info for some middleend nodes which still appear in
62 switch (get_irn_opcode(node)) {
72 info->flags |= arch_irn_flags_not_scheduled;
75 info->out_infos = NEW_ARR_D(reg_out_info_t, obst, 1);
76 memset(info->out_infos, 0, 1 * sizeof(info->out_infos[0]));
77 info->out_infos[0].req = arch_no_register_req;
84 static void new_phi_copy_attr(ir_graph *irg, const ir_node *old_node,
87 backend_info_t *old_info = be_get_info(old_node);
88 backend_info_t *new_info = be_get_info(new_node);
90 *new_info = *old_info;
92 old_phi_copy_attr(irg, old_node, new_node);
95 int be_nodes_equal(const ir_node *node1, const ir_node *node2)
97 const backend_info_t *info1 = be_get_info(node1);
98 const backend_info_t *info2 = be_get_info(node2);
99 size_t len = ARR_LEN(info1->out_infos);
100 int arity = get_irn_arity(node1);
104 if (ARR_LEN(info2->out_infos) != len)
107 assert(arity == get_irn_arity(node2));
109 for (in = 0; in < arity; ++in) {
110 if (info1->in_reqs[in] != info2->in_reqs[in])
114 for (i = 0; i < len; ++i) {
115 const reg_out_info_t *out1 = &info1->out_infos[i];
116 const reg_out_info_t *out2 = &info2->out_infos[i];
117 if (out1->reg != out2->reg)
119 if (!reg_reqs_equal(out1->req, out2->req))
126 static void init_walker(ir_node *node, void *data)
128 ir_graph *irg = get_irn_irg(node);
130 be_info_new_node(irg, node);
133 static bool initialized = false;
134 static hook_entry_t hook_liveness_info;
136 static void dump_liveness_info_hook(void *context, FILE *F, const ir_node *node)
141 ir_graph *irg = get_irn_irg(node);
142 if (!irg_is_constrained(irg, IR_GRAPH_CONSTRAINT_BACKEND))
145 be_lv_t *lv = be_get_irg_liveness(irg);
151 be_dump_liveness_block(lv, F, node);
154 void be_info_init(void)
157 panic("double initialization of be_info");
159 old_phi_copy_attr = op_Phi->ops.copy_attr;
160 op_Phi->ops.copy_attr = new_phi_copy_attr;
163 /* phis have register and register requirements now which we want to dump */
164 assert(op_Phi->ops.dump_node == NULL);
165 op_Phi->ops.dump_node = be_dump_phi_reg_reqs;
167 hook_liveness_info.hook._hook_node_info = dump_liveness_info_hook;
168 register_hook(hook_node_info, &hook_liveness_info);
172 * Edge hook to dump the schedule edges.
174 static void sched_edge_hook(FILE *F, const ir_node *irn)
176 ir_graph *irg = get_irn_irg(irn);
177 if (!irg_is_constrained(irg, IR_GRAPH_CONSTRAINT_BACKEND))
180 if (is_Proj(irn) || is_Block(irn) || !sched_is_scheduled(irn))
183 ir_node *const prev = sched_prev(irn);
184 if (!sched_is_begin(prev)) {
185 fprintf(F, "edge:{sourcename: ");
186 print_nodeid(F, irn);
187 fprintf(F, " targetname: ");
188 print_nodeid(F, prev);
189 fprintf(F, " color:magenta}\n");
193 void be_info_init_irg(ir_graph *irg)
195 add_irg_constraints(irg, IR_GRAPH_CONSTRAINT_BACKEND);
196 irg_walk_anchors(irg, init_walker, NULL, NULL);
198 set_dump_node_edge_hook(sched_edge_hook);
201 void be_info_free(void)
204 panic("called without prior init");
206 assert(op_Phi->ops.copy_attr == new_phi_copy_attr);
207 op_Phi->ops.copy_attr = old_phi_copy_attr;
210 assert(op_Phi->ops.dump_node == be_dump_phi_reg_reqs);
211 op_Phi->ops.dump_node = NULL;
213 unregister_hook(hook_node_info, &hook_liveness_info);