+
+/**
+ * Returns non-zero if n is possible loop head of an endless loop.
+ * I.e., it is a Block, Phi or Filter node and has only predecessors
+ * within the loop.
+ *
+ * @param n the block node to check
+ * @param root only needed for assertion.
+ */
+static int
+is_endless_head (ir_node *n, ir_node *root)
+{
+ int i, arity;
+ int some_outof_loop = 0, some_in_loop = 0;
+
+ assert(is_Block(n));
+ /* Test for legal loop header: Block, Phi, ... */
+ if (!is_outermost_StartBlock(n)) {
+ arity = get_irn_arity(n);
+ for (i = 0; i < arity; i++) {
+ ir_node *pred = get_nodes_block(skip_Proj(get_irn_n(n, i)));
+ assert(pred);
+ if (is_backedge(n, i)) { continue; }
+ if (!irn_is_in_stack(pred)) {
+ some_outof_loop = 1; //printf(" some out of loop ");
+ } else {
+ if(get_irn_uplink(pred) < get_irn_uplink(root)) {
+ DDMN(pred); DDMN(root);
+ assert(get_irn_uplink(pred) >= get_irn_uplink(root));
+ }
+ some_in_loop = 1;
+ }
+ }
+ }
+ return !some_outof_loop && some_in_loop;
+}
+
+/**
+ * Returns index of the predecessor with the smallest dfn number
+ * greater-equal than limit.
+ */