fix backend nodes not copying flags correctly
[libfirm] / ir / be / beabi.c
index e5eb80f..8b80946 100644 (file)
@@ -979,6 +979,7 @@ static int cmp_call_dependency(const void *c1, const void *c2)
 {
        ir_node *n1 = *(ir_node **) c1;
        ir_node *n2 = *(ir_node **) c2;
+       unsigned h1, h2;
 
        /*
                Classical qsort() comparison function behavior:
@@ -993,7 +994,16 @@ static int cmp_call_dependency(const void *c1, const void *c2)
                return 1;
 
        /* The nodes have no depth order, but we need a total order because qsort()
-        * is not stable. */
+        * is not stable.
+        *
+        * Additionally, we need to respect transitive dependencies. Consider a
+        * Call a depending on Call b and an independent Call c.
+        * We MUST NOT order c > a and b > c. */
+       h1 = get_irn_height(ir_heights, n1);
+       h2 = get_irn_height(ir_heights, n2);
+       if (h1 < h2) return -1;
+       if (h1 > h2) return  1;
+       /* Same height, so use a random (but stable) order */
        return get_irn_idx(n1) - get_irn_idx(n2);
 }
 
@@ -1611,25 +1621,13 @@ static void fix_address_of_parameter_access(be_abi_irg_t *env, ir_graph *irg,
  */
 static void fix_start_block(ir_graph *irg)
 {
-       ir_node         *initial_X   = get_irg_initial_exec(irg);
-       ir_node         *start_block = get_irg_start_block(irg);
-       const ir_edge_t *edge;
+       ir_node *initial_X   = get_irg_initial_exec(irg);
+       ir_node *start_block = get_irg_start_block(irg);
+       ir_node *jmp         = new_r_Jmp(start_block);
 
        assert(is_Proj(initial_X));
-
-       foreach_out_edge(initial_X, edge) {
-               ir_node *block = get_edge_src_irn(edge);
-
-               if (is_Anchor(block))
-                       continue;
-               if (block != start_block) {
-                       ir_node *jmp = new_r_Jmp(start_block);
-                       set_Block_cfgpred(block, get_edge_src_pos(edge), jmp);
-                       set_irg_initial_exec(irg, jmp);
-                       return;
-               }
-       }
-       panic("Initial exec has no follow block in %+F", irg);
+       exchange(initial_X, jmp);
+       set_irg_initial_exec(irg, new_r_Bad(irg));
 }
 
 /**
@@ -1856,6 +1854,7 @@ static void modify_irg(ir_graph *irg)
        pmap_insert(env->regs, (void *) arch_env->bp, NULL);
        start_bl   = get_irg_start_block(irg);
        env->start = be_new_Start(NULL, start_bl, pmap_count(env->regs) + 1);
+       set_irg_start(irg, env->start);
 
        /*
         * make proj nodes for the callee save registers.