]> gcc.gnu.org Git - gcc.git/commitdiff
tree-dfa.c (add_referenced_var_1): Do not add global vars.
authorRichard Biener <rguenth@gcc.gnu.org>
Wed, 23 May 2012 12:25:41 +0000 (12:25 +0000)
committerRichard Biener <rguenth@gcc.gnu.org>
Wed, 23 May 2012 12:25:41 +0000 (12:25 +0000)
2012-05-23  Richard Guenther  <rguenther@suse.de>

* tree-dfa.c (add_referenced_var_1): Do not add global vars.
* tree-ssa-live.c (mark_all_vars_used_1): Handle global vars
via the global_unused_vars bitmap.
(remove_unused_locals): Handle global vars in local-decls via
a global_unused_vars bitmap instead of the used flag in the
var annotation.  Simplify global variable handling and removal.

* gcc.dg/torture/pr39074-2.c: Adjust.
* gcc.dg/torture/pr39074.c: Likewise.
* gcc.dg/torture/pta-structcopy-1.c: Likewise.
* gcc.dg/tree-ssa/alias-19.c: Likewise.

From-SVN: r187800

gcc/ChangeLog
gcc/testsuite/ChangeLog
gcc/testsuite/gcc.dg/torture/pr39074-2.c
gcc/testsuite/gcc.dg/torture/pr39074.c
gcc/testsuite/gcc.dg/torture/pta-structcopy-1.c
gcc/testsuite/gcc.dg/tree-ssa/alias-19.c
gcc/tree-dfa.c
gcc/tree-ssa-live.c

index 15cb4eb99640c41ae819a76ec4e82c083b6a2439..112f31873cc44c50c111ad166e1f2598dcd171d3 100644 (file)
@@ -1,8 +1,17 @@
+2012-05-23  Richard Guenther  <rguenther@suse.de>
+
+       * tree-dfa.c (add_referenced_var_1): Do not add global vars.
+       * tree-ssa-live.c (mark_all_vars_used_1): Handle global vars
+       via the global_unused_vars bitmap.
+       (remove_unused_locals): Handle global vars in local-decls via
+       a global_unused_vars bitmap instead of the used flag in the
+       var annotation.  Simplify global variable handling and removal.
+
 2012-05-22  Jan Hubicka  <jh@suse.cz>
 
        PR middle-end/53426
-       * tree-ssa-structalias.c (create_variable_info_for): Skip constructors from
-       other partitions.
+       * tree-ssa-structalias.c (create_variable_info_for): Skip constructors
+       from other partitions.
 
 2012-05-22  Jan Hubicka  <jh@suse.cz>
 
index 09bc357bebf1597a3d5492ec43cc424d61861f48..4934bd2e4fe97c3c48a50da6c6efac15940f5ec8 100644 (file)
@@ -1,3 +1,10 @@
+2012-05-23  Richard Guenther  <rguenther@suse.de>
+
+       * gcc.dg/torture/pr39074-2.c: Adjust.
+       * gcc.dg/torture/pr39074.c: Likewise.
+       * gcc.dg/torture/pta-structcopy-1.c: Likewise.
+       * gcc.dg/tree-ssa/alias-19.c: Likewise.
+
 2012-05-22  Jan Hubicka  <jh@suse.cz>
 
        PR middle-end/53161
index 2278c23ef8f0711da6f671fe4eeb205f4988b12b..d18930a4d6e1610788f5226cf4300a8e6988350a 100644 (file)
@@ -30,5 +30,6 @@ int main()
   return 0;
 }
 
-/* { dg-final { scan-tree-dump "y.._., points-to vars: { i }" "alias" } } */
+/* { dg-final { scan-tree-dump "y.._. = { i }" "alias" } } */
+/* { dg-final { scan-tree-dump "y.._., points-to vars: { D..... }" "alias" } } */
 /* { dg-final { cleanup-tree-dump "alias" } } */
index 89c4ac6ca9fe6195fe9d8ac9c6977c9d4f0bf482..5d46f3120d1fddcd5a53db7cebfe5eef5e5241f0 100644 (file)
@@ -29,5 +29,6 @@ int main()
   return 0;
 }
 
-/* { dg-final { scan-tree-dump "y.._., points-to vars: { i }" "alias" } } */
+/* { dg-final { scan-tree-dump "y.._. = { i }" "alias" } } */
+/* { dg-final { scan-tree-dump "y.._., points-to vars: { D..... }" "alias" } } */
 /* { dg-final { cleanup-tree-dump "alias" } } */
index 97e8946da544d5056f4b71e63defaf07e76434ea..4846dd69879ae821d9dcf3c643273726054d50d9 100644 (file)
@@ -31,5 +31,6 @@ int main()
   return 0;
 }
 
-/* { dg-final { scan-tree-dump "points-to vars: { i }" "ealias" } } */
+/* { dg-final { scan-tree-dump "y.* = { i }" "ealias" } } */
+/* { dg-final { scan-tree-dump "y.*, points-to vars: { D..... }" "ealias" } } */
 /* { dg-final { cleanup-tree-dump "ealias" } } */
index 7b3689049ac54baa6f5064eb028c6c0a7d6a749a..63a4eee0fe6917cb3440932cc67681e36e1ac4cc 100644 (file)
@@ -26,5 +26,5 @@ int main()
 }
 
 /* { dg-final { scan-tree-dump "q_. = { a b }" "alias" } } */
-/* { dg-final { scan-tree-dump "q_., points-to vars: { a b }" "alias" } } */
+/* { dg-final { scan-tree-dump "q_., points-to vars: { D..... b }" "alias" } } */
 /* { dg-final { cleanup-tree-dump "alias" } } */
index 31cafa09a73ceaa83c264eb47e96120136779242..e9db01d8b82d5e5fcdb9b90d80640c5064a6f723 100644 (file)
@@ -581,6 +581,11 @@ add_referenced_var_1 (tree var, struct function *fn)
                       || TREE_CODE (var) == PARM_DECL
                       || TREE_CODE (var) == RESULT_DECL);
 
+  if (!(TREE_CODE (var) == VAR_DECL
+       && VAR_DECL_IS_VIRTUAL_OPERAND (var))
+      && is_global_var (var))
+    return false;
+
   if (!*DECL_VAR_ANN_PTR (var))
     create_var_ann (var);
 
index 5f3484d3a7d3b0bcb92da11712de416b33fb3883..397be1d421fe7b4b5a567e6c99e7f86e970653ed 100644 (file)
@@ -348,6 +348,7 @@ static inline void mark_all_vars_used (tree *, void *data);
 static tree
 mark_all_vars_used_1 (tree *tp, int *walk_subtrees, void *data)
 {
+  bitmap global_unused_vars = (bitmap)data;
   tree t = *tp;
   enum tree_code_class c = TREE_CODE_CLASS (TREE_CODE (t));
   tree b;
@@ -374,15 +375,20 @@ mark_all_vars_used_1 (tree *tp, int *walk_subtrees, void *data)
      eliminated as unused.  */
   if (TREE_CODE (t) == VAR_DECL)
     {
-      if (data != NULL && bitmap_clear_bit ((bitmap) data, DECL_UID (t))
-         && DECL_CONTEXT (t) == current_function_decl)
-       mark_all_vars_used (&DECL_INITIAL (t), data);
-      if (var_ann (t) != NULL)
+      /* Global vars do not have a var-annotation so their use is tracked
+         with the global_unused_vars bitmap.  Also walk their initializer
+        when they are first recognized as used.  */
+      if (is_global_var (t))
+       {
+         if (bitmap_clear_bit (global_unused_vars, DECL_UID (t)))
+           mark_all_vars_used (&DECL_INITIAL (t), data);
+       }
+      else
        set_is_used (t);
     }
   /* remove_unused_scope_block_p requires information about labels
      which are not DECL_IGNORED_P to tell if they might be used in the IL.  */
-  if (TREE_CODE (t) == LABEL_DECL)
+  else if (TREE_CODE (t) == LABEL_DECL)
     /* Although the TREE_USED values that the frontend uses would be
        acceptable (albeit slightly over-conservative) for our purposes,
        init_vars_expansion clears TREE_USED for LABEL_DECLs too, so we
@@ -689,7 +695,7 @@ remove_unused_locals (void)
   tree var, t;
   referenced_var_iterator rvi;
   bitmap global_unused_vars = NULL;
-  unsigned srcidx, dstidx, num;
+  unsigned srcidx, dstidx, num, ix;
   bool have_local_clobbers = false;
 
   /* Removing declarations from lexical blocks when not optimizing is
@@ -706,6 +712,13 @@ remove_unused_locals (void)
   FOR_EACH_REFERENCED_VAR (cfun, t, rvi)
     clear_is_used (t);
 
+  /* Assume all globals in local decls are unused.  */
+  global_unused_vars = BITMAP_ALLOC (NULL);
+  FOR_EACH_LOCAL_DECL (cfun, ix, var)
+    if (TREE_CODE (var) == VAR_DECL
+       && is_global_var (var))
+      bitmap_set_bit (global_unused_vars, DECL_UID (var));
+
   /* Walk the CFG marking all referenced symbols.  */
   FOR_EACH_BB (bb)
     {
@@ -733,7 +746,8 @@ remove_unused_locals (void)
            TREE_USED (b) = true;
 
          for (i = 0; i < gimple_num_ops (stmt); i++)
-           mark_all_vars_used (gimple_op_ptr (gsi_stmt (gsi), i), NULL);
+           mark_all_vars_used (gimple_op_ptr (gsi_stmt (gsi), i),
+                               global_unused_vars);
        }
 
       for (gsi = gsi_start_phis (bb); !gsi_end_p (gsi); gsi_next (&gsi))
@@ -743,17 +757,16 @@ remove_unused_locals (void)
          tree def;
          gimple phi = gsi_stmt (gsi);
 
-         /* No point processing globals.  */
-         if (is_global_var (SSA_NAME_VAR (gimple_phi_result (phi))))
+         if (!is_gimple_reg (gimple_phi_result (phi)))
            continue;
 
          def = gimple_phi_result (phi);
-         mark_all_vars_used (&def, NULL);
+         mark_all_vars_used (&def, global_unused_vars);
 
           FOR_EACH_PHI_ARG (arg_p, phi, i, SSA_OP_ALL_USES)
             {
              tree arg = USE_FROM_PTR (arg_p);
-             mark_all_vars_used (&arg, NULL);
+             mark_all_vars_used (&arg, global_unused_vars);
             }
         }
 
@@ -783,7 +796,10 @@ remove_unused_locals (void)
                lhs = get_base_address (lhs);
                if (TREE_CODE (lhs) == SSA_NAME)
                  lhs = SSA_NAME_VAR (lhs);
-               if (DECL_P (lhs) && (!var_ann (lhs) || !is_used_p (lhs)))
+               if (TREE_CODE (lhs) == VAR_DECL
+                   && ((is_global_var (lhs)
+                        && bitmap_bit_p (global_unused_vars, DECL_UID (lhs)))
+                       || (!is_global_var (lhs) && !is_used_p (lhs))))
                  {
                    unlink_stmt_vdef (stmt);
                    gsi_remove (&gsi, true);
@@ -799,27 +815,30 @@ remove_unused_locals (void)
 
   cfun->has_local_explicit_reg_vars = false;
 
-  /* Remove unmarked local vars from local_decls.  */
+  /* Remove unmarked local and global vars from local_decls
+     and referenced vars.  */
   num = VEC_length (tree, cfun->local_decls);
   for (srcidx = 0, dstidx = 0; srcidx < num; srcidx++)
     {
       var = VEC_index (tree, cfun->local_decls, srcidx);
-      if (TREE_CODE (var) != FUNCTION_DECL
-         && (!var_ann (var)
-             || !is_used_p (var)))
+      if (TREE_CODE (var) == VAR_DECL)
        {
          if (is_global_var (var))
            {
-             if (global_unused_vars == NULL)
-               global_unused_vars = BITMAP_ALLOC (NULL);
-             bitmap_set_bit (global_unused_vars, DECL_UID (var));
+             if (bitmap_bit_p (global_unused_vars, DECL_UID (var)))
+               continue;
+           }
+         else if (var_ann (var) == NULL
+                  || !is_used_p (var))
+           {
+             if (var_ann (var))
+               remove_referenced_var (var);
+             continue;
            }
-         else
-           continue;
        }
-      else if (TREE_CODE (var) == VAR_DECL
-              && DECL_HARD_REGISTER (var)
-              && !is_global_var (var))
+      if (TREE_CODE (var) == VAR_DECL
+         && DECL_HARD_REGISTER (var)
+         && !is_global_var (var))
        cfun->has_local_explicit_reg_vars = true;
 
       if (srcidx != dstidx)
@@ -828,45 +847,8 @@ remove_unused_locals (void)
     }
   if (dstidx != num)
     VEC_truncate (tree, cfun->local_decls, dstidx);
+  BITMAP_FREE (global_unused_vars);
 
-  /* Remove unmarked global vars from local_decls.  */
-  if (global_unused_vars != NULL)
-    {
-      tree var;
-      unsigned ix;
-      FOR_EACH_LOCAL_DECL (cfun, ix, var)
-       if (TREE_CODE (var) == VAR_DECL
-           && is_global_var (var)
-           && var_ann (var) != NULL
-           && is_used_p (var)
-           && DECL_CONTEXT (var) == current_function_decl)
-         mark_all_vars_used (&DECL_INITIAL (var), global_unused_vars);
-
-      num = VEC_length (tree, cfun->local_decls);
-      for (srcidx = 0, dstidx = 0; srcidx < num; srcidx++)
-       {
-         var = VEC_index (tree, cfun->local_decls, srcidx);
-         if (TREE_CODE (var) == VAR_DECL
-             && is_global_var (var)
-             && bitmap_bit_p (global_unused_vars, DECL_UID (var)))
-           continue;
-
-         if (srcidx != dstidx)
-           VEC_replace (tree, cfun->local_decls, dstidx, var);
-         dstidx++;
-       }
-      if (dstidx != num)
-       VEC_truncate (tree, cfun->local_decls, dstidx);
-      BITMAP_FREE (global_unused_vars);
-    }
-
-  /* Remove unused variables from REFERENCED_VARs.  */
-  FOR_EACH_REFERENCED_VAR (cfun, t, rvi)
-    if (!is_global_var (t)
-       && TREE_CODE (t) != PARM_DECL
-       && TREE_CODE (t) != RESULT_DECL
-       && !is_used_p (t))
-      remove_referenced_var (t);
   remove_unused_scope_block_p (DECL_INITIAL (current_function_decl));
   if (dump_file && (dump_flags & TDF_DETAILS))
     {
This page took 0.096084 seconds and 5 git commands to generate.