14 #include "firm_types.h"
15 #include "irgraph_t.h"
16 #include "iredges_t.h"
23 #include "besched_t.h"
25 #include "belistsched.h"
27 FIRM_IMPL1(sched_get_time_step, int, const ir_node *)
28 FIRM_IMPL1(sched_has_next, int, const ir_node *)
29 FIRM_IMPL1(sched_has_prev, int, const ir_node *)
30 FIRM_IMPL1(sched_next, ir_node *, const ir_node *)
31 FIRM_IMPL1(sched_prev, ir_node *, const ir_node *)
32 FIRM_IMPL1(sched_first, ir_node *, const ir_node *)
33 FIRM_IMPL1(sched_last, ir_node *, const ir_node *)
34 FIRM_IMPL2(sched_add_after, ir_node *, ir_node *, ir_node *)
35 FIRM_IMPL2(sched_add_before, ir_node *, ir_node *, ir_node *)
36 FIRM_IMPL1_VOID(sched_init_block, ir_node *)
37 FIRM_IMPL1_VOID(sched_reset, ir_node *)
38 FIRM_IMPL2(sched_comes_after, int, const ir_node *, const ir_node *)
39 FIRM_IMPL1_VOID(sched_remove, ir_node *)
41 size_t sched_irn_data_offset = 0;
43 static void block_sched_dumper(ir_node *block, void *env)
48 ir_fprintf(f, "%+F:\n", block);
50 sched_foreach(block, curr) {
51 sched_info_t *info = get_irn_sched_info(curr);
52 ir_fprintf(f, "\t%6d: %+F\n", info->time_step, curr);
56 void be_sched_dump(FILE *f, ir_graph *irg)
58 irg_block_walk_graph(irg, block_sched_dumper, NULL, f);
61 /* Init the scheduling stuff. */
62 void be_init_sched(void)
64 sched_irn_data_offset = register_additional_node_data(sizeof(sched_info_t));
67 BE_REGISTER_MODULE_CONSTRUCTOR(be_init_sched);
69 void sched_renumber(const ir_node *block)
73 sched_timestep_t step = SCHED_INITIAL_GRANULARITY;
75 sched_foreach(block, irn) {
76 inf = get_irn_sched_info(irn);
77 inf->time_step = step;
78 step += SCHED_INITIAL_GRANULARITY;
82 int sched_skip_cf_predicator(const ir_node *irn, void *data) {
83 arch_env_t *ae = data;
84 return arch_irn_class_is(ae, irn, branch);
87 int sched_skip_phi_predicator(const ir_node *irn, void *data) {
91 /* Skip nodes in a schedule. */
92 ir_node *sched_skip(ir_node *from, int forward, sched_predicator_t *predicator, void *data)
94 const ir_node *bl = get_block(from);
99 from = sched_next(from);
100 for (curr = from; curr != bl && predicator(curr, data); curr = sched_next(curr)) {
104 from = sched_prev(from);
105 for (curr = from; curr != bl && predicator(curr, data); curr = sched_prev(curr)) {
112 //---------------------------------------------------------------------------
114 typedef struct remove_dead_nodes_env_t_ {
117 } remove_dead_nodes_env_t;
120 * Post-walker: remember all visited nodes in a bitset.
122 static void mark_dead_nodes_walker(ir_node *node, void *data)
124 remove_dead_nodes_env_t *env = (remove_dead_nodes_env_t*) data;
125 bitset_set(env->reachable, get_irn_idx(node));
130 * Walk through the schedule of every block and remove all dead nodes from it.
132 static void remove_dead_nodes_walker(ir_node *block, void *data)
134 remove_dead_nodes_env_t *env = (remove_dead_nodes_env_t*) data;
135 ir_node *node, *next;
137 for (node = sched_first(block); ! sched_is_end(node); node = next) {
138 /* get next node now, as after calling sched_remove it will be invalid */
139 next = sched_next(node);
141 if (bitset_is_set(env->reachable, get_irn_idx(node)))
149 void be_remove_dead_nodes_from_schedule(ir_graph *irg)
151 remove_dead_nodes_env_t env;
153 env.reachable = bitset_alloca(get_irg_last_idx(irg));
155 // mark all reachable nodes
156 irg_walk_graph(irg, mark_dead_nodes_walker, NULL, &env);
158 // walk schedule and remove non-marked nodes
159 irg_block_walk_graph(irg, remove_dead_nodes_walker, NULL, &env);