- sched_env_t *env = env_ptr;
- block_sched_env_t be;
-
- ir_node *irn;
- int j, m;
- int phi_seen = 0;
- sched_info_t *info = get_irn_sched_info(block);
-
- /* Initialize the block's list head that will hold the schedule. */
- INIT_LIST_HEAD(&info->list);
-
- /* Initialize the block scheduling environment */
- be.block = block;
- be.curr_time = 0;
- be.ready_set = new_pset(node_cmp_func, get_irn_n_outs(block));
- be.already_scheduled = new_pset(node_cmp_func, get_irn_n_outs(block));
-
- ir_debugf("scheduling %n\n", block);
-
- /* Then one can add all nodes are ready to the set. */
- for(int i = 0, n = get_irn_n_outs(block); i < n; ++i) {
- ir_node *irn = get_irn_out(block, i);
-
- /* Phi functions are scheduled immediately, since they only transfer
- * data flow from the predecessors to this block. */
- if(is_Phi(irn)) {
- add_to_sched(&be, irn);
- make_users_ready(&be, irn);
- phi_seen = 1;
- }
-
- /* Other nodes must have all operands in other blocks to be made
- * ready */
- else {
- bool ready = true;
-
- /* Check, if the operands of a node are not local to this block */
- for(j = 0, m = get_irn_arity(irn); j < m; ++j) {
- ir_node *operand = get_irn_n(irn, j);
-
- if(get_nodes_block(operand) == block) {
- ready = false;
- break;
- }
- }
-
- /* Make the node ready, if all operands live in a foreign block */
- if(ready) {
- ir_debugf("\timmediately ready: %n\n", irn);
- make_ready(&be, irn);
- }
- }
- }
-
- /* Increase the time, if some phi functions have been scheduled */
- be.curr_time += phi_seen;
-
- while(pset_count(be.ready_set) > 0) {
- ir_debugf("\tready set: %*n\n", pset_iterator, be.ready_set);
- // pset_print(stdout, be.ready_set, irn_printer);
-
- /* select a node to be scheduled and check if it was ready */
- irn = env->select(env->select_env, block, be.curr_time,
- be.already_scheduled, be.ready_set);
-
- ir_debugf("\tpicked node %n\n", irn);
-
- /* Add the node to the schedule. */
- add_to_sched(&be, irn);
-
- if(get_irn_mode(irn) == mode_T)
- add_tuple_projs(&be, irn);
- else
- make_users_ready(&be, irn);
-
- /* Increase the time step. */
- be.curr_time += 1;
-
- /* remove the scheduled node from the ready list. */
- if(pset_find_ptr(be.ready_set, irn))
- pset_remove_ptr(be.ready_set, irn);
- }
-
- del_pset(be.ready_set);
- del_pset(be.already_scheduled);
-
- {
- sched_info_t *inf;
- list_for_each_entry(sched_info_t, inf, &info->list, list) {
- ir_node *irn = get_sched_info_irn(inf);
- ir_debugf("node: %n, pos: %d\n", irn, inf->time_step);
- }
- }
+ sched_env_t *env = env_ptr;
+ block_sched_env_t be;
+
+ ir_node *irn;
+ int i, n, j, m;
+ int phi_seen = 0;
+ sched_info_t *info = get_irn_sched_info(block);
+
+ /* Initialize the block's list head that will hold the schedule. */
+ INIT_LIST_HEAD(&info->list);
+
+ /* Initialize the block scheduling environment */
+ be.dbg = firm_dbg_register("firm.be.sched");
+ be.block = block;
+ be.curr_time = 0;
+ be.ready_set = new_pset(node_cmp_func, get_irn_n_outs(block));
+ be.already_scheduled = new_pset(node_cmp_func, get_irn_n_outs(block));
+
+ DBG((be.dbg, LEVEL_1, "scheduling %n\n", block));
+
+ /* Then one can add all nodes are ready to the set. */
+ for(i = 0, n = get_irn_n_outs(block); i < n; ++i) {
+ ir_node *irn = get_irn_out(block, i);
+
+ /* Skip the end node because of keepalive edges. */
+ if(get_irn_opcode(irn) == iro_End)
+ continue;
+
+ /* Phi functions are scheduled immediately, since they only transfer
+ * data flow from the predecessors to this block. */
+ if(is_Phi(irn)) {
+ add_to_sched(&be, irn);
+ make_users_ready(&be, irn);
+ phi_seen = 1;
+ }
+
+ /* Other nodes must have all operands in other blocks to be made
+ * ready */
+ else {
+ bool ready = true;
+
+ /* Check, if the operands of a node are not local to this block */
+ for(j = 0, m = get_irn_arity(irn); j < m; ++j) {
+ ir_node *operand = get_irn_n(irn, j);
+
+ if(get_nodes_block(operand) == block) {
+ ready = false;
+ break;
+ }
+ }
+
+ /* Make the node ready, if all operands live in a foreign block */
+ if(ready) {
+ DBG((be.dbg, LEVEL_2, "\timmediately ready: %n\n", irn));
+ make_ready(&be, irn);
+ }
+ }
+ }
+
+ /* Increase the time, if some phi functions have been scheduled */
+ be.curr_time += phi_seen;
+
+ while(pset_count(be.ready_set) > 0) {
+ DBG((be.dbg, LEVEL_2, "\tready set: %*n\n", pset_iterator, be.ready_set));
+ // pset_print(stdout, be.ready_set, irn_printer);
+
+ /* select a node to be scheduled and check if it was ready */
+ irn = env->select(env->select_env, block, be.curr_time,
+ be.already_scheduled, be.ready_set);
+
+ DBG((be.dbg, LEVEL_3, "\tpicked node %n\n", irn));
+
+ /* Add the node to the schedule. */
+ add_to_sched(&be, irn);
+
+ if(get_irn_mode(irn) == mode_T)
+ add_tuple_projs(&be, irn);
+ else
+ make_users_ready(&be, irn);
+
+ /* Increase the time step. */
+ be.curr_time += 1;
+
+ /* remove the scheduled node from the ready list. */
+ if(pset_find_ptr(be.ready_set, irn))
+ pset_remove_ptr(be.ready_set, irn);
+ }
+
+ del_pset(be.ready_set);
+ del_pset(be.already_scheduled);