removed makro calls, dokumentation
[libfirm] / ir / ir / irgopt.c
index 200dfdb..462c8de 100644 (file)
@@ -510,10 +510,13 @@ void remove_bad_predecessors(ir_graph *irg) {
 /*  Funcionality for inlining                                         */
 /**********************************************************************/
 
-/* Copy node for inlineing.  Copies the node by calling copy_node and
-   then updates the entity if it's a local one.  env must be a pointer
-   to the frame type of the procedure. The new entities must be in
-   the link field of the entities. */
+/* Copy node for inlineing.  Updates attributes that change when
+ * inlineing but not for dead node elimination.
+ *
+ * Copies the node by calling copy_node and then updates the entity if
+ * it's a local one.  env must be a pointer of the frame type of the
+ * inlined procedure. The new entities must be in the link field of
+ * the entities. */
 static INLINE void
 copy_node_inline (ir_node *n, void *env) {
   ir_node *new;
@@ -526,9 +529,13 @@ copy_node_inline (ir_node *n, void *env) {
     if (get_entity_owner(get_Sel_entity(n)) == frame_tp) {
       set_Sel_entity(new, get_entity_link(get_Sel_entity(n)));
     }
+  } else if (get_irn_op(n) == op_Block) {
+    new = get_new_node (n);
+    new->attr.block.irg = current_ir_graph;
   }
 }
 
+
 void inline_method(ir_node *call, ir_graph *called_graph) {
   ir_node *pre_call;
   ir_node *post_call, *post_bl;
@@ -775,8 +782,10 @@ void inline_method(ir_node *call, ir_graph *called_graph) {
       cf_op = get_Block_cfgpred(end_bl, i);
       if (get_irn_op(cf_op) == op_Proj) {
        cf_op = get_Proj_pred(cf_op);
-       if (get_irn_op(cf_op) == op_Tuple) {
-         cf_op = get_Tuple_pred(cf_op, 1);
+       if ((get_irn_op(cf_op) == op_Tuple) && (cf_op == call)) {
+         // There are unoptimized tuples from inlineing before when no exc
+         assert(get_Proj_proj(get_Block_cfgpred(end_bl, i)) == pn_Call_X_except);
+         cf_op = get_Tuple_pred(cf_op, pn_Call_X_except);
          assert(get_irn_op(cf_op) == op_Jmp);
          break;
        }
@@ -795,6 +804,8 @@ void inline_method(ir_node *call, ir_graph *called_graph) {
        cf_pred[j] = get_Block_cfgpred(end_bl, j-get_Block_n_cfgpreds(bl) +1);
       set_irn_in(end_bl, arity, cf_pred);
       free(cf_pred);
+      // Remove the exception pred from post-call Tuple.
+      set_Tuple_pred(call, pn_Call_X_except, new_Bad());
     }
   }
 
@@ -905,7 +916,8 @@ place_floats_early (ir_node *n)
 
     if ((get_irn_op(n) == op_Const) ||
        (get_irn_op(n) == op_SymConst) ||
-       (is_Bad(n))) {
+       (is_Bad(n)) ||
+       (get_irn_op(n) == op_Unknown)) {
       /* These nodes will not be placed by the loop below. */
       b = get_irg_start_block(current_ir_graph);
       depth = 1;
@@ -1179,7 +1191,9 @@ static void merge_blocks(ir_node *n, void *env) {
     while (irn_not_visited(b) && (!is_Bad(new)) && (new != b)) {
       /* We would have to run gigo if new is bad, so we
         promote it directly below. */
-      assert(((b == new) || get_opt_control_flow_straightening() || get_opt_control_flow_weak_simplification()) &&
+      assert(((b == new) ||
+             get_opt_control_flow_straightening() ||
+             get_opt_control_flow_weak_simplification()) &&
             ("strange flag setting"));
       exchange (b, new);
       b = new;
@@ -1488,10 +1502,15 @@ static void walk_critical_cf_edges(ir_node *n, void *env) {
       (get_irn_arity(n) > 1)) {
     arity = get_irn_arity(n);
 
+    if (n == get_irg_end_block(current_ir_graph))
+      return;  // No use to add a block here.
+
     for (i=0; i<arity; i++) {
       pre = get_irn_n(n, i);
       /* Predecessor has multiple sucessors. Insert new flow edge */
-      if ((NULL != pre) && (op_Proj == get_irn_op(pre))) {
+      if ((NULL != pre) &&
+         (op_Proj == get_irn_op(pre)) &&
+         op_Raise != get_irn_op(skip_Proj(pre))) {
 
        /* set predecessor array for new block */
        in = NEW_ARR_D (ir_node *, current_ir_graph->obst, 1);