-unsigned be_get_next_use(be_uses_t *uses,
- const ir_node *from, unsigned from_step, const ir_node *def,
- int skip_from_uses)
-{
- unsigned next_use = USES_INFINITY;
- unsigned step = from_step;
- unsigned n = 0;
- const ir_node *irn;
- const ir_node *bl = get_block(from);
- const ir_edge_t *succ_edge;
-
- sched_foreach_from(from, irn) {
- int i, n;
-
- if(!skip_from_uses) {
- for(i = 0, n = get_irn_arity(irn); i < n; ++i) {
- ir_node *operand = get_irn_n(irn, i);
-
- if(operand == def) {
- DBG((uses->dbg, LEVEL_3, "found use of %+F at %+F\n", operand, irn));
- return step;
- }
- }
+ if(is_Anchor(node))
+ continue;
+ if(get_nodes_block(node) != block)
+ continue;
+ if(is_Phi(node))
+ continue;
+
+ node_step = get_step(node);
+ if(node_step < timestep)
+ continue;
+ if(node_step < next_use_step) {
+ next_use = node;
+ next_use_step = node_step;
+ }
+ }
+
+ if(next_use != NULL) {
+ be_next_use_t result;
+ result.time = next_use_step - timestep + skip_from_uses;
+ result.outermost_loop = get_loop_depth(get_irn_loop(block));
+ result.before = next_use;
+ return result;
+ }
+
+ node = sched_last(block);
+ step = get_step(node) + 1 + timestep + skip_from_uses;
+
+#else
+ if(skip_from_uses) {
+ from = sched_next(from);
+ ++step;
+ }
+
+ sched_foreach_from(from, node) {
+ int i, arity;
+
+ if(is_Phi(node)) {
+ step++;
+ continue;
+ }
+
+ arity = get_irn_arity(node);
+ for (i = 0; i < arity; ++i) {
+ const ir_node *operand = get_irn_n(node, i);
+
+ if (operand == def) {
+ be_next_use_t result;
+
+ DBG((env->dbg, LEVEL_3, "found use of %+F at %+F\n", operand, node));
+
+ /**
+ * Spills/Reloads are a special case, they're not really a
+ * usage of a value, continue searching
+ */
+ if (be_is_Spill(node) || be_is_Reload(node)) {
+ return be_get_next_use(env, node, step, node, 1);
+ }
+
+ result.time = step;
+ result.outermost_loop = get_loop_depth(get_irn_loop(block));
+ result.before = node;
+ return result;
+ }
+ }
+
+ step++;
+ }
+#endif
+
+ if(be_is_phi_argument(block, def)) {
+ // TODO we really should continue searching the uses of the phi,
+ // as a phi isn't a real use that implies a reload (because we could
+ // easily spill the whole phi)
+
+ be_next_use_t result;
+ result.time = step;
+ result.outermost_loop = get_loop_depth(get_irn_loop(block));
+ result.before = block;
+ return result;