OSDN Git Service

* tree-ssa-loop-ivopts.c: New file.
[pf3gnuchains/gcc-fork.git] / gcc / tree-alias-common.c
index f7b6fed..eac7746 100644 (file)
@@ -18,6 +18,7 @@ You should have received a copy of the GNU General Public License
 along with GCC; if not, write to the Free Software
 Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
 */
+
 #include "config.h"
 #include "system.h"
 #include "coretypes.h"
@@ -26,10 +27,12 @@ Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
 #include "tree-alias-type.h"
 #include "bitmap.h"
 #include "tree-alias-common.h"
-/* If we have andersen's points-to analysis, include it. */
+
+/* If we have andersen's points-to analysis, include it.  */
 #ifdef HAVE_BANSHEE
 #include "tree-alias-ander.h"
 #endif
+
 #include "flags.h"
 #include "rtl.h"
 #include "tm_p.h"
@@ -150,18 +153,14 @@ get_alias_var_decl (tree decl)
     {
       newvar = create_alias_var (decl);
       /* Assign globals to global var for purposes of intraprocedural
-        analysis. */
-      if ((DECL_CONTEXT (decl) == NULL 
-          || TREE_PUBLIC (decl)
-          || TREE_STATIC (decl)
-          || decl_function_context (decl) == NULL) 
-         && decl != pta_global_var)
+        analysis.  */
+      if (TREE_STATIC (decl) && decl != pta_global_var)
        {
          current_alias_ops->addr_assign (current_alias_ops, 
                                          get_alias_var (pta_global_var), 
                                          newvar);
          /* If the global has some DECL_INITIAL, we need to process
-            it here. */
+            it here.  */
          if (DECL_INITIAL (decl))
            find_func_aliases (decl);
        }
@@ -190,7 +189,7 @@ get_alias_var (tree expr)
   /* If it's a decl, get the alias var of the decl. We farm this off
      to get_alias_var_decl so it can abort if the alias var doesn't
      exist, and in case something else *knows* it has a decl, and
-     wants the alias var. */
+     wants the alias var.  */
 
   if (DECL_P (expr))
     return get_alias_var_decl (expr);
@@ -204,12 +203,15 @@ get_alias_var (tree expr)
   switch (TREE_CODE (expr))
     {
     case ARRAY_REF:
+    case ARRAY_RANGE_REF:
       {
-       /* Find the first non-array ref, and return it's alias
-          variable */
+       /* Find the first non-array ref, and return its alias variable.  */
        tree p;
-       for (p = expr; TREE_CODE (p) == ARRAY_REF;
-            p = TREE_OPERAND (p, 0));
+
+       for (p = expr;
+            TREE_CODE (p) == ARRAY_REF || TREE_CODE (p) == ARRAY_RANGE_REF;
+            p = TREE_OPERAND (p, 0))
+         ;
        return get_alias_var (p);
       }
       break;
@@ -240,7 +242,7 @@ get_alias_var (tree expr)
            return get_alias_var (TREE_OPERAND (expr, 1));
          }
 #else
-        /* Find the first non-component ref, and return its alias variable. */
+        /* Find the first non-component ref, and return its alias variable.  */
        tree p;
        for (p = expr; TREE_CODE (p) == COMPONENT_REF;
             p = TREE_OPERAND (p, 0));
@@ -260,7 +262,7 @@ get_alias_var (tree expr)
     case INDIRECT_REF:
     case BIT_FIELD_REF:
       /* If it's a ref or cast or conversion of something, get the
-         alias var of the something. */
+         alias var of the something.  */
       return get_alias_var (TREE_OPERAND (expr, 0));
       break;
 
@@ -280,7 +282,7 @@ intra_function_call (varray_type args)
   size_t i;
   alias_var av = get_alias_var (pta_global_var);
 
-  /* We assume assignments among the actual parameters. */
+  /* We assume assignments among the actual parameters.  */
   for (i = 0; i < l; i++)
     {
       alias_var argi = VARRAY_GENERIC_PTR (args, i);
@@ -292,26 +294,26 @@ intra_function_call (varray_type args)
            continue;
          argj = VARRAY_GENERIC_PTR (args, j);
          /* Restricted pointers can't be aliased with other
-            restricted pointers. */
+            restricted pointers.  */
          if (!TYPE_RESTRICT (TREE_TYPE (ALIAS_VAR_DECL (argi)))
              || !TYPE_RESTRICT (TREE_TYPE (ALIAS_VAR_DECL (argj))))
-           /* Do a bit of TBAA to avoid pointless assignments. */
+           /* Do a bit of TBAA to avoid pointless assignments.  */
            if (alias_sets_conflict_p (get_alias_set (ALIAS_VAR_DECL (argi)),
                                       get_alias_set (ALIAS_VAR_DECL (argj))))        
              current_alias_ops->simple_assign (current_alias_ops, argi, argj);
        }
     }
-  /* We assume that an actual parameter can point to any global. */
+  /* We assume that an actual parameter can point to any global.  */
   for (i = 0; i < l; i++)
     {
       alias_var argav = VARRAY_GENERIC_PTR (args, i);
       /* Restricted pointers can't be aliased with other
-        restricted pointers. */
+        restricted pointers.  */
       if (!TYPE_RESTRICT (TREE_TYPE (ALIAS_VAR_DECL (argav)))
          || !TYPE_RESTRICT (TREE_TYPE (ALIAS_VAR_DECL (av))))
        {
          /* Arguments can alias globals, and whatever they point to
-            can point to a global as well. */
+            can point to a global as well.  */
          current_alias_ops->simple_assign (current_alias_ops, argav, av);
        }
     }
@@ -442,7 +444,10 @@ find_func_aliases (tree stp)
        {
          op0 = TREE_OPERAND (stp, 0);
          op1 = TREE_OPERAND (stp, 1);
+         if (TREE_CODE (op1) == WITH_SIZE_EXPR)
+           op1 = TREE_OPERAND (op1, 0);
        }
+
       /* lhsAV should always have an alias variable */
       lhsAV = get_alias_var (op0);
       if (!lhsAV)
@@ -460,7 +465,7 @@ find_func_aliases (tree stp)
          op1 = TREE_OPERAND (op1, 0);
        }
       /* Take care of fact that we may have multi-level component
-        refs. */ 
+        refs.  */ 
       if (TREE_CODE (op1) == COMPONENT_REF)
        op1 = find_op_of_decl (op1);
 #endif
@@ -468,11 +473,11 @@ find_func_aliases (tree stp)
       /* You would think we could test rhsAV at the top, rather than
         50 separate times, but we can't, because it can be NULL for
         operator assignments, where we'd still collect the individual
-        alias vars for the operator. */
+        alias vars for the operator.  */
 
       /* Note that structures are treated as a single alias
         variable, since we can disambiguate based on TBAA first,
-        and fall back on points-to. */
+        and fall back on points-to.  */
       /* x = <something> */
       if (is_gimple_variable (op0))
        {
@@ -527,13 +532,13 @@ find_func_aliases (tree stp)
          else if (TREE_CODE (op1) == CALL_EXPR)
            {
              /* Heap assignment. These are __attribute__ malloc or
-                something, i'll deal with it later. */
+                something, I'll deal with it later.  */
              if (0)
                {}
              else
                {
                  
-                 /* NORETURN functions have no effect on aliasing. */
+                 /* NORETURN functions have no effect on aliasing.  */
                  if (call_may_return (op1))
                    {                 
                      varray_type args;
@@ -656,7 +661,7 @@ find_func_aliases (tree stp)
                    || TREE_CODE (op0) == ARRAY_REF)
                   && TREE_CODE (op1) == ADDR_EXPR)
            {
-             /* This becomes temp = &y and *x = temp . */
+             /* This becomes temp = &y and *x = temp .  */
              alias_var tempvar;
              tree temp = create_tmp_var_raw (void_type_node, "aliastmp");
              tempvar = current_alias_ops->add_var (current_alias_ops, temp);
@@ -672,7 +677,7 @@ find_func_aliases (tree stp)
                   && (TREE_CODE (op1) == INDIRECT_REF
                       || TREE_CODE (op1) == ARRAY_REF))
            {
-             /* This becomes temp = *y and *x = temp . */
+             /* This becomes temp = *y and *x = temp .  */
              alias_var tempvar;
              tree temp;
              temp = create_tmp_var_raw (void_type_node, "aliastmp");
@@ -690,7 +695,7 @@ find_func_aliases (tree stp)
            {
              if (rhsAV != NULL)
                {
-                 /* This becomes temp = (cast) y and  *x = temp. */
+                 /* This becomes temp = (cast) y and  *x = temp.  */
                  alias_var tempvar;
                  tree temp;
                  temp = create_tmp_var_raw (void_type_node, "aliastmp");
@@ -711,7 +716,7 @@ find_func_aliases (tree stp)
            }
        }
     }
-  /* Calls without return values. */
+  /* Calls without return values.  */
   else if (TREE_CODE (stp) == CALL_EXPR)
     {
       alias_var callvar;
@@ -787,10 +792,10 @@ create_fun_alias_var (tree decl, int force)
          /* Incoming pointers can point to pta_global_var, unless
             either we are interprocedural, or we can do ip on all
             statics + this function has been defined + it's not an
-            external function. */
+            external function.  */
          if (POINTER_TYPE_P (TREE_TYPE (arg))
              && !current_alias_ops->ip
-             /* FIXME: Need to let analyzer decide in partial case. */
+             /* FIXME: Need to let analyzer decide in partial case.  */
              && (!current_alias_ops->ip_partial
                  || !cgraph_local_info (decl)->local))
            current_alias_ops->simple_assign (current_alias_ops, var,
@@ -814,10 +819,10 @@ create_fun_alias_var (tree decl, int force)
          /* Incoming pointers can point to pta_global_var, unless
             either we are interprocedural, or we can do ip on all
             statics + this function has been defined + it's not an
-            external function. */
+            external function.  */
          if (POINTER_TYPE_P (TREE_TYPE (fakedecl))
              && !current_alias_ops->ip
-             /* FIXME: need to let analyzer decide in partial case. */
+             /* FIXME: need to let analyzer decide in partial case.  */
              && (!current_alias_ops->ip_partial
                  || !TREE_STATIC (decl)
                  || TREE_PUBLIC (decl)))
@@ -860,7 +865,7 @@ create_fun_alias_var (tree decl, int force)
   DECL_PTA_ALIASVAR (decl) = avar;
 
   /* FIXME: Also, if this is a defining declaration then add the annotation
-     to all extern definitions of the function. */
+     to all extern definitions of the function.  */
   return avar;
 }
 
@@ -1007,7 +1012,7 @@ create_alias_vars (void)
        {
          var = TREE_VALUE (vars);
          if (TREE_CODE (var) != LABEL_DECL
-             && decl_function_context (var) == NULL
+             && TREE_STATIC (var)
              && DECL_INITIAL (var))
            find_func_aliases (var);
        }
@@ -1024,10 +1029,20 @@ create_alias_vars (void)
   pta_global_var = NULL_TREE;
 }
 
+static bool
+gate_pta (void)
+{
+#ifdef HAVE_BANSHEE
+  return flag_tree_points_to != PTA_NONE;
+#else
+  return false;
+#endif
+}
+
 struct tree_opt_pass pass_build_pta = 
 {
   "pta",                               /* name */
-  NULL,                                        /* gate */
+  gate_pta,                            /* gate */
   create_alias_vars,                   /* execute */
   NULL,                                        /* sub */
   NULL,                                        /* next */
@@ -1048,9 +1063,6 @@ delete_alias_vars (void)
 {
   size_t i;
 
-  if (flag_tree_points_to != PTA_ANDERSEN)
-    return;
-
   for (i = 0; i < VARRAY_ACTIVE_SIZE (local_alias_vars); i++)
     {
       tree key = VARRAY_TREE (local_alias_vars, i);
@@ -1075,7 +1087,7 @@ delete_alias_vars (void)
 struct tree_opt_pass pass_del_pta = 
 {
   "pta",                               /* name */
-  NULL,                                        /* gate */
+  gate_pta,                            /* gate */
   delete_alias_vars,                   /* execute */
   NULL,                                        /* sub */
   NULL,                                        /* next */
@@ -1252,7 +1264,7 @@ alias_get_name (tree t)
       /* 2 = UF
         4 = the masked pointer
         2 = the <> around it
-        1 = the terminator. */
+        1 = the terminator.  */
       namep = ggc_alloc (2 + 4 + 2 + 1);
       sprintf (namep, "<UV%x>", MASK_POINTER (t));
       return namep;