+
+ return curr_sp;
+}
+
+/**
+ * Adjust an alloca.
+ * The alloca is transformed into a back end alloca node and connected to the stack nodes.
+ */
+static ir_node *adjust_alloc(be_abi_irg_t *env, ir_node *alloc, ir_node *curr_sp)
+{
+ if(get_Alloc_where(alloc) == stack_alloc) {
+ ir_node *new_alloc;
+
+ ir_node *bl = get_nodes_block(alloc);
+ ir_graph *irg = get_irn_irg(bl);
+
+ new_alloc = be_new_Alloca(env->isa->sp, irg, bl, get_Alloc_mem(alloc), curr_sp, get_Alloc_size(alloc));
+ exchange(alloc, new_alloc);
+ curr_sp = new_r_Proj(irg, bl, new_alloc, mode_P, pn_Alloc_res);
+ }
+
+ return curr_sp;
+}
+
+/**
+ * Walker for dependent_on().
+ * This function searches a node tgt recursively from a given node
+ * but is restricted to the given block.
+ * @return 1 if tgt was reachable from curr, 0 if not.
+ */
+static int check_dependence(ir_node *curr, ir_node *tgt, ir_node *bl, unsigned long visited_nr)
+{
+ int n, i;
+
+ if(get_irn_visited(curr) >= visited_nr)
+ return 0;
+
+ set_irn_visited(curr, visited_nr);
+ if(get_nodes_block(curr) != bl)
+ return 0;
+
+ if(curr == tgt)
+ return 1;
+
+ for(i = 0, n = get_irn_arity(curr); i < n; ++i) {
+ if(check_dependence(get_irn_n(curr, i), tgt, bl, visited_nr))
+ return 1;
+ }
+
+ return 0;
+}
+
+/**
+ * Check if a node is somehow data dependent on another one.
+ * both nodes must be in the same basic block.
+ * @param n1 The first node.
+ * @param n2 The second node.
+ * @return 1, if n1 is data dependent (transitively) on n2, 0 if not.
+ */
+static int dependent_on(ir_node *n1, ir_node *n2)
+{
+ ir_node *bl = get_nodes_block(n1);
+ ir_graph *irg = get_irn_irg(bl);
+ long vis_nr = get_irg_visited(irg) + 1;
+
+ assert(bl == get_nodes_block(n2));
+ set_irg_visited(irg, vis_nr);
+ return check_dependence(n1, n2, bl, vis_nr);
+}
+
+static int cmp_call_dependecy(const void *c1, const void *c2)
+{
+ ir_node *n1 = *(ir_node **) c1;
+ ir_node *n2 = *(ir_node **) c2;
+
+ /*
+ Classical qsort() comparison function behavior:
+ 0 if both elements are equal
+ 1 if second is "smaller" that first
+ -1 if first is "smaller" that second
+ */
+ return n1 == n2 ? 0 : (dependent_on(n1, n2) ? -1 : 1);