OSDN Git Service

PR ada/24533
[pf3gnuchains/gcc-fork.git] / gcc / tree-ssa-copyrename.c
index f74b2e4..71599cd 100644 (file)
@@ -16,8 +16,8 @@ GNU General Public License for more details.
 
 You should have received a copy of the GNU General Public License
 along with GCC; see the file COPYING.  If not, write to
-the Free Software Foundation, 59 Temple Place - Suite 330,
-Boston, MA 02111-1307, USA.  */
+the Free Software Foundation, 51 Franklin Street, Fifth Floor,
+Boston, MA 02110-1301, USA.  */
 
 #include "config.h"
 #include "system.h"
@@ -33,13 +33,11 @@ Boston, MA 02111-1307, USA.  */
 #include "tree-gimple.h"
 #include "tree-inline.h"
 #include "timevar.h"
-#include "tree-alias-common.h"
 #include "hashtab.h"
 #include "tree-dump.h"
 #include "tree-ssa-live.h"
 #include "tree-pass.h"
-
-extern void rename_ssa_copies (void);
+#include "langhooks.h"
 
 /* The following routines implement the SSA copy renaming phase.
 
@@ -48,7 +46,7 @@ extern void rename_ssa_copies (void);
 
    Each copy is examined to determine if it is possible to rename the base
    variable of one of the operands to the same variable as the other operand.
-   ie.
+   i.e.
    T.3_5 = <blah>
    a_1 = T.3_5
 
@@ -116,13 +114,12 @@ copy_rename_partition_coalesce (var_map map, tree var1, tree var2, FILE *debug)
 {
   int p1, p2, p3;
   tree root1, root2;
+  tree rep1, rep2;
   var_ann_t ann1, ann2, ann3;
-  bool gimp1, gimp2;
+  bool ign1, ign2, abnorm;
 
-#ifdef ENABLE_CHECKING
-  if (TREE_CODE (var1) != SSA_NAME || TREE_CODE (var2) != SSA_NAME)
-    abort ();
-#endif
+  gcc_assert (TREE_CODE (var1) == SSA_NAME);
+  gcc_assert (TREE_CODE (var2) == SSA_NAME);
 
   register_ssa_partition (map, var1, false);
   register_ssa_partition (map, var2, true);
@@ -139,26 +136,13 @@ copy_rename_partition_coalesce (var_map map, tree var1, tree var2, FILE *debug)
       fprintf (debug, "(P%d)", p2);
     }
 
-#ifdef ENABLE_CHECKING
-  if (p1 == NO_PARTITION || p2 == NO_PARTITION)
-    abort ();
-#endif
+  gcc_assert (p1 != NO_PARTITION);
+  gcc_assert (p2 != NO_PARTITION);
 
-  root1 = SSA_NAME_VAR (partition_to_var (map, p1));
-  root2 = SSA_NAME_VAR (partition_to_var (map, p2));
-
-  if (DECL_HARD_REGISTER (root1) || DECL_HARD_REGISTER (root2))
-    {
-      if (debug)
-        {
-         if (DECL_HARD_REGISTER (root1))
-           print_generic_expr (debug, var1, TDF_SLIM);
-         else
-           print_generic_expr (debug, var2, TDF_SLIM);
-         fprintf (debug, " is a hardware register.  No Coalescing.\n");
-       }
-      return;
-    }
+  rep1 = partition_to_var (map, p1);
+  rep2 = partition_to_var (map, p2);
+  root1 = SSA_NAME_VAR (rep1);
+  root2 = SSA_NAME_VAR (rep2);
 
   ann1 = var_ann (root1);
   ann2 = var_ann (root2);
@@ -170,6 +154,16 @@ copy_rename_partition_coalesce (var_map map, tree var1, tree var2, FILE *debug)
       return;
     }
 
+  /* Don't coalesce if one of the variables occurs in an abnormal PHI.  */
+  abnorm = (SSA_NAME_OCCURS_IN_ABNORMAL_PHI (rep1)
+           || SSA_NAME_OCCURS_IN_ABNORMAL_PHI (rep2));
+  if (abnorm)
+    {
+      if (debug)
+       fprintf (debug, " : Abnormal PHI barrier.  No coalesce.\n");
+      return;
+    }
+
   /* Partitions already have the same root, simply merge them.  */
   if (root1 == root2)
     {
@@ -194,27 +188,25 @@ copy_rename_partition_coalesce (var_map map, tree var1, tree var2, FILE *debug)
       return;
     }
 
-  gimp1 = is_gimple_tmp_var (root1);
-  gimp2 = is_gimple_tmp_var (root2);
+  ign1 = TREE_CODE (root1) == VAR_DECL && DECL_IGNORED_P (root1);
+  ign2 = TREE_CODE (root2) == VAR_DECL && DECL_IGNORED_P (root2);
 
   /* Never attempt to coalesce 2 user variables unless one is an inline 
      variable.  */
-  if (!gimp1 && !gimp2)
+  if (!ign1 && !ign2)
     {
       if (DECL_FROM_INLINE (root2))
-        gimp2 = true;
-      else
-        if (DECL_FROM_INLINE (root1))
-         gimp1 = true;
-       else 
-         {
-           if (debug)
-             fprintf (debug, " : 2 different USER vars. No coalesce.\n");
-           return;
-         }
+        ign2 = true;
+      else if (DECL_FROM_INLINE (root1))
+       ign1 = true;
+      else 
+       {
+         if (debug)
+           fprintf (debug, " : 2 different USER vars. No coalesce.\n");
+         return;
+       }
     }
 
-    
   /* Don't coalesce if there are two different memory tags.  */
   if (ann1->type_mem_tag && ann2->type_mem_tag
       && ann1->type_mem_tag != ann2->type_mem_tag)
@@ -236,27 +228,45 @@ copy_rename_partition_coalesce (var_map map, tree var1, tree var2, FILE *debug)
        }
       else
         {
-         gimp2 = true;
-         gimp1 = false;
+         ign2 = true;
+         ign1 = false;
        }
     }
-  else
-    if (default_def (root2))
-      {
-       gimp1 = true;
-       gimp2 = false;
-      }
+  else if (default_def (root2))
+    {
+      ign1 = true;
+      ign2 = false;
+    }
+
+  /* Don't coalesce if the two variables aren't type compatible.  */
+  if (!lang_hooks.types_compatible_p (TREE_TYPE (root1), TREE_TYPE (root2)))
+    {
+      if (debug)
+       fprintf (debug, " : Incompatible types.  No coalesce.\n");
+      return;
+    }
+
+  /* Don't coalesce if the aliasing sets of the types are different.  */
+  if (POINTER_TYPE_P (TREE_TYPE (root1))
+      && POINTER_TYPE_P (TREE_TYPE (root2))
+      && get_alias_set (TREE_TYPE (TREE_TYPE (root1)))
+          != get_alias_set (TREE_TYPE (TREE_TYPE (root2))))
+    {
+      if (debug)
+       fprintf (debug, " : 2 different aliasing sets. No coalesce.\n");
+      return;
+    }
+
 
   /* Merge the two partitions.  */
   p3 = partition_union (map->var_partition, p1, p2);
 
   /* Set the root variable of the partition to the better choice, if there is 
      one.  */
-  if (!gimp2)
-    SSA_NAME_VAR (partition_to_var (map, p3)) = root2;
-  else
-    if (!gimp1)
-      SSA_NAME_VAR (partition_to_var (map, p3)) = root1;
+  if (!ign2)
+    replace_ssa_name_symbol (partition_to_var (map, p3), root2);
+  else if (!ign1)
+    replace_ssa_name_symbol (partition_to_var (map, p3), root1);
 
   /* Update the various flag widgitry of the current base representative.  */
   ann3 = var_ann (SSA_NAME_VAR (partition_to_var (map, p3)));
@@ -281,7 +291,7 @@ copy_rename_partition_coalesce (var_map map, tree var1, tree var2, FILE *debug)
    then cause the SSA->normal pass to attempt to coalesce them all to the same 
    variable.  */
 
-void
+static void
 rename_ssa_copies (void)
 {
   var_map map;
@@ -309,9 +319,7 @@ rename_ssa_copies (void)
              tree lhs = TREE_OPERAND (stmt, 0);
              tree rhs = TREE_OPERAND (stmt, 1);
 
-              if (TREE_CODE (lhs) == SSA_NAME
-                 && !has_hidden_use (SSA_NAME_VAR (lhs))
-                 && TREE_CODE (rhs) == SSA_NAME)
+              if (TREE_CODE (lhs) == SSA_NAME && TREE_CODE (rhs) == SSA_NAME)
                copy_rename_partition_coalesce (map, lhs, rhs, debug);
            }
        }
@@ -320,15 +328,13 @@ rename_ssa_copies (void)
   FOR_EACH_BB (bb)
     {
       /* Treat PHI nodes as copies between the result and each argument.  */
-      for (phi = phi_nodes (bb); phi; phi = TREE_CHAIN (phi))
+      for (phi = phi_nodes (bb); phi; phi = PHI_CHAIN (phi))
         {
           int i;
          tree res = PHI_RESULT (phi);
 
-         /* Do not process virtual SSA_NAMES or variables which have
-            hidden uses.  */
-         if (!is_gimple_reg (SSA_NAME_VAR (res))
-             || has_hidden_use (SSA_NAME_VAR (res)))
+         /* Do not process virtual SSA_NAMES.  */
+         if (!is_gimple_reg (SSA_NAME_VAR (res)))
            continue;
 
           for (i = 0; i < PHI_NUM_ARGS (phi); i++)
@@ -363,7 +369,7 @@ rename_ssa_copies (void)
              fprintf (debug, "\n");
            }
        }
-      SSA_NAME_VAR (var) = SSA_NAME_VAR (part_var);
+      replace_ssa_name_symbol (var, SSA_NAME_VAR (part_var));
     }
 
   delete_var_map (map);
@@ -386,10 +392,11 @@ struct tree_opt_pass pass_rename_ssa_copies =
   NULL,                                        /* next */
   0,                                   /* static_pass_number */
   TV_TREE_COPY_RENAME,                 /* tv_id */
-  PROP_cfg | PROP_ssa,                 /* properties_required */
+  PROP_cfg | PROP_ssa | PROP_alias,    /* properties_required */
   0,                                   /* properties_provided */
   0,                                   /* properties_destroyed */
   0,                                   /* todo_flags_start */ 
-  TODO_dump_func | TODO_verify_ssa      /* todo_flags_finish */
+  TODO_dump_func | TODO_verify_ssa,     /* todo_flags_finish */
+  0                                    /* letter */
 };