+ while (nodeset_count(be.cands) > 0) {
+ nodeset *mcands; /**< the set of candidates with maximum delay time */
+ nodeset *ecands; /**< the set of nodes in mcands whose etime <= curr_time */
+ sched_timestep_t max_delay = 0;
+
+ /* collect statistics about amount of ready nodes */
+ be_do_stat_sched_ready(block, be.cands);
+
+ /* calculate the max delay of all candidates */
+ foreach_nodeset(be.cands, irn) {
+ sched_timestep_t d = get_irn_delay(&be, irn);
+
+ max_delay = d > max_delay ? d : max_delay;
+ }
+ mcands = new_nodeset(8);
+ ecands = new_nodeset(8);
+
+ /* calculate mcands and ecands */
+ foreach_nodeset(be.cands, irn) {
+ if (be_is_Keep(irn)) {
+ nodeset_break(be.cands);
+ break;
+ }
+ if (get_irn_delay(&be, irn) == max_delay) {
+ nodeset_insert(mcands, irn);
+ if (get_irn_etime(&be, irn) <= be.curr_time)
+ nodeset_insert(ecands, irn);
+ }
+ }
+
+ if (irn) {
+ /* Keeps must be immediately scheduled */
+ }
+ else {
+ DB((be.dbg, LEVEL_2, "\tbe.curr_time = %u\n", be.curr_time));
+
+ /* select a node to be scheduled and check if it was ready */
+ if (nodeset_count(mcands) == 1) {
+ DB((be.dbg, LEVEL_3, "\tmcand = 1, max_delay = %u\n", max_delay));
+ irn = nodeset_first(mcands);
+ }
+ else {
+ int cnt = nodeset_count(ecands);
+ if (cnt == 1) {
+ arch_irn_class_t irn_class;
+
+ irn = nodeset_first(ecands);
+ irn_class = arch_irn_classify(env->arch_env, irn);
+
+ if (irn_class == arch_irn_class_branch) {
+ /* BEWARE: don't select a JUMP if others are still possible */
+ goto force_mcands;
+ }
+ DB((be.dbg, LEVEL_3, "\tecand = 1, max_delay = %u\n", max_delay));
+ }
+ else if (cnt > 1) {
+ DB((be.dbg, LEVEL_3, "\tecand = %d, max_delay = %u\n", cnt, max_delay));
+ irn = select_node_heuristic(&be, ecands);
+ }
+ else {
+force_mcands:
+ DB((be.dbg, LEVEL_3, "\tmcand = %d\n", nodeset_count(mcands)));
+ irn = select_node_heuristic(&be, mcands);
+ }
+ }
+ }
+ del_nodeset(mcands);
+ del_nodeset(ecands);