- DBG((uses->dbg, LEVEL_2, "\t\tnext use in succ %+F: %d\n", succ_bl, next));
- next_use = MIN(next_use, next);
- n++;
- }
+ if (succ_block == startblock)
+ continue;
+
+ DBG((env->dbg, LEVEL_5, "Checking succ of block %+F: %+F (for use of %+F)\n", block, succ_block, def));
+ if (!be_is_live_in(env->lv, succ_block, def)) {
+ //next_use = USES_INFINITY;
+ DBG((env->dbg, LEVEL_5, " not live in\n"));
+ continue;
+ }
+
+ use = get_or_set_use_block(env, succ_block, def);
+ DBG((env->dbg, LEVEL_5, "Found %u (loopdepth %u) (we're in block %+F)\n", use->next_use,
+ use->outermost_loop, block));
+ if (USES_IS_INFINITE(use->next_use)) {
+ if (use->outermost_loop == UNKNOWN_OUTERMOST_LOOP) {
+ found_visited = 1;
+ }
+ continue;
+ }
+
+ found_use = 1;
+ use_dist = use->next_use;
+
+ succ_loop = get_irn_loop(succ_block);
+ if (get_loop_depth(succ_loop) < loopdepth) {
+ unsigned factor = (loopdepth - get_loop_depth(succ_loop)) * 5000;
+ DBG((env->dbg, LEVEL_5, "Increase usestep because of loop out edge %d -> %d (%u)\n", factor));
+ // TODO we should use the number of nodes in the loop or so...
+ use_dist += factor;
+ }
+
+ if (use_dist < next_use) {
+ next_use = use_dist;
+ outermost_loop = use->outermost_loop;
+ result.before = use->node;
+ }