In gcc/objc/: 2010-12-08 Nicola Pero <nicola.pero@meta-innovation.com>
[platform/upstream/gcc.git] / gcc / tree-ssa-pre.c
index e17aefc..fda9437 100644 (file)
@@ -484,10 +484,12 @@ static tree pretemp;
 static tree storetemp;
 static tree prephitemp;
 
-/* Set of blocks with statements that have had its EH information
-   cleaned up.  */
+/* Set of blocks with statements that have had their EH properties changed.  */
 static bitmap need_eh_cleanup;
 
+/* Set of blocks with statements that have had their AB properties changed.  */
+static bitmap need_ab_cleanup;
+
 /* The phi_translate_table caches phi translations for a given
    expression and predecessor.  */
 
@@ -855,9 +857,8 @@ bitmap_set_replace_value (bitmap_set_t set, unsigned int lookfor,
   exprset = VEC_index (bitmap_set_t, value_expressions, lookfor);
   FOR_EACH_EXPR_ID_IN_SET (exprset, i, bi)
     {
-      if (bitmap_bit_p (&set->expressions, i))
+      if (bitmap_clear_bit (&set->expressions, i))
        {
-         bitmap_clear_bit (&set->expressions, i);
          bitmap_set_bit (&set->expressions, get_expression_id (expr));
          return;
        }
@@ -894,9 +895,7 @@ bitmap_value_insert_into_set (bitmap_set_t set, pre_expr expr)
 {
   unsigned int val = get_expr_value_id (expr);
 
-#ifdef ENABLE_CHECKING
-  gcc_assert (expr->id == get_or_alloc_expression_id (expr));
-#endif
+  gcc_checking_assert (expr->id == get_or_alloc_expression_id (expr));
 
   /* Constant values are always considered to be part of the set.  */
   if (value_id_constant_p (val))
@@ -1887,7 +1886,7 @@ phi_translate_set (bitmap_set_t dest, bitmap_set_t set, basic_block pred,
     }
 
   exprs = sorted_array_from_bitmap_set (set);
-  for (i = 0; VEC_iterate (pre_expr, exprs, i, expr); i++)
+  FOR_EACH_VEC_ELT (pre_expr, exprs, i, expr)
     {
       pre_expr translated;
       translated = phi_translate (expr, set, NULL, pred, phiblock);
@@ -2151,7 +2150,7 @@ valid_in_sets (bitmap_set_t set1, bitmap_set_t set2, pre_expr expr,
        vn_reference_op_t vro;
        unsigned int i;
 
-       for (i = 0; VEC_iterate (vn_reference_op_s, ref->operands, i, vro); i++)
+       FOR_EACH_VEC_ELT (vn_reference_op_s, ref->operands, i, vro)
          {
            if (!vro_valid_in_sets (set1, set2, vro))
              return false;
@@ -2185,7 +2184,7 @@ dependent_clean (bitmap_set_t set1, bitmap_set_t set2, basic_block block)
   pre_expr expr;
   int i;
 
-  for (i = 0; VEC_iterate (pre_expr, exprs, i, expr); i++)
+  FOR_EACH_VEC_ELT (pre_expr, exprs, i, expr)
     {
       if (!valid_in_sets (set1, set2, expr, block))
        bitmap_remove_from_set (set1, expr);
@@ -2204,7 +2203,7 @@ clean (bitmap_set_t set, basic_block block)
   pre_expr expr;
   int i;
 
-  for (i = 0; VEC_iterate (pre_expr, exprs, i, expr); i++)
+  FOR_EACH_VEC_ELT (pre_expr, exprs, i, expr)
     {
       if (!valid_in_sets (set, NULL, expr, block))
        bitmap_remove_from_set (set, expr);
@@ -2338,7 +2337,7 @@ compute_antic_aux (basic_block block, bool block_has_abnormal_pred_edge)
       else
        bitmap_set_copy (ANTIC_OUT, ANTIC_IN (first));
 
-      for (i = 0; VEC_iterate (basic_block, worklist, i, bprime); i++)
+      FOR_EACH_VEC_ELT (basic_block, worklist, i, bprime)
        {
          if (!gimple_seq_empty_p (phi_nodes (bprime)))
            {
@@ -2481,7 +2480,7 @@ compute_partial_antic_aux (basic_block block,
        }
       if (VEC_length (basic_block, worklist) > 0)
        {
-         for (i = 0; VEC_iterate (basic_block, worklist, i, bprime); i++)
+         FOR_EACH_VEC_ELT (basic_block, worklist, i, bprime)
            {
              unsigned int i;
              bitmap_iterator bi;
@@ -2607,10 +2606,8 @@ compute_antic (void)
                                                      block->index));
            }
        }
-#ifdef ENABLE_CHECKING
       /* Theoretically possible, but *highly* unlikely.  */
-      gcc_assert (num_iterations < 500);
-#endif
+      gcc_checking_assert (num_iterations < 500);
     }
 
   statistics_histogram_event (cfun, "compute_antic iterations",
@@ -2639,10 +2636,8 @@ compute_antic (void)
                                                            block->index));
                }
            }
-#ifdef ENABLE_CHECKING
          /* Theoretically possible, but *highly* unlikely.  */
-         gcc_assert (num_iterations < 500);
-#endif
+         gcc_checking_assert (num_iterations < 500);
        }
       statistics_histogram_event (cfun, "compute_partial_antic iterations",
                                  num_iterations);
@@ -2773,8 +2768,10 @@ create_component_ref_by_pieces_1 (basic_block block, vn_reference_t ref,
       break;
     case TARGET_MEM_REF:
       {
-       pre_expr op0expr;
-       tree genop0 = NULL_TREE;
+       pre_expr op0expr, op1expr;
+       tree genop0 = NULL_TREE, genop1 = NULL_TREE;
+       vn_reference_op_t nextop = VEC_index (vn_reference_op_s, ref->operands,
+                                             ++*operand);
        tree baseop = create_component_ref_by_pieces_1 (block, ref, operand,
                                                        stmts, domstmt);
        if (!baseop)
@@ -2787,14 +2784,16 @@ create_component_ref_by_pieces_1 (basic_block block, vn_reference_t ref,
            if (!genop0)
              return NULL_TREE;
          }
-       if (DECL_P (baseop))
-         return build5 (TARGET_MEM_REF, currop->type,
-                        baseop, NULL_TREE,
-                        genop0, currop->op1, currop->op2);
-       else
-         return build5 (TARGET_MEM_REF, currop->type,
-                        NULL_TREE, baseop,
-                        genop0, currop->op1, currop->op2);
+       if (nextop->op0)
+         {
+           op1expr = get_or_alloc_expr_for (nextop->op0);
+           genop1 = find_or_generate_expression (block, op1expr,
+                                                 stmts, domstmt);
+           if (!genop1)
+             return NULL_TREE;
+         }
+       return build5 (TARGET_MEM_REF, currop->type,
+                      baseop, currop->op2, genop0, currop->op1, genop1);
       }
       break;
     case ADDR_EXPR:
@@ -2819,26 +2818,6 @@ create_component_ref_by_pieces_1 (basic_block block, vn_reference_t ref,
        return folded;
       }
       break;
-    case MISALIGNED_INDIRECT_REF:
-      {
-       tree folded;
-       tree genop1 = create_component_ref_by_pieces_1 (block, ref,
-                                                       operand,
-                                                       stmts, domstmt);
-       if (!genop1)
-         return NULL_TREE;
-       genop1 = fold_convert (build_pointer_type (currop->type),
-                              genop1);
-
-       if (currop->opcode == MISALIGNED_INDIRECT_REF)
-         folded = fold_build2 (currop->opcode, currop->type,
-                               genop1, currop->op1);
-       else
-         folded = fold_build1 (currop->opcode, currop->type,
-                               genop1);
-       return folded;
-      }
-      break;
     case BIT_FIELD_REF:
       {
        tree folded;
@@ -3260,7 +3239,7 @@ inhibit_phi_insertion (basic_block bb, pre_expr expr)
      memory reference is a simple induction variable.  In other
      cases the vectorizer won't do anything anyway (either it's
      loop invariant or a complicated expression).  */
-  for (i = 0; VEC_iterate (vn_reference_op_s, ops, i, op); ++i)
+  FOR_EACH_VEC_ELT (vn_reference_op_s, ops, i, op)
     {
       switch (op->opcode)
        {
@@ -3547,7 +3526,7 @@ do_regular_insertion (basic_block block, basic_block dom)
   pre_expr expr;
   int i;
 
-  for (i = 0; VEC_iterate (pre_expr, exprs, i, expr); i++)
+  FOR_EACH_VEC_ELT (pre_expr, exprs, i, expr)
     {
       if (expr->kind != NAME)
        {
@@ -3693,7 +3672,7 @@ do_partial_partial_insertion (basic_block block, basic_block dom)
   pre_expr expr;
   int i;
 
-  for (i = 0; VEC_iterate (pre_expr, exprs, i, expr); i++)
+  FOR_EACH_VEC_ELT (pre_expr, exprs, i, expr)
     {
       if (expr->kind != NAME)
        {
@@ -4270,6 +4249,10 @@ eliminate (void)
                      || TREE_CODE (rhs) != SSA_NAME
                      || may_propagate_copy (rhs, sprime)))
                {
+                 bool can_make_abnormal_goto
+                   = is_gimple_call (stmt)
+                     && stmt_can_make_abnormal_goto (stmt);
+
                  gcc_assert (sprime != rhs);
 
                  if (dump_file && (dump_flags & TDF_DETAILS))
@@ -4298,14 +4281,24 @@ eliminate (void)
                  stmt = gsi_stmt (gsi);
                  update_stmt (stmt);
 
-                 /* If we removed EH side effects from the statement, clean
+                 /* If we removed EH side-effects from the statement, clean
                     its EH information.  */
                  if (maybe_clean_or_replace_eh_stmt (stmt, stmt))
                    {
                      bitmap_set_bit (need_eh_cleanup,
                                      gimple_bb (stmt)->index);
                      if (dump_file && (dump_flags & TDF_DETAILS))
-                       fprintf (dump_file, "  Removed EH side effects.\n");
+                       fprintf (dump_file, "  Removed EH side-effects.\n");
+                   }
+
+                 /* Likewise for AB side-effects.  */
+                 if (can_make_abnormal_goto
+                     && !stmt_can_make_abnormal_goto (stmt))
+                   {
+                     bitmap_set_bit (need_ab_cleanup,
+                                     gimple_bb (stmt)->index);
+                     if (dump_file && (dump_flags & TDF_DETAILS))
+                       fprintf (dump_file, "  Removed AB side-effects.\n");
                    }
                }
            }
@@ -4362,13 +4355,17 @@ eliminate (void)
            }
          /* Visit indirect calls and turn them into direct calls if
             possible.  */
-         if (gimple_code (stmt) == GIMPLE_CALL
+         if (is_gimple_call (stmt)
              && TREE_CODE (gimple_call_fn (stmt)) == SSA_NAME)
            {
              tree fn = VN_INFO (gimple_call_fn (stmt))->valnum;
              if (TREE_CODE (fn) == ADDR_EXPR
                  && TREE_CODE (TREE_OPERAND (fn, 0)) == FUNCTION_DECL)
                {
+                 bool can_make_abnormal_goto
+                   = stmt_can_make_abnormal_goto (stmt);
+                 bool was_noreturn = gimple_call_noreturn_p (stmt);
+
                  if (dump_file && (dump_flags & TDF_DETAILS))
                    {
                      fprintf (dump_file, "Replacing call target with ");
@@ -4379,12 +4376,30 @@ eliminate (void)
 
                  gimple_call_set_fn (stmt, fn);
                  update_stmt (stmt);
+
+                 /* When changing a call into a noreturn call, cfg cleanup
+                    is needed to fix up the noreturn call.  */
+                 if (!was_noreturn && gimple_call_noreturn_p (stmt))
+                   todo |= TODO_cleanup_cfg;
+
+                 /* If we removed EH side-effects from the statement, clean
+                    its EH information.  */
                  if (maybe_clean_or_replace_eh_stmt (stmt, stmt))
                    {
                      bitmap_set_bit (need_eh_cleanup,
                                      gimple_bb (stmt)->index);
                      if (dump_file && (dump_flags & TDF_DETAILS))
-                       fprintf (dump_file, "  Removed EH side effects.\n");
+                       fprintf (dump_file, "  Removed EH side-effects.\n");
+                   }
+
+                 /* Likewise for AB side-effects.  */
+                 if (can_make_abnormal_goto
+                     && !stmt_can_make_abnormal_goto (stmt))
+                   {
+                     bitmap_set_bit (need_ab_cleanup,
+                                     gimple_bb (stmt)->index);
+                     if (dump_file && (dump_flags & TDF_DETAILS))
+                       fprintf (dump_file, "  Removed AB side-effects.\n");
                    }
 
                  /* Changing an indirect call to a direct call may
@@ -4474,7 +4489,7 @@ eliminate (void)
   /* We cannot remove stmts during BB walk, especially not release SSA
      names there as this confuses the VN machinery.  The stmts ending
      up in to_remove are either stores or simple copies.  */
-  for (i = 0; VEC_iterate (gimple, to_remove, i, stmt); ++i)
+  FOR_EACH_VEC_ELT (gimple, to_remove, i, stmt)
     {
       tree lhs = gimple_assign_lhs (stmt);
       tree rhs = gimple_assign_rhs1 (stmt);
@@ -4499,9 +4514,12 @@ eliminate (void)
       if (TREE_CODE (lhs) != SSA_NAME
          || has_zero_uses (lhs))
        {
+         basic_block bb = gimple_bb (stmt);
          gsi = gsi_for_stmt (stmt);
          unlink_stmt_vdef (stmt);
          gsi_remove (&gsi, true);
+         if (gimple_purge_dead_eh_edges (bb))
+           todo |= TODO_cleanup_cfg;
          if (TREE_CODE (lhs) == SSA_NAME)
            bitmap_clear_bit (inserted_exprs, SSA_NAME_VERSION (lhs));
          release_defs (stmt);
@@ -4760,6 +4778,7 @@ init_pre (bool do_fre)
     }
 
   need_eh_cleanup = BITMAP_ALLOC (NULL);
+  need_ab_cleanup = BITMAP_ALLOC (NULL);
 }
 
 
@@ -4791,6 +4810,14 @@ fini_pre (bool do_fre)
 
   BITMAP_FREE (need_eh_cleanup);
 
+  if (!bitmap_empty_p (need_ab_cleanup))
+    {
+      gimple_purge_all_dead_abnormal_call_edges (need_ab_cleanup);
+      cleanup_tree_cfg ();
+    }
+
+  BITMAP_FREE (need_ab_cleanup);
+
   if (!do_fre)
     loop_optimizer_finalize ();
 }