16 #include "besched_t.h"
24 static void dump_allocated_block(ir_node *block, void *data)
28 struct dump_env *dump_env = data;
29 FILE *f = dump_env->f;
30 arch_env_t *env = dump_env->env;
32 ir_fprintf(f, "node:{title:\"b%N\"\nlabel:\"", block);
33 sched_foreach(block, irn) {
34 const char *prefix = "";
36 const arch_register_t *reg = arch_get_irn_register(env, irn);
40 ir_fprintf(f, "%s = ", arch_register_get_name(reg));
42 ir_fprintf(f, "%n(", irn);
44 if(block != get_irg_start_block(get_irn_irg(block))) {
45 for(i = 0, n = get_irn_arity(irn); i < n; ++i) {
46 ir_node *op = get_irn_n(irn, i);
47 if(arch_is_register_operand(dump_env->env, op, -1)) {
48 ir_fprintf(f, "%s%s", prefix,
49 arch_register_get_name(arch_get_irn_register(env, op)));
57 ir_fprintf(f, "\"}\n");
59 if(get_irg_start_block(get_irn_irg(block)) != block) {
60 for(i = 0, n = get_irn_arity(block); i < n; ++i) {
61 ir_node *pred_bl = get_nodes_block(get_irn_n(block, i));
62 ir_fprintf(f, "edge:{sourcename:\"b%N\" targetname:\"b%N\"}\n", block, pred_bl);
67 void dump_allocated_irg(arch_env_t *arch_env, ir_graph *irg, char *suffix)
74 ir_snprintf(buf, sizeof(buf), "%F-alloc%s.vcg", irg, suffix);
76 if((env.f = fopen(buf, "wt")) != NULL) {
77 fprintf(env.f, "graph:{title:\"prg\"\n");
78 irg_block_walk_graph(irg, dump_allocated_block, NULL, &env);
79 fprintf(env.f, "}\n");
84 static void localize_const_walker(ir_node *irn, void *data)
89 for(i = 0, n = get_irn_arity(irn); i < n; ++i) {
90 ir_node *op = get_irn_n(irn, i);
91 if(get_irn_opcode(op) == iro_Const) {
92 ir_node *tgt_block, *cnst;
94 /* Special treatment for phi nodes, because phi-usage is different */
95 tgt_block = get_nodes_block(irn);
97 tgt_block = get_nodes_block(get_irn_n(tgt_block, i));
100 * We have to create the const node by ourselves, since the
101 * firmcons implementation always places it in the start block.
103 cnst = new_ir_node(NULL, get_irn_irg(irn),
104 tgt_block, op_Const, get_irn_mode(op), 0, NULL);
105 cnst->attr.con.tv = get_Const_tarval(op);
106 set_irn_n(irn, i, cnst);
112 void localize_consts(ir_graph *irg)
114 irg_walk_graph(irg, localize_const_walker, NULL, NULL);
115 dead_node_elimination(irg);
118 static int sched_edge_hook(FILE *F, ir_node *irn)
120 if(sched_is_scheduled(irn) && sched_has_prev(irn)) {
121 ir_node *prev = sched_prev(irn);
122 fprintf(F, "edge:{sourcename:\"");
124 fprintf(F, "\" targetname:\"");
126 fprintf(F, "\" color:magenta}\n");
131 void dump_ir_block_graph_sched(ir_graph *irg, const char *suffix) {
132 DUMP_NODE_EDGE_FUNC old = get_dump_node_edge_hook();
134 dump_consts_local(0);
135 set_dump_node_edge_hook(sched_edge_hook);
136 dump_ir_block_graph(irg, suffix);
137 set_dump_node_edge_hook(old);
140 static void clear_link(ir_node *irn, void *data)
142 set_irn_link(irn, NULL);
145 static void collect_phis(ir_node *irn, void *data)
148 ir_node *bl = get_nodes_block(irn);
149 set_irn_link(irn, get_irn_link(bl));
150 set_irn_link(bl, irn);
154 void be_clear_links(ir_graph *irg)
156 irg_walk_graph(irg, clear_link, NULL, NULL);
159 void be_collect_phis(ir_graph *irg)
161 irg_walk_graph(irg, collect_phis, NULL, NULL);