OSDN Git Service

PR c/18946
[pf3gnuchains/gcc-fork.git] / gcc / tree-dfa.c
index af6d9ed..d7ccd69 100644 (file)
@@ -24,6 +24,7 @@ Boston, MA 02111-1307, USA.  */
 #include "coretypes.h"
 #include "tm.h"
 #include "hashtab.h"
+#include "pointer-set.h"
 #include "tree.h"
 #include "rtl.h"
 #include "tm_p.h"
@@ -45,6 +46,7 @@ Boston, MA 02111-1307, USA.  */
 #include "tree-pass.h"
 #include "convert.h"
 #include "params.h"
+#include "cgraph.h"
 
 /* Build and maintain data flow information for trees.  */
 
@@ -129,7 +131,7 @@ struct tree_opt_pass pass_referenced_vars =
   NULL,                                        /* sub */
   NULL,                                        /* next */
   0,                                   /* static_pass_number */
-  0,                                   /* tv_id */
+  TV_FIND_REFERENCED_VARS,             /* tv_id */
   PROP_gimple_leh | PROP_cfg,          /* properties_required */
   PROP_referenced_vars,                        /* properties_provided */
   0,                                   /* properties_destroyed */
@@ -188,7 +190,7 @@ compute_immediate_uses (int flags, bool (*calc_for)(tree))
 
 /* Invalidates dataflow information for a statement STMT.  */
 
-static void
+void
 free_df_for_stmt (tree stmt)
 {
   dataflow_t *df;
@@ -219,7 +221,13 @@ free_df_for_stmt (tree stmt)
 }
 
 
-/* Invalidate dataflow information for the whole function.  */
+/* Invalidate dataflow information for the whole function. 
+
+   Note this only invalidates dataflow information on statements and
+   PHI nodes which are reachable.
+
+   A deleted statement may still have attached dataflow information
+   on it.  */
 
 void
 free_df (void)
@@ -304,7 +312,14 @@ compute_immediate_uses_for_stmt (tree stmt, int flags, bool (*calc_for)(tree))
          if (!IS_EMPTY_STMT (imm_rdef_stmt) && (!calc_for || calc_for (use)))
            add_immediate_use (imm_rdef_stmt, stmt);
        }
-    }
+      
+      FOR_EACH_SSA_TREE_OPERAND (use, stmt, iter, SSA_OP_ALL_KILLS)
+       {
+         tree imm_rdef_stmt = SSA_NAME_DEF_STMT (use);
+         if (!IS_EMPTY_STMT (imm_rdef_stmt) && (!calc_for || calc_for (use)))
+           add_immediate_use (imm_rdef_stmt, stmt);
+       }
+    }  
 }
 
 
@@ -526,6 +541,9 @@ dump_variable (FILE *file, tree var)
 
   fprintf (file, ", UID %u", (unsigned) ann->uid);
 
+  fprintf (file, ", ");
+  print_generic_expr (file, TREE_TYPE (var), dump_flags);
+
   if (ann->type_mem_tag)
     {
       fprintf (file, ", type memory tag: ");
@@ -541,6 +559,9 @@ dump_variable (FILE *file, tree var)
   if (is_global_var (var))
     fprintf (file, ", is global");
 
+  if (TREE_THIS_VOLATILE (var))
+    fprintf (file, ", is volatile");
+
   if (is_call_clobbered (var))
     fprintf (file, ", call clobbered");
 
@@ -667,7 +688,7 @@ dump_dfa_stats (FILE *file)
 
   size = num_referenced_vars * sizeof (tree);
   total += size;
-  fprintf (file, fmt_str_1, "Referenced variables", num_referenced_vars,
+  fprintf (file, fmt_str_1, "Referenced variables", (unsigned long)num_referenced_vars,
           SCALE (size), LABEL (size));
 
   size = dfa_stats.num_stmt_anns * sizeof (struct stmt_ann_d);
@@ -745,7 +766,7 @@ debug_dfa_stats (void)
 static void
 collect_dfa_stats (struct dfa_stats_d *dfa_stats_p)
 {
-  htab_t htab;
+  struct pointer_set_t *pset;
   basic_block bb;
   block_stmt_iterator i;
 
@@ -755,13 +776,13 @@ collect_dfa_stats (struct dfa_stats_d *dfa_stats_p)
 
   /* Walk all the trees in the function counting references.  Start at
      basic block 0, but don't stop at block boundaries.  */
-  htab = htab_create (30, htab_hash_pointer, htab_eq_pointer, NULL);
+  pset = pointer_set_create ();
 
   for (i = bsi_start (BASIC_BLOCK (0)); !bsi_end_p (i); bsi_next (&i))
     walk_tree (bsi_stmt_ptr (i), collect_dfa_stats_r, (void *) dfa_stats_p,
-              (void *) htab);
+              pset);
 
-  htab_delete (htab);
+  pointer_set_destroy (pset);
 
   FOR_EACH_BB (bb)
     {
@@ -836,9 +857,7 @@ find_vars_r (tree *tp, int *walk_subtrees, void *data)
 
   /* Type, _DECL and constant nodes have no interesting children.
      Ignore them.  */
-  else if (DECL_P (*tp)
-          || TYPE_P (*tp)
-          || TREE_CODE_CLASS (TREE_CODE (*tp)) == 'c')
+  else if (IS_TYPE_OR_DECL_P (*tp) || CONSTANT_CLASS_P (*tp))
     *walk_subtrees = 0;
 
   return NULL_TREE;
@@ -879,12 +898,11 @@ add_referenced_var (tree var, struct walk_state *walk_state)
       if (is_global_var (var))
        mark_call_clobbered (var);
 
-      /* If an initialized global variable then register the initializer
-        as well.  */
-      if (POINTER_TYPE_P (TREE_TYPE (var))
-         && TREE_READONLY (var)
-         && DECL_INITIAL (var)
-         && TREE_CODE (DECL_INITIAL (var)) == ADDR_EXPR)
+      /* Scan DECL_INITIAL for pointer variables as they may contain
+        address arithmetic referencing the address of other
+        variables.  */
+      if (DECL_INITIAL (var)
+         && POINTER_TYPE_P (TREE_TYPE (var)))
        walk_tree (&DECL_INITIAL (var), find_vars_r, walk_state, 0);
     }
 }
@@ -969,9 +987,7 @@ mark_new_vars_to_rename (tree stmt, bitmap vars_to_rename)
   v_may_defs_after = NUM_V_MAY_DEFS (STMT_V_MAY_DEF_OPS (stmt));
   v_must_defs_after = NUM_V_MUST_DEFS (STMT_V_MUST_DEF_OPS (stmt));
 
-  FOR_EACH_SSA_TREE_OPERAND (val, stmt, iter, 
-                            SSA_OP_VMAYDEF | SSA_OP_VUSE | SSA_OP_VMUSTDEF)
-
+  FOR_EACH_SSA_TREE_OPERAND (val, stmt, iter, SSA_OP_ALL_OPERANDS)
     {
       if (DECL_P (val))
        {
@@ -988,7 +1004,46 @@ mark_new_vars_to_rename (tree stmt, bitmap vars_to_rename)
   if (found_exposed_symbol
       || v_may_defs_before > v_may_defs_after
       || v_must_defs_before > v_must_defs_after)
-    bitmap_a_or_b (vars_to_rename, vars_to_rename, vars_in_vops_to_rename);
+    bitmap_ior_into (vars_to_rename, vars_in_vops_to_rename);
 
   BITMAP_XFREE (vars_in_vops_to_rename);
 }
+
+/* Find all variables within the gimplified statement that were not previously
+   visible to the function and add them to the referenced variables list.  */
+
+static tree
+find_new_referenced_vars_1 (tree *tp, int *walk_subtrees,
+                           void *data ATTRIBUTE_UNUSED)
+{
+  tree t = *tp;
+
+  if (TREE_CODE (t) == VAR_DECL && !var_ann (t))
+    add_referenced_tmp_var (t);
+
+  if (IS_TYPE_OR_DECL_P (t))
+    *walk_subtrees = 0;
+
+  return NULL;
+}
+
+void
+find_new_referenced_vars (tree *stmt_p)
+{
+  walk_tree (stmt_p, find_new_referenced_vars_1, NULL, NULL);
+}
+
+
+/* Mark all call-clobbered variables for renaming.  */
+
+void
+mark_call_clobbered_vars_to_rename (void)
+{
+  unsigned i;
+  bitmap_iterator bi;
+  EXECUTE_IF_SET_IN_BITMAP (call_clobbered_vars, 0, i, bi)
+    {
+      tree var = referenced_var (i);
+      bitmap_set_bit (vars_to_rename, var_ann (var)->uid);
+    }
+}